@tanstack/lit-hotkeys 0.22.3 → 0.24.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/controllers/app-hotkeys.d.ts +5 -0
- package/dist/controllers/app-hotkeys.js +8 -0
- package/dist/controllers/held-key-codes.d.ts +5 -0
- package/dist/controllers/held-key-codes.js +8 -0
- package/dist/controllers/held-keys.d.ts +5 -0
- package/dist/controllers/held-keys.js +8 -0
- package/dist/controllers/hotkey-hint.d.ts +5 -0
- package/dist/controllers/hotkey-hint.js +8 -0
- package/dist/controllers/hotkey-recorder.d.ts +8 -2
- package/dist/controllers/hotkey-recorder.js +11 -2
- package/dist/controllers/hotkey-registrations.d.ts +5 -0
- package/dist/controllers/hotkey-registrations.js +8 -0
- package/dist/controllers/hotkey-scopes-state.d.ts +5 -0
- package/dist/controllers/hotkey-scopes-state.js +8 -0
- package/dist/controllers/hotkey.d.ts +9 -1
- package/dist/controllers/hotkey.js +8 -0
- package/dist/controllers/key-hold.d.ts +5 -0
- package/dist/controllers/key-hold.js +9 -2
- package/dist/decorators/hotkey.d.ts +3 -1
- package/dist/decorators/hotkey.js +13 -1
- package/package.json +5 -3
- package/skills/lit-hotkeys/SKILL.md +3 -1
|
@@ -43,4 +43,9 @@ export declare class AppHotkeysController implements ReactiveController {
|
|
|
43
43
|
findConflicts(id: keyof RegisteredAppHotkeys & string, hotkey: Hotkey): Array<AppHotkey>;
|
|
44
44
|
hostConnected(): void;
|
|
45
45
|
hostDisconnected(): void;
|
|
46
|
+
/**
|
|
47
|
+
* Releases the controller now and removes it from its host. Use it to
|
|
48
|
+
* remove a controller early: Lit's `removeController` alone leaves it active.
|
|
49
|
+
*/
|
|
50
|
+
dispose(): void;
|
|
46
51
|
}
|
|
@@ -81,6 +81,14 @@ var AppHotkeysController = class {
|
|
|
81
81
|
this._unsubscribe?.();
|
|
82
82
|
this._unsubscribe = void 0;
|
|
83
83
|
}
|
|
84
|
+
/**
|
|
85
|
+
* Releases the controller now and removes it from its host. Use it to
|
|
86
|
+
* remove a controller early: Lit's `removeController` alone leaves it active.
|
|
87
|
+
*/
|
|
88
|
+
dispose() {
|
|
89
|
+
this.hostDisconnected();
|
|
90
|
+
this._host.removeController(this);
|
|
91
|
+
}
|
|
84
92
|
};
|
|
85
93
|
|
|
86
94
|
export { AppHotkeysController };
|
|
@@ -37,4 +37,9 @@ export declare class HeldKeyCodesController implements ReactiveController {
|
|
|
37
37
|
hostConnected(): void;
|
|
38
38
|
/** Unsubscribes from the tracker store and stops tracking the held key codes. */
|
|
39
39
|
hostDisconnected(): void;
|
|
40
|
+
/**
|
|
41
|
+
* Releases the controller now and removes it from its host. Use it to
|
|
42
|
+
* remove a controller early: Lit's `removeController` alone leaves it active.
|
|
43
|
+
*/
|
|
44
|
+
dispose(): void;
|
|
40
45
|
}
|
|
@@ -61,6 +61,14 @@ var HeldKeyCodesController = class {
|
|
|
61
61
|
this._unsubscribe = void 0;
|
|
62
62
|
this._value = {};
|
|
63
63
|
}
|
|
64
|
+
/**
|
|
65
|
+
* Releases the controller now and removes it from its host. Use it to
|
|
66
|
+
* remove a controller early: Lit's `removeController` alone leaves it active.
|
|
67
|
+
*/
|
|
68
|
+
dispose() {
|
|
69
|
+
this.hostDisconnected();
|
|
70
|
+
this._host.removeController(this);
|
|
71
|
+
}
|
|
64
72
|
};
|
|
65
73
|
|
|
66
74
|
export { HeldKeyCodesController };
|
|
@@ -36,4 +36,9 @@ export declare class HeldKeysController implements ReactiveController {
|
|
|
36
36
|
hostConnected(): void;
|
|
37
37
|
/** Unsubscribes from the tracker store and stops tracking the held keys. */
|
|
38
38
|
hostDisconnected(): void;
|
|
39
|
+
/**
|
|
40
|
+
* Releases the controller now and removes it from its host. Use it to
|
|
41
|
+
* remove a controller early: Lit's `removeController` alone leaves it active.
|
|
42
|
+
*/
|
|
43
|
+
dispose(): void;
|
|
39
44
|
}
|
|
@@ -60,6 +60,14 @@ var HeldKeysController = class {
|
|
|
60
60
|
this._unsubscribe = void 0;
|
|
61
61
|
this._value = [];
|
|
62
62
|
}
|
|
63
|
+
/**
|
|
64
|
+
* Releases the controller now and removes it from its host. Use it to
|
|
65
|
+
* remove a controller early: Lit's `removeController` alone leaves it active.
|
|
66
|
+
*/
|
|
67
|
+
dispose() {
|
|
68
|
+
this.hostDisconnected();
|
|
69
|
+
this._host.removeController(this);
|
|
70
|
+
}
|
|
63
71
|
};
|
|
64
72
|
|
|
65
73
|
export { HeldKeysController };
|
|
@@ -27,6 +27,11 @@ export declare class HotkeyHintController implements ReactiveController {
|
|
|
27
27
|
hostUpdate(): void;
|
|
28
28
|
/** Releases the subscription and clears cached visibility while disconnected. */
|
|
29
29
|
hostDisconnected(): void;
|
|
30
|
+
/**
|
|
31
|
+
* Releases the controller now and removes it from its host. Use it to
|
|
32
|
+
* remove a controller early: Lit's `removeController` alone leaves it active.
|
|
33
|
+
*/
|
|
34
|
+
dispose(): void;
|
|
30
35
|
/** Recomputes visibility and reports whether the host needs another render. */
|
|
31
36
|
private update;
|
|
32
37
|
}
|
|
@@ -59,6 +59,14 @@ var HotkeyHintController = class {
|
|
|
59
59
|
this.unsubscribe = void 0;
|
|
60
60
|
this.visible = false;
|
|
61
61
|
}
|
|
62
|
+
/**
|
|
63
|
+
* Releases the controller now and removes it from its host. Use it to
|
|
64
|
+
* remove a controller early: Lit's `removeController` alone leaves it active.
|
|
65
|
+
*/
|
|
66
|
+
dispose() {
|
|
67
|
+
this.hostDisconnected();
|
|
68
|
+
this.host.removeController(this);
|
|
69
|
+
}
|
|
62
70
|
/** Recomputes visibility and reports whether the host needs another render. */
|
|
63
71
|
update() {
|
|
64
72
|
const value = typeof this.hotkey === "function" ? this.hotkey() : this.hotkey;
|
|
@@ -6,8 +6,9 @@ import { ReactiveController, ReactiveControllerHost } from "lit";
|
|
|
6
6
|
* With the default `maxSteps: 1`, the first valid chord is recorded. With a
|
|
7
7
|
* larger `maxSteps`, each chord adds a step; the recording commits on Enter
|
|
8
8
|
* (unless `commitKeys: 'none'`), after `idleTimeoutMs`, or at `maxSteps`, and
|
|
9
|
-
* `onRecord` receives a chord (one step) or a sequence. Escape cancels
|
|
10
|
-
*
|
|
9
|
+
* `onRecord` receives a chord (one step) or a sequence. Escape cancels, and
|
|
10
|
+
* so do Tab and Shift+Tab unless `recordTab` is set; Backspace/Delete removes
|
|
11
|
+
* the last step or clears.
|
|
11
12
|
*
|
|
12
13
|
* @example
|
|
13
14
|
* ```ts
|
|
@@ -70,6 +71,11 @@ export declare class HotkeyRecorderController implements ReactiveController {
|
|
|
70
71
|
hostConnected(): void;
|
|
71
72
|
/** Unsubscribes from the recorder store and destroys the recorder instance to prevent memory leaks. */
|
|
72
73
|
hostDisconnected(): void;
|
|
74
|
+
/**
|
|
75
|
+
* Releases the controller now and removes it from its host. Use it to
|
|
76
|
+
* remove a controller early: Lit's `removeController` alone leaves it active.
|
|
77
|
+
*/
|
|
78
|
+
dispose(): void;
|
|
73
79
|
/** Updates the recorder options (e.g. callbacks). */
|
|
74
80
|
setOptions(options: Partial<HotkeyRecorderOptions>): void;
|
|
75
81
|
/** Start recording a new hotkey. */
|
|
@@ -8,8 +8,9 @@ import { HotkeyRecorder } from "@tanstack/hotkeys";
|
|
|
8
8
|
* With the default `maxSteps: 1`, the first valid chord is recorded. With a
|
|
9
9
|
* larger `maxSteps`, each chord adds a step; the recording commits on Enter
|
|
10
10
|
* (unless `commitKeys: 'none'`), after `idleTimeoutMs`, or at `maxSteps`, and
|
|
11
|
-
* `onRecord` receives a chord (one step) or a sequence. Escape cancels
|
|
12
|
-
*
|
|
11
|
+
* `onRecord` receives a chord (one step) or a sequence. Escape cancels, and
|
|
12
|
+
* so do Tab and Shift+Tab unless `recordTab` is set; Backspace/Delete removes
|
|
13
|
+
* the last step or clears.
|
|
13
14
|
*
|
|
14
15
|
* @example
|
|
15
16
|
* ```ts
|
|
@@ -98,6 +99,14 @@ var HotkeyRecorderController = class {
|
|
|
98
99
|
this._recordedHotkey = null;
|
|
99
100
|
this._steps = [];
|
|
100
101
|
}
|
|
102
|
+
/**
|
|
103
|
+
* Releases the controller now and removes it from its host. Use it to
|
|
104
|
+
* remove a controller early: Lit's `removeController` alone leaves it active.
|
|
105
|
+
*/
|
|
106
|
+
dispose() {
|
|
107
|
+
this.hostDisconnected();
|
|
108
|
+
this._host.removeController(this);
|
|
109
|
+
}
|
|
101
110
|
/** Updates the recorder options (e.g. callbacks). */
|
|
102
111
|
setOptions(options) {
|
|
103
112
|
this._optionOverrides = {
|
|
@@ -29,4 +29,9 @@ export declare class HotkeyRegistrationsController implements ReactiveController
|
|
|
29
29
|
constructor(_host: ReactiveControllerHost);
|
|
30
30
|
hostConnected(): void;
|
|
31
31
|
hostDisconnected(): void;
|
|
32
|
+
/**
|
|
33
|
+
* Releases the controller now and removes it from its host. Use it to
|
|
34
|
+
* remove a controller early: Lit's `removeController` alone leaves it active.
|
|
35
|
+
*/
|
|
36
|
+
dispose(): void;
|
|
32
37
|
}
|
|
@@ -51,6 +51,14 @@ var HotkeyRegistrationsController = class {
|
|
|
51
51
|
this._unsubscribe = void 0;
|
|
52
52
|
this._hotkeys = [];
|
|
53
53
|
}
|
|
54
|
+
/**
|
|
55
|
+
* Releases the controller now and removes it from its host. Use it to
|
|
56
|
+
* remove a controller early: Lit's `removeController` alone leaves it active.
|
|
57
|
+
*/
|
|
58
|
+
dispose() {
|
|
59
|
+
this.hostDisconnected();
|
|
60
|
+
this._host.removeController(this);
|
|
61
|
+
}
|
|
54
62
|
};
|
|
55
63
|
|
|
56
64
|
export { HotkeyRegistrationsController };
|
|
@@ -35,4 +35,9 @@ export declare class HotkeyScopesStateController implements ReactiveController {
|
|
|
35
35
|
hostConnected(): void;
|
|
36
36
|
/** Unsubscribes from the scopes store. */
|
|
37
37
|
hostDisconnected(): void;
|
|
38
|
+
/**
|
|
39
|
+
* Releases the controller now and removes it from its host. Use it to
|
|
40
|
+
* remove a controller early: Lit's `removeController` alone leaves it active.
|
|
41
|
+
*/
|
|
42
|
+
dispose(): void;
|
|
38
43
|
}
|
|
@@ -51,6 +51,14 @@ var HotkeyScopesStateController = class {
|
|
|
51
51
|
this._unsubscribe?.();
|
|
52
52
|
this._unsubscribe = void 0;
|
|
53
53
|
}
|
|
54
|
+
/**
|
|
55
|
+
* Releases the controller now and removes it from its host. Use it to
|
|
56
|
+
* remove a controller early: Lit's `removeController` alone leaves it active.
|
|
57
|
+
*/
|
|
58
|
+
dispose() {
|
|
59
|
+
this.hostDisconnected();
|
|
60
|
+
this._host.removeController(this);
|
|
61
|
+
}
|
|
54
62
|
};
|
|
55
63
|
|
|
56
64
|
export { HotkeyScopesStateController };
|
|
@@ -1,7 +1,10 @@
|
|
|
1
1
|
import { AppHotkey, HotkeyCallback, RegisterableHotkey, Target } from "@tanstack/hotkeys";
|
|
2
2
|
import { AdapterAppHotkeyOptions, AdapterChordOptions, AdapterCommonOptions, AdapterHotkeyOptions, AdapterOptionsFor, AdapterSequenceOptions } from "@tanstack/hotkeys/adapter";
|
|
3
3
|
import { ReactiveController, ReactiveControllerHost } from "lit";
|
|
4
|
-
/**
|
|
4
|
+
/**
|
|
5
|
+
* The element to listen on. A `null` or `undefined` target skips registration
|
|
6
|
+
* until it is set. Omit `target` for the document.
|
|
7
|
+
*/
|
|
5
8
|
export type HotkeyControllerTarget = Target | null;
|
|
6
9
|
/** Options shared by chords and sequences. */
|
|
7
10
|
export type HotkeyControllerOptions = AdapterHotkeyOptions<HotkeyControllerTarget>;
|
|
@@ -57,5 +60,10 @@ export declare class HotkeyController implements ReactiveController {
|
|
|
57
60
|
private _sync;
|
|
58
61
|
/** Releases registrations when the host disconnects. */
|
|
59
62
|
hostDisconnected(): void;
|
|
63
|
+
/**
|
|
64
|
+
* Releases the controller now and removes it from its host. Use it to
|
|
65
|
+
* remove a controller early: Lit's `removeController` alone leaves it active.
|
|
66
|
+
*/
|
|
67
|
+
dispose(): void;
|
|
60
68
|
}
|
|
61
69
|
export {};
|
|
@@ -65,6 +65,14 @@ var HotkeyController = class {
|
|
|
65
65
|
this._unsubscribe = void 0;
|
|
66
66
|
this._bindings.destroy();
|
|
67
67
|
}
|
|
68
|
+
/**
|
|
69
|
+
* Releases the controller now and removes it from its host. Use it to
|
|
70
|
+
* remove a controller early: Lit's `removeController` alone leaves it active.
|
|
71
|
+
*/
|
|
72
|
+
dispose() {
|
|
73
|
+
this.hostDisconnected();
|
|
74
|
+
this._host.removeController(this);
|
|
75
|
+
}
|
|
68
76
|
};
|
|
69
77
|
|
|
70
78
|
export { HotkeyController };
|
|
@@ -58,6 +58,11 @@ export declare class KeyHoldController implements ReactiveController {
|
|
|
58
58
|
/** Re-reads a getter key when host properties trigger an update. */
|
|
59
59
|
hostUpdate(): void;
|
|
60
60
|
hostDisconnected(): void;
|
|
61
|
+
/**
|
|
62
|
+
* Releases the controller now and removes it from its host. Use it to
|
|
63
|
+
* remove a controller early: Lit's `removeController` alone leaves it active.
|
|
64
|
+
*/
|
|
65
|
+
dispose(): void;
|
|
61
66
|
/** Recomputes the held state and reports whether it changed. */
|
|
62
67
|
private _refresh;
|
|
63
68
|
}
|
|
@@ -80,10 +80,17 @@ var KeyHoldController = class {
|
|
|
80
80
|
this._unsubscribe = void 0;
|
|
81
81
|
this._value = false;
|
|
82
82
|
}
|
|
83
|
+
/**
|
|
84
|
+
* Releases the controller now and removes it from its host. Use it to
|
|
85
|
+
* remove a controller early: Lit's `removeController` alone leaves it active.
|
|
86
|
+
*/
|
|
87
|
+
dispose() {
|
|
88
|
+
this.hostDisconnected();
|
|
89
|
+
this._host.removeController(this);
|
|
90
|
+
}
|
|
83
91
|
/** Recomputes the held state and reports whether it changed. */
|
|
84
92
|
_refresh() {
|
|
85
|
-
const
|
|
86
|
-
const next = getKeyStateTracker().store.state.heldKeys.some((heldKey) => heldKey.toLowerCase() === key);
|
|
93
|
+
const next = getKeyStateTracker().isKeyHeld(typeof this._key === "function" ? this._key() : this._key);
|
|
87
94
|
const changed = next !== this._value;
|
|
88
95
|
this._value = next;
|
|
89
96
|
return changed;
|
|
@@ -16,7 +16,9 @@ export type HotkeyDecorator<TContext extends HotkeyCallbackContext = HotkeyCallb
|
|
|
16
16
|
* as `['G', 'G']`, or an app hotkey. Uses {@link HotkeyController} under the hood.
|
|
17
17
|
*
|
|
18
18
|
* Works with legacy (`experimentalDecorators`) and standard decorators. The
|
|
19
|
-
* method is looked up when the hotkey fires, so subclass overrides run.
|
|
19
|
+
* method is looked up when the hotkey fires, so subclass overrides run. A
|
|
20
|
+
* subclass that decorates an override replaces the parent's hotkeys for that
|
|
21
|
+
* method; an override without `@hotkey` keeps them.
|
|
20
22
|
*
|
|
21
23
|
* @param hotkey - The chord, sequence, or app hotkey to listen for.
|
|
22
24
|
* @param options - Optional registration options (target, platform, enabled, etc.).
|
|
@@ -1,13 +1,25 @@
|
|
|
1
1
|
import { HotkeyController } from "../controllers/hotkey.js";
|
|
2
2
|
|
|
3
3
|
// src/decorators/hotkey.ts
|
|
4
|
+
const owners = /* @__PURE__ */ new WeakMap();
|
|
4
5
|
function hotkey(hotkey, options) {
|
|
5
6
|
return (proto, context) => {
|
|
6
7
|
const standard = typeof context === "object";
|
|
8
|
+
const owner = standard ? context.metadata ?? proto : proto;
|
|
9
|
+
const name = standard ? context.name : context;
|
|
7
10
|
const init = (host) => {
|
|
8
|
-
new HotkeyController(host, hotkey, function(event, callbackContext) {
|
|
11
|
+
const controller = new HotkeyController(host, hotkey, function(event, callbackContext) {
|
|
9
12
|
return (standard ? context.access.get(this) : this[context]).call(this, event, callbackContext);
|
|
10
13
|
}, options);
|
|
14
|
+
if (standard && context.private) return;
|
|
15
|
+
let methods = owners.get(host);
|
|
16
|
+
if (!methods) owners.set(host, methods = /* @__PURE__ */ new Map());
|
|
17
|
+
const entry = methods.get(name);
|
|
18
|
+
if (entry?.[0] === owner) entry[1].push(controller);
|
|
19
|
+
else {
|
|
20
|
+
entry?.[1].forEach((previous) => previous.dispose());
|
|
21
|
+
methods.set(name, [owner, [controller]]);
|
|
22
|
+
}
|
|
11
23
|
};
|
|
12
24
|
if (standard) context.addInitializer(function() {
|
|
13
25
|
init(this);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tanstack/lit-hotkeys",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.24.0",
|
|
4
4
|
"description": "Lit adapter for TanStack Hotkeys",
|
|
5
5
|
"author": "Tanner Linsley",
|
|
6
6
|
"license": "MIT",
|
|
@@ -35,9 +35,10 @@
|
|
|
35
35
|
"skills"
|
|
36
36
|
],
|
|
37
37
|
"dependencies": {
|
|
38
|
-
"@tanstack/hotkeys": "0.
|
|
38
|
+
"@tanstack/hotkeys": "0.27.0"
|
|
39
39
|
},
|
|
40
40
|
"devDependencies": {
|
|
41
|
+
"@tanstack/hotkeys-test-utils": "0.0.0",
|
|
41
42
|
"lit": "^3.3.3"
|
|
42
43
|
},
|
|
43
44
|
"peerDependencies": {
|
|
@@ -48,8 +49,9 @@
|
|
|
48
49
|
"lint": "oxlint ./src",
|
|
49
50
|
"lint:fix": "oxlint ./src --fix",
|
|
50
51
|
"test:oxlint": "oxlint ./src",
|
|
51
|
-
"test:lib": "vitest
|
|
52
|
+
"test:lib": "vitest",
|
|
52
53
|
"test:lib:dev": "pnpm test:lib --watch",
|
|
54
|
+
"test:coverage": "vitest --coverage",
|
|
53
55
|
"test:types": "tsc",
|
|
54
56
|
"build": "tsdown",
|
|
55
57
|
"test:build": "publint --strict && node ../../scripts/verify-package.ts"
|
|
@@ -69,7 +69,7 @@ export class MyEditor extends LitElement {
|
|
|
69
69
|
| `new HotkeyRegistrationsController(host)` | Read `.hotkeys`, every registered hotkey with its options, `meta`, and `status` (whether it's enabled and in an active scope). |
|
|
70
70
|
| `new HotkeyScopesStateController(host)` | Read `.value`, the active scopes and the exclusive scope that owns the keyboard. |
|
|
71
71
|
| `new HotkeyHintController(host, hotkey, options?)` | Read `.value`, whether held modifiers should reveal a shortcut's hint. False unless a registration of the hotkey can fire: enabled, in an active scope, and with focus inside its element target. |
|
|
72
|
-
| `new KeyHoldController(host, key)` | Read `.value`, whether one key is held. Pass a getter, such as `() => this.key`, for a key that changes.
|
|
72
|
+
| `new KeyHoldController(host, key)` | Read `.value`, whether one key is held. Pass a getter, such as `() => this.key`, for a key that changes. Letters match in any case; other names, such as `Shift`, are case-sensitive. |
|
|
73
73
|
| `new HeldKeysController(host)` | Read `.value`, every key that's held right now. |
|
|
74
74
|
| `new HeldKeyCodesController(host)` | Read `.value`, which maps each held key to its physical `event.code`. |
|
|
75
75
|
|
|
@@ -79,6 +79,8 @@ The package also re-exports `@tanstack/hotkeys`, such as `formatForDisplay`, `ma
|
|
|
79
79
|
|
|
80
80
|
- **`@hotkey` works with standard and legacy decorators.** It needs no tsconfig change. Lit's `@property` and `@state` have their own rules: with standard decorators they need `accessor` fields; with `"experimentalDecorators": true` they need `"useDefineForClassFields": false`. Match the project's existing mode.
|
|
81
81
|
- **Decorator options are fixed when the class is defined.** For options that read instance state, or a `target` from a `ref`, use `HotkeyController` with an options function, which reruns after each update of its host.
|
|
82
|
+
- **Remove a controller with `dispose()`.** Lit's `removeController` doesn't call `hostDisconnected`, so a `HotkeyController` removed that way stays registered, even after its host disconnects. For a list that changes, keep each item's controller and call `controller.dispose()` when the item goes. Every controller in this package has `dispose()`.
|
|
83
|
+
- **Decorating an override replaces the parent's hotkeys.** With `@hotkey` on both a method and a subclass override, only the subclass's hotkeys register for that method. Leave `@hotkey` off the override to keep the parent's.
|
|
82
84
|
- **Render a `ref` target in the controller's host.** The options function reruns only when the host updates. If a child element renders the target, keep it in a reactive property or call `requestUpdate()` on the host when it changes.
|
|
83
85
|
- **Release every scope you activate.** Lit has no provider, so a dialog activates its scope in `connectedCallback` with `this.release = getHotkeyManager().activateScope('dialog-1', { exclusive: true })` and calls `this.release()` in `disconnectedCallback`. A forgotten release keeps every other hotkey suspended. Give each open dialog its own scope name.
|
|
84
86
|
|