@tanstack/ember-hotkeys 0.14.5 → 0.15.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/_formatter.js +29 -0
- package/dist/_registrations.js +28 -0
- package/dist/bindings.js +17 -2
- package/dist/createHotkeysScope.js +8 -21
- package/dist/formatForAria.d.ts +11 -0
- package/dist/formatForAria.js +14 -0
- package/dist/index.d.ts +3 -1
- package/dist/index.js +3 -1
- package/dist/keyboardLayout.js +3 -3
- package/dist/tracked.js +16 -0
- package/dist/useFormatForAria.d.ts +34 -0
- package/dist/useFormatForAria.js +42 -0
- package/dist/useFormatForDisplay.js +3 -18
- package/dist/utils.js +3 -3
- package/package.json +3 -3
- package/skills/ember-hotkeys/SKILL.md +23 -22
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import { layoutEnabled, requestLayout, trackedLayout, untilRendered } from "./keyboardLayout.js";
|
|
2
|
+
import { scopeDefaults } from "./utils.js";
|
|
3
|
+
import { createFormatter } from "@tanstack/hotkeys/adapter";
|
|
4
|
+
|
|
5
|
+
// src/_formatter.ts
|
|
6
|
+
/**
|
|
7
|
+
* `format`, such as `formatForDisplay`, bound to the scope's `platform` and the
|
|
8
|
+
* keyboard layout. The layout loads after the render in which the formatter
|
|
9
|
+
* first reads it, unless the scope sets `keyboardLayout: false`.
|
|
10
|
+
*/
|
|
11
|
+
function bindFormatter(format, scope) {
|
|
12
|
+
const layoutMap = untilRendered(trackedLayout);
|
|
13
|
+
let requested = false;
|
|
14
|
+
/** The loaded layout, unless the scope turns it off. */
|
|
15
|
+
const loadedLayout = () => {
|
|
16
|
+
if (!layoutEnabled(scope)) {
|
|
17
|
+
requested = false;
|
|
18
|
+
return;
|
|
19
|
+
}
|
|
20
|
+
if (!requested) {
|
|
21
|
+
requested = true;
|
|
22
|
+
requestLayout();
|
|
23
|
+
}
|
|
24
|
+
return layoutMap() ?? void 0;
|
|
25
|
+
};
|
|
26
|
+
return createFormatter(format, () => scope && scopeDefaults.get(scope)().platform, loadedLayout);
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
export { bindFormatter };
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { trackedVersion } from "./tracked.js";
|
|
2
|
+
import { getHotkeyManager } from "@tanstack/hotkeys";
|
|
3
|
+
import { getHotkeyRegistrationViews } from "@tanstack/hotkeys/adapter";
|
|
4
|
+
|
|
5
|
+
// src/_registrations.ts
|
|
6
|
+
let watched;
|
|
7
|
+
/**
|
|
8
|
+
* The registration views, read so that templates render again when a
|
|
9
|
+
* registration changes. It needs no owner: the subscription follows the
|
|
10
|
+
* current manager and lasts as long as it does.
|
|
11
|
+
*/
|
|
12
|
+
function trackedRegistrationViews() {
|
|
13
|
+
const manager = getHotkeyManager();
|
|
14
|
+
if (watched?.manager !== manager) {
|
|
15
|
+
const changes = trackedVersion();
|
|
16
|
+
manager.registrations.subscribe(() => {
|
|
17
|
+
changes.version++;
|
|
18
|
+
});
|
|
19
|
+
watched = {
|
|
20
|
+
manager,
|
|
21
|
+
changes
|
|
22
|
+
};
|
|
23
|
+
}
|
|
24
|
+
watched.changes.version;
|
|
25
|
+
return getHotkeyRegistrationViews(manager.registrations.state);
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
export { trackedRegistrationViews };
|
package/dist/bindings.js
CHANGED
|
@@ -12,6 +12,18 @@ function copyHotkey(hotkey) {
|
|
|
12
12
|
return { ...hotkey };
|
|
13
13
|
}
|
|
14
14
|
/**
|
|
15
|
+
* Hotkey defaults for the helper and modifier classes a `createHotkeysScope`
|
|
16
|
+
* scope creates. They are the lowest layer, below an app hotkey's declaration.
|
|
17
|
+
*/
|
|
18
|
+
const classDefaults = /* @__PURE__ */ new WeakMap();
|
|
19
|
+
/** The scope defaults for a helper or modifier, including a subclass of one. */
|
|
20
|
+
function defaultsFor(owner) {
|
|
21
|
+
for (let helper = owner.constructor; typeof helper === "function"; helper = Object.getPrototypeOf(helper)) {
|
|
22
|
+
const defaults = classDefaults.get(helper);
|
|
23
|
+
if (defaults) return defaults();
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
/**
|
|
15
27
|
* Registrations owned by a helper or modifier. `set` records the latest
|
|
16
28
|
* definitions while Ember tracks the caller; registration changes publish
|
|
17
29
|
* after rendering, and again when app hotkeys or custom hotkeys change.
|
|
@@ -21,13 +33,15 @@ function createOwnedBindings(owner) {
|
|
|
21
33
|
const state = {
|
|
22
34
|
definitions: [],
|
|
23
35
|
commonOptions: {},
|
|
36
|
+
defaults: void 0,
|
|
24
37
|
element: void 0
|
|
25
38
|
};
|
|
26
39
|
function update() {
|
|
27
40
|
if (isDestroying(owner) || isDestroyed(owner)) return;
|
|
28
|
-
const { definitions, commonOptions, element } = state;
|
|
41
|
+
const { definitions, commonOptions, defaults, element } = state;
|
|
29
42
|
bindings.update(prepareHotkeyDefinitions(definitions, {
|
|
30
43
|
appHotkeysStore: getPublishedAppHotkeysStore(),
|
|
44
|
+
defaults,
|
|
31
45
|
commonOptions: element ? {
|
|
32
46
|
...commonOptions,
|
|
33
47
|
target: element
|
|
@@ -48,9 +62,10 @@ function createOwnedBindings(owner) {
|
|
|
48
62
|
options: { ...definition.options }
|
|
49
63
|
}));
|
|
50
64
|
state.commonOptions = { ...commonOptions };
|
|
65
|
+
state.defaults = defaultsFor(owner);
|
|
51
66
|
state.element = element;
|
|
52
67
|
schedule();
|
|
53
68
|
} };
|
|
54
69
|
}
|
|
55
70
|
|
|
56
|
-
export { createOwnedBindings };
|
|
71
|
+
export { classDefaults, createOwnedBindings };
|
|
@@ -1,9 +1,10 @@
|
|
|
1
|
+
import { classDefaults } from "./bindings.js";
|
|
1
2
|
import { OnHotkey } from "./onHotkey.js";
|
|
2
3
|
import { OnHotkeys } from "./onHotkeys.js";
|
|
3
4
|
import { UseHotkey } from "./useHotkey.js";
|
|
4
5
|
import { UseHotkeys } from "./useHotkeys.js";
|
|
5
6
|
import { scopeDefaults } from "./utils.js";
|
|
6
|
-
import {
|
|
7
|
+
import { mergeHotkeysProviderDefaults, resolveMaybeGetter } from "@tanstack/hotkeys/adapter";
|
|
7
8
|
|
|
8
9
|
// src/createHotkeysScope.ts
|
|
9
10
|
/**
|
|
@@ -13,27 +14,13 @@ import { definedOptions, mergeHotkeysProviderDefaults, resolveMaybeGetter } from
|
|
|
13
14
|
function createHotkeysScope(defaultOptions = {}) {
|
|
14
15
|
const defaults = () => mergeHotkeysProviderDefaults(void 0, resolveMaybeGetter(defaultOptions), void 0);
|
|
15
16
|
const scope = {
|
|
16
|
-
onHotkey: class extends OnHotkey {
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
},
|
|
21
|
-
onHotkeys: class extends OnHotkeys {
|
|
22
|
-
modify(...[element, args, options]) {
|
|
23
|
-
super.modify(element, args, { ...definedOptions(defaults().hotkey, options) });
|
|
24
|
-
}
|
|
25
|
-
},
|
|
26
|
-
useHotkey: class extends UseHotkey {
|
|
27
|
-
compute(...[args, options]) {
|
|
28
|
-
super.compute(args, { ...definedOptions(defaults().hotkey, options) });
|
|
29
|
-
}
|
|
30
|
-
},
|
|
31
|
-
useHotkeys: class extends UseHotkeys {
|
|
32
|
-
compute(...[args, options]) {
|
|
33
|
-
super.compute(args, { ...definedOptions(defaults().hotkey, options) });
|
|
34
|
-
}
|
|
35
|
-
}
|
|
17
|
+
onHotkey: class extends OnHotkey {},
|
|
18
|
+
onHotkeys: class extends OnHotkeys {},
|
|
19
|
+
useHotkey: class extends UseHotkey {},
|
|
20
|
+
useHotkeys: class extends UseHotkeys {}
|
|
36
21
|
};
|
|
22
|
+
const hotkeyDefaults = () => defaults().hotkey;
|
|
23
|
+
for (const helper of Object.values(scope)) classDefaults.set(helper, hotkeyDefaults);
|
|
37
24
|
scopeDefaults.set(scope, defaults);
|
|
38
25
|
return scope;
|
|
39
26
|
}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { formatForAria } from "@tanstack/hotkeys";
|
|
2
|
+
/**
|
|
3
|
+
* Formats a hotkey for `aria-keyshortcuts`, without the scope's platform or the
|
|
4
|
+
* user's keyboard layout.
|
|
5
|
+
*
|
|
6
|
+
* @deprecated Use `useFormatForAria()` in components. It returns this
|
|
7
|
+
* function with the scope's platform and the user's keyboard layout filled in.
|
|
8
|
+
* Outside a component, keep calling this function and pass `platform` yourself.
|
|
9
|
+
*/
|
|
10
|
+
declare const formatForAria$1: typeof formatForAria;
|
|
11
|
+
export { formatForAria$1 as formatForAria };
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { formatForAria } from "@tanstack/hotkeys";
|
|
2
|
+
|
|
3
|
+
// src/formatForAria.ts
|
|
4
|
+
/**
|
|
5
|
+
* Formats a hotkey for `aria-keyshortcuts`, without the scope's platform or the
|
|
6
|
+
* user's keyboard layout.
|
|
7
|
+
*
|
|
8
|
+
* @deprecated Use `useFormatForAria()` in components. It returns this
|
|
9
|
+
* function with the scope's platform and the user's keyboard layout filled in.
|
|
10
|
+
* Outside a component, keep calling this function and pass `platform` yourself.
|
|
11
|
+
*/
|
|
12
|
+
const formatForAria$1 = formatForAria;
|
|
13
|
+
|
|
14
|
+
export { formatForAria$1 as formatForAria };
|
package/dist/index.d.ts
CHANGED
|
@@ -9,11 +9,13 @@ import { useHotkeyScopesState } from "./useHotkeyScopesState.js";
|
|
|
9
9
|
import { useHotkeyRecorder } from "./useHotkeyRecorder.js";
|
|
10
10
|
import { useAppHotkeyList, useAppHotkeys, useCustomHotkeys } from "./useAppHotkeys.js";
|
|
11
11
|
import { useFormatForDisplay } from "./useFormatForDisplay.js";
|
|
12
|
+
import { useFormatForAria } from "./useFormatForAria.js";
|
|
12
13
|
import { formatForDisplay } from "./formatForDisplay.js";
|
|
14
|
+
import { formatForAria } from "./formatForAria.js";
|
|
13
15
|
import { useKeyboardLayout } from "./useKeyboardLayout.js";
|
|
14
16
|
import { DefaultHotkeysOptions, EmberAppHotkeyList, EmberCustomHotkeys, EmberHotkeyCommonOptions, EmberHotkeyDefinition, EmberHotkeyRecorder, EmberHotkeyState, EmberHotkeyTarget } from "./types.js";
|
|
15
17
|
import { EmberHotkeysScope, createHotkeysScope } from "./createHotkeysScope.js";
|
|
16
18
|
import { OnHotkey } from "./onHotkey.js";
|
|
17
19
|
import { ElementHotkeyOptions, OnHotkeys } from "./onHotkeys.js";
|
|
18
20
|
export * from "@tanstack/hotkeys";
|
|
19
|
-
export { DefaultHotkeysOptions, type ElementHotkeyOptions, EmberAppHotkeyList, EmberCustomHotkeys, EmberHotkeyCommonOptions, EmberHotkeyDefinition, EmberHotkeyRecorder, EmberHotkeyState, EmberHotkeyTarget, EmberHotkeysScope, createHotkeysScope, formatForDisplay, OnHotkey as onHotkey, OnHotkeys as onHotkeys, useAppHotkeyList, useAppHotkeys, useCustomHotkeys, useFormatForDisplay, useHeldKeyCodes, useHeldKeys, UseHotkey as useHotkey, useHotkeyHint, useHotkeyRecorder, useHotkeyRegistrations, useHotkeyScopesState, UseHotkeys as useHotkeys, useKeyHold, useKeyboardLayout };
|
|
21
|
+
export { DefaultHotkeysOptions, type ElementHotkeyOptions, EmberAppHotkeyList, EmberCustomHotkeys, EmberHotkeyCommonOptions, EmberHotkeyDefinition, EmberHotkeyRecorder, EmberHotkeyState, EmberHotkeyTarget, EmberHotkeysScope, createHotkeysScope, formatForAria, formatForDisplay, OnHotkey as onHotkey, OnHotkeys as onHotkeys, useAppHotkeyList, useAppHotkeys, useCustomHotkeys, useFormatForAria, useFormatForDisplay, useHeldKeyCodes, useHeldKeys, UseHotkey as useHotkey, useHotkeyHint, useHotkeyRecorder, useHotkeyRegistrations, useHotkeyScopesState, UseHotkeys as useHotkeys, useKeyHold, useKeyboardLayout };
|
package/dist/index.js
CHANGED
|
@@ -9,7 +9,9 @@ import { useHotkeyScopesState } from "./useHotkeyScopesState.js";
|
|
|
9
9
|
import { useHotkeyRecorder } from "./useHotkeyRecorder.js";
|
|
10
10
|
import { useAppHotkeyList, useAppHotkeys, useCustomHotkeys } from "./useAppHotkeys.js";
|
|
11
11
|
import { useFormatForDisplay } from "./useFormatForDisplay.js";
|
|
12
|
+
import { useFormatForAria } from "./useFormatForAria.js";
|
|
12
13
|
import { formatForDisplay } from "./formatForDisplay.js";
|
|
14
|
+
import { formatForAria } from "./formatForAria.js";
|
|
13
15
|
import { useKeyboardLayout } from "./useKeyboardLayout.js";
|
|
14
16
|
import { createHotkeysScope } from "./createHotkeysScope.js";
|
|
15
17
|
import { OnHotkey } from "./onHotkey.js";
|
|
@@ -17,4 +19,4 @@ import { OnHotkeys } from "./onHotkeys.js";
|
|
|
17
19
|
|
|
18
20
|
export * from "@tanstack/hotkeys"
|
|
19
21
|
|
|
20
|
-
export { createHotkeysScope, formatForDisplay, OnHotkey as onHotkey, OnHotkeys as onHotkeys, useAppHotkeyList, useAppHotkeys, useCustomHotkeys, useFormatForDisplay, useHeldKeyCodes, useHeldKeys, UseHotkey as useHotkey, useHotkeyHint, useHotkeyRecorder, useHotkeyRegistrations, useHotkeyScopesState, UseHotkeys as useHotkeys, useKeyHold, useKeyboardLayout };
|
|
22
|
+
export { createHotkeysScope, formatForAria, formatForDisplay, OnHotkey as onHotkey, OnHotkeys as onHotkeys, useAppHotkeyList, useAppHotkeys, useCustomHotkeys, useFormatForAria, useFormatForDisplay, useHeldKeyCodes, useHeldKeys, UseHotkey as useHotkey, useHotkeyHint, useHotkeyRecorder, useHotkeyRegistrations, useHotkeyScopesState, UseHotkeys as useHotkeys, useKeyHold, useKeyboardLayout };
|
package/dist/keyboardLayout.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
+
import { trackedVersion } from "./tracked.js";
|
|
1
2
|
import { scopeDefaults } from "./utils.js";
|
|
2
3
|
import { getKeyboardLayoutStore, loadKeyboardLayout } from "@tanstack/hotkeys";
|
|
3
4
|
import { schedule, scheduleOnce } from "@ember/runloop";
|
|
4
|
-
import { trackedObject } from "@ember/reactive/collections";
|
|
5
5
|
|
|
6
6
|
// src/keyboardLayout.ts
|
|
7
7
|
/** Whether a scope's defaults let labels follow the keyboard layout. */
|
|
@@ -33,7 +33,7 @@ let changes;
|
|
|
33
33
|
function trackedLayout() {
|
|
34
34
|
const store = getKeyboardLayoutStore();
|
|
35
35
|
if (!changes) {
|
|
36
|
-
const state = changes =
|
|
36
|
+
const state = changes = trackedVersion();
|
|
37
37
|
store.subscribe(() => {
|
|
38
38
|
state.version++;
|
|
39
39
|
});
|
|
@@ -48,7 +48,7 @@ function trackedLayout() {
|
|
|
48
48
|
*/
|
|
49
49
|
function untilRendered(read, onRendered) {
|
|
50
50
|
let rendered = false;
|
|
51
|
-
const state =
|
|
51
|
+
const state = trackedVersion();
|
|
52
52
|
schedule("afterRender", () => {
|
|
53
53
|
rendered = true;
|
|
54
54
|
onRendered?.();
|
package/dist/tracked.js
ADDED
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { tracked } from "@glimmer/tracking";
|
|
2
|
+
|
|
3
|
+
// src/tracked.ts
|
|
4
|
+
var TrackedVersion = class {};
|
|
5
|
+
Object.defineProperty(TrackedVersion.prototype, "version", tracked(TrackedVersion.prototype, "version", {
|
|
6
|
+
configurable: true,
|
|
7
|
+
enumerable: true,
|
|
8
|
+
writable: true,
|
|
9
|
+
initializer: () => 0
|
|
10
|
+
}));
|
|
11
|
+
/** A counter that invalidates its readers when it changes. */
|
|
12
|
+
function trackedVersion() {
|
|
13
|
+
return new TrackedVersion();
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
export { trackedVersion };
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import { EmberHotkeysScope } from "./createHotkeysScope.js";
|
|
2
|
+
import { formatForAria } from "@tanstack/hotkeys";
|
|
3
|
+
/**
|
|
4
|
+
* Returns `formatForAria` with the scope's `platform` as the default. Use its
|
|
5
|
+
* value for `aria-keyshortcuts`, so screen readers announce the shortcut. It
|
|
6
|
+
* returns `undefined` for a multi-step sequence, no hotkey, or a hotkey that
|
|
7
|
+
* can't fire right now (one that is disabled, in a suspended scope, a
|
|
8
|
+
* suspended character key, or not registered), so Glimmer omits the attribute.
|
|
9
|
+
* The returned function works anywhere, including templates, and reads the
|
|
10
|
+
* scope's defaults when called. An explicit `platform` option wins.
|
|
11
|
+
*
|
|
12
|
+
* Physical bindings such as `[KeyQ]` name the key the user presses in
|
|
13
|
+
* Chromium browsers, once the keyboard layout has loaded, the same way as
|
|
14
|
+
* `useFormatForDisplay`. A `layoutMap` passed to the returned function wins.
|
|
15
|
+
* To never ask the browser for the layout, set `keyboardLayout: false` in the
|
|
16
|
+
* scope's default options.
|
|
17
|
+
*
|
|
18
|
+
* Server-rendered apps should set the scope's default `platform` from the
|
|
19
|
+
* request user agent, such as
|
|
20
|
+
* `detectPlatform(fastboot.request.headers.get('user-agent'))` with the
|
|
21
|
+
* FastBoot service.
|
|
22
|
+
*
|
|
23
|
+
* @example
|
|
24
|
+
* ```gts
|
|
25
|
+
* class SearchButton extends Component<{ Args: { hotkeys: EmberHotkeysScope } }> {
|
|
26
|
+
* formatForAria = useFormatForAria(this.args.hotkeys)
|
|
27
|
+
*
|
|
28
|
+
* <template>
|
|
29
|
+
* <button aria-keyshortcuts={{this.formatForAria "Mod+K"}}>Search</button>
|
|
30
|
+
* </template>
|
|
31
|
+
* }
|
|
32
|
+
* ```
|
|
33
|
+
*/
|
|
34
|
+
export declare function useFormatForAria(scope?: EmberHotkeysScope): typeof formatForAria;
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import { bindFormatter } from "./_formatter.js";
|
|
2
|
+
import { trackedRegistrationViews } from "./_registrations.js";
|
|
3
|
+
import { formatForAria } from "@tanstack/hotkeys";
|
|
4
|
+
import { announceLiveHotkeys } from "@tanstack/hotkeys/adapter";
|
|
5
|
+
|
|
6
|
+
// src/useFormatForAria.ts
|
|
7
|
+
/**
|
|
8
|
+
* Returns `formatForAria` with the scope's `platform` as the default. Use its
|
|
9
|
+
* value for `aria-keyshortcuts`, so screen readers announce the shortcut. It
|
|
10
|
+
* returns `undefined` for a multi-step sequence, no hotkey, or a hotkey that
|
|
11
|
+
* can't fire right now (one that is disabled, in a suspended scope, a
|
|
12
|
+
* suspended character key, or not registered), so Glimmer omits the attribute.
|
|
13
|
+
* The returned function works anywhere, including templates, and reads the
|
|
14
|
+
* scope's defaults when called. An explicit `platform` option wins.
|
|
15
|
+
*
|
|
16
|
+
* Physical bindings such as `[KeyQ]` name the key the user presses in
|
|
17
|
+
* Chromium browsers, once the keyboard layout has loaded, the same way as
|
|
18
|
+
* `useFormatForDisplay`. A `layoutMap` passed to the returned function wins.
|
|
19
|
+
* To never ask the browser for the layout, set `keyboardLayout: false` in the
|
|
20
|
+
* scope's default options.
|
|
21
|
+
*
|
|
22
|
+
* Server-rendered apps should set the scope's default `platform` from the
|
|
23
|
+
* request user agent, such as
|
|
24
|
+
* `detectPlatform(fastboot.request.headers.get('user-agent'))` with the
|
|
25
|
+
* FastBoot service.
|
|
26
|
+
*
|
|
27
|
+
* @example
|
|
28
|
+
* ```gts
|
|
29
|
+
* class SearchButton extends Component<{ Args: { hotkeys: EmberHotkeysScope } }> {
|
|
30
|
+
* formatForAria = useFormatForAria(this.args.hotkeys)
|
|
31
|
+
*
|
|
32
|
+
* <template>
|
|
33
|
+
* <button aria-keyshortcuts={{this.formatForAria "Mod+K"}}>Search</button>
|
|
34
|
+
* </template>
|
|
35
|
+
* }
|
|
36
|
+
* ```
|
|
37
|
+
*/
|
|
38
|
+
function useFormatForAria(scope) {
|
|
39
|
+
return announceLiveHotkeys(bindFormatter(formatForAria, scope), trackedRegistrationViews);
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
export { useFormatForAria };
|
|
@@ -1,6 +1,5 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
import { createFormatForDisplay } from "@tanstack/hotkeys/adapter";
|
|
1
|
+
import { bindFormatter } from "./_formatter.js";
|
|
2
|
+
import { formatForDisplay } from "@tanstack/hotkeys";
|
|
4
3
|
|
|
5
4
|
// src/useFormatForDisplay.ts
|
|
6
5
|
/**
|
|
@@ -34,21 +33,7 @@ import { createFormatForDisplay } from "@tanstack/hotkeys/adapter";
|
|
|
34
33
|
* ```
|
|
35
34
|
*/
|
|
36
35
|
function useFormatForDisplay(scope) {
|
|
37
|
-
|
|
38
|
-
let requested = false;
|
|
39
|
-
/** The loaded layout, unless the scope turns it off. */
|
|
40
|
-
const loadedLayout = () => {
|
|
41
|
-
if (!layoutEnabled(scope)) {
|
|
42
|
-
requested = false;
|
|
43
|
-
return;
|
|
44
|
-
}
|
|
45
|
-
if (!requested) {
|
|
46
|
-
requested = true;
|
|
47
|
-
requestLayout();
|
|
48
|
-
}
|
|
49
|
-
return layoutMap() ?? void 0;
|
|
50
|
-
};
|
|
51
|
-
return createFormatForDisplay(() => scope && scopeDefaults.get(scope)().platform, loadedLayout);
|
|
36
|
+
return bindFormatter(formatForDisplay, scope);
|
|
52
37
|
}
|
|
53
38
|
|
|
54
39
|
export { useFormatForDisplay };
|
package/dist/utils.js
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
|
+
import { trackedVersion } from "./tracked.js";
|
|
1
2
|
import { registerDestructor } from "@ember/destroyable";
|
|
2
3
|
import { getPublishedAppHotkeysStore, subscribePublishedAppHotkeys } from "@tanstack/hotkeys/adapter";
|
|
3
|
-
import { trackedObject } from "@ember/reactive/collections";
|
|
4
4
|
|
|
5
5
|
// src/utils.ts
|
|
6
6
|
/** Reads the merged defaults behind each `createHotkeysScope` result. */
|
|
7
7
|
const scopeDefaults = /* @__PURE__ */ new WeakMap();
|
|
8
8
|
function select(owner, store, selector) {
|
|
9
|
-
const state =
|
|
9
|
+
const state = trackedVersion();
|
|
10
10
|
let last;
|
|
11
11
|
const subscription = store.subscribe(() => {
|
|
12
12
|
const next = selector(store.state);
|
|
@@ -26,7 +26,7 @@ function select(owner, store, selector) {
|
|
|
26
26
|
* hotkey and custom hotkey changes for the owner's lifetime.
|
|
27
27
|
*/
|
|
28
28
|
function trackPublishedAppHotkeys(owner) {
|
|
29
|
-
const state =
|
|
29
|
+
const state = trackedVersion();
|
|
30
30
|
registerDestructor(owner, subscribePublishedAppHotkeys(() => {
|
|
31
31
|
state.version++;
|
|
32
32
|
}));
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tanstack/ember-hotkeys",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.15.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.11.0",
|
|
43
|
-
"@tanstack/hotkeys": "0.
|
|
43
|
+
"@tanstack/hotkeys": "0.37.0",
|
|
44
44
|
"ember-modifier": "^4.2.2"
|
|
45
45
|
},
|
|
46
46
|
"devDependencies": {
|
|
@@ -69,7 +69,7 @@
|
|
|
69
69
|
"vite": "^8.3.7"
|
|
70
70
|
},
|
|
71
71
|
"peerDependencies": {
|
|
72
|
-
"ember-source": ">=
|
|
72
|
+
"ember-source": ">=4.12.0"
|
|
73
73
|
},
|
|
74
74
|
"ember-addon": {
|
|
75
75
|
"version": 2,
|
|
@@ -55,30 +55,31 @@ export default class Editor extends Component {
|
|
|
55
55
|
|
|
56
56
|
## API
|
|
57
57
|
|
|
58
|
-
| API | What it's for
|
|
59
|
-
| --------------------------------------------------- |
|
|
60
|
-
| `{{useHotkey hotkey callback ...options}}` | Register one chord, sequence, or app hotkey while the template renders the helper.
|
|
61
|
-
| `{{useHotkeys definitions}}` | Register several hotkeys, or a list built from data, in one helper.
|
|
62
|
-
| `{{onHotkey hotkey callback ...options}}` | Attach a hotkey to the element the modifier is on, so it fires while focus is inside that element.
|
|
63
|
-
| `{{onHotkeys definitions}}` | Attach several hotkeys to one element.
|
|
64
|
-
| `createHotkeysScope(defaults?)` | Create `useHotkey`, `useHotkeys`, `onHotkey`, and `onHotkeys` that share default options.
|
|
65
|
-
| `useFormatForDisplay(scope?)` | Get the function that formats a hotkey as a label, with the scope's `platform` and the user's keyboard layout filled in. Only Chromium browsers report a layout, so physical keys keep their US labels in Firefox and Safari. Use it for every label in a component: `formatForDisplay = useFormatForDisplay()` as a class field, then `{{this.formatForDisplay hotkey}}`.
|
|
66
|
-
| `
|
|
67
|
-
| `
|
|
68
|
-
| `
|
|
69
|
-
| `
|
|
70
|
-
| `
|
|
71
|
-
| `
|
|
72
|
-
| `
|
|
73
|
-
| `
|
|
74
|
-
| `
|
|
75
|
-
| `
|
|
76
|
-
| `
|
|
77
|
-
| `
|
|
58
|
+
| API | What it's for |
|
|
59
|
+
| --------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
|
|
60
|
+
| `{{useHotkey hotkey callback ...options}}` | Register one chord, sequence, or app hotkey while the template renders the helper. |
|
|
61
|
+
| `{{useHotkeys definitions}}` | Register several hotkeys, or a list built from data, in one helper. |
|
|
62
|
+
| `{{onHotkey hotkey callback ...options}}` | Attach a hotkey to the element the modifier is on, so it fires while focus is inside that element. |
|
|
63
|
+
| `{{onHotkeys definitions}}` | Attach several hotkeys to one element. |
|
|
64
|
+
| `createHotkeysScope(defaults?)` | Create `useHotkey`, `useHotkeys`, `onHotkey`, and `onHotkeys` that share default options. |
|
|
65
|
+
| `useFormatForDisplay(scope?)` | Get the function that formats a hotkey as a label, with the scope's `platform` and the user's keyboard layout filled in. Only Chromium browsers report a layout, so physical keys keep their US labels in Firefox and Safari. Use it for every label in a component: `formatForDisplay = useFormatForDisplay()` as a class field, then `{{this.formatForDisplay hotkey}}`. |
|
|
66
|
+
| `useFormatForAria(scope?)` | Get the function that formats a hotkey for `aria-keyshortcuts`, with the scope's `platform` and the user's keyboard layout filled in. Returns `undefined` for a multi-step sequence, no hotkey, or a hotkey that can't fire right now, such as a disabled or suspended one, so the attribute is omitted. Set `aria-keyshortcuts` on every control that has a shortcut, next to the visible label. |
|
|
67
|
+
| `provideAppHotkeys(appHotkeys, options?)` | Declare app hotkeys and load the user's custom hotkeys before the app boots, since Ember has no provider. |
|
|
68
|
+
| `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. |
|
|
69
|
+
| `useAppHotkeys(this)` | Get the declared app hotkeys with the user's custom hotkeys applied. |
|
|
70
|
+
| `useAppHotkeyList(this)` | List every app hotkey with its status, for a cheat sheet or settings screen. |
|
|
71
|
+
| `useCustomHotkeys(this)` | Read, change, and reset the user's custom hotkeys, and check a new one for conflicts. |
|
|
72
|
+
| `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. |
|
|
73
|
+
| `useHotkeyRegistrations(this)` | Read `.hotkeys`, every registered hotkey with its options, `meta`, and `status` (whether it's enabled and in an active scope). |
|
|
74
|
+
| `useHotkeyScopesState(this)` | Get the active scopes and the exclusive scope that owns the keyboard. |
|
|
75
|
+
| `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. |
|
|
76
|
+
| `useKeyHold(this, key)` | Get whether one key is held. Letters match in any case; other names, such as `Shift`, are case-sensitive. |
|
|
77
|
+
| `useHeldKeys(this)` | Get every key that's held right now. |
|
|
78
|
+
| `useHeldKeyCodes(this)` | Map each held key to its physical `event.code`. |
|
|
78
79
|
|
|
79
|
-
The package also re-exports `@tanstack/hotkeys`, such as `matchesKeyboardEvent` and `defineAppHotkeys`. Its plain `formatForDisplay` export is deprecated: use `useFormatForDisplay()` in components. Outside a component, call the plain function and pass `platform`.
|
|
80
|
+
The package also re-exports `@tanstack/hotkeys`, such as `matchesKeyboardEvent` and `defineAppHotkeys`. Its plain `formatForDisplay` export is deprecated: use `useFormatForDisplay()` in components. Outside a component, call the plain function and pass `platform`. The plain `formatForAria` export is deprecated the same way, in favor of `useFormatForAria()`.
|
|
80
81
|
|
|
81
|
-
The helpers are template helpers, not JavaScript functions. State readers take the component as their owner, and their state is read through `.value`, or `.hotkeys` for registrations. Use Ember
|
|
82
|
+
The helpers are template helpers, not JavaScript functions. State readers take the component as their owner, and their state is read through `.value`, or `.hotkeys` for registrations. Use Ember 4.12 or newer and strict-mode `.gts` components.
|
|
82
83
|
|
|
83
84
|
## Pitfalls
|
|
84
85
|
|