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