@antv/g-plugin-dragndrop
Advanced tools
Comparing version 1.6.51 to 1.7.0-alpha.1
@@ -9,2 +9,1 @@ import type { RenderingPlugin, RenderingPluginContext } from '@antv/g-lite'; | ||
} | ||
//# sourceMappingURL=DragndropPlugin.d.ts.map |
@@ -11,2 +11,1 @@ import { AbstractRendererPlugin } from '@antv/g-lite'; | ||
} | ||
//# sourceMappingURL=index.d.ts.map |
@@ -0,542 +1,167 @@ | ||
import { __awaiter, __generator, __extends, __assign } from 'tslib'; | ||
import { AbstractRendererPlugin } from '@antv/g-lite'; | ||
import { distanceSquareRoot } from '@antv/util'; | ||
function _regeneratorRuntime() { | ||
_regeneratorRuntime = function () { | ||
return exports; | ||
}; | ||
var exports = {}, | ||
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) { | ||
return Object.defineProperty(obj, key, { | ||
value: value, | ||
enumerable: !0, | ||
configurable: !0, | ||
writable: !0 | ||
}), obj[key]; | ||
} | ||
try { | ||
define({}, ""); | ||
} catch (err) { | ||
define = function (obj, key, value) { | ||
return obj[key] = value; | ||
}; | ||
} | ||
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 defineProperty(generator, "_invoke", { | ||
value: makeInvokeMethod(innerFn, self, context) | ||
}), generator; | ||
} | ||
function tryCatch(fn, obj, arg) { | ||
try { | ||
return { | ||
type: "normal", | ||
arg: fn.call(obj, arg) | ||
}; | ||
} catch (err) { | ||
return { | ||
type: "throw", | ||
arg: err | ||
}; | ||
var DragndropPlugin = /** @class */ (function () { | ||
function DragndropPlugin(dragndropPluginOptions) { | ||
this.dragndropPluginOptions = dragndropPluginOptions; | ||
} | ||
} | ||
exports.wrap = wrap; | ||
var ContinueSentinel = {}; | ||
function Generator() {} | ||
function GeneratorFunction() {} | ||
function GeneratorFunctionPrototype() {} | ||
var IteratorPrototype = {}; | ||
define(IteratorPrototype, iteratorSymbol, function () { | ||
return this; | ||
}); | ||
var getProto = Object.getPrototypeOf, | ||
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) { | ||
["next", "throw", "return"].forEach(function (method) { | ||
define(prototype, method, function (arg) { | ||
return this._invoke(method, arg); | ||
}); | ||
}); | ||
} | ||
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; | ||
return value && "object" == typeof value && hasOwn.call(value, "__await") ? PromiseImpl.resolve(value.__await).then(function (value) { | ||
invoke("next", value, resolve, reject); | ||
}, function (err) { | ||
invoke("throw", err, resolve, reject); | ||
}) : PromiseImpl.resolve(value).then(function (unwrapped) { | ||
result.value = unwrapped, resolve(result); | ||
}, function (error) { | ||
return invoke("throw", error, resolve, reject); | ||
}); | ||
} | ||
reject(record.arg); | ||
} | ||
var previousPromise; | ||
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(); | ||
} | ||
}); | ||
} | ||
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 methodName = context.method, | ||
method = delegate.iterator[methodName]; | ||
if (undefined === method) return context.delegate = null, "throw" === methodName && delegate.iterator.return && (context.method = "return", context.arg = undefined, maybeInvokeDelegate(delegate, context), "throw" === context.method) || "return" !== methodName && (context.method = "throw", context.arg = new TypeError("The iterator does not provide a '" + methodName + "' method")), ContinueSentinel; | ||
var record = tryCatch(method, delegate.iterator, context.arg); | ||
if ("throw" === record.type) return context.method = "throw", context.arg = record.arg, context.delegate = null, ContinueSentinel; | ||
var info = record.arg; | ||
return info ? info.done ? (context[delegate.resultName] = info.value, context.next = delegate.nextLoc, "return" !== context.method && (context.method = "next", context.arg = undefined), context.delegate = null, ContinueSentinel) : info : (context.method = "throw", context.arg = new TypeError("iterator result is not an object"), context.delegate = null, ContinueSentinel); | ||
} | ||
function pushTryEntry(locs) { | ||
var entry = { | ||
tryLoc: locs[0] | ||
}; | ||
1 in locs && (entry.catchLoc = locs[1]), 2 in locs && (entry.finallyLoc = locs[2], entry.afterLoc = locs[3]), this.tryEntries.push(entry); | ||
} | ||
function resetTryEntry(entry) { | ||
var record = entry.completion || {}; | ||
record.type = "normal", delete record.arg, entry.completion = record; | ||
} | ||
function Context(tryLocsList) { | ||
this.tryEntries = [{ | ||
tryLoc: "root" | ||
}], tryLocsList.forEach(pushTryEntry, this), this.reset(!0); | ||
} | ||
function values(iterable) { | ||
if (iterable) { | ||
var iteratorMethod = iterable[iteratorSymbol]; | ||
if (iteratorMethod) return iteratorMethod.call(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; | ||
}; | ||
return next.next = next; | ||
} | ||
} | ||
return { | ||
next: doneResult | ||
}; | ||
} | ||
function doneResult() { | ||
return { | ||
value: undefined, | ||
done: !0 | ||
}; | ||
} | ||
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; | ||
return !!ctor && (ctor === GeneratorFunction || "GeneratorFunction" === (ctor.displayName || ctor.name)); | ||
}, exports.mark = function (genFun) { | ||
return Object.setPrototypeOf ? Object.setPrototypeOf(genFun, GeneratorFunctionPrototype) : (genFun.__proto__ = GeneratorFunctionPrototype, define(genFun, toStringTagSymbol, "GeneratorFunction")), genFun.prototype = Object.create(Gp), genFun; | ||
}, exports.awrap = function (arg) { | ||
return { | ||
__await: arg | ||
}; | ||
}, defineIteratorMethods(AsyncIterator.prototype), define(AsyncIterator.prototype, asyncIteratorSymbol, function () { | ||
return this; | ||
}), exports.AsyncIterator = AsyncIterator, exports.async = function (innerFn, outerFn, self, tryLocsList, PromiseImpl) { | ||
void 0 === PromiseImpl && (PromiseImpl = Promise); | ||
var iter = new AsyncIterator(wrap(innerFn, outerFn, self, tryLocsList), PromiseImpl); | ||
return exports.isGeneratorFunction(outerFn) ? iter : iter.next().then(function (result) { | ||
return result.done ? result.value : iter.next(); | ||
}); | ||
}, defineIteratorMethods(Gp), define(Gp, toStringTagSymbol, "Generator"), define(Gp, iteratorSymbol, function () { | ||
return this; | ||
}), define(Gp, "toString", function () { | ||
return "[object Generator]"; | ||
}), exports.keys = function (val) { | ||
var object = Object(val), | ||
keys = []; | ||
for (var key in object) keys.push(key); | ||
return keys.reverse(), function next() { | ||
for (; keys.length;) { | ||
var key = keys.pop(); | ||
if (key in object) return next.value = key, next.done = !1, next; | ||
} | ||
return next.done = !0, next; | ||
}; | ||
}, exports.values = values, Context.prototype = { | ||
constructor: Context, | ||
reset: function (skipTempReset) { | ||
if (this.prev = 0, this.next = 0, this.sent = this._sent = undefined, this.done = !1, this.delegate = null, this.method = "next", this.arg = undefined, this.tryEntries.forEach(resetTryEntry), !skipTempReset) for (var name in this) "t" === name.charAt(0) && hasOwn.call(this, name) && !isNaN(+name.slice(1)) && (this[name] = undefined); | ||
}, | ||
stop: function () { | ||
this.done = !0; | ||
var rootRecord = this.tryEntries[0].completion; | ||
if ("throw" === rootRecord.type) throw rootRecord.arg; | ||
return this.rval; | ||
}, | ||
dispatchException: function (exception) { | ||
if (this.done) throw exception; | ||
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; | ||
if ("root" === entry.tryLoc) return handle("end"); | ||
if (entry.tryLoc <= this.prev) { | ||
var hasCatch = hasOwn.call(entry, "catchLoc"), | ||
hasFinally = hasOwn.call(entry, "finallyLoc"); | ||
if (hasCatch && hasFinally) { | ||
if (this.prev < entry.catchLoc) return handle(entry.catchLoc, !0); | ||
if (this.prev < entry.finallyLoc) return handle(entry.finallyLoc); | ||
} else if (hasCatch) { | ||
if (this.prev < entry.catchLoc) return handle(entry.catchLoc, !0); | ||
} else { | ||
if (!hasFinally) throw new Error("try statement without catch or finally"); | ||
if (this.prev < entry.finallyLoc) return handle(entry.finallyLoc); | ||
} | ||
} | ||
} | ||
}, | ||
abrupt: function (type, arg) { | ||
for (var i = this.tryEntries.length - 1; i >= 0; --i) { | ||
var entry = this.tryEntries[i]; | ||
if (entry.tryLoc <= this.prev && hasOwn.call(entry, "finallyLoc") && this.prev < entry.finallyLoc) { | ||
var finallyEntry = entry; | ||
break; | ||
} | ||
} | ||
finallyEntry && ("break" === type || "continue" === type) && finallyEntry.tryLoc <= arg && arg <= finallyEntry.finallyLoc && (finallyEntry = null); | ||
var record = finallyEntry ? finallyEntry.completion : {}; | ||
return record.type = type, record.arg = arg, finallyEntry ? (this.method = "next", this.next = finallyEntry.finallyLoc, ContinueSentinel) : this.complete(record); | ||
}, | ||
complete: function (record, afterLoc) { | ||
if ("throw" === record.type) throw record.arg; | ||
return "break" === record.type || "continue" === record.type ? this.next = record.arg : "return" === record.type ? (this.rval = this.arg = record.arg, this.method = "return", this.next = "end") : "normal" === record.type && afterLoc && (this.next = afterLoc), ContinueSentinel; | ||
}, | ||
finish: function (finallyLoc) { | ||
for (var i = this.tryEntries.length - 1; i >= 0; --i) { | ||
var entry = this.tryEntries[i]; | ||
if (entry.finallyLoc === finallyLoc) return this.complete(entry.completion, entry.afterLoc), resetTryEntry(entry), ContinueSentinel; | ||
} | ||
}, | ||
catch: function (tryLoc) { | ||
for (var i = this.tryEntries.length - 1; i >= 0; --i) { | ||
var entry = this.tryEntries[i]; | ||
if (entry.tryLoc === tryLoc) { | ||
var record = entry.completion; | ||
if ("throw" === record.type) { | ||
var thrown = record.arg; | ||
resetTryEntry(entry); | ||
} | ||
return thrown; | ||
} | ||
} | ||
throw new Error("illegal catch attempt"); | ||
}, | ||
delegateYield: function (iterable, resultName, nextLoc) { | ||
return this.delegate = { | ||
iterator: values(iterable), | ||
resultName: resultName, | ||
nextLoc: nextLoc | ||
}, "next" === this.method && (this.arg = undefined), ContinueSentinel; | ||
} | ||
}, exports; | ||
} | ||
function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) { | ||
try { | ||
var info = gen[key](arg); | ||
var value = info.value; | ||
} catch (error) { | ||
reject(error); | ||
return; | ||
} | ||
if (info.done) { | ||
resolve(value); | ||
} else { | ||
Promise.resolve(value).then(_next, _throw); | ||
} | ||
} | ||
function _asyncToGenerator(fn) { | ||
return function () { | ||
var self = this, | ||
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); | ||
}); | ||
}; | ||
} | ||
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]; | ||
} | ||
} | ||
} | ||
return target; | ||
}; | ||
return _extends.apply(this, arguments); | ||
} | ||
function _inheritsLoose(subClass, superClass) { | ||
subClass.prototype = Object.create(superClass.prototype); | ||
subClass.prototype.constructor = subClass; | ||
_setPrototypeOf(subClass, superClass); | ||
} | ||
function _setPrototypeOf(o, p) { | ||
_setPrototypeOf = Object.setPrototypeOf ? Object.setPrototypeOf.bind() : function _setPrototypeOf(o, p) { | ||
o.__proto__ = p; | ||
return o; | ||
}; | ||
return _setPrototypeOf(o, p); | ||
} | ||
var DragndropPlugin = /*#__PURE__*/function () { | ||
function DragndropPlugin(dragndropPluginOptions) { | ||
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); | ||
DragndropPlugin.prototype.apply = function (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 (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_1 = false; | ||
var dragstartTimeStamp_1 = event.timeStamp; | ||
var dragstartClientCoordinates_1 = [ | ||
event.clientX, | ||
event.clientY, | ||
]; | ||
var currentDroppable_1 = null; | ||
var lastDragClientCoordinates_1 = [event.clientX, event.clientY]; | ||
// @ts-ignore | ||
// eslint-disable-next-line no-inner-declarations | ||
var handlePointermove_1 = function (event) { return __awaiter(_this, void 0, void 0, function () { | ||
var timeElapsed, distanceMoved, point, elementsBelow, elementBelow, droppableBelow; | ||
return __generator(this, function (_a) { | ||
switch (_a.label) { | ||
case 0: | ||
if (!dragstartTriggered_1) { | ||
timeElapsed = event.timeStamp - dragstartTimeStamp_1; | ||
distanceMoved = distanceSquareRoot([event.clientX, event.clientY], dragstartClientCoordinates_1); | ||
// check thresholds | ||
if (timeElapsed <= | ||
this.dragndropPluginOptions.dragstartTimeThreshold || | ||
distanceMoved <= | ||
this.dragndropPluginOptions.dragstartDistanceThreshold) { | ||
return [2 /*return*/]; | ||
} | ||
// @see https://developer.mozilla.org/zh-CN/docs/Web/API/Document/dragstart_event | ||
event.type = 'dragstart'; | ||
draggableEventTarget.dispatchEvent(event); | ||
dragstartTriggered_1 = true; | ||
} | ||
// @see https://developer.mozilla.org/zh-CN/docs/Web/API/Document/drag_event | ||
event.type = 'drag'; | ||
// @ts-ignore | ||
event.dx = event.clientX - lastDragClientCoordinates_1[0]; | ||
// @ts-ignore | ||
event.dy = event.clientY - lastDragClientCoordinates_1[1]; | ||
draggableEventTarget.dispatchEvent(event); | ||
lastDragClientCoordinates_1 = [event.clientX, event.clientY]; | ||
if (!!isDocument) return [3 /*break*/, 2]; | ||
point = this.dragndropPluginOptions.overlap === 'pointer' | ||
? [event.canvasX, event.canvasY] | ||
: target.getBounds().center; | ||
return [4 /*yield*/, document.elementsFromPoint(point[0], point[1])]; | ||
case 1: | ||
elementsBelow = _a.sent(); | ||
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_1 !== droppableBelow) { | ||
if (currentDroppable_1) { | ||
// 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_1; | ||
currentDroppable_1.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_1 = droppableBelow; | ||
if (currentDroppable_1) { | ||
// 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_1; | ||
currentDroppable_1.dispatchEvent(event); | ||
} | ||
} | ||
_a.label = 2; | ||
case 2: return [2 /*return*/]; | ||
} | ||
}); | ||
}); }; | ||
canvas.addEventListener('pointermove', handlePointermove_1); | ||
var stopDragging = function (originalPointerUpEvent) { | ||
if (dragstartTriggered_1) { | ||
// prevent click event being triggerd | ||
// @see https://github.com/antvis/G/issues/1091 | ||
originalPointerUpEvent.detail = { | ||
preventClick: true, | ||
}; | ||
// clone event first | ||
var event_1 = originalPointerUpEvent.clone(); | ||
// drop should fire before dragend | ||
// @see https://javascript.tutorialink.com/is-there-a-defined-ordering-between-dragend-and-drop-events/ | ||
if (currentDroppable_1) { | ||
// @see https://developer.mozilla.org/zh-CN/docs/Web/API/Document/drop_event | ||
event_1.type = 'drop'; | ||
event_1.target = currentDroppable_1; | ||
currentDroppable_1.dispatchEvent(event_1); | ||
} | ||
// @see https://developer.mozilla.org/zh-CN/docs/Web/API/Document/dragend_event | ||
event_1.type = 'dragend'; | ||
draggableEventTarget.dispatchEvent(event_1); | ||
dragstartTriggered_1 = false; | ||
} | ||
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); | ||
canvas.removeEventListener('pointermove', handlePointermove_1); | ||
}; | ||
target.addEventListener('pointerup', stopDragging, { once: true }); | ||
target.addEventListener('pointerupoutside', stopDragging, { | ||
once: true, | ||
}); | ||
} | ||
// @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); | ||
}; | ||
target.addEventListener('pointerup', stopDragging, { | ||
once: true | ||
renderingService.hooks.init.tap(DragndropPlugin.tag, function () { | ||
canvas.addEventListener('pointerdown', handlePointerdown); | ||
}); | ||
target.addEventListener('pointerupoutside', stopDragging, { | ||
once: true | ||
renderingService.hooks.destroy.tap(DragndropPlugin.tag, function () { | ||
canvas.removeEventListener('pointerdown', handlePointerdown); | ||
}); | ||
} | ||
}; | ||
renderingService.hooks.init.tap(DragndropPlugin.tag, function () { | ||
canvas.addEventListener('pointerdown', handlePointerdown); | ||
}); | ||
renderingService.hooks.destroy.tap(DragndropPlugin.tag, function () { | ||
canvas.removeEventListener('pointerdown', handlePointerdown); | ||
}); | ||
}; | ||
return DragndropPlugin; | ||
}(); | ||
DragndropPlugin.tag = 'Dragndrop'; | ||
DragndropPlugin.tag = 'Dragndrop'; | ||
return DragndropPlugin; | ||
}()); | ||
var Plugin = /*#__PURE__*/function (_AbstractRendererPlug) { | ||
_inheritsLoose(Plugin, _AbstractRendererPlug); | ||
function Plugin(options) { | ||
var _this; | ||
if (options === void 0) { | ||
options = {}; | ||
var Plugin = /** @class */ (function (_super) { | ||
__extends(Plugin, _super); | ||
function Plugin(options) { | ||
if (options === void 0) { options = {}; } | ||
var _this = _super.call(this) || this; | ||
_this.options = options; | ||
_this.name = 'dragndrop'; | ||
return _this; | ||
} | ||
_this = _AbstractRendererPlug.call(this) || this; | ||
_this.options = void 0; | ||
_this.name = 'dragndrop'; | ||
_this.options = options; | ||
return _this; | ||
} | ||
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); | ||
}; | ||
return Plugin; | ||
}(AbstractRendererPlugin); | ||
Plugin.prototype.init = function () { | ||
this.addRenderingPlugin(new DragndropPlugin(__assign({ overlap: 'pointer', isDocumentDraggable: false, isDocumentDroppable: false, dragstartDistanceThreshold: 0, dragstartTimeThreshold: 0 }, this.options))); | ||
}; | ||
Plugin.prototype.destroy = function () { | ||
this.removeAllRenderingPlugins(); | ||
}; | ||
Plugin.prototype.setOptions = function (options) { | ||
Object.assign(this.plugins[0].dragndropPluginOptions, options); | ||
}; | ||
return Plugin; | ||
}(AbstractRendererPlugin)); | ||
export { Plugin }; | ||
//# sourceMappingURL=index.esm.js.map |
'use strict'; | ||
Object.defineProperty(exports, '__esModule', { value: true }); | ||
var tslib = require('tslib'); | ||
var gLite = require('@antv/g-lite'); | ||
var util = require('@antv/util'); | ||
function _regeneratorRuntime() { | ||
_regeneratorRuntime = function () { | ||
return exports; | ||
}; | ||
var exports = {}, | ||
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) { | ||
return Object.defineProperty(obj, key, { | ||
value: value, | ||
enumerable: !0, | ||
configurable: !0, | ||
writable: !0 | ||
}), obj[key]; | ||
} | ||
try { | ||
define({}, ""); | ||
} catch (err) { | ||
define = function (obj, key, value) { | ||
return obj[key] = value; | ||
}; | ||
} | ||
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 defineProperty(generator, "_invoke", { | ||
value: makeInvokeMethod(innerFn, self, context) | ||
}), generator; | ||
} | ||
function tryCatch(fn, obj, arg) { | ||
try { | ||
return { | ||
type: "normal", | ||
arg: fn.call(obj, arg) | ||
}; | ||
} catch (err) { | ||
return { | ||
type: "throw", | ||
arg: err | ||
}; | ||
var DragndropPlugin = /** @class */ (function () { | ||
function DragndropPlugin(dragndropPluginOptions) { | ||
this.dragndropPluginOptions = dragndropPluginOptions; | ||
} | ||
} | ||
exports.wrap = wrap; | ||
var ContinueSentinel = {}; | ||
function Generator() {} | ||
function GeneratorFunction() {} | ||
function GeneratorFunctionPrototype() {} | ||
var IteratorPrototype = {}; | ||
define(IteratorPrototype, iteratorSymbol, function () { | ||
return this; | ||
}); | ||
var getProto = Object.getPrototypeOf, | ||
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) { | ||
["next", "throw", "return"].forEach(function (method) { | ||
define(prototype, method, function (arg) { | ||
return this._invoke(method, arg); | ||
}); | ||
}); | ||
} | ||
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; | ||
return value && "object" == typeof value && hasOwn.call(value, "__await") ? PromiseImpl.resolve(value.__await).then(function (value) { | ||
invoke("next", value, resolve, reject); | ||
}, function (err) { | ||
invoke("throw", err, resolve, reject); | ||
}) : PromiseImpl.resolve(value).then(function (unwrapped) { | ||
result.value = unwrapped, resolve(result); | ||
}, function (error) { | ||
return invoke("throw", error, resolve, reject); | ||
}); | ||
} | ||
reject(record.arg); | ||
} | ||
var previousPromise; | ||
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(); | ||
} | ||
}); | ||
} | ||
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 methodName = context.method, | ||
method = delegate.iterator[methodName]; | ||
if (undefined === method) return context.delegate = null, "throw" === methodName && delegate.iterator.return && (context.method = "return", context.arg = undefined, maybeInvokeDelegate(delegate, context), "throw" === context.method) || "return" !== methodName && (context.method = "throw", context.arg = new TypeError("The iterator does not provide a '" + methodName + "' method")), ContinueSentinel; | ||
var record = tryCatch(method, delegate.iterator, context.arg); | ||
if ("throw" === record.type) return context.method = "throw", context.arg = record.arg, context.delegate = null, ContinueSentinel; | ||
var info = record.arg; | ||
return info ? info.done ? (context[delegate.resultName] = info.value, context.next = delegate.nextLoc, "return" !== context.method && (context.method = "next", context.arg = undefined), context.delegate = null, ContinueSentinel) : info : (context.method = "throw", context.arg = new TypeError("iterator result is not an object"), context.delegate = null, ContinueSentinel); | ||
} | ||
function pushTryEntry(locs) { | ||
var entry = { | ||
tryLoc: locs[0] | ||
}; | ||
1 in locs && (entry.catchLoc = locs[1]), 2 in locs && (entry.finallyLoc = locs[2], entry.afterLoc = locs[3]), this.tryEntries.push(entry); | ||
} | ||
function resetTryEntry(entry) { | ||
var record = entry.completion || {}; | ||
record.type = "normal", delete record.arg, entry.completion = record; | ||
} | ||
function Context(tryLocsList) { | ||
this.tryEntries = [{ | ||
tryLoc: "root" | ||
}], tryLocsList.forEach(pushTryEntry, this), this.reset(!0); | ||
} | ||
function values(iterable) { | ||
if (iterable) { | ||
var iteratorMethod = iterable[iteratorSymbol]; | ||
if (iteratorMethod) return iteratorMethod.call(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; | ||
}; | ||
return next.next = next; | ||
} | ||
} | ||
return { | ||
next: doneResult | ||
}; | ||
} | ||
function doneResult() { | ||
return { | ||
value: undefined, | ||
done: !0 | ||
}; | ||
} | ||
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; | ||
return !!ctor && (ctor === GeneratorFunction || "GeneratorFunction" === (ctor.displayName || ctor.name)); | ||
}, exports.mark = function (genFun) { | ||
return Object.setPrototypeOf ? Object.setPrototypeOf(genFun, GeneratorFunctionPrototype) : (genFun.__proto__ = GeneratorFunctionPrototype, define(genFun, toStringTagSymbol, "GeneratorFunction")), genFun.prototype = Object.create(Gp), genFun; | ||
}, exports.awrap = function (arg) { | ||
return { | ||
__await: arg | ||
}; | ||
}, defineIteratorMethods(AsyncIterator.prototype), define(AsyncIterator.prototype, asyncIteratorSymbol, function () { | ||
return this; | ||
}), exports.AsyncIterator = AsyncIterator, exports.async = function (innerFn, outerFn, self, tryLocsList, PromiseImpl) { | ||
void 0 === PromiseImpl && (PromiseImpl = Promise); | ||
var iter = new AsyncIterator(wrap(innerFn, outerFn, self, tryLocsList), PromiseImpl); | ||
return exports.isGeneratorFunction(outerFn) ? iter : iter.next().then(function (result) { | ||
return result.done ? result.value : iter.next(); | ||
}); | ||
}, defineIteratorMethods(Gp), define(Gp, toStringTagSymbol, "Generator"), define(Gp, iteratorSymbol, function () { | ||
return this; | ||
}), define(Gp, "toString", function () { | ||
return "[object Generator]"; | ||
}), exports.keys = function (val) { | ||
var object = Object(val), | ||
keys = []; | ||
for (var key in object) keys.push(key); | ||
return keys.reverse(), function next() { | ||
for (; keys.length;) { | ||
var key = keys.pop(); | ||
if (key in object) return next.value = key, next.done = !1, next; | ||
} | ||
return next.done = !0, next; | ||
}; | ||
}, exports.values = values, Context.prototype = { | ||
constructor: Context, | ||
reset: function (skipTempReset) { | ||
if (this.prev = 0, this.next = 0, this.sent = this._sent = undefined, this.done = !1, this.delegate = null, this.method = "next", this.arg = undefined, this.tryEntries.forEach(resetTryEntry), !skipTempReset) for (var name in this) "t" === name.charAt(0) && hasOwn.call(this, name) && !isNaN(+name.slice(1)) && (this[name] = undefined); | ||
}, | ||
stop: function () { | ||
this.done = !0; | ||
var rootRecord = this.tryEntries[0].completion; | ||
if ("throw" === rootRecord.type) throw rootRecord.arg; | ||
return this.rval; | ||
}, | ||
dispatchException: function (exception) { | ||
if (this.done) throw exception; | ||
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; | ||
if ("root" === entry.tryLoc) return handle("end"); | ||
if (entry.tryLoc <= this.prev) { | ||
var hasCatch = hasOwn.call(entry, "catchLoc"), | ||
hasFinally = hasOwn.call(entry, "finallyLoc"); | ||
if (hasCatch && hasFinally) { | ||
if (this.prev < entry.catchLoc) return handle(entry.catchLoc, !0); | ||
if (this.prev < entry.finallyLoc) return handle(entry.finallyLoc); | ||
} else if (hasCatch) { | ||
if (this.prev < entry.catchLoc) return handle(entry.catchLoc, !0); | ||
} else { | ||
if (!hasFinally) throw new Error("try statement without catch or finally"); | ||
if (this.prev < entry.finallyLoc) return handle(entry.finallyLoc); | ||
} | ||
} | ||
} | ||
}, | ||
abrupt: function (type, arg) { | ||
for (var i = this.tryEntries.length - 1; i >= 0; --i) { | ||
var entry = this.tryEntries[i]; | ||
if (entry.tryLoc <= this.prev && hasOwn.call(entry, "finallyLoc") && this.prev < entry.finallyLoc) { | ||
var finallyEntry = entry; | ||
break; | ||
} | ||
} | ||
finallyEntry && ("break" === type || "continue" === type) && finallyEntry.tryLoc <= arg && arg <= finallyEntry.finallyLoc && (finallyEntry = null); | ||
var record = finallyEntry ? finallyEntry.completion : {}; | ||
return record.type = type, record.arg = arg, finallyEntry ? (this.method = "next", this.next = finallyEntry.finallyLoc, ContinueSentinel) : this.complete(record); | ||
}, | ||
complete: function (record, afterLoc) { | ||
if ("throw" === record.type) throw record.arg; | ||
return "break" === record.type || "continue" === record.type ? this.next = record.arg : "return" === record.type ? (this.rval = this.arg = record.arg, this.method = "return", this.next = "end") : "normal" === record.type && afterLoc && (this.next = afterLoc), ContinueSentinel; | ||
}, | ||
finish: function (finallyLoc) { | ||
for (var i = this.tryEntries.length - 1; i >= 0; --i) { | ||
var entry = this.tryEntries[i]; | ||
if (entry.finallyLoc === finallyLoc) return this.complete(entry.completion, entry.afterLoc), resetTryEntry(entry), ContinueSentinel; | ||
} | ||
}, | ||
catch: function (tryLoc) { | ||
for (var i = this.tryEntries.length - 1; i >= 0; --i) { | ||
var entry = this.tryEntries[i]; | ||
if (entry.tryLoc === tryLoc) { | ||
var record = entry.completion; | ||
if ("throw" === record.type) { | ||
var thrown = record.arg; | ||
resetTryEntry(entry); | ||
} | ||
return thrown; | ||
} | ||
} | ||
throw new Error("illegal catch attempt"); | ||
}, | ||
delegateYield: function (iterable, resultName, nextLoc) { | ||
return this.delegate = { | ||
iterator: values(iterable), | ||
resultName: resultName, | ||
nextLoc: nextLoc | ||
}, "next" === this.method && (this.arg = undefined), ContinueSentinel; | ||
} | ||
}, exports; | ||
} | ||
function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) { | ||
try { | ||
var info = gen[key](arg); | ||
var value = info.value; | ||
} catch (error) { | ||
reject(error); | ||
return; | ||
} | ||
if (info.done) { | ||
resolve(value); | ||
} else { | ||
Promise.resolve(value).then(_next, _throw); | ||
} | ||
} | ||
function _asyncToGenerator(fn) { | ||
return function () { | ||
var self = this, | ||
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); | ||
}); | ||
}; | ||
} | ||
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]; | ||
} | ||
} | ||
} | ||
return target; | ||
}; | ||
return _extends.apply(this, arguments); | ||
} | ||
function _inheritsLoose(subClass, superClass) { | ||
subClass.prototype = Object.create(superClass.prototype); | ||
subClass.prototype.constructor = subClass; | ||
_setPrototypeOf(subClass, superClass); | ||
} | ||
function _setPrototypeOf(o, p) { | ||
_setPrototypeOf = Object.setPrototypeOf ? Object.setPrototypeOf.bind() : function _setPrototypeOf(o, p) { | ||
o.__proto__ = p; | ||
return o; | ||
}; | ||
return _setPrototypeOf(o, p); | ||
} | ||
var DragndropPlugin = /*#__PURE__*/function () { | ||
function DragndropPlugin(dragndropPluginOptions) { | ||
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); | ||
DragndropPlugin.prototype.apply = function (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 (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_1 = false; | ||
var dragstartTimeStamp_1 = event.timeStamp; | ||
var dragstartClientCoordinates_1 = [ | ||
event.clientX, | ||
event.clientY, | ||
]; | ||
var currentDroppable_1 = null; | ||
var lastDragClientCoordinates_1 = [event.clientX, event.clientY]; | ||
// @ts-ignore | ||
// eslint-disable-next-line no-inner-declarations | ||
var handlePointermove_1 = function (event) { return tslib.__awaiter(_this, void 0, void 0, function () { | ||
var timeElapsed, distanceMoved, point, elementsBelow, elementBelow, droppableBelow; | ||
return tslib.__generator(this, function (_a) { | ||
switch (_a.label) { | ||
case 0: | ||
if (!dragstartTriggered_1) { | ||
timeElapsed = event.timeStamp - dragstartTimeStamp_1; | ||
distanceMoved = util.distanceSquareRoot([event.clientX, event.clientY], dragstartClientCoordinates_1); | ||
// check thresholds | ||
if (timeElapsed <= | ||
this.dragndropPluginOptions.dragstartTimeThreshold || | ||
distanceMoved <= | ||
this.dragndropPluginOptions.dragstartDistanceThreshold) { | ||
return [2 /*return*/]; | ||
} | ||
// @see https://developer.mozilla.org/zh-CN/docs/Web/API/Document/dragstart_event | ||
event.type = 'dragstart'; | ||
draggableEventTarget.dispatchEvent(event); | ||
dragstartTriggered_1 = true; | ||
} | ||
// @see https://developer.mozilla.org/zh-CN/docs/Web/API/Document/drag_event | ||
event.type = 'drag'; | ||
// @ts-ignore | ||
event.dx = event.clientX - lastDragClientCoordinates_1[0]; | ||
// @ts-ignore | ||
event.dy = event.clientY - lastDragClientCoordinates_1[1]; | ||
draggableEventTarget.dispatchEvent(event); | ||
lastDragClientCoordinates_1 = [event.clientX, event.clientY]; | ||
if (!!isDocument) return [3 /*break*/, 2]; | ||
point = this.dragndropPluginOptions.overlap === 'pointer' | ||
? [event.canvasX, event.canvasY] | ||
: target.getBounds().center; | ||
return [4 /*yield*/, document.elementsFromPoint(point[0], point[1])]; | ||
case 1: | ||
elementsBelow = _a.sent(); | ||
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_1 !== droppableBelow) { | ||
if (currentDroppable_1) { | ||
// 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_1; | ||
currentDroppable_1.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_1 = droppableBelow; | ||
if (currentDroppable_1) { | ||
// 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_1; | ||
currentDroppable_1.dispatchEvent(event); | ||
} | ||
} | ||
_a.label = 2; | ||
case 2: return [2 /*return*/]; | ||
} | ||
}); | ||
}); }; | ||
canvas.addEventListener('pointermove', handlePointermove_1); | ||
var stopDragging = function (originalPointerUpEvent) { | ||
if (dragstartTriggered_1) { | ||
// prevent click event being triggerd | ||
// @see https://github.com/antvis/G/issues/1091 | ||
originalPointerUpEvent.detail = { | ||
preventClick: true, | ||
}; | ||
// clone event first | ||
var event_1 = originalPointerUpEvent.clone(); | ||
// drop should fire before dragend | ||
// @see https://javascript.tutorialink.com/is-there-a-defined-ordering-between-dragend-and-drop-events/ | ||
if (currentDroppable_1) { | ||
// @see https://developer.mozilla.org/zh-CN/docs/Web/API/Document/drop_event | ||
event_1.type = 'drop'; | ||
event_1.target = currentDroppable_1; | ||
currentDroppable_1.dispatchEvent(event_1); | ||
} | ||
// @see https://developer.mozilla.org/zh-CN/docs/Web/API/Document/dragend_event | ||
event_1.type = 'dragend'; | ||
draggableEventTarget.dispatchEvent(event_1); | ||
dragstartTriggered_1 = false; | ||
} | ||
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); | ||
canvas.removeEventListener('pointermove', handlePointermove_1); | ||
}; | ||
target.addEventListener('pointerup', stopDragging, { once: true }); | ||
target.addEventListener('pointerupoutside', stopDragging, { | ||
once: true, | ||
}); | ||
} | ||
// @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); | ||
}; | ||
target.addEventListener('pointerup', stopDragging, { | ||
once: true | ||
renderingService.hooks.init.tap(DragndropPlugin.tag, function () { | ||
canvas.addEventListener('pointerdown', handlePointerdown); | ||
}); | ||
target.addEventListener('pointerupoutside', stopDragging, { | ||
once: true | ||
renderingService.hooks.destroy.tap(DragndropPlugin.tag, function () { | ||
canvas.removeEventListener('pointerdown', handlePointerdown); | ||
}); | ||
} | ||
}; | ||
renderingService.hooks.init.tap(DragndropPlugin.tag, function () { | ||
canvas.addEventListener('pointerdown', handlePointerdown); | ||
}); | ||
renderingService.hooks.destroy.tap(DragndropPlugin.tag, function () { | ||
canvas.removeEventListener('pointerdown', handlePointerdown); | ||
}); | ||
}; | ||
return DragndropPlugin; | ||
}(); | ||
DragndropPlugin.tag = 'Dragndrop'; | ||
DragndropPlugin.tag = 'Dragndrop'; | ||
return DragndropPlugin; | ||
}()); | ||
var Plugin = /*#__PURE__*/function (_AbstractRendererPlug) { | ||
_inheritsLoose(Plugin, _AbstractRendererPlug); | ||
function Plugin(options) { | ||
var _this; | ||
if (options === void 0) { | ||
options = {}; | ||
var Plugin = /** @class */ (function (_super) { | ||
tslib.__extends(Plugin, _super); | ||
function Plugin(options) { | ||
if (options === void 0) { options = {}; } | ||
var _this = _super.call(this) || this; | ||
_this.options = options; | ||
_this.name = 'dragndrop'; | ||
return _this; | ||
} | ||
_this = _AbstractRendererPlug.call(this) || this; | ||
_this.options = void 0; | ||
_this.name = 'dragndrop'; | ||
_this.options = options; | ||
return _this; | ||
} | ||
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); | ||
}; | ||
return Plugin; | ||
}(gLite.AbstractRendererPlugin); | ||
Plugin.prototype.init = function () { | ||
this.addRenderingPlugin(new DragndropPlugin(tslib.__assign({ overlap: 'pointer', isDocumentDraggable: false, isDocumentDroppable: false, dragstartDistanceThreshold: 0, dragstartTimeThreshold: 0 }, this.options))); | ||
}; | ||
Plugin.prototype.destroy = function () { | ||
this.removeAllRenderingPlugins(); | ||
}; | ||
Plugin.prototype.setOptions = function (options) { | ||
Object.assign(this.plugins[0].dragndropPluginOptions, options); | ||
}; | ||
return Plugin; | ||
}(gLite.AbstractRendererPlugin)); | ||
exports.Plugin = Plugin; | ||
//# sourceMappingURL=index.js.map |
@@ -1,1 +0,2 @@ | ||
!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(){return o=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},o.apply(this,arguments)}function i(t,e){return i=Object.setPrototypeOf?Object.setPrototypeOf.bind():function(t,e){return t.__proto__=e,t},i(t,e)}var a=function(){function t(t){this.dragndropPluginOptions=void 0,this.dragndropPluginOptions=t}return t.prototype.apply=function(e){var o=this,i=e.renderingService,a=e.renderingContext.root.ownerDocument,c=a.defaultView,u=function(t){var e=t.target,i=e===a,u=i&&o.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,c=(t=r().mark((function t(n){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=n.timeStamp-l,d=Math.sqrt(((r=[n.clientX,n.clientY])[0]-(w=p)[0])*(r[0]-w[0])+(r[1]-w[1])*(r[1]-w[1])),c>o.dragndropPluginOptions.dragstartTimeThreshold&&d>o.dragndropPluginOptions.dragstartDistanceThreshold){t.next=5;break}return t.abrupt("return");case 5:n.type="dragstart",u.dispatchEvent(n),s=!0;case 8:if(n.type="drag",n.dx=n.clientX-h[0],n.dy=n.clientY-h[1],u.dispatchEvent(n),h=[n.clientX,n.clientY],i){t.next=21;break}return v="pointer"===o.dragndropPluginOptions.overlap?[n.canvasX,n.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]"))||(o.dragndropPluginOptions.isDocumentDroppable?a:null),f!==m&&(f&&(n.type="dragleave",n.target=f,f.dispatchEvent(n)),m&&(n.type="dragenter",n.target=m,m.dispatchEvent(n)),(f=m)&&(n.type="dragover",n.target=f,f.dispatchEvent(n)));case 21:case"end":return t.stop()}var r,w}),t)})),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)}))});return function(t){return c.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.tap(t.tag,(function(){c.addEventListener("pointerdown",u)})),i.hooks.destroy.tap(t.tag,(function(){c.removeEventListener("pointerdown",u)}))},t}();a.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,i(e,r);var c=n.prototype;return c.init=function(){this.addRenderingPlugin(new a(o({overlap:"pointer",isDocumentDraggable:!1,isDocumentDroppable:!1,dragstartDistanceThreshold:0,dragstartTimeThreshold:0},this.options)))},c.destroy=function(){this.removeAllRenderingPlugins()},c.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";var n=function(t,e){return n=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(t,e){t.__proto__=e}||function(t,e){for(var n in e)Object.prototype.hasOwnProperty.call(e,n)&&(t[n]=e[n])},n(t,e)};var r=function(){return r=Object.assign||function(t){for(var e,n=1,r=arguments.length;r>n;n++)for(var o in e=arguments[n])Object.prototype.hasOwnProperty.call(e,o)&&(t[o]=e[o]);return t},r.apply(this,arguments)};function o(t,e,n,r){return new(n||(n=Promise))((function(o,i){function a(t){try{c(r.next(t))}catch(t){i(t)}}function s(t){try{c(r.throw(t))}catch(t){i(t)}}function c(t){var e;t.done?o(t.value):(e=t.value,e instanceof n?e:new n((function(t){t(e)}))).then(a,s)}c((r=r.apply(t,e||[])).next())}))}function i(t,e){var n,r,o,i,a={label:0,sent:function(){if(1&o[0])throw o[1];return o[1]},trys:[],ops:[]};return i={next:s(0),throw:s(1),return:s(2)},"function"==typeof Symbol&&(i[Symbol.iterator]=function(){return this}),i;function s(s){return function(c){return function(s){if(n)throw new TypeError("Generator is already executing.");for(;i&&(i=0,s[0]&&(a=0)),a;)try{if(n=1,r&&(o=2&s[0]?r.return:s[0]?r.throw||((o=r.return)&&o.call(r),0):r.next)&&!(o=o.call(r,s[1])).done)return o;switch(r=0,o&&(s=[2&s[0],o.value]),s[0]){case 0:case 1:o=s;break;case 4:return a.label++,{value:s[1],done:!1};case 5:a.label++,r=s[1],s=[0];continue;case 7:s=a.ops.pop(),a.trys.pop();continue;default:if(!(o=a.trys,(o=o.length>0&&o[o.length-1])||6!==s[0]&&2!==s[0])){a=0;continue}if(3===s[0]&&(!o||s[1]>o[0]&&o[3]>s[1])){a.label=s[1];break}if(6===s[0]&&o[1]>a.label){a.label=o[1],o=s;break}if(o&&o[2]>a.label){a.label=o[2],a.ops.push(s);break}o[2]&&a.ops.pop(),a.trys.pop();continue}s=e.call(t,a)}catch(t){s=[6,t],r=0}finally{n=o=0}if(5&s[0])throw s[1];return{value:s[0]?s[1]:void 0,done:!0}}([s,c])}}}var a=function(){function t(t){this.dragndropPluginOptions=t}return t.prototype.apply=function(e){var n=this,r=e.renderingService,a=e.renderingContext.root.ownerDocument,s=a.defaultView,c=function(t){var e=t.target,r=e===a,c=r&&n.dragndropPluginOptions.isDocumentDraggable?a:e.closest&&e.closest("[draggable=true]");if(c){var l=!1,p=t.timeStamp,u=[t.clientX,t.clientY],d=null,f=[t.clientX,t.clientY],g=function(t){return o(n,void 0,void 0,(function(){var n,o,s,g,h,v;return i(this,(function(i){switch(i.label){case 0:if(!l){if(n=t.timeStamp-p,o=Math.sqrt(((y=[t.clientX,t.clientY])[0]-(b=u)[0])*(y[0]-b[0])+(y[1]-b[1])*(y[1]-b[1])),this.dragndropPluginOptions.dragstartTimeThreshold>=n||this.dragndropPluginOptions.dragstartDistanceThreshold>=o)return[2];t.type="dragstart",c.dispatchEvent(t),l=!0}return t.type="drag",t.dx=t.clientX-f[0],t.dy=t.clientY-f[1],c.dispatchEvent(t),f=[t.clientX,t.clientY],r?[3,2]:(s="pointer"===this.dragndropPluginOptions.overlap?[t.canvasX,t.canvasY]:e.getBounds().center,[4,a.elementsFromPoint(s[0],s[1])]);case 1:g=i.sent(),h=g[g.indexOf(e)+1],v=(null==h?void 0:h.closest("[droppable=true]"))||(this.dragndropPluginOptions.isDocumentDroppable?a:null),d!==v&&(d&&(t.type="dragleave",t.target=d,d.dispatchEvent(t)),v&&(t.type="dragenter",t.target=v,v.dispatchEvent(t)),(d=v)&&(t.type="dragover",t.target=d,d.dispatchEvent(t))),i.label=2;case 2:return[2]}var y,b}))}))};s.addEventListener("pointermove",g);var h=function(t){if(l){t.detail={preventClick:!0};var e=t.clone();d&&(e.type="drop",e.target=d,d.dispatchEvent(e)),e.type="dragend",c.dispatchEvent(e),l=!1}s.removeEventListener("pointermove",g)};e.addEventListener("pointerup",h,{once:!0}),e.addEventListener("pointerupoutside",h,{once:!0})}};r.hooks.init.tap(t.tag,(function(){s.addEventListener("pointerdown",c)})),r.hooks.destroy.tap(t.tag,(function(){s.removeEventListener("pointerdown",c)}))},t.tag="Dragndrop",t}(),s=function(t){function e(e){void 0===e&&(e={});var n=t.call(this)||this;return n.options=e,n.name="dragndrop",n}return function(t,e){if("function"!=typeof e&&null!==e)throw new TypeError("Class extends value "+e+" is not a constructor or null");function r(){this.constructor=t}n(t,e),t.prototype=null===e?Object.create(e):(r.prototype=e.prototype,new r)}(e,t),e.prototype.init=function(){this.addRenderingPlugin(new a(r({overlap:"pointer",isDocumentDraggable:!1,isDocumentDroppable:!1,dragstartDistanceThreshold:0,dragstartTimeThreshold:0},this.options)))},e.prototype.destroy=function(){this.removeAllRenderingPlugins()},e.prototype.setOptions=function(t){Object.assign(this.plugins[0].dragndropPluginOptions,t)},e}(e.AbstractRendererPlugin);t.Plugin=s})); | ||
//# sourceMappingURL=index.umd.min.js.map |
@@ -28,2 +28,1 @@ export interface DragndropPluginOptions { | ||
} | ||
//# sourceMappingURL=interfaces.d.ts.map |
{ | ||
"name": "@antv/g-plugin-dragndrop", | ||
"version": "1.6.51", | ||
"version": "1.7.0-alpha.1", | ||
"description": "A G plugin for Drag n Drop implemented with PointerEvents", | ||
@@ -19,2 +19,7 @@ "keywords": [ | ||
"author": "https://github.com/orgs/antvis/people", | ||
"exports": { | ||
"types": "./dist/index.d.ts", | ||
"import": "./dist/index.esm.js", | ||
"default": "./dist/index.js" | ||
}, | ||
"main": "dist/index.js", | ||
@@ -31,18 +36,15 @@ "unpkg": "dist/index.umd.min.js", | ||
"scripts": { | ||
"sync": "tnpm sync" | ||
"build": "npm run clean && rollup -c", | ||
"clean": "rimraf dist", | ||
"sync": "tnpm sync", | ||
"watch": "rollup -c -w" | ||
}, | ||
"dependencies": { | ||
"@antv/g-lite": "workspace:*", | ||
"@antv/util": "^3.3.1", | ||
"tslib": "^2.3.1" | ||
"tslib": "^2.5.3" | ||
}, | ||
"devDependencies": { | ||
"@types/jest": "^25.0.0" | ||
}, | ||
"peerDependencies": { | ||
"@antv/g-lite": "^1.0.0" | ||
}, | ||
"publishConfig": { | ||
"access": "public" | ||
}, | ||
"gitHead": "09b3114354c305562668f22159d9cc35d56c813a" | ||
} | ||
} |
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
No v1
QualityPackage is not semver >=1. This means it is not stable and does not support ^ ranges.
Found 1 instance in 1 package
0
63134
12
394
2
1
+ Added@antv/g-lite@workspace:*
- Removed@antv/g-lite@1.2.24(transitive)
- Removed@antv/g-math@2.0.2(transitive)
- Removedd3-color@1.4.1(transitive)
- Removedeventemitter3@5.0.1(transitive)
- Removedquickselect@2.0.0(transitive)
- Removedrbush@3.0.1(transitive)
Updatedtslib@^2.5.3