chizu 0.4.0 → 0.5.2

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 (44) hide show
  1. package/README.md +63 -65
  2. package/dist/chizu.js +6 -6
  3. package/dist/chizu.umd.cjs +1 -1
  4. package/dist/{action → src/library/action}/utils.d.ts +3 -3
  5. package/dist/src/library/boundary/components/mode/index.d.ts +15 -0
  6. package/dist/src/library/boundary/components/mode/types.d.ts +7 -0
  7. package/dist/src/library/boundary/components/mode/utils.d.ts +55 -0
  8. package/dist/src/library/boundary/components/scope/index.d.ts +40 -0
  9. package/dist/src/library/boundary/components/scope/types.d.ts +20 -0
  10. package/dist/{boundary → src/library/boundary}/components/scope/utils.d.ts +3 -6
  11. package/dist/{boundary → src/library/boundary}/index.d.ts +1 -1
  12. package/dist/src/library/error/index.d.ts +2 -0
  13. package/dist/{error → src/library/error}/types.d.ts +1 -18
  14. package/dist/{hooks → src/library/hooks}/index.d.ts +2 -2
  15. package/dist/{hooks → src/library/hooks}/types.d.ts +1 -17
  16. package/dist/{hooks → src/library/hooks}/utils.d.ts +32 -30
  17. package/dist/{index.d.ts → src/library/index.d.ts} +5 -5
  18. package/dist/{types → src/library/types}/index.d.ts +55 -306
  19. package/package.json +5 -2
  20. package/dist/boundary/components/regulators/index.d.ts +0 -14
  21. package/dist/boundary/components/regulators/types.d.ts +0 -52
  22. package/dist/boundary/components/regulators/utils.d.ts +0 -21
  23. package/dist/boundary/components/scope/index.d.ts +0 -82
  24. package/dist/boundary/components/scope/types.d.ts +0 -28
  25. package/dist/error/index.d.ts +0 -2
  26. /package/dist/{action → src/library/action}/index.d.ts +0 -0
  27. /package/dist/{annotate → src/library/annotate}/index.d.ts +0 -0
  28. /package/dist/{boundary → src/library/boundary}/components/broadcast/index.d.ts +0 -0
  29. /package/dist/{boundary → src/library/boundary}/components/broadcast/types.d.ts +0 -0
  30. /package/dist/{boundary → src/library/boundary}/components/broadcast/utils.d.ts +0 -0
  31. /package/dist/{boundary → src/library/boundary}/components/consumer/components/partition/index.d.ts +0 -0
  32. /package/dist/{boundary → src/library/boundary}/components/consumer/components/partition/types.d.ts +0 -0
  33. /package/dist/{boundary → src/library/boundary}/components/consumer/index.d.ts +0 -0
  34. /package/dist/{boundary → src/library/boundary}/components/consumer/types.d.ts +0 -0
  35. /package/dist/{boundary → src/library/boundary}/components/consumer/utils.d.ts +0 -0
  36. /package/dist/{boundary → src/library/boundary}/components/tasks/index.d.ts +0 -0
  37. /package/dist/{boundary → src/library/boundary}/components/tasks/types.d.ts +0 -0
  38. /package/dist/{boundary → src/library/boundary}/components/tasks/utils.d.ts +0 -0
  39. /package/dist/{boundary → src/library/boundary}/types.d.ts +0 -0
  40. /package/dist/{error → src/library/error}/utils.d.ts +0 -0
  41. /package/dist/{resource → src/library/resource}/index.d.ts +0 -0
  42. /package/dist/{utils → src/library/utils}/index.d.ts +0 -0
  43. /package/dist/{utils → src/library/utils}/utils.d.ts +0 -0
  44. /package/dist/{utils.d.ts → src/library/utils.d.ts} +0 -0
