From 4a060b426a073e35c27bb3554fa836ca7b54743b Mon Sep 17 00:00:00 2001 From: cha0s Date: Tue, 13 Jun 2023 01:58:58 -0500 Subject: [PATCH 1/2] feat: drop as sibling to open folder --- packages/react-arborist/src/dnd/compute-drop.ts | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/packages/react-arborist/src/dnd/compute-drop.ts b/packages/react-arborist/src/dnd/compute-drop.ts index 5f00dbc..736bef0 100644 --- a/packages/react-arborist/src/dnd/compute-drop.ts +++ b/packages/react-arborist/src/dnd/compute-drop.ts @@ -60,7 +60,8 @@ function getDropLevel( hovering: HoverData, aboveCursor: NodeApi | null, belowCursor: NodeApi | null, - indent: number + indent: number, + isAboveNodeOpen: boolean ) { const hoverLevel = Math.round(Math.max(0, hovering.x - indent) / indent); let min, max; @@ -68,10 +69,10 @@ function getDropLevel( max = 0; min = 0; } else if (!belowCursor) { - max = aboveCursor.level; + max = aboveCursor.level + (isAboveNodeOpen ? 1 : 0); min = 0; } else { - max = aboveCursor.level; + max = aboveCursor.level + (isAboveNodeOpen ? 1 : 0); min = belowCursor.level; } @@ -150,7 +151,7 @@ export function computeDrop(args: Args): ComputedDrop { /* The above node is an item or a closed folder */ if (isItem(above) || isClosed(above)) { - const level = getDropLevel(hover, above, below, args.indent); + const level = getDropLevel(hover, above, below, args.indent, false); return { drop: walkUpFrom(above, level), cursor: lineCursor(above.rowIndex! + 1, level), @@ -158,8 +159,9 @@ export function computeDrop(args: Args): ComputedDrop { } /* The above node is an open folder */ + const level = getDropLevel(hover, above, below, args.indent, true); return { - drop: dropAt(above?.id, 0), - cursor: lineCursor(above.rowIndex! + 1, above.level + 1), + drop: walkUpFrom(above, level), + cursor: lineCursor(above.rowIndex! + 1, level), }; } From a9dc368ccd1316d2a70ce6919f50fcfacc45d37b Mon Sep 17 00:00:00 2001 From: cha0s Date: Tue, 13 Jun 2023 02:29:31 -0500 Subject: [PATCH 2/2] fix: check drop level --- packages/react-arborist/src/dnd/compute-drop.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/react-arborist/src/dnd/compute-drop.ts b/packages/react-arborist/src/dnd/compute-drop.ts index 736bef0..f47627b 100644 --- a/packages/react-arborist/src/dnd/compute-drop.ts +++ b/packages/react-arborist/src/dnd/compute-drop.ts @@ -161,7 +161,7 @@ export function computeDrop(args: Args): ComputedDrop { /* The above node is an open folder */ const level = getDropLevel(hover, above, below, args.indent, true); return { - drop: walkUpFrom(above, level), + drop: level === above.level + 1 ? dropAt(above?.id, 0) : walkUpFrom(above, level), cursor: lineCursor(above.rowIndex! + 1, level), }; }