@lynx-js/lynx-ui-sortable 3.133.1 → 3.134.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 +6 -0
- package/dist/Sortable.d.ts.map +1 -1
- package/dist/Sortable.jsx +645 -40
- package/dist/Sortable.jsx.map +1 -1
- package/dist/SortableContext.d.ts +12 -1
- package/dist/SortableContext.d.ts.map +1 -1
- package/dist/SortableContext.jsx +8 -0
- package/dist/SortableContext.jsx.map +1 -1
- package/dist/types/index.docs.d.ts +63 -0
- package/dist/types/index.docs.d.ts.map +1 -1
- package/dist/useSortable.d.ts +2 -1
- package/dist/useSortable.d.ts.map +1 -1
- package/dist/useSortable.jsx +51 -20
- package/dist/useSortable.jsx.map +1 -1
- package/package.json +1 -1
- package/src/Sortable.tsx +898 -42
- package/src/SortableContext.ts +23 -1
- package/src/types/index.docs.ts +63 -0
- package/src/useSortable.tsx +60 -22
package/dist/Sortable.jsx.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Sortable.jsx","sources":["webpack://@lynx-js/lynx-ui-sortable/./src/Sortable.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 runOnMainThread,\n useCallback,\n useContext,\n useEffect,\n useMainThreadRef,\n useMemo,\n useRef,\n useState,\n} from '@lynx-js/react'\nimport type { RefObject } from '@lynx-js/react'\n\nimport type { Point } from '@lynx-js/lynx-ui-common'\nimport {\n Draggable,\n DraggableArea,\n DraggableRoot,\n} from '@lynx-js/lynx-ui-draggable'\nimport type { DraggableRef } from '@lynx-js/lynx-ui-draggable'\nimport type { MainThread, NodesRef } from '@lynx-js/types'\n\nimport { SortableContext } from './SortableContext'\nimport type { SortableItemProps, SortableRootProps } from './types'\nimport { useSortable } from './useSortable'\n\nexport { DraggableArea as SortableItemArea }\n\nexport function SortableRoot<T>(props: SortableRootProps<T>) {\n const {\n children,\n data,\n debugLog = false,\n boundaryId,\n onSortEnd,\n onSortStart,\n enableSorting = true,\n } = props\n const sizeMap = useMainThreadRef<Record<string, number>>({})\n const childrenRefMap = useMainThreadRef<\n Record<string, DraggableRef | null>\n >(\n {},\n )\n const childrenMTSRefMap = useMainThreadRef<\n Record<string, DraggableRef | null>\n >(\n {},\n )\n const updateItemSize = useCallback((sortingKey: string, size: number) => {\n 'main thread'\n sizeMap.current[sortingKey] = size\n }, [])\n\n const setChildrenRef = useCallback(\n (refI: RefObject<DraggableRef>, key: string) => {\n 'main thread'\n childrenRefMap.current[key] = refI.current\n },\n [],\n )\n\n const setChildrenMTSRef = useCallback((\n refI: RefObject<DraggableRef>,\n key: string,\n ) => {\n 'main thread'\n childrenMTSRefMap.current[key] = refI.current\n }, [])\n\n const { handleDragEnd, handleDragMove, handleDragStart } = useSortable<T>({\n data,\n sizeMap: sizeMap,\n itemRefMap: childrenRefMap,\n itemMTSRefMap: childrenMTSRefMap,\n onDragEnd: onSortEnd,\n onDragStart: onSortStart,\n debugLog,\n })\n const sortableContextValue = useMemo(() => ({\n data,\n enableSorting,\n boundaryId,\n updateItemSize,\n setChildrenRef,\n setChildrenMTSRef,\n handleDragEnd,\n handleDragMove,\n handleDragStart,\n }), [\n data,\n enableSorting,\n boundaryId,\n updateItemSize,\n setChildrenRef,\n setChildrenMTSRef,\n handleDragEnd,\n handleDragMove,\n handleDragStart,\n ])\n\n const renderedChildren = useMemo(\n () => data?.map(item => children(item)),\n [data, children],\n )\n\n return (\n <SortableContext.Provider\n value={sortableContextValue}\n >\n {renderedChildren}\n </SortableContext.Provider>\n )\n}\n\ninterface boundingClientRectRes {\n height: number\n width: number\n top: number\n left: number\n bottom: number\n right: number\n}\n\nexport function SortableItem(props: SortableItemProps) {\n const { className, children, sortingKey, as = 'Draggable' } = props\n const {\n data,\n enableSorting,\n boundaryId,\n updateItemSize,\n setChildrenRef,\n setChildrenMTSRef,\n handleDragStart,\n handleDragEnd,\n handleDragMove,\n } = useContext(SortableContext)\n\n const MTSRef = useMainThreadRef<DraggableRef>(null)\n const ref = useRef<NodesRef>(null)\n const [itemRect, setItemRect] = useState<boundingClientRectRes>({\n height: 0,\n width: 0,\n top: 0,\n left: 0,\n bottom: 0,\n right: 0,\n })\n const [boundaryRect, setBoundaryRect] = useState<boundingClientRectRes>({\n height: 0,\n width: 0,\n top: 0,\n left: 0,\n bottom: 0,\n right: 0,\n })\n useEffect(() => {\n runOnMainThread(setChildrenMTSRef)(MTSRef, sortingKey)\n if (boundaryId) {\n ref?.current\n ?.invoke({\n method: 'boundingClientRect',\n params: {},\n success: (res) => {\n setItemRect(res as boundingClientRectRes)\n },\n })\n .exec()\n lynx.createSelectorQuery().select(`#${boundaryId}`)?.invoke({\n method: 'boundingClientRect',\n params: {},\n success: (res) => {\n setBoundaryRect(res as boundingClientRectRes)\n },\n })\n .exec()\n }\n }, [setChildrenRef, setChildrenMTSRef, sortingKey, data, boundaryId])\n\n const handleMTSLayoutChange = (e: MainThread.LayoutChangeEvent) => {\n 'main thread'\n updateItemSize(sortingKey, e.detail.height)\n }\n\n const itemDragStart = (\n pagePoint: Point,\n event: MainThread.MouseEvent | MainThread.TouchEvent,\n ) => {\n 'main thread'\n handleDragStart?.(pagePoint, sortingKey, event)\n }\n\n const itemDragging = (\n translate: Point,\n event: MainThread.MouseEvent | MainThread.TouchEvent,\n ) => {\n 'main thread'\n handleDragMove?.(translate, sortingKey, event)\n }\n\n const itemDragEnd = (\n _pagePoint: Point,\n event: MainThread.MouseEvent | MainThread.TouchEvent,\n ) => {\n 'main thread'\n handleDragEnd?.(sortingKey, event)\n }\n\n const resetStyle = useMemo(\n () => ({ transform: 'translate(0, 0)', zIndex: '0' }),\n [data],\n )\n\n if (as === 'Draggable') {\n return (\n <Draggable\n MTSRef={MTSRef}\n ref={ref}\n trigger='immediate'\n style={resetStyle}\n className={className}\n enableDragging={enableSorting}\n draggableProps={{\n 'main-thread:bindlayoutchange': handleMTSLayoutChange,\n }}\n onMTSDragStart={itemDragStart}\n onMTSDragEnd={itemDragEnd}\n onMTSDragging={itemDragging}\n allowedDirection={['up', 'down']}\n {...(boundaryId\n && {\n minTranslateY: -(itemRect?.top - boundaryRect?.top),\n maxTranslateY: boundaryRect?.bottom - itemRect?.bottom,\n })}\n >\n {children}\n </Draggable>\n )\n } else {\n return (\n <DraggableRoot\n MTSRef={MTSRef}\n ref={ref}\n trigger='immediate'\n style={resetStyle}\n className={className}\n draggableProps={{\n 'main-thread:bindlayoutchange': handleMTSLayoutChange,\n }}\n onMTSDragStart={itemDragStart}\n onMTSDragEnd={itemDragEnd}\n onMTSDragging={itemDragging}\n enableDragging={enableSorting}\n {...(boundaryId\n && {\n minTranslateY: -(itemRect?.top - boundaryRect?.top),\n maxTranslateY: boundaryRect?.bottom - itemRect?.bottom,\n })}\n allowedDirection={['up', 'down']}\n >\n {children}\n </DraggableRoot>\n )\n }\n}\n"],"names":["SortableRoot","props","children","data","debugLog","boundaryId","onSortEnd","onSortStart","enableSorting","sizeMap","useMainThreadRef","childrenRefMap","childrenMTSRefMap","updateItemSize","useCallback","sortingKey","size","setChildrenRef","refI","key","setChildrenMTSRef","handleDragEnd","handleDragMove","handleDragStart","useSortable","sortableContextValue","useMemo","renderedChildren","item","SortableContext","SortableItem","className","as","useContext","MTSRef","ref","useRef","itemRect","setItemRect","useState","boundaryRect","setBoundaryRect","useEffect","runOnMainThread","res","lynx","handleMTSLayoutChange","e","itemDragStart","pagePoint","event","itemDragging","translate","itemDragEnd","_pagePoint","resetStyle","Draggable","DraggableRoot"],"mappings":";;;;AA+BO,SAASA,aAAgBC,KAA2B;IACzD,MAAM,EACJC,QAAQ,EACRC,IAAI,EACJC,WAAW,KAAK,EAChBC,UAAU,EACVC,SAAS,EACTC,WAAW,EACXC,gBAAgB,IAAI,EACrB,GAAGP;IACJ,MAAMQ,UAAUC,iBAAyC,CAAC;IAC1D,MAAMC,iBAAiBD,iBAGrB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eF,cACf,kBAAkB;QAAC;QAAM;KAAO,GAC/B,GAAI9C,cACA;QACD,eAAe,CAAEgC,CAAAA,UAAU,MAAMG,cAAc,GAAE;QACjD,eAAeA,cAAc,SAASH,UAAU;IAClD,CAAC,EACJ;QACC,CAACnC,SAAS;MACZ,EAAEsD;IAGJ,QACGC,cACC,QAAQvB,QACR,KAAKC,KACL,QAAQ,YACR,OAAOoB,YACP,WAAWxB,WACX,gBAAgB;QACd,gCAAgCe;IAClC,GACA,gBAAgBE,eAChB,cAAcK,aACd,eAAeF,cACf,gBAAgB3C,gBACf,GAAIH,cACA;QACD,eAAe,CAAEgC,CAAAA,UAAU,MAAMG,cAAc,GAAE;QACjD,eAAeA,cAAc,SAASH,UAAU;IAClD,CAAC,EACH,kBAAkB;QAAC;QAAM;KAAO,EACjC;QACC,CAACnC,SAAS;MACZ,EAAEuD;AAGR"}
|
|
1
|
+
{"version":3,"file":"Sortable.jsx","sources":["webpack://@lynx-js/lynx-ui-sortable/./src/Sortable.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 runOnMainThread,\n useCallback,\n useContext,\n useEffect,\n useMainThreadRef,\n useMemo,\n useState,\n} from '@lynx-js/react'\nimport type { RefObject } from '@lynx-js/react'\n\nimport type { Point } from '@lynx-js/lynx-ui-common'\nimport { usePreCommit } from '@lynx-js/lynx-ui-common'\nimport {\n Draggable,\n DraggableArea,\n DraggableRoot,\n} from '@lynx-js/lynx-ui-draggable'\nimport type { DraggableRef } from '@lynx-js/lynx-ui-draggable'\nimport type { MainThread, ScrollEvent } from '@lynx-js/types'\n\nimport { SortableContext } from './SortableContext'\nimport type {\n SortableData,\n SortableItemProps,\n SortableRootProps,\n} from './types'\nimport { useSortable } from './useSortable'\n\nexport { DraggableArea as SortableItemArea }\n\ntype RectTarget = 'item' | 'boundary' | 'scrollableBoundary'\ninterface ScrollByResult {\n scrollTop?: number\n detail?: { scrollTop?: number }\n}\ninterface ScrollTranslateDelta {\n dragDeltaY: number\n measuredRectDeltaY: number\n}\ninterface VerticalBounds {\n top: number\n bottom: number\n}\ninterface EdgeDistance {\n distanceToTop: number\n distanceToBottom: number\n}\n\nfunction getEdgeDistance(\n itemBounds: VerticalBounds,\n boundaryRect: VerticalBounds,\n): EdgeDistance {\n 'main thread'\n return {\n distanceToTop: itemBounds.top - boundaryRect.top,\n distanceToBottom: boundaryRect.bottom - itemBounds.bottom,\n }\n}\n\nfunction getAutoScrollTriggerOverflow(\n edgeDistance: EdgeDistance,\n upperTriggerZone: number,\n lowerTriggerZone: number,\n) {\n 'main thread'\n if (edgeDistance.distanceToTop < upperTriggerZone) {\n return edgeDistance.distanceToTop - upperTriggerZone\n }\n if (edgeDistance.distanceToBottom < lowerTriggerZone) {\n return lowerTriggerZone - edgeDistance.distanceToBottom\n }\n return 0\n}\n\nconst AUTO_SCROLL_MAX_STEP = 18\nconst AUTO_SCROLL_VELOCITY_FACTOR = 0.35\n\nfunction getNormalizedElementKey(sortingKey: string) {\n return String(sortingKey).replace(/[^\\w-]/g, '-')\n}\n\nfunction getSortableItemElementId(sortingKey: string) {\n return `sortable-item-${getNormalizedElementKey(sortingKey)}`\n}\n\nfunction getSortableDragOverlayElementId(sortingKey: string) {\n return `sortable-drag-overlay-${getNormalizedElementKey(sortingKey)}`\n}\n\nexport function SortableRoot<T>(props: SortableRootProps<T>) {\n const {\n children,\n data,\n debugLog = false,\n boundaryId,\n scrollableBoundaryId,\n as,\n scrollableClassName,\n scrollableContentClassName,\n scrollableEnableScroll = true,\n scrollableStickyUpperOffset = 0,\n scrollableStickyLowerOffset = 0,\n onSortEnd,\n onSortStart,\n enableSorting = true,\n } = props\n const scrollable = as === 'ScrollView'\n const [isDragging, setIsDragging] = useState(false)\n const handleInternalSortStart = useCallback(() => {\n setIsDragging(true)\n onSortStart?.()\n }, [onSortStart])\n const handleInternalSortEnd = useCallback(\n (sortedData: SortableData<T>[]) => {\n setIsDragging(false)\n onSortEnd(sortedData)\n },\n [onSortEnd],\n )\n const scrollableElementId = useMemo(\n () => scrollableBoundaryId ?? 'sortable-scrollable-boundary',\n [scrollableBoundaryId],\n )\n const scrollableContentId = useMemo(\n () => boundaryId ?? 'sortable-scrollable-content',\n [boundaryId],\n )\n const sizeMap = useMainThreadRef<Record<string, number>>({})\n const childrenRefMap = useMainThreadRef<\n Record<string, DraggableRef | null>\n >(\n {},\n )\n const childrenMTSRefMap = useMainThreadRef<\n Record<string, DraggableRef | null>\n >(\n {},\n )\n const dragOverlayRefMap = useMainThreadRef<\n Record<string, MainThread.Element | null>\n >(\n {},\n )\n const dirtyKeysRef = useMainThreadRef<Record<string, boolean>>({})\n const scrollableBoundaryUpperEdgeRef = useMainThreadRef(false)\n const scrollableBoundaryLowerEdgeRef = useMainThreadRef(false)\n const scrollableScrollTopRef = useMainThreadRef(0)\n const updateItemSize = useCallback((sortingKey: string, size: number) => {\n 'main thread'\n sizeMap.current[sortingKey] = size\n }, [])\n\n const handleScrollableBoundaryScroll = useCallback((event: ScrollEvent) => {\n 'main thread'\n scrollableScrollTopRef.current = event.detail.scrollTop\n }, [scrollableScrollTopRef])\n\n const handleScrollableBoundaryUpperExposure = useCallback(() => {\n 'main thread'\n scrollableBoundaryUpperEdgeRef.current = true\n }, [scrollableBoundaryUpperEdgeRef])\n\n const handleScrollableBoundaryUpperDisexposure = useCallback(() => {\n 'main thread'\n scrollableBoundaryUpperEdgeRef.current = false\n }, [scrollableBoundaryUpperEdgeRef])\n\n const handleScrollableBoundaryLowerExposure = useCallback(() => {\n 'main thread'\n scrollableBoundaryLowerEdgeRef.current = true\n }, [scrollableBoundaryLowerEdgeRef])\n\n const handleScrollableBoundaryLowerDisexposure = useCallback(() => {\n 'main thread'\n scrollableBoundaryLowerEdgeRef.current = false\n }, [scrollableBoundaryLowerEdgeRef])\n\n const setChildrenRef = useCallback(\n (refI: RefObject<DraggableRef>, key: string) => {\n 'main thread'\n childrenRefMap.current[key] = refI.current\n },\n [],\n )\n\n const setChildrenMTSRef = useCallback((\n refI: RefObject<DraggableRef>,\n key: string,\n ) => {\n 'main thread'\n childrenMTSRefMap.current[key] = refI.current\n }, [])\n\n const setDragOverlayRef = useCallback((\n refI: RefObject<MainThread.Element | null>,\n key: string,\n ) => {\n 'main thread'\n dragOverlayRefMap.current[key] = refI.current\n }, [dragOverlayRefMap])\n\n const { handleDragEnd, handleDragMove, handleDragStart } = useSortable({\n data: data,\n sizeMap: sizeMap,\n itemRefMap: childrenRefMap,\n itemMTSRefMap: childrenMTSRefMap,\n dirtyKeysRef,\n onDragEnd: handleInternalSortEnd,\n onDragStart: handleInternalSortStart,\n debugLog,\n })\n const sortableContextValue = useMemo(() => ({\n data,\n isDragOverlay: false,\n debugLog,\n enableSorting,\n boundaryId: scrollable ? scrollableContentId : boundaryId,\n scrollableBoundaryId: scrollable\n ? scrollableElementId\n : scrollableBoundaryId,\n scrollableBoundaryUpperEdgeRef: scrollable\n ? scrollableBoundaryUpperEdgeRef\n : undefined,\n scrollableBoundaryLowerEdgeRef: scrollable\n ? scrollableBoundaryLowerEdgeRef\n : undefined,\n scrollableScrollTopRef: scrollable\n ? scrollableScrollTopRef\n : undefined,\n dragOverlayRefMap: scrollable ? dragOverlayRefMap : undefined,\n dirtyKeysRef,\n scrollableStickyUpperOffset,\n scrollableStickyLowerOffset,\n updateItemSize,\n setChildrenRef,\n setChildrenMTSRef,\n setDragOverlayRef,\n handleDragEnd,\n handleDragMove,\n handleDragStart,\n }), [\n data,\n debugLog,\n enableSorting,\n boundaryId,\n scrollable,\n scrollableContentId,\n scrollableElementId,\n scrollableBoundaryId,\n scrollableBoundaryLowerEdgeRef,\n scrollableBoundaryUpperEdgeRef,\n scrollableScrollTopRef,\n dragOverlayRefMap,\n dirtyKeysRef,\n scrollableStickyLowerOffset,\n scrollableStickyUpperOffset,\n updateItemSize,\n setChildrenRef,\n setChildrenMTSRef,\n setDragOverlayRef,\n handleDragEnd,\n handleDragMove,\n handleDragStart,\n ])\n\n const sortableDragOverlayContextValue = useMemo(() => ({\n ...sortableContextValue,\n isDragOverlay: true,\n }), [sortableContextValue])\n\n const renderedChildren = useMemo(\n () => data?.map(item => children(item)),\n [data, children],\n )\n\n const renderedDragOverlayChildren = useMemo(\n () => data?.map(item => children(item)),\n [data, children],\n )\n\n if (scrollable) {\n return (\n <>\n <scroll-view\n id={scrollableElementId}\n className={scrollableClassName}\n enable-scroll={scrollableEnableScroll && !isDragging}\n scroll-orientation='vertical'\n main-thread:bindscroll={handleScrollableBoundaryScroll}\n >\n <view\n id={scrollableContentId}\n className={scrollableContentClassName}\n style={{ zIndex: '0' }}\n >\n <view\n style='display: flex; flex-direction: column; overflow:hidden; height: 1ppx; width: 100%;'\n exposure-scene={scrollableElementId}\n exposure-id='upperExposureView'\n id={`${scrollableElementId}-upperExposureView`}\n main-thread:binduiappear={handleScrollableBoundaryUpperExposure}\n main-thread:binduidisappear={handleScrollableBoundaryUpperDisexposure}\n />\n <SortableContext.Provider\n value={sortableContextValue}\n >\n {renderedChildren}\n </SortableContext.Provider>\n <view\n style='display: flex; flex-direction: column; overflow:hidden; height: 1ppx; width: 100%;'\n exposure-scene={scrollableElementId}\n exposure-id='lowerExposureView'\n id={`${scrollableElementId}-lowerExposureView`}\n main-thread:binduiappear={handleScrollableBoundaryLowerExposure}\n main-thread:binduidisappear={handleScrollableBoundaryLowerDisexposure}\n />\n </view>\n </scroll-view>\n <SortableContext.Provider\n value={sortableDragOverlayContextValue}\n >\n {renderedDragOverlayChildren}\n </SortableContext.Provider>\n </>\n )\n }\n\n return (\n <SortableContext.Provider\n value={sortableContextValue}\n >\n {renderedChildren}\n </SortableContext.Provider>\n )\n}\n\ninterface boundingClientRectRes {\n height: number\n width: number\n top: number\n left: number\n bottom: number\n right: number\n}\n\nexport function SortableItem(props: SortableItemProps) {\n const { isDragOverlay } = useContext(SortableContext)\n if (isDragOverlay) {\n return <SortableDragOverlayItem {...props} />\n }\n\n return <SortableInteractiveItem {...props} />\n}\n\nfunction SortableDragOverlayItem(props: SortableItemProps) {\n const { className, children, sortingKey } = props\n const { setDragOverlayRef } = useContext(SortableContext)\n const overlayRef = useMainThreadRef<MainThread.Element | null>(null)\n const overlayElementId = useMemo(\n () => getSortableDragOverlayElementId(sortingKey),\n [sortingKey],\n )\n const overlayStyle = useMemo(() => ({\n position: 'fixed',\n top: '0px',\n left: '0px',\n width: '0px',\n height: '0px',\n opacity: 0,\n visibility: 'hidden',\n zIndex: '10000',\n transform: 'translate(0px, 0px)',\n } as const), [])\n\n useEffect(() => {\n runOnMainThread(setDragOverlayRef)(overlayRef, sortingKey)\n }, [overlayRef, setDragOverlayRef, sortingKey])\n\n return (\n <view\n id={overlayElementId}\n className={className}\n main-thread:ref={overlayRef}\n style={overlayStyle}\n user-interaction-enabled={false}\n >\n {children}\n </view>\n )\n}\n\nfunction SortableInteractiveItem(props: SortableItemProps) {\n const { className, children, sortingKey, as = 'Draggable' } = props\n const {\n data,\n enableSorting,\n boundaryId,\n scrollableBoundaryId,\n scrollableBoundaryUpperEdgeRef,\n scrollableBoundaryLowerEdgeRef,\n scrollableScrollTopRef,\n dragOverlayRefMap,\n dirtyKeysRef,\n scrollableStickyUpperOffset,\n scrollableStickyLowerOffset,\n updateItemSize,\n setChildrenRef,\n setChildrenMTSRef,\n handleDragStart,\n handleDragEnd,\n handleDragMove,\n } = useContext(SortableContext)\n\n const MTSRef = useMainThreadRef<DraggableRef>(null)\n const [itemRect, setItemRect] = useState<boundingClientRectRes>({\n height: 0,\n width: 0,\n top: 0,\n left: 0,\n bottom: 0,\n right: 0,\n })\n const [boundaryRect, setBoundaryRect] = useState<boundingClientRectRes>({\n height: 0,\n width: 0,\n top: 0,\n left: 0,\n bottom: 0,\n right: 0,\n })\n const [scrollableBoundaryRect, setScrollableBoundaryRect] = useState<\n boundingClientRectRes\n >({\n height: 0,\n width: 0,\n top: 0,\n left: 0,\n bottom: 0,\n right: 0,\n })\n const autoScrollingRef = useMainThreadRef(false)\n const lastAutoScrollTranslateY = useMainThreadRef(0)\n const autoScrollDistanceSum = useMainThreadRef(0)\n const autoScrollCompensationY = useMainThreadRef(0)\n const autoScrollStartScrollTop = useMainThreadRef(0)\n const itemMeasuredScrollTop = useMainThreadRef(0)\n const dragStartScrollDeltaFromMeasuredRect = useMainThreadRef(0)\n const autoScrollOverflow = useMainThreadRef(0)\n const autoScrollDirection = useMainThreadRef(0)\n const autoScrollStickyDirection = useMainThreadRef(0)\n const dragSourceHidden = useMainThreadRef(false)\n const latestDragTranslate = useMainThreadRef<Point>({ x: 0, y: 0 })\n const latestDragEvent = useMainThreadRef<\n MainThread.MouseEvent | MainThread.TouchEvent | null\n >(null)\n const autoScrollFrameRef = useMainThreadRef<(() => void) | null>(null)\n const syncScrollDeltaForItemTranslateY = useCallback((\n scrollByResult?: ScrollByResult,\n fallbackScrollByOffset = 0,\n ): ScrollTranslateDelta => {\n 'main thread'\n if (scrollableScrollTopRef) {\n const previousScrollTop = scrollableScrollTopRef.current\n const scrollTop = scrollByResult?.scrollTop\n ?? scrollByResult?.detail?.scrollTop\n if (typeof scrollTop === 'number') {\n scrollableScrollTopRef.current = scrollTop\n } else if (scrollByResult || fallbackScrollByOffset !== 0) {\n scrollableScrollTopRef.current += fallbackScrollByOffset\n }\n\n if (scrollByResult || fallbackScrollByOffset !== 0) {\n autoScrollDistanceSum.current += scrollableScrollTopRef.current\n - previousScrollTop\n }\n autoScrollCompensationY.current = scrollableScrollTopRef.current\n - autoScrollStartScrollTop.current\n return {\n dragDeltaY: autoScrollCompensationY.current,\n measuredRectDeltaY: scrollableScrollTopRef.current\n - itemMeasuredScrollTop.current,\n }\n }\n\n if (fallbackScrollByOffset !== 0) {\n autoScrollDistanceSum.current += fallbackScrollByOffset\n autoScrollCompensationY.current += fallbackScrollByOffset\n }\n return {\n dragDeltaY: autoScrollCompensationY.current,\n measuredRectDeltaY: dragStartScrollDeltaFromMeasuredRect.current\n + autoScrollDistanceSum.current,\n }\n }, [\n autoScrollDistanceSum,\n autoScrollCompensationY,\n autoScrollStartScrollTop,\n dragStartScrollDeltaFromMeasuredRect,\n itemMeasuredScrollTop,\n scrollableScrollTopRef,\n ])\n\n const itemElementId = useMemo(\n () => getSortableItemElementId(sortingKey),\n [sortingKey],\n )\n const setAutoScrolling = useCallback((isAutoScrolling: boolean) => {\n 'main thread'\n autoScrollingRef.current = isAutoScrolling\n }, [autoScrollingRef])\n const captureItemMeasuredScrollTop = useCallback(() => {\n 'main thread'\n itemMeasuredScrollTop.current = scrollableScrollTopRef?.current ?? 0\n }, [itemMeasuredScrollTop, scrollableScrollTopRef])\n\n const measureRectById = useCallback((\n id: string | undefined,\n target: RectTarget,\n ) => {\n if (!id) {\n return\n }\n\n lynx.createSelectorQuery().select(`#${id}`)?.invoke({\n method: 'boundingClientRect',\n params: {},\n success: (res: unknown) => {\n const rect = res as boundingClientRectRes\n if (target === 'item') {\n setItemRect(rect)\n runOnMainThread(captureItemMeasuredScrollTop)()\n return\n }\n if (target === 'boundary') {\n setBoundaryRect(rect)\n return\n }\n\n setScrollableBoundaryRect(rect)\n },\n }).exec()\n }, [captureItemMeasuredScrollTop])\n\n const refreshDraggingRects = useCallback(() => {\n measureRectById(itemElementId, 'item')\n measureRectById(boundaryId, 'boundary')\n measureRectById(scrollableBoundaryId, 'scrollableBoundary')\n }, [\n boundaryId,\n itemElementId,\n measureRectById,\n scrollableBoundaryId,\n ])\n\n const scrollScrollableBoundaryBy = useCallback((\n offset: number,\n onScrolled?: () => void,\n ) => {\n 'main thread'\n if (\n !scrollableBoundaryId\n || offset === 0\n ) {\n onScrolled?.()\n return\n }\n\n const element = lynx.querySelector(`#${scrollableBoundaryId}`)\n if (!element) {\n onScrolled?.()\n return\n }\n\n element.invoke('scrollBy', {\n offset,\n }).then((res) => {\n 'main thread'\n syncScrollDeltaForItemTranslateY(res as ScrollByResult, offset)\n onScrolled?.()\n })\n }, [\n autoScrollingRef,\n scrollableBoundaryId,\n sortingKey,\n syncScrollDeltaForItemTranslateY,\n ])\n\n const isAutoScrollBlocked = useCallback((offset: number) => {\n 'main thread'\n if (offset > 0) { // block autoScroll down when at lower edge\n return scrollableBoundaryLowerEdgeRef?.current === true\n }\n if (offset < 0) { // block autoScroll up when at upper edge\n return scrollableBoundaryUpperEdgeRef?.current === true\n }\n return false\n }, [scrollableBoundaryLowerEdgeRef, scrollableBoundaryUpperEdgeRef])\n\n const getDragStartItemBounds = useCallback((translateY: number) => {\n 'main thread'\n const measuredTopAtDragStart = itemRect.top\n - dragStartScrollDeltaFromMeasuredRect.current\n const measuredBottomAtDragStart = itemRect.bottom\n - dragStartScrollDeltaFromMeasuredRect.current\n\n return {\n top: measuredTopAtDragStart + translateY,\n bottom: measuredBottomAtDragStart + translateY,\n }\n }, [dragStartScrollDeltaFromMeasuredRect, itemRect])\n\n const getAutoScrollOverflow = useCallback((\n distanceToTop: number,\n distanceToBottom: number,\n ) => {\n 'main thread'\n return getAutoScrollTriggerOverflow(\n { distanceToTop, distanceToBottom },\n scrollableStickyUpperOffset,\n scrollableStickyLowerOffset,\n )\n }, [scrollableStickyLowerOffset, scrollableStickyUpperOffset])\n\n const getAutoScrollDirection = useCallback((\n overflowDirection: number,\n translateDeltaY: number,\n ) => {\n 'main thread'\n if (translateDeltaY === 0) {\n return autoScrollDirection.current || overflowDirection\n }\n\n const dragDirection = translateDeltaY > 0 ? 1 : -1\n return dragDirection === overflowDirection ? overflowDirection : 0\n }, [autoScrollDirection])\n\n const getVisualTranslateY = useCallback(() => {\n 'main thread'\n const scrollDelta = syncScrollDeltaForItemTranslateY()\n if (autoScrollStickyDirection.current > 0) {\n return scrollableBoundaryRect.bottom\n - itemRect.bottom\n - scrollableStickyLowerOffset\n + scrollDelta.measuredRectDeltaY\n }\n if (autoScrollStickyDirection.current < 0) {\n return scrollableBoundaryRect.top\n - itemRect.top\n + scrollableStickyUpperOffset\n + scrollDelta.measuredRectDeltaY\n }\n return latestDragTranslate.current.y + scrollDelta.dragDeltaY\n }, [\n autoScrollStickyDirection,\n itemRect,\n latestDragTranslate,\n scrollableBoundaryRect,\n scrollableStickyLowerOffset,\n scrollableStickyUpperOffset,\n syncScrollDeltaForItemTranslateY,\n ])\n\n const getVisualBounds = useCallback((visualTranslateY: number) => {\n 'main thread'\n const scrollDelta = syncScrollDeltaForItemTranslateY()\n return {\n top: itemRect.top - scrollDelta.measuredRectDeltaY\n + visualTranslateY,\n left: itemRect.left + latestDragTranslate.current.x,\n width: itemRect.width,\n height: itemRect.height,\n }\n }, [\n itemRect,\n latestDragTranslate,\n syncScrollDeltaForItemTranslateY,\n ])\n\n const getDragOverlayElement = useCallback(() => {\n 'main thread'\n return dragOverlayRefMap?.current?.[sortingKey] ?? null\n }, [dragOverlayRefMap, sortingKey])\n\n const hideDragSourceItem = useCallback(() => {\n 'main thread'\n if (!scrollableBoundaryId || dragSourceHidden.current) {\n return\n }\n\n MTSRef.current?.MTSSetOtherStyles({\n visibility: 'hidden',\n opacity: '0',\n })\n dragSourceHidden.current = true\n dirtyKeysRef.current[sortingKey] = true\n }, [\n MTSRef,\n dragSourceHidden,\n scrollableBoundaryId,\n dirtyKeysRef,\n sortingKey,\n ])\n\n const showDragSourceItem = useCallback(() => {\n 'main thread'\n if (!dragSourceHidden.current) {\n return\n }\n\n MTSRef.current?.MTSSetOtherStyles({\n visibility: 'visible',\n opacity: '1',\n })\n dragSourceHidden.current = false\n }, [\n MTSRef,\n dragSourceHidden,\n ])\n\n const updateDragOverlayTransform = useCallback((visualTranslateY: number) => {\n 'main thread'\n const overlay = getDragOverlayElement()\n if (!overlay) {\n return\n }\n\n const bounds = getVisualBounds(visualTranslateY)\n overlay.setStyleProperty(\n 'transform',\n `translate(${bounds.left}px, ${bounds.top}px)`,\n )\n }, [\n getDragOverlayElement,\n getVisualBounds,\n ])\n\n const activateDragOverlay = useCallback(() => {\n 'main thread'\n if (!scrollableBoundaryId) {\n return\n }\n\n hideDragSourceItem()\n\n const overlay = getDragOverlayElement()\n if (!overlay) {\n return\n }\n\n const visualTranslateY = getVisualTranslateY()\n const bounds = getVisualBounds(visualTranslateY)\n overlay.setStyleProperties({\n position: 'fixed',\n top: '0px',\n left: '0px',\n width: `${bounds.width}px`,\n height: `${bounds.height}px`,\n opacity: '1',\n visibility: 'visible',\n 'z-index': '10000',\n transform: `translate(${bounds.left}px, ${bounds.top}px)`,\n })\n }, [\n getDragOverlayElement,\n getVisualBounds,\n getVisualTranslateY,\n hideDragSourceItem,\n scrollableBoundaryId,\n ])\n\n const applyVisualTranslate = useCallback(() => {\n 'main thread'\n const visualTranslateY = getVisualTranslateY()\n if (scrollableBoundaryId) {\n MTSRef.current?.MTSSetTransform(0, 0)\n console.info('reset local drag visual')\n updateDragOverlayTransform(visualTranslateY)\n } else {\n MTSRef.current?.MTSSetTransform(\n latestDragTranslate.current.x,\n visualTranslateY,\n )\n }\n dirtyKeysRef.current[sortingKey] = true\n return visualTranslateY\n }, [\n MTSRef,\n getVisualTranslateY,\n latestDragTranslate,\n scrollableBoundaryId,\n updateDragOverlayTransform,\n dirtyKeysRef,\n sortingKey,\n ])\n\n const emitSortableDragMove = useCallback((\n visualTranslateY: number,\n event: MainThread.MouseEvent | MainThread.TouchEvent | null,\n ) => {\n 'main thread'\n if (!event) {\n return\n }\n\n handleDragMove?.(\n { x: latestDragTranslate.current.x, y: visualTranslateY },\n sortingKey,\n event,\n )\n }, [handleDragMove, latestDragTranslate, sortingKey])\n\n const scheduleNextAutoScrollFrame = useCallback(() => {\n 'main thread'\n const nextFrame = autoScrollFrameRef.current\n if (nextFrame) {\n setTimeout(nextFrame, 8)\n }\n }, [autoScrollFrameRef])\n\n const finishAutoScrollFrame = useCallback(() => {\n 'main thread'\n const visualTranslateY = applyVisualTranslate()\n\n emitSortableDragMove(visualTranslateY, latestDragEvent.current)\n scheduleNextAutoScrollFrame()\n }, [\n applyVisualTranslate,\n emitSortableDragMove,\n latestDragEvent,\n scheduleNextAutoScrollFrame,\n ])\n\n const runAutoScrollFrame = useCallback(() => {\n 'main thread'\n if (!autoScrollingRef.current) {\n return\n }\n\n const overflow = autoScrollOverflow.current\n if (overflow === 0) {\n setAutoScrolling(false)\n return\n }\n\n const direction = autoScrollDirection.current || (overflow > 0 ? 1 : -1)\n if (isAutoScrollBlocked(direction)) {\n const visualTranslateY = applyVisualTranslate()\n emitSortableDragMove(visualTranslateY, latestDragEvent.current)\n setAutoScrolling(false)\n return\n }\n\n const step = direction * Math.min(\n AUTO_SCROLL_MAX_STEP,\n Math.abs(overflow) * AUTO_SCROLL_VELOCITY_FACTOR,\n )\n const finishScrolledFrame = () => {\n 'main thread'\n finishAutoScrollFrame()\n }\n\n scrollScrollableBoundaryBy(step, finishScrolledFrame)\n }, [\n applyVisualTranslate,\n autoScrollDirection,\n autoScrollOverflow,\n autoScrollingRef,\n emitSortableDragMove,\n finishAutoScrollFrame,\n isAutoScrollBlocked,\n latestDragEvent,\n scrollScrollableBoundaryBy,\n setAutoScrolling,\n ])\n\n const startAutoScrollLoop = useCallback(() => {\n 'main thread'\n if (autoScrollingRef.current) {\n return\n }\n autoScrollFrameRef.current = runAutoScrollFrame\n setAutoScrolling(true)\n scheduleNextAutoScrollFrame()\n }, [\n autoScrollingRef,\n runAutoScrollFrame,\n scheduleNextAutoScrollFrame,\n setAutoScrolling,\n ])\n\n const stopAutoScrollLoop = useCallback(() => {\n 'main thread'\n autoScrollOverflow.current = 0\n autoScrollDirection.current = 0\n autoScrollStickyDirection.current = 0\n setAutoScrolling(false)\n }, [\n autoScrollDirection,\n autoScrollOverflow,\n autoScrollStickyDirection,\n setAutoScrolling,\n ])\n\n useEffect(() => {\n runOnMainThread(setChildrenMTSRef)(MTSRef, sortingKey)\n refreshDraggingRects()\n }, [\n data,\n refreshDraggingRects,\n setChildrenRef,\n setChildrenMTSRef,\n sortingKey,\n ])\n\n const handleMTSLayoutChange = (e: MainThread.LayoutChangeEvent) => {\n 'main thread'\n updateItemSize(sortingKey, e.detail.height)\n }\n\n const resetAutoScrollDragState = useCallback(() => {\n 'main thread'\n lastAutoScrollTranslateY.current = 0\n autoScrollDistanceSum.current = 0\n autoScrollCompensationY.current = 0\n autoScrollOverflow.current = 0\n autoScrollDirection.current = 0\n autoScrollStickyDirection.current = 0\n latestDragTranslate.current = { x: 0, y: 0 }\n }, [\n autoScrollCompensationY,\n autoScrollDirection,\n autoScrollDistanceSum,\n autoScrollOverflow,\n autoScrollStickyDirection,\n lastAutoScrollTranslateY,\n latestDragTranslate,\n ])\n\n const itemDragStart = (\n pagePoint: Point,\n event: MainThread.MouseEvent | MainThread.TouchEvent,\n ) => {\n 'main thread'\n resetAutoScrollDragState()\n const scrollTop = scrollableScrollTopRef?.current ?? 0\n autoScrollStartScrollTop.current = scrollTop\n dragStartScrollDeltaFromMeasuredRect.current = scrollTop\n - itemMeasuredScrollTop.current\n latestDragEvent.current = event\n if (scrollableBoundaryId && scrollableBoundaryRect.height > 0) {\n const draggedItem = getDragStartItemBounds(0)\n const { distanceToTop, distanceToBottom } = getEdgeDistance(\n draggedItem,\n scrollableBoundaryRect,\n )\n const overflow = getAutoScrollOverflow(distanceToTop, distanceToBottom)\n if (overflow !== 0) {\n autoScrollStickyDirection.current = overflow > 0 ? 1 : -1\n }\n }\n activateDragOverlay()\n handleDragStart?.(pagePoint, sortingKey, event)\n if (autoScrollStickyDirection.current !== 0) {\n const visualTranslateY = getVisualTranslateY()\n emitSortableDragMove(visualTranslateY, event)\n }\n }\n\n const itemDragging = (\n translate: Point,\n event: MainThread.MouseEvent | MainThread.TouchEvent,\n ) => {\n 'main thread'\n latestDragTranslate.current = translate\n latestDragEvent.current = event\n if (scrollableBoundaryId && scrollableBoundaryRect.height > 0) {\n const draggedItem = getDragStartItemBounds(translate.y)\n const { distanceToTop, distanceToBottom } = getEdgeDistance(\n draggedItem,\n scrollableBoundaryRect,\n )\n const translateDeltaY = translate.y - lastAutoScrollTranslateY.current\n const overflow = getAutoScrollOverflow(distanceToTop, distanceToBottom)\n\n lastAutoScrollTranslateY.current = translate.y\n\n if (overflow === 0) {\n stopAutoScrollLoop()\n const visualTranslateY = applyVisualTranslate()\n emitSortableDragMove(visualTranslateY, event)\n } else {\n const overflowDirection = overflow > 0 ? 1 : -1\n const scrollDirection = getAutoScrollDirection(\n overflowDirection,\n translateDeltaY,\n )\n autoScrollOverflow.current = overflow\n autoScrollStickyDirection.current = overflowDirection\n autoScrollDirection.current = scrollDirection\n const visualTranslateY = applyVisualTranslate()\n const blockedByScrollableEdge = scrollDirection !== 0\n && isAutoScrollBlocked(scrollDirection)\n if (scrollDirection === 0) {\n setAutoScrolling(false)\n } else if (blockedByScrollableEdge) {\n setAutoScrolling(false)\n } else {\n startAutoScrollLoop()\n }\n emitSortableDragMove(visualTranslateY, event)\n }\n return\n }\n\n handleDragMove?.(translate, sortingKey, event)\n }\n\n const resetLocalDragVisuals = () => {\n 'main thread'\n if (!dirtyKeysRef.current[sortingKey]) {\n return\n }\n console.info('reset local drag visual2')\n MTSRef.current?.MTSSetTransform(0, 0)\n const overlayWasActive = dragSourceHidden.current\n showDragSourceItem()\n if (overlayWasActive) {\n const overlay = getDragOverlayElement()\n if (overlay) {\n overlay.setStyleProperties({\n opacity: '0',\n visibility: 'hidden',\n transform: 'translate(0px, 0px)',\n })\n }\n }\n dirtyKeysRef.current[sortingKey] = false\n }\n\n const itemDragEnd = (\n _pagePoint: Point,\n event: MainThread.MouseEvent | MainThread.TouchEvent,\n ) => {\n 'main thread'\n resetAutoScrollDragState()\n autoScrollStartScrollTop.current = 0\n dragStartScrollDeltaFromMeasuredRect.current = 0\n latestDragEvent.current = null\n stopAutoScrollLoop()\n const orderChanged = handleDragEnd?.(sortingKey, event) ?? false\n if (!orderChanged) {\n // no data update -> no precommit will run -> reset locally now\n resetLocalDragVisuals()\n }\n // if orderChanged: precommit will run resetLocalDragVisuals in the same frame as setData\n }\n\n const dataKeyOrderSignature = useMemo(\n () => (data ?? []).map(item => item.getSortingKey()).join('|'),\n [data],\n )\n\n usePreCommit(() => {\n 'main thread'\n resetLocalDragVisuals()\n }, [dataKeyOrderSignature])\n\n if (as === 'Draggable') {\n return (\n <Draggable\n id={itemElementId}\n MTSRef={MTSRef}\n trigger='immediate'\n className={className}\n enableDragging={enableSorting}\n draggableProps={{\n 'main-thread:bindlayoutchange': handleMTSLayoutChange,\n }}\n onMTSDragStart={itemDragStart}\n onMTSDragEnd={itemDragEnd}\n onMTSDragging={itemDragging}\n allowedDirection={['up', 'down']}\n {...(!scrollableBoundaryId && boundaryId\n && {\n minTranslateY: -(itemRect.top - boundaryRect.top),\n maxTranslateY: boundaryRect.bottom\n - itemRect.bottom,\n })}\n >\n {children}\n </Draggable>\n )\n } else {\n return (\n <DraggableRoot\n id={itemElementId}\n MTSRef={MTSRef}\n trigger='immediate'\n className={className}\n draggableProps={{\n 'main-thread:bindlayoutchange': handleMTSLayoutChange,\n }}\n onMTSDragStart={itemDragStart}\n onMTSDragEnd={itemDragEnd}\n onMTSDragging={itemDragging}\n enableDragging={enableSorting}\n {...(!scrollableBoundaryId && boundaryId\n && {\n minTranslateY: -(itemRect.top - boundaryRect.top),\n maxTranslateY: boundaryRect.bottom\n - itemRect.bottom,\n })}\n allowedDirection={['up', 'down']}\n >\n {children}\n </DraggableRoot>\n )\n }\n}\n"],"names":["getEdgeDistance","itemBounds","boundaryRect","getAutoScrollTriggerOverflow","edgeDistance","upperTriggerZone","lowerTriggerZone","AUTO_SCROLL_MAX_STEP","AUTO_SCROLL_VELOCITY_FACTOR","getNormalizedElementKey","sortingKey","String","getSortableItemElementId","getSortableDragOverlayElementId","SortableRoot","props","children","data","debugLog","boundaryId","scrollableBoundaryId","as","scrollableClassName","scrollableContentClassName","scrollableEnableScroll","scrollableStickyUpperOffset","scrollableStickyLowerOffset","onSortEnd","onSortStart","enableSorting","scrollable","isDragging","setIsDragging","useState","handleInternalSortStart","useCallback","handleInternalSortEnd","sortedData","scrollableElementId","useMemo","scrollableContentId","sizeMap","useMainThreadRef","childrenRefMap","childrenMTSRefMap","dragOverlayRefMap","dirtyKeysRef","scrollableBoundaryUpperEdgeRef","scrollableBoundaryLowerEdgeRef","scrollableScrollTopRef","updateItemSize","size","handleScrollableBoundaryScroll","event","handleScrollableBoundaryUpperExposure","handleScrollableBoundaryUpperDisexposure","handleScrollableBoundaryLowerExposure","handleScrollableBoundaryLowerDisexposure","setChildrenRef","refI","key","setChildrenMTSRef","setDragOverlayRef","handleDragEnd","handleDragMove","handleDragStart","useSortable","sortableContextValue","undefined","sortableDragOverlayContextValue","renderedChildren","item","renderedDragOverlayChildren","scroll-view","view","SortableContext","SortableItem","isDragOverlay","useContext","SortableDragOverlayItem","SortableInteractiveItem","className","overlayRef","overlayElementId","overlayStyle","useEffect","runOnMainThread","MTSRef","itemRect","setItemRect","setBoundaryRect","scrollableBoundaryRect","setScrollableBoundaryRect","autoScrollingRef","lastAutoScrollTranslateY","autoScrollDistanceSum","autoScrollCompensationY","autoScrollStartScrollTop","itemMeasuredScrollTop","dragStartScrollDeltaFromMeasuredRect","autoScrollOverflow","autoScrollDirection","autoScrollStickyDirection","dragSourceHidden","latestDragTranslate","latestDragEvent","autoScrollFrameRef","syncScrollDeltaForItemTranslateY","scrollByResult","fallbackScrollByOffset","previousScrollTop","scrollTop","itemElementId","setAutoScrolling","isAutoScrolling","captureItemMeasuredScrollTop","measureRectById","id","target","lynx","res","rect","refreshDraggingRects","scrollScrollableBoundaryBy","offset","onScrolled","element","isAutoScrollBlocked","getDragStartItemBounds","translateY","measuredTopAtDragStart","measuredBottomAtDragStart","getAutoScrollOverflow","distanceToTop","distanceToBottom","getAutoScrollDirection","overflowDirection","translateDeltaY","dragDirection","getVisualTranslateY","scrollDelta","getVisualBounds","visualTranslateY","getDragOverlayElement","hideDragSourceItem","showDragSourceItem","updateDragOverlayTransform","overlay","bounds","activateDragOverlay","applyVisualTranslate","console","emitSortableDragMove","scheduleNextAutoScrollFrame","nextFrame","setTimeout","finishAutoScrollFrame","runAutoScrollFrame","overflow","direction","step","Math","finishScrolledFrame","startAutoScrollLoop","stopAutoScrollLoop","handleMTSLayoutChange","e","resetAutoScrollDragState","itemDragStart","pagePoint","draggedItem","itemDragging","translate","scrollDirection","blockedByScrollableEdge","resetLocalDragVisuals","overlayWasActive","itemDragEnd","_pagePoint","orderChanged","dataKeyOrderSignature","usePreCommit","Draggable","DraggableRoot"],"mappings":";;;;;AAqDA,SAASA,gBACPC,UAA0B,EAC1BC,YAA4B;IAE5B;IACA,OAAO;QACL,eAAeD,WAAW,GAAG,GAAGC,aAAa,GAAG;QAChD,kBAAkBA,aAAa,MAAM,GAAGD,WAAW,MAAM;IAC3D;AACF;AAEA,SAASE,6BACPC,YAA0B,EAC1BC,gBAAwB,EACxBC,gBAAwB;IAExB;IACA,IAAIF,aAAa,aAAa,GAAGC,kBAC/B,OAAOD,aAAa,aAAa,GAAGC;IAEtC,IAAID,aAAa,gBAAgB,GAAGE,kBAClC,OAAOA,mBAAmBF,aAAa,gBAAgB;IAEzD,OAAO;AACT;AAEA,MAAMG,uBAAuB;AAC7B,MAAMC,8BAA8B;AAEpC,SAASC,wBAAwBC,UAAkB;IACjD,OAAOC,OAAOD,YAAY,OAAO,CAAC,WAAW;AAC/C;AAEA,SAASE,yBAAyBF,UAAkB;IAClD,OAAO,CAAC,cAAc,EAAED,wBAAwBC,aAAa;AAC/D;AAEA,SAASG,gCAAgCH,UAAkB;IACzD,OAAO,CAAC,sBAAsB,EAAED,wBAAwBC,aAAa;AACvE;AAEO,SAASI,aAAgBC,KAA2B;IACzD,MAAM,EACJC,QAAQ,EACRC,IAAI,EACJC,WAAW,KAAK,EAChBC,UAAU,EACVC,oBAAoB,EACpBC,EAAE,EACFC,mBAAmB,EACnBC,0BAA0B,EAC1BC,yBAAyB,IAAI,EAC7BC,8BAA8B,CAAC,EAC/BC,8BAA8B,CAAC,EAC/BC,SAAS,EACTC,WAAW,EACXC,gBAAgB,IAAI,EACrB,GAAGd;IACJ,MAAMe,aAAaT,AAAO,iBAAPA;IACnB,MAAM,CAACU,YAAYC,c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+
import type { MutableRefObject, RefObject } from '@lynx-js/react';
|
|
2
2
|
import type { Point } from '@lynx-js/lynx-ui-common';
|
|
3
3
|
import type { DraggableRef } from '@lynx-js/lynx-ui-draggable';
|
|
4
4
|
import type { MainThread } from '@lynx-js/types';
|
|
5
5
|
import type { SortableData } from './types';
|
|
6
6
|
interface SortableContextType<T = unknown> {
|
|
7
7
|
data: SortableData<T>[];
|
|
8
|
+
isDragOverlay: boolean;
|
|
8
9
|
boundaryId?: string;
|
|
10
|
+
scrollableBoundaryId?: string;
|
|
11
|
+
scrollableBoundaryUpperEdgeRef?: MutableRefObject<boolean>;
|
|
12
|
+
scrollableBoundaryLowerEdgeRef?: MutableRefObject<boolean>;
|
|
13
|
+
scrollableScrollTopRef?: MutableRefObject<number>;
|
|
14
|
+
dragOverlayRefMap?: MutableRefObject<Record<string, MainThread.Element | null>>;
|
|
15
|
+
dirtyKeysRef: MutableRefObject<Record<string, boolean>>;
|
|
16
|
+
scrollableStickyUpperOffset: number;
|
|
17
|
+
scrollableStickyLowerOffset: number;
|
|
18
|
+
debugLog: boolean;
|
|
9
19
|
enableSorting: boolean;
|
|
10
20
|
updateItemSize: (sortingKey: string, size: number) => void;
|
|
11
21
|
setChildrenRef: (refI: RefObject<DraggableRef>, key: string) => void;
|
|
12
22
|
setChildrenMTSRef: (refI: RefObject<DraggableRef>, key: string) => void;
|
|
23
|
+
setDragOverlayRef: (refI: RefObject<MainThread.Element | null>, key: string) => void;
|
|
13
24
|
handleDragStart: (pagePoint: Point, sortingKey: string, event: MainThread.MouseEvent | MainThread.TouchEvent) => void;
|
|
14
25
|
handleDragMove: (delta: Point, sortingKey: string, event: MainThread.MouseEvent | MainThread.TouchEvent) => void;
|
|
15
26
|
handleDragEnd: (sortingKey: string, event: MainThread.MouseEvent | MainThread.TouchEvent) => void;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"SortableContext.d.ts","sourceRoot":"","sources":["../src/SortableContext.ts"],"names":[],"mappings":"A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,cAAc,EAAE,CAAC,IAAI,EAAE,SAAS,CAAC,YAAY,CAAC,EAAE,GAAG,EAAE,MAAM,KAAK,IAAI,CAAA;IACpE,iBAAiB,EAAE,CACjB,IAAI,EAAE,SAAS,CAAC,YAAY,CAAC,EAC7B,GAAG,EAAE,MAAM,KACR,IAAI,CAAA;IACT,iBAAiB,EAAE,CACjB,IAAI,EAAE,SAAS,CAAC,UAAU,CAAC,OAAO,GAAG,IAAI,CAAC,EAC1C,GAAG,EAAE,MAAM,KACR,IAAI,CAAA;IACT,eAAe,EAAE,CACf,SAAS,EAAE,KAAK,EAChB,UAAU,EAAE,MAAM,EAClB,KAAK,EAAE,UAAU,CAAC,UAAU,GAAG,UAAU,CAAC,UAAU,KACjD,IAAI,CAAA;IACT,cAAc,EAAE,CACd,KAAK,EAAE,KAAK,EACZ,UAAU,EAAE,MAAM,EAClB,KAAK,EAAE,UAAU,CAAC,UAAU,GAAG,UAAU,CAAC,UAAU,KACjD,IAAI,CAAA;IACT,aAAa,EAAE,CACb,UAAU,EAAE,MAAM,EAClB,KAAK,EAAE,UAAU,CAAC,UAAU,GAAG,UAAU,CAAC,UAAU,KACjD,IAAI,CAAA;CACV;AAED,eAAO,MAAM,eAAe,uDAe1B,CAAA"}
|
package/dist/SortableContext.jsx
CHANGED
|
@@ -2,10 +2,18 @@ import { createContext } from "@lynx-js/react";
|
|
|
2
2
|
import { noop } from "@lynx-js/lynx-ui-common";
|
|
3
3
|
const SortableContext = createContext({
|
|
4
4
|
data: [],
|
|
5
|
+
isDragOverlay: false,
|
|
6
|
+
debugLog: false,
|
|
5
7
|
enableSorting: true,
|
|
8
|
+
scrollableStickyUpperOffset: 0,
|
|
9
|
+
scrollableStickyLowerOffset: 0,
|
|
10
|
+
dirtyKeysRef: {
|
|
11
|
+
current: {}
|
|
12
|
+
},
|
|
6
13
|
updateItemSize: noop,
|
|
7
14
|
setChildrenRef: noop,
|
|
8
15
|
setChildrenMTSRef: noop,
|
|
16
|
+
setDragOverlayRef: noop,
|
|
9
17
|
handleDragStart: noop,
|
|
10
18
|
handleDragMove: noop,
|
|
11
19
|
handleDragEnd: noop
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"SortableContext.jsx","sources":["webpack://@lynx-js/lynx-ui-sortable/./src/SortableContext.ts"],"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 { createContext } from '@lynx-js/react'\nimport type { RefObject } from '@lynx-js/react'\n\nimport { noop } 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 SortableContextType<T = unknown> {\n data: SortableData<T>[]\n boundaryId?: string\n enableSorting: boolean\n updateItemSize: (sortingKey: string, size: number) => void\n setChildrenRef: (refI: RefObject<DraggableRef>, key: string) => void\n setChildrenMTSRef: (\n refI: RefObject<DraggableRef>,\n key: string,\n ) => void\n handleDragStart: (\n pagePoint: Point,\n sortingKey: string,\n event: MainThread.MouseEvent | MainThread.TouchEvent,\n ) => void\n handleDragMove: (\n delta: Point,\n sortingKey: string,\n event: MainThread.MouseEvent | MainThread.TouchEvent,\n ) => void\n handleDragEnd: (\n sortingKey: string,\n event: MainThread.MouseEvent | MainThread.TouchEvent,\n ) => void\n}\n\nexport const SortableContext = createContext<SortableContextType>({\n data: [],\n enableSorting: true,\n updateItemSize: noop,\n setChildrenRef: noop,\n setChildrenMTSRef: noop,\n handleDragStart: noop,\n handleDragMove: noop,\n handleDragEnd: noop,\n})\n"],"names":["SortableContext","createContext","noop"],"mappings":";;
|
|
1
|
+
{"version":3,"file":"SortableContext.jsx","sources":["webpack://@lynx-js/lynx-ui-sortable/./src/SortableContext.ts"],"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 { createContext } from '@lynx-js/react'\nimport type { MutableRefObject, RefObject } from '@lynx-js/react'\n\nimport { noop } 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 SortableContextType<T = unknown> {\n data: SortableData<T>[]\n isDragOverlay: boolean\n boundaryId?: string\n scrollableBoundaryId?: string\n scrollableBoundaryUpperEdgeRef?: MutableRefObject<boolean>\n scrollableBoundaryLowerEdgeRef?: MutableRefObject<boolean>\n scrollableScrollTopRef?: MutableRefObject<number>\n dragOverlayRefMap?: MutableRefObject<\n Record<string, MainThread.Element | null>\n >\n dirtyKeysRef: MutableRefObject<Record<string, boolean>>\n scrollableStickyUpperOffset: number\n scrollableStickyLowerOffset: number\n debugLog: boolean\n enableSorting: boolean\n updateItemSize: (sortingKey: string, size: number) => void\n setChildrenRef: (refI: RefObject<DraggableRef>, key: string) => void\n setChildrenMTSRef: (\n refI: RefObject<DraggableRef>,\n key: string,\n ) => void\n setDragOverlayRef: (\n refI: RefObject<MainThread.Element | null>,\n key: string,\n ) => void\n handleDragStart: (\n pagePoint: Point,\n sortingKey: string,\n event: MainThread.MouseEvent | MainThread.TouchEvent,\n ) => void\n handleDragMove: (\n delta: Point,\n sortingKey: string,\n event: MainThread.MouseEvent | MainThread.TouchEvent,\n ) => void\n handleDragEnd: (\n sortingKey: string,\n event: MainThread.MouseEvent | MainThread.TouchEvent,\n ) => void\n}\n\nexport const SortableContext = createContext<SortableContextType>({\n data: [],\n isDragOverlay: false,\n debugLog: false,\n enableSorting: true,\n scrollableStickyUpperOffset: 0,\n scrollableStickyLowerOffset: 0,\n dirtyKeysRef: { current: {} },\n updateItemSize: noop,\n setChildrenRef: noop,\n setChildrenMTSRef: noop,\n setDragOverlayRef: noop,\n handleDragStart: noop,\n handleDragMove: noop,\n handleDragEnd: noop,\n})\n"],"names":["SortableContext","createContext","noop"],"mappings":";;AAwDO,MAAMA,kBAAkBC,cAAmC;IAChE,MAAM,EAAE;IACR,eAAe;IACf,UAAU;IACV,eAAe;IACf,6BAA6B;IAC7B,6BAA6B;IAC7B,cAAc;QAAE,SAAS,CAAC;IAAE;IAC5B,gBAAgBC;IAChB,gBAAgBA;IAChB,mBAAmBA;IACnB,mBAAmBA;IACnB,iBAAiBA;IACjB,gBAAgBA;IAChB,eAAeA;AACjB"}
|
|
@@ -22,6 +22,61 @@ export interface SortableData<T> {
|
|
|
22
22
|
dataItem: T;
|
|
23
23
|
}
|
|
24
24
|
export interface SortableRootProps<T> {
|
|
25
|
+
/**
|
|
26
|
+
* Specifies which container element SortableRoot should render and own as the scrollable boundary.
|
|
27
|
+
* - `'ScrollView'`: render an internal vertical `scroll-view`.
|
|
28
|
+
* - Omit (default): render a plain `view` without scrolling capability.
|
|
29
|
+
* @Android
|
|
30
|
+
* @iOS
|
|
31
|
+
* @Harmony
|
|
32
|
+
* @zh 指定 SortableRoot 渲染并持有的滚动容器类型。
|
|
33
|
+
* - `'ScrollView'`:渲染一个内部的纵向 `scroll-view`。
|
|
34
|
+
* - 不传(默认):渲染普通 `view`,不带滚动能力。
|
|
35
|
+
*/
|
|
36
|
+
as?: 'ScrollView';
|
|
37
|
+
/**
|
|
38
|
+
* Class name applied to the owned `scroll-view` when `as` is `'ScrollView'`.
|
|
39
|
+
* @Android
|
|
40
|
+
* @iOS
|
|
41
|
+
* @Harmony
|
|
42
|
+
* @zh `as` 为 `'ScrollView'` 时应用到内部 `scroll-view` 的类名。
|
|
43
|
+
*/
|
|
44
|
+
scrollableClassName?: string;
|
|
45
|
+
/**
|
|
46
|
+
* Class name applied to the owned content boundary view when `as` is `'ScrollView'`.
|
|
47
|
+
* @Android
|
|
48
|
+
* @iOS
|
|
49
|
+
* @Harmony
|
|
50
|
+
* @zh `as` 为 `'ScrollView'` 时应用到内部内容边界 view 的类名。
|
|
51
|
+
*/
|
|
52
|
+
scrollableContentClassName?: string;
|
|
53
|
+
/**
|
|
54
|
+
* Whether the owned `scroll-view` can be scrolled by user gestures.
|
|
55
|
+
* @defaultValue true
|
|
56
|
+
* @Android
|
|
57
|
+
* @iOS
|
|
58
|
+
* @Harmony
|
|
59
|
+
* @zh 内部 `scroll-view` 是否允许用户手势滚动。
|
|
60
|
+
*/
|
|
61
|
+
scrollableEnableScroll?: boolean;
|
|
62
|
+
/**
|
|
63
|
+
* Distance between the dragged item and the upper edge of the owned or configured scrollable boundary while auto-scrolling upward.
|
|
64
|
+
* @defaultValue 0
|
|
65
|
+
* @Android
|
|
66
|
+
* @iOS
|
|
67
|
+
* @Harmony
|
|
68
|
+
* @zh 向上自动滚动时,拖拽项与可滚动边界上边缘之间保持的距离。
|
|
69
|
+
*/
|
|
70
|
+
scrollableStickyUpperOffset?: number;
|
|
71
|
+
/**
|
|
72
|
+
* Distance between the dragged item and the lower edge of the owned or configured scrollable boundary while auto-scrolling downward.
|
|
73
|
+
* @defaultValue 0
|
|
74
|
+
* @Android
|
|
75
|
+
* @iOS
|
|
76
|
+
* @Harmony
|
|
77
|
+
* @zh 向下自动滚动时,拖拽项与可滚动边界下边缘之间保持的距离。
|
|
78
|
+
*/
|
|
79
|
+
scrollableStickyLowerOffset?: number;
|
|
25
80
|
/**
|
|
26
81
|
* Whether to enable sorting.
|
|
27
82
|
* @defaultValue true
|
|
@@ -55,6 +110,14 @@ export interface SortableRootProps<T> {
|
|
|
55
110
|
* @zh 作为边界限制的项的唯一键。如果项被拖出边界,排序将被取消。
|
|
56
111
|
*/
|
|
57
112
|
boundaryId?: string;
|
|
113
|
+
/**
|
|
114
|
+
* The unique id of a scrollable boundary container. When the dragged item reaches the edge of this container, Sortable will call `scrollBy` on it so the list can continue moving with the drag direction.
|
|
115
|
+
* @Android
|
|
116
|
+
* @iOS
|
|
117
|
+
* @Harmony
|
|
118
|
+
* @zh 可滚动边界容器的唯一 id。当拖拽项触达该容器边缘时,Sortable 会对其调用 `scrollBy`,使列表随拖拽方向继续滚动。
|
|
119
|
+
*/
|
|
120
|
+
scrollableBoundaryId?: string;
|
|
58
121
|
/**
|
|
59
122
|
* Callback function that is triggered when sorting ends. The parameter is the sorted data.
|
|
60
123
|
* @Android
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.docs.d.ts","sourceRoot":"","sources":["../../src/types/index.docs.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAA;AAE/C;;;GAGG;AACH,MAAM,WAAW,YAAY,CAAC,CAAC;IAC7B;;;;;;OAMG;IACH,aAAa,EAAE,MAAM,MAAM,CAAA;IAC3B;;;;;;OAMG;IACH,QAAQ,EAAE,CAAC,CAAA;CACZ;AAED,MAAM,WAAW,iBAAiB,CAAC,CAAC;IAClC;;;;;;;OAOG;IACH,aAAa,CAAC,EAAE,OAAO,CAAA;IACvB;;;;;;OAMG;IACH,QAAQ,EAAE,CAAC,IAAI,EAAE,YAAY,CAAC,CAAC,CAAC,KAAK,SAAS,CAAA;IAC9C;;;;;;OAMG;IACH,IAAI,EAAE,YAAY,CAAC,CAAC,CAAC,EAAE,CAAA;IACvB;;;;;;OAMG;IACH,UAAU,CAAC,EAAE,MAAM,CAAA;IACnB;;;;;;OAMG;IACH,SAAS,EAAE,CAAC,UAAU,EAAE,YAAY,CAAC,CAAC,CAAC,EAAE,KAAK,IAAI,CAAA;IAClD;;;;;;OAMG;IACH,WAAW,CAAC,EAAE,MAAM,IAAI,CAAA;IACxB;;;;;;;OAOG;IACH,QAAQ,CAAC,EAAE,OAAO,CAAA;CACnB;AAED;;;GAGG;AACH,MAAM,WAAW,iBAAiB;IAChC;;;;;;OAMG;IACH,SAAS,CAAC,EAAE,MAAM,CAAA;IAClB;;;;;;OAMG;IACH,UAAU,EAAE,MAAM,CAAA;IAClB;;;;;;OAMG;IACH,QAAQ,EAAE,SAAS,CAAA;IACnB;;;;;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IACxB;;;;;;;OAOG;IACH,QAAQ,CAAC,EAAE,OAAO,CAAA;CACnB;AAED;;;GAGG;AACH,MAAM,WAAW,iBAAiB;IAChC;;;;;;OAMG;IACH,SAAS,CAAC,EAAE,MAAM,CAAA;IAClB;;;;;;OAMG;IACH,UAAU,EAAE,MAAM,CAAA;IAClB;;;;;;OAMG;IACH,QAAQ,EAAE,SAAS,CAAA;IACnB;;;;;;;OAOG;IACH,EAAE,CAAC,EAAE,WAAW,GAAG,eAAe,CAAA;CACnC"}
|
package/dist/useSortable.d.ts
CHANGED
|
@@ -8,6 +8,7 @@ interface SortableOptionsType<T> {
|
|
|
8
8
|
sizeMap: MainThreadRef<Record<string, number>>;
|
|
9
9
|
itemRefMap: RefObject<Record<string, DraggableRef | null>>;
|
|
10
10
|
itemMTSRefMap: MainThreadRef<Record<string, DraggableRef | null>>;
|
|
11
|
+
dirtyKeysRef: MainThreadRef<Record<string, boolean>>;
|
|
11
12
|
onDragEnd?: (sortedKeyArray: SortableData<T>[]) => void;
|
|
12
13
|
onDragStart?: () => void;
|
|
13
14
|
debugLog?: boolean;
|
|
@@ -15,7 +16,7 @@ interface SortableOptionsType<T> {
|
|
|
15
16
|
export declare function useSortable<T>(useSortableOptions: SortableOptionsType<T>): {
|
|
16
17
|
handleDragStart: (pagePoint: Point, sortingKey: string, event: MainThread.MouseEvent | MainThread.TouchEvent) => void;
|
|
17
18
|
handleDragMove: (delta: Point, sortingKey: string, event: MainThread.MouseEvent | MainThread.TouchEvent) => void;
|
|
18
|
-
handleDragEnd: (sortingKey: string, event: MainThread.MouseEvent | MainThread.TouchEvent) =>
|
|
19
|
+
handleDragEnd: (sortingKey: string, event: MainThread.MouseEvent | MainThread.TouchEvent) => boolean;
|
|
19
20
|
};
|
|
20
21
|
export {};
|
|
21
22
|
//# sourceMappingURL=useSortable.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useSortable.d.ts","sourceRoot":"","sources":["../src/useSortable.tsx"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CAAA;AAEhD,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,SAAS,CAAA;AAE3C,UAAU,mBAAmB,CAAC,CAAC;IAC7B,IAAI,EAAE,YAAY,CAAC,CAAC,CAAC,EAAE,CAAA;IACvB,OAAO,EAAE,aAAa,CAAC,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC,CAAA;IAC9C,UAAU,EAAE,SAAS,CAAC,MAAM,CAAC,MAAM,EAAE,YAAY,GAAG,IAAI,CAAC,CAAC,CAAA;IAC1D,aAAa,EAAE,aAAa,CAAC,MAAM,CAAC,MAAM,EAAE,YAAY,GAAG,IAAI,CAAC,CAAC,CAAA;IACjE,YAAY,EAAE,aAAa,CAAC,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC,CAAA;IACpD,SAAS,CAAC,EAAE,CAAC,cAAc,EAAE,YAAY,CAAC,CAAC,CAAC,EAAE,KAAK,IAAI,CAAA;IACvD,WAAW,CAAC,EAAE,MAAM,IAAI,CAAA;IACxB,QAAQ,CAAC,EAAE,OAAO,CAAA;CACnB;AAED,wBAAgB,WAAW,CAAC,CAAC,EAC3B,kBAAkB,EAAE,mBAAmB,CAAC,CAAC,CAAC;iCAuC3B,KAAK,cACJ,MAAM,SACX,UAAU,CAAC,UAAU,GAAG,UAAU,CAAC,UAAU;4BAmN7C,KAAK,cACA,MAAM,SACX,UAAU,CAAC,UAAU,GAAG,UAAU,CAAC,UAAU;gCAsExC,MAAM,SACX,UAAU,CAAC,UAAU,GAAG,UAAU,CAAC,UAAU,KACnD,OAAO;EAkCb"}
|
package/dist/useSortable.jsx
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { runOnBackground, useCallback, useMainThreadRef, useMemo } from "@lynx-js/react";
|
|
2
2
|
import { mtsLog } from "@lynx-js/lynx-ui-common";
|
|
3
3
|
function useSortable(useSortableOptions) {
|
|
4
|
-
const { data, sizeMap, itemMTSRefMap, onDragEnd, onDragStart, debugLog = false } = useSortableOptions;
|
|
4
|
+
const { data, sizeMap, itemMTSRefMap, dirtyKeysRef, onDragEnd, onDragStart, debugLog = false } = useSortableOptions;
|
|
5
5
|
const safeData = Array.isArray(data) ? data : [];
|
|
6
6
|
const keyArray = useMemo(()=>safeData.map((item)=>item.getSortingKey()), [
|
|
7
7
|
safeData
|
|
@@ -21,8 +21,10 @@ function useSortable(useSortableOptions) {
|
|
|
21
21
|
item?.MTSSetOtherStyles({
|
|
22
22
|
'z-index': `${zIndex}`
|
|
23
23
|
});
|
|
24
|
+
dirtyKeysRef.current[sortingKey] = true;
|
|
24
25
|
}, [
|
|
25
|
-
itemMTSRefMap
|
|
26
|
+
itemMTSRefMap,
|
|
27
|
+
dirtyKeysRef
|
|
26
28
|
]);
|
|
27
29
|
const handleDragStartJS = useCallback(()=>{
|
|
28
30
|
onDragStart?.();
|
|
@@ -80,19 +82,22 @@ function useSortable(useSortableOptions) {
|
|
|
80
82
|
keyArray,
|
|
81
83
|
sizeMap
|
|
82
84
|
]);
|
|
83
|
-
const setTransform = useCallback((
|
|
85
|
+
const setTransform = useCallback((key, translate)=>{
|
|
84
86
|
'main thread';
|
|
85
|
-
item
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
}, [
|
|
87
|
+
const item = key ? itemMTSRefMap.current[key] : null;
|
|
88
|
+
item?.MTSSetTransform(0, translate);
|
|
89
|
+
if (key) dirtyKeysRef.current[key] = true;
|
|
90
|
+
}, [
|
|
91
|
+
itemMTSRefMap,
|
|
92
|
+
dirtyKeysRef
|
|
93
|
+
]);
|
|
89
94
|
const clampPreviousItem = (movingDistance, sortingKey)=>{
|
|
90
95
|
'main thread';
|
|
91
96
|
mtsLog(debugLog, `clamp ${lastSwappingKey.current} to grid`);
|
|
92
97
|
const draggingItemSize = sizeMap.current[sortingKey];
|
|
93
98
|
if (null !== lastSwappingKey.current) {
|
|
94
|
-
const
|
|
95
|
-
Math.abs(swappingItemTranslation.current) > draggingItemSize * swapConfirmedPercentage.current ? setTransform(
|
|
99
|
+
const lastSwappingItemKey = lastSwappingKey.current;
|
|
100
|
+
Math.abs(swappingItemTranslation.current) > draggingItemSize * swapConfirmedPercentage.current ? setTransform(lastSwappingItemKey, (movingDistance < 0 ? 1 : -1) * draggingItemSize) : setTransform(lastSwappingItemKey, 0);
|
|
96
101
|
}
|
|
97
102
|
};
|
|
98
103
|
const updateLastSwappingItem = (movingDistance, sortingKey, swappingKey)=>{
|
|
@@ -128,14 +133,13 @@ function useSortable(useSortableOptions) {
|
|
|
128
133
|
mtsLog(debugLog, 'swappingIndexAndDistance', swappingIndex, consumedDistance);
|
|
129
134
|
if (swappingIndex < 0) return void clampPreviousItem(consumedDistance, sortingKey);
|
|
130
135
|
const swappingKey = keyArray[swappingIndex];
|
|
131
|
-
const swappingItem = itemMTSRefMap.current[swappingKey];
|
|
132
136
|
if (swappingKey !== lastSwappingKey.current) {
|
|
133
137
|
updateLastSwappingItem(movingDistance, sortingKey, swappingKey);
|
|
134
138
|
changedKey.current.push(swappingKey);
|
|
135
139
|
}
|
|
136
140
|
const unconsumedDistance = movingDistance - consumedDistance;
|
|
137
141
|
updateConfirmedInteractedID(unconsumedDistance, sortingKey);
|
|
138
|
-
setTransform(
|
|
142
|
+
setTransform(swappingKey, -unconsumedDistance);
|
|
139
143
|
}, [
|
|
140
144
|
changedKey,
|
|
141
145
|
itemMTSRefMap,
|
|
@@ -171,20 +175,32 @@ function useSortable(useSortableOptions) {
|
|
|
171
175
|
keyArray,
|
|
172
176
|
lastSwappedKey
|
|
173
177
|
]);
|
|
174
|
-
const
|
|
178
|
+
const resetSwapTrackingRefs = useCallback(()=>{
|
|
175
179
|
'main thread';
|
|
176
|
-
changedKey.current.map((key)=>{
|
|
177
|
-
const item = itemMTSRefMap?.current?.[key];
|
|
178
|
-
if (item && 'function' == typeof item.MTSResetInternalTranslateValues) item?.MTSResetInternalTranslateValues();
|
|
179
|
-
});
|
|
180
180
|
lastSwappedKey.current = '';
|
|
181
181
|
lastSwappingKey.current = '';
|
|
182
|
+
swappingItemTranslation.current = 0;
|
|
182
183
|
changedKey.current = [];
|
|
183
184
|
}, [
|
|
184
185
|
changedKey,
|
|
185
|
-
itemMTSRefMap,
|
|
186
186
|
lastSwappedKey,
|
|
187
|
-
lastSwappingKey
|
|
187
|
+
lastSwappingKey,
|
|
188
|
+
swappingItemTranslation
|
|
189
|
+
]);
|
|
190
|
+
const resetStatus = useCallback((draggingKey)=>{
|
|
191
|
+
'main thread';
|
|
192
|
+
changedKey.current.map((key)=>{
|
|
193
|
+
if (key === draggingKey) return;
|
|
194
|
+
const item = itemMTSRefMap?.current?.[key];
|
|
195
|
+
if (!item) return;
|
|
196
|
+
if ('function' == typeof item.MTSSetTransform) item.MTSSetTransform(0, 0);
|
|
197
|
+
if ('function' == typeof item.MTSResetInternalTranslateValues) item.MTSResetInternalTranslateValues();
|
|
198
|
+
});
|
|
199
|
+
resetSwapTrackingRefs();
|
|
200
|
+
}, [
|
|
201
|
+
changedKey,
|
|
202
|
+
itemMTSRefMap,
|
|
203
|
+
resetSwapTrackingRefs
|
|
188
204
|
]);
|
|
189
205
|
const rootDragEnd = useCallback((sortedKey)=>{
|
|
190
206
|
const keyToItemMap = new Map(data.map((item, index)=>[
|
|
@@ -202,10 +218,25 @@ function useSortable(useSortableOptions) {
|
|
|
202
218
|
'main thread';
|
|
203
219
|
mtsLog(debugLog, '[event drag end]', event);
|
|
204
220
|
const sortedKey = sortArray(sortingKey);
|
|
205
|
-
|
|
206
|
-
|
|
221
|
+
let orderChanged = sortedKey.length !== keyArray.length;
|
|
222
|
+
if (!orderChanged) {
|
|
223
|
+
for(let i = 0; i < sortedKey.length; i++)if (sortedKey[i] !== keyArray[i]) {
|
|
224
|
+
orderChanged = true;
|
|
225
|
+
break;
|
|
226
|
+
}
|
|
227
|
+
}
|
|
228
|
+
if (orderChanged) {
|
|
229
|
+
runOnBackground(rootDragEnd)(sortedKey);
|
|
230
|
+
resetSwapTrackingRefs();
|
|
231
|
+
} else {
|
|
232
|
+
resetStatus(sortingKey);
|
|
233
|
+
runOnBackground(rootDragEnd)(sortedKey);
|
|
234
|
+
}
|
|
235
|
+
return orderChanged;
|
|
207
236
|
}, [
|
|
237
|
+
keyArray,
|
|
208
238
|
resetStatus,
|
|
239
|
+
resetSwapTrackingRefs,
|
|
209
240
|
rootDragEnd,
|
|
210
241
|
sortArray
|
|
211
242
|
]);
|
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<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 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 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,kBAA0C;IAE1C,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,iB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,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"}
|
|
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<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 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 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 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 } = 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 (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 setTransform(\n lastSwappingItemKey,\n (movingDistance < 0 ? 1 : -1) * draggingItemSize,\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 { 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\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(swappingKey, -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 resetSwapTrackingRefs = useCallback(() => {\n 'main thread'\n lastSwappedKey.current = ''\n lastSwappingKey.current = ''\n swappingItemTranslation.current = 0\n changedKey.current = []\n }, [changedKey, lastSwappedKey, lastSwappingKey, swappingItemTranslation])\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","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","key","translate","clampPreviousItem","draggingItemSize","lastSwappingItemKey","updateLastSwappingItem","swappingKey","updateConfirmedInteractedID","unconsumedDistance","swappingIndex","draggedItemIndex","indexModifier","newSwappedKeyIndex","newSwappedKey","switchHandler","consumedDistance","handleDragMove","delta","sortArray","draggingIndex","swappedIndex","swappedKeyArray","draggedItem","resetSwapTrackingRefs","resetStatus","draggingKey","rootDragEnd","sortedKey","keyToItemMap","Map","sortedData","handleDragEnd","orderChanged","i"],"mappings":";;AA8BO,SAASA,YACdC,kBAA0C;IAE1C,MAAM,EACJC,IAAI,EACJC,OAAO,EACPC,aAAa,EACbC,YAAY,EACZC,SAAS,EACTC,WAAW,EACXC,WAAW,KAAK,EACjB,GAAGP;IAEJ,MAAMQ,WAAWC,MAAM,OAAO,CAACR,QAAQA,OAAO,EAAE;IAChD,MAAMS,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;QACp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