@tanstack/octane-hotkeys 0.15.6 → 0.16.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.
@@ -57,7 +57,7 @@ export declare function useDefaultHotkeysOptions(): DefaultHotkeysOptions;
57
57
  * hotkeys and merges default options. With `scope`, its hotkeys fire only
58
58
  * while it is mounted and enabled; with `exclusive`, only its hotkeys fire.
59
59
  */
60
- export declare function HotkeysProvider({ children, defaultOptions, appHotkeys, customHotkeys, onCustomHotkeysChange, scope, exclusive, enabled }: HotkeysProviderProps): import("octane").ElementDescriptor<{
60
+ export declare function HotkeysProvider({ children, defaultOptions, appHotkeys, customHotkeys, onCustomHotkeysChange, scope, exclusive, enabled, suspendCharacterKeys }: HotkeysProviderProps): import("octane").ElementDescriptor<{
61
61
  value: {
62
62
  defaultOptions: DefaultHotkeysOptions;
63
63
  appHotkeysStore: AppHotkeysStore<Readonly<Record<string, import("@tanstack/hotkeys").AppHotkey<string, import("@tanstack/hotkeys").HotkeyChord | import("@tanstack/hotkeys").HotkeySequence | null>>>> | null;
@@ -1,5 +1,5 @@
1
1
  import { subSlot } from "./internal.js";
2
- import { publishAppHotkeysStore } from "@tanstack/hotkeys";
2
+ import { getHotkeyManager, publishAppHotkeysStore } from "@tanstack/hotkeys";
3
3
  import { activateHotkeysProviderScope, createAppHotkeysStore, getHotkeysProviderScopeKey, mergeHotkeysProviderDefaults } from "@tanstack/hotkeys/adapter";
4
4
  import { createContext, createElement, useContext, useLayoutEffect, useRef } from "octane";
5
5
 
@@ -20,7 +20,7 @@ function useDefaultHotkeysOptions() {
20
20
  * hotkeys and merges default options. With `scope`, its hotkeys fire only
21
21
  * while it is mounted and enabled; with `exclusive`, only its hotkeys fire.
22
22
  */
23
- function HotkeysProvider({ children, defaultOptions, appHotkeys, customHotkeys, onCustomHotkeysChange, scope, exclusive, enabled = true }) {
23
+ function HotkeysProvider({ children, defaultOptions, appHotkeys, customHotkeys, onCustomHotkeysChange, scope, exclusive, enabled = true, suspendCharacterKeys = false }) {
24
24
  const parent = useContext(HotkeysContext);
25
25
  const callbackRef = useRef(onCustomHotkeysChange, subSlot(void 0, "provider-callback"));
26
26
  callbackRef.current = onCustomHotkeysChange;
@@ -54,6 +54,7 @@ function HotkeysProvider({ children, defaultOptions, appHotkeys, customHotkeys,
54
54
  parent: parent?.defaultOptions.hotkey?.scope
55
55
  });
56
56
  useLayoutEffect(() => scopeKey ? activateHotkeysProviderScope(scopeKey) : void 0, [scopeKey], subSlot(void 0, "provider-scope"));
57
+ useLayoutEffect(() => suspendCharacterKeys ? getHotkeyManager().suspendCharacterKeys() : void 0, [suspendCharacterKeys], subSlot(void 0, "provider-character-keys"));
57
58
  return createElement(HotkeysContext, {
58
59
  value: {
59
60
  defaultOptions: mergeHotkeysProviderDefaults(parent?.defaultOptions, defaultOptions, scope),
@@ -0,0 +1,24 @@
1
+ import { useDefaultHotkeysOptions } from "./HotkeysProvider.js";
2
+ import { subSlot } from "./internal.js";
3
+ import { useKeyboardLayout } from "./useKeyboardLayout.js";
4
+ import { detectPlatform } from "@tanstack/hotkeys";
5
+ import { createFormatter, getServerPlatformSnapshot } from "@tanstack/hotkeys/adapter";
6
+ import { useCallback, useSyncExternalStore } from "octane";
7
+
8
+ // src/_useFormatter.ts
9
+ const subscribe = () => () => {};
10
+ /**
11
+ * `format`, such as `formatForDisplay`, bound to the provider's platform, or the
12
+ * detected one, and the keyboard layout. `tag` keeps each formatter's slots
13
+ * apart when a component uses both. Without a provider platform, server
14
+ * rendering and hydration use 'linux', then the client re-renders with the
15
+ * detected platform.
16
+ */
17
+ function useFormatter(format, tag, slot) {
18
+ const provided = useDefaultHotkeysOptions().platform;
19
+ const platform = useSyncExternalStore(subscribe, () => provided ?? detectPlatform(), () => provided ?? getServerPlatformSnapshot(), subSlot(slot, `${tag}platform`));
20
+ const layoutMap = useKeyboardLayout(subSlot(slot, `${tag}layout`));
21
+ return useCallback(createFormatter(format, () => platform, () => layoutMap), [platform, layoutMap], subSlot(slot, `${tag}format`));
22
+ }
23
+
24
+ export { useFormatter };
@@ -0,0 +1,12 @@
1
+ import { formatForAria } from "@tanstack/hotkeys";
2
+ /**
3
+ * Formats a hotkey for `aria-keyshortcuts`, without the provider's platform or
4
+ * the user's keyboard layout.
5
+ *
6
+ * @deprecated Use `useFormatForAria()` in components. It returns this
7
+ * function with the provider's platform and the user's keyboard layout filled
8
+ * in. Outside a component, keep calling this function and pass `platform`
9
+ * yourself.
10
+ */
11
+ declare const formatForAria$1: typeof formatForAria;
12
+ export { formatForAria$1 as formatForAria };
@@ -0,0 +1,15 @@
1
+ import { formatForAria } from "@tanstack/hotkeys";
2
+
3
+ // src/formatForAria.ts
4
+ /**
5
+ * Formats a hotkey for `aria-keyshortcuts`, without the provider's platform or
6
+ * the user's keyboard layout.
7
+ *
8
+ * @deprecated Use `useFormatForAria()` in components. It returns this
9
+ * function with the provider's platform and the user's keyboard layout filled
10
+ * in. Outside a component, keep calling this function and pass `platform`
11
+ * yourself.
12
+ */
13
+ const formatForAria$1 = formatForAria;
14
+
15
+ export { formatForAria$1 as formatForAria };
package/dist/index.d.ts CHANGED
@@ -6,7 +6,9 @@ import { useHeldKeyCodes } from "./useHeldKeyCodes.js";
6
6
  import { useKeyHold } from "./useKeyHold.js";
7
7
  import { useHotkeyHint } from "./useHotkeyHint.js";
8
8
  import { useFormatForDisplay } from "./useFormatForDisplay.js";
9
+ import { useFormatForAria } from "./useFormatForAria.js";
9
10
  import { formatForDisplay } from "./formatForDisplay.js";
11
+ import { formatForAria } from "./formatForAria.js";
10
12
  import { useKeyboardLayout } from "./useKeyboardLayout.js";
11
13
  import { useHotkeyRegistrations } from "./useHotkeyRegistrations.js";
12
14
  import { useHotkeyScopesState } from "./useHotkeyScopesState.js";
@@ -14,4 +16,4 @@ import { useHotkeyRecorder } from "./useHotkeyRecorder.js";
14
16
  import { useAppHotkeyList, useAppHotkeys, useCustomHotkeys } from "./useAppHotkeys.js";
15
17
  import { HotkeyRegistrationsResult, OctaneHotkeyRecorder, UseCustomHotkeysResult } from "./types.js";
16
18
  export * from "@tanstack/hotkeys";
17
- export { type DefaultHotkeysOptions, HotkeyRegistrationsResult, HotkeysProvider, type HotkeysProviderOptions, type HotkeysProviderProps, OctaneHotkeyRecorder, UseAppHotkeyOptions, UseCustomHotkeysResult, UseHotkeyChordOptions, UseHotkeyCommonOptions, UseHotkeyDefinition, UseHotkeyOptions, UseHotkeyOptionsFor, UseHotkeySequenceOptions, UseHotkeyTarget, formatForDisplay, useAppHotkeyList, useAppHotkeys, useCustomHotkeys, useDefaultHotkeysOptions, useFormatForDisplay, useHeldKeyCodes, useHeldKeys, useHotkey, useHotkeyHint, useHotkeyRecorder, useHotkeyRegistrations, useHotkeyScopesState, useHotkeys, useHotkeysContext, useKeyHold, useKeyboardLayout };
19
+ export { type DefaultHotkeysOptions, HotkeyRegistrationsResult, HotkeysProvider, type HotkeysProviderOptions, type HotkeysProviderProps, OctaneHotkeyRecorder, UseAppHotkeyOptions, UseCustomHotkeysResult, UseHotkeyChordOptions, UseHotkeyCommonOptions, UseHotkeyDefinition, UseHotkeyOptions, UseHotkeyOptionsFor, UseHotkeySequenceOptions, UseHotkeyTarget, formatForAria, formatForDisplay, useAppHotkeyList, useAppHotkeys, useCustomHotkeys, useDefaultHotkeysOptions, useFormatForAria, useFormatForDisplay, useHeldKeyCodes, useHeldKeys, useHotkey, useHotkeyHint, useHotkeyRecorder, useHotkeyRegistrations, useHotkeyScopesState, useHotkeys, useHotkeysContext, useKeyHold, useKeyboardLayout };
package/dist/index.js CHANGED
@@ -6,7 +6,9 @@ import { useHeldKeyCodes } from "./useHeldKeyCodes.js";
6
6
  import { useKeyHold } from "./useKeyHold.js";
7
7
  import { useHotkeyHint } from "./useHotkeyHint.js";
8
8
  import { useFormatForDisplay } from "./useFormatForDisplay.js";
9
+ import { useFormatForAria } from "./useFormatForAria.js";
9
10
  import { formatForDisplay } from "./formatForDisplay.js";
11
+ import { formatForAria } from "./formatForAria.js";
10
12
  import { useKeyboardLayout } from "./useKeyboardLayout.js";
11
13
  import { useHotkeyRegistrations } from "./useHotkeyRegistrations.js";
12
14
  import { useHotkeyScopesState } from "./useHotkeyScopesState.js";
@@ -15,4 +17,4 @@ import { useAppHotkeyList, useAppHotkeys, useCustomHotkeys } from "./useAppHotke
15
17
 
16
18
  export * from "@tanstack/hotkeys"
17
19
 
18
- export { HotkeysProvider, formatForDisplay, useAppHotkeyList, useAppHotkeys, useCustomHotkeys, useDefaultHotkeysOptions, useFormatForDisplay, useHeldKeyCodes, useHeldKeys, useHotkey, useHotkeyHint, useHotkeyRecorder, useHotkeyRegistrations, useHotkeyScopesState, useHotkeys, useHotkeysContext, useKeyHold, useKeyboardLayout };
20
+ export { HotkeysProvider, formatForAria, formatForDisplay, useAppHotkeyList, useAppHotkeys, useCustomHotkeys, useDefaultHotkeysOptions, useFormatForAria, useFormatForDisplay, useHeldKeyCodes, useHeldKeys, useHotkey, useHotkeyHint, useHotkeyRecorder, useHotkeyRegistrations, useHotkeyScopesState, useHotkeys, useHotkeysContext, useKeyHold, useKeyboardLayout };
@@ -0,0 +1,30 @@
1
+ import { formatForAria } from "@tanstack/hotkeys";
2
+ /**
3
+ * Returns `formatForAria` with the platform from `HotkeysProvider`, or the
4
+ * detected platform without one. A `platform` passed to the returned function
5
+ * wins. Use its value for `aria-keyshortcuts`, so screen readers announce the
6
+ * shortcut. It returns `undefined` for a multi-step sequence, no hotkey, or a
7
+ * hotkey that can't fire right now (one that is disabled, in a suspended
8
+ * scope, a suspended character key, or not registered), so Octane omits the
9
+ * attribute. Without a provider platform, server rendering and hydration use
10
+ * 'linux', then the client re-renders with the detected platform.
11
+ *
12
+ * Physical bindings such as `[KeyQ]` name the key the user presses in
13
+ * Chromium browsers, once the keyboard layout has loaded. See
14
+ * `useKeyboardLayout`. A `layoutMap` passed to the returned function wins.
15
+ *
16
+ * Call the hook once at the top of the component; the returned function can
17
+ * be called anywhere. Server-rendered apps should set the provider's
18
+ * `defaultOptions.platform` from the request with `detectPlatform(userAgent)`,
19
+ * so the server HTML matches the user's platform.
20
+ *
21
+ * @example
22
+ * ```tsx
23
+ * function SearchButton() @{
24
+ * const formatForAria = useFormatForAria()
25
+ *
26
+ * <button aria-keyshortcuts={formatForAria('Mod+K')}>Search</button>
27
+ * }
28
+ * ```
29
+ */
30
+ export declare function useFormatForAria(): typeof formatForAria;
@@ -0,0 +1,15 @@
1
+ import { useFormatter } from "./_useFormatter.js";
2
+ import { subSlot } from "./internal.js";
3
+ import { useHotkeyRegistrations } from "./useHotkeyRegistrations.js";
4
+ import { formatForAria } from "@tanstack/hotkeys";
5
+ import { announceLiveHotkeys } from "@tanstack/hotkeys/adapter";
6
+ import { useCallback } from "octane";
7
+
8
+ // src/useFormatForAria.ts
9
+ function useFormatForAria(slot) {
10
+ const format = useFormatter(formatForAria, "aria-", slot);
11
+ const { hotkeys } = useHotkeyRegistrations(subSlot(slot, "aria-registrations"));
12
+ return useCallback(announceLiveHotkeys(format, () => hotkeys), [format, hotkeys], subSlot(slot, "aria-live"));
13
+ }
14
+
15
+ export { useFormatForAria };
@@ -1,17 +1,9 @@
1
- import { useDefaultHotkeysOptions } from "./HotkeysProvider.js";
2
- import { subSlot } from "./internal.js";
3
- import { useKeyboardLayout } from "./useKeyboardLayout.js";
4
- import { detectPlatform } from "@tanstack/hotkeys";
5
- import { createFormatForDisplay, getServerPlatformSnapshot } from "@tanstack/hotkeys/adapter";
6
- import { useCallback, useSyncExternalStore } from "octane";
1
+ import { useFormatter } from "./_useFormatter.js";
2
+ import { formatForDisplay } from "@tanstack/hotkeys";
7
3
 
8
4
  // src/useFormatForDisplay.ts
9
- const subscribe = () => () => {};
10
5
  function useFormatForDisplay(slot) {
11
- const provided = useDefaultHotkeysOptions().platform;
12
- const platform = useSyncExternalStore(subscribe, () => provided ?? detectPlatform(), () => provided ?? getServerPlatformSnapshot(), subSlot(slot, "platform"));
13
- const layoutMap = useKeyboardLayout(subSlot(slot, "layout"));
14
- return useCallback(createFormatForDisplay(() => platform, () => layoutMap), [platform, layoutMap], subSlot(slot, "format"));
6
+ return useFormatter(formatForDisplay, "", slot);
15
7
  }
16
8
 
17
9
  export { useFormatForDisplay };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tanstack/octane-hotkeys",
3
- "version": "0.15.6",
3
+ "version": "0.16.0",
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.36.0"
38
+ "@tanstack/hotkeys": "0.37.0"
39
39
  },
40
40
  "devDependencies": {
41
41
  "@tanstack/hotkeys-test-utils": "0.0.0",
@@ -49,26 +49,27 @@ export function Panel({ onSave }: { onSave: () => void }) @{
49
49
 
50
50
  ## API
51
51
 
52
- | API | What it's for |
53
- | ----------------------------------------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
54
- | `useHotkey(hotkey, callback, options?)` | Register one chord, sequence, or app hotkey while the component is mounted. |
55
- | `useHotkeys(definitions, commonOptions?)` | Register several hotkeys, or a list built from data, in one call. |
56
- | `<HotkeysProvider>` | Set default options, a scope (`exclusive` for dialogs), `enabled`, and app hotkeys for the components inside it. |
57
- | `useHotkeysContext()` | Read the nearest provider's merged defaults and enabled state, or `null` outside a provider. |
58
- | `useDefaultHotkeysOptions()` | Read the default options merged from every provider above. |
59
- | `useFormatForDisplay()` | Get the function that formats a hotkey as a label, with the provider's `platform` and the user's keyboard layout filled in. Only Chromium browsers report a layout, so physical keys keep their US labels in Firefox and Safari. Use it for every label in a component: `const formatForDisplay = useFormatForDisplay()` at the top, then `formatForDisplay(hotkey)`. |
60
- | `useAppHotkeys()` | Get the declared app hotkeys with the user's custom hotkeys applied, to pass to the register API. |
61
- | `useAppHotkeyList()` | List every app hotkey with its status, including ones whose components aren't mounted, for a cheat sheet or settings screen. |
62
- | `useCustomHotkeys()` | Read, change, and reset the user's custom hotkeys, and check a new one for conflicts. |
63
- | `useHotkeyRecorder(options)` | Record a chord or sequence the user presses, for a settings screen. |
64
- | `useHotkeyRegistrations()` | List every registered hotkey with its options, `meta`, and `status` (whether it's enabled and in an active scope), for a cheat sheet of what's mounted. |
65
- | `useHotkeyScopesState()` | Get the active scopes and the exclusive scope that owns the keyboard. |
66
- | `useHotkeyHint(hotkey, options?)` | Get whether held modifiers should reveal a shortcut's hint, such as labels that appear while Mod is held. False unless a registration of the hotkey can fire: enabled, in an active scope, and with focus inside its element target. |
67
- | `useKeyHold(key)` | Get whether one key is held, such as Shift for a range-select mode. Letters match in any case; other names, such as `Shift`, are case-sensitive. |
68
- | `useHeldKeys()` | Get every key that's held right now. |
69
- | `useHeldKeyCodes()` | Map each held key to its physical `event.code`. |
52
+ | API | What it's for |
53
+ | ----------------------------------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
54
+ | `useHotkey(hotkey, callback, options?)` | Register one chord, sequence, or app hotkey while the component is mounted. |
55
+ | `useHotkeys(definitions, commonOptions?)` | Register several hotkeys, or a list built from data, in one call. |
56
+ | `<HotkeysProvider>` | Set default options, a scope (`exclusive` for dialogs), `enabled`, `suspendCharacterKeys` (set from a user setting that turns off single-key shortcuts; it applies app-wide while the provider is mounted), and app hotkeys for the components inside it. |
57
+ | `useHotkeysContext()` | Read the nearest provider's merged defaults and enabled state, or `null` outside a provider. |
58
+ | `useDefaultHotkeysOptions()` | Read the default options merged from every provider above. |
59
+ | `useFormatForDisplay()` | Get the function that formats a hotkey as a label, with the provider's `platform` and the user's keyboard layout filled in. Only Chromium browsers report a layout, so physical keys keep their US labels in Firefox and Safari. Use it for every label in a component: `const formatForDisplay = useFormatForDisplay()` at the top, then `formatForDisplay(hotkey)`. |
60
+ | `useFormatForAria()` | Get the function that formats a hotkey for `aria-keyshortcuts`, with the provider's `platform` and the user's keyboard layout filled in. Returns `undefined` for a multi-step sequence, no hotkey, or a hotkey that can't fire right now, such as a disabled or suspended one, so the attribute is omitted. Set `aria-keyshortcuts` on every control that has a shortcut, next to the visible label. |
61
+ | `useAppHotkeys()` | Get the declared app hotkeys with the user's custom hotkeys applied, to pass to the register API. |
62
+ | `useAppHotkeyList()` | List every app hotkey with its status, including ones whose components aren't mounted, for a cheat sheet or settings screen. |
63
+ | `useCustomHotkeys()` | Read, change, and reset the user's custom hotkeys, and check a new one for conflicts. |
64
+ | `useHotkeyRecorder(options)` | Record a chord or sequence the user presses, for a settings screen. |
65
+ | `useHotkeyRegistrations()` | List every registered hotkey with its options, `meta`, and `status` (whether it's enabled and in an active scope), for a cheat sheet of what's mounted. |
66
+ | `useHotkeyScopesState()` | Get the active scopes and the exclusive scope that owns the keyboard. |
67
+ | `useHotkeyHint(hotkey, options?)` | Get whether held modifiers should reveal a shortcut's hint, such as labels that appear while Mod is held. False unless a registration of the hotkey can fire: enabled, in an active scope, and with focus inside its element target. |
68
+ | `useKeyHold(key)` | Get whether one key is held, such as Shift for a range-select mode. Letters match in any case; other names, such as `Shift`, are case-sensitive. |
69
+ | `useHeldKeys()` | Get every key that's held right now. |
70
+ | `useHeldKeyCodes()` | Map each held key to its physical `event.code`. |
70
71
 
71
- The package also re-exports `@tanstack/hotkeys`, such as `matchesKeyboardEvent` and `defineAppHotkeys`. Its plain `formatForDisplay` export is deprecated: use `useFormatForDisplay()` in components. Outside a component, call the plain function and pass `platform`.
72
+ The package also re-exports `@tanstack/hotkeys`, such as `matchesKeyboardEvent` and `defineAppHotkeys`. Its plain `formatForDisplay` export is deprecated: use `useFormatForDisplay()` in components. Outside a component, call the plain function and pass `platform`. The plain `formatForAria` export is deprecated the same way, in favor of `useFormatForAria()`.
72
73
 
73
74
  No provider is required. Use Octane 0.12 or newer, with hooks in compiler-enabled `.tsrx` components.
74
75