@antv/g-plugin-dragndrop 1.0.3 → 1.0.5-alpha.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.
package/dist/index.js CHANGED
@@ -2,35 +2,8 @@
2
2
 
3
3
  Object.defineProperty(exports, '__esModule', { value: true });
4
4
 
5
- var manaSyringe = require('mana-syringe');
6
- var tslib = require('tslib');
7
5
  var g = require('@antv/g');
8
-
9
- function ownKeys(object, enumerableOnly) {
10
- var keys = Object.keys(object);
11
-
12
- if (Object.getOwnPropertySymbols) {
13
- var symbols = Object.getOwnPropertySymbols(object);
14
- enumerableOnly && (symbols = symbols.filter(function (sym) {
15
- return Object.getOwnPropertyDescriptor(object, sym).enumerable;
16
- })), keys.push.apply(keys, symbols);
17
- }
18
-
19
- return keys;
20
- }
21
-
22
- function _objectSpread2(target) {
23
- for (var i = 1; i < arguments.length; i++) {
24
- var source = null != arguments[i] ? arguments[i] : {};
25
- i % 2 ? ownKeys(Object(source), !0).forEach(function (key) {
26
- _defineProperty(target, key, source[key]);
27
- }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) {
28
- Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key));
29
- });
30
- }
31
-
32
- return target;
33
- }
6
+ var tslib = require('tslib');
34
7
 
35
8
  function _regeneratorRuntime() {
36
9
  /*! regenerator-runtime -- Copyright (c) 2014-present, Facebook, Inc. -- license (MIT): https://github.com/facebook/regenerator/blob/main/LICENSE */
@@ -413,232 +386,205 @@ function _asyncToGenerator(fn) {
413
386
  };
414
387
  }
415
388
 
