import { onMounted , onUnmounted } from '@vue/composition-api' ; type KeyboardHandler = ( event : KeyboardEvent ) => boolean | void | Promise < boolean | void > ; function handleKeyboard ( type , cb ) { function handler ( event ) { if ( event . target instanceof HTMLElement && ( event . target . tagName === 'INPUT' || event . target . tagName === 'TEXTAREA' ) ) { return ; } const result = cb ( event ) ; if ( ! result ) { event . preventDefault ( ) ; } } onMounted ( ( ) => { document . addEventListener ( type , handler ) ; } ) ; onUnmounted ( ( ) => { document . removeEventListener ( type , handler ) ; } ) ; } export function onKeyUp ( cb ) { handleKeyboard ( 'keyup' , cb ) ; } export function onKeyDown ( cb ) { handleKeyboard ( 'keydown' , cb ) ; }