@tanstack/alpine-hotkeys 0.1.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.
package/README.md ADDED
@@ -0,0 +1,140 @@
1
+ <div align="center">
2
+ <picture>
3
+ <source
4
+ media="(prefers-color-scheme: dark)"
5
+ srcset="https://tanstack.com/api/readme/hotkeys.png?theme=dark"
6
+ />
7
+ <source
8
+ media="(prefers-color-scheme: light)"
9
+ srcset="https://tanstack.com/api/readme/hotkeys.png"
10
+ />
11
+ <img
12
+ src="https://tanstack.com/api/readme/hotkeys.png"
13
+ alt="TanStack Hotkeys"
14
+ width="900"
15
+ />
16
+ </picture>
17
+ </div>
18
+
19
+ <br />
20
+
21
+ <div align="center">
22
+ <a href="https://www.npmjs.com/package/@tanstack/hotkeys" target="\_parent">
23
+ <img alt="" src="https://img.shields.io/npm/dm/@tanstack/hotkeys.svg" alt="npm downloads" />
24
+ </a>
25
+ <a href="https://github.com/TanStack/hotkeys" target="\_parent">
26
+ <img alt="" src="https://img.shields.io/github/stars/TanStack/hotkeys.svg?style=social&label=Star" alt="GitHub stars" />
27
+ </a>
28
+ <a href="https://bundlephobia.com/result?p=@tanstack/react-hotkeys@latest" target="\_parent">
29
+ <img alt="" src="https://badgen.net/bundlephobia/minzip/@tanstack/react-hotkeys@latest" alt="Bundle size" />
30
+ </a>
31
+ </div>
32
+
33
+ <div align="center">
34
+ <a href="#badge">
35
+ <img alt="semantic-release" src="https://img.shields.io/badge/%20%20%F0%9F%93%A6%F0%9F%9A%80-semantic--release-e10079.svg">
36
+ </a>
37
+ <a href="#badge">
38
+ <img src="https://img.shields.io/github/v/release/tanstack/hotkeys" alt="Release"/>
39
+ </a>
40
+ <a href="https://twitter.com/tan_stack">
41
+ <img src="https://img.shields.io/twitter/follow/tan_stack.svg?style=social" alt="Follow @TanStack"/>
42
+ </a>
43
+ </div>
44
+
45
+ <div align="center">
46
+
47
+ ### [Become a Sponsor!](https://github.com/sponsors/tannerlinsley/)
48
+
49
+ </div>
50
+
51
+ # TanStack Hotkeys
52
+
53
+ > [!NOTE]
54
+ > TanStack Hotkeys is alpha. We are actively developing the library and are open to feedback and contributions.
55
+
56
+ Type-safe keyboard shortcuts for the web. Template-string bindings, parsed objects, a cross-platform `Mod` key, a singleton Hotkey Manager, and utilities for cheatsheet UIs—built to stay SSR-friendly.
57
+
58
+ - Type-safe bindings — template strings (`Mod+Shift+S`, `Escape`) or parsed objects for full control
59
+ - Flexible options — `keydown`/`keyup`, `preventDefault`, `stopPropagation`, conditional enabled, `requireReset`
60
+ - Cross-platform Mod — maps to Cmd on macOS and Ctrl on Windows/Linux
61
+ - Batteries included — validation + matching, sequences (Vim-style), key-state tracking, recorder UI helpers, framework adapters, and devtools
62
+
63
+ ### <a href="https://tanstack.com/hotkeys">Read the docs →</a>
64
+
65
+ <br />
66
+
67
+ > [!NOTE]
68
+ > You may know **TanStack Hotkeys** by our adapter names, too!
69
+ >
70
+ > - [**Alpine Hotkeys**](https://tanstack.com/hotkeys/latest/docs/framework/alpine/quick-start)
71
+ > - [**Ember Hotkeys**](https://tanstack.com/hotkeys/latest/docs/framework/ember/quick-start)
72
+ > - [**Octane Hotkeys**](https://tanstack.com/hotkeys/latest/docs/framework/octane/quick-start)
73
+ > - [**React Hotkeys**](https://tanstack.com/hotkeys/latest/docs/framework/react/react-hotkeys)
74
+ > - [**Preact Hotkeys**](https://tanstack.com/hotkeys/latest/docs/framework/preact/preact-hotkeys)
75
+ > - [**Solid Hotkeys**](https://tanstack.com/hotkeys/latest/docs/framework/solid/reference)
76
+ > - [**Angular Hotkeys**](https://tanstack.com/hotkeys/latest/docs/framework/angular/reference)
77
+ > - [**Vue Hotkeys**](https://tanstack.com/hotkeys/latest/docs/framework/vue/reference)
78
+ > - [**Lit Hotkeys**](https://tanstack.com/hotkeys/latest/docs/framework/lit/reference)
79
+ > - [**Svelte Hotkeys**](https://tanstack.com/hotkeys/latest/docs/framework/svelte/reference)
80
+
81
+ ## Get Involved
82
+
83
+ - We welcome issues and pull requests!
84
+ - Participate in [GitHub discussions](https://github.com/TanStack/hotkeys/discussions)
85
+ - Chat with the community on [Discord](https://discord.com/invite/WrRKjPJ)
86
+ - See [CONTRIBUTING.md](./CONTRIBUTING.md) for setup instructions
87
+
88
+ ## Partners
89
+
90
+ <div align="center">
91
+
92
+ <table align="center">
93
+ <tr>
94
+ <td>
95
+ <a href="https://www.coderabbit.ai/?via=tanstack&dub_id=aCcEEdAOqqutX6OS" >
96
+ <picture>
97
+ <source media="(prefers-color-scheme: dark)" srcset="https://tanstack.com/assets/coderabbit-dark-D643Zkrv.svg" height="40" />
98
+ <source media="(prefers-color-scheme: light)" srcset="https://tanstack.com/assets/coderabbit-light-CIzGLYU_.svg" height="40" />
99
+ <img src="https://tanstack.com/assets/coderabbit-light-DVMJ2jHi.svg" height="40" alt="CodeRabbit" />
100
+ </picture>
101
+ </a>
102
+ </td>
103
+ <td>
104
+ <a href="https://www.cloudflare.com?utm_source=tanstack">
105
+ <picture>
106
+ <source media="(prefers-color-scheme: dark)" srcset="https://tanstack.com/assets/cloudflare-white-Co-Tyjbl.svg" height="60" />
107
+ <source media="(prefers-color-scheme: light)" srcset="https://tanstack.com/assets/cloudflare-black-6Ojsn8yh.svg" height="60" />
108
+ <img src="https://tanstack.com/assets/cloudflare-black-CPufaW0B.svg" height="60" alt="Cloudflare" />
109
+ </picture>
110
+ </a>
111
+ </td>
112
+ </tr>
113
+ </table>
114
+
115
+ <div align="center">
116
+ <img src="media/partner_logo.svg" alt="Keys & you?" height="65">
117
+ <p>
118
+ We're looking for TanStack Hotkeys Partners to join our mission! Partner with us to push the boundaries of TanStack Hotkeys and build amazing things together.
119
+ </p>
120
+ <a href="mailto:partners@tanstack.com?subject=TanStack Hotkeys Partnership"><b>LET'S CHAT</b></a>
121
+ </div>
122
+
123
+ </div>
124
+
125
+ ## Explore the TanStack Ecosystem
126
+
127
+ - <a href="https://github.com/tanstack/config"><b>TanStack Config</b></a> – Tooling for JS/TS packages
128
+ - <a href="https://github.com/tanstack/db"><b>TanStack DB</b></a> – Reactive sync client store
129
+ - <a href="https://github.com/tanstack/devtools"><b>TanStack DevTools</b></a> – Unified devtools panel
130
+ - <a href="https://github.com/tanstack/form"><b>TanStack Form</b></a> – Type‑safe form state
131
+ - <a href="https://github.com/tanstack/hotkeys"><b>TanStack Hotkeys</b></a> – Type‑safe keyboard shortcuts
132
+ - <a href="https://github.com/tanstack/query"><b>TanStack Query</b></a> – Async state & caching
133
+ - <a href="https://github.com/tanstack/ranger"><b>TanStack Ranger</b></a> – Range & slider primitives
134
+ - <a href="https://github.com/tanstack/router"><b>TanStack Router</b></a> – Type‑safe routing, caching & URL state
135
+ - <a href="https://github.com/tanstack/start"><b>TanStack Start</b></a> – Full‑stack SSR & streaming
136
+ - <a href="https://github.com/tanstack/store"><b>TanStack Store</b></a> – Reactive data store
137
+ - <a href="https://github.com/tanstack/table"><b>TanStack Table</b></a> – Headless datagrids
138
+ - <a href="https://github.com/tanstack/virtual"><b>TanStack Virtual</b></a> – Virtualized rendering
139
+
140
+ … and more at <a href="https://tanstack.com"><b>TanStack.com »</b></a>
@@ -0,0 +1,9 @@
1
+ import { getKeyStateTracker } from "@tanstack/hotkeys";
2
+
3
+ //#region src/createHeldKeyCodes.ts
4
+ function createHeldKeyCodes(scope) {
5
+ return scope.select(getKeyStateTracker().store, (state) => state.heldCodes);
6
+ }
7
+
8
+ //#endregion
9
+ export { createHeldKeyCodes };
@@ -0,0 +1,9 @@
1
+ import { getKeyStateTracker } from "@tanstack/hotkeys";
2
+
3
+ //#region src/createHeldKeys.ts
4
+ function createHeldKeys(scope) {
5
+ return scope.select(getKeyStateTracker().store, (state) => state.heldKeys);
6
+ }
7
+
8
+ //#endregion
9
+ export { createHeldKeys };
@@ -0,0 +1,13 @@
1
+ import { read } from "./scope.js";
2
+ import { createHotkeys } from "./createHotkeys.js";
3
+
4
+ //#region src/createHotkey.ts
5
+ function createHotkey(scope, hotkey, callback, options = {}) {
6
+ createHotkeys(scope, () => [{
7
+ hotkey: read(hotkey),
8
+ callback
9
+ }], options);
10
+ }
11
+
12
+ //#endregion
13
+ export { createHotkey };
@@ -0,0 +1,10 @@
1
+ import { read } from "./scope.js";
2
+ import { getKeyStateTracker, matchesHeldModifiers } from "@tanstack/hotkeys";
3
+
4
+ //#region src/createHotkeyHint.ts
5
+ function createHotkeyHint(scope, hotkey, options = {}) {
6
+ return scope.select(getKeyStateTracker().store, (state) => matchesHeldModifiers(read(hotkey), state.heldKeys, read(options)));
7
+ }
8
+
9
+ //#endregion
10
+ export { createHotkeyHint };
@@ -0,0 +1,29 @@
1
+ import { read } from "./scope.js";
2
+ import { HotkeyRecorder } from "@tanstack/hotkeys";
3
+
4
+ //#region src/createHotkeyRecorder.ts
5
+ function createHotkeyRecorder(scope, options) {
6
+ scope.assertActive();
7
+ const instance = new HotkeyRecorder(() => ({
8
+ ...scope.defaultOptions().hotkeyRecorder,
9
+ ...read(options)
10
+ }));
11
+ const state = scope.select(instance.store, (value) => value);
12
+ scope.addCleanup(() => instance.destroy());
13
+ return {
14
+ get isRecording() {
15
+ return state.value.isRecording;
16
+ },
17
+ get recordedHotkey() {
18
+ return state.value.recordedHotkey;
19
+ },
20
+ startRecording: () => {
21
+ if (!scope.destroyed) instance.start();
22
+ },
23
+ stopRecording: () => instance.stop(),
24
+ cancelRecording: () => instance.cancel()
25
+ };
26
+ }
27
+
28
+ //#endregion
29
+ export { createHotkeyRecorder };
@@ -0,0 +1,18 @@
1
+ import { getHotkeyManager, getSequenceManager, toHotkeyRegistrationView } from "@tanstack/hotkeys";
2
+
3
+ //#region src/createHotkeyRegistrations.ts
4
+ function createHotkeyRegistrations(scope) {
5
+ const hotkeyState = scope.select(getHotkeyManager().registrations, (state) => Array.from(state.values()).map(toHotkeyRegistrationView));
6
+ const sequenceState = scope.select(getSequenceManager().registrations, (state) => Array.from(state.values()));
7
+ return {
8
+ get hotkeys() {
9
+ return hotkeyState.value;
10
+ },
11
+ get sequences() {
12
+ return sequenceState.value;
13
+ }
14
+ };
15
+ }
16
+
17
+ //#endregion
18
+ export { createHotkeyRegistrations };
@@ -0,0 +1,13 @@
1
+ import { read } from "./scope.js";
2
+ import { createHotkeySequences } from "./createHotkeySequences.js";
3
+
4
+ //#region src/createHotkeySequence.ts
5
+ function createHotkeySequence(scope, sequence, callback, options = {}) {
6
+ createHotkeySequences(scope, () => [{
7
+ sequence: read(sequence),
8
+ callback
9
+ }], options);
10
+ }
11
+
12
+ //#endregion
13
+ export { createHotkeySequence };
@@ -0,0 +1,33 @@
1
+ import { read } from "./scope.js";
2
+ import { HotkeySequenceRecorder } from "@tanstack/hotkeys";
3
+
4
+ //#region src/createHotkeySequenceRecorder.ts
5
+ function createHotkeySequenceRecorder(scope, options) {
6
+ scope.assertActive();
7
+ const instance = new HotkeySequenceRecorder(() => ({
8
+ ...scope.defaultOptions().hotkeySequenceRecorder,
9
+ ...read(options)
10
+ }));
11
+ const state = scope.select(instance.store, (value) => value);
12
+ scope.addCleanup(() => instance.destroy());
13
+ return {
14
+ get isRecording() {
15
+ return state.value.isRecording;
16
+ },
17
+ get steps() {
18
+ return state.value.steps;
19
+ },
20
+ get recordedSequence() {
21
+ return state.value.recordedSequence;
22
+ },
23
+ startRecording: () => {
24
+ if (!scope.destroyed) instance.start();
25
+ },
26
+ stopRecording: () => instance.stop(),
27
+ cancelRecording: () => instance.cancel(),
28
+ commitRecording: () => instance.commit()
29
+ };
30
+ }
31
+
32
+ //#endregion
33
+ export { createHotkeySequenceRecorder };
@@ -0,0 +1,16 @@
1
+ import { read } from "./scope.js";
2
+ import { createHotkeySequenceBindings } from "@tanstack/hotkeys/adapter";
3
+
4
+ //#region src/createHotkeySequences.ts
5
+ function createHotkeySequences(scope, definitions, options = {}) {
6
+ scope.assertActive();
7
+ const bindings = createHotkeySequenceBindings();
8
+ scope.addCleanup(bindings.destroy);
9
+ scope.effect(() => bindings.update(read(definitions), {
10
+ ...scope.defaultOptions().hotkeySequence,
11
+ ...read(options)
12
+ }));
13
+ }
14
+
15
+ //#endregion
16
+ export { createHotkeySequences };
@@ -0,0 +1,16 @@
1
+ import { read } from "./scope.js";
2
+ import { createHotkeyBindings } from "@tanstack/hotkeys/adapter";
3
+
4
+ //#region src/createHotkeys.ts
5
+ function createHotkeys(scope, definitions, options = {}) {
6
+ scope.assertActive();
7
+ const bindings = createHotkeyBindings();
8
+ scope.addCleanup(bindings.destroy);
9
+ scope.effect(() => bindings.update(read(definitions), {
10
+ ...scope.defaultOptions().hotkey,
11
+ ...read(options)
12
+ }));
13
+ }
14
+
15
+ //#endregion
16
+ export { createHotkeys };
@@ -0,0 +1,6 @@
1
+ import { AlpineHotkeys, DefaultHotkeysOptions, MaybeGetter } from "./types.js";
2
+ //#region src/createHotkeysScope.d.ts
3
+ /** Owns Alpine effects and Store subscriptions, with optional shared defaults. Call destroy from x-data's destroy hook. */
4
+ export declare function createHotkeysScope(defaultOptions?: MaybeGetter<DefaultHotkeysOptions>): AlpineHotkeys;
5
+ //#endregion
6
+ export type { AlpineHotkeys, DefaultHotkeysOptions, MaybeGetter };
@@ -0,0 +1,35 @@
1
+ import { createScope } from "./scope.js";
2
+ import { createHotkeys } from "./createHotkeys.js";
3
+ import { createHotkey } from "./createHotkey.js";
4
+ import { createHotkeySequences } from "./createHotkeySequences.js";
5
+ import { createHotkeySequence } from "./createHotkeySequence.js";
6
+ import { createHeldKeys } from "./createHeldKeys.js";
7
+ import { createHeldKeyCodes } from "./createHeldKeyCodes.js";
8
+ import { createKeyHold } from "./createKeyHold.js";
9
+ import { createHotkeyHint } from "./createHotkeyHint.js";
10
+ import { createHotkeyRegistrations } from "./createHotkeyRegistrations.js";
11
+ import { createHotkeyRecorder } from "./createHotkeyRecorder.js";
12
+ import { createHotkeySequenceRecorder } from "./createHotkeySequenceRecorder.js";
13
+
14
+ //#region src/createHotkeysScope.ts
15
+ /** Owns Alpine effects and Store subscriptions, with optional shared defaults. Call destroy from x-data's destroy hook. */
16
+ function createHotkeysScope(defaultOptions = {}) {
17
+ const scope = createScope(defaultOptions);
18
+ return {
19
+ createHotkey: (...args) => createHotkey(scope, ...args),
20
+ createHotkeys: (...args) => createHotkeys(scope, ...args),
21
+ createHotkeySequence: (...args) => createHotkeySequence(scope, ...args),
22
+ createHotkeySequences: (...args) => createHotkeySequences(scope, ...args),
23
+ createHeldKeys: (...args) => createHeldKeys(scope, ...args),
24
+ createHeldKeyCodes: (...args) => createHeldKeyCodes(scope, ...args),
25
+ createKeyHold: (...args) => createKeyHold(scope, ...args),
26
+ createHotkeyHint: (...args) => createHotkeyHint(scope, ...args),
27
+ createHotkeyRegistrations: (...args) => createHotkeyRegistrations(scope, ...args),
28
+ createHotkeyRecorder: (...args) => createHotkeyRecorder(scope, ...args),
29
+ createHotkeySequenceRecorder: (...args) => createHotkeySequenceRecorder(scope, ...args),
30
+ destroy: scope.destroy
31
+ };
32
+ }
33
+
34
+ //#endregion
35
+ export { createHotkeysScope };
@@ -0,0 +1,10 @@
1
+ import { read } from "./scope.js";
2
+ import { getKeyStateTracker } from "@tanstack/hotkeys";
3
+
4
+ //#region src/createKeyHold.ts
5
+ function createKeyHold(scope, key) {
6
+ return scope.select(getKeyStateTracker().store, (state) => state.heldKeys.includes(read(key)));
7
+ }
8
+
9
+ //#endregion
10
+ export { createKeyHold };
@@ -0,0 +1,5 @@
1
+ import Alpine from "alpinejs";
2
+ //#region src/hotkeysPlugin.d.ts
3
+ /** Installs $hotkeys, whose registrations and subscriptions belong to its element. */
4
+ export declare function hotkeysPlugin(alpine: typeof Alpine): void;
5
+ //#endregion
@@ -0,0 +1,23 @@
1
+ import { createHotkeysScope } from "./createHotkeysScope.js";
2
+
3
+ //#region src/hotkeysPlugin.ts
4
+ /** Installs $hotkeys, whose registrations and subscriptions belong to its element. */
5
+ function hotkeysPlugin(alpine) {
6
+ const scopes = /* @__PURE__ */ new WeakMap();
7
+ alpine.magic("hotkeys", (element, { cleanup }) => {
8
+ let scope = scopes.get(element);
9
+ if (!scope) {
10
+ scope = createHotkeysScope();
11
+ scopes.set(element, scope);
12
+ const ownedScope = scope;
13
+ cleanup(() => {
14
+ ownedScope.destroy();
15
+ scopes.delete(element);
16
+ });
17
+ }
18
+ return scope;
19
+ });
20
+ }
21
+
22
+ //#endregion
23
+ export { hotkeysPlugin };
@@ -0,0 +1,6 @@
1
+ import { AlpineHotkeyRecorder, AlpineHotkeySequenceRecorder, AlpineHotkeyState, AlpineHotkeys, DefaultHotkeysOptions, HotkeyRegistrationsResult, MaybeGetter } from "./types.js";
2
+ import { createHotkeysScope } from "./createHotkeysScope.js";
3
+ import { hotkeysPlugin } from "./hotkeysPlugin.js";
4
+ import { HotkeyDefinition, HotkeySequenceDefinition } from "@tanstack/hotkeys/adapter";
5
+ export * from "@tanstack/hotkeys";
6
+ export { AlpineHotkeyRecorder, AlpineHotkeySequenceRecorder, AlpineHotkeyState, AlpineHotkeys, DefaultHotkeysOptions, type HotkeyDefinition, HotkeyRegistrationsResult, type HotkeySequenceDefinition, MaybeGetter, createHotkeysScope, hotkeysPlugin };
package/dist/index.js ADDED
@@ -0,0 +1,6 @@
1
+ import { createHotkeysScope } from "./createHotkeysScope.js";
2
+ import { hotkeysPlugin } from "./hotkeysPlugin.js";
3
+
4
+ export * from "@tanstack/hotkeys"
5
+
6
+ export { createHotkeysScope, hotkeysPlugin };
package/dist/scope.js ADDED
@@ -0,0 +1,50 @@
1
+ import Alpine from "alpinejs";
2
+
3
+ //#region src/scope.ts
4
+ function read(value) {
5
+ return typeof value === "function" ? value() : value;
6
+ }
7
+ function createScope(defaultOptions) {
8
+ const cleanups = /* @__PURE__ */ new Set();
9
+ let destroyed = false;
10
+ function assertActive() {
11
+ if (destroyed) throw new Error("Cannot use a destroyed hotkeys scope");
12
+ }
13
+ function effect(callback) {
14
+ assertActive();
15
+ const runner = Alpine.effect(() => {
16
+ if (!destroyed) callback();
17
+ });
18
+ cleanups.add(() => Alpine.release(runner));
19
+ }
20
+ function select(store, selector) {
21
+ assertActive();
22
+ const state = Alpine.reactive({ snapshot: store.state });
23
+ const subscription = store.subscribe(() => {
24
+ state.snapshot = store.state;
25
+ });
26
+ cleanups.add(() => subscription.unsubscribe());
27
+ return { get value() {
28
+ return selector(state.snapshot);
29
+ } };
30
+ }
31
+ return {
32
+ assertActive,
33
+ effect,
34
+ select,
35
+ defaultOptions: () => read(defaultOptions),
36
+ addCleanup: (cleanup) => cleanups.add(cleanup),
37
+ get destroyed() {
38
+ return destroyed;
39
+ },
40
+ destroy() {
41
+ if (destroyed) return;
42
+ destroyed = true;
43
+ for (const cleanup of [...cleanups].reverse()) cleanup();
44
+ cleanups.clear();
45
+ }
46
+ };
47
+ }
48
+
49
+ //#endregion
50
+ export { createScope, read };
@@ -0,0 +1,79 @@
1
+ import { HeldModifierOptions, Hotkey, HotkeyCallback, HotkeyOptions, HotkeyRecorderOptions, HotkeyRegistrationView, HotkeySequence, HotkeySequenceRecorderOptions, IndividualKey, RegisterableHotkey, SequenceOptions, SequenceRegistrationView } from "@tanstack/hotkeys";
2
+ import { HotkeyDefinition, HotkeySequenceDefinition } from "@tanstack/hotkeys/adapter";
3
+ //#region src/types.d.ts
4
+ /** A reactive value. Read `.value` where the framework tracks dependencies. */
5
+ export interface AlpineHotkeyState<T> {
6
+ readonly value: T;
7
+ }
8
+ /** Recording state and controls owned by the containing scope. */
9
+ export interface AlpineHotkeyRecorder {
10
+ /** Whether the recorder is listening for a shortcut. */
11
+ readonly isRecording: boolean;
12
+ /** The last recorded binding, including brackets for physical codes. */
13
+ readonly recordedHotkey: Hotkey | null;
14
+ /** Start a new recording session. */
15
+ startRecording: () => void;
16
+ /** Stop and clear recorder state without calling onRecord or onCancel. */
17
+ stopRecording: () => void;
18
+ /** Stop, clear recorder state, and call onCancel. */
19
+ cancelRecording: () => void;
20
+ }
21
+ /** Sequence recording state and controls. */
22
+ export interface AlpineHotkeySequenceRecorder {
23
+ /** Whether the recorder is listening for chords. */
24
+ readonly isRecording: boolean;
25
+ /** Chords captured in the current session. */
26
+ readonly steps: HotkeySequence;
27
+ /** The last committed sequence. */
28
+ readonly recordedSequence: HotkeySequence | null;
29
+ /** Start a new recording session. */
30
+ startRecording: () => void;
31
+ /** Stop without committing or calling onCancel. */
32
+ stopRecording: () => void;
33
+ /** Discard the current session and call onCancel. */
34
+ cancelRecording: () => void;
35
+ /** Commit the current steps. Does nothing when no steps are recorded. */
36
+ commitRecording: () => void;
37
+ }
38
+ /** Live registration views from the shared hotkey and sequence managers. */
39
+ export interface HotkeyRegistrationsResult {
40
+ readonly hotkeys: Array<HotkeyRegistrationView>;
41
+ readonly sequences: Array<SequenceRegistrationView>;
42
+ }
43
+ /** A value or a getter evaluated within an Alpine effect or reactive read. */
44
+ export type MaybeGetter<T> = T | (() => T);
45
+ /** Registrations, recorders, and reactive state owned by one Alpine component. */
46
+ export interface AlpineHotkeys {
47
+ /** Register one shortcut. Getters track changing bindings and options. */
48
+ createHotkey: (hotkey: MaybeGetter<RegisterableHotkey>, callback: HotkeyCallback, options?: MaybeGetter<HotkeyOptions>) => void;
49
+ /** Reconcile a list of shortcuts. Definition options override common options. */
50
+ createHotkeys: (definitions: MaybeGetter<Array<HotkeyDefinition>>, options?: MaybeGetter<HotkeyOptions>) => void;
51
+ /** Register consecutive chords with an optional timeout and element target. */
52
+ createHotkeySequence: (sequence: MaybeGetter<HotkeySequence>, callback: HotkeyCallback, options?: MaybeGetter<SequenceOptions>) => void;
53
+ /** Reconcile a changing list of sequences. */
54
+ createHotkeySequences: (definitions: MaybeGetter<Array<HotkeySequenceDefinition>>, options?: MaybeGetter<SequenceOptions>) => void;
55
+ /** Read held logical key names through `.value`. */
56
+ createHeldKeys: () => AlpineHotkeyState<Array<string>>;
57
+ /** Read the mapping of held logical names to physical codes through `.value`. */
58
+ createHeldKeyCodes: () => AlpineHotkeyState<Record<string, string>>;
59
+ /** Read whether a key is held through `.value`. */
60
+ createKeyHold: (key: MaybeGetter<IndividualKey>) => AlpineHotkeyState<boolean>;
61
+ /** Read whether held modifiers reveal a binding through `.value`. */
62
+ createHotkeyHint: (hotkey: MaybeGetter<RegisterableHotkey>, options?: MaybeGetter<HeldModifierOptions>) => AlpineHotkeyState<boolean>;
63
+ /** Read live hotkey and sequence registrations, including disabled entries. */
64
+ createHotkeyRegistrations: () => HotkeyRegistrationsResult;
65
+ /** Create a recorder whose options can follow Alpine state. */
66
+ createHotkeyRecorder: (options: MaybeGetter<HotkeyRecorderOptions>) => AlpineHotkeyRecorder;
67
+ /** Create a sequence recorder with live steps and explicit commit controls. */
68
+ createHotkeySequenceRecorder: (options: MaybeGetter<HotkeySequenceRecorderOptions>) => AlpineHotkeySequenceRecorder;
69
+ /** Release every registration, subscription, effect, and recorder. Idempotent. */
70
+ destroy: () => void;
71
+ }
72
+ /** Shared defaults; call-specific options take precedence. */
73
+ export interface DefaultHotkeysOptions {
74
+ hotkey?: HotkeyOptions;
75
+ hotkeySequence?: SequenceOptions;
76
+ hotkeyRecorder?: Partial<HotkeyRecorderOptions>;
77
+ hotkeySequenceRecorder?: Partial<HotkeySequenceRecorderOptions>;
78
+ }
79
+ //#endregion
package/package.json ADDED
@@ -0,0 +1,57 @@
1
+ {
2
+ "name": "@tanstack/alpine-hotkeys",
3
+ "version": "0.1.0",
4
+ "description": "Alpine adapter for TanStack Hotkeys",
5
+ "author": "Tanner Linsley",
6
+ "license": "MIT",
7
+ "repository": {
8
+ "type": "git",
9
+ "url": "git+https://github.com/TanStack/hotkeys.git",
10
+ "directory": "packages/alpine-hotkeys"
11
+ },
12
+ "homepage": "https://tanstack.com/hotkeys",
13
+ "funding": {
14
+ "type": "github",
15
+ "url": "https://github.com/sponsors/tannerlinsley"
16
+ },
17
+ "keywords": [
18
+ "alpine",
19
+ "tanstack",
20
+ "hotkeys"
21
+ ],
22
+ "scripts": {
23
+ "clean": "premove ./build ./dist",
24
+ "lint": "eslint ./src",
25
+ "lint:fix": "eslint ./src --fix",
26
+ "test:eslint": "eslint ./src",
27
+ "test:lib": "vitest --passWithNoTests",
28
+ "test:lib:dev": "pnpm test:lib --watch",
29
+ "test:types": "tsc",
30
+ "build": "tsdown",
31
+ "test:build": "publint --strict && node ../../scripts/verify-package.ts"
32
+ },
33
+ "type": "module",
34
+ "types": "./dist/index.d.ts",
35
+ "exports": {
36
+ ".": "./dist/index.js",
37
+ "./package.json": "./package.json"
38
+ },
39
+ "sideEffects": false,
40
+ "engines": {
41
+ "node": ">=20"
42
+ },
43
+ "files": [
44
+ "dist"
45
+ ],
46
+ "dependencies": {
47
+ "@tanstack/hotkeys": "workspace:*",
48
+ "@tanstack/store": "^0.11.2"
49
+ },
50
+ "devDependencies": {
51
+ "@types/alpinejs": "^3.17.0",
52
+ "alpinejs": "^3.17.4"
53
+ },
54
+ "peerDependencies": {
55
+ "alpinejs": "^3.15.12"
56
+ }
57
+ }