From 70120a033af95e4d09f3c152c7a6464c5b2ec683 Mon Sep 17 00:00:00 2001 From: liujuping Date: Wed, 26 Apr 2023 15:34:02 +0800 Subject: [PATCH 01/15] feat: get editor from this or params --- .../bem-tools/border-resizing.tsx | 13 ++++---- .../bem-tools/border-selecting.tsx | 5 ++- .../live-editing/live-editing.ts | 17 +++++----- .../builtin-simulator/node-selector/index.tsx | 5 ++- packages/designer/src/component-meta.ts | 2 ++ .../designer/src/document/document-model.ts | 5 +++ packages/designer/src/document/history.ts | 13 ++++---- .../src/document/node/node-children.ts | 33 +++++++------------ .../settings/settings-primary-pane.tsx | 5 +-- .../src/components/widget-views/index.tsx | 14 +++----- packages/workspace/src/workspace.ts | 3 ++ 11 files changed, 53 insertions(+), 62 deletions(-) diff --git a/packages/designer/src/builtin-simulator/bem-tools/border-resizing.tsx b/packages/designer/src/builtin-simulator/bem-tools/border-resizing.tsx index 29401ca6b..4b3c5c31a 100644 --- a/packages/designer/src/builtin-simulator/bem-tools/border-resizing.tsx +++ b/packages/designer/src/builtin-simulator/bem-tools/border-resizing.tsx @@ -1,10 +1,10 @@ import React, { Component, Fragment } from 'react'; import DragResizeEngine from './drag-resize-engine'; -import { observer, computed, globalContext } from '@alilc/lowcode-editor-core'; +import { observer, computed } from '@alilc/lowcode-editor-core'; import classNames from 'classnames'; import { SimulatorContext } from '../context'; import { BuiltinSimulatorHost } from '../host'; -import { OffsetObserver, Designer } from '../../designer'; +import { OffsetObserver, Designer, INode } from '../../designer'; import { Node } from '../../document'; import { normalizeTriggers } from '../../utils/misc'; @@ -135,7 +135,7 @@ export class BoxResizingInstance extends Component<{ // this.hoveringCapture.setBoundary(this.outline); this.willBind(); - const resize = (e: MouseEvent, direction: string, node: any, moveX: number, moveY: number) => { + const resize = (e: MouseEvent, direction: string, node: INode, moveX: number, moveY: number) => { const { advanced } = node.componentMeta; if ( advanced.callbacks && @@ -149,7 +149,7 @@ export class BoxResizingInstance extends Component<{ } }; - const resizeStart = (e: MouseEvent, direction: string, node: any) => { + const resizeStart = (e: MouseEvent, direction: string, node: INode) => { const { advanced } = node.componentMeta; if ( advanced.callbacks && @@ -161,7 +161,7 @@ export class BoxResizingInstance extends Component<{ } }; - const resizeEnd = (e: MouseEvent, direction: string, node: any) => { + const resizeEnd = (e: MouseEvent, direction: string, node: INode) => { const { advanced } = node.componentMeta; if ( advanced.callbacks && @@ -172,8 +172,7 @@ export class BoxResizingInstance extends Component<{ advanced.callbacks.onResizeEnd(e, cbNode); } - const workspace = globalContext.get('workspace'); - const editor = workspace.isActive ? workspace.window.editor : globalContext.get('editor'); + const editor = node.document?.designer.editor; const npm = node?.componentMeta?.npm; const selected = [npm?.package, npm?.componentName].filter((item) => !!item).join('-') || diff --git a/packages/designer/src/builtin-simulator/bem-tools/border-selecting.tsx b/packages/designer/src/builtin-simulator/bem-tools/border-selecting.tsx index 75b4a3488..0e9d734b6 100644 --- a/packages/designer/src/builtin-simulator/bem-tools/border-selecting.tsx +++ b/packages/designer/src/builtin-simulator/bem-tools/border-selecting.tsx @@ -9,7 +9,7 @@ import { ComponentType, } from 'react'; import classNames from 'classnames'; -import { observer, computed, Tip, globalContext } from '@alilc/lowcode-editor-core'; +import { observer, computed, Tip } from '@alilc/lowcode-editor-core'; import { createIcon, isReactComponent, isActionContentObject } from '@alilc/lowcode-utils'; import { IPublicTypeActionContentObject } from '@alilc/lowcode-types'; import { BuiltinSimulatorHost } from '../host'; @@ -131,8 +131,7 @@ function createAction(content: ReactNode | ComponentType | IPublicTypeActio className="lc-borders-action" onClick={() => { action && action(node.internalToShellNode()!); - const workspace = globalContext.get('workspace'); - const editor = workspace.isActive ? workspace.window.editor : globalContext.get('editor'); + const editor = node.document?.designer.editor; const npm = node?.componentMeta?.npm; const selected = [npm?.package, npm?.componentName].filter((item) => !!item).join('-') || diff --git a/packages/designer/src/builtin-simulator/live-editing/live-editing.ts b/packages/designer/src/builtin-simulator/live-editing/live-editing.ts index e92e266ee..c8594d701 100644 --- a/packages/designer/src/builtin-simulator/live-editing/live-editing.ts +++ b/packages/designer/src/builtin-simulator/live-editing/live-editing.ts @@ -1,6 +1,6 @@ -import { obx, globalContext } from '@alilc/lowcode-editor-core'; +import { obx } from '@alilc/lowcode-editor-core'; import { IPublicTypePluginConfig, IPublicTypeLiveTextEditingConfig } from '@alilc/lowcode-types'; -import { Node, Prop } from '../../document'; +import { INode, Prop } from '../../document'; const EDITOR_KEY = 'data-setter-prop'; @@ -17,7 +17,7 @@ function defaultSaveContent(content: string, prop: Prop) { } export interface EditingTarget { - node: Node; + node: INode; rootElement: HTMLElement; event: MouseEvent; } @@ -47,13 +47,16 @@ export class LiveEditing { @obx.ref private _editing: Prop | null = null; + private _dispose?: () => void; + + private _save?: () => void; + apply(target: EditingTarget) { const { node, event, rootElement } = target; const targetElement = event.target as HTMLElement; const { liveTextEditing } = node.componentMeta; - const workspace = globalContext.get('workspace'); - const editor = workspace.isActive ? workspace.window.editor : globalContext.get('editor'); + const editor = node.document?.designer.editor; const npm = node?.componentMeta?.npm; const selected = [npm?.package, npm?.componentName].filter((item) => !!item).join('-') || node?.componentMeta?.componentName || ''; @@ -166,10 +169,6 @@ export class LiveEditing { return this._editing; } - private _dispose?: () => void; - - private _save?: () => void; - saveAndDispose() { if (this._save) { this._save(); diff --git a/packages/designer/src/builtin-simulator/node-selector/index.tsx b/packages/designer/src/builtin-simulator/node-selector/index.tsx index 09c8f1262..07ae754aa 100644 --- a/packages/designer/src/builtin-simulator/node-selector/index.tsx +++ b/packages/designer/src/builtin-simulator/node-selector/index.tsx @@ -1,6 +1,6 @@ import { Overlay } from '@alifd/next'; import React, { MouseEvent } from 'react'; -import { Title, globalContext } from '@alilc/lowcode-editor-core'; +import { Title } from '@alilc/lowcode-editor-core'; import { canClickNode } from '@alilc/lowcode-utils'; import './index.less'; @@ -66,8 +66,7 @@ export default class InstanceNodeSelector extends React.Component !!item).join('-') || diff --git a/packages/designer/src/component-meta.ts b/packages/designer/src/component-meta.ts index 4b0a613cb..00c495621 100644 --- a/packages/designer/src/component-meta.ts +++ b/packages/designer/src/component-meta.ts @@ -60,6 +60,8 @@ export function buildFilter(rule?: string | string[] | RegExp | IPublicTypeNesti export interface IComponentMeta extends IPublicModelComponentMeta { prototype?: any; + liveTextEditing?: IPublicTypeLiveTextEditingConfig[]; + get rootSelector(): string | undefined; setMetadata(metadata: IPublicTypeComponentMetadata): void; diff --git a/packages/designer/src/document/document-model.ts b/packages/designer/src/document/document-model.ts index c55e7a8e4..699775bc7 100644 --- a/packages/designer/src/document/document-model.ts +++ b/packages/designer/src/document/document-model.ts @@ -148,6 +148,10 @@ export interface IDocumentModel extends Omit implements IHistory { return this.session.data; } + private timeGap: number = 1000; + constructor( dataFn: () => T | null, private redoer: (data: T) => void, - private timeGap: number = 1000, + private document?: IDocumentModel, ) { this.session = new Session(0, null, this.timeGap); this.records = [this.session]; @@ -130,8 +133,7 @@ export class History implements IHistory { } const cursor = this.session.cursor - 1; this.go(cursor); - const workspace = globalContext.get('workspace'); - const editor = workspace.isActive ? workspace.window.editor : globalContext.get('editor'); + const editor = this.document?.designer.editor; if (!editor) { return; } @@ -144,8 +146,7 @@ export class History implements IHistory { } const cursor = this.session.cursor + 1; this.go(cursor); - const workspace = globalContext.get('workspace'); - const editor = workspace.isActive ? workspace.window.editor : globalContext.get('editor'); + const editor = this.document?.designer.editor; if (!editor) { return; } diff --git a/packages/designer/src/document/node/node-children.ts b/packages/designer/src/document/node/node-children.ts index 1b6df5866..4fb1c3d22 100644 --- a/packages/designer/src/document/node/node-children.ts +++ b/packages/designer/src/document/node/node-children.ts @@ -1,4 +1,4 @@ -import { obx, computed, globalContext, makeObservable, IEventBus, createModuleEventBus } from '@alilc/lowcode-editor-core'; +import { obx, computed, makeObservable, IEventBus, createModuleEventBus } from '@alilc/lowcode-editor-core'; import { Node, INode } from './node'; import { IPublicTypeNodeData, IPublicModelNodeChildren, IPublicEnumTransformStage, IPublicTypeDisposable } from '@alilc/lowcode-types'; import { shallowEqual, compatStage, isNodeSchema } from '@alilc/lowcode-utils'; @@ -16,12 +16,12 @@ export interface INodeChildren extends Omit, 'isEmpty' | 'notEmpty' > { + children: INode[]; + get owner(): INode; get length(): number; - children: INode[]; - unlinkChild(node: INode): void; /** @@ -239,11 +239,8 @@ export class NodeChildren implements INodeChildren { } const { document } = node; /* istanbul ignore next */ - if (globalContext.has('editor')) { - const workspace = globalContext.get('workspace'); - const editor = workspace.isActive ? workspace.window.editor : globalContext.get('editor'); - editor.eventBus.emit('node.remove', { node, index: i }); - } + const editor = node.document?.designer.editor; + editor?.eventBus.emit('node.remove', { node, index: i }); document?.unlinkNode(node); document?.selection.remove(node.id); document?.destroyNode(node); @@ -281,14 +278,11 @@ export class NodeChildren implements INodeChildren { const i = children.map(d => d.id).indexOf(node.id); if (node.parent) { - if (globalContext.has('editor')) { - const workspace = globalContext.get('workspace'); - const editor = workspace.isActive ? workspace.window.editor : globalContext.get('editor'); - editor.eventBus.emit('node.remove.topLevel', { - node, - index: node.index, - }); - } + const editor = node.document?.designer.editor; + editor?.eventBus.emit('node.remove.topLevel', { + node, + index: node.index, + }); } if (i < 0) { @@ -317,11 +311,8 @@ export class NodeChildren implements INodeChildren { }); this.emitter.emit('insert', node); /* istanbul ignore next */ - if (globalContext.has('editor')) { - const workspace = globalContext.get('workspace'); - const editor = workspace.isActive ? workspace.window.editor : globalContext.get('editor'); - editor.eventBus.emit('node.add', { node }); - } + const editor = node.document?.designer.editor; + editor?.eventBus.emit('node.add', { node }); if (useMutator) { this.reportModified(node, this.owner, { type: 'insert' }); } diff --git a/packages/editor-skeleton/src/components/settings/settings-primary-pane.tsx b/packages/editor-skeleton/src/components/settings/settings-primary-pane.tsx index 0bbef4bf2..800719588 100644 --- a/packages/editor-skeleton/src/components/settings/settings-primary-pane.tsx +++ b/packages/editor-skeleton/src/components/settings/settings-primary-pane.tsx @@ -53,8 +53,7 @@ export class SettingsPrimaryPane extends Component { } // 抛出事件,对于有些需要 panel 插件随着 度变化进行再次渲染的,由panel插件内部监听事件实现 - const workspace = globalContext.get('workspace'); - const editor = workspace.isActive ? workspace.window.editor : globalContext.get('editor'); + const editor = this.props.panel.skeleton.editor; editor?.eventBus.emit('dockpane.drag', width); } onDragChange(type: 'start' | 'end') { - const workspace = globalContext.get('workspace'); - const editor = workspace.isActive ? workspace.window.editor : globalContext.get('editor'); + const editor = this.props.panel.skeleton.editor; editor?.eventBus.emit('dockpane.dragchange', type); // builtinSimulator 屏蔽掉 鼠标事件 editor?.eventBus.emit('designer.builtinSimulator.disabledEvents', type === 'start'); @@ -187,8 +185,7 @@ export class TitledPanelView extends Component<{ panel: Panel; area?: string }> if (!panel.inited) { return null; } - const workspace = globalContext.get('workspace'); - const editor = workspace.isActive ? workspace.window.editor : globalContext.get('editor'); + const editor = panel.skeleton.editor; const panelName = area ? `${area}-${panel.name}` : panel.name; editor?.eventBus.emit('skeleton.panel.toggle', { name: panelName || '', @@ -250,8 +247,7 @@ export class PanelView extends Component<{ if (!panel.inited) { return null; } - const workspace = globalContext.get('workspace'); - const editor = workspace.isActive ? workspace.window.editor : globalContext.get('editor'); + const editor = panel.skeleton.editor; const panelName = area ? `${area}-${panel.name}` : panel.name; editor?.eventBus.emit('skeleton.panel.toggle', { name: panelName || '', diff --git a/packages/workspace/src/workspace.ts b/packages/workspace/src/workspace.ts index c723d2b5c..26e1d6551 100644 --- a/packages/workspace/src/workspace.ts +++ b/packages/workspace/src/workspace.ts @@ -183,6 +183,9 @@ export class Workspace implements IWorkspace { } private remove(index: number) { + if (index < 0) { + return; + } const window = this.windows[index]; this.windows.splice(index, 1); if (this.window === window) { From c11bceb2cea9548947b724a179518ac0ea280b62 Mon Sep 17 00:00:00 2001 From: wendell0316 Date: Thu, 27 Apr 2023 09:43:56 +0800 Subject: [PATCH 02/15] feat: add more props for popup MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * feat: popup可以接受外部参数 目前配置都是固定的,对于一些简单定制化的需求无法满足 * feat: 增加类型约束,固定可修改项 * Revert "feat: 增加类型约束,固定可修改项" This reverts commit 7e3b4dd1fafce56bfb94d7f77fda729eec4066d0. * feat: 添加类型 --- .../src/components/popup/index.tsx | 41 ++++++++++++++----- 1 file changed, 31 insertions(+), 10 deletions(-) diff --git a/packages/editor-skeleton/src/components/popup/index.tsx b/packages/editor-skeleton/src/components/popup/index.tsx index 68897d61a..1367723a1 100644 --- a/packages/editor-skeleton/src/components/popup/index.tsx +++ b/packages/editor-skeleton/src/components/popup/index.tsx @@ -4,6 +4,22 @@ import { uniqueId } from '@alilc/lowcode-utils'; import { IEventBus, createModuleEventBus } from '@alilc/lowcode-editor-core'; import './style.less'; +export interface PopupExtProps { + width?: number; + hasMask?: boolean; + trigger?: ReactNode; + canCloseByOutSideClick?: boolean + className?: string; + safeNode?: string[]; +} + +interface PopupProps extends PopupExtProps{ + content?: ReactNode, + title?: ReactNode, + actionKey?: string +} + + export const PopupContext = createContext({} as any); export class PopupPipe { @@ -11,7 +27,7 @@ export class PopupPipe { private currentId?: string; - create(props?: object): { + create(props?: PopupExtProps): { send: (content: ReactNode, title: ReactNode) => void; show: (target: Element) => void; } { @@ -45,13 +61,13 @@ export class PopupPipe { }; } - private popup(props: object, target?: Element) { + private popup(props: PopupProps, target?: Element) { Promise.resolve().then(() => { this.emitter.emit('popupchange', props, target); }); } - onPopupChange(fn: (props: object, target?: Element) => void): () => void { + onPopupChange(fn: (props: PopupProps, target?: Element) => void): () => void { this.emitter.on('popupchange', fn); return () => { this.emitter.removeListener('popupchange', fn); @@ -86,18 +102,23 @@ export default class PopupService extends Component<{ } } +interface StateType extends PopupProps { + visible?: boolean, + offsetX?: number, + pos?: {top: number, height: number} +} export class PopupContent extends PureComponent<{ safeId?: string; popupContainer?: string }> { static contextType = PopupContext; popupContainerId = uniqueId('popupContainer'); - state: any = { + state: StateType = { visible: false, offsetX: -300, }; private dispose = (this.context as PopupPipe).onPopupChange((props, target) => { - const state: any = { + const state: StateType = { ...props, visible: true, }; @@ -132,7 +153,7 @@ export class PopupContent extends PureComponent<{ safeId?: string; popupContaine }; render() { - const { content, visible, title, actionKey, pos, offsetX } = this.state; + const { content, visible, title, actionKey, pos, offsetX, width = 360, hasMask = false, canCloseByOutSideClick = true, safeNode = [] } = this.state; if (!visible) { return null; } @@ -146,10 +167,10 @@ export class PopupContent extends PureComponent<{ safeId?: string; popupContaine return ( { if (avoidLaterHidden) { return; @@ -160,11 +181,11 @@ export class PopupContent extends PureComponent<{ safeId?: string; popupContaine }} trigger={
} triggerType="click" - canCloseByOutSideClick + canCloseByOutSideClick={canCloseByOutSideClick} animation={false} onClose={this.onClose} id={this.props.safeId} - safeNode={id} + safeNode={[id, ...safeNode]} closeable container={this.props.popupContainer} > From 04f5416050e4bf1f0fb286762eac1c023190033f Mon Sep 17 00:00:00 2001 From: JackLian Date: Thu, 27 Apr 2023 10:05:55 +0800 Subject: [PATCH 03/15] chore(docs): publish docs 1.0.28 --- docs/package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/package.json b/docs/package.json index 8c6e8a86c..80f146513 100644 --- a/docs/package.json +++ b/docs/package.json @@ -1,6 +1,6 @@ { "name": "@alilc/lowcode-engine-docs", - "version": "1.0.27", + "version": "1.0.28", "description": "低代码引擎版本化文档", "license": "MIT", "files": [ From ec4a95c9ba4de05c950ee7cd216311e225a2aef8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=A9=99=E6=9E=97?= Date: Thu, 27 Apr 2023 15:41:20 +0800 Subject: [PATCH 04/15] fix: fix proxy plugins.delete not added async --- packages/shell/src/api/plugins.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/shell/src/api/plugins.ts b/packages/shell/src/api/plugins.ts index e5a79edbd..b6f5e6371 100644 --- a/packages/shell/src/api/plugins.ts +++ b/packages/shell/src/api/plugins.ts @@ -66,8 +66,8 @@ export class Plugins implements IPublicApiPlugins { return this[pluginsSymbol].has(pluginName); } - delete(pluginName: string) { - this[pluginsSymbol].delete(pluginName); + async delete(pluginName: string) { + return await this[pluginsSymbol].delete(pluginName); } toProxy() { From 1bb46dcf3be698dd12bdecb6d9e03f673674365f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=A9=99=E6=9E=97?= Date: Thu, 4 May 2023 15:28:09 +0800 Subject: [PATCH 05/15] chore: safer plugins.delete --- packages/designer/src/plugin/plugin-manager.ts | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/packages/designer/src/plugin/plugin-manager.ts b/packages/designer/src/plugin/plugin-manager.ts index 449afebdf..071bfa9d1 100644 --- a/packages/designer/src/plugin/plugin-manager.ts +++ b/packages/designer/src/plugin/plugin-manager.ts @@ -143,11 +143,10 @@ export class LowCodePluginManager implements ILowCodePluginManager { } async delete(pluginName: string): Promise { - const idx = this.plugins.findIndex((plugin) => plugin.name === pluginName); - if (idx === -1) return false; - const plugin = this.plugins[idx]; + const plugin = this.plugins.find(({ name }) => name === pluginName); + if (!plugin) return false; await plugin.destroy(); - + const idx = this.plugins.indexOf(plugin); this.plugins.splice(idx, 1); return this.pluginsMap.delete(pluginName); } From 4db1971c3f84ff55d73e5b4199f52289f33dab54 Mon Sep 17 00:00:00 2001 From: milocooper Date: Wed, 3 May 2023 21:24:37 +0800 Subject: [PATCH 06/15] fix: Corrects the fourth heading name related to how drag is made in edit page documents. --- docs/docs/guide/design/editor.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/docs/guide/design/editor.md b/docs/docs/guide/design/editor.md index fcead2922..0614d9c33 100644 --- a/docs/docs/guide/design/editor.md +++ b/docs/docs/guide/design/editor.md @@ -336,7 +336,7 @@ simulator-renderer 通过调用 host 的方法,将 schema、components 等参 1. **画布内拖拽:**此时 sensor 是 simulatorHost,拖拽完成之后,会根据拖拽的位置来完成节点的精确插入。 2. **从组件面板拖拽到画布**:此时的 sensor 还是 simulatorHost,因为拖拽结束的目标还是画布。 3. **大纲树面板拖拽到画布中**:此时有两个 sensor,一个是大纲树,当我们拖拽到画布区域时,画布区域内的 simulatorHost 开始接管。 -4. **画布拖拽到画布中**:从画布中开始拖拽时,最新生效的是 simulatorHost,当离开画布到大纲树时,大纲树 sensor 开始接管生效。当拖拽到大纲树的某一个节点下时,大纲树会将大纲树中的信息转化为 schema,然后渲染到画布中。 +4. **画布拖拽到大纲树中**:从画布中开始拖拽时,最新生效的是 simulatorHost,当离开画布到大纲树时,大纲树 sensor 开始接管生效。当拖拽到大纲树的某一个节点下时,大纲树会将大纲树中的信息转化为 schema,然后渲染到画布中。 ### 其他 引擎的编排能力远远不止上述所描述的功能,这里只描述了其核心和关键的功能。在整个引擎的迭代和设计过程中还有很多细节来使我们的引擎更好用、更容易扩展。 From 57889d5ad02aa2a3418ab3dc719e9a60aef2a3dc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?LeoYuan=20=E8=A2=81=E5=8A=9B=E7=9A=93?= Date: Thu, 4 May 2023 17:01:02 +0800 Subject: [PATCH 07/15] fix: use noop function instead --- modules/code-generator/src/plugins/component/react/jsx.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modules/code-generator/src/plugins/component/react/jsx.ts b/modules/code-generator/src/plugins/component/react/jsx.ts index 7cf5bd9de..588b356ad 100644 --- a/modules/code-generator/src/plugins/component/react/jsx.ts +++ b/modules/code-generator/src/plugins/component/react/jsx.ts @@ -58,7 +58,7 @@ const pluginFactory: BuilderComponentPluginFactory = (config?) => generateCompositeType( { type: 'JSFunction', - value: input.value || 'null', + value: input.value || 'function () {}', }, Scope.createRootScope(), ), From 9a68f0f27c062b637ace824eca7ccaa6ed9573b6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?LeoYuan=20=E8=A2=81=E5=8A=9B=E7=9A=93?= Date: Thu, 4 May 2023 17:02:17 +0800 Subject: [PATCH 08/15] fix: attr name in IPublicTypePanelDockConfig should not be optional --- packages/types/src/shell/type/widget-base-config.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/types/src/shell/type/widget-base-config.ts b/packages/types/src/shell/type/widget-base-config.ts index f8268628b..edddf2d68 100644 --- a/packages/types/src/shell/type/widget-base-config.ts +++ b/packages/types/src/shell/type/widget-base-config.ts @@ -25,7 +25,7 @@ export interface IPublicTypePanelDockConfig extends IPublicTypeWidgetBaseConfig props?: IPublicTypePanelDockProps; /** 面板 name, 当没有 props.title 时, 会使用 name 作为标题 */ - name?: string; + name: string; } export interface IPublicTypePanelDockProps { From 5b68b860acdcd078d7a9bb6acd18cb01d51a4552 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?LeoYuan=20=E8=A2=81=E5=8A=9B=E7=9A=93?= Date: Thu, 4 May 2023 17:03:37 +0800 Subject: [PATCH 09/15] refactor: moduleName of Component should not be converted --- modules/code-generator/src/parser/SchemaParser.ts | 5 +++-- .../src/plugins/component/react/containerClass.ts | 2 +- modules/code-generator/src/utils/schema.ts | 6 ++++++ 3 files changed, 10 insertions(+), 3 deletions(-) diff --git a/modules/code-generator/src/parser/SchemaParser.ts b/modules/code-generator/src/parser/SchemaParser.ts index 3108fee47..c6263877c 100644 --- a/modules/code-generator/src/parser/SchemaParser.ts +++ b/modules/code-generator/src/parser/SchemaParser.ts @@ -32,7 +32,7 @@ import { import { SUPPORT_SCHEMA_VERSION_LIST } from '../const'; import { getErrorMessage } from '../utils/errors'; -import { handleSubNodes, isValidContainerType } from '../utils/schema'; +import { handleSubNodes, isValidContainerType, ContainerType } from '../utils/schema'; import { uniqueArray } from '../utils/common'; import { componentAnalyzer } from '../analyzer/componentAnalyzer'; import { ensureValidClassName } from '../utils/validate'; @@ -161,7 +161,8 @@ export class SchemaParser implements ISchemaParser { ...subRoot, componentName: getRootComponentName(subRoot.componentName, compDeps), containerType: subRoot.componentName, - moduleName: ensureValidClassName(changeCase.pascalCase(subRoot.fileName)), + moduleName: ensureValidClassName(subRoot.componentName === ContainerType.Component ? + subRoot.fileName : changeCase.pascalCase(subRoot.fileName)), }; return container; }); diff --git a/modules/code-generator/src/plugins/component/react/containerClass.ts b/modules/code-generator/src/plugins/component/react/containerClass.ts index b4c474b38..eab6cbebe 100644 --- a/modules/code-generator/src/plugins/component/react/containerClass.ts +++ b/modules/code-generator/src/plugins/component/react/containerClass.ts @@ -48,7 +48,7 @@ const pluginFactory: BuilderComponentPluginFactory = () => { type: ChunkType.STRING, fileType: FileType.JSX, name: CLASS_DEFINE_CHUNK_NAME.InsVar, - content: `static displayName = '${changeCase.pascalCase(ir.moduleName)}';`, + content: `static displayName = '${ir.moduleName}';`, linkAfter: [ CLASS_DEFINE_CHUNK_NAME.Start, ], diff --git a/modules/code-generator/src/utils/schema.ts b/modules/code-generator/src/utils/schema.ts index 831b38965..f9529945e 100644 --- a/modules/code-generator/src/utils/schema.ts +++ b/modules/code-generator/src/utils/schema.ts @@ -147,4 +147,10 @@ export function isValidContainerType(schema: IPublicTypeNodeSchema) { 'Component', 'Block', ].includes(schema.componentName); +} + +export const enum ContainerType { + Page = 'Page', + Component = 'Component', + Block = 'Block', } \ No newline at end of file From b695bdaadb47db02dd85ea59b8df3739927fd164 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?LeoYuan=20=E8=A2=81=E5=8A=9B=E7=9A=93?= Date: Sat, 6 May 2023 17:08:58 +0800 Subject: [PATCH 10/15] chore(release): code-generator - 1.1.1 --- modules/code-generator/package.json | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/modules/code-generator/package.json b/modules/code-generator/package.json index 97d945469..8fc9ef953 100644 --- a/modules/code-generator/package.json +++ b/modules/code-generator/package.json @@ -1,6 +1,6 @@ { "name": "@alilc/lowcode-code-generator", - "version": "1.1.0", + "version": "1.1.1", "description": "出码引擎 for LowCode Engine", "license": "MIT", "main": "lib/index.js", @@ -145,4 +145,4 @@ "registry": "https://registry.npmjs.org/" }, "repository": "git@github.com:alibaba/lowcode-engine.git" -} \ No newline at end of file +} From 9410d21de3f7a86769b37038b3b49365cc84511e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?LeoYuan=20=E8=A2=81=E5=8A=9B=E7=9A=93?= Date: Sat, 6 May 2023 17:11:26 +0800 Subject: [PATCH 11/15] chore(release): code-generator - 1.1.2 --- modules/code-generator/package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modules/code-generator/package.json b/modules/code-generator/package.json index 8fc9ef953..f830b23ed 100644 --- a/modules/code-generator/package.json +++ b/modules/code-generator/package.json @@ -1,6 +1,6 @@ { "name": "@alilc/lowcode-code-generator", - "version": "1.1.1", + "version": "1.1.2", "description": "出码引擎 for LowCode Engine", "license": "MIT", "main": "lib/index.js", From 9947a36d1778e9cf76740b4d8bf4a6b134d1e74e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?LeoYuan=20=E8=A2=81=E5=8A=9B=E7=9A=93?= Date: Sat, 6 May 2023 17:46:53 +0800 Subject: [PATCH 12/15] refactor: synchronize exports of standalone with the normal entry --- modules/code-generator/src/index.ts | 4 +-- modules/code-generator/src/standalone.ts | 31 ++++++++++++++++++------ 2 files changed, 26 insertions(+), 9 deletions(-) diff --git a/modules/code-generator/src/index.ts b/modules/code-generator/src/index.ts index 0c8fdf384..da9b12d87 100644 --- a/modules/code-generator/src/index.ts +++ b/modules/code-generator/src/index.ts @@ -9,7 +9,7 @@ import { createModuleBuilder } from './generator/ModuleBuilder'; import { createDiskPublisher } from './publisher/disk'; import { createZipPublisher } from './publisher/zip'; import createIceJsProjectBuilder, { plugins as icejsPlugins } from './solutions/icejs'; -import createIce3JsProjectBuilder, { plugins as icejs3Plugins } from './solutions/icejs3'; +import createIceJs3ProjectBuilder, { plugins as icejs3Plugins } from './solutions/icejs3'; import createRaxAppProjectBuilder, { plugins as raxPlugins } from './solutions/rax-app'; // 引入说明 @@ -42,7 +42,7 @@ export default { createModuleBuilder, solutions: { icejs: createIceJsProjectBuilder, - icejs3: createIce3JsProjectBuilder, + icejs3: createIceJs3ProjectBuilder, rax: createRaxAppProjectBuilder, }, solutionParts: { diff --git a/modules/code-generator/src/standalone.ts b/modules/code-generator/src/standalone.ts index 2f15515cf..23d16e61f 100644 --- a/modules/code-generator/src/standalone.ts +++ b/modules/code-generator/src/standalone.ts @@ -8,7 +8,8 @@ import './polyfills/buffer'; import { createProjectBuilder } from './generator/ProjectBuilder'; import { createModuleBuilder } from './generator/ModuleBuilder'; import { createZipPublisher } from './publisher/zip'; -import createIceJsProjectBuilder, { plugins as reactPlugins } from './solutions/icejs'; +import createIceJsProjectBuilder, { plugins as icejsPlugins } from './solutions/icejs'; +import createIceJs3ProjectBuilder, { plugins as icejs3Plugins } from './solutions/icejs3'; import createRaxAppProjectBuilder, { plugins as raxPlugins } from './solutions/rax-app'; // 引入说明 @@ -18,6 +19,7 @@ import { COMMON_CHUNK_NAME, CLASS_DEFINE_CHUNK_NAME, DEFAULT_LINK_AFTER } from ' // 引入通用插件组 import esmodule from './plugins/common/esmodule'; import requireUtils from './plugins/common/requireUtils'; +import styleImport from './plugins/common/styleImport'; import css from './plugins/component/style/css'; import constants from './plugins/project/constants'; @@ -32,6 +34,7 @@ import * as CONSTANTS from './const'; // 引入内置解决方案模块 import icejs from './plugins/project/framework/icejs'; +import icejs3 from './plugins/project/framework/icejs3'; import rax from './plugins/project/framework/rax'; export default { @@ -39,10 +42,12 @@ export default { createModuleBuilder, solutions: { icejs: createIceJsProjectBuilder, + icejs3: createIceJs3ProjectBuilder, rax: createRaxAppProjectBuilder, }, solutionParts: { icejs, + icejs3, rax, }, publishers: { @@ -50,6 +55,7 @@ export default { }, plugins: { common: { + /** * 处理 ES Module * @deprecated please use esModule @@ -57,12 +63,7 @@ export default { esmodule, esModule: esmodule, requireUtils, - }, - react: { - ...reactPlugins, - }, - rax: { - ...raxPlugins, + styleImport, }, style: { css, @@ -72,6 +73,22 @@ export default { i18n, utils, }, + icejs: { + ...icejsPlugins, + }, + icejs3: { + ...icejs3Plugins, + }, + rax: { + ...raxPlugins, + }, + + /** + * @deprecated please use icejs + */ + react: { + ...icejsPlugins, + }, }, postprocessor: { prettier, From 239bb29de1853c87f687a4355df76179a09d5ae5 Mon Sep 17 00:00:00 2001 From: liujuping Date: Thu, 11 May 2023 10:01:56 +0800 Subject: [PATCH 13/15] feat: add skeleton item model --- .../designer/src/document/document-model.ts | 2 +- .../designer/src/document/node/props/prop.ts | 4 +++ packages/designer/src/project/project.ts | 8 ++--- packages/editor-skeleton/src/skeleton.ts | 7 +++-- packages/editor-skeleton/src/widget/panel.ts | 4 +++ packages/engine/src/modules/classes.ts | 2 ++ packages/engine/src/modules/symbols.ts | 2 ++ packages/shell/src/api/skeleton.ts | 18 ++++++++--- packages/shell/src/index.ts | 2 ++ packages/shell/src/model/index.ts | 1 + packages/shell/src/model/skeleton-item.ts | 31 +++++++++++++++++++ packages/shell/src/symbols.ts | 3 +- packages/types/src/shell/api/skeleton.ts | 3 +- packages/types/src/shell/model/index.ts | 1 + .../types/src/shell/model/skeleton-item.ts | 6 ++++ .../workspace/src/context/view-context.ts | 2 ++ 16 files changed, 83 insertions(+), 13 deletions(-) create mode 100644 packages/shell/src/model/skeleton-item.ts create mode 100644 packages/types/src/shell/model/skeleton-item.ts diff --git a/packages/designer/src/document/document-model.ts b/packages/designer/src/document/document-model.ts index 699775bc7..2d39ed115 100644 --- a/packages/designer/src/document/document-model.ts +++ b/packages/designer/src/document/document-model.ts @@ -141,7 +141,7 @@ export interface IDocumentModel extends Omit, 'exportSchema' | 'node'>, IPropParent { + spread: boolean; + key: string | number | undefined; readonly props: IProps; @@ -42,6 +44,8 @@ export interface IProp extends Omit item.fileName === doc || item.id === doc); + if (typeof doc === 'string' || typeof doc === 'number') { + const got = this.documents.find((item) => item.fileName === String(doc) || String(item.id) === String(doc)); if (got) { return got.open(); } - const data = this.data.componentsTree.find((data) => data.fileName === doc); + const data = this.data.componentsTree.find((data) => data.fileName === String(doc)); if (data) { doc = this.createDocument(data); return doc.open(); diff --git a/packages/editor-skeleton/src/skeleton.ts b/packages/editor-skeleton/src/skeleton.ts index 180859f1d..616e7f017 100644 --- a/packages/editor-skeleton/src/skeleton.ts +++ b/packages/editor-skeleton/src/skeleton.ts @@ -56,7 +56,8 @@ export interface ISkeleton extends Omit { editor: IEditor; @@ -101,6 +102,8 @@ export interface ISkeleton extends Omit): IWidget | Widget | Panel | Stage | Dock | PanelDock | undefined; } export class Skeleton { @@ -440,7 +443,7 @@ export class Skeleton { return restConfig; } - add(config: IPublicTypeSkeletonConfig, extraConfig?: Record) { + add(config: IPublicTypeSkeletonConfig, extraConfig?: Record): IWidget | Widget | Panel | Stage | Dock | PanelDock | undefined { const parsedConfig = { ...this.parseConfig(config), ...extraConfig, diff --git a/packages/editor-skeleton/src/widget/panel.ts b/packages/editor-skeleton/src/widget/panel.ts index feec08da7..b35af6a21 100644 --- a/packages/editor-skeleton/src/widget/panel.ts +++ b/packages/editor-skeleton/src/widget/panel.ts @@ -211,6 +211,10 @@ export class Panel implements IWidget { this.setActive(false); } + disable() {} + + enable(): void {} + show() { this.setActive(true); } diff --git a/packages/engine/src/modules/classes.ts b/packages/engine/src/modules/classes.ts index 44aeed965..d68ea43de 100644 --- a/packages/engine/src/modules/classes.ts +++ b/packages/engine/src/modules/classes.ts @@ -10,6 +10,7 @@ import { Selection, Prop, SimulatorHost, + SkeletonItem, } from '@alilc/lowcode-shell'; import { Node as InnerNode } from '@alilc/lowcode-designer'; @@ -26,4 +27,5 @@ export default { Selection, Prop, SimulatorHost, + SkeletonItem, }; diff --git a/packages/engine/src/modules/symbols.ts b/packages/engine/src/modules/symbols.ts index 7faccff51..a0371abf9 100644 --- a/packages/engine/src/modules/symbols.ts +++ b/packages/engine/src/modules/symbols.ts @@ -11,6 +11,7 @@ import { designerCabinSymbol, propSymbol, simulatorHostSymbol, + skeletonItemSymbol, } from '@alilc/lowcode-shell'; export default { @@ -26,4 +27,5 @@ export default { designerCabinSymbol, propSymbol, simulatorHostSymbol, + skeletonItemSymbol, }; diff --git a/packages/shell/src/api/skeleton.ts b/packages/shell/src/api/skeleton.ts index cb5c8f8aa..b48747598 100644 --- a/packages/shell/src/api/skeleton.ts +++ b/packages/shell/src/api/skeleton.ts @@ -4,8 +4,9 @@ import { SkeletonEvents, } from '@alilc/lowcode-editor-skeleton'; import { skeletonSymbol } from '../symbols'; -import { IPublicApiSkeleton, IPublicTypeDisposable, IPublicTypeSkeletonConfig, IPublicTypeWidgetConfigArea } from '@alilc/lowcode-types'; +import { IPublicApiSkeleton, IPublicModelSkeletonItem, IPublicTypeDisposable, IPublicTypeSkeletonConfig, IPublicTypeWidgetConfigArea } from '@alilc/lowcode-types'; import { getLogger } from '@alilc/lowcode-utils'; +import { SkeletonItem } from '../model/skeleton-item'; const innerSkeletonSymbol = Symbol('skeleton'); @@ -46,12 +47,15 @@ export class Skeleton implements IPublicApiSkeleton { * @param extraConfig * @returns */ - add(config: IPublicTypeSkeletonConfig, extraConfig?: Record) { + add(config: IPublicTypeSkeletonConfig, extraConfig?: Record): IPublicModelSkeletonItem | undefined { const configWithName = { ...config, pluginName: this.pluginName, }; - return this[skeletonSymbol].add(configWithName, extraConfig); + const item = this[skeletonSymbol].add(configWithName, extraConfig); + if (item) { + return new SkeletonItem(item); + } } /** @@ -68,6 +72,10 @@ export class Skeleton implements IPublicApiSkeleton { skeleton[normalizeArea(area)].container?.remove(name); } + getAreaItems(areaName: IPublicTypeWidgetConfigArea): IPublicModelSkeletonItem[] { + return this[skeletonSymbol][normalizeArea(areaName)].container.items?.map(d => new SkeletonItem(d)); + } + /** * 显示面板 * @param name @@ -193,7 +201,7 @@ export class Skeleton implements IPublicApiSkeleton { } } -function normalizeArea(area: IPublicTypeWidgetConfigArea | undefined): 'leftArea' | 'rightArea' | 'topArea' | 'toolbar' | 'mainArea' | 'bottomArea' | 'leftFixedArea' | 'leftFloatArea' | 'stages' { +function normalizeArea(area: IPublicTypeWidgetConfigArea | undefined): 'leftArea' | 'rightArea' | 'topArea' | 'toolbar' | 'mainArea' | 'bottomArea' | 'leftFixedArea' | 'leftFloatArea' | 'stages' | 'subTopArea' { switch (area) { case 'leftArea': case 'left': @@ -220,6 +228,8 @@ function normalizeArea(area: IPublicTypeWidgetConfigArea | undefined): 'leftArea return 'leftFloatArea'; case 'stages': return 'stages'; + case 'subTopArea': + return 'subTopArea'; default: throw new Error(`${area} not supported`); } diff --git a/packages/shell/src/index.ts b/packages/shell/src/index.ts index b3fca90b0..6f79c78bc 100644 --- a/packages/shell/src/index.ts +++ b/packages/shell/src/index.ts @@ -11,6 +11,7 @@ import { Clipboard, SettingField, Window, + SkeletonItem, } from './model'; import { Project, @@ -66,4 +67,5 @@ export { SimulatorHost, Config, SettingField, + SkeletonItem, }; diff --git a/packages/shell/src/model/index.ts b/packages/shell/src/model/index.ts index 8b668c947..a15d50b54 100644 --- a/packages/shell/src/model/index.ts +++ b/packages/shell/src/model/index.ts @@ -20,3 +20,4 @@ export * from './plugin-instance'; export * from './window'; export * from './clipboard'; export * from './editor-view'; +export * from './skeleton-item'; diff --git a/packages/shell/src/model/skeleton-item.ts b/packages/shell/src/model/skeleton-item.ts new file mode 100644 index 000000000..b91e5a19a --- /dev/null +++ b/packages/shell/src/model/skeleton-item.ts @@ -0,0 +1,31 @@ +import { skeletonItemSymbol } from '../symbols'; +import { IPublicModelSkeletonItem } from '@alilc/lowcode-types'; +import { Dock, IWidget, Panel, PanelDock, Stage, Widget } from '@alilc/lowcode-editor-skeleton'; + +export class SkeletonItem implements IPublicModelSkeletonItem { + private [skeletonItemSymbol]: IWidget | Widget | Panel | Stage | Dock | PanelDock; + + constructor(skeletonItem: IWidget | Widget | Panel | Stage | Dock | PanelDock) { + this[skeletonItemSymbol] = skeletonItem; + } + + get name() { + return this[skeletonItemSymbol].name; + } + + disable() { + this[skeletonItemSymbol].disable?.(); + } + + enable() { + this[skeletonItemSymbol].enable?.(); + } + + hide() { + this[skeletonItemSymbol].hide(); + } + + show() { + this[skeletonItemSymbol].show(); + } +} \ No newline at end of file diff --git a/packages/shell/src/symbols.ts b/packages/shell/src/symbols.ts index 48d6a9656..b4ec01c7e 100644 --- a/packages/shell/src/symbols.ts +++ b/packages/shell/src/symbols.ts @@ -35,4 +35,5 @@ export const clipboardSymbol = Symbol('clipboard'); export const configSymbol = Symbol('configSymbol'); export const conditionGroupSymbol = Symbol('conditionGroup'); export const editorViewSymbol = Symbol('editorView'); -export const pluginContextSymbol = Symbol('pluginContext'); \ No newline at end of file +export const pluginContextSymbol = Symbol('pluginContext'); +export const skeletonItemSymbol = Symbol('skeletonItem'); \ No newline at end of file diff --git a/packages/types/src/shell/api/skeleton.ts b/packages/types/src/shell/api/skeleton.ts index b22b3586c..13ba3468b 100644 --- a/packages/types/src/shell/api/skeleton.ts +++ b/packages/types/src/shell/api/skeleton.ts @@ -1,3 +1,4 @@ +import { IPublicModelSkeletonItem } from '../model'; import { IPublicTypeDisposable, IPublicTypeSkeletonConfig } from '../type'; export interface IPublicApiSkeleton { @@ -9,7 +10,7 @@ export interface IPublicApiSkeleton { * @param extraConfig * @returns */ - add(config: IPublicTypeSkeletonConfig, extraConfig?: Record): any; + add(config: IPublicTypeSkeletonConfig, extraConfig?: Record): IPublicModelSkeletonItem | undefined; /** * 移除一个面板实例 diff --git a/packages/types/src/shell/model/index.ts b/packages/types/src/shell/model/index.ts index e310128ca..1924f1121 100644 --- a/packages/types/src/shell/model/index.ts +++ b/packages/types/src/shell/model/index.ts @@ -31,3 +31,4 @@ export * from './resource'; export * from './clipboard'; export * from './setting-field'; export * from './editor-view'; +export * from './skeleton-item'; diff --git a/packages/types/src/shell/model/skeleton-item.ts b/packages/types/src/shell/model/skeleton-item.ts new file mode 100644 index 000000000..ca262ccbf --- /dev/null +++ b/packages/types/src/shell/model/skeleton-item.ts @@ -0,0 +1,6 @@ +/** + * @since 1.1.7 + */ +export interface IPublicModelSkeletonItem { + +} \ No newline at end of file diff --git a/packages/workspace/src/context/view-context.ts b/packages/workspace/src/context/view-context.ts index 7dfc66393..ff4c12eee 100644 --- a/packages/workspace/src/context/view-context.ts +++ b/packages/workspace/src/context/view-context.ts @@ -7,7 +7,9 @@ import { IEditorWindow } from '../window'; import { getWebviewPlugin } from '../inner-plugins/webview'; export interface IViewContext extends IBasicContext { + editorWindow: IEditorWindow; + viewName: string; } export class Context extends BasicContext implements IViewContext { From 8ac68b982b29493f9b367d1e96cf4ef49ff1bdd5 Mon Sep 17 00:00:00 2001 From: liujuping Date: Thu, 11 May 2023 10:08:27 +0800 Subject: [PATCH 14/15] feat: support reset locale config --- packages/plugin-designer/src/index.tsx | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/packages/plugin-designer/src/index.tsx b/packages/plugin-designer/src/index.tsx index d40609c48..54eda1365 100644 --- a/packages/plugin-designer/src/index.tsx +++ b/packages/plugin-designer/src/index.tsx @@ -62,6 +62,11 @@ export default class DesignerPlugin extends PureComponent { + this.setState({ + locale, + }); + }); const { components, packages, extraEnvironment, utils } = assets; const state = { componentMetadatas: components || [], From 22d2fddc3e999dc8516f2d5b0e2b57527efbe741 Mon Sep 17 00:00:00 2001 From: liujuping Date: Thu, 11 May 2023 10:11:33 +0800 Subject: [PATCH 15/15] feat: workspace add onChangeActiveWindow event api --- packages/shell/src/api/workspace.ts | 4 ++++ packages/shell/src/model/editor-view.ts | 2 +- packages/workspace/src/window.ts | 7 +++++-- packages/workspace/src/workspace.ts | 18 ++++++++++++++++++ 4 files changed, 28 insertions(+), 3 deletions(-) diff --git a/packages/shell/src/api/workspace.ts b/packages/shell/src/api/workspace.ts index 9676b8522..bfc7b27e1 100644 --- a/packages/shell/src/api/workspace.ts +++ b/packages/shell/src/api/workspace.ts @@ -73,4 +73,8 @@ export class Workspace implements IPublicApiWorkspace { onChangeActiveWindow(fn: () => void): IPublicTypeDisposable { return this[workspaceSymbol].onChangeActiveWindow(fn); } + + onChangeActiveEditorView(fn: () => void): IPublicTypeDisposable { + return this[workspaceSymbol].onChangeActiveEditorView(fn); + } } diff --git a/packages/shell/src/model/editor-view.ts b/packages/shell/src/model/editor-view.ts index 31027a5de..d70a109b1 100644 --- a/packages/shell/src/model/editor-view.ts +++ b/packages/shell/src/model/editor-view.ts @@ -10,7 +10,7 @@ export class EditorView { constructor(editorView: IViewContext) { this[editorViewSymbol] = editorView; this[pluginContextSymbol] = this[editorViewSymbol].innerPlugins._getLowCodePluginContext({ - pluginName: '', + pluginName: editorView.editorWindow + editorView.viewName, }); } diff --git a/packages/workspace/src/window.ts b/packages/workspace/src/window.ts index 92b707851..41b9c53ea 100644 --- a/packages/workspace/src/window.ts +++ b/packages/workspace/src/window.ts @@ -3,8 +3,7 @@ import { createModuleEventBus, IEventBus, makeObservable, obx } from '@alilc/low import { Context, IViewContext } from './context/view-context'; import { IWorkspace } from './workspace'; import { IResource } from './resource'; -import { IPublicTypeDisposable } from '../../types/es/shell/type/disposable'; -import { IPublicModelWindow } from '@alilc/lowcode-types'; +import { IPublicModelWindow, IPublicTypeDisposable } from '@alilc/lowcode-types'; interface IWindowCOnfig { title: string | undefined; @@ -158,6 +157,10 @@ export class EditorWindow implements IEditorWindow { if (!ignoreEmit) { this.emitter.emit('window.change.view.type', name); + + if (this.id === this.workspace.window.id) { + this.workspace.emitChangeActiveEditorView(); + } } this.editorView.setActivate(true); }; diff --git a/packages/workspace/src/workspace.ts b/packages/workspace/src/workspace.ts index 26e1d6551..33daf064a 100644 --- a/packages/workspace/src/workspace.ts +++ b/packages/workspace/src/workspace.ts @@ -13,6 +13,8 @@ enum EVENT { CHANGE_ACTIVE_WINDOW = 'change_active_window', WINDOW_RENDER_READY = 'window_render_ready', + + CHANGE_ACTIVE_EDITOR_VIEW = 'change_active_editor_view', } const CHANGE_EVENT = 'resource.list.change'; @@ -42,6 +44,10 @@ export interface IWorkspace extends Omit void): IPublicTypeDisposable; + + emitChangeActiveEditorView(): void; } export class Workspace implements IWorkspace { @@ -258,12 +264,24 @@ export class Workspace implements IWorkspace { }; } + onChangeActiveEditorView(fn: () => void) { + this.emitter.on(EVENT.CHANGE_ACTIVE_EDITOR_VIEW, fn); + return () => { + this.emitter.removeListener(EVENT.CHANGE_ACTIVE_EDITOR_VIEW, fn); + }; + } + + emitChangeActiveEditorView() { + this.emitter.emit(EVENT.CHANGE_ACTIVE_EDITOR_VIEW); + } + emitChangeWindow() { this.emitter.emit(EVENT.CHANGE_WINDOW); } emitChangeActiveWindow() { this.emitter.emit(EVENT.CHANGE_ACTIVE_WINDOW); + this.emitChangeActiveEditorView(); } onChangeActiveWindow(fn: () => void) {