@tooee/commands 0.10.1 → 0.10.3
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/README.md +23 -77
- package/dist/build-context.d.ts +1 -1
- package/dist/build-context.d.ts.map +1 -1
- package/dist/command-store-wrapper.d.ts +1 -1
- package/dist/command-store-wrapper.d.ts.map +1 -1
- package/dist/command-store-wrapper.js.map +1 -1
- package/dist/command-store.d.ts +1 -1
- package/dist/command-store.d.ts.map +1 -1
- package/dist/command-store.js.map +1 -1
- package/dist/context.d.ts +3 -11
- package/dist/context.d.ts.map +1 -1
- package/dist/context.js +21 -21
- package/dist/context.js.map +1 -1
- package/dist/key-dispatch.d.ts.map +1 -1
- package/dist/key-dispatch.js +1 -1
- package/dist/key-dispatch.js.map +1 -1
- package/dist/match.d.ts.map +1 -1
- package/dist/match.js.map +1 -1
- package/dist/sequence.d.ts.map +1 -1
- package/dist/sequence.js.map +1 -1
- package/dist/use-actions.d.ts +1 -1
- package/dist/use-actions.d.ts.map +1 -1
- package/dist/use-actions.js.map +1 -1
- package/dist/use-command.d.ts +1 -1
- package/dist/use-command.d.ts.map +1 -1
- package/dist/use-command.js.map +1 -1
- package/package.json +9 -9
- package/src/build-context.ts +4 -4
- package/src/command-store-wrapper.ts +3 -2
- package/src/command-store.ts +25 -21
- package/src/context.tsx +49 -48
- package/src/key-dispatch.ts +12 -11
- package/src/match.ts +1 -0
- package/src/mode.tsx +1 -1
- package/src/parse.ts +1 -1
- package/src/screen-focus.tsx +1 -1
- package/src/sequence.ts +6 -5
- package/src/use-actions.ts +4 -3
- package/src/use-command.ts +3 -2
package/src/key-dispatch.ts
CHANGED
|
@@ -1,7 +1,5 @@
|
|
|
1
1
|
import type { KeyEvent } from "@opentui/core";
|
|
2
|
-
|
|
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
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
|
}
|
package/src/screen-focus.tsx
CHANGED
|
@@ -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
|
-
|
|
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) {
|
package/src/use-actions.ts
CHANGED
|
@@ -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(() => {
|
package/src/use-command.ts
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
import { useEffect, useRef } from "react";
|
|
2
|
-
|
|
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;
|