Skip to content

Commit 6ae7c1b

Browse files
authored
refactor: remove dependency of shell from designer (alibaba#1328)
1 parent a54ded2 commit 6ae7c1b

35 files changed

+159
-214
lines changed

packages/designer/jest.config.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,8 @@ const jestConfig = {
1212
// testMatch: ['**/node-children.test.ts'],
1313
// testMatch: ['**/plugin-manager.test.ts'],
1414
// testMatch: ['**/history/history.test.ts'],
15-
// testMatch: ['**/host-view.test.tsx'],
15+
// testMatch: ['**/document-model.test.ts'],
16+
// testMatch: ['**/prop.test.ts'],
1617
// testMatch: ['(/tests?/.*(test))\\.[jt]s$'],
1718
transformIgnorePatterns: [
1819
`/node_modules/(?!${esModules})/`,

packages/designer/package.json

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,12 +16,9 @@
1616
"license": "MIT",
1717
"dependencies": {
1818
"@alilc/lowcode-editor-core": "1.0.17",
19-
"@alilc/lowcode-shell": "1.0.17",
2019
"@alilc/lowcode-types": "1.0.17",
2120
"@alilc/lowcode-utils": "1.0.17",
2221
"classnames": "^2.2.6",
23-
"enzyme": "^3.11.0",
24-
"enzyme-adapter-react-16": "^1.15.5",
2522
"react": "^16",
2623
"react-dom": "^16.7.0",
2724
"ric-shim": "^1.0.1",
@@ -30,6 +27,7 @@
3027
},
3128
"devDependencies": {
3229
"@alib/build-scripts": "^0.1.29",
30+
"@alilc/lowcode-shell": "1.0.17",
3331
"@alilc/lowcode-test-mate": "^1.0.1",
3432
"@testing-library/react": "^11.2.2",
3533
"@types/classnames": "^2.2.7",
@@ -43,6 +41,10 @@
4341
"babel-jest": "^26.5.2",
4442
"build-plugin-component": "^0.2.10",
4543
"build-scripts-config": "^0.1.8",
44+
"enzyme": "^3.11.0",
45+
"@types/enzyme": "^3.10.12",
46+
"enzyme-adapter-react-16": "^1.15.5",
47+
"@types/enzyme-adapter-react-16": "^1.0.6",
4648
"jest": "^26.6.3",
4749
"lodash": "^4.17.20",
4850
"moment": "^2.29.1",

packages/designer/src/designer/designer.ts

Lines changed: 6 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import {
1010
PropsList,
1111
NodeSchema,
1212
PropsTransducer,
13+
IShellModelFactory,
1314
} from '@alilc/lowcode-types';
1415
import { megreAssets, AssetsJson, isNodeSchema } from '@alilc/lowcode-utils';
1516
import { Project } from '../project';
@@ -28,6 +29,7 @@ import { BemToolsManager } from '../builtin-simulator/bem-tools/manager';
2829

2930
export interface DesignerProps {
3031
editor: IEditor;
32+
shellModelFactory: IShellModelFactory;
3133
className?: string;
3234
style?: object;
3335
defaultSchema?: ProjectSchema;
@@ -58,6 +60,8 @@ export class Designer {
5860

5961
readonly bemToolsManager = new BemToolsManager(this);
6062

63+
readonly shellModelFactory: IShellModelFactory;
64+
6165
get currentDocument() {
6266
return this.project.currentDocument;
6367
}
@@ -72,25 +76,17 @@ export class Designer {
7276

7377
constructor(props: DesignerProps) {
7478
makeObservable(this);
75-
const { editor } = props;
79+
const { editor, shellModelFactory } = props;
7680
this.editor = editor;
81+
this.shellModelFactory = shellModelFactory;
7782
this.setProps(props);
7883

7984
this.project = new Project(this, props.defaultSchema);
8085

81-
let startTime: any;
82-
let src = '';
8386
this.dragon.onDragstart((e) => {
84-
startTime = Date.now() / 1000;
8587
this.detecting.enable = false;
8688
const { dragObject } = e;
8789
if (isDragNodeObject(dragObject)) {
88-
const node = dragObject.nodes[0]?.parent;
89-
const npm = node?.componentMeta?.npm;
90-
src =
91-
[npm?.package, npm?.componentName].filter((item) => !!item).join('-') ||
92-
node?.componentMeta?.componentName ||
93-
'';
9490
if (dragObject.nodes.length === 1) {
9591
if (dragObject.nodes[0].parent) {
9692
// ensure current selecting
@@ -135,34 +131,6 @@ export class Designer {
135131
if (nodes) {
136132
loc.document.selection.selectAll(nodes.map((o) => o.id));
137133
setTimeout(() => this.activeTracker.track(nodes![0]), 10);
138-
const endTime: any = Date.now() / 1000;
139-
const parent = nodes[0]?.parent;
140-
const npm = parent?.componentMeta?.npm;
141-
const dest =
142-
[npm?.package, npm?.componentName].filter((item) => !!item).join('-') ||
143-
parent?.componentMeta?.componentName ||
144-
'';
145-
// eslint-disable-next-line no-unused-expressions
146-
// this.postEvent('drag', {
147-
// time: (endTime - startTime).toFixed(2),
148-
// selected: nodes
149-
// ?.map((n) => {
150-
// if (!n) {
151-
// return;
152-
// }
153-
// // eslint-disable-next-line no-shadow
154-
// const npm = n?.componentMeta?.npm;
155-
// return (
156-
// [npm?.package, npm?.componentName].filter((item) => !!item).join('-') ||
157-
// n?.componentMeta?.componentName
158-
// );
159-
// })
160-
// .join('&'),
161-
// align: loc?.detail?.near?.align || '',
162-
// pos: loc?.detail?.near?.pos || '',
163-
// src,
164-
// dest,
165-
// });
166134
}
167135
}
168136
}

packages/designer/src/designer/dragon.ts

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
import { EventEmitter } from 'events';
22
import { obx, makeObservable } from '@alilc/lowcode-editor-core';
3-
import { DragNodeObject, DragAnyObject, DragObjectType, DragNodeDataObject, DragObject } from '@alilc/lowcode-types';
4-
import { Node as ShellNode } from '@alilc/lowcode-shell';
3+
import { DragNodeObject, DragAnyObject, DragObjectType, DragNodeDataObject, DragObject, IPublicModelNode } from '@alilc/lowcode-types';
54
import { setNativeSelection, cursor } from '@alilc/lowcode-utils';
65
import { DropLocation } from './location';
76
import { Node, DocumentModel } from '../document';
@@ -201,13 +200,13 @@ export class Dragon {
201200
* @param dragObject 拖拽对象
202201
* @param boostEvent 拖拽初始时事件
203202
*/
204-
boost(dragObject: DragObject, boostEvent: MouseEvent | DragEvent, fromRglNode?: Node | ShellNode) {
203+
boost(dragObject: DragObject, boostEvent: MouseEvent | DragEvent, fromRglNode?: Node | IPublicModelNode) {
205204
const { designer } = this;
206205
const masterSensors = this.getMasterSensors();
207206
const handleEvents = makeEventsHandler(boostEvent, masterSensors);
208207
const newBie = !isDragNodeObject(dragObject);
209208
const forceCopyState =
210-
isDragNodeObject(dragObject) && dragObject.nodes.some((node: Node | ShellNode) => (typeof node.isSlot === 'function' ? node.isSlot() : node.isSlot));
209+
isDragNodeObject(dragObject) && dragObject.nodes.some((node: Node | IPublicModelNode) => (typeof node.isSlot === 'function' ? node.isSlot() : node.isSlot));
211210
const isBoostFromDragAPI = isDragEvent(boostEvent);
212211
let lastSensor: ISensor | undefined;
213212

packages/designer/src/designer/setting/setting-prop-entry.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
import { obx, computed, makeObservable, runInAction } from '@alilc/lowcode-editor-core';
22
import { GlobalEvent, IEditor, ISetValueOptions } from '@alilc/lowcode-types';
33
import { uniqueId, isJSExpression } from '@alilc/lowcode-utils';
4-
import { SettingPropEntry as ShellSettingPropEntry } from '@alilc/lowcode-shell';
54
import { SettingEntry } from './setting-entry';
65
import { Node } from '../../document';
76
import { ComponentMeta } from '../../component-meta';
@@ -363,6 +362,6 @@ export class SettingPropEntry implements SettingEntry {
363362
}
364363

365364
internalToShellPropEntry() {
366-
return ShellSettingPropEntry.create(this) as any;
365+
return this.designer.shellModelFactory.createSettingPropEntry(this);
367366
}
368367
}

packages/designer/src/document/history.ts

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
import { EventEmitter } from 'events';
22
import { reaction, untracked, globalContext, Editor } from '@alilc/lowcode-editor-core';
33
import { NodeSchema } from '@alilc/lowcode-types';
4-
import { History as ShellHistory } from '@alilc/lowcode-shell';
54

65
export interface Serialization<K = NodeSchema, T = string> {
76
serialize(data: K): T;
@@ -192,10 +191,6 @@ export class History<T = NodeSchema> {
192191
isModified() {
193192
return this.isSavePoint();
194193
}
195-
196-
internalToShellHistory() {
197-
return new ShellHistory(this);
198-
}
199194
}
200195

201196
export class Session {

packages/designer/src/document/node/node.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,10 @@ import {
1414
CompositeValue,
1515
GlobalEvent,
1616
ComponentAction,
17+
IPublicModelNode,
1718
} from '@alilc/lowcode-types';
1819
import { compatStage, isDOMText, isJSExpression } from '@alilc/lowcode-utils';
1920
import { SettingTopEntry } from '@alilc/lowcode-designer';
20-
import { Node as ShellNode } from '@alilc/lowcode-shell';
2121
import { Props, getConvertedExtraKey } from './props/props';
2222
import { DocumentModel } from '../document-model';
2323
import { NodeChildren } from './node-children';
@@ -366,8 +366,8 @@ export class Node<Schema extends NodeSchema = NodeSchema> {
366366
this._slotFor = slotFor;
367367
}
368368

369-
internalToShellNode(): ShellNode | null {
370-
return ShellNode.create(this);
369+
internalToShellNode(): IPublicModelNode | null {
370+
return this.document.designer.shellModelFactory.createNode(this);
371371
}
372372

373373
/**

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

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,14 @@
22
import { EngineConfig, engineConfig } from '@alilc/lowcode-editor-core';
33
import { ILowCodePluginManager } from '@alilc/lowcode-designer';
44
import {
5-
Hotkey,
6-
Project,
7-
Skeleton,
8-
Setters,
9-
Material,
10-
Event,
11-
Common,
12-
} from '@alilc/lowcode-shell';
5+
IPublicApiHotkey,
6+
IPublicApiProject,
7+
IPublicApiSkeleton,
8+
IPublicApiSetters,
9+
IPublicApiMaterial,
10+
IPublicApiEvent,
11+
IPublicApiCommon,
12+
} from '@alilc/lowcode-types';
1313
import { getLogger, Logger } from '@alilc/lowcode-utils';
1414
import {
1515
ILowCodePluginContext,
@@ -24,14 +24,14 @@ import { isValidPreferenceKey } from './plugin-utils';
2424

2525

2626
export default class PluginContext implements ILowCodePluginContext, ILowCodePluginContextPrivate {
27-
hotkey: Hotkey;
28-
project: Project;
29-
skeleton: Skeleton;
30-
setters: Setters;
31-
material: Material;
32-
event: Event;
27+
hotkey: IPublicApiHotkey;
28+
project: IPublicApiProject;
29+
skeleton: IPublicApiSkeleton;
30+
setters: IPublicApiSetters;
31+
material: IPublicApiMaterial;
32+
event: IPublicApiEvent;
3333
config: EngineConfig;
34-
common: Common;
34+
common: IPublicApiCommon;
3535
logger: Logger;
3636
plugins: ILowCodePluginManager;
3737
preference: IPluginPreferenceMananger;

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

Lines changed: 25 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,16 @@
1-
import { CompositeObject, ComponentAction, MetadataTransducer } from '@alilc/lowcode-types';
21
import Logger from 'zen-logger';
3-
import { Hotkey, Skeleton, Project, Event, Material, Common } from '@alilc/lowcode-shell';
2+
import {
3+
IPublicApiHotkey,
4+
IPublicApiProject,
5+
IPublicApiSkeleton,
6+
IPublicApiSetters,
7+
IPublicApiMaterial,
8+
IPublicApiEvent,
9+
IPublicApiCommon,
10+
CompositeObject,
11+
ComponentAction,
12+
MetadataTransducer,
13+
} from '@alilc/lowcode-types';
414
import { EngineConfig } from '@alilc/lowcode-editor-core';
515
import { Setters } from '../types';
616

@@ -95,27 +105,27 @@ export interface IPluginPreferenceMananger {
95105
}
96106

97107
export interface ILowCodePluginContext {
98-
get skeleton(): Skeleton;
99-
get hotkey(): Hotkey;
100-
get setters(): Setters;
108+
get skeleton(): IPublicApiSkeleton;
109+
get hotkey(): IPublicApiHotkey;
110+
get setters(): IPublicApiSetters;
101111
get config(): EngineConfig;
102-
get material(): Material;
103-
get event(): Event;
104-
get project(): Project;
105-
get common(): Common;
112+
get material(): IPublicApiMaterial;
113+
get event(): IPublicApiEvent;
114+
get project(): IPublicApiProject;
115+
get common(): IPublicApiCommon;
106116
logger: Logger;
107117
plugins: ILowCodePluginManager;
108118
preference: IPluginPreferenceMananger;
109119
}
110120
export interface ILowCodePluginContextPrivate {
111-
set hotkey(hotkey: Hotkey);
112-
set project(project: Project);
113-
set skeleton(skeleton: Skeleton);
121+
set hotkey(hotkey: IPublicApiHotkey);
122+
set project(project: IPublicApiProject);
123+
set skeleton(skeleton: IPublicApiSkeleton);
114124
set setters(setters: Setters);
115-
set material(material: Material);
116-
set event(event: Event);
125+
set material(material: IPublicApiMaterial);
126+
set event(event: IPublicApiEvent);
117127
set config(config: EngineConfig);
118-
set common(common: Common);
128+
set common(common: IPublicApiCommon);
119129
}
120130
export interface ILowCodePluginContextApiAssembler {
121131
assembleApis: (context: ILowCodePluginContextPrivate) => void;

packages/designer/tests/bugs/prop-variable-jse.test.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
// @ts-nocheck
21
import { Editor } from '@alilc/lowcode-editor-core';
32
import { TransformStage } from '@alilc/lowcode-types';
43
import { isPlainObject, isVariable, isJSBlock } from '@alilc/lowcode-utils';
@@ -7,6 +6,7 @@ import { Designer } from '../../src/designer/designer';
76
import { DocumentModel } from '../../src/document/document-model';
87
import { Project } from '../../src/project/project';
98
import formSchema from '../fixtures/schema/form';
9+
import { shellModelFactory } from '../../../engine/src/modules/shell-model-factory';
1010

1111
/**
1212
* bug 背景:
@@ -58,7 +58,7 @@ describe('Node 方法测试', () => {
5858

5959
it('原始 prop 值是 variable 结构,通过一个 propsReducer 转成了 JSExpression 结构', () => {
6060
editor = new Editor();
61-
designer = new Designer({ editor });
61+
designer = new Designer({ editor, shellModelFactory });
6262
designer.addPropsReducer(upgradePropsReducer, TransformStage.Upgrade);
6363
project = designer.project;
6464
doc = new DocumentModel(project, formSchema);

0 commit comments

Comments
 (0)