@tooee/commands 0.1.18 → 0.1.20

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/context.d.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  import { type ReactNode } from "react";
2
- import type { Command, CommandContext, CommandGroup, CommandRegistry, CommandSequenceState, RegisteredCommandGroup } from "./types.js";
2
+ import type { ActiveCommandSurface, Command, CommandContext, CommandGroup, CommandRegistry, CommandSequenceState, CommandSurfaceRole, RegisteredCommandGroup } from "./types.js";
3
3
  import type { Mode } from "./mode.js";
4
4
  type ContextGetter = () => Partial<CommandContext>;
5
5
  interface CommandContextValue {
@@ -17,12 +17,36 @@ export interface CommandProviderProps {
17
17
  sequenceTimeoutMs?: number;
18
18
  }
19
19
  export declare function CommandProvider({ children, leader, keymap, initialMode, sequenceTimeoutMs, }: CommandProviderProps): ReactNode;
20
+ export interface CommandSurfaceProviderProps {
21
+ children: ReactNode;
22
+ /** Stable id for the surface (typically the overlay id). */
23
+ id: string;
24
+ /** Interaction role (default "modal"). */
25
+ role?: CommandSurfaceRole;
26
+ /** Initial local mode for this surface (default "cursor"). */
27
+ initialMode?: Mode;
28
+ }
29
+ /**
30
+ * Mounts an overlay-owned command surface. Children registered via `useCommand`
31
+ * target this surface's local registry, and `useMode`/`useSetMode` read/write
32
+ * this surface's local mode instead of the root app's mode.
33
+ *
34
+ * While a `modal` surface is topmost it owns keyboard input and suspends the
35
+ * parent app's commands; a `passive` surface never becomes the keyboard owner.
36
+ */
37
+ export declare function CommandSurfaceProvider({ children, id, role, initialMode, }: CommandSurfaceProviderProps): ReactNode;
20
38
  export declare function useCommandContext(): {
21
39
  commands: Command[];
22
40
  invoke: (id: string) => void;
23
41
  };
24
42
  export declare function useCommandRegistry(): CommandContextValue;
25
43
  export declare function useCommandSequenceState(): CommandSequenceState | null;
44
+ /**
45
+ * Metadata for the topmost modal command surface, or null when the root app is
46
+ * the active surface. Intended for which-key/help to read shortcuts from the
47
+ * active interaction surface.
48
+ */
49
+ export declare function useActiveCommandSurface(): ActiveCommandSurface | null;
26
50
  export declare function useCommandGroup(group: CommandGroup): void;
27
51
  export declare function useProvideCommandContext(getter: () => Partial<CommandContext>): void;
28
52
  export {};
@@ -1 +1 @@
1
- {"version":3,"file":"context.d.ts","sourceRoot":"","sources":["../src/context.tsx"],"names":[],"mappings":"AAAA,OAAO,EAQL,KAAK,SAAS,EACf,MAAM,OAAO,CAAA;AAEd,OAAO,KAAK,EACV,OAAO,EACP,cAAc,EACd,YAAY,EACZ,eAAe,EACf,oBAAoB,EAGpB,sBAAsB,EACvB,MAAM,YAAY,CAAA;AACnB,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,WAAW,CAAA;AAQrC,KAAK,aAAa,GAAG,MAAM,OAAO,CAAC,cAAc,CAAC,CAAA;AAElD,UAAU,mBAAmB;IAC3B,QAAQ,EAAE,eAAe,CAAA;IACzB,SAAS,CAAC,EAAE,MAAM,CAAA;IAClB,cAAc,EAAE,GAAG,CAAC,MAAM,EAAE,aAAa,CAAC,CAAA;IAC1C,MAAM,EAAE,GAAG,CAAC,MAAM,EAAE,sBAAsB,CAAC,CAAA;CAC5C;AAED,QAAA,MAAM,cAAc,qDAAkD,CAAA;AAGtE,MAAM,WAAW,oBAAoB;IACnC,QAAQ,EAAE,SAAS,CAAA;IACnB,MAAM,CAAC,EAAE,MAAM,CAAA;IACf,MAAM,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAA;IAC/B,WAAW,CAAC,EAAE,IAAI,CAAA;IAClB,iBAAiB,CAAC,EAAE,MAAM,CAAA;CAC3B;AAED,wBAAgB,eAAe,CAAC,EAC9B,QAAQ,EACR,MAAM,EACN,MAAM,EACN,WAAW,EACX,iBAAiB,GAClB,EAAE,oBAAoB,aAQtB;AAqLD,wBAAgB,iBAAiB,IAAI;IAAE,QAAQ,EAAE,OAAO,EAAE,CAAC;IAAC,MAAM,EAAE,CAAC,EAAE,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EACN,MAAM,EACN,WAAW,EACX,iBAAiB,GAClB,EAAE,oBAAoB,aAQtB;AAqOD,MAAM,WAAW,2BAA2B;IAC1C,QAAQ,EAAE,SAAS,CAAA;IACnB,4DAA4D;IAC5D,EAAE,EAAE,MAAM,CAAA;IACV,0CAA0C;IAC1C,IAAI,CAAC,EAAE,kBAAkB,CAAA;IACzB,8DAA8D;IAC9D,WAAW,CAAC,EAAE,IAAI,CAAA;CACnB;AAED;;;;;;;GAOG;AACH,wBAAgB,sBAAsB,CAAC,EACrC,QAAQ,EACR,EAAE,EACF,IAAc,EACd,WAAsB,GACvB,EAAE,2BAA2B,aAQ7B;AAmFD,wBAAgB,iBAAiB,IAAI;IAAE,QAAQ,EAAE,OAAO,EAAE,CAAC;IAAC,MAAM,EAAE,CAAC,EAAE,EAAE,MAAM,KAAK,IAAI,CAAA;CAAE,CAazF;AAED,wBAAgB,kBAAkB,IAAI,mBAAmB,CAMxD;AAED,wBAAgB,uBAAuB,IAAI,oBAAoB,GAAG,IAAI,CAErE;AAED;;;;GAIG;AACH,wBAAgB,uBAAuB,IAAI,oBAAoB,GAAG,IAAI,CAGrE;AAED,wBAAgB,eAAe,CAAC,KAAK,EAAE,YAAY,GAAG,IAAI,CA8BzD;AAkBD,wBAAgB,wBAAwB,CAAC,MAAM,EAAE,MAAM,OAAO,CAAC,cAAc,CAAC,GAAG,IAAI,CAuBpF"}
package/dist/context.js CHANGED
@@ -8,6 +8,33 @@ import { SequenceTracker } from "./sequence.js";
8
8
  const DEFAULT_MODES = ["cursor"];
9
9
  const CommandContext = createContext(null);
10
10
  const CommandSequenceContext = createContext(null);
11
+ const CommandSurfaceStackContext = createContext(null);
12
+ /** Nesting depth of the nearest command surface (0 at the root app). */
13
+ const CommandSurfaceDepthContext = createContext(0);
14
+ /**
15
+ * Build a command registry whose `invoke` resolves the command context lazily
16
+ * via `getCtx`, so a surface always dispatches with its own (local) mode and
17
+ * the current shared context sources.
18
+ */
19
+ function createRegistry(getCtx) {
20
+ const commands = new Map();
21
+ return {
22
+ commands,
23
+ register(command) {
24
+ commands.set(command.id, command);
25
+ return () => {
26
+ commands.delete(command.id);
27
+ };
28
+ },
29
+ invoke(id) {
30
+ const ctx = getCtx();
31
+ const cmd = commands.get(id);
32
+ if (cmd && (!cmd.when || cmd.when(ctx))) {
33
+ cmd.handler(ctx);
34
+ }
35
+ },
36
+ };
37
+ }
11
38
  export function CommandProvider({ children, leader, keymap, initialMode, sequenceTimeoutMs, }) {
12
39
  return (_jsx(ModeProvider, { initialMode: initialMode, children: _jsx(CommandDispatcher, { leader: leader, keymap: keymap, sequenceTimeoutMs: sequenceTimeoutMs, children: children }) }));
13
40
  }
@@ -37,25 +64,47 @@ function CommandDispatcher({ children, leader, keymap, sequenceTimeoutMs, }) {
37
64
  }
38
65
  return ctx;
39
66
  }, [setMode]);
