@tanstack/svelte-hotkeys 0.22.1 → 0.24.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.
@@ -9,6 +9,14 @@ export interface HotkeysProviderOptions {
9
9
  * from the request with `detectPlatform(userAgent)`.
10
10
  */
11
11
  platform?: HotkeyPlatform;
12
+ /**
13
+ * Whether labels from `getFormatForDisplay` follow the user's keyboard
14
+ * layout, so `[KeyQ]` reads `A` on a French AZERTY keyboard. The layout
15
+ * loads from the browser when the first label mounts. Only Chromium
16
+ * browsers report one. Set `false` to never ask the browser for it.
17
+ * Default: `true`.
18
+ */
19
+ keyboardLayout?: boolean;
12
20
  /**
13
21
  * Defaults for every hotkey registered by `createHotkey` and `createHotkeys`.
14
22
  * `requireReset` applies to chords and `timeout` applies to sequences.
@@ -26,6 +26,7 @@ export interface SvelteHotkeyRecorder<THotkey extends Hotkey = Hotkey> {
26
26
  * @example
27
27
  * ```svelte
28
28
  * <script lang="ts">
29
+ * const formatForDisplay = getFormatForDisplay()
29
30
  * const recorder = createHotkeyRecorder({ onRecord: (hotkey) => (shortcut = hotkey) })
30
31
  * const sequenceRecorder = createHotkeyRecorder({ maxSteps: Infinity, onRecord: save })
31
32
  * </script>
@@ -0,0 +1,11 @@
1
+ import { formatForDisplay as coreFormatForDisplay } from '@tanstack/hotkeys';
2
+ /**
3
+ * Formats a hotkey as a label, without the provider's platform or the user's
4
+ * keyboard layout.
5
+ *
6
+ * @deprecated Use `getFormatForDisplay()` 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
+ export declare const formatForDisplay: typeof coreFormatForDisplay;
@@ -0,0 +1,11 @@
1
+ import { formatForDisplay as coreFormatForDisplay } from '@tanstack/hotkeys';
2
+ /**
3
+ * Formats a hotkey as a label, without the provider's platform or the user's
4
+ * keyboard layout.
5
+ *
6
+ * @deprecated Use `getFormatForDisplay()` 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
+ export const formatForDisplay = coreFormatForDisplay;
@@ -1,4 +1,4 @@
1
- import type { AppHotkey, AppHotkeyListItem, CustomHotkeys, Hotkey, RegisteredAppHotkeys } from '@tanstack/hotkeys';
1
+ import type { AppHotkey, AppHotkeyListItem, CustomHotkeys, Hotkey, RecordedKeyPresses, RegisteredAppHotkeys } from '@tanstack/hotkeys';
2
2
  export interface SvelteAppHotkeys {
3
3
  /** Effective app hotkeys: each declaration with the user's custom hotkey applied. */
4
4
  readonly current: RegisteredAppHotkeys;
@@ -31,15 +31,20 @@ export interface SvelteCustomHotkeys {
31
31
  readonly current: CustomHotkeys;
32
32
  /**
33
33
  * Sets the user's hotkey for an app hotkey. `null` unbinds it.
34
- * Returns conflicting app hotkeys; when any exist, nothing changes.
34
+ * Returns conflicting app hotkeys; when any exist, nothing changes. Pass
35
+ * the recorder's `context` for a recorded hotkey, as for `findConflicts`.
35
36
  */
36
- setCustomHotkey: (id: keyof RegisteredAppHotkeys & string, hotkey: Hotkey | null) => Array<AppHotkey>;
37
+ setCustomHotkey: (id: keyof RegisteredAppHotkeys & string, hotkey: Hotkey | null, recordedWith?: RecordedKeyPresses) => Array<AppHotkey>;
37
38
  /** Restores the default hotkey for an app hotkey. */
38
39
  resetCustomHotkey: (id: keyof RegisteredAppHotkeys & string) => void;
39
40
  /** Restores every default hotkey. */
40
41
  resetCustomHotkeys: () => void;
41
- /** Other app hotkeys that would collide if `id` used `hotkey`. */
42
- findConflicts: (id: keyof RegisteredAppHotkeys & string, hotkey: Hotkey) => Array<AppHotkey>;
42
+ /**
43
+ * Other app hotkeys that would collide if `id` used `hotkey`. Pass the
44
+ * recorder's `context` for a recorded hotkey: it has the key press, which
45
+ * also finds a hotkey written differently that the same press fires.
46
+ */
47
+ findConflicts: (id: keyof RegisteredAppHotkeys & string, hotkey: Hotkey, recordedWith?: RecordedKeyPresses) => Array<AppHotkey>;
43
48
  }
44
49
  /**
45
50
  * Reads and changes the user's custom hotkeys. Changes apply to every
@@ -63,9 +63,9 @@ export function getCustomHotkeys() {
63
63
  subscribe();
64
64
  return store().customHotkeys;
65
65
  },
66
- setCustomHotkey: (id, hotkey) => store().setCustomHotkey(id, hotkey),
66
+ setCustomHotkey: (id, hotkey, recordedWith) => store().setCustomHotkey(id, hotkey, recordedWith),
67
67
  resetCustomHotkey: (id) => store().resetCustomHotkey(id),
68
68
  resetCustomHotkeys: () => store().resetCustomHotkeys(),
69
- findConflicts: (id, hotkey) => store().findConflicts(id, hotkey),
69
+ findConflicts: (id, hotkey, recordedWith) => store().findConflicts(id, hotkey, recordedWith),
70
70
  };
71
71
  }
@@ -5,16 +5,22 @@ import { formatForDisplay } from '@tanstack/hotkeys';
5
5
  * like `getContext`; the returned function works anywhere and reads the
6
6
  * provider's current defaults. An explicit `platform` option wins.
7
7
  *
8
+ * Physical bindings such as `[KeyQ]` are labeled with the character the key
9
+ * types for this user in Chromium browsers, once the keyboard layout has
10
+ * loaded, and markup updates when it arrives. See `getKeyboardLayout`. A
11
+ * `layoutMap` passed to the returned function wins. Firefox and Safari report
12
+ * no layout, so labels there keep the key's US character.
13
+ *
8
14
  * Server-rendered apps should set the provider's `defaultOptions.platform`
9
15
  * from the request user agent with `detectPlatform(userAgent)`.
10
16
  *
11
17
  * @example
12
18
  * ```svelte
13
19
  * <script lang="ts">
14
- * const format = getFormatForDisplay()
20
+ * const formatForDisplay = getFormatForDisplay()
15
21
  * </script>
16
22
  *
17
- * <kbd>{format('Mod+S')}</kbd>
23
+ * <kbd>{formatForDisplay('Mod+S')}</kbd>
18
24
  * ```
19
25
  */
20
26
  export declare function getFormatForDisplay(): typeof formatForDisplay;
@@ -1,27 +1,40 @@
1
1
  import { formatForDisplay } from '@tanstack/hotkeys';
2
+ import { namesPhysicalKey } from '@tanstack/hotkeys/adapter';
2
3
  import { getHotkeysContext } from './HotkeysCtx.js';
4
+ import { getKeyboardLayout } from './getKeyboardLayout.svelte.js';
3
5
  /**
4
6
  * Returns `formatForDisplay` with the provider's `platform` as the default,
5
7
  * so labels match the user's platform. Call during component initialization,
6
8
  * like `getContext`; the returned function works anywhere and reads the
7
9
  * provider's current defaults. An explicit `platform` option wins.
8
10
  *
11
+ * Physical bindings such as `[KeyQ]` are labeled with the character the key
12
+ * types for this user in Chromium browsers, once the keyboard layout has
13
+ * loaded, and markup updates when it arrives. See `getKeyboardLayout`. A
14
+ * `layoutMap` passed to the returned function wins. Firefox and Safari report
15
+ * no layout, so labels there keep the key's US character.
16
+ *
9
17
  * Server-rendered apps should set the provider's `defaultOptions.platform`
10
18
  * from the request user agent with `detectPlatform(userAgent)`.
11
19
  *
12
20
  * @example
13
21
  * ```svelte
14
22
  * <script lang="ts">
15
- * const format = getFormatForDisplay()
23
+ * const formatForDisplay = getFormatForDisplay()
16
24
  * </script>
17
25
  *
18
- * <kbd>{format('Mod+S')}</kbd>
26
+ * <kbd>{formatForDisplay('Mod+S')}</kbd>
19
27
  * ```
20
28
  */
21
29
  export function getFormatForDisplay() {
22
30
  const context = getHotkeysContext();
31
+ const keyboard = getKeyboardLayout();
23
32
  return ((hotkey, options) => formatForDisplay(hotkey, {
24
33
  ...options,
25
34
  platform: options?.platform ?? context?.defaultOptions.platform,
35
+ // Only a position's label follows the layout. Other labels don't read
36
+ // it, so they don't render again when it loads.
37
+ layoutMap: options?.layoutMap ??
38
+ (namesPhysicalKey(hotkey) ? (keyboard.layout ?? undefined) : undefined),
26
39
  }));
27
40
  }
@@ -12,6 +12,7 @@ export interface SvelteHotkeyRegistrations {
12
12
  * @example
13
13
  * ```svelte
14
14
  * <script lang="ts">
15
+ * const formatForDisplay = getFormatForDisplay()
15
16
  * const registrations = getHotkeyRegistrations()
16
17
  * </script>
17
18
  *
@@ -17,6 +17,7 @@ class HotkeyRegistrationsState {
17
17
  * @example
18
18
  * ```svelte
19
19
  * <script lang="ts">
20
+ * const formatForDisplay = getFormatForDisplay()
20
21
  * const registrations = getHotkeyRegistrations()
21
22
  * </script>
22
23
  *
@@ -0,0 +1,34 @@
1
+ import type { KeyboardLayoutMap } from '@tanstack/hotkeys';
2
+ export interface SvelteKeyboardLayout {
3
+ readonly layout: KeyboardLayoutMap | null;
4
+ }
5
+ /**
6
+ * Svelte function that returns reactive access to the browser's keyboard
7
+ * layout. `layout` is `null` until the layout loads and in browsers that
8
+ * don't report one. The layout maps each physical code to the character it
9
+ * types, such as `KeyQ` to `a` on a French AZERTY keyboard. Only Chromium
10
+ * browsers report one.
11
+ *
12
+ * The layout loads after the first component that uses this function mounts,
13
+ * so server-rendered output hydrates unchanged. `getFormatForDisplay` uses
14
+ * this function, so you only need it for labels you draw yourself.
15
+ *
16
+ * To never ask the browser for the layout, set `keyboardLayout: false` in
17
+ * `HotkeysProvider`'s `defaultOptions`. `layout` then stays `null`.
18
+ *
19
+ * @returns Object with a reactive `layout` property
20
+ *
21
+ * @example
22
+ * ```svelte
23
+ * <script lang="ts">
24
+ * import { getKeyboardLayout } from '@tanstack/svelte-hotkeys'
25
+ *
26
+ * const keyboard = getKeyboardLayout()
27
+ * const label = (code: string) =>
28
+ * (keyboard.layout?.get(code) ?? code).toUpperCase()
29
+ * </script>
30
+ *
31
+ * <kbd>{label('KeyW')}</kbd>
32
+ * ```
33
+ */
34
+ export declare function getKeyboardLayout(): SvelteKeyboardLayout;
@@ -0,0 +1,76 @@
1
+ import { getKeyboardLayoutStore, loadKeyboardLayout } from '@tanstack/hotkeys';
2
+ import { createSubscriber } from 'svelte/reactivity';
3
+ import { getHotkeysContext } from './HotkeysCtx.js';
4
+ class KeyboardLayoutState {
5
+ #context = getHotkeysContext();
6
+ #store = getKeyboardLayoutStore();
7
+ // Loads the layout while an effect or markup reads it. Calls are counted,
8
+ // so every reader can load it.
9
+ #subscribe = createSubscriber((update) => {
10
+ const stop = loadKeyboardLayout();
11
+ const { unsubscribe } = this.#store.subscribe(update);
12
+ return () => {
13
+ unsubscribe();
14
+ stop();
15
+ };
16
+ });
17
+ // Server HTML never has a layout, so a component that hydrates starts
18
+ // without one, even when the layout has already loaded.
19
+ #mounted = $state(false);
20
+ constructor() {
21
+ try {
22
+ // Effects run after the component mounts, and never on a server.
23
+ $effect(() => {
24
+ this.#mounted = true;
25
+ });
26
+ // Loads the layout even when nothing else reads it reactively.
27
+ $effect(() => {
28
+ void this.layout;
29
+ });
30
+ }
31
+ catch {
32
+ // Outside a component there is no hydration to wait for.
33
+ this.#mounted = true;
34
+ }
35
+ }
36
+ get layout() {
37
+ if (!this.#mounted)
38
+ return null;
39
+ if (this.#context?.defaultOptions.keyboardLayout === false)
40
+ return null;
41
+ this.#subscribe();
42
+ return this.#store.state;
43
+ }
44
+ }
45
+ /**
46
+ * Svelte function that returns reactive access to the browser's keyboard
47
+ * layout. `layout` is `null` until the layout loads and in browsers that
48
+ * don't report one. The layout maps each physical code to the character it
49
+ * types, such as `KeyQ` to `a` on a French AZERTY keyboard. Only Chromium
50
+ * browsers report one.
51
+ *
52
+ * The layout loads after the first component that uses this function mounts,
53
+ * so server-rendered output hydrates unchanged. `getFormatForDisplay` uses
54
+ * this function, so you only need it for labels you draw yourself.
55
+ *
56
+ * To never ask the browser for the layout, set `keyboardLayout: false` in
57
+ * `HotkeysProvider`'s `defaultOptions`. `layout` then stays `null`.
58
+ *
59
+ * @returns Object with a reactive `layout` property
60
+ *
61
+ * @example
62
+ * ```svelte
63
+ * <script lang="ts">
64
+ * import { getKeyboardLayout } from '@tanstack/svelte-hotkeys'
65
+ *
66
+ * const keyboard = getKeyboardLayout()
67
+ * const label = (code: string) =>
68
+ * (keyboard.layout?.get(code) ?? code).toUpperCase()
69
+ * </script>
70
+ *
71
+ * <kbd>{label('KeyW')}</kbd>
72
+ * ```
73
+ */
74
+ export function getKeyboardLayout() {
75
+ return new KeyboardLayoutState();
76
+ }
package/dist/index.d.ts CHANGED
@@ -13,3 +13,5 @@ export { DEFAULT_OPTIONS, getDefaultHotkeysOptions, getHotkeysContext, setHotkey
13
13
  export type { HotkeysContextOptions, HotkeysProviderOptions, HotkeysProviderProps, } from './HotkeysCtx.js';
14
14
  export * from './getHotkeyHint.svelte.js';
15
15
  export * from './getFormatForDisplay.js';
16
+ export { formatForDisplay } from './formatForDisplay.js';
17
+ export * from './getKeyboardLayout.svelte.js';
package/dist/index.js CHANGED
@@ -13,3 +13,6 @@ export { default as HotkeysProvider } from './HotkeysProvider.svelte';
13
13
  export { DEFAULT_OPTIONS, getDefaultHotkeysOptions, getHotkeysContext, setHotkeysContext, } from './HotkeysCtx.js';
14
14
  export * from './getHotkeyHint.svelte.js';
15
15
  export * from './getFormatForDisplay.js';
16
+ // Replaces the core export, to point components to `getFormatForDisplay`
17
+ export { formatForDisplay } from './formatForDisplay.js';
18
+ export * from './getKeyboardLayout.svelte.js';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tanstack/svelte-hotkeys",
3
- "version": "0.22.1",
3
+ "version": "0.24.0",
4
4
  "description": "Svelte adapter for TanStack Hotkeys",
5
5
  "author": "Kunal Rao",
6
6
  "license": "MIT",
@@ -41,7 +41,7 @@
41
41
  "skills"
42
42
  ],
43
43
  "dependencies": {
44
- "@tanstack/hotkeys": "0.27.1"
44
+ "@tanstack/hotkeys": "0.29.0"
45
45
  },
46
46
  "devDependencies": {
47
47
  "@sveltejs/package": "^3.0.2",
@@ -49,7 +49,7 @@
49
49
  "@tanstack/hotkeys-test-utils": "0.0.0",
50
50
  "@typescript-eslint/parser": "^8.72.1",
51
51
  "eslint": "^10.14.0",
52
- "eslint-plugin-svelte": "^3.24.0",
52
+ "eslint-plugin-svelte": "^3.24.1",
53
53
  "svelte": "^5.57.3"
54
54
  },
55
55
  "peerDependencies": {
@@ -55,29 +55,29 @@ Before starting, load the `@tanstack/hotkeys#hotkeys-core` skill (`npx @tanstack
55
55
 
56
56
  ## API
57
57
 
58
- | API | What it's for |
59
- | ------------------------------------------------------ | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
60
- | `createHotkey(hotkey, callback, options?)` | Register one chord, sequence, or app hotkey on the document while the component is mounted; pass getters for values that change. |
61
- | `createHotkeys(definitions, commonOptions?)` | Register several hotkeys on the document, or a getter of a list built from data. |
62
- | `createHotkeyAttachment(hotkey, callback, options?)` | Create an attachment for `{@attach}` that listens on one element. |
63
- | `createHotkeysAttachment(definitions, commonOptions?)` | Create an attachment that registers several hotkeys on one element. |
64
- | `<HotkeysProvider>` | Set default options, a scope (`exclusive` for dialogs), `enabled`, and app hotkeys for the components inside it. |
65
- | `setHotkeysContext(options)` | Set the same options from a component's script instead of rendering `HotkeysProvider`; they apply to that component too. |
66
- | `getHotkeysContext()` | Read the nearest context's merged defaults and enabled state, or `null` outside one. |
67
- | `getDefaultHotkeysOptions()` | Read the default options merged from every context above. |
68
- | `getFormatForDisplay()` | Get `formatForDisplay` with the provider's `platform` filled in, for labels in server-rendered apps. Call it during component initialization. |
69
- | `getAppHotkeys()` | Read `.current`, the declared app hotkeys with the user's custom hotkeys applied. |
70
- | `getAppHotkeyList()` | Read `.current`, every app hotkey with its status, for a cheat sheet or settings screen. |
71
- | `getCustomHotkeys()` | Read the user's custom hotkeys from `.current`, change or reset them, and check a new one for conflicts. |
72
- | `createHotkeyRecorder(options)` | Record a chord or sequence the user presses, for a settings screen. |
73
- | `getHotkeyRegistrations()` | Read `.hotkeys`, every registered hotkey with its options, `meta`, and `status` (whether it's enabled and in an active scope). |
74
- | `getHotkeyScopesState()` | Read `.state`, the active scopes and the exclusive scope that owns the keyboard. |
75
- | `getHotkeyHint(hotkey, options?)` | Read `.visible`, 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. |
76
- | `getIsKeyHeld(key)` | Read `.held`, whether one key is held. Letters match in any case; other names, such as `Shift`, are case-sensitive. |
77
- | `getHeldKeys()` | Read `.keys`, every key that's held right now. |
78
- | `getHeldKeyCodesMap()` | Read `.codes`, which maps each held key to its physical `event.code`. |
58
+ | API | What it's for |
59
+ | ------------------------------------------------------ | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ |
60
+ | `createHotkey(hotkey, callback, options?)` | Register one chord, sequence, or app hotkey on the document while the component is mounted; pass getters for values that change. |
61
+ | `createHotkeys(definitions, commonOptions?)` | Register several hotkeys on the document, or a getter of a list built from data. |
62
+ | `createHotkeyAttachment(hotkey, callback, options?)` | Create an attachment for `{@attach}` that listens on one element. |
63
+ | `createHotkeysAttachment(definitions, commonOptions?)` | Create an attachment that registers several hotkeys on one element. |
64
+ | `<HotkeysProvider>` | Set default options, a scope (`exclusive` for dialogs), `enabled`, and app hotkeys for the components inside it. |
65
+ | `setHotkeysContext(options)` | Set the same options from a component's script instead of rendering `HotkeysProvider`; they apply to that component too. |
66
+ | `getHotkeysContext()` | Read the nearest context's merged defaults and enabled state, or `null` outside one. |
67
+ | `getDefaultHotkeysOptions()` | Read the default options merged from every context above. |
68
+ | `getFormatForDisplay()` | 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 = getFormatForDisplay()` during component initialization, then `formatForDisplay(hotkey)`. |
69
+ | `getAppHotkeys()` | Read `.current`, the declared app hotkeys with the user's custom hotkeys applied. |
70
+ | `getAppHotkeyList()` | Read `.current`, every app hotkey with its status, for a cheat sheet or settings screen. |
71
+ | `getCustomHotkeys()` | Read the user's custom hotkeys from `.current`, change or reset them, and check a new one for conflicts. |
72
+ | `createHotkeyRecorder(options)` | Record a chord or sequence the user presses, for a settings screen. |
73
+ | `getHotkeyRegistrations()` | Read `.hotkeys`, every registered hotkey with its options, `meta`, and `status` (whether it's enabled and in an active scope). |
74
+ | `getHotkeyScopesState()` | Read `.state`, the active scopes and the exclusive scope that owns the keyboard. |
75
+ | `getHotkeyHint(hotkey, options?)` | Read `.visible`, 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. |
76
+ | `getIsKeyHeld(key)` | Read `.held`, whether one key is held. Letters match in any case; other names, such as `Shift`, are case-sensitive. |
77
+ | `getHeldKeys()` | Read `.keys`, every key that's held right now. |
78
+ | `getHeldKeyCodesMap()` | Read `.codes`, which maps each held key to its physical `event.code`. |
79
79
 
80
- The package also re-exports `@tanstack/hotkeys`, such as `formatForDisplay`, `matchesKeyboardEvent`, and `defineAppHotkeys`.
80
+ The package also re-exports `@tanstack/hotkeys`, such as `matchesKeyboardEvent` and `defineAppHotkeys`. Its plain `formatForDisplay` export is deprecated: use `getFormatForDisplay()` in components. Outside a component, call the plain function and pass `platform`.
81
81
 
82
82
  No provider is required. Call these at the top level of a component's `<script>`.
83
83
 
@@ -89,7 +89,7 @@ No provider is required. Call these at the top level of a component's `<script>`
89
89
  - **Call `setHotkeysContext` before creating the component's hotkeys.** It applies to the component itself, so a hotkey created first lands in the outer scope, which an exclusive context then suspends. It reads its options once; for `enabled` or `exclusive` that change, wrap the component in `<HotkeysProvider>`. Give each open dialog its own scope name.
90
90
  - **The callback isn't tracked.** Read state and props inside it.
91
91
  - **Call the functions directly.** A `createShortcut(keys: string)` wrapper has to cast strings to hotkeys, which turns off type checking and drops sequences, getter options, and app hotkeys.
92
- - **Server-rendered labels need the user's platform.** On the server, `formatForDisplay` can't see the user's OS, so it renders Linux labels that differ after hydration for Mac and Windows users. Set the provider's `defaultOptions.platform` to `detectPlatform(userAgent)` from the request's `User-Agent` header, and format labels with `const format = getFormatForDisplay()` during component initialization, then `format(hotkey)`. Keep plain `formatForDisplay` for labels that render only in the browser, when no provider sets `platform`.
92
+ - **Server-rendered labels need the user's platform.** The server can't see the user's OS, so without a platform it renders Linux labels that differ after hydration for Mac and Windows users. Set the provider's `defaultOptions.platform` to `detectPlatform(userAgent)` from the request's `User-Agent` header. `getFormatForDisplay()` reads it.
93
93
 
94
94
  When declaring app hotkeys, building a cheat sheet, or letting users rebind shortcuts, load `@tanstack/hotkeys#app-hotkeys` and read [app hotkeys in Svelte](references/app-hotkeys.md).
95
95
 
@@ -49,24 +49,25 @@ A settings row records with `createHotkeyRecorder` and saves through `getCustomH
49
49
  <script lang="ts">
50
50
  import {
51
51
  createHotkeyRecorder,
52
- formatForDisplay,
53
52
  getAppHotkeys,
54
53
  getCustomHotkeys,
54
+ getFormatForDisplay,
55
55
  } from '@tanstack/svelte-hotkeys'
56
56
  import type { AppHotkeyId } from '@tanstack/svelte-hotkeys'
57
57
 
58
58
  let { id }: { id: AppHotkeyId } = $props()
59
+ const formatForDisplay = getFormatForDisplay()
59
60
  const appHotkeys = getAppHotkeys()
60
61
  const custom = getCustomHotkeys()
61
62
  const appHotkey = $derived(appHotkeys.current[id])
62
63
 
63
64
  const recorder = createHotkeyRecorder(() => ({
64
65
  maxSteps: Infinity,
65
- validate: (hotkey) => {
66
- const [conflict] = custom.findConflicts(id, hotkey)
66
+ validate: (hotkey, context) => {
67
+ const [conflict] = custom.findConflicts(id, hotkey, context)
67
68
  return conflict ? `Used by ${conflict.meta?.name ?? conflict.id}` : true
68
69
  },
69
- onRecord: (hotkey) => custom.setCustomHotkey(id, hotkey),
70
+ onRecord: (hotkey, context) => custom.setCustomHotkey(id, hotkey, context),
70
71
  onClear: () => custom.setCustomHotkey(id, null),
71
72
  }))
72
73
  </script>