@tooee/commands 0.7.3 → 0.8.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/README.md +26 -1
- package/dist/build-context.d.ts +3 -12
- package/dist/build-context.d.ts.map +1 -1
- package/dist/build-context.js +6 -17
- package/dist/build-context.js.map +1 -1
- package/dist/command-store-wrapper.d.ts +28 -0
- package/dist/command-store-wrapper.d.ts.map +1 -0
- package/dist/command-store-wrapper.js +115 -0
- package/dist/command-store-wrapper.js.map +1 -0
- package/dist/command-store.d.ts +2 -65
- package/dist/command-store.d.ts.map +1 -1
- package/dist/command-store.js +1 -345
- package/dist/command-store.js.map +1 -1
- package/dist/context.d.ts +9 -4
- package/dist/context.d.ts.map +1 -1
- package/dist/context.js +59 -50
- package/dist/context.js.map +1 -1
- package/dist/hooks/use-latest.d.ts +4 -0
- package/dist/hooks/use-latest.d.ts.map +1 -0
- package/dist/hooks/use-latest.js +8 -0
- package/dist/hooks/use-latest.js.map +1 -0
- package/dist/hooks/use-lazy-ref.d.ts +4 -0
- package/dist/hooks/use-lazy-ref.d.ts.map +1 -0
- package/dist/hooks/use-lazy-ref.js +8 -0
- package/dist/hooks/use-lazy-ref.js.map +1 -0
- package/dist/index.d.ts +7 -7
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +7 -4
- package/dist/index.js.map +1 -1
- package/dist/key-dispatch.d.ts +24 -0
- package/dist/key-dispatch.d.ts.map +1 -0
- package/dist/key-dispatch.js +159 -0
- package/dist/key-dispatch.js.map +1 -0
- package/dist/parse.js +10 -10
- package/dist/parse.js.map +1 -1
- package/dist/store.d.ts +9 -0
- package/dist/store.d.ts.map +1 -0
- package/dist/store.js +5 -0
- package/dist/store.js.map +1 -0
- package/dist/types.d.ts +6 -5
- package/dist/types.d.ts.map +1 -1
- package/dist/use-actions.d.ts.map +1 -1
- package/dist/use-actions.js +3 -1
- package/dist/use-actions.js.map +1 -1
- package/dist/use-command.d.ts.map +1 -1
- package/dist/use-command.js +3 -1
- package/dist/use-command.js.map +1 -1
- package/package.json +8 -1
- package/src/build-context.ts +7 -18
- package/src/command-store-wrapper.ts +149 -0
- package/src/command-store.ts +1 -491
- package/src/context.tsx +78 -65
- package/src/hooks/use-latest.ts +9 -0
- package/src/hooks/use-lazy-ref.ts +9 -0
- package/src/index.ts +8 -21
- package/src/key-dispatch.ts +272 -0
- package/src/parse.ts +10 -10
- package/src/store.ts +12 -0
- package/src/types.ts +6 -5
- package/src/use-actions.ts +3 -1
- package/src/use-command.ts +3 -1
package/src/parse.ts
CHANGED
|
@@ -1,18 +1,18 @@
|
|
|
1
1
|
import type { ParsedHotkey, ParsedStep } from "./types.js";
|
|
2
2
|
|
|
3
|
-
const KEY_ALIASES:
|
|
4
|
-
backspace
|
|
5
|
-
cr
|
|
6
|
-
del
|
|
7
|
-
enter
|
|
8
|
-
esc
|
|
9
|
-
plus
|
|
10
|
-
tab
|
|
11
|
-
|
|
3
|
+
const KEY_ALIASES: ReadonlyMap<string, string> = new Map([
|
|
4
|
+
["backspace", "backspace"],
|
|
5
|
+
["cr", "return"],
|
|
6
|
+
["del", "delete"],
|
|
7
|
+
["enter", "return"],
|
|
8
|
+
["esc", "escape"],
|
|
9
|
+
["plus", "+"],
|
|
10
|
+
["tab", "tab"],
|
|
11
|
+
]);
|
|
12
12
|
|
|
13
13
|
const normalizeKey = function normalizeKey(key: string): string {
|
|
14
14
|
const lower = key.toLowerCase();
|
|
15
|
-
return KEY_ALIASES
|
|
15
|
+
return KEY_ALIASES.get(lower) ?? lower;
|
|
16
16
|
};
|
|
17
17
|
|
|
18
18
|
const warned = new Set<string>();
|
package/src/store.ts
ADDED
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
export { ModeProvider } from "./mode.js";
|
|
2
|
+
export type { ModeProviderProps } from "./mode.js";
|
|
3
|
+
export { DEFAULT_SEQUENCE_TIMEOUT_MS, SequenceTracker } from "./sequence.js";
|
|
4
|
+
export type {
|
|
5
|
+
SequenceFeedResult,
|
|
6
|
+
SequencePendingMatch,
|
|
7
|
+
SequenceTrackerOptions,
|
|
8
|
+
} from "./sequence.js";
|
|
9
|
+
export { createBaseStore, selectGroups, selectSurfaceCommandMap } from "./command-store.js";
|
|
10
|
+
export type { CommandStoreInstance, ContextGetter } from "./command-store.js";
|
|
11
|
+
export { createCommandStore } from "./command-store-wrapper.js";
|
|
12
|
+
export type { CreateCommandStoreOptions, KeyDispatchResult } from "./command-store-wrapper.js";
|
package/src/types.ts
CHANGED
|
@@ -14,14 +14,15 @@ export interface CommandCommands {
|
|
|
14
14
|
* ```ts
|
|
15
15
|
* declare module "@tooee/commands" {
|
|
16
16
|
* interface CommandContext {
|
|
17
|
-
* myDomain
|
|
17
|
+
* myDomain?: MyDomainContext
|
|
18
18
|
* }
|
|
19
19
|
* }
|
|
20
20
|
* ```
|
|
21
21
|
*
|
|
22
|
-
* Augmented fields
|
|
23
|
-
*
|
|
24
|
-
*
|
|
22
|
+
* Augmented fields must be optional because their providers are not present on
|
|
23
|
+
* every command surface. They are contributed at runtime by context sources
|
|
24
|
+
* (`useCommandContextSource`), so handlers must check a field before reading
|
|
25
|
+
* it. The core fields are declared here directly: the
|
|
25
26
|
* interface is still open for merging, but it is no longer an empty declaration
|
|
26
27
|
* that only inherits its own members.
|
|
27
28
|
*/
|
|
@@ -66,7 +67,7 @@ export interface ParsedStep {
|
|
|
66
67
|
}
|
|
67
68
|
|
|
68
69
|
export interface CommandRegistry {
|
|
69
|
-
commands:
|
|
70
|
+
commands: ReadonlyMap<string, Command>;
|
|
70
71
|
register: (command: Command) => () => void;
|
|
71
72
|
invoke: (id: string) => void;
|
|
72
73
|
}
|
package/src/use-actions.ts
CHANGED
|
@@ -37,7 +37,9 @@ export const useActions = function useActions(actions: ActionDefinition[] | unde
|
|
|
37
37
|
useEffect(() => {
|
|
38
38
|
const { current } = actionsRef;
|
|
39
39
|
if (!current || current.length === 0) {
|
|
40
|
-
return () =>
|
|
40
|
+
return () => {
|
|
41
|
+
// Nothing was registered, so there is nothing to unregister.
|
|
42
|
+
};
|
|
41
43
|
}
|
|
42
44
|
|
|
43
45
|
const unregisters = current.map((action, i) => {
|
package/src/use-command.ts
CHANGED
|
@@ -36,7 +36,9 @@ export const useCommand = function useCommand(options: UseCommandOptions): void
|
|
|
36
36
|
|
|
37
37
|
useEffect(() => {
|
|
38
38
|
if (options.enabled === false) {
|
|
39
|
-
return () =>
|
|
39
|
+
return () => {
|
|
40
|
+
// A disabled command registers nothing, so there is nothing to unregister.
|
|
41
|
+
};
|
|
40
42
|
}
|
|
41
43
|
|
|
42
44
|
const command: Command = {
|