416
- function _classCallCheck(instance, Constructor) {
417
- if (!(instance instanceof Constructor)) {
418
- throw new TypeError("Cannot call a class as a function");
419
- }
420
- }
421
-
422
- function _defineProperties(target, props) {
423
- for (var i = 0; i < props.length; i++) {
424
- var descriptor = props[i];
425
- descriptor.enumerable = descriptor.enumerable || false;
426
- descriptor.configurable = true;
427
- if ("value" in descriptor) descriptor.writable = true;
428
- Object.defineProperty(target, descriptor.key, descriptor);
429
- }
430
- }
389
+ function _extends() {
390
+ _extends = Object.assign || function (target) {
391
+ for (var i = 1; i < arguments.length; i++) {
392
+ var source = arguments[i];
431
393
 
432
- function _createClass(Constructor, protoProps, staticProps) {
433
- if (protoProps) _defineProperties(Constructor.prototype, protoProps);
434
- if (staticProps) _defineProperties(Constructor, staticProps);
435
- Object.defineProperty(Constructor, "prototype", {
436
- writable: false
437
- });
438
- return Constructor;
439
- }
394
+ for (var key in source) {
395
+ if (Object.prototype.hasOwnProperty.call(source, key)) {
396
+ target[key] = source[key];
397
+ }
398
+ }
399
+ }
440
400
 
441
- function _defineProperty(obj, key, value) {
442
- if (key in obj) {
443
- Object.defineProperty(obj, key, {
444
- value: value,
445
- enumerable: true,
446
- configurable: true,
447
- writable: true
448
- });
449
- } else {
450
- obj[key] = value;
451
- }
401
+ return target;
402
+ };
452
403
 
453
- return obj;
404
+ return _extends.apply(this, arguments);
454
405
  }
455
406
 
456
- var DragndropPluginOptions = manaSyringe.Syringe.defineToken('DragndropPluginOptions');
407
+ var DragndropPluginOptions = g.Syringe.defineToken('DragndropPluginOptions');
457
408
 
458
409
  var _class;
459
410
 
460
411
  var DragndropPlugin_1;
461
412
  var DragndropPlugin = DragndropPlugin_1 = (_class = /*#__PURE__*/function () {
462
413
  function DragndropPlugin() {
463
- _classCallCheck(this, DragndropPlugin);
464
-
465
414
  this.sceneGraphService = void 0;
466
415
  this.renderingContext = void 0;
467
416
  this.dragndropPluginOptions = void 0;
468
417
  }
469
418
 
470
- _createClass(DragndropPlugin, [{
471
- key: "apply",
472
- value: function apply(renderingService) {
473
- var _this = this;
474
-
475
- var document = this.renderingContext.root.ownerDocument;
476
- var overlap = this.dragndropPluginOptions.overlap;
477
-
478
- var handlePointerdown = function handlePointerdown(event) {
479
- var target = event.target;
480
-
481
- if (target.getAttribute('draggable')) {
482
- // @ts-ignore
483
- var onMouseMove = /*#__PURE__*/function () {
484
- var _ref = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee(event) {
485
- var pointerEventsOldValue, point, elemBelow, droppableBelow;
486
- return _regeneratorRuntime().wrap(function _callee$(_context) {
487
- while (1) {
488
- switch (_context.prev = _context.next) {
489
- case 0:
490
- // @see https://developer.mozilla.org/zh-CN/docs/Web/API/Document/drag_event
491
- event.type = 'drag';
492
- target.dispatchEvent(event); // prevent from picking the dragging element
493
-
494
- pointerEventsOldValue = target.style.pointerEvents;
495
- target.style.pointerEvents = 'none';
496
- point = overlap === 'pointer' ? [event.canvasX, event.canvasY] : target.getBounds().center;
497
- _context.next = 7;
498
- return document.elementFromPoint(point[0], point[1]);
499
-
500
- case 7:
501
- elemBelow = _context.sent;
502
- target.style.pointerEvents = pointerEventsOldValue;
503
-
504
- if (elemBelow) {
505
- _context.next = 11;
506
- break;
419
+ var _proto = DragndropPlugin.prototype;
420
+
421
+ _proto.apply = function apply(renderingService) {
422
+ var _this = this;
423
+
424
+ var document = this.renderingContext.root.ownerDocument;
425
+ var overlap = this.dragndropPluginOptions.overlap;
426
+
427
+ var handlePointerdown = function handlePointerdown(event) {
428
+ var target = event.target;
429
+
430
+ if (target.getAttribute('draggable')) {
431
+ // @ts-ignore
432
+ var onMouseMove = /*#__PURE__*/function () {
433
+ var _ref = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee(event) {
434
+ var pointerEventsOldValue, point, elemBelow, droppableBelow;
435
+ return _regeneratorRuntime().wrap(function _callee$(_context) {
436
+ while (1) {
437
+ switch (_context.prev = _context.next) {
438
+ case 0:
439
+ // @see https://developer.mozilla.org/zh-CN/docs/Web/API/Document/drag_event
440
+ event.type = 'drag';
441
+ target.dispatchEvent(event); // prevent from picking the dragging element
442
+
443
+ pointerEventsOldValue = target.style.pointerEvents;
444
+ target.style.pointerEvents = 'none';
445
+ point = overlap === 'pointer' ? [event.canvasX, event.canvasY] : target.getBounds().center;
446
+ _context.next = 7;
447
+ return document.elementFromPoint(point[0], point[1]);
448
+
449
+ case 7:
450
+ elemBelow = _context.sent;
451
+ target.style.pointerEvents = pointerEventsOldValue;
452
+
453
+ if (elemBelow) {
454
+ _context.next = 11;
455
+ break;
456
+ }
457
+
458
+ return _context.abrupt("return");
459
+
460
+ case 11:
461
+ droppableBelow = (elemBelow === null || elemBelow === void 0 ? void 0 : elemBelow.closest('[droppable=true]')) || null;
462
+
463
+ if (currentDroppable !== droppableBelow) {
464
+ if (currentDroppable) {
465
+ // null when we were not over a droppable before this event
466
+ // @see https://developer.mozilla.org/zh-CN/docs/Web/API/Document/dragleave_event
467
+ event.type = 'dragleave';
468
+ event.target = currentDroppable;
469
+ currentDroppable.dispatchEvent(event);
507
470
  }
508
471
 
509
- return _context.abrupt("return");
510
-
511
- case 11:
512
- droppableBelow = (elemBelow === null || elemBelow === void 0 ? void 0 : elemBelow.closest('[droppable=true]')) || null;
513
-
514
- if (currentDroppable !== droppableBelow) {
515
- if (currentDroppable) {
516
- // null when we were not over a droppable before this event
517
- // @see https://developer.mozilla.org/zh-CN/docs/Web/API/Document/dragleave_event
518
- event.type = 'dragleave';
519
- event.target = currentDroppable;
520
- currentDroppable.dispatchEvent(event);
521
- }
522
-
523
- if (droppableBelow) {
524
- // @see https://developer.mozilla.org/zh-CN/docs/Web/API/Document/dragleave_event
525
- event.type = 'dragenter';
526
- event.target = droppableBelow;
527
- droppableBelow.dispatchEvent(event);
528
- }
529
-
530
- currentDroppable = droppableBelow;
531
-
532
- if (currentDroppable) {
533
- // null if we're not coming over a droppable now
534
- // @see https://developer.mozilla.org/zh-CN/docs/Web/API/Document/dragover_event
535
- event.type = 'dragover';
536
- event.target = currentDroppable;
537
- currentDroppable.dispatchEvent(event);
538
- }
472
+ if (droppableBelow) {
473
+ // @see https://developer.mozilla.org/zh-CN/docs/Web/API/Document/dragleave_event
474
+ event.type = 'dragenter';
475
+ event.target = droppableBelow;
476
+ droppableBelow.dispatchEvent(event);
539
477
  }
540
478
 
541
- case 13:
542
- case "end":
543
- return _context.stop();
544
- }
545
- }
546
- }, _callee);
547
- }));
479
+ currentDroppable = droppableBelow;
548
480
 
549
- return function onMouseMove(_x) {
550
- return _ref.apply(this, arguments);
551
- };
552
- }();
481
+ if (currentDroppable) {
482
+ // null if we're not coming over a droppable now
483
+ // @see https://developer.mozilla.org/zh-CN/docs/Web/API/Document/dragover_event
484
+ event.type = 'dragover';
485
+ event.target = currentDroppable;
486
+ currentDroppable.dispatchEvent(event);
487
+ }
488
+ }
553
489
 
554
- // @see https://developer.mozilla.org/zh-CN/docs/Web/API/Document/dragstart_event
555
- event.type = 'dragstart';
490
+ case 13:
491
+ case "end":
492
+ return _context.stop();
493
+ }
494
+ }
495
+ }, _callee);
496
+ }));
497
+
498
+ return function onMouseMove(_x) {
499
+ return _ref.apply(this, arguments);
500
+ };
501
+ }();
502
+
503
+ // @see https://developer.mozilla.org/zh-CN/docs/Web/API/Document/dragstart_event
504
+ event.type = 'dragstart';
505
+ target.dispatchEvent(event);
506
+ var currentDroppable = null;
507
+ document.addEventListener('pointermove', onMouseMove);
508
+ target.addEventListener('pointerup', function () {
509
+ // @see https://developer.mozilla.org/zh-CN/docs/Web/API/Document/dragend_event
510
+ event.type = 'dragend';
556
511
  target.dispatchEvent(event);
557
- var currentDroppable = null;
558
- document.addEventListener('pointermove', onMouseMove);
559
- target.addEventListener('pointerup', function () {
560
- // @see https://developer.mozilla.org/zh-CN/docs/Web/API/Document/dragend_event
561
- event.type = 'dragend';
562
- target.dispatchEvent(event);
563
-
564
- if (currentDroppable) {
565
- // @see https://developer.mozilla.org/zh-CN/docs/Web/API/Document/drop_event
566
- event.type = 'drop';
567
- event.target = currentDroppable;
568
- currentDroppable.dispatchEvent(event);
569
- }
570
512
 
571
- document.removeEventListener('pointermove', onMouseMove);
572
- }, {
573
- once: true
574
- });
575
- }
576
- };
513
+ if (currentDroppable) {
514
+ // @see https://developer.mozilla.org/zh-CN/docs/Web/API/Document/drop_event
515
+ event.type = 'drop';
516
+ event.target = currentDroppable;
517
+ currentDroppable.dispatchEvent(event);
518
+ }
577
519
 
578
- renderingService.hooks.init.tapPromise(DragndropPlugin_1.tag, /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee2() {
579
- return _regeneratorRuntime().wrap(function _callee2$(_context2) {
580
- while (1) {
581
- switch (_context2.prev = _context2.next) {
582
- case 0:
583
- _this.renderingContext.root.addEventListener('pointerdown', handlePointerdown);
520
+ document.removeEventListener('pointermove', onMouseMove);
521
+ }, {
522
+ once: true
523
+ });
524
+ }
525
+ };
584
526
 
585
- case 1:
586
- case "end":
587
- return _context2.stop();
588
- }
527
+ renderingService.hooks.init.tapPromise(DragndropPlugin_1.tag, /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee2() {
528
+ return _regeneratorRuntime().wrap(function _callee2$(_context2) {
529
+ while (1) {
530
+ switch (_context2.prev = _context2.next) {
531
+ case 0:
532
+ _this.renderingContext.root.addEventListener('pointerdown', handlePointerdown);
533
+
534
+ case 1:
535
+ case "end":
536
+ return _context2.stop();
589
537
  }
590
- }, _callee2);
591
- })));
592
- renderingService.hooks.destroy.tap(DragndropPlugin_1.tag, function () {
593
- _this.renderingContext.root.removeEventListener('pointerdown', handlePointerdown);
594
- });
595
- }
596
- }]);
538
+ }
539
+ }, _callee2);
540
+ })));
541
+ renderingService.hooks.destroy.tap(DragndropPlugin_1.tag, function () {
542
+ _this.renderingContext.root.removeEventListener('pointerdown', handlePointerdown);
543
+ });
544
+ };
597
545
 
