sortablejs 1.12.0 → 1.15.0

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