svelte-dnd-action 0.9.19 → 0.9.21

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.mjs CHANGED
@@ -1,16 +1,13 @@
1
1
  function ownKeys(object, enumerableOnly) {
2
2
  var keys = Object.keys(object);
3
-
4
3
  if (Object.getOwnPropertySymbols) {
5
4
  var symbols = Object.getOwnPropertySymbols(object);
6
5
  enumerableOnly && (symbols = symbols.filter(function (sym) {
7
6
  return Object.getOwnPropertyDescriptor(object, sym).enumerable;
8
7
  })), keys.push.apply(keys, symbols);
9
8
  }
10
-
11
9
  return keys;
12
10
  }
13
-
14
11
  function _objectSpread2(target) {
15
12
  for (var i = 1; i < arguments.length; i++) {
16
13
  var source = null != arguments[i] ? arguments[i] : {};
@@ -20,10 +17,8 @@ function _objectSpread2(target) {
20
17
  Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key));
21
18
  });
22
19
  }
23
-
24
20
  return target;
25
21
  }
26
-
27
22
  function _typeof(obj) {
28
23
  "@babel/helpers - typeof";
29
24
 
@@ -33,7 +28,6 @@ function _typeof(obj) {
33
28
  return obj && "function" == typeof Symbol && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj;
34
29
  }, _typeof(obj);
35
30
  }
