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
10 changes: 10 additions & 0 deletions .changeset/red-pens-taste.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
---
'@tanstack/hotkeys': minor
'@tanstack/react-hotkeys': minor
'@tanstack/solid-hotkeys': minor
'@tanstack/hotkeys-devtools': minor
'@tanstack/solid-hotkeys-devtools': minor
'@tanstack/react-hotkeys-devtools': minor
---

feat: overhaul sequence-manager and hooks to be in feature parity with hotkey-manager.
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ function useHotkeySequence(
options): void;
```

Defined in: [useHotkeySequence.ts:50](https://github.com/TanStack/hotkeys/blob/main/packages/react-hotkeys/src/useHotkeySequence.ts#L50)
Defined in: [useHotkeySequence.ts:61](https://github.com/TanStack/hotkeys/blob/main/packages/react-hotkeys/src/useHotkeySequence.ts#L61)

React hook for registering a keyboard shortcut sequence (Vim-style).

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,20 +5,27 @@ title: UseHotkeySequenceOptions

# Interface: UseHotkeySequenceOptions

Defined in: [useHotkeySequence.ts:10](https://github.com/TanStack/hotkeys/blob/main/packages/react-hotkeys/src/useHotkeySequence.ts#L10)
Defined in: [useHotkeySequence.ts:12](https://github.com/TanStack/hotkeys/blob/main/packages/react-hotkeys/src/useHotkeySequence.ts#L12)

## Extends

- `Omit`\<`SequenceOptions`, `"enabled"`\>
- `Omit`\<`SequenceOptions`, `"target"`\>

## Properties

### enabled?
### target?

```ts
optional enabled: boolean;
optional target:
| HTMLElement
| Document
| Window
| RefObject<HTMLElement | null>
| null;
```

Defined in: [useHotkeySequence.ts:15](https://github.com/TanStack/hotkeys/blob/main/packages/react-hotkeys/src/useHotkeySequence.ts#L15)
Defined in: [useHotkeySequence.ts:21](https://github.com/TanStack/hotkeys/blob/main/packages/react-hotkeys/src/useHotkeySequence.ts#L21)

Whether the sequence is enabled. Defaults to true.
The DOM element to attach the event listener to.
Can be a React ref, direct DOM element, or null.
Defaults to document.
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ function createHotkeySequence(
options): void;
```

