@os-design/drag-sort 1.0.0 → 1.0.4

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.
@@ -29,6 +29,8 @@ var _useGeneratedId = _interopRequireDefault(require("./utils/useGeneratedId"));
29
29
 
30
30
  var _useTransitionStyle = _interopRequireDefault(require("./utils/useTransitionStyle"));
31
31
 
32
+ var _useInitRect = _interopRequireDefault(require("./utils/useInitRect"));
33
+
32
34
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
33
35
 
34
36
  function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function _getRequireWildcardCache(nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
@@ -171,6 +173,7 @@ var DragAndDrop = function DragAndDrop(_ref) {
171
173
  distPercent: autoScrollDistPercent,
172
174
  maxSpeedPx: autoScrollMaxSpeedPx
173
175
  });
176
+ var initRect = (0, _useInitRect["default"])(draggedNode ? draggedNode.node[2] : undefined);
174
177
  var dragAndDropContext = (0, _useMemoObject["default"])({
175
178
  registerList: registerList,
176
179
  deregisterList: deregisterList,
@@ -187,7 +190,10 @@ var DragAndDrop = function DragAndDrop(_ref) {
187
190
  style: {
188
191
  position: 'fixed',
189
192
  left: cursorPosition.x - draggedNode.position.x,
190
- top: cursorPosition.y - draggedNode.position.y
193
+ top: cursorPosition.y - draggedNode.position.y,
194
+ width: initRect ? initRect.initWidth : undefined,
195
+ height: initRect ? initRect.initHeight : undefined,
196
+ zIndex: 1001
191
197
  }
192
198
  })));
