Skip to content

Commit 20c8419

Browse files
JackLianliujuping
authored andcommitted
feat: feat: remove circular dependency between designer and shell
1 parent da010ee commit 20c8419

File tree

8 files changed

+86
-54
lines changed

8 files changed

+86
-54
lines changed

docs/docs/api/plugins.md

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -223,15 +223,16 @@ plugins.delete('builtinPluginRegistry');
223223
**类型定义**
224224
```typescript
225225
export interface ILowCodePluginContext {
226-
skeleton: Skeleton; // 参考面板 API
227-
hotkey: Hotkey; // 参考快捷键 API
228-
logger: Logger; // 参考日志 API
229-
plugins: ILowCodePluginManager; // 参考插件 API
230-
setters: Setters; // 参考设置器 API
231-
config: EngineConfig; // 参考配置 API
232-
material: Material; // 参考物料 API
233-
event: Event; // 参考事件 API
234-
project: Project; // 参考模型 API
226+
skeleton: Skeleton; // 参考面板 API
227+
hotkey: Hotkey; // 参考快捷键 API
228+
setters: Setters; // 参考设置器 API
229+
config: EngineConfig; // 参考配置 API
230+
material: Material; // 参考物料 API
231+
event: Event; // 参考事件 API
232+
project: Project; // 参考模型 API
233+
common: Common; // 参考模型 API
234+
logger: Logger; // 参考日志 API
235+
plugins: ILowCodePluginManager; // 即本文档描述内容
235236
preference: IPluginPreferenceMananger;
236237
}
237238
```

