Skip to content

Commit e2b3215

Browse files
author
taojiu
committed
refactor(editor-skeleton): 调整getEvent处理,解决循环引用问题
- 更新 context-menu-actions 中的节点创建方式 - 调整 designer 组件中的 shellModelFactory 为必选属性 - 移除 editor-skeleton 中对 lowcode-shell 的依赖 - 更新 widget 组件中的事件创建方式 - 为 shell-model-factory 接口添加 createEvent 方法
1 parent ce4d0a5 commit e2b3215

File tree

8 files changed

+18
-16
lines changed

8 files changed

+18
-16
lines changed

packages/designer/src/context-menu-actions.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -186,7 +186,7 @@ export class ContextMenuActions implements IContextMenuActions {
186186
) as IPublicModelPluginContext;
187187

188188
const menus: IPublicTypeContextMenuItem[] = parseContextMenuProperties(actions, {
189-
nodes: nodes.map((d) => designer.shellModelFactory!.createNode(d)!),
189+
nodes: nodes.map((d) => designer.shellModelFactory.createNode(d)!),
190190
destroy,
191191
event,
192192
pluginContext,

packages/designer/src/designer/designer.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ const logger = new Logger({ level: 'warn', bizName: 'designer' });
6363
export interface DesignerProps {
6464
[key: string]: any;
6565
editor: IPublicModelEditor;
66-
shellModelFactory?: IShellModelFactory;
66+
shellModelFactory: IShellModelFactory;
6767
className?: string;
6868
style?: object;
6969
defaultSchema?: IPublicTypeProjectSchema;
@@ -85,7 +85,7 @@ export interface DesignerProps {
8585
}
8686

8787
export interface IDesigner {
88-
readonly shellModelFactory?: IShellModelFactory;
88+
readonly shellModelFactory: IShellModelFactory;
8989

9090
viewName: string | undefined;
9191

@@ -172,7 +172,7 @@ export class Designer implements IDesigner {
172172

173173
readonly bemToolsManager = new BemToolsManager(this);
174174

175-
readonly shellModelFactory?: IShellModelFactory;
175+
readonly shellModelFactory: IShellModelFactory;
176176

177177
private _dropLocation?: DropLocation;
178178

packages/editor-skeleton/package.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@
2020
"@alifd/next": "^1.27.30",
2121
"@felce/lowcode-designer": "1.5.1-beta.3",
2222
"@felce/lowcode-editor-core": "1.5.1-beta.3",
23-
"@felce/lowcode-shell": "1.5.1-beta.3",
2423
"@felce/lowcode-types": "1.5.1-beta.3",
2524
"@felce/lowcode-utils": "1.5.1-beta.3",
2625
"classnames": "^2.5.1",

packages/editor-skeleton/src/widget/dock.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
import { ReactNode, createElement } from 'react';
22
import { makeObservable, obx } from '@felce/lowcode-editor-core';
33
import { uniqueId, createContent } from '@felce/lowcode-utils';
4-
import { getEvent } from '@felce/lowcode-shell';
54
import { DockConfig } from '../types';
65
import { ISkeleton } from '../skeleton';
76
import { DockView, WidgetView } from '../components/widget-views';
@@ -46,10 +45,11 @@ export class Dock implements IWidget {
4645
const { props, content, contentProps } = this.config;
4746

4847
if (content) {
48+
const designer = this.skeleton.editor.get('designer');
4949
this._body = createContent(content, {
5050
...contentProps,
5151
config: this.config,
52-
editor: getEvent(this.skeleton.editor),
52+
editor: designer.shellModelFactory.createEvent(this.skeleton.editor),
5353
});
5454
} else {
5555
this._body = createElement(DockView, props);

packages/editor-skeleton/src/widget/panel.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@ import {
1313
IPublicTypeTitleContent,
1414
} from '@felce/lowcode-types';
1515
import { WidgetContainer } from './widget-container';
16-
import { getEvent } from '@felce/lowcode-shell';
1716
import { TitledPanelView, TabsPanelView, PanelView } from '../components/widget-views';
1817
import { ISkeleton } from '../skeleton';
1918
import { composeTitle } from './utils';
@@ -66,9 +65,10 @@ export class Panel implements IWidget {
6665
return null;
6766
}
6867

68+
const designer = this.skeleton.editor.get('designer');
6969
return createContent(content, {
7070
...contentProps,
71-
editor: getEvent(this.skeleton.editor),
71+
editor: designer.shellModelFactory.createEvent(this.skeleton.editor),
7272
config: this.config,
7373
panel: this,
7474
pane: this,

packages/editor-skeleton/src/widget/widget.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,13 @@
11
import { ReactNode, createElement } from 'react';
22
import { makeObservable, obx } from '@felce/lowcode-editor-core';
33
import { createContent, uniqueId } from '@felce/lowcode-utils';
4-
import { getEvent } from '@felce/lowcode-shell';
54
import { WidgetConfig } from '../types';
65
import { ISkeleton } from '../skeleton';
76
import { WidgetView } from '../components/widget-views';
87
import { IPublicModelWidget, IPublicTypeTitleContent } from '@felce/lowcode-types';
98

109
export interface IWidget extends Omit<IPublicModelWidget, 'skeleton'> {
11-
skeleton: ISkeleton
10+
skeleton: ISkeleton;
1211
}
1312

1413
export class Widget implements IWidget {
@@ -38,10 +37,11 @@ export class Widget implements IWidget {
3837
}
3938
this.inited = true;
4039
const { content, contentProps } = this.config;
40+
const designer = this.skeleton.editor.get('designer');
4141
this._body = createContent(content, {
4242
...contentProps,
4343
config: this.config,
44-
editor: getEvent(this.skeleton.editor),
44+
editor: designer.shellModelFactory.createEvent(this.skeleton.editor),
4545
});
4646
return this._body;
4747
}
Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,15 @@
11
import { INode, ISettingField } from '@felce/lowcode-designer';
2-
import { IShellModelFactory, IPublicModelNode } from '@felce/lowcode-types';
2+
import { Node, SettingField, getEvent } from '@felce/lowcode-shell';
3+
import { IPublicModelNode, IShellModelFactory } from '@felce/lowcode-types';
34
import { IPublicModelSettingField } from '../../../types/src/shell/model/setting-field';
4-
import { Node, SettingField } from '@felce/lowcode-shell';
5+
56
class ShellModelFactory implements IShellModelFactory {
67
createNode(node: INode | null | undefined): IPublicModelNode | null {
78
return Node.create(node);
89
}
910
createSettingField(prop: ISettingField): IPublicModelSettingField {
1011
return SettingField.create(prop);
1112
}
13+
createEvent = getEvent;
1214
}
1315
export const shellModelFactory = new ShellModelFactory();
Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
1-
import { IPublicModelNode, IPublicModelSettingField } from './shell';
1+
import { IPublicApiEvent, IPublicModelNode, IPublicModelSettingField } from './shell';
22

33
export interface IShellModelFactory {
44
// TODO: 需要给 innerNode 提供一个 interface 并用在这里
55
createNode(node: any | null | undefined): IPublicModelNode | null;
66
// TODO: 需要给 InnerSettingField 提供一个 interface 并用在这里
7-
87
createSettingField(prop: any): IPublicModelSettingField;
8+
// TODO: 需要给 InnerEditor 提供一个 interface 并用在这里
9+
createEvent(editor: any, options: any): IPublicApiEvent;
910
}

0 commit comments

Comments
 (0)