Socket
Socket
Sign inDemoInstall

@antv/g-plugin-dragndrop

Package Overview
Dependencies
10
Maintainers
64
Versions
129
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

Comparing version 1.6.46 to 1.6.47

480

dist/index.esm.js
import { AbstractRendererPlugin } from '@antv/g-lite';
import { distanceSquareRoot } from '@antv/util';
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() {

@@ -335,21 +356,60 @@ _regeneratorRuntime = function () {

}
function _extends() {
_extends = Object.assign ? Object.assign.bind() : function (target) {
for (var i = 1; i < arguments.length; i++) {
var source = arguments[i];
for (var key in source) {
if (Object.prototype.hasOwnProperty.call(source, key)) {
target[key] = source[key];
}
}
function _classCallCheck(instance, Constructor) {
if (!(instance instanceof Constructor)) {
throw new TypeError("Cannot call a class as a function");
}
}
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, _toPropertyKey(descriptor.key), descriptor);
}
}
function _createClass(Constructor, protoProps, staticProps) {
if (protoProps) _defineProperties(Constructor.prototype, protoProps);
if (staticProps) _defineProperties(Constructor, staticProps);
Object.defineProperty(Constructor, "prototype", {
writable: false
});
return Constructor;
}
function _defineProperty(obj, key, value) {
key = _toPropertyKey(key);
if (key in obj) {
Object.defineProperty(obj, key, {
value: value,
enumerable: true,
configurable: true,
writable: true
});
} else {
obj[key] = value;
}
return obj;
}
function _inherits(subClass, superClass) {
if (typeof superClass !== "function" && superClass !== null) {
throw new TypeError("Super expression must either be null or a function");
}
subClass.prototype = Object.create(superClass && superClass.prototype, {
constructor: {
value: subClass,
writable: true,
configurable: true
}
return target;
});
Object.defineProperty(subClass, "prototype", {
writable: false
});
if (superClass) _setPrototypeOf(subClass, superClass);
}
function _getPrototypeOf(o) {
_getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf.bind() : function _getPrototypeOf(o) {
return o.__proto__ || Object.getPrototypeOf(o);
};
return _extends.apply(this, arguments);
return _getPrototypeOf(o);
}
function _inheritsLoose(subClass, superClass) {
subClass.prototype = Object.create(superClass.prototype);
subClass.prototype.constructor = subClass;
_setPrototypeOf(subClass, superClass);
}
function _setPrototypeOf(o, p) {

@@ -362,155 +422,211 @@ _setPrototypeOf = Object.setPrototypeOf ? Object.setPrototypeOf.bind() : function _setPrototypeOf(o, p) {

}
function _isNativeReflectConstruct() {
if (typeof Reflect === "undefined" || !Reflect.construct) return false;
if (Reflect.construct.sham) return false;
if (typeof Proxy === "function") return true;
try {
Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {}));
return true;
} catch (e) {
return false;
}
}
function _assertThisInitialized(self) {
if (self === void 0) {
throw new ReferenceError("this hasn't been initialised - super() hasn't been called");
}
return self;
}
function _possibleConstructorReturn(self, call) {
if (call && (typeof call === "object" || typeof call === "function")) {
return call;
} else if (call !== void 0) {
throw new TypeError("Derived constructors may only return object or undefined");
}
return _assertThisInitialized(self);
}
function _createSuper(Derived) {
var hasNativeReflectConstruct = _isNativeReflectConstruct();
return function _createSuperInternal() {
var Super = _getPrototypeOf(Derived),
result;
if (hasNativeReflectConstruct) {
var NewTarget = _getPrototypeOf(this).constructor;
result = Reflect.construct(Super, arguments, NewTarget);
} else {
result = Super.apply(this, arguments);
}
return _possibleConstructorReturn(this, result);
};
}
function _toPrimitive(input, hint) {
if (typeof input !== "object" || input === null) return input;
var prim = input[Symbol.toPrimitive];
if (prim !== undefined) {
var res = prim.call(input, hint || "default");
if (typeof res !== "object") return res;
throw new TypeError("@@toPrimitive must return a primitive value.");
}
return (hint === "string" ? String : Number)(input);
}
function _toPropertyKey(arg) {
var key = _toPrimitive(arg, "string");
return typeof key === "symbol" ? key : String(key);
}
var DragndropPlugin = /*#__PURE__*/function () {
function DragndropPlugin(dragndropPluginOptions) {
_classCallCheck(this, DragndropPlugin);
this.dragndropPluginOptions = void 0;
this.dragndropPluginOptions = dragndropPluginOptions;
}
var _proto = DragndropPlugin.prototype;
_proto.apply = function apply(context) {
var _this = this;
var renderingService = context.renderingService,
renderingContext = context.renderingContext;
var document = renderingContext.root.ownerDocument;
// TODO: should we add an option like `draggable` to Canvas
var canvas = document.defaultView;
var handlePointerdown = function handlePointerdown(event) {
var target = event.target;
var isDocument = target === document;
var draggableEventTarget = isDocument && _this.dragndropPluginOptions.isDocumentDraggable ? document : target.closest && target.closest('[draggable=true]');
// `draggable` may be set on ancestor nodes:
// @see https://github.com/antvis/G/issues/1088
if (draggableEventTarget) {
// delay triggering dragstart event
var dragstartTriggered = false;
var dragstartTimeStamp = event.timeStamp;
var dragstartClientCoordinates = [event.clientX, event.clientY];
var currentDroppable = null;
var lastDragClientCoordinates = [event.clientX, event.clientY];
// @ts-ignore
// eslint-disable-next-line no-inner-declarations
var handlePointermove = /*#__PURE__*/function () {
var _ref = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee(event) {
var timeElapsed, distanceMoved, point, elementsBelow, elementBelow, 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 = distanceSquareRoot([event.clientX, event.clientY], dragstartClientCoordinates); // check thresholds
if (!(timeElapsed <= _this.dragndropPluginOptions.dragstartTimeThreshold || distanceMoved <= _this.dragndropPluginOptions.dragstartDistanceThreshold)) {
_context.next = 5;
break;
}
return _context.abrupt("return");
case 5:
// @see https://developer.mozilla.org/zh-CN/docs/Web/API/Document/dragstart_event
event.type = 'dragstart';
draggableEventTarget.dispatchEvent(event);
dragstartTriggered = true;
case 8:
// @see https://developer.mozilla.org/zh-CN/docs/Web/API/Document/drag_event
event.type = 'drag';
// @ts-ignore
event.dx = event.clientX - lastDragClientCoordinates[0];
// @ts-ignore
event.dy = event.clientY - lastDragClientCoordinates[1];
draggableEventTarget.dispatchEvent(event);
lastDragClientCoordinates = [event.clientX, event.clientY];
if (isDocument) {
_context.next = 21;
break;
}
point = _this.dragndropPluginOptions.overlap === 'pointer' ? [event.canvasX, event.canvasY] : target.getBounds().center;
_context.next = 17;
return document.elementsFromPoint(point[0], point[1]);
case 17:
elementsBelow = _context.sent;
// prevent from picking the dragging element
elementBelow = elementsBelow[elementsBelow.indexOf(target) + 1];
droppableBelow = (elementBelow === null || elementBelow === void 0 ? void 0 : elementBelow.closest('[droppable=true]')) || (_this.dragndropPluginOptions.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);
_createClass(DragndropPlugin, [{
key: "apply",
value: function apply(context) {
var _this = this;
var renderingService = context.renderingService,
renderingContext = context.renderingContext;
var document = renderingContext.root.ownerDocument;
// TODO: should we add an option like `draggable` to Canvas
var canvas = document.defaultView;
var handlePointerdown = function handlePointerdown(event) {
var target = event.target;
var isDocument = target === document;
var draggableEventTarget = isDocument && _this.dragndropPluginOptions.isDocumentDraggable ? document : target.closest && target.closest('[draggable=true]');
// `draggable` may be set on ancestor nodes:
// @see https://github.com/antvis/G/issues/1088
if (draggableEventTarget) {
// delay triggering dragstart event
var dragstartTriggered = false;
var dragstartTimeStamp = event.timeStamp;
var dragstartClientCoordinates = [event.clientX, event.clientY];
var currentDroppable = null;
var lastDragClientCoordinates = [event.clientX, event.clientY];
// @ts-ignore
// eslint-disable-next-line no-inner-declarations
var handlePointermove = /*#__PURE__*/function () {
var _ref = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee(event) {
var timeElapsed, distanceMoved, point, elementsBelow, elementBelow, droppableBelow;
return _regeneratorRuntime().wrap(function _callee$(_context) {
while (1) switch (_context.prev = _context.next) {
case 0:
if (dragstartTriggered) {
_context.next = 8;
break;
}
if (droppableBelow) {
// @see https://developer.mozilla.org/zh-CN/docs/Web/API/Document/dragleave_event
event.type = 'dragenter';
event.target = droppableBelow;
droppableBelow.dispatchEvent(event);
timeElapsed = event.timeStamp - dragstartTimeStamp;
distanceMoved = distanceSquareRoot([event.clientX, event.clientY], dragstartClientCoordinates); // check thresholds
if (!(timeElapsed <= _this.dragndropPluginOptions.dragstartTimeThreshold || distanceMoved <= _this.dragndropPluginOptions.dragstartDistanceThreshold)) {
_context.next = 5;
break;
}
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);
return _context.abrupt("return");
case 5:
// @see https://developer.mozilla.org/zh-CN/docs/Web/API/Document/dragstart_event
event.type = 'dragstart';
draggableEventTarget.dispatchEvent(event);
dragstartTriggered = true;
case 8:
// @see https://developer.mozilla.org/zh-CN/docs/Web/API/Document/drag_event
event.type = 'drag';
// @ts-ignore
event.dx = event.clientX - lastDragClientCoordinates[0];
// @ts-ignore
event.dy = event.clientY - lastDragClientCoordinates[1];
draggableEventTarget.dispatchEvent(event);
lastDragClientCoordinates = [event.clientX, event.clientY];
if (isDocument) {
_context.next = 21;
break;
}
}
case 21:
case "end":
return _context.stop();
point = _this.dragndropPluginOptions.overlap === 'pointer' ? [event.canvasX, event.canvasY] : target.getBounds().center;
_context.next = 17;
return document.elementsFromPoint(point[0], point[1]);
case 17:
elementsBelow = _context.sent;
// prevent from picking the dragging element
elementBelow = elementsBelow[elementsBelow.indexOf(target) + 1];
droppableBelow = (elementBelow === null || elementBelow === void 0 ? void 0 : elementBelow.closest('[droppable=true]')) || (_this.dragndropPluginOptions.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 (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;
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 21:
case "end":
return _context.stop();
}
}, _callee);
}));
return function handlePointermove(_x) {
return _ref.apply(this, arguments);
};
}();
canvas.addEventListener('pointermove', handlePointermove);
var stopDragging = function stopDragging(originalPointerUpEvent) {
if (dragstartTriggered) {
// prevent click event being triggerd
// @see https://github.com/antvis/G/issues/1091
originalPointerUpEvent.detail = {
preventClick: true
};
// clone event first
var _event = originalPointerUpEvent.clone();
// 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);
}
}, _callee);
}));
return function handlePointermove(_x) {
return _ref.apply(this, arguments);
// @see https://developer.mozilla.org/zh-CN/docs/Web/API/Document/dragend_event
_event.type = 'dragend';
draggableEventTarget.dispatchEvent(_event);
dragstartTriggered = false;
}
canvas.removeEventListener('pointermove', handlePointermove);
};
}();
canvas.addEventListener('pointermove', handlePointermove);
var stopDragging = function stopDragging(originalPointerUpEvent) {
if (dragstartTriggered) {
// prevent click event being triggerd
// @see https://github.com/antvis/G/issues/1091
originalPointerUpEvent.detail = {
preventClick: true
};
// clone event first
var _event = originalPointerUpEvent.clone();
// 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';
draggableEventTarget.dispatchEvent(_event);
dragstartTriggered = false;
target.addEventListener('pointerup', stopDragging, {
once: true
});
target.addEventListener('pointerupoutside', stopDragging, {
once: true
});
}
};
renderingService.hooks.init.tapPromise(DragndropPlugin.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();
}
canvas.removeEventListener('pointermove', handlePointermove);
};
target.addEventListener('pointerup', stopDragging, {
once: true
});
target.addEventListener('pointerupoutside', stopDragging, {
once: true
});
}
};
renderingService.hooks.init.tapPromise(DragndropPlugin.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();
}
}, _callee2);
})));
renderingService.hooks.destroy.tap(DragndropPlugin.tag, function () {
canvas.removeEventListener('pointerdown', handlePointerdown);
});
};
}, _callee2);
})));
renderingService.hooks.destroy.tap(DragndropPlugin.tag, function () {
canvas.removeEventListener('pointerdown', handlePointerdown);
});
}
}]);
return DragndropPlugin;

