Skip to content

Commit d5341c3

Browse files
committed
feat: fallback if renderDepthOffset is not set (#148)
1 parent 64d8ee4 commit d5341c3

File tree

3 files changed

+17
-9
lines changed

3 files changed

+17
-9
lines changed

packages/core/src/drag/DraggingPositionEvaluation.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ export class DraggingPositionEvaluation {
2222

2323
private offset: 'bottom' | 'top' | undefined;
2424

25-
private indentation: number;
25+
private indentation: number | undefined;
2626

2727
private targetItem: LinearItem;
2828

@@ -82,6 +82,10 @@ export class DraggingPositionEvaluation {
8282
* the x-coordinate of the mouse allows to reparent upwards.
8383
*/
8484
private maybeReparentUpwards(): DraggingPosition | undefined {
85+
if (this.indentation === undefined) {
86+
return undefined;
87+
}
88+
8589
const treeLinearItems = this.env.linearItems[this.treeId];
8690
const deepestDepth = treeLinearItems[this.linearIndex].depth;
8791

packages/core/src/drag/useDraggingPosition.ts

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -80,13 +80,15 @@ export const useDraggingPosition = () => {
8080
const targetLinearItem = treeLinearItems[linearIndex];
8181
const targetItem = env.items[targetLinearItem.item];
8282

83-
const indentation = Math.min(
84-
Math.max(
85-
Math.floor((e.clientX - treeBb.left) / env.renderDepthOffset),
86-
0
87-
),
88-
targetLinearItem.depth
89-
);
83+
const indentation = !env.renderDepthOffset
84+
? undefined
85+
: Math.min(
86+
Math.max(
87+
Math.floor((e.clientX - treeBb.left) / env.renderDepthOffset),
88+
0
89+
),
90+
targetLinearItem.depth
91+
);
9092

9193
let offset: 'top' | 'bottom' | undefined;
9294

packages/core/src/types.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -523,5 +523,7 @@ export interface LiveDescriptors {
523523
export type HoveringPosition = {
524524
linearIndex: number;
525525
offset: 'bottom' | 'top' | undefined;
526-
indentation: number;
526+
527+
// is undefined if tree renderDepthOffset is not set or zero
528+
indentation: number | undefined;
527529
};

0 commit comments

Comments
 (0)