@tanstack/preact-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 -13
- 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 +6 -4
- 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 +11 -16
- package/dist/HotkeysProvider.cjs +0 -26
- package/dist/HotkeysProvider.cjs.map +0 -1
- package/dist/HotkeysProvider.d.cts +0 -29
- package/dist/HotkeysProvider.js.map +0 -1
- package/dist/index.cjs +0 -33
- package/dist/index.d.cts +0 -13
- package/dist/useHeldKeyCodes.cjs +0 -37
- 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 -33
- 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 -121
- package/dist/useHotkey.cjs.map +0 -1
- package/dist/useHotkey.d.cts +0 -75
- package/dist/useHotkey.js.map +0 -1
- package/dist/useHotkeyRecorder.cjs +0 -71
- 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 -26
- package/dist/useHotkeyRegistrations.cjs.map +0 -1
- package/dist/useHotkeyRegistrations.d.cts +0 -26
- package/dist/useHotkeyRegistrations.js.map +0 -1
- package/dist/useHotkeySequence.cjs +0 -116
- package/dist/useHotkeySequence.cjs.map +0 -1
- package/dist/useHotkeySequence.d.cts +0 -59
- package/dist/useHotkeySequence.js.map +0 -1
- package/dist/useHotkeySequenceRecorder.cjs +0 -39
- package/dist/useHotkeySequenceRecorder.cjs.map +0 -1
- package/dist/useHotkeySequenceRecorder.d.cts +0 -19
- package/dist/useHotkeySequenceRecorder.js.map +0 -1
- package/dist/useHotkeySequences.cjs +0 -138
- 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 -136
- 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 -53
- 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 -56
- package/src/index.ts +0 -17
- package/src/useHeldKeyCodes.ts +0 -33
- package/src/useHeldKeys.ts +0 -29
- package/src/useHotkey.ts +0 -188
- package/src/useHotkeyRecorder.ts +0 -101
- package/src/useHotkeyRegistrations.ts +0 -45
- package/src/useHotkeySequence.ts +0 -188
- package/src/useHotkeySequenceRecorder.ts +0 -64
- package/src/useHotkeySequences.ts +0 -206
- package/src/useHotkeys.ts +0 -207
- package/src/useKeyHold.ts +0 -52
- package/src/utils.ts +0 -8
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 />
|
|
@@ -1,11 +1,9 @@
|
|
|
1
1
|
import { UseHotkeyOptions } from "./useHotkey.js";
|
|
2
2
|
import { UseHotkeySequenceOptions } from "./useHotkeySequence.js";
|
|
3
3
|
import { HotkeyRecorderOptions, HotkeySequenceRecorderOptions } from "@tanstack/hotkeys";
|
|
4
|
-
import * as _$preact from "preact";
|
|
5
4
|
import { ComponentChildren } from "preact";
|
|
6
|
-
|
|
7
5
|
//#region src/HotkeysProvider.d.ts
|
|
8
|
-
interface HotkeysProviderOptions {
|
|
6
|
+
export interface HotkeysProviderOptions {
|
|
9
7
|
hotkey?: Partial<UseHotkeyOptions>;
|
|
10
8
|
hotkeyRecorder?: Partial<HotkeyRecorderOptions>;
|
|
11
9
|
hotkeySequenceRecorder?: Partial<HotkeySequenceRecorderOptions>;
|
|
@@ -14,16 +12,11 @@ interface HotkeysProviderOptions {
|
|
|
14
12
|
interface HotkeysContextValue {
|
|
15
13
|
defaultOptions: HotkeysProviderOptions;
|
|
16
14
|
}
|
|
17
|
-
interface HotkeysProviderProps {
|
|
15
|
+
export interface HotkeysProviderProps {
|
|
18
16
|
children: ComponentChildren;
|
|
19
17
|
defaultOptions?: HotkeysProviderOptions;
|
|
20
18
|
}
|
|
21
|
-
declare function HotkeysProvider({
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
declare function useHotkeysContext(): HotkeysContextValue | null;
|
|
26
|
-
declare function useDefaultHotkeysOptions(): HotkeysProviderOptions;
|
|
27
|
-
//#endregion
|
|
28
|
-
export { HotkeysProvider, HotkeysProviderOptions, HotkeysProviderProps, useDefaultHotkeysOptions, useHotkeysContext };
|
|
29
|
-
//# sourceMappingURL=HotkeysProvider.d.ts.map
|
|
19
|
+
export declare function HotkeysProvider({ children, defaultOptions }: HotkeysProviderProps): import("preact").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 { PreactHotkeyRecorder, useHotkeyRecorder } from "./useHotkeyRecorder.js";
|
|
10
10
|
import { HotkeyRegistrationsResult, useHotkeyRegistrations } from "./useHotkeyRegistrations.js";
|
|
11
11
|
import { PreactHotkeySequenceRecorder, useHotkeySequenceRecorder } from "./useHotkeySequenceRecorder.js";
|
|
12
|
+
import { useHotkeyHint } from "./useHotkeyHint.js";
|
|
12
13
|
export * from "@tanstack/hotkeys";
|
|
13
|
-
export { HotkeyRegistrationsResult, HotkeysProvider, HotkeysProviderOptions, HotkeysProviderProps, PreactHotkeyRecorder, PreactHotkeySequenceRecorder, UseHotkeyDefinition, UseHotkeyOptions, UseHotkeySequenceDefinition, UseHotkeySequenceOptions, useDefaultHotkeysOptions, useHeldKeyCodes, useHeldKeys, useHotkey, useHotkeyRecorder, useHotkeyRegistrations, useHotkeySequence, useHotkeySequenceRecorder, useHotkeySequences, useHotkeys, useHotkeysContext, useKeyHold };
|
|
14
|
+
export { HotkeyRegistrationsResult, HotkeysProvider, HotkeysProviderOptions, HotkeysProviderProps, PreactHotkeyRecorder, PreactHotkeySequenceRecorder, 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/preact-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/preact-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,8 +1,7 @@
|
|
|
1
1
|
import { HotkeyCallback, HotkeyOptions, RegisterableHotkey } from "@tanstack/hotkeys";
|
|
2
2
|
import { RefObject } from "preact";
|
|
3
|
-
|
|
4
3
|
//#region src/useHotkey.d.ts
|
|
5
|
-
interface UseHotkeyOptions extends Omit<HotkeyOptions, 'target'> {
|
|
4
|
+
export interface UseHotkeyOptions extends Omit<HotkeyOptions, 'target'> {
|
|
6
5
|
/**
|
|
7
6
|
* The DOM element to attach the event listener to.
|
|
8
7
|
* Can be a Preact ref, direct DOM element, or null.
|
|
@@ -69,7 +68,5 @@ interface UseHotkeyOptions extends Omit<HotkeyOptions, 'target'> {
|
|
|
69
68
|
* }
|
|
70
69
|
* ```
|
|
71
70
|
*/
|
|
72
|
-
declare function useHotkey(hotkey: RegisterableHotkey, callback: HotkeyCallback, options?: UseHotkeyOptions): void;
|
|
73
|
-
//#endregion
|
|
74
|
-
export { UseHotkeyOptions, useHotkey };
|
|
75
|
-
//# sourceMappingURL=useHotkey.d.ts.map
|
|
71
|
+
export declare function useHotkey(hotkey: RegisterableHotkey, callback: HotkeyCallback, options?: UseHotkeyOptions): void;
|
|
72
|
+
//#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/preact-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 PreactHotkeyRecorder {
|
|
3
|
+
export interface PreactHotkeyRecorder {
|
|
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 PreactHotkeyRecorder {
|
|
|
51
50
|
* }
|
|
52
51
|
* ```
|
|
53
52
|
*/
|
|
54
|
-
declare function useHotkeyRecorder(options: HotkeyRecorderOptions): PreactHotkeyRecorder;
|
|
55
|
-
//#endregion
|
|
56
|
-
export { PreactHotkeyRecorder, useHotkeyRecorder };
|
|
57
|
-
//# sourceMappingURL=useHotkeyRecorder.d.ts.map
|
|
53
|
+
export declare function useHotkeyRecorder(options: HotkeyRecorderOptions): PreactHotkeyRecorder;
|
|
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 */
|
|
@@ -20,7 +19,5 @@ interface HotkeyRegistrationsResult {
|
|
|
20
19
|
*
|
|
21
20
|
* @returns Object with `hotkeys` and `sequences` arrays
|
|
22
21
|
*/
|
|
23
|
-
declare function useHotkeyRegistrations(): HotkeyRegistrationsResult;
|
|
24
|
-
//#endregion
|
|
25
|
-
export { HotkeyRegistrationsResult, useHotkeyRegistrations };
|
|
26
|
-
//# sourceMappingURL=useHotkeyRegistrations.d.ts.map
|
|
22
|
+
export declare function useHotkeyRegistrations(): HotkeyRegistrationsResult;
|
|
23
|
+
//#endregion
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { getHotkeyManager, getSequenceManager, toHotkeyRegistrationView } from "@tanstack/hotkeys";
|
|
2
|
+
import { useMemo } from "preact/hooks";
|
|
2
3
|
import { useSelector } from "@tanstack/preact-store";
|
|
3
4
|
|
|
4
5
|
//#region src/useHotkeyRegistrations.ts
|
|
@@ -15,12 +16,13 @@ import { useSelector } from "@tanstack/preact-store";
|
|
|
15
16
|
function useHotkeyRegistrations() {
|
|
16
17
|
const hotkeyManager = getHotkeyManager();
|
|
17
18
|
const sequenceManager = getSequenceManager();
|
|
19
|
+
const hotkeyState = useSelector(hotkeyManager.registrations);
|
|
20
|
+
const sequenceState = useSelector(sequenceManager.registrations);
|
|
18
21
|
return {
|
|
19
|
-
hotkeys:
|
|
20
|
-
sequences:
|
|
22
|
+
hotkeys: useMemo(() => Array.from(hotkeyState.values()).map(toHotkeyRegistrationView), [hotkeyState]),
|
|
23
|
+
sequences: useMemo(() => Array.from(sequenceState.values()), [sequenceState])
|
|
21
24
|
};
|
|
22
25
|
}
|
|
23
26
|
|
|
24
27
|
//#endregion
|
|
25
|
-
export { useHotkeyRegistrations };
|
|
26
|
-
//# sourceMappingURL=useHotkeyRegistrations.js.map
|
|
28
|
+
export { useHotkeyRegistrations };
|
|
@@ -1,8 +1,7 @@
|
|
|
1
1
|
import { HotkeyCallback, HotkeySequence, SequenceOptions } from "@tanstack/hotkeys";
|
|
2
2
|
import { RefObject } from "preact";
|
|
3
|
-
|
|
4
3
|
//#region src/useHotkeySequence.d.ts
|
|
5
|
-
interface UseHotkeySequenceOptions extends Omit<SequenceOptions, 'target'> {
|
|
4
|
+
export interface UseHotkeySequenceOptions extends Omit<SequenceOptions, 'target'> {
|
|
6
5
|
/**
|
|
7
6
|
* The DOM element to attach the event listener to.
|
|
8
7
|
* Can be a Preact ref, direct DOM element, or null.
|
|
@@ -53,7 +52,5 @@ interface UseHotkeySequenceOptions extends Omit<SequenceOptions, 'target'> {
|
|
|
53
52
|
* }
|
|
54
53
|
* ```
|
|
55
54
|
*/
|
|
56
|
-
declare function useHotkeySequence(sequence: HotkeySequence, callback: HotkeyCallback, options?: UseHotkeySequenceOptions): void;
|
|
57
|
-
//#endregion
|
|
58
|
-
export { UseHotkeySequenceOptions, useHotkeySequence };
|
|
59
|
-
//# sourceMappingURL=useHotkeySequence.d.ts.map
|
|
55
|
+
export declare function useHotkeySequence(sequence: HotkeySequence, callback: HotkeyCallback, options?: UseHotkeySequenceOptions): void;
|
|
56
|
+
//#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 PreactHotkeySequenceRecorder {
|
|
3
|
+
export interface PreactHotkeySequenceRecorder {
|
|
5
4
|
isRecording: boolean;
|
|
6
5
|
steps: HotkeySequence;
|
|
7
6
|
recordedSequence: HotkeySequence | null;
|
|
@@ -13,7 +12,5 @@ interface PreactHotkeySequenceRecorder {
|
|
|
13
12
|
/**
|
|
14
13
|
* Preact hook for recording multi-chord sequences (Vim-style shortcuts).
|
|
15
14
|
*/
|
|
16
|
-
declare function useHotkeySequenceRecorder(options: HotkeySequenceRecorderOptions): PreactHotkeySequenceRecorder;
|
|
17
|
-
//#endregion
|
|
18
|
-
export { PreactHotkeySequenceRecorder, useHotkeySequenceRecorder };
|
|
19
|
-
//# sourceMappingURL=useHotkeySequenceRecorder.d.ts.map
|
|
15
|
+
export declare function useHotkeySequenceRecorder(options: HotkeySequenceRecorderOptions): PreactHotkeySequenceRecorder;
|
|
16
|
+
//#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
|
* Preact 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/preact-hotkeys",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.12.0",
|
|
4
4
|
"description": "Preact adapter for TanStack Hotkeys",
|
|
5
5
|
"author": "Tanner Linsley",
|
|
6
6
|
"license": "MIT",
|
|
@@ -20,32 +20,26 @@
|
|
|
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/preact-store": "^0.13.3"
|
|
44
38
|
},
|
|
45
39
|
"devDependencies": {
|
|
46
|
-
"@preact/preset-vite": "^2.10.
|
|
40
|
+
"@preact/preset-vite": "^2.10.6",
|
|
47
41
|
"@testing-library/preact": "^3.2.4",
|
|
48
|
-
"preact": "^10.29.
|
|
42
|
+
"preact": "^10.29.8"
|
|
49
43
|
},
|
|
50
44
|
"peerDependencies": {
|
|
51
45
|
"preact": ">=10.0.0"
|
|
@@ -58,6 +52,7 @@
|
|
|
58
52
|
"test:lib": "vitest --passWithNoTests",
|
|
59
53
|
"test:lib:dev": "pnpm test:lib --watch",
|
|
60
54
|
"test:types": "tsc",
|
|
61
|
-
"build": "tsdown"
|
|
55
|
+
"build": "tsdown",
|
|
56
|
+
"test:build": "publint --strict && node ../../scripts/verify-package.ts"
|
|
62
57
|
}
|
|
63
58
|
}
|
package/dist/HotkeysProvider.cjs
DELETED
|
@@ -1,26 +0,0 @@
|
|
|
1
|
-
let preact = require("preact");
|
|
2
|
-
let preact_hooks = require("preact/hooks");
|
|
3
|
-
let preact_jsx_runtime = require("preact/jsx-runtime");
|
|
4
|
-
|
|
5
|
-
//#region src/HotkeysProvider.tsx
|
|
6
|
-
const HotkeysContext = (0, preact.createContext)(null);
|
|
7
|
-
const DEFAULT_OPTIONS = {};
|
|
8
|
-
function HotkeysProvider({ children, defaultOptions = DEFAULT_OPTIONS }) {
|
|
9
|
-
const contextValue = (0, preact_hooks.useMemo)(() => ({ defaultOptions }), [defaultOptions]);
|
|
10
|
-
return /* @__PURE__ */ (0, preact_jsx_runtime.jsx)(HotkeysContext.Provider, {
|
|
11
|
-
value: contextValue,
|
|
12
|
-
children
|
|
13
|
-
});
|
|
14
|
-
}
|
|
15
|
-
function useHotkeysContext() {
|
|
16
|
-
return (0, preact_hooks.useContext)(HotkeysContext);
|
|
17
|
-
}
|
|
18
|
-
function useDefaultHotkeysOptions() {
|
|
19
|
-
return (0, preact_hooks.useContext)(HotkeysContext)?.defaultOptions ?? {};
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
//#endregion
|
|
23
|
-
exports.HotkeysProvider = HotkeysProvider;
|
|
24
|
-
exports.useDefaultHotkeysOptions = useDefaultHotkeysOptions;
|
|
25
|
-
exports.useHotkeysContext = useHotkeysContext;
|
|
26
|
-
//# sourceMappingURL=HotkeysProvider.cjs.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"HotkeysProvider.cjs","names":[],"sources":["../src/HotkeysProvider.tsx"],"sourcesContent":["import { createContext } from 'preact'\nimport { useContext, useMemo } from 'preact/hooks'\nimport type { ComponentChildren } from 'preact'\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 hotkeySequenceRecorder?: Partial<HotkeySequenceRecorderOptions>\n hotkeySequence?: Partial<UseHotkeySequenceOptions>\n}\n\ninterface HotkeysContextValue {\n defaultOptions: HotkeysProviderOptions\n}\n\nconst HotkeysContext = createContext<HotkeysContextValue | null>(null)\n\nexport interface HotkeysProviderProps {\n children: ComponentChildren\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 <HotkeysContext.Provider value={contextValue}>\n {children}\n </HotkeysContext.Provider>\n )\n}\n\nexport function useHotkeysContext() {\n return useContext(HotkeysContext)\n}\n\nexport function useDefaultHotkeysOptions() {\n const context = useContext(HotkeysContext)\n return context?.defaultOptions ?? {}\n}\n"],"mappings":";;;;;AAqBA,MAAM,2CAA2D,KAAK;AAOtE,MAAM,kBAA0C,EAAE;AAElD,SAAgB,gBAAgB,EAC9B,UACA,iBAAiB,mBACM;CACvB,MAAM,gDACG,EACL,gBACD,GACD,CAAC,eAAe,CACjB;AAED,QACE,4CAAC,eAAe,UAAhB;EAAyB,OAAO;EAC7B;EACuB;;AAI9B,SAAgB,oBAAoB;AAClC,qCAAkB,eAAe;;AAGnC,SAAgB,2BAA2B;AAEzC,qCAD2B,eAAe,EAC1B,kBAAkB,EAAE"}
|