@satriobagasp/vue-slicksort 1.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,1273 @@
1
+ import { defineComponent, h } from 'vue';
2
+
3
+ // Export Sortable Element Component Mixin
4
+ const ElementMixin = defineComponent({
5
+ inject: ['manager'],
6
+ props: {
7
+ index: {
8
+ type: Number,
9
+ required: true,
10
+ },
11
+ disabled: {
12
+ type: Boolean,
13
+ default: false,
14
+ },
15
+ },
16
+ data() {
17
+ return {};
18
+ },
19
+ watch: {
20
+ index(newIndex) {
21
+ if (this.$el && this.$el.sortableInfo) {
22
+ this.$el.sortableInfo.index = newIndex;
23
+ }
24
+ },
25
+ disabled(isDisabled) {
26
+ if (isDisabled) {
27
+ this.removeDraggable();
28
+ }
29
+ else {
30
+ this.setDraggable(this.index);
31
+ }
32
+ },
33
+ },
34
+ mounted() {
35
+ const { disabled, index } = this.$props;
36
+ if (!disabled) {
37
+ this.setDraggable(index);
38
+ }
39
+ },
40
+ beforeUnmount() {
41
+ if (!this.disabled)
42
+ this.removeDraggable();
43
+ },
44
+ methods: {
45
+ setDraggable(index) {
46
+ const node = this.$el;
47
+ node.sortableInfo = {
48
+ index,
49
+ manager: this.manager,
50
+ };
51
+ this.ref = { node };
52
+ this.manager.add(this.ref);
53
+ },
54
+ removeDraggable() {
55
+ this.manager.remove(this.ref);
56
+ },
57
+ },
58
+ });
59
+
60
+ class Manager {
61
+ constructor() {
62
+ this.refs = [];
63
+ this.active = null;
64
+ }
65
+ add(ref) {
66
+ if (!this.refs) {
67
+ this.refs = [];
68
+ }
69
+ this.refs.push(ref);
70
+ }
71
+ remove(ref) {
72
+ const index = this.getIndex(ref);
73
+ if (index !== -1) {
74
+ this.refs.splice(index, 1);
75
+ }
76
+ }
77
+ isActive() {
78
+ return !!this.active;
79
+ }
80
+ getActive() {
81
+ return this.refs.find(({ node }) => { var _a, _b; return ((_a = node === null || node === void 0 ? void 0 : node.sortableInfo) === null || _a === void 0 ? void 0 : _a.index) == ((_b = this === null || this === void 0 ? void 0 : this.active) === null || _b === void 0 ? void 0 : _b.index); }) || null;
82
+ }
83
+ getIndex(ref) {
84
+ return this.refs.indexOf(ref);
85
+ }
86
+ getRefs() {
87
+ return this.refs;
88
+ }
89
+ getOrderedRefs() {
90
+ return this.refs.sort((a, b) => {
91
+ return a.node.sortableInfo.index - b.node.sortableInfo.index;
92
+ });
93
+ }
94
+ }
95
+
96
+ const isTouch = (e) => {
97
+ return e.touches != null;
98
+ };
99
+ // eslint-disable-next-line @typescript-eslint/ban-types
100
+ function hasOwnProperty(obj, prop) {
101
+ return !!obj && Object.prototype.hasOwnProperty.call(obj, prop);
102
+ }
103
+ function arrayMove(arr, previousIndex, newIndex) {
104
+ const array = arr.slice(0);
105
+ if (newIndex >= array.length) {
106
+ let k = newIndex - array.length;
107
+ while (k-- + 1) {
108
+ array.push(undefined);
109
+ }
110
+ }
111
+ array.splice(newIndex, 0, array.splice(previousIndex, 1)[0]);
112
+ return array;
113
+ }
114
+ function arrayRemove(arr, previousIndex) {
115
+ const array = arr.slice(0);
116
+ if (previousIndex >= array.length)
117
+ return array;
118
+ array.splice(previousIndex, 1);
119
+ return array;
120
+ }
121
+ function arrayInsert(arr, newIndex, value) {
122
+ const array = arr.slice(0);
123
+ if (newIndex === array.length) {
124
+ array.push(value);
125
+ }
126
+ else {
127
+ array.splice(newIndex, 0, value);
128
+ }
129
+ return array;
130
+ }
131
+ const events = {
132
+ start: ['touchstart', 'mousedown'],
133
+ move: ['touchmove', 'mousemove'],
134
+ end: ['touchend', 'mouseup'],
135
+ cancel: ['touchcancel', 'keyup'],
136
+ };
137
+ function closest(el, fn) {
138
+ while (el) {
139
+ if (fn(el))
140
+ return el;
141
+ el = el.parentNode;
142
+ }
143
+ }
144
+ function limit(min, max, value) {
145
+ if (value < min) {
146
+ return min;
147
+ }
148
+ if (value > max) {
149
+ return max;
150
+ }
151
+ return value;
152
+ }
153
+ function getCSSPixelValue(stringValue) {
154
+ if (stringValue.substr(-2) === 'px') {
155
+ return parseFloat(stringValue);
156
+ }
157
+ return 0;
158
+ }
159
+ function getElementMargin(element) {
160
+ const style = window.getComputedStyle(element);
161
+ return {
162
+ top: getCSSPixelValue(style.marginTop),
163
+ right: getCSSPixelValue(style.marginRight),
164
+ bottom: getCSSPixelValue(style.marginBottom),
165
+ left: getCSSPixelValue(style.marginLeft),
166
+ };
167
+ }
168
+ function getPointerOffset(e, reference = 'page') {
169
+ const x = `${reference}X`;
170
+ const y = `${reference}Y`;
171
+ return {
172
+ x: isTouch(e) ? e.touches[0][x] : e[x],
173
+ y: isTouch(e) ? e.touches[0][y] : e[y],
174
+ };
175
+ }
176
+ function offsetParents(node) {
177
+ const nodes = [node];
178
+ for (; node; node = node.offsetParent) {
179
+ nodes.unshift(node);
180
+ }
181
+ return nodes;
182
+ }
183
+ function commonOffsetParent(node1, node2) {
184
+ const parents1 = offsetParents(node1);
185
+ const parents2 = offsetParents(node2);
186
+ if (parents1[0] != parents2[0])
187
+ throw 'No common ancestor!';
188
+ for (let i = 0; i < parents1.length; i++) {
189
+ if (parents1[i] != parents2[i])
190
+ return parents1[i - 1];
191
+ }
192
+ }
193
+ function getEdgeOffset(node, container, offset = { top: 0, left: 0 }) {
194
+ // Get the actual offsetTop / offsetLeft value, no matter how deep the node is nested
195
+ if (node) {
196
+ const nodeOffset = {
197
+ top: offset.top + node.offsetTop,
198
+ left: offset.left + node.offsetLeft,
199
+ };
200
+ if (node.offsetParent !== container.offsetParent) {
201
+ return getEdgeOffset(node.offsetParent, container, nodeOffset);
202
+ }
203
+ else {
204
+ return nodeOffset;
205
+ }
206
+ }
207
+ return { top: 0, left: 0 };
208
+ }
209
+ function cloneNode(node) {
210
+ const fields = node.querySelectorAll('input, textarea, select');
211
+ const clonedNode = node.cloneNode(true);
212
+ const clonedFields = [...clonedNode.querySelectorAll('input, textarea, select')]; // Convert NodeList to Array
213
+ clonedFields.forEach((field, index) => {
214
+ if (field.type !== 'file' && fields[index]) {
215
+ field.value = fields[index].value;
216
+ }
217
+ });
218
+ return clonedNode;
219
+ }
220
+ function getLockPixelOffsets(lockOffset, width, height) {
221
+ if (typeof lockOffset == 'string') {
222
+ lockOffset = +lockOffset;
223
+ }
224
+ if (!Array.isArray(lockOffset)) {
225
+ lockOffset = [lockOffset, lockOffset];
226
+ }
227
+ if (lockOffset.length !== 2) {
228
+ throw new Error(`lockOffset prop of SortableContainer should be a single value or an array of exactly two values. Given ${lockOffset}`);
229
+ }
230
+ const [minLockOffset, maxLockOffset] = lockOffset;
231
+ return [getLockPixelOffset(minLockOffset, width, height), getLockPixelOffset(maxLockOffset, width, height)];
232
+ }
233
+ function getLockPixelOffset(lockOffset, width, height) {
234
+ let offsetX = lockOffset;
235
+ let offsetY = lockOffset;
236
+ let unit = 'px';
237
+ if (typeof lockOffset === 'string') {
238
+ const match = /^[+-]?\d*(?:\.\d*)?(px|%)$/.exec(lockOffset);
239
+ if (match === null) {
240
+ throw new Error(`lockOffset value should be a number or a string of a number followed by "px" or "%". Given ${lockOffset}`);
241
+ }
242
+ offsetX = offsetY = parseFloat(lockOffset);
243
+ unit = match[1];
244
+ }
245
+ if (!isFinite(offsetX) || !isFinite(offsetY)) {
246
+ throw new Error(`lockOffset value should be a finite. Given ${lockOffset}`);
247
+ }
248
+ if (unit === '%') {
249
+ offsetX = (offsetX * width) / 100;
250
+ offsetY = (offsetY * height) / 100;
251
+ }
252
+ return {
253
+ x: offsetX,
254
+ y: offsetY,
255
+ };
256
+ }
257
+ function getDistance(x1, y1, x2, y2) {
258
+ const x = x1 - x2;
259
+ const y = y1 - y2;
260
+ return Math.sqrt(x * x + y * y);
261
+ }
262
+ function getRectCenter(clientRect) {
263
+ return {
264
+ x: clientRect.left + clientRect.width / 2,
265
+ y: clientRect.top + clientRect.height / 2,
266
+ };
267
+ }
268
+ function resetTransform(nodes = []) {
269
+ for (let i = 0, len = nodes.length; i < len; i++) {
270
+ const node = nodes[i];
271
+ const el = node.node;
272
+ if (!el)
273
+ return;
274
+ // Clear the cached offsetTop / offsetLeft value
275
+ node.edgeOffset = null;
276
+ // Remove the transforms / transitions
277
+ setTransform(el);
278
+ }
279
+ }
280
+ function setTransform(el, transform = '', duration = '') {
281
+ if (!el)
282
+ return;
283
+ el.style['transform'] = transform;
284
+ el.style['transitionDuration'] = duration;
285
+ }
286
+ function withinBounds(pos, top, bottom) {
287
+ const upper = Math.max(top, bottom);
288
+ const lower = Math.min(top, bottom);
289
+ return lower <= pos && pos <= upper;
290
+ }
291
+ function isPointWithinRect({ x, y }, { top, left, width, height }) {
292
+ const withinX = withinBounds(x, left, left + width);
293
+ const withinY = withinBounds(y, top, top + height);
294
+ return withinX && withinY;
295
+ }
296
+
297
+ /* eslint-disable @typescript-eslint/ban-ts-comment */
298
+ // eslint-disable-next-line @typescript-eslint/ban-types
299
+ const timeout = setTimeout;
300
+ // Export Sortable Container Component Mixin
301
+ const ContainerMixin = defineComponent({
302
+ inject: {
303
+ SlicksortHub: {
304
+ from: 'SlicksortHub',
305
+ default: null,
306
+ },
307
+ },
308
+ provide() {
309
+ return {
310
+ manager: this.manager,
311
+ };
312
+ },
313
+ props: {
314
+ list: { type: Array, required: true },
315
+ axis: { type: String, default: 'y' },
316
+ distance: { type: Number, default: 0 },
317
+ pressDelay: { type: Number, default: 0 },
318
+ pressThreshold: { type: Number, default: 5 },
319
+ useDragHandle: { type: Boolean, default: false },
320
+ useWindowAsScrollContainer: { type: Boolean, default: false },
321
+ hideSortableGhost: { type: Boolean, default: true },
322
+ lockToContainerEdges: { type: Boolean, default: false },
323
+ lockOffset: { type: [String, Number, Array], default: '50%' },
324
+ transitionDuration: { type: Number, default: 300 },
325
+ appendTo: { type: String, default: 'body' },
326
+ draggedSettlingDuration: { type: Number, default: null },
327
+ group: { type: String, default: '' },
328
+ accept: { type: [Boolean, Array, Function], default: null },
329
+ cancelKey: { type: String, default: 'Escape' },
330
+ block: { type: Array, default: () => [] },
331
+ lockAxis: { type: String, default: '' },
332
+ helperClass: { type: String, default: '' },
333
+ contentWindow: { type: Object, default: null },
334
+ shouldCancelStart: {
335
+ type: Function,
336
+ default: (e) => {
337
+ // Cancel sorting if the event target is an `input`, `textarea`, `select` or `option`
338
+ const disabledElements = ['input', 'textarea', 'select', 'option', 'button'];
339
+ return disabledElements.indexOf(e.target.tagName.toLowerCase()) !== -1;
340
+ },
341
+ },
342
+ getHelperDimensions: {
343
+ type: Function,
344
+ default: ({ node }) => ({
345
+ width: node.offsetWidth,
346
+ height: node.offsetHeight,
347
+ }),
348
+ },
349
+ },
350
+ emits: ['sort-start', 'sort-move', 'sort-end', 'sort-cancel', 'sort-insert', 'sort-remove', 'update:list'],
351
+ data() {
352
+ let useHub = false;
353
+ if (this.group) {
354
+ // If the group option is set, it is assumed the user intends
355
+ // to drag between containers and the required plugin has been installed
356
+ if (this.SlicksortHub) {
357
+ useHub = true;
358
+ }
359
+ else if (process.env.NODE_ENV !== 'production') {
360
+ throw new Error('Slicksort plugin required to use "group" prop');
361
+ }
362
+ }
363
+ return {
364
+ sorting: false,
365
+ hub: useHub ? this.SlicksortHub : null,
366
+ manager: new Manager(),
367
+ };
368
+ },
369
+ mounted() {
370
+ if (this.hub) {
371
+ this.id = this.hub.getId();
372
+ }
373
+ this.container = this.$el;
374
+ this.document = this.container.ownerDocument || document;
375
+ this._window = this.contentWindow || window;
376
+ // Find the actual scroll container by traversing up the DOM
377
+ if (this.useWindowAsScrollContainer) {
378
+ this.scrollContainer = { scrollLeft: 0, scrollTop: 0 };
379
+ }
380
+ else {
381
+ // Start from parent element to find scrollable container
382
+ let scrollContainer = this.container.parentElement;
383
+ while (scrollContainer && scrollContainer !== document.body) {
384
+ const overflowY = window.getComputedStyle(scrollContainer).overflowY;
385
+ if (overflowY === 'auto' || overflowY === 'scroll') {
386
+ break;
387
+ }
388
+ scrollContainer = scrollContainer.parentElement;
389
+ }
390
+ this.scrollContainer = scrollContainer || this.container;
391
+ }
392
+ this.events = {
393
+ start: this.handleStart,
394
+ move: this.handleMove,
395
+ end: this.handleEnd,
396
+ };
397
+ for (const key in this.events) {
398
+ if (hasOwnProperty(this.events, key)) {
399
+ // @ts-ignore
400
+ events[key].forEach((eventName) => this.container.addEventListener(eventName, this.events[key]));
401
+ }
402
+ }
403
+ if (this.hub) {
404
+ this.hub.addContainer(this);
405
+ }
406
+ },
407
+ beforeUnmount() {
408
+ for (const key in this.events) {
409
+ if (hasOwnProperty(this.events, key)) {
410
+ // @ts-ignore
411
+ events[key].forEach((eventName) => this.container.removeEventListener(eventName, this.events[key]));
412
+ }
413
+ }
414
+ if (this.hub) {
415
+ this.hub.removeContainer(this);
416
+ }
417
+ if (this.dragendTimer)
418
+ clearTimeout(this.dragendTimer);
419
+ if (this.cancelTimer)
420
+ clearTimeout(this.cancelTimer);
421
+ if (this.pressTimer)
422
+ clearTimeout(this.pressTimer);
423
+ if (this.autoscrollInterval)
424
+ clearInterval(this.autoscrollInterval);
425
+ },
426
+ methods: {
427
+ handleStart(e) {
428
+ const { distance, shouldCancelStart } = this.$props;
429
+ if ((!isTouch(e) && e.button === 2) || shouldCancelStart(e)) {
430
+ return false;
431
+ }
432
+ this._touched = true;
433
+ this._pos = getPointerOffset(e);
434
+ const target = e.target;
435
+ const node = closest(target, (el) => el.sortableInfo != null);
436
+ if (node && node.sortableInfo && this.nodeIsChild(node) && !this.sorting) {
437
+ const { useDragHandle } = this.$props;
438
+ const { index } = node.sortableInfo;
439
+ if (useDragHandle && !closest(target, (el) => el.sortableHandle != null))
440
+ return;
441
+ this.manager.active = { index };
442
+ /*
443
+ * Fixes a bug in Firefox where the :active state of anchor tags
444
+ * prevent subsequent 'mousemove' events from being fired
445
+ * (see https://github.com/clauderic/react-sortable-hoc/issues/118)
446
+ */
447
+ if (target.tagName.toLowerCase() === 'a') {
448
+ e.preventDefault();
449
+ }
450
+ if (!distance) {
451
+ if (this.pressDelay === 0) {
452
+ this.handlePress(e);
453
+ }
454
+ else {
455
+ this.pressTimer = timeout(() => this.handlePress(e), this.pressDelay);
456
+ }
457
+ }
458
+ }
459
+ },
460
+ nodeIsChild(node) {
461
+ return node.sortableInfo.manager === this.manager;
462
+ },
463
+ handleMove(e) {
464
+ const { distance, pressThreshold } = this.$props;
465
+ if (!this.sorting && this._touched) {
466
+ const offset = getPointerOffset(e);
467
+ this._delta = {
468
+ x: this._pos.x - offset.x,
469
+ y: this._pos.y - offset.y,
470
+ };
471
+ const delta = Math.abs(this._delta.x) + Math.abs(this._delta.y);
472
+ if (!distance && (!pressThreshold || (pressThreshold && delta >= pressThreshold))) {
473
+ if (this.cancelTimer)
474
+ clearTimeout(this.cancelTimer);
475
+ this.cancelTimer = timeout(this.cancel, 0);
476
+ }
477
+ else if (distance && delta >= distance && this.manager.isActive()) {
478
+ this.handlePress(e);
479
+ }
480
+ }
481
+ },
482
+ handleEnd() {
483
+ if (!this._touched)
484
+ return;
485
+ const { distance } = this.$props;
486
+ this._touched = false;
487
+ if (!distance) {
488
+ this.cancel();
489
+ }
490
+ },
491
+ cancel() {
492
+ if (!this.sorting) {
493
+ clearTimeout(this.pressTimer);
494
+ this.manager.active = null;
495
+ if (this.hub)
496
+ this.hub.cancel();
497
+ }
498
+ },
499
+ handleSortCancel(e) {
500
+ if (isTouch(e) || e.key === this.cancelKey) {
501
+ this.newIndex = this.index;
502
+ this.canceling = true;
503
+ this.translate = { x: 0, y: 0 };
504
+ this.animateNodes();
505
+ this.handleSortEnd(e);
506
+ }
507
+ },
508
+ handlePress(e) {
509
+ e.stopPropagation();
510
+ const active = this.manager.getActive();
511
+ if (active) {
512
+ const { getHelperDimensions, helperClass, hideSortableGhost, appendTo } = this.$props;
513
+ const { node } = active;
514
+ const { index } = node.sortableInfo;
515
+ const margin = getElementMargin(node);
516
+ const containerBoundingRect = this.container.getBoundingClientRect();
517
+ const dimensions = getHelperDimensions({ index, node });
518
+ this.node = node;
519
+ this.margin = margin;
520
+ this.width = dimensions.width;
521
+ this.height = dimensions.height;
522
+ this.marginOffset = {
523
+ x: this.margin.left + this.margin.right,
524
+ y: Math.max(this.margin.top, this.margin.bottom),
525
+ };
526
+ this.boundingClientRect = node.getBoundingClientRect();
527
+ this.containerBoundingRect = containerBoundingRect;
528
+ this.index = index;
529
+ this.newIndex = index;
530
+ const clonedNode = cloneNode(node);
531
+ this.helper = this.document.querySelector(appendTo).appendChild(clonedNode);
532
+ this.helper.style.position = 'fixed';
533
+ this.helper.style.top = `${this.boundingClientRect.top - margin.top}px`;
534
+ this.helper.style.left = `${this.boundingClientRect.left - margin.left}px`;
535
+ this.helper.style.width = `${this.width}px`;
536
+ this.helper.style.height = `${this.height}px`;
537
+ this.helper.style.boxSizing = 'border-box';
538
+ this.helper.style.pointerEvents = 'none';
539
+ if (hideSortableGhost) {
540
+ this.sortableGhost = node;
541
+ node.style.visibility = 'hidden';
542
+ node.style.opacity = '0';
543
+ }
544
+ if (this.hub) {
545
+ this.hub.sortStart(this);
546
+ this.hub.helper = this.helper;
547
+ this.hub.ghost = this.sortableGhost;
548
+ }
549
+ this.intializeOffsets(e, this.boundingClientRect);
550
+ this.offsetEdge = getEdgeOffset(node, this.container);
551
+ if (helperClass) {
552
+ this.helper.classList.add(...helperClass.split(' '));
553
+ }
554
+ this.listenerNode = isTouch(e) ? node : this._window;
555
+ // @ts-ignore
556
+ events.move.forEach((eventName) => this.listenerNode.addEventListener(eventName, this.handleSortMove));
557
+ // @ts-ignore
558
+ events.end.forEach((eventName) => this.listenerNode.addEventListener(eventName, this.handleSortEnd));
559
+ // @ts-ignore
560
+ events.cancel.forEach((eventName) => this.listenerNode.addEventListener(eventName, this.handleSortCancel));
561
+ this.sorting = true;
562
+ this.$emit('sort-start', { event: e, node, index });
563
+ }
564
+ },
565
+ handleSortMove(e) {
566
+ e.preventDefault(); // Prevent scrolling on mobile
567
+ this.updatePosition(e);
568
+ if (this.hub) {
569
+ const payload = this.list[this.index];
570
+ this.hub.handleSortMove(e, payload);
571
+ }
572
+ if (!this.hub || this.hub.isDest(this)) {
573
+ this.animateNodes();
574
+ this.autoscroll();
575
+ }
576
+ this.$emit('sort-move', { event: e });
577
+ },
578
+ handleDropOut() {
579
+ const removed = this.list[this.index];
580
+ const newValue = arrayRemove(this.list, this.index);
581
+ this.$emit('sort-remove', {
582
+ oldIndex: this.index,
583
+ });
584
+ this.$emit('update:list', newValue);
585
+ return removed;
586
+ },
587
+ handleDropIn(payload) {
588
+ const newValue = arrayInsert(this.list, this.newIndex, payload);
589
+ this.$emit('sort-insert', {
590
+ newIndex: this.newIndex,
591
+ value: payload,
592
+ });
593
+ this.$emit('update:list', newValue);
594
+ this.handleDragEnd();
595
+ },
596
+ handleDragOut() {
597
+ if (this.autoscrollInterval) {
598
+ clearInterval(this.autoscrollInterval);
599
+ this.autoscrollInterval = null;
600
+ }
601
+ if (this.hub.isSource(this)) {
602
+ // Trick to animate all nodes up
603
+ this.translate = {
604
+ x: 10000,
605
+ y: 10000,
606
+ };
607
+ this.animateNodes();
608
+ }
609
+ else {
610
+ this.manager.getRefs().forEach((ref) => {
611
+ ref.node.style['transform'] = '';
612
+ });
613
+ this.dragendTimer = timeout(this.handleDragEnd, this.transitionDuration || 0);
614
+ }
615
+ },
616
+ handleDragEnd() {
617
+ if (this.autoscrollInterval) {
618
+ clearInterval(this.autoscrollInterval);
619
+ this.autoscrollInterval = null;
620
+ }
621
+ resetTransform(this.manager.getRefs());
622
+ if (this.sortableGhost) {
623
+ this.sortableGhost.remove();
624
+ this.sortableGhost = null;
625
+ }
626
+ if (this.dragendTimer) {
627
+ clearTimeout(this.dragendTimer);
628
+ this.dragendTimer = null;
629
+ }
630
+ this.manager.active = null;
631
+ this._touched = false;
632
+ this.sorting = false;
633
+ },
634
+ intializeOffsets(e, clientRect) {
635
+ const { useWindowAsScrollContainer, containerBoundingRect, _window } = this;
636
+ this.marginOffset = {
637
+ x: this.margin.left + this.margin.right,
638
+ y: Math.max(this.margin.top, this.margin.bottom),
639
+ };
640
+ this._axis = {
641
+ x: this.axis.indexOf('x') >= 0,
642
+ y: this.axis.indexOf('y') >= 0,
643
+ };
644
+ this.initialOffset = getPointerOffset(e);
645
+ // initialScroll;
646
+ this.initialScroll = {
647
+ top: this.scrollContainer.scrollTop,
648
+ left: this.scrollContainer.scrollLeft,
649
+ };
650
+ // initialWindowScroll;
651
+ this.initialWindowScroll = {
652
+ top: window.pageYOffset,
653
+ left: window.pageXOffset,
654
+ };
655
+ this.translate = { x: 0, y: 0 };
656
+ this.minTranslate = {};
657
+ this.maxTranslate = {};
658
+ if (this._axis.x) {
659
+ this.minTranslate.x =
660
+ (useWindowAsScrollContainer ? 0 : containerBoundingRect.left) - clientRect.left - this.width / 2;
661
+ this.maxTranslate.x =
662
+ (useWindowAsScrollContainer ? _window.innerWidth : containerBoundingRect.left + containerBoundingRect.width) -
663
+ clientRect.left -
664
+ this.width / 2;
665
+ }
666
+ if (this._axis.y) {
667
+ this.minTranslate.y =
668
+ (useWindowAsScrollContainer ? 0 : containerBoundingRect.top) - clientRect.top - this.height / 2;
669
+ this.maxTranslate.y =
670
+ (useWindowAsScrollContainer
671
+ ? _window.innerHeight
672
+ : containerBoundingRect.top + containerBoundingRect.height) -
673
+ clientRect.top -
674
+ this.height / 2;
675
+ }
676
+ },
677
+ handleDragIn(e, sortableGhost, helper) {
678
+ if (this.hub.isSource(this)) {
679
+ return;
680
+ }
681
+ if (this.dragendTimer) {
682
+ this.handleDragEnd();
683
+ clearTimeout(this.dragendTimer);
684
+ this.dragendTimer = null;
685
+ }
686
+ const nodes = this.manager.getRefs();
687
+ this.index = nodes.length;
688
+ this.manager.active = { index: this.index };
689
+ const containerBoundingRect = this.container.getBoundingClientRect();
690
+ const helperBoundingRect = helper.getBoundingClientRect();
691
+ this.containerBoundingRect = containerBoundingRect;
692
+ this.sortableGhost = cloneNode(sortableGhost);
693
+ this.container.appendChild(this.sortableGhost);
694
+ const ghostRect = this.sortableGhost.getBoundingClientRect();
695
+ this.boundingClientRect = ghostRect;
696
+ this.margin = getElementMargin(this.sortableGhost);
697
+ this.width = ghostRect.width;
698
+ this.height = ghostRect.height;
699
+ // XY coords of the inserted node, relative to the top-left corner of the container
700
+ this.offsetEdge = getEdgeOffset(this.sortableGhost, this.container);
701
+ this.intializeOffsets(e, ghostRect);
702
+ // Move the initialOffset back to the insertion point of the
703
+ // sortableGhost (end of the list), as if we had started the drag there.
704
+ this.initialOffset.x += ghostRect.x - helperBoundingRect.x;
705
+ this.initialOffset.y += ghostRect.y - helperBoundingRect.y;
706
+ // Turn on dragging
707
+ this.sorting = true;
708
+ },
709
+ handleSortEnd(e) {
710
+ // Remove the event listeners if the node is still in the DOM
711
+ if (this.listenerNode) {
712
+ events.move.forEach((eventName) =>
713
+ // @ts-ignore
714
+ this.listenerNode.removeEventListener(eventName, this.handleSortMove));
715
+ events.end.forEach((eventName) =>
716
+ // @ts-ignore
717
+ this.listenerNode.removeEventListener(eventName, this.handleSortEnd));
718
+ events.cancel.forEach((eventName) =>
719
+ // @ts-ignore
720
+ this.listenerNode.removeEventListener(eventName, this.handleSortCancel));
721
+ }
722
+ const nodes = this.manager.getRefs();
723
+ // Remove the helper class(es) early to give it a chance to transition back
724
+ if (this.helper && this.helperClass) {
725
+ this.helper.classList.remove(...this.helperClass.split(' '));
726
+ }
727
+ // Stop autoscroll
728
+ if (this.autoscrollInterval)
729
+ clearInterval(this.autoscrollInterval);
730
+ this.autoscrollInterval = null;
731
+ const onEnd = () => {
732
+ // Remove the helper from the DOM
733
+ if (this.helper) {
734
+ this.helper.remove();
735
+ this.helper = null;
736
+ }
737
+ if (this.hideSortableGhost && this.sortableGhost) {
738
+ this.sortableGhost.style.visibility = '';
739
+ this.sortableGhost.style.opacity = '';
740
+ }
741
+ resetTransform(nodes);
742
+ // Update state
743
+ if (this.hub && !this.hub.isDest(this)) {
744
+ this.canceling ? this.hub.cancel() : this.hub.handleSortEnd();
745
+ }
746
+ else if (this.canceling) {
747
+ this.$emit('sort-cancel', { event: e });
748
+ }
749
+ else {
750
+ this.$emit('sort-end', {
751
+ event: e,
752
+ oldIndex: this.index,
753
+ newIndex: this.newIndex,
754
+ });
755
+ this.$emit('update:list', arrayMove(this.list, this.index, this.newIndex));
756
+ }
757
+ this.manager.active = null;
758
+ this._touched = false;
759
+ this.canceling = false;
760
+ this.sorting = false;
761
+ };
762
+ if (this.transitionDuration || this.draggedSettlingDuration) {
763
+ this.transitionHelperIntoPlace(nodes, onEnd);
764
+ }
765
+ else {
766
+ onEnd();
767
+ }
768
+ },
769
+ transitionHelperIntoPlace(nodes, cb) {
770
+ if (this.draggedSettlingDuration === 0 || nodes.length === 0 || !this.helper) {
771
+ return Promise.resolve();
772
+ }
773
+ const indexNode = nodes[this.index].node;
774
+ let targetX = 0;
775
+ let targetY = 0;
776
+ const scrollDifference = {
777
+ top: window.pageYOffset - this.initialWindowScroll.top,
778
+ left: window.pageXOffset - this.initialWindowScroll.left,
779
+ };
780
+ if (this.hub && !this.hub.isDest(this) && !this.canceling) {
781
+ const dest = this.hub.getDest();
782
+ if (!dest)
783
+ return;
784
+ const destIndex = dest.newIndex;
785
+ const destRefs = dest.manager.getOrderedRefs();
786
+ const destNode = destIndex < destRefs.length ? destRefs[destIndex].node : dest.sortableGhost;
787
+ const ancestor = commonOffsetParent(indexNode, destNode);
788
+ const sourceOffset = getEdgeOffset(indexNode, ancestor);
789
+ const targetOffset = getEdgeOffset(destNode, ancestor);
790
+ targetX = targetOffset.left - sourceOffset.left - scrollDifference.left;
791
+ targetY = targetOffset.top - sourceOffset.top - scrollDifference.top;
792
+ }
793
+ else {
794
+ const newIndexNode = nodes[this.newIndex].node;
795
+ const deltaScroll = {
796
+ left: this.scrollContainer.scrollLeft - this.initialScroll.left + scrollDifference.left,
797
+ top: this.scrollContainer.scrollTop - this.initialScroll.top + scrollDifference.top,
798
+ };
799
+ targetX = -deltaScroll.left;
800
+ if (this.translate && this.translate.x > 0) {
801
+ // Diff against right edge when moving to the right
802
+ targetX +=
803
+ newIndexNode.offsetLeft + newIndexNode.offsetWidth - (indexNode.offsetLeft + indexNode.offsetWidth);
804
+ }
805
+ else {
806
+ targetX += newIndexNode.offsetLeft - indexNode.offsetLeft;
807
+ }
808
+ targetY = -deltaScroll.top;
809
+ if (this.translate && this.translate.y > 0) {
810
+ // Diff against the bottom edge when moving down
811
+ targetY +=
812
+ newIndexNode.offsetTop + newIndexNode.offsetHeight - (indexNode.offsetTop + indexNode.offsetHeight);
813
+ }
814
+ else {
815
+ targetY += newIndexNode.offsetTop - indexNode.offsetTop;
816
+ }
817
+ }
818
+ const duration = this.draggedSettlingDuration !== null ? this.draggedSettlingDuration : this.transitionDuration;
819
+ setTransform(this.helper, `translate3d(${targetX}px,${targetY}px, 0)`, `${duration}ms`);
820
+ // Register an event handler to clean up styles when the transition
821
+ // finishes.
822
+ const cleanup = (event) => {
823
+ if (!event || event.propertyName === 'transform') {
824
+ clearTimeout(cleanupTimer);
825
+ setTransform(this.helper);
826
+ cb();
827
+ }
828
+ };
829
+ // Force cleanup in case 'transitionend' never fires
830
+ const cleanupTimer = setTimeout(cleanup, duration + 10);
831
+ this.helper.addEventListener('transitionend', cleanup);
832
+ },
833
+ updatePosition(e) {
834
+ const { lockAxis, lockToContainerEdges } = this.$props;
835
+ const offset = getPointerOffset(e);
836
+ const translate = {
837
+ x: offset.x - this.initialOffset.x,
838
+ y: offset.y - this.initialOffset.y,
839
+ };
840
+ // Adjust for window scroll
841
+ translate.y -= window.pageYOffset - this.initialWindowScroll.top;
842
+ translate.x -= window.pageXOffset - this.initialWindowScroll.left;
843
+ this.translate = translate;
844
+ if (lockToContainerEdges) {
845
+ const [minLockOffset, maxLockOffset] = getLockPixelOffsets(this.lockOffset, this.height, this.width);
846
+ const minOffset = {
847
+ x: this.width / 2 - minLockOffset.x,
848
+ y: this.height / 2 - minLockOffset.y,
849
+ };
850
+ const maxOffset = {
851
+ x: this.width / 2 - maxLockOffset.x,
852
+ y: this.height / 2 - maxLockOffset.y,
853
+ };
854
+ if (this.minTranslate.x && this.maxTranslate.x)
855
+ translate.x = limit(this.minTranslate.x + minOffset.x, this.maxTranslate.x - maxOffset.x, translate.x);
856
+ if (this.minTranslate.y && this.maxTranslate.y)
857
+ translate.y = limit(this.minTranslate.y + minOffset.y, this.maxTranslate.y - maxOffset.y, translate.y);
858
+ }
859
+ if (lockAxis === 'x') {
860
+ translate.y = 0;
861
+ }
862
+ else if (lockAxis === 'y') {
863
+ translate.x = 0;
864
+ }
865
+ if (this.helper) {
866
+ this.helper.style['transform'] = `translate3d(${translate.x}px,${translate.y}px, 0)`;
867
+ }
868
+ },
869
+ animateNodes() {
870
+ const { transitionDuration, hideSortableGhost } = this.$props;
871
+ const nodes = this.manager.getOrderedRefs();
872
+ const deltaScroll = {
873
+ left: this.scrollContainer.scrollLeft - this.initialScroll.left,
874
+ top: this.scrollContainer.scrollTop - this.initialScroll.top,
875
+ };
876
+ const sortingOffset = {
877
+ left: this.offsetEdge.left + this.translate.x + deltaScroll.left,
878
+ top: this.offsetEdge.top + this.translate.y + deltaScroll.top,
879
+ };
880
+ const scrollDifference = {
881
+ top: window.pageYOffset - this.initialWindowScroll.top,
882
+ left: window.pageXOffset - this.initialWindowScroll.left,
883
+ };
884
+ this.newIndex = null;
885
+ for (let i = 0, len = nodes.length; i < len; i++) {
886
+ const { node } = nodes[i];
887
+ const index = node.sortableInfo.index;
888
+ const width = node.offsetWidth;
889
+ const height = node.offsetHeight;
890
+ const offset = {
891
+ width: this.width > width ? width / 2 : this.width / 2,
892
+ height: this.height > height ? height / 2 : this.height / 2,
893
+ };
894
+ const translate = {
895
+ x: 0,
896
+ y: 0,
897
+ };
898
+ let { edgeOffset } = nodes[i];
899
+ // If we haven't cached the node's offsetTop / offsetLeft value
900
+ if (!edgeOffset) {
901
+ nodes[i].edgeOffset = edgeOffset = getEdgeOffset(node, this.container);
902
+ }
903
+ // Get a reference to the next and previous node
904
+ const nextNode = i < nodes.length - 1 && nodes[i + 1];
905
+ const prevNode = i > 0 && nodes[i - 1];
906
+ // Also cache the next node's edge offset if needed.
907
+ // We need this for calculating the animation in a grid setup
908
+ if (nextNode && !nextNode.edgeOffset) {
909
+ nextNode.edgeOffset = getEdgeOffset(nextNode.node, this.container);
910
+ }
911
+ // If the node is the one we're currently animating, skip it
912
+ if (index === this.index) {
913
+ /*
914
+ * With windowing libraries such as `react-virtualized`, the sortableGhost
915
+ * node may change while scrolling down and then back up (or vice-versa),
916
+ * so we need to update the reference to the new node just to be safe.
917
+ */
918
+ if (hideSortableGhost) {
919
+ this.sortableGhost = node;
920
+ node.style.visibility = 'hidden';
921
+ node.style.opacity = '0';
922
+ }
923
+ continue;
924
+ }
925
+ if (transitionDuration) {
926
+ node.style['transitionDuration'] = `${transitionDuration}ms`;
927
+ }
928
+ if (this._axis.x) {
929
+ if (this._axis.y) {
930
+ // Calculations for a grid setup
931
+ if (index < this.index &&
932
+ ((sortingOffset.left + scrollDifference.left - offset.width <= edgeOffset.left &&
933
+ sortingOffset.top + scrollDifference.top <= edgeOffset.top + offset.height) ||
934
+ sortingOffset.top + scrollDifference.top + offset.height <= edgeOffset.top)) {
935
+ // If the current node is to the left on the same row, or above the node that's being dragged
936
+ // then move it to the right
937
+ translate.x = this.width + this.marginOffset.x;
938
+ if (edgeOffset.left + translate.x > this.containerBoundingRect.width - offset.width && nextNode) {
939
+ // If it moves passed the right bounds, then animate it to the first position of the next row.
940
+ // We just use the offset of the next node to calculate where to move, because that node's original position
941
+ // is exactly where we want to go
942
+ translate.x = nextNode.edgeOffset.left - edgeOffset.left;
943
+ translate.y = nextNode.edgeOffset.top - edgeOffset.top;
944
+ }
945
+ if (this.newIndex === null) {
946
+ this.newIndex = index;
947
+ }
948
+ }
949
+ else if (index > this.index &&
950
+ ((sortingOffset.left + scrollDifference.left + offset.width >= edgeOffset.left &&
951
+ sortingOffset.top + scrollDifference.top + offset.height >= edgeOffset.top) ||
952
+ sortingOffset.top + scrollDifference.top + offset.height >= edgeOffset.top + height)) {
953
+ // If the current node is to the right on the same row, or below the node that's being dragged
954
+ // then move it to the left
955
+ translate.x = -(this.width + this.marginOffset.x);
956
+ if (edgeOffset.left + translate.x < this.containerBoundingRect.left + offset.width && prevNode) {
957
+ // If it moves passed the left bounds, then animate it to the last position of the previous row.
958
+ // We just use the offset of the previous node to calculate where to move, because that node's original position
959
+ // is exactly where we want to go
960
+ translate.x = prevNode.edgeOffset.left - edgeOffset.left;
961
+ translate.y = prevNode.edgeOffset.top - edgeOffset.top;
962
+ }
963
+ this.newIndex = index;
964
+ }
965
+ }
966
+ else {
967
+ if (index > this.index && sortingOffset.left + scrollDifference.left + offset.width >= edgeOffset.left) {
968
+ translate.x = -(this.width + this.marginOffset.x);
969
+ this.newIndex = index;
970
+ }
971
+ else if (index < this.index &&
972
+ sortingOffset.left + scrollDifference.left <= edgeOffset.left + offset.width) {
973
+ translate.x = this.width + this.marginOffset.x;
974
+ if (this.newIndex == null) {
975
+ this.newIndex = index;
976
+ }
977
+ }
978
+ }
979
+ }
980
+ else if (this._axis.y) {
981
+ if (index > this.index && sortingOffset.top + scrollDifference.top + offset.height >= edgeOffset.top) {
982
+ translate.y = -(this.height + this.marginOffset.y);
983
+ this.newIndex = index;
984
+ }
985
+ else if (index < this.index &&
986
+ sortingOffset.top + scrollDifference.top <= edgeOffset.top + offset.height) {
987
+ translate.y = this.height + this.marginOffset.y;
988
+ if (this.newIndex == null) {
989
+ this.newIndex = index;
990
+ }
991
+ }
992
+ }
993
+ node.style['transform'] = `translate3d(${translate.x}px,${translate.y}px,0)`;
994
+ }
995
+ if (this.newIndex == null) {
996
+ this.newIndex = this.index;
997
+ }
998
+ },
999
+ autoscroll() {
1000
+ const translate = this.translate;
1001
+ const direction = {
1002
+ x: 0,
1003
+ y: 0,
1004
+ };
1005
+ const speed = {
1006
+ x: 1,
1007
+ y: 1,
1008
+ };
1009
+ const acceleration = {
1010
+ x: 10,
1011
+ y: 10,
1012
+ };
1013
+ if (translate.y >= this.maxTranslate.y - this.height / 2) {
1014
+ direction.y = 1; // Scroll Down
1015
+ speed.y = acceleration.y * Math.abs((this.maxTranslate.y - this.height / 2 - translate.y) / this.height);
1016
+ }
1017
+ else if (translate.x >= this.maxTranslate.x - this.width / 2) {
1018
+ direction.x = 1; // Scroll Right
1019
+ speed.x = acceleration.x * Math.abs((this.maxTranslate.x - this.width / 2 - translate.x) / this.width);
1020
+ }
1021
+ else if (translate.y <= this.minTranslate.y + this.height / 2) {
1022
+ direction.y = -1; // Scroll Up
1023
+ speed.y = acceleration.y * Math.abs((translate.y - this.height / 2 - this.minTranslate.y) / this.height);
1024
+ }
1025
+ else if (translate.x <= this.minTranslate.x + this.width / 2) {
1026
+ direction.x = -1; // Scroll Left
1027
+ speed.x = acceleration.x * Math.abs((translate.x - this.width / 2 - this.minTranslate.x) / this.width);
1028
+ }
1029
+ if (this.autoscrollInterval) {
1030
+ clearInterval(this.autoscrollInterval);
1031
+ this.autoscrollInterval = null;
1032
+ }
1033
+ if (direction.x !== 0 || direction.y !== 0) {
1034
+ this.autoscrollInterval = window.setInterval(() => {
1035
+ const offset = {
1036
+ left: 1 * speed.x * direction.x,
1037
+ top: 1 * speed.y * direction.y,
1038
+ };
1039
+ if (this.useWindowAsScrollContainer) {
1040
+ this._window.scrollBy(offset.left, offset.top);
1041
+ }
1042
+ else {
1043
+ this.scrollContainer.scrollTop += offset.top;
1044
+ this.scrollContainer.scrollLeft += offset.left;
1045
+ }
1046
+ this.translate.x += offset.left;
1047
+ this.translate.y += offset.top;
1048
+ this.animateNodes();
1049
+ }, 5);
1050
+ }
1051
+ },
1052
+ },
1053
+ });
1054
+
1055
+ // Export Sortable Element Handle Directive
1056
+ const HandleDirective = {
1057
+ beforeMount(el) {
1058
+ el.sortableHandle = true;
1059
+ },
1060
+ };
1061
+
1062
+ const SlickItem = defineComponent({
1063
+ name: 'SlickItem',
1064
+ mixins: [ElementMixin],
1065
+ props: {
1066
+ tag: {
1067
+ type: String,
1068
+ default: 'div',
1069
+ },
1070
+ },
1071
+ render() {
1072
+ var _a, _b;
1073
+ return h(this.tag, (_b = (_a = this.$slots).default) === null || _b === void 0 ? void 0 : _b.call(_a));
1074
+ },
1075
+ });
1076
+
1077
+ const SlickList = defineComponent({
1078
+ name: 'SlickList',
1079
+ mixins: [ContainerMixin],
1080
+ props: {
1081
+ tag: {
1082
+ type: String,
1083
+ default: 'div',
1084
+ },
1085
+ itemKey: {
1086
+ type: [String, Function],
1087
+ default: 'id',
1088
+ },
1089
+ },
1090
+ render() {
1091
+ var _a, _b;
1092
+ if (this.$slots.item) {
1093
+ return h(this.tag, this.list.map((item, index) => {
1094
+ let key;
1095
+ if (item == null) {
1096
+ return;
1097
+ }
1098
+ else if (typeof this.itemKey === 'function') {
1099
+ key = this.itemKey(item);
1100
+ }
1101
+ else if (typeof item === 'object' &&
1102
+ hasOwnProperty(item, this.itemKey) &&
1103
+ typeof item[this.itemKey] == 'string') {
1104
+ key = item[this.itemKey];
1105
+ }
1106
+ else if (typeof item === 'string') {
1107
+ key = item;
1108
+ }
1109
+ else {
1110
+ throw new Error('Cannot find key for item, use the item-key prop and pass a function or string');
1111
+ }
1112
+ return h(SlickItem, {
1113
+ key,
1114
+ index,
1115
+ }, {
1116
+ default: () => { var _a, _b; return (_b = (_a = this.$slots).item) === null || _b === void 0 ? void 0 : _b.call(_a, { item, index }); },
1117
+ });
1118
+ }));
1119
+ }
1120
+ return h(this.tag, (_b = (_a = this.$slots).default) === null || _b === void 0 ? void 0 : _b.call(_a));
1121
+ },
1122
+ });
1123
+
1124
+ const DragHandle = defineComponent({
1125
+ props: {
1126
+ tag: {
1127
+ type: String,
1128
+ default: 'span',
1129
+ },
1130
+ },
1131
+ mounted() {
1132
+ this.$el.sortableHandle = true;
1133
+ },
1134
+ render() {
1135
+ var _a, _b;
1136
+ return h(this.tag, (_b = (_a = this.$slots).default) === null || _b === void 0 ? void 0 : _b.call(_a));
1137
+ },
1138
+ });
1139
+
1140
+ let containerIDCounter = 1;
1141
+ /**
1142
+ * Always allow when dest === source
1143
+ * Defer to 'dest.accept()' if it is a function
1144
+ * Allow any group in the accept lists
1145
+ * Deny any group in the block list
1146
+ * Allow the same group by default, this can be overridden with the block prop
1147
+ */
1148
+ function canAcceptElement(dest, source, payload) {
1149
+ if (source.id === dest.id)
1150
+ return true;
1151
+ if (dest.block && dest.block.includes(source.group))
1152
+ return false;
1153
+ if (typeof dest.accept === 'function') {
1154
+ return dest.accept({ dest, source, payload });
1155
+ }
1156
+ if (typeof dest.accept === 'boolean') {
1157
+ return dest.accept;
1158
+ }
1159
+ if (dest.accept && dest.accept.includes(source.group))
1160
+ return true;
1161
+ if (dest.group === source.group)
1162
+ return true;
1163
+ return false;
1164
+ }
1165
+ function findClosestDest({ x, y }, refs, currentDest) {
1166
+ // Quickly check if we are within the bounds of the current destination
1167
+ if (isPointWithinRect({ x, y }, currentDest.container.getBoundingClientRect())) {
1168
+ return currentDest;
1169
+ }
1170
+ let closest = null;
1171
+ let minDistance = Infinity;
1172
+ for (let i = 0; i < refs.length; i++) {
1173
+ const ref = refs[i];
1174
+ const rect = ref.container.getBoundingClientRect();
1175
+ const isWithin = isPointWithinRect({ x, y }, rect);
1176
+ if (isWithin) {
1177
+ // If we are within another destination, stop here
1178
+ return ref;
1179
+ }
1180
+ const center = getRectCenter(rect);
1181
+ const distance = getDistance(x, y, center.x, center.y);
1182
+ if (distance < minDistance) {
1183
+ closest = ref;
1184
+ minDistance = distance;
1185
+ }
1186
+ }
1187
+ // Try to guess the closest destination
1188
+ return closest;
1189
+ }
1190
+ class SlicksortHub {
1191
+ constructor() {
1192
+ this.helper = null;
1193
+ this.ghost = null;
1194
+ this.refs = [];
1195
+ this.source = null;
1196
+ this.dest = null;
1197
+ }
1198
+ getId() {
1199
+ return '' + containerIDCounter++;
1200
+ }
1201
+ isSource({ id }) {
1202
+ var _a;
1203
+ return ((_a = this.source) === null || _a === void 0 ? void 0 : _a.id) === id;
1204
+ }
1205
+ getSource() {
1206
+ return this.source;
1207
+ }
1208
+ isDest({ id }) {
1209
+ var _a;
1210
+ return ((_a = this.dest) === null || _a === void 0 ? void 0 : _a.id) === id;
1211
+ }
1212
+ getDest() {
1213
+ return this.dest;
1214
+ }
1215
+ addContainer(ref) {
1216
+ this.refs.push(ref);
1217
+ }
1218
+ removeContainer(ref) {
1219
+ this.refs = this.refs.filter((c) => c.id !== ref.id);
1220
+ }
1221
+ sortStart(ref) {
1222
+ this.source = ref;
1223
+ this.dest = ref;
1224
+ }
1225
+ handleSortMove(e, payload) {
1226
+ var _a, _b, _c, _d;
1227
+ const dest = this.dest;
1228
+ const source = this.source;
1229
+ if (!dest || !source)
1230
+ return;
1231
+ const refs = this.refs;
1232
+ const pointer = getPointerOffset(e, 'client');
1233
+ const newDest = findClosestDest(pointer, refs, dest) || dest;
1234
+ if (dest.id !== newDest.id && canAcceptElement(newDest, source, payload)) {
1235
+ this.dest = newDest;
1236
+ dest.handleDragOut();
1237
+ newDest.handleDragIn(e, this.ghost, this.helper);
1238
+ }
1239
+ if (dest.id !== ((_a = this.source) === null || _a === void 0 ? void 0 : _a.id)) {
1240
+ (_b = this.dest) === null || _b === void 0 ? void 0 : _b.updatePosition(e);
1241
+ (_c = this.dest) === null || _c === void 0 ? void 0 : _c.animateNodes();
1242
+ (_d = this.dest) === null || _d === void 0 ? void 0 : _d.autoscroll();
1243
+ }
1244
+ }
1245
+ handleSortEnd() {
1246
+ var _a, _b, _c, _d;
1247
+ if (((_a = this.source) === null || _a === void 0 ? void 0 : _a.id) === ((_b = this.dest) === null || _b === void 0 ? void 0 : _b.id))
1248
+ return;
1249
+ const payload = (_c = this.source) === null || _c === void 0 ? void 0 : _c.handleDropOut();
1250
+ (_d = this.dest) === null || _d === void 0 ? void 0 : _d.handleDropIn(payload);
1251
+ this.reset();
1252
+ }
1253
+ reset() {
1254
+ this.source = null;
1255
+ this.dest = null;
1256
+ this.helper = null;
1257
+ this.ghost = null;
1258
+ }
1259
+ cancel() {
1260
+ var _a;
1261
+ (_a = this.dest) === null || _a === void 0 ? void 0 : _a.handleDragEnd();
1262
+ this.reset();
1263
+ }
1264
+ }
1265
+
1266
+ const plugin = {
1267
+ install(app) {
1268
+ app.directive('drag-handle', HandleDirective);
1269
+ app.provide('SlicksortHub', new SlicksortHub());
1270
+ },
1271
+ };
1272
+
1273
+ export { ContainerMixin, DragHandle, ElementMixin, HandleDirective, SlickItem, SlickList, arrayMove, plugin };