@tanstack/octane-hotkeys 0.14.0 → 0.14.1
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 +5 -13
- package/dist/types.d.ts +6 -36
- package/dist/useAppHotkeys.d.ts +2 -2
- package/dist/useAppHotkeys.js +3 -7
- package/dist/useFormatForDisplay.js +3 -7
- package/dist/useHotkey.d.ts +3 -5
- package/dist/useHotkeyHint.js +5 -5
- package/dist/useHotkeyRegistrations.js +3 -2
- package/dist/useHotkeys.js +2 -2
- package/package.json +2 -2
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { UseHotkeyCommonOptions } from "./useHotkey.js";
|
|
2
|
-
import { AppHotkeys, AppHotkeysStore, CustomHotkeys,
|
|
3
|
-
import { HotkeysProviderScopeProps } from "@tanstack/hotkeys/adapter";
|
|
2
|
+
import { AppHotkeys, AppHotkeysStore, CustomHotkeys, HotkeyPlatform } from "@tanstack/hotkeys";
|
|
3
|
+
import { HotkeyRecorderDefaults, HotkeysContextValue, HotkeysProviderScopeProps } from "@tanstack/hotkeys/adapter";
|
|
4
4
|
export interface DefaultHotkeysOptions {
|
|
5
5
|
/**
|
|
6
6
|
* The user's platform, for labels from `useFormatForDisplay`, hotkeys,
|
|
@@ -23,14 +23,7 @@ export interface DefaultHotkeysOptions {
|
|
|
23
23
|
*/
|
|
24
24
|
hotkey?: UseHotkeyCommonOptions;
|
|
25
25
|
/** Defaults for every `useHotkeyRecorder`. */
|
|
26
|
-
hotkeyRecorder?:
|
|
27
|
-
}
|
|
28
|
-
interface HotkeysContextValue {
|
|
29
|
-
/** Merged with every ancestor provider's defaults, including `hotkey.scope`. */
|
|
30
|
-
defaultOptions: DefaultHotkeysOptions;
|
|
31
|
-
appHotkeysStore: AppHotkeysStore | null;
|
|
32
|
-
/** Whether this provider and every ancestor are enabled. */
|
|
33
|
-
enabled: boolean;
|
|
26
|
+
hotkeyRecorder?: HotkeyRecorderDefaults;
|
|
34
27
|
}
|
|
35
28
|
export type HotkeysProviderOptions = DefaultHotkeysOptions;
|
|
36
29
|
export interface HotkeysProviderProps extends HotkeysProviderScopeProps {
|
|
@@ -54,7 +47,7 @@ export interface HotkeysProviderProps extends HotkeysProviderScopeProps {
|
|
|
54
47
|
onCustomHotkeysChange?: (customHotkeys: CustomHotkeys) => void;
|
|
55
48
|
}
|
|
56
49
|
/** Reads the nearest provider, or null outside a provider. */
|
|
57
|
-
export declare function useHotkeysContext(): HotkeysContextValue | null;
|
|
50
|
+
export declare function useHotkeysContext(): HotkeysContextValue<DefaultHotkeysOptions> | null;
|
|
58
51
|
/** Reads the nearest provider's defaults, or an empty object. */
|
|
59
52
|
export declare function useDefaultHotkeysOptions(): DefaultHotkeysOptions;
|
|
60
53
|
/**
|
|
@@ -71,5 +64,4 @@ export declare function HotkeysProvider({ children, defaultOptions, appHotkeys,
|
|
|
71
64
|
enabled: boolean;
|
|
72
65
|
};
|
|
73
66
|
children: unknown;
|
|
74
|
-
}>;
|
|
75
|
-
export {};
|
|
67
|
+
}>;
|
package/dist/types.d.ts
CHANGED
|
@@ -1,44 +1,14 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { CustomHotkeyActions, CustomHotkeys, Hotkey, HotkeyRecorderActions, HotkeyRecorderState, HotkeyRegistrationView, HotkeyRegistrationsResult } from "@tanstack/hotkeys";
|
|
2
2
|
/** Recording state and controls owned by the containing component. */
|
|
3
|
-
export interface OctaneHotkeyRecorder<THotkey extends Hotkey = Hotkey> {
|
|
4
|
-
/** Whether the recorder is listening for a shortcut. */
|
|
5
|
-
isRecording: boolean;
|
|
6
|
-
/** Chords captured so far in a multi-step recording. */
|
|
7
|
-
steps: HotkeySequence;
|
|
8
|
-
/** The last committed hotkey, including brackets for physical codes. */
|
|
9
|
-
recordedHotkey: THotkey | null;
|
|
10
|
-
/** Start a new recording session. */
|
|
11
|
-
startRecording: () => void;
|
|
12
|
-
/** Stop and clear recorder state without calling onRecord or onCancel. */
|
|
13
|
-
stopRecording: () => void;
|
|
14
|
-
/** Stop, clear recorder state, and call onCancel. */
|
|
15
|
-
cancelRecording: () => void;
|
|
16
|
-
/** Commit the current steps (multi-step recordings). */
|
|
17
|
-
commitRecording: () => void;
|
|
18
|
-
}
|
|
3
|
+
export interface OctaneHotkeyRecorder<THotkey extends Hotkey = Hotkey> extends HotkeyRecorderState<THotkey>, HotkeyRecorderActions {}
|
|
19
4
|
/** Live registration views from the shared hotkey manager. */
|
|
20
|
-
|
|
5
|
+
interface HotkeyRegistrationsResult$1 extends HotkeyRegistrationsResult {
|
|
21
6
|
/** Every registration, chords and sequences. Narrow each view with `kind`. */
|
|
22
7
|
hotkeys: Array<HotkeyRegistrationView>;
|
|
23
8
|
}
|
|
24
9
|
/** Custom hotkey state and actions returned by `useCustomHotkeys`. */
|
|
25
|
-
export interface UseCustomHotkeysResult {
|
|
10
|
+
export interface UseCustomHotkeysResult extends CustomHotkeyActions {
|
|
26
11
|
/** The user's hotkeys that differ from the defaults. */
|
|
27
12
|
customHotkeys: CustomHotkeys;
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
* Returns conflicting app hotkeys; when any exist, nothing changes. Pass
|
|
31
|
-
* the recorder's `context` for a recorded hotkey, as for `findConflicts`.
|
|
32
|
-
*/
|
|
33
|
-
setCustomHotkey: (id: keyof RegisteredAppHotkeys & string, hotkey: Hotkey | null, recordedWith?: RecordedKeyPresses) => Array<AppHotkey>;
|
|
34
|
-
/** Restores the default hotkey for an app hotkey. */
|
|
35
|
-
resetCustomHotkey: (id: keyof RegisteredAppHotkeys & string) => void;
|
|
36
|
-
/** Restores every default hotkey. */
|
|
37
|
-
resetCustomHotkeys: () => void;
|
|
38
|
-
/**
|
|
39
|
-
* Other app hotkeys that would collide if `id` used `hotkey`. Pass the
|
|
40
|
-
* recorder's `context` for a recorded hotkey: it has the key press, which
|
|
41
|
-
* also finds a hotkey written differently that the same press fires.
|
|
42
|
-
*/
|
|
43
|
-
findConflicts: (id: keyof RegisteredAppHotkeys & string, hotkey: Hotkey, recordedWith?: RecordedKeyPresses) => Array<AppHotkey>;
|
|
44
|
-
}
|
|
13
|
+
}
|
|
14
|
+
export { HotkeyRegistrationsResult$1 as HotkeyRegistrationsResult };
|
package/dist/useAppHotkeys.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { UseCustomHotkeysResult } from "./types.js";
|
|
2
|
-
import {
|
|
2
|
+
import { RegisteredAppHotkeyListItem, RegisteredAppHotkeys } from "@tanstack/hotkeys";
|
|
3
3
|
/**
|
|
4
4
|
* Returns the effective app hotkeys from `HotkeysProvider`, typed by
|
|
5
5
|
* `Register`: each declaration with the user's custom hotkey applied.
|
|
@@ -10,7 +10,7 @@ export declare function useAppHotkeys(): RegisteredAppHotkeys;
|
|
|
10
10
|
* cheat sheets and settings screens. App hotkeys whose components have not
|
|
11
11
|
* mounted are `'inactive'`; those without a hotkey are `'unbound'`.
|
|
12
12
|
*/
|
|
13
|
-
export declare function useAppHotkeyList(): Array<
|
|
13
|
+
export declare function useAppHotkeyList(): Array<RegisteredAppHotkeyListItem>;
|
|
14
14
|
/**
|
|
15
15
|
* Reads and changes the user's custom hotkeys. Changes apply to every
|
|
16
16
|
* registered app hotkey immediately and are passed to the provider's
|
package/dist/useAppHotkeys.js
CHANGED
|
@@ -1,12 +1,11 @@
|
|
|
1
1
|
import { useHotkeysContext } from "./HotkeysProvider.js";
|
|
2
2
|
import { subSlot, useAppHotkeysStore } from "./internal.js";
|
|
3
3
|
import { useHotkeyRegistrations } from "./useHotkeyRegistrations.js";
|
|
4
|
+
import { bindCustomHotkeyActions, requireAppHotkeysStore } from "@tanstack/hotkeys/adapter";
|
|
4
5
|
|
|
5
6
|
// src/useAppHotkeys.ts
|
|
6
7
|
function useRequiredStore(name, slot) {
|
|
7
|
-
|
|
8
|
-
if (!store) throw new Error(`[hotkeys] ${name} requires a HotkeysProvider with appHotkeys`);
|
|
9
|
-
return store;
|
|
8
|
+
return requireAppHotkeysStore(useAppHotkeysStore(useHotkeysContext()?.appHotkeysStore ?? null, subSlot(slot, `${name}-store`)), `${name} requires a HotkeysProvider with appHotkeys`);
|
|
10
9
|
}
|
|
11
10
|
function useAppHotkeys(slot) {
|
|
12
11
|
return useRequiredStore("useAppHotkeys", slot).appHotkeys;
|
|
@@ -20,10 +19,7 @@ function useCustomHotkeys(slot) {
|
|
|
20
19
|
const store = useRequiredStore("useCustomHotkeys", slot);
|
|
21
20
|
return {
|
|
22
21
|
customHotkeys: store.customHotkeys,
|
|
23
|
-
|
|
24
|
-
resetCustomHotkey: (id) => store.resetCustomHotkey(id),
|
|
25
|
-
resetCustomHotkeys: () => store.resetCustomHotkeys(),
|
|
26
|
-
findConflicts: (id, hotkey, recordedWith) => store.findConflicts(id, hotkey, recordedWith)
|
|
22
|
+
...bindCustomHotkeyActions(() => store)
|
|
27
23
|
};
|
|
28
24
|
}
|
|
29
25
|
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { useDefaultHotkeysOptions } from "./HotkeysProvider.js";
|
|
2
2
|
import { subSlot } from "./internal.js";
|
|
3
3
|
import { useKeyboardLayout } from "./useKeyboardLayout.js";
|
|
4
|
-
import { detectPlatform
|
|
5
|
-
import { getServerPlatformSnapshot } from "@tanstack/hotkeys/adapter";
|
|
4
|
+
import { detectPlatform } from "@tanstack/hotkeys";
|
|
5
|
+
import { createFormatForDisplay, getServerPlatformSnapshot } from "@tanstack/hotkeys/adapter";
|
|
6
6
|
import { useCallback, useSyncExternalStore } from "octane";
|
|
7
7
|
|
|
8
8
|
// src/useFormatForDisplay.ts
|
|
@@ -11,11 +11,7 @@ function useFormatForDisplay(slot) {
|
|
|
11
11
|
const provided = useDefaultHotkeysOptions().platform;
|
|
12
12
|
const platform = useSyncExternalStore(subscribe, () => provided ?? detectPlatform(), () => provided ?? getServerPlatformSnapshot(), subSlot(slot, "platform"));
|
|
13
13
|
const layoutMap = useKeyboardLayout(subSlot(slot, "layout"));
|
|
14
|
-
return useCallback((
|
|
15
|
-
...options,
|
|
16
|
-
platform: options?.platform ?? platform,
|
|
17
|
-
layoutMap: options?.layoutMap ?? layoutMap ?? void 0
|
|
18
|
-
}), [platform, layoutMap], subSlot(slot, "format"));
|
|
14
|
+
return useCallback(createFormatForDisplay(() => platform, () => layoutMap), [platform, layoutMap], subSlot(slot, "format"));
|
|
19
15
|
}
|
|
20
16
|
|
|
21
17
|
export { useFormatForDisplay };
|
package/dist/useHotkey.d.ts
CHANGED
|
@@ -1,12 +1,10 @@
|
|
|
1
|
-
import { AppHotkey, HotkeyCallback, HotkeyCallbackContextFor, RegisterableHotkey
|
|
2
|
-
import { AdapterAppHotkeyOptions, AdapterChordOptions, AdapterCommonOptions, AdapterHotkeyOptions, AdapterOptionsFor, AdapterSequenceOptions } from "@tanstack/hotkeys/adapter";
|
|
1
|
+
import { AppHotkey, HotkeyCallback, HotkeyCallbackContextFor, RegisterableHotkey } from "@tanstack/hotkeys";
|
|
2
|
+
import { AdapterAppHotkeyOptions, AdapterChordOptions, AdapterCommonOptions, AdapterHotkeyOptions, AdapterOptionsFor, AdapterSequenceOptions, RefTarget } from "@tanstack/hotkeys/adapter";
|
|
3
3
|
/**
|
|
4
4
|
* A ref object, element, document, or window to listen on. A `null` or
|
|
5
5
|
* `undefined` target, or a ref that is still unset, waits for the element.
|
|
6
6
|
*/
|
|
7
|
-
export type UseHotkeyTarget =
|
|
8
|
-
current: HTMLElement | null | undefined;
|
|
9
|
-
} | Target | null;
|
|
7
|
+
export type UseHotkeyTarget = RefTarget;
|
|
10
8
|
/** Options shared by chords and sequences. */
|
|
11
9
|
export type UseHotkeyOptions = AdapterHotkeyOptions<UseHotkeyTarget>;
|
|
12
10
|
/** Options for a chord such as `'Mod+S'`. */
|
package/dist/useHotkeyHint.js
CHANGED
|
@@ -1,16 +1,16 @@
|
|
|
1
1
|
import { useHotkeysContext } from "./HotkeysProvider.js";
|
|
2
2
|
import { select, splitSlot, subSlot, useAppHotkeysStore } from "./internal.js";
|
|
3
|
-
import { getHotkeyManager, getKeyStateTracker
|
|
3
|
+
import { getHotkeyManager, getKeyStateTracker } from "@tanstack/hotkeys";
|
|
4
|
+
import { isHotkeyHintVisible } from "@tanstack/hotkeys/adapter";
|
|
4
5
|
|
|
5
6
|
// src/useHotkeyHint.ts
|
|
6
7
|
function useHotkeyHint(hotkey, ...rest) {
|
|
7
8
|
const [args, slot] = splitSlot(rest);
|
|
8
9
|
const store = useAppHotkeysStore(useHotkeysContext()?.appHotkeysStore ?? null, subSlot(slot, "app-hotkeys"));
|
|
9
|
-
const resolved = isAppHotkey(hotkey) ? resolveAppHotkey(hotkey, store).hotkey : hotkey;
|
|
10
10
|
const manager = getHotkeyManager();
|
|
11
|
-
const active = select(manager.registrations, () =>
|
|
12
|
-
const
|
|
13
|
-
return active &&
|
|
11
|
+
const active = select(manager.registrations, () => manager.hasActiveRegistration(hotkey), subSlot(slot, "hint-active"));
|
|
12
|
+
const visible = select(getKeyStateTracker().store, (state) => isHotkeyHintVisible(hotkey, state.heldKeys, args[0], store), subSlot(slot, "hint"));
|
|
13
|
+
return active && visible;
|
|
14
14
|
}
|
|
15
15
|
|
|
16
16
|
export { useHotkeyHint };
|
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
import { select, subSlot } from "./internal.js";
|
|
2
|
-
import { getHotkeyManager
|
|
2
|
+
import { getHotkeyManager } from "@tanstack/hotkeys";
|
|
3
|
+
import { getHotkeyRegistrationViews } from "@tanstack/hotkeys/adapter";
|
|
3
4
|
|
|
4
5
|
// src/useHotkeyRegistrations.ts
|
|
5
6
|
function useHotkeyRegistrations(slot) {
|
|
6
|
-
return { hotkeys: select(getHotkeyManager().registrations,
|
|
7
|
+
return { hotkeys: select(getHotkeyManager().registrations, getHotkeyRegistrationViews, subSlot(slot, "hotkeys")) };
|
|
7
8
|
}
|
|
8
9
|
|
|
9
10
|
export { useHotkeyRegistrations };
|
package/dist/useHotkeys.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { useHotkeysContext } from "./HotkeysProvider.js";
|
|
2
2
|
import { splitSlot, subSlot, useAppHotkeysStore } from "./internal.js";
|
|
3
|
-
import { createHotkeyBindings, prepareHotkeyDefinitions } from "@tanstack/hotkeys/adapter";
|
|
3
|
+
import { createHotkeyBindings, prepareHotkeyDefinitions, resolveRefTarget } from "@tanstack/hotkeys/adapter";
|
|
4
4
|
import { useLayoutEffect, useRef } from "octane";
|
|
5
5
|
|
|
6
6
|
// src/useHotkeys.ts
|
|
@@ -17,7 +17,7 @@ function useHotkeys(definitions, ...rest) {
|
|
|
17
17
|
appHotkeysStore,
|
|
18
18
|
defaults: context?.defaultOptions.hotkey,
|
|
19
19
|
commonOptions,
|
|
20
|
-
resolveTarget:
|
|
20
|
+
resolveTarget: resolveRefTarget
|
|
21
21
|
}));
|
|
22
22
|
}, null, subSlot(slot, "update"));
|
|
23
23
|
useLayoutEffect(() => () => bindings.destroy(), [], subSlot(slot, "cleanup"));
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tanstack/octane-hotkeys",
|
|
3
|
-
"version": "0.14.
|
|
3
|
+
"version": "0.14.1",
|
|
4
4
|
"description": "Octane adapter for TanStack Hotkeys",
|
|
5
5
|
"author": "Tanner Linsley",
|
|
6
6
|
"license": "MIT",
|
|
@@ -35,7 +35,7 @@
|
|
|
35
35
|
"skills"
|
|
36
36
|
],
|
|
37
37
|
"dependencies": {
|
|
38
|
-
"@tanstack/hotkeys": "0.
|
|
38
|
+
"@tanstack/hotkeys": "0.30.0"
|
|
39
39
|
},
|
|
40
40
|
"devDependencies": {
|
|
41
41
|
"@tanstack/hotkeys-test-utils": "0.0.0",
|