@@ -7,12 +7,8 @@ export declare enum Reason {
7
7
  Timedout = 0,
8
8
  /** Action was cancelled by a newer dispatch. */
9
9
  Supplanted = 1,
10
- /** Action was blocked by the regulator's `allow` function returning `false`. */
11
- Disallowed = 2,
12
10
  /** A generic error thrown in the user's action handler. */
13
- Errored = 3,
14
- /** Action was aborted because the component unmounted. */
15
- Unmounted = 4
11
+ Errored = 2
16
12
  }
17
13
  /**
18
14
  * Error thrown when an action is aborted, e.g., when a component unmounts
@@ -41,19 +37,6 @@ export declare class TimeoutError extends Error {
41
37
  name: string;
42
38
  constructor(message?: string);
43
39
  }
44
- /**
45
- * Error thrown when an action is blocked by the regulator policy.
46
- * Works across all platforms including React Native where `DOMException` is unavailable.
47
- *
48
- * @example
49
- * ```ts
50
- * throw new DisallowedError("Action blocked by regulator");
51
- * ```
52
- */
53
- export declare class DisallowedError extends Error {
54
- name: string;
55
- constructor(message?: string);
56
- }
57
40
  /**
58
41
  * Details about an error that occurred during action execution.
59
42
  *
@@ -1,5 +1,5 @@
1
1
  import { Data } from './types.ts';
2
- import { Model, Props, Actions, UseActions, ValidateFeatures, NullableNodes } from '../types/index.ts';
2
+ import { Model, Props, Actions, UseActions } from '../types/index.ts';
3
3
  export { With } from './utils.ts';
4
4
  /**
5
5
  * A hook for managing state with actions.
@@ -40,4 +40,4 @@ export { With } from './utils.ts';
40
40
  * ```
41
41
  */
42
42
  export declare function useActions<_M extends void = void, A extends Actions | void = void, D extends Props = Props>(getData?: Data<D>): UseActions<void, A, D>;
43
- export declare function useActions<M extends Model, A extends Actions | void = void, D extends Props = Props>(initialModel: NullableNodes<M> & ValidateFeatures<M>, getData?: Data<D>): UseActions<M, A, D>;
43
+ export declare function useActions<M extends Model, A extends Actions | void = void, D extends Props = Props>(initialModel: M, getData?: Data<D>): UseActions<M, A, D>;
@@ -1,24 +1,8 @@
1
1
  import { default as EventEmitter } from 'eventemitter3';
2
2
  import { RefObject } from 'react';
3
- import { Model, HandlerContext, Actions, Props, Tasks, ActionId, Phase, Filter, ExtractNodes } from '../types/index.ts';
3
+ import { Model, HandlerContext, Actions, Props, Tasks, ActionId, Phase, Filter } from '../types/index.ts';
4
4
  import { BroadcastEmitter } from '../boundary/components/broadcast/utils.ts';
5
5
  import { ScopeContext } from '../boundary/components/scope/types.ts';
