@tanstack/solid-hotkeys 0.26.3 → 0.27.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.
@@ -1,4 +1,4 @@
1
- import { publishAppHotkeysStore } from "@tanstack/hotkeys";
1
+ import { getHotkeyManager, publishAppHotkeysStore } from "@tanstack/hotkeys";
2
2
  import { activateHotkeysProviderScope, createAppHotkeysStore, getHotkeysProviderScopeKey, mergeHotkeysProviderDefaults } from "@tanstack/hotkeys/adapter";
3
3
  import { createComponent, createContext, createEffect, createMemo, untrack, useContext } from "solid-js";
4
4
 
@@ -60,6 +60,7 @@ const HotkeysProvider = (props) => {
60
60
  parent: parent?.defaultOptions.hotkey?.scope
61
61
  }));
62
62
  createEffect(scopeKey, (key) => key ? activateHotkeysProviderScope(key) : void 0);
63
+ createEffect(() => !!props.suspendCharacterKeys, (suspend) => suspend ? getHotkeyManager().suspendCharacterKeys() : void 0);
63
64
  return createComponent(HotkeysContext, {
64
65
  value: {
65
66
  get appHotkeysStore() {
@@ -0,0 +1,31 @@
1
+ import { formatForAria } from "@tanstack/hotkeys";
2
+ /**
3
+ * Returns `formatForAria` with the provider's `platform` as the default. Use
4
+ * its value for `aria-keyshortcuts`, so screen readers announce the shortcut.
5
+ * It returns `undefined` for a multi-step sequence, no hotkey, or a hotkey
6
+ * that can't fire right now (one that is disabled, in a suspended scope, a
7
+ * suspended character key, or not registered), so Solid omits the attribute.
8
+ * Call in a component; the returned function works anywhere, and JSX updates
9
+ * when the provider's platform changes. An explicit `platform` option wins.
10
+ *
11
+ * Physical bindings such as `[KeyQ]` name the key the user presses in
12
+ * Chromium browsers, once the keyboard layout has loaded. See
13
+ * `createKeyboardLayout`. An explicit `layoutMap` option wins.
14
+ *
15
+ * Server-rendered apps should set the provider's `defaultOptions.platform`
16
+ * from the request user agent with `detectPlatform(userAgent)`.
17
+ *
18
+ * @example
19
+ * ```tsx
20
+ * function SearchButton() {
21
+ * const appHotkeys = useAppHotkeys()
22
+ * const formatForAria = createFormatForAria()
23
+ * return (
24
+ * <button aria-keyshortcuts={formatForAria(appHotkeys()['search.open'].hotkey)}>
25
+ * Search
26
+ * </button>
27
+ * )
28
+ * }
29
+ * ```
30
+ */
31
+ export declare function createFormatForAria(): typeof formatForAria;
@@ -0,0 +1,44 @@
1
+ import { createHotkeyRegistrations } from "./createHotkeyRegistrations.js";
2
+ import { createKeyboardLayout } from "./createKeyboardLayout.js";
3
+ import { useDefaultHotkeysOptionsSource } from "./defaultOptions.js";
4
+ import { formatForAria } from "@tanstack/hotkeys";
5
+ import { announceLiveHotkeys, createFormatter } from "@tanstack/hotkeys/adapter";
6
+
7
+ // src/createFormatForAria.ts
8
+ /**
9
+ * Returns `formatForAria` with the provider's `platform` as the default. Use
10
+ * its value for `aria-keyshortcuts`, so screen readers announce the shortcut.
11
+ * It returns `undefined` for a multi-step sequence, no hotkey, or a hotkey
12
+ * that can't fire right now (one that is disabled, in a suspended scope, a
13
+ * suspended character key, or not registered), so Solid omits the attribute.
14
+ * Call in a component; the returned function works anywhere, and JSX updates
15
+ * when the provider's platform changes. An explicit `platform` option wins.
16
+ *
17
+ * Physical bindings such as `[KeyQ]` name the key the user presses in
18
+ * Chromium browsers, once the keyboard layout has loaded. See
19
+ * `createKeyboardLayout`. An explicit `layoutMap` option wins.
20
+ *
21
+ * Server-rendered apps should set the provider's `defaultOptions.platform`
22
+ * from the request user agent with `detectPlatform(userAgent)`.
23
+ *
24
+ * @example
25
+ * ```tsx
26
+ * function SearchButton() {
27
+ * const appHotkeys = useAppHotkeys()
28
+ * const formatForAria = createFormatForAria()
29
+ * return (
30
+ * <button aria-keyshortcuts={formatForAria(appHotkeys()['search.open'].hotkey)}>
31
+ * Search
32
+ * </button>
33
+ * )
34
+ * }
35
+ * ```
36
+ */
37
+ function createFormatForAria() {
38
+ const defaultOptions = useDefaultHotkeysOptionsSource();
39
+ const layoutMap = createKeyboardLayout();
40
+ const registrations = createHotkeyRegistrations();
41
+ return announceLiveHotkeys(createFormatter(formatForAria, () => defaultOptions().platform, layoutMap), registrations);
42
+ }
43
+
44
+ export { createFormatForAria };
@@ -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 `createFormatForAria()` 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 `createFormatForAria()` 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,11 +6,13 @@ import { createHotkeyRegistrations } from "./createHotkeyRegistrations.js";
6
6
  import { createHotkeyScopesState } from "./createHotkeyScopesState.js";
7
7
  import { createHotkeyHint } from "./createHotkeyHint.js";
8
8
  import { createFormatForDisplay } from "./createFormatForDisplay.js";
9
+ import { createFormatForAria } from "./createFormatForAria.js";
9
10
  import { formatForDisplay } from "./formatForDisplay.js";
11
+ import { formatForAria } from "./formatForAria.js";
10
12
  import { createKeyboardLayout } from "./createKeyboardLayout.js";
11
13
  import { UseCustomHotkeysResult, createAppHotkeyList, useAppHotkeys, useCustomHotkeys } from "./appHotkeys.js";
12
14
  import { createHeldKeys } from "./createHeldKeys.js";
13
15
  import { createHeldKeyCodes } from "./createHeldKeyCodes.js";
14
16
  import { createKeyHold } from "./createKeyHold.js";
15
17
  export * from "@tanstack/hotkeys";
16
- export { CreateAppHotkeyOptions, CreateHotkeyChordOptions, CreateHotkeyCommonOptions, CreateHotkeyDefinition, CreateHotkeyOptions, CreateHotkeyOptionsFor, CreateHotkeySequenceOptions, CreateHotkeyTarget, HotkeysProvider, HotkeysProviderOptions, HotkeysProviderProps, SolidHotkeyRecorder, UseCustomHotkeysResult, createAppHotkeyList, createFormatForDisplay, createHeldKeyCodes, createHeldKeys, createHotkey, createHotkeyHint, createHotkeyRecorder, createHotkeyRegistrations, createHotkeyScopesState, createHotkeys, createKeyHold, createKeyboardLayout, formatForDisplay, useAppHotkeys, useCustomHotkeys, useDefaultHotkeysOptions, useHotkeysContext };
18
+ export { CreateAppHotkeyOptions, CreateHotkeyChordOptions, CreateHotkeyCommonOptions, CreateHotkeyDefinition, CreateHotkeyOptions, CreateHotkeyOptionsFor, CreateHotkeySequenceOptions, CreateHotkeyTarget, HotkeysProvider, HotkeysProviderOptions, HotkeysProviderProps, SolidHotkeyRecorder, UseCustomHotkeysResult, createAppHotkeyList, createFormatForAria, createFormatForDisplay, createHeldKeyCodes, createHeldKeys, createHotkey, createHotkeyHint, createHotkeyRecorder, createHotkeyRegistrations, createHotkeyScopesState, createHotkeys, createKeyHold, createKeyboardLayout, formatForAria, formatForDisplay, useAppHotkeys, useCustomHotkeys, useDefaultHotkeysOptions, useHotkeysContext };
package/dist/index.js CHANGED
@@ -6,7 +6,9 @@ import { createHotkeyRegistrations } from "./createHotkeyRegistrations.js";
6
6
  import { createHotkeyScopesState } from "./createHotkeyScopesState.js";
7
7
  import { createHotkeyHint } from "./createHotkeyHint.js";
8
8
  import { createFormatForDisplay } from "./createFormatForDisplay.js";
9
+ import { createFormatForAria } from "./createFormatForAria.js";
9
10
  import { formatForDisplay } from "./formatForDisplay.js";
11
+ import { formatForAria } from "./formatForAria.js";
10
12
  import { createKeyboardLayout } from "./createKeyboardLayout.js";
11
13
  import { createAppHotkeyList, useAppHotkeys, useCustomHotkeys } from "./appHotkeys.js";
12
14
  import { createHeldKeys } from "./createHeldKeys.js";
@@ -15,4 +17,4 @@ import { createKeyHold } from "./createKeyHold.js";
15
17
 
16
18
  export * from "@tanstack/hotkeys"
17
19
 
18
- export { HotkeysProvider, createAppHotkeyList, createFormatForDisplay, createHeldKeyCodes, createHeldKeys, createHotkey, createHotkeyHint, createHotkeyRecorder, createHotkeyRegistrations, createHotkeyScopesState, createHotkeys, createKeyHold, createKeyboardLayout, formatForDisplay, useAppHotkeys, useCustomHotkeys, useDefaultHotkeysOptions, useHotkeysContext };
20
+ export { HotkeysProvider, createAppHotkeyList, createFormatForAria, createFormatForDisplay, createHeldKeyCodes, createHeldKeys, createHotkey, createHotkeyHint, createHotkeyRecorder, createHotkeyRegistrations, createHotkeyScopesState, createHotkeys, createKeyHold, createKeyboardLayout, formatForAria, formatForDisplay, useAppHotkeys, useCustomHotkeys, useDefaultHotkeysOptions, useHotkeysContext };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tanstack/solid-hotkeys",
3
- "version": "0.26.3",
3
+ "version": "0.27.0",
4
4
  "description": "SolidJS adapter for TanStack Hotkeys",
5
5
  "author": "Tanner Linsley",
6
6
  "license": "MIT",
@@ -38,7 +38,7 @@
38
38
  "skills"
39
39
  ],
40
40
  "dependencies": {
41
- "@tanstack/hotkeys": "0.36.0"
41
+ "@tanstack/hotkeys": "0.37.0"
42
42
  },
43
43
  "devDependencies": {
44
44
  "@solidjs/testing-library": "^1.0.0-rc.2",
@@ -56,26 +56,27 @@ export function Editor() {
56
56
 
57
57
  ## API
58
58
 
59
- | API | What it's for |
60
- | -------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ |
61
- | `createHotkey(hotkey, callback, options?)` | Register one chord, sequence, or app hotkey for the owning component's lifetime; the hotkey and options can be accessors. |
62
- | `createHotkeys(definitions, commonOptions?)` | Register several hotkeys, or an accessor of a list built from data, in one call. |
63
- | `<HotkeysProvider>` | Set default options, a scope (`exclusive` for dialogs), `enabled`, and app hotkeys for the components inside it. |
64
- | `useHotkeysContext()` | Read the nearest provider's merged defaults and enabled state, or `null` outside a provider. |
65
- | `useDefaultHotkeysOptions()` | Read the default options merged from every provider above. |
66
- | `createFormatForDisplay()` | 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 = createFormatForDisplay()` in the component, then `formatForDisplay(hotkey)`. |
67
- | `useAppHotkeys()` | Get an accessor of the declared app hotkeys with the user's custom hotkeys applied. |
68
- | `createAppHotkeyList()` | Get an accessor listing every app hotkey with its status, for a cheat sheet or settings screen. |
69
- | `useCustomHotkeys()` | Read, change, and reset the user's custom hotkeys, and check a new one for conflicts. |
70
- | `createHotkeyRecorder(options)` | Record a chord or sequence the user presses; its state fields are accessors. |
71
- | `createHotkeyRegistrations()` | Get an accessor listing every registered hotkey with its options, `meta`, and `status` (whether it's enabled and in an active scope). |
72
- | `createHotkeyScopesState()` | Get an accessor of the active scopes and the exclusive scope that owns the keyboard. |
73
- | `createHotkeyHint(hotkey, options?)` | Get an accessor of whether held modifiers should reveal a shortcut's hint. False unless a registration of the hotkey can fire: enabled, in an active scope, and with focus inside its element target. |
74
- | `createKeyHold(key)` | Get an accessor of whether one key is held. Letters match in any case; other names, such as `Shift`, are case-sensitive. |
75
- | `createHeldKeys()` | Get an accessor of every key that's held right now. |
76
- | `createHeldKeyCodes()` | Get an accessor mapping each held key to its physical `event.code`. |
77
-
78
- The package also re-exports `@tanstack/hotkeys`, such as `matchesKeyboardEvent` and `defineAppHotkeys`. Its plain `formatForDisplay` export is deprecated: use `createFormatForDisplay()` in components. Outside a component, call the plain function and pass `platform`.
59
+ | API | What it's for |
60
+ | -------------------------------------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
61
+ | `createHotkey(hotkey, callback, options?)` | Register one chord, sequence, or app hotkey for the owning component's lifetime; the hotkey and options can be accessors. |
62
+ | `createHotkeys(definitions, commonOptions?)` | Register several hotkeys, or an accessor of a list built from data, in one call. |
63
+ | `<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. |
64
+ | `useHotkeysContext()` | Read the nearest provider's merged defaults and enabled state, or `null` outside a provider. |
65
+ | `useDefaultHotkeysOptions()` | Read the default options merged from every provider above. |
66
+ | `createFormatForDisplay()` | 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 = createFormatForDisplay()` in the component, then `formatForDisplay(hotkey)`. |
67
+ | `createFormatForAria()` | 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. |
68
+ | `useAppHotkeys()` | Get an accessor of the declared app hotkeys with the user's custom hotkeys applied. |
69
+ | `createAppHotkeyList()` | Get an accessor listing every app hotkey with its status, for a cheat sheet or settings screen. |
70
+ | `useCustomHotkeys()` | Read, change, and reset the user's custom hotkeys, and check a new one for conflicts. |
71
+ | `createHotkeyRecorder(options)` | Record a chord or sequence the user presses; its state fields are accessors. |
72
+ | `createHotkeyRegistrations()` | Get an accessor listing every registered hotkey with its options, `meta`, and `status` (whether it's enabled and in an active scope). |
73
+ | `createHotkeyScopesState()` | Get an accessor of the active scopes and the exclusive scope that owns the keyboard. |
74
+ | `createHotkeyHint(hotkey, options?)` | Get an accessor of whether held modifiers should reveal a shortcut's hint. False unless a registration of the hotkey can fire: enabled, in an active scope, and with focus inside its element target. |
75
+ | `createKeyHold(key)` | Get an accessor of whether one key is held. Letters match in any case; other names, such as `Shift`, are case-sensitive. |
76
+ | `createHeldKeys()` | Get an accessor of every key that's held right now. |
77
+ | `createHeldKeyCodes()` | Get an accessor mapping each held key to its physical `event.code`. |
78
+
79
+ The package also re-exports `@tanstack/hotkeys`, such as `matchesKeyboardEvent` and `defineAppHotkeys`. Its plain `formatForDisplay` export is deprecated: use `createFormatForDisplay()` in components. Outside a component, call the plain function and pass `platform`. The plain `formatForAria` export is deprecated the same way, in favor of `createFormatForAria()`.
79
80
 
80
81
  The state these return is accessors, including the recorder's fields. No provider is required.
81
82