@tanstack/ember-hotkeys 0.8.1 → 0.10.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/createHotkeysScope.d.ts +6 -4
- package/dist/createHotkeysScope.js +12 -11
- package/dist/index.d.ts +4 -3
- package/dist/index.js +2 -1
- package/dist/types.d.ts +8 -1
- package/dist/useFormatForDisplay.d.ts +25 -0
- package/dist/useFormatForDisplay.js +33 -0
- package/dist/useHotkeyHint.js +3 -2
- package/dist/useHotkeyRecorder.d.ts +8 -5
- package/dist/useHotkeyRecorder.js +4 -3
- package/dist/utils.d.ts +1 -0
- package/dist/utils.js +12 -4
- package/package.json +2 -2
- package/skills/ember-hotkeys/SKILL.md +6 -2
|
@@ -2,20 +2,22 @@ import { DefaultHotkeysOptions } from "./types.js";
|
|
|
2
2
|
import { UseHotkey } from "./useHotkey.js";
|
|
3
3
|
import { UseHotkeys } from "./useHotkeys.js";
|
|
4
4
|
import { MaybeGetter } from "./utils.js";
|
|
5
|
-
import { useHotkeyRecorder } from "./useHotkeyRecorder.js";
|
|
6
5
|
import { OnHotkeys } from "./onHotkeys.js";
|
|
7
6
|
import { OnHotkey } from "./onHotkey.js";
|
|
8
7
|
//#region src/createHotkeysScope.d.ts
|
|
9
|
-
/**
|
|
8
|
+
/**
|
|
9
|
+
* Helpers and modifiers with shared defaults. Owners retain their own cleanup.
|
|
10
|
+
* Pass the scope to `useHotkeyRecorder` to apply its recorder defaults, and to
|
|
11
|
+
* `useFormatForDisplay` to apply its `platform`.
|
|
12
|
+
*/
|
|
10
13
|
export interface EmberHotkeysScope {
|
|
11
14
|
onHotkey: typeof OnHotkey;
|
|
12
15
|
onHotkeys: typeof OnHotkeys;
|
|
13
16
|
useHotkey: typeof UseHotkey;
|
|
14
17
|
useHotkeys: typeof UseHotkeys;
|
|
15
|
-
useHotkeyRecorder: typeof useHotkeyRecorder;
|
|
16
18
|
}
|
|
17
19
|
/**
|
|
18
|
-
* Creates contextual helpers
|
|
20
|
+
* Creates contextual helpers and modifiers with shared, optionally reactive defaults.
|
|
19
21
|
* Pass the scope to child components through arguments to share configuration.
|
|
20
22
|
*/
|
|
21
23
|
export declare function createHotkeysScope(defaultOptions?: MaybeGetter<DefaultHotkeysOptions>): EmberHotkeysScope;
|
|
@@ -1,40 +1,41 @@
|
|
|
1
1
|
import { UseHotkey } from "./useHotkey.js";
|
|
2
2
|
import { UseHotkeys } from "./useHotkeys.js";
|
|
3
|
-
import { read } from "./utils.js";
|
|
4
|
-
import { useHotkeyRecorder } from "./useHotkeyRecorder.js";
|
|
3
|
+
import { read, scopeDefaults } from "./utils.js";
|
|
5
4
|
import { OnHotkey } from "./onHotkey.js";
|
|
6
5
|
import { OnHotkeys } from "./onHotkeys.js";
|
|
7
|
-
import { definedOptions,
|
|
6
|
+
import { definedOptions, mergeHotkeysProviderDefaults } from "@tanstack/hotkeys/adapter";
|
|
8
7
|
|
|
9
8
|
//#region src/createHotkeysScope.ts
|
|
10
9
|
/**
|
|
11
|
-
* Creates contextual helpers
|
|
10
|
+
* Creates contextual helpers and modifiers with shared, optionally reactive defaults.
|
|
12
11
|
* Pass the scope to child components through arguments to share configuration.
|
|
13
12
|
*/
|
|
14
13
|
function createHotkeysScope(defaultOptions = {}) {
|
|
15
|
-
|
|
14
|
+
const defaults = () => mergeHotkeysProviderDefaults(void 0, read(defaultOptions), void 0);
|
|
15
|
+
const scope = {
|
|
16
16
|
onHotkey: class extends OnHotkey {
|
|
17
17
|
modify(...[element, args, options]) {
|
|
18
|
-
super.modify(element, args, { ...definedOptions(
|
|
18
|
+
super.modify(element, args, { ...definedOptions(defaults().hotkey, options) });
|
|
19
19
|
}
|
|
20
20
|
},
|
|
21
21
|
onHotkeys: class extends OnHotkeys {
|
|
22
22
|
modify(...[element, args, options]) {
|
|
23
|
-
super.modify(element, args, { ...definedOptions(
|
|
23
|
+
super.modify(element, args, { ...definedOptions(defaults().hotkey, options) });
|
|
24
24
|
}
|
|
25
25
|
},
|
|
26
26
|
useHotkey: class extends UseHotkey {
|
|
27
27
|
compute(...[args, options]) {
|
|
28
|
-
super.compute(args, { ...definedOptions(
|
|
28
|
+
super.compute(args, { ...definedOptions(defaults().hotkey, options) });
|
|
29
29
|
}
|
|
30
30
|
},
|
|
31
31
|
useHotkeys: class extends UseHotkeys {
|
|
32
32
|
compute(...[args, options]) {
|
|
33
|
-
super.compute(args, { ...definedOptions(
|
|
33
|
+
super.compute(args, { ...definedOptions(defaults().hotkey, options) });
|
|
34
34
|
}
|
|
35
|
-
}
|
|
36
|
-
useHotkeyRecorder: ((owner, options) => useHotkeyRecorder(owner, () => withDefaults(read(defaultOptions).hotkeyRecorder, read(options))))
|
|
35
|
+
}
|
|
37
36
|
};
|
|
37
|
+
scopeDefaults.set(scope, defaults);
|
|
38
|
+
return scope;
|
|
38
39
|
}
|
|
39
40
|
|
|
40
41
|
//#endregion
|
package/dist/index.d.ts
CHANGED
|
@@ -8,10 +8,11 @@ import { useKeyHold } from "./useKeyHold.js";
|
|
|
8
8
|
import { useHotkeyHint } from "./useHotkeyHint.js";
|
|
9
9
|
import { useHotkeyRegistrations } from "./useHotkeyRegistrations.js";
|
|
10
10
|
import { useHotkeyScopesState } from "./useHotkeyScopesState.js";
|
|
11
|
-
import { useHotkeyRecorder } from "./useHotkeyRecorder.js";
|
|
12
|
-
import { useAppHotkeyList, useAppHotkeys, useCustomHotkeys } from "./useAppHotkeys.js";
|
|
13
11
|
import { ElementHotkeyOptions, OnHotkeys } from "./onHotkeys.js";
|
|
14
12
|
import { OnHotkey } from "./onHotkey.js";
|
|
15
13
|
import { EmberHotkeysScope, createHotkeysScope } from "./createHotkeysScope.js";
|
|
14
|
+
import { useHotkeyRecorder } from "./useHotkeyRecorder.js";
|
|
15
|
+
import { useAppHotkeyList, useAppHotkeys, useCustomHotkeys } from "./useAppHotkeys.js";
|
|
16
|
+
import { useFormatForDisplay } from "./useFormatForDisplay.js";
|
|
16
17
|
export * from "@tanstack/hotkeys";
|
|
17
|
-
export { DefaultHotkeysOptions, type ElementHotkeyOptions, EmberAppHotkeyList, EmberCustomHotkeys, EmberHotkeyCommonOptions, EmberHotkeyDefinition, EmberHotkeyRecorder, EmberHotkeyState, EmberHotkeyTarget, EmberHotkeysScope, HotkeyRegistrationsResult, type MaybeGetter, createHotkeysScope, OnHotkey as onHotkey, OnHotkeys as onHotkeys, useAppHotkeyList, useAppHotkeys, useCustomHotkeys, useHeldKeyCodes, useHeldKeys, UseHotkey as useHotkey, useHotkeyHint, useHotkeyRecorder, useHotkeyRegistrations, useHotkeyScopesState, UseHotkeys as useHotkeys, useKeyHold };
|
|
18
|
+
export { DefaultHotkeysOptions, type ElementHotkeyOptions, EmberAppHotkeyList, EmberCustomHotkeys, EmberHotkeyCommonOptions, EmberHotkeyDefinition, EmberHotkeyRecorder, EmberHotkeyState, EmberHotkeyTarget, EmberHotkeysScope, HotkeyRegistrationsResult, type MaybeGetter, createHotkeysScope, OnHotkey as onHotkey, OnHotkeys as onHotkeys, useAppHotkeyList, useAppHotkeys, useCustomHotkeys, useFormatForDisplay, useHeldKeyCodes, useHeldKeys, UseHotkey as useHotkey, useHotkeyHint, useHotkeyRecorder, useHotkeyRegistrations, useHotkeyScopesState, UseHotkeys as useHotkeys, useKeyHold };
|
package/dist/index.js
CHANGED
|
@@ -8,10 +8,11 @@ import { useHotkeyRegistrations } from "./useHotkeyRegistrations.js";
|
|
|
8
8
|
import { useHotkeyScopesState } from "./useHotkeyScopesState.js";
|
|
9
9
|
import { useHotkeyRecorder } from "./useHotkeyRecorder.js";
|
|
10
10
|
import { useAppHotkeyList, useAppHotkeys, useCustomHotkeys } from "./useAppHotkeys.js";
|
|
11
|
+
import { useFormatForDisplay } from "./useFormatForDisplay.js";
|
|
11
12
|
import { OnHotkey } from "./onHotkey.js";
|
|
12
13
|
import { OnHotkeys } from "./onHotkeys.js";
|
|
13
14
|
import { createHotkeysScope } from "./createHotkeysScope.js";
|
|
14
15
|
|
|
15
16
|
export * from "@tanstack/hotkeys"
|
|
16
17
|
|
|
17
|
-
export { createHotkeysScope, OnHotkey as onHotkey, OnHotkeys as onHotkeys, useAppHotkeyList, useAppHotkeys, useCustomHotkeys, useHeldKeyCodes, useHeldKeys, UseHotkey as useHotkey, useHotkeyHint, useHotkeyRecorder, useHotkeyRegistrations, useHotkeyScopesState, UseHotkeys as useHotkeys, useKeyHold };
|
|
18
|
+
export { createHotkeysScope, OnHotkey as onHotkey, OnHotkeys as onHotkeys, useAppHotkeyList, useAppHotkeys, useCustomHotkeys, useFormatForDisplay, useHeldKeyCodes, useHeldKeys, UseHotkey as useHotkey, useHotkeyHint, useHotkeyRecorder, useHotkeyRegistrations, useHotkeyScopesState, UseHotkeys as useHotkeys, useKeyHold };
|
package/dist/types.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { AppHotkey, AppHotkeyListItem, CustomHotkeys, Hotkey, HotkeyChordRecorderOptions, HotkeyRegistrationView, HotkeySequence, HotkeySequenceRecorderOptions, RegisteredAppHotkeys, Target } from "@tanstack/hotkeys";
|
|
1
|
+
import { AppHotkey, AppHotkeyListItem, CustomHotkeys, Hotkey, HotkeyChordRecorderOptions, HotkeyPlatform, HotkeyRegistrationView, HotkeySequence, HotkeySequenceRecorderOptions, RegisteredAppHotkeys, Target } from "@tanstack/hotkeys";
|
|
2
2
|
import { AdapterCommonOptions, AdapterHotkeyDefinition } from "@tanstack/hotkeys/adapter";
|
|
3
3
|
//#region src/types.d.ts
|
|
4
4
|
/** A reactive value. Read `.value` where the framework tracks dependencies. */
|
|
@@ -53,6 +53,13 @@ export interface EmberCustomHotkeys {
|
|
|
53
53
|
}
|
|
54
54
|
/** Shared defaults; call-specific options take precedence. */
|
|
55
55
|
export interface DefaultHotkeysOptions {
|
|
56
|
+
/**
|
|
57
|
+
* The user's platform, for labels from `useFormatForDisplay`, hotkeys, and
|
|
58
|
+
* recorders. `hotkey.platform` and `hotkeyRecorder.platform` win. Detected
|
|
59
|
+
* when unset. On a server, set it from the request with
|
|
60
|
+
* `detectPlatform(userAgent)`.
|
|
61
|
+
*/
|
|
62
|
+
platform?: HotkeyPlatform;
|
|
56
63
|
/** Defaults for every hotkey. `requireReset` applies to chords and `timeout` to sequences. */
|
|
57
64
|
hotkey?: EmberHotkeyCommonOptions;
|
|
58
65
|
/** Defaults for every recorder. */
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { EmberHotkeysScope } from "./createHotkeysScope.js";
|
|
2
|
+
import { formatForDisplay } from "@tanstack/hotkeys";
|
|
3
|
+
//#region src/useFormatForDisplay.d.ts
|
|
4
|
+
/**
|
|
5
|
+
* Returns `formatForDisplay` with the scope's `platform` as the default, so
|
|
6
|
+
* labels match the user's platform. The returned function works anywhere,
|
|
7
|
+
* including templates, and reads the scope's defaults when called, so
|
|
8
|
+
* templates update when they change. An explicit `platform` option wins.
|
|
9
|
+
*
|
|
10
|
+
* Server-rendered apps should set the scope's default `platform` from the
|
|
11
|
+
* request user agent, such as
|
|
12
|
+
* `detectPlatform(fastboot.request.headers.get('user-agent'))` with the
|
|
13
|
+
* FastBoot service.
|
|
14
|
+
*
|
|
15
|
+
* @example
|
|
16
|
+
* ```gts
|
|
17
|
+
* class SaveButton extends Component<{ Args: { hotkeys: EmberHotkeysScope } }> {
|
|
18
|
+
* format = useFormatForDisplay(this.args.hotkeys)
|
|
19
|
+
*
|
|
20
|
+
* <template><kbd>{{this.format "Mod+S"}}</kbd></template>
|
|
21
|
+
* }
|
|
22
|
+
* ```
|
|
23
|
+
*/
|
|
24
|
+
export declare function useFormatForDisplay(scope?: EmberHotkeysScope): typeof formatForDisplay;
|
|
25
|
+
//#endregion
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import { scopeDefaults } from "./utils.js";
|
|
2
|
+
import { formatForDisplay } from "@tanstack/hotkeys";
|
|
3
|
+
|
|
4
|
+
//#region src/useFormatForDisplay.ts
|
|
5
|
+
/**
|
|
6
|
+
* Returns `formatForDisplay` with the scope's `platform` as the default, so
|
|
7
|
+
* labels match the user's platform. The returned function works anywhere,
|
|
8
|
+
* including templates, and reads the scope's defaults when called, so
|
|
9
|
+
* templates update when they change. An explicit `platform` option wins.
|
|
10
|
+
*
|
|
11
|
+
* Server-rendered apps should set the scope's default `platform` from the
|
|
12
|
+
* request user agent, such as
|
|
13
|
+
* `detectPlatform(fastboot.request.headers.get('user-agent'))` with the
|
|
14
|
+
* FastBoot service.
|
|
15
|
+
*
|
|
16
|
+
* @example
|
|
17
|
+
* ```gts
|
|
18
|
+
* class SaveButton extends Component<{ Args: { hotkeys: EmberHotkeysScope } }> {
|
|
19
|
+
* format = useFormatForDisplay(this.args.hotkeys)
|
|
20
|
+
*
|
|
21
|
+
* <template><kbd>{{this.format "Mod+S"}}</kbd></template>
|
|
22
|
+
* }
|
|
23
|
+
* ```
|
|
24
|
+
*/
|
|
25
|
+
function useFormatForDisplay(scope) {
|
|
26
|
+
return ((hotkey, options) => formatForDisplay(hotkey, {
|
|
27
|
+
...options,
|
|
28
|
+
platform: options?.platform ?? (scope && scopeDefaults.get(scope)().platform)
|
|
29
|
+
}));
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
//#endregion
|
|
33
|
+
export { useFormatForDisplay };
|
package/dist/useHotkeyHint.js
CHANGED
|
@@ -13,11 +13,12 @@ import { getHotkeyManager, getKeyStateTracker, isAppHotkey, matchesHeldModifiers
|
|
|
13
13
|
function useHotkeyHint(owner, hotkey, options = {}) {
|
|
14
14
|
const appHotkeys = trackPublishedAppHotkeys(owner);
|
|
15
15
|
const manager = getHotkeyManager();
|
|
16
|
-
const
|
|
16
|
+
const active = select(owner, manager.registrations, () => manager.hasActiveRegistration(read(hotkey)));
|
|
17
17
|
return select(owner, getKeyStateTracker().store, (state) => {
|
|
18
|
+
const isActive = active.value;
|
|
18
19
|
const value = read(hotkey);
|
|
19
20
|
const resolved = isAppHotkey(value) ? resolveAppHotkey(value, appHotkeys()).hotkey : value;
|
|
20
|
-
return resolved !== null && matchesHeldModifiers(resolved, state.heldKeys, read(options)) &&
|
|
21
|
+
return resolved !== null && matchesHeldModifiers(resolved, state.heldKeys, read(options)) && isActive;
|
|
21
22
|
});
|
|
22
23
|
}
|
|
23
24
|
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { EmberHotkeyRecorder } from "./types.js";
|
|
2
|
+
import { EmberHotkeysScope } from "./createHotkeysScope.js";
|
|
2
3
|
import { HotkeyChord, HotkeyChordRecorderOptions, HotkeyRecorderOptions, HotkeySequenceRecorderOptions } from "@tanstack/hotkeys";
|
|
3
4
|
//#region src/useHotkeyRecorder.d.ts
|
|
4
5
|
/**
|
|
@@ -7,10 +8,12 @@ import { HotkeyChord, HotkeyChordRecorderOptions, HotkeyRecorderOptions, HotkeyS
|
|
|
7
8
|
* With a larger `maxSteps`, each chord adds a step; the recording commits on
|
|
8
9
|
* Enter (unless `commitKeys: 'none'`), after `idleTimeoutMs`, or at
|
|
9
10
|
* `maxSteps`, and `onRecord` receives a chord (one step) or a sequence.
|
|
11
|
+
* Pass a scope from `createHotkeysScope` to apply its `hotkeyRecorder`
|
|
12
|
+
* defaults.
|
|
10
13
|
*/
|
|
11
|
-
export declare function useHotkeyRecorder(owner: object, options: HotkeyChordRecorderOptions): EmberHotkeyRecorder<HotkeyChord>;
|
|
12
|
-
export declare function useHotkeyRecorder(owner: object, options: HotkeySequenceRecorderOptions): EmberHotkeyRecorder;
|
|
13
|
-
export declare function useHotkeyRecorder(owner: object, options: () => HotkeySequenceRecorderOptions): EmberHotkeyRecorder;
|
|
14
|
-
export declare function useHotkeyRecorder(owner: object, options: () => HotkeyChordRecorderOptions): EmberHotkeyRecorder<HotkeyChord>;
|
|
15
|
-
export declare function useHotkeyRecorder(owner: object, options: () => HotkeyRecorderOptions): EmberHotkeyRecorder;
|
|
14
|
+
export declare function useHotkeyRecorder(owner: object, options: HotkeyChordRecorderOptions, scope?: EmberHotkeysScope): EmberHotkeyRecorder<HotkeyChord>;
|
|
15
|
+
export declare function useHotkeyRecorder(owner: object, options: HotkeySequenceRecorderOptions, scope?: EmberHotkeysScope): EmberHotkeyRecorder;
|
|
16
|
+
export declare function useHotkeyRecorder(owner: object, options: () => HotkeySequenceRecorderOptions, scope?: EmberHotkeysScope): EmberHotkeyRecorder;
|
|
17
|
+
export declare function useHotkeyRecorder(owner: object, options: () => HotkeyChordRecorderOptions, scope?: EmberHotkeysScope): EmberHotkeyRecorder<HotkeyChord>;
|
|
18
|
+
export declare function useHotkeyRecorder(owner: object, options: () => HotkeyRecorderOptions, scope?: EmberHotkeysScope): EmberHotkeyRecorder;
|
|
16
19
|
//#endregion
|
|
@@ -1,10 +1,11 @@
|
|
|
1
|
-
import { read, select } from "./utils.js";
|
|
1
|
+
import { read, scopeDefaults, select } from "./utils.js";
|
|
2
2
|
import { HotkeyRecorder } from "@tanstack/hotkeys";
|
|
3
3
|
import { isDestroyed, isDestroying, registerDestructor } from "@ember/destroyable";
|
|
4
|
+
import { withDefaults } from "@tanstack/hotkeys/adapter";
|
|
4
5
|
|
|
5
6
|
//#region src/useHotkeyRecorder.ts
|
|
6
|
-
function useHotkeyRecorder(owner, options) {
|
|
7
|
-
const recorder = new HotkeyRecorder(() => read(options));
|
|
7
|
+
function useHotkeyRecorder(owner, options, scope) {
|
|
8
|
+
const recorder = new HotkeyRecorder(() => withDefaults(scope && scopeDefaults.get(scope)().hotkeyRecorder, read(options)));
|
|
8
9
|
const state = select(owner, recorder.store, (value) => value);
|
|
9
10
|
registerDestructor(owner, () => recorder.destroy());
|
|
10
11
|
return {
|
package/dist/utils.d.ts
CHANGED
package/dist/utils.js
CHANGED
|
@@ -4,17 +4,25 @@ import { subscribePublishedAppHotkeys } from "@tanstack/hotkeys/adapter";
|
|
|
4
4
|
import { trackedObject } from "@ember/reactive/collections";
|
|
5
5
|
|
|
6
6
|
//#region src/utils.ts
|
|
7
|
+
/** Reads the merged defaults behind each `createHotkeysScope` result. */
|
|
8
|
+
const scopeDefaults = /* @__PURE__ */ new WeakMap();
|
|
7
9
|
function read(value) {
|
|
8
10
|
return typeof value === "function" ? value() : value;
|
|
9
11
|
}
|
|
10
12
|
function select(owner, store, selector) {
|
|
11
|
-
const state = trackedObject({
|
|
13
|
+
const state = trackedObject({ version: 0 });
|
|
14
|
+
let last;
|
|
12
15
|
const subscription = store.subscribe(() => {
|
|
13
|
-
|
|
16
|
+
const next = selector(store.state);
|
|
17
|
+
if (!Object.is(next, last)) {
|
|
18
|
+
last = next;
|
|
19
|
+
state.version++;
|
|
20
|
+
}
|
|
14
21
|
});
|
|
15
22
|
registerDestructor(owner, () => subscription.unsubscribe());
|
|
16
23
|
return { get value() {
|
|
17
|
-
|
|
24
|
+
state.version;
|
|
25
|
+
return last = selector(store.state);
|
|
18
26
|
} };
|
|
19
27
|
}
|
|
20
28
|
/**
|
|
@@ -33,4 +41,4 @@ function trackPublishedAppHotkeys(owner) {
|
|
|
33
41
|
}
|
|
34
42
|
|
|
35
43
|
//#endregion
|
|
36
|
-
export { read, select, trackPublishedAppHotkeys };
|
|
44
|
+
export { read, scopeDefaults, select, trackPublishedAppHotkeys };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tanstack/ember-hotkeys",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.10.0",
|
|
4
4
|
"description": "Ember adapter for TanStack Hotkeys",
|
|
5
5
|
"author": "Tanner Linsley",
|
|
6
6
|
"license": "MIT",
|
|
@@ -40,7 +40,7 @@
|
|
|
40
40
|
],
|
|
41
41
|
"dependencies": {
|
|
42
42
|
"@embroider/addon-shim": "^1.10.3",
|
|
43
|
-
"@tanstack/hotkeys": "0.
|
|
43
|
+
"@tanstack/hotkeys": "0.23.0",
|
|
44
44
|
"ember-modifier": "^4.2.2"
|
|
45
45
|
},
|
|
46
46
|
"devDependencies": {
|
|
@@ -21,6 +21,7 @@ sources:
|
|
|
21
21
|
- src/onHotkey.ts
|
|
22
22
|
- src/onHotkeys.ts
|
|
23
23
|
- src/createHotkeysScope.ts
|
|
24
|
+
- src/useHotkeyRecorder.ts
|
|
24
25
|
- src/useAppHotkeys.ts
|
|
25
26
|
- TanStack/hotkeys:docs/framework/ember/quick-start.md
|
|
26
27
|
- TanStack/hotkeys:docs/framework/ember/guides/app-hotkeys.md
|
|
@@ -60,13 +61,14 @@ export default class Editor extends Component {
|
|
|
60
61
|
| `{{useHotkeys definitions}}` | Register several hotkeys, or a list built from data, in one helper. |
|
|
61
62
|
| `{{onHotkey hotkey callback ...options}}` | Attach a hotkey to the element the modifier is on, so it fires while focus is inside that element. |
|
|
62
63
|
| `{{onHotkeys definitions}}` | Attach several hotkeys to one element. |
|
|
63
|
-
| `createHotkeysScope(defaults?)` | Create `useHotkey`, `useHotkeys`, `onHotkey`,
|
|
64
|
+
| `createHotkeysScope(defaults?)` | Create `useHotkey`, `useHotkeys`, `onHotkey`, and `onHotkeys` that share default options. |
|
|
65
|
+
| `useFormatForDisplay(scope?)` | Get `formatForDisplay` with the scope's `platform` filled in, for labels rendered by FastBoot. |
|
|
64
66
|
| `provideAppHotkeys(appHotkeys, options?)` | Declare app hotkeys and load the user's custom hotkeys before the app boots, since Ember has no provider. |
|
|
65
67
|
| `getHotkeyManager().activateScope(scope, options?)` | Turn on a scope, such as an exclusive one for a dialog; it returns the function that turns the scope off. |
|
|
66
68
|
| `useAppHotkeys(this)` | Get the declared app hotkeys with the user's custom hotkeys applied. |
|
|
67
69
|
| `useAppHotkeyList(this)` | List every app hotkey with its status, for a cheat sheet or settings screen. |
|
|
68
70
|
| `useCustomHotkeys(this)` | Read, change, and reset the user's custom hotkeys, and check a new one for conflicts. |
|
|
69
|
-
| `useHotkeyRecorder(this, options)`
|
|
71
|
+
| `useHotkeyRecorder(this, options, scope?)` | Record a chord or sequence the user presses, for a settings screen. Pass a `createHotkeysScope` result to apply its `hotkeyRecorder` defaults. |
|
|
70
72
|
| `useHotkeyRegistrations(this)` | Read `.hotkeys`, every registered hotkey with its options, `meta`, and `status` (whether it's enabled and in an active scope). |
|
|
71
73
|
| `useHotkeyScopesState(this)` | Get the active scopes and the exclusive scope that owns the keyboard. |
|
|
72
74
|
| `useHotkeyHint(this, hotkey, options?)` | Get 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. |
|
|
@@ -84,6 +86,8 @@ The helpers are template helpers, not JavaScript functions. State readers take t
|
|
|
84
86
|
- **Build template sequences with `array`.** `{{useHotkey "G G" ...}}` registers a single key named `G G`, which never matches.
|
|
85
87
|
- **`createHotkeysScope` isn't a hotkey scope.** It only sets defaults for its helpers. For a dialog, call `getHotkeyManager().activateScope(name, { exclusive: true })` in the constructor, pass the result to `registerDestructor(this, release)`, and put `scope=name` on the dialog's hotkeys. Give each open dialog its own name.
|
|
86
88
|
- **Read app hotkeys through getters.** Template paths can't index ids that contain dots.
|
|
89
|
+
- **Scopes have no `useHotkeyRecorder`** since v0.9.0. Call `useHotkeyRecorder(this, options, this.hotkeys)`, so apps that set defaults but don't record don't ship the recorder.
|
|
90
|
+
- **Server-rendered labels need the user's platform.** On the server, `formatForDisplay` can't see the user's OS, so it renders Linux labels that differ after hydration for Mac and Windows users. Pass `platform: detectPlatform(userAgent)` to `createHotkeysScope`, with the user agent from FastBoot's request, and format labels with `format = useFormatForDisplay(this.hotkeys)`, then `{{this.format hotkey}}`. Keep plain `formatForDisplay` for labels that render only in the browser.
|
|
87
91
|
|
|
88
92
|
When declaring app hotkeys, building a cheat sheet, or letting users rebind shortcuts, load `@tanstack/hotkeys#app-hotkeys` and read [app hotkeys in Ember](references/app-hotkeys.md).
|
|
89
93
|
|