6
- /**
7
- * Return type for the useNodes hook.
8
- * Contains refs for captured nodes, pending captures, and last emitted nodes.
9
- *
10
- * @template M - The model type containing a `nodes` property
11
- */
12
- export type References<M extends Model | void> = {
13
- /** Ref containing captured DOM nodes by name */
14
- refs: RefObject<{
15
- [K in keyof ExtractNodes<M>]: ExtractNodes<M>[K] | null;
16
- }>;
17
- /** Ref containing pending node captures to be processed after render */
18
- pending: RefObject<Map<keyof ExtractNodes<M>, ExtractNodes<M>[keyof ExtractNodes<M>] | null>>;
19
- /** Ref containing last emitted node values to detect true changes */
20
- emitted: RefObject<Map<keyof ExtractNodes<M>, ExtractNodes<M>[keyof ExtractNodes<M>] | null>>;
21
- };
22
6
  /**
23
7
  * Function signature for action handlers registered via `useAction`.
24
8
  * Receives the reactive context and payload, returning void or a promise/generator.
@@ -1,7 +1,7 @@
1
1
  import { RefObject } from 'react';
2
2
  import { Props, Model, Actions, Filter, ActionId, HandlerPayload, ChanneledAction, HandlerContext } from '../types/index.ts';
3
3
  import { default as EventEmitter } from 'eventemitter3';
4
- import { Dispatchers, LifecycleConfig, References, Scope } from './types.ts';
4
+ import { Dispatchers, LifecycleConfig, Scope } from './types.ts';
5
5
  import { isChanneledAction, getActionSymbol } from '../action/index.ts';
6
6
  import * as React from "react";
7
7
  /**
@@ -38,12 +38,14 @@ export declare function emitAsync(emitter: EventEmitter, event: string | symbol,
38
38
  * Also invokes broadcast action handlers with cached values on mount.
39
39
  * Updates the phase ref to track the component's current lifecycle state.
40
40
  *
41
- * Uses a ref guard to prevent React Strict Mode from causing duplicate
42
- * Mount emissions during its development-only double-invocation cycle.
41
+ * The Mount effect skips when `phase` is already `Mounted` this catches
42
+ * Strict Mode's dev-only double-invocation. It accepts both `Mounting` (first
43
+ * mount) and `Unmounted` (re-mount after `<Activity>` show) as entry states
44
+ * so that hidden-then-shown subtrees correctly re-emit Mount.
43
45
  *
44
- * Note: The phase transitions are:
45
- * - Mounting → (cached broadcast action values emitted here) → Mounted
46
- * - Mounted → Unmounting → Unmounted
46
+ * Phase transitions:
47
+ * - First mount: Mounting → Mounted
48
+ * - Activity hide / show: Mounted → Unmounting → Unmounted → Mounting → Mounted
47
49
  */
48
50
  export declare function useLifecycles({ unicast, broadcast, dispatchers, scope, phase, data, handlers, }: LifecycleConfig): void;
49
51
  /**
@@ -60,36 +62,44 @@ export declare function useLifecycles({ unicast, broadcast, dispatchers, scope,
60
62
  */
61
63
  export declare function useData<P extends Props>(props: P): P;
62
64
  /**
63
- * Creates a handler that binds an action's payload directly to a model property.
65
+ * Handler factories that wire an action directly to a model field.
64
66
  *
65
- * The returned handler updates `model[key]` with the payload when the action is dispatched.
66
- * Type safety is enforced at the call site: the payload type must be assignable to
67
- * the model property's type.
67
+ * - {@link With.Update} assigns the dispatched payload to `model[key]`.
68
+ * - {@link With.Invert} flips a boolean field on `model[key]`.
68
69
  *
69
- * @template K The property key type (inferred from the argument)
70
- * @param key The model property key to bind the payload to
71
- * @returns A handler function compatible with `useAction`
70
+ * Both are typed so the call site fails to compile when `key` is missing or
71
+ * has an incompatible type.
72
72
  *
73
73
  * @example
74
74
  * ```ts
75
75
  * import { With } from "chizu";
76
76
  *
77
- * type Model = { name: string; count: number };
77
+ * type Model = { name: string; sidebar: boolean };
78
78
  *
79
79
  * class Actions {
80
80
  * static SetName = Action<string>("SetName");
81
- * static SetCount = Action<number>("SetCount");
81
+ * static ToggleSidebar = Action("ToggleSidebar");
82
82
  * }
83
83
  *
84
- * // These work - payload types match model property types
85
- * actions.useAction(Actions.SetName, With("name")); // string -> string ✓
86
- * actions.useAction(Actions.SetCount, With("count")); // number -> number ✓
87
- *
88
- * // This would error - Country is not assignable to string
89
- * actions.useAction(Actions.Visitor, With("name")); // Country -> string ✗
84
+ * actions.useAction(Actions.SetName, With.Update("name"));
85
+ * actions.useAction(Actions.ToggleSidebar, With.Invert("sidebar"));
90
86
  * ```
91
87
  */
