@@ -601,7 +601,23 @@ export function useHeTree<T extends Record<string, any>>(
601601 }
602602 return index
603603 }
604- return { visibleIds, attrsList, onDragOverRoot, onDropToRoot, onDragEndOnRoot }
604+ function scrollToNode ( idOrNodeOrStat : Id | T | Stat < T > , block : 'start' | 'end' | 'center' | 'nearest' = 'start' ) {
605+ const stat = getStat ( idOrNodeOrStat )
606+ if ( ! stat ) {
607+ return false
608+ }
609+ let index = visibleIds . indexOf ( stat . id )
610+ if ( index === - 1 ) {
611+ return false
612+ }
613+ if ( virtualListRef . current ) {
614+ virtualListRef . current . scrollToIndex ( index , block )
615+ return true
616+ } else {
617+ return false
618+ }
619+ }
620+ return { visibleIds, attrsList, onDragOverRoot, onDropToRoot, onDragEndOnRoot, scrollToNode }
605621 } , [ mainCache , indent , draggingStat ,
606622 // watch placeholder position
607623 placeholder ?. parentStat , placeholder ?. index ,
@@ -639,7 +655,7 @@ export function useHeTree<T extends Record<string, any>>(
639655 } , [ props . keepPlaceholder ] )
640656 useAddEventListener ( t2 . getEl , 'dragover' , t2 . onDragOverWindow )
641657 //
642- const { visibleIds, attrsList, onDragOverRoot, onDropToRoot, onDragEndOnRoot } = cacheForVisible
658+ const { visibleIds, attrsList, onDragOverRoot, onDropToRoot, onDragEndOnRoot, scrollToNode } = cacheForVisible
643659 const persistentIndices = useMemo ( ( ) => draggingStat ? [ visibleIds . indexOf ( draggingStat . id ) ] : [ ] , [ draggingStat , visibleIds ] ) ;
644660 // render
645661 const renderTree = ( options ?: { className ?: string , style ?: React . CSSProperties } ) : ReactNode => {
@@ -671,6 +687,8 @@ export function useHeTree<T extends Record<string, any>>(
671687 draggingStat, dragOverStat, placeholder,
672688 // render
673689 renderTree, renderHeTree : renderTree ,
690+ // methods
691+ scrollToNode,
674692 }
675693}
676694// react components ==================================
0 commit comments