@antv/g-plugin-dragndrop 1.2.0 → 1.4.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.
@@ -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;CAkIzC"}
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;AAIjB,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;CAuIzC"}
package/dist/index.esm.js CHANGED
@@ -1,5 +1,6 @@
1
1
  import { Syringe, inject, SceneGraphService, RenderingContext, singleton, RenderingPluginContribution, Module } from '@antv/g';
2
2
  import { __decorate, __metadata } from 'tslib';
3
+ import { distanceSquareRoot } from '@antv/util';
3
4
 
4
5
  function _regeneratorRuntime() {
5
6
  /*! regenerator-runtime -- Copyright (c) 2014-present, Facebook, Inc. -- license (MIT): https://github.com/facebook/regenerator/blob/main/LICENSE */
@@ -430,7 +431,7 @@ var DragndropPlugin = DragndropPlugin_1 = (_class = /*#__PURE__*/function () {
430
431
 
431
432
  if (isDocument && isDocumentDraggable || target.getAttribute && target.getAttribute('draggable')) {
432
433
  // @ts-ignore
433
- var onMouseMove = /*#__PURE__*/function () {
434
+ var handlePointermove = /*#__PURE__*/function () {
434
435
  var _ref = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee(event) {
435
436
  var timeElapsed, distanceMoved, pointerEventsOldValue, point, elemBelow, droppableBelow;
436
437
  return _regeneratorRuntime().wrap(function _callee$(_context) {
@@ -443,7 +444,7 @@ var DragndropPlugin = DragndropPlugin_1 = (_class = /*#__PURE__*/function () {
443
444
  }
444
445
 
445
446
  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
+ distanceMoved = distanceSquareRoot([event.clientX, event.clientY], dragstartClientCoordinates); // check thresholds
447
448
 
448
449
  if (!(timeElapsed <= dragstartTimeThreshold || distanceMoved <= dragstartDistanceThreshold)) {
449
450
  _context.next = 5;
@@ -460,11 +461,16 @@ var DragndropPlugin = DragndropPlugin_1 = (_class = /*#__PURE__*/function () {
460
461
 
461
462
  case 8:
462
463
  // @see https://developer.mozilla.org/zh-CN/docs/Web/API/Document/drag_event
463
- event.type = 'drag';
464
+ event.type = 'drag'; // @ts-ignore
465
+
466
+ event.dx = event.clientX - lastDragClientCoordinates[0]; // @ts-ignore
467
+
468
+ event.dy = event.clientY - lastDragClientCoordinates[1];
464
469
  target.dispatchEvent(event);
470
+ lastDragClientCoordinates = [event.clientX, event.clientY];
465
471
 
466
472
  if (isDocument) {
467
- _context.next = 20;
473
+ _context.next = 23;
468
474
  break;
469
475
  }
470
476
 
@@ -472,10 +478,10 @@ var DragndropPlugin = DragndropPlugin_1 = (_class = /*#__PURE__*/function () {
472
478
  pointerEventsOldValue = target.style.pointerEvents;
473
479
  target.style.pointerEvents = 'none';
474
480
  point = overlap === 'pointer' ? [event.canvasX, event.canvasY] : target.getBounds().center;
475
- _context.next = 16;
481
+ _context.next = 19;
476
482
  return document.elementFromPoint(point[0], point[1]);
477
483
 
478
- case 16:
484
+ case 19:
479
485
  elemBelow = _context.sent;
480
486
  target.style.pointerEvents = pointerEventsOldValue;
481
487
  droppableBelow = (elemBelow === null || elemBelow === void 0 ? void 0 : elemBelow.closest('[droppable=true]')) || (isDocumentDroppable ? document : null);
@@ -507,7 +513,7 @@ var DragndropPlugin = DragndropPlugin_1 = (_class = /*#__PURE__*/function () {
507
513
  }
508
514
  }
509
515
 
510
- case 20:
516
+ case 23:
511
517
  case "end":
512
518
  return _context.stop();
513
519
  }
@@ -515,7 +521,7 @@ var DragndropPlugin = DragndropPlugin_1 = (_class = /*#__PURE__*/function () {
515
521
  }, _callee);
516
522
  }));
517
523
 
518
- return function onMouseMove(_x) {
524
+ return function handlePointermove(_x) {
519
525
  return _ref.apply(this, arguments);
520
526
  };
521
527
  }();
@@ -523,9 +529,10 @@ var DragndropPlugin = DragndropPlugin_1 = (_class = /*#__PURE__*/function () {
523
529
  // delay triggering dragstart event
524
530
  var dragstartTriggered = false;
525
531
  var dragstartTimeStamp = event.timeStamp;
526
- var dragstartCanvasCoordinates = [event.canvasX, event.canvasY];
532
+ var dragstartClientCoordinates = [event.clientX, event.clientY];
527
533
  var currentDroppable = null;
528
- canvas.addEventListener('pointermove', onMouseMove);
534
+ var lastDragClientCoordinates = [event.clientX, event.clientY];
535
+ canvas.addEventListener('pointermove', handlePointermove);
529
536
 
530
537
  var stopDragging = function stopDragging() {
531
538
  if (dragstartTriggered) {
@@ -544,7 +551,7 @@ var DragndropPlugin = DragndropPlugin_1 = (_class = /*#__PURE__*/function () {
544
551
  dragstartTriggered = false;
545
552
  }
546
553
 
547
- canvas.removeEventListener('pointermove', onMouseMove);
554
+ canvas.removeEventListener('pointermove', handlePointermove);
548
555
  };
549
556
 
550
557
  target.addEventListener('pointerup', stopDragging, {
package/dist/index.js CHANGED
@@ -4,6 +4,7 @@ Object.defineProperty(exports, '__esModule', { value: true });
4
4
 
5
5
  var g = require('@antv/g');
6
6
  var tslib = require('tslib');
7
+ var util = require('@antv/util');
7
8
 
8
9
  function _regeneratorRuntime() {
9
10
  /*! regenerator-runtime -- Copyright (c) 2014-present, Facebook, Inc. -- license (MIT): https://github.com/facebook/regenerator/blob/main/LICENSE */
@@ -434,7 +435,7 @@ var DragndropPlugin = DragndropPlugin_1 = (_class = /*#__PURE__*/function () {
434
435
 
435
436
  if (isDocument && isDocumentDraggable || target.getAttribute && target.getAttribute('draggable')) {
436
437
  // @ts-ignore
437
- var onMouseMove = /*#__PURE__*/function () {
438
+ var handlePointermove = /*#__PURE__*/function () {
438
439
  var _ref = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee(event) {
439
440
  var timeElapsed, distanceMoved, pointerEventsOldValue, point, elemBelow, droppableBelow;
440
441
  return _regeneratorRuntime().wrap(function _callee$(_context) {
@@ -447,7 +448,7 @@ var DragndropPlugin = DragndropPlugin_1 = (_class = /*#__PURE__*/function () {
447
448
  }
448
449
 
449
450
  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
+ distanceMoved = util.distanceSquareRoot([event.clientX, event.clientY], dragstartClientCoordinates); // check thresholds
451
452
 
452
453
  if (!(timeElapsed <= dragstartTimeThreshold || distanceMoved <= dragstartDistanceThreshold)) {
453
454
  _context.next = 5;
@@ -464,11 +465,16 @@ var DragndropPlugin = DragndropPlugin_1 = (_class = /*#__PURE__*/function () {
464
465
 
465
466
  case 8:
466
467
  // @see https://developer.mozilla.org/zh-CN/docs/Web/API/Document/drag_event
467
- event.type = 'drag';
468
+ event.type = 'drag'; // @ts-ignore
469
+
470
+ event.dx = event.clientX - lastDragClientCoordinates[0]; // @ts-ignore
471
+
472
+ event.dy = event.clientY - lastDragClientCoordinates[1];
468
473
  target.dispatchEvent(event);
474
+ lastDragClientCoordinates = [event.clientX, event.clientY];
469
475
 
470
476
  if (isDocument) {
471
- _context.next = 20;
477
+ _context.next = 23;
472
478
  break;
473
479
  }
474
480
 
@@ -476,10 +482,10 @@ var DragndropPlugin = DragndropPlugin_1 = (_class = /*#__PURE__*/function () {
476
482
  pointerEventsOldValue = target.style.pointerEvents;
477
483
  target.style.pointerEvents = 'none';
478
484
  point = overlap === 'pointer' ? [event.canvasX, event.canvasY] : target.getBounds().center;
479
- _context.next = 16;
485
+ _context.next = 19;
480
486
  return document.elementFromPoint(point[0], point[1]);
481
487
 
482
- case 16:
488
+ case 19:
483
489
  elemBelow = _context.sent;
484
490
  target.style.pointerEvents = pointerEventsOldValue;
485
491
  droppableBelow = (elemBelow === null || elemBelow === void 0 ? void 0 : elemBelow.closest('[droppable=true]')) || (isDocumentDroppable ? document : null);
@@ -511,7 +517,7 @@ var DragndropPlugin = DragndropPlugin_1 = (_class = /*#__PURE__*/function () {
511
517
  }
512
518
  }
513
519
 
514
- case 20:
520
+ case 23:
515
521
  case "end":
516
522
  return _context.stop();
517
523
  }
@@ -519,7 +525,7 @@ var DragndropPlugin = DragndropPlugin_1 = (_class = /*#__PURE__*/function () {
519
525
  }, _callee);
520
526
  }));
521
527
 
522
- return function onMouseMove(_x) {
528
+ return function handlePointermove(_x) {
523
529
  return _ref.apply(this, arguments);
524
530
  };
525
531
  }();
@@ -527,9 +533,10 @@ var DragndropPlugin = DragndropPlugin_1 = (_class = /*#__PURE__*/function () {
527
533
  // delay triggering dragstart event
528
534
  var dragstartTriggered = false;
529
535
  var dragstartTimeStamp = event.timeStamp;
530
- var dragstartCanvasCoordinates = [event.canvasX, event.canvasY];
536
+ var dragstartClientCoordinates = [event.clientX, event.clientY];
531
537
  var currentDroppable = null;
532
- canvas.addEventListener('pointermove', onMouseMove);
538
+ var lastDragClientCoordinates = [event.clientX, event.clientY];
539
+ canvas.addEventListener('pointermove', handlePointermove);
533
540
 
534
541
  var stopDragging = function stopDragging() {
535
542
  if (dragstartTriggered) {
@@ -548,7 +555,7 @@ var DragndropPlugin = DragndropPlugin_1 = (_class = /*#__PURE__*/function () {
548
555
  dragstartTriggered = false;
549
556
  }
550
557
 
551
- canvas.removeEventListener('pointermove', onMouseMove);
558
+ canvas.removeEventListener('pointermove', handlePointermove);
552
559
  };
553
560
 
554
561
  target.addEventListener('pointerup', stopDragging, {
package/dist/index.umd.js CHANGED
@@ -428,6 +428,10 @@
428
428
  if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(metadataKey, metadataValue);
429
429
  }
430
430
 
431
+ function distanceSquareRoot(a, b) {
432
+ return Math.sqrt((a[0] - b[0]) * (a[0] - b[0]) + (a[1] - b[1]) * (a[1] - b[1]));
433
+ }
434
+
431
435
  var DragndropPluginOptions = g.Syringe.defineToken('DragndropPluginOptions');
432
436
 
433
437
  var _class;
@@ -459,7 +463,7 @@
459
463
 
460
464
  if (isDocument && isDocumentDraggable || target.getAttribute && target.getAttribute('draggable')) {
461
465
  // @ts-ignore
462
- var onMouseMove = /*#__PURE__*/function () {
466
+ var handlePointermove = /*#__PURE__*/function () {
463
467
  var _ref = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee(event) {
464
468
  var timeElapsed, distanceMoved, pointerEventsOldValue, point, elemBelow, droppableBelow;
465
469
  return _regeneratorRuntime().wrap(function _callee$(_context) {
@@ -472,7 +476,7 @@
472
476
  }
473
477
 
474
478
  timeElapsed = event.timeStamp - dragstartTimeStamp;
475
- distanceMoved = Math.sqrt(Math.pow(event.canvasX - dragstartCanvasCoordinates[0], 2) + Math.pow(event.canvasY - dragstartCanvasCoordinates[1], 2)); // check thresholds
479
+ distanceMoved = distanceSquareRoot([event.clientX, event.clientY], dragstartClientCoordinates); // check thresholds
476
480
 
477
481
  if (!(timeElapsed <= dragstartTimeThreshold || distanceMoved <= dragstartDistanceThreshold)) {
478
482
  _context.next = 5;
@@ -489,11 +493,16 @@
489
493
 
490
494
  case 8:
491
495
  // @see https://developer.mozilla.org/zh-CN/docs/Web/API/Document/drag_event
492
- event.type = 'drag';
496
+ event.type = 'drag'; // @ts-ignore
497
+
498
+ event.dx = event.clientX - lastDragClientCoordinates[0]; // @ts-ignore
499
+
500
+ event.dy = event.clientY - lastDragClientCoordinates[1];
493
501
  target.dispatchEvent(event);
502
+ lastDragClientCoordinates = [event.clientX, event.clientY];
494
503
 
495
504
  if (isDocument) {
496
- _context.next = 20;
505
+ _context.next = 23;
497
506
  break;
498
507
  }
499
508
 
@@ -501,10 +510,10 @@
501
510
  pointerEventsOldValue = target.style.pointerEvents;
502
511
  target.style.pointerEvents = 'none';
503
512
  point = overlap === 'pointer' ? [event.canvasX, event.canvasY] : target.getBounds().center;
504
- _context.next = 16;
513
+ _context.next = 19;
505
514
  return document.elementFromPoint(point[0], point[1]);
506
515
 
507
- case 16:
516
+ case 19:
508
517
  elemBelow = _context.sent;
509
518
  target.style.pointerEvents = pointerEventsOldValue;
510
519
  droppableBelow = (elemBelow === null || elemBelow === void 0 ? void 0 : elemBelow.closest('[droppable=true]')) || (isDocumentDroppable ? document : null);
@@ -536,7 +545,7 @@
536
545
  }
537
546
  }
538
547
 
539
- case 20:
548
+ case 23:
540
549
  case "end":
541
550
  return _context.stop();
542
551
  }
@@ -544,7 +553,7 @@
544
553
  }, _callee);
545
554
  }));
546
555
 
547
- return function onMouseMove(_x) {
556
+ return function handlePointermove(_x) {
548
557
  return _ref.apply(this, arguments);
549
558
  };
550
559
  }();
@@ -552,9 +561,10 @@
552
561
  // delay triggering dragstart event
553
562
  var dragstartTriggered = false;
554
563
  var dragstartTimeStamp = event.timeStamp;
555
- var dragstartCanvasCoordinates = [event.canvasX, event.canvasY];
564
+ var dragstartClientCoordinates = [event.clientX, event.clientY];
556
565
  var currentDroppable = null;
557
- canvas.addEventListener('pointermove', onMouseMove);
566
+ var lastDragClientCoordinates = [event.clientX, event.clientY];
567
+ canvas.addEventListener('pointermove', handlePointermove);
558
568
 
559
569
  var stopDragging = function stopDragging() {
560
570
  if (dragstartTriggered) {
@@ -573,7 +583,7 @@
573
583
  dragstartTriggered = false;
574
584
  }
575
585
 
576
- canvas.removeEventListener('pointermove', onMouseMove);
586
+ canvas.removeEventListener('pointermove', handlePointermove);
577
587
  };
578
588
 
579
589
  target.addEventListener('pointerup', stopDragging, {
@@ -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 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})}));
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 p?e:p).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===f)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=l(t,e,r);if("normal"===u.type){if(n=r.done?"completed":"suspendedYield",u.arg===f)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 l(t,e,r){try{return{type:"normal",arg:t.call(e,r)}}catch(t){return{type:"throw",arg:t}}}t.wrap=s;var f={};function p(){}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=p.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=l(t[o],t,i);if("throw"!==u.type){var s=u.arg,f=s.value;return f&&"object"==typeof f&&n.call(f,"__await")?e.resolve(f.__await).then((function(t){r("next",t,a,c)}),(function(t){r("throw",t,a,c)})):e.resolve(f).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 f;e.method="throw",e.arg=new TypeError("The iterator does not provide a 'throw' method")}return f}var n=l(r,t.iterator,e.arg);if("throw"===n.type)return e.method="throw",e.arg=n.arg,e.delegate=null,f;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,f):o:(e.method="throw",e.arg=new TypeError("iterator result is not an object"),e.delegate=null,f)}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,f):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),f},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),f}},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),f}},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,l=e.Syringe.defineToken("DragndropPluginOptions"),f=(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,l=i.dragstartDistanceThreshold,f=i.dragstartTimeThreshold,p=function(t){var i=t.target,s=i===e;if(s&&c||i.getAttribute&&i.getAttribute("draggable")){var p=function(){var t=o(r().mark((function t(n){var o,c,p,m,w,b;return r().wrap((function(t){for(;;)switch(t.prev=t.next){case 0:if(h){t.next=8;break}if(o=n.timeStamp-d,r=[n.clientX,n.clientY],x=v,c=Math.sqrt((r[0]-x[0])*(r[0]-x[0])+(r[1]-x[1])*(r[1]-x[1])),o>f&&c>l){t.next=5;break}return t.abrupt("return");case 5:n.type="dragstart",i.dispatchEvent(n),h=!0;case 8:if(n.type="drag",n.dx=n.clientX-g[0],n.dy=n.clientY-g[1],i.dispatchEvent(n),g=[n.clientX,n.clientY],s){t.next=23;break}return p=i.style.pointerEvents,i.style.pointerEvents="none",m="pointer"===a?[n.canvasX,n.canvasY]:i.getBounds().center,t.next=19,e.elementFromPoint(m[0],m[1]);case 19:w=t.sent,i.style.pointerEvents=p,b=(null==w?void 0:w.closest("[droppable=true]"))||(u?e:null),y!==b&&(y&&(n.type="dragleave",n.target=y,y.dispatchEvent(n)),b&&(n.type="dragenter",n.target=b,b.dispatchEvent(n)),(y=b)&&(n.type="dragover",n.target=y,y.dispatchEvent(n)));case 23:case"end":return t.stop()}var r,x}),t)})));return function(e){return t.apply(this,arguments)}}(),h=!1,d=t.timeStamp,v=[t.clientX,t.clientY],y=null,g=[t.clientX,t.clientY];n.addEventListener("pointermove",p);var m=function(){h&&(y&&(t.type="drop",t.target=y,y.dispatchEvent(t)),t.type="dragend",i.dispatchEvent(t),h=!1),n.removeEventListener("pointermove",p)};i.addEventListener("pointerup",m,{once:!0}),i.addEventListener("pointerupoutside",m,{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",p);case 1:case"end":return t.stop()}}),t)})))),t.hooks.destroy.tap(s.tag,(function(){n.removeEventListener("pointerdown",p)}))},t}(),u.tag="Dragndrop",s=u);a([e.inject(e.SceneGraphService),c("design:type",Object)],f.prototype,"sceneGraphService",void 0),a([e.inject(e.RenderingContext),c("design:type",Object)],f.prototype,"renderingContext",void 0),a([e.inject(l),c("design:type",Object)],f.prototype,"dragndropPluginOptions",void 0),f=s=a([e.singleton({contrib:e.RenderingPluginContribution})],f);var p=e.Module((function(t){t(f)}));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(l,{useValue:i({overlap:"pointer",isDocumentDraggable:!1,isDocumentDroppable:!1,dragstartDistanceThreshold:0,dragstartTimeThreshold:0},this.options)}),t.load(p,!0)},e.destroy=function(t){t.remove(l),t.unload(p)},t}(),Object.defineProperty(t,"__esModule",{value:!0})}));
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@antv/g-plugin-dragndrop",
3
- "version": "1.2.0",
3
+ "version": "1.4.0",
4
4
  "description": "A G plugin for Drag n Drop implemented with PointerEvents",
5
5
  "keywords": [
6
6
  "antv",
@@ -27,6 +27,7 @@
27
27
  "README.md"
28
28
  ],
29
29
  "dependencies": {
30
+ "@antv/util": "^3.2.0",
30
31
  "tslib": "^2.3.1"
31
32
  },
32
33
  "devDependencies": {
@@ -38,5 +39,5 @@
38
39
  "publishConfig": {
39
40
  "access": "public"
40
41
  },
41
- "gitHead": "d0d7ed366353cc551e34cd8163a379cd1a8789b6"
42
+ "gitHead": "464ea5f09af7cd041434233f113feeec3912357e"
42
43
  }