Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/nested-app-hotkeys.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@tanstack/hotkeys': patch
---

App hotkeys spread from one `defineAppHotkeys` call into another keep the kind of their default hotkey, so adapters accept `timeout` or `requireReset` for them, and an entry that replaces a spread-in `hotkey` or `options` is checked like any other declaration. A large app can declare its hotkeys in several files and combine them with full types.
451 changes: 259 additions & 192 deletions .intent/review-state.json

Large diffs are not rendered by default.

7 changes: 7 additions & 0 deletions _artifacts/domain_map.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -224,6 +224,13 @@ skills:
skills:
- app-hotkeys
- hotkeys-core
- mistake: Splitting declarations with satisfies instead of nested defineAppHotkeys
mechanism: '`as const satisfies Record<string, AppHotkeyInput>` checks hotkey strings but not kind-specific options, so a `timeout` on a chord fails only at the final defineAppHotkeys call, far from the file that declares it.'
wrong_pattern: "export const editorHotkeys = { 'editor.format': { hotkey: 'Mod+Shift+F' } } as const satisfies Record<string, AppHotkeyInput>"
correct_pattern: "export const editorHotkeys = defineAppHotkeys({ 'editor.format': { hotkey: 'Mod+Shift+F' } }); defineAppHotkeys({ ...editorHotkeys })"
source: src/app-hotkeys.ts (DefinedAppHotkeys); docs/framework/react/guides/app-hotkeys.md#split-declarations-across-files
priority: MEDIUM
status: active
- mistake: Declaring a copy of a shared hotkey per page
mechanism: One app hotkey per page splits the user's custom binding and settings row for what is one shortcut.
wrong_pattern: "defineAppHotkeys({ 'tables.search': { hotkey: 'Shift+F' }, 'roles.search': { hotkey: 'Shift+F' } })"
Expand Down
9 changes: 8 additions & 1 deletion _artifacts/skill_spec.md
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ The skills teach agents to use those APIs directly. The core skills hold the fra
| 12 | A second copy of @tanstack/hotkeys | MEDIUM | src/_manager-ref.ts | — |
| 13 | Testing without a fixed platform | MEDIUM | src/platform.ts, runtime probe | — |

### app-hotkeys (10 failure modes)
### app-hotkeys (11 failure modes)

| # | Mistake | Priority | Source | Cross-skill? |
| --- | ------------------------------------------------ | -------- | ---------------------------------- | -------------------- |
Expand All @@ -63,6 +63,7 @@ The skills teach agents to use those APIs directly. The core skills hold the fra
| 8 | Rewriting recorded physical bindings | MEDIUM | sensible-defaults.md | — |
| 9 | A palette that keeps its own action map | HIGH | src/hotkey-manager.ts (trigger) | hotkeys-core |
| 10 | Declaring a copy of a shared hotkey per page | MEDIUM | src/adapter.ts (call-site meta) | — |
| 11 | Splitting declarations with `satisfies` | MEDIUM | src/app-hotkeys.ts (nested define) | — |

### Framework skills

Expand Down Expand Up @@ -217,3 +218,9 @@ The skills teach agents to use those APIs directly. The core skills hold the fra
- **Source:** branch `feat/hotkey-trigger` from `7cf53a0c`. Registration views, registration handles, and `HotkeyManager` gain `trigger()`, which runs the registered callback without a key press with the key press's context, a synthetic event for the hotkey when none is passed, and only `enabled` checked. The devtools Trigger button uses it. App hotkey registrations accept call-site `meta`, merged over the declared meta for that registration only. `enabled` accepts a getter, read on each key press, on `trigger()`, and when views report `status`.
- **Changes:** `app-hotkeys` gains two pitfalls: a command palette runs registrations with `view.trigger()` instead of keeping its own action map, and a shared hotkey gets a page-specific name with call-site `meta` instead of a copy per page. `hotkeys-core` gains a table row for a palette that copies each shortcut's action. `references/scopes.md` describes `'disabled'` for getters. `domain_map.yaml` records both failure modes. Framework skills are unchanged: none claims `meta` comes only from the declaration, and Vue already resolves a getter `enabled` as a reactive source. `skill_tree.yaml` is unchanged.
- **Checks:** `packages/hotkeys/tests/trigger.test.ts` covers `trigger()`, getters, and the meta merge; React and Preact app hotkey tests cover call-site meta through an adapter. `intent validate` passes. Not run: fresh-consumer sessions.

