@tooee/commands 0.7.2 → 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.
Files changed (61) hide show
  1. package/README.md +26 -1
  2. package/dist/build-context.d.ts +3 -12
  3. package/dist/build-context.d.ts.map +1 -1
  4. package/dist/build-context.js +6 -17
  5. package/dist/build-context.js.map +1 -1
  6. package/dist/command-store-wrapper.d.ts +28 -0
  7. package/dist/command-store-wrapper.d.ts.map +1 -0
  8. package/dist/command-store-wrapper.js +115 -0
  9. package/dist/command-store-wrapper.js.map +1 -0
  10. package/dist/command-store.d.ts +2 -65
  11. package/dist/command-store.d.ts.map +1 -1
  12. package/dist/command-store.js +1 -345
  13. package/dist/command-store.js.map +1 -1
  14. package/dist/context.d.ts +9 -4
  15. package/dist/context.d.ts.map +1 -1
  16. package/dist/context.js +59 -50
  17. package/dist/context.js.map +1 -1
  18. package/dist/hooks/use-latest.d.ts +4 -0
  19. package/dist/hooks/use-latest.d.ts.map +1 -0
  20. package/dist/hooks/use-latest.js +8 -0
  21. package/dist/hooks/use-latest.js.map +1 -0
  22. package/dist/hooks/use-lazy-ref.d.ts +4 -0
  23. package/dist/hooks/use-lazy-ref.d.ts.map +1 -0
  24. package/dist/hooks/use-lazy-ref.js +8 -0
  25. package/dist/hooks/use-lazy-ref.js.map +1 -0
  26. package/dist/index.d.ts +7 -7
  27. package/dist/index.d.ts.map +1 -1
  28. package/dist/index.js +7 -4
  29. package/dist/index.js.map +1 -1
  30. package/dist/key-dispatch.d.ts +24 -0
  31. package/dist/key-dispatch.d.ts.map +1 -0
  32. package/dist/key-dispatch.js +159 -0
  33. package/dist/key-dispatch.js.map +1 -0
  34. package/dist/parse.js +10 -10
  35. package/dist/parse.js.map +1 -1
  36. package/dist/store.d.ts +9 -0
  37. package/dist/store.d.ts.map +1 -0
  38. package/dist/store.js +5 -0
  39. package/dist/store.js.map +1 -0
  40. package/dist/types.d.ts +6 -5
  41. package/dist/types.d.ts.map +1 -1
  42. package/dist/use-actions.d.ts.map +1 -1
  43. package/dist/use-actions.js +3 -1
  44. package/dist/use-actions.js.map +1 -1
  45. package/dist/use-command.d.ts.map +1 -1
  46. package/dist/use-command.js +3 -1
  47. package/dist/use-command.js.map +1 -1
  48. package/package.json +8 -1
  49. package/src/build-context.ts +7 -18
  50. package/src/command-store-wrapper.ts +149 -0
  51. package/src/command-store.ts +1 -491
  52. package/src/context.tsx +78 -65
  53. package/src/hooks/use-latest.ts +9 -0
  54. package/src/hooks/use-lazy-ref.ts +9 -0
  55. package/src/index.ts +8 -21
  56. package/src/key-dispatch.ts +272 -0
  57. package/src/parse.ts +10 -10
  58. package/src/store.ts +12 -0
  59. package/src/types.ts +6 -5
  60. package/src/use-actions.ts +3 -1
  61. 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: Record<string, string> = {
4
- backspace: "backspace",
5
- cr: "return",
6
- del: "delete",
7
- enter: "return",
8
- esc: "escape",
9
- plus: "+",
10
- tab: "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[lower] ?? lower;
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: MyDomainContext
17
+ * myDomain?: MyDomainContext
18
18
  * }
19
19
  * }
20
20
  * ```
21
21
  *
22
- * Augmented fields are contributed at runtime by context sources
23
- * (`useCommandContextSource`), so an augmenting package is responsible for
24
- * mounting its provider. The core fields are declared here directly: the
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: Map<string, Command>;
70
+ commands: ReadonlyMap<string, Command>;
70
71
  register: (command: Command) => () => void;
71
72
  invoke: (id: string) => void;
72
73
  }
@@ -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 () => void 0;
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) => {
@@ -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 () => void 0;
39
+ return () => {
40
+ // A disabled command registers nothing, so there is nothing to unregister.
41
+ };
40
42
  }
41
43
 
42
44
  const command: Command = {