diff --git a/packages/vision-polyfill/src/drag-engine.ts b/packages/vision-polyfill/src/drag-engine.ts new file mode 100644 index 000000000..94c57b0fa --- /dev/null +++ b/packages/vision-polyfill/src/drag-engine.ts @@ -0,0 +1,47 @@ +import { designer } from './editor'; +import { DragObjectType, isNode } from '@ali/lowcode-designer'; + +const dragon = designer.dragon; +const DragEngine = { + from(shell: Element, boost: (e: MouseEvent) => any): any { + dragon.from(shell, (e) => { + const r = boost(e); + if (!r) { + return null; + } + if (isNode(r)) { + return { + type: DragObjectType.Node, + nodes: [r], + }; + } else { + return { + type: DragObjectType.NodeData, + data: r, + }; + } + }); + }, + onDragstart(func: (e: any, dragment: any) => any) { + return dragon.onDragstart((evt) => { + func(evt.originalEvent, evt.dragObject.nodes[0]); + }); + }, + onDrag(func: (e: any, dragment: any, location: any) => any) { + return dragon.onDrag((evt) => { + const loc = designer.currentDocument?.dropLocation; + func(evt.originalEvent, evt.dragObject.nodes[0], loc); + }); + }, + onDragend(func: (dragment: any, location: any, copy: any) => any) { + return dragon.onDragend(({ dragObject, copy }) => { + const loc = designer.currentDocument?.dropLocation; + func(dragObject.nodes[0], loc, copy); + }); + }, + inDragging() { + return dragon.dragging; + }, +}; + +export default DragEngine; diff --git a/packages/vision-polyfill/src/dragon.ts b/packages/vision-polyfill/src/dragon.ts deleted file mode 100644 index 8ccbdbe27..000000000 --- a/packages/vision-polyfill/src/dragon.ts +++ /dev/null @@ -1,34 +0,0 @@ -import { editor, designer } from './editor'; - -const dragon = designer.dragon; - -const dragengine = { - from (shell: Element, boost: (e: MouseEvent) => any): any { - - }, - onDragstart(func: (e: any, dragment: any) => any) { - return dragon.onDragstart((evt) => { - func(evt.originalEvent, evt.dragObject.nodes[0]); - }); - }, - onDrag (func: (e: any, dragment: any, location: Location) => any) { - return dragon.onDrag((evt) => { - const loc = designer.currentDocument?.dropLocation; - func(evt.originalEvent, evt.dragObject.nodes[0]); - }); - }, - onDragend (func: (dragment: any, location: Location, copy: any) => any) { - - }, - addSensor (sensor: any) { - - }, - removeSensor (sensor: any) { - - }, - inDragging () { - - } -} - -export default dragengine; diff --git a/packages/vision-polyfill/src/vision.ts b/packages/vision-polyfill/src/vision.ts index 4da902057..ec1f360bd 100644 --- a/packages/vision-polyfill/src/vision.ts +++ b/packages/vision-polyfill/src/vision.ts @@ -22,6 +22,7 @@ import Field from './field'; import Prop from './prop'; import Env from './env'; import './vision.less'; +import DragEngine from './drag-engine'; function init(container?: Element) { if (!container) { @@ -94,6 +95,7 @@ const VisualEngine = { Prototype, Bundle, Pages, + DragEngine, }; export default VisualEngine;