@antv/g-plugin-dragndrop 1.5.3 → 1.6.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -5,7 +5,6 @@ export declare class DragndropPlugin implements RenderingPlugin {
5
5
  protected sceneGraphService: SceneGraphService;
6
6
  private renderingContext;
7
7
  private dragndropPluginOptions;
8
- private findClosestDraggable;
9
8
  apply(renderingService: RenderingService): void;
10
9
  }
11
10
  //# sourceMappingURL=DragndropPlugin.d.ts.map
@@ -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,EAKL,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,OAAO,CAAC,oBAAoB;IAa5B,KAAK,CAAC,gBAAgB,EAAE,gBAAgB;CA+IzC"}
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;CAgJzC"}
package/dist/index.esm.js CHANGED
@@ -1,4 +1,4 @@
1
- import { Syringe, inject, SceneGraphService, RenderingContext, singleton, RenderingPluginContribution, Element, Module, AbstractRendererPlugin } from '@antv/g';
1
+ import { Syringe, inject, SceneGraphService, RenderingContext, singleton, RenderingPluginContribution, Module, AbstractRendererPlugin } from '@antv/g';
2
2
  import { __decorate, __metadata } from 'tslib';
3
3
  import { distanceSquareRoot } from '@antv/util';
4
4
 
@@ -415,7 +415,7 @@ function _setPrototypeOf(o, p) {
415
415
  return _setPrototypeOf(o, p);
416
416
  }
417
417
 
418
- var DragndropPluginOptions = Syringe.defineToken('DragndropPluginOptions');
418
+ var DragndropPluginOptions = Syringe.defineToken('');
419
419
 
420
420
  var _class;
421
421
 
