@tooee/commands 0.10.0 → 0.10.2

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.
@@ -1,7 +1,5 @@
1
1
  import type { KeyEvent } from "@opentui/core";
2
- import type { Mode } from "./mode.js";
3
- import { matchStep } from "./match.js";
4
- import { parseHotkey } from "./parse.js";
2
+
5
3
  import {
6
4
  ROOT_SURFACE_ID,
7
5
  selectActiveModalSurface,
@@ -9,6 +7,9 @@ import {
9
7
  stepsKey,
10
8
  } from "./command-store.js";
11
9
  import type { CommandStoreContext, CommandStoreInstance, SurfaceRecord } from "./command-store.js";
10
+ import { matchStep } from "./match.js";
11
+ import type { Mode } from "./mode.js";
12
+ import { parseHotkey } from "./parse.js";
12
13
  import {
13
14
  DEFAULT_SEQUENCE_TIMEOUT_MS,
14
15
  findPendingMatch,
@@ -57,7 +58,7 @@ const collectCandidates = function collectCandidates(
57
58
  currentMode: Mode,
58
59
  cmdCtx: CommandContext,
59
60
  config: KeyDispatchConfig,
60
- getParsedHotkey: (hotkey: string) => ParsedHotkey,
61
+ getParsedHotkey: (hotkey: string) => ParsedHotkey
61
62
  ): HotkeyCandidates {
62
63
  const singleStep: HotkeyCandidates["singleStep"] = [];
63
64
  const multiStep: HotkeyCandidates["multiStep"] = [];
@@ -92,7 +93,7 @@ const runSurface = function runSurface(
92
93
  environment: DispatchEnvironment,
93
94
  getParsedHotkey: (hotkey: string) => ParsedHotkey,
94
95
  armTimer: () => void,
95
- clearBufferAndTimer: () => void,
96
+ clearBufferAndTimer: () => void
96
97
  ): SurfaceDispatch {
97
98
  const cmdCtx = record.buildCtx();
98
99
  const candidates = collectCandidates(
@@ -100,7 +101,7 @@ const runSurface = function runSurface(
100
101
  record.getMode(),
101
102
  cmdCtx,
102
103
  environment.getConfig(),
103
- getParsedHotkey,
104
+ getParsedHotkey
104
105
  );
105
106
 
106
107
  if (candidates.multiStep.length > 0) {
@@ -167,7 +168,7 @@ const runSurface = function runSurface(
167
168
  const finishDispatch = function finishDispatch(
168
169
  dispatch: SurfaceDispatch,
169
170
  ownerId: string,
170
- state: DispatchState,
171
+ state: DispatchState
171
172
  ): KeyDispatchResult {
172
173
  if (dispatch.outcome === "pending") {
173
174
  state.sequenceOwnerId = ownerId;
@@ -186,7 +187,7 @@ export interface KeyDispatcher {
186
187
  }
187
188
 
188
189
  export const createKeyDispatcher = function createKeyDispatcher(
189
- environment: DispatchEnvironment,
190
+ environment: DispatchEnvironment
190
191
  ): KeyDispatcher {
191
192
  const state: DispatchState = { buffer: [], sequenceOwnerId: null, timer: null };
192
193
  const parseCache = new Map<string, ParsedHotkey>();
@@ -210,7 +211,7 @@ export const createKeyDispatcher = function createKeyDispatcher(
210
211
  clearTimer();
211
212
  state.timer = setTimeout(
212
213
  reset,
213
- environment.getConfig().sequenceTimeoutMs ?? DEFAULT_SEQUENCE_TIMEOUT_MS,
214
+ environment.getConfig().sequenceTimeoutMs ?? DEFAULT_SEQUENCE_TIMEOUT_MS
214
215
  );
215
216
  };
216
217
  const getParsedHotkey = (hotkey: string): ParsedHotkey => {
@@ -226,7 +227,7 @@ export const createKeyDispatcher = function createKeyDispatcher(
226
227
  const dispatchTo = (
227
228
  record: SurfaceRecord,
228
229
  event: KeyEvent,
229
- ctx: CommandStoreContext,
230
+ ctx: CommandStoreContext
230
231
  ): SurfaceDispatch =>
231
232
  runSurface(
232
233
  record,
@@ -236,7 +237,7 @@ export const createKeyDispatcher = function createKeyDispatcher(
236
237
  environment,
237
238
  getParsedHotkey,
238
239
  armTimer,
239
- clearBufferAndTimer,
240
+ clearBufferAndTimer
240
241
  );
241
242
  const finish = (dispatch: SurfaceDispatch, ownerId: string): KeyDispatchResult =>
242
243
  finishDispatch(dispatch, ownerId, state);
package/src/match.ts CHANGED
@@ -1,4 +1,5 @@
1
1
  import type { KeyEvent } from "@opentui/core";
2
+
2
3
  import type { ParsedStep } from "./types.js";
3
4
 
4
5
  /**
package/src/mode.tsx CHANGED
@@ -41,7 +41,7 @@ export const ModeProvider = function ModeProvider({
41
41
 
42
42
  const value = useMemo<ModeContextValue>(
43
43
  () => ({ mode, setMode: changeMode }),
44
- [mode, changeMode],
44
+ [mode, changeMode]
45
45
  );
46
46
 
47
47
  return <ModeContext.Provider value={value}>{children}</ModeContext.Provider>;
package/src/parse.ts CHANGED
@@ -72,7 +72,7 @@ export const parseHotkey = function parseHotkey(hotkey: string, leaderKey?: stri
72
72
  // No leader configured: the hotkey must not spring to life on some
73
73
  // invented default. Zero steps = unmatchable; the dispatcher skips it.
74
74
  warnOnce(
75
- `[tooee/commands] Hotkey "${trimmed}" uses <leader> but no leader key is configured; the hotkey is disabled.`,
75
+ `[tooee/commands] Hotkey "${trimmed}" uses <leader> but no leader key is configured; the hotkey is disabled.`
76
76
  );
77
77
  return { steps: [] };
78
78
  }
@@ -32,7 +32,7 @@ export const ScreenScopeProvider = function ScreenScopeProvider({
32
32
  const parent = useContext(ScreenScopeContext);
33
33
  const value = useMemo<ScreenScopeState>(
34
34
  () => ({ isFocused: parent.isFocused && active }),
35
- [parent.isFocused, active],
35
+ [parent.isFocused, active]
36
36
  );
37
37
  return <ScreenScopeContext value={value}>{children}</ScreenScopeContext>;
38
38
  };
package/src/sequence.ts CHANGED
@@ -1,6 +1,7 @@
1
1
  import type { KeyEvent } from "@opentui/core";
2
- import type { ParsedHotkey } from "./types.js";
2
+
3
3
  import { matchStep } from "./match.js";
4
+ import type { ParsedHotkey } from "./types.js";
4
5
 
5
6
  export const DEFAULT_SEQUENCE_TIMEOUT_MS = 1500;
6
7
 
@@ -32,7 +33,7 @@ export interface SequenceFeedResult {
32
33
  */
33
34
  export const matchesBuffer = function matchesBuffer(
34
35
  buffer: readonly KeyEvent[],
35
- hotkey: ParsedHotkey,
36
+ hotkey: ParsedHotkey
36
37
  ): boolean {
37
38
  const { steps } = hotkey;
38
39
  if (steps.length === 0) {
@@ -60,11 +61,11 @@ export const matchesBuffer = function matchesBuffer(
60
61
  */
61
62
  export const findPendingMatch = function findPendingMatch(
62
63
  buffer: readonly KeyEvent[],
63
- hotkeys: readonly ParsedHotkey[],
64
+ hotkeys: readonly ParsedHotkey[]
64
65
  ): SequencePendingMatch | null {
65
66
  const maxPrefixLength = Math.min(
66
67
  buffer.length,
67
- Math.max(0, ...hotkeys.map((h) => h.steps.length - 1)),
68
+ Math.max(0, ...hotkeys.map((h) => h.steps.length - 1))
68
69
  );
69
70
 
70
71
  for (let prefixLength = maxPrefixLength; prefixLength > 0; prefixLength -= 1) {
@@ -104,7 +105,7 @@ export const findPendingMatch = function findPendingMatch(
104
105
  */
105
106
  export const pruneBuffer = function pruneBuffer(
106
107
  buffer: readonly KeyEvent[],
107
- hotkeys: readonly ParsedHotkey[],
108
+ hotkeys: readonly ParsedHotkey[]
108
109
  ): readonly KeyEvent[] {
109
110
  const maxLen = Math.max(0, ...hotkeys.map((h) => h.steps.length));
110
111
  if (maxLen > 0 && buffer.length > maxLen) {
@@ -1,7 +1,8 @@
1
1
  import { useEffect, useMemo, useRef } from "react";
2
+
2
3
  import { useSurfaceRegistry } from "./context.js";
3
- import type { Command, CommandHandler, CommandWhen } from "./types.js";
4
4
  import type { Mode } from "./mode.js";
5
+ import type { Command, CommandHandler, CommandWhen } from "./types.js";
5
6
 
6
7
  export interface ActionDefinition {
7
8
  id: string;
@@ -28,10 +29,10 @@ export const useActions = function useActions(actions: ActionDefinition[] | unde
28
29
  (a) =>
29
30
  // modes and when-presence are frozen into the registration, so
30
31
  // they must participate in the re-registration key.
31
- `${a.id}:${a.title}:${a.hotkey ?? ""}:${a.category ?? ""}:${a.group ?? ""}:${a.icon ?? ""}:${a.hidden ?? false}:${a.modes?.join("|") ?? ""}:${a.when ? 1 : 0}`,
32
+ `${a.id}:${a.title}:${a.hotkey ?? ""}:${a.category ?? ""}:${a.group ?? ""}:${a.icon ?? ""}:${a.hidden ?? false}:${a.modes?.join("|") ?? ""}:${a.when ? 1 : 0}`
32
33
  )
33
34
  .join(",") ?? "",
34
- [actions],
35
+ [actions]
35
36
  );
36
37
 
37
38
  useEffect(() => {
@@ -1,7 +1,8 @@
1
1
  import { useEffect, useRef } from "react";
2
- import type { Command, CommandHandler, CommandWhen } from "./types.js";
3
- import type { Mode } from "./mode.js";
2
+
4
3
  import { useSurfaceRegistry } from "./context.js";
4
+ import type { Mode } from "./mode.js";
5
+ import type { Command, CommandHandler, CommandWhen } from "./types.js";
5
6
 
6
7
  export interface UseCommandOptions {
7
8
  id: string;