@lynx-js/lynx-ui-sortable 3.139.0 → 3.140.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.
- package/CHANGELOG.md +14 -0
- package/dist/Sortable.d.ts.map +1 -1
- package/dist/Sortable.jsx +366 -92
- package/dist/Sortable.jsx.map +1 -1
- package/dist/SortableContext.d.ts +16 -6
- package/dist/SortableContext.d.ts.map +1 -1
- package/dist/SortableContext.jsx +7 -3
- package/dist/SortableContext.jsx.map +1 -1
- package/dist/commitSortableOrder.d.ts +4 -0
- package/dist/commitSortableOrder.d.ts.map +1 -0
- package/dist/commitSortableOrder.jsx +15 -0
- package/dist/commitSortableOrder.jsx.map +1 -0
- package/dist/useSortable.d.ts +2 -1
- package/dist/useSortable.d.ts.map +1 -1
- package/dist/useSortable.jsx +64 -31
- package/dist/useSortable.jsx.map +1 -1
- package/package.json +2 -2
- package/src/Sortable.tsx +513 -118
- package/src/SortableContext.ts +24 -6
- package/src/commitSortableOrder.ts +31 -0
- package/src/useSortable.tsx +66 -32
package/dist/useSortable.jsx
CHANGED
|
@@ -1,11 +1,12 @@
|
|
|
1
|
-
import { runOnBackground, useCallback, useMainThreadRef
|
|
2
|
-
import { mtsLog } from "@lynx-js/lynx-ui-common";
|
|
1
|
+
import { runOnBackground, useCallback, useMainThreadRef } from "@lynx-js/react";
|
|
2
|
+
import { mtsLog, useLatest } from "@lynx-js/lynx-ui-common";
|
|
3
3
|
function useSortable(useSortableOptions) {
|
|
4
|
-
const { data, sizeMap, itemMTSRefMap, dirtyKeysRef, disabledKeysRef, onDragEnd, onDragStart, debugLog = false } = useSortableOptions;
|
|
5
|
-
const
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
4
|
+
const { data, orderRef, sizeMap, itemMTSRefMap, dirtyKeysRef, disabledKeysRef, onDragEnd, onDragStart, debugLog = false } = useSortableOptions;
|
|
5
|
+
const latest = useLatest({
|
|
6
|
+
data,
|
|
7
|
+
onDragEnd,
|
|
8
|
+
onDragStart
|
|
9
|
+
});
|
|
9
10
|
const swapConfirmedPercentage = useMainThreadRef(0.5);
|
|
10
11
|
const touchStartPoint = useMainThreadRef({
|
|
11
12
|
x: 0,
|
|
@@ -27,14 +28,14 @@ function useSortable(useSortableOptions) {
|
|
|
27
28
|
itemMTSRefMap,
|
|
28
29
|
dirtyKeysRef
|
|
29
30
|
]);
|
|
30
|
-
const handleDragStartJS = useCallback(()=>{
|
|
31
|
-
onDragStart?.();
|
|
31
|
+
const handleDragStartJS = useCallback((sortingKey)=>{
|
|
32
|
+
latest.current.onDragStart?.(sortingKey);
|
|
32
33
|
}, [
|
|
33
|
-
|
|
34
|
+
latest
|
|
34
35
|
]);
|
|
35
36
|
const handleDragStart = useCallback((pagePoint, sortingKey, event)=>{
|
|
36
37
|
'main thread';
|
|
37
|
-
runOnBackground(handleDragStartJS)();
|
|
38
|
+
runOnBackground(handleDragStartJS)(sortingKey);
|
|
38
39
|
touchStartPoint.current = pagePoint;
|
|
39
40
|
changedKey.current.push(sortingKey);
|
|
40
41
|
changeItemZIndex(10000, sortingKey);
|
|
@@ -43,10 +44,12 @@ function useSortable(useSortableOptions) {
|
|
|
43
44
|
handleDragStartJS,
|
|
44
45
|
touchStartPoint,
|
|
45
46
|
changedKey,
|
|
46
|
-
changeItemZIndex
|
|
47
|
+
changeItemZIndex,
|
|
48
|
+
debugLog
|
|
47
49
|
]);
|
|
48
50
|
const swappingIndexAndDistance = useCallback((movingDistance, sortingKey)=>{
|
|
49
51
|
'main thread';
|
|
52
|
+
const keyArray = orderRef.current;
|
|
50
53
|
const index = keyArray.indexOf(sortingKey);
|
|
51
54
|
if (0 === keyArray.length || index < 0 || index >= keyArray.length) {
|
|
52
55
|
mtsLog(debugLog, '[swappingIndexAndDistance] invalid index', index);
|
|
@@ -111,9 +114,10 @@ function useSortable(useSortableOptions) {
|
|
|
111
114
|
currentIndex += direction;
|
|
112
115
|
}
|
|
113
116
|
}, [
|
|
114
|
-
|
|
117
|
+
orderRef,
|
|
115
118
|
sizeMap,
|
|
116
|
-
disabledKeysRef
|
|
119
|
+
disabledKeysRef,
|
|
120
|
+
debugLog
|
|
117
121
|
]);
|
|
118
122
|
const setTransform = useCallback((key, translate)=>{
|
|
119
123
|
'main thread';
|
|
@@ -124,7 +128,7 @@ function useSortable(useSortableOptions) {
|
|
|
124
128
|
itemMTSRefMap,
|
|
125
129
|
dirtyKeysRef
|
|
126
130
|
]);
|
|
127
|
-
const clampPreviousItem = (movingDistance, sortingKey)=>{
|
|
131
|
+
const clampPreviousItem = useCallback((movingDistance, sortingKey)=>{
|
|
128
132
|
'main thread';
|
|
129
133
|
mtsLog(debugLog, `clamp ${lastSwappingKey.current} to grid`);
|
|
130
134
|
const draggingItemSize = sizeMap.current[sortingKey];
|
|
@@ -132,15 +136,28 @@ function useSortable(useSortableOptions) {
|
|
|
132
136
|
const lastSwappingItemKey = lastSwappingKey.current;
|
|
133
137
|
Math.abs(swappingItemTranslation.current) > draggingItemSize * swapConfirmedPercentage.current ? setTransform(lastSwappingItemKey, (movingDistance < 0 ? 1 : -1) * (draggingItemSize + lastCrossedDisabledSize.current)) : setTransform(lastSwappingItemKey, 0);
|
|
134
138
|
}
|
|
135
|
-
}
|
|
136
|
-
|
|
139
|
+
}, [
|
|
140
|
+
debugLog,
|
|
141
|
+
lastCrossedDisabledSize,
|
|
142
|
+
lastSwappingKey,
|
|
143
|
+
setTransform,
|
|
144
|
+
sizeMap,
|
|
145
|
+
swapConfirmedPercentage,
|
|
146
|
+
swappingItemTranslation
|
|
147
|
+
]);
|
|
148
|
+
const updateLastSwappingItem = useCallback((movingDistance, sortingKey, swappingKey)=>{
|
|
137
149
|
'main thread';
|
|
138
150
|
mtsLog(debugLog, `interact item from ${lastSwappingKey.current} to ${swappingKey}`);
|
|
139
151
|
clampPreviousItem(movingDistance, sortingKey);
|
|
140
152
|
lastSwappingKey.current = swappingKey;
|
|
141
|
-
}
|
|
142
|
-
|
|
153
|
+
}, [
|
|
154
|
+
clampPreviousItem,
|
|
155
|
+
debugLog,
|
|
156
|
+
lastSwappingKey
|
|
157
|
+
]);
|
|
158
|
+
const updateConfirmedInteractedID = useCallback((unconsumedDistance, sortingKey)=>{
|
|
143
159
|
'main thread';
|
|
160
|
+
const keyArray = orderRef.current;
|
|
144
161
|
mtsLog(debugLog, `swapping with ${lastSwappingKey.current} at ${unconsumedDistance}`);
|
|
145
162
|
const draggingItemSize = sizeMap.current[sortingKey];
|
|
146
163
|
if (Math.abs(unconsumedDistance) > draggingItemSize * swapConfirmedPercentage.current) {
|
|
@@ -159,9 +176,18 @@ function useSortable(useSortableOptions) {
|
|
|
159
176
|
mtsLog(debugLog, `Reverted swap with ${lastSwappingKey.current}. New confirmed swap is with ${lastSwappedKey.current || 'none'}.`);
|
|
160
177
|
}
|
|
161
178
|
swappingItemTranslation.current = unconsumedDistance;
|
|
162
|
-
}
|
|
179
|
+
}, [
|
|
180
|
+
debugLog,
|
|
181
|
+
orderRef,
|
|
182
|
+
lastSwappedKey,
|
|
183
|
+
lastSwappingKey,
|
|
184
|
+
sizeMap,
|
|
185
|
+
swapConfirmedPercentage,
|
|
186
|
+
swappingItemTranslation
|
|
187
|
+
]);
|
|
163
188
|
const switchHandler = useCallback((movingDistance, sortingKey)=>{
|
|
164
189
|
'main thread';
|
|
190
|
+
const keyArray = orderRef.current;
|
|
165
191
|
const { index: swappingIndex, distance: consumedDistance, crossedDisabledSize = 0 } = swappingIndexAndDistance(movingDistance, sortingKey);
|
|
166
192
|
mtsLog(debugLog, 'swappingIndexAndDistance', swappingIndex, consumedDistance, crossedDisabledSize);
|
|
167
193
|
if (swappingIndex < 0) return void clampPreviousItem(consumedDistance, sortingKey);
|
|
@@ -179,7 +205,10 @@ function useSortable(useSortableOptions) {
|
|
|
179
205
|
}, [
|
|
180
206
|
changedKey,
|
|
181
207
|
itemMTSRefMap,
|
|
182
|
-
|
|
208
|
+
orderRef,
|
|
209
|
+
debugLog,
|
|
210
|
+
sizeMap,
|
|
211
|
+
lastCrossedDisabledSize,
|
|
183
212
|
lastSwappingKey,
|
|
184
213
|
setTransform,
|
|
185
214
|
swappingIndexAndDistance,
|
|
@@ -193,10 +222,12 @@ function useSortable(useSortableOptions) {
|
|
|
193
222
|
mtsLog(debugLog, '[event drag move]', event);
|
|
194
223
|
}, [
|
|
195
224
|
switchHandler,
|
|
196
|
-
changeItemZIndex
|
|
225
|
+
changeItemZIndex,
|
|
226
|
+
debugLog
|
|
197
227
|
]);
|
|
198
228
|
const sortArray = useCallback((sortingKey)=>{
|
|
199
229
|
'main thread';
|
|
230
|
+
const keyArray = orderRef.current;
|
|
200
231
|
const draggingIndex = keyArray.indexOf(sortingKey);
|
|
201
232
|
const swappedIndex = keyArray.indexOf(lastSwappedKey.current);
|
|
202
233
|
mtsLog(debugLog, 'sortArray with lastSwappedKey ', lastSwappedKey.current);
|
|
@@ -225,9 +256,10 @@ function useSortable(useSortableOptions) {
|
|
|
225
256
|
} else result.push(disabledIndices[i]);
|
|
226
257
|
return result;
|
|
227
258
|
}, [
|
|
228
|
-
|
|
259
|
+
orderRef,
|
|
229
260
|
lastSwappedKey,
|
|
230
|
-
disabledKeysRef
|
|
261
|
+
disabledKeysRef,
|
|
262
|
+
debugLog
|
|
231
263
|
]);
|
|
232
264
|
const resetSwapTrackingRefs = useCallback(()=>{
|
|
233
265
|
'main thread';
|
|
@@ -259,19 +291,19 @@ function useSortable(useSortableOptions) {
|
|
|
259
291
|
resetSwapTrackingRefs
|
|
260
292
|
]);
|
|
261
293
|
const rootDragEnd = useCallback((sortedKey)=>{
|
|
262
|
-
const
|
|
263
|
-
|
|
294
|
+
const { data, onDragEnd } = latest.current;
|
|
295
|
+
const keyToItemMap = new Map(data.map((item)=>[
|
|
296
|
+
item.getSortingKey(),
|
|
264
297
|
item
|
|
265
298
|
]));
|
|
266
299
|
const sortedData = sortedKey.map((key)=>keyToItemMap.get(key)).filter((item)=>!!item);
|
|
267
300
|
onDragEnd?.(sortedData);
|
|
268
301
|
}, [
|
|
269
|
-
|
|
270
|
-
keyArray,
|
|
271
|
-
onDragEnd
|
|
302
|
+
latest
|
|
272
303
|
]);
|
|
273
304
|
const handleDragEnd = useCallback((sortingKey, event)=>{
|
|
274
305
|
'main thread';
|
|
306
|
+
const keyArray = orderRef.current;
|
|
275
307
|
mtsLog(debugLog, '[event drag end]', event);
|
|
276
308
|
const sortedKey = sortArray(sortingKey);
|
|
277
309
|
let orderChanged = sortedKey.length !== keyArray.length;
|
|
@@ -290,11 +322,12 @@ function useSortable(useSortableOptions) {
|
|
|
290
322
|
}
|
|
291
323
|
return orderChanged;
|
|
292
324
|
}, [
|
|
293
|
-
|
|
325
|
+
orderRef,
|
|
294
326
|
resetStatus,
|
|
295
327
|
resetSwapTrackingRefs,
|
|
296
328
|
rootDragEnd,
|
|
297
|
-
sortArray
|
|
329
|
+
sortArray,
|
|
330
|
+
debugLog
|
|
298
331
|
]);
|
|
299
332
|
return {
|
|
300
333
|
handleDragStart,
|
package/dist/useSortable.jsx.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useSortable.jsx","sources":["../src/useSortable.tsx"],"sourcesContent":["// Copyright 2026 The Lynx Authors. All rights reserved.\n// Licensed under the Apache License Version 2.0 that can be found in the\n// LICENSE file in the root directory of this source tree.\n\nimport {\n runOnBackground,\n useCallback,\n useMainThreadRef,\n useMemo,\n} from '@lynx-js/react'\nimport type { MainThreadRef, RefObject } from '@lynx-js/react'\n\nimport { mtsLog } from '@lynx-js/lynx-ui-common'\nimport type { Point } from '@lynx-js/lynx-ui-common'\nimport type { DraggableRef } from '@lynx-js/lynx-ui-draggable'\nimport type { MainThread } from '@lynx-js/types'\n\nimport type { SortableData } from './types'\n\ninterface SortableOptionsType<T> {\n data: SortableData<T>[] // sorting key array\n sizeMap: MainThreadRef<Record<string, number>> // sorting key -> size\n itemRefMap: RefObject<Record<string, DraggableRef | null>>\n itemMTSRefMap: MainThreadRef<Record<string, DraggableRef | null>> // sortingKey -> element Ref\n dirtyKeysRef: MainThreadRef<Record<string, boolean>>\n disabledKeysRef: MainThreadRef<Record<string, boolean>>\n onDragEnd?: (sortedKeyArray: SortableData<T>[]) => void\n onDragStart?: () => void\n debugLog?: boolean\n}\n\nexport function useSortable<T>(\n useSortableOptions: SortableOptionsType<T>,\n) {\n const {\n data,\n sizeMap,\n itemMTSRefMap,\n dirtyKeysRef,\n disabledKeysRef,\n onDragEnd,\n onDragStart,\n debugLog = false,\n } = useSortableOptions\n\n const safeData = Array.isArray(data) ? data : []\n const keyArray = useMemo(() => safeData.map(item => item.getSortingKey()), [\n safeData,\n ])\n const swapConfirmedPercentage = useMainThreadRef<number>(0.5)\n const touchStartPoint = useMainThreadRef<Point>({ x: 0, y: 0 })\n const lastSwappingKey = useMainThreadRef<string>('')\n const swappingItemTranslation = useMainThreadRef<number>(0)\n const lastCrossedDisabledSize = useMainThreadRef<number>(0)\n const changedKey = useMainThreadRef<string[]>([]) // Store all the moved item. Remember to reset them\n const lastSwappedKey = useMainThreadRef<string>('') // Store the last swapped item. Use it to do the sorting.\n\n const changeItemZIndex = useCallback((zIndex: number, sortingKey: string) => {\n 'main thread'\n const item = itemMTSRefMap.current[sortingKey]\n\n item?.MTSSetOtherStyles({\n 'z-index': `${zIndex}`,\n })\n dirtyKeysRef.current[sortingKey] = true\n }, [itemMTSRefMap, dirtyKeysRef])\n\n const handleDragStartJS = useCallback(() => {\n onDragStart?.()\n }, [onDragStart])\n\n const handleDragStart = useCallback(\n (\n pagePoint: Point,\n sortingKey: string,\n event: MainThread.MouseEvent | MainThread.TouchEvent,\n ) => {\n 'main thread'\n runOnBackground(handleDragStartJS)()\n touchStartPoint.current = pagePoint\n changedKey.current.push(sortingKey)\n changeItemZIndex(10000, sortingKey)\n mtsLog(debugLog, '[event drag start]', event)\n },\n [handleDragStartJS, touchStartPoint, changedKey, changeItemZIndex],\n )\n\n const swappingIndexAndDistance: (\n movingDistance: number,\n sortingKey: string,\n ) => { index: number, distance: number, crossedDisabledSize: number } =\n useCallback(\n (movingDistance, sortingKey) => {\n 'main thread'\n const index = keyArray.indexOf(sortingKey)\n if (keyArray.length === 0 || index < 0 || index >= keyArray.length) {\n mtsLog(debugLog, '[swappingIndexAndDistance] invalid index', index)\n return { index: -1, distance: 0, crossedDisabledSize: 0 }\n }\n\n const absDistance = Math.abs(movingDistance)\n const direction = movingDistance > 0 ? 1 : -1\n let currentIndex = index + direction\n let accumulatedDistance = 0\n // The total size of the contiguous disabled (locked) items immediately\n // preceding the current candidate movable, i.e. the disabled gap\n // between the previous movable neighbor (or the drag start) and the\n // movable we are about to evaluate. Every time we pass a movable\n // without picking it as the swap target, this gap resets to 0, so\n // each potential swap target only sees the locked items strictly\n // between it and its previous movable neighbor — never a cumulative\n // total from the drag origin.\n let disabledGap = 0\n while (true) {\n if (currentIndex < 0 || currentIndex >= keyArray.length) {\n return {\n index: -1,\n distance: (movingDistance > 0 ? 1 : -1)\n * (absDistance - accumulatedDistance),\n crossedDisabledSize: disabledGap,\n }\n }\n const currentKey = keyArray[currentIndex]\n // Disabled (locked) items are never picked as a swap candidate and\n // never displaced. The dragged item is allowed to cross over them by\n // skipping past while still consuming their height, so the dragged\n // item's physical displacement keeps in sync with `accumulatedDistance`\n // and the disabled item's absolute position is preserved.\n if (disabledKeysRef.current[currentKey]) {\n const disabledSize = sizeMap.current[currentKey]\n if (typeof disabledSize !== 'number') {\n mtsLog(\n debugLog,\n `[swappingIndexAndDistance] disabled item size not found for key ${currentKey}, stopping at index ${currentIndex}.`,\n )\n return {\n index: -1,\n distance: (movingDistance > 0 ? 1 : -1) * accumulatedDistance,\n crossedDisabledSize: disabledGap,\n }\n }\n // The dragged item is still physically over this disabled item,\n // so no swap target should be produced yet.\n if (accumulatedDistance + disabledSize >= absDistance) {\n mtsLog(\n debugLog,\n `[swappingIndexAndDistance] still over disabled item ${currentKey} at index ${currentIndex}.`,\n )\n return {\n index: -1,\n distance: (movingDistance > 0 ? 1 : -1) * accumulatedDistance,\n crossedDisabledSize: disabledGap,\n }\n }\n mtsLog(\n debugLog,\n `[swappingIndexAndDistance] cross disabled item ${currentKey} at index ${currentIndex}.`,\n )\n accumulatedDistance += disabledSize\n disabledGap += disabledSize\n currentIndex += direction\n continue\n }\n const size = sizeMap.current[currentKey]\n if (typeof size !== 'number') {\n mtsLog(\n debugLog,\n `[swappingIndexAndDistance] item size not found for key ${sortingKey}, stopping at index ${currentIndex}.`,\n )\n return {\n index: -1,\n distance: (movingDistance > 0 ? 1 : -1) * accumulatedDistance,\n crossedDisabledSize: disabledGap,\n }\n }\n accumulatedDistance += size\n\n if (accumulatedDistance >= absDistance) {\n return {\n index: currentIndex,\n // This distance is the remained dragging distance needs to be consumed by current interacting item.\n // E.g.: the total delta is 458 and all item is all 100px tall. Then the first 400 will be consumed the previous clamped items. And the 58 is current interacting item.\n distance: (movingDistance > 0 ? 1 : -1)\n * (accumulatedDistance - size),\n // Only the disabled items strictly between the previous movable\n // neighbor and this swap target. Locked items further back have\n // already been accounted for when their own following movable\n // became (and was clamped as) a swap target.\n crossedDisabledSize: disabledGap,\n }\n }\n // We just passed this movable without choosing it as the swap target,\n // so the disabled gap \"in front of\" the next candidate restarts here.\n disabledGap = 0\n currentIndex += direction\n }\n },\n [keyArray, sizeMap, disabledKeysRef],\n )\n\n const setTransform = useCallback(\n (key: string, translate: number) => {\n 'main thread'\n\n const item = key ? itemMTSRefMap.current[key] : null\n item?.MTSSetTransform(0, translate)\n if (key) {\n dirtyKeysRef.current[key] = true\n }\n },\n [itemMTSRefMap, dirtyKeysRef],\n )\n\n // Clamp the previous interacting item to the grid\n const clampPreviousItem = (movingDistance: number, sortingKey: string) => {\n 'main thread'\n mtsLog(\n debugLog,\n `clamp ${lastSwappingKey.current} to grid`,\n )\n const draggingItemSize = sizeMap.current[sortingKey]\n if (lastSwappingKey.current !== null) {\n const lastSwappingItemKey = lastSwappingKey.current\n if (\n Math.abs(swappingItemTranslation.current)\n > draggingItemSize * swapConfirmedPercentage.current\n ) {\n // The previous swap target's \"swapped\" position must include the\n // height of any disabled items the dragged item had crossed over to\n // reach it; otherwise it would visually overlap with the (still\n // in-place) disabled items after we leave it behind.\n setTransform(\n lastSwappingItemKey,\n (movingDistance < 0 ? 1 : -1)\n * (draggingItemSize + lastCrossedDisabledSize.current),\n )\n } else {\n setTransform(lastSwappingItemKey, 0)\n }\n }\n }\n\n const updateLastSwappingItem = (\n movingDistance: number,\n sortingKey: string,\n swappingKey: string,\n ) => {\n 'main thread'\n mtsLog(\n debugLog,\n `interact item from ${lastSwappingKey.current} to ${swappingKey}`,\n )\n clampPreviousItem(movingDistance, sortingKey)\n lastSwappingKey.current = swappingKey\n }\n\n // Update the confirmed interacting ID if the condition is met\n const updateConfirmedInteractedID = (\n unconsumedDistance: number,\n sortingKey: string,\n ) => {\n 'main thread'\n mtsLog(\n debugLog,\n `swapping with ${lastSwappingKey.current} at ${unconsumedDistance}`,\n )\n const draggingItemSize = sizeMap.current[sortingKey]\n if (\n Math.abs(unconsumedDistance)\n > draggingItemSize * swapConfirmedPercentage.current\n ) {\n lastSwappedKey.current = lastSwappingKey.current\n mtsLog(\n debugLog,\n `confirmed swapping with ${lastSwappedKey.current} at cross ${unconsumedDistance}`,\n )\n } else if (lastSwappedKey.current === lastSwappingKey.current) {\n // Handle case when dragging back over a previously swapped item\n const swappingIndex = keyArray.indexOf(lastSwappingKey.current)\n const draggedItemIndex = keyArray.indexOf(sortingKey)\n\n // Get new swap candidate index based on drag direction reversal\n // Drag down → reverse up: `swappingIndex - 1`\n // Drag up → reverse down: `swappingIndex + 1`\n const indexModifier = swappingIndex > draggedItemIndex ? -1 : 1\n const newSwappedKeyIndex = swappingIndex + indexModifier\n\n // The logic should prevent out-of-bounds access, but as a safeguard:\n if (newSwappedKeyIndex >= 0 && newSwappedKeyIndex < keyArray.length) {\n const newSwappedKey = keyArray[newSwappedKeyIndex]\n\n // If new candidate's index matches dragged item's index, item returned to original position; no swap confirmed.\n if (newSwappedKeyIndex === draggedItemIndex) {\n lastSwappedKey.current = ''\n } else {\n lastSwappedKey.current = newSwappedKey\n }\n } else {\n // Item is returning to original position when reverting swap at list start/end.\n lastSwappedKey.current = ''\n }\n\n mtsLog(\n debugLog,\n `Reverted swap with ${lastSwappingKey.current}. New confirmed swap is with ${\n lastSwappedKey.current || 'none'\n }.`,\n )\n }\n swappingItemTranslation.current = unconsumedDistance\n }\n\n const switchHandler = useCallback(\n (movingDistance: number, sortingKey: string) => {\n 'main thread'\n const {\n index: swappingIndex,\n distance: consumedDistance,\n crossedDisabledSize = 0,\n } = swappingIndexAndDistance(movingDistance, sortingKey)\n mtsLog(\n debugLog,\n 'swappingIndexAndDistance',\n swappingIndex,\n consumedDistance,\n crossedDisabledSize,\n )\n if (swappingIndex < 0) {\n clampPreviousItem(consumedDistance, sortingKey)\n return\n }\n const swappingKey = keyArray[swappingIndex]\n\n if (swappingKey !== lastSwappingKey.current) {\n updateLastSwappingItem(movingDistance, sortingKey, swappingKey)\n changedKey.current.push(swappingKey)\n }\n\n const unconsumedDistance = movingDistance - consumedDistance\n updateConfirmedInteractedID(unconsumedDistance, sortingKey)\n // When the dragged item has crossed over disabled items, those items do\n // not translate. To avoid the swap target jumping, scale its translate\n // proportionally as the dragged item progresses over it: while the\n // dragged item moves `swappingItemSize` over the swap target, the swap\n // target translates `swappingItemSize + crossedDisabledSize`, ending\n // exactly at the dragged item's original slot without any jump.\n const swappingItemSize = sizeMap.current[swappingKey] ?? 0\n const speedMultiplier = swappingItemSize > 0\n ? (swappingItemSize + crossedDisabledSize) / swappingItemSize\n : 1\n setTransform(swappingKey, -unconsumedDistance * speedMultiplier)\n lastCrossedDisabledSize.current = crossedDisabledSize\n },\n [\n changedKey,\n itemMTSRefMap,\n keyArray,\n lastSwappingKey,\n setTransform,\n swappingIndexAndDistance,\n updateConfirmedInteractedID,\n updateLastSwappingItem,\n ],\n )\n\n const handleDragMove = useCallback(\n (\n delta: Point,\n sortingKey: string,\n event: MainThread.MouseEvent | MainThread.TouchEvent,\n ) => {\n 'main thread'\n switchHandler(delta.y, sortingKey)\n changeItemZIndex(10000, sortingKey)\n mtsLog(debugLog, '[event drag move]', event)\n },\n [switchHandler, changeItemZIndex],\n )\n\n const sortArray = useCallback((sortingKey: string) => {\n 'main thread'\n const draggingIndex = keyArray.indexOf(sortingKey)\n const swappedIndex = keyArray.indexOf(lastSwappedKey.current)\n\n mtsLog(debugLog, 'sortArray with lastSwappedKey ', lastSwappedKey.current)\n\n if (\n draggingIndex === -1 || swappedIndex === -1\n || draggingIndex === swappedIndex\n ) {\n return [...keyArray]\n }\n\n // Disabled items must keep their absolute positions in the result. We\n // splice only the movable (non-disabled) sequence and then reinsert\n // disabled items at their original indices.\n const disabledIndices: Record<number, string> = {}\n const movableKeys: string[] = []\n for (let i = 0; i < keyArray.length; i++) {\n const k = keyArray[i]\n if (disabledKeysRef.current[k]) {\n disabledIndices[i] = k\n } else {\n movableKeys.push(k)\n }\n }\n const movableDraggingIdx = movableKeys.indexOf(sortingKey)\n const movableSwappedIdx = movableKeys.indexOf(lastSwappedKey.current)\n if (movableDraggingIdx === -1 || movableSwappedIdx === -1) {\n return [...keyArray]\n }\n const [draggedItem] = movableKeys.splice(movableDraggingIdx, 1)\n movableKeys.splice(movableSwappedIdx, 0, draggedItem)\n const result: string[] = []\n let cursor = 0\n for (let i = 0; i < keyArray.length; i++) {\n if (disabledIndices[i] === undefined) {\n result.push(movableKeys[cursor])\n cursor++\n } else {\n result.push(disabledIndices[i])\n }\n }\n return result\n }, [keyArray, lastSwappedKey, disabledKeysRef])\n\n const resetSwapTrackingRefs = useCallback(() => {\n 'main thread'\n lastSwappedKey.current = ''\n lastSwappingKey.current = ''\n swappingItemTranslation.current = 0\n lastCrossedDisabledSize.current = 0\n changedKey.current = []\n }, [\n changedKey,\n lastSwappedKey,\n lastSwappingKey,\n swappingItemTranslation,\n lastCrossedDisabledSize,\n ])\n\n const resetStatus = useCallback((draggingKey?: string) => {\n 'main thread'\n changedKey.current.map((key: string) => {\n if (key === draggingKey) {\n return\n }\n const item = itemMTSRefMap?.current?.[key]\n if (!item) {\n return\n }\n if (typeof item.MTSSetTransform === 'function') {\n item.MTSSetTransform(0, 0)\n }\n if (typeof item.MTSResetInternalTranslateValues === 'function') {\n item.MTSResetInternalTranslateValues()\n }\n })\n resetSwapTrackingRefs()\n }, [changedKey, itemMTSRefMap, resetSwapTrackingRefs])\n\n const rootDragEnd = useCallback((sortedKey: string[]) => {\n const keyToItemMap = new Map(data.map((item, index) => {\n return [keyArray[index], item]\n }))\n const sortedData = sortedKey\n .map(key => keyToItemMap.get(key))\n .filter((item): item is NonNullable<typeof item> => !!item)\n onDragEnd?.(sortedData)\n }, [data, keyArray, onDragEnd])\n\n const handleDragEnd = useCallback(\n (\n sortingKey: string,\n event: MainThread.MouseEvent | MainThread.TouchEvent,\n ): boolean => {\n 'main thread'\n mtsLog(debugLog, '[event drag end]', event)\n const sortedKey = sortArray(sortingKey)\n let orderChanged = sortedKey.length !== keyArray.length\n if (!orderChanged) {\n for (let i = 0; i < sortedKey.length; i++) {\n if (sortedKey[i] !== keyArray[i]) {\n orderChanged = true\n break\n }\n }\n }\n if (orderChanged) {\n // data will be updated by consumer -> usePreCommit will reset dirty items\n runOnBackground(rootDragEnd)(sortedKey)\n // dom transforms are reset by usePreCommit, but swap tracking refs\n // must be cleared synchronously to avoid stale state on next drag\n resetSwapTrackingRefs()\n } else {\n // no data update -> no precommit -> reset dirty items synchronously here\n resetStatus(sortingKey)\n runOnBackground(rootDragEnd)(sortedKey)\n }\n return orderChanged\n },\n [keyArray, resetStatus, resetSwapTrackingRefs, rootDragEnd, sortArray],\n )\n\n return {\n handleDragStart,\n handleDragMove,\n handleDragEnd,\n }\n}\n"],"names":["useSortable","useSortableOptions","data","sizeMap","itemMTSRefMap","dirtyKeysRef","disabledKeysRef","onDragEnd","onDragStart","debugLog","safeData","Array","keyArray","useMemo","item","swapConfirmedPercentage","useMainThreadRef","touchStartPoint","lastSwappingKey","swappingItemTranslation","lastCrossedDisabledSize","changedKey","lastSwappedKey","changeItemZIndex","useCallback","zIndex","sortingKey","handleDragStartJS","handleDragStart","pagePoint","event","runOnBackground","mtsLog","swappingIndexAndDistance","movingDistance","index","absDistance","Math","direction","currentIndex","accumulatedDistance","disabledGap","currentKey","disabledSize","size","setTransform","key","translate","clampPreviousItem","draggingItemSize","lastSwappingItemKey","updateLastSwappingItem","swappingKey","updateConfirmedInteractedID","unconsumedDistance","swappingIndex","draggedItemIndex","indexModifier","newSwappedKeyIndex","newSwappedKey","switchHandler","consumedDistance","crossedDisabledSize","swappingItemSize","speedMultiplier","handleDragMove","delta","sortArray","draggingIndex","swappedIndex","disabledIndices","movableKeys","i","k","movableDraggingIdx","movableSwappedIdx","draggedItem","result","cursor","undefined","resetSwapTrackingRefs","resetStatus","draggingKey","rootDragEnd","sortedKey","keyToItemMap","Map","sortedData","handleDragEnd","orderChanged"],"mappings":";;AA+BO,SAASA,YACdC,kBAA0C;IAE1C,MAAM,EACJC,IAAI,EACJC,OAAO,EACPC,aAAa,EACbC,YAAY,EACZC,eAAe,EACfC,SAAS,EACTC,WAAW,EACXC,WAAW,KAAK,EACjB,GAAGR;IAEJ,MAAMS,WAAWC,MAAM,OAAO,CAACT,QAAQA,OAAO,EAAE;IAChD,MAAMU,WAAWC,QAAQ,IAAMH,SAAS,GAAG,CAACI,CAAAA,OAAQA,KAAK,aAAa,KAAK;QACzEJ;KACD;IACD,MAAMK,0BAA0BC,iBAAyB;IACzD,MAAMC,kBAAkBD,iBAAwB;QAAE,GAAG;QAAG,GAAG;IAAE;IAC7D,MAAME,kBAAkBF,iBAAyB;IACjD,MAAMG,0BAA0BH,iBAAyB;IACzD,MAAMI,0BAA0BJ,iBAAyB;IACzD,MAAMK,aAAaL,iBAA2B,EAAE;IAChD,MAAMM,iBAAiBN,iBAAyB;IAEhD,MAAMO,mBAAmBC,YAAY,CAACC,QAAgBC;QACpD;QACA,MAAMZ,OAAOV,cAAc,OAAO,CAACsB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AEA;QACAE,OAAOvB,UAAU,oBAAoBqB;QACrC,MAAMsD,YAAYjB,UAAUzC;QAC5B,IAAI+D,eAAeL,UAAU,MAAM,KAAKxE,SAAS,MAAM;QACvD,IAAI,CAAC6E,cACH;YAAA,IAAK,IAAIjB,IAAI,GAAGA,IAAIY,UAAU,MAAM,EAAEZ,IACpC,IAAIY,SAAS,CAACZ,EAAE,KAAK5D,QAAQ,CAAC4D,EAAE,EAAE;gBAChCiB,eAAe;gBACf;YACF;QACF;QAEF,IAAIA,cAAc;YAEhB1D,gBAAgBoD,aAAaC;YAG7BJ;QACF,OAAO;YAELC,YAAYvD;YACZK,gBAAgBoD,aAAaC;QAC/B;QACA,OAAOK;IACT,GACA;QAAC7E;QAAUqE;QAAaD;QAAuBG;QAAahB;KAAU;IAGxE,OAAO;QACLvC;QACAqC;QACAuB;IACF;AACF"}
|
|
1
|
+
{"version":3,"file":"useSortable.jsx","sources":["../src/useSortable.tsx"],"sourcesContent":["// Copyright 2026 The Lynx Authors. All rights reserved.\n// Licensed under the Apache License Version 2.0 that can be found in the\n// LICENSE file in the root directory of this source tree.\n\nimport { runOnBackground, useCallback, useMainThreadRef } from '@lynx-js/react'\nimport type { MainThreadRef, RefObject } from '@lynx-js/react'\n\nimport { mtsLog, useLatest } from '@lynx-js/lynx-ui-common'\nimport type { Point } from '@lynx-js/lynx-ui-common'\nimport type { DraggableRef } from '@lynx-js/lynx-ui-draggable'\nimport type { MainThread } from '@lynx-js/types'\n\nimport type { SortableData } from './types'\n\ninterface SortableOptionsType<T> {\n data: SortableData<T>[] // sorting key array\n orderRef: MainThreadRef<string[]>\n sizeMap: MainThreadRef<Record<string, number>> // sorting key -> size\n itemRefMap: RefObject<Record<string, DraggableRef | null>>\n itemMTSRefMap: MainThreadRef<Record<string, DraggableRef | null>> // sortingKey -> element Ref\n dirtyKeysRef: MainThreadRef<Record<string, boolean>>\n disabledKeysRef: MainThreadRef<Record<string, boolean>>\n onDragEnd?: (sortedKeyArray: SortableData<T>[]) => void\n onDragStart?: (sortingKey: string) => void\n debugLog?: boolean\n}\n\nexport function useSortable<T>(\n useSortableOptions: SortableOptionsType<T>,\n) {\n const {\n data,\n orderRef,\n sizeMap,\n itemMTSRefMap,\n dirtyKeysRef,\n disabledKeysRef,\n onDragEnd,\n onDragStart,\n debugLog = false,\n } = useSortableOptions\n\n // Business data and callbacks stay on BTS; MTS only captures stable refs.\n const latest = useLatest({ data, onDragEnd, onDragStart })\n const swapConfirmedPercentage = useMainThreadRef<number>(0.5)\n const touchStartPoint = useMainThreadRef<Point>({ x: 0, y: 0 })\n const lastSwappingKey = useMainThreadRef<string>('')\n const swappingItemTranslation = useMainThreadRef<number>(0)\n const lastCrossedDisabledSize = useMainThreadRef<number>(0)\n const changedKey = useMainThreadRef<string[]>([]) // Store all the moved item. Remember to reset them\n const lastSwappedKey = useMainThreadRef<string>('') // Store the last swapped item. Use it to do the sorting.\n\n const changeItemZIndex = useCallback((zIndex: number, sortingKey: string) => {\n 'main thread'\n const item = itemMTSRefMap.current[sortingKey]\n\n item?.MTSSetOtherStyles({\n 'z-index': `${zIndex}`,\n })\n dirtyKeysRef.current[sortingKey] = true\n }, [itemMTSRefMap, dirtyKeysRef])\n\n const handleDragStartJS = useCallback((sortingKey: string) => {\n latest.current.onDragStart?.(sortingKey)\n }, [latest])\n\n const handleDragStart = useCallback(\n (\n pagePoint: Point,\n sortingKey: string,\n event: MainThread.MouseEvent | MainThread.TouchEvent,\n ) => {\n 'main thread'\n runOnBackground(handleDragStartJS)(sortingKey)\n touchStartPoint.current = pagePoint\n changedKey.current.push(sortingKey)\n changeItemZIndex(10000, sortingKey)\n mtsLog(debugLog, '[event drag start]', event)\n },\n [\n handleDragStartJS,\n touchStartPoint,\n changedKey,\n changeItemZIndex,\n debugLog,\n ],\n )\n\n const swappingIndexAndDistance: (\n movingDistance: number,\n sortingKey: string,\n ) => { index: number, distance: number, crossedDisabledSize: number } =\n useCallback(\n (movingDistance, sortingKey) => {\n 'main thread'\n const keyArray = orderRef.current\n const index = keyArray.indexOf(sortingKey)\n if (keyArray.length === 0 || index < 0 || index >= keyArray.length) {\n mtsLog(debugLog, '[swappingIndexAndDistance] invalid index', index)\n return { index: -1, distance: 0, crossedDisabledSize: 0 }\n }\n\n const absDistance = Math.abs(movingDistance)\n const direction = movingDistance > 0 ? 1 : -1\n let currentIndex = index + direction\n let accumulatedDistance = 0\n // The total size of the contiguous disabled (locked) items immediately\n // preceding the current candidate movable, i.e. the disabled gap\n // between the previous movable neighbor (or the drag start) and the\n // movable we are about to evaluate. Every time we pass a movable\n // without picking it as the swap target, this gap resets to 0, so\n // each potential swap target only sees the locked items strictly\n // between it and its previous movable neighbor — never a cumulative\n // total from the drag origin.\n let disabledGap = 0\n while (true) {\n if (currentIndex < 0 || currentIndex >= keyArray.length) {\n return {\n index: -1,\n distance: (movingDistance > 0 ? 1 : -1)\n * (absDistance - accumulatedDistance),\n crossedDisabledSize: disabledGap,\n }\n }\n const currentKey = keyArray[currentIndex]\n // Disabled (locked) items are never picked as a swap candidate and\n // never displaced. The dragged item is allowed to cross over them by\n // skipping past while still consuming their height, so the dragged\n // item's physical displacement keeps in sync with `accumulatedDistance`\n // and the disabled item's absolute position is preserved.\n if (disabledKeysRef.current[currentKey]) {\n const disabledSize = sizeMap.current[currentKey]\n if (typeof disabledSize !== 'number') {\n mtsLog(\n debugLog,\n `[swappingIndexAndDistance] disabled item size not found for key ${currentKey}, stopping at index ${currentIndex}.`,\n )\n return {\n index: -1,\n distance: (movingDistance > 0 ? 1 : -1) * accumulatedDistance,\n crossedDisabledSize: disabledGap,\n }\n }\n // The dragged item is still physically over this disabled item,\n // so no swap target should be produced yet.\n if (accumulatedDistance + disabledSize >= absDistance) {\n mtsLog(\n debugLog,\n `[swappingIndexAndDistance] still over disabled item ${currentKey} at index ${currentIndex}.`,\n )\n return {\n index: -1,\n distance: (movingDistance > 0 ? 1 : -1) * accumulatedDistance,\n crossedDisabledSize: disabledGap,\n }\n }\n mtsLog(\n debugLog,\n `[swappingIndexAndDistance] cross disabled item ${currentKey} at index ${currentIndex}.`,\n )\n accumulatedDistance += disabledSize\n disabledGap += disabledSize\n currentIndex += direction\n continue\n }\n const size = sizeMap.current[currentKey]\n if (typeof size !== 'number') {\n mtsLog(\n debugLog,\n `[swappingIndexAndDistance] item size not found for key ${sortingKey}, stopping at index ${currentIndex}.`,\n )\n return {\n index: -1,\n distance: (movingDistance > 0 ? 1 : -1) * accumulatedDistance,\n crossedDisabledSize: disabledGap,\n }\n }\n accumulatedDistance += size\n\n if (accumulatedDistance >= absDistance) {\n return {\n index: currentIndex,\n // This distance is the remained dragging distance needs to be consumed by current interacting item.\n // E.g.: the total delta is 458 and all item is all 100px tall. Then the first 400 will be consumed the previous clamped items. And the 58 is current interacting item.\n distance: (movingDistance > 0 ? 1 : -1)\n * (accumulatedDistance - size),\n // Only the disabled items strictly between the previous movable\n // neighbor and this swap target. Locked items further back have\n // already been accounted for when their own following movable\n // became (and was clamped as) a swap target.\n crossedDisabledSize: disabledGap,\n }\n }\n // We just passed this movable without choosing it as the swap target,\n // so the disabled gap \"in front of\" the next candidate restarts here.\n disabledGap = 0\n currentIndex += direction\n }\n },\n [orderRef, sizeMap, disabledKeysRef, debugLog],\n )\n\n const setTransform = useCallback(\n (key: string, translate: number) => {\n 'main thread'\n\n const item = key ? itemMTSRefMap.current[key] : null\n item?.MTSSetTransform(0, translate)\n if (key) {\n dirtyKeysRef.current[key] = true\n }\n },\n [itemMTSRefMap, dirtyKeysRef],\n )\n\n // Clamp the previous interacting item to the grid\n const clampPreviousItem = useCallback((\n movingDistance: number,\n sortingKey: string,\n ) => {\n 'main thread'\n mtsLog(\n debugLog,\n `clamp ${lastSwappingKey.current} to grid`,\n )\n const draggingItemSize = sizeMap.current[sortingKey]\n if (lastSwappingKey.current !== null) {\n const lastSwappingItemKey = lastSwappingKey.current\n if (\n Math.abs(swappingItemTranslation.current)\n > draggingItemSize * swapConfirmedPercentage.current\n ) {\n // The previous swap target's \"swapped\" position must include the\n // height of any disabled items the dragged item had crossed over to\n // reach it; otherwise it would visually overlap with the (still\n // in-place) disabled items after we leave it behind.\n setTransform(\n lastSwappingItemKey,\n (movingDistance < 0 ? 1 : -1)\n * (draggingItemSize + lastCrossedDisabledSize.current),\n )\n } else {\n setTransform(lastSwappingItemKey, 0)\n }\n }\n }, [\n debugLog,\n lastCrossedDisabledSize,\n lastSwappingKey,\n setTransform,\n sizeMap,\n swapConfirmedPercentage,\n swappingItemTranslation,\n ])\n\n const updateLastSwappingItem = useCallback((\n movingDistance: number,\n sortingKey: string,\n swappingKey: string,\n ) => {\n 'main thread'\n mtsLog(\n debugLog,\n `interact item from ${lastSwappingKey.current} to ${swappingKey}`,\n )\n clampPreviousItem(movingDistance, sortingKey)\n lastSwappingKey.current = swappingKey\n }, [clampPreviousItem, debugLog, lastSwappingKey])\n\n // Update the confirmed interacting ID if the condition is met\n const updateConfirmedInteractedID = useCallback((\n unconsumedDistance: number,\n sortingKey: string,\n ) => {\n 'main thread'\n const keyArray = orderRef.current\n mtsLog(\n debugLog,\n `swapping with ${lastSwappingKey.current} at ${unconsumedDistance}`,\n )\n const draggingItemSize = sizeMap.current[sortingKey]\n if (\n Math.abs(unconsumedDistance)\n > draggingItemSize * swapConfirmedPercentage.current\n ) {\n lastSwappedKey.current = lastSwappingKey.current\n mtsLog(\n debugLog,\n `confirmed swapping with ${lastSwappedKey.current} at cross ${unconsumedDistance}`,\n )\n } else if (lastSwappedKey.current === lastSwappingKey.current) {\n // Handle case when dragging back over a previously swapped item\n const swappingIndex = keyArray.indexOf(lastSwappingKey.current)\n const draggedItemIndex = keyArray.indexOf(sortingKey)\n\n // Get new swap candidate index based on drag direction reversal\n // Drag down → reverse up: `swappingIndex - 1`\n // Drag up → reverse down: `swappingIndex + 1`\n const indexModifier = swappingIndex > draggedItemIndex ? -1 : 1\n const newSwappedKeyIndex = swappingIndex + indexModifier\n\n // The logic should prevent out-of-bounds access, but as a safeguard:\n if (newSwappedKeyIndex >= 0 && newSwappedKeyIndex < keyArray.length) {\n const newSwappedKey = keyArray[newSwappedKeyIndex]\n\n // If new candidate's index matches dragged item's index, item returned to original position; no swap confirmed.\n if (newSwappedKeyIndex === draggedItemIndex) {\n lastSwappedKey.current = ''\n } else {\n lastSwappedKey.current = newSwappedKey\n }\n } else {\n // Item is returning to original position when reverting swap at list start/end.\n lastSwappedKey.current = ''\n }\n\n mtsLog(\n debugLog,\n `Reverted swap with ${lastSwappingKey.current}. New confirmed swap is with ${\n lastSwappedKey.current || 'none'\n }.`,\n )\n }\n swappingItemTranslation.current = unconsumedDistance\n }, [\n debugLog,\n orderRef,\n lastSwappedKey,\n lastSwappingKey,\n sizeMap,\n swapConfirmedPercentage,\n swappingItemTranslation,\n ])\n\n const switchHandler = useCallback(\n (movingDistance: number, sortingKey: string) => {\n 'main thread'\n const keyArray = orderRef.current\n const {\n index: swappingIndex,\n distance: consumedDistance,\n crossedDisabledSize = 0,\n } = swappingIndexAndDistance(movingDistance, sortingKey)\n mtsLog(\n debugLog,\n 'swappingIndexAndDistance',\n swappingIndex,\n consumedDistance,\n crossedDisabledSize,\n )\n if (swappingIndex < 0) {\n clampPreviousItem(consumedDistance, sortingKey)\n return\n }\n const swappingKey = keyArray[swappingIndex]\n\n if (swappingKey !== lastSwappingKey.current) {\n updateLastSwappingItem(movingDistance, sortingKey, swappingKey)\n changedKey.current.push(swappingKey)\n }\n\n const unconsumedDistance = movingDistance - consumedDistance\n updateConfirmedInteractedID(unconsumedDistance, sortingKey)\n // When the dragged item has crossed over disabled items, those items do\n // not translate. To avoid the swap target jumping, scale its translate\n // proportionally as the dragged item progresses over it: while the\n // dragged item moves `swappingItemSize` over the swap target, the swap\n // target translates `swappingItemSize + crossedDisabledSize`, ending\n // exactly at the dragged item's original slot without any jump.\n const swappingItemSize = sizeMap.current[swappingKey] ?? 0\n const speedMultiplier = swappingItemSize > 0\n ? (swappingItemSize + crossedDisabledSize) / swappingItemSize\n : 1\n setTransform(swappingKey, -unconsumedDistance * speedMultiplier)\n lastCrossedDisabledSize.current = crossedDisabledSize\n },\n [\n changedKey,\n itemMTSRefMap,\n orderRef,\n debugLog,\n sizeMap,\n lastCrossedDisabledSize,\n lastSwappingKey,\n setTransform,\n swappingIndexAndDistance,\n updateConfirmedInteractedID,\n updateLastSwappingItem,\n ],\n )\n\n const handleDragMove = useCallback(\n (\n delta: Point,\n sortingKey: string,\n event: MainThread.MouseEvent | MainThread.TouchEvent,\n ) => {\n 'main thread'\n switchHandler(delta.y, sortingKey)\n changeItemZIndex(10000, sortingKey)\n mtsLog(debugLog, '[event drag move]', event)\n },\n [switchHandler, changeItemZIndex, debugLog],\n )\n\n const sortArray = useCallback((sortingKey: string) => {\n 'main thread'\n const keyArray = orderRef.current\n const draggingIndex = keyArray.indexOf(sortingKey)\n const swappedIndex = keyArray.indexOf(lastSwappedKey.current)\n\n mtsLog(debugLog, 'sortArray with lastSwappedKey ', lastSwappedKey.current)\n\n if (\n draggingIndex === -1 || swappedIndex === -1\n || draggingIndex === swappedIndex\n ) {\n return [...keyArray]\n }\n\n // Disabled items must keep their absolute positions in the result. We\n // splice only the movable (non-disabled) sequence and then reinsert\n // disabled items at their original indices.\n const disabledIndices: Record<number, string> = {}\n const movableKeys: string[] = []\n for (let i = 0; i < keyArray.length; i++) {\n const k = keyArray[i]\n if (disabledKeysRef.current[k]) {\n disabledIndices[i] = k\n } else {\n movableKeys.push(k)\n }\n }\n const movableDraggingIdx = movableKeys.indexOf(sortingKey)\n const movableSwappedIdx = movableKeys.indexOf(lastSwappedKey.current)\n if (movableDraggingIdx === -1 || movableSwappedIdx === -1) {\n return [...keyArray]\n }\n const [draggedItem] = movableKeys.splice(movableDraggingIdx, 1)\n movableKeys.splice(movableSwappedIdx, 0, draggedItem)\n const result: string[] = []\n let cursor = 0\n for (let i = 0; i < keyArray.length; i++) {\n if (disabledIndices[i] === undefined) {\n result.push(movableKeys[cursor])\n cursor++\n } else {\n result.push(disabledIndices[i])\n }\n }\n return result\n }, [orderRef, lastSwappedKey, disabledKeysRef, debugLog])\n\n const resetSwapTrackingRefs = useCallback(() => {\n 'main thread'\n lastSwappedKey.current = ''\n lastSwappingKey.current = ''\n swappingItemTranslation.current = 0\n lastCrossedDisabledSize.current = 0\n changedKey.current = []\n }, [\n changedKey,\n lastSwappedKey,\n lastSwappingKey,\n swappingItemTranslation,\n lastCrossedDisabledSize,\n ])\n\n const resetStatus = useCallback((draggingKey?: string) => {\n 'main thread'\n changedKey.current.map((key: string) => {\n if (key === draggingKey) {\n return\n }\n const item = itemMTSRefMap?.current?.[key]\n if (!item) {\n return\n }\n if (typeof item.MTSSetTransform === 'function') {\n item.MTSSetTransform(0, 0)\n }\n if (typeof item.MTSResetInternalTranslateValues === 'function') {\n item.MTSResetInternalTranslateValues()\n }\n })\n resetSwapTrackingRefs()\n }, [changedKey, itemMTSRefMap, resetSwapTrackingRefs])\n\n const rootDragEnd = useCallback((sortedKey: string[]) => {\n const { data, onDragEnd } = latest.current\n const keyToItemMap = new Map(data.map(item => [item.getSortingKey(), item]))\n const sortedData = sortedKey\n .map(key => keyToItemMap.get(key))\n .filter((item): item is NonNullable<typeof item> => !!item)\n onDragEnd?.(sortedData)\n }, [latest])\n\n const handleDragEnd = useCallback(\n (\n sortingKey: string,\n event: MainThread.MouseEvent | MainThread.TouchEvent,\n ): boolean => {\n 'main thread'\n const keyArray = orderRef.current\n mtsLog(debugLog, '[event drag end]', event)\n const sortedKey = sortArray(sortingKey)\n let orderChanged = sortedKey.length !== keyArray.length\n if (!orderChanged) {\n for (let i = 0; i < sortedKey.length; i++) {\n if (sortedKey[i] !== keyArray[i]) {\n orderChanged = true\n break\n }\n }\n }\n if (orderChanged) {\n // data will be updated by consumer -> usePreCommit will reset dirty items\n runOnBackground(rootDragEnd)(sortedKey)\n // dom transforms are reset by usePreCommit, but swap tracking refs\n // must be cleared synchronously to avoid stale state on next drag\n resetSwapTrackingRefs()\n } else {\n // no data update -> no precommit -> reset dirty items synchronously here\n resetStatus(sortingKey)\n runOnBackground(rootDragEnd)(sortedKey)\n }\n return orderChanged\n },\n [\n orderRef,\n resetStatus,\n resetSwapTrackingRefs,\n rootDragEnd,\n sortArray,\n debugLog,\n ],\n )\n\n return {\n handleDragStart,\n handleDragMove,\n handleDragEnd,\n }\n}\n"],"names":["useSortable","useSortableOptions","data","orderRef","sizeMap","itemMTSRefMap","dirtyKeysRef","disabledKeysRef","onDragEnd","onDragStart","debugLog","latest","useLatest","swapConfirmedPercentage","useMainThreadRef","touchStartPoint","lastSwappingKey","swappingItemTranslation","lastCrossedDisabledSize","changedKey","lastSwappedKey","changeItemZIndex","useCallback","zIndex","sortingKey","item","handleDragStartJS","handleDragStart","pagePoint","event","runOnBackground","mtsLog","swappingIndexAndDistance","movingDistance","keyArray","index","absDistance","Math","direction","currentIndex","accumulatedDistance","disabledGap","currentKey","disabledSize","size","setTransform","key","translate","clampPreviousItem","draggingItemSize","lastSwappingItemKey","updateLastSwappingItem","swappingKey","updateConfirmedInteractedID","unconsumedDistance","swappingIndex","draggedItemIndex","indexModifier","newSwappedKeyIndex","newSwappedKey","switchHandler","consumedDistance","crossedDisabledSize","swappingItemSize","speedMultiplier","handleDragMove","delta","sortArray","draggingIndex","swappedIndex","disabledIndices","movableKeys","i","k","movableDraggingIdx","movableSwappedIdx","draggedItem","result","cursor","undefined","resetSwapTrackingRefs","resetStatus","draggingKey","rootDragEnd","sortedKey","keyToItemMap","Map","sortedData","handleDragEnd","orderChanged"],"mappings":";;AA2BO,SAASA,YACdC,kBAA0C;IAE1C,MAAM,EACJC,IAAI,EACJC,QAAQ,EACRC,OAAO,EACPC,aAAa,EACbC,YAAY,EACZC,eAAe,EACfC,SAAS,EACTC,WAAW,EACXC,WAAW,KAAK,EACjB,GAAGT;IAGJ,MAAMU,SAASC,UAAU;QAAEV;QAAMM;QAAWC;IAAY;IACxD,MAAMI,0BAA0BC,iBAAyB;IACzD,MAAMC,kBAAkBD,iBAAwB;QAAE,GAAG;QAAG,GAAG;I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ACF"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@lynx-js/lynx-ui-sortable",
|
|
3
|
-
"version": "3.
|
|
3
|
+
"version": "3.140.0",
|
|
4
4
|
"repository": {
|
|
5
5
|
"type": "git",
|
|
6
6
|
"url": "git+https://github.com/lynx-family/lynx-ui.git",
|
|
@@ -26,7 +26,7 @@
|
|
|
26
26
|
],
|
|
27
27
|
"dependencies": {
|
|
28
28
|
"@lynx-js/lynx-ui-common": "3.139.0",
|
|
29
|
-
"@lynx-js/lynx-ui-draggable": "3.
|
|
29
|
+
"@lynx-js/lynx-ui-draggable": "3.140.0"
|
|
30
30
|
},
|
|
31
31
|
"devDependencies": {
|
|
32
32
|
"@lynx-js/react": "0.123.1",
|