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