@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.
@@ -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 => {
@@ -43,11 +41,10 @@ const useDragEffect = props => {
43
41
  }, [onDragEnd]); // The initial bounds of the dragged node.
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
- const initDraggedNodeRect = useInitRect(draggedNode?.node[2]); // 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.
44
+ const initDraggedNodeRect = useInitRect(draggedNode ? draggedNode.node[2] : undefined); // The initial scroll position of the list where the dragged node is located.
45
+ // Used to detect the actual position of the dragged node. The purpose is the same as with initDraggedNodeRect.
49
46
 
50
- const initDraggedNodeListScrollOffset = useInitScrollOffset(draggedNode?.list.ref); // The central position of the dragged node
47
+ const initDraggedNodeListScrollOffset = useInitScrollOffset(draggedNode ? draggedNode.list.ref : undefined); // The central position of the dragged node
51
48
 
52
49
  const position = useMemo(() => {
53
50
  if (!draggedNode || !initDraggedNodeRect) return null;
@@ -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,25 +164,27 @@ 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;
169
172
  } // Dragging inside another list
170
173
 
171
174
 
172
- if (targetList && targetList !== draggedNode.list && prevTargetNode?.list !== targetList) {
175
+ if (targetList && targetList !== draggedNode.list && (!prevTargetNode || prevTargetNode.list !== targetList)) {
173
176
  const tail = targetList.getTail();
174
177
  if (!tail) return;
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,39 +230,43 @@ 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;
241
249
  } // Dragging in another list
242
250
 
243
251
 
244
- if (targetList && targetList !== draggedNode.list && prevTargetNode?.list === targetList) {
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
  }
@@ -267,78 +277,82 @@ const useDragEffect = props => {
267
277
  }, [updateTargetNode]); // Update the target node if the target list has been scrolled
268
278
 
269
279
  const [throttledUpdateTargetNode] = useThrottle(updateTargetNode, 100);
270
- useEvent(targetList?.ref, 'scroll', throttledUpdateTargetNode);
271
- useEvent(window, 'scroll', throttledUpdateTargetNode); // Reset styles of the nodes when the dragged node was dropped
280
+ useEvent(targetList ? targetList.ref : undefined, 'scroll', throttledUpdateTargetNode);
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?.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?.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);
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../src/utils/useDragEffect.ts"],"names":["useCallback","useEffect","useMemo","useRef","useThrottle","useEvent","getElementScroll","useTargetList","useInitRect","useInitScrollOffset","useGetNodeStyle","useMoveNode","getNodeRect","useBlankNode","HIDDEN_NODE_STYLE","opacity","pointerEvents","createEmptyNode","prev","next","current","useDragEffect","props","draggedNode","cursorPosition","listStoreRef","onDragEnd","targetRef","targetNodeRef","onDragEndRef","initDraggedNodeRect","node","initDraggedNodeListScrollOffset","list","ref","position","x","y","initWidth","initHeight","getNodeStyle","targetList","moveNode","setTargetNode","nodeIndex","id","index","clearTargetNode","getDraggedNodePos","initX","initY","initScrollLeft","initScrollTop","scrollLeft","scrollTop","getDraggedNodePosRef","draggedNodeSetStyle","removeBlankNode","updateTargetNode","prevTargetNode","startNode","type","untilTheEnd","insideAnotherList","tail","getTail","axis","horizontal","prevTargetNodeRef","draggedNodePos","isDraggingUp","head","getHead","prevTargetNodeRect","rectProp","isMoveUp","throttledUpdateTargetNode","window","draggedNodeIndex","targetNode","nodeSetStyle","targetNodeSetStyle","targetNodeIndex","update","nodeProps","setStyle","addListener","removeListener","target","dragged"],"mappings":"AACA,SAGEA,WAHF,EAIEC,SAJF,EAKEC,OALF,EAMEC,MANF,QAOO,OAPP;AAQA,OAAOC,WAAP,MAAwB,yBAAxB;AACA,OAAOC,QAAP,MAAqB,sBAArB;AAGA,OAAOC,gBAAP,MAA6B,oBAA7B;AACA,OAAOC,aAAP,MAA0B,iBAA1B;AACA,OAAOC,WAAP,MAAwB,eAAxB;AACA,OAAOC,mBAAP,MAAgC,uBAAhC;AACA,OAAOC,eAAP,MAA4B,mBAA5B,C,CACA;;AACA,OAAOC,WAAP,MAAwB,eAAxB;AACA,OAAOC,WAAP,MAAwB,eAAxB,C,CACA;;AACA,OAAOC,YAAP,MAAyB,gBAAzB;AA8BA,MAAMC,iBAAgC,GAAG;AACvCC,EAAAA,OAAO,EAAE,CAD8B;AAEvCC,EAAAA,aAAa,EAAE;AAFwB,CAAzC;;AAKA,MAAMC,eAAe,GAAG,CAAC;AACvBC,EAAAA,IAAI,GAAG,IADgB;AAEvBC,EAAAA,IAAI,GAAG;AAFgB,CAAD,KAMJ,CAACD,IAAD,EAAOC,IAAP,EAAa;AAAEC,EAAAA,OAAO,EAAE;AAAX,CAAb,EAAgC,MAAM,CAAE,CAAxC,EAA0C,CAAC,CAA3C,CANpB;AAQA;;;AAEA,MAAMC,aAAa,GAAIC,KAAD,IAA+B;AACnD,QAAM;AAAEC,IAAAA,WAAF;AAAeC,IAAAA,cAAf;AAA+BC,IAAAA,YAA/B;AAA6CC,IAAAA;AAA7C,MAA2DJ,KAAjE;AAEA,QAAMK,SAAS,GAAGxB,MAAM,CAAsB,IAAtB,CAAxB;AACA,QAAMyB,aAAa,GAAGzB,MAAM,CAAoBoB,WAApB,CAA5B;AAEAtB,EAAAA,SAAS,CAAC,MAAM;AACd2B,IAAAA,aAAa,CAACR,OAAd,GAAwBG,WAAxB;AACD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;AACA,YAAML,UAAU,GAAGnD,aAAa,CAACR,OAAjC;AACA,UAAI,CAAC2D,UAAL,EAAiB;AACjB,YAAM,MAASG,eAAT,IAA4BH,UAAU,CAAChD,IAA7C;AACA,UAAIe,KAAK,GAAGoC,eAAZ,EAA6B;AAC7BG,MAAAA,QAAQ,CAAC7C,YAAY,CAAC,MAAD,EAASC,UAAU,CAAC0B,UAApB,CAAb,CAAR;AACD,KAPD;;AAQA1B,IAAAA,UAAU,CAAC6C,WAAX,CAAuBH,MAAvB;AACA,WAAO,MAAM1C,UAAU,CAAC8C,cAAX,CAA0BJ,MAA1B,CAAb;AACD,GAdQ,EAcN,CAAC5D,WAAD,EAAciB,YAAd,EAA4BC,UAA5B,CAdM,CAAT,CAxWmD,CAwXnD;;AACAxC,EAAAA,SAAS,CAAC,MAAM;AACd,QAAI,CAACsB,WAAL,EAAkB,OAAO,MAAM,CAAE,CAAf;AAClB,WAAO,MAAM;AACX;AACA,YAAMiE,MAAM,GAAG7D,SAAS,CAACP,OAAzB;AACA,UAAI,CAACoE,MAAL,EAAa;AACb,YAAM,MAASV,gBAAT,IAA6BvD,WAAW,CAACQ,IAA/C;AACA,YAAM0D,OAAO,GAAG;AAAE5C,QAAAA,EAAE,EAAEtB,WAAW,CAACU,IAAZ,CAAiBY,EAAvB;AAA2BC,QAAAA,KAAK,EAAEgC;AAAlC,OAAhB;AACA,UAAIW,OAAO,CAAC5C,EAAR,KAAe2C,MAAM,CAAC3C,EAAtB,IAA4B4C,OAAO,CAAC3C,KAAR,KAAkB0C,MAAM,CAAC1C,KAAzD,EAAgE;AAChEjB,MAAAA,YAAY,CAACT,OAAb,CAAqBqE,OAArB,EAA8BD,MAA9B;AACD,KARD;AASD,GAXQ,EAWN,CAACjE,WAAD,CAXM,CAAT;AAYD,CArYD;;AAuYA,eAAeF,aAAf","sourcesContent":["import { Position } from '@os-design/use-drag';\nimport {\n CSSProperties,\n RefObject,\n useCallback,\n useEffect,\n useMemo,\n useRef,\n} from 'react';\nimport useThrottle from '@os-design/use-throttle';\nimport useEvent from '@os-design/use-event';\nimport NodeList, { ExistingNode, Node, NodeProps } from './NodeList';\nimport ListStore from './ListStore';\nimport getElementScroll from './getElementScroll';\nimport useTargetList from './useTargetList';\nimport useInitRect from './useInitRect';\nimport useInitScrollOffset from './useInitScrollOffset';\nimport useGetNodeStyle from './useGetNodeStyle';\n// eslint-disable-next-line import/no-cycle\nimport useMoveNode from './useMoveNode';\nimport getNodeRect from './getNodeRect';\n// eslint-disable-next-line import/no-cycle\nimport useBlankNode from './useBlankNode';\n\nexport interface DraggedNode {\n list: NodeList;\n node: ExistingNode;\n position: Position;\n}\n\ninterface TargetNode {\n list: NodeList;\n node: ExistingNode;\n}\n\nexport interface ItemLocation {\n id: string;\n index: number;\n}\n\nexport type DragEndHandler = (\n dragged: ItemLocation,\n target: ItemLocation\n) => void;\n\ninterface UseDragEffectProps {\n draggedNode: DraggedNode | null;\n cursorPosition: Position;\n listStoreRef: RefObject<ListStore>;\n onDragEnd: DragEndHandler;\n}\n\nconst HIDDEN_NODE_STYLE: CSSProperties = {\n opacity: 0,\n pointerEvents: 'none',\n};\n\nconst createEmptyNode = ({\n prev = null,\n next = null,\n}: {\n prev?: Node;\n next?: Node;\n}): ExistingNode => [prev, next, { current: null }, () => {}, -1];\n\n/* eslint-disable @typescript-eslint/no-explicit-any,no-constant-condition */\n\nconst useDragEffect = (props: UseDragEffectProps) => {\n const { draggedNode, cursorPosition, listStoreRef, onDragEnd } = props;\n\n const targetRef = useRef<ItemLocation | null>(null);\n const targetNodeRef = useRef<TargetNode | null>(draggedNode);\n\n useEffect(() => {\n targetNodeRef.current = draggedNode;\n }, [draggedNode]);\n\n const onDragEndRef = useRef(onDragEnd);\n useEffect(() => {\n onDragEndRef.current = onDragEnd;\n }, [onDragEnd]);\n\n // The initial bounds of the dragged node.\n // We can't read the bounds of the dragged node on the fly because the node can be unmounted in the virtual list.\n const initDraggedNodeRect = useInitRect(draggedNode?.node[2]);\n\n // The initial scroll position of the list where the dragged node is located.\n // Used to detect the actual position of the dragged node.\n // The purpose is the same as with initDraggedNodeRect.\n const initDraggedNodeListScrollOffset = useInitScrollOffset(\n draggedNode?.list.ref\n );\n\n // The central position of the dragged node\n const position = useMemo(() => {\n if (!draggedNode || !initDraggedNodeRect) return null;\n const { x, y } = cursorPosition;\n const { initWidth, initHeight } = initDraggedNodeRect;\n return {\n x: x - draggedNode.position.x + initWidth / 2,\n y: y - draggedNode.position.y + initHeight / 2,\n };\n }, [cursorPosition, draggedNode, initDraggedNodeRect]);\n\n // Returns the style for moving the node in the specified direction\n const getNodeStyle = useGetNodeStyle(initDraggedNodeRect);\n\n // The list in which the cursor is located\n const targetList = useTargetList(position, listStoreRef);\n\n const moveNode = useMoveNode(position, draggedNode, getNodeStyle);\n\n const setTargetNode = useCallback((list: NodeList, node: ExistingNode) => {\n const [, , , , nodeIndex] = node;\n targetNodeRef.current = { list, node };\n targetRef.current = { id: list.id, index: nodeIndex };\n }, []);\n\n const clearTargetNode = useCallback(() => {\n targetNodeRef.current = null;\n targetRef.current = null;\n }, []);\n\n // Returns the central position of the dragged node in the list\n const getDraggedNodePos = useCallback(() => {\n if (\n !targetList ||\n !targetList.ref.current ||\n !initDraggedNodeRect ||\n !initDraggedNodeListScrollOffset\n ) {\n return null;\n }\n const { initX, initY, initWidth, initHeight } = initDraggedNodeRect;\n const { initScrollLeft, initScrollTop } = initDraggedNodeListScrollOffset;\n const { scrollLeft, scrollTop } = getElementScroll(targetList.ref.current);\n return {\n x: initX + initWidth / 2 + initScrollLeft - scrollLeft,\n y: initY + initHeight / 2 + initScrollTop - scrollTop,\n };\n }, [initDraggedNodeListScrollOffset, initDraggedNodeRect, targetList]);\n\n const getDraggedNodePosRef = useRef(getDraggedNodePos);\n useEffect(() => {\n getDraggedNodePosRef.current = getDraggedNodePos;\n }, [getDraggedNodePos]);\n\n // Hide the dragged node\n useEffect(() => {\n if (!draggedNode) return () => {};\n const [, , , draggedNodeSetStyle] = draggedNode.node;\n draggedNodeSetStyle(HIDDEN_NODE_STYLE);\n return () => draggedNodeSetStyle({});\n }, [draggedNode]);\n\n // Append the blank node to the list to increase the height of it.\n // Used when the dragged node is located inside another list.\n const removeBlankNode = useBlankNode({\n draggedNode,\n targetList,\n initDraggedNodeRect,\n });\n\n const updateTargetNode = useCallback(() => {\n if (!draggedNode) return;\n const prevTargetNode = targetNodeRef.current; // The last updated node\n\n // Dragging outside the list\n if (\n prevTargetNode &&\n prevTargetNode.list === draggedNode.list &&\n targetList !== draggedNode.list\n ) {\n moveNode({\n list: prevTargetNode.list,\n startNode: prevTargetNode.node,\n type: 'down',\n untilTheEnd: true,\n });\n clearTargetNode();\n }\n\n // Dragging outside another list\n if (\n prevTargetNode &&\n prevTargetNode.list !== draggedNode.list &&\n targetList !== prevTargetNode.list\n ) {\n moveNode({\n list: prevTargetNode.list,\n startNode: prevTargetNode.node,\n type: 'down',\n untilTheEnd: true,\n insideAnotherList: true,\n });\n removeBlankNode();\n clearTargetNode();\n }\n\n // Dragging inside the list\n if (!prevTargetNode && targetList === draggedNode.list) {\n const tail = targetList.getTail();\n if (!tail) return;\n const node = moveNode({\n list: targetList,\n startNode: tail,\n type: 'up',\n });\n setTargetNode(targetList, node);\n return;\n }\n\n // Dragging inside another list\n if (\n targetList &&\n targetList !== draggedNode.list &&\n prevTargetNode?.list !== targetList\n ) {\n const tail = targetList.getTail();\n if (!tail) return;\n const node = moveNode({\n list: targetList,\n startNode: tail,\n type: 'up',\n insideAnotherList: true,\n });\n setTargetNode(targetList, node);\n return;\n }\n\n // Dragging in the same list\n if (\n prevTargetNode &&\n prevTargetNode.list === draggedNode.list &&\n targetList === draggedNode.list\n ) {\n const axis = targetList.horizontal ? 'x' : 'y';\n const [, , prevTargetNodeRef, ,] = prevTargetNode.node;\n if (!prevTargetNodeRef.current) {\n // The target node was unmounted. It happens when the virtual list is used.\n // If the cursor is above the dragged node, we need to move the nodes down from the tail to the node where\n // the cursor is located. Otherwise, we need to move the nodes up from the head to the node where the cursor\n // is located.\n const draggedNodePos = getDraggedNodePosRef.current();\n if (!position || !draggedNodePos) return;\n const isDraggingUp = position[axis] < draggedNodePos[axis];\n if (isDraggingUp) {\n const tail = targetList.getTail();\n if (!tail || !tail[2].current) return;\n const node = moveNode({\n list: targetList,\n startNode: createEmptyNode({ prev: tail }),\n type: 'up',\n });\n setTargetNode(targetList, node);\n } else {\n const head = targetList.getHead();\n if (!head || !head[2].current) return;\n const node = moveNode({\n list: targetList,\n startNode: createEmptyNode({ next: head }),\n type: 'down',\n });\n setTargetNode(targetList, node);\n }\n return;\n }\n const prevTargetNodeRect = getNodeRect(prevTargetNode.node[2]);\n const rectProp = targetList.horizontal ? 'left' : 'top';\n if (!position || !prevTargetNodeRect) return;\n const isMoveUp = position[axis] < prevTargetNodeRect[rectProp];\n const node = isMoveUp\n ? moveNode({\n list: targetList,\n startNode: prevTargetNode.node,\n type: 'up',\n })\n : moveNode({\n list: targetList,\n startNode: prevTargetNode.node,\n type: 'down',\n });\n setTargetNode(targetList, node);\n return;\n }\n\n // Dragging in another list\n if (\n targetList &&\n targetList !== draggedNode.list &&\n prevTargetNode?.list === targetList\n ) {\n const axis = targetList.horizontal ? 'x' : 'y';\n const prevTargetNodeRect = getNodeRect(prevTargetNode.node[2]);\n const rectProp = targetList.horizontal ? 'left' : 'top';\n if (!position || !prevTargetNodeRect) return;\n const isMoveUp = position[axis] < prevTargetNodeRect[rectProp];\n const node = isMoveUp\n ? moveNode({\n list: targetList,\n startNode: prevTargetNode.node,\n type: 'up',\n insideAnotherList: true,\n })\n : moveNode({\n list: targetList,\n startNode: prevTargetNode.node,\n type: 'down',\n insideAnotherList: true,\n });\n setTargetNode(targetList, node);\n }\n }, [\n draggedNode,\n targetList,\n moveNode,\n clearTargetNode,\n removeBlankNode,\n setTargetNode,\n position,\n ]);\n\n // Update the target node if either the position or the target list has been changed\n useEffect(() => {\n updateTargetNode();\n }, [updateTargetNode]);\n\n // Update the target node if the target list has been scrolled\n const [throttledUpdateTargetNode] = useThrottle(updateTargetNode, 100);\n useEvent(targetList?.ref as any, 'scroll', throttledUpdateTargetNode);\n useEvent(window, 'scroll', throttledUpdateTargetNode);\n\n // Reset styles of the nodes when the dragged node was dropped\n useEffect(() => {\n if (!draggedNode) return () => {};\n const [, , , , draggedNodeIndex] = draggedNode.node;\n return () => {\n const targetNode = targetNodeRef.current;\n\n // If the dragged node was inside another list, reset the styles for the nodes,\n // starting at the tail and ending with the dragged node.\n if (targetNode && targetNode.list !== draggedNode.list) {\n const tail = targetNode.list.getTail();\n if (!tail) return;\n let node = tail;\n while (true) {\n const [prev, , , nodeSetStyle, nodeIndex] = node;\n nodeSetStyle({});\n if (!prev || nodeIndex <= draggedNodeIndex) break;\n node = prev;\n }\n }\n\n // If the dragged node was outside the origin list, reset the styles for the nodes,\n // starting at the tail and ending with the dragged node.\n const tail = draggedNode.list.getTail();\n if (targetNode?.list !== draggedNode.list && tail) {\n let node = tail;\n while (true) {\n const [prev, , , nodeSetStyle, nodeIndex] = node;\n nodeSetStyle({});\n if (!prev || nodeIndex <= draggedNodeIndex) break;\n node = prev;\n }\n }\n\n if (!targetNode) return;\n const [, , , targetNodeSetStyle, targetNodeIndex] = targetNode.node;\n if (targetNodeIndex > draggedNodeIndex) {\n let { node } = targetNode;\n while (true) {\n const [prev, , , nodeSetStyle, nodeIndex] = node;\n nodeSetStyle({});\n if (!prev || nodeIndex < draggedNodeIndex) return;\n node = prev;\n }\n }\n if (targetNodeIndex < draggedNodeIndex) {\n let { node } = targetNode;\n while (true) {\n const [, next, , nodeSetStyle, nodeIndex] = node;\n nodeSetStyle({});\n if (!next || nodeIndex > draggedNodeIndex) return;\n node = next;\n }\n }\n if (targetNodeIndex === draggedNodeIndex) {\n targetNodeSetStyle({});\n }\n };\n }, [draggedNode]);\n\n // Update the position of the mounted nodes between the dragged and target nodes (used in virtual list)\n useEffect(() => {\n if (!draggedNode) return () => {};\n const [, , , , draggedNodeIndex] = draggedNode.node;\n const update = (nodeProps: NodeProps) => {\n const { setStyle, index } = nodeProps;\n const targetNode = targetNodeRef.current;\n\n // If the dragged node outside the origin list\n if (\n targetNodeRef.current?.list !== draggedNode.list &&\n index > draggedNodeIndex\n ) {\n setStyle(getNodeStyle('up', draggedNode.list.horizontal));\n return;\n }\n\n if (!targetNode || !targetNode.node) return;\n const [, , , , targetNodeIndex] = targetNode.node;\n // If the dragged node was mounted\n if (index === draggedNodeIndex) {\n setStyle(HIDDEN_NODE_STYLE);\n return;\n }\n // If the node between the dragged and target nodes was mounted\n if (index > draggedNodeIndex && index < targetNodeIndex) {\n setStyle(getNodeStyle('up', targetNode.list.horizontal));\n } else if (index < draggedNodeIndex && index > targetNodeIndex) {\n setStyle(getNodeStyle('down', targetNode.list.horizontal));\n }\n };\n draggedNode.list.addListener(update);\n return () => draggedNode.list.removeListener(update);\n }, [draggedNode, getNodeStyle]);\n\n useEffect(() => {\n if (!draggedNode || !targetList || targetList === draggedNode.list) {\n return () => {};\n }\n const update = (nodeProps: NodeProps) => {\n const { setStyle, index } = nodeProps;\n const targetNode = targetNodeRef.current;\n if (!targetNode) return;\n const [, , , , targetNodeIndex] = targetNode.node;\n if (index < targetNodeIndex) return;\n setStyle(getNodeStyle('down', targetList.horizontal));\n };\n targetList.addListener(update);\n return () => targetList.removeListener(update);\n }, [draggedNode, getNodeStyle, targetList]);\n\n // Call the onDragEnd callback if the draggedNode was changed to null\n useEffect(() => {\n if (!draggedNode) return () => {};\n return () => {\n // eslint-disable-next-line react-hooks/exhaustive-deps\n const target = targetRef.current;\n if (!target) return;\n const [, , , , draggedNodeIndex] = draggedNode.node;\n const dragged = { id: draggedNode.list.id, index: draggedNodeIndex };\n if (dragged.id === target.id && dragged.index === target.index) return;\n onDragEndRef.current(dragged, target);\n };\n }, [draggedNode]);\n};\n\nexport default useDragEffect;\n"],"file":"useDragEffect.js"}
1
+ {"version":3,"sources":["../../../src/utils/useDragEffect.ts"],"names":["useCallback","useEffect","useMemo","useRef","useThrottle","useEvent","getElementScroll","useTargetList","useInitRect","useInitScrollOffset","useGetNodeStyle","useMoveNode","getNodeRect","useBlankNode","HIDDEN_NODE_STYLE","opacity","pointerEvents","createEmptyNode","prev","next","current","useDragEffect","props","draggedNode","cursorPosition","listStoreRef","onDragEnd","targetRef","targetNodeRef","onDragEndRef","initDraggedNodeRect","node","undefined","initDraggedNodeListScrollOffset","list","ref","position","x","y","initWidth","initHeight","targetList","getNodeStyle","moveNode","setTargetNode","nodeIndex","id","index","clearTargetNode","getDraggedNodePos","initX","initY","initScrollLeft","initScrollTop","scrollLeft","scrollTop","getDraggedNodePosRef","draggedNodeSetStyle","removeBlankNode","updateTargetNode","prevTargetNode","startNode","direction","destination","isAnotherList","tail","getTail","axis","horizontal","prevTargetNodeRef","draggedNodePos","isDraggingUp","head","getHead","prevTargetNodeRect","startRectProp","isMoveUp","throttledUpdateTargetNode","window","draggedNodeIndex","targetNode","nodeSetStyle","targetNodeIndex","targetNodeSetStyle","update","nodeProps","setStyle","addListener","removeListener","target","dragged"],"mappings":"AACA,SAGEA,WAHF,EAIEC,SAJF,EAKEC,OALF,EAMEC,MANF,QAOO,OAPP;AAQA,OAAOC,WAAP,MAAwB,yBAAxB;AACA,OAAOC,QAAP,MAAqB,sBAArB;AAGA,OAAOC,gBAAP,MAA6B,oBAA7B;AACA,OAAOC,aAAP,MAA0B,iBAA1B;AACA,OAAOC,WAAP,MAAwB,eAAxB;AACA,OAAOC,mBAAP,MAAgC,uBAAhC;AACA,OAAOC,eAAP,MAA4B,mBAA5B;AACA,OAAOC,WAAP,MAAwB,eAAxB;AACA,OAAOC,WAAP,MAAwB,eAAxB;AACA,OAAOC,YAAP,MAAyB,gBAAzB;AA8BA,MAAMC,iBAAgC,GAAG;AACvCC,EAAAA,OAAO,EAAE,CAD8B;AAEvCC,EAAAA,aAAa,EAAE;AAFwB,CAAzC;;AAKA,MAAMC,eAAe,GAAG,CAAC;AACvBC,EAAAA,IAAI,GAAG,IADgB;AAEvBC,EA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IAAImC,eAAb,EAA8B;AAC5B;AACAI,QAAAA,QAAQ,CAAC5C,YAAY,CAAC,MAAD,EAASD,UAAU,CAAC2B,UAApB,CAAb,CAAR;AACD;AACF,KATD;;AAWA3B,IAAAA,UAAU,CAAC8C,WAAX,CAAuBH,MAAvB;AACA,WAAO,MAAM3C,UAAU,CAAC+C,cAAX,CAA0BJ,MAA1B,CAAb;AACD,GAlBQ,EAkBN,CAAC7D,WAAD,EAAcmB,YAAd,EAA4BD,UAA5B,CAlBM,CAAT,CA5XmD,CAgZnD;;AACAxC,EAAAA,SAAS,CAAC,MAAM;AACd,QAAI,CAACsB,WAAL,EAAkB,OAAO,MAAM,CAAE,CAAf;AAClB,WAAO,MAAM;AACX;AACA,YAAMkE,MAAM,GAAG9D,SAAS,CAACP,OAAzB;AACA,UAAI,CAACqE,MAAL,EAAa;AACb,YAAM,MAASV,gBAAT,IAA6BxD,WAAW,CAACQ,IAA/C;AACA,YAAM2D,OAAO,GAAG;AAAE5C,QAAAA,EAAE,EAAEvB,WAAW,CAACW,IAAZ,CAAiBY,EAAvB;AAA2BC,QAAAA,KAAK,EAAEgC;AAAlC,OAAhB;AACA,UAAIW,OAAO,CAAC5C,EAAR,KAAe2C,MAAM,CAAC3C,EAAtB,IAA4B4C,OAAO,CAAC3C,KAAR,KAAkB0C,MAAM,CAAC1C,KAAzD,EAAgE;AAChElB,MAAAA,YAAY,CAACT,OAAb,CAAqBsE,OAArB,EAA8BD,MAA9B;AACD,KARD;AASD,GAXQ,EAWN,CAAClE,WAAD,CAXM,CAAT;AAYD,CA7ZD;;AA+ZA,eAAeF,aAAf","sourcesContent":["import { Position } from '@os-design/use-drag';\nimport {\n CSSProperties,\n RefObject,\n useCallback,\n useEffect,\n useMemo,\n useRef,\n} from 'react';\nimport useThrottle from '@os-design/use-throttle';\nimport useEvent from '@os-design/use-event';\nimport NodeList, { ExistingNode, Node, NodeProps } from './NodeList';\nimport ListStore from './ListStore';\nimport getElementScroll from './getElementScroll';\nimport useTargetList from './useTargetList';\nimport useInitRect from './useInitRect';\nimport useInitScrollOffset from './useInitScrollOffset';\nimport useGetNodeStyle from './useGetNodeStyle';\nimport useMoveNode from './useMoveNode';\nimport getNodeRect from './getNodeRect';\nimport useBlankNode from './useBlankNode';\n\nexport interface DraggedNode {\n list: NodeList;\n node: ExistingNode;\n position: Position;\n}\n\ninterface TargetNode {\n list: NodeList;\n node: ExistingNode;\n}\n\nexport interface ItemLocation {\n id: string;\n index: number;\n}\n\nexport type DragEndHandler = (\n dragged: ItemLocation,\n target: ItemLocation\n) => void;\n\ninterface UseDragEffectProps {\n draggedNode: DraggedNode | null;\n cursorPosition: Position;\n listStoreRef: RefObject<ListStore>;\n onDragEnd: DragEndHandler;\n}\n\nconst HIDDEN_NODE_STYLE: CSSProperties = {\n opacity: 0,\n pointerEvents: 'none',\n};\n\nconst createEmptyNode = ({\n prev = null,\n next = null,\n}: {\n prev?: Node;\n next?: Node;\n}): ExistingNode => [prev, next, { current: null }, () => {}, -1];\n\n/* eslint-disable no-constant-condition */\n\nconst useDragEffect = (props: UseDragEffectProps) => {\n const { draggedNode, cursorPosition, listStoreRef, onDragEnd } = props;\n\n const targetRef = useRef<ItemLocation | null>(null);\n const targetNodeRef = useRef<TargetNode | null>(draggedNode);\n\n useEffect(() => {\n targetNodeRef.current = draggedNode;\n }, [draggedNode]);\n\n const onDragEndRef = useRef(onDragEnd);\n useEffect(() => {\n onDragEndRef.current = onDragEnd;\n }, [onDragEnd]);\n\n // The initial bounds of the dragged node.\n // We can't read the bounds of the dragged node on the fly because the node can be unmounted in the virtual list.\n const initDraggedNodeRect = useInitRect(\n draggedNode ? draggedNode.node[2] : undefined\n );\n\n // The initial scroll position of the list where the dragged node is located.\n // Used to detect the actual position of the dragged node. The purpose is the same as with initDraggedNodeRect.\n const initDraggedNodeListScrollOffset = useInitScrollOffset(\n draggedNode ? draggedNode.list.ref : undefined\n );\n\n // The central position of the dragged node\n const position = useMemo(() => {\n if (!draggedNode || !initDraggedNodeRect) return null;\n const { x, y } = cursorPosition;\n const { initWidth, initHeight } = initDraggedNodeRect;\n return {\n x: x - draggedNode.position.x + initWidth / 2,\n y: y - draggedNode.position.y + initHeight / 2,\n };\n }, [cursorPosition, draggedNode, initDraggedNodeRect]);\n\n // The list in which the cursor is located\n const targetList = useTargetList(position, listStoreRef);\n\n // Returns the style for moving the node in the specified direction\n const getNodeStyle = useGetNodeStyle(initDraggedNodeRect);\n\n // Moves the node up or down\n const moveNode = useMoveNode({ position, draggedNode, getNodeStyle });\n\n const setTargetNode = useCallback((list: NodeList, node: ExistingNode) => {\n const [, , , , nodeIndex] = node;\n targetNodeRef.current = { list, node };\n targetRef.current = { id: list.id, index: nodeIndex };\n }, []);\n\n const clearTargetNode = useCallback(() => {\n targetNodeRef.current = null;\n targetRef.current = null;\n }, []);\n\n // Returns the central position of the dragged node in the list\n const getDraggedNodePos = useCallback(() => {\n if (\n !targetList ||\n !targetList.ref.current ||\n !initDraggedNodeRect ||\n !initDraggedNodeListScrollOffset\n ) {\n return null;\n }\n const { initX, initY, initWidth, initHeight } = initDraggedNodeRect;\n const { initScrollLeft, initScrollTop } = initDraggedNodeListScrollOffset;\n const { scrollLeft, scrollTop } = getElementScroll(targetList.ref.current);\n return {\n x: initX + initWidth / 2 + initScrollLeft - scrollLeft,\n y: initY + initHeight / 2 + initScrollTop - scrollTop,\n };\n }, [initDraggedNodeListScrollOffset, initDraggedNodeRect, targetList]);\n\n const getDraggedNodePosRef = useRef(getDraggedNodePos);\n useEffect(() => {\n getDraggedNodePosRef.current = getDraggedNodePos;\n }, [getDraggedNodePos]);\n\n // Hide the dragged node\n useEffect(() => {\n if (!draggedNode) return () => {};\n const [, , , draggedNodeSetStyle] = draggedNode.node;\n draggedNodeSetStyle(HIDDEN_NODE_STYLE);\n return () => draggedNodeSetStyle({});\n }, [draggedNode]);\n\n // Append the blank node to the list to increase the height of it.\n // Used when the dragged node is located inside another list.\n const removeBlankNode = useBlankNode({\n draggedNode,\n targetList,\n initDraggedNodeRect,\n });\n\n const updateTargetNode = useCallback(() => {\n if (!draggedNode) return;\n const prevTargetNode = targetNodeRef.current; // The last updated node\n\n // Dragging outside the origin list\n if (\n prevTargetNode &&\n prevTargetNode.list === draggedNode.list &&\n targetList !== draggedNode.list\n ) {\n moveNode({\n list: prevTargetNode.list,\n startNode: prevTargetNode.node,\n direction: 'down',\n destination: 'end',\n });\n clearTargetNode();\n }\n\n // Dragging outside another list\n if (\n prevTargetNode &&\n prevTargetNode.list !== draggedNode.list &&\n targetList !== prevTargetNode.list\n ) {\n moveNode({\n list: prevTargetNode.list,\n startNode: prevTargetNode.node,\n direction: 'down',\n destination: 'end',\n isAnotherList: true,\n });\n removeBlankNode();\n clearTargetNode();\n }\n\n // Dragging inside the origin list\n if (!prevTargetNode && targetList === draggedNode.list) {\n const tail = targetList.getTail();\n if (!tail) return;\n const node = moveNode({\n list: targetList,\n startNode: tail,\n direction: 'up',\n destination: 'cursor',\n });\n setTargetNode(targetList, node);\n return;\n }\n\n // Dragging inside another list\n if (\n targetList &&\n targetList !== draggedNode.list &&\n (!prevTargetNode || prevTargetNode.list !== targetList)\n ) {\n const tail = targetList.getTail();\n if (!tail) return;\n const node = moveNode({\n list: targetList,\n startNode: tail,\n direction: 'up',\n destination: 'cursor',\n isAnotherList: true,\n });\n setTargetNode(targetList, node);\n return;\n }\n\n // Dragging in the origin list\n if (\n prevTargetNode &&\n prevTargetNode.list === draggedNode.list &&\n targetList === draggedNode.list\n ) {\n const axis = targetList.horizontal ? 'x' : 'y';\n const [, , prevTargetNodeRef, ,] = prevTargetNode.node;\n if (!prevTargetNodeRef.current) {\n // The target node was unmounted. It happens when the virtual list is used.\n // If the cursor is above the dragged node, we need to move the nodes down from the tail to the node where\n // the cursor is located. Otherwise, we need to move the nodes up from the head to the node where the cursor\n // is located.\n const draggedNodePos = getDraggedNodePosRef.current();\n if (!position || !draggedNodePos) return;\n const isDraggingUp = position[axis] < draggedNodePos[axis];\n if (isDraggingUp) {\n const tail = targetList.getTail();\n if (!tail || !tail[2].current) return;\n const node = moveNode({\n list: targetList,\n startNode: createEmptyNode({ prev: tail }),\n direction: 'up',\n destination: 'cursor',\n });\n setTargetNode(targetList, node);\n } else {\n const head = targetList.getHead();\n if (!head || !head[2].current) return;\n const node = moveNode({\n list: targetList,\n startNode: createEmptyNode({ next: head }),\n direction: 'down',\n destination: 'cursor',\n });\n setTargetNode(targetList, node);\n }\n return;\n }\n const prevTargetNodeRect = getNodeRect(prevTargetNode.node[2]);\n const startRectProp = targetList.horizontal ? 'left' : 'top';\n if (!position || !prevTargetNodeRect) return;\n const isMoveUp = position[axis] < prevTargetNodeRect[startRectProp];\n const node = isMoveUp\n ? moveNode({\n list: targetList,\n startNode: prevTargetNode.node,\n direction: 'up',\n destination: 'cursor',\n })\n : moveNode({\n list: targetList,\n startNode: prevTargetNode.node,\n direction: 'down',\n destination: 'cursor',\n });\n setTargetNode(targetList, node);\n return;\n }\n\n // Dragging in another list\n if (\n targetList &&\n targetList !== draggedNode.list &&\n prevTargetNode &&\n prevTargetNode.list === targetList\n ) {\n const axis = targetList.horizontal ? 'x' : 'y';\n const prevTargetNodeRect = getNodeRect(prevTargetNode.node[2]);\n const startRectProp = targetList.horizontal ? 'left' : 'top';\n if (!position || !prevTargetNodeRect) return;\n const isMoveUp = position[axis] < prevTargetNodeRect[startRectProp];\n const node = isMoveUp\n ? moveNode({\n list: targetList,\n startNode: prevTargetNode.node,\n direction: 'up',\n destination: 'cursor',\n isAnotherList: true,\n })\n : moveNode({\n list: targetList,\n startNode: prevTargetNode.node,\n direction: 'down',\n destination: 'cursor',\n isAnotherList: true,\n });\n setTargetNode(targetList, node);\n }\n }, [\n draggedNode,\n targetList,\n moveNode,\n clearTargetNode,\n removeBlankNode,\n setTargetNode,\n position,\n ]);\n\n // Update the target node if either the position or the target list has been changed\n useEffect(() => {\n updateTargetNode();\n }, [updateTargetNode]);\n\n // Update the target node if the target list has been scrolled\n const [throttledUpdateTargetNode] = useThrottle(updateTargetNode, 100);\n useEvent(\n (targetList ? targetList.ref : undefined) as unknown as EventTarget,\n 'scroll',\n throttledUpdateTargetNode\n );\n useEvent(window, 'scroll', throttledUpdateTargetNode);\n\n // Reset styles of the affected nodes when the dragged node was dropped\n useEffect(() => {\n if (!draggedNode) return () => {};\n const [, , , , draggedNodeIndex] = draggedNode.node;\n return () => {\n const targetNode = targetNodeRef.current;\n\n // If the dragged node was outside the origin list, reset the styles for the nodes,\n // starting at the tail and ending with the dragged node in the origin list.\n if (!targetNode || targetNode.list !== draggedNode.list) {\n const tail = draggedNode.list.getTail();\n if (tail) {\n let node = tail;\n while (true) {\n const [prev, , , nodeSetStyle, nodeIndex] = node;\n nodeSetStyle({});\n if (!prev || nodeIndex <= draggedNodeIndex) break;\n node = prev;\n }\n }\n }\n\n // If the dragged node was inside another list, reset the styles for the nodes,\n // starting at the tail and ending with the dragged node in the target list.\n if (targetNode && targetNode.list !== draggedNode.list) {\n const tail = targetNode.list.getTail();\n const [, , , , targetNodeIndex] = targetNode.node;\n if (tail) {\n let node = tail;\n while (true) {\n const [prev, , , nodeSetStyle, nodeIndex] = node;\n nodeSetStyle({});\n if (!prev || nodeIndex <= targetNodeIndex) break;\n node = prev;\n }\n }\n }\n\n // If the dragged node was moved inside the origin list, reset the styles for the nodes,\n // starting with target node and ending with the dragged node.\n if (targetNode && targetNode.list === draggedNode.list) {\n const [, , , targetNodeSetStyle, targetNodeIndex] = targetNode.node;\n if (targetNodeIndex > draggedNodeIndex) {\n let { node } = targetNode;\n while (true) {\n const [prev, , , nodeSetStyle, nodeIndex] = node;\n nodeSetStyle({});\n if (!prev || nodeIndex <= draggedNodeIndex) break;\n node = prev;\n }\n } else if (targetNodeIndex < draggedNodeIndex) {\n let { node } = targetNode;\n while (true) {\n const [, next, , nodeSetStyle, nodeIndex] = node;\n nodeSetStyle({});\n if (!next || nodeIndex >= draggedNodeIndex) break;\n node = next;\n }\n } else if (targetNodeIndex === draggedNodeIndex) {\n targetNodeSetStyle({});\n }\n }\n };\n }, [draggedNode]);\n\n // Update the position of the newly mounted nodes in the origin list (used in the virtual list)\n useEffect(() => {\n if (!draggedNode) return () => {};\n const [, , , , draggedNodeIndex] = draggedNode.node;\n\n const update = (nodeProps: NodeProps) => {\n const { setStyle, index } = nodeProps;\n const targetNode = targetNodeRef.current;\n\n // Set the hidden style, if the mounted node is the dragged node\n if (index === draggedNodeIndex) {\n setStyle(HIDDEN_NODE_STYLE);\n return;\n }\n\n // If the dragged node is inside the origin list\n if (targetNode && targetNode.list === draggedNode.list) {\n // Move the mounted node up/down, if it is located between the dragged and target node\n const [, , , , targetNodeIndex] = targetNode.node;\n if (index > draggedNodeIndex && index < targetNodeIndex) {\n setStyle(getNodeStyle('up', targetNode.list.horizontal));\n } else if (index < draggedNodeIndex && index > targetNodeIndex) {\n setStyle(getNodeStyle('down', targetNode.list.horizontal));\n }\n } else if (index > draggedNodeIndex) {\n // Otherwise, move the mounted node up, if it is located below the dragged node\n setStyle(getNodeStyle('up', draggedNode.list.horizontal));\n }\n };\n\n draggedNode.list.addListener(update);\n return () => draggedNode.list.removeListener(update);\n }, [draggedNode, getNodeStyle]);\n\n // Update the position of the newly mounted nodes in the target list (used in the virtual list)\n useEffect(() => {\n if (!draggedNode || !targetList || targetList === draggedNode.list) {\n return () => {};\n }\n\n const update = (nodeProps: NodeProps) => {\n const { setStyle, index } = nodeProps;\n const targetNode = targetNodeRef.current;\n if (!targetNode) return;\n const [, , , , targetNodeIndex] = targetNode.node;\n if (index >= targetNodeIndex) {\n // Move the mounted node down, if it is located below the target node or if it is the target node\n setStyle(getNodeStyle('down', targetList.horizontal));\n }\n };\n\n targetList.addListener(update);\n return () => targetList.removeListener(update);\n }, [draggedNode, getNodeStyle, targetList]);\n\n // Call the onDragEnd callback if the draggedNode was changed to null\n useEffect(() => {\n if (!draggedNode) return () => {};\n return () => {\n // eslint-disable-next-line react-hooks/exhaustive-deps\n const target = targetRef.current;\n if (!target) return;\n const [, , , , draggedNodeIndex] = draggedNode.node;\n const dragged = { id: draggedNode.list.id, index: draggedNodeIndex };\n if (dragged.id === target.id && dragged.index === target.index) return;\n onDragEndRef.current(dragged, target);\n };\n }, [draggedNode]);\n};\n\nexport default useDragEffect;\n"],"file":"useDragEffect.js"}
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../src/utils/useInitRect.ts"],"names":["useMemo","useInitRect","ref","current","rect","getBoundingClientRect","initX","x","initY","y","initWidth","width","initHeight","height"],"mappings":"AAAA,SAAoBA,OAApB,QAAmC,OAAnC;;AAEA,MAAMC,WAAW,GAAIC,GAAD,IAClBF,OAAO,CAAC,MAAM;AACZ,MAAI,CAACE,GAAD,IAAQ,CAACA,GAAG,CAACC,OAAjB,EAA0B,OAAO,IAAP;AAC1B,QAAMC,IAAI,GAAGF,GAAG,CAACC,OAAJ,CAAYE,qBAAZ,EAAb;AACA,SAAO;AACLC,IAAAA,KAAK,EAAEF,IAAI,CAACG,CADP;AAELC,IAAAA,KAAK,EAAEJ,IAAI,CAACK,CAFP;AAGLC,IAAAA,SAAS,EAAEN,IAAI,CAACO,KAHX;AAILC,IAAAA,UAAU,EAAER,IAAI,CAACS;AAJZ,GAAP;AAMD,CATM,EASJ,CAACX,GAAD,CATI,CADT;;AAYA,eAAeD,WAAf","sourcesContent":["import { RefObject, useMemo } from 'react';\n\nconst useInitRect = (ref?: RefObject<HTMLElement>) =>\n useMemo(() => {\n if (!ref || !ref.current) return null;\n const rect = ref.current.getBoundingClientRect();\n return {\n initX: rect.x,\n initY: rect.y,\n initWidth: rect.width,\n initHeight: rect.height,\n };\n }, [ref]);\n\nexport default useInitRect;\n"],"file":"useInitRect.js"}
1
+ {"version":3,"sources":["../../../src/utils/useInitRect.ts"],"names":["useMemo","useInitRect","ref","current","rect","getBoundingClientRect","initX","x","initY","y","initWidth","width","initHeight","height"],"mappings":"AAAA,SAAoBA,OAApB,QAAmC,OAAnC;;AAEA,MAAMC,WAAW,GAAIC,GAAD,IAClBF,OAAO,CAAC,MAAM;AACZ,MAAI,CAACE,GAAD,IAAQ,CAACA,GAAG,CAACC,OAAjB,EAA0B,OAAO,IAAP;AAE1B,QAAMC,IAAI,GAAGF,GAAG,CAACC,OAAJ,CAAYE,qBAAZ,EAAb;AAEA,SAAO;AACLC,IAAAA,KAAK,EAAEF,IAAI,CAACG,CADP;AAELC,IAAAA,KAAK,EAAEJ,IAAI,CAACK,CAFP;AAGLC,IAAAA,SAAS,EAAEN,IAAI,CAACO,KAHX;AAILC,IAAAA,UAAU,EAAER,IAAI,CAACS;AAJZ,GAAP;AAMD,CAXM,EAWJ,CAACX,GAAD,CAXI,CADT;;AAcA,eAAeD,WAAf","sourcesContent":["import { RefObject, useMemo } from 'react';\n\nconst useInitRect = (ref?: RefObject<HTMLElement>) =>\n useMemo(() => {\n if (!ref || !ref.current) return null;\n\n const rect = ref.current.getBoundingClientRect();\n\n return {\n initX: rect.x,\n initY: rect.y,\n initWidth: rect.width,\n initHeight: rect.height,\n };\n }, [ref]);\n\nexport default useInitRect;\n"],"file":"useInitRect.js"}
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../src/utils/useInitScrollOffset.ts"],"names":["useMemo","getElementScroll","useInitScrollOffset","ref","current","scrollOffset","initScrollLeft","scrollLeft","initScrollTop","scrollTop"],"mappings":"AAAA,SAAoBA,OAApB,QAAmC,OAAnC;AACA,OAAOC,gBAAP,MAA6B,oBAA7B;;AAEA,MAAMC,mBAAmB,GAAIC,GAAD,IAC1BH,OAAO,CAAC,MAAM;AACZ,MAAI,CAACG,GAAD,IAAQ,CAACA,GAAG,CAACC,OAAjB,EAA0B,OAAO,IAAP;AAC1B,QAAMC,YAAY,GAAGJ,gBAAgB,CAACE,GAAG,CAACC,OAAL,CAArC;AACA,SAAO;AACLE,IAAAA,cAAc,EAAED,YAAY,CAACE,UADxB;AAELC,IAAAA,aAAa,EAAEH,YAAY,CAACI;AAFvB,GAAP;AAID,CAPM,EAOJ,CAACN,GAAD,CAPI,CADT;;AAUA,eAAeD,mBAAf","sourcesContent":["import { RefObject, useMemo } from 'react';\nimport getElementScroll from './getElementScroll';\n\nconst useInitScrollOffset = (ref?: RefObject<HTMLElement>) =>\n useMemo(() => {\n if (!ref || !ref.current) return null;\n const scrollOffset = getElementScroll(ref.current);\n return {\n initScrollLeft: scrollOffset.scrollLeft,\n initScrollTop: scrollOffset.scrollTop,\n };\n }, [ref]);\n\nexport default useInitScrollOffset;\n"],"file":"useInitScrollOffset.js"}
1
+ {"version":3,"sources":["../../../src/utils/useInitScrollOffset.ts"],"names":["useMemo","getElementScroll","useInitScrollOffset","ref","current","scrollOffset","initScrollLeft","scrollLeft","initScrollTop","scrollTop"],"mappings":"AAAA,SAAoBA,OAApB,QAAmC,OAAnC;AACA,OAAOC,gBAAP,MAA6B,oBAA7B;;AAEA,MAAMC,mBAAmB,GAAIC,GAAD,IAC1BH,OAAO,CAAC,MAAM;AACZ,MAAI,CAACG,GAAD,IAAQ,CAACA,GAAG,CAACC,OAAjB,EAA0B,OAAO,IAAP;AAE1B,QAAMC,YAAY,GAAGJ,gBAAgB,CAACE,GAAG,CAACC,OAAL,CAArC;AAEA,SAAO;AACLE,IAAAA,cAAc,EAAED,YAAY,CAACE,UADxB;AAELC,IAAAA,aAAa,EAAEH,YAAY,CAACI;AAFvB,GAAP;AAID,CATM,EASJ,CAACN,GAAD,CATI,CADT;;AAYA,eAAeD,mBAAf","sourcesContent":["import { RefObject, useMemo } from 'react';\nimport getElementScroll from './getElementScroll';\n\nconst useInitScrollOffset = (ref?: RefObject<HTMLElement>) =>\n useMemo(() => {\n if (!ref || !ref.current) return null;\n\n const scrollOffset = getElementScroll(ref.current);\n\n return {\n initScrollLeft: scrollOffset.scrollLeft,\n initScrollTop: scrollOffset.scrollTop,\n };\n }, [ref]);\n\nexport default useInitScrollOffset;\n"],"file":"useInitScrollOffset.js"}