@antv/g-plugin-dragndrop
Advanced tools
Comparing version 1.1.0 to 1.1.1
import { Syringe, inject, SceneGraphService, RenderingContext, singleton, RenderingPluginContribution, Module } from '@antv/g'; | ||
import { __decorate, __metadata } from 'tslib'; | ||
function ownKeys(object, enumerableOnly) { | ||
var keys = Object.keys(object); | ||
if (Object.getOwnPropertySymbols) { | ||
var symbols = Object.getOwnPropertySymbols(object); | ||
enumerableOnly && (symbols = symbols.filter(function (sym) { | ||
return Object.getOwnPropertyDescriptor(object, sym).enumerable; | ||
})), keys.push.apply(keys, symbols); | ||
} | ||
return keys; | ||
} | ||
function _objectSpread2(target) { | ||
for (var i = 1; i < arguments.length; i++) { | ||
var source = null != arguments[i] ? arguments[i] : {}; | ||
i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { | ||
_defineProperty(target, key, source[key]); | ||
}) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { | ||
Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); | ||
}); | ||
} | ||
return target; | ||
} | ||
function _regeneratorRuntime() { | ||
@@ -385,18 +411,40 @@ /*! regenerator-runtime -- Copyright (c) 2014-present, Facebook, Inc. -- license (MIT): https://github.com/facebook/regenerator/blob/main/LICENSE */ | ||
function _extends() { | ||
_extends = Object.assign || function (target) { | ||
for (var i = 1; i < arguments.length; i++) { | ||
var source = arguments[i]; | ||
function _classCallCheck(instance, Constructor) { | ||
if (!(instance instanceof Constructor)) { | ||
throw new TypeError("Cannot call a class as a function"); | ||
} | ||
} | ||
for (var key in source) { | ||
if (Object.prototype.hasOwnProperty.call(source, key)) { | ||
target[key] = source[key]; | ||
} | ||
} | ||
} | ||
function _defineProperties(target, props) { | ||
for (var i = 0; i < props.length; i++) { | ||
var descriptor = props[i]; | ||
descriptor.enumerable = descriptor.enumerable || false; | ||
descriptor.configurable = true; | ||
if ("value" in descriptor) descriptor.writable = true; | ||
Object.defineProperty(target, descriptor.key, descriptor); | ||
} | ||
} | ||
return target; | ||
}; | ||
function _createClass(Constructor, protoProps, staticProps) { | ||
if (protoProps) _defineProperties(Constructor.prototype, protoProps); | ||
if (staticProps) _defineProperties(Constructor, staticProps); | ||
Object.defineProperty(Constructor, "prototype", { | ||
writable: false | ||
}); | ||
return Constructor; | ||
} | ||
return _extends.apply(this, arguments); | ||
function _defineProperty(obj, key, value) { | ||
if (key in obj) { | ||
Object.defineProperty(obj, key, { | ||
value: value, | ||
enumerable: true, | ||
configurable: true, | ||
writable: true | ||
}); | ||
} else { | ||
obj[key] = value; | ||
} | ||
return obj; | ||
} | ||
@@ -411,2 +459,4 @@ | ||
function DragndropPlugin() { | ||
_classCallCheck(this, DragndropPlugin); | ||
this.sceneGraphService = void 0; | ||
@@ -417,165 +467,166 @@ this.renderingContext = void 0; | ||
var _proto = DragndropPlugin.prototype; | ||
_createClass(DragndropPlugin, [{ | ||
key: "apply", | ||
value: function apply(renderingService) { | ||
var document = this.renderingContext.root.ownerDocument; // TODO: should we add an option like `draggable` to Canvas | ||
_proto.apply = function apply(renderingService) { | ||
var document = this.renderingContext.root.ownerDocument; // TODO: should we add an option like `draggable` to Canvas | ||
var canvas = document.defaultView; | ||
var _this$dragndropPlugin = this.dragndropPluginOptions, | ||
overlap = _this$dragndropPlugin.overlap, | ||
isDocumentDraggable = _this$dragndropPlugin.isDocumentDraggable, | ||
isDocumentDroppable = _this$dragndropPlugin.isDocumentDroppable, | ||
dragstartDistanceThreshold = _this$dragndropPlugin.dragstartDistanceThreshold, | ||
dragstartTimeThreshold = _this$dragndropPlugin.dragstartTimeThreshold; | ||
var canvas = document.defaultView; | ||
var _this$dragndropPlugin = this.dragndropPluginOptions, | ||
overlap = _this$dragndropPlugin.overlap, | ||
isDocumentDraggable = _this$dragndropPlugin.isDocumentDraggable, | ||
isDocumentDroppable = _this$dragndropPlugin.isDocumentDroppable, | ||
dragstartDistanceThreshold = _this$dragndropPlugin.dragstartDistanceThreshold, | ||
dragstartTimeThreshold = _this$dragndropPlugin.dragstartTimeThreshold; | ||
var handlePointerdown = function handlePointerdown(event) { | ||
var target = event.target; | ||
var isDocument = target === document; | ||
var handlePointerdown = function handlePointerdown(event) { | ||
var target = event.target; | ||
var isDocument = target === document; | ||
if (isDocument && isDocumentDraggable || target.getAttribute && target.getAttribute('draggable')) { | ||
// @ts-ignore | ||
var onMouseMove = /*#__PURE__*/function () { | ||
var _ref = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee(event) { | ||
var timeElapsed, distanceMoved, pointerEventsOldValue, point, elemBelow, droppableBelow; | ||
return _regeneratorRuntime().wrap(function _callee$(_context) { | ||
while (1) { | ||
switch (_context.prev = _context.next) { | ||
case 0: | ||
if (dragstartTriggered) { | ||
_context.next = 8; | ||
break; | ||
} | ||
if (isDocument && isDocumentDraggable || target.getAttribute && target.getAttribute('draggable')) { | ||
// @ts-ignore | ||
var onMouseMove = /*#__PURE__*/function () { | ||
var _ref = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee(event) { | ||
var timeElapsed, distanceMoved, pointerEventsOldValue, point, elemBelow, droppableBelow; | ||
return _regeneratorRuntime().wrap(function _callee$(_context) { | ||
while (1) { | ||
switch (_context.prev = _context.next) { | ||
case 0: | ||
if (dragstartTriggered) { | ||
_context.next = 8; | ||
break; | ||
} | ||
timeElapsed = event.timeStamp - dragstartTimeStamp; | ||
distanceMoved = Math.sqrt(Math.pow(event.canvasX - dragstartCanvasCoordinates[0], 2) + Math.pow(event.canvasY - dragstartCanvasCoordinates[1], 2)); // check thresholds | ||
timeElapsed = event.timeStamp - dragstartTimeStamp; | ||
distanceMoved = Math.sqrt(Math.pow(event.canvasX - dragstartCanvasCoordinates[0], 2) + Math.pow(event.canvasY - dragstartCanvasCoordinates[1], 2)); // check thresholds | ||
if (!(timeElapsed <= dragstartTimeThreshold || distanceMoved <= dragstartDistanceThreshold)) { | ||
_context.next = 5; | ||
break; | ||
} | ||
if (!(timeElapsed <= dragstartTimeThreshold || distanceMoved <= dragstartDistanceThreshold)) { | ||
_context.next = 5; | ||
break; | ||
} | ||
return _context.abrupt("return"); | ||
return _context.abrupt("return"); | ||
case 5: | ||
// @see https://developer.mozilla.org/zh-CN/docs/Web/API/Document/dragstart_event | ||
event.type = 'dragstart'; | ||
target.dispatchEvent(event); | ||
dragstartTriggered = true; | ||
case 5: | ||
// @see https://developer.mozilla.org/zh-CN/docs/Web/API/Document/dragstart_event | ||
event.type = 'dragstart'; | ||
target.dispatchEvent(event); | ||
dragstartTriggered = true; | ||
case 8: | ||
// @see https://developer.mozilla.org/zh-CN/docs/Web/API/Document/drag_event | ||
event.type = 'drag'; | ||
target.dispatchEvent(event); | ||
case 8: | ||
// @see https://developer.mozilla.org/zh-CN/docs/Web/API/Document/drag_event | ||
event.type = 'drag'; | ||
target.dispatchEvent(event); | ||
if (isDocument) { | ||
_context.next = 20; | ||
break; | ||
} | ||
if (isDocument) { | ||
_context.next = 20; | ||
break; | ||
} | ||
// prevent from picking the dragging element | ||
pointerEventsOldValue = target.style.pointerEvents; | ||
target.style.pointerEvents = 'none'; | ||
point = overlap === 'pointer' ? [event.canvasX, event.canvasY] : target.getBounds().center; | ||
_context.next = 16; | ||
return document.elementFromPoint(point[0], point[1]); | ||
// prevent from picking the dragging element | ||
pointerEventsOldValue = target.style.pointerEvents; | ||
target.style.pointerEvents = 'none'; | ||
point = overlap === 'pointer' ? [event.canvasX, event.canvasY] : target.getBounds().center; | ||
_context.next = 16; | ||
return document.elementFromPoint(point[0], point[1]); | ||
case 16: | ||
elemBelow = _context.sent; | ||
target.style.pointerEvents = pointerEventsOldValue; | ||
droppableBelow = (elemBelow === null || elemBelow === void 0 ? void 0 : elemBelow.closest('[droppable=true]')) || (isDocumentDroppable ? document : null); | ||
case 16: | ||
elemBelow = _context.sent; | ||
target.style.pointerEvents = pointerEventsOldValue; | ||
droppableBelow = (elemBelow === null || elemBelow === void 0 ? void 0 : elemBelow.closest('[droppable=true]')) || (isDocumentDroppable ? document : null); | ||
if (currentDroppable !== droppableBelow) { | ||
if (currentDroppable) { | ||
// null when we were not over a droppable before this event | ||
// @see https://developer.mozilla.org/zh-CN/docs/Web/API/Document/dragleave_event | ||
event.type = 'dragleave'; | ||
event.target = currentDroppable; | ||
currentDroppable.dispatchEvent(event); | ||
} | ||
if (currentDroppable !== droppableBelow) { | ||
if (currentDroppable) { | ||
// null when we were not over a droppable before this event | ||
// @see https://developer.mozilla.org/zh-CN/docs/Web/API/Document/dragleave_event | ||
event.type = 'dragleave'; | ||
event.target = currentDroppable; | ||
currentDroppable.dispatchEvent(event); | ||
} | ||
if (droppableBelow) { | ||
// @see https://developer.mozilla.org/zh-CN/docs/Web/API/Document/dragleave_event | ||
event.type = 'dragenter'; | ||
event.target = droppableBelow; | ||
droppableBelow.dispatchEvent(event); | ||
} | ||
if (droppableBelow) { | ||
// @see https://developer.mozilla.org/zh-CN/docs/Web/API/Document/dragleave_event | ||
event.type = 'dragenter'; | ||
event.target = droppableBelow; | ||
droppableBelow.dispatchEvent(event); | ||
} | ||
currentDroppable = droppableBelow; | ||
currentDroppable = droppableBelow; | ||
if (currentDroppable) { | ||
// null if we're not coming over a droppable now | ||
// @see https://developer.mozilla.org/zh-CN/docs/Web/API/Document/dragover_event | ||
event.type = 'dragover'; | ||
event.target = currentDroppable; | ||
currentDroppable.dispatchEvent(event); | ||
if (currentDroppable) { | ||
// null if we're not coming over a droppable now | ||
// @see https://developer.mozilla.org/zh-CN/docs/Web/API/Document/dragover_event | ||
event.type = 'dragover'; | ||
event.target = currentDroppable; | ||
currentDroppable.dispatchEvent(event); | ||
} | ||
} | ||
} | ||
case 20: | ||
case "end": | ||
return _context.stop(); | ||
case 20: | ||
case "end": | ||
return _context.stop(); | ||
} | ||
} | ||
} | ||
}, _callee); | ||
})); | ||
}, _callee); | ||
})); | ||
return function onMouseMove(_x) { | ||
return _ref.apply(this, arguments); | ||
}; | ||
}(); | ||
return function onMouseMove(_x) { | ||
return _ref.apply(this, arguments); | ||
}; | ||
}(); | ||
// delay triggering dragstart event | ||
var dragstartTriggered = false; | ||
var dragstartTimeStamp = event.timeStamp; | ||
var dragstartCanvasCoordinates = [event.canvasX, event.canvasY]; | ||
var currentDroppable = null; | ||
canvas.addEventListener('pointermove', onMouseMove); | ||
// delay triggering dragstart event | ||
var dragstartTriggered = false; | ||
var dragstartTimeStamp = event.timeStamp; | ||
var dragstartCanvasCoordinates = [event.canvasX, event.canvasY]; | ||
var currentDroppable = null; | ||
canvas.addEventListener('pointermove', onMouseMove); | ||
var stopDragging = function stopDragging() { | ||
if (dragstartTriggered) { | ||
// drop should fire before dragend | ||
// @see https://javascript.tutorialink.com/is-there-a-defined-ordering-between-dragend-and-drop-events/ | ||
if (currentDroppable) { | ||
// @see https://developer.mozilla.org/zh-CN/docs/Web/API/Document/drop_event | ||
event.type = 'drop'; | ||
event.target = currentDroppable; | ||
currentDroppable.dispatchEvent(event); | ||
} // @see https://developer.mozilla.org/zh-CN/docs/Web/API/Document/dragend_event | ||
var stopDragging = function stopDragging() { | ||
if (dragstartTriggered) { | ||
// drop should fire before dragend | ||
// @see https://javascript.tutorialink.com/is-there-a-defined-ordering-between-dragend-and-drop-events/ | ||
if (currentDroppable) { | ||
// @see https://developer.mozilla.org/zh-CN/docs/Web/API/Document/drop_event | ||
event.type = 'drop'; | ||
event.target = currentDroppable; | ||
currentDroppable.dispatchEvent(event); | ||
} // @see https://developer.mozilla.org/zh-CN/docs/Web/API/Document/dragend_event | ||
event.type = 'dragend'; | ||
target.dispatchEvent(event); | ||
dragstartTriggered = false; | ||
} | ||
event.type = 'dragend'; | ||
target.dispatchEvent(event); | ||
dragstartTriggered = false; | ||
} | ||
canvas.removeEventListener('pointermove', onMouseMove); | ||
}; | ||
canvas.removeEventListener('pointermove', onMouseMove); | ||
}; | ||
target.addEventListener('pointerup', stopDragging, { | ||
once: true | ||
}); | ||
target.addEventListener('pointerupoutside', stopDragging, { | ||
once: true | ||
}); | ||
} | ||
}; | ||
target.addEventListener('pointerup', stopDragging, { | ||
once: true | ||
}); | ||
target.addEventListener('pointerupoutside', stopDragging, { | ||
once: true | ||
}); | ||
} | ||
}; | ||
renderingService.hooks.init.tapPromise(DragndropPlugin_1.tag, /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee2() { | ||
return _regeneratorRuntime().wrap(function _callee2$(_context2) { | ||
while (1) { | ||
switch (_context2.prev = _context2.next) { | ||
case 0: | ||
canvas.addEventListener('pointerdown', handlePointerdown); | ||
renderingService.hooks.init.tapPromise(DragndropPlugin_1.tag, /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee2() { | ||
return _regeneratorRuntime().wrap(function _callee2$(_context2) { | ||
while (1) { | ||
switch (_context2.prev = _context2.next) { | ||
case 0: | ||
canvas.addEventListener('pointerdown', handlePointerdown); | ||
case 1: | ||
case "end": | ||
return _context2.stop(); | ||
case 1: | ||
case "end": | ||
return _context2.stop(); | ||
} | ||
} | ||
} | ||
}, _callee2); | ||
}))); | ||
renderingService.hooks.destroy.tap(DragndropPlugin_1.tag, function () { | ||
canvas.removeEventListener('pointerdown', handlePointerdown); | ||
}); | ||
}; | ||
}, _callee2); | ||
}))); | ||
renderingService.hooks.destroy.tap(DragndropPlugin_1.tag, function () { | ||
canvas.removeEventListener('pointerdown', handlePointerdown); | ||
}); | ||
} | ||
}]); | ||
@@ -599,7 +650,7 @@ return DragndropPlugin; | ||
var Plugin = /*#__PURE__*/function () { | ||
function Plugin(options) { | ||
if (options === void 0) { | ||
options = {}; | ||
} | ||
function Plugin() { | ||
var options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {}; | ||
_classCallCheck(this, Plugin); | ||
this.options = void 0; | ||
@@ -610,22 +661,24 @@ this.name = 'dragndrop'; | ||
var _proto = Plugin.prototype; | ||
_createClass(Plugin, [{ | ||
key: "init", | ||
value: function init(container) { | ||
container.register(DragndropPluginOptions, { | ||
useValue: _objectSpread2({ | ||
overlap: 'pointer', | ||
isDocumentDraggable: false, | ||
isDocumentDroppable: false, | ||
dragstartDistanceThreshold: 0, | ||
dragstartTimeThreshold: 0 | ||
}, this.options) | ||
}); | ||
container.load(containerModule, true); | ||
} | ||
}, { | ||
key: "destroy", | ||
value: function destroy(container) { | ||
container.remove(DragndropPluginOptions); | ||
container.unload(containerModule); | ||
} | ||
}]); | ||
_proto.init = function init(container) { | ||
container.register(DragndropPluginOptions, { | ||
useValue: _extends({ | ||
overlap: 'pointer', | ||
isDocumentDraggable: false, | ||
isDocumentDroppable: false, | ||
dragstartDistanceThreshold: 0, | ||
dragstartTimeThreshold: 0 | ||
}, this.options) | ||
}); | ||
container.load(containerModule, true); | ||
}; | ||
_proto.destroy = function destroy(container) { | ||
container.remove(DragndropPluginOptions); | ||
container.unload(containerModule); | ||
}; | ||
return Plugin; | ||
@@ -632,0 +685,0 @@ }(); |
@@ -8,2 +8,28 @@ 'use strict'; | ||
function ownKeys(object, enumerableOnly) { | ||
var keys = Object.keys(object); | ||
if (Object.getOwnPropertySymbols) { | ||
var symbols = Object.getOwnPropertySymbols(object); | ||
enumerableOnly && (symbols = symbols.filter(function (sym) { | ||
return Object.getOwnPropertyDescriptor(object, sym).enumerable; | ||
})), keys.push.apply(keys, symbols); | ||
} | ||
return keys; | ||
} | ||
function _objectSpread2(target) { | ||
for (var i = 1; i < arguments.length; i++) { | ||
var source = null != arguments[i] ? arguments[i] : {}; | ||
i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { | ||
_defineProperty(target, key, source[key]); | ||
}) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { | ||
Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); | ||
}); | ||
} | ||
return target; | ||
} | ||
function _regeneratorRuntime() { | ||
@@ -390,18 +416,40 @@ /*! regenerator-runtime -- Copyright (c) 2014-present, Facebook, Inc. -- license (MIT): https://github.com/facebook/regenerator/blob/main/LICENSE */ | ||
function _extends() { | ||
_extends = Object.assign || function (target) { | ||
for (var i = 1; i < arguments.length; i++) { | ||
var source = arguments[i]; | ||
function _classCallCheck(instance, Constructor) { | ||
if (!(instance instanceof Constructor)) { | ||
throw new TypeError("Cannot call a class as a function"); | ||
} | ||
} | ||
for (var key in source) { | ||
if (Object.prototype.hasOwnProperty.call(source, key)) { | ||
target[key] = source[key]; | ||
} | ||
} | ||
} | ||
function _defineProperties(target, props) { | ||
for (var i = 0; i < props.length; i++) { | ||
var descriptor = props[i]; | ||
descriptor.enumerable = descriptor.enumerable || false; | ||
descriptor.configurable = true; | ||
if ("value" in descriptor) descriptor.writable = true; | ||
Object.defineProperty(target, descriptor.key, descriptor); | ||
} | ||
} | ||
return target; | ||
}; | ||
function _createClass(Constructor, protoProps, staticProps) { | ||
if (protoProps) _defineProperties(Constructor.prototype, protoProps); | ||
if (staticProps) _defineProperties(Constructor, staticProps); | ||
Object.defineProperty(Constructor, "prototype", { | ||
writable: false | ||
}); | ||
return Constructor; | ||
} | ||
return _extends.apply(this, arguments); | ||
function _defineProperty(obj, key, value) { | ||
if (key in obj) { | ||
Object.defineProperty(obj, key, { | ||
value: value, | ||
enumerable: true, | ||
configurable: true, | ||
writable: true | ||
}); | ||
} else { | ||
obj[key] = value; | ||
} | ||
return obj; | ||
} | ||
@@ -416,2 +464,4 @@ | ||
function DragndropPlugin() { | ||
_classCallCheck(this, DragndropPlugin); | ||
this.sceneGraphService = void 0; | ||
@@ -422,165 +472,166 @@ this.renderingContext = void 0; | ||
var _proto = DragndropPlugin.prototype; | ||
_createClass(DragndropPlugin, [{ | ||
key: "apply", | ||
value: function apply(renderingService) { | ||
var document = this.renderingContext.root.ownerDocument; // TODO: should we add an option like `draggable` to Canvas | ||
_proto.apply = function apply(renderingService) { | ||
var document = this.renderingContext.root.ownerDocument; // TODO: should we add an option like `draggable` to Canvas | ||
var canvas = document.defaultView; | ||
var _this$dragndropPlugin = this.dragndropPluginOptions, | ||
overlap = _this$dragndropPlugin.overlap, | ||
isDocumentDraggable = _this$dragndropPlugin.isDocumentDraggable, | ||
isDocumentDroppable = _this$dragndropPlugin.isDocumentDroppable, | ||
dragstartDistanceThreshold = _this$dragndropPlugin.dragstartDistanceThreshold, | ||
dragstartTimeThreshold = _this$dragndropPlugin.dragstartTimeThreshold; | ||
var canvas = document.defaultView; | ||
var _this$dragndropPlugin = this.dragndropPluginOptions, | ||
overlap = _this$dragndropPlugin.overlap, | ||
isDocumentDraggable = _this$dragndropPlugin.isDocumentDraggable, | ||
isDocumentDroppable = _this$dragndropPlugin.isDocumentDroppable, | ||
dragstartDistanceThreshold = _this$dragndropPlugin.dragstartDistanceThreshold, | ||
dragstartTimeThreshold = _this$dragndropPlugin.dragstartTimeThreshold; | ||
var handlePointerdown = function handlePointerdown(event) { | ||
var target = event.target; | ||
var isDocument = target === document; | ||
var handlePointerdown = function handlePointerdown(event) { | ||
var target = event.target; | ||
var isDocument = target === document; | ||
if (isDocument && isDocumentDraggable || target.getAttribute && target.getAttribute('draggable')) { | ||
// @ts-ignore | ||
var onMouseMove = /*#__PURE__*/function () { | ||
var _ref = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee(event) { | ||
var timeElapsed, distanceMoved, pointerEventsOldValue, point, elemBelow, droppableBelow; | ||
return _regeneratorRuntime().wrap(function _callee$(_context) { | ||
while (1) { | ||
switch (_context.prev = _context.next) { | ||
case 0: | ||
if (dragstartTriggered) { | ||
_context.next = 8; | ||
break; | ||
} | ||
if (isDocument && isDocumentDraggable || target.getAttribute && target.getAttribute('draggable')) { | ||
// @ts-ignore | ||
var onMouseMove = /*#__PURE__*/function () { | ||
var _ref = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee(event) { | ||
var timeElapsed, distanceMoved, pointerEventsOldValue, point, elemBelow, droppableBelow; | ||
return _regeneratorRuntime().wrap(function _callee$(_context) { | ||
while (1) { | ||
switch (_context.prev = _context.next) { | ||
case 0: | ||
if (dragstartTriggered) { | ||
_context.next = 8; | ||
break; | ||
} | ||
timeElapsed = event.timeStamp - dragstartTimeStamp; | ||
distanceMoved = Math.sqrt(Math.pow(event.canvasX - dragstartCanvasCoordinates[0], 2) + Math.pow(event.canvasY - dragstartCanvasCoordinates[1], 2)); // check thresholds | ||
timeElapsed = event.timeStamp - dragstartTimeStamp; | ||
distanceMoved = Math.sqrt(Math.pow(event.canvasX - dragstartCanvasCoordinates[0], 2) + Math.pow(event.canvasY - dragstartCanvasCoordinates[1], 2)); // check thresholds | ||
if (!(timeElapsed <= dragstartTimeThreshold || distanceMoved <= dragstartDistanceThreshold)) { | ||
_context.next = 5; | ||
break; | ||
} | ||
if (!(timeElapsed <= dragstartTimeThreshold || distanceMoved <= dragstartDistanceThreshold)) { | ||
_context.next = 5; | ||
break; | ||
} | ||
return _context.abrupt("return"); | ||
return _context.abrupt("return"); | ||
case 5: | ||
// @see https://developer.mozilla.org/zh-CN/docs/Web/API/Document/dragstart_event | ||
event.type = 'dragstart'; | ||
target.dispatchEvent(event); | ||
dragstartTriggered = true; | ||
case 5: | ||
// @see https://developer.mozilla.org/zh-CN/docs/Web/API/Document/dragstart_event | ||
event.type = 'dragstart'; | ||
target.dispatchEvent(event); | ||
dragstartTriggered = true; | ||
case 8: | ||
// @see https://developer.mozilla.org/zh-CN/docs/Web/API/Document/drag_event | ||
event.type = 'drag'; | ||
target.dispatchEvent(event); | ||
case 8: | ||
// @see https://developer.mozilla.org/zh-CN/docs/Web/API/Document/drag_event | ||
event.type = 'drag'; | ||
target.dispatchEvent(event); | ||
if (isDocument) { | ||
_context.next = 20; | ||
break; | ||
} | ||
if (isDocument) { | ||
_context.next = 20; | ||
break; | ||
} | ||
// prevent from picking the dragging element | ||
pointerEventsOldValue = target.style.pointerEvents; | ||
target.style.pointerEvents = 'none'; | ||
point = overlap === 'pointer' ? [event.canvasX, event.canvasY] : target.getBounds().center; | ||
_context.next = 16; | ||
return document.elementFromPoint(point[0], point[1]); | ||
// prevent from picking the dragging element | ||
pointerEventsOldValue = target.style.pointerEvents; | ||
target.style.pointerEvents = 'none'; | ||
point = overlap === 'pointer' ? [event.canvasX, event.canvasY] : target.getBounds().center; | ||
_context.next = 16; | ||
return document.elementFromPoint(point[0], point[1]); | ||
case 16: | ||
elemBelow = _context.sent; | ||
target.style.pointerEvents = pointerEventsOldValue; | ||
droppableBelow = (elemBelow === null || elemBelow === void 0 ? void 0 : elemBelow.closest('[droppable=true]')) || (isDocumentDroppable ? document : null); | ||
case 16: | ||
elemBelow = _context.sent; | ||
target.style.pointerEvents = pointerEventsOldValue; | ||
droppableBelow = (elemBelow === null || elemBelow === void 0 ? void 0 : elemBelow.closest('[droppable=true]')) || (isDocumentDroppable ? document : null); | ||
if (currentDroppable !== droppableBelow) { | ||
if (currentDroppable) { | ||
// null when we were not over a droppable before this event | ||
// @see https://developer.mozilla.org/zh-CN/docs/Web/API/Document/dragleave_event | ||
event.type = 'dragleave'; | ||
event.target = currentDroppable; | ||
currentDroppable.dispatchEvent(event); | ||
} | ||
if (currentDroppable !== droppableBelow) { | ||
if (currentDroppable) { | ||
// null when we were not over a droppable before this event | ||
// @see https://developer.mozilla.org/zh-CN/docs/Web/API/Document/dragleave_event | ||
event.type = 'dragleave'; | ||
event.target = currentDroppable; | ||
currentDroppable.dispatchEvent(event); | ||
} | ||
if (droppableBelow) { | ||
// @see https://developer.mozilla.org/zh-CN/docs/Web/API/Document/dragleave_event | ||
event.type = 'dragenter'; | ||
event.target = droppableBelow; | ||
droppableBelow.dispatchEvent(event); | ||
} | ||
if (droppableBelow) { | ||
// @see https://developer.mozilla.org/zh-CN/docs/Web/API/Document/dragleave_event | ||
event.type = 'dragenter'; | ||
event.target = droppableBelow; | ||
droppableBelow.dispatchEvent(event); | ||
} | ||
currentDroppable = droppableBelow; | ||
currentDroppable = droppableBelow; | ||
if (currentDroppable) { | ||
// null if we're not coming over a droppable now | ||
// @see https://developer.mozilla.org/zh-CN/docs/Web/API/Document/dragover_event | ||
event.type = 'dragover'; | ||
event.target = currentDroppable; | ||
currentDroppable.dispatchEvent(event); | ||
if (currentDroppable) { | ||
// null if we're not coming over a droppable now | ||
// @see https://developer.mozilla.org/zh-CN/docs/Web/API/Document/dragover_event | ||
event.type = 'dragover'; | ||
event.target = currentDroppable; | ||
currentDroppable.dispatchEvent(event); | ||
} | ||
} | ||
} | ||
case 20: | ||
case "end": | ||
return _context.stop(); | ||
case 20: | ||
case "end": | ||
return _context.stop(); | ||
} | ||
} | ||
} | ||
}, _callee); | ||
})); | ||
}, _callee); | ||
})); | ||
return function onMouseMove(_x) { | ||
return _ref.apply(this, arguments); | ||
}; | ||
}(); | ||
return function onMouseMove(_x) { | ||
return _ref.apply(this, arguments); | ||
}; | ||
}(); | ||
// delay triggering dragstart event | ||
var dragstartTriggered = false; | ||
var dragstartTimeStamp = event.timeStamp; | ||
var dragstartCanvasCoordinates = [event.canvasX, event.canvasY]; | ||
var currentDroppable = null; | ||
canvas.addEventListener('pointermove', onMouseMove); | ||
// delay triggering dragstart event | ||
var dragstartTriggered = false; | ||
var dragstartTimeStamp = event.timeStamp; | ||
var dragstartCanvasCoordinates = [event.canvasX, event.canvasY]; | ||
var currentDroppable = null; | ||
canvas.addEventListener('pointermove', onMouseMove); | ||
var stopDragging = function stopDragging() { | ||
if (dragstartTriggered) { | ||
// drop should fire before dragend | ||
// @see https://javascript.tutorialink.com/is-there-a-defined-ordering-between-dragend-and-drop-events/ | ||
if (currentDroppable) { | ||
// @see https://developer.mozilla.org/zh-CN/docs/Web/API/Document/drop_event | ||
event.type = 'drop'; | ||
event.target = currentDroppable; | ||
currentDroppable.dispatchEvent(event); | ||
} // @see https://developer.mozilla.org/zh-CN/docs/Web/API/Document/dragend_event | ||
var stopDragging = function stopDragging() { | ||
if (dragstartTriggered) { | ||
// drop should fire before dragend | ||
// @see https://javascript.tutorialink.com/is-there-a-defined-ordering-between-dragend-and-drop-events/ | ||
if (currentDroppable) { | ||
// @see https://developer.mozilla.org/zh-CN/docs/Web/API/Document/drop_event | ||
event.type = 'drop'; | ||
event.target = currentDroppable; | ||
currentDroppable.dispatchEvent(event); | ||
} // @see https://developer.mozilla.org/zh-CN/docs/Web/API/Document/dragend_event | ||
event.type = 'dragend'; | ||
target.dispatchEvent(event); | ||
dragstartTriggered = false; | ||
} | ||
event.type = 'dragend'; | ||
target.dispatchEvent(event); | ||
dragstartTriggered = false; | ||
} | ||
canvas.removeEventListener('pointermove', onMouseMove); | ||
}; | ||
canvas.removeEventListener('pointermove', onMouseMove); | ||
}; | ||
target.addEventListener('pointerup', stopDragging, { | ||
once: true | ||
}); | ||
target.addEventListener('pointerupoutside', stopDragging, { | ||
once: true | ||
}); | ||
} | ||
}; | ||
target.addEventListener('pointerup', stopDragging, { | ||
once: true | ||
}); | ||
target.addEventListener('pointerupoutside', stopDragging, { | ||
once: true | ||
}); | ||
} | ||
}; | ||
renderingService.hooks.init.tapPromise(DragndropPlugin_1.tag, /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee2() { | ||
return _regeneratorRuntime().wrap(function _callee2$(_context2) { | ||
while (1) { | ||
switch (_context2.prev = _context2.next) { | ||
case 0: | ||
canvas.addEventListener('pointerdown', handlePointerdown); | ||
renderingService.hooks.init.tapPromise(DragndropPlugin_1.tag, /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee2() { | ||
return _regeneratorRuntime().wrap(function _callee2$(_context2) { | ||
while (1) { | ||
switch (_context2.prev = _context2.next) { | ||
case 0: | ||
canvas.addEventListener('pointerdown', handlePointerdown); | ||
case 1: | ||
case "end": | ||
return _context2.stop(); | ||
case 1: | ||
case "end": | ||
return _context2.stop(); | ||
} | ||
} | ||
} | ||
}, _callee2); | ||
}))); | ||
renderingService.hooks.destroy.tap(DragndropPlugin_1.tag, function () { | ||
canvas.removeEventListener('pointerdown', handlePointerdown); | ||
}); | ||
}; | ||
}, _callee2); | ||
}))); | ||
renderingService.hooks.destroy.tap(DragndropPlugin_1.tag, function () { | ||
canvas.removeEventListener('pointerdown', handlePointerdown); | ||
}); | ||
} | ||
}]); | ||
@@ -604,7 +655,7 @@ return DragndropPlugin; | ||
var Plugin = /*#__PURE__*/function () { | ||
function Plugin(options) { | ||
if (options === void 0) { | ||
options = {}; | ||
} | ||
function Plugin() { | ||
var options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {}; | ||
_classCallCheck(this, Plugin); | ||
this.options = void 0; | ||
@@ -615,22 +666,24 @@ this.name = 'dragndrop'; | ||
var _proto = Plugin.prototype; | ||
_createClass(Plugin, [{ | ||
key: "init", | ||
value: function init(container) { | ||
container.register(DragndropPluginOptions, { | ||
useValue: _objectSpread2({ | ||
overlap: 'pointer', | ||
isDocumentDraggable: false, | ||
isDocumentDroppable: false, | ||
dragstartDistanceThreshold: 0, | ||
dragstartTimeThreshold: 0 | ||
}, this.options) | ||
}); | ||
container.load(containerModule, true); | ||
} | ||
}, { | ||
key: "destroy", | ||
value: function destroy(container) { | ||
container.remove(DragndropPluginOptions); | ||
container.unload(containerModule); | ||
} | ||
}]); | ||
_proto.init = function init(container) { | ||
container.register(DragndropPluginOptions, { | ||
useValue: _extends({ | ||
overlap: 'pointer', | ||
isDocumentDraggable: false, | ||
isDocumentDroppable: false, | ||
dragstartDistanceThreshold: 0, | ||
dragstartTimeThreshold: 0 | ||
}, this.options) | ||
}); | ||
container.load(containerModule, true); | ||
}; | ||
_proto.destroy = function destroy(container) { | ||
container.remove(DragndropPluginOptions); | ||
container.unload(containerModule); | ||
}; | ||
return Plugin; | ||
@@ -637,0 +690,0 @@ }(); |
@@ -7,2 +7,28 @@ (function (global, factory) { | ||
function ownKeys(object, enumerableOnly) { | ||
var keys = Object.keys(object); | ||
if (Object.getOwnPropertySymbols) { | ||
var symbols = Object.getOwnPropertySymbols(object); | ||
enumerableOnly && (symbols = symbols.filter(function (sym) { | ||
return Object.getOwnPropertyDescriptor(object, sym).enumerable; | ||
})), keys.push.apply(keys, symbols); | ||
} | ||
return keys; | ||
} | ||
function _objectSpread2(target) { | ||
for (var i = 1; i < arguments.length; i++) { | ||
var source = null != arguments[i] ? arguments[i] : {}; | ||
i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { | ||
_defineProperty(target, key, source[key]); | ||
}) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { | ||
Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); | ||
}); | ||
} | ||
return target; | ||
} | ||
function _regeneratorRuntime() { | ||
@@ -389,18 +415,40 @@ /*! regenerator-runtime -- Copyright (c) 2014-present, Facebook, Inc. -- license (MIT): https://github.com/facebook/regenerator/blob/main/LICENSE */ | ||
function _extends() { | ||
_extends = Object.assign || function (target) { | ||
for (var i = 1; i < arguments.length; i++) { | ||
var source = arguments[i]; | ||
function _classCallCheck(instance, Constructor) { | ||
if (!(instance instanceof Constructor)) { | ||
throw new TypeError("Cannot call a class as a function"); | ||
} | ||
} | ||
for (var key in source) { | ||
if (Object.prototype.hasOwnProperty.call(source, key)) { | ||
target[key] = source[key]; | ||
} | ||
} | ||
} | ||
function _defineProperties(target, props) { | ||
for (var i = 0; i < props.length; i++) { | ||
var descriptor = props[i]; | ||
descriptor.enumerable = descriptor.enumerable || false; | ||
descriptor.configurable = true; | ||
if ("value" in descriptor) descriptor.writable = true; | ||
Object.defineProperty(target, descriptor.key, descriptor); | ||
} | ||
} | ||
return target; | ||
}; | ||
function _createClass(Constructor, protoProps, staticProps) { | ||
if (protoProps) _defineProperties(Constructor.prototype, protoProps); | ||
if (staticProps) _defineProperties(Constructor, staticProps); | ||
Object.defineProperty(Constructor, "prototype", { | ||
writable: false | ||
}); | ||
return Constructor; | ||
} | ||
return _extends.apply(this, arguments); | ||
function _defineProperty(obj, key, value) { | ||
if (key in obj) { | ||
Object.defineProperty(obj, key, { | ||
value: value, | ||
enumerable: true, | ||
configurable: true, | ||
writable: true | ||
}); | ||
} else { | ||
obj[key] = value; | ||
} | ||
return obj; | ||
} | ||
@@ -441,2 +489,4 @@ | ||
function DragndropPlugin() { | ||
_classCallCheck(this, DragndropPlugin); | ||
this.sceneGraphService = void 0; | ||
@@ -447,165 +497,166 @@ this.renderingContext = void 0; | ||
var _proto = DragndropPlugin.prototype; | ||
_createClass(DragndropPlugin, [{ | ||
key: "apply", | ||
value: function apply(renderingService) { | ||
var document = this.renderingContext.root.ownerDocument; // TODO: should we add an option like `draggable` to Canvas | ||
_proto.apply = function apply(renderingService) { | ||
var document = this.renderingContext.root.ownerDocument; // TODO: should we add an option like `draggable` to Canvas | ||
var canvas = document.defaultView; | ||
var _this$dragndropPlugin = this.dragndropPluginOptions, | ||
overlap = _this$dragndropPlugin.overlap, | ||
isDocumentDraggable = _this$dragndropPlugin.isDocumentDraggable, | ||
isDocumentDroppable = _this$dragndropPlugin.isDocumentDroppable, | ||
dragstartDistanceThreshold = _this$dragndropPlugin.dragstartDistanceThreshold, | ||
dragstartTimeThreshold = _this$dragndropPlugin.dragstartTimeThreshold; | ||
var canvas = document.defaultView; | ||
var _this$dragndropPlugin = this.dragndropPluginOptions, | ||
overlap = _this$dragndropPlugin.overlap, | ||
isDocumentDraggable = _this$dragndropPlugin.isDocumentDraggable, | ||
isDocumentDroppable = _this$dragndropPlugin.isDocumentDroppable, | ||
dragstartDistanceThreshold = _this$dragndropPlugin.dragstartDistanceThreshold, | ||
dragstartTimeThreshold = _this$dragndropPlugin.dragstartTimeThreshold; | ||
var handlePointerdown = function handlePointerdown(event) { | ||
var target = event.target; | ||
var isDocument = target === document; | ||
var handlePointerdown = function handlePointerdown(event) { | ||
var target = event.target; | ||
var isDocument = target === document; | ||
if (isDocument && isDocumentDraggable || target.getAttribute && target.getAttribute('draggable')) { | ||
// @ts-ignore | ||
var onMouseMove = /*#__PURE__*/function () { | ||
var _ref = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee(event) { | ||
var timeElapsed, distanceMoved, pointerEventsOldValue, point, elemBelow, droppableBelow; | ||
return _regeneratorRuntime().wrap(function _callee$(_context) { | ||
while (1) { | ||
switch (_context.prev = _context.next) { | ||
case 0: | ||
if (dragstartTriggered) { | ||
_context.next = 8; | ||
break; | ||
} | ||
if (isDocument && isDocumentDraggable || target.getAttribute && target.getAttribute('draggable')) { | ||
// @ts-ignore | ||
var onMouseMove = /*#__PURE__*/function () { | ||
var _ref = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee(event) { | ||
var timeElapsed, distanceMoved, pointerEventsOldValue, point, elemBelow, droppableBelow; | ||
return _regeneratorRuntime().wrap(function _callee$(_context) { | ||
while (1) { | ||
switch (_context.prev = _context.next) { | ||
case 0: | ||
if (dragstartTriggered) { | ||
_context.next = 8; | ||
break; | ||
} | ||
timeElapsed = event.timeStamp - dragstartTimeStamp; | ||
distanceMoved = Math.sqrt(Math.pow(event.canvasX - dragstartCanvasCoordinates[0], 2) + Math.pow(event.canvasY - dragstartCanvasCoordinates[1], 2)); // check thresholds | ||
timeElapsed = event.timeStamp - dragstartTimeStamp; | ||
distanceMoved = Math.sqrt(Math.pow(event.canvasX - dragstartCanvasCoordinates[0], 2) + Math.pow(event.canvasY - dragstartCanvasCoordinates[1], 2)); // check thresholds | ||
if (!(timeElapsed <= dragstartTimeThreshold || distanceMoved <= dragstartDistanceThreshold)) { | ||
_context.next = 5; | ||
break; | ||
} | ||
if (!(timeElapsed <= dragstartTimeThreshold || distanceMoved <= dragstartDistanceThreshold)) { | ||
_context.next = 5; | ||
break; | ||
} | ||
return _context.abrupt("return"); | ||
return _context.abrupt("return"); | ||
case 5: | ||
// @see https://developer.mozilla.org/zh-CN/docs/Web/API/Document/dragstart_event | ||
event.type = 'dragstart'; | ||
target.dispatchEvent(event); | ||
dragstartTriggered = true; | ||
case 5: | ||
// @see https://developer.mozilla.org/zh-CN/docs/Web/API/Document/dragstart_event | ||
event.type = 'dragstart'; | ||
target.dispatchEvent(event); | ||
dragstartTriggered = true; | ||
case 8: | ||
// @see https://developer.mozilla.org/zh-CN/docs/Web/API/Document/drag_event | ||
event.type = 'drag'; | ||
target.dispatchEvent(event); | ||
case 8: | ||
// @see https://developer.mozilla.org/zh-CN/docs/Web/API/Document/drag_event | ||
event.type = 'drag'; | ||
target.dispatchEvent(event); | ||
if (isDocument) { | ||
_context.next = 20; | ||
break; | ||
} | ||
if (isDocument) { | ||
_context.next = 20; | ||
break; | ||
} | ||
// prevent from picking the dragging element | ||
pointerEventsOldValue = target.style.pointerEvents; | ||
target.style.pointerEvents = 'none'; | ||
point = overlap === 'pointer' ? [event.canvasX, event.canvasY] : target.getBounds().center; | ||
_context.next = 16; | ||
return document.elementFromPoint(point[0], point[1]); | ||
// prevent from picking the dragging element | ||
pointerEventsOldValue = target.style.pointerEvents; | ||
target.style.pointerEvents = 'none'; | ||
point = overlap === 'pointer' ? [event.canvasX, event.canvasY] : target.getBounds().center; | ||
_context.next = 16; | ||
return document.elementFromPoint(point[0], point[1]); | ||
case 16: | ||
elemBelow = _context.sent; | ||
target.style.pointerEvents = pointerEventsOldValue; | ||
droppableBelow = (elemBelow === null || elemBelow === void 0 ? void 0 : elemBelow.closest('[droppable=true]')) || (isDocumentDroppable ? document : null); | ||
case 16: | ||
elemBelow = _context.sent; | ||
target.style.pointerEvents = pointerEventsOldValue; | ||
droppableBelow = (elemBelow === null || elemBelow === void 0 ? void 0 : elemBelow.closest('[droppable=true]')) || (isDocumentDroppable ? document : null); | ||
if (currentDroppable !== droppableBelow) { | ||
if (currentDroppable) { | ||
// null when we were not over a droppable before this event | ||
// @see https://developer.mozilla.org/zh-CN/docs/Web/API/Document/dragleave_event | ||
event.type = 'dragleave'; | ||
event.target = currentDroppable; | ||
currentDroppable.dispatchEvent(event); | ||
} | ||
if (currentDroppable !== droppableBelow) { | ||
if (currentDroppable) { | ||
// null when we were not over a droppable before this event | ||
// @see https://developer.mozilla.org/zh-CN/docs/Web/API/Document/dragleave_event | ||
event.type = 'dragleave'; | ||
event.target = currentDroppable; | ||
currentDroppable.dispatchEvent(event); | ||
} | ||
if (droppableBelow) { | ||
// @see https://developer.mozilla.org/zh-CN/docs/Web/API/Document/dragleave_event | ||
event.type = 'dragenter'; | ||
event.target = droppableBelow; | ||
droppableBelow.dispatchEvent(event); | ||
} | ||
if (droppableBelow) { | ||
// @see https://developer.mozilla.org/zh-CN/docs/Web/API/Document/dragleave_event | ||
event.type = 'dragenter'; | ||
event.target = droppableBelow; | ||
droppableBelow.dispatchEvent(event); | ||
} | ||
currentDroppable = droppableBelow; | ||
currentDroppable = droppableBelow; | ||
if (currentDroppable) { | ||
// null if we're not coming over a droppable now | ||
// @see https://developer.mozilla.org/zh-CN/docs/Web/API/Document/dragover_event | ||
event.type = 'dragover'; | ||
event.target = currentDroppable; | ||
currentDroppable.dispatchEvent(event); | ||
if (currentDroppable) { | ||
// null if we're not coming over a droppable now | ||
// @see https://developer.mozilla.org/zh-CN/docs/Web/API/Document/dragover_event | ||
event.type = 'dragover'; | ||
event.target = currentDroppable; | ||
currentDroppable.dispatchEvent(event); | ||
} | ||
} | ||
} | ||
case 20: | ||
case "end": | ||
return _context.stop(); | ||
case 20: | ||
case "end": | ||
return _context.stop(); | ||
} | ||
} | ||
} | ||
}, _callee); | ||
})); | ||
}, _callee); | ||
})); | ||
return function onMouseMove(_x) { | ||
return _ref.apply(this, arguments); | ||
}; | ||
}(); | ||
return function onMouseMove(_x) { | ||
return _ref.apply(this, arguments); | ||
}; | ||
}(); | ||
// delay triggering dragstart event | ||
var dragstartTriggered = false; | ||
var dragstartTimeStamp = event.timeStamp; | ||
var dragstartCanvasCoordinates = [event.canvasX, event.canvasY]; | ||
var currentDroppable = null; | ||
canvas.addEventListener('pointermove', onMouseMove); | ||
// delay triggering dragstart event | ||
var dragstartTriggered = false; | ||
var dragstartTimeStamp = event.timeStamp; | ||
var dragstartCanvasCoordinates = [event.canvasX, event.canvasY]; | ||
var currentDroppable = null; | ||
canvas.addEventListener('pointermove', onMouseMove); | ||
var stopDragging = function stopDragging() { | ||
if (dragstartTriggered) { | ||
// drop should fire before dragend | ||
// @see https://javascript.tutorialink.com/is-there-a-defined-ordering-between-dragend-and-drop-events/ | ||
if (currentDroppable) { | ||
// @see https://developer.mozilla.org/zh-CN/docs/Web/API/Document/drop_event | ||
event.type = 'drop'; | ||
event.target = currentDroppable; | ||
currentDroppable.dispatchEvent(event); | ||
} // @see https://developer.mozilla.org/zh-CN/docs/Web/API/Document/dragend_event | ||
var stopDragging = function stopDragging() { | ||
if (dragstartTriggered) { | ||
// drop should fire before dragend | ||
// @see https://javascript.tutorialink.com/is-there-a-defined-ordering-between-dragend-and-drop-events/ | ||
if (currentDroppable) { | ||
// @see https://developer.mozilla.org/zh-CN/docs/Web/API/Document/drop_event | ||
event.type = 'drop'; | ||
event.target = currentDroppable; | ||
currentDroppable.dispatchEvent(event); | ||
} // @see https://developer.mozilla.org/zh-CN/docs/Web/API/Document/dragend_event | ||
event.type = 'dragend'; | ||
target.dispatchEvent(event); | ||
dragstartTriggered = false; | ||
} | ||
event.type = 'dragend'; | ||
target.dispatchEvent(event); | ||
dragstartTriggered = false; | ||
} | ||
canvas.removeEventListener('pointermove', onMouseMove); | ||
}; | ||
canvas.removeEventListener('pointermove', onMouseMove); | ||
}; | ||
target.addEventListener('pointerup', stopDragging, { | ||
once: true | ||
}); | ||
target.addEventListener('pointerupoutside', stopDragging, { | ||
once: true | ||
}); | ||
} | ||
}; | ||
target.addEventListener('pointerup', stopDragging, { | ||
once: true | ||
}); | ||
target.addEventListener('pointerupoutside', stopDragging, { | ||
once: true | ||
}); | ||
} | ||
}; | ||
renderingService.hooks.init.tapPromise(DragndropPlugin_1.tag, /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee2() { | ||
return _regeneratorRuntime().wrap(function _callee2$(_context2) { | ||
while (1) { | ||
switch (_context2.prev = _context2.next) { | ||
case 0: | ||
canvas.addEventListener('pointerdown', handlePointerdown); | ||
renderingService.hooks.init.tapPromise(DragndropPlugin_1.tag, /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee2() { | ||
return _regeneratorRuntime().wrap(function _callee2$(_context2) { | ||
while (1) { | ||
switch (_context2.prev = _context2.next) { | ||
case 0: | ||
canvas.addEventListener('pointerdown', handlePointerdown); | ||
case 1: | ||
case "end": | ||
return _context2.stop(); | ||
case 1: | ||
case "end": | ||
return _context2.stop(); | ||
} | ||
} | ||
} | ||
}, _callee2); | ||
}))); | ||
renderingService.hooks.destroy.tap(DragndropPlugin_1.tag, function () { | ||
canvas.removeEventListener('pointerdown', handlePointerdown); | ||
}); | ||
}; | ||
}, _callee2); | ||
}))); | ||
renderingService.hooks.destroy.tap(DragndropPlugin_1.tag, function () { | ||
canvas.removeEventListener('pointerdown', handlePointerdown); | ||
}); | ||
} | ||
}]); | ||
@@ -629,7 +680,7 @@ return DragndropPlugin; | ||
var Plugin = /*#__PURE__*/function () { | ||
function Plugin(options) { | ||
if (options === void 0) { | ||
options = {}; | ||
} | ||
function Plugin() { | ||
var options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {}; | ||
_classCallCheck(this, Plugin); | ||
this.options = void 0; | ||
@@ -640,22 +691,24 @@ this.name = 'dragndrop'; | ||
var _proto = Plugin.prototype; | ||
_createClass(Plugin, [{ | ||
key: "init", | ||
value: function init(container) { | ||
container.register(DragndropPluginOptions, { | ||
useValue: _objectSpread2({ | ||
overlap: 'pointer', | ||
isDocumentDraggable: false, | ||
isDocumentDroppable: false, | ||
dragstartDistanceThreshold: 0, | ||
dragstartTimeThreshold: 0 | ||
}, this.options) | ||
}); | ||
container.load(containerModule, true); | ||
} | ||
}, { | ||
key: "destroy", | ||
value: function destroy(container) { | ||
container.remove(DragndropPluginOptions); | ||
container.unload(containerModule); | ||
} | ||
}]); | ||
_proto.init = function init(container) { | ||
container.register(DragndropPluginOptions, { | ||
useValue: _extends({ | ||
overlap: 'pointer', | ||
isDocumentDraggable: false, | ||
isDocumentDroppable: false, | ||
dragstartDistanceThreshold: 0, | ||
dragstartTimeThreshold: 0 | ||
}, this.options) | ||
}); | ||
container.load(containerModule, true); | ||
}; | ||
_proto.destroy = function destroy(container) { | ||
container.remove(DragndropPluginOptions); | ||
container.unload(containerModule); | ||
}; | ||
return Plugin; | ||
@@ -662,0 +715,0 @@ }(); |
@@ -1,3 +0,3 @@ | ||
!function(t,e){"object"==typeof exports&&"undefined"!=typeof module?e(exports,require("@antv/g")):"function"==typeof define&&define.amd?define(["exports","@antv/g"],e):e(((t="undefined"!=typeof globalThis?globalThis:t||self).G=t.G||{},t.G.Dragndrop={}),t.window.G)}(this,(function(t,e){"use strict";function r(){ | ||
!function(t,e){"object"==typeof exports&&"undefined"!=typeof module?e(exports,require("@antv/g")):"function"==typeof define&&define.amd?define(["exports","@antv/g"],e):e(((t="undefined"!=typeof globalThis?globalThis:t||self).G=t.G||{},t.G.Dragndrop={}),t.window.G)}(this,(function(t,e){"use strict";function r(t,e){var r=Object.keys(t);if(Object.getOwnPropertySymbols){var n=Object.getOwnPropertySymbols(t);e&&(n=n.filter((function(e){return Object.getOwnPropertyDescriptor(t,e).enumerable}))),r.push.apply(r,n)}return r}function n(t){for(var e=1;arguments.length>e;e++){var n=null!=arguments[e]?arguments[e]:{};e%2?r(Object(n),!0).forEach((function(e){f(t,e,n[e])})):Object.getOwnPropertyDescriptors?Object.defineProperties(t,Object.getOwnPropertyDescriptors(n)):r(Object(n)).forEach((function(e){Object.defineProperty(t,e,Object.getOwnPropertyDescriptor(n,e))}))}return t}function o(){ | ||
/*! regenerator-runtime -- Copyright (c) 2014-present, Facebook, Inc. -- license (MIT): https://github.com/facebook/regenerator/blob/main/LICENSE */ | ||
r=function(){return t};var t={},e=Object.prototype,n=e.hasOwnProperty,o="function"==typeof Symbol?Symbol:{},i=o.iterator||"@@iterator",a=o.asyncIterator||"@@asyncIterator",c=o.toStringTag||"@@toStringTag";function u(t,e,r){return Object.defineProperty(t,e,{value:r,enumerable:!0,configurable:!0,writable:!0}),t[e]}try{u({},"")}catch(t){u=function(t,e,r){return t[e]=r}}function s(t,e,r,n){var o=Object.create((e&&e.prototype instanceof l?e:l).prototype),i=new O(n||[]);return o._invoke=function(t,e,r){var n="suspendedStart";return function(o,i){if("executing"===n)throw new Error("Generator is already running");if("completed"===n){if("throw"===o)throw i;return P()}for(r.method=o,r.arg=i;;){var a=r.delegate;if(a){var c=x(a,r);if(c){if(c===p)continue;return c}}if("next"===r.method)r.sent=r._sent=r.arg;else if("throw"===r.method){if("suspendedStart"===n)throw n="completed",r.arg;r.dispatchException(r.arg)}else"return"===r.method&&r.abrupt("return",r.arg);n="executing";var u=f(t,e,r);if("normal"===u.type){if(n=r.done?"completed":"suspendedYield",u.arg===p)continue;return{value:u.arg,done:r.done}}"throw"===u.type&&(n="completed",r.method="throw",r.arg=u.arg)}}}(t,r,i),o}function f(t,e,r){try{return{type:"normal",arg:t.call(e,r)}}catch(t){return{type:"throw",arg:t}}}t.wrap=s;var p={};function l(){}function h(){}function d(){}var v={};u(v,i,(function(){return this}));var y=Object.getPrototypeOf,g=y&&y(y(j([])));g&&g!==e&&n.call(g,i)&&(v=g);var m=d.prototype=l.prototype=Object.create(v);function w(t){["next","throw","return"].forEach((function(e){u(t,e,(function(t){return this._invoke(e,t)}))}))}function b(t,e){function r(o,i,a,c){var u=f(t[o],t,i);if("throw"!==u.type){var s=u.arg,p=s.value;return p&&"object"==typeof p&&n.call(p,"__await")?e.resolve(p.__await).then((function(t){r("next",t,a,c)}),(function(t){r("throw",t,a,c)})):e.resolve(p).then((function(t){s.value=t,a(s)}),(function(t){return r("throw",t,a,c)}))}c(u.arg)}var o;this._invoke=function(t,n){function i(){return new e((function(e,o){r(t,n,e,o)}))}return o=o?o.then(i,i):i()}}function x(t,e){var r=t.iterator[e.method];if(void 0===r){if(e.delegate=null,"throw"===e.method){if(t.iterator.return&&(e.method="return",e.arg=void 0,x(t,e),"throw"===e.method))return p;e.method="throw",e.arg=new TypeError("The iterator does not provide a 'throw' method")}return p}var n=f(r,t.iterator,e.arg);if("throw"===n.type)return e.method="throw",e.arg=n.arg,e.delegate=null,p;var o=n.arg;return o?o.done?(e[t.resultName]=o.value,e.next=t.nextLoc,"return"!==e.method&&(e.method="next",e.arg=void 0),e.delegate=null,p):o:(e.method="throw",e.arg=new TypeError("iterator result is not an object"),e.delegate=null,p)}function E(t){var e={tryLoc:t[0]};1 in t&&(e.catchLoc=t[1]),2 in t&&(e.finallyLoc=t[2],e.afterLoc=t[3]),this.tryEntries.push(e)}function L(t){var e=t.completion||{};e.type="normal",delete e.arg,t.completion=e}function O(t){this.tryEntries=[{tryLoc:"root"}],t.forEach(E,this),this.reset(!0)}function j(t){if(t){var e=t[i];if(e)return e.call(t);if("function"==typeof t.next)return t;if(!isNaN(t.length)){var r=-1,o=function e(){for(;++r<t.length;)if(n.call(t,r))return e.value=t[r],e.done=!1,e;return e.value=void 0,e.done=!0,e};return o.next=o}}return{next:P}}function P(){return{value:void 0,done:!0}}return h.prototype=d,u(m,"constructor",d),u(d,"constructor",h),h.displayName=u(d,c,"GeneratorFunction"),t.isGeneratorFunction=function(t){var e="function"==typeof t&&t.constructor;return!!e&&(e===h||"GeneratorFunction"===(e.displayName||e.name))},t.mark=function(t){return Object.setPrototypeOf?Object.setPrototypeOf(t,d):(t.__proto__=d,u(t,c,"GeneratorFunction")),t.prototype=Object.create(m),t},t.awrap=function(t){return{__await:t}},w(b.prototype),u(b.prototype,a,(function(){return this})),t.AsyncIterator=b,t.async=function(e,r,n,o,i){void 0===i&&(i=Promise);var a=new b(s(e,r,n,o),i);return t.isGeneratorFunction(r)?a:a.next().then((function(t){return t.done?t.value:a.next()}))},w(m),u(m,c,"Generator"),u(m,i,(function(){return this})),u(m,"toString",(function(){return"[object Generator]"})),t.keys=function(t){var e=[];for(var r in t)e.push(r);return e.reverse(),function r(){for(;e.length;){var n=e.pop();if(n in t)return r.value=n,r.done=!1,r}return r.done=!0,r}},t.values=j,O.prototype={constructor:O,reset:function(t){if(this.prev=0,this.next=0,this.sent=this._sent=void 0,this.done=!1,this.delegate=null,this.method="next",this.arg=void 0,this.tryEntries.forEach(L),!t)for(var e in this)"t"===e.charAt(0)&&n.call(this,e)&&!isNaN(+e.slice(1))&&(this[e]=void 0)},stop:function(){this.done=!0;var t=this.tryEntries[0].completion;if("throw"===t.type)throw t.arg;return this.rval},dispatchException:function(t){if(this.done)throw t;var e=this;function r(r,n){return a.type="throw",a.arg=t,e.next=r,n&&(e.method="next",e.arg=void 0),!!n}for(var o=this.tryEntries.length-1;o>=0;--o){var i=this.tryEntries[o],a=i.completion;if("root"===i.tryLoc)return r("end");if(this.prev>=i.tryLoc){var c=n.call(i,"catchLoc"),u=n.call(i,"finallyLoc");if(c&&u){if(i.catchLoc>this.prev)return r(i.catchLoc,!0);if(i.finallyLoc>this.prev)return r(i.finallyLoc)}else if(c){if(i.catchLoc>this.prev)return r(i.catchLoc,!0)}else{if(!u)throw new Error("try statement without catch or finally");if(i.finallyLoc>this.prev)return r(i.finallyLoc)}}}},abrupt:function(t,e){for(var r=this.tryEntries.length-1;r>=0;--r){var o=this.tryEntries[r];if(this.prev>=o.tryLoc&&n.call(o,"finallyLoc")&&o.finallyLoc>this.prev){var i=o;break}}i&&("break"===t||"continue"===t)&&e>=i.tryLoc&&i.finallyLoc>=e&&(i=null);var a=i?i.completion:{};return a.type=t,a.arg=e,i?(this.method="next",this.next=i.finallyLoc,p):this.complete(a)},complete:function(t,e){if("throw"===t.type)throw t.arg;return"break"===t.type||"continue"===t.type?this.next=t.arg:"return"===t.type?(this.rval=this.arg=t.arg,this.method="return",this.next="end"):"normal"===t.type&&e&&(this.next=e),p},finish:function(t){for(var e=this.tryEntries.length-1;e>=0;--e){var r=this.tryEntries[e];if(r.finallyLoc===t)return this.complete(r.completion,r.afterLoc),L(r),p}},catch:function(t){for(var e=this.tryEntries.length-1;e>=0;--e){var r=this.tryEntries[e];if(r.tryLoc===t){var n=r.completion;if("throw"===n.type){var o=n.arg;L(r)}return o}}throw new Error("illegal catch attempt")},delegateYield:function(t,e,r){return this.delegate={iterator:j(t),resultName:e,nextLoc:r},"next"===this.method&&(this.arg=void 0),p}},t}function n(t,e,r,n,o,i,a){try{var c=t[i](a),u=c.value}catch(t){return void r(t)}c.done?e(u):Promise.resolve(u).then(n,o)}function o(t){return function(){var e=this,r=arguments;return new Promise((function(o,i){var a=t.apply(e,r);function c(t){n(a,o,i,c,u,"next",t)}function u(t){n(a,o,i,c,u,"throw",t)}c(void 0)}))}}function i(){return i=Object.assign||function(t){for(var e=1;arguments.length>e;e++){var r=arguments[e];for(var n in r)Object.prototype.hasOwnProperty.call(r,n)&&(t[n]=r[n])}return t},i.apply(this,arguments)}function a(t,e,r,n){var o,i=arguments.length,a=3>i?e:null===n?n=Object.getOwnPropertyDescriptor(e,r):n;if("object"==typeof Reflect&&"function"==typeof Reflect.decorate)a=Reflect.decorate(t,e,r,n);else for(var c=t.length-1;c>=0;c--)(o=t[c])&&(a=(3>i?o(a):i>3?o(e,r,a):o(e,r))||a);return i>3&&a&&Object.defineProperty(e,r,a),a}function c(t,e){if("object"==typeof Reflect&&"function"==typeof Reflect.metadata)return Reflect.metadata(t,e)}var u,s,f=e.Syringe.defineToken("DragndropPluginOptions"),p=(u=function(){function t(){this.sceneGraphService=void 0,this.renderingContext=void 0,this.dragndropPluginOptions=void 0}return t.prototype.apply=function(t){var e=this.renderingContext.root.ownerDocument,n=e.defaultView,i=this.dragndropPluginOptions,a=i.overlap,c=i.isDocumentDraggable,u=i.isDocumentDroppable,f=i.dragstartDistanceThreshold,p=i.dragstartTimeThreshold,l=function(t){var i=t.target,s=i===e;if(s&&c||i.getAttribute&&i.getAttribute("draggable")){var l=function(){var t=o(r().mark((function t(n){var o,c,l,g,m,w;return r().wrap((function(t){for(;;)switch(t.prev=t.next){case 0:if(h){t.next=8;break}if(o=n.timeStamp-d,c=Math.sqrt(Math.pow(n.canvasX-v[0],2)+Math.pow(n.canvasY-v[1],2)),o>p&&c>f){t.next=5;break}return t.abrupt("return");case 5:n.type="dragstart",i.dispatchEvent(n),h=!0;case 8:if(n.type="drag",i.dispatchEvent(n),s){t.next=20;break}return l=i.style.pointerEvents,i.style.pointerEvents="none",g="pointer"===a?[n.canvasX,n.canvasY]:i.getBounds().center,t.next=16,e.elementFromPoint(g[0],g[1]);case 16:m=t.sent,i.style.pointerEvents=l,w=(null==m?void 0:m.closest("[droppable=true]"))||(u?e:null),y!==w&&(y&&(n.type="dragleave",n.target=y,y.dispatchEvent(n)),w&&(n.type="dragenter",n.target=w,w.dispatchEvent(n)),(y=w)&&(n.type="dragover",n.target=y,y.dispatchEvent(n)));case 20:case"end":return t.stop()}}),t)})));return function(e){return t.apply(this,arguments)}}(),h=!1,d=t.timeStamp,v=[t.canvasX,t.canvasY],y=null;n.addEventListener("pointermove",l);var g=function(){h&&(y&&(t.type="drop",t.target=y,y.dispatchEvent(t)),t.type="dragend",i.dispatchEvent(t),h=!1),n.removeEventListener("pointermove",l)};i.addEventListener("pointerup",g,{once:!0}),i.addEventListener("pointerupoutside",g,{once:!0})}};t.hooks.init.tapPromise(s.tag,o(r().mark((function t(){return r().wrap((function(t){for(;;)switch(t.prev=t.next){case 0:n.addEventListener("pointerdown",l);case 1:case"end":return t.stop()}}),t)})))),t.hooks.destroy.tap(s.tag,(function(){n.removeEventListener("pointerdown",l)}))},t}(),u.tag="Dragndrop",s=u);a([e.inject(e.SceneGraphService),c("design:type",Object)],p.prototype,"sceneGraphService",void 0),a([e.inject(e.RenderingContext),c("design:type",Object)],p.prototype,"renderingContext",void 0),a([e.inject(f),c("design:type",Object)],p.prototype,"dragndropPluginOptions",void 0),p=s=a([e.singleton({contrib:e.RenderingPluginContribution})],p);var l=e.Module((function(t){t(p)}));t.Plugin=function(){function t(t){void 0===t&&(t={}),this.options=void 0,this.name="dragndrop",this.options=t}var e=t.prototype;return e.init=function(t){t.register(f,{useValue:i({overlap:"pointer",isDocumentDraggable:!1,isDocumentDroppable:!1,dragstartDistanceThreshold:0,dragstartTimeThreshold:0},this.options)}),t.load(l,!0)},e.destroy=function(t){t.remove(f),t.unload(l)},t}(),Object.defineProperty(t,"__esModule",{value:!0})})); | ||
o=function(){return t};var t={},e=Object.prototype,r=e.hasOwnProperty,n="function"==typeof Symbol?Symbol:{},i=n.iterator||"@@iterator",a=n.asyncIterator||"@@asyncIterator",c=n.toStringTag||"@@toStringTag";function u(t,e,r){return Object.defineProperty(t,e,{value:r,enumerable:!0,configurable:!0,writable:!0}),t[e]}try{u({},"")}catch(t){u=function(t,e,r){return t[e]=r}}function s(t,e,r,n){var o=Object.create((e&&e.prototype instanceof p?e:p).prototype),i=new j(n||[]);return o._invoke=function(t,e,r){var n="suspendedStart";return function(o,i){if("executing"===n)throw Error("Generator is already running");if("completed"===n){if("throw"===o)throw i;return P()}for(r.method=o,r.arg=i;;){var a=r.delegate;if(a){var c=O(a,r);if(c){if(c===l)continue;return c}}if("next"===r.method)r.sent=r._sent=r.arg;else if("throw"===r.method){if("suspendedStart"===n)throw n="completed",r.arg;r.dispatchException(r.arg)}else"return"===r.method&&r.abrupt("return",r.arg);n="executing";var u=f(t,e,r);if("normal"===u.type){if(n=r.done?"completed":"suspendedYield",u.arg===l)continue;return{value:u.arg,done:r.done}}"throw"===u.type&&(n="completed",r.method="throw",r.arg=u.arg)}}}(t,r,i),o}function f(t,e,r){try{return{type:"normal",arg:t.call(e,r)}}catch(t){return{type:"throw",arg:t}}}t.wrap=s;var l={};function p(){}function h(){}function d(){}var v={};u(v,i,(function(){return this}));var y=Object.getPrototypeOf,g=y&&y(y(L([])));g&&g!==e&&r.call(g,i)&&(v=g);var m=d.prototype=p.prototype=Object.create(v);function b(t){["next","throw","return"].forEach((function(e){u(t,e,(function(t){return this._invoke(e,t)}))}))}function w(t,e){function n(o,i,a,c){var u=f(t[o],t,i);if("throw"!==u.type){var s=u.arg,l=s.value;return l&&"object"==typeof l&&r.call(l,"__await")?e.resolve(l.__await).then((function(t){n("next",t,a,c)}),(function(t){n("throw",t,a,c)})):e.resolve(l).then((function(t){s.value=t,a(s)}),(function(t){return n("throw",t,a,c)}))}c(u.arg)}var o;this._invoke=function(t,r){function i(){return new e((function(e,o){n(t,r,e,o)}))}return o=o?o.then(i,i):i()}}function O(t,e){var r=t.iterator[e.method];if(void 0===r){if(e.delegate=null,"throw"===e.method){if(t.iterator.return&&(e.method="return",e.arg=void 0,O(t,e),"throw"===e.method))return l;e.method="throw",e.arg=new TypeError("The iterator does not provide a 'throw' method")}return l}var n=f(r,t.iterator,e.arg);if("throw"===n.type)return e.method="throw",e.arg=n.arg,e.delegate=null,l;var o=n.arg;return o?o.done?(e[t.resultName]=o.value,e.next=t.nextLoc,"return"!==e.method&&(e.method="next",e.arg=void 0),e.delegate=null,l):o:(e.method="throw",e.arg=new TypeError("iterator result is not an object"),e.delegate=null,l)}function E(t){var e={tryLoc:t[0]};1 in t&&(e.catchLoc=t[1]),2 in t&&(e.finallyLoc=t[2],e.afterLoc=t[3]),this.tryEntries.push(e)}function x(t){var e=t.completion||{};e.type="normal",delete e.arg,t.completion=e}function j(t){this.tryEntries=[{tryLoc:"root"}],t.forEach(E,this),this.reset(!0)}function L(t){if(t){var e=t[i];if(e)return e.call(t);if("function"==typeof t.next)return t;if(!isNaN(t.length)){var n=-1,o=function e(){for(;++n<t.length;)if(r.call(t,n))return e.value=t[n],e.done=!1,e;return e.value=void 0,e.done=!0,e};return o.next=o}}return{next:P}}function P(){return{value:void 0,done:!0}}return h.prototype=d,u(m,"constructor",d),u(d,"constructor",h),h.displayName=u(d,c,"GeneratorFunction"),t.isGeneratorFunction=function(t){var e="function"==typeof t&&t.constructor;return!!e&&(e===h||"GeneratorFunction"===(e.displayName||e.name))},t.mark=function(t){return Object.setPrototypeOf?Object.setPrototypeOf(t,d):(t.__proto__=d,u(t,c,"GeneratorFunction")),t.prototype=Object.create(m),t},t.awrap=function(t){return{__await:t}},b(w.prototype),u(w.prototype,a,(function(){return this})),t.AsyncIterator=w,t.async=function(e,r,n,o,i){void 0===i&&(i=Promise);var a=new w(s(e,r,n,o),i);return t.isGeneratorFunction(r)?a:a.next().then((function(t){return t.done?t.value:a.next()}))},b(m),u(m,c,"Generator"),u(m,i,(function(){return this})),u(m,"toString",(function(){return"[object Generator]"})),t.keys=function(t){var e=[];for(var r in t)e.push(r);return e.reverse(),function r(){for(;e.length;){var n=e.pop();if(n in t)return r.value=n,r.done=!1,r}return r.done=!0,r}},t.values=L,j.prototype={constructor:j,reset:function(t){if(this.prev=0,this.next=0,this.sent=this._sent=void 0,this.done=!1,this.delegate=null,this.method="next",this.arg=void 0,this.tryEntries.forEach(x),!t)for(var e in this)"t"===e.charAt(0)&&r.call(this,e)&&!isNaN(+e.slice(1))&&(this[e]=void 0)},stop:function(){this.done=!0;var t=this.tryEntries[0].completion;if("throw"===t.type)throw t.arg;return this.rval},dispatchException:function(t){if(this.done)throw t;var e=this;function n(r,n){return a.type="throw",a.arg=t,e.next=r,n&&(e.method="next",e.arg=void 0),!!n}for(var o=this.tryEntries.length-1;o>=0;--o){var i=this.tryEntries[o],a=i.completion;if("root"===i.tryLoc)return n("end");if(this.prev>=i.tryLoc){var c=r.call(i,"catchLoc"),u=r.call(i,"finallyLoc");if(c&&u){if(i.catchLoc>this.prev)return n(i.catchLoc,!0);if(i.finallyLoc>this.prev)return n(i.finallyLoc)}else if(c){if(i.catchLoc>this.prev)return n(i.catchLoc,!0)}else{if(!u)throw Error("try statement without catch or finally");if(i.finallyLoc>this.prev)return n(i.finallyLoc)}}}},abrupt:function(t,e){for(var n=this.tryEntries.length-1;n>=0;--n){var o=this.tryEntries[n];if(this.prev>=o.tryLoc&&r.call(o,"finallyLoc")&&o.finallyLoc>this.prev){var i=o;break}}i&&("break"===t||"continue"===t)&&e>=i.tryLoc&&i.finallyLoc>=e&&(i=null);var a=i?i.completion:{};return a.type=t,a.arg=e,i?(this.method="next",this.next=i.finallyLoc,l):this.complete(a)},complete:function(t,e){if("throw"===t.type)throw t.arg;return"break"===t.type||"continue"===t.type?this.next=t.arg:"return"===t.type?(this.rval=this.arg=t.arg,this.method="return",this.next="end"):"normal"===t.type&&e&&(this.next=e),l},finish:function(t){for(var e=this.tryEntries.length-1;e>=0;--e){var r=this.tryEntries[e];if(r.finallyLoc===t)return this.complete(r.completion,r.afterLoc),x(r),l}},catch:function(t){for(var e=this.tryEntries.length-1;e>=0;--e){var r=this.tryEntries[e];if(r.tryLoc===t){var n=r.completion;if("throw"===n.type){var o=n.arg;x(r)}return o}}throw Error("illegal catch attempt")},delegateYield:function(t,e,r){return this.delegate={iterator:L(t),resultName:e,nextLoc:r},"next"===this.method&&(this.arg=void 0),l}},t}function i(t,e,r,n,o,i,a){try{var c=t[i](a),u=c.value}catch(t){return void r(t)}c.done?e(u):Promise.resolve(u).then(n,o)}function a(t){return function(){var e=this,r=arguments;return new Promise((function(n,o){var a=t.apply(e,r);function c(t){i(a,n,o,c,u,"next",t)}function u(t){i(a,n,o,c,u,"throw",t)}c(void 0)}))}}function c(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}function u(t,e){for(var r=0;e.length>r;r++){var n=e[r];n.enumerable=n.enumerable||!1,n.configurable=!0,"value"in n&&(n.writable=!0),Object.defineProperty(t,n.key,n)}}function s(t,e,r){return e&&u(t.prototype,e),r&&u(t,r),Object.defineProperty(t,"prototype",{writable:!1}),t}function f(t,e,r){return e in t?Object.defineProperty(t,e,{value:r,enumerable:!0,configurable:!0,writable:!0}):t[e]=r,t}function l(t,e,r,n){var o,i=arguments.length,a=3>i?e:null===n?n=Object.getOwnPropertyDescriptor(e,r):n;if("object"==typeof Reflect&&"function"==typeof Reflect.decorate)a=Reflect.decorate(t,e,r,n);else for(var c=t.length-1;c>=0;c--)(o=t[c])&&(a=(3>i?o(a):i>3?o(e,r,a):o(e,r))||a);return i>3&&a&&Object.defineProperty(e,r,a),a}function p(t,e){if("object"==typeof Reflect&&"function"==typeof Reflect.metadata)return Reflect.metadata(t,e)}var h,d,v=e.Syringe.defineToken("DragndropPluginOptions"),y=(h=function(){function t(){c(this,t),this.sceneGraphService=void 0,this.renderingContext=void 0,this.dragndropPluginOptions=void 0}return s(t,[{key:"apply",value:function(t){var e=this.renderingContext.root.ownerDocument,r=e.defaultView,n=this.dragndropPluginOptions,i=n.overlap,c=n.isDocumentDraggable,u=n.isDocumentDroppable,s=n.dragstartDistanceThreshold,f=n.dragstartTimeThreshold,l=function(t){var n=t.target,l=n===e;if(l&&c||n.getAttribute&&n.getAttribute("draggable")){var p=function(){var t=a(o().mark((function t(r){var a,c,p,g,m,b;return o().wrap((function(t){for(;;)switch(t.prev=t.next){case 0:if(h){t.next=8;break}if(a=r.timeStamp-d,c=Math.sqrt(Math.pow(r.canvasX-v[0],2)+Math.pow(r.canvasY-v[1],2)),a>f&&c>s){t.next=5;break}return t.abrupt("return");case 5:r.type="dragstart",n.dispatchEvent(r),h=!0;case 8:if(r.type="drag",n.dispatchEvent(r),l){t.next=20;break}return p=n.style.pointerEvents,n.style.pointerEvents="none",g="pointer"===i?[r.canvasX,r.canvasY]:n.getBounds().center,t.next=16,e.elementFromPoint(g[0],g[1]);case 16:m=t.sent,n.style.pointerEvents=p,b=(null==m?void 0:m.closest("[droppable=true]"))||(u?e:null),y!==b&&(y&&(r.type="dragleave",r.target=y,y.dispatchEvent(r)),b&&(r.type="dragenter",r.target=b,b.dispatchEvent(r)),(y=b)&&(r.type="dragover",r.target=y,y.dispatchEvent(r)));case 20:case"end":return t.stop()}}),t)})));return function(e){return t.apply(this,arguments)}}(),h=!1,d=t.timeStamp,v=[t.canvasX,t.canvasY],y=null;r.addEventListener("pointermove",p);var g=function(){h&&(y&&(t.type="drop",t.target=y,y.dispatchEvent(t)),t.type="dragend",n.dispatchEvent(t),h=!1),r.removeEventListener("pointermove",p)};n.addEventListener("pointerup",g,{once:!0}),n.addEventListener("pointerupoutside",g,{once:!0})}};t.hooks.init.tapPromise(d.tag,a(o().mark((function t(){return o().wrap((function(t){for(;;)switch(t.prev=t.next){case 0:r.addEventListener("pointerdown",l);case 1:case"end":return t.stop()}}),t)})))),t.hooks.destroy.tap(d.tag,(function(){r.removeEventListener("pointerdown",l)}))}}]),t}(),h.tag="Dragndrop",d=h);l([e.inject(e.SceneGraphService),p("design:type",Object)],y.prototype,"sceneGraphService",void 0),l([e.inject(e.RenderingContext),p("design:type",Object)],y.prototype,"renderingContext",void 0),l([e.inject(v),p("design:type",Object)],y.prototype,"dragndropPluginOptions",void 0),y=d=l([e.singleton({contrib:e.RenderingPluginContribution})],y);var g=e.Module((function(t){t(y)})),m=function(){function t(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};c(this,t),this.options=void 0,this.name="dragndrop",this.options=e}return s(t,[{key:"init",value:function(t){t.register(v,{useValue:n({overlap:"pointer",isDocumentDraggable:!1,isDocumentDroppable:!1,dragstartDistanceThreshold:0,dragstartTimeThreshold:0},this.options)}),t.load(g,!0)}},{key:"destroy",value:function(t){t.remove(v),t.unload(g)}}]),t}();t.Plugin=m,Object.defineProperty(t,"__esModule",{value:!0})})); |
{ | ||
"name": "@antv/g-plugin-dragndrop", | ||
"version": "1.1.0", | ||
"version": "1.1.1", | ||
"description": "A G plugin for Drag n Drop implemented with PointerEvents", | ||
@@ -41,3 +41,3 @@ "keywords": [ | ||
}, | ||
"gitHead": "bf0d57ef10d56f48d6258906281b9edb34bffb48" | ||
"gitHead": "90eceace1d9a96e36b20926e853b958c03cf3a67" | ||
} |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
97493
1846