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