import type { $IntentionalAny } from '@theatre/shared/utils/types' ; import { useEffect } from 'react' ; export default function useOnClickOutside ( container , onOutside , enabled ? ) { useEffect ( ( ) => { if ( ! container || enabled === false ) return ; const onMouseDown = ( e ) => { if ( ! e . composedPath ( ) . includes ( container ) ) { onOutside ( e ) ; } } ; window . addEventListener ( 'mousedown' , onMouseDown , { capture : true , passive : false , } ) ; return ( ) => { window . removeEventListener ( 'mousedown' , onMouseDown , { capture : true , passive : false , } as unknown as $IntentionalAny ) ; } ; } , [ container , enabled ] ) ; }