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