react-hotkeys-hook 4.4.2 → 4.4.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/BoundHotkeysProxyProvider.d.ts +14 -0
- package/dist/HotkeysProvider.d.ts +16 -0
- package/dist/deepEqual.d.ts +1 -0
- package/dist/index.d.ts +6 -0
- package/dist/index.js +8 -0
- package/dist/isHotkeyPressed.d.ts +4 -0
- package/dist/parseHotkeys.d.ts +5 -0
- package/dist/react-hotkeys-hook.cjs.development.js +529 -0
- package/dist/react-hotkeys-hook.cjs.development.js.map +1 -0
- package/dist/react-hotkeys-hook.cjs.production.min.js +2 -0
- package/dist/react-hotkeys-hook.cjs.production.min.js.map +1 -0
- package/dist/react-hotkeys-hook.esm.js +523 -0
- package/dist/react-hotkeys-hook.esm.js.map +1 -0
- package/dist/setupTests.d.ts +1 -0
- package/dist/types.d.ts +36 -0
- package/dist/useDeepEqualMemo.d.ts +1 -0
- package/dist/useHotkeys.d.ts +3 -0
- package/dist/useRecordHotkeys.d.ts +5 -0
- package/dist/validators.d.ts +7 -0
- package/package.json +13 -13
- package/src/useHotkeys.ts +14 -12
- package/src/validators.ts +2 -2
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { FormTags, Hotkey, Scopes, Trigger } from './types';
|
|
2
|
+
export declare function maybePreventDefault(e: KeyboardEvent, hotkey: Hotkey, preventDefault?: Trigger): void;
|
|
3
|
+
export declare function isHotkeyEnabled(e: KeyboardEvent, hotkey: Hotkey, enabled?: Trigger): boolean;
|
|
4
|
+
export declare function isKeyboardEventTriggeredByInput(ev: KeyboardEvent): boolean;
|
|
5
|
+
export declare function isHotkeyEnabledOnTag({ target }: KeyboardEvent, enabledOnTags?: readonly FormTags[] | boolean): boolean;
|
|
6
|
+
export declare function isScopeActive(activeScopes: string[], scopes?: Scopes): boolean;
|
|
7
|
+
export declare const isHotkeyMatchingKeyboardEvent: (e: KeyboardEvent, hotkey: Hotkey, ignoreModifiers?: boolean) => boolean;
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "react-hotkeys-hook",
|
|
3
3
|
"description": "React hook for handling keyboard shortcuts",
|
|
4
|
-
"version": "4.4.
|
|
4
|
+
"version": "4.4.4",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
7
7
|
"url": "https://github.com/JohannesKlauss/react-keymap-hook.git"
|
|
@@ -78,18 +78,18 @@
|
|
|
78
78
|
}
|
|
79
79
|
},
|
|
80
80
|
"devDependencies": {
|
|
81
|
-
"@babel/core": "7.23.
|
|
81
|
+
"@babel/core": "7.23.7",
|
|
82
82
|
"@babel/plugin-proposal-class-properties": "7.18.6",
|
|
83
|
-
"@babel/plugin-transform-react-jsx": "7.
|
|
84
|
-
"@babel/preset-env": "7.23.
|
|
85
|
-
"@babel/preset-react": "7.
|
|
86
|
-
"@babel/preset-typescript": "7.23.
|
|
83
|
+
"@babel/plugin-transform-react-jsx": "7.23.4",
|
|
84
|
+
"@babel/preset-env": "7.23.7",
|
|
85
|
+
"@babel/preset-react": "7.23.3",
|
|
86
|
+
"@babel/preset-typescript": "7.23.3",
|
|
87
87
|
"@testing-library/jest-dom": "5.17.0",
|
|
88
|
-
"@testing-library/react": "14.
|
|
89
|
-
"@testing-library/user-event": "14.
|
|
90
|
-
"@types/jest": "29.5.
|
|
91
|
-
"@types/react": "18.2.
|
|
92
|
-
"@types/react-dom": "18.2.
|
|
88
|
+
"@testing-library/react": "14.1.2",
|
|
89
|
+
"@testing-library/user-event": "14.5.2",
|
|
90
|
+
"@types/jest": "29.5.11",
|
|
91
|
+
"@types/react": "18.2.47",
|
|
92
|
+
"@types/react-dom": "18.2.18",
|
|
93
93
|
"@typescript-eslint/eslint-plugin": "5.60.0",
|
|
94
94
|
"@typescript-eslint/parser": "5.60.0",
|
|
95
95
|
"eslint": "8.56.0",
|
|
@@ -102,8 +102,8 @@
|
|
|
102
102
|
"react-dom": "18.2.0",
|
|
103
103
|
"react-test-renderer": "18.2.0",
|
|
104
104
|
"tsdx": "0.14.1",
|
|
105
|
-
"tslib": "2.
|
|
106
|
-
"typescript": "5.
|
|
105
|
+
"tslib": "2.6.2",
|
|
106
|
+
"typescript": "5.3.3"
|
|
107
107
|
},
|
|
108
108
|
"peerDependencies": {
|
|
109
109
|
"react": ">=16.8.1",
|
package/src/useHotkeys.ts
CHANGED
|
@@ -64,20 +64,18 @@ export default function useHotkeys<T extends HTMLElement>(
|
|
|
64
64
|
return
|
|
65
65
|
}
|
|
66
66
|
|
|
67
|
-
if (memoisedOptions?.ignoreEventWhen?.(e)) {
|
|
68
|
-
return
|
|
69
|
-
}
|
|
70
|
-
|
|
71
67
|
// TODO: SINCE THE EVENT IS NOW ATTACHED TO THE REF, THE ACTIVE ELEMENT CAN NEVER BE INSIDE THE REF. THE HOTKEY ONLY TRIGGERS IF THE
|
|
72
68
|
// REF IS THE ACTIVE ELEMENT. THIS IS A PROBLEM SINCE FOCUSED SUB COMPONENTS WON'T TRIGGER THE HOTKEY.
|
|
73
|
-
if (
|
|
74
|
-
ref.current
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
69
|
+
if (ref.current !== null) {
|
|
70
|
+
const rootNode = ref.current.getRootNode()
|
|
71
|
+
if (
|
|
72
|
+
(rootNode instanceof Document || rootNode instanceof ShadowRoot) &&
|
|
73
|
+
rootNode.activeElement !== ref.current &&
|
|
74
|
+
!ref.current.contains(rootNode.activeElement)
|
|
75
|
+
) {
|
|
76
|
+
stopPropagation(e)
|
|
77
|
+
return
|
|
78
|
+
}
|
|
81
79
|
}
|
|
82
80
|
|
|
83
81
|
if ((e.target as HTMLElement)?.isContentEditable && !memoisedOptions?.enableOnContentEditable) {
|
|
@@ -88,6 +86,10 @@ export default function useHotkeys<T extends HTMLElement>(
|
|
|
88
86
|
const hotkey = parseHotkey(key, memoisedOptions?.combinationKey)
|
|
89
87
|
|
|
90
88
|
if (isHotkeyMatchingKeyboardEvent(e, hotkey, memoisedOptions?.ignoreModifiers) || hotkey.keys?.includes('*')) {
|
|
89
|
+
if (memoisedOptions?.ignoreEventWhen?.(e)) {
|
|
90
|
+
return
|
|
91
|
+
}
|
|
92
|
+
|
|
91
93
|
if (isKeyUp && hasTriggeredRef.current) {
|
|
92
94
|
return
|
|
93
95
|
}
|
package/src/validators.ts
CHANGED
|
@@ -58,8 +58,8 @@ export const isHotkeyMatchingKeyboardEvent = (e: KeyboardEvent, hotkey: Hotkey,
|
|
|
58
58
|
const keyCode = mapKey(code)
|
|
59
59
|
const pressedKey = pressedKeyUppercase.toLowerCase()
|
|
60
60
|
|
|
61
|
-
if (!keys?.includes(keyCode) && !['ctrl', 'control', 'unknown', 'meta', 'alt', 'shift', 'os'].includes(keyCode)) {
|
|
62
|
-
return false
|
|
61
|
+
if (!keys?.includes(keyCode) && !keys?.includes(pressedKey) && !['ctrl', 'control', 'unknown', 'meta', 'alt', 'shift', 'os'].includes(keyCode)) {
|
|
62
|
+
return false
|
|
63
63
|
}
|
|
64
64
|
|
|
65
65
|
if (!ignoreModifiers) {
|