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