193
199
  };
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/DragAndDrop.tsx"],"names":["DragAndDrop","draggedNodeContainer","minMouseDistPx","longPressMs","autoScrollDistPercent","autoScrollMaxSpeedPx","transitionDelayMs","onDragEnd","children","listStoreRef","ListStore","generatedId","nodeClassName","draggedNode","setDraggedNode","startNodeRef","x","y","cursorPosition","setCursorPosition","registerList","list","current","add","deregisterList","id","remove","className","ms","enabled","onDragStart","pos","startPos","startNode","node","nodeRef","rect","getBoundingClientRect","position","onDragMove","dragEndHandler","onMouseDown","onTouchStart","mouseDownHandler","e","touchStartHandler","document","body","distPercent","maxSpeedPx","dragAndDropContext","renderDraggedNode","index","style","left","top"],"mappings":";;;;;;;;;AAAA;;AAQA;;AACA;;AACA;;AAMA;;AACA;;AACA;;AACA;;AAEA;;AAIA;;AACA;;;;;;;;;;;;;;;;;;;;AA6CA;AACA;AACA;AACA,IAAMA,WAAuC,GAAG,SAA1CA,WAA0C,OAS1C;AAAA,MARJC,oBAQI,QARJA,oBAQI;AAAA,iCAPJC,cAOI;AAAA,MAPJA,cAOI,oCAPa,EAOb;AAAA,8BANJC,WAMI;AAAA,MANJA,WAMI,iCANU,GAMV;AAAA,mCALJC,qBAKI;AAAA,MALJA,qBAKI,sCALoB,EAKpB;AAAA,mCAJJC,oBAII;AAAA,MAJJA,oBAII,sCAJmB,GAInB;AAAA,mCAHJC,iBAGI;AAAA,MAHJA,iBAGI,sCAHgB,GAGhB;AAAA,4BAFJC,SAEI;AAAA,MAFJA,SAEI,+BAFQ,YAAM,CAAE,CAEhB;AAAA,MADJC,QACI,QADJA,QACI;AACJ;AACA;AACA,MAAMC,YAAY,GAAG,mBAAkB,IAAIC,qBAAJ,EAAlB,CAArB,CAHI,CAKJ;;AACA,MAAMC,WAAW,GAAG,gCAAe,CAAf,CAApB;AACA,MAAMC,aAAa,GAAG,oBAAQ;AAAA,sBAAUD,WAAV;AAAA,GAAR,EAAiC,CAACA,WAAD,CAAjC,CAAtB,CAPI,CASJ;;AACA,kBAAsC,qBAA6B,IAA7B,CAAtC;AAAA;AAAA,MAAOE,WAAP;AAAA,MAAoBC,cAApB;;AACA,MAAMC,YAAY,GAAG,mBAAyB,IAAzB,CAArB;;AACA,mBAA4C,qBAAmB;AAC7DC,IAAAA,C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W","sourcesContent":["import React, {\n useCallback,\n useMemo,\n useRef,\n useState,\n MouseEvent,\n TouchEvent,\n} from 'react';\nimport usePreventDefaultEvent from '@os-design/use-prevent-default-event';\nimport useMemoObject from '@os-design/use-memo-object';\nimport useDrag, {\n Position,\n OnDragEnd,\n OnDragMove,\n OnDragStart,\n} from '@os-design/use-drag';\nimport Portal, { PortalProps } from '@os-design/portal';\nimport useAutoScroll from '@os-design/use-auto-scroll';\nimport { DragAndDropContext } from './utils/useDragAndDrop';\nimport ListStore from './utils/ListStore';\nimport NodeList, { ExistingNode } from './utils/NodeList';\nimport useDragEffect, {\n DragEndHandler,\n DraggedNode,\n} from './utils/useDragEffect';\nimport useGeneratedId from './utils/useGeneratedId';\nimport useTransitionStyle from './utils/useTransitionStyle';\n\nexport interface DragAndDropProps {\n /**\n * The container in which the dragged node will be rendered.\n * @default document.body\n */\n draggedNodeContainer?: PortalProps['container'];\n /**\n * The min distance required to start dragging a node (in px).\n * @default 10\n */\n minMouseDistPx?: number;\n /**\n * The delay of the long press event required to start dragging a node on the touch device (in ms).\n * @default 500\n */\n longPressMs?: number;\n /**\n * The distance to the bound at which the list starts to scroll automatically (in percent).\n * @default 20\n */\n autoScrollDistPercent?: number;\n /**\n * The max auto scroll speed (in px).\n * @default 100\n */\n autoScrollMaxSpeedPx?: number;\n /**\n * The animation duration (in ms).\n * @default 250\n */\n transitionDelayMs?: number;\n /**\n * The callback that is called when the drag is completed.\n * @default undefined\n */\n onDragEnd?: DragEndHandler;\n}\n\ninterface StartNode {\n list: NodeList;\n node: ExistingNode;\n}\n\n/**\n * The container containing one or more lists with draggable nodes.\n */\nconst DragAndDrop: React.FC<DragAndDropProps> = ({\n draggedNodeContainer,\n minMouseDistPx = 10,\n longPressMs = 500,\n autoScrollDistPercent = 20,\n autoScrollMaxSpeedPx = 100,\n transitionDelayMs = 250,\n onDragEnd = () => {},\n children,\n}) => {\n // The user can drag a node between the lists (the Droppable components).\n // To determine which list a node should be dropped in, we need to store refs to all the lists.\n const listStoreRef = useRef<ListStore>(new ListStore());\n\n // The class name for a node used to set the transition style\n const generatedId = useGeneratedId(4);\n const nodeClassName = useMemo(() => `n${generatedId}`, [generatedId]);\n\n // The node that is currently being dragged\n const [draggedNode, setDraggedNode] = useState<DraggedNode | null>(null);\n const startNodeRef = useRef<StartNode | null>(null);\n const [cursorPosition, setCursorPosition] = useState<Position>({\n x: 0,\n y: 0,\n });\n\n // Add a new list to the store\n const registerList = useCallback((list: NodeList) => {\n listStoreRef.current.add(list);\n }, []);\n\n // Remove the existing list from the store\n const deregisterList = useCallback((id: string) => {\n listStoreRef.current.remove(id);\n }, []);\n\n // Set the style to delay transitions when the node is dragging\n useTransitionStyle({\n className: nodeClassName,\n ms: transitionDelayMs,\n enabled: !!draggedNode,\n });\n\n const onDragStart = useCallback<OnDragStart>(\n (pos: Position, startPos: Position) => {\n const startNode = startNodeRef.current;\n if (!startNode) return;\n const [, , nodeRef] = startNode.node;\n if (!nodeRef.current) return;\n const rect = nodeRef.current.getBoundingClientRect();\n setCursorPosition(pos);\n setDraggedNode({\n list: startNode.list,\n node: startNode.node,\n position: {\n x: startPos.x - rect.x,\n y: startPos.y - rect.y,\n },\n });\n startNodeRef.current = null;\n },\n []\n );\n\n const onDragMove = useCallback<OnDragMove>((pos: Position) => {\n setCursorPosition(pos);\n }, []);\n\n const dragEndHandler = useCallback<OnDragEnd>(() => {\n setDraggedNode(null);\n }, []);\n\n const { onMouseDown, onTouchStart } = useDrag({\n onDragStart,\n onDragMove,\n onDragEnd: dragEndHandler,\n minMouseDistPx,\n longPressMs,\n });\n\n // Handlers that determine whether a user clicks on the node\n const mouseDownHandler = useCallback(\n (e: MouseEvent, list: NodeList, node: ExistingNode) => {\n startNodeRef.current = { list, node };\n onMouseDown(e);\n },\n [onMouseDown]\n );\n const touchStartHandler = useCallback(\n (e: TouchEvent, list: NodeList, node: ExistingNode) => {\n startNodeRef.current = { list, node };\n onTouchStart(e);\n },\n [onTouchStart]\n );\n\n // Prevent body scrolling when the node is dragging.\n // It's important to attach the event to the body (not to the document). Otherwise, it won't work in mobile chrome.\n usePreventDefaultEvent(document.body, 'touchmove', !!draggedNode);\n\n // Implement the drag animation\n useDragEffect({\n draggedNode,\n cursorPosition,\n listStoreRef,\n onDragEnd,\n });\n\n // Auto scroll if the cursor position is located near the border\n useAutoScroll({\n enabled: !!draggedNode,\n distPercent: autoScrollDistPercent,\n maxSpeedPx: autoScrollMaxSpeedPx,\n });\n\n const dragAndDropContext = useMemoObject({\n registerList,\n deregisterList,\n onMouseDown: mouseDownHandler,\n onTouchStart: touchStartHandler,\n nodeClassName,\n });\n\n return (\n <DragAndDropContext.Provider value={dragAndDropContext}>\n {children}\n\n {draggedNode && (\n <Portal container={draggedNodeContainer}>\n {draggedNode.list.renderDraggedNode({\n index: draggedNode.node[4],\n style: {\n position: 'fixed',\n left: cursorPosition.x - draggedNode.position.x,\n top: cursorPosition.y - draggedNode.position.y,\n },\n })}\n </Portal>\n )}\n </DragAndDropContext.Provider>\n );\n};\n\nexport type { DragEndHandler } from './utils/useDragEffect';\n\nexport default DragAndDrop;\n"],"file":"DragAndDrop.js"}
1
+ {"version":3,"sources":["../../src/DragAndDrop.tsx"],"names":["DragAndDrop","draggedNodeContainer","minMouseDistPx","longPressMs","autoScrollDistPercent","autoScrollMaxSpeedPx","transitionDelayMs","onDragEnd","children","listStoreRef","ListStore","generatedId","nodeClassName","draggedNode","setDraggedNode","startNodeRef","x","y","cursorPosition","setCursorPosition","registerList","list","current","add","deregisterList","id","remove","className","ms","enabled","onDragStart","pos","startPos","startNode","node","nodeRef","rect","getBoundingClientRect","position","onDragMove","dragEndHandler","onMouseDown","onTouchStart","mouseDownHandler","e","touchStartHandler","document","body","distPercent","maxSpeedPx","initRect","undefined","dragAndDropContext","renderDraggedNode","index","style","left","top","width","initWidth","height","initHeight","zIndex"],"mappings":";;;;;;;;;AAAA;;AAQA;;AACA;;AACA;;AAMA;;AACA;;AACA;;AACA;;AAEA;;AAIA;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,\n useMemo,\n useRef,\n useState,\n MouseEvent,\n TouchEvent,\n} from 'react';\nimport usePreventDefaultEvent from '@os-design/use-prevent-default-event';\nimport useMemoObject from '@os-design/use-memo-object';\nimport useDrag, {\n Position,\n OnDragEnd,\n OnDragMove,\n OnDragStart,\n} from '@os-design/use-drag';\nimport Portal, { PortalProps } from '@os-design/portal';\nimport useAutoScroll from '@os-design/use-auto-scroll';\nimport { DragAndDropContext } from './utils/useDragAndDrop';\nimport ListStore from './utils/ListStore';\nimport NodeList, { ExistingNode } from './utils/NodeList';\nimport useDragEffect, {\n DragEndHandler,\n DraggedNode,\n} from './utils/useDragEffect';\nimport useGeneratedId from './utils/useGeneratedId';\nimport useTransitionStyle from './utils/useTransitionStyle';\nimport useInitRect from './utils/useInitRect';\n\nexport interface DragAndDropProps {\n /**\n * The container in which the dragged node will be rendered.\n * @default document.body\n */\n draggedNodeContainer?: PortalProps['container'];\n /**\n * The min distance required to start dragging a node (in px).\n * @default 10\n */\n minMouseDistPx?: number;\n /**\n * The delay of the long press event required to start dragging a node on the touch device (in ms).\n * @default 500\n */\n longPressMs?: number;\n /**\n * The distance to the bound at which the list starts to scroll automatically (in percent).\n * @default 20\n */\n autoScrollDistPercent?: number;\n /**\n * The max auto scroll speed (in px).\n * @default 100\n */\n autoScrollMaxSpeedPx?: number;\n /**\n * The animation duration (in ms).\n * @default 250\n */\n transitionDelayMs?: number;\n /**\n * The callback that is called when the drag is completed.\n * @default undefined\n */\n onDragEnd?: DragEndHandler;\n}\n\ninterface StartNode {\n list: NodeList;\n node: ExistingNode;\n}\n\n/**\n * The container containing one or more lists with draggable nodes.\n */\nconst DragAndDrop: React.FC<DragAndDropProps> = ({\n draggedNodeContainer,\n minMouseDistPx = 10,\n longPressMs = 500,\n autoScrollDistPercent = 20,\n autoScrollMaxSpeedPx = 100,\n transitionDelayMs = 250,\n onDragEnd = () => {},\n children,\n}) => {\n // The user can drag a node between the lists (the Droppable components).\n // To determine which list a node should be dropped in, we need to store refs to all the lists.\n const listStoreRef = useRef<ListStore>(new ListStore());\n\n // The class name for a node used to set the transition style\n const generatedId = useGeneratedId(4);\n const nodeClassName = useMemo(() => `n${generatedId}`, [generatedId]);\n\n // The node that is currently being dragged\n const [draggedNode, setDraggedNode] = useState<DraggedNode | null>(null);\n const startNodeRef = useRef<StartNode | null>(null);\n const [cursorPosition, setCursorPosition] = useState<Position>({\n x: 0,\n y: 0,\n });\n\n // Add a new list to the store\n const registerList = useCallback((list: NodeList) => {\n listStoreRef.current.add(list);\n }, []);\n\n // Remove the existing list from the store\n const deregisterList = useCallback((id: string) => {\n listStoreRef.current.remove(id);\n }, []);\n\n // Set the style to delay transitions when the node is dragging\n useTransitionStyle({\n className: nodeClassName,\n ms: transitionDelayMs,\n enabled: !!draggedNode,\n });\n\n const onDragStart = useCallback<OnDragStart>(\n (pos: Position, startPos: Position) => {\n const startNode = startNodeRef.current;\n if (!startNode) return;\n const [, , nodeRef] = startNode.node;\n if (!nodeRef.current) return;\n const rect = nodeRef.current.getBoundingClientRect();\n setCursorPosition(pos);\n setDraggedNode({\n list: startNode.list,\n node: startNode.node,\n position: {\n x: startPos.x - rect.x,\n y: startPos.y - rect.y,\n },\n });\n startNodeRef.current = null;\n },\n []\n );\n\n const onDragMove = useCallback<OnDragMove>((pos: Position) => {\n setCursorPosition(pos);\n }, []);\n\n const dragEndHandler = useCallback<OnDragEnd>(() => {\n setDraggedNode(null);\n }, []);\n\n const { onMouseDown, onTouchStart } = useDrag({\n onDragStart,\n onDragMove,\n onDragEnd: dragEndHandler,\n minMouseDistPx,\n longPressMs,\n });\n\n // Handlers that determine whether a user clicks on the node\n const mouseDownHandler = useCallback(\n (e: MouseEvent, list: NodeList, node: ExistingNode) => {\n startNodeRef.current = { list, node };\n onMouseDown(e);\n },\n [onMouseDown]\n );\n const touchStartHandler = useCallback(\n (e: TouchEvent, list: NodeList, node: ExistingNode) => {\n startNodeRef.current = { list, node };\n onTouchStart(e);\n },\n [onTouchStart]\n );\n\n // Prevent body scrolling when the node is dragging.\n // It's important to attach the event to the body (not to the document). Otherwise, it won't work in mobile chrome.\n usePreventDefaultEvent(document.body, 'touchmove', !!draggedNode);\n\n // Implement the drag animation\n useDragEffect({\n draggedNode,\n cursorPosition,\n listStoreRef,\n onDragEnd,\n });\n\n // Auto scroll if the cursor position is located near the border\n useAutoScroll({\n enabled: !!draggedNode,\n distPercent: autoScrollDistPercent,\n maxSpeedPx: autoScrollMaxSpeedPx,\n });\n\n const initRect = useInitRect(draggedNode ? draggedNode.node[2] : undefined);\n\n const dragAndDropContext = useMemoObject({\n registerList,\n deregisterList,\n onMouseDown: mouseDownHandler,\n onTouchStart: touchStartHandler,\n nodeClassName,\n });\n\n return (\n <DragAndDropContext.Provider value={dragAndDropContext}>\n {children}\n\n {draggedNode && (\n <Portal container={draggedNodeContainer}>\n {draggedNode.list.renderDraggedNode({\n index: draggedNode.node[4],\n style: {\n position: 'fixed',\n left: cursorPosition.x - draggedNode.position.x,\n top: cursorPosition.y - draggedNode.position.y,\n width: initRect ? initRect.initWidth : undefined,\n height: initRect ? initRect.initHeight : undefined,\n zIndex: 1001,\n },\n })}\n </Portal>\n )}\n </DragAndDropContext.Provider>\n );\n};\n\nexport type { DragEndHandler } from './utils/useDragEffect';\n\nexport default DragAndDrop;\n"],"file":"DragAndDrop.js"}
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/Draggable.tsx"],"names":["Draggable","index","children","ref","nodeRef","style","setStyle","nodeClassName","registerNode","deregisterNode","onMouseDown","onTouchStart","current","mouseDownHandler","e","touchStartHandler","handlers"],"mappings":";;;;;;;;;AAAA;;AAUA;;AAEA;;AACA;;AACA;;;;;;;;;;;;;;;;;;;;AAuCA,IAAMA,SAAmC,GAAG,SAAtCA,SAAsC,OAAyB;AAAA,MAAtBC,KAAsB,QAAtBA,KAAsB;AAAA,MAAfC,QAAe,QAAfA,QAAe;AACnE;AACA,MAAMC,GAAG,GAAG,mBAA8B,IAA9B,CAAZ,CAFmE,CAGn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O,CAACQ,OAAZ,CAAZ;AACD,GAJuB,EAKxB,CAACD,YAAD,CALwB,CAA1B;AAQA,MAAMK,QAAQ,GAAG,+BAAc;AAC7BN,IAAAA,WAAW,EAAEG,gBADgB;AAE7BF,IAAAA,YAAY,EAAEI;AAFe,GAAd,CAAjB;AAKA,sBAAO,kEAAGb,QAAQ,CAAC;AAAEC,IAAAA,GAAG,EAAHA,GAAF;AAAOE,IAAAA,KAAK,EAALA,KAAP;AAAcW,IAAAA,QAAQ,EAARA;AAAd,GAAD,CAAX,CAAP;AACD,CA/CD;;eAiDehB,S","sourcesContent":["import React, {\n CSSProperties,\n RefObject,\n useCallback,\n useEffect,\n useRef,\n useState,\n MouseEvent,\n TouchEvent,\n} from 'react';\nimport useMemoObject from '@os-design/use-memo-object';\nimport { Node } from './utils/NodeList';\nimport useDroppable from './utils/useDroppable';\nimport useDragAndDrop from './utils/useDragAndDrop';\nimport useAppendClassName from './utils/useAppendClassName';\n\nexport interface DraggableHandlers {\n /**\n * The handler that should be called when the mouse down event occurs.\n */\n onMouseDown: (e: MouseEvent) => void;\n /**\n * The handler that should be called when the touch start event occurs.\n */\n onTouchStart: (e: TouchEvent) => void;\n}\n\nexport interface DraggableChildrenProps {\n /**\n * The reference to the draggable list item.\n */\n ref: RefObject<HTMLDivElement>;\n /**\n * Additional styles for moving the list item.\n */\n style: CSSProperties;\n /**\n * The handlers to catch events when the user starts dragging the list item.\n */\n handlers: DraggableHandlers;\n}\n\nexport interface DraggableProps {\n /**\n * The index of the draggable node.\n */\n index: number;\n /**\n * The function that renders the draggable node.\n */\n children: (props: DraggableChildrenProps) => React.ReactNode;\n}\n\nconst Draggable: React.FC<DraggableProps> = ({ index, children }) => {\n // The reference to the list item\n const ref = useRef<HTMLDivElement | null>(null);\n // The reference to the node containing the refs to the prev and next nodes\n const nodeRef = useRef<Node>(null);\n // Additional styles for moving the list item\n const [style, setStyle] = useState<CSSProperties>({});\n\n const { nodeClassName } = useDragAndDrop();\n const { registerNode, deregisterNode, onMouseDown, onTouchStart } =\n useDroppable();\n\n // Register the node in the list\n useEffect(() => {\n nodeRef.current = registerNode({ ref, setStyle, index });\n return () => {\n if (!nodeRef.current) return;\n deregisterNode(nodeRef.current);\n nodeRef.current = null;\n };\n }, [deregisterNode, index, registerNode]);\n\n // Set the class name for the node to apply the transition style (see the DragAndDrop container)\n useAppendClassName(ref, nodeClassName);\n\n // Handlers that determine whether a user clicks on the node\n const mouseDownHandler = useCallback(\n (e: MouseEvent) => {\n if (!nodeRef.current) return;\n onMouseDown(e, nodeRef.current);\n },\n [onMouseDown]\n );\n const touchStartHandler = useCallback(\n (e: TouchEvent) => {\n if (!nodeRef.current) return;\n onTouchStart(e, nodeRef.current);\n },\n [onTouchStart]\n );\n\n const handlers = useMemoObject({\n onMouseDown: mouseDownHandler,\n onTouchStart: touchStartHandler,\n });\n\n return <>{children({ ref, style, handlers })}</>;\n};\n\nexport default Draggable;\n"],"file":"Draggable.js"}
1
+ {"version":3,"sources":["../../src/Draggable.tsx"],"names":["Draggable","index","children","ref","nodeRef","style","setStyle","nodeClassName","registerNode","deregisterNode","onMouseDown","onTouchStart","current","mouseDownHandler","e","touchStartHandler","handlers"],"mappings":";;;;;;;;;AAAA;;AAUA;;AAEA;;AACA;;AACA;;;;;;;;;;;;;;;;;;;;AAuCA,IAAMA,SAAmC,GAAG,SAAtCA,SAAsC,OAAyB;AAAA,MAAtBC,KAAsB,QAAtBA,KAAsB;AAAA,MAAfC,QAAe,QAAfA,QAAe;AACnE;AACA,MAAMC,GAAG,GAAG,mBAA8B,IAA9B,CAAZ,CAFmE,CAGnE;;AACA,MAAMC,OAAO,GAAG,mBAAa,IAAb,CAAhB,CAJmE,CAKnE;;AACA,kBAA0B,qBAAwB,EAAxB,CAA1B;AAAA;AAAA,MAAOC,KAAP;AAAA,MAAcC,QAAd;;AAEA,wBAA0B,kCAA1B;AAAA,MAAQC,aAAR,mBAAQA,aAAR;;AACA,sBACE,gCADF;AAAA,MAAQC,YAA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AAG,EAAHA,GAAF;AAAOE,IAAAA,KAAK,EAALA,KAAP;AAAcW,IAAAA,QAAQ,EAARA;AAAd,GAAD,CAAX,CAAP;AACD,CA/CD;;eAiDehB,S","sourcesContent":["import React, {\n CSSProperties,\n RefObject,\n useCallback,\n useEffect,\n useRef,\n useState,\n MouseEvent,\n TouchEvent,\n} from 'react';\nimport useMemoObject from '@os-design/use-memo-object';\nimport { Node } from './utils/NodeList';\nimport useDroppable from './utils/useDroppable';\nimport useDragAndDrop from './utils/useDragAndDrop';\nimport useAppendClassName from './utils/useAppendClassName';\n\nexport interface DraggableHandlers {\n /**\n * The handler that should be called when the mouse down event occurs.\n */\n onMouseDown: (e: MouseEvent) => void;\n /**\n * The handler that should be called when the touch start event occurs.\n */\n onTouchStart: (e: TouchEvent) => void;\n}\n\nexport interface DraggableChildrenProps {\n /**\n * The reference to the draggable list item.\n */\n ref: RefObject<any>; // eslint-disable-line @typescript-eslint/no-explicit-any\n /**\n * Additional styles for moving the list item.\n */\n style: CSSProperties;\n /**\n * The handlers to catch events when the user starts dragging the list item.\n */\n handlers: DraggableHandlers;\n}\n\nexport interface DraggableProps {\n /**\n * The index of the draggable node.\n */\n index: number;\n /**\n * The function that renders the draggable node.\n */\n children: (props: DraggableChildrenProps) => React.ReactNode;\n}\n\nconst Draggable: React.FC<DraggableProps> = ({ index, children }) => {\n // The reference to the list item\n const ref = useRef<HTMLDivElement | null>(null);\n // The reference to the node containing the refs to the prev and next nodes\n const nodeRef = useRef<Node>(null);\n // Additional styles for moving the list item\n const [style, setStyle] = useState<CSSProperties>({});\n\n const { nodeClassName } = useDragAndDrop();\n const { registerNode, deregisterNode, onMouseDown, onTouchStart } =\n useDroppable();\n\n // Register the node in the list\n useEffect(() => {\n nodeRef.current = registerNode({ ref, setStyle, index });\n return () => {\n if (!nodeRef.current) return;\n deregisterNode(nodeRef.current);\n nodeRef.current = null;\n };\n }, [deregisterNode, index, registerNode]);\n\n // Set the class name for the node to apply the transition style (see the DragAndDrop container)\n useAppendClassName(ref, nodeClassName);\n\n // Handlers that determine whether a user clicks on the node\n const mouseDownHandler = useCallback(\n (e: MouseEvent) => {\n if (!nodeRef.current) return;\n onMouseDown(e, nodeRef.current);\n },\n [onMouseDown]\n );\n const touchStartHandler = useCallback(\n (e: TouchEvent) => {\n if (!nodeRef.current) return;\n onTouchStart(e, nodeRef.current);\n },\n [onTouchStart]\n );\n\n const handlers = useMemoObject({\n onMouseDown: mouseDownHandler,\n onTouchStart: touchStartHandler,\n });\n\n return <>{children({ ref, style, handlers })}</>;\n};\n\nexport default Draggable;\n"],"file":"Draggable.js"}
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../src/utils/useBlankNode.ts"],"names":["useBlankNode","props","draggedNode","targetList","initDraggedNodeRect","initDraggedNodeRectRef","blankNode","current","ref","list","initWidth","initHeight","div","document","createElement","style","width","height","minWidth","minHeight","parent","innerList","innerRef","getBoundingClientRect","position","left","horizontal","top","appendChild","tail","getTail","node","add","setStyle","index","removeBlankNode","blank","remove","blankNodeRef","parentElement","removeChild"],"mappings":";;;;;;;AAAA;;;;;;;;;;;;;;AAqBA;AACA;AACA;AACA;AACA,IAAMA,YAAY,GAAG,SAAfA,YAAe,CAACC,KAAD,EAA8B;AACjD,MAAQC,WAAR,GAAyDD,KAAzD,CAAQC,WAAR;AAAA,MAAqBC,UAArB,GAAyDF,KAAzD,CAAqBE,UAArB;AAAA,MAAiCC,mBAAjC,GAAyDH,KAAzD,CAAiCG,mBAAjC;AACA,MAAMC,sBAAsB,GAAG,mBAAOD,mBAAP,CAA/B;AACA,MAAME,SAAS,GAAG,mBAAyB,IAAzB,CAAlB;AAEA,wBAAU,YAAM;AACdD,IAAAA,sBAAsB,CAACE,OAAvB,GAAiCH,mBAAjC;AACD,GAFD,EAEG,CAACA,mBAAD,CAFH;AAIA,wBAAU,YAAM;AACd,QACE,CAACF,WAAD,IACA,CAACC,UADD,IAEA,CAACA,UAAU,CAACK,GAAX,CAAeD,OAFhB,IAGAL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esContent":["import { useCallback, useEffect, useRef } from 'react';\nimport NodeList, { ExistingNode } from './NodeList';\n// eslint-disable-next-line import/no-cycle\nimport { DraggedNode } from './useDragEffect';\n\ninterface InitSize {\n initWidth: number;\n initHeight: number;\n}\n\ninterface UseBlankNodeProps {\n draggedNode: DraggedNode | null;\n targetList: NodeList | null;\n initDraggedNodeRect: InitSize | null;\n}\n\ninterface BlankNode {\n list: NodeList;\n node: ExistingNode;\n}\n\n/**\n * Appends the blank node to the list to increase the height of it.\n * Used when the dragged node is located inside another list.\n */\nconst useBlankNode = (props: UseBlankNodeProps) => {\n const { draggedNode, targetList, initDraggedNodeRect } = props;\n const initDraggedNodeRectRef = useRef(initDraggedNodeRect);\n const blankNode = useRef<BlankNode | null>(null);\n\n useEffect(() => {\n initDraggedNodeRectRef.current = initDraggedNodeRect;\n }, [initDraggedNodeRect]);\n\n useEffect(() => {\n if (\n !draggedNode ||\n !targetList ||\n !targetList.ref.current ||\n draggedNode.list === targetList ||\n !initDraggedNodeRectRef.current\n ) {\n return;\n }\n\n // Create a new blank div\n const { initWidth, initHeight } = initDraggedNodeRectRef.current;\n const div = document.createElement('div');\n div.style.width = `${initWidth}px`;\n div.style.height = `${initHeight}px`;\n div.style.minWidth = `${initWidth}px`;\n div.style.minHeight = `${initHeight}px`;\n\n let parent = targetList.ref.current;\n const innerList = targetList.innerRef.current;\n\n // The inner ref used only in the virtual list\n if (innerList) {\n const { width, height } = innerList.getBoundingClientRect();\n div.style.position = 'absolute';\n div.style.left = targetList.horizontal ? `${width}px` : '0px';\n div.style.top = targetList.horizontal ? '0px' : `${height}px`;\n parent = innerList;\n }\n\n // Append the blank div to increase the height of the list\n parent.appendChild(div);\n\n // Add the blank node to the node list\n const tail = targetList.getTail();\n blankNode.current = {\n list: targetList,\n node: targetList.add({\n ref: { current: div },\n setStyle: () => {},\n index: tail ? tail[4] + 1 : 0,\n }),\n };\n }, [draggedNode, targetList]);\n\n const removeBlankNode = useCallback(() => {\n const blank = blankNode.current;\n if (!blank) return;\n blankNode.current = null;\n blank.list.remove(blank.node);\n const [, , blankNodeRef] = blank.node;\n if (!blank.list.ref.current || !blankNodeRef.current) return;\n const parent = blankNodeRef.current.parentElement;\n if (parent) parent.removeChild(blankNodeRef.current);\n }, []);\n\n // Remove the blank node if the dragged node has been dropped\n useEffect(() => {\n if (!draggedNode) return () => {};\n return () => removeBlankNode();\n }, [draggedNode, removeBlankNode]);\n\n return removeBlankNode;\n};\n\nexport default useBlankNode;\n"],"file":"useBlankNode.js"}
1
+ {"version":3,"sources":["../../../src/utils/useBlankNode.ts"],"names":["useBlankNode","props","draggedNode","targetList","initDraggedNodeRect","initDraggedNodeRectRef","blankNode","current","ref","list","initWidth","initHeight","div","document","createElement","style","width","height","minWidth","minHeight","parent","innerList","innerRef","getBoundingClientRect","position","left","horizontal","top","appendChild","tail","getTail","node","add","setStyle","index","removeBlankNode","blank","remove","blankNodeRef","parentElement","removeChild"],"mappings":";;;;;;;AAAA;;;;;;;;;;;;;;AAuBA;AACA;AACA;AACA;AACA,IAAMA,YAAY,GAAG,SAAfA,YAAe,CAACC,KAAD,EAA8B;AACjD,MAAQC,WAAR,GAAyDD,KAAzD,CAAQC,WAAR;AAAA,MAAqBC,UAArB,GAAyDF,KAAzD,CAAqBE,UAArB;AAAA,MAAiCC,mBAAjC,GAAyDH,KAAzD,CAAiCG,mBAAjC;AACA,MAAMC,sBAAsB,GAAG,mBAAOD,mBAAP,CAA/B;AACA,MAAME,SAAS,GAAG,mBAAyB,IAAzB,CAAlB;AAEA,wBAAU,YAAM;AACdD,IAAAA,sBAAsB,CAACE,OAAvB,GAAiCH,mBAAjC;AACD,GAFD,EAEG,CAACA,mBAAD,CAFH;AAIA,wBAAU,YAAM;AACd,QACE,CAACF,WAAD,IACA,CAACC,UADD,IAEA,CAACA,UAAU,CAACK,GAAX,CAAeD,OAFhB,IAGAL,WAAW,CAACO,IAAZ,KAAqBN,UAHrB,IAIA,CAACE,sBAAsB,CAACE,OAL1B,E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AEN,UADY;AAElB4B,MAAAA,IAAI,EAAE5B,UAAU,CAAC6B,GAAX,CAAe;AACnBxB,QAAAA,GAAG,EAAE;AAAED,UAAAA,OAAO,EAAEK;AAAX,SADc;AAEnBqB,QAAAA,QAAQ,EAAE,oBAAM,CAAE,CAFC;AAGnBC,QAAAA,KAAK,EAAEL,IAAI,GAAGA,IAAI,CAAC,CAAD,CAAJ,GAAU,CAAb,GAAiB;AAHT,OAAf;AAFY,KAApB;AAQD,GA5CD,EA4CG,CAAC3B,WAAD,EAAcC,UAAd,CA5CH;AA8CA,MAAMgC,eAAe,GAAG,wBAAY,YAAM;AACxC,QAAMC,KAAK,GAAG9B,SAAS,CAACC,OAAxB;AACA,QAAI,CAAC6B,KAAL,EAAY;AACZ9B,IAAAA,SAAS,CAACC,OAAV,GAAoB,IAApB;AACA6B,IAAAA,KAAK,CAAC3B,IAAN,CAAW4B,MAAX,CAAkBD,KAAK,CAACL,IAAxB;;AACA,qCAA2BK,KAAK,CAACL,IAAjC;AAAA,QAAWO,YAAX;;AACA,QAAI,CAACF,KAAK,CAAC3B,IAAN,CAAWD,GAAX,CAAeD,OAAhB,IAA2B,CAAC+B,YAAY,CAAC/B,OAA7C,EAAsD;AACtD,QAAMa,MAAM,GAAGkB,YAAY,CAAC/B,OAAb,CAAqBgC,aAApC;AACA,QAAInB,MAAJ,EAAYA,MAAM,CAACoB,WAAP,CAAmBF,YAAY,CAAC/B,OAAhC;AACb,GATuB,EASrB,EATqB,CAAxB,CAvDiD,CAkEjD;;AACA,wBAAU,YAAM;AACd,QAAI,CAACL,WAAL,EAAkB,OAAO,YAAM,CAAE,CAAf;AAClB,WAAO;AAAA,aAAMiC,eAAe,EAArB;AAAA,KAAP;AACD,GAHD,EAGG,CAACjC,WAAD,EAAciC,eAAd,CAHH;AAKA,SAAOA,eAAP;AACD,CAzED;;eA2EenC,Y","sourcesContent":["import { useCallback, useEffect, useRef } from 'react';\nimport NodeList, { ExistingNode } from './NodeList';\n\ninterface InitSize {\n initWidth: number;\n initHeight: number;\n}\n\ninterface DraggedNode {\n list: NodeList;\n}\n\ninterface UseBlankNodeProps {\n draggedNode: DraggedNode | null;\n targetList: NodeList | null;\n initDraggedNodeRect: InitSize | null;\n}\n\ninterface BlankNode {\n list: NodeList;\n node: ExistingNode;\n}\n\n/**\n * Appends the blank node to the list to increase the height of it.\n * Used when the dragged node is located inside another list.\n */\nconst useBlankNode = (props: UseBlankNodeProps) => {\n const { draggedNode, targetList, initDraggedNodeRect } = props;\n const initDraggedNodeRectRef = useRef(initDraggedNodeRect);\n const blankNode = useRef<BlankNode | null>(null);\n\n useEffect(() => {\n initDraggedNodeRectRef.current = initDraggedNodeRect;\n }, [initDraggedNodeRect]);\n\n useEffect(() => {\n if (\n !draggedNode ||\n !targetList ||\n !targetList.ref.current ||\n draggedNode.list === targetList ||\n !initDraggedNodeRectRef.current\n ) {\n return;\n }\n\n // Create a new blank div\n const { initWidth, initHeight } = initDraggedNodeRectRef.current;\n const div = document.createElement('div');\n div.style.width = `${initWidth}px`;\n div.style.height = `${initHeight}px`;\n div.style.minWidth = `${initWidth}px`;\n div.style.minHeight = `${initHeight}px`;\n\n let parent = targetList.ref.current;\n const innerList = targetList.innerRef.current;\n\n // The inner ref used only in the virtual list\n if (innerList) {\n const { width, height } = innerList.getBoundingClientRect();\n div.style.position = 'absolute';\n div.style.left = targetList.horizontal ? `${width}px` : '0px';\n div.style.top = targetList.horizontal ? '0px' : `${height}px`;\n parent = innerList;\n }\n\n // Append the blank div to increase the height of the list\n parent.appendChild(div);\n\n // Add the blank node to the node list\n const tail = targetList.getTail();\n blankNode.current = {\n list: targetList,\n node: targetList.add({\n ref: { current: div },\n setStyle: () => {},\n index: tail ? tail[4] + 1 : 0,\n }),\n };\n }, [draggedNode, targetList]);\n\n const removeBlankNode = useCallback(() => {\n const blank = blankNode.current;\n if (!blank) return;\n blankNode.current = null;\n blank.list.remove(blank.node);\n const [, , blankNodeRef] = blank.node;\n if (!blank.list.ref.current || !blankNodeRef.current) return;\n const parent = blankNodeRef.current.parentElement;\n if (parent) parent.removeChild(blankNodeRef.current);\n }, []);\n\n // Remove the blank node if the dragged node has been dropped\n useEffect(() => {\n if (!draggedNode) return () => {};\n return () => removeBlankNode();\n }, [draggedNode, removeBlankNode]);\n\n return removeBlankNode;\n};\n\nexport default useBlankNode;\n"],"file":"useBlankNode.js"}
@@ -55,7 +55,7 @@ var createEmptyNode = function createEmptyNode(_ref) {
55
55
  current: null
56
56
  }, function () {}, -1];
