@antv/g-plugin-dragndrop 1.0.5-alpha.0 → 1.1.0
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/DragndropPlugin.d.ts.map +1 -1
- package/dist/index.d.ts +1 -2
- package/dist/index.d.ts.map +1 -1
- package/dist/index.esm.js +80 -40
- package/dist/index.js +86 -46
- package/dist/index.umd.js +89 -48
- package/dist/index.umd.min.js +2 -2
- package/dist/tokens.d.ts +19 -1
- package/dist/tokens.d.ts.map +1 -1
- package/package.json +3 -4
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"DragndropPlugin.d.ts","sourceRoot":"","sources":["../src/DragndropPlugin.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,
|
|
1
|
+
{"version":3,"file":"DragndropPlugin.d.ts","sourceRoot":"","sources":["../src/DragndropPlugin.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAIV,eAAe,EACf,gBAAgB,EACjB,MAAM,SAAS,CAAC;AACjB,OAAO,EAIL,iBAAiB,EAElB,MAAM,SAAS,CAAC;AAGjB,qBACa,eAAgB,YAAW,eAAe;IACrD,MAAM,CAAC,GAAG,SAAe;IAGzB,SAAS,CAAC,iBAAiB,EAAE,iBAAiB,CAAC;IAG/C,OAAO,CAAC,gBAAgB,CAAmB;IAG3C,OAAO,CAAC,sBAAsB,CAAyB;IAEvD,KAAK,CAAC,gBAAgB,EAAE,gBAAgB;CAkIzC"}
|
package/dist/index.d.ts
CHANGED
|
@@ -1,5 +1,4 @@
|
|
|
1
|
-
import type { RendererPlugin } from '@antv/g';
|
|
2
|
-
import type { Syringe } from 'mana-syringe';
|
|
1
|
+
import type { RendererPlugin, Syringe } from '@antv/g';
|
|
3
2
|
import { DragndropPluginOptions } from './tokens';
|
|
4
3
|
export declare class Plugin implements RendererPlugin {
|
|
5
4
|
private options;
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,cAAc,EAAE,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,cAAc,EAAE,OAAO,EAAE,MAAM,SAAS,CAAC;AAGvD,OAAO,EAAE,sBAAsB,EAAE,MAAM,UAAU,CAAC;AAMlD,qBAAa,MAAO,YAAW,cAAc;IAG/B,OAAO,CAAC,OAAO;IAF3B,IAAI,SAAe;gBAEC,OAAO,GAAE,OAAO,CAAC,sBAAsB,CAAM;IAEjE,IAAI,CAAC,SAAS,EAAE,OAAO,CAAC,SAAS,GAAG,IAAI;IAaxC,OAAO,CAAC,SAAS,EAAE,OAAO,CAAC,SAAS,GAAG,IAAI;CAI5C"}
|
package/dist/index.esm.js
CHANGED
|
@@ -1,6 +1,5 @@
|
|
|
1
|
-
import { Syringe, inject, singleton, Module } from '
|
|
1
|
+
import { Syringe, inject, SceneGraphService, RenderingContext, singleton, RenderingPluginContribution, Module } from '@antv/g';
|
|
2
2
|
import { __decorate, __metadata } from 'tslib';
|
|
3
|
-
import { SceneGraphService, RenderingContext, RenderingPluginContribution } from '@antv/g';
|
|
4
3
|
|
|
5
4
|
function _regeneratorRuntime() {
|
|
6
5
|
/*! regenerator-runtime -- Copyright (c) 2014-present, Facebook, Inc. -- license (MIT): https://github.com/facebook/regenerator/blob/main/LICENSE */
|
|
@@ -416,46 +415,71 @@ var DragndropPlugin = DragndropPlugin_1 = (_class = /*#__PURE__*/function () {
|
|
|
416
415
|
var _proto = DragndropPlugin.prototype;
|
|
417
416
|
|
|
418
417
|
_proto.apply = function apply(renderingService) {
|
|
419
|
-
var
|
|
418
|
+
var document = this.renderingContext.root.ownerDocument; // TODO: should we add an option like `draggable` to Canvas
|
|
420
419
|
|
|
421
|
-
var
|
|
422
|
-
var
|
|
420
|
+
var canvas = document.defaultView;
|
|
421
|
+
var _this$dragndropPlugin = this.dragndropPluginOptions,
|
|
422
|
+
overlap = _this$dragndropPlugin.overlap,
|
|
423
|
+
isDocumentDraggable = _this$dragndropPlugin.isDocumentDraggable,
|
|
424
|
+
isDocumentDroppable = _this$dragndropPlugin.isDocumentDroppable,
|
|
425
|
+
dragstartDistanceThreshold = _this$dragndropPlugin.dragstartDistanceThreshold,
|
|
426
|
+
dragstartTimeThreshold = _this$dragndropPlugin.dragstartTimeThreshold;
|
|
423
427
|
|
|
424
428
|
var handlePointerdown = function handlePointerdown(event) {
|
|
425
429
|
var target = event.target;
|
|
430
|
+
var isDocument = target === document;
|
|
426
431
|
|
|
427
|
-
if (target.getAttribute('draggable')) {
|
|
432
|
+
if (isDocument && isDocumentDraggable || target.getAttribute && target.getAttribute('draggable')) {
|
|
428
433
|
// @ts-ignore
|
|
429
434
|
var onMouseMove = /*#__PURE__*/function () {
|
|
430
435
|
var _ref = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee(event) {
|
|
431
|
-
var pointerEventsOldValue, point, elemBelow, droppableBelow;
|
|
436
|
+
var timeElapsed, distanceMoved, pointerEventsOldValue, point, elemBelow, droppableBelow;
|
|
432
437
|
return _regeneratorRuntime().wrap(function _callee$(_context) {
|
|
433
438
|
while (1) {
|
|
434
439
|
switch (_context.prev = _context.next) {
|
|
435
440
|
case 0:
|
|
441
|
+
if (dragstartTriggered) {
|
|
442
|
+
_context.next = 8;
|
|
443
|
+
break;
|
|
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:
|
|
436
463
|
// @see https://developer.mozilla.org/zh-CN/docs/Web/API/Document/drag_event
|
|
437
464
|
event.type = 'drag';
|
|
438
|
-
target.dispatchEvent(event);
|
|
465
|
+
target.dispatchEvent(event);
|
|
439
466
|
|
|
467
|
+
if (isDocument) {
|
|
468
|
+
_context.next = 20;
|
|
469
|
+
break;
|
|
470
|
+
}
|
|
471
|
+
|
|
472
|
+
// prevent from picking the dragging element
|
|
440
473
|
pointerEventsOldValue = target.style.pointerEvents;
|
|
441
474
|
target.style.pointerEvents = 'none';
|
|
442
475
|
point = overlap === 'pointer' ? [event.canvasX, event.canvasY] : target.getBounds().center;
|
|
443
|
-
_context.next =
|
|
476
|
+
_context.next = 16;
|
|
444
477
|
return document.elementFromPoint(point[0], point[1]);
|
|
445
478
|
|
|
446
|
-
case
|
|
479
|
+
case 16:
|
|
447
480
|
elemBelow = _context.sent;
|
|
448
481
|
target.style.pointerEvents = pointerEventsOldValue;
|
|
449
|
-
|
|
450
|
-
if (elemBelow) {
|
|
451
|
-
_context.next = 11;
|
|
452
|
-
break;
|
|
453
|
-
}
|
|
454
|
-
|
|
455
|
-
return _context.abrupt("return");
|
|
456
|
-
|
|
457
|
-
case 11:
|
|
458
|
-
droppableBelow = (elemBelow === null || elemBelow === void 0 ? void 0 : elemBelow.closest('[droppable=true]')) || null;
|
|
482
|
+
droppableBelow = (elemBelow === null || elemBelow === void 0 ? void 0 : elemBelow.closest('[droppable=true]')) || (isDocumentDroppable ? document : null);
|
|
459
483
|
|
|
460
484
|
if (currentDroppable !== droppableBelow) {
|
|
461
485
|
if (currentDroppable) {
|
|
@@ -484,7 +508,7 @@ var DragndropPlugin = DragndropPlugin_1 = (_class = /*#__PURE__*/function () {
|
|
|
484
508
|
}
|
|
485
509
|
}
|
|
486
510
|
|
|
487
|
-
case
|
|
511
|
+
case 20:
|
|
488
512
|
case "end":
|
|
489
513
|
return _context.stop();
|
|
490
514
|
}
|
|
@@ -497,25 +521,37 @@ var DragndropPlugin = DragndropPlugin_1 = (_class = /*#__PURE__*/function () {
|
|
|
497
521
|
};
|
|
498
522
|
}();
|
|
499
523
|
|
|
500
|
-
//
|
|
501
|
-
|
|
502
|
-
|
|
524
|
+
// delay triggering dragstart event
|
|
525
|
+
var dragstartTriggered = false;
|
|
526
|
+
var dragstartTimeStamp = event.timeStamp;
|
|
527
|
+
var dragstartCanvasCoordinates = [event.canvasX, event.canvasY];
|
|
503
528
|
var currentDroppable = null;
|
|
504
|
-
|
|
505
|
-
|
|
506
|
-
|
|
507
|
-
|
|
508
|
-
|
|
509
|
-
|
|
510
|
-
|
|
511
|
-
|
|
512
|
-
|
|
513
|
-
|
|
514
|
-
|
|
529
|
+
canvas.addEventListener('pointermove', onMouseMove);
|
|
530
|
+
|
|
531
|
+
var stopDragging = function stopDragging() {
|
|
532
|
+
if (dragstartTriggered) {
|
|
533
|
+
// drop should fire before dragend
|
|
534
|
+
// @see https://javascript.tutorialink.com/is-there-a-defined-ordering-between-dragend-and-drop-events/
|
|
535
|
+
if (currentDroppable) {
|
|
536
|
+
// @see https://developer.mozilla.org/zh-CN/docs/Web/API/Document/drop_event
|
|
537
|
+
event.type = 'drop';
|
|
538
|
+
event.target = currentDroppable;
|
|
539
|
+
currentDroppable.dispatchEvent(event);
|
|
540
|
+
} // @see https://developer.mozilla.org/zh-CN/docs/Web/API/Document/dragend_event
|
|
541
|
+
|
|
542
|
+
|
|
543
|
+
event.type = 'dragend';
|
|
544
|
+
target.dispatchEvent(event);
|
|
545
|
+
dragstartTriggered = false;
|
|
515
546
|
}
|
|
516
547
|
|
|
517
|
-
|
|
518
|
-
}
|
|
548
|
+
canvas.removeEventListener('pointermove', onMouseMove);
|
|
549
|
+
};
|
|
550
|
+
|
|
551
|
+
target.addEventListener('pointerup', stopDragging, {
|
|
552
|
+
once: true
|
|
553
|
+
});
|
|
554
|
+
target.addEventListener('pointerupoutside', stopDragging, {
|
|
519
555
|
once: true
|
|
520
556
|
});
|
|
521
557
|
}
|
|
@@ -526,7 +562,7 @@ var DragndropPlugin = DragndropPlugin_1 = (_class = /*#__PURE__*/function () {
|
|
|
526
562
|
while (1) {
|
|
527
563
|
switch (_context2.prev = _context2.next) {
|
|
528
564
|
case 0:
|
|
529
|
-
|
|
565
|
+
canvas.addEventListener('pointerdown', handlePointerdown);
|
|
530
566
|
|
|
531
567
|
case 1:
|
|
532
568
|
case "end":
|
|
@@ -536,7 +572,7 @@ var DragndropPlugin = DragndropPlugin_1 = (_class = /*#__PURE__*/function () {
|
|
|
536
572
|
}, _callee2);
|
|
537
573
|
})));
|
|
538
574
|
renderingService.hooks.destroy.tap(DragndropPlugin_1.tag, function () {
|
|
539
|
-
|
|
575
|
+
canvas.removeEventListener('pointerdown', handlePointerdown);
|
|
540
576
|
});
|
|
541
577
|
};
|
|
542
578
|
|
|
@@ -572,7 +608,11 @@ var Plugin = /*#__PURE__*/function () {
|
|
|
572
608
|
_proto.init = function init(container) {
|
|
573
609
|
container.register(DragndropPluginOptions, {
|
|
574
610
|
useValue: _extends({
|
|
575
|
-
overlap: 'pointer'
|
|
611
|
+
overlap: 'pointer',
|
|
612
|
+
isDocumentDraggable: false,
|
|
613
|
+
isDocumentDroppable: false,
|
|
614
|
+
dragstartDistanceThreshold: 0,
|
|
615
|
+
dragstartTimeThreshold: 0
|
|
576
616
|
}, this.options)
|
|
577
617
|
});
|
|
578
618
|
container.load(containerModule, true);
|
package/dist/index.js
CHANGED
|
@@ -2,9 +2,8 @@
|
|
|
2
2
|
|
|
3
3
|
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
4
|
|
|
5
|
-
var manaSyringe = require('mana-syringe');
|
|
6
|
-
var tslib = require('tslib');
|
|
7
5
|
var g = require('@antv/g');
|
|
6
|
+
var tslib = require('tslib');
|
|
8
7
|
|
|
9
8
|
function _regeneratorRuntime() {
|
|
10
9
|
/*! regenerator-runtime -- Copyright (c) 2014-present, Facebook, Inc. -- license (MIT): https://github.com/facebook/regenerator/blob/main/LICENSE */
|
|
@@ -405,7 +404,7 @@ function _extends() {
|
|
|
405
404
|
return _extends.apply(this, arguments);
|
|
406
405
|
}
|
|
407
406
|
|
|
408
|
-
var DragndropPluginOptions =
|
|
407
|
+
var DragndropPluginOptions = g.Syringe.defineToken('DragndropPluginOptions');
|
|
409
408
|
|
|
410
409
|
var _class;
|
|
411
410
|
|
|
@@ -420,46 +419,71 @@ var DragndropPlugin = DragndropPlugin_1 = (_class = /*#__PURE__*/function () {
|
|
|
420
419
|
var _proto = DragndropPlugin.prototype;
|
|
421
420
|
|
|
422
421
|
_proto.apply = function apply(renderingService) {
|
|
423
|
-
var
|
|
422
|
+
var document = this.renderingContext.root.ownerDocument; // TODO: should we add an option like `draggable` to Canvas
|
|
424
423
|
|
|
425
|
-
var
|
|
426
|
-
var
|
|
424
|
+
var canvas = document.defaultView;
|
|
425
|
+
var _this$dragndropPlugin = this.dragndropPluginOptions,
|
|
426
|
+
overlap = _this$dragndropPlugin.overlap,
|
|
427
|
+
isDocumentDraggable = _this$dragndropPlugin.isDocumentDraggable,
|
|
428
|
+
isDocumentDroppable = _this$dragndropPlugin.isDocumentDroppable,
|
|
429
|
+
dragstartDistanceThreshold = _this$dragndropPlugin.dragstartDistanceThreshold,
|
|
430
|
+
dragstartTimeThreshold = _this$dragndropPlugin.dragstartTimeThreshold;
|
|
427
431
|
|
|
428
432
|
var handlePointerdown = function handlePointerdown(event) {
|
|
429
433
|
var target = event.target;
|
|
434
|
+
var isDocument = target === document;
|
|
430
435
|
|
|
431
|
-
if (target.getAttribute('draggable')) {
|
|
436
|
+
if (isDocument && isDocumentDraggable || target.getAttribute && target.getAttribute('draggable')) {
|
|
432
437
|
// @ts-ignore
|
|
433
438
|
var onMouseMove = /*#__PURE__*/function () {
|
|
434
439
|
var _ref = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee(event) {
|
|
435
|
-
var pointerEventsOldValue, point, elemBelow, droppableBelow;
|
|
440
|
+
var timeElapsed, distanceMoved, pointerEventsOldValue, point, elemBelow, droppableBelow;
|
|
436
441
|
return _regeneratorRuntime().wrap(function _callee$(_context) {
|
|
437
442
|
while (1) {
|
|
438
443
|
switch (_context.prev = _context.next) {
|
|
439
444
|
case 0:
|
|
445
|
+
if (dragstartTriggered) {
|
|
446
|
+
_context.next = 8;
|
|
447
|
+
break;
|
|
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:
|
|
440
467
|
// @see https://developer.mozilla.org/zh-CN/docs/Web/API/Document/drag_event
|
|
441
468
|
event.type = 'drag';
|
|
442
|
-
target.dispatchEvent(event);
|
|
469
|
+
target.dispatchEvent(event);
|
|
443
470
|
|
|
471
|
+
if (isDocument) {
|
|
472
|
+
_context.next = 20;
|
|
473
|
+
break;
|
|
474
|
+
}
|
|
475
|
+
|
|
476
|
+
// prevent from picking the dragging element
|
|
444
477
|
pointerEventsOldValue = target.style.pointerEvents;
|
|
445
478
|
target.style.pointerEvents = 'none';
|
|
446
479
|
point = overlap === 'pointer' ? [event.canvasX, event.canvasY] : target.getBounds().center;
|
|
447
|
-
_context.next =
|
|
480
|
+
_context.next = 16;
|
|
448
481
|
return document.elementFromPoint(point[0], point[1]);
|
|
449
482
|
|
|
450
|
-
case
|
|
483
|
+
case 16:
|
|
451
484
|
elemBelow = _context.sent;
|
|
452
485
|
target.style.pointerEvents = pointerEventsOldValue;
|
|
453
|
-
|
|
454
|
-
if (elemBelow) {
|
|
455
|
-
_context.next = 11;
|
|
456
|
-
break;
|
|
457
|
-
}
|
|
458
|
-
|
|
459
|
-
return _context.abrupt("return");
|
|
460
|
-
|
|
461
|
-
case 11:
|
|
462
|
-
droppableBelow = (elemBelow === null || elemBelow === void 0 ? void 0 : elemBelow.closest('[droppable=true]')) || null;
|
|
486
|
+
droppableBelow = (elemBelow === null || elemBelow === void 0 ? void 0 : elemBelow.closest('[droppable=true]')) || (isDocumentDroppable ? document : null);
|
|
463
487
|
|
|
464
488
|
if (currentDroppable !== droppableBelow) {
|
|
465
489
|
if (currentDroppable) {
|
|
@@ -488,7 +512,7 @@ var DragndropPlugin = DragndropPlugin_1 = (_class = /*#__PURE__*/function () {
|
|
|
488
512
|
}
|
|
489
513
|
}
|
|
490
514
|
|
|
491
|
-
case
|
|
515
|
+
case 20:
|
|
492
516
|
case "end":
|
|
493
517
|
return _context.stop();
|
|
494
518
|
}
|
|
@@ -501,25 +525,37 @@ var DragndropPlugin = DragndropPlugin_1 = (_class = /*#__PURE__*/function () {
|
|
|
501
525
|
};
|
|
502
526
|
}();
|
|
503
527
|
|
|
504
|
-
//
|
|
505
|
-
|
|
506
|
-
|
|
528
|
+
// delay triggering dragstart event
|
|
529
|
+
var dragstartTriggered = false;
|
|
530
|
+
var dragstartTimeStamp = event.timeStamp;
|
|
531
|
+
var dragstartCanvasCoordinates = [event.canvasX, event.canvasY];
|
|
507
532
|
var currentDroppable = null;
|
|
508
|
-
|
|
509
|
-
|
|
510
|
-
|
|
511
|
-
|
|
512
|
-
|
|
513
|
-
|
|
514
|
-
|
|
515
|
-
|
|
516
|
-
|
|
517
|
-
|
|
518
|
-
|
|
533
|
+
canvas.addEventListener('pointermove', onMouseMove);
|
|
534
|
+
|
|
535
|
+
var stopDragging = function stopDragging() {
|
|
536
|
+
if (dragstartTriggered) {
|
|
537
|
+
// drop should fire before dragend
|
|
538
|
+
// @see https://javascript.tutorialink.com/is-there-a-defined-ordering-between-dragend-and-drop-events/
|
|
539
|
+
if (currentDroppable) {
|
|
540
|
+
// @see https://developer.mozilla.org/zh-CN/docs/Web/API/Document/drop_event
|
|
541
|
+
event.type = 'drop';
|
|
542
|
+
event.target = currentDroppable;
|
|
543
|
+
currentDroppable.dispatchEvent(event);
|
|
544
|
+
} // @see https://developer.mozilla.org/zh-CN/docs/Web/API/Document/dragend_event
|
|
545
|
+
|
|
546
|
+
|
|
547
|
+
event.type = 'dragend';
|
|
548
|
+
target.dispatchEvent(event);
|
|
549
|
+
dragstartTriggered = false;
|
|
519
550
|
}
|
|
520
551
|
|
|
521
|
-
|
|
522
|
-
}
|
|
552
|
+
canvas.removeEventListener('pointermove', onMouseMove);
|
|
553
|
+
};
|
|
554
|
+
|
|
555
|
+
target.addEventListener('pointerup', stopDragging, {
|
|
556
|
+
once: true
|
|
557
|
+
});
|
|
558
|
+
target.addEventListener('pointerupoutside', stopDragging, {
|
|
523
559
|
once: true
|
|
524
560
|
});
|
|
525
561
|
}
|
|
@@ -530,7 +566,7 @@ var DragndropPlugin = DragndropPlugin_1 = (_class = /*#__PURE__*/function () {
|
|
|
530
566
|
while (1) {
|
|
531
567
|
switch (_context2.prev = _context2.next) {
|
|
532
568
|
case 0:
|
|
533
|
-
|
|
569
|
+
canvas.addEventListener('pointerdown', handlePointerdown);
|
|
534
570
|
|
|
535
571
|
case 1:
|
|
536
572
|
case "end":
|
|
@@ -540,24 +576,24 @@ var DragndropPlugin = DragndropPlugin_1 = (_class = /*#__PURE__*/function () {
|
|
|
540
576
|
}, _callee2);
|
|
541
577
|
})));
|
|
542
578
|
renderingService.hooks.destroy.tap(DragndropPlugin_1.tag, function () {
|
|
543
|
-
|
|
579
|
+
canvas.removeEventListener('pointerdown', handlePointerdown);
|
|
544
580
|
});
|
|
545
581
|
};
|
|
546
582
|
|
|
547
583
|
return DragndropPlugin;
|
|
548
584
|
}(), _class.tag = 'Dragndrop', _class);
|
|
549
585
|
|
|
550
|
-
tslib.__decorate([
|
|
586
|
+
tslib.__decorate([g.inject(g.SceneGraphService), tslib.__metadata("design:type", Object)], DragndropPlugin.prototype, "sceneGraphService", void 0);
|
|
551
587
|
|
|
552
|
-
tslib.__decorate([
|
|
588
|
+
tslib.__decorate([g.inject(g.RenderingContext), tslib.__metadata("design:type", Object)], DragndropPlugin.prototype, "renderingContext", void 0);
|
|
553
589
|
|
|
554
|
-
tslib.__decorate([
|
|
590
|
+
tslib.__decorate([g.inject(DragndropPluginOptions), tslib.__metadata("design:type", Object)], DragndropPlugin.prototype, "dragndropPluginOptions", void 0);
|
|
555
591
|
|
|
556
|
-
DragndropPlugin = DragndropPlugin_1 = tslib.__decorate([
|
|
592
|
+
DragndropPlugin = DragndropPlugin_1 = tslib.__decorate([g.singleton({
|
|
557
593
|
contrib: g.RenderingPluginContribution
|
|
558
594
|
})], DragndropPlugin);
|
|
559
595
|
|
|
560
|
-
var containerModule =
|
|
596
|
+
var containerModule = g.Module(function (register) {
|
|
561
597
|
register(DragndropPlugin);
|
|
562
598
|
});
|
|
563
599
|
var Plugin = /*#__PURE__*/function () {
|
|
@@ -576,7 +612,11 @@ var Plugin = /*#__PURE__*/function () {
|
|
|
576
612
|
_proto.init = function init(container) {
|
|
577
613
|
container.register(DragndropPluginOptions, {
|
|
578
614
|
useValue: _extends({
|
|
579
|
-
overlap: 'pointer'
|
|
615
|
+
overlap: 'pointer',
|
|
616
|
+
isDocumentDraggable: false,
|
|
617
|
+
isDocumentDroppable: false,
|
|
618
|
+
dragstartDistanceThreshold: 0,
|
|
619
|
+
dragstartTimeThreshold: 0
|
|
580
620
|
}, this.options)
|
|
581
621
|
});
|
|
582
622
|
container.load(containerModule, true);
|
package/dist/index.umd.js
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
(function (global, factory) {
|
|
2
|
-
typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports, require('
|
|
3
|
-
typeof define === 'function' && define.amd ? define(['exports', '
|
|
4
|
-
(global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory((global.G = global.G || {}, global.G.Dragndrop = {}), global.window.G
|
|
5
|
-
}(this, (function (exports,
|
|
2
|
+
typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports, require('@antv/g')) :
|
|
3
|
+
typeof define === 'function' && define.amd ? define(['exports', '@antv/g'], factory) :
|
|
4
|
+
(global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory((global.G = global.G || {}, global.G.Dragndrop = {}), global.window.G));
|
|
5
|
+
}(this, (function (exports, g) { 'use strict';
|
|
6
6
|
|
|
7
7
|
function _regeneratorRuntime() {
|
|
8
8
|
/*! regenerator-runtime -- Copyright (c) 2014-present, Facebook, Inc. -- license (MIT): https://github.com/facebook/regenerator/blob/main/LICENSE */
|
|
@@ -429,7 +429,7 @@
|
|
|
429
429
|
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(metadataKey, metadataValue);
|
|
430
430
|
}
|
|
431
431
|
|
|
432
|
-
var DragndropPluginOptions =
|
|
432
|
+
var DragndropPluginOptions = g.Syringe.defineToken('DragndropPluginOptions');
|
|
433
433
|
|
|
434
434
|
var _class;
|
|
435
435
|
|
|
@@ -444,46 +444,71 @@
|
|
|
444
444
|
var _proto = DragndropPlugin.prototype;
|
|
445
445
|
|
|
446
446
|
_proto.apply = function apply(renderingService) {
|
|
447
|
-
var
|
|
447
|
+
var document = this.renderingContext.root.ownerDocument; // TODO: should we add an option like `draggable` to Canvas
|
|
448
448
|
|
|
449
|
-
var
|
|
450
|
-
var
|
|
449
|
+
var canvas = document.defaultView;
|
|
450
|
+
var _this$dragndropPlugin = this.dragndropPluginOptions,
|
|
451
|
+
overlap = _this$dragndropPlugin.overlap,
|
|
452
|
+
isDocumentDraggable = _this$dragndropPlugin.isDocumentDraggable,
|
|
453
|
+
isDocumentDroppable = _this$dragndropPlugin.isDocumentDroppable,
|
|
454
|
+
dragstartDistanceThreshold = _this$dragndropPlugin.dragstartDistanceThreshold,
|
|
455
|
+
dragstartTimeThreshold = _this$dragndropPlugin.dragstartTimeThreshold;
|
|
451
456
|
|
|
452
457
|
var handlePointerdown = function handlePointerdown(event) {
|
|
453
458
|
var target = event.target;
|
|
459
|
+
var isDocument = target === document;
|
|
454
460
|
|
|
455
|
-
if (target.getAttribute('draggable')) {
|
|
461
|
+
if (isDocument && isDocumentDraggable || target.getAttribute && target.getAttribute('draggable')) {
|
|
456
462
|
// @ts-ignore
|
|
457
463
|
var onMouseMove = /*#__PURE__*/function () {
|
|
458
464
|
var _ref = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee(event) {
|
|
459
|
-
var pointerEventsOldValue, point, elemBelow, droppableBelow;
|
|
465
|
+
var timeElapsed, distanceMoved, pointerEventsOldValue, point, elemBelow, droppableBelow;
|
|
460
466
|
return _regeneratorRuntime().wrap(function _callee$(_context) {
|
|
461
467
|
while (1) {
|
|
462
468
|
switch (_context.prev = _context.next) {
|
|
463
469
|
case 0:
|
|
470
|
+
if (dragstartTriggered) {
|
|
471
|
+
_context.next = 8;
|
|
472
|
+
break;
|
|
473
|
+
}
|
|
474
|
+
|
|
475
|
+
timeElapsed = event.timeStamp - dragstartTimeStamp;
|
|
476
|
+
distanceMoved = Math.sqrt(Math.pow(event.canvasX - dragstartCanvasCoordinates[0], 2) + Math.pow(event.canvasY - dragstartCanvasCoordinates[1], 2)); // check thresholds
|
|
477
|
+
|
|
478
|
+
if (!(timeElapsed <= dragstartTimeThreshold || distanceMoved <= dragstartDistanceThreshold)) {
|
|
479
|
+
_context.next = 5;
|
|
480
|
+
break;
|
|
481
|
+
}
|
|
482
|
+
|
|
483
|
+
return _context.abrupt("return");
|
|
484
|
+
|
|
485
|
+
case 5:
|
|
486
|
+
// @see https://developer.mozilla.org/zh-CN/docs/Web/API/Document/dragstart_event
|
|
487
|
+
event.type = 'dragstart';
|
|
488
|
+
target.dispatchEvent(event);
|
|
489
|
+
dragstartTriggered = true;
|
|
490
|
+
|
|
491
|
+
case 8:
|
|
464
492
|
// @see https://developer.mozilla.org/zh-CN/docs/Web/API/Document/drag_event
|
|
465
493
|
event.type = 'drag';
|
|
466
|
-
target.dispatchEvent(event);
|
|
494
|
+
target.dispatchEvent(event);
|
|
467
495
|
|
|
496
|
+
if (isDocument) {
|
|
497
|
+
_context.next = 20;
|
|
498
|
+
break;
|
|
499
|
+
}
|
|
500
|
+
|
|
501
|
+
// prevent from picking the dragging element
|
|
468
502
|
pointerEventsOldValue = target.style.pointerEvents;
|
|
469
503
|
target.style.pointerEvents = 'none';
|
|
470
504
|
point = overlap === 'pointer' ? [event.canvasX, event.canvasY] : target.getBounds().center;
|
|
471
|
-
_context.next =
|
|
505
|
+
_context.next = 16;
|
|
472
506
|
return document.elementFromPoint(point[0], point[1]);
|
|
473
507
|
|
|
474
|
-
case
|
|
508
|
+
case 16:
|
|
475
509
|
elemBelow = _context.sent;
|
|
476
510
|
target.style.pointerEvents = pointerEventsOldValue;
|
|
477
|
-
|
|
478
|
-
if (elemBelow) {
|
|
479
|
-
_context.next = 11;
|
|
480
|
-
break;
|
|
481
|
-
}
|
|
482
|
-
|
|
483
|
-
return _context.abrupt("return");
|
|
484
|
-
|
|
485
|
-
case 11:
|
|
486
|
-
droppableBelow = (elemBelow === null || elemBelow === void 0 ? void 0 : elemBelow.closest('[droppable=true]')) || null;
|
|
511
|
+
droppableBelow = (elemBelow === null || elemBelow === void 0 ? void 0 : elemBelow.closest('[droppable=true]')) || (isDocumentDroppable ? document : null);
|
|
487
512
|
|
|
488
513
|
if (currentDroppable !== droppableBelow) {
|
|
489
514
|
if (currentDroppable) {
|
|
@@ -512,7 +537,7 @@
|
|
|
512
537
|
}
|
|
513
538
|
}
|
|
514
539
|
|
|
515
|
-
case
|
|
540
|
+
case 20:
|
|
516
541
|
case "end":
|
|
517
542
|
return _context.stop();
|
|
518
543
|
}
|
|
@@ -525,25 +550,37 @@
|
|
|
525
550
|
};
|
|
526
551
|
}();
|
|
527
552
|
|
|
528
|
-
//
|
|
529
|
-
|
|
530
|
-
|
|
553
|
+
// delay triggering dragstart event
|
|
554
|
+
var dragstartTriggered = false;
|
|
555
|
+
var dragstartTimeStamp = event.timeStamp;
|
|
556
|
+
var dragstartCanvasCoordinates = [event.canvasX, event.canvasY];
|
|
531
557
|
var currentDroppable = null;
|
|
532
|
-
|
|
533
|
-
|
|
534
|
-
|
|
535
|
-
|
|
536
|
-
|
|
537
|
-
|
|
538
|
-
|
|
539
|
-
|
|
540
|
-
|
|
541
|
-
|
|
542
|
-
|
|
558
|
+
canvas.addEventListener('pointermove', onMouseMove);
|
|
559
|
+
|
|
560
|
+
var stopDragging = function stopDragging() {
|
|
561
|
+
if (dragstartTriggered) {
|
|
562
|
+
// drop should fire before dragend
|
|
563
|
+
// @see https://javascript.tutorialink.com/is-there-a-defined-ordering-between-dragend-and-drop-events/
|
|
564
|
+
if (currentDroppable) {
|
|
565
|
+
// @see https://developer.mozilla.org/zh-CN/docs/Web/API/Document/drop_event
|
|
566
|
+
event.type = 'drop';
|
|
567
|
+
event.target = currentDroppable;
|
|
568
|
+
currentDroppable.dispatchEvent(event);
|
|
569
|
+
} // @see https://developer.mozilla.org/zh-CN/docs/Web/API/Document/dragend_event
|
|
570
|
+
|
|
571
|
+
|
|
572
|
+
event.type = 'dragend';
|
|
573
|
+
target.dispatchEvent(event);
|
|
574
|
+
dragstartTriggered = false;
|
|
543
575
|
}
|
|
544
576
|
|
|
545
|
-
|
|
546
|
-
}
|
|
577
|
+
canvas.removeEventListener('pointermove', onMouseMove);
|
|
578
|
+
};
|
|
579
|
+
|
|
580
|
+
target.addEventListener('pointerup', stopDragging, {
|
|
581
|
+
once: true
|
|
582
|
+
});
|
|
583
|
+
target.addEventListener('pointerupoutside', stopDragging, {
|
|
547
584
|
once: true
|
|
548
585
|
});
|
|
549
586
|
}
|
|
@@ -554,7 +591,7 @@
|
|
|
554
591
|
while (1) {
|
|
555
592
|
switch (_context2.prev = _context2.next) {
|
|
556
593
|
case 0:
|
|
557
|
-
|
|
594
|
+
canvas.addEventListener('pointerdown', handlePointerdown);
|
|
558
595
|
|
|
559
596
|
case 1:
|
|
560
597
|
case "end":
|
|
@@ -564,24 +601,24 @@
|
|
|
564
601
|
}, _callee2);
|
|
565
602
|
})));
|
|
566
603
|
renderingService.hooks.destroy.tap(DragndropPlugin_1.tag, function () {
|
|
567
|
-
|
|
604
|
+
canvas.removeEventListener('pointerdown', handlePointerdown);
|
|
568
605
|
});
|
|
569
606
|
};
|
|
570
607
|
|
|
571
608
|
return DragndropPlugin;
|
|
572
609
|
}(), _class.tag = 'Dragndrop', _class);
|
|
573
610
|
|
|
574
|
-
__decorate([
|
|
611
|
+
__decorate([g.inject(g.SceneGraphService), __metadata("design:type", Object)], DragndropPlugin.prototype, "sceneGraphService", void 0);
|
|
575
612
|
|
|
576
|
-
__decorate([
|
|
613
|
+
__decorate([g.inject(g.RenderingContext), __metadata("design:type", Object)], DragndropPlugin.prototype, "renderingContext", void 0);
|
|
577
614
|
|
|
578
|
-
__decorate([
|
|
615
|
+
__decorate([g.inject(DragndropPluginOptions), __metadata("design:type", Object)], DragndropPlugin.prototype, "dragndropPluginOptions", void 0);
|
|
579
616
|
|
|
580
|
-
DragndropPlugin = DragndropPlugin_1 = __decorate([
|
|
617
|
+
DragndropPlugin = DragndropPlugin_1 = __decorate([g.singleton({
|
|
581
618
|
contrib: g.RenderingPluginContribution
|
|
582
619
|
})], DragndropPlugin);
|
|
583
620
|
|
|
584
|
-
var containerModule =
|
|
621
|
+
var containerModule = g.Module(function (register) {
|
|
585
622
|
register(DragndropPlugin);
|
|
586
623
|
});
|
|
587
624
|
var Plugin = /*#__PURE__*/function () {
|
|
@@ -600,7 +637,11 @@
|
|
|
600
637
|
_proto.init = function init(container) {
|
|
601
638
|
container.register(DragndropPluginOptions, {
|
|
602
639
|
useValue: _extends({
|
|
603
|
-
overlap: 'pointer'
|
|
640
|
+
overlap: 'pointer',
|
|
641
|
+
isDocumentDraggable: false,
|
|
642
|
+
isDocumentDroppable: false,
|
|
643
|
+
dragstartDistanceThreshold: 0,
|
|
644
|
+
dragstartTimeThreshold: 0
|
|
604
645
|
}, this.options)
|
|
605
646
|
});
|
|
606
647
|
container.load(containerModule, true);
|
package/dist/index.umd.min.js
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
!function(t,e){"object"==typeof exports&&"undefined"!=typeof module?e(exports,require("
|
|
1
|
+
!function(t,e){"object"==typeof exports&&"undefined"!=typeof module?e(exports,require("@antv/g")):"function"==typeof define&&define.amd?define(["exports","@antv/g"],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(){
|
|
2
2
|
/*! regenerator-runtime -- Copyright (c) 2014-present, Facebook, Inc. -- license (MIT): https://github.com/facebook/regenerator/blob/main/LICENSE */
|
|
3
|
-
n=function(){return t};var t={},e=Object.prototype,r=e.hasOwnProperty,o="function"==typeof Symbol?Symbol:{},i=o.iterator||"@@iterator",a=o.asyncIterator||"@@asyncIterator",c=o.toStringTag||"@@toStringTag";function u(t,e,r){return Object.defineProperty(t,e,{value:r,enumerable:!0,configurable:!0,writable:!0}),t[e]}try{u({},"")}catch(t){u=function(t,e,r){return t[e]=r}}function s(t,e,r,n){var o=Object.create((e&&e.prototype instanceof l?e:l).prototype),i=new O(n||[]);return o._invoke=function(t,e,r){var n="suspendedStart";return function(o,i){if("executing"===n)throw new Error("Generator is already running");if("completed"===n){if("throw"===o)throw i;return P()}for(r.method=o,r.arg=i;;){var a=r.delegate;if(a){var c=x(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)}}}(t,r,i),o}function f(t,e,r){try{return{type:"normal",arg:t.call(e,r)}}catch(t){return{type:"throw",arg:t}}}t.wrap=s;var p={};function l(){}function h(){}function d(){}var v={};u(v,i,(function(){return this}));var y=Object.getPrototypeOf,g=y&&y(y(j([])));g&&g!==e&&r.call(g,i)&&(v=g);var m=d.prototype=l.prototype=Object.create(v);function w(t){["next","throw","return"].forEach((function(e){u(t,e,(function(t){return this._invoke(e,t)}))}))}function b(t,e){function n(o,i,a,c){var u=f(t[o],t,i);if("throw"!==u.type){var s=u.arg,p=s.value;return p&&"object"==typeof p&&r.call(p,"__await")?e.resolve(p.__await).then((function(t){n("next",t,a,c)}),(function(t){n("throw",t,a,c)})):e.resolve(p).then((function(t){s.value=t,a(s)}),(function(t){return n("throw",t,a,c)}))}c(u.arg)}var o;this._invoke=function(t,r){function i(){return new e((function(e,o){n(t,r,e,o)}))}return o=o?o.then(i,i):i()}}function x(t,e){var r=t.iterator[e.method];if(void 0===r){if(e.delegate=null,"throw"===e.method){if(t.iterator.return&&(e.method="return",e.arg=void 0,x(t,e),"throw"===e.method))return p;e.method="throw",e.arg=new TypeError("The iterator does not provide a 'throw' method")}return p}var n=f(r,t.iterator,e.arg);if("throw"===n.type)return e.method="throw",e.arg=n.arg,e.delegate=null,p;var o=n.arg;return o?o.done?(e[t.resultName]=o.value,e.next=t.nextLoc,"return"!==e.method&&(e.method="next",e.arg=void 0),e.delegate=null,p):o:(e.method="throw",e.arg=new TypeError("iterator result is not an object"),e.delegate=null,p)}function E(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 L(t){var e=t.completion||{};e.type="normal",delete e.arg,t.completion=e}function O(t){this.tryEntries=[{tryLoc:"root"}],t.forEach(E,this),this.reset(!0)}function j(t){if(t){var e=t[i];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:P}}function P(){return{value:void 0,done:!0}}return h.prototype=d,u(m,"constructor",d),u(d,"constructor",h),h.displayName=u(d,c,"GeneratorFunction"),t.isGeneratorFunction=function(t){var e="function"==typeof t&&t.constructor;return!!e&&(e===h||"GeneratorFunction"===(e.displayName||e.name))},t.mark=function(t){return Object.setPrototypeOf?Object.setPrototypeOf(t,d):(t.__proto__=d,u(t,c,"GeneratorFunction")),t.prototype=Object.create(m),t},t.awrap=function(t){return{__await:t}},w(b.prototype),u(b.prototype,a,(function(){return this})),t.AsyncIterator=b,t.async=function(e,r,n,o,i){void 0===i&&(i=Promise);var a=new b(s(e,r,n,o),i);return t.isGeneratorFunction(r)?a:a.next().then((function(t){return t.done?t.value:a.next()}))},w(m),u(m,c,"Generator"),u(m,i,(function(){return this})),u(m,"toString",(function(){return"[object Generator]"})),t.keys=function(t){var e=[];for(var r in t)e.push(r);return e.reverse(),function r(){for(;e.length;){var n=e.pop();if(n in t)return r.value=n,r.done=!1,r}return r.done=!0,r}},t.values=j,O.prototype={constructor:O,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(L),!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 new 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),L(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;L(r)}return o}}throw new Error("illegal catch attempt")},delegateYield:function(t,e,r){return this.delegate={iterator:j(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(){return a=Object.assign||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},a.apply(this,arguments)}function c(t,e,r,n){var o,i=arguments.length,a=3>i?e:null===n?n=Object.getOwnPropertyDescriptor(e,r):n;if("object"==typeof Reflect&&"function"==typeof Reflect.decorate)a=Reflect.decorate(t,e,r,n);else for(var c=t.length-1;c>=0;c--)(o=t[c])&&(a=(3>i?o(a):i>3?o(e,r,a):o(e,r))||a);return i>3&&a&&Object.defineProperty(e,r,a),a}function u(t,e){if("object"==typeof Reflect&&"function"==typeof Reflect.metadata)return Reflect.metadata(t,e)}var s,f,p=e.Syringe.defineToken("DragndropPluginOptions"),l=(s=function(){function t(){this.sceneGraphService=void 0,this.renderingContext=void 0,this.dragndropPluginOptions=void 0}return t.prototype.apply=function(t){var e=this,r=this.renderingContext.root.ownerDocument,o=this.dragndropPluginOptions.overlap,a=function(t){var e=t.target;if(e.getAttribute("draggable")){var a=function(){var t=i(n().mark((function t(i){var a,u,s,f;return n().wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return i.type="drag",e.dispatchEvent(i),a=e.style.pointerEvents,e.style.pointerEvents="none",u="pointer"===o?[i.canvasX,i.canvasY]:e.getBounds().center,t.next=7,r.elementFromPoint(u[0],u[1]);case 7:if(s=t.sent,e.style.pointerEvents=a,s){t.next=11;break}return t.abrupt("return");case 11:f=(null==s?void 0:s.closest("[droppable=true]"))||null,c!==f&&(c&&(i.type="dragleave",i.target=c,c.dispatchEvent(i)),f&&(i.type="dragenter",i.target=f,f.dispatchEvent(i)),(c=f)&&(i.type="dragover",i.target=c,c.dispatchEvent(i)));case 13:case"end":return t.stop()}}),t)})));return function(e){return t.apply(this,arguments)}}();t.type="dragstart",e.dispatchEvent(t);var c=null;r.addEventListener("pointermove",a),e.addEventListener("pointerup",(function(){t.type="dragend",e.dispatchEvent(t),c&&(t.type="drop",t.target=c,c.dispatchEvent(t)),r.removeEventListener("pointermove",a)}),{once:!0})}};t.hooks.init.tapPromise(f.tag,i(n().mark((function t(){return n().wrap((function(t){for(;;)switch(t.prev=t.next){case 0:e.renderingContext.root.addEventListener("pointerdown",a);case 1:case"end":return t.stop()}}),t)})))),t.hooks.destroy.tap(f.tag,(function(){e.renderingContext.root.removeEventListener("pointerdown",a)}))},t}(),s.tag="Dragndrop",f=s);c([e.inject(r.SceneGraphService),u("design:type",Object)],l.prototype,"sceneGraphService",void 0),c([e.inject(r.RenderingContext),u("design:type",Object)],l.prototype,"renderingContext",void 0),c([e.inject(p),u("design:type",Object)],l.prototype,"dragndropPluginOptions",void 0),l=f=c([e.singleton({contrib:r.RenderingPluginContribution})],l);var h=e.Module((function(t){t(l)}));t.Plugin=function(){function t(t){void 0===t&&(t={}),this.options=void 0,this.name="dragndrop",this.options=t}var e=t.prototype;return e.init=function(t){t.register(p,{useValue:a({overlap:"pointer"},this.options)}),t.load(h,!0)},e.destroy=function(t){t.remove(p),t.unload(h)},t}(),Object.defineProperty(t,"__esModule",{value:!0})}));
|
|
3
|
+
r=function(){return t};var t={},e=Object.prototype,n=e.hasOwnProperty,o="function"==typeof Symbol?Symbol:{},i=o.iterator||"@@iterator",a=o.asyncIterator||"@@asyncIterator",c=o.toStringTag||"@@toStringTag";function u(t,e,r){return Object.defineProperty(t,e,{value:r,enumerable:!0,configurable:!0,writable:!0}),t[e]}try{u({},"")}catch(t){u=function(t,e,r){return t[e]=r}}function s(t,e,r,n){var o=Object.create((e&&e.prototype instanceof l?e:l).prototype),i=new O(n||[]);return o._invoke=function(t,e,r){var n="suspendedStart";return function(o,i){if("executing"===n)throw new Error("Generator is already running");if("completed"===n){if("throw"===o)throw i;return P()}for(r.method=o,r.arg=i;;){var a=r.delegate;if(a){var c=x(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)}}}(t,r,i),o}function f(t,e,r){try{return{type:"normal",arg:t.call(e,r)}}catch(t){return{type:"throw",arg:t}}}t.wrap=s;var p={};function l(){}function h(){}function d(){}var v={};u(v,i,(function(){return this}));var y=Object.getPrototypeOf,g=y&&y(y(j([])));g&&g!==e&&n.call(g,i)&&(v=g);var m=d.prototype=l.prototype=Object.create(v);function w(t){["next","throw","return"].forEach((function(e){u(t,e,(function(t){return this._invoke(e,t)}))}))}function b(t,e){function r(o,i,a,c){var u=f(t[o],t,i);if("throw"!==u.type){var s=u.arg,p=s.value;return p&&"object"==typeof p&&n.call(p,"__await")?e.resolve(p.__await).then((function(t){r("next",t,a,c)}),(function(t){r("throw",t,a,c)})):e.resolve(p).then((function(t){s.value=t,a(s)}),(function(t){return r("throw",t,a,c)}))}c(u.arg)}var o;this._invoke=function(t,n){function i(){return new e((function(e,o){r(t,n,e,o)}))}return o=o?o.then(i,i):i()}}function x(t,e){var r=t.iterator[e.method];if(void 0===r){if(e.delegate=null,"throw"===e.method){if(t.iterator.return&&(e.method="return",e.arg=void 0,x(t,e),"throw"===e.method))return p;e.method="throw",e.arg=new TypeError("The iterator does not provide a 'throw' method")}return p}var n=f(r,t.iterator,e.arg);if("throw"===n.type)return e.method="throw",e.arg=n.arg,e.delegate=null,p;var o=n.arg;return o?o.done?(e[t.resultName]=o.value,e.next=t.nextLoc,"return"!==e.method&&(e.method="next",e.arg=void 0),e.delegate=null,p):o:(e.method="throw",e.arg=new TypeError("iterator result is not an object"),e.delegate=null,p)}function E(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 L(t){var e=t.completion||{};e.type="normal",delete e.arg,t.completion=e}function O(t){this.tryEntries=[{tryLoc:"root"}],t.forEach(E,this),this.reset(!0)}function j(t){if(t){var e=t[i];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:P}}function P(){return{value:void 0,done:!0}}return h.prototype=d,u(m,"constructor",d),u(d,"constructor",h),h.displayName=u(d,c,"GeneratorFunction"),t.isGeneratorFunction=function(t){var e="function"==typeof t&&t.constructor;return!!e&&(e===h||"GeneratorFunction"===(e.displayName||e.name))},t.mark=function(t){return Object.setPrototypeOf?Object.setPrototypeOf(t,d):(t.__proto__=d,u(t,c,"GeneratorFunction")),t.prototype=Object.create(m),t},t.awrap=function(t){return{__await:t}},w(b.prototype),u(b.prototype,a,(function(){return this})),t.AsyncIterator=b,t.async=function(e,r,n,o,i){void 0===i&&(i=Promise);var a=new b(s(e,r,n,o),i);return t.isGeneratorFunction(r)?a:a.next().then((function(t){return t.done?t.value:a.next()}))},w(m),u(m,c,"Generator"),u(m,i,(function(){return this})),u(m,"toString",(function(){return"[object Generator]"})),t.keys=function(t){var e=[];for(var r in t)e.push(r);return e.reverse(),function r(){for(;e.length;){var n=e.pop();if(n in t)return r.value=n,r.done=!1,r}return r.done=!0,r}},t.values=j,O.prototype={constructor:O,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(L),!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 new 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,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),L(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;L(r)}return o}}throw new Error("illegal catch attempt")},delegateYield:function(t,e,r){return this.delegate={iterator:j(t),resultName:e,nextLoc:r},"next"===this.method&&(this.arg=void 0),p}},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||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,r,n){var o,i=arguments.length,a=3>i?e:null===n?n=Object.getOwnPropertyDescriptor(e,r):n;if("object"==typeof Reflect&&"function"==typeof Reflect.decorate)a=Reflect.decorate(t,e,r,n);else for(var c=t.length-1;c>=0;c--)(o=t[c])&&(a=(3>i?o(a):i>3?o(e,r,a):o(e,r))||a);return i>3&&a&&Object.defineProperty(e,r,a),a}function c(t,e){if("object"==typeof Reflect&&"function"==typeof Reflect.metadata)return Reflect.metadata(t,e)}var u,s,f=e.Syringe.defineToken("DragndropPluginOptions"),p=(u=function(){function t(){this.sceneGraphService=void 0,this.renderingContext=void 0,this.dragndropPluginOptions=void 0}return t.prototype.apply=function(t){var e=this.renderingContext.root.ownerDocument,n=e.defaultView,i=this.dragndropPluginOptions,a=i.overlap,c=i.isDocumentDraggable,u=i.isDocumentDroppable,f=i.dragstartDistanceThreshold,p=i.dragstartTimeThreshold,l=function(t){var i=t.target,s=i===e;if(s&&c||i.getAttribute&&i.getAttribute("draggable")){var l=function(){var t=o(r().mark((function t(n){var o,c,l,g,m,w;return r().wrap((function(t){for(;;)switch(t.prev=t.next){case 0:if(h){t.next=8;break}if(o=n.timeStamp-d,c=Math.sqrt(Math.pow(n.canvasX-v[0],2)+Math.pow(n.canvasY-v[1],2)),o>p&&c>f){t.next=5;break}return t.abrupt("return");case 5:n.type="dragstart",i.dispatchEvent(n),h=!0;case 8:if(n.type="drag",i.dispatchEvent(n),s){t.next=20;break}return l=i.style.pointerEvents,i.style.pointerEvents="none",g="pointer"===a?[n.canvasX,n.canvasY]:i.getBounds().center,t.next=16,e.elementFromPoint(g[0],g[1]);case 16:m=t.sent,i.style.pointerEvents=l,w=(null==m?void 0:m.closest("[droppable=true]"))||(u?e:null),y!==w&&(y&&(n.type="dragleave",n.target=y,y.dispatchEvent(n)),w&&(n.type="dragenter",n.target=w,w.dispatchEvent(n)),(y=w)&&(n.type="dragover",n.target=y,y.dispatchEvent(n)));case 20:case"end":return t.stop()}}),t)})));return function(e){return t.apply(this,arguments)}}(),h=!1,d=t.timeStamp,v=[t.canvasX,t.canvasY],y=null;n.addEventListener("pointermove",l);var g=function(){h&&(y&&(t.type="drop",t.target=y,y.dispatchEvent(t)),t.type="dragend",i.dispatchEvent(t),h=!1),n.removeEventListener("pointermove",l)};i.addEventListener("pointerup",g,{once:!0}),i.addEventListener("pointerupoutside",g,{once:!0})}};t.hooks.init.tapPromise(s.tag,o(r().mark((function t(){return r().wrap((function(t){for(;;)switch(t.prev=t.next){case 0:n.addEventListener("pointerdown",l);case 1:case"end":return t.stop()}}),t)})))),t.hooks.destroy.tap(s.tag,(function(){n.removeEventListener("pointerdown",l)}))},t}(),u.tag="Dragndrop",s=u);a([e.inject(e.SceneGraphService),c("design:type",Object)],p.prototype,"sceneGraphService",void 0),a([e.inject(e.RenderingContext),c("design:type",Object)],p.prototype,"renderingContext",void 0),a([e.inject(f),c("design:type",Object)],p.prototype,"dragndropPluginOptions",void 0),p=s=a([e.singleton({contrib:e.RenderingPluginContribution})],p);var l=e.Module((function(t){t(p)}));t.Plugin=function(){function t(t){void 0===t&&(t={}),this.options=void 0,this.name="dragndrop",this.options=t}var e=t.prototype;return e.init=function(t){t.register(f,{useValue:i({overlap:"pointer",isDocumentDraggable:!1,isDocumentDroppable:!1,dragstartDistanceThreshold:0,dragstartTimeThreshold:0},this.options)}),t.load(l,!0)},e.destroy=function(t){t.remove(f),t.unload(l)},t}(),Object.defineProperty(t,"__esModule",{value:!0})}));
|
package/dist/tokens.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { Syringe } from '
|
|
1
|
+
import { Syringe } from '@antv/g';
|
|
2
2
|
export declare const DragndropPluginOptions: Syringe.DefinedToken;
|
|
3
3
|
export interface DragndropPluginOptions {
|
|
4
4
|
/**
|
|
@@ -8,5 +8,23 @@ export interface DragndropPluginOptions {
|
|
|
8
8
|
* @see https://interactjs.io/docs/dropzone/#accept
|
|
9
9
|
*/
|
|
10
10
|
overlap: 'pointer' | 'center';
|
|
11
|
+
/**
|
|
12
|
+
* Since Canvas & Document don't have `draggable` attribute,
|
|
13
|
+
* we need to add an extra option.
|
|
14
|
+
*/
|
|
15
|
+
isDocumentDraggable: boolean;
|
|
16
|
+
/**
|
|
17
|
+
* Since Canvas & Document don't have `droppable` attribute,
|
|
18
|
+
* we need to add an extra option.
|
|
19
|
+
*/
|
|
20
|
+
isDocumentDroppable: boolean;
|
|
21
|
+
/**
|
|
22
|
+
* Threshold for triggering `dragstart` event in milliseconds.
|
|
23
|
+
*/
|
|
24
|
+
dragstartTimeThreshold: number;
|
|
25
|
+
/**
|
|
26
|
+
* Threshold for triggering `dragstart` event in pixels.
|
|
27
|
+
*/
|
|
28
|
+
dragstartDistanceThreshold: number;
|
|
11
29
|
}
|
|
12
30
|
//# sourceMappingURL=tokens.d.ts.map
|
package/dist/tokens.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"tokens.d.ts","sourceRoot":"","sources":["../src/tokens.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,
|
|
1
|
+
{"version":3,"file":"tokens.d.ts","sourceRoot":"","sources":["../src/tokens.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,SAAS,CAAC;AAElC,eAAO,MAAM,sBAAsB,sBAAgD,CAAC;AAEpF,MAAM,WAAW,sBAAsB;IACrC;;;;;OAKG;IACH,OAAO,EAAE,SAAS,GAAG,QAAQ,CAAC;IAE9B;;;OAGG;IACH,mBAAmB,EAAE,OAAO,CAAC;IAE7B;;;OAGG;IACH,mBAAmB,EAAE,OAAO,CAAC;IAE7B;;OAEG;IACH,sBAAsB,EAAE,MAAM,CAAC;IAE/B;;OAEG;IACH,0BAA0B,EAAE,MAAM,CAAC;CACpC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@antv/g-plugin-dragndrop",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.1.0",
|
|
4
4
|
"description": "A G plugin for Drag n Drop implemented with PointerEvents",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"antv",
|
|
@@ -33,11 +33,10 @@
|
|
|
33
33
|
"@types/jest": "^25.0.0"
|
|
34
34
|
},
|
|
35
35
|
"peerDependencies": {
|
|
36
|
-
"@antv/g": "^5.0.1"
|
|
37
|
-
"mana-syringe": "^0.3.0"
|
|
36
|
+
"@antv/g": "^5.0.1"
|
|
38
37
|
},
|
|
39
38
|
"publishConfig": {
|
|
40
39
|
"access": "public"
|
|
41
40
|
},
|
|
42
|
-
"gitHead": "
|
|
41
|
+
"gitHead": "bf0d57ef10d56f48d6258906281b9edb34bffb48"
|
|
43
42
|
}
|