@@ -429,23 +429,7 @@ var DragndropPlugin = DragndropPlugin_1 = (_class = /*#__PURE__*/function () {
429
429
 
430
430
  var _proto = DragndropPlugin.prototype;
431
431
 
432
- _proto.findClosestDraggable = function findClosestDraggable(event) {
433
- var composedPath = event.composedPath();
434
-
435
- for (var i = 0; i < composedPath.length; i++) {
436
- var target = composedPath[i];
437
-
438
- if (Element.isElement(target) && target.getAttribute('draggable')) {
439
- return target;
440
- }
441
- }
442
-
443
- return null;
444
- };
445
-
446
432
  _proto.apply = function apply(renderingService) {
447
- var _this = this;
448
-
449
433
  var document = this.renderingContext.root.ownerDocument; // TODO: should we add an option like `draggable` to Canvas
450
434
 
451
435
  var canvas = document.defaultView;
@@ -459,16 +443,14 @@ var DragndropPlugin = DragndropPlugin_1 = (_class = /*#__PURE__*/function () {
459
443
  var handlePointerdown = function handlePointerdown(event) {
460
444
  var target = event.target;
461
445
  var isDocument = target === document;
462
-
463
- var draggableEventTarget = _this.findClosestDraggable(event); // `draggable` may be set on ancestor nodes:
446
+ var draggableEventTarget = isDocument && isDocumentDraggable ? document : target.closest && target.closest('[draggable=true]'); // `draggable` may be set on ancestor nodes:
464
447
  // @see https://github.com/antvis/G/issues/1088
465
448
 
466
-
467
- if (isDocument && isDocumentDraggable || !!draggableEventTarget) {
449
+ if (!!draggableEventTarget) {
468
450
  // @ts-ignore
469
451
  var handlePointermove = /*#__PURE__*/function () {
470
452
  var _ref = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee(event) {
471
- var timeElapsed, distanceMoved, pointerEventsOldValue, point, elemBelow, droppableBelow;
453
+ var timeElapsed, distanceMoved, point, elementsBelow, elementBelow, droppableBelow;
472
454
  return _regeneratorRuntime().wrap(function _callee$(_context) {
473
455
  while (1) {
474
456
  switch (_context.prev = _context.next) {
@@ -505,21 +487,19 @@ var DragndropPlugin = DragndropPlugin_1 = (_class = /*#__PURE__*/function () {
505
487
  lastDragClientCoordinates = [event.clientX, event.clientY];
506
488
 
507
489
  if (isDocument) {
508
- _context.next = 23;
490
+ _context.next = 21;
509
491
  break;
510
492
  }
511
493
 
512
- // prevent from picking the dragging element
513
- pointerEventsOldValue = target.style.pointerEvents;
514
- target.style.pointerEvents = 'none';
515
494
  point = overlap === 'pointer' ? [event.canvasX, event.canvasY] : target.getBounds().center;
516
- _context.next = 19;
517
- return document.elementFromPoint(point[0], point[1]);
495
+ _context.next = 17;
496
+ return document.elementsFromPoint(point[0], point[1]);
518
497
 
519
- case 19:
520
- elemBelow = _context.sent;
521
- target.style.pointerEvents = pointerEventsOldValue;
522
- droppableBelow = (elemBelow === null || elemBelow === void 0 ? void 0 : elemBelow.closest('[droppable=true]')) || (isDocumentDroppable ? document : null);
498
+ case 17:
499
+ elementsBelow = _context.sent;
500
+ // prevent from picking the dragging element
501
+ elementBelow = elementsBelow[elementsBelow.indexOf(target) + 1];
502
+ droppableBelow = (elementBelow === null || elementBelow === void 0 ? void 0 : elementBelow.closest('[droppable=true]')) || (isDocumentDroppable ? document : null);
523
503
 
524
504
  if (currentDroppable !== droppableBelow) {
525
505
  if (currentDroppable) {
@@ -548,7 +528,7 @@ var DragndropPlugin = DragndropPlugin_1 = (_class = /*#__PURE__*/function () {
548
528
  }
549
529
  }
550
530
 
551
- case 23:
531
+ case 21:
552
532
  case "end":
553
533
  return _context.stop();
554
534
  }
package/dist/index.js CHANGED
@@ -419,7 +419,7 @@ function _setPrototypeOf(o, p) {
419
419
  return _setPrototypeOf(o, p);
420
420
  }
421
421
 
422
- var DragndropPluginOptions = g.Syringe.defineToken('DragndropPluginOptions');
422
+ var DragndropPluginOptions = g.Syringe.defineToken('');
423
423
 
424
424
  var _class;
425
425
 
@@ -433,23 +433,7 @@ var DragndropPlugin = DragndropPlugin_1 = (_class = /*#__PURE__*/function () {
433
433
 
434
434
  var _proto = DragndropPlugin.prototype;
435
435
 
436
- _proto.findClosestDraggable = function findClosestDraggable(event) {
437
- var composedPath = event.composedPath();
438
-
439
- for (var i = 0; i < composedPath.length; i++) {
440
- var target = composedPath[i];
441
-
442
- if (g.Element.isElement(target) && target.getAttribute('draggable')) {
443
- return target;
444
- }
445
- }
446
-
447
- return null;
448
- };
449
-
450
436
  _proto.apply = function apply(renderingService) {
451
- var _this = this;
452
-
453
437
  var document = this.renderingContext.root.ownerDocument; // TODO: should we add an option like `draggable` to Canvas
454
438
 
455
439
  var canvas = document.defaultView;
@@ -463,16 +447,14 @@ var DragndropPlugin = DragndropPlugin_1 = (_class = /*#__PURE__*/function () {
463
447
  var handlePointerdown = function handlePointerdown(event) {
464
448
  var target = event.target;
465
449
  var isDocument = target === document;
466
-
467
- var draggableEventTarget = _this.findClosestDraggable(event); // `draggable` may be set on ancestor nodes:
450
+ var draggableEventTarget = isDocument && isDocumentDraggable ? document : target.closest && target.closest('[draggable=true]'); // `draggable` may be set on ancestor nodes:
468
451
  // @see https://github.com/antvis/G/issues/1088
469
452
 
470
-
471
- if (isDocument && isDocumentDraggable || !!draggableEventTarget) {
453
+ if (!!draggableEventTarget) {
472
454
  // @ts-ignore
473
455
  var handlePointermove = /*#__PURE__*/function () {
474
456
  var _ref = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee(event) {
475
- var timeElapsed, distanceMoved, pointerEventsOldValue, point, elemBelow, droppableBelow;
457
+ var timeElapsed, distanceMoved, point, elementsBelow, elementBelow, droppableBelow;
476
458
  return _regeneratorRuntime().wrap(function _callee$(_context) {
477
459
  while (1) {
478
460
  switch (_context.prev = _context.next) {
@@ -509,21 +491,19 @@ var DragndropPlugin = DragndropPlugin_1 = (_class = /*#__PURE__*/function () {
509
491
  lastDragClientCoordinates = [event.clientX, event.clientY];
510
492
 
511
493
  if (isDocument) {
512
- _context.next = 23;
494
+ _context.next = 21;
513
495
  break;
514
496
  }
515
497
 
516
- // prevent from picking the dragging element
517
- pointerEventsOldValue = target.style.pointerEvents;
518
- target.style.pointerEvents = 'none';
519
498
  point = overlap === 'pointer' ? [event.canvasX, event.canvasY] : target.getBounds().center;
520
- _context.next = 19;
521
- return document.elementFromPoint(point[0], point[1]);
499
+ _context.next = 17;
500
+ return document.elementsFromPoint(point[0], point[1]);
522
501
 
523
- case 19:
524
- elemBelow = _context.sent;
525
- target.style.pointerEvents = pointerEventsOldValue;
526
- droppableBelow = (elemBelow === null || elemBelow === void 0 ? void 0 : elemBelow.closest('[droppable=true]')) || (isDocumentDroppable ? document : null);
502
+ case 17:
503
+ elementsBelow = _context.sent;
504
+ // prevent from picking the dragging element
505
+ elementBelow = elementsBelow[elementsBelow.indexOf(target) + 1];
506
+ droppableBelow = (elementBelow === null || elementBelow === void 0 ? void 0 : elementBelow.closest('[droppable=true]')) || (isDocumentDroppable ? document : null);
527
507
 
528
508
  if (currentDroppable !== droppableBelow) {
529
509
  if (currentDroppable) {
@@ -552,7 +532,7 @@ var DragndropPlugin = DragndropPlugin_1 = (_class = /*#__PURE__*/function () {
552
532
  }
553
533
  }
554
534
 
555
- case 23:
535
+ case 21:
556
536
  case "end":
557
537
  return _context.stop();
558
538
  }
package/dist/index.umd.js CHANGED
@@ -447,7 +447,7 @@
447
447
  return Math.sqrt((a[0] - b[0]) * (a[0] - b[0]) + (a[1] - b[1]) * (a[1] - b[1]));
448
448
  }
449
449
 
450
- var DragndropPluginOptions = g.Syringe.defineToken('DragndropPluginOptions');
450
+ var DragndropPluginOptions = g.Syringe.defineToken('');
451
451
 
452
452
  var _class;
453
453
 
@@ -461,23 +461,7 @@
461
461
 
462
462
  var _proto = DragndropPlugin.prototype;
463
463
 
464
- _proto.findClosestDraggable = function findClosestDraggable(event) {
465
- var composedPath = event.composedPath();
466
-
467
- for (var i = 0; i < composedPath.length; i++) {
468
- var target = composedPath[i];
469
-
470
- if (g.Element.isElement(target) && target.getAttribute('draggable')) {
471
- return target;
472
- }
473
- }
474
-
475
- return null;
476
- };
477
-
478
464
  _proto.apply = function apply(renderingService) {
479
- var _this = this;
480
-
481
465
  var document = this.renderingContext.root.ownerDocument; // TODO: should we add an option like `draggable` to Canvas
482
466
 
483
467
  var canvas = document.defaultView;
@@ -491,16 +475,14 @@
491
475
  var handlePointerdown = function handlePointerdown(event) {
492
476
  var target = event.target;
493
477
  var isDocument = target === document;
494
-
495
- var draggableEventTarget = _this.findClosestDraggable(event); // `draggable` may be set on ancestor nodes:
478
+ var draggableEventTarget = isDocument && isDocumentDraggable ? document : target.closest && target.closest('[draggable=true]'); // `draggable` may be set on ancestor nodes:
496
479
  // @see https://github.com/antvis/G/issues/1088
497
480
 
498
-
499
- if (isDocument && isDocumentDraggable || !!draggableEventTarget) {
481
+ if (!!draggableEventTarget) {
500
482
  // @ts-ignore
501
483
  var handlePointermove = /*#__PURE__*/function () {
502
484
  var _ref = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee(event) {
503
- var timeElapsed, distanceMoved, pointerEventsOldValue, point, elemBelow, droppableBelow;
485
+ var timeElapsed, distanceMoved, point, elementsBelow, elementBelow, droppableBelow;
504
486
  return _regeneratorRuntime().wrap(function _callee$(_context) {
505
487
  while (1) {
506
488
  switch (_context.prev = _context.next) {
@@ -537,21 +519,19 @@
537
519
  lastDragClientCoordinates = [event.clientX, event.clientY];
538
520
 
539
521
  if (isDocument) {
540
- _context.next = 23;
522
+ _context.next = 21;
541
523
  break;
542
524
  }
543
525
 
544
- // prevent from picking the dragging element
545
- pointerEventsOldValue = target.style.pointerEvents;
546
- target.style.pointerEvents = 'none';
547
526
  point = overlap === 'pointer' ? [event.canvasX, event.canvasY] : target.getBounds().center;
548
- _context.next = 19;
549
- return document.elementFromPoint(point[0], point[1]);
527
+ _context.next = 17;
528
+ return document.elementsFromPoint(point[0], point[1]);
550
529
 
551
- case 19:
552
- elemBelow = _context.sent;
553
- target.style.pointerEvents = pointerEventsOldValue;
554
- droppableBelow = (elemBelow === null || elemBelow === void 0 ? void 0 : elemBelow.closest('[droppable=true]')) || (isDocumentDroppable ? document : null);
530
+ case 17:
531
+ elementsBelow = _context.sent;
532
+ // prevent from picking the dragging element
533
+ elementBelow = elementsBelow[elementsBelow.indexOf(target) + 1];
534
+ droppableBelow = (elementBelow === null || elementBelow === void 0 ? void 0 : elementBelow.closest('[droppable=true]')) || (isDocumentDroppable ? document : null);
555
535
 
556
536
  if (currentDroppable !== droppableBelow) {
557
537
  if (currentDroppable) {
@@ -580,7 +560,7 @@
580
560
  }
581
561
  }
582
562
 
583
- case 23:
563
+ case 21:
584
564
  case "end":
585
565
  return _context.stop();
586
566
  }
@@ -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 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){return a=Object.setPrototypeOf?Object.setPrototypeOf.bind():function(t,e){return t.__proto__=e,t},a(t,e)}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,l,f=e.Syringe.defineToken("DragndropPluginOptions"),p=(s=function(){function t(){this.sceneGraphService=void 0,this.renderingContext=void 0,this.dragndropPluginOptions=void 0}var n=t.prototype;return n.findClosestDraggable=function(t){for(var r=t.composedPath(),n=0;r.length>n;n++){var o=r[n];if(e.Element.isElement(o)&&o.getAttribute("draggable"))return o}return null},n.apply=function(t){var e=this,n=this.renderingContext.root.ownerDocument,i=n.defaultView,a=this.dragndropPluginOptions,c=a.overlap,u=a.isDocumentDraggable,s=a.isDocumentDroppable,f=a.dragstartDistanceThreshold,p=a.dragstartTimeThreshold,h=function(t){var a=t.target,l=a===n,h=e.findClosestDraggable(t);if(l&&u||h){var d=function(){var t=o(r().mark((function t(e){var o,i,u,d,b,x;return r().wrap((function(t){for(;;)switch(t.prev=t.next){case 0:if(v){t.next=8;break}if(o=e.timeStamp-y,r=[e.clientX,e.clientY],E=g,i=Math.sqrt((r[0]-E[0])*(r[0]-E[0])+(r[1]-E[1])*(r[1]-E[1])),o>p&&i>f){t.next=5;break}return t.abrupt("return");case 5:e.type="dragstart",h.dispatchEvent(e),v=!0;case 8:if(e.type="drag",e.dx=e.clientX-w[0],e.dy=e.clientY-w[1],h.dispatchEvent(e),w=[e.clientX,e.clientY],l){t.next=23;break}return u=a.style.pointerEvents,a.style.pointerEvents="none",d="pointer"===c?[e.canvasX,e.canvasY]:a.getBounds().center,t.next=19,n.elementFromPoint(d[0],d[1]);case 19:b=t.sent,a.style.pointerEvents=u,x=(null==b?void 0:b.closest("[droppable=true]"))||(s?n:null),m!==x&&(m&&(e.type="dragleave",e.target=m,m.dispatchEvent(e)),x&&(e.type="dragenter",e.target=x,x.dispatchEvent(e)),(m=x)&&(e.type="dragover",e.target=m,m.dispatchEvent(e)));case 23:case"end":return t.stop()}var r,E}),t)})));return function(e){return t.apply(this,arguments)}}(),v=!1,y=t.timeStamp,g=[t.clientX,t.clientY],m=null,w=[t.clientX,t.clientY];i.addEventListener("pointermove",d);var b=function(){v&&(m&&(t.type="drop",t.target=m,m.dispatchEvent(t)),t.type="dragend",t.detail={preventClick:!0},h.dispatchEvent(t),v=!1),i.removeEventListener("pointermove",d)};a.addEventListener("pointerup",b,{once:!0}),a.addEventListener("pointerupoutside",b,{once:!0})}};t.hooks.init.tapPromise(l.tag,o(r().mark((function t(){return r().wrap((function(t){for(;;)switch(t.prev=t.next){case 0:i.addEventListener("pointerdown",h);case 1:case"end":return t.stop()}}),t)})))),t.hooks.destroy.tap(l.tag,(function(){i.removeEventListener("pointerdown",h)}))},t}(),s.tag="Dragndrop",l=s);c([e.inject(e.SceneGraphService),u("design:type",Object)],p.prototype,"sceneGraphService",void 0),c([e.inject(e.RenderingContext),u("design:type",Object)],p.prototype,"renderingContext",void 0),c([e.inject(f),u("design:type",Object)],p.prototype,"dragndropPluginOptions",void 0),p=l=c([e.singleton({contrib:e.RenderingPluginContribution})],p);var h=e.Module((function(t){t(p)}));t.Plugin=function(t){var e,r;function n(e){var r;return void 0===e&&(e={}),(r=t.call(this)||this).options=void 0,r.name="dragndrop",r.options=e,r}r=t,(e=n).prototype=Object.create(r.prototype),e.prototype.constructor=e,a(e,r);var o=n.prototype;return o.init=function(){this.container.register(f,{useValue:i({overlap:"pointer",isDocumentDraggable:!1,isDocumentDroppable:!1,dragstartDistanceThreshold:0,dragstartTimeThreshold:0},this.options)}),this.container.load(h,!0)},o.destroy=function(){this.container.remove(f),this.container.unload(h)},n}(e.AbstractRendererPlugin),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===l)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===l)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 l={};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=f(t[o],t,i);if("throw"!==u.type){var s=u.arg,l=s.value;return l&&"object"==typeof l&&n.call(l,"__await")?e.resolve(l.__await).then((function(t){r("next",t,a,c)}),(function(t){r("throw",t,a,c)})):e.resolve(l).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 l;e.method="throw",e.arg=new TypeError("The iterator does not provide a 'throw' method")}return l}var n=f(r,t.iterator,e.arg);if("throw"===n.type)return e.method="throw",e.arg=n.arg,e.delegate=null,l;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,l):o:(e.method="throw",e.arg=new TypeError("iterator result is not an object"),e.delegate=null,l)}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,l):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),l},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),l}},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),l}},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){return a=Object.setPrototypeOf?Object.setPrototypeOf.bind():function(t,e){return t.__proto__=e,t},a(t,e)}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,l=e.Syringe.defineToken(""),p=(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.renderingContext.root.ownerDocument,n=e.defaultView,i=this.dragndropPluginOptions,a=i.overlap,c=i.isDocumentDraggable,u=i.isDocumentDroppable,s=i.dragstartDistanceThreshold,l=i.dragstartTimeThreshold,p=function(t){var i=t.target,f=i===e,p=f&&c?e:i.closest&&i.closest("[draggable=true]");if(p){var h=function(){var t=o(r().mark((function t(n){var o,c,h,w,b,x;return r().wrap((function(t){for(;;)switch(t.prev=t.next){case 0:if(d){t.next=8;break}if(o=n.timeStamp-v,r=[n.clientX,n.clientY],E=y,c=Math.sqrt((r[0]-E[0])*(r[0]-E[0])+(r[1]-E[1])*(r[1]-E[1])),o>l&&c>s){t.next=5;break}return t.abrupt("return");case 5:n.type="dragstart",p.dispatchEvent(n),d=!0;case 8:if(n.type="drag",n.dx=n.clientX-m[0],n.dy=n.clientY-m[1],p.dispatchEvent(n),m=[n.clientX,n.clientY],f){t.next=21;break}return h="pointer"===a?[n.canvasX,n.canvasY]:i.getBounds().center,t.next=17,e.elementsFromPoint(h[0],h[1]);case 17:b=(w=t.sent)[w.indexOf(i)+1],x=(null==b?void 0:b.closest("[droppable=true]"))||(u?e:null),g!==x&&(g&&(n.type="dragleave",n.target=g,g.dispatchEvent(n)),x&&(n.type="dragenter",n.target=x,x.dispatchEvent(n)),(g=x)&&(n.type="dragover",n.target=g,g.dispatchEvent(n)));case 21:case"end":return t.stop()}var r,E}),t)})));return function(e){return t.apply(this,arguments)}}(),d=!1,v=t.timeStamp,y=[t.clientX,t.clientY],g=null,m=[t.clientX,t.clientY];n.addEventListener("pointermove",h);var w=function(){d&&(g&&(t.type="drop",t.target=g,g.dispatchEvent(t)),t.type="dragend",t.detail={preventClick:!0},p.dispatchEvent(t),d=!1),n.removeEventListener("pointermove",h)};i.addEventListener("pointerup",w,{once:!0}),i.addEventListener("pointerupoutside",w,{once:!0})}};t.hooks.init.tapPromise(f.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(f.tag,(function(){n.removeEventListener("pointerdown",p)}))},t}(),s.tag="Dragndrop",f=s);c([e.inject(e.SceneGraphService),u("design:type",Object)],p.prototype,"sceneGraphService",void 0),c([e.inject(e.RenderingContext),u("design:type",Object)],p.prototype,"renderingContext",void 0),c([e.inject(l),u("design:type",Object)],p.prototype,"dragndropPluginOptions",void 0),p=f=c([e.singleton({contrib:e.RenderingPluginContribution})],p);var h=e.Module((function(t){t(p)}));t.Plugin=function(t){var e,r;function n(e){var r;return void 0===e&&(e={}),(r=t.call(this)||this).options=void 0,r.name="dragndrop",r.options=e,r}r=t,(e=n).prototype=Object.create(r.prototype),e.prototype.constructor=e,a(e,r);var o=n.prototype;return o.init=function(){this.container.register(l,{useValue:i({overlap:"pointer",isDocumentDraggable:!1,isDocumentDroppable:!1,dragstartDistanceThreshold:0,dragstartTimeThreshold:0},this.options)}),this.container.load(h,!0)},o.destroy=function(){this.container.remove(l),this.container.unload(h)},n}(e.AbstractRendererPlugin),Object.defineProperty(t,"__esModule",{value:!0})}));
@@ -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;IAE7B;;;OAGG;IACH,mBAAmB,EAAE,OAAO,CAAC;IAE7B;;OAEG;IACH,sBAAsB,EAAE,MAAM,CAAC;IAE/B;;OAEG;IACH,0BAA0B,EAAE,MAAM,CAAC;CACpC"}
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,sBAA0B,CAAC;AAE9D,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.5.3",
3
+ "version": "1.6.1",
4
4
  "description": "A G plugin for Drag n Drop implemented with PointerEvents",
5
5
  "keywords": [
6
6
  "antv",
@@ -27,7 +27,7 @@
27
27
  "README.md"
28
28
  ],
29
29
  "dependencies": {
30
- "@antv/util": "^3.2.2",
30
+ "@antv/util": "^3.2.3",
31
31
  "tslib": "^2.3.1"
32
32
  },
33
33
  "devDependencies": {
@@ -39,5 +39,5 @@
39
39
  "publishConfig": {
40
40
  "access": "public"
41
41
  },
42
- "gitHead": "a7ec61aed32ec1ab64d9c0cc50d8965db7d55a38"
42
+ "gitHead": "f450c50c66b1c5e57bfa9e76d231d0cbbb3643c0"
43
43
  }