@lucasols/dnd-kit-sortable 0.1.3 → 0.2.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 (38) hide show
  1. package/dist/index.d.ts +137 -9
  2. package/dist/index.js +520 -7
  3. package/dist/index.js.map +1 -0
  4. package/package.json +21 -17
  5. package/dist/components/SortableContext.d.ts +0 -26
  6. package/dist/components/index.d.ts +0 -2
  7. package/dist/dnd-kit-sortable.cjs.development.js +0 -801
  8. package/dist/dnd-kit-sortable.cjs.development.js.map +0 -1
  9. package/dist/dnd-kit-sortable.cjs.production.min.js +0 -2
  10. package/dist/dnd-kit-sortable.cjs.production.min.js.map +0 -1
  11. package/dist/dnd-kit-sortable.esm.js +0 -783
  12. package/dist/dnd-kit-sortable.esm.js.map +0 -1
  13. package/dist/hooks/defaults.d.ts +0 -9
  14. package/dist/hooks/index.d.ts +0 -4
  15. package/dist/hooks/types.d.ts +0 -24
  16. package/dist/hooks/useSortable.d.ts +0 -36
  17. package/dist/hooks/utilities/index.d.ts +0 -1
  18. package/dist/hooks/utilities/useDerivedTransform.d.ts +0 -11
  19. package/dist/sensors/index.d.ts +0 -1
  20. package/dist/sensors/keyboard/index.d.ts +0 -1
  21. package/dist/sensors/keyboard/sortableKeyboardCoordinates.d.ts +0 -2
  22. package/dist/strategies/horizontalListSorting.d.ts +0 -2
  23. package/dist/strategies/index.d.ts +0 -4
  24. package/dist/strategies/rectSorting.d.ts +0 -2
  25. package/dist/strategies/rectSwapping.d.ts +0 -2
  26. package/dist/strategies/verticalListSorting.d.ts +0 -2
  27. package/dist/types/data.d.ts +0 -8
  28. package/dist/types/disabled.d.ts +0 -4
  29. package/dist/types/index.d.ts +0 -4
  30. package/dist/types/strategies.d.ts +0 -9
  31. package/dist/types/type-guard.d.ts +0 -7
  32. package/dist/utilities/arrayMove.d.ts +0 -4
  33. package/dist/utilities/arraySwap.d.ts +0 -4
  34. package/dist/utilities/getSortedRects.d.ts +0 -2
  35. package/dist/utilities/index.d.ts +0 -6
  36. package/dist/utilities/isValidIndex.d.ts +0 -1
  37. package/dist/utilities/itemsEqual.d.ts +0 -2
  38. package/dist/utilities/normalizeDisabled.d.ts +0 -2
