@antv/g-plugin-dragndrop 1.1.1 → 1.1.2
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 +185 -239
- package/dist/index.js +185 -239
- package/dist/index.umd.js +185 -239
- package/dist/index.umd.min.js +2 -2
- package/package.json +2 -2
package/dist/index.js
CHANGED
|
@@ -5,32 +5,6 @@ Object.defineProperty(exports, '__esModule', { value: true });
|
|
|
5
5
|
var g = require('@antv/g');
|
|
6
6
|
var tslib = require('tslib');
|
|
7
7
|
|
|
8
|
-
function ownKeys(object, enumerableOnly) {
|
|
9
|
-
var keys = Object.keys(object);
|
|
10
|
-
|
|
11
|
-
if (Object.getOwnPropertySymbols) {
|
|
12
|
-
var symbols = Object.getOwnPropertySymbols(object);
|
|
13
|
-
enumerableOnly && (symbols = symbols.filter(function (sym) {
|
|
14
|
-
return Object.getOwnPropertyDescriptor(object, sym).enumerable;
|
|
15
|
-
})), keys.push.apply(keys, symbols);
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
return keys;
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
function _objectSpread2(target) {
|
|
22
|
-
for (var i = 1; i < arguments.length; i++) {
|
|
23
|
-
var source = null != arguments[i] ? arguments[i] : {};
|
|
24
|
-
i % 2 ? ownKeys(Object(source), !0).forEach(function (key) {
|
|
25
|
-
_defineProperty(target, key, source[key]);
|
|
26
|
-
}) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) {
|
|
27
|
-
Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key));
|
|
28
|
-
});
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
return target;
|
|
32
|
-
}
|
|
33
|
-
|
|
34
8
|
function _regeneratorRuntime() {
|
|
35
9
|
/*! regenerator-runtime -- Copyright (c) 2014-present, Facebook, Inc. -- license (MIT): https://github.com/facebook/regenerator/blob/main/LICENSE */
|
|
36
10
|
|
|
@@ -412,44 +386,21 @@ function _asyncToGenerator(fn) {
|
|
|
412
386
|
};
|
|
413
387
|
}
|
|
414
388
|
|
|
415
|
-
function
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
}
|
|
389
|
+
function _extends() {
|
|
390
|
+
_extends = Object.assign ? Object.assign.bind() : function (target) {
|
|
391
|
+
for (var i = 1; i < arguments.length; i++) {
|
|
392
|
+
var source = arguments[i];
|
|
420
393
|
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
Object.defineProperty(target, descriptor.key, descriptor);
|
|
428
|
-
}
|
|
429
|
-
}
|
|
430
|
-
|
|
431
|
-
function _createClass(Constructor, protoProps, staticProps) {
|
|
432
|
-
if (protoProps) _defineProperties(Constructor.prototype, protoProps);
|
|
433
|
-
if (staticProps) _defineProperties(Constructor, staticProps);
|
|
434
|
-
Object.defineProperty(Constructor, "prototype", {
|
|
435
|
-
writable: false
|
|
436
|
-
});
|
|
437
|
-
return Constructor;
|
|
438
|
-
}
|
|
439
|
-
|
|
440
|
-
function _defineProperty(obj, key, value) {
|
|
441
|
-
if (key in obj) {
|
|
442
|
-
Object.defineProperty(obj, key, {
|
|
443
|
-
value: value,
|
|
444
|
-
enumerable: true,
|
|
445
|
-
configurable: true,
|
|
446
|
-
writable: true
|
|
447
|
-
});
|
|
448
|
-
} else {
|
|
449
|
-
obj[key] = value;
|
|
450
|
-
}
|
|
394
|
+
for (var key in source) {
|
|
395
|
+
if (Object.prototype.hasOwnProperty.call(source, key)) {
|
|
396
|
+
target[key] = source[key];
|
|
397
|
+
}
|
|
398
|
+
}
|
|
399
|
+
}
|
|
451
400
|
|
|
452
|
-
|
|
401
|
+
return target;
|
|
402
|
+
};
|
|
403
|
+
return _extends.apply(this, arguments);
|
|
453
404
|
}
|
|
454
405
|
|
|
455
406
|
var DragndropPluginOptions = g.Syringe.defineToken('DragndropPluginOptions');
|
|
@@ -459,177 +410,174 @@ var _class;
|
|
|
459
410
|
var DragndropPlugin_1;
|
|
460
411
|
var DragndropPlugin = DragndropPlugin_1 = (_class = /*#__PURE__*/function () {
|
|
461
412
|
function DragndropPlugin() {
|
|
462
|
-
_classCallCheck(this, DragndropPlugin);
|
|
463
|
-
|
|
464
413
|
this.sceneGraphService = void 0;
|
|
465
414
|
this.renderingContext = void 0;
|
|
466
415
|
this.dragndropPluginOptions = void 0;
|
|
467
416
|
}
|
|
468
417
|
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
|
|
492
|
-
|
|
493
|
-
|
|
494
|
-
|
|
495
|
-
|
|
496
|
-
|
|
497
|
-
|
|
418
|
+
var _proto = DragndropPlugin.prototype;
|
|
419
|
+
|
|
420
|
+
_proto.apply = function apply(renderingService) {
|
|
421
|
+
var document = this.renderingContext.root.ownerDocument; // TODO: should we add an option like `draggable` to Canvas
|
|
422
|
+
|
|
423
|
+
var canvas = document.defaultView;
|
|
424
|
+
var _this$dragndropPlugin = this.dragndropPluginOptions,
|
|
425
|
+
overlap = _this$dragndropPlugin.overlap,
|
|
426
|
+
isDocumentDraggable = _this$dragndropPlugin.isDocumentDraggable,
|
|
427
|
+
isDocumentDroppable = _this$dragndropPlugin.isDocumentDroppable,
|
|
428
|
+
dragstartDistanceThreshold = _this$dragndropPlugin.dragstartDistanceThreshold,
|
|
429
|
+
dragstartTimeThreshold = _this$dragndropPlugin.dragstartTimeThreshold;
|
|
430
|
+
|
|
431
|
+
var handlePointerdown = function handlePointerdown(event) {
|
|
432
|
+
var target = event.target;
|
|
433
|
+
var isDocument = target === document;
|
|
434
|
+
|
|
435
|
+
if (isDocument && isDocumentDraggable || target.getAttribute && target.getAttribute('draggable')) {
|
|
436
|
+
// @ts-ignore
|
|
437
|
+
var onMouseMove = /*#__PURE__*/function () {
|
|
438
|
+
var _ref = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee(event) {
|
|
439
|
+
var timeElapsed, distanceMoved, pointerEventsOldValue, point, elemBelow, droppableBelow;
|
|
440
|
+
return _regeneratorRuntime().wrap(function _callee$(_context) {
|
|
441
|
+
while (1) {
|
|
442
|
+
switch (_context.prev = _context.next) {
|
|
443
|
+
case 0:
|
|
444
|
+
if (dragstartTriggered) {
|
|
445
|
+
_context.next = 8;
|
|
446
|
+
break;
|
|
447
|
+
}
|
|
448
|
+
|
|
449
|
+
timeElapsed = event.timeStamp - dragstartTimeStamp;
|
|
450
|
+
distanceMoved = Math.sqrt(Math.pow(event.canvasX - dragstartCanvasCoordinates[0], 2) + Math.pow(event.canvasY - dragstartCanvasCoordinates[1], 2)); // check thresholds
|
|
451
|
+
|
|
452
|
+
if (!(timeElapsed <= dragstartTimeThreshold || distanceMoved <= dragstartDistanceThreshold)) {
|
|
453
|
+
_context.next = 5;
|
|
454
|
+
break;
|
|
455
|
+
}
|
|
456
|
+
|
|
457
|
+
return _context.abrupt("return");
|
|
458
|
+
|
|
459
|
+
case 5:
|
|
460
|
+
// @see https://developer.mozilla.org/zh-CN/docs/Web/API/Document/dragstart_event
|
|
461
|
+
event.type = 'dragstart';
|
|
462
|
+
target.dispatchEvent(event);
|
|
463
|
+
dragstartTriggered = true;
|
|
464
|
+
|
|
465
|
+
case 8:
|
|
466
|
+
// @see https://developer.mozilla.org/zh-CN/docs/Web/API/Document/drag_event
|
|
467
|
+
event.type = 'drag';
|
|
468
|
+
target.dispatchEvent(event);
|
|
469
|
+
|
|
470
|
+
if (isDocument) {
|
|
471
|
+
_context.next = 20;
|
|
472
|
+
break;
|
|
473
|
+
}
|
|
474
|
+
|
|
475
|
+
// prevent from picking the dragging element
|
|
476
|
+
pointerEventsOldValue = target.style.pointerEvents;
|
|
477
|
+
target.style.pointerEvents = 'none';
|
|
478
|
+
point = overlap === 'pointer' ? [event.canvasX, event.canvasY] : target.getBounds().center;
|
|
479
|
+
_context.next = 16;
|
|
480
|
+
return document.elementFromPoint(point[0], point[1]);
|
|
481
|
+
|
|
482
|
+
case 16:
|
|
483
|
+
elemBelow = _context.sent;
|
|
484
|
+
target.style.pointerEvents = pointerEventsOldValue;
|
|
485
|
+
droppableBelow = (elemBelow === null || elemBelow === void 0 ? void 0 : elemBelow.closest('[droppable=true]')) || (isDocumentDroppable ? document : null);
|
|
486
|
+
|
|
487
|
+
if (currentDroppable !== droppableBelow) {
|
|
488
|
+
if (currentDroppable) {
|
|
489
|
+
// null when we were not over a droppable before this event
|
|
490
|
+
// @see https://developer.mozilla.org/zh-CN/docs/Web/API/Document/dragleave_event
|
|
491
|
+
event.type = 'dragleave';
|
|
492
|
+
event.target = currentDroppable;
|
|
493
|
+
currentDroppable.dispatchEvent(event);
|
|
498
494
|
}
|
|
499
495
|
|
|
500
|
-
|
|
501
|
-
|
|
502
|
-
|
|
503
|
-
|
|
504
|
-
|
|
505
|
-
break;
|
|
496
|
+
if (droppableBelow) {
|
|
497
|
+
// @see https://developer.mozilla.org/zh-CN/docs/Web/API/Document/dragleave_event
|
|
498
|
+
event.type = 'dragenter';
|
|
499
|
+
event.target = droppableBelow;
|
|
500
|
+
droppableBelow.dispatchEvent(event);
|
|
506
501
|
}
|
|
507
502
|
|
|
508
|
-
|
|
509
|
-
|
|
510
|
-
case 5:
|
|
511
|
-
// @see https://developer.mozilla.org/zh-CN/docs/Web/API/Document/dragstart_event
|
|
512
|
-
event.type = 'dragstart';
|
|
513
|
-
target.dispatchEvent(event);
|
|
514
|
-
dragstartTriggered = true;
|
|
515
|
-
|
|
516
|
-
case 8:
|
|
517
|
-
// @see https://developer.mozilla.org/zh-CN/docs/Web/API/Document/drag_event
|
|
518
|
-
event.type = 'drag';
|
|
519
|
-
target.dispatchEvent(event);
|
|
503
|
+
currentDroppable = droppableBelow;
|
|
520
504
|
|
|
521
|
-
if (
|
|
522
|
-
|
|
523
|
-
|
|
505
|
+
if (currentDroppable) {
|
|
506
|
+
// null if we're not coming over a droppable now
|
|
507
|
+
// @see https://developer.mozilla.org/zh-CN/docs/Web/API/Document/dragover_event
|
|
508
|
+
event.type = 'dragover';
|
|
509
|
+
event.target = currentDroppable;
|
|
510
|
+
currentDroppable.dispatchEvent(event);
|
|
524
511
|
}
|
|
512
|
+
}
|
|
525
513
|
|
|
526
|
-
|
|
527
|
-
|
|
528
|
-
|
|
529
|
-
point = overlap === 'pointer' ? [event.canvasX, event.canvasY] : target.getBounds().center;
|
|
530
|
-
_context.next = 16;
|
|
531
|
-
return document.elementFromPoint(point[0], point[1]);
|
|
532
|
-
|
|
533
|
-
case 16:
|
|
534
|
-
elemBelow = _context.sent;
|
|
535
|
-
target.style.pointerEvents = pointerEventsOldValue;
|
|
536
|
-
droppableBelow = (elemBelow === null || elemBelow === void 0 ? void 0 : elemBelow.closest('[droppable=true]')) || (isDocumentDroppable ? document : null);
|
|
537
|
-
|
|
538
|
-
if (currentDroppable !== droppableBelow) {
|
|
539
|
-
if (currentDroppable) {
|
|
540
|
-
// null when we were not over a droppable before this event
|
|
541
|
-
// @see https://developer.mozilla.org/zh-CN/docs/Web/API/Document/dragleave_event
|
|
542
|
-
event.type = 'dragleave';
|
|
543
|
-
event.target = currentDroppable;
|
|
544
|
-
currentDroppable.dispatchEvent(event);
|
|
545
|
-
}
|
|
546
|
-
|
|
547
|
-
if (droppableBelow) {
|
|
548
|
-
// @see https://developer.mozilla.org/zh-CN/docs/Web/API/Document/dragleave_event
|
|
549
|
-
event.type = 'dragenter';
|
|
550
|
-
event.target = droppableBelow;
|
|
551
|
-
droppableBelow.dispatchEvent(event);
|
|
552
|
-
}
|
|
553
|
-
|
|
554
|
-
currentDroppable = droppableBelow;
|
|
555
|
-
|
|
556
|
-
if (currentDroppable) {
|
|
557
|
-
// null if we're not coming over a droppable now
|
|
558
|
-
// @see https://developer.mozilla.org/zh-CN/docs/Web/API/Document/dragover_event
|
|
559
|
-
event.type = 'dragover';
|
|
560
|
-
event.target = currentDroppable;
|
|
561
|
-
currentDroppable.dispatchEvent(event);
|
|
562
|
-
}
|
|
563
|
-
}
|
|
564
|
-
|
|
565
|
-
case 20:
|
|
566
|
-
case "end":
|
|
567
|
-
return _context.stop();
|
|
568
|
-
}
|
|
514
|
+
case 20:
|
|
515
|
+
case "end":
|
|
516
|
+
return _context.stop();
|
|
569
517
|
}
|
|
570
|
-
}
|
|
571
|
-
})
|
|
572
|
-
|
|
573
|
-
return function onMouseMove(_x) {
|
|
574
|
-
return _ref.apply(this, arguments);
|
|
575
|
-
};
|
|
576
|
-
}();
|
|
577
|
-
|
|
578
|
-
// delay triggering dragstart event
|
|
579
|
-
var dragstartTriggered = false;
|
|
580
|
-
var dragstartTimeStamp = event.timeStamp;
|
|
581
|
-
var dragstartCanvasCoordinates = [event.canvasX, event.canvasY];
|
|
582
|
-
var currentDroppable = null;
|
|
583
|
-
canvas.addEventListener('pointermove', onMouseMove);
|
|
584
|
-
|
|
585
|
-
var stopDragging = function stopDragging() {
|
|
586
|
-
if (dragstartTriggered) {
|
|
587
|
-
// drop should fire before dragend
|
|
588
|
-
// @see https://javascript.tutorialink.com/is-there-a-defined-ordering-between-dragend-and-drop-events/
|
|
589
|
-
if (currentDroppable) {
|
|
590
|
-
// @see https://developer.mozilla.org/zh-CN/docs/Web/API/Document/drop_event
|
|
591
|
-
event.type = 'drop';
|
|
592
|
-
event.target = currentDroppable;
|
|
593
|
-
currentDroppable.dispatchEvent(event);
|
|
594
|
-
} // @see https://developer.mozilla.org/zh-CN/docs/Web/API/Document/dragend_event
|
|
595
|
-
|
|
596
|
-
|
|
597
|
-
event.type = 'dragend';
|
|
598
|
-
target.dispatchEvent(event);
|
|
599
|
-
dragstartTriggered = false;
|
|
600
|
-
}
|
|
518
|
+
}
|
|
519
|
+
}, _callee);
|
|
520
|
+
}));
|
|
601
521
|
|
|
602
|
-
|
|
522
|
+
return function onMouseMove(_x) {
|
|
523
|
+
return _ref.apply(this, arguments);
|
|
603
524
|
};
|
|
525
|
+
}();
|
|
526
|
+
|
|
527
|
+
// delay triggering dragstart event
|
|
528
|
+
var dragstartTriggered = false;
|
|
529
|
+
var dragstartTimeStamp = event.timeStamp;
|
|
530
|
+
var dragstartCanvasCoordinates = [event.canvasX, event.canvasY];
|
|
531
|
+
var currentDroppable = null;
|
|
532
|
+
canvas.addEventListener('pointermove', onMouseMove);
|
|
533
|
+
|
|
534
|
+
var stopDragging = function stopDragging() {
|
|
535
|
+
if (dragstartTriggered) {
|
|
536
|
+
// drop should fire before dragend
|
|
537
|
+
// @see https://javascript.tutorialink.com/is-there-a-defined-ordering-between-dragend-and-drop-events/
|
|
538
|
+
if (currentDroppable) {
|
|
539
|
+
// @see https://developer.mozilla.org/zh-CN/docs/Web/API/Document/drop_event
|
|
540
|
+
event.type = 'drop';
|
|
541
|
+
event.target = currentDroppable;
|
|
542
|
+
currentDroppable.dispatchEvent(event);
|
|
543
|
+
} // @see https://developer.mozilla.org/zh-CN/docs/Web/API/Document/dragend_event
|
|
544
|
+
|
|
545
|
+
|
|
546
|
+
event.type = 'dragend';
|
|
547
|
+
target.dispatchEvent(event);
|
|
548
|
+
dragstartTriggered = false;
|
|
549
|
+
}
|
|
604
550
|
|
|
605
|
-
|
|
606
|
-
|
|
607
|
-
});
|
|
608
|
-
target.addEventListener('pointerupoutside', stopDragging, {
|
|
609
|
-
once: true
|
|
610
|
-
});
|
|
611
|
-
}
|
|
612
|
-
};
|
|
551
|
+
canvas.removeEventListener('pointermove', onMouseMove);
|
|
552
|
+
};
|
|
613
553
|
|
|
614
|
-
|
|
615
|
-
|
|
616
|
-
|
|
617
|
-
|
|
618
|
-
|
|
619
|
-
|
|
554
|
+
target.addEventListener('pointerup', stopDragging, {
|
|
555
|
+
once: true
|
|
556
|
+
});
|
|
557
|
+
target.addEventListener('pointerupoutside', stopDragging, {
|
|
558
|
+
once: true
|
|
559
|
+
});
|
|
560
|
+
}
|
|
561
|
+
};
|
|
620
562
|
|
|
621
|
-
|
|
622
|
-
|
|
623
|
-
|
|
624
|
-
|
|
563
|
+
renderingService.hooks.init.tapPromise(DragndropPlugin_1.tag, /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee2() {
|
|
564
|
+
return _regeneratorRuntime().wrap(function _callee2$(_context2) {
|
|
565
|
+
while (1) {
|
|
566
|
+
switch (_context2.prev = _context2.next) {
|
|
567
|
+
case 0:
|
|
568
|
+
canvas.addEventListener('pointerdown', handlePointerdown);
|
|
569
|
+
|
|
570
|
+
case 1:
|
|
571
|
+
case "end":
|
|
572
|
+
return _context2.stop();
|
|
625
573
|
}
|
|
626
|
-
}
|
|
627
|
-
})
|
|
628
|
-
|
|
629
|
-
|
|
630
|
-
|
|
631
|
-
}
|
|
632
|
-
}
|
|
574
|
+
}
|
|
575
|
+
}, _callee2);
|
|
576
|
+
})));
|
|
577
|
+
renderingService.hooks.destroy.tap(DragndropPlugin_1.tag, function () {
|
|
578
|
+
canvas.removeEventListener('pointerdown', handlePointerdown);
|
|
579
|
+
});
|
|
580
|
+
};
|
|
633
581
|
|
|
634
582
|
return DragndropPlugin;
|
|
635
583
|
}(), _class.tag = 'Dragndrop', _class);
|
|
@@ -648,37 +596,35 @@ var containerModule = g.Module(function (register) {
|
|
|
648
596
|
register(DragndropPlugin);
|
|
649
597
|
});
|
|
650
598
|
var Plugin = /*#__PURE__*/function () {
|
|
651
|
-
function Plugin() {
|
|
652
|
-
|
|
653
|
-
|
|
654
|
-
|
|
599
|
+
function Plugin(options) {
|
|
600
|
+
if (options === void 0) {
|
|
601
|
+
options = {};
|
|
602
|
+
}
|
|
655
603
|
|
|
656
604
|
this.options = void 0;
|
|
657
605
|
this.name = 'dragndrop';
|
|
658
606
|
this.options = options;
|
|
659
607
|
}
|
|
660
608
|
|
|
661
|
-
|
|
662
|
-
|
|
663
|
-
|
|
664
|
-
|
|
665
|
-
|
|
666
|
-
|
|
667
|
-
|
|
668
|
-
|
|
669
|
-
|
|
670
|
-
|
|
671
|
-
|
|
672
|
-
|
|
673
|
-
|
|
674
|
-
|
|
675
|
-
|
|
676
|
-
|
|
677
|
-
|
|
678
|
-
|
|
679
|
-
|
|
680
|
-
}
|
|
681
|
-
}]);
|
|
609
|
+
var _proto = Plugin.prototype;
|
|
610
|
+
|
|
611
|
+
_proto.init = function init(container) {
|
|
612
|
+
container.register(DragndropPluginOptions, {
|
|
613
|
+
useValue: _extends({
|
|
614
|
+
overlap: 'pointer',
|
|
615
|
+
isDocumentDraggable: false,
|
|
616
|
+
isDocumentDroppable: false,
|
|
617
|
+
dragstartDistanceThreshold: 0,
|
|
618
|
+
dragstartTimeThreshold: 0
|
|
619
|
+
}, this.options)
|
|
620
|
+
});
|
|
621
|
+
container.load(containerModule, true);
|
|
622
|
+
};
|
|
623
|
+
|
|
624
|
+
_proto.destroy = function destroy(container) {
|
|
625
|
+
container.remove(DragndropPluginOptions);
|
|
626
|
+
container.unload(containerModule);
|
|
627
|
+
};
|
|
682
628
|
|
|
683
629
|
return Plugin;
|
|
684
630
|
}();
|