@antv/g-plugin-dragndrop 1.0.5 → 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/DragndropPlugin.d.ts.map +1 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.esm.js +65 -27
- package/dist/index.js +65 -27
- package/dist/index.umd.js +65 -27
- package/dist/index.umd.min.js +1 -1
- package/dist/tokens.d.ts +13 -0
- package/dist/tokens.d.ts.map +1 -1
- package/package.json +2 -2
|
@@ -1 +1 @@
|
|
|
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;
|
|
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.map
CHANGED
|
@@ -1 +1 @@
|
|
|
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;
|
|
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
|
@@ -383,7 +383,7 @@ function _asyncToGenerator(fn) {
|
|
|
383
383
|
}
|
|
384
384
|
|
|
385
385
|
function _extends() {
|
|
386
|
-
_extends = Object.assign
|
|
386
|
+
_extends = Object.assign ? Object.assign.bind() : function (target) {
|
|
387
387
|
for (var i = 1; i < arguments.length; i++) {
|
|
388
388
|
var source = arguments[i];
|
|
389
389
|
|
|
@@ -396,7 +396,6 @@ function _extends() {
|
|
|
396
396
|
|
|
397
397
|
return target;
|
|
398
398
|
};
|
|
399
|
-
|
|
400
399
|
return _extends.apply(this, arguments);
|
|
401
400
|
}
|
|
402
401
|
|
|
@@ -420,7 +419,10 @@ var DragndropPlugin = DragndropPlugin_1 = (_class = /*#__PURE__*/function () {
|
|
|
420
419
|
var canvas = document.defaultView;
|
|
421
420
|
var _this$dragndropPlugin = this.dragndropPluginOptions,
|
|
422
421
|
overlap = _this$dragndropPlugin.overlap,
|
|
423
|
-
isDocumentDraggable = _this$dragndropPlugin.isDocumentDraggable
|
|
422
|
+
isDocumentDraggable = _this$dragndropPlugin.isDocumentDraggable,
|
|
423
|
+
isDocumentDroppable = _this$dragndropPlugin.isDocumentDroppable,
|
|
424
|
+
dragstartDistanceThreshold = _this$dragndropPlugin.dragstartDistanceThreshold,
|
|
425
|
+
dragstartTimeThreshold = _this$dragndropPlugin.dragstartTimeThreshold;
|
|
424
426
|
|
|
425
427
|
var handlePointerdown = function handlePointerdown(event) {
|
|
426
428
|
var target = event.target;
|
|
@@ -430,17 +432,39 @@ var DragndropPlugin = DragndropPlugin_1 = (_class = /*#__PURE__*/function () {
|
|
|
430
432
|
// @ts-ignore
|
|
431
433
|
var onMouseMove = /*#__PURE__*/function () {
|
|
432
434
|
var _ref = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee(event) {
|
|
433
|
-
var pointerEventsOldValue, point, elemBelow, droppableBelow;
|
|
435
|
+
var timeElapsed, distanceMoved, pointerEventsOldValue, point, elemBelow, droppableBelow;
|
|
434
436
|
return _regeneratorRuntime().wrap(function _callee$(_context) {
|
|
435
437
|
while (1) {
|
|
436
438
|
switch (_context.prev = _context.next) {
|
|
437
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:
|
|
438
462
|
// @see https://developer.mozilla.org/zh-CN/docs/Web/API/Document/drag_event
|
|
439
463
|
event.type = 'drag';
|
|
440
464
|
target.dispatchEvent(event);
|
|
441
465
|
|
|
442
466
|
if (isDocument) {
|
|
443
|
-
_context.next =
|
|
467
|
+
_context.next = 20;
|
|
444
468
|
break;
|
|
445
469
|
}
|
|
446
470
|
|
|
@@ -448,13 +472,13 @@ var DragndropPlugin = DragndropPlugin_1 = (_class = /*#__PURE__*/function () {
|
|
|
448
472
|
pointerEventsOldValue = target.style.pointerEvents;
|
|
449
473
|
target.style.pointerEvents = 'none';
|
|
450
474
|
point = overlap === 'pointer' ? [event.canvasX, event.canvasY] : target.getBounds().center;
|
|
451
|
-
_context.next =
|
|
475
|
+
_context.next = 16;
|
|
452
476
|
return document.elementFromPoint(point[0], point[1]);
|
|
453
477
|
|
|
454
|
-
case
|
|
478
|
+
case 16:
|
|
455
479
|
elemBelow = _context.sent;
|
|
456
480
|
target.style.pointerEvents = pointerEventsOldValue;
|
|
457
|
-
droppableBelow = (elemBelow === null || elemBelow === void 0 ? void 0 : elemBelow.closest('[droppable=true]')) || null;
|
|
481
|
+
droppableBelow = (elemBelow === null || elemBelow === void 0 ? void 0 : elemBelow.closest('[droppable=true]')) || (isDocumentDroppable ? document : null);
|
|
458
482
|
|
|
459
483
|
if (currentDroppable !== droppableBelow) {
|
|
460
484
|
if (currentDroppable) {
|
|
@@ -483,7 +507,7 @@ var DragndropPlugin = DragndropPlugin_1 = (_class = /*#__PURE__*/function () {
|
|
|
483
507
|
}
|
|
484
508
|
}
|
|
485
509
|
|
|
486
|
-
case
|
|
510
|
+
case 20:
|
|
487
511
|
case "end":
|
|
488
512
|
return _context.stop();
|
|
489
513
|
}
|
|
@@ -496,26 +520,37 @@ var DragndropPlugin = DragndropPlugin_1 = (_class = /*#__PURE__*/function () {
|
|
|
496
520
|
};
|
|
497
521
|
}();
|
|
498
522
|
|
|
499
|
-
//
|
|
500
|
-
|
|
501
|
-
|
|
523
|
+
// delay triggering dragstart event
|
|
524
|
+
var dragstartTriggered = false;
|
|
525
|
+
var dragstartTimeStamp = event.timeStamp;
|
|
526
|
+
var dragstartCanvasCoordinates = [event.canvasX, event.canvasY];
|
|
502
527
|
var currentDroppable = null;
|
|
503
528
|
canvas.addEventListener('pointermove', onMouseMove);
|
|
504
|
-
|
|
505
|
-
|
|
506
|
-
|
|
507
|
-
|
|
508
|
-
// @see https://
|
|
509
|
-
|
|
510
|
-
|
|
511
|
-
|
|
512
|
-
|
|
513
|
-
|
|
514
|
-
|
|
515
|
-
|
|
516
|
-
|
|
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
|
+
}
|
|
546
|
+
|
|
517
547
|
canvas.removeEventListener('pointermove', onMouseMove);
|
|
518
|
-
}
|
|
548
|
+
};
|
|
549
|
+
|
|
550
|
+
target.addEventListener('pointerup', stopDragging, {
|
|
551
|
+
once: true
|
|
552
|
+
});
|
|
553
|
+
target.addEventListener('pointerupoutside', stopDragging, {
|
|
519
554
|
once: true
|
|
520
555
|
});
|
|
521
556
|
}
|
|
@@ -573,7 +608,10 @@ var Plugin = /*#__PURE__*/function () {
|
|
|
573
608
|
container.register(DragndropPluginOptions, {
|
|
574
609
|
useValue: _extends({
|
|
575
610
|
overlap: 'pointer',
|
|
576
|
-
isDocumentDraggable: false
|
|
611
|
+
isDocumentDraggable: false,
|
|
612
|
+
isDocumentDroppable: false,
|
|
613
|
+
dragstartDistanceThreshold: 0,
|
|
614
|
+
dragstartTimeThreshold: 0
|
|
577
615
|
}, this.options)
|
|
578
616
|
});
|
|
579
617
|
container.load(containerModule, true);
|
package/dist/index.js
CHANGED
|
@@ -387,7 +387,7 @@ function _asyncToGenerator(fn) {
|
|
|
387
387
|
}
|
|
388
388
|
|
|
389
389
|
function _extends() {
|
|
390
|
-
_extends = Object.assign
|
|
390
|
+
_extends = Object.assign ? Object.assign.bind() : function (target) {
|
|
391
391
|
for (var i = 1; i < arguments.length; i++) {
|
|
392
392
|
var source = arguments[i];
|
|
393
393
|
|
|
@@ -400,7 +400,6 @@ function _extends() {
|
|
|
400
400
|
|
|
401
401
|
return target;
|
|
402
402
|
};
|
|
403
|
-
|
|
404
403
|
return _extends.apply(this, arguments);
|
|
405
404
|
}
|
|
406
405
|
|
|
@@ -424,7 +423,10 @@ var DragndropPlugin = DragndropPlugin_1 = (_class = /*#__PURE__*/function () {
|
|
|
424
423
|
var canvas = document.defaultView;
|
|
425
424
|
var _this$dragndropPlugin = this.dragndropPluginOptions,
|
|
426
425
|
overlap = _this$dragndropPlugin.overlap,
|
|
427
|
-
isDocumentDraggable = _this$dragndropPlugin.isDocumentDraggable
|
|
426
|
+
isDocumentDraggable = _this$dragndropPlugin.isDocumentDraggable,
|
|
427
|
+
isDocumentDroppable = _this$dragndropPlugin.isDocumentDroppable,
|
|
428
|
+
dragstartDistanceThreshold = _this$dragndropPlugin.dragstartDistanceThreshold,
|
|
429
|
+
dragstartTimeThreshold = _this$dragndropPlugin.dragstartTimeThreshold;
|
|
428
430
|
|
|
429
431
|
var handlePointerdown = function handlePointerdown(event) {
|
|
430
432
|
var target = event.target;
|
|
@@ -434,17 +436,39 @@ var DragndropPlugin = DragndropPlugin_1 = (_class = /*#__PURE__*/function () {
|
|
|
434
436
|
// @ts-ignore
|
|
435
437
|
var onMouseMove = /*#__PURE__*/function () {
|
|
436
438
|
var _ref = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee(event) {
|
|
437
|
-
var pointerEventsOldValue, point, elemBelow, droppableBelow;
|
|
439
|
+
var timeElapsed, distanceMoved, pointerEventsOldValue, point, elemBelow, droppableBelow;
|
|
438
440
|
return _regeneratorRuntime().wrap(function _callee$(_context) {
|
|
439
441
|
while (1) {
|
|
440
442
|
switch (_context.prev = _context.next) {
|
|
441
443
|
case 0:
|
|
444
|
+
if (dragstartTriggered) {
|
|
445
|
+
_context.next = 8;
|
|
446
|
+
break;
|
|
447
|
+
}
|
|
448
|
+
|
|
449
|
+
timeElapsed = event.timeStamp - dragstartTimeStamp;
|
|
450
|
+
distanceMoved = Math.sqrt(Math.pow(event.canvasX - dragstartCanvasCoordinates[0], 2) + Math.pow(event.canvasY - dragstartCanvasCoordinates[1], 2)); // check thresholds
|
|
451
|
+
|
|
452
|
+
if (!(timeElapsed <= dragstartTimeThreshold || distanceMoved <= dragstartDistanceThreshold)) {
|
|
453
|
+
_context.next = 5;
|
|
454
|
+
break;
|
|
455
|
+
}
|
|
456
|
+
|
|
457
|
+
return _context.abrupt("return");
|
|
458
|
+
|
|
459
|
+
case 5:
|
|
460
|
+
// @see https://developer.mozilla.org/zh-CN/docs/Web/API/Document/dragstart_event
|
|
461
|
+
event.type = 'dragstart';
|
|
462
|
+
target.dispatchEvent(event);
|
|
463
|
+
dragstartTriggered = true;
|
|
464
|
+
|
|
465
|
+
case 8:
|
|
442
466
|
// @see https://developer.mozilla.org/zh-CN/docs/Web/API/Document/drag_event
|
|
443
467
|
event.type = 'drag';
|
|
444
468
|
target.dispatchEvent(event);
|
|
445
469
|
|
|
446
470
|
if (isDocument) {
|
|
447
|
-
_context.next =
|
|
471
|
+
_context.next = 20;
|
|
448
472
|
break;
|
|
449
473
|
}
|
|
450
474
|
|
|
@@ -452,13 +476,13 @@ var DragndropPlugin = DragndropPlugin_1 = (_class = /*#__PURE__*/function () {
|
|
|
452
476
|
pointerEventsOldValue = target.style.pointerEvents;
|
|
453
477
|
target.style.pointerEvents = 'none';
|
|
454
478
|
point = overlap === 'pointer' ? [event.canvasX, event.canvasY] : target.getBounds().center;
|
|
455
|
-
_context.next =
|
|
479
|
+
_context.next = 16;
|
|
456
480
|
return document.elementFromPoint(point[0], point[1]);
|
|
457
481
|
|
|
458
|
-
case
|
|
482
|
+
case 16:
|
|
459
483
|
elemBelow = _context.sent;
|
|
460
484
|
target.style.pointerEvents = pointerEventsOldValue;
|
|
461
|
-
droppableBelow = (elemBelow === null || elemBelow === void 0 ? void 0 : elemBelow.closest('[droppable=true]')) || null;
|
|
485
|
+
droppableBelow = (elemBelow === null || elemBelow === void 0 ? void 0 : elemBelow.closest('[droppable=true]')) || (isDocumentDroppable ? document : null);
|
|
462
486
|
|
|
463
487
|
if (currentDroppable !== droppableBelow) {
|
|
464
488
|
if (currentDroppable) {
|
|
@@ -487,7 +511,7 @@ var DragndropPlugin = DragndropPlugin_1 = (_class = /*#__PURE__*/function () {
|
|
|
487
511
|
}
|
|
488
512
|
}
|
|
489
513
|
|
|
490
|
-
case
|
|
514
|
+
case 20:
|
|
491
515
|
case "end":
|
|
492
516
|
return _context.stop();
|
|
493
517
|
}
|
|
@@ -500,26 +524,37 @@ var DragndropPlugin = DragndropPlugin_1 = (_class = /*#__PURE__*/function () {
|
|
|
500
524
|
};
|
|
501
525
|
}();
|
|
502
526
|
|
|
503
|
-
//
|
|
504
|
-
|
|
505
|
-
|
|
527
|
+
// delay triggering dragstart event
|
|
528
|
+
var dragstartTriggered = false;
|
|
529
|
+
var dragstartTimeStamp = event.timeStamp;
|
|
530
|
+
var dragstartCanvasCoordinates = [event.canvasX, event.canvasY];
|
|
506
531
|
var currentDroppable = null;
|
|
507
532
|
canvas.addEventListener('pointermove', onMouseMove);
|
|
508
|
-
|
|
509
|
-
|
|
510
|
-
|
|
511
|
-
|
|
512
|
-
// @see https://
|
|
513
|
-
|
|
514
|
-
|
|
515
|
-
|
|
516
|
-
|
|
517
|
-
|
|
518
|
-
|
|
519
|
-
|
|
520
|
-
|
|
533
|
+
|
|
534
|
+
var stopDragging = function stopDragging() {
|
|
535
|
+
if (dragstartTriggered) {
|
|
536
|
+
// drop should fire before dragend
|
|
537
|
+
// @see https://javascript.tutorialink.com/is-there-a-defined-ordering-between-dragend-and-drop-events/
|
|
538
|
+
if (currentDroppable) {
|
|
539
|
+
// @see https://developer.mozilla.org/zh-CN/docs/Web/API/Document/drop_event
|
|
540
|
+
event.type = 'drop';
|
|
541
|
+
event.target = currentDroppable;
|
|
542
|
+
currentDroppable.dispatchEvent(event);
|
|
543
|
+
} // @see https://developer.mozilla.org/zh-CN/docs/Web/API/Document/dragend_event
|
|
544
|
+
|
|
545
|
+
|
|
546
|
+
event.type = 'dragend';
|
|
547
|
+
target.dispatchEvent(event);
|
|
548
|
+
dragstartTriggered = false;
|
|
549
|
+
}
|
|
550
|
+
|
|
521
551
|
canvas.removeEventListener('pointermove', onMouseMove);
|
|
522
|
-
}
|
|
552
|
+
};
|
|
553
|
+
|
|
554
|
+
target.addEventListener('pointerup', stopDragging, {
|
|
555
|
+
once: true
|
|
556
|
+
});
|
|
557
|
+
target.addEventListener('pointerupoutside', stopDragging, {
|
|
523
558
|
once: true
|
|
524
559
|
});
|
|
525
560
|
}
|
|
@@ -577,7 +612,10 @@ var Plugin = /*#__PURE__*/function () {
|
|
|
577
612
|
container.register(DragndropPluginOptions, {
|
|
578
613
|
useValue: _extends({
|
|
579
614
|
overlap: 'pointer',
|
|
580
|
-
isDocumentDraggable: false
|
|
615
|
+
isDocumentDraggable: false,
|
|
616
|
+
isDocumentDroppable: false,
|
|
617
|
+
dragstartDistanceThreshold: 0,
|
|
618
|
+
dragstartTimeThreshold: 0
|
|
581
619
|
}, this.options)
|
|
582
620
|
});
|
|
583
621
|
container.load(containerModule, true);
|
package/dist/index.umd.js
CHANGED
|
@@ -386,7 +386,7 @@
|
|
|
386
386
|
}
|
|
387
387
|
|
|
388
388
|
function _extends() {
|
|
389
|
-
_extends = Object.assign
|
|
389
|
+
_extends = Object.assign ? Object.assign.bind() : function (target) {
|
|
390
390
|
for (var i = 1; i < arguments.length; i++) {
|
|
391
391
|
var source = arguments[i];
|
|
392
392
|
|
|
@@ -399,7 +399,6 @@
|
|
|
399
399
|
|
|
400
400
|
return target;
|
|
401
401
|
};
|
|
402
|
-
|
|
403
402
|
return _extends.apply(this, arguments);
|
|
404
403
|
}
|
|
405
404
|
|
|
@@ -449,7 +448,10 @@
|
|
|
449
448
|
var canvas = document.defaultView;
|
|
450
449
|
var _this$dragndropPlugin = this.dragndropPluginOptions,
|
|
451
450
|
overlap = _this$dragndropPlugin.overlap,
|
|
452
|
-
isDocumentDraggable = _this$dragndropPlugin.isDocumentDraggable
|
|
451
|
+
isDocumentDraggable = _this$dragndropPlugin.isDocumentDraggable,
|
|
452
|
+
isDocumentDroppable = _this$dragndropPlugin.isDocumentDroppable,
|
|
453
|
+
dragstartDistanceThreshold = _this$dragndropPlugin.dragstartDistanceThreshold,
|
|
454
|
+
dragstartTimeThreshold = _this$dragndropPlugin.dragstartTimeThreshold;
|
|
453
455
|
|
|
454
456
|
var handlePointerdown = function handlePointerdown(event) {
|
|
455
457
|
var target = event.target;
|
|
@@ -459,17 +461,39 @@
|
|
|
459
461
|
// @ts-ignore
|
|
460
462
|
var onMouseMove = /*#__PURE__*/function () {
|
|
461
463
|
var _ref = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee(event) {
|
|
462
|
-
var pointerEventsOldValue, point, elemBelow, droppableBelow;
|
|
464
|
+
var timeElapsed, distanceMoved, pointerEventsOldValue, point, elemBelow, droppableBelow;
|
|
463
465
|
return _regeneratorRuntime().wrap(function _callee$(_context) {
|
|
464
466
|
while (1) {
|
|
465
467
|
switch (_context.prev = _context.next) {
|
|
466
468
|
case 0:
|
|
469
|
+
if (dragstartTriggered) {
|
|
470
|
+
_context.next = 8;
|
|
471
|
+
break;
|
|
472
|
+
}
|
|
473
|
+
|
|
474
|
+
timeElapsed = event.timeStamp - dragstartTimeStamp;
|
|
475
|
+
distanceMoved = Math.sqrt(Math.pow(event.canvasX - dragstartCanvasCoordinates[0], 2) + Math.pow(event.canvasY - dragstartCanvasCoordinates[1], 2)); // check thresholds
|
|
476
|
+
|
|
477
|
+
if (!(timeElapsed <= dragstartTimeThreshold || distanceMoved <= dragstartDistanceThreshold)) {
|
|
478
|
+
_context.next = 5;
|
|
479
|
+
break;
|
|
480
|
+
}
|
|
481
|
+
|
|
482
|
+
return _context.abrupt("return");
|
|
483
|
+
|
|
484
|
+
case 5:
|
|
485
|
+
// @see https://developer.mozilla.org/zh-CN/docs/Web/API/Document/dragstart_event
|
|
486
|
+
event.type = 'dragstart';
|
|
487
|
+
target.dispatchEvent(event);
|
|
488
|
+
dragstartTriggered = true;
|
|
489
|
+
|
|
490
|
+
case 8:
|
|
467
491
|
// @see https://developer.mozilla.org/zh-CN/docs/Web/API/Document/drag_event
|
|
468
492
|
event.type = 'drag';
|
|
469
493
|
target.dispatchEvent(event);
|
|
470
494
|
|
|
471
495
|
if (isDocument) {
|
|
472
|
-
_context.next =
|
|
496
|
+
_context.next = 20;
|
|
473
497
|
break;
|
|
474
498
|
}
|
|
475
499
|
|
|
@@ -477,13 +501,13 @@
|
|
|
477
501
|
pointerEventsOldValue = target.style.pointerEvents;
|
|
478
502
|
target.style.pointerEvents = 'none';
|
|
479
503
|
point = overlap === 'pointer' ? [event.canvasX, event.canvasY] : target.getBounds().center;
|
|
480
|
-
_context.next =
|
|
504
|
+
_context.next = 16;
|
|
481
505
|
return document.elementFromPoint(point[0], point[1]);
|
|
482
506
|
|
|
483
|
-
case
|
|
507
|
+
case 16:
|
|
484
508
|
elemBelow = _context.sent;
|
|
485
509
|
target.style.pointerEvents = pointerEventsOldValue;
|
|
486
|
-
droppableBelow = (elemBelow === null || elemBelow === void 0 ? void 0 : elemBelow.closest('[droppable=true]')) || null;
|
|
510
|
+
droppableBelow = (elemBelow === null || elemBelow === void 0 ? void 0 : elemBelow.closest('[droppable=true]')) || (isDocumentDroppable ? document : null);
|
|
487
511
|
|
|
488
512
|
if (currentDroppable !== droppableBelow) {
|
|
489
513
|
if (currentDroppable) {
|
|
@@ -512,7 +536,7 @@
|
|
|
512
536
|
}
|
|
513
537
|
}
|
|
514
538
|
|
|
515
|
-
case
|
|
539
|
+
case 20:
|
|
516
540
|
case "end":
|
|
517
541
|
return _context.stop();
|
|
518
542
|
}
|
|
@@ -525,26 +549,37 @@
|
|
|
525
549
|
};
|
|
526
550
|
}();
|
|
527
551
|
|
|
528
|
-
//
|
|
529
|
-
|
|
530
|
-
|
|
552
|
+
// delay triggering dragstart event
|
|
553
|
+
var dragstartTriggered = false;
|
|
554
|
+
var dragstartTimeStamp = event.timeStamp;
|
|
555
|
+
var dragstartCanvasCoordinates = [event.canvasX, event.canvasY];
|
|
531
556
|
var currentDroppable = null;
|
|
532
557
|
canvas.addEventListener('pointermove', onMouseMove);
|
|
533
|
-
|
|
534
|
-
|
|
535
|
-
|
|
536
|
-
|
|
537
|
-
// @see https://
|
|
538
|
-
|
|
539
|
-
|
|
540
|
-
|
|
541
|
-
|
|
542
|
-
|
|
543
|
-
|
|
544
|
-
|
|
545
|
-
|
|
558
|
+
|
|
559
|
+
var stopDragging = function stopDragging() {
|
|
560
|
+
if (dragstartTriggered) {
|
|
561
|
+
// drop should fire before dragend
|
|
562
|
+
// @see https://javascript.tutorialink.com/is-there-a-defined-ordering-between-dragend-and-drop-events/
|
|
563
|
+
if (currentDroppable) {
|
|
564
|
+
// @see https://developer.mozilla.org/zh-CN/docs/Web/API/Document/drop_event
|
|
565
|
+
event.type = 'drop';
|
|
566
|
+
event.target = currentDroppable;
|
|
567
|
+
currentDroppable.dispatchEvent(event);
|
|
568
|
+
} // @see https://developer.mozilla.org/zh-CN/docs/Web/API/Document/dragend_event
|
|
569
|
+
|
|
570
|
+
|
|
571
|
+
event.type = 'dragend';
|
|
572
|
+
target.dispatchEvent(event);
|
|
573
|
+
dragstartTriggered = false;
|
|
574
|
+
}
|
|
575
|
+
|
|
546
576
|
canvas.removeEventListener('pointermove', onMouseMove);
|
|
547
|
-
}
|
|
577
|
+
};
|
|
578
|
+
|
|
579
|
+
target.addEventListener('pointerup', stopDragging, {
|
|
580
|
+
once: true
|
|
581
|
+
});
|
|
582
|
+
target.addEventListener('pointerupoutside', stopDragging, {
|
|
548
583
|
once: true
|
|
549
584
|
});
|
|
550
585
|
}
|
|
@@ -602,7 +637,10 @@
|
|
|
602
637
|
container.register(DragndropPluginOptions, {
|
|
603
638
|
useValue: _extends({
|
|
604
639
|
overlap: 'pointer',
|
|
605
|
-
isDocumentDraggable: false
|
|
640
|
+
isDocumentDraggable: false,
|
|
641
|
+
isDocumentDroppable: false,
|
|
642
|
+
dragstartDistanceThreshold: 0,
|
|
643
|
+
dragstartTimeThreshold: 0
|
|
606
644
|
}, this.options)
|
|
607
645
|
});
|
|
608
646
|
container.load(containerModule, true);
|
package/dist/index.umd.min.js
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
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
|
-
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=function(t){var i=t.target,u=i===e;if(u&&c||i.getAttribute&&i.getAttribute("draggable")){var s=function(){var t=o(r().mark((function t(n){var o,c,s,p;return r().wrap((function(t){for(;;)switch(t.prev=t.next){case 0:if(n.type="drag",i.dispatchEvent(n),u){t.next=12;break}return o=i.style.pointerEvents,i.style.pointerEvents="none",c="pointer"===a?[n.canvasX,n.canvasY]:i.getBounds().center,t.next=8,e.elementFromPoint(c[0],c[1]);case 8:s=t.sent,i.style.pointerEvents=o,p=(null==s?void 0:s.closest("[droppable=true]"))||null,f!==p&&(f&&(n.type="dragleave",n.target=f,f.dispatchEvent(n)),p&&(n.type="dragenter",n.target=p,p.dispatchEvent(n)),(f=p)&&(n.type="dragover",n.target=f,f.dispatchEvent(n)));case 12:case"end":return t.stop()}}),t)})));return function(e){return t.apply(this,arguments)}}();t.type="dragstart",i.dispatchEvent(t);var f=null;n.addEventListener("pointermove",s),i.addEventListener("pointerup",(function(){f&&(t.type="drop",t.target=f,f.dispatchEvent(t)),t.type="dragend",i.dispatchEvent(t),n.removeEventListener("pointermove",s)}),{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",u);case 1:case"end":return t.stop()}}),t)})))),t.hooks.destroy.tap(s.tag,(function(){n.removeEventListener("pointerdown",u)}))},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},this.options)}),t.load(l,!0)},e.destroy=function(t){t.remove(f),t.unload(l)},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 g=Object.getPrototypeOf,y=g&&g(g(j([])));y&&y!==e&&n.call(y,i)&&(v=y);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?Object.assign.bind():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,y,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",y="pointer"===a?[n.canvasX,n.canvasY]:i.getBounds().center,t.next=16,e.elementFromPoint(y[0],y[1]);case 16:m=t.sent,i.style.pointerEvents=l,w=(null==m?void 0:m.closest("[droppable=true]"))||(u?e:null),g!==w&&(g&&(n.type="dragleave",n.target=g,g.dispatchEvent(n)),w&&(n.type="dragenter",n.target=w,w.dispatchEvent(n)),(g=w)&&(n.type="dragover",n.target=g,g.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],g=null;n.addEventListener("pointermove",l);var y=function(){h&&(g&&(t.type="drop",t.target=g,g.dispatchEvent(t)),t.type="dragend",i.dispatchEvent(t),h=!1),n.removeEventListener("pointermove",l)};i.addEventListener("pointerup",y,{once:!0}),i.addEventListener("pointerupoutside",y,{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
|
@@ -13,5 +13,18 @@ export interface DragndropPluginOptions {
|
|
|
13
13
|
* we need to add an extra option.
|
|
14
14
|
*/
|
|
15
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;
|
|
16
29
|
}
|
|
17
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,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;
|
|
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.2",
|
|
4
4
|
"description": "A G plugin for Drag n Drop implemented with PointerEvents",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"antv",
|
|
@@ -38,5 +38,5 @@
|
|
|
38
38
|
"publishConfig": {
|
|
39
39
|
"access": "public"
|
|
40
40
|
},
|
|
41
|
-
"gitHead": "
|
|
41
|
+
"gitHead": "f0d3036ed1439859167f135b8a61c84a415582df"
|
|
42
42
|
}
|