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