@tanstack/preact-hotkeys 0.20.1 → 0.20.2
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/HotkeysProvider.d.ts +4 -5
- package/dist/HotkeysProvider.js +2 -3
- package/dist/_appHotkeysStore.js +1 -2
- package/dist/_useSelector.js +1 -2
- package/dist/index.d.ts +1 -1
- package/dist/index.js +1 -1
- package/dist/useAppHotkeys.d.ts +1 -3
- package/dist/useAppHotkeys.js +2 -3
- package/dist/useFormatForDisplay.d.ts +1 -3
- package/dist/useFormatForDisplay.js +1 -2
- package/dist/useHeldKeyCodes.d.ts +1 -3
- package/dist/useHeldKeyCodes.js +1 -2
- package/dist/useHeldKeys.d.ts +1 -3
- package/dist/useHeldKeys.js +1 -2
- package/dist/useHotkey.d.ts +2 -4
- package/dist/useHotkey.js +1 -2
- package/dist/useHotkeyHint.d.ts +1 -3
- package/dist/useHotkeyHint.js +2 -3
- package/dist/useHotkeyRecorder.d.ts +1 -3
- package/dist/useHotkeyRecorder.js +2 -3
- package/dist/useHotkeyRegistrations.d.ts +1 -3
- package/dist/useHotkeyRegistrations.js +1 -2
- package/dist/useHotkeyScopesState.d.ts +1 -3
- package/dist/useHotkeyScopesState.js +1 -2
- package/dist/useHotkeys.d.ts +1 -3
- package/dist/useHotkeys.js +2 -3
- package/dist/useKeyHold.d.ts +1 -3
- package/dist/useKeyHold.js +1 -2
- package/dist/utils.js +1 -2
- package/package.json +7 -7
- package/skills/preact-hotkeys/SKILL.md +1 -1
- package/skills/preact-hotkeys/references/app-hotkeys.md +2 -2
|
@@ -1,8 +1,7 @@
|
|
|
1
1
|
import { UseHotkeyCommonOptions } from "./useHotkey.js";
|
|
2
2
|
import { AppHotkeys, AppHotkeysStore, CustomHotkeys, HotkeyChordRecorderOptions, HotkeyPlatform, HotkeySequenceRecorderOptions } from "@tanstack/hotkeys";
|
|
3
|
-
import { ComponentChildren } from "preact";
|
|
4
3
|
import { HotkeysProviderScopeProps } from "@tanstack/hotkeys/adapter";
|
|
5
|
-
|
|
4
|
+
import { ComponentChildren } from "preact";
|
|
6
5
|
export interface HotkeysProviderOptions {
|
|
7
6
|
/**
|
|
8
7
|
* The user's platform, for labels from `useFormatForDisplay`, hotkeys, and
|
|
@@ -35,8 +34,8 @@ export interface HotkeysProviderProps<T extends AppHotkeys = AppHotkeys> extends
|
|
|
35
34
|
/**
|
|
36
35
|
* The user's saved custom hotkeys. When the value changes, such as after
|
|
37
36
|
* saved data loads or the user signs in, it replaces the current custom
|
|
38
|
-
* hotkeys. `undefined` leaves them unchanged; `null` clears them.
|
|
39
|
-
* entries are ignored
|
|
37
|
+
* hotkeys. `undefined` leaves them unchanged; `null` clears them. Unknown
|
|
38
|
+
* ids and invalid entries are ignored.
|
|
40
39
|
*/
|
|
41
40
|
customHotkeys?: CustomHotkeys<T> | null;
|
|
42
41
|
/** Called with the custom hotkeys after every change, ready to save. */
|
|
@@ -78,4 +77,4 @@ export interface HotkeysProviderProps<T extends AppHotkeys = AppHotkeys> extends
|
|
|
78
77
|
export declare function HotkeysProvider<T extends AppHotkeys = AppHotkeys>({ children, appHotkeys, customHotkeys, onCustomHotkeysChange, defaultOptions, scope, exclusive, enabled }: HotkeysProviderProps<T>): import("preact").JSX.Element;
|
|
79
78
|
export declare function useHotkeysContext(): HotkeysContextValue | null;
|
|
80
79
|
export declare function useDefaultHotkeysOptions(): HotkeysProviderOptions;
|
|
81
|
-
|
|
80
|
+
export {};
|
package/dist/HotkeysProvider.js
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import { publishAppHotkeysStore } from "@tanstack/hotkeys";
|
|
2
|
+
import { activateHotkeysProviderScope, createAppHotkeysStore, getHotkeysProviderScopeKey, mergeHotkeysProviderDefaults } from "@tanstack/hotkeys/adapter";
|
|
2
3
|
import { createContext } from "preact";
|
|
3
4
|
import { useContext, useLayoutEffect, useMemo, useState } from "preact/hooks";
|
|
4
|
-
import { activateHotkeysProviderScope, createAppHotkeysStore, getHotkeysProviderScopeKey, mergeHotkeysProviderDefaults } from "@tanstack/hotkeys/adapter";
|
|
5
5
|
import { jsx } from "preact/jsx-runtime";
|
|
6
6
|
|
|
7
|
-
|
|
7
|
+
// src/HotkeysProvider.tsx
|
|
8
8
|
const HotkeysContext = createContext(null);
|
|
9
9
|
const DEFAULT_OPTIONS = {};
|
|
10
10
|
const NO_PARENT = {
|
|
@@ -99,5 +99,4 @@ function useDefaultHotkeysOptions() {
|
|
|
99
99
|
return useContext(HotkeysContext)?.defaultOptions ?? DEFAULT_OPTIONS;
|
|
100
100
|
}
|
|
101
101
|
|
|
102
|
-
//#endregion
|
|
103
102
|
export { HotkeysProvider, useDefaultHotkeysOptions, useHotkeysContext };
|
package/dist/_appHotkeysStore.js
CHANGED
|
@@ -2,7 +2,7 @@ import { useHotkeysContext } from "./HotkeysProvider.js";
|
|
|
2
2
|
import { useSelector } from "./_useSelector.js";
|
|
3
3
|
import { createStore } from "@tanstack/hotkeys/adapter";
|
|
4
4
|
|
|
5
|
-
|
|
5
|
+
// src/_appHotkeysStore.ts
|
|
6
6
|
const NO_APP_HOTKEYS = createStore(null);
|
|
7
7
|
/**
|
|
8
8
|
* The provider's app hotkeys store, re-rendering when app hotkeys or custom
|
|
@@ -14,5 +14,4 @@ function useAppHotkeysStoreState() {
|
|
|
14
14
|
return store;
|
|
15
15
|
}
|
|
16
16
|
|
|
17
|
-
//#endregion
|
|
18
17
|
export { useAppHotkeysStoreState };
|
package/dist/_useSelector.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { useEffect, useLayoutEffect, useMemo, useRef, useState } from "preact/hooks";
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
// src/_useSelector.ts
|
|
4
4
|
/**
|
|
5
5
|
* Subscribes to a store and returns the selected value, re-rendering when it
|
|
6
6
|
* changes (by `Object.is`). The selector runs again only when the store's
|
|
@@ -50,5 +50,4 @@ function useSelector(store, selector) {
|
|
|
50
50
|
return value;
|
|
51
51
|
}
|
|
52
52
|
|
|
53
|
-
//#endregion
|
|
54
53
|
export { useSelector };
|
package/dist/index.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { UseAppHotkeyOptions, UseHotkeyChordOptions, UseHotkeyCommonOptions, UseHotkeyOptions, UseHotkeyOptionsFor, UseHotkeySequenceOptions, UseHotkeyTarget, useHotkey } from "./useHotkey.js";
|
|
2
1
|
import { HotkeysProvider, HotkeysProviderOptions, HotkeysProviderProps, useDefaultHotkeysOptions, useHotkeysContext } from "./HotkeysProvider.js";
|
|
2
|
+
import { UseAppHotkeyOptions, UseHotkeyChordOptions, UseHotkeyCommonOptions, UseHotkeyOptions, UseHotkeyOptionsFor, UseHotkeySequenceOptions, UseHotkeyTarget, useHotkey } from "./useHotkey.js";
|
|
3
3
|
import { UseHotkeyDefinition, useHotkeys } from "./useHotkeys.js";
|
|
4
4
|
import { PreactHotkeyRecorder, useHotkeyRecorder } from "./useHotkeyRecorder.js";
|
|
5
5
|
import { useHotkeyRegistrations } from "./useHotkeyRegistrations.js";
|
package/dist/index.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { HotkeysProvider, useDefaultHotkeysOptions, useHotkeysContext } from "./HotkeysProvider.js";
|
|
2
|
-
import { useHotkeys } from "./useHotkeys.js";
|
|
3
2
|
import { useHotkey } from "./useHotkey.js";
|
|
3
|
+
import { useHotkeys } from "./useHotkeys.js";
|
|
4
4
|
import { useHotkeyRecorder } from "./useHotkeyRecorder.js";
|
|
5
5
|
import { useHotkeyRegistrations } from "./useHotkeyRegistrations.js";
|
|
6
6
|
import { useHotkeyScopesState } from "./useHotkeyScopesState.js";
|
package/dist/useAppHotkeys.d.ts
CHANGED
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import { AppHotkey, AppHotkeyListItem, CustomHotkeys, Hotkey, RegisteredAppHotkeys } from "@tanstack/hotkeys";
|
|
2
|
-
//#region src/useAppHotkeys.d.ts
|
|
3
2
|
/**
|
|
4
3
|
* Returns the effective app hotkeys from `HotkeysProvider`, typed by
|
|
5
4
|
* `Register`: each declaration with the user's custom hotkey applied.
|
|
@@ -67,5 +66,4 @@ export interface UseCustomHotkeysResult {
|
|
|
67
66
|
* })
|
|
68
67
|
* ```
|
|
69
68
|
*/
|
|
70
|
-
export declare function useCustomHotkeys(): UseCustomHotkeysResult;
|
|
71
|
-
//#endregion
|
|
69
|
+
export declare function useCustomHotkeys(): UseCustomHotkeysResult;
|
package/dist/useAppHotkeys.js
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import { useAppHotkeysStoreState } from "./_appHotkeysStore.js";
|
|
2
2
|
import { useHotkeyRegistrations } from "./useHotkeyRegistrations.js";
|
|
3
3
|
|
|
4
|
-
|
|
4
|
+
// src/useAppHotkeys.ts
|
|
5
5
|
function useRequiredStore(hook) {
|
|
6
6
|
const store = useAppHotkeysStoreState();
|
|
7
|
-
if (!store) throw new Error(
|
|
7
|
+
if (!store) throw new Error(`[hotkeys] ${hook} requires a HotkeysProvider with an appHotkeys prop`);
|
|
8
8
|
return store;
|
|
9
9
|
}
|
|
10
10
|
/**
|
|
@@ -75,5 +75,4 @@ function useCustomHotkeys() {
|
|
|
75
75
|
};
|
|
76
76
|
}
|
|
77
77
|
|
|
78
|
-
//#endregion
|
|
79
78
|
export { useAppHotkeyList, useAppHotkeys, useCustomHotkeys };
|
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import { formatForDisplay } from "@tanstack/hotkeys";
|
|
2
|
-
//#region src/useFormatForDisplay.d.ts
|
|
3
2
|
/**
|
|
4
3
|
* Returns `formatForDisplay` with the platform from `HotkeysProvider`, or the
|
|
5
4
|
* detected platform without one. A `platform` passed to the returned function
|
|
@@ -23,5 +22,4 @@ import { formatForDisplay } from "@tanstack/hotkeys";
|
|
|
23
22
|
* }
|
|
24
23
|
* ```
|
|
25
24
|
*/
|
|
26
|
-
export declare function useFormatForDisplay(): typeof formatForDisplay;
|
|
27
|
-
//#endregion
|
|
25
|
+
export declare function useFormatForDisplay(): typeof formatForDisplay;
|
|
@@ -2,7 +2,7 @@ import { useDefaultHotkeysOptions } from "./HotkeysProvider.js";
|
|
|
2
2
|
import { formatForDisplay } from "@tanstack/hotkeys";
|
|
3
3
|
import { useCallback } from "preact/hooks";
|
|
4
4
|
|
|
5
|
-
|
|
5
|
+
// src/useFormatForDisplay.ts
|
|
6
6
|
/**
|
|
7
7
|
* Returns `formatForDisplay` with the platform from `HotkeysProvider`, or the
|
|
8
8
|
* detected platform without one. A `platform` passed to the returned function
|
|
@@ -34,5 +34,4 @@ function useFormatForDisplay() {
|
|
|
34
34
|
}), [platform]);
|
|
35
35
|
}
|
|
36
36
|
|
|
37
|
-
//#endregion
|
|
38
37
|
export { useFormatForDisplay };
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
//#region src/useHeldKeyCodes.d.ts
|
|
2
1
|
/**
|
|
3
2
|
* Preact hook that returns a map of currently held key names to their physical `event.code` values.
|
|
4
3
|
*
|
|
@@ -25,5 +24,4 @@
|
|
|
25
24
|
* }
|
|
26
25
|
* ```
|
|
27
26
|
*/
|
|
28
|
-
export declare function useHeldKeyCodes(): Record<string, string>;
|
|
29
|
-
//#endregion
|
|
27
|
+
export declare function useHeldKeyCodes(): Record<string, string>;
|
package/dist/useHeldKeyCodes.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { useSelector } from "./_useSelector.js";
|
|
2
2
|
import { getKeyStateTracker } from "@tanstack/hotkeys";
|
|
3
3
|
|
|
4
|
-
|
|
4
|
+
// src/useHeldKeyCodes.ts
|
|
5
5
|
/**
|
|
6
6
|
* Preact hook that returns a map of currently held key names to their physical `event.code` values.
|
|
7
7
|
*
|
|
@@ -33,5 +33,4 @@ function useHeldKeyCodes() {
|
|
|
33
33
|
return useSelector(tracker.store, (state) => state.heldCodes);
|
|
34
34
|
}
|
|
35
35
|
|
|
36
|
-
//#endregion
|
|
37
36
|
export { useHeldKeyCodes };
|
package/dist/useHeldKeys.d.ts
CHANGED
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
//#region src/useHeldKeys.d.ts
|
|
2
1
|
/**
|
|
3
2
|
* Preact hook that returns an array of currently held keyboard keys.
|
|
4
3
|
*
|
|
@@ -20,5 +19,4 @@
|
|
|
20
19
|
* }
|
|
21
20
|
* ```
|
|
22
21
|
*/
|
|
23
|
-
export declare function useHeldKeys(): Array<string>;
|
|
24
|
-
//#endregion
|
|
22
|
+
export declare function useHeldKeys(): Array<string>;
|
package/dist/useHeldKeys.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { useSelector } from "./_useSelector.js";
|
|
2
2
|
import { getKeyStateTracker } from "@tanstack/hotkeys";
|
|
3
3
|
|
|
4
|
-
|
|
4
|
+
// src/useHeldKeys.ts
|
|
5
5
|
/**
|
|
6
6
|
* Preact hook that returns an array of currently held keyboard keys.
|
|
7
7
|
*
|
|
@@ -28,5 +28,4 @@ function useHeldKeys() {
|
|
|
28
28
|
return useSelector(tracker.store, (state) => state.heldKeys);
|
|
29
29
|
}
|
|
30
30
|
|
|
31
|
-
//#endregion
|
|
32
31
|
export { useHeldKeys };
|
package/dist/useHotkey.d.ts
CHANGED
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import { AppHotkey, HotkeyCallback, HotkeyCallbackContextFor, RegisterableHotkey } from "@tanstack/hotkeys";
|
|
2
|
-
import { RefObject } from "preact";
|
|
3
2
|
import { AdapterAppHotkeyOptions, AdapterChordOptions, AdapterCommonOptions, AdapterHotkeyOptions, AdapterOptionsFor, AdapterSequenceOptions } from "@tanstack/hotkeys/adapter";
|
|
4
|
-
|
|
3
|
+
import { RefObject } from "preact";
|
|
5
4
|
/** A Preact ref, element, document, or window to listen on. */
|
|
6
5
|
export type UseHotkeyTarget = RefObject<HTMLElement | null> | HTMLElement | Document | Window | null;
|
|
7
6
|
/** Options shared by chords and sequences. */
|
|
@@ -63,5 +62,4 @@ export type UseAppHotkeyOptions<T extends AppHotkey = AppHotkey> = AdapterAppHot
|
|
|
63
62
|
* ```
|
|
64
63
|
*/
|
|
65
64
|
export declare function useHotkey<T extends AppHotkey>(hotkey: T | null | undefined, callback: HotkeyCallback, options?: UseAppHotkeyOptions<T>): void;
|
|
66
|
-
export declare function useHotkey<const T extends RegisterableHotkey>(hotkey: T | null | undefined, callback: HotkeyCallback<HotkeyCallbackContextFor<T>>, options?: UseHotkeyOptionsFor<T>): void;
|
|
67
|
-
//#endregion
|
|
65
|
+
export declare function useHotkey<const T extends RegisterableHotkey>(hotkey: T | null | undefined, callback: HotkeyCallback<HotkeyCallbackContextFor<T>>, options?: UseHotkeyOptionsFor<T>): void;
|
package/dist/useHotkey.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { useHotkeys } from "./useHotkeys.js";
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
// src/useHotkey.ts
|
|
4
4
|
function useHotkey(hotkey, callback, options) {
|
|
5
5
|
useHotkeys([{
|
|
6
6
|
hotkey,
|
|
@@ -9,5 +9,4 @@ function useHotkey(hotkey, callback, options) {
|
|
|
9
9
|
}]);
|
|
10
10
|
}
|
|
11
11
|
|
|
12
|
-
//#endregion
|
|
13
12
|
export { useHotkey };
|
package/dist/useHotkeyHint.d.ts
CHANGED
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import { AppHotkey, HeldModifierOptions, RegisterableHotkey } from "@tanstack/hotkeys";
|
|
2
|
-
//#region src/useHotkeyHint.d.ts
|
|
3
2
|
/**
|
|
4
3
|
* Returns a boolean indicating whether held modifiers reveal this shortcut.
|
|
5
4
|
* The hint shows only while the hotkey can fire: some registration of it is
|
|
@@ -10,5 +9,4 @@ import { AppHotkey, HeldModifierOptions, RegisterableHotkey } from "@tanstack/ho
|
|
|
10
9
|
* requires every modifier. A sequence reveals its hint from its first step.
|
|
11
10
|
* Only visibility changes cause a rerender. This helper does not register a shortcut. A hotkey on an element counts only while focus is inside it.
|
|
12
11
|
*/
|
|
13
|
-
export declare function useHotkeyHint(hotkey: RegisterableHotkey | AppHotkey | null | undefined, options?: HeldModifierOptions): boolean;
|
|
14
|
-
//#endregion
|
|
12
|
+
export declare function useHotkeyHint(hotkey: RegisterableHotkey | AppHotkey | null | undefined, options?: HeldModifierOptions): boolean;
|
package/dist/useHotkeyHint.js
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import { useSelector } from "./_useSelector.js";
|
|
2
1
|
import { useAppHotkeysStoreState } from "./_appHotkeysStore.js";
|
|
2
|
+
import { useSelector } from "./_useSelector.js";
|
|
3
3
|
import { getHotkeyManager, getKeyStateTracker, isAppHotkey, matchesHeldModifiers, resolveAppHotkey } from "@tanstack/hotkeys";
|
|
4
4
|
|
|
5
|
-
|
|
5
|
+
// src/useHotkeyHint.ts
|
|
6
6
|
/**
|
|
7
7
|
* Returns a boolean indicating whether held modifiers reveal this shortcut.
|
|
8
8
|
* The hint shows only while the hotkey can fire: some registration of it is
|
|
@@ -22,5 +22,4 @@ function useHotkeyHint(hotkey, options = {}) {
|
|
|
22
22
|
return active && held;
|
|
23
23
|
}
|
|
24
24
|
|
|
25
|
-
//#endregion
|
|
26
25
|
export { useHotkeyHint };
|
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import { Hotkey, HotkeyChord, HotkeyChordRecorderOptions, HotkeySequence, HotkeySequenceRecorderOptions } from "@tanstack/hotkeys";
|
|
2
|
-
//#region src/useHotkeyRecorder.d.ts
|
|
3
2
|
export interface PreactHotkeyRecorder<THotkey extends Hotkey = Hotkey> {
|
|
4
3
|
/** Whether recording is currently active */
|
|
5
4
|
isRecording: boolean;
|
|
@@ -54,5 +53,4 @@ export interface PreactHotkeyRecorder<THotkey extends Hotkey = Hotkey> {
|
|
|
54
53
|
* ```
|
|
55
54
|
*/
|
|
56
55
|
export declare function useHotkeyRecorder(options: HotkeyChordRecorderOptions): PreactHotkeyRecorder<HotkeyChord>;
|
|
57
|
-
export declare function useHotkeyRecorder(options: HotkeySequenceRecorderOptions): PreactHotkeyRecorder;
|
|
58
|
-
//#endregion
|
|
56
|
+
export declare function useHotkeyRecorder(options: HotkeySequenceRecorderOptions): PreactHotkeyRecorder;
|
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import { useDefaultHotkeysOptions } from "./HotkeysProvider.js";
|
|
2
2
|
import { useSelector } from "./_useSelector.js";
|
|
3
3
|
import { HotkeyRecorder } from "@tanstack/hotkeys";
|
|
4
|
-
import { useLayoutEffect, useRef, useState } from "preact/hooks";
|
|
5
4
|
import { withDefaults } from "@tanstack/hotkeys/adapter";
|
|
5
|
+
import { useLayoutEffect, useRef, useState } from "preact/hooks";
|
|
6
6
|
|
|
7
|
-
|
|
7
|
+
// src/useHotkeyRecorder.ts
|
|
8
8
|
function useHotkeyRecorder(options) {
|
|
9
9
|
const mergedOptions = withDefaults(useDefaultHotkeysOptions().hotkeyRecorder, options);
|
|
10
10
|
const recorderRef = useRef(null);
|
|
@@ -33,5 +33,4 @@ function useHotkeyRecorder(options) {
|
|
|
33
33
|
};
|
|
34
34
|
}
|
|
35
35
|
|
|
36
|
-
//#endregion
|
|
37
36
|
export { useHotkeyRecorder };
|
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import { HotkeyRegistrationView } from "@tanstack/hotkeys";
|
|
2
|
-
//#region src/useHotkeyRegistrations.d.ts
|
|
3
2
|
/**
|
|
4
3
|
* Preact hook that reactively reads every hotkey registration, chords and
|
|
5
4
|
* sequences, from the singleton HotkeyManager. Narrow each view with `kind`.
|
|
@@ -26,5 +25,4 @@ import { HotkeyRegistrationView } from "@tanstack/hotkeys";
|
|
|
26
25
|
* }
|
|
27
26
|
* ```
|
|
28
27
|
*/
|
|
29
|
-
export declare function useHotkeyRegistrations(): Array<HotkeyRegistrationView>;
|
|
30
|
-
//#endregion
|
|
28
|
+
export declare function useHotkeyRegistrations(): Array<HotkeyRegistrationView>;
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { useSelector } from "./_useSelector.js";
|
|
2
2
|
import { getHotkeyManager, toHotkeyRegistrationView } from "@tanstack/hotkeys";
|
|
3
3
|
|
|
4
|
-
|
|
4
|
+
// src/useHotkeyRegistrations.ts
|
|
5
5
|
/**
|
|
6
6
|
* Preact hook that reactively reads every hotkey registration, chords and
|
|
7
7
|
* sequences, from the singleton HotkeyManager. Narrow each view with `kind`.
|
|
@@ -32,5 +32,4 @@ function useHotkeyRegistrations() {
|
|
|
32
32
|
return useSelector(getHotkeyManager().registrations, (state) => Array.from(state.values()).map(toHotkeyRegistrationView));
|
|
33
33
|
}
|
|
34
34
|
|
|
35
|
-
//#endregion
|
|
36
35
|
export { useHotkeyRegistrations };
|
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import { HotkeyScopesState } from "@tanstack/hotkeys";
|
|
2
|
-
//#region src/useHotkeyScopesState.d.ts
|
|
3
2
|
/**
|
|
4
3
|
* Preact hook that returns the hotkey manager's scope state: the active
|
|
5
4
|
* scopes, the exclusive scope that owns the keyboard, and the scopes it
|
|
@@ -16,5 +15,4 @@ import { HotkeyScopesState } from "@tanstack/hotkeys";
|
|
|
16
15
|
* }
|
|
17
16
|
* ```
|
|
18
17
|
*/
|
|
19
|
-
export declare function useHotkeyScopesState(): HotkeyScopesState;
|
|
20
|
-
//#endregion
|
|
18
|
+
export declare function useHotkeyScopesState(): HotkeyScopesState;
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { useSelector } from "./_useSelector.js";
|
|
2
2
|
import { getHotkeyManager } from "@tanstack/hotkeys";
|
|
3
3
|
|
|
4
|
-
|
|
4
|
+
// src/useHotkeyScopesState.ts
|
|
5
5
|
/**
|
|
6
6
|
* Preact hook that returns the hotkey manager's scope state: the active
|
|
7
7
|
* scopes, the exclusive scope that owns the keyboard, and the scopes it
|
|
@@ -22,5 +22,4 @@ function useHotkeyScopesState() {
|
|
|
22
22
|
return useSelector(getHotkeyManager().scopes, (state) => state);
|
|
23
23
|
}
|
|
24
24
|
|
|
25
|
-
//#endregion
|
|
26
25
|
export { useHotkeyScopesState };
|
package/dist/useHotkeys.d.ts
CHANGED
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import { UseHotkeyCommonOptions, UseHotkeyTarget } from "./useHotkey.js";
|
|
2
2
|
import { AdapterHotkeyDefinition } from "@tanstack/hotkeys/adapter";
|
|
3
|
-
//#region src/useHotkeys.d.ts
|
|
4
3
|
/**
|
|
5
4
|
* One hotkey for `useHotkeys`. Chords accept `requireReset`; sequences accept
|
|
6
5
|
* `timeout`; hotkeys of unknown kind accept only shared options.
|
|
@@ -47,5 +46,4 @@ export type UseHotkeyDefinition = AdapterHotkeyDefinition<UseHotkeyTarget>;
|
|
|
47
46
|
* }
|
|
48
47
|
* ```
|
|
49
48
|
*/
|
|
50
|
-
export declare function useHotkeys(hotkeys: ReadonlyArray<UseHotkeyDefinition>, commonOptions?: UseHotkeyCommonOptions): void;
|
|
51
|
-
//#endregion
|
|
49
|
+
export declare function useHotkeys(hotkeys: ReadonlyArray<UseHotkeyDefinition>, commonOptions?: UseHotkeyCommonOptions): void;
|
package/dist/useHotkeys.js
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import { useHotkeysContext } from "./HotkeysProvider.js";
|
|
2
2
|
import { useAppHotkeysStoreState } from "./_appHotkeysStore.js";
|
|
3
3
|
import { resolveTarget } from "./utils.js";
|
|
4
|
-
import { useLayoutEffect, useRef } from "preact/hooks";
|
|
5
4
|
import { createHotkeyBindings, prepareHotkeyDefinitions } from "@tanstack/hotkeys/adapter";
|
|
5
|
+
import { useLayoutEffect, useRef } from "preact/hooks";
|
|
6
6
|
|
|
7
|
-
|
|
7
|
+
// src/useHotkeys.ts
|
|
8
8
|
/**
|
|
9
9
|
* Preact hook for registering several hotkeys at once: chords, sequences, and
|
|
10
10
|
* app hotkeys. Accepts a dynamic array, so it is safe to use with
|
|
@@ -78,5 +78,4 @@ function useHotkeys(hotkeys, commonOptions = {}) {
|
|
|
78
78
|
}, []);
|
|
79
79
|
}
|
|
80
80
|
|
|
81
|
-
//#endregion
|
|
82
81
|
export { useHotkeys };
|
package/dist/useKeyHold.d.ts
CHANGED
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import { IndividualKey } from "@tanstack/hotkeys";
|
|
2
|
-
//#region src/useKeyHold.d.ts
|
|
3
2
|
/**
|
|
4
3
|
* Preact hook that returns whether a specific key is currently being held.
|
|
5
4
|
*
|
|
@@ -39,5 +38,4 @@ import { IndividualKey } from "@tanstack/hotkeys";
|
|
|
39
38
|
* }
|
|
40
39
|
* ```
|
|
41
40
|
*/
|
|
42
|
-
export declare function useKeyHold(key: IndividualKey): boolean;
|
|
43
|
-
//#endregion
|
|
41
|
+
export declare function useKeyHold(key: IndividualKey): boolean;
|
package/dist/useKeyHold.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { useSelector } from "./_useSelector.js";
|
|
2
2
|
import { getKeyStateTracker } from "@tanstack/hotkeys";
|
|
3
3
|
|
|
4
|
-
|
|
4
|
+
// src/useKeyHold.ts
|
|
5
5
|
/**
|
|
6
6
|
* Preact hook that returns whether a specific key is currently being held.
|
|
7
7
|
*
|
|
@@ -47,5 +47,4 @@ function useKeyHold(key) {
|
|
|
47
47
|
return useSelector(tracker.store, (state) => state.heldKeys.some((heldKey) => heldKey.toLowerCase() === normalizedKey));
|
|
48
48
|
}
|
|
49
49
|
|
|
50
|
-
//#endregion
|
|
51
50
|
export { useKeyHold };
|
package/dist/utils.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
|
|
1
|
+
// src/utils.ts
|
|
2
2
|
/**
|
|
3
3
|
* Type guard to check if a value is a Preact ref-like object.
|
|
4
4
|
*/
|
|
@@ -13,5 +13,4 @@ function resolveTarget(target) {
|
|
|
13
13
|
return isRef(target) ? target.current : target;
|
|
14
14
|
}
|
|
15
15
|
|
|
16
|
-
//#endregion
|
|
17
16
|
export { resolveTarget };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tanstack/preact-hotkeys",
|
|
3
|
-
"version": "0.20.
|
|
3
|
+
"version": "0.20.2",
|
|
4
4
|
"description": "Preact adapter for TanStack Hotkeys",
|
|
5
5
|
"author": "Tanner Linsley",
|
|
6
6
|
"license": "MIT",
|
|
@@ -35,21 +35,21 @@
|
|
|
35
35
|
"skills"
|
|
36
36
|
],
|
|
37
37
|
"dependencies": {
|
|
38
|
-
"@tanstack/hotkeys": "0.
|
|
38
|
+
"@tanstack/hotkeys": "0.25.0"
|
|
39
39
|
},
|
|
40
40
|
"devDependencies": {
|
|
41
41
|
"@preact/preset-vite": "^2.10.6",
|
|
42
|
-
"@testing-library/preact": "^3.2.
|
|
43
|
-
"preact": "^11.0
|
|
42
|
+
"@testing-library/preact": "^3.2.6",
|
|
43
|
+
"preact": "^11.2.0"
|
|
44
44
|
},
|
|
45
45
|
"peerDependencies": {
|
|
46
46
|
"preact": ">=10.5.2"
|
|
47
47
|
},
|
|
48
48
|
"scripts": {
|
|
49
49
|
"clean": "premove ./build ./dist",
|
|
50
|
-
"lint": "
|
|
51
|
-
"lint:fix": "
|
|
52
|
-
"test:
|
|
50
|
+
"lint": "oxlint ./src",
|
|
51
|
+
"lint:fix": "oxlint ./src --fix",
|
|
52
|
+
"test:oxlint": "oxlint ./src",
|
|
53
53
|
"test:lib": "vitest --passWithNoTests",
|
|
54
54
|
"test:lib:dev": "pnpm test:lib --watch",
|
|
55
55
|
"test:types": "tsc",
|
|
@@ -71,9 +71,9 @@ No provider is required.
|
|
|
71
71
|
## A dialog that owns the keyboard
|
|
72
72
|
|
|
73
73
|
```tsx no-check
|
|
74
|
+
import { HotkeysProvider, useHotkey } from '@tanstack/preact-hotkeys'
|
|
74
75
|
import { useId } from 'preact/hooks'
|
|
75
76
|
import type { ComponentChildren } from 'preact'
|
|
76
|
-
import { HotkeysProvider, useHotkey } from '@tanstack/preact-hotkeys'
|
|
77
77
|
|
|
78
78
|
export function Dialog(props: {
|
|
79
79
|
onClose: () => void
|
|
@@ -19,10 +19,10 @@ declare module '@tanstack/preact-hotkeys' {
|
|
|
19
19
|
```
|
|
20
20
|
|
|
21
21
|
```tsx no-check
|
|
22
|
-
import type { ComponentChildren } from 'preact'
|
|
23
22
|
import { HotkeysProvider } from '@tanstack/preact-hotkeys'
|
|
24
|
-
import type { CustomHotkeys } from '@tanstack/preact-hotkeys'
|
|
25
23
|
import { appHotkeys } from './app-hotkeys'
|
|
24
|
+
import type { CustomHotkeys } from '@tanstack/preact-hotkeys'
|
|
25
|
+
import type { ComponentChildren } from 'preact'
|
|
26
26
|
|
|
27
27
|
const saved: CustomHotkeys = JSON.parse(localStorage.getItem('hotkeys') ?? '{}')
|
|
28
28
|
|