@tanstack/ember-hotkeys 0.13.0 → 0.13.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/bindings.js CHANGED
@@ -1,7 +1,7 @@
1
- import { getHotkeyManager, isAppHotkey, isHotkeySequence } from "@tanstack/hotkeys";
1
+ import { isAppHotkey, isHotkeySequence } from "@tanstack/hotkeys";
2
2
  import { isDestroyed, isDestroying, registerDestructor } from "@ember/destroyable";
3
3
  import { scheduleOnce } from "@ember/runloop";
4
- import { createHotkeyBindings, prepareHotkeyDefinitions, subscribePublishedAppHotkeys } from "@tanstack/hotkeys/adapter";
4
+ import { createHotkeyBindings, getPublishedAppHotkeysStore, prepareHotkeyDefinitions, subscribePublishedAppHotkeys } from "@tanstack/hotkeys/adapter";
5
5
 
6
6
  // src/bindings.ts
7
7
  /** Copies a hotkey so tracked getters are read while Ember tracks the caller. */
@@ -27,7 +27,7 @@ function createOwnedBindings(owner) {
27
27
  if (isDestroying(owner) || isDestroyed(owner)) return;
28
28
  const { definitions, commonOptions, element } = state;
29
29
  bindings.update(prepareHotkeyDefinitions(definitions, {
30
- appHotkeysStore: getHotkeyManager().appHotkeys.state,
30
+ appHotkeysStore: getPublishedAppHotkeysStore(),
31
31
  commonOptions: element ? {
32
32
  ...commonOptions,
33
33
  target: element
@@ -3,7 +3,7 @@ import { OnHotkeys } from "./onHotkeys.js";
3
3
  import { UseHotkey } from "./useHotkey.js";
4
4
  import { UseHotkeys } from "./useHotkeys.js";
5
5
  import { DefaultHotkeysOptions } from "./types.js";
6
- import { MaybeGetter } from "./utils.js";
6
+ import { MaybeGetter } from "@tanstack/hotkeys";
7
7
  /**
8
8
  * Helpers and modifiers with shared defaults. Owners retain their own cleanup.
9
9
  * Pass the scope to `useHotkeyRecorder` to apply its recorder defaults, to
@@ -2,8 +2,8 @@ import { OnHotkey } from "./onHotkey.js";
2
2
  import { OnHotkeys } from "./onHotkeys.js";
3
3
  import { UseHotkey } from "./useHotkey.js";
4
4
  import { UseHotkeys } from "./useHotkeys.js";
5
- import { read, scopeDefaults } from "./utils.js";
6
- import { definedOptions, mergeHotkeysProviderDefaults } from "@tanstack/hotkeys/adapter";
5
+ import { scopeDefaults } from "./utils.js";
6
+ import { definedOptions, mergeHotkeysProviderDefaults, resolveMaybeGetter } from "@tanstack/hotkeys/adapter";
7
7
 
8
8
  // src/createHotkeysScope.ts
9
9
  /**
@@ -11,7 +11,7 @@ import { definedOptions, mergeHotkeysProviderDefaults } from "@tanstack/hotkeys/
11
11
  * Pass the scope to child components through arguments to share configuration.
12
12
  */
13
13
  function createHotkeysScope(defaultOptions = {}) {
14
- const defaults = () => mergeHotkeysProviderDefaults(void 0, read(defaultOptions), void 0);
14
+ const defaults = () => mergeHotkeysProviderDefaults(void 0, resolveMaybeGetter(defaultOptions), void 0);
15
15
  const scope = {
16
16
  onHotkey: class extends OnHotkey {
17
17
  modify(...[element, args, options]) {
package/dist/index.d.ts CHANGED
@@ -1,6 +1,5 @@
1
1
  import { UseHotkey } from "./useHotkey.js";
2
2
  import { UseHotkeys } from "./useHotkeys.js";
3
- import { MaybeGetter } from "./utils.js";
4
3
  import { useHeldKeys } from "./useHeldKeys.js";
5
4
  import { useHeldKeyCodes } from "./useHeldKeyCodes.js";
6
5
  import { useKeyHold } from "./useKeyHold.js";
@@ -12,9 +11,9 @@ import { useAppHotkeyList, useAppHotkeys, useCustomHotkeys } from "./useAppHotke
12
11
  import { useFormatForDisplay } from "./useFormatForDisplay.js";
13
12
  import { formatForDisplay } from "./formatForDisplay.js";
14
13
  import { useKeyboardLayout } from "./useKeyboardLayout.js";
15
- import { DefaultHotkeysOptions, EmberAppHotkeyList, EmberCustomHotkeys, EmberHotkeyCommonOptions, EmberHotkeyDefinition, EmberHotkeyRecorder, EmberHotkeyState, EmberHotkeyTarget, HotkeyRegistrationsResult } from "./types.js";
14
+ import { DefaultHotkeysOptions, EmberAppHotkeyList, EmberCustomHotkeys, EmberHotkeyCommonOptions, EmberHotkeyDefinition, EmberHotkeyRecorder, EmberHotkeyState, EmberHotkeyTarget } from "./types.js";
16
15
  import { EmberHotkeysScope, createHotkeysScope } from "./createHotkeysScope.js";
17
16
  import { OnHotkey } from "./onHotkey.js";
18
17
  import { ElementHotkeyOptions, OnHotkeys } from "./onHotkeys.js";
19
18
  export * from "@tanstack/hotkeys";
20
- export { DefaultHotkeysOptions, type ElementHotkeyOptions, EmberAppHotkeyList, EmberCustomHotkeys, EmberHotkeyCommonOptions, EmberHotkeyDefinition, EmberHotkeyRecorder, EmberHotkeyState, EmberHotkeyTarget, EmberHotkeysScope, HotkeyRegistrationsResult, type MaybeGetter, 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 };
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 };
package/dist/types.d.ts CHANGED
@@ -1,5 +1,5 @@
1
- import { AppHotkey, AppHotkeyListItem, CustomHotkeys, Hotkey, HotkeyChordRecorderOptions, HotkeyPlatform, HotkeyRegistrationView, HotkeySequence, HotkeySequenceRecorderOptions, RecordedKeyPresses, RegisteredAppHotkeys, Target } from "@tanstack/hotkeys";
2
- import { AdapterCommonOptions, AdapterHotkeyDefinition } from "@tanstack/hotkeys/adapter";
1
+ import { CustomHotkeyActions, CustomHotkeys, Hotkey, HotkeyPlatform, HotkeyRecorderActions, HotkeyRecorderState, RegisteredAppHotkeyListItem, Target } from "@tanstack/hotkeys";
2
+ import { AdapterCommonOptions, AdapterHotkeyDefinition, HotkeyRecorderDefaults } from "@tanstack/hotkeys/adapter";
3
3
  /** A reactive value. Read `.value` where the framework tracks dependencies. */
4
4
  export interface EmberHotkeyState<T> {
5
5
  readonly value: T;
@@ -14,49 +14,13 @@ export type EmberHotkeyDefinition = AdapterHotkeyDefinition<EmberHotkeyTarget>;
14
14
  /** Options for every kind; each applies to the kinds that support it. */
15
15
  export type EmberHotkeyCommonOptions = AdapterCommonOptions<EmberHotkeyTarget>;
16
16
  /** Recording state and controls owned by the containing component. */
17
- export interface EmberHotkeyRecorder<THotkey extends Hotkey = Hotkey> {
18
- /** Whether the recorder is listening for a shortcut. */
19
- readonly isRecording: boolean;
20
- /** Chords captured so far in a multi-step recording. */
21
- readonly steps: HotkeySequence;
22
- /** The last committed hotkey, including brackets for physical codes. */
23
- readonly recordedHotkey: THotkey | null;
24
- /** Start a new recording session. */
25
- startRecording: () => void;
26
- /** Stop and clear recorder state without calling onRecord or onCancel. */
27
- stopRecording: () => void;
28
- /** Stop, clear recorder state, and call onCancel. */
29
- cancelRecording: () => void;
30
- /** Commit the current steps (multi-step recordings). */
31
- commitRecording: () => void;
32
- }
33
- /** Live registration views from the shared hotkey manager. */
34
- export interface HotkeyRegistrationsResult {
35
- /** Every registration, chords and sequences. Narrow each view with `kind`. */
36
- readonly hotkeys: Array<HotkeyRegistrationView>;
37
- }
17
+ export interface EmberHotkeyRecorder<THotkey extends Hotkey = Hotkey> extends Readonly<HotkeyRecorderState<THotkey>>, HotkeyRecorderActions {}
38
18
  /** Every app hotkey with its live status. */
39
- export type EmberAppHotkeyList = EmberHotkeyState<Array<AppHotkeyListItem<RegisteredAppHotkeys[keyof RegisteredAppHotkeys]>>>;
19
+ export type EmberAppHotkeyList = EmberHotkeyState<Array<RegisteredAppHotkeyListItem>>;
40
20
  /** Custom hotkey state and actions. */
41
- export interface EmberCustomHotkeys {
21
+ export interface EmberCustomHotkeys extends CustomHotkeyActions {
42
22
  /** The user's hotkeys that differ from the defaults. */
43
23
  readonly value: CustomHotkeys;
44
- /**
45
- * Sets the user's hotkey for an app hotkey. `null` unbinds it.
46
- * Returns conflicting app hotkeys; when any exist, nothing changes. Pass
47
- * the recorder's `context` for a recorded hotkey, as for `findConflicts`.
48
- */
49
- setCustomHotkey: (id: keyof RegisteredAppHotkeys & string, hotkey: Hotkey | null, recordedWith?: RecordedKeyPresses) => Array<AppHotkey>;
50
- /** Restores the default hotkey for an app hotkey. */
51
- resetCustomHotkey: (id: keyof RegisteredAppHotkeys & string) => void;
52
- /** Restores every default hotkey. */
53
- resetCustomHotkeys: () => void;
54
- /**
55
- * Other app hotkeys that would collide if `id` used `hotkey`. Pass the
56
- * recorder's `context` for a recorded hotkey: it has the key press, which
57
- * also finds a hotkey written differently that the same press fires.
58
- */
59
- findConflicts: (id: keyof RegisteredAppHotkeys & string, hotkey: Hotkey, recordedWith?: RecordedKeyPresses) => Array<AppHotkey>;
60
24
  }
61
25
  /** Shared defaults; call-specific options take precedence. */
62
26
  export interface DefaultHotkeysOptions {
@@ -78,5 +42,5 @@ export interface DefaultHotkeysOptions {
78
42
  /** Defaults for every hotkey. `requireReset` applies to chords and `timeout` to sequences. */
79
43
  hotkey?: EmberHotkeyCommonOptions;
80
44
  /** Defaults for every recorder. */
81
- hotkeyRecorder?: Partial<Omit<HotkeyChordRecorderOptions & HotkeySequenceRecorderOptions, 'maxSteps' | 'onRecord' | 'validate'>>;
45
+ hotkeyRecorder?: HotkeyRecorderDefaults;
82
46
  }
@@ -1,11 +1,10 @@
1
1
  import { useHotkeyRegistrations } from "./useHotkeyRegistrations.js";
2
2
  import { trackPublishedAppHotkeys } from "./utils.js";
3
+ import { bindCustomHotkeyActions, requireAppHotkeysStore } from "@tanstack/hotkeys/adapter";
3
4
 
4
5
  // src/useAppHotkeys.ts
5
6
  function requireStore(store) {
6
- const current = store();
7
- if (!current) throw new Error("[hotkeys] App hotkeys require provideAppHotkeys()");
8
- return current;
7
+ return requireAppHotkeysStore(store(), "App hotkeys require provideAppHotkeys()");
9
8
  }
10
9
  /** Reads the effective app hotkeys from `provideAppHotkeys`, typed by `Register`. */
11
10
  function useAppHotkeys(owner) {
@@ -37,10 +36,7 @@ function useCustomHotkeys(owner) {
37
36
  get value() {
38
37
  return requireStore(store).customHotkeys;
39
38
  },
40
- setCustomHotkey: (id, hotkey, recordedWith) => requireStore(store).setCustomHotkey(id, hotkey, recordedWith),
41
- resetCustomHotkey: (id) => requireStore(store).resetCustomHotkey(id),
42
- resetCustomHotkeys: () => requireStore(store).resetCustomHotkeys(),
43
- findConflicts: (id, hotkey, recordedWith) => requireStore(store).findConflicts(id, hotkey, recordedWith)
39
+ ...bindCustomHotkeyActions(() => requireStore(store))
44
40
  };
45
41
  }
46
42
 
@@ -1,7 +1,6 @@
1
1
  import { layoutEnabled, requestLayout, trackedLayout, untilRendered } from "./keyboardLayout.js";
2
2
  import { scopeDefaults } from "./utils.js";
3
- import { formatForDisplay } from "@tanstack/hotkeys";
4
- import { namesPhysicalKey } from "@tanstack/hotkeys/adapter";
3
+ import { createFormatForDisplay } from "@tanstack/hotkeys/adapter";
5
4
 
6
5
  // src/useFormatForDisplay.ts
7
6
  /**
@@ -49,11 +48,7 @@ function useFormatForDisplay(scope) {
49
48
  }
50
49
  return layoutMap() ?? void 0;
51
50
  };
52
- return ((hotkey, options) => formatForDisplay(hotkey, {
53
- ...options,
54
- platform: options?.platform ?? (scope && scopeDefaults.get(scope)().platform),
55
- layoutMap: options?.layoutMap ?? (namesPhysicalKey(hotkey) ? loadedLayout() : void 0)
56
- }));
51
+ return createFormatForDisplay(() => scope && scopeDefaults.get(scope)().platform, loadedLayout);
57
52
  }
58
53
 
59
54
  export { useFormatForDisplay };
@@ -1,6 +1,5 @@
1
1
  import { EmberHotkeyState } from "./types.js";
2
- import { MaybeGetter } from "./utils.js";
3
- import { AppHotkey, HeldModifierOptions, RegisterableHotkey } from "@tanstack/hotkeys";
2
+ import { AppHotkey, HeldModifierOptions, MaybeGetter, RegisterableHotkey } from "@tanstack/hotkeys";
4
3
  /**
5
4
  * Recomputes for held modifiers and tracked changes to the hotkey or options.
6
5
  * The hint shows only while the hotkey can fire: some registration of it is
@@ -1,5 +1,6 @@
1
- import { read, select, trackPublishedAppHotkeys } from "./utils.js";
2
- import { getHotkeyManager, getKeyStateTracker, isAppHotkey, matchesHeldModifiers, resolveAppHotkey } from "@tanstack/hotkeys";
1
+ import { select, trackPublishedAppHotkeys } from "./utils.js";
2
+ import { getHotkeyManager, getKeyStateTracker, isAppHotkey } from "@tanstack/hotkeys";
3
+ import { isHotkeyHintVisible, resolveMaybeGetter } from "@tanstack/hotkeys/adapter";
3
4
 
4
5
  // src/useHotkeyHint.ts
5
6
  /**
@@ -13,12 +14,11 @@ import { getHotkeyManager, getKeyStateTracker, isAppHotkey, matchesHeldModifiers
13
14
  function useHotkeyHint(owner, hotkey, options = {}) {
14
15
  const appHotkeys = trackPublishedAppHotkeys(owner);
15
16
  const manager = getHotkeyManager();
16
- const active = select(owner, manager.registrations, () => manager.hasActiveRegistration(read(hotkey)));
17
+ const active = select(owner, manager.registrations, () => manager.hasActiveRegistration(resolveMaybeGetter(hotkey)));
17
18
  return select(owner, getKeyStateTracker().store, (state) => {
18
- const isActive = active.value;
19
- const value = read(hotkey);
20
- const resolved = isAppHotkey(value) ? resolveAppHotkey(value, appHotkeys()).hotkey : value;
21
- return resolved !== null && matchesHeldModifiers(resolved, state.heldKeys, read(options)) && isActive;
19
+ active.value;
20
+ const value = resolveMaybeGetter(hotkey);
21
+ return isHotkeyHintVisible(value, state.heldKeys, resolveMaybeGetter(options), isAppHotkey(value) ? appHotkeys() : null);
22
22
  });
23
23
  }
24
24
 
@@ -1,11 +1,11 @@
1
- import { read, scopeDefaults, select } from "./utils.js";
1
+ import { 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
+ import { resolveMaybeGetter, withDefaults } from "@tanstack/hotkeys/adapter";
5
5
 
6
6
  // src/useHotkeyRecorder.ts
7
7
  function useHotkeyRecorder(owner, options, scope) {
8
- const recorder = new HotkeyRecorder(() => withDefaults(scope && scopeDefaults.get(scope)().hotkeyRecorder, read(options)));
8
+ const recorder = new HotkeyRecorder(() => withDefaults(scope && scopeDefaults.get(scope)().hotkeyRecorder, resolveMaybeGetter(options)));
9
9
  const state = select(owner, recorder.store, (value) => value);
10
10
  registerDestructor(owner, () => recorder.destroy());
11
11
  return {
@@ -1,3 +1,3 @@
1
- import { HotkeyRegistrationsResult } from "./types.js";
1
+ import { HotkeyRegistrationsResult } from "@tanstack/hotkeys";
2
2
  /** Reads public snapshots of every registration, chords and sequences. */
3
3
  export declare function useHotkeyRegistrations(owner: object): HotkeyRegistrationsResult;
@@ -1,10 +1,11 @@
1
1
  import { select } from "./utils.js";
2
- import { getHotkeyManager, toHotkeyRegistrationView } from "@tanstack/hotkeys";
2
+ import { getHotkeyManager } from "@tanstack/hotkeys";
3
+ import { getHotkeyRegistrationViews } from "@tanstack/hotkeys/adapter";
3
4
 
4
5
  // src/useHotkeyRegistrations.ts
5
6
  /** Reads public snapshots of every registration, chords and sequences. */
6
7
  function useHotkeyRegistrations(owner) {
7
- const hotkeys = select(owner, getHotkeyManager().registrations, (state) => Array.from(state.values()).map(toHotkeyRegistrationView));
8
+ const hotkeys = select(owner, getHotkeyManager().registrations, (state) => getHotkeyRegistrationViews(state));
8
9
  return { get hotkeys() {
9
10
  return hotkeys.value;
10
11
  } };
@@ -1,5 +1,4 @@
1
1
  import { EmberHotkeyState } from "./types.js";
2
- import { MaybeGetter } from "./utils.js";
3
- import { IndividualKey } from "@tanstack/hotkeys";
2
+ import { IndividualKey, MaybeGetter } from "@tanstack/hotkeys";
4
3
  /** Getter arguments can read changing tracked component properties. */
5
4
  export declare function useKeyHold(owner: object, key: MaybeGetter<IndividualKey>): EmberHotkeyState<boolean>;
@@ -1,11 +1,12 @@
1
- import { read, select } from "./utils.js";
1
+ import { select } from "./utils.js";
2
2
  import { getKeyStateTracker } from "@tanstack/hotkeys";
3
+ import { resolveMaybeGetter } from "@tanstack/hotkeys/adapter";
3
4
 
4
5
  // src/useKeyHold.ts
5
6
  /** Getter arguments can read changing tracked component properties. */
6
7
  function useKeyHold(owner, key) {
7
8
  const tracker = getKeyStateTracker();
8
- return select(owner, tracker.store, () => tracker.isKeyHeld(read(key)));
9
+ return select(owner, tracker.store, () => tracker.isKeyHeld(resolveMaybeGetter(key)));
9
10
  }
10
11
 
11
12
  export { useKeyHold };
package/dist/utils.js CHANGED
@@ -1,14 +1,10 @@
1
- import { getHotkeyManager } from "@tanstack/hotkeys";
2
1
  import { registerDestructor } from "@ember/destroyable";
3
- import { subscribePublishedAppHotkeys } from "@tanstack/hotkeys/adapter";
2
+ import { getPublishedAppHotkeysStore, subscribePublishedAppHotkeys } from "@tanstack/hotkeys/adapter";
4
3
  import { trackedObject } from "@ember/reactive/collections";
5
4
 
6
5
  // src/utils.ts
7
6
  /** Reads the merged defaults behind each `createHotkeysScope` result. */
8
7
  const scopeDefaults = /* @__PURE__ */ new WeakMap();
9
- function read(value) {
10
- return typeof value === "function" ? value() : value;
11
- }
12
8
  function select(owner, store, selector) {
13
9
  const state = trackedObject({ version: 0 });
14
10
  let last;
@@ -36,8 +32,8 @@ function trackPublishedAppHotkeys(owner) {
36
32
  }));
37
33
  return () => {
38
34
  state.version;
39
- return getHotkeyManager().appHotkeys.state;
35
+ return getPublishedAppHotkeysStore();
40
36
  };
41
37
  }
42
38
 
43
- export { read, scopeDefaults, select, trackPublishedAppHotkeys };
39
+ export { scopeDefaults, select, trackPublishedAppHotkeys };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tanstack/ember-hotkeys",
3
- "version": "0.13.0",
3
+ "version": "0.13.1",
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.29.0",
43
+ "@tanstack/hotkeys": "0.30.0",
44
44
  "ember-modifier": "^4.2.2"
45
45
  },
46
46
  "devDependencies": {
package/dist/utils.d.ts DELETED
@@ -1,4 +0,0 @@
1
- import "./types.js";
2
- import "@tanstack/hotkeys";
3
- import "@tanstack/hotkeys/adapter";
4
- export type MaybeGetter<T> = T | (() => T);