From 6d2a77a766f5a961e4b5bc007888c175c9b83eeb Mon Sep 17 00:00:00 2001 From: liujuping Date: Sat, 10 Dec 2022 13:54:38 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E4=BF=AE=E5=A4=8D=20workspace=20mode=20?= =?UTF-8?q?=E4=B8=8B=E6=8A=A5=E9=94=99=E7=9A=84=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../designer/src/plugin/plugin-manager.ts | 2 +- packages/workspace/src/base-context.ts | 29 +++++++++++++++---- packages/workspace/src/shell-model-factory.ts | 18 ++++++++++++ 3 files changed, 42 insertions(+), 7 deletions(-) create mode 100644 packages/workspace/src/shell-model-factory.ts diff --git a/packages/designer/src/plugin/plugin-manager.ts b/packages/designer/src/plugin/plugin-manager.ts index bc0dfd947..27891d4de 100644 --- a/packages/designer/src/plugin/plugin-manager.ts +++ b/packages/designer/src/plugin/plugin-manager.ts @@ -37,7 +37,7 @@ export class LowCodePluginManager implements ILowCodePluginManager { this.contextApiAssembler = contextApiAssembler; } - private _getLowCodePluginContext(options: IPluginContextOptions) { + _getLowCodePluginContext(options: IPluginContextOptions) { return new LowCodePluginContext(this, options, this.contextApiAssembler); } diff --git a/packages/workspace/src/base-context.ts b/packages/workspace/src/base-context.ts index 2bf86542c..f1b4cfa18 100644 --- a/packages/workspace/src/base-context.ts +++ b/packages/workspace/src/base-context.ts @@ -1,8 +1,9 @@ import { Editor, engineConfig, Setters as InnerSetters } from '@alilc/lowcode-editor-core'; import { Designer, + ILowCodePluginContextApiAssembler, LowCodePluginManager, - TransformStage, + ILowCodePluginContextPrivate, } from '@alilc/lowcode-designer'; import { Skeleton as InnerSkeleton, @@ -12,12 +13,13 @@ import { WorkSpace, } from '@alilc/lowcode-workspace'; -import { Hotkey, Project, Skeleton, Setters, Material, Event } from '@alilc/lowcode-shell'; +import { Hotkey, Project, Skeleton, Setters, Material, Event, Common } from '@alilc/lowcode-shell'; import { getLogger } from '@alilc/lowcode-utils'; import { setterRegistry } from 'engine/src/inner-plugins/setter-registry'; import { componentMetaParser } from 'engine/src/inner-plugins/component-meta-parser'; import defaultPanelRegistry from 'engine/src/inner-plugins/default-panel-registry'; import { EditorWindow } from './editor-window/context'; +import { shellModelFactory } from './shell-model-factory'; export class BasicContext { skeleton; @@ -53,12 +55,10 @@ export class BasicContext { const designer: Designer = new Designer({ editor, name, + shellModelFactory, }); editor.set('designer' as any, designer); - const plugins = new LowCodePluginManager(editor).toProxy(); - editor.set('plugins' as any, plugins); - const { project: innerProject } = designer; const hotkey = new Hotkey(name); const innerSetters = new InnerSetters(name); @@ -75,7 +75,6 @@ export class BasicContext { this.innerSetters = innerSetters; this.innerSkeleton = innerSkeleton; this.skeleton = skeleton; - this.plugins = plugins; this.innerProject = innerProject; this.project = project; this.setters = setters; @@ -86,6 +85,24 @@ export class BasicContext { this.hotkey = hotkey; this.editor = editor; this.designer = designer; + const common = new Common(editor, innerSkeleton); + + const pluginContextApiAssembler: ILowCodePluginContextApiAssembler = { + assembleApis: (context: ILowCodePluginContextPrivate) => { + context.hotkey = hotkey; + context.project = project; + context.skeleton = skeleton; + context.setters = setters; + context.material = material; + context.event = event; + context.config = config; + context.common = common; + }, + }; + + const plugins = new LowCodePluginManager(pluginContextApiAssembler).toProxy(); + editor.set('plugins' as any, plugins); + this.plugins = plugins; // 注册一批内置插件 this.registerInnerPlugins = async function registerPlugins() { diff --git a/packages/workspace/src/shell-model-factory.ts b/packages/workspace/src/shell-model-factory.ts new file mode 100644 index 000000000..05c7b19cb --- /dev/null +++ b/packages/workspace/src/shell-model-factory.ts @@ -0,0 +1,18 @@ +import { + Node as InnerNode, + SettingField as InnerSettingField, +} from '@alilc/lowcode-designer'; +import { IShellModelFactory, IPublicModelNode, IPublicModelSettingPropEntry } from '@alilc/lowcode-types'; +import { + Node, + SettingPropEntry, +} from '@alilc/lowcode-shell'; +class ShellModelFactory implements IShellModelFactory { + createNode(node: InnerNode | null | undefined): IPublicModelNode | null { + return Node.create(node); + } + createSettingPropEntry(prop: InnerSettingField): IPublicModelSettingPropEntry { + return SettingPropEntry.create(prop); + } +} +export const shellModelFactory = new ShellModelFactory(); \ No newline at end of file