@antv/g-plugin-dragndrop 1.6.46 → 1.6.47
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.esm.js +301 -179
- package/dist/index.js +301 -179
- package/dist/index.umd.js +301 -179
- package/dist/index.umd.min.js +1 -1
- package/package.json +2 -2
package/dist/index.umd.js
CHANGED
|
@@ -4,6 +4,27 @@
|
|
|
4
4
|
(global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory((global.G = global.G || {}, global.G.Dragndrop = {}), global.window.G));
|
|
5
5
|
}(this, (function (exports, gLite) { 'use strict';
|
|
6
6
|
|
|
7
|
+
function ownKeys(object, enumerableOnly) {
|
|
8
|
+
var keys = Object.keys(object);
|
|
9
|
+
if (Object.getOwnPropertySymbols) {
|
|
10
|
+
var symbols = Object.getOwnPropertySymbols(object);
|
|
11
|
+
enumerableOnly && (symbols = symbols.filter(function (sym) {
|
|
12
|
+
return Object.getOwnPropertyDescriptor(object, sym).enumerable;
|
|
13
|
+
})), keys.push.apply(keys, symbols);
|
|
14
|
+
}
|
|
15
|
+
return keys;
|
|
16
|
+
}
|
|
17
|
+
function _objectSpread2(target) {
|
|
18
|
+
for (var i = 1; i < arguments.length; i++) {
|
|
19
|
+
var source = null != arguments[i] ? arguments[i] : {};
|
|
20
|
+
i % 2 ? ownKeys(Object(source), !0).forEach(function (key) {
|
|
21
|
+
_defineProperty(target, key, source[key]);
|
|
22
|
+
}) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) {
|
|
23
|
+
Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key));
|
|
24
|
+
});
|
|
25
|
+
}
|
|
26
|
+
return target;
|
|
27
|
+
}
|
|
7
28
|
function _regeneratorRuntime() {
|
|
8
29
|
_regeneratorRuntime = function () {
|
|
9
30
|
return exports;
|
|
@@ -335,24 +356,63 @@
|
|
|
335
356
|
});
|
|
336
357
|
};
|
|
337
358
|
}
|
|
338
|
-
function
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
359
|
+
function _classCallCheck(instance, Constructor) {
|
|
360
|
+
if (!(instance instanceof Constructor)) {
|
|
361
|
+
throw new TypeError("Cannot call a class as a function");
|
|
362
|
+
}
|
|
363
|
+
}
|
|
364
|
+
function _defineProperties(target, props) {
|
|
365
|
+
for (var i = 0; i < props.length; i++) {
|
|
366
|
+
var descriptor = props[i];
|
|
367
|
+
descriptor.enumerable = descriptor.enumerable || false;
|
|
368
|
+
descriptor.configurable = true;
|
|
369
|
+
if ("value" in descriptor) descriptor.writable = true;
|
|
370
|
+
Object.defineProperty(target, _toPropertyKey(descriptor.key), descriptor);
|
|
371
|
+
}
|
|
372
|
+
}
|
|
373
|
+
function _createClass(Constructor, protoProps, staticProps) {
|
|
374
|
+
if (protoProps) _defineProperties(Constructor.prototype, protoProps);
|
|
375
|
+
if (staticProps) _defineProperties(Constructor, staticProps);
|
|
376
|
+
Object.defineProperty(Constructor, "prototype", {
|
|
377
|
+
writable: false
|
|
378
|
+
});
|
|
379
|
+
return Constructor;
|
|
380
|
+
}
|
|
381
|
+
function _defineProperty(obj, key, value) {
|
|
382
|
+
key = _toPropertyKey(key);
|
|
383
|
+
if (key in obj) {
|
|
384
|
+
Object.defineProperty(obj, key, {
|
|
385
|
+
value: value,
|
|
386
|
+
enumerable: true,
|
|
387
|
+
configurable: true,
|
|
388
|
+
writable: true
|
|
389
|
+
});
|
|
390
|
+
} else {
|
|
391
|
+
obj[key] = value;
|
|
392
|
+
}
|
|
393
|
+
return obj;
|
|
394
|
+
}
|
|
395
|
+
function _inherits(subClass, superClass) {
|
|
396
|
+
if (typeof superClass !== "function" && superClass !== null) {
|
|
397
|
+
throw new TypeError("Super expression must either be null or a function");
|
|
398
|
+
}
|
|
399
|
+
subClass.prototype = Object.create(superClass && superClass.prototype, {
|
|
400
|
+
constructor: {
|
|
401
|
+
value: subClass,
|
|
402
|
+
writable: true,
|
|
403
|
+
configurable: true
|
|
347
404
|
}
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
405
|
+
});
|
|
406
|
+
Object.defineProperty(subClass, "prototype", {
|
|
407
|
+
writable: false
|
|
408
|
+
});
|
|
409
|
+
if (superClass) _setPrototypeOf(subClass, superClass);
|
|
351
410
|
}
|
|
352
|
-
function
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
411
|
+
function _getPrototypeOf(o) {
|
|
412
|
+
_getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf.bind() : function _getPrototypeOf(o) {
|
|
413
|
+
return o.__proto__ || Object.getPrototypeOf(o);
|
|
414
|
+
};
|
|
415
|
+
return _getPrototypeOf(o);
|
|
356
416
|
}
|
|
357
417
|
function _setPrototypeOf(o, p) {
|
|
358
418
|
_setPrototypeOf = Object.setPrototypeOf ? Object.setPrototypeOf.bind() : function _setPrototypeOf(o, p) {
|
|
@@ -361,6 +421,59 @@
|
|
|
361
421
|
};
|
|
362
422
|
return _setPrototypeOf(o, p);
|
|
363
423
|
}
|
|
424
|
+
function _isNativeReflectConstruct() {
|
|
425
|
+
if (typeof Reflect === "undefined" || !Reflect.construct) return false;
|
|
426
|
+
if (Reflect.construct.sham) return false;
|
|
427
|
+
if (typeof Proxy === "function") return true;
|
|
428
|
+
try {
|
|
429
|
+
Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {}));
|
|
430
|
+
return true;
|
|
431
|
+
} catch (e) {
|
|
432
|
+
return false;
|
|
433
|
+
}
|
|
434
|
+
}
|
|
435
|
+
function _assertThisInitialized(self) {
|
|
436
|
+
if (self === void 0) {
|
|
437
|
+
throw new ReferenceError("this hasn't been initialised - super() hasn't been called");
|
|
438
|
+
}
|
|
439
|
+
return self;
|
|
440
|
+
}
|
|
441
|
+
function _possibleConstructorReturn(self, call) {
|
|
442
|
+
if (call && (typeof call === "object" || typeof call === "function")) {
|
|
443
|
+
return call;
|
|
444
|
+
} else if (call !== void 0) {
|
|
445
|
+
throw new TypeError("Derived constructors may only return object or undefined");
|
|
446
|
+
}
|
|
447
|
+
return _assertThisInitialized(self);
|
|
448
|
+
}
|
|
449
|
+
function _createSuper(Derived) {
|
|
450
|
+
var hasNativeReflectConstruct = _isNativeReflectConstruct();
|
|
451
|
+
return function _createSuperInternal() {
|
|
452
|
+
var Super = _getPrototypeOf(Derived),
|
|
453
|
+
result;
|
|
454
|
+
if (hasNativeReflectConstruct) {
|
|
455
|
+
var NewTarget = _getPrototypeOf(this).constructor;
|
|
456
|
+
result = Reflect.construct(Super, arguments, NewTarget);
|
|
457
|
+
} else {
|
|
458
|
+
result = Super.apply(this, arguments);
|
|
459
|
+
}
|
|
460
|
+
return _possibleConstructorReturn(this, result);
|
|
461
|
+
};
|
|
462
|
+
}
|
|
463
|
+
function _toPrimitive(input, hint) {
|
|
464
|
+
if (typeof input !== "object" || input === null) return input;
|
|
465
|
+
var prim = input[Symbol.toPrimitive];
|
|
466
|
+
if (prim !== undefined) {
|
|
467
|
+
var res = prim.call(input, hint || "default");
|
|
468
|
+
if (typeof res !== "object") return res;
|
|
469
|
+
throw new TypeError("@@toPrimitive must return a primitive value.");
|
|
470
|
+
}
|
|
471
|
+
return (hint === "string" ? String : Number)(input);
|
|
472
|
+
}
|
|
473
|
+
function _toPropertyKey(arg) {
|
|
474
|
+
var key = _toPrimitive(arg, "string");
|
|
475
|
+
return typeof key === "symbol" ? key : String(key);
|
|
476
|
+
}
|
|
364
477
|
|
|
365
478
|
function distanceSquareRoot(a, b) {
|
|
366
479
|
return Math.sqrt((a[0] - b[0]) * (a[0] - b[0]) + (a[1] - b[1]) * (a[1] - b[1]));
|
|
@@ -368,189 +481,198 @@
|
|
|
368
481
|
|
|
369
482
|
var DragndropPlugin = /*#__PURE__*/function () {
|
|
370
483
|
function DragndropPlugin(dragndropPluginOptions) {
|
|
484
|
+
_classCallCheck(this, DragndropPlugin);
|
|
371
485
|
this.dragndropPluginOptions = void 0;
|
|
372
486
|
this.dragndropPluginOptions = dragndropPluginOptions;
|
|
373
487
|
}
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
var
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
var
|
|
399
|
-
var
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
timeElapsed = event.timeStamp - dragstartTimeStamp;
|
|
408
|
-
distanceMoved = distanceSquareRoot([event.clientX, event.clientY], dragstartClientCoordinates); // check thresholds
|
|
409
|
-
if (!(timeElapsed <= _this.dragndropPluginOptions.dragstartTimeThreshold || distanceMoved <= _this.dragndropPluginOptions.dragstartDistanceThreshold)) {
|
|
410
|
-
_context.next = 5;
|
|
411
|
-
break;
|
|
412
|
-
}
|
|
413
|
-
return _context.abrupt("return");
|
|
414
|
-
case 5:
|
|
415
|
-
// @see https://developer.mozilla.org/zh-CN/docs/Web/API/Document/dragstart_event
|
|
416
|
-
event.type = 'dragstart';
|
|
417
|
-
draggableEventTarget.dispatchEvent(event);
|
|
418
|
-
dragstartTriggered = true;
|
|
419
|
-
case 8:
|
|
420
|
-
// @see https://developer.mozilla.org/zh-CN/docs/Web/API/Document/drag_event
|
|
421
|
-
event.type = 'drag';
|
|
422
|
-
// @ts-ignore
|
|
423
|
-
event.dx = event.clientX - lastDragClientCoordinates[0];
|
|
424
|
-
// @ts-ignore
|
|
425
|
-
event.dy = event.clientY - lastDragClientCoordinates[1];
|
|
426
|
-
draggableEventTarget.dispatchEvent(event);
|
|
427
|
-
lastDragClientCoordinates = [event.clientX, event.clientY];
|
|
428
|
-
if (isDocument) {
|
|
429
|
-
_context.next = 21;
|
|
430
|
-
break;
|
|
431
|
-
}
|
|
432
|
-
point = _this.dragndropPluginOptions.overlap === 'pointer' ? [event.canvasX, event.canvasY] : target.getBounds().center;
|
|
433
|
-
_context.next = 17;
|
|
434
|
-
return document.elementsFromPoint(point[0], point[1]);
|
|
435
|
-
case 17:
|
|
436
|
-
elementsBelow = _context.sent;
|
|
437
|
-
// prevent from picking the dragging element
|
|
438
|
-
elementBelow = elementsBelow[elementsBelow.indexOf(target) + 1];
|
|
439
|
-
droppableBelow = (elementBelow === null || elementBelow === void 0 ? void 0 : elementBelow.closest('[droppable=true]')) || (_this.dragndropPluginOptions.isDocumentDroppable ? document : null);
|
|
440
|
-
if (currentDroppable !== droppableBelow) {
|
|
441
|
-
if (currentDroppable) {
|
|
442
|
-
// null when we were not over a droppable before this event
|
|
443
|
-
// @see https://developer.mozilla.org/zh-CN/docs/Web/API/Document/dragleave_event
|
|
444
|
-
event.type = 'dragleave';
|
|
445
|
-
event.target = currentDroppable;
|
|
446
|
-
currentDroppable.dispatchEvent(event);
|
|
488
|
+
_createClass(DragndropPlugin, [{
|
|
489
|
+
key: "apply",
|
|
490
|
+
value: function apply(context) {
|
|
491
|
+
var _this = this;
|
|
492
|
+
var renderingService = context.renderingService,
|
|
493
|
+
renderingContext = context.renderingContext;
|
|
494
|
+
var document = renderingContext.root.ownerDocument;
|
|
495
|
+
// TODO: should we add an option like `draggable` to Canvas
|
|
496
|
+
var canvas = document.defaultView;
|
|
497
|
+
var handlePointerdown = function handlePointerdown(event) {
|
|
498
|
+
var target = event.target;
|
|
499
|
+
var isDocument = target === document;
|
|
500
|
+
var draggableEventTarget = isDocument && _this.dragndropPluginOptions.isDocumentDraggable ? document : target.closest && target.closest('[draggable=true]');
|
|
501
|
+
// `draggable` may be set on ancestor nodes:
|
|
502
|
+
// @see https://github.com/antvis/G/issues/1088
|
|
503
|
+
if (draggableEventTarget) {
|
|
504
|
+
// delay triggering dragstart event
|
|
505
|
+
var dragstartTriggered = false;
|
|
506
|
+
var dragstartTimeStamp = event.timeStamp;
|
|
507
|
+
var dragstartClientCoordinates = [event.clientX, event.clientY];
|
|
508
|
+
var currentDroppable = null;
|
|
509
|
+
var lastDragClientCoordinates = [event.clientX, event.clientY];
|
|
510
|
+
// @ts-ignore
|
|
511
|
+
// eslint-disable-next-line no-inner-declarations
|
|
512
|
+
var handlePointermove = /*#__PURE__*/function () {
|
|
513
|
+
var _ref = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee(event) {
|
|
514
|
+
var timeElapsed, distanceMoved, point, elementsBelow, elementBelow, droppableBelow;
|
|
515
|
+
return _regeneratorRuntime().wrap(function _callee$(_context) {
|
|
516
|
+
while (1) switch (_context.prev = _context.next) {
|
|
517
|
+
case 0:
|
|
518
|
+
if (dragstartTriggered) {
|
|
519
|
+
_context.next = 8;
|
|
520
|
+
break;
|
|
447
521
|
}
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
522
|
+
timeElapsed = event.timeStamp - dragstartTimeStamp;
|
|
523
|
+
distanceMoved = distanceSquareRoot([event.clientX, event.clientY], dragstartClientCoordinates); // check thresholds
|
|
524
|
+
if (!(timeElapsed <= _this.dragndropPluginOptions.dragstartTimeThreshold || distanceMoved <= _this.dragndropPluginOptions.dragstartDistanceThreshold)) {
|
|
525
|
+
_context.next = 5;
|
|
526
|
+
break;
|
|
453
527
|
}
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
528
|
+
return _context.abrupt("return");
|
|
529
|
+
case 5:
|
|
530
|
+
// @see https://developer.mozilla.org/zh-CN/docs/Web/API/Document/dragstart_event
|
|
531
|
+
event.type = 'dragstart';
|
|
532
|
+
draggableEventTarget.dispatchEvent(event);
|
|
533
|
+
dragstartTriggered = true;
|
|
534
|
+
case 8:
|
|
535
|
+
// @see https://developer.mozilla.org/zh-CN/docs/Web/API/Document/drag_event
|
|
536
|
+
event.type = 'drag';
|
|
537
|
+
// @ts-ignore
|
|
538
|
+
event.dx = event.clientX - lastDragClientCoordinates[0];
|
|
539
|
+
// @ts-ignore
|
|
540
|
+
event.dy = event.clientY - lastDragClientCoordinates[1];
|
|
541
|
+
draggableEventTarget.dispatchEvent(event);
|
|
542
|
+
lastDragClientCoordinates = [event.clientX, event.clientY];
|
|
543
|
+
if (isDocument) {
|
|
544
|
+
_context.next = 21;
|
|
545
|
+
break;
|
|
461
546
|
}
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
|
|
547
|
+
point = _this.dragndropPluginOptions.overlap === 'pointer' ? [event.canvasX, event.canvasY] : target.getBounds().center;
|
|
548
|
+
_context.next = 17;
|
|
549
|
+
return document.elementsFromPoint(point[0], point[1]);
|
|
550
|
+
case 17:
|
|
551
|
+
elementsBelow = _context.sent;
|
|
552
|
+
// prevent from picking the dragging element
|
|
553
|
+
elementBelow = elementsBelow[elementsBelow.indexOf(target) + 1];
|
|
554
|
+
droppableBelow = (elementBelow === null || elementBelow === void 0 ? void 0 : elementBelow.closest('[droppable=true]')) || (_this.dragndropPluginOptions.isDocumentDroppable ? document : null);
|
|
555
|
+
if (currentDroppable !== droppableBelow) {
|
|
556
|
+
if (currentDroppable) {
|
|
557
|
+
// null when we were not over a droppable before this event
|
|
558
|
+
// @see https://developer.mozilla.org/zh-CN/docs/Web/API/Document/dragleave_event
|
|
559
|
+
event.type = 'dragleave';
|
|
560
|
+
event.target = currentDroppable;
|
|
561
|
+
currentDroppable.dispatchEvent(event);
|
|
562
|
+
}
|
|
563
|
+
if (droppableBelow) {
|
|
564
|
+
// @see https://developer.mozilla.org/zh-CN/docs/Web/API/Document/dragleave_event
|
|
565
|
+
event.type = 'dragenter';
|
|
566
|
+
event.target = droppableBelow;
|
|
567
|
+
droppableBelow.dispatchEvent(event);
|
|
568
|
+
}
|
|
569
|
+
currentDroppable = droppableBelow;
|
|
570
|
+
if (currentDroppable) {
|
|
571
|
+
// null if we're not coming over a droppable now
|
|
572
|
+
// @see https://developer.mozilla.org/zh-CN/docs/Web/API/Document/dragover_event
|
|
573
|
+
event.type = 'dragover';
|
|
574
|
+
event.target = currentDroppable;
|
|
575
|
+
currentDroppable.dispatchEvent(event);
|
|
576
|
+
}
|
|
577
|
+
}
|
|
578
|
+
case 21:
|
|
579
|
+
case "end":
|
|
580
|
+
return _context.stop();
|
|
581
|
+
}
|
|
582
|
+
}, _callee);
|
|
583
|
+
}));
|
|
584
|
+
return function handlePointermove(_x) {
|
|
585
|
+
return _ref.apply(this, arguments);
|
|
480
586
|
};
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
// @see https://
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
|
|
587
|
+
}();
|
|
588
|
+
canvas.addEventListener('pointermove', handlePointermove);
|
|
589
|
+
var stopDragging = function stopDragging(originalPointerUpEvent) {
|
|
590
|
+
if (dragstartTriggered) {
|
|
591
|
+
// prevent click event being triggerd
|
|
592
|
+
// @see https://github.com/antvis/G/issues/1091
|
|
593
|
+
originalPointerUpEvent.detail = {
|
|
594
|
+
preventClick: true
|
|
595
|
+
};
|
|
596
|
+
// clone event first
|
|
597
|
+
var _event = originalPointerUpEvent.clone();
|
|
598
|
+
// drop should fire before dragend
|
|
599
|
+
// @see https://javascript.tutorialink.com/is-there-a-defined-ordering-between-dragend-and-drop-events/
|
|
600
|
+
if (currentDroppable) {
|
|
601
|
+
// @see https://developer.mozilla.org/zh-CN/docs/Web/API/Document/drop_event
|
|
602
|
+
_event.type = 'drop';
|
|
603
|
+
_event.target = currentDroppable;
|
|
604
|
+
currentDroppable.dispatchEvent(_event);
|
|
605
|
+
}
|
|
606
|
+
// @see https://developer.mozilla.org/zh-CN/docs/Web/API/Document/dragend_event
|
|
607
|
+
_event.type = 'dragend';
|
|
608
|
+
draggableEventTarget.dispatchEvent(_event);
|
|
609
|
+
dragstartTriggered = false;
|
|
490
610
|
}
|
|
491
|
-
|
|
492
|
-
|
|
493
|
-
|
|
494
|
-
|
|
495
|
-
}
|
|
496
|
-
|
|
497
|
-
|
|
498
|
-
|
|
499
|
-
once: true
|
|
500
|
-
});
|
|
501
|
-
target.addEventListener('pointerupoutside', stopDragging, {
|
|
502
|
-
once: true
|
|
503
|
-
});
|
|
504
|
-
}
|
|
505
|
-
};
|
|
506
|
-
renderingService.hooks.init.tapPromise(DragndropPlugin.tag, /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee2() {
|
|
507
|
-
return _regeneratorRuntime().wrap(function _callee2$(_context2) {
|
|
508
|
-
while (1) switch (_context2.prev = _context2.next) {
|
|
509
|
-
case 0:
|
|
510
|
-
canvas.addEventListener('pointerdown', handlePointerdown);
|
|
511
|
-
case 1:
|
|
512
|
-
case "end":
|
|
513
|
-
return _context2.stop();
|
|
611
|
+
canvas.removeEventListener('pointermove', handlePointermove);
|
|
612
|
+
};
|
|
613
|
+
target.addEventListener('pointerup', stopDragging, {
|
|
614
|
+
once: true
|
|
615
|
+
});
|
|
616
|
+
target.addEventListener('pointerupoutside', stopDragging, {
|
|
617
|
+
once: true
|
|
618
|
+
});
|
|
514
619
|
}
|
|
515
|
-
}
|
|
516
|
-
|
|
517
|
-
|
|
518
|
-
|
|
519
|
-
|
|
520
|
-
|
|
620
|
+
};
|
|
621
|
+
renderingService.hooks.init.tapPromise(DragndropPlugin.tag, /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee2() {
|
|
622
|
+
return _regeneratorRuntime().wrap(function _callee2$(_context2) {
|
|
623
|
+
while (1) switch (_context2.prev = _context2.next) {
|
|
624
|
+
case 0:
|
|
625
|
+
canvas.addEventListener('pointerdown', handlePointerdown);
|
|
626
|
+
case 1:
|
|
627
|
+
case "end":
|
|
628
|
+
return _context2.stop();
|
|
629
|
+
}
|
|
630
|
+
}, _callee2);
|
|
631
|
+
})));
|
|
632
|
+
renderingService.hooks.destroy.tap(DragndropPlugin.tag, function () {
|
|
633
|
+
canvas.removeEventListener('pointerdown', handlePointerdown);
|
|
634
|
+
});
|
|
635
|
+
}
|
|
636
|
+
}]);
|
|
521
637
|
return DragndropPlugin;
|
|
522
638
|
}();
|
|
523
639
|
DragndropPlugin.tag = 'Dragndrop';
|
|
524
640
|
|
|
525
641
|
var Plugin = /*#__PURE__*/function (_AbstractRendererPlug) {
|
|
526
|
-
|
|
527
|
-
|
|
642
|
+
_inherits(Plugin, _AbstractRendererPlug);
|
|
643
|
+
var _super = _createSuper(Plugin);
|
|
644
|
+
function Plugin() {
|
|
528
645
|
var _this;
|
|
529
|
-
|
|
530
|
-
|
|
531
|
-
|
|
532
|
-
_this = _AbstractRendererPlug.call(this) || this;
|
|
646
|
+
var options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
|
|
647
|
+
_classCallCheck(this, Plugin);
|
|
648
|
+
_this = _super.call(this);
|
|
533
649
|
_this.options = void 0;
|
|
534
650
|
_this.name = 'dragndrop';
|
|
535
651
|
_this.options = options;
|
|
536
652
|
return _this;
|
|
537
653
|
}
|
|
538
|
-
|
|
539
|
-
|
|
540
|
-
|
|
541
|
-
|
|
542
|
-
|
|
543
|
-
|
|
544
|
-
|
|
545
|
-
|
|
546
|
-
|
|
547
|
-
|
|
548
|
-
|
|
549
|
-
|
|
550
|
-
|
|
551
|
-
|
|
552
|
-
|
|
553
|
-
|
|
654
|
+
_createClass(Plugin, [{
|
|
655
|
+
key: "init",
|
|
656
|
+
value: function init() {
|
|
657
|
+
this.addRenderingPlugin(new DragndropPlugin(_objectSpread2({
|
|
658
|
+
overlap: 'pointer',
|
|
659
|
+
isDocumentDraggable: false,
|
|
660
|
+
isDocumentDroppable: false,
|
|
661
|
+
dragstartDistanceThreshold: 0,
|
|
662
|
+
dragstartTimeThreshold: 0
|
|
663
|
+
}, this.options)));
|
|
664
|
+
}
|
|
665
|
+
}, {
|
|
666
|
+
key: "destroy",
|
|
667
|
+
value: function destroy() {
|
|
668
|
+
this.removeAllRenderingPlugins();
|
|
669
|
+
}
|
|
670
|
+
}, {
|
|
671
|
+
key: "setOptions",
|
|
672
|
+
value: function setOptions(options) {
|
|
673
|
+
Object.assign(this.plugins[0].dragndropPluginOptions, options);
|
|
674
|
+
}
|
|
675
|
+
}]);
|
|
554
676
|
return Plugin;
|
|
555
677
|
}(gLite.AbstractRendererPlugin);
|
|
556
678
|
|
package/dist/index.umd.min.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
!function(t,e){"object"==typeof exports&&"undefined"!=typeof module?e(exports,require("@antv/g-lite")):"function"==typeof define&&define.amd?define(["exports","@antv/g-lite"],e):e(((t="undefined"!=typeof globalThis?globalThis:t||self).G=t.G||{},t.G.Dragndrop={}),t.window.G)}(this,(function(t,e){"use strict";function r(){r=function(){return t};var t={},e=Object.prototype,n=e.hasOwnProperty,o=Object.defineProperty||function(t,e,r){t[e]=r.value},i="function"==typeof Symbol?Symbol:{},a=i.iterator||"@@iterator",c=i.asyncIterator||"@@asyncIterator",u=i.toStringTag||"@@toStringTag";function s(t,e,r){return Object.defineProperty(t,e,{value:r,enumerable:!0,configurable:!0,writable:!0}),t[e]}try{s({},"")}catch(t){s=function(t,e,r){return t[e]=r}}function l(t,e,r,n){var i=Object.create((e&&e.prototype instanceof h?e:h).prototype),a=new j(n||[]);return o(i,"_invoke",{value:E(t,r,a)}),i}function p(t,e,r){try{return{type:"normal",arg:t.call(e,r)}}catch(t){return{type:"throw",arg:t}}}t.wrap=l;var f={};function h(){}function d(){}function v(){}var g={};s(g,a,(function(){return this}));var y=Object.getPrototypeOf,m=y&&y(y(_([])));m&&m!==e&&n.call(m,a)&&(g=m);var w=v.prototype=h.prototype=Object.create(g);function b(t){["next","throw","return"].forEach((function(e){s(t,e,(function(t){return this._invoke(e,t)}))}))}function x(t,e){function r(o,i,a,c){var u=p(t[o],t,i);if("throw"!==u.type){var s=u.arg,l=s.value;return l&&"object"==typeof l&&n.call(l,"__await")?e.resolve(l.__await).then((function(t){r("next",t,a,c)}),(function(t){r("throw",t,a,c)})):e.resolve(l).then((function(t){s.value=t,a(s)}),(function(t){return r("throw",t,a,c)}))}c(u.arg)}var i;o(this,"_invoke",{value:function(t,n){function o(){return new e((function(e,o){r(t,n,e,o)}))}return i=i?i.then(o,o):o()}})}function E(t,e,r){var n="suspendedStart";return function(o,i){if("executing"===n)throw Error("Generator is already running");if("completed"===n){if("throw"===o)throw i;return k()}for(r.method=o,r.arg=i;;){var a=r.delegate;if(a){var c=O(a,r);if(c){if(c===f)continue;return c}}if("next"===r.method)r.sent=r._sent=r.arg;else if("throw"===r.method){if("suspendedStart"===n)throw n="completed",r.arg;r.dispatchException(r.arg)}else"return"===r.method&&r.abrupt("return",r.arg);n="executing";var u=p(t,e,r);if("normal"===u.type){if(n=r.done?"completed":"suspendedYield",u.arg===f)continue;return{value:u.arg,done:r.done}}"throw"===u.type&&(n="completed",r.method="throw",r.arg=u.arg)}}}function O(t,e){var r=e.method,n=t.iterator[r];if(void 0===n)return e.delegate=null,"throw"===r&&t.iterator.return&&(e.method="return",e.arg=void 0,O(t,e),"throw"===e.method)||"return"!==r&&(e.method="throw",e.arg=new TypeError("The iterator does not provide a '"+r+"' method")),f;var o=p(n,t.iterator,e.arg);if("throw"===o.type)return e.method="throw",e.arg=o.arg,e.delegate=null,f;var i=o.arg;return i?i.done?(e[t.resultName]=i.value,e.next=t.nextLoc,"return"!==e.method&&(e.method="next",e.arg=void 0),e.delegate=null,f):i:(e.method="throw",e.arg=new TypeError("iterator result is not an object"),e.delegate=null,f)}function L(t){var e={tryLoc:t[0]};1 in t&&(e.catchLoc=t[1]),2 in t&&(e.finallyLoc=t[2],e.afterLoc=t[3]),this.tryEntries.push(e)}function P(t){var e=t.completion||{};e.type="normal",delete e.arg,t.completion=e}function j(t){this.tryEntries=[{tryLoc:"root"}],t.forEach(L,this),this.reset(!0)}function _(t){if(t){var e=t[a];if(e)return e.call(t);if("function"==typeof t.next)return t;if(!isNaN(t.length)){var r=-1,o=function e(){for(;++r<t.length;)if(n.call(t,r))return e.value=t[r],e.done=!1,e;return e.value=void 0,e.done=!0,e};return o.next=o}}return{next:k}}function k(){return{value:void 0,done:!0}}return d.prototype=v,o(w,"constructor",{value:v,configurable:!0}),o(v,"constructor",{value:d,configurable:!0}),d.displayName=s(v,u,"GeneratorFunction"),t.isGeneratorFunction=function(t){var e="function"==typeof t&&t.constructor;return!!e&&(e===d||"GeneratorFunction"===(e.displayName||e.name))},t.mark=function(t){return Object.setPrototypeOf?Object.setPrototypeOf(t,v):(t.__proto__=v,s(t,u,"GeneratorFunction")),t.prototype=Object.create(w),t},t.awrap=function(t){return{__await:t}},b(x.prototype),s(x.prototype,c,(function(){return this})),t.AsyncIterator=x,t.async=function(e,r,n,o,i){void 0===i&&(i=Promise);var a=new x(l(e,r,n,o),i);return t.isGeneratorFunction(r)?a:a.next().then((function(t){return t.done?t.value:a.next()}))},b(w),s(w,u,"Generator"),s(w,a,(function(){return this})),s(w,"toString",(function(){return"[object Generator]"})),t.keys=function(t){var e=Object(t),r=[];for(var n in e)r.push(n);return r.reverse(),function t(){for(;r.length;){var n=r.pop();if(n in e)return t.value=n,t.done=!1,t}return t.done=!0,t}},t.values=_,j.prototype={constructor:j,reset:function(t){if(this.prev=0,this.next=0,this.sent=this._sent=void 0,this.done=!1,this.delegate=null,this.method="next",this.arg=void 0,this.tryEntries.forEach(P),!t)for(var e in this)"t"===e.charAt(0)&&n.call(this,e)&&!isNaN(+e.slice(1))&&(this[e]=void 0)},stop:function(){this.done=!0;var t=this.tryEntries[0].completion;if("throw"===t.type)throw t.arg;return this.rval},dispatchException:function(t){if(this.done)throw t;var e=this;function r(r,n){return a.type="throw",a.arg=t,e.next=r,n&&(e.method="next",e.arg=void 0),!!n}for(var o=this.tryEntries.length-1;o>=0;--o){var i=this.tryEntries[o],a=i.completion;if("root"===i.tryLoc)return r("end");if(this.prev>=i.tryLoc){var c=n.call(i,"catchLoc"),u=n.call(i,"finallyLoc");if(c&&u){if(i.catchLoc>this.prev)return r(i.catchLoc,!0);if(i.finallyLoc>this.prev)return r(i.finallyLoc)}else if(c){if(i.catchLoc>this.prev)return r(i.catchLoc,!0)}else{if(!u)throw Error("try statement without catch or finally");if(i.finallyLoc>this.prev)return r(i.finallyLoc)}}}},abrupt:function(t,e){for(var r=this.tryEntries.length-1;r>=0;--r){var o=this.tryEntries[r];if(this.prev>=o.tryLoc&&n.call(o,"finallyLoc")&&o.finallyLoc>this.prev){var i=o;break}}i&&("break"===t||"continue"===t)&&e>=i.tryLoc&&i.finallyLoc>=e&&(i=null);var a=i?i.completion:{};return a.type=t,a.arg=e,i?(this.method="next",this.next=i.finallyLoc,f):this.complete(a)},complete:function(t,e){if("throw"===t.type)throw t.arg;return"break"===t.type||"continue"===t.type?this.next=t.arg:"return"===t.type?(this.rval=this.arg=t.arg,this.method="return",this.next="end"):"normal"===t.type&&e&&(this.next=e),f},finish:function(t){for(var e=this.tryEntries.length-1;e>=0;--e){var r=this.tryEntries[e];if(r.finallyLoc===t)return this.complete(r.completion,r.afterLoc),P(r),f}},catch:function(t){for(var e=this.tryEntries.length-1;e>=0;--e){var r=this.tryEntries[e];if(r.tryLoc===t){var n=r.completion;if("throw"===n.type){var o=n.arg;P(r)}return o}}throw Error("illegal catch attempt")},delegateYield:function(t,e,r){return this.delegate={iterator:_(t),resultName:e,nextLoc:r},"next"===this.method&&(this.arg=void 0),f}},t}function n(t,e,r,n,o,i,a){try{var c=t[i](a),u=c.value}catch(t){return void r(t)}c.done?e(u):Promise.resolve(u).then(n,o)}function o(t){return function(){var e=this,r=arguments;return new Promise((function(o,i){var a=t.apply(e,r);function c(t){n(a,o,i,c,u,"next",t)}function u(t){n(a,o,i,c,u,"throw",t)}c(void 0)}))}}function i(){return i=Object.assign?Object.assign.bind():function(t){for(var e=1;arguments.length>e;e++){var r=arguments[e];for(var n in r)Object.prototype.hasOwnProperty.call(r,n)&&(t[n]=r[n])}return t},i.apply(this,arguments)}function a(t,e){return a=Object.setPrototypeOf?Object.setPrototypeOf.bind():function(t,e){return t.__proto__=e,t},a(t,e)}var c=function(){function t(t){this.dragndropPluginOptions=void 0,this.dragndropPluginOptions=t}return t.prototype.apply=function(e){var n=this,i=e.renderingService,a=e.renderingContext.root.ownerDocument,c=a.defaultView,u=function(t){var e=t.target,i=e===a,u=i&&n.dragndropPluginOptions.isDocumentDraggable?a:e.closest&&e.closest("[draggable=true]");if(u){var s=!1,l=t.timeStamp,p=[t.clientX,t.clientY],f=null,h=[t.clientX,t.clientY],d=function(){var t=o(r().mark((function t(o){var c,d,v,g,y,m;return r().wrap((function(t){for(;;)switch(t.prev=t.next){case 0:if(s){t.next=8;break}if(c=o.timeStamp-l,d=Math.sqrt(((r=[o.clientX,o.clientY])[0]-(w=p)[0])*(r[0]-w[0])+(r[1]-w[1])*(r[1]-w[1])),c>n.dragndropPluginOptions.dragstartTimeThreshold&&d>n.dragndropPluginOptions.dragstartDistanceThreshold){t.next=5;break}return t.abrupt("return");case 5:o.type="dragstart",u.dispatchEvent(o),s=!0;case 8:if(o.type="drag",o.dx=o.clientX-h[0],o.dy=o.clientY-h[1],u.dispatchEvent(o),h=[o.clientX,o.clientY],i){t.next=21;break}return v="pointer"===n.dragndropPluginOptions.overlap?[o.canvasX,o.canvasY]:e.getBounds().center,t.next=17,a.elementsFromPoint(v[0],v[1]);case 17:y=(g=t.sent)[g.indexOf(e)+1],m=(null==y?void 0:y.closest("[droppable=true]"))||(n.dragndropPluginOptions.isDocumentDroppable?a:null),f!==m&&(f&&(o.type="dragleave",o.target=f,f.dispatchEvent(o)),m&&(o.type="dragenter",o.target=m,m.dispatchEvent(o)),(f=m)&&(o.type="dragover",o.target=f,f.dispatchEvent(o)));case 21:case"end":return t.stop()}var r,w}),t)})));return function(e){return t.apply(this,arguments)}}();c.addEventListener("pointermove",d);var v=function(t){if(s){t.detail={preventClick:!0};var e=t.clone();f&&(e.type="drop",e.target=f,f.dispatchEvent(e)),e.type="dragend",u.dispatchEvent(e),s=!1}c.removeEventListener("pointermove",d)};e.addEventListener("pointerup",v,{once:!0}),e.addEventListener("pointerupoutside",v,{once:!0})}};i.hooks.init.tapPromise(t.tag,o(r().mark((function t(){return r().wrap((function(t){for(;;)switch(t.prev=t.next){case 0:c.addEventListener("pointerdown",u);case 1:case"end":return t.stop()}}),t)})))),i.hooks.destroy.tap(t.tag,(function(){c.removeEventListener("pointerdown",u)}))},t}();c.tag="Dragndrop",t.Plugin=function(t){var e,r;function n(e){var r;return void 0===e&&(e={}),(r=t.call(this)||this).options=void 0,r.name="dragndrop",r.options=e,r}(e=n).prototype=Object.create((r=t).prototype),e.prototype.constructor=e,a(e,r);var o=n.prototype;return o.init=function(){this.addRenderingPlugin(new c(i({overlap:"pointer",isDocumentDraggable:!1,isDocumentDroppable:!1,dragstartDistanceThreshold:0,dragstartTimeThreshold:0},this.options)))},o.destroy=function(){this.removeAllRenderingPlugins()},o.setOptions=function(t){Object.assign(this.plugins[0].dragndropPluginOptions,t)},n}(e.AbstractRendererPlugin),Object.defineProperty(t,"__esModule",{value:!0})}));
|
|
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(t,e){var r=Object.keys(t);if(Object.getOwnPropertySymbols){var n=Object.getOwnPropertySymbols(t);e&&(n=n.filter((function(e){return Object.getOwnPropertyDescriptor(t,e).enumerable}))),r.push.apply(r,n)}return r}function n(){n=function(){return t};var t={},e=Object.prototype,r=e.hasOwnProperty,o=Object.defineProperty||function(t,e,r){t[e]=r.value},i="function"==typeof Symbol?Symbol:{},a=i.iterator||"@@iterator",c=i.asyncIterator||"@@asyncIterator",u=i.toStringTag||"@@toStringTag";function s(t,e,r){return Object.defineProperty(t,e,{value:r,enumerable:!0,configurable:!0,writable:!0}),t[e]}try{s({},"")}catch(t){s=function(t,e,r){return t[e]=r}}function l(t,e,r,n){var i=Object.create((e&&e.prototype instanceof h?e:h).prototype),a=new L(n||[]);return o(i,"_invoke",{value:P(t,r,a)}),i}function f(t,e,r){try{return{type:"normal",arg:t.call(e,r)}}catch(t){return{type:"throw",arg:t}}}t.wrap=l;var p={};function h(){}function d(){}function v(){}var y={};s(y,a,(function(){return this}));var g=Object.getPrototypeOf,m=g&&g(g(_([])));m&&m!==e&&r.call(m,a)&&(y=m);var b=v.prototype=h.prototype=Object.create(y);function w(t){["next","throw","return"].forEach((function(e){s(t,e,(function(t){return this._invoke(e,t)}))}))}function O(t,e){function n(o,i,a,c){var u=f(t[o],t,i);if("throw"!==u.type){var s=u.arg,l=s.value;return l&&"object"==typeof l&&r.call(l,"__await")?e.resolve(l.__await).then((function(t){n("next",t,a,c)}),(function(t){n("throw",t,a,c)})):e.resolve(l).then((function(t){s.value=t,a(s)}),(function(t){return n("throw",t,a,c)}))}c(u.arg)}var i;o(this,"_invoke",{value:function(t,r){function o(){return new e((function(e,o){n(t,r,e,o)}))}return i=i?i.then(o,o):o()}})}function P(t,e,r){var n="suspendedStart";return function(o,i){if("executing"===n)throw Error("Generator is already running");if("completed"===n){if("throw"===o)throw i;return k()}for(r.method=o,r.arg=i;;){var a=r.delegate;if(a){var c=E(a,r);if(c){if(c===p)continue;return c}}if("next"===r.method)r.sent=r._sent=r.arg;else if("throw"===r.method){if("suspendedStart"===n)throw n="completed",r.arg;r.dispatchException(r.arg)}else"return"===r.method&&r.abrupt("return",r.arg);n="executing";var u=f(t,e,r);if("normal"===u.type){if(n=r.done?"completed":"suspendedYield",u.arg===p)continue;return{value:u.arg,done:r.done}}"throw"===u.type&&(n="completed",r.method="throw",r.arg=u.arg)}}}function E(t,e){var r=e.method,n=t.iterator[r];if(void 0===n)return e.delegate=null,"throw"===r&&t.iterator.return&&(e.method="return",e.arg=void 0,E(t,e),"throw"===e.method)||"return"!==r&&(e.method="throw",e.arg=new TypeError("The iterator does not provide a '"+r+"' method")),p;var o=f(n,t.iterator,e.arg);if("throw"===o.type)return e.method="throw",e.arg=o.arg,e.delegate=null,p;var i=o.arg;return i?i.done?(e[t.resultName]=i.value,e.next=t.nextLoc,"return"!==e.method&&(e.method="next",e.arg=void 0),e.delegate=null,p):i:(e.method="throw",e.arg=new TypeError("iterator result is not an object"),e.delegate=null,p)}function j(t){var e={tryLoc:t[0]};1 in t&&(e.catchLoc=t[1]),2 in t&&(e.finallyLoc=t[2],e.afterLoc=t[3]),this.tryEntries.push(e)}function x(t){var e=t.completion||{};e.type="normal",delete e.arg,t.completion=e}function L(t){this.tryEntries=[{tryLoc:"root"}],t.forEach(j,this),this.reset(!0)}function _(t){if(t){var e=t[a];if(e)return e.call(t);if("function"==typeof t.next)return t;if(!isNaN(t.length)){var n=-1,o=function e(){for(;++n<t.length;)if(r.call(t,n))return e.value=t[n],e.done=!1,e;return e.value=void 0,e.done=!0,e};return o.next=o}}return{next:k}}function k(){return{value:void 0,done:!0}}return d.prototype=v,o(b,"constructor",{value:v,configurable:!0}),o(v,"constructor",{value:d,configurable:!0}),d.displayName=s(v,u,"GeneratorFunction"),t.isGeneratorFunction=function(t){var e="function"==typeof t&&t.constructor;return!!e&&(e===d||"GeneratorFunction"===(e.displayName||e.name))},t.mark=function(t){return Object.setPrototypeOf?Object.setPrototypeOf(t,v):(t.__proto__=v,s(t,u,"GeneratorFunction")),t.prototype=Object.create(b),t},t.awrap=function(t){return{__await:t}},w(O.prototype),s(O.prototype,c,(function(){return this})),t.AsyncIterator=O,t.async=function(e,r,n,o,i){void 0===i&&(i=Promise);var a=new O(l(e,r,n,o),i);return t.isGeneratorFunction(r)?a:a.next().then((function(t){return t.done?t.value:a.next()}))},w(b),s(b,u,"Generator"),s(b,a,(function(){return this})),s(b,"toString",(function(){return"[object Generator]"})),t.keys=function(t){var e=Object(t),r=[];for(var n in e)r.push(n);return r.reverse(),function t(){for(;r.length;){var n=r.pop();if(n in e)return t.value=n,t.done=!1,t}return t.done=!0,t}},t.values=_,L.prototype={constructor:L,reset:function(t){if(this.prev=0,this.next=0,this.sent=this._sent=void 0,this.done=!1,this.delegate=null,this.method="next",this.arg=void 0,this.tryEntries.forEach(x),!t)for(var e in this)"t"===e.charAt(0)&&r.call(this,e)&&!isNaN(+e.slice(1))&&(this[e]=void 0)},stop:function(){this.done=!0;var t=this.tryEntries[0].completion;if("throw"===t.type)throw t.arg;return this.rval},dispatchException:function(t){if(this.done)throw t;var e=this;function n(r,n){return a.type="throw",a.arg=t,e.next=r,n&&(e.method="next",e.arg=void 0),!!n}for(var o=this.tryEntries.length-1;o>=0;--o){var i=this.tryEntries[o],a=i.completion;if("root"===i.tryLoc)return n("end");if(this.prev>=i.tryLoc){var c=r.call(i,"catchLoc"),u=r.call(i,"finallyLoc");if(c&&u){if(i.catchLoc>this.prev)return n(i.catchLoc,!0);if(i.finallyLoc>this.prev)return n(i.finallyLoc)}else if(c){if(i.catchLoc>this.prev)return n(i.catchLoc,!0)}else{if(!u)throw Error("try statement without catch or finally");if(i.finallyLoc>this.prev)return n(i.finallyLoc)}}}},abrupt:function(t,e){for(var n=this.tryEntries.length-1;n>=0;--n){var o=this.tryEntries[n];if(this.prev>=o.tryLoc&&r.call(o,"finallyLoc")&&o.finallyLoc>this.prev){var i=o;break}}i&&("break"===t||"continue"===t)&&e>=i.tryLoc&&i.finallyLoc>=e&&(i=null);var a=i?i.completion:{};return a.type=t,a.arg=e,i?(this.method="next",this.next=i.finallyLoc,p):this.complete(a)},complete:function(t,e){if("throw"===t.type)throw t.arg;return"break"===t.type||"continue"===t.type?this.next=t.arg:"return"===t.type?(this.rval=this.arg=t.arg,this.method="return",this.next="end"):"normal"===t.type&&e&&(this.next=e),p},finish:function(t){for(var e=this.tryEntries.length-1;e>=0;--e){var r=this.tryEntries[e];if(r.finallyLoc===t)return this.complete(r.completion,r.afterLoc),x(r),p}},catch:function(t){for(var e=this.tryEntries.length-1;e>=0;--e){var r=this.tryEntries[e];if(r.tryLoc===t){var n=r.completion;if("throw"===n.type){var o=n.arg;x(r)}return o}}throw Error("illegal catch attempt")},delegateYield:function(t,e,r){return this.delegate={iterator:_(t),resultName:e,nextLoc:r},"next"===this.method&&(this.arg=void 0),p}},t}function o(t,e,r,n,o,i,a){try{var c=t[i](a),u=c.value}catch(t){return void r(t)}c.done?e(u):Promise.resolve(u).then(n,o)}function i(t){return function(){var e=this,r=arguments;return new Promise((function(n,i){var a=t.apply(e,r);function c(t){o(a,n,i,c,u,"next",t)}function u(t){o(a,n,i,c,u,"throw",t)}c(void 0)}))}}function a(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}function c(t,e){for(var r=0;e.length>r;r++){var n=e[r];n.enumerable=n.enumerable||!1,n.configurable=!0,"value"in n&&(n.writable=!0),Object.defineProperty(t,d(n.key),n)}}function u(t,e,r){return e&&c(t.prototype,e),r&&c(t,r),Object.defineProperty(t,"prototype",{writable:!1}),t}function s(t,e,r){return(e=d(e))in t?Object.defineProperty(t,e,{value:r,enumerable:!0,configurable:!0,writable:!0}):t[e]=r,t}function l(t){return l=Object.setPrototypeOf?Object.getPrototypeOf.bind():function(t){return t.__proto__||Object.getPrototypeOf(t)},l(t)}function f(t,e){return f=Object.setPrototypeOf?Object.setPrototypeOf.bind():function(t,e){return t.__proto__=e,t},f(t,e)}function p(t,e){if(e&&("object"==typeof e||"function"==typeof e))return e;if(void 0!==e)throw new TypeError("Derived constructors may only return object or undefined");return function(t){if(void 0===t)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return t}(t)}function h(t){var e=function(){if("undefined"==typeof Reflect||!Reflect.construct)return!1;if(Reflect.construct.sham)return!1;if("function"==typeof Proxy)return!0;try{return Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],(function(){}))),!0}catch(t){return!1}}();return function(){var r,n=l(t);if(e){var o=l(this).constructor;r=Reflect.construct(n,arguments,o)}else r=n.apply(this,arguments);return p(this,r)}}function d(t){var e=function(t,e){if("object"!=typeof t||null===t)return t;var r=t[Symbol.toPrimitive];if(void 0!==r){var n=r.call(t,e||"default");if("object"!=typeof n)return n;throw new TypeError("@@toPrimitive must return a primitive value.")}return("string"===e?String:Number)(t)}(t,"string");return"symbol"==typeof e?e:e+""}var v=function(){function t(e){a(this,t),this.dragndropPluginOptions=void 0,this.dragndropPluginOptions=e}return u(t,[{key:"apply",value:function(e){var r=this,o=e.renderingService,a=e.renderingContext.root.ownerDocument,c=a.defaultView,u=function(t){var e=t.target,o=e===a,u=o&&r.dragndropPluginOptions.isDocumentDraggable?a:e.closest&&e.closest("[draggable=true]");if(u){var s=!1,l=t.timeStamp,f=[t.clientX,t.clientY],p=null,h=[t.clientX,t.clientY],d=function(){var t=i(n().mark((function t(i){var c,d,v,y,g,m;return n().wrap((function(t){for(;;)switch(t.prev=t.next){case 0:if(s){t.next=8;break}if(c=i.timeStamp-l,d=Math.sqrt(((n=[i.clientX,i.clientY])[0]-(b=f)[0])*(n[0]-b[0])+(n[1]-b[1])*(n[1]-b[1])),c>r.dragndropPluginOptions.dragstartTimeThreshold&&d>r.dragndropPluginOptions.dragstartDistanceThreshold){t.next=5;break}return t.abrupt("return");case 5:i.type="dragstart",u.dispatchEvent(i),s=!0;case 8:if(i.type="drag",i.dx=i.clientX-h[0],i.dy=i.clientY-h[1],u.dispatchEvent(i),h=[i.clientX,i.clientY],o){t.next=21;break}return v="pointer"===r.dragndropPluginOptions.overlap?[i.canvasX,i.canvasY]:e.getBounds().center,t.next=17,a.elementsFromPoint(v[0],v[1]);case 17:g=(y=t.sent)[y.indexOf(e)+1],m=(null==g?void 0:g.closest("[droppable=true]"))||(r.dragndropPluginOptions.isDocumentDroppable?a:null),p!==m&&(p&&(i.type="dragleave",i.target=p,p.dispatchEvent(i)),m&&(i.type="dragenter",i.target=m,m.dispatchEvent(i)),(p=m)&&(i.type="dragover",i.target=p,p.dispatchEvent(i)));case 21:case"end":return t.stop()}var n,b}),t)})));return function(e){return t.apply(this,arguments)}}();c.addEventListener("pointermove",d);var v=function(t){if(s){t.detail={preventClick:!0};var e=t.clone();p&&(e.type="drop",e.target=p,p.dispatchEvent(e)),e.type="dragend",u.dispatchEvent(e),s=!1}c.removeEventListener("pointermove",d)};e.addEventListener("pointerup",v,{once:!0}),e.addEventListener("pointerupoutside",v,{once:!0})}};o.hooks.init.tapPromise(t.tag,i(n().mark((function t(){return n().wrap((function(t){for(;;)switch(t.prev=t.next){case 0:c.addEventListener("pointerdown",u);case 1:case"end":return t.stop()}}),t)})))),o.hooks.destroy.tap(t.tag,(function(){c.removeEventListener("pointerdown",u)}))}}]),t}();v.tag="Dragndrop";var y=function(t){!function(t,e){if("function"!=typeof e&&null!==e)throw new TypeError("Super expression must either be null or a function");t.prototype=Object.create(e&&e.prototype,{constructor:{value:t,writable:!0,configurable:!0}}),Object.defineProperty(t,"prototype",{writable:!1}),e&&f(t,e)}(n,t);var e=h(n);function n(){var t,r=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};return a(this,n),(t=e.call(this)).options=void 0,t.name="dragndrop",t.options=r,t}return u(n,[{key:"init",value:function(){this.addRenderingPlugin(new v(function(t){for(var e=1;arguments.length>e;e++){var n=null!=arguments[e]?arguments[e]:{};e%2?r(Object(n),!0).forEach((function(e){s(t,e,n[e])})):Object.getOwnPropertyDescriptors?Object.defineProperties(t,Object.getOwnPropertyDescriptors(n)):r(Object(n)).forEach((function(e){Object.defineProperty(t,e,Object.getOwnPropertyDescriptor(n,e))}))}return t}({overlap:"pointer",isDocumentDraggable:!1,isDocumentDroppable:!1,dragstartDistanceThreshold:0,dragstartTimeThreshold:0},this.options)))}},{key:"destroy",value:function(){this.removeAllRenderingPlugins()}},{key:"setOptions",value:function(t){Object.assign(this.plugins[0].dragndropPluginOptions,t)}}]),n}(e.AbstractRendererPlugin);t.Plugin=y,Object.defineProperty(t,"__esModule",{value:!0})}));
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@antv/g-plugin-dragndrop",
|
|
3
|
-
"version": "1.6.
|
|
3
|
+
"version": "1.6.47",
|
|
4
4
|
"description": "A G plugin for Drag n Drop implemented with PointerEvents",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"antv",
|
|
@@ -42,5 +42,5 @@
|
|
|
42
42
|
"publishConfig": {
|
|
43
43
|
"access": "public"
|
|
44
44
|
},
|
|
45
|
-
"gitHead": "
|
|
45
|
+
"gitHead": "059286bbeff21a63e75a41811b89623c37f511f4"
|
|
46
46
|
}
|