Skip to content

Commit b664663

Browse files
JackLianliujuping
authored andcommitted
refactor: move common to shell
1 parent f49c629 commit b664663

7 files changed

Lines changed: 201 additions & 119 deletions

File tree

packages/engine/src/engine-core.ts

Lines changed: 15 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ import {
66
LowCodePluginManager,
77
ILowCodePluginContext,
88
PluginPreference,
9-
TransformStage,
109
} from '@alilc/lowcode-designer';
1110
import {
1211
Skeleton as InnerSkeleton,
@@ -16,15 +15,21 @@ import {
1615

1716
import Outline, { OutlineBackupPane, getTreeMaster } from '@alilc/lowcode-plugin-outline-pane';
1817
import DesignerPlugin from '@alilc/lowcode-plugin-designer';
19-
import { Hotkey, Project, Skeleton, Setters, Material, Event, DocumentModel } from '@alilc/lowcode-shell';
18+
import {
19+
Hotkey,
20+
Project,
21+
Skeleton,
22+
Setters,
23+
Material,
24+
Event,
25+
DocumentModel,
26+
Common,
27+
} from '@alilc/lowcode-shell';
2028
import { getLogger, isPlainObject } from '@alilc/lowcode-utils';
2129
import './modules/live-editing';
22-
import utils from './modules/utils';
23-
import * as editorCabin from './modules/editor-cabin';
24-
import getSkeletonCabin from './modules/skeleton-cabin';
25-
import getDesignerCabin from './modules/designer-cabin';
2630
import classes from './modules/classes';
2731
import symbols from './modules/symbols';
32+
2833
export * from './modules/editor-types';
2934
export * from './modules/skeleton-types';
3035
export * from './modules/designer-types';
@@ -46,8 +51,6 @@ const plugins = new LowCodePluginManager(editor).toProxy();
4651
editor.set('plugins' as any, plugins);
4752

4853
const { project: innerProject } = designer;
49-
const skeletonCabin = getSkeletonCabin(innerSkeleton);
50-
const { Workbench } = skeletonCabin;
5154

5255
const hotkey = new Hotkey();
5356
const project = new Project(innerProject);
@@ -57,17 +60,7 @@ const material = new Material(editor);
5760
const config = engineConfig;
5861
const event = new Event(editor, { prefix: 'common' });
5962
const logger = getLogger({ level: 'warn', bizName: 'common' });
60-
const designerCabin = getDesignerCabin(editor);
61-
const objects = {
62-
TransformStage,
63-
};
64-
const common = {
65-
utils,
66-
objects,
67-
editorCabin,
68-
designerCabin,
69-
skeletonCabin,
70-
};
63+
const common = new Common(editor, innerSkeleton);
7164

7265
export {
7366
skeleton,
@@ -189,6 +182,7 @@ let engineContainer: HTMLElement;
189182
// @ts-ignore webpack Define variable
190183
export const version = VERSION_PLACEHOLDER;
191184
engineConfig.set('ENGINE_VERSION', version);
185+
192186
export async function init(
193187
container?: HTMLElement,
194188
options?: EngineOptions,
@@ -213,6 +207,8 @@ export async function init(
213207
engineConfig.setEngineOptions(engineOptions as any);
214208

215209
await plugins.init(pluginPreference as any);
210+
211+
const { Workbench } = common.skeletonCabin;
216212
render(
217213
createElement(Workbench, {
218214
skeleton: innerSkeleton,

packages/engine/src/modules/designer-cabin.ts

Lines changed: 0 additions & 50 deletions
This file was deleted.

packages/engine/src/modules/editor-cabin.ts

Lines changed: 0 additions & 15 deletions
This file was deleted.

packages/engine/src/modules/skeleton-cabin.tsx

Lines changed: 0 additions & 16 deletions
This file was deleted.

packages/engine/src/modules/utils.ts

Lines changed: 0 additions & 17 deletions
This file was deleted.

packages/shell/src/common.tsx

Lines changed: 183 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,183 @@
1+
import { editorSymbol, skeletonSymbol, designerCabinSymbol } from './symbols';
2+
import {
3+
isFormEvent as innerIsFormEvent,
4+
compatibleLegaoSchema as innerCompatibleLegaoSchema,
5+
getNodeSchemaById as innerGetNodeSchemaById,
6+
transactionManager,
7+
} from '@alilc/lowcode-utils';
8+
import {
9+
isNodeSchema as innerIsNodeSchema,
10+
NodeSchema,
11+
TransitionType,
12+
} from '@alilc/lowcode-types';
13+
import {
14+
SettingField,
15+
isSettingField,
16+
Designer,
17+
TransformStage,
18+
LiveEditing,
19+
isDragNodeDataObject,
20+
isDragNodeObject,
21+
isDragAnyObject,
22+
DragObjectType,
23+
isNode,
24+
isShaken,
25+
contains,
26+
LocationDetailType,
27+
isLocationChildrenDetail,
28+
ScrollTarget,
29+
getConvertedExtraKey as innerGetConvertedExtraKey,
30+
getOriginalExtraKey as innerGetOriginalExtraKey,
31+
} from '@alilc/lowcode-designer';
32+
import {
33+
Skeleton as InnerSkeleton,
34+
createSettingFieldView,
35+
PopupContext,
36+
PopupPipe,
37+
Workbench as InnerWorkbench,
38+
} from '@alilc/lowcode-editor-skeleton';
39+
import Dragon from './dragon';
40+
import {
41+
Editor,
42+
Title as InnerTitle,
43+
Tip as InnerTip,
44+
shallowIntl,
45+
createIntl as innerCreateIntl,
46+
intl,
47+
createSetterContent,
48+
obx,
49+
observable,
50+
makeObservable,
51+
untracked,
52+
computed,
53+
observer,
54+
globalLocale,
55+
} from '@alilc/lowcode-editor-core';
56+
import { ReactNode } from 'react';
57+
58+
59+
const getDesignerCabin = (editor: Editor) => {
60+
const designer = editor.get('designer') as Designer;
61+
62+
return {
63+
SettingField,
64+
isSettingField,
65+
dragon: Dragon.create(designer.dragon),
66+
TransformStage,
67+
LiveEditing,
68+
DragObjectType,
69+
isDragNodeDataObject,
70+
isNode,
71+
[designerCabinSymbol]: {
72+
isDragNodeObject,
73+
isDragAnyObject,
74+
isShaken,
75+
contains,
76+
LocationDetailType,
77+
isLocationChildrenDetail,
78+
ScrollTarget,
79+
isSettingField,
80+
TransformStage,
81+
SettingField,
82+
LiveEditing,
83+
DragObjectType,
84+
isDragNodeDataObject,
85+
isNode,
86+
},
87+
};
88+
};
89+
90+
const getSkeletonCabin = (skeleton: InnerSkeleton) => {
91+
return {
92+
createSettingFieldView,
93+
PopupContext,
94+
PopupPipe,
95+
Workbench: (props: any) => <InnerWorkbench {...props} skeleton={skeleton} />, // hijack skeleton
96+
};
97+
};
98+
99+
class Utils {
100+
isNodeSchema(data: any): data is NodeSchema {
101+
return innerIsNodeSchema(data);
102+
}
103+
104+
isFormEvent(e: KeyboardEvent | MouseEvent): boolean {
105+
return innerIsFormEvent(e);
106+
}
107+
108+
compatibleLegaoSchema(props: any): any {
109+
return innerCompatibleLegaoSchema(props);
110+
}
111+
112+
getNodeSchemaById(schema: NodeSchema, nodeId: string): NodeSchema | undefined {
113+
return innerGetNodeSchemaById(schema, nodeId);
114+
}
115+
116+
getConvertedExtraKey(key: string): string {
117+
return innerGetConvertedExtraKey(key);
118+
}
119+
120+
getOriginalExtraKey(key: string): string {
121+
return innerGetOriginalExtraKey(key);
122+
}
123+
124+
executeTransaction(fn: () => void, type: TransitionType = TransitionType.REPAINT): void {
125+
transactionManager.executeTransaction(fn, type);
126+
}
127+
128+
createIntl(instance: string | object): {
129+
intlNode(id: string, params?: object): ReactNode;
130+
intl(id: string, params?: object): string;
131+
getLocale(): string;
132+
setLocale(locale: string): void;
133+
} {
134+
return innerCreateIntl(instance);
135+
}
136+
}
137+
138+
export default class Common {
139+
private readonly [editorSymbol]: Editor;
140+
private readonly [skeletonSymbol]: InnerSkeleton;
141+
private readonly __designerCabin: any;
142+
private readonly __skeletonCabin: any;
143+
private readonly __editorCabin: any;
144+
private readonly __utils: Utils;
145+
146+
constructor(editor: Editor, skeleton: InnerSkeleton) {
147+
this[editorSymbol] = editor;
148+
this[skeletonSymbol] = skeleton;
149+
this.__designerCabin = getDesignerCabin(this[editorSymbol]);
150+
this.__skeletonCabin = getSkeletonCabin(this[skeletonSymbol]);
151+
this.__utils = new Utils();
152+
}
153+
154+
get utils(): any {
155+
return this.__utils;
156+
}
157+
158+
get editorCabin(): any {
159+
return {
160+
Title: InnerTitle,
161+
Tip: InnerTip,
162+
shallowIntl,
163+
createIntl: innerCreateIntl,
164+
intl,
165+
createSetterContent,
166+
obx,
167+
observable,
168+
makeObservable,
169+
untracked,
170+
computed,
171+
observer,
172+
globalLocale,
173+
};
174+
}
175+
176+
get designerCabin(): any {
177+
return this.__designerCabin;
178+
}
179+
180+
get skeletonCabin(): any {
181+
return this.__skeletonCabin;
182+
}
183+
}

0 commit comments

Comments
 (0)