@@ -521,9 +637,9 @@ }();

var Plugin = /*#__PURE__*/function (_AbstractRendererPlug) {
_inheritsLoose(Plugin, _AbstractRendererPlug);
function Plugin(options) {
_inherits(Plugin, _AbstractRendererPlug);
var _super = _createSuper(Plugin);
function Plugin() {
var _this;
if (options === void 0) {
options = {};
}
_this = _AbstractRendererPlug.call(this) || this;
var options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
_classCallCheck(this, Plugin);
_this = _super.call(this);
_this.options = void 0;

@@ -534,18 +650,24 @@ _this.name = 'dragndrop';

}
var _proto = Plugin.prototype;
_proto.init = function init() {
this.addRenderingPlugin(new DragndropPlugin(_extends({
overlap: 'pointer',
isDocumentDraggable: false,
isDocumentDroppable: false,
dragstartDistanceThreshold: 0,
dragstartTimeThreshold: 0
}, this.options)));
};
_proto.destroy = function destroy() {
this.removeAllRenderingPlugins();
};
_proto.setOptions = function setOptions(options) {
Object.assign(this.plugins[0].dragndropPluginOptions, options);
};
_createClass(Plugin, [{
key: "init",
value: function init() {
this.addRenderingPlugin(new DragndropPlugin(_objectSpread2({
overlap: 'pointer',
isDocumentDraggable: false,
isDocumentDroppable: false,
dragstartDistanceThreshold: 0,
dragstartTimeThreshold: 0
}, this.options)));
}
}, {
key: "destroy",
value: function destroy() {
this.removeAllRenderingPlugins();
}
}, {
key: "setOptions",
value: function setOptions(options) {
Object.assign(this.plugins[0].dragndropPluginOptions, options);
}
}]);
return Plugin;

@@ -552,0 +674,0 @@ }(AbstractRendererPlugin);

@@ -8,2 +8,23 @@ '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() {

@@ -340,21 +361,60 @@ _regeneratorRuntime = function () {

}
function _extends() {
_extends = Object.assign ? Object.assign.bind() : function (target) {
for (var i = 1; i < arguments.length; i++) {
var source = arguments[i];
for (var key in source) {
if (Object.prototype.hasOwnProperty.call(source, key)) {
target[key] = source[key];
}
}
function _classCallCheck(instance, Constructor) {
if (!(instance instanceof Constructor)) {
throw new TypeError("Cannot call a class as a function");
}
}
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, _toPropertyKey(descriptor.key), descriptor);
}
}
function _createClass(Constructor, protoProps, staticProps) {
if (protoProps) _defineProperties(Constructor.prototype, protoProps);
if (staticProps) _defineProperties(Constructor, staticProps);
Object.defineProperty(Constructor, "prototype", {
writable: false
});
return Constructor;
}
function _defineProperty(obj, key, value) {
key = _toPropertyKey(key);
if (key in obj) {
Object.defineProperty(obj, key, {
value: value,
enumerable: true,
configurable: true,
writable: true
});
} else {
obj[key] = value;
}
return obj;
}
function _inherits(subClass, superClass) {
if (typeof superClass !== "function" && superClass !== null) {
throw new TypeError("Super expression must either be null or a function");
}
subClass.prototype = Object.create(superClass && superClass.prototype, {
constructor: {
value: subClass,
writable: true,
configurable: true
}
return target;
});
Object.defineProperty(subClass, "prototype", {
writable: false
});
if (superClass) _setPrototypeOf(subClass, superClass);
}
function _getPrototypeOf(o) {
_getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf.bind() : function _getPrototypeOf(o) {
return o.__proto__ || Object.getPrototypeOf(o);
};
return _extends.apply(this, arguments);
return _getPrototypeOf(o);
}
function _inheritsLoose(subClass, superClass) {
subClass.prototype = Object.create(superClass.prototype);
subClass.prototype.constructor = subClass;
_setPrototypeOf(subClass, superClass);
}
function _setPrototypeOf(o, p) {

@@ -367,155 +427,211 @@ _setPrototypeOf = Object.setPrototypeOf ? Object.setPrototypeOf.bind() : function _setPrototypeOf(o, p) {

}
function _isNativeReflectConstruct() {
if (typeof Reflect === "undefined" || !Reflect.construct) return false;
if (Reflect.construct.sham) return false;
if (typeof Proxy === "function") return true;
try {
Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {}));
return true;
} catch (e) {
return false;
}
}
function _assertThisInitialized(self) {
if (self === void 0) {
throw new ReferenceError("this hasn't been initialised - super() hasn't been called");
}
return self;
}
function _possibleConstructorReturn(self, call) {
if (call && (typeof call === "object" || typeof call === "function")) {
return call;
} else if (call !== void 0) {
throw new TypeError("Derived constructors may only return object or undefined");
}
return _assertThisInitialized(self);
}
function _createSuper(Derived) {
var hasNativeReflectConstruct = _isNativeReflectConstruct();
return function _createSuperInternal() {
var Super = _getPrototypeOf(Derived),
result;
if (hasNativeReflectConstruct) {
var NewTarget = _getPrototypeOf(this).constructor;
result = Reflect.construct(Super, arguments, NewTarget);
} else {
result = Super.apply(this, arguments);
}
return _possibleConstructorReturn(this, result);
};
}
function _toPrimitive(input, hint) {
if (typeof input !== "object" || input === null) return input;
var prim = input[Symbol.toPrimitive];
if (prim !== undefined) {
var res = prim.call(input, hint || "default");
if (typeof res !== "object") return res;
throw new TypeError("@@toPrimitive must return a primitive value.");
}
return (hint === "string" ? String : Number)(input);
}
function _toPropertyKey(arg) {
var key = _toPrimitive(arg, "string");
return typeof key === "symbol" ? key : String(key);
}
var DragndropPlugin = /*#__PURE__*/function () {
function DragndropPlugin(dragndropPluginOptions) {
_classCallCheck(this, DragndropPlugin);
this.dragndropPluginOptions = void 0;
this.dragndropPluginOptions = dragndropPluginOptions;
}
var _proto = DragndropPlugin.prototype;
_proto.apply = function apply(context) {
var _this = this;
var renderingService = context.renderingService,
renderingContext = context.renderingContext;
var document = renderingContext.root.ownerDocument;
// TODO: should we add an option like `draggable` to Canvas
var canvas = document.defaultView;
var handlePointerdown = function handlePointerdown(event) {
var target = event.target;
var isDocument = target === document;
var draggableEventTarget = isDocument && _this.dragndropPluginOptions.isDocumentDraggable ? document : target.closest && target.closest('[draggable=true]');
// `draggable` may be set on ancestor nodes:
// @see https://github.com/antvis/G/issues/1088
if (draggableEventTarget) {
// delay triggering dragstart event
var dragstartTriggered = false;
var dragstartTimeStamp = event.timeStamp;
var dragstartClientCoordinates = [event.clientX, event.clientY];
var currentDroppable = null;
var lastDragClientCoordinates = [event.clientX, event.clientY];
// @ts-ignore
// eslint-disable-next-line no-inner-declarations
var handlePointermove = /*#__PURE__*/function () {
var _ref = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee(event) {
var timeElapsed, distanceMoved, point, elementsBelow, elementBelow, 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 = util.distanceSquareRoot([event.clientX, event.clientY], dragstartClientCoordinates); // check thresholds
if (!(timeElapsed <= _this.dragndropPluginOptions.dragstartTimeThreshold || distanceMoved <= _this.dragndropPluginOptions.dragstartDistanceThreshold)) {
_context.next = 5;
break;
}
return _context.abrupt("return");
case 5:
// @see https://developer.mozilla.org/zh-CN/docs/Web/API/Document/dragstart_event
event.type = 'dragstart';
draggableEventTarget.dispatchEvent(event);
dragstartTriggered = true;
case 8:
// @see https://developer.mozilla.org/zh-CN/docs/Web/API/Document/drag_event
event.type = 'drag';
// @ts-ignore
event.dx = event.clientX - lastDragClientCoordinates[0];
// @ts-ignore
event.dy = event.clientY - lastDragClientCoordinates[1];
draggableEventTarget.dispatchEvent(event);
lastDragClientCoordinates = [event.clientX, event.clientY];
if (isDocument) {
_context.next = 21;
break;
}
point = _this.dragndropPluginOptions.overlap === 'pointer' ? [event.canvasX, event.canvasY] : target.getBounds().center;
_context.next = 17;
return document.elementsFromPoint(point[0], point[1]);
case 17:
elementsBelow = _context.sent;
// prevent from picking the dragging element
elementBelow = elementsBelow[elementsBelow.indexOf(target) + 1];
droppableBelow = (elementBelow === null || elementBelow === void 0 ? void 0 : elementBelow.closest('[droppable=true]')) || (_this.dragndropPluginOptions.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);
_createClass(DragndropPlugin, [{
key: "apply",
value: function apply(context) {
var _this = this;
var renderingService = context.renderingService,
renderingContext = context.renderingContext;
var document = renderingContext.root.ownerDocument;
// TODO: should we add an option like `draggable` to Canvas
var canvas = document.defaultView;
var handlePointerdown = function handlePointerdown(event) {
var target = event.target;
var isDocument = target === document;
var draggableEventTarget = isDocument && _this.dragndropPluginOptions.isDocumentDraggable ? document : target.closest && target.closest('[draggable=true]');
// `draggable` may be set on ancestor nodes:
// @see https://github.com/antvis/G/issues/1088
if (draggableEventTarget) {
// delay triggering dragstart event
var dragstartTriggered = false;
var dragstartTimeStamp = event.timeStamp;
var dragstartClientCoordinates = [event.clientX, event.clientY];
var currentDroppable = null;
var lastDragClientCoordinates = [event.clientX, event.clientY];
// @ts-ignore
// eslint-disable-next-line no-inner-declarations
var handlePointermove = /*#__PURE__*/function () {
var _ref = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee(event) {
var timeElapsed, distanceMoved, point, elementsBelow, elementBelow, droppableBelow;
return _regeneratorRuntime().wrap(function _callee$(_context) {
while (1) switch (_context.prev = _context.next) {
case 0:
if (dragstartTriggered) {
_context.next = 8;
break;
}
if (droppableBelow) {
// @see https://developer.mozilla.org/zh-CN/docs/Web/API/Document/dragleave_event
event.type = 'dragenter';
event.target = droppableBelow;
droppableBelow.dispatchEvent(event);
timeElapsed = event.timeStamp - dragstartTimeStamp;
distanceMoved = util.distanceSquareRoot([event.clientX, event.clientY], dragstartClientCoordinates); // check thresholds
if (!(timeElapsed <= _this.dragndropPluginOptions.dragstartTimeThreshold || distanceMoved <= _this.dragndropPluginOptions.dragstartDistanceThreshold)) {
_context.next = 5;
break;
}
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);
return _context.abrupt("return");
case 5:
// @see https://developer.mozilla.org/zh-CN/docs/Web/API/Document/dragstart_event
event.type = 'dragstart';
draggableEventTarget.dispatchEvent(event);
dragstartTriggered = true;
case 8:
// @see https://developer.mozilla.org/zh-CN/docs/Web/API/Document/drag_event
event.type = 'drag';
// @ts-ignore
event.dx = event.clientX - lastDragClientCoordinates[0];
// @ts-ignore
event.dy = event.clientY - lastDragClientCoordinates[1];
draggableEventTarget.dispatchEvent(event);
lastDragClientCoordinates = [event.clientX, event.clientY];
if (isDocument) {
_context.next = 21;
break;
}
}
case 21:
case "end":
return _context.stop();
point = _this.dragndropPluginOptions.overlap === 'pointer' ? [event.canvasX, event.canvasY] : target.getBounds().center;
_context.next = 17;
return document.elementsFromPoint(point[0], point[1]);
case 17:
elementsBelow = _context.sent;
// prevent from picking the dragging element
elementBelow = elementsBelow[elementsBelow.indexOf(target) + 1];
droppableBelow = (elementBelow === null || elementBelow === void 0 ? void 0 : elementBelow.closest('[droppable=true]')) || (_this.dragndropPluginOptions.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 (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;
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 21:
case "end":
return _context.stop();
}
}, _callee);
}));
return function handlePointermove(_x) {
return _ref.apply(this, arguments);
};
}();
canvas.addEventListener('pointermove', handlePointermove);
var stopDragging = function stopDragging(originalPointerUpEvent) {
if (dragstartTriggered) {
// prevent click event being triggerd
// @see https://github.com/antvis/G/issues/1091
originalPointerUpEvent.detail = {
preventClick: true
};
// clone event first
var _event = originalPointerUpEvent.clone();
// 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);
}
}, _callee);
}));
return function handlePointermove(_x) {
return _ref.apply(this, arguments);
// @see https://developer.mozilla.org/zh-CN/docs/Web/API/Document/dragend_event
_event.type = 'dragend';
draggableEventTarget.dispatchEvent(_event);
dragstartTriggered = false;
}
canvas.removeEventListener('pointermove', handlePointermove);
};
}();
canvas.addEventListener('pointermove', handlePointermove);
var stopDragging = function stopDragging(originalPointerUpEvent) {
if (dragstartTriggered) {
// prevent click event being triggerd
// @see https://github.com/antvis/G/issues/1091
originalPointerUpEvent.detail = {
preventClick: true
};
// clone event first
var _event = originalPointerUpEvent.clone();
// 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';
draggableEventTarget.dispatchEvent(_event);
dragstartTriggered = false;
target.addEventListener('pointerup', stopDragging, {
once: true
});
target.addEventListener('pointerupoutside', stopDragging, {
once: true
});
}
};
renderingService.hooks.init.tapPromise(DragndropPlugin.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();
}
canvas.removeEventListener('pointermove', handlePointermove);
};
target.addEventListener('pointerup', stopDragging, {
once: true
});
target.addEventListener('pointerupoutside', stopDragging, {
once: true
});
}
};
renderingService.hooks.init.tapPromise(DragndropPlugin.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();
}
}, _callee2);
})));
renderingService.hooks.destroy.tap(DragndropPlugin.tag, function () {
canvas.removeEventListener('pointerdown', handlePointerdown);
});
};
}, _callee2);
})));
renderingService.hooks.destroy.tap(DragndropPlugin.tag, function () {
canvas.removeEventListener('pointerdown', handlePointerdown);
});
}
}]);
return DragndropPlugin;

