From 8dd8c33de3bf9fe67b1fbb5622bde7260c200f5e Mon Sep 17 00:00:00 2001 From: kangwei Date: Thu, 18 Jun 2020 10:28:10 +0800 Subject: [PATCH 1/4] join 83 --- packages/editor-preset-vision/src/editor.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/editor-preset-vision/src/editor.ts b/packages/editor-preset-vision/src/editor.ts index 2e75c0366..d6a895983 100644 --- a/packages/editor-preset-vision/src/editor.ts +++ b/packages/editor-preset-vision/src/editor.ts @@ -125,7 +125,7 @@ function compatiableReducer(props: any) { }); return newProps; } -// Dirty fix: will remove this reducer +// FIXME: Dirty fix, will remove this reducer designer.addPropsReducer(compatiableReducer, TransformStage.Save); // 设计器组件样式处理 From 52013023b4d5ee0bf7a91f5b1d57f4060fbab355 Mon Sep 17 00:00:00 2001 From: kangwei Date: Thu, 18 Jun 2020 10:45:36 +0800 Subject: [PATCH 2/4] add comments --- packages/designer/src/designer/dragon.ts | 29 ++++++++++++++++++++---- 1 file changed, 24 insertions(+), 5 deletions(-) diff --git a/packages/designer/src/designer/dragon.ts b/packages/designer/src/designer/dragon.ts index 8cb020ca4..13ecf4d16 100644 --- a/packages/designer/src/designer/dragon.ts +++ b/packages/designer/src/designer/dragon.ts @@ -178,6 +178,9 @@ function isDragEvent(e: any): e is DragEvent { return e?.type?.substr(0, 4) === 'drag'; } +/** + * Drag-on 拖拽引擎 + */ export class Dragon { private sensors: ISensor[] = []; @@ -195,12 +198,15 @@ export class Dragon { } private emitter = new EventEmitter(); - // private emptyImage: HTMLImageElement = new Image(); constructor(readonly designer: Designer) { - // this.emptyImage.src = 'data:image/gif;base64,R0lGODlhAQABAAAAACH5BAEKAAEALAAAAAABAAEAAAICTAEAOw=='; } + /** + * Quick listen a shell(container element) drag behavior + * @param shell container element + * @param boost boost got a drag object + */ from(shell: Element, boost: (e: MouseEvent) => DragObject | null) { const mousedown = (e: MouseEvent) => { // ESC or RightClick @@ -222,6 +228,12 @@ export class Dragon { }; } + /** + * boost your dragObject for dragging(flying) 发射拖拽对象 + * + * @param dragObject 拖拽对象 + * @param boostEvent 拖拽初始时事件 + */ boost(dragObject: DragObject, boostEvent: MouseEvent | DragEvent) { const designer = this.designer; const masterSensors = this.getMasterSensors(); @@ -313,16 +325,20 @@ export class Dragon { this.emitter.emit('dragstart', locateEvent); }; + // route: drag-move const move = (e: MouseEvent | DragEvent) => { if (isBoostFromDragAPI) { e.preventDefault(); } if (this._dragging) { + // process dragging drag(e); return; } + // first move check is shaken if (isShaken(boostEvent, e)) { + // is shaken dragstart dragstart(); drag(e); } @@ -335,6 +351,7 @@ export class Dragon { didDrop = true; }; + // end-tail drag process const over = (e?: any) => { if (e && isDragEvent(e)) { e.preventDefault(); @@ -381,6 +398,7 @@ export class Dragon { } }; + // create drag locate event const createLocateEvent = (e: MouseEvent | DragEvent): LocateEvent => { const evt: any = { type: 'LocateEvent', @@ -391,12 +409,14 @@ export class Dragon { const sourceDocument = e.view?.document; + // event from current document if (!sourceDocument || sourceDocument === document) { evt.globalX = e.clientX; evt.globalY = e.clientY; - } else { + } else { // event from simulator sandbox let srcSim: ISimulatorHost | undefined; const lastSim = lastSensor && isSimulatorHost(lastSensor) ? lastSensor : null; + // check source simulator if (lastSim && lastSim.contentDocument === sourceDocument) { srcSim = lastSim; } else { @@ -406,6 +426,7 @@ export class Dragon { } } if (srcSim) { + // transform point by simulator const g = srcSim.viewport.toGlobalPoint(e); evt.globalX = g.clientX; evt.globalY = g.clientY; @@ -454,9 +475,7 @@ export class Dragon { const { dataTransfer } = boostEvent; if (dataTransfer) { - // dataTransfer.setDragImage(this.emptyImage, 0, 0); dataTransfer.effectAllowed = 'all'; - // dataTransfer.dropEffect = newBie || forceCopyState ? 'copy' : 'move'; try { dataTransfer.setData('application/json', '{}'); From b843117fc4a302bf3f0a23fb98e7bda0dc63dac9 Mon Sep 17 00:00:00 2001 From: kangwei Date: Thu, 18 Jun 2020 10:48:20 +0800 Subject: [PATCH 3/4] add comments --- packages/designer/src/designer/dragon.ts | 3 +++ 1 file changed, 3 insertions(+) diff --git a/packages/designer/src/designer/dragon.ts b/packages/designer/src/designer/dragon.ts index 13ecf4d16..60ecef509 100644 --- a/packages/designer/src/designer/dragon.ts +++ b/packages/designer/src/designer/dragon.ts @@ -152,6 +152,9 @@ function getSourceSensor(dragObject: DragObject): ISimulatorHost | null { return dragObject.nodes[0]?.document.simulator || null; } +/** + * make a handler that listen all sensors:document, avoid frame lost + */ function makeEventsHandler( boostEvent: MouseEvent | DragEvent, sensors: ISimulatorHost[], From 9058ac82d5564c9640c62179b1b542b60a4d33f7 Mon Sep 17 00:00:00 2001 From: kangwei Date: Mon, 22 Jun 2020 11:09:01 +0800 Subject: [PATCH 4/4] fix: add extraEnv --- packages/designer/src/builtin-simulator/host.ts | 3 +++ packages/editor-preset-vision/src/bundle/bundle.ts | 6 +++--- packages/editor-preset-vision/src/bundle/prototype.ts | 2 +- packages/editor-preset-vision/src/bundle/trunk.ts | 2 +- packages/plugin-designer/src/index.tsx | 8 ++++++-- 5 files changed, 14 insertions(+), 7 deletions(-) diff --git a/packages/designer/src/builtin-simulator/host.ts b/packages/designer/src/builtin-simulator/host.ts index bc5b70e1c..1283d1e53 100644 --- a/packages/designer/src/builtin-simulator/host.ts +++ b/packages/designer/src/builtin-simulator/host.ts @@ -40,6 +40,7 @@ export interface BuiltinSimulatorProps { device?: 'mobile' | 'iphone' | string; deviceClassName?: string; environment?: Asset; + extraEnvironment?: Asset; library?: LibraryItem[]; simulatorUrl?: Asset; theme?: Asset; @@ -187,6 +188,8 @@ export class BuiltinSimulatorHost implements ISimulatorHost { + propList.forEach((proto: any, index: number) => { if (Array.isArray(proto)) { this.recursivelyRegisterPrototypes(proto, cp); return; } - if (proto instanceof Prototype) { + if (isPrototype(proto)) { const componentName = proto.getComponentName()!; if (!proto.getView() && this.viewsMap[componentName]) { proto.setView(this.viewsMap[componentName]); diff --git a/packages/editor-preset-vision/src/bundle/prototype.ts b/packages/editor-preset-vision/src/bundle/prototype.ts index fa715382e..90553cb73 100644 --- a/packages/editor-preset-vision/src/bundle/prototype.ts +++ b/packages/editor-preset-vision/src/bundle/prototype.ts @@ -217,7 +217,7 @@ class Prototype { } readonly isPrototype = true; - private meta: ComponentMeta; + readonly meta: ComponentMeta; readonly options: OldPrototypeConfig | ComponentMetadata; constructor(input: OldPrototypeConfig | ComponentMetadata | ComponentMeta) { diff --git a/packages/editor-preset-vision/src/bundle/trunk.ts b/packages/editor-preset-vision/src/bundle/trunk.ts index e4e41e35d..f38f1db2c 100644 --- a/packages/editor-preset-vision/src/bundle/trunk.ts +++ b/packages/editor-preset-vision/src/bundle/trunk.ts @@ -35,7 +35,7 @@ export class Trunk { bundle = this.trunk[i]; prototype = bundle.get(name); if (prototype) { - return prototype; + return (prototype.meta as any).prototype; } } return this.metaBundle.getFromMeta(name); diff --git a/packages/plugin-designer/src/index.tsx b/packages/plugin-designer/src/index.tsx index 88647e809..aac7dab28 100644 --- a/packages/plugin-designer/src/index.tsx +++ b/packages/plugin-designer/src/index.tsx @@ -10,6 +10,7 @@ export interface PluginProps { interface DesignerPluginState { componentMetadatas?: any[] | null; library?: any[] | null; + extraEnvironment?: any[] | null; } export default class DesignerPlugin extends PureComponent { @@ -18,6 +19,7 @@ export default class DesignerPlugin extends PureComponent );