57
57
  };
58
- /* eslint-disable @typescript-eslint/no-explicit-any,no-constant-condition */
58
+ /* eslint-disable no-constant-condition */
59
59
 
60
60
 
61
61
  var useDragEffect = function useDragEffect(props) {
@@ -74,11 +74,10 @@ var useDragEffect = function useDragEffect(props) {
74
74
  }, [onDragEnd]); // The initial bounds of the dragged node.
75
75
  // We can't read the bounds of the dragged node on the fly because the node can be unmounted in the virtual list.
76
76
 
77
- var initDraggedNodeRect = (0, _useInitRect["default"])(draggedNode === null || draggedNode === void 0 ? void 0 : draggedNode.node[2]); // The initial scroll position of the list where the dragged node is located.
78
- // Used to detect the actual position of the dragged node.
79
- // The purpose is the same as with initDraggedNodeRect.
77
+ var initDraggedNodeRect = (0, _useInitRect["default"])(draggedNode ? draggedNode.node[2] : undefined); // The initial scroll position of the list where the dragged node is located.
78
+ // Used to detect the actual position of the dragged node. The purpose is the same as with initDraggedNodeRect.
80
79
 
81
- var initDraggedNodeListScrollOffset = (0, _useInitScrollOffset["default"])(draggedNode === null || draggedNode === void 0 ? void 0 : draggedNode.list.ref); // The central position of the dragged node
80
+ var initDraggedNodeListScrollOffset = (0, _useInitScrollOffset["default"])(draggedNode ? draggedNode.list.ref : undefined); // The central position of the dragged node
82
81
 
