Skip to content

Commit 25cd6ea

Browse files
committed
feat: move drag inbetween line down to targets child contents (#148)
1 parent 5f52497 commit 25cd6ea

File tree

3 files changed

+16
-1
lines changed

3 files changed

+16
-1
lines changed

packages/core/src/controlledEnvironment/useOnDragOverTreeHandler.ts

+10
Original file line numberDiff line numberDiff line change
@@ -231,6 +231,15 @@ export const useOnDragOverTreeHandler = (
231231

232232
let draggingPosition: DraggingPosition;
233233

234+
// Used to move the dragBetweenLine component down to the actual
235+
// end of the target item's contents, see #148
236+
const targetItemEndOfContents =
237+
offset === 'top'
238+
? 0
239+
: linearItems[treeId]
240+
.slice(linearIndex + 1)
241+
.findIndex(item => item.depth <= depth);
242+
234243
if (offset) {
235244
draggingPosition = {
236245
targetType: 'between-items',
@@ -242,6 +251,7 @@ export const useOnDragOverTreeHandler = (
242251
// childIndex: environment.items[parent.item].children!.indexOf(targetItem.item) + (offset === 'top' ? 0 : 1),
243252
childIndex: newChildIndex,
244253
linePosition: offset,
254+
targetItemEndOfContents,
245255
};
246256
} else {
247257
draggingPosition = {

packages/core/src/tree/DragBetweenLine.tsx

+5-1
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,10 @@ export const DragBetweenLine: React.FC<{
1818
return null;
1919
}
2020

21+
const position =
22+
(draggingPosition?.linearIndex ?? 0) +
23+
(draggingPosition.targetItemEndOfContents ?? 0);
24+
2125
const lineProps: HTMLProps<any> = {
2226
onDragOver: e => e.preventDefault(), // Allow dropping
2327
};
@@ -28,7 +32,7 @@ export const DragBetweenLine: React.FC<{
2832
position: 'absolute',
2933
left: '0',
3034
right: '0',
31-
top: `${(draggingPosition?.linearIndex ?? 0) * itemHeight}px`,
35+
top: `${position * itemHeight}px`,
3236
}}
3337
>
3438
{renderers.renderDragBetweenLine({

packages/core/src/types.ts

+1
Original file line numberDiff line numberDiff line change
@@ -323,6 +323,7 @@ export interface DraggingPositionBetweenItems extends AbstractDraggingPosition {
323323
childIndex: number;
324324
linePosition: 'top' | 'bottom';
325325
parentItem: TreeItemIndex;
326+
targetItemEndOfContents: number;
326327
}
327328

328329
export interface DraggingPositionRoot extends AbstractDraggingPosition {

0 commit comments

Comments
 (0)