@@ -1,801 +0,0 @@
1
- 'use strict';
2
-
3
- Object.defineProperty(exports, '__esModule', { value: true });
4
-
5
- function _interopDefault (ex) { return (ex && (typeof ex === 'object') && 'default' in ex) ? ex['default'] : ex; }
6
-
7
- var React = require('react');
8
- var React__default = _interopDefault(React);
9
- var dndKitCore = require('@lucasols/dnd-kit-core');
10
- var dndKitUtilities = require('@lucasols/dnd-kit-utilities');
11
-
12
- /**
13
- * Move an array item to a different position. Returns a new array with the item moved to the new position.
14
- */
15
- function arrayMove(array, from, to) {
16
- const newArray = array.slice();
17
- newArray.splice(to < 0 ? newArray.length + to : to, 0, newArray.splice(from, 1)[0]);
18
- return newArray;
19
- }
20
-
21
- /**
22
- * Swap an array item to a different position. Returns a new array with the item swapped to the new position.
23
- */
24
- function arraySwap(array, from, to) {
25
- const newArray = array.slice();
26
- newArray[from] = array[to];
27
- newArray[to] = array[from];
28
- return newArray;
29
- }
30
-
31
- function getSortedRects(items, rects) {
32
- return items.reduce((accumulator, id, index) => {
33
- const rect = rects.get(id);
34
-
35
- if (rect) {
36
- accumulator[index] = rect;
37
- }
38
-
39
- return accumulator;
40
- }, Array(items.length));
41
- }
42
-
43
- function isValidIndex(index) {
44
- return index !== null && index >= 0;
45
- }
46
-
47
- function itemsEqual(a, b) {
48
- if (a === b) {
49
- return true;
50
- }
51
-
52
- if (a.length !== b.length) {
53
- return false;
54
- }
55
-
56
- for (let i = 0; i < a.length; i++) {
57
- if (a[i] !== b[i]) {
58
- return false;
59
- }
60
- }
61
-
62
- return true;
63
- }
64
-
65
- function normalizeDisabled(disabled) {
66
- if (typeof disabled === 'boolean') {
67
- return {
68
- draggable: disabled,
69
- droppable: disabled
70
- };
71
- }
72
-
73
- return disabled;
74
- }
75
-
76
- // To-do: We should be calculating scale transformation
77
- const defaultScale = {
78
- scaleX: 1,
79
- scaleY: 1
80
- };
81
- const horizontalListSortingStrategy = _ref => {
82
- var _rects$activeIndex;
83
-
84
- let {
85
- rects,
86
- activeNodeRect: fallbackActiveRect,
87
- activeIndex,
88
- overIndex,
89
- index
90
- } = _ref;
91
- const activeNodeRect = (_rects$activeIndex = rects[activeIndex]) != null ? _rects$activeIndex : fallbackActiveRect;
92
-
93
- if (!activeNodeRect) {
94
- return null;
95
- }
96
-
97
- const itemGap = getItemGap(rects, index, activeIndex);
98
-
99
- if (index === activeIndex) {
100
- const newIndexRect = rects[overIndex];
101
-
102
- if (!newIndexRect) {
103
- return null;
104
- }
105
-
106
- return {
107
- x: activeIndex < overIndex ? newIndexRect.left + newIndexRect.width - (activeNodeRect.left + activeNodeRect.width) : newIndexRect.left - activeNodeRect.left,
108
- y: 0,
109
- ...defaultScale
110
- };
111
- }
112
-
113
- if (index > activeIndex && index <= overIndex) {
114
- return {
115
- x: -activeNodeRect.width - itemGap,
116
- y: 0,
117
- ...defaultScale
118
- };
119
- }
120
-
121
- if (index < activeIndex && index >= overIndex) {
122
- return {
123
- x: activeNodeRect.width + itemGap,
124
- y: 0,
125
- ...defaultScale
126
- };
127
- }
128
-
129
- return {
130
- x: 0,
131
- y: 0,
132
- ...defaultScale
133
- };
134
- };
135
-
136
- function getItemGap(rects, index, activeIndex) {
137
- const currentRect = rects[index];
138
- const previousRect = rects[index - 1];
139
- const nextRect = rects[index + 1];
140
-
141
- if (!currentRect || !previousRect && !nextRect) {
142
- return 0;
143
- }
144
-
145
- if (activeIndex < index) {
146
- return previousRect ? currentRect.left - (previousRect.left + previousRect.width) : nextRect.left - (currentRect.left + currentRect.width);
147
- }
148
-
149
- return nextRect ? nextRect.left - (currentRect.left + currentRect.width) : currentRect.left - (previousRect.left + previousRect.width);
150
- }
151
-
152
- const rectSortingStrategy = _ref => {
153
- let {
154
- rects,
155
- activeIndex,
156
- overIndex,
157
- index
158
- } = _ref;
159
- const newRects = arrayMove(rects, overIndex, activeIndex);
160
- const oldRect = rects[index];
161
- const newRect = newRects[index];
162
-
163
- if (!newRect || !oldRect) {
164
- return null;
165
- }
166
-
167
- return {
168
- x: newRect.left - oldRect.left,
169
- y: newRect.top - oldRect.top,
170
- scaleX: newRect.width / oldRect.width,
171
- scaleY: newRect.height / oldRect.height
172
- };
173
- };
174
-
175
- const rectSwappingStrategy = _ref => {
176
- let {
177
- activeIndex,
178
- index,
179
- rects,
180
- overIndex
181
- } = _ref;
182
- let oldRect;
183
- let newRect;
184
-
185
- if (index === activeIndex) {
186
- oldRect = rects[index];
187
- newRect = rects[overIndex];
188
- }
189
-
190
- if (index === overIndex) {
191
- oldRect = rects[index];
192
- newRect = rects[activeIndex];
193
- }
194
-
195
- if (!newRect || !oldRect) {
196
- return null;
197
- }
198
-
199
- return {
200
- x: newRect.left - oldRect.left,
201
- y: newRect.top - oldRect.top,
202
- scaleX: newRect.width / oldRect.width,
203
- scaleY: newRect.height / oldRect.height
204
- };
205
- };
206
-
207
- // To-do: We should be calculating scale transformation
208
- const defaultScale$1 = {
209
- scaleX: 1,
210
- scaleY: 1
211
- };
212
- const verticalListSortingStrategy = _ref => {
213
- var _rects$activeIndex;
214
-
215
- let {
216
- activeIndex,
217
- activeNodeRect: fallbackActiveRect,
218
- index,
219
- rects,
220
- overIndex
221
- } = _ref;
222
- const activeNodeRect = (_rects$activeIndex = rects[activeIndex]) != null ? _rects$activeIndex : fallbackActiveRect;
223
-
224
- if (!activeNodeRect) {
225
- return null;
226
- }
227
-
228
- if (index === activeIndex) {
229
- const overIndexRect = rects[overIndex];
230
-
231
- if (!overIndexRect) {
232
- return null;
233
- }
234
-
235
- return {
236
- x: 0,
237
- y: activeIndex < overIndex ? overIndexRect.top + overIndexRect.height - (activeNodeRect.top + activeNodeRect.height) : overIndexRect.top - activeNodeRect.top,
238
- ...defaultScale$1
239
- };
240
- }
241
-
242
- const itemGap = getItemGap$1(rects, index, activeIndex);
243
-
244
- if (index > activeIndex && index <= overIndex) {
245
- return {
246
- x: 0,
247
- y: -activeNodeRect.height - itemGap,
248
- ...defaultScale$1
249
- };
250
- }
251
-
252
- if (index < activeIndex && index >= overIndex) {
253
- return {
254
- x: 0,
255
- y: activeNodeRect.height + itemGap,
256
- ...defaultScale$1
257
- };
258
- }
259
-
260
- return {
261
- x: 0,
262
- y: 0,
263
- ...defaultScale$1
264
- };
265
- };
266
-
267
- function getItemGap$1(clientRects, index, activeIndex) {
268
- const currentRect = clientRects[index];
269
- const previousRect = clientRects[index - 1];
270
- const nextRect = clientRects[index + 1];
271
-
272
- if (!currentRect) {
273
- return 0;
274
- }
275
-
276
- if (activeIndex < index) {
277
- return previousRect ? currentRect.top - (previousRect.top + previousRect.height) : nextRect ? nextRect.top - (currentRect.top + currentRect.height) : 0;
278
- }
279
-
280
- return nextRect ? nextRect.top - (currentRect.top + currentRect.height) : previousRect ? currentRect.top - (previousRect.top + previousRect.height) : 0;
281
- }
282
-
283
- const ID_PREFIX = 'Sortable';
284
- const Context = /*#__PURE__*/React__default.createContext({
285
- activeIndex: -1,
286
- containerId: ID_PREFIX,
287
- disableTransforms: false,
288
- items: [],
289
- overIndex: -1,
290
- useDragOverlay: false,
291
- sortedRects: [],
292
- strategy: rectSortingStrategy,
293
- disabled: {
294
- draggable: false,
295
- droppable: false
296
- }
297
- });
298
- function SortableContext(_ref) {
299
- let {
300
- children,
301
- id,
302
- items: userDefinedItems,
303
- strategy = rectSortingStrategy,
304
- disabled: disabledProp = false
305
- } = _ref;
306
- const {
307
- active,
308
- dragOverlay,
309
- droppableRects,
310
- over,
311
- measureDroppableContainers
312
- } = dndKitCore.useDndContext();
313
- const containerId = dndKitUtilities.useUniqueId(ID_PREFIX, id);
314
- const useDragOverlay = Boolean(dragOverlay.rect !== null);
315
- const items = React.useMemo(() => userDefinedItems.map(item => typeof item === 'object' && 'id' in item ? item.id : item), [userDefinedItems]);
316
- const isDragging = active != null;
317
- const activeIndex = active ? items.indexOf(active.id) : -1;
318
- const overIndex = over ? items.indexOf(over.id) : -1;
319
- const previousItemsRef = React.useRef(items);
320
- const itemsHaveChanged = !itemsEqual(items, previousItemsRef.current);
321
- const disableTransforms = overIndex !== -1 && activeIndex === -1 || itemsHaveChanged;
322
- const disabled = normalizeDisabled(disabledProp);
323
- dndKitUtilities.useIsomorphicLayoutEffect(() => {
324
- if (itemsHaveChanged && isDragging) {
325
- measureDroppableContainers(items);
326
- }
327
- }, [itemsHaveChanged, items, isDragging, measureDroppableContainers]);
328
- React.useEffect(() => {
329
- previousItemsRef.current = items;
330
- }, [items]);
331
- const contextValue = React.useMemo(() => ({
332
- activeIndex,
333
- containerId,
334
- disabled,
335
- disableTransforms,
336
- items,
337
- overIndex,
338
- useDragOverlay,
339
- sortedRects: getSortedRects(items, droppableRects),
340
- strategy
341
- }), // eslint-disable-next-line react-hooks/exhaustive-deps
342
- [activeIndex, containerId, disabled.draggable, disabled.droppable, disableTransforms, items, overIndex, droppableRects, useDragOverlay, strategy]);
343
- return React__default.createElement(Context.Provider, {
344
- value: contextValue
345
- }, children);
346
- }
347
-
348
- const defaultNewIndexGetter = _ref => {
349
- let {
350
- id,
351
- items,
352
- activeIndex,
353
- overIndex
354
- } = _ref;
355
- return arrayMove(items, activeIndex, overIndex).indexOf(id);
356
- };
357
- const defaultAnimateLayoutChanges = _ref2 => {
358
- let {
359
- containerId,
360
- isSorting,
361
- wasDragging,
362
- index,
363
- items,
364
- newIndex,
365
- previousItems,
366
- previousContainerId,
367
- transition
368
- } = _ref2;
369
-
370
- if (!transition || !wasDragging) {
371
- return false;
372
- }
373
-
374
- if (previousItems !== items && index === newIndex) {
375
- return false;
376
- }
377
-
378
- if (isSorting) {
379
- return true;
380
- }
381
-
382
- return newIndex !== index && containerId === previousContainerId;
383
- };
384
- const defaultTransition = {
385
- duration: 200,
386
- easing: 'ease'
387
- };
388
- const transitionProperty = 'transform';
389
- const disabledTransition = /*#__PURE__*/dndKitUtilities.CSS.Transition.toString({
390
- property: transitionProperty,
391
- duration: 0,
392
- easing: 'linear'
393
- });
394
- const defaultAttributes = {
395
- roleDescription: 'sortable'
396
- };
397
-
398
- /*
399
- * When the index of an item changes while sorting,
400
- * we need to temporarily disable the transforms
401
- */
402
-
403
- function useDerivedTransform(_ref) {
404
- let {
405
- disabled,
406
- index,
407
- node,
408
- rect
409
- } = _ref;
410
- const [derivedTransform, setDerivedtransform] = React.useState(null);
411
- const previousIndex = React.useRef(index);
412
- dndKitUtilities.useIsomorphicLayoutEffect(() => {
413
- if (!disabled && index !== previousIndex.current && node.current) {
414
- const initial = rect.current;
415
-
416
- if (initial) {
417
- const current = dndKitCore.getClientRect(node.current, {
418
- ignoreTransform: true
419
- });
420
- const delta = {
421
- x: initial.left - current.left,
422
- y: initial.top - current.top,
423
- scaleX: initial.width / current.width,
424
- scaleY: initial.height / current.height
425
- };
426
-
427
- if (delta.x || delta.y) {
428
- setDerivedtransform(delta);
429
- }
430
- }
431
- }
432
-
433
- if (index !== previousIndex.current) {
434
- previousIndex.current = index;
435
- }
436
- }, [disabled, index, node, rect]);
437
- React.useEffect(() => {
438
- if (derivedTransform) {
439
- setDerivedtransform(null);
440
- }
441
- }, [derivedTransform]);
442
- return derivedTransform;
443
- }
444
-
445
- function useSortable(_ref) {
446
- let {
447
- animateLayoutChanges = defaultAnimateLayoutChanges,
448
- attributes: userDefinedAttributes,
449
- disabled: localDisabled,
450
- data: customData,
451
- getNewIndex = defaultNewIndexGetter,
452
- id,
453
- strategy: localStrategy,
454
- resizeObserverConfig,
455
- transition = defaultTransition
456
- } = _ref;
457
- const {
458
- items,
459
- containerId,
460
- activeIndex,
461
- disabled: globalDisabled,
462
- disableTransforms,
463
- sortedRects,
464
- overIndex,
465
- useDragOverlay,
466
- strategy: globalStrategy
467
- } = React.useContext(Context);
468
- const disabled = normalizeLocalDisabled(localDisabled, globalDisabled);
469
- const index = items.indexOf(id);
470
- const data = React.useMemo(() => ({
471
- sortable: {
472
- containerId,
473
- index,
474
- items
475
- },
476
- ...customData
477
- }), [containerId, customData, index, items]);
478
- const itemsAfterCurrentSortable = React.useMemo(() => items.slice(items.indexOf(id)), [items, id]);
479
- const {
480
- rect,
481
- node,
482
- isOver,
483
- setNodeRef: setDroppableNodeRef
484
- } = dndKitCore.useDroppable({
485
- id,
486
- data,
487
- disabled: disabled.droppable,
488
- resizeObserverConfig: {
489
- updateMeasurementsFor: itemsAfterCurrentSortable,
490
- ...resizeObserverConfig
491
- }
492
- });
493
- const {
494
- active,
495
- activatorEvent,
496
- activeNodeRect,
497
- attributes,
498
- setNodeRef: setDraggableNodeRef,
499
- listeners,
500
- isDragging,
501
- over,
502
- setActivatorNodeRef,
503
- transform
504
- } = dndKitCore.useDraggable({
505
- id,
506
- data,
507
- attributes: { ...defaultAttributes,
508
- ...userDefinedAttributes
509
- },
510
- disabled: disabled.draggable
511
- });
512
- const setNodeRef = dndKitUtilities.useCombinedRefs(setDroppableNodeRef, setDraggableNodeRef);
513
- const isSorting = Boolean(active);
514
- const displaceItem = isSorting && !disableTransforms && isValidIndex(activeIndex) && isValidIndex(overIndex);
515
- const shouldDisplaceDragSource = !useDragOverlay && isDragging;
516
- const dragSourceDisplacement = shouldDisplaceDragSource && displaceItem ? transform : null;
517
- const strategy = localStrategy != null ? localStrategy : globalStrategy;
518
- const finalTransform = displaceItem ? dragSourceDisplacement != null ? dragSourceDisplacement : strategy({
519
- rects: sortedRects,
520
- activeNodeRect,
521
- activeIndex,
522
- overIndex,
523
- index
524
- }) : null;
525
- const newIndex = isValidIndex(activeIndex) && isValidIndex(overIndex) ? getNewIndex({
526
- id,
527
- items,
528
- activeIndex,
529
- overIndex
530
- }) : index;
531
- const activeId = active == null ? void 0 : active.id;
532
- const previous = React.useRef({
533
- activeId,
534
- items,
535
- newIndex,
536
- containerId
537
- });
538
- const itemsHaveChanged = items !== previous.current.items;
539
- const shouldAnimateLayoutChanges = animateLayoutChanges({
540
- active,
541
- containerId,
542
- isDragging,
543
- isSorting,
544
- id,
545
- index,
546
- items,
547
- newIndex: previous.current.newIndex,
548
- previousItems: previous.current.items,
549
- previousContainerId: previous.current.containerId,
550
- transition,
551
- wasDragging: previous.current.activeId != null
552
- });
553
- const derivedTransform = useDerivedTransform({
554
- disabled: !shouldAnimateLayoutChanges,
555
- index,
556
- node,
557
- rect
558
- });
559
- React.useEffect(() => {
560
- if (isSorting && previous.current.newIndex !== newIndex) {
561
- previous.current.newIndex = newIndex;
562
- }
563
-
564
- if (containerId !== previous.current.containerId) {
565
- previous.current.containerId = containerId;
566
- }
567
-
568
- if (items !== previous.current.items) {
569
- previous.current.items = items;
570
- }
571
- }, [isSorting, newIndex, containerId, items]);
572
- React.useEffect(() => {
573
- if (activeId === previous.current.activeId) {
574
- return;
575
- }
576
-
577
- if (activeId && !previous.current.activeId) {
578
- previous.current.activeId = activeId;
579
- return;
580
- }
581
-
582
- const timeoutId = setTimeout(() => {
583
- previous.current.activeId = activeId;
584
- }, 50);
585
- return () => clearTimeout(timeoutId);
586
- }, [activeId]);
587
- return {
588
- active,
589
- activeIndex,
590
- attributes,
591
- data,
592
- rect,
593
- index,
594
- newIndex,
595
- items,
596
- isOver,
597
- isSorting,
598
- isDragging,
599
- listeners,
600
- node,
601
- overIndex,
602
- over,
603
- setNodeRef,
604
- setActivatorNodeRef,
605
- setDroppableNodeRef,
606
- setDraggableNodeRef,
607
- transform: derivedTransform != null ? derivedTransform : finalTransform,
608
- transition: getTransition()
609
- };
610
-
611
- function getTransition() {
612
- if ( // Temporarily disable transitions for a single frame to set up derived transforms
613
- derivedTransform || // Or to prevent items jumping to back to their "new" position when items change
614
- itemsHaveChanged && previous.current.newIndex === index) {
615
- return disabledTransition;
616
- }
617
-
618
- if (shouldDisplaceDragSource && !dndKitUtilities.isKeyboardEvent(activatorEvent) || !transition) {
619
- return undefined;
620
- }
621
-
622
- if (isSorting || shouldAnimateLayoutChanges) {
623
- return dndKitUtilities.CSS.Transition.toString({ ...transition,
624
- property: transitionProperty
625
- });
626
- }
627
-
628
- return undefined;
629
- }
630
- }
631
-
632
- function normalizeLocalDisabled(localDisabled, globalDisabled) {
633
- var _localDisabled$dragga, _localDisabled$droppa;
634
-
635
- if (typeof localDisabled === 'boolean') {
636
- return {
637
- draggable: localDisabled,
638
- // Backwards compatibility
639
- droppable: false
640
- };
641
- }
642
-
643
- return {
644
- draggable: (_localDisabled$dragga = localDisabled == null ? void 0 : localDisabled.draggable) != null ? _localDisabled$dragga : globalDisabled.draggable,
645
- droppable: (_localDisabled$droppa = localDisabled == null ? void 0 : localDisabled.droppable) != null ? _localDisabled$droppa : globalDisabled.droppable
646
- };
647
- }
648
-
649
- function hasSortableData(entry) {
650
- if (!entry) {
651
- return false;
652
- }
653
-
654
- const data = entry.data.current;
655
-
656
- if (data && 'sortable' in data && typeof data.sortable === 'object' && 'containerId' in data.sortable && 'items' in data.sortable && 'index' in data.sortable) {
657
- return true;
658
- }
659
-
660
- return false;
661
- }
662
-
663
- const directions = [dndKitCore.KeyboardCode.Down, dndKitCore.KeyboardCode.Right, dndKitCore.KeyboardCode.Up, dndKitCore.KeyboardCode.Left];
664
- const sortableKeyboardCoordinates = (event, _ref) => {
665
- let {
666
- context: {
667
- active,
668
- collisionRect,
669
- droppableRects,
670
- droppableContainers,
671
- over,
672
- scrollableAncestors
673
- }
674
- } = _ref;
675
-
676
- if (directions.includes(event.code)) {
677
- event.preventDefault();
678
-
679
- if (!active || !collisionRect) {
680
- return;
681
- }
682
-
683
- const filteredContainers = [];
684
- droppableContainers.getEnabled().forEach(entry => {
685
- if (!entry || entry != null && entry.disabled) {
686
- return;
687
- }
688
-
689
- const rect = droppableRects.get(entry.id);
690
-
691
- if (!rect) {
692
- return;
693
- }
694
-
695
- switch (event.code) {
696
- case dndKitCore.KeyboardCode.Down:
697
- if (collisionRect.top < rect.top) {
698
- filteredContainers.push(entry);
699
- }
700
-
701
- break;
702
-
703
- case dndKitCore.KeyboardCode.Up:
704
- if (collisionRect.top > rect.top) {
705
- filteredContainers.push(entry);
706
- }
707
-
708
- break;
709
-
710
- case dndKitCore.KeyboardCode.Left:
711
- if (collisionRect.left > rect.left) {
712
- filteredContainers.push(entry);
713
- }
714
-
715
- break;
716
-
717
- case dndKitCore.KeyboardCode.Right:
718
- if (collisionRect.left < rect.left) {
719
- filteredContainers.push(entry);
720
- }
721
-
722
- break;
723
- }
724
- });
725
- const collisions = dndKitCore.closestCorners({
726
- active,
727
- collisionRect: collisionRect,
728
- droppableRects,
729
- droppableContainers: filteredContainers,
730
- pointerCoordinates: null
731
- });
732
- let closestId = dndKitCore.getFirstCollision(collisions, 'id');
733
-
734
- if (closestId === (over == null ? void 0 : over.id) && collisions.length > 1) {
735
- closestId = collisions[1].id;
736
- }
737
-
738
- if (closestId != null) {
739
- const activeDroppable = droppableContainers.get(active.id);
740
- const newDroppable = droppableContainers.get(closestId);
741
- const newRect = newDroppable ? droppableRects.get(newDroppable.id) : null;
742
- const newNode = newDroppable == null ? void 0 : newDroppable.node.current;
743
-
744
- if (newNode && newRect && activeDroppable && newDroppable) {
745
- const newScrollAncestors = dndKitCore.getScrollableAncestors(newNode);
746
- const hasDifferentScrollAncestors = newScrollAncestors.some((element, index) => scrollableAncestors[index] !== element);
747
- const hasSameContainer = isSameContainer(activeDroppable, newDroppable);
748
- const isAfterActive = isAfter(activeDroppable, newDroppable);
749
- const offset = hasDifferentScrollAncestors || !hasSameContainer ? {
750
- x: 0,
751
- y: 0
752
- } : {
753
- x: isAfterActive ? collisionRect.width - newRect.width : 0,
754
- y: isAfterActive ? collisionRect.height - newRect.height : 0
755
- };
756
- const rectCoordinates = {
757
- x: newRect.left,
758
- y: newRect.top
759
- };
760
- const newCoordinates = offset.x && offset.y ? rectCoordinates : dndKitUtilities.subtract(rectCoordinates, offset);
761
- return newCoordinates;
762
- }
763
- }
764
- }
765
-
766
- return undefined;
767
- };
768
-
769
- function isSameContainer(a, b) {
770
- if (!hasSortableData(a) || !hasSortableData(b)) {
771
- return false;
772
- }
773
-
774
- return a.data.current.sortable.containerId === b.data.current.sortable.containerId;
775
- }
776
-
777
- function isAfter(a, b) {
778
- if (!hasSortableData(a) || !hasSortableData(b)) {
779
- return false;
780
- }
781
-
782
- if (!isSameContainer(a, b)) {
783
- return false;
784
- }
785
-
786
- return a.data.current.sortable.index < b.data.current.sortable.index;
787
- }
788
-
789
- exports.SortableContext = SortableContext;
790
- exports.arrayMove = arrayMove;
791
- exports.arraySwap = arraySwap;
792
- exports.defaultAnimateLayoutChanges = defaultAnimateLayoutChanges;
793
- exports.defaultNewIndexGetter = defaultNewIndexGetter;
794
- exports.hasSortableData = hasSortableData;
795
- exports.horizontalListSortingStrategy = horizontalListSortingStrategy;
796
- exports.rectSortingStrategy = rectSortingStrategy;
797
- exports.rectSwappingStrategy = rectSwappingStrategy;
798
- exports.sortableKeyboardCoordinates = sortableKeyboardCoordinates;
799
- exports.useSortable = useSortable;
800
- exports.verticalListSortingStrategy = verticalListSortingStrategy;
801
- //# sourceMappingURL=dnd-kit-sortable.cjs.development.js.map