Defined in: [createHotkeySequence.ts:50](https://github.com/TanStack/hotkeys/blob/main/packages/solid-hotkeys/src/createHotkeySequence.ts#L50)
Defined in: [createHotkeySequence.ts:54](https://github.com/TanStack/hotkeys/blob/main/packages/solid-hotkeys/src/createHotkeySequence.ts#L54)

SolidJS primitive for registering a keyboard shortcut sequence (Vim-style).

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,20 +5,21 @@ title: CreateHotkeySequenceOptions

# Interface: CreateHotkeySequenceOptions

Defined in: [createHotkeySequence.ts:10](https://github.com/TanStack/hotkeys/blob/main/packages/solid-hotkeys/src/createHotkeySequence.ts#L10)
Defined in: [createHotkeySequence.ts:11](https://github.com/TanStack/hotkeys/blob/main/packages/solid-hotkeys/src/createHotkeySequence.ts#L11)

## Extends

- `Omit`\<`SequenceOptions`, `"enabled"`\>
- `Omit`\<`SequenceOptions`, `"target"`\>

## Properties

### enabled?
### target?

```ts
optional enabled: boolean;
optional target: HTMLElement | Document | Window | null;
```

Defined in: [createHotkeySequence.ts:15](https://github.com/TanStack/hotkeys/blob/main/packages/solid-hotkeys/src/createHotkeySequence.ts#L15)
Defined in: [createHotkeySequence.ts:19](https://github.com/TanStack/hotkeys/blob/main/packages/solid-hotkeys/src/createHotkeySequence.ts#L19)

Whether the sequence is enabled. Defaults to true.
The DOM element to attach the event listener to.
Can be a direct DOM element, an accessor, or null. Defaults to document.
20 changes: 10 additions & 10 deletions docs/reference/classes/HotkeyManager.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ title: HotkeyManager

# Class: HotkeyManager

Defined in: [hotkey-manager.ts:166](https://github.com/TanStack/hotkeys/blob/main/packages/hotkeys/src/hotkey-manager.ts#L166)
Defined in: [hotkey-manager.ts:140](https://github.com/TanStack/hotkeys/blob/main/packages/hotkeys/src/hotkey-manager.ts#L140)

Singleton manager for hotkey registrations.

Expand Down Expand Up @@ -34,7 +34,7 @@ unregister()
readonly registrations: Store<Map<string, HotkeyRegistration>>;
```

Defined in: [hotkey-manager.ts:188](https://github.com/TanStack/hotkeys/blob/main/packages/hotkeys/src/hotkey-manager.ts#L188)
Defined in: [hotkey-manager.ts:162](https://github.com/TanStack/hotkeys/blob/main/packages/hotkeys/src/hotkey-manager.ts#L162)

The TanStack Store containing all hotkey registrations.
Use this to subscribe to registration changes or access current registrations.
Expand Down Expand Up @@ -63,7 +63,7 @@ for (const [id, reg] of manager.registrations.state) {
destroy(): void;
```

Defined in: [hotkey-manager.ts:836](https://github.com/TanStack/hotkeys/blob/main/packages/hotkeys/src/hotkey-manager.ts#L836)
Defined in: [hotkey-manager.ts:698](https://github.com/TanStack/hotkeys/blob/main/packages/hotkeys/src/hotkey-manager.ts#L698)

Destroys the manager and removes all listeners.

Expand All @@ -79,7 +79,7 @@ Destroys the manager and removes all listeners.
getRegistrationCount(): number;
```

Defined in: [hotkey-manager.ts:807](https://github.com/TanStack/hotkeys/blob/main/packages/hotkeys/src/hotkey-manager.ts#L807)
Defined in: [hotkey-manager.ts:669](https://github.com/TanStack/hotkeys/blob/main/packages/hotkeys/src/hotkey-manager.ts#L669)

Gets the number of registered hotkeys.

Expand All @@ -95,7 +95,7 @@ Gets the number of registered hotkeys.
isRegistered(hotkey, target?): boolean;
```

Defined in: [hotkey-manager.ts:818](https://github.com/TanStack/hotkeys/blob/main/packages/hotkeys/src/hotkey-manager.ts#L818)
Defined in: [hotkey-manager.ts:680](https://github.com/TanStack/hotkeys/blob/main/packages/hotkeys/src/hotkey-manager.ts#L680)

Checks if a specific hotkey is registered.

Expand All @@ -111,7 +111,7 @@ The hotkey string to check

Optional target element to match (if provided, both hotkey and target must match)

`Document` | `Window` | `HTMLElement`
`HTMLElement` | `Document` | `Window`

#### Returns

Expand All @@ -130,7 +130,7 @@ register(
options): HotkeyRegistrationHandle;
```

Defined in: [hotkey-manager.ts:251](https://github.com/TanStack/hotkeys/blob/main/packages/hotkeys/src/hotkey-manager.ts#L251)
Defined in: [hotkey-manager.ts:225](https://github.com/TanStack/hotkeys/blob/main/packages/hotkeys/src/hotkey-manager.ts#L225)

Registers a hotkey handler and returns a handle for updating the registration.

Expand Down Expand Up @@ -186,7 +186,7 @@ handle.unregister()
triggerRegistration(id): boolean;
```

Defined in: [hotkey-manager.ts:771](https://github.com/TanStack/hotkeys/blob/main/packages/hotkeys/src/hotkey-manager.ts#L771)
Defined in: [hotkey-manager.ts:633](https://github.com/TanStack/hotkeys/blob/main/packages/hotkeys/src/hotkey-manager.ts#L633)

Triggers a registration's callback programmatically from devtools.
Creates a synthetic KeyboardEvent and invokes the callback.
Expand All @@ -213,7 +213,7 @@ True if the registration was found and triggered
static getInstance(): HotkeyManager;
```

Defined in: [hotkey-manager.ts:209](https://github.com/TanStack/hotkeys/blob/main/packages/hotkeys/src/hotkey-manager.ts#L209)
Defined in: [hotkey-manager.ts:183](https://github.com/TanStack/hotkeys/blob/main/packages/hotkeys/src/hotkey-manager.ts#L183)

Gets the singleton instance of HotkeyManager.

Expand All @@ -229,7 +229,7 @@ Gets the singleton instance of HotkeyManager.
static resetInstance(): void;
```

Defined in: [hotkey-manager.ts:219](https://github.com/TanStack/hotkeys/blob/main/packages/hotkeys/src/hotkey-manager.ts#L219)
Defined in: [hotkey-manager.ts:193](https://github.com/TanStack/hotkeys/blob/main/packages/hotkeys/src/hotkey-manager.ts#L193)

Resets the singleton instance. Useful for testing.

Expand Down
72 changes: 43 additions & 29 deletions docs/reference/classes/SequenceManager.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,27 +5,20 @@ title: SequenceManager

# Class: SequenceManager

Defined in: [sequence.ts:79](https://github.com/TanStack/hotkeys/blob/main/packages/hotkeys/src/sequence.ts#L79)
Defined in: [sequence-manager.ts:148](https://github.com/TanStack/hotkeys/blob/main/packages/hotkeys/src/sequence-manager.ts#L148)

Manages keyboard sequence matching for Vim-style shortcuts.
## Properties

This class allows registering multi-key sequences like 'g g' or 'd d'
that trigger callbacks when the full sequence is pressed within
a configurable timeout.

## Example
### registrations

```ts
const matcher = SequenceManager.getInstance()
readonly registrations: Store<Map<string, SequenceRegistrationView>>;
```

// Register 'g g' to go to top
const unregister = matcher.register(['G', 'G'], (event, context) => {
scrollToTop()
}, { timeout: 500 })
Defined in: [sequence-manager.ts:155](https://github.com/TanStack/hotkeys/blob/main/packages/hotkeys/src/sequence-manager.ts#L155)

// Later, to unregister:
unregister()
```
The TanStack Store containing sequence registration views for devtools.
Subscribe to this to observe registration changes.

## Methods

Expand All @@ -35,7 +28,7 @@ unregister()
destroy(): void;
```

Defined in: [sequence.ts:300](https://github.com/TanStack/hotkeys/blob/main/packages/hotkeys/src/sequence.ts#L300)
Defined in: [sequence-manager.ts:597](https://github.com/TanStack/hotkeys/blob/main/packages/hotkeys/src/sequence-manager.ts#L597)

Destroys the manager and removes all listeners.

Expand All @@ -51,7 +44,7 @@ Destroys the manager and removes all listeners.
getRegistrationCount(): number;
```

Defined in: [sequence.ts:293](https://github.com/TanStack/hotkeys/blob/main/packages/hotkeys/src/sequence.ts#L293)
Defined in: [sequence-manager.ts:590](https://github.com/TanStack/hotkeys/blob/main/packages/hotkeys/src/sequence-manager.ts#L590)

Gets the number of registered sequences.

Expand All @@ -67,10 +60,10 @@ Gets the number of registered sequences.
register(
sequence,
callback,
options): () => void;
options): SequenceRegistrationHandle;
```

Defined in: [sequence.ts:118](https://github.com/TanStack/hotkeys/blob/main/packages/hotkeys/src/sequence.ts#L118)
Defined in: [sequence-manager.ts:201](https://github.com/TanStack/hotkeys/blob/main/packages/hotkeys/src/sequence-manager.ts#L201)

Registers a hotkey sequence handler.

Expand All @@ -96,31 +89,52 @@ Options for the sequence behavior

#### Returns

A function to unregister the sequence
[`SequenceRegistrationHandle`](../interfaces/SequenceRegistrationHandle.md)

A handle to update or unregister the sequence

***

### resetAll()

```ts
(): void;
resetAll(): void;
```

##### Returns
Defined in: [sequence-manager.ts:532](https://github.com/TanStack/hotkeys/blob/main/packages/hotkeys/src/sequence-manager.ts#L532)

Resets all sequence progress.

#### Returns

`void`

***

### resetAll()
### triggerSequence()

```ts
resetAll(): void;
triggerSequence(id): boolean;
```

Defined in: [sequence.ts:283](https://github.com/TanStack/hotkeys/blob/main/packages/hotkeys/src/sequence.ts#L283)
Defined in: [sequence-manager.ts:546](https://github.com/TanStack/hotkeys/blob/main/packages/hotkeys/src/sequence-manager.ts#L546)

Resets all sequence progress.
Triggers a sequence's callback programmatically from devtools.
Creates a synthetic KeyboardEvent from the last key in the sequence.

#### Parameters

##### id

`string`

The registration ID to trigger

#### Returns

`void`
`boolean`

True if the registration was found and triggered

***

Expand All @@ -130,7 +144,7 @@ Resets all sequence progress.
static getInstance(): SequenceManager;
```

Defined in: [sequence.ts:93](https://github.com/TanStack/hotkeys/blob/main/packages/hotkeys/src/sequence.ts#L93)
Defined in: [sequence-manager.ts:176](https://github.com/TanStack/hotkeys/blob/main/packages/hotkeys/src/sequence-manager.ts#L176)

Gets the singleton instance of SequenceManager.

Expand All @@ -146,7 +160,7 @@ Gets the singleton instance of SequenceManager.
static resetInstance(): void;
```

Defined in: [sequence.ts:103](https://github.com/TanStack/hotkeys/blob/main/packages/hotkeys/src/sequence.ts#L103)
Defined in: [sequence-manager.ts:186](https://github.com/TanStack/hotkeys/blob/main/packages/hotkeys/src/sequence-manager.ts#L186)

Resets the singleton instance. Useful for testing.

Expand Down
6 changes: 5 additions & 1 deletion docs/reference/functions/createSequenceMatcher.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,14 @@ title: createSequenceMatcher
function createSequenceMatcher(sequence, options): object;
```

Defined in: [sequence.ts:332](https://github.com/TanStack/hotkeys/blob/main/packages/hotkeys/src/sequence.ts#L332)
Defined in: [sequence-manager.ts:636](https://github.com/TanStack/hotkeys/blob/main/packages/hotkeys/src/sequence-manager.ts#L636)

Creates a simple sequence matcher for one-off use.

This is a low-level helper that does not support ignoreInputs, target,
or other HotkeyOptions. Callers must handle input filtering themselves
if attaching to document.

## Parameters

### sequence
Expand Down
2 changes: 1 addition & 1 deletion docs/reference/functions/formatForDisplay.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ title: formatForDisplay
function formatForDisplay(hotkey, options): string;
```

Defined in: [format.ts:61](https://github.com/TanStack/hotkeys/blob/main/packages/hotkeys/src/format.ts#L61)
Defined in: [format.ts:77](https://github.com/TanStack/hotkeys/blob/main/packages/hotkeys/src/format.ts#L77)

Formats a hotkey for display in a user interface.

Expand Down
2 changes: 1 addition & 1 deletion docs/reference/functions/formatHotkey.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ title: formatHotkey
function formatHotkey(parsed): string;
```

Defined in: [format.ts:23](https://github.com/TanStack/hotkeys/blob/main/packages/hotkeys/src/format.ts#L23)
Defined in: [format.ts:39](https://github.com/TanStack/hotkeys/blob/main/packages/hotkeys/src/format.ts#L39)

Converts a ParsedHotkey back to a hotkey string.

Expand Down
35 changes: 35 additions & 0 deletions docs/reference/functions/formatHotkeySequence.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
---
id: formatHotkeySequence
title: formatHotkeySequence
---

# Function: formatHotkeySequence()

```ts
function formatHotkeySequence(sequence): string;
```

Defined in: [format.ts:23](https://github.com/TanStack/hotkeys/blob/main/packages/hotkeys/src/format.ts#L23)

Converts a hotkey sequence array to a display string.

## Parameters

### sequence

[`Hotkey`](../type-aliases/Hotkey.md)[]

Array of hotkey strings that form the sequence

## Returns

`string`

A space-separated string (e.g. ['G','G'] β†’ 'G G')

## Example

```ts
formatHotkeySequence(['G', 'G']) // 'G G'
formatHotkeySequence(['D', 'I', 'W']) // 'D I W'
```
Loading
Loading