Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: drop as sibling to open folder #150

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 8 additions & 6 deletions packages/react-arborist/src/dnd/compute-drop.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,18 +60,19 @@ 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;
if (!aboveCursor) {
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;
}

Expand Down Expand Up @@ -150,16 +151,17 @@ 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),
};
}

/* 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: level === above.level + 1 ? dropAt(above?.id, 0) : walkUpFrom(above, level),
cursor: lineCursor(above.rowIndex! + 1, level),
};
}