92
- export declare function With<K extends string>(key: K): <M extends Model, A extends Actions | void, D extends Props, P extends K extends keyof M ? M[K] : never>(context: HandlerContext<M, A, D>, payload: P) => void;
88
+ export declare const With: {
89
+ /**
90
+ * Returns a handler that assigns the action payload to `model[key]`.
91
+ *
92
+ * Type-checks at the call site: the payload type must be assignable to
93
+ * the model property's type, and the key must exist on the model.
94
+ */
95
+ Update<K extends string>(key: K): <M extends Model, A extends Actions | void, D extends Props, P extends K extends keyof M ? M[K] : never>(context: HandlerContext<M, A, D>, payload: P) => void;
96
+ /**
97
+ * Returns a handler that inverts a boolean field on the model.
98
+ *
99
+ * Type-checks at the call site: `model[key]` must be a boolean.
100
+ */
101
+ Invert<K extends string>(key: K): <M extends Model & Record<K, boolean>, A extends Actions | void, D extends Props>(context: HandlerContext<M, A, D>) => void;
102
+ };
93
103
  /**
94
104
  * Scans a handler registry for a lifecycle action of the given type.
95
105
  *
@@ -169,14 +179,6 @@ export declare function useDispatchers(): Dispatchers;
169
179
  * @internal
170
180
  */
171
181
  export declare function useRegisterHandler<M extends Model | void, A extends Actions | void, D extends Props>(scope: React.RefObject<Scope<M, A, D>>, action: ActionId | HandlerPayload | ChanneledAction, handler: (context: HandlerContext<M, A, D>, payload: unknown) => void | Promise<void> | AsyncGenerator | Generator): void;
172
- /**
173
- * Manages captured DOM nodes for a model type.
174
- * Returns refs for nodes, pending captures, and last emitted nodes.
175
- *
176
- * @template M The model type containing a `nodes` property
177
- * @returns Object containing refs for nodes, pending captures, and emitted nodes
178
- */
179
- export declare function useNodes<M extends Model | void>(): References<M>;
180
182
  /**
181
183
  * Checks if a dispatch channel matches a registered handler channel.
182
184
  * All properties in the dispatch channel must match the corresponding properties in the registered channel.
@@ -1,16 +1,16 @@
1
1
  export { Action } from './action/index.ts';
2
2
  export { Distribution, Lifecycle } from './types/index.ts';
3
- export { Reason, AbortError, TimeoutError, DisallowedError, } from './error/index.ts';
3
+ export { Reason, AbortError, TimeoutError } from './error/index.ts';
4
4
  export { Operation, Op, State } from 'immertation';
5
5
  export { annotate } from './annotate/index.ts';
6
6
  export { Boundary } from './boundary/index.tsx';
7
- export { Regulators } from './boundary/components/regulators/index.tsx';
8
- export { Scope, withScope } from './boundary/components/scope/index.tsx';
7
+ export { withScope } from './boundary/components/scope/index.tsx';
8
+ export { useMode } from './boundary/components/mode/index.tsx';
9
+ export type { ModeHandle } from './boundary/components/mode/index.tsx';
9
10
  export { useActions, With } from './hooks/index.ts';
10
11
  export { Resource } from './resource/index.ts';
11
12
  export type { ResourceHandle, ResourceDispatch, ResourceSuccess, ResourceFailure, } from './resource/index.ts';
12
13
  export * as utils from './utils/index.ts';
13
14
  export type { Box } from 'immertation';
14
15
  export type { Fault } from './error/index.ts';
15
- export type { Pk, Task, Tasks, Handlers, Meta } from './types/index.ts';
16
- export type { Regulator } from './boundary/components/regulators/index.tsx';
16
+ export type { Pk, Task, Tasks, Handlers } from './types/index.ts';