diff --git a/packages/designer/src/component-meta.ts b/packages/designer/src/component-meta.ts index dd4b964c4..1410ea334 100644 --- a/packages/designer/src/component-meta.ts +++ b/packages/designer/src/component-meta.ts @@ -352,6 +352,8 @@ const builtinComponentActions: ComponentAction[] = [ title: intlNode('copy'), action(node: Node) { // node.remove(); + const { document: doc, parent, schema, index } = node; + parent && doc.insertNode(parent, schema, index); }, }, important: true, diff --git a/packages/designer/src/designer/builtin-hotkey.ts b/packages/designer/src/designer/builtin-hotkey.ts index d11edbe03..7831f95e3 100644 --- a/packages/designer/src/designer/builtin-hotkey.ts +++ b/packages/designer/src/designer/builtin-hotkey.ts @@ -58,14 +58,15 @@ hotkey.bind(['command+c', 'ctrl+c', 'command+x', 'ctrl+x'], (e, action) => { const data = { type: 'nodeSchema', componentsMap, componentsTree }; clipboard.setData(data); - /* + const cutMode = action.indexOf('x') > 0; if (cutMode) { - const parentNode = selected.getParent(); - parentNode.select(); - selected.remove(); + selected.forEach((node) => { + const parentNode = node.getParent(); + parentNode?.select(); + node.remove(); + }); } - */ }); // command + v paste diff --git a/packages/designer/src/document/document-model.ts b/packages/designer/src/document/document-model.ts index 16f3df6d6..e4442734f 100644 --- a/packages/designer/src/document/document-model.ts +++ b/packages/designer/src/document/document-model.ts @@ -41,6 +41,7 @@ export class DocumentModel { private seqId = 0; private _simulator?: ISimulatorHost; + /** * 模拟器 */ @@ -110,6 +111,14 @@ export class DocumentModel { } readonly designer = this.project.designer; + // getAddonData(name: string) { + // const addon = this.addons.find((item) => item.name === name); + // if (addon) { + // return addon.exportData(); + // } + // return this.addonsData[name]; + // } + /** * 生成唯一id @@ -230,6 +239,14 @@ export class DocumentModel { this.selection.remove(node.id); node.remove(); } + getAddonData(name: string) { + const addon = this.getNode(name) + if (addon) { + // 无法确定是否有这个api + // return addon.exportData(); + } + return addon + } @obx.ref private _dropLocation: DropLocation | null = null; /** diff --git a/packages/designer/src/document/history.ts b/packages/designer/src/document/history.ts index 0f283b65b..8a37f1032 100644 --- a/packages/designer/src/document/history.ts +++ b/packages/designer/src/document/history.ts @@ -174,6 +174,10 @@ export class History { this.emitter.removeAllListeners(); this.records = []; } + + isModified() { + return this.point !== this.session.cursor; + } } class Session { diff --git a/packages/editor-skeleton/src/widget/dock.ts b/packages/editor-skeleton/src/widget/dock.ts index c63bbdc2c..4b2081e53 100644 --- a/packages/editor-skeleton/src/widget/dock.ts +++ b/packages/editor-skeleton/src/widget/dock.ts @@ -45,6 +45,8 @@ export default class Dock implements IWidget { } else { this._body = createElement(DockView, props); } + this.inited = true; + return this._body; } diff --git a/packages/vision-preset/src/env.ts b/packages/vision-preset/src/env.ts index bd5ab894a..8c7eae39b 100644 --- a/packages/vision-preset/src/env.ts +++ b/packages/vision-preset/src/env.ts @@ -1,13 +1,13 @@ import { EventEmitter } from 'events'; import { ALI_SCHEMA_VERSION } from './base/const'; +import { obx } from '@ali/lowcode-editor-core'; interface ILiteralObject { [key: string]: any; } export class Env { - - public envs: ILiteralObject; + @obx.val envs: ILiteralObject = {}; private emitter: EventEmitter; private featureMap: ILiteralObject; @@ -15,23 +15,22 @@ export class Env { constructor() { this.emitter = new EventEmitter(); this.emitter.setMaxListeners(0); - this.envs = {}; this.featureMap = {}; } - public get(name: string): any { + get(name: string): any { return this.getEnv(name); } - public getEnv(name: string): any { + getEnv(name: string): any { return this.envs[name]; } - public set(name: string, value: any) { + set(name: string, value: any) { return this.setEnv(name, value); } - public setEnv(name: string, value: any) { + setEnv(name: string, value: any) { const orig = this.envs[name]; if (JSON.stringify(orig) === JSON.stringify(value)) { return; @@ -40,47 +39,47 @@ export class Env { this.emitter.emit('envchange', this.envs, name, value); } - public setEnvMap(envs: ILiteralObject): void { + setEnvMap(envs: ILiteralObject): void { this.envs = Object.assign(this.envs, envs); this.emitter.emit('envchange', this.envs); } - public getLocale(): string { + getLocale(): string { return this.getEnv('locale') || 'zh_CN'; } - public setLocale(locale: string) { + setLocale(locale: string) { this.setEnv('locale', locale); } - public setExpertMode(flag: string) { + setExpertMode(flag: string) { this.setEnv('expertMode', !!flag); } - public isExpertMode() { + isExpertMode() { return !!this.getEnv('expertMode'); } - public getSupportFeatures() { + getSupportFeatures() { return Object.assign({}, this.featureMap); } - public setSupportFeatures(features: ILiteralObject) { + setSupportFeatures(features: ILiteralObject) { this.featureMap = Object.assign({}, this.featureMap, features); } - public supports(name = 'supports') { + supports(name = 'supports') { return !!this.featureMap[name]; } - public onEnvChange(func: (envs: ILiteralObject, name: string, value: any) => any) { + onEnvChange(func: (envs: ILiteralObject, name: string, value: any) => any) { this.emitter.on('envchange', func); return () => { this.emitter.removeListener('envchange', func); }; } - public getAliSchemaVersion() { + getAliSchemaVersion() { return ALI_SCHEMA_VERSION; } } diff --git a/packages/vision-preset/src/i18n-reducer.ts b/packages/vision-preset/src/i18n-reducer.ts index 693ee0cae..a1a153932 100644 --- a/packages/vision-preset/src/i18n-reducer.ts +++ b/packages/vision-preset/src/i18n-reducer.ts @@ -1,5 +1,5 @@ -const I18nUtil = require('@ali/ve-i18n-util'); import Env from './env'; +const I18nUtil = require('@ali/ve-i18n-util'); interface I18nObject { type?: string; @@ -9,7 +9,9 @@ interface I18nObject { } export function i18nReducer(obj?: any): any { - if (!obj) { return obj; } + if (!obj) { + return obj; + } if (Array.isArray(obj)) { return obj.map((item) => i18nReducer(item)); } @@ -18,6 +20,7 @@ export function i18nReducer(obj?: any): any { // FIXME! use editor.get let locale = Env.getLocale(); if (obj.key) { + // FIXME: 此处需要升级I18nUtil,改成响应式 return I18nUtil.get(obj.key, locale); } if (locale !== 'zh_CN' && locale !== 'zh_TW' && !obj[locale]) { diff --git a/packages/vision-preset/src/index.ts b/packages/vision-preset/src/index.ts index 23dbe607a..ed632b3ef 100644 --- a/packages/vision-preset/src/index.ts +++ b/packages/vision-preset/src/index.ts @@ -25,6 +25,7 @@ import DragEngine from './drag-engine'; import Viewport from './viewport'; import Project from './project'; import { designer, editor } from './editor'; +import Symbols from './symbols'; import './vision.less'; @@ -109,6 +110,7 @@ const VisualEngine = { Version, Project, logger, + Symbols, }; (window as any).VisualEngine = VisualEngine; @@ -156,6 +158,7 @@ export { Version, Project, logger, + Symbols, }; diff --git a/packages/vision-preset/src/panes.ts b/packages/vision-preset/src/panes.ts index e9d509525..3be27f531 100644 --- a/packages/vision-preset/src/panes.ts +++ b/packages/vision-preset/src/panes.ts @@ -85,10 +85,10 @@ function upgradeConfig(config: OldPaneConfig): IWidgetBaseConfig & { area: strin }; if (contents && Array.isArray(contents)) { - newConfig.content = contents.map(({ title, content, tip }) => { + newConfig.content = contents.map(({ title, content, tip }, index) => { return { type: 'Panel', - name: title, + name: typeof title === 'string' ? title : `${name}:${index}`, content, props: { title, diff --git a/packages/vision-preset/src/symbols.ts b/packages/vision-preset/src/symbols.ts new file mode 100644 index 000000000..81091e371 --- /dev/null +++ b/packages/vision-preset/src/symbols.ts @@ -0,0 +1,17 @@ +export class SymbolManager { + private symbolMap: { [symbolName: string]: symbol } = {}; + + public create(name: string): symbol { + if (this.symbolMap[name]) { + return this.symbolMap[name]; + } + this.symbolMap[name] = Symbol(name); + return this.symbolMap[name]; + } + + public get(name: string) { + return this.symbolMap[name]; + } +} + +export default new SymbolManager(); diff --git a/packages/vision-preset/src/vision.less b/packages/vision-preset/src/vision.less index 7c04b0955..d188878a5 100644 --- a/packages/vision-preset/src/vision.less +++ b/packages/vision-preset/src/vision.less @@ -101,3 +101,9 @@ html.engine-blur #engine { .lc-left-float-pane { font-size: 14px; } + +html.engine-preview-mode { + .lc-left-area, .lc-right-area { + display: none !important; + } +}