@tanstack/react-hotkeys 0.10.0 → 0.12.0
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/README.md +15 -1
- package/dist/HotkeysProvider.d.ts +6 -12
- package/dist/HotkeysProvider.js +1 -2
- package/dist/index.d.ts +2 -1
- package/dist/index.js +2 -1
- package/dist/useHeldKeyCodes.d.ts +2 -4
- package/dist/useHeldKeyCodes.js +3 -3
- package/dist/useHeldKeys.d.ts +2 -4
- package/dist/useHeldKeys.js +3 -3
- package/dist/useHotkey.d.ts +3 -6
- package/dist/useHotkey.js +12 -8
- package/dist/useHotkeyHint.d.ts +11 -0
- package/dist/useHotkeyHint.js +17 -0
- package/dist/useHotkeyRecorder.d.ts +3 -6
- package/dist/useHotkeyRecorder.js +1 -2
- package/dist/useHotkeyRegistrations.d.ts +3 -6
- package/dist/useHotkeyRegistrations.js +1 -2
- package/dist/useHotkeySequence.d.ts +3 -6
- package/dist/useHotkeySequence.js +10 -7
- package/dist/useHotkeySequenceRecorder.d.ts +3 -6
- package/dist/useHotkeySequenceRecorder.js +1 -2
- package/dist/useHotkeySequences.d.ts +3 -6
- package/dist/useHotkeySequences.js +4 -17
- package/dist/useHotkeys.d.ts +3 -6
- package/dist/useHotkeys.js +4 -17
- package/dist/useKeyHold.d.ts +2 -5
- package/dist/useKeyHold.js +1 -2
- package/dist/utils.js +1 -2
- package/package.json +14 -19
- package/dist/HotkeysProvider.cjs +0 -23
- package/dist/HotkeysProvider.cjs.map +0 -1
- package/dist/HotkeysProvider.d.cts +0 -28
- package/dist/HotkeysProvider.js.map +0 -1
- package/dist/_virtual/_rolldown/runtime.cjs +0 -29
- package/dist/index.cjs +0 -33
- package/dist/index.d.cts +0 -13
- package/dist/useHeldKeyCodes.cjs +0 -38
- package/dist/useHeldKeyCodes.cjs.map +0 -1
- package/dist/useHeldKeyCodes.d.cts +0 -31
- package/dist/useHeldKeyCodes.js.map +0 -1
- package/dist/useHeldKeys.cjs +0 -34
- package/dist/useHeldKeys.cjs.map +0 -1
- package/dist/useHeldKeys.d.cts +0 -27
- package/dist/useHeldKeys.js.map +0 -1
- package/dist/useHotkey.cjs +0 -122
- package/dist/useHotkey.cjs.map +0 -1
- package/dist/useHotkey.d.cts +0 -74
- package/dist/useHotkey.js.map +0 -1
- package/dist/useHotkeyRecorder.cjs +0 -72
- package/dist/useHotkeyRecorder.cjs.map +0 -1
- package/dist/useHotkeyRecorder.d.cts +0 -57
- package/dist/useHotkeyRecorder.js.map +0 -1
- package/dist/useHotkeyRegistrations.cjs +0 -49
- package/dist/useHotkeyRegistrations.cjs.map +0 -1
- package/dist/useHotkeyRegistrations.d.cts +0 -48
- package/dist/useHotkeyRegistrations.js.map +0 -1
- package/dist/useHotkeySequence.cjs +0 -117
- package/dist/useHotkeySequence.cjs.map +0 -1
- package/dist/useHotkeySequence.d.cts +0 -58
- package/dist/useHotkeySequence.js.map +0 -1
- package/dist/useHotkeySequenceRecorder.cjs +0 -42
- package/dist/useHotkeySequenceRecorder.cjs.map +0 -1
- package/dist/useHotkeySequenceRecorder.d.cts +0 -25
- package/dist/useHotkeySequenceRecorder.js.map +0 -1
- package/dist/useHotkeySequences.cjs +0 -139
- package/dist/useHotkeySequences.cjs.map +0 -1
- package/dist/useHotkeySequences.d.cts +0 -63
- package/dist/useHotkeySequences.js.map +0 -1
- package/dist/useHotkeys.cjs +0 -137
- package/dist/useHotkeys.cjs.map +0 -1
- package/dist/useHotkeys.d.cts +0 -63
- package/dist/useHotkeys.js.map +0 -1
- package/dist/useKeyHold.cjs +0 -54
- package/dist/useKeyHold.cjs.map +0 -1
- package/dist/useKeyHold.d.cts +0 -47
- package/dist/useKeyHold.js.map +0 -1
- package/dist/utils.cjs +0 -12
- package/dist/utils.cjs.map +0 -1
- package/dist/utils.js.map +0 -1
- package/src/HotkeysProvider.tsx +0 -58
- package/src/index.ts +0 -17
- package/src/useHeldKeyCodes.ts +0 -33
- package/src/useHeldKeys.ts +0 -29
- package/src/useHotkey.ts +0 -187
- package/src/useHotkeyRecorder.ts +0 -101
- package/src/useHotkeyRegistrations.ts +0 -67
- package/src/useHotkeySequence.ts +0 -187
- package/src/useHotkeySequenceRecorder.ts +0 -70
- package/src/useHotkeySequences.ts +0 -206
- package/src/useHotkeys.ts +0 -208
- package/src/useKeyHold.ts +0 -52
- package/src/utils.ts +0 -10
package/README.md
CHANGED
|
@@ -1,5 +1,19 @@
|
|
|
1
1
|
<div align="center">
|
|
2
|
-
<
|
|
2
|
+
<picture>
|
|
3
|
+
<source
|
|
4
|
+
media="(prefers-color-scheme: dark)"
|
|
5
|
+
srcset="https://tanstack.com/api/readme/hotkeys.png?theme=dark"
|
|
6
|
+
/>
|
|
7
|
+
<source
|
|
8
|
+
media="(prefers-color-scheme: light)"
|
|
9
|
+
srcset="https://tanstack.com/api/readme/hotkeys.png"
|
|
10
|
+
/>
|
|
11
|
+
<img
|
|
12
|
+
src="https://tanstack.com/api/readme/hotkeys.png"
|
|
13
|
+
alt="TanStack Hotkeys"
|
|
14
|
+
width="900"
|
|
15
|
+
/>
|
|
16
|
+
</picture>
|
|
3
17
|
</div>
|
|
4
18
|
|
|
5
19
|
<br />
|
|
@@ -2,9 +2,8 @@ import { UseHotkeyOptions } from "./useHotkey.js";
|
|
|
2
2
|
import { UseHotkeySequenceOptions } from "./useHotkeySequence.js";
|
|
3
3
|
import { HotkeyRecorderOptions, HotkeySequenceRecorderOptions } from "@tanstack/hotkeys";
|
|
4
4
|
import React, { ReactNode } from "react";
|
|
5
|
-
|
|
6
5
|
//#region src/HotkeysProvider.d.ts
|
|
7
|
-
interface HotkeysProviderOptions {
|
|
6
|
+
export interface HotkeysProviderOptions {
|
|
8
7
|
hotkey?: Partial<UseHotkeyOptions>;
|
|
9
8
|
hotkeyRecorder?: Partial<HotkeyRecorderOptions>;
|
|
10
9
|
hotkeySequence?: Partial<UseHotkeySequenceOptions>;
|
|
@@ -13,16 +12,11 @@ interface HotkeysProviderOptions {
|
|
|
13
12
|
interface HotkeysContextValue {
|
|
14
13
|
defaultOptions: HotkeysProviderOptions;
|
|
15
14
|
}
|
|
16
|
-
interface HotkeysProviderProps {
|
|
15
|
+
export interface HotkeysProviderProps {
|
|
17
16
|
children: ReactNode;
|
|
18
17
|
defaultOptions?: HotkeysProviderOptions;
|
|
19
18
|
}
|
|
20
|
-
declare function HotkeysProvider({
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
declare function useHotkeysContext(): HotkeysContextValue | null;
|
|
25
|
-
declare function useDefaultHotkeysOptions(): HotkeysProviderOptions;
|
|
26
|
-
//#endregion
|
|
27
|
-
export { HotkeysProvider, HotkeysProviderOptions, HotkeysProviderProps, useDefaultHotkeysOptions, useHotkeysContext };
|
|
28
|
-
//# sourceMappingURL=HotkeysProvider.d.ts.map
|
|
19
|
+
export declare function HotkeysProvider({ children, defaultOptions }: HotkeysProviderProps): React.JSX.Element;
|
|
20
|
+
export declare function useHotkeysContext(): HotkeysContextValue | null;
|
|
21
|
+
export declare function useDefaultHotkeysOptions(): HotkeysProviderOptions;
|
|
22
|
+
//#endregion
|
package/dist/HotkeysProvider.js
CHANGED
package/dist/index.d.ts
CHANGED
|
@@ -9,5 +9,6 @@ import { UseHotkeySequenceDefinition, useHotkeySequences } from "./useHotkeySequ
|
|
|
9
9
|
import { ReactHotkeyRecorder, useHotkeyRecorder } from "./useHotkeyRecorder.js";
|
|
10
10
|
import { HotkeyRegistrationsResult, useHotkeyRegistrations } from "./useHotkeyRegistrations.js";
|
|
11
11
|
import { ReactHotkeySequenceRecorder, useHotkeySequenceRecorder } from "./useHotkeySequenceRecorder.js";
|
|
12
|
+
import { useHotkeyHint } from "./useHotkeyHint.js";
|
|
12
13
|
export * from "@tanstack/hotkeys";
|
|
13
|
-
export { HotkeyRegistrationsResult, HotkeysProvider, HotkeysProviderOptions, HotkeysProviderProps, ReactHotkeyRecorder, ReactHotkeySequenceRecorder, UseHotkeyDefinition, UseHotkeyOptions, UseHotkeySequenceDefinition, UseHotkeySequenceOptions, useDefaultHotkeysOptions, useHeldKeyCodes, useHeldKeys, useHotkey, useHotkeyRecorder, useHotkeyRegistrations, useHotkeySequence, useHotkeySequenceRecorder, useHotkeySequences, useHotkeys, useHotkeysContext, useKeyHold };
|
|
14
|
+
export { HotkeyRegistrationsResult, HotkeysProvider, HotkeysProviderOptions, HotkeysProviderProps, ReactHotkeyRecorder, ReactHotkeySequenceRecorder, UseHotkeyDefinition, UseHotkeyOptions, UseHotkeySequenceDefinition, UseHotkeySequenceOptions, useDefaultHotkeysOptions, useHeldKeyCodes, useHeldKeys, useHotkey, useHotkeyHint, useHotkeyRecorder, useHotkeyRegistrations, useHotkeySequence, useHotkeySequenceRecorder, useHotkeySequences, useHotkeys, useHotkeysContext, useKeyHold };
|
package/dist/index.js
CHANGED
|
@@ -9,7 +9,8 @@ import { useHotkeySequences } from "./useHotkeySequences.js";
|
|
|
9
9
|
import { useHotkeyRecorder } from "./useHotkeyRecorder.js";
|
|
10
10
|
import { useHotkeyRegistrations } from "./useHotkeyRegistrations.js";
|
|
11
11
|
import { useHotkeySequenceRecorder } from "./useHotkeySequenceRecorder.js";
|
|
12
|
+
import { useHotkeyHint } from "./useHotkeyHint.js";
|
|
12
13
|
|
|
13
14
|
export * from "@tanstack/hotkeys"
|
|
14
15
|
|
|
15
|
-
export { HotkeysProvider, useDefaultHotkeysOptions, useHeldKeyCodes, useHeldKeys, useHotkey, useHotkeyRecorder, useHotkeyRegistrations, useHotkeySequence, useHotkeySequenceRecorder, useHotkeySequences, useHotkeys, useHotkeysContext, useKeyHold };
|
|
16
|
+
export { HotkeysProvider, useDefaultHotkeysOptions, useHeldKeyCodes, useHeldKeys, useHotkey, useHotkeyHint, useHotkeyRecorder, useHotkeyRegistrations, useHotkeySequence, useHotkeySequenceRecorder, useHotkeySequences, useHotkeys, useHotkeysContext, useKeyHold };
|
|
@@ -25,7 +25,5 @@
|
|
|
25
25
|
* }
|
|
26
26
|
* ```
|
|
27
27
|
*/
|
|
28
|
-
declare function useHeldKeyCodes(): Record<string, string>;
|
|
29
|
-
//#endregion
|
|
30
|
-
export { useHeldKeyCodes };
|
|
31
|
-
//# sourceMappingURL=useHeldKeyCodes.d.ts.map
|
|
28
|
+
export declare function useHeldKeyCodes(): Record<string, string>;
|
|
29
|
+
//#endregion
|
package/dist/useHeldKeyCodes.js
CHANGED
|
@@ -29,9 +29,9 @@ import { useSelector } from "@tanstack/react-store";
|
|
|
29
29
|
* ```
|
|
30
30
|
*/
|
|
31
31
|
function useHeldKeyCodes() {
|
|
32
|
-
|
|
32
|
+
const tracker = getKeyStateTracker();
|
|
33
|
+
return useSelector(tracker.store, (state) => state.heldCodes);
|
|
33
34
|
}
|
|
34
35
|
|
|
35
36
|
//#endregion
|
|
36
|
-
export { useHeldKeyCodes };
|
|
37
|
-
//# sourceMappingURL=useHeldKeyCodes.js.map
|
|
37
|
+
export { useHeldKeyCodes };
|
package/dist/useHeldKeys.d.ts
CHANGED
package/dist/useHeldKeys.js
CHANGED
|
@@ -25,9 +25,9 @@ import { useSelector } from "@tanstack/react-store";
|
|
|
25
25
|
* ```
|
|
26
26
|
*/
|
|
27
27
|
function useHeldKeys() {
|
|
28
|
-
|
|
28
|
+
const tracker = getKeyStateTracker();
|
|
29
|
+
return useSelector(tracker.store, (state) => state.heldKeys);
|
|
29
30
|
}
|
|
30
31
|
|
|
31
32
|
//#endregion
|
|
32
|
-
export { useHeldKeys };
|
|
33
|
-
//# sourceMappingURL=useHeldKeys.js.map
|
|
33
|
+
export { useHeldKeys };
|
package/dist/useHotkey.d.ts
CHANGED
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import { HotkeyCallback, HotkeyOptions, RegisterableHotkey } from "@tanstack/hotkeys";
|
|
2
|
-
|
|
3
2
|
//#region src/useHotkey.d.ts
|
|
4
|
-
interface UseHotkeyOptions extends Omit<HotkeyOptions, 'target'> {
|
|
3
|
+
export interface UseHotkeyOptions extends Omit<HotkeyOptions, 'target'> {
|
|
5
4
|
/**
|
|
6
5
|
* The DOM element to attach the event listener to.
|
|
7
6
|
* Can be a React ref, direct DOM element, or null.
|
|
@@ -68,7 +67,5 @@ interface UseHotkeyOptions extends Omit<HotkeyOptions, 'target'> {
|
|
|
68
67
|
* }
|
|
69
68
|
* ```
|
|
70
69
|
*/
|
|
71
|
-
declare function useHotkey(hotkey: RegisterableHotkey, callback: HotkeyCallback, options?: UseHotkeyOptions): void;
|
|
72
|
-
//#endregion
|
|
73
|
-
export { UseHotkeyOptions, useHotkey };
|
|
74
|
-
//# sourceMappingURL=useHotkey.d.ts.map
|
|
70
|
+
export declare function useHotkey(hotkey: RegisterableHotkey, callback: HotkeyCallback, options?: UseHotkeyOptions): void;
|
|
71
|
+
//#endregion
|
package/dist/useHotkey.js
CHANGED
|
@@ -78,7 +78,8 @@ function useHotkey(hotkey, callback, options = {}) {
|
|
|
78
78
|
managerRef.current = manager;
|
|
79
79
|
const prevTargetRef = useRef(null);
|
|
80
80
|
const prevHotkeyRef = useRef(null);
|
|
81
|
-
const
|
|
81
|
+
const platform = mergedOptions.platform ?? detectPlatform();
|
|
82
|
+
const hotkeyString = normalizeRegisterableHotkey(hotkey, platform);
|
|
82
83
|
const { target: _target, ...optionsWithoutTarget } = mergedOptions;
|
|
83
84
|
useEffect(() => {
|
|
84
85
|
const resolvedTarget = isRef(optionsRef.current.target) ? optionsRef.current.target.current : optionsRef.current.target ?? (typeof document !== "undefined" ? document : null);
|
|
@@ -103,19 +104,22 @@ function useHotkey(hotkey, callback, options = {}) {
|
|
|
103
104
|
});
|
|
104
105
|
prevTargetRef.current = resolvedTarget;
|
|
105
106
|
prevHotkeyRef.current = hotkeyString;
|
|
107
|
+
});
|
|
108
|
+
useEffect(() => {
|
|
106
109
|
return () => {
|
|
107
110
|
if (registrationRef.current?.isActive) {
|
|
108
111
|
registrationRef.current.unregister();
|
|
109
112
|
registrationRef.current = null;
|
|
110
113
|
}
|
|
111
114
|
};
|
|
112
|
-
}, [
|
|
113
|
-
|
|
114
|
-
registrationRef.current
|
|
115
|
-
|
|
116
|
-
|
|
115
|
+
}, []);
|
|
116
|
+
useEffect(() => {
|
|
117
|
+
if (registrationRef.current?.isActive) {
|
|
118
|
+
registrationRef.current.callback = callback;
|
|
119
|
+
registrationRef.current.setOptions(optionsWithoutTarget);
|
|
120
|
+
}
|
|
121
|
+
});
|
|
117
122
|
}
|
|
118
123
|
|
|
119
124
|
//#endregion
|
|
120
|
-
export { useHotkey };
|
|
121
|
-
//# sourceMappingURL=useHotkey.js.map
|
|
125
|
+
export { useHotkey };
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { HeldModifierOptions, RegisterableHotkey } from "@tanstack/hotkeys";
|
|
2
|
+
//#region src/useHotkeyHint.d.ts
|
|
3
|
+
/**
|
|
4
|
+
* Returns a boolean indicating whether held modifiers reveal this shortcut.
|
|
5
|
+
* Only visibility changes from held-key updates cause a rerender.
|
|
6
|
+
* Uses the nonempty-subset/AltGr rules of `matchesHeldModifiers`; `exact` requires
|
|
7
|
+
* every modifier. Combine with the action's enabled state before showing a badge.
|
|
8
|
+
* This helper does not register a shortcut or check whether its target is focused.
|
|
9
|
+
*/
|
|
10
|
+
export declare function useHotkeyHint(hotkey: RegisterableHotkey, options?: HeldModifierOptions): boolean;
|
|
11
|
+
//#endregion
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { getKeyStateTracker, matchesHeldModifiers } from "@tanstack/hotkeys";
|
|
2
|
+
import { useSelector } from "@tanstack/react-store";
|
|
3
|
+
|
|
4
|
+
//#region src/useHotkeyHint.ts
|
|
5
|
+
/**
|
|
6
|
+
* Returns a boolean indicating whether held modifiers reveal this shortcut.
|
|
7
|
+
* Only visibility changes from held-key updates cause a rerender.
|
|
8
|
+
* Uses the nonempty-subset/AltGr rules of `matchesHeldModifiers`; `exact` requires
|
|
9
|
+
* every modifier. Combine with the action's enabled state before showing a badge.
|
|
10
|
+
* This helper does not register a shortcut or check whether its target is focused.
|
|
11
|
+
*/
|
|
12
|
+
function useHotkeyHint(hotkey, options = {}) {
|
|
13
|
+
return useSelector(getKeyStateTracker().store, (state) => matchesHeldModifiers(hotkey, state.heldKeys, options));
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
//#endregion
|
|
17
|
+
export { useHotkeyHint };
|
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import { Hotkey, HotkeyRecorderOptions } from "@tanstack/hotkeys";
|
|
2
|
-
|
|
3
2
|
//#region src/useHotkeyRecorder.d.ts
|
|
4
|
-
interface ReactHotkeyRecorder {
|
|
3
|
+
export interface ReactHotkeyRecorder {
|
|
5
4
|
/** Whether recording is currently active */
|
|
6
5
|
isRecording: boolean;
|
|
7
6
|
/** The currently recorded hotkey (for live preview) */
|
|
@@ -51,7 +50,5 @@ interface ReactHotkeyRecorder {
|
|
|
51
50
|
* }
|
|
52
51
|
* ```
|
|
53
52
|
*/
|
|
54
|
-
declare function useHotkeyRecorder(options: HotkeyRecorderOptions): ReactHotkeyRecorder;
|
|
55
|
-
//#endregion
|
|
56
|
-
export { ReactHotkeyRecorder, useHotkeyRecorder };
|
|
57
|
-
//# sourceMappingURL=useHotkeyRecorder.d.ts.map
|
|
53
|
+
export declare function useHotkeyRecorder(options: HotkeyRecorderOptions): ReactHotkeyRecorder;
|
|
54
|
+
//#endregion
|
|
@@ -1,10 +1,9 @@
|
|
|
1
1
|
import { HotkeyRegistrationView, SequenceRegistrationView } from "@tanstack/hotkeys";
|
|
2
|
-
|
|
3
2
|
//#region src/useHotkeyRegistrations.d.ts
|
|
4
3
|
/**
|
|
5
4
|
* Return type for useHotkeyRegistrations.
|
|
6
5
|
*/
|
|
7
|
-
interface HotkeyRegistrationsResult {
|
|
6
|
+
export interface HotkeyRegistrationsResult {
|
|
8
7
|
/** All registered hotkeys (public view, no callbacks) */
|
|
9
8
|
hotkeys: Array<HotkeyRegistrationView>;
|
|
10
9
|
/** All registered sequences */
|
|
@@ -42,7 +41,5 @@ interface HotkeyRegistrationsResult {
|
|
|
42
41
|
* }
|
|
43
42
|
* ```
|
|
44
43
|
*/
|
|
45
|
-
declare function useHotkeyRegistrations(): HotkeyRegistrationsResult;
|
|
46
|
-
//#endregion
|
|
47
|
-
export { HotkeyRegistrationsResult, useHotkeyRegistrations };
|
|
48
|
-
//# sourceMappingURL=useHotkeyRegistrations.d.ts.map
|
|
44
|
+
export declare function useHotkeyRegistrations(): HotkeyRegistrationsResult;
|
|
45
|
+
//#endregion
|
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import { HotkeyCallback, HotkeySequence, SequenceOptions } from "@tanstack/hotkeys";
|
|
2
|
-
|
|
3
2
|
//#region src/useHotkeySequence.d.ts
|
|
4
|
-
interface UseHotkeySequenceOptions extends Omit<SequenceOptions, 'target'> {
|
|
3
|
+
export interface UseHotkeySequenceOptions extends Omit<SequenceOptions, 'target'> {
|
|
5
4
|
/**
|
|
6
5
|
* The DOM element to attach the event listener to.
|
|
7
6
|
* Can be a React ref, direct DOM element, or null.
|
|
@@ -52,7 +51,5 @@ interface UseHotkeySequenceOptions extends Omit<SequenceOptions, 'target'> {
|
|
|
52
51
|
* }
|
|
53
52
|
* ```
|
|
54
53
|
*/
|
|
55
|
-
declare function useHotkeySequence(sequence: HotkeySequence, callback: HotkeyCallback, options?: UseHotkeySequenceOptions): void;
|
|
56
|
-
//#endregion
|
|
57
|
-
export { UseHotkeySequenceOptions, useHotkeySequence };
|
|
58
|
-
//# sourceMappingURL=useHotkeySequence.d.ts.map
|
|
54
|
+
export declare function useHotkeySequence(sequence: HotkeySequence, callback: HotkeyCallback, options?: UseHotkeySequenceOptions): void;
|
|
55
|
+
//#endregion
|
|
@@ -98,19 +98,22 @@ function useHotkeySequence(sequence, callback, options = {}) {
|
|
|
98
98
|
});
|
|
99
99
|
prevTargetRef.current = resolvedTarget;
|
|
100
100
|
prevSequenceRef.current = hotkeySequenceString;
|
|
101
|
+
});
|
|
102
|
+
useEffect(() => {
|
|
101
103
|
return () => {
|
|
102
104
|
if (registrationRef.current?.isActive) {
|
|
103
105
|
registrationRef.current.unregister();
|
|
104
106
|
registrationRef.current = null;
|
|
105
107
|
}
|
|
106
108
|
};
|
|
107
|
-
}, [
|
|
108
|
-
|
|
109
|
-
registrationRef.current
|
|
110
|
-
|
|
111
|
-
|
|
109
|
+
}, []);
|
|
110
|
+
useEffect(() => {
|
|
111
|
+
if (registrationRef.current?.isActive) {
|
|
112
|
+
registrationRef.current.callback = (event, context) => callbackRef.current(event, context);
|
|
113
|
+
registrationRef.current.setOptions(optionsWithoutTarget);
|
|
114
|
+
}
|
|
115
|
+
});
|
|
112
116
|
}
|
|
113
117
|
|
|
114
118
|
//#endregion
|
|
115
|
-
export { useHotkeySequence };
|
|
116
|
-
//# sourceMappingURL=useHotkeySequence.js.map
|
|
119
|
+
export { useHotkeySequence };
|
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import { HotkeySequence, HotkeySequenceRecorderOptions } from "@tanstack/hotkeys";
|
|
2
|
-
|
|
3
2
|
//#region src/useHotkeySequenceRecorder.d.ts
|
|
4
|
-
interface ReactHotkeySequenceRecorder {
|
|
3
|
+
export interface ReactHotkeySequenceRecorder {
|
|
5
4
|
/** Whether recording is currently active */
|
|
6
5
|
isRecording: boolean;
|
|
7
6
|
/** Chords captured in the current session */
|
|
@@ -19,7 +18,5 @@ interface ReactHotkeySequenceRecorder {
|
|
|
19
18
|
*
|
|
20
19
|
* @param options - Configuration options for the hotkey sequence recorder
|
|
21
20
|
*/
|
|
22
|
-
declare function useHotkeySequenceRecorder(options: HotkeySequenceRecorderOptions): ReactHotkeySequenceRecorder;
|
|
23
|
-
//#endregion
|
|
24
|
-
export { ReactHotkeySequenceRecorder, useHotkeySequenceRecorder };
|
|
25
|
-
//# sourceMappingURL=useHotkeySequenceRecorder.d.ts.map
|
|
21
|
+
export declare function useHotkeySequenceRecorder(options: HotkeySequenceRecorderOptions): ReactHotkeySequenceRecorder;
|
|
22
|
+
//#endregion
|
|
@@ -1,11 +1,10 @@
|
|
|
1
1
|
import { UseHotkeySequenceOptions } from "./useHotkeySequence.js";
|
|
2
2
|
import { HotkeyCallback, HotkeySequence } from "@tanstack/hotkeys";
|
|
3
|
-
|
|
4
3
|
//#region src/useHotkeySequences.d.ts
|
|
5
4
|
/**
|
|
6
5
|
* A single sequence definition for use with `useHotkeySequences`.
|
|
7
6
|
*/
|
|
8
|
-
interface UseHotkeySequenceDefinition {
|
|
7
|
+
export interface UseHotkeySequenceDefinition {
|
|
9
8
|
/** Array of hotkey strings that form the sequence */
|
|
10
9
|
sequence: HotkeySequence;
|
|
11
10
|
/** The function to call when the sequence is completed */
|
|
@@ -57,7 +56,5 @@ interface UseHotkeySequenceDefinition {
|
|
|
57
56
|
* }
|
|
58
57
|
* ```
|
|
59
58
|
*/
|
|
60
|
-
declare function useHotkeySequences(definitions: Array<UseHotkeySequenceDefinition>, commonOptions?: UseHotkeySequenceOptions): void;
|
|
61
|
-
//#endregion
|
|
62
|
-
export { UseHotkeySequenceDefinition, useHotkeySequences };
|
|
63
|
-
//# sourceMappingURL=useHotkeySequences.d.ts.map
|
|
59
|
+
export declare function useHotkeySequences(definitions: Array<UseHotkeySequenceDefinition>, commonOptions?: UseHotkeySequenceOptions): void;
|
|
60
|
+
//#endregion
|
|
@@ -95,6 +95,9 @@ function useHotkeySequences(definitions, commonOptions = {}) {
|
|
|
95
95
|
const { registrationKey, def, seq, mergedOptions, resolvedTarget } = row;
|
|
96
96
|
const existing = prevRegistrations.get(registrationKey);
|
|
97
97
|
if (existing?.handle.isActive && existing.target === resolvedTarget) {
|
|
98
|
+
existing.handle.callback = def.callback;
|
|
99
|
+
const { target: _target, ...optionsWithoutTarget } = mergedOptions;
|
|
100
|
+
existing.handle.setOptions(optionsWithoutTarget);
|
|
98
101
|
nextRegistrations.set(registrationKey, existing);
|
|
99
102
|
continue;
|
|
100
103
|
}
|
|
@@ -116,23 +119,7 @@ function useHotkeySequences(definitions, commonOptions = {}) {
|
|
|
116
119
|
registrationsRef.current = /* @__PURE__ */ new Map();
|
|
117
120
|
};
|
|
118
121
|
}, []);
|
|
119
|
-
for (let i = 0; i < definitions.length; i++) {
|
|
120
|
-
const def = definitions[i];
|
|
121
|
-
const seqStr = sequenceStrings[i];
|
|
122
|
-
const registrationKey = `${i}:${seqStr}`;
|
|
123
|
-
const handle = registrationsRef.current.get(registrationKey)?.handle;
|
|
124
|
-
if (handle?.isActive && def.sequence.length > 0) {
|
|
125
|
-
handle.callback = def.callback;
|
|
126
|
-
const { target: _target, ...optionsWithoutTarget } = {
|
|
127
|
-
...defaultOptions,
|
|
128
|
-
...commonOptions,
|
|
129
|
-
...def.options
|
|
130
|
-
};
|
|
131
|
-
handle.setOptions(optionsWithoutTarget);
|
|
132
|
-
}
|
|
133
|
-
}
|
|
134
122
|
}
|
|
135
123
|
|
|
136
124
|
//#endregion
|
|
137
|
-
export { useHotkeySequences };
|
|
138
|
-
//# sourceMappingURL=useHotkeySequences.js.map
|
|
125
|
+
export { useHotkeySequences };
|
package/dist/useHotkeys.d.ts
CHANGED
|
@@ -1,11 +1,10 @@
|
|
|
1
1
|
import { UseHotkeyOptions } from "./useHotkey.js";
|
|
2
2
|
import { HotkeyCallback, RegisterableHotkey } from "@tanstack/hotkeys";
|
|
3
|
-
|
|
4
3
|
//#region src/useHotkeys.d.ts
|
|
5
4
|
/**
|
|
6
5
|
* A single hotkey definition for use with `useHotkeys`.
|
|
7
6
|
*/
|
|
8
|
-
interface UseHotkeyDefinition {
|
|
7
|
+
export interface UseHotkeyDefinition {
|
|
9
8
|
/** The hotkey string (e.g., 'Mod+S', 'Escape') or RawHotkey object */
|
|
10
9
|
hotkey: RegisterableHotkey;
|
|
11
10
|
/** The function to call when the hotkey is pressed */
|
|
@@ -57,7 +56,5 @@ interface UseHotkeyDefinition {
|
|
|
57
56
|
* }
|
|
58
57
|
* ```
|
|
59
58
|
*/
|
|
60
|
-
declare function useHotkeys(hotkeys: Array<UseHotkeyDefinition>, commonOptions?: UseHotkeyOptions): void;
|
|
61
|
-
//#endregion
|
|
62
|
-
export { UseHotkeyDefinition, useHotkeys };
|
|
63
|
-
//# sourceMappingURL=useHotkeys.d.ts.map
|
|
59
|
+
export declare function useHotkeys(hotkeys: Array<UseHotkeyDefinition>, commonOptions?: UseHotkeyOptions): void;
|
|
60
|
+
//#endregion
|
package/dist/useHotkeys.js
CHANGED
|
@@ -93,6 +93,9 @@ function useHotkeys(hotkeys, commonOptions = {}) {
|
|
|
93
93
|
const { registrationKey, def, hotkeyStr, mergedOptions, resolvedTarget } = row;
|
|
94
94
|
const existing = prevRegistrations.get(registrationKey);
|
|
95
95
|
if (existing?.handle.isActive && existing.target === resolvedTarget) {
|
|
96
|
+
existing.handle.callback = def.callback;
|
|
97
|
+
const { target: _target, ...optionsWithoutTarget } = mergedOptions;
|
|
98
|
+
existing.handle.setOptions(optionsWithoutTarget);
|
|
96
99
|
nextRegistrations.set(registrationKey, existing);
|
|
97
100
|
continue;
|
|
98
101
|
}
|
|
@@ -114,23 +117,7 @@ function useHotkeys(hotkeys, commonOptions = {}) {
|
|
|
114
117
|
registrationsRef.current = /* @__PURE__ */ new Map();
|
|
115
118
|
};
|
|
116
119
|
}, []);
|
|
117
|
-
for (let i = 0; i < hotkeys.length; i++) {
|
|
118
|
-
const def = hotkeys[i];
|
|
119
|
-
const hotkeyStr = hotkeyStrings[i];
|
|
120
|
-
const registrationKey = `${i}:${hotkeyStr}`;
|
|
121
|
-
const handle = registrationsRef.current.get(registrationKey)?.handle;
|
|
122
|
-
if (handle?.isActive) {
|
|
123
|
-
handle.callback = def.callback;
|
|
124
|
-
const { target: _target, ...optionsWithoutTarget } = {
|
|
125
|
-
...defaultOptions,
|
|
126
|
-
...commonOptions,
|
|
127
|
-
...def.options
|
|
128
|
-
};
|
|
129
|
-
handle.setOptions(optionsWithoutTarget);
|
|
130
|
-
}
|
|
131
|
-
}
|
|
132
120
|
}
|
|
133
121
|
|
|
134
122
|
//#endregion
|
|
135
|
-
export { useHotkeys };
|
|
136
|
-
//# sourceMappingURL=useHotkeys.js.map
|
|
123
|
+
export { useHotkeys };
|
package/dist/useKeyHold.d.ts
CHANGED
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import { IndividualKey } from "@tanstack/hotkeys";
|
|
2
|
-
|
|
3
2
|
//#region src/useKeyHold.d.ts
|
|
4
3
|
/**
|
|
5
4
|
* React hook that returns whether a specific key is currently being held.
|
|
@@ -41,7 +40,5 @@ import { IndividualKey } from "@tanstack/hotkeys";
|
|
|
41
40
|
* }
|
|
42
41
|
* ```
|
|
43
42
|
*/
|
|
44
|
-
declare function useKeyHold(key: IndividualKey): boolean;
|
|
45
|
-
//#endregion
|
|
46
|
-
export { useKeyHold };
|
|
47
|
-
//# sourceMappingURL=useKeyHold.d.ts.map
|
|
43
|
+
export declare function useKeyHold(key: IndividualKey): boolean;
|
|
44
|
+
//#endregion
|
package/dist/useKeyHold.js
CHANGED
package/dist/utils.js
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tanstack/react-hotkeys",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.12.0",
|
|
4
4
|
"description": "React adapter for TanStack Hotkeys",
|
|
5
5
|
"author": "Tanner Linsley",
|
|
6
6
|
"license": "MIT",
|
|
@@ -20,37 +20,31 @@
|
|
|
20
20
|
"keys"
|
|
21
21
|
],
|
|
22
22
|
"type": "module",
|
|
23
|
-
"
|
|
24
|
-
"module": "./dist/index.js",
|
|
25
|
-
"types": "./dist/index.d.cts",
|
|
23
|
+
"types": "./dist/index.d.ts",
|
|
26
24
|
"exports": {
|
|
27
|
-
".":
|
|
28
|
-
"import": "./dist/index.js",
|
|
29
|
-
"require": "./dist/index.cjs"
|
|
30
|
-
},
|
|
25
|
+
".": "./dist/index.js",
|
|
31
26
|
"./package.json": "./package.json"
|
|
32
27
|
},
|
|
33
28
|
"sideEffects": false,
|
|
34
29
|
"engines": {
|
|
35
|
-
"node": ">=
|
|
30
|
+
"node": ">=20"
|
|
36
31
|
},
|
|
37
32
|
"files": [
|
|
38
|
-
"dist"
|
|
39
|
-
"src"
|
|
33
|
+
"dist"
|
|
40
34
|
],
|
|
41
35
|
"dependencies": {
|
|
42
|
-
"@tanstack/
|
|
43
|
-
"@tanstack/
|
|
36
|
+
"@tanstack/hotkeys": "0.10.0",
|
|
37
|
+
"@tanstack/react-store": "^0.11.1"
|
|
44
38
|
},
|
|
45
39
|
"devDependencies": {
|
|
46
40
|
"@eslint-react/eslint-plugin": "^4.2.3",
|
|
47
|
-
"@testing-library/react": "^16.3.
|
|
48
|
-
"@types/react": "^19.
|
|
49
|
-
"@vitejs/plugin-react": "^6.
|
|
41
|
+
"@testing-library/react": "^16.3.3",
|
|
42
|
+
"@types/react": "^19.3.0",
|
|
43
|
+
"@vitejs/plugin-react": "^6.1.1",
|
|
50
44
|
"eslint-plugin-react-compiler": "19.1.0-rc.2",
|
|
51
45
|
"eslint-plugin-react-hooks": "^7.1.1",
|
|
52
|
-
"react": "^19.
|
|
53
|
-
"react-dom": "^19.
|
|
46
|
+
"react": "^19.3.0",
|
|
47
|
+
"react-dom": "^19.3.0"
|
|
54
48
|
},
|
|
55
49
|
"peerDependencies": {
|
|
56
50
|
"react": ">=16.8",
|
|
@@ -64,6 +58,7 @@
|
|
|
64
58
|
"test:lib": "vitest --passWithNoTests",
|
|
65
59
|
"test:lib:dev": "pnpm test:lib --watch",
|
|
66
60
|
"test:types": "tsc",
|
|
67
|
-
"build": "tsdown"
|
|
61
|
+
"build": "tsdown",
|
|
62
|
+
"test:build": "publint --strict && node ../../scripts/verify-package.ts"
|
|
68
63
|
}
|
|
69
64
|
}
|
package/dist/HotkeysProvider.cjs
DELETED
|
@@ -1,23 +0,0 @@
|
|
|
1
|
-
const require_runtime = require('./_virtual/_rolldown/runtime.cjs');
|
|
2
|
-
let react = require("react");
|
|
3
|
-
react = require_runtime.__toESM(react);
|
|
4
|
-
|
|
5
|
-
//#region src/HotkeysProvider.tsx
|
|
6
|
-
const HotkeysContext = (0, react.createContext)(null);
|
|
7
|
-
const DEFAULT_OPTIONS = {};
|
|
8
|
-
function HotkeysProvider({ children, defaultOptions = DEFAULT_OPTIONS }) {
|
|
9
|
-
const contextValue = (0, react.useMemo)(() => ({ defaultOptions }), [defaultOptions]);
|
|
10
|
-
return /* @__PURE__ */ react.default.createElement(HotkeysContext.Provider, { value: contextValue }, children);
|
|
11
|
-
}
|
|
12
|
-
function useHotkeysContext() {
|
|
13
|
-
return (0, react.useContext)(HotkeysContext);
|
|
14
|
-
}
|
|
15
|
-
function useDefaultHotkeysOptions() {
|
|
16
|
-
return (0, react.useContext)(HotkeysContext)?.defaultOptions ?? {};
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
//#endregion
|
|
20
|
-
exports.HotkeysProvider = HotkeysProvider;
|
|
21
|
-
exports.useDefaultHotkeysOptions = useDefaultHotkeysOptions;
|
|
22
|
-
exports.useHotkeysContext = useHotkeysContext;
|
|
23
|
-
//# sourceMappingURL=HotkeysProvider.cjs.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"HotkeysProvider.cjs","names":[],"sources":["../src/HotkeysProvider.tsx"],"sourcesContent":["import React, { createContext, useContext, useMemo } from 'react'\nimport type { ReactNode } from 'react'\nimport type {\n HotkeyRecorderOptions,\n HotkeySequenceRecorderOptions,\n} from '@tanstack/hotkeys'\nimport type { UseHotkeyOptions } from './useHotkey'\nimport type { UseHotkeySequenceOptions } from './useHotkeySequence'\n\nexport interface HotkeysProviderOptions {\n hotkey?: Partial<UseHotkeyOptions>\n hotkeyRecorder?: Partial<HotkeyRecorderOptions>\n hotkeySequence?: Partial<UseHotkeySequenceOptions>\n hotkeySequenceRecorder?: Partial<HotkeySequenceRecorderOptions>\n}\n\ninterface HotkeysContextValue {\n defaultOptions: HotkeysProviderOptions\n}\n\nconst HotkeysContext = createContext<HotkeysContextValue | null>(null)\n\nexport interface HotkeysProviderProps {\n children: ReactNode\n defaultOptions?: HotkeysProviderOptions\n}\n\nconst DEFAULT_OPTIONS: HotkeysProviderOptions = {}\n\nexport function HotkeysProvider({\n children,\n defaultOptions = DEFAULT_OPTIONS,\n}: HotkeysProviderProps) {\n const contextValue: HotkeysContextValue = useMemo(\n () => ({\n defaultOptions,\n }),\n [defaultOptions],\n )\n\n return (\n // eslint-disable-next-line @eslint-react/no-context-provider -- React 19+ only; we support React >=16.8\n <HotkeysContext.Provider value={contextValue}>\n {children}\n </HotkeysContext.Provider>\n )\n}\n\nexport function useHotkeysContext() {\n // eslint-disable-next-line @eslint-react/no-use-context -- React 19+ only; we support React >=16.8\n return useContext(HotkeysContext)\n}\n\nexport function useDefaultHotkeysOptions() {\n // eslint-disable-next-line @eslint-react/no-use-context -- React 19+ only; we support React >=16.8\n const context = useContext(HotkeysContext)\n return context?.defaultOptions ?? {}\n}\n"],"mappings":";;;;;AAoBA,MAAM,0CAA2D,KAAK;AAOtE,MAAM,kBAA0C,EAAE;AAElD,SAAgB,gBAAgB,EAC9B,UACA,iBAAiB,mBACM;CACvB,MAAM,yCACG,EACL,gBACD,GACD,CAAC,eAAe,CACjB;AAED,QAEE,4CAAC,eAAe,UAAhB,EAAyB,OAAO,cAEN,EADvB,SACuB;;AAI9B,SAAgB,oBAAoB;AAElC,8BAAkB,eAAe;;AAGnC,SAAgB,2BAA2B;AAGzC,8BAD2B,eAAe,EAC1B,kBAAkB,EAAE"}
|
|
@@ -1,28 +0,0 @@
|
|
|
1
|
-
import { UseHotkeyOptions } from "./useHotkey.cjs";
|
|
2
|
-
import { UseHotkeySequenceOptions } from "./useHotkeySequence.cjs";
|
|
3
|
-
import { HotkeyRecorderOptions, HotkeySequenceRecorderOptions } from "@tanstack/hotkeys";
|
|
4
|
-
import React, { ReactNode } from "react";
|
|
5
|
-
|
|
6
|
-
//#region src/HotkeysProvider.d.ts
|
|
7
|
-
interface HotkeysProviderOptions {
|
|
8
|
-
hotkey?: Partial<UseHotkeyOptions>;
|
|
9
|
-
hotkeyRecorder?: Partial<HotkeyRecorderOptions>;
|
|
10
|
-
hotkeySequence?: Partial<UseHotkeySequenceOptions>;
|
|
11
|
-
hotkeySequenceRecorder?: Partial<HotkeySequenceRecorderOptions>;
|
|
12
|
-
}
|
|
13
|
-
interface HotkeysContextValue {
|
|
14
|
-
defaultOptions: HotkeysProviderOptions;
|
|
15
|
-
}
|
|
16
|
-
interface HotkeysProviderProps {
|
|
17
|
-
children: ReactNode;
|
|
18
|
-
defaultOptions?: HotkeysProviderOptions;
|
|
19
|
-
}
|
|
20
|
-
declare function HotkeysProvider({
|
|
21
|
-
children,
|
|
22
|
-
defaultOptions
|
|
23
|
-
}: HotkeysProviderProps): React.JSX.Element;
|
|
24
|
-
declare function useHotkeysContext(): HotkeysContextValue | null;
|
|
25
|
-
declare function useDefaultHotkeysOptions(): HotkeysProviderOptions;
|
|
26
|
-
//#endregion
|
|
27
|
-
export { HotkeysProvider, HotkeysProviderOptions, HotkeysProviderProps, useDefaultHotkeysOptions, useHotkeysContext };
|
|
28
|
-
//# sourceMappingURL=HotkeysProvider.d.cts.map
|