@sankhyalabs/ezui 5.22.0-dev.141 → 5.22.0-dev.142

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