@limetech/lime-elements 40.12.3 → 40.13.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (86) hide show
  1. package/CHANGELOG.md +10 -0
  2. package/dist/cjs/drag-to-reorder-BP5YkPuu.js +3092 -0
  3. package/dist/cjs/lime-elements.cjs.js +1 -1
  4. package/dist/cjs/{limel-scroller.cjs.entry.js → limel-drag-handle_2.cjs.entry.js} +38 -0
  5. package/dist/cjs/limel-file-viewer.cjs.entry.js +64 -55
  6. package/dist/cjs/limel-form.cjs.entry.js +539 -3171
  7. package/dist/cjs/limel-tab-bar.cjs.entry.js +120 -16
  8. package/dist/cjs/limel-tab-panel.cjs.entry.js +7 -1
  9. package/dist/cjs/loader.cjs.js +1 -1
  10. package/dist/collection/components/form/form.css +59 -0
  11. package/dist/collection/components/form/form.js +49 -2
  12. package/dist/collection/components/form/show-field.js +116 -0
  13. package/dist/collection/components/form/templates/array-field-collapsible-item.js +1 -0
  14. package/dist/collection/components/form/templates/array-field-item.js +5 -0
  15. package/dist/collection/components/form/templates/array-field.js +20 -158
  16. package/dist/collection/components/form/templates/field.js +17 -0
  17. package/dist/collection/components/tab-bar/tab-bar.css +68 -22
  18. package/dist/collection/components/tab-bar/tab-bar.js +131 -4
  19. package/dist/collection/components/tab-bar/tabs.js +23 -0
  20. package/dist/collection/components/tab-panel/tab-panel.js +54 -1
  21. package/dist/collection/util/drag-to-reorder.js +116 -0
  22. package/dist/esm/{_baseForOwn-D5j7fHlv.js → _baseForOwn-vKFWmmaS.js} +1 -1
  23. package/dist/esm/{_baseIsEqual-CyF4P8uM.js → _baseIsEqual-B_JRErB0.js} +1 -1
  24. package/dist/esm/{_baseIteratee-CpbczHY1.js → _baseIteratee-CVz7aes3.js} +1 -1
  25. package/dist/esm/{_baseSet-Cw2IE6ZF.js → _baseSet-BUAq8NGm.js} +1 -1
  26. package/dist/esm/{cloneDeep-DAbOtbs8.js → cloneDeep-Bcll-3f8.js} +1 -1
  27. package/dist/esm/drag-to-reorder-BXmXIwCa.js +3086 -0
  28. package/dist/esm/{isEqual-CE83yS8T.js → isEqual-C-pK6AAU.js} +1 -1
  29. package/dist/esm/lime-elements.js +1 -1
  30. package/dist/esm/limel-chip-set.entry.js +2 -2
  31. package/dist/esm/limel-dialog.entry.js +2 -2
  32. package/dist/esm/{limel-scroller.entry.js → limel-drag-handle_2.entry.js} +38 -1
  33. package/dist/esm/limel-file-dropzone_2.entry.js +3 -3
  34. package/dist/esm/limel-file-viewer.entry.js +64 -55
  35. package/dist/esm/limel-form.entry.js +536 -3168
  36. package/dist/esm/limel-prosemirror-adapter.entry.js +3 -3
  37. package/dist/esm/limel-tab-bar.entry.js +117 -13
  38. package/dist/esm/limel-tab-panel.entry.js +7 -1
  39. package/dist/esm/limel-table.entry.js +4 -4
  40. package/dist/esm/loader.js +1 -1
  41. package/dist/lime-elements/lime-elements.esm.js +1 -1
  42. package/dist/lime-elements/{p-35bc5ed2.entry.js → p-13f2afc9.entry.js} +1 -1
  43. package/dist/lime-elements/p-3b6d4934.entry.js +1 -0
  44. package/dist/lime-elements/p-67767276.entry.js +1 -0
  45. package/dist/lime-elements/{p-fb15f608.entry.js → p-6d65ee35.entry.js} +1 -1
  46. package/dist/lime-elements/p-714ab66d.entry.js +16 -0
  47. package/dist/lime-elements/{p-ff4a8b89.entry.js → p-7ae71c13.entry.js} +1 -1
  48. package/dist/lime-elements/p-BAqAt5It.js +1 -0
  49. package/dist/lime-elements/p-Cu9Ji1iJ.js +1 -0
  50. package/dist/lime-elements/{p-BY5NjPj8.js → p-D9Ezd43A.js} +1 -1
  51. package/dist/lime-elements/{p-nVemxylR.js → p-DFu1q54T.js} +1 -1
  52. package/dist/lime-elements/p-DdnBHYb-.js +7 -0
  53. package/dist/lime-elements/{p-B6-3WXAv.js → p-DeIIlp6m.js} +1 -1
  54. package/dist/lime-elements/p-Dq0uNStc.js +1 -0
  55. package/dist/lime-elements/p-b5bb124f.entry.js +1 -0
  56. package/dist/lime-elements/{p-9168793f.entry.js → p-bd58c761.entry.js} +1 -1
  57. package/dist/lime-elements/{p-458c131f.entry.js → p-c7e34502.entry.js} +1 -1
  58. package/dist/lime-elements/p-fb526a05.entry.js +1 -0
  59. package/dist/types/components/form/form.d.ts +15 -0
  60. package/dist/types/components/form/show-field.d.ts +9 -0
  61. package/dist/types/components/form/templates/array-context.d.ts +4 -0
  62. package/dist/types/components/form/templates/array-field-collapsible-item.d.ts +5 -0
  63. package/dist/types/components/form/templates/array-field.d.ts +3 -13
  64. package/dist/types/components/form/templates/field.d.ts +1 -0
  65. package/dist/types/components/form/templates/object-field.d.ts +2 -2
  66. package/dist/types/components/tab-bar/tab-bar.d.ts +25 -0
  67. package/dist/types/components/tab-bar/tab.types.d.ts +18 -0
  68. package/dist/types/components/tab-bar/tabs.d.ts +12 -1
  69. package/dist/types/components/tab-panel/tab-panel.d.ts +18 -1
  70. package/dist/types/components.d.ts +80 -2
  71. package/dist/types/util/drag-to-reorder.d.ts +65 -0
  72. package/package.json +4 -4
  73. package/dist/cjs/isArrayLikeObject-U2Ddbw4n.js +0 -326
  74. package/dist/cjs/limel-drag-handle.cjs.entry.js +0 -42
  75. package/dist/esm/isArrayLikeObject-CJB8HbtH.js +0 -321
  76. package/dist/esm/limel-drag-handle.entry.js +0 -40
  77. package/dist/lime-elements/p-49eb2f64.entry.js +0 -13
  78. package/dist/lime-elements/p-646731b6.entry.js +0 -1
  79. package/dist/lime-elements/p-8d567e42.entry.js +0 -1
  80. package/dist/lime-elements/p-BQeIv4aA.js +0 -1
  81. package/dist/lime-elements/p-COdirXg1.js +0 -1
  82. package/dist/lime-elements/p-ORUNaKm-.js +0 -1
  83. package/dist/lime-elements/p-a5246373.entry.js +0 -1
  84. package/dist/lime-elements/p-b609552e.entry.js +0 -1
  85. package/dist/lime-elements/p-bf849dc9.entry.js +0 -1
  86. package/dist/lime-elements/p-pk5KIdKH.js +0 -1
