@pantograph/sortable 1.15.6

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.
@@ -0,0 +1,3637 @@
1
+ /**!
2
+ * Sortable 1.15.6
3
+ * @author RubaXa <trash@rubaxa.org>
4
+ * @author owenm <owen23355@gmail.com>
5
+ * @license MIT
6
+ */
7
+ function _arrayLikeToArray(r, a) {
8
+ (null == a || a > r.length) && (a = r.length);
9
+ for (var e = 0, n = Array(a); e < a; e++) n[e] = r[e];
10
+ return n;
11
+ }
12
+ function _arrayWithoutHoles(r) {
13
+ if (Array.isArray(r)) return _arrayLikeToArray(r);
14
+ }
15
+ function _classCallCheck(a, n) {
16
+ if (!(a instanceof n)) throw new TypeError("Cannot call a class as a function");
17
+ }
18
+ function _defineProperties(e, r) {
19
+ for (var t = 0; t < r.length; t++) {
20
+ var o = r[t];
21
+ o.enumerable = o.enumerable || !1, o.configurable = !0, "value" in o && (o.writable = !0), Object.defineProperty(e, _toPropertyKey(o.key), o);
22
+ }
23
+ }
24
+ function _createClass(e, r, t) {
25
+ return r && _defineProperties(e.prototype, r), t && _defineProperties(e, t), Object.defineProperty(e, "prototype", {
26
+ writable: !1
27
+ }), e;
28
+ }
29
+ function _createForOfIteratorHelper(r, e) {
30
+ var t = "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"];
31
+ if (!t) {
32
+ if (Array.isArray(r) || (t = _unsupportedIterableToArray(r)) || e && r && "number" == typeof r.length) {
33
+ t && (r = t);
34
+ var n = 0,
35
+ F = function () {};
36
+ return {
37
+ s: F,
38
+ n: function () {
39
+ return n >= r.length ? {
40
+ done: !0
41
+ } : {
42
+ done: !1,
43
+ value: r[n++]
44
+ };
45
+ },
46
+ e: function (r) {
47
+ throw r;
48
+ },
49
+ f: F
50
+ };
51
+ }
52
+ throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
53
+ }
54
+ var o,
55
+ a = !0,
56
+ u = !1;
57
+ return {
58
+ s: function () {
59
+ t = t.call(r);
60
+ },
61
+ n: function () {
62
+ var r = t.next();
63
+ return a = r.done, r;
64
+ },
65
+ e: function (r) {
66
+ u = !0, o = r;
67
+ },
68
+ f: function () {
69
+ try {
70
+ a || null == t.return || t.return();
71
+ } finally {
72
+ if (u) throw o;
73
+ }
74
+ }
75
+ };
76
+ }
77
+ function _defineProperty(e, r, t) {
78
+ return (r = _toPropertyKey(r)) in e ? Object.defineProperty(e, r, {
79
+ value: t,
80
+ enumerable: !0,
81
+ configurable: !0,
82
+ writable: !0
83
+ }) : e[r] = t, e;
84
+ }
85
+ function _extends() {
86
+ return _extends = Object.assign ? Object.assign.bind() : function (n) {
87
+ for (var e = 1; e < arguments.length; e++) {
88
+ var t = arguments[e];
89
+ for (var r in t) ({}).hasOwnProperty.call(t, r) && (n[r] = t[r]);
90
+ }
91
+ return n;
92
+ }, _extends.apply(null, arguments);
93
+ }
94
+ function _iterableToArray(r) {
95
+ if ("undefined" != typeof Symbol && null != r[Symbol.iterator] || null != r["@@iterator"]) return Array.from(r);
96
+ }
97
+ function _nonIterableSpread() {
98
+ throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
99
+ }
100
+ function ownKeys(e, r) {
101
+ var t = Object.keys(e);
102
+ if (Object.getOwnPropertySymbols) {
103
+ var o = Object.getOwnPropertySymbols(e);
104
+ r && (o = o.filter(function (r) {
105
+ return Object.getOwnPropertyDescriptor(e, r).enumerable;
106
+ })), t.push.apply(t, o);
107
+ }
108
+ return t;
109
+ }
110
+ function _objectSpread2(e) {
111
+ for (var r = 1; r < arguments.length; r++) {
112
+ var t = null != arguments[r] ? arguments[r] : {};
113
+ r % 2 ? ownKeys(Object(t), !0).forEach(function (r) {
114
+ _defineProperty(e, r, t[r]);
115
+ }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) {
116
+ Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r));
117
+ });
118
+ }
119
+ return e;
120
+ }
121
+ function _objectWithoutProperties(e, t) {
122
+ if (null == e) return {};
123
+ var o,
124
+ r,
125
+ i = _objectWithoutPropertiesLoose(e, t);
126
+ if (Object.getOwnPropertySymbols) {
127
+ var n = Object.getOwnPropertySymbols(e);
128
+ for (r = 0; r < n.length; r++) o = n[r], -1 === t.indexOf(o) && {}.propertyIsEnumerable.call(e, o) && (i[o] = e[o]);
129
+ }
130
+ return i;
131
+ }
132
+ function _objectWithoutPropertiesLoose(r, e) {
133
+ if (null == r) return {};
134
+ var t = {};
135
+ for (var n in r) if ({}.hasOwnProperty.call(r, n)) {
136
+ if (-1 !== e.indexOf(n)) continue;
137
+ t[n] = r[n];
138
+ }
139
+ return t;
140
+ }
141
+ function _toConsumableArray(r) {
142
+ return _arrayWithoutHoles(r) || _iterableToArray(r) || _unsupportedIterableToArray(r) || _nonIterableSpread();
143
+ }
144
+ function _toPrimitive(t, r) {
145
+ if ("object" != typeof t || !t) return t;
146
+ var e = t[Symbol.toPrimitive];
147
+ if (void 0 !== e) {
148
+ var i = e.call(t, r || "default");
149
+ if ("object" != typeof i) return i;
150
+ throw new TypeError("@@toPrimitive must return a primitive value.");
151
+ }
152
+ return ("string" === r ? String : Number)(t);
153
+ }
154
+ function _toPropertyKey(t) {
155
+ var i = _toPrimitive(t, "string");
156
+ return "symbol" == typeof i ? i : i + "";
157
+ }
158
+ function _typeof(o) {
159
+ "@babel/helpers - typeof";
160
+
161
+ return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) {
162
+ return typeof o;
163
+ } : function (o) {
164
+ return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o;
165
+ }, _typeof(o);
166
+ }
167
+ function _unsupportedIterableToArray(r, a) {
168
+ if (r) {
169
+ if ("string" == typeof r) return _arrayLikeToArray(r, a);
170
+ var t = {}.toString.call(r).slice(8, -1);
171
+ return "Object" === t && r.constructor && (t = r.constructor.name), "Map" === t || "Set" === t ? Array.from(r) : "Arguments" === t || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(t) ? _arrayLikeToArray(r, a) : void 0;
172
+ }
173
+ }
174
+
175
+ var version = "1.15.6";
176
+
177
+ function userAgent(pattern) {
178
+ if (typeof window !== 'undefined' && window.navigator) {
179
+ return !! /*@__PURE__*/navigator.userAgent.match(pattern);
180
+ }
181
+ }
182
+ var IE11OrLess = userAgent(/(?:Trident.*rv[ :]?11\.|msie|iemobile|Windows Phone)/i);
183
+ var Edge = userAgent(/Edge/i);
184
+ var FireFox = userAgent(/firefox/i);
185
+ var Safari = userAgent(/safari/i) && !userAgent(/chrome/i) && !userAgent(/android/i);
186
+ var IOS = userAgent(/iP(ad|od|hone)/i);
187
+ var ChromeForAndroid = userAgent(/chrome/i) && userAgent(/android/i);
188
+
189
+ var captureMode = {
190
+ capture: false,
191
+ passive: false
192
+ };
193
+ function on(el, event, fn) {
194
+ el.addEventListener(event, fn, !IE11OrLess && captureMode);
195
+ }
196
+ function off(el, event, fn) {
197
+ el.removeEventListener(event, fn, !IE11OrLess && captureMode);
198
+ }
199
+ function matches(/**HTMLElement*/el, /**String*/selector) {
200
+ if (!selector) return;
201
+ selector[0] === '>' && (selector = selector.substring(1));
202
+ if (el) {
203
+ try {
204
+ if (el.matches) {
205
+ return el.matches(selector);
206
+ } else if (el.msMatchesSelector) {
207
+ return el.msMatchesSelector(selector);
208
+ } else if (el.webkitMatchesSelector) {
209
+ return el.webkitMatchesSelector(selector);
210
+ }
211
+ } catch (_) {
212
+ return false;
213
+ }
214
+ }
215
+ return false;
216
+ }
217
+ function getParentOrHost(el) {
218
+ return el.host && el !== document && el.host.nodeType && el.host !== el ? el.host : el.parentNode;
219
+ }
220
+ function closest(/**HTMLElement*/el, /**String*/selector, /**HTMLElement*/ctx, includeCTX, /**HTMLElement*/ignoreEl) {
221
+ if (el) {
222
+ ctx = ctx || document;
223
+ do {
224
+ if (el !== ignoreEl && (selector != null && (selector[0] === '>' ? el.parentNode === ctx && matches(el, selector) : matches(el, selector)) || includeCTX && el === ctx)) {
225
+ return el;
226
+ }
227
+ if (el === ctx) break;
228
+ /* jshint boss:true */
229
+ } while (el = getParentOrHost(el));
230
+ }
231
+ return null;
232
+ }
233
+ var R_SPACE = /\s+/g;
234
+ function toggleClass(el, name, state) {
235
+ if (el && name) {
236
+ if (el.classList) {
237
+ el.classList[state ? 'add' : 'remove'](name);
238
+ } else {
239
+ var className = (' ' + el.className + ' ').replace(R_SPACE, ' ').replace(' ' + name + ' ', ' ');
240
+ el.className = (className + (state ? ' ' + name : '')).replace(R_SPACE, ' ');
241
+ }
242
+ }
243
+ }
244
+ function css(el, prop, val) {
245
+ var style = el && el.style;
246
+ if (style) {
247
+ if (val === void 0) {
248
+ if (document.defaultView && document.defaultView.getComputedStyle) {
249
+ val = document.defaultView.getComputedStyle(el, '');
250
+ } else if (el.currentStyle) {
251
+ val = el.currentStyle;
252
+ }
253
+ return prop === void 0 ? val : val[prop];
254
+ } else {
255
+ if (!(prop in style) && prop.indexOf('webkit') === -1) {
256
+ prop = '-webkit-' + prop;
257
+ }
258
+ style[prop] = val + (typeof val === 'string' ? '' : 'px');
259
+ }
260
+ }
261
+ }
262
+ function matrix(el, selfOnly) {
263
+ var appliedTransforms = '';
264
+ if (typeof el === 'string') {
265
+ appliedTransforms = el;
266
+ } else {
267
+ do {
268
+ var transform = css(el, 'transform');
269
+ if (transform && transform !== 'none') {
270
+ appliedTransforms = transform + ' ' + appliedTransforms;
271
+ }
272
+ /* jshint boss:true */
273
+ } while (!selfOnly && (el = el.parentNode));
274
+ }
275
+ var matrixFn = window.DOMMatrix || window.WebKitCSSMatrix || window.CSSMatrix || window.MSCSSMatrix;
276
+ /*jshint -W056 */
277
+ return matrixFn && new matrixFn(appliedTransforms);
278
+ }
279
+ function find(ctx, tagName, iterator) {
280
+ if (ctx) {
281
+ var list = ctx.getElementsByTagName(tagName),
282
+ i = 0,
283
+ n = list.length;
284
+ if (iterator) {
285
+ for (; i < n; i++) {
286
+ iterator(list[i], i);
287
+ }
288
+ }
289
+ return list;
290
+ }
291
+ return [];
292
+ }
293
+ function getWindowScrollingElement() {
294
+ var scrollingElement = document.scrollingElement;
295
+ if (scrollingElement) {
296
+ return scrollingElement;
297
+ } else {
298
+ return document.documentElement;
299
+ }
300
+ }
301
+
302
+ /**
303
+ * Returns the "bounding client rect" of given element
304
+ * @param {HTMLElement} el The element whose boundingClientRect is wanted
305
+ * @param {[Boolean]} relativeToContainingBlock Whether the rect should be relative to the containing block of (including) the container
306
+ * @param {[Boolean]} relativeToNonStaticParent Whether the rect should be relative to the relative parent of (including) the contaienr
307
+ * @param {[Boolean]} undoScale Whether the container's scale() should be undone
308
+ * @param {[HTMLElement]} container The parent the element will be placed in
309
+ * @return {Object} The boundingClientRect of el, with specified adjustments
310
+ */
311
+ function getRect(el, relativeToContainingBlock, relativeToNonStaticParent, undoScale, container) {
312
+ if (!el.getBoundingClientRect && el !== window) return;
313
+ var elRect, top, left, bottom, right, height, width;
314
+ if (el !== window && el.parentNode && el !== getWindowScrollingElement()) {
315
+ elRect = el.getBoundingClientRect();
316
+ top = elRect.top;
317
+ left = elRect.left;
318
+ bottom = elRect.bottom;
319
+ right = elRect.right;
320
+ height = elRect.height;
321
+ width = elRect.width;
322
+ } else {
323
+ top = 0;
324
+ left = 0;
325
+ bottom = window.innerHeight;
326
+ right = window.innerWidth;
327
+ height = window.innerHeight;
328
+ width = window.innerWidth;
329
+ }
330
+ if ((relativeToContainingBlock || relativeToNonStaticParent) && el !== window) {
331
+ // Adjust for translate()
332
+ container = container || el.parentNode;
333
+
334
+ // solves #1123 (see: https://stackoverflow.com/a/37953806/6088312)
335
+ // Not needed on <= IE11
336
+ if (!IE11OrLess) {
337
+ do {
338
+ if (container && container.getBoundingClientRect && (css(container, 'transform') !== 'none' || relativeToNonStaticParent && css(container, 'position') !== 'static')) {
339
+ var containerRect = container.getBoundingClientRect();
340
+
341
+ // Set relative to edges of padding box of container
342
+ top -= containerRect.top + parseInt(css(container, 'border-top-width'));
343
+ left -= containerRect.left + parseInt(css(container, 'border-left-width'));
344
+ bottom = top + elRect.height;
345
+ right = left + elRect.width;
346
+ break;
347
+ }
348
+ /* jshint boss:true */
349
+ } while (container = container.parentNode);
350
+ }
351
+ }
352
+ if (undoScale && el !== window) {
353
+ // Adjust for scale()
354
+ var elMatrix = matrix(container || el),
355
+ scaleX = elMatrix && elMatrix.a,
356
+ scaleY = elMatrix && elMatrix.d;
357
+ if (elMatrix) {
358
+ top /= scaleY;
359
+ left /= scaleX;
360
+ width /= scaleX;
361
+ height /= scaleY;
362
+ bottom = top + height;
363
+ right = left + width;
364
+ }
365
+ }
366
+ return {
367
+ top: top,
368
+ left: left,
369
+ bottom: bottom,
370
+ right: right,
371
+ width: width,
372
+ height: height
373
+ };
374
+ }
375
+
376
+ /**
377
+ * Checks if a side of an element is scrolled past a side of its parents
378
+ * @param {HTMLElement} el The element who's side being scrolled out of view is in question
379
+ * @param {String} elSide Side of the element in question ('top', 'left', 'right', 'bottom')
380
+ * @param {String} parentSide Side of the parent in question ('top', 'left', 'right', 'bottom')
381
+ * @return {HTMLElement} The parent scroll element that the el's side is scrolled past, or null if there is no such element
382
+ */
383
+ function isScrolledPast(el, elSide, parentSide) {
384
+ var parent = getParentAutoScrollElement(el, true),
385
+ elSideVal = getRect(el)[elSide];
386
+
387
+ /* jshint boss:true */
388
+ while (parent) {
389
+ var parentSideVal = getRect(parent)[parentSide],
390
+ visible = void 0;
391
+ if (parentSide === 'top' || parentSide === 'left') {
392
+ visible = elSideVal >= parentSideVal;
393
+ } else {
394
+ visible = elSideVal <= parentSideVal;
395
+ }
396
+ if (!visible) return parent;
397
+ if (parent === getWindowScrollingElement()) break;
398
+ parent = getParentAutoScrollElement(parent, false);
399
+ }
400
+ return false;
401
+ }
402
+
403
+ /**
404
+ * Gets nth child of el, ignoring hidden children, sortable's elements (does not ignore clone if it's visible)
405
+ * and non-draggable elements
406
+ * @param {HTMLElement} el The parent element
407
+ * @param {Number} childNum The index of the child
408
+ * @param {Object} options Parent Sortable's options
409
+ * @param {boolean} includeDragEl include dragging item
410
+ * @param {HTMLElement} ignoreEl exclude item
411
+ * @return {HTMLElement} The child at index childNum, or null if not found
412
+ */
413
+ function getChild(el, childNum, options, includeDragEl, ignoreEl) {
414
+ var currentChild = 0,
415
+ i = 0,
416
+ children = el.children;
417
+ while (i < children.length) {
418
+ if (children[i] !== ignoreEl && children[i].style.display !== 'none' && children[i] !== Sortable.ghost && (includeDragEl || children[i] !== Sortable.dragged) && closest(children[i], options.draggable, el, false)) {
419
+ if (currentChild === childNum) {
420
+ return children[i];
421
+ }
422
+ currentChild++;
423
+ }
424
+ i++;
425
+ }
426
+ return null;
427
+ }
428
+
429
+ /**
430
+ * Gets the last child in the el, ignoring ghostEl or invisible elements (clones)
431
+ * @param {HTMLElement} el Parent element
432
+ * @param {selector} selector Any other elements that should be ignored
433
+ * @return {HTMLElement} The last child, ignoring ghostEl
434
+ */
435
+ function lastChild(el, selector) {
436
+ var last = el.lastElementChild;
437
+ while (last && (last === Sortable.ghost || css(last, 'display') === 'none' || selector && !matches(last, selector))) {
438
+ last = last.previousElementSibling;
439
+ }
440
+ return last || null;
441
+ }
442
+
443
+ /**
444
+ * Returns the index of an element within its parent for a selected set of
445
+ * elements
446
+ * @param {HTMLElement} el
447
+ * @param {selector} selector
448
+ * @param {HTMLElement} ignoreEl
449
+ * @return {number}
450
+ */
451
+ function index(el, selector, ignoreEl) {
452
+ var index = 0;
453
+ if (!el || !el.parentNode) {
454
+ return -1;
455
+ }
456
+
457
+ /* jshint boss:true */
458
+ while (el = el.previousElementSibling) {
459
+ if (el.nodeName.toUpperCase() !== 'TEMPLATE' && el !== Sortable.clone && (!selector || matches(el, selector)) && el !== ignoreEl) {
460
+ index++;
461
+ }
462
+ }
463
+ return index;
464
+ }
465
+
466
+ /**
467
+ * Returns the scroll offset of the given element, added with all the scroll offsets of parent elements.
468
+ * The value is returned in real pixels.
469
+ * @param {HTMLElement} el
470
+ * @return {Array} Offsets in the format of [left, top]
471
+ */
472
+ function getRelativeScrollOffset(el) {
473
+ var offsetLeft = 0,
474
+ offsetTop = 0,
475
+ winScroller = getWindowScrollingElement();
476
+ if (el) {
477
+ do {
478
+ var elMatrix = matrix(el),
479
+ scaleX = elMatrix.a,
480
+ scaleY = elMatrix.d;
481
+ offsetLeft += el.scrollLeft * scaleX;
482
+ offsetTop += el.scrollTop * scaleY;
483
+ } while (el !== winScroller && (el = el.parentNode));
484
+ }
485
+ return [offsetLeft, offsetTop];
486
+ }
487
+
488
+ /**
489
+ * Returns the index of the object within the given array
490
+ * @param {Array} arr Array that may or may not hold the object
491
+ * @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
492
+ * @return {Number} The index of the object in the array, or -1
493
+ */
494
+ function indexOfObject(arr, obj) {
495
+ for (var i in arr) {
496
+ if (!arr.hasOwnProperty(i)) continue;
497
+ for (var key in obj) {
498
+ if (obj.hasOwnProperty(key) && obj[key] === arr[i][key]) return Number(i);
499
+ }
500
+ }
501
+ return -1;
502
+ }
503
+ function getParentAutoScrollElement(el, includeSelf) {
504
+ // skip to window
505
+ if (!el || !el.getBoundingClientRect) return getWindowScrollingElement();
506
+ var elem = el;
507
+ var gotSelf = false;
508
+ do {
509
+ // we don't need to get elem css if it isn't even overflowing in the first place (performance)
510
+ if (elem.clientWidth < elem.scrollWidth || elem.clientHeight < elem.scrollHeight) {
511
+ var elemCSS = css(elem);
512
+ if (elem.clientWidth < elem.scrollWidth && (elemCSS.overflowX == 'auto' || elemCSS.overflowX == 'scroll') || elem.clientHeight < elem.scrollHeight && (elemCSS.overflowY == 'auto' || elemCSS.overflowY == 'scroll')) {
513
+ if (!elem.getBoundingClientRect || elem === document.body) return getWindowScrollingElement();
514
+ if (gotSelf || includeSelf) return elem;
515
+ gotSelf = true;
516
+ }
517
+ }
518
+ /* jshint boss:true */
519
+ } while (elem = elem.parentNode);
520
+ return getWindowScrollingElement();
521
+ }
522
+ function extend(dst, src) {
523
+ if (dst && src) {
524
+ for (var key in src) {
525
+ if (src.hasOwnProperty(key)) {
526
+ dst[key] = src[key];
527
+ }
528
+ }
529
+ }
530
+ return dst;
531
+ }
532
+ function isRectEqual(rect1, rect2) {
533
+ 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);
534
+ }
535
+ var _throttleTimeout;
536
+ function throttle(callback, ms) {
537
+ return function () {
538
+ if (!_throttleTimeout) {
539
+ var args = arguments,
540
+ _this = this;
541
+ if (args.length === 1) {
542
+ callback.call(_this, args[0]);
543
+ } else {
544
+ callback.apply(_this, args);
545
+ }
546
+ _throttleTimeout = setTimeout(function () {
547
+ _throttleTimeout = void 0;
548
+ }, ms);
549
+ }
550
+ };
551
+ }
552
+ function cancelThrottle() {
553
+ clearTimeout(_throttleTimeout);
554
+ _throttleTimeout = void 0;
555
+ }
556
+ function scrollBy(el, x, y) {
557
+ el.scrollLeft += x;
558
+ el.scrollTop += y;
559
+ }
560
+ function clone(el) {
561
+ var Polymer = window.Polymer;
562
+ var $ = window.jQuery || window.Zepto;
563
+ if (Polymer && Polymer.dom) {
564
+ return Polymer.dom(el).cloneNode(true);
565
+ } else if ($) {
566
+ return $(el).clone(true)[0];
567
+ } else {
568
+ return el.cloneNode(true);
569
+ }
570
+ }
571
+ function setRect(el, rect) {
572
+ css(el, 'position', 'absolute');
573
+ css(el, 'top', rect.top);
574
+ css(el, 'left', rect.left);
575
+ css(el, 'width', rect.width);
576
+ css(el, 'height', rect.height);
577
+ }
578
+ function unsetRect(el) {
579
+ css(el, 'position', '');
580
+ css(el, 'top', '');
581
+ css(el, 'left', '');
582
+ css(el, 'width', '');
583
+ css(el, 'height', '');
584
+ }
585
+ function getChildContainingRectFromElement(container, options, ghostEl, ignoreEl) {
586
+ var rect = {};
587
+ Array.from(container.children).forEach(function (child) {
588
+ var _rect$left, _rect$top, _rect$right, _rect$bottom;
589
+ if (!closest(child, options.draggable, container, false, ignoreEl) || child.animated || child === ghostEl) return;
590
+ var childRect = getRect(child);
591
+ rect.left = Math.min((_rect$left = rect.left) !== null && _rect$left !== void 0 ? _rect$left : Infinity, childRect.left);
592
+ rect.top = Math.min((_rect$top = rect.top) !== null && _rect$top !== void 0 ? _rect$top : Infinity, childRect.top);
593
+ rect.right = Math.max((_rect$right = rect.right) !== null && _rect$right !== void 0 ? _rect$right : -Infinity, childRect.right);
594
+ rect.bottom = Math.max((_rect$bottom = rect.bottom) !== null && _rect$bottom !== void 0 ? _rect$bottom : -Infinity, childRect.bottom);
595
+ });
596
+ rect.width = rect.right - rect.left;
597
+ rect.height = rect.bottom - rect.top;
598
+ rect.x = rect.left;
599
+ rect.y = rect.top;
600
+ return rect;
601
+ }
602
+ var expando = 'Sortable' + new Date().getTime();
603
+
604
+ function AnimationStateManager() {
605
+ var animationStates = [],
606
+ animationCallbackId;
607
+ return {
608
+ captureAnimationState: function captureAnimationState() {
609
+ animationStates = [];
610
+ if (!this.options.animation) return;
611
+ var children = [].slice.call(this.el.children);
612
+ children.forEach(function (child) {
613
+ if (css(child, 'display') === 'none' || child === Sortable.ghost) return;
614
+ animationStates.push({
615
+ target: child,
616
+ rect: getRect(child)
617
+ });
618
+ var fromRect = _objectSpread2({}, animationStates[animationStates.length - 1].rect);
619
+
620
+ // If animating: compensate for current animation
621
+ if (child.thisAnimationDuration) {
622
+ var childMatrix = matrix(child, true);
623
+ if (childMatrix) {
624
+ fromRect.top -= childMatrix.f;
625
+ fromRect.left -= childMatrix.e;
626
+ }
627
+ }
628
+ child.fromRect = fromRect;
629
+ });
630
+ },
631
+ addAnimationState: function addAnimationState(state) {
632
+ animationStates.push(state);
633
+ },
634
+ removeAnimationState: function removeAnimationState(target) {
635
+ animationStates.splice(indexOfObject(animationStates, {
636
+ target: target
637
+ }), 1);
638
+ },
639
+ animateAll: function animateAll(callback) {
640
+ var _this = this;
641
+ if (!this.options.animation) {
642
+ clearTimeout(animationCallbackId);
643
+ if (typeof callback === 'function') callback();
644
+ return;
645
+ }
646
+ var animating = false,
647
+ animationTime = 0;
648
+ animationStates.forEach(function (state) {
649
+ var time = 0,
650
+ target = state.target,
651
+ fromRect = target.fromRect,
652
+ toRect = getRect(target),
653
+ prevFromRect = target.prevFromRect,
654
+ prevToRect = target.prevToRect,
655
+ animatingRect = state.rect,
656
+ targetMatrix = matrix(target, true);
657
+ if (targetMatrix) {
658
+ // Compensate for current animation
659
+ toRect.top -= targetMatrix.f;
660
+ toRect.left -= targetMatrix.e;
661
+ }
662
+ target.toRect = toRect;
663
+ if (target.thisAnimationDuration) {
664
+ // Could also check if animatingRect is between fromRect and toRect
665
+ if (isRectEqual(prevFromRect, toRect) && !isRectEqual(fromRect, toRect) &&
666
+ // Make sure animatingRect is on line between toRect & fromRect
667
+ (animatingRect.top - toRect.top) / (animatingRect.left - toRect.left) === (fromRect.top - toRect.top) / (fromRect.left - toRect.left)) {
668
+ // If returning to same place as started from animation and on same axis
669
+ time = calculateRealTime(animatingRect, prevFromRect, prevToRect, _this.options);
670
+ }
671
+ }
672
+
673
+ // if fromRect != toRect: animate
674
+ if (!isRectEqual(toRect, fromRect)) {
675
+ target.prevFromRect = fromRect;
676
+ target.prevToRect = toRect;
677
+ if (!time) {
678
+ time = _this.options.animation;
679
+ }
680
+ _this.animate(target, animatingRect, toRect, time);
681
+ }
682
+ if (time) {
683
+ animating = true;
684
+ animationTime = Math.max(animationTime, time);
685
+ clearTimeout(target.animationResetTimer);
686
+ target.animationResetTimer = setTimeout(function () {
687
+ target.animationTime = 0;
688
+ target.prevFromRect = null;
689
+ target.fromRect = null;
690
+ target.prevToRect = null;
691
+ target.thisAnimationDuration = null;
692
+ }, time);
693
+ target.thisAnimationDuration = time;
694
+ }
695
+ });
696
+ clearTimeout(animationCallbackId);
697
+ if (!animating) {
698
+ if (typeof callback === 'function') callback();
699
+ } else {
700
+ animationCallbackId = setTimeout(function () {
701
+ if (typeof callback === 'function') callback();
702
+ }, animationTime);
703
+ }
704
+ animationStates = [];
705
+ },
706
+ animate: function animate(target, currentRect, toRect, duration) {
707
+ if (duration) {
708
+ css(target, 'transition', '');
709
+ css(target, 'transform', '');
710
+ var elMatrix = matrix(this.el),
711
+ scaleX = elMatrix && elMatrix.a,
712
+ scaleY = elMatrix && elMatrix.d,
713
+ translateX = (currentRect.left - toRect.left) / (scaleX || 1),
714
+ translateY = (currentRect.top - toRect.top) / (scaleY || 1);
715
+ target.animatingX = !!translateX;
716
+ target.animatingY = !!translateY;
717
+ css(target, 'transform', 'translate3d(' + translateX + 'px,' + translateY + 'px,0)');
718
+ this.forRepaintDummy = repaint(target); // repaint
719
+
720
+ css(target, 'transition', 'transform ' + duration + 'ms' + (this.options.easing ? ' ' + this.options.easing : ''));
721
+ css(target, 'transform', 'translate3d(0,0,0)');
722
+ typeof target.animated === 'number' && clearTimeout(target.animated);
723
+ target.animated = setTimeout(function () {
724
+ css(target, 'transition', '');
725
+ css(target, 'transform', '');
726
+ target.animated = false;
727
+ target.animatingX = false;
728
+ target.animatingY = false;
729
+ }, duration);
730
+ }
731
+ }
732
+ };
733
+ }
734
+ function repaint(target) {
735
+ return target.offsetWidth;
736
+ }
737
+ function calculateRealTime(animatingRect, fromRect, toRect, options) {
738
+ 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;
739
+ }
740
+
741
+ var plugins = [];
742
+ var defaults = {
743
+ initializeByDefault: true
744
+ };
745
+ var PluginManager = {
746
+ mount: function mount(plugin) {
747
+ // Set default static properties
748
+ for (var option in defaults) {
749
+ if (defaults.hasOwnProperty(option) && !(option in plugin)) {
750
+ plugin[option] = defaults[option];
751
+ }
752
+ }
753
+ plugins.forEach(function (p) {
754
+ if (p.pluginName === plugin.pluginName) {
755
+ throw "Sortable: Cannot mount plugin ".concat(plugin.pluginName, " more than once");
756
+ }
757
+ });
758
+ plugins.push(plugin);
759
+ },
760
+ pluginEvent: function pluginEvent(eventName, sortable, evt) {
761
+ var _this = this;
762
+ this.eventCanceled = false;
763
+ evt.cancel = function () {
764
+ _this.eventCanceled = true;
765
+ };
766
+ var eventNameGlobal = eventName + 'Global';
767
+ plugins.forEach(function (plugin) {
768
+ if (!sortable[plugin.pluginName]) return;
769
+ // Fire global events if it exists in this sortable
770
+ if (sortable[plugin.pluginName][eventNameGlobal]) {
771
+ sortable[plugin.pluginName][eventNameGlobal](_objectSpread2({
772
+ sortable: sortable
773
+ }, evt));
774
+ }
775
+
776
+ // Only fire plugin event if plugin is enabled in this sortable,
777
+ // and plugin has event defined
778
+ if (sortable.options[plugin.pluginName] && sortable[plugin.pluginName][eventName]) {
779
+ sortable[plugin.pluginName][eventName](_objectSpread2({
780
+ sortable: sortable
781
+ }, evt));
782
+ }
783
+ });
784
+ },
785
+ initializePlugins: function initializePlugins(sortable, el, defaults, options) {
786
+ plugins.forEach(function (plugin) {
787
+ var pluginName = plugin.pluginName;
788
+ if (!sortable.options[pluginName] && !plugin.initializeByDefault) return;
789
+ var initialized = new plugin(sortable, el, sortable.options);
790
+ initialized.sortable = sortable;
791
+ initialized.options = sortable.options;
792
+ sortable[pluginName] = initialized;
793
+
794
+ // Add default options from plugin
795
+ _extends(defaults, initialized.defaults);
796
+ });
797
+ for (var option in sortable.options) {
798
+ if (!sortable.options.hasOwnProperty(option)) continue;
799
+ var modified = this.modifyOption(sortable, option, sortable.options[option]);
800
+ if (typeof modified !== 'undefined') {
801
+ sortable.options[option] = modified;
802
+ }
803
+ }
804
+ },
805
+ getEventProperties: function getEventProperties(name, sortable) {
806
+ var eventProperties = {};
807
+ plugins.forEach(function (plugin) {
808
+ if (typeof plugin.eventProperties !== 'function') return;
809
+ _extends(eventProperties, plugin.eventProperties.call(sortable[plugin.pluginName], name));
810
+ });
811
+ return eventProperties;
812
+ },
813
+ modifyOption: function modifyOption(sortable, name, value) {
814
+ var modifiedValue;
815
+ plugins.forEach(function (plugin) {
816
+ // Plugin must exist on the Sortable
817
+ if (!sortable[plugin.pluginName]) return;
818
+
819
+ // If static option listener exists for this option, call in the context of the Sortable's instance of this plugin
820
+ if (plugin.optionListeners && typeof plugin.optionListeners[name] === 'function') {
821
+ modifiedValue = plugin.optionListeners[name].call(sortable[plugin.pluginName], value);
822
+ }
823
+ });
824
+ return modifiedValue;
825
+ }
826
+ };
827
+
828
+ function dispatchEvent(_ref) {
829
+ var sortable = _ref.sortable,
830
+ rootEl = _ref.rootEl,
831
+ name = _ref.name,
832
+ targetEl = _ref.targetEl,
833
+ cloneEl = _ref.cloneEl,
834
+ toEl = _ref.toEl,
835
+ fromEl = _ref.fromEl,
836
+ oldIndex = _ref.oldIndex,
837
+ newIndex = _ref.newIndex,
838
+ oldDraggableIndex = _ref.oldDraggableIndex,
839
+ newDraggableIndex = _ref.newDraggableIndex,
840
+ originalEvent = _ref.originalEvent,
841
+ putSortable = _ref.putSortable,
842
+ extraEventProperties = _ref.extraEventProperties;
843
+ sortable = sortable || rootEl && rootEl[expando];
844
+ if (!sortable) return;
845
+ var evt,
846
+ options = sortable.options,
847
+ onName = 'on' + name.charAt(0).toUpperCase() + name.substr(1);
848
+ // Support for new CustomEvent feature
849
+ if (window.CustomEvent && !IE11OrLess && !Edge) {
850
+ evt = new CustomEvent(name, {
851
+ bubbles: true,
852
+ cancelable: true
853
+ });
854
+ } else {
855
+ evt = document.createEvent('Event');
856
+ evt.initEvent(name, true, true);
857
+ }
858
+ evt.to = toEl || rootEl;
859
+ evt.from = fromEl || rootEl;
860
+ evt.item = targetEl || rootEl;
861
+ evt.clone = cloneEl;
862
+ evt.oldIndex = oldIndex;
863
+ evt.newIndex = newIndex;
864
+ evt.oldDraggableIndex = oldDraggableIndex;
865
+ evt.newDraggableIndex = newDraggableIndex;
866
+ evt.originalEvent = originalEvent;
867
+ evt.pullMode = putSortable ? putSortable.lastPutMode : undefined;
868
+ var allEventProperties = _objectSpread2(_objectSpread2({}, extraEventProperties), PluginManager.getEventProperties(name, sortable));
869
+ for (var option in allEventProperties) {
870
+ evt[option] = allEventProperties[option];
871
+ }
872
+ if (rootEl) {
873
+ rootEl.dispatchEvent(evt);
874
+ }
875
+ if (options[onName]) {
876
+ options[onName].call(sortable, evt);
877
+ }
878
+ }
879
+
880
+ var _excluded = ["evt"];
881
+ var pluginEvent = function pluginEvent(eventName, sortable) {
882
+ var _ref = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {},
883
+ originalEvent = _ref.evt,
884
+ data = _objectWithoutProperties(_ref, _excluded);
885
+ PluginManager.pluginEvent.bind(Sortable)(eventName, sortable, _objectSpread2({
886
+ dragEl: dragEl,
887
+ originalDragEl: originalDragEl,
888
+ originalDragElDisplay: originalDragElDisplay,
889
+ parentEl: parentEl,
890
+ ghostEl: ghostEl,
891
+ rootEl: rootEl,
892
+ nextEl: nextEl,
893
+ lastDownEl: lastDownEl,
894
+ cloneEl: cloneEl,
895
+ cloneHidden: cloneHidden,
896
+ dragStarted: moved,
897
+ putSortable: putSortable,
898
+ activeSortable: Sortable.active,
899
+ originalEvent: originalEvent,
900
+ oldIndex: oldIndex,
901
+ oldDraggableIndex: oldDraggableIndex,
902
+ newIndex: newIndex,
903
+ newDraggableIndex: newDraggableIndex,
904
+ hideGhostForTarget: _hideGhostForTarget,
905
+ unhideGhostForTarget: _unhideGhostForTarget,
906
+ cloneNowHidden: function cloneNowHidden() {
907
+ cloneHidden = true;
908
+ },
909
+ cloneNowShown: function cloneNowShown() {
910
+ cloneHidden = false;
911
+ },
912
+ dispatchSortableEvent: function dispatchSortableEvent(name) {
913
+ _dispatchEvent({
914
+ sortable: sortable,
915
+ name: name,
916
+ originalEvent: originalEvent
917
+ });
918
+ }
919
+ }, data));
920
+ };
921
+ function _dispatchEvent(info) {
922
+ dispatchEvent(_objectSpread2({
923
+ putSortable: putSortable,
924
+ cloneEl: cloneEl,
925
+ targetEl: originalDragEl || dragEl,
926
+ rootEl: rootEl,
927
+ oldIndex: oldIndex,
928
+ oldDraggableIndex: oldDraggableIndex,
929
+ newIndex: newIndex,
930
+ newDraggableIndex: newDraggableIndex
931
+ }, info));
932
+ }
933
+ var dragEl,
934
+ originalDragEl,
935
+ originalDragElDisplay,
936
+ parentEl,
937
+ ghostEl,
938
+ rootEl,
939
+ nextEl,
940
+ lastDownEl,
941
+ cloneEl,
942
+ cloneHidden,
943
+ oldIndex,
944
+ newIndex,
945
+ oldDraggableIndex,
946
+ newDraggableIndex,
947
+ activeGroup,
948
+ putSortable,
949
+ awaitingDragStarted = false,
950
+ ignoreNextClick = false,
951
+ sortables = [],
952
+ tapEvt,
953
+ touchEvt,
954
+ lastDx,
955
+ lastDy,
956
+ tapDistanceLeft,
957
+ tapDistanceTop,
958
+ moved,
959
+ lastTarget,
960
+ lastDirection,
961
+ pastFirstInvertThresh = false,
962
+ isCircumstantialInvert = false,
963
+ targetMoveDistance,
964
+ // For positioning ghost absolutely
965
+ ghostRelativeParent,
966
+ ghostRelativeParentInitialScroll = [],
967
+ // (left, top)
968
+
969
+ _silent = false,
970
+ savedInputChecked = [];
971
+
972
+ /** @const */
973
+ var documentExists = typeof document !== 'undefined',
974
+ PositionGhostAbsolutely = IOS,
975
+ CSSFloatProperty = Edge || IE11OrLess ? 'cssFloat' : 'float',
976
+ // This will not pass for IE9, because IE9 DnD only works on anchors
977
+ supportDraggable = documentExists && !ChromeForAndroid && !IOS && 'draggable' in document.createElement('div'),
978
+ supportCssPointerEvents = function () {
979
+ if (!documentExists) return;
980
+ // false when <= IE11
981
+ if (IE11OrLess) {
982
+ return false;
983
+ }
984
+ var el = document.createElement('x');
985
+ el.style.cssText = 'pointer-events:auto';
986
+ return el.style.pointerEvents === 'auto';
987
+ }(),
988
+ _detectDirection = function _detectDirection(el, options) {
989
+ var elCSS = css(el),
990
+ elWidth = parseInt(elCSS.width) - parseInt(elCSS.paddingLeft) - parseInt(elCSS.paddingRight) - parseInt(elCSS.borderLeftWidth) - parseInt(elCSS.borderRightWidth),
991
+ child1 = getChild(el, 0, options, false, originalDragEl),
992
+ child2 = getChild(el, 1, options, false, originalDragEl),
993
+ firstChildCSS = child1 && css(child1),
994
+ secondChildCSS = child2 && css(child2),
995
+ firstChildWidth = firstChildCSS && parseInt(firstChildCSS.marginLeft) + parseInt(firstChildCSS.marginRight) + getRect(child1).width,
996
+ secondChildWidth = secondChildCSS && parseInt(secondChildCSS.marginLeft) + parseInt(secondChildCSS.marginRight) + getRect(child2).width;
997
+ if (elCSS.display === 'flex') {
998
+ return elCSS.flexDirection === 'column' || elCSS.flexDirection === 'column-reverse' ? 'vertical' : 'horizontal';
999
+ }
1000
+ if (elCSS.display === 'grid') {
1001
+ return elCSS.gridTemplateColumns.split(' ').length <= 1 ? 'vertical' : 'horizontal';
1002
+ }
1003
+ if (child1 && firstChildCSS["float"] && firstChildCSS["float"] !== 'none') {
1004
+ var touchingSideChild2 = firstChildCSS["float"] === 'left' ? 'left' : 'right';
1005
+ return child2 && (secondChildCSS.clear === 'both' || secondChildCSS.clear === touchingSideChild2) ? 'vertical' : 'horizontal';
1006
+ }
1007
+ 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';
1008
+ },
1009
+ _dragElInRowColumn = function _dragElInRowColumn(dragRect, targetRect, vertical) {
1010
+ var dragElS1Opp = vertical ? dragRect.left : dragRect.top,
1011
+ dragElS2Opp = vertical ? dragRect.right : dragRect.bottom,
1012
+ dragElOppLength = vertical ? dragRect.width : dragRect.height,
1013
+ targetS1Opp = vertical ? targetRect.left : targetRect.top,
1014
+ targetS2Opp = vertical ? targetRect.right : targetRect.bottom,
1015
+ targetOppLength = vertical ? targetRect.width : targetRect.height;
1016
+ return dragElS1Opp === targetS1Opp || dragElS2Opp === targetS2Opp || dragElS1Opp + dragElOppLength / 2 === targetS1Opp + targetOppLength / 2;
1017
+ },
1018
+ /**
1019
+ * Detects first nearest empty sortable to X and Y position using emptyInsertThreshold.
1020
+ * @param {Number} x X position
1021
+ * @param {Number} y Y position
1022
+ * @return {HTMLElement} Element of the first found nearest Sortable
1023
+ */
1024
+ _detectNearestEmptySortable = function _detectNearestEmptySortable(x, y) {
1025
+ var ret;
1026
+ sortables.some(function (sortable) {
1027
+ var threshold = sortable[expando].options.emptyInsertThreshold;
1028
+ if (!threshold || lastChild(sortable)) return;
1029
+ var rect = getRect(sortable),
1030
+ insideHorizontally = x >= rect.left - threshold && x <= rect.right + threshold,
1031
+ insideVertically = y >= rect.top - threshold && y <= rect.bottom + threshold;
1032
+ if (insideHorizontally && insideVertically) {
1033
+ return ret = sortable;
1034
+ }
1035
+ });
1036
+ return ret;
1037
+ },
1038
+ _prepareGroup = function _prepareGroup(options) {
1039
+ function toFn(value, pull) {
1040
+ return function (to, from, dragEl, evt) {
1041
+ var sameGroup = to.options.group.name && from.options.group.name && to.options.group.name === from.options.group.name;
1042
+ if (value == null && (pull || sameGroup)) {
1043
+ // Default pull value
1044
+ // Default pull and put value if same group
1045
+ return true;
1046
+ } else if (value == null || value === false) {
1047
+ return false;
1048
+ } else if (pull && value === 'clone') {
1049
+ return value;
1050
+ } else if (typeof value === 'function') {
1051
+ return toFn(value(to, from, dragEl, evt), pull)(to, from, dragEl, evt);
1052
+ } else {
1053
+ var otherGroup = (pull ? to : from).options.group.name;
1054
+ return value === true || typeof value === 'string' && value === otherGroup || value.join && value.indexOf(otherGroup) > -1;
1055
+ }
1056
+ };
1057
+ }
1058
+ var group = {};
1059
+ var originalGroup = options.group;
1060
+ if (!originalGroup || _typeof(originalGroup) != 'object') {
1061
+ originalGroup = {
1062
+ name: originalGroup
1063
+ };
1064
+ }
1065
+ group.name = originalGroup.name;
1066
+ group.checkPull = toFn(originalGroup.pull, true);
1067
+ group.checkPut = toFn(originalGroup.put);
1068
+ group.revertClone = originalGroup.revertClone;
1069
+ options.group = group;
1070
+ },
1071
+ _hideGhostForTarget = function _hideGhostForTarget() {
1072
+ if (!supportCssPointerEvents && ghostEl) {
1073
+ css(ghostEl, 'display', 'none');
1074
+ }
1075
+ },
1076
+ _unhideGhostForTarget = function _unhideGhostForTarget() {
1077
+ if (!supportCssPointerEvents && ghostEl) {
1078
+ css(ghostEl, 'display', '');
1079
+ }
1080
+ };
1081
+
1082
+ // #1184 fix - Prevent click event on fallback if dragged but item not changed position
1083
+ if (documentExists && !ChromeForAndroid) {
1084
+ document.addEventListener('click', function (evt) {
1085
+ if (ignoreNextClick) {
1086
+ evt.preventDefault();
1087
+ evt.stopPropagation && evt.stopPropagation();
1088
+ evt.stopImmediatePropagation && evt.stopImmediatePropagation();
1089
+ ignoreNextClick = false;
1090
+ return false;
1091
+ }
1092
+ }, true);
1093
+ }
1094
+ var nearestEmptyInsertDetectEvent = function nearestEmptyInsertDetectEvent(evt) {
1095
+ if (dragEl) {
1096
+ evt = evt.touches ? evt.touches[0] : evt;
1097
+ var nearest = _detectNearestEmptySortable(evt.clientX, evt.clientY);
1098
+ if (nearest) {
1099
+ // Create imitation event
1100
+ var event = {};
1101
+ for (var i in evt) {
1102
+ if (evt.hasOwnProperty(i)) {
1103
+ event[i] = evt[i];
1104
+ }
1105
+ }
1106
+ event.target = event.rootEl = nearest;
1107
+ event.preventDefault = void 0;
1108
+ event.stopPropagation = void 0;
1109
+ nearest[expando]._onDragOver(event);
1110
+ }
1111
+ }
1112
+ };
1113
+ var _checkOutsideTargetEl = function _checkOutsideTargetEl(evt) {
1114
+ if (dragEl) {
1115
+ dragEl.parentNode[expando]._isOutsideThisEl(evt.target);
1116
+ }
1117
+ };
1118
+
1119
+ /**
1120
+ * @class Sortable
1121
+ * @param {HTMLElement} el
1122
+ * @param {Object} [options]
1123
+ */
1124
+ function Sortable(el, options) {
1125
+ if (!(el && el.nodeType && el.nodeType === 1)) {
1126
+ throw "Sortable: `el` must be an HTMLElement, not ".concat({}.toString.call(el));
1127
+ }
1128
+ this.el = el; // root element
1129
+ this.options = options = _extends({}, options);
1130
+
1131
+ // Export instance
1132
+ el[expando] = this;
1133
+ var defaults = {
1134
+ group: null,
1135
+ sort: true,
1136
+ disabled: false,
1137
+ store: null,
1138
+ handle: null,
1139
+ draggable: /^[uo]l$/i.test(el.nodeName) ? '>li' : '>*',
1140
+ swapThreshold: 1,
1141
+ // percentage; 0 <= x <= 1
1142
+ invertSwap: false,
1143
+ // invert always
1144
+ invertedSwapThreshold: null,
1145
+ // will be set to same as swapThreshold if default
1146
+ removeCloneOnHide: true,
1147
+ direction: function direction() {
1148
+ return _detectDirection(el, this.options);
1149
+ },
1150
+ ghostClass: 'sortable-ghost',
1151
+ chosenClass: 'sortable-chosen',
1152
+ dragClass: 'sortable-drag',
1153
+ ignore: 'a, img',
1154
+ filter: null,
1155
+ preventOnFilter: true,
1156
+ getGhostFallback: undefined,
1157
+ getPlaceholder: undefined,
1158
+ getPlaceholderOnMove: undefined,
1159
+ tree: false,
1160
+ treeItemLevelAttr: 'data-level',
1161
+ treeIndentThreshold: 10,
1162
+ animation: 0,
1163
+ easing: null,
1164
+ setData: function setData(dataTransfer, dragEl) {
1165
+ dataTransfer.setData('Text', dragEl.textContent);
1166
+ },
1167
+ dropBubble: false,
1168
+ dragoverBubble: false,
1169
+ dataIdAttr: 'data-id',
1170
+ delay: 0,
1171
+ delayOnTouchOnly: false,
1172
+ touchStartThreshold: (Number.parseInt ? Number : window).parseInt(window.devicePixelRatio, 10) || 1,
1173
+ forceFallback: false,
1174
+ fallbackClass: 'sortable-fallback',
1175
+ fallbackOnBody: false,
1176
+ fallbackTolerance: 0,
1177
+ fallbackOffset: {
1178
+ x: 0,
1179
+ y: 0
1180
+ },
1181
+ // Disabled on Safari: #1571; Enabled on Safari IOS: #2244
1182
+ supportPointer: Sortable.supportPointer !== false && 'PointerEvent' in window && (!Safari || IOS),
1183
+ emptyInsertThreshold: 5
1184
+ };
1185
+ PluginManager.initializePlugins(this, el, defaults);
1186
+
1187
+ // Set default options
1188
+ for (var name in defaults) {
1189
+ !(name in options) && (options[name] = defaults[name]);
1190
+ }
1191
+ _prepareGroup(options);
1192
+
1193
+ // Bind all private methods
1194
+ for (var fn in this) {
1195
+ if (fn.charAt(0) === '_' && typeof this[fn] === 'function') {
1196
+ this[fn] = this[fn].bind(this);
1197
+ }
1198
+ }
1199
+
1200
+ // Setup drag mode
1201
+ this.nativeDraggable = options.forceFallback ? false : supportDraggable;
1202
+ if (this.nativeDraggable) {
1203
+ // Touch start threshold cannot be greater than the native dragstart threshold
1204
+ this.options.touchStartThreshold = 1;
1205
+ }
1206
+
1207
+ // Bind events
1208
+ if (options.supportPointer) {
1209
+ on(el, 'pointerdown', this._onTapStart);
1210
+ } else {
1211
+ on(el, 'mousedown', this._onTapStart);
1212
+ on(el, 'touchstart', this._onTapStart);
1213
+ }
1214
+ if (this.nativeDraggable) {
1215
+ on(el, 'dragover', this);
1216
+ on(el, 'dragenter', this);
1217
+ }
1218
+ sortables.push(this.el);
1219
+
1220
+ // Restore sorting
1221
+ options.store && options.store.get && this.sort(options.store.get(this) || []);
1222
+
1223
+ // Add animation state manager
1224
+ _extends(this, AnimationStateManager());
1225
+ }
1226
+ Sortable.prototype = /** @lends Sortable.prototype */{
1227
+ constructor: Sortable,
1228
+ _isOutsideThisEl: function _isOutsideThisEl(target) {
1229
+ if (!this.el.contains(target) && target !== this.el) {
1230
+ lastTarget = null;
1231
+ }
1232
+ },
1233
+ _getDirection: function _getDirection(evt, target) {
1234
+ return typeof this.options.direction === 'function' ? this.options.direction.call(this, evt, target, originalDragEl || dragEl) : this.options.direction;
1235
+ },
1236
+ _onTapStart: function _onTapStart(/** Event|TouchEvent */evt) {
1237
+ if (!evt.cancelable) return;
1238
+ var _this = this,
1239
+ el = this.el,
1240
+ options = this.options,
1241
+ preventOnFilter = options.preventOnFilter,
1242
+ type = evt.type,
1243
+ touch = evt.touches && evt.touches[0] || evt.pointerType && evt.pointerType === 'touch' && evt,
1244
+ target = (touch || evt).target,
1245
+ originalTarget = evt.target.shadowRoot && (evt.path && evt.path[0] || evt.composedPath && evt.composedPath()[0]) || target,
1246
+ filter = options.filter;
1247
+ _saveInputCheckedState(el);
1248
+
1249
+ // Don't trigger start event when an element is been dragged, otherwise the evt.oldindex always wrong when set option.group.
1250
+ if (dragEl) {
1251
+ return;
1252
+ }
1253
+ if (/mousedown|pointerdown/.test(type) && evt.button !== 0 || options.disabled) {
1254
+ return; // only left button and enabled
1255
+ }
1256
+
1257
+ // cancel dnd if original target is content editable
1258
+ if (originalTarget.isContentEditable) {
1259
+ return;
1260
+ }
1261
+
1262
+ // Safari ignores further event handling after mousedown
1263
+ if (!this.nativeDraggable && Safari && target && target.tagName.toUpperCase() === 'SELECT') {
1264
+ return;
1265
+ }
1266
+ target = closest(target, options.draggable, el, false, originalDragEl);
1267
+ if (target && target.animated) {
1268
+ return;
1269
+ }
1270
+ if (lastDownEl === target) {
1271
+ // Ignoring duplicate `down`
1272
+ return;
1273
+ }
1274
+
1275
+ // Get the index of the dragged element within its parent
1276
+ oldIndex = index(target, undefined, originalDragEl);
1277
+ oldDraggableIndex = index(target, options.draggable, originalDragEl);
1278
+
1279
+ // Check filter
1280
+ if (typeof filter === 'function') {
1281
+ if (filter.call(this, evt, target, this)) {
1282
+ _dispatchEvent({
1283
+ sortable: _this,
1284
+ rootEl: originalTarget,
1285
+ name: 'filter',
1286
+ targetEl: target,
1287
+ toEl: el,
1288
+ fromEl: el
1289
+ });
1290
+ pluginEvent('filter', _this, {
1291
+ evt: evt
1292
+ });
1293
+ preventOnFilter && evt.preventDefault();
1294
+ return; // cancel dnd
1295
+ }
1296
+ } else if (filter) {
1297
+ filter = filter.split(',').some(function (criteria) {
1298
+ criteria = closest(originalTarget, criteria.trim(), el, false, originalDragEl);
1299
+ if (criteria) {
1300
+ _dispatchEvent({
1301
+ sortable: _this,
1302
+ rootEl: criteria,
1303
+ name: 'filter',
1304
+ targetEl: target,
1305
+ fromEl: el,
1306
+ toEl: el
1307
+ });
1308
+ pluginEvent('filter', _this, {
1309
+ evt: evt
1310
+ });
1311
+ return true;
1312
+ }
1313
+ });
1314
+ if (filter) {
1315
+ preventOnFilter && evt.preventDefault();
1316
+ return; // cancel dnd
1317
+ }
1318
+ }
1319
+ if (options.handle && !closest(originalTarget, options.handle, el, false, originalDragEl)) {
1320
+ return;
1321
+ }
1322
+
1323
+ // Prepare `dragstart`
1324
+ this._prepareDragStart(evt, touch, target);
1325
+ },
1326
+ _prepareDragStart: function _prepareDragStart(/** Event */evt, /** Touch */touch, /** HTMLElement */target) {
1327
+ var _this = this,
1328
+ el = _this.el,
1329
+ options = _this.options,
1330
+ ownerDocument = el.ownerDocument,
1331
+ dragStartFn;
1332
+ if (target && !dragEl && target.parentNode === el) {
1333
+ var dragRect = getRect(target);
1334
+ rootEl = el;
1335
+ dragEl = target;
1336
+ parentEl = dragEl.parentNode;
1337
+ nextEl = dragEl.nextSibling;
1338
+ lastDownEl = target;
1339
+ activeGroup = options.group;
1340
+ Sortable.dragged = dragEl;
1341
+ tapEvt = {
1342
+ target: dragEl,
1343
+ clientX: (touch || evt).clientX,
1344
+ clientY: (touch || evt).clientY
1345
+ };
1346
+ tapDistanceLeft = tapEvt.clientX - dragRect.left;
1347
+ tapDistanceTop = tapEvt.clientY - dragRect.top;
1348
+ this._lastX = (touch || evt).clientX;
1349
+ this._lastY = (touch || evt).clientY;
1350
+ dragEl.style['will-change'] = 'all';
1351
+ dragStartFn = function dragStartFn() {
1352
+ pluginEvent('delayEnded', _this, {
1353
+ evt: evt
1354
+ });
1355
+ if (Sortable.eventCanceled) {
1356
+ _this._onDrop();
1357
+ return;
1358
+ }
1359
+ // Delayed drag has been triggered
1360
+ // we can re-enable the events: touchmove/mousemove
1361
+ _this._disableDelayedDragEvents();
1362
+ if (!FireFox && _this.nativeDraggable) {
1363
+ dragEl.draggable = true;
1364
+ }
1365
+
1366
+ // Bind the events: dragstart/dragend
1367
+ _this._triggerDragStart(evt, touch);
1368
+
1369
+ // Drag start event
1370
+ _dispatchEvent({
1371
+ sortable: _this,
1372
+ name: 'choose',
1373
+ originalEvent: evt
1374
+ });
1375
+
1376
+ // Chosen item
1377
+ toggleClass(dragEl, options.chosenClass, true);
1378
+ };
1379
+
1380
+ // Disable "draggable"
1381
+ options.ignore.split(',').forEach(function (criteria) {
1382
+ find(dragEl, criteria.trim(), _disableDraggable);
1383
+ });
1384
+ on(ownerDocument, 'dragover', nearestEmptyInsertDetectEvent);
1385
+ on(ownerDocument, 'mousemove', nearestEmptyInsertDetectEvent);
1386
+ on(ownerDocument, 'touchmove', nearestEmptyInsertDetectEvent);
1387
+ if (options.supportPointer) {
1388
+ on(ownerDocument, 'pointerup', _this._onDrop);
1389
+ // Native D&D triggers pointercancel
1390
+ !this.nativeDraggable && on(ownerDocument, 'pointercancel', _this._onDrop);
1391
+ } else {
1392
+ on(ownerDocument, 'mouseup', _this._onDrop);
1393
+ on(ownerDocument, 'touchend', _this._onDrop);
1394
+ on(ownerDocument, 'touchcancel', _this._onDrop);
1395
+ }
1396
+
1397
+ // Make dragEl draggable (must be before delay for FireFox)
1398
+ if (FireFox && this.nativeDraggable) {
1399
+ this.options.touchStartThreshold = 4;
1400
+ dragEl.draggable = true;
1401
+ }
1402
+ pluginEvent('delayStart', this, {
1403
+ evt: evt
1404
+ });
1405
+
1406
+ // Delay is impossible for native DnD in Edge or IE
1407
+ if (options.delay && (!options.delayOnTouchOnly || touch) && (!this.nativeDraggable || !(Edge || IE11OrLess))) {
1408
+ if (Sortable.eventCanceled) {
1409
+ this._onDrop();
1410
+ return;
1411
+ }
1412
+ // If the user moves the pointer or let go the click or touch
1413
+ // before the delay has been reached:
1414
+ // disable the delayed drag
1415
+ if (options.supportPointer) {
1416
+ on(ownerDocument, 'pointerup', _this._disableDelayedDrag);
1417
+ on(ownerDocument, 'pointercancel', _this._disableDelayedDrag);
1418
+ } else {
1419
+ on(ownerDocument, 'mouseup', _this._disableDelayedDrag);
1420
+ on(ownerDocument, 'touchend', _this._disableDelayedDrag);
1421
+ on(ownerDocument, 'touchcancel', _this._disableDelayedDrag);
1422
+ }
1423
+ on(ownerDocument, 'mousemove', _this._delayedDragTouchMoveHandler);
1424
+ on(ownerDocument, 'touchmove', _this._delayedDragTouchMoveHandler);
1425
+ options.supportPointer && on(ownerDocument, 'pointermove', _this._delayedDragTouchMoveHandler);
1426
+ _this._dragStartTimer = setTimeout(dragStartFn, options.delay);
1427
+ } else {
1428
+ dragStartFn();
1429
+ }
1430
+ }
1431
+ },
1432
+ _delayedDragTouchMoveHandler: function _delayedDragTouchMoveHandler(/** TouchEvent|PointerEvent **/e) {
1433
+ var touch = e.touches ? e.touches[0] : e;
1434
+ 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))) {
1435
+ this._disableDelayedDrag();
1436
+ }
1437
+ },
1438
+ _disableDelayedDrag: function _disableDelayedDrag() {
1439
+ dragEl && _disableDraggable(dragEl);
1440
+ clearTimeout(this._dragStartTimer);
1441
+ this._disableDelayedDragEvents();
1442
+ },
1443
+ _disableDelayedDragEvents: function _disableDelayedDragEvents() {
1444
+ var ownerDocument = this.el.ownerDocument;
1445
+ off(ownerDocument, 'mouseup', this._disableDelayedDrag);
1446
+ off(ownerDocument, 'touchend', this._disableDelayedDrag);
1447
+ off(ownerDocument, 'touchcancel', this._disableDelayedDrag);
1448
+ off(ownerDocument, 'pointerup', this._disableDelayedDrag);
1449
+ off(ownerDocument, 'pointercancel', this._disableDelayedDrag);
1450
+ off(ownerDocument, 'mousemove', this._delayedDragTouchMoveHandler);
1451
+ off(ownerDocument, 'touchmove', this._delayedDragTouchMoveHandler);
1452
+ off(ownerDocument, 'pointermove', this._delayedDragTouchMoveHandler);
1453
+ },
1454
+ _triggerDragStart: function _triggerDragStart(/** Event */evt, /** Touch */touch) {
1455
+ touch = touch || evt.pointerType == 'touch' && evt;
1456
+ if (!this.nativeDraggable || touch) {
1457
+ if (this.options.supportPointer) {
1458
+ on(document, 'pointermove', this._onTouchMove);
1459
+ } else if (touch) {
1460
+ on(document, 'touchmove', this._onTouchMove);
1461
+ } else {
1462
+ on(document, 'mousemove', this._onTouchMove);
1463
+ }
1464
+ } else {
1465
+ on(dragEl, 'dragend', this);
1466
+ on(rootEl, 'dragstart', this._onDragStart);
1467
+ }
1468
+ try {
1469
+ if (document.selection) {
1470
+ _nextTick(function () {
1471
+ document.selection.empty();
1472
+ });
1473
+ } else {
1474
+ window.getSelection().removeAllRanges();
1475
+ }
1476
+ } catch (err) {}
1477
+ },
1478
+ _getPlaceholder: function _getPlaceholder() {
1479
+ if (typeof this.options.getPlaceholder === 'function') {
1480
+ originalDragEl = dragEl;
1481
+ originalDragElDisplay = dragEl.style.display;
1482
+ dragEl = this.options.getPlaceholder(dragEl);
1483
+ if (dragEl && originalDragEl) {
1484
+ originalDragEl.after(dragEl);
1485
+ css(originalDragEl, 'display', 'none');
1486
+ css(originalDragEl, 'transform', '');
1487
+ toggleClass(originalDragEl, this.options.dragClass, false);
1488
+ toggleClass(originalDragEl, this.options.ghostClass, false);
1489
+ toggleClass(originalDragEl, this.options.chosenClass, false);
1490
+ }
1491
+ pluginEvent('getPlaceholder', this);
1492
+ }
1493
+ },
1494
+ _removeClonedSelectedItem: function _removeClonedSelectedItem() {
1495
+ if (typeof this.options.getPlaceholder === 'function' || typeof this.options.getPlaceholderOnMove === 'function') {
1496
+ if (dragEl && originalDragEl) {
1497
+ css(originalDragEl, 'display', originalDragElDisplay || '');
1498
+ dragEl.remove();
1499
+ }
1500
+ }
1501
+ },
1502
+ _replacePlaceholder: function _replacePlaceholder(newDragEl) {
1503
+ var parent = dragEl.parentNode;
1504
+ if (parent) {
1505
+ parent.replaceChild(newDragEl, dragEl);
1506
+ } else {
1507
+ dragEl.remove();
1508
+ }
1509
+ dragEl = newDragEl;
1510
+ },
1511
+ _getPlaceholderOnMove: function _getPlaceholderOnMove(el, dragRect, target, targetRect, evt, after) {
1512
+ if (typeof this.options.getPlaceholderOnMove === 'function') {
1513
+ var newPlaceholder = this.options.getPlaceholderOnMove(getMoveEvent(rootEl, el, originalDragEl || dragEl, dragRect, target, targetRect, evt, after));
1514
+ if (newPlaceholder) {
1515
+ this._replacePlaceholder(newPlaceholder);
1516
+ }
1517
+ }
1518
+ },
1519
+ _dragStarted: function _dragStarted(fallback, evt) {
1520
+ awaitingDragStarted = false;
1521
+ if (rootEl && dragEl) {
1522
+ this._getPlaceholder();
1523
+ pluginEvent('dragStarted', this, {
1524
+ evt: evt
1525
+ });
1526
+ if (this.nativeDraggable) {
1527
+ on(document, 'dragover', _checkOutsideTargetEl);
1528
+ }
1529
+ var options = this.options;
1530
+
1531
+ // Apply effect
1532
+ !fallback && toggleClass(dragEl, options.dragClass, false);
1533
+ toggleClass(dragEl, options.ghostClass, true);
1534
+ Sortable.active = this;
1535
+ fallback && this._appendGhost();
1536
+
1537
+ // Drag start event
1538
+ _dispatchEvent({
1539
+ sortable: this,
1540
+ name: 'start',
1541
+ originalEvent: evt
1542
+ });
1543
+ } else {
1544
+ this._nulling();
1545
+ }
1546
+ },
1547
+ _emulateDragOver: function _emulateDragOver() {
1548
+ if (touchEvt) {
1549
+ this._lastX = touchEvt.clientX;
1550
+ this._lastY = touchEvt.clientY;
1551
+ _hideGhostForTarget();
1552
+ var target = document.elementFromPoint(touchEvt.clientX, touchEvt.clientY);
1553
+ var parent = target;
1554
+ while (target && target.shadowRoot) {
1555
+ target = target.shadowRoot.elementFromPoint(touchEvt.clientX, touchEvt.clientY);
1556
+ if (target === parent) break;
1557
+ parent = target;
1558
+ }
1559
+ dragEl.parentNode[expando]._isOutsideThisEl(target);
1560
+ if (parent) {
1561
+ do {
1562
+ if (parent[expando]) {
1563
+ var inserted = void 0;
1564
+ inserted = parent[expando]._onDragOver({
1565
+ clientX: touchEvt.clientX,
1566
+ clientY: touchEvt.clientY,
1567
+ target: target,
1568
+ rootEl: parent
1569
+ });
1570
+ if (inserted && !this.options.dragoverBubble) {
1571
+ break;
1572
+ }
1573
+ }
1574
+ target = parent; // store last element
1575
+ }
1576
+ /* jshint boss:true */ while (parent = getParentOrHost(parent));
1577
+ }
1578
+ _unhideGhostForTarget();
1579
+ }
1580
+ },
1581
+ _onTouchMove: function _onTouchMove(/**TouchEvent*/evt) {
1582
+ if (tapEvt) {
1583
+ var options = this.options,
1584
+ fallbackTolerance = options.fallbackTolerance,
1585
+ fallbackOffset = options.fallbackOffset,
1586
+ touch = evt.touches ? evt.touches[0] : evt,
1587
+ ghostMatrix = ghostEl && matrix(ghostEl, true),
1588
+ scaleX = ghostEl && ghostMatrix && ghostMatrix.a,
1589
+ scaleY = ghostEl && ghostMatrix && ghostMatrix.d,
1590
+ relativeScrollOffset = PositionGhostAbsolutely && ghostRelativeParent && getRelativeScrollOffset(ghostRelativeParent),
1591
+ dx = (touch.clientX - tapEvt.clientX + fallbackOffset.x) / (scaleX || 1) + (relativeScrollOffset ? relativeScrollOffset[0] - ghostRelativeParentInitialScroll[0] : 0) / (scaleX || 1),
1592
+ dy = (touch.clientY - tapEvt.clientY + fallbackOffset.y) / (scaleY || 1) + (relativeScrollOffset ? relativeScrollOffset[1] - ghostRelativeParentInitialScroll[1] : 0) / (scaleY || 1);
1593
+
1594
+ // only set the status to dragging, when we are actually dragging
1595
+ if (!Sortable.active && !awaitingDragStarted) {
1596
+ if (fallbackTolerance && Math.max(Math.abs(touch.clientX - this._lastX), Math.abs(touch.clientY - this._lastY)) < fallbackTolerance) {
1597
+ return;
1598
+ }
1599
+ this._onDragStart(evt, true);
1600
+ }
1601
+ if (ghostEl) {
1602
+ if (ghostMatrix) {
1603
+ ghostMatrix.e += dx - (lastDx || 0);
1604
+ ghostMatrix.f += dy - (lastDy || 0);
1605
+ } else {
1606
+ ghostMatrix = {
1607
+ a: 1,
1608
+ b: 0,
1609
+ c: 0,
1610
+ d: 1,
1611
+ e: dx,
1612
+ f: dy
1613
+ };
1614
+ }
1615
+ var cssMatrix = "matrix(".concat(ghostMatrix.a, ",").concat(ghostMatrix.b, ",").concat(ghostMatrix.c, ",").concat(ghostMatrix.d, ",").concat(ghostMatrix.e, ",").concat(ghostMatrix.f, ")");
1616
+ css(ghostEl, 'webkitTransform', cssMatrix);
1617
+ css(ghostEl, 'mozTransform', cssMatrix);
1618
+ css(ghostEl, 'msTransform', cssMatrix);
1619
+ css(ghostEl, 'transform', cssMatrix);
1620
+ lastDx = dx;
1621
+ lastDy = dy;
1622
+ touchEvt = touch;
1623
+ }
1624
+ evt.cancelable && evt.preventDefault();
1625
+ }
1626
+ },
1627
+ _appendGhost: function _appendGhost() {
1628
+ // Bug if using scale(): https://stackoverflow.com/questions/2637058
1629
+ // Not being adjusted for
1630
+ if (!ghostEl) {
1631
+ var container = this.options.fallbackOnBody ? document.body : rootEl,
1632
+ rect = getRect(dragEl, true, PositionGhostAbsolutely, true, container),
1633
+ options = this.options;
1634
+
1635
+ // Position absolutely
1636
+ if (PositionGhostAbsolutely) {
1637
+ // Get relatively positioned parent
1638
+ ghostRelativeParent = container;
1639
+ while (css(ghostRelativeParent, 'position') === 'static' && css(ghostRelativeParent, 'transform') === 'none' && ghostRelativeParent !== document) {
1640
+ ghostRelativeParent = ghostRelativeParent.parentNode;
1641
+ }
1642
+ if (ghostRelativeParent !== document.body && ghostRelativeParent !== document.documentElement) {
1643
+ if (ghostRelativeParent === document) ghostRelativeParent = getWindowScrollingElement();
1644
+ rect.top += ghostRelativeParent.scrollTop;
1645
+ rect.left += ghostRelativeParent.scrollLeft;
1646
+ } else {
1647
+ ghostRelativeParent = getWindowScrollingElement();
1648
+ }
1649
+ ghostRelativeParentInitialScroll = getRelativeScrollOffset(ghostRelativeParent);
1650
+ }
1651
+ ghostEl = this.options.getGhostFallback && typeof this.options.getGhostFallback === 'function' ? this.options.getGhostFallback(dragEl) : dragEl.cloneNode(true);
1652
+ toggleClass(ghostEl, options.ghostClass, false);
1653
+ toggleClass(ghostEl, options.fallbackClass, true);
1654
+ toggleClass(ghostEl, options.dragClass, true);
1655
+ css(ghostEl, 'transition', '');
1656
+ css(ghostEl, 'transform', '');
1657
+ css(ghostEl, 'box-sizing', 'border-box');
1658
+ css(ghostEl, 'margin', 0);
1659
+ css(ghostEl, 'top', rect.top);
1660
+ css(ghostEl, 'left', rect.left);
1661
+ css(ghostEl, 'width', rect.width);
1662
+ css(ghostEl, 'height', rect.height);
1663
+ css(ghostEl, 'opacity', '0.8');
1664
+ css(ghostEl, 'position', PositionGhostAbsolutely ? 'absolute' : 'fixed');
1665
+ css(ghostEl, 'zIndex', '100000');
1666
+ css(ghostEl, 'pointerEvents', 'none');
1667
+ Sortable.ghost = ghostEl;
1668
+ container.appendChild(ghostEl);
1669
+
1670
+ // Set transform-origin
1671
+ css(ghostEl, 'transform-origin', tapDistanceLeft / parseInt(ghostEl.style.width) * 100 + '% ' + tapDistanceTop / parseInt(ghostEl.style.height) * 100 + '%');
1672
+ }
1673
+ },
1674
+ _onDragStart: function _onDragStart(/**Event*/evt, /**boolean*/fallback) {
1675
+ var _this = this;
1676
+ var dataTransfer = evt.dataTransfer;
1677
+ var options = _this.options;
1678
+ pluginEvent('dragStart', this, {
1679
+ evt: evt
1680
+ });
1681
+ if (Sortable.eventCanceled) {
1682
+ this._onDrop();
1683
+ return;
1684
+ }
1685
+ pluginEvent('setupClone', this);
1686
+ if (!Sortable.eventCanceled) {
1687
+ cloneEl = clone(dragEl);
1688
+ cloneEl.removeAttribute("id");
1689
+ cloneEl.draggable = false;
1690
+ cloneEl.style['will-change'] = '';
1691
+ this._hideClone();
1692
+ toggleClass(cloneEl, this.options.chosenClass, false);
1693
+ Sortable.clone = cloneEl;
1694
+ }
1695
+
1696
+ // #1143: IFrame support workaround
1697
+ _this.cloneId = _nextTick(function () {
1698
+ pluginEvent('clone', _this);
1699
+ if (Sortable.eventCanceled) return;
1700
+ if (!_this.options.removeCloneOnHide) {
1701
+ rootEl.insertBefore(cloneEl, dragEl);
1702
+ }
1703
+ _this._hideClone();
1704
+ _dispatchEvent({
1705
+ sortable: _this,
1706
+ name: 'clone'
1707
+ });
1708
+ });
1709
+ !fallback && toggleClass(dragEl, options.dragClass, true);
1710
+
1711
+ // Set proper drop events
1712
+ if (fallback) {
1713
+ ignoreNextClick = true;
1714
+ _this._loopId = setInterval(_this._emulateDragOver, 50);
1715
+ } else {
1716
+ // Undo what was set in _prepareDragStart before drag started
1717
+ off(document, 'mouseup', _this._onDrop);
1718
+ off(document, 'touchend', _this._onDrop);
1719
+ off(document, 'touchcancel', _this._onDrop);
1720
+ if (dataTransfer) {
1721
+ dataTransfer.effectAllowed = 'move';
1722
+ options.setData && options.setData.call(_this, dataTransfer, dragEl);
1723
+ }
1724
+ on(document, 'drop', _this);
1725
+
1726
+ // #1276 fix:
1727
+ css(dragEl, 'transform', 'translateZ(0)');
1728
+ }
1729
+ awaitingDragStarted = true;
1730
+ _this._dragStartId = _nextTick(_this._dragStarted.bind(_this, fallback, evt));
1731
+ on(document, 'selectstart', _this);
1732
+ moved = true;
1733
+ window.getSelection().removeAllRanges();
1734
+ if (Safari) {
1735
+ css(document.body, 'user-select', 'none');
1736
+ }
1737
+ },
1738
+ // Returns true - if no further action is needed (either inserted or another condition)
1739
+ _onDragOver: function _onDragOver(/**Event*/evt) {
1740
+ var el = this.el,
1741
+ target = evt.target,
1742
+ dragRect,
1743
+ targetRect,
1744
+ revert,
1745
+ options = this.options,
1746
+ group = options.group,
1747
+ activeSortable = Sortable.active,
1748
+ isOwner = activeGroup === group,
1749
+ canSort = options.sort,
1750
+ fromSortable = putSortable || activeSortable,
1751
+ vertical,
1752
+ _this = this,
1753
+ completedFired = false;
1754
+ if (_silent) return;
1755
+ function dragOverEvent(name, extra) {
1756
+ pluginEvent(name, _this, _objectSpread2({
1757
+ evt: evt,
1758
+ isOwner: isOwner,
1759
+ axis: vertical ? 'vertical' : 'horizontal',
1760
+ revert: revert,
1761
+ dragRect: dragRect,
1762
+ targetRect: targetRect,
1763
+ canSort: canSort,
1764
+ fromSortable: fromSortable,
1765
+ target: target,
1766
+ completed: completed,
1767
+ onMove: function onMove(target, after) {
1768
+ return _onMove(rootEl, el, originalDragEl || dragEl, dragRect, target, getRect(target), evt, after);
1769
+ },
1770
+ changed: changed
1771
+ }, extra));
1772
+ }
1773
+
1774
+ // Capture animation state
1775
+ function capture() {
1776
+ dragOverEvent('dragOverAnimationCapture');
1777
+ _this.captureAnimationState();
1778
+ if (_this !== fromSortable) {
1779
+ fromSortable.captureAnimationState();
1780
+ }
1781
+ }
1782
+
1783
+ // Return invocation when dragEl is inserted (or completed)
1784
+ function completed(insertion) {
1785
+ dragOverEvent('dragOverCompleted', {
1786
+ insertion: insertion
1787
+ });
1788
+ if (insertion) {
1789
+ // Clones must be hidden before folding animation to capture dragRectAbsolute properly
1790
+ if (isOwner) {
1791
+ activeSortable._hideClone();
1792
+ } else {
1793
+ activeSortable._showClone(_this);
1794
+ }
1795
+ if (_this !== fromSortable) {
1796
+ // Set ghost class to new sortable's ghost class
1797
+ toggleClass(dragEl, putSortable ? putSortable.options.ghostClass : activeSortable.options.ghostClass, false);
1798
+ toggleClass(dragEl, options.ghostClass, true);
1799
+ }
1800
+ if (putSortable !== _this && _this !== Sortable.active) {
1801
+ putSortable = _this;
1802
+ } else if (_this === Sortable.active && putSortable) {
1803
+ putSortable = null;
1804
+ }
1805
+
1806
+ // Animation
1807
+ if (fromSortable === _this) {
1808
+ _this._ignoreWhileAnimating = target;
1809
+ }
1810
+ _this.animateAll(function () {
1811
+ dragOverEvent('dragOverAnimationComplete');
1812
+ _this._ignoreWhileAnimating = null;
1813
+ });
1814
+ if (_this !== fromSortable) {
1815
+ fromSortable.animateAll();
1816
+ fromSortable._ignoreWhileAnimating = null;
1817
+ }
1818
+ }
1819
+
1820
+ // Null lastTarget if it is not inside a previously swapped element
1821
+ if (target === dragEl && !dragEl.animated || target === el && !target.animated) {
1822
+ lastTarget = null;
1823
+ }
1824
+
1825
+ // no bubbling and not fallback
1826
+ if (!options.dragoverBubble && !evt.rootEl && target !== document) {
1827
+ dragEl.parentNode[expando]._isOutsideThisEl(evt.target);
1828
+
1829
+ // Do not detect for empty insert if already inserted
1830
+ !insertion && nearestEmptyInsertDetectEvent(evt);
1831
+ }
1832
+ !options.dragoverBubble && evt.stopPropagation && evt.stopPropagation();
1833
+ return completedFired = true;
1834
+ }
1835
+
1836
+ // Call when dragEl has been inserted
1837
+ function changed() {
1838
+ newIndex = index(dragEl, undefined, originalDragEl);
1839
+ newDraggableIndex = index(dragEl, options.draggable, originalDragEl);
1840
+ _dispatchEvent({
1841
+ sortable: _this,
1842
+ name: 'change',
1843
+ toEl: el,
1844
+ newIndex: newIndex,
1845
+ newDraggableIndex: newDraggableIndex,
1846
+ originalEvent: evt
1847
+ });
1848
+ }
1849
+ if (evt.preventDefault !== void 0) {
1850
+ evt.cancelable && evt.preventDefault();
1851
+ }
1852
+ target = closest(target, options.draggable, el, true, originalDragEl);
1853
+ dragOverEvent('dragOver');
1854
+ if (Sortable.eventCanceled) return completedFired;
1855
+ if (dragEl.contains(evt.target) || target.animated && target.animatingX && target.animatingY || _this._ignoreWhileAnimating === target) {
1856
+ return completed(false);
1857
+ }
1858
+ ignoreNextClick = false;
1859
+ if (activeSortable && !options.disabled && (isOwner ? canSort || (revert = parentEl !== rootEl) // Reverting item into the original list
1860
+ : putSortable === this || (this.lastPutMode = activeGroup.checkPull(this, activeSortable, originalDragEl || dragEl, evt)) && group.checkPut(this, activeSortable, originalDragEl || dragEl, evt))) {
1861
+ vertical = this._getDirection(evt, target) === 'vertical';
1862
+ dragRect = getRect(dragEl);
1863
+ dragOverEvent('dragOverValid');
1864
+ if (Sortable.eventCanceled) return completedFired;
1865
+ if (revert) {
1866
+ parentEl = rootEl; // actualization
1867
+ capture();
1868
+ this._hideClone();
1869
+ dragOverEvent('revert');
1870
+ if (!Sortable.eventCanceled) {
1871
+ if (nextEl) {
1872
+ rootEl.insertBefore(dragEl, nextEl);
1873
+ } else {
1874
+ rootEl.appendChild(dragEl);
1875
+ }
1876
+ }
1877
+ return completed(true);
1878
+ }
1879
+ var elLastChild = lastChild(el, options.draggable);
1880
+ if (!elLastChild || _ghostIsLast(evt, vertical, this) && !elLastChild.animated) {
1881
+ // Insert to end of list
1882
+
1883
+ // If already at end of list: Do not insert
1884
+ if (elLastChild === dragEl) {
1885
+ return completed(false);
1886
+ }
1887
+
1888
+ // if there is a last element, it is the target
1889
+ if (elLastChild && el === evt.target) {
1890
+ target = elLastChild;
1891
+ }
1892
+ if (target) {
1893
+ targetRect = getRect(target);
1894
+ }
1895
+ if (_onMove(rootEl, el, originalDragEl || dragEl, dragRect, target, targetRect, evt, !!target) !== false) {
1896
+ capture();
1897
+ this._getPlaceholderOnMove(el, dragRect, target, targetRect, evt, Boolean(target));
1898
+ if (elLastChild && elLastChild.nextSibling) {
1899
+ // the last draggable element is not the last node
1900
+ el.insertBefore(dragEl, elLastChild.nextSibling);
1901
+ } else {
1902
+ el.appendChild(dragEl);
1903
+ }
1904
+ parentEl = el; // actualization
1905
+
1906
+ changed();
1907
+ return completed(true);
1908
+ }
1909
+ } else if (elLastChild && _ghostIsFirst(evt, vertical, this)) {
1910
+ // Insert to start of list
1911
+ var firstChild = getChild(el, 0, options, true, originalDragEl);
1912
+ if (firstChild === dragEl) {
1913
+ return completed(false);
1914
+ }
1915
+ target = firstChild;
1916
+ targetRect = getRect(target);
1917
+ if (_onMove(rootEl, el, originalDragEl || dragEl, dragRect, target, targetRect, evt, false) !== false) {
1918
+ this._getPlaceholderOnMove(el, dragRect, target, targetRect, evt, false);
1919
+ capture();
1920
+ el.insertBefore(dragEl, firstChild);
1921
+ parentEl = el; // actualization
1922
+
1923
+ changed();
1924
+ return completed(true);
1925
+ }
1926
+ } else if (target.parentNode === el) {
1927
+ targetRect = getRect(target);
1928
+ var direction = 0,
1929
+ targetBeforeFirstSwap,
1930
+ differentLevel = dragEl.parentNode !== el,
1931
+ differentRowCol = !_dragElInRowColumn(dragEl.animated && dragEl.toRect || dragRect, target.animated && target.toRect || targetRect, vertical),
1932
+ side1 = vertical ? 'top' : 'left',
1933
+ scrolledPastTop = isScrolledPast(target, 'top', 'top') || isScrolledPast(dragEl, 'top', 'top'),
1934
+ scrollBefore = scrolledPastTop ? scrolledPastTop.scrollTop : void 0;
1935
+ if (lastTarget !== target) {
1936
+ targetBeforeFirstSwap = targetRect[side1];
1937
+ pastFirstInvertThresh = false;
1938
+ isCircumstantialInvert = !differentRowCol && options.invertSwap || differentLevel;
1939
+ }
1940
+ direction = _getSwapDirection(evt, target, targetRect, vertical, differentRowCol ? 1 : options.swapThreshold, options.invertedSwapThreshold == null ? options.swapThreshold : options.invertedSwapThreshold, isCircumstantialInvert, lastTarget === target);
1941
+ var sibling;
1942
+ if (direction !== 0) {
1943
+ // Check if target is beside dragEl in respective direction (ignoring hidden elements)
1944
+ var dragIndex = index(dragEl, undefined, originalDragEl);
1945
+ do {
1946
+ dragIndex -= direction;
1947
+ sibling = parentEl.children[dragIndex];
1948
+ } while (sibling && (css(sibling, 'display') === 'none' || sibling === ghostEl));
1949
+ }
1950
+ // If dragEl is already beside target: Do not insert
1951
+ if (direction === 0 || sibling === target) {
1952
+ return completed(false);
1953
+ }
1954
+ lastTarget = target;
1955
+ lastDirection = direction;
1956
+ var after = false;
1957
+ after = direction === 1;
1958
+ var moveVector = _onMove(rootEl, el, originalDragEl || dragEl, dragRect, target, targetRect, evt, after);
1959
+ if (moveVector !== false) {
1960
+ if (moveVector === 1 || moveVector === -1) {
1961
+ after = moveVector === 1;
1962
+ }
1963
+ _silent = true;
1964
+ setTimeout(_unsilent, 30);
1965
+ capture();
1966
+ this._getPlaceholderOnMove(el, dragRect, target, targetRect, evt, after);
1967
+ var nextSibling = target.nextElementSibling;
1968
+ if (after && !nextSibling) {
1969
+ el.appendChild(dragEl);
1970
+ } else {
1971
+ target.parentNode.insertBefore(dragEl, after ? nextSibling : target);
1972
+ }
1973
+
1974
+ // Undo chrome's scroll adjustment (has no effect on other browsers)
1975
+ if (scrolledPastTop) {
1976
+ scrollBy(scrolledPastTop, 0, scrollBefore - scrolledPastTop.scrollTop);
1977
+ }
1978
+ parentEl = dragEl.parentNode; // actualization
1979
+
1980
+ // must be done before animation
1981
+ if (targetBeforeFirstSwap !== undefined && !isCircumstantialInvert) {
1982
+ targetMoveDistance = Math.abs(targetBeforeFirstSwap - getRect(target)[side1]);
1983
+ }
1984
+ changed();
1985
+ return completed(true);
1986
+ }
1987
+ }
1988
+ if (el.contains(dragEl)) {
1989
+ return completed(false);
1990
+ }
1991
+ }
1992
+ return false;
1993
+ },
1994
+ _ignoreWhileAnimating: null,
1995
+ _offMoveEvents: function _offMoveEvents() {
1996
+ off(document, 'mousemove', this._onTouchMove);
1997
+ off(document, 'touchmove', this._onTouchMove);
1998
+ off(document, 'pointermove', this._onTouchMove);
1999
+ off(document, 'dragover', nearestEmptyInsertDetectEvent);
2000
+ off(document, 'mousemove', nearestEmptyInsertDetectEvent);
2001
+ off(document, 'touchmove', nearestEmptyInsertDetectEvent);
2002
+ },
2003
+ _offUpEvents: function _offUpEvents() {
2004
+ var ownerDocument = this.el.ownerDocument;
2005
+ off(ownerDocument, 'mouseup', this._onDrop);
2006
+ off(ownerDocument, 'touchend', this._onDrop);
2007
+ off(ownerDocument, 'pointerup', this._onDrop);
2008
+ off(ownerDocument, 'pointercancel', this._onDrop);
2009
+ off(ownerDocument, 'touchcancel', this._onDrop);
2010
+ off(document, 'selectstart', this);
2011
+ },
2012
+ _onDrop: function _onDrop(/**Event*/evt) {
2013
+ var el = this.el,
2014
+ options = this.options;
2015
+
2016
+ // Get the index of the dragged element within its parent
2017
+ newIndex = index(dragEl, undefined, originalDragEl);
2018
+ newDraggableIndex = index(dragEl, options.draggable, originalDragEl);
2019
+ pluginEvent('drop', this, {
2020
+ evt: evt
2021
+ });
2022
+ parentEl = dragEl && dragEl.parentNode;
2023
+
2024
+ // Get again after plugin event
2025
+ newIndex = index(dragEl, undefined, originalDragEl);
2026
+ newDraggableIndex = index(dragEl, options.draggable, originalDragEl);
2027
+ if (Sortable.eventCanceled) {
2028
+ this._nulling();
2029
+ return;
2030
+ }
2031
+ awaitingDragStarted = false;
2032
+ isCircumstantialInvert = false;
2033
+ pastFirstInvertThresh = false;
2034
+ clearInterval(this._loopId);
2035
+ clearTimeout(this._dragStartTimer);
2036
+ _cancelNextTick(this.cloneId);
2037
+ _cancelNextTick(this._dragStartId);
2038
+
2039
+ // Unbind events
2040
+ if (this.nativeDraggable) {
2041
+ off(document, 'drop', this);
2042
+ off(el, 'dragstart', this._onDragStart);
2043
+ }
2044
+ this._offMoveEvents();
2045
+ this._offUpEvents();
2046
+ if (Safari) {
2047
+ css(document.body, 'user-select', '');
2048
+ }
2049
+ css(dragEl, 'transform', '');
2050
+ if (evt) {
2051
+ if (moved) {
2052
+ evt.cancelable && evt.preventDefault();
2053
+ !options.dropBubble && evt.stopPropagation();
2054
+ }
2055
+ ghostEl && ghostEl.parentNode && ghostEl.parentNode.removeChild(ghostEl);
2056
+ if (rootEl === parentEl || putSortable && putSortable.lastPutMode !== 'clone') {
2057
+ // Remove clone(s)
2058
+ cloneEl && cloneEl.parentNode && cloneEl.parentNode.removeChild(cloneEl);
2059
+ }
2060
+ if (dragEl) {
2061
+ if (this.nativeDraggable) {
2062
+ off(dragEl, 'dragend', this);
2063
+ }
2064
+ _disableDraggable(dragEl);
2065
+ dragEl.style['will-change'] = '';
2066
+
2067
+ // Remove classes
2068
+ // ghostClass is added in dragStarted
2069
+ if (moved && !awaitingDragStarted) {
2070
+ toggleClass(dragEl, putSortable ? putSortable.options.ghostClass : this.options.ghostClass, false);
2071
+ }
2072
+ toggleClass(dragEl, this.options.chosenClass, false);
2073
+
2074
+ // Drag stop event
2075
+ _dispatchEvent({
2076
+ sortable: this,
2077
+ name: 'unchoose',
2078
+ toEl: parentEl,
2079
+ newIndex: null,
2080
+ newDraggableIndex: null,
2081
+ originalEvent: evt
2082
+ });
2083
+ if (rootEl !== parentEl) {
2084
+ if (newIndex >= 0) {
2085
+ // Add event
2086
+ _dispatchEvent({
2087
+ rootEl: parentEl,
2088
+ name: 'add',
2089
+ toEl: parentEl,
2090
+ fromEl: rootEl,
2091
+ originalEvent: evt
2092
+ });
2093
+
2094
+ // Remove event
2095
+ _dispatchEvent({
2096
+ sortable: this,
2097
+ name: 'remove',
2098
+ toEl: parentEl,
2099
+ originalEvent: evt
2100
+ });
2101
+
2102
+ // drag from one list and drop into another
2103
+ _dispatchEvent({
2104
+ rootEl: parentEl,
2105
+ name: 'sort',
2106
+ toEl: parentEl,
2107
+ fromEl: rootEl,
2108
+ originalEvent: evt
2109
+ });
2110
+ _dispatchEvent({
2111
+ sortable: this,
2112
+ name: 'sort',
2113
+ toEl: parentEl,
2114
+ originalEvent: evt
2115
+ });
2116
+ }
2117
+ putSortable && putSortable.save();
2118
+ } else {
2119
+ if (newIndex !== oldIndex) {
2120
+ if (newIndex >= 0) {
2121
+ // drag & drop within the same list
2122
+ _dispatchEvent({
2123
+ sortable: this,
2124
+ name: 'update',
2125
+ toEl: parentEl,
2126
+ originalEvent: evt
2127
+ });
2128
+ _dispatchEvent({
2129
+ sortable: this,
2130
+ name: 'sort',
2131
+ toEl: parentEl,
2132
+ originalEvent: evt
2133
+ });
2134
+ }
2135
+ }
2136
+ }
2137
+ if (Sortable.active) {
2138
+ /* jshint eqnull:true */
2139
+ if (newIndex == null || newIndex === -1) {
2140
+ newIndex = oldIndex;
2141
+ newDraggableIndex = oldDraggableIndex;
2142
+ }
2143
+ _dispatchEvent({
2144
+ sortable: this,
2145
+ name: 'end',
2146
+ toEl: parentEl,
2147
+ originalEvent: evt
2148
+ });
2149
+
2150
+ // Save sorting
2151
+ this.save();
2152
+ }
2153
+ }
2154
+ }
2155
+ this._nulling();
2156
+ },
2157
+ _nulling: function _nulling() {
2158
+ pluginEvent('nulling', this);
2159
+ this._removeClonedSelectedItem();
2160
+ rootEl = dragEl = originalDragEl = originalDragElDisplay = 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;
2161
+ var el = this.el;
2162
+ savedInputChecked.forEach(function (checkEl) {
2163
+ if (el.contains(checkEl)) {
2164
+ checkEl.checked = true;
2165
+ }
2166
+ });
2167
+ savedInputChecked.length = lastDx = lastDy = 0;
2168
+ },
2169
+ handleEvent: function handleEvent(/**Event*/evt) {
2170
+ switch (evt.type) {
2171
+ case 'drop':
2172
+ case 'dragend':
2173
+ this._onDrop(evt);
2174
+ break;
2175
+ case 'dragenter':
2176
+ case 'dragover':
2177
+ if (dragEl) {
2178
+ this._onDragOver(evt);
2179
+ _globalDragOver(evt);
2180
+ }
2181
+ break;
2182
+ case 'selectstart':
2183
+ evt.preventDefault();
2184
+ break;
2185
+ }
2186
+ },
2187
+ /**
2188
+ * Serializes the item into an array of string.
2189
+ * @returns {String[]}
2190
+ */
2191
+ toArray: function toArray() {
2192
+ var order = [],
2193
+ el,
2194
+ children = this.el.children,
2195
+ i = 0,
2196
+ n = children.length,
2197
+ options = this.options;
2198
+ for (; i < n; i++) {
2199
+ el = children[i];
2200
+ if (closest(el, options.draggable, this.el, false, originalDragEl)) {
2201
+ order.push(el.getAttribute(options.dataIdAttr) || _generateId(el));
2202
+ }
2203
+ }
2204
+ return order;
2205
+ },
2206
+ /**
2207
+ * Sorts the elements according to the array.
2208
+ * @param {String[]} order order of the items
2209
+ */
2210
+ sort: function sort(order, useAnimation) {
2211
+ var items = {},
2212
+ rootEl = this.el;
2213
+ this.toArray().forEach(function (id, i) {
2214
+ var el = rootEl.children[i];
2215
+ if (closest(el, this.options.draggable, rootEl, false, originalDragEl)) {
2216
+ items[id] = el;
2217
+ }
2218
+ }, this);
2219
+ useAnimation && this.captureAnimationState();
2220
+ order.forEach(function (id) {
2221
+ if (items[id]) {
2222
+ rootEl.removeChild(items[id]);
2223
+ rootEl.appendChild(items[id]);
2224
+ }
2225
+ });
2226
+ useAnimation && this.animateAll();
2227
+ },
2228
+ /**
2229
+ * Save the current sorting
2230
+ */
2231
+ save: function save() {
2232
+ var store = this.options.store;
2233
+ store && store.set && store.set(this);
2234
+ },
2235
+ /**
2236
+ * 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.
2237
+ * @param {HTMLElement} el
2238
+ * @param {String} [selector] default: `options.draggable`
2239
+ * @returns {HTMLElement|null}
2240
+ */
2241
+ closest: function closest$1(el, selector) {
2242
+ return closest(el, selector || this.options.draggable, this.el, false, originalDragEl);
2243
+ },
2244
+ /**
2245
+ * Set/get option
2246
+ * @param {string} name
2247
+ * @param {*} [value]
2248
+ * @returns {*}
2249
+ */
2250
+ option: function option(name, value) {
2251
+ var options = this.options;
2252
+ if (value === void 0) {
2253
+ return options[name];
2254
+ } else {
2255
+ var modifiedValue = PluginManager.modifyOption(this, name, value);
2256
+ if (typeof modifiedValue !== 'undefined') {
2257
+ options[name] = modifiedValue;
2258
+ } else {
2259
+ options[name] = value;
2260
+ }
2261
+ if (name === 'group') {
2262
+ _prepareGroup(options);
2263
+ }
2264
+ }
2265
+ },
2266
+ /**
2267
+ * Destroy
2268
+ */
2269
+ destroy: function destroy() {
2270
+ pluginEvent('destroy', this);
2271
+ var el = this.el;
2272
+ el[expando] = null;
2273
+ off(el, 'mousedown', this._onTapStart);
2274
+ off(el, 'touchstart', this._onTapStart);
2275
+ off(el, 'pointerdown', this._onTapStart);
2276
+ if (this.nativeDraggable) {
2277
+ off(el, 'dragover', this);
2278
+ off(el, 'dragenter', this);
2279
+ }
2280
+ // Remove draggable attributes
2281
+ Array.prototype.forEach.call(el.querySelectorAll('[draggable]'), function (el) {
2282
+ el.removeAttribute('draggable');
2283
+ });
2284
+ this._onDrop();
2285
+ this._disableDelayedDragEvents();
2286
+ sortables.splice(sortables.indexOf(this.el), 1);
2287
+ this.el = el = null;
2288
+ },
2289
+ _hideClone: function _hideClone() {
2290
+ if (!cloneHidden) {
2291
+ pluginEvent('hideClone', this);
2292
+ if (Sortable.eventCanceled) return;
2293
+ css(cloneEl, 'display', 'none');
2294
+ if (this.options.removeCloneOnHide && cloneEl.parentNode) {
2295
+ cloneEl.parentNode.removeChild(cloneEl);
2296
+ }
2297
+ cloneHidden = true;
2298
+ }
2299
+ },
2300
+ _showClone: function _showClone(putSortable) {
2301
+ if (putSortable.lastPutMode !== 'clone') {
2302
+ this._hideClone();
2303
+ return;
2304
+ }
2305
+ if (cloneHidden) {
2306
+ pluginEvent('showClone', this);
2307
+ if (Sortable.eventCanceled) return;
2308
+
2309
+ // show clone at dragEl or original position
2310
+ if (typeof this.options.getPlaceholder !== 'function' && typeof this.options.getPlaceholderOnMove !== 'function') {
2311
+ if (dragEl.parentNode == rootEl && !this.options.group.revertClone) {
2312
+ rootEl.insertBefore(cloneEl, dragEl);
2313
+ } else if (nextEl) {
2314
+ rootEl.insertBefore(cloneEl, nextEl);
2315
+ } else {
2316
+ rootEl.appendChild(cloneEl);
2317
+ }
2318
+ }
2319
+ if (this.options.group.revertClone) {
2320
+ this.animate(dragEl, cloneEl);
2321
+ }
2322
+ css(cloneEl, 'display', '');
2323
+ cloneHidden = false;
2324
+ }
2325
+ }
2326
+ };
2327
+ function _globalDragOver(/**Event*/evt) {
2328
+ if (evt.dataTransfer) {
2329
+ evt.dataTransfer.dropEffect = 'move';
2330
+ }
2331
+ evt.cancelable && evt.preventDefault();
2332
+ }
2333
+ var getMoveEvent = function getMoveEvent(fromEl, toEl, dragEl, dragRect, targetEl, targetRect, originalEvent, willInsertAfter) {
2334
+ var evt;
2335
+ // Support for new CustomEvent feature
2336
+ if (window.CustomEvent && !IE11OrLess && !Edge) {
2337
+ evt = new CustomEvent('move', {
2338
+ bubbles: true,
2339
+ cancelable: true
2340
+ });
2341
+ } else {
2342
+ evt = document.createEvent('Event');
2343
+ evt.initEvent('move', true, true);
2344
+ }
2345
+ evt.to = toEl;
2346
+ evt.from = fromEl;
2347
+ evt.dragged = dragEl;
2348
+ evt.draggedRect = dragRect;
2349
+ evt.related = targetEl || toEl;
2350
+ evt.relatedRect = targetRect || getRect(toEl);
2351
+ evt.willInsertAfter = willInsertAfter;
2352
+ evt.originalEvent = originalEvent;
2353
+ return evt;
2354
+ };
2355
+ function _onMove(fromEl, toEl, dragEl, dragRect, targetEl, targetRect, originalEvent, willInsertAfter) {
2356
+ var sortable = fromEl[expando],
2357
+ onMoveFn = sortable.options.onMove,
2358
+ retVal;
2359
+ var evt = getMoveEvent(fromEl, toEl, dragEl, dragRect, targetEl, targetRect, originalEvent, willInsertAfter);
2360
+ fromEl.dispatchEvent(evt);
2361
+ if (onMoveFn) {
2362
+ retVal = onMoveFn.call(sortable, evt);
2363
+ }
2364
+ return retVal;
2365
+ }
2366
+ function _disableDraggable(el) {
2367
+ el.draggable = false;
2368
+ }
2369
+ function _unsilent() {
2370
+ _silent = false;
2371
+ }
2372
+ function _ghostIsFirst(evt, vertical, sortable) {
2373
+ var firstElRect = getRect(getChild(sortable.el, 0, sortable.options, true, originalDragEl));
2374
+ var childContainingRect = getChildContainingRectFromElement(sortable.el, sortable.options, ghostEl, originalDragEl);
2375
+ var spacer = 10;
2376
+ 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;
2377
+ }
2378
+ function _ghostIsLast(evt, vertical, sortable) {
2379
+ var lastElRect = getRect(lastChild(sortable.el, sortable.options.draggable));
2380
+ var childContainingRect = getChildContainingRectFromElement(sortable.el, sortable.options, ghostEl, originalDragEl);
2381
+ var spacer = 10;
2382
+ 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;
2383
+ }
2384
+ function _getSwapDirection(evt, target, targetRect, vertical, swapThreshold, invertedSwapThreshold, invertSwap, isLastTarget) {
2385
+ var mouseOnAxis = vertical ? evt.clientY : evt.clientX,
2386
+ targetLength = vertical ? targetRect.height : targetRect.width,
2387
+ targetS1 = vertical ? targetRect.top : targetRect.left,
2388
+ targetS2 = vertical ? targetRect.bottom : targetRect.right,
2389
+ invert = false;
2390
+ if (!invertSwap) {
2391
+ // Never invert or create dragEl shadow when target movemenet causes mouse to move past the end of regular swapThreshold
2392
+ if (isLastTarget && targetMoveDistance < targetLength * swapThreshold) {
2393
+ // multiplied only by swapThreshold because mouse will already be inside target by (1 - threshold) * targetLength / 2
2394
+ // check if past first invert threshold on side opposite of lastDirection
2395
+ if (!pastFirstInvertThresh && (lastDirection === 1 ? mouseOnAxis > targetS1 + targetLength * invertedSwapThreshold / 2 : mouseOnAxis < targetS2 - targetLength * invertedSwapThreshold / 2)) {
2396
+ // past first invert threshold, do not restrict inverted threshold to dragEl shadow
2397
+ pastFirstInvertThresh = true;
2398
+ }
2399
+ if (!pastFirstInvertThresh) {
2400
+ // dragEl shadow (target move distance shadow)
2401
+ if (lastDirection === 1 ? mouseOnAxis < targetS1 + targetMoveDistance // over dragEl shadow
2402
+ : mouseOnAxis > targetS2 - targetMoveDistance) {
2403
+ return -lastDirection;
2404
+ }
2405
+ } else {
2406
+ invert = true;
2407
+ }
2408
+ } else {
2409
+ // Regular
2410
+ if (mouseOnAxis > targetS1 + targetLength * (1 - swapThreshold) / 2 && mouseOnAxis < targetS2 - targetLength * (1 - swapThreshold) / 2) {
2411
+ return _getInsertDirection(target);
2412
+ }
2413
+ }
2414
+ }
2415
+ invert = invert || invertSwap;
2416
+ if (invert) {
2417
+ // Invert of regular
2418
+ if (mouseOnAxis < targetS1 + targetLength * invertedSwapThreshold / 2 || mouseOnAxis > targetS2 - targetLength * invertedSwapThreshold / 2) {
2419
+ return mouseOnAxis > targetS1 + targetLength / 2 ? 1 : -1;
2420
+ }
2421
+ }
2422
+ return 0;
2423
+ }
2424
+
2425
+ /**
2426
+ * Gets the direction dragEl must be swapped relative to target in order to make it
2427
+ * seem that dragEl has been "inserted" into that element's position
2428
+ * @param {HTMLElement} target The target whose position dragEl is being inserted at
2429
+ * @return {Number} Direction dragEl must be swapped
2430
+ */
2431
+ function _getInsertDirection(target) {
2432
+ if (index(dragEl, undefined, originalDragEl) < index(target, undefined, originalDragEl)) {
2433
+ return 1;
2434
+ } else {
2435
+ return -1;
2436
+ }
2437
+ }
2438
+
2439
+ /**
2440
+ * Generate id
2441
+ * @param {HTMLElement} el
2442
+ * @returns {String}
2443
+ * @private
2444
+ */
2445
+ function _generateId(el) {
2446
+ var str = el.tagName + el.className + el.src + el.href + el.textContent,
2447
+ i = str.length,
2448
+ sum = 0;
2449
+ while (i--) {
2450
+ sum += str.charCodeAt(i);
2451
+ }
2452
+ return sum.toString(36);
2453
+ }
2454
+ function _saveInputCheckedState(root) {
2455
+ savedInputChecked.length = 0;
2456
+ var inputs = root.getElementsByTagName('input');
2457
+ var idx = inputs.length;
2458
+ while (idx--) {
2459
+ var el = inputs[idx];
2460
+ el.checked && savedInputChecked.push(el);
2461
+ }
2462
+ }
2463
+ function _nextTick(fn) {
2464
+ return setTimeout(fn, 0);
2465
+ }
2466
+ function _cancelNextTick(id) {
2467
+ return clearTimeout(id);
2468
+ }
2469
+
2470
+ // Fixed #973:
2471
+ if (documentExists) {
2472
+ on(document, 'touchmove', function (evt) {
2473
+ if ((Sortable.active || awaitingDragStarted) && evt.cancelable) {
2474
+ evt.preventDefault();
2475
+ }
2476
+ });
2477
+ }
2478
+
2479
+ // Export utils
2480
+ Sortable.utils = {
2481
+ on: on,
2482
+ off: off,
2483
+ css: css,
2484
+ find: find,
2485
+ is: function is(el, selector) {
2486
+ return !!closest(el, selector, el, false, originalDragEl);
2487
+ },
2488
+ extend: extend,
2489
+ throttle: throttle,
2490
+ closest: closest,
2491
+ toggleClass: toggleClass,
2492
+ clone: clone,
2493
+ index: index,
2494
+ nextTick: _nextTick,
2495
+ cancelNextTick: _cancelNextTick,
2496
+ detectDirection: _detectDirection,
2497
+ getChild: getChild,
2498
+ expando: expando
2499
+ };
2500
+
2501
+ /**
2502
+ * Get the Sortable instance of an element
2503
+ * @param {HTMLElement} element The element
2504
+ * @return {Sortable|undefined} The instance of Sortable
2505
+ */
2506
+ Sortable.get = function (element) {
2507
+ return element[expando];
2508
+ };
2509
+
2510
+ /**
2511
+ * Mount a plugin to Sortable
2512
+ * @param {...SortablePlugin|SortablePlugin[]} plugins Plugins being mounted
2513
+ */
2514
+ Sortable.mount = function () {
2515
+ for (var _len = arguments.length, plugins = new Array(_len), _key = 0; _key < _len; _key++) {
2516
+ plugins[_key] = arguments[_key];
2517
+ }
2518
+ if (plugins[0].constructor === Array) plugins = plugins[0];
2519
+ plugins.forEach(function (plugin) {
2520
+ if (!plugin.prototype || !plugin.prototype.constructor) {
2521
+ throw "Sortable: Mounted plugin must be a constructor function, not ".concat({}.toString.call(plugin));
2522
+ }
2523
+ if (plugin.utils) Sortable.utils = _objectSpread2(_objectSpread2({}, Sortable.utils), plugin.utils);
2524
+ PluginManager.mount(plugin);
2525
+ });
2526
+ };
2527
+
2528
+ /**
2529
+ * Create sortable instance
2530
+ * @param {HTMLElement} el
2531
+ * @param {Object} [options]
2532
+ */
2533
+ Sortable.create = function (el, options) {
2534
+ return new Sortable(el, options);
2535
+ };
2536
+
2537
+ // Export
2538
+ Sortable.version = version;
2539
+
2540
+ var autoScrolls = [],
2541
+ scrollEl,
2542
+ scrollRootEl,
2543
+ scrolling = false,
2544
+ lastAutoScrollX,
2545
+ lastAutoScrollY,
2546
+ touchEvt$1,
2547
+ pointerElemChangedInterval;
2548
+ var AutoScroll = /*#__PURE__*/function () {
2549
+ function AutoScroll(sortable) {
2550
+ _classCallCheck(this, AutoScroll);
2551
+ this.sortable = sortable;
2552
+ this.options = sortable.options;
2553
+ this.defaults = {
2554
+ scroll: true,
2555
+ forceAutoScrollFallback: false,
2556
+ scrollSensitivity: 30,
2557
+ scrollSpeed: 10,
2558
+ bubbleScroll: true
2559
+ };
2560
+ // Bind all private methods
2561
+ var _iterator = _createForOfIteratorHelper(Object.getOwnPropertyNames(Object.getPrototypeOf(this))),
2562
+ _step;
2563
+ try {
2564
+ for (_iterator.s(); !(_step = _iterator.n()).done;) {
2565
+ var fn = _step.value;
2566
+ if (fn.charAt(0) === '_' && typeof this[fn] === 'function') {
2567
+ this[fn] = this[fn].bind(this);
2568
+ }
2569
+ }
2570
+ } catch (err) {
2571
+ _iterator.e(err);
2572
+ } finally {
2573
+ _iterator.f();
2574
+ }
2575
+ }
2576
+ return _createClass(AutoScroll, [{
2577
+ key: "dragStarted",
2578
+ value: function dragStarted(_ref) {
2579
+ var originalEvent = _ref.originalEvent;
2580
+ if (this.sortable.nativeDraggable) {
2581
+ on(document, 'dragover', this._handleAutoScroll);
2582
+ } else {
2583
+ if (this.options.supportPointer) {
2584
+ on(document, 'pointermove', this._handleFallbackAutoScroll);
2585
+ } else if (originalEvent.touches) {
2586
+ on(document, 'touchmove', this._handleFallbackAutoScroll);
2587
+ } else {
2588
+ on(document, 'mousemove', this._handleFallbackAutoScroll);
2589
+ }
2590
+ }
2591
+ }
2592
+ }, {
2593
+ key: "dragOverCompleted",
2594
+ value: function dragOverCompleted(_ref2) {
2595
+ var originalEvent = _ref2.originalEvent;
2596
+ if (!this.options.dragOverBubble && !originalEvent.rootEl) {
2597
+ this._handleAutoScroll(originalEvent);
2598
+ }
2599
+ }
2600
+ }, {
2601
+ key: "drop",
2602
+ value: function drop() {
2603
+ if (this.sortable.nativeDraggable) {
2604
+ off(document, 'dragover', this._handleAutoScroll);
2605
+ } else {
2606
+ off(document, 'pointermove', this._handleFallbackAutoScroll);
2607
+ off(document, 'touchmove', this._handleFallbackAutoScroll);
2608
+ off(document, 'mousemove', this._handleFallbackAutoScroll);
2609
+ }
2610
+ clearPointerElemChangedInterval();
2611
+ clearAutoScrolls();
2612
+ cancelThrottle();
2613
+ }
2614
+ }, {
2615
+ key: "nulling",
2616
+ value: function nulling() {
2617
+ touchEvt$1 = scrollRootEl = scrollEl = scrolling = pointerElemChangedInterval = lastAutoScrollX = lastAutoScrollY = null;
2618
+ autoScrolls.length = 0;
2619
+ }
2620
+ }, {
2621
+ key: "_handleFallbackAutoScroll",
2622
+ value: function _handleFallbackAutoScroll(evt) {
2623
+ this._handleAutoScroll(evt, true);
2624
+ }
2625
+ }, {
2626
+ key: "_handleAutoScroll",
2627
+ value: function _handleAutoScroll(evt, fallback) {
2628
+ var _this = this;
2629
+ var x = (evt.touches ? evt.touches[0] : evt).clientX,
2630
+ y = (evt.touches ? evt.touches[0] : evt).clientY,
2631
+ elem = document.elementFromPoint(x, y);
2632
+ touchEvt$1 = evt;
2633
+ if (fallback || this.options.forceAutoScrollFallback || Edge || IE11OrLess || Safari) {
2634
+ autoScroll(evt, this.options, elem, fallback);
2635
+ var ogElemScroller = getParentAutoScrollElement(elem, true);
2636
+ if (scrolling && (!pointerElemChangedInterval || x !== lastAutoScrollX || y !== lastAutoScrollY)) {
2637
+ pointerElemChangedInterval && clearPointerElemChangedInterval();
2638
+ pointerElemChangedInterval = setInterval(function () {
2639
+ var newElem = getParentAutoScrollElement(document.elementFromPoint(x, y), true);
2640
+ if (newElem !== ogElemScroller) {
2641
+ ogElemScroller = newElem;
2642
+ clearAutoScrolls();
2643
+ }
2644
+ autoScroll(evt, _this.options, newElem, fallback);
2645
+ }, 10);
2646
+ lastAutoScrollX = x;
2647
+ lastAutoScrollY = y;
2648
+ }
2649
+ } else {
2650
+ if (!this.options.bubbleScroll || getParentAutoScrollElement(elem, true) === getWindowScrollingElement()) {
2651
+ clearAutoScrolls();
2652
+ return;
2653
+ }
2654
+ autoScroll(evt, this.options, getParentAutoScrollElement(elem, false), false);
2655
+ }
2656
+ }
2657
+ }]);
2658
+ }();
2659
+ _defineProperty(AutoScroll, "pluginName", 'scroll');
2660
+ _defineProperty(AutoScroll, "initializeByDefault", true);
2661
+ function clearAutoScrolls() {
2662
+ autoScrolls.forEach(function (autoScroll) {
2663
+ clearInterval(autoScroll.pid);
2664
+ });
2665
+ autoScrolls = [];
2666
+ }
2667
+ function clearPointerElemChangedInterval() {
2668
+ clearInterval(pointerElemChangedInterval);
2669
+ }
2670
+ var autoScroll = throttle(function (evt, options, rootEl, isFallback) {
2671
+ // Bug: https://bugzilla.mozilla.org/show_bug.cgi?id=505521
2672
+ if (!options.scroll) return;
2673
+ var x = (evt.touches ? evt.touches[0] : evt).clientX,
2674
+ y = (evt.touches ? evt.touches[0] : evt).clientY,
2675
+ sens = options.scrollSensitivity,
2676
+ speed = options.scrollSpeed,
2677
+ winScroller = getWindowScrollingElement();
2678
+ var scrollThisInstance = false,
2679
+ scrollCustomFn;
2680
+
2681
+ // New scroll root, set scrollEl
2682
+ if (scrollRootEl !== rootEl) {
2683
+ scrollRootEl = rootEl;
2684
+ clearAutoScrolls();
2685
+ scrollEl = options.scroll;
2686
+ scrollCustomFn = options.scrollFn;
2687
+ if (scrollEl === true) {
2688
+ scrollEl = getParentAutoScrollElement(rootEl, true);
2689
+ }
2690
+ }
2691
+ var layersOut = 0;
2692
+ var currentParent = scrollEl;
2693
+ do {
2694
+ var el = currentParent,
2695
+ rect = getRect(el),
2696
+ top = rect.top,
2697
+ bottom = rect.bottom,
2698
+ left = rect.left,
2699
+ right = rect.right,
2700
+ width = rect.width,
2701
+ height = rect.height,
2702
+ canScrollX = void 0,
2703
+ canScrollY = void 0,
2704
+ scrollWidth = el.scrollWidth,
2705
+ scrollHeight = el.scrollHeight,
2706
+ elCSS = css(el),
2707
+ scrollPosX = el.scrollLeft,
2708
+ scrollPosY = el.scrollTop;
2709
+ if (el === winScroller) {
2710
+ canScrollX = width < scrollWidth && (elCSS.overflowX === 'auto' || elCSS.overflowX === 'scroll' || elCSS.overflowX === 'visible');
2711
+ canScrollY = height < scrollHeight && (elCSS.overflowY === 'auto' || elCSS.overflowY === 'scroll' || elCSS.overflowY === 'visible');
2712
+ } else {
2713
+ canScrollX = width < scrollWidth && (elCSS.overflowX === 'auto' || elCSS.overflowX === 'scroll');
2714
+ canScrollY = height < scrollHeight && (elCSS.overflowY === 'auto' || elCSS.overflowY === 'scroll');
2715
+ }
2716
+ var vx = canScrollX && (Math.abs(right - x) <= sens && scrollPosX + width < scrollWidth) - (Math.abs(left - x) <= sens && !!scrollPosX);
2717
+ var vy = canScrollY && (Math.abs(bottom - y) <= sens && scrollPosY + height < scrollHeight) - (Math.abs(top - y) <= sens && !!scrollPosY);
2718
+ if (!autoScrolls[layersOut]) {
2719
+ for (var i = 0; i <= layersOut; i++) {
2720
+ if (!autoScrolls[i]) {
2721
+ autoScrolls[i] = {};
2722
+ }
2723
+ }
2724
+ }
2725
+ if (autoScrolls[layersOut].vx != vx || autoScrolls[layersOut].vy != vy || autoScrolls[layersOut].el !== el) {
2726
+ autoScrolls[layersOut].el = el;
2727
+ autoScrolls[layersOut].vx = vx;
2728
+ autoScrolls[layersOut].vy = vy;
2729
+ clearInterval(autoScrolls[layersOut].pid);
2730
+ if (vx != 0 || vy != 0) {
2731
+ scrollThisInstance = true;
2732
+ /* jshint loopfunc:true */
2733
+ autoScrolls[layersOut].pid = setInterval(function () {
2734
+ // emulate drag over during autoscroll (fallback), emulating native DnD behaviour
2735
+ if (isFallback && this.layer === 0) {
2736
+ Sortable.active._onTouchMove(touchEvt$1); // To move ghost if it is positioned absolutely
2737
+ }
2738
+ var scrollOffsetY = autoScrolls[this.layer].vy ? autoScrolls[this.layer].vy * speed : 0;
2739
+ var scrollOffsetX = autoScrolls[this.layer].vx ? autoScrolls[this.layer].vx * speed : 0;
2740
+ if (typeof scrollCustomFn === 'function') {
2741
+ if (scrollCustomFn.call(Sortable.dragged.parentNode[expando], scrollOffsetX, scrollOffsetY, evt, touchEvt$1, autoScrolls[this.layer].el) !== 'continue') {
2742
+ return;
2743
+ }
2744
+ }
2745
+ scrollBy(autoScrolls[this.layer].el, scrollOffsetX, scrollOffsetY);
2746
+ }.bind({
2747
+ layer: layersOut
2748
+ }), 24);
2749
+ }
2750
+ }
2751
+ layersOut++;
2752
+ } while (options.bubbleScroll && currentParent !== winScroller && (currentParent = getParentAutoScrollElement(currentParent, false)));
2753
+ scrolling = scrollThisInstance; // in case another function catches scrolling as false in between when it is not
2754
+ }, 30);
2755
+
2756
+ var originalDragEl$1;
2757
+ var drop = function drop(_ref) {
2758
+ var originalEvent = _ref.originalEvent,
2759
+ putSortable = _ref.putSortable,
2760
+ dragEl = _ref.dragEl,
2761
+ activeSortable = _ref.activeSortable,
2762
+ dispatchSortableEvent = _ref.dispatchSortableEvent,
2763
+ hideGhostForTarget = _ref.hideGhostForTarget,
2764
+ unhideGhostForTarget = _ref.unhideGhostForTarget;
2765
+ if (!originalEvent) return;
2766
+ var toSortable = putSortable || activeSortable;
2767
+ hideGhostForTarget();
2768
+ var touch = originalEvent.changedTouches && originalEvent.changedTouches.length ? originalEvent.changedTouches[0] : originalEvent;
2769
+ var target = document.elementFromPoint(touch.clientX, touch.clientY);
2770
+ unhideGhostForTarget();
2771
+ if (toSortable && !toSortable.el.contains(target)) {
2772
+ dispatchSortableEvent('spill');
2773
+ this.onSpill({
2774
+ dragEl: dragEl,
2775
+ putSortable: putSortable
2776
+ });
2777
+ }
2778
+ };
2779
+ function Revert() {}
2780
+ Revert.prototype = {
2781
+ startIndex: null,
2782
+ dragStart: function dragStart(_ref2) {
2783
+ var oldDraggableIndex = _ref2.oldDraggableIndex;
2784
+ this.startIndex = oldDraggableIndex;
2785
+ },
2786
+ getPlaceholder: function getPlaceholder(_ref3) {
2787
+ var originalDrag = _ref3.originalDragEl;
2788
+ originalDragEl$1 = originalDrag;
2789
+ },
2790
+ onSpill: function onSpill(_ref4) {
2791
+ var dragEl = _ref4.dragEl,
2792
+ putSortable = _ref4.putSortable;
2793
+ this.sortable.captureAnimationState();
2794
+ if (putSortable) {
2795
+ putSortable.captureAnimationState();
2796
+ }
2797
+ var nextSibling = getChild(this.sortable.el, this.startIndex, this.options, originalDragEl$1);
2798
+ if (nextSibling) {
2799
+ this.sortable.el.insertBefore(dragEl, nextSibling);
2800
+ } else {
2801
+ this.sortable.el.appendChild(dragEl);
2802
+ }
2803
+ this.sortable.animateAll();
2804
+ if (putSortable) {
2805
+ putSortable.animateAll();
2806
+ }
2807
+ },
2808
+ drop: drop
2809
+ };
2810
+ _extends(Revert, {
2811
+ pluginName: 'revertOnSpill'
2812
+ });
2813
+ function Remove() {}
2814
+ Remove.prototype = {
2815
+ onSpill: function onSpill(_ref5) {
2816
+ var dragEl = _ref5.dragEl,
2817
+ putSortable = _ref5.putSortable;
2818
+ var parentSortable = putSortable || this.sortable;
2819
+ parentSortable.captureAnimationState();
2820
+ dragEl.parentNode && dragEl.parentNode.removeChild(dragEl);
2821
+ parentSortable.animateAll();
2822
+ },
2823
+ drop: drop
2824
+ };
2825
+ _extends(Remove, {
2826
+ pluginName: 'removeOnSpill'
2827
+ });
2828
+
2829
+ var lastSwapEl;
2830
+ function SwapPlugin() {
2831
+ function Swap() {
2832
+ this.defaults = {
2833
+ swapClass: 'sortable-swap-highlight'
2834
+ };
2835
+ }
2836
+ Swap.prototype = {
2837
+ dragStart: function dragStart(_ref) {
2838
+ var dragEl = _ref.dragEl;
2839
+ lastSwapEl = dragEl;
2840
+ },
2841
+ dragOverValid: function dragOverValid(_ref2) {
2842
+ var completed = _ref2.completed,
2843
+ target = _ref2.target,
2844
+ onMove = _ref2.onMove,
2845
+ activeSortable = _ref2.activeSortable,
2846
+ changed = _ref2.changed,
2847
+ cancel = _ref2.cancel;
2848
+ if (!activeSortable.options.swap) return;
2849
+ var el = this.sortable.el,
2850
+ options = this.options;
2851
+ if (target && target !== el) {
2852
+ var prevSwapEl = lastSwapEl;
2853
+ if (onMove(target) !== false) {
2854
+ toggleClass(target, options.swapClass, true);
2855
+ lastSwapEl = target;
2856
+ } else {
2857
+ lastSwapEl = null;
2858
+ }
2859
+ if (prevSwapEl && prevSwapEl !== lastSwapEl) {
2860
+ toggleClass(prevSwapEl, options.swapClass, false);
2861
+ }
2862
+ }
2863
+ changed();
2864
+ completed(true);
2865
+ cancel();
2866
+ },
2867
+ drop: function drop(_ref3) {
2868
+ var activeSortable = _ref3.activeSortable,
2869
+ putSortable = _ref3.putSortable,
2870
+ dragEl = _ref3.dragEl;
2871
+ var toSortable = putSortable || this.sortable;
2872
+ var options = this.options;
2873
+ lastSwapEl && toggleClass(lastSwapEl, options.swapClass, false);
2874
+ if (lastSwapEl && (options.swap || putSortable && putSortable.options.swap)) {
2875
+ if (dragEl !== lastSwapEl) {
2876
+ toSortable.captureAnimationState();
2877
+ if (toSortable !== activeSortable) activeSortable.captureAnimationState();
2878
+ swapNodes(dragEl, lastSwapEl);
2879
+ toSortable.animateAll();
2880
+ if (toSortable !== activeSortable) activeSortable.animateAll();
2881
+ }
2882
+ }
2883
+ },
2884
+ nulling: function nulling() {
2885
+ lastSwapEl = null;
2886
+ }
2887
+ };
2888
+ return _extends(Swap, {
2889
+ pluginName: 'swap',
2890
+ eventProperties: function eventProperties() {
2891
+ return {
2892
+ swapItem: lastSwapEl
2893
+ };
2894
+ }
2895
+ });
2896
+ }
2897
+ function swapNodes(n1, n2) {
2898
+ var p1 = n1.parentNode,
2899
+ p2 = n2.parentNode,
2900
+ i1,
2901
+ i2;
2902
+ if (!p1 || !p2 || p1.isEqualNode(n2) || p2.isEqualNode(n1)) return;
2903
+ i1 = index(n1);
2904
+ i2 = index(n2);
2905
+ if (p1.isEqualNode(p2) && i1 < i2) {
2906
+ i2++;
2907
+ }
2908
+ p1.insertBefore(n2, p1.children[i1]);
2909
+ p2.insertBefore(n1, p2.children[i2]);
2910
+ }
2911
+
2912
+ var multiDragElements = [],
2913
+ multiDragClones = [],
2914
+ lastMultiDragSelect,
2915
+ // for selection with modifier key down (SHIFT)
2916
+ multiDragSortable,
2917
+ initialFolding = false,
2918
+ // Initial multi-drag fold when drag started
2919
+ folding = false,
2920
+ // Folding any other time
2921
+ dragStarted = false,
2922
+ dragEl$1,
2923
+ originalDragEl$2,
2924
+ clonesFromRect,
2925
+ clonesHidden;
2926
+ function MultiDragPlugin() {
2927
+ function MultiDrag(sortable) {
2928
+ // Bind all private methods
2929
+ for (var fn in this) {
2930
+ if (fn.charAt(0) === '_' && typeof this[fn] === 'function') {
2931
+ this[fn] = this[fn].bind(this);
2932
+ }
2933
+ }
2934
+ if (!sortable.options.avoidImplicitDeselect) {
2935
+ if (sortable.options.supportPointer) {
2936
+ on(document, 'pointerup', this._deselectMultiDrag);
2937
+ } else {
2938
+ on(document, 'mouseup', this._deselectMultiDrag);
2939
+ on(document, 'touchend', this._deselectMultiDrag);
2940
+ }
2941
+ }
2942
+ on(document, 'keydown', this._checkKeyDown);
2943
+ on(document, 'keyup', this._checkKeyUp);
2944
+ this.defaults = {
2945
+ selectedClass: 'sortable-selected',
2946
+ multiDragKey: null,
2947
+ avoidImplicitDeselect: false,
2948
+ setData: function setData(dataTransfer, dragEl) {
2949
+ var data = '';
2950
+ if (multiDragElements.length && multiDragSortable === sortable) {
2951
+ multiDragElements.forEach(function (multiDragElement, i) {
2952
+ data += (!i ? '' : ', ') + multiDragElement.textContent;
2953
+ });
2954
+ } else {
2955
+ data = dragEl.textContent;
2956
+ }
2957
+ dataTransfer.setData('Text', data);
2958
+ }
2959
+ };
2960
+ }
2961
+ MultiDrag.prototype = {
2962
+ multiDragKeyDown: false,
2963
+ isMultiDrag: false,
2964
+ delayStartGlobal: function delayStartGlobal(_ref) {
2965
+ var dragged = _ref.dragEl;
2966
+ dragEl$1 = dragged;
2967
+ },
2968
+ delayEnded: function delayEnded() {
2969
+ this.isMultiDrag = ~multiDragElements.indexOf(dragEl$1);
2970
+ },
2971
+ setupClone: function setupClone(_ref2) {
2972
+ var sortable = _ref2.sortable,
2973
+ cancel = _ref2.cancel;
2974
+ if (!this.isMultiDrag) return;
2975
+ for (var i = 0; i < multiDragElements.length; i++) {
2976
+ multiDragClones.push(clone(multiDragElements[i]));
2977
+ multiDragClones[i].sortableIndex = multiDragElements[i].sortableIndex;
2978
+ multiDragClones[i].draggable = false;
2979
+ multiDragClones[i].style['will-change'] = '';
2980
+ toggleClass(multiDragClones[i], this.options.selectedClass, false);
2981
+ multiDragElements[i] === dragEl$1 && toggleClass(multiDragClones[i], this.options.chosenClass, false);
2982
+ }
2983
+ sortable._hideClone();
2984
+ cancel();
2985
+ },
2986
+ clone: function clone(_ref3) {
2987
+ var sortable = _ref3.sortable,
2988
+ rootEl = _ref3.rootEl,
2989
+ dispatchSortableEvent = _ref3.dispatchSortableEvent,
2990
+ cancel = _ref3.cancel;
2991
+ if (!this.isMultiDrag) return;
2992
+ if (!this.options.removeCloneOnHide) {
2993
+ if (multiDragElements.length && multiDragSortable === sortable) {
2994
+ insertMultiDragClones(true, rootEl);
2995
+ dispatchSortableEvent('clone');
2996
+ cancel();
2997
+ }
2998
+ }
2999
+ },
3000
+ showClone: function showClone(_ref4) {
3001
+ var cloneNowShown = _ref4.cloneNowShown,
3002
+ rootEl = _ref4.rootEl,
3003
+ cancel = _ref4.cancel;
3004
+ if (!this.isMultiDrag) return;
3005
+ insertMultiDragClones(false, rootEl);
3006
+ multiDragClones.forEach(function (clone) {
3007
+ css(clone, 'display', '');
3008
+ });
3009
+ cloneNowShown();
3010
+ clonesHidden = false;
3011
+ cancel();
3012
+ },
3013
+ hideClone: function hideClone(_ref5) {
3014
+ var _this = this;
3015
+ var sortable = _ref5.sortable,
3016
+ cloneNowHidden = _ref5.cloneNowHidden,
3017
+ cancel = _ref5.cancel;
3018
+ if (!this.isMultiDrag) return;
3019
+ multiDragClones.forEach(function (clone) {
3020
+ css(clone, 'display', 'none');
3021
+ if (_this.options.removeCloneOnHide && clone.parentNode) {
3022
+ clone.parentNode.removeChild(clone);
3023
+ }
3024
+ });
3025
+ cloneNowHidden();
3026
+ clonesHidden = true;
3027
+ cancel();
3028
+ },
3029
+ dragStartGlobal: function dragStartGlobal(_ref6) {
3030
+ var sortable = _ref6.sortable;
3031
+ if (!this.isMultiDrag && multiDragSortable) {
3032
+ multiDragSortable.multiDrag._deselectMultiDrag();
3033
+ }
3034
+ multiDragElements.forEach(function (multiDragElement) {
3035
+ multiDragElement.sortableIndex = index(multiDragElement);
3036
+ });
3037
+
3038
+ // Sort multi-drag elements
3039
+ multiDragElements = multiDragElements.sort(function (a, b) {
3040
+ return a.sortableIndex - b.sortableIndex;
3041
+ });
3042
+ dragStarted = true;
3043
+ },
3044
+ getPlaceholder: function getPlaceholder(_ref7) {
3045
+ var originalDrag = _ref7.originalDragEl;
3046
+ originalDragEl$2 = originalDrag;
3047
+ },
3048
+ dragStarted: function dragStarted(_ref8) {
3049
+ var _this2 = this;
3050
+ var sortable = _ref8.sortable;
3051
+ if (!this.isMultiDrag) return;
3052
+ if (this.options.sort) {
3053
+ // Capture rects,
3054
+ // hide multi drag elements (by positioning them absolute),
3055
+ // set multi drag elements rects to dragRect,
3056
+ // show multi drag elements,
3057
+ // animate to rects,
3058
+ // unset rects & remove from DOM
3059
+
3060
+ sortable.captureAnimationState();
3061
+ if (this.options.animation) {
3062
+ multiDragElements.forEach(function (multiDragElement) {
3063
+ if (multiDragElement === dragEl$1) return;
3064
+ css(multiDragElement, 'position', 'absolute');
3065
+ });
3066
+ var dragRect = getRect(dragEl$1, false, true, true);
3067
+ multiDragElements.forEach(function (multiDragElement) {
3068
+ if (multiDragElement === dragEl$1) return;
3069
+ setRect(multiDragElement, dragRect);
3070
+ });
3071
+ folding = true;
3072
+ initialFolding = true;
3073
+ }
3074
+ }
3075
+ sortable.animateAll(function () {
3076
+ folding = false;
3077
+ initialFolding = false;
3078
+ if (_this2.options.animation) {
3079
+ multiDragElements.forEach(function (multiDragElement) {
3080
+ unsetRect(multiDragElement);
3081
+ });
3082
+ }
3083
+
3084
+ // Remove all auxiliary multidrag items from el, if sorting enabled
3085
+ if (_this2.options.sort) {
3086
+ removeMultiDragElements();
3087
+ }
3088
+ });
3089
+ },
3090
+ dragOver: function dragOver(_ref9) {
3091
+ var target = _ref9.target,
3092
+ completed = _ref9.completed,
3093
+ cancel = _ref9.cancel;
3094
+ if (folding && ~multiDragElements.indexOf(target)) {
3095
+ completed(false);
3096
+ cancel();
3097
+ }
3098
+ },
3099
+ revert: function revert(_ref0) {
3100
+ var fromSortable = _ref0.fromSortable,
3101
+ rootEl = _ref0.rootEl,
3102
+ sortable = _ref0.sortable,
3103
+ dragRect = _ref0.dragRect;
3104
+ if (multiDragElements.length > 1) {
3105
+ // Setup unfold animation
3106
+ multiDragElements.forEach(function (multiDragElement) {
3107
+ sortable.addAnimationState({
3108
+ target: multiDragElement,
3109
+ rect: folding ? getRect(multiDragElement) : dragRect
3110
+ });
3111
+ unsetRect(multiDragElement);
3112
+ multiDragElement.fromRect = dragRect;
3113
+ fromSortable.removeAnimationState(multiDragElement);
3114
+ });
3115
+ folding = false;
3116
+ insertMultiDragElements(!this.options.removeCloneOnHide, rootEl);
3117
+ }
3118
+ },
3119
+ dragOverCompleted: function dragOverCompleted(_ref1) {
3120
+ var sortable = _ref1.sortable,
3121
+ isOwner = _ref1.isOwner,
3122
+ insertion = _ref1.insertion,
3123
+ activeSortable = _ref1.activeSortable,
3124
+ parentEl = _ref1.parentEl,
3125
+ putSortable = _ref1.putSortable;
3126
+ var options = this.options;
3127
+ if (insertion) {
3128
+ // Clones must be hidden before folding animation to capture dragRectAbsolute properly
3129
+ if (isOwner) {
3130
+ activeSortable._hideClone();
3131
+ }
3132
+ initialFolding = false;
3133
+ // If leaving sort:false root, or already folding - Fold to new location
3134
+ if (options.animation && multiDragElements.length > 1 && (folding || !isOwner && !activeSortable.options.sort && !putSortable)) {
3135
+ // Fold: Set all multi drag elements's rects to dragEl's rect when multi-drag elements are invisible
3136
+ var dragRectAbsolute = getRect(dragEl$1, false, true, true);
3137
+ multiDragElements.forEach(function (multiDragElement) {
3138
+ if (multiDragElement === dragEl$1) return;
3139
+ setRect(multiDragElement, dragRectAbsolute);
3140
+
3141
+ // Move element(s) to end of parentEl so that it does not interfere with multi-drag clones insertion if they are inserted
3142
+ // while folding, and so that we can capture them again because old sortable will no longer be fromSortable
3143
+ parentEl.appendChild(multiDragElement);
3144
+ });
3145
+ folding = true;
3146
+ }
3147
+
3148
+ // Clones must be shown (and check to remove multi drags) after folding when interfering multiDragElements are moved out
3149
+ if (!isOwner) {
3150
+ // Only remove if not folding (folding will remove them anyways)
3151
+ if (!folding) {
3152
+ removeMultiDragElements();
3153
+ }
3154
+ if (multiDragElements.length > 1) {
3155
+ var clonesHiddenBefore = clonesHidden;
3156
+ activeSortable._showClone(sortable);
3157
+
3158
+ // Unfold animation for clones if showing from hidden
3159
+ if (activeSortable.options.animation && !clonesHidden && clonesHiddenBefore) {
3160
+ multiDragClones.forEach(function (clone) {
3161
+ activeSortable.addAnimationState({
3162
+ target: clone,
3163
+ rect: clonesFromRect
3164
+ });
3165
+ clone.fromRect = clonesFromRect;
3166
+ clone.thisAnimationDuration = null;
3167
+ });
3168
+ }
3169
+ } else {
3170
+ activeSortable._showClone(sortable);
3171
+ }
3172
+ }
3173
+ }
3174
+ },
3175
+ dragOverAnimationCapture: function dragOverAnimationCapture(_ref10) {
3176
+ var dragRect = _ref10.dragRect,
3177
+ isOwner = _ref10.isOwner,
3178
+ activeSortable = _ref10.activeSortable;
3179
+ multiDragElements.forEach(function (multiDragElement) {
3180
+ multiDragElement.thisAnimationDuration = null;
3181
+ });
3182
+ if (activeSortable.options.animation && !isOwner && activeSortable.multiDrag.isMultiDrag) {
3183
+ clonesFromRect = _extends({}, dragRect);
3184
+ var dragMatrix = matrix(dragEl$1, true);
3185
+ clonesFromRect.top -= dragMatrix.f;
3186
+ clonesFromRect.left -= dragMatrix.e;
3187
+ }
3188
+ },
3189
+ dragOverAnimationComplete: function dragOverAnimationComplete() {
3190
+ if (folding) {
3191
+ folding = false;
3192
+ removeMultiDragElements();
3193
+ }
3194
+ },
3195
+ drop: function drop(_ref11) {
3196
+ var evt = _ref11.originalEvent,
3197
+ rootEl = _ref11.rootEl,
3198
+ parentEl = _ref11.parentEl,
3199
+ sortable = _ref11.sortable,
3200
+ dispatchSortableEvent = _ref11.dispatchSortableEvent,
3201
+ oldIndex = _ref11.oldIndex,
3202
+ putSortable = _ref11.putSortable;
3203
+ var toSortable = putSortable || this.sortable;
3204
+ if (!evt) return;
3205
+ var options = this.options,
3206
+ children = parentEl.children;
3207
+
3208
+ // Multi-drag selection
3209
+ if (!dragStarted) {
3210
+ if (options.multiDragKey && !this.multiDragKeyDown) {
3211
+ this._deselectMultiDrag();
3212
+ }
3213
+ toggleClass(dragEl$1, options.selectedClass, !~multiDragElements.indexOf(dragEl$1));
3214
+ if (!~multiDragElements.indexOf(dragEl$1)) {
3215
+ multiDragElements.push(dragEl$1);
3216
+ dispatchEvent({
3217
+ sortable: sortable,
3218
+ rootEl: rootEl,
3219
+ name: 'select',
3220
+ targetEl: dragEl$1,
3221
+ originalEvent: evt
3222
+ });
3223
+
3224
+ // Modifier activated, select from last to dragEl
3225
+ if (evt.shiftKey && lastMultiDragSelect && sortable.el.contains(lastMultiDragSelect)) {
3226
+ var lastIndex = index(lastMultiDragSelect),
3227
+ currentIndex = index(dragEl$1);
3228
+ if (~lastIndex && ~currentIndex && lastIndex !== currentIndex) {
3229
+ // Must include lastMultiDragSelect (select it), in case modified selection from no selection
3230
+ // (but previous selection existed)
3231
+ var n, i;
3232
+ if (currentIndex > lastIndex) {
3233
+ i = lastIndex;
3234
+ n = currentIndex;
3235
+ } else {
3236
+ i = currentIndex;
3237
+ n = lastIndex + 1;
3238
+ }
3239
+ var filter = options.filter;
3240
+ for (; i < n; i++) {
3241
+ if (~multiDragElements.indexOf(children[i])) continue;
3242
+ // Check if element is draggable
3243
+ if (!closest(children[i], options.draggable, parentEl, false, originalDragEl$2)) continue;
3244
+ // Check if element is filtered
3245
+ var filtered = filter && (typeof filter === 'function' ? filter.call(sortable, evt, children[i], sortable) : filter.split(',').some(function (criteria) {
3246
+ return closest(children[i], criteria.trim(), parentEl, false, originalDragEl$2);
3247
+ }));
3248
+ if (filtered) continue;
3249
+ toggleClass(children[i], options.selectedClass, true);
3250
+ multiDragElements.push(children[i]);
3251
+ dispatchEvent({
3252
+ sortable: sortable,
3253
+ rootEl: rootEl,
3254
+ name: 'select',
3255
+ targetEl: children[i],
3256
+ originalEvent: evt
3257
+ });
3258
+ }
3259
+ }
3260
+ } else {
3261
+ lastMultiDragSelect = dragEl$1;
3262
+ }
3263
+ multiDragSortable = toSortable;
3264
+ } else {
3265
+ multiDragElements.splice(multiDragElements.indexOf(dragEl$1), 1);
3266
+ lastMultiDragSelect = null;
3267
+ dispatchEvent({
3268
+ sortable: sortable,
3269
+ rootEl: rootEl,
3270
+ name: 'deselect',
3271
+ targetEl: dragEl$1,
3272
+ originalEvent: evt
3273
+ });
3274
+ }
3275
+ }
3276
+
3277
+ // Multi-drag drop
3278
+ if (dragStarted && this.isMultiDrag) {
3279
+ folding = false;
3280
+ // Do not "unfold" after around dragEl if reverted
3281
+ if ((parentEl[expando].options.sort || parentEl !== rootEl) && multiDragElements.length > 1) {
3282
+ var dragRect = getRect(dragEl$1),
3283
+ multiDragIndex = index(dragEl$1, ':not(.' + this.options.selectedClass + ')');
3284
+ if (!initialFolding && options.animation) dragEl$1.thisAnimationDuration = null;
3285
+ toSortable.captureAnimationState();
3286
+ if (!initialFolding) {
3287
+ if (options.animation) {
3288
+ dragEl$1.fromRect = dragRect;
3289
+ multiDragElements.forEach(function (multiDragElement) {
3290
+ multiDragElement.thisAnimationDuration = null;
3291
+ if (multiDragElement !== dragEl$1) {
3292
+ var rect = folding ? getRect(multiDragElement) : dragRect;
3293
+ multiDragElement.fromRect = rect;
3294
+
3295
+ // Prepare unfold animation
3296
+ toSortable.addAnimationState({
3297
+ target: multiDragElement,
3298
+ rect: rect
3299
+ });
3300
+ }
3301
+ });
3302
+ }
3303
+
3304
+ // Multi drag elements are not necessarily removed from the DOM on drop, so to reinsert
3305
+ // properly they must all be removed
3306
+ removeMultiDragElements();
3307
+ multiDragElements.forEach(function (multiDragElement) {
3308
+ if (children[multiDragIndex]) {
3309
+ parentEl.insertBefore(multiDragElement, children[multiDragIndex]);
3310
+ } else {
3311
+ parentEl.appendChild(multiDragElement);
3312
+ }
3313
+ multiDragIndex++;
3314
+ });
3315
+
3316
+ // If initial folding is done, the elements may have changed position because they are now
3317
+ // unfolding around dragEl, even though dragEl may not have his index changed, so update event
3318
+ // must be fired here as Sortable will not.
3319
+ if (oldIndex === index(dragEl$1)) {
3320
+ var update = false;
3321
+ multiDragElements.forEach(function (multiDragElement) {
3322
+ if (multiDragElement.sortableIndex !== index(multiDragElement)) {
3323
+ update = true;
3324
+ return;
3325
+ }
3326
+ });
3327
+ if (update) {
3328
+ dispatchSortableEvent('update');
3329
+ dispatchSortableEvent('sort');
3330
+ }
3331
+ }
3332
+ }
3333
+
3334
+ // Must be done after capturing individual rects (scroll bar)
3335
+ multiDragElements.forEach(function (multiDragElement) {
3336
+ unsetRect(multiDragElement);
3337
+ });
3338
+ toSortable.animateAll();
3339
+ }
3340
+ multiDragSortable = toSortable;
3341
+ }
3342
+
3343
+ // Remove clones if necessary
3344
+ if (rootEl === parentEl || putSortable && putSortable.lastPutMode !== 'clone') {
3345
+ multiDragClones.forEach(function (clone) {
3346
+ clone.parentNode && clone.parentNode.removeChild(clone);
3347
+ });
3348
+ }
3349
+ },
3350
+ nullingGlobal: function nullingGlobal() {
3351
+ this.isMultiDrag = dragStarted = false;
3352
+ multiDragClones.length = 0;
3353
+ },
3354
+ destroyGlobal: function destroyGlobal() {
3355
+ this._deselectMultiDrag();
3356
+ off(document, 'pointerup', this._deselectMultiDrag);
3357
+ off(document, 'mouseup', this._deselectMultiDrag);
3358
+ off(document, 'touchend', this._deselectMultiDrag);
3359
+ off(document, 'keydown', this._checkKeyDown);
3360
+ off(document, 'keyup', this._checkKeyUp);
3361
+ },
3362
+ _deselectMultiDrag: function _deselectMultiDrag(evt) {
3363
+ if (typeof dragStarted !== "undefined" && dragStarted) return;
3364
+
3365
+ // Only deselect if selection is in this sortable
3366
+ if (multiDragSortable !== this.sortable) return;
3367
+
3368
+ // Only deselect if target is not item in this sortable
3369
+ if (evt && closest(evt.target, this.options.draggable, this.sortable.el, false, originalDragEl$2)) return;
3370
+
3371
+ // Only deselect if left click
3372
+ if (evt && evt.button !== 0) return;
3373
+ while (multiDragElements.length) {
3374
+ var el = multiDragElements[0];
3375
+ toggleClass(el, this.options.selectedClass, false);
3376
+ multiDragElements.shift();
3377
+ dispatchEvent({
3378
+ sortable: this.sortable,
3379
+ rootEl: this.sortable.el,
3380
+ name: 'deselect',
3381
+ targetEl: el,
3382
+ originalEvent: evt
3383
+ });
3384
+ }
3385
+ },
3386
+ _checkKeyDown: function _checkKeyDown(evt) {
3387
+ if (evt.key === this.options.multiDragKey) {
3388
+ this.multiDragKeyDown = true;
3389
+ }
3390
+ },
3391
+ _checkKeyUp: function _checkKeyUp(evt) {
3392
+ if (evt.key === this.options.multiDragKey) {
3393
+ this.multiDragKeyDown = false;
3394
+ }
3395
+ }
3396
+ };
3397
+ return _extends(MultiDrag, {
3398
+ // Static methods & properties
3399
+ pluginName: 'multiDrag',
3400
+ utils: {
3401
+ /**
3402
+ * Selects the provided multi-drag item
3403
+ * @param {HTMLElement} el The element to be selected
3404
+ */
3405
+ select: function select(el) {
3406
+ var sortable = el.parentNode[expando];
3407
+ if (!sortable || !sortable.options.multiDrag || ~multiDragElements.indexOf(el)) return;
3408
+ if (multiDragSortable && multiDragSortable !== sortable) {
3409
+ multiDragSortable.multiDrag._deselectMultiDrag();
3410
+ multiDragSortable = sortable;
3411
+ }
3412
+ toggleClass(el, sortable.options.selectedClass, true);
3413
+ multiDragElements.push(el);
3414
+ },
3415
+ /**
3416
+ * Deselects the provided multi-drag item
3417
+ * @param {HTMLElement} el The element to be deselected
3418
+ */
3419
+ deselect: function deselect(el) {
3420
+ var sortable = el.parentNode[expando],
3421
+ index = multiDragElements.indexOf(el);
3422
+ if (!sortable || !sortable.options.multiDrag || !~index) return;
3423
+ toggleClass(el, sortable.options.selectedClass, false);
3424
+ multiDragElements.splice(index, 1);
3425
+ }
3426
+ },
3427
+ eventProperties: function eventProperties() {
3428
+ var _this3 = this;
3429
+ var oldIndicies = [],
3430
+ newIndicies = [];
3431
+ multiDragElements.forEach(function (multiDragElement) {
3432
+ oldIndicies.push({
3433
+ multiDragElement: multiDragElement,
3434
+ index: multiDragElement.sortableIndex
3435
+ });
3436
+
3437
+ // multiDragElements will already be sorted if folding
3438
+ var newIndex;
3439
+ if (folding && multiDragElement !== dragEl$1) {
3440
+ newIndex = -1;
3441
+ } else if (folding) {
3442
+ newIndex = index(multiDragElement, ':not(.' + _this3.options.selectedClass + ')');
3443
+ } else {
3444
+ newIndex = index(multiDragElement);
3445
+ }
3446
+ newIndicies.push({
3447
+ multiDragElement: multiDragElement,
3448
+ index: newIndex
3449
+ });
3450
+ });
3451
+ return {
3452
+ items: _toConsumableArray(multiDragElements),
3453
+ clones: [].concat(multiDragClones),
3454
+ oldIndicies: oldIndicies,
3455
+ newIndicies: newIndicies
3456
+ };
3457
+ },
3458
+ optionListeners: {
3459
+ multiDragKey: function multiDragKey(key) {
3460
+ key = key.toLowerCase();
3461
+ if (key === 'ctrl') {
3462
+ key = 'Control';
3463
+ } else if (key.length > 1) {
3464
+ key = key.charAt(0).toUpperCase() + key.substr(1);
3465
+ }
3466
+ return key;
3467
+ }
3468
+ }
3469
+ });
3470
+ }
3471
+ function insertMultiDragElements(clonesInserted, rootEl) {
3472
+ multiDragElements.forEach(function (multiDragElement, i) {
3473
+ var target = rootEl.children[multiDragElement.sortableIndex + (clonesInserted ? Number(i) : 0)];
3474
+ if (target) {
3475
+ rootEl.insertBefore(multiDragElement, target);
3476
+ } else {
3477
+ rootEl.appendChild(multiDragElement);
3478
+ }
3479
+ });
3480
+ }
3481
+
3482
+ /**
3483
+ * Insert multi-drag clones
3484
+ * @param {[Boolean]} elementsInserted Whether the multi-drag elements are inserted
3485
+ * @param {HTMLElement} rootEl
3486
+ */
3487
+ function insertMultiDragClones(elementsInserted, rootEl) {
3488
+ multiDragClones.forEach(function (clone, i) {
3489
+ var target = rootEl.children[clone.sortableIndex + (elementsInserted ? Number(i) : 0)];
3490
+ if (target) {
3491
+ rootEl.insertBefore(clone, target);
3492
+ } else {
3493
+ rootEl.appendChild(clone);
3494
+ }
3495
+ });
3496
+ }
3497
+ function removeMultiDragElements() {
3498
+ multiDragElements.forEach(function (multiDragElement) {
3499
+ if (multiDragElement === dragEl$1) return;
3500
+ multiDragElement.parentNode && multiDragElement.parentNode.removeChild(multiDragElement);
3501
+ });
3502
+ }
3503
+
3504
+ var dragParent;
3505
+ var TreePlugin = /*#__PURE__*/function () {
3506
+ function TreePlugin(sortable) {
3507
+ _classCallCheck(this, TreePlugin);
3508
+ this.sortable = sortable;
3509
+ this.options = sortable.options;
3510
+ this.startX = 0;
3511
+ this.startLevel = 1;
3512
+ this.currentLevel = 1;
3513
+ this.beforeElement = null;
3514
+ }
3515
+ return _createClass(TreePlugin, [{
3516
+ key: "mount",
3517
+ value: function mount() {
3518
+ if (!this.options.tree) return;
3519
+ }
3520
+ }, {
3521
+ key: "dragStarted",
3522
+ value: function dragStarted(evt) {
3523
+ if (!this.options.tree) return;
3524
+ this.startX = evt.originalEvent.clientX;
3525
+ this.startLevel = getLevel(evt.originalDragEl || evt.dragEl, this.options);
3526
+ this.currentLevel = this.startLevel;
3527
+ }
3528
+ }, {
3529
+ key: "_findPrevSibling",
3530
+ value: function _findPrevSibling(el, originalDragEl) {
3531
+ var level = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : undefined;
3532
+ var prev = el.previousElementSibling;
3533
+ var levelAttr = this.options.treeItemLevelAttr || 'data-level';
3534
+ while (prev) {
3535
+ var match = closest(prev, this.options.draggable, this.sortable.el, false, originalDragEl);
3536
+ if (match) {
3537
+ if (typeof level === 'number' && match.getAttribute(levelAttr) === level.toString() || level === undefined) return match;
3538
+ }
3539
+ prev = prev.previousElementSibling;
3540
+ }
3541
+ return null;
3542
+ }
3543
+ }, {
3544
+ key: "_findNextSibling",
3545
+ value: function _findNextSibling(el, originalDragEl) {
3546
+ var next = el.nextElementSibling;
3547
+ while (next) {
3548
+ var match = closest(next, this.options.draggable, this.sortable.el, false, originalDragEl);
3549
+ if (match) return match;
3550
+ next = next.nextElementSibling;
3551
+ }
3552
+ return null;
3553
+ }
3554
+ }, {
3555
+ key: "dragOver",
3556
+ value: function dragOver(evt) {
3557
+ if (!this.options.tree || evt.axis === 'vertical') return;
3558
+ var deltaX = evt.originalEvent.clientX - this.startX;
3559
+ var indent = this.options.treeIndentThreshold || 10;
3560
+ var levelAttr = this.options.treeItemLevelAttr || 'data-level';
3561
+ var before = this._findPrevSibling(evt.dragEl, evt.originalDragEl);
3562
+ var after = this._findNextSibling(evt.dragEl, evt.originalDragEl);
3563
+ var beforeLevel = before ? getLevel(before, this.options) : 1;
3564
+ var afterLevel = after ? getLevel(after, this.options) : 1;
3565
+ var minLevel = 1;
3566
+ var maxLevel = 1;
3567
+ if (before && after) {
3568
+ minLevel = Math.min(beforeLevel + 1, afterLevel, beforeLevel);
3569
+ maxLevel = Math.max(beforeLevel + 1, afterLevel);
3570
+ } else if (!after) {
3571
+ minLevel = 1;
3572
+ maxLevel = beforeLevel + 1;
3573
+ } else {
3574
+ minLevel = maxLevel = 1;
3575
+ }
3576
+ var levelChange = Math.floor(deltaX / indent);
3577
+ var newLevel = Math.max(minLevel, Math.min(maxLevel, this.startLevel + levelChange));
3578
+ if (newLevel !== this.currentLevel || this.beforeElement !== before) {
3579
+ var _evt$dragEl, _evt$dragEl$setAttrib, _evt$ghostEl, _evt$ghostEl$setAttri;
3580
+ this.beforeElement = before;
3581
+ this.currentLevel = newLevel;
3582
+ if (evt.originalDragEl) {
3583
+ evt.originalDragEl.setAttribute("sortable-".concat(levelAttr), this.currentLevel);
3584
+ }
3585
+ (_evt$dragEl = evt.dragEl) === null || _evt$dragEl === void 0 || (_evt$dragEl$setAttrib = _evt$dragEl.setAttribute) === null || _evt$dragEl$setAttrib === void 0 || _evt$dragEl$setAttrib.call(_evt$dragEl, "sortable-".concat(levelAttr), this.currentLevel);
3586
+ (_evt$ghostEl = evt.ghostEl) === null || _evt$ghostEl === void 0 || (_evt$ghostEl$setAttri = _evt$ghostEl.setAttribute) === null || _evt$ghostEl$setAttri === void 0 || _evt$ghostEl$setAttri.call(_evt$ghostEl, "sortable-".concat(levelAttr), this.currentLevel);
3587
+ this.removeDragPrent();
3588
+ if (newLevel > 1) {
3589
+ dragParent = this._findPrevSibling(evt.dragEl, evt.originalDragEl, newLevel - 1);
3590
+ if (dragParent) dragParent.setAttribute('sortable-data-parent', 'true');
3591
+ }
3592
+ var target = before || after || this.sortable.el;
3593
+ var targetRect = getRect(target);
3594
+ this.sortable._getPlaceholderOnMove(this.sortable.el, getRect(evt.dragEl), target, targetRect, evt, Boolean(before));
3595
+ }
3596
+ }
3597
+ }, {
3598
+ key: "drop",
3599
+ value: function drop(evt) {
3600
+ var _evt$dragEl2, _evt$dragEl2$setAttri, _evt$ghostEl2, _evt$ghostEl2$setAttr;
3601
+ if (!this.options.tree) return;
3602
+ var levelAttr = this.options.treeItemLevelAttr || 'data-level';
3603
+ if (evt.originalDragEl) {
3604
+ evt.originalDragEl.setAttribute("sortable-".concat(levelAttr), this.currentLevel);
3605
+ }
3606
+ (_evt$dragEl2 = evt.dragEl) === null || _evt$dragEl2 === void 0 || (_evt$dragEl2$setAttri = _evt$dragEl2.setAttribute) === null || _evt$dragEl2$setAttri === void 0 || _evt$dragEl2$setAttri.call(_evt$dragEl2, "sortable-".concat(levelAttr), this.currentLevel);
3607
+ (_evt$ghostEl2 = evt.ghostEl) === null || _evt$ghostEl2 === void 0 || (_evt$ghostEl2$setAttr = _evt$ghostEl2.setAttribute) === null || _evt$ghostEl2$setAttr === void 0 || _evt$ghostEl2$setAttr.call(_evt$ghostEl2, "sortable-".concat(levelAttr), this.currentLevel);
3608
+ }
3609
+ }, {
3610
+ key: "removeDragPrent",
3611
+ value: function removeDragPrent() {
3612
+ if (dragParent) {
3613
+ dragParent.removeAttribute('sortable-data-parent');
3614
+ }
3615
+ dragParent = null;
3616
+ }
3617
+ }, {
3618
+ key: "nulling",
3619
+ value: function nulling() {
3620
+ this.removeDragPrent();
3621
+ this.startX = 0;
3622
+ this.startLevel = this.currentLevel = 1;
3623
+ }
3624
+ }]);
3625
+ }();
3626
+ _defineProperty(TreePlugin, "pluginName", 'tree');
3627
+ function getLevel(el, options) {
3628
+ var attr = options.treeItemLevelAttr || 'data-level';
3629
+ return parseInt(el.getAttribute(attr)) || 1;
3630
+ }
3631
+
3632
+ Sortable.mount(TreePlugin);
3633
+ Sortable.mount(AutoScroll);
3634
+ Sortable.mount(Remove, Revert);
3635
+
3636
+ export default Sortable;
3637
+ export { MultiDragPlugin as MultiDrag, Sortable, SwapPlugin as Swap };