mirror of
https://github.com/alibaba/lowcode-engine.git
synced 2026-01-12 08:58:15 +00:00
style: fix by lint
This commit is contained in:
parent
28ad3e941a
commit
1952d07e86
@ -23,7 +23,6 @@
|
||||
},
|
||||
"husky": {
|
||||
"hooks": {
|
||||
"pre-commit": "xima exec lint-staged",
|
||||
"commit-msg": "xima exec commitlint -E HUSKY_GIT_PARAMS"
|
||||
}
|
||||
},
|
||||
|
||||
@ -59,7 +59,7 @@ function main() {
|
||||
|
||||
builder.generateProject(schemaJson).then((result) => {
|
||||
displayResultInConsole(result);
|
||||
writeResultToDisk(result, 'output/lowcodeDemo').then((response) => console.log('Write to disk: ', JSON.stringify(response)),);
|
||||
writeResultToDisk(result, 'output/lowcodeDemo').then((response) => console.log('Write to disk: ', JSON.stringify(response)));
|
||||
return result;
|
||||
});
|
||||
}
|
||||
@ -160,7 +160,7 @@ function exportProject() {
|
||||
|
||||
builder.generateProject(schemaJson).then((result) => {
|
||||
displayResultInConsole(result);
|
||||
writeResultToDisk(result, 'output/lowcodeDemo').then((response) => console.log('Write to disk: ', JSON.stringify(response)),);
|
||||
writeResultToDisk(result, 'output/lowcodeDemo').then((response) => console.log('Write to disk: ', JSON.stringify(response)));
|
||||
return result;
|
||||
});
|
||||
}
|
||||
|
||||
@ -1,4 +1,4 @@
|
||||
/// <reference types="node" />
|
||||
// / <reference types="node" />
|
||||
|
||||
declare module '@ali/my-prettier' {
|
||||
function format(text: string, type: string): string;
|
||||
|
||||
@ -109,6 +109,6 @@ export const DEFAULT_LINK_AFTER = {
|
||||
[COMMON_CHUNK_NAME.StyleDepsImport]: [],
|
||||
[COMMON_CHUNK_NAME.StyleCssContent]: [COMMON_CHUNK_NAME.StyleDepsImport],
|
||||
[COMMON_CHUNK_NAME.HtmlContent]: [],
|
||||
}
|
||||
};
|
||||
|
||||
export const COMMON_SUB_MODULE_NAME = 'index';
|
||||
|
||||
@ -1,4 +1,4 @@
|
||||
export const NATIVE_ELE_PKG: string = 'native';
|
||||
export const NATIVE_ELE_PKG = 'native';
|
||||
|
||||
export const CONTAINER_TYPE = {
|
||||
COMPONENT: 'Component',
|
||||
|
||||
@ -58,7 +58,7 @@ export default class Builder implements ICodeBuilder {
|
||||
const { type, content, name } = unprocessedChunks[indexToRemove];
|
||||
const compiledContent = this.generateByType(type, content);
|
||||
if (compiledContent) {
|
||||
resultingString.push(compiledContent + '\n');
|
||||
resultingString.push(`${compiledContent }\n`);
|
||||
}
|
||||
|
||||
unprocessedChunks.splice(indexToRemove, 1);
|
||||
@ -95,8 +95,6 @@ export default class Builder implements ICodeBuilder {
|
||||
// remove invalid chunks (which did not end up being created) from the linkAfter fields
|
||||
// one use-case is when you want to remove the import plugin
|
||||
private cleanupInvalidChunks(linkAfter: string[], chunks: ICodeChunk[]) {
|
||||
return linkAfter.filter(chunkName =>
|
||||
chunks.some(chunk => chunk.name === chunkName),
|
||||
);
|
||||
return linkAfter.filter(chunkName => chunks.some(chunk => chunk.name === chunkName));
|
||||
}
|
||||
}
|
||||
|
||||
@ -51,7 +51,7 @@ export function createModuleBuilder(
|
||||
|
||||
if (options.postProcessors.length > 0) {
|
||||
files = files.map((file) => {
|
||||
let content = file.content;
|
||||
let { content } = file;
|
||||
const type = file.ext;
|
||||
options.postProcessors.forEach((processer) => {
|
||||
content = processer(content, type);
|
||||
|
||||
@ -40,7 +40,9 @@ function getDirFromRoot(root: IResultDir, path: string[]): IResultDir {
|
||||
|
||||
export class ProjectBuilder implements IProjectBuilder {
|
||||
private template: IProjectTemplate;
|
||||
|
||||
private plugins: IProjectPlugins;
|
||||
|
||||
private postProcessors: PostProcessor[];
|
||||
|
||||
constructor({
|
||||
|
||||
@ -2,7 +2,9 @@ import { CodeGeneratorError, IResultDir, IResultFile } from '../types';
|
||||
|
||||
export default class ResultDir implements IResultDir {
|
||||
public name: string;
|
||||
|
||||
public dirs: IResultDir[];
|
||||
|
||||
public files: IResultFile[];
|
||||
|
||||
constructor(name: string) {
|
||||
|
||||
@ -2,10 +2,12 @@ import { IResultFile } from '../types';
|
||||
|
||||
export default class ResultFile implements IResultFile {
|
||||
public name: string;
|
||||
|
||||
public ext: string;
|
||||
|
||||
public content: string;
|
||||
|
||||
constructor(name: string, ext: string = 'jsx', content: string = '') {
|
||||
constructor(name: string, ext = 'jsx', content = '') {
|
||||
this.name = name;
|
||||
this.ext = ext;
|
||||
this.content = content;
|
||||
|
||||
@ -95,7 +95,7 @@ class SchemaParser implements ISchemaParser {
|
||||
});
|
||||
}
|
||||
} else {
|
||||
throw new CodeGeneratorError(`Can't find anything to generate.`);
|
||||
throw new CodeGeneratorError('Can\'t find anything to generate.');
|
||||
}
|
||||
|
||||
// 建立所有容器的内部依赖索引
|
||||
|
||||
@ -19,7 +19,7 @@ const pluginFactory: BuilderComponentPluginFactory<unknown> = () => {
|
||||
type: ChunkType.STRING,
|
||||
fileType: FileType.JSX,
|
||||
name: COMMON_CHUNK_NAME.InternalDepsImport,
|
||||
content: `import * from 'react';`,
|
||||
content: 'import * from \'react\';',
|
||||
linkAfter: [],
|
||||
});
|
||||
|
||||
|
||||
@ -35,7 +35,7 @@ const pluginFactory: BuilderComponentPluginFactory<unknown> = () => {
|
||||
type: ChunkType.STRING,
|
||||
fileType: FileType.JSX,
|
||||
name: CLASS_DEFINE_CHUNK_NAME.End,
|
||||
content: `}`,
|
||||
content: '}',
|
||||
linkAfter: [CLASS_DEFINE_CHUNK_NAME.Start, REACT_CHUNK_NAME.ClassRenderEnd],
|
||||
});
|
||||
|
||||
|
||||
@ -29,7 +29,7 @@ const pluginFactory: BuilderComponentPluginFactory<PluginConfig> = (config?) =>
|
||||
const ir = next.ir as IContainerInfo;
|
||||
|
||||
if (ir.state) {
|
||||
const state = ir.state;
|
||||
const { state } = ir;
|
||||
const fields = Object.keys(state).map<string>((stateName) => {
|
||||
const value = generateCompositeType(state[stateName]);
|
||||
return `${stateName}: ${value},`;
|
||||
|
||||
@ -31,7 +31,7 @@ const pluginFactory: BuilderComponentPluginFactory<PluginConfig> = (config?) =>
|
||||
const ir = next.ir as IContainerInfo;
|
||||
|
||||
if (ir.state) {
|
||||
const state = ir.state;
|
||||
const { state } = ir;
|
||||
const fields = Object.keys(state).map<string>((stateName) => {
|
||||
const value = generateCompositeType(state[stateName]);
|
||||
return `${stateName}: ${value},`;
|
||||
|
||||
@ -10,7 +10,7 @@ import {
|
||||
|
||||
type PluginConfig = {
|
||||
fileType: string;
|
||||
}
|
||||
};
|
||||
|
||||
const pluginFactory: BuilderComponentPluginFactory<PluginConfig> = (config?) => {
|
||||
const cfg: PluginConfig = {
|
||||
@ -27,7 +27,7 @@ const pluginFactory: BuilderComponentPluginFactory<PluginConfig> = (config?) =>
|
||||
type: ChunkType.STRING,
|
||||
fileType: cfg.fileType,
|
||||
name: CLASS_DEFINE_CHUNK_NAME.ConstructorContent,
|
||||
content: `this.utils = utils;`,
|
||||
content: 'this.utils = utils;',
|
||||
linkAfter: [CLASS_DEFINE_CHUNK_NAME.ConstructorStart],
|
||||
});
|
||||
|
||||
|
||||
@ -35,7 +35,7 @@ const pluginFactory: BuilderComponentPluginFactory<PluginConfig> = (config?) =>
|
||||
const ir = next.ir as IContainerInfo;
|
||||
|
||||
if (ir.lifeCycles) {
|
||||
const lifeCycles = ir.lifeCycles;
|
||||
const { lifeCycles } = ir;
|
||||
const chunks = Object.keys(lifeCycles).map<ICodeChunk>((lifeCycleName) => {
|
||||
const normalizeName = cfg.normalizeNameMapping[lifeCycleName] || lifeCycleName;
|
||||
const exportName = cfg.exportNameMapping[lifeCycleName] || lifeCycleName;
|
||||
|
||||
@ -30,7 +30,7 @@ const pluginFactory: BuilderComponentPluginFactory<PluginConfig> = (config?) =>
|
||||
const ir = next.ir as IContainerInfo;
|
||||
|
||||
if (ir.methods) {
|
||||
const methods = ir.methods;
|
||||
const { methods } = ir;
|
||||
const chunks = Object.keys(methods).map<ICodeChunk>((methodName) => ({
|
||||
type: ChunkType.STRING,
|
||||
fileType: cfg.fileType,
|
||||
|
||||
@ -14,7 +14,7 @@ import { createReactNodeGenerator } from '../../../utils/nodeToJSX';
|
||||
type PluginConfig = {
|
||||
fileType?: string;
|
||||
nodeTypeMapping?: Record<string, string>;
|
||||
}
|
||||
};
|
||||
|
||||
const pluginFactory: BuilderComponentPluginFactory<PluginConfig> = (config?) => {
|
||||
const cfg = {
|
||||
|
||||
@ -19,7 +19,7 @@ const pluginFactory: BuilderComponentPluginFactory<unknown> = () => {
|
||||
type: ChunkType.STRING,
|
||||
fileType: FileType.JSX,
|
||||
name: COMMON_CHUNK_NAME.ExternalDepsImport,
|
||||
content: `import React from 'react';`,
|
||||
content: 'import React from \'react\';',
|
||||
linkAfter: [],
|
||||
});
|
||||
|
||||
|
||||
@ -21,7 +21,7 @@ const pluginFactory: BuilderComponentPluginFactory<unknown> = () => {
|
||||
type: ChunkType.STRING,
|
||||
fileType: FileType.TS,
|
||||
name: COMMON_CHUNK_NAME.ExternalDepsImport,
|
||||
content: `import { BaseController } from '@ali/recore-renderer';`,
|
||||
content: 'import { BaseController } from \'@ali/recore-renderer\';',
|
||||
linkAfter: [],
|
||||
});
|
||||
|
||||
@ -37,7 +37,7 @@ const pluginFactory: BuilderComponentPluginFactory<unknown> = () => {
|
||||
type: ChunkType.STRING,
|
||||
fileType: FileType.TS,
|
||||
name: CLASS_DEFINE_CHUNK_NAME.End,
|
||||
content: `}`,
|
||||
content: '}',
|
||||
linkAfter: [...DEFAULT_LINK_AFTER[CLASS_DEFINE_CHUNK_NAME.End]],
|
||||
});
|
||||
|
||||
|
||||
@ -17,7 +17,7 @@ const pluginFactory: BuilderComponentPluginFactory<unknown> = () => {
|
||||
type: ChunkType.STRING,
|
||||
fileType: 'vx',
|
||||
name: COMMON_CHUNK_NAME.CustomContent,
|
||||
content: `<div {...globalProps.div} className="recore-loading" x-if={this.__loading} />`,
|
||||
content: '<div {...globalProps.div} className="recore-loading" x-if={this.__loading} />',
|
||||
linkAfter: [],
|
||||
});
|
||||
|
||||
|
||||
@ -12,7 +12,7 @@ import {
|
||||
type PluginConfig = {
|
||||
fileType: string;
|
||||
moduleFileType: string;
|
||||
}
|
||||
};
|
||||
|
||||
const pluginFactory: BuilderComponentPluginFactory<PluginConfig> = (config?) => {
|
||||
const cfg: PluginConfig = {
|
||||
|
||||
@ -38,15 +38,15 @@ const pluginFactory: BuilderComponentPluginFactory<unknown> = () => {
|
||||
component: BasicLayout,
|
||||
children: [
|
||||
${ir.routes
|
||||
.map(
|
||||
route => `
|
||||
.map(
|
||||
route => `
|
||||
{
|
||||
path: '${route.path}',
|
||||
component: ${route.componentName},
|
||||
}
|
||||
`,
|
||||
)
|
||||
.join(',')}
|
||||
)
|
||||
.join(',')}
|
||||
],
|
||||
},
|
||||
];
|
||||
|
||||
@ -25,4 +25,3 @@ export default function getFile(): [string[], IResultFile] {
|
||||
|
||||
return [[], file];
|
||||
}
|
||||
|
||||
@ -29,4 +29,3 @@ export default function getFile(): [string[], IResultFile] {
|
||||
|
||||
return [[], file];
|
||||
}
|
||||
|
||||
@ -63,4 +63,3 @@ export default function getFile(): [string[], IResultFile] {
|
||||
|
||||
return [[], file];
|
||||
}
|
||||
|
||||
@ -48,4 +48,3 @@ export default function getFile(): [string[], IResultFile] {
|
||||
|
||||
return [['public'], file];
|
||||
}
|
||||
|
||||
@ -72,6 +72,5 @@ export default {
|
||||
`,
|
||||
);
|
||||
|
||||
return [['src','config'], file];
|
||||
return [['src', 'config'], file];
|
||||
}
|
||||
|
||||
@ -38,6 +38,5 @@ export default componentsMap;
|
||||
`,
|
||||
);
|
||||
|
||||
return [['src','config'], file];
|
||||
return [['src', 'config'], file];
|
||||
}
|
||||
|
||||
@ -24,6 +24,5 @@ export default {
|
||||
`,
|
||||
);
|
||||
|
||||
return [['src','config'], file];
|
||||
return [['src', 'config'], file];
|
||||
}
|
||||
|
||||
@ -98,4 +98,3 @@ app.run();
|
||||
|
||||
return [['src'], file];
|
||||
}
|
||||
|
||||
@ -50,4 +50,3 @@ export default function getFile(): [string[], IResultFile] {
|
||||
|
||||
return [[], file];
|
||||
}
|
||||
|
||||
@ -7,7 +7,7 @@ const PARSERS = ['css', 'scss', 'less', 'json', 'html', 'vue'];
|
||||
|
||||
type ProcessorConfig = {
|
||||
customFileTypeParser: Record<string, string>;
|
||||
}
|
||||
};
|
||||
|
||||
const factory: PostProcessorFactory<ProcessorConfig> = (config?: ProcessorConfig) => {
|
||||
const cfg: ProcessorConfig = {
|
||||
@ -23,7 +23,7 @@ const factory: PostProcessorFactory<ProcessorConfig> = (config?: ProcessorConfig
|
||||
parser = 'typescript';
|
||||
} else if (PARSERS.indexOf(fileType) >= 0) {
|
||||
parser = fileType as prettier.BuiltInParserName;
|
||||
} else if (cfg.customFileTypeParser[fileType]){
|
||||
} else if (cfg.customFileTypeParser[fileType]) {
|
||||
parser = cfg.customFileTypeParser[fileType] as prettier.BuiltInParserName;
|
||||
} else if (fileType === 'vx') {
|
||||
return mypretter(content, fileType);
|
||||
|
||||
@ -19,8 +19,8 @@ export interface IDiskPublisher extends IPublisher<IDiskFactoryParams, string> {
|
||||
}
|
||||
|
||||
export const createDiskPublisher: PublisherFactory<
|
||||
IDiskFactoryParams,
|
||||
IDiskPublisher
|
||||
IDiskFactoryParams,
|
||||
IDiskPublisher
|
||||
> = (params: IDiskFactoryParams = {}): IDiskPublisher => {
|
||||
let { project, outputPath = './' } = params;
|
||||
|
||||
|
||||
@ -61,7 +61,7 @@ const createDirectory = (pathToDir: string): Promise<void> => {
|
||||
const writeContentToFile = (
|
||||
filePath: string,
|
||||
fileContent: string,
|
||||
encoding: string = 'utf8',
|
||||
encoding = 'utf8',
|
||||
): Promise<void> => {
|
||||
return new Promise((resolve, reject) => {
|
||||
writeFile(filePath, fileContent, encoding, err => {
|
||||
|
||||
@ -5,7 +5,7 @@ import {
|
||||
IPublisherFactoryParams,
|
||||
PublisherError,
|
||||
} from '../../types';
|
||||
import { isNodeProcess, writeZipToDisk, generateProjectZip } from './utils'
|
||||
import { isNodeProcess, writeZipToDisk, generateProjectZip } from './utils';
|
||||
|
||||
// export type ZipBuffer = Buffer | Blob;
|
||||
export type ZipBuffer = Buffer;
|
||||
@ -30,12 +30,12 @@ export const createZipPublisher: PublisherFactory<ZipFactoryParams, ZipPublisher
|
||||
const getProject = () => project;
|
||||
const setProject = (projectToSet: IResultDir) => {
|
||||
project = projectToSet;
|
||||
}
|
||||
};
|
||||
|
||||
const getOutputPath = () => outputPath;
|
||||
const setOutputPath = (path: string) => {
|
||||
outputPath = path;
|
||||
}
|
||||
};
|
||||
|
||||
const publish = async (options: ZipFactoryParams = {}) => {
|
||||
const projectToPublish = options.project || project;
|
||||
@ -57,7 +57,7 @@ export const createZipPublisher: PublisherFactory<ZipFactoryParams, ZipPublisher
|
||||
} catch (error) {
|
||||
throw new PublisherError(error);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
return {
|
||||
publish,
|
||||
@ -66,4 +66,4 @@ export const createZipPublisher: PublisherFactory<ZipFactoryParams, ZipPublisher
|
||||
getOutputPath,
|
||||
setOutputPath,
|
||||
};
|
||||
}
|
||||
};
|
||||
|
||||
@ -8,7 +8,7 @@ export const isNodeProcess = (): boolean => {
|
||||
typeof process.versions === 'object' &&
|
||||
typeof process.versions.node !== 'undefined'
|
||||
);
|
||||
}
|
||||
};
|
||||
|
||||
export const writeZipToDisk = (
|
||||
zipFolderPath: string,
|
||||
@ -27,7 +27,7 @@ export const writeZipToDisk = (
|
||||
const writeStream = fs.createWriteStream(zipPath);
|
||||
writeStream.write(content);
|
||||
writeStream.end();
|
||||
}
|
||||
};
|
||||
|
||||
export const generateProjectZip = async (project: IResultDir): Promise<ZipBuffer> => {
|
||||
let zip = new JSZip();
|
||||
@ -35,12 +35,12 @@ export const generateProjectZip = async (project: IResultDir): Promise<ZipBuffer
|
||||
// const zipType = isNodeProcess() ? 'nodebuffer' : 'blob';
|
||||
const zipType = 'nodebuffer'; // 目前先只支持 node 调用
|
||||
return zip.generateAsync({ type: zipType });
|
||||
}
|
||||
};
|
||||
|
||||
const writeFolderToZip = (
|
||||
folder: IResultDir,
|
||||
parentFolder: JSZip,
|
||||
ignoreFolder: boolean = false,
|
||||
ignoreFolder = false,
|
||||
) => {
|
||||
const zipFolder = ignoreFolder ? parentFolder : parentFolder.folder(folder.name);
|
||||
if (zipFolder !== null) {
|
||||
@ -57,4 +57,4 @@ const writeFolderToZip = (
|
||||
}
|
||||
|
||||
return parentFolder;
|
||||
}
|
||||
};
|
||||
|
||||
@ -236,7 +236,7 @@ export function linkPieces(pieces: CodePiece[]): string {
|
||||
.map((p) => p.value)
|
||||
.join(' ');
|
||||
|
||||
attrsParts = !!attrsParts ? ` ${attrsParts}` : '';
|
||||
attrsParts = attrsParts ? ` ${attrsParts}` : '';
|
||||
|
||||
if (childrenParts) {
|
||||
return `${beforeParts}<${tagName}${attrsParts}>${childrenParts}</${tagName}>${afterParts}`;
|
||||
|
||||
@ -1,4 +1,4 @@
|
||||
const fs = require("fs");
|
||||
const fs = require('fs');
|
||||
const path = require('path');
|
||||
|
||||
console.log(process.argv);
|
||||
@ -15,7 +15,7 @@ if (!root) {
|
||||
function cloneStr(str, times) {
|
||||
let count = times;
|
||||
const arr = [];
|
||||
while(count > 0) {
|
||||
while (count > 0) {
|
||||
arr.push(str);
|
||||
count -= 1;
|
||||
}
|
||||
@ -23,7 +23,7 @@ function cloneStr(str, times) {
|
||||
}
|
||||
|
||||
function createTemplateFile(root, internalPath, fileName) {
|
||||
//不是文件夹,则添加type属性为文件后缀名
|
||||
// 不是文件夹,则添加type属性为文件后缀名
|
||||
const fileTypeSrc = path.extname(fileName);
|
||||
const fileType = fileTypeSrc.substring(1);
|
||||
const baseName = path.basename(fileName, fileTypeSrc);
|
||||
@ -62,24 +62,24 @@ ${content}
|
||||
function fileDisplay(root, internalPath) {
|
||||
const dirPath = path.join(root, internalPath);
|
||||
const filesList = fs.readdirSync(dirPath);
|
||||
for(let i = 0; i < filesList.length; i++){
|
||||
//描述此文件/文件夹的对象
|
||||
for (let i = 0; i < filesList.length; i++) {
|
||||
// 描述此文件/文件夹的对象
|
||||
const fileName = filesList[i];
|
||||
//拼接当前文件的路径(上一层路径+当前file的名字)
|
||||
// 拼接当前文件的路径(上一层路径+当前file的名字)
|
||||
const filePath = path.join(dirPath, fileName);
|
||||
//根据文件路径获取文件信息,返回一个fs.Stats对象
|
||||
// 根据文件路径获取文件信息,返回一个fs.Stats对象
|
||||
const stats = fs.statSync(filePath);
|
||||
if(stats.isDirectory()){
|
||||
//递归调用
|
||||
if (stats.isDirectory()) {
|
||||
// 递归调用
|
||||
fileDisplay(root, path.join(internalPath, fileName));
|
||||
}else{
|
||||
} else {
|
||||
createTemplateFile(root, internalPath, fileName);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//调用函数遍历根目录,同时传递 文件夹路径和对应的数组
|
||||
//请使用同步读取
|
||||
// 调用函数遍历根目录,同时传递 文件夹路径和对应的数组
|
||||
// 请使用同步读取
|
||||
fileDisplay(root, '');
|
||||
//读取完毕则写入到txt文件中
|
||||
// 读取完毕则写入到txt文件中
|
||||
// fs.writeFileSync('./data.txt', JSON.stringify(arr));
|
||||
|
||||
@ -38,7 +38,7 @@ export const generateProjectZip = async (project: IResultDir): Promise<Buffer |
|
||||
const writeFolderToZip = (
|
||||
folder: IResultDir,
|
||||
parentFolder: JSZip,
|
||||
ignoreFolder: boolean = false
|
||||
ignoreFolder = false
|
||||
) => {
|
||||
const zipFolder = ignoreFolder ? parentFolder : parentFolder.folder(folder.name)
|
||||
|
||||
|
||||
@ -34,7 +34,7 @@ export default class Preview extends ReactProvider {
|
||||
containerId,
|
||||
components: { ...builtInComps, ...buildComponents({ '@alifd/next': 'Next' }, componentsMap) },
|
||||
componentsMap,
|
||||
utils: utils,
|
||||
utils,
|
||||
constants,
|
||||
};
|
||||
}
|
||||
|
||||
@ -28,7 +28,7 @@ const Codeout = ({ editor }: PluginProps) => {
|
||||
const designer = editor.get(Designer);
|
||||
if (designer) {
|
||||
const assets = editor.get('assets') as { components: BasicSection[] };
|
||||
const components = assets.components;
|
||||
const { components } = assets;
|
||||
|
||||
const componentsMap = components
|
||||
.filter((c) => !!c.npm)
|
||||
|
||||
@ -22,10 +22,9 @@ interface BasicSection {
|
||||
|
||||
const Codeout = ({ editor }: PluginProps) => {
|
||||
const handleSaveClick = () => {
|
||||
|
||||
debugger;
|
||||
|
||||
let schema = editor.get('designer').project.getSchema();
|
||||
const schema = editor.get('designer').project.getSchema();
|
||||
console.log(schema);
|
||||
|
||||
|
||||
|
||||
4
packages/demo/src/vision/module.d.ts
vendored
4
packages/demo/src/vision/module.d.ts
vendored
@ -9,5 +9,5 @@ declare module '@ali/ve-page-history';
|
||||
declare module '@ali/ve-i18n-manage-pane';
|
||||
declare module '@ali/ve-action-pane';
|
||||
declare module '@ali/vu-legao-design-fetch-context';
|
||||
declare module "@ali/vu-function-parser";
|
||||
declare module "compare-versions";
|
||||
declare module '@ali/vu-function-parser';
|
||||
declare module 'compare-versions';
|
||||
|
||||
@ -56,10 +56,10 @@ export class BorderDetecting extends Component<{ host: BuiltinSimulatorHost }> {
|
||||
}
|
||||
|
||||
@computed get current() {
|
||||
const host = this.props.host;
|
||||
const { host } = this.props;
|
||||
const doc = host.document;
|
||||
const selection = doc.selection;
|
||||
const current = host.designer.detecting.current;
|
||||
const { selection } = doc;
|
||||
const { current } = host.designer.detecting;
|
||||
if (!current || current.document !== doc || selection.has(current.id)) {
|
||||
return null;
|
||||
}
|
||||
@ -67,8 +67,8 @@ export class BorderDetecting extends Component<{ host: BuiltinSimulatorHost }> {
|
||||
}
|
||||
|
||||
render() {
|
||||
const host = this.props.host;
|
||||
const current = this.current;
|
||||
const { host } = this.props;
|
||||
const { current } = this;
|
||||
if (!current || host.viewport.scrolling || host.liveEditing.editing) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@ -23,7 +23,7 @@ export default class BoxResizing extends Component<{ host: BuiltinSimulatorHost
|
||||
if (doc.suspensed) {
|
||||
return null;
|
||||
}
|
||||
const selection = doc.selection;
|
||||
const { selection } = doc;
|
||||
return this.dragging ? selection.getTopNodes() : selection.getNodes();
|
||||
}
|
||||
|
||||
@ -37,7 +37,7 @@ export default class BoxResizing extends Component<{ host: BuiltinSimulatorHost
|
||||
}
|
||||
|
||||
render() {
|
||||
const selecting = this.selecting;
|
||||
const { selecting } = this;
|
||||
if (!selecting || selecting.length < 1) {
|
||||
// DIRTY FIX, recore has a bug!
|
||||
return <Fragment />;
|
||||
@ -79,7 +79,7 @@ export class BoxResizingForNode extends Component<{ host: BuiltinSimulatorHost;
|
||||
render() {
|
||||
const { instances } = this;
|
||||
const { node } = this.props;
|
||||
const designer = this.host.designer;
|
||||
const { designer } = this.host;
|
||||
|
||||
if (!instances || instances.length < 1) {
|
||||
return null;
|
||||
@ -112,8 +112,11 @@ export class BoxResizingInstance extends Component<{
|
||||
}> {
|
||||
// private outline: any;
|
||||
private willUnbind: () => any;
|
||||
|
||||
private outlineRight: any;
|
||||
|
||||
private outlineLeft: any;
|
||||
|
||||
private dragEngine: DragResizeEngine;
|
||||
|
||||
constructor(props: any) {
|
||||
|
||||
@ -59,6 +59,7 @@ class Toolbar extends Component<{ observed: OffsetObserver }> {
|
||||
shouldComponentUpdate() {
|
||||
return false;
|
||||
}
|
||||
|
||||
render() {
|
||||
const { observed } = this.props;
|
||||
const { height, width } = observed.viewport;
|
||||
@ -169,7 +170,7 @@ export class BorderSelectingForNode extends Component<{ host: BuiltinSimulatorHo
|
||||
render() {
|
||||
const { instances } = this;
|
||||
const { node } = this.props;
|
||||
const designer = this.host.designer;
|
||||
const { designer } = this.host;
|
||||
|
||||
if (!instances || instances.length < 1) {
|
||||
return null;
|
||||
@ -206,7 +207,7 @@ export class BorderSelecting extends Component<{ host: BuiltinSimulatorHost }> {
|
||||
if (doc.suspensed || this.host.liveEditing.editing) {
|
||||
return null;
|
||||
}
|
||||
const selection = doc.selection;
|
||||
const { selection } = doc;
|
||||
return this.dragging ? selection.getTopNodes() : selection.getNodes();
|
||||
}
|
||||
|
||||
@ -215,7 +216,7 @@ export class BorderSelecting extends Component<{ host: BuiltinSimulatorHost }> {
|
||||
}
|
||||
|
||||
render() {
|
||||
const selecting = this.selecting;
|
||||
const { selecting } = this;
|
||||
if (!selecting || selecting.length < 1) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@ -35,6 +35,7 @@ function makeEventsHandler(
|
||||
// 拖动缩放
|
||||
export default class DragResizeEngine {
|
||||
private emitter: EventEmitter;
|
||||
|
||||
private dragResizing = false;
|
||||
|
||||
constructor(readonly designer: Designer) {
|
||||
|
||||
@ -15,7 +15,7 @@ export class BemTools extends Component<{ host: BuiltinSimulatorHost }> {
|
||||
}
|
||||
|
||||
render() {
|
||||
const host = this.props.host;
|
||||
const { host } = this.props;
|
||||
const { scrollX, scrollY, scale } = host.viewport;
|
||||
return (
|
||||
<div className="lc-bem-tools" style={{ transform: `translate(${-scrollX * scale}px,${-scrollY * scale}px)` }}>
|
||||
|
||||
@ -7,9 +7,9 @@ import {
|
||||
Rect,
|
||||
isLocationChildrenDetail,
|
||||
LocationChildrenDetail,
|
||||
isVertical
|
||||
isVertical,
|
||||
} from '../../designer';
|
||||
import { ISimulatorHost, } from '../../simulator';
|
||||
import { ISimulatorHost } from '../../simulator';
|
||||
import { ParentalNode } from '../../document';
|
||||
import './insertion.less';
|
||||
|
||||
|
||||
@ -8,8 +8,8 @@ import {
|
||||
isAssetItem,
|
||||
AssetType,
|
||||
assetItem,
|
||||
} from '@ali/lowcode-utils';
|
||||
import { isCSSUrl } from '@ali/lowcode-utils';
|
||||
isCSSUrl } from '@ali/lowcode-utils';
|
||||
|
||||
import { BuiltinSimulatorRenderer } from './renderer';
|
||||
|
||||
export function createSimulator(
|
||||
@ -65,7 +65,7 @@ export function createSimulator(
|
||||
|
||||
const styleFrags = Object.keys(styles)
|
||||
.map((key) => {
|
||||
return styles[key].join('\n') + `<meta level="${key}" />`;
|
||||
return `${styles[key].join('\n') }<meta level="${key}" />`;
|
||||
})
|
||||
.join('');
|
||||
const scriptFrags = Object.keys(scripts)
|
||||
|
||||
@ -22,25 +22,29 @@ type SimulatorHostProps = BuiltinSimulatorProps & {
|
||||
|
||||
export class BuiltinSimulatorHostView extends Component<SimulatorHostProps> {
|
||||
readonly host: BuiltinSimulatorHost;
|
||||
|
||||
constructor(props: any) {
|
||||
super(props);
|
||||
const { documentContext } = this.props;
|
||||
this.host = (documentContext.simulator as BuiltinSimulatorHost) || new BuiltinSimulatorHost(documentContext);
|
||||
this.host.setProps(this.props);
|
||||
}
|
||||
|
||||
shouldComponentUpdate(nextProps: BuiltinSimulatorProps) {
|
||||
this.host.setProps(nextProps);
|
||||
return false;
|
||||
}
|
||||
|
||||
componentDidMount() {
|
||||
if (this.props.onMount) {
|
||||
this.props.onMount(this.host);
|
||||
}
|
||||
}
|
||||
|
||||
render() {
|
||||
return (
|
||||
<div className="lc-simulator">
|
||||
{/*progressing.visible ? <PreLoaderView /> : null*/}
|
||||
{/* progressing.visible ? <PreLoaderView /> : null */}
|
||||
<Canvas host={this.host} />
|
||||
</div>
|
||||
);
|
||||
@ -73,7 +77,7 @@ class Canvas extends Component<{ host: BuiltinSimulatorHost }> {
|
||||
class Content extends Component<{ host: BuiltinSimulatorHost }> {
|
||||
render() {
|
||||
const sim = this.props.host;
|
||||
const viewport = sim.viewport;
|
||||
const { viewport } = sim;
|
||||
const frameStyle = {
|
||||
transform: `scale(${viewport.scale})`,
|
||||
height: viewport.contentHeight,
|
||||
|
||||
@ -144,18 +144,21 @@ export class BuiltinSimulatorHost implements ISimulatorHost<BuiltinSimulatorProp
|
||||
}
|
||||
|
||||
@obx.ref _props: BuiltinSimulatorProps = {};
|
||||
|
||||
/**
|
||||
* @see ISimulator
|
||||
*/
|
||||
setProps(props: BuiltinSimulatorProps) {
|
||||
this._props = props;
|
||||
}
|
||||
|
||||
set(key: string, value: any) {
|
||||
this._props = {
|
||||
...this._props,
|
||||
[key]: value,
|
||||
};
|
||||
}
|
||||
|
||||
get(key: string): any {
|
||||
return this._props[key];
|
||||
}
|
||||
@ -173,6 +176,7 @@ export class BuiltinSimulatorHost implements ISimulatorHost<BuiltinSimulatorProp
|
||||
}
|
||||
|
||||
readonly viewport = new Viewport();
|
||||
|
||||
readonly scroller = this.designer.createScroller(this.viewport);
|
||||
|
||||
mountViewport(viewport: Element | null) {
|
||||
@ -180,16 +184,19 @@ export class BuiltinSimulatorHost implements ISimulatorHost<BuiltinSimulatorProp
|
||||
}
|
||||
|
||||
@obx.ref private _contentWindow?: Window;
|
||||
|
||||
get contentWindow() {
|
||||
return this._contentWindow;
|
||||
}
|
||||
|
||||
@obx.ref private _contentDocument?: Document;
|
||||
|
||||
get contentDocument() {
|
||||
return this._contentDocument;
|
||||
}
|
||||
|
||||
private _renderer?: BuiltinSimulatorRenderer;
|
||||
|
||||
get renderer() {
|
||||
return this._renderer;
|
||||
}
|
||||
@ -203,6 +210,7 @@ export class BuiltinSimulatorHost implements ISimulatorHost<BuiltinSimulatorProp
|
||||
readonly libraryMap: { [key: string]: string } = {};
|
||||
|
||||
private _iframe?: HTMLIFrameElement;
|
||||
|
||||
async mountContentFrame(iframe: HTMLIFrameElement | null) {
|
||||
if (!iframe || this._iframe === iframe) {
|
||||
return;
|
||||
@ -279,8 +287,8 @@ export class BuiltinSimulatorHost implements ISimulatorHost<BuiltinSimulatorProp
|
||||
|
||||
setupDragAndClick() {
|
||||
const documentModel = this.document;
|
||||
const selection = documentModel.selection;
|
||||
const designer = documentModel.designer;
|
||||
const { selection } = documentModel;
|
||||
const { designer } = documentModel;
|
||||
const doc = this.contentDocument!;
|
||||
|
||||
// TODO: think of lock when edit a node
|
||||
@ -312,7 +320,7 @@ export class BuiltinSimulatorHost implements ISimulatorHost<BuiltinSimulatorProp
|
||||
const checkSelect = (e: MouseEvent) => {
|
||||
doc.removeEventListener('mouseup', checkSelect, true);
|
||||
if (!isShaken(downEvent, e)) {
|
||||
const id = node.id;
|
||||
const { id } = node;
|
||||
designer.activeTracker.track({ node, instance: nodeInst?.instance });
|
||||
if (isMulti && !isRootNode(node) && selection.has(id)) {
|
||||
selection.remove(id);
|
||||
@ -411,12 +419,13 @@ export class BuiltinSimulatorHost implements ISimulatorHost<BuiltinSimulatorProp
|
||||
}
|
||||
|
||||
private disableHovering?: () => void;
|
||||
|
||||
/**
|
||||
* 设置悬停处理
|
||||
*/
|
||||
setupDetecting() {
|
||||
const doc = this.contentDocument!;
|
||||
const detecting = this.document.designer.detecting;
|
||||
const { detecting } = this.document.designer;
|
||||
const hover = (e: MouseEvent) => {
|
||||
if (!detecting.enable) {
|
||||
return;
|
||||
@ -448,6 +457,7 @@ export class BuiltinSimulatorHost implements ISimulatorHost<BuiltinSimulatorProp
|
||||
}
|
||||
|
||||
readonly liveEditing = new LiveEditing();
|
||||
|
||||
setupLiveEditing() {
|
||||
const doc = this.contentDocument!;
|
||||
// cause edit
|
||||
@ -567,6 +577,7 @@ export class BuiltinSimulatorHost implements ISimulatorHost<BuiltinSimulatorProp
|
||||
}
|
||||
|
||||
@obx.val private instancesMap = new Map<string, ComponentInstance[]>();
|
||||
|
||||
setInstance(id: string, instances: ComponentInstance[] | null) {
|
||||
if (instances == null) {
|
||||
this.instancesMap.delete(id);
|
||||
@ -719,6 +730,7 @@ export class BuiltinSimulatorHost implements ISimulatorHost<BuiltinSimulatorProp
|
||||
}
|
||||
|
||||
private tryScrollAgain: number | null = null;
|
||||
|
||||
/**
|
||||
* @see ISimulator
|
||||
*/
|
||||
@ -744,7 +756,7 @@ export class BuiltinSimulatorHost implements ISimulatorHost<BuiltinSimulatorProp
|
||||
if (y < bounds.top || y > bounds.bottom) {
|
||||
scroll = true;
|
||||
}
|
||||
}*/
|
||||
} */
|
||||
} else {
|
||||
/*
|
||||
const rect = this.document.computeRect(node);
|
||||
@ -768,7 +780,7 @@ export class BuiltinSimulatorHost implements ISimulatorHost<BuiltinSimulatorProp
|
||||
if (rect.width > width ? rect.left > right || rect.right < left : rect.left < left || rect.right > right) {
|
||||
opt.left = Math.min(rect.left + rect.width / 2 + sl - left - width / 2, scrollWidth - width);
|
||||
scroll = true;
|
||||
}*/
|
||||
} */
|
||||
}
|
||||
|
||||
if (scroll && this.scroller) {
|
||||
@ -783,18 +795,21 @@ export class BuiltinSimulatorHost implements ISimulatorHost<BuiltinSimulatorProp
|
||||
setNativeSelection(enableFlag: boolean) {
|
||||
this.renderer?.setNativeSelection(enableFlag);
|
||||
}
|
||||
|
||||
/**
|
||||
* @see ISimulator
|
||||
*/
|
||||
setDraggingState(state: boolean) {
|
||||
this.renderer?.setDraggingState(state);
|
||||
}
|
||||
|
||||
/**
|
||||
* @see ISimulator
|
||||
*/
|
||||
setCopyState(state: boolean) {
|
||||
this.renderer?.setCopyState(state);
|
||||
}
|
||||
|
||||
/**
|
||||
* @see ISimulator
|
||||
*/
|
||||
@ -803,6 +818,7 @@ export class BuiltinSimulatorHost implements ISimulatorHost<BuiltinSimulatorProp
|
||||
}
|
||||
|
||||
private _sensorAvailable = true;
|
||||
|
||||
/**
|
||||
* @see ISensor
|
||||
*/
|
||||
@ -851,6 +867,7 @@ export class BuiltinSimulatorHost implements ISimulatorHost<BuiltinSimulatorProp
|
||||
}
|
||||
|
||||
private sensing = false;
|
||||
|
||||
/**
|
||||
* @see ISensor
|
||||
*/
|
||||
@ -905,7 +922,7 @@ export class BuiltinSimulatorHost implements ISimulatorHost<BuiltinSimulatorProp
|
||||
return null;
|
||||
}
|
||||
|
||||
const children = container.children;
|
||||
const { children } = container;
|
||||
|
||||
const detail: LocationChildrenDetail = {
|
||||
type: LocationDetailType.Children,
|
||||
@ -916,7 +933,7 @@ export class BuiltinSimulatorHost implements ISimulatorHost<BuiltinSimulatorProp
|
||||
const locationData = {
|
||||
target: container,
|
||||
detail,
|
||||
source: 'simulator' + this.document.id,
|
||||
source: `simulator${ this.document.id}`,
|
||||
event: e,
|
||||
};
|
||||
|
||||
@ -934,7 +951,7 @@ export class BuiltinSimulatorHost implements ISimulatorHost<BuiltinSimulatorProp
|
||||
index: 0,
|
||||
valid: true,
|
||||
},
|
||||
source: 'simulator' + this.document.id,
|
||||
source: `simulator${ this.document.id}`,
|
||||
event: e,
|
||||
});
|
||||
}
|
||||
@ -1014,7 +1031,7 @@ export class BuiltinSimulatorHost implements ISimulatorHost<BuiltinSimulatorProp
|
||||
if (!row && nearDistance !== 0) {
|
||||
const edgeDistance = distanceToEdge(e as any, edge);
|
||||
if (edgeDistance.distance < nearDistance!) {
|
||||
const nearAfter = edgeDistance.nearAfter;
|
||||
const { nearAfter } = edgeDistance;
|
||||
if (minTop == null) {
|
||||
minTop = edge.top;
|
||||
}
|
||||
@ -1077,7 +1094,7 @@ export class BuiltinSimulatorHost implements ISimulatorHost<BuiltinSimulatorProp
|
||||
// TODO: renderengine support pointerEvents: none for acceleration
|
||||
const drillDownExcludes = new Set<Node>();
|
||||
if (isDragNodeObject(dragObject)) {
|
||||
const nodes = dragObject.nodes;
|
||||
const { nodes } = dragObject;
|
||||
let i = nodes.length;
|
||||
let p: any = container;
|
||||
while (i-- > 0) {
|
||||
@ -1139,7 +1156,7 @@ export class BuiltinSimulatorHost implements ISimulatorHost<BuiltinSimulatorProp
|
||||
container = upward;
|
||||
upward = null;
|
||||
}
|
||||
}*/
|
||||
} */
|
||||
container = res;
|
||||
upward = null;
|
||||
}
|
||||
|
||||
@ -34,13 +34,15 @@ function addLiveEditingSpecificRule(rule: SpecificRule) {
|
||||
|
||||
export class LiveEditing {
|
||||
static addLiveEditingSpecificRule = addLiveEditingSpecificRule;
|
||||
|
||||
static addLiveEditingSaveHandler = addLiveEditingSaveHandler;
|
||||
|
||||
@obx.ref private _editing: Prop | null = null;
|
||||
|
||||
apply(target: EditingTarget) {
|
||||
const { node, event, rootElement } = target;
|
||||
const targetElement = event.target as HTMLElement;
|
||||
const liveTextEditing = node.componentMeta.liveTextEditing;
|
||||
const { liveTextEditing } = node.componentMeta;
|
||||
|
||||
const editor = globalContext.get(Editor);
|
||||
const npm = node?.componentMeta?.npm;
|
||||
@ -64,14 +66,14 @@ export class LiveEditing {
|
||||
return false;
|
||||
}
|
||||
setterPropElement = queryPropElement(rootElement, targetElement, config.selector);
|
||||
return setterPropElement ? true : false;
|
||||
return !!setterPropElement;
|
||||
});
|
||||
propTarget = matched?.propTarget;
|
||||
}
|
||||
} else {
|
||||
specificRules.some((rule) => {
|
||||
matched = rule(target);
|
||||
return matched ? true : false;
|
||||
return !!matched;
|
||||
});
|
||||
if (matched) {
|
||||
propTarget = matched.propTarget;
|
||||
@ -147,8 +149,6 @@ export class LiveEditing {
|
||||
// TODO: process enter | esc events & joint the FocusTracker
|
||||
|
||||
// TODO: upward testing for b/i/a html elements
|
||||
|
||||
|
||||
}
|
||||
|
||||
get editing() {
|
||||
@ -156,7 +156,9 @@ export class LiveEditing {
|
||||
}
|
||||
|
||||
private _dispose?: () => void;
|
||||
|
||||
private _save?: () => void;
|
||||
|
||||
saveAndDispose() {
|
||||
if (this._save) {
|
||||
this._save();
|
||||
|
||||
@ -58,16 +58,19 @@ export default class InstanceNodeSelector extends React.Component<IProps, IState
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
onMouseOver = (node: Node) => (_: any, flag = true) => {
|
||||
if (node && typeof node.hover === 'function') {
|
||||
node.hover(flag);
|
||||
}
|
||||
};
|
||||
|
||||
onMouseOut = (node: Node) => (_: any, flag = false) => {
|
||||
if (node && typeof node.hover === 'function') {
|
||||
node.hover(flag);
|
||||
}
|
||||
};
|
||||
|
||||
renderNodes = (node: Node) => {
|
||||
const nodes = this.state.parentNodes || [];
|
||||
const children = nodes.map((node, key) => {
|
||||
|
||||
@ -21,9 +21,11 @@ export type RendererConsumer<T> = (renderer: BuiltinSimulatorRenderer, data: T)
|
||||
|
||||
export default class ResourceConsumer<T = any> {
|
||||
private emitter = new EventEmitter();
|
||||
|
||||
@obx.ref private _data: T | typeof UNSET = UNSET;
|
||||
|
||||
private _providing?: () => void;
|
||||
|
||||
constructor(provider: () => T, private consumer?: RendererConsumer<T>) {
|
||||
this._providing = autorun(() => {
|
||||
this._data = provider();
|
||||
@ -31,6 +33,7 @@ export default class ResourceConsumer<T = any> {
|
||||
}
|
||||
|
||||
private _consuming?: () => void;
|
||||
|
||||
consume(consumerOrRenderer: BuiltinSimulatorRenderer | ((data: T) => any)) {
|
||||
if (this._consuming) {
|
||||
return;
|
||||
@ -72,6 +75,7 @@ export default class ResourceConsumer<T = any> {
|
||||
}
|
||||
|
||||
private _firstConsumed = false;
|
||||
|
||||
private resovleFirst?: () => void;
|
||||
|
||||
waitFirstConsume(): Promise<any> {
|
||||
|
||||
@ -136,7 +136,7 @@ export function parseProps(component: any): PropConfig[] {
|
||||
Object.keys(propTypes).forEach(key => {
|
||||
const propTypeItem = propTypes[key];
|
||||
const defaultValue = defaultProps[key];
|
||||
const lowcodeType = propTypeItem.lowcodeType;
|
||||
const { lowcodeType } = propTypeItem;
|
||||
if (lowcodeType) {
|
||||
result[key] = {
|
||||
name: key,
|
||||
|
||||
@ -158,7 +158,7 @@ export function joinPath(...segments: string[]) {
|
||||
if (path === '') {
|
||||
path += seg;
|
||||
} else {
|
||||
path += '/' + seg;
|
||||
path += `/${ seg}`;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -4,7 +4,9 @@ import { AutoFit, IViewport } from '../simulator';
|
||||
|
||||
export default class Viewport implements IViewport {
|
||||
@obx.ref private rect?: DOMRect;
|
||||
|
||||
private _bounds?: DOMRect;
|
||||
|
||||
get bounds(): DOMRect {
|
||||
if (this._bounds) {
|
||||
return this._bounds;
|
||||
@ -17,12 +19,13 @@ export default class Viewport implements IViewport {
|
||||
}
|
||||
|
||||
get contentBounds(): DOMRect {
|
||||
const bounds = this.bounds;
|
||||
const scale = this.scale;
|
||||
const { bounds } = this;
|
||||
const { scale } = this;
|
||||
return new DOMRect(0, 0, bounds.width / scale, bounds.height / scale);
|
||||
}
|
||||
|
||||
private viewportElement?: HTMLElement;
|
||||
|
||||
mount(viewportElement: HTMLElement | null) {
|
||||
if (!viewportElement || this.viewportElement === viewportElement) {
|
||||
return;
|
||||
@ -67,7 +70,7 @@ export default class Viewport implements IViewport {
|
||||
}
|
||||
}
|
||||
|
||||
@obx.ref private _scale: number = 1;
|
||||
@obx.ref private _scale = 1;
|
||||
|
||||
/**
|
||||
* 缩放比例
|
||||
@ -87,6 +90,7 @@ export default class Viewport implements IViewport {
|
||||
}
|
||||
|
||||
@obx.ref private _contentWidth: number | AutoFit = AutoFit;
|
||||
|
||||
@obx.ref private _contentHeight: number | AutoFit = AutoFit;
|
||||
|
||||
@computed get contentHeight(): number | AutoFit {
|
||||
@ -106,15 +110,19 @@ export default class Viewport implements IViewport {
|
||||
}
|
||||
|
||||
@obx.ref private _scrollX = 0;
|
||||
|
||||
@obx.ref private _scrollY = 0;
|
||||
|
||||
get scrollX() {
|
||||
return this._scrollX;
|
||||
}
|
||||
|
||||
get scrollY() {
|
||||
return this._scrollY;
|
||||
}
|
||||
|
||||
private _scrollTarget?: ScrollTarget;
|
||||
|
||||
/**
|
||||
* 滚动对象
|
||||
*/
|
||||
@ -123,6 +131,7 @@ export default class Viewport implements IViewport {
|
||||
}
|
||||
|
||||
@obx private _scrolling = false;
|
||||
|
||||
get scrolling(): boolean {
|
||||
return this._scrolling;
|
||||
}
|
||||
|
||||
@ -63,45 +63,62 @@ function buildFilter(rule?: string | string[] | RegExp | NestingFilter) {
|
||||
|
||||
export class ComponentMeta {
|
||||
readonly isComponentMeta = true;
|
||||
|
||||
private _npm?: NpmInfo;
|
||||
|
||||
get npm() {
|
||||
return this._npm;
|
||||
}
|
||||
|
||||
private _componentName?: string;
|
||||
|
||||
get componentName(): string {
|
||||
return this._componentName!;
|
||||
}
|
||||
|
||||
private _isContainer?: boolean;
|
||||
|
||||
get isContainer(): boolean {
|
||||
return this._isContainer! || this.isRootComponent();
|
||||
}
|
||||
|
||||
private _isModal?: boolean;
|
||||
|
||||
get isModal(): boolean {
|
||||
return this._isModal!;
|
||||
}
|
||||
|
||||
private _descriptor?: string;
|
||||
|
||||
get descriptor(): string | undefined {
|
||||
return this._descriptor;
|
||||
}
|
||||
|
||||
private _rootSelector?: string;
|
||||
|
||||
get rootSelector(): string | undefined {
|
||||
return this._rootSelector;
|
||||
}
|
||||
|
||||
private _transformedMetadata?: TransformedComponentMetadata;
|
||||
|
||||
get configure() {
|
||||
const config = this._transformedMetadata?.configure;
|
||||
return config?.combined || config?.props || [];
|
||||
}
|
||||
|
||||
private _liveTextEditing?: LiveTextEditingConfig[];
|
||||
|
||||
get liveTextEditing() {
|
||||
return this._liveTextEditing;
|
||||
}
|
||||
|
||||
private parentWhitelist?: NestingFilter | null;
|
||||
|
||||
private childWhitelist?: NestingFilter | null;
|
||||
|
||||
private _title?: TitleContent;
|
||||
|
||||
get title(): string | I18nData | ReactElement {
|
||||
// TODO: 标记下。这块需要康师傅加一下API,页面正常渲染。
|
||||
// string | i18nData | ReactElement
|
||||
@ -123,6 +140,7 @@ export class ComponentMeta {
|
||||
}
|
||||
|
||||
private _acceptable?: boolean;
|
||||
|
||||
get acceptable(): boolean {
|
||||
return this._acceptable!;
|
||||
}
|
||||
@ -145,7 +163,7 @@ export class ComponentMeta {
|
||||
// 额外转换逻辑
|
||||
this._transformedMetadata = this.transformMetadata(metadata);
|
||||
|
||||
const title = this._transformedMetadata.title;
|
||||
const { title } = this._transformedMetadata;
|
||||
if (title) {
|
||||
this._title =
|
||||
typeof title === 'string'
|
||||
@ -182,8 +200,8 @@ export class ComponentMeta {
|
||||
|
||||
const { component } = configure;
|
||||
if (component) {
|
||||
this._isContainer = component.isContainer ? true : false;
|
||||
this._isModal = component.isModal ? true : false;
|
||||
this._isContainer = !!component.isContainer;
|
||||
this._isModal = !!component.isModal;
|
||||
this._descriptor = component.descriptor;
|
||||
this._rootSelector = component.rootSelector;
|
||||
if (component.nestingRule) {
|
||||
@ -208,7 +226,7 @@ export class ComponentMeta {
|
||||
return result as any;
|
||||
}
|
||||
|
||||
isRootComponent(includeBlock: boolean = true) {
|
||||
isRootComponent(includeBlock = true) {
|
||||
return this.componentName === 'Page' || this.componentName === 'Component' || (includeBlock && this.componentName === 'Block');
|
||||
}
|
||||
|
||||
|
||||
@ -1,6 +1,6 @@
|
||||
import { EventEmitter } from 'events';
|
||||
import { LocationDetail } from './location';
|
||||
import { Node, isNode } from '../document/node/node';
|
||||
import { Node, isNode } from '../document/node/node';
|
||||
import { ComponentInstance } from '../simulator';
|
||||
import { obx } from '@ali/lowcode-editor-core';
|
||||
|
||||
|
||||
@ -107,7 +107,7 @@ hotkey.bind(['command+c', 'ctrl+c', 'command+x', 'ctrl+x'], (e, action) => {
|
||||
let selected = doc.selection.getTopNodes(true);
|
||||
selected = selected.filter((node) => {
|
||||
return node.canPerformAction('copy');
|
||||
})
|
||||
});
|
||||
if (!selected || selected.length < 1) {
|
||||
return;
|
||||
}
|
||||
@ -242,7 +242,6 @@ hotkey.bind(['option+left', 'option+right'], (e, action) => {
|
||||
parent.insertAfter(firstNode, silbing);
|
||||
}
|
||||
firstNode?.select();
|
||||
return;
|
||||
}
|
||||
});
|
||||
|
||||
@ -275,7 +274,6 @@ hotkey.bind(['option+up'], (e, action) => {
|
||||
parent.insertBefore(firstNode, silbing);
|
||||
}
|
||||
firstNode?.select();
|
||||
return;
|
||||
} else {
|
||||
const place = parent.getSuitablePlace(firstNode, null); // upwards
|
||||
if (place) {
|
||||
@ -315,7 +313,6 @@ hotkey.bind(['option+down'], (e, action) => {
|
||||
parent.insertAfter(firstNode, silbing);
|
||||
}
|
||||
firstNode?.select();
|
||||
return;
|
||||
} else {
|
||||
const place = parent.getSuitablePlace(firstNode, null); // upwards
|
||||
if (place) {
|
||||
|
||||
@ -1,5 +1,5 @@
|
||||
function getDataFromPasteEvent(event: ClipboardEvent) {
|
||||
const clipboardData = event.clipboardData;
|
||||
const { clipboardData } = event;
|
||||
if (!clipboardData) {
|
||||
return null;
|
||||
}
|
||||
@ -14,7 +14,7 @@ function getDataFromPasteEvent(event: ClipboardEvent) {
|
||||
return data;
|
||||
} else if (data.componentName) {
|
||||
return {
|
||||
componentsTree: [ data ]
|
||||
componentsTree: [data],
|
||||
};
|
||||
}
|
||||
} catch (error) {
|
||||
@ -34,12 +34,13 @@ function getDataFromPasteEvent(event: ClipboardEvent) {
|
||||
return {
|
||||
code: clipboardData.getData('text/plain'),
|
||||
maps: {},
|
||||
};*/
|
||||
}; */
|
||||
}
|
||||
}
|
||||
|
||||
class Clipboard {
|
||||
private copyPasters: HTMLTextAreaElement[] = [];
|
||||
|
||||
private waitFn?: (data: any, e: ClipboardEvent) => void;
|
||||
|
||||
isCopyPasteEvent(e: Event) {
|
||||
|
||||
@ -24,7 +24,7 @@ export class DesignerView extends Component<DesignerProps & {
|
||||
|
||||
shouldComponentUpdate(nextProps: DesignerProps) {
|
||||
this.designer.setProps(nextProps);
|
||||
const props = this.props;
|
||||
const { props } = this;
|
||||
if (
|
||||
nextProps.className !== props.className ||
|
||||
nextProps.style !== props.style ||
|
||||
@ -40,7 +40,7 @@ export class DesignerView extends Component<DesignerProps & {
|
||||
if (onMount) {
|
||||
onMount(this.designer);
|
||||
}
|
||||
clipboard.injectCopyPaster(document)
|
||||
clipboard.injectCopyPaster(document);
|
||||
this.designer.postEvent('mount', this.designer);
|
||||
}
|
||||
|
||||
|
||||
@ -44,9 +44,13 @@ export interface DesignerProps {
|
||||
|
||||
export class Designer {
|
||||
readonly dragon = new Dragon(this);
|
||||
|
||||
readonly activeTracker = new ActiveTracker();
|
||||
|
||||
readonly detecting = new Detecting();
|
||||
|
||||
readonly project: Project;
|
||||
|
||||
readonly editor: IEditor;
|
||||
|
||||
get currentDocument() {
|
||||
@ -173,7 +177,7 @@ export class Designer {
|
||||
}
|
||||
this.postEvent('selection.change', this.currentSelection);
|
||||
if (this.currentSelection) {
|
||||
const currentSelection = this.currentSelection;
|
||||
const { currentSelection } = this;
|
||||
selectionDispose = currentSelection.onSelectionChange(() => {
|
||||
this.postEvent('selection.change', currentSelection);
|
||||
});
|
||||
@ -187,7 +191,7 @@ export class Designer {
|
||||
}
|
||||
this.postEvent('history.change', this.currentHistory);
|
||||
if (this.currentHistory) {
|
||||
const currentHistory = this.currentHistory;
|
||||
const { currentHistory } = this;
|
||||
historyDispose = currentHistory.onStateChange(() => {
|
||||
this.postEvent('history.change', currentHistory);
|
||||
});
|
||||
@ -217,6 +221,7 @@ export class Designer {
|
||||
get dropLocation() {
|
||||
return this._dropLocation;
|
||||
}
|
||||
|
||||
/**
|
||||
* 创建插入位置,考虑放到 dragon 中
|
||||
*/
|
||||
@ -246,6 +251,7 @@ export class Designer {
|
||||
}
|
||||
|
||||
private oobxList: OffsetObserver[] = [];
|
||||
|
||||
createOffsetObserver(nodeInstance: INodeSelector): OffsetObserver | null {
|
||||
const oobx = createOffsetObserver(nodeInstance);
|
||||
this.clearOobxList();
|
||||
@ -302,6 +308,7 @@ export class Designer {
|
||||
}
|
||||
|
||||
private props?: DesignerProps;
|
||||
|
||||
setProps(nextProps: DesignerProps) {
|
||||
const props = this.props ? { ...this.props, ...nextProps } : nextProps;
|
||||
if (this.props) {
|
||||
@ -380,6 +387,7 @@ export class Designer {
|
||||
}
|
||||
|
||||
@obx.val private _componentMetasMap = new Map<string, ComponentMeta>();
|
||||
|
||||
private _lostComponentMetasMap = new Map<string, ComponentMeta>();
|
||||
|
||||
private buildComponentMetasMap(metas: ComponentMetadata[]) {
|
||||
@ -451,6 +459,7 @@ export class Designer {
|
||||
}
|
||||
|
||||
private propsReducers = new Map<TransformStage, PropsReducer[]>();
|
||||
|
||||
transformProps(props: CompositeObject | PropsList, node: Node, stage: TransformStage) {
|
||||
if (Array.isArray(props)) {
|
||||
// current not support, make this future
|
||||
@ -464,7 +473,7 @@ export class Designer {
|
||||
|
||||
return reducers.reduce((xprops, reducer) => {
|
||||
try {
|
||||
return reducer(xprops, node)
|
||||
return reducer(xprops, node);
|
||||
} catch (e) {
|
||||
// todo: add log
|
||||
console.warn(e);
|
||||
|
||||
@ -3,18 +3,22 @@ import { Node, DocumentModel } from '../document';
|
||||
|
||||
export class Detecting {
|
||||
@obx.ref private _enable = true;
|
||||
|
||||
get enable() {
|
||||
return this._enable;
|
||||
}
|
||||
|
||||
set enable(flag: boolean) {
|
||||
this._enable = flag;
|
||||
if (!flag) {
|
||||
this._current = null;
|
||||
}
|
||||
}
|
||||
|
||||
@obx.ref xRayMode = false;
|
||||
|
||||
@obx.ref private _current: Node | null = null;
|
||||
|
||||
get current() {
|
||||
return this._current;
|
||||
}
|
||||
|
||||
@ -9,9 +9,13 @@ type offBinding = () => any;
|
||||
@observer
|
||||
export default class DragGhost extends Component<{ designer: Designer }> {
|
||||
private dispose: offBinding[] = [];
|
||||
|
||||
@obx.ref private dragObject: DragObject | null = null;
|
||||
|
||||
@obx.ref private x = 0;
|
||||
|
||||
@obx.ref private y = 0;
|
||||
|
||||
private dragon = this.props.designer.dragon;
|
||||
|
||||
constructor(props: any) {
|
||||
@ -48,7 +52,7 @@ export default class DragGhost extends Component<{ designer: Designer }> {
|
||||
}
|
||||
|
||||
renderGhostGroup() {
|
||||
const dragObject = this.dragObject;
|
||||
const { dragObject } = this;
|
||||
if (isDragNodeObject(dragObject)) {
|
||||
return dragObject.nodes.map(node => {
|
||||
const ghost = (
|
||||
|
||||
@ -191,11 +191,13 @@ export class Dragon {
|
||||
* current actived sensor, 可用于感应区高亮
|
||||
*/
|
||||
@obx.ref private _activeSensor: ISensor | undefined;
|
||||
|
||||
get activeSensor(): ISensor | undefined {
|
||||
return this._activeSensor;
|
||||
}
|
||||
|
||||
@obx.ref private _dragging = false;
|
||||
|
||||
get dragging(): boolean {
|
||||
return this._dragging;
|
||||
}
|
||||
@ -238,7 +240,7 @@ export class Dragon {
|
||||
* @param boostEvent 拖拽初始时事件
|
||||
*/
|
||||
boost(dragObject: DragObject, boostEvent: MouseEvent | DragEvent) {
|
||||
const designer = this.designer;
|
||||
const { designer } = this;
|
||||
const masterSensors = this.getMasterSensors();
|
||||
const handleEvents = makeEventsHandler(boostEvent, masterSensors);
|
||||
const newBie = !isDragNodeObject(dragObject);
|
||||
|
||||
@ -1,4 +1,5 @@
|
||||
import './builtin-hotkey';
|
||||
|
||||
export * from './designer';
|
||||
export * from './designer-view';
|
||||
export * from './dragon';
|
||||
|
||||
@ -127,9 +127,13 @@ export function getWindow(elem: Element | Document): Window {
|
||||
|
||||
export class DropLocation {
|
||||
readonly target: ParentalNode;
|
||||
|
||||
readonly detail: LocationDetail;
|
||||
|
||||
readonly event: LocateEvent;
|
||||
|
||||
readonly source: string;
|
||||
|
||||
get document(): DocumentModel {
|
||||
return this.target.document;
|
||||
}
|
||||
|
||||
@ -7,14 +7,23 @@ export class OffsetObserver {
|
||||
readonly id = uniqueId('oobx');
|
||||
|
||||
private lastOffsetLeft?: number;
|
||||
|
||||
private lastOffsetTop?: number;
|
||||
|
||||
private lastOffsetHeight?: number;
|
||||
|
||||
private lastOffsetWidth?: number;
|
||||
|
||||
@obx private _height = 0;
|
||||
|
||||
@obx private _width = 0;
|
||||
|
||||
@obx private _left = 0;
|
||||
|
||||
@obx private _top = 0;
|
||||
|
||||
@obx private _right = 0;
|
||||
|
||||
@obx private _bottom = 0;
|
||||
|
||||
@computed get height() {
|
||||
@ -42,6 +51,7 @@ export class OffsetObserver {
|
||||
}
|
||||
|
||||
@obx hasOffset = false;
|
||||
|
||||
@computed get offsetLeft() {
|
||||
if (this.isRoot) {
|
||||
return this.viewport.scrollX * this.scale;
|
||||
@ -51,6 +61,7 @@ export class OffsetObserver {
|
||||
}
|
||||
return this.lastOffsetLeft;
|
||||
}
|
||||
|
||||
@computed get offsetTop() {
|
||||
if (this.isRoot) {
|
||||
return this.viewport.scrollY * this.scale;
|
||||
@ -60,12 +71,14 @@ export class OffsetObserver {
|
||||
}
|
||||
return this.lastOffsetTop;
|
||||
}
|
||||
|
||||
@computed get offsetHeight() {
|
||||
if (!this.viewport.scrolling || this.lastOffsetHeight == null) {
|
||||
this.lastOffsetHeight = this.isRoot ? this.viewport.height : this.height;
|
||||
}
|
||||
return this.lastOffsetHeight;
|
||||
}
|
||||
|
||||
@computed get offsetWidth() {
|
||||
if (!this.viewport.scrolling || this.lastOffsetWidth == null) {
|
||||
this.lastOffsetWidth = this.isRoot ? this.viewport.width : this.width;
|
||||
@ -78,8 +91,11 @@ export class OffsetObserver {
|
||||
}
|
||||
|
||||
private pid: number | undefined;
|
||||
|
||||
readonly viewport: IViewport;
|
||||
|
||||
private isRoot: boolean;
|
||||
|
||||
readonly node: Node;
|
||||
|
||||
readonly compute: () => void;
|
||||
@ -109,16 +125,14 @@ export class OffsetObserver {
|
||||
|
||||
if (!rect) {
|
||||
this.hasOffset = false;
|
||||
} else {
|
||||
if (!this.viewport.scrolling || !this.hasOffset) {
|
||||
this._height = rect.height;
|
||||
this._width = rect.width;
|
||||
this._left = rect.left;
|
||||
this._top = rect.top;
|
||||
this._right = rect.right;
|
||||
this._bottom = rect.bottom;
|
||||
this.hasOffset = true;
|
||||
}
|
||||
} else if (!this.viewport.scrolling || !this.hasOffset) {
|
||||
this._height = rect.height;
|
||||
this._width = rect.width;
|
||||
this._left = rect.left;
|
||||
this._top = rect.top;
|
||||
this._right = rect.right;
|
||||
this._bottom = rect.bottom;
|
||||
this.hasOffset = true;
|
||||
}
|
||||
this.pid = pid = (window as any).requestIdleCallback(compute);
|
||||
};
|
||||
|
||||
@ -4,9 +4,11 @@ export class ScrollTarget {
|
||||
get left() {
|
||||
return 'scrollX' in this.target ? this.target.scrollX : this.target.scrollLeft;
|
||||
}
|
||||
|
||||
get top() {
|
||||
return 'scrollY' in this.target ? this.target.scrollY : this.target.scrollTop;
|
||||
}
|
||||
|
||||
scrollTo(options: { left?: number; top?: number }) {
|
||||
this.target.scrollTo(options);
|
||||
}
|
||||
@ -24,6 +26,7 @@ export class ScrollTarget {
|
||||
}
|
||||
|
||||
private doe?: HTMLElement;
|
||||
|
||||
constructor(private target: Window | Element) {
|
||||
if (isWindow(target)) {
|
||||
this.doe = target.document.documentElement;
|
||||
@ -67,14 +70,14 @@ export class Scroller {
|
||||
scrollTo(options: { left?: number; top?: number }) {
|
||||
this.cancel();
|
||||
|
||||
const scrollTarget = this.scrollTarget;
|
||||
const { scrollTarget } = this;
|
||||
if (!scrollTarget) {
|
||||
return;
|
||||
}
|
||||
|
||||
let pid: number;
|
||||
const left = scrollTarget.left;
|
||||
const top = scrollTarget.top;
|
||||
const { left } = scrollTarget;
|
||||
const { top } = scrollTarget;
|
||||
const end = () => {
|
||||
this.cancel();
|
||||
};
|
||||
@ -119,7 +122,7 @@ export class Scroller {
|
||||
this.cancel();
|
||||
|
||||
const { bounds, scale = 1 } = this.scrollable;
|
||||
const scrollTarget = this.scrollTarget;
|
||||
const { scrollTarget } = this;
|
||||
if (!scrollTarget || !bounds) {
|
||||
return;
|
||||
}
|
||||
|
||||
@ -19,29 +19,37 @@ function getSettingFieldCollectorKey(parent: SettingEntry, config: FieldConfig)
|
||||
|
||||
export class SettingField extends SettingPropEntry implements SettingEntry {
|
||||
readonly isSettingField = true;
|
||||
|
||||
readonly isRequired: boolean;
|
||||
|
||||
readonly transducer: Transducer;
|
||||
|
||||
private _config: FieldConfig;
|
||||
|
||||
extraProps: FieldExtraProps;
|
||||
|
||||
// ==== dynamic properties ====
|
||||
private _title?: TitleContent;
|
||||
|
||||
get title() {
|
||||
// FIXME! intl
|
||||
return this._title || (typeof this.name === 'number' ? `项目 ${this.name}` : this.name);
|
||||
}
|
||||
|
||||
private _setter?: SetterType | DynamicSetter;
|
||||
|
||||
@computed get setter(): SetterType | null {
|
||||
if (!this._setter) {
|
||||
return null;
|
||||
}
|
||||
if (isDynamicSetter(this._setter)) {
|
||||
return this._setter.call(this,this);
|
||||
return this._setter.call(this, this);
|
||||
}
|
||||
return this._setter;
|
||||
}
|
||||
|
||||
@obx.ref private _expanded = true;
|
||||
|
||||
get expanded(): boolean {
|
||||
return this._expanded;
|
||||
}
|
||||
@ -62,7 +70,7 @@ export class SettingField extends SettingPropEntry implements SettingEntry {
|
||||
...extraProps,
|
||||
};
|
||||
this.isRequired = config.isRequired || (setter as any)?.isRequired;
|
||||
this._expanded = extraProps?.defaultCollapsed ? false : true;
|
||||
this._expanded = !extraProps?.defaultCollapsed;
|
||||
|
||||
// initial items
|
||||
if (items && items.length > 0) {
|
||||
|
||||
@ -10,24 +10,36 @@ import { EventEmitter } from 'events';
|
||||
export class SettingPropEntry implements SettingEntry {
|
||||
// === static properties ===
|
||||
readonly editor: IEditor;
|
||||
|
||||
readonly isSameComponent: boolean;
|
||||
|
||||
readonly isMultiple: boolean;
|
||||
|
||||
readonly isSingle: boolean;
|
||||
|
||||
readonly nodes: Node[];
|
||||
|
||||
readonly componentMeta: ComponentMeta | null;
|
||||
|
||||
readonly designer: Designer;
|
||||
|
||||
readonly top: SettingEntry;
|
||||
|
||||
readonly isGroup: boolean;
|
||||
|
||||
readonly type: 'field' | 'group';
|
||||
|
||||
readonly id = uniqueId('entry');
|
||||
|
||||
readonly emitter = new EventEmitter();
|
||||
|
||||
// ==== dynamic properties ====
|
||||
@obx.ref private _name: string | number;
|
||||
|
||||
get name() {
|
||||
return this._name;
|
||||
}
|
||||
|
||||
@computed get path() {
|
||||
const path = this.parent.path.slice();
|
||||
if (this.type === 'field') {
|
||||
@ -133,7 +145,7 @@ export class SettingPropEntry implements SettingEntry {
|
||||
* 获取当前属性值
|
||||
*/
|
||||
@computed getValue(): any {
|
||||
let val: any = undefined;
|
||||
let val: any;
|
||||
if (this.type === 'field') {
|
||||
val = this.parent.getPropValue(this.name);
|
||||
}
|
||||
@ -271,6 +283,7 @@ export class SettingPropEntry implements SettingEntry {
|
||||
isIgnore() {
|
||||
return false;
|
||||
}
|
||||
|
||||
/*
|
||||
getConfig<K extends keyof IPropConfig>(configName?: K): IPropConfig[K] | IPropConfig {
|
||||
if (configName) {
|
||||
@ -287,6 +300,7 @@ export class SettingPropEntry implements SettingEntry {
|
||||
}
|
||||
return '';
|
||||
}
|
||||
|
||||
setVariableValue(value: string) {
|
||||
const v = this.getValue();
|
||||
this.setValue({
|
||||
@ -295,6 +309,7 @@ export class SettingPropEntry implements SettingEntry {
|
||||
mock: isJSExpression(v) ? v.mock : v,
|
||||
});
|
||||
}
|
||||
|
||||
setUseVariable(flag: boolean) {
|
||||
if (this.isUseVariable() === flag) {
|
||||
return;
|
||||
@ -310,12 +325,15 @@ export class SettingPropEntry implements SettingEntry {
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
isUseVariable() {
|
||||
return isJSExpression(this.getValue());
|
||||
}
|
||||
|
||||
get useVariable() {
|
||||
return this.isUseVariable();
|
||||
}
|
||||
|
||||
getMockOrValue() {
|
||||
const v = this.getValue();
|
||||
if (isJSExpression(v)) {
|
||||
|
||||
@ -17,12 +17,19 @@ function generateSessionId(nodes: Node[]) {
|
||||
|
||||
export class SettingTopEntry implements SettingEntry {
|
||||
private emitter = new EventEmitter();
|
||||
|
||||
private _items: Array<SettingField | CustomView> = [];
|
||||
|
||||
private _componentMeta: ComponentMeta | null = null;
|
||||
private _isSame: boolean = true;
|
||||
|
||||
private _isSame = true;
|
||||
|
||||
private _settingFieldMap: { [prop: string]: SettingField } = {};
|
||||
|
||||
readonly path = [];
|
||||
|
||||
readonly top = this;
|
||||
|
||||
readonly parent = this;
|
||||
|
||||
get componentMeta() {
|
||||
@ -55,7 +62,9 @@ export class SettingTopEntry implements SettingEntry {
|
||||
}
|
||||
|
||||
readonly id: string;
|
||||
|
||||
readonly first: Node;
|
||||
|
||||
readonly designer: Designer;
|
||||
|
||||
constructor(readonly editor: IEditor, readonly nodes: Node[]) {
|
||||
@ -75,7 +84,7 @@ export class SettingTopEntry implements SettingEntry {
|
||||
|
||||
private setupComponentMeta() {
|
||||
// todo: enhance compile a temp configure.compiled
|
||||
const first = this.first;
|
||||
const { first } = this;
|
||||
const meta = first.componentMeta;
|
||||
const l = this.nodes.length;
|
||||
let theSame = true;
|
||||
@ -100,7 +109,7 @@ export class SettingTopEntry implements SettingEntry {
|
||||
const settingFieldMap: { [prop: string]: SettingField } = {};
|
||||
const settingFieldCollector = (name: string | number, field: SettingField) => {
|
||||
settingFieldMap[name] = field;
|
||||
}
|
||||
};
|
||||
this._items = this.componentMeta.configure.map((item) => {
|
||||
if (isCustomView(item)) {
|
||||
return item;
|
||||
@ -209,18 +218,23 @@ export class SettingTopEntry implements SettingEntry {
|
||||
getStatus() {
|
||||
|
||||
}
|
||||
|
||||
setStatus() {
|
||||
|
||||
}
|
||||
|
||||
getChildren() {
|
||||
// this.nodes.map()
|
||||
}
|
||||
|
||||
getDOMNode() {
|
||||
|
||||
}
|
||||
|
||||
getId() {
|
||||
return this.id;
|
||||
}
|
||||
|
||||
getPage() {
|
||||
return this.first.document;
|
||||
}
|
||||
@ -231,6 +245,7 @@ export class SettingTopEntry implements SettingEntry {
|
||||
get node() {
|
||||
return this.getNode();
|
||||
}
|
||||
|
||||
getNode() {
|
||||
return this.nodes[0];
|
||||
}
|
||||
|
||||
@ -8,9 +8,9 @@ import { isDragNodeDataObject, DragNodeObject, DragNodeDataObject, DropLocation
|
||||
import { Node, insertChildren, insertChild, isNode, RootNode, ParentalNode } from './node/node';
|
||||
import { Selection } from './selection';
|
||||
import { History } from './history';
|
||||
import { TransformStage } from './node';
|
||||
import { TransformStage, ModalNodesManager } from './node';
|
||||
import { uniqueId } from '@ali/lowcode-utils';
|
||||
import { ModalNodesManager } from './node';
|
||||
|
||||
|
||||
export type GetDataType<T, NodeType> = T extends undefined
|
||||
? NodeType extends {
|
||||
@ -34,28 +34,37 @@ export class DocumentModel {
|
||||
* 根节点 类型有:Page/Component/Block
|
||||
*/
|
||||
rootNode: RootNode | null;
|
||||
|
||||
/**
|
||||
* 文档编号
|
||||
*/
|
||||
id: string = uniqueId('doc');
|
||||
|
||||
/**
|
||||
* 选区控制
|
||||
*/
|
||||
readonly selection: Selection = new Selection(this);
|
||||
|
||||
/**
|
||||
* 操作记录控制
|
||||
*/
|
||||
readonly history: History;
|
||||
|
||||
/**
|
||||
* 模态节点管理
|
||||
*/
|
||||
readonly modalNodesManager: ModalNodesManager;
|
||||
|
||||
private _nodesMap = new Map<string, Node>();
|
||||
|
||||
@obx.val private nodes = new Set<Node>();
|
||||
|
||||
private seqId = 0;
|
||||
|
||||
private _simulator?: ISimulatorHost;
|
||||
|
||||
private emitter: EventEmitter;
|
||||
|
||||
private rootNodeVisitorMap: { [visitorName: string]: any } = {};
|
||||
|
||||
/**
|
||||
@ -83,7 +92,9 @@ export class DocumentModel {
|
||||
}
|
||||
|
||||
private _modalNode?: ParentalNode;
|
||||
|
||||
private _blank?: boolean;
|
||||
|
||||
get modalNode() {
|
||||
return this._modalNode;
|
||||
}
|
||||
@ -93,6 +104,7 @@ export class DocumentModel {
|
||||
}
|
||||
|
||||
private inited = false;
|
||||
|
||||
constructor(readonly project: Project, schema?: RootSchema) {
|
||||
/*
|
||||
// TODO
|
||||
@ -128,9 +140,11 @@ export class DocumentModel {
|
||||
}
|
||||
|
||||
@obx.val private willPurgeSpace: Node[] = [];
|
||||
|
||||
addWillPurge(node: Node) {
|
||||
this.willPurgeSpace.push(node);
|
||||
}
|
||||
|
||||
removeWillPurge(node: Node) {
|
||||
const i = this.willPurgeSpace.indexOf(node);
|
||||
if (i > -1) {
|
||||
@ -150,8 +164,8 @@ export class DocumentModel {
|
||||
nextId() {
|
||||
let id;
|
||||
do {
|
||||
id = 'node_' + (this.id.slice(-10) + (++this.seqId).toString(36)).toLocaleLowerCase();
|
||||
} while (this.nodesMap.get(id))
|
||||
id = `node_${ (this.id.slice(-10) + (++this.seqId).toString(36)).toLocaleLowerCase()}`;
|
||||
} while (this.nodesMap.get(id));
|
||||
|
||||
return id;
|
||||
}
|
||||
@ -278,6 +292,7 @@ export class DocumentModel {
|
||||
}
|
||||
|
||||
@obx.ref private _dropLocation: DropLocation | null = null;
|
||||
|
||||
/**
|
||||
* 内部方法,请勿调用
|
||||
*/
|
||||
@ -356,7 +371,7 @@ export class DocumentModel {
|
||||
* 提供给模拟器的参数
|
||||
*/
|
||||
@computed get simulatorProps(): object {
|
||||
let simulatorProps = this.designer.simulatorProps;
|
||||
let { simulatorProps } = this.designer;
|
||||
if (typeof simulatorProps === 'function') {
|
||||
simulatorProps = simulatorProps(this);
|
||||
}
|
||||
@ -386,6 +401,7 @@ export class DocumentModel {
|
||||
}
|
||||
|
||||
@obx.ref private _opened = false;
|
||||
|
||||
@obx.ref private _suspensed = false;
|
||||
|
||||
/**
|
||||
@ -526,8 +542,8 @@ export class DocumentModel {
|
||||
const data = {
|
||||
componentsMap: this.getComponentsMap(extraComps),
|
||||
componentsTree: [node],
|
||||
};
|
||||
return data;
|
||||
};
|
||||
return data;
|
||||
}
|
||||
|
||||
getHistory(): History {
|
||||
@ -576,20 +592,21 @@ export class DocumentModel {
|
||||
|
||||
|
||||
acceptRootNodeVisitor(
|
||||
visitorName: string = 'default',
|
||||
visitorFn: (node: RootNode) => any ) {
|
||||
let visitorResult = {};
|
||||
if (!visitorName) {
|
||||
/* tslint:disable no-console */
|
||||
console.warn('Invalid or empty RootNodeVisitor name.');
|
||||
}
|
||||
try {
|
||||
visitorResult = visitorFn.call(this, this.rootNode);
|
||||
this.rootNodeVisitorMap[visitorName] = visitorResult;
|
||||
} catch (e) {
|
||||
console.error('RootNodeVisitor is not valid.');
|
||||
}
|
||||
return visitorResult;
|
||||
visitorName = 'default',
|
||||
visitorFn: (node: RootNode) => any,
|
||||
) {
|
||||
let visitorResult = {};
|
||||
if (!visitorName) {
|
||||
/* tslint:disable no-console */
|
||||
console.warn('Invalid or empty RootNodeVisitor name.');
|
||||
}
|
||||
try {
|
||||
visitorResult = visitorFn.call(this, this.rootNode);
|
||||
this.rootNodeVisitorMap[visitorName] = visitorResult;
|
||||
} catch (e) {
|
||||
console.error('RootNodeVisitor is not valid.');
|
||||
}
|
||||
return visitorResult;
|
||||
}
|
||||
|
||||
getRootNodeVisitor(name: string) {
|
||||
@ -600,7 +617,7 @@ export class DocumentModel {
|
||||
const componentsMap: ComponentMap[] = [];
|
||||
// 组件去重
|
||||
const map: any = {};
|
||||
for (let node of this._nodesMap.values()) {
|
||||
for (const node of this._nodesMap.values()) {
|
||||
const { componentName } = node || {};
|
||||
if (!map[componentName] && node?.componentMeta?.npm?.package) {
|
||||
map[componentName] = true;
|
||||
|
||||
@ -9,9 +9,10 @@ export class DocumentView extends Component<{ document: DocumentModel }> {
|
||||
shouldComponentUpdate() {
|
||||
return false;
|
||||
}
|
||||
|
||||
render() {
|
||||
const { document } = this.props;
|
||||
const simulatorProps = document.simulatorProps;
|
||||
const { simulatorProps } = document;
|
||||
const Simulator = document.designer.simulatorComponent || BuiltinSimulatorHostView;
|
||||
return (
|
||||
<div
|
||||
|
||||
@ -24,10 +24,15 @@ export function setSerialization(serializion: Serialization) {
|
||||
|
||||
export class History {
|
||||
private session: Session;
|
||||
|
||||
private records: Session[];
|
||||
|
||||
private point = 0;
|
||||
|
||||
private emitter = new EventEmitter();
|
||||
|
||||
private obx: Reaction;
|
||||
|
||||
private justWokeup = false;
|
||||
|
||||
constructor(logger: () => any, private redoer: (data: NodeSchema) => void, private timeGap: number = 1000) {
|
||||
@ -147,7 +152,7 @@ export class History {
|
||||
* | modified | redoable | undoable |
|
||||
*/
|
||||
getState(): number {
|
||||
const cursor = this.session.cursor;
|
||||
const { cursor } = this.session;
|
||||
let state = 7;
|
||||
// undoable ?
|
||||
if (cursor <= 0) {
|
||||
@ -190,6 +195,7 @@ export class History {
|
||||
|
||||
class Session {
|
||||
private _data: any;
|
||||
|
||||
private activedTimer: any;
|
||||
|
||||
get data() {
|
||||
|
||||
@ -8,22 +8,29 @@ import { intl } from '../../locale';
|
||||
// if-else-if assoc conditionGroup value, should be the same level, and siblings, need renderEngine support
|
||||
export class ExclusiveGroup {
|
||||
readonly isExclusiveGroup = true;
|
||||
|
||||
readonly id = uniqueId('exclusive');
|
||||
|
||||
@obx.val readonly children: Node[] = [];
|
||||
|
||||
@obx private visibleIndex = 0;
|
||||
|
||||
@computed get document() {
|
||||
return this.visibleNode.document;
|
||||
}
|
||||
|
||||
@computed get zLevel() {
|
||||
return this.visibleNode.zLevel;
|
||||
}
|
||||
|
||||
@computed get length() {
|
||||
return this.children.length;
|
||||
}
|
||||
|
||||
@computed get visibleNode(): Node {
|
||||
return this.children[this.visibleIndex];
|
||||
}
|
||||
|
||||
@computed get firstNode(): Node {
|
||||
return this.children[0]!;
|
||||
}
|
||||
|
||||
@ -21,8 +21,11 @@ export class ModalNodesManager {
|
||||
public willDestroy: any;
|
||||
|
||||
private page: DocumentModel;
|
||||
|
||||
private modalNodes: Node[];
|
||||
|
||||
private nodeRemoveEvents: any;
|
||||
|
||||
private emitter: EventEmitter;
|
||||
|
||||
constructor(page: DocumentModel) {
|
||||
@ -44,8 +47,8 @@ export class ModalNodesManager {
|
||||
public getVisibleModalNode() {
|
||||
const visibleNode = this.modalNodes
|
||||
? this.modalNodes.find((node: Node) => {
|
||||
return node.getVisible();
|
||||
})
|
||||
return node.getVisible();
|
||||
})
|
||||
: null;
|
||||
return visibleNode;
|
||||
}
|
||||
|
||||
@ -7,6 +7,7 @@ import { EventEmitter } from 'events';
|
||||
|
||||
export class NodeChildren {
|
||||
@obx.val private children: Node[];
|
||||
|
||||
private emitter = new EventEmitter();
|
||||
|
||||
constructor(readonly owner: ParentalNode, data: NodeData | NodeData[]) {
|
||||
@ -63,7 +64,7 @@ export class NodeChildren {
|
||||
|
||||
/**
|
||||
* @deprecated
|
||||
* @param nodes
|
||||
* @param nodes
|
||||
*/
|
||||
concat(nodes: Node[]) {
|
||||
return this.children.concat(nodes);
|
||||
@ -107,7 +108,7 @@ export class NodeChildren {
|
||||
}
|
||||
this.emitter.emit('change');
|
||||
if (useMutator) {
|
||||
this.reportModified(node, this.owner, {type: 'remove', removeIndex: i, removeNode: node});
|
||||
this.reportModified(node, this.owner, { type: 'remove', removeIndex: i, removeNode: node });
|
||||
}
|
||||
return false;
|
||||
}
|
||||
@ -116,7 +117,7 @@ export class NodeChildren {
|
||||
* 插入一个节点,返回新长度
|
||||
*/
|
||||
insert(node: Node, at?: number | null, useMutator = true): void {
|
||||
const children = this.children;
|
||||
const { children } = this;
|
||||
let index = at == null || at === -1 ? children.length : at;
|
||||
|
||||
const i = children.indexOf(node);
|
||||
@ -159,7 +160,7 @@ export class NodeChildren {
|
||||
}
|
||||
}
|
||||
if (node.prevSibling && node.nextSibling) {
|
||||
const conditionGroup = node.prevSibling.conditionGroup;
|
||||
const { conditionGroup } = node.prevSibling;
|
||||
// insert at condition group
|
||||
if (conditionGroup && conditionGroup === node.nextSibling.conditionGroup) {
|
||||
node.setConditionGroup(conditionGroup);
|
||||
@ -200,7 +201,7 @@ export class NodeChildren {
|
||||
*/
|
||||
[Symbol.iterator](): { next(): { value: Node } } {
|
||||
let index = 0;
|
||||
const children = this.children;
|
||||
const { children } = this;
|
||||
const length = children.length || 0;
|
||||
return {
|
||||
next() {
|
||||
@ -291,6 +292,7 @@ export class NodeChildren {
|
||||
}
|
||||
|
||||
private purged = false;
|
||||
|
||||
/**
|
||||
* 回收销毁
|
||||
*/
|
||||
|
||||
@ -73,6 +73,7 @@ import { EventEmitter } from 'events';
|
||||
*/
|
||||
export class Node<Schema extends NodeSchema = NodeSchema> {
|
||||
private emitter: EventEmitter;
|
||||
|
||||
/**
|
||||
* 是节点实例
|
||||
*/
|
||||
@ -94,28 +95,35 @@ export class Node<Schema extends NodeSchema = NodeSchema> {
|
||||
* * Slot 插槽节点,无 props,正常 children,有 slotArgs,有指令
|
||||
*/
|
||||
readonly componentName: string;
|
||||
|
||||
/**
|
||||
* 属性抽象
|
||||
*/
|
||||
props: Props;
|
||||
|
||||
protected _children?: NodeChildren;
|
||||
|
||||
/**
|
||||
* @deprecated
|
||||
*/
|
||||
private _addons: { [key: string]: { exportData: () => any; isProp: boolean; } } = {};
|
||||
|
||||
@obx.ref private _parent: ParentalNode | null = null;
|
||||
|
||||
/**
|
||||
* 父级节点
|
||||
*/
|
||||
get parent(): ParentalNode | null {
|
||||
return this._parent;
|
||||
}
|
||||
|
||||
/**
|
||||
* 当前节点子集
|
||||
*/
|
||||
get children(): NodeChildren | null {
|
||||
return this._children || null;
|
||||
}
|
||||
|
||||
/**
|
||||
* 当前节点深度
|
||||
*/
|
||||
@ -162,18 +170,20 @@ export class Node<Schema extends NodeSchema = NodeSchema> {
|
||||
this.setupAutoruns();
|
||||
}
|
||||
|
||||
this.settingEntry = this.document.designer.createSettingEntry([ this ]);
|
||||
this.settingEntry = this.document.designer.createSettingEntry([this]);
|
||||
this.emitter = new EventEmitter();
|
||||
}
|
||||
|
||||
private initProps(props: any): any {
|
||||
return this.document.designer.transformProps(props, this, TransformStage.Init);
|
||||
}
|
||||
|
||||
private upgradeProps(props: any): any {
|
||||
return this.document.designer.transformProps(props, this, TransformStage.Upgrade);
|
||||
}
|
||||
|
||||
private autoruns?: Array<() => void>;
|
||||
|
||||
private setupAutoruns() {
|
||||
const autoruns = this.componentMeta.getMetadata().experimental?.autoruns;
|
||||
if (!autoruns || autoruns.length < 1) {
|
||||
@ -284,6 +294,7 @@ export class Node<Schema extends NodeSchema = NodeSchema> {
|
||||
}
|
||||
|
||||
private _slotFor?: Prop | null = null;
|
||||
|
||||
internalSetSlotFor(slotFor: Prop | null | undefined) {
|
||||
this._slotFor = slotFor;
|
||||
}
|
||||
@ -341,6 +352,7 @@ export class Node<Schema extends NodeSchema = NodeSchema> {
|
||||
}
|
||||
|
||||
@obx.val _slots: Node[] = [];
|
||||
|
||||
@computed hasSlots() {
|
||||
return this._slots.length > 0;
|
||||
}
|
||||
@ -350,6 +362,7 @@ export class Node<Schema extends NodeSchema = NodeSchema> {
|
||||
}
|
||||
|
||||
@obx.ref private _conditionGroup: ExclusiveGroup | null = null;
|
||||
|
||||
get conditionGroup(): ExclusiveGroup | null {
|
||||
return this._conditionGroup;
|
||||
}
|
||||
@ -503,7 +516,7 @@ export class Node<Schema extends NodeSchema = NodeSchema> {
|
||||
* 设置多个属性值,替换原有值
|
||||
*/
|
||||
setProps(props?: PropsMap | PropsList | Props | null) {
|
||||
if(props instanceof Props) {
|
||||
if (props instanceof Props) {
|
||||
this.props = props;
|
||||
return;
|
||||
}
|
||||
@ -527,7 +540,7 @@ export class Node<Schema extends NodeSchema = NodeSchema> {
|
||||
if (!this.parent) {
|
||||
return null;
|
||||
}
|
||||
const index = this.index;
|
||||
const { index } = this;
|
||||
if (index < 0) {
|
||||
return null;
|
||||
}
|
||||
@ -541,7 +554,7 @@ export class Node<Schema extends NodeSchema = NodeSchema> {
|
||||
if (!this.parent) {
|
||||
return null;
|
||||
}
|
||||
const index = this.index;
|
||||
const { index } = this;
|
||||
if (index < 1) {
|
||||
return null;
|
||||
}
|
||||
@ -666,6 +679,7 @@ export class Node<Schema extends NodeSchema = NodeSchema> {
|
||||
slotNode.internalSetParent(this as ParentalNode, true);
|
||||
this._slots.push(slotNode);
|
||||
}
|
||||
|
||||
/**
|
||||
* 当前node对应组件是否已注册可用
|
||||
*/
|
||||
@ -686,12 +700,14 @@ export class Node<Schema extends NodeSchema = NodeSchema> {
|
||||
}
|
||||
|
||||
private purged = false;
|
||||
|
||||
/**
|
||||
* 是否已销毁
|
||||
*/
|
||||
get isPurged() {
|
||||
return this.purged;
|
||||
}
|
||||
|
||||
/**
|
||||
* 销毁
|
||||
*/
|
||||
@ -727,9 +743,11 @@ export class Node<Schema extends NodeSchema = NodeSchema> {
|
||||
isEmpty(): boolean {
|
||||
return this.children ? this.children.isEmpty() : true;
|
||||
}
|
||||
|
||||
getChildren() {
|
||||
return this.children;
|
||||
}
|
||||
|
||||
getComponentName() {
|
||||
return this.componentName;
|
||||
}
|
||||
@ -740,9 +758,11 @@ export class Node<Schema extends NodeSchema = NodeSchema> {
|
||||
insert(node: Node, ref?: Node, useMutator = true) {
|
||||
this.insertAfter(node, ref, useMutator);
|
||||
}
|
||||
|
||||
insertBefore(node: Node, ref?: Node, useMutator = true) {
|
||||
this.children?.insert(node, ref ? ref.index : null, useMutator);
|
||||
}
|
||||
|
||||
insertAfter(node: any, ref?: Node, useMutator = true) {
|
||||
if (!isNode(node)) {
|
||||
if (node.getComponentName) {
|
||||
@ -755,21 +775,27 @@ export class Node<Schema extends NodeSchema = NodeSchema> {
|
||||
}
|
||||
this.children?.insert(node, ref ? ref.index + 1 : null, useMutator);
|
||||
}
|
||||
|
||||
getParent() {
|
||||
return this.parent;
|
||||
}
|
||||
|
||||
getId() {
|
||||
return this.id;
|
||||
}
|
||||
|
||||
getIndex() {
|
||||
return this.index;
|
||||
}
|
||||
|
||||
getNode() {
|
||||
return this;
|
||||
}
|
||||
|
||||
getRoot() {
|
||||
return this.document.rootNode;
|
||||
}
|
||||
|
||||
getProps() {
|
||||
return this.props;
|
||||
}
|
||||
@ -798,6 +824,7 @@ export class Node<Schema extends NodeSchema = NodeSchema> {
|
||||
|
||||
return this.status;
|
||||
}
|
||||
|
||||
/**
|
||||
* @deprecated
|
||||
*/
|
||||
@ -810,6 +837,7 @@ export class Node<Schema extends NodeSchema = NodeSchema> {
|
||||
this.status[field] = flag;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @deprecated
|
||||
*/
|
||||
@ -820,6 +848,7 @@ export class Node<Schema extends NodeSchema = NodeSchema> {
|
||||
}
|
||||
return this.document.simulator?.findDOMNodes(instance)?.[0];
|
||||
}
|
||||
|
||||
/**
|
||||
* @deprecated
|
||||
*/
|
||||
@ -827,6 +856,7 @@ export class Node<Schema extends NodeSchema = NodeSchema> {
|
||||
console.warn('getPage is deprecated, use document instead');
|
||||
return this.document;
|
||||
}
|
||||
|
||||
/**
|
||||
* @deprecated
|
||||
*/
|
||||
@ -839,7 +869,7 @@ export class Node<Schema extends NodeSchema = NodeSchema> {
|
||||
const canDropIn = c.componentMeta?.prototype?.options?.canDropIn;
|
||||
if (typeof canDropIn === 'function') {
|
||||
return canDropIn(node);
|
||||
} else if (typeof canDropIn === 'boolean'){
|
||||
} else if (typeof canDropIn === 'boolean') {
|
||||
return canDropIn;
|
||||
}
|
||||
return true;
|
||||
@ -854,7 +884,7 @@ export class Node<Schema extends NodeSchema = NodeSchema> {
|
||||
if (this.isContainer()) {
|
||||
if (canDropIn === undefined ||
|
||||
(typeof canDropIn === 'boolean' && canDropIn) ||
|
||||
(typeof canDropIn === 'function' && canDropIn(node))){
|
||||
(typeof canDropIn === 'function' && canDropIn(node))) {
|
||||
return { container: this, ref };
|
||||
}
|
||||
}
|
||||
@ -865,6 +895,7 @@ export class Node<Schema extends NodeSchema = NodeSchema> {
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* @deprecated
|
||||
*/
|
||||
@ -875,10 +906,11 @@ export class Node<Schema extends NodeSchema = NodeSchema> {
|
||||
}
|
||||
return this.getExtraProp(key)?.getValue();
|
||||
}
|
||||
|
||||
/**
|
||||
* @deprecated
|
||||
*/
|
||||
registerAddon(key: string, exportData: () => any, isProp: boolean = false) {
|
||||
registerAddon(key: string, exportData: () => any, isProp = false) {
|
||||
// if (this._addons[key]) {
|
||||
// throw new Error(`node addon ${key} exist`);
|
||||
// }
|
||||
|
||||
@ -6,6 +6,7 @@ import { Node } from '../node';
|
||||
export type PendingItem = Prop[];
|
||||
export class PropStash implements IPropParent {
|
||||
@obx.val private space: Set<Prop> = new Set();
|
||||
|
||||
@computed private get maps(): Map<string | number, Prop> {
|
||||
const maps = new Map();
|
||||
if (this.space.size > 0) {
|
||||
@ -15,7 +16,9 @@ export class PropStash implements IPropParent {
|
||||
}
|
||||
return maps;
|
||||
}
|
||||
|
||||
private willPurge: () => void;
|
||||
|
||||
readonly owner: Node;
|
||||
|
||||
constructor(readonly props: Props, write: (item: Prop) => void) {
|
||||
|
||||
@ -20,6 +20,7 @@ export type ValueTypes = 'unset' | 'literal' | 'map' | 'list' | 'expression' | '
|
||||
|
||||
export class Prop implements IPropParent {
|
||||
readonly isProp = true;
|
||||
|
||||
readonly owner: Node;
|
||||
|
||||
/**
|
||||
@ -46,6 +47,7 @@ export class Prop implements IPropParent {
|
||||
readonly id = uniqueId('prop$');
|
||||
|
||||
@obx.ref private _type: ValueTypes = 'unset';
|
||||
|
||||
/**
|
||||
* 属性类型
|
||||
*/
|
||||
@ -131,6 +133,7 @@ export class Prop implements IPropParent {
|
||||
}
|
||||
|
||||
private _code: string | null = null;
|
||||
|
||||
/**
|
||||
* 获得表达式值
|
||||
*/
|
||||
@ -241,9 +244,11 @@ export class Prop implements IPropParent {
|
||||
}
|
||||
|
||||
private _slotNode?: SlotNode;
|
||||
|
||||
get slotNode() {
|
||||
return this._slotNode;
|
||||
}
|
||||
|
||||
setAsSlot(data: JSSlot) {
|
||||
this._type = 'slot';
|
||||
const slotSchema: SlotSchema = {
|
||||
@ -256,7 +261,7 @@ export class Prop implements IPropParent {
|
||||
if (this._slotNode) {
|
||||
this._slotNode.import(slotSchema);
|
||||
} else {
|
||||
const owner = this.props.owner;
|
||||
const { owner } = this.props;
|
||||
this._slotNode = owner.document.createNode<SlotNode>(slotSchema);
|
||||
owner.addSlot(this._slotNode);
|
||||
this._slotNode.internalSetSlotFor(this);
|
||||
@ -305,7 +310,9 @@ export class Prop implements IPropParent {
|
||||
}
|
||||
|
||||
@obx.val private _items: Prop[] | null = null;
|
||||
|
||||
@obx.val private _maps: Map<string | number, Prop> | null = null;
|
||||
|
||||
@computed private get items(): Prop[] | null {
|
||||
let _items: any;
|
||||
untracked(() => {
|
||||
@ -340,6 +347,7 @@ export class Prop implements IPropParent {
|
||||
}
|
||||
return _items;
|
||||
}
|
||||
|
||||
@computed private get maps(): Map<string | number, Prop> | null {
|
||||
if (!this.items) {
|
||||
return null;
|
||||
@ -353,6 +361,7 @@ export class Prop implements IPropParent {
|
||||
* 键值
|
||||
*/
|
||||
@obx key: string | number | undefined;
|
||||
|
||||
/**
|
||||
* 扩展值
|
||||
*/
|
||||
@ -379,7 +388,7 @@ export class Prop implements IPropParent {
|
||||
* 获取某个属性
|
||||
* @param stash 如果不存在,临时获取一个待写入
|
||||
*/
|
||||
get(path: string | number, stash: boolean = true): Prop | null {
|
||||
get(path: string | number, stash = true): Prop | null {
|
||||
const type = this._type;
|
||||
if (type !== 'map' && type !== 'list' && type !== 'unset' && !stash) {
|
||||
return null;
|
||||
@ -521,7 +530,7 @@ export class Prop implements IPropParent {
|
||||
}
|
||||
items[key] = prop;
|
||||
} else if (this.maps) {
|
||||
const maps = this.maps;
|
||||
const { maps } = this;
|
||||
const orig = maps.get(key);
|
||||
if (orig) {
|
||||
// replace
|
||||
@ -556,6 +565,7 @@ export class Prop implements IPropParent {
|
||||
}
|
||||
|
||||
private purged = false;
|
||||
|
||||
/**
|
||||
* 回收销毁
|
||||
*/
|
||||
@ -581,7 +591,7 @@ export class Prop implements IPropParent {
|
||||
*/
|
||||
[Symbol.iterator](): { next(): { value: Prop } } {
|
||||
let index = 0;
|
||||
const items = this.items;
|
||||
const { items } = this;
|
||||
const length = items?.length || 0;
|
||||
return {
|
||||
next() {
|
||||
@ -603,7 +613,7 @@ export class Prop implements IPropParent {
|
||||
* 遍历
|
||||
*/
|
||||
forEach(fn: (item: Prop, key: number | string | undefined) => void): void {
|
||||
const items = this.items;
|
||||
const { items } = this;
|
||||
if (!items) {
|
||||
return;
|
||||
}
|
||||
@ -617,7 +627,7 @@ export class Prop implements IPropParent {
|
||||
* 遍历
|
||||
*/
|
||||
map<T>(fn: (item: Prop, key: number | string | undefined) => T): T[] | null {
|
||||
const items = this.items;
|
||||
const { items } = this;
|
||||
if (!items) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@ -23,7 +23,9 @@ export function getOriginalExtraKey(key: string): string {
|
||||
|
||||
export class Props implements IPropParent {
|
||||
readonly id = uniqueId('props');
|
||||
|
||||
@obx.val private items: Prop[] = [];
|
||||
|
||||
@computed private get maps(): Map<string, Prop> {
|
||||
const maps = new Map();
|
||||
if (this.items.length > 0) {
|
||||
@ -257,7 +259,7 @@ export class Props implements IPropParent {
|
||||
*/
|
||||
[Symbol.iterator](): { next(): { value: Prop } } {
|
||||
let index = 0;
|
||||
const items = this.items;
|
||||
const { items } = this;
|
||||
const length = items.length || 0;
|
||||
return {
|
||||
next() {
|
||||
@ -300,6 +302,7 @@ export class Props implements IPropParent {
|
||||
}
|
||||
|
||||
private purged = false;
|
||||
|
||||
/**
|
||||
* 回收销毁
|
||||
*/
|
||||
|
||||
@ -57,15 +57,15 @@ export function valueToSource(
|
||||
if (value instanceof Map) {
|
||||
return value.size
|
||||
? `${indentString.repeat(indentLevel)}new Map(${valueToSource([...value], {
|
||||
circularReferenceToken,
|
||||
doubleQuote,
|
||||
includeFunctions,
|
||||
includeUndefinedProperties,
|
||||
indentLevel,
|
||||
indentString,
|
||||
lineEnding,
|
||||
visitedObjects: new Set([value, ...visitedObjects]),
|
||||
}).substr(indentLevel * indentString.length)})`
|
||||
circularReferenceToken,
|
||||
doubleQuote,
|
||||
includeFunctions,
|
||||
includeUndefinedProperties,
|
||||
indentLevel,
|
||||
indentString,
|
||||
lineEnding,
|
||||
visitedObjects: new Set([value, ...visitedObjects]),
|
||||
}).substr(indentLevel * indentString.length)})`
|
||||
: `${indentString.repeat(indentLevel)}new Map()`;
|
||||
}
|
||||
|
||||
@ -76,15 +76,15 @@ export function valueToSource(
|
||||
if (value instanceof Set) {
|
||||
return value.size
|
||||
? `${indentString.repeat(indentLevel)}new Set(${valueToSource([...value], {
|
||||
circularReferenceToken,
|
||||
doubleQuote,
|
||||
includeFunctions,
|
||||
includeUndefinedProperties,
|
||||
indentLevel,
|
||||
indentString,
|
||||
lineEnding,
|
||||
visitedObjects: new Set([value, ...visitedObjects]),
|
||||
}).substr(indentLevel * indentString.length)})`
|
||||
circularReferenceToken,
|
||||
doubleQuote,
|
||||
includeFunctions,
|
||||
includeUndefinedProperties,
|
||||
indentLevel,
|
||||
indentString,
|
||||
lineEnding,
|
||||
visitedObjects: new Set([value, ...visitedObjects]),
|
||||
}).substr(indentLevel * indentString.length)})`
|
||||
: `${indentString.repeat(indentLevel)}new Set()`;
|
||||
}
|
||||
|
||||
@ -94,8 +94,7 @@ export function valueToSource(
|
||||
}
|
||||
|
||||
const itemsStayOnTheSameLine = value.every(
|
||||
item =>
|
||||
typeof item === 'object' &&
|
||||
item => typeof item === 'object' &&
|
||||
item &&
|
||||
!(item instanceof Date) &&
|
||||
!(item instanceof Map) &&
|
||||
@ -140,33 +139,33 @@ export function valueToSource(
|
||||
return itemsStayOnTheSameLine
|
||||
? `${indentString.repeat(indentLevel)}[${value.join(', ')}]`
|
||||
: `${indentString.repeat(indentLevel)}[${lineEnding}${value.join(
|
||||
`,${lineEnding}`,
|
||||
)}${lineEnding}${indentString.repeat(indentLevel)}]`;
|
||||
`,${lineEnding}`,
|
||||
)}${lineEnding}${indentString.repeat(indentLevel)}]`;
|
||||
}
|
||||
|
||||
value = Object.keys(value).reduce<string[]>((entries, propertyName) => {
|
||||
const propertyValue = value[propertyName],
|
||||
propertyValueString =
|
||||
const propertyValue = value[propertyName];
|
||||
const propertyValueString =
|
||||
typeof propertyValue !== 'undefined' || includeUndefinedProperties
|
||||
? valueToSource(value[propertyName], {
|
||||
circularReferenceToken,
|
||||
doubleQuote,
|
||||
includeFunctions,
|
||||
includeUndefinedProperties,
|
||||
indentLevel: indentLevel + 1,
|
||||
indentString,
|
||||
lineEnding,
|
||||
visitedObjects: new Set([value, ...visitedObjects]),
|
||||
})
|
||||
circularReferenceToken,
|
||||
doubleQuote,
|
||||
includeFunctions,
|
||||
includeUndefinedProperties,
|
||||
indentLevel: indentLevel + 1,
|
||||
indentString,
|
||||
lineEnding,
|
||||
visitedObjects: new Set([value, ...visitedObjects]),
|
||||
})
|
||||
: null;
|
||||
|
||||
if (propertyValueString) {
|
||||
const quotedPropertyName = propertyNameRequiresQuotes(propertyName)
|
||||
? quoteString(propertyName, {
|
||||
doubleQuote,
|
||||
})
|
||||
: propertyName,
|
||||
trimmedPropertyValueString = propertyValueString.substr((indentLevel + 1) * indentString.length);
|
||||
? quoteString(propertyName, {
|
||||
doubleQuote,
|
||||
})
|
||||
: propertyName;
|
||||
const trimmedPropertyValueString = propertyValueString.substr((indentLevel + 1) * indentString.length);
|
||||
|
||||
if (typeof propertyValue === 'function' && trimmedPropertyValueString.startsWith(`${propertyName}()`)) {
|
||||
entries.push(
|
||||
@ -184,8 +183,8 @@ export function valueToSource(
|
||||
|
||||
return value.length
|
||||
? `${indentString.repeat(indentLevel)}{${lineEnding}${value.join(
|
||||
`,${lineEnding}`,
|
||||
)}${lineEnding}${indentString.repeat(indentLevel)}}`
|
||||
`,${lineEnding}`,
|
||||
)}${lineEnding}${indentString.repeat(indentLevel)}}`
|
||||
: `${indentString.repeat(indentLevel)}{}`;
|
||||
case 'string':
|
||||
return `${indentString.repeat(indentLevel)}${quoteString(value, {
|
||||
|
||||
@ -5,7 +5,9 @@ import { DocumentModel } from './document-model';
|
||||
|
||||
export class Selection {
|
||||
private emitter = new EventEmitter();
|
||||
|
||||
@obx.val private _selected: string[] = [];
|
||||
|
||||
/**
|
||||
* 选中的节点 id
|
||||
*/
|
||||
|
||||
@ -1,9 +1,9 @@
|
||||
import { SVGIcon, IconProps } from "@ali/lowcode-utils";
|
||||
import { SVGIcon, IconProps } from '@ali/lowcode-utils';
|
||||
|
||||
export function IconClone(props: IconProps) {
|
||||
return (
|
||||
<SVGIcon viewBox="0 0 1024 1024" {...props}>
|
||||
<path d="M192 256.16C192 220.736 220.704 192 256.16 192h639.68C931.264 192 960 220.704 960 256.16v639.68A64.16 64.16 0 0 1 895.84 960H256.16A64.16 64.16 0 0 1 192 895.84V256.16z m64 31.584v576.512a32 32 0 0 0 31.744 31.744h576.512a32 32 0 0 0 31.744-31.744V287.744A32 32 0 0 0 864.256 256H287.744A32 32 0 0 0 256 287.744zM288 192v64h64V192H288z m128 0v64h64V192h-64z m128 0v64h64V192h-64z m128 0v64h64V192h-64z m128 0v64h64V192h-64z m96 96v64h64V288h-64z m0 128v64h64v-64h-64z m0 128v64h64v-64h-64z m0 128v64h64v-64h-64z m0 128v64h64v-64h-64z m-96 96v64h64v-64h-64z m-128 0v64h64v-64h-64z m-128 0v64h64v-64h-64z m-128 0v64h64v-64h-64z m-128 0v64h64v-64H288z m-96-96v64h64v-64H192z m0-128v64h64v-64H192z m0-128v64h64v-64H192z m0-128v64h64v-64H192z m0-128v64h64V288H192z m160 416c0-17.664 14.592-32 32.064-32h319.872a31.968 31.968 0 1 1 0 64h-319.872A31.968 31.968 0 0 1 352 704z m0-128c0-17.664 14.4-32 32.224-32h383.552c17.792 0 32.224 14.208 32.224 32 0 17.664-14.4 32-32.224 32H384.224A32.032 32.032 0 0 1 352 576z m0-128c0-17.664 14.4-32 32.224-32h383.552c17.792 0 32.224 14.208 32.224 32 0 17.664-14.4 32-32.224 32H384.224A32.032 32.032 0 0 1 352 448z m512 47.936V192h-64V159.968A31.776 31.776 0 0 0 768.032 128H160A31.776 31.776 0 0 0 128 159.968V768c0 17.92 14.304 31.968 31.968 31.968H192v64h303.936H128.128A63.968 63.968 0 0 1 64 799.872V128.128C64 92.704 92.48 64 128.128 64h671.744C835.296 64 864 92.48 864 128.128v367.808z"/>
|
||||
<path d="M192 256.16C192 220.736 220.704 192 256.16 192h639.68C931.264 192 960 220.704 960 256.16v639.68A64.16 64.16 0 0 1 895.84 960H256.16A64.16 64.16 0 0 1 192 895.84V256.16z m64 31.584v576.512a32 32 0 0 0 31.744 31.744h576.512a32 32 0 0 0 31.744-31.744V287.744A32 32 0 0 0 864.256 256H287.744A32 32 0 0 0 256 287.744zM288 192v64h64V192H288z m128 0v64h64V192h-64z m128 0v64h64V192h-64z m128 0v64h64V192h-64z m128 0v64h64V192h-64z m96 96v64h64V288h-64z m0 128v64h64v-64h-64z m0 128v64h64v-64h-64z m0 128v64h64v-64h-64z m0 128v64h64v-64h-64z m-96 96v64h64v-64h-64z m-128 0v64h64v-64h-64z m-128 0v64h64v-64h-64z m-128 0v64h64v-64h-64z m-128 0v64h64v-64H288z m-96-96v64h64v-64H192z m0-128v64h64v-64H192z m0-128v64h64v-64H192z m0-128v64h64v-64H192z m0-128v64h64V288H192z m160 416c0-17.664 14.592-32 32.064-32h319.872a31.968 31.968 0 1 1 0 64h-319.872A31.968 31.968 0 0 1 352 704z m0-128c0-17.664 14.4-32 32.224-32h383.552c17.792 0 32.224 14.208 32.224 32 0 17.664-14.4 32-32.224 32H384.224A32.032 32.032 0 0 1 352 576z m0-128c0-17.664 14.4-32 32.224-32h383.552c17.792 0 32.224 14.208 32.224 32 0 17.664-14.4 32-32.224 32H384.224A32.032 32.032 0 0 1 352 448z m512 47.936V192h-64V159.968A31.776 31.776 0 0 0 768.032 128H160A31.776 31.776 0 0 0 128 159.968V768c0 17.92 14.304 31.968 31.968 31.968H192v64h303.936H128.128A63.968 63.968 0 0 1 64 799.872V128.128C64 92.704 92.48 64 128.128 64h671.744C835.296 64 864 92.48 864 128.128v367.808z" />
|
||||
</SVGIcon>
|
||||
);
|
||||
}
|
||||
|
||||
@ -1,4 +1,4 @@
|
||||
import { SVGIcon, IconProps } from "@ali/lowcode-utils";
|
||||
import { SVGIcon, IconProps } from '@ali/lowcode-utils';
|
||||
|
||||
export function IconComponent(props: IconProps) {
|
||||
return (
|
||||
|
||||
@ -1,4 +1,4 @@
|
||||
import { SVGIcon, IconProps } from "@ali/lowcode-utils";
|
||||
import { SVGIcon, IconProps } from '@ali/lowcode-utils';
|
||||
|
||||
export function IconContainer(props: IconProps) {
|
||||
return (
|
||||
|
||||
@ -1,4 +1,4 @@
|
||||
import { SVGIcon, IconProps } from "@ali/lowcode-utils";
|
||||
import { SVGIcon, IconProps } from '@ali/lowcode-utils';
|
||||
|
||||
export function IconHidden(props: IconProps) {
|
||||
return (
|
||||
|
||||
@ -1,4 +1,4 @@
|
||||
import { SVGIcon, IconProps } from "@ali/lowcode-utils";
|
||||
import { SVGIcon, IconProps } from '@ali/lowcode-utils';
|
||||
|
||||
export function IconPage(props: IconProps) {
|
||||
return (
|
||||
|
||||
@ -6,6 +6,7 @@ import { ProjectSchema, RootSchema } from '@ali/lowcode-types';
|
||||
|
||||
export class Project {
|
||||
private emitter = new EventEmitter();
|
||||
|
||||
@obx.val readonly documents: DocumentModel[] = [];
|
||||
|
||||
private data: ProjectSchema = { version: '1.0.0', componentsMap: [], componentsTree: [] };
|
||||
@ -82,15 +83,15 @@ export class Project {
|
||||
*/
|
||||
set(
|
||||
key:
|
||||
| 'version'
|
||||
| 'componentsTree'
|
||||
| 'componentsMap'
|
||||
| 'utils'
|
||||
| 'constants'
|
||||
| 'i18n'
|
||||
| 'css'
|
||||
| 'dataSource'
|
||||
| string,
|
||||
| 'version'
|
||||
| 'componentsTree'
|
||||
| 'componentsMap'
|
||||
| 'utils'
|
||||
| 'constants'
|
||||
| 'i18n'
|
||||
| 'css'
|
||||
| 'dataSource'
|
||||
| string,
|
||||
value: any,
|
||||
): void {}
|
||||
|
||||
@ -99,15 +100,15 @@ export class Project {
|
||||
*/
|
||||
get(
|
||||
key:
|
||||
| 'version'
|
||||
| 'componentsTree'
|
||||
| 'componentsMap'
|
||||
| 'utils'
|
||||
| 'constants'
|
||||
| 'i18n'
|
||||
| 'css'
|
||||
| 'dataSource'
|
||||
| string,
|
||||
| 'version'
|
||||
| 'componentsTree'
|
||||
| 'componentsMap'
|
||||
| 'utils'
|
||||
| 'constants'
|
||||
| 'i18n'
|
||||
| 'css'
|
||||
| 'dataSource'
|
||||
| string,
|
||||
): any {}
|
||||
|
||||
open(doc?: string | DocumentModel | RootSchema): DocumentModel {
|
||||
|
||||
@ -6,7 +6,7 @@ module.exports = ({ onGetWebpackConfig }) => {
|
||||
config.resolve
|
||||
.plugin('tsconfigpaths')
|
||||
.use(TsconfigPathsPlugin, [{
|
||||
configFile: "./tsconfig.json"
|
||||
configFile: './tsconfig.json',
|
||||
}]);
|
||||
});
|
||||
};
|
||||
|
||||
@ -1,4 +1,5 @@
|
||||
import { IocContext } from 'power-di';
|
||||
|
||||
export * from 'power-di';
|
||||
|
||||
export const globalContext = IocContext.DefaultInstance;
|
||||
|
||||
@ -52,7 +52,7 @@ export function registerSetter(
|
||||
|
||||
function getInitialFromSetter(setter: any) {
|
||||
return setter && (
|
||||
setter.initial || setter.Initial
|
||||
setter.initial || setter.Initial
|
||||
|| (setter.type && (setter.type.initial || setter.type.Initial))
|
||||
) || null; // eslint-disable-line
|
||||
}
|
||||
|
||||
@ -86,7 +86,9 @@ export class Editor extends EventEmitter implements IEditor {
|
||||
}
|
||||
|
||||
config?: EditorConfig;
|
||||
|
||||
components?: PluginClassSet;
|
||||
|
||||
async init(config?: EditorConfig, components?: PluginClassSet): Promise<any> {
|
||||
this.config = config || {};
|
||||
this.components = components || {};
|
||||
@ -152,12 +154,13 @@ export class Editor extends EventEmitter implements IEditor {
|
||||
};
|
||||
|
||||
private waits = new Map<
|
||||
KeyType,
|
||||
Array<{
|
||||
once?: boolean;
|
||||
resolve: (data: any) => void;
|
||||
}>
|
||||
KeyType,
|
||||
Array<{
|
||||
once?: boolean;
|
||||
resolve:(data: any) => void;
|
||||
}>
|
||||
>();
|
||||
|
||||
private notifyGot(key: KeyType) {
|
||||
let waits = this.waits.get(key);
|
||||
if (!waits) {
|
||||
|
||||
@ -124,7 +124,7 @@ let REVERSE_MAP: CtrlKeyMap;
|
||||
* programatically
|
||||
*/
|
||||
for (let i = 1; i < 20; ++i) {
|
||||
MAP[111 + i] = 'f' + i;
|
||||
MAP[111 + i] = `f${ i}`;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -346,22 +346,28 @@ function fireCallback(callback: HotkeyCallback, e: KeyboardEvent, combo?: string
|
||||
sequence,
|
||||
selected,
|
||||
});
|
||||
} catch(err) {
|
||||
} catch (err) {
|
||||
console.error(err.message);
|
||||
}
|
||||
}
|
||||
|
||||
export class Hotkey {
|
||||
private callBacks: HotkeyCallbacks = {};
|
||||
|
||||
private directMap: HotkeyDirectMap = {};
|
||||
|
||||
private sequenceLevels: SequenceLevels = {};
|
||||
|
||||
private resetTimer = 0;
|
||||
|
||||
private ignoreNextKeyup: boolean | string = false;
|
||||
|
||||
private ignoreNextKeypress = false;
|
||||
|
||||
private nextExpectedAction: boolean | string = false;
|
||||
|
||||
mount(window: Window) {
|
||||
const document = window.document;
|
||||
const { document } = window;
|
||||
const handleKeyEvent = this.handleKeyEvent.bind(this);
|
||||
document.addEventListener('keypress', handleKeyEvent, false);
|
||||
document.addEventListener('keydown', handleKeyEvent, false);
|
||||
|
||||
@ -1,5 +1,6 @@
|
||||
import { EventEmitter } from 'events';
|
||||
import { obx, computed } from '../utils/obx';
|
||||
|
||||
const languageMap: { [key: string]: string } = {
|
||||
en: 'en-US',
|
||||
zh: 'zh-CN',
|
||||
@ -30,7 +31,9 @@ const LowcodeConfigKey = 'ali-lowcode-config';
|
||||
|
||||
class AliGlobalLocale {
|
||||
private emitter = new EventEmitter();
|
||||
|
||||
@obx.ref private _locale?: string;
|
||||
|
||||
@computed get locale() {
|
||||
if (this._locale != null) {
|
||||
return this._locale;
|
||||
@ -67,7 +70,7 @@ class AliGlobalLocale {
|
||||
const it = navigator.browserLanguage.split('-');
|
||||
locale = it[0];
|
||||
if (it[1]) {
|
||||
locale += '-' + it[1].toUpperCase();
|
||||
locale += `-${ it[1].toUpperCase()}`;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Some files were not shown because too many files have changed in this diff Show More
Loading…
x
Reference in New Issue
Block a user