### Source sync — 2026-11-29 — app hotkeys split across files

- **Source:** branch `feat/nested-app-hotkeys` from `00217cf3`. `defineAppHotkeys` accepts the app hotkeys of another `defineAppHotkeys` call. Spread-in entries keep their id and the kind of their default, and skip the option check that their own call already ran. An entry that replaces a spread-in `hotkey` or `options` is checked like any other declaration. Types only; no runtime change.
- **Changes:** `app-hotkeys` gains a pitfall: split a large catalog with nested `defineAppHotkeys` calls instead of `as const satisfies Record<string, AppHotkeyInput>`, which defers the kind-specific option check to the final call. Every framework's `app-hotkeys.md` guide gains a "Split declarations across files" section. `domain_map.yaml` records the failure mode. Framework skills and `skill_tree.yaml` are unchanged: no framework skill shows split declarations.
- **Checks:** `packages/hotkeys/tests/app-hotkeys.test.ts` covers spread-in types, a renamed entry, and option errors beside spread-in entries; `app-hotkeys-type-performance.test.ts` spreads 100 entries. `intent validate` passes. Not run: fresh-consumer sessions.
26 changes: 26 additions & 0 deletions docs/framework/alpine/guides/app-hotkeys.md
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,32 @@ declare module '@tanstack/alpine-hotkeys' {

The `Register` augmentation types `createAppHotkeys()`, the ids accepted by `createCustomHotkeys()`, and the `CustomHotkeys` type.

### Split declarations across files

A large app can declare its hotkeys next to the features that own them. Call `defineAppHotkeys` in each file, then spread the results into the one object you register:

```ts
// features/editor/hotkeys.ts
import { defineAppHotkeys } from '@tanstack/alpine-hotkeys'

export const editorHotkeys = defineAppHotkeys({
'editor.format': { hotkey: 'Mod+Shift+F', meta: { name: 'Format document' } },
})
```

```ts
// app-hotkeys.ts
import { defineAppHotkeys } from '@tanstack/alpine-hotkeys'
import { editorHotkeys } from './features/editor/hotkeys'

export const appHotkeys = defineAppHotkeys({
...editorHotkeys,
'palette.open': { hotkey: null, meta: { name: 'Command palette' } },
})
```

Each file's call checks its own declarations, so a mismatched option is a type error in that file. Spread-in entries keep their id and the kind of their default. Register and provide only the combined object, since a file's own object lists only that file's hotkeys. A later spread replaces an entry with the same id without an error, so keep ids unique across files.

## Provide app hotkeys

Publish the declarations with `provideAppHotkeys` before Alpine starts:
Expand Down
26 changes: 26 additions & 0 deletions docs/framework/angular/guides/app-hotkeys.md
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,32 @@ declare module '@tanstack/angular-hotkeys' {

The `Register` module augmentation enables autocomplete and type checking for `injectAppHotkeys()`, `injectCustomHotkeys()`, and `CustomHotkeys`.

### Split declarations across files

A large app can declare its hotkeys next to the features that own them. Call `defineAppHotkeys` in each file, then spread the results into the one object you register:

```ts
// features/editor/hotkeys.ts
import { defineAppHotkeys } from '@tanstack/angular-hotkeys'

export const editorHotkeys = defineAppHotkeys({
'editor.format': { hotkey: 'Mod+Shift+F', meta: { name: 'Format document' } },
})
```

```ts
// app-hotkeys.ts
import { defineAppHotkeys } from '@tanstack/angular-hotkeys'
import { editorHotkeys } from './features/editor/hotkeys'

export const appHotkeys = defineAppHotkeys({
...editorHotkeys,
'palette.open': { hotkey: null, meta: { name: 'Command palette' } },
})
```

Each file's call checks its own declarations, so a mismatched option is a type error in that file. Spread-in entries keep their id and the kind of their default. Register and provide only the combined object, since a file's own object lists only that file's hotkeys. A later spread replaces an entry with the same id without an error, so keep ids unique across files.

## Provide app hotkeys

Pass the declarations to `provideHotkeys` in your application config. See [Provide app hotkeys](./provide-hotkeys-and-scopes#provide-app-hotkeys):
Expand Down
26 changes: 26 additions & 0 deletions docs/framework/ember/guides/app-hotkeys.md
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,32 @@ declare module '@tanstack/ember-hotkeys' {

The `Register` augmentation types `useAppHotkeys()`, the ids accepted by `useCustomHotkeys()`, and the `CustomHotkeys` type.

### Split declarations across files

A large app can declare its hotkeys next to the features that own them. Call `defineAppHotkeys` in each file, then spread the results into the one object you register:

```ts
// features/editor/hotkeys.ts
import { defineAppHotkeys } from '@tanstack/ember-hotkeys'

export const editorHotkeys = defineAppHotkeys({
'editor.format': { hotkey: 'Mod+Shift+F', meta: { name: 'Format document' } },
})
```

```ts
// app-hotkeys.ts
import { defineAppHotkeys } from '@tanstack/ember-hotkeys'
import { editorHotkeys } from './features/editor/hotkeys'

export const appHotkeys = defineAppHotkeys({
...editorHotkeys,
'palette.open': { hotkey: null, meta: { name: 'Command palette' } },
})
```

Each file's call checks its own declarations, so a mismatched option is a type error in that file. Spread-in entries keep their id and the kind of their default. Register and provide only the combined object, since a file's own object lists only that file's hotkeys. A later spread replaces an entry with the same id without an error, so keep ids unique across files.

## Provide app hotkeys

Publish the declarations with `provideAppHotkeys` before the application boots:
Expand Down
26 changes: 26 additions & 0 deletions docs/framework/lit/guides/app-hotkeys.md
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,32 @@ declare module '@tanstack/lit-hotkeys' {

The `Register` augmentation types `AppHotkeysController`, the ids it accepts when changing custom hotkeys, and the `CustomHotkeys` type.

### Split declarations across files

A large app can declare its hotkeys next to the features that own them. Call `defineAppHotkeys` in each file, then spread the results into the one object you register:

```ts
// features/editor/hotkeys.ts
import { defineAppHotkeys } from '@tanstack/lit-hotkeys'

export const editorHotkeys = defineAppHotkeys({
'editor.format': { hotkey: 'Mod+Shift+F', meta: { name: 'Format document' } },
})
```

```ts
// app-hotkeys.ts
import { defineAppHotkeys } from '@tanstack/lit-hotkeys'
import { editorHotkeys } from './features/editor/hotkeys'

export const appHotkeys = defineAppHotkeys({
...editorHotkeys,
'palette.open': { hotkey: null, meta: { name: 'Command palette' } },
})
```

Each file's call checks its own declarations, so a mismatched option is a type error in that file. Spread-in entries keep their id and the kind of their default. Register and provide only the combined object, since a file's own object lists only that file's hotkeys. A later spread replaces an entry with the same id without an error, so keep ids unique across files.

## Provide app hotkeys

Publish the declarations with `provideAppHotkeys` before your elements render:
Expand Down
26 changes: 26 additions & 0 deletions docs/framework/octane/guides/app-hotkeys.md
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,32 @@ declare module '@tanstack/octane-hotkeys' {

The `Register` module augmentation enables autocomplete and type checking for `useAppHotkeys()`, `useCustomHotkeys()`, and `CustomHotkeys`.

### Split declarations across files

A large app can declare its hotkeys next to the features that own them. Call `defineAppHotkeys` in each file, then spread the results into the one object you register:

```ts
// features/editor/hotkeys.ts
import { defineAppHotkeys } from '@tanstack/octane-hotkeys'

export const editorHotkeys = defineAppHotkeys({
'editor.format': { hotkey: 'Mod+Shift+F', meta: { name: 'Format document' } },
})
```

```ts
// app-hotkeys.ts
import { defineAppHotkeys } from '@tanstack/octane-hotkeys'
import { editorHotkeys } from './features/editor/hotkeys'

export const appHotkeys = defineAppHotkeys({
...editorHotkeys,
'palette.open': { hotkey: null, meta: { name: 'Command palette' } },
})
```

Each file's call checks its own declarations, so a mismatched option is a type error in that file. Spread-in entries keep their id and the kind of their default. Register and provide only the combined object, since a file's own object lists only that file's hotkeys. A later spread replaces an entry with the same id without an error, so keep ids unique across files.

## Provide app hotkeys

Pass your declarations to the root `HotkeysProvider` (see [Provide app hotkeys](./hotkeys-provider-and-scopes#provide-app-hotkeys)):
Expand Down
26 changes: 26 additions & 0 deletions docs/framework/preact/guides/app-hotkeys.md
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,32 @@ declare module '@tanstack/preact-hotkeys' {

The `Register` module augmentation enables autocomplete and type checking for `useAppHotkeys()`, `useCustomHotkeys()`, and `CustomHotkeys`.

### Split declarations across files

A large app can declare its hotkeys next to the features that own them. Call `defineAppHotkeys` in each file, then spread the results into the one object you register:

```ts
// features/editor/hotkeys.ts
import { defineAppHotkeys } from '@tanstack/preact-hotkeys'

export const editorHotkeys = defineAppHotkeys({
'editor.format': { hotkey: 'Mod+Shift+F', meta: { name: 'Format document' } },
})
```

```ts
// app-hotkeys.ts
import { defineAppHotkeys } from '@tanstack/preact-hotkeys'
import { editorHotkeys } from './features/editor/hotkeys'

export const appHotkeys = defineAppHotkeys({
...editorHotkeys,
'palette.open': { hotkey: null, meta: { name: 'Command palette' } },
})
```

Each file's call checks its own declarations, so a mismatched option is a type error in that file. Spread-in entries keep their id and the kind of their default. Register and provide only the combined object, since a file's own object lists only that file's hotkeys. A later spread replaces an entry with the same id without an error, so keep ids unique across files.

## Provide app hotkeys

Pass your declarations to the root `HotkeysProvider` (see [Provide app hotkeys](./hotkeys-provider-and-scopes#provide-app-hotkeys)):
Expand Down
26 changes: 26 additions & 0 deletions docs/framework/react/guides/app-hotkeys.md
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,32 @@ declare module '@tanstack/react-hotkeys' {

The `Register` module augmentation enables autocomplete and type checking for `useAppHotkeys()`, `useCustomHotkeys()`, and `CustomHotkeys`.

### Split declarations across files

A large app can declare its hotkeys next to the features that own them. Call `defineAppHotkeys` in each file, then spread the results into the one object you register:

```ts
// features/editor/hotkeys.ts
import { defineAppHotkeys } from '@tanstack/react-hotkeys'

export const editorHotkeys = defineAppHotkeys({
'editor.format': { hotkey: 'Mod+Shift+F', meta: { name: 'Format document' } },
})
```

```ts
// app-hotkeys.ts
import { defineAppHotkeys } from '@tanstack/react-hotkeys'
import { editorHotkeys } from './features/editor/hotkeys'

export const appHotkeys = defineAppHotkeys({
...editorHotkeys,
'palette.open': { hotkey: null, meta: { name: 'Command palette' } },
})
```

Each file's call checks its own declarations, so a mismatched option is a type error in that file. Spread-in entries keep their id and the kind of their default. Register and provide only the combined object, since a file's own object lists only that file's hotkeys. A later spread replaces an entry with the same id without an error, so keep ids unique across files.

## Provide app hotkeys

Pass your declarations to the root `HotkeysProvider` (see [Provide app hotkeys](./hotkeys-provider-and-scopes#provide-app-hotkeys)):
Expand Down
26 changes: 26 additions & 0 deletions docs/framework/solid/guides/app-hotkeys.md
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,32 @@ declare module '@tanstack/solid-hotkeys' {

The `Register` module augmentation enables autocomplete and type checking for `useAppHotkeys()`, `useCustomHotkeys()`, and `CustomHotkeys`.

### Split declarations across files

A large app can declare its hotkeys next to the features that own them. Call `defineAppHotkeys` in each file, then spread the results into the one object you register:

```ts
// features/editor/hotkeys.ts
import { defineAppHotkeys } from '@tanstack/solid-hotkeys'

export const editorHotkeys = defineAppHotkeys({
'editor.format': { hotkey: 'Mod+Shift+F', meta: { name: 'Format document' } },
})
```

```ts
// app-hotkeys.ts
import { defineAppHotkeys } from '@tanstack/solid-hotkeys'
import { editorHotkeys } from './features/editor/hotkeys'

export const appHotkeys = defineAppHotkeys({
...editorHotkeys,
'palette.open': { hotkey: null, meta: { name: 'Command palette' } },
})
```

Each file's call checks its own declarations, so a mismatched option is a type error in that file. Spread-in entries keep their id and the kind of their default. Register and provide only the combined object, since a file's own object lists only that file's hotkeys. A later spread replaces an entry with the same id without an error, so keep ids unique across files.

## Provide app hotkeys

Pass your declarations to the root `HotkeysProvider` (see [Provide app hotkeys](./hotkeys-provider-and-scopes#provide-app-hotkeys)):
Expand Down
26 changes: 26 additions & 0 deletions docs/framework/svelte/guides/app-hotkeys.md
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,32 @@ declare module '@tanstack/svelte-hotkeys' {

The `Register` module augmentation enables autocomplete and type checking for `getAppHotkeys()`, `getCustomHotkeys()`, and `CustomHotkeys`.

### Split declarations across files

A large app can declare its hotkeys next to the features that own them. Call `defineAppHotkeys` in each file, then spread the results into the one object you register:

```ts
// features/editor/hotkeys.ts
import { defineAppHotkeys } from '@tanstack/svelte-hotkeys'

export const editorHotkeys = defineAppHotkeys({
'editor.format': { hotkey: 'Mod+Shift+F', meta: { name: 'Format document' } },
})
```

```ts
// app-hotkeys.ts
import { defineAppHotkeys } from '@tanstack/svelte-hotkeys'
import { editorHotkeys } from './features/editor/hotkeys'

export const appHotkeys = defineAppHotkeys({
...editorHotkeys,
'palette.open': { hotkey: null, meta: { name: 'Command palette' } },
})
```

Each file's call checks its own declarations, so a mismatched option is a type error in that file. Spread-in entries keep their id and the kind of their default. Register and provide only the combined object, since a file's own object lists only that file's hotkeys. A later spread replaces an entry with the same id without an error, so keep ids unique across files.

## Provide app hotkeys

Pass the declarations to the root `HotkeysProvider`. See [Provide app hotkeys](./hotkeys-provider-and-scopes#provide-app-hotkeys):
Expand Down
26 changes: 26 additions & 0 deletions docs/framework/vue/guides/app-hotkeys.md
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,32 @@ declare module '@tanstack/vue-hotkeys' {

The `Register` module augmentation enables autocomplete and type checking for `useAppHotkeys()`, `useCustomHotkeys()`, and `CustomHotkeys`.

### Split declarations across files

A large app can declare its hotkeys next to the features that own them. Call `defineAppHotkeys` in each file, then spread the results into the one object you register:

```ts
// features/editor/hotkeys.ts
import { defineAppHotkeys } from '@tanstack/vue-hotkeys'

export const editorHotkeys = defineAppHotkeys({
'editor.format': { hotkey: 'Mod+Shift+F', meta: { name: 'Format document' } },
})
```

```ts
// app-hotkeys.ts
import { defineAppHotkeys } from '@tanstack/vue-hotkeys'
import { editorHotkeys } from './features/editor/hotkeys'

export const appHotkeys = defineAppHotkeys({
...editorHotkeys,
'palette.open': { hotkey: null, meta: { name: 'Command palette' } },
})
```

Each file's call checks its own declarations, so a mismatched option is a type error in that file. Spread-in entries keep their id and the kind of their default. Register and provide only the combined object, since a file's own object lists only that file's hotkeys. A later spread replaces an entry with the same id without an error, so keep ids unique across files.

## Provide app hotkeys

Pass the declarations to the root `HotkeysProvider`. See [Provide app hotkeys](./hotkeys-provider-and-scopes#provide-app-hotkeys):
Expand Down
Loading
Loading