598
546
  return DragndropPlugin;
599
547
  }(), _class.tag = 'Dragndrop', _class);
600
548
 
601
- tslib.__decorate([manaSyringe.inject(g.SceneGraphService), tslib.__metadata("design:type", Object)], DragndropPlugin.prototype, "sceneGraphService", void 0);
549
+ tslib.__decorate([g.inject(g.SceneGraphService), tslib.__metadata("design:type", Object)], DragndropPlugin.prototype, "sceneGraphService", void 0);
602
550
 
603
- tslib.__decorate([manaSyringe.inject(g.RenderingContext), tslib.__metadata("design:type", Object)], DragndropPlugin.prototype, "renderingContext", void 0);
551
+ tslib.__decorate([g.inject(g.RenderingContext), tslib.__metadata("design:type", Object)], DragndropPlugin.prototype, "renderingContext", void 0);
604
552
 
605
- tslib.__decorate([manaSyringe.inject(DragndropPluginOptions), tslib.__metadata("design:type", Object)], DragndropPlugin.prototype, "dragndropPluginOptions", void 0);
553
+ tslib.__decorate([g.inject(DragndropPluginOptions), tslib.__metadata("design:type", Object)], DragndropPlugin.prototype, "dragndropPluginOptions", void 0);
606
554
 
