dragselect 2.1.2 → 2.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,6 +1,6 @@
1
1
  /***
2
2
 
3
- ~~~ Version 2.1.2 ~~~
3
+ ~~~ Version 2.3.0 ~~~
4
4
 
5
5
  ******************************************
6
6
 
@@ -66,6 +66,40 @@ function _defineProperty(obj, key, value) {
66
66
  return obj;
67
67
  }
68
68
 
69
+ function ownKeys(object, enumerableOnly) {
70
+ var keys = Object.keys(object);
71
+
72
+ if (Object.getOwnPropertySymbols) {
73
+ var symbols = Object.getOwnPropertySymbols(object);
74
+ if (enumerableOnly) symbols = symbols.filter(function (sym) {
75
+ return Object.getOwnPropertyDescriptor(object, sym).enumerable;
76
+ });
77
+ keys.push.apply(keys, symbols);
78
+ }
79
+
80
+ return keys;
81
+ }
82
+
83
+ function _objectSpread2(target) {
84
+ for (var i = 1; i < arguments.length; i++) {
85
+ var source = arguments[i] != null ? arguments[i] : {};
86
+
87
+ if (i % 2) {
88
+ ownKeys(Object(source), true).forEach(function (key) {
89
+ _defineProperty(target, key, source[key]);
90
+ });
91
+ } else if (Object.getOwnPropertyDescriptors) {
92
+ Object.defineProperties(target, Object.getOwnPropertyDescriptors(source));
93
+ } else {
94
+ ownKeys(Object(source)).forEach(function (key) {
95
+ Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key));
96
+ });
97
+ }
98
+ }
99
+
100
+ return target;
101
+ }
102
+
69
103
  function _inherits(subClass, superClass) {
70
104
  if (typeof superClass !== "function" && superClass !== null) {
71
105
  throw new TypeError("Super expression must either be null or a function");
@@ -230,6 +264,10 @@ function _get(target, property, receiver) {
230
264
  return _get(target, property, receiver || target);
231
265
  }
232
266
 
267
+ function _slicedToArray(arr, i) {
268
+ return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest();
269
+ }
270
+
233
271
  function _toConsumableArray(arr) {
234
272
  return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _unsupportedIterableToArray(arr) || _nonIterableSpread();
235
273
  }
@@ -238,10 +276,41 @@ function _arrayWithoutHoles(arr) {
238
276
  if (Array.isArray(arr)) return _arrayLikeToArray(arr);
239
277
  }
240
278
 
279
+ function _arrayWithHoles(arr) {
280
+ if (Array.isArray(arr)) return arr;
281
+ }
282
+
241
283
  function _iterableToArray(iter) {
242
284
  if (typeof Symbol !== "undefined" && Symbol.iterator in Object(iter)) return Array.from(iter);
243
285
  }
244
286
 
287
+ function _iterableToArrayLimit(arr, i) {
288
+ if (typeof Symbol === "undefined" || !(Symbol.iterator in Object(arr))) return;
289
+ var _arr = [];
290
+ var _n = true;
291
+ var _d = false;
292
+ var _e = undefined;
293
+
294
+ try {
295
+ for (var _i = arr[Symbol.iterator](), _s; !(_n = (_s = _i.next()).done); _n = true) {
296
+ _arr.push(_s.value);
297
+
298
+ if (i && _arr.length === i) break;
299
+ }
300
+ } catch (err) {
301
+ _d = true;
302
+ _e = err;
303
+ } finally {
304
+ try {
305
+ if (!_n && _i["return"] != null) _i["return"]();
306
+ } finally {
307
+ if (_d) throw _e;
308
+ }
309
+ }
310
+
311
+ return _arr;
312
+ }
313
+
245
314
  function _unsupportedIterableToArray(o, minLen) {
246
315
  if (!o) return;
247
316
  if (typeof o === "string") return _arrayLikeToArray(o, minLen);
@@ -263,6 +332,10 @@ function _nonIterableSpread() {
263
332
  throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
264
333
  }
265
334
 
335
+ function _nonIterableRest() {
336
+ throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
337
+ }
338
+
266
339
  /**
267
340
  * The Settings to be passed to the Class
268
341
  * @typedef {Object} Settings
@@ -278,6 +351,7 @@ function _nonIterableSpread() {
278
351
  * @property {HTMLElement} [selector=HTMLElement] the square that will draw the selection
279
352
  * @property {boolean} [draggability=true] When a user is dragging on an already selected element, the selection is dragged.
280
353
  * @property {boolean} [immediateDrag=true] Whether an element is draggable from the start or needs to be selected first
354
+ * @property {boolean} [keyboardDrag=true] Whether or not the user can drag with the keyboard (we don't recommend disabling it)
281
355
  * @property {DSDragKeys} [dragKeys={up:['ArrowUp'],down:['ArrowDown'],left:['ArrowLeft'],righ:['ArrowRight']}] The keys available to drag element using the keyboard.
282
356
  * @property {number} [keyboardDragSpeed=10] The speed at which elements are dragged using the keyboard. In pixels per keydown.
283
357
  * @property {boolean} [useTransform=true] Whether to use hardware accelerated css transforms when dragging or top/left instead
@@ -298,9 +372,11 @@ function _nonIterableSpread() {
298
372
  * The Object that is passed back to any callback method
299
373
  * @typedef {Object} CallbackObject
300
374
  * @property {Array<HTMLElement|SVGElement|any>} [items] The items currently selected
301
- * @property {MouseEvent|TouchEvent|Event} [event] The respective event object
375
+ * @property {MouseEvent|TouchEvent|KeyboardEvent|Event} [event] The respective event object
302
376
  * @property {HTMLElement|SVGElement|any} [item] The single item currently interacted with
303
377
  * @property {boolean} [isDragging] Whether the interaction is a drag or a select
378
+ * @property {boolean} [isDraggingKeyboard] Whether or not the drag interaction is via keyboard
379
+ * @property {string} [key] Pressed key (lowercase)
304
380
  * @property {Array.<'top'|'bottom'|'left'|'right'|undefined>} [scroll_directions]
305
381
  * @property {number} [scroll_multiplier]
306
382
  */
@@ -334,7 +410,9 @@ function _nonIterableSpread() {
334
410
 
335
411
  /** @typedef {'Interaction:init'|'Interaction:start'|'Interaction:end'|'Interaction:update'|'Area:modified'|'Area:scroll'|'PointerStore:updated'|'Selected:added'|'Selected:removed'|'Selectable:click'|'Selectable:pointer'|'KeyStore:down'|'KeyStore:up'} DSInternalEventNames */
336
412
 
337
- /** @typedef {DSEventNames|DSInternalEventNames} DSCallbackNames the name of the callback */
413
+ /** @typedef {'Interaction:init:pre'|'Interaction:start:pre'|'Interaction:end:pre'|'Interaction:update:pre'|'Area:modified:pre'|'Area:scroll:pre'|'PointerStore:updated:pre'|'Selected:added:pre'|'Selected:removed:pre'|'Selectable:click:pre'|'Selectable:pointer:pre'|'KeyStore:down:pre'|'KeyStore:up:pre'} DSInternalEventNamesPre */
414
+
415
+ /** @typedef {DSEventNames|DSInternalEventNames|DSInternalEventNamesPre} DSCallbackNames the name of the callback */
338
416
 
339
417
  /** @typedef {{top:number,left:number,bottom:number,right:number,width:number,height:number}} DSBoundingRect */
340
418
 
@@ -1125,6 +1203,84 @@ var setStylePosition = (function (element, values, useTranslate) {
1125
1203
  return element;
1126
1204
  });
1127
1205
 
1206
+ /**
1207
+ * @typedef {function} DSSubscribe
1208
+ * @param {DSCallbackNames} eventName
1209
+ * @param {DSCallback} callback
1210
+ * @returns {number} event id, can be used to unsubscribe more efficiently
1211
+ */
1212
+
1213
+ /**
1214
+ * @typedef {function} DSPublish
1215
+ * @param {DSCallbackNames} eventName
1216
+ * @param {CallbackObject} data passed to the subscription method
1217
+ */
1218
+
1219
+ /**
1220
+ * Maps internal events to external ones
1221
+ *
1222
+ * @param {Object} p
1223
+ * @param {DSSubscribe} p.subscribe
1224
+ * @param {DSPublish} p.publish
1225
+ * @param {Interaction} p.Interaction
1226
+ * @param {SelectedSet} p.SelectedSet
1227
+ */
1228
+
1229
+ var subscriberAliases = (function (_ref) {
1230
+ var subscribe = _ref.subscribe,
1231
+ publish = _ref.publish,
1232
+ Interaction = _ref.Interaction,
1233
+ SelectedSet = _ref.SelectedSet;
1234
+ var mapping = {
1235
+ 'Selected:added': [{
1236
+ name: 'elementselect'
1237
+ }],
1238
+ 'Selected:removed': [{
1239
+ name: 'elementunselect'
1240
+ }],
1241
+ 'Area:scroll': [{
1242
+ name: 'autoscroll'
1243
+ }],
1244
+ // scroll_directions, scroll_multiplier
1245
+ 'Interaction:start': [{
1246
+ name: 'dragstart'
1247
+ }],
1248
+ // event, isDraggingKeyboard
1249
+ 'Interaction:update': [{
1250
+ name: 'dragmove',
1251
+ condition: function condition(data) {
1252
+ return data.event;
1253
+ }
1254
+ }],
1255
+ // event, isDraggingKeyboard
1256
+ 'Interaction:end': [{
1257
+ name: 'callback'
1258
+ }] // event, isDraggingKeyboard
1259
+
1260
+ };
1261
+
1262
+ var _loop = function _loop() {
1263
+ var _Object$entries$_i = _slicedToArray(_Object$entries[_i], 2),
1264
+ sub_name = _Object$entries$_i[0],
1265
+ pubs = _Object$entries$_i[1];
1266
+
1267
+ ['pre', false].forEach(function (filler) {
1268
+ return subscribe(filler ? "".concat(sub_name, ":").concat(filler) : sub_name, function (data) {
1269
+ return pubs.forEach(function (pub) {
1270
+ return (!pub.condition || pub.condition(data)) && publish(filler ? "".concat(filler).concat(pub.name) : pub.name, _objectSpread2({
1271
+ items: SelectedSet.elements,
1272
+ isDragging: Interaction.isDragging
1273
+ }, data));
1274
+ });
1275
+ });
1276
+ });
1277
+ };
1278
+
1279
+ for (var _i = 0, _Object$entries = Object.entries(mapping); _i < _Object$entries.length; _i++) {
1280
+ _loop();
1281
+ }
1282
+ });
1283
+
1128
1284
  /**
1129
1285
  * Transforms any list or single item to an array so user doesn’t have to care.
1130
1286
  * @param {DSInputElements} items a single item, a Node-list or any element group
@@ -1152,6 +1308,13 @@ var updateElementStylePos = (function (element, pos) {
1152
1308
  element.style.height = "".concat(pos.height, "px");
1153
1309
  });
1154
1310
 
1311
+ /**
1312
+ * @typedef {Object} AreaProps
1313
+ * @property {DSArea} area
1314
+ * @property {PubSub} PS
1315
+ * @property {number} zoom
1316
+ */
1317
+
1155
1318
  var Area = /*#__PURE__*/function () {
1156
1319
  /**
1157
1320
  * @type {DSModificationCallback}
@@ -1195,16 +1358,13 @@ var Area = /*#__PURE__*/function () {
1195
1358
 
1196
1359
  /**
1197
1360
  * @constructor Area
1198
- * @param {Object} obj
1199
- * @param {DSArea} obj.area
1200
- * @param {PubSub} obj.PS
1201
- * @param {number} obj.zoom
1361
+ * @param {AreaProps} settings
1202
1362
  * @ignore
1203
1363
  */
1204
1364
  function Area(_ref) {
1205
1365
  var _this = this;
1206
1366
 
1207
- var area = _ref.area,
1367
+ var _area = _ref.area,
1208
1368
  PS = _ref.PS,
1209
1369
  zoom = _ref.zoom;
1210
1370
 
@@ -1226,6 +1386,26 @@ var Area = /*#__PURE__*/function () {
1226
1386
 
1227
1387
  _defineProperty(this, "_rect", void 0);
1228
1388
 
1389
+ _defineProperty(this, "setArea", function (area) {
1390
+ _this._node = area;
1391
+ handleElementPositionAttribute({
1392
+ computedStyle: _this.computedStyle,
1393
+ node: _this._node
1394
+ }); // first immediate debounce to update values after dom-update
1395
+
1396
+ setTimeout(function () {
1397
+ _this.PubSub.publish('Area:modified:pre', {
1398
+ item: _this
1399
+ });
1400
+
1401
+ _this.reset();
1402
+
1403
+ _this.PubSub.publish('Area:modified', {
1404
+ item: _this
1405
+ });
1406
+ });
1407
+ });
1408
+
1229
1409
  _defineProperty(this, "start", function () {
1230
1410
  addModificationObservers(_this.parentNodes, _this._modificationCallback, _this._modificationObserver);
1231
1411
  });
@@ -1244,42 +1424,40 @@ var Area = /*#__PURE__*/function () {
1244
1424
  });
1245
1425
 
1246
1426
  _defineProperty(this, "scroll", function (directions, multiplier) {
1247
- scrollElement(_this._node, directions, multiplier);
1248
-
1249
- _this.PubSub.publish('Area:scroll', {
1427
+ var data = {
1250
1428
  scroll_directions: directions,
1251
1429
  scroll_multiplier: multiplier
1252
- });
1430
+ };
1431
+
1432
+ _this.PubSub.publish('Area:scroll:pre', data);
1433
+
1434
+ scrollElement(_this._node, directions, multiplier);
1435
+
1436
+ _this.PubSub.publish('Area:scroll', data);
1253
1437
  });
1254
1438
 
1255
- this._node = area;
1256
1439
  this._zoom = zoom;
1257
1440
  this.PubSub = PS;
1258
- handleElementPositionAttribute({
1259
- computedStyle: this.computedStyle,
1260
- node: this._node
1261
- });
1441
+ this.setArea(_area);
1262
1442
  this._modificationCallback = debounce(function (event) {
1263
- _this.reset();
1264
-
1265
- _this.PubSub.publish('Area:modified', {
1443
+ _this.PubSub.publish('Area:modified:pre', {
1266
1444
  event: event,
1267
1445
  item: _this
1268
1446
  });
1269
- }, 60);
1270
- this._modificationObserver = new MutationObserver(this._modificationCallback); // first immediate debounce to update values after dom-update
1271
1447
 
1272
- setTimeout(function () {
1273
1448
  _this.reset();
1274
1449
 
1275
1450
  _this.PubSub.publish('Area:modified', {
1276
1451
  event: event,
1277
1452
  item: _this
1278
1453
  });
1279
- });
1454
+ }, 60);
1455
+ this._modificationObserver = new MutationObserver(this._modificationCallback);
1280
1456
  this.PubSub.subscribe('Interaction:init', this.start);
1281
1457
  this.PubSub.subscribe('Interaction:end', this.reset);
1282
1458
  }
1459
+ /** @param {DSArea} area */
1460
+
1283
1461
 
1284
1462
  _createClass(Area, [{
1285
1463
  key: "HTMLNode",
@@ -1393,6 +1571,11 @@ var Drag = /*#__PURE__*/function () {
1393
1571
  * @private
1394
1572
  */
1395
1573
 
1574
+ /**
1575
+ * @type {boolean}
1576
+ * @private
1577
+ */
1578
+
1396
1579
  /**
1397
1580
  * @type {number}
1398
1581
  * @private
@@ -1409,6 +1592,7 @@ var Drag = /*#__PURE__*/function () {
1409
1592
  * @param {boolean} p.draggability
1410
1593
  * @param {boolean} p.useTransform
1411
1594
  * @param {DSDragKeys} p.dragKeys
1595
+ * @param {boolean} p.keyboardDrag
1412
1596
  * @param {number} p.keyboardDragSpeed
1413
1597
  * @param {number} p.zoom
1414
1598
  * @ignore
@@ -1419,6 +1603,7 @@ var Drag = /*#__PURE__*/function () {
1419
1603
  var DS = _ref.DS,
1420
1604
  dragKeys = _ref.dragKeys,
1421
1605
  draggability = _ref.draggability,
1606
+ keyboardDrag = _ref.keyboardDrag,
1422
1607
  keyboardDragSpeed = _ref.keyboardDragSpeed,
1423
1608
  useTransform = _ref.useTransform,
1424
1609
  zoom = _ref.zoom;
@@ -1439,6 +1624,8 @@ var Drag = /*#__PURE__*/function () {
1439
1624
 
1440
1625
  _defineProperty(this, "_dragKeysFlat", void 0);
1441
1626
 
1627
+ _defineProperty(this, "_keyboardDrag", void 0);
1628
+
1442
1629
  _defineProperty(this, "_keyboardDragSpeed", void 0);
1443
1630
 
1444
1631
  _defineProperty(this, "_zoom", void 0);
@@ -1446,14 +1633,14 @@ var Drag = /*#__PURE__*/function () {
1446
1633
  _defineProperty(this, "keyboardDrag", function (_ref2) {
1447
1634
  var event = _ref2.event,
1448
1635
  key = _ref2.key;
1449
- console.log(event, key, _this._draggability);
1450
- if (!_this._dragKeysFlat.includes(key) || !_this.DS.SelectedSet.size || !_this._draggability) return;
1451
- _this._isKeyboard = true;
1452
-
1453
- _this.DS.publish('Interaction:start', {
1636
+ if (!_this._keyboardDrag || !_this._dragKeysFlat.includes(key) || !_this.DS.SelectedSet.size || !_this._draggability || _this.DS["continue"]) return;
1637
+ var publishData = {
1454
1638
  event: event,
1455
- isDragging: true
1456
- });
1639
+ isDragging: true,
1640
+ isDraggingKeyboard: true
1641
+ };
1642
+
1643
+ _this.DS.publish(['Interaction:start:pre', 'Interaction:start'], publishData);
1457
1644
 
1458
1645
  _this._elements = _this.DS.getSelection();
1459
1646
 
@@ -1479,31 +1666,26 @@ var Drag = /*#__PURE__*/function () {
1479
1666
  });
1480
1667
  });
1481
1668
 
1482
- _this.DS.publish('Interaction:update', {
1483
- event: event,
1484
- isDragging: true
1485
- });
1486
-
1487
- _this._isKeyboard = false;
1669
+ _this.DS.publish(['Interaction:update:pre', 'Interaction:update'], publishData);
1488
1670
  });
1489
1671
 
1490
1672
  _defineProperty(this, "keyboardEnd", function (_ref3) {
1491
1673
  var event = _ref3.event,
1492
1674
  key = _ref3.key;
1493
- if (!_this._dragKeysFlat.includes(key) || !_this.DS.SelectedSet.size || !_this._draggability) return;
1494
- _this._isKeyboard = true;
1495
-
1496
- _this.DS.publish('Interaction:end', {
1675
+ if (!_this._keyboardDrag || !_this._dragKeysFlat.includes(key) || !_this.DS.SelectedSet.size || !_this._draggability) return;
1676
+ var publishData = {
1497
1677
  event: event,
1498
- isDragging: true
1499
- });
1678
+ isDragging: _this._draggability,
1679
+ isDraggingKeyboard: true
1680
+ };
1500
1681
 
1501
- _this._isKeyboard = false;
1682
+ _this.DS.publish(['Interaction:end:pre', 'Interaction:end'], publishData);
1502
1683
  });
1503
1684
 
1504
1685
  _defineProperty(this, "start", function (_ref4) {
1505
- var isDragging = _ref4.isDragging;
1506
- if (!isDragging || _this._isKeyboard) return;
1686
+ var isDragging = _ref4.isDragging,
1687
+ isDraggingKeyboard = _ref4.isDraggingKeyboard;
1688
+ if (!isDragging || isDraggingKeyboard) return;
1507
1689
  _this._prevCursorPos = null;
1508
1690
  _this._prevScrollPos = null;
1509
1691
  _this._elements = _this.DS.getSelection();
@@ -1511,8 +1693,8 @@ var Drag = /*#__PURE__*/function () {
1511
1693
  _this.handleZIndex(true);
1512
1694
  });
1513
1695
 
1514
- _defineProperty(this, "stop", function () {
1515
- if (_this._isKeyboard) return;
1696
+ _defineProperty(this, "stop", function (evt) {
1697
+ if (evt !== null && evt !== void 0 && evt.isKeyboard) return;
1516
1698
  _this._prevCursorPos = null;
1517
1699
  _this._prevScrollPos = null;
1518
1700
 
@@ -1522,8 +1704,9 @@ var Drag = /*#__PURE__*/function () {
1522
1704
  });
1523
1705
 
1524
1706
  _defineProperty(this, "update", function (_ref5) {
1525
- var isDragging = _ref5.isDragging;
1526
- if (!isDragging || !_this._elements.length || _this._isKeyboard) return;
1707
+ var isDragging = _ref5.isDragging,
1708
+ isDraggingKeyboard = _ref5.isDraggingKeyboard;
1709
+ if (!isDragging || !_this._elements.length || isDraggingKeyboard || _this.DS["continue"]) return;
1527
1710
  var posDirection = calc(_this._cursorDiff, '+', _this._scrollDiff);
1528
1711
 
1529
1712
  _this._elements.forEach(function (element) {
@@ -1545,6 +1728,7 @@ var Drag = /*#__PURE__*/function () {
1545
1728
  this.DS = DS;
1546
1729
  this._useTransform = useTransform;
1547
1730
  this._keyboardDragSpeed = keyboardDragSpeed;
1731
+ this._keyboardDrag = keyboardDrag;
1548
1732
  this._zoom = zoom;
1549
1733
  this._draggability = draggability;
1550
1734
  this._dragKeys = {
@@ -1646,6 +1830,10 @@ var Interaction = /*#__PURE__*/function () {
1646
1830
  _defineProperty(this, "isDragging", void 0);
1647
1831
 
1648
1832
  _defineProperty(this, "init", function () {
1833
+ return _this.DS.publish('Interaction:init:pre', {});
1834
+ });
1835
+
1836
+ _defineProperty(this, "_init", function () {
1649
1837
  _this.stop();
1650
1838
 
1651
1839
  _this._areaElement.addEventListener('mousedown', _this.start);
@@ -1658,6 +1846,13 @@ var Interaction = /*#__PURE__*/function () {
1658
1846
  });
1659
1847
 
1660
1848
  _defineProperty(this, "start", function (event) {
1849
+ return _this.DS.publish('Interaction:start:pre', {
1850
+ event: event,
1851
+ isDragging: _this.isDragging
1852
+ });
1853
+ });
1854
+
1855
+ _defineProperty(this, "_start", function (event) {
1661
1856
  if (event.type === 'touchstart') event.preventDefault(); // Call preventDefault() to prevent double click issue, see https://github.com/ThibaultJanBeyer/DragSelect/pull/29 & https://developer.mozilla.org/vi/docs/Web/API/Touch_events/Supporting_both_TouchEvent_and_MouseEvent
1662
1857
 
1663
1858
  if (!_this._canInteract(event)) return;
@@ -1702,8 +1897,7 @@ var Interaction = /*#__PURE__*/function () {
1702
1897
  PointerStore = _this$DS$stores.PointerStore,
1703
1898
  KeyStore = _this$DS$stores.KeyStore,
1704
1899
  SelectableSet = _this$DS.SelectableSet,
1705
- SelectedSet = _this$DS.SelectedSet,
1706
- publish = _this$DS.publish;
1900
+ SelectedSet = _this$DS.SelectedSet;
1707
1901
  PointerStore.start(event);
1708
1902
  var node =
1709
1903
  /** @type {any} */
@@ -1711,10 +1905,9 @@ var Interaction = /*#__PURE__*/function () {
1711
1905
  if (!SelectableSet.has(node)) return;
1712
1906
  if (!KeyStore.isMultiSelectKeyPressed(event)) SelectedSet.clear();
1713
1907
  SelectedSet.toggle(node);
1714
- publish('Interaction:end', {
1715
- event: event,
1716
- isDragging: _this.isDragging
1717
- }); // simulate mouse-up (that does not exist on keyboard)
1908
+
1909
+ _this.reset(); // simulate mouse-up (that does not exist on keyboard)
1910
+
1718
1911
  });
1719
1912
 
1720
1913
  _defineProperty(this, "stop", function () {
@@ -1734,15 +1927,24 @@ var Interaction = /*#__PURE__*/function () {
1734
1927
 
1735
1928
  _defineProperty(this, "update", function (_ref3) {
1736
1929
  var event = _ref3.event,
1737
- data = _ref3.data;
1738
- if (_this.isInteracting) _this.DS.publish('Interaction:update', {
1930
+ scroll_directions = _ref3.scroll_directions,
1931
+ scroll_multiplier = _ref3.scroll_multiplier;
1932
+ if (_this.isInteracting) _this.DS.publish(['Interaction:update:pre', 'Interaction:update'], {
1739
1933
  event: event,
1740
- data: data,
1934
+ scroll_directions: scroll_directions,
1935
+ scroll_multiplier: scroll_multiplier,
1741
1936
  isDragging: _this.isDragging
1742
1937
  });
1743
1938
  });
1744
1939
 
1745
1940
  _defineProperty(this, "reset", function (event) {
1941
+ return _this.DS.publish('Interaction:end:pre', {
1942
+ event: event,
1943
+ isDragging: _this.isDragging
1944
+ });
1945
+ });
1946
+
1947
+ _defineProperty(this, "_reset", function (event) {
1746
1948
  var isDragging = _this.isDragging;
1747
1949
 
1748
1950
  _this.stop();
@@ -1765,19 +1967,41 @@ var Interaction = /*#__PURE__*/function () {
1765
1967
  var event = _ref4.event;
1766
1968
  return _this.start(event);
1767
1969
  });
1970
+ this.DS.subscribe('Interaction:start:pre', function (_ref5) {
1971
+ var event = _ref5.event;
1972
+ return _this._start(event);
1973
+ });
1974
+ this.DS.subscribe('Interaction:init:pre', this._init);
1975
+ this.DS.subscribe('Interaction:end:pre', function (_ref6) {
1976
+ var event = _ref6.event;
1977
+ return _this._reset(event);
1978
+ });
1768
1979
  this.DS.subscribe('Area:scroll', this.update);
1769
1980
  }
1770
1981
 
1771
1982
  _createClass(Interaction, [{
1772
1983
  key: "_canInteract",
1984
+
1985
+ /**
1986
+ * @param {DSEvent} event
1987
+ */
1773
1988
  value: function _canInteract(event) {
1989
+ var isKeyboardClick =
1990
+ /** @type {MouseEvent} */
1991
+ event.clientX === 0 &&
1992
+ /** @type {MouseEvent} */
1993
+ event.clientY === 0 &&
1994
+ /** @type {MouseEvent} */
1995
+ event.detail === 0 && event.target;
1774
1996
  if (
1775
- /* right-clicks */
1776
- event.button === 2 ||
1777
- /* fix double-click issues */
1778
- this.isInteracting ||
1779
- /* fix outside elements issue */
1780
- event.target && !this.DS.SelectorArea.isInside(event.target)) return false;
1997
+ /** @type {MouseEvent} */
1998
+ event.button === 2 || // right-clicks
1999
+ this.isInteracting || // fix double-click issues
2000
+ event.target && !this.DS.SelectorArea.isInside(
2001
+ /** @type {DSElement} */
2002
+ event.target) || //fix outside elements issue
2003
+ !isKeyboardClick && !this.DS.SelectorArea.isClicked(event) // make sure the mouse click is inside the area
2004
+ ) return false;
1781
2005
  return true;
1782
2006
  }
1783
2007
  /**
@@ -1789,9 +2013,11 @@ var Interaction = /*#__PURE__*/function () {
1789
2013
  return Interaction;
1790
2014
  }();
1791
2015
 
1792
- var PubSub = function PubSub() {
2016
+ var PubSub = function PubSub(_ref) {
1793
2017
  var _this = this;
1794
2018
 
2019
+ var DS = _ref.DS;
2020
+
1795
2021
  _classCallCheck(this, PubSub);
1796
2022
 
1797
2023
  _defineProperty(this, "subscribers", {});
@@ -1811,13 +2037,44 @@ var PubSub = function PubSub() {
1811
2037
  });
1812
2038
 
1813
2039
  _defineProperty(this, "publish", function (eventName, data) {
1814
- if (!Array.isArray(_this.subscribers[eventName])) return;
2040
+ if (Array.isArray(eventName)) eventName.forEach(function (name) {
2041
+ return _this._publish(name, data);
2042
+ });else _this._publish(eventName, data);
2043
+ });
1815
2044
 
1816
- _this.subscribers[eventName].forEach(function (callback) {
1817
- return callback(data);
1818
- });
2045
+ _defineProperty(this, "_publish", function (eventName, data) {
2046
+ var subscribers = _this.subscribers[eventName];
2047
+ if (!Array.isArray(subscribers)) return;
2048
+ if (eventName.includes(":pre")) _this._handlePrePublish(subscribers, data);else _this._handlePublish(subscribers, data);
2049
+ });
2050
+
2051
+ _defineProperty(this, "_handlePublish", function (subscribers, data) {
2052
+ for (var i = 0, il = subscribers.length; i < il; i++) {
2053
+ if (_this.DS.stopped) return;
2054
+ subscribers[i](data);
2055
+ }
2056
+ });
2057
+
2058
+ _defineProperty(this, "_handlePrePublish", function (subscribers, data) {
2059
+ var i = subscribers.length;
2060
+
2061
+ while (i--) {
2062
+ if (_this.DS.stopped) return;
2063
+ subscribers[i](data);
2064
+ }
1819
2065
  });
1820
- };
2066
+
2067
+ this.DS = DS;
2068
+ }
2069
+ /**
2070
+ * Subscribe to an event
2071
+ * @memberof DragSelect#
2072
+ * @function subscribe
2073
+ * @param {DSCallbackNames} eventName
2074
+ * @param {DSCallback} callback
2075
+ * @returns {number} event id, can be used to unsubscribe more efficiently
2076
+ */
2077
+ ;
1821
2078
 
1822
2079
  var SelectableSet = /*#__PURE__*/function (_Set) {
1823
2080
  _inherits(SelectableSet, _Set);
@@ -1897,13 +2154,13 @@ var SelectableSet = /*#__PURE__*/function (_Set) {
1897
2154
  });
1898
2155
 
1899
2156
  _defineProperty(_assertThisInitialized(_this), "_onClick", function (event) {
1900
- return _this.DS.publish('Selectable:click', {
2157
+ return _this.DS.publish(['Selectable:click:pre', 'Selectable:click'], {
1901
2158
  event: event
1902
2159
  });
1903
2160
  });
1904
2161
 
1905
2162
  _defineProperty(_assertThisInitialized(_this), "_onPointer", function (event) {
1906
- return _this.DS.publish('Selectable:pointer', {
2163
+ return _this.DS.publish(['Selectable:pointer:pre', 'Selectable:pointer'], {
1907
2164
  event: event
1908
2165
  });
1909
2166
  });
@@ -2035,15 +2292,17 @@ var SelectedSet = /*#__PURE__*/function (_Set) {
2035
2292
  key: "add",
2036
2293
  value: function add(element) {
2037
2294
  if (_get(_getPrototypeOf(SelectedSet.prototype), "has", this).call(this, element)) return;
2295
+ var publishData = {
2296
+ items: this.elements,
2297
+ item: element
2298
+ };
2299
+ this.DS.publish('Selected:added:pre', publishData);
2038
2300
 
2039
2301
  _get(_getPrototypeOf(SelectedSet.prototype), "add", this).call(this, element);
2040
2302
 
2041
2303
  element.classList.add(this._className);
2042
- this.DS.publish('Selected:added', {
2043
- items: this.elements,
2044
- item: element
2045
- });
2046
2304
  element.style.zIndex = "".concat((parseInt(element.style.zIndex) || 0) + 1);
2305
+ this.DS.publish('Selected:added', publishData);
2047
2306
  return this;
2048
2307
  }
2049
2308
  /** @param {DSElement} element */
@@ -2052,15 +2311,17 @@ var SelectedSet = /*#__PURE__*/function (_Set) {
2052
2311
  key: "delete",
2053
2312
  value: function _delete(element) {
2054
2313
  if (!_get(_getPrototypeOf(SelectedSet.prototype), "has", this).call(this, element)) return;
2314
+ var publishData = {
2315
+ items: this.elements,
2316
+ item: element
2317
+ };
2318
+ this.DS.publish('Selected:removed:pre', publishData);
2055
2319
 
2056
2320
  var deleted = _get(_getPrototypeOf(SelectedSet.prototype), "delete", this).call(this, element);
2057
2321
 
2058
2322
  element.classList.remove(this._className);
2059
- this.DS.publish('Selected:removed', {
2060
- items: this.elements,
2061
- item: element
2062
- });
2063
2323
  element.style.zIndex = "".concat((parseInt(element.style.zIndex) || 0) - 1);
2324
+ this.DS.publish('Selected:removed', publishData);
2064
2325
  return deleted;
2065
2326
  }
2066
2327
  }, {
@@ -2137,7 +2398,7 @@ var Selection = /*#__PURE__*/function () {
2137
2398
 
2138
2399
  _defineProperty(this, "update", function (_ref3) {
2139
2400
  var isDragging = _ref3.isDragging;
2140
- if (isDragging) return;
2401
+ if (isDragging || _this.DS["continue"]) return;
2141
2402
 
2142
2403
  _this._handleInsideSelection();
2143
2404
  });
@@ -2162,6 +2423,7 @@ var Selection = /*#__PURE__*/function () {
2162
2423
 
2163
2424
  var multiSelectionToggle = _this.DS.stores.KeyStore.isMultiSelectKeyPressed(event) && _this._multiSelectToggling;
2164
2425
 
2426
+ if (_this.DS["continue"]) return;
2165
2427
  select.forEach(function (element) {
2166
2428
  return handleSelection({
2167
2429
  element: element,
@@ -2255,7 +2517,7 @@ var Selector = /*#__PURE__*/function () {
2255
2517
 
2256
2518
  _defineProperty(this, "update", function (_ref3) {
2257
2519
  var isDragging = _ref3.isDragging;
2258
- if (isDragging) return;
2520
+ if (isDragging || _this.DS["continue"]) return;
2259
2521
  var _this$DS$stores = _this.DS.stores,
2260
2522
  ScrollStore = _this$DS$stores.ScrollStore,
2261
2523
  PointerStore = _this$DS$stores.PointerStore;
@@ -2339,6 +2601,20 @@ var SelectorArea = /*#__PURE__*/function () {
2339
2601
 
2340
2602
  _defineProperty(this, "_overflowTolerance", void 0);
2341
2603
 
2604
+ _defineProperty(this, "start", function () {
2605
+ return _this.applyElements('append');
2606
+ });
2607
+
2608
+ _defineProperty(this, "applyElements", function () {
2609
+ var method = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 'append';
2610
+ var docEl = document.body ? 'body' : 'documentElement';
2611
+ var methodName = "".concat(method, "Child");
2612
+
2613
+ _this.HTMLNode[methodName](_this.DS.Selector.HTMLNode);
2614
+
2615
+ document[docEl][methodName](_this.HTMLNode);
2616
+ });
2617
+
2342
2618
  _defineProperty(this, "updatePos", function () {
2343
2619
  _this._rect = null;
2344
2620
  var rect = _this.DS.Area.rect;
@@ -2354,6 +2630,12 @@ var SelectorArea = /*#__PURE__*/function () {
2354
2630
  if (style.height !== height) style.height = height;
2355
2631
  });
2356
2632
 
2633
+ _defineProperty(this, "stop", function (remove) {
2634
+ _this.stopAutoScroll();
2635
+
2636
+ if (remove) _this.applyElements('remove');
2637
+ });
2638
+
2357
2639
  _defineProperty(this, "startAutoScroll", function () {
2358
2640
  _this.currentEdges = [];
2359
2641
  _this._scrollInterval = setInterval(function () {
@@ -2362,6 +2644,7 @@ var SelectorArea = /*#__PURE__*/function () {
2362
2644
  });
2363
2645
 
2364
2646
  _defineProperty(this, "handleAutoScroll", function () {
2647
+ if (_this.DS["continue"]) return;
2365
2648
  var _this$DS = _this.DS,
2366
2649
  PointerStore = _this$DS.stores.PointerStore,
2367
2650
  Area = _this$DS.Area;
@@ -2387,10 +2670,8 @@ var SelectorArea = /*#__PURE__*/function () {
2387
2670
  this._overflowTolerance = overflowTolerance;
2388
2671
  this.DS = DS;
2389
2672
  this.HTMLNode = createSelectorAreaElement(selectorAreaClass);
2390
- this.HTMLNode.appendChild(this.DS.Selector.HTMLNode);
2391
- var docEl = document.body ? 'body' : 'documentElement';
2392
- document[docEl].appendChild(this.HTMLNode);
2393
2673
  this.DS.subscribe('Area:modified', this.updatePos);
2674
+ this.DS.subscribe('Interaction:init', this.start);
2394
2675
  this.DS.subscribe('Interaction:start', this.startAutoScroll);
2395
2676
  this.DS.subscribe('Interaction:end', function () {
2396
2677
  _this.updatePos();
@@ -2398,23 +2679,23 @@ var SelectorArea = /*#__PURE__*/function () {
2398
2679
  _this.stopAutoScroll();
2399
2680
  });
2400
2681
  }
2401
- /** Updates the selectorAreas positions to match the areas */
2402
-
2403
2682
 
2404
2683
  _createClass(SelectorArea, [{
2405
2684
  key: "isClicked",
2406
2685
 
2407
2686
  /**
2408
2687
  * checks if the click was triggered on the area.
2688
+ * @param {DSEvent} [event]
2409
2689
  * @returns {boolean}
2410
2690
  */
2411
- value: function isClicked() {
2691
+ value: function isClicked(event) {
2412
2692
  var PointerStore = this.DS.stores.PointerStore;
2693
+ var initialVal = event ? PointerStore.getPointerPosition(event) : PointerStore.initialVal;
2413
2694
  return isCollision({
2414
- left: PointerStore.initialVal.x,
2415
- top: PointerStore.initialVal.y,
2416
- right: PointerStore.initialVal.x,
2417
- bottom: PointerStore.initialVal.y
2695
+ left: initialVal.x,
2696
+ top: initialVal.y,
2697
+ right: initialVal.x,
2698
+ bottom: initialVal.y
2418
2699
  }, this.rect);
2419
2700
  }
2420
2701
  }, {
@@ -2485,6 +2766,11 @@ var KeyStore = /*#__PURE__*/function () {
2485
2766
  _defineProperty(this, "keydown", function (event) {
2486
2767
  var key = event.key.toLowerCase();
2487
2768
 
2769
+ _this.DS.publish('KeyStore:down:pre', {
2770
+ event: event,
2771
+ key: key
2772
+ });
2773
+
2488
2774
  _this._currentValues.add(key);
2489
2775
 
2490
2776
  _this.DS.publish('KeyStore:down', {
@@ -2496,6 +2782,11 @@ var KeyStore = /*#__PURE__*/function () {
2496
2782
  _defineProperty(this, "keyup", function (event) {
2497
2783
  var key = event.key.toLowerCase();
2498
2784
 
2785
+ _this.DS.publish('KeyStore:up:pre', {
2786
+ event: event,
2787
+ key: key
2788
+ });
2789
+
2499
2790
  _this._currentValues["delete"](key);
2500
2791
 
2501
2792
  _this.DS.publish('KeyStore:up', {
@@ -2642,11 +2933,20 @@ var PointerStore = /*#__PURE__*/function () {
2642
2933
  });
2643
2934
  });
2644
2935
 
2936
+ _defineProperty(this, "getPointerPosition", function (event) {
2937
+ return getPointerPos({
2938
+ event: _this._normalizedEvent(event)
2939
+ });
2940
+ });
2941
+
2645
2942
  _defineProperty(this, "update", function (event) {
2646
2943
  if (!event) return;
2647
- _this.currentVal = getPointerPos({
2648
- event: _this._normalizedEvent(event)
2944
+
2945
+ _this.DS.publish('PointerStore:updated:pre', {
2946
+ event: event
2649
2947
  });
2948
+
2949
+ _this.currentVal = _this.getPointerPosition(event);
2650
2950
  if (!_this._isMouseInteraction) return;
2651
2951
 
2652
2952
  _this.DS.publish('PointerStore:updated', {
@@ -2668,9 +2968,7 @@ var PointerStore = /*#__PURE__*/function () {
2668
2968
 
2669
2969
  _defineProperty(this, "reset", function (event) {
2670
2970
  if (!event) return;
2671
- _this.currentVal = _this.lastVal = getPointerPos({
2672
- event: _this._normalizedEvent(event)
2673
- });
2971
+ _this.currentVal = _this.lastVal = _this.getPointerPosition(event);
2674
2972
 
2675
2973
  _this.stop();
2676
2974
 
@@ -2696,11 +2994,9 @@ var PointerStore = /*#__PURE__*/function () {
2696
2994
  value: function start(event) {
2697
2995
  if (!event) return;
2698
2996
  this._isMouseInteraction = true;
2699
- this.currentVal = this.initialVal = getPointerPos({
2700
- event: this._normalizedEvent(event)
2701
- });
2997
+ this.currentVal = this.initialVal = this.getPointerPosition(event);
2702
2998
  }
2703
- /** @param {DSEvent} [event] */
2999
+ /** @param {DSEvent} event */
2704
3000
 
2705
3001
  }, {
2706
3002
  key: "_normalizedEvent",
@@ -2923,6 +3219,11 @@ var ScrollStore = /*#__PURE__*/function () {
2923
3219
  //////////////////////////////////////////////////////////////////////////////////////
2924
3220
 
2925
3221
  var DragSelect = /*#__PURE__*/function () {
3222
+ /**
3223
+ * used to skip all current Selection and dragNdrop functionality
3224
+ * @type {boolean}
3225
+ */
3226
+
2926
3227
  /**
2927
3228
  * @class DragSelect
2928
3229
  * @constructor DragSelect
@@ -2958,6 +3259,8 @@ var DragSelect = /*#__PURE__*/function () {
2958
3259
  draggability = _ref$draggability === void 0 ? true : _ref$draggability,
2959
3260
  _ref$immediateDrag = _ref.immediateDrag,
2960
3261
  immediateDrag = _ref$immediateDrag === void 0 ? true : _ref$immediateDrag,
3262
+ _ref$keyboardDrag = _ref.keyboardDrag,
3263
+ keyboardDrag = _ref$keyboardDrag === void 0 ? true : _ref$keyboardDrag,
2961
3264
  dragKeys = _ref.dragKeys,
2962
3265
  _ref$keyboardDragSpee = _ref.keyboardDragSpeed,
2963
3266
  keyboardDragSpeed = _ref$keyboardDragSpee === void 0 ? 10 : _ref$keyboardDragSpee,
@@ -2982,8 +3285,16 @@ var DragSelect = /*#__PURE__*/function () {
2982
3285
 
2983
3286
  _classCallCheck(this, DragSelect);
2984
3287
 
3288
+ _defineProperty(this, "continue", false);
3289
+
2985
3290
  _defineProperty(this, "start", function () {
2986
- return _this.Interaction.init();
3291
+ _this.stopped = false;
3292
+
3293
+ _this.Interaction.init();
3294
+ });
3295
+
3296
+ _defineProperty(this, "break", function () {
3297
+ return _this["continue"] = true;
2987
3298
  });
2988
3299
 
2989
3300
  _defineProperty(this, "getSelection", function () {
@@ -3026,7 +3337,9 @@ var DragSelect = /*#__PURE__*/function () {
3026
3337
  return _this.Interaction.isDragging;
3027
3338
  });
3028
3339
 
3029
- this.PubSub = new PubSub();
3340
+ this.PubSub = new PubSub({
3341
+ DS: this
3342
+ });
3030
3343
  this.subscribe = this.PubSub.subscribe;
3031
3344
  this.unsubscribe = this.PubSub.unsubscribe;
3032
3345
  this.publish = this.PubSub.publish;
@@ -3093,6 +3406,7 @@ var DragSelect = /*#__PURE__*/function () {
3093
3406
  DS: this,
3094
3407
  draggability: draggability,
3095
3408
  useTransform: useTransform,
3409
+ keyboardDrag: keyboardDrag,
3096
3410
  dragKeys: Object.assign({
3097
3411
  up: ['ArrowUp'],
3098
3412
  down: ['ArrowDown'],
@@ -3109,61 +3423,14 @@ var DragSelect = /*#__PURE__*/function () {
3109
3423
  immediateDrag: immediateDrag
3110
3424
  }); // Subscriber Aliases
3111
3425
 
3112
- this.subscribe('Selected:added', function (_ref2) {
3113
- var items = _ref2.items,
3114
- item = _ref2.item;
3115
- return _this.publish('elementselect', {
3116
- items: items,
3117
- item: item,
3118
- isDragging: _this.Interaction.isDragging
3119
- });
3426
+ subscriberAliases({
3427
+ subscribe: this.subscribe,
3428
+ publish: this.publish,
3429
+ SelectedSet: this.SelectedSet,
3430
+ Interaction: this.Interaction
3120
3431
  });
3121
- this.subscribe('Selected:removed', function (_ref3) {
3122
- var items = _ref3.items,
3123
- item = _ref3.item;
3124
- return _this.publish('elementunselect', {
3125
- items: items,
3126
- item: item,
3127
- isDragging: _this.Interaction.isDragging
3128
- });
3129
- });
3130
- this.subscribe('Interaction:update', function (_ref4) {
3131
- var event = _ref4.event,
3132
- isDragging = _ref4.isDragging;
3133
- if (event) _this.publish('dragmove', {
3134
- items: _this.getSelection(),
3135
- event: event,
3136
- isDragging: isDragging
3137
- });
3138
- });
3139
- this.subscribe('Area:scroll', function (_ref5) {
3140
- var scroll_directions = _ref5.scroll_directions,
3141
- scroll_multiplier = _ref5.scroll_multiplier;
3142
-
3143
- _this.publish('autoscroll', {
3144
- items: _this.getSelection(),
3145
- scroll_directions: scroll_directions,
3146
- scroll_multiplier: scroll_multiplier,
3147
- isDragging: _this.Interaction.isDragging
3148
- });
3149
- });
3150
- this.subscribe('Interaction:start', function (_ref6) {
3151
- var event = _ref6.event,
3152
- isDragging = _ref6.isDragging;
3153
- return _this.publish('dragstart', {
3154
- items: _this.getSelection(),
3155
- event: event,
3156
- isDragging: isDragging
3157
- });
3158
- });
3159
- this.subscribe('Interaction:end', function (_ref7) {
3160
- var event = _ref7.event,
3161
- isDragging = _ref7.isDragging;
3162
- return _this.publish('callback', {
3163
- items: _this.getSelection(),
3164
- event: event,
3165
- isDragging: isDragging
3166
- });
3432
+ this.subscribe('Interaction:end', function () {
3433
+ return _this["continue"] = false;
3167
3434
  });
3168
3435
  this.start();
3169
3436
  } // @TODO: remove after deprecation
@@ -3171,13 +3438,13 @@ var DragSelect = /*#__PURE__*/function () {
3171
3438
 
3172
3439
  _createClass(DragSelect, [{
3173
3440
  key: "_callbacksTemp",
3174
- value: function _callbacksTemp(_ref8) {
3175
- var callback = _ref8.callback,
3176
- onDragMove = _ref8.onDragMove,
3177
- onDragStart = _ref8.onDragStart,
3178
- onDragStartBegin = _ref8.onDragStartBegin,
3179
- onElementSelect = _ref8.onElementSelect,
3180
- onElementUnselect = _ref8.onElementUnselect;
3441
+ value: function _callbacksTemp(_ref2) {
3442
+ var callback = _ref2.callback,
3443
+ onDragMove = _ref2.onDragMove,
3444
+ onDragStart = _ref2.onDragStart,
3445
+ onDragStartBegin = _ref2.onDragStartBegin,
3446
+ onElementSelect = _ref2.onElementSelect,
3447
+ onElementUnselect = _ref2.onElementUnselect;
3181
3448
 
3182
3449
  var warnMessage = function warnMessage(name, newName) {
3183
3450
  return console.warn("[DragSelect] ".concat(name, " is deprecated. Use DragSelect.subscribe(\"").concat(newName, "\", (callbackObject) => {}) instead. Act Now! See docs for more info"));
@@ -3185,60 +3452,60 @@ var DragSelect = /*#__PURE__*/function () {
3185
3452
 
3186
3453
  if (callback) {
3187
3454
  warnMessage('callback', 'callback');
3188
- this.subscribe('callback', function (_ref9) {
3189
- var items = _ref9.items,
3190
- item = _ref9.item,
3191
- event = _ref9.event;
3455
+ this.subscribe('callback', function (_ref3) {
3456
+ var items = _ref3.items,
3457
+ item = _ref3.item,
3458
+ event = _ref3.event;
3192
3459
  return callback(items, event);
3193
3460
  });
3194
3461
  }
3195
3462
 
3196
3463
  if (onDragMove) {
3197
3464
  warnMessage('onDragMove', 'dragmove');
3198
- this.subscribe('dragmove', function (_ref10) {
3199
- var items = _ref10.items,
3200
- item = _ref10.item,
3201
- event = _ref10.event;
3465
+ this.subscribe('dragmove', function (_ref4) {
3466
+ var items = _ref4.items,
3467
+ item = _ref4.item,
3468
+ event = _ref4.event;
3202
3469
  return onDragMove(event);
3203
3470
  });
3204
3471
  }
3205
3472
 
3206
3473
  if (onDragStart) {
3207
3474
  warnMessage('onDragStart', 'dragstart');
3208
- this.subscribe('dragstart', function (_ref11) {
3209
- var items = _ref11.items,
3210
- item = _ref11.item,
3211
- event = _ref11.event;
3475
+ this.subscribe('dragstart', function (_ref5) {
3476
+ var items = _ref5.items,
3477
+ item = _ref5.item,
3478
+ event = _ref5.event;
3212
3479
  return onDragStart(event);
3213
3480
  });
3214
3481
  }
3215
3482
 
3216
3483
  if (onDragStartBegin) {
3217
3484
  warnMessage('onDragStartBegin', 'dragstart');
3218
- this.subscribe('dragstart', function (_ref12) {
3219
- var items = _ref12.items,
3220
- item = _ref12.item,
3221
- event = _ref12.event;
3485
+ this.subscribe('dragstart', function (_ref6) {
3486
+ var items = _ref6.items,
3487
+ item = _ref6.item,
3488
+ event = _ref6.event;
3222
3489
  return onDragStartBegin(event);
3223
3490
  });
3224
3491
  }
3225
3492
 
3226
3493
  if (onElementSelect) {
3227
3494
  warnMessage('onElementSelect', 'elementselect');
3228
- this.subscribe('elementselect', function (_ref13) {
3229
- var items = _ref13.items,
3230
- item = _ref13.item,
3231
- event = _ref13.event;
3495
+ this.subscribe('elementselect', function (_ref7) {
3496
+ var items = _ref7.items,
3497
+ item = _ref7.item,
3498
+ event = _ref7.event;
3232
3499
  return onElementSelect(item, event);
3233
3500
  });
3234
3501
  }
3235
3502
 
3236
3503
  if (onElementUnselect) {
3237
3504
  warnMessage('onElementUnselect', 'elementunselect');
3238
- this.subscribe('elementunselect', function (_ref14) {
3239
- var items = _ref14.items,
3240
- item = _ref14.item,
3241
- event = _ref14.event;
3505
+ this.subscribe('elementunselect', function (_ref8) {
3506
+ var items = _ref8.items,
3507
+ item = _ref8.item,
3508
+ event = _ref8.event;
3242
3509
  return onElementUnselect(item, event);
3243
3510
  });
3244
3511
  }
@@ -3271,15 +3538,18 @@ var DragSelect = /*#__PURE__*/function () {
3271
3538
  this.Area.stop();
3272
3539
  this.Drag.stop();
3273
3540
  this.Selector.stop();
3541
+ this.SelectorArea.stop(remove);
3274
3542
  this.stores.KeyStore.stop();
3275
3543
  this.stores.PointerStore.stop();
3276
3544
  this.stores.ScrollStore.stop();
3277
3545
  if (remove) this.SelectableSet.clear();
3278
3546
  if (fromSelection) this.SelectedSet.clear();
3547
+ this.stopped = true;
3279
3548
  }
3280
3549
  /**
3281
- * Returns the current selected nodes
3282
- * @return {DSElements}
3550
+ * Utility to override DragSelect internal functionality:
3551
+ * Break will skip the selection or dragging functionality (until after the callback) but let everything continue to run.
3552
+ * Useful utility to write your own functionality/move/dragNdrop based on DragSelect pointer positions.
3283
3553
  */
3284
3554
 
3285
3555
  }, {
@@ -3443,16 +3713,18 @@ var DragSelect = /*#__PURE__*/function () {
3443
3713
  key: "getCursorPositionDifference",
3444
3714
 
3445
3715
  /**
3446
- * Returns the cursor position difference between start and now
3716
+ * Utility method that returns the cursor position difference between start and now
3447
3717
  * @param {boolean} [usePreviousCursorDifference] if true, it will output the cursor position difference between the previous selection and now
3718
+ * @param {boolean} [useAreaPositions] if true, it will use cursor positions relative to the area
3448
3719
  * @return {Vect2}
3449
3720
  * @deprecated
3450
3721
  */
3451
3722
  value: function getCursorPositionDifference() {
3452
3723
  var usePreviousCursorDifference = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : false;
3724
+ var useAreaPositions = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false;
3453
3725
  console.warn('[DragSelect] Using .getCursorPositionDifference is deprecated. Calculate yourself instead. i.e. `.getCurrentCursorPosition().x - .getInitialCursorPosition().x`');
3454
- var posA = this.getCurrentCursorPosition();
3455
- var posB = usePreviousCursorDifference ? this.getPreviousCursorPosition() : this.getInitialCursorPosition();
3726
+ var posA = useAreaPositions ? this.getCurrentCursorPositionArea() : this.getCurrentCursorPosition();
3727
+ var posB = usePreviousCursorDifference ? useAreaPositions ? this.getPreviousCursorPositionArea() : this.getPreviousCursorPosition() : useAreaPositions ? this.getInitialCursorPositionArea() : this.getInitialCursorPosition();
3456
3728
  return calc(posA, '-', posB);
3457
3729
  }
3458
3730
  /**