@tanstack/alpine-hotkeys 0.14.0 → 0.14.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/dist/createAppHotkeys.js +3 -7
- package/dist/createFormatForDisplay.js +4 -9
- package/dist/createHotkey.js +3 -3
- package/dist/createHotkeyHint.js +6 -5
- package/dist/createHotkeyRecorder.js +3 -3
- package/dist/createHotkeyRegistrations.js +3 -2
- package/dist/createHotkeys.js +3 -4
- package/dist/createHotkeysScope.d.ts +3 -2
- package/dist/createKeyHold.js +2 -2
- package/dist/index.d.ts +2 -2
- package/dist/scope.js +4 -8
- package/dist/types.d.ts +6 -44
- package/package.json +2 -2
package/dist/createAppHotkeys.js
CHANGED
|
@@ -1,10 +1,9 @@
|
|
|
1
1
|
import { createHotkeyRegistrations } from "./createHotkeyRegistrations.js";
|
|
2
|
+
import { bindCustomHotkeyActions, requireAppHotkeysStore } from "@tanstack/hotkeys/adapter";
|
|
2
3
|
|
|
3
4
|
// src/createAppHotkeys.ts
|
|
4
5
|
function requireStore(scope) {
|
|
5
|
-
|
|
6
|
-
if (!store) throw new Error("[hotkeys] App hotkeys require provideAppHotkeys()");
|
|
7
|
-
return store;
|
|
6
|
+
return requireAppHotkeysStore(scope.appHotkeys(), "App hotkeys require provideAppHotkeys()");
|
|
8
7
|
}
|
|
9
8
|
function createAppHotkeys(scope) {
|
|
10
9
|
return { get value() {
|
|
@@ -22,10 +21,7 @@ function createCustomHotkeys(scope) {
|
|
|
22
21
|
get value() {
|
|
23
22
|
return requireStore(scope).customHotkeys;
|
|
24
23
|
},
|
|
25
|
-
|
|
26
|
-
resetCustomHotkey: (id) => requireStore(scope).resetCustomHotkey(id),
|
|
27
|
-
resetCustomHotkeys: () => requireStore(scope).resetCustomHotkeys(),
|
|
28
|
-
findConflicts: (id, hotkey, recordedWith) => requireStore(scope).findConflicts(id, hotkey, recordedWith)
|
|
24
|
+
...bindCustomHotkeyActions(() => requireStore(scope))
|
|
29
25
|
};
|
|
30
26
|
}
|
|
31
27
|
|
|
@@ -1,15 +1,10 @@
|
|
|
1
1
|
import { createKeyboardLayout } from "./createKeyboardLayout.js";
|
|
2
|
-
import {
|
|
3
|
-
import { namesPhysicalKey } from "@tanstack/hotkeys/adapter";
|
|
2
|
+
import { createFormatForDisplay } from "@tanstack/hotkeys/adapter";
|
|
4
3
|
|
|
5
4
|
// src/createFormatForDisplay.ts
|
|
6
|
-
function createFormatForDisplay(scope) {
|
|
5
|
+
function createFormatForDisplay$1(scope) {
|
|
7
6
|
const layout = createKeyboardLayout(scope);
|
|
8
|
-
return ((
|
|
9
|
-
...options,
|
|
10
|
-
platform: options?.platform ?? scope.defaultOptions().platform,
|
|
11
|
-
layoutMap: options?.layoutMap ?? (namesPhysicalKey(hotkey) ? layout.value ?? void 0 : void 0)
|
|
12
|
-
}));
|
|
7
|
+
return createFormatForDisplay(() => scope.defaultOptions().platform, () => layout.value);
|
|
13
8
|
}
|
|
14
9
|
|
|
15
|
-
export { createFormatForDisplay };
|
|
10
|
+
export { createFormatForDisplay$1 as createFormatForDisplay };
|
package/dist/createHotkey.js
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
import { createHotkeys } from "./createHotkeys.js";
|
|
2
|
-
import {
|
|
2
|
+
import { resolveMaybeGetter } from "@tanstack/hotkeys/adapter";
|
|
3
3
|
|
|
4
4
|
// src/createHotkey.ts
|
|
5
5
|
function createHotkey(scope, hotkey, callback, options = {}) {
|
|
6
6
|
createHotkeys(scope, () => [{
|
|
7
|
-
hotkey:
|
|
7
|
+
hotkey: resolveMaybeGetter(hotkey),
|
|
8
8
|
callback,
|
|
9
|
-
options:
|
|
9
|
+
options: resolveMaybeGetter(options)
|
|
10
10
|
}]);
|
|
11
11
|
}
|
|
12
12
|
|
package/dist/createHotkeyHint.js
CHANGED
|
@@ -1,14 +1,15 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
1
|
+
import { getHotkeyManager, getKeyStateTracker, isAppHotkey } from "@tanstack/hotkeys";
|
|
2
|
+
import { isHotkeyHintVisible, resolveMaybeGetter } from "@tanstack/hotkeys/adapter";
|
|
3
3
|
|
|
4
4
|
// src/createHotkeyHint.ts
|
|
5
5
|
function createHotkeyHint(scope, hotkey, options = {}) {
|
|
6
6
|
const manager = getHotkeyManager();
|
|
7
7
|
const registrations = scope.select(manager.registrations, (state) => state);
|
|
8
8
|
return scope.select(getKeyStateTracker().store, (state) => {
|
|
9
|
-
const value =
|
|
10
|
-
|
|
11
|
-
|
|
9
|
+
const value = resolveMaybeGetter(hotkey);
|
|
10
|
+
registrations.value;
|
|
11
|
+
const appHotkeysStore = isAppHotkey(value) ? scope.appHotkeys() : null;
|
|
12
|
+
return isHotkeyHintVisible(value, state.heldKeys, resolveMaybeGetter(options), appHotkeysStore);
|
|
12
13
|
});
|
|
13
14
|
}
|
|
14
15
|
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { scopeOf } from "./scope.js";
|
|
2
2
|
import { HotkeyRecorder } from "@tanstack/hotkeys";
|
|
3
|
-
import { withDefaults } from "@tanstack/hotkeys/adapter";
|
|
3
|
+
import { resolveMaybeGetter, withDefaults } from "@tanstack/hotkeys/adapter";
|
|
4
4
|
|
|
5
5
|
// src/createHotkeyRecorder.ts
|
|
6
6
|
function createHotkeyRecorder(owner, options) {
|
|
@@ -8,7 +8,7 @@ function createHotkeyRecorder(owner, options) {
|
|
|
8
8
|
}
|
|
9
9
|
function createRecorder(scope, options) {
|
|
10
10
|
scope.assertActive();
|
|
11
|
-
const instance = new HotkeyRecorder(() => withDefaults(scope.defaultOptions().hotkeyRecorder,
|
|
11
|
+
const instance = new HotkeyRecorder(() => withDefaults(scope.defaultOptions().hotkeyRecorder, resolveMaybeGetter(options)));
|
|
12
12
|
const state = scope.select(instance.store, (value) => value);
|
|
13
13
|
scope.addCleanup(() => instance.destroy());
|
|
14
14
|
return {
|
|
@@ -1,8 +1,9 @@
|
|
|
1
|
-
import { getHotkeyManager
|
|
1
|
+
import { getHotkeyManager } from "@tanstack/hotkeys";
|
|
2
|
+
import { getHotkeyRegistrationViews } from "@tanstack/hotkeys/adapter";
|
|
2
3
|
|
|
3
4
|
// src/createHotkeyRegistrations.ts
|
|
4
5
|
function createHotkeyRegistrations(scope) {
|
|
5
|
-
const state = scope.select(getHotkeyManager().registrations, (value) =>
|
|
6
|
+
const state = scope.select(getHotkeyManager().registrations, (value) => getHotkeyRegistrationViews(value));
|
|
6
7
|
return { get hotkeys() {
|
|
7
8
|
return state.value;
|
|
8
9
|
} };
|
package/dist/createHotkeys.js
CHANGED
|
@@ -1,5 +1,4 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { createHotkeyBindings, prepareHotkeyDefinitions } from "@tanstack/hotkeys/adapter";
|
|
1
|
+
import { createHotkeyBindings, prepareHotkeyDefinitions, resolveMaybeGetter } from "@tanstack/hotkeys/adapter";
|
|
3
2
|
|
|
4
3
|
// src/createHotkeys.ts
|
|
5
4
|
function createHotkeys(scope, definitions, options = {}) {
|
|
@@ -7,10 +6,10 @@ function createHotkeys(scope, definitions, options = {}) {
|
|
|
7
6
|
const bindings = createHotkeyBindings();
|
|
8
7
|
scope.addCleanup(bindings.destroy);
|
|
9
8
|
try {
|
|
10
|
-
scope.effect(() => bindings.update(prepareHotkeyDefinitions(
|
|
9
|
+
scope.effect(() => bindings.update(prepareHotkeyDefinitions(resolveMaybeGetter(definitions), {
|
|
11
10
|
appHotkeysStore: scope.appHotkeys(),
|
|
12
11
|
defaults: scope.defaultOptions().hotkey,
|
|
13
|
-
commonOptions:
|
|
12
|
+
commonOptions: resolveMaybeGetter(options),
|
|
14
13
|
resolveTarget: (target) => target
|
|
15
14
|
})));
|
|
16
15
|
} catch (error) {
|
|
@@ -1,8 +1,9 @@
|
|
|
1
|
-
import { AlpineHotkeys, DefaultHotkeysOptions
|
|
1
|
+
import { AlpineHotkeys, DefaultHotkeysOptions } from "./types.js";
|
|
2
|
+
import { MaybeGetter } from "@tanstack/hotkeys";
|
|
2
3
|
/**
|
|
3
4
|
* Owns Alpine effects and Store subscriptions, with optional shared defaults.
|
|
4
5
|
* App hotkeys come from `provideAppHotkeys`. Call destroy from x-data's
|
|
5
6
|
* destroy hook.
|
|
6
7
|
*/
|
|
7
8
|
export declare function createHotkeysScope(defaultOptions?: MaybeGetter<DefaultHotkeysOptions>): AlpineHotkeys;
|
|
8
|
-
export type { AlpineHotkeys, DefaultHotkeysOptions
|
|
9
|
+
export type { AlpineHotkeys, DefaultHotkeysOptions };
|
package/dist/createKeyHold.js
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
import { read } from "./scope.js";
|
|
2
1
|
import { getKeyStateTracker } from "@tanstack/hotkeys";
|
|
2
|
+
import { resolveMaybeGetter } from "@tanstack/hotkeys/adapter";
|
|
3
3
|
|
|
4
4
|
// src/createKeyHold.ts
|
|
5
5
|
function createKeyHold(scope, key) {
|
|
6
6
|
const tracker = getKeyStateTracker();
|
|
7
|
-
return scope.select(tracker.store, () => tracker.isKeyHeld(
|
|
7
|
+
return scope.select(tracker.store, () => tracker.isKeyHeld(resolveMaybeGetter(key)));
|
|
8
8
|
}
|
|
9
9
|
|
|
10
10
|
export { createKeyHold };
|
package/dist/index.d.ts
CHANGED
|
@@ -3,6 +3,6 @@ import { formatForDisplay } from "./formatForDisplay.js";
|
|
|
3
3
|
import { hotkeysPlugin } from "./hotkeysPlugin.js";
|
|
4
4
|
import { createHotkeyRecorder } from "./createHotkeyRecorder.js";
|
|
5
5
|
import { hotkeyRecorderPlugin } from "./hotkeyRecorderPlugin.js";
|
|
6
|
-
import { AlpineAppHotkeyOptions, AlpineCreateHotkey, AlpineCreateHotkeyRecorder, AlpineCustomHotkeys, AlpineHotkeyCommonOptions, AlpineHotkeyDefinition, AlpineHotkeyOptionsFor, AlpineHotkeyRecorder, AlpineHotkeyState, AlpineHotkeyTarget, AlpineHotkeys, DefaultHotkeysOptions
|
|
6
|
+
import { AlpineAppHotkeyOptions, AlpineCreateHotkey, AlpineCreateHotkeyRecorder, AlpineCustomHotkeys, AlpineHotkeyCommonOptions, AlpineHotkeyDefinition, AlpineHotkeyOptionsFor, AlpineHotkeyRecorder, AlpineHotkeyState, AlpineHotkeyTarget, AlpineHotkeys, DefaultHotkeysOptions } from "./types.js";
|
|
7
7
|
export * from "@tanstack/hotkeys";
|
|
8
|
-
export { AlpineAppHotkeyOptions, AlpineCreateHotkey, AlpineCreateHotkeyRecorder, AlpineCustomHotkeys, AlpineHotkeyCommonOptions, AlpineHotkeyDefinition, AlpineHotkeyOptionsFor, AlpineHotkeyRecorder, AlpineHotkeyState, AlpineHotkeyTarget, AlpineHotkeys, DefaultHotkeysOptions,
|
|
8
|
+
export { AlpineAppHotkeyOptions, AlpineCreateHotkey, AlpineCreateHotkeyRecorder, AlpineCustomHotkeys, AlpineHotkeyCommonOptions, AlpineHotkeyDefinition, AlpineHotkeyOptionsFor, AlpineHotkeyRecorder, AlpineHotkeyState, AlpineHotkeyTarget, AlpineHotkeys, DefaultHotkeysOptions, createHotkeyRecorder, createHotkeysScope, formatForDisplay, hotkeyRecorderPlugin, hotkeysPlugin };
|
package/dist/scope.js
CHANGED
|
@@ -1,5 +1,4 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { mergeHotkeysProviderDefaults, subscribePublishedAppHotkeys } from "@tanstack/hotkeys/adapter";
|
|
1
|
+
import { getPublishedAppHotkeysStore, mergeHotkeysProviderDefaults, resolveMaybeGetter, subscribePublishedAppHotkeys } from "@tanstack/hotkeys/adapter";
|
|
3
2
|
|
|
4
3
|
// src/scope.ts
|
|
5
4
|
let pluginAlpine;
|
|
@@ -21,9 +20,6 @@ const ownerScopes = /* @__PURE__ */ new WeakMap();
|
|
|
21
20
|
function scopeOf(owner) {
|
|
22
21
|
return ownerScopes.get(getAlpine().raw(owner));
|
|
23
22
|
}
|
|
24
|
-
function read(value) {
|
|
25
|
-
return typeof value === "function" ? value() : value;
|
|
26
|
-
}
|
|
27
23
|
function createScope(defaultOptions) {
|
|
28
24
|
const cleanups = /* @__PURE__ */ new Set();
|
|
29
25
|
let destroyed = false;
|
|
@@ -74,14 +70,14 @@ function createScope(defaultOptions) {
|
|
|
74
70
|
cleanups.add(subscribePublishedAppHotkeys(() => state.version++));
|
|
75
71
|
}
|
|
76
72
|
appHotkeysState.version;
|
|
77
|
-
return
|
|
73
|
+
return getPublishedAppHotkeysStore();
|
|
78
74
|
}
|
|
79
75
|
return {
|
|
80
76
|
assertActive,
|
|
81
77
|
effect,
|
|
82
78
|
select,
|
|
83
79
|
appHotkeys,
|
|
84
|
-
defaultOptions: () => mergeHotkeysProviderDefaults(void 0,
|
|
80
|
+
defaultOptions: () => mergeHotkeysProviderDefaults(void 0, resolveMaybeGetter(defaultOptions), void 0),
|
|
85
81
|
addCleanup: (cleanup) => cleanups.add(cleanup),
|
|
86
82
|
get destroyed() {
|
|
87
83
|
return destroyed;
|
|
@@ -95,4 +91,4 @@ function createScope(defaultOptions) {
|
|
|
95
91
|
};
|
|
96
92
|
}
|
|
97
93
|
|
|
98
|
-
export { createScope, ownerScopes,
|
|
94
|
+
export { createScope, ownerScopes, scopeOf, setAlpine };
|
package/dist/types.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { AppHotkey,
|
|
2
|
-
import { AdapterAppHotkeyOptions, AdapterCommonOptions, AdapterHotkeyDefinition, AdapterOptionsFor } from "@tanstack/hotkeys/adapter";
|
|
1
|
+
import { AppHotkey, CustomHotkeyActions, CustomHotkeys, HeldModifierOptions, Hotkey, HotkeyCallback, HotkeyCallbackContextFor, HotkeyChord, HotkeyChordRecorderOptions, HotkeyPlatform, HotkeyRecorderActions, HotkeyRecorderOptions, HotkeyRecorderState, HotkeyRegistrationsResult, HotkeyScopesState, HotkeySequenceRecorderOptions, IndividualKey, KeyboardLayoutMap, MaybeGetter, RegisterableHotkey, RegisteredAppHotkeyListItem, RegisteredAppHotkeys, Target, formatForDisplay } from "@tanstack/hotkeys";
|
|
2
|
+
import { AdapterAppHotkeyOptions, AdapterCommonOptions, AdapterHotkeyDefinition, AdapterOptionsFor, HotkeyRecorderDefaults } from "@tanstack/hotkeys/adapter";
|
|
3
3
|
/** A reactive value. Read `.value` where the framework tracks dependencies. */
|
|
4
4
|
export interface AlpineHotkeyState<T> {
|
|
5
5
|
readonly value: T;
|
|
@@ -18,50 +18,12 @@ export type AlpineHotkeyOptionsFor<T extends RegisterableHotkey> = AdapterOption
|
|
|
18
18
|
/** Call-site options for an app hotkey, typed by its declared default kind. */
|
|
19
19
|
export type AlpineAppHotkeyOptions<T extends AppHotkey = AppHotkey> = AdapterAppHotkeyOptions<T, AlpineHotkeyTarget>;
|
|
20
20
|
/** Recording state and controls owned by the containing scope. */
|
|
21
|
-
export interface AlpineHotkeyRecorder<THotkey extends Hotkey = Hotkey> {
|
|
22
|
-
/** Whether the recorder is listening for a shortcut. */
|
|
23
|
-
readonly isRecording: boolean;
|
|
24
|
-
/** Chords captured so far in a multi-step recording. */
|
|
25
|
-
readonly steps: HotkeySequence;
|
|
26
|
-
/** The last committed hotkey, including brackets for physical codes. */
|
|
27
|
-
readonly recordedHotkey: THotkey | null;
|
|
28
|
-
/** Start a new recording session. */
|
|
29
|
-
startRecording: () => void;
|
|
30
|
-
/** Stop and clear recorder state without calling onRecord or onCancel. */
|
|
31
|
-
stopRecording: () => void;
|
|
32
|
-
/** Stop, clear recorder state, and call onCancel. */
|
|
33
|
-
cancelRecording: () => void;
|
|
34
|
-
/** Commit the current steps (multi-step recordings). */
|
|
35
|
-
commitRecording: () => void;
|
|
36
|
-
}
|
|
37
|
-
/** Live registration views from the shared hotkey manager. */
|
|
38
|
-
export interface HotkeyRegistrationsResult {
|
|
39
|
-
/** Every registration, chords and sequences. Narrow each view with `kind`. */
|
|
40
|
-
readonly hotkeys: Array<HotkeyRegistrationView>;
|
|
41
|
-
}
|
|
21
|
+
export interface AlpineHotkeyRecorder<THotkey extends Hotkey = Hotkey> extends Readonly<HotkeyRecorderState<THotkey>>, HotkeyRecorderActions {}
|
|
42
22
|
/** Custom hotkey state and actions. */
|
|
43
|
-
export interface AlpineCustomHotkeys {
|
|
23
|
+
export interface AlpineCustomHotkeys extends CustomHotkeyActions {
|
|
44
24
|
/** The user's hotkeys that differ from the defaults. */
|
|
45
25
|
readonly value: CustomHotkeys;
|
|
46
|
-
/**
|
|
47
|
-
* Sets the user's hotkey for an app hotkey. `null` unbinds it.
|
|
48
|
-
* Returns conflicting app hotkeys; when any exist, nothing changes. Pass
|
|
49
|
-
* the recorder's `context` for a recorded hotkey, as for `findConflicts`.
|
|
50
|
-
*/
|
|
51
|
-
setCustomHotkey: (id: keyof RegisteredAppHotkeys & string, hotkey: Hotkey | null, recordedWith?: RecordedKeyPresses) => Array<AppHotkey>;
|
|
52
|
-
/** Restores the default hotkey for an app hotkey. */
|
|
53
|
-
resetCustomHotkey: (id: keyof RegisteredAppHotkeys & string) => void;
|
|
54
|
-
/** Restores every default hotkey. */
|
|
55
|
-
resetCustomHotkeys: () => void;
|
|
56
|
-
/**
|
|
57
|
-
* Other app hotkeys that would collide if `id` used `hotkey`. Pass the
|
|
58
|
-
* recorder's `context` for a recorded hotkey: it has the key press, which
|
|
59
|
-
* also finds a hotkey written differently that the same press fires.
|
|
60
|
-
*/
|
|
61
|
-
findConflicts: (id: keyof RegisteredAppHotkeys & string, hotkey: Hotkey, recordedWith?: RecordedKeyPresses) => Array<AppHotkey>;
|
|
62
26
|
}
|
|
63
|
-
/** A value or a getter evaluated within an Alpine effect or reactive read. */
|
|
64
|
-
export type MaybeGetter<T> = T | (() => T);
|
|
65
27
|
/** Registers a hotkey: a chord, a sequence, or an app hotkey. */
|
|
66
28
|
export interface AlpineCreateHotkey {
|
|
67
29
|
<T extends AppHotkey>(hotkey: MaybeGetter<T | null | undefined>, callback: HotkeyCallback, options?: MaybeGetter<AlpineAppHotkeyOptions<T>>): void;
|
|
@@ -168,7 +130,7 @@ export interface AlpineHotkeys {
|
|
|
168
130
|
/** Read the effective app hotkeys from `provideAppHotkeys` through `.value`. */
|
|
169
131
|
createAppHotkeys: () => AlpineHotkeyState<RegisteredAppHotkeys>;
|
|
170
132
|
/** Read every app hotkey with its live status through `.value`. */
|
|
171
|
-
createAppHotkeyList: () => AlpineHotkeyState<Array<
|
|
133
|
+
createAppHotkeyList: () => AlpineHotkeyState<Array<RegisteredAppHotkeyListItem>>;
|
|
172
134
|
/** Read and change the user's custom hotkeys. */
|
|
173
135
|
createCustomHotkeys: () => AlpineCustomHotkeys;
|
|
174
136
|
/** Release every registration, subscription, effect, and recorder. Idempotent. */
|
|
@@ -193,5 +155,5 @@ export interface DefaultHotkeysOptions {
|
|
|
193
155
|
/** Defaults for every hotkey. `requireReset` applies to chords and `timeout` to sequences. */
|
|
194
156
|
hotkey?: AlpineHotkeyCommonOptions;
|
|
195
157
|
/** Defaults for every recorder. */
|
|
196
|
-
hotkeyRecorder?:
|
|
158
|
+
hotkeyRecorder?: HotkeyRecorderDefaults;
|
|
197
159
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tanstack/alpine-hotkeys",
|
|
3
|
-
"version": "0.14.
|
|
3
|
+
"version": "0.14.1",
|
|
4
4
|
"description": "Alpine 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.30.0"
|
|
39
39
|
},
|
|
40
40
|
"devDependencies": {
|
|
41
41
|
"@tanstack/hotkeys-test-utils": "0.0.0",
|