607
- DragndropPlugin = DragndropPlugin_1 = tslib.__decorate([manaSyringe.singleton({
555
+ DragndropPlugin = DragndropPlugin_1 = tslib.__decorate([g.singleton({
608
556
  contrib: g.RenderingPluginContribution
609
557
  })], DragndropPlugin);
610
558
 
611
- var containerModule = manaSyringe.Module(function (register) {
559
+ var containerModule = g.Module(function (register) {
612
560
  register(DragndropPlugin);
613
561
  });
614
562
  var Plugin = /*#__PURE__*/function () {
615
- function Plugin() {
616
- var options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
617
-
618
- _classCallCheck(this, Plugin);
563
+ function Plugin(options) {
564
+ if (options === void 0) {
565
+ options = {};
566
+ }
619
567
 
620
568
  this.options = void 0;
621
569
  this.name = 'dragndrop';
622
570
  this.options = options;
623
571
  }
624
572
 
625
- _createClass(Plugin, [{
626
- key: "init",
627
- value: function init(container) {
628
- container.register(DragndropPluginOptions, {
629
- useValue: _objectSpread2({
630
- overlap: 'pointer'
631
- }, this.options)
632
- });
633
- container.load(containerModule, true);
634
- }
635
- }, {
636
- key: "destroy",
637
- value: function destroy(container) {
638
- container.remove(DragndropPluginOptions);
639
- container.unload(containerModule);
640
- }
641
- }]);
573
+ var _proto = Plugin.prototype;
574
+
575
+ _proto.init = function init(container) {
576
+ container.register(DragndropPluginOptions, {
577
+ useValue: _extends({
578
+ overlap: 'pointer'
579
+ }, this.options)
580
+ });
581
+ container.load(containerModule, true);
582
+ };
583
+
584
+ _proto.destroy = function destroy(container) {
585
+ container.remove(DragndropPluginOptions);
586
+ container.unload(containerModule);
587
+ };
642
588
 
643
589
  return Plugin;
644
590
  }();