@@ -526,9 +642,9 @@ }();

var Plugin = /*#__PURE__*/function (_AbstractRendererPlug) {
_inheritsLoose(Plugin, _AbstractRendererPlug);
function Plugin(options) {
_inherits(Plugin, _AbstractRendererPlug);
var _super = _createSuper(Plugin);
function Plugin() {
var _this;
if (options === void 0) {
options = {};
}
_this = _AbstractRendererPlug.call(this) || this;
var options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
_classCallCheck(this, Plugin);
_this = _super.call(this);
_this.options = void 0;

@@ -539,18 +655,24 @@ _this.name = 'dragndrop';

}
var _proto = Plugin.prototype;
_proto.init = function init() {
this.addRenderingPlugin(new DragndropPlugin(_extends({
overlap: 'pointer',
isDocumentDraggable: false,
isDocumentDroppable: false,
dragstartDistanceThreshold: 0,
dragstartTimeThreshold: 0
}, this.options)));
};
_proto.destroy = function destroy() {
this.removeAllRenderingPlugins();
};
_proto.setOptions = function setOptions(options) {
Object.assign(this.plugins[0].dragndropPluginOptions, options);
};
_createClass(Plugin, [{
key: "init",
value: function init() {
this.addRenderingPlugin(new DragndropPlugin(_objectSpread2({
overlap: 'pointer',
isDocumentDraggable: false,
isDocumentDroppable: false,
dragstartDistanceThreshold: 0,
dragstartTimeThreshold: 0
}, this.options)));
}
}, {
key: "destroy",
value: function destroy() {
this.removeAllRenderingPlugins();
}
}, {
key: "setOptions",
value: function setOptions(options) {
Object.assign(this.plugins[0].dragndropPluginOptions, options);
}
}]);
return Plugin;

@@ -557,0 +679,0 @@ }(gLite.AbstractRendererPlugin);

@@ -7,2 +7,23 @@ (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() {

@@ -339,21 +360,60 @@ _regeneratorRuntime = function () {

}
function _extends() {
_extends = Object.assign ? Object.assign.bind() : function (target) {
for (var i = 1; i < arguments.length; i++) {
var source = arguments[i];
for (var key in source) {
if (Object.prototype.hasOwnProperty.call(source, key)) {
target[key] = source[key];
}
}
function _classCallCheck(instance, Constructor) {
if (!(instance instanceof Constructor)) {
throw new TypeError("Cannot call a class as a function");
}
}
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, _toPropertyKey(descriptor.key), descriptor);
}
}
function _createClass(Constructor, protoProps, staticProps) {
if (protoProps) _defineProperties(Constructor.prototype, protoProps);
if (staticProps) _defineProperties(Constructor, staticProps);
Object.defineProperty(Constructor, "prototype", {
writable: false
});
return Constructor;
}
function _defineProperty(obj, key, value) {
key = _toPropertyKey(key);
if (key in obj) {
Object.defineProperty(obj, key, {
value: value,
enumerable: true,
configurable: true,
writable: true
});
} else {
obj[key] = value;
}
return obj;
}
function _inherits(subClass, superClass) {
if (typeof superClass !== "function" && superClass !== null) {
throw new TypeError("Super expression must either be null or a function");
}
subClass.prototype = Object.create(superClass && superClass.prototype, {
constructor: {
value: subClass,
writable: true,
configurable: true
}
return target;
});
Object.defineProperty(subClass, "prototype", {
writable: false
});
if (superClass) _setPrototypeOf(subClass, superClass);
}
function _getPrototypeOf(o) {
_getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf.bind() : function _getPrototypeOf(o) {
return o.__proto__ || Object.getPrototypeOf(o);
};
return _extends.apply(this, arguments);
return _getPrototypeOf(o);
}
function _inheritsLoose(subClass, superClass) {
subClass.prototype = Object.create(superClass.prototype);
subClass.prototype.constructor = subClass;
_setPrototypeOf(subClass, superClass);
}
function _setPrototypeOf(o, p) {

@@ -366,2 +426,55 @@ _setPrototypeOf = Object.setPrototypeOf ? Object.setPrototypeOf.bind() : function _setPrototypeOf(o, p) {

}
function _isNativeReflectConstruct() {
if (typeof Reflect === "undefined" || !Reflect.construct) return false;
if (Reflect.construct.sham) return false;
if (typeof Proxy === "function") return true;
try {
Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {}));
return true;
} catch (e) {
return false;
}
}
function _assertThisInitialized(self) {
if (self === void 0) {
throw new ReferenceError("this hasn't been initialised - super() hasn't been called");
}
return self;
}
function _possibleConstructorReturn(self, call) {
if (call && (typeof call === "object" || typeof call === "function")) {
return call;
} else if (call !== void 0) {
throw new TypeError("Derived constructors may only return object or undefined");
}
return _assertThisInitialized(self);
}
function _createSuper(Derived) {
var hasNativeReflectConstruct = _isNativeReflectConstruct();
return function _createSuperInternal() {
var Super = _getPrototypeOf(Derived),
result;
if (hasNativeReflectConstruct) {
var NewTarget = _getPrototypeOf(this).constructor;
result = Reflect.construct(Super, arguments, NewTarget);
} else {
result = Super.apply(this, arguments);
}
return _possibleConstructorReturn(this, result);
};
}
function _toPrimitive(input, hint) {
if (typeof input !== "object" || input === null) return input;
var prim = input[Symbol.toPrimitive];
if (prim !== undefined) {
var res = prim.call(input, hint || "default");
if (typeof res !== "object") return res;
throw new TypeError("@@toPrimitive must return a primitive value.");
}
return (hint === "string" ? String : Number)(input);
}
function _toPropertyKey(arg) {
var key = _toPrimitive(arg, "string");
return typeof key === "symbol" ? key : String(key);
}

@@ -374,152 +487,155 @@ function distanceSquareRoot(a, b) {

function DragndropPlugin(dragndropPluginOptions) {
_classCallCheck(this, DragndropPlugin);
this.dragndropPluginOptions = void 0;
this.dragndropPluginOptions = dragndropPluginOptions;
}
var _proto = DragndropPlugin.prototype;
_proto.apply = function apply(context) {
var _this = this;
var renderingService = context.renderingService,
renderingContext = context.renderingContext;
var document = renderingContext.root.ownerDocument;
// TODO: should we add an option like `draggable` to Canvas
var canvas = document.defaultView;
var handlePointerdown = function handlePointerdown(event) {
var target = event.target;
var isDocument = target === document;
var draggableEventTarget = isDocument && _this.dragndropPluginOptions.isDocumentDraggable ? document : target.closest && target.closest('[draggable=true]');
// `draggable` may be set on ancestor nodes:
// @see https://github.com/antvis/G/issues/1088
if (draggableEventTarget) {
// delay triggering dragstart event
var dragstartTriggered = false;
var dragstartTimeStamp = event.timeStamp;
var dragstartClientCoordinates = [event.clientX, event.clientY];
var currentDroppable = null;
var lastDragClientCoordinates = [event.clientX, event.clientY];
// @ts-ignore
// eslint-disable-next-line no-inner-declarations
var handlePointermove = /*#__PURE__*/function () {
var _ref = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee(event) {
var timeElapsed, distanceMoved, point, elementsBelow, elementBelow, 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 = distanceSquareRoot([event.clientX, event.clientY], dragstartClientCoordinates); // check thresholds
if (!(timeElapsed <= _this.dragndropPluginOptions.dragstartTimeThreshold || distanceMoved <= _this.dragndropPluginOptions.dragstartDistanceThreshold)) {
_context.next = 5;
break;
}
return _context.abrupt("return");
case 5:
// @see https://developer.mozilla.org/zh-CN/docs/Web/API/Document/dragstart_event
event.type = 'dragstart';
draggableEventTarget.dispatchEvent(event);
dragstartTriggered = true;
case 8:
// @see https://developer.mozilla.org/zh-CN/docs/Web/API/Document/drag_event
event.type = 'drag';
// @ts-ignore
event.dx = event.clientX - lastDragClientCoordinates[0];
// @ts-ignore
event.dy = event.clientY - lastDragClientCoordinates[1];
draggableEventTarget.dispatchEvent(event);
lastDragClientCoordinates = [event.clientX, event.clientY];
if (isDocument) {
_context.next = 21;
break;
}
point = _this.dragndropPluginOptions.overlap === 'pointer' ? [event.canvasX, event.canvasY] : target.getBounds().center;
_context.next = 17;
return document.elementsFromPoint(point[0], point[1]);
case 17:
elementsBelow = _context.sent;
// prevent from picking the dragging element
elementBelow = elementsBelow[elementsBelow.indexOf(target) + 1];
droppableBelow = (elementBelow === null || elementBelow === void 0 ? void 0 : elementBelow.closest('[droppable=true]')) || (_this.dragndropPluginOptions.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);
_createClass(DragndropPlugin, [{
key: "apply",
value: function apply(context) {
var _this = this;
var renderingService = context.renderingService,
renderingContext = context.renderingContext;
var document = renderingContext.root.ownerDocument;
// TODO: should we add an option like `draggable` to Canvas
var canvas = document.defaultView;
var handlePointerdown = function handlePointerdown(event) {
var target = event.target;
var isDocument = target === document;
var draggableEventTarget = isDocument && _this.dragndropPluginOptions.isDocumentDraggable ? document : target.closest && target.closest('[draggable=true]');
// `draggable` may be set on ancestor nodes:
// @see https://github.com/antvis/G/issues/1088
if (draggableEventTarget) {
// delay triggering dragstart event
var dragstartTriggered = false;
var dragstartTimeStamp = event.timeStamp;
var dragstartClientCoordinates = [event.clientX, event.clientY];
var currentDroppable = null;
var lastDragClientCoordinates = [event.clientX, event.clientY];
// @ts-ignore
// eslint-disable-next-line no-inner-declarations
var handlePointermove = /*#__PURE__*/function () {
var _ref = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee(event) {
var timeElapsed, distanceMoved, point, elementsBelow, elementBelow, droppableBelow;
return _regeneratorRuntime().wrap(function _callee$(_context) {
while (1) switch (_context.prev = _context.next) {
case 0:
if (dragstartTriggered) {
_context.next = 8;
break;
}
if (droppableBelow) {
// @see https://developer.mozilla.org/zh-CN/docs/Web/API/Document/dragleave_event
event.type = 'dragenter';
event.target = droppableBelow;
droppableBelow.dispatchEvent(event);
timeElapsed = event.timeStamp - dragstartTimeStamp;
distanceMoved = distanceSquareRoot([event.clientX, event.clientY], dragstartClientCoordinates); // check thresholds
if (!(timeElapsed <= _this.dragndropPluginOptions.dragstartTimeThreshold || distanceMoved <= _this.dragndropPluginOptions.dragstartDistanceThreshold)) {
_context.next = 5;
break;
}
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);
return _context.abrupt("return");
case 5:
// @see https://developer.mozilla.org/zh-CN/docs/Web/API/Document/dragstart_event
event.type = 'dragstart';
draggableEventTarget.dispatchEvent(event);
dragstartTriggered = true;
case 8:
// @see https://developer.mozilla.org/zh-CN/docs/Web/API/Document/drag_event
event.type = 'drag';
// @ts-ignore
event.dx = event.clientX - lastDragClientCoordinates[0];
// @ts-ignore
event.dy = event.clientY - lastDragClientCoordinates[1];
draggableEventTarget.dispatchEvent(event);
lastDragClientCoordinates = [event.clientX, event.clientY];
if (isDocument) {
_context.next = 21;
break;
}
}
case 21:
case "end":
return _context.stop();
point = _this.dragndropPluginOptions.overlap === 'pointer' ? [event.canvasX, event.canvasY] : target.getBounds().center;
_context.next = 17;
return document.elementsFromPoint(point[0], point[1]);
case 17:
elementsBelow = _context.sent;
// prevent from picking the dragging element
elementBelow = elementsBelow[elementsBelow.indexOf(target) + 1];
droppableBelow = (elementBelow === null || elementBelow === void 0 ? void 0 : elementBelow.closest('[droppable=true]')) || (_this.dragndropPluginOptions.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 (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;
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 21:
case "end":
return _context.stop();
}
}, _callee);
}));
return function handlePointermove(_x) {
return _ref.apply(this, arguments);
};
}();
canvas.addEventListener('pointermove', handlePointermove);
var stopDragging = function stopDragging(originalPointerUpEvent) {
if (dragstartTriggered) {
// prevent click event being triggerd
// @see https://github.com/antvis/G/issues/1091
originalPointerUpEvent.detail = {
preventClick: true
};
// clone event first
var _event = originalPointerUpEvent.clone();
// 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);
}
}, _callee);
}));
return function handlePointermove(_x) {
return _ref.apply(this, arguments);
// @see https://developer.mozilla.org/zh-CN/docs/Web/API/Document/dragend_event
_event.type = 'dragend';
draggableEventTarget.dispatchEvent(_event);
dragstartTriggered = false;
}
canvas.removeEventListener('pointermove', handlePointermove);
};
}();
canvas.addEventListener('pointermove', handlePointermove);
var stopDragging = function stopDragging(originalPointerUpEvent) {
if (dragstartTriggered) {
// prevent click event being triggerd
// @see https://github.com/antvis/G/issues/1091
originalPointerUpEvent.detail = {
preventClick: true
};
// clone event first
var _event = originalPointerUpEvent.clone();
// 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';
draggableEventTarget.dispatchEvent(_event);
dragstartTriggered = false;
target.addEventListener('pointerup', stopDragging, {
once: true
});
target.addEventListener('pointerupoutside', stopDragging, {
once: true
});
}
};
renderingService.hooks.init.tapPromise(DragndropPlugin.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();
}
canvas.removeEventListener('pointermove', handlePointermove);
};
target.addEventListener('pointerup', stopDragging, {
once: true
});
target.addEventListener('pointerupoutside', stopDragging, {
once: true
});
}
};
renderingService.hooks.init.tapPromise(DragndropPlugin.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();
}
}, _callee2);
})));
renderingService.hooks.destroy.tap(DragndropPlugin.tag, function () {
canvas.removeEventListener('pointerdown', handlePointerdown);
});
};
}, _callee2);
})));
renderingService.hooks.destroy.tap(DragndropPlugin.tag, function () {
canvas.removeEventListener('pointerdown', handlePointerdown);
});
}
}]);
return DragndropPlugin;