67
+ const buildCtxRef = useRef(buildCtx);
68
+ buildCtxRef.current = buildCtx;
40
69
  if (registryRef.current === null) {
41
- const commands = new Map();
42
- registryRef.current = {
43
- commands,
44
- register(command) {
45
- commands.set(command.id, command);
46
- return () => {
47
- commands.delete(command.id);
48
- };
49
- },
50
- invoke(id) {
51
- const ctx = buildCtx();
52
- const cmd = commands.get(id);
53
- if (cmd && (!cmd.when || cmd.when(ctx))) {
54
- cmd.handler(ctx);
55
- }
56
- },
57
- };
70
+ registryRef.current = createRegistry(() => buildCtxRef.current());
58
71
  }
72
+ // --- Command surface stack ----------------------------------------------
73
+ // The root registry above is the implicit base surface. Modal overlays push
74
+ // surfaces on top of it; while a modal surface is topmost, key dispatch is
75
+ // arbitrated to that surface only and the root (and lower surfaces) are
76
+ // suspended — even for keys the surface does not handle.
77
+ const surfaceEntriesRef = useRef([]);
78
+ const surfaceOrderRef = useRef(0);
79
+ const [surfaceVersion, setSurfaceVersion] = useState(0);
80
+ const registerSurface = useCallback((entry) => {
81
+ entry.order = surfaceOrderRef.current++;
82
+ surfaceEntriesRef.current = [...surfaceEntriesRef.current, entry];
83
+ setSurfaceVersion((v) => v + 1);
84
+ return () => {
85
+ surfaceEntriesRef.current = surfaceEntriesRef.current.filter((e) => e !== entry);
86
+ setSurfaceVersion((v) => v + 1);
87
+ };
88
+ }, []);
89
+ const getActiveModalSurface = useCallback(() => {
90
+ let best = null;
91
+ for (const entry of surfaceEntriesRef.current) {
92
+ if (entry.role !== "modal")
93
+ continue;
94
+ if (best === null ||
95
+ entry.depth > best.depth ||
96
+ (entry.depth === best.depth && entry.order > best.order)) {
97
+ best = entry;
98
+ }
99
+ }
100
+ return best;
101
+ }, []);
102
+ const activeModalSurface = useMemo(() => {
103
+ const surface = getActiveModalSurface();
104
+ return surface ? { id: surface.id, role: surface.role } : null;
105
+ // eslint-disable-next-line react-hooks/exhaustive-deps
106
+ }, [getActiveModalSurface, surfaceVersion]);
107
+ const surfaceStackValue = useMemo(() => ({ register: registerSurface, getActiveModalSurface, activeModalSurface }), [registerSurface, getActiveModalSurface, activeModalSurface]);
59
108
  const trackerRef = useRef(new SequenceTracker({
60
109
  timeout: sequenceTimeoutMs,
61
110
  onReset: () => clearSequenceStateRef.current(),
@@ -74,11 +123,14 @@ function CommandDispatcher({ children, leader, keymap, sequenceTimeoutMs, }) {
74
123
  useKeyboard((event) => {
75
124
  if (event.defaultPrevented)
76
125
  return;
77
- const registry = registryRef.current;
78
- if (!registry)
126
+ const rootRegistry = registryRef.current;
127
+ if (!rootRegistry)
79
128
  return;
80
- const currentMode = mode;
81
- const ctx = buildCtx();
129
+ // Arbitration: a topmost modal surface owns input; otherwise the root app.
130
+ const activeSurface = getActiveModalSurface();
131
+ const registry = activeSurface ? activeSurface.registry : rootRegistry;
132
+ const currentMode = activeSurface ? activeSurface.getMode() : modeRef.current;
133
+ const ctx = activeSurface ? activeSurface.buildCtx() : buildCtx();
82
134
  // Collect eligible commands with their parsed hotkeys
83
135
  const singleStepCandidates = [];
84
136
  const multiStepCandidates = [];
@@ -139,18 +191,92 @@ function CommandDispatcher({ children, leader, keymap, sequenceTimeoutMs, }) {
139
191
  return;
140
192
  }
141
193
  }
194
+ // A modal surface swallows unhandled keys: dispatch never falls through to
195
+ // the root app while a modal surface is topmost.
142
196
  });
143
197
  useEffect(() => {
144
198
  trackerRef.current.reset();
145
199
  setSequenceState(null);
146
200
  }, [mode]);
201
+ // Reset any in-flight sequence when keyboard ownership changes (e.g. a modal
202
+ // surface opens/closes) so partial chords don't leak across surfaces. Passive
203
+ // surfaces such as which-key must not clear the sequence they are displaying.
204
+ useEffect(() => {
205
+ trackerRef.current.reset();
206
+ setSequenceState(null);
207
+ }, [activeModalSurface?.id]);
147
208
  const ctxValue = useMemo(() => ({
148
209
  registry: registryRef.current,
149
210
  leaderKey: leader,
150
211
  contextSources: contextSourcesRef.current,
151
212
  groups: groupsRef.current,
152
213
  }), [leader]);
153
- return (_jsx(CommandContext.Provider, { value: ctxValue, children: _jsx(CommandSequenceContext, { value: sequenceState, children: children }) }));
214
+ return (_jsx(CommandContext.Provider, { value: ctxValue, children: _jsx(CommandSurfaceStackContext.Provider, { value: surfaceStackValue, children: _jsx(CommandSequenceContext, { value: sequenceState, children: children }) }) }));
215
+ }
216
+ /**
217
+ * Mounts an overlay-owned command surface. Children registered via `useCommand`
218
+ * target this surface's local registry, and `useMode`/`useSetMode` read/write
219
+ * this surface's local mode instead of the root app's mode.
220
+ *
221
+ * While a `modal` surface is topmost it owns keyboard input and suspends the
222
+ * parent app's commands; a `passive` surface never becomes the keyboard owner.
223
+ */
224
+ export function CommandSurfaceProvider({ children, id, role = "modal", initialMode = "cursor", }) {
225
+ return (_jsx(ModeProvider, { initialMode: initialMode, children: _jsx(CommandSurfaceInner, { id: id, role: role, children: children }) }));
226
+ }
227
+ function CommandSurfaceInner({ children, id, role, }) {
228
+ const parent = useContext(CommandContext);
229
+ const stack = useContext(CommandSurfaceStackContext);
230
+ if (!parent || !stack) {
231
+ throw new Error("CommandSurfaceProvider must be used within a CommandProvider");
232
+ }
233
+ const parentDepth = useContext(CommandSurfaceDepthContext);
234
+ const depth = parentDepth + 1;
235
+ const mode = useMode();
236
+ const setMode = useSetMode();
237
+ const modeRef = useRef(mode);
238
+ modeRef.current = mode;
239
+ const registryRef = useRef(null);
240
+ const buildCtx = useCallback(() => {
241
+ const ctx = {
242
+ mode: modeRef.current,
243
+ setMode,
244
+ commands: {
245
+ invoke: (cmdId) => registryRef.current?.invoke(cmdId),
246
+ list: () => Array.from(registryRef.current?.commands.values() ?? []),
247
+ },
248
+ exit: () => { },
249
+ };
250
+ for (const getter of parent.contextSources.values()) {
251
+ Object.assign(ctx, getter());
252
+ }
253
+ return ctx;
254
+ }, [parent.contextSources, setMode]);
255
+ const buildCtxRef = useRef(buildCtx);
256
+ buildCtxRef.current = buildCtx;
257
+ if (registryRef.current === null) {
258
+ registryRef.current = createRegistry(() => buildCtxRef.current());
259
+ }
260
+ const { register } = stack;
261
+ useEffect(() => {
262
+ const entry = {
263
+ id,
264
+ role,
265
+ depth,
266
+ order: 0,
267
+ registry: registryRef.current,
268
+ getMode: () => modeRef.current,
269
+ buildCtx: () => buildCtxRef.current(),
270
+ };
271
+ return register(entry);
272
+ }, [register, id, role, depth]);
273
+ const ctxValue = useMemo(() => ({
274
+ registry: registryRef.current,
275
+ leaderKey: parent.leaderKey,
276
+ contextSources: parent.contextSources,
277
+ groups: parent.groups,
278
+ }), [parent.leaderKey, parent.contextSources, parent.groups]);
279
+ return (_jsx(CommandContext.Provider, { value: ctxValue, children: _jsx(CommandSurfaceDepthContext.Provider, { value: depth, children: children }) }));
154
280
  }
155
281
  export function useCommandContext() {
156
282
  const ctx = useContext(CommandContext);
@@ -175,6 +301,15 @@ export function useCommandRegistry() {
175
301
  export function useCommandSequenceState() {
176
302
  return useContext(CommandSequenceContext);
177
303
  }
304
+ /**
305
+ * Metadata for the topmost modal command surface, or null when the root app is
306
+ * the active surface. Intended for which-key/help to read shortcuts from the
307
+ * active interaction surface.
308
+ */
309
+ export function useActiveCommandSurface() {
310
+ const ctx = useContext(CommandSurfaceStackContext);
311
+ return ctx ? ctx.activeModalSurface : null;
312
+ }
178
313
  export function useCommandGroup(group) {
179
314
  const ctx = useContext(CommandContext);
180
315
  if (!ctx) {
@@ -1 +1 @@
1
- {"version":3,"file":"context.js","sourceRoot":"","sources":["../src/context.tsx"],"names":[],"mappings":";AAAA,OAAO,EACL,aAAa,EACb,UAAU,EACV,MAAM,EACN,WAAW,EACX,SAAS,EACT,OAAO,EACP,QAAQ,GAET,MAAM,OAAO,CAAA;AACd,OAAO,EAAE,WAAW,EAAE,MAAM,gBAAgB,CAAA;AAY5C,OAAO,EAAE,YAAY,EAAE,OAAO,EAAE,UAAU,EAAE,MAAM,WAAW,CAAA;AAC7D,OAAO,EAAE,WAAW,EAAE,MAAM,YAAY,CAAA;AACxC,OAAO,EAAE,SAAS,EAAE,MAAM,YAAY,CAAA;AACtC,OAAO,EAAE,eAAe,EAAE,MAAM,eAAe,CAAA;AAE/C,MAAM,aAAa,GAAW,CAAC,QAAQ,CAAC,CAAA;AAWxC,MAAM,cAAc,GAAG,aAAa,CAA6B,IAAI,CAAC,CAAA;AACtE,MAAM,sBAAsB,GAAG,aAAa,CAA8B,IAAI,CAAC,CAAA;AAU/E,MAAM,UAAU,eAAe,CAAC,EAC9B,QAAQ,EACR,MAAM,EACN,MAAM,EACN,WAAW,EACX,iBAAiB,GACI;IACrB,OAAO,CACL,KAAC,YAAY,IAAC,WAAW,EAAE,WAAW,YACpC,KAAC,iBAAiB,IAAC,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,iBAAiB,EAAE,iBAAiB,YACpF,QAAQ,GACS,GACP,CAChB,CAAA;AACH,CAAC;AAED,SAAS,iBAAiB,CAAC,EACzB,QAAQ,EACR,MAAM,EACN,MAAM,EACN,iBAAiB,GAMlB;IACC,MAAM,WAAW,GAAG,MAAM,CAAyB,IAAI,CAAC,CAAA;IACxD,MAAM,iBAAiB,GAAG,MAAM,CAAC,IAAI,GAAG,EAAyB,CAAC,CAAA;IAClE,MAAM,SAAS,GAAG,MAAM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GAAG,EAAE,CAAC,SAAS,CAAC,OAAO,EAAE,CAAC,CAAA;QACjD,OAAO,GAAG,EAAE;YACV,cAAc,CAAC,MAAM,CAAC,EAAE,CAAC,CAAA;QAC3B,CAAC,CAAA;IACH,CAAC,EAAE,CAAC,cAAc,CAAC,CAAC,CAAA;AACtB,CAAC"}
package/dist/index.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- export type { Command, CommandContext, CommandContextBase, CommandGroup, CommandHandler, CommandSequenceCandidate, CommandSequenceState, CommandWhen, ParsedHotkey, ParsedStep, RegisteredCommandGroup, } from "./types.js";
1
+ export type { ActiveCommandSurface, Command, CommandContext, CommandContextBase, CommandGroup, CommandHandler, CommandSequenceCandidate, CommandSequenceState, CommandSurfaceEntry, CommandSurfaceRole, CommandWhen, ParsedHotkey, ParsedStep, RegisteredCommandGroup, } from "./types.js";
2
2
  export type { Mode } from "./mode.js";
3
3
  export { ModeProvider, useMode, useSetMode } from "./mode.js";
4
4
  export type { ModeProviderProps } from "./mode.js";
@@ -6,8 +6,8 @@ export { parseHotkey } from "./parse.js";
6
6
  export { matchStep } from "./match.js";
7
7
  export { DEFAULT_SEQUENCE_TIMEOUT_MS, SequenceTracker } from "./sequence.js";
8
8
  export type { SequenceFeedResult, SequencePendingMatch, SequenceTrackerOptions, } from "./sequence.js";
9
- export { CommandProvider, useCommandContext, useCommandGroup, useCommandRegistry, useCommandSequenceState, useProvideCommandContext, } from "./context.js";
10
- export type { CommandProviderProps } from "./context.js";
9
+ export { CommandProvider, CommandSurfaceProvider, useActiveCommandSurface, useCommandContext, useCommandGroup, useCommandRegistry, useCommandSequenceState, useProvideCommandContext, } from "./context.js";
10
+ export type { CommandProviderProps, CommandSurfaceProviderProps } from "./context.js";
11
11
  export { useCommand } from "./use-command.js";
12
12
  export type { UseCommandOptions } from "./use-command.js";
13
13
  export { useActions } from "./use-actions.js";
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],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YAAY,CAAA;AACnB,YAAY,EAAE,IAAI,EAAE,MAAM,WAAW,CAAA;AACrC,OAAO,EAAE,YAAY,EAAE,OAAO,EAAE,UAAU,EAAE,MAAM,WAAW,CAAA;AAC7D,YAAY,EAAE,iBAAiB,EAAE,MAAM,WAAW,CAAA;AAClD,OAAO,EAAE,WAAW,EAAE,MAAM,YAAY,CAAA;AACxC,OAAO,EAAE,SAAS,EAAE,MAAM,YAAY,CAAA;AACtC,OAAO,EAAE,2BAA2B,EAAE,eAAe,EAAE,MAAM,eAAe,CAAA;AAC5E,YAAY,EACV,kBAAkB,EAClB,oBAAoB,EACpB,sBAAsB,GACvB,MAAM,eAAe,CAAA;AACtB,OAAO,EACL,eAAe,EACf,sBAAsB,EACtB,uBAAuB,EACvB,iBAAiB,EACjB,eAAe,EACf,kBAAkB,EAClB,uBAAuB,EACvB,wBAAwB,GACzB,MAAM,cAAc,CAAA;AACrB,YAAY,EAAE,oBAAoB,EAAE,2BAA2B,EAAE,MAAM,cAAc,CAAA;AACrF,OAAO,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAA;AAC7C,YAAY,EAAE,iBAAiB,EAAE,MAAM,kBAAkB,CAAA;AACzD,OAAO,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAA;AAC7C,YAAY,EAAE,gBAAgB,EAAE,MAAM,kBAAkB,CAAA"}
package/dist/index.js CHANGED
@@ -2,7 +2,7 @@ export { ModeProvider, useMode, useSetMode } from "./mode.js";
2
2
  export { parseHotkey } from "./parse.js";
3
3
  export { matchStep } from "./match.js";
4
4
  export { DEFAULT_SEQUENCE_TIMEOUT_MS, SequenceTracker } from "./sequence.js";
5
- export { CommandProvider, useCommandContext, useCommandGroup, useCommandRegistry, useCommandSequenceState, useProvideCommandContext, } from "./context.js";
5
+ export { CommandProvider, CommandSurfaceProvider, useActiveCommandSurface, useCommandContext, useCommandGroup, useCommandRegistry, useCommandSequenceState, useProvideCommandContext, } from "./context.js";
6
6
  export { useCommand } from "./use-command.js";
7
7
  export { useActions } from "./use-actions.js";
8
8
  //# sourceMappingURL=index.js.map
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAcA,OAAO,EAAE,YAAY,EAAE,OAAO,EAAE,UAAU,EAAE,MAAM,WAAW,CAAA;AAE7D,OAAO,EAAE,WAAW,EAAE,MAAM,YAAY,CAAA;AACxC,OAAO,EAAE,SAAS,EAAE,MAAM,YAAY,CAAA;AACtC,OAAO,EAAE,2BAA2B,EAAE,eAAe,EAAE,MAAM,eAAe,CAAA;AAM5E,OAAO,EACL,eAAe,EACf,iBAAiB,EACjB,eAAe,EACf,kBAAkB,EAClB,uBAAuB,EACvB,wBAAwB,GACzB,MAAM,cAAc,CAAA;AAErB,OAAO,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAA;AAE7C,OAAO,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAA"}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAiBA,OAAO,EAAE,YAAY,EAAE,OAAO,EAAE,UAAU,EAAE,MAAM,WAAW,CAAA;AAE7D,OAAO,EAAE,WAAW,EAAE,MAAM,YAAY,CAAA;AACxC,OAAO,EAAE,SAAS,EAAE,MAAM,YAAY,CAAA;AACtC,OAAO,EAAE,2BAA2B,EAAE,eAAe,EAAE,MAAM,eAAe,CAAA;AAM5E,OAAO,EACL,eAAe,EACf,sBAAsB,EACtB,uBAAuB,EACvB,iBAAiB,EACjB,eAAe,EACf,kBAAkB,EAClB,uBAAuB,EACvB,wBAAwB,GACzB,MAAM,cAAc,CAAA;AAErB,OAAO,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAA;AAE7C,OAAO,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAA"}
package/dist/types.d.ts CHANGED
@@ -40,6 +40,37 @@ export interface CommandRegistry {
40
40
  register: (command: Command) => () => void;
41
41
  invoke: (id: string) => void;
42
42
  }
43
+ /**
44
+ * Interaction role of a command surface.
45
+ * - `modal`: owns keyboard input while topmost and suspends every lower surface
46
+ * (including the root app) — even for keys it does not handle.
47
+ * - `passive`: never becomes the keyboard owner; purely visual.
48
+ */
49
+ export type CommandSurfaceRole = "modal" | "passive";
50
+ /**
51
+ * A command surface is an interaction surface that can own keyboard input.
52
+ * The root app is the implicit base surface; modal overlays push surfaces on
53
+ * top of it. Each surface carries its own command registry and local mode so
54
+ * the same command definitions can be rooted in a standalone app or pushed by
55
+ * an overlay without leaking mode/command state into the parent.
56
+ */
57
+ export interface CommandSurfaceEntry {
58
+ id: string;
59
+ role: CommandSurfaceRole;
60
+ /** Nesting depth (root children are depth 0; the first overlay surface is 1). */
61
+ depth: number;
62
+ /** Monotonic registration order, used to break depth ties. */
63
+ order: number;
64
+ registry: CommandRegistry;
65
+ /** Reads this surface's current local mode. */
66
+ getMode: () => Mode;
67
+ /** Builds the command context handed to this surface's command handlers. */
68
+ buildCtx: () => CommandContext;
69
+ }
70
+ export interface ActiveCommandSurface {
71
+ id: string;
72
+ role: CommandSurfaceRole;
73
+ }
43
74
  export interface CommandGroup {
44
75
  id: string;
45
76
  title: string;
@@ -1 +1 @@
1
- {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,WAAW,CAAA;AAErC,MAAM,WAAW,kBAAkB;IACjC,IAAI,EAAE,IAAI,CAAA;IACV,OAAO,EAAE,CAAC,IAAI,EAAE,IAAI,KAAK,IAAI,CAAA;IAC7B,QAAQ,EAAE;QAAE,MAAM,EAAE,CAAC,EAAE,EAAE,MAAM,KAAK,IAAI,CAAC;QAAC,IAAI,EAAE,MAAM,OAAO,EAAE,CAAA;KAAE,CAAA;IACjE,IAAI,EAAE,MAAM,IAAI,CAAA;CACjB;AAED,MAAM,WAAW,cAAe,SAAQ,kBAAkB;IACxD,CAAC,GAAG,EAA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ACzB;AAED,MAAM,WAAW,YAAY;IAC3B,EAAE,EAAE,MAAM,CAAA;IACV,KAAK,EAAE,MAAM,CAAA;IACb,MAAM,EAAE,MAAM,CAAA;IACd,WAAW,CAAC,EAAE,MAAM,CAAA;IACpB,IAAI,CAAC,EAAE,MAAM,CAAA;IACb,KAAK,CAAC,EAAE,MAAM,CAAA;CACf;AAED,MAAM,WAAW,sBAAuB,SAAQ,YAAY;IAC1D,SAAS,EAAE,MAAM,CAAA;CAClB;AAED,MAAM,WAAW,wBAAwB;IACvC,OAAO,EAAE,OAAO,CAAA;IAChB,MAAM,EAAE,MAAM,CAAA;IACd,KAAK,EAAE,UAAU,EAAE,CAAA;IACnB,cAAc,EAAE,UAAU,EAAE,CAAA;IAC5B,QAAQ,EAAE,UAAU,CAAA;IACpB,KAAK,CAAC,EAAE,YAAY,CAAA;CACrB;AAED,MAAM,WAAW,oBAAoB;IACnC,MAAM,EAAE,UAAU,EAAE,CAAA;IACpB,UAAU,EAAE,wBAAwB,EAAE,CAAA;CACvC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tooee/commands",
3
- "version": "0.1.18",
3
+ "version": "0.1.20",
4
4
  "description": "Vim-inspired modal command system for Tooee",
5
5
  "keywords": [
6
6
  "cli",
package/src/context.tsx CHANGED
@@ -10,11 +10,14 @@ import {
10
10
  } from "react"
11
11
  import { useKeyboard } from "@opentui/react"
12
12
  import type {
13
+ ActiveCommandSurface,
13
14
  Command,
14
15
  CommandContext,
15
16
  CommandGroup,
16
17
  CommandRegistry,
17
18
  CommandSequenceState,
19
+ CommandSurfaceEntry,
20
+ CommandSurfaceRole,
18
21
  ParsedHotkey,
19
22
  ParsedStep,
20
23
  RegisteredCommandGroup,
@@ -36,8 +39,45 @@ interface CommandContextValue {
36
39
  groups: Map<string, RegisteredCommandGroup>
37
40
  }
38
41
 
42
+ interface CommandSurfaceStackValue {
43
+ /** Register a surface; returns an unregister function. Mutates entry.order. */
44
+ register: (entry: CommandSurfaceEntry) => () => void
45
+ /** Resolve the topmost modal surface (deepest, then most-recently registered). */
46
+ getActiveModalSurface: () => CommandSurfaceEntry | null
47
+ /** Reactive metadata for the active modal surface (for which-key/help). */
48
+ activeModalSurface: ActiveCommandSurface | null
49
+ }
50
+
39
51
  const CommandContext = createContext<CommandContextValue | null>(null)
40
52
  const CommandSequenceContext = createContext<CommandSequenceState | null>(null)
53
+ const CommandSurfaceStackContext = createContext<CommandSurfaceStackValue | null>(null)
54
+ /** Nesting depth of the nearest command surface (0 at the root app). */
55
+ const CommandSurfaceDepthContext = createContext(0)
56
+
57
+ /**
58
+ * Build a command registry whose `invoke` resolves the command context lazily
59
+ * via `getCtx`, so a surface always dispatches with its own (local) mode and
60
+ * the current shared context sources.
61
+ */
62
+ function createRegistry(getCtx: () => CommandContext): CommandRegistry {
63
+ const commands = new Map<string, Command>()
64
+ return {
65
+ commands,
66
+ register(command: Command) {
67
+ commands.set(command.id, command)
68
+ return () => {
69
+ commands.delete(command.id)
70
+ }
71
+ },
72
+ invoke(id: string) {
73
+ const ctx = getCtx()
74
+ const cmd = commands.get(id)
75
+ if (cmd && (!cmd.when || cmd.when(ctx))) {
76
+ cmd.handler(ctx)
77
+ }
78
+ },
79
+ }
80
+ }
41
81
 
42
82
  export interface CommandProviderProps {
43
83
  children: ReactNode
@@ -101,26 +141,58 @@ function CommandDispatcher({
101
141
  return ctx as CommandContext
102
142
  }, [setMode])
103
143
 
144
+ const buildCtxRef = useRef(buildCtx)
145
+ buildCtxRef.current = buildCtx
146
+
104
147
  if (registryRef.current === null) {
105
- const commands = new Map<string, Command>()
106
- registryRef.current = {
107
- commands,
108
- register(command: Command) {
109
- commands.set(command.id, command)
110
- return () => {
111
- commands.delete(command.id)
112
- }
113
- },
114
- invoke(id: string) {
115
- const ctx = buildCtx()
116
- const cmd = commands.get(id)
117
- if (cmd && (!cmd.when || cmd.when(ctx))) {
118
- cmd.handler(ctx)
119
- }
120
- },
121
- }
148
+ registryRef.current = createRegistry(() => buildCtxRef.current())
122
149
  }
123
150
 
151
+ // --- Command surface stack ----------------------------------------------
152
+ // The root registry above is the implicit base surface. Modal overlays push
153
+ // surfaces on top of it; while a modal surface is topmost, key dispatch is
154
+ // arbitrated to that surface only and the root (and lower surfaces) are
155
+ // suspended — even for keys the surface does not handle.
156
+ const surfaceEntriesRef = useRef<CommandSurfaceEntry[]>([])
157
+ const surfaceOrderRef = useRef(0)
158
+ const [surfaceVersion, setSurfaceVersion] = useState(0)
159
+
160
+ const registerSurface = useCallback((entry: CommandSurfaceEntry) => {
161
+ entry.order = surfaceOrderRef.current++
162
+ surfaceEntriesRef.current = [...surfaceEntriesRef.current, entry]
163
+ setSurfaceVersion((v) => v + 1)
164
+ return () => {
165
+ surfaceEntriesRef.current = surfaceEntriesRef.current.filter((e) => e !== entry)
166
+ setSurfaceVersion((v) => v + 1)
167
+ }
168
+ }, [])
169
+
170
+ const getActiveModalSurface = useCallback((): CommandSurfaceEntry | null => {
171
+ let best: CommandSurfaceEntry | null = null
172
+ for (const entry of surfaceEntriesRef.current) {
173
+ if (entry.role !== "modal") continue
174
+ if (
175
+ best === null ||
176
+ entry.depth > best.depth ||
177
+ (entry.depth === best.depth && entry.order > best.order)
178
+ ) {
179
+ best = entry
180
+ }
181
+ }
182
+ return best
183
+ }, [])
184
+
185
+ const activeModalSurface = useMemo<ActiveCommandSurface | null>(() => {
186
+ const surface = getActiveModalSurface()
187
+ return surface ? { id: surface.id, role: surface.role } : null
188
+ // eslint-disable-next-line react-hooks/exhaustive-deps
189
+ }, [getActiveModalSurface, surfaceVersion])
190
+
191
+ const surfaceStackValue = useMemo<CommandSurfaceStackValue>(
192
+ () => ({ register: registerSurface, getActiveModalSurface, activeModalSurface }),
193
+ [registerSurface, getActiveModalSurface, activeModalSurface],
194
+ )
195
+
124
196
  const trackerRef = useRef(
125
197
  new SequenceTracker({
126
198
  timeout: sequenceTimeoutMs,
@@ -146,11 +218,14 @@ function CommandDispatcher({
146
218
  useKeyboard((event) => {
147
219
  if (event.defaultPrevented) return
148
220
 
149
- const registry = registryRef.current
150
- if (!registry) return
221
+ const rootRegistry = registryRef.current
222
+ if (!rootRegistry) return
151
223
 
152
- const currentMode = mode
153
- const ctx = buildCtx()
224
+ // Arbitration: a topmost modal surface owns input; otherwise the root app.
225
+ const activeSurface = getActiveModalSurface()
226
+ const registry = activeSurface ? activeSurface.registry : rootRegistry
227
+ const currentMode = activeSurface ? activeSurface.getMode() : modeRef.current
228
+ const ctx = activeSurface ? activeSurface.buildCtx() : buildCtx()
154
229
 
155
230
  // Collect eligible commands with their parsed hotkeys
156
231
  const singleStepCandidates: { command: Command; parsed: ParsedHotkey }[] = []
@@ -218,6 +293,9 @@ function CommandDispatcher({
218
293
  return
219
294
  }
220
295
  }
296
+
297
+ // A modal surface swallows unhandled keys: dispatch never falls through to
298
+ // the root app while a modal surface is topmost.
221
299
  })
222
300
 
223
301
  useEffect(() => {
@@ -225,6 +303,14 @@ function CommandDispatcher({
225
303
  setSequenceState(null)
226
304
  }, [mode])
227
305
 
306
+ // Reset any in-flight sequence when keyboard ownership changes (e.g. a modal
307
+ // surface opens/closes) so partial chords don't leak across surfaces. Passive
308
+ // surfaces such as which-key must not clear the sequence they are displaying.
309
+ useEffect(() => {
310
+ trackerRef.current.reset()
311
+ setSequenceState(null)
312
+ }, [activeModalSurface?.id])
313
+
228
314
  const ctxValue = useMemo(
229
315
  () => ({
230
316
  registry: registryRef.current!,
@@ -237,7 +323,123 @@ function CommandDispatcher({
237
323
 
238
324
  return (
239
325
  <CommandContext.Provider value={ctxValue}>
240
- <CommandSequenceContext value={sequenceState}>{children}</CommandSequenceContext>
326
+ <CommandSurfaceStackContext.Provider value={surfaceStackValue}>
327
+ <CommandSequenceContext value={sequenceState}>{children}</CommandSequenceContext>
328
+ </CommandSurfaceStackContext.Provider>
329
+ </CommandContext.Provider>
330
+ )
331
+ }
332
+
333
+ export interface CommandSurfaceProviderProps {
334
+ children: ReactNode
335
+ /** Stable id for the surface (typically the overlay id). */
336
+ id: string
337
+ /** Interaction role (default "modal"). */
338
+ role?: CommandSurfaceRole
339
+ /** Initial local mode for this surface (default "cursor"). */
340
+ initialMode?: Mode
341
+ }
342
+
343
+ /**
344
+ * Mounts an overlay-owned command surface. Children registered via `useCommand`
345
+ * target this surface's local registry, and `useMode`/`useSetMode` read/write
346
+ * this surface's local mode instead of the root app's mode.
347
+ *
348
+ * While a `modal` surface is topmost it owns keyboard input and suspends the
349
+ * parent app's commands; a `passive` surface never becomes the keyboard owner.
350
+ */
351
+ export function CommandSurfaceProvider({
352
+ children,
353
+ id,
354
+ role = "modal",
355
+ initialMode = "cursor",
356
+ }: CommandSurfaceProviderProps) {
357
+ return (
358
+ <ModeProvider initialMode={initialMode}>
359
+ <CommandSurfaceInner id={id} role={role}>
360
+ {children}
361
+ </CommandSurfaceInner>
362
+ </ModeProvider>
363
+ )
364
+ }
365
+
366
+ function CommandSurfaceInner({
367
+ children,
368
+ id,
369
+ role,
370
+ }: {
371
+ children: ReactNode
372
+ id: string
373
+ role: CommandSurfaceRole
374
+ }) {
375
+ const parent = useContext(CommandContext)
376
+ const stack = useContext(CommandSurfaceStackContext)
377
+ if (!parent || !stack) {
378
+ throw new Error("CommandSurfaceProvider must be used within a CommandProvider")
379
+ }
380
+
381
+ const parentDepth = useContext(CommandSurfaceDepthContext)
382
+ const depth = parentDepth + 1
383
+
384
+ const mode = useMode()
385
+ const setMode = useSetMode()
386
+ const modeRef = useRef(mode)
387
+ modeRef.current = mode
388
+
389
+ const registryRef = useRef<CommandRegistry | null>(null)
390
+
391
+ const buildCtx = useCallback((): CommandContext => {
392
+ const ctx: Record<string, any> = {
393
+ mode: modeRef.current,
394
+ setMode,
395
+ commands: {
396
+ invoke: (cmdId: string) => registryRef.current?.invoke(cmdId),
397
+ list: () => Array.from(registryRef.current?.commands.values() ?? []),
398
+ },
399
+ exit: () => {},
400
+ }
401
+ for (const getter of parent.contextSources.values()) {
402
+ Object.assign(ctx, getter())
403
+ }
404
+ return ctx as CommandContext
405
+ }, [parent.contextSources, setMode])
406
+
407
+ const buildCtxRef = useRef(buildCtx)
408
+ buildCtxRef.current = buildCtx
409
+
410
+ if (registryRef.current === null) {
411
+ registryRef.current = createRegistry(() => buildCtxRef.current())
412
+ }
413
+
414
+ const { register } = stack
415
+ useEffect(() => {
416
+ const entry: CommandSurfaceEntry = {
417
+ id,
418
+ role,
419
+ depth,
420
+ order: 0,
421
+ registry: registryRef.current!,
422
+ getMode: () => modeRef.current,
423
+ buildCtx: () => buildCtxRef.current(),
424
+ }
425
+ return register(entry)
426
+ }, [register, id, role, depth])
427
+
428
+ const ctxValue = useMemo<CommandContextValue>(
429
+ () => ({
430
+ registry: registryRef.current!,
431
+ leaderKey: parent.leaderKey,
432
+ contextSources: parent.contextSources,
433
+ groups: parent.groups,
434
+ }),
435
+ [parent.leaderKey, parent.contextSources, parent.groups],
436
+ )
437
+
438
+ return (
439
+ <CommandContext.Provider value={ctxValue}>
440
+ <CommandSurfaceDepthContext.Provider value={depth}>
441
+ {children}
442
+ </CommandSurfaceDepthContext.Provider>
241
443
  </CommandContext.Provider>
242
444
  )
243
445
  }
@@ -269,6 +471,16 @@ export function useCommandSequenceState(): CommandSequenceState | null {
269
471
  return useContext(CommandSequenceContext)
270
472
  }
271
473
 
474
+ /**
475
+ * Metadata for the topmost modal command surface, or null when the root app is
476
+ * the active surface. Intended for which-key/help to read shortcuts from the
477
+ * active interaction surface.
478
+ */
479
+ export function useActiveCommandSurface(): ActiveCommandSurface | null {
480
+ const ctx = useContext(CommandSurfaceStackContext)
481
+ return ctx ? ctx.activeModalSurface : null
482
+ }
483
+
272
484
  export function useCommandGroup(group: CommandGroup): void {
273
485
  const ctx = useContext(CommandContext)
274
486
  if (!ctx) {
package/src/index.ts CHANGED
@@ -1,4 +1,5 @@
1
1
  export type {
2
+ ActiveCommandSurface,
2
3
  Command,
3
4
  CommandContext,
4
5
  CommandContextBase,
@@ -6,6 +7,8 @@ export type {
6
7
  CommandHandler,
7
8
  CommandSequenceCandidate,
8
9
  CommandSequenceState,
10
+ CommandSurfaceEntry,
11
+ CommandSurfaceRole,
9
12
  CommandWhen,
10
13
  ParsedHotkey,
11
14
  ParsedStep,
@@ -24,13 +27,15 @@ export type {
24
27
  } from "./sequence.js"
25
28
  export {
26
29
  CommandProvider,
30
+ CommandSurfaceProvider,
31
+ useActiveCommandSurface,
27
32
  useCommandContext,
28
33
  useCommandGroup,
29
34
  useCommandRegistry,
30
35
  useCommandSequenceState,
31
36
  useProvideCommandContext,
32
37
  } from "./context.js"
33
- export type { CommandProviderProps } from "./context.js"
38
+ export type { CommandProviderProps, CommandSurfaceProviderProps } from "./context.js"
34
39
  export { useCommand } from "./use-command.js"
35
40
  export type { UseCommandOptions } from "./use-command.js"
36
41
  export { useActions } from "./use-actions.js"
package/src/types.ts CHANGED
@@ -45,6 +45,40 @@ export interface CommandRegistry {
45
45
  invoke: (id: string) => void
46
46
  }
47
47
 
48
+ /**
49
+ * Interaction role of a command surface.
50
+ * - `modal`: owns keyboard input while topmost and suspends every lower surface
51
+ * (including the root app) — even for keys it does not handle.
52
+ * - `passive`: never becomes the keyboard owner; purely visual.
53
+ */
54
+ export type CommandSurfaceRole = "modal" | "passive"
55
+
56
+ /**
57
+ * A command surface is an interaction surface that can own keyboard input.
58
+ * The root app is the implicit base surface; modal overlays push surfaces on
59
+ * top of it. Each surface carries its own command registry and local mode so
60
+ * the same command definitions can be rooted in a standalone app or pushed by
61
+ * an overlay without leaking mode/command state into the parent.
62
+ */
63
+ export interface CommandSurfaceEntry {
64
+ id: string
65
+ role: CommandSurfaceRole
66
+ /** Nesting depth (root children are depth 0; the first overlay surface is 1). */
67
+ depth: number
68
+ /** Monotonic registration order, used to break depth ties. */
69
+ order: number
70
+ registry: CommandRegistry
71
+ /** Reads this surface's current local mode. */
72
+ getMode: () => Mode
73
+ /** Builds the command context handed to this surface's command handlers. */
74
+ buildCtx: () => CommandContext
75
+ }
76
+
77
+ export interface ActiveCommandSurface {
78
+ id: string
79
+ role: CommandSurfaceRole
80
+ }
81
+
48
82
  export interface CommandGroup {
49
83
  id: string
50
84
  title: string