Skip to content

Commit 810ccbd

Browse files
JackLianliujuping
authored andcommitted
feat: add get advanced api for ComponentMeta
1 parent 5cf3959 commit 810ccbd

File tree

23 files changed

+288
-231
lines changed

23 files changed

+288
-231
lines changed

packages/designer/src/builtin-simulator/bem-tools/border-detecting.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ export class BorderDetecting extends Component<{ host: BuiltinSimulatorHost }> {
7676
const { host } = this.props;
7777
const { current } = this;
7878

79-
const canHoverHook = current?.componentMeta.getMetadata()?.configure.advanced?.callbacks?.onHoverHook;
79+
const canHoverHook = current?.componentMeta.advanced.callbacks?.onHoverHook;
8080
const canHover = (canHoverHook && typeof canHoverHook === 'function') ? canHoverHook(current.internalToShellNode()) : true;
8181

8282
if (!canHover || !current || host.viewport.scrolling || host.liveEditing.editing) {

packages/designer/src/builtin-simulator/bem-tools/border-resizing.tsx

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -136,40 +136,40 @@ export class BoxResizingInstance extends Component<{
136136
this.willBind();
137137

138138
const resize = (e: MouseEvent, direction: string, node: any, moveX: number, moveY: number) => {
139-
const metadata = node.componentMeta.getMetadata();
139+
const { advanced } = node.componentMeta;
140140
if (
141-
metadata.configure?.advanced?.callbacks &&
142-
typeof metadata.configure.advanced.callbacks.onResize === 'function'
141+
advanced.callbacks &&
142+
typeof advanced.callbacks.onResize === 'function'
143143
) {
144144
(e as any).trigger = direction;
145145
(e as any).deltaX = moveX;
146146
(e as any).deltaY = moveY;
147147
const cbNode = node?.isNode ? node.internalToShellNode() : node;
148-
metadata.configure.advanced.callbacks.onResize(e, cbNode);
148+
advanced.callbacks.onResize(e, cbNode);
149149
}
150150
};
151151

152152
const resizeStart = (e: MouseEvent, direction: string, node: any) => {
153-
const metadata = node.componentMeta.getMetadata();
153+
const { advanced } = node.componentMeta;
154154
if (
155-
metadata.configure?.advanced?.callbacks &&
156-
typeof metadata.configure.advanced.callbacks.onResizeStart === 'function'
155+
advanced.callbacks &&
156+
typeof advanced.callbacks.onResizeStart === 'function'
157157
) {
158158
(e as any).trigger = direction;
159159
const cbNode = node?.isNode ? node.internalToShellNode() : node;
160-
metadata.configure.advanced.callbacks.onResizeStart(e, cbNode);
160+
advanced.callbacks.onResizeStart(e, cbNode);
161161
}
162162
};
163163

164164
const resizeEnd = (e: MouseEvent, direction: string, node: any) => {
165-
const metadata = node.componentMeta.getMetadata();
165+
const { advanced } = node.componentMeta;
166166
if (
167-
metadata.configure?.advanced?.callbacks &&
168-
typeof metadata.configure.advanced.callbacks.onResizeEnd === 'function'
167+
advanced.callbacks &&
168+
typeof advanced.callbacks.onResizeEnd === 'function'
169169
) {
170170
(e as any).trigger = direction;
171171
const cbNode = node?.isNode ? node.internalToShellNode() : node;
172-
metadata.configure.advanced.callbacks.onResizeEnd(e, cbNode);
172+
advanced.callbacks.onResizeEnd(e, cbNode);
173173
}
174174

175175
const workspace = globalContext.get('workspace');
@@ -242,9 +242,9 @@ export class BoxResizingInstance extends Component<{
242242

243243
const { node, offsetWidth, offsetHeight, offsetTop, offsetLeft } = observed;
244244
let triggerVisible: any = [];
245-
const metadata = node.componentMeta.getMetadata();
246-
if (metadata.configure?.advanced?.getResizingHandlers) {
247-
triggerVisible = metadata.configure.advanced.getResizingHandlers(node.internalToShellNode());
245+
const { advanced } = node.componentMeta;
246+
if (advanced.getResizingHandlers) {
247+
triggerVisible = advanced.getResizingHandlers(node.internalToShellNode());
248248
}
249249

250250
triggerVisible = normalizeTriggers(triggerVisible);

packages/designer/src/builtin-simulator/bem-tools/border-selecting.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ export class BorderSelectingInstance extends Component<{
4646
dragging,
4747
});
4848

49-
const hideSelectTools = observed.node.componentMeta.getMetadata().configure.advanced?.hideSelectTools;
49+
const { hideSelectTools } = observed.node.componentMeta.advanced;
5050

5151
if (hideSelectTools) {
5252
return null;

packages/designer/src/builtin-simulator/bem-tools/insertion.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,7 @@ export class InsertionView extends Component<{ host: BuiltinSimulatorHost }> {
121121
return null;
122122
}
123123
// 如果是个绝对定位容器,不需要渲染插入标记
124-
if (loc.target.componentMeta.getMetadata().configure.advanced?.isAbsoluteLayoutContainer) {
124+
if (loc.target?.componentMeta?.advanced.isAbsoluteLayoutContainer) {
125125
return null;
126126
}
127127

packages/designer/src/builtin-simulator/host.ts

Lines changed: 85 additions & 83 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,7 @@ export interface BuiltinSimulatorProps {
9999
simulatorUrl?: Asset;
100100
theme?: Asset;
101101
componentsAsset?: Asset;
102+
// eslint-disable-next-line @typescript-eslint/member-ordering
102103
[key: string]: any;
103104
}
104105

@@ -184,40 +185,6 @@ export class BuiltinSimulatorHost implements ISimulatorHost<BuiltinSimulatorProp
184185
*/
185186
autoRender = true;
186187

187-
stopAutoRepaintNode() {
188-
this.renderer?.stopAutoRepaintNode();
189-
}
190-
191-
enableAutoRepaintNode() {
192-
this.renderer?.enableAutoRepaintNode();
193-
}
194-
195-
constructor(project: Project, designer: Designer) {
196-
makeObservable(this);
197-
this.project = project;
198-
this.designer = designer;
199-
this.scroller = this.designer.createScroller(this.viewport);
200-
this.autoRender = !engineConfig.get('disableAutoRender', false);
201-
this.componentsConsumer = new ResourceConsumer<Asset | undefined>(() => this.componentsAsset);
202-
this.injectionConsumer = new ResourceConsumer(() => {
203-
return {
204-
appHelper: engineConfig.get('appHelper'),
205-
};
206-
});
207-
208-
this.i18nConsumer = new ResourceConsumer(() => this.project.i18n);
209-
210-
transactionManager.onStartTransaction(() => {
211-
this.stopAutoRepaintNode();
212-
}, IPublicEnumTransitionType.REPAINT);
213-
// 防止批量调用 transaction 时,执行多次 rerender
214-
const rerender = debounce(this.rerender.bind(this), 28);
215-
transactionManager.onEndTransaction(() => {
216-
rerender();
217-
this.enableAutoRepaintNode();
218-
}, IPublicEnumTransitionType.REPAINT);
219-
}
220-
221188
get currentDocument() {
222189
return this.project.currentDocument;
223190
}
@@ -285,6 +252,87 @@ export class BuiltinSimulatorHost implements ISimulatorHost<BuiltinSimulatorProp
285252

286253
@obx.ref _props: BuiltinSimulatorProps = {};
287254

255+
@obx.ref private _contentWindow?: Window;
256+
257+
get contentWindow() {
258+
return this._contentWindow;
259+
}
260+
261+
@obx.ref private _contentDocument?: Document;
262+
263+
get contentDocument() {
264+
return this._contentDocument;
265+
}
266+
267+
private _renderer?: BuiltinSimulatorRenderer;
268+
269+
get renderer() {
270+
return this._renderer;
271+
}
272+
273+
readonly asyncLibraryMap: { [key: string]: {} } = {};
274+
275+
readonly libraryMap: { [key: string]: string } = {};
276+
277+
private _iframe?: HTMLIFrameElement;
278+
279+
private disableHovering?: () => void;
280+
281+
private disableDetecting?: () => void;
282+
283+
readonly liveEditing = new LiveEditing();
284+
285+
@obx private instancesMap: {
286+
[docId: string]: Map<string, IPublicTypeComponentInstance[]>;
287+
} = {};
288+
289+
private tryScrollAgain: number | null = null;
290+
291+
private _sensorAvailable = true;
292+
293+
/**
294+
* @see IPublicModelSensor
295+
*/
296+
get sensorAvailable(): boolean {
297+
return this._sensorAvailable;
298+
}
299+
300+
private sensing = false;
301+
302+
constructor(project: Project, designer: Designer) {
303+
makeObservable(this);
304+
this.project = project;
305+
this.designer = designer;
306+
this.scroller = this.designer.createScroller(this.viewport);
307+
this.autoRender = !engineConfig.get('disableAutoRender', false);
308+
this.componentsConsumer = new ResourceConsumer<Asset | undefined>(() => this.componentsAsset);
309+
this.injectionConsumer = new ResourceConsumer(() => {
310+
return {
311+
appHelper: engineConfig.get('appHelper'),
312+
};
313+
});
314+
315+
this.i18nConsumer = new ResourceConsumer(() => this.project.i18n);
316+
317+
transactionManager.onStartTransaction(() => {
318+
this.stopAutoRepaintNode();
319+
}, IPublicEnumTransitionType.REPAINT);
320+
// 防止批量调用 transaction 时,执行多次 rerender
321+
const rerender = debounce(this.rerender.bind(this), 28);
322+
transactionManager.onEndTransaction(() => {
323+
rerender();
324+
this.enableAutoRepaintNode();
325+
}, IPublicEnumTransitionType.REPAINT);
326+
}
327+
328+
stopAutoRepaintNode() {
329+
this.renderer?.stopAutoRepaintNode();
330+
}
331+
332+
enableAutoRepaintNode() {
333+
this.renderer?.enableAutoRepaintNode();
334+
}
335+
288336
/**
289337
* @see ISimulator
290338
*/
@@ -337,30 +385,6 @@ export class BuiltinSimulatorHost implements ISimulatorHost<BuiltinSimulatorProp
337385
this.viewport.mount(viewport);
338386
}
339387

340-
@obx.ref private _contentWindow?: Window;
341-
342-
get contentWindow() {
343-
return this._contentWindow;
344-
}
345-
346-
@obx.ref private _contentDocument?: Document;
347-
348-
get contentDocument() {
349-
return this._contentDocument;
350-
}
351-
352-
private _renderer?: BuiltinSimulatorRenderer;
353-
354-
get renderer() {
355-
return this._renderer;
356-
}
357-
358-
readonly asyncLibraryMap: { [key: string]: {} } = {};
359-
360-
readonly libraryMap: { [key: string]: string } = {};
361-
362-
private _iframe?: HTMLIFrameElement;
363-
364388
/**
365389
* {
366390
* "title":"BizCharts",
@@ -544,7 +568,7 @@ export class BuiltinSimulatorHost implements ISimulatorHost<BuiltinSimulatorProp
544568
return;
545569
}
546570
// 触发 onMouseDownHook 钩子
547-
const onMouseDownHook = node.componentMeta?.getMetadata()?.configure.advanced?.callbacks?.onMouseDownHook;
571+
const onMouseDownHook = node.componentMeta.advanced.callbacks?.onMouseDownHook;
548572
if (onMouseDownHook) {
549573
onMouseDownHook(downEvent, node.internalToShellNode());
550574
}
@@ -689,10 +713,6 @@ export class BuiltinSimulatorHost implements ISimulatorHost<BuiltinSimulatorProp
689713
);
690714
}
691715

692-
private disableHovering?: () => void;
693-
694-
private disableDetecting?: () => void;
695-
696716
/**
697717
* 设置悬停处理
698718
*/
@@ -742,8 +762,6 @@ export class BuiltinSimulatorHost implements ISimulatorHost<BuiltinSimulatorProp
742762
// };
743763
}
744764

745-
readonly liveEditing = new LiveEditing();
746-
747765
setupLiveEditing() {
748766
const doc = this.contentDocument!;
749767
// cause edit
@@ -880,9 +898,6 @@ export class BuiltinSimulatorHost implements ISimulatorHost<BuiltinSimulatorProp
880898
// return this.renderer?.createComponent(schema) || null;
881899
}
882900

883-
@obx private instancesMap: {
884-
[docId: string]: Map<string, IPublicTypeComponentInstance[]>;
885-
} = {};
886901
setInstance(docId: string, id: string, instances: IPublicTypeComponentInstance[] | null) {
887902
if (!hasOwnProperty(this.instancesMap, docId)) {
888903
this.instancesMap[docId] = new Map();
@@ -1045,8 +1060,6 @@ export class BuiltinSimulatorHost implements ISimulatorHost<BuiltinSimulatorProp
10451060
};
10461061
}
10471062

1048-
private tryScrollAgain: number | null = null;
1049-
10501063
/**
10511064
* @see ISimulator
10521065
*/
@@ -1107,15 +1120,6 @@ export class BuiltinSimulatorHost implements ISimulatorHost<BuiltinSimulatorProp
11071120
this.renderer?.clearState();
11081121
}
11091122

1110-
private _sensorAvailable = true;
1111-
1112-
/**
1113-
* @see IPublicModelSensor
1114-
*/
1115-
get sensorAvailable(): boolean {
1116-
return this._sensorAvailable;
1117-
}
1118-
11191123
/**
11201124
* @see IPublicModelSensor
11211125
*/
@@ -1160,8 +1164,6 @@ export class BuiltinSimulatorHost implements ISimulatorHost<BuiltinSimulatorProp
11601164
);
11611165
}
11621166

1163-
private sensing = false;
1164-
11651167
/**
11661168
* @see IPublicModelSensor
11671169
*/
@@ -1180,7 +1182,7 @@ export class BuiltinSimulatorHost implements ISimulatorHost<BuiltinSimulatorProp
11801182
const { nodes } = dragObject as IPublicTypeDragNodeObject;
11811183

11821184
const operationalNodes = nodes?.filter((node) => {
1183-
const onMoveHook = node.componentMeta?.getMetadata()?.configure.advanced?.callbacks?.onMoveHook;
1185+
const onMoveHook = node.componentMeta?.advanced.callbacks?.onMoveHook;
11841186
const canMove = onMoveHook && typeof onMoveHook === 'function' ? onMoveHook(node.internalToShellNode()) : true;
11851187

11861188
let parentContainerNode: Node | null = null;
@@ -1195,7 +1197,7 @@ export class BuiltinSimulatorHost implements ISimulatorHost<BuiltinSimulatorProp
11951197
parentNode = parentNode.parent;
11961198
}
11971199

1198-
const onChildMoveHook = parentContainerNode?.componentMeta?.getMetadata()?.configure.advanced?.callbacks?.onChildMoveHook;
1200+
const onChildMoveHook = parentContainerNode?.componentMeta?.advanced.callbacks?.onChildMoveHook;
11991201

12001202
const childrenCanMove = onChildMoveHook && parentContainerNode && typeof onChildMoveHook === 'function' ? onChildMoveHook(node.internalToShellNode(), parentContainerNode.internalToShellNode()) : true;
12011203

0 commit comments

Comments
 (0)