@@ -252,11 +252,13 @@ export function useDragDrop(options: UseDragDropOptions = {}) {
252252 if ( ! isDragging ) {
253253 isDraggingRef . current = true
254254 setIsDragging ( true )
255+ } else if ( scrollAnimationRef . current === null ) {
256+ scrollAnimationRef . current = requestAnimationFrame ( handleAutoScroll )
255257 }
256258
257259 return true
258260 } ,
259- [ isDragging ]
261+ [ isDragging , handleAutoScroll ]
260262 )
261263
262264 const getSiblingItems = useCallback (
@@ -616,6 +618,34 @@ export function useDragDrop(options: UseDragDropOptions = {}) {
616618 siblingsCacheRef . current . clear ( )
617619 } , [ ] )
618620
621+ useEffect ( ( ) => {
622+ if ( ! isDragging ) return
623+ const container = scrollContainerRef . current
624+ if ( ! container ) return
625+ const onLeave = ( e : DragEvent ) => {
626+ const related = e . relatedTarget as Node | null
627+ if ( related && container . contains ( related ) ) return
628+ if ( scrollAnimationRef . current !== null ) {
629+ cancelAnimationFrame ( scrollAnimationRef . current )
630+ scrollAnimationRef . current = null
631+ }
632+ dropIndicatorRef . current = null
633+ setDropIndicator ( null )
634+ setHoverFolderId ( null )
635+ }
636+ const onWindowDrop = ( e : DragEvent ) => {
637+ const target = e . target as Node | null
638+ if ( target && container . contains ( target ) ) return
639+ handleDragEnd ( )
640+ }
641+ container . addEventListener ( 'dragleave' , onLeave )
642+ window . addEventListener ( 'drop' , onWindowDrop , true )
643+ return ( ) => {
644+ container . removeEventListener ( 'dragleave' , onLeave )
645+ window . removeEventListener ( 'drop' , onWindowDrop , true )
646+ }
647+ } , [ isDragging , handleDragEnd ] )
648+
619649 const setScrollContainer = useCallback ( ( element : HTMLDivElement | null ) => {
620650 scrollContainerRef . current = element
621651 } , [ ] )
0 commit comments