@@ -29,9 +29,8 @@ const getHoveringPosition = (
2929 if ( linearIndex > treeLinearItems . length - 1 ) {
3030 return {
3131 linearIndex : treeLinearItems . length - 1 ,
32- targetItem : treeLinearItems [ treeLinearItems . length - 1 ] . item ,
3332 offset : 'bottom' ,
34- targetLinearItem : treeLinearItems [ treeLinearItems . length - 1 ] ,
33+ veryBottom : true ,
3534 } as const ;
3635 }
3736
@@ -51,7 +50,7 @@ const getHoveringPosition = (
5150 offset = 'bottom' ;
5251 }
5352
54- return { linearIndex, offset, targetItem , targetLinearItem } ;
53+ return { linearIndex, offset } ;
5554} ;
5655
5756const useIsDescendant = ( ) => {
@@ -137,7 +136,8 @@ export const useOnDragOverTreeHandler = (
137136 return ;
138137 }
139138
140- let { linearIndex, offset } = getHoveringPosition (
139+ // eslint-disable-next-line prefer-const
140+ let { linearIndex, offset, veryBottom } = getHoveringPosition (
141141 e . clientY ,
142142 treeBb . top ,
143143 itemHeight ,
@@ -151,7 +151,7 @@ export const useOnDragOverTreeHandler = (
151151
152152 const nextDragCode = outsideContainer
153153 ? 'outside'
154- : `${ treeId } ${ linearIndex } ${ offset ?? '' } ` ;
154+ : `${ treeId } ${ linearIndex } ${ offset ?? '' } ${ veryBottom && 'vb' } ` ;
155155
156156 if ( lastDragCode === nextDragCode ) {
157157 return ;
@@ -244,15 +244,24 @@ export const useOnDragOverTreeHandler = (
244244
245245 let draggingPosition : DraggingPosition ;
246246
247- if ( offset ) {
247+ if ( veryBottom ) {
248+ const { rootItem } = trees [ treeId ] ;
249+ draggingPosition = {
250+ targetType : 'between-items' ,
251+ treeId,
252+ parentItem : rootItem ,
253+ depth : 0 ,
254+ linearIndex : linearIndex + 1 ,
255+ childIndex : items [ rootItem ] . children ?. length ?? 0 ,
256+ linePosition : 'bottom' ,
257+ } ;
258+ } else if ( offset ) {
248259 draggingPosition = {
249260 targetType : 'between-items' ,
250261 treeId,
251262 parentItem : parent . item ,
252263 depth : targetItem . depth ,
253264 linearIndex : linearIndex + ( offset === 'top' ? 0 : 1 ) ,
254- // childIndex: linearIndex - parentLinearIndex - 1 + (offset === 'top' ? 0 : 1),
255- // childIndex: environment.items[parent.item].children!.indexOf(targetItem.item) + (offset === 'top' ? 0 : 1),
256265 childIndex : newChildIndex ,
257266 linePosition : offset ,
258267 } ;
0 commit comments