@@ -18,44 +18,60 @@ export class DropPositionEvaluation {
18
18
19
19
private getParentOfLinearItem : ReturnType < typeof useGetGetParentOfLinearItem > ;
20
20
21
- public readonly draggingItems : TreeItem [ ] | undefined ; // TODO make private again
21
+ private dragCode = 'initial' ;
22
22
23
- public readonly itemHeight : number ; // TODO should maybe be calculated inside, when dragging starts/class is instantiated
23
+ public readonly draggingItems : TreeItem [ ] | undefined ;
24
+
25
+ public readonly itemHeight : number ;
24
26
25
27
constructor (
26
- // TODO direct variables didnt work with the current ts version
27
28
env : TreeEnvironmentContextProps ,
28
29
getParentOfLinearItem : ReturnType < typeof useGetGetParentOfLinearItem > ,
29
- draggingItems : TreeItem [ ] | undefined , // TODO make private again
30
- itemHeight : number // TODO should maybe be calculated inside, when dragging starts/class is instantiated
30
+ draggingItems : TreeItem [ ] | undefined ,
31
+ itemHeight : number
31
32
) {
32
33
this . env = env ;
33
34
this . getParentOfLinearItem = getParentOfLinearItem ;
34
35
this . draggingItems = draggingItems ;
35
36
this . itemHeight = itemHeight ;
36
37
}
37
38
38
- getDragCode (
39
+ isNewDragPosition (
39
40
e : DragEvent ,
40
41
treeId : string ,
41
42
hoveringPosition : HoveringPosition | undefined
42
43
) {
43
44
if ( ! hoveringPosition ) {
44
- return 'invalidhover' ;
45
+ return false ;
45
46
}
46
47
const { offset, linearIndex, veryBottom } = hoveringPosition ;
47
48
48
- return `${ treeId } ${ linearIndex } ${ offset ?? '' } ${ veryBottom && 'vb' } ` ;
49
+ const newDragCode = `${ treeId } ${ linearIndex } ${ offset ?? '' } ${
50
+ veryBottom && 'vb'
51
+ } `;
52
+ if ( newDragCode !== this . dragCode ) {
53
+ this . dragCode = newDragCode ;
54
+ return true ;
55
+ }
56
+
57
+ return false ;
49
58
}
50
59
51
60
// returning undefined means calling onDragAtPosition(undefined), returning a dropposition means calling onPerformDrag(dropposition)
52
61
// TODO old function sometimes returned undefined when old state could be kept; is it okay to also return undefined to enter invalid drop state here? e.g. !this.draggingItems, !canDragAndDrop...
53
62
getDraggingPosition (
54
63
e : DragEvent ,
55
- hoveringPosition : HoveringPosition | undefined ,
56
- treeId : string
64
+ treeId : string ,
65
+ containerRef : React . MutableRefObject < HTMLElement | undefined >
57
66
) : DraggingPosition | undefined {
58
- if ( ! this . draggingItems || ! this . env . canDragAndDrop || ! hoveringPosition ) {
67
+ const hoveringPosition = this . getHoveringPosition ( e , treeId , containerRef ) ;
68
+
69
+ if (
70
+ ! this . draggingItems ||
71
+ ! this . env . canDragAndDrop ||
72
+ ! hoveringPosition ||
73
+ ! this . isNewDragPosition ( e , treeId , hoveringPosition )
74
+ ) {
59
75
return undefined ;
60
76
}
61
77
@@ -185,7 +201,7 @@ export class DropPositionEvaluation {
185
201
/**
186
202
* Returns undefined for invalid drop targets, like outside the tree.
187
203
*/
188
- getHoveringPosition (
204
+ private getHoveringPosition (
189
205
e : DragEvent ,
190
206
treeId : string ,
191
207
containerRef : React . MutableRefObject < HTMLElement | undefined >
0 commit comments