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