@antv/g-plugin-dragndrop 1.0.2 → 1.0.3
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.esm.js +200 -147
- package/dist/index.js +200 -147
- package/dist/index.umd.js +200 -147
- package/dist/index.umd.min.js +2 -2
- package/package.json +2 -2
package/dist/index.esm.js
CHANGED
|
@@ -2,6 +2,32 @@ import { Syringe, inject, singleton, Module } from 'mana-syringe';
|
|
|
2
2
|
import { __decorate, __metadata } from 'tslib';
|
|
3
3
|
import { SceneGraphService, RenderingContext, RenderingPluginContribution } from '@antv/g';
|
|
4
4
|
|
|
5
|
+
function ownKeys(object, enumerableOnly) {
|
|
6
|
+
var keys = Object.keys(object);
|
|
7
|
+
|
|
8
|
+
if (Object.getOwnPropertySymbols) {
|
|
9
|
+
var symbols = Object.getOwnPropertySymbols(object);
|
|
10
|
+
enumerableOnly && (symbols = symbols.filter(function (sym) {
|
|
11
|
+
return Object.getOwnPropertyDescriptor(object, sym).enumerable;
|
|
12
|
+
})), keys.push.apply(keys, symbols);
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
return keys;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
function _objectSpread2(target) {
|
|
19
|
+
for (var i = 1; i < arguments.length; i++) {
|
|
20
|
+
var source = null != arguments[i] ? arguments[i] : {};
|
|
21
|
+
i % 2 ? ownKeys(Object(source), !0).forEach(function (key) {
|
|
22
|
+
_defineProperty(target, key, source[key]);
|
|
23
|
+
}) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) {
|
|
24
|
+
Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key));
|
|
25
|
+
});
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
return target;
|
|
29
|
+
}
|
|
30
|
+
|
|
5
31
|
function _regeneratorRuntime() {
|
|
6
32
|
/*! regenerator-runtime -- Copyright (c) 2014-present, Facebook, Inc. -- license (MIT): https://github.com/facebook/regenerator/blob/main/LICENSE */
|
|
7
33
|
|
|
@@ -383,22 +409,44 @@ function _asyncToGenerator(fn) {
|
|
|
383
409
|
};
|
|
384
410
|
}
|
|
385
411
|
|
|
386
|
-
function
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
412
|
+
function _classCallCheck(instance, Constructor) {
|
|
413
|
+
if (!(instance instanceof Constructor)) {
|
|
414
|
+
throw new TypeError("Cannot call a class as a function");
|
|
415
|
+
}
|
|
416
|
+
}
|
|
390
417
|
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
418
|
+
function _defineProperties(target, props) {
|
|
419
|
+
for (var i = 0; i < props.length; i++) {
|
|
420
|
+
var descriptor = props[i];
|
|
421
|
+
descriptor.enumerable = descriptor.enumerable || false;
|
|
422
|
+
descriptor.configurable = true;
|
|
423
|
+
if ("value" in descriptor) descriptor.writable = true;
|
|
424
|
+
Object.defineProperty(target, descriptor.key, descriptor);
|
|
425
|
+
}
|
|
426
|
+
}
|
|
397
427
|
|
|
398
|
-
|
|
399
|
-
|
|
428
|
+
function _createClass(Constructor, protoProps, staticProps) {
|
|
429
|
+
if (protoProps) _defineProperties(Constructor.prototype, protoProps);
|
|
430
|
+
if (staticProps) _defineProperties(Constructor, staticProps);
|
|
431
|
+
Object.defineProperty(Constructor, "prototype", {
|
|
432
|
+
writable: false
|
|
433
|
+
});
|
|
434
|
+
return Constructor;
|
|
435
|
+
}
|
|
400
436
|
|
|
401
|
-
|
|
437
|
+
function _defineProperty(obj, key, value) {
|
|
438
|
+
if (key in obj) {
|
|
439
|
+
Object.defineProperty(obj, key, {
|
|
440
|
+
value: value,
|
|
441
|
+
enumerable: true,
|
|
442
|
+
configurable: true,
|
|
443
|
+
writable: true
|
|
444
|
+
});
|
|
445
|
+
} else {
|
|
446
|
+
obj[key] = value;
|
|
447
|
+
}
|
|
448
|
+
|
|
449
|
+
return obj;
|
|
402
450
|
}
|
|
403
451
|
|
|
404
452
|
var DragndropPluginOptions = Syringe.defineToken('DragndropPluginOptions');
|
|
@@ -408,137 +456,140 @@ var _class;
|
|
|
408
456
|
var DragndropPlugin_1;
|
|
409
457
|
var DragndropPlugin = DragndropPlugin_1 = (_class = /*#__PURE__*/function () {
|
|
410
458
|
function DragndropPlugin() {
|
|
459
|
+
_classCallCheck(this, DragndropPlugin);
|
|
460
|
+
|
|
411
461
|
this.sceneGraphService = void 0;
|
|
412
462
|
this.renderingContext = void 0;
|
|
413
463
|
this.dragndropPluginOptions = void 0;
|
|
414
464
|
}
|
|
415
465
|
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
}
|
|
454
|
-
|
|
455
|
-
return _context.abrupt("return");
|
|
456
|
-
|
|
457
|
-
case 11:
|
|
458
|
-
droppableBelow = (elemBelow === null || elemBelow === void 0 ? void 0 : elemBelow.closest('[droppable=true]')) || null;
|
|
459
|
-
|
|
460
|
-
if (currentDroppable !== droppableBelow) {
|
|
461
|
-
if (currentDroppable) {
|
|
462
|
-
// null when we were not over a droppable before this event
|
|
463
|
-
// @see https://developer.mozilla.org/zh-CN/docs/Web/API/Document/dragleave_event
|
|
464
|
-
event.type = 'dragleave';
|
|
465
|
-
event.target = currentDroppable;
|
|
466
|
-
currentDroppable.dispatchEvent(event);
|
|
466
|
+
_createClass(DragndropPlugin, [{
|
|
467
|
+
key: "apply",
|
|
468
|
+
value: function apply(renderingService) {
|
|
469
|
+
var _this = this;
|
|
470
|
+
|
|
471
|
+
var document = this.renderingContext.root.ownerDocument;
|
|
472
|
+
var overlap = this.dragndropPluginOptions.overlap;
|
|
473
|
+
|
|
474
|
+
var handlePointerdown = function handlePointerdown(event) {
|
|
475
|
+
var target = event.target;
|
|
476
|
+
|
|
477
|
+
if (target.getAttribute('draggable')) {
|
|
478
|
+
// @ts-ignore
|
|
479
|
+
var onMouseMove = /*#__PURE__*/function () {
|
|
480
|
+
var _ref = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee(event) {
|
|
481
|
+
var pointerEventsOldValue, point, elemBelow, droppableBelow;
|
|
482
|
+
return _regeneratorRuntime().wrap(function _callee$(_context) {
|
|
483
|
+
while (1) {
|
|
484
|
+
switch (_context.prev = _context.next) {
|
|
485
|
+
case 0:
|
|
486
|
+
// @see https://developer.mozilla.org/zh-CN/docs/Web/API/Document/drag_event
|
|
487
|
+
event.type = 'drag';
|
|
488
|
+
target.dispatchEvent(event); // prevent from picking the dragging element
|
|
489
|
+
|
|
490
|
+
pointerEventsOldValue = target.style.pointerEvents;
|
|
491
|
+
target.style.pointerEvents = 'none';
|
|
492
|
+
point = overlap === 'pointer' ? [event.canvasX, event.canvasY] : target.getBounds().center;
|
|
493
|
+
_context.next = 7;
|
|
494
|
+
return document.elementFromPoint(point[0], point[1]);
|
|
495
|
+
|
|
496
|
+
case 7:
|
|
497
|
+
elemBelow = _context.sent;
|
|
498
|
+
target.style.pointerEvents = pointerEventsOldValue;
|
|
499
|
+
|
|
500
|
+
if (elemBelow) {
|
|
501
|
+
_context.next = 11;
|
|
502
|
+
break;
|
|
467
503
|
}
|
|
468
504
|
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
|
|
505
|
+
return _context.abrupt("return");
|
|
506
|
+
|
|
507
|
+
case 11:
|
|
508
|
+
droppableBelow = (elemBelow === null || elemBelow === void 0 ? void 0 : elemBelow.closest('[droppable=true]')) || null;
|
|
509
|
+
|
|
510
|
+
if (currentDroppable !== droppableBelow) {
|
|
511
|
+
if (currentDroppable) {
|
|
512
|
+
// null when we were not over a droppable before this event
|
|
513
|
+
// @see https://developer.mozilla.org/zh-CN/docs/Web/API/Document/dragleave_event
|
|
514
|
+
event.type = 'dragleave';
|
|
515
|
+
event.target = currentDroppable;
|
|
516
|
+
currentDroppable.dispatchEvent(event);
|
|
517
|
+
}
|
|
518
|
+
|
|
519
|
+
if (droppableBelow) {
|
|
520
|
+
// @see https://developer.mozilla.org/zh-CN/docs/Web/API/Document/dragleave_event
|
|
521
|
+
event.type = 'dragenter';
|
|
522
|
+
event.target = droppableBelow;
|
|
523
|
+
droppableBelow.dispatchEvent(event);
|
|
524
|
+
}
|
|
525
|
+
|
|
526
|
+
currentDroppable = droppableBelow;
|
|
527
|
+
|
|
528
|
+
if (currentDroppable) {
|
|
529
|
+
// null if we're not coming over a droppable now
|
|
530
|
+
// @see https://developer.mozilla.org/zh-CN/docs/Web/API/Document/dragover_event
|
|
531
|
+
event.type = 'dragover';
|
|
532
|
+
event.target = currentDroppable;
|
|
533
|
+
currentDroppable.dispatchEvent(event);
|
|
534
|
+
}
|
|
474
535
|
}
|
|
475
536
|
|
|
476
|
-
|
|
537
|
+
case 13:
|
|
538
|
+
case "end":
|
|
539
|
+
return _context.stop();
|
|
540
|
+
}
|
|
541
|
+
}
|
|
542
|
+
}, _callee);
|
|
543
|
+
}));
|
|
477
544
|
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
|
|
481
|
-
|
|
482
|
-
event.target = currentDroppable;
|
|
483
|
-
currentDroppable.dispatchEvent(event);
|
|
484
|
-
}
|
|
485
|
-
}
|
|
545
|
+
return function onMouseMove(_x) {
|
|
546
|
+
return _ref.apply(this, arguments);
|
|
547
|
+
};
|
|
548
|
+
}();
|
|
486
549
|
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
return _context.stop();
|
|
490
|
-
}
|
|
491
|
-
}
|
|
492
|
-
}, _callee);
|
|
493
|
-
}));
|
|
494
|
-
|
|
495
|
-
return function onMouseMove(_x) {
|
|
496
|
-
return _ref.apply(this, arguments);
|
|
497
|
-
};
|
|
498
|
-
}();
|
|
499
|
-
|
|
500
|
-
// @see https://developer.mozilla.org/zh-CN/docs/Web/API/Document/dragstart_event
|
|
501
|
-
event.type = 'dragstart';
|
|
502
|
-
target.dispatchEvent(event);
|
|
503
|
-
var currentDroppable = null;
|
|
504
|
-
document.addEventListener('pointermove', onMouseMove);
|
|
505
|
-
target.addEventListener('pointerup', function () {
|
|
506
|
-
// @see https://developer.mozilla.org/zh-CN/docs/Web/API/Document/dragend_event
|
|
507
|
-
event.type = 'dragend';
|
|
550
|
+
// @see https://developer.mozilla.org/zh-CN/docs/Web/API/Document/dragstart_event
|
|
551
|
+
event.type = 'dragstart';
|
|
508
552
|
target.dispatchEvent(event);
|
|
553
|
+
var currentDroppable = null;
|
|
554
|
+
document.addEventListener('pointermove', onMouseMove);
|
|
555
|
+
target.addEventListener('pointerup', function () {
|
|
556
|
+
// @see https://developer.mozilla.org/zh-CN/docs/Web/API/Document/dragend_event
|
|
557
|
+
event.type = 'dragend';
|
|
558
|
+
target.dispatchEvent(event);
|
|
559
|
+
|
|
560
|
+
if (currentDroppable) {
|
|
561
|
+
// @see https://developer.mozilla.org/zh-CN/docs/Web/API/Document/drop_event
|
|
562
|
+
event.type = 'drop';
|
|
563
|
+
event.target = currentDroppable;
|
|
564
|
+
currentDroppable.dispatchEvent(event);
|
|
565
|
+
}
|
|
509
566
|
|
|
510
|
-
|
|
511
|
-
|
|
512
|
-
|
|
513
|
-
|
|
514
|
-
|
|
515
|
-
|
|
516
|
-
|
|
517
|
-
document.removeEventListener('pointermove', onMouseMove);
|
|
518
|
-
}, {
|
|
519
|
-
once: true
|
|
520
|
-
});
|
|
521
|
-
}
|
|
522
|
-
};
|
|
567
|
+
document.removeEventListener('pointermove', onMouseMove);
|
|
568
|
+
}, {
|
|
569
|
+
once: true
|
|
570
|
+
});
|
|
571
|
+
}
|
|
572
|
+
};
|
|
523
573
|
|
|
524
|
-
|
|
525
|
-
|
|
526
|
-
|
|
527
|
-
|
|
528
|
-
|
|
529
|
-
|
|
574
|
+
renderingService.hooks.init.tapPromise(DragndropPlugin_1.tag, /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee2() {
|
|
575
|
+
return _regeneratorRuntime().wrap(function _callee2$(_context2) {
|
|
576
|
+
while (1) {
|
|
577
|
+
switch (_context2.prev = _context2.next) {
|
|
578
|
+
case 0:
|
|
579
|
+
_this.renderingContext.root.addEventListener('pointerdown', handlePointerdown);
|
|
530
580
|
|
|
531
|
-
|
|
532
|
-
|
|
533
|
-
|
|
581
|
+
case 1:
|
|
582
|
+
case "end":
|
|
583
|
+
return _context2.stop();
|
|
584
|
+
}
|
|
534
585
|
}
|
|
535
|
-
}
|
|
536
|
-
}
|
|
537
|
-
|
|
538
|
-
|
|
539
|
-
|
|
540
|
-
}
|
|
541
|
-
};
|
|
586
|
+
}, _callee2);
|
|
587
|
+
})));
|
|
588
|
+
renderingService.hooks.destroy.tap(DragndropPlugin_1.tag, function () {
|
|
589
|
+
_this.renderingContext.root.removeEventListener('pointerdown', handlePointerdown);
|
|
590
|
+
});
|
|
591
|
+
}
|
|
592
|
+
}]);
|
|
542
593
|
|
|
543
594
|
return DragndropPlugin;
|
|
544
595
|
}(), _class.tag = 'Dragndrop', _class);
|
|
@@ -557,31 +608,33 @@ var containerModule = Module(function (register) {
|
|
|
557
608
|
register(DragndropPlugin);
|
|
558
609
|
});
|
|
559
610
|
var Plugin = /*#__PURE__*/function () {
|
|
560
|
-
function Plugin(
|
|
561
|
-
|
|
562
|
-
|
|
563
|
-
|
|
611
|
+
function Plugin() {
|
|
612
|
+
var options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
|
|
613
|
+
|
|
614
|
+
_classCallCheck(this, Plugin);
|
|
564
615
|
|
|
565
616
|
this.options = void 0;
|
|
566
617
|
this.name = 'dragndrop';
|
|
567
618
|
this.options = options;
|
|
568
619
|
}
|
|
569
620
|
|
|
570
|
-
|
|
571
|
-
|
|
572
|
-
|
|
573
|
-
|
|
574
|
-
|
|
575
|
-
|
|
576
|
-
|
|
577
|
-
|
|
578
|
-
|
|
579
|
-
|
|
580
|
-
|
|
581
|
-
|
|
582
|
-
container
|
|
583
|
-
|
|
584
|
-
|
|
621
|
+
_createClass(Plugin, [{
|
|
622
|
+
key: "init",
|
|
623
|
+
value: function init(container) {
|
|
624
|
+
container.register(DragndropPluginOptions, {
|
|
625
|
+
useValue: _objectSpread2({
|
|
626
|
+
overlap: 'pointer'
|
|
627
|
+
}, this.options)
|
|
628
|
+
});
|
|
629
|
+
container.load(containerModule, true);
|
|
630
|
+
}
|
|
631
|
+
}, {
|
|
632
|
+
key: "destroy",
|
|
633
|
+
value: function destroy(container) {
|
|
634
|
+
container.remove(DragndropPluginOptions);
|
|
635
|
+
container.unload(containerModule);
|
|
636
|
+
}
|
|
637
|
+
}]);
|
|
585
638
|
|
|
586
639
|
return Plugin;
|
|
587
640
|
}();
|
package/dist/index.js
CHANGED
|
@@ -6,6 +6,32 @@ var manaSyringe = require('mana-syringe');
|
|
|
6
6
|
var tslib = require('tslib');
|
|
7
7
|
var g = require('@antv/g');
|
|
8
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
|
+
}
|
|
34
|
+
|
|
9
35
|
function _regeneratorRuntime() {
|
|
10
36
|
/*! regenerator-runtime -- Copyright (c) 2014-present, Facebook, Inc. -- license (MIT): https://github.com/facebook/regenerator/blob/main/LICENSE */
|
|
11
37
|
|
|
@@ -387,22 +413,44 @@ function _asyncToGenerator(fn) {
|
|
|
387
413
|
};
|
|
388
414
|
}
|
|
389
415
|
|
|
390
|
-
function
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
416
|
+
function _classCallCheck(instance, Constructor) {
|
|
417
|
+
if (!(instance instanceof Constructor)) {
|
|
418
|
+
throw new TypeError("Cannot call a class as a function");
|
|
419
|
+
}
|
|
420
|
+
}
|
|
394
421
|
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
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
|
+
}
|
|
401
431
|
|
|
402
|
-
|
|
403
|
-
|
|
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
|
+
}
|
|
404
440
|
|
|
405
|
-
|
|
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
|
+
}
|
|
452
|
+
|
|
453
|
+
return obj;
|
|
406
454
|
}
|
|
407
455
|
|
|
408
456
|
var DragndropPluginOptions = manaSyringe.Syringe.defineToken('DragndropPluginOptions');
|
|
@@ -412,137 +460,140 @@ var _class;
|
|
|
412
460
|
var DragndropPlugin_1;
|
|
413
461
|
var DragndropPlugin = DragndropPlugin_1 = (_class = /*#__PURE__*/function () {
|
|
414
462
|
function DragndropPlugin() {
|
|
463
|
+
_classCallCheck(this, DragndropPlugin);
|
|
464
|
+
|
|
415
465
|
this.sceneGraphService = void 0;
|
|
416
466
|
this.renderingContext = void 0;
|
|
417
467
|
this.dragndropPluginOptions = void 0;
|
|
418
468
|
}
|
|
419
469
|
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
}
|
|
458
|
-
|
|
459
|
-
return _context.abrupt("return");
|
|
460
|
-
|
|
461
|
-
case 11:
|
|
462
|
-
droppableBelow = (elemBelow === null || elemBelow === void 0 ? void 0 : elemBelow.closest('[droppable=true]')) || null;
|
|
463
|
-
|
|
464
|
-
if (currentDroppable !== droppableBelow) {
|
|
465
|
-
if (currentDroppable) {
|
|
466
|
-
// null when we were not over a droppable before this event
|
|
467
|
-
// @see https://developer.mozilla.org/zh-CN/docs/Web/API/Document/dragleave_event
|
|
468
|
-
event.type = 'dragleave';
|
|
469
|
-
event.target = currentDroppable;
|
|
470
|
-
currentDroppable.dispatchEvent(event);
|
|
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;
|
|
471
507
|
}
|
|
472
508
|
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
|
|
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
|
+
}
|
|
478
539
|
}
|
|
479
540
|
|
|
480
|
-
|
|
541
|
+
case 13:
|
|
542
|
+
case "end":
|
|
543
|
+
return _context.stop();
|
|
544
|
+
}
|
|
545
|
+
}
|
|
546
|
+
}, _callee);
|
|
547
|
+
}));
|
|
481
548
|
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
event.target = currentDroppable;
|
|
487
|
-
currentDroppable.dispatchEvent(event);
|
|
488
|
-
}
|
|
489
|
-
}
|
|
549
|
+
return function onMouseMove(_x) {
|
|
550
|
+
return _ref.apply(this, arguments);
|
|
551
|
+
};
|
|
552
|
+
}();
|
|
490
553
|
|
|
491
|
-
|
|
492
|
-
|
|
493
|
-
return _context.stop();
|
|
494
|
-
}
|
|
495
|
-
}
|
|
496
|
-
}, _callee);
|
|
497
|
-
}));
|
|
498
|
-
|
|
499
|
-
return function onMouseMove(_x) {
|
|
500
|
-
return _ref.apply(this, arguments);
|
|
501
|
-
};
|
|
502
|
-
}();
|
|
503
|
-
|
|
504
|
-
// @see https://developer.mozilla.org/zh-CN/docs/Web/API/Document/dragstart_event
|
|
505
|
-
event.type = 'dragstart';
|
|
506
|
-
target.dispatchEvent(event);
|
|
507
|
-
var currentDroppable = null;
|
|
508
|
-
document.addEventListener('pointermove', onMouseMove);
|
|
509
|
-
target.addEventListener('pointerup', function () {
|
|
510
|
-
// @see https://developer.mozilla.org/zh-CN/docs/Web/API/Document/dragend_event
|
|
511
|
-
event.type = 'dragend';
|
|
554
|
+
// @see https://developer.mozilla.org/zh-CN/docs/Web/API/Document/dragstart_event
|
|
555
|
+
event.type = 'dragstart';
|
|
512
556
|
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
|
+
}
|
|
513
570
|
|
|
514
|
-
|
|
515
|
-
|
|
516
|
-
|
|
517
|
-
|
|
518
|
-
|
|
519
|
-
|
|
520
|
-
|
|
521
|
-
document.removeEventListener('pointermove', onMouseMove);
|
|
522
|
-
}, {
|
|
523
|
-
once: true
|
|
524
|
-
});
|
|
525
|
-
}
|
|
526
|
-
};
|
|
571
|
+
document.removeEventListener('pointermove', onMouseMove);
|
|
572
|
+
}, {
|
|
573
|
+
once: true
|
|
574
|
+
});
|
|
575
|
+
}
|
|
576
|
+
};
|
|
527
577
|
|
|
528
|
-
|
|
529
|
-
|
|
530
|
-
|
|
531
|
-
|
|
532
|
-
|
|
533
|
-
|
|
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);
|
|
534
584
|
|
|
535
|
-
|
|
536
|
-
|
|
537
|
-
|
|
585
|
+
case 1:
|
|
586
|
+
case "end":
|
|
587
|
+
return _context2.stop();
|
|
588
|
+
}
|
|
538
589
|
}
|
|
539
|
-
}
|
|
540
|
-
}
|
|
541
|
-
|
|
542
|
-
|
|
543
|
-
|
|
544
|
-
}
|
|
545
|
-
};
|
|
590
|
+
}, _callee2);
|
|
591
|
+
})));
|
|
592
|
+
renderingService.hooks.destroy.tap(DragndropPlugin_1.tag, function () {
|
|
593
|
+
_this.renderingContext.root.removeEventListener('pointerdown', handlePointerdown);
|
|
594
|
+
});
|
|
595
|
+
}
|
|
596
|
+
}]);
|
|
546
597
|
|
|
547
598
|
return DragndropPlugin;
|
|
548
599
|
}(), _class.tag = 'Dragndrop', _class);
|
|
@@ -561,31 +612,33 @@ var containerModule = manaSyringe.Module(function (register) {
|
|
|
561
612
|
register(DragndropPlugin);
|
|
562
613
|
});
|
|
563
614
|
var Plugin = /*#__PURE__*/function () {
|
|
564
|
-
function Plugin(
|
|
565
|
-
|
|
566
|
-
|
|
567
|
-
|
|
615
|
+
function Plugin() {
|
|
616
|
+
var options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
|
|
617
|
+
|
|
618
|
+
_classCallCheck(this, Plugin);
|
|
568
619
|
|
|
569
620
|
this.options = void 0;
|
|
570
621
|
this.name = 'dragndrop';
|
|
571
622
|
this.options = options;
|
|
572
623
|
}
|
|
573
624
|
|
|
574
|
-
|
|
575
|
-
|
|
576
|
-
|
|
577
|
-
|
|
578
|
-
|
|
579
|
-
|
|
580
|
-
|
|
581
|
-
|
|
582
|
-
|
|
583
|
-
|
|
584
|
-
|
|
585
|
-
|
|
586
|
-
container
|
|
587
|
-
|
|
588
|
-
|
|
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
|
+
}]);
|
|
589
642
|
|
|
590
643
|
return Plugin;
|
|
591
644
|
}();
|
package/dist/index.umd.js
CHANGED
|
@@ -4,6 +4,32 @@
|
|
|
4
4
|
(global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory((global.G = global.G || {}, global.G.Dragndrop = {}), global.window.G.ManaSyringe, global.window.G));
|
|
5
5
|
}(this, (function (exports, manaSyringe, g) { 'use strict';
|
|
6
6
|
|
|
7
|
+
function ownKeys(object, enumerableOnly) {
|
|
8
|
+
var keys = Object.keys(object);
|
|
9
|
+
|
|
10
|
+
if (Object.getOwnPropertySymbols) {
|
|
11
|
+
var symbols = Object.getOwnPropertySymbols(object);
|
|
12
|
+
enumerableOnly && (symbols = symbols.filter(function (sym) {
|
|
13
|
+
return Object.getOwnPropertyDescriptor(object, sym).enumerable;
|
|
14
|
+
})), keys.push.apply(keys, symbols);
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
return keys;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
function _objectSpread2(target) {
|
|
21
|
+
for (var i = 1; i < arguments.length; i++) {
|
|
22
|
+
var source = null != arguments[i] ? arguments[i] : {};
|
|
23
|
+
i % 2 ? ownKeys(Object(source), !0).forEach(function (key) {
|
|
24
|
+
_defineProperty(target, key, source[key]);
|
|
25
|
+
}) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) {
|
|
26
|
+
Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key));
|
|
27
|
+
});
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
return target;
|
|
31
|
+
}
|
|
32
|
+
|
|
7
33
|
function _regeneratorRuntime() {
|
|
8
34
|
/*! regenerator-runtime -- Copyright (c) 2014-present, Facebook, Inc. -- license (MIT): https://github.com/facebook/regenerator/blob/main/LICENSE */
|
|
9
35
|
|
|
@@ -385,22 +411,44 @@
|
|
|
385
411
|
};
|
|
386
412
|
}
|
|
387
413
|
|
|
388
|
-
function
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
414
|
+
function _classCallCheck(instance, Constructor) {
|
|
415
|
+
if (!(instance instanceof Constructor)) {
|
|
416
|
+
throw new TypeError("Cannot call a class as a function");
|
|
417
|
+
}
|
|
418
|
+
}
|
|
392
419
|
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
420
|
+
function _defineProperties(target, props) {
|
|
421
|
+
for (var i = 0; i < props.length; i++) {
|
|
422
|
+
var descriptor = props[i];
|
|
423
|
+
descriptor.enumerable = descriptor.enumerable || false;
|
|
424
|
+
descriptor.configurable = true;
|
|
425
|
+
if ("value" in descriptor) descriptor.writable = true;
|
|
426
|
+
Object.defineProperty(target, descriptor.key, descriptor);
|
|
427
|
+
}
|
|
428
|
+
}
|
|
399
429
|
|
|
400
|
-
|
|
401
|
-
|
|
430
|
+
function _createClass(Constructor, protoProps, staticProps) {
|
|
431
|
+
if (protoProps) _defineProperties(Constructor.prototype, protoProps);
|
|
432
|
+
if (staticProps) _defineProperties(Constructor, staticProps);
|
|
433
|
+
Object.defineProperty(Constructor, "prototype", {
|
|
434
|
+
writable: false
|
|
435
|
+
});
|
|
436
|
+
return Constructor;
|
|
437
|
+
}
|
|
402
438
|
|
|
403
|
-
|
|
439
|
+
function _defineProperty(obj, key, value) {
|
|
440
|
+
if (key in obj) {
|
|
441
|
+
Object.defineProperty(obj, key, {
|
|
442
|
+
value: value,
|
|
443
|
+
enumerable: true,
|
|
444
|
+
configurable: true,
|
|
445
|
+
writable: true
|
|
446
|
+
});
|
|
447
|
+
} else {
|
|
448
|
+
obj[key] = value;
|
|
449
|
+
}
|
|
450
|
+
|
|
451
|
+
return obj;
|
|
404
452
|
}
|
|
405
453
|
|
|
406
454
|
/******************************************************************************
|
|
@@ -436,137 +484,140 @@
|
|
|
436
484
|
var DragndropPlugin_1;
|
|
437
485
|
var DragndropPlugin = DragndropPlugin_1 = (_class = /*#__PURE__*/function () {
|
|
438
486
|
function DragndropPlugin() {
|
|
487
|
+
_classCallCheck(this, DragndropPlugin);
|
|
488
|
+
|
|
439
489
|
this.sceneGraphService = void 0;
|
|
440
490
|
this.renderingContext = void 0;
|
|
441
491
|
this.dragndropPluginOptions = void 0;
|
|
442
492
|
}
|
|
443
493
|
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
|
|
481
|
-
}
|
|
482
|
-
|
|
483
|
-
return _context.abrupt("return");
|
|
484
|
-
|
|
485
|
-
case 11:
|
|
486
|
-
droppableBelow = (elemBelow === null || elemBelow === void 0 ? void 0 : elemBelow.closest('[droppable=true]')) || null;
|
|
487
|
-
|
|
488
|
-
if (currentDroppable !== droppableBelow) {
|
|
489
|
-
if (currentDroppable) {
|
|
490
|
-
// null when we were not over a droppable before this event
|
|
491
|
-
// @see https://developer.mozilla.org/zh-CN/docs/Web/API/Document/dragleave_event
|
|
492
|
-
event.type = 'dragleave';
|
|
493
|
-
event.target = currentDroppable;
|
|
494
|
-
currentDroppable.dispatchEvent(event);
|
|
494
|
+
_createClass(DragndropPlugin, [{
|
|
495
|
+
key: "apply",
|
|
496
|
+
value: function apply(renderingService) {
|
|
497
|
+
var _this = this;
|
|
498
|
+
|
|
499
|
+
var document = this.renderingContext.root.ownerDocument;
|
|
500
|
+
var overlap = this.dragndropPluginOptions.overlap;
|
|
501
|
+
|
|
502
|
+
var handlePointerdown = function handlePointerdown(event) {
|
|
503
|
+
var target = event.target;
|
|
504
|
+
|
|
505
|
+
if (target.getAttribute('draggable')) {
|
|
506
|
+
// @ts-ignore
|
|
507
|
+
var onMouseMove = /*#__PURE__*/function () {
|
|
508
|
+
var _ref = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee(event) {
|
|
509
|
+
var pointerEventsOldValue, point, elemBelow, droppableBelow;
|
|
510
|
+
return _regeneratorRuntime().wrap(function _callee$(_context) {
|
|
511
|
+
while (1) {
|
|
512
|
+
switch (_context.prev = _context.next) {
|
|
513
|
+
case 0:
|
|
514
|
+
// @see https://developer.mozilla.org/zh-CN/docs/Web/API/Document/drag_event
|
|
515
|
+
event.type = 'drag';
|
|
516
|
+
target.dispatchEvent(event); // prevent from picking the dragging element
|
|
517
|
+
|
|
518
|
+
pointerEventsOldValue = target.style.pointerEvents;
|
|
519
|
+
target.style.pointerEvents = 'none';
|
|
520
|
+
point = overlap === 'pointer' ? [event.canvasX, event.canvasY] : target.getBounds().center;
|
|
521
|
+
_context.next = 7;
|
|
522
|
+
return document.elementFromPoint(point[0], point[1]);
|
|
523
|
+
|
|
524
|
+
case 7:
|
|
525
|
+
elemBelow = _context.sent;
|
|
526
|
+
target.style.pointerEvents = pointerEventsOldValue;
|
|
527
|
+
|
|
528
|
+
if (elemBelow) {
|
|
529
|
+
_context.next = 11;
|
|
530
|
+
break;
|
|
495
531
|
}
|
|
496
532
|
|
|
497
|
-
|
|
498
|
-
|
|
499
|
-
|
|
500
|
-
|
|
501
|
-
|
|
533
|
+
return _context.abrupt("return");
|
|
534
|
+
|
|
535
|
+
case 11:
|
|
536
|
+
droppableBelow = (elemBelow === null || elemBelow === void 0 ? void 0 : elemBelow.closest('[droppable=true]')) || null;
|
|
537
|
+
|
|
538
|
+
if (currentDroppable !== droppableBelow) {
|
|
539
|
+
if (currentDroppable) {
|
|
540
|
+
// null when we were not over a droppable before this event
|
|
541
|
+
// @see https://developer.mozilla.org/zh-CN/docs/Web/API/Document/dragleave_event
|
|
542
|
+
event.type = 'dragleave';
|
|
543
|
+
event.target = currentDroppable;
|
|
544
|
+
currentDroppable.dispatchEvent(event);
|
|
545
|
+
}
|
|
546
|
+
|
|
547
|
+
if (droppableBelow) {
|
|
548
|
+
// @see https://developer.mozilla.org/zh-CN/docs/Web/API/Document/dragleave_event
|
|
549
|
+
event.type = 'dragenter';
|
|
550
|
+
event.target = droppableBelow;
|
|
551
|
+
droppableBelow.dispatchEvent(event);
|
|
552
|
+
}
|
|
553
|
+
|
|
554
|
+
currentDroppable = droppableBelow;
|
|
555
|
+
|
|
556
|
+
if (currentDroppable) {
|
|
557
|
+
// null if we're not coming over a droppable now
|
|
558
|
+
// @see https://developer.mozilla.org/zh-CN/docs/Web/API/Document/dragover_event
|
|
559
|
+
event.type = 'dragover';
|
|
560
|
+
event.target = currentDroppable;
|
|
561
|
+
currentDroppable.dispatchEvent(event);
|
|
562
|
+
}
|
|
502
563
|
}
|
|
503
564
|
|
|
504
|
-
|
|
565
|
+
case 13:
|
|
566
|
+
case "end":
|
|
567
|
+
return _context.stop();
|
|
568
|
+
}
|
|
569
|
+
}
|
|
570
|
+
}, _callee);
|
|
571
|
+
}));
|
|
505
572
|
|
|
506
|
-
|
|
507
|
-
|
|
508
|
-
|
|
509
|
-
|
|
510
|
-
event.target = currentDroppable;
|
|
511
|
-
currentDroppable.dispatchEvent(event);
|
|
512
|
-
}
|
|
513
|
-
}
|
|
573
|
+
return function onMouseMove(_x) {
|
|
574
|
+
return _ref.apply(this, arguments);
|
|
575
|
+
};
|
|
576
|
+
}();
|
|
514
577
|
|
|
515
|
-
|
|
516
|
-
|
|
517
|
-
return _context.stop();
|
|
518
|
-
}
|
|
519
|
-
}
|
|
520
|
-
}, _callee);
|
|
521
|
-
}));
|
|
522
|
-
|
|
523
|
-
return function onMouseMove(_x) {
|
|
524
|
-
return _ref.apply(this, arguments);
|
|
525
|
-
};
|
|
526
|
-
}();
|
|
527
|
-
|
|
528
|
-
// @see https://developer.mozilla.org/zh-CN/docs/Web/API/Document/dragstart_event
|
|
529
|
-
event.type = 'dragstart';
|
|
530
|
-
target.dispatchEvent(event);
|
|
531
|
-
var currentDroppable = null;
|
|
532
|
-
document.addEventListener('pointermove', onMouseMove);
|
|
533
|
-
target.addEventListener('pointerup', function () {
|
|
534
|
-
// @see https://developer.mozilla.org/zh-CN/docs/Web/API/Document/dragend_event
|
|
535
|
-
event.type = 'dragend';
|
|
578
|
+
// @see https://developer.mozilla.org/zh-CN/docs/Web/API/Document/dragstart_event
|
|
579
|
+
event.type = 'dragstart';
|
|
536
580
|
target.dispatchEvent(event);
|
|
581
|
+
var currentDroppable = null;
|
|
582
|
+
document.addEventListener('pointermove', onMouseMove);
|
|
583
|
+
target.addEventListener('pointerup', function () {
|
|
584
|
+
// @see https://developer.mozilla.org/zh-CN/docs/Web/API/Document/dragend_event
|
|
585
|
+
event.type = 'dragend';
|
|
586
|
+
target.dispatchEvent(event);
|
|
587
|
+
|
|
588
|
+
if (currentDroppable) {
|
|
589
|
+
// @see https://developer.mozilla.org/zh-CN/docs/Web/API/Document/drop_event
|
|
590
|
+
event.type = 'drop';
|
|
591
|
+
event.target = currentDroppable;
|
|
592
|
+
currentDroppable.dispatchEvent(event);
|
|
593
|
+
}
|
|
537
594
|
|
|
538
|
-
|
|
539
|
-
|
|
540
|
-
|
|
541
|
-
|
|
542
|
-
|
|
543
|
-
|
|
544
|
-
|
|
545
|
-
document.removeEventListener('pointermove', onMouseMove);
|
|
546
|
-
}, {
|
|
547
|
-
once: true
|
|
548
|
-
});
|
|
549
|
-
}
|
|
550
|
-
};
|
|
595
|
+
document.removeEventListener('pointermove', onMouseMove);
|
|
596
|
+
}, {
|
|
597
|
+
once: true
|
|
598
|
+
});
|
|
599
|
+
}
|
|
600
|
+
};
|
|
551
601
|
|
|
552
|
-
|
|
553
|
-
|
|
554
|
-
|
|
555
|
-
|
|
556
|
-
|
|
557
|
-
|
|
602
|
+
renderingService.hooks.init.tapPromise(DragndropPlugin_1.tag, /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee2() {
|
|
603
|
+
return _regeneratorRuntime().wrap(function _callee2$(_context2) {
|
|
604
|
+
while (1) {
|
|
605
|
+
switch (_context2.prev = _context2.next) {
|
|
606
|
+
case 0:
|
|
607
|
+
_this.renderingContext.root.addEventListener('pointerdown', handlePointerdown);
|
|
558
608
|
|
|
559
|
-
|
|
560
|
-
|
|
561
|
-
|
|
609
|
+
case 1:
|
|
610
|
+
case "end":
|
|
611
|
+
return _context2.stop();
|
|
612
|
+
}
|
|
562
613
|
}
|
|
563
|
-
}
|
|
564
|
-
}
|
|
565
|
-
|
|
566
|
-
|
|
567
|
-
|
|
568
|
-
}
|
|
569
|
-
};
|
|
614
|
+
}, _callee2);
|
|
615
|
+
})));
|
|
616
|
+
renderingService.hooks.destroy.tap(DragndropPlugin_1.tag, function () {
|
|
617
|
+
_this.renderingContext.root.removeEventListener('pointerdown', handlePointerdown);
|
|
618
|
+
});
|
|
619
|
+
}
|
|
620
|
+
}]);
|
|
570
621
|
|
|
571
622
|
return DragndropPlugin;
|
|
572
623
|
}(), _class.tag = 'Dragndrop', _class);
|
|
@@ -585,31 +636,33 @@
|
|
|
585
636
|
register(DragndropPlugin);
|
|
586
637
|
});
|
|
587
638
|
var Plugin = /*#__PURE__*/function () {
|
|
588
|
-
function Plugin(
|
|
589
|
-
|
|
590
|
-
|
|
591
|
-
|
|
639
|
+
function Plugin() {
|
|
640
|
+
var options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
|
|
641
|
+
|
|
642
|
+
_classCallCheck(this, Plugin);
|
|
592
643
|
|
|
593
644
|
this.options = void 0;
|
|
594
645
|
this.name = 'dragndrop';
|
|
595
646
|
this.options = options;
|
|
596
647
|
}
|
|
597
648
|
|
|
598
|
-
|
|
599
|
-
|
|
600
|
-
|
|
601
|
-
|
|
602
|
-
|
|
603
|
-
|
|
604
|
-
|
|
605
|
-
|
|
606
|
-
|
|
607
|
-
|
|
608
|
-
|
|
609
|
-
|
|
610
|
-
container
|
|
611
|
-
|
|
612
|
-
|
|
649
|
+
_createClass(Plugin, [{
|
|
650
|
+
key: "init",
|
|
651
|
+
value: function init(container) {
|
|
652
|
+
container.register(DragndropPluginOptions, {
|
|
653
|
+
useValue: _objectSpread2({
|
|
654
|
+
overlap: 'pointer'
|
|
655
|
+
}, this.options)
|
|
656
|
+
});
|
|
657
|
+
container.load(containerModule, true);
|
|
658
|
+
}
|
|
659
|
+
}, {
|
|
660
|
+
key: "destroy",
|
|
661
|
+
value: function destroy(container) {
|
|
662
|
+
container.remove(DragndropPluginOptions);
|
|
663
|
+
container.unload(containerModule);
|
|
664
|
+
}
|
|
665
|
+
}]);
|
|
613
666
|
|
|
614
667
|
return Plugin;
|
|
615
668
|
}();
|
package/dist/index.umd.min.js
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
!function(t,e){"object"==typeof exports&&"undefined"!=typeof module?e(exports,require("mana-syringe"),require("@antv/g")):"function"==typeof define&&define.amd?define(["exports","mana-syringe","@antv/g"],e):e(((t="undefined"!=typeof globalThis?globalThis:t||self).G=t.G||{},t.G.Dragndrop={}),t.window.G.ManaSyringe,t.window.G)}(this,(function(t,e,r){"use strict";function n(){
|
|
1
|
+
!function(t,e){"object"==typeof exports&&"undefined"!=typeof module?e(exports,require("mana-syringe"),require("@antv/g")):"function"==typeof define&&define.amd?define(["exports","mana-syringe","@antv/g"],e):e(((t="undefined"!=typeof globalThis?globalThis:t||self).G=t.G||{},t.G.Dragndrop={}),t.window.G.ManaSyringe,t.window.G)}(this,(function(t,e,r){"use strict";function n(t,e){var r=Object.keys(t);if(Object.getOwnPropertySymbols){var n=Object.getOwnPropertySymbols(t);e&&(n=n.filter((function(e){return Object.getOwnPropertyDescriptor(t,e).enumerable}))),r.push.apply(r,n)}return r}function o(t){for(var e=1;arguments.length>e;e++){var r=null!=arguments[e]?arguments[e]:{};e%2?n(Object(r),!0).forEach((function(e){l(t,e,r[e])})):Object.getOwnPropertyDescriptors?Object.defineProperties(t,Object.getOwnPropertyDescriptors(r)):n(Object(r)).forEach((function(e){Object.defineProperty(t,e,Object.getOwnPropertyDescriptor(r,e))}))}return t}function i(){
|
|
2
2
|
/*! regenerator-runtime -- Copyright (c) 2014-present, Facebook, Inc. -- license (MIT): https://github.com/facebook/regenerator/blob/main/LICENSE */
|
|
3
|
-
n=function(){return t};var t={},e=Object.prototype,r=e.hasOwnProperty,o="function"==typeof Symbol?Symbol:{},i=o.iterator||"@@iterator",a=o.asyncIterator||"@@asyncIterator",c=o.toStringTag||"@@toStringTag";function u(t,e,r){return Object.defineProperty(t,e,{value:r,enumerable:!0,configurable:!0,writable:!0}),t[e]}try{u({},"")}catch(t){u=function(t,e,r){return t[e]=r}}function s(t,e,r,n){var o=Object.create((e&&e.prototype instanceof l?e:l).prototype),i=new O(n||[]);return o._invoke=function(t,e,r){var n="suspendedStart";return function(o,i){if("executing"===n)throw new Error("Generator is already running");if("completed"===n){if("throw"===o)throw i;return P()}for(r.method=o,r.arg=i;;){var a=r.delegate;if(a){var c=x(a,r);if(c){if(c===p)continue;return c}}if("next"===r.method)r.sent=r._sent=r.arg;else if("throw"===r.method){if("suspendedStart"===n)throw n="completed",r.arg;r.dispatchException(r.arg)}else"return"===r.method&&r.abrupt("return",r.arg);n="executing";var u=f(t,e,r);if("normal"===u.type){if(n=r.done?"completed":"suspendedYield",u.arg===p)continue;return{value:u.arg,done:r.done}}"throw"===u.type&&(n="completed",r.method="throw",r.arg=u.arg)}}}(t,r,i),o}function f(t,e,r){try{return{type:"normal",arg:t.call(e,r)}}catch(t){return{type:"throw",arg:t}}}t.wrap=s;var p={};function l(){}function h(){}function d(){}var v={};u(v,i,(function(){return this}));var y=Object.getPrototypeOf,g=y&&y(y(j([])));g&&g!==e&&r.call(g,i)&&(v=g);var m=d.prototype=l.prototype=Object.create(v);function w(t){["next","throw","return"].forEach((function(e){u(t,e,(function(t){return this._invoke(e,t)}))}))}function b(t,e){function n(o,i,a,c){var u=f(t[o],t,i);if("throw"!==u.type){var s=u.arg,p=s.value;return p&&"object"==typeof p&&r.call(p,"__await")?e.resolve(p.__await).then((function(t){n("next",t,a,c)}),(function(t){n("throw",t,a,c)})):e.resolve(p).then((function(t){s.value=t,a(s)}),(function(t){return n("throw",t,a,c)}))}c(u.arg)}var o;this._invoke=function(t,r){function i(){return new e((function(e,o){n(t,r,e,o)}))}return o=o?o.then(i,i):i()}}function x(t,e){var r=t.iterator[e.method];if(void 0===r){if(e.delegate=null,"throw"===e.method){if(t.iterator.return&&(e.method="return",e.arg=void 0,x(t,e),"throw"===e.method))return p;e.method="throw",e.arg=new TypeError("The iterator does not provide a 'throw' method")}return p}var n=f(r,t.iterator,e.arg);if("throw"===n.type)return e.method="throw",e.arg=n.arg,e.delegate=null,p;var o=n.arg;return o?o.done?(e[t.resultName]=o.value,e.next=t.nextLoc,"return"!==e.method&&(e.method="next",e.arg=void 0),e.delegate=null,p):o:(e.method="throw",e.arg=new TypeError("iterator result is not an object"),e.delegate=null,p)}function E(t){var e={tryLoc:t[0]};1 in t&&(e.catchLoc=t[1]),2 in t&&(e.finallyLoc=t[2],e.afterLoc=t[3]),this.tryEntries.push(e)}function L(t){var e=t.completion||{};e.type="normal",delete e.arg,t.completion=e}function O(t){this.tryEntries=[{tryLoc:"root"}],t.forEach(E,this),this.reset(!0)}function j(t){if(t){var e=t[i];if(e)return e.call(t);if("function"==typeof t.next)return t;if(!isNaN(t.length)){var n=-1,o=function e(){for(;++n<t.length;)if(r.call(t,n))return e.value=t[n],e.done=!1,e;return e.value=void 0,e.done=!0,e};return o.next=o}}return{next:P}}function P(){return{value:void 0,done:!0}}return h.prototype=d,u(m,"constructor",d),u(d,"constructor",h),h.displayName=u(d,c,"GeneratorFunction"),t.isGeneratorFunction=function(t){var e="function"==typeof t&&t.constructor;return!!e&&(e===h||"GeneratorFunction"===(e.displayName||e.name))},t.mark=function(t){return Object.setPrototypeOf?Object.setPrototypeOf(t,d):(t.__proto__=d,u(t,c,"GeneratorFunction")),t.prototype=Object.create(m),t},t.awrap=function(t){return{__await:t}},w(b.prototype),u(b.prototype,a,(function(){return this})),t.AsyncIterator=b,t.async=function(e,r,n,o,i){void 0===i&&(i=Promise);var a=new b(s(e,r,n,o),i);return t.isGeneratorFunction(r)?a:a.next().then((function(t){return t.done?t.value:a.next()}))},w(m),u(m,c,"Generator"),u(m,i,(function(){return this})),u(m,"toString",(function(){return"[object Generator]"})),t.keys=function(t){var e=[];for(var r in t)e.push(r);return e.reverse(),function r(){for(;e.length;){var n=e.pop();if(n in t)return r.value=n,r.done=!1,r}return r.done=!0,r}},t.values=j,O.prototype={constructor:O,reset:function(t){if(this.prev=0,this.next=0,this.sent=this._sent=void 0,this.done=!1,this.delegate=null,this.method="next",this.arg=void 0,this.tryEntries.forEach(L),!t)for(var e in this)"t"===e.charAt(0)&&r.call(this,e)&&!isNaN(+e.slice(1))&&(this[e]=void 0)},stop:function(){this.done=!0;var t=this.tryEntries[0].completion;if("throw"===t.type)throw t.arg;return this.rval},dispatchException:function(t){if(this.done)throw t;var e=this;function n(r,n){return a.type="throw",a.arg=t,e.next=r,n&&(e.method="next",e.arg=void 0),!!n}for(var o=this.tryEntries.length-1;o>=0;--o){var i=this.tryEntries[o],a=i.completion;if("root"===i.tryLoc)return n("end");if(this.prev>=i.tryLoc){var c=r.call(i,"catchLoc"),u=r.call(i,"finallyLoc");if(c&&u){if(i.catchLoc>this.prev)return n(i.catchLoc,!0);if(i.finallyLoc>this.prev)return n(i.finallyLoc)}else if(c){if(i.catchLoc>this.prev)return n(i.catchLoc,!0)}else{if(!u)throw new Error("try statement without catch or finally");if(i.finallyLoc>this.prev)return n(i.finallyLoc)}}}},abrupt:function(t,e){for(var n=this.tryEntries.length-1;n>=0;--n){var o=this.tryEntries[n];if(this.prev>=o.tryLoc&&r.call(o,"finallyLoc")&&o.finallyLoc>this.prev){var i=o;break}}i&&("break"===t||"continue"===t)&&e>=i.tryLoc&&i.finallyLoc>=e&&(i=null);var a=i?i.completion:{};return a.type=t,a.arg=e,i?(this.method="next",this.next=i.finallyLoc,p):this.complete(a)},complete:function(t,e){if("throw"===t.type)throw t.arg;return"break"===t.type||"continue"===t.type?this.next=t.arg:"return"===t.type?(this.rval=this.arg=t.arg,this.method="return",this.next="end"):"normal"===t.type&&e&&(this.next=e),p},finish:function(t){for(var e=this.tryEntries.length-1;e>=0;--e){var r=this.tryEntries[e];if(r.finallyLoc===t)return this.complete(r.completion,r.afterLoc),L(r),p}},catch:function(t){for(var e=this.tryEntries.length-1;e>=0;--e){var r=this.tryEntries[e];if(r.tryLoc===t){var n=r.completion;if("throw"===n.type){var o=n.arg;L(r)}return o}}throw new Error("illegal catch attempt")},delegateYield:function(t,e,r){return this.delegate={iterator:j(t),resultName:e,nextLoc:r},"next"===this.method&&(this.arg=void 0),p}},t}function o(t,e,r,n,o,i,a){try{var c=t[i](a),u=c.value}catch(t){return void r(t)}c.done?e(u):Promise.resolve(u).then(n,o)}function i(t){return function(){var e=this,r=arguments;return new Promise((function(n,i){var a=t.apply(e,r);function c(t){o(a,n,i,c,u,"next",t)}function u(t){o(a,n,i,c,u,"throw",t)}c(void 0)}))}}function a(){return a=Object.assign||function(t){for(var e=1;arguments.length>e;e++){var r=arguments[e];for(var n in r)Object.prototype.hasOwnProperty.call(r,n)&&(t[n]=r[n])}return t},a.apply(this,arguments)}function c(t,e,r,n){var o,i=arguments.length,a=3>i?e:null===n?n=Object.getOwnPropertyDescriptor(e,r):n;if("object"==typeof Reflect&&"function"==typeof Reflect.decorate)a=Reflect.decorate(t,e,r,n);else for(var c=t.length-1;c>=0;c--)(o=t[c])&&(a=(3>i?o(a):i>3?o(e,r,a):o(e,r))||a);return i>3&&a&&Object.defineProperty(e,r,a),a}function u(t,e){if("object"==typeof Reflect&&"function"==typeof Reflect.metadata)return Reflect.metadata(t,e)}var s,f,p=e.Syringe.defineToken("DragndropPluginOptions"),l=(s=function(){function t(){this.sceneGraphService=void 0,this.renderingContext=void 0,this.dragndropPluginOptions=void 0}return t.prototype.apply=function(t){var e=this,r=this.renderingContext.root.ownerDocument,o=this.dragndropPluginOptions.overlap,a=function(t){var e=t.target;if(e.getAttribute("draggable")){var a=function(){var t=i(n().mark((function t(i){var a,u,s,f;return n().wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return i.type="drag",e.dispatchEvent(i),a=e.style.pointerEvents,e.style.pointerEvents="none",u="pointer"===o?[i.canvasX,i.canvasY]:e.getBounds().center,t.next=7,r.elementFromPoint(u[0],u[1]);case 7:if(s=t.sent,e.style.pointerEvents=a,s){t.next=11;break}return t.abrupt("return");case 11:f=(null==s?void 0:s.closest("[droppable=true]"))||null,c!==f&&(c&&(i.type="dragleave",i.target=c,c.dispatchEvent(i)),f&&(i.type="dragenter",i.target=f,f.dispatchEvent(i)),(c=f)&&(i.type="dragover",i.target=c,c.dispatchEvent(i)));case 13:case"end":return t.stop()}}),t)})));return function(e){return t.apply(this,arguments)}}();t.type="dragstart",e.dispatchEvent(t);var c=null;r.addEventListener("pointermove",a),e.addEventListener("pointerup",(function(){t.type="dragend",e.dispatchEvent(t),c&&(t.type="drop",t.target=c,c.dispatchEvent(t)),r.removeEventListener("pointermove",a)}),{once:!0})}};t.hooks.init.tapPromise(f.tag,i(n().mark((function t(){return n().wrap((function(t){for(;;)switch(t.prev=t.next){case 0:e.renderingContext.root.addEventListener("pointerdown",a);case 1:case"end":return t.stop()}}),t)})))),t.hooks.destroy.tap(f.tag,(function(){e.renderingContext.root.removeEventListener("pointerdown",a)}))},t}(),s.tag="Dragndrop",f=s);c([e.inject(r.SceneGraphService),u("design:type",Object)],l.prototype,"sceneGraphService",void 0),c([e.inject(r.RenderingContext),u("design:type",Object)],l.prototype,"renderingContext",void 0),c([e.inject(p),u("design:type",Object)],l.prototype,"dragndropPluginOptions",void 0),l=f=c([e.singleton({contrib:r.RenderingPluginContribution})],l);var h=e.Module((function(t){t(l)}));t.Plugin=function(){function t(t){void 0===t&&(t={}),this.options=void 0,this.name="dragndrop",this.options=t}var e=t.prototype;return e.init=function(t){t.register(p,{useValue:a({overlap:"pointer"},this.options)}),t.load(h,!0)},e.destroy=function(t){t.remove(p),t.unload(h)},t}(),Object.defineProperty(t,"__esModule",{value:!0})}));
|
|
3
|
+
i=function(){return t};var t={},e=Object.prototype,r=e.hasOwnProperty,n="function"==typeof Symbol?Symbol:{},o=n.iterator||"@@iterator",a=n.asyncIterator||"@@asyncIterator",c=n.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 j(n||[]);return o._invoke=function(t,e,r){var n="suspendedStart";return function(o,i){if("executing"===n)throw 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=O(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,o,(function(){return this}));var y=Object.getPrototypeOf,g=y&&y(y(L([])));g&&g!==e&&r.call(g,o)&&(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 n(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&&r.call(l,"__await")?e.resolve(l.__await).then((function(t){n("next",t,a,c)}),(function(t){n("throw",t,a,c)})):e.resolve(l).then((function(t){s.value=t,a(s)}),(function(t){return n("throw",t,a,c)}))}c(u.arg)}var o;this._invoke=function(t,r){function i(){return new e((function(e,o){n(t,r,e,o)}))}return o=o?o.then(i,i):i()}}function O(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,O(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 x(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 E(t){var e=t.completion||{};e.type="normal",delete e.arg,t.completion=e}function j(t){this.tryEntries=[{tryLoc:"root"}],t.forEach(x,this),this.reset(!0)}function L(t){if(t){var e=t[o];if(e)return e.call(t);if("function"==typeof t.next)return t;if(!isNaN(t.length)){var n=-1,i=function e(){for(;++n<t.length;)if(r.call(t,n))return e.value=t[n],e.done=!1,e;return e.value=void 0,e.done=!0,e};return i.next=i}}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,o,(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=L,j.prototype={constructor:j,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(E),!t)for(var e in this)"t"===e.charAt(0)&&r.call(this,e)&&!isNaN(+e.slice(1))&&(this[e]=void 0)},stop:function(){this.done=!0;var t=this.tryEntries[0].completion;if("throw"===t.type)throw t.arg;return this.rval},dispatchException:function(t){if(this.done)throw t;var e=this;function n(r,n){return a.type="throw",a.arg=t,e.next=r,n&&(e.method="next",e.arg=void 0),!!n}for(var o=this.tryEntries.length-1;o>=0;--o){var i=this.tryEntries[o],a=i.completion;if("root"===i.tryLoc)return n("end");if(this.prev>=i.tryLoc){var c=r.call(i,"catchLoc"),u=r.call(i,"finallyLoc");if(c&&u){if(i.catchLoc>this.prev)return n(i.catchLoc,!0);if(i.finallyLoc>this.prev)return n(i.finallyLoc)}else if(c){if(i.catchLoc>this.prev)return n(i.catchLoc,!0)}else{if(!u)throw Error("try statement without catch or finally");if(i.finallyLoc>this.prev)return n(i.finallyLoc)}}}},abrupt:function(t,e){for(var n=this.tryEntries.length-1;n>=0;--n){var o=this.tryEntries[n];if(this.prev>=o.tryLoc&&r.call(o,"finallyLoc")&&o.finallyLoc>this.prev){var i=o;break}}i&&("break"===t||"continue"===t)&&e>=i.tryLoc&&i.finallyLoc>=e&&(i=null);var a=i?i.completion:{};return a.type=t,a.arg=e,i?(this.method="next",this.next=i.finallyLoc,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),E(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;E(r)}return o}}throw Error("illegal catch attempt")},delegateYield:function(t,e,r){return this.delegate={iterator:L(t),resultName:e,nextLoc:r},"next"===this.method&&(this.arg=void 0),l}},t}function a(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 c(t){return function(){var e=this,r=arguments;return new Promise((function(n,o){var i=t.apply(e,r);function c(t){a(i,n,o,c,u,"next",t)}function u(t){a(i,n,o,c,u,"throw",t)}c(void 0)}))}}function u(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}function s(t,e){for(var r=0;e.length>r;r++){var n=e[r];n.enumerable=n.enumerable||!1,n.configurable=!0,"value"in n&&(n.writable=!0),Object.defineProperty(t,n.key,n)}}function f(t,e,r){return e&&s(t.prototype,e),r&&s(t,r),Object.defineProperty(t,"prototype",{writable:!1}),t}function l(t,e,r){return e in t?Object.defineProperty(t,e,{value:r,enumerable:!0,configurable:!0,writable:!0}):t[e]=r,t}function p(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 h(t,e){if("object"==typeof Reflect&&"function"==typeof Reflect.metadata)return Reflect.metadata(t,e)}var d,v,y=e.Syringe.defineToken("DragndropPluginOptions"),g=(d=function(){function t(){u(this,t),this.sceneGraphService=void 0,this.renderingContext=void 0,this.dragndropPluginOptions=void 0}return f(t,[{key:"apply",value:function(t){var e=this,r=this.renderingContext.root.ownerDocument,n=this.dragndropPluginOptions.overlap,o=function(t){var e=t.target;if(e.getAttribute("draggable")){var o=function(){var t=c(i().mark((function t(o){var c,u,s,f;return i().wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return o.type="drag",e.dispatchEvent(o),c=e.style.pointerEvents,e.style.pointerEvents="none",u="pointer"===n?[o.canvasX,o.canvasY]:e.getBounds().center,t.next=7,r.elementFromPoint(u[0],u[1]);case 7:if(s=t.sent,e.style.pointerEvents=c,s){t.next=11;break}return t.abrupt("return");case 11:f=(null==s?void 0:s.closest("[droppable=true]"))||null,a!==f&&(a&&(o.type="dragleave",o.target=a,a.dispatchEvent(o)),f&&(o.type="dragenter",o.target=f,f.dispatchEvent(o)),(a=f)&&(o.type="dragover",o.target=a,a.dispatchEvent(o)));case 13:case"end":return t.stop()}}),t)})));return function(e){return t.apply(this,arguments)}}();t.type="dragstart",e.dispatchEvent(t);var a=null;r.addEventListener("pointermove",o),e.addEventListener("pointerup",(function(){t.type="dragend",e.dispatchEvent(t),a&&(t.type="drop",t.target=a,a.dispatchEvent(t)),r.removeEventListener("pointermove",o)}),{once:!0})}};t.hooks.init.tapPromise(v.tag,c(i().mark((function t(){return i().wrap((function(t){for(;;)switch(t.prev=t.next){case 0:e.renderingContext.root.addEventListener("pointerdown",o);case 1:case"end":return t.stop()}}),t)})))),t.hooks.destroy.tap(v.tag,(function(){e.renderingContext.root.removeEventListener("pointerdown",o)}))}}]),t}(),d.tag="Dragndrop",v=d);p([e.inject(r.SceneGraphService),h("design:type",Object)],g.prototype,"sceneGraphService",void 0),p([e.inject(r.RenderingContext),h("design:type",Object)],g.prototype,"renderingContext",void 0),p([e.inject(y),h("design:type",Object)],g.prototype,"dragndropPluginOptions",void 0),g=v=p([e.singleton({contrib:r.RenderingPluginContribution})],g);var m=e.Module((function(t){t(g)})),w=function(){function t(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};u(this,t),this.options=void 0,this.name="dragndrop",this.options=e}return f(t,[{key:"init",value:function(t){t.register(y,{useValue:o({overlap:"pointer"},this.options)}),t.load(m,!0)}},{key:"destroy",value:function(t){t.remove(y),t.unload(m)}}]),t}();t.Plugin=w,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.0.
|
|
3
|
+
"version": "1.0.3",
|
|
4
4
|
"description": "A G plugin for Drag n Drop implemented with PointerEvents",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"antv",
|
|
@@ -39,5 +39,5 @@
|
|
|
39
39
|
"publishConfig": {
|
|
40
40
|
"access": "public"
|
|
41
41
|
},
|
|
42
|
-
"gitHead": "
|
|
42
|
+
"gitHead": "ee946c7c12c90946c37926b34ee5165bf0c35f25"
|
|
43
43
|
}
|