@tanstack/lit-hotkeys 0.26.0 → 0.27.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.js +1 -8
- package/dist/controllers/app-hotkeys.d.ts +6 -6
- package/dist/controllers/app-hotkeys.js +4 -5
- package/dist/controllers/format-for-display.d.ts +2 -2
- package/dist/controllers/format-for-display.js +3 -10
- package/dist/controllers/hotkey-hint.d.ts +2 -2
- package/dist/controllers/hotkey-hint.js +3 -4
- package/dist/controllers/hotkey-recorder.d.ts +2 -2
- package/dist/controllers/hotkey-recorder.js +2 -1
- package/dist/controllers/hotkey-registrations.js +3 -2
- package/dist/controllers/hotkey.d.ts +2 -4
- package/dist/controllers/hotkey.js +3 -3
- package/dist/controllers/key-hold.d.ts +2 -2
- package/dist/controllers/key-hold.js +2 -1
- package/dist/controllers/keyboard-layout.js +3 -7
- package/package.json +2 -2
|
@@ -1,10 +1,3 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { subscribePublishedAppHotkeys as subscribeAppHotkeys } from "@tanstack/hotkeys/adapter";
|
|
3
|
-
|
|
4
|
-
// src/controllers/_app-hotkeys.ts
|
|
5
|
-
/** The app hotkeys store published by `provideAppHotkeys`, if any. */
|
|
6
|
-
function getAppHotkeysStore() {
|
|
7
|
-
return getHotkeyManager().appHotkeys.state;
|
|
8
|
-
}
|
|
1
|
+
import { getPublishedAppHotkeysStore as getAppHotkeysStore, subscribePublishedAppHotkeys as subscribeAppHotkeys } from "@tanstack/hotkeys/adapter";
|
|
9
2
|
|
|
10
3
|
export { getAppHotkeysStore, subscribeAppHotkeys };
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { AppHotkey,
|
|
1
|
+
import { AppHotkey, AppHotkeyId, CustomHotkeyActions, CustomHotkeys, Hotkey, RecordedKeyPresses, RegisteredAppHotkeyListItem, RegisteredAppHotkeys } from "@tanstack/hotkeys";
|
|
2
2
|
import { ReactiveController, ReactiveControllerHost } from "lit";
|
|
3
3
|
/**
|
|
4
4
|
* A Lit ReactiveController for app hotkeys provided with `provideAppHotkeys`:
|
|
@@ -20,14 +20,14 @@ import { ReactiveController, ReactiveControllerHost } from "lit";
|
|
|
20
20
|
* }
|
|
21
21
|
* ```
|
|
22
22
|
*/
|
|
23
|
-
export declare class AppHotkeysController implements ReactiveController {
|
|
23
|
+
export declare class AppHotkeysController implements ReactiveController, CustomHotkeyActions {
|
|
24
24
|
private _host;
|
|
25
25
|
private _unsubscribe;
|
|
26
26
|
constructor(_host: ReactiveControllerHost);
|
|
27
27
|
/** Effective app hotkeys, typed by `Register`. */
|
|
28
28
|
get appHotkeys(): RegisteredAppHotkeys;
|
|
29
29
|
/** Every app hotkey with its live status, in declaration order. */
|
|
30
|
-
get list(): Array<
|
|
30
|
+
get list(): Array<RegisteredAppHotkeyListItem>;
|
|
31
31
|
/** The user's hotkeys that differ from the defaults. */
|
|
32
32
|
get customHotkeys(): CustomHotkeys;
|
|
33
33
|
/**
|
|
@@ -35,9 +35,9 @@ export declare class AppHotkeysController implements ReactiveController {
|
|
|
35
35
|
* Returns conflicting app hotkeys; when any exist, nothing changes. Pass
|
|
36
36
|
* the recorder's `context` for a recorded hotkey, as for `findConflicts`.
|
|
37
37
|
*/
|
|
38
|
-
setCustomHotkey(id:
|
|
38
|
+
setCustomHotkey(id: AppHotkeyId, hotkey: Hotkey | null, recordedWith?: RecordedKeyPresses): Array<AppHotkey>;
|
|
39
39
|
/** Restores the default hotkey for an app hotkey. */
|
|
40
|
-
resetCustomHotkey(id:
|
|
40
|
+
resetCustomHotkey(id: AppHotkeyId): void;
|
|
41
41
|
/** Restores every default hotkey. */
|
|
42
42
|
resetCustomHotkeys(): void;
|
|
43
43
|
/**
|
|
@@ -45,7 +45,7 @@ export declare class AppHotkeysController implements ReactiveController {
|
|
|
45
45
|
* recorder's `context` for a recorded hotkey: it has the key press, which
|
|
46
46
|
* also finds a hotkey written differently that the same press fires.
|
|
47
47
|
*/
|
|
48
|
-
findConflicts(id:
|
|
48
|
+
findConflicts(id: AppHotkeyId, hotkey: Hotkey, recordedWith?: RecordedKeyPresses): Array<AppHotkey>;
|
|
49
49
|
hostConnected(): void;
|
|
50
50
|
hostDisconnected(): void;
|
|
51
51
|
/**
|
|
@@ -1,12 +1,11 @@
|
|
|
1
1
|
import { getAppHotkeysStore, subscribeAppHotkeys } from "./_app-hotkeys.js";
|
|
2
2
|
import { isServer } from "./_server.js";
|
|
3
|
-
import { getHotkeyManager
|
|
3
|
+
import { getHotkeyManager } from "@tanstack/hotkeys";
|
|
4
|
+
import { getHotkeyRegistrationViews, requireAppHotkeysStore } from "@tanstack/hotkeys/adapter";
|
|
4
5
|
|
|
5
6
|
// src/controllers/app-hotkeys.ts
|
|
6
7
|
function requireStore() {
|
|
7
|
-
|
|
8
|
-
if (!store) throw new Error("[hotkeys] AppHotkeysController requires provideAppHotkeys()");
|
|
9
|
-
return store;
|
|
8
|
+
return requireAppHotkeysStore(getAppHotkeysStore(), "AppHotkeysController requires provideAppHotkeys()");
|
|
10
9
|
}
|
|
11
10
|
/**
|
|
12
11
|
* A Lit ReactiveController for app hotkeys provided with `provideAppHotkeys`:
|
|
@@ -41,7 +40,7 @@ var AppHotkeysController = class {
|
|
|
41
40
|
}
|
|
42
41
|
/** Every app hotkey with its live status, in declaration order. */
|
|
43
42
|
get list() {
|
|
44
|
-
return requireStore().getList(
|
|
43
|
+
return requireStore().getList(getHotkeyRegistrationViews());
|
|
45
44
|
}
|
|
46
45
|
/** The user's hotkeys that differ from the defaults. */
|
|
47
46
|
get customHotkeys() {
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { HotkeyPlatform, formatForDisplay } from "@tanstack/hotkeys";
|
|
1
|
+
import { HotkeyPlatform, MaybeGetter, formatForDisplay } from "@tanstack/hotkeys";
|
|
2
2
|
import { ReactiveController, ReactiveControllerHost } from "lit";
|
|
3
3
|
/** Options for `FormatForDisplayController`. */
|
|
4
4
|
export interface FormatForDisplayControllerOptions {
|
|
@@ -61,7 +61,7 @@ export declare class FormatForDisplayController implements ReactiveController {
|
|
|
61
61
|
* @param _host - The Lit component that owns this controller. The controller adds itself to it.
|
|
62
62
|
* @param _options - Options or a getter. `platform` is read for each label. `keyboardLayout` is read on connection and before host updates.
|
|
63
63
|
*/
|
|
64
|
-
constructor(_host: ReactiveControllerHost, _options?: FormatForDisplayControllerOptions
|
|
64
|
+
constructor(_host: ReactiveControllerHost, _options?: MaybeGetter<FormatForDisplayControllerOptions>);
|
|
65
65
|
/** Starts reading the layout, unless `keyboardLayout` is false. */
|
|
66
66
|
hostConnected(): void;
|
|
67
67
|
/** Follows a `keyboardLayout` option that a host property changed. */
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { KeyboardLayoutController } from "./keyboard-layout.js";
|
|
2
|
-
import {
|
|
2
|
+
import { createFormatForDisplay, resolveMaybeGetter } from "@tanstack/hotkeys/adapter";
|
|
3
3
|
|
|
4
4
|
// src/controllers/format-for-display.ts
|
|
5
5
|
/**
|
|
@@ -43,14 +43,7 @@ var FormatForDisplayController = class {
|
|
|
43
43
|
* user's keyboard layout filled in. It takes the same options as
|
|
44
44
|
* `formatForDisplay` and needs no `this`, so it can be passed around.
|
|
45
45
|
*/
|
|
46
|
-
format = ((
|
|
47
|
-
const { platform, keyboardLayout } = this._read();
|
|
48
|
-
return formatForDisplay(hotkey, {
|
|
49
|
-
...options,
|
|
50
|
-
platform: options?.platform ?? platform,
|
|
51
|
-
layoutMap: options?.layoutMap ?? (keyboardLayout !== false && this._layout?.value || void 0)
|
|
52
|
-
});
|
|
53
|
-
});
|
|
46
|
+
format = createFormatForDisplay(() => this._read().platform, () => this._read().keyboardLayout !== false && this._layout?.value || null);
|
|
54
47
|
/**
|
|
55
48
|
* @param _host - The Lit component that owns this controller. The controller adds itself to it.
|
|
56
49
|
* @param _options - Options or a getter. `platform` is read for each label. `keyboardLayout` is read on connection and before host updates.
|
|
@@ -79,7 +72,7 @@ var FormatForDisplayController = class {
|
|
|
79
72
|
this._host.removeController(this);
|
|
80
73
|
}
|
|
81
74
|
_read() {
|
|
82
|
-
return
|
|
75
|
+
return resolveMaybeGetter(this._options);
|
|
83
76
|
}
|
|
84
77
|
_sync() {
|
|
85
78
|
if (this._read().keyboardLayout === false) {
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { AppHotkey, HeldModifierOptions, RegisterableHotkey } from "@tanstack/hotkeys";
|
|
1
|
+
import { AppHotkey, HeldModifierOptions, MaybeGetter, RegisterableHotkey } from "@tanstack/hotkeys";
|
|
2
2
|
import { ReactiveController, ReactiveControllerHost } from "lit";
|
|
3
3
|
/**
|
|
4
4
|
* Modifier hint controller. Getter arguments can read reactive host
|
|
@@ -11,7 +11,7 @@ export declare class HotkeyHintController implements ReactiveController {
|
|
|
11
11
|
private unsubscribe?;
|
|
12
12
|
private visible;
|
|
13
13
|
/** Attaches to the host; getter arguments can read changing reactive properties. */
|
|
14
|
-
constructor(host: ReactiveControllerHost, hotkey: RegisterableHotkey | AppHotkey | null | undefined
|
|
14
|
+
constructor(host: ReactiveControllerHost, hotkey: MaybeGetter<RegisterableHotkey | AppHotkey | null | undefined>, options?: MaybeGetter<HeldModifierOptions>);
|
|
15
15
|
/**
|
|
16
16
|
* Current visibility. True only while the hotkey can fire: some registration
|
|
17
17
|
* of it is enabled and in an active scope. A hotkey on an element counts only while focus is inside it.
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { getAppHotkeysStore, subscribeAppHotkeys } from "./_app-hotkeys.js";
|
|
2
2
|
import { isServer } from "./_server.js";
|
|
3
|
-
import { getHotkeyManager, getKeyStateTracker
|
|
3
|
+
import { getHotkeyManager, getKeyStateTracker } from "@tanstack/hotkeys";
|
|
4
|
+
import { isHotkeyHintVisible, resolveMaybeGetter } from "@tanstack/hotkeys/adapter";
|
|
4
5
|
|
|
5
6
|
// src/controllers/hotkey-hint.ts
|
|
6
7
|
/**
|
|
@@ -69,9 +70,7 @@ var HotkeyHintController = class {
|
|
|
69
70
|
}
|
|
70
71
|
/** Recomputes visibility and reports whether the host needs another render. */
|
|
71
72
|
update() {
|
|
72
|
-
const
|
|
73
|
-
const hotkey = isAppHotkey(value) ? resolveAppHotkey(value, getAppHotkeysStore()).hotkey : value;
|
|
74
|
-
const next = hotkey !== null && matchesHeldModifiers(hotkey, getKeyStateTracker().store.state.heldKeys, typeof this.options === "function" ? this.options() : this.options) && getHotkeyManager().hasActiveRegistration(value);
|
|
73
|
+
const next = isHotkeyHintVisible(resolveMaybeGetter(this.hotkey), getKeyStateTracker().store.state.heldKeys, resolveMaybeGetter(this.options), getAppHotkeysStore());
|
|
75
74
|
const changed = next !== this.visible;
|
|
76
75
|
this.visible = next;
|
|
77
76
|
return changed;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { Hotkey, HotkeyChordRecorderOptions, HotkeyRecorderOptions, HotkeySequence, HotkeySequenceRecorderOptions } from "@tanstack/hotkeys";
|
|
1
|
+
import { Hotkey, HotkeyChordRecorderOptions, HotkeyRecorderActions, HotkeyRecorderOptions, HotkeyRecorderState, HotkeySequence, HotkeySequenceRecorderOptions } from "@tanstack/hotkeys";
|
|
2
2
|
import { ReactiveController, ReactiveControllerHost } from "lit";
|
|
3
3
|
/**
|
|
4
4
|
* A Lit ReactiveController that records keyboard shortcuts.
|
|
@@ -38,7 +38,7 @@ import { ReactiveController, ReactiveControllerHost } from "lit";
|
|
|
38
38
|
* }
|
|
39
39
|
* ```
|
|
40
40
|
*/
|
|
41
|
-
export declare class HotkeyRecorderController implements ReactiveController {
|
|
41
|
+
export declare class HotkeyRecorderController implements ReactiveController, HotkeyRecorderState, HotkeyRecorderActions {
|
|
42
42
|
private _host;
|
|
43
43
|
private _options;
|
|
44
44
|
/** The recorder instance. */
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { isServer } from "./_server.js";
|
|
2
2
|
import { HotkeyRecorder } from "@tanstack/hotkeys";
|
|
3
|
+
import { resolveMaybeGetter } from "@tanstack/hotkeys/adapter";
|
|
3
4
|
|
|
4
5
|
// src/controllers/hotkey-recorder.ts
|
|
5
6
|
/**
|
|
@@ -70,7 +71,7 @@ var HotkeyRecorderController = class {
|
|
|
70
71
|
this._host = _host;
|
|
71
72
|
this._options = _options;
|
|
72
73
|
this._recorder = new HotkeyRecorder(() => ({
|
|
73
|
-
...
|
|
74
|
+
...resolveMaybeGetter(this._options),
|
|
74
75
|
...this._optionOverrides
|
|
75
76
|
}));
|
|
76
77
|
this._host.addController(this);
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { isServer } from "./_server.js";
|
|
2
|
-
import { getHotkeyManager
|
|
2
|
+
import { getHotkeyManager } from "@tanstack/hotkeys";
|
|
3
|
+
import { getHotkeyRegistrationViews } from "@tanstack/hotkeys/adapter";
|
|
3
4
|
|
|
4
5
|
// src/controllers/hotkey-registrations.ts
|
|
5
6
|
/**
|
|
@@ -38,7 +39,7 @@ var HotkeyRegistrationsController = class {
|
|
|
38
39
|
hostConnected() {
|
|
39
40
|
if (this._unsubscribe) return;
|
|
40
41
|
const manager = getHotkeyManager();
|
|
41
|
-
const read = () =>
|
|
42
|
+
const read = () => getHotkeyRegistrationViews(manager.registrations.state);
|
|
42
43
|
this._hotkeys = read();
|
|
43
44
|
if (isServer()) return;
|
|
44
45
|
const subscription = manager.registrations.subscribe(() => {
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { AppHotkey, HotkeyCallback, RegisterableHotkey, Target } from "@tanstack/hotkeys";
|
|
1
|
+
import { AppHotkey, HotkeyCallback, MaybeGetter, 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
|
/**
|
|
@@ -18,7 +18,6 @@ export type HotkeyControllerCommonOptions = AdapterCommonOptions<HotkeyControlle
|
|
|
18
18
|
export type HotkeyControllerOptionsFor<T extends RegisterableHotkey> = AdapterOptionsFor<T, HotkeyControllerTarget>;
|
|
19
19
|
/** Call-site options for an app hotkey, typed by its declared default kind. */
|
|
20
20
|
export type AppHotkeyControllerOptions<T extends AppHotkey = AppHotkey> = AdapterAppHotkeyOptions<T, HotkeyControllerTarget>;
|
|
21
|
-
type MaybeGetter<T> = T | (() => T);
|
|
22
21
|
/**
|
|
23
22
|
* A Lit ReactiveController that registers a hotkey when the host element is
|
|
24
23
|
* connected and unregisters it when the host is disconnected. The hotkey can
|
|
@@ -65,5 +64,4 @@ export declare class HotkeyController implements ReactiveController {
|
|
|
65
64
|
* remove a controller early: Lit's `removeController` alone leaves it active.
|
|
66
65
|
*/
|
|
67
66
|
dispose(): void;
|
|
68
|
-
}
|
|
69
|
-
export {};
|
|
67
|
+
}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { getAppHotkeysStore, subscribeAppHotkeys } from "./_app-hotkeys.js";
|
|
2
2
|
import { isServer } from "./_server.js";
|
|
3
|
-
import { createHotkeyBindings, prepareHotkeyDefinitions } from "@tanstack/hotkeys/adapter";
|
|
3
|
+
import { createHotkeyBindings, prepareHotkeyDefinitions, resolveMaybeGetter } from "@tanstack/hotkeys/adapter";
|
|
4
4
|
|
|
5
5
|
// src/controllers/hotkey.ts
|
|
6
6
|
/**
|
|
@@ -48,9 +48,9 @@ var HotkeyController = class {
|
|
|
48
48
|
if (this._connected) this._sync();
|
|
49
49
|
}
|
|
50
50
|
_sync() {
|
|
51
|
-
const options =
|
|
51
|
+
const options = resolveMaybeGetter(this._options);
|
|
52
52
|
this._bindings.update(prepareHotkeyDefinitions([{
|
|
53
|
-
hotkey:
|
|
53
|
+
hotkey: resolveMaybeGetter(this._hotkey),
|
|
54
54
|
callback: this._boundCallback,
|
|
55
55
|
options
|
|
56
56
|
}], {
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { IndividualKey } from "@tanstack/hotkeys";
|
|
1
|
+
import { IndividualKey, MaybeGetter } from "@tanstack/hotkeys";
|
|
2
2
|
import { ReactiveController, ReactiveControllerHost } from "lit";
|
|
3
3
|
/**
|
|
4
4
|
* A Lit ReactiveController that tracks whether a specific key is currently held.
|
|
@@ -53,7 +53,7 @@ export declare class KeyHoldController implements ReactiveController {
|
|
|
53
53
|
* @param _host - The Lit component that owns this controller.
|
|
54
54
|
* @param _key - The key to track (e.g. 'Shift', 'Control', 'A'), or a getter.
|
|
55
55
|
*/
|
|
56
|
-
constructor(_host: ReactiveControllerHost, _key: IndividualKey
|
|
56
|
+
constructor(_host: ReactiveControllerHost, _key: MaybeGetter<IndividualKey>);
|
|
57
57
|
hostConnected(): void;
|
|
58
58
|
/** Re-reads a getter key when host properties trigger an update. */
|
|
59
59
|
hostUpdate(): void;
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { isServer } from "./_server.js";
|
|
2
2
|
import { getKeyStateTracker } from "@tanstack/hotkeys";
|
|
3
|
+
import { resolveMaybeGetter } from "@tanstack/hotkeys/adapter";
|
|
3
4
|
|
|
4
5
|
// src/controllers/key-hold.ts
|
|
5
6
|
/**
|
|
@@ -90,7 +91,7 @@ var KeyHoldController = class {
|
|
|
90
91
|
}
|
|
91
92
|
/** Recomputes the held state and reports whether it changed. */
|
|
92
93
|
_refresh() {
|
|
93
|
-
const next = getKeyStateTracker().isKeyHeld(
|
|
94
|
+
const next = getKeyStateTracker().isKeyHeld(resolveMaybeGetter(this._key));
|
|
94
95
|
const changed = next !== this._value;
|
|
95
96
|
this._value = next;
|
|
96
97
|
return changed;
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { isServer } from "./_server.js";
|
|
2
|
-
import { getKeyboardLayoutStore
|
|
2
|
+
import { getKeyboardLayoutStore } from "@tanstack/hotkeys";
|
|
3
|
+
import { followKeyboardLayout } from "@tanstack/hotkeys/adapter";
|
|
3
4
|
|
|
4
5
|
// src/controllers/keyboard-layout.ts
|
|
5
6
|
/**
|
|
@@ -58,12 +59,7 @@ var KeyboardLayoutController = class {
|
|
|
58
59
|
this._host.requestUpdate();
|
|
59
60
|
if (isServer()) return;
|
|
60
61
|
const store = getKeyboardLayoutStore();
|
|
61
|
-
|
|
62
|
-
const stop = loadKeyboardLayout();
|
|
63
|
-
this._release = () => {
|
|
64
|
-
subscription.unsubscribe();
|
|
65
|
-
stop();
|
|
66
|
-
};
|
|
62
|
+
this._release = followKeyboardLayout(() => this._host.requestUpdate());
|
|
67
63
|
if (this._rendered) return;
|
|
68
64
|
const show = () => {
|
|
69
65
|
this._rendered = true;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tanstack/lit-hotkeys",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.27.0",
|
|
4
4
|
"description": "Lit adapter for TanStack Hotkeys",
|
|
5
5
|
"author": "Tanner Linsley",
|
|
6
6
|
"license": "MIT",
|
|
@@ -35,7 +35,7 @@
|
|
|
35
35
|
"skills"
|
|
36
36
|
],
|
|
37
37
|
"dependencies": {
|
|
38
|
-
"@tanstack/hotkeys": "0.
|
|
38
|
+
"@tanstack/hotkeys": "0.31.0"
|
|
39
39
|
},
|
|
40
40
|
"devDependencies": {
|
|
41
41
|
"@lit-labs/ssr": "^4.1.0",
|