@getflip/swirl-components 0.66.0 → 0.68.0

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