@lynx-js/lynx-ui-sortable 3.131.0 → 3.133.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/useSortable.d.ts.map +1 -1
- package/dist/useSortable.jsx +3 -2
- package/dist/useSortable.jsx.map +1 -1
- package/package.json +4 -4
- package/src/useSortable.tsx +2 -2
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,19 @@
|
|
|
1
1
|
# @lynx-js/lynx-ui-sortable
|
|
2
2
|
|
|
3
|
+
## 3.133.0
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- Updated dependencies [[`85d2e9d`](https://github.com/lynx-family/lynx-ui/commit/85d2e9d12e9aeee3256856f1be0076524ddb7d8a)]:
|
|
8
|
+
- @lynx-js/lynx-ui-common@3.133.0
|
|
9
|
+
- @lynx-js/lynx-ui-draggable@3.133.0
|
|
10
|
+
|
|
11
|
+
## 3.131.1
|
|
12
|
+
|
|
13
|
+
### Patch Changes
|
|
14
|
+
|
|
15
|
+
- Improve robustness for unstable input data. ([#134](https://github.com/lynx-family/lynx-ui/pull/134))
|
|
16
|
+
|
|
3
17
|
## 3.131.0
|
|
4
18
|
|
|
5
19
|
### Patch Changes
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useSortable.d.ts","sourceRoot":"","sources":["../src/useSortable.tsx"],"names":[],"mappings":"AAUA,OAAO,KAAK,EAAE,aAAa,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAA;AAG9D,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,yBAAyB,CAAA;AACpD,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,4BAA4B,CAAA;AAC9D,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,gBAAgB,CAAA;AAEhD,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,SAAS,CAAA;AAE3C,UAAU,mBAAmB;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AG,IAAI,CAAC,CAAC,CAAA;IACjE,SAAS,CAAC,EAAE,CAAC,cAAc,EAAE,YAAY,CAAC,OAAO,CAAC,EAAE,KAAK,IAAI,CAAA;IAC7D,WAAW,CAAC,EAAE,MAAM,IAAI,CAAA;IACxB,QAAQ,CAAC,EAAE,OAAO,CAAA;CACnB;AAED,wBAAgB,WAAW,CACzB,kBAAkB,EAAE,mBAAmB;iCAqCxB,KAAK,cACJ,MAAM,SACX,UAAU,CAAC,UAAU,GAAG,UAAU,CAAC,UAAU;4BAkN7C,KAAK,cACA,MAAM,SACX,UAAU,CAAC,UAAU,GAAG,UAAU,CAAC,UAAU;gCAuDxC,MAAM,SACX,UAAU,CAAC,UAAU,GAAG,UAAU,CAAC,UAAU;EAgBzD"}
|
package/dist/useSortable.jsx
CHANGED
|
@@ -19,7 +19,6 @@ function useSortable(useSortableOptions) {
|
|
|
19
19
|
'main thread';
|
|
20
20
|
const item = itemMTSRefMap.current[sortingKey];
|
|
21
21
|
item?.MTSSetOtherStyles({
|
|
22
|
-
transform: `translateZ(${zIndex}px)`,
|
|
23
22
|
'z-index': `${zIndex}`
|
|
24
23
|
});
|
|
25
24
|
}, [
|
|
@@ -150,9 +149,11 @@ function useSortable(useSortableOptions) {
|
|
|
150
149
|
const handleDragMove = useCallback((delta, sortingKey, event)=>{
|
|
151
150
|
'main thread';
|
|
152
151
|
switchHandler(delta.y, sortingKey);
|
|
152
|
+
changeItemZIndex(10000, sortingKey);
|
|
153
153
|
mtsLog(debugLog, '[event drag move]', event);
|
|
154
154
|
}, [
|
|
155
|
-
switchHandler
|
|
155
|
+
switchHandler,
|
|
156
|
+
changeItemZIndex
|
|
156
157
|
]);
|
|
157
158
|
const sortArray = useCallback((sortingKey)=>{
|
|
158
159
|
'main thread';
|
package/dist/useSortable.jsx.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useSortable.jsx","sources":["webpack://@lynx-js/lynx-ui-sortable/./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 {\n data: SortableData<unknown>[] // 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 onDragEnd?: (sortedKeyArray: SortableData<unknown>[]) => void\n onDragStart?: () => void\n debugLog?: boolean\n}\n\nexport function useSortable(\n useSortableOptions: SortableOptionsType,\n) {\n const {\n data,\n sizeMap,\n itemMTSRefMap,\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 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 'transform': `translateZ(${zIndex}px)`,\n 'z-index': `${zIndex}`,\n })\n }, [itemMTSRefMap])\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 } = 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 }\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 while (true) {\n if (currentIndex < 0 || currentIndex >= keyArray.length) {\n return {\n index: -1,\n distance: (movingDistance > 0 ? 1 : -1)\n * (absDistance - accumulatedDistance),\n }\n }\n const size = sizeMap.current[keyArray[currentIndex]]\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 }\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 }\n }\n currentIndex += direction\n }\n },\n [keyArray, sizeMap],\n )\n\n const setTransform = useCallback(\n (item: DraggableRef | null, translate: number) => {\n 'main thread'\n\n item?.MTSSetOtherStyles({ 'transform': `translateY(${translate}px)` })\n },\n [],\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 lastSwappingItem = lastSwappingKey.current\n ? itemMTSRefMap.current[lastSwappingKey.current]\n : null\n if (\n Math.abs(swappingItemTranslation.current)\n > draggingItemSize * swapConfirmedPercentage.current\n ) {\n setTransform(\n lastSwappingItem,\n (movingDistance < 0 ? 1 : -1) * draggingItemSize,\n )\n } else {\n setTransform(lastSwappingItem, 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 { index: swappingIndex, distance: consumedDistance } =\n swappingIndexAndDistance(movingDistance, sortingKey)\n mtsLog(\n debugLog,\n 'swappingIndexAndDistance',\n swappingIndex,\n consumedDistance,\n )\n if (swappingIndex < 0) {\n clampPreviousItem(consumedDistance, sortingKey)\n return\n }\n const swappingKey = keyArray[swappingIndex]\n const swappingItem = itemMTSRefMap.current[swappingKey]\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 setTransform(swappingItem, -unconsumedDistance)\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 mtsLog(debugLog, '[event drag move]', event)\n },\n [switchHandler],\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 const swappedKeyArray = [...keyArray]\n\n mtsLog(debugLog, 'sortArray with lastSwappedKey ', lastSwappedKey.current)\n\n if (\n draggingIndex === -1 || swappedIndex === -1\n || draggingIndex === swappedIndex\n ) {\n return swappedKeyArray\n }\n\n const [draggedItem] = swappedKeyArray.splice(draggingIndex, 1)\n swappedKeyArray.splice(swappedIndex, 0, draggedItem)\n return swappedKeyArray\n }, [keyArray, lastSwappedKey])\n\n const resetStatus = useCallback(() => {\n 'main thread'\n changedKey.current.map((key: string) => {\n const item = itemMTSRefMap?.current?.[key]\n if (item && typeof item.MTSResetInternalTranslateValues === 'function') {\n item?.MTSResetInternalTranslateValues()\n }\n })\n lastSwappedKey.current = ''\n lastSwappingKey.current = ''\n changedKey.current = []\n }, [changedKey, itemMTSRefMap, lastSwappedKey, lastSwappingKey])\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 ) => {\n 'main thread'\n mtsLog(debugLog, '[event drag end]', event)\n const sortedKey = sortArray(sortingKey)\n runOnBackground(rootDragEnd)(sortedKey)\n resetStatus()\n },\n [resetStatus, rootDragEnd, sortArray],\n )\n\n return {\n handleDragStart,\n handleDragMove,\n handleDragEnd,\n }\n}\n"],"names":["useSortable","useSortableOptions","data","sizeMap","itemMTSRefMap","onDragEnd","onDragStart","debugLog","safeData","Array","keyArray","useMemo","item","swapConfirmedPercentage","useMainThreadRef","touchStartPoint","lastSwappingKey","swappingItemTranslation","changedKey","lastSwappedKey","changeItemZIndex","useCallback","zIndex","sortingKey","handleDragStartJS","handleDragStart","pagePoint","event","runOnBackground","mtsLog","swappingIndexAndDistance","movingDistance","index","absDistance","Math","direction","currentIndex","accumulatedDistance","size","setTransform","translate","clampPreviousItem","draggingItemSize","lastSwappingItem","updateLastSwappingItem","swappingKey","updateConfirmedInteractedID","unconsumedDistance","swappingIndex","draggedItemIndex","indexModifier","newSwappedKeyIndex","newSwappedKey","switchHandler","consumedDistance","swappingItem","handleDragMove","delta","sortArray","draggingIndex","swappedIndex","swappedKeyArray","draggedItem","resetStatus","key","rootDragEnd","sortedKey","keyToItemMap","Map","sortedData","handleDragEnd"],"mappings":";;AA6BO,SAASA,YACdC,kBAAuC;IAEvC,MAAM,EACJC,IAAI,EACJC,OAAO,EACPC,aAAa,EACbC,SAAS,EACTC,WAAW,EACXC,WAAW,KAAK,EACjB,GAAGN;IAEJ,MAAMO,WAAWC,MAAM,OAAO,CAACP,QAAQA,OAAO,EAAE;IAChD,MAAMQ,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,aAAaJ,iBAA2B,EAAE;IAChD,MAAMK,iBAAiBL,iBAAyB;IAEhD,MAAMM,mBAAmBC,YAAY,CAACC,QAAgBC;QACpD;QACA,MAAMX,OAAOR,cAAc,OAAO,CAACmB,WAAW;QAE9CX,MAAM,kBAAkB;YACtB,WAAa,CAAC,WAAW,EAAEU,OAAO,GAAG,CAAC;YACtC,WAAW,GAAGA,QAAQ;QACxB;IACF,GAAG;QAAClB;KAAc;IAElB,MAAMoB,oBAAoBH,YAAY;QACpCf;IACF,GAAG;QAACA;KAAY;IAEhB,MAAMmB,kBAAkB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,CAAC,CAACpD,OAA2C,CAAC,CAACA;QACxDP,YAAYgE;IACd,GAAG;QAACnE;QAAMQ;QAAUL;KAAU;IAE9B,MAAMiE,gBAAgBjD,YACpB,CACEE,YACAI;QAEA;QACAE,OAAOtB,UAAU,oBAAoBoB;QACrC,MAAMuC,YAAYR,UAAUnC;QAC5BK,gBAAgBqC,aAAaC;QAC7BH;IACF,GACA;QAACA;QAAaE;QAAaP;KAAU;IAGvC,OAAO;QACLjC;QACA+B;QACAc;IACF;AACF"}
|
|
1
|
+
{"version":3,"file":"useSortable.jsx","sources":["webpack://@lynx-js/lynx-ui-sortable/./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 {\n data: SortableData<unknown>[] // 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 onDragEnd?: (sortedKeyArray: SortableData<unknown>[]) => void\n onDragStart?: () => void\n debugLog?: boolean\n}\n\nexport function useSortable(\n useSortableOptions: SortableOptionsType,\n) {\n const {\n data,\n sizeMap,\n itemMTSRefMap,\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 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 }, [itemMTSRefMap])\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 } = 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 }\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 while (true) {\n if (currentIndex < 0 || currentIndex >= keyArray.length) {\n return {\n index: -1,\n distance: (movingDistance > 0 ? 1 : -1)\n * (absDistance - accumulatedDistance),\n }\n }\n const size = sizeMap.current[keyArray[currentIndex]]\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 }\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 }\n }\n currentIndex += direction\n }\n },\n [keyArray, sizeMap],\n )\n\n const setTransform = useCallback(\n (item: DraggableRef | null, translate: number) => {\n 'main thread'\n\n item?.MTSSetOtherStyles({ 'transform': `translateY(${translate}px)` })\n },\n [],\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 lastSwappingItem = lastSwappingKey.current\n ? itemMTSRefMap.current[lastSwappingKey.current]\n : null\n if (\n Math.abs(swappingItemTranslation.current)\n > draggingItemSize * swapConfirmedPercentage.current\n ) {\n setTransform(\n lastSwappingItem,\n (movingDistance < 0 ? 1 : -1) * draggingItemSize,\n )\n } else {\n setTransform(lastSwappingItem, 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 { index: swappingIndex, distance: consumedDistance } =\n swappingIndexAndDistance(movingDistance, sortingKey)\n mtsLog(\n debugLog,\n 'swappingIndexAndDistance',\n swappingIndex,\n consumedDistance,\n )\n if (swappingIndex < 0) {\n clampPreviousItem(consumedDistance, sortingKey)\n return\n }\n const swappingKey = keyArray[swappingIndex]\n const swappingItem = itemMTSRefMap.current[swappingKey]\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 setTransform(swappingItem, -unconsumedDistance)\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 const swappedKeyArray = [...keyArray]\n\n mtsLog(debugLog, 'sortArray with lastSwappedKey ', lastSwappedKey.current)\n\n if (\n draggingIndex === -1 || swappedIndex === -1\n || draggingIndex === swappedIndex\n ) {\n return swappedKeyArray\n }\n\n const [draggedItem] = swappedKeyArray.splice(draggingIndex, 1)\n swappedKeyArray.splice(swappedIndex, 0, draggedItem)\n return swappedKeyArray\n }, [keyArray, lastSwappedKey])\n\n const resetStatus = useCallback(() => {\n 'main thread'\n changedKey.current.map((key: string) => {\n const item = itemMTSRefMap?.current?.[key]\n if (item && typeof item.MTSResetInternalTranslateValues === 'function') {\n item?.MTSResetInternalTranslateValues()\n }\n })\n lastSwappedKey.current = ''\n lastSwappingKey.current = ''\n changedKey.current = []\n }, [changedKey, itemMTSRefMap, lastSwappedKey, lastSwappingKey])\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 ) => {\n 'main thread'\n mtsLog(debugLog, '[event drag end]', event)\n const sortedKey = sortArray(sortingKey)\n runOnBackground(rootDragEnd)(sortedKey)\n resetStatus()\n },\n [resetStatus, rootDragEnd, sortArray],\n )\n\n return {\n handleDragStart,\n handleDragMove,\n handleDragEnd,\n }\n}\n"],"names":["useSortable","useSortableOptions","data","sizeMap","itemMTSRefMap","onDragEnd","onDragStart","debugLog","safeData","Array","keyArray","useMemo","item","swapConfirmedPercentage","useMainThreadRef","touchStartPoint","lastSwappingKey","swappingItemTranslation","changedKey","lastSwappedKey","changeItemZIndex","useCallback","zIndex","sortingKey","handleDragStartJS","handleDragStart","pagePoint","event","runOnBackground","mtsLog","swappingIndexAndDistance","movingDistance","index","absDistance","Math","direction","currentIndex","accumulatedDistance","size","setTransform","translate","clampPreviousItem","draggingItemSize","lastSwappingItem","updateLastSwappingItem","swappingKey","updateConfirmedInteractedID","unconsumedDistance","swappingIndex","draggedItemIndex","indexModifier","newSwappedKeyIndex","newSwappedKey","switchHandler","consumedDistance","swappingItem","handleDragMove","delta","sortArray","draggingIndex","swappedIndex","swappedKeyArray","draggedItem","resetStatus","key","rootDragEnd","sortedKey","keyToItemMap","Map","sortedData","handleDragEnd"],"mappings":";;AA6BO,SAASA,YACdC,kBAAuC;IAEvC,MAAM,EACJC,IAAI,EACJC,OAAO,EACPC,aAAa,EACbC,SAAS,EACTC,WAAW,EACXC,WAAW,KAAK,EACjB,GAAGN;IAEJ,MAAMO,WAAWC,MAAM,OAAO,CAACP,QAAQA,OAAO,EAAE;IAChD,MAAMQ,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,iBA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EACrDA,MAAM;QAEV;QACAO,eAAe,OAAO,GAAG;QACzBH,gBAAgB,OAAO,GAAG;QAC1BE,WAAW,OAAO,GAAG,EAAE;IACzB,GAAG;QAACA;QAAYd;QAAee;QAAgBH;KAAgB;IAE/D,MAAMiD,cAAc5C,YAAY,CAAC6C;QAC/B,MAAMC,eAAe,IAAIC,IAAIlE,KAAK,GAAG,CAAC,CAACU,MAAMoB,QACpC;gBAACtB,QAAQ,CAACsB,MAAM;gBAAEpB;aAAK;QAEhC,MAAMyD,aAAaH,UAChB,GAAG,CAACF,CAAAA,MAAOG,aAAa,GAAG,CAACH,MAC5B,MAAM,CAAC,CAACpD,OAA2C,CAAC,CAACA;QACxDP,YAAYgE;IACd,GAAG;QAACnE;QAAMQ;QAAUL;KAAU;IAE9B,MAAMiE,gBAAgBjD,YACpB,CACEE,YACAI;QAEA;QACAE,OAAOtB,UAAU,oBAAoBoB;QACrC,MAAMuC,YAAYR,UAAUnC;QAC5BK,gBAAgBqC,aAAaC;QAC7BH;IACF,GACA;QAACA;QAAaE;QAAaP;KAAU;IAGvC,OAAO;QACLjC;QACA+B;QACAc;IACF;AACF"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@lynx-js/lynx-ui-sortable",
|
|
3
|
-
"version": "3.
|
|
3
|
+
"version": "3.133.0",
|
|
4
4
|
"repository": {
|
|
5
5
|
"type": "git",
|
|
6
6
|
"url": "git+https://github.com/lynx-family/lynx-ui.git",
|
|
@@ -25,11 +25,11 @@
|
|
|
25
25
|
"dist/**"
|
|
26
26
|
],
|
|
27
27
|
"dependencies": {
|
|
28
|
-
"@lynx-js/lynx-ui-common": "3.
|
|
29
|
-
"@lynx-js/lynx-ui-draggable": "3.
|
|
28
|
+
"@lynx-js/lynx-ui-common": "3.133.0",
|
|
29
|
+
"@lynx-js/lynx-ui-draggable": "3.133.0"
|
|
30
30
|
},
|
|
31
31
|
"devDependencies": {
|
|
32
|
-
"@lynx-js/react": "0.
|
|
32
|
+
"@lynx-js/react": "0.114.0",
|
|
33
33
|
"@lynx-js/types": "3.6.0",
|
|
34
34
|
"@rslib/core": "^0.16.0",
|
|
35
35
|
"@types/react": "^18.3.8",
|
package/src/useSortable.tsx
CHANGED
|
@@ -55,7 +55,6 @@ export function useSortable(
|
|
|
55
55
|
const item = itemMTSRefMap.current[sortingKey]
|
|
56
56
|
|
|
57
57
|
item?.MTSSetOtherStyles({
|
|
58
|
-
'transform': `translateZ(${zIndex}px)`,
|
|
59
58
|
'z-index': `${zIndex}`,
|
|
60
59
|
})
|
|
61
60
|
}, [itemMTSRefMap])
|
|
@@ -284,9 +283,10 @@ export function useSortable(
|
|
|
284
283
|
) => {
|
|
285
284
|
'main thread'
|
|
286
285
|
switchHandler(delta.y, sortingKey)
|
|
286
|
+
changeItemZIndex(10000, sortingKey)
|
|
287
287
|
mtsLog(debugLog, '[event drag move]', event)
|
|
288
288
|
},
|
|
289
|
-
[switchHandler],
|
|
289
|
+
[switchHandler, changeItemZIndex],
|
|
290
290
|
)
|
|
291
291
|
|
|
292
292
|
const sortArray = useCallback((sortingKey: string) => {
|