@os-design/drag-sort 1.0.1 → 1.0.2

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.
@@ -24,24 +24,28 @@ function _iterableToArrayLimit(arr, i) { var _i = arr == null ? null : typeof Sy
24
24
  function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
25
25
 
26
26
  /* eslint-disable no-constant-condition */
27
- var useMoveNode = function useMoveNode(position, draggedNode, getNodeStyle) {
28
- return (0, _react.useCallback)(function (props) {
29
- var list = props.list,
30
- startNode = props.startNode,
31
- type = props.type,
32
- _props$untilTheEnd = props.untilTheEnd,
33
- untilTheEnd = _props$untilTheEnd === void 0 ? false : _props$untilTheEnd,
34
- _props$insideAnotherL = props.insideAnotherList,
35
- insideAnotherList = _props$insideAnotherL === void 0 ? false : _props$insideAnotherL;
27
+ var useMoveNode = function useMoveNode(props) {
28
+ var position = props.position,
29
+ draggedNode = props.draggedNode,
30
+ getNodeStyle = props.getNodeStyle;
31
+ return (0, _react.useCallback)(function (options) {
32
+ var list = options.list,
33
+ startNode = options.startNode,
34
+ direction = options.direction,
35
+ destination = options.destination,
36
+ _options$isAnotherLis = options.isAnotherList,
37
+ isAnotherList = _options$isAnotherLis === void 0 ? false : _options$isAnotherLis;
36
38
  if (!draggedNode || !position) return startNode;
37
39
 
38
40
  var _draggedNode$node = _slicedToArray(draggedNode.node, 5),
39
41
  draggedNodeIndex = _draggedNode$node[4];
40
42
 
41
43
  var axis = list.horizontal ? 'x' : 'y';
44
+ var startRectProp = list.horizontal ? 'left' : 'top';
45
+ var endRectProp = list.horizontal ? 'right' : 'bottom';
42
46
  var node = startNode;
43
47
 
44
- if (type === 'up') {
48
+ if (direction === 'up') {
45
49
  while (true) {
46
50
  var _node = node,
47
51
  _node2 = _slicedToArray(_node, 5),
@@ -56,13 +60,15 @@ var useMoveNode = function useMoveNode(position, draggedNode, getNodeStyle) {
56
60
  prevNodeSetStyle = _prev[3],
57
61
  prevNodeIndex = _prev[4];
58
62
 
59
- if (!untilTheEnd) {
63
+ if (destination === 'cursor') {
60
64
  var prevNodeRect = (0, _getNodeRect["default"])(prevNodeRef);
61
- var rectProp = list.horizontal ? 'right' : 'bottom';
62
- if (prevNodeRect && position[axis] > prevNodeRect[rectProp]) return node;
65
+
66
+ if (prevNodeRect && position[axis] > prevNodeRect[endRectProp]) {
67
+ return node;
68
+ }
63
69
  }
64
70
 
65
- if (insideAnotherList || prevNodeIndex < draggedNodeIndex) {
71
+ if (isAnotherList || prevNodeIndex < draggedNodeIndex) {
66
72
  prevNodeSetStyle(getNodeStyle('down', list.horizontal));
67
73
  } else if (nodeIndex > draggedNodeIndex) {
68
74
  nodeSetStyle(getNodeStyle('init', list.horizontal));
@@ -85,15 +91,15 @@ var useMoveNode = function useMoveNode(position, draggedNode, getNodeStyle) {
85
91
  nextNodeSetStyle = _next[3],
86
92
  nextNodeIndex = _next[4];
87
93
 
88
- if (!untilTheEnd) {
94
+ if (destination === 'cursor') {
89
95
  var nextNodeRect = (0, _getNodeRect["default"])(nextNodeRef);
90
96
 
91
- var _rectProp = list.horizontal ? 'left' : 'top';
92
-
93
- if (nextNodeRect && position[axis] < nextNodeRect[_rectProp]) return node;
97
+ if (nextNodeRect && position[axis] < nextNodeRect[startRectProp]) {
98
+ return node;
99
+ }
94
100
  }
95
101
 
96
- if (insideAnotherList || _nodeIndex < draggedNodeIndex) {
102
+ if (isAnotherList || _nodeIndex < draggedNodeIndex) {
97
103
  _nodeSetStyle(getNodeStyle('init', list.horizontal));
98
104
  } else if (nextNodeIndex > draggedNodeIndex) {
99
105
  nextNodeSetStyle(getNodeStyle('up', list.horizontal));
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../src/utils/useMoveNode.ts"],"names":["useMoveNode","position","draggedNode","getNodeStyle","props","list","startNode","type","untilTheEnd","insideAnotherList","node","draggedNodeIndex","axis","horizontal","prev","nodeSetStyle","nodeIndex","prevNodeRef","prevNodeSetStyle","prevNodeIndex","pr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ACF,GApDH,EAqDE,CAACpB,WAAD,EAAcC,YAAd,EAA4BF,QAA5B,CArDF,CALkB;AAAA,CAApB;;eA6DeD,W","sourcesContent":["import { useCallback } from 'react';\nimport { Position } from '@os-design/use-drag';\nimport NodeList, { ExistingNode } from './NodeList';\n// eslint-disable-next-line import/no-cycle\nimport { DraggedNode } from './useDragEffect';\nimport getNodeRect from './getNodeRect';\nimport { NodeStyleGetter } from './useGetNodeStyle';\n\ninterface MoveProps {\n list: NodeList;\n startNode: ExistingNode;\n type: 'up' | 'down';\n untilTheEnd?: boolean;\n insideAnotherList?: boolean;\n}\n\n/* eslint-disable no-constant-condition */\n\nconst useMoveNode = (\n position: Position | null,\n draggedNode: DraggedNode | null,\n getNodeStyle: NodeStyleGetter\n) =>\n useCallback(\n (props: MoveProps) => {\n const {\n list,\n startNode,\n type,\n untilTheEnd = false,\n insideAnotherList = false,\n } = props;\n\n if (!draggedNode || !position) return startNode;\n const [, , , , draggedNodeIndex] = draggedNode.node;\n const axis = list.horizontal ? 'x' : 'y';\n let node = startNode;\n\n if (type === 'up') {\n while (true) {\n const [prev, , , nodeSetStyle, nodeIndex] = node;\n if (!prev) return node;\n const [, , prevNodeRef, prevNodeSetStyle, prevNodeIndex] = prev;\n if (!untilTheEnd) {\n const prevNodeRect = getNodeRect(prevNodeRef);\n const rectProp = list.horizontal ? 'right' : 'bottom';\n if (prevNodeRect && position[axis] > prevNodeRect[rectProp])\n return node;\n }\n if (insideAnotherList || prevNodeIndex < draggedNodeIndex) {\n prevNodeSetStyle(getNodeStyle('down', list.horizontal));\n } else if (nodeIndex > draggedNodeIndex) {\n nodeSetStyle(getNodeStyle('init', list.horizontal));\n }\n node = prev;\n }\n } else {\n while (true) {\n const [, next, , nodeSetStyle, nodeIndex] = node;\n if (!next) return node;\n const [, , nextNodeRef, nextNodeSetStyle, nextNodeIndex] = next;\n if (!untilTheEnd) {\n const nextNodeRect = getNodeRect(nextNodeRef);\n const rectProp = list.horizontal ? 'left' : 'top';\n if (nextNodeRect && position[axis] < nextNodeRect[rectProp])\n return node;\n }\n if (insideAnotherList || nodeIndex < draggedNodeIndex) {\n nodeSetStyle(getNodeStyle('init', list.horizontal));\n } else if (nextNodeIndex > draggedNodeIndex) {\n nextNodeSetStyle(getNodeStyle('up', list.horizontal));\n }\n node = next;\n }\n }\n },\n [draggedNode, getNodeStyle, position]\n );\n\nexport default useMoveNode;\n"],"file":"useMoveNode.js"}
1
+ {"version":3,"sources":["../../../src/utils/useMoveNode.ts"],"names":["useMoveNode","props","position","draggedNode","getNodeStyle","options","list","startNode","direction","destination","isAnotherList","node","draggedNodeIndex","axis","horizontal","startRectProp","endRectProp","prev","nodeSetStyle","nodeIndex","prevNodeRef","prevNodeSetStyle","prevNodeIndex","prevNodeRect","next","nextNodeRef","nextNodeSetStyle","nextNodeIndex","nextNodeRect"],"mappings":";;;;;;;AAAA;;AAGA;;;;;;;;;;;;;;;;AAqBA;AAEA,IAAMA,WAAW,GAAG,SAAdA,WAAc,CAACC,KAAD,EAA6B;AAC/C,MAAQC,QAAR,GAAgDD,KAAhD,CAAQC,QAAR;AAAA,MAAkBC,WAAlB,GAAgDF,KAAhD,CAAkBE,WAAlB;AAAA,MAA+BC,YAA/B,GAAgDH,KAAhD,CAA+BG,YAA/B;AAEA,SAAO,wBACL,UAACC,OAAD,EAAwB;AACtB,QACEC,IADF,GAMID,OANJ,CACEC,IADF;AAAA,QAEEC,SAFF,GAMIF,OANJ,CAEEE,SAFF;AAAA,QAGEC,SAHF,GAMIH,OANJ,CAGEG,SAHF;AAAA,QAIEC,WAJF,GAMIJ,OANJ,CAIEI,WAJF;AAAA,gCAMIJ,OANJ,CAKEK,aALF;AAAA,QAKEA,aALF,sCAKkB,KALlB;AAQA,QAAI,CAACP,WAAD,IAAgB,CAACD,QAArB,EAA+B,OAAOK,SAAP;;AAC/B,2CAAmCJ,WAAW,CAACQ,IAA/C;AAAA,QAAeC,gBAAf;;AACA,QAAMC,IAAI,GAAGP,IAAI,CAAC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AAAA,YAAWC,WAAX;AAAA,YAAwBC,gBAAxB;AAAA,YAA0CC,aAA1C;;AAEA,YAAIlB,WAAW,KAAK,QAApB,EAA8B;AAC5B,cAAMmB,YAAY,GAAG,6BAAYH,WAAZ,CAArB;;AACA,cAAIG,YAAY,IAAI1B,QAAQ,CAACW,IAAD,CAAR,GAAiBe,YAAY,CAACb,aAAD,CAAjD,EAAkE;AAChE,mBAAOJ,IAAP;AACD;AACF;;AAED,YAAID,aAAa,IAAIS,UAAS,GAAGP,gBAAjC,EAAmD;AACjDM,UAAAA,aAAY,CAACd,YAAY,CAAC,MAAD,EAASE,IAAI,CAACQ,UAAd,CAAb,CAAZ;AACD,SAFD,MAEO,IAAIa,aAAa,GAAGf,gBAApB,EAAsC;AAC3Cc,UAAAA,gBAAgB,CAACtB,YAAY,CAAC,IAAD,EAAOE,IAAI,CAACQ,UAAZ,CAAb,CAAhB;AACD;;AAEDH,QAAAA,IAAI,GAAGa,IAAP;AACD;AACF;AACF,GA9DI,EA+DL,CAACrB,WAAD,EAAcC,YAAd,EAA4BF,QAA5B,CA/DK,CAAP;AAiED,CApED;;eAsEeF,W","sourcesContent":["import { useCallback } from 'react';\nimport { Position } from '@os-design/use-drag';\nimport NodeList, { ExistingNode } from './NodeList';\nimport getNodeRect from './getNodeRect';\nimport { NodeStyleGetter } from './useGetNodeStyle';\n\ninterface DraggedNode {\n node: ExistingNode;\n}\n\ninterface UseMoveNodeProps {\n position: Position | null;\n draggedNode: DraggedNode | null;\n getNodeStyle: NodeStyleGetter;\n}\n\ninterface MoveProps {\n list: NodeList;\n startNode: ExistingNode;\n direction: 'up' | 'down';\n destination: 'cursor' | 'end';\n isAnotherList?: boolean;\n}\n\n/* eslint-disable no-constant-condition */\n\nconst useMoveNode = (props: UseMoveNodeProps) => {\n const { position, draggedNode, getNodeStyle } = props;\n\n return useCallback(\n (options: MoveProps) => {\n const {\n list,\n startNode,\n direction,\n destination,\n isAnotherList = false,\n } = options;\n\n if (!draggedNode || !position) return startNode;\n const [, , , , draggedNodeIndex] = draggedNode.node;\n const axis = list.horizontal ? 'x' : 'y';\n const startRectProp = list.horizontal ? 'left' : 'top';\n const endRectProp = list.horizontal ? 'right' : 'bottom';\n let node = startNode;\n\n if (direction === 'up') {\n while (true) {\n const [prev, , , nodeSetStyle, nodeIndex] = node;\n if (!prev) return node;\n\n const [, , prevNodeRef, prevNodeSetStyle, prevNodeIndex] = prev;\n\n if (destination === 'cursor') {\n const prevNodeRect = getNodeRect(prevNodeRef);\n if (prevNodeRect && position[axis] > prevNodeRect[endRectProp]) {\n return node;\n }\n }\n\n if (isAnotherList || prevNodeIndex < draggedNodeIndex) {\n prevNodeSetStyle(getNodeStyle('down', list.horizontal));\n } else if (nodeIndex > draggedNodeIndex) {\n nodeSetStyle(getNodeStyle('init', list.horizontal));\n }\n\n node = prev;\n }\n } else {\n while (true) {\n const [, next, , nodeSetStyle, nodeIndex] = node;\n if (!next) return node;\n\n const [, , nextNodeRef, nextNodeSetStyle, nextNodeIndex] = next;\n\n if (destination === 'cursor') {\n const nextNodeRect = getNodeRect(nextNodeRef);\n if (nextNodeRect && position[axis] < nextNodeRect[startRectProp]) {\n return node;\n }\n }\n\n if (isAnotherList || nodeIndex < draggedNodeIndex) {\n nodeSetStyle(getNodeStyle('init', list.horizontal));\n } else if (nextNodeIndex > draggedNodeIndex) {\n nextNodeSetStyle(getNodeStyle('up', list.horizontal));\n }\n\n node = next;\n }\n }\n },\n [draggedNode, getNodeStyle, position]\n );\n};\n\nexport default useMoveNode;\n"],"file":"useMoveNode.js"}
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../src/utils/useBlankNode.ts"],"names":["useCallback","useEffect","useRef","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","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CAAC3B,IAAN,CAAW4B,MAAX,CAAkBD,KAAK,CAACL,IAAxB;AACA,UAAM,IAAKO,YAAL,IAAqBF,KAAK,CAACL,IAAjC;AACA,QAAI,CAACK,KAAK,CAAC3B,IAAN,CAAWD,GAAX,CAAeD,OAAhB,IAA2B,CAAC+B,YAAY,CAAC/B,OAA7C,EAAsD;AACtD,UAAMa,MAAM,GAAGkB,YAAY,CAAC/B,OAAb,CAAqBgC,aAApC;AACA,QAAInB,MAAJ,EAAYA,MAAM,CAACoB,WAAP,CAAmBF,YAAY,CAAC/B,OAAhC;AACb,GATkC,EAShC,EATgC,CAAnC,CAvDiD,CAkEjD;;AACAT,EAAAA,SAAS,CAAC,MAAM;AACd,QAAI,CAACI,WAAL,EAAkB,OAAO,MAAM,CAAE,CAAf;AAClB,WAAO,MAAMiC,eAAe,EAA5B;AACD,GAHQ,EAGN,CAACjC,WAAD,EAAciC,eAAd,CAHM,CAAT;AAKA,SAAOA,eAAP;AACD,CAzED;;AA2EA,eAAenC,YAAf","sourcesContent":["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":["useCallback","useEffect","useRef","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","remove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,MAAX,CAAkBD,KAAK,CAACL,IAAxB;AACA,UAAM,IAAKO,YAAL,IAAqBF,KAAK,CAACL,IAAjC;AACA,QAAI,CAACK,KAAK,CAAC3B,IAAN,CAAWD,GAAX,CAAeD,OAAhB,IAA2B,CAAC+B,YAAY,CAAC/B,OAA7C,EAAsD;AACtD,UAAMa,MAAM,GAAGkB,YAAY,CAAC/B,OAAb,CAAqBgC,aAApC;AACA,QAAInB,MAAJ,EAAYA,MAAM,CAACoB,WAAP,CAAmBF,YAAY,CAAC/B,OAAhC;AACb,GATkC,EAShC,EATgC,CAAnC,CAvDiD,CAkEjD;;AACAT,EAAAA,SAAS,CAAC,MAAM;AACd,QAAI,CAACI,WAAL,EAAkB,OAAO,MAAM,CAAE,CAAf;AAClB,WAAO,MAAMiC,eAAe,EAA5B;AACD,GAHQ,EAGN,CAACjC,WAAD,EAAciC,eAAd,CAHM,CAAT;AAKA,SAAOA,eAAP;AACD,CAzED;;AA2EA,eAAenC,YAAf","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"}
@@ -5,11 +5,9 @@ import getElementScroll from './getElementScroll';
5
5
  import useTargetList from './useTargetList';
6
6
  import useInitRect from './useInitRect';
7
7
  import useInitScrollOffset from './useInitScrollOffset';
8
- import useGetNodeStyle from './useGetNodeStyle'; // eslint-disable-next-line import/no-cycle
9
-
8
+ import useGetNodeStyle from './useGetNodeStyle';
10
9
  import useMoveNode from './useMoveNode';
11
- import getNodeRect from './getNodeRect'; // eslint-disable-next-line import/no-cycle
12
-
10
+ import getNodeRect from './getNodeRect';
13
11
  import useBlankNode from './useBlankNode';
14
12
  const HIDDEN_NODE_STYLE = {
15
13
  opacity: 0,
@@ -22,7 +20,7 @@ const createEmptyNode = ({
22
20
  }) => [prev, next, {
23
21
  current: null
24
22
  }, () => {}, -1];
25
- /* eslint-disable @typescript-eslint/no-explicit-any,no-constant-condition */
23
+ /* eslint-disable no-constant-condition */
26
24
 
27
25
 
28
26
  const useDragEffect = props => {
@@ -44,8 +42,7 @@ const useDragEffect = props => {
44
42
  // We can't read the bounds of the dragged node on the fly because the node can be unmounted in the virtual list.
45
43
 
46
44
  const initDraggedNodeRect = useInitRect(draggedNode ? draggedNode.node[2] : undefined); // The initial scroll position of the list where the dragged node is located.
47
- // Used to detect the actual position of the dragged node.
48
- // The purpose is the same as with initDraggedNodeRect.
45
+ // Used to detect the actual position of the dragged node. The purpose is the same as with initDraggedNodeRect.
49
46
 
50
47
  const initDraggedNodeListScrollOffset = useInitScrollOffset(draggedNode ? draggedNode.list.ref : undefined); // The central position of the dragged node
51
48
 
@@ -63,12 +60,17 @@ const useDragEffect = props => {
63
60
  x: x - draggedNode.position.x + initWidth / 2,
64
61
  y: y - draggedNode.position.y + initHeight / 2
65
62
  };
66
- }, [cursorPosition, draggedNode, initDraggedNodeRect]); // Returns the style for moving the node in the specified direction
63
+ }, [cursorPosition, draggedNode, initDraggedNodeRect]); // The list in which the cursor is located
67
64
 
68
- const getNodeStyle = useGetNodeStyle(initDraggedNodeRect); // The list in which the cursor is located
65
+ const targetList = useTargetList(position, listStoreRef); // Returns the style for moving the node in the specified direction
69
66
 
70
- const targetList = useTargetList(position, listStoreRef);
71
- const moveNode = useMoveNode(position, draggedNode, getNodeStyle);
67
+ const getNodeStyle = useGetNodeStyle(initDraggedNodeRect); // Moves the node up or down
68
+
69
+ const moveNode = useMoveNode({
70
+ position,
71
+ draggedNode,
72
+ getNodeStyle
73
+ });
72
74
  const setTargetNode = useCallback((list, node) => {
73
75
  const [,,,, nodeIndex] = node;
74
76
  targetNodeRef.current = {
@@ -130,14 +132,14 @@ const useDragEffect = props => {
130
132
  const updateTargetNode = useCallback(() => {
131
133
  if (!draggedNode) return;
132
134
  const prevTargetNode = targetNodeRef.current; // The last updated node
133
- // Dragging outside the list
135
+ // Dragging outside the origin list
134
136
 
135
137
  if (prevTargetNode && prevTargetNode.list === draggedNode.list && targetList !== draggedNode.list) {
136
138
  moveNode({
137
139
  list: prevTargetNode.list,
138
140
  startNode: prevTargetNode.node,
139
- type: 'down',
140
- untilTheEnd: true
141
+ direction: 'down',
142
+ destination: 'end'
141
143
  });
142
144
  clearTargetNode();
143
145
  } // Dragging outside another list
@@ -147,13 +149,13 @@ const useDragEffect = props => {
147
149
  moveNode({
148
150
  list: prevTargetNode.list,
149
151
  startNode: prevTargetNode.node,
150
- type: 'down',
151
- untilTheEnd: true,
152
- insideAnotherList: true
152
+ direction: 'down',
153
+ destination: 'end',
154
+ isAnotherList: true
153
155
  });
154
156
  removeBlankNode();
155
157
  clearTargetNode();
156
- } // Dragging inside the list
158
+ } // Dragging inside the origin list
157
159
 
158
160
 
159
161
  if (!prevTargetNode && targetList === draggedNode.list) {
@@ -162,7 +164,8 @@ const useDragEffect = props => {
162
164
  const node = moveNode({
163
165
  list: targetList,
164
166
  startNode: tail,
165
- type: 'up'
167
+ direction: 'up',
168
+ destination: 'cursor'
166
169
  });
167
170
  setTargetNode(targetList, node);
168
171
  return;
@@ -175,12 +178,13 @@ const useDragEffect = props => {
175
178
  const node = moveNode({
176
179
  list: targetList,
177
180
  startNode: tail,
178
- type: 'up',
179
- insideAnotherList: true
181
+ direction: 'up',
182
+ destination: 'cursor',
183
+ isAnotherList: true
180
184
  });
181
185
  setTargetNode(targetList, node);
182
186
  return;
183
- } // Dragging in the same list
187
+ } // Dragging in the origin list
184
188
 
185
189
 
186
190
  if (prevTargetNode && prevTargetNode.list === draggedNode.list && targetList === draggedNode.list) {
@@ -204,7 +208,8 @@ const useDragEffect = props => {
204
208
  startNode: createEmptyNode({
205
209
  prev: tail
206
210
  }),
207
- type: 'up'
211
+ direction: 'up',
212
+ destination: 'cursor'
208
213
  });
209
214
  setTargetNode(targetList, node);
210
215
  } else {
@@ -215,7 +220,8 @@ const useDragEffect = props => {
215
220
  startNode: createEmptyNode({
216
221
  next: head
217
222
  }),
218
- type: 'down'
223
+ direction: 'down',
224
+ destination: 'cursor'
219
225
  });
220
226
  setTargetNode(targetList, node);
221
227
  }
@@ -224,17 +230,19 @@ const useDragEffect = props => {
224
230
  }
225
231
 
226
232
  const prevTargetNodeRect = getNodeRect(prevTargetNode.node[2]);
227
- const rectProp = targetList.horizontal ? 'left' : 'top';
233
+ const startRectProp = targetList.horizontal ? 'left' : 'top';
228
234
  if (!position || !prevTargetNodeRect) return;
229
- const isMoveUp = position[axis] < prevTargetNodeRect[rectProp];
235
+ const isMoveUp = position[axis] < prevTargetNodeRect[startRectProp];
230
236
  const node = isMoveUp ? moveNode({
231
237
  list: targetList,
232
238
  startNode: prevTargetNode.node,
233
- type: 'up'
239
+ direction: 'up',
240
+ destination: 'cursor'
234
241
  }) : moveNode({
235
242
  list: targetList,
236
243
  startNode: prevTargetNode.node,
237
- type: 'down'
244
+ direction: 'down',
245
+ destination: 'cursor'
238
246
  });
239
247
  setTargetNode(targetList, node);
240
248
  return;
@@ -244,19 +252,21 @@ const useDragEffect = props => {
244
252
  if (targetList && targetList !== draggedNode.list && prevTargetNode && prevTargetNode.list === targetList) {
245
253
  const axis = targetList.horizontal ? 'x' : 'y';
246
254
  const prevTargetNodeRect = getNodeRect(prevTargetNode.node[2]);
247
- const rectProp = targetList.horizontal ? 'left' : 'top';
255
+ const startRectProp = targetList.horizontal ? 'left' : 'top';
248
256
  if (!position || !prevTargetNodeRect) return;
249
- const isMoveUp = position[axis] < prevTargetNodeRect[rectProp];
257
+ const isMoveUp = position[axis] < prevTargetNodeRect[startRectProp];
250
258
  const node = isMoveUp ? moveNode({
251
259
  list: targetList,
252
260
  startNode: prevTargetNode.node,
253
- type: 'up',
254
- insideAnotherList: true
261
+ direction: 'up',
262
+ destination: 'cursor',
263
+ isAnotherList: true
255
264
  }) : moveNode({
256
265
  list: targetList,
257
266
  startNode: prevTargetNode.node,
258
- type: 'down',
259
- insideAnotherList: true
267
+ direction: 'down',
268
+ destination: 'cursor',
269
+ isAnotherList: true
260
270
  });
261
271
  setTargetNode(targetList, node);
262
272
  }
@@ -268,77 +278,81 @@ const useDragEffect = props => {
268
278
 
269
279
  const [throttledUpdateTargetNode] = useThrottle(updateTargetNode, 100);
270
280
  useEvent(targetList ? targetList.ref : undefined, 'scroll', throttledUpdateTargetNode);
271
- useEvent(window, 'scroll', throttledUpdateTargetNode); // Reset styles of the nodes when the dragged node was dropped
281
+ useEvent(window, 'scroll', throttledUpdateTargetNode); // Reset styles of the affected nodes when the dragged node was dropped
272
282
 
273
283
  useEffect(() => {
274
284
  if (!draggedNode) return () => {};
275
285
  const [,,,, draggedNodeIndex] = draggedNode.node;
276
286
  return () => {
277
- const targetNode = targetNodeRef.current; // If the dragged node was inside another list, reset the styles for the nodes,
278
- // starting at the tail and ending with the dragged node.
279
-
280
- if (targetNode && targetNode.list !== draggedNode.list) {
281
- const tail = targetNode.list.getTail();
282
- if (!tail) return;
283
- let node = tail;
284
-
285
- while (true) {
286
- const [prev,,, nodeSetStyle, nodeIndex] = node;
287
- nodeSetStyle({});
288
- if (!prev || nodeIndex <= draggedNodeIndex) break;
289
- node = prev;
290
- }
291
- } // If the dragged node was outside the origin list, reset the styles for the nodes,
292
- // starting at the tail and ending with the dragged node.
293
-
287
+ const targetNode = targetNodeRef.current; // If the dragged node was outside the origin list, reset the styles for the nodes,
288
+ // starting at the tail and ending with the dragged node in the origin list.
294
289
 
295
- const tail = draggedNode.list.getTail();
290
+ if (!targetNode || targetNode.list !== draggedNode.list) {
291
+ const tail = draggedNode.list.getTail();
296
292
 
297
- if ((!targetNode || targetNode.list !== draggedNode.list) && tail) {
298
- let node = tail;
293
+ if (tail) {
294
+ let node = tail;
299
295
 
300
- while (true) {
301
- const [prev,,, nodeSetStyle, nodeIndex] = node;
302
- nodeSetStyle({});
303
- if (!prev || nodeIndex <= draggedNodeIndex) break;
304
- node = prev;
296
+ while (true) {
297
+ const [prev,,, nodeSetStyle, nodeIndex] = node;
298
+ nodeSetStyle({});
299
+ if (!prev || nodeIndex <= draggedNodeIndex) break;
300
+ node = prev;
301
+ }
305
302
  }
306
- }
303
+ } // If the dragged node was inside another list, reset the styles for the nodes,
304
+ // starting at the tail and ending with the dragged node in the target list.
307
305
 
308
- if (!targetNode) return;
309
- const [,,, targetNodeSetStyle, targetNodeIndex] = targetNode.node;
310
-
311
- if (targetNodeIndex > draggedNodeIndex) {
312
- let {
313
- node
314
- } = targetNode;
315
-
316
- while (true) {
317
- const [prev,,, nodeSetStyle, nodeIndex] = node;
318
- nodeSetStyle({});
319
- if (!prev || nodeIndex < draggedNodeIndex) return;
320
- node = prev;
321
- }
322
- }
323
306
 
324
- if (targetNodeIndex < draggedNodeIndex) {
325
- let {
326
- node
327
- } = targetNode;
307
+ if (targetNode && targetNode.list !== draggedNode.list) {
308
+ const tail = targetNode.list.getTail();
309
+ const [,,,, targetNodeIndex] = targetNode.node;
328
310
 
329
- while (true) {
330
- const [, next,, nodeSetStyle, nodeIndex] = node;
331
- nodeSetStyle({});
332
- if (!next || nodeIndex > draggedNodeIndex) return;
333
- node = next;
334
- }
335
- }
311
+ if (tail) {
312
+ let node = tail;
336
313
 
337
- if (targetNodeIndex === draggedNodeIndex) {
338
- targetNodeSetStyle({});
314
+ while (true) {
315
+ const [prev,,, nodeSetStyle, nodeIndex] = node;
316
+ nodeSetStyle({});
317
+ if (!prev || nodeIndex <= targetNodeIndex) break;
318
+ node = prev;
319
+ }
320
+ }
321
+ } // If the dragged node was moved inside the origin list, reset the styles for the nodes,
322
+ // starting with target node and ending with the dragged node.
323
+
324
+
325
+ if (targetNode && targetNode.list === draggedNode.list) {
326
+ const [,,, targetNodeSetStyle, targetNodeIndex] = targetNode.node;
327
+
328
+ if (targetNodeIndex > draggedNodeIndex) {
329
+ let {
330
+ node
331
+ } = targetNode;
332
+
333
+ while (true) {
334
+ const [prev,,, nodeSetStyle, nodeIndex] = node;
335
+ nodeSetStyle({});
336
+ if (!prev || nodeIndex <= draggedNodeIndex) break;
337
+ node = prev;
338
+ }
339
+ } else if (targetNodeIndex < draggedNodeIndex) {
340
+ let {
341
+ node
342
+ } = targetNode;
343
+
344
+ while (true) {
345
+ const [, next,, nodeSetStyle, nodeIndex] = node;
346
+ nodeSetStyle({});
347
+ if (!next || nodeIndex >= draggedNodeIndex) break;
348
+ node = next;
349
+ }
350
+ } else if (targetNodeIndex === draggedNodeIndex) {
351
+ targetNodeSetStyle({});
352
+ }
339
353
  }
340
354
  };
341
- }, [draggedNode]); // Update the position of the mounted nodes between the dragged and target nodes (used in virtual list)
355
+ }, [draggedNode]); // Update the position of the newly mounted nodes in the origin list (used in the virtual list)
342
356
 
343
357
  useEffect(() => {
344
358
  if (!draggedNode) return () => {};
@@ -349,32 +363,33 @@ const useDragEffect = props => {
349
363
  setStyle,
350
364
  index
351
365
  } = nodeProps;
352
- const targetNode = targetNodeRef.current; // If the dragged node outside the origin list
353
-
354
- if ((!targetNodeRef.current || targetNodeRef.current.list !== draggedNode.list) && index > draggedNodeIndex) {
355
- setStyle(getNodeStyle('up', draggedNode.list.horizontal));
356
- return;
357
- }
358
-
359
- if (!targetNode || !targetNode.node) return;
360
- const [,,,, targetNodeIndex] = targetNode.node; // If the dragged node was mounted
366
+ const targetNode = targetNodeRef.current; // Set the hidden style, if the mounted node is the dragged node
361
367
 
362
368
  if (index === draggedNodeIndex) {
363
369
  setStyle(HIDDEN_NODE_STYLE);
364
370
  return;
365
- } // If the node between the dragged and target nodes was mounted
371
+ } // If the dragged node is inside the origin list
372
+
366
373
 
374
+ if (targetNode && targetNode.list === draggedNode.list) {
375
+ // Move the mounted node up/down, if it is located between the dragged and target node
376
+ const [,,,, targetNodeIndex] = targetNode.node;
367
377
 
368
- if (index > draggedNodeIndex && index < targetNodeIndex) {
369
- setStyle(getNodeStyle('up', targetNode.list.horizontal));
370
- } else if (index < draggedNodeIndex && index > targetNodeIndex) {
371
- setStyle(getNodeStyle('down', targetNode.list.horizontal));
378
+ if (index > draggedNodeIndex && index < targetNodeIndex) {
379
+ setStyle(getNodeStyle('up', targetNode.list.horizontal));
380
+ } else if (index < draggedNodeIndex && index > targetNodeIndex) {
381
+ setStyle(getNodeStyle('down', targetNode.list.horizontal));
382
+ }
383
+ } else if (index > draggedNodeIndex) {
384
+ // Otherwise, move the mounted node up, if it is located below the dragged node
385
+ setStyle(getNodeStyle('up', draggedNode.list.horizontal));
372
386
  }
373
387
  };
374
388
 
375
389
  draggedNode.list.addListener(update);
376
390
  return () => draggedNode.list.removeListener(update);
377
- }, [draggedNode, getNodeStyle]);
391
+ }, [draggedNode, getNodeStyle]); // Update the position of the newly mounted nodes in the target list (used in the virtual list)
392
+
378
393
  useEffect(() => {
379
394
  if (!draggedNode || !targetList || targetList === draggedNode.list) {
380
395
  return () => {};
@@ -388,8 +403,11 @@ const useDragEffect = props => {
388
403
  const targetNode = targetNodeRef.current;
389
404
  if (!targetNode) return;
390
405
  const [,,,, targetNodeIndex] = targetNode.node;
391
- if (index < targetNodeIndex) return;
392
- setStyle(getNodeStyle('down', targetList.horizontal));
406
+
407
+ if (index >= targetNodeIndex) {
408
+ // Move the mounted node down, if it is located below the target node or if it is the target node
409
+ setStyle(getNodeStyle('down', targetList.horizontal));
410
+ }
393
411
  };
394
412
 
395
413
  targetList.addListener(update);