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