@tooee/commands 0.7.3 → 0.9.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 +5 -4
- package/dist/context.d.ts.map +1 -1
- package/dist/context.js +55 -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 +5 -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/public-contract.typecheck.d.ts +2 -0
- package/dist/public-contract.typecheck.d.ts.map +1 -0
- package/dist/public-contract.typecheck.js +7 -0
- package/dist/public-contract.typecheck.js.map +1 -0
- 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 +73 -65
- package/src/hooks/use-latest.ts +9 -0
- package/src/hooks/use-lazy-ref.ts +9 -0
- package/src/index.ts +7 -22
- package/src/key-dispatch.ts +272 -0
- package/src/parse.ts +10 -10
- package/src/public-contract.typecheck.ts +7 -0
- 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
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
// @ts-expect-error useCommandContext is not exported; use useSurfaceInvoke.
|
|
2
|
+
import { useCommandContext, useSurfaceInvoke } from "./index.js";
|
|
3
|
+
|
|
4
|
+
export const commandPublicContractTypeChecks = function commandPublicContractTypeChecks(): void {
|
|
5
|
+
void useSurfaceInvoke;
|
|
6
|
+
void useCommandContext;
|
|
7
|
+
};
|
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 = {
|