@@ -0,0 +1,3086 @@
1
+ import { i as identity } from './identity-CK4jS9_E.js';
2
+ import { d as defineProperty } from './_defineProperty-C69Btzid.js';
3
+ import { a as arrayPush } from './_baseIsEqual-B_JRErB0.js';
4
+ import { S as Symbol$1 } from './isObject-BJQylLSL.js';
5
+ import { i as isArguments } from './_getTag-BiAaLWvH.js';
6
+ import { i as isArray } from './isArray-B8VKuhvH.js';
7
+ import { i as isArrayLike } from './isArrayLike-CyVGB489.js';
8
+ import { i as isObjectLike } from './isObjectLike-oiMYqRQ0.js';
9
+
10
+ /**
11
+ * A faster alternative to `Function#apply`, this function invokes `func`
12
+ * with the `this` binding of `thisArg` and the arguments of `args`.
13
+ *
14
+ * @private
15
+ * @param {Function} func The function to invoke.
16
+ * @param {*} thisArg The `this` binding of `func`.
17
+ * @param {Array} args The arguments to invoke `func` with.
18
+ * @returns {*} Returns the result of `func`.
19
+ */
20
+ function apply(func, thisArg, args) {
21
+ switch (args.length) {
22
+ case 0: return func.call(thisArg);
23
+ case 1: return func.call(thisArg, args[0]);
24
+ case 2: return func.call(thisArg, args[0], args[1]);
25
+ case 3: return func.call(thisArg, args[0], args[1], args[2]);
26
+ }
27
+ return func.apply(thisArg, args);
28
+ }
29
+
30
+ /** Used to detect hot functions by number of calls within a span of milliseconds. */
31
+ var HOT_COUNT = 800,
32
+ HOT_SPAN = 16;
33
+
34
+ /* Built-in method references for those with the same name as other `lodash` methods. */
35
+ var nativeNow = Date.now;
36
+
37
+ /**
38
+ * Creates a function that'll short out and invoke `identity` instead
39
+ * of `func` when it's called `HOT_COUNT` or more times in `HOT_SPAN`
40
+ * milliseconds.
41
+ *
42
+ * @private
43
+ * @param {Function} func The function to restrict.
44
+ * @returns {Function} Returns the new shortable function.
45
+ */
46
+ function shortOut(func) {
47
+ var count = 0,
48
+ lastCalled = 0;
49
+
50
+ return function() {
51
+ var stamp = nativeNow(),
52
+ remaining = HOT_SPAN - (stamp - lastCalled);
53
+
54
+ lastCalled = stamp;
55
+ if (remaining > 0) {
56
+ if (++count >= HOT_COUNT) {
57
+ return arguments[0];
58
+ }
59
+ } else {
60
+ count = 0;
61
+ }
62
+ return func.apply(undefined, arguments);
63
+ };
64
+ }
65
+
66
+ /**
67
+ * Creates a function that returns `value`.
68
+ *
69
+ * @static
70
+ * @memberOf _
71
+ * @since 2.4.0
72
+ * @category Util
73
+ * @param {*} value The value to return from the new function.
74
+ * @returns {Function} Returns the new constant function.
75
+ * @example
76
+ *
77
+ * var objects = _.times(2, _.constant({ 'a': 1 }));
78
+ *
79
+ * console.log(objects);
80
+ * // => [{ 'a': 1 }, { 'a': 1 }]
81
+ *
82
+ * console.log(objects[0] === objects[1]);
83
+ * // => true
84
+ */
85
+ function constant(value) {
86
+ return function() {
87
+ return value;
88
+ };
89
+ }
90
+
91
+ /**
92
+ * The base implementation of `setToString` without support for hot loop shorting.
93
+ *
94
+ * @private
95
+ * @param {Function} func The function to modify.
96
+ * @param {Function} string The `toString` result.
97
+ * @returns {Function} Returns `func`.
98
+ */
99
+ var baseSetToString = !defineProperty ? identity : function(func, string) {
100
+ return defineProperty(func, 'toString', {
101
+ 'configurable': true,
102
+ 'enumerable': false,
103
+ 'value': constant(string),
104
+ 'writable': true
105
+ });
106
+ };
107
+
108
+ /**
109
+ * Sets the `toString` method of `func` to return `string`.
110
+ *
111
+ * @private
112
+ * @param {Function} func The function to modify.
113
+ * @param {Function} string The `toString` result.
114
+ * @returns {Function} Returns `func`.
115
+ */
116
+ var setToString = shortOut(baseSetToString);
117
+
118
+ /**
119
+ * The base implementation of `_.findIndex` and `_.findLastIndex` without
120
+ * support for iteratee shorthands.
121
+ *
122
+ * @private
123
+ * @param {Array} array The array to inspect.
124
+ * @param {Function} predicate The function invoked per iteration.
125
+ * @param {number} fromIndex The index to search from.
126
+ * @param {boolean} [fromRight] Specify iterating from right to left.
127
+ * @returns {number} Returns the index of the matched value, else `-1`.
128
+ */
129
+ function baseFindIndex(array, predicate, fromIndex, fromRight) {
130
+ var length = array.length,
131
+ index = fromIndex + (-1);
132
+
133
+ while ((++index < length)) {
134
+ if (predicate(array[index], index, array)) {
135
+ return index;
136
+ }
137
+ }
138
+ return -1;
139
+ }
140
+
141
+ /**
142
+ * The base implementation of `_.isNaN` without support for number objects.
143
+ *
144
+ * @private
145
+ * @param {*} value The value to check.
146
+ * @returns {boolean} Returns `true` if `value` is `NaN`, else `false`.
147
+ */
148
+ function baseIsNaN(value) {
149
+ return value !== value;
150
+ }
151
+
152
+ /**
153
+ * A specialized version of `_.indexOf` which performs strict equality
154
+ * comparisons of values, i.e. `===`.
155
+ *
156
+ * @private
157
+ * @param {Array} array The array to inspect.
158
+ * @param {*} value The value to search for.
159
+ * @param {number} fromIndex The index to search from.
160
+ * @returns {number} Returns the index of the matched value, else `-1`.
161
+ */
162
+ function strictIndexOf(array, value, fromIndex) {
163
+ var index = fromIndex - 1,
164
+ length = array.length;
165
+
166
+ while (++index < length) {
167
+ if (array[index] === value) {
168
+ return index;
169
+ }
170
+ }
171
+ return -1;
172
+ }
173
+
174
+ /**
175
+ * The base implementation of `_.indexOf` without `fromIndex` bounds checks.
176
+ *
177
+ * @private
178
+ * @param {Array} array The array to inspect.
179
+ * @param {*} value The value to search for.
180
+ * @param {number} fromIndex The index to search from.
181
+ * @returns {number} Returns the index of the matched value, else `-1`.
182
+ */
183
+ function baseIndexOf(array, value, fromIndex) {
184
+ return value === value
185
+ ? strictIndexOf(array, value, fromIndex)
186
+ : baseFindIndex(array, baseIsNaN, fromIndex);
187
+ }
188
+
189
+ /**
190
+ * A specialized version of `_.includes` for arrays without support for
191
+ * specifying an index to search from.
192
+ *
193
+ * @private
194
+ * @param {Array} [array] The array to inspect.
195
+ * @param {*} target The value to search for.
196
+ * @returns {boolean} Returns `true` if `target` is found, else `false`.
197
+ */
198
+ function arrayIncludes(array, value) {
199
+ var length = array == null ? 0 : array.length;
200
+ return !!length && baseIndexOf(array, value, 0) > -1;
201
+ }
202
+
203
+ /* Built-in method references for those with the same name as other `lodash` methods. */
204
+ var nativeMax = Math.max;
205
+
206
+ /**
207
+ * A specialized version of `baseRest` which transforms the rest array.
208
+ *
209
+ * @private
210
+ * @param {Function} func The function to apply a rest parameter to.
211
+ * @param {number} [start=func.length-1] The start position of the rest parameter.
212
+ * @param {Function} transform The rest array transform.
213
+ * @returns {Function} Returns the new function.
214
+ */
215
+ function overRest(func, start, transform) {
216
+ start = nativeMax(start === undefined ? (func.length - 1) : start, 0);
217
+ return function() {
218
+ var args = arguments,
219
+ index = -1,
220
+ length = nativeMax(args.length - start, 0),
221
+ array = Array(length);
222
+
223
+ while (++index < length) {
224
+ array[index] = args[start + index];
225
+ }
226
+ index = -1;
227
+ var otherArgs = Array(start + 1);
228
+ while (++index < start) {
229
+ otherArgs[index] = args[index];
230
+ }
231
+ otherArgs[start] = transform(array);
232
+ return apply(func, this, otherArgs);
233
+ };
234
+ }
235
+
236
+ /**
237
+ * The base implementation of `_.rest` which doesn't validate or coerce arguments.
238
+ *
239
+ * @private
240
+ * @param {Function} func The function to apply a rest parameter to.
241
+ * @param {number} [start=func.length-1] The start position of the rest parameter.
242
+ * @returns {Function} Returns the new function.
243
+ */
244
+ function baseRest(func, start) {
245
+ return setToString(overRest(func, start, identity), func + '');
246
+ }
247
+
248
+ /** Built-in value references. */
249
+ var spreadableSymbol = Symbol$1 ? Symbol$1.isConcatSpreadable : undefined;
250
+
251
+ /**
252
+ * Checks if `value` is a flattenable `arguments` object or array.
253
+ *
254
+ * @private
255
+ * @param {*} value The value to check.
256
+ * @returns {boolean} Returns `true` if `value` is flattenable, else `false`.
257
+ */
258
+ function isFlattenable(value) {
259
+ return isArray(value) || isArguments(value) ||
260
+ !!(spreadableSymbol && value && value[spreadableSymbol]);
261
+ }
262
+
263
+ /**
264
+ * The base implementation of `_.flatten` with support for restricting flattening.
265
+ *
266
+ * @private
267
+ * @param {Array} array The array to flatten.
268
+ * @param {number} depth The maximum recursion depth.
269
+ * @param {boolean} [predicate=isFlattenable] The function invoked per iteration.
270
+ * @param {boolean} [isStrict] Restrict to values that pass `predicate` checks.
271
+ * @param {Array} [result=[]] The initial result value.
272
+ * @returns {Array} Returns the new flattened array.
273
+ */
274
+ function baseFlatten(array, depth, predicate, isStrict, result) {
275
+ var index = -1,
276
+ length = array.length;
277
+
278
+ predicate || (predicate = isFlattenable);
279
+ result || (result = []);
280
+
281
+ while (++index < length) {
282
+ var value = array[index];
283
+ if (predicate(value)) {
284
+ {
285
+ arrayPush(result, value);
286
+ }
287
+ }
288
+ }
289
+ return result;
290
+ }
291
+
292
+ /**
293
+ * This method is like `_.isArrayLike` except that it also checks if `value`
294
+ * is an object.
295
+ *
296
+ * @static
297
+ * @memberOf _
298
+ * @since 4.0.0
299
+ * @category Lang
300
+ * @param {*} value The value to check.
301
+ * @returns {boolean} Returns `true` if `value` is an array-like object,
302
+ * else `false`.
303
+ * @example
304
+ *
305
+ * _.isArrayLikeObject([1, 2, 3]);
306
+ * // => true
307
+ *
308
+ * _.isArrayLikeObject(document.body.children);
309
+ * // => true
310
+ *
311
+ * _.isArrayLikeObject('abc');
312
+ * // => false
313
+ *
314
+ * _.isArrayLikeObject(_.noop);
315
+ * // => false
316
+ */
317
+ function isArrayLikeObject(value) {
318
+ return isObjectLike(value) && isArrayLike(value);
319
+ }
320
+
321
+ /**!
322
+ * Sortable 1.15.7
323
+ * @author RubaXa <trash@rubaxa.org>
324
+ * @author owenm <owen23355@gmail.com>
325
+ * @license MIT
326
+ */
327
+ function _defineProperty(e, r, t) {
328
+ return (r = _toPropertyKey(r)) in e ? Object.defineProperty(e, r, {
329
+ value: t,
330
+ enumerable: true,
331
+ configurable: true,
332
+ writable: true
333
+ }) : e[r] = t, e;
334
+ }
335
+ function _extends() {
336
+ return _extends = Object.assign ? Object.assign.bind() : function (n) {
337
+ for (var e = 1; e < arguments.length; e++) {
338
+ var t = arguments[e];
339
+ for (var r in t) ({}).hasOwnProperty.call(t, r) && (n[r] = t[r]);
340
+ }
341
+ return n;
342
+ }, _extends.apply(null, arguments);
343
+ }
344
+ function ownKeys(e, r) {
345
+ var t = Object.keys(e);
346
+ if (Object.getOwnPropertySymbols) {
347
+ var o = Object.getOwnPropertySymbols(e);
348
+ r && (o = o.filter(function (r) {
349
+ return Object.getOwnPropertyDescriptor(e, r).enumerable;
350
+ })), t.push.apply(t, o);
351
+ }
352
+ return t;
353
+ }
354
+ function _objectSpread2(e) {
355
+ for (var r = 1; r < arguments.length; r++) {
356
+ var t = null != arguments[r] ? arguments[r] : {};
357
+ r % 2 ? ownKeys(Object(t), true).forEach(function (r) {
358
+ _defineProperty(e, r, t[r]);
359
+ }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) {
360
+ Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r));
361
+ });
362
+ }
363
+ return e;
364
+ }
365
+ function _objectWithoutProperties(e, t) {
366
+ if (null == e) return {};
367
+ var o,
368
+ r,
369
+ i = _objectWithoutPropertiesLoose(e, t);
370
+ if (Object.getOwnPropertySymbols) {
371
+ var n = Object.getOwnPropertySymbols(e);
372
+ for (r = 0; r < n.length; r++) o = n[r], -1 === t.indexOf(o) && {}.propertyIsEnumerable.call(e, o) && (i[o] = e[o]);
373
+ }
374
+ return i;
375
+ }
376
+ function _objectWithoutPropertiesLoose(r, e) {
377
+ if (null == r) return {};
378
+ var t = {};
379
+ for (var n in r) if ({}.hasOwnProperty.call(r, n)) {
380
+ if (-1 !== e.indexOf(n)) continue;
381
+ t[n] = r[n];
382
+ }
383
+ return t;
384
+ }
385
+ function _toPrimitive(t, r) {
386
+ if ("object" != typeof t || !t) return t;
387
+ var e = t[Symbol.toPrimitive];
388
+ if (void 0 !== e) {
389
+ var i = e.call(t, r);
390
+ if ("object" != typeof i) return i;
391
+ throw new TypeError("@@toPrimitive must return a primitive value.");
392
+ }
393
+ return ("string" === r ? String : Number)(t);
394
+ }
395
+ function _toPropertyKey(t) {
396
+ var i = _toPrimitive(t, "string");
397
+ return "symbol" == typeof i ? i : i + "";
398
+ }
399
+ function _typeof(o) {
400
+ "@babel/helpers - typeof";
401
+
402
+ return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) {
403
+ return typeof o;
404
+ } : function (o) {
405
+ return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o;
406
+ }, _typeof(o);
407
+ }
408
+
409
+ var version = "1.15.7";
410
+
411
+ function userAgent(pattern) {
412
+ if (typeof window !== 'undefined' && window.navigator) {
413
+ return !! /*@__PURE__*/navigator.userAgent.match(pattern);
414
+ }
415
+ }
416
+ var IE11OrLess = userAgent(/(?:Trident.*rv[ :]?11\.|msie|iemobile|Windows Phone)/i);
417
+ var Edge = userAgent(/Edge/i);
418
+ var FireFox = userAgent(/firefox/i);
419
+ var Safari = userAgent(/safari/i) && !userAgent(/chrome/i) && !userAgent(/android/i);
420
+ var IOS = userAgent(/iP(ad|od|hone)/i);
421
+ var ChromeForAndroid = userAgent(/chrome/i) && userAgent(/android/i);
422
+
423
+ var captureMode = {
424
+ capture: false,
425
+ passive: false
426
+ };
427
+ function on(el, event, fn) {
428
+ el.addEventListener(event, fn, !IE11OrLess && captureMode);
429
+ }
430
+ function off(el, event, fn) {
431
+ el.removeEventListener(event, fn, !IE11OrLess && captureMode);
432
+ }
433
+ function matches( /**HTMLElement*/el, /**String*/selector) {
434
+ if (!selector) return;
435
+ selector[0] === '>' && (selector = selector.substring(1));
436
+ if (el) {
437
+ try {
438
+ if (el.matches) {
439
+ return el.matches(selector);
440
+ } else if (el.msMatchesSelector) {
441
+ return el.msMatchesSelector(selector);
442
+ } else if (el.webkitMatchesSelector) {
443
+ return el.webkitMatchesSelector(selector);
444
+ }
445
+ } catch (_) {
446
+ return false;
447
+ }
448
+ }
449
+ return false;
450
+ }
451
+ function getParentOrHost(el) {
452
+ return el.host && el !== document && el.host.nodeType && el.host !== el ? el.host : el.parentNode;
453
+ }
454
+ function closest( /**HTMLElement*/el, /**String*/selector, /**HTMLElement*/ctx, includeCTX) {
455
+ if (el) {
456
+ ctx = ctx || document;
457
+ do {
458
+ if (selector != null && (selector[0] === '>' ? el.parentNode === ctx && matches(el, selector) : matches(el, selector)) || includeCTX && el === ctx) {
459
+ return el;
460
+ }
461
+ if (el === ctx) break;
462
+ /* jshint boss:true */
463
+ } while (el = getParentOrHost(el));
464
+ }
465
+ return null;
466
+ }
467
+ var R_SPACE = /\s+/g;
468
+ function toggleClass(el, name, state) {
469
+ if (el && name) {
470
+ if (el.classList) {
471
+ el.classList[state ? 'add' : 'remove'](name);
472
+ } else {
473
+ var className = (' ' + el.className + ' ').replace(R_SPACE, ' ').replace(' ' + name + ' ', ' ');
474
+ el.className = (className + (state ? ' ' + name : '')).replace(R_SPACE, ' ');
475
+ }
476
+ }
477
+ }
478
+ function css(el, prop, val) {
479
+ var style = el && el.style;
480
+ if (style) {
481
+ if (val === void 0) {
482
+ if (document.defaultView && document.defaultView.getComputedStyle) {
483
+ val = document.defaultView.getComputedStyle(el, '');
484
+ } else if (el.currentStyle) {
485
+ val = el.currentStyle;
486
+ }
487
+ return prop === void 0 ? val : val[prop];
488
+ } else {
489
+ if (!(prop in style) && prop.indexOf('webkit') === -1) {
490
+ prop = '-webkit-' + prop;
491
+ }
492
+ style[prop] = val + (typeof val === 'string' ? '' : 'px');
493
+ }
494
+ }
495
+ }
496
+ function matrix(el, selfOnly) {
497
+ var appliedTransforms = '';
498
+ if (typeof el === 'string') {
499
+ appliedTransforms = el;
500
+ } else {
501
+ do {
502
+ var transform = css(el, 'transform');
503
+ if (transform && transform !== 'none') {
504
+ appliedTransforms = transform + ' ' + appliedTransforms;
505
+ }
506
+ /* jshint boss:true */
507
+ } while (!selfOnly && (el = el.parentNode));
508
+ }
509
+ var matrixFn = window.DOMMatrix || window.WebKitCSSMatrix || window.CSSMatrix || window.MSCSSMatrix;
510
+ /*jshint -W056 */
511
+ return matrixFn && new matrixFn(appliedTransforms);
512
+ }
513
+ function find(ctx, tagName, iterator) {
514
+ if (ctx) {
515
+ var list = ctx.getElementsByTagName(tagName),
516
+ i = 0,
517
+ n = list.length;
518
+ if (iterator) {
519
+ for (; i < n; i++) {
520
+ iterator(list[i], i);
521
+ }
522
+ }
523
+ return list;
524
+ }
525
+ return [];
526
+ }
527
+ function getWindowScrollingElement() {
528
+ var scrollingElement = document.scrollingElement;
529
+ if (scrollingElement) {
530
+ return scrollingElement;
531
+ } else {
532
+ return document.documentElement;
533
+ }
534
+ }
535
+
536
+ /**
537
+ * Returns the "bounding client rect" of given element
538
+ * @param {HTMLElement} el The element whose boundingClientRect is wanted
539
+ * @param {[Boolean]} relativeToContainingBlock Whether the rect should be relative to the containing block of (including) the container
540
+ * @param {[Boolean]} relativeToNonStaticParent Whether the rect should be relative to the relative parent of (including) the contaienr
541
+ * @param {[Boolean]} undoScale Whether the container's scale() should be undone
542
+ * @param {[HTMLElement]} container The parent the element will be placed in
543
+ * @return {Object} The boundingClientRect of el, with specified adjustments
544
+ */
545
+ function getRect(el, relativeToContainingBlock, relativeToNonStaticParent, undoScale, container) {
546
+ if (!el.getBoundingClientRect && el !== window) return;
547
+ var elRect, top, left, bottom, right, height, width;
548
+ if (el !== window && el.parentNode && el !== getWindowScrollingElement()) {
549
+ elRect = el.getBoundingClientRect();
550
+ top = elRect.top;
551
+ left = elRect.left;
552
+ bottom = elRect.bottom;
553
+ right = elRect.right;
554
+ height = elRect.height;
555
+ width = elRect.width;
556
+ } else {
557
+ top = 0;
558
+ left = 0;
559
+ bottom = window.innerHeight;
560
+ right = window.innerWidth;
561
+ height = window.innerHeight;
562
+ width = window.innerWidth;
563
+ }
564
+ if ((relativeToContainingBlock || relativeToNonStaticParent) && el !== window) {
565
+ // Adjust for translate()
566
+ container = container || el.parentNode;
567
+
568
+ // solves #1123 (see: https://stackoverflow.com/a/37953806/6088312)
569
+ // Not needed on <= IE11
570
+ if (!IE11OrLess) {
571
+ do {
572
+ if (container && container.getBoundingClientRect && (css(container, 'transform') !== 'none' || relativeToNonStaticParent && css(container, 'position') !== 'static')) {
573
+ var containerRect = container.getBoundingClientRect();
574
+
575
+ // Set relative to edges of padding box of container
576
+ top -= containerRect.top + parseInt(css(container, 'border-top-width'));
577
+ left -= containerRect.left + parseInt(css(container, 'border-left-width'));
578
+ bottom = top + elRect.height;
579
+ right = left + elRect.width;
580
+ break;
581
+ }
582
+ /* jshint boss:true */
583
+ } while (container = container.parentNode);
584
+ }
585
+ }
586
+ if (undoScale && el !== window) {
587
+ // Adjust for scale()
588
+ var elMatrix = matrix(container || el),
589
+ scaleX = elMatrix && elMatrix.a,
590
+ scaleY = elMatrix && elMatrix.d;
591
+ if (elMatrix) {
592
+ top /= scaleY;
593
+ left /= scaleX;
594
+ width /= scaleX;
595
+ height /= scaleY;
596
+ bottom = top + height;
597
+ right = left + width;
598
+ }
599
+ }
600
+ return {
601
+ top: top,
602
+ left: left,
603
+ bottom: bottom,
604
+ right: right,
605
+ width: width,
606
+ height: height
607
+ };
608
+ }
609
+
610
+ /**
611
+ * Checks if a side of an element is scrolled past a side of its parents
612
+ * @param {HTMLElement} el The element who's side being scrolled out of view is in question
613
+ * @param {String} elSide Side of the element in question ('top', 'left', 'right', 'bottom')
614
+ * @param {String} parentSide Side of the parent in question ('top', 'left', 'right', 'bottom')
615
+ * @return {HTMLElement} The parent scroll element that the el's side is scrolled past, or null if there is no such element
616
+ */
617
+ function isScrolledPast(el, elSide, parentSide) {
618
+ var parent = getParentAutoScrollElement(el, true),
619
+ elSideVal = getRect(el)[elSide];
620
+
621
+ /* jshint boss:true */
622
+ while (parent) {
623
+ var parentSideVal = getRect(parent)[parentSide],
624
+ visible = void 0;
625
+ {
626
+ visible = elSideVal >= parentSideVal;
627
+ }
628
+ if (!visible) return parent;
629
+ if (parent === getWindowScrollingElement()) break;
630
+ parent = getParentAutoScrollElement(parent, false);
631
+ }
632
+ return false;
633
+ }
634
+
635
+ /**
636
+ * Gets nth child of el, ignoring hidden children, sortable's elements (does not ignore clone if it's visible)
637
+ * and non-draggable elements
638
+ * @param {HTMLElement} el The parent element
639
+ * @param {Number} childNum The index of the child
640
+ * @param {Object} options Parent Sortable's options
641
+ * @return {HTMLElement} The child at index childNum, or null if not found
642
+ */
643
+ function getChild(el, childNum, options, includeDragEl) {
644
+ var currentChild = 0,
645
+ i = 0,
646
+ children = el.children;
647
+ while (i < children.length) {
648
+ if (children[i].style.display !== 'none' && children[i] !== Sortable.ghost && (includeDragEl || children[i] !== Sortable.dragged) && closest(children[i], options.draggable, el, false)) {
649
+ if (currentChild === childNum) {
650
+ return children[i];
651
+ }
652
+ currentChild++;
653
+ }
654
+ i++;
655
+ }
656
+ return null;
657
+ }
658
+
659
+ /**
660
+ * Gets the last child in the el, ignoring ghostEl or invisible elements (clones)
661
+ * @param {HTMLElement} el Parent element
662
+ * @param {selector} selector Any other elements that should be ignored
663
+ * @return {HTMLElement} The last child, ignoring ghostEl
664
+ */
665
+ function lastChild(el, selector) {
666
+ var last = el.lastElementChild;
667
+ while (last && (last === Sortable.ghost || css(last, 'display') === 'none' || selector && !matches(last, selector))) {
668
+ last = last.previousElementSibling;
669
+ }
670
+ return last || null;
671
+ }
672
+
673
+ /**
674
+ * Returns the index of an element within its parent for a selected set of
675
+ * elements
676
+ * @param {HTMLElement} el
677
+ * @param {selector} selector
678
+ * @return {number}
679
+ */
680
+ function index(el, selector) {
681
+ var index = 0;
682
+ if (!el || !el.parentNode) {
683
+ return -1;
684
+ }
685
+
686
+ /* jshint boss:true */
687
+ while (el = el.previousElementSibling) {
688
+ if (el.nodeName.toUpperCase() !== 'TEMPLATE' && el !== Sortable.clone && (!selector || matches(el, selector))) {
689
+ index++;
690
+ }
691
+ }
692
+ return index;
693
+ }
694
+
695
+ /**
696
+ * Returns the scroll offset of the given element, added with all the scroll offsets of parent elements.
697
+ * The value is returned in real pixels.
698
+ * @param {HTMLElement} el
699
+ * @return {Array} Offsets in the format of [left, top]
700
+ */
701
+ function getRelativeScrollOffset(el) {
702
+ var offsetLeft = 0,
703
+ offsetTop = 0,
704
+ winScroller = getWindowScrollingElement();
705
+ if (el) {
706
+ do {
707
+ var elMatrix = matrix(el),
708
+ scaleX = elMatrix.a,
709
+ scaleY = elMatrix.d;
710
+ offsetLeft += el.scrollLeft * scaleX;
711
+ offsetTop += el.scrollTop * scaleY;
712
+ } while (el !== winScroller && (el = el.parentNode));
713
+ }
714
+ return [offsetLeft, offsetTop];
715
+ }
716
+
717
+ /**
718
+ * Returns the index of the object within the given array
719
+ * @param {Array} arr Array that may or may not hold the object
720
+ * @param {Object} obj An object that has a key-value pair unique to and identical to a key-value pair in the object you want to find
721
+ * @return {Number} The index of the object in the array, or -1
722
+ */
723
+ function indexOfObject(arr, obj) {
724
+ for (var i in arr) {
725
+ if (!arr.hasOwnProperty(i)) continue;
726
+ for (var key in obj) {
727
+ if (obj.hasOwnProperty(key) && obj[key] === arr[i][key]) return Number(i);
728
+ }
729
+ }
730
+ return -1;
731
+ }
732
+ function getParentAutoScrollElement(el, includeSelf) {
733
+ // skip to window
734
+ if (!el || !el.getBoundingClientRect) return getWindowScrollingElement();
735
+ var elem = el;
736
+ var gotSelf = false;
737
+ do {
738
+ // we don't need to get elem css if it isn't even overflowing in the first place (performance)
739
+ if (elem.clientWidth < elem.scrollWidth || elem.clientHeight < elem.scrollHeight) {
740
+ var elemCSS = css(elem);
741
+ if (elem.clientWidth < elem.scrollWidth && (elemCSS.overflowX == 'auto' || elemCSS.overflowX == 'scroll') || elem.clientHeight < elem.scrollHeight && (elemCSS.overflowY == 'auto' || elemCSS.overflowY == 'scroll')) {
742
+ if (!elem.getBoundingClientRect || elem === document.body) return getWindowScrollingElement();
743
+ if (gotSelf || includeSelf) return elem;
744
+ gotSelf = true;
745
+ }
746
+ }
747
+ /* jshint boss:true */
748
+ } while (elem = elem.parentNode);
749
+ return getWindowScrollingElement();
750
+ }
751
+ function extend(dst, src) {
752
+ if (dst && src) {
753
+ for (var key in src) {
754
+ if (src.hasOwnProperty(key)) {
755
+ dst[key] = src[key];
756
+ }
757
+ }
758
+ }
759
+ return dst;
760
+ }
761
+ function isRectEqual(rect1, rect2) {
762
+ return Math.round(rect1.top) === Math.round(rect2.top) && Math.round(rect1.left) === Math.round(rect2.left) && Math.round(rect1.height) === Math.round(rect2.height) && Math.round(rect1.width) === Math.round(rect2.width);
763
+ }
764
+ var _throttleTimeout;
765
+ function throttle(callback, ms) {
766
+ return function () {
767
+ if (!_throttleTimeout) {
768
+ var args = arguments,
769
+ _this = this;
770
+ if (args.length === 1) {
771
+ callback.call(_this, args[0]);
772
+ } else {
773
+ callback.apply(_this, args);
774
+ }
775
+ _throttleTimeout = setTimeout(function () {
776
+ _throttleTimeout = void 0;
777
+ }, ms);
778
+ }
779
+ };
780
+ }
781
+ function cancelThrottle() {
782
+ clearTimeout(_throttleTimeout);
783
+ _throttleTimeout = void 0;
784
+ }
785
+ function scrollBy(el, x, y) {
786
+ el.scrollLeft += x;
787
+ el.scrollTop += y;
788
+ }
789
+ function clone(el) {
790
+ var Polymer = window.Polymer;
791
+ var $ = window.jQuery || window.Zepto;
792
+ if (Polymer && Polymer.dom) {
793
+ return Polymer.dom(el).cloneNode(true);
794
+ } else if ($) {
795
+ return $(el).clone(true)[0];
796
+ } else {
797
+ return el.cloneNode(true);
798
+ }
799
+ }
800
+ function getChildContainingRectFromElement(container, options, ghostEl) {
801
+ var rect = {};
802
+ Array.from(container.children).forEach(function (child) {
803
+ var _rect$left, _rect$top, _rect$right, _rect$bottom;
804
+ if (!closest(child, options.draggable, container, false) || child.animated || child === ghostEl) return;
805
+ var childRect = getRect(child);
806
+ rect.left = Math.min((_rect$left = rect.left) !== null && _rect$left !== void 0 ? _rect$left : Infinity, childRect.left);
807
+ rect.top = Math.min((_rect$top = rect.top) !== null && _rect$top !== void 0 ? _rect$top : Infinity, childRect.top);
808
+ rect.right = Math.max((_rect$right = rect.right) !== null && _rect$right !== void 0 ? _rect$right : -Infinity, childRect.right);
809
+ rect.bottom = Math.max((_rect$bottom = rect.bottom) !== null && _rect$bottom !== void 0 ? _rect$bottom : -Infinity, childRect.bottom);
810
+ });
811
+ rect.width = rect.right - rect.left;
812
+ rect.height = rect.bottom - rect.top;
813
+ rect.x = rect.left;
814
+ rect.y = rect.top;
815
+ return rect;
816
+ }
817
+ var expando = 'Sortable' + new Date().getTime();
818
+
819
+ function AnimationStateManager() {
820
+ var animationStates = [],
821
+ animationCallbackId;
822
+ return {
823
+ captureAnimationState: function captureAnimationState() {
824
+ animationStates = [];
825
+ if (!this.options.animation) return;
826
+ var children = [].slice.call(this.el.children);
827
+ children.forEach(function (child) {
828
+ if (css(child, 'display') === 'none' || child === Sortable.ghost) return;
829
+ animationStates.push({
830
+ target: child,
831
+ rect: getRect(child)
832
+ });
833
+ var fromRect = _objectSpread2({}, animationStates[animationStates.length - 1].rect);
834
+
835
+ // If animating: compensate for current animation
836
+ if (child.thisAnimationDuration) {
837
+ var childMatrix = matrix(child, true);
838
+ if (childMatrix) {
839
+ fromRect.top -= childMatrix.f;
840
+ fromRect.left -= childMatrix.e;
841
+ }
842
+ }
843
+ child.fromRect = fromRect;
844
+ });
845
+ },
846
+ addAnimationState: function addAnimationState(state) {
847
+ animationStates.push(state);
848
+ },
849
+ removeAnimationState: function removeAnimationState(target) {
850
+ animationStates.splice(indexOfObject(animationStates, {
851
+ target: target
852
+ }), 1);
853
+ },
854
+ animateAll: function animateAll(callback) {
855
+ var _this = this;
856
+ if (!this.options.animation) {
857
+ clearTimeout(animationCallbackId);
858
+ if (typeof callback === 'function') callback();
859
+ return;
860
+ }
861
+ var animating = false,
862
+ animationTime = 0;
863
+ animationStates.forEach(function (state) {
864
+ var time = 0,
865
+ target = state.target,
866
+ fromRect = target.fromRect,
867
+ toRect = getRect(target),
868
+ prevFromRect = target.prevFromRect,
869
+ prevToRect = target.prevToRect,
870
+ animatingRect = state.rect,
871
+ targetMatrix = matrix(target, true);
872
+ if (targetMatrix) {
873
+ // Compensate for current animation
874
+ toRect.top -= targetMatrix.f;
875
+ toRect.left -= targetMatrix.e;
876
+ }
877
+ target.toRect = toRect;
878
+ if (target.thisAnimationDuration) {
879
+ // Could also check if animatingRect is between fromRect and toRect
880
+ if (isRectEqual(prevFromRect, toRect) && !isRectEqual(fromRect, toRect) &&
881
+ // Make sure animatingRect is on line between toRect & fromRect
882
+ (animatingRect.top - toRect.top) / (animatingRect.left - toRect.left) === (fromRect.top - toRect.top) / (fromRect.left - toRect.left)) {
883
+ // If returning to same place as started from animation and on same axis
884
+ time = calculateRealTime(animatingRect, prevFromRect, prevToRect, _this.options);
885
+ }
886
+ }
887
+
888
+ // if fromRect != toRect: animate
889
+ if (!isRectEqual(toRect, fromRect)) {
890
+ target.prevFromRect = fromRect;
891
+ target.prevToRect = toRect;
892
+ if (!time) {
893
+ time = _this.options.animation;
894
+ }
895
+ _this.animate(target, animatingRect, toRect, time);
896
+ }
897
+ if (time) {
898
+ animating = true;
899
+ animationTime = Math.max(animationTime, time);
900
+ clearTimeout(target.animationResetTimer);
901
+ target.animationResetTimer = setTimeout(function () {
902
+ target.animationTime = 0;
903
+ target.prevFromRect = null;
904
+ target.fromRect = null;
905
+ target.prevToRect = null;
906
+ target.thisAnimationDuration = null;
907
+ }, time);
908
+ target.thisAnimationDuration = time;
909
+ }
910
+ });
911
+ clearTimeout(animationCallbackId);
912
+ if (!animating) {
913
+ if (typeof callback === 'function') callback();
914
+ } else {
915
+ animationCallbackId = setTimeout(function () {
916
+ if (typeof callback === 'function') callback();
917
+ }, animationTime);
918
+ }
919
+ animationStates = [];
920
+ },
921
+ animate: function animate(target, currentRect, toRect, duration) {
922
+ if (duration) {
923
+ css(target, 'transition', '');
924
+ css(target, 'transform', '');
925
+ var elMatrix = matrix(this.el),
926
+ scaleX = elMatrix && elMatrix.a,
927
+ scaleY = elMatrix && elMatrix.d,
928
+ translateX = (currentRect.left - toRect.left) / (scaleX || 1),
929
+ translateY = (currentRect.top - toRect.top) / (scaleY || 1);
930
+ target.animatingX = !!translateX;
931
+ target.animatingY = !!translateY;
932
+ css(target, 'transform', 'translate3d(' + translateX + 'px,' + translateY + 'px,0)');
933
+ this.forRepaintDummy = repaint(target); // repaint
934
+
935
+ css(target, 'transition', 'transform ' + duration + 'ms' + (this.options.easing ? ' ' + this.options.easing : ''));
936
+ css(target, 'transform', 'translate3d(0,0,0)');
937
+ typeof target.animated === 'number' && clearTimeout(target.animated);
938
+ target.animated = setTimeout(function () {
939
+ css(target, 'transition', '');
940
+ css(target, 'transform', '');
941
+ target.animated = false;
942
+ target.animatingX = false;
943
+ target.animatingY = false;
944
+ }, duration);
945
+ }
946
+ }
947
+ };
948
+ }
949
+ function repaint(target) {
950
+ return target.offsetWidth;
951
+ }
952
+ function calculateRealTime(animatingRect, fromRect, toRect, options) {
953
+ return Math.sqrt(Math.pow(fromRect.top - animatingRect.top, 2) + Math.pow(fromRect.left - animatingRect.left, 2)) / Math.sqrt(Math.pow(fromRect.top - toRect.top, 2) + Math.pow(fromRect.left - toRect.left, 2)) * options.animation;
954
+ }
955
+
956
+ var plugins = [];
957
+ var defaults = {
958
+ initializeByDefault: true
959
+ };
960
+ var PluginManager = {
961
+ mount: function mount(plugin) {
962
+ // Set default static properties
963
+ for (var option in defaults) {
964
+ if (defaults.hasOwnProperty(option) && !(option in plugin)) {
965
+ plugin[option] = defaults[option];
966
+ }
967
+ }
968
+ plugins.forEach(function (p) {
969
+ if (p.pluginName === plugin.pluginName) {
970
+ throw "Sortable: Cannot mount plugin ".concat(plugin.pluginName, " more than once");
971
+ }
972
+ });
973
+ plugins.push(plugin);
974
+ },
975
+ pluginEvent: function pluginEvent(eventName, sortable, evt) {
976
+ var _this = this;
977
+ this.eventCanceled = false;
978
+ evt.cancel = function () {
979
+ _this.eventCanceled = true;
980
+ };
981
+ var eventNameGlobal = eventName + 'Global';
982
+ plugins.forEach(function (plugin) {
983
+ if (!sortable[plugin.pluginName]) return;
984
+ // Fire global events if it exists in this sortable
985
+ if (sortable[plugin.pluginName][eventNameGlobal]) {
986
+ sortable[plugin.pluginName][eventNameGlobal](_objectSpread2({
987
+ sortable: sortable
988
+ }, evt));
989
+ }
990
+
991
+ // Only fire plugin event if plugin is enabled in this sortable,
992
+ // and plugin has event defined
993
+ if (sortable.options[plugin.pluginName] && sortable[plugin.pluginName][eventName]) {
994
+ sortable[plugin.pluginName][eventName](_objectSpread2({
995
+ sortable: sortable
996
+ }, evt));
997
+ }
998
+ });
999
+ },
1000
+ initializePlugins: function initializePlugins(sortable, el, defaults, options) {
1001
+ plugins.forEach(function (plugin) {
1002
+ var pluginName = plugin.pluginName;
1003
+ if (!sortable.options[pluginName] && !plugin.initializeByDefault) return;
1004
+ var initialized = new plugin(sortable, el, sortable.options);
1005
+ initialized.sortable = sortable;
1006
+ initialized.options = sortable.options;
1007
+ sortable[pluginName] = initialized;
1008
+
1009
+ // Add default options from plugin
1010
+ _extends(defaults, initialized.defaults);
1011
+ });
1012
+ for (var option in sortable.options) {
1013
+ if (!sortable.options.hasOwnProperty(option)) continue;
1014
+ var modified = this.modifyOption(sortable, option, sortable.options[option]);
1015
+ if (typeof modified !== 'undefined') {
1016
+ sortable.options[option] = modified;
1017
+ }
1018
+ }
1019
+ },
1020
+ getEventProperties: function getEventProperties(name, sortable) {
1021
+ var eventProperties = {};
1022
+ plugins.forEach(function (plugin) {
1023
+ if (typeof plugin.eventProperties !== 'function') return;
1024
+ _extends(eventProperties, plugin.eventProperties.call(sortable[plugin.pluginName], name));
1025
+ });
1026
+ return eventProperties;
1027
+ },
1028
+ modifyOption: function modifyOption(sortable, name, value) {
1029
+ var modifiedValue;
1030
+ plugins.forEach(function (plugin) {
1031
+ // Plugin must exist on the Sortable
1032
+ if (!sortable[plugin.pluginName]) return;
1033
+
1034
+ // If static option listener exists for this option, call in the context of the Sortable's instance of this plugin
1035
+ if (plugin.optionListeners && typeof plugin.optionListeners[name] === 'function') {
1036
+ modifiedValue = plugin.optionListeners[name].call(sortable[plugin.pluginName], value);
1037
+ }
1038
+ });
1039
+ return modifiedValue;
1040
+ }
1041
+ };
1042
+
1043
+ function dispatchEvent(_ref) {
1044
+ var sortable = _ref.sortable,
1045
+ rootEl = _ref.rootEl,
1046
+ name = _ref.name,
1047
+ targetEl = _ref.targetEl,
1048
+ cloneEl = _ref.cloneEl,
1049
+ toEl = _ref.toEl,
1050
+ fromEl = _ref.fromEl,
1051
+ oldIndex = _ref.oldIndex,
1052
+ newIndex = _ref.newIndex,
1053
+ oldDraggableIndex = _ref.oldDraggableIndex,
1054
+ newDraggableIndex = _ref.newDraggableIndex,
1055
+ originalEvent = _ref.originalEvent,
1056
+ putSortable = _ref.putSortable,
1057
+ extraEventProperties = _ref.extraEventProperties;
1058
+ sortable = sortable || rootEl && rootEl[expando];
1059
+ if (!sortable) return;
1060
+ var evt,
1061
+ options = sortable.options,
1062
+ onName = 'on' + name.charAt(0).toUpperCase() + name.substr(1);
1063
+ // Support for new CustomEvent feature
1064
+ if (window.CustomEvent && !IE11OrLess && !Edge) {
1065
+ evt = new CustomEvent(name, {
1066
+ bubbles: true,
1067
+ cancelable: true
1068
+ });
1069
+ } else {
1070
+ evt = document.createEvent('Event');
1071
+ evt.initEvent(name, true, true);
1072
+ }
1073
+ evt.to = toEl || rootEl;
1074
+ evt.from = fromEl || rootEl;
1075
+ evt.item = targetEl || rootEl;
1076
+ evt.clone = cloneEl;
1077
+ evt.oldIndex = oldIndex;
1078
+ evt.newIndex = newIndex;
1079
+ evt.oldDraggableIndex = oldDraggableIndex;
1080
+ evt.newDraggableIndex = newDraggableIndex;
1081
+ evt.originalEvent = originalEvent;
1082
+ evt.pullMode = putSortable ? putSortable.lastPutMode : undefined;
1083
+ var allEventProperties = _objectSpread2(_objectSpread2({}, extraEventProperties), PluginManager.getEventProperties(name, sortable));
1084
+ for (var option in allEventProperties) {
1085
+ evt[option] = allEventProperties[option];
1086
+ }
1087
+ if (rootEl) {
1088
+ rootEl.dispatchEvent(evt);
1089
+ }
1090
+ if (options[onName]) {
1091
+ options[onName].call(sortable, evt);
1092
+ }
1093
+ }
1094
+
1095
+ var _excluded = ["evt"];
1096
+ var pluginEvent = function pluginEvent(eventName, sortable) {
1097
+ var _ref = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {},
1098
+ originalEvent = _ref.evt,
1099
+ data = _objectWithoutProperties(_ref, _excluded);
1100
+ PluginManager.pluginEvent.bind(Sortable)(eventName, sortable, _objectSpread2({
1101
+ dragEl: dragEl,
1102
+ parentEl: parentEl,
1103
+ ghostEl: ghostEl,
1104
+ rootEl: rootEl,
1105
+ nextEl: nextEl,
1106
+ lastDownEl: lastDownEl,
1107
+ cloneEl: cloneEl,
1108
+ cloneHidden: cloneHidden,
1109
+ dragStarted: moved,
1110
+ putSortable: putSortable,
1111
+ activeSortable: Sortable.active,
1112
+ originalEvent: originalEvent,
1113
+ oldIndex: oldIndex,
1114
+ oldDraggableIndex: oldDraggableIndex,
1115
+ newIndex: newIndex,
1116
+ newDraggableIndex: newDraggableIndex,
1117
+ hideGhostForTarget: _hideGhostForTarget,
1118
+ unhideGhostForTarget: _unhideGhostForTarget,
1119
+ cloneNowHidden: function cloneNowHidden() {
1120
+ cloneHidden = true;
1121
+ },
1122
+ cloneNowShown: function cloneNowShown() {
1123
+ cloneHidden = false;
1124
+ },
1125
+ dispatchSortableEvent: function dispatchSortableEvent(name) {
1126
+ _dispatchEvent({
1127
+ sortable: sortable,
1128
+ name: name,
1129
+ originalEvent: originalEvent
1130
+ });
1131
+ }
1132
+ }, data));
1133
+ };
1134
+ function _dispatchEvent(info) {
1135
+ dispatchEvent(_objectSpread2({
1136
+ putSortable: putSortable,
1137
+ cloneEl: cloneEl,
1138
+ targetEl: dragEl,
1139
+ rootEl: rootEl,
1140
+ oldIndex: oldIndex,
1141
+ oldDraggableIndex: oldDraggableIndex,
1142
+ newIndex: newIndex,
1143
+ newDraggableIndex: newDraggableIndex
1144
+ }, info));
1145
+ }
1146
+ var dragEl,
1147
+ parentEl,
1148
+ ghostEl,
1149
+ rootEl,
1150
+ nextEl,
1151
+ lastDownEl,
1152
+ cloneEl,
1153
+ cloneHidden,
1154
+ oldIndex,
1155
+ newIndex,
1156
+ oldDraggableIndex,
1157
+ newDraggableIndex,
1158
+ activeGroup,
1159
+ putSortable,
1160
+ awaitingDragStarted = false,
1161
+ ignoreNextClick = false,
1162
+ sortables = [],
1163
+ tapEvt,
1164
+ touchEvt,
1165
+ lastDx,
1166
+ lastDy,
1167
+ tapDistanceLeft,
1168
+ tapDistanceTop,
1169
+ moved,
1170
+ lastTarget,
1171
+ lastDirection,
1172
+ pastFirstInvertThresh = false,
1173
+ isCircumstantialInvert = false,
1174
+ targetMoveDistance,
1175
+ // For positioning ghost absolutely
1176
+ ghostRelativeParent,
1177
+ ghostRelativeParentInitialScroll = [],
1178
+ // (left, top)
1179
+
1180
+ _silent = false,
1181
+ savedInputChecked = [];
1182
+
1183
+ /** @const */
1184
+ var documentExists = typeof document !== 'undefined',
1185
+ PositionGhostAbsolutely = IOS,
1186
+ CSSFloatProperty = Edge || IE11OrLess ? 'cssFloat' : 'float',
1187
+ // This will not pass for IE9, because IE9 DnD only works on anchors
1188
+ supportDraggable = documentExists && !ChromeForAndroid && !IOS && 'draggable' in document.createElement('div'),
1189
+ supportCssPointerEvents = function () {
1190
+ if (!documentExists) return;
1191
+ // false when <= IE11
1192
+ if (IE11OrLess) {
1193
+ return false;
1194
+ }
1195
+ var el = document.createElement('x');
1196
+ el.style.cssText = 'pointer-events:auto';
1197
+ return el.style.pointerEvents === 'auto';
1198
+ }(),
1199
+ _detectDirection = function _detectDirection(el, options) {
1200
+ var elCSS = css(el),
1201
+ elWidth = parseInt(elCSS.width) - parseInt(elCSS.paddingLeft) - parseInt(elCSS.paddingRight) - parseInt(elCSS.borderLeftWidth) - parseInt(elCSS.borderRightWidth),
1202
+ child1 = getChild(el, 0, options),
1203
+ child2 = getChild(el, 1, options),
1204
+ firstChildCSS = child1 && css(child1),
1205
+ secondChildCSS = child2 && css(child2),
1206
+ firstChildWidth = firstChildCSS && parseInt(firstChildCSS.marginLeft) + parseInt(firstChildCSS.marginRight) + getRect(child1).width,
1207
+ secondChildWidth = secondChildCSS && parseInt(secondChildCSS.marginLeft) + parseInt(secondChildCSS.marginRight) + getRect(child2).width;
1208
+ if (elCSS.display === 'flex') {
1209
+ return elCSS.flexDirection === 'column' || elCSS.flexDirection === 'column-reverse' ? 'vertical' : 'horizontal';
1210
+ }
1211
+ if (elCSS.display === 'grid') {
1212
+ return elCSS.gridTemplateColumns.split(' ').length <= 1 ? 'vertical' : 'horizontal';
1213
+ }
1214
+ if (child1 && firstChildCSS["float"] && firstChildCSS["float"] !== 'none') {
1215
+ var touchingSideChild2 = firstChildCSS["float"] === 'left' ? 'left' : 'right';
1216
+ return child2 && (secondChildCSS.clear === 'both' || secondChildCSS.clear === touchingSideChild2) ? 'vertical' : 'horizontal';
1217
+ }
1218
+ return child1 && (firstChildCSS.display === 'block' || firstChildCSS.display === 'flex' || firstChildCSS.display === 'table' || firstChildCSS.display === 'grid' || firstChildWidth >= elWidth && elCSS[CSSFloatProperty] === 'none' || child2 && elCSS[CSSFloatProperty] === 'none' && firstChildWidth + secondChildWidth > elWidth) ? 'vertical' : 'horizontal';
1219
+ },
1220
+ _dragElInRowColumn = function _dragElInRowColumn(dragRect, targetRect, vertical) {
1221
+ var dragElS1Opp = vertical ? dragRect.left : dragRect.top,
1222
+ dragElS2Opp = vertical ? dragRect.right : dragRect.bottom,
1223
+ dragElOppLength = vertical ? dragRect.width : dragRect.height,
1224
+ targetS1Opp = vertical ? targetRect.left : targetRect.top,
1225
+ targetS2Opp = vertical ? targetRect.right : targetRect.bottom,
1226
+ targetOppLength = vertical ? targetRect.width : targetRect.height;
1227
+ return dragElS1Opp === targetS1Opp || dragElS2Opp === targetS2Opp || dragElS1Opp + dragElOppLength / 2 === targetS1Opp + targetOppLength / 2;
1228
+ },
1229
+ /**
1230
+ * Detects first nearest empty sortable to X and Y position using emptyInsertThreshold.
1231
+ * @param {Number} x X position
1232
+ * @param {Number} y Y position
1233
+ * @return {HTMLElement} Element of the first found nearest Sortable
1234
+ */
1235
+ _detectNearestEmptySortable = function _detectNearestEmptySortable(x, y) {
1236
+ var ret;
1237
+ sortables.some(function (sortable) {
1238
+ var threshold = sortable[expando].options.emptyInsertThreshold;
1239
+ if (!threshold || lastChild(sortable)) return;
1240
+ var rect = getRect(sortable),
1241
+ insideHorizontally = x >= rect.left - threshold && x <= rect.right + threshold,
1242
+ insideVertically = y >= rect.top - threshold && y <= rect.bottom + threshold;
1243
+ if (insideHorizontally && insideVertically) {
1244
+ return ret = sortable;
1245
+ }
1246
+ });
1247
+ return ret;
1248
+ },
1249
+ _prepareGroup = function _prepareGroup(options) {
1250
+ function toFn(value, pull) {
1251
+ return function (to, from, dragEl, evt) {
1252
+ var sameGroup = to.options.group.name && from.options.group.name && to.options.group.name === from.options.group.name;
1253
+ if (value == null && (pull || sameGroup)) {
1254
+ // Default pull value
1255
+ // Default pull and put value if same group
1256
+ return true;
1257
+ } else if (value == null || value === false) {
1258
+ return false;
1259
+ } else if (pull && value === 'clone') {
1260
+ return value;
1261
+ } else if (typeof value === 'function') {
1262
+ return toFn(value(to, from, dragEl, evt), pull)(to, from, dragEl, evt);
1263
+ } else {
1264
+ var otherGroup = (pull ? to : from).options.group.name;
1265
+ return value === true || typeof value === 'string' && value === otherGroup || value.join && value.indexOf(otherGroup) > -1;
1266
+ }
1267
+ };
1268
+ }
1269
+ var group = {};
1270
+ var originalGroup = options.group;
1271
+ if (!originalGroup || _typeof(originalGroup) != 'object') {
1272
+ originalGroup = {
1273
+ name: originalGroup
1274
+ };
1275
+ }
1276
+ group.name = originalGroup.name;
1277
+ group.checkPull = toFn(originalGroup.pull, true);
1278
+ group.checkPut = toFn(originalGroup.put);
1279
+ group.revertClone = originalGroup.revertClone;
1280
+ options.group = group;
1281
+ },
1282
+ _hideGhostForTarget = function _hideGhostForTarget() {
1283
+ if (!supportCssPointerEvents && ghostEl) {
1284
+ css(ghostEl, 'display', 'none');
1285
+ }
1286
+ },
1287
+ _unhideGhostForTarget = function _unhideGhostForTarget() {
1288
+ if (!supportCssPointerEvents && ghostEl) {
1289
+ css(ghostEl, 'display', '');
1290
+ }
1291
+ };
1292
+
1293
+ // #1184 fix - Prevent click event on fallback if dragged but item not changed position
1294
+ if (documentExists && !ChromeForAndroid) {
1295
+ document.addEventListener('click', function (evt) {
1296
+ if (ignoreNextClick) {
1297
+ evt.preventDefault();
1298
+ evt.stopPropagation && evt.stopPropagation();
1299
+ evt.stopImmediatePropagation && evt.stopImmediatePropagation();
1300
+ ignoreNextClick = false;
1301
+ return false;
1302
+ }
1303
+ }, true);
1304
+ }
1305
+ var nearestEmptyInsertDetectEvent = function nearestEmptyInsertDetectEvent(evt) {
1306
+ if (dragEl) {
1307
+ evt = evt.touches ? evt.touches[0] : evt;
1308
+ var nearest = _detectNearestEmptySortable(evt.clientX, evt.clientY);
1309
+ if (nearest) {
1310
+ // Create imitation event
1311
+ var event = {};
1312
+ for (var i in evt) {
1313
+ if (evt.hasOwnProperty(i)) {
1314
+ event[i] = evt[i];
1315
+ }
1316
+ }
1317
+ event.target = event.rootEl = nearest;
1318
+ event.preventDefault = void 0;
1319
+ event.stopPropagation = void 0;
1320
+ nearest[expando]._onDragOver(event);
1321
+ }
1322
+ }
1323
+ };
1324
+ var _checkOutsideTargetEl = function _checkOutsideTargetEl(evt) {
1325
+ if (dragEl) {
1326
+ dragEl.parentNode[expando]._isOutsideThisEl(evt.target);
1327
+ }
1328
+ };
1329
+
1330
+ /**
1331
+ * @class Sortable
1332
+ * @param {HTMLElement} el
1333
+ * @param {Object} [options]
1334
+ */
1335
+ function Sortable(el, options) {
1336
+ if (!(el && el.nodeType && el.nodeType === 1)) {
1337
+ throw "Sortable: `el` must be an HTMLElement, not ".concat({}.toString.call(el));
1338
+ }
1339
+ this.el = el; // root element
1340
+ this.options = options = _extends({}, options);
1341
+
1342
+ // Export instance
1343
+ el[expando] = this;
1344
+ var defaults = {
1345
+ group: null,
1346
+ sort: true,
1347
+ disabled: false,
1348
+ store: null,
1349
+ handle: null,
1350
+ draggable: /^[uo]l$/i.test(el.nodeName) ? '>li' : '>*',
1351
+ swapThreshold: 1,
1352
+ // percentage; 0 <= x <= 1
1353
+ invertSwap: false,
1354
+ // invert always
1355
+ invertedSwapThreshold: null,
1356
+ // will be set to same as swapThreshold if default
1357
+ removeCloneOnHide: true,
1358
+ direction: function direction() {
1359
+ return _detectDirection(el, this.options);
1360
+ },
1361
+ ghostClass: 'sortable-ghost',
1362
+ chosenClass: 'sortable-chosen',
1363
+ dragClass: 'sortable-drag',
1364
+ ignore: 'a, img',
1365
+ filter: null,
1366
+ preventOnFilter: true,
1367
+ animation: 0,
1368
+ easing: null,
1369
+ setData: function setData(dataTransfer, dragEl) {
1370
+ dataTransfer.setData('Text', dragEl.textContent);
1371
+ },
1372
+ dropBubble: false,
1373
+ dragoverBubble: false,
1374
+ dataIdAttr: 'data-id',
1375
+ delay: 0,
1376
+ delayOnTouchOnly: false,
1377
+ touchStartThreshold: (Number.parseInt ? Number : window).parseInt(window.devicePixelRatio, 10) || 1,
1378
+ forceFallback: false,
1379
+ fallbackClass: 'sortable-fallback',
1380
+ fallbackOnBody: false,
1381
+ fallbackTolerance: 0,
1382
+ fallbackOffset: {
1383
+ x: 0,
1384
+ y: 0
1385
+ },
1386
+ // Disabled on Safari: #1571; Enabled on Safari IOS: #2244
1387
+ supportPointer: Sortable.supportPointer !== false && 'PointerEvent' in window && (!Safari || IOS),
1388
+ emptyInsertThreshold: 5
1389
+ };
1390
+ PluginManager.initializePlugins(this, el, defaults);
1391
+
1392
+ // Set default options
1393
+ for (var name in defaults) {
1394
+ !(name in options) && (options[name] = defaults[name]);
1395
+ }
1396
+ _prepareGroup(options);
1397
+
1398
+ // Bind all private methods
1399
+ for (var fn in this) {
1400
+ if (fn.charAt(0) === '_' && typeof this[fn] === 'function') {
1401
+ this[fn] = this[fn].bind(this);
1402
+ }
1403
+ }
1404
+
1405
+ // Setup drag mode
1406
+ this.nativeDraggable = options.forceFallback ? false : supportDraggable;
1407
+ if (this.nativeDraggable) {
1408
+ // Touch start threshold cannot be greater than the native dragstart threshold
1409
+ this.options.touchStartThreshold = 1;
1410
+ }
1411
+
1412
+ // Bind events
1413
+ if (options.supportPointer) {
1414
+ on(el, 'pointerdown', this._onTapStart);
1415
+ } else {
1416
+ on(el, 'mousedown', this._onTapStart);
1417
+ on(el, 'touchstart', this._onTapStart);
1418
+ }
1419
+ if (this.nativeDraggable) {
1420
+ on(el, 'dragover', this);
1421
+ on(el, 'dragenter', this);
1422
+ }
1423
+ sortables.push(this.el);
1424
+
1425
+ // Restore sorting
1426
+ options.store && options.store.get && this.sort(options.store.get(this) || []);
1427
+
1428
+ // Add animation state manager
1429
+ _extends(this, AnimationStateManager());
1430
+ }
1431
+ Sortable.prototype = /** @lends Sortable.prototype */{
1432
+ constructor: Sortable,
1433
+ _isOutsideThisEl: function _isOutsideThisEl(target) {
1434
+ if (!this.el.contains(target) && target !== this.el) {
1435
+ lastTarget = null;
1436
+ }
1437
+ },
1438
+ _getDirection: function _getDirection(evt, target) {
1439
+ return typeof this.options.direction === 'function' ? this.options.direction.call(this, evt, target, dragEl) : this.options.direction;
1440
+ },
1441
+ _onTapStart: function _onTapStart( /** Event|TouchEvent */evt) {
1442
+ if (!evt.cancelable) return;
1443
+ var _this = this,
1444
+ el = this.el,
1445
+ options = this.options,
1446
+ preventOnFilter = options.preventOnFilter,
1447
+ type = evt.type,
1448
+ touch = evt.touches && evt.touches[0] || evt.pointerType && evt.pointerType === 'touch' && evt,
1449
+ target = (touch || evt).target,
1450
+ originalTarget = evt.target.shadowRoot && (evt.path && evt.path[0] || evt.composedPath && evt.composedPath()[0]) || target,
1451
+ filter = options.filter;
1452
+ _saveInputCheckedState(el);
1453
+
1454
+ // Don't trigger start event when an element is been dragged, otherwise the evt.oldindex always wrong when set option.group.
1455
+ if (dragEl) {
1456
+ return;
1457
+ }
1458
+ if (/mousedown|pointerdown/.test(type) && evt.button !== 0 || options.disabled) {
1459
+ return; // only left button and enabled
1460
+ }
1461
+
1462
+ // cancel dnd if original target is content editable
1463
+ if (originalTarget.isContentEditable) {
1464
+ return;
1465
+ }
1466
+
1467
+ // Safari ignores further event handling after mousedown
1468
+ if (!this.nativeDraggable && Safari && target && target.tagName.toUpperCase() === 'SELECT') {
1469
+ return;
1470
+ }
1471
+ target = closest(target, options.draggable, el, false);
1472
+ if (target && target.animated) {
1473
+ return;
1474
+ }
1475
+ if (lastDownEl === target) {
1476
+ // Ignoring duplicate `down`
1477
+ return;
1478
+ }
1479
+
1480
+ // Get the index of the dragged element within its parent
1481
+ oldIndex = index(target);
1482
+ oldDraggableIndex = index(target, options.draggable);
1483
+
1484
+ // Check filter
1485
+ if (typeof filter === 'function') {
1486
+ if (filter.call(this, evt, target, this)) {
1487
+ _dispatchEvent({
1488
+ sortable: _this,
1489
+ rootEl: originalTarget,
1490
+ name: 'filter',
1491
+ targetEl: target,
1492
+ toEl: el,
1493
+ fromEl: el
1494
+ });
1495
+ pluginEvent('filter', _this, {
1496
+ evt: evt
1497
+ });
1498
+ preventOnFilter && evt.preventDefault();
1499
+ return; // cancel dnd
1500
+ }
1501
+ } else if (filter) {
1502
+ filter = filter.split(',').some(function (criteria) {
1503
+ criteria = closest(originalTarget, criteria.trim(), el, false);
1504
+ if (criteria) {
1505
+ _dispatchEvent({
1506
+ sortable: _this,
1507
+ rootEl: criteria,
1508
+ name: 'filter',
1509
+ targetEl: target,
1510
+ fromEl: el,
1511
+ toEl: el
1512
+ });
1513
+ pluginEvent('filter', _this, {
1514
+ evt: evt
1515
+ });
1516
+ return true;
1517
+ }
1518
+ });
1519
+ if (filter) {
1520
+ preventOnFilter && evt.preventDefault();
1521
+ return; // cancel dnd
1522
+ }
1523
+ }
1524
+ if (options.handle && !closest(originalTarget, options.handle, el, false)) {
1525
+ return;
1526
+ }
1527
+
1528
+ // Prepare `dragstart`
1529
+ this._prepareDragStart(evt, touch, target);
1530
+ },
1531
+ _prepareDragStart: function _prepareDragStart( /** Event */evt, /** Touch */touch, /** HTMLElement */target) {
1532
+ var _this = this,
1533
+ el = _this.el,
1534
+ options = _this.options,
1535
+ ownerDocument = el.ownerDocument,
1536
+ dragStartFn;
1537
+ if (target && !dragEl && target.parentNode === el) {
1538
+ var dragRect = getRect(target);
1539
+ rootEl = el;
1540
+ dragEl = target;
1541
+ parentEl = dragEl.parentNode;
1542
+ nextEl = dragEl.nextSibling;
1543
+ lastDownEl = target;
1544
+ activeGroup = options.group;
1545
+ Sortable.dragged = dragEl;
1546
+ tapEvt = {
1547
+ target: dragEl,
1548
+ clientX: (touch || evt).clientX,
1549
+ clientY: (touch || evt).clientY
1550
+ };
1551
+ tapDistanceLeft = tapEvt.clientX - dragRect.left;
1552
+ tapDistanceTop = tapEvt.clientY - dragRect.top;
1553
+ this._lastX = (touch || evt).clientX;
1554
+ this._lastY = (touch || evt).clientY;
1555
+ dragEl.style['will-change'] = 'all';
1556
+ dragStartFn = function dragStartFn() {
1557
+ pluginEvent('delayEnded', _this, {
1558
+ evt: evt
1559
+ });
1560
+ if (Sortable.eventCanceled) {
1561
+ _this._onDrop();
1562
+ return;
1563
+ }
1564
+ // Delayed drag has been triggered
1565
+ // we can re-enable the events: touchmove/mousemove
1566
+ _this._disableDelayedDragEvents();
1567
+ if (!FireFox && _this.nativeDraggable) {
1568
+ dragEl.draggable = true;
1569
+ }
1570
+
1571
+ // Bind the events: dragstart/dragend
1572
+ _this._triggerDragStart(evt, touch);
1573
+
1574
+ // Drag start event
1575
+ _dispatchEvent({
1576
+ sortable: _this,
1577
+ name: 'choose',
1578
+ originalEvent: evt
1579
+ });
1580
+
1581
+ // Chosen item
1582
+ toggleClass(dragEl, options.chosenClass, true);
1583
+ };
1584
+
1585
+ // Disable "draggable"
1586
+ options.ignore.split(',').forEach(function (criteria) {
1587
+ find(dragEl, criteria.trim(), _disableDraggable);
1588
+ });
1589
+ on(ownerDocument, 'dragover', nearestEmptyInsertDetectEvent);
1590
+ on(ownerDocument, 'mousemove', nearestEmptyInsertDetectEvent);
1591
+ on(ownerDocument, 'touchmove', nearestEmptyInsertDetectEvent);
1592
+ if (options.supportPointer) {
1593
+ on(ownerDocument, 'pointerup', _this._onDrop);
1594
+ // Native D&D triggers pointercancel
1595
+ !this.nativeDraggable && on(ownerDocument, 'pointercancel', _this._onDrop);
1596
+ } else {
1597
+ on(ownerDocument, 'mouseup', _this._onDrop);
1598
+ on(ownerDocument, 'touchend', _this._onDrop);
1599
+ on(ownerDocument, 'touchcancel', _this._onDrop);
1600
+ }
1601
+
1602
+ // Make dragEl draggable (must be before delay for FireFox)
1603
+ if (FireFox && this.nativeDraggable) {
1604
+ this.options.touchStartThreshold = 4;
1605
+ dragEl.draggable = true;
1606
+ }
1607
+ pluginEvent('delayStart', this, {
1608
+ evt: evt
1609
+ });
1610
+
1611
+ // Delay is impossible for native DnD in Edge or IE
1612
+ if (options.delay && (!options.delayOnTouchOnly || touch) && (!this.nativeDraggable || !(Edge || IE11OrLess))) {
1613
+ if (Sortable.eventCanceled) {
1614
+ this._onDrop();
1615
+ return;
1616
+ }
1617
+ // If the user moves the pointer or let go the click or touch
1618
+ // before the delay has been reached:
1619
+ // disable the delayed drag
1620
+ if (options.supportPointer) {
1621
+ on(ownerDocument, 'pointerup', _this._disableDelayedDrag);
1622
+ on(ownerDocument, 'pointercancel', _this._disableDelayedDrag);
1623
+ } else {
1624
+ on(ownerDocument, 'mouseup', _this._disableDelayedDrag);
1625
+ on(ownerDocument, 'touchend', _this._disableDelayedDrag);
1626
+ on(ownerDocument, 'touchcancel', _this._disableDelayedDrag);
1627
+ }
1628
+ on(ownerDocument, 'mousemove', _this._delayedDragTouchMoveHandler);
1629
+ on(ownerDocument, 'touchmove', _this._delayedDragTouchMoveHandler);
1630
+ options.supportPointer && on(ownerDocument, 'pointermove', _this._delayedDragTouchMoveHandler);
1631
+ _this._dragStartTimer = setTimeout(dragStartFn, options.delay);
1632
+ } else {
1633
+ dragStartFn();
1634
+ }
1635
+ }
1636
+ },
1637
+ _delayedDragTouchMoveHandler: function _delayedDragTouchMoveHandler( /** TouchEvent|PointerEvent **/e) {
1638
+ var touch = e.touches ? e.touches[0] : e;
1639
+ if (Math.max(Math.abs(touch.clientX - this._lastX), Math.abs(touch.clientY - this._lastY)) >= Math.floor(this.options.touchStartThreshold / (this.nativeDraggable && window.devicePixelRatio || 1))) {
1640
+ this._disableDelayedDrag();
1641
+ }
1642
+ },
1643
+ _disableDelayedDrag: function _disableDelayedDrag() {
1644
+ dragEl && _disableDraggable(dragEl);
1645
+ clearTimeout(this._dragStartTimer);
1646
+ this._disableDelayedDragEvents();
1647
+ },
1648
+ _disableDelayedDragEvents: function _disableDelayedDragEvents() {
1649
+ var ownerDocument = this.el.ownerDocument;
1650
+ off(ownerDocument, 'mouseup', this._disableDelayedDrag);
1651
+ off(ownerDocument, 'touchend', this._disableDelayedDrag);
1652
+ off(ownerDocument, 'touchcancel', this._disableDelayedDrag);
1653
+ off(ownerDocument, 'pointerup', this._disableDelayedDrag);
1654
+ off(ownerDocument, 'pointercancel', this._disableDelayedDrag);
1655
+ off(ownerDocument, 'mousemove', this._delayedDragTouchMoveHandler);
1656
+ off(ownerDocument, 'touchmove', this._delayedDragTouchMoveHandler);
1657
+ off(ownerDocument, 'pointermove', this._delayedDragTouchMoveHandler);
1658
+ },
1659
+ _triggerDragStart: function _triggerDragStart( /** Event */evt, /** Touch */touch) {
1660
+ touch = touch || evt.pointerType == 'touch' && evt;
1661
+ if (!this.nativeDraggable || touch) {
1662
+ if (this.options.supportPointer) {
1663
+ on(document, 'pointermove', this._onTouchMove);
1664
+ } else if (touch) {
1665
+ on(document, 'touchmove', this._onTouchMove);
1666
+ } else {
1667
+ on(document, 'mousemove', this._onTouchMove);
1668
+ }
1669
+ } else {
1670
+ on(dragEl, 'dragend', this);
1671
+ on(rootEl, 'dragstart', this._onDragStart);
1672
+ }
1673
+ try {
1674
+ if (document.selection) {
1675
+ _nextTick(function () {
1676
+ document.selection.empty();
1677
+ });
1678
+ } else {
1679
+ window.getSelection().removeAllRanges();
1680
+ }
1681
+ } catch (err) {}
1682
+ },
1683
+ _dragStarted: function _dragStarted(fallback, evt) {
1684
+ awaitingDragStarted = false;
1685
+ if (rootEl && dragEl) {
1686
+ pluginEvent('dragStarted', this, {
1687
+ evt: evt
1688
+ });
1689
+ if (this.nativeDraggable) {
1690
+ on(document, 'dragover', _checkOutsideTargetEl);
1691
+ }
1692
+ var options = this.options;
1693
+
1694
+ // Apply effect
1695
+ !fallback && toggleClass(dragEl, options.dragClass, false);
1696
+ toggleClass(dragEl, options.ghostClass, true);
1697
+ Sortable.active = this;
1698
+ fallback && this._appendGhost();
1699
+
1700
+ // Drag start event
1701
+ _dispatchEvent({
1702
+ sortable: this,
1703
+ name: 'start',
1704
+ originalEvent: evt
1705
+ });
1706
+ } else {
1707
+ this._nulling();
1708
+ }
1709
+ },
1710
+ _emulateDragOver: function _emulateDragOver() {
1711
+ if (touchEvt) {
1712
+ this._lastX = touchEvt.clientX;
1713
+ this._lastY = touchEvt.clientY;
1714
+ _hideGhostForTarget();
1715
+ var target = document.elementFromPoint(touchEvt.clientX, touchEvt.clientY);
1716
+ var parent = target;
1717
+ while (target && target.shadowRoot) {
1718
+ target = target.shadowRoot.elementFromPoint(touchEvt.clientX, touchEvt.clientY);
1719
+ if (target === parent) break;
1720
+ parent = target;
1721
+ }
1722
+ dragEl.parentNode[expando]._isOutsideThisEl(target);
1723
+ if (parent) {
1724
+ do {
1725
+ if (parent[expando]) {
1726
+ var inserted = void 0;
1727
+ inserted = parent[expando]._onDragOver({
1728
+ clientX: touchEvt.clientX,
1729
+ clientY: touchEvt.clientY,
1730
+ target: target,
1731
+ rootEl: parent
1732
+ });
1733
+ if (inserted && !this.options.dragoverBubble) {
1734
+ break;
1735
+ }
1736
+ }
1737
+ target = parent; // store last element
1738
+ }
1739
+ /* jshint boss:true */ while (parent = getParentOrHost(parent));
1740
+ }
1741
+ _unhideGhostForTarget();
1742
+ }
1743
+ },
1744
+ _onTouchMove: function _onTouchMove( /**TouchEvent*/evt) {
1745
+ if (tapEvt) {
1746
+ var options = this.options,
1747
+ fallbackTolerance = options.fallbackTolerance,
1748
+ fallbackOffset = options.fallbackOffset,
1749
+ touch = evt.touches ? evt.touches[0] : evt,
1750
+ ghostMatrix = ghostEl && matrix(ghostEl, true),
1751
+ scaleX = ghostEl && ghostMatrix && ghostMatrix.a,
1752
+ scaleY = ghostEl && ghostMatrix && ghostMatrix.d,
1753
+ relativeScrollOffset = PositionGhostAbsolutely && ghostRelativeParent && getRelativeScrollOffset(ghostRelativeParent),
1754
+ dx = (touch.clientX - tapEvt.clientX + fallbackOffset.x) / (scaleX || 1) + (relativeScrollOffset ? relativeScrollOffset[0] - ghostRelativeParentInitialScroll[0] : 0) / (scaleX || 1),
1755
+ dy = (touch.clientY - tapEvt.clientY + fallbackOffset.y) / (scaleY || 1) + (relativeScrollOffset ? relativeScrollOffset[1] - ghostRelativeParentInitialScroll[1] : 0) / (scaleY || 1);
1756
+
1757
+ // only set the status to dragging, when we are actually dragging
1758
+ if (!Sortable.active && !awaitingDragStarted) {
1759
+ if (fallbackTolerance && Math.max(Math.abs(touch.clientX - this._lastX), Math.abs(touch.clientY - this._lastY)) < fallbackTolerance) {
1760
+ return;
1761
+ }
1762
+ this._onDragStart(evt, true);
1763
+ }
1764
+ if (ghostEl) {
1765
+ if (ghostMatrix) {
1766
+ ghostMatrix.e += dx - (lastDx || 0);
1767
+ ghostMatrix.f += dy - (lastDy || 0);
1768
+ } else {
1769
+ ghostMatrix = {
1770
+ a: 1,
1771
+ b: 0,
1772
+ c: 0,
1773
+ d: 1,
1774
+ e: dx,
1775
+ f: dy
1776
+ };
1777
+ }
1778
+ var cssMatrix = "matrix(".concat(ghostMatrix.a, ",").concat(ghostMatrix.b, ",").concat(ghostMatrix.c, ",").concat(ghostMatrix.d, ",").concat(ghostMatrix.e, ",").concat(ghostMatrix.f, ")");
1779
+ css(ghostEl, 'webkitTransform', cssMatrix);
1780
+ css(ghostEl, 'mozTransform', cssMatrix);
1781
+ css(ghostEl, 'msTransform', cssMatrix);
1782
+ css(ghostEl, 'transform', cssMatrix);
1783
+ lastDx = dx;
1784
+ lastDy = dy;
1785
+ touchEvt = touch;
1786
+ }
1787
+ evt.cancelable && evt.preventDefault();
1788
+ }
1789
+ },
1790
+ _appendGhost: function _appendGhost() {
1791
+ // Bug if using scale(): https://stackoverflow.com/questions/2637058
1792
+ // Not being adjusted for
1793
+ if (!ghostEl) {
1794
+ var container = this.options.fallbackOnBody ? document.body : rootEl,
1795
+ rect = getRect(dragEl, true, PositionGhostAbsolutely, true, container),
1796
+ options = this.options;
1797
+
1798
+ // Position absolutely
1799
+ if (PositionGhostAbsolutely) {
1800
+ // Get relatively positioned parent
1801
+ ghostRelativeParent = container;
1802
+ while (css(ghostRelativeParent, 'position') === 'static' && css(ghostRelativeParent, 'transform') === 'none' && ghostRelativeParent !== document) {
1803
+ ghostRelativeParent = ghostRelativeParent.parentNode;
1804
+ }
1805
+ if (ghostRelativeParent !== document.body && ghostRelativeParent !== document.documentElement) {
1806
+ if (ghostRelativeParent === document) ghostRelativeParent = getWindowScrollingElement();
1807
+ rect.top += ghostRelativeParent.scrollTop;
1808
+ rect.left += ghostRelativeParent.scrollLeft;
1809
+ } else {
1810
+ ghostRelativeParent = getWindowScrollingElement();
1811
+ }
1812
+ ghostRelativeParentInitialScroll = getRelativeScrollOffset(ghostRelativeParent);
1813
+ }
1814
+ ghostEl = dragEl.cloneNode(true);
1815
+ toggleClass(ghostEl, options.ghostClass, false);
1816
+ toggleClass(ghostEl, options.fallbackClass, true);
1817
+ toggleClass(ghostEl, options.dragClass, true);
1818
+ css(ghostEl, 'transition', '');
1819
+ css(ghostEl, 'transform', '');
1820
+ css(ghostEl, 'box-sizing', 'border-box');
1821
+ css(ghostEl, 'margin', 0);
1822
+ css(ghostEl, 'top', rect.top);
1823
+ css(ghostEl, 'left', rect.left);
1824
+ css(ghostEl, 'width', rect.width);
1825
+ css(ghostEl, 'height', rect.height);
1826
+ css(ghostEl, 'opacity', '0.8');
1827
+ css(ghostEl, 'position', PositionGhostAbsolutely ? 'absolute' : 'fixed');
1828
+ css(ghostEl, 'zIndex', '100000');
1829
+ css(ghostEl, 'pointerEvents', 'none');
1830
+ Sortable.ghost = ghostEl;
1831
+ container.appendChild(ghostEl);
1832
+
1833
+ // Set transform-origin
1834
+ css(ghostEl, 'transform-origin', tapDistanceLeft / parseInt(ghostEl.style.width) * 100 + '% ' + tapDistanceTop / parseInt(ghostEl.style.height) * 100 + '%');
1835
+ }
1836
+ },
1837
+ _onDragStart: function _onDragStart( /**Event*/evt, /**boolean*/fallback) {
1838
+ var _this = this;
1839
+ var dataTransfer = evt.dataTransfer;
1840
+ var options = _this.options;
1841
+ pluginEvent('dragStart', this, {
1842
+ evt: evt
1843
+ });
1844
+ if (Sortable.eventCanceled) {
1845
+ this._onDrop();
1846
+ return;
1847
+ }
1848
+ pluginEvent('setupClone', this);
1849
+ if (!Sortable.eventCanceled) {
1850
+ cloneEl = clone(dragEl);
1851
+ cloneEl.removeAttribute("id");
1852
+ cloneEl.draggable = false;
1853
+ cloneEl.style['will-change'] = '';
1854
+ this._hideClone();
1855
+ toggleClass(cloneEl, this.options.chosenClass, false);
1856
+ Sortable.clone = cloneEl;
1857
+ }
1858
+
1859
+ // #1143: IFrame support workaround
1860
+ _this.cloneId = _nextTick(function () {
1861
+ pluginEvent('clone', _this);
1862
+ if (Sortable.eventCanceled) return;
1863
+ if (!_this.options.removeCloneOnHide) {
1864
+ rootEl.insertBefore(cloneEl, dragEl);
1865
+ }
1866
+ _this._hideClone();
1867
+ _dispatchEvent({
1868
+ sortable: _this,
1869
+ name: 'clone'
1870
+ });
1871
+ });
1872
+ !fallback && toggleClass(dragEl, options.dragClass, true);
1873
+
1874
+ // Set proper drop events
1875
+ if (fallback) {
1876
+ ignoreNextClick = true;
1877
+ _this._loopId = setInterval(_this._emulateDragOver, 50);
1878
+ } else {
1879
+ // Undo what was set in _prepareDragStart before drag started
1880
+ off(document, 'mouseup', _this._onDrop);
1881
+ off(document, 'touchend', _this._onDrop);
1882
+ off(document, 'touchcancel', _this._onDrop);
1883
+ if (dataTransfer) {
1884
+ dataTransfer.effectAllowed = 'move';
1885
+ options.setData && options.setData.call(_this, dataTransfer, dragEl);
1886
+ }
1887
+ on(document, 'drop', _this);
1888
+
1889
+ // #1276 fix:
1890
+ css(dragEl, 'transform', 'translateZ(0)');
1891
+ }
1892
+ awaitingDragStarted = true;
1893
+ _this._dragStartId = _nextTick(_this._dragStarted.bind(_this, fallback, evt));
1894
+ on(document, 'selectstart', _this);
1895
+ moved = true;
1896
+ window.getSelection().removeAllRanges();
1897
+ if (Safari) {
1898
+ css(document.body, 'user-select', 'none');
1899
+ }
1900
+ },
1901
+ // Returns true - if no further action is needed (either inserted or another condition)
1902
+ _onDragOver: function _onDragOver( /**Event*/evt) {
1903
+ var el = this.el,
1904
+ target = evt.target,
1905
+ dragRect,
1906
+ targetRect,
1907
+ revert,
1908
+ options = this.options,
1909
+ group = options.group,
1910
+ activeSortable = Sortable.active,
1911
+ isOwner = activeGroup === group,
1912
+ canSort = options.sort,
1913
+ fromSortable = putSortable || activeSortable,
1914
+ vertical,
1915
+ _this = this,
1916
+ completedFired = false;
1917
+ if (_silent) return;
1918
+ function dragOverEvent(name, extra) {
1919
+ pluginEvent(name, _this, _objectSpread2({
1920
+ evt: evt,
1921
+ isOwner: isOwner,
1922
+ axis: vertical ? 'vertical' : 'horizontal',
1923
+ revert: revert,
1924
+ dragRect: dragRect,
1925
+ targetRect: targetRect,
1926
+ canSort: canSort,
1927
+ fromSortable: fromSortable,
1928
+ target: target,
1929
+ completed: completed,
1930
+ onMove: function onMove(target, after) {
1931
+ return _onMove(rootEl, el, dragEl, dragRect, target, getRect(target), evt, after);
1932
+ },
1933
+ changed: changed
1934
+ }, extra));
1935
+ }
1936
+
1937
+ // Capture animation state
1938
+ function capture() {
1939
+ dragOverEvent('dragOverAnimationCapture');
1940
+ _this.captureAnimationState();
1941
+ if (_this !== fromSortable) {
1942
+ fromSortable.captureAnimationState();
1943
+ }
1944
+ }
1945
+
1946
+ // Return invocation when dragEl is inserted (or completed)
1947
+ function completed(insertion) {
1948
+ dragOverEvent('dragOverCompleted', {
1949
+ insertion: insertion
1950
+ });
1951
+ if (insertion) {
1952
+ // Clones must be hidden before folding animation to capture dragRectAbsolute properly
1953
+ if (isOwner) {
1954
+ activeSortable._hideClone();
1955
+ } else {
1956
+ activeSortable._showClone(_this);
1957
+ }
1958
+ if (_this !== fromSortable) {
1959
+ // Set ghost class to new sortable's ghost class
1960
+ toggleClass(dragEl, putSortable ? putSortable.options.ghostClass : activeSortable.options.ghostClass, false);
1961
+ toggleClass(dragEl, options.ghostClass, true);
1962
+ }
1963
+ if (putSortable !== _this && _this !== Sortable.active) {
1964
+ putSortable = _this;
1965
+ } else if (_this === Sortable.active && putSortable) {
1966
+ putSortable = null;
1967
+ }
1968
+
1969
+ // Animation
1970
+ if (fromSortable === _this) {
1971
+ _this._ignoreWhileAnimating = target;
1972
+ }
1973
+ _this.animateAll(function () {
1974
+ dragOverEvent('dragOverAnimationComplete');
1975
+ _this._ignoreWhileAnimating = null;
1976
+ });
1977
+ if (_this !== fromSortable) {
1978
+ fromSortable.animateAll();
1979
+ fromSortable._ignoreWhileAnimating = null;
1980
+ }
1981
+ }
1982
+
1983
+ // Null lastTarget if it is not inside a previously swapped element
1984
+ if (target === dragEl && !dragEl.animated || target === el && !target.animated) {
1985
+ lastTarget = null;
1986
+ }
1987
+
1988
+ // no bubbling and not fallback
1989
+ if (!options.dragoverBubble && !evt.rootEl && target !== document) {
1990
+ dragEl.parentNode[expando]._isOutsideThisEl(evt.target);
1991
+
1992
+ // Do not detect for empty insert if already inserted
1993
+ !insertion && nearestEmptyInsertDetectEvent(evt);
1994
+ }
1995
+ !options.dragoverBubble && evt.stopPropagation && evt.stopPropagation();
1996
+ return completedFired = true;
1997
+ }
1998
+
1999
+ // Call when dragEl has been inserted
2000
+ function changed() {
2001
+ newIndex = index(dragEl);
2002
+ newDraggableIndex = index(dragEl, options.draggable);
2003
+ _dispatchEvent({
2004
+ sortable: _this,
2005
+ name: 'change',
2006
+ toEl: el,
2007
+ newIndex: newIndex,
2008
+ newDraggableIndex: newDraggableIndex,
2009
+ originalEvent: evt
2010
+ });
2011
+ }
2012
+ if (evt.preventDefault !== void 0) {
2013
+ evt.cancelable && evt.preventDefault();
2014
+ }
2015
+ target = closest(target, options.draggable, el, true);
2016
+ dragOverEvent('dragOver');
2017
+ if (Sortable.eventCanceled) return completedFired;
2018
+ if (dragEl.contains(evt.target) || target.animated && target.animatingX && target.animatingY || _this._ignoreWhileAnimating === target) {
2019
+ return completed(false);
2020
+ }
2021
+ ignoreNextClick = false;
2022
+ if (activeSortable && !options.disabled && (isOwner ? canSort || (revert = parentEl !== rootEl) // Reverting item into the original list
2023
+ : putSortable === this || (this.lastPutMode = activeGroup.checkPull(this, activeSortable, dragEl, evt)) && group.checkPut(this, activeSortable, dragEl, evt))) {
2024
+ vertical = this._getDirection(evt, target) === 'vertical';
2025
+ dragRect = getRect(dragEl);
2026
+ dragOverEvent('dragOverValid');
2027
+ if (Sortable.eventCanceled) return completedFired;
2028
+ if (revert) {
2029
+ parentEl = rootEl; // actualization
2030
+ capture();
2031
+ this._hideClone();
2032
+ dragOverEvent('revert');
2033
+ if (!Sortable.eventCanceled) {
2034
+ if (nextEl) {
2035
+ rootEl.insertBefore(dragEl, nextEl);
2036
+ } else {
2037
+ rootEl.appendChild(dragEl);
2038
+ }
2039
+ }
2040
+ return completed(true);
2041
+ }
2042
+ var elLastChild = lastChild(el, options.draggable);
2043
+ if (!elLastChild || _ghostIsLast(evt, vertical, this) && !elLastChild.animated) {
2044
+ // Insert to end of list
2045
+
2046
+ // If already at end of list: Do not insert
2047
+ if (elLastChild === dragEl) {
2048
+ return completed(false);
2049
+ }
2050
+
2051
+ // if there is a last element, it is the target
2052
+ if (elLastChild && el === evt.target) {
2053
+ target = elLastChild;
2054
+ }
2055
+ if (target) {
2056
+ targetRect = getRect(target);
2057
+ }
2058
+ if (_onMove(rootEl, el, dragEl, dragRect, target, targetRect, evt, !!target) !== false) {
2059
+ capture();
2060
+ if (elLastChild && elLastChild.nextSibling) {
2061
+ // the last draggable element is not the last node
2062
+ el.insertBefore(dragEl, elLastChild.nextSibling);
2063
+ } else {
2064
+ el.appendChild(dragEl);
2065
+ }
2066
+ parentEl = el; // actualization
2067
+
2068
+ changed();
2069
+ return completed(true);
2070
+ }
2071
+ } else if (elLastChild && _ghostIsFirst(evt, vertical, this)) {
2072
+ // Insert to start of list
2073
+ var firstChild = getChild(el, 0, options, true);
2074
+ if (firstChild === dragEl) {
2075
+ return completed(false);
2076
+ }
2077
+ target = firstChild;
2078
+ targetRect = getRect(target);
2079
+ if (_onMove(rootEl, el, dragEl, dragRect, target, targetRect, evt, false) !== false) {
2080
+ capture();
2081
+ el.insertBefore(dragEl, firstChild);
2082
+ parentEl = el; // actualization
2083
+
2084
+ changed();
2085
+ return completed(true);
2086
+ }
2087
+ } else if (target.parentNode === el) {
2088
+ targetRect = getRect(target);
2089
+ var direction = 0,
2090
+ targetBeforeFirstSwap,
2091
+ differentLevel = dragEl.parentNode !== el,
2092
+ differentRowCol = !_dragElInRowColumn(dragEl.animated && dragEl.toRect || dragRect, target.animated && target.toRect || targetRect, vertical),
2093
+ side1 = vertical ? 'top' : 'left',
2094
+ scrolledPastTop = isScrolledPast(target, 'top', 'top') || isScrolledPast(dragEl, 'top', 'top'),
2095
+ scrollBefore = scrolledPastTop ? scrolledPastTop.scrollTop : void 0;
2096
+ if (lastTarget !== target) {
2097
+ targetBeforeFirstSwap = targetRect[side1];
2098
+ pastFirstInvertThresh = false;
2099
+ isCircumstantialInvert = !differentRowCol && options.invertSwap || differentLevel;
2100
+ }
2101
+ direction = _getSwapDirection(evt, target, targetRect, vertical, differentRowCol ? 1 : options.swapThreshold, options.invertedSwapThreshold == null ? options.swapThreshold : options.invertedSwapThreshold, isCircumstantialInvert, lastTarget === target);
2102
+ var sibling;
2103
+ if (direction !== 0) {
2104
+ // Check if target is beside dragEl in respective direction (ignoring hidden elements)
2105
+ var dragIndex = index(dragEl);
2106
+ do {
2107
+ dragIndex -= direction;
2108
+ sibling = parentEl.children[dragIndex];
2109
+ } while (sibling && (css(sibling, 'display') === 'none' || sibling === ghostEl));
2110
+ }
2111
+ // If dragEl is already beside target: Do not insert
2112
+ if (direction === 0 || sibling === target) {
2113
+ return completed(false);
2114
+ }
2115
+ lastTarget = target;
2116
+ lastDirection = direction;
2117
+ var nextSibling = target.nextElementSibling,
2118
+ after = false;
2119
+ after = direction === 1;
2120
+ var moveVector = _onMove(rootEl, el, dragEl, dragRect, target, targetRect, evt, after);
2121
+ if (moveVector !== false) {
2122
+ if (moveVector === 1 || moveVector === -1) {
2123
+ after = moveVector === 1;
2124
+ }
2125
+ _silent = true;
2126
+ setTimeout(_unsilent, 30);
2127
+ capture();
2128
+ if (after && !nextSibling) {
2129
+ el.appendChild(dragEl);
2130
+ } else {
2131
+ target.parentNode.insertBefore(dragEl, after ? nextSibling : target);
2132
+ }
2133
+
2134
+ // Undo chrome's scroll adjustment (has no effect on other browsers)
2135
+ if (scrolledPastTop) {
2136
+ scrollBy(scrolledPastTop, 0, scrollBefore - scrolledPastTop.scrollTop);
2137
+ }
2138
+ parentEl = dragEl.parentNode; // actualization
2139
+
2140
+ // must be done before animation
2141
+ if (targetBeforeFirstSwap !== undefined && !isCircumstantialInvert) {
2142
+ targetMoveDistance = Math.abs(targetBeforeFirstSwap - getRect(target)[side1]);
2143
+ }
2144
+ changed();
2145
+ return completed(true);
2146
+ }
2147
+ }
2148
+ if (el.contains(dragEl)) {
2149
+ return completed(false);
2150
+ }
2151
+ }
2152
+ return false;
2153
+ },
2154
+ _ignoreWhileAnimating: null,
2155
+ _offMoveEvents: function _offMoveEvents() {
2156
+ off(document, 'mousemove', this._onTouchMove);
2157
+ off(document, 'touchmove', this._onTouchMove);
2158
+ off(document, 'pointermove', this._onTouchMove);
2159
+ off(document, 'dragover', nearestEmptyInsertDetectEvent);
2160
+ off(document, 'mousemove', nearestEmptyInsertDetectEvent);
2161
+ off(document, 'touchmove', nearestEmptyInsertDetectEvent);
2162
+ },
2163
+ _offUpEvents: function _offUpEvents() {
2164
+ var ownerDocument = this.el.ownerDocument;
2165
+ off(ownerDocument, 'mouseup', this._onDrop);
2166
+ off(ownerDocument, 'touchend', this._onDrop);
2167
+ off(ownerDocument, 'pointerup', this._onDrop);
2168
+ off(ownerDocument, 'pointercancel', this._onDrop);
2169
+ off(ownerDocument, 'touchcancel', this._onDrop);
2170
+ off(document, 'selectstart', this);
2171
+ },
2172
+ _onDrop: function _onDrop( /**Event*/evt) {
2173
+ var el = this.el,
2174
+ options = this.options;
2175
+
2176
+ // Get the index of the dragged element within its parent
2177
+ newIndex = index(dragEl);
2178
+ newDraggableIndex = index(dragEl, options.draggable);
2179
+ pluginEvent('drop', this, {
2180
+ evt: evt
2181
+ });
2182
+ parentEl = dragEl && dragEl.parentNode;
2183
+
2184
+ // Get again after plugin event
2185
+ newIndex = index(dragEl);
2186
+ newDraggableIndex = index(dragEl, options.draggable);
2187
+ if (Sortable.eventCanceled) {
2188
+ this._nulling();
2189
+ return;
2190
+ }
2191
+ awaitingDragStarted = false;
2192
+ isCircumstantialInvert = false;
2193
+ pastFirstInvertThresh = false;
2194
+ clearInterval(this._loopId);
2195
+ clearTimeout(this._dragStartTimer);
2196
+ _cancelNextTick(this.cloneId);
2197
+ _cancelNextTick(this._dragStartId);
2198
+
2199
+ // Unbind events
2200
+ if (this.nativeDraggable) {
2201
+ off(document, 'drop', this);
2202
+ off(el, 'dragstart', this._onDragStart);
2203
+ }
2204
+ this._offMoveEvents();
2205
+ this._offUpEvents();
2206
+ if (Safari) {
2207
+ css(document.body, 'user-select', '');
2208
+ }
2209
+ css(dragEl, 'transform', '');
2210
+ if (evt) {
2211
+ if (moved) {
2212
+ evt.cancelable && evt.preventDefault();
2213
+ !options.dropBubble && evt.stopPropagation();
2214
+ }
2215
+ ghostEl && ghostEl.parentNode && ghostEl.parentNode.removeChild(ghostEl);
2216
+ if (rootEl === parentEl || putSortable && putSortable.lastPutMode !== 'clone') {
2217
+ // Remove clone(s)
2218
+ cloneEl && cloneEl.parentNode && cloneEl.parentNode.removeChild(cloneEl);
2219
+ }
2220
+ if (dragEl) {
2221
+ if (this.nativeDraggable) {
2222
+ off(dragEl, 'dragend', this);
2223
+ }
2224
+ _disableDraggable(dragEl);
2225
+ dragEl.style['will-change'] = '';
2226
+
2227
+ // Remove classes
2228
+ // ghostClass is added in dragStarted
2229
+ if (moved && !awaitingDragStarted) {
2230
+ toggleClass(dragEl, putSortable ? putSortable.options.ghostClass : this.options.ghostClass, false);
2231
+ }
2232
+ toggleClass(dragEl, this.options.chosenClass, false);
2233
+
2234
+ // Drag stop event
2235
+ _dispatchEvent({
2236
+ sortable: this,
2237
+ name: 'unchoose',
2238
+ toEl: parentEl,
2239
+ newIndex: null,
2240
+ newDraggableIndex: null,
2241
+ originalEvent: evt
2242
+ });
2243
+ if (rootEl !== parentEl) {
2244
+ if (newIndex >= 0) {
2245
+ // Add event
2246
+ _dispatchEvent({
2247
+ rootEl: parentEl,
2248
+ name: 'add',
2249
+ toEl: parentEl,
2250
+ fromEl: rootEl,
2251
+ originalEvent: evt
2252
+ });
2253
+
2254
+ // Remove event
2255
+ _dispatchEvent({
2256
+ sortable: this,
2257
+ name: 'remove',
2258
+ toEl: parentEl,
2259
+ originalEvent: evt
2260
+ });
2261
+
2262
+ // drag from one list and drop into another
2263
+ _dispatchEvent({
2264
+ rootEl: parentEl,
2265
+ name: 'sort',
2266
+ toEl: parentEl,
2267
+ fromEl: rootEl,
2268
+ originalEvent: evt
2269
+ });
2270
+ _dispatchEvent({
2271
+ sortable: this,
2272
+ name: 'sort',
2273
+ toEl: parentEl,
2274
+ originalEvent: evt
2275
+ });
2276
+ }
2277
+ putSortable && putSortable.save();
2278
+ } else {
2279
+ if (newIndex !== oldIndex) {
2280
+ if (newIndex >= 0) {
2281
+ // drag & drop within the same list
2282
+ _dispatchEvent({
2283
+ sortable: this,
2284
+ name: 'update',
2285
+ toEl: parentEl,
2286
+ originalEvent: evt
2287
+ });
2288
+ _dispatchEvent({
2289
+ sortable: this,
2290
+ name: 'sort',
2291
+ toEl: parentEl,
2292
+ originalEvent: evt
2293
+ });
2294
+ }
2295
+ }
2296
+ }
2297
+ if (Sortable.active) {
2298
+ /* jshint eqnull:true */
2299
+ if (newIndex == null || newIndex === -1) {
2300
+ newIndex = oldIndex;
2301
+ newDraggableIndex = oldDraggableIndex;
2302
+ }
2303
+ _dispatchEvent({
2304
+ sortable: this,
2305
+ name: 'end',
2306
+ toEl: parentEl,
2307
+ originalEvent: evt
2308
+ });
2309
+
2310
+ // Save sorting
2311
+ this.save();
2312
+ }
2313
+ }
2314
+ }
2315
+ this._nulling();
2316
+ },
2317
+ _nulling: function _nulling() {
2318
+ pluginEvent('nulling', this);
2319
+ rootEl = dragEl = parentEl = ghostEl = nextEl = cloneEl = lastDownEl = cloneHidden = tapEvt = touchEvt = moved = newIndex = newDraggableIndex = oldIndex = oldDraggableIndex = lastTarget = lastDirection = putSortable = activeGroup = Sortable.dragged = Sortable.ghost = Sortable.clone = Sortable.active = null;
2320
+ var el = this.el;
2321
+ savedInputChecked.forEach(function (checkEl) {
2322
+ if (el.contains(checkEl)) {
2323
+ checkEl.checked = true;
2324
+ }
2325
+ });
2326
+ savedInputChecked.length = lastDx = lastDy = 0;
2327
+ },
2328
+ handleEvent: function handleEvent( /**Event*/evt) {
2329
+ switch (evt.type) {
2330
+ case 'drop':
2331
+ case 'dragend':
2332
+ this._onDrop(evt);
2333
+ break;
2334
+ case 'dragenter':
2335
+ case 'dragover':
2336
+ if (dragEl) {
2337
+ this._onDragOver(evt);
2338
+ _globalDragOver(evt);
2339
+ }
2340
+ break;
2341
+ case 'selectstart':
2342
+ evt.preventDefault();
2343
+ break;
2344
+ }
2345
+ },
2346
+ /**
2347
+ * Serializes the item into an array of string.
2348
+ * @returns {String[]}
2349
+ */
2350
+ toArray: function toArray() {
2351
+ var order = [],
2352
+ el,
2353
+ children = this.el.children,
2354
+ i = 0,
2355
+ n = children.length,
2356
+ options = this.options;
2357
+ for (; i < n; i++) {
2358
+ el = children[i];
2359
+ if (closest(el, options.draggable, this.el, false)) {
2360
+ order.push(el.getAttribute(options.dataIdAttr) || _generateId(el));
2361
+ }
2362
+ }
2363
+ return order;
2364
+ },
2365
+ /**
2366
+ * Sorts the elements according to the array.
2367
+ * @param {String[]} order order of the items
2368
+ */
2369
+ sort: function sort(order, useAnimation) {
2370
+ var items = {},
2371
+ rootEl = this.el;
2372
+ this.toArray().forEach(function (id, i) {
2373
+ var el = rootEl.children[i];
2374
+ if (closest(el, this.options.draggable, rootEl, false)) {
2375
+ items[id] = el;
2376
+ }
2377
+ }, this);
2378
+ useAnimation && this.captureAnimationState();
2379
+ order.forEach(function (id) {
2380
+ if (items[id]) {
2381
+ rootEl.removeChild(items[id]);
2382
+ rootEl.appendChild(items[id]);
2383
+ }
2384
+ });
2385
+ useAnimation && this.animateAll();
2386
+ },
2387
+ /**
2388
+ * Save the current sorting
2389
+ */
2390
+ save: function save() {
2391
+ var store = this.options.store;
2392
+ store && store.set && store.set(this);
2393
+ },
2394
+ /**
2395
+ * For each element in the set, get the first element that matches the selector by testing the element itself and traversing up through its ancestors in the DOM tree.
2396
+ * @param {HTMLElement} el
2397
+ * @param {String} [selector] default: `options.draggable`
2398
+ * @returns {HTMLElement|null}
2399
+ */
2400
+ closest: function closest$1(el, selector) {
2401
+ return closest(el, selector || this.options.draggable, this.el, false);
2402
+ },
2403
+ /**
2404
+ * Set/get option
2405
+ * @param {string} name
2406
+ * @param {*} [value]
2407
+ * @returns {*}
2408
+ */
2409
+ option: function option(name, value) {
2410
+ var options = this.options;
2411
+ if (value === void 0) {
2412
+ return options[name];
2413
+ } else {
2414
+ var modifiedValue = PluginManager.modifyOption(this, name, value);
2415
+ if (typeof modifiedValue !== 'undefined') {
2416
+ options[name] = modifiedValue;
2417
+ } else {
2418
+ options[name] = value;
2419
+ }
2420
+ if (name === 'group') {
2421
+ _prepareGroup(options);
2422
+ }
2423
+ }
2424
+ },
2425
+ /**
2426
+ * Destroy
2427
+ */
2428
+ destroy: function destroy() {
2429
+ pluginEvent('destroy', this);
2430
+ var el = this.el;
2431
+ el[expando] = null;
2432
+ off(el, 'mousedown', this._onTapStart);
2433
+ off(el, 'touchstart', this._onTapStart);
2434
+ off(el, 'pointerdown', this._onTapStart);
2435
+ if (this.nativeDraggable) {
2436
+ off(el, 'dragover', this);
2437
+ off(el, 'dragenter', this);
2438
+ }
2439
+ // Remove draggable attributes
2440
+ Array.prototype.forEach.call(el.querySelectorAll('[draggable]'), function (el) {
2441
+ el.removeAttribute('draggable');
2442
+ });
2443
+ this._onDrop();
2444
+ this._disableDelayedDragEvents();
2445
+ sortables.splice(sortables.indexOf(this.el), 1);
2446
+ this.el = el = null;
2447
+ },
2448
+ _hideClone: function _hideClone() {
2449
+ if (!cloneHidden) {
2450
+ pluginEvent('hideClone', this);
2451
+ if (Sortable.eventCanceled) return;
2452
+ css(cloneEl, 'display', 'none');
2453
+ if (this.options.removeCloneOnHide && cloneEl.parentNode) {
2454
+ cloneEl.parentNode.removeChild(cloneEl);
2455
+ }
2456
+ cloneHidden = true;
2457
+ }
2458
+ },
2459
+ _showClone: function _showClone(putSortable) {
2460
+ if (putSortable.lastPutMode !== 'clone') {
2461
+ this._hideClone();
2462
+ return;
2463
+ }
2464
+ if (cloneHidden) {
2465
+ pluginEvent('showClone', this);
2466
+ if (Sortable.eventCanceled) return;
2467
+
2468
+ // show clone at dragEl or original position
2469
+ if (dragEl.parentNode == rootEl && !this.options.group.revertClone) {
2470
+ rootEl.insertBefore(cloneEl, dragEl);
2471
+ } else if (nextEl) {
2472
+ rootEl.insertBefore(cloneEl, nextEl);
2473
+ } else {
2474
+ rootEl.appendChild(cloneEl);
2475
+ }
2476
+ if (this.options.group.revertClone) {
2477
+ this.animate(dragEl, cloneEl);
2478
+ }
2479
+ css(cloneEl, 'display', '');
2480
+ cloneHidden = false;
2481
+ }
2482
+ }
2483
+ };
2484
+ function _globalDragOver( /**Event*/evt) {
2485
+ if (evt.dataTransfer) {
2486
+ evt.dataTransfer.dropEffect = 'move';
2487
+ }
2488
+ evt.cancelable && evt.preventDefault();
2489
+ }
2490
+ function _onMove(fromEl, toEl, dragEl, dragRect, targetEl, targetRect, originalEvent, willInsertAfter) {
2491
+ var evt,
2492
+ sortable = fromEl[expando],
2493
+ onMoveFn = sortable.options.onMove,
2494
+ retVal;
2495
+ // Support for new CustomEvent feature
2496
+ if (window.CustomEvent && !IE11OrLess && !Edge) {
2497
+ evt = new CustomEvent('move', {
2498
+ bubbles: true,
2499
+ cancelable: true
2500
+ });
2501
+ } else {
2502
+ evt = document.createEvent('Event');
2503
+ evt.initEvent('move', true, true);
2504
+ }
2505
+ evt.to = toEl;
2506
+ evt.from = fromEl;
2507
+ evt.dragged = dragEl;
2508
+ evt.draggedRect = dragRect;
2509
+ evt.related = targetEl || toEl;
2510
+ evt.relatedRect = targetRect || getRect(toEl);
2511
+ evt.willInsertAfter = willInsertAfter;
2512
+ evt.originalEvent = originalEvent;
2513
+ fromEl.dispatchEvent(evt);
2514
+ if (onMoveFn) {
2515
+ retVal = onMoveFn.call(sortable, evt, originalEvent);
2516
+ }
2517
+ return retVal;
2518
+ }
2519
+ function _disableDraggable(el) {
2520
+ el.draggable = false;
2521
+ }
2522
+ function _unsilent() {
2523
+ _silent = false;
2524
+ }
2525
+ function _ghostIsFirst(evt, vertical, sortable) {
2526
+ var firstElRect = getRect(getChild(sortable.el, 0, sortable.options, true));
2527
+ var childContainingRect = getChildContainingRectFromElement(sortable.el, sortable.options, ghostEl);
2528
+ var spacer = 10;
2529
+ return vertical ? evt.clientX < childContainingRect.left - spacer || evt.clientY < firstElRect.top && evt.clientX < firstElRect.right : evt.clientY < childContainingRect.top - spacer || evt.clientY < firstElRect.bottom && evt.clientX < firstElRect.left;
2530
+ }
2531
+ function _ghostIsLast(evt, vertical, sortable) {
2532
+ var lastElRect = getRect(lastChild(sortable.el, sortable.options.draggable));
2533
+ var childContainingRect = getChildContainingRectFromElement(sortable.el, sortable.options, ghostEl);
2534
+ var spacer = 10;
2535
+ return vertical ? evt.clientX > childContainingRect.right + spacer || evt.clientY > lastElRect.bottom && evt.clientX > lastElRect.left : evt.clientY > childContainingRect.bottom + spacer || evt.clientX > lastElRect.right && evt.clientY > lastElRect.top;
2536
+ }
2537
+ function _getSwapDirection(evt, target, targetRect, vertical, swapThreshold, invertedSwapThreshold, invertSwap, isLastTarget) {
2538
+ var mouseOnAxis = vertical ? evt.clientY : evt.clientX,
2539
+ targetLength = vertical ? targetRect.height : targetRect.width,
2540
+ targetS1 = vertical ? targetRect.top : targetRect.left,
2541
+ targetS2 = vertical ? targetRect.bottom : targetRect.right,
2542
+ invert = false;
2543
+ if (!invertSwap) {
2544
+ // Never invert or create dragEl shadow when target movemenet causes mouse to move past the end of regular swapThreshold
2545
+ if (isLastTarget && targetMoveDistance < targetLength * swapThreshold) {
2546
+ // multiplied only by swapThreshold because mouse will already be inside target by (1 - threshold) * targetLength / 2
2547
+ // check if past first invert threshold on side opposite of lastDirection
2548
+ if (!pastFirstInvertThresh && (lastDirection === 1 ? mouseOnAxis > targetS1 + targetLength * invertedSwapThreshold / 2 : mouseOnAxis < targetS2 - targetLength * invertedSwapThreshold / 2)) {
2549
+ // past first invert threshold, do not restrict inverted threshold to dragEl shadow
2550
+ pastFirstInvertThresh = true;
2551
+ }
2552
+ if (!pastFirstInvertThresh) {
2553
+ // dragEl shadow (target move distance shadow)
2554
+ if (lastDirection === 1 ? mouseOnAxis < targetS1 + targetMoveDistance // over dragEl shadow
2555
+ : mouseOnAxis > targetS2 - targetMoveDistance) {
2556
+ return -lastDirection;
2557
+ }
2558
+ } else {
2559
+ invert = true;
2560
+ }
2561
+ } else {
2562
+ // Regular
2563
+ if (mouseOnAxis > targetS1 + targetLength * (1 - swapThreshold) / 2 && mouseOnAxis < targetS2 - targetLength * (1 - swapThreshold) / 2) {
2564
+ return _getInsertDirection(target);
2565
+ }
2566
+ }
2567
+ }
2568
+ invert = invert || invertSwap;
2569
+ if (invert) {
2570
+ // Invert of regular
2571
+ if (mouseOnAxis < targetS1 + targetLength * invertedSwapThreshold / 2 || mouseOnAxis > targetS2 - targetLength * invertedSwapThreshold / 2) {
2572
+ return mouseOnAxis > targetS1 + targetLength / 2 ? 1 : -1;
2573
+ }
2574
+ }
2575
+ return 0;
2576
+ }
2577
+
2578
+ /**
2579
+ * Gets the direction dragEl must be swapped relative to target in order to make it
2580
+ * seem that dragEl has been "inserted" into that element's position
2581
+ * @param {HTMLElement} target The target whose position dragEl is being inserted at
2582
+ * @return {Number} Direction dragEl must be swapped
2583
+ */
2584
+ function _getInsertDirection(target) {
2585
+ if (index(dragEl) < index(target)) {
2586
+ return 1;
2587
+ } else {
2588
+ return -1;
2589
+ }
2590
+ }
2591
+
2592
+ /**
2593
+ * Generate id
2594
+ * @param {HTMLElement} el
2595
+ * @returns {String}
2596
+ * @private
2597
+ */
2598
+ function _generateId(el) {
2599
+ var str = el.tagName + el.className + el.src + el.href + el.textContent,
2600
+ i = str.length,
2601
+ sum = 0;
2602
+ while (i--) {
2603
+ sum += str.charCodeAt(i);
2604
+ }
2605
+ return sum.toString(36);
2606
+ }
2607
+ function _saveInputCheckedState(root) {
2608
+ savedInputChecked.length = 0;
2609
+ var inputs = root.getElementsByTagName('input');
2610
+ var idx = inputs.length;
2611
+ while (idx--) {
2612
+ var el = inputs[idx];
2613
+ el.checked && savedInputChecked.push(el);
2614
+ }
2615
+ }
2616
+ function _nextTick(fn) {
2617
+ return setTimeout(fn, 0);
2618
+ }
2619
+ function _cancelNextTick(id) {
2620
+ return clearTimeout(id);
2621
+ }
2622
+
2623
+ // Fixed #973:
2624
+ if (documentExists) {
2625
+ on(document, 'touchmove', function (evt) {
2626
+ if ((Sortable.active || awaitingDragStarted) && evt.cancelable) {
2627
+ evt.preventDefault();
2628
+ }
2629
+ });
2630
+ }
2631
+
2632
+ // Export utils
2633
+ Sortable.utils = {
2634
+ on: on,
2635
+ off: off,
2636
+ css: css,
2637
+ find: find,
2638
+ is: function is(el, selector) {
2639
+ return !!closest(el, selector, el, false);
2640
+ },
2641
+ extend: extend,
2642
+ throttle: throttle,
2643
+ closest: closest,
2644
+ toggleClass: toggleClass,
2645
+ clone: clone,
2646
+ index: index,
2647
+ nextTick: _nextTick,
2648
+ cancelNextTick: _cancelNextTick,
2649
+ detectDirection: _detectDirection,
2650
+ getChild: getChild,
2651
+ expando: expando
2652
+ };
2653
+
2654
+ /**
2655
+ * Get the Sortable instance of an element
2656
+ * @param {HTMLElement} element The element
2657
+ * @return {Sortable|undefined} The instance of Sortable
2658
+ */
2659
+ Sortable.get = function (element) {
2660
+ return element[expando];
2661
+ };
2662
+
2663
+ /**
2664
+ * Mount a plugin to Sortable
2665
+ * @param {...SortablePlugin|SortablePlugin[]} plugins Plugins being mounted
2666
+ */
2667
+ Sortable.mount = function () {
2668
+ for (var _len = arguments.length, plugins = new Array(_len), _key = 0; _key < _len; _key++) {
2669
+ plugins[_key] = arguments[_key];
2670
+ }
2671
+ if (plugins[0].constructor === Array) plugins = plugins[0];
2672
+ plugins.forEach(function (plugin) {
2673
+ if (!plugin.prototype || !plugin.prototype.constructor) {
2674
+ throw "Sortable: Mounted plugin must be a constructor function, not ".concat({}.toString.call(plugin));
2675
+ }
2676
+ if (plugin.utils) Sortable.utils = _objectSpread2(_objectSpread2({}, Sortable.utils), plugin.utils);
2677
+ PluginManager.mount(plugin);
2678
+ });
2679
+ };
2680
+
2681
+ /**
2682
+ * Create sortable instance
2683
+ * @param {HTMLElement} el
2684
+ * @param {Object} [options]
2685
+ */
2686
+ Sortable.create = function (el, options) {
2687
+ return new Sortable(el, options);
2688
+ };
2689
+
2690
+ // Export
2691
+ Sortable.version = version;
2692
+
2693
+ var autoScrolls = [],
2694
+ scrollEl,
2695
+ scrollRootEl,
2696
+ scrolling = false,
2697
+ lastAutoScrollX,
2698
+ lastAutoScrollY,
2699
+ touchEvt$1,
2700
+ pointerElemChangedInterval;
2701
+ function AutoScrollPlugin() {
2702
+ function AutoScroll() {
2703
+ this.defaults = {
2704
+ scroll: true,
2705
+ forceAutoScrollFallback: false,
2706
+ scrollSensitivity: 30,
2707
+ scrollSpeed: 10,
2708
+ bubbleScroll: true
2709
+ };
2710
+
2711
+ // Bind all private methods
2712
+ for (var fn in this) {
2713
+ if (fn.charAt(0) === '_' && typeof this[fn] === 'function') {
2714
+ this[fn] = this[fn].bind(this);
2715
+ }
2716
+ }
2717
+ }
2718
+ AutoScroll.prototype = {
2719
+ dragStarted: function dragStarted(_ref) {
2720
+ var originalEvent = _ref.originalEvent;
2721
+ if (this.sortable.nativeDraggable) {
2722
+ on(document, 'dragover', this._handleAutoScroll);
2723
+ } else {
2724
+ if (this.options.supportPointer) {
2725
+ on(document, 'pointermove', this._handleFallbackAutoScroll);
2726
+ } else if (originalEvent.touches) {
2727
+ on(document, 'touchmove', this._handleFallbackAutoScroll);
2728
+ } else {
2729
+ on(document, 'mousemove', this._handleFallbackAutoScroll);
2730
+ }
2731
+ }
2732
+ },
2733
+ dragOverCompleted: function dragOverCompleted(_ref2) {
2734
+ var originalEvent = _ref2.originalEvent;
2735
+ // For when bubbling is canceled and using fallback (fallback 'touchmove' always reached)
2736
+ if (!this.options.dragOverBubble && !originalEvent.rootEl) {
2737
+ this._handleAutoScroll(originalEvent);
2738
+ }
2739
+ },
2740
+ drop: function drop() {
2741
+ if (this.sortable.nativeDraggable) {
2742
+ off(document, 'dragover', this._handleAutoScroll);
2743
+ } else {
2744
+ off(document, 'pointermove', this._handleFallbackAutoScroll);
2745
+ off(document, 'touchmove', this._handleFallbackAutoScroll);
2746
+ off(document, 'mousemove', this._handleFallbackAutoScroll);
2747
+ }
2748
+ clearPointerElemChangedInterval();
2749
+ clearAutoScrolls();
2750
+ cancelThrottle();
2751
+ },
2752
+ nulling: function nulling() {
2753
+ touchEvt$1 = scrollRootEl = scrollEl = scrolling = pointerElemChangedInterval = lastAutoScrollX = lastAutoScrollY = null;
2754
+ autoScrolls.length = 0;
2755
+ },
2756
+ _handleFallbackAutoScroll: function _handleFallbackAutoScroll(evt) {
2757
+ this._handleAutoScroll(evt, true);
2758
+ },
2759
+ _handleAutoScroll: function _handleAutoScroll(evt, fallback) {
2760
+ var _this = this;
2761
+ var x = (evt.touches ? evt.touches[0] : evt).clientX,
2762
+ y = (evt.touches ? evt.touches[0] : evt).clientY,
2763
+ elem = document.elementFromPoint(x, y);
2764
+ touchEvt$1 = evt;
2765
+
2766
+ // IE does not seem to have native autoscroll,
2767
+ // Edge's autoscroll seems too conditional,
2768
+ // MACOS Safari does not have autoscroll,
2769
+ // Firefox and Chrome are good
2770
+ if (fallback || this.options.forceAutoScrollFallback || Edge || IE11OrLess || Safari) {
2771
+ autoScroll(evt, this.options, elem, fallback);
2772
+
2773
+ // Listener for pointer element change
2774
+ var ogElemScroller = getParentAutoScrollElement(elem, true);
2775
+ if (scrolling && (!pointerElemChangedInterval || x !== lastAutoScrollX || y !== lastAutoScrollY)) {
2776
+ pointerElemChangedInterval && clearPointerElemChangedInterval();
2777
+ // Detect for pointer elem change, emulating native DnD behaviour
2778
+ pointerElemChangedInterval = setInterval(function () {
2779
+ var newElem = getParentAutoScrollElement(document.elementFromPoint(x, y), true);
2780
+ if (newElem !== ogElemScroller) {
2781
+ ogElemScroller = newElem;
2782
+ clearAutoScrolls();
2783
+ }
2784
+ autoScroll(evt, _this.options, newElem, fallback);
2785
+ }, 10);
2786
+ lastAutoScrollX = x;
2787
+ lastAutoScrollY = y;
2788
+ }
2789
+ } else {
2790
+ // if DnD is enabled (and browser has good autoscrolling), first autoscroll will already scroll, so get parent autoscroll of first autoscroll
2791
+ if (!this.options.bubbleScroll || getParentAutoScrollElement(elem, true) === getWindowScrollingElement()) {
2792
+ clearAutoScrolls();
2793
+ return;
2794
+ }
2795
+ autoScroll(evt, this.options, getParentAutoScrollElement(elem, false), false);
2796
+ }
2797
+ }
2798
+ };
2799
+ return _extends(AutoScroll, {
2800
+ pluginName: 'scroll',
2801
+ initializeByDefault: true
2802
+ });
2803
+ }
2804
+ function clearAutoScrolls() {
2805
+ autoScrolls.forEach(function (autoScroll) {
2806
+ clearInterval(autoScroll.pid);
2807
+ });
2808
+ autoScrolls = [];
2809
+ }
2810
+ function clearPointerElemChangedInterval() {
2811
+ clearInterval(pointerElemChangedInterval);
2812
+ }
2813
+ var autoScroll = throttle(function (evt, options, rootEl, isFallback) {
2814
+ // Bug: https://bugzilla.mozilla.org/show_bug.cgi?id=505521
2815
+ if (!options.scroll) return;
2816
+ var x = (evt.touches ? evt.touches[0] : evt).clientX,
2817
+ y = (evt.touches ? evt.touches[0] : evt).clientY,
2818
+ sens = options.scrollSensitivity,
2819
+ speed = options.scrollSpeed,
2820
+ winScroller = getWindowScrollingElement();
2821
+ var scrollThisInstance = false,
2822
+ scrollCustomFn;
2823
+
2824
+ // New scroll root, set scrollEl
2825
+ if (scrollRootEl !== rootEl) {
2826
+ scrollRootEl = rootEl;
2827
+ clearAutoScrolls();
2828
+ scrollEl = options.scroll;
2829
+ scrollCustomFn = options.scrollFn;
2830
+ if (scrollEl === true) {
2831
+ scrollEl = getParentAutoScrollElement(rootEl, true);
2832
+ }
2833
+ }
2834
+ var layersOut = 0;
2835
+ var currentParent = scrollEl;
2836
+ do {
2837
+ var el = currentParent,
2838
+ rect = getRect(el),
2839
+ top = rect.top,
2840
+ bottom = rect.bottom,
2841
+ left = rect.left,
2842
+ right = rect.right,
2843
+ width = rect.width,
2844
+ height = rect.height,
2845
+ canScrollX = void 0,
2846
+ canScrollY = void 0,
2847
+ scrollWidth = el.scrollWidth,
2848
+ scrollHeight = el.scrollHeight,
2849
+ elCSS = css(el),
2850
+ scrollPosX = el.scrollLeft,
2851
+ scrollPosY = el.scrollTop;
2852
+ if (el === winScroller) {
2853
+ canScrollX = width < scrollWidth && (elCSS.overflowX === 'auto' || elCSS.overflowX === 'scroll' || elCSS.overflowX === 'visible');
2854
+ canScrollY = height < scrollHeight && (elCSS.overflowY === 'auto' || elCSS.overflowY === 'scroll' || elCSS.overflowY === 'visible');
2855
+ } else {
2856
+ canScrollX = width < scrollWidth && (elCSS.overflowX === 'auto' || elCSS.overflowX === 'scroll');
2857
+ canScrollY = height < scrollHeight && (elCSS.overflowY === 'auto' || elCSS.overflowY === 'scroll');
2858
+ }
2859
+ var vx = canScrollX && (Math.abs(right - x) <= sens && scrollPosX + width < scrollWidth) - (Math.abs(left - x) <= sens && !!scrollPosX);
2860
+ var vy = canScrollY && (Math.abs(bottom - y) <= sens && scrollPosY + height < scrollHeight) - (Math.abs(top - y) <= sens && !!scrollPosY);
2861
+ if (!autoScrolls[layersOut]) {
2862
+ for (var i = 0; i <= layersOut; i++) {
2863
+ if (!autoScrolls[i]) {
2864
+ autoScrolls[i] = {};
2865
+ }
2866
+ }
2867
+ }
2868
+ if (autoScrolls[layersOut].vx != vx || autoScrolls[layersOut].vy != vy || autoScrolls[layersOut].el !== el) {
2869
+ autoScrolls[layersOut].el = el;
2870
+ autoScrolls[layersOut].vx = vx;
2871
+ autoScrolls[layersOut].vy = vy;
2872
+ clearInterval(autoScrolls[layersOut].pid);
2873
+ if (vx != 0 || vy != 0) {
2874
+ scrollThisInstance = true;
2875
+ /* jshint loopfunc:true */
2876
+ autoScrolls[layersOut].pid = setInterval(function () {
2877
+ // emulate drag over during autoscroll (fallback), emulating native DnD behaviour
2878
+ if (isFallback && this.layer === 0) {
2879
+ Sortable.active._onTouchMove(touchEvt$1); // To move ghost if it is positioned absolutely
2880
+ }
2881
+ var scrollOffsetY = autoScrolls[this.layer].vy ? autoScrolls[this.layer].vy * speed : 0;
2882
+ var scrollOffsetX = autoScrolls[this.layer].vx ? autoScrolls[this.layer].vx * speed : 0;
2883
+ if (typeof scrollCustomFn === 'function') {
2884
+ if (scrollCustomFn.call(Sortable.dragged.parentNode[expando], scrollOffsetX, scrollOffsetY, evt, touchEvt$1, autoScrolls[this.layer].el) !== 'continue') {
2885
+ return;
2886
+ }
2887
+ }
2888
+ scrollBy(autoScrolls[this.layer].el, scrollOffsetX, scrollOffsetY);
2889
+ }.bind({
2890
+ layer: layersOut
2891
+ }), 24);
2892
+ }
2893
+ }
2894
+ layersOut++;
2895
+ } while (options.bubbleScroll && currentParent !== winScroller && (currentParent = getParentAutoScrollElement(currentParent, false)));
2896
+ scrolling = scrollThisInstance; // in case another function catches scrolling as false in between when it is not
2897
+ }, 30);
2898
+
2899
+ var drop = function drop(_ref) {
2900
+ var originalEvent = _ref.originalEvent,
2901
+ putSortable = _ref.putSortable,
2902
+ dragEl = _ref.dragEl,
2903
+ activeSortable = _ref.activeSortable,
2904
+ dispatchSortableEvent = _ref.dispatchSortableEvent,
2905
+ hideGhostForTarget = _ref.hideGhostForTarget,
2906
+ unhideGhostForTarget = _ref.unhideGhostForTarget;
2907
+ if (!originalEvent) return;
2908
+ var toSortable = putSortable || activeSortable;
2909
+ hideGhostForTarget();
2910
+ var touch = originalEvent.changedTouches && originalEvent.changedTouches.length ? originalEvent.changedTouches[0] : originalEvent;
2911
+ var target = document.elementFromPoint(touch.clientX, touch.clientY);
2912
+ unhideGhostForTarget();
2913
+ if (toSortable && !toSortable.el.contains(target)) {
2914
+ dispatchSortableEvent('spill');
2915
+ this.onSpill({
2916
+ dragEl: dragEl,
2917
+ putSortable: putSortable
2918
+ });
2919
+ }
2920
+ };
2921
+ function Revert() {}
2922
+ Revert.prototype = {
2923
+ startIndex: null,
2924
+ dragStart: function dragStart(_ref2) {
2925
+ var oldDraggableIndex = _ref2.oldDraggableIndex;
2926
+ this.startIndex = oldDraggableIndex;
2927
+ },
2928
+ onSpill: function onSpill(_ref3) {
2929
+ var dragEl = _ref3.dragEl,
2930
+ putSortable = _ref3.putSortable;
2931
+ this.sortable.captureAnimationState();
2932
+ if (putSortable) {
2933
+ putSortable.captureAnimationState();
2934
+ }
2935
+ var nextSibling = getChild(this.sortable.el, this.startIndex, this.options);
2936
+ if (nextSibling) {
2937
+ this.sortable.el.insertBefore(dragEl, nextSibling);
2938
+ } else {
2939
+ this.sortable.el.appendChild(dragEl);
2940
+ }
2941
+ this.sortable.animateAll();
2942
+ if (putSortable) {
2943
+ putSortable.animateAll();
2944
+ }
2945
+ },
2946
+ drop: drop
2947
+ };
2948
+ _extends(Revert, {
2949
+ pluginName: 'revertOnSpill'
2950
+ });
2951
+ function Remove() {}
2952
+ Remove.prototype = {
2953
+ onSpill: function onSpill(_ref4) {
2954
+ var dragEl = _ref4.dragEl,
2955
+ putSortable = _ref4.putSortable;
2956
+ var parentSortable = putSortable || this.sortable;
2957
+ parentSortable.captureAnimationState();
2958
+ dragEl.parentNode && dragEl.parentNode.removeChild(dragEl);
2959
+ parentSortable.animateAll();
2960
+ },
2961
+ drop: drop
2962
+ };
2963
+ _extends(Remove, {
2964
+ pluginName: 'removeOnSpill'
2965
+ });
2966
+
2967
+ Sortable.mount(new AutoScrollPlugin());
2968
+ Sortable.mount(Remove, Revert);
2969
+
2970
+ const DRAG_HANDLE_SELECTOR = '[data-drag-handle]';
2971
+ const DRAGGING_CONTAINER_CLASS = 'has-an-item-which-is-being-dragged';
2972
+ const ELEVATED_ITEM_CLASS = 'is-elevated';
2973
+ const ELEVATION_DURATION_MS = 1000;
2974
+ const TOUCH_DRAG_DELAY_MS = 200;
2975
+ const ANIMATION_DURATION_MS = 150;
2976
+ /**
2977
+ * Lets the user reorder the children of a list with a drag handle.
2978
+ *
2979
+ * Every child of the list has a `data-reorder-id`, and the drag starts from
2980
+ * an element with the `data-drag-handle` attribute inside a child.
2981
+ */
2982
+ class DragToReorder {
2983
+ constructor(options) {
2984
+ this.options = options;
2985
+ this.orderBeforeDrag = [];
2986
+ this.handleStart = (event) => {
2987
+ var _a, _b;
2988
+ this.orderBeforeDrag = this.readOrder();
2989
+ this.nextSiblingBeforeDrag = (_a = event.item.nextElementSibling) !== null && _a !== void 0 ? _a : undefined;
2990
+ (_b = this.container) === null || _b === void 0 ? void 0 : _b.classList.add(DRAGGING_CONTAINER_CLASS);
2991
+ this.elevate(event.item);
2992
+ };
2993
+ this.handleEnd = (event) => {
2994
+ var _a;
2995
+ (_a = this.container) === null || _a === void 0 ? void 0 : _a.classList.remove(DRAGGING_CONTAINER_CLASS);
2996
+ this.keepElevatedBriefly(event.item);
2997
+ const order = this.readOrder();
2998
+ const id = event.item.dataset.reorderId;
2999
+ const fromIndex = this.orderBeforeDrag.indexOf(id);
3000
+ const toIndex = order.indexOf(id);
3001
+ const nextSibling = this.nextSiblingBeforeDrag;
3002
+ this.orderBeforeDrag = [];
3003
+ this.nextSiblingBeforeDrag = undefined;
3004
+ if (fromIndex === -1 || toIndex === -1 || fromIndex === toIndex) {
3005
+ return;
3006
+ }
3007
+ if (this.options.revertDrop) {
3008
+ this.putBack(event.item, nextSibling);
3009
+ }
3010
+ this.options.onReorder({ order, fromIndex, toIndex });
3011
+ };
3012
+ }
3013
+ /**
3014
+ * @param container - the list
3015
+ * @param direction - the way the children are laid out. Leave it out to
3016
+ * let SortableJS find out. Setting up the same list again without it keeps
3017
+ * the direction that the list has.
3018
+ */
3019
+ setup(container, direction) {
3020
+ if (this.getDraggableItems(container).length < 2) {
3021
+ this.teardown();
3022
+ return;
3023
+ }
3024
+ if (this.sortable && this.container === container) {
3025
+ this.changeDirection(direction);
3026
+ return;
3027
+ }
3028
+ this.teardown();
3029
+ this.container = container;
3030
+ this.direction = direction;
3031
+ this.sortable = Sortable.create(container, Object.assign(Object.assign({ animation: ANIMATION_DURATION_MS, handle: DRAG_HANDLE_SELECTOR, draggable: this.options.draggable, delay: TOUCH_DRAG_DELAY_MS, delayOnTouchOnly: true }, (direction && { direction: direction })), { onStart: this.handleStart, onEnd: this.handleEnd }));
3032
+ }
3033
+ teardown() {
3034
+ var _a, _b;
3035
+ (_a = this.sortable) === null || _a === void 0 ? void 0 : _a.destroy();
3036
+ this.sortable = undefined;
3037
+ this.removeElevation();
3038
+ (_b = this.container) === null || _b === void 0 ? void 0 : _b.classList.remove(DRAGGING_CONTAINER_CLASS);
3039
+ this.container = undefined;
3040
+ this.direction = undefined;
3041
+ this.orderBeforeDrag = [];
3042
+ this.nextSiblingBeforeDrag = undefined;
3043
+ }
3044
+ putBack(item, nextSibling) {
3045
+ const isStillInList = (nextSibling === null || nextSibling === void 0 ? void 0 : nextSibling.parentNode) === this.container;
3046
+ this.container.insertBefore(item, isStillInList ? nextSibling : null);
3047
+ }
3048
+ changeDirection(direction) {
3049
+ if (!direction || direction === this.direction) {
3050
+ return;
3051
+ }
3052
+ this.direction = direction;
3053
+ this.sortable.option('direction', direction);
3054
+ }
3055
+ getDraggableItems(container) {
3056
+ return [...container.children].filter((child) => child.matches(this.options.draggable));
3057
+ }
3058
+ readOrder() {
3059
+ var _a, _b;
3060
+ const children = [...((_b = (_a = this.container) === null || _a === void 0 ? void 0 : _a.children) !== null && _b !== void 0 ? _b : [])];
3061
+ return children
3062
+ .filter((child) => {
3063
+ return (child instanceof HTMLElement &&
3064
+ child.dataset.reorderId !== undefined);
3065
+ })
3066
+ .map((child) => child.dataset.reorderId);
3067
+ }
3068
+ elevate(item) {
3069
+ this.removeElevation();
3070
+ item.classList.add(ELEVATED_ITEM_CLASS);
3071
+ this.elevatedItem = item;
3072
+ }
3073
+ keepElevatedBriefly(item) {
3074
+ this.elevate(item);
3075
+ this.elevationTimeout = setTimeout(() => this.removeElevation(), ELEVATION_DURATION_MS);
3076
+ }
3077
+ removeElevation() {
3078
+ var _a;
3079
+ clearTimeout(this.elevationTimeout);
3080
+ this.elevationTimeout = undefined;
3081
+ (_a = this.elevatedItem) === null || _a === void 0 ? void 0 : _a.classList.remove(ELEVATED_ITEM_CLASS);
3082
+ this.elevatedItem = undefined;
3083
+ }
3084
+ }
3085
+
3086
+ export { DragToReorder as D, arrayIncludes as a, baseRest as b, baseFlatten as c, isArrayLikeObject as i };