83
82
  var position = (0, _react.useMemo)(function () {
84
83
  if (!draggedNode || !initDraggedNodeRect) return null;
@@ -90,12 +89,17 @@ var useDragEffect = function useDragEffect(props) {
90
89
  x: x - draggedNode.position.x + initWidth / 2,
91
90
  y: y - draggedNode.position.y + initHeight / 2
92
91
  };
93
- }, [cursorPosition, draggedNode, initDraggedNodeRect]); // Returns the style for moving the node in the specified direction
92
+ }, [cursorPosition, draggedNode, initDraggedNodeRect]); // The list in which the cursor is located
94
93
 
95
- var getNodeStyle = (0, _useGetNodeStyle["default"])(initDraggedNodeRect); // The list in which the cursor is located
94
+ var targetList = (0, _useTargetList["default"])(position, listStoreRef); // Returns the style for moving the node in the specified direction
96
95
 
97
- var targetList = (0, _useTargetList["default"])(position, listStoreRef);
98
- var moveNode = (0, _useMoveNode["default"])(position, draggedNode, getNodeStyle);
96
+ var getNodeStyle = (0, _useGetNodeStyle["default"])(initDraggedNodeRect); // Moves the node up or down
97
+
98
+ var moveNode = (0, _useMoveNode["default"])({
99
+ position: position,
100
+ draggedNode: draggedNode,
101
+ getNodeStyle: getNodeStyle
102
+ });
99
103
  var setTargetNode = (0, _react.useCallback)(function (list, node) {
100
104
  var _node = _slicedToArray(node, 5),
101
105
  nodeIndex = _node[4];
@@ -161,14 +165,14 @@ var useDragEffect = function useDragEffect(props) {
161
165
  var updateTargetNode = (0, _react.useCallback)(function () {
162
166
  if (!draggedNode) return;
163
167
  var prevTargetNode = targetNodeRef.current; // The last updated node
164
- // Dragging outside the list
168
+ // Dragging outside the origin list
165
169
 
166
170
  if (prevTargetNode && prevTargetNode.list === draggedNode.list && targetList !== draggedNode.list) {
167
171
  moveNode({
168
172
  list: prevTargetNode.list,
169
173
  startNode: prevTargetNode.node,
170
- type: 'down',
171
- untilTheEnd: true
174
+ direction: 'down',
175
+ destination: 'end'
172
176
  });
173
177
  clearTargetNode();
174
178
  } // Dragging outside another list
@@ -178,13 +182,13 @@ var useDragEffect = function useDragEffect(props) {
178
182
  moveNode({
179
183
  list: prevTargetNode.list,
180
184
  startNode: prevTargetNode.node,
181
- type: 'down',
182
- untilTheEnd: true,
183
- insideAnotherList: true
185
+ direction: 'down',
186
+ destination: 'end',
187
+ isAnotherList: true
184
188
  });
185
189
  removeBlankNode();
186
190
  clearTargetNode();
187
- } // Dragging inside the list
191
+ } // Dragging inside the origin list
188
192
 
189
193
 
190
194
  if (!prevTargetNode && targetList === draggedNode.list) {
@@ -193,14 +197,15 @@ var useDragEffect = function useDragEffect(props) {
193
197
  var node = moveNode({
194
198
  list: targetList,
195
199
  startNode: tail,
196
- type: 'up'
200
+ direction: 'up',
201
+ destination: 'cursor'
197
202
  });
198
203
  setTargetNode(targetList, node);
199
204
  return;
200
205
  } // Dragging inside another list
201
206
 
202
207
 
203
- if (targetList && targetList !== draggedNode.list && (prevTargetNode === null || prevTargetNode === void 0 ? void 0 : prevTargetNode.list) !== targetList) {
208
+ if (targetList && targetList !== draggedNode.list && (!prevTargetNode || prevTargetNode.list !== targetList)) {
204
209
  var _tail = targetList.getTail();
205
210
 
206
211
  if (!_tail) return;
@@ -208,13 +213,14 @@ var useDragEffect = function useDragEffect(props) {
208
213
  var _node2 = moveNode({
209
214
  list: targetList,
210
215
  startNode: _tail,
211
- type: 'up',
212
- insideAnotherList: true
216
+ direction: 'up',
217
+ destination: 'cursor',
218
+ isAnotherList: true
213
219
  });
214
220
 
215
221
  setTargetNode(targetList, _node2);
216
222
  return;
217
- } // Dragging in the same list
223
+ } // Dragging in the origin list
218
224
 
219
225
 
220
226
  if (prevTargetNode && prevTargetNode.list === draggedNode.list && targetList === draggedNode.list) {
@@ -242,7 +248,8 @@ var useDragEffect = function useDragEffect(props) {
242
248
  startNode: createEmptyNode({
243
249
  prev: _tail2
244
250
  }),
245
- type: 'up'
251
+ direction: 'up',
252
+ destination: 'cursor'
246
253
  });
247
254
 
248
255
  setTargetNode(targetList, _node4);
@@ -255,7 +262,8 @@ var useDragEffect = function useDragEffect(props) {
255
262
  startNode: createEmptyNode({
256
263
  next: head
257
264
  }),
258
- type: 'down'
265
+ direction: 'down',
266
+ destination: 'cursor'
259
267
  });
260
268
 
261
269
  setTargetNode(targetList, _node5);
@@ -265,18 +273,20 @@ var useDragEffect = function useDragEffect(props) {
265
273
  }
266
274
 
267
275
  var prevTargetNodeRect = (0, _getNodeRect["default"])(prevTargetNode.node[2]);
268
- var rectProp = targetList.horizontal ? 'left' : 'top';
276
+ var startRectProp = targetList.horizontal ? 'left' : 'top';
269
277
  if (!position || !prevTargetNodeRect) return;
270
- var isMoveUp = position[axis] < prevTargetNodeRect[rectProp];
278
+ var isMoveUp = position[axis] < prevTargetNodeRect[startRectProp];
271
279
 
272
280
  var _node3 = isMoveUp ? moveNode({
273
281
  list: targetList,
274
282
  startNode: prevTargetNode.node,
275
- type: 'up'
283
+ direction: 'up',
284
+ destination: 'cursor'
276
285
  }) : moveNode({
277
286
  list: targetList,
278
287
  startNode: prevTargetNode.node,
279
- type: 'down'
288
+ direction: 'down',
289
+ destination: 'cursor'
280
290
  });
281
291
 
282
292
  setTargetNode(targetList, _node3);
@@ -284,27 +294,29 @@ var useDragEffect = function useDragEffect(props) {
284
294
  } // Dragging in another list
285
295
 
286
296
 
287
- if (targetList && targetList !== draggedNode.list && (prevTargetNode === null || prevTargetNode === void 0 ? void 0 : prevTargetNode.list) === targetList) {
297
+ if (targetList && targetList !== draggedNode.list && prevTargetNode && prevTargetNode.list === targetList) {
288
298
  var _axis = targetList.horizontal ? 'x' : 'y';
289
299
 
290
300
  var _prevTargetNodeRect = (0, _getNodeRect["default"])(prevTargetNode.node[2]);
291
301
 
292
- var _rectProp = targetList.horizontal ? 'left' : 'top';
302
+ var _startRectProp = targetList.horizontal ? 'left' : 'top';
293
303
 
294
304
  if (!position || !_prevTargetNodeRect) return;
295
305
 
296
- var _isMoveUp = position[_axis] < _prevTargetNodeRect[_rectProp];
306
+ var _isMoveUp = position[_axis] < _prevTargetNodeRect[_startRectProp];
297
307
 
298
308
  var _node6 = _isMoveUp ? moveNode({
299
309
  list: targetList,
300
310
  startNode: prevTargetNode.node,
301
- type: 'up',
302
- insideAnotherList: true
311
+ direction: 'up',
312
+ destination: 'cursor',
313
+ isAnotherList: true
303
314
  }) : moveNode({
304
315
  list: targetList,
305
316
  startNode: prevTargetNode.node,
306
- type: 'down',
307
- insideAnotherList: true
317
+ direction: 'down',
318
+ destination: 'cursor',
319
+ isAnotherList: true
308
320
  });
309
321
 
310
322
  setTargetNode(targetList, _node6);
@@ -319,8 +331,8 @@ var useDragEffect = function useDragEffect(props) {
319
331
  _useThrottle2 = _slicedToArray(_useThrottle, 1),
320
332
  throttledUpdateTargetNode = _useThrottle2[0];
321
333
 
322
- (0, _useEvent["default"])(targetList === null || targetList === void 0 ? void 0 : targetList.ref, 'scroll', throttledUpdateTargetNode);
323
- (0, _useEvent["default"])(window, 'scroll', throttledUpdateTargetNode); // Reset styles of the nodes when the dragged node was dropped
334
+ (0, _useEvent["default"])(targetList ? targetList.ref : undefined, 'scroll', throttledUpdateTargetNode);
335
+ (0, _useEvent["default"])(window, 'scroll', throttledUpdateTargetNode); // Reset styles of the affected nodes when the dragged node was dropped
324
336
 
325
337
  (0, _react.useEffect)(function () {
326
338
  if (!draggedNode) return function () {};
@@ -329,94 +341,98 @@ var useDragEffect = function useDragEffect(props) {
329
341
  draggedNodeIndex = _draggedNode$node2[4];
330
342
 
331
343
  return function () {
332
- var targetNode = targetNodeRef.current; // If the dragged node was inside another list, reset the styles for the nodes,
333
- // starting at the tail and ending with the dragged node.
344
+ var targetNode = targetNodeRef.current; // If the dragged node was outside the origin list, reset the styles for the nodes,
345
+ // starting at the tail and ending with the dragged node in the origin list.
346
+
347
+ if (!targetNode || targetNode.list !== draggedNode.list) {
348
+ var tail = draggedNode.list.getTail();
349
+
350
+ if (tail) {
351
+ var node = tail;
352
+
353
+ while (true) {
354
+ var _node7 = node,
355
+ _node8 = _slicedToArray(_node7, 5),
356
+ prev = _node8[0],
357
+ nodeSetStyle = _node8[3],
358
+ nodeIndex = _node8[4];
359
+
360
+ nodeSetStyle({});
361
+ if (!prev || nodeIndex <= draggedNodeIndex) break;
362
+ node = prev;
363
+ }
364
+ }
365
+ } // If the dragged node was inside another list, reset the styles for the nodes,
366
+ // starting at the tail and ending with the dragged node in the target list.
367
+
334
368
 
335
369
  if (targetNode && targetNode.list !== draggedNode.list) {
336
370
  var _tail3 = targetNode.list.getTail();
337
371
 
338
- if (!_tail3) return;
339
- var node = _tail3;
340
-
341
- while (true) {
342
- var _node7 = node,
343
- _node8 = _slicedToArray(_node7, 5),
344
- prev = _node8[0],
345
- nodeSetStyle = _node8[3],
346
- nodeIndex = _node8[4];
347
-
348
- nodeSetStyle({});
349
- if (!prev || nodeIndex <= draggedNodeIndex) break;
350
- node = prev;
351
- }
352
- } // If the dragged node was outside the origin list, reset the styles for the nodes,
353
- // starting at the tail and ending with the dragged node.
354
-
355
-
356
- var tail = draggedNode.list.getTail();
372
+ var _targetNode$node = _slicedToArray(targetNode.node, 5),
373
+ targetNodeIndex = _targetNode$node[4];
357
374
 
358
- if ((targetNode === null || targetNode === void 0 ? void 0 : targetNode.list) !== draggedNode.list && tail) {
359
- var _node9 = tail;
375
+ if (_tail3) {
376
+ var _node9 = _tail3;
360
377
 
361
- while (true) {
362
- var _node10 = _node9,
363
- _node11 = _slicedToArray(_node10, 5),
364
- _prev = _node11[0],
365
- _nodeSetStyle = _node11[3],
366
- _nodeIndex = _node11[4];
378
+ while (true) {
379
+ var _node10 = _node9,
380
+ _node11 = _slicedToArray(_node10, 5),
381
+ _prev = _node11[0],
382
+ _nodeSetStyle = _node11[3],
383
+ _nodeIndex = _node11[4];
367
384
 
368
- _nodeSetStyle({});
385
+ _nodeSetStyle({});
369
386
 
370
- if (!_prev || _nodeIndex <= draggedNodeIndex) break;
371
- _node9 = _prev;
387
+ if (!_prev || _nodeIndex <= targetNodeIndex) break;
388
+ _node9 = _prev;
389
+ }
372
390
  }
373
- }
374
-
375
- if (!targetNode) return;
376
-
377
- var _targetNode$node = _slicedToArray(targetNode.node, 5),
378
- targetNodeSetStyle = _targetNode$node[3],
379
- targetNodeIndex = _targetNode$node[4];
380
-
381
- if (targetNodeIndex > draggedNodeIndex) {
382
- var _node12 = targetNode.node;
383
-
384
- while (true) {
385
- var _node13 = _node12,
386
- _node14 = _slicedToArray(_node13, 5),
387
- _prev2 = _node14[0],
388
- _nodeSetStyle2 = _node14[3],
389
- _nodeIndex2 = _node14[4];
390
-
391
- _nodeSetStyle2({});
392
-
393
- if (!_prev2 || _nodeIndex2 < draggedNodeIndex) return;
394
- _node12 = _prev2;
391
+ } // If the dragged node was moved inside the origin list, reset the styles for the nodes,
392
+ // starting with target node and ending with the dragged node.
393
+
394
+
395
+ if (targetNode && targetNode.list === draggedNode.list) {
396
+ var _targetNode$node2 = _slicedToArray(targetNode.node, 5),
397
+ targetNodeSetStyle = _targetNode$node2[3],
398
+ _targetNodeIndex = _targetNode$node2[4];
399
+
400
+ if (_targetNodeIndex > draggedNodeIndex) {
401
+ var _node12 = targetNode.node;
402
+
403
+ while (true) {
404
+ var _node13 = _node12,
405
+ _node14 = _slicedToArray(_node13, 5),
406
+ _prev2 = _node14[0],
407
+ _nodeSetStyle2 = _node14[3],
408
+ _nodeIndex2 = _node14[4];
409
+
410
+ _nodeSetStyle2({});
411
+
412
+ if (!_prev2 || _nodeIndex2 <= draggedNodeIndex) break;
413
+ _node12 = _prev2;
414
+ }
415
+ } else if (_targetNodeIndex < draggedNodeIndex) {
416
+ var _node15 = targetNode.node;
417
+
418
+ while (true) {
419
+ var _node16 = _node15,
420
+ _node17 = _slicedToArray(_node16, 5),
421
+ next = _node17[1],
422
+ _nodeSetStyle3 = _node17[3],
423
+ _nodeIndex3 = _node17[4];
424
+
425
+ _nodeSetStyle3({});
426
+
427
+ if (!next || _nodeIndex3 >= draggedNodeIndex) break;
428
+ _node15 = next;
429
+ }
430
+ } else if (_targetNodeIndex === draggedNodeIndex) {
431
+ targetNodeSetStyle({});
395
432
  }
396
433
  }
397
-
398
- if (targetNodeIndex < draggedNodeIndex) {
399
- var _node15 = targetNode.node;
400
-
401
- while (true) {
402
- var _node16 = _node15,
403
- _node17 = _slicedToArray(_node16, 5),
404
- next = _node17[1],
405
- _nodeSetStyle3 = _node17[3],
406
- _nodeIndex3 = _node17[4];
407
-
408
- _nodeSetStyle3({});
409
-
410
- if (!next || _nodeIndex3 > draggedNodeIndex) return;
411
- _node15 = next;
412
- }
413
- }
414
-
415
- if (targetNodeIndex === draggedNodeIndex) {
416
- targetNodeSetStyle({});
417
- }
418
434
  };
419
- }, [draggedNode]); // Update the position of the mounted nodes between the dragged and target nodes (used in virtual list)
435
+ }, [draggedNode]); // Update the position of the newly mounted nodes in the origin list (used in the virtual list)
420
436
 
421
437
  (0, _react.useEffect)(function () {
422
438
  if (!draggedNode) return function () {};
@@ -425,33 +441,29 @@ var useDragEffect = function useDragEffect(props) {
425
441
  draggedNodeIndex = _draggedNode$node3[4];
426
442
 
427
443
  var update = function update(nodeProps) {
428
- var _targetNodeRef$curren;
429
-
430
444
  var setStyle = nodeProps.setStyle,
431
445
  index = nodeProps.index;
432
- var targetNode = targetNodeRef.current; // If the dragged node outside the origin list
433
-
434
- if (((_targetNodeRef$curren = targetNodeRef.current) === null || _targetNodeRef$curren === void 0 ? void 0 : _targetNodeRef$curren.list) !== draggedNode.list && index > draggedNodeIndex) {
435
- setStyle(getNodeStyle('up', draggedNode.list.horizontal));
436
- return;
437
- }
438
-
439
- if (!targetNode || !targetNode.node) return;
440
-
441
- var _targetNode$node2 = _slicedToArray(targetNode.node, 5),
442
- targetNodeIndex = _targetNode$node2[4]; // If the dragged node was mounted
443
-
446
+ var targetNode = targetNodeRef.current; // Set the hidden style, if the mounted node is the dragged node
444
447
 
445
448
  if (index === draggedNodeIndex) {
446
449
  setStyle(HIDDEN_NODE_STYLE);
447
450
  return;
448
- } // If the node between the dragged and target nodes was mounted
451
+ } // If the dragged node is inside the origin list
452
+
449
453
 
454
+ if (targetNode && targetNode.list === draggedNode.list) {
455
+ // Move the mounted node up/down, if it is located between the dragged and target node
456
+ var _targetNode$node3 = _slicedToArray(targetNode.node, 5),
457
+ targetNodeIndex = _targetNode$node3[4];
450
458
 
451
- if (index > draggedNodeIndex && index < targetNodeIndex) {
452
- setStyle(getNodeStyle('up', targetNode.list.horizontal));
453
- } else if (index < draggedNodeIndex && index > targetNodeIndex) {
454
- setStyle(getNodeStyle('down', targetNode.list.horizontal));
459
+ if (index > draggedNodeIndex && index < targetNodeIndex) {
460
+ setStyle(getNodeStyle('up', targetNode.list.horizontal));
461
+ } else if (index < draggedNodeIndex && index > targetNodeIndex) {
462
+ setStyle(getNodeStyle('down', targetNode.list.horizontal));
463
+ }
464
+ } else if (index > draggedNodeIndex) {
465
+ // Otherwise, move the mounted node up, if it is located below the dragged node
466
+ setStyle(getNodeStyle('up', draggedNode.list.horizontal));
455
467
  }
456
468
  };
457
469
 
@@ -459,7 +471,8 @@ var useDragEffect = function useDragEffect(props) {
459
471
  return function () {
460
472
  return draggedNode.list.removeListener(update);
461
473
  };
462
- }, [draggedNode, getNodeStyle]);
474
+ }, [draggedNode, getNodeStyle]); // Update the position of the newly mounted nodes in the target list (used in the virtual list)
475
+
463
476
  (0, _react.useEffect)(function () {
464
477
  if (!draggedNode || !targetList || targetList === draggedNode.list) {
465
478
  return function () {};
@@ -471,11 +484,13 @@ var useDragEffect = function useDragEffect(props) {
471
484
  var targetNode = targetNodeRef.current;
472
485
  if (!targetNode) return;
473
486
 
474
- var _targetNode$node3 = _slicedToArray(targetNode.node, 5),
475
- targetNodeIndex = _targetNode$node3[4];
487
+ var _targetNode$node4 = _slicedToArray(targetNode.node, 5),
488
+ targetNodeIndex = _targetNode$node4[4];
476
489
 
477
- if (index < targetNodeIndex) return;
478
- setStyle(getNodeStyle('down', targetList.horizontal));
490
+ if (index >= targetNodeIndex) {
491
+ // Move the mounted node down, if it is located below the target node or if it is the target node
492
+ setStyle(getNodeStyle('down', targetList.horizontal));
493
+ }
479
494
  };
480
495
 
481
496
  targetList.addListener(update);