Debian Codegraph @

templates/lib/400_Sortable-1.15.7.js

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