@@ -54,6 +54,31 @@ const getHoveringPosition = (
5454 return { linearIndex, offset, targetItem, targetLinearItem } ;
5555} ;
5656
57+ const useIsDescendant = ( ) => {
58+ const getParentOfLinearItem = useGetGetParentOfLinearItem ( ) ;
59+ const isDescendant = (
60+ treeId : string ,
61+ itemLinearIndex : number ,
62+ potentialParents : TreeItem [ ]
63+ ) => {
64+ const { parentLinearIndex, parent } = getParentOfLinearItem (
65+ itemLinearIndex ,
66+ treeId
67+ ) ;
68+
69+ if ( potentialParents . find ( p => p . index === parent . item ) ) {
70+ return true ;
71+ }
72+
73+ if ( parent . depth === 0 ) {
74+ return false ;
75+ }
76+
77+ return isDescendant ( treeId , parentLinearIndex , potentialParents ) ;
78+ } ;
79+ return isDescendant ;
80+ } ;
81+
5782export const useOnDragOverTreeHandler = (
5883 lastDragCode : string ,
5984 setLastDragCode : ( code : string ) => void ,
@@ -72,6 +97,7 @@ export const useOnDragOverTreeHandler = (
7297 trees,
7398 } = useTreeEnvironment ( ) ;
7499 const getParentOfLinearItem = useGetGetParentOfLinearItem ( ) ;
100+ const isDescendant = useIsDescendant ( ) ;
75101
76102 return useStableHandler (
77103 (
@@ -157,6 +183,11 @@ export const useOnDragOverTreeHandler = (
157183 linearIndex = parentLinearIndex ;
158184 }
159185
186+ if ( isDescendant ( treeId , linearIndex , draggingItems ) ) {
187+ onDragAtPosition ( undefined ) ;
188+ return ;
189+ }
190+
160191 const { depth } = targetItem ;
161192 const targetItemData = items [ targetItem . item ] ;
162193
0 commit comments