import { onMounted , onUnmounted , Ref } from '@src/api' ; const defaultEvents = [ 'mousedown' , 'touchstart' ] ; export function useClickAway ( elRef , callback , events = defaultEvents ) { const handler = ( e ) => { if ( elRef . value && ! elRef . value . contains ( e . target as Node ) ) { callback ( e ) ; } } ; onMounted ( ( ) => { events . forEach ( evtName => document . addEventListener ( evtName , handler ) ) ; } ) ; onUnmounted ( ( ) => { events . forEach ( evtName => document . removeEventListener ( evtName , handler ) ) ; } ) ; }