docs/docs/participate/flow.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,7 @@ sidebar_position: 2
9191
2. 拉 release 分支,此处以 1.0.1 版本做示例
9292
```bash
9393
git checkout -b release/1.0.1-beta
94+
git push --set-upstream origin release/1.0.1-beta
9495
```
9596
3. build
9697
```bash

packages/designer/jest.config.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ const jestConfig = {
1010
// // '^.+\\.(js|jsx)$': 'babel-jest',
1111
// },
1212
// testMatch: ['**/node-children.test.ts'],
13+
// testMatch: ['**/plugin-manager.test.ts'],
1314
// testMatch: ['**/history/history.test.ts'],
1415
// testMatch: ['**/host-view.test.tsx'],
1516
// testMatch: ['(/tests?/.*(test))\\.[jt]s$'],

packages/designer/src/plugin/plugin-context.ts

Lines changed: 18 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,14 @@
11
/* eslint-disable no-multi-assign */
2-
import { Editor, EngineConfig, engineConfig } from '@alilc/lowcode-editor-core';
3-
import { Designer, ILowCodePluginManager } from '@alilc/lowcode-designer';
4-
import { Skeleton as InnerSkeleton } from '@alilc/lowcode-editor-skeleton';
2+
import { EngineConfig, engineConfig } from '@alilc/lowcode-editor-core';
3+
import { ILowCodePluginManager } from '@alilc/lowcode-designer';
54
import {
65
Hotkey,
76
Project,
87
Skeleton,
98
Setters,
109
Material,
1110
Event,
12-
editorSymbol,
13-
designerSymbol,
14-
skeletonSymbol,
11+
Common,
1512
} from '@alilc/lowcode-shell';
1613
import { getLogger, Logger } from '@alilc/lowcode-utils';
1714
import {
@@ -20,45 +17,40 @@ import {
2017
ILowCodePluginPreferenceDeclaration,
2118
PreferenceValueType,
2219
IPluginPreferenceMananger,
20+
ILowCodePluginContextApiAssembler,
21+
ILowCodePluginContextPrivate,
2322
} from './plugin-types';
2423
import { isValidPreferenceKey } from './plugin-utils';
2524

26-
export default class PluginContext implements ILowCodePluginContext {
27-
private readonly [editorSymbol]: Editor;
28-
private readonly [designerSymbol]: Designer;
29-
private readonly [skeletonSymbol]: InnerSkeleton;
25+
26+
export default class PluginContext implements ILowCodePluginContext, ILowCodePluginContextPrivate {
3027
hotkey: Hotkey;
3128
project: Project;
3229
skeleton: Skeleton;
33-
logger: Logger;
3430
setters: Setters;
3531
material: Material;
36-
config: EngineConfig;
3732
event: Event;
33+
config: EngineConfig;
34+
common: Common;
35+
logger: Logger;
3836
plugins: ILowCodePluginManager;
3937
preference: IPluginPreferenceMananger;
4038

41-
constructor(plugins: ILowCodePluginManager, options: IPluginContextOptions) {
42-
const editor = this[editorSymbol] = plugins.editor;
43-
const designer = this[designerSymbol] = editor.get('designer')!;
44-
const skeleton = this[skeletonSymbol] = editor.get('skeleton')!;
45-
46-
const { pluginName = 'anonymous' } = options;
47-
const project = designer?.project;
48-
this.hotkey = new Hotkey();
49-
this.project = new Project(project);
50-
this.skeleton = new Skeleton(skeleton);
51-
this.setters = new Setters();
52-
this.material = new Material(editor);
53-
this.config = engineConfig;
39+
constructor(
40+
plugins: ILowCodePluginManager,
41+
options: IPluginContextOptions,
42+
contextApiAssembler: ILowCodePluginContextApiAssembler,
43+
) {
5444
this.plugins = plugins;
55-
this.event = new Event(editor, { prefix: 'common' });
45+
const { pluginName = 'anonymous' } = options;
5646
this.logger = getLogger({ level: 'warn', bizName: `designer:plugin:${pluginName}` });
5747

5848
const enhancePluginContextHook = engineConfig.get('enhancePluginContextHook');
5949
if (enhancePluginContextHook) {
6050
enhancePluginContextHook(this);
6151
}
52+
53+
contextApiAssembler.assembleApis(this);
6254
}
6355

6456
setPreference(

packages/designer/src/plugin/plugin-manager.ts

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { Editor, engineConfig } from '@alilc/lowcode-editor-core';
1+
import { engineConfig } from '@alilc/lowcode-editor-core';
22
import { getLogger } from '@alilc/lowcode-utils';
33
import {
44
ILowCodePlugin,
@@ -12,9 +12,11 @@ import {
1212
PluginPreference,
1313
ILowCodePluginPreferenceDeclaration,
1414
isLowCodeRegisterOptions,
15+
ILowCodePluginContextApiAssembler,
1516
} from './plugin-types';
1617
import { filterValidOptions } from './plugin-utils';
1718
import { LowCodePlugin } from './plugin';
19+
// eslint-disable-next-line import/no-named-as-default
1820
import LowCodePluginContext from './plugin-context';
1921
import { invariant } from '../utils';
2022
import sequencify from './sequencify';
@@ -28,14 +30,15 @@ export class LowCodePluginManager implements ILowCodePluginManager {
2830
private pluginsMap: Map<string, ILowCodePlugin> = new Map();
2931

3032
private pluginPreference?: PluginPreference = new Map();
31-
private editor: Editor;
3233

33-
constructor(editor: Editor) {
34-
this.editor = editor;
34+
contextApiAssembler: ILowCodePluginContextApiAssembler;
35+
36+
constructor(contextApiAssembler: ILowCodePluginContextApiAssembler) {
37+
this.contextApiAssembler = contextApiAssembler;
3538
}
3639

3740
private _getLowCodePluginContext(options: IPluginContextOptions) {
38-
return new LowCodePluginContext(this, options);
41+
return new LowCodePluginContext(this, options, this.contextApiAssembler);
3942
}
4043

4144
isEngineVersionMatched(versionExp: string): boolean {

packages/designer/src/plugin/plugin-types.ts

Lines changed: 23 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { CompositeObject, ComponentAction } from '@alilc/lowcode-types';
22
import Logger from 'zen-logger';
3-
import { Hotkey, Skeleton, Project, Event, Material } from '@alilc/lowcode-shell';
3+
import { Hotkey, Skeleton, Project, Event, Material, Common } from '@alilc/lowcode-shell';
44
import { EngineConfig } from '@alilc/lowcode-editor-core';
55
import { MetadataTransducer } from '@alilc/lowcode-designer';
66
import { Setters } from '../types';
@@ -96,17 +96,32 @@ export interface IPluginPreferenceMananger {
9696
}
9797

9898
export interface ILowCodePluginContext {
99-
skeleton: Skeleton;
100-
hotkey: Hotkey;
99+
get skeleton(): Skeleton;
100+
get hotkey(): Hotkey;
101+
get setters(): Setters;
102+
get config(): EngineConfig;
103+
get material(): Material;
104+
get event(): Event;
105+
get project(): Project;
106+
get common(): Common;
101107
logger: Logger;
102108
plugins: ILowCodePluginManager;
103-
setters: Setters;
104-
config: EngineConfig;
105-
material: Material;
106-
event: Event;
107-
project: Project;
108109
preference: IPluginPreferenceMananger;
109110
}
111+
export interface ILowCodePluginContextPrivate {
112+
set hotkey(hotkey: Hotkey);
113+
set project(project: Project);
114+
set skeleton(skeleton: Skeleton);
115+
set setters(setters: Setters);
116+
set material(material: Material);
117+
set event(event: Event);
118+
set config(config: EngineConfig);
119+
set common(common: Common);
120+
}
121+
export interface ILowCodePluginContextApiAssembler {
122+
assembleApis: (context: ILowCodePluginContextPrivate) => void;
123+
}
124+
110125

111126
interface ILowCodePluginManagerPluginAccessor {
112127
[pluginName: string]: ILowCodePlugin | any;

packages/designer/tests/plugin/plugin-manager.test.ts

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,19 @@
11
import '../fixtures/window';
22
import { Editor, engineConfig } from '@alilc/lowcode-editor-core';
33
import { LowCodePluginManager } from '../../src/plugin/plugin-manager';
4-
import { ILowCodePluginContext, ILowCodePluginManager } from '../../src/plugin/plugin-types';
4+
import { ILowCodePluginContext, ILowCodePluginManager, ILowCodePluginContextApiAssembler } from '../../src/plugin/plugin-types';
55

66
const editor = new Editor();
7+
const contextApiAssembler = {
8+
assembleApis(){
9+
// mock set apis
10+
}
11+
};
712

813
describe('plugin 测试', () => {
914
let pluginManager: ILowCodePluginManager;
1015
beforeEach(() => {
11-
pluginManager = new LowCodePluginManager(editor).toProxy();
16+
pluginManager = new LowCodePluginManager(contextApiAssembler).toProxy();
1217
});
1318
afterEach(() => {
1419
pluginManager.dispose();

packages/engine/src/engine-core.ts

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,13 @@
1+
/* eslint-disable no-param-reassign */
12
import { createElement } from 'react';
23
import { render, unmountComponentAtNode } from 'react-dom';
34
import { globalContext, Editor, engineConfig, EngineOptions } from '@alilc/lowcode-editor-core';
45
import {
56
Designer,
67
LowCodePluginManager,
78
ILowCodePluginContext,
9+
ILowCodePluginContextPrivate,
10+
ILowCodePluginContextApiAssembler,
811
PluginPreference,
912
} from '@alilc/lowcode-designer';
1013
import {
@@ -46,10 +49,6 @@ editor.set('skeleton' as any, innerSkeleton);
4649

4750
const designer = new Designer({ editor });
4851
editor.set('designer' as any, designer);
49-
50-
const plugins = new LowCodePluginManager(editor).toProxy();
51-
editor.set('plugins' as any, plugins);
52-
5352
const { project: innerProject } = designer;
5453

5554
const hotkey = new Hotkey();
@@ -62,6 +61,21 @@ const event = new Event(editor, { prefix: 'common' });
6261
const logger = getLogger({ level: 'warn', bizName: 'common' });
6362
const common = new Common(editor, innerSkeleton);
6463

64+
const pluginContextApiAssembler: ILowCodePluginContextApiAssembler = {
65+
assembleApis: (context: ILowCodePluginContextPrivate) => {
66+
context.hotkey = hotkey;
67+
context.project = project;
68+
context.skeleton = skeleton;
69+
context.setters = setters;
70+
context.material = material;
71+
context.event = event;
72+
context.config = config;
73+
context.common = common;
74+
},
75+
};
76+
const plugins = new LowCodePluginManager(pluginContextApiAssembler).toProxy();
77+
editor.set('plugins' as any, plugins);
78+
6579
export {
6680
skeleton,
6781
plugins,

0 commit comments

Comments
 (0)