@@ -530,9 +646,9 @@ }();

var Plugin = /*#__PURE__*/function (_AbstractRendererPlug) {
_inheritsLoose(Plugin, _AbstractRendererPlug);
function Plugin(options) {
_inherits(Plugin, _AbstractRendererPlug);
var _super = _createSuper(Plugin);
function Plugin() {
var _this;
if (options === void 0) {
options = {};
}
_this = _AbstractRendererPlug.call(this) || this;
var options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
_classCallCheck(this, Plugin);
_this = _super.call(this);
_this.options = void 0;

@@ -543,18 +659,24 @@ _this.name = 'dragndrop';

}
var _proto = Plugin.prototype;
_proto.init = function init() {
this.addRenderingPlugin(new DragndropPlugin(_extends({
overlap: 'pointer',
isDocumentDraggable: false,
isDocumentDroppable: false,
dragstartDistanceThreshold: 0,
dragstartTimeThreshold: 0
}, this.options)));
};
_proto.destroy = function destroy() {
this.removeAllRenderingPlugins();
};
_proto.setOptions = function setOptions(options) {
Object.assign(this.plugins[0].dragndropPluginOptions, options);
};
_createClass(Plugin, [{
key: "init",
value: function init() {
this.addRenderingPlugin(new DragndropPlugin(_objectSpread2({
overlap: 'pointer',
isDocumentDraggable: false,
isDocumentDroppable: false,
dragstartDistanceThreshold: 0,
dragstartTimeThreshold: 0
}, this.options)));
}
}, {
key: "destroy",
value: function destroy() {
this.removeAllRenderingPlugins();
}
}, {
key: "setOptions",
value: function setOptions(options) {
Object.assign(this.plugins[0].dragndropPluginOptions, options);
}
}]);
return Plugin;

@@ -561,0 +683,0 @@ }(gLite.AbstractRendererPlugin);

@@ -1,1 +0,1 @@

!function(t,e){"object"==typeof exports&&"undefined"!=typeof module?e(exports,require("@antv/g-lite")):"function"==typeof define&&define.amd?define(["exports","@antv/g-lite"],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(){r=function(){return t};var t={},e=Object.prototype,n=e.hasOwnProperty,o=Object.defineProperty||function(t,e,r){t[e]=r.value},i="function"==typeof Symbol?Symbol:{},a=i.iterator||"@@iterator",c=i.asyncIterator||"@@asyncIterator",u=i.toStringTag||"@@toStringTag";function s(t,e,r){return Object.defineProperty(t,e,{value:r,enumerable:!0,configurable:!0,writable:!0}),t[e]}try{s({},"")}catch(t){s=function(t,e,r){return t[e]=r}}function l(t,e,r,n){var i=Object.create((e&&e.prototype instanceof h?e:h).prototype),a=new j(n||[]);return o(i,"_invoke",{value:E(t,r,a)}),i}function p(t,e,r){try{return{type:"normal",arg:t.call(e,r)}}catch(t){return{type:"throw",arg:t}}}t.wrap=l;var f={};function h(){}function d(){}function v(){}var g={};s(g,a,(function(){return this}));var y=Object.getPrototypeOf,m=y&&y(y(_([])));m&&m!==e&&n.call(m,a)&&(g=m);var w=v.prototype=h.prototype=Object.create(g);function b(t){["next","throw","return"].forEach((function(e){s(t,e,(function(t){return this._invoke(e,t)}))}))}function x(t,e){function r(o,i,a,c){var u=p(t[o],t,i);if("throw"!==u.type){var s=u.arg,l=s.value;return l&&"object"==typeof l&&n.call(l,"__await")?e.resolve(l.__await).then((function(t){r("next",t,a,c)}),(function(t){r("throw",t,a,c)})):e.resolve(l).then((function(t){s.value=t,a(s)}),(function(t){return r("throw",t,a,c)}))}c(u.arg)}var i;o(this,"_invoke",{value:function(t,n){function o(){return new e((function(e,o){r(t,n,e,o)}))}return i=i?i.then(o,o):o()}})}function E(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 k()}for(r.method=o,r.arg=i;;){var a=r.delegate;if(a){var c=O(a,r);if(c){if(c===f)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=p(t,e,r);if("normal"===u.type){if(n=r.done?"completed":"suspendedYield",u.arg===f)continue;return{value:u.arg,done:r.done}}"throw"===u.type&&(n="completed",r.method="throw",r.arg=u.arg)}}}function O(t,e){var r=e.method,n=t.iterator[r];if(void 0===n)return e.delegate=null,"throw"===r&&t.iterator.return&&(e.method="return",e.arg=void 0,O(t,e),"throw"===e.method)||"return"!==r&&(e.method="throw",e.arg=new TypeError("The iterator does not provide a '"+r+"' method")),f;var o=p(n,t.iterator,e.arg);if("throw"===o.type)return e.method="throw",e.arg=o.arg,e.delegate=null,f;var i=o.arg;return i?i.done?(e[t.resultName]=i.value,e.next=t.nextLoc,"return"!==e.method&&(e.method="next",e.arg=void 0),e.delegate=null,f):i:(e.method="throw",e.arg=new TypeError("iterator result is not an object"),e.delegate=null,f)}function L(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 P(t){var e=t.completion||{};e.type="normal",delete e.arg,t.completion=e}function j(t){this.tryEntries=[{tryLoc:"root"}],t.forEach(L,this),this.reset(!0)}function _(t){if(t){var e=t[a];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:k}}function k(){return{value:void 0,done:!0}}return d.prototype=v,o(w,"constructor",{value:v,configurable:!0}),o(v,"constructor",{value:d,configurable:!0}),d.displayName=s(v,u,"GeneratorFunction"),t.isGeneratorFunction=function(t){var e="function"==typeof t&&t.constructor;return!!e&&(e===d||"GeneratorFunction"===(e.displayName||e.name))},t.mark=function(t){return Object.setPrototypeOf?Object.setPrototypeOf(t,v):(t.__proto__=v,s(t,u,"GeneratorFunction")),t.prototype=Object.create(w),t},t.awrap=function(t){return{__await:t}},b(x.prototype),s(x.prototype,c,(function(){return this})),t.AsyncIterator=x,t.async=function(e,r,n,o,i){void 0===i&&(i=Promise);var a=new x(l(e,r,n,o),i);return t.isGeneratorFunction(r)?a:a.next().then((function(t){return t.done?t.value:a.next()}))},b(w),s(w,u,"Generator"),s(w,a,(function(){return this})),s(w,"toString",(function(){return"[object Generator]"})),t.keys=function(t){var e=Object(t),r=[];for(var n in e)r.push(n);return r.reverse(),function t(){for(;r.length;){var n=r.pop();if(n in e)return t.value=n,t.done=!1,t}return t.done=!0,t}},t.values=_,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(P),!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 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,f):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),f},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),P(r),f}},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;P(r)}return o}}throw Error("illegal catch attempt")},delegateYield:function(t,e,r){return this.delegate={iterator:_(t),resultName:e,nextLoc:r},"next"===this.method&&(this.arg=void 0),f}},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?Object.assign.bind():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){return a=Object.setPrototypeOf?Object.setPrototypeOf.bind():function(t,e){return t.__proto__=e,t},a(t,e)}var c=function(){function t(t){this.dragndropPluginOptions=void 0,this.dragndropPluginOptions=t}return t.prototype.apply=function(e){var n=this,i=e.renderingService,a=e.renderingContext.root.ownerDocument,c=a.defaultView,u=function(t){var e=t.target,i=e===a,u=i&&n.dragndropPluginOptions.isDocumentDraggable?a:e.closest&&e.closest("[draggable=true]");if(u){var s=!1,l=t.timeStamp,p=[t.clientX,t.clientY],f=null,h=[t.clientX,t.clientY],d=function(){var t=o(r().mark((function t(o){var c,d,v,g,y,m;return r().wrap((function(t){for(;;)switch(t.prev=t.next){case 0:if(s){t.next=8;break}if(c=o.timeStamp-l,d=Math.sqrt(((r=[o.clientX,o.clientY])[0]-(w=p)[0])*(r[0]-w[0])+(r[1]-w[1])*(r[1]-w[1])),c>n.dragndropPluginOptions.dragstartTimeThreshold&&d>n.dragndropPluginOptions.dragstartDistanceThreshold){t.next=5;break}return t.abrupt("return");case 5:o.type="dragstart",u.dispatchEvent(o),s=!0;case 8:if(o.type="drag",o.dx=o.clientX-h[0],o.dy=o.clientY-h[1],u.dispatchEvent(o),h=[o.clientX,o.clientY],i){t.next=21;break}return v="pointer"===n.dragndropPluginOptions.overlap?[o.canvasX,o.canvasY]:e.getBounds().center,t.next=17,a.elementsFromPoint(v[0],v[1]);case 17:y=(g=t.sent)[g.indexOf(e)+1],m=(null==y?void 0:y.closest("[droppable=true]"))||(n.dragndropPluginOptions.isDocumentDroppable?a:null),f!==m&&(f&&(o.type="dragleave",o.target=f,f.dispatchEvent(o)),m&&(o.type="dragenter",o.target=m,m.dispatchEvent(o)),(f=m)&&(o.type="dragover",o.target=f,f.dispatchEvent(o)));case 21:case"end":return t.stop()}var r,w}),t)})));return function(e){return t.apply(this,arguments)}}();c.addEventListener("pointermove",d);var v=function(t){if(s){t.detail={preventClick:!0};var e=t.clone();f&&(e.type="drop",e.target=f,f.dispatchEvent(e)),e.type="dragend",u.dispatchEvent(e),s=!1}c.removeEventListener("pointermove",d)};e.addEventListener("pointerup",v,{once:!0}),e.addEventListener("pointerupoutside",v,{once:!0})}};i.hooks.init.tapPromise(t.tag,o(r().mark((function t(){return r().wrap((function(t){for(;;)switch(t.prev=t.next){case 0:c.addEventListener("pointerdown",u);case 1:case"end":return t.stop()}}),t)})))),i.hooks.destroy.tap(t.tag,(function(){c.removeEventListener("pointerdown",u)}))},t}();c.tag="Dragndrop",t.Plugin=function(t){var e,r;function n(e){var r;return void 0===e&&(e={}),(r=t.call(this)||this).options=void 0,r.name="dragndrop",r.options=e,r}(e=n).prototype=Object.create((r=t).prototype),e.prototype.constructor=e,a(e,r);var o=n.prototype;return o.init=function(){this.addRenderingPlugin(new c(i({overlap:"pointer",isDocumentDraggable:!1,isDocumentDroppable:!1,dragstartDistanceThreshold:0,dragstartTimeThreshold:0},this.options)))},o.destroy=function(){this.removeAllRenderingPlugins()},o.setOptions=function(t){Object.assign(this.plugins[0].dragndropPluginOptions,t)},n}(e.AbstractRendererPlugin),Object.defineProperty(t,"__esModule",{value:!0})}));
!function(t,e){"object"==typeof exports&&"undefined"!=typeof module?e(exports,require("@antv/g-lite")):"function"==typeof define&&define.amd?define(["exports","@antv/g-lite"],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(){n=function(){return t};var t={},e=Object.prototype,r=e.hasOwnProperty,o=Object.defineProperty||function(t,e,r){t[e]=r.value},i="function"==typeof Symbol?Symbol:{},a=i.iterator||"@@iterator",c=i.asyncIterator||"@@asyncIterator",u=i.toStringTag||"@@toStringTag";function s(t,e,r){return Object.defineProperty(t,e,{value:r,enumerable:!0,configurable:!0,writable:!0}),t[e]}try{s({},"")}catch(t){s=function(t,e,r){return t[e]=r}}function l(t,e,r,n){var i=Object.create((e&&e.prototype instanceof h?e:h).prototype),a=new L(n||[]);return o(i,"_invoke",{value:P(t,r,a)}),i}function f(t,e,r){try{return{type:"normal",arg:t.call(e,r)}}catch(t){return{type:"throw",arg:t}}}t.wrap=l;var p={};function h(){}function d(){}function v(){}var y={};s(y,a,(function(){return this}));var g=Object.getPrototypeOf,m=g&&g(g(_([])));m&&m!==e&&r.call(m,a)&&(y=m);var b=v.prototype=h.prototype=Object.create(y);function w(t){["next","throw","return"].forEach((function(e){s(t,e,(function(t){return this._invoke(e,t)}))}))}function O(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 i;o(this,"_invoke",{value:function(t,r){function o(){return new e((function(e,o){n(t,r,e,o)}))}return i=i?i.then(o,o):o()}})}function P(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 k()}for(r.method=o,r.arg=i;;){var a=r.delegate;if(a){var c=E(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)}}}function E(t,e){var r=e.method,n=t.iterator[r];if(void 0===n)return e.delegate=null,"throw"===r&&t.iterator.return&&(e.method="return",e.arg=void 0,E(t,e),"throw"===e.method)||"return"!==r&&(e.method="throw",e.arg=new TypeError("The iterator does not provide a '"+r+"' method")),p;var o=f(n,t.iterator,e.arg);if("throw"===o.type)return e.method="throw",e.arg=o.arg,e.delegate=null,p;var i=o.arg;return i?i.done?(e[t.resultName]=i.value,e.next=t.nextLoc,"return"!==e.method&&(e.method="next",e.arg=void 0),e.delegate=null,p):i:(e.method="throw",e.arg=new TypeError("iterator result is not an object"),e.delegate=null,p)}function j(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 L(t){this.tryEntries=[{tryLoc:"root"}],t.forEach(j,this),this.reset(!0)}function _(t){if(t){var e=t[a];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:k}}function k(){return{value:void 0,done:!0}}return d.prototype=v,o(b,"constructor",{value:v,configurable:!0}),o(v,"constructor",{value:d,configurable:!0}),d.displayName=s(v,u,"GeneratorFunction"),t.isGeneratorFunction=function(t){var e="function"==typeof t&&t.constructor;return!!e&&(e===d||"GeneratorFunction"===(e.displayName||e.name))},t.mark=function(t){return Object.setPrototypeOf?Object.setPrototypeOf(t,v):(t.__proto__=v,s(t,u,"GeneratorFunction")),t.prototype=Object.create(b),t},t.awrap=function(t){return{__await:t}},w(O.prototype),s(O.prototype,c,(function(){return this})),t.AsyncIterator=O,t.async=function(e,r,n,o,i){void 0===i&&(i=Promise);var a=new O(l(e,r,n,o),i);return t.isGeneratorFunction(r)?a:a.next().then((function(t){return t.done?t.value:a.next()}))},w(b),s(b,u,"Generator"),s(b,a,(function(){return this})),s(b,"toString",(function(){return"[object Generator]"})),t.keys=function(t){var e=Object(t),r=[];for(var n in e)r.push(n);return r.reverse(),function t(){for(;r.length;){var n=r.pop();if(n in e)return t.value=n,t.done=!1,t}return t.done=!0,t}},t.values=_,L.prototype={constructor:L,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,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),x(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;x(r)}return o}}throw Error("illegal catch attempt")},delegateYield:function(t,e,r){return this.delegate={iterator:_(t),resultName:e,nextLoc:r},"next"===this.method&&(this.arg=void 0),p}},t}function o(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 i(t){return function(){var e=this,r=arguments;return new Promise((function(n,i){var a=t.apply(e,r);function c(t){o(a,n,i,c,u,"next",t)}function u(t){o(a,n,i,c,u,"throw",t)}c(void 0)}))}}function a(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}function c(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,d(n.key),n)}}function u(t,e,r){return e&&c(t.prototype,e),r&&c(t,r),Object.defineProperty(t,"prototype",{writable:!1}),t}function s(t,e,r){return(e=d(e))in t?Object.defineProperty(t,e,{value:r,enumerable:!0,configurable:!0,writable:!0}):t[e]=r,t}function l(t){return l=Object.setPrototypeOf?Object.getPrototypeOf.bind():function(t){return t.__proto__||Object.getPrototypeOf(t)},l(t)}function f(t,e){return f=Object.setPrototypeOf?Object.setPrototypeOf.bind():function(t,e){return t.__proto__=e,t},f(t,e)}function p(t,e){if(e&&("object"==typeof e||"function"==typeof e))return e;if(void 0!==e)throw new TypeError("Derived constructors may only return object or undefined");return function(t){if(void 0===t)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return t}(t)}function h(t){var e=function(){if("undefined"==typeof Reflect||!Reflect.construct)return!1;if(Reflect.construct.sham)return!1;if("function"==typeof Proxy)return!0;try{return Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],(function(){}))),!0}catch(t){return!1}}();return function(){var r,n=l(t);if(e){var o=l(this).constructor;r=Reflect.construct(n,arguments,o)}else r=n.apply(this,arguments);return p(this,r)}}function d(t){var e=function(t,e){if("object"!=typeof t||null===t)return t;var r=t[Symbol.toPrimitive];if(void 0!==r){var n=r.call(t,e||"default");if("object"!=typeof n)return n;throw new TypeError("@@toPrimitive must return a primitive value.")}return("string"===e?String:Number)(t)}(t,"string");return"symbol"==typeof e?e:e+""}var v=function(){function t(e){a(this,t),this.dragndropPluginOptions=void 0,this.dragndropPluginOptions=e}return u(t,[{key:"apply",value:function(e){var r=this,o=e.renderingService,a=e.renderingContext.root.ownerDocument,c=a.defaultView,u=function(t){var e=t.target,o=e===a,u=o&&r.dragndropPluginOptions.isDocumentDraggable?a:e.closest&&e.closest("[draggable=true]");if(u){var s=!1,l=t.timeStamp,f=[t.clientX,t.clientY],p=null,h=[t.clientX,t.clientY],d=function(){var t=i(n().mark((function t(i){var c,d,v,y,g,m;return n().wrap((function(t){for(;;)switch(t.prev=t.next){case 0:if(s){t.next=8;break}if(c=i.timeStamp-l,d=Math.sqrt(((n=[i.clientX,i.clientY])[0]-(b=f)[0])*(n[0]-b[0])+(n[1]-b[1])*(n[1]-b[1])),c>r.dragndropPluginOptions.dragstartTimeThreshold&&d>r.dragndropPluginOptions.dragstartDistanceThreshold){t.next=5;break}return t.abrupt("return");case 5:i.type="dragstart",u.dispatchEvent(i),s=!0;case 8:if(i.type="drag",i.dx=i.clientX-h[0],i.dy=i.clientY-h[1],u.dispatchEvent(i),h=[i.clientX,i.clientY],o){t.next=21;break}return v="pointer"===r.dragndropPluginOptions.overlap?[i.canvasX,i.canvasY]:e.getBounds().center,t.next=17,a.elementsFromPoint(v[0],v[1]);case 17:g=(y=t.sent)[y.indexOf(e)+1],m=(null==g?void 0:g.closest("[droppable=true]"))||(r.dragndropPluginOptions.isDocumentDroppable?a:null),p!==m&&(p&&(i.type="dragleave",i.target=p,p.dispatchEvent(i)),m&&(i.type="dragenter",i.target=m,m.dispatchEvent(i)),(p=m)&&(i.type="dragover",i.target=p,p.dispatchEvent(i)));case 21:case"end":return t.stop()}var n,b}),t)})));return function(e){return t.apply(this,arguments)}}();c.addEventListener("pointermove",d);var v=function(t){if(s){t.detail={preventClick:!0};var e=t.clone();p&&(e.type="drop",e.target=p,p.dispatchEvent(e)),e.type="dragend",u.dispatchEvent(e),s=!1}c.removeEventListener("pointermove",d)};e.addEventListener("pointerup",v,{once:!0}),e.addEventListener("pointerupoutside",v,{once:!0})}};o.hooks.init.tapPromise(t.tag,i(n().mark((function t(){return n().wrap((function(t){for(;;)switch(t.prev=t.next){case 0:c.addEventListener("pointerdown",u);case 1:case"end":return t.stop()}}),t)})))),o.hooks.destroy.tap(t.tag,(function(){c.removeEventListener("pointerdown",u)}))}}]),t}();v.tag="Dragndrop";var y=function(t){!function(t,e){if("function"!=typeof e&&null!==e)throw new TypeError("Super expression must either be null or a function");t.prototype=Object.create(e&&e.prototype,{constructor:{value:t,writable:!0,configurable:!0}}),Object.defineProperty(t,"prototype",{writable:!1}),e&&f(t,e)}(n,t);var e=h(n);function n(){var t,r=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};return a(this,n),(t=e.call(this)).options=void 0,t.name="dragndrop",t.options=r,t}return u(n,[{key:"init",value:function(){this.addRenderingPlugin(new v(function(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){s(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}({overlap:"pointer",isDocumentDraggable:!1,isDocumentDroppable:!1,dragstartDistanceThreshold:0,dragstartTimeThreshold:0},this.options)))}},{key:"destroy",value:function(){this.removeAllRenderingPlugins()}},{key:"setOptions",value:function(t){Object.assign(this.plugins[0].dragndropPluginOptions,t)}}]),n}(e.AbstractRendererPlugin);t.Plugin=y,Object.defineProperty(t,"__esModule",{value:!0})}));
{
"name": "@antv/g-plugin-dragndrop",
"version": "1.6.46",
"version": "1.6.47",
"description": "A G plugin for Drag n Drop implemented with PointerEvents",

@@ -45,3 +45,3 @@ "keywords": [

},
"gitHead": "b20172e3797a20282ef40bb5c3361df611cf8fbf"
"gitHead": "059286bbeff21a63e75a41811b89623c37f511f4"
}
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc