dragselect 2.4.3 → 2.5.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.
Files changed (52) hide show
  1. package/CHANGELOG.md +10 -0
  2. package/README.md +103 -27
  3. package/deploying.md +1 -1
  4. package/dist/DragSelect.d.ts +26 -4
  5. package/dist/DragSelect.es6m.js +882 -792
  6. package/dist/DragSelect.js +882 -792
  7. package/dist/ds.es6m.min.js +1 -1
  8. package/dist/ds.min.js +1 -1
  9. package/dist/methods/addModificationObservers.d.ts +9 -1
  10. package/dist/methods/getAllParentNodes.d.ts +3 -0
  11. package/dist/methods/getPointerPos.d.ts +1 -1
  12. package/dist/methods/index.d.ts +1 -0
  13. package/dist/methods/isCollision.d.ts +1 -1
  14. package/dist/methods/subscriberAliases.d.ts +3 -1
  15. package/dist/modules/Area.d.ts +2 -12
  16. package/dist/modules/DropZone.d.ts +88 -0
  17. package/dist/modules/DropZones.d.ts +76 -0
  18. package/dist/modules/Interaction.d.ts +1 -0
  19. package/dist/modules/SelectableSet.d.ts +12 -0
  20. package/dist/modules/Selection.d.ts +1 -0
  21. package/dist/modules/Selector.d.ts +1 -1
  22. package/dist/modules/SelectorArea.d.ts +1 -1
  23. package/dist/modules/index.d.ts +1 -0
  24. package/dist/stores/KeyStore.d.ts +2 -2
  25. package/dist/stores/PointerStore.d.ts +2 -1
  26. package/dist/types.d.ts +78 -4
  27. package/jest-puppeteer.config.js +1 -0
  28. package/package.json +10 -9
  29. package/rollup.config.js +1 -1
  30. package/src/DragSelect.js +29 -5
  31. package/src/methods/addModificationObservers.js +26 -5
  32. package/src/methods/canScroll.js +1 -1
  33. package/src/methods/getAllParentNodes.js +18 -0
  34. package/src/methods/getPointerPos.js +1 -1
  35. package/src/methods/handleElementPositionAttribute.js +1 -1
  36. package/src/methods/hydrateSettings.js +17 -0
  37. package/src/methods/index.js +1 -0
  38. package/src/methods/isCollision.js +24 -5
  39. package/src/methods/scrollElement.js +1 -1
  40. package/src/methods/subscriberAliases.js +16 -5
  41. package/src/methods/toArray.js +3 -2
  42. package/src/modules/Area.js +12 -44
  43. package/src/modules/DropZone.js +224 -0
  44. package/src/modules/DropZones.js +153 -0
  45. package/src/modules/Interaction.js +32 -7
  46. package/src/modules/SelectableSet.js +45 -8
  47. package/src/modules/Selection.js +9 -11
  48. package/src/modules/index.js +1 -0
  49. package/src/stores/KeyStore.js +1 -1
  50. package/src/stores/PointerStore.js +17 -3
  51. package/src/stores/SettingsStore.js +0 -1
  52. package/src/types.js +33 -4
@@ -1,6 +1,6 @@
1
1
  /***
2
2
 
3
- ~~~ Version 2.4.3 ~~~
3
+ ~~~ Version 2.4.4 ~~~
4
4
 
5
5
  ******************************************
6
6
 
@@ -34,7 +34,6 @@ function _classCallCheck(instance, Constructor) {
34
34
  throw new TypeError("Cannot call a class as a function");
35
35
  }
36
36
  }
37
-
38
37
  function _defineProperties(target, props) {
39
38
  for (var i = 0; i < props.length; i++) {
40
39
  var descriptor = props[i];
@@ -44,13 +43,11 @@ function _defineProperties(target, props) {
44
43
  Object.defineProperty(target, descriptor.key, descriptor);
45
44
  }
46
45
  }
47
-
48
46
  function _createClass(Constructor, protoProps, staticProps) {
49
47
  if (protoProps) _defineProperties(Constructor.prototype, protoProps);
50
48
  if (staticProps) _defineProperties(Constructor, staticProps);
51
49
  return Constructor;
52
50
  }
53
-
54
51
  function _defineProperty(obj, key, value) {
55
52
  if (key in obj) {
56
53
  Object.defineProperty(obj, key, {
@@ -62,13 +59,10 @@ function _defineProperty(obj, key, value) {
62
59
  } else {
63
60
  obj[key] = value;
64
61
  }
65
-
66
62
  return obj;
67
63
  }
68
-
69
64
  function ownKeys(object, enumerableOnly) {
70
65
  var keys = Object.keys(object);
71
-
72
66
  if (Object.getOwnPropertySymbols) {
73
67
  var symbols = Object.getOwnPropertySymbols(object);
74
68
  if (enumerableOnly) symbols = symbols.filter(function (sym) {
@@ -76,14 +70,11 @@ function ownKeys(object, enumerableOnly) {
76
70
  });
77
71
  keys.push.apply(keys, symbols);
78
72
  }
79
-
80
73
  return keys;
81
74
  }
82
-
83
75
  function _objectSpread2(target) {
84
76
  for (var i = 1; i < arguments.length; i++) {
85
77
  var source = arguments[i] != null ? arguments[i] : {};
86
-
87
78
  if (i % 2) {
88
79
  ownKeys(Object(source), true).forEach(function (key) {
89
80
  _defineProperty(target, key, source[key]);
@@ -96,15 +87,12 @@ function _objectSpread2(target) {
96
87
  });
97
88
  }
98
89
  }
99
-
100
90
  return target;
101
91
  }
102
-
103
92
  function _inherits(subClass, superClass) {
104
93
  if (typeof superClass !== "function" && superClass !== null) {
105
94
  throw new TypeError("Super expression must either be null or a function");
106
95
  }
107
-
108
96
  subClass.prototype = Object.create(superClass && superClass.prototype, {
109
97
  constructor: {
110
98
  value: subClass,
@@ -114,28 +102,23 @@ function _inherits(subClass, superClass) {
114
102
  });
115
103
  if (superClass) _setPrototypeOf(subClass, superClass);
116
104
  }
117
-
118
105
  function _getPrototypeOf(o) {
119
106
  _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) {
120
107
  return o.__proto__ || Object.getPrototypeOf(o);
121
108
  };
122
109
  return _getPrototypeOf(o);
123
110
  }
124
-
125
111
  function _setPrototypeOf(o, p) {
126
112
  _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) {
127
113
  o.__proto__ = p;
128
114
  return o;
129
115
  };
130
-
131
116
  return _setPrototypeOf(o, p);
132
117
  }
133
-
134
118
  function _isNativeReflectConstruct() {
135
119
  if (typeof Reflect === "undefined" || !Reflect.construct) return false;
136
120
  if (Reflect.construct.sham) return false;
137
121
  if (typeof Proxy === "function") return true;
138
-
139
122
  try {
140
123
  Date.prototype.toString.call(Reflect.construct(Date, [], function () {}));
141
124
  return true;
@@ -143,7 +126,6 @@ function _isNativeReflectConstruct() {
143
126
  return false;
144
127
  }
145
128
  }
146
-
147
129
  function _construct(Parent, args, Class) {
148
130
  if (_isNativeReflectConstruct()) {
149
131
  _construct = Reflect.construct;
@@ -157,34 +139,25 @@ function _construct(Parent, args, Class) {
157
139
  return instance;
158
140
  };
159
141
  }
160
-
161
142
  return _construct.apply(null, arguments);
162
143
  }
163
-
164
144
  function _isNativeFunction(fn) {
165
145
  return Function.toString.call(fn).indexOf("[native code]") !== -1;
166
146
  }
167
-
168
147
  function _wrapNativeSuper(Class) {
169
148
  var _cache = typeof Map === "function" ? new Map() : undefined;
170
-
171
149
  _wrapNativeSuper = function _wrapNativeSuper(Class) {
172
150
  if (Class === null || !_isNativeFunction(Class)) return Class;
173
-
174
151
  if (typeof Class !== "function") {
175
152
  throw new TypeError("Super expression must either be null or a function");
176
153
  }
177
-
178
154
  if (typeof _cache !== "undefined") {
179
155
  if (_cache.has(Class)) return _cache.get(Class);
180
-
181
156
  _cache.set(Class, Wrapper);
182
157
  }
183
-
184
158
  function Wrapper() {
185
159
  return _construct(Class, arguments, _getPrototypeOf(this).constructor);
186
160
  }
187
-
188
161
  Wrapper.prototype = Object.create(Class.prototype, {
189
162
  constructor: {
190
163
  value: Wrapper,
@@ -195,106 +168,81 @@ function _wrapNativeSuper(Class) {
195
168
  });
196
169
  return _setPrototypeOf(Wrapper, Class);
197
170
  };
198
-
199
171
  return _wrapNativeSuper(Class);
200
172
  }
201
-
202
173
  function _assertThisInitialized(self) {
203
174
  if (self === void 0) {
204
175
  throw new ReferenceError("this hasn't been initialised - super() hasn't been called");
205
176
  }
206
-
207
177
  return self;
208
178
  }
209
-
210
179
  function _possibleConstructorReturn(self, call) {
211
180
  if (call && (typeof call === "object" || typeof call === "function")) {
212
181
  return call;
213
182
  }
214
-
215
183
  return _assertThisInitialized(self);
216
184
  }
217
-
218
185
  function _createSuper(Derived) {
219
186
  var hasNativeReflectConstruct = _isNativeReflectConstruct();
220
-
221
187
  return function _createSuperInternal() {
222
188
  var Super = _getPrototypeOf(Derived),
223
- result;
224
-
189
+ result;
225
190
  if (hasNativeReflectConstruct) {
226
191
  var NewTarget = _getPrototypeOf(this).constructor;
227
-
228
192
  result = Reflect.construct(Super, arguments, NewTarget);
229
193
  } else {
230
194
  result = Super.apply(this, arguments);
231
195
  }
232
-
233
196
  return _possibleConstructorReturn(this, result);
234
197
  };
235
198
  }
236
-
237
199
  function _superPropBase(object, property) {
238
200
  while (!Object.prototype.hasOwnProperty.call(object, property)) {
239
201
  object = _getPrototypeOf(object);
240
202
  if (object === null) break;
241
203
  }
242
-
243
204
  return object;
244
205
  }
245
-
246
206
  function _get(target, property, receiver) {
247
207
  if (typeof Reflect !== "undefined" && Reflect.get) {
248
208
  _get = Reflect.get;
249
209
  } else {
250
210
  _get = function _get(target, property, receiver) {
251
211
  var base = _superPropBase(target, property);
252
-
253
212
  if (!base) return;
254
213
  var desc = Object.getOwnPropertyDescriptor(base, property);
255
-
256
214
  if (desc.get) {
257
215
  return desc.get.call(receiver);
258
216
  }
259
-
260
217
  return desc.value;
261
218
  };
262
219
  }
263
-
264
220
  return _get(target, property, receiver || target);
265
221
  }
266
-
267
222
  function _slicedToArray(arr, i) {
268
223
  return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest();
269
224
  }
270
-
271
225
  function _toConsumableArray(arr) {
272
226
  return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _unsupportedIterableToArray(arr) || _nonIterableSpread();
273
227
  }
274
-
275
228
  function _arrayWithoutHoles(arr) {
276
229
  if (Array.isArray(arr)) return _arrayLikeToArray(arr);
277
230
  }
278
-
279
231
  function _arrayWithHoles(arr) {
280
232
  if (Array.isArray(arr)) return arr;
281
233
  }
282
-
283
234
  function _iterableToArray(iter) {
284
235
  if (typeof Symbol !== "undefined" && Symbol.iterator in Object(iter)) return Array.from(iter);
285
236
  }
286
-
287
237
  function _iterableToArrayLimit(arr, i) {
288
238
  if (typeof Symbol === "undefined" || !(Symbol.iterator in Object(arr))) return;
289
239
  var _arr = [];
290
240
  var _n = true;
291
241
  var _d = false;
292
242
  var _e = undefined;
293
-
294
243
  try {
295
244
  for (var _i = arr[Symbol.iterator](), _s; !(_n = (_s = _i.next()).done); _n = true) {
296
245
  _arr.push(_s.value);
297
-
298
246
  if (i && _arr.length === i) break;
299
247
  }
300
248
  } catch (err) {
@@ -307,10 +255,8 @@ function _iterableToArrayLimit(arr, i) {
307
255
  if (_d) throw _e;
308
256
  }
309
257
  }
310
-
311
258
  return _arr;
312
259
  }
313
-
314
260
  function _unsupportedIterableToArray(o, minLen) {
315
261
  if (!o) return;
316
262
  if (typeof o === "string") return _arrayLikeToArray(o, minLen);
@@ -319,27 +265,73 @@ function _unsupportedIterableToArray(o, minLen) {
319
265
  if (n === "Map" || n === "Set") return Array.from(o);
320
266
  if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen);
321
267
  }
322
-
323
268
  function _arrayLikeToArray(arr, len) {
324
269
  if (len == null || len > arr.length) len = arr.length;
325
-
326
270
  for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i];
327
-
328
271
  return arr2;
329
272
  }
330
-
331
273
  function _nonIterableSpread() {
332
274
  throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
333
275
  }
334
-
335
276
  function _nonIterableRest() {
336
277
  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
278
  }
279
+ function _createForOfIteratorHelper(o, allowArrayLike) {
280
+ var it;
281
+ if (typeof Symbol === "undefined" || o[Symbol.iterator] == null) {
282
+ if (Array.isArray(o) || (it = _unsupportedIterableToArray(o)) || allowArrayLike && o && typeof o.length === "number") {
283
+ if (it) o = it;
284
+ var i = 0;
285
+ var F = function () {};
286
+ return {
287
+ s: F,
288
+ n: function () {
289
+ if (i >= o.length) return {
290
+ done: true
291
+ };
292
+ return {
293
+ done: false,
294
+ value: o[i++]
295
+ };
296
+ },
297
+ e: function (e) {
298
+ throw e;
299
+ },
300
+ f: F
301
+ };
302
+ }
303
+ throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
304
+ }
305
+ var normalCompletion = true,
306
+ didErr = false,
307
+ err;
308
+ return {
309
+ s: function () {
310
+ it = o[Symbol.iterator]();
311
+ },
312
+ n: function () {
313
+ var step = it.next();
314
+ normalCompletion = step.done;
315
+ return step;
316
+ },
317
+ e: function (e) {
318
+ didErr = true;
319
+ err = e;
320
+ },
321
+ f: function () {
322
+ try {
323
+ if (!normalCompletion && it.return != null) it.return();
324
+ } finally {
325
+ if (didErr) throw err;
326
+ }
327
+ }
328
+ };
329
+ }
338
330
 
339
331
  /**
340
332
  * The Settings to be passed to the Class
341
333
  * @typedef {Object} Settings
342
- * @property {HTMLElement|SVGElement|HTMLDocument} [area=document] area in which you can drag. If not provided it will be the whole document
334
+ * @property {HTMLElement|SVGElement|Document} [area=document] area in which you can drag. If not provided it will be the whole document
343
335
  * @property {DSInputElements} [selectables=[]] the elements that can be selected
344
336
  * @property {number} [autoScrollSpeed=5] Speed in which the area scrolls while selecting (if available). Unit is pixel per movement.
345
337
  * @property {Vect2} [overflowTolerance={x:25,y:25}] Tolerance for autoScroll (how close one has to be near an edges for autoScroll to start)
@@ -349,24 +341,37 @@ function _nonIterableRest() {
349
341
  * @property {boolean} [multiSelectToggling=true] Whether or not to toggle already active elements while multi-selecting
350
342
  * @property {DSMultiSelectKeys} [multiSelectKeys=['Control', 'Shift', 'Meta']] Keys that allows switching to the multi-select mode (see the multiSelectMode option). Any key value is possible ([see MDN docs](https://developer.mozilla.org/en-US/docs/Web/API/KeyboardEvent/key)). Note that the best support is given for <kbd>Control</kbd>, <kbd>Shift</kbd> and <kbd>Meta</kbd>. Provide an empty array `[]` if you want to turn off the functionality.
351
343
  * @property {HTMLElement} [selector=HTMLElement] the square that will draw the selection
344
+ * @property {number} [selectionThreshold=0] how much % of the element has to be selected to be considered selected (0 = just touching, 1 = inside the selection)
352
345
  * @property {boolean} [draggability=true] When a user is dragging on an already selected element, the selection is dragged.
353
346
  * @property {boolean} [immediateDrag=true] Whether an element is draggable from the start or needs to be selected first
354
347
  * @property {boolean} [keyboardDrag=true] Whether or not the user can drag with the keyboard (we don't recommend disabling it)
355
348
  * @property {DSDragKeys} [dragKeys={up:['ArrowUp'],down:['ArrowDown'],left:['ArrowLeft'],righ:['ArrowRight']}] The keys available to drag element using the keyboard.
356
349
  * @property {number} [keyboardDragSpeed=10] The speed at which elements are dragged using the keyboard. In pixels per keydown.
357
350
  * @property {boolean} [useTransform=true] Whether to use hardware accelerated css transforms when dragging or top/left instead
351
+ * @property {number} [refreshMemoryRate=80] Refresh rate on memoization, higher numbers mean better performance but more lag if elements are moving, lower numbers mean less lag but worse performance. If none of your DOMNodes are moving, you can set it to a very high number to increase performance. Value in milliseconds.
352
+ * @property {DSInputDropZone[]} [dropZones=[]] one or more drop-elements: where the selectables can be dropped into
353
+ * @property {number} [dropInsideThreshold=1] how much % of the item has to be inside the dropzone to be considered inside (0 = barely touching, 1 = completely inside)
354
+ * @property {number} [dropTargetThreshold=0] how much % of the zone does the pointer has to be in to be considered a target (0 = anywhere in the zone, max: 0.5 = has to point at the center of the zone)
355
+ * @property {boolean} [usePointerEvents=false] Whether to use Pointer Events to replace traditional Mouse or Touch Events. Useful for tools like Google Blockly.
358
356
  * @property {string} [hoverClass=ds-hover] the class assigned to the mouse hovered items
359
357
  * @property {string} [selectableClass=ds-selectable] the class assigned to the elements that can be selected
360
358
  * @property {string} [selectedClass=ds-selected] the class assigned to the selected items
361
359
  * @property {string} [selectorClass=ds-selector] the class assigned to the square selector helper
362
360
  * @property {string} [selectorAreaClass=ds-selector-area] the class assigned to the square in which the selector resides. By default it's invisible
361
+ * @property {string} [droppedTargetClass=ds-dropped-target] on an item corresponding the target dropzone. This is also the prefix for ds-dropped-target-${zone.id}
362
+ * @property {string} [droppedInsideClass=ds-dropped-inside] on an item that is within its dropzone bounds after a drop. This is also the prefix for ds-dropped-inside-${zone.id}
363
+ * @property {string} [droppableClass=ds-droppable] on element that can be dropped into at least one container. This is also the prefix for ds-droppable-${zone.id}
364
+ * @property {string} [dropZoneClass=ds-dropzone] on each dropZone
365
+ * @property {string} [dropZoneReadyClass=ds-dropzone-ready] on corresponding dropZone when element is dragged
366
+ * @property {string} [dropZoneTargetClass=ds-dropzone-target] on dropZone that has elements from any successful target drop
367
+ * @property {string} [dropZoneInsideClass=ds-dropzone-inside] on dropZone that has elements inside after any drop
363
368
  */
364
369
 
365
370
  /**
366
371
  * The Object that is passed back to any callback method
367
372
  * @typedef {Object} CallbackObject
368
373
  * @property {Array<HTMLElement|SVGElement|any>} [items] The items currently selected
369
- * @property {MouseEvent|TouchEvent|KeyboardEvent|Event} [event] The respective event object
374
+ * @property {MouseEvent|TouchEvent|PointerEvent|KeyboardEvent|Event} [event] The respective event object
370
375
  * @property {HTMLElement|SVGElement|any} [item] The single item currently interacted with
371
376
  * @property {boolean} [isDragging] Whether the interaction is a drag or a select
372
377
  * @property {boolean} [isDraggingKeyboard] Whether or not the drag interaction is via keyboard
@@ -374,46 +379,48 @@ function _nonIterableRest() {
374
379
  * @property {Settings} [settings] the settings being updates/manipulated/passed, also holds the previous value. i.e. updating selectorClass will publish { settings: { selectorClass: 'newVal', 'selectorClass:pre': 'oldVal' } }
375
380
  * @property {Array.<'top'|'bottom'|'left'|'right'|undefined>} [scroll_directions]
376
381
  * @property {number} [scroll_multiplier]
382
+ * @property {DSDropZone} [dropTarget] The dropZone element that the element was dropped into (or the mouse is currently hovering over)
377
383
  */
378
-
379
384
  /**
380
385
  * @typedef {function} DSCallback
381
386
  * @param {CallbackObject} data
382
387
  */
383
388
 
384
- /** @typedef {{x: number, y: number}} Vect2 */
389
+ /**
390
+ * @typedef {Object} DSInputDropZone
391
+ * @property {string} id
392
+ * @property {DSElement} element
393
+ * @property {DSInputElements} droppables
394
+ */
395
+ /**
396
+ * @typedef {Object} DSDropZone
397
+ * @property {string} id
398
+ * @property {DSElement} element
399
+ * @property {DSElements} droppables
400
+ * @property {DSElements} [itemsDropped] the items related to the target zone
401
+ * @property {DSElements} [itemsInside] the items that are within the targets bounds
402
+ */
385
403
 
404
+ /** @typedef {{x: number, y: number}} Vect2 */
386
405
  /** @typedef {{x:number,y:number,w:number,h:number,r:number,b:number}} DSElementPos */
387
-
388
406
  /** @typedef {Array.<'top'|'bottom'|'left'|'right'|undefined>} DSEdges */
389
407
 
390
- /** @typedef {HTMLElement|SVGElement|HTMLDocument} DSArea area within which you can drag */
391
-
408
+ /** @typedef {HTMLElement|SVGElement|Document} DSArea area within which you can drag */
392
409
  /** @typedef {HTMLElement} DSSelectorArea area in which you can drag */
393
-
394
410
  /** @typedef {Array.<HTMLElement|SVGElement> | HTMLElement | SVGElement} DSInputElements the elements that can be selected */
395
-
396
411
  /** @typedef {Array.<HTMLElement|SVGElement>} DSElements the elements that can be selected */
397
-
398
412
  /** @typedef {HTMLElement|SVGElement} DSElement a single element that can be selected */
399
-
400
- /** @typedef {MouseEvent|TouchEvent} DSEvent en event from a touch or mouse interaction */
401
-
413
+ /** @typedef {MouseEvent|TouchEvent|PointerEvent} DSEvent en event from a touch or mouse interaction */
402
414
  /** @typedef {Array.<'Shift'|'Control'|'Meta'|string>} DSMultiSelectKeys An array of keys that allows switching to the multi-select mode */
403
415
 
404
416
  /** @typedef {'dragmove'|'autoscroll'|'dragstart'|'elementselect'|'elementunselect'|'callback'} DSEventNames */
405
-
406
417
  /** @typedef {'Interaction:init'|'Interaction:start'|'Interaction:end'|'Interaction:update'|'Area:modified'|'Area:scroll'|'PointerStore:updated'|'Selected:added'|'Selected:removed'|'Selectable:click'|'Selectable:added'|'Selectable:removed'|'Selectable:pointer'|'KeyStore:down'|'KeyStore:up'} DSInternalEventNames */
407
-
408
418
  /** @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:added:pre'|'Selectable:removed:pre'|'Selectable:pointer:pre'|'KeyStore:down:pre'|'KeyStore:up:pre'} DSInternalEventNamesPre */
409
419
  // @todo: update to typescript for complex defs like `Settings:updated:${string}` | `Settings:updated:${string}:pre`
410
-
411
420
  /** @typedef {'Settings:updated'|'Settings:updated:pre'|'Settings:updated:*'|'Settings:updated:*:pre'} DSInternalSettingEvents */
412
-
413
421
  /** @typedef {DSEventNames|DSInternalEventNames|DSInternalEventNamesPre|DSInternalSettingEvents} DSCallbackNames the name of the callback */
414
422
 
415
423
  /** @typedef {{top:number,left:number,bottom:number,right:number,width:number,height:number}} DSBoundingRect */
416
-
417
424
  /** @typedef {{up:string[],down:string[],left:string[],right:string[]}} DSDragKeys */
418
425
 
419
426
  /**
@@ -422,18 +429,18 @@ function _nonIterableRest() {
422
429
  */
423
430
 
424
431
  // @ts-check
432
+
425
433
  /**
426
434
  * @param {Vect2} v1
427
435
  * @param {'+'|'-'|'*'|'/'} operator
428
436
  * @param {Vect2} v2
429
437
  * @return {Vect2}
430
438
  */
431
-
432
439
  var calc = function calc(_ref, operator, _ref2) {
433
440
  var x1 = _ref.x,
434
- y1 = _ref.y;
441
+ y1 = _ref.y;
435
442
  var x2 = _ref2.x,
436
- y2 = _ref2.y;
443
+ y2 = _ref2.y;
437
444
  var calculations = {
438
445
  '+': {
439
446
  x: x1 + x2,
@@ -454,11 +461,11 @@ var calc = function calc(_ref, operator, _ref2) {
454
461
  };
455
462
  return calculations[operator];
456
463
  };
464
+
457
465
  /**
458
466
  * @param {{left:number,top:number}} rect
459
467
  * @returns {Vect2}
460
468
  */
461
-
462
469
  var rect2vect = function rect2vect(rect) {
463
470
  return {
464
471
  x: rect.left,
@@ -470,7 +477,6 @@ var rect2vect = function rect2vect(rect) {
470
477
  * @param {number} dimension
471
478
  * @returns {DSBoundingRect}
472
479
  */
473
-
474
480
  var vect2rect = function vect2rect(vect) {
475
481
  var dimension = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 0;
476
482
  return {
@@ -486,7 +492,6 @@ var vect2rect = function vect2rect(vect) {
486
492
  * @param {number} n
487
493
  * @returns {Vect2}
488
494
  */
489
-
490
495
  var num2vect = function num2vect(n) {
491
496
  return {
492
497
  x: n,
@@ -495,48 +500,65 @@ var num2vect = function num2vect(n) {
495
500
  };
496
501
 
497
502
  // @ts-check
503
+
498
504
  /**
499
- * Adds event-listeners to the selectorArea
500
- * @param {DSArea[]} nodes
501
- * @param {DSModificationCallback} callback
502
- * @param {MutationObserver} modificationObserver
505
+ * Removes event-listeners from the DOMNode
506
+ * @typedef {()=>void} DSCleanup
503
507
  */
504
508
 
505
- var addModificationObservers = (function (nodes, callback, modificationObserver) {
509
+ /**
510
+ * Adds event-listeners to a DOMNode
511
+ * @param {DSArea[]} nodes
512
+ * @param {DSModificationCallback} cb
513
+ * @return {{observer:MutationObserver,callback:DSModificationCallback,cleanup:DSCleanup}}
514
+ */
515
+ var addModificationObservers = (function (nodes, cb) {
516
+ var callback = cb;
506
517
  window.addEventListener('resize', callback);
507
518
  window.addEventListener('scroll', callback);
519
+ var observer = new MutationObserver(callback);
508
520
  nodes.forEach(function (el, i) {
509
- modificationObserver.observe(el, {
521
+ observer.observe(el, {
510
522
  childList: i !== 0,
511
523
  attributes: true
512
524
  });
513
525
  });
526
+
527
+ /**
528
+ * Removes all observers
529
+ */
530
+ var cleanup = function cleanup() {
531
+ return removeModificationObservers(observer, callback);
532
+ };
533
+ return {
534
+ observer: observer,
535
+ callback: callback,
536
+ cleanup: cleanup
537
+ };
514
538
  });
515
539
 
516
540
  // @ts-check
541
+
517
542
  /**
518
543
  * Checks whether the area can scroll or not
519
544
  * @param {DSArea} area
520
545
  * @return {boolean} scroll X/Y
521
546
  */
522
-
523
547
  var canScroll = (function (area) {
524
548
  var scroll = getCurrentScroll(area);
525
549
  if (scroll.x || scroll.y) return true;
526
-
527
- if (area instanceof HTMLDocument) {
550
+ if (area instanceof Document) {
528
551
  if (area.body) return !!(area.body.scrollTop = 1);else return !!(area.documentElement.scrollTop = 1);
529
552
  }
530
-
531
553
  return !!(area.scrollTop = 1);
532
554
  });
533
555
 
534
556
  // @ts-check
557
+
535
558
  /**
536
559
  * Creates the SelectorArea
537
560
  * @return {HTMLDivElement}
538
561
  */
539
-
540
562
  var createSelectorAreaElement = (function () {
541
563
  var node = document.createElement('div');
542
564
  node.style.position = 'fixed';
@@ -547,16 +569,15 @@ var createSelectorAreaElement = (function () {
547
569
  });
548
570
 
549
571
  // @ts-check
572
+
550
573
  /**
551
574
  * Create the selector node
552
575
  * @param {boolean} customStyles
553
576
  * @return {HTMLElement}
554
577
  */
555
-
556
578
  var createSelectorElement = (function (customStyles) {
557
579
  var selector = document.createElement('div');
558
580
  selector.style.position = 'absolute';
559
-
560
581
  if (!customStyles) {
561
582
  selector.style.background = 'rgba(0, 0, 255, 0.1)';
562
583
  selector.style.border = '1px solid rgba(0, 0, 255, 0.45)';
@@ -568,6 +589,7 @@ var createSelectorElement = (function (customStyles) {
568
589
  });
569
590
 
570
591
  // @ts-check
592
+
571
593
  /**
572
594
  * Returns a function, that, as long as it continues to be invoked, will not
573
595
  * be triggered. The function will be called after it stops being called for
@@ -576,32 +598,32 @@ var createSelectorElement = (function (customStyles) {
576
598
  * @param {number} wait
577
599
  * @returns {DSModificationCallback}
578
600
  */
579
-
580
601
  var debounce = (function (func, wait) {
581
- var timeout; // This is the function that is returned and will be executed many times
582
- // We spread (...args) to capture any number of parameters we want to pass
602
+ var timeout;
583
603
 
604
+ // This is the function that is returned and will be executed many times
605
+ // We spread (...args) to capture any number of parameters we want to pass
584
606
  return function () {
585
607
  for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
586
608
  args[_key] = arguments[_key];
587
609
  }
588
-
589
610
  // The callback function to be executed after
590
611
  // the debounce time has elapsed
591
612
  var later = function later() {
592
613
  // null timeout to indicate the debounce ended
593
- timeout = null; // Execute the callback
614
+ timeout = null;
594
615
 
616
+ // Execute the callback
595
617
  func.apply(void 0, args);
596
- }; // This will reset the waiting every function execution.
618
+ };
619
+ // This will reset the waiting every function execution.
597
620
  // This is the step that prevents the function from
598
621
  // being executed because it will never reach the
599
622
  // inside of the previous setTimeout
623
+ clearTimeout(timeout);
600
624
 
601
-
602
- clearTimeout(timeout); // Restart the debounce waiting period.
625
+ // Restart the debounce waiting period.
603
626
  // setTimeout returns a truthy value (it differs in web vs Node)
604
-
605
627
  timeout = setTimeout(later, wait);
606
628
  };
607
629
  });
@@ -609,13 +631,32 @@ var debounce = (function (func, wait) {
609
631
  // @ts-check
610
632
  var documentScroll = (function () {
611
633
  var _document$body, _document$documentEle, _document$body2, _document$documentEle2;
612
-
613
634
  return {
614
635
  y: ((_document$body = document.body) === null || _document$body === void 0 ? void 0 : _document$body.scrollTop) || ((_document$documentEle = document.documentElement) === null || _document$documentEle === void 0 ? void 0 : _document$documentEle.scrollTop) || 0,
615
636
  x: ((_document$body2 = document.body) === null || _document$body2 === void 0 ? void 0 : _document$body2.scrollLeft) || ((_document$documentEle2 = document.documentElement) === null || _document$documentEle2 === void 0 ? void 0 : _document$documentEle2.scrollLeft) || 0
616
637
  };
617
638
  });
618
639
 
640
+ /**
641
+ * @param {DSElement|DSArea} node
642
+ * @returns {DSElements}
643
+ */
644
+ var getAllParentNodes = (function (node) {
645
+ var traverse = function traverse(toWatch) {
646
+ var _toWatch$index;
647
+ var index = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 0;
648
+ var parent = (_toWatch$index = toWatch[index]) === null || _toWatch$index === void 0 ? void 0 : _toWatch$index.parentNode;
649
+ if (parent) {
650
+ toWatch.push(parent);
651
+ index++;
652
+ return traverse(toWatch, index);
653
+ } else {
654
+ return toWatch;
655
+ }
656
+ };
657
+ return traverse([node]);
658
+ });
659
+
619
660
  // @ts-check
620
661
  /**
621
662
  * Returns the top/left/bottom/right/width/height
@@ -625,7 +666,6 @@ var documentScroll = (function () {
625
666
  * @param {number} zoom
626
667
  * @returns {DSBoundingRect}
627
668
  */
628
-
629
669
  var getAreaRect = (function (area, zoom) {
630
670
  if (area instanceof Document) return {
631
671
  top: 0,
@@ -647,11 +687,11 @@ var getAreaRect = (function (area, zoom) {
647
687
  });
648
688
 
649
689
  // @ts-check
690
+
650
691
  /**
651
692
  * @param {DSArea} [area]
652
693
  * @return {Vect2} scroll X/Y
653
694
  */
654
-
655
695
  var getCurrentScroll = (function (area) {
656
696
  if (!area || area instanceof Document) return documentScroll();
657
697
  return {
@@ -661,6 +701,7 @@ var getCurrentScroll = (function (area) {
661
701
  });
662
702
 
663
703
  // @ts-check
704
+
664
705
  /**
665
706
  * Returns the edges that an element is overflowing
666
707
  * @param {Object} p
@@ -669,34 +710,31 @@ var getCurrentScroll = (function (area) {
669
710
  * @param {Vect2} [p.tolerance]
670
711
  * @returns {DSEdges}
671
712
  */
672
-
673
713
  var getOverflowEdges = (function (_ref) {
674
714
  var elementRect = _ref.elementRect,
675
- containerRect = _ref.containerRect,
676
- _ref$tolerance = _ref.tolerance,
677
- tolerance = _ref$tolerance === void 0 ? {
678
- x: 0,
679
- y: 0
680
- } : _ref$tolerance;
715
+ containerRect = _ref.containerRect,
716
+ _ref$tolerance = _ref.tolerance,
717
+ tolerance = _ref$tolerance === void 0 ? {
718
+ x: 0,
719
+ y: 0
720
+ } : _ref$tolerance;
681
721
  var edges = [];
682
722
  if (elementRect.top - tolerance.y < containerRect.top) edges.push('top');
683
723
  if (elementRect.left - tolerance.x < containerRect.left) edges.push('left');
684
724
  if (elementRect.bottom + tolerance.y > containerRect.bottom) edges.push('bottom');
685
725
  if (elementRect.right + tolerance.y > containerRect.right) edges.push('right');
686
- return (
687
- /** @type {DSEdges} */
688
- edges
726
+ return (/** @type {DSEdges} */edges
689
727
  );
690
728
  });
691
729
 
692
730
  // @ts-check
731
+
693
732
  /**
694
733
  * Returns cursor x, y position based on event object
695
734
  * @param {Object} p
696
- * @param {MouseEvent|Touch} p.event
735
+ * @param {MouseEvent|Touch|PointerEvent} p.event
697
736
  * @return {Vect2} cursor X/Y position
698
737
  */
699
-
700
738
  var getPointerPos = (function (_ref) {
701
739
  var event = _ref.event;
702
740
  return {
@@ -711,12 +749,10 @@ var getPointerPos = (function (_ref) {
711
749
  * @param {{ scrollAmount:Vect2, initialPointerPos:Vect2, pointerPos:Vect2 }} p
712
750
  * @returns {{left:number,top:number,width:number,height:number}}
713
751
  */
714
-
715
752
  var getSelectorPosition = (function (_ref) {
716
753
  var scrollAmount = _ref.scrollAmount,
717
- initialPointerPos = _ref.initialPointerPos,
718
- pointerPos = _ref.pointerPos;
719
-
754
+ initialPointerPos = _ref.initialPointerPos,
755
+ pointerPos = _ref.pointerPos;
720
756
  /** check for direction
721
757
  *
722
758
  * This is quite complicated, so also quite complicated to explain. Lemme’ try:
@@ -755,39 +791,38 @@ var getSelectorPosition = (function (_ref) {
755
791
  *
756
792
  * I hope that makes sense. Try stuff out and play around with variables to get a hang of it.
757
793
  */
758
- var selectorPos = {}; // right
794
+ var selectorPos = {};
759
795
 
796
+ // right
760
797
  if (pointerPos.x > initialPointerPos.x - scrollAmount.x) {
761
798
  // 1.
762
799
  selectorPos.left = initialPointerPos.x - scrollAmount.x; // 2.
763
-
764
800
  selectorPos.width = pointerPos.x - initialPointerPos.x + scrollAmount.x; // 3.
765
801
  // left
766
802
  } else {
767
803
  // 1b.
768
804
  selectorPos.left = pointerPos.x; // 2b.
769
-
770
805
  selectorPos.width = initialPointerPos.x - pointerPos.x - scrollAmount.x; // 3b.
771
- } // bottom
772
-
806
+ }
773
807
 
808
+ // bottom
774
809
  if (pointerPos.y > initialPointerPos.y - scrollAmount.y) {
775
810
  selectorPos.top = initialPointerPos.y - scrollAmount.y;
776
- selectorPos.height = pointerPos.y - initialPointerPos.y + scrollAmount.y; // top
811
+ selectorPos.height = pointerPos.y - initialPointerPos.y + scrollAmount.y;
812
+ // top
777
813
  } else {
778
814
  selectorPos.top = pointerPos.y;
779
815
  selectorPos.height = initialPointerPos.y - pointerPos.y - scrollAmount.y;
780
816
  }
781
-
782
817
  return selectorPos;
783
818
  });
784
819
 
785
820
  // @ts-check
821
+
786
822
  /**
787
823
  * @param {DSElement} element
788
824
  * @return {Vect2}
789
825
  */
790
-
791
826
  var getComputedTranslatePositions = function getComputedTranslatePositions(element) {
792
827
  var position = {
793
828
  x: 0,
@@ -795,40 +830,31 @@ var getComputedTranslatePositions = function getComputedTranslatePositions(eleme
795
830
  };
796
831
  var computed = window.getComputedStyle(element);
797
832
  if (!computed.transform || computed.transform === 'none') return position;
798
-
799
833
  if (computed.transform.indexOf('3d') >= 0) {
800
834
  var match = computed.transform.trim().match(/matrix3d\((.*?)\)/);
801
-
802
835
  if (match && match.length) {
803
836
  var _match$;
804
-
805
837
  var values = (_match$ = match[1]) === null || _match$ === void 0 ? void 0 : _match$.split(',');
806
838
  position.x = parseInt(values[12]) || 0;
807
839
  position.y = parseInt(values[13]) || 0;
808
840
  }
809
-
810
841
  return position;
811
842
  } else {
812
843
  var _match = computed.transform.trim().match(/matrix\((.*?)\)/);
813
-
814
844
  if (_match && _match.length) {
815
845
  var _match$2;
816
-
817
846
  var _values = (_match$2 = _match[1]) === null || _match$2 === void 0 ? void 0 : _match$2.split(',');
818
-
819
847
  position.x = parseInt(_values[4]) || 0;
820
848
  position.y = parseInt(_values[5]) || 0;
821
849
  }
822
-
823
850
  return position;
824
851
  }
825
852
  };
853
+
826
854
  /**
827
855
  * @param {DSElement} element
828
856
  * @return {Vect2}
829
857
  */
830
-
831
-
832
858
  var getTranslatedPositions = function getTranslatedPositions(element) {
833
859
  var transform = element.style.transform;
834
860
  if (!transform || transform.indexOf('translate') < 0) return getComputedTranslatePositions(element);
@@ -837,37 +863,32 @@ var getTranslatedPositions = function getTranslatedPositions(element) {
837
863
  y: 0
838
864
  };
839
865
  var match = transform.trim().match(/translate[3dD]*?\(.*?\)/);
840
-
841
866
  if (match) {
842
867
  var _match$3;
843
-
844
868
  var split = (_match$3 = match[0]) === null || _match$3 === void 0 ? void 0 : _match$3.split('(');
845
-
846
869
  if (split) {
847
870
  var _split$;
848
-
849
871
  var values = (_split$ = split[1]) === null || _split$ === void 0 ? void 0 : _split$.split(',');
850
872
  position.x = parseInt(values[0]) || 0;
851
873
  position.y = parseInt(values[1]) || 0;
852
874
  }
853
875
  }
854
-
855
876
  if (!position.x && !position.x) return getComputedTranslatePositions(element);
856
877
  return position;
857
878
  };
879
+
858
880
  /**
859
881
  * @param {DSElement} element
860
882
  * @return {Vect2}
861
883
  */
862
-
863
-
864
884
  var getTopLeftPosition = function getTopLeftPosition(element) {
865
885
  var style = element.style;
866
886
  var position = {
867
887
  x: parseInt(style.left) || 0,
868
888
  y: parseInt(style.top) || 0
869
- }; // initial positions
889
+ };
870
890
 
891
+ // initial positions
871
892
  if (!position.x && !position.x) {
872
893
  var computed = window.getComputedStyle(element);
873
894
  return {
@@ -875,9 +896,9 @@ var getTopLeftPosition = function getTopLeftPosition(element) {
875
896
  y: parseInt(computed.top) || 0
876
897
  };
877
898
  }
878
-
879
899
  return position;
880
900
  };
901
+
881
902
  /**
882
903
  * Returns the X and Y coordinates based on styles
883
904
  * Can handle translate and top/left
@@ -885,13 +906,12 @@ var getTopLeftPosition = function getTopLeftPosition(element) {
885
906
  * @param {boolean} [useTranslate]
886
907
  * @return {Vect2}
887
908
  */
888
-
889
-
890
909
  var getStylePosition = (function (element, useTranslate) {
891
910
  if (useTranslate) return getTranslatedPositions(element);else return getTopLeftPosition(element);
892
911
  });
893
912
 
894
913
  // @ts-check
914
+
895
915
  /**
896
916
  * pushes element back the overflow amount
897
917
  * (top - top gives overflow, then new position pushed back by overflow)
@@ -903,36 +923,31 @@ var getStylePosition = (function (element, useTranslate) {
903
923
  * @param {Vect2} p.elementPos
904
924
  * @param {boolean} p.useTransform
905
925
  */
906
-
907
926
  var handleElementOverflow = (function (_ref) {
908
927
  var element = _ref.element,
909
- edges = _ref.edges,
910
- elementRect = _ref.elementRect,
911
- containerRect = _ref.containerRect,
912
- elementPos = _ref.elementPos,
913
- useTransform = _ref.useTransform;
914
-
928
+ edges = _ref.edges,
929
+ elementRect = _ref.elementRect,
930
+ containerRect = _ref.containerRect,
931
+ elementPos = _ref.elementPos,
932
+ useTransform = _ref.useTransform;
915
933
  if (edges.includes('top')) {
916
934
  setStylePosition(element, {
917
935
  y: elementPos.y + containerRect.top - elementRect.top,
918
936
  x: elementPos.x
919
937
  }, useTransform);
920
938
  }
921
-
922
939
  if (edges.includes('left')) {
923
940
  setStylePosition(element, {
924
941
  y: elementPos.y,
925
942
  x: elementPos.x + containerRect.left - elementRect.left
926
943
  }, useTransform);
927
944
  }
928
-
929
945
  if (edges.includes('bottom')) {
930
946
  setStylePosition(element, {
931
947
  y: elementPos.y + containerRect.bottom - elementRect.bottom,
932
948
  x: elementPos.x
933
949
  }, useTransform);
934
950
  }
935
-
936
951
  if (edges.includes('right')) {
937
952
  setStylePosition(element, {
938
953
  y: elementPos.y,
@@ -942,28 +957,28 @@ var handleElementOverflow = (function (_ref) {
942
957
  });
943
958
 
944
959
  // @ts-check
960
+
945
961
  /**
946
962
  * Fix: some elements have to have a special position attribute for calculations
947
963
  * @param {Object} p
948
964
  * @param {CSSStyleDeclaration} p.computedStyle
949
965
  * @param {DSArea} p.node
950
966
  */
951
-
952
967
  var handleElementPositionAttribute = (function (_ref) {
953
968
  var computedStyle = _ref.computedStyle,
954
- node = _ref.node;
969
+ node = _ref.node;
955
970
  var position = computedStyle.position;
956
971
  var isPositioned = position === 'absolute' || position === 'relative' || position === 'fixed';
957
- if (!(node instanceof HTMLDocument) && !isPositioned) node.style.position = 'relative';
972
+ if (!(node instanceof Document) && !isPositioned) node.style.position = 'relative';
958
973
  });
959
974
 
960
975
  // @ts-check
976
+
961
977
  /**
962
978
  * @typedef {function} ScrollCallback
963
979
  * @property {Array.<'top'|'bottom'|'left'|'right'|undefined>} directions
964
980
  * @property {number} multiplier
965
981
  */
966
-
967
982
  /**
968
983
  * @param {Object} p
969
984
  * @param {string} p.key the keyboard key that was pressed
@@ -976,46 +991,41 @@ var handleElementPositionAttribute = (function (_ref) {
976
991
  * @param {DSDragKeys} p.dragKeys
977
992
  * @returns {Vect2}
978
993
  */
979
-
980
994
  var handleKeyboardDragPosDifference = (function (_ref) {
981
995
  var shiftKey = _ref.shiftKey,
982
- keyboardDragSpeed = _ref.keyboardDragSpeed,
983
- zoom = _ref.zoom,
984
- key = _ref.key,
985
- dragKeys = _ref.dragKeys,
986
- scrollDiff = _ref.scrollDiff,
987
- canScroll = _ref.canScroll,
988
- scrollCallback = _ref.scrollCallback;
996
+ keyboardDragSpeed = _ref.keyboardDragSpeed,
997
+ zoom = _ref.zoom,
998
+ key = _ref.key,
999
+ dragKeys = _ref.dragKeys,
1000
+ scrollDiff = _ref.scrollDiff,
1001
+ canScroll = _ref.canScroll,
1002
+ scrollCallback = _ref.scrollCallback;
989
1003
  var posDirection = {
990
1004
  x: 0,
991
1005
  y: 0
992
1006
  };
993
1007
  var increase = shiftKey ? keyboardDragSpeed * 4 * zoom : keyboardDragSpeed * zoom;
994
-
995
1008
  if (dragKeys.left.includes(key)) {
996
1009
  posDirection.x = scrollDiff.x || -increase;
997
1010
  if (!shiftKey && !scrollDiff.x && canScroll) scrollCallback(['left'], keyboardDragSpeed);
998
1011
  }
999
-
1000
1012
  if (dragKeys.right.includes(key)) {
1001
1013
  posDirection.x = scrollDiff.x || increase;
1002
1014
  if (!shiftKey && !scrollDiff.x && canScroll) scrollCallback(['right'], keyboardDragSpeed);
1003
1015
  }
1004
-
1005
1016
  if (dragKeys.up.includes(key)) {
1006
1017
  posDirection.y = scrollDiff.y || -increase;
1007
1018
  if (!shiftKey && !scrollDiff.y && canScroll) scrollCallback(['top'], keyboardDragSpeed);
1008
1019
  }
1009
-
1010
1020
  if (dragKeys.down.includes(key)) {
1011
1021
  posDirection.y = scrollDiff.y || increase;
1012
1022
  if (!shiftKey && !scrollDiff.y && canScroll) scrollCallback(['bottom'], keyboardDragSpeed);
1013
1023
  }
1014
-
1015
1024
  return posDirection;
1016
1025
  });
1017
1026
 
1018
1027
  // @ts-check
1028
+
1019
1029
  /**
1020
1030
  * Logic when an element is selected
1021
1031
  * @param {Object} p
@@ -1025,19 +1035,19 @@ var handleKeyboardDragPosDifference = (function (_ref) {
1025
1035
  * @param {Set} p.SelectedSet
1026
1036
  * @param {string} p.hoverClassName
1027
1037
  */
1028
-
1029
1038
  var handleSelection = (function (_ref) {
1030
1039
  var element = _ref.element,
1031
- force = _ref.force,
1032
- multiSelectionToggle = _ref.multiSelectionToggle,
1033
- SelectedSet = _ref.SelectedSet,
1034
- hoverClassName = _ref.hoverClassName;
1040
+ force = _ref.force,
1041
+ multiSelectionToggle = _ref.multiSelectionToggle,
1042
+ SelectedSet = _ref.SelectedSet,
1043
+ hoverClassName = _ref.hoverClassName;
1035
1044
  if (element.classList.contains(hoverClassName) && !force) return;
1036
1045
  if (!SelectedSet.has(element)) SelectedSet.add(element);else if (multiSelectionToggle) SelectedSet["delete"](element);
1037
1046
  element.classList.add(hoverClassName);
1038
1047
  });
1039
1048
 
1040
1049
  // @ts-check
1050
+
1041
1051
  /**
1042
1052
  * Logic when an element is de-selected
1043
1053
  * @param {Object} p
@@ -1047,16 +1057,16 @@ var handleSelection = (function (_ref) {
1047
1057
  * @param {Set} p.PrevSelectedSet
1048
1058
  * @param {string} p.hoverClassName
1049
1059
  */
1050
-
1051
1060
  var handleUnSelection = (function (_ref) {
1052
1061
  var element = _ref.element,
1053
- force = _ref.force,
1054
- SelectedSet = _ref.SelectedSet,
1055
- PrevSelectedSet = _ref.PrevSelectedSet,
1056
- hoverClassName = _ref.hoverClassName;
1062
+ force = _ref.force,
1063
+ SelectedSet = _ref.SelectedSet,
1064
+ PrevSelectedSet = _ref.PrevSelectedSet,
1065
+ hoverClassName = _ref.hoverClassName;
1057
1066
  if (!element.classList.contains(hoverClassName) && !force) return false;
1058
1067
  var inSelection = SelectedSet.has(element);
1059
1068
  var inPrevSelection = PrevSelectedSet.has(element);
1069
+
1060
1070
  /**
1061
1071
  * Special for issue #9.
1062
1072
  * if a multi-select-key is pressed, ds 'remembers' the last selection and reverts
@@ -1064,7 +1074,6 @@ var handleUnSelection = (function (_ref) {
1064
1074
  * = if item was selected and is not in selection anymore, reselect it
1065
1075
  * = if item was not selected and is not in selection anymore, unselect it
1066
1076
  */
1067
-
1068
1077
  if (inSelection && !inPrevSelection) SelectedSet["delete"](element);else if (!inSelection && inPrevSelection) SelectedSet.add(element);
1069
1078
  element.classList.remove(hoverClassName);
1070
1079
  });
@@ -1078,6 +1087,7 @@ var handleUnSelection = (function (_ref) {
1078
1087
  var wrongTypeWarn = function wrongTypeWarn(key, type, fallback) {
1079
1088
  return console.warn("[DragSelect] TypeIssue: setting \"".concat(key, "\" is not of type \"").concat(type, "\"."));
1080
1089
  };
1090
+
1081
1091
  /**
1082
1092
  * @param {string} key
1083
1093
  * @param {*} value
@@ -1085,67 +1095,67 @@ var wrongTypeWarn = function wrongTypeWarn(key, type, fallback) {
1085
1095
  * @param {*} fallback
1086
1096
  * @returns {object}
1087
1097
  */
1088
-
1089
-
1090
1098
  var hydrateHelper = function hydrateHelper(key, value, withFallback, fallback) {
1091
1099
  // no value available
1092
- if (value === undefined) return withFallback ? _defineProperty({}, key, fallback) : {}; // force unsetting of a value
1093
-
1094
- if (value === null) return _defineProperty({}, key, null); // TypeCheck [GENERIC]
1100
+ if (value === undefined) return withFallback ? _defineProperty({}, key, fallback) : {};
1101
+ // force unsetting of a value
1102
+ if (value === null) return _defineProperty({}, key, null);
1095
1103
 
1104
+ // TypeCheck [GENERIC]
1096
1105
  var isAvailable = true; // if it’s not undefined, it was set voluntarily
1106
+ var forceFallback = false;
1097
1107
 
1098
- var forceFallback = false; // TypeCheck [String]
1099
-
1108
+ // TypeCheck [String]
1100
1109
  var expectedString = typeof fallback === 'string';
1101
1110
  if (expectedString) isAvailable = typeof value === 'string' || value instanceof String;
1102
-
1103
1111
  if (expectedString && !isAvailable) {
1104
1112
  forceFallback = true;
1105
1113
  wrongTypeWarn(key, 'string');
1106
- } // TypeCheck [Number]
1107
-
1114
+ }
1108
1115
 
1116
+ // TypeCheck [Number]
1109
1117
  var expectedNumber = !isNaN(fallback) && typeof fallback === 'number';
1110
1118
  if (expectedNumber) isAvailable = !isNaN(value) && typeof value === 'number';
1111
-
1112
1119
  if (expectedNumber && !isAvailable) {
1113
1120
  forceFallback = true;
1114
1121
  wrongTypeWarn(key, 'number');
1115
- } // TypeCheck [Object]
1116
-
1122
+ }
1117
1123
 
1124
+ // TypeCheck [Object]
1118
1125
  var expectedObject = Object.prototype.toString.call(fallback) === "[object Object]";
1119
1126
  if (expectedObject) isAvailable = Object.prototype.toString.call(value) === "[object Object]";
1120
-
1121
1127
  if (expectedObject && !isAvailable) {
1122
1128
  forceFallback = true;
1123
1129
  wrongTypeWarn(key, 'object');
1124
- } // TypeCheck [Boolean]
1125
-
1130
+ }
1126
1131
 
1132
+ // TypeCheck [Boolean]
1127
1133
  var expectedBoolean = typeof fallback === "boolean";
1128
1134
  if (expectedBoolean) isAvailable = typeof value === "boolean";
1129
-
1130
1135
  if (expectedBoolean && !isAvailable) {
1131
1136
  forceFallback = true;
1132
1137
  wrongTypeWarn(key, 'boolean');
1133
- } // TypeCheck [Array]
1134
-
1138
+ }
1135
1139
 
1140
+ // TypeCheck [Array]
1136
1141
  var expectedArray = Array.isArray(fallback);
1137
1142
  if (expectedArray) isAvailable = Array.isArray(value);
1138
-
1139
1143
  if (expectedArray && !isAvailable) {
1140
1144
  forceFallback = true;
1141
1145
  wrongTypeWarn(key, 'array');
1142
1146
  }
1147
+ var isFallback = forceFallback || withFallback;
1143
1148
 
1144
- var isFallback = forceFallback || withFallback; // Special rule for [dragKeys]
1145
-
1149
+ // Special rule for [dragKeys]
1146
1150
  if (key === 'dragKeys' && isAvailable) return _defineProperty({}, key, Object.assign(fallback, value));else if (key === 'dragKeys' && !isAvailable) return isFallback ? _defineProperty({}, key, fallback) : {};
1151
+
1152
+ // Special rule for [dropZones]
1153
+ if (key === 'dropZones' && isAvailable && new Set(value.map(function (v) {
1154
+ return v.id;
1155
+ })).size !== value.length) console.warn("[DragSelect] UniqueConstraintsIssue: setting \"dropZones\" contains duplicate ids.");
1147
1156
  return isAvailable ? _defineProperty({}, key, value) : isFallback ? _defineProperty({}, key, fallback) : {};
1148
1157
  };
1158
+
1149
1159
  /**
1150
1160
  * This helper method creates the setting object,
1151
1161
  * - if the settings provided are of wrong type, the fallback value will be used
@@ -1156,18 +1166,16 @@ var hydrateHelper = function hydrateHelper(key, value, withFallback, fallback) {
1156
1166
  * @param {Settings} settings
1157
1167
  * @param {boolean} withFallback
1158
1168
  */
1159
-
1160
-
1161
1169
  var hydrateSettings = (function (settings, withFallback) {
1162
- return _objectSpread2(_objectSpread2(_objectSpread2(_objectSpread2(_objectSpread2(_objectSpread2(_objectSpread2(_objectSpread2(_objectSpread2(_objectSpread2(_objectSpread2(_objectSpread2(_objectSpread2(_objectSpread2(_objectSpread2(_objectSpread2(_objectSpread2(_objectSpread2(_objectSpread2(_objectSpread2(_objectSpread2({}, hydrateHelper('area', settings.area, withFallback, document)), hydrateHelper('selectables', settings.selectables, withFallback, null)), hydrateHelper('autoScrollSpeed', settings.autoScrollSpeed, withFallback, 5)), hydrateHelper('overflowTolerance', settings.overflowTolerance, withFallback, {
1170
+ return _objectSpread2(_objectSpread2(_objectSpread2(_objectSpread2(_objectSpread2(_objectSpread2(_objectSpread2(_objectSpread2(_objectSpread2(_objectSpread2(_objectSpread2(_objectSpread2(_objectSpread2(_objectSpread2(_objectSpread2(_objectSpread2(_objectSpread2(_objectSpread2(_objectSpread2(_objectSpread2(_objectSpread2(_objectSpread2(_objectSpread2(_objectSpread2(_objectSpread2(_objectSpread2(_objectSpread2(_objectSpread2(_objectSpread2(_objectSpread2(_objectSpread2(_objectSpread2(_objectSpread2(_objectSpread2({}, hydrateHelper('area', settings.area, withFallback, document)), hydrateHelper('selectables', settings.selectables, withFallback, null)), hydrateHelper('autoScrollSpeed', settings.autoScrollSpeed, withFallback, 5)), hydrateHelper('overflowTolerance', settings.overflowTolerance, withFallback, {
1163
1171
  x: 25,
1164
1172
  y: 25
1165
- })), hydrateHelper('zoom', settings.zoom, withFallback, 1)), hydrateHelper('customStyles', settings.customStyles, withFallback, false)), hydrateHelper('multiSelectMode', settings.multiSelectMode, withFallback, false)), hydrateHelper('multiSelectToggling', settings.multiSelectToggling, withFallback, true)), hydrateHelper('multiSelectKeys', settings.multiSelectKeys, withFallback, ['Control', 'Shift', 'Meta'])), hydrateHelper('selector', settings.selector, withFallback, null)), hydrateHelper('draggability', settings.draggability, withFallback, true)), hydrateHelper('immediateDrag', settings.immediateDrag, withFallback, true)), hydrateHelper('keyboardDrag', settings.keyboardDrag, withFallback, true)), hydrateHelper('dragKeys', settings.dragKeys, withFallback, {
1173
+ })), hydrateHelper('zoom', settings.zoom, withFallback, 1)), hydrateHelper('customStyles', settings.customStyles, withFallback, false)), hydrateHelper('multiSelectMode', settings.multiSelectMode, withFallback, false)), hydrateHelper('multiSelectToggling', settings.multiSelectToggling, withFallback, true)), hydrateHelper('multiSelectKeys', settings.multiSelectKeys, withFallback, ['Control', 'Shift', 'Meta'])), hydrateHelper('selector', settings.selector, withFallback, null)), hydrateHelper('selectionThreshold', settings.selectionThreshold, withFallback, 0)), hydrateHelper('draggability', settings.draggability, withFallback, true)), hydrateHelper('immediateDrag', settings.immediateDrag, withFallback, true)), hydrateHelper('keyboardDrag', settings.keyboardDrag, withFallback, true)), hydrateHelper('dragKeys', settings.dragKeys, withFallback, {
1166
1174
  up: ['ArrowUp'],
1167
1175
  down: ['ArrowDown'],
1168
1176
  left: ['ArrowLeft'],
1169
1177
  right: ['ArrowRight']
1170
- })), hydrateHelper('keyboardDragSpeed', settings.keyboardDragSpeed, withFallback, 10)), hydrateHelper('useTransform', settings.useTransform, withFallback, true)), hydrateHelper('hoverClass', settings.hoverClass, withFallback, 'ds-hover')), hydrateHelper('selectableClass', settings.selectableClass, withFallback, 'ds-selectable')), hydrateHelper('selectedClass', settings.selectedClass, withFallback, 'ds-selected')), hydrateHelper('selectorClass', settings.selectorClass, withFallback, 'ds-selector')), hydrateHelper('selectorAreaClass', settings.selectorAreaClass, withFallback, 'ds-selector-area'));
1178
+ })), hydrateHelper('keyboardDragSpeed', settings.keyboardDragSpeed, withFallback, 10)), hydrateHelper('useTransform', settings.useTransform, withFallback, true)), hydrateHelper('refreshMemoryRate', settings.refreshMemoryRate, withFallback, 80)), hydrateHelper('dropZones', settings.dropZones, withFallback, [])), hydrateHelper('dropInsideThreshold', settings.dropInsideThreshold, withFallback, 1)), hydrateHelper('dropTargetThreshold', settings.dropTargetThreshold, withFallback, 0)), hydrateHelper('usePointerEvents', settings.usePointerEvents, withFallback, false)), hydrateHelper('hoverClass', settings.hoverClass, withFallback, 'ds-hover')), hydrateHelper('selectableClass', settings.selectableClass, withFallback, 'ds-selectable')), hydrateHelper('selectedClass', settings.selectedClass, withFallback, 'ds-selected')), hydrateHelper('selectorClass', settings.selectorClass, withFallback, 'ds-selector')), hydrateHelper('selectorAreaClass', settings.selectorAreaClass, withFallback, 'ds-selector-area')), hydrateHelper('droppedTargetClass', settings.droppedTargetClass, withFallback, 'ds-dropped-target')), hydrateHelper('droppedInsideClass', settings.droppedInsideClass, withFallback, 'ds-dropped-inside')), hydrateHelper('droppableClass', settings.droppableClass, withFallback, 'ds-droppable')), hydrateHelper('dropZoneClass', settings.dropZoneClass, withFallback, 'ds-dropzone')), hydrateHelper('dropZoneReadyClass', settings.dropZoneReadyClass, withFallback, 'ds-dropzone-ready')), hydrateHelper('dropZoneTargetClass', settings.dropZoneTargetClass, withFallback, 'ds-dropzone-target')), hydrateHelper('dropZoneInsideClass', settings.dropZoneInsideClass, withFallback, 'ds-dropzone-inside'));
1171
1179
  });
1172
1180
 
1173
1181
  // @ts-check
@@ -1192,19 +1200,41 @@ var hydrateSettings = (function (settings, withFallback) {
1192
1200
  * {@link https://developer.mozilla.org/en-US/docs/Games/Techniques/2D_collision_detection MDN}
1193
1201
  * @param {{left:number,right:number,top:number,bottom:number}} el1
1194
1202
  * @param {{left:number,right:number,top:number,bottom:number}} el2
1203
+ * @param {number} [percent=0]
1204
+ * 1 = the element has to be completely inside the other element
1205
+ * 0.8 = the element has to be 80% inside the other element
1206
+ * 0.5 = the element has to be 50% inside the other element
1207
+ * 0.2 = the element has to be 20% inside the other element
1208
+ * 0 = the element only has to touch the other element
1195
1209
  * @returns {boolean}
1196
1210
  */
1197
-
1198
1211
  var isCollision = (function (el1, el2) {
1199
- if (el1.left < el2.right && // 1.
1200
- el1.right > el2.left && // 2.
1201
- el1.top < el2.bottom && // 3.
1202
- el1.bottom > el2.top // 4.
1203
- ) return true; // collision detected!
1212
+ var percent = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 0;
1213
+ var element1 = el1;
1214
+ if (percent > 0) {
1215
+ var widthPoint = (el1.right - el1.left) * percent;
1216
+ var heightPoint = (el1.bottom - el1.top) * percent;
1217
+ element1 = {
1218
+ left: el1.left + widthPoint,
1219
+ right: el1.right - widthPoint,
1220
+ top: el1.top + heightPoint,
1221
+ bottom: el1.bottom - heightPoint
1222
+ };
1223
+ }
1224
+ if (element1.left < el2.right &&
1225
+ // 1.
1226
+ element1.right > el2.left &&
1227
+ // 2.
1228
+ element1.top < el2.bottom &&
1229
+ // 3.
1230
+ element1.bottom > el2.top // 4.
1231
+ ) return true;
1232
+ // collision detected!
1204
1233
  else return false;
1205
1234
  });
1206
1235
 
1207
1236
  // @ts-check
1237
+
1208
1238
  /**
1209
1239
  * Moves the element in a posDirection
1210
1240
  * @param {Object} p
@@ -1213,12 +1243,11 @@ var isCollision = (function (el1, el2) {
1213
1243
  * @param {DSBoundingRect} p.containerRect
1214
1244
  * @param {boolean} p.useTransform
1215
1245
  */
1216
-
1217
1246
  var moveElement = (function (_ref) {
1218
1247
  var element = _ref.element,
1219
- posDirection = _ref.posDirection,
1220
- containerRect = _ref.containerRect,
1221
- useTransform = _ref.useTransform;
1248
+ posDirection = _ref.posDirection,
1249
+ containerRect = _ref.containerRect,
1250
+ useTransform = _ref.useTransform;
1222
1251
  var elementPos = getStylePosition(element, useTransform);
1223
1252
  var newPos = calc(elementPos, '+', posDirection);
1224
1253
  setStylePosition(element, newPos, useTransform);
@@ -1238,12 +1267,12 @@ var moveElement = (function (_ref) {
1238
1267
  });
1239
1268
 
1240
1269
  // @ts-check
1270
+
1241
1271
  /**
1242
1272
  * Removes event-listeners to the selectorArea
1243
1273
  * @param {MutationObserver} modificationObserver
1244
1274
  * @param {DSModificationCallback} callback
1245
1275
  */
1246
-
1247
1276
  var removeModificationObservers = (function (modificationObserver, callback) {
1248
1277
  window.removeEventListener('resize', callback);
1249
1278
  window.removeEventListener('scroll', callback);
@@ -1251,27 +1280,21 @@ var removeModificationObservers = (function (modificationObserver, callback) {
1251
1280
  });
1252
1281
 
1253
1282
  // @ts-check
1283
+
1254
1284
  /**
1255
1285
  * Scroll the element in the specified direction
1256
1286
  * @param {DSArea} element
1257
1287
  * @param {Array.<'top'|'bottom'|'left'|'right'|undefined>} directions
1258
1288
  * @param {number} multiplier
1259
1289
  */
1260
-
1261
1290
  var scrollElement = (function (element, directions, multiplier) {
1262
1291
  if (!directions.length) return;
1263
1292
  var docEl = document && document.documentElement && document.documentElement.scrollTop && document.documentElement;
1264
-
1265
- var _element = element instanceof HTMLDocument ? docEl || document.body : element;
1266
-
1293
+ var _element = element instanceof Document ? docEl || document.body : element;
1267
1294
  var scrollTop = directions.includes('top') && _element.scrollTop > 0;
1268
-
1269
1295
  var scrollBot = directions.includes('bottom') && _element.scrollTop < _element.scrollHeight;
1270
-
1271
1296
  var scrollLeft = directions.includes('left') && _element.scrollLeft > 0;
1272
-
1273
1297
  var scrollRight = directions.includes('right') && _element.scrollLeft < _element.scrollWidth;
1274
-
1275
1298
  if (scrollTop) _element.scrollTop -= 1 * multiplier;
1276
1299
  if (scrollBot) _element.scrollTop += 1 * multiplier;
1277
1300
  if (scrollLeft) _element.scrollLeft -= 1 * multiplier;
@@ -1279,6 +1302,7 @@ var scrollElement = (function (element, directions, multiplier) {
1279
1302
  });
1280
1303
 
1281
1304
  // @ts-check
1305
+
1282
1306
  /**
1283
1307
  * Sets the style position to the X and Y coordinates
1284
1308
  * Can handle translate and top/left
@@ -1287,7 +1311,6 @@ var scrollElement = (function (element, directions, multiplier) {
1287
1311
  * @param {boolean} [useTranslate]
1288
1312
  * @return {DSElement}
1289
1313
  */
1290
-
1291
1314
  var setStylePosition = (function (element, values, useTranslate) {
1292
1315
  if (useTranslate) {
1293
1316
  var prevTransform = element.style.transform;
@@ -1296,7 +1319,6 @@ var setStylePosition = (function (element, values, useTranslate) {
1296
1319
  element.style.left = "".concat(values.x, "px");
1297
1320
  element.style.top = "".concat(values.y, "px");
1298
1321
  }
1299
-
1300
1322
  return element;
1301
1323
  });
1302
1324
 
@@ -1306,7 +1328,6 @@ var setStylePosition = (function (element, values, useTranslate) {
1306
1328
  * @param {DSCallback} callback
1307
1329
  * @returns {number} event id, can be used to unsubscribe more efficiently
1308
1330
  */
1309
-
1310
1331
  /**
1311
1332
  * @typedef {function} DSPublish
1312
1333
  * @param {DSCallbackNames} eventName
@@ -1321,13 +1342,14 @@ var setStylePosition = (function (element, values, useTranslate) {
1321
1342
  * @param {DSPublish} p.publish
1322
1343
  * @param {Interaction} p.Interaction
1323
1344
  * @param {SelectedSet} p.SelectedSet
1345
+ * @param {DropZones} p.DropZones
1324
1346
  */
1325
-
1326
1347
  var subscriberAliases = (function (_ref) {
1327
1348
  var subscribe = _ref.subscribe,
1328
- publish = _ref.publish,
1329
- Interaction = _ref.Interaction,
1330
- SelectedSet = _ref.SelectedSet;
1349
+ publish = _ref.publish,
1350
+ Interaction = _ref.Interaction,
1351
+ SelectedSet = _ref.SelectedSet,
1352
+ DropZones = _ref.DropZones;
1331
1353
  var mapping = {
1332
1354
  'Selected:added': [{
1333
1355
  name: 'elementselect'
@@ -1343,61 +1365,66 @@ var subscriberAliases = (function (_ref) {
1343
1365
  name: 'dragstart'
1344
1366
  }],
1345
1367
  // event, isDraggingKeyboard
1346
- 'Interaction:update': [{
1368
+ 'Interaction:update': [
1369
+ // event, isDraggingKeyboard
1370
+ {
1347
1371
  name: 'dragmove',
1348
1372
  condition: function condition(data) {
1349
1373
  return data.event;
1350
1374
  }
1351
1375
  }],
1376
+ 'Interaction:end': [
1352
1377
  // event, isDraggingKeyboard
1353
- 'Interaction:end': [{
1354
- name: 'callback'
1355
- }] // event, isDraggingKeyboard
1356
-
1378
+ {
1379
+ name: 'callback',
1380
+ extraData: function extraData() {
1381
+ var target = DropZones.getTarget();
1382
+ return _objectSpread2({}, target ? {
1383
+ dropTarget: target.toObject()
1384
+ } : {});
1385
+ }
1386
+ }]
1357
1387
  };
1358
-
1359
1388
  var _loop = function _loop() {
1360
1389
  var _Object$entries$_i = _slicedToArray(_Object$entries[_i], 2),
1361
- sub_name = _Object$entries$_i[0],
1362
- pubs = _Object$entries$_i[1];
1363
-
1390
+ sub_name = _Object$entries$_i[0],
1391
+ pubs = _Object$entries$_i[1];
1364
1392
  ['pre', false].forEach(function (filler) {
1365
1393
  return subscribe(filler ? "".concat(sub_name, ":").concat(filler) : sub_name, function (data) {
1366
1394
  return pubs.forEach(function (pub) {
1367
- return (!pub.condition || pub.condition(data)) && publish(filler ? "".concat(filler).concat(pub.name) : pub.name, _objectSpread2({
1395
+ return (!pub.condition || pub.condition(data)) && publish(filler ? "".concat(filler).concat(pub.name) : pub.name, _objectSpread2(_objectSpread2({
1368
1396
  items: SelectedSet.elements,
1369
1397
  isDragging: Interaction.isDragging
1370
- }, data));
1398
+ }, data), pub.extraData ? pub.extraData(data) : {}));
1371
1399
  });
1372
1400
  });
1373
1401
  });
1374
1402
  };
1375
-
1376
1403
  for (var _i = 0, _Object$entries = Object.entries(mapping); _i < _Object$entries.length; _i++) {
1377
1404
  _loop();
1378
1405
  }
1379
1406
  });
1380
1407
 
1381
1408
  /**
1382
- * Transforms any list or single item to an array so user doesn’t have to care.
1409
+ * Transforms any list or single dom node to an array so user doesn’t have to care. Also removes duplicates.
1383
1410
  * @param {DSInputElements} items a single item, a Node-list or any element group
1384
1411
  * @return {DSElements}
1385
1412
  */
1386
-
1387
1413
  var toArray = (function (items) {
1388
1414
  if (!items) return [];
1389
1415
  if (!Array.isArray(items) && (items instanceof HTMLElement || items instanceof SVGElement)) return [items];
1390
- return _toConsumableArray(items);
1416
+ // @ts-ignore
1417
+ return _toConsumableArray(new Set(_toConsumableArray(items)));
1391
1418
  });
1392
1419
 
1393
1420
  // @ts-check
1421
+
1394
1422
  /**
1395
1423
  * Updates element style left, top, width, height values
1396
1424
  * according to pos input object.
1397
1425
  * @param {HTMLElement} element
1398
1426
  * @param {{left:number,top:number,width:number,height:number}} pos
1399
1427
  */
1400
-
1401
1428
  var updateElementStylePos = (function (element, pos) {
1402
1429
  element.style.left = "".concat(pos.left, "px");
1403
1430
  element.style.top = "".concat(pos.top, "px");
@@ -1412,34 +1439,24 @@ var Area = /*#__PURE__*/function () {
1412
1439
  */
1413
1440
 
1414
1441
  /**
1415
- * @type {DSModificationCallback}
1442
+ * @type {{cleanup:() => void}}
1416
1443
  * @private
1417
1444
  */
1418
1445
 
1419
1446
  /**
1420
- * @type {MutationObserver}
1447
+ * @type {DSArea}
1421
1448
  * @private
1422
1449
  */
1423
1450
 
1424
1451
  /**
1425
- * @type {number}
1452
+ * @type {DSArea[]}
1426
1453
  * @private
1427
1454
  */
1428
1455
 
1429
1456
  /**
1430
- * @type {DSArea}
1457
+ * @type {CSSStyleDeclaration}
1431
1458
  * @private
1432
- */
1433
-
1434
- /**
1435
- * @type {DSArea[]}
1436
- * @private
1437
- */
1438
-
1439
- /**
1440
- * @type {CSSStyleDeclaration}
1441
- * @private
1442
- * */
1459
+ * */
1443
1460
 
1444
1461
  /**
1445
1462
  * @type {{top:number,bottom:number,left:number,right:number}}
@@ -1458,121 +1475,89 @@ var Area = /*#__PURE__*/function () {
1458
1475
  */
1459
1476
  function Area(_ref) {
1460
1477
  var _this = this;
1461
-
1462
1478
  var DS = _ref.DS;
1463
-
1464
1479
  _classCallCheck(this, Area);
1465
-
1466
1480
  _defineProperty(this, "DS", void 0);
1467
-
1468
- _defineProperty(this, "_modificationCallback", void 0);
1469
-
1470
- _defineProperty(this, "_modificationObserver", void 0);
1471
-
1472
- _defineProperty(this, "_zoom", void 0);
1473
-
1481
+ _defineProperty(this, "_observers", void 0);
1474
1482
  _defineProperty(this, "_node", void 0);
1475
-
1476
1483
  _defineProperty(this, "_parentNodes", void 0);
1477
-
1478
1484
  _defineProperty(this, "_computedStyle", void 0);
1479
-
1480
1485
  _defineProperty(this, "_computedBorder", void 0);
1481
-
1482
1486
  _defineProperty(this, "_rect", void 0);
1483
-
1484
1487
  _defineProperty(this, "setArea", function (area) {
1485
1488
  _this._node = area;
1486
1489
  handleElementPositionAttribute({
1487
1490
  computedStyle: _this.computedStyle,
1488
1491
  node: _this._node
1489
- }); // first immediate debounce to update values after dom-update
1492
+ });
1490
1493
 
1494
+ // first immediate debounce to update values after dom-update
1491
1495
  setTimeout(function () {
1492
1496
  _this.DS.PubSub.publish('Area:modified:pre', {
1493
1497
  item: _this
1494
1498
  });
1495
-
1496
1499
  _this.reset();
1497
-
1498
1500
  _this.DS.PubSub.publish('Area:modified', {
1499
1501
  item: _this
1500
1502
  });
1501
1503
  });
1502
1504
  });
1503
-
1504
1505
  _defineProperty(this, "start", function () {
1505
- addModificationObservers(_this.parentNodes, _this._modificationCallback, _this._modificationObserver);
1506
+ _this._observers = addModificationObservers(_this.parentNodes, debounce(function (event) {
1507
+ _this.DS.PubSub.publish('Area:modified:pre', {
1508
+ event: event,
1509
+ item: _this
1510
+ });
1511
+ _this.reset();
1512
+ _this.DS.PubSub.publish('Area:modified', {
1513
+ event: event,
1514
+ item: _this
1515
+ });
1516
+ }, 60));
1506
1517
  });
1507
-
1508
1518
  _defineProperty(this, "reset", function () {
1509
1519
  _this._computedStyle = undefined;
1510
1520
  _this._rect = undefined;
1511
1521
  _this._computedBorder = undefined;
1512
1522
  _this._parentNodes = undefined;
1513
1523
  });
1514
-
1515
1524
  _defineProperty(this, "stop", function () {
1516
- removeModificationObservers(_this._modificationObserver, _this._modificationCallback);
1517
-
1525
+ _this._observers.cleanup();
1518
1526
  _this.reset();
1519
1527
  });
1520
-
1521
1528
  _defineProperty(this, "scroll", function (directions, multiplier) {
1522
1529
  var data = {
1523
1530
  scroll_directions: directions,
1524
1531
  scroll_multiplier: multiplier
1525
1532
  };
1526
-
1527
1533
  _this.DS.PubSub.publish('Area:scroll:pre', data);
1528
-
1529
1534
  scrollElement(_this._node, directions, multiplier);
1530
-
1531
1535
  _this.DS.PubSub.publish('Area:scroll', data);
1532
1536
  });
1533
-
1534
1537
  this.DS = DS;
1535
- this.setArea(this.DS.stores.SettingsStore.s.area); // @ts-ignore: @todo: update to typescript
1536
-
1538
+ this.setArea(this.DS.stores.SettingsStore.s.area);
1539
+ // @ts-ignore: @todo: update to typescript
1537
1540
  this.DS.PubSub.subscribe('Settings:updated:area', function (_ref2) {
1538
1541
  var settings = _ref2.settings;
1539
1542
  return _this.setArea(settings.area);
1540
1543
  });
1541
- this._modificationCallback = debounce(function (event) {
1542
- _this.DS.PubSub.publish('Area:modified:pre', {
1543
- event: event,
1544
- item: _this
1545
- });
1546
-
1547
- _this.reset();
1548
-
1549
- _this.DS.PubSub.publish('Area:modified', {
1550
- event: event,
1551
- item: _this
1552
- });
1553
- }, 60);
1554
- this._modificationObserver = new MutationObserver(this._modificationCallback);
1555
1544
  this.DS.PubSub.subscribe('Interaction:init', this.start);
1556
1545
  this.DS.PubSub.subscribe('Interaction:end', this.reset);
1557
1546
  }
1558
- /** @param {DSArea} area */
1559
-
1560
1547
 
1548
+ /** @param {DSArea} area */
1561
1549
  _createClass(Area, [{
1562
1550
  key: "HTMLNode",
1563
1551
  //////////////////////////////////////////////////////////////////////////////////////
1564
1552
  // Node Getters
1565
1553
  get: function get() {
1566
- return (
1567
- /** @type {DSArea} */
1568
- this._node
1554
+ return (/** @type {DSArea} */this._node
1569
1555
  );
1570
1556
  }
1571
1557
  /**
1572
1558
  * The computed border from the element (caches result)
1573
1559
  * @type {{top:number,bottom:number,left:number,right:number}}
1574
1560
  */
1575
-
1576
1561
  }, {
1577
1562
  key: "computedBorder",
1578
1563
  get: function get() {
@@ -1588,18 +1573,16 @@ var Area = /*#__PURE__*/function () {
1588
1573
  * The computed styles from the element (caches result)
1589
1574
  * @type {CSSStyleDeclaration}
1590
1575
  */
1591
-
1592
1576
  }, {
1593
1577
  key: "computedStyle",
1594
1578
  get: function get() {
1595
1579
  if (this._computedStyle) return this._computedStyle;
1596
- if (this.HTMLNode instanceof HTMLDocument) return this._computedStyle = window.getComputedStyle(this.HTMLNode.body || this.HTMLNode.documentElement);else return this._computedStyle = window.getComputedStyle(this.HTMLNode);
1580
+ if (this.HTMLNode instanceof Document) return this._computedStyle = window.getComputedStyle(this.HTMLNode.body || this.HTMLNode.documentElement);else return this._computedStyle = window.getComputedStyle(this.HTMLNode);
1597
1581
  }
1598
1582
  /**
1599
1583
  * The element rect (caches result) (without scrollbar or borders)
1600
1584
  * @type {DSBoundingRect}
1601
1585
  */
1602
-
1603
1586
  }, {
1604
1587
  key: "rect",
1605
1588
  get: function get() {
@@ -1610,27 +1593,9 @@ var Area = /*#__PURE__*/function () {
1610
1593
  key: "parentNodes",
1611
1594
  get: function get() {
1612
1595
  if (this._parentNodes) return this._parentNodes;
1613
-
1614
- var traverse = function traverse(toWatch) {
1615
- var _toWatch$index;
1616
-
1617
- var index = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 0;
1618
- var parent = (_toWatch$index = toWatch[index]) === null || _toWatch$index === void 0 ? void 0 : _toWatch$index.parentNode;
1619
-
1620
- if (parent) {
1621
- toWatch.push(parent);
1622
- index++;
1623
- return traverse(toWatch, index);
1624
- } else {
1625
- return toWatch;
1626
- }
1627
- };
1628
-
1629
- this._parentNodes = traverse([this.HTMLNode]);
1630
- return this._parentNodes;
1596
+ return this._parentNodes = getAllParentNodes(this.HTMLNode);
1631
1597
  }
1632
1598
  }]);
1633
-
1634
1599
  return Area;
1635
1600
  }();
1636
1601
 
@@ -1667,21 +1632,13 @@ var Drag = /*#__PURE__*/function () {
1667
1632
  */
1668
1633
  function Drag(_ref) {
1669
1634
  var _this = this;
1670
-
1671
1635
  var DS = _ref.DS;
1672
-
1673
1636
  _classCallCheck(this, Drag);
1674
-
1675
1637
  _defineProperty(this, "_prevCursorPos", void 0);
1676
-
1677
1638
  _defineProperty(this, "_prevScrollPos", void 0);
1678
-
1679
1639
  _defineProperty(this, "_elements", []);
1680
-
1681
1640
  _defineProperty(this, "_dragKeys", void 0);
1682
-
1683
1641
  _defineProperty(this, "_dragKeysFlat", []);
1684
-
1685
1642
  _defineProperty(this, "assignDragkeys", function () {
1686
1643
  _this._dragKeys = {
1687
1644
  up: _this.DS.stores.SettingsStore.s.dragKeys.up.map(function (k) {
@@ -1699,26 +1656,19 @@ var Drag = /*#__PURE__*/function () {
1699
1656
  };
1700
1657
  _this._dragKeysFlat = [].concat(_toConsumableArray(_this._dragKeys.up), _toConsumableArray(_this._dragKeys.down), _toConsumableArray(_this._dragKeys.left), _toConsumableArray(_this._dragKeys.right));
1701
1658
  });
1702
-
1703
1659
  _defineProperty(this, "keyboardDrag", function (_ref2) {
1704
1660
  var event = _ref2.event,
1705
- key = _ref2.key;
1706
-
1661
+ key = _ref2.key;
1707
1662
  var _key = key.toLowerCase();
1708
-
1709
1663
  if (!_this.DS.stores.SettingsStore.s.keyboardDrag || !_this._dragKeysFlat.includes(_key) || !_this.DS.SelectedSet.size || !_this.DS.stores.SettingsStore.s.draggability || _this.DS["continue"]) return;
1710
1664
  var publishData = {
1711
1665
  event: event,
1712
1666
  isDragging: true,
1713
1667
  isDraggingKeyboard: true
1714
1668
  };
1715
-
1716
1669
  _this.DS.publish(['Interaction:start:pre', 'Interaction:start'], publishData);
1717
-
1718
1670
  _this._elements = _this.DS.getSelection();
1719
-
1720
1671
  _this.handleZIndex(true);
1721
-
1722
1672
  var posDirection = handleKeyboardDragPosDifference({
1723
1673
  shiftKey: _this.DS.stores.KeyStore.currentValues.includes('shift'),
1724
1674
  keyboardDragSpeed: _this.DS.stores.SettingsStore.s.keyboardDragSpeed,
@@ -1729,7 +1679,6 @@ var Drag = /*#__PURE__*/function () {
1729
1679
  canScroll: _this.DS.stores.ScrollStore.canScroll,
1730
1680
  dragKeys: _this._dragKeys
1731
1681
  });
1732
-
1733
1682
  _this._elements.forEach(function (element) {
1734
1683
  return moveElement({
1735
1684
  element: element,
@@ -1738,53 +1687,41 @@ var Drag = /*#__PURE__*/function () {
1738
1687
  useTransform: _this.DS.stores.SettingsStore.s.useTransform
1739
1688
  });
1740
1689
  });
1741
-
1742
1690
  _this.DS.publish(['Interaction:update:pre', 'Interaction:update'], publishData);
1743
1691
  });
1744
-
1745
1692
  _defineProperty(this, "keyboardEnd", function (_ref3) {
1746
1693
  var event = _ref3.event,
1747
- key = _ref3.key;
1748
-
1694
+ key = _ref3.key;
1749
1695
  var _key = key.toLowerCase();
1750
-
1751
1696
  if (!_this.DS.stores.SettingsStore.s.keyboardDrag || !_this._dragKeysFlat.includes(_key) || !_this.DS.SelectedSet.size || !_this.DS.stores.SettingsStore.s.draggability) return;
1752
1697
  var publishData = {
1753
1698
  event: event,
1754
1699
  isDragging: _this.DS.stores.SettingsStore.s.draggability,
1755
1700
  isDraggingKeyboard: true
1756
1701
  };
1757
-
1758
1702
  _this.DS.publish(['Interaction:end:pre', 'Interaction:end'], publishData);
1759
1703
  });
1760
-
1761
1704
  _defineProperty(this, "start", function (_ref4) {
1762
1705
  var isDragging = _ref4.isDragging,
1763
- isDraggingKeyboard = _ref4.isDraggingKeyboard;
1706
+ isDraggingKeyboard = _ref4.isDraggingKeyboard;
1764
1707
  if (!isDragging || isDraggingKeyboard) return;
1765
1708
  _this._prevCursorPos = null;
1766
1709
  _this._prevScrollPos = null;
1767
1710
  _this._elements = _this.DS.getSelection();
1768
-
1769
1711
  _this.handleZIndex(true);
1770
1712
  });
1771
-
1772
1713
  _defineProperty(this, "stop", function (evt) {
1773
1714
  if (evt !== null && evt !== void 0 && evt.isKeyboard) return;
1774
1715
  _this._prevCursorPos = null;
1775
1716
  _this._prevScrollPos = null;
1776
-
1777
1717
  _this.handleZIndex(false);
1778
-
1779
1718
  _this._elements = [];
1780
1719
  });
1781
-
1782
1720
  _defineProperty(this, "update", function (_ref5) {
1783
1721
  var isDragging = _ref5.isDragging,
1784
- isDraggingKeyboard = _ref5.isDraggingKeyboard;
1722
+ isDraggingKeyboard = _ref5.isDraggingKeyboard;
1785
1723
  if (!isDragging || !_this._elements.length || isDraggingKeyboard || _this.DS["continue"]) return;
1786
1724
  var posDirection = calc(_this._cursorDiff, '+', _this._scrollDiff);
1787
-
1788
1725
  _this._elements.forEach(function (element) {
1789
1726
  return moveElement({
1790
1727
  element: element,
@@ -1794,15 +1731,14 @@ var Drag = /*#__PURE__*/function () {
1794
1731
  });
1795
1732
  });
1796
1733
  });
1797
-
1798
1734
  _defineProperty(this, "handleZIndex", function (add) {
1799
1735
  _this._elements.forEach(function (element) {
1800
1736
  return element.style.zIndex = "".concat((parseInt(element.style.zIndex) || 0) + add ? 9999 : -9998);
1801
1737
  });
1802
1738
  });
1739
+ this.DS = DS;
1803
1740
 
1804
- this.DS = DS; // @ts-ignore: @todo: update to typescript
1805
-
1741
+ // @ts-ignore: @todo: update to typescript
1806
1742
  this.DS.subscribe('Settings:updated:dragKeys', this.assignDragkeys);
1807
1743
  this.assignDragkeys();
1808
1744
  this.DS.subscribe('Interaction:start', this.start);
@@ -1811,7 +1747,6 @@ var Drag = /*#__PURE__*/function () {
1811
1747
  this.DS.subscribe('KeyStore:down', this.keyboardDrag);
1812
1748
  this.DS.subscribe('KeyStore:up', this.keyboardEnd);
1813
1749
  }
1814
-
1815
1750
  _createClass(Drag, [{
1816
1751
  key: "_cursorDiff",
1817
1752
  get: function get() {
@@ -1835,10 +1770,370 @@ var Drag = /*#__PURE__*/function () {
1835
1770
  return scrollDiff;
1836
1771
  }
1837
1772
  }]);
1838
-
1839
1773
  return Drag;
1840
1774
  }();
1841
1775
 
1776
+ var DropZone = /*#__PURE__*/function () {
1777
+ /**
1778
+ * @type {string}
1779
+ */
1780
+
1781
+ /**
1782
+ * @type {DSElement}
1783
+ */
1784
+
1785
+ /**
1786
+ * @type {DSElements}
1787
+ */
1788
+
1789
+ /**
1790
+ * @type {DOMRect}
1791
+ * @private
1792
+ */
1793
+
1794
+ /**
1795
+ * @type {{cleanup:()=>void}}
1796
+ * @private
1797
+ */
1798
+
1799
+ /**
1800
+ * @type {NodeJS.Timeout}
1801
+ * @private
1802
+ */
1803
+
1804
+ /**
1805
+ * @type {DSElements}
1806
+ * @private
1807
+ */
1808
+
1809
+ /**
1810
+ * @type {DSElements}
1811
+ * @private
1812
+ */
1813
+
1814
+ /**
1815
+ * @constructor Drag
1816
+ * @param {Object} obj
1817
+ * @param {DragSelect} obj.DS
1818
+ * @param {string} obj.id
1819
+ * @param {DSElement} obj.element
1820
+ * @param {DSInputElements} obj.droppables
1821
+ * @ignore
1822
+ */
1823
+ function DropZone(_ref) {
1824
+ var _this = this;
1825
+ var DS = _ref.DS,
1826
+ id = _ref.id,
1827
+ element = _ref.element,
1828
+ droppables = _ref.droppables;
1829
+ _classCallCheck(this, DropZone);
1830
+ _defineProperty(this, "id", void 0);
1831
+ _defineProperty(this, "element", void 0);
1832
+ _defineProperty(this, "droppables", void 0);
1833
+ _defineProperty(this, "_rect", void 0);
1834
+ _defineProperty(this, "_observers", void 0);
1835
+ _defineProperty(this, "_timeout", void 0);
1836
+ _defineProperty(this, "_itemsDropped", []);
1837
+ _defineProperty(this, "_itemsInside", void 0);
1838
+ _defineProperty(this, "setReadyClasses", function (action) {
1839
+ if (_this.isDestroyed) return;
1840
+ var selectedEls = _this.droppables.filter(function (el) {
1841
+ return _this.DS.SelectedSet.has(el);
1842
+ });
1843
+ if (!selectedEls.length) return;
1844
+ selectedEls.forEach(function (item) {
1845
+ item.classList[action]("".concat(_this.Settings.droppableClass));
1846
+ item.classList[action]("".concat(_this.Settings.droppableClass, "-").concat(_this.id));
1847
+ });
1848
+ _this.element.classList[action]("".concat(_this.Settings.dropZoneReadyClass));
1849
+ });
1850
+ _defineProperty(this, "handleNoDrop", function () {
1851
+ var _this$_itemsDropped;
1852
+ if (_this.isDestroyed) return;
1853
+ // for each selected element that is not part of the target zone, remove the classes
1854
+ _this.DS.SelectedSet.forEach(function (item) {
1855
+ item.classList.remove(_this.Settings.droppedTargetClass);
1856
+ item.classList.remove("".concat(_this.Settings.droppedTargetClass, "-").concat(_this.id));
1857
+ });
1858
+ // and remove them from the zones dropped items
1859
+ _this._itemsDropped = _this._itemsDropped.filter(function (item) {
1860
+ return !_this.DS.SelectedSet.has(item);
1861
+ });
1862
+ // if the zone has no dropped left, also remove the zones class
1863
+ if (!((_this$_itemsDropped = _this._itemsDropped) !== null && _this$_itemsDropped !== void 0 && _this$_itemsDropped.length)) _this.element.classList.remove("".concat(_this.Settings.dropZoneTargetClass));
1864
+ });
1865
+ _defineProperty(this, "handleDrop", function () {
1866
+ var _this$droppables, _this$_itemsDropped2, _this$_itemsDropped3;
1867
+ if (_this.isDestroyed) return;
1868
+ // @ts-ignore
1869
+ _this._itemsDropped = _toConsumableArray(new Set([].concat(_toConsumableArray(_this._itemsDropped), _toConsumableArray((_this$droppables = _this.droppables) === null || _this$droppables === void 0 ? void 0 : _this$droppables.filter(function (item) {
1870
+ return _this.DS.SelectedSet.has(item);
1871
+ })))));
1872
+ // add the target class to the zones dropped items
1873
+ (_this$_itemsDropped2 = _this._itemsDropped) === null || _this$_itemsDropped2 === void 0 ? void 0 : _this$_itemsDropped2.forEach(function (item) {
1874
+ item.classList.add("".concat(_this.Settings.droppedTargetClass));
1875
+ item.classList.add("".concat(_this.Settings.droppedTargetClass, "-").concat(_this.id));
1876
+ });
1877
+ // if the zone has dropped, add the zones class
1878
+ if ((_this$_itemsDropped3 = _this._itemsDropped) !== null && _this$_itemsDropped3 !== void 0 && _this$_itemsDropped3.length) _this.element.classList.add("".concat(_this.Settings.dropZoneTargetClass));
1879
+ });
1880
+ _defineProperty(this, "handleItemsInsideClasses", function () {
1881
+ var isAnyInside = false;
1882
+ _this.droppables.forEach(function (item) {
1883
+ if (_this.itemsInside.includes(item)) {
1884
+ item.classList.add("".concat(_this.Settings.droppedInsideClass));
1885
+ item.classList.add("".concat(_this.Settings.droppedInsideClass, "-").concat(_this.id));
1886
+ isAnyInside = true;
1887
+ } else {
1888
+ item.classList.remove("".concat(_this.Settings.droppedInsideClass));
1889
+ item.classList.remove("".concat(_this.Settings.droppedInsideClass, "-").concat(_this.id));
1890
+ }
1891
+ });
1892
+ if (isAnyInside) _this.element.classList.add("".concat(_this.Settings.dropZoneInsideClass));else _this.element.classList.remove("".concat(_this.Settings.dropZoneInsideClass));
1893
+ });
1894
+ _defineProperty(this, "start", function (_ref2) {
1895
+ var isDragging = _ref2.isDragging;
1896
+ if (!isDragging || _this.isDestroyed) return;
1897
+ _this.setReadyClasses('add');
1898
+ });
1899
+ _defineProperty(this, "stop", function (_ref3) {
1900
+ var isDragging = _ref3.isDragging;
1901
+ if (!isDragging || _this.isDestroyed) return;
1902
+ _this.setReadyClasses('remove');
1903
+ _this.handleItemsInsideClasses();
1904
+ });
1905
+ _defineProperty(this, "toObject", function () {
1906
+ return {
1907
+ id: _this.id,
1908
+ element: _this.element,
1909
+ droppables: _this.droppables,
1910
+ itemsDropped: _this.itemsDropped,
1911
+ itemsInside: _this.itemsInside
1912
+ };
1913
+ });
1914
+ this.DS = DS;
1915
+ this.Settings = DS.stores.SettingsStore.s;
1916
+ this.id = id;
1917
+ this.element = element;
1918
+ this.droppables = toArray(droppables);
1919
+ this.element.classList.add("".concat(this.Settings.dropZoneClass));
1920
+
1921
+ // @ts-ignore: @todo: update to typescript
1922
+ this.DS.subscribe('Settings:updated:dropZoneClass', function (_ref4) {
1923
+ var settings = _ref4.settings;
1924
+ _this.element.classList.remove(settings['dropZoneClass:pre']);
1925
+ _this.element.classList.add(settings['dropZoneClass']);
1926
+ });
1927
+ this._observers = addModificationObservers(this.parentNodes, debounce(function () {
1928
+ return _this._rect = null;
1929
+ }, this.Settings.refreshMemoryRate));
1930
+ this.DS.subscribe('Interaction:start', this.start);
1931
+ this.DS.subscribe('Interaction:end', this.stop);
1932
+ }
1933
+
1934
+ /**
1935
+ * @param {'add'|'remove'} action
1936
+ */
1937
+ _createClass(DropZone, [{
1938
+ key: "destroy",
1939
+ value: function destroy() {
1940
+ var _this2 = this;
1941
+ this._observers.cleanup();
1942
+ this.element.classList.remove("".concat(this.Settings.dropZoneClass));
1943
+ this.element.classList.remove("".concat(this.Settings.dropZoneTargetClass));
1944
+ this.element.classList.remove("".concat(this.Settings.dropZoneReadyClass));
1945
+ this.droppables.forEach(function (item) {
1946
+ item.classList.remove("".concat(_this2.Settings.droppedTargetClass));
1947
+ item.classList.remove("".concat(_this2.Settings.droppedTargetClass, "-").concat(_this2.id));
1948
+ item.classList.remove("".concat(_this2.Settings.droppableClass));
1949
+ item.classList.remove("".concat(_this2.Settings.droppableClass, "-").concat(_this2.id));
1950
+ });
1951
+ this.DS.unsubscribe('Interaction:start', this.start);
1952
+ this.DS.unsubscribe('Interaction:end', this.stop);
1953
+ this.element = null;
1954
+ this.droppables = null;
1955
+ this.id = null;
1956
+ this._itemsDropped = null;
1957
+ this._itemsInside = null;
1958
+ this.isDestroyed = true;
1959
+ }
1960
+ /**
1961
+ * @returns {DSDropZone}
1962
+ */
1963
+ }, {
1964
+ key: "rect",
1965
+ get: function get() {
1966
+ if (this.isDestroyed) return null;
1967
+ if (this._rect) return this._rect;
1968
+ return this._rect = this.element.getBoundingClientRect();
1969
+ }
1970
+ }, {
1971
+ key: "itemsDropped",
1972
+ get: function get() {
1973
+ if (this.isDestroyed) return null;
1974
+ return this._itemsDropped;
1975
+ }
1976
+ }, {
1977
+ key: "itemsInside",
1978
+ get: function get() {
1979
+ var _this3 = this;
1980
+ if (this.isDestroyed) return null;
1981
+ if (this._itemsInside) return this._itemsInside;
1982
+ this._itemsInside = this.droppables.flatMap(function (item) {
1983
+ if (isCollision(_this3.DS.SelectableSet.rects.get(item), _this3.rect, _this3.Settings.dropInsideThreshold)) return [item];
1984
+ return [];
1985
+ });
1986
+
1987
+ // since elements can be moved while this getter is called, we need to update the values every X seconds
1988
+ if (this._timeout) clearTimeout(this._timeout);
1989
+ this._timeout = setTimeout(function () {
1990
+ return _this3._itemsInside = null;
1991
+ }, this.Settings.refreshMemoryRate);
1992
+ return this._itemsInside;
1993
+ }
1994
+ }, {
1995
+ key: "parentNodes",
1996
+ get: function get() {
1997
+ if (this._parentNodes) return this._parentNodes;
1998
+ return this._parentNodes = getAllParentNodes(this.element);
1999
+ }
2000
+ }]);
2001
+ return DropZone;
2002
+ }();
2003
+
2004
+ var DropZones =
2005
+ /**
2006
+ * Get the drop zone by the zone element
2007
+ * @type {Map<DSElement, DropZone>}
2008
+ * @private
2009
+ */
2010
+
2011
+ /**
2012
+ * Get the drop zone by the zone id
2013
+ * @type {Map<string, DropZone>}
2014
+ * @private
2015
+ */
2016
+
2017
+ /**
2018
+ * Get the drop zones by one zone item
2019
+ * @type {Map<DSElement,DropZone[]>}
2020
+ * @private
2021
+ */
2022
+
2023
+ /**
2024
+ * Get the drop zones by one zone item
2025
+ * @type {DropZone[]}
2026
+ * @private
2027
+ */
2028
+
2029
+ /**
2030
+ * @constructor Drag
2031
+ * @param {{DS:DragSelect}} obj
2032
+ * @ignore
2033
+ */
2034
+ function DropZones(_ref) {
2035
+ var _this = this;
2036
+ var DS = _ref.DS;
2037
+ _classCallCheck(this, DropZones);
2038
+ _defineProperty(this, "_zoneByElement", new Map());
2039
+ _defineProperty(this, "_zoneById", new Map());
2040
+ _defineProperty(this, "_zonesByDroppable", new Map());
2041
+ _defineProperty(this, "_zones", void 0);
2042
+ _defineProperty(this, "setDropZones", function (_ref2) {
2043
+ var dropZones = _ref2.dropZones;
2044
+ if (!dropZones) return;
2045
+ if (_this._zones) _this._zones.forEach(function (zone) {
2046
+ return zone.destroy();
2047
+ });
2048
+ _this._zones = dropZones.map(function (zone) {
2049
+ return new DropZone(_objectSpread2({
2050
+ DS: _this.DS
2051
+ }, zone));
2052
+ });
2053
+ _this._zones.forEach(function (zone) {
2054
+ _this._zoneByElement.set(zone.element, zone);
2055
+ _this._zoneById.set(zone.id, zone);
2056
+ zone.droppables.forEach(function (droppable) {
2057
+ var zones = _this._zonesByDroppable.get(droppable);
2058
+ if (!(zones !== null && zones !== void 0 && zones.length)) return _this._zonesByDroppable.set(droppable, [zone]);
2059
+ // @ts-ignore
2060
+ _this._zonesByDroppable.set(droppable, _toConsumableArray(new Set([].concat(_toConsumableArray(zones), [zone]))));
2061
+ });
2062
+ });
2063
+ });
2064
+ _defineProperty(this, "_handleDrop", function (target) {
2065
+ _this._zones.forEach(function (zone) {
2066
+ if (zone === target) return;
2067
+ zone.handleNoDrop();
2068
+ });
2069
+ if (!target) return;
2070
+ target.handleDrop();
2071
+ });
2072
+ _defineProperty(this, "_getZoneByElementsFromPoint", function (elements, _ref3) {
2073
+ var x = _ref3.x,
2074
+ y = _ref3.y;
2075
+ for (var i = 0, il = elements.length; i < il; i++) {
2076
+ var zone = _this._zoneByElement.get(elements[i]);
2077
+ if (zone && isCollision(zone.rect, {
2078
+ left: x,
2079
+ right: x,
2080
+ top: y,
2081
+ bottom: y
2082
+ }, Math.min(_this.Settings.dropTargetThreshold, 0.5))) {
2083
+ return zone;
2084
+ }
2085
+ }
2086
+ });
2087
+ _defineProperty(this, "start", function (_ref4) {
2088
+ var isDragging = _ref4.isDragging;
2089
+ if (!isDragging) return;
2090
+ });
2091
+ _defineProperty(this, "stop", function (_ref5) {
2092
+ var isDragging = _ref5.isDragging;
2093
+ if (!isDragging) return;
2094
+ var target = _this.getTarget();
2095
+ _this._handleDrop(target);
2096
+ });
2097
+ _defineProperty(this, "getItemsDroppedById", function (zoneId) {
2098
+ var zone = _this._zoneById.get(zoneId);
2099
+ if (!zone) return console.warn("[DragSelect] No zone found (id: ".concat(zoneId, ")"));
2100
+ return zone.itemsDropped;
2101
+ });
2102
+ _defineProperty(this, "getItemsInsideById", function (zoneId, addClasses) {
2103
+ var zone = _this._zoneById.get(zoneId);
2104
+ if (!zone) return console.warn("[DragSelect] No zone found (id: ".concat(zoneId, ")"));
2105
+ var itemsInside = zone.itemsInside;
2106
+ if (addClasses) zone.handleItemsInsideClasses();
2107
+ return itemsInside;
2108
+ });
2109
+ _defineProperty(this, "getTarget", function (coordinates) {
2110
+ var _this$_zones;
2111
+ if (!((_this$_zones = _this._zones) !== null && _this$_zones !== void 0 && _this$_zones.length)) return;
2112
+ var x = (coordinates === null || coordinates === void 0 ? void 0 : coordinates.x) || _this.DS.stores.PointerStore.currentVal.x;
2113
+ var y = (coordinates === null || coordinates === void 0 ? void 0 : coordinates.y) || _this.DS.stores.PointerStore.currentVal.y;
2114
+ var elements = document.elementsFromPoint(x, y);
2115
+ return _this._getZoneByElementsFromPoint( /** @type {DSElements} */elements, {
2116
+ x: x,
2117
+ y: y
2118
+ });
2119
+ });
2120
+ this.DS = DS;
2121
+ this.Settings = DS.stores.SettingsStore.s;
2122
+
2123
+ // @ts-ignore: @todo: update to typescript
2124
+ this.DS.subscribe('Settings:updated:dropZones', this.setDropZones);
2125
+ this.setDropZones({
2126
+ dropZones: /** @type {DSDropZone[]} */this.DS.stores.SettingsStore.s.dropZones
2127
+ });
2128
+ this.DS.subscribe('Interaction:start', this.start);
2129
+ this.DS.subscribe('Interaction:end', this.stop);
2130
+ }
2131
+
2132
+ /**
2133
+ * @param {Object} obj
2134
+ * @param {DSDropZone[]} [obj.dropZones]
2135
+ */;
2136
+
1842
2137
  var Interaction = /*#__PURE__*/function () {
1843
2138
  /** @type {boolean} */
1844
2139
 
@@ -1851,118 +2146,103 @@ var Interaction = /*#__PURE__*/function () {
1851
2146
  */
1852
2147
  function Interaction(_ref) {
1853
2148
  var _this = this;
1854
-
1855
2149
  var DS = _ref.DS;
1856
-
1857
2150
  _classCallCheck(this, Interaction);
1858
-
1859
2151
  _defineProperty(this, "isInteracting", void 0);
1860
-
1861
2152
  _defineProperty(this, "isDragging", void 0);
1862
-
1863
2153
  _defineProperty(this, "init", function () {
1864
2154
  return _this.DS.publish('Interaction:init:pre', {});
1865
2155
  });
1866
-
1867
2156
  _defineProperty(this, "_init", function () {
1868
2157
  _this.stop();
1869
2158
 
1870
- _this.DS.Area.HTMLNode.addEventListener('mousedown', _this.start);
1871
-
2159
+ // @TODO: fix pointer events mixing issue see [PR](https://github.com/ThibaultJanBeyer/DragSelect/pull/128#issuecomment-1154885289)
2160
+ if (_this.Settings.usePointerEvents) _this.DS.Area.HTMLNode.addEventListener('pointerdown', _this.start, {
2161
+ passive: false
2162
+ });else _this.DS.Area.HTMLNode.addEventListener('mousedown', _this.start);
1872
2163
  _this.DS.Area.HTMLNode.addEventListener('touchstart', _this.start, {
1873
2164
  passive: false
1874
2165
  });
1875
-
1876
2166
  _this.DS.publish('Interaction:init', {});
1877
2167
  });
1878
-
1879
2168
  _defineProperty(this, "start", function (event) {
1880
2169
  return _this.DS.publish('Interaction:start:pre', {
1881
2170
  event: event,
1882
2171
  isDragging: _this.isDragging
1883
2172
  });
1884
2173
  });
1885
-
1886
2174
  _defineProperty(this, "_start", function (event) {
1887
2175
  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
1888
-
1889
2176
  if (!_this._canInteract(event)) return;
1890
2177
  _this.isInteracting = true;
1891
2178
  _this.isDragging = _this.isDragEvent(event);
1892
-
1893
2179
  _this.DS.publish('Interaction:start', {
1894
2180
  event: event,
1895
2181
  isDragging: _this.isDragging
1896
2182
  });
1897
2183
 
1898
- document.addEventListener('mouseup', _this.reset);
2184
+ // @TODO: fix pointer events mixing issue see [PR](https://github.com/ThibaultJanBeyer/DragSelect/pull/128#issuecomment-1154885289)
2185
+ if (_this.Settings.usePointerEvents) {
2186
+ document.addEventListener('pointerup', _this.reset);
2187
+ document.addEventListener('pointercancel', _this.reset);
2188
+ } else document.addEventListener('mouseup', _this.reset);
1899
2189
  document.addEventListener('touchend', _this.reset);
1900
2190
  });
1901
-
1902
2191
  _defineProperty(this, "isDragEvent", function (event) {
1903
- var clickedElement =
1904
- /** @type {Element} */
1905
- event.target.closest(".".concat(_this.DS.stores.SettingsStore.s.selectableClass));
1906
- if (!_this.DS.stores.SettingsStore.s.draggability || _this.DS.stores.KeyStore.isMultiSelectKeyPressed(event) || !clickedElement) return false;
1907
-
1908
- if (_this.DS.stores.SettingsStore.s.immediateDrag) {
1909
- if (!_this.DS.SelectedSet.size) _this.DS.SelectedSet.add(
1910
- /** @type {DSElement} */
1911
- clickedElement);else if (!_this.DS.SelectedSet.has(clickedElement)) {
2192
+ var clickedElement = /** @type {Element} */event.target.closest(".".concat(_this.Settings.selectableClass));
2193
+ if (!_this.Settings.draggability || _this.DS.stores.KeyStore.isMultiSelectKeyPressed(event) || !clickedElement) return false;
2194
+ if (_this.Settings.immediateDrag) {
2195
+ if (!_this.DS.SelectedSet.size) _this.DS.SelectedSet.add( /** @type {DSElement} */clickedElement);else if (!_this.DS.SelectedSet.has(clickedElement)) {
1912
2196
  _this.DS.SelectedSet.clear();
1913
-
1914
- _this.DS.SelectedSet.add(
1915
- /** @type {DSElement} */
1916
- clickedElement);
2197
+ _this.DS.SelectedSet.add( /** @type {DSElement} */clickedElement);
1917
2198
  }
1918
2199
  }
1919
-
1920
2200
  if (_this.DS.SelectedSet.has(clickedElement)) return true;
1921
2201
  return false;
1922
2202
  });
1923
-
1924
2203
  _defineProperty(this, "onClick", function (_ref2) {
1925
2204
  var event = _ref2.event;
1926
2205
  if (!_this._canInteract(event)) return;
1927
2206
  if (event.detail > 0) return; // mouse interaction
1928
-
1929
2207
  var _this$DS = _this.DS,
1930
- _this$DS$stores = _this$DS.stores,
1931
- PointerStore = _this$DS$stores.PointerStore,
1932
- KeyStore = _this$DS$stores.KeyStore,
1933
- SelectableSet = _this$DS.SelectableSet,
1934
- SelectedSet = _this$DS.SelectedSet;
2208
+ _this$DS$stores = _this$DS.stores,
2209
+ PointerStore = _this$DS$stores.PointerStore,
2210
+ KeyStore = _this$DS$stores.KeyStore,
2211
+ SelectableSet = _this$DS.SelectableSet,
2212
+ SelectedSet = _this$DS.SelectedSet;
1935
2213
  PointerStore.start(event);
1936
- var node =
1937
- /** @type {any} */
1938
- event.target;
2214
+ var node = /** @type {any} */event.target;
1939
2215
  if (!SelectableSet.has(node)) return;
1940
2216
  if (!KeyStore.isMultiSelectKeyPressed(event)) SelectedSet.clear();
1941
2217
  SelectedSet.toggle(node);
1942
-
1943
2218
  _this.reset(); // simulate mouse-up (that does not exist on keyboard)
1944
-
1945
2219
  });
1946
-
1947
2220
  _defineProperty(this, "stop", function () {
1948
2221
  _this.isInteracting = false;
1949
2222
  _this.isDragging = false;
1950
2223
 
1951
- _this.DS.Area.HTMLNode.removeEventListener('mousedown', _this.start);
1952
-
2224
+ // @TODO: fix pointer events mixing issue see [PR](https://github.com/ThibaultJanBeyer/DragSelect/pull/128#issuecomment-1154885289)
2225
+ if (_this.Settings.usePointerEvents) {
2226
+ _this.DS.Area.HTMLNode.removeEventListener('pointerdown', _this.start, {
2227
+ // @ts-ignore
2228
+ passive: false
2229
+ });
2230
+ document.removeEventListener('pointerup', _this.reset);
2231
+ document.removeEventListener('pointercancel', _this.reset);
2232
+ } else {
2233
+ _this.DS.Area.HTMLNode.removeEventListener('mousedown', _this.start);
2234
+ document.removeEventListener('mouseup', _this.reset);
2235
+ }
1953
2236
  _this.DS.Area.HTMLNode.removeEventListener('touchstart', _this.start, {
1954
2237
  // @ts-ignore
1955
2238
  passive: false
1956
2239
  });
1957
-
1958
- document.removeEventListener('mouseup', _this.reset);
1959
2240
  document.removeEventListener('touchend', _this.reset);
1960
2241
  });
1961
-
1962
2242
  _defineProperty(this, "update", function (_ref3) {
1963
2243
  var event = _ref3.event,
1964
- scroll_directions = _ref3.scroll_directions,
1965
- scroll_multiplier = _ref3.scroll_multiplier;
2244
+ scroll_directions = _ref3.scroll_directions,
2245
+ scroll_multiplier = _ref3.scroll_multiplier;
1966
2246
  if (_this.isInteracting) _this.DS.publish(['Interaction:update:pre', 'Interaction:update'], {
1967
2247
  event: event,
1968
2248
  scroll_directions: scroll_directions,
@@ -1970,29 +2250,24 @@ var Interaction = /*#__PURE__*/function () {
1970
2250
  isDragging: _this.isDragging
1971
2251
  });
1972
2252
  });
1973
-
1974
2253
  _defineProperty(this, "reset", function (event) {
1975
2254
  return _this.DS.publish('Interaction:end:pre', {
1976
2255
  event: event,
1977
2256
  isDragging: _this.isDragging
1978
2257
  });
1979
2258
  });
1980
-
1981
2259
  _defineProperty(this, "_reset", function (event) {
1982
2260
  var isDragging = _this.isDragging;
1983
-
1984
2261
  _this.stop();
1985
-
1986
2262
  _this.init();
1987
-
1988
2263
  _this.DS.publish('Interaction:end', {
1989
2264
  event: event,
1990
2265
  isDragging: isDragging
1991
2266
  });
1992
2267
  });
1993
-
1994
- this.DS = DS; // @ts-ignore: @todo: update to typescript
1995
-
2268
+ this.DS = DS;
2269
+ this.Settings = DS.stores.SettingsStore.s;
2270
+ // @ts-ignore: @todo: update to typescript
1996
2271
  this.DS.subscribe('Settings:updated:area', this.init);
1997
2272
  this.DS.subscribe('PointerStore:updated', this.update);
1998
2273
  this.DS.subscribe('Selectable:click', this.onClick);
@@ -2011,28 +2286,19 @@ var Interaction = /*#__PURE__*/function () {
2011
2286
  });
2012
2287
  this.DS.subscribe('Area:scroll', this.update);
2013
2288
  }
2014
-
2015
2289
  _createClass(Interaction, [{
2016
2290
  key: "_canInteract",
2017
-
2018
2291
  /**
2019
2292
  * @param {DSEvent} event
2020
2293
  */
2021
2294
  value: function _canInteract(event) {
2022
- var isKeyboardClick =
2023
- /** @type {MouseEvent} */
2024
- event.clientX === 0 &&
2025
- /** @type {MouseEvent} */
2026
- event.clientY === 0 &&
2027
- /** @type {MouseEvent} */
2028
- event.detail === 0 && event.target;
2029
- if (
2030
- /** @type {MouseEvent} */
2031
- event.button === 2 || // right-clicks
2032
- this.isInteracting || // fix double-click issues
2033
- event.target && !this.DS.SelectorArea.isInside(
2034
- /** @type {DSElement} */
2035
- event.target) || //fix outside elements issue
2295
+ var isKeyboardClick = /** @type {MouseEvent} */event.clientX === 0 && /** @type {MouseEvent} */event.clientY === 0 && /** @type {MouseEvent} */event.detail === 0 && event.target;
2296
+ if ( /** @type {MouseEvent} */event.button === 2 ||
2297
+ // right-clicks
2298
+ this.isInteracting ||
2299
+ // fix double-click issues
2300
+ event.target && !this.DS.SelectorArea.isInside( /** @type {DSElement} */event.target) ||
2301
+ //fix outside elements issue
2036
2302
  !isKeyboardClick && !this.DS.SelectorArea.isClicked(event) // make sure the mouse click is inside the area
2037
2303
  ) return false;
2038
2304
  return true;
@@ -2040,65 +2306,51 @@ var Interaction = /*#__PURE__*/function () {
2040
2306
  /**
2041
2307
  * @param {DSEvent} event
2042
2308
  */
2043
-
2044
2309
  }]);
2045
-
2046
2310
  return Interaction;
2047
2311
  }();
2048
2312
 
2049
2313
  var PubSub = function PubSub(_ref) {
2050
2314
  var _this = this;
2051
-
2052
2315
  var DS = _ref.DS;
2053
-
2054
2316
  _classCallCheck(this, PubSub);
2055
-
2056
2317
  _defineProperty(this, "subscribers", {});
2057
-
2058
2318
  _defineProperty(this, "subscribe", function (eventName, callback) {
2059
2319
  if (!Array.isArray(_this.subscribers[eventName])) _this.subscribers[eventName] = [];
2060
-
2061
2320
  _this.subscribers[eventName].push(callback);
2062
-
2063
2321
  return _this.subscribers[eventName].length - 1;
2064
2322
  });
2065
-
2066
2323
  _defineProperty(this, "unsubscribe", function (eventName, callback, id) {
2067
2324
  if (id >= 0) _this.subscribers[eventName].splice(id, 1);else if (callback) _this.subscribers[eventName] = _this.subscribers[eventName].filter(function (cb) {
2068
2325
  return cb !== callback;
2069
2326
  });
2070
2327
  });
2071
-
2072
2328
  _defineProperty(this, "publish", function (eventName, data) {
2073
2329
  if (Array.isArray(eventName)) eventName.forEach(function (name) {
2074
2330
  return _this._publish(name, data);
2075
2331
  });else _this._publish(eventName, data);
2076
2332
  });
2077
-
2078
2333
  _defineProperty(this, "_publish", function (eventName, data) {
2079
2334
  var subscribers = _this.subscribers[eventName];
2080
2335
  if (!Array.isArray(subscribers)) return;
2081
2336
  if (eventName.includes(":pre")) _this._handlePrePublish(subscribers, data);else _this._handlePublish(subscribers, data);
2082
2337
  });
2083
-
2084
2338
  _defineProperty(this, "_handlePublish", function (subscribers, data) {
2085
2339
  for (var i = 0, il = subscribers.length; i < il; i++) {
2086
2340
  if (_this.DS.stopped) return;
2087
2341
  subscribers[i](data);
2088
2342
  }
2089
2343
  });
2090
-
2091
2344
  _defineProperty(this, "_handlePrePublish", function (subscribers, data) {
2092
2345
  var i = subscribers.length;
2093
-
2094
2346
  while (i--) {
2095
2347
  if (_this.DS.stopped) return;
2096
2348
  subscribers[i](data);
2097
2349
  }
2098
2350
  });
2099
-
2100
2351
  this.DS = DS;
2101
2352
  }
2353
+
2102
2354
  /**
2103
2355
  * Subscribe to an event
2104
2356
  * @memberof DragSelect#
@@ -2106,13 +2358,20 @@ var PubSub = function PubSub(_ref) {
2106
2358
  * @param {DSCallbackNames} eventName
2107
2359
  * @param {DSCallback} callback
2108
2360
  * @returns {number} event id, can be used to unsubscribe more efficiently
2109
- */
2110
- ;
2361
+ */;
2111
2362
 
2112
2363
  var SelectableSet = /*#__PURE__*/function (_Set) {
2113
2364
  _inherits(SelectableSet, _Set);
2114
-
2115
2365
  var _super = _createSuper(SelectableSet);
2366
+ /**
2367
+ * @type {Map<DSElement,DSBoundingRect>}
2368
+ * @private
2369
+ */
2370
+
2371
+ /**
2372
+ * @type {NodeJS.Timeout}
2373
+ * @private
2374
+ */
2116
2375
 
2117
2376
  /**
2118
2377
  * @constructor SelectableSet
@@ -2121,100 +2380,85 @@ var SelectableSet = /*#__PURE__*/function (_Set) {
2121
2380
  */
2122
2381
  function SelectableSet(_ref) {
2123
2382
  var _this;
2124
-
2125
2383
  var DS = _ref.DS;
2126
-
2127
2384
  _classCallCheck(this, SelectableSet);
2128
-
2129
2385
  _this = _super.call(this);
2130
-
2386
+ _defineProperty(_assertThisInitialized(_this), "_rects", void 0);
2387
+ _defineProperty(_assertThisInitialized(_this), "_timeout", void 0);
2131
2388
  _defineProperty(_assertThisInitialized(_this), "init", function () {
2132
- return toArray(_this.DS.stores.SettingsStore.s.selectables).forEach(function (el) {
2389
+ return toArray(_this.Settings.selectables).forEach(function (el) {
2133
2390
  return _this.add(el);
2134
2391
  });
2135
2392
  });
2136
-
2137
2393
  _defineProperty(_assertThisInitialized(_this), "clear", function () {
2138
2394
  return _this.forEach(function (el) {
2139
2395
  return _this["delete"](el);
2140
2396
  });
2141
2397
  });
2142
-
2143
2398
  _defineProperty(_assertThisInitialized(_this), "_onClick", function (event) {
2144
2399
  return _this.DS.publish(['Selectable:click:pre', 'Selectable:click'], {
2145
2400
  event: event
2146
2401
  });
2147
2402
  });
2148
-
2149
2403
  _defineProperty(_assertThisInitialized(_this), "_onPointer", function (event) {
2150
2404
  return _this.DS.publish(['Selectable:pointer:pre', 'Selectable:pointer'], {
2151
2405
  event: event
2152
2406
  });
2153
2407
  });
2154
-
2155
2408
  _defineProperty(_assertThisInitialized(_this), "addAll", function (elements) {
2156
2409
  return elements.forEach(function (el) {
2157
2410
  return _this.add(el);
2158
2411
  });
2159
2412
  });
2160
-
2161
2413
  _defineProperty(_assertThisInitialized(_this), "deleteAll", function (elements) {
2162
2414
  return elements.forEach(function (el) {
2163
2415
  return _this["delete"](el);
2164
2416
  });
2165
2417
  });
2166
-
2167
2418
  _this.DS = DS;
2168
-
2169
- _this.DS.subscribe('Interaction:init', _this.init); // @ts-ignore: @todo: update to typescript
2170
-
2171
-
2419
+ _this.Settings = DS.stores.SettingsStore.s;
2420
+ _this.DS.subscribe('Interaction:init', _this.init);
2421
+ // @ts-ignore: @todo: update to typescript
2172
2422
  _this.DS.PubSub.subscribe('Settings:updated:selectables', function () {
2173
2423
  _this.clear();
2174
-
2175
2424
  _this.init();
2176
- }); // @ts-ignore: @todo: update to typescript
2177
-
2178
-
2425
+ });
2426
+ // @ts-ignore: @todo: update to typescript
2179
2427
  _this.DS.subscribe('Settings:updated:selectableClass', function (_ref2) {
2180
2428
  var settings = _ref2.settings;
2181
-
2182
2429
  _this.forEach(function (el) {
2183
2430
  el.classList.remove(settings['selectableClass:pre']);
2184
2431
  el.classList.add(settings['selectableClass']);
2185
2432
  });
2186
2433
  });
2187
-
2188
2434
  return _this;
2189
2435
  }
2190
-
2191
2436
  _createClass(SelectableSet, [{
2192
2437
  key: "add",
2193
-
2194
- /** @param {DSElement} element */
2195
- value: function add(element) {
2438
+ /** @param {DSElement} element */value: function add(element) {
2196
2439
  if (_get(_getPrototypeOf(SelectableSet.prototype), "has", this).call(this, element)) return;
2197
2440
  var publishData = {
2198
2441
  items: this.elements,
2199
2442
  item: element
2200
2443
  };
2201
2444
  this.DS.publish('Selectable:added:pre', publishData);
2202
- element.classList.add(this.DS.stores.SettingsStore.s.selectableClass);
2445
+ element.classList.add(this.Settings.selectableClass);
2203
2446
  element.addEventListener('click', this._onClick);
2204
- element.addEventListener('mousedown', this._onPointer);
2447
+ if (this.Settings.usePointerEvents) element.addEventListener('pointerdown', this._onPointer, {
2448
+ // @ts-ignore
2449
+ passive: false
2450
+ });else element.addEventListener('mousedown', this._onPointer);
2205
2451
  element.addEventListener('touchstart', this._onPointer, {
2206
2452
  // @ts-ignore
2207
2453
  passive: false
2208
2454
  });
2209
- if (this.DS.stores.SettingsStore.s.draggability && !this.DS.stores.SettingsStore.s.useTransform) handleElementPositionAttribute({
2455
+ if (this.Settings.draggability && !this.Settings.useTransform) handleElementPositionAttribute({
2210
2456
  computedStyle: window.getComputedStyle(element),
2211
2457
  node: element
2212
2458
  });
2213
2459
  this.DS.publish('Selectable:added', publishData);
2214
2460
  return _get(_getPrototypeOf(SelectableSet.prototype), "add", this).call(this, element);
2215
- }
2216
- /** @param {DSElement} element */
2217
-
2461
+ } /** @param {DSElement} element */
2218
2462
  }, {
2219
2463
  key: "delete",
2220
2464
  value: function _delete(element) {
@@ -2224,10 +2468,13 @@ var SelectableSet = /*#__PURE__*/function (_Set) {
2224
2468
  item: element
2225
2469
  };
2226
2470
  this.DS.publish('Selectable:removed:pre', publishData);
2227
- element.classList.remove(this.DS.stores.SettingsStore.s.selectableClass);
2228
- element.classList.remove(this.DS.stores.SettingsStore.s.hoverClass);
2471
+ element.classList.remove(this.Settings.selectableClass);
2472
+ element.classList.remove(this.Settings.hoverClass);
2229
2473
  element.removeEventListener('click', this._onClick);
2230
- element.removeEventListener('mousedown', this._onPointer);
2474
+ if (this.Settings.usePointerEvents) element.removeEventListener('pointerdown', this._onPointer, {
2475
+ // @ts-ignore
2476
+ passive: false
2477
+ });else element.removeEventListener('mousedown', this._onPointer);
2231
2478
  element.removeEventListener('touchstart', this._onPointer, {
2232
2479
  // @ts-ignore
2233
2480
  passive: false
@@ -2237,21 +2484,33 @@ var SelectableSet = /*#__PURE__*/function (_Set) {
2237
2484
  }
2238
2485
  }, {
2239
2486
  key: "elements",
2240
-
2241
- /** @return {DSElements} */
2242
- get: function get() {
2487
+ /** @return {DSElements} */get: function get() {
2243
2488
  return Array.from(this.values());
2244
2489
  }
2245
- }]);
2490
+ }, {
2491
+ key: "rects",
2492
+ get: function get() {
2493
+ var _this2 = this;
2494
+ if (this._rects) return this._rects;
2495
+ this._rects = new Map();
2496
+ this.forEach(function (element) {
2497
+ return _this2._rects.set(element, element.getBoundingClientRect());
2498
+ });
2246
2499
 
2500
+ // since elements can be moved, we need to update the rects every X ms
2501
+ if (this._timeout) clearTimeout(this._timeout);
2502
+ this._timeout = setTimeout(function () {
2503
+ return _this2._rects = null;
2504
+ }, this.Settings.refreshMemoryRate);
2505
+ return this._rects;
2506
+ }
2507
+ }]);
2247
2508
  return SelectableSet;
2248
2509
  }( /*#__PURE__*/_wrapNativeSuper(Set));
2249
2510
 
2250
2511
  var SelectedSet = /*#__PURE__*/function (_Set) {
2251
2512
  _inherits(SelectedSet, _Set);
2252
-
2253
2513
  var _super = _createSuper(SelectedSet);
2254
-
2255
2514
  /**
2256
2515
  * @constructor SelectableSet
2257
2516
  * @param {{DS:DragSelect}} obj
@@ -2259,37 +2518,29 @@ var SelectedSet = /*#__PURE__*/function (_Set) {
2259
2518
  */
2260
2519
  function SelectedSet(_ref) {
2261
2520
  var _this;
2262
-
2263
2521
  var DS = _ref.DS;
2264
-
2265
2522
  _classCallCheck(this, SelectedSet);
2266
-
2267
2523
  _this = _super.call(this);
2268
-
2269
2524
  _defineProperty(_assertThisInitialized(_this), "clear", function () {
2270
2525
  return _this.forEach(function (el) {
2271
2526
  return _this["delete"](el);
2272
2527
  });
2273
2528
  });
2274
-
2275
2529
  _defineProperty(_assertThisInitialized(_this), "addAll", function (elements) {
2276
2530
  return elements.forEach(function (el) {
2277
2531
  return _this.add(el);
2278
2532
  });
2279
2533
  });
2280
-
2281
2534
  _defineProperty(_assertThisInitialized(_this), "deleteAll", function (elements) {
2282
2535
  return elements.forEach(function (el) {
2283
2536
  return _this["delete"](el);
2284
2537
  });
2285
2538
  });
2286
-
2287
2539
  _this.DS = DS;
2288
2540
  return _this;
2289
2541
  }
2290
- /** @param {DSElement} element */
2291
-
2292
2542
 
2543
+ /** @param {DSElement} element */
2293
2544
  _createClass(SelectedSet, [{
2294
2545
  key: "add",
2295
2546
  value: function add(element) {
@@ -2299,16 +2550,12 @@ var SelectedSet = /*#__PURE__*/function (_Set) {
2299
2550
  item: element
2300
2551
  };
2301
2552
  this.DS.publish('Selected:added:pre', publishData);
2302
-
2303
2553
  _get(_getPrototypeOf(SelectedSet.prototype), "add", this).call(this, element);
2304
-
2305
2554
  element.classList.add(this.DS.stores.SettingsStore.s.selectedClass);
2306
2555
  element.style.zIndex = "".concat((parseInt(element.style.zIndex) || 0) + 1);
2307
2556
  this.DS.publish('Selected:added', publishData);
2308
2557
  return this;
2309
- }
2310
- /** @param {DSElement} element */
2311
-
2558
+ } /** @param {DSElement} element */
2312
2559
  }, {
2313
2560
  key: "delete",
2314
2561
  value: function _delete(element) {
@@ -2318,9 +2565,7 @@ var SelectedSet = /*#__PURE__*/function (_Set) {
2318
2565
  item: element
2319
2566
  };
2320
2567
  this.DS.publish('Selected:removed:pre', publishData);
2321
-
2322
2568
  var deleted = _get(_getPrototypeOf(SelectedSet.prototype), "delete", this).call(this, element);
2323
-
2324
2569
  element.classList.remove(this.DS.stores.SettingsStore.s.selectedClass);
2325
2570
  element.style.zIndex = "".concat((parseInt(element.style.zIndex) || 0) - 1);
2326
2571
  this.DS.publish('Selected:removed', publishData);
@@ -2328,7 +2573,6 @@ var SelectedSet = /*#__PURE__*/function (_Set) {
2328
2573
  }
2329
2574
  }, {
2330
2575
  key: "toggle",
2331
-
2332
2576
  /**
2333
2577
  * Adds/Removes an element. If it is already selected = remove, if not = add.
2334
2578
  * @param {DSElement} element
@@ -2337,18 +2581,13 @@ var SelectedSet = /*#__PURE__*/function (_Set) {
2337
2581
  value: function toggle(element) {
2338
2582
  if (this.has(element)) this["delete"](element);else this.add(element);
2339
2583
  return element;
2340
- }
2341
- /** @param {DSElements} elements */
2342
-
2584
+ } /** @param {DSElements} elements */
2343
2585
  }, {
2344
2586
  key: "elements",
2345
-
2346
- /** @return {DSElements} */
2347
- get: function get() {
2587
+ /** @return {DSElements} */get: function get() {
2348
2588
  return Array.from(this.values());
2349
2589
  }
2350
2590
  }]);
2351
-
2352
2591
  return SelectedSet;
2353
2592
  }( /*#__PURE__*/_wrapNativeSuper(Set));
2354
2593
 
@@ -2365,50 +2604,46 @@ var Selection = /*#__PURE__*/function () {
2365
2604
  */
2366
2605
  function Selection(_ref) {
2367
2606
  var _this = this;
2368
-
2369
2607
  var DS = _ref.DS;
2370
-
2371
2608
  _classCallCheck(this, Selection);
2372
-
2373
2609
  _defineProperty(this, "_prevSelectedSet", void 0);
2374
-
2375
2610
  _defineProperty(this, "start", function (_ref2) {
2376
2611
  var event = _ref2.event,
2377
- isDragging = _ref2.isDragging;
2612
+ isDragging = _ref2.isDragging;
2378
2613
  if (isDragging) return;
2379
-
2380
2614
  _this._storePrevious(event);
2381
-
2382
2615
  _this._handleInsideSelection(true, event);
2383
2616
  });
2384
-
2385
2617
  _defineProperty(this, "update", function (_ref3) {
2386
2618
  var isDragging = _ref3.isDragging;
2387
2619
  if (isDragging || _this.DS["continue"]) return;
2388
-
2389
2620
  _this._handleInsideSelection();
2390
2621
  });
2391
-
2392
2622
  _defineProperty(this, "_handleInsideSelection", function (force, event) {
2393
2623
  var _this$DS = _this.DS,
2394
- SelectableSet = _this$DS.SelectableSet,
2395
- SelectorArea = _this$DS.SelectorArea,
2396
- Selector = _this$DS.Selector;
2624
+ SelectableSet = _this$DS.SelectableSet,
2625
+ SelectorArea = _this$DS.SelectorArea,
2626
+ Selector = _this$DS.Selector;
2397
2627
  /** @type {any} */
2398
-
2399
- var elPosCombo = SelectableSet.elements.map(function (element) {
2400
- return [element, element.getBoundingClientRect()];
2401
- });
2628
+ var elRects = SelectableSet.rects;
2402
2629
  var select = [];
2403
2630
  var unselect = [];
2404
-
2405
- for (var i = 0, il = elPosCombo.length; i < il; i++) {
2406
- if (!SelectorArea.isInside(elPosCombo[i][0], elPosCombo[i][1])) continue;
2407
- if (isCollision(elPosCombo[i][1], Selector.rect)) select.push(elPosCombo[i][0]);else unselect.push(elPosCombo[i][0]);
2631
+ var _iterator = _createForOfIteratorHelper(elRects),
2632
+ _step;
2633
+ try {
2634
+ for (_iterator.s(); !(_step = _iterator.n()).done;) {
2635
+ var _step$value = _slicedToArray(_step.value, 2),
2636
+ element = _step$value[0],
2637
+ rect = _step$value[1];
2638
+ if (!SelectorArea.isInside(element, rect)) continue;
2639
+ if (isCollision(rect, Selector.rect, _this.Settings.selectionThreshold)) select.push(element);else unselect.push(element);
2640
+ }
2641
+ } catch (err) {
2642
+ _iterator.e(err);
2643
+ } finally {
2644
+ _iterator.f();
2408
2645
  }
2409
-
2410
- var multiSelectionToggle = _this.DS.stores.KeyStore.isMultiSelectKeyPressed(event) && _this.DS.stores.SettingsStore.s.multiSelectToggling;
2411
-
2646
+ var multiSelectionToggle = _this.DS.stores.KeyStore.isMultiSelectKeyPressed(event) && _this.Settings.multiSelectToggling;
2412
2647
  if (_this.DS["continue"]) return;
2413
2648
  select.forEach(function (element) {
2414
2649
  return handleSelection({
@@ -2416,7 +2651,7 @@ var Selection = /*#__PURE__*/function () {
2416
2651
  force: force,
2417
2652
  multiSelectionToggle: multiSelectionToggle,
2418
2653
  SelectedSet: _this.DS.SelectedSet,
2419
- hoverClassName: _this.DS.stores.SettingsStore.s.hoverClass
2654
+ hoverClassName: _this.Settings.hoverClass
2420
2655
  });
2421
2656
  });
2422
2657
  unselect.forEach(function (element) {
@@ -2424,35 +2659,31 @@ var Selection = /*#__PURE__*/function () {
2424
2659
  element: element,
2425
2660
  force: force,
2426
2661
  SelectedSet: _this.DS.SelectedSet,
2427
- hoverClassName: _this.DS.stores.SettingsStore.s.hoverClass,
2662
+ hoverClassName: _this.Settings.hoverClass,
2428
2663
  PrevSelectedSet: _this._prevSelectedSet
2429
2664
  });
2430
2665
  });
2431
2666
  });
2432
-
2433
2667
  this.DS = DS;
2668
+ this.Settings = this.DS.stores.SettingsStore.s;
2434
2669
  this.DS.subscribe('Interaction:start', this.start);
2435
2670
  this.DS.subscribe('Interaction:update', this.update);
2436
2671
  }
2672
+
2437
2673
  /**
2438
2674
  * Stores the previous selection (solves #9)
2439
2675
  * @param {DSEvent} event
2440
2676
  * @private
2441
2677
  * */
2442
-
2443
-
2444
2678
  _createClass(Selection, [{
2445
2679
  key: "_storePrevious",
2446
2680
  value: function _storePrevious(event) {
2447
2681
  var _this$DS2 = this.DS,
2448
- KeyStore = _this$DS2.stores.KeyStore,
2449
- SelectedSet = _this$DS2.SelectedSet;
2682
+ KeyStore = _this$DS2.stores.KeyStore,
2683
+ SelectedSet = _this$DS2.SelectedSet;
2450
2684
  if (KeyStore.isMultiSelectKeyPressed(event)) this._prevSelectedSet = new Set(SelectedSet);else this._prevSelectedSet = new Set();
2451
- }
2452
- /** @param {{event:DSEvent,isDragging:boolean}} event */
2453
-
2685
+ } /** @param {{event:DSEvent,isDragging:boolean}} event */
2454
2686
  }]);
2455
-
2456
2687
  return Selection;
2457
2688
  }();
2458
2689
 
@@ -2469,24 +2700,16 @@ var Selector = /*#__PURE__*/function () {
2469
2700
  */
2470
2701
  function Selector(_ref) {
2471
2702
  var _this = this;
2472
-
2473
2703
  var DS = _ref.DS;
2474
-
2475
2704
  _classCallCheck(this, Selector);
2476
-
2477
2705
  _defineProperty(this, "_rect", void 0);
2478
-
2479
2706
  _defineProperty(this, "attachSelector", function () {
2480
2707
  var _this$DS$SelectorArea, _this$DS$SelectorArea2;
2481
-
2482
2708
  if (_this.HTMLNode && (_this$DS$SelectorArea = _this.DS.SelectorArea) !== null && _this$DS$SelectorArea !== void 0 && _this$DS$SelectorArea.HTMLNode) _this.DS.SelectorArea.HTMLNode.removeChild(_this.HTMLNode);
2483
2709
  _this.HTMLNode = _this.DS.stores.SettingsStore.s.selector || createSelectorElement(_this.DS.stores.SettingsStore.s.customStyles);
2484
-
2485
2710
  _this.HTMLNode.classList.add(_this.DS.stores.SettingsStore.s.selectorClass);
2486
-
2487
2711
  if (_this.HTMLNode && (_this$DS$SelectorArea2 = _this.DS.SelectorArea) !== null && _this$DS$SelectorArea2 !== void 0 && _this$DS$SelectorArea2.HTMLNode) _this.DS.SelectorArea.HTMLNode.appendChild(_this.HTMLNode);
2488
2712
  });
2489
-
2490
2713
  _defineProperty(this, "start", function (_ref2) {
2491
2714
  var isDragging = _ref2.isDragging;
2492
2715
  if (isDragging) return;
@@ -2496,19 +2719,17 @@ var Selector = /*#__PURE__*/function () {
2496
2719
  _this.HTMLNode.style.display = 'block';
2497
2720
  _this._rect = null;
2498
2721
  });
2499
-
2500
2722
  _defineProperty(this, "stop", function () {
2501
2723
  _this.HTMLNode.style.width = '0';
2502
2724
  _this.HTMLNode.style.height = '0';
2503
2725
  _this.HTMLNode.style.display = 'none';
2504
2726
  });
2505
-
2506
2727
  _defineProperty(this, "update", function (_ref3) {
2507
2728
  var isDragging = _ref3.isDragging;
2508
2729
  if (isDragging || _this.DS["continue"]) return;
2509
2730
  var _this$DS$stores = _this.DS.stores,
2510
- ScrollStore = _this$DS$stores.ScrollStore,
2511
- PointerStore = _this$DS$stores.PointerStore;
2731
+ ScrollStore = _this$DS$stores.ScrollStore,
2732
+ PointerStore = _this$DS$stores.PointerStore;
2512
2733
  var pos = getSelectorPosition({
2513
2734
  scrollAmount: ScrollStore.scrollAmount,
2514
2735
  initialPointerPos: PointerStore.initialValArea,
@@ -2517,24 +2738,21 @@ var Selector = /*#__PURE__*/function () {
2517
2738
  updateElementStylePos(_this.HTMLNode, pos);
2518
2739
  _this._rect = null;
2519
2740
  });
2741
+ this.DS = DS;
2520
2742
 
2521
- this.DS = DS; // @ts-ignore: @todo: update to typescript
2522
-
2743
+ // @ts-ignore: @todo: update to typescript
2523
2744
  this.DS.subscribe('Settings:updated:selectorClass', function (_ref4) {
2524
2745
  var settings = _ref4.settings;
2525
-
2526
2746
  _this.HTMLNode.classList.remove(settings['selectorClass:pre']);
2527
-
2528
2747
  _this.HTMLNode.classList.add(settings['selectorClass']);
2529
- }); // @ts-ignore: @todo: update to typescript
2530
-
2748
+ });
2749
+ // @ts-ignore: @todo: update to typescript
2531
2750
  this.DS.subscribe('Settings:updated:selector', this.attachSelector);
2532
2751
  this.attachSelector();
2533
2752
  this.DS.subscribe('Interaction:start', this.start);
2534
2753
  this.DS.subscribe('Interaction:update', this.update);
2535
2754
  this.DS.subscribe('Interaction:end', this.stop);
2536
2755
  }
2537
-
2538
2756
  _createClass(Selector, [{
2539
2757
  key: "rect",
2540
2758
  get: function get() {
@@ -2542,7 +2760,6 @@ var Selector = /*#__PURE__*/function () {
2542
2760
  return this._rect = this.HTMLNode.getBoundingClientRect();
2543
2761
  }
2544
2762
  }]);
2545
-
2546
2763
  return Selector;
2547
2764
  }();
2548
2765
 
@@ -2570,31 +2787,21 @@ var SelectorArea = /*#__PURE__*/function () {
2570
2787
  */
2571
2788
  function SelectorArea(_ref) {
2572
2789
  var _this = this;
2573
-
2574
2790
  var DS = _ref.DS;
2575
-
2576
2791
  _classCallCheck(this, SelectorArea);
2577
-
2578
2792
  _defineProperty(this, "_scrollInterval", void 0);
2579
-
2580
2793
  _defineProperty(this, "_rect", void 0);
2581
-
2582
2794
  _defineProperty(this, "currentEdges", []);
2583
-
2584
2795
  _defineProperty(this, "start", function () {
2585
2796
  return _this.applyElements('append');
2586
2797
  });
2587
-
2588
2798
  _defineProperty(this, "applyElements", function () {
2589
2799
  var method = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 'append';
2590
2800
  var docEl = document.body ? 'body' : 'documentElement';
2591
2801
  var methodName = "".concat(method, "Child");
2592
-
2593
2802
  _this.HTMLNode[methodName](_this.DS.Selector.HTMLNode);
2594
-
2595
2803
  document[docEl][methodName](_this.HTMLNode);
2596
2804
  });
2597
-
2598
2805
  _defineProperty(this, "updatePos", function () {
2599
2806
  _this._rect = null;
2600
2807
  var rect = _this.DS.Area.rect;
@@ -2609,25 +2816,21 @@ var SelectorArea = /*#__PURE__*/function () {
2609
2816
  if (style.width !== width) style.width = width;
2610
2817
  if (style.height !== height) style.height = height;
2611
2818
  });
2612
-
2613
2819
  _defineProperty(this, "stop", function (remove) {
2614
2820
  _this.stopAutoScroll();
2615
-
2616
2821
  if (remove) _this.applyElements('remove');
2617
2822
  });
2618
-
2619
2823
  _defineProperty(this, "startAutoScroll", function () {
2620
2824
  _this.currentEdges = [];
2621
2825
  _this._scrollInterval = setInterval(function () {
2622
2826
  return _this.handleAutoScroll();
2623
2827
  }, 16);
2624
2828
  });
2625
-
2626
2829
  _defineProperty(this, "handleAutoScroll", function () {
2627
2830
  if (_this.DS["continue"]) return;
2628
2831
  var _this$DS = _this.DS,
2629
- PointerStore = _this$DS.stores.PointerStore,
2630
- Area = _this$DS.Area;
2832
+ PointerStore = _this$DS.stores.PointerStore,
2833
+ Area = _this$DS.Area;
2631
2834
  _this.currentEdges = getOverflowEdges({
2632
2835
  elementRect: vect2rect(PointerStore.currentVal),
2633
2836
  containerRect: _this.rect,
@@ -2635,25 +2838,20 @@ var SelectorArea = /*#__PURE__*/function () {
2635
2838
  });
2636
2839
  if (_this.currentEdges.length) Area.scroll(_this.currentEdges, _this.DS.stores.SettingsStore.s.autoScrollSpeed);
2637
2840
  });
2638
-
2639
2841
  _defineProperty(this, "stopAutoScroll", function () {
2640
2842
  _this.currentEdges = [];
2641
2843
  clearInterval(_this._scrollInterval);
2642
2844
  });
2643
-
2644
2845
  _defineProperty(this, "isInside", function (element, elementRect) {
2645
2846
  if (_this.DS.Area.HTMLNode.contains(element) && _this.DS.stores.ScrollStore.canScroll) return true;
2646
2847
  return isCollision(_this.rect, elementRect || element.getBoundingClientRect());
2647
2848
  });
2648
-
2649
2849
  this.DS = DS;
2650
- this.HTMLNode = createSelectorAreaElement(); // @ts-ignore: @todo: update to typescript
2651
-
2850
+ this.HTMLNode = createSelectorAreaElement();
2851
+ // @ts-ignore: @todo: update to typescript
2652
2852
  this.DS.subscribe('Settings:updated:selectorAreaClass', function (_ref2) {
2653
2853
  var settings = _ref2.settings;
2654
-
2655
2854
  _this.HTMLNode.classList.remove(settings['selectorAreaClass:pre']);
2656
-
2657
2855
  _this.HTMLNode.classList.add(settings['selectorAreaClass']);
2658
2856
  });
2659
2857
  this.HTMLNode.classList.add(this.DS.stores.SettingsStore.s.selectorAreaClass);
@@ -2663,14 +2861,11 @@ var SelectorArea = /*#__PURE__*/function () {
2663
2861
  this.DS.subscribe('Interaction:start', this.startAutoScroll);
2664
2862
  this.DS.subscribe('Interaction:end', function () {
2665
2863
  _this.updatePos();
2666
-
2667
2864
  _this.stopAutoScroll();
2668
2865
  });
2669
2866
  }
2670
-
2671
2867
  _createClass(SelectorArea, [{
2672
2868
  key: "isClicked",
2673
-
2674
2869
  /**
2675
2870
  * checks if the click was triggered on the area.
2676
2871
  * @param {DSEvent} [event]
@@ -2693,7 +2888,6 @@ var SelectorArea = /*#__PURE__*/function () {
2693
2888
  return this._rect = this.HTMLNode.getBoundingClientRect();
2694
2889
  }
2695
2890
  }]);
2696
-
2697
2891
  return SelectorArea;
2698
2892
  }();
2699
2893
 
@@ -2716,80 +2910,59 @@ var KeyStore = /*#__PURE__*/function () {
2716
2910
  */
2717
2911
  function KeyStore(_ref) {
2718
2912
  var _this = this;
2719
-
2720
2913
  var DS = _ref.DS;
2721
-
2722
2914
  _classCallCheck(this, KeyStore);
2723
-
2724
2915
  _defineProperty(this, "_currentValues", new Set());
2725
-
2726
2916
  _defineProperty(this, "_keyMapping", {
2727
2917
  control: 'ctrlKey',
2728
2918
  shift: 'shiftKey',
2729
2919
  meta: 'metaKey'
2730
2920
  });
2731
-
2732
2921
  _defineProperty(this, "init", function () {
2733
2922
  document.addEventListener('keydown', _this.keydown);
2734
2923
  document.addEventListener('keyup', _this.keyup);
2735
2924
  window.addEventListener('blur', _this.reset);
2736
2925
  });
2737
-
2738
2926
  _defineProperty(this, "keydown", function (event) {
2739
2927
  var key = event.key.toLowerCase();
2740
-
2741
2928
  _this.DS.publish('KeyStore:down:pre', {
2742
2929
  event: event,
2743
2930
  key: key
2744
2931
  });
2745
-
2746
2932
  _this._currentValues.add(key);
2747
-
2748
2933
  _this.DS.publish('KeyStore:down', {
2749
2934
  event: event,
2750
2935
  key: key
2751
2936
  });
2752
2937
  });
2753
-
2754
2938
  _defineProperty(this, "keyup", function (event) {
2755
2939
  var key = event.key.toLowerCase();
2756
-
2757
2940
  _this.DS.publish('KeyStore:up:pre', {
2758
2941
  event: event,
2759
2942
  key: key
2760
2943
  });
2761
-
2762
2944
  _this._currentValues["delete"](key);
2763
-
2764
2945
  _this.DS.publish('KeyStore:up', {
2765
2946
  event: event,
2766
2947
  key: key
2767
2948
  });
2768
2949
  });
2769
-
2770
2950
  _defineProperty(this, "stop", function () {
2771
2951
  document.removeEventListener('keydown', _this.keydown);
2772
2952
  document.removeEventListener('keyup', _this.reset);
2773
2953
  window.removeEventListener('blur', _this.reset);
2774
-
2775
2954
  _this.reset();
2776
2955
  });
2777
-
2778
2956
  _defineProperty(this, "reset", function () {
2779
2957
  return _this._currentValues.clear();
2780
2958
  });
2781
-
2782
2959
  this.DS = DS;
2783
2960
  this.DS.subscribe('Interaction:init', this.init);
2784
2961
  }
2785
-
2786
2962
  _createClass(KeyStore, [{
2787
2963
  key: "isMultiSelectKeyPressed",
2788
-
2789
- /** @param {KeyboardEvent|MouseEvent|TouchEvent} [event] */
2790
- value: function isMultiSelectKeyPressed(event) {
2964
+ /** @param {KeyboardEvent|MouseEvent|PointerEvent|TouchEvent} [event] */value: function isMultiSelectKeyPressed(event) {
2791
2965
  var _this2 = this;
2792
-
2793
2966
  if (this.DS.stores.SettingsStore.s.multiSelectMode) return true;
2794
2967
  var multiSelectKeys = this.DS.stores.SettingsStore.s.multiSelectKeys.map(function (key) {
2795
2968
  return key.toLocaleLowerCase();
@@ -2808,14 +2981,13 @@ var KeyStore = /*#__PURE__*/function () {
2808
2981
  return Array.from(this._currentValues.values());
2809
2982
  }
2810
2983
  }]);
2811
-
2812
2984
  return KeyStore;
2813
2985
  }();
2814
2986
 
2815
2987
  var PointerStore = /*#__PURE__*/function () {
2816
2988
  /** @type {boolean} */
2817
- // Pointer Positions within Area
2818
2989
 
2990
+ // Pointer Positions within Area
2819
2991
  /**
2820
2992
  * @type {Vect2}
2821
2993
  * @private
@@ -2830,8 +3002,8 @@ var PointerStore = /*#__PURE__*/function () {
2830
3002
  * @type {Vect2}
2831
3003
  * @private
2832
3004
  * */
2833
- // General Pointer Position
2834
3005
 
3006
+ // General Pointer Position
2835
3007
  /**
2836
3008
  * @type {Vect2}
2837
3009
  * @private
@@ -2860,78 +3032,65 @@ var PointerStore = /*#__PURE__*/function () {
2860
3032
  */
2861
3033
  function PointerStore(_ref) {
2862
3034
  var _this = this;
2863
-
2864
3035
  var DS = _ref.DS;
2865
-
2866
3036
  _classCallCheck(this, PointerStore);
2867
-
2868
3037
  _defineProperty(this, "_isMouseInteraction", false);
2869
-
2870
3038
  _defineProperty(this, "_initialValArea", void 0);
2871
-
2872
3039
  _defineProperty(this, "_currentValArea", void 0);
2873
-
2874
3040
  _defineProperty(this, "_lastValArea", void 0);
2875
-
2876
3041
  _defineProperty(this, "_initialVal", void 0);
2877
-
2878
3042
  _defineProperty(this, "_currentVal", void 0);
2879
-
2880
3043
  _defineProperty(this, "_lastVal", void 0);
2881
-
2882
3044
  _defineProperty(this, "_lastTouch", void 0);
2883
-
2884
3045
  _defineProperty(this, "init", function () {
2885
- document.addEventListener('mousemove', _this.update);
3046
+ if (_this.Settings.usePointerEvents) document.addEventListener('pointermove', _this.update, {
3047
+ // @ts-ignore
3048
+ passive: false
3049
+ });else document.addEventListener('mousemove', _this.update);
2886
3050
  document.addEventListener('touchmove', _this.update, {
2887
3051
  // @ts-ignore
2888
3052
  passive: false
2889
3053
  });
2890
3054
  });
2891
-
2892
3055
  _defineProperty(this, "getPointerPosition", function (event) {
2893
3056
  return getPointerPos({
2894
3057
  event: _this._normalizedEvent(event)
2895
3058
  });
2896
3059
  });
2897
-
2898
3060
  _defineProperty(this, "update", function (event) {
2899
3061
  if (!event) return;
2900
-
2901
3062
  _this.DS.publish('PointerStore:updated:pre', {
2902
3063
  event: event
2903
3064
  });
2904
-
2905
3065
  _this.currentVal = _this.getPointerPosition(event);
2906
3066
  if (!_this._isMouseInteraction) return;
2907
-
2908
3067
  _this.DS.publish('PointerStore:updated', {
2909
3068
  event: event
2910
3069
  });
2911
3070
  });
2912
-
2913
3071
  _defineProperty(this, "stop", function () {
2914
- document.removeEventListener('mousemove', _this.update);
3072
+ // @TODO: fix pointer events mixing issue see [PR](https://github.com/ThibaultJanBeyer/DragSelect/pull/128#issuecomment-1154885289)
3073
+ if (_this.Settings.usePointerEvents) document.removeEventListener('pointermove', _this.update, {
3074
+ // @ts-ignore
3075
+ passive: false
3076
+ });else document.removeEventListener('mousemove', _this.update);
2915
3077
  document.removeEventListener('touchmove', _this.update, {
2916
3078
  // @ts-ignore
2917
3079
  passive: false
2918
- }); // debounce in order "onClick" to work
2919
-
3080
+ });
3081
+ // debounce in order "onClick" to work
2920
3082
  setTimeout(function () {
2921
3083
  return _this._isMouseInteraction = false;
2922
3084
  }, 100);
2923
3085
  });
2924
-
2925
3086
  _defineProperty(this, "reset", function (event) {
2926
3087
  if (!event) return;
2927
3088
  _this.currentVal = _this.lastVal = _this.getPointerPosition(event);
2928
-
2929
3089
  _this.stop();
2930
-
2931
3090
  _this.init();
2932
3091
  });
2933
-
2934
3092
  this.DS = DS;
3093
+ this.Settings = DS.stores.SettingsStore.s;
2935
3094
  this.DS.subscribe('Interaction:init', this.init);
2936
3095
  this.DS.subscribe('Interaction:start', function (_ref2) {
2937
3096
  var event = _ref2.event;
@@ -2942,35 +3101,27 @@ var PointerStore = /*#__PURE__*/function () {
2942
3101
  return _this.reset(event);
2943
3102
  });
2944
3103
  }
2945
-
2946
3104
  _createClass(PointerStore, [{
2947
3105
  key: "start",
2948
-
2949
- /** @param {DSEvent} [event] */
2950
- value: function start(event) {
3106
+ /** @param {DSEvent} [event] */value: function start(event) {
2951
3107
  if (!event) return;
2952
3108
  this._isMouseInteraction = true;
2953
3109
  this.currentVal = this.initialVal = this.getPointerPosition(event);
2954
- }
2955
- /** @param {DSEvent} event */
2956
-
3110
+ } /** @param {DSEvent} event */
2957
3111
  }, {
2958
3112
  key: "_normalizedEvent",
2959
-
2960
3113
  /**
2961
3114
  * @param {DSEvent} event
2962
- * @return {MouseEvent|Touch}
3115
+ * @return {MouseEvent|PointerEvent|Touch}
2963
3116
  * @private
2964
3117
  */
2965
3118
  value: function _normalizedEvent(event) {
2966
3119
  // touchend has not touches. so we take the last touch if a touchevent, we need to store the positions
2967
- if ('touches' in event && event.type !== 'touchend') this._lastTouch = event; // if a touchevent, return the last touch rather than the regular event
3120
+ if ('touches' in event && event.type !== 'touchend') this._lastTouch = event;
3121
+ // if a touchevent, return the last touch rather than the regular event
2968
3122
  // we need .touches[0] from that event instead
2969
-
2970
3123
  return 'touches' in event ? this._lastTouch.touches[0] : event;
2971
- }
2972
- /** First recorded pointer position within the area */
2973
-
3124
+ } /** First recorded pointer position within the area */
2974
3125
  }, {
2975
3126
  key: "initialValArea",
2976
3127
  get: function get() {
@@ -2979,9 +3130,7 @@ var PointerStore = /*#__PURE__*/function () {
2979
3130
  y: 0
2980
3131
  };
2981
3132
  return this._initialValArea;
2982
- }
2983
- /** Current pointer position within the area */
2984
-
3133
+ } /** Current pointer position within the area */
2985
3134
  }, {
2986
3135
  key: "currentValArea",
2987
3136
  get: function get() {
@@ -2990,9 +3139,7 @@ var PointerStore = /*#__PURE__*/function () {
2990
3139
  y: 0
2991
3140
  };
2992
3141
  return this._currentValArea;
2993
- }
2994
- /** Last recorded pointer position within the area */
2995
-
3142
+ } /** Last recorded pointer position within the area */
2996
3143
  }, {
2997
3144
  key: "lastValArea",
2998
3145
  get: function get() {
@@ -3001,9 +3148,7 @@ var PointerStore = /*#__PURE__*/function () {
3001
3148
  y: 0
3002
3149
  };
3003
3150
  return this._lastValArea;
3004
- }
3005
- /** First recorded pointer position */
3006
-
3151
+ } /** First recorded pointer position */
3007
3152
  }, {
3008
3153
  key: "initialVal",
3009
3154
  get: function get() {
@@ -3012,9 +3157,7 @@ var PointerStore = /*#__PURE__*/function () {
3012
3157
  y: 0
3013
3158
  };
3014
3159
  return this._initialVal;
3015
- }
3016
- /** Current pointer position */
3017
- ,
3160
+ } /** Current pointer position */,
3018
3161
  set: function set(value) {
3019
3162
  this._initialVal = value;
3020
3163
  this._initialValArea = value && calc(value, '-', calc(rect2vect(this.DS.Area.rect), '+', rect2vect(this.DS.Area.computedBorder)));
@@ -3027,9 +3170,7 @@ var PointerStore = /*#__PURE__*/function () {
3027
3170
  y: 0
3028
3171
  };
3029
3172
  return this._currentVal;
3030
- }
3031
- /** Last recorded pointer position */
3032
- ,
3173
+ } /** Last recorded pointer position */,
3033
3174
  set: function set(value) {
3034
3175
  this._currentVal = value;
3035
3176
  this._currentValArea = value && calc(value, '-', calc(rect2vect(this.DS.Area.rect), '+', rect2vect(this.DS.Area.computedBorder)));
@@ -3048,7 +3189,6 @@ var PointerStore = /*#__PURE__*/function () {
3048
3189
  this._lastValArea = value && calc(value, '-', calc(rect2vect(this.DS.Area.rect), '+', rect2vect(this.DS.Area.computedBorder)));
3049
3190
  }
3050
3191
  }]);
3051
-
3052
3192
  return PointerStore;
3053
3193
  }();
3054
3194
 
@@ -3073,47 +3213,33 @@ var ScrollStore = /*#__PURE__*/function () {
3073
3213
  */
3074
3214
  function ScrollStore(_ref) {
3075
3215
  var _this = this;
3076
-
3077
3216
  var DS = _ref.DS;
3078
-
3079
3217
  _classCallCheck(this, ScrollStore);
3080
-
3081
3218
  _defineProperty(this, "_initialVal", void 0);
3082
-
3083
3219
  _defineProperty(this, "_currentVal", void 0);
3084
-
3085
3220
  _defineProperty(this, "_canScroll", void 0);
3086
-
3087
3221
  _defineProperty(this, "init", function () {
3088
3222
  return _this.DS.stores.SettingsStore.s.area.addEventListener('scroll', _this.update);
3089
3223
  });
3090
-
3091
3224
  _defineProperty(this, "start", function () {
3092
3225
  _this._currentVal = _this._initialVal = getCurrentScroll(_this.DS.stores.SettingsStore.s.area);
3093
-
3094
3226
  _this.DS.stores.SettingsStore.s.area.addEventListener('scroll', _this.update);
3095
3227
  });
3096
-
3097
3228
  _defineProperty(this, "update", function () {
3098
3229
  return _this._currentVal = getCurrentScroll(_this.DS.stores.SettingsStore.s.area);
3099
3230
  });
3100
-
3101
3231
  _defineProperty(this, "stop", function () {
3102
3232
  _this.DS.stores.SettingsStore.s.area.removeEventListener('scroll', _this.update);
3103
-
3104
3233
  _this._initialVal = {
3105
3234
  x: 0,
3106
3235
  y: 0
3107
3236
  };
3108
3237
  _this._canScroll = null;
3109
3238
  });
3110
-
3111
3239
  _defineProperty(this, "reset", function () {
3112
3240
  _this.stop();
3113
-
3114
3241
  _this.start();
3115
3242
  });
3116
-
3117
3243
  this.DS = DS;
3118
3244
  this.DS.subscribe('Interaction:init', this.init);
3119
3245
  this.DS.subscribe('Interaction:start', function () {
@@ -3123,7 +3249,6 @@ var ScrollStore = /*#__PURE__*/function () {
3123
3249
  return _this.reset();
3124
3250
  });
3125
3251
  }
3126
-
3127
3252
  _createClass(ScrollStore, [{
3128
3253
  key: "canScroll",
3129
3254
  get: function get() {
@@ -3133,8 +3258,9 @@ var ScrollStore = /*#__PURE__*/function () {
3133
3258
  }, {
3134
3259
  key: "scrollAmount",
3135
3260
  get: function get() {
3136
- var scrollDiff = calc(this.currentVal, '-', this.initialVal); // if area is zoomed, the scroll values are skewed, we need to fix that manually :(
3261
+ var scrollDiff = calc(this.currentVal, '-', this.initialVal);
3137
3262
 
3263
+ // if area is zoomed, the scroll values are skewed, we need to fix that manually :(
3138
3264
  var zoom = num2vect(this.DS.stores.SettingsStore.s.zoom);
3139
3265
  var zoomScroll = calc(calc(scrollDiff, '*', zoom), '-', scrollDiff);
3140
3266
  return {
@@ -3158,7 +3284,6 @@ var ScrollStore = /*#__PURE__*/function () {
3158
3284
  return this._currentVal;
3159
3285
  }
3160
3286
  }]);
3161
-
3162
3287
  return ScrollStore;
3163
3288
  }();
3164
3289
 
@@ -3185,39 +3310,29 @@ var SettingsStore =
3185
3310
  */
3186
3311
  function SettingsStore(_ref) {
3187
3312
  var _this = this;
3188
-
3189
3313
  var DS = _ref.DS,
3190
- _settings2 = _ref.settings;
3191
-
3314
+ _settings2 = _ref.settings;
3192
3315
  _classCallCheck(this, SettingsStore);
3193
-
3194
3316
  _defineProperty(this, "_settings", {});
3195
-
3196
3317
  _defineProperty(this, "s", {});
3197
-
3198
3318
  _defineProperty(this, "update", function (_ref2) {
3199
3319
  var settings = _ref2.settings,
3200
- init = _ref2.init;
3320
+ init = _ref2.init;
3201
3321
  return _this.DS.publish('Settings:updated:pre', _objectSpread2({
3202
3322
  settings: settings
3203
3323
  }, init ? {
3204
3324
  init: init
3205
3325
  } : {}));
3206
3326
  });
3207
-
3208
3327
  _defineProperty(this, "_update", function (_ref3) {
3209
3328
  var settings = _ref3.settings,
3210
- init = _ref3.init;
3211
-
3329
+ init = _ref3.init;
3212
3330
  var _settings = hydrateSettings(settings, init);
3213
-
3214
3331
  var _loop = function _loop() {
3215
3332
  var _settings4;
3216
-
3217
3333
  var _Object$entries$_i = _slicedToArray(_Object$entries[_i], 2),
3218
- key = _Object$entries$_i[0],
3219
- value = _Object$entries$_i[1];
3220
-
3334
+ key = _Object$entries$_i[0],
3335
+ value = _Object$entries$_i[1];
3221
3336
  if (!(key in _this._settings)) {
3222
3337
  Object.defineProperty(_this.s, key, {
3223
3338
  get: function get() {
@@ -3230,24 +3345,19 @@ function SettingsStore(_ref) {
3230
3345
  }
3231
3346
  });
3232
3347
  }
3233
-
3234
3348
  _this._settings["".concat(key, ":pre")] = _this._settings[key];
3235
3349
  _this._settings[key] = value;
3236
3350
  var update = {
3237
3351
  settings: (_settings4 = {}, _defineProperty(_settings4, key, _this._settings[key]), _defineProperty(_settings4, "".concat(key, ":pre"), _this._settings["".concat(key, ":pre")]), _settings4)
3238
3352
  };
3239
-
3240
- _this.DS.publish('Settings:updated', update); // @ts-ignore: @todo: update to typescript
3241
-
3242
-
3353
+ _this.DS.publish('Settings:updated', update);
3354
+ // @ts-ignore: @todo: update to typescript
3243
3355
  _this.DS.publish("Settings:updated:".concat(key), update);
3244
3356
  };
3245
-
3246
3357
  for (var _i = 0, _Object$entries = Object.entries(_settings); _i < _Object$entries.length; _i++) {
3247
3358
  _loop();
3248
3359
  }
3249
3360
  });
3250
-
3251
3361
  this.DS = DS;
3252
3362
  this.DS.subscribe('Settings:updated:pre', this._update);
3253
3363
  this.update({
@@ -3255,11 +3365,11 @@ function SettingsStore(_ref) {
3255
3365
  init: true
3256
3366
  });
3257
3367
  }
3258
- /** @param {{settings: Settings, init?: boolean}} props */
3259
- ;
3260
3368
 
3261
- //////////////////////////////////////////////////////////////////////////////////////
3369
+ /** @param {{settings: Settings, init?: boolean}} props */;
3262
3370
 
3371
+ // Setup
3372
+ //////////////////////////////////////////////////////////////////////////////////////
3263
3373
  var DragSelect = /*#__PURE__*/function () {
3264
3374
  /**
3265
3375
  * used to skip all current Selection and dragNdrop functionality
@@ -3273,76 +3383,67 @@ var DragSelect = /*#__PURE__*/function () {
3273
3383
  */
3274
3384
  function DragSelect(_settings) {
3275
3385
  var _this = this;
3276
-
3277
3386
  _classCallCheck(this, DragSelect);
3278
-
3279
3387
  _defineProperty(this, "continue", false);
3280
-
3281
3388
  _defineProperty(this, "start", function () {
3282
3389
  _this.stopped = false;
3283
-
3284
3390
  _this.Interaction.init();
3285
3391
  });
3286
-
3287
3392
  _defineProperty(this, "break", function () {
3288
3393
  return _this["continue"] = true;
3289
3394
  });
3290
-
3395
+ _defineProperty(this, "setSettings", function (settings) {
3396
+ return _this.stores.SettingsStore.update({
3397
+ settings: settings
3398
+ });
3399
+ });
3291
3400
  _defineProperty(this, "getSelection", function () {
3292
3401
  return _this.SelectedSet.elements;
3293
3402
  });
3294
-
3295
3403
  _defineProperty(this, "getSelectables", function () {
3296
3404
  return _this.SelectableSet.elements;
3297
3405
  });
3298
-
3299
3406
  _defineProperty(this, "getInitialCursorPosition", function () {
3300
3407
  return _this.stores.PointerStore.initialVal;
3301
3408
  });
3302
-
3303
3409
  _defineProperty(this, "getCurrentCursorPosition", function () {
3304
3410
  return _this.stores.PointerStore.currentVal;
3305
3411
  });
3306
-
3307
3412
  _defineProperty(this, "getPreviousCursorPosition", function () {
3308
3413
  return _this.stores.PointerStore.lastVal;
3309
3414
  });
3310
-
3311
3415
  _defineProperty(this, "getInitialCursorPositionArea", function () {
3312
3416
  return _this.stores.PointerStore.initialValArea;
3313
3417
  });
3314
-
3315
3418
  _defineProperty(this, "getCurrentCursorPositionArea", function () {
3316
3419
  return _this.stores.PointerStore.currentValArea;
3317
3420
  });
3318
-
3319
3421
  _defineProperty(this, "getPreviousCursorPositionArea", function () {
3320
3422
  return _this.stores.PointerStore.lastValArea;
3321
3423
  });
3322
-
3323
3424
  _defineProperty(this, "isMultiSelect", function (event) {
3324
3425
  return _this.stores.KeyStore.isMultiSelectKeyPressed(event);
3325
3426
  });
3326
-
3327
3427
  _defineProperty(this, "isDragging", function () {
3328
3428
  return _this.Interaction.isDragging;
3329
3429
  });
3330
-
3331
- _defineProperty(this, "setSettings", function (settings) {
3332
- return _this.stores.SettingsStore.update({
3333
- settings: settings
3334
- });
3430
+ _defineProperty(this, "getZoneByCoordinates", function (coordinates) {
3431
+ var _this$DropZones$getTa;
3432
+ return (_this$DropZones$getTa = _this.DropZones.getTarget(coordinates)) === null || _this$DropZones$getTa === void 0 ? void 0 : _this$DropZones$getTa.toObject();
3433
+ });
3434
+ _defineProperty(this, "getItemsDroppedByZoneId", function (zoneId) {
3435
+ return _this.DropZones.getItemsDroppedById(zoneId);
3436
+ });
3437
+ _defineProperty(this, "getItemsInsideByZoneId", function (zoneId, addClasses) {
3438
+ return _this.DropZones.getItemsInsideById(zoneId, addClasses);
3335
3439
  });
3336
-
3337
3440
  this.PubSub = new PubSub({
3338
3441
  DS: this
3339
3442
  });
3340
3443
  this.subscribe = this.PubSub.subscribe;
3341
3444
  this.unsubscribe = this.PubSub.unsubscribe;
3342
3445
  this.publish = this.PubSub.publish;
3343
- this.stores =
3344
- /** @type {{ SettingsStore:SettingsStore, PointerStore:PointerStore, ScrollStore:ScrollStore, KeyStore:KeyStore }} */
3345
- {};
3446
+ this.stores = /** @type {{ SettingsStore:SettingsStore, PointerStore:PointerStore, ScrollStore:ScrollStore, KeyStore:KeyStore }} */{};
3346
3447
  this.stores.SettingsStore = new SettingsStore({
3347
3448
  DS: this,
3348
3449
  settings: _settings
@@ -3377,32 +3478,35 @@ var DragSelect = /*#__PURE__*/function () {
3377
3478
  this.Drag = new Drag({
3378
3479
  DS: this
3379
3480
  });
3481
+ this.DropZones = new DropZones({
3482
+ DS: this
3483
+ });
3380
3484
  this.Interaction = new Interaction({
3381
3485
  DS: this
3382
- }); // Subscriber Aliases
3486
+ });
3383
3487
 
3488
+ // Subscriber Aliases
3384
3489
  subscriberAliases({
3385
3490
  subscribe: this.subscribe,
3386
3491
  publish: this.publish,
3387
3492
  SelectedSet: this.SelectedSet,
3388
- Interaction: this.Interaction
3493
+ Interaction: this.Interaction,
3494
+ DropZones: this.DropZones
3389
3495
  });
3390
3496
  this.subscribe('Interaction:end', function () {
3391
3497
  return _this["continue"] = false;
3392
3498
  });
3393
3499
  this.start();
3394
- } // Useful methods for the user
3395
- //////////////////////////////////////////////////////////////////////////////////////
3500
+ }
3396
3501
 
3502
+ // Useful methods for the user
3503
+ //////////////////////////////////////////////////////////////////////////////////////
3397
3504
  /**
3398
3505
  * Initializes the functionality. Automatically triggered when created.
3399
3506
  * Also, reset the functionality after a teardown
3400
3507
  */
3401
-
3402
-
3403
3508
  _createClass(DragSelect, [{
3404
3509
  key: "stop",
3405
-
3406
3510
  /**
3407
3511
  * Complete function teardown
3408
3512
  * Will teardown/stop the whole functionality
@@ -3434,10 +3538,8 @@ var DragSelect = /*#__PURE__*/function () {
3434
3538
  * Break will skip the selection or dragging functionality (until after the callback) but let everything continue to run.
3435
3539
  * Useful utility to write your own functionality/move/dragNdrop based on DragSelect pointer positions.
3436
3540
  */
3437
-
3438
3541
  }, {
3439
3542
  key: "addSelection",
3440
-
3441
3543
  /**
3442
3544
  * Adds several elements to the selection list also adds the specific classes and take into account all calculations.
3443
3545
  * Does not clear the selection, in contrary to .setSelection. Can add multiple elements at once
@@ -3464,7 +3566,6 @@ var DragSelect = /*#__PURE__*/function () {
3464
3566
  * @param {boolean} [removeFromSelectables] - if element should be removed from the list of selectable elements
3465
3567
  * @return {DSElements} all selected elements
3466
3568
  */
3467
-
3468
3569
  }, {
3469
3570
  key: "removeSelection",
3470
3571
  value: function removeSelection(elements) {
@@ -3486,12 +3587,10 @@ var DragSelect = /*#__PURE__*/function () {
3486
3587
  * @param {boolean} [alsoSelectables] - if element should not be added/removed to the list of selectable elements accordingly
3487
3588
  * @return {DSElements} all selected elements
3488
3589
  */
3489
-
3490
3590
  }, {
3491
3591
  key: "toggleSelection",
3492
3592
  value: function toggleSelection(elements) {
3493
3593
  var _this2 = this;
3494
-
3495
3594
  var triggerCallback = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false;
3496
3595
  var alsoSelectables = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : false;
3497
3596
  toArray(elements).forEach(function (el) {
@@ -3510,7 +3609,6 @@ var DragSelect = /*#__PURE__*/function () {
3510
3609
  * @param {boolean} [dontAddToSelectables] - if element should not be added to the list of selectable elements
3511
3610
  * @return {DSElements}
3512
3611
  */
3513
-
3514
3612
  }, {
3515
3613
  key: "setSelection",
3516
3614
  value: function setSelection(elements) {
@@ -3525,7 +3623,6 @@ var DragSelect = /*#__PURE__*/function () {
3525
3623
  * @param {boolean} [triggerCallback] - if callback should be called
3526
3624
  * @return {DSElements} this.selected, should be empty
3527
3625
  */
3528
-
3529
3626
  }, {
3530
3627
  key: "clearSelection",
3531
3628
  value: function clearSelection() {
@@ -3543,7 +3640,6 @@ var DragSelect = /*#__PURE__*/function () {
3543
3640
  * @param {boolean} [triggerCallback] - if callback should be called
3544
3641
  * @return {DSInputElements} the added element(s)
3545
3642
  */
3546
-
3547
3643
  }, {
3548
3644
  key: "addSelectables",
3549
3645
  value: function addSelectables(elements, addToSelection, triggerCallback) {
@@ -3559,10 +3655,8 @@ var DragSelect = /*#__PURE__*/function () {
3559
3655
  * Gets all nodes that can potentially be selected
3560
3656
  * @return {DSElements} this.selectables
3561
3657
  */
3562
-
3563
3658
  }, {
3564
3659
  key: "setSelectables",
3565
-
3566
3660
  /**
3567
3661
  * Sets all elements that can be selected.
3568
3662
  * Removes all current selectables (& their respective classes).
@@ -3586,7 +3680,6 @@ var DragSelect = /*#__PURE__*/function () {
3586
3680
  * @param {boolean} [triggerCallback] - if callback should be called
3587
3681
  * @return {DSInputElements} the removed element(s)
3588
3682
  */
3589
-
3590
3683
  }, {
3591
3684
  key: "removeSelectables",
3592
3685
  value: function removeSelectables(elements, removeFromSelection, triggerCallback) {
@@ -3596,11 +3689,8 @@ var DragSelect = /*#__PURE__*/function () {
3596
3689
  items: this.getSelection()
3597
3690
  });
3598
3691
  return elements;
3599
- }
3600
- /** The starting/initial position of the cursor/selector @return {Vect2} */
3601
-
3692
+ } /** The starting/initial position of the cursor/selector @return {Vect2} */
3602
3693
  }]);
3603
-
3604
3694
  return DragSelect;
3605
3695
  }();
3606
3696