[d565449] | 1 | "use strict";
|
---|
| 2 | Object.defineProperty(exports, "__esModule", { value: true });
|
---|
| 3 | exports.DD = void 0;
|
---|
| 4 | const Global_1 = require("./Global");
|
---|
| 5 | const Util_1 = require("./Util");
|
---|
| 6 | exports.DD = {
|
---|
| 7 | get isDragging() {
|
---|
| 8 | var flag = false;
|
---|
| 9 | exports.DD._dragElements.forEach((elem) => {
|
---|
| 10 | if (elem.dragStatus === 'dragging') {
|
---|
| 11 | flag = true;
|
---|
| 12 | }
|
---|
| 13 | });
|
---|
| 14 | return flag;
|
---|
| 15 | },
|
---|
| 16 | justDragged: false,
|
---|
| 17 | get node() {
|
---|
| 18 | var node;
|
---|
| 19 | exports.DD._dragElements.forEach((elem) => {
|
---|
| 20 | node = elem.node;
|
---|
| 21 | });
|
---|
| 22 | return node;
|
---|
| 23 | },
|
---|
| 24 | _dragElements: new Map(),
|
---|
| 25 | _drag(evt) {
|
---|
| 26 | const nodesToFireEvents = [];
|
---|
| 27 | exports.DD._dragElements.forEach((elem, key) => {
|
---|
| 28 | const { node } = elem;
|
---|
| 29 | const stage = node.getStage();
|
---|
| 30 | stage.setPointersPositions(evt);
|
---|
| 31 | if (elem.pointerId === undefined) {
|
---|
| 32 | elem.pointerId = Util_1.Util._getFirstPointerId(evt);
|
---|
| 33 | }
|
---|
| 34 | const pos = stage._changedPointerPositions.find((pos) => pos.id === elem.pointerId);
|
---|
| 35 | if (!pos) {
|
---|
| 36 | return;
|
---|
| 37 | }
|
---|
| 38 | if (elem.dragStatus !== 'dragging') {
|
---|
| 39 | var dragDistance = node.dragDistance();
|
---|
| 40 | var distance = Math.max(Math.abs(pos.x - elem.startPointerPos.x), Math.abs(pos.y - elem.startPointerPos.y));
|
---|
| 41 | if (distance < dragDistance) {
|
---|
| 42 | return;
|
---|
| 43 | }
|
---|
| 44 | node.startDrag({ evt });
|
---|
| 45 | if (!node.isDragging()) {
|
---|
| 46 | return;
|
---|
| 47 | }
|
---|
| 48 | }
|
---|
| 49 | node._setDragPosition(evt, elem);
|
---|
| 50 | nodesToFireEvents.push(node);
|
---|
| 51 | });
|
---|
| 52 | nodesToFireEvents.forEach((node) => {
|
---|
| 53 | node.fire('dragmove', {
|
---|
| 54 | type: 'dragmove',
|
---|
| 55 | target: node,
|
---|
| 56 | evt: evt,
|
---|
| 57 | }, true);
|
---|
| 58 | });
|
---|
| 59 | },
|
---|
| 60 | _endDragBefore(evt) {
|
---|
| 61 | const drawNodes = [];
|
---|
| 62 | exports.DD._dragElements.forEach((elem) => {
|
---|
| 63 | const { node } = elem;
|
---|
| 64 | const stage = node.getStage();
|
---|
| 65 | if (evt) {
|
---|
| 66 | stage.setPointersPositions(evt);
|
---|
| 67 | }
|
---|
| 68 | const pos = stage._changedPointerPositions.find((pos) => pos.id === elem.pointerId);
|
---|
| 69 | if (!pos) {
|
---|
| 70 | return;
|
---|
| 71 | }
|
---|
| 72 | if (elem.dragStatus === 'dragging' || elem.dragStatus === 'stopped') {
|
---|
| 73 | exports.DD.justDragged = true;
|
---|
| 74 | Global_1.Konva._mouseListenClick = false;
|
---|
| 75 | Global_1.Konva._touchListenClick = false;
|
---|
| 76 | Global_1.Konva._pointerListenClick = false;
|
---|
| 77 | elem.dragStatus = 'stopped';
|
---|
| 78 | }
|
---|
| 79 | const drawNode = elem.node.getLayer() ||
|
---|
| 80 | (elem.node instanceof Global_1.Konva['Stage'] && elem.node);
|
---|
| 81 | if (drawNode && drawNodes.indexOf(drawNode) === -1) {
|
---|
| 82 | drawNodes.push(drawNode);
|
---|
| 83 | }
|
---|
| 84 | });
|
---|
| 85 | drawNodes.forEach((drawNode) => {
|
---|
| 86 | drawNode.draw();
|
---|
| 87 | });
|
---|
| 88 | },
|
---|
| 89 | _endDragAfter(evt) {
|
---|
| 90 | exports.DD._dragElements.forEach((elem, key) => {
|
---|
| 91 | if (elem.dragStatus === 'stopped') {
|
---|
| 92 | elem.node.fire('dragend', {
|
---|
| 93 | type: 'dragend',
|
---|
| 94 | target: elem.node,
|
---|
| 95 | evt: evt,
|
---|
| 96 | }, true);
|
---|
| 97 | }
|
---|
| 98 | if (elem.dragStatus !== 'dragging') {
|
---|
| 99 | exports.DD._dragElements.delete(key);
|
---|
| 100 | }
|
---|
| 101 | });
|
---|
| 102 | },
|
---|
| 103 | };
|
---|
| 104 | if (Global_1.Konva.isBrowser) {
|
---|
| 105 | window.addEventListener('mouseup', exports.DD._endDragBefore, true);
|
---|
| 106 | window.addEventListener('touchend', exports.DD._endDragBefore, true);
|
---|
| 107 | window.addEventListener('mousemove', exports.DD._drag);
|
---|
| 108 | window.addEventListener('touchmove', exports.DD._drag);
|
---|
| 109 | window.addEventListener('mouseup', exports.DD._endDragAfter, false);
|
---|
| 110 | window.addEventListener('touchend', exports.DD._endDragAfter, false);
|
---|
| 111 | }
|
---|