1
1
import { RefObject , useEffect , useLayoutEffect , useState } from 'react' ;
2
- import keys , { Callback , Handler , Key } from 'ctrl-keys' ;
2
+ import type { Callback , HandlerInterface , Key } from 'ctrl-keys' ;
3
+ import keys from 'ctrl-keys' ;
3
4
4
5
type Keys = [ Key ] | [ Key , Key ] | [ Key , Key , Key ] | [ Key , Key , Key , Key ] ;
5
6
@@ -24,7 +25,7 @@ const keydownGlobalHandler = keys();
24
25
/**
25
26
* Map of specific elements handlers
26
27
*/
27
- const handlers = new Map < HTMLElement , Handler > ( ) ;
28
+ const handlers = new Map < HTMLElement , HandlerInterface > ( ) ;
28
29
let hotkeys : HotkeyShortcuts [ ] = [ ] ;
29
30
30
31
const extractKeys = ( keys : string | string [ ] ) : Keys => {
@@ -78,10 +79,9 @@ const registerElementShortcut = (shortcut: HotkeyShortcuts) => {
78
79
79
80
const removeElementShortcut = ( shortcut : HotkeyShortcuts ) => {
80
81
if ( shortcut . ref ?. current && ! shortcut . disabled ) {
81
- const handler = handlers . get ( shortcut . ref ?. current ) as Handler ;
82
-
83
- handler . remove ( ...extractKeys ( shortcut . keys ) , shortcut . callback ) ;
82
+ const handler = handlers . get ( shortcut . ref ?. current ) as HandlerInterface ;
84
83
84
+ handler ?. remove ( ...extractKeys ( shortcut . keys ) , shortcut . callback ) ;
85
85
shortcut . ref ?. current ?. removeEventListener ( shortcut . action ?? 'keypress' , handler . handle ) ;
86
86
}
87
87
} ;
0 commit comments