dragselect 3.1.1 → 3.1.4

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