@tanstack/lit-hotkeys 0.0.1
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 +123 -0
- package/dist/constants.cjs +27 -0
- package/dist/constants.cjs.map +1 -0
- package/dist/constants.js +25 -0
- package/dist/constants.js.map +1 -0
- package/dist/controllers/held-key-codes.cjs +61 -0
- package/dist/controllers/held-key-codes.cjs.map +1 -0
- package/dist/controllers/held-key-codes.d.cts +45 -0
- package/dist/controllers/held-key-codes.d.ts +45 -0
- package/dist/controllers/held-key-codes.js +61 -0
- package/dist/controllers/held-key-codes.js.map +1 -0
- package/dist/controllers/held-keys.cjs +58 -0
- package/dist/controllers/held-keys.cjs.map +1 -0
- package/dist/controllers/held-keys.d.cts +44 -0
- package/dist/controllers/held-keys.d.ts +44 -0
- package/dist/controllers/held-keys.js +58 -0
- package/dist/controllers/held-keys.js.map +1 -0
- package/dist/controllers/hotkey-recorder.cjs +104 -0
- package/dist/controllers/hotkey-recorder.cjs.map +1 -0
- package/dist/controllers/hotkey-recorder.d.cts +75 -0
- package/dist/controllers/hotkey-recorder.d.ts +75 -0
- package/dist/controllers/hotkey-recorder.js +104 -0
- package/dist/controllers/hotkey-recorder.js.map +1 -0
- package/dist/controllers/hotkey-sequence-recorder.cjs +117 -0
- package/dist/controllers/hotkey-sequence-recorder.cjs.map +1 -0
- package/dist/controllers/hotkey-sequence-recorder.d.cts +83 -0
- package/dist/controllers/hotkey-sequence-recorder.d.ts +83 -0
- package/dist/controllers/hotkey-sequence-recorder.js +117 -0
- package/dist/controllers/hotkey-sequence-recorder.js.map +1 -0
- package/dist/controllers/hotkey-sequence.cjs +58 -0
- package/dist/controllers/hotkey-sequence.cjs.map +1 -0
- package/dist/controllers/hotkey-sequence.d.cts +45 -0
- package/dist/controllers/hotkey-sequence.d.ts +45 -0
- package/dist/controllers/hotkey-sequence.js +58 -0
- package/dist/controllers/hotkey-sequence.js.map +1 -0
- package/dist/controllers/hotkey.cjs +60 -0
- package/dist/controllers/hotkey.cjs.map +1 -0
- package/dist/controllers/hotkey.d.cts +45 -0
- package/dist/controllers/hotkey.d.ts +45 -0
- package/dist/controllers/hotkey.js +60 -0
- package/dist/controllers/hotkey.js.map +1 -0
- package/dist/controllers/index.d.cts +7 -0
- package/dist/controllers/index.d.ts +7 -0
- package/dist/controllers/key-hold.cjs +78 -0
- package/dist/controllers/key-hold.cjs.map +1 -0
- package/dist/controllers/key-hold.d.cts +62 -0
- package/dist/controllers/key-hold.d.ts +62 -0
- package/dist/controllers/key-hold.js +78 -0
- package/dist/controllers/key-hold.js.map +1 -0
- package/dist/decorators/hotkey-sequence.cjs +45 -0
- package/dist/decorators/hotkey-sequence.cjs.map +1 -0
- package/dist/decorators/hotkey-sequence.d.cts +28 -0
- package/dist/decorators/hotkey-sequence.d.ts +28 -0
- package/dist/decorators/hotkey-sequence.js +45 -0
- package/dist/decorators/hotkey-sequence.js.map +1 -0
- package/dist/decorators/hotkey.cjs +44 -0
- package/dist/decorators/hotkey.cjs.map +1 -0
- package/dist/decorators/hotkey.d.cts +27 -0
- package/dist/decorators/hotkey.d.ts +27 -0
- package/dist/decorators/hotkey.js +44 -0
- package/dist/decorators/hotkey.js.map +1 -0
- package/dist/decorators/index.d.cts +2 -0
- package/dist/decorators/index.d.ts +2 -0
- package/dist/index.cjs +27 -0
- package/dist/index.d.cts +11 -0
- package/dist/index.d.ts +11 -0
- package/dist/index.js +13 -0
- package/package.json +60 -0
- package/src/constants.ts +23 -0
- package/src/controllers/held-key-codes.ts +67 -0
- package/src/controllers/held-keys.ts +64 -0
- package/src/controllers/hotkey-recorder.ts +120 -0
- package/src/controllers/hotkey-sequence-recorder.ts +141 -0
- package/src/controllers/hotkey-sequence.ts +82 -0
- package/src/controllers/hotkey.ts +96 -0
- package/src/controllers/index.ts +7 -0
- package/src/controllers/key-hold.ts +88 -0
- package/src/decorators/hotkey-sequence.ts +68 -0
- package/src/decorators/hotkey.ts +70 -0
- package/src/decorators/index.ts +2 -0
- package/src/index.ts +6 -0
package/README.md
ADDED
|
@@ -0,0 +1,123 @@
|
|
|
1
|
+
<div align="center">
|
|
2
|
+
<img src="./media/header_hotkeys.png" alt="TanStack Hotkeys" />
|
|
3
|
+
</div>
|
|
4
|
+
|
|
5
|
+
<br />
|
|
6
|
+
|
|
7
|
+
<div align="center">
|
|
8
|
+
<a href="https://www.npmjs.com/package/@tanstack/hotkeys" target="\_parent">
|
|
9
|
+
<img alt="" src="https://img.shields.io/npm/dm/@tanstack/hotkeys.svg" alt="npm downloads" />
|
|
10
|
+
</a>
|
|
11
|
+
<a href="https://github.com/TanStack/hotkeys" target="\_parent">
|
|
12
|
+
<img alt="" src="https://img.shields.io/github/stars/TanStack/hotkeys.svg?style=social&label=Star" alt="GitHub stars" />
|
|
13
|
+
</a>
|
|
14
|
+
<a href="https://bundlephobia.com/result?p=@tanstack/react-hotkeys@latest" target="\_parent">
|
|
15
|
+
<img alt="" src="https://badgen.net/bundlephobia/minzip/@tanstack/react-hotkeys@latest" alt="Bundle size" />
|
|
16
|
+
</a>
|
|
17
|
+
</div>
|
|
18
|
+
|
|
19
|
+
<div align="center">
|
|
20
|
+
<a href="#badge">
|
|
21
|
+
<img alt="semantic-release" src="https://img.shields.io/badge/%20%20%F0%9F%93%A6%F0%9F%9A%80-semantic--release-e10079.svg">
|
|
22
|
+
</a>
|
|
23
|
+
<a href="#badge">
|
|
24
|
+
<img src="https://img.shields.io/github/v/release/tanstack/hotkeys" alt="Release"/>
|
|
25
|
+
</a>
|
|
26
|
+
<a href="https://twitter.com/tan_stack">
|
|
27
|
+
<img src="https://img.shields.io/twitter/follow/tan_stack.svg?style=social" alt="Follow @TanStack"/>
|
|
28
|
+
</a>
|
|
29
|
+
</div>
|
|
30
|
+
|
|
31
|
+
<div align="center">
|
|
32
|
+
|
|
33
|
+
### [Become a Sponsor!](https://github.com/sponsors/tannerlinsley/)
|
|
34
|
+
|
|
35
|
+
</div>
|
|
36
|
+
|
|
37
|
+
# TanStack Hotkeys
|
|
38
|
+
|
|
39
|
+
> [!NOTE]
|
|
40
|
+
> TanStack Hotkeys is alpha. We are actively developing the library and are open to feedback and contributions.
|
|
41
|
+
|
|
42
|
+
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.
|
|
43
|
+
|
|
44
|
+
- Type-safe bindings — template strings (`Mod+Shift+S`, `Escape`) or parsed objects for full control
|
|
45
|
+
- Flexible options — `keydown`/`keyup`, `preventDefault`, `stopPropagation`, conditional enabled, `requireReset`
|
|
46
|
+
- Cross-platform Mod — maps to Cmd on macOS and Ctrl on Windows/Linux
|
|
47
|
+
- Batteries included — validation + matching, sequences (Vim-style), key-state tracking, recorder UI helpers, framework adapters, and devtools
|
|
48
|
+
|
|
49
|
+
### <a href="https://tanstack.com/hotkeys">Read the docs →</a>
|
|
50
|
+
|
|
51
|
+
<br />
|
|
52
|
+
|
|
53
|
+
> [!NOTE]
|
|
54
|
+
> You may know **TanStack Hotkeys** by our adapter names, too!
|
|
55
|
+
>
|
|
56
|
+
> - [**React Hotkeys**](https://tanstack.com/hotkeys/latest/docs/framework/react/react-hotkeys)
|
|
57
|
+
> - [**Preact Hotkeys**](https://tanstack.com/hotkeys/latest/docs/framework/preact/preact-hotkeys)
|
|
58
|
+
> - [**Solid Hotkeys**](https://tanstack.com/hotkeys/latest/docs/framework/solid/reference)
|
|
59
|
+
> - [**Angular Hotkeys**](https://tanstack.com/hotkeys/latest/docs/framework/angular/reference)
|
|
60
|
+
> - [**Vue Hotkeys**](https://tanstack.com/hotkeys/latest/docs/framework/vue/reference)
|
|
61
|
+
> - [**Lit Hotkeys**](https://tanstack.com/hotkeys/latest/docs/framework/lit/reference)
|
|
62
|
+
> - [**Svelte Hotkeys**](https://tanstack.com/hotkeys/latest/docs/framework/svelte/reference)
|
|
63
|
+
|
|
64
|
+
## Get Involved
|
|
65
|
+
|
|
66
|
+
- We welcome issues and pull requests!
|
|
67
|
+
- Participate in [GitHub discussions](https://github.com/TanStack/hotkeys/discussions)
|
|
68
|
+
- Chat with the community on [Discord](https://discord.com/invite/WrRKjPJ)
|
|
69
|
+
- See [CONTRIBUTING.md](./CONTRIBUTING.md) for setup instructions
|
|
70
|
+
|
|
71
|
+
## Partners
|
|
72
|
+
|
|
73
|
+
<div align="center">
|
|
74
|
+
|
|
75
|
+
<table align="center">
|
|
76
|
+
<tr>
|
|
77
|
+
<td>
|
|
78
|
+
<a href="https://www.coderabbit.ai/?via=tanstack&dub_id=aCcEEdAOqqutX6OS" >
|
|
79
|
+
<picture>
|
|
80
|
+
<source media="(prefers-color-scheme: dark)" srcset="https://tanstack.com/assets/coderabbit-dark-D643Zkrv.svg" height="40" />
|
|
81
|
+
<source media="(prefers-color-scheme: light)" srcset="https://tanstack.com/assets/coderabbit-light-CIzGLYU_.svg" height="40" />
|
|
82
|
+
<img src="https://tanstack.com/assets/coderabbit-light-DVMJ2jHi.svg" height="40" alt="CodeRabbit" />
|
|
83
|
+
</picture>
|
|
84
|
+
</a>
|
|
85
|
+
</td>
|
|
86
|
+
<td>
|
|
87
|
+
<a href="https://www.cloudflare.com?utm_source=tanstack">
|
|
88
|
+
<picture>
|
|
89
|
+
<source media="(prefers-color-scheme: dark)" srcset="https://tanstack.com/assets/cloudflare-white-Co-Tyjbl.svg" height="60" />
|
|
90
|
+
<source media="(prefers-color-scheme: light)" srcset="https://tanstack.com/assets/cloudflare-black-6Ojsn8yh.svg" height="60" />
|
|
91
|
+
<img src="https://tanstack.com/assets/cloudflare-black-CPufaW0B.svg" height="60" alt="Cloudflare" />
|
|
92
|
+
</picture>
|
|
93
|
+
</a>
|
|
94
|
+
</td>
|
|
95
|
+
</tr>
|
|
96
|
+
</table>
|
|
97
|
+
|
|
98
|
+
<div align="center">
|
|
99
|
+
<img src="media/partner_logo.svg" alt="Keys & you?" height="65">
|
|
100
|
+
<p>
|
|
101
|
+
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.
|
|
102
|
+
</p>
|
|
103
|
+
<a href="mailto:partners@tanstack.com?subject=TanStack Hotkeys Partnership"><b>LET'S CHAT</b></a>
|
|
104
|
+
</div>
|
|
105
|
+
|
|
106
|
+
</div>
|
|
107
|
+
|
|
108
|
+
## Explore the TanStack Ecosystem
|
|
109
|
+
|
|
110
|
+
- <a href="https://github.com/tanstack/config"><b>TanStack Config</b></a> – Tooling for JS/TS packages
|
|
111
|
+
- <a href="https://github.com/tanstack/db"><b>TanStack DB</b></a> – Reactive sync client store
|
|
112
|
+
- <a href="https://github.com/tanstack/devtools"><b>TanStack DevTools</b></a> – Unified devtools panel
|
|
113
|
+
- <a href="https://github.com/tanstack/form"><b>TanStack Form</b></a> – Type‑safe form state
|
|
114
|
+
- <a href="https://github.com/tanstack/hotkeys"><b>TanStack Hotkeys</b></a> – Type‑safe keyboard shortcuts
|
|
115
|
+
- <a href="https://github.com/tanstack/query"><b>TanStack Query</b></a> – Async state & caching
|
|
116
|
+
- <a href="https://github.com/tanstack/ranger"><b>TanStack Ranger</b></a> – Range & slider primitives
|
|
117
|
+
- <a href="https://github.com/tanstack/router"><b>TanStack Router</b></a> – Type‑safe routing, caching & URL state
|
|
118
|
+
- <a href="https://github.com/tanstack/start"><b>TanStack Start</b></a> – Full‑stack SSR & streaming
|
|
119
|
+
- <a href="https://github.com/tanstack/store"><b>TanStack Store</b></a> – Reactive data store
|
|
120
|
+
- <a href="https://github.com/tanstack/table"><b>TanStack Table</b></a> – Headless datagrids
|
|
121
|
+
- <a href="https://github.com/tanstack/virtual"><b>TanStack Virtual</b></a> – Virtualized rendering
|
|
122
|
+
|
|
123
|
+
… and more at <a href="https://tanstack.com"><b>TanStack.com »</b></a>
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
|
|
2
|
+
//#region src/constants.ts
|
|
3
|
+
const HOTKEY_DEFAULT_OPTIONS = {
|
|
4
|
+
enabled: true,
|
|
5
|
+
preventDefault: true,
|
|
6
|
+
stopPropagation: true,
|
|
7
|
+
eventType: "keydown",
|
|
8
|
+
requireReset: false,
|
|
9
|
+
ignoreInputs: void 0,
|
|
10
|
+
platform: void 0,
|
|
11
|
+
conflictBehavior: "warn"
|
|
12
|
+
};
|
|
13
|
+
const HOTKEY_SEQUENCE_DEFAULT_OPTIONS = {
|
|
14
|
+
enabled: true,
|
|
15
|
+
timeout: 1e3,
|
|
16
|
+
preventDefault: true,
|
|
17
|
+
stopPropagation: true,
|
|
18
|
+
eventType: "keydown",
|
|
19
|
+
ignoreInputs: void 0,
|
|
20
|
+
platform: void 0,
|
|
21
|
+
conflictBehavior: "warn"
|
|
22
|
+
};
|
|
23
|
+
|
|
24
|
+
//#endregion
|
|
25
|
+
exports.HOTKEY_DEFAULT_OPTIONS = HOTKEY_DEFAULT_OPTIONS;
|
|
26
|
+
exports.HOTKEY_SEQUENCE_DEFAULT_OPTIONS = HOTKEY_SEQUENCE_DEFAULT_OPTIONS;
|
|
27
|
+
//# sourceMappingURL=constants.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"constants.cjs","names":[],"sources":["../src/constants.ts"],"sourcesContent":["import type { HotkeyOptions, SequenceOptions } from '@tanstack/hotkeys'\n\nexport const HOTKEY_DEFAULT_OPTIONS: HotkeyOptions = {\n enabled: true,\n preventDefault: true,\n stopPropagation: true,\n eventType: 'keydown',\n requireReset: false,\n ignoreInputs: undefined, // smart default: false for Mod+S, true for single keys\n platform: undefined, // auto-detected\n conflictBehavior: 'warn',\n}\n\nexport const HOTKEY_SEQUENCE_DEFAULT_OPTIONS: SequenceOptions = {\n enabled: true,\n timeout: 1000,\n preventDefault: true,\n stopPropagation: true,\n eventType: 'keydown',\n ignoreInputs: undefined, // smart default: false for Mod+S, true for single keys\n platform: undefined, // auto-detected\n conflictBehavior: 'warn',\n}\n"],"mappings":";;AAEA,MAAa,yBAAwC;CACnD,SAAS;CACT,gBAAgB;CAChB,iBAAiB;CACjB,WAAW;CACX,cAAc;CACd,cAAc;CACd,UAAU;CACV,kBAAkB;CACnB;AAED,MAAa,kCAAmD;CAC9D,SAAS;CACT,SAAS;CACT,gBAAgB;CAChB,iBAAiB;CACjB,WAAW;CACX,cAAc;CACd,UAAU;CACV,kBAAkB;CACnB"}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
//#region src/constants.ts
|
|
2
|
+
const HOTKEY_DEFAULT_OPTIONS = {
|
|
3
|
+
enabled: true,
|
|
4
|
+
preventDefault: true,
|
|
5
|
+
stopPropagation: true,
|
|
6
|
+
eventType: "keydown",
|
|
7
|
+
requireReset: false,
|
|
8
|
+
ignoreInputs: void 0,
|
|
9
|
+
platform: void 0,
|
|
10
|
+
conflictBehavior: "warn"
|
|
11
|
+
};
|
|
12
|
+
const HOTKEY_SEQUENCE_DEFAULT_OPTIONS = {
|
|
13
|
+
enabled: true,
|
|
14
|
+
timeout: 1e3,
|
|
15
|
+
preventDefault: true,
|
|
16
|
+
stopPropagation: true,
|
|
17
|
+
eventType: "keydown",
|
|
18
|
+
ignoreInputs: void 0,
|
|
19
|
+
platform: void 0,
|
|
20
|
+
conflictBehavior: "warn"
|
|
21
|
+
};
|
|
22
|
+
|
|
23
|
+
//#endregion
|
|
24
|
+
export { HOTKEY_DEFAULT_OPTIONS, HOTKEY_SEQUENCE_DEFAULT_OPTIONS };
|
|
25
|
+
//# sourceMappingURL=constants.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"constants.js","names":[],"sources":["../src/constants.ts"],"sourcesContent":["import type { HotkeyOptions, SequenceOptions } from '@tanstack/hotkeys'\n\nexport const HOTKEY_DEFAULT_OPTIONS: HotkeyOptions = {\n enabled: true,\n preventDefault: true,\n stopPropagation: true,\n eventType: 'keydown',\n requireReset: false,\n ignoreInputs: undefined, // smart default: false for Mod+S, true for single keys\n platform: undefined, // auto-detected\n conflictBehavior: 'warn',\n}\n\nexport const HOTKEY_SEQUENCE_DEFAULT_OPTIONS: SequenceOptions = {\n enabled: true,\n timeout: 1000,\n preventDefault: true,\n stopPropagation: true,\n eventType: 'keydown',\n ignoreInputs: undefined, // smart default: false for Mod+S, true for single keys\n platform: undefined, // auto-detected\n conflictBehavior: 'warn',\n}\n"],"mappings":";AAEA,MAAa,yBAAwC;CACnD,SAAS;CACT,gBAAgB;CAChB,iBAAiB;CACjB,WAAW;CACX,cAAc;CACd,cAAc;CACd,UAAU;CACV,kBAAkB;CACnB;AAED,MAAa,kCAAmD;CAC9D,SAAS;CACT,SAAS;CACT,gBAAgB;CAChB,iBAAiB;CACjB,WAAW;CACX,cAAc;CACd,UAAU;CACV,kBAAkB;CACnB"}
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
let _tanstack_hotkeys = require("@tanstack/hotkeys");
|
|
2
|
+
|
|
3
|
+
//#region src/controllers/held-key-codes.ts
|
|
4
|
+
/**
|
|
5
|
+
* A Lit ReactiveController that tracks all currently held key names to their physical `event.code` values.
|
|
6
|
+
*
|
|
7
|
+
* Subscribes to the global KeyStateTracker and triggers host updates
|
|
8
|
+
* whenever keys are pressed or released.
|
|
9
|
+
*
|
|
10
|
+
* @example
|
|
11
|
+
* ```ts
|
|
12
|
+
* class KeyDisplay extends LitElement {
|
|
13
|
+
* private heldKeyCodes = new HeldKeyCodesController(this)
|
|
14
|
+
*
|
|
15
|
+
* render() {
|
|
16
|
+
* const heldCodes = Object.entries(this.heldKeyCodes.value).map(([key, code]) => `${key}: ${code}`).join(' + ')
|
|
17
|
+
* return html`
|
|
18
|
+
* <div>
|
|
19
|
+
* Currently pressed: ${heldCodes || 'None'}
|
|
20
|
+
* </div>
|
|
21
|
+
* `
|
|
22
|
+
* }
|
|
23
|
+
* }
|
|
24
|
+
* ```
|
|
25
|
+
*/
|
|
26
|
+
var HeldKeyCodesController = class {
|
|
27
|
+
/** Map of currently held key names to their physical `event.code` values. */
|
|
28
|
+
get value() {
|
|
29
|
+
return this._value;
|
|
30
|
+
}
|
|
31
|
+
/**
|
|
32
|
+
* @param _host - The Lit component that owns this controller.
|
|
33
|
+
*/
|
|
34
|
+
constructor(_host) {
|
|
35
|
+
this._host = _host;
|
|
36
|
+
this._value = {};
|
|
37
|
+
this._host.addController(this);
|
|
38
|
+
}
|
|
39
|
+
/** Subscribes to the tracker store and updates the internal state when changes occur. */
|
|
40
|
+
hostConnected() {
|
|
41
|
+
const tracker = (0, _tanstack_hotkeys.getKeyStateTracker)();
|
|
42
|
+
this._value = tracker.store.state.heldCodes;
|
|
43
|
+
this._host.requestUpdate();
|
|
44
|
+
const subscription = tracker.store.subscribe(() => {
|
|
45
|
+
const { heldCodes } = tracker.store.state;
|
|
46
|
+
this._value = heldCodes;
|
|
47
|
+
this._host.requestUpdate();
|
|
48
|
+
});
|
|
49
|
+
this._unsubscribe = () => subscription.unsubscribe();
|
|
50
|
+
}
|
|
51
|
+
/** Unsubscribes from the tracker store and stops tracking the held key codes. */
|
|
52
|
+
hostDisconnected() {
|
|
53
|
+
this._unsubscribe?.();
|
|
54
|
+
this._unsubscribe = void 0;
|
|
55
|
+
this._value = {};
|
|
56
|
+
}
|
|
57
|
+
};
|
|
58
|
+
|
|
59
|
+
//#endregion
|
|
60
|
+
exports.HeldKeyCodesController = HeldKeyCodesController;
|
|
61
|
+
//# sourceMappingURL=held-key-codes.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"held-key-codes.cjs","names":[],"sources":["../../src/controllers/held-key-codes.ts"],"sourcesContent":["import { getKeyStateTracker } from '@tanstack/hotkeys'\nimport type { KeyStateTracker } from '@tanstack/hotkeys'\nimport type { ReactiveController, ReactiveControllerHost } from 'lit'\n\n/**\n * A Lit ReactiveController that tracks all currently held key names to their physical `event.code` values.\n *\n * Subscribes to the global KeyStateTracker and triggers host updates\n * whenever keys are pressed or released.\n *\n * @example\n * ```ts\n * class KeyDisplay extends LitElement {\n * private heldKeyCodes = new HeldKeyCodesController(this)\n *\n * render() {\n * const heldCodes = Object.entries(this.heldKeyCodes.value).map(([key, code]) => `${key}: ${code}`).join(' + ')\n * return html`\n * <div>\n * Currently pressed: ${heldCodes || 'None'}\n * </div>\n * `\n * }\n * }\n * ```\n */\nexport class HeldKeyCodesController implements ReactiveController {\n /** The unsubscribe function to unsubscribe from the tracker store. */\n private _unsubscribe: (() => void) | undefined\n /** The currently held key names to their physical `event.code` values. */\n private _value: Record<string, string> = {}\n\n /** Map of currently held key names to their physical `event.code` values. */\n public get value(): Record<string, string> {\n return this._value\n }\n\n /**\n * @param _host - The Lit component that owns this controller.\n */\n constructor(private _host: ReactiveControllerHost) {\n this._host.addController(this)\n }\n\n /** Subscribes to the tracker store and updates the internal state when changes occur. */\n public hostConnected(): void {\n const tracker: KeyStateTracker = getKeyStateTracker()\n this._value = tracker.store.state.heldCodes\n this._host.requestUpdate()\n\n const subscription = tracker.store.subscribe(() => {\n const { heldCodes } = tracker.store.state\n\n this._value = heldCodes\n this._host.requestUpdate()\n })\n\n this._unsubscribe = () => subscription.unsubscribe()\n }\n\n /** Unsubscribes from the tracker store and stops tracking the held key codes. */\n public hostDisconnected(): void {\n this._unsubscribe?.()\n this._unsubscribe = undefined\n this._value = {}\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;AA0BA,IAAa,yBAAb,MAAkE;;CAOhE,IAAW,QAAgC;AACzC,SAAO,KAAK;;;;;CAMd,YAAY,AAAQ,OAA+B;EAA/B;gBAVqB,EAAE;AAWzC,OAAK,MAAM,cAAc,KAAK;;;CAIhC,AAAO,gBAAsB;EAC3B,MAAM,qDAA+C;AACrD,OAAK,SAAS,QAAQ,MAAM,MAAM;AAClC,OAAK,MAAM,eAAe;EAE1B,MAAM,eAAe,QAAQ,MAAM,gBAAgB;GACjD,MAAM,EAAE,cAAc,QAAQ,MAAM;AAEpC,QAAK,SAAS;AACd,QAAK,MAAM,eAAe;IAC1B;AAEF,OAAK,qBAAqB,aAAa,aAAa;;;CAItD,AAAO,mBAAyB;AAC9B,OAAK,gBAAgB;AACrB,OAAK,eAAe;AACpB,OAAK,SAAS,EAAE"}
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import { ReactiveController, ReactiveControllerHost } from "lit";
|
|
2
|
+
|
|
3
|
+
//#region src/controllers/held-key-codes.d.ts
|
|
4
|
+
/**
|
|
5
|
+
* A Lit ReactiveController that tracks all currently held key names to their physical `event.code` values.
|
|
6
|
+
*
|
|
7
|
+
* Subscribes to the global KeyStateTracker and triggers host updates
|
|
8
|
+
* whenever keys are pressed or released.
|
|
9
|
+
*
|
|
10
|
+
* @example
|
|
11
|
+
* ```ts
|
|
12
|
+
* class KeyDisplay extends LitElement {
|
|
13
|
+
* private heldKeyCodes = new HeldKeyCodesController(this)
|
|
14
|
+
*
|
|
15
|
+
* render() {
|
|
16
|
+
* const heldCodes = Object.entries(this.heldKeyCodes.value).map(([key, code]) => `${key}: ${code}`).join(' + ')
|
|
17
|
+
* return html`
|
|
18
|
+
* <div>
|
|
19
|
+
* Currently pressed: ${heldCodes || 'None'}
|
|
20
|
+
* </div>
|
|
21
|
+
* `
|
|
22
|
+
* }
|
|
23
|
+
* }
|
|
24
|
+
* ```
|
|
25
|
+
*/
|
|
26
|
+
declare class HeldKeyCodesController implements ReactiveController {
|
|
27
|
+
private _host;
|
|
28
|
+
/** The unsubscribe function to unsubscribe from the tracker store. */
|
|
29
|
+
private _unsubscribe;
|
|
30
|
+
/** The currently held key names to their physical `event.code` values. */
|
|
31
|
+
private _value;
|
|
32
|
+
/** Map of currently held key names to their physical `event.code` values. */
|
|
33
|
+
get value(): Record<string, string>;
|
|
34
|
+
/**
|
|
35
|
+
* @param _host - The Lit component that owns this controller.
|
|
36
|
+
*/
|
|
37
|
+
constructor(_host: ReactiveControllerHost);
|
|
38
|
+
/** Subscribes to the tracker store and updates the internal state when changes occur. */
|
|
39
|
+
hostConnected(): void;
|
|
40
|
+
/** Unsubscribes from the tracker store and stops tracking the held key codes. */
|
|
41
|
+
hostDisconnected(): void;
|
|
42
|
+
}
|
|
43
|
+
//#endregion
|
|
44
|
+
export { HeldKeyCodesController };
|
|
45
|
+
//# sourceMappingURL=held-key-codes.d.cts.map
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import { ReactiveController, ReactiveControllerHost } from "lit";
|
|
2
|
+
|
|
3
|
+
//#region src/controllers/held-key-codes.d.ts
|
|
4
|
+
/**
|
|
5
|
+
* A Lit ReactiveController that tracks all currently held key names to their physical `event.code` values.
|
|
6
|
+
*
|
|
7
|
+
* Subscribes to the global KeyStateTracker and triggers host updates
|
|
8
|
+
* whenever keys are pressed or released.
|
|
9
|
+
*
|
|
10
|
+
* @example
|
|
11
|
+
* ```ts
|
|
12
|
+
* class KeyDisplay extends LitElement {
|
|
13
|
+
* private heldKeyCodes = new HeldKeyCodesController(this)
|
|
14
|
+
*
|
|
15
|
+
* render() {
|
|
16
|
+
* const heldCodes = Object.entries(this.heldKeyCodes.value).map(([key, code]) => `${key}: ${code}`).join(' + ')
|
|
17
|
+
* return html`
|
|
18
|
+
* <div>
|
|
19
|
+
* Currently pressed: ${heldCodes || 'None'}
|
|
20
|
+
* </div>
|
|
21
|
+
* `
|
|
22
|
+
* }
|
|
23
|
+
* }
|
|
24
|
+
* ```
|
|
25
|
+
*/
|
|
26
|
+
declare class HeldKeyCodesController implements ReactiveController {
|
|
27
|
+
private _host;
|
|
28
|
+
/** The unsubscribe function to unsubscribe from the tracker store. */
|
|
29
|
+
private _unsubscribe;
|
|
30
|
+
/** The currently held key names to their physical `event.code` values. */
|
|
31
|
+
private _value;
|
|
32
|
+
/** Map of currently held key names to their physical `event.code` values. */
|
|
33
|
+
get value(): Record<string, string>;
|
|
34
|
+
/**
|
|
35
|
+
* @param _host - The Lit component that owns this controller.
|
|
36
|
+
*/
|
|
37
|
+
constructor(_host: ReactiveControllerHost);
|
|
38
|
+
/** Subscribes to the tracker store and updates the internal state when changes occur. */
|
|
39
|
+
hostConnected(): void;
|
|
40
|
+
/** Unsubscribes from the tracker store and stops tracking the held key codes. */
|
|
41
|
+
hostDisconnected(): void;
|
|
42
|
+
}
|
|
43
|
+
//#endregion
|
|
44
|
+
export { HeldKeyCodesController };
|
|
45
|
+
//# sourceMappingURL=held-key-codes.d.ts.map
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
import { getKeyStateTracker } from "@tanstack/hotkeys";
|
|
2
|
+
|
|
3
|
+
//#region src/controllers/held-key-codes.ts
|
|
4
|
+
/**
|
|
5
|
+
* A Lit ReactiveController that tracks all currently held key names to their physical `event.code` values.
|
|
6
|
+
*
|
|
7
|
+
* Subscribes to the global KeyStateTracker and triggers host updates
|
|
8
|
+
* whenever keys are pressed or released.
|
|
9
|
+
*
|
|
10
|
+
* @example
|
|
11
|
+
* ```ts
|
|
12
|
+
* class KeyDisplay extends LitElement {
|
|
13
|
+
* private heldKeyCodes = new HeldKeyCodesController(this)
|
|
14
|
+
*
|
|
15
|
+
* render() {
|
|
16
|
+
* const heldCodes = Object.entries(this.heldKeyCodes.value).map(([key, code]) => `${key}: ${code}`).join(' + ')
|
|
17
|
+
* return html`
|
|
18
|
+
* <div>
|
|
19
|
+
* Currently pressed: ${heldCodes || 'None'}
|
|
20
|
+
* </div>
|
|
21
|
+
* `
|
|
22
|
+
* }
|
|
23
|
+
* }
|
|
24
|
+
* ```
|
|
25
|
+
*/
|
|
26
|
+
var HeldKeyCodesController = class {
|
|
27
|
+
/** Map of currently held key names to their physical `event.code` values. */
|
|
28
|
+
get value() {
|
|
29
|
+
return this._value;
|
|
30
|
+
}
|
|
31
|
+
/**
|
|
32
|
+
* @param _host - The Lit component that owns this controller.
|
|
33
|
+
*/
|
|
34
|
+
constructor(_host) {
|
|
35
|
+
this._host = _host;
|
|
36
|
+
this._value = {};
|
|
37
|
+
this._host.addController(this);
|
|
38
|
+
}
|
|
39
|
+
/** Subscribes to the tracker store and updates the internal state when changes occur. */
|
|
40
|
+
hostConnected() {
|
|
41
|
+
const tracker = getKeyStateTracker();
|
|
42
|
+
this._value = tracker.store.state.heldCodes;
|
|
43
|
+
this._host.requestUpdate();
|
|
44
|
+
const subscription = tracker.store.subscribe(() => {
|
|
45
|
+
const { heldCodes } = tracker.store.state;
|
|
46
|
+
this._value = heldCodes;
|
|
47
|
+
this._host.requestUpdate();
|
|
48
|
+
});
|
|
49
|
+
this._unsubscribe = () => subscription.unsubscribe();
|
|
50
|
+
}
|
|
51
|
+
/** Unsubscribes from the tracker store and stops tracking the held key codes. */
|
|
52
|
+
hostDisconnected() {
|
|
53
|
+
this._unsubscribe?.();
|
|
54
|
+
this._unsubscribe = void 0;
|
|
55
|
+
this._value = {};
|
|
56
|
+
}
|
|
57
|
+
};
|
|
58
|
+
|
|
59
|
+
//#endregion
|
|
60
|
+
export { HeldKeyCodesController };
|
|
61
|
+
//# sourceMappingURL=held-key-codes.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"held-key-codes.js","names":[],"sources":["../../src/controllers/held-key-codes.ts"],"sourcesContent":["import { getKeyStateTracker } from '@tanstack/hotkeys'\nimport type { KeyStateTracker } from '@tanstack/hotkeys'\nimport type { ReactiveController, ReactiveControllerHost } from 'lit'\n\n/**\n * A Lit ReactiveController that tracks all currently held key names to their physical `event.code` values.\n *\n * Subscribes to the global KeyStateTracker and triggers host updates\n * whenever keys are pressed or released.\n *\n * @example\n * ```ts\n * class KeyDisplay extends LitElement {\n * private heldKeyCodes = new HeldKeyCodesController(this)\n *\n * render() {\n * const heldCodes = Object.entries(this.heldKeyCodes.value).map(([key, code]) => `${key}: ${code}`).join(' + ')\n * return html`\n * <div>\n * Currently pressed: ${heldCodes || 'None'}\n * </div>\n * `\n * }\n * }\n * ```\n */\nexport class HeldKeyCodesController implements ReactiveController {\n /** The unsubscribe function to unsubscribe from the tracker store. */\n private _unsubscribe: (() => void) | undefined\n /** The currently held key names to their physical `event.code` values. */\n private _value: Record<string, string> = {}\n\n /** Map of currently held key names to their physical `event.code` values. */\n public get value(): Record<string, string> {\n return this._value\n }\n\n /**\n * @param _host - The Lit component that owns this controller.\n */\n constructor(private _host: ReactiveControllerHost) {\n this._host.addController(this)\n }\n\n /** Subscribes to the tracker store and updates the internal state when changes occur. */\n public hostConnected(): void {\n const tracker: KeyStateTracker = getKeyStateTracker()\n this._value = tracker.store.state.heldCodes\n this._host.requestUpdate()\n\n const subscription = tracker.store.subscribe(() => {\n const { heldCodes } = tracker.store.state\n\n this._value = heldCodes\n this._host.requestUpdate()\n })\n\n this._unsubscribe = () => subscription.unsubscribe()\n }\n\n /** Unsubscribes from the tracker store and stops tracking the held key codes. */\n public hostDisconnected(): void {\n this._unsubscribe?.()\n this._unsubscribe = undefined\n this._value = {}\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;AA0BA,IAAa,yBAAb,MAAkE;;CAOhE,IAAW,QAAgC;AACzC,SAAO,KAAK;;;;;CAMd,YAAY,AAAQ,OAA+B;EAA/B;gBAVqB,EAAE;AAWzC,OAAK,MAAM,cAAc,KAAK;;;CAIhC,AAAO,gBAAsB;EAC3B,MAAM,UAA2B,oBAAoB;AACrD,OAAK,SAAS,QAAQ,MAAM,MAAM;AAClC,OAAK,MAAM,eAAe;EAE1B,MAAM,eAAe,QAAQ,MAAM,gBAAgB;GACjD,MAAM,EAAE,cAAc,QAAQ,MAAM;AAEpC,QAAK,SAAS;AACd,QAAK,MAAM,eAAe;IAC1B;AAEF,OAAK,qBAAqB,aAAa,aAAa;;;CAItD,AAAO,mBAAyB;AAC9B,OAAK,gBAAgB;AACrB,OAAK,eAAe;AACpB,OAAK,SAAS,EAAE"}
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
let _tanstack_hotkeys = require("@tanstack/hotkeys");
|
|
2
|
+
|
|
3
|
+
//#region src/controllers/held-keys.ts
|
|
4
|
+
/**
|
|
5
|
+
* A Lit ReactiveController that tracks all currently held keyboard keys.
|
|
6
|
+
*
|
|
7
|
+
* Subscribes to the global KeyStateTracker and triggers host updates
|
|
8
|
+
* whenever keys are pressed or released.
|
|
9
|
+
*
|
|
10
|
+
* @example
|
|
11
|
+
* ```ts
|
|
12
|
+
* class KeyDisplay extends LitElement {
|
|
13
|
+
* private heldKeys = new HeldKeysController(this)
|
|
14
|
+
*
|
|
15
|
+
* render() {
|
|
16
|
+
* return html`
|
|
17
|
+
* <div>
|
|
18
|
+
* Currently pressed: ${this.heldKeys.value.join(' + ') || 'None'}
|
|
19
|
+
* </div>
|
|
20
|
+
* `
|
|
21
|
+
* }
|
|
22
|
+
* }
|
|
23
|
+
* ```
|
|
24
|
+
*/
|
|
25
|
+
var HeldKeysController = class {
|
|
26
|
+
/** Array of currently held key names. */
|
|
27
|
+
get value() {
|
|
28
|
+
return this._value;
|
|
29
|
+
}
|
|
30
|
+
/**
|
|
31
|
+
* @param _host - The Lit component that owns this controller.
|
|
32
|
+
*/
|
|
33
|
+
constructor(_host) {
|
|
34
|
+
this._host = _host;
|
|
35
|
+
this._value = [];
|
|
36
|
+
this._host.addController(this);
|
|
37
|
+
}
|
|
38
|
+
/** Subscribes to the tracker store and updates the internal state when changes occur. */
|
|
39
|
+
hostConnected() {
|
|
40
|
+
const tracker = (0, _tanstack_hotkeys.getKeyStateTracker)();
|
|
41
|
+
const subscription = tracker.store.subscribe(() => {
|
|
42
|
+
const { heldKeys } = tracker.store.state;
|
|
43
|
+
this._value = heldKeys;
|
|
44
|
+
this._host.requestUpdate();
|
|
45
|
+
});
|
|
46
|
+
this._unsubscribe = () => subscription.unsubscribe();
|
|
47
|
+
}
|
|
48
|
+
/** Unsubscribes from the tracker store and stops tracking the held keys. */
|
|
49
|
+
hostDisconnected() {
|
|
50
|
+
this._unsubscribe?.();
|
|
51
|
+
this._unsubscribe = void 0;
|
|
52
|
+
this._value = [];
|
|
53
|
+
}
|
|
54
|
+
};
|
|
55
|
+
|
|
56
|
+
//#endregion
|
|
57
|
+
exports.HeldKeysController = HeldKeysController;
|
|
58
|
+
//# sourceMappingURL=held-keys.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"held-keys.cjs","names":[],"sources":["../../src/controllers/held-keys.ts"],"sourcesContent":["import { getKeyStateTracker } from '@tanstack/hotkeys'\nimport type { KeyStateTracker } from '@tanstack/hotkeys'\nimport type { ReactiveController, ReactiveControllerHost } from 'lit'\n\n/**\n * A Lit ReactiveController that tracks all currently held keyboard keys.\n *\n * Subscribes to the global KeyStateTracker and triggers host updates\n * whenever keys are pressed or released.\n *\n * @example\n * ```ts\n * class KeyDisplay extends LitElement {\n * private heldKeys = new HeldKeysController(this)\n *\n * render() {\n * return html`\n * <div>\n * Currently pressed: ${this.heldKeys.value.join(' + ') || 'None'}\n * </div>\n * `\n * }\n * }\n * ```\n */\nexport class HeldKeysController implements ReactiveController {\n /** The unsubscribe function to unsubscribe from the tracker store. */\n private _unsubscribe: (() => void) | undefined\n /** The currently held key names. */\n private _value: Array<string> = []\n\n /** Array of currently held key names. */\n public get value(): Array<string> {\n return this._value\n }\n\n /**\n * @param _host - The Lit component that owns this controller.\n */\n constructor(private _host: ReactiveControllerHost) {\n this._host.addController(this)\n }\n\n /** Subscribes to the tracker store and updates the internal state when changes occur. */\n public hostConnected(): void {\n const tracker: KeyStateTracker = getKeyStateTracker()\n\n const subscription = tracker.store.subscribe(() => {\n const { heldKeys } = tracker.store.state\n\n this._value = heldKeys\n this._host.requestUpdate()\n })\n\n this._unsubscribe = () => subscription.unsubscribe()\n }\n\n /** Unsubscribes from the tracker store and stops tracking the held keys. */\n public hostDisconnected(): void {\n this._unsubscribe?.()\n this._unsubscribe = undefined\n this._value = []\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;AAyBA,IAAa,qBAAb,MAA8D;;CAO5D,IAAW,QAAuB;AAChC,SAAO,KAAK;;;;;CAMd,YAAY,AAAQ,OAA+B;EAA/B;gBAVY,EAAE;AAWhC,OAAK,MAAM,cAAc,KAAK;;;CAIhC,AAAO,gBAAsB;EAC3B,MAAM,qDAA+C;EAErD,MAAM,eAAe,QAAQ,MAAM,gBAAgB;GACjD,MAAM,EAAE,aAAa,QAAQ,MAAM;AAEnC,QAAK,SAAS;AACd,QAAK,MAAM,eAAe;IAC1B;AAEF,OAAK,qBAAqB,aAAa,aAAa;;;CAItD,AAAO,mBAAyB;AAC9B,OAAK,gBAAgB;AACrB,OAAK,eAAe;AACpB,OAAK,SAAS,EAAE"}
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import { ReactiveController, ReactiveControllerHost } from "lit";
|
|
2
|
+
|
|
3
|
+
//#region src/controllers/held-keys.d.ts
|
|
4
|
+
/**
|
|
5
|
+
* A Lit ReactiveController that tracks all currently held keyboard keys.
|
|
6
|
+
*
|
|
7
|
+
* Subscribes to the global KeyStateTracker and triggers host updates
|
|
8
|
+
* whenever keys are pressed or released.
|
|
9
|
+
*
|
|
10
|
+
* @example
|
|
11
|
+
* ```ts
|
|
12
|
+
* class KeyDisplay extends LitElement {
|
|
13
|
+
* private heldKeys = new HeldKeysController(this)
|
|
14
|
+
*
|
|
15
|
+
* render() {
|
|
16
|
+
* return html`
|
|
17
|
+
* <div>
|
|
18
|
+
* Currently pressed: ${this.heldKeys.value.join(' + ') || 'None'}
|
|
19
|
+
* </div>
|
|
20
|
+
* `
|
|
21
|
+
* }
|
|
22
|
+
* }
|
|
23
|
+
* ```
|
|
24
|
+
*/
|
|
25
|
+
declare class HeldKeysController implements ReactiveController {
|
|
26
|
+
private _host;
|
|
27
|
+
/** The unsubscribe function to unsubscribe from the tracker store. */
|
|
28
|
+
private _unsubscribe;
|
|
29
|
+
/** The currently held key names. */
|
|
30
|
+
private _value;
|
|
31
|
+
/** Array of currently held key names. */
|
|
32
|
+
get value(): Array<string>;
|
|
33
|
+
/**
|
|
34
|
+
* @param _host - The Lit component that owns this controller.
|
|
35
|
+
*/
|
|
36
|
+
constructor(_host: ReactiveControllerHost);
|
|
37
|
+
/** Subscribes to the tracker store and updates the internal state when changes occur. */
|
|
38
|
+
hostConnected(): void;
|
|
39
|
+
/** Unsubscribes from the tracker store and stops tracking the held keys. */
|
|
40
|
+
hostDisconnected(): void;
|
|
41
|
+
}
|
|
42
|
+
//#endregion
|
|
43
|
+
export { HeldKeysController };
|
|
44
|
+
//# sourceMappingURL=held-keys.d.cts.map
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import { ReactiveController, ReactiveControllerHost } from "lit";
|
|
2
|
+
|
|
3
|
+
//#region src/controllers/held-keys.d.ts
|
|
4
|
+
/**
|
|
5
|
+
* A Lit ReactiveController that tracks all currently held keyboard keys.
|
|
6
|
+
*
|
|
7
|
+
* Subscribes to the global KeyStateTracker and triggers host updates
|
|
8
|
+
* whenever keys are pressed or released.
|
|
9
|
+
*
|
|
10
|
+
* @example
|
|
11
|
+
* ```ts
|
|
12
|
+
* class KeyDisplay extends LitElement {
|
|
13
|
+
* private heldKeys = new HeldKeysController(this)
|
|
14
|
+
*
|
|
15
|
+
* render() {
|
|
16
|
+
* return html`
|
|
17
|
+
* <div>
|
|
18
|
+
* Currently pressed: ${this.heldKeys.value.join(' + ') || 'None'}
|
|
19
|
+
* </div>
|
|
20
|
+
* `
|
|
21
|
+
* }
|
|
22
|
+
* }
|
|
23
|
+
* ```
|
|
24
|
+
*/
|
|
25
|
+
declare class HeldKeysController implements ReactiveController {
|
|
26
|
+
private _host;
|
|
27
|
+
/** The unsubscribe function to unsubscribe from the tracker store. */
|
|
28
|
+
private _unsubscribe;
|
|
29
|
+
/** The currently held key names. */
|
|
30
|
+
private _value;
|
|
31
|
+
/** Array of currently held key names. */
|
|
32
|
+
get value(): Array<string>;
|
|
33
|
+
/**
|
|
34
|
+
* @param _host - The Lit component that owns this controller.
|
|
35
|
+
*/
|
|
36
|
+
constructor(_host: ReactiveControllerHost);
|
|
37
|
+
/** Subscribes to the tracker store and updates the internal state when changes occur. */
|
|
38
|
+
hostConnected(): void;
|
|
39
|
+
/** Unsubscribes from the tracker store and stops tracking the held keys. */
|
|
40
|
+
hostDisconnected(): void;
|
|
41
|
+
}
|
|
42
|
+
//#endregion
|
|
43
|
+
export { HeldKeysController };
|
|
44
|
+
//# sourceMappingURL=held-keys.d.ts.map
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
import { getKeyStateTracker } from "@tanstack/hotkeys";
|
|
2
|
+
|
|
3
|
+
//#region src/controllers/held-keys.ts
|
|
4
|
+
/**
|
|
5
|
+
* A Lit ReactiveController that tracks all currently held keyboard keys.
|
|
6
|
+
*
|
|
7
|
+
* Subscribes to the global KeyStateTracker and triggers host updates
|
|
8
|
+
* whenever keys are pressed or released.
|
|
9
|
+
*
|
|
10
|
+
* @example
|
|
11
|
+
* ```ts
|
|
12
|
+
* class KeyDisplay extends LitElement {
|
|
13
|
+
* private heldKeys = new HeldKeysController(this)
|
|
14
|
+
*
|
|
15
|
+
* render() {
|
|
16
|
+
* return html`
|
|
17
|
+
* <div>
|
|
18
|
+
* Currently pressed: ${this.heldKeys.value.join(' + ') || 'None'}
|
|
19
|
+
* </div>
|
|
20
|
+
* `
|
|
21
|
+
* }
|
|
22
|
+
* }
|
|
23
|
+
* ```
|
|
24
|
+
*/
|
|
25
|
+
var HeldKeysController = class {
|
|
26
|
+
/** Array of currently held key names. */
|
|
27
|
+
get value() {
|
|
28
|
+
return this._value;
|
|
29
|
+
}
|
|
30
|
+
/**
|
|
31
|
+
* @param _host - The Lit component that owns this controller.
|
|
32
|
+
*/
|
|
33
|
+
constructor(_host) {
|
|
34
|
+
this._host = _host;
|
|
35
|
+
this._value = [];
|
|
36
|
+
this._host.addController(this);
|
|
37
|
+
}
|
|
38
|
+
/** Subscribes to the tracker store and updates the internal state when changes occur. */
|
|
39
|
+
hostConnected() {
|
|
40
|
+
const tracker = getKeyStateTracker();
|
|
41
|
+
const subscription = tracker.store.subscribe(() => {
|
|
42
|
+
const { heldKeys } = tracker.store.state;
|
|
43
|
+
this._value = heldKeys;
|
|
44
|
+
this._host.requestUpdate();
|
|
45
|
+
});
|
|
46
|
+
this._unsubscribe = () => subscription.unsubscribe();
|
|
47
|
+
}
|
|
48
|
+
/** Unsubscribes from the tracker store and stops tracking the held keys. */
|
|
49
|
+
hostDisconnected() {
|
|
50
|
+
this._unsubscribe?.();
|
|
51
|
+
this._unsubscribe = void 0;
|
|
52
|
+
this._value = [];
|
|
53
|
+
}
|
|
54
|
+
};
|
|
55
|
+
|
|
56
|
+
//#endregion
|
|
57
|
+
export { HeldKeysController };
|
|
58
|
+
//# sourceMappingURL=held-keys.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"held-keys.js","names":[],"sources":["../../src/controllers/held-keys.ts"],"sourcesContent":["import { getKeyStateTracker } from '@tanstack/hotkeys'\nimport type { KeyStateTracker } from '@tanstack/hotkeys'\nimport type { ReactiveController, ReactiveControllerHost } from 'lit'\n\n/**\n * A Lit ReactiveController that tracks all currently held keyboard keys.\n *\n * Subscribes to the global KeyStateTracker and triggers host updates\n * whenever keys are pressed or released.\n *\n * @example\n * ```ts\n * class KeyDisplay extends LitElement {\n * private heldKeys = new HeldKeysController(this)\n *\n * render() {\n * return html`\n * <div>\n * Currently pressed: ${this.heldKeys.value.join(' + ') || 'None'}\n * </div>\n * `\n * }\n * }\n * ```\n */\nexport class HeldKeysController implements ReactiveController {\n /** The unsubscribe function to unsubscribe from the tracker store. */\n private _unsubscribe: (() => void) | undefined\n /** The currently held key names. */\n private _value: Array<string> = []\n\n /** Array of currently held key names. */\n public get value(): Array<string> {\n return this._value\n }\n\n /**\n * @param _host - The Lit component that owns this controller.\n */\n constructor(private _host: ReactiveControllerHost) {\n this._host.addController(this)\n }\n\n /** Subscribes to the tracker store and updates the internal state when changes occur. */\n public hostConnected(): void {\n const tracker: KeyStateTracker = getKeyStateTracker()\n\n const subscription = tracker.store.subscribe(() => {\n const { heldKeys } = tracker.store.state\n\n this._value = heldKeys\n this._host.requestUpdate()\n })\n\n this._unsubscribe = () => subscription.unsubscribe()\n }\n\n /** Unsubscribes from the tracker store and stops tracking the held keys. */\n public hostDisconnected(): void {\n this._unsubscribe?.()\n this._unsubscribe = undefined\n this._value = []\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;AAyBA,IAAa,qBAAb,MAA8D;;CAO5D,IAAW,QAAuB;AAChC,SAAO,KAAK;;;;;CAMd,YAAY,AAAQ,OAA+B;EAA/B;gBAVY,EAAE;AAWhC,OAAK,MAAM,cAAc,KAAK;;;CAIhC,AAAO,gBAAsB;EAC3B,MAAM,UAA2B,oBAAoB;EAErD,MAAM,eAAe,QAAQ,MAAM,gBAAgB;GACjD,MAAM,EAAE,aAAa,QAAQ,MAAM;AAEnC,QAAK,SAAS;AACd,QAAK,MAAM,eAAe;IAC1B;AAEF,OAAK,qBAAqB,aAAa,aAAa;;;CAItD,AAAO,mBAAyB;AAC9B,OAAK,gBAAgB;AACrB,OAAK,eAAe;AACpB,OAAK,SAAS,EAAE"}
|