Skip to content

Commit e1b9c75

Browse files
committed
feat: items dropped at space below tree are moved at root bottom-most position [#261]
1 parent dea964c commit e1b9c75

File tree

2 files changed

+20
-17
lines changed

2 files changed

+20
-17
lines changed

next-release-notes.md

+3-9
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,3 @@
1-
<!--
2-
### Breaking Changes
3-
4-
### Features
5-
6-
### Bug Fixes and Improvements
7-
8-
### Other Changes
9-
-->
1+
### Bug Fixes
2+
- Items dropped at the bottom most position (outside of the rectangle of tree items, but still inside the tree container)
3+
will now be placed in the root item, at the final position, instead of the contents of the last open item (#261)

packages/core/src/controlledEnvironment/useOnDragOverTreeHandler.ts

+17-8
Original file line numberDiff line numberDiff line change
@@ -29,9 +29,8 @@ const getHoveringPosition = (
2929
if (linearIndex > treeLinearItems.length - 1) {
3030
return {
3131
linearIndex: treeLinearItems.length - 1,
32-
targetItem: treeLinearItems[treeLinearItems.length - 1].item,
3332
offset: 'bottom',
34-
targetLinearItem: treeLinearItems[treeLinearItems.length - 1],
33+
veryBottom: true,
3534
} as const;
3635
}
3736

@@ -51,7 +50,7 @@ const getHoveringPosition = (
5150
offset = 'bottom';
5251
}
5352

54-
return { linearIndex, offset, targetItem, targetLinearItem };
53+
return { linearIndex, offset };
5554
};
5655

5756
const useIsDescendant = () => {
@@ -137,7 +136,8 @@ export const useOnDragOverTreeHandler = (
137136
return;
138137
}
139138

140-
let { linearIndex, offset } = getHoveringPosition(
139+
// eslint-disable-next-line prefer-const
140+
let { linearIndex, offset, veryBottom } = getHoveringPosition(
141141
e.clientY,
142142
treeBb.top,
143143
itemHeight,
@@ -151,7 +151,7 @@ export const useOnDragOverTreeHandler = (
151151

152152
const nextDragCode = outsideContainer
153153
? 'outside'
154-
: `${treeId}${linearIndex}${offset ?? ''}`;
154+
: `${treeId}${linearIndex}${offset ?? ''}${veryBottom && 'vb'}`;
155155

156156
if (lastDragCode === nextDragCode) {
157157
return;
@@ -244,15 +244,24 @@ export const useOnDragOverTreeHandler = (
244244

245245
let draggingPosition: DraggingPosition;
246246

247-
if (offset) {
247+
if (veryBottom) {
248+
const { rootItem } = trees[treeId];
249+
draggingPosition = {
250+
targetType: 'between-items',
251+
treeId,
252+
parentItem: rootItem,
253+
depth: 0,
254+
linearIndex: linearIndex + 1,
255+
childIndex: items[rootItem].children?.length ?? 0,
256+
linePosition: 'bottom',
257+
};
258+
} else if (offset) {
248259
draggingPosition = {
249260
targetType: 'between-items',
250261
treeId,
251262
parentItem: parent.item,
252263
depth: targetItem.depth,
253264
linearIndex: linearIndex + (offset === 'top' ? 0 : 1),
254-
// childIndex: linearIndex - parentLinearIndex - 1 + (offset === 'top' ? 0 : 1),
255-
// childIndex: environment.items[parent.item].children!.indexOf(targetItem.item) + (offset === 'top' ? 0 : 1),
256265
childIndex: newChildIndex,
257266
linePosition: offset,
258267
};

0 commit comments

Comments
 (0)