@antv/g-plugin-dragndrop
Advanced tools
Comparing version 1.6.27 to 1.6.28
@@ -5,16 +5,15 @@ import { AbstractRendererPlugin } from '@antv/g-lite'; | ||
function _regeneratorRuntime() { | ||
/*! regenerator-runtime -- Copyright (c) 2014-present, Facebook, Inc. -- license (MIT): https://github.com/facebook/regenerator/blob/main/LICENSE */ | ||
_regeneratorRuntime = function () { | ||
return exports; | ||
}; | ||
var exports = {}, | ||
Op = Object.prototype, | ||
hasOwn = Op.hasOwnProperty, | ||
$Symbol = "function" == typeof Symbol ? Symbol : {}, | ||
iteratorSymbol = $Symbol.iterator || "@@iterator", | ||
asyncIteratorSymbol = $Symbol.asyncIterator || "@@asyncIterator", | ||
toStringTagSymbol = $Symbol.toStringTag || "@@toStringTag"; | ||
Op = Object.prototype, | ||
hasOwn = Op.hasOwnProperty, | ||
defineProperty = Object.defineProperty || function (obj, key, desc) { | ||
obj[key] = desc.value; | ||
}, | ||
$Symbol = "function" == typeof Symbol ? Symbol : {}, | ||
iteratorSymbol = $Symbol.iterator || "@@iterator", | ||
asyncIteratorSymbol = $Symbol.asyncIterator || "@@asyncIterator", | ||
toStringTagSymbol = $Symbol.toStringTag || "@@toStringTag"; | ||
function define(obj, key, value) { | ||
@@ -28,3 +27,2 @@ return Object.defineProperty(obj, key, { | ||
} | ||
try { | ||
@@ -37,50 +35,10 @@ define({}, ""); | ||
} | ||
function wrap(innerFn, outerFn, self, tryLocsList) { | ||
var protoGenerator = outerFn && outerFn.prototype instanceof Generator ? outerFn : Generator, | ||
generator = Object.create(protoGenerator.prototype), | ||
context = new Context(tryLocsList || []); | ||
return generator._invoke = function (innerFn, self, context) { | ||
var state = "suspendedStart"; | ||
return function (method, arg) { | ||
if ("executing" === state) throw new Error("Generator is already running"); | ||
if ("completed" === state) { | ||
if ("throw" === method) throw arg; | ||
return doneResult(); | ||
} | ||
for (context.method = method, context.arg = arg;;) { | ||
var delegate = context.delegate; | ||
if (delegate) { | ||
var delegateResult = maybeInvokeDelegate(delegate, context); | ||
if (delegateResult) { | ||
if (delegateResult === ContinueSentinel) continue; | ||
return delegateResult; | ||
} | ||
} | ||
if ("next" === context.method) context.sent = context._sent = context.arg;else if ("throw" === context.method) { | ||
if ("suspendedStart" === state) throw state = "completed", context.arg; | ||
context.dispatchException(context.arg); | ||
} else "return" === context.method && context.abrupt("return", context.arg); | ||
state = "executing"; | ||
var record = tryCatch(innerFn, self, context); | ||
if ("normal" === record.type) { | ||
if (state = context.done ? "completed" : "suspendedYield", record.arg === ContinueSentinel) continue; | ||
return { | ||
value: record.arg, | ||
done: context.done | ||
}; | ||
} | ||
"throw" === record.type && (state = "completed", context.method = "throw", context.arg = record.arg); | ||
} | ||
}; | ||
}(innerFn, self, context), generator; | ||
generator = Object.create(protoGenerator.prototype), | ||
context = new Context(tryLocsList || []); | ||
return defineProperty(generator, "_invoke", { | ||
value: makeInvokeMethod(innerFn, self, context) | ||
}), generator; | ||
} | ||
function tryCatch(fn, obj, arg) { | ||
@@ -99,12 +57,7 @@ try { | ||
} | ||
exports.wrap = wrap; | ||
var ContinueSentinel = {}; | ||
function Generator() {} | ||
function GeneratorFunction() {} | ||
function GeneratorFunctionPrototype() {} | ||
var IteratorPrototype = {}; | ||
@@ -115,6 +68,5 @@ define(IteratorPrototype, iteratorSymbol, function () { | ||
var getProto = Object.getPrototypeOf, | ||
NativeIteratorPrototype = getProto && getProto(getProto(values([]))); | ||
NativeIteratorPrototype = getProto && getProto(getProto(values([]))); | ||
NativeIteratorPrototype && NativeIteratorPrototype !== Op && hasOwn.call(NativeIteratorPrototype, iteratorSymbol) && (IteratorPrototype = NativeIteratorPrototype); | ||
var Gp = GeneratorFunctionPrototype.prototype = Generator.prototype = Object.create(IteratorPrototype); | ||
function defineIteratorMethods(prototype) { | ||
@@ -127,10 +79,8 @@ ["next", "throw", "return"].forEach(function (method) { | ||
} | ||
function AsyncIterator(generator, PromiseImpl) { | ||
function invoke(method, arg, resolve, reject) { | ||
var record = tryCatch(generator[method], generator, arg); | ||
if ("throw" !== record.type) { | ||
var result = record.arg, | ||
value = result.value; | ||
value = result.value; | ||
return value && "object" == typeof value && hasOwn.call(value, "__await") ? PromiseImpl.resolve(value.__await).then(function (value) { | ||
@@ -146,22 +96,52 @@ invoke("next", value, resolve, reject); | ||
} | ||
reject(record.arg); | ||
} | ||
var previousPromise; | ||
this._invoke = function (method, arg) { | ||
function callInvokeWithMethodAndArg() { | ||
return new PromiseImpl(function (resolve, reject) { | ||
invoke(method, arg, resolve, reject); | ||
}); | ||
defineProperty(this, "_invoke", { | ||
value: function (method, arg) { | ||
function callInvokeWithMethodAndArg() { | ||
return new PromiseImpl(function (resolve, reject) { | ||
invoke(method, arg, resolve, reject); | ||
}); | ||
} | ||
return previousPromise = previousPromise ? previousPromise.then(callInvokeWithMethodAndArg, callInvokeWithMethodAndArg) : callInvokeWithMethodAndArg(); | ||
} | ||
return previousPromise = previousPromise ? previousPromise.then(callInvokeWithMethodAndArg, callInvokeWithMethodAndArg) : callInvokeWithMethodAndArg(); | ||
}); | ||
} | ||
function makeInvokeMethod(innerFn, self, context) { | ||
var state = "suspendedStart"; | ||
return function (method, arg) { | ||
if ("executing" === state) throw new Error("Generator is already running"); | ||
if ("completed" === state) { | ||
if ("throw" === method) throw arg; | ||
return doneResult(); | ||
} | ||
for (context.method = method, context.arg = arg;;) { | ||
var delegate = context.delegate; | ||
if (delegate) { | ||
var delegateResult = maybeInvokeDelegate(delegate, context); | ||
if (delegateResult) { | ||
if (delegateResult === ContinueSentinel) continue; | ||
return delegateResult; | ||
} | ||
} | ||
if ("next" === context.method) context.sent = context._sent = context.arg;else if ("throw" === context.method) { | ||
if ("suspendedStart" === state) throw state = "completed", context.arg; | ||
context.dispatchException(context.arg); | ||
} else "return" === context.method && context.abrupt("return", context.arg); | ||
state = "executing"; | ||
var record = tryCatch(innerFn, self, context); | ||
if ("normal" === record.type) { | ||
if (state = context.done ? "completed" : "suspendedYield", record.arg === ContinueSentinel) continue; | ||
return { | ||
value: record.arg, | ||
done: context.done | ||
}; | ||
} | ||
"throw" === record.type && (state = "completed", context.method = "throw", context.arg = record.arg); | ||
} | ||
}; | ||
} | ||
function maybeInvokeDelegate(delegate, context) { | ||
var method = delegate.iterator[context.method]; | ||
if (undefined === method) { | ||
@@ -172,6 +152,4 @@ if (context.delegate = null, "throw" === context.method) { | ||
} | ||
return ContinueSentinel; | ||
} | ||
var record = tryCatch(method, delegate.iterator, context.arg); | ||
@@ -182,3 +160,2 @@ if ("throw" === record.type) return context.method = "throw", context.arg = record.arg, context.delegate = null, ContinueSentinel; | ||
} | ||
function pushTryEntry(locs) { | ||
@@ -190,3 +167,2 @@ var entry = { | ||
} | ||
function resetTryEntry(entry) { | ||
@@ -196,3 +172,2 @@ var record = entry.completion || {}; | ||
} | ||
function Context(tryLocsList) { | ||
@@ -203,3 +178,2 @@ this.tryEntries = [{ | ||
} | ||
function values(iterable) { | ||
@@ -210,15 +184,11 @@ if (iterable) { | ||
if ("function" == typeof iterable.next) return iterable; | ||
if (!isNaN(iterable.length)) { | ||
var i = -1, | ||
next = function next() { | ||
for (; ++i < iterable.length;) if (hasOwn.call(iterable, i)) return next.value = iterable[i], next.done = !1, next; | ||
return next.value = undefined, next.done = !0, next; | ||
}; | ||
next = function next() { | ||
for (; ++i < iterable.length;) if (hasOwn.call(iterable, i)) return next.value = iterable[i], next.done = !1, next; | ||
return next.value = undefined, next.done = !0, next; | ||
}; | ||
return next.next = next; | ||
} | ||
} | ||
return { | ||
@@ -228,3 +198,2 @@ next: doneResult | ||
} | ||
function doneResult() { | ||
@@ -236,4 +205,9 @@ return { | ||
} | ||
return GeneratorFunction.prototype = GeneratorFunctionPrototype, define(Gp, "constructor", GeneratorFunctionPrototype), define(GeneratorFunctionPrototype, "constructor", GeneratorFunction), GeneratorFunction.displayName = define(GeneratorFunctionPrototype, toStringTagSymbol, "GeneratorFunction"), exports.isGeneratorFunction = function (genFun) { | ||
return GeneratorFunction.prototype = GeneratorFunctionPrototype, defineProperty(Gp, "constructor", { | ||
value: GeneratorFunctionPrototype, | ||
configurable: !0 | ||
}), defineProperty(GeneratorFunctionPrototype, "constructor", { | ||
value: GeneratorFunction, | ||
configurable: !0 | ||
}), GeneratorFunction.displayName = define(GeneratorFunctionPrototype, toStringTagSymbol, "GeneratorFunction"), exports.isGeneratorFunction = function (genFun) { | ||
var ctor = "function" == typeof genFun && genFun.constructor; | ||
@@ -259,7 +233,6 @@ return !!ctor && (ctor === GeneratorFunction || "GeneratorFunction" === (ctor.displayName || ctor.name)); | ||
return "[object Generator]"; | ||
}), exports.keys = function (object) { | ||
var keys = []; | ||
}), exports.keys = function (val) { | ||
var object = Object(val), | ||
keys = []; | ||
for (var key in object) keys.push(key); | ||
return keys.reverse(), function next() { | ||
@@ -270,3 +243,2 @@ for (; keys.length;) { | ||
} | ||
return next.done = !0, next; | ||
@@ -288,16 +260,12 @@ }; | ||
var context = this; | ||
function handle(loc, caught) { | ||
return record.type = "throw", record.arg = exception, context.next = loc, caught && (context.method = "next", context.arg = undefined), !!caught; | ||
} | ||
for (var i = this.tryEntries.length - 1; i >= 0; --i) { | ||
var entry = this.tryEntries[i], | ||
record = entry.completion; | ||
record = entry.completion; | ||
if ("root" === entry.tryLoc) return handle("end"); | ||
if (entry.tryLoc <= this.prev) { | ||
var hasCatch = hasOwn.call(entry, "catchLoc"), | ||
hasFinally = hasOwn.call(entry, "finallyLoc"); | ||
hasFinally = hasOwn.call(entry, "finallyLoc"); | ||
if (hasCatch && hasFinally) { | ||
@@ -318,3 +286,2 @@ if (this.prev < entry.catchLoc) return handle(entry.catchLoc, !0); | ||
var entry = this.tryEntries[i]; | ||
if (entry.tryLoc <= this.prev && hasOwn.call(entry, "finallyLoc") && this.prev < entry.finallyLoc) { | ||
@@ -325,3 +292,2 @@ var finallyEntry = entry; | ||
} | ||
finallyEntry && ("break" === type || "continue" === type) && finallyEntry.tryLoc <= arg && arg <= finallyEntry.finallyLoc && (finallyEntry = null); | ||
@@ -344,6 +310,4 @@ var record = finallyEntry ? finallyEntry.completion : {}; | ||
var entry = this.tryEntries[i]; | ||
if (entry.tryLoc === tryLoc) { | ||
var record = entry.completion; | ||
if ("throw" === record.type) { | ||
@@ -353,7 +317,5 @@ var thrown = record.arg; | ||
} | ||
return thrown; | ||
} | ||
} | ||
throw new Error("illegal catch attempt"); | ||
@@ -370,3 +332,2 @@ }, | ||
} | ||
function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) { | ||
@@ -380,3 +341,2 @@ try { | ||
} | ||
if (info.done) { | ||
@@ -388,18 +348,14 @@ resolve(value); | ||
} | ||
function _asyncToGenerator(fn) { | ||
return function () { | ||
var self = this, | ||
args = arguments; | ||
args = arguments; | ||
return new Promise(function (resolve, reject) { | ||
var gen = fn.apply(self, args); | ||
function _next(value) { | ||
asyncGeneratorStep(gen, resolve, reject, _next, _throw, "next", value); | ||
} | ||
function _throw(err) { | ||
asyncGeneratorStep(gen, resolve, reject, _next, _throw, "throw", err); | ||
} | ||
_next(undefined); | ||
@@ -409,3 +365,2 @@ }); | ||
} | ||
function _extends() { | ||
@@ -415,3 +370,2 @@ _extends = Object.assign ? Object.assign.bind() : function (target) { | ||
var source = arguments[i]; | ||
for (var key in source) { | ||
@@ -423,3 +377,2 @@ if (Object.prototype.hasOwnProperty.call(source, key)) { | ||
} | ||
return target; | ||
@@ -429,10 +382,7 @@ }; | ||
} | ||
function _inheritsLoose(subClass, superClass) { | ||
subClass.prototype = Object.create(superClass.prototype); | ||
subClass.prototype.constructor = subClass; | ||
_setPrototypeOf(subClass, superClass); | ||
} | ||
function _setPrototypeOf(o, p) { | ||
@@ -451,24 +401,21 @@ _setPrototypeOf = Object.setPrototypeOf ? Object.setPrototypeOf.bind() : function _setPrototypeOf(o, p) { | ||
} | ||
var _proto = DragndropPlugin.prototype; | ||
_proto.apply = function apply(context) { | ||
var renderingService = context.renderingService, | ||
renderingContext = context.renderingContext; | ||
var document = renderingContext.root.ownerDocument; // TODO: should we add an option like `draggable` to Canvas | ||
renderingContext = context.renderingContext; | ||
var document = 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; | ||
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 draggableEventTarget = isDocument && isDocumentDraggable ? document : target.closest && target.closest('[draggable=true]'); // `draggable` may be set on ancestor nodes: | ||
var draggableEventTarget = isDocument && 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) { | ||
@@ -487,6 +434,4 @@ // @ts-ignore | ||
} | ||
timeElapsed = event.timeStamp - dragstartTimeStamp; | ||
distanceMoved = distanceSquareRoot([event.clientX, event.clientY], dragstartClientCoordinates); // check thresholds | ||
if (!(timeElapsed <= dragstartTimeThreshold || distanceMoved <= dragstartDistanceThreshold)) { | ||
@@ -496,5 +441,3 @@ _context.next = 5; | ||
} | ||
return _context.abrupt("return"); | ||
case 5: | ||
@@ -505,13 +448,11 @@ // @see https://developer.mozilla.org/zh-CN/docs/Web/API/Document/dragstart_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.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) { | ||
@@ -521,7 +462,5 @@ _context.next = 21; | ||
} | ||
point = overlap === 'pointer' ? [event.canvasX, event.canvasY] : target.getBounds().center; | ||
_context.next = 17; | ||
return document.elementsFromPoint(point[0], point[1]); | ||
case 17: | ||
@@ -532,3 +471,2 @@ elementsBelow = _context.sent; | ||
droppableBelow = (elementBelow === null || elementBelow === void 0 ? void 0 : elementBelow.closest('[droppable=true]')) || (isDocumentDroppable ? document : null); | ||
if (currentDroppable !== droppableBelow) { | ||
@@ -542,3 +480,2 @@ if (currentDroppable) { | ||
} | ||
if (droppableBelow) { | ||
@@ -550,5 +487,3 @@ // @see https://developer.mozilla.org/zh-CN/docs/Web/API/Document/dragleave_event | ||
} | ||
currentDroppable = droppableBelow; | ||
if (currentDroppable) { | ||
@@ -562,3 +497,2 @@ // null if we're not coming over a droppable now | ||
} | ||
case 21: | ||
@@ -571,3 +505,2 @@ case "end": | ||
})); | ||
return function handlePointermove(_x) { | ||
@@ -577,3 +510,2 @@ return _ref.apply(this, arguments); | ||
}(); | ||
// delay triggering dragstart event | ||
@@ -586,3 +518,2 @@ var dragstartTriggered = false; | ||
canvas.addEventListener('pointermove', handlePointermove); | ||
var stopDragging = function stopDragging(originalPointerUpEvent) { | ||
@@ -594,8 +525,7 @@ if (dragstartTriggered) { | ||
preventClick: true | ||
}; // clone event first | ||
var _event = originalPointerUpEvent.clone(); // drop should fire before dragend | ||
}; | ||
// 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) { | ||
@@ -606,5 +536,4 @@ // @see https://developer.mozilla.org/zh-CN/docs/Web/API/Document/drop_event | ||
currentDroppable.dispatchEvent(_event); | ||
} // @see https://developer.mozilla.org/zh-CN/docs/Web/API/Document/dragend_event | ||
} | ||
// @see https://developer.mozilla.org/zh-CN/docs/Web/API/Document/dragend_event | ||
_event.type = 'dragend'; | ||
@@ -614,6 +543,4 @@ draggableEventTarget.dispatchEvent(_event); | ||
} | ||
canvas.removeEventListener('pointermove', handlePointermove); | ||
}; | ||
target.addEventListener('pointerup', stopDragging, { | ||
@@ -627,3 +554,2 @@ once: true | ||
}; | ||
renderingService.hooks.init.tapPromise(DragndropPlugin.tag, /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee2() { | ||
@@ -635,3 +561,2 @@ return _regeneratorRuntime().wrap(function _callee2$(_context2) { | ||
canvas.addEventListener('pointerdown', handlePointerdown); | ||
case 1: | ||
@@ -648,3 +573,2 @@ case "end": | ||
}; | ||
return DragndropPlugin; | ||
@@ -656,10 +580,7 @@ }(); | ||
_inheritsLoose(Plugin, _AbstractRendererPlug); | ||
function Plugin(options) { | ||
var _this; | ||
if (options === void 0) { | ||
options = {}; | ||
} | ||
_this = _AbstractRendererPlug.call(this) || this; | ||
@@ -671,5 +592,3 @@ _this.options = void 0; | ||
} | ||
var _proto = Plugin.prototype; | ||
_proto.init = function init() { | ||
@@ -684,7 +603,5 @@ this.addRenderingPlugin(new DragndropPlugin(_extends({ | ||
}; | ||
_proto.destroy = function destroy() { | ||
this.removeAllRenderingPlugins(); | ||
}; | ||
return Plugin; | ||
@@ -691,0 +608,0 @@ }(AbstractRendererPlugin); |
@@ -9,16 +9,15 @@ 'use strict'; | ||
function _regeneratorRuntime() { | ||
/*! regenerator-runtime -- Copyright (c) 2014-present, Facebook, Inc. -- license (MIT): https://github.com/facebook/regenerator/blob/main/LICENSE */ | ||
_regeneratorRuntime = function () { | ||
return exports; | ||
}; | ||
var exports = {}, | ||
Op = Object.prototype, | ||
hasOwn = Op.hasOwnProperty, | ||
$Symbol = "function" == typeof Symbol ? Symbol : {}, | ||
iteratorSymbol = $Symbol.iterator || "@@iterator", | ||
asyncIteratorSymbol = $Symbol.asyncIterator || "@@asyncIterator", | ||
toStringTagSymbol = $Symbol.toStringTag || "@@toStringTag"; | ||
Op = Object.prototype, | ||
hasOwn = Op.hasOwnProperty, | ||
defineProperty = Object.defineProperty || function (obj, key, desc) { | ||
obj[key] = desc.value; | ||
}, | ||
$Symbol = "function" == typeof Symbol ? Symbol : {}, | ||
iteratorSymbol = $Symbol.iterator || "@@iterator", | ||
asyncIteratorSymbol = $Symbol.asyncIterator || "@@asyncIterator", | ||
toStringTagSymbol = $Symbol.toStringTag || "@@toStringTag"; | ||
function define(obj, key, value) { | ||
@@ -32,3 +31,2 @@ return Object.defineProperty(obj, key, { | ||
} | ||
try { | ||
@@ -41,50 +39,10 @@ define({}, ""); | ||
} | ||
function wrap(innerFn, outerFn, self, tryLocsList) { | ||
var protoGenerator = outerFn && outerFn.prototype instanceof Generator ? outerFn : Generator, | ||
generator = Object.create(protoGenerator.prototype), | ||
context = new Context(tryLocsList || []); | ||
return generator._invoke = function (innerFn, self, context) { | ||
var state = "suspendedStart"; | ||
return function (method, arg) { | ||
if ("executing" === state) throw new Error("Generator is already running"); | ||
if ("completed" === state) { | ||
if ("throw" === method) throw arg; | ||
return doneResult(); | ||
} | ||
for (context.method = method, context.arg = arg;;) { | ||
var delegate = context.delegate; | ||
if (delegate) { | ||
var delegateResult = maybeInvokeDelegate(delegate, context); | ||
if (delegateResult) { | ||
if (delegateResult === ContinueSentinel) continue; | ||
return delegateResult; | ||
} | ||
} | ||
if ("next" === context.method) context.sent = context._sent = context.arg;else if ("throw" === context.method) { | ||
if ("suspendedStart" === state) throw state = "completed", context.arg; | ||
context.dispatchException(context.arg); | ||
} else "return" === context.method && context.abrupt("return", context.arg); | ||
state = "executing"; | ||
var record = tryCatch(innerFn, self, context); | ||
if ("normal" === record.type) { | ||
if (state = context.done ? "completed" : "suspendedYield", record.arg === ContinueSentinel) continue; | ||
return { | ||
value: record.arg, | ||
done: context.done | ||
}; | ||
} | ||
"throw" === record.type && (state = "completed", context.method = "throw", context.arg = record.arg); | ||
} | ||
}; | ||
}(innerFn, self, context), generator; | ||
generator = Object.create(protoGenerator.prototype), | ||
context = new Context(tryLocsList || []); | ||
return defineProperty(generator, "_invoke", { | ||
value: makeInvokeMethod(innerFn, self, context) | ||
}), generator; | ||
} | ||
function tryCatch(fn, obj, arg) { | ||
@@ -103,12 +61,7 @@ try { | ||
} | ||
exports.wrap = wrap; | ||
var ContinueSentinel = {}; | ||
function Generator() {} | ||
function GeneratorFunction() {} | ||
function GeneratorFunctionPrototype() {} | ||
var IteratorPrototype = {}; | ||
@@ -119,6 +72,5 @@ define(IteratorPrototype, iteratorSymbol, function () { | ||
var getProto = Object.getPrototypeOf, | ||
NativeIteratorPrototype = getProto && getProto(getProto(values([]))); | ||
NativeIteratorPrototype = getProto && getProto(getProto(values([]))); | ||
NativeIteratorPrototype && NativeIteratorPrototype !== Op && hasOwn.call(NativeIteratorPrototype, iteratorSymbol) && (IteratorPrototype = NativeIteratorPrototype); | ||
var Gp = GeneratorFunctionPrototype.prototype = Generator.prototype = Object.create(IteratorPrototype); | ||
function defineIteratorMethods(prototype) { | ||
@@ -131,10 +83,8 @@ ["next", "throw", "return"].forEach(function (method) { | ||
} | ||
function AsyncIterator(generator, PromiseImpl) { | ||
function invoke(method, arg, resolve, reject) { | ||
var record = tryCatch(generator[method], generator, arg); | ||
if ("throw" !== record.type) { | ||
var result = record.arg, | ||
value = result.value; | ||
value = result.value; | ||
return value && "object" == typeof value && hasOwn.call(value, "__await") ? PromiseImpl.resolve(value.__await).then(function (value) { | ||
@@ -150,22 +100,52 @@ invoke("next", value, resolve, reject); | ||
} | ||
reject(record.arg); | ||
} | ||
var previousPromise; | ||
this._invoke = function (method, arg) { | ||
function callInvokeWithMethodAndArg() { | ||
return new PromiseImpl(function (resolve, reject) { | ||
invoke(method, arg, resolve, reject); | ||
}); | ||
defineProperty(this, "_invoke", { | ||
value: function (method, arg) { | ||
function callInvokeWithMethodAndArg() { | ||
return new PromiseImpl(function (resolve, reject) { | ||
invoke(method, arg, resolve, reject); | ||
}); | ||
} | ||
return previousPromise = previousPromise ? previousPromise.then(callInvokeWithMethodAndArg, callInvokeWithMethodAndArg) : callInvokeWithMethodAndArg(); | ||
} | ||
return previousPromise = previousPromise ? previousPromise.then(callInvokeWithMethodAndArg, callInvokeWithMethodAndArg) : callInvokeWithMethodAndArg(); | ||
}); | ||
} | ||
function makeInvokeMethod(innerFn, self, context) { | ||
var state = "suspendedStart"; | ||
return function (method, arg) { | ||
if ("executing" === state) throw new Error("Generator is already running"); | ||
if ("completed" === state) { | ||
if ("throw" === method) throw arg; | ||
return doneResult(); | ||
} | ||
for (context.method = method, context.arg = arg;;) { | ||
var delegate = context.delegate; | ||
if (delegate) { | ||
var delegateResult = maybeInvokeDelegate(delegate, context); | ||
if (delegateResult) { | ||
if (delegateResult === ContinueSentinel) continue; | ||
return delegateResult; | ||
} | ||
} | ||
if ("next" === context.method) context.sent = context._sent = context.arg;else if ("throw" === context.method) { | ||
if ("suspendedStart" === state) throw state = "completed", context.arg; | ||
context.dispatchException(context.arg); | ||
} else "return" === context.method && context.abrupt("return", context.arg); | ||
state = "executing"; | ||
var record = tryCatch(innerFn, self, context); | ||
if ("normal" === record.type) { | ||
if (state = context.done ? "completed" : "suspendedYield", record.arg === ContinueSentinel) continue; | ||
return { | ||
value: record.arg, | ||
done: context.done | ||
}; | ||
} | ||
"throw" === record.type && (state = "completed", context.method = "throw", context.arg = record.arg); | ||
} | ||
}; | ||
} | ||
function maybeInvokeDelegate(delegate, context) { | ||
var method = delegate.iterator[context.method]; | ||
if (undefined === method) { | ||
@@ -176,6 +156,4 @@ if (context.delegate = null, "throw" === context.method) { | ||
} | ||
return ContinueSentinel; | ||
} | ||
var record = tryCatch(method, delegate.iterator, context.arg); | ||
@@ -186,3 +164,2 @@ if ("throw" === record.type) return context.method = "throw", context.arg = record.arg, context.delegate = null, ContinueSentinel; | ||
} | ||
function pushTryEntry(locs) { | ||
@@ -194,3 +171,2 @@ var entry = { | ||
} | ||
function resetTryEntry(entry) { | ||
@@ -200,3 +176,2 @@ var record = entry.completion || {}; | ||
} | ||
function Context(tryLocsList) { | ||
@@ -207,3 +182,2 @@ this.tryEntries = [{ | ||
} | ||
function values(iterable) { | ||
@@ -214,15 +188,11 @@ if (iterable) { | ||
if ("function" == typeof iterable.next) return iterable; | ||
if (!isNaN(iterable.length)) { | ||
var i = -1, | ||
next = function next() { | ||
for (; ++i < iterable.length;) if (hasOwn.call(iterable, i)) return next.value = iterable[i], next.done = !1, next; | ||
return next.value = undefined, next.done = !0, next; | ||
}; | ||
next = function next() { | ||
for (; ++i < iterable.length;) if (hasOwn.call(iterable, i)) return next.value = iterable[i], next.done = !1, next; | ||
return next.value = undefined, next.done = !0, next; | ||
}; | ||
return next.next = next; | ||
} | ||
} | ||
return { | ||
@@ -232,3 +202,2 @@ next: doneResult | ||
} | ||
function doneResult() { | ||
@@ -240,4 +209,9 @@ return { | ||
} | ||
return GeneratorFunction.prototype = GeneratorFunctionPrototype, define(Gp, "constructor", GeneratorFunctionPrototype), define(GeneratorFunctionPrototype, "constructor", GeneratorFunction), GeneratorFunction.displayName = define(GeneratorFunctionPrototype, toStringTagSymbol, "GeneratorFunction"), exports.isGeneratorFunction = function (genFun) { | ||
return GeneratorFunction.prototype = GeneratorFunctionPrototype, defineProperty(Gp, "constructor", { | ||
value: GeneratorFunctionPrototype, | ||
configurable: !0 | ||
}), defineProperty(GeneratorFunctionPrototype, "constructor", { | ||
value: GeneratorFunction, | ||
configurable: !0 | ||
}), GeneratorFunction.displayName = define(GeneratorFunctionPrototype, toStringTagSymbol, "GeneratorFunction"), exports.isGeneratorFunction = function (genFun) { | ||
var ctor = "function" == typeof genFun && genFun.constructor; | ||
@@ -263,7 +237,6 @@ return !!ctor && (ctor === GeneratorFunction || "GeneratorFunction" === (ctor.displayName || ctor.name)); | ||
return "[object Generator]"; | ||
}), exports.keys = function (object) { | ||
var keys = []; | ||
}), exports.keys = function (val) { | ||
var object = Object(val), | ||
keys = []; | ||
for (var key in object) keys.push(key); | ||
return keys.reverse(), function next() { | ||
@@ -274,3 +247,2 @@ for (; keys.length;) { | ||
} | ||
return next.done = !0, next; | ||
@@ -292,16 +264,12 @@ }; | ||
var context = this; | ||
function handle(loc, caught) { | ||
return record.type = "throw", record.arg = exception, context.next = loc, caught && (context.method = "next", context.arg = undefined), !!caught; | ||
} | ||
for (var i = this.tryEntries.length - 1; i >= 0; --i) { | ||
var entry = this.tryEntries[i], | ||
record = entry.completion; | ||
record = entry.completion; | ||
if ("root" === entry.tryLoc) return handle("end"); | ||
if (entry.tryLoc <= this.prev) { | ||
var hasCatch = hasOwn.call(entry, "catchLoc"), | ||
hasFinally = hasOwn.call(entry, "finallyLoc"); | ||
hasFinally = hasOwn.call(entry, "finallyLoc"); | ||
if (hasCatch && hasFinally) { | ||
@@ -322,3 +290,2 @@ if (this.prev < entry.catchLoc) return handle(entry.catchLoc, !0); | ||
var entry = this.tryEntries[i]; | ||
if (entry.tryLoc <= this.prev && hasOwn.call(entry, "finallyLoc") && this.prev < entry.finallyLoc) { | ||
@@ -329,3 +296,2 @@ var finallyEntry = entry; | ||
} | ||
finallyEntry && ("break" === type || "continue" === type) && finallyEntry.tryLoc <= arg && arg <= finallyEntry.finallyLoc && (finallyEntry = null); | ||
@@ -348,6 +314,4 @@ var record = finallyEntry ? finallyEntry.completion : {}; | ||
var entry = this.tryEntries[i]; | ||
if (entry.tryLoc === tryLoc) { | ||
var record = entry.completion; | ||
if ("throw" === record.type) { | ||
@@ -357,7 +321,5 @@ var thrown = record.arg; | ||
} | ||
return thrown; | ||
} | ||
} | ||
throw new Error("illegal catch attempt"); | ||
@@ -374,3 +336,2 @@ }, | ||
} | ||
function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) { | ||
@@ -384,3 +345,2 @@ try { | ||
} | ||
if (info.done) { | ||
@@ -392,18 +352,14 @@ resolve(value); | ||
} | ||
function _asyncToGenerator(fn) { | ||
return function () { | ||
var self = this, | ||
args = arguments; | ||
args = arguments; | ||
return new Promise(function (resolve, reject) { | ||
var gen = fn.apply(self, args); | ||
function _next(value) { | ||
asyncGeneratorStep(gen, resolve, reject, _next, _throw, "next", value); | ||
} | ||
function _throw(err) { | ||
asyncGeneratorStep(gen, resolve, reject, _next, _throw, "throw", err); | ||
} | ||
_next(undefined); | ||
@@ -413,3 +369,2 @@ }); | ||
} | ||
function _extends() { | ||
@@ -419,3 +374,2 @@ _extends = Object.assign ? Object.assign.bind() : function (target) { | ||
var source = arguments[i]; | ||
for (var key in source) { | ||
@@ -427,3 +381,2 @@ if (Object.prototype.hasOwnProperty.call(source, key)) { | ||
} | ||
return target; | ||
@@ -433,10 +386,7 @@ }; | ||
} | ||
function _inheritsLoose(subClass, superClass) { | ||
subClass.prototype = Object.create(superClass.prototype); | ||
subClass.prototype.constructor = subClass; | ||
_setPrototypeOf(subClass, superClass); | ||
} | ||
function _setPrototypeOf(o, p) { | ||
@@ -455,24 +405,21 @@ _setPrototypeOf = Object.setPrototypeOf ? Object.setPrototypeOf.bind() : function _setPrototypeOf(o, p) { | ||
} | ||
var _proto = DragndropPlugin.prototype; | ||
_proto.apply = function apply(context) { | ||
var renderingService = context.renderingService, | ||
renderingContext = context.renderingContext; | ||
var document = renderingContext.root.ownerDocument; // TODO: should we add an option like `draggable` to Canvas | ||
renderingContext = context.renderingContext; | ||
var document = 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; | ||
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 draggableEventTarget = isDocument && isDocumentDraggable ? document : target.closest && target.closest('[draggable=true]'); // `draggable` may be set on ancestor nodes: | ||
var draggableEventTarget = isDocument && 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) { | ||
@@ -491,6 +438,4 @@ // @ts-ignore | ||
} | ||
timeElapsed = event.timeStamp - dragstartTimeStamp; | ||
distanceMoved = util.distanceSquareRoot([event.clientX, event.clientY], dragstartClientCoordinates); // check thresholds | ||
if (!(timeElapsed <= dragstartTimeThreshold || distanceMoved <= dragstartDistanceThreshold)) { | ||
@@ -500,5 +445,3 @@ _context.next = 5; | ||
} | ||
return _context.abrupt("return"); | ||
case 5: | ||
@@ -509,13 +452,11 @@ // @see https://developer.mozilla.org/zh-CN/docs/Web/API/Document/dragstart_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.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) { | ||
@@ -525,7 +466,5 @@ _context.next = 21; | ||
} | ||
point = overlap === 'pointer' ? [event.canvasX, event.canvasY] : target.getBounds().center; | ||
_context.next = 17; | ||
return document.elementsFromPoint(point[0], point[1]); | ||
case 17: | ||
@@ -536,3 +475,2 @@ elementsBelow = _context.sent; | ||
droppableBelow = (elementBelow === null || elementBelow === void 0 ? void 0 : elementBelow.closest('[droppable=true]')) || (isDocumentDroppable ? document : null); | ||
if (currentDroppable !== droppableBelow) { | ||
@@ -546,3 +484,2 @@ if (currentDroppable) { | ||
} | ||
if (droppableBelow) { | ||
@@ -554,5 +491,3 @@ // @see https://developer.mozilla.org/zh-CN/docs/Web/API/Document/dragleave_event | ||
} | ||
currentDroppable = droppableBelow; | ||
if (currentDroppable) { | ||
@@ -566,3 +501,2 @@ // null if we're not coming over a droppable now | ||
} | ||
case 21: | ||
@@ -575,3 +509,2 @@ case "end": | ||
})); | ||
return function handlePointermove(_x) { | ||
@@ -581,3 +514,2 @@ return _ref.apply(this, arguments); | ||
}(); | ||
// delay triggering dragstart event | ||
@@ -590,3 +522,2 @@ var dragstartTriggered = false; | ||
canvas.addEventListener('pointermove', handlePointermove); | ||
var stopDragging = function stopDragging(originalPointerUpEvent) { | ||
@@ -598,8 +529,7 @@ if (dragstartTriggered) { | ||
preventClick: true | ||
}; // clone event first | ||
var _event = originalPointerUpEvent.clone(); // drop should fire before dragend | ||
}; | ||
// 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) { | ||
@@ -610,5 +540,4 @@ // @see https://developer.mozilla.org/zh-CN/docs/Web/API/Document/drop_event | ||
currentDroppable.dispatchEvent(_event); | ||
} // @see https://developer.mozilla.org/zh-CN/docs/Web/API/Document/dragend_event | ||
} | ||
// @see https://developer.mozilla.org/zh-CN/docs/Web/API/Document/dragend_event | ||
_event.type = 'dragend'; | ||
@@ -618,6 +547,4 @@ draggableEventTarget.dispatchEvent(_event); | ||
} | ||
canvas.removeEventListener('pointermove', handlePointermove); | ||
}; | ||
target.addEventListener('pointerup', stopDragging, { | ||
@@ -631,3 +558,2 @@ once: true | ||
}; | ||
renderingService.hooks.init.tapPromise(DragndropPlugin.tag, /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee2() { | ||
@@ -639,3 +565,2 @@ return _regeneratorRuntime().wrap(function _callee2$(_context2) { | ||
canvas.addEventListener('pointerdown', handlePointerdown); | ||
case 1: | ||
@@ -652,3 +577,2 @@ case "end": | ||
}; | ||
return DragndropPlugin; | ||
@@ -660,10 +584,7 @@ }(); | ||
_inheritsLoose(Plugin, _AbstractRendererPlug); | ||
function Plugin(options) { | ||
var _this; | ||
if (options === void 0) { | ||
options = {}; | ||
} | ||
_this = _AbstractRendererPlug.call(this) || this; | ||
@@ -675,5 +596,3 @@ _this.options = void 0; | ||
} | ||
var _proto = Plugin.prototype; | ||
_proto.init = function init() { | ||
@@ -688,7 +607,5 @@ this.addRenderingPlugin(new DragndropPlugin(_extends({ | ||
}; | ||
_proto.destroy = function destroy() { | ||
this.removeAllRenderingPlugins(); | ||
}; | ||
return Plugin; | ||
@@ -695,0 +612,0 @@ }(gLite.AbstractRendererPlugin); |
@@ -8,16 +8,15 @@ (function (global, factory) { | ||
function _regeneratorRuntime() { | ||
/*! regenerator-runtime -- Copyright (c) 2014-present, Facebook, Inc. -- license (MIT): https://github.com/facebook/regenerator/blob/main/LICENSE */ | ||
_regeneratorRuntime = function () { | ||
return exports; | ||
}; | ||
var exports = {}, | ||
Op = Object.prototype, | ||
hasOwn = Op.hasOwnProperty, | ||
$Symbol = "function" == typeof Symbol ? Symbol : {}, | ||
iteratorSymbol = $Symbol.iterator || "@@iterator", | ||
asyncIteratorSymbol = $Symbol.asyncIterator || "@@asyncIterator", | ||
toStringTagSymbol = $Symbol.toStringTag || "@@toStringTag"; | ||
Op = Object.prototype, | ||
hasOwn = Op.hasOwnProperty, | ||
defineProperty = Object.defineProperty || function (obj, key, desc) { | ||
obj[key] = desc.value; | ||
}, | ||
$Symbol = "function" == typeof Symbol ? Symbol : {}, | ||
iteratorSymbol = $Symbol.iterator || "@@iterator", | ||
asyncIteratorSymbol = $Symbol.asyncIterator || "@@asyncIterator", | ||
toStringTagSymbol = $Symbol.toStringTag || "@@toStringTag"; | ||
function define(obj, key, value) { | ||
@@ -31,3 +30,2 @@ return Object.defineProperty(obj, key, { | ||
} | ||
try { | ||
@@ -40,50 +38,10 @@ define({}, ""); | ||
} | ||
function wrap(innerFn, outerFn, self, tryLocsList) { | ||
var protoGenerator = outerFn && outerFn.prototype instanceof Generator ? outerFn : Generator, | ||
generator = Object.create(protoGenerator.prototype), | ||
context = new Context(tryLocsList || []); | ||
return generator._invoke = function (innerFn, self, context) { | ||
var state = "suspendedStart"; | ||
return function (method, arg) { | ||
if ("executing" === state) throw new Error("Generator is already running"); | ||
if ("completed" === state) { | ||
if ("throw" === method) throw arg; | ||
return doneResult(); | ||
} | ||
for (context.method = method, context.arg = arg;;) { | ||
var delegate = context.delegate; | ||
if (delegate) { | ||
var delegateResult = maybeInvokeDelegate(delegate, context); | ||
if (delegateResult) { | ||
if (delegateResult === ContinueSentinel) continue; | ||
return delegateResult; | ||
} | ||
} | ||
if ("next" === context.method) context.sent = context._sent = context.arg;else if ("throw" === context.method) { | ||
if ("suspendedStart" === state) throw state = "completed", context.arg; | ||
context.dispatchException(context.arg); | ||
} else "return" === context.method && context.abrupt("return", context.arg); | ||
state = "executing"; | ||
var record = tryCatch(innerFn, self, context); | ||
if ("normal" === record.type) { | ||
if (state = context.done ? "completed" : "suspendedYield", record.arg === ContinueSentinel) continue; | ||
return { | ||
value: record.arg, | ||
done: context.done | ||
}; | ||
} | ||
"throw" === record.type && (state = "completed", context.method = "throw", context.arg = record.arg); | ||
} | ||
}; | ||
}(innerFn, self, context), generator; | ||
generator = Object.create(protoGenerator.prototype), | ||
context = new Context(tryLocsList || []); | ||
return defineProperty(generator, "_invoke", { | ||
value: makeInvokeMethod(innerFn, self, context) | ||
}), generator; | ||
} | ||
function tryCatch(fn, obj, arg) { | ||
@@ -102,12 +60,7 @@ try { | ||
} | ||
exports.wrap = wrap; | ||
var ContinueSentinel = {}; | ||
function Generator() {} | ||
function GeneratorFunction() {} | ||
function GeneratorFunctionPrototype() {} | ||
var IteratorPrototype = {}; | ||
@@ -118,6 +71,5 @@ define(IteratorPrototype, iteratorSymbol, function () { | ||
var getProto = Object.getPrototypeOf, | ||
NativeIteratorPrototype = getProto && getProto(getProto(values([]))); | ||
NativeIteratorPrototype = getProto && getProto(getProto(values([]))); | ||
NativeIteratorPrototype && NativeIteratorPrototype !== Op && hasOwn.call(NativeIteratorPrototype, iteratorSymbol) && (IteratorPrototype = NativeIteratorPrototype); | ||
var Gp = GeneratorFunctionPrototype.prototype = Generator.prototype = Object.create(IteratorPrototype); | ||
function defineIteratorMethods(prototype) { | ||
@@ -130,10 +82,8 @@ ["next", "throw", "return"].forEach(function (method) { | ||
} | ||
function AsyncIterator(generator, PromiseImpl) { | ||
function invoke(method, arg, resolve, reject) { | ||
var record = tryCatch(generator[method], generator, arg); | ||
if ("throw" !== record.type) { | ||
var result = record.arg, | ||
value = result.value; | ||
value = result.value; | ||
return value && "object" == typeof value && hasOwn.call(value, "__await") ? PromiseImpl.resolve(value.__await).then(function (value) { | ||
@@ -149,22 +99,52 @@ invoke("next", value, resolve, reject); | ||
} | ||
reject(record.arg); | ||
} | ||
var previousPromise; | ||
this._invoke = function (method, arg) { | ||
function callInvokeWithMethodAndArg() { | ||
return new PromiseImpl(function (resolve, reject) { | ||
invoke(method, arg, resolve, reject); | ||
}); | ||
defineProperty(this, "_invoke", { | ||
value: function (method, arg) { | ||
function callInvokeWithMethodAndArg() { | ||
return new PromiseImpl(function (resolve, reject) { | ||
invoke(method, arg, resolve, reject); | ||
}); | ||
} | ||
return previousPromise = previousPromise ? previousPromise.then(callInvokeWithMethodAndArg, callInvokeWithMethodAndArg) : callInvokeWithMethodAndArg(); | ||
} | ||
return previousPromise = previousPromise ? previousPromise.then(callInvokeWithMethodAndArg, callInvokeWithMethodAndArg) : callInvokeWithMethodAndArg(); | ||
}); | ||
} | ||
function makeInvokeMethod(innerFn, self, context) { | ||
var state = "suspendedStart"; | ||
return function (method, arg) { | ||
if ("executing" === state) throw new Error("Generator is already running"); | ||
if ("completed" === state) { | ||
if ("throw" === method) throw arg; | ||
return doneResult(); | ||
} | ||
for (context.method = method, context.arg = arg;;) { | ||
var delegate = context.delegate; | ||
if (delegate) { | ||
var delegateResult = maybeInvokeDelegate(delegate, context); | ||
if (delegateResult) { | ||
if (delegateResult === ContinueSentinel) continue; | ||
return delegateResult; | ||
} | ||
} | ||
if ("next" === context.method) context.sent = context._sent = context.arg;else if ("throw" === context.method) { | ||
if ("suspendedStart" === state) throw state = "completed", context.arg; | ||
context.dispatchException(context.arg); | ||
} else "return" === context.method && context.abrupt("return", context.arg); | ||
state = "executing"; | ||
var record = tryCatch(innerFn, self, context); | ||
if ("normal" === record.type) { | ||
if (state = context.done ? "completed" : "suspendedYield", record.arg === ContinueSentinel) continue; | ||
return { | ||
value: record.arg, | ||
done: context.done | ||
}; | ||
} | ||
"throw" === record.type && (state = "completed", context.method = "throw", context.arg = record.arg); | ||
} | ||
}; | ||
} | ||
function maybeInvokeDelegate(delegate, context) { | ||
var method = delegate.iterator[context.method]; | ||
if (undefined === method) { | ||
@@ -175,6 +155,4 @@ if (context.delegate = null, "throw" === context.method) { | ||
} | ||
return ContinueSentinel; | ||
} | ||
var record = tryCatch(method, delegate.iterator, context.arg); | ||
@@ -185,3 +163,2 @@ if ("throw" === record.type) return context.method = "throw", context.arg = record.arg, context.delegate = null, ContinueSentinel; | ||
} | ||
function pushTryEntry(locs) { | ||
@@ -193,3 +170,2 @@ var entry = { | ||
} | ||
function resetTryEntry(entry) { | ||
@@ -199,3 +175,2 @@ var record = entry.completion || {}; | ||
} | ||
function Context(tryLocsList) { | ||
@@ -206,3 +181,2 @@ this.tryEntries = [{ | ||
} | ||
function values(iterable) { | ||
@@ -213,15 +187,11 @@ if (iterable) { | ||
if ("function" == typeof iterable.next) return iterable; | ||
if (!isNaN(iterable.length)) { | ||
var i = -1, | ||
next = function next() { | ||
for (; ++i < iterable.length;) if (hasOwn.call(iterable, i)) return next.value = iterable[i], next.done = !1, next; | ||
return next.value = undefined, next.done = !0, next; | ||
}; | ||
next = function next() { | ||
for (; ++i < iterable.length;) if (hasOwn.call(iterable, i)) return next.value = iterable[i], next.done = !1, next; | ||
return next.value = undefined, next.done = !0, next; | ||
}; | ||
return next.next = next; | ||
} | ||
} | ||
return { | ||
@@ -231,3 +201,2 @@ next: doneResult | ||
} | ||
function doneResult() { | ||
@@ -239,4 +208,9 @@ return { | ||
} | ||
return GeneratorFunction.prototype = GeneratorFunctionPrototype, define(Gp, "constructor", GeneratorFunctionPrototype), define(GeneratorFunctionPrototype, "constructor", GeneratorFunction), GeneratorFunction.displayName = define(GeneratorFunctionPrototype, toStringTagSymbol, "GeneratorFunction"), exports.isGeneratorFunction = function (genFun) { | ||
return GeneratorFunction.prototype = GeneratorFunctionPrototype, defineProperty(Gp, "constructor", { | ||
value: GeneratorFunctionPrototype, | ||
configurable: !0 | ||
}), defineProperty(GeneratorFunctionPrototype, "constructor", { | ||
value: GeneratorFunction, | ||
configurable: !0 | ||
}), GeneratorFunction.displayName = define(GeneratorFunctionPrototype, toStringTagSymbol, "GeneratorFunction"), exports.isGeneratorFunction = function (genFun) { | ||
var ctor = "function" == typeof genFun && genFun.constructor; | ||
@@ -262,7 +236,6 @@ return !!ctor && (ctor === GeneratorFunction || "GeneratorFunction" === (ctor.displayName || ctor.name)); | ||
return "[object Generator]"; | ||
}), exports.keys = function (object) { | ||
var keys = []; | ||
}), exports.keys = function (val) { | ||
var object = Object(val), | ||
keys = []; | ||
for (var key in object) keys.push(key); | ||
return keys.reverse(), function next() { | ||
@@ -273,3 +246,2 @@ for (; keys.length;) { | ||
} | ||
return next.done = !0, next; | ||
@@ -291,16 +263,12 @@ }; | ||
var context = this; | ||
function handle(loc, caught) { | ||
return record.type = "throw", record.arg = exception, context.next = loc, caught && (context.method = "next", context.arg = undefined), !!caught; | ||
} | ||
for (var i = this.tryEntries.length - 1; i >= 0; --i) { | ||
var entry = this.tryEntries[i], | ||
record = entry.completion; | ||
record = entry.completion; | ||
if ("root" === entry.tryLoc) return handle("end"); | ||
if (entry.tryLoc <= this.prev) { | ||
var hasCatch = hasOwn.call(entry, "catchLoc"), | ||
hasFinally = hasOwn.call(entry, "finallyLoc"); | ||
hasFinally = hasOwn.call(entry, "finallyLoc"); | ||
if (hasCatch && hasFinally) { | ||
@@ -321,3 +289,2 @@ if (this.prev < entry.catchLoc) return handle(entry.catchLoc, !0); | ||
var entry = this.tryEntries[i]; | ||
if (entry.tryLoc <= this.prev && hasOwn.call(entry, "finallyLoc") && this.prev < entry.finallyLoc) { | ||
@@ -328,3 +295,2 @@ var finallyEntry = entry; | ||
} | ||
finallyEntry && ("break" === type || "continue" === type) && finallyEntry.tryLoc <= arg && arg <= finallyEntry.finallyLoc && (finallyEntry = null); | ||
@@ -347,6 +313,4 @@ var record = finallyEntry ? finallyEntry.completion : {}; | ||
var entry = this.tryEntries[i]; | ||
if (entry.tryLoc === tryLoc) { | ||
var record = entry.completion; | ||
if ("throw" === record.type) { | ||
@@ -356,7 +320,5 @@ var thrown = record.arg; | ||
} | ||
return thrown; | ||
} | ||
} | ||
throw new Error("illegal catch attempt"); | ||
@@ -373,3 +335,2 @@ }, | ||
} | ||
function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) { | ||
@@ -383,3 +344,2 @@ try { | ||
} | ||
if (info.done) { | ||
@@ -391,18 +351,14 @@ resolve(value); | ||
} | ||
function _asyncToGenerator(fn) { | ||
return function () { | ||
var self = this, | ||
args = arguments; | ||
args = arguments; | ||
return new Promise(function (resolve, reject) { | ||
var gen = fn.apply(self, args); | ||
function _next(value) { | ||
asyncGeneratorStep(gen, resolve, reject, _next, _throw, "next", value); | ||
} | ||
function _throw(err) { | ||
asyncGeneratorStep(gen, resolve, reject, _next, _throw, "throw", err); | ||
} | ||
_next(undefined); | ||
@@ -412,3 +368,2 @@ }); | ||
} | ||
function _extends() { | ||
@@ -418,3 +373,2 @@ _extends = Object.assign ? Object.assign.bind() : function (target) { | ||
var source = arguments[i]; | ||
for (var key in source) { | ||
@@ -426,3 +380,2 @@ if (Object.prototype.hasOwnProperty.call(source, key)) { | ||
} | ||
return target; | ||
@@ -432,10 +385,7 @@ }; | ||
} | ||
function _inheritsLoose(subClass, superClass) { | ||
subClass.prototype = Object.create(superClass.prototype); | ||
subClass.prototype.constructor = subClass; | ||
_setPrototypeOf(subClass, superClass); | ||
} | ||
function _setPrototypeOf(o, p) { | ||
@@ -458,24 +408,21 @@ _setPrototypeOf = Object.setPrototypeOf ? Object.setPrototypeOf.bind() : function _setPrototypeOf(o, p) { | ||
} | ||
var _proto = DragndropPlugin.prototype; | ||
_proto.apply = function apply(context) { | ||
var renderingService = context.renderingService, | ||
renderingContext = context.renderingContext; | ||
var document = renderingContext.root.ownerDocument; // TODO: should we add an option like `draggable` to Canvas | ||
renderingContext = context.renderingContext; | ||
var document = 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; | ||
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 draggableEventTarget = isDocument && isDocumentDraggable ? document : target.closest && target.closest('[draggable=true]'); // `draggable` may be set on ancestor nodes: | ||
var draggableEventTarget = isDocument && 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) { | ||
@@ -494,6 +441,4 @@ // @ts-ignore | ||
} | ||
timeElapsed = event.timeStamp - dragstartTimeStamp; | ||
distanceMoved = distanceSquareRoot([event.clientX, event.clientY], dragstartClientCoordinates); // check thresholds | ||
if (!(timeElapsed <= dragstartTimeThreshold || distanceMoved <= dragstartDistanceThreshold)) { | ||
@@ -503,5 +448,3 @@ _context.next = 5; | ||
} | ||
return _context.abrupt("return"); | ||
case 5: | ||
@@ -512,13 +455,11 @@ // @see https://developer.mozilla.org/zh-CN/docs/Web/API/Document/dragstart_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.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) { | ||
@@ -528,7 +469,5 @@ _context.next = 21; | ||
} | ||
point = overlap === 'pointer' ? [event.canvasX, event.canvasY] : target.getBounds().center; | ||
_context.next = 17; | ||
return document.elementsFromPoint(point[0], point[1]); | ||
case 17: | ||
@@ -539,3 +478,2 @@ elementsBelow = _context.sent; | ||
droppableBelow = (elementBelow === null || elementBelow === void 0 ? void 0 : elementBelow.closest('[droppable=true]')) || (isDocumentDroppable ? document : null); | ||
if (currentDroppable !== droppableBelow) { | ||
@@ -549,3 +487,2 @@ if (currentDroppable) { | ||
} | ||
if (droppableBelow) { | ||
@@ -557,5 +494,3 @@ // @see https://developer.mozilla.org/zh-CN/docs/Web/API/Document/dragleave_event | ||
} | ||
currentDroppable = droppableBelow; | ||
if (currentDroppable) { | ||
@@ -569,3 +504,2 @@ // null if we're not coming over a droppable now | ||
} | ||
case 21: | ||
@@ -578,3 +512,2 @@ case "end": | ||
})); | ||
return function handlePointermove(_x) { | ||
@@ -584,3 +517,2 @@ return _ref.apply(this, arguments); | ||
}(); | ||
// delay triggering dragstart event | ||
@@ -593,3 +525,2 @@ var dragstartTriggered = false; | ||
canvas.addEventListener('pointermove', handlePointermove); | ||
var stopDragging = function stopDragging(originalPointerUpEvent) { | ||
@@ -601,8 +532,7 @@ if (dragstartTriggered) { | ||
preventClick: true | ||
}; // clone event first | ||
var _event = originalPointerUpEvent.clone(); // drop should fire before dragend | ||
}; | ||
// 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) { | ||
@@ -613,5 +543,4 @@ // @see https://developer.mozilla.org/zh-CN/docs/Web/API/Document/drop_event | ||
currentDroppable.dispatchEvent(_event); | ||
} // @see https://developer.mozilla.org/zh-CN/docs/Web/API/Document/dragend_event | ||
} | ||
// @see https://developer.mozilla.org/zh-CN/docs/Web/API/Document/dragend_event | ||
_event.type = 'dragend'; | ||
@@ -621,6 +550,4 @@ draggableEventTarget.dispatchEvent(_event); | ||
} | ||
canvas.removeEventListener('pointermove', handlePointermove); | ||
}; | ||
target.addEventListener('pointerup', stopDragging, { | ||
@@ -634,3 +561,2 @@ once: true | ||
}; | ||
renderingService.hooks.init.tapPromise(DragndropPlugin.tag, /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee2() { | ||
@@ -642,3 +568,2 @@ return _regeneratorRuntime().wrap(function _callee2$(_context2) { | ||
canvas.addEventListener('pointerdown', handlePointerdown); | ||
case 1: | ||
@@ -655,3 +580,2 @@ case "end": | ||
}; | ||
return DragndropPlugin; | ||
@@ -663,10 +587,7 @@ }(); | ||
_inheritsLoose(Plugin, _AbstractRendererPlug); | ||
function Plugin(options) { | ||
var _this; | ||
if (options === void 0) { | ||
options = {}; | ||
} | ||
_this = _AbstractRendererPlug.call(this) || this; | ||
@@ -678,5 +599,3 @@ _this.options = void 0; | ||
} | ||
var _proto = Plugin.prototype; | ||
_proto.init = function init() { | ||
@@ -691,7 +610,5 @@ this.addRenderingPlugin(new DragndropPlugin(_extends({ | ||
}; | ||
_proto.destroy = function destroy() { | ||
this.removeAllRenderingPlugins(); | ||
}; | ||
return Plugin; | ||
@@ -698,0 +615,0 @@ }(gLite.AbstractRendererPlugin); |
@@ -1,3 +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(){ | ||
/*! 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 p?e:p).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 _()}for(r.method=o,r.arg=i;;){var a=r.delegate;if(a){var c=x(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=l(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)}}}(t,r,i),o}function l(t,e,r){try{return{type:"normal",arg:t.call(e,r)}}catch(t){return{type:"throw",arg:t}}}t.wrap=s;var f={};function p(){}function h(){}function d(){}var v={};u(v,i,(function(){return this}));var y=Object.getPrototypeOf,g=y&&y(y(P([])));g&&g!==e&&n.call(g,i)&&(v=g);var m=d.prototype=p.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=l(t[o],t,i);if("throw"!==u.type){var s=u.arg,f=s.value;return f&&"object"==typeof f&&n.call(f,"__await")?e.resolve(f.__await).then((function(t){r("next",t,a,c)}),(function(t){r("throw",t,a,c)})):e.resolve(f).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 f;e.method="throw",e.arg=new TypeError("The iterator does not provide a 'throw' method")}return f}var n=l(r,t.iterator,e.arg);if("throw"===n.type)return e.method="throw",e.arg=n.arg,e.delegate=null,f;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,f):o:(e.method="throw",e.arg=new TypeError("iterator result is not an object"),e.delegate=null,f)}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 P(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:_}}function _(){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=P,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,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),L(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;L(r)}return o}}throw new Error("illegal catch attempt")},delegateYield:function(t,e,r){return this.delegate={iterator:P(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=e.renderingService,i=e.renderingContext.root.ownerDocument,a=i.defaultView,c=this.dragndropPluginOptions,u=c.overlap,s=c.isDocumentDraggable,l=c.isDocumentDroppable,f=c.dragstartDistanceThreshold,p=c.dragstartTimeThreshold,h=function(t){var e=t.target,n=e===i,c=n&&s?i:e.closest&&e.closest("[draggable=true]");if(c){var h=function(){var t=o(r().mark((function t(o){var a,s,h,w,b,x;return r().wrap((function(t){for(;;)switch(t.prev=t.next){case 0:if(d){t.next=8;break}if(a=o.timeStamp-v,r=[o.clientX,o.clientY],E=y,s=Math.sqrt((r[0]-E[0])*(r[0]-E[0])+(r[1]-E[1])*(r[1]-E[1])),a>p&&s>f){t.next=5;break}return t.abrupt("return");case 5:o.type="dragstart",c.dispatchEvent(o),d=!0;case 8:if(o.type="drag",o.dx=o.clientX-m[0],o.dy=o.clientY-m[1],c.dispatchEvent(o),m=[o.clientX,o.clientY],n){t.next=21;break}return h="pointer"===u?[o.canvasX,o.canvasY]:e.getBounds().center,t.next=17,i.elementsFromPoint(h[0],h[1]);case 17:b=(w=t.sent)[w.indexOf(e)+1],x=(null==b?void 0:b.closest("[droppable=true]"))||(l?i:null),g!==x&&(g&&(o.type="dragleave",o.target=g,g.dispatchEvent(o)),x&&(o.type="dragenter",o.target=x,x.dispatchEvent(o)),(g=x)&&(o.type="dragover",o.target=g,g.dispatchEvent(o)));case 21:case"end":return t.stop()}var r,E}),t)})));return function(e){return t.apply(this,arguments)}}(),d=!1,v=t.timeStamp,y=[t.clientX,t.clientY],g=null,m=[t.clientX,t.clientY];a.addEventListener("pointermove",h);var w=function(t){if(d){t.detail={preventClick:!0};var e=t.clone();g&&(e.type="drop",e.target=g,g.dispatchEvent(e)),e.type="dragend",c.dispatchEvent(e),d=!1}a.removeEventListener("pointermove",h)};e.addEventListener("pointerup",w,{once:!0}),e.addEventListener("pointerupoutside",w,{once:!0})}};n.hooks.init.tapPromise(t.tag,o(r().mark((function t(){return r().wrap((function(t){for(;;)switch(t.prev=t.next){case 0:a.addEventListener("pointerdown",h);case 1:case"end":return t.stop()}}),t)})))),n.hooks.destroy.tap(t.tag,(function(){a.removeEventListener("pointerdown",h)}))},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}r=t,(e=n).prototype=Object.create(r.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()},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(){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 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&&n.call(m,a)&&(y=m);var w=v.prototype=h.prototype=Object.create(y);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=f(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 new 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=L(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 L(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,L(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 O(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(O,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 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),P(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;P(r)}return o}}throw new 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 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=e.renderingService,i=e.renderingContext.root.ownerDocument,a=i.defaultView,c=this.dragndropPluginOptions,u=c.overlap,s=c.isDocumentDraggable,l=c.isDocumentDroppable,f=c.dragstartDistanceThreshold,p=c.dragstartTimeThreshold,h=function(t){var e=t.target,n=e===i,c=n&&s?i:e.closest&&e.closest("[draggable=true]");if(c){var h=function(){var t=o(r().mark((function t(o){var a,s,h,w,b,x;return r().wrap((function(t){for(;;)switch(t.prev=t.next){case 0:if(d){t.next=8;break}if(a=o.timeStamp-v,r=[o.clientX,o.clientY],E=y,s=Math.sqrt((r[0]-E[0])*(r[0]-E[0])+(r[1]-E[1])*(r[1]-E[1])),a>p&&s>f){t.next=5;break}return t.abrupt("return");case 5:o.type="dragstart",c.dispatchEvent(o),d=!0;case 8:if(o.type="drag",o.dx=o.clientX-m[0],o.dy=o.clientY-m[1],c.dispatchEvent(o),m=[o.clientX,o.clientY],n){t.next=21;break}return h="pointer"===u?[o.canvasX,o.canvasY]:e.getBounds().center,t.next=17,i.elementsFromPoint(h[0],h[1]);case 17:b=(w=t.sent)[w.indexOf(e)+1],x=(null==b?void 0:b.closest("[droppable=true]"))||(l?i:null),g!==x&&(g&&(o.type="dragleave",o.target=g,g.dispatchEvent(o)),x&&(o.type="dragenter",o.target=x,x.dispatchEvent(o)),(g=x)&&(o.type="dragover",o.target=g,g.dispatchEvent(o)));case 21:case"end":return t.stop()}var r,E}),t)})));return function(e){return t.apply(this,arguments)}}(),d=!1,v=t.timeStamp,y=[t.clientX,t.clientY],g=null,m=[t.clientX,t.clientY];a.addEventListener("pointermove",h);var w=function(t){if(d){t.detail={preventClick:!0};var e=t.clone();g&&(e.type="drop",e.target=g,g.dispatchEvent(e)),e.type="dragend",c.dispatchEvent(e),d=!1}a.removeEventListener("pointermove",h)};e.addEventListener("pointerup",w,{once:!0}),e.addEventListener("pointerupoutside",w,{once:!0})}};n.hooks.init.tapPromise(t.tag,o(r().mark((function t(){return r().wrap((function(t){for(;;)switch(t.prev=t.next){case 0:a.addEventListener("pointerdown",h);case 1:case"end":return t.stop()}}),t)})))),n.hooks.destroy.tap(t.tag,(function(){a.removeEventListener("pointerdown",h)}))},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}r=t,(e=n).prototype=Object.create(r.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()},n}(e.AbstractRendererPlugin),Object.defineProperty(t,"__esModule",{value:!0})})); |
{ | ||
"name": "@antv/g-plugin-dragndrop", | ||
"version": "1.6.27", | ||
"version": "1.6.28", | ||
"description": "A G plugin for Drag n Drop implemented with PointerEvents", | ||
@@ -33,3 +33,3 @@ "keywords": [ | ||
"dependencies": { | ||
"@antv/util": "^3.2.4", | ||
"@antv/util": "^3.3.1", | ||
"tslib": "^2.3.1" | ||
@@ -46,3 +46,3 @@ }, | ||
}, | ||
"gitHead": "e7c23dd07f888b9e46a27a4f79ec80ed2db62fc7" | ||
"gitHead": "c92278756907344ff54ebc6f6a83630559ef36ff" | ||
} |
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
89912
1768
Updated@antv/util@^3.3.1