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