Skip to content

Commit

Permalink
feat: move drag inbetween line down to targets child contents (#148)
Browse files Browse the repository at this point in the history
  • Loading branch information
lukasbach committed Nov 27, 2023
1 parent 5f52497 commit 25cd6ea
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -231,6 +231,15 @@ export const useOnDragOverTreeHandler = (

let draggingPosition: DraggingPosition;

// Used to move the dragBetweenLine component down to the actual
// end of the target item's contents, see #148
const targetItemEndOfContents =
offset === 'top'
? 0
: linearItems[treeId]
.slice(linearIndex + 1)
.findIndex(item => item.depth <= depth);

if (offset) {
draggingPosition = {
targetType: 'between-items',
Expand All @@ -242,6 +251,7 @@ export const useOnDragOverTreeHandler = (
// childIndex: environment.items[parent.item].children!.indexOf(targetItem.item) + (offset === 'top' ? 0 : 1),
childIndex: newChildIndex,
linePosition: offset,
targetItemEndOfContents,
};
} else {
draggingPosition = {
Expand Down
6 changes: 5 additions & 1 deletion packages/core/src/tree/DragBetweenLine.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,10 @@ export const DragBetweenLine: React.FC<{
return null;
}

const position =
(draggingPosition?.linearIndex ?? 0) +
(draggingPosition.targetItemEndOfContents ?? 0);

const lineProps: HTMLProps<any> = {
onDragOver: e => e.preventDefault(), // Allow dropping
};
Expand All @@ -28,7 +32,7 @@ export const DragBetweenLine: React.FC<{
position: 'absolute',
left: '0',
right: '0',
top: `${(draggingPosition?.linearIndex ?? 0) * itemHeight}px`,
top: `${position * itemHeight}px`,
}}
>
{renderers.renderDragBetweenLine({
Expand Down
1 change: 1 addition & 0 deletions packages/core/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -323,6 +323,7 @@ export interface DraggingPositionBetweenItems extends AbstractDraggingPosition {
childIndex: number;
linePosition: 'top' | 'bottom';
parentItem: TreeItemIndex;
targetItemEndOfContents: number;
}

export interface DraggingPositionRoot extends AbstractDraggingPosition {
Expand Down

0 comments on commit 25cd6ea

Please sign in to comment.