polyfill dragengine

This commit is contained in:
kangwei 2020-04-21 21:18:21 +08:00
parent 36e4b564b1
commit 8e3e3b589a
3 changed files with 49 additions and 34 deletions

View File

@ -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;

View File

@ -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;

View File

@ -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;