@pantograph/sortable 2.1.1 → 2.2.1

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