36
-
37
31
  function _defineProperty(obj, key, value) {
38
32
  if (key in obj) {
39
33
  Object.defineProperty(obj, key, {
@@ -45,35 +39,26 @@ function _defineProperty(obj, key, value) {
45
39
  } else {
46
40
  obj[key] = value;
47
41
  }
48
-
49
42
  return obj;
50
43
  }
51
-
52
44
  function _objectWithoutPropertiesLoose(source, excluded) {
53
45
  if (source == null) return {};
54
46
  var target = {};
55
47
  var sourceKeys = Object.keys(source);
56
48
  var key, i;
57
-
58
49
  for (i = 0; i < sourceKeys.length; i++) {
59
50
  key = sourceKeys[i];
60
51
  if (excluded.indexOf(key) >= 0) continue;
61
52
  target[key] = source[key];
62
53
  }
63
-
64
54
  return target;
65
55
  }
66
-
67
56
  function _objectWithoutProperties(source, excluded) {
68
57
  if (source == null) return {};
69
-
70
58
  var target = _objectWithoutPropertiesLoose(source, excluded);
71
-
72
59
  var key, i;
73
-
74
60
  if (Object.getOwnPropertySymbols) {
75
61
  var sourceSymbolKeys = Object.getOwnPropertySymbols(source);
76
-
77
62
  for (i = 0; i < sourceSymbolKeys.length; i++) {
78
63
  key = sourceSymbolKeys[i];
79
64
  if (excluded.indexOf(key) >= 0) continue;
@@ -81,44 +66,33 @@ function _objectWithoutProperties(source, excluded) {
81
66
  target[key] = source[key];
82
67
  }
83
68
  }
84
-
85
69
  return target;
86
70
  }
87
-
88
71
  function _slicedToArray(arr, i) {
89
72
  return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest();
90
73
  }
91
-
92
74
  function _toConsumableArray(arr) {
93
75
  return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _unsupportedIterableToArray(arr) || _nonIterableSpread();
94
76
  }
95
-
96
77
  function _arrayWithoutHoles(arr) {
97
78
  if (Array.isArray(arr)) return _arrayLikeToArray(arr);
98
79
  }
99
-
100
80
  function _arrayWithHoles(arr) {
101
81
  if (Array.isArray(arr)) return arr;
102
82
  }
103
-
104
83
  function _iterableToArray(iter) {
105
84
  if (typeof Symbol !== "undefined" && iter[Symbol.iterator] != null || iter["@@iterator"] != null) return Array.from(iter);
106
85
  }
107
-
108
86
  function _iterableToArrayLimit(arr, i) {
109
87
  var _i = arr == null ? null : typeof Symbol !== "undefined" && arr[Symbol.iterator] || arr["@@iterator"];
110
-
111
88
  if (_i == null) return;
112
89
  var _arr = [];
113
90
  var _n = true;
114
91
  var _d = false;
115
-
116
92
  var _s, _e;
117
-
118
93
  try {
119
94
  for (_i = _i.call(arr); !(_n = (_s = _i.next()).done); _n = true) {
120
95
  _arr.push(_s.value);
121
-
122
96
  if (i && _arr.length === i) break;
123
97
  }
124
98
  } catch (err) {
@@ -131,10 +105,8 @@ function _iterableToArrayLimit(arr, i) {
131
105
  if (_d) throw _e;
132
106
  }
133
107
  }
134
-
135
108
  return _arr;
136
109
  }
137
-
138
110
  function _unsupportedIterableToArray(o, minLen) {
139
111
  if (!o) return;
140
112
  if (typeof o === "string") return _arrayLikeToArray(o, minLen);
@@ -143,33 +115,24 @@ function _unsupportedIterableToArray(o, minLen) {
143
115
  if (n === "Map" || n === "Set") return Array.from(o);
144
116
  if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen);
145
117
  }
146
-
147
118
  function _arrayLikeToArray(arr, len) {
148
119
  if (len == null || len > arr.length) len = arr.length;
149
-
150
120
  for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i];
151
-
152
121
  return arr2;
153
122
  }
154
-
155
123
  function _nonIterableSpread() {
156
124
  throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
157
125
  }
158
-
159
126
  function _nonIterableRest() {
160
127
  throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
161
128
  }
162
-
163
129
  function _createForOfIteratorHelper(o, allowArrayLike) {
164
130
  var it = typeof Symbol !== "undefined" && o[Symbol.iterator] || o["@@iterator"];
165
-
166
131
  if (!it) {
167
132
  if (Array.isArray(o) || (it = _unsupportedIterableToArray(o)) || allowArrayLike && o && typeof o.length === "number") {
168
133
  if (it) o = it;
169
134
  var i = 0;
170
-
171
135
  var F = function () {};
172
-
173
136
  return {
174
137
  s: F,
175
138
  n: function () {
@@ -187,13 +150,11 @@ function _createForOfIteratorHelper(o, allowArrayLike) {
187
150
  f: F
188
151
  };
189
152
  }
190
-
191
153
  throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
192
154
  }
193
-
194
155
  var normalCompletion = true,
195
- didErr = false,
196
- err;
156
+ didErr = false,
157
+ err;
197
158
  return {
198
159
  s: function () {
199
160
  it = it.call(o);
@@ -220,6 +181,7 @@ function _createForOfIteratorHelper(o, allowArrayLike) {
220
181
  // external events
221
182
  var FINALIZE_EVENT_NAME = "finalize";
222
183
  var CONSIDER_EVENT_NAME = "consider";
184
+
223
185
  /**
224
186
  * @typedef {Object} Info
225
187
  * @property {string} trigger
@@ -229,7 +191,6 @@ var CONSIDER_EVENT_NAME = "consider";
229
191
  * @param {Array} items
230
192
  * @param {Info} info
231
193
  */
232
-
233
194
  function dispatchFinalizeEvent(el, items, info) {
234
195
  el.dispatchEvent(new CustomEvent(FINALIZE_EVENT_NAME, {
235
196
  detail: {
@@ -238,13 +199,13 @@ function dispatchFinalizeEvent(el, items, info) {
238
199
  }
239
200
  }));
240
201
  }
202
+
241
203
  /**
242
204
  * Dispatches a consider event
243
205
  * @param {Node} el
244
206
  * @param {Array} items
245
207
  * @param {Info} info
246
208
  */
247
-
248
209
  function dispatchConsiderEvent(el, items, info) {
249
210
  el.dispatchEvent(new CustomEvent(CONSIDER_EVENT_NAME, {
250
211
  detail: {
@@ -252,8 +213,9 @@ function dispatchConsiderEvent(el, items, info) {
252
213
  info: info
253
214
  }
254
215
  }));
255
- } // internal events
216
+ }
256
217
 
218
+ // internal events
257
219
  var DRAGGED_ENTERED_EVENT_NAME = "draggedEntered";
258
220
  var DRAGGED_LEFT_EVENT_NAME = "draggedLeft";
259
221
  var DRAGGED_OVER_INDEX_EVENT_NAME = "draggedOverIndex";
@@ -270,12 +232,12 @@ function dispatchDraggedElementEnteredContainer(containerEl, indexObj, draggedEl
270
232
  }
271
233
  }));
272
234
  }
235
+
273
236
  /**
274
237
  * @param containerEl - the dropzone the element left
275
238
  * @param draggedEl - the dragged element
276
239
  * @param theOtherDz - the new dropzone the element entered
277
240
  */
278
-
279
241
  function dispatchDraggedElementLeftContainerForAnother(containerEl, draggedEl, theOtherDz) {
280
242
  containerEl.dispatchEvent(new CustomEvent(DRAGGED_LEFT_EVENT_NAME, {
281
243
  detail: {
@@ -338,25 +300,22 @@ function decrementActiveDropZoneCount() {
338
300
  if (activeDndZoneCount === 0) {
339
301
  throw new Error("Bug! trying to decrement when there are no dropzones");
340
302
  }
341
-
342
303
  activeDndZoneCount--;
343
304
  }
305
+
344
306
  /**
345
307
  * Allows using another key instead of "id" in the items data. This is global and applies to all dndzones.
346
308
  * Has to be called when there are no rendered dndzones whatsoever.
347
309
  * @param {String} newKeyName
348
310
  * @throws {Error} if it was called when there are rendered dndzones or if it is given the wrong type (not a string)
349
311
  */
350
-
351
312
  function overrideItemIdKeyNameBeforeInitialisingDndZones(newKeyName) {
352
313
  if (activeDndZoneCount > 0) {
353
314
  throw new Error("can only override the id key before initialising any dndzone");
354
315
  }
355
-
356
316
  if (typeof newKeyName !== "string") {
357
317
  throw new Error("item id key has to be a string");
358
318
  }
359
-
360
319
  printDebug(function () {
361
320
  return ["overriding item id key name", newKeyName];
362
321
  });
@@ -364,17 +323,16 @@ function overrideItemIdKeyNameBeforeInitialisingDndZones(newKeyName) {
364
323
  }
365
324
  var isOnServer = typeof window === "undefined";
366
325
  var printDebug = function printDebug() {};
326
+
367
327
  /**
368
328
  * Allows the user to show/hide console debug output
369
329
  * * @param {Boolean} isDebug
370
330
  */
371
-
372
331
  function setDebugMode(isDebug) {
373
332
  if (isDebug) {
374
333
  printDebug = function printDebug(generateMessage) {
375
334
  var logFunction = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : console.debug;
376
335
  var message = generateMessage();
377
-
378
336
  if (Array.isArray(message)) {
379
337
  logFunction.apply(void 0, _toConsumableArray(message));
380
338
  } else {
@@ -388,7 +346,6 @@ function setDebugMode(isDebug) {
388
346
 
389
347
  // This is based off https://stackoverflow.com/questions/27745438/how-to-compute-getboundingclientrect-without-considering-transforms/57876601#57876601
390
348
  // It removes the transforms that are potentially applied by the flip animations
391
-
392
349
  /**
393
350
  * Gets the bounding rect but removes transforms (ex: flip animation)
394
351
  * @param {HTMLElement} el
@@ -399,10 +356,8 @@ function getBoundingRectNoTransforms(el) {
399
356
  var rect = el.getBoundingClientRect();
400
357
  var style = getComputedStyle(el);
401
358
  var tx = style.transform;
402
-
403
359
  if (tx) {
404
360
  var sx, sy, dx, dy;
405
-
406
361
  if (tx.startsWith("matrix3d(")) {
407
362
  ta = tx.slice(9, -1).split(/, /);
408
363
  sx = +ta[0];
@@ -418,7 +373,6 @@ function getBoundingRectNoTransforms(el) {
418
373
  } else {
419
374
  return rect;
420
375
  }
421
-
422
376
  var to = style.transformOrigin;
423
377
  var x = rect.x - dx - (1 - sx) * parseFloat(to);
424
378
  var y = rect.y - dy - (1 - sy) * parseFloat(to.slice(to.indexOf(" ") + 1));
@@ -438,12 +392,12 @@ function getBoundingRectNoTransforms(el) {
438
392
  return rect;
439
393
  }
440
394
  }
395
+
441
396
  /**
442
397
  * Gets the absolute bounding rect (accounts for the window's scroll position and removes transforms)
443
398
  * @param {HTMLElement} el
444
399
  * @return {{top: number, left: number, bottom: number, right: number}}
445
400
  */
446
-
447
401
  function getAbsoluteRectNoTransforms(el) {
448
402
  var rect = getBoundingRectNoTransforms(el);
449
403
  return {
@@ -453,12 +407,12 @@ function getAbsoluteRectNoTransforms(el) {
453
407
  right: rect.right + window.scrollX
454
408
  };
455
409
  }
410
+
456
411
  /**
457
412
  * Gets the absolute bounding rect (accounts for the window's scroll position)
458
413
  * @param {HTMLElement} el
459
414
  * @return {{top: number, left: number, bottom: number, right: number}}
460
415
  */
461
-
462
416
  function getAbsoluteRect(el) {
463
417
  var rect = el.getBoundingClientRect();
464
418
  return {
@@ -468,6 +422,7 @@ function getAbsoluteRect(el) {
468
422
  right: rect.right + window.scrollX
469
423
  };
470
424
  }
425
+
471
426
  /**
472
427
  * finds the center :)
473
428
  * @typedef {Object} Rect
@@ -478,13 +433,13 @@ function getAbsoluteRect(el) {
478
433
  * @param {Rect} rect
479
434
  * @return {{x: number, y: number}}
480
435
  */
481
-
482
436
  function findCenter(rect) {
483
437
  return {
484
438
  x: (rect.left + rect.right) / 2,
485
439
  y: (rect.top + rect.bottom) / 2
486
440
  };
487
441
  }
442
+
488
443
  /**
489
444
  * @typedef {Object} Point
490
445
  * @property {number} x
@@ -493,74 +448,70 @@ function findCenter(rect) {
493
448
  * @param {Point} pointB
494
449
  * @return {number}
495
450
  */
496
-
497
451
  function calcDistance(pointA, pointB) {
498
452
  return Math.sqrt(Math.pow(pointA.x - pointB.x, 2) + Math.pow(pointA.y - pointB.y, 2));
499
453
  }
454
+
500
455
  /**
501
456
  * @param {Point} point
502
457
  * @param {Rect} rect
503
458
  * @return {boolean|boolean}
504
459
  */
505
-
506
-
507
460
  function isPointInsideRect(point, rect) {
508
461
  return point.y <= rect.bottom && point.y >= rect.top && point.x >= rect.left && point.x <= rect.right;
509
462
  }
463
+
510
464
  /**
511
465
  * find the absolute coordinates of the center of a dom element
512
466
  * @param el {HTMLElement}
513
467
  * @returns {{x: number, y: number}}
514
468
  */
515
-
516
469
  function findCenterOfElement(el) {
517
470
  return findCenter(getAbsoluteRect(el));
518
471
  }
472
+
519
473
  /**
520
474
  * @param {HTMLElement} elA
521
475
  * @param {HTMLElement} elB
522
476
  * @return {boolean}
523
477
  */
524
-
525
478
  function isCenterOfAInsideB(elA, elB) {
526
479
  var centerOfA = findCenterOfElement(elA);
527
480
  var rectOfB = getAbsoluteRectNoTransforms(elB);
528
481
  return isPointInsideRect(centerOfA, rectOfB);
529
482
  }
483
+
530
484
  /**
531
485
  * @param {HTMLElement|ChildNode} elA
532
486
  * @param {HTMLElement|ChildNode} elB
533
487
  * @return {number}
534
488
  */
535
-
536
489
  function calcDistanceBetweenCenters(elA, elB) {
537
490
  var centerOfA = findCenterOfElement(elA);
538
491
  var centerOfB = findCenterOfElement(elB);
539
492
  return calcDistance(centerOfA, centerOfB);
540
493
  }
494
+
541
495
  /**
542
496
  * @param {HTMLElement} el - the element to check
543
497
  * @returns {boolean} - true if the element in its entirety is off screen including the scrollable area (the normal dom events look at the mouse rather than the element)
544
498
  */
545
-
546
499
  function isElementOffDocument(el) {
547
500
  var rect = getAbsoluteRect(el);
548
501
  return rect.right < 0 || rect.left > document.documentElement.scrollWidth || rect.bottom < 0 || rect.top > document.documentElement.scrollHeight;
549
502
  }
503
+
550
504
  /**
551
505
  * If the point is inside the element returns its distances from the sides, otherwise returns null
552
506
  * @param {Point} point
553
507
  * @param {HTMLElement} el
554
508
  * @return {null|{top: number, left: number, bottom: number, right: number}}
555
509
  */
556
-
557
510
  function calcInnerDistancesBetweenPointAndSidesOfElement(point, el) {
558
511
  var rect = getAbsoluteRect(el);
559
-
560
512
  if (!isPointInsideRect(point, rect)) {
561
513
  return null;
562
514
  }
563
-
564
515
  return {
565
516
  top: point.y - rect.top,
566
517
  bottom: rect.bottom - point.y,
@@ -571,10 +522,10 @@ function calcInnerDistancesBetweenPointAndSidesOfElement(point, el) {
571
522
  }
572
523
 
573
524
  var dzToShadowIndexToRect;
525
+
574
526
  /**
575
527
  * Resets the cache that allows for smarter "would be index" resolution. Should be called after every drag operation
576
528
  */
577
-
578
529
  function resetIndexesCache() {
579
530
  printDebug(function () {
580
531
  return "resetting indexes cache";
@@ -582,75 +533,68 @@ function resetIndexesCache() {
582
533
  dzToShadowIndexToRect = new Map();
583
534
  }
584
535
  resetIndexesCache();
536
+
585
537
  /**
586
538
  * Resets the cache that allows for smarter "would be index" resolution for a specific dropzone, should be called after the zone was scrolled
587
539
  * @param {HTMLElement} dz
588
540
  */
589
-
590
541
  function resetIndexesCacheForDz(dz) {
591
542
  printDebug(function () {
592
543
  return "resetting indexes cache for dz";
593
544
  });
594
545
  dzToShadowIndexToRect["delete"](dz);
595
546
  }
547
+
596
548
  /**
597
549
  * Caches the coordinates of the shadow element when it's in a certain index in a certain dropzone.
598
550
  * Helpful in order to determine "would be index" more effectively
599
551
  * @param {HTMLElement} dz
600
552
  * @return {number} - the shadow element index
601
553
  */
602
-
603
554
  function cacheShadowRect(dz) {
604
555
  var shadowElIndex = Array.from(dz.children).findIndex(function (child) {
605
556
  return child.getAttribute(SHADOW_ELEMENT_ATTRIBUTE_NAME);
606
557
  });
607
-
608
558
  if (shadowElIndex >= 0) {
609
559
  if (!dzToShadowIndexToRect.has(dz)) {
610
560
  dzToShadowIndexToRect.set(dz, new Map());
611
561
  }
612
-
613
562
  dzToShadowIndexToRect.get(dz).set(shadowElIndex, getAbsoluteRectNoTransforms(dz.children[shadowElIndex]));
614
563
  return shadowElIndex;
615
564
  }
616
-
617
565
  return undefined;
618
566
  }
567
+
619
568
  /**
620
569
  * @typedef {Object} Index
621
570
  * @property {number} index - the would be index
622
571
  * @property {boolean} isProximityBased - false if the element is actually over the index, true if it is not over it but this index is the closest
623
572
  */
624
-
625
573
  /**
626
574
  * Find the index for the dragged element in the list it is dragged over
627
575
  * @param {HTMLElement} floatingAboveEl
628
576
  * @param {HTMLElement} collectionBelowEl
629
577
  * @returns {Index|null} - if the element is over the container the Index object otherwise null
630
578
  */
631
-
632
-
633
579
  function findWouldBeIndex(floatingAboveEl, collectionBelowEl) {
634
580
  if (!isCenterOfAInsideB(floatingAboveEl, collectionBelowEl)) {
635
581
  return null;
636
582
  }
637
-
638
- var children = collectionBelowEl.children; // the container is empty, floating element should be the first
639
-
583
+ var children = collectionBelowEl.children;
584
+ // the container is empty, floating element should be the first
640
585
  if (children.length === 0) {
641
586
  return {
642
587
  index: 0,
643
588
  isProximityBased: true
644
589
  };
645
590
  }
591
+ var shadowElIndex = cacheShadowRect(collectionBelowEl);
646
592
 
647
- var shadowElIndex = cacheShadowRect(collectionBelowEl); // the search could be more efficient but keeping it simple for now
593
+ // the search could be more efficient but keeping it simple for now
648
594
  // a possible improvement: pass in the lastIndex it was found in and check there first, then expand from there
649
-
650
595
  for (var i = 0; i < children.length; i++) {
651
596
  if (isCenterOfAInsideB(floatingAboveEl, children[i])) {
652
597
  var cachedShadowRect = dzToShadowIndexToRect.has(collectionBelowEl) && dzToShadowIndexToRect.get(collectionBelowEl).get(i);
653
-
654
598
  if (cachedShadowRect) {
655
599
  if (!isPointInsideRect(findCenterOfElement(floatingAboveEl), cachedShadowRect)) {
656
600
  return {
@@ -659,28 +603,24 @@ function findWouldBeIndex(floatingAboveEl, collectionBelowEl) {
659
603
  };
660
604
  }
661
605
  }
662
-
663
606
  return {
664
607
  index: i,
665
608
  isProximityBased: false
666
609
  };
667
610
  }
668
- } // this can happen if there is space around the children so the floating element has
611
+ }
612
+ // this can happen if there is space around the children so the floating element has
669
613
  //entered the container but not any of the children, in this case we will find the nearest child
670
-
671
-
672
614
  var minDistanceSoFar = Number.MAX_VALUE;
673
- var indexOfMin = undefined; // we are checking all of them because we don't know whether we are dealing with a horizontal or vertical container and where the floating element entered from
674
-
615
+ var indexOfMin = undefined;
616
+ // we are checking all of them because we don't know whether we are dealing with a horizontal or vertical container and where the floating element entered from
675
617
  for (var _i = 0; _i < children.length; _i++) {
676
618
  var distance = calcDistanceBetweenCenters(floatingAboveEl, children[_i]);
677
-
678
619
  if (distance < minDistanceSoFar) {
679
620
  minDistanceSoFar = distance;
680
621
  indexOfMin = _i;
681
622
  }
682
623
  }
683
-
684
624
  return {
685
625
  index: indexOfMin,
686
626
  isProximityBased: true
@@ -690,21 +630,18 @@ function findWouldBeIndex(floatingAboveEl, collectionBelowEl) {
690
630
  var SCROLL_ZONE_PX = 25;
691
631
  function makeScroller() {
692
632
  var scrollingInfo;
693
-
694
633
  function resetScrolling() {
695
634
  scrollingInfo = {
696
635
  directionObj: undefined,
697
636
  stepPx: 0
698
637
  };
699
638
  }
700
-
701
- resetScrolling(); // directionObj {x: 0|1|-1, y:0|1|-1} - 1 means down in y and right in x
702
-
639
+ resetScrolling();
640
+ // directionObj {x: 0|1|-1, y:0|1|-1} - 1 means down in y and right in x
703
641
  function scrollContainer(containerEl) {
704
642
  var _scrollingInfo = scrollingInfo,
705
- directionObj = _scrollingInfo.directionObj,
706
- stepPx = _scrollingInfo.stepPx;
707
-
643
+ directionObj = _scrollingInfo.directionObj,
644
+ stepPx = _scrollingInfo.stepPx;
708
645
  if (directionObj) {
709
646
  containerEl.scrollBy(directionObj.x * stepPx, directionObj.y * stepPx);
710
647
  window.requestAnimationFrame(function () {
@@ -712,33 +649,28 @@ function makeScroller() {
712
649
  });
713
650
  }
714
651
  }
715
-
716
652
  function calcScrollStepPx(distancePx) {
717
653
  return SCROLL_ZONE_PX - distancePx;
718
654
  }
655
+
719
656
  /**
720
657
  * If the pointer is next to the sides of the element to scroll, will trigger scrolling
721
658
  * Can be called repeatedly with updated pointer and elementToScroll values without issues
722
659
  * @return {boolean} - true if scrolling was needed
723
660
  */
724
-
725
-
726
661
  function scrollIfNeeded(pointer, elementToScroll) {
727
662
  if (!elementToScroll) {
728
663
  return false;
729
664
  }
730
-
731
665
  var distances = calcInnerDistancesBetweenPointAndSidesOfElement(pointer, elementToScroll);
732
-
733
666
  if (distances === null) {
734
667
  resetScrolling();
735
668
  return false;
736
669
  }
737
-
738
670
  var isAlreadyScrolling = !!scrollingInfo.directionObj;
739
671
  var scrollingVertically = false,
740
- scrollingHorizontally = false; // vertical
741
-
672
+ scrollingHorizontally = false;
673
+ // vertical
742
674
  if (elementToScroll.scrollHeight > elementToScroll.clientHeight) {
743
675
  if (distances.bottom < SCROLL_ZONE_PX) {
744
676
  scrollingVertically = true;
@@ -755,14 +687,12 @@ function makeScroller() {
755
687
  };
756
688
  scrollingInfo.stepPx = calcScrollStepPx(distances.top);
757
689
  }
758
-
759
690
  if (!isAlreadyScrolling && scrollingVertically) {
760
691
  scrollContainer(elementToScroll);
761
692
  return true;
762
693
  }
763
- } // horizontal
764
-
765
-
694
+ }
695
+ // horizontal
766
696
  if (elementToScroll.scrollWidth > elementToScroll.clientWidth) {
767
697
  if (distances.right < SCROLL_ZONE_PX) {
768
698
  scrollingHorizontally = true;
@@ -779,17 +709,14 @@ function makeScroller() {
779
709
  };
780
710
  scrollingInfo.stepPx = calcScrollStepPx(distances.left);
781
711
  }
782
-
783
712
  if (!isAlreadyScrolling && scrollingHorizontally) {
784
713
  scrollContainer(elementToScroll);
785
714
  return true;
786
715
  }
787
716
  }
788
-
789
717
  resetScrolling();
790
718
  return false;
791
719
  }
792
-
793
720
  return {
794
721
  scrollIfNeeded: scrollIfNeeded,
795
722
  resetScrolling: resetScrolling
@@ -803,110 +730,98 @@ function makeScroller() {
803
730
  function toString(object) {
804
731
  return JSON.stringify(object, null, 2);
805
732
  }
733
+
806
734
  /**
807
735
  * Finds the depth of the given node in the DOM tree
808
736
  * @param {HTMLElement} node
809
737
  * @return {number} - the depth of the node
810
738
  */
811
-
812
739
  function getDepth(node) {
813
740
  if (!node) {
814
741
  throw new Error("cannot get depth of a falsy node");
815
742
  }
816
-
817
743
  return _getDepth(node, 0);
818
744
  }
819
-
820
745
  function _getDepth(node) {
821
746
  var countSoFar = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 0;
822
-
823
747
  if (!node.parentElement) {
824
748
  return countSoFar - 1;
825
749
  }
826
-
827
750
  return _getDepth(node.parentElement, countSoFar + 1);
828
751
  }
752
+
829
753
  /**
830
754
  * A simple util to shallow compare objects quickly, it doesn't validate the arguments so pass objects in
831
755
  * @param {Object} objA
832
756
  * @param {Object} objB
833
757
  * @return {boolean} - true if objA and objB are shallow equal
834
758
  */
835
-
836
-
837
759
  function areObjectsShallowEqual(objA, objB) {
838
760
  if (Object.keys(objA).length !== Object.keys(objB).length) {
839
761
  return false;
840
762
  }
841
-
842
763
  for (var keyA in objA) {
843
764
  if (!{}.hasOwnProperty.call(objB, keyA) || objB[keyA] !== objA[keyA]) {
844
765
  return false;
845
766
  }
846
767
  }
847
-
848
768
  return true;
849
769
  }
770
+
850
771
  /**
851
772
  * Shallow compares two arrays
852
773
  * @param arrA
853
774
  * @param arrB
854
775
  * @return {boolean} - whether the arrays are shallow equal
855
776
  */
856
-
857
777
  function areArraysShallowEqualSameOrder(arrA, arrB) {
858
778
  if (arrA.length !== arrB.length) {
859
779
  return false;
860
780
  }
861
-
862
781
  for (var i = 0; i < arrA.length; i++) {
863
782
  if (arrA[i] !== arrB[i]) {
864
783
  return false;
865
784
  }
866
785
  }
867
-
868
786
  return true;
869
787
  }
870
788
 
871
789
  var INTERVAL_MS = 200;
872
790
  var TOLERANCE_PX = 10;
873
-
874
791
  var _makeScroller = makeScroller(),
875
- scrollIfNeeded = _makeScroller.scrollIfNeeded,
876
- resetScrolling = _makeScroller.resetScrolling;
877
-
792
+ scrollIfNeeded = _makeScroller.scrollIfNeeded,
793
+ resetScrolling = _makeScroller.resetScrolling;
878
794
  var next;
795
+
879
796
  /**
880
797
  * Tracks the dragged elements and performs the side effects when it is dragged over a drop zone (basically dispatching custom-events scrolling)
881
798
  * @param {Set<HTMLElement>} dropZones
882
799
  * @param {HTMLElement} draggedEl
883
800
  * @param {number} [intervalMs = INTERVAL_MS]
884
801
  */
885
-
886
802
  function observe(draggedEl, dropZones) {
887
803
  var intervalMs = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : INTERVAL_MS;
888
804
  // initialization
889
805
  var lastDropZoneFound;
890
806
  var lastIndexFound;
891
807
  var lastIsDraggedInADropZone = false;
892
- var lastCentrePositionOfDragged; // We are sorting to make sure that in case of nested zones of the same type the one "on top" is considered first
893
-
808
+ var lastCentrePositionOfDragged;
809
+ // We are sorting to make sure that in case of nested zones of the same type the one "on top" is considered first
894
810
  var dropZonesFromDeepToShallow = Array.from(dropZones).sort(function (dz1, dz2) {
895
811
  return getDepth(dz2) - getDepth(dz1);
896
812
  });
813
+
897
814
  /**
898
815
  * The main function in this module. Tracks where everything is/ should be a take the actions
899
816
  */
900
-
901
817
  function andNow() {
902
818
  var currentCenterOfDragged = findCenterOfElement(draggedEl);
903
- var scrolled = scrollIfNeeded(currentCenterOfDragged, lastDropZoneFound); // we only want to make a new decision after the element was moved a bit to prevent flickering
904
-
819
+ var scrolled = scrollIfNeeded(currentCenterOfDragged, lastDropZoneFound);
820
+ // we only want to make a new decision after the element was moved a bit to prevent flickering
905
821
  if (!scrolled && lastCentrePositionOfDragged && Math.abs(lastCentrePositionOfDragged.x - currentCenterOfDragged.x) < TOLERANCE_PX && Math.abs(lastCentrePositionOfDragged.y - currentCenterOfDragged.y) < TOLERANCE_PX) {
906
822
  next = window.setTimeout(andNow, intervalMs);
907
823
  return;
908
824
  }
909
-
910
825
  if (isElementOffDocument(draggedEl)) {
911
826
  printDebug(function () {
912
827
  return "off document";
@@ -914,28 +829,23 @@ function observe(draggedEl, dropZones) {
914
829
  dispatchDraggedLeftDocument(draggedEl);
915
830
  return;
916
831
  }
917
-
918
- lastCentrePositionOfDragged = currentCenterOfDragged; // this is a simple algorithm, potential improvement: first look at lastDropZoneFound
919
-
832
+ lastCentrePositionOfDragged = currentCenterOfDragged;
833
+ // this is a simple algorithm, potential improvement: first look at lastDropZoneFound
920
834
  var isDraggedInADropZone = false;
921
-
922
835
  var _iterator = _createForOfIteratorHelper(dropZonesFromDeepToShallow),
923
- _step;
924
-
836
+ _step;
925
837
  try {
926
838
  for (_iterator.s(); !(_step = _iterator.n()).done;) {
927
839
  var dz = _step.value;
928
840
  if (scrolled) resetIndexesCacheForDz(lastDropZoneFound);
929
841
  var indexObj = findWouldBeIndex(draggedEl, dz);
930
-
931
842
  if (indexObj === null) {
932
843
  // it is not inside
933
844
  continue;
934
845
  }
935
-
936
846
  var index = indexObj.index;
937
- isDraggedInADropZone = true; // the element is over a container
938
-
847
+ isDraggedInADropZone = true;
848
+ // the element is over a container
939
849
  if (dz !== lastDropZoneFound) {
940
850
  lastDropZoneFound && dispatchDraggedElementLeftContainerForAnother(lastDropZoneFound, draggedEl, dz);
941
851
  dispatchDraggedElementEnteredContainer(dz, indexObj, draggedEl);
@@ -943,18 +853,16 @@ function observe(draggedEl, dropZones) {
943
853
  } else if (index !== lastIndexFound) {
944
854
  dispatchDraggedElementIsOverIndex(dz, indexObj, draggedEl);
945
855
  lastIndexFound = index;
946
- } // we handle looping with the 'continue' statement above
947
-
948
-
856
+ }
857
+ // we handle looping with the 'continue' statement above
949
858
  break;
950
- } // the first time the dragged element is not in any dropzone we need to notify the last dropzone it was in
951
-
859
+ }
860
+ // the first time the dragged element is not in any dropzone we need to notify the last dropzone it was in
952
861
  } catch (err) {
953
862
  _iterator.e(err);
954
863
  } finally {
955
864
  _iterator.f();
956
865
  }
957
-
958
866
  if (!isDraggedInADropZone && lastIsDraggedInADropZone && lastDropZoneFound) {
959
867
  dispatchDraggedElementLeftContainerForNone(lastDropZoneFound, draggedEl);
960
868
  lastDropZoneFound = undefined;
@@ -963,13 +871,12 @@ function observe(draggedEl, dropZones) {
963
871
  } else {
964
872
  lastIsDraggedInADropZone = true;
965
873
  }
966
-
967
874
  next = window.setTimeout(andNow, intervalMs);
968
875
  }
969
-
970
876
  andNow();
971
- } // assumption - we can only observe one dragged element at a time, this could be changed in the future
877
+ }
972
878
 
879
+ // assumption - we can only observe one dragged element at a time, this could be changed in the future
973
880
  function unobserve() {
974
881
  printDebug(function () {
975
882
  return "unobserving";
@@ -981,12 +888,12 @@ function unobserve() {
981
888
 
982
889
  var INTERVAL_MS$1 = 300;
983
890
  var mousePosition;
891
+
984
892
  /**
985
893
  * Do not use this! it is visible for testing only until we get over the issue Cypress not triggering the mousemove listeners
986
894
  * // TODO - make private (remove export)
987
895
  * @param {{clientX: number, clientY: number}} e
988
896
  */
989
-
990
897
  function updateMousePosition(e) {
991
898
  var c = e.touches ? e.touches[0] : e;
992
899
  mousePosition = {
@@ -994,26 +901,21 @@ function updateMousePosition(e) {
994
901
  y: c.clientY
995
902
  };
996
903
  }
997
-
998
904
  var _makeScroller$1 = makeScroller(),
999
- scrollIfNeeded$1 = _makeScroller$1.scrollIfNeeded,
1000
- resetScrolling$1 = _makeScroller$1.resetScrolling;
1001
-
905
+ scrollIfNeeded$1 = _makeScroller$1.scrollIfNeeded,
906
+ resetScrolling$1 = _makeScroller$1.resetScrolling;
1002
907
  var next$1;
1003
-
1004
908
  function loop() {
1005
909
  if (mousePosition) {
1006
910
  var scrolled = scrollIfNeeded$1(mousePosition, document.documentElement);
1007
911
  if (scrolled) resetIndexesCache();
1008
912
  }
1009
-
1010
913
  next$1 = window.setTimeout(loop, INTERVAL_MS$1);
1011
914
  }
915
+
1012
916
  /**
1013
917
  * will start watching the mouse pointer and scroll the window if it goes next to the edges
1014
918
  */
1015
-
1016
-
1017
919
  function armWindowScroller() {
1018
920
  printDebug(function () {
1019
921
  return "arming window scroller";
@@ -1022,10 +924,10 @@ function armWindowScroller() {
1022
924
  window.addEventListener("touchmove", updateMousePosition);
1023
925
  loop();
1024
926
  }
927
+
1025
928
  /**
1026
929
  * will stop watching the mouse pointer and won't scroll the window anymore
1027
930
  */
1028
-
1029
931
  function disarmWindowScroller() {
1030
932
  printDebug(function () {
1031
933
  return "disarming window scroller";
@@ -1051,10 +953,8 @@ function svelteNodeClone(el) {
1051
953
  var values = [];
1052
954
  var elIsSelect = el.tagName === "SELECT";
1053
955
  var selects = elIsSelect ? [el] : _toConsumableArray(el.querySelectorAll('select'));
1054
-
1055
956
  var _iterator = _createForOfIteratorHelper(selects),
1056
- _step;
1057
-
957
+ _step;
1058
958
  try {
1059
959
  for (_iterator.s(); !(_step = _iterator.n()).done;) {
1060
960
  var _select = _step.value;
@@ -1065,33 +965,28 @@ function svelteNodeClone(el) {
1065
965
  } finally {
1066
966
  _iterator.f();
1067
967
  }
1068
-
1069
968
  if (selects.length <= 0) {
1070
969
  return cloned;
1071
970
  }
1072
-
1073
971
  var clonedSelects = elIsSelect ? [cloned] : _toConsumableArray(cloned.querySelectorAll('select'));
1074
-
1075
972
  for (var i = 0; i < clonedSelects.length; i++) {
1076
973
  var select = clonedSelects[i];
1077
974
  var value = values[i];
1078
975
  var optionEl = select.querySelector("option[value=\"".concat(value, "\""));
1079
-
1080
976
  if (optionEl) {
1081
977
  optionEl.setAttribute('selected', true);
1082
978
  }
1083
979
  }
1084
-
1085
980
  return cloned;
1086
981
  }
1087
982
 
1088
983
  var TRANSITION_DURATION_SECONDS = 0.2;
984
+
1089
985
  /**
1090
986
  * private helper function - creates a transition string for a property
1091
987
  * @param {string} property
1092
988
  * @return {string} - the transition string
1093
989
  */
1094
-
1095
990
  function trs(property) {
1096
991
  return "".concat(property, " ").concat(TRANSITION_DURATION_SECONDS, "s ease");
1097
992
  }
@@ -1101,8 +996,6 @@ function trs(property) {
1101
996
  * @param {Point} [positionCenterOnXY]
1102
997
  * @return {Node} - the cloned, styled element
1103
998
  */
1104
-
1105
-
1106
999
  function createDraggedElementFrom(originalElement, positionCenterOnXY) {
1107
1000
  var rect = originalElement.getBoundingClientRect();
1108
1001
  var draggedEl = svelteNodeClone(originalElement);
@@ -1113,7 +1006,6 @@ function createDraggedElementFrom(originalElement, positionCenterOnXY) {
1113
1006
  var elLeftPx = rect.left;
1114
1007
  draggedEl.style.top = "".concat(elTopPx, "px");
1115
1008
  draggedEl.style.left = "".concat(elLeftPx, "px");
1116
-
1117
1009
  if (positionCenterOnXY) {
1118
1010
  var center = findCenter(rect);
1119
1011
  elTopPx -= center.y - positionCenterOnXY.y;
@@ -1123,14 +1015,13 @@ function createDraggedElementFrom(originalElement, positionCenterOnXY) {
1123
1015
  draggedEl.style.left = "".concat(elLeftPx, "px");
1124
1016
  }, 0);
1125
1017
  }
1126
-
1127
- draggedEl.style.margin = "0"; // we can't have relative or automatic height and width or it will break the illusion
1128
-
1018
+ draggedEl.style.margin = "0";
1019
+ // we can't have relative or automatic height and width or it will break the illusion
1129
1020
  draggedEl.style.boxSizing = "border-box";
1130
1021
  draggedEl.style.height = "".concat(rect.height, "px");
1131
1022
  draggedEl.style.width = "".concat(rect.width, "px");
1132
- draggedEl.style.transition = "".concat(trs("top"), ", ").concat(trs("left"), ", ").concat(trs("background-color"), ", ").concat(trs("opacity"), ", ").concat(trs("color"), " "); // this is a workaround for a strange browser bug that causes the right border to disappear when all the transitions are added at the same time
1133
-
1023
+ draggedEl.style.transition = "".concat(trs("top"), ", ").concat(trs("left"), ", ").concat(trs("background-color"), ", ").concat(trs("opacity"), ", ").concat(trs("color"), " ");
1024
+ // this is a workaround for a strange browser bug that causes the right border to disappear when all the transitions are added at the same time
1134
1025
  window.setTimeout(function () {
1135
1026
  return draggedEl.style.transition += ", ".concat(trs("width"), ", ").concat(trs("height"));
1136
1027
  }, 0);
@@ -1138,29 +1029,28 @@ function createDraggedElementFrom(originalElement, positionCenterOnXY) {
1138
1029
  draggedEl.style.cursor = "grabbing";
1139
1030
  return draggedEl;
1140
1031
  }
1032
+
1141
1033
  /**
1142
1034
  * styles the dragged element to a 'dropped' state
1143
1035
  * @param {HTMLElement} draggedEl
1144
1036
  */
1145
-
1146
1037
  function moveDraggedElementToWasDroppedState(draggedEl) {
1147
1038
  draggedEl.style.cursor = "grab";
1148
1039
  }
1040
+
1149
1041
  /**
1150
1042
  * Morphs the dragged element style, maintains the mouse pointer within the element
1151
1043
  * @param {HTMLElement} draggedEl
1152
1044
  * @param {HTMLElement} copyFromEl - the element the dragged element should look like, typically the shadow element
1153
1045
  * @param {number} currentMouseX
1154
1046
  * @param {number} currentMouseY
1155
- * @param {function} transformDraggedElement - function to transform the dragged element, does nothing by default.
1156
1047
  */
1157
-
1158
- function morphDraggedElementToBeLike(draggedEl, copyFromEl, currentMouseX, currentMouseY, transformDraggedElement) {
1048
+ function morphDraggedElementToBeLike(draggedEl, copyFromEl, currentMouseX, currentMouseY) {
1049
+ copyStylesFromTo(copyFromEl, draggedEl);
1159
1050
  var newRect = copyFromEl.getBoundingClientRect();
1160
1051
  var draggedElRect = draggedEl.getBoundingClientRect();
1161
1052
  var widthChange = newRect.width - draggedElRect.width;
1162
1053
  var heightChange = newRect.height - draggedElRect.height;
1163
-
1164
1054
  if (widthChange || heightChange) {
1165
1055
  var relativeDistanceOfMousePointerFromDraggedSides = {
1166
1056
  left: (currentMouseX - draggedElRect.left) / draggedElRect.width,
@@ -1170,17 +1060,13 @@ function morphDraggedElementToBeLike(draggedEl, copyFromEl, currentMouseX, curre
1170
1060
  draggedEl.style.width = "".concat(newRect.width, "px");
1171
1061
  draggedEl.style.left = "".concat(parseFloat(draggedEl.style.left) - relativeDistanceOfMousePointerFromDraggedSides.left * widthChange, "px");
1172
1062
  draggedEl.style.top = "".concat(parseFloat(draggedEl.style.top) - relativeDistanceOfMousePointerFromDraggedSides.top * heightChange, "px");
1173
- } /// other properties
1174
-
1175
-
1176
- copyStylesFromTo(copyFromEl, draggedEl);
1177
- transformDraggedElement();
1063
+ }
1178
1064
  }
1065
+
1179
1066
  /**
1180
1067
  * @param {HTMLElement} copyFromEl
1181
1068
  * @param {HTMLElement} copyToEl
1182
1069
  */
1183
-
1184
1070
  function copyStylesFromTo(copyFromEl, copyToEl) {
1185
1071
  var computedStyle = window.getComputedStyle(copyFromEl);
1186
1072
  Array.from(computedStyle).filter(function (s) {
@@ -1189,20 +1075,17 @@ function copyStylesFromTo(copyFromEl, copyToEl) {
1189
1075
  return copyToEl.style.setProperty(s, computedStyle.getPropertyValue(s), computedStyle.getPropertyPriority(s));
1190
1076
  });
1191
1077
  }
1078
+
1192
1079
  /**
1193
1080
  * makes the element compatible with being draggable
1194
1081
  * @param {HTMLElement} draggableEl
1195
1082
  * @param {boolean} dragDisabled
1196
1083
  */
1197
-
1198
-
1199
1084
  function styleDraggable(draggableEl, dragDisabled) {
1200
1085
  draggableEl.draggable = false;
1201
-
1202
1086
  draggableEl.ondragstart = function () {
1203
1087
  return false;
1204
1088
  };
1205
-
1206
1089
  if (!dragDisabled) {
1207
1090
  draggableEl.style.userSelect = "none";
1208
1091
  draggableEl.style.WebkitUserSelect = "none";
@@ -1213,41 +1096,41 @@ function styleDraggable(draggableEl, dragDisabled) {
1213
1096
  draggableEl.style.cursor = "";
1214
1097
  }
1215
1098
  }
1099
+
1216
1100
  /**
1217
1101
  * Hides the provided element so that it can stay in the dom without interrupting
1218
1102
  * @param {HTMLElement} dragTarget
1219
1103
  */
1220
-
1221
1104
  function hideElement(dragTarget) {
1222
1105
  dragTarget.style.display = "none";
1223
1106
  dragTarget.style.position = "fixed";
1224
1107
  dragTarget.style.zIndex = "-5";
1225
1108
  }
1109
+
1226
1110
  /**
1227
1111
  * styles the shadow element
1228
1112
  * @param {HTMLElement} shadowEl
1229
1113
  */
1230
-
1231
1114
  function decorateShadowEl(shadowEl) {
1232
1115
  shadowEl.style.visibility = "hidden";
1233
1116
  shadowEl.setAttribute(SHADOW_ELEMENT_ATTRIBUTE_NAME, "true");
1234
1117
  }
1118
+
1235
1119
  /**
1236
1120
  * undo the styles the shadow element
1237
1121
  * @param {HTMLElement} shadowEl
1238
1122
  */
1239
-
1240
1123
  function unDecorateShadowElement(shadowEl) {
1241
1124
  shadowEl.style.visibility = "";
1242
1125
  shadowEl.removeAttribute(SHADOW_ELEMENT_ATTRIBUTE_NAME);
1243
1126
  }
1127
+
1244
1128
  /**
1245
1129
  * will mark the given dropzones as visually active
1246
1130
  * @param {Array<HTMLElement>} dropZones
1247
1131
  * @param {Function} getStyles - maps a dropzone to a styles object (so the styles can be removed)
1248
1132
  * @param {Function} getClasses - maps a dropzone to a classList
1249
1133
  */
1250
-
1251
1134
  function styleActiveDropZones(dropZones) {
1252
1135
  var getStyles = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : function () {};
1253
1136
  var getClasses = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : function () {
@@ -1263,13 +1146,13 @@ function styleActiveDropZones(dropZones) {
1263
1146
  });
1264
1147
  });
1265
1148
  }
1149
+
1266
1150
  /**
1267
1151
  * will remove the 'active' styling from given dropzones
1268
1152
  * @param {Array<HTMLElement>} dropZones
1269
1153
  * @param {Function} getStyles - maps a dropzone to a styles object
1270
1154
  * @param {Function} getClasses - maps a dropzone to a classList
1271
1155
  */
1272
-
1273
1156
  function styleInactiveDropZones(dropZones) {
1274
1157
  var getStyles = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : function () {};
1275
1158
  var getClasses = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : function () {
@@ -1285,12 +1168,12 @@ function styleInactiveDropZones(dropZones) {
1285
1168
  });
1286
1169
  });
1287
1170
  }
1171
+
1288
1172
  /**
1289
1173
  * will prevent the provided element from shrinking by setting its minWidth and minHeight to the current width and height values
1290
1174
  * @param {HTMLElement} el
1291
1175
  * @return {function(): void} - run this function to undo the operation and restore the original values
1292
1176
  */
1293
-
1294
1177
  function preventShrinking(el) {
1295
1178
  var originalMinHeight = el.style.minHeight;
1296
1179
  el.style.minHeight = window.getComputedStyle(el).getPropertyValue("height");
@@ -1322,51 +1205,45 @@ var isWorkingOnPreviousDrag = false;
1322
1205
  var finalizingPreviousDrag = false;
1323
1206
  var unlockOriginDzMinDimensions;
1324
1207
  var isDraggedOutsideOfAnyDz = false;
1325
- var scheduledForRemovalAfterDrop = []; // a map from type to a set of drop-zones
1326
-
1327
- var typeToDropZones = new Map(); // important - this is needed because otherwise the config that would be used for everyone is the config of the element that created the event listeners
1328
-
1329
- var dzToConfig = new Map(); // this is needed in order to be able to cleanup old listeners and avoid stale closures issues (as the listener is defined within each zone)
1208
+ var scheduledForRemovalAfterDrop = [];
1330
1209
 
1210
+ // a map from type to a set of drop-zones
1211
+ var typeToDropZones = new Map();
1212
+ // important - this is needed because otherwise the config that would be used for everyone is the config of the element that created the event listeners
1213
+ var dzToConfig = new Map();
1214
+ // this is needed in order to be able to cleanup old listeners and avoid stale closures issues (as the listener is defined within each zone)
1331
1215
  var elToMouseDownListener = new WeakMap();
1332
- /* drop-zones registration management */
1333
1216
 
1217
+ /* drop-zones registration management */
1334
1218
  function registerDropZone(dropZoneEl, type) {
1335
1219
  printDebug(function () {
1336
1220
  return "registering drop-zone if absent";
1337
1221
  });
1338
-
1339
1222
  if (!typeToDropZones.has(type)) {
1340
1223
  typeToDropZones.set(type, new Set());
1341
1224
  }
1342
-
1343
1225
  if (!typeToDropZones.get(type).has(dropZoneEl)) {
1344
1226
  typeToDropZones.get(type).add(dropZoneEl);
1345
1227
  incrementActiveDropZoneCount();
1346
1228
  }
1347
1229
  }
1348
-
1349
1230
  function unregisterDropZone(dropZoneEl, type) {
1350
1231
  typeToDropZones.get(type)["delete"](dropZoneEl);
1351
1232
  decrementActiveDropZoneCount();
1352
-
1353
1233
  if (typeToDropZones.get(type).size === 0) {
1354
1234
  typeToDropZones["delete"](type);
1355
1235
  }
1356
1236
  }
1357
- /* functions to manage observing the dragged element and trigger custom drag-events */
1358
-
1359
1237
 
1238
+ /* functions to manage observing the dragged element and trigger custom drag-events */
1360
1239
  function watchDraggedElement() {
1361
1240
  printDebug(function () {
1362
1241
  return "watching dragged element";
1363
1242
  });
1364
1243
  armWindowScroller();
1365
1244
  var dropZones = typeToDropZones.get(draggedElType);
1366
-
1367
1245
  var _iterator = _createForOfIteratorHelper(dropZones),
1368
- _step;
1369
-
1246
+ _step;
1370
1247
  try {
1371
1248
  for (_iterator.s(); !(_step = _iterator.n()).done;) {
1372
1249
  var dz = _step.value;
@@ -1379,25 +1256,21 @@ function watchDraggedElement() {
1379
1256
  } finally {
1380
1257
  _iterator.f();
1381
1258
  }
1382
-
1383
- window.addEventListener(DRAGGED_LEFT_DOCUMENT_EVENT_NAME, handleDrop); // it is important that we don't have an interval that is faster than the flip duration because it can cause elements to jump bach and forth
1384
-
1259
+ window.addEventListener(DRAGGED_LEFT_DOCUMENT_EVENT_NAME, handleDrop);
1260
+ // it is important that we don't have an interval that is faster than the flip duration because it can cause elements to jump bach and forth
1385
1261
  var observationIntervalMs = Math.max.apply(Math, [MIN_OBSERVATION_INTERVAL_MS].concat(_toConsumableArray(Array.from(dropZones.keys()).map(function (dz) {
1386
1262
  return dzToConfig.get(dz).dropAnimationDurationMs;
1387
1263
  }))));
1388
1264
  observe(draggedEl, dropZones, observationIntervalMs * 1.07);
1389
1265
  }
1390
-
1391
1266
  function unWatchDraggedElement() {
1392
1267
  printDebug(function () {
1393
1268
  return "unwatching dragged element";
1394
1269
  });
1395
1270
  disarmWindowScroller();
1396
1271
  var dropZones = typeToDropZones.get(draggedElType);
1397
-
1398
1272
  var _iterator2 = _createForOfIteratorHelper(dropZones),
1399
- _step2;
1400
-
1273
+ _step2;
1401
1274
  try {
1402
1275
  for (_iterator2.s(); !(_step2 = _iterator2.n()).done;) {
1403
1276
  var dz = _step2.value;
@@ -1410,52 +1283,45 @@ function unWatchDraggedElement() {
1410
1283
  } finally {
1411
1284
  _iterator2.f();
1412
1285
  }
1413
-
1414
1286
  window.removeEventListener(DRAGGED_LEFT_DOCUMENT_EVENT_NAME, handleDrop);
1415
1287
  unobserve();
1416
- } // finds the initial placeholder that is placed there on drag start
1417
-
1288
+ }
1418
1289
 
1290
+ // finds the initial placeholder that is placed there on drag start
1419
1291
  function findShadowPlaceHolderIdx(items) {
1420
1292
  return items.findIndex(function (item) {
1421
1293
  return item[ITEM_ID_KEY] === SHADOW_PLACEHOLDER_ITEM_ID;
1422
1294
  });
1423
1295
  }
1424
-
1425
1296
  function findShadowElementIdx(items) {
1426
1297
  // checking that the id is not the placeholder's for Dragula like usecases
1427
1298
  return items.findIndex(function (item) {
1428
1299
  return !!item[SHADOW_ITEM_MARKER_PROPERTY_NAME] && item[ITEM_ID_KEY] !== SHADOW_PLACEHOLDER_ITEM_ID;
1429
1300
  });
1430
1301
  }
1431
- /* custom drag-events handlers */
1432
-
1433
1302
 
1303
+ /* custom drag-events handlers */
1434
1304
  function handleDraggedEntered(e) {
1435
1305
  printDebug(function () {
1436
1306
  return ["dragged entered", e.currentTarget, e.detail];
1437
1307
  });
1438
-
1439
1308
  var _dzToConfig$get = dzToConfig.get(e.currentTarget),
1440
- items = _dzToConfig$get.items,
1441
- dropFromOthersDisabled = _dzToConfig$get.dropFromOthersDisabled;
1442
-
1309
+ items = _dzToConfig$get.items,
1310
+ dropFromOthersDisabled = _dzToConfig$get.dropFromOthersDisabled;
1443
1311
  if (dropFromOthersDisabled && e.currentTarget !== originDropZone) {
1444
1312
  printDebug(function () {
1445
1313
  return "ignoring dragged entered because drop is currently disabled";
1446
1314
  });
1447
1315
  return;
1448
1316
  }
1449
-
1450
- isDraggedOutsideOfAnyDz = false; // this deals with another race condition. in rare occasions (super rapid operations) the list hasn't updated yet
1451
-
1317
+ isDraggedOutsideOfAnyDz = false;
1318
+ // this deals with another race condition. in rare occasions (super rapid operations) the list hasn't updated yet
1452
1319
  items = items.filter(function (item) {
1453
1320
  return item[ITEM_ID_KEY] !== shadowElData[ITEM_ID_KEY];
1454
1321
  });
1455
1322
  printDebug(function () {
1456
1323
  return "dragged entered items ".concat(toString(items));
1457
1324
  });
1458
-
1459
1325
  if (originDropZone !== e.currentTarget) {
1460
1326
  var originZoneItems = dzToConfig.get(originDropZone).items;
1461
1327
  var newOriginZoneItems = originZoneItems.filter(function (item) {
@@ -1468,7 +1334,6 @@ function handleDraggedEntered(e) {
1468
1334
  });
1469
1335
  } else {
1470
1336
  var shadowPlaceHolderIdx = findShadowPlaceHolderIdx(items);
1471
-
1472
1337
  if (shadowPlaceHolderIdx !== -1) {
1473
1338
  // only happens right after drag start, on the first drag entered event
1474
1339
  printDebug(function () {
@@ -1477,10 +1342,9 @@ function handleDraggedEntered(e) {
1477
1342
  items.splice(shadowPlaceHolderIdx, 1);
1478
1343
  }
1479
1344
  }
1480
-
1481
1345
  var _e$detail$indexObj = e.detail.indexObj,
1482
- index = _e$detail$indexObj.index,
1483
- isProximityBased = _e$detail$indexObj.isProximityBased;
1346
+ index = _e$detail$indexObj.index,
1347
+ isProximityBased = _e$detail$indexObj.isProximityBased;
1484
1348
  var shadowElIdx = isProximityBased && index === e.currentTarget.children.length - 1 ? index + 1 : index;
1485
1349
  shadowElDropZone = e.currentTarget;
1486
1350
  items.splice(shadowElIdx, 0, shadowElData);
@@ -1490,32 +1354,27 @@ function handleDraggedEntered(e) {
1490
1354
  source: SOURCES.POINTER
1491
1355
  });
1492
1356
  }
1493
-
1494
1357
  function handleDraggedLeft(e) {
1495
1358
  // dealing with a rare race condition on extremely rapid clicking and dropping
1496
1359
  if (!isWorkingOnPreviousDrag) return;
1497
1360
  printDebug(function () {
1498
1361
  return ["dragged left", e.currentTarget, e.detail];
1499
1362
  });
1500
-
1501
1363
  var _dzToConfig$get2 = dzToConfig.get(e.currentTarget),
1502
- items = _dzToConfig$get2.items,
1503
- dropFromOthersDisabled = _dzToConfig$get2.dropFromOthersDisabled;
1504
-
1364
+ items = _dzToConfig$get2.items,
1365
+ dropFromOthersDisabled = _dzToConfig$get2.dropFromOthersDisabled;
1505
1366
  if (dropFromOthersDisabled && e.currentTarget !== originDropZone && e.currentTarget !== shadowElDropZone) {
1506
1367
  printDebug(function () {
1507
1368
  return "drop is currently disabled";
1508
1369
  });
1509
1370
  return;
1510
1371
  }
1511
-
1512
1372
  var shadowElIdx = findShadowElementIdx(items);
1513
1373
  var shadowItem = items.splice(shadowElIdx, 1)[0];
1514
1374
  shadowElDropZone = undefined;
1515
1375
  var _e$detail = e.detail,
1516
- type = _e$detail.type,
1517
- theOtherDz = _e$detail.theOtherDz;
1518
-
1376
+ type = _e$detail.type,
1377
+ theOtherDz = _e$detail.theOtherDz;
1519
1378
  if (type === DRAGGED_LEFT_TYPES.OUTSIDE_OF_ANY || type === DRAGGED_LEFT_TYPES.LEFT_FOR_ANOTHER && theOtherDz !== originDropZone && dzToConfig.get(theOtherDz).dropFromOthersDisabled) {
1520
1379
  printDebug(function () {
1521
1380
  return "dragged left all, putting shadow element back in the origin dz";
@@ -1529,32 +1388,27 @@ function handleDraggedLeft(e) {
1529
1388
  id: draggedElData[ITEM_ID_KEY],
1530
1389
  source: SOURCES.POINTER
1531
1390
  });
1532
- } // for the origin dz, when the dragged is outside of any, this will be fired in addition to the previous. this is for simplicity
1533
-
1534
-
1391
+ }
1392
+ // for the origin dz, when the dragged is outside of any, this will be fired in addition to the previous. this is for simplicity
1535
1393
  dispatchConsiderEvent(e.currentTarget, items, {
1536
1394
  trigger: TRIGGERS.DRAGGED_LEFT,
1537
1395
  id: draggedElData[ITEM_ID_KEY],
1538
1396
  source: SOURCES.POINTER
1539
1397
  });
1540
1398
  }
1541
-
1542
1399
  function handleDraggedIsOverIndex(e) {
1543
1400
  printDebug(function () {
1544
1401
  return ["dragged is over index", e.currentTarget, e.detail];
1545
1402
  });
1546
-
1547
1403
  var _dzToConfig$get3 = dzToConfig.get(e.currentTarget),
1548
- items = _dzToConfig$get3.items,
1549
- dropFromOthersDisabled = _dzToConfig$get3.dropFromOthersDisabled;
1550
-
1404
+ items = _dzToConfig$get3.items,
1405
+ dropFromOthersDisabled = _dzToConfig$get3.dropFromOthersDisabled;
1551
1406
  if (dropFromOthersDisabled && e.currentTarget !== originDropZone) {
1552
1407
  printDebug(function () {
1553
1408
  return "drop is currently disabled";
1554
1409
  });
1555
1410
  return;
1556
1411
  }
1557
-
1558
1412
  isDraggedOutsideOfAnyDz = false;
1559
1413
  var index = e.detail.indexObj.index;
1560
1414
  var shadowElIdx = findShadowElementIdx(items);
@@ -1565,9 +1419,9 @@ function handleDraggedIsOverIndex(e) {
1565
1419
  id: draggedElData[ITEM_ID_KEY],
1566
1420
  source: SOURCES.POINTER
1567
1421
  });
1568
- } // Global mouse/touch-events handlers
1569
-
1422
+ }
1570
1423
 
1424
+ // Global mouse/touch-events handlers
1571
1425
  function handleMouseMove(e) {
1572
1426
  e.preventDefault();
1573
1427
  var c = e.touches ? e.touches[0] : e;
@@ -1577,47 +1431,41 @@ function handleMouseMove(e) {
1577
1431
  };
1578
1432
  draggedEl.style.transform = "translate3d(".concat(currentMousePosition.x - dragStartMousePosition.x, "px, ").concat(currentMousePosition.y - dragStartMousePosition.y, "px, 0)");
1579
1433
  }
1580
-
1581
1434
  function handleDrop() {
1582
1435
  printDebug(function () {
1583
1436
  return "dropped";
1584
1437
  });
1585
- finalizingPreviousDrag = true; // cleanup
1586
-
1438
+ finalizingPreviousDrag = true;
1439
+ // cleanup
1587
1440
  window.removeEventListener("mousemove", handleMouseMove);
1588
1441
  window.removeEventListener("touchmove", handleMouseMove);
1589
1442
  window.removeEventListener("mouseup", handleDrop);
1590
1443
  window.removeEventListener("touchend", handleDrop);
1591
1444
  unWatchDraggedElement();
1592
1445
  moveDraggedElementToWasDroppedState(draggedEl);
1593
-
1594
1446
  if (!shadowElDropZone) {
1595
1447
  printDebug(function () {
1596
1448
  return "element was dropped right after it left origin but before entering somewhere else";
1597
1449
  });
1598
1450
  shadowElDropZone = originDropZone;
1599
1451
  }
1600
-
1601
1452
  printDebug(function () {
1602
1453
  return ["dropped in dz", shadowElDropZone];
1603
1454
  });
1604
-
1605
1455
  var _dzToConfig$get4 = dzToConfig.get(shadowElDropZone),
1606
- items = _dzToConfig$get4.items,
1607
- type = _dzToConfig$get4.type;
1608
-
1456
+ items = _dzToConfig$get4.items,
1457
+ type = _dzToConfig$get4.type;
1609
1458
  styleInactiveDropZones(typeToDropZones.get(type), function (dz) {
1610
1459
  return dzToConfig.get(dz).dropTargetStyle;
1611
1460
  }, function (dz) {
1612
1461
  return dzToConfig.get(dz).dropTargetClasses;
1613
1462
  });
1614
- var shadowElIdx = findShadowElementIdx(items); // the handler might remove the shadow element, ex: dragula like copy on drag
1615
-
1463
+ var shadowElIdx = findShadowElementIdx(items);
1464
+ // the handler might remove the shadow element, ex: dragula like copy on drag
1616
1465
  if (shadowElIdx === -1) shadowElIdx = originIndex;
1617
1466
  items = items.map(function (item) {
1618
1467
  return item[SHADOW_ITEM_MARKER_PROPERTY_NAME] ? draggedElData : item;
1619
1468
  });
1620
-
1621
1469
  function finalizeWithinZone() {
1622
1470
  unlockOriginDzMinDimensions();
1623
1471
  dispatchFinalizeEvent(shadowElDropZone, items, {
@@ -1625,7 +1473,6 @@ function handleDrop() {
1625
1473
  id: draggedElData[ITEM_ID_KEY],
1626
1474
  source: SOURCES.POINTER
1627
1475
  });
1628
-
1629
1476
  if (shadowElDropZone !== originDropZone) {
1630
1477
  // letting the origin drop zone know the element was permanently taken away
1631
1478
  dispatchFinalizeEvent(originDropZone, dzToConfig.get(originDropZone).items, {
@@ -1634,31 +1481,26 @@ function handleDrop() {
1634
1481
  source: SOURCES.POINTER
1635
1482
  });
1636
1483
  }
1637
-
1638
1484
  unDecorateShadowElement(shadowElDropZone.children[shadowElIdx]);
1639
1485
  cleanupPostDrop();
1640
1486
  }
1641
-
1642
1487
  animateDraggedToFinalPosition(shadowElIdx, finalizeWithinZone);
1643
- } // helper function for handleDrop
1644
-
1488
+ }
1645
1489
 
1490
+ // helper function for handleDrop
1646
1491
  function animateDraggedToFinalPosition(shadowElIdx, callback) {
1647
1492
  var shadowElRect = getBoundingRectNoTransforms(shadowElDropZone.children[shadowElIdx]);
1648
1493
  var newTransform = {
1649
1494
  x: shadowElRect.left - parseFloat(draggedEl.style.left),
1650
1495
  y: shadowElRect.top - parseFloat(draggedEl.style.top)
1651
1496
  };
1652
-
1653
1497
  var _dzToConfig$get5 = dzToConfig.get(shadowElDropZone),
1654
- dropAnimationDurationMs = _dzToConfig$get5.dropAnimationDurationMs;
1655
-
1498
+ dropAnimationDurationMs = _dzToConfig$get5.dropAnimationDurationMs;
1656
1499
  var transition = "transform ".concat(dropAnimationDurationMs, "ms ease");
1657
1500
  draggedEl.style.transition = draggedEl.style.transition ? draggedEl.style.transition + "," + transition : transition;
1658
1501
  draggedEl.style.transform = "translate3d(".concat(newTransform.x, "px, ").concat(newTransform.y, "px, 0)");
1659
1502
  window.setTimeout(callback, dropAnimationDurationMs);
1660
1503
  }
1661
-
1662
1504
  function scheduleDZForRemovalAfterDrop(dz, destroy) {
1663
1505
  scheduledForRemovalAfterDrop.push({
1664
1506
  dz: dz,
@@ -1670,25 +1512,21 @@ function scheduleDZForRemovalAfterDrop(dz, destroy) {
1670
1512
  });
1671
1513
  }
1672
1514
  /* cleanup */
1673
-
1674
-
1675
1515
  function cleanupPostDrop() {
1676
1516
  draggedEl.remove();
1677
1517
  originalDragTarget.remove();
1678
-
1679
1518
  if (scheduledForRemovalAfterDrop.length) {
1680
1519
  printDebug(function () {
1681
1520
  return ["will destroy zones that were removed during drag", scheduledForRemovalAfterDrop];
1682
1521
  });
1683
1522
  scheduledForRemovalAfterDrop.forEach(function (_ref) {
1684
1523
  var dz = _ref.dz,
1685
- destroy = _ref.destroy;
1524
+ destroy = _ref.destroy;
1686
1525
  destroy();
1687
1526
  dz.remove();
1688
1527
  });
1689
1528
  scheduledForRemovalAfterDrop = [];
1690
1529
  }
1691
-
1692
1530
  draggedEl = undefined;
1693
1531
  originalDragTarget = undefined;
1694
1532
  draggedElData = undefined;
@@ -1704,7 +1542,6 @@ function cleanupPostDrop() {
1704
1542
  unlockOriginDzMinDimensions = undefined;
1705
1543
  isDraggedOutsideOfAnyDz = false;
1706
1544
  }
1707
-
1708
1545
  function dndzone(node, options) {
1709
1546
  var initialized = false;
1710
1547
  var config = {
@@ -1725,7 +1562,6 @@ function dndzone(node, options) {
1725
1562
  }];
1726
1563
  });
1727
1564
  var elToIdx = new Map();
1728
-
1729
1565
  function addMaybeListeners() {
1730
1566
  window.addEventListener("mousemove", handleMouseMoveMaybeDragStart, {
1731
1567
  passive: false
@@ -1741,21 +1577,18 @@ function dndzone(node, options) {
1741
1577
  passive: false
1742
1578
  });
1743
1579
  }
1744
-
1745
1580
  function removeMaybeListeners() {
1746
1581
  window.removeEventListener("mousemove", handleMouseMoveMaybeDragStart);
1747
1582
  window.removeEventListener("touchmove", handleMouseMoveMaybeDragStart);
1748
1583
  window.removeEventListener("mouseup", handleFalseAlarm);
1749
1584
  window.removeEventListener("touchend", handleFalseAlarm);
1750
1585
  }
1751
-
1752
1586
  function handleFalseAlarm() {
1753
1587
  removeMaybeListeners();
1754
1588
  originalDragTarget = undefined;
1755
1589
  dragStartMousePosition = undefined;
1756
1590
  currentMousePosition = undefined;
1757
1591
  }
1758
-
1759
1592
  function handleMouseMoveMaybeDragStart(e) {
1760
1593
  e.preventDefault();
1761
1594
  var c = e.touches ? e.touches[0] : e;
@@ -1763,13 +1596,11 @@ function dndzone(node, options) {
1763
1596
  x: c.clientX,
1764
1597
  y: c.clientY
1765
1598
  };
1766
-
1767
1599
  if (Math.abs(currentMousePosition.x - dragStartMousePosition.x) >= MIN_MOVEMENT_BEFORE_DRAG_START_PX || Math.abs(currentMousePosition.y - dragStartMousePosition.y) >= MIN_MOVEMENT_BEFORE_DRAG_START_PX) {
1768
1600
  removeMaybeListeners();
1769
1601
  handleDragStart();
1770
1602
  }
1771
1603
  }
1772
-
1773
1604
  function handleMouseDown(e) {
1774
1605
  // on safari clicking on a select element doesn't fire mouseup at the end of the click and in general this makes more sense
1775
1606
  if (e.target !== e.currentTarget && (e.target.value !== undefined || e.target.isContentEditable)) {
@@ -1777,23 +1608,20 @@ function dndzone(node, options) {
1777
1608
  return "won't initiate drag on a nested input element";
1778
1609
  });
1779
1610
  return;
1780
- } // prevents responding to any button but left click which equals 0 (which is falsy)
1781
-
1782
-
1611
+ }
1612
+ // prevents responding to any button but left click which equals 0 (which is falsy)
1783
1613
  if (e.button) {
1784
1614
  printDebug(function () {
1785
1615
  return "ignoring none left click button: ".concat(e.button);
1786
1616
  });
1787
1617
  return;
1788
1618
  }
1789
-
1790
1619
  if (isWorkingOnPreviousDrag) {
1791
1620
  printDebug(function () {
1792
1621
  return "cannot start a new drag before finalizing previous one";
1793
1622
  });
1794
1623
  return;
1795
1624
  }
1796
-
1797
1625
  e.stopPropagation();
1798
1626
  var c = e.touches ? e.touches[0] : e;
1799
1627
  dragStartMousePosition = {
@@ -1804,36 +1632,35 @@ function dndzone(node, options) {
1804
1632
  originalDragTarget = e.currentTarget;
1805
1633
  addMaybeListeners();
1806
1634
  }
1807
-
1808
1635
  function handleDragStart() {
1809
1636
  printDebug(function () {
1810
1637
  return ["drag start config: ".concat(toString(config)), originalDragTarget];
1811
1638
  });
1812
- isWorkingOnPreviousDrag = true; // initialising globals
1639
+ isWorkingOnPreviousDrag = true;
1813
1640
 
1641
+ // initialising globals
1814
1642
  var currentIdx = elToIdx.get(originalDragTarget);
1815
1643
  originIndex = currentIdx;
1816
1644
  originDropZone = originalDragTarget.parentElement;
1817
1645
  /** @type {ShadowRoot | HTMLDocument} */
1818
-
1819
1646
  var rootNode = originDropZone.getRootNode();
1820
1647
  var originDropZoneRoot = rootNode.body || rootNode;
1821
1648
  var items = config.items,
1822
- type = config.type,
1823
- centreDraggedOnCursor = config.centreDraggedOnCursor;
1649
+ type = config.type,
1650
+ centreDraggedOnCursor = config.centreDraggedOnCursor;
1824
1651
  draggedElData = _objectSpread2({}, items[currentIdx]);
1825
1652
  draggedElType = type;
1826
- shadowElData = _objectSpread2(_objectSpread2({}, draggedElData), {}, _defineProperty({}, SHADOW_ITEM_MARKER_PROPERTY_NAME, true)); // The initial shadow element. We need a different id at first in order to avoid conflicts and timing issues
1827
-
1828
- var placeHolderElData = _objectSpread2(_objectSpread2({}, shadowElData), {}, _defineProperty({}, ITEM_ID_KEY, SHADOW_PLACEHOLDER_ITEM_ID)); // creating the draggable element
1829
-
1830
-
1831
- draggedEl = createDraggedElementFrom(originalDragTarget, centreDraggedOnCursor && currentMousePosition); // We will keep the original dom node in the dom because touch events keep firing on it, we want to re-add it after the framework removes it
1653
+ shadowElData = _objectSpread2(_objectSpread2({}, draggedElData), {}, _defineProperty({}, SHADOW_ITEM_MARKER_PROPERTY_NAME, true));
1654
+ // The initial shadow element. We need a different id at first in order to avoid conflicts and timing issues
1655
+ var placeHolderElData = _objectSpread2(_objectSpread2({}, shadowElData), {}, _defineProperty({}, ITEM_ID_KEY, SHADOW_PLACEHOLDER_ITEM_ID));
1832
1656
 
1657
+ // creating the draggable element
1658
+ draggedEl = createDraggedElementFrom(originalDragTarget, centreDraggedOnCursor && currentMousePosition);
1659
+ // We will keep the original dom node in the dom because touch events keep firing on it, we want to re-add it after the framework removes it
1833
1660
  function keepOriginalElementInDom() {
1834
1661
  if (!draggedEl.parentElement) {
1835
- originDropZoneRoot.appendChild(draggedEl); // to prevent the outline from disappearing
1836
-
1662
+ originDropZoneRoot.appendChild(draggedEl);
1663
+ // to prevent the outline from disappearing
1837
1664
  draggedEl.focus();
1838
1665
  watchDraggedElement();
1839
1666
  hideElement(originalDragTarget);
@@ -1842,7 +1669,6 @@ function dndzone(node, options) {
1842
1669
  window.requestAnimationFrame(keepOriginalElementInDom);
1843
1670
  }
1844
1671
  }
1845
-
1846
1672
  window.requestAnimationFrame(keepOriginalElementInDom);
1847
1673
  styleActiveDropZones(Array.from(typeToDropZones.get(config.type)).filter(function (dz) {
1848
1674
  return dz === originDropZone || !dzToConfig.get(dz).dropFromOthersDisabled;
@@ -1850,16 +1676,18 @@ function dndzone(node, options) {
1850
1676
  return dzToConfig.get(dz).dropTargetStyle;
1851
1677
  }, function (dz) {
1852
1678
  return dzToConfig.get(dz).dropTargetClasses;
1853
- }); // removing the original element by removing its data entry
1679
+ });
1854
1680
 
1681
+ // removing the original element by removing its data entry
1855
1682
  items.splice(currentIdx, 1, placeHolderElData);
1856
1683
  unlockOriginDzMinDimensions = preventShrinking(originDropZone);
1857
1684
  dispatchConsiderEvent(originDropZone, items, {
1858
1685
  trigger: TRIGGERS.DRAG_STARTED,
1859
1686
  id: draggedElData[ITEM_ID_KEY],
1860
1687
  source: SOURCES.POINTER
1861
- }); // handing over to global handlers - starting to watch the element
1688
+ });
1862
1689
 
1690
+ // handing over to global handlers - starting to watch the element
1863
1691
  window.addEventListener("mousemove", handleMouseMove, {
1864
1692
  passive: false
1865
1693
  });
@@ -1874,42 +1702,40 @@ function dndzone(node, options) {
1874
1702
  passive: false
1875
1703
  });
1876
1704
  }
1877
-
1878
1705
  function configure(_ref2) {
1879
1706
  var _ref2$items = _ref2.items,
1880
- items = _ref2$items === void 0 ? undefined : _ref2$items,
1881
- _ref2$flipDurationMs = _ref2.flipDurationMs,
1882
- dropAnimationDurationMs = _ref2$flipDurationMs === void 0 ? 0 : _ref2$flipDurationMs,
1883
- _ref2$type = _ref2.type,
1884
- newType = _ref2$type === void 0 ? DEFAULT_DROP_ZONE_TYPE : _ref2$type,
1885
- _ref2$dragDisabled = _ref2.dragDisabled,
1886
- dragDisabled = _ref2$dragDisabled === void 0 ? false : _ref2$dragDisabled,
1887
- _ref2$morphDisabled = _ref2.morphDisabled,
1888
- morphDisabled = _ref2$morphDisabled === void 0 ? false : _ref2$morphDisabled,
1889
- _ref2$dropFromOthersD = _ref2.dropFromOthersDisabled,
1890
- dropFromOthersDisabled = _ref2$dropFromOthersD === void 0 ? false : _ref2$dropFromOthersD,
1891
- _ref2$dropTargetStyle = _ref2.dropTargetStyle,
1892
- dropTargetStyle = _ref2$dropTargetStyle === void 0 ? DEFAULT_DROP_TARGET_STYLE : _ref2$dropTargetStyle,
1893
- _ref2$dropTargetClass = _ref2.dropTargetClasses,
1894
- dropTargetClasses = _ref2$dropTargetClass === void 0 ? [] : _ref2$dropTargetClass,
1895
- _ref2$transformDragge = _ref2.transformDraggedElement,
1896
- transformDraggedElement = _ref2$transformDragge === void 0 ? function () {} : _ref2$transformDragge,
1897
- _ref2$centreDraggedOn = _ref2.centreDraggedOnCursor,
1898
- centreDraggedOnCursor = _ref2$centreDraggedOn === void 0 ? false : _ref2$centreDraggedOn;
1707
+ items = _ref2$items === void 0 ? undefined : _ref2$items,
1708
+ _ref2$flipDurationMs = _ref2.flipDurationMs,
1709
+ dropAnimationDurationMs = _ref2$flipDurationMs === void 0 ? 0 : _ref2$flipDurationMs,
1710
+ _ref2$type = _ref2.type,
1711
+ newType = _ref2$type === void 0 ? DEFAULT_DROP_ZONE_TYPE : _ref2$type,
1712
+ _ref2$dragDisabled = _ref2.dragDisabled,
1713
+ dragDisabled = _ref2$dragDisabled === void 0 ? false : _ref2$dragDisabled,
1714
+ _ref2$morphDisabled = _ref2.morphDisabled,
1715
+ morphDisabled = _ref2$morphDisabled === void 0 ? false : _ref2$morphDisabled,
1716
+ _ref2$dropFromOthersD = _ref2.dropFromOthersDisabled,
1717
+ dropFromOthersDisabled = _ref2$dropFromOthersD === void 0 ? false : _ref2$dropFromOthersD,
1718
+ _ref2$dropTargetStyle = _ref2.dropTargetStyle,
1719
+ dropTargetStyle = _ref2$dropTargetStyle === void 0 ? DEFAULT_DROP_TARGET_STYLE : _ref2$dropTargetStyle,
1720
+ _ref2$dropTargetClass = _ref2.dropTargetClasses,
1721
+ dropTargetClasses = _ref2$dropTargetClass === void 0 ? [] : _ref2$dropTargetClass,
1722
+ _ref2$transformDragge = _ref2.transformDraggedElement,
1723
+ transformDraggedElement = _ref2$transformDragge === void 0 ? function () {} : _ref2$transformDragge,
1724
+ _ref2$centreDraggedOn = _ref2.centreDraggedOnCursor,
1725
+ centreDraggedOnCursor = _ref2$centreDraggedOn === void 0 ? false : _ref2$centreDraggedOn;
1899
1726
  config.dropAnimationDurationMs = dropAnimationDurationMs;
1900
-
1901
1727
  if (config.type && newType !== config.type) {
1902
1728
  unregisterDropZone(node, config.type);
1903
1729
  }
1904
-
1905
1730
  config.type = newType;
1906
1731
  registerDropZone(node, newType);
1907
1732
  config.items = _toConsumableArray(items);
1908
1733
  config.dragDisabled = dragDisabled;
1909
1734
  config.morphDisabled = morphDisabled;
1910
1735
  config.transformDraggedElement = transformDraggedElement;
1911
- config.centreDraggedOnCursor = centreDraggedOnCursor; // realtime update for dropTargetStyle
1736
+ config.centreDraggedOnCursor = centreDraggedOnCursor;
1912
1737
 
1738
+ // realtime update for dropTargetStyle
1913
1739
  if (initialized && isWorkingOnPreviousDrag && !finalizingPreviousDrag && (!areObjectsShallowEqual(dropTargetStyle, config.dropTargetStyle) || !areArraysShallowEqualSameOrder(dropTargetClasses, config.dropTargetClasses))) {
1914
1740
  styleInactiveDropZones([node], function () {
1915
1741
  return config.dropTargetStyle;
@@ -1922,14 +1748,13 @@ function dndzone(node, options) {
1922
1748
  return dropTargetClasses;
1923
1749
  });
1924
1750
  }
1925
-
1926
1751
  config.dropTargetStyle = dropTargetStyle;
1927
- config.dropTargetClasses = _toConsumableArray(dropTargetClasses); // realtime update for dropFromOthersDisabled
1752
+ config.dropTargetClasses = _toConsumableArray(dropTargetClasses);
1928
1753
 
1754
+ // realtime update for dropFromOthersDisabled
1929
1755
  function getConfigProp(dz, propName) {
1930
1756
  return dzToConfig.get(dz) ? dzToConfig.get(dz)[propName] : config[propName];
1931
1757
  }
1932
-
1933
1758
  if (initialized && isWorkingOnPreviousDrag && config.dropFromOthersDisabled !== dropFromOthersDisabled) {
1934
1759
  if (dropFromOthersDisabled) {
1935
1760
  styleInactiveDropZones([node], function (dz) {
@@ -1945,50 +1770,34 @@ function dndzone(node, options) {
1945
1770
  });
1946
1771
  }
1947
1772
  }
1948
-
1949
1773
  config.dropFromOthersDisabled = dropFromOthersDisabled;
1950
1774
  dzToConfig.set(node, config);
1951
1775
  var shadowElIdx = findShadowElementIdx(config.items);
1952
-
1953
- var _loop = function _loop(idx) {
1776
+ for (var idx = 0; idx < node.children.length; idx++) {
1954
1777
  var draggableEl = node.children[idx];
1955
1778
  styleDraggable(draggableEl, dragDisabled);
1956
-
1957
1779
  if (idx === shadowElIdx) {
1780
+ config.transformDraggedElement(draggedEl, draggedElData, idx);
1958
1781
  if (!morphDisabled) {
1959
- morphDraggedElementToBeLike(draggedEl, draggableEl, currentMousePosition.x, currentMousePosition.y, function () {
1960
- return config.transformDraggedElement(draggedEl, draggedElData, idx);
1961
- });
1782
+ morphDraggedElementToBeLike(draggedEl, draggableEl, currentMousePosition.x, currentMousePosition.y);
1962
1783
  }
1963
-
1964
1784
  decorateShadowEl(draggableEl);
1965
- return "continue";
1785
+ continue;
1966
1786
  }
1967
-
1968
1787
  draggableEl.removeEventListener("mousedown", elToMouseDownListener.get(draggableEl));
1969
1788
  draggableEl.removeEventListener("touchstart", elToMouseDownListener.get(draggableEl));
1970
-
1971
1789
  if (!dragDisabled) {
1972
1790
  draggableEl.addEventListener("mousedown", handleMouseDown);
1973
1791
  draggableEl.addEventListener("touchstart", handleMouseDown);
1974
1792
  elToMouseDownListener.set(draggableEl, handleMouseDown);
1975
- } // updating the idx
1976
-
1977
-
1793
+ }
1794
+ // updating the idx
1978
1795
  elToIdx.set(draggableEl, idx);
1979
-
1980
1796
  if (!initialized) {
1981
1797
  initialized = true;
1982
1798
  }
1983
- };
1984
-
1985
- for (var idx = 0; idx < node.children.length; idx++) {
1986
- var _ret = _loop(idx);
1987
-
1988
- if (_ret === "continue") continue;
1989
1799
  }
1990
1800
  }
1991
-
1992
1801
  configure(options);
1993
1802
  return {
1994
1803
  update: function update(newOptions) {
@@ -2005,7 +1814,6 @@ function dndzone(node, options) {
2005
1814
  unregisterDropZone(node, dzToConfig.get(node).type);
2006
1815
  dzToConfig["delete"](node);
2007
1816
  }
2008
-
2009
1817
  if (isWorkingOnPreviousDrag) {
2010
1818
  printDebug(function () {
2011
1819
  return "pointer dndzone will be scheduled for destruction";
@@ -2026,20 +1834,17 @@ var INSTRUCTION_IDs = {
2026
1834
  var ID_TO_INSTRUCTION = (_ID_TO_INSTRUCTION = {}, _defineProperty(_ID_TO_INSTRUCTION, INSTRUCTION_IDs.DND_ZONE_ACTIVE, "Tab to one the items and press space-bar or enter to start dragging it"), _defineProperty(_ID_TO_INSTRUCTION, INSTRUCTION_IDs.DND_ZONE_DRAG_DISABLED, "This is a disabled drag and drop list"), _ID_TO_INSTRUCTION);
2027
1835
  var ALERT_DIV_ID = "dnd-action-aria-alert";
2028
1836
  var alertsDiv;
2029
-
2030
1837
  function initAriaOnBrowser() {
2031
1838
  if (alertsDiv) {
2032
1839
  // it is already initialized
2033
1840
  return;
2034
- } // setting the dynamic alerts
2035
-
2036
-
1841
+ }
1842
+ // setting the dynamic alerts
2037
1843
  alertsDiv = document.createElement("div");
2038
-
2039
1844
  (function initAlertsDiv() {
2040
- alertsDiv.id = ALERT_DIV_ID; // tab index -1 makes the alert be read twice on chrome for some reason
1845
+ alertsDiv.id = ALERT_DIV_ID;
1846
+ // tab index -1 makes the alert be read twice on chrome for some reason
2041
1847
  //alertsDiv.tabIndex = -1;
2042
-
2043
1848
  alertsDiv.style.position = "fixed";
2044
1849
  alertsDiv.style.bottom = "0";
2045
1850
  alertsDiv.style.left = "0";
@@ -2049,49 +1854,43 @@ function initAriaOnBrowser() {
2049
1854
  alertsDiv.style.width = "0";
2050
1855
  alertsDiv.setAttribute("role", "alert");
2051
1856
  })();
1857
+ document.body.prepend(alertsDiv);
2052
1858
 
2053
- document.body.prepend(alertsDiv); // setting the instructions
2054
-
1859
+ // setting the instructions
2055
1860
  Object.entries(ID_TO_INSTRUCTION).forEach(function (_ref) {
2056
1861
  var _ref2 = _slicedToArray(_ref, 2),
2057
- id = _ref2[0],
2058
- txt = _ref2[1];
2059
-
1862
+ id = _ref2[0],
1863
+ txt = _ref2[1];
2060
1864
  return document.body.prepend(instructionToHiddenDiv(id, txt));
2061
1865
  });
2062
1866
  }
1867
+
2063
1868
  /**
2064
1869
  * Initializes the static aria instructions so they can be attached to zones
2065
1870
  * @return {{DND_ZONE_ACTIVE: string, DND_ZONE_DRAG_DISABLED: string} | null} - the IDs for static aria instruction (to be used via aria-describedby) or null on the server
2066
1871
  */
2067
-
2068
-
2069
1872
  function initAria() {
2070
1873
  if (isOnServer) return null;
2071
-
2072
1874
  if (document.readyState === "complete") {
2073
1875
  initAriaOnBrowser();
2074
1876
  } else {
2075
1877
  window.addEventListener("DOMContentLoaded", initAriaOnBrowser);
2076
1878
  }
2077
-
2078
1879
  return _objectSpread2({}, INSTRUCTION_IDs);
2079
1880
  }
1881
+
2080
1882
  /**
2081
1883
  * Removes all the artifacts (dom elements) added by this module
2082
1884
  */
2083
-
2084
1885
  function destroyAria() {
2085
1886
  if (isOnServer || !alertsDiv) return;
2086
1887
  Object.keys(ID_TO_INSTRUCTION).forEach(function (id) {
2087
1888
  var _document$getElementB;
2088
-
2089
1889
  return (_document$getElementB = document.getElementById(id)) === null || _document$getElementB === void 0 ? void 0 : _document$getElementB.remove();
2090
1890
  });
2091
1891
  alertsDiv.remove();
2092
1892
  alertsDiv = undefined;
2093
1893
  }
2094
-
2095
1894
  function instructionToHiddenDiv(id, txt) {
2096
1895
  var div = document.createElement("div");
2097
1896
  div.id = id;
@@ -2101,23 +1900,20 @@ function instructionToHiddenDiv(id, txt) {
2101
1900
  div.style.zIndex = "-5";
2102
1901
  return div;
2103
1902
  }
1903
+
2104
1904
  /**
2105
1905
  * Will make the screen reader alert the provided text to the user
2106
1906
  * @param {string} txt
2107
1907
  */
2108
-
2109
-
2110
1908
  function alertToScreenReader(txt) {
2111
1909
  if (isOnServer) return;
2112
-
2113
1910
  if (!alertsDiv) {
2114
1911
  initAriaOnBrowser();
2115
1912
  }
2116
-
2117
1913
  alertsDiv.innerHTML = "";
2118
1914
  var alertText = document.createTextNode(txt);
2119
- alertsDiv.appendChild(alertText); // this is needed for Safari
2120
-
1915
+ alertsDiv.appendChild(alertText);
1916
+ // this is needed for Safari
2121
1917
  alertsDiv.style.display = "none";
2122
1918
  alertsDiv.style.display = "inline";
2123
1919
  }
@@ -2139,19 +1935,19 @@ var elToFocusListeners = new WeakMap();
2139
1935
  var dzToHandles = new Map();
2140
1936
  var dzToConfig$1 = new Map();
2141
1937
  var typeToDropZones$1 = new Map();
1938
+
2142
1939
  /* TODO (potentially)
2143
1940
  * what's the deal with the black border of voice-reader not following focus?
2144
1941
  * maybe keep focus on the last dragged item upon drop?
2145
1942
  */
2146
1943
 
2147
1944
  var INSTRUCTION_IDs$1;
2148
- /* drop-zones registration management */
2149
1945
 
1946
+ /* drop-zones registration management */
2150
1947
  function registerDropZone$1(dropZoneEl, type) {
2151
1948
  printDebug(function () {
2152
1949
  return "registering drop-zone if absent";
2153
1950
  });
2154
-
2155
1951
  if (typeToDropZones$1.size === 0) {
2156
1952
  printDebug(function () {
2157
1953
  return "adding global keydown and click handlers";
@@ -2160,33 +1956,26 @@ function registerDropZone$1(dropZoneEl, type) {
2160
1956
  window.addEventListener("keydown", globalKeyDownHandler);
2161
1957
  window.addEventListener("click", globalClickHandler);
2162
1958
  }
2163
-
2164
1959
  if (!typeToDropZones$1.has(type)) {
2165
1960
  typeToDropZones$1.set(type, new Set());
2166
1961
  }
2167
-
2168
1962
  if (!typeToDropZones$1.get(type).has(dropZoneEl)) {
2169
1963
  typeToDropZones$1.get(type).add(dropZoneEl);
2170
1964
  incrementActiveDropZoneCount();
2171
1965
  }
2172
1966
  }
2173
-
2174
1967
  function unregisterDropZone$1(dropZoneEl, type) {
2175
1968
  printDebug(function () {
2176
1969
  return "unregistering drop-zone";
2177
1970
  });
2178
-
2179
1971
  if (focusedDz === dropZoneEl) {
2180
1972
  handleDrop$1();
2181
1973
  }
2182
-
2183
1974
  typeToDropZones$1.get(type)["delete"](dropZoneEl);
2184
1975
  decrementActiveDropZoneCount();
2185
-
2186
1976
  if (typeToDropZones$1.get(type).size === 0) {
2187
1977
  typeToDropZones$1["delete"](type);
2188
1978
  }
2189
-
2190
1979
  if (typeToDropZones$1.size === 0) {
2191
1980
  printDebug(function () {
2192
1981
  return "removing global keydown and click handlers";
@@ -2197,10 +1986,8 @@ function unregisterDropZone$1(dropZoneEl, type) {
2197
1986
  destroyAria();
2198
1987
  }
2199
1988
  }
2200
-
2201
1989
  function globalKeyDownHandler(e) {
2202
1990
  if (!isDragging) return;
2203
-
2204
1991
  switch (e.key) {
2205
1992
  case "Escape":
2206
1993
  {
@@ -2209,10 +1996,8 @@ function globalKeyDownHandler(e) {
2209
1996
  }
2210
1997
  }
2211
1998
  }
2212
-
2213
1999
  function globalClickHandler() {
2214
2000
  if (!isDragging) return;
2215
-
2216
2001
  if (!allDragTargets.has(document.activeElement)) {
2217
2002
  printDebug(function () {
2218
2003
  return "clicked outside of any draggable";
@@ -2220,7 +2005,6 @@ function globalClickHandler() {
2220
2005
  handleDrop$1();
2221
2006
  }
2222
2007
  }
2223
-
2224
2008
  function handleZoneFocus(e) {
2225
2009
  printDebug(function () {
2226
2010
  return "zone focus";
@@ -2229,34 +2013,27 @@ function handleZoneFocus(e) {
2229
2013
  var newlyFocusedDz = e.currentTarget;
2230
2014
  if (newlyFocusedDz === focusedDz) return;
2231
2015
  focusedDzLabel = newlyFocusedDz.getAttribute("aria-label") || "";
2232
-
2233
2016
  var _dzToConfig$get = dzToConfig$1.get(focusedDz),
2234
- originItems = _dzToConfig$get.items;
2235
-
2017
+ originItems = _dzToConfig$get.items;
2236
2018
  var originItem = originItems.find(function (item) {
2237
2019
  return item[ITEM_ID_KEY] === focusedItemId;
2238
2020
  });
2239
2021
  var originIdx = originItems.indexOf(originItem);
2240
2022
  var itemToMove = originItems.splice(originIdx, 1)[0];
2241
-
2242
2023
  var _dzToConfig$get2 = dzToConfig$1.get(newlyFocusedDz),
2243
- targetItems = _dzToConfig$get2.items,
2244
- autoAriaDisabled = _dzToConfig$get2.autoAriaDisabled;
2245
-
2024
+ targetItems = _dzToConfig$get2.items,
2025
+ autoAriaDisabled = _dzToConfig$get2.autoAriaDisabled;
2246
2026
  if (newlyFocusedDz.getBoundingClientRect().top < focusedDz.getBoundingClientRect().top || newlyFocusedDz.getBoundingClientRect().left < focusedDz.getBoundingClientRect().left) {
2247
2027
  targetItems.push(itemToMove);
2248
-
2249
2028
  if (!autoAriaDisabled) {
2250
2029
  alertToScreenReader("Moved item ".concat(focusedItemLabel, " to the end of the list ").concat(focusedDzLabel));
2251
2030
  }
2252
2031
  } else {
2253
2032
  targetItems.unshift(itemToMove);
2254
-
2255
2033
  if (!autoAriaDisabled) {
2256
2034
  alertToScreenReader("Moved item ".concat(focusedItemLabel, " to the beginning of the list ").concat(focusedDzLabel));
2257
2035
  }
2258
2036
  }
2259
-
2260
2037
  var dzFrom = focusedDz;
2261
2038
  dispatchFinalizeEvent(dzFrom, originItems, {
2262
2039
  trigger: TRIGGERS.DROPPED_INTO_ANOTHER,
@@ -2270,28 +2047,23 @@ function handleZoneFocus(e) {
2270
2047
  });
2271
2048
  focusedDz = newlyFocusedDz;
2272
2049
  }
2273
-
2274
2050
  function triggerAllDzsUpdate() {
2275
2051
  dzToHandles.forEach(function (_ref, dz) {
2276
2052
  var update = _ref.update;
2277
2053
  return update(dzToConfig$1.get(dz));
2278
2054
  });
2279
2055
  }
2280
-
2281
2056
  function handleDrop$1() {
2282
2057
  var dispatchConsider = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : true;
2283
2058
  printDebug(function () {
2284
2059
  return "drop";
2285
2060
  });
2286
-
2287
2061
  if (!dzToConfig$1.get(focusedDz).autoAriaDisabled) {
2288
2062
  alertToScreenReader("Stopped dragging item ".concat(focusedItemLabel));
2289
2063
  }
2290
-
2291
2064
  if (allDragTargets.has(document.activeElement)) {
2292
2065
  document.activeElement.blur();
2293
2066
  }
2294
-
2295
2067
  if (dispatchConsider) {
2296
2068
  dispatchConsiderEvent(focusedDz, dzToConfig$1.get(focusedDz).items, {
2297
2069
  trigger: TRIGGERS.DRAG_STOPPED,
@@ -2299,7 +2071,6 @@ function handleDrop$1() {
2299
2071
  source: SOURCES.KEYBOARD
2300
2072
  });
2301
2073
  }
2302
-
2303
2074
  styleInactiveDropZones(typeToDropZones$1.get(draggedItemType), function (dz) {
2304
2075
  return dzToConfig$1.get(dz).dropTargetStyle;
2305
2076
  }, function (dz) {
@@ -2313,9 +2084,8 @@ function handleDrop$1() {
2313
2084
  focusedDzLabel = "";
2314
2085
  isDragging = false;
2315
2086
  triggerAllDzsUpdate();
2316
- } //////
2317
-
2318
-
2087
+ }
2088
+ //////
2319
2089
  function dndzone$1(node, options) {
2320
2090
  var config = {
2321
2091
  items: undefined,
@@ -2327,17 +2097,14 @@ function dndzone$1(node, options) {
2327
2097
  dropTargetClasses: [],
2328
2098
  autoAriaDisabled: false
2329
2099
  };
2330
-
2331
2100
  function swap(arr, i, j) {
2332
2101
  if (arr.length <= 1) return;
2333
2102
  arr.splice(j, 1, arr.splice(i, 1, arr[j])[0]);
2334
2103
  }
2335
-
2336
2104
  function handleKeyDown(e) {
2337
2105
  printDebug(function () {
2338
2106
  return ["handling key down", e.key];
2339
2107
  });
2340
-
2341
2108
  switch (e.key) {
2342
2109
  case "Enter":
2343
2110
  case " ":
@@ -2346,11 +2113,8 @@ function dndzone$1(node, options) {
2346
2113
  if ((e.target.disabled !== undefined || e.target.href || e.target.isContentEditable) && !allDragTargets.has(e.target)) {
2347
2114
  return;
2348
2115
  }
2349
-
2350
2116
  e.preventDefault(); // preventing scrolling on spacebar
2351
-
2352
2117
  e.stopPropagation();
2353
-
2354
2118
  if (isDragging) {
2355
2119
  // TODO - should this trigger a drop? only here or in general (as in when hitting space or enter outside of any zone)?
2356
2120
  handleDrop$1();
@@ -2358,32 +2122,25 @@ function dndzone$1(node, options) {
2358
2122
  // drag start
2359
2123
  handleDragStart(e);
2360
2124
  }
2361
-
2362
2125
  break;
2363
2126
  }
2364
-
2365
2127
  case "ArrowDown":
2366
2128
  case "ArrowRight":
2367
2129
  {
2368
2130
  if (!isDragging) return;
2369
2131
  e.preventDefault(); // prevent scrolling
2370
-
2371
2132
  e.stopPropagation();
2372
-
2373
2133
  var _dzToConfig$get3 = dzToConfig$1.get(node),
2374
- items = _dzToConfig$get3.items;
2375
-
2134
+ items = _dzToConfig$get3.items;
2376
2135
  var children = Array.from(node.children);
2377
2136
  var idx = children.indexOf(e.currentTarget);
2378
2137
  printDebug(function () {
2379
2138
  return ["arrow down", idx];
2380
2139
  });
2381
-
2382
2140
  if (idx < children.length - 1) {
2383
2141
  if (!config.autoAriaDisabled) {
2384
2142
  alertToScreenReader("Moved item ".concat(focusedItemLabel, " to position ").concat(idx + 2, " in the list ").concat(focusedDzLabel));
2385
2143
  }
2386
-
2387
2144
  swap(items, idx, idx + 1);
2388
2145
  dispatchFinalizeEvent(node, items, {
2389
2146
  trigger: TRIGGERS.DROPPED_INTO_ZONE,
@@ -2391,34 +2148,25 @@ function dndzone$1(node, options) {
2391
2148
  source: SOURCES.KEYBOARD
2392
2149
  });
2393
2150
  }
2394
-
2395
2151
  break;
2396
2152
  }
2397
-
2398
2153
  case "ArrowUp":
2399
2154
  case "ArrowLeft":
2400
2155
  {
2401
2156
  if (!isDragging) return;
2402
2157
  e.preventDefault(); // prevent scrolling
2403
-
2404
2158
  e.stopPropagation();
2405
-
2406
2159
  var _dzToConfig$get4 = dzToConfig$1.get(node),
2407
- _items = _dzToConfig$get4.items;
2408
-
2160
+ _items = _dzToConfig$get4.items;
2409
2161
  var _children = Array.from(node.children);
2410
-
2411
2162
  var _idx = _children.indexOf(e.currentTarget);
2412
-
2413
2163
  printDebug(function () {
2414
2164
  return ["arrow up", _idx];
2415
2165
  });
2416
-
2417
2166
  if (_idx > 0) {
2418
2167
  if (!config.autoAriaDisabled) {
2419
2168
  alertToScreenReader("Moved item ".concat(focusedItemLabel, " to position ").concat(_idx, " in the list ").concat(focusedDzLabel));
2420
2169
  }
2421
-
2422
2170
  swap(_items, _idx, _idx - 1);
2423
2171
  dispatchFinalizeEvent(node, _items, {
2424
2172
  trigger: TRIGGERS.DROPPED_INTO_ZONE,
@@ -2426,12 +2174,10 @@ function dndzone$1(node, options) {
2426
2174
  source: SOURCES.KEYBOARD
2427
2175
  });
2428
2176
  }
2429
-
2430
2177
  break;
2431
2178
  }
2432
2179
  }
2433
2180
  }
2434
-
2435
2181
  function handleDragStart(e) {
2436
2182
  printDebug(function () {
2437
2183
  return "drag start";
@@ -2448,17 +2194,13 @@ function dndzone$1(node, options) {
2448
2194
  }, function (dz) {
2449
2195
  return dzToConfig$1.get(dz).dropTargetClasses;
2450
2196
  });
2451
-
2452
2197
  if (!config.autoAriaDisabled) {
2453
2198
  var msg = "Started dragging item ".concat(focusedItemLabel, ". Use the arrow keys to move it within its list ").concat(focusedDzLabel);
2454
-
2455
2199
  if (dropTargets.length > 1) {
2456
2200
  msg += ", or tab to another list in order to move the item into it";
2457
2201
  }
2458
-
2459
2202
  alertToScreenReader(msg);
2460
2203
  }
2461
-
2462
2204
  dispatchConsiderEvent(node, dzToConfig$1.get(node).items, {
2463
2205
  trigger: TRIGGERS.DRAG_STARTED,
2464
2206
  id: focusedItemId,
@@ -2466,7 +2208,6 @@ function dndzone$1(node, options) {
2466
2208
  });
2467
2209
  triggerAllDzsUpdate();
2468
2210
  }
2469
-
2470
2211
  function handleClick(e) {
2471
2212
  if (!isDragging) return;
2472
2213
  if (e.currentTarget === focusedItem) return;
@@ -2474,11 +2215,9 @@ function dndzone$1(node, options) {
2474
2215
  handleDrop$1(false);
2475
2216
  handleDragStart(e);
2476
2217
  }
2477
-
2478
2218
  function setCurrentFocusedItem(draggableEl) {
2479
2219
  var _dzToConfig$get5 = dzToConfig$1.get(node),
2480
- items = _dzToConfig$get5.items;
2481
-
2220
+ items = _dzToConfig$get5.items;
2482
2221
  var children = Array.from(node.children);
2483
2222
  var focusedItemIdx = children.indexOf(draggableEl);
2484
2223
  focusedItem = draggableEl;
@@ -2486,24 +2225,23 @@ function dndzone$1(node, options) {
2486
2225
  focusedItemId = items[focusedItemIdx][ITEM_ID_KEY];
2487
2226
  focusedItemLabel = children[focusedItemIdx].getAttribute("aria-label") || "";
2488
2227
  }
2489
-
2490
2228
  function configure(_ref2) {
2491
2229
  var _ref2$items = _ref2.items,
2492
- items = _ref2$items === void 0 ? [] : _ref2$items,
2493
- _ref2$type = _ref2.type,
2494
- newType = _ref2$type === void 0 ? DEFAULT_DROP_ZONE_TYPE$1 : _ref2$type,
2495
- _ref2$dragDisabled = _ref2.dragDisabled,
2496
- dragDisabled = _ref2$dragDisabled === void 0 ? false : _ref2$dragDisabled,
2497
- _ref2$zoneTabIndex = _ref2.zoneTabIndex,
2498
- zoneTabIndex = _ref2$zoneTabIndex === void 0 ? 0 : _ref2$zoneTabIndex,
2499
- _ref2$dropFromOthersD = _ref2.dropFromOthersDisabled,
2500
- dropFromOthersDisabled = _ref2$dropFromOthersD === void 0 ? false : _ref2$dropFromOthersD,
2501
- _ref2$dropTargetStyle = _ref2.dropTargetStyle,
2502
- dropTargetStyle = _ref2$dropTargetStyle === void 0 ? DEFAULT_DROP_TARGET_STYLE$1 : _ref2$dropTargetStyle,
2503
- _ref2$dropTargetClass = _ref2.dropTargetClasses,
2504
- dropTargetClasses = _ref2$dropTargetClass === void 0 ? [] : _ref2$dropTargetClass,
2505
- _ref2$autoAriaDisable = _ref2.autoAriaDisabled,
2506
- autoAriaDisabled = _ref2$autoAriaDisable === void 0 ? false : _ref2$autoAriaDisable;
2230
+ items = _ref2$items === void 0 ? [] : _ref2$items,
2231
+ _ref2$type = _ref2.type,
2232
+ newType = _ref2$type === void 0 ? DEFAULT_DROP_ZONE_TYPE$1 : _ref2$type,
2233
+ _ref2$dragDisabled = _ref2.dragDisabled,
2234
+ dragDisabled = _ref2$dragDisabled === void 0 ? false : _ref2$dragDisabled,
2235
+ _ref2$zoneTabIndex = _ref2.zoneTabIndex,
2236
+ zoneTabIndex = _ref2$zoneTabIndex === void 0 ? 0 : _ref2$zoneTabIndex,
2237
+ _ref2$dropFromOthersD = _ref2.dropFromOthersDisabled,
2238
+ dropFromOthersDisabled = _ref2$dropFromOthersD === void 0 ? false : _ref2$dropFromOthersD,
2239
+ _ref2$dropTargetStyle = _ref2.dropTargetStyle,
2240
+ dropTargetStyle = _ref2$dropTargetStyle === void 0 ? DEFAULT_DROP_TARGET_STYLE$1 : _ref2$dropTargetStyle,
2241
+ _ref2$dropTargetClass = _ref2.dropTargetClasses,
2242
+ dropTargetClasses = _ref2$dropTargetClass === void 0 ? [] : _ref2$dropTargetClass,
2243
+ _ref2$autoAriaDisable = _ref2.autoAriaDisabled,
2244
+ autoAriaDisabled = _ref2$autoAriaDisable === void 0 ? false : _ref2$autoAriaDisable;
2507
2245
  config.items = _toConsumableArray(items);
2508
2246
  config.dragDisabled = dragDisabled;
2509
2247
  config.dropFromOthersDisabled = dropFromOthersDisabled;
@@ -2511,69 +2249,56 @@ function dndzone$1(node, options) {
2511
2249
  config.dropTargetStyle = dropTargetStyle;
2512
2250
  config.dropTargetClasses = dropTargetClasses;
2513
2251
  config.autoAriaDisabled = autoAriaDisabled;
2514
-
2515
2252
  if (config.type && newType !== config.type) {
2516
2253
  unregisterDropZone$1(node, config.type);
2517
2254
  }
2518
-
2519
2255
  config.type = newType;
2520
2256
  registerDropZone$1(node, newType);
2521
-
2522
2257
  if (!autoAriaDisabled) {
2523
2258
  node.setAttribute("aria-disabled", dragDisabled);
2524
2259
  node.setAttribute("role", "list");
2525
2260
  node.setAttribute("aria-describedby", dragDisabled ? INSTRUCTION_IDs$1.DND_ZONE_DRAG_DISABLED : INSTRUCTION_IDs$1.DND_ZONE_ACTIVE);
2526
2261
  }
2527
-
2528
2262
  dzToConfig$1.set(node, config);
2529
-
2530
2263
  if (isDragging) {
2531
2264
  node.tabIndex = node === focusedDz || focusedItem.contains(node) || config.dropFromOthersDisabled || focusedDz && config.type !== dzToConfig$1.get(focusedDz).type ? -1 : 0;
2532
2265
  } else {
2533
2266
  node.tabIndex = config.zoneTabIndex;
2534
2267
  }
2535
-
2536
2268
  node.addEventListener("focus", handleZoneFocus);
2537
-
2538
2269
  var _loop = function _loop(i) {
2539
2270
  var draggableEl = node.children[i];
2540
2271
  allDragTargets.add(draggableEl);
2541
2272
  draggableEl.tabIndex = isDragging ? -1 : 0;
2542
-
2543
2273
  if (!autoAriaDisabled) {
2544
2274
  draggableEl.setAttribute("role", "listitem");
2545
2275
  }
2546
-
2547
2276
  draggableEl.removeEventListener("keydown", elToKeyDownListeners.get(draggableEl));
2548
2277
  draggableEl.removeEventListener("click", elToFocusListeners.get(draggableEl));
2549
-
2550
2278
  if (!dragDisabled) {
2551
2279
  draggableEl.addEventListener("keydown", handleKeyDown);
2552
2280
  elToKeyDownListeners.set(draggableEl, handleKeyDown);
2553
2281
  draggableEl.addEventListener("click", handleClick);
2554
2282
  elToFocusListeners.set(draggableEl, handleClick);
2555
2283
  }
2556
-
2557
2284
  if (isDragging && config.items[i][ITEM_ID_KEY] === focusedItemId) {
2558
2285
  printDebug(function () {
2559
2286
  return ["focusing on", {
2560
2287
  i: i,
2561
2288
  focusedItemId: focusedItemId
2562
2289
  }];
2563
- }); // if it is a nested dropzone, it was re-rendered and we need to refresh our pointer
2564
-
2290
+ });
2291
+ // if it is a nested dropzone, it was re-rendered and we need to refresh our pointer
2565
2292
  focusedItem = draggableEl;
2566
- focusedItem.tabIndex = 0; // without this the element loses focus if it moves backwards in the list
2567
-
2293
+ focusedItem.tabIndex = 0;
2294
+ // without this the element loses focus if it moves backwards in the list
2568
2295
  draggableEl.focus();
2569
2296
  }
2570
2297
  };
2571
-
2572
2298
  for (var i = 0; i < node.children.length; i++) {
2573
2299
  _loop(i);
2574
2300
  }
2575
2301
  }
2576
-
2577
2302
  configure(options);
2578
2303
  var handles = {
2579
2304
  update: function update(newOptions) {
@@ -2596,6 +2321,7 @@ function dndzone$1(node, options) {
2596
2321
  }
2597
2322
 
2598
2323
  var _excluded = ["items", "flipDurationMs", "type", "dragDisabled", "morphDisabled", "dropFromOthersDisabled", "zoneTabIndex", "dropTargetStyle", "dropTargetClasses", "transformDraggedElement", "autoAriaDisabled", "centreDraggedOnCursor"];
2324
+
2599
2325
  /**
2600
2326
  * A custom action to turn any container to a dnd zone and all of its direct children to draggables
2601
2327
  * Supports mouse, touch and keyboard interactions.
@@ -2617,7 +2343,6 @@ var _excluded = ["items", "flipDurationMs", "type", "dragDisabled", "morphDisabl
2617
2343
  * @param {Options} options
2618
2344
  * @return {{update: function, destroy: function}}
2619
2345
  */
2620
-
2621
2346
  function dndzone$2(node, options) {
2622
2347
  validateOptions(options);
2623
2348
  var pointerZone = dndzone(node, options);
@@ -2634,50 +2359,41 @@ function dndzone$2(node, options) {
2634
2359
  }
2635
2360
  };
2636
2361
  }
2637
-
2638
2362
  function validateOptions(options) {
2639
2363
  /*eslint-disable*/
2640
2364
  var items = options.items,
2641
- flipDurationMs = options.flipDurationMs,
2642
- type = options.type,
2643
- dragDisabled = options.dragDisabled,
2644
- morphDisabled = options.morphDisabled,
2645
- dropFromOthersDisabled = options.dropFromOthersDisabled,
2646
- zoneTabIndex = options.zoneTabIndex,
2647
- dropTargetStyle = options.dropTargetStyle,
2648
- dropTargetClasses = options.dropTargetClasses,
2649
- transformDraggedElement = options.transformDraggedElement,
2650
- autoAriaDisabled = options.autoAriaDisabled,
2651
- centreDraggedOnCursor = options.centreDraggedOnCursor,
2652
- rest = _objectWithoutProperties(options, _excluded);
2365
+ flipDurationMs = options.flipDurationMs,
2366
+ type = options.type,
2367
+ dragDisabled = options.dragDisabled,
2368
+ morphDisabled = options.morphDisabled,
2369
+ dropFromOthersDisabled = options.dropFromOthersDisabled,
2370
+ zoneTabIndex = options.zoneTabIndex,
2371
+ dropTargetStyle = options.dropTargetStyle,
2372
+ dropTargetClasses = options.dropTargetClasses,
2373
+ transformDraggedElement = options.transformDraggedElement,
2374
+ autoAriaDisabled = options.autoAriaDisabled,
2375
+ centreDraggedOnCursor = options.centreDraggedOnCursor,
2376
+ rest = _objectWithoutProperties(options, _excluded);
2653
2377
  /*eslint-enable*/
2654
-
2655
-
2656
2378
  if (Object.keys(rest).length > 0) {
2657
2379
  console.warn("dndzone will ignore unknown options", rest);
2658
2380
  }
2659
-
2660
2381
  if (!items) {
2661
2382
  throw new Error("no 'items' key provided to dndzone");
2662
2383
  }
2663
-
2664
2384
  var itemWithMissingId = items.find(function (item) {
2665
2385
  return !{}.hasOwnProperty.call(item, ITEM_ID_KEY);
2666
2386
  });
2667
-
2668
2387
  if (itemWithMissingId) {
2669
2388
  throw new Error("missing '".concat(ITEM_ID_KEY, "' property for item ").concat(toString(itemWithMissingId)));
2670
2389
  }
2671
-
2672
2390
  if (dropTargetClasses && !Array.isArray(dropTargetClasses)) {
2673
2391
  throw new Error("dropTargetClasses should be an array but instead it is a ".concat(_typeof(dropTargetClasses), ", ").concat(toString(dropTargetClasses)));
2674
2392
  }
2675
-
2676
2393
  if (zoneTabIndex && !isInt(zoneTabIndex)) {
2677
2394
  throw new Error("zoneTabIndex should be a number but instead it is a ".concat(_typeof(zoneTabIndex), ", ").concat(toString(zoneTabIndex)));
2678
2395
  }
2679
2396
  }
2680
-
2681
2397
  function isInt(value) {
2682
2398
  return !isNaN(value) && function (x) {
2683
2399
  return (x | 0) === x;