vultus-core 0.1.0 → 0.2.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 (72) hide show
  1. package/README.md +72 -0
  2. package/dist/LinkContext.d.ts +13 -0
  3. package/dist/LinkContext.d.ts.map +1 -0
  4. package/dist/LinkContext.js +8 -0
  5. package/dist/LinkContext.js.map +1 -0
  6. package/dist/MessageSink.d.ts +13 -0
  7. package/dist/MessageSink.d.ts.map +1 -0
  8. package/dist/MessageSink.js +6 -0
  9. package/dist/MessageSink.js.map +1 -0
  10. package/dist/action-core.d.ts +36 -0
  11. package/dist/action-core.d.ts.map +1 -0
  12. package/dist/action-core.js +91 -0
  13. package/dist/action-core.js.map +1 -0
  14. package/dist/decision.d.ts +10 -0
  15. package/dist/decision.d.ts.map +1 -0
  16. package/dist/decision.js +17 -0
  17. package/dist/decision.js.map +1 -0
  18. package/dist/field.d.ts +97 -0
  19. package/dist/field.d.ts.map +1 -0
  20. package/dist/field.js +95 -0
  21. package/dist/field.js.map +1 -0
  22. package/dist/index.d.ts +14 -0
  23. package/dist/index.d.ts.map +1 -0
  24. package/dist/index.js +14 -0
  25. package/dist/index.js.map +1 -0
  26. package/dist/parseApiError.d.ts +3 -0
  27. package/dist/parseApiError.d.ts.map +1 -0
  28. package/dist/parseApiError.js +11 -0
  29. package/dist/parseApiError.js.map +1 -0
  30. package/dist/resolve.d.ts +3 -0
  31. package/dist/resolve.d.ts.map +1 -0
  32. package/dist/resolve.js +6 -0
  33. package/dist/resolve.js.map +1 -0
  34. package/dist/routeApiError.d.ts +3 -0
  35. package/dist/routeApiError.d.ts.map +1 -0
  36. package/dist/routeApiError.js +19 -0
  37. package/dist/routeApiError.js.map +1 -0
  38. package/dist/types.d.ts +104 -0
  39. package/dist/types.d.ts.map +1 -0
  40. package/dist/types.js +2 -0
  41. package/dist/types.js.map +1 -0
  42. package/dist/useAction.d.ts +3 -0
  43. package/dist/useAction.d.ts.map +1 -0
  44. package/dist/useAction.js +47 -0
  45. package/dist/useAction.js.map +1 -0
  46. package/dist/useActionErrorCtx.d.ts +4 -0
  47. package/dist/useActionErrorCtx.d.ts.map +1 -0
  48. package/dist/useActionErrorCtx.js +6 -0
  49. package/dist/useActionErrorCtx.js.map +1 -0
  50. package/dist/useActionList.d.ts +13 -0
  51. package/dist/useActionList.d.ts.map +1 -0
  52. package/dist/useActionList.js +42 -0
  53. package/dist/useActionList.js.map +1 -0
  54. package/dist/useBoolField.d.ts +17 -0
  55. package/dist/useBoolField.d.ts.map +1 -0
  56. package/dist/useBoolField.js +12 -0
  57. package/dist/useBoolField.js.map +1 -0
  58. package/dist/useMixedBoolField.d.ts +24 -0
  59. package/dist/useMixedBoolField.d.ts.map +1 -0
  60. package/dist/useMixedBoolField.js +25 -0
  61. package/dist/useMixedBoolField.js.map +1 -0
  62. package/package.json +20 -5
  63. package/src/MessageSink.tsx +8 -5
  64. package/src/action-core.ts +27 -7
  65. package/src/decision.ts +4 -0
  66. package/src/field.ts +197 -0
  67. package/src/index.ts +8 -0
  68. package/src/types.ts +28 -1
  69. package/src/useAction.ts +5 -5
  70. package/src/useActionList.ts +7 -7
  71. package/src/useBoolField.ts +30 -0
  72. package/src/useMixedBoolField.ts +43 -0
package/README.md ADDED
@@ -0,0 +1,72 @@
1
+ # vultus-core
2
+
3
+ Framework-neutral action model, hooks, and error-routing for the vultus UI
4
+ family. It is antd-free by design: no Ant Design import appears anywhere in
5
+ this package. Consumed by `vultus-antd` and, transitively, by excavator and
6
+ optio-conversation-ui.
7
+
8
+ ## Install
9
+
10
+ ```sh
11
+ npm install vultus-core
12
+ ```
13
+
14
+ ## Peer dependencies
15
+
16
+ - `react` >=18
17
+ - `react-i18next` >=15
18
+
19
+ ## Entry points
20
+
21
+ - `.` — the action model, exporting: the core `types`, `decision`, `resolve`,
22
+ `parseApiError`, `routeApiError`, `ActionErrorContext` / `useActionErrorCtx`,
23
+ `useAction`, `useActionList`, the fields (`useBoolField`, `useFieldCore` and
24
+ their types), `InternalLinkContext` / `useInternalLink` /
25
+ `InternalLinkComponent`, and `MessageSinkContext` / `useMessageSink` /
26
+ `MessageSink`.
27
+ - `./link` — `InternalLinkContext`, `useInternalLink`, and the
28
+ `InternalLinkComponent` type on their own, for consumers that only need the
29
+ link-injection seam.
30
+
31
+ ## Actions report messages
32
+
33
+ An action's `fire(args, ctx)` receives an `ExecutionContext` next to its arguments:
34
+ `ctx.info(text)`, `ctx.warn(text)` and `ctx.error(text)` report messages while it runs.
35
+ They land on the action's status as `messages` (with their `severity`) and go to the
36
+ `MessageSink` (`(text, severity?)`). A thrown error still fails the action and ends the
37
+ run's messages; `errors` lists the error texts among them.
38
+
39
+ ## Fields
40
+
41
+ `useBoolField(options)` is the first field hook: the value half of vultus, next to
42
+ actions. Fields are built by composition on a shared core (`useFieldCore`): label,
43
+ description, `visible`/`hidden`, `enabled`/`disabled` (a `Decision`, so with a reason),
44
+ and where the value lives:
45
+
46
+ - inside the field: `initialValue` (default `false`), changed locally;
47
+ - outside, changed locally: `value` + `onChange` (the caller owns the value, e.g. a form);
48
+ - outside, committed immediately: `value` + `commit: { fire(next, ctx), confirmation?, errorRoute? }`.
49
+ The commit runs as an action, so the field is `pending` while it runs and carries its
50
+ `messages`; afterwards it shows whatever `value` the caller passes. `confirmation` may
51
+ depend on the requested value.
52
+
53
+ The returned controls (`value`, `setValue`, `toggle`, `pending`, `enabled`, `whyDisabled`,
54
+ `description`, `valueDescription`, `messages`, `confirmationFor(next)`, ...) are what widgets
55
+ render: vultus-antd's `BoolSwitch` and `BoolCheckbox` take the same field.
56
+ `valueDescriptions` (texts keyed by value: `true`, `false`, `mixed`) say what the current value
57
+ means, next to `description` (what the field is).
58
+
59
+ `useMixedBoolField` is the same field over an aggregate: it shows `true`, `false` or `'mixed'`
60
+ and can be asked for `true` or `false` only (the field core separates the shown type from the
61
+ requestable one); a toggle from mixed requests `true`. `aggregateBool(values)` derives the
62
+ value; with no items at all, disable the field with a reason instead.
63
+
64
+ ## Distribution
65
+
66
+ This package ships compiled ESM (`dist/`) with TypeScript declarations to
67
+ npm; the repository's own `exports` field resolves `src/` directly for
68
+ workspace consumers.
69
+
70
+ ## License
71
+
72
+ Apache-2.0
@@ -0,0 +1,13 @@
1
+ import { type ComponentType, type ReactNode } from 'react';
2
+ /**
3
+ * How an internal (`/`-prefixed) markdown link renders. Hosts with a router
4
+ * inject an SPA link; the default is a full-navigation anchor so router-less
5
+ * consumers (optio-conversation-ui) work with zero setup.
6
+ */
7
+ export type InternalLinkComponent = ComponentType<{
8
+ href: string;
9
+ children?: ReactNode;
10
+ }>;
11
+ export declare const InternalLinkContext: import("react").Context<InternalLinkComponent>;
12
+ export declare function useInternalLink(): InternalLinkComponent;
13
+ //# sourceMappingURL=LinkContext.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"LinkContext.d.ts","sourceRoot":"","sources":["../src/LinkContext.tsx"],"names":[],"mappings":"AAAA,OAAO,EAA6B,KAAK,aAAa,EAAE,KAAK,SAAS,EAAE,MAAM,OAAO,CAAC;AAEtF;;;;GAIG;AACH,MAAM,MAAM,qBAAqB,GAAG,aAAa,CAAC;IAAE,IAAI,EAAE,MAAM,CAAC;IAAC,QAAQ,CAAC,EAAE,SAAS,CAAA;CAAE,CAAC,CAAC;AAM1F,eAAO,MAAM,mBAAmB,gDAA4D,CAAC;AAE7F,wBAAgB,eAAe,IAAI,qBAAqB,CAEvD"}
@@ -0,0 +1,8 @@
1
+ import { jsx as _jsx } from "react/jsx-runtime";
2
+ import { createContext, useContext } from 'react';
3
+ const DefaultInternalLink = ({ href, children }) => (_jsx("a", { href: href, children: children }));
4
+ export const InternalLinkContext = createContext(DefaultInternalLink);
5
+ export function useInternalLink() {
6
+ return useContext(InternalLinkContext);
7
+ }
8
+ //# sourceMappingURL=LinkContext.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"LinkContext.js","sourceRoot":"","sources":["../src/LinkContext.tsx"],"names":[],"mappings":";AAAA,OAAO,EAAE,aAAa,EAAE,UAAU,EAAsC,MAAM,OAAO,CAAC;AAStF,MAAM,mBAAmB,GAA0B,CAAC,EAAE,IAAI,EAAE,QAAQ,EAAE,EAAE,EAAE,CAAC,CACzE,YAAG,IAAI,EAAE,IAAI,YAAG,QAAQ,GAAK,CAC9B,CAAC;AAEF,MAAM,CAAC,MAAM,mBAAmB,GAAG,aAAa,CAAwB,mBAAmB,CAAC,CAAC;AAE7F,MAAM,UAAU,eAAe;IAC7B,OAAO,UAAU,CAAC,mBAAmB,CAAC,CAAC;AACzC,CAAC"}
@@ -0,0 +1,13 @@
1
+ import type { Severity } from './types.js';
2
+ /**
3
+ * How the action framework surfaces messages: an otherwise-unhandled error (no
4
+ * form field, no inline error target), and the messages an action reports
5
+ * through its ExecutionContext. `severity` defaults to 'error'. Default is a
6
+ * no-op so vultus-core stays antd-free and framework-neutral; vultus-antd's
7
+ * VultusProvider wires this to antd's message API. Hosts may inject any
8
+ * toast/notification mechanism.
9
+ */
10
+ export type MessageSink = (text: string, severity?: Severity) => void;
11
+ export declare const MessageSinkContext: import("react").Context<MessageSink>;
12
+ export declare function useMessageSink(): MessageSink;
13
+ //# sourceMappingURL=MessageSink.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"MessageSink.d.ts","sourceRoot":"","sources":["../src/MessageSink.tsx"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,YAAY,CAAC;AAE3C;;;;;;;GAOG;AACH,MAAM,MAAM,WAAW,GAAG,CAAC,IAAI,EAAE,MAAM,EAAE,QAAQ,CAAC,EAAE,QAAQ,KAAK,IAAI,CAAC;AAEtE,eAAO,MAAM,kBAAkB,sCAAuC,CAAC;AAEvE,wBAAgB,cAAc,IAAI,WAAW,CAE5C"}
@@ -0,0 +1,6 @@
1
+ import { createContext, useContext } from 'react';
2
+ export const MessageSinkContext = createContext(() => { });
3
+ export function useMessageSink() {
4
+ return useContext(MessageSinkContext);
5
+ }
6
+ //# sourceMappingURL=MessageSink.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"MessageSink.js","sourceRoot":"","sources":["../src/MessageSink.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,UAAU,EAAE,MAAM,OAAO,CAAC;AAalD,MAAM,CAAC,MAAM,kBAAkB,GAAG,aAAa,CAAc,GAAG,EAAE,GAAE,CAAC,CAAC,CAAC;AAEvE,MAAM,UAAU,cAAc;IAC5B,OAAO,UAAU,CAAC,kBAAkB,CAAC,CAAC;AACxC,CAAC"}
@@ -0,0 +1,36 @@
1
+ import type React from 'react';
2
+ import type { MutableRefObject } from 'react';
3
+ import type { MessageSink } from './MessageSink.js';
4
+ import type { ActionErrorCtx, ActionOptions, ActionStatus, ConfirmationSpec, ErrorRoutesRegistry, Message } from './types.js';
5
+ /**
6
+ * Hookless core of the action framework, shared by useAction (single) and
7
+ * useActionList (dynamic list) so the firing machinery + ActionStatus shape
8
+ * live in exactly one place — neither entry point reimplements the other.
9
+ */
10
+ export interface ResolvedFields {
11
+ label: string;
12
+ icon: React.ReactNode | undefined;
13
+ variant: 'default' | 'primary' | 'danger';
14
+ disabled: boolean;
15
+ reason: string | undefined;
16
+ invisible: boolean;
17
+ confirmation: ConfirmationSpec | undefined;
18
+ }
19
+ /** Resolve the static (hookless) ActionStatus fields from the options. */
20
+ export declare function resolveActionFields(opts: ActionOptions<any, any, any>): ResolvedFields;
21
+ export interface FirePromiseDeps<RouteId extends string> {
22
+ disabled: boolean;
23
+ reason: string | undefined;
24
+ getPending: () => boolean;
25
+ setPending: (value: boolean) => void;
26
+ setMessages: (messages: Message[]) => void;
27
+ errCtxRef: MutableRefObject<ActionErrorCtx | null>;
28
+ t: (key: string, opts?: Record<string, unknown>) => string;
29
+ registry?: ErrorRoutesRegistry<RouteId>;
30
+ messageSink?: MessageSink;
31
+ }
32
+ /** Build the async fire (pending guard + error routing) for one action. */
33
+ export declare function makeFirePromise<TArgs, TResult, RouteId extends string>(opts: ActionOptions<TArgs, TResult, RouteId>, deps: FirePromiseDeps<RouteId>): (args: TArgs) => Promise<void>;
34
+ /** Assemble the public ActionStatus from resolved fields + state + fire. */
35
+ export declare function assembleStatus<TArgs>(opts: ActionOptions<TArgs, any, any>, fields: ResolvedFields, pending: boolean, messages: Message[], firePromise: (args: TArgs) => Promise<void>): ActionStatus<TArgs>;
36
+ //# sourceMappingURL=action-core.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"action-core.d.ts","sourceRoot":"","sources":["../src/action-core.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,KAAK,MAAM,OAAO,CAAC;AAC/B,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,OAAO,CAAC;AAK9C,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,kBAAkB,CAAC;AACpD,OAAO,KAAK,EACV,cAAc,EACd,aAAa,EACb,YAAY,EACZ,gBAAgB,EAEhB,mBAAmB,EAEnB,OAAO,EAER,MAAM,YAAY,CAAC;AAEpB;;;;GAIG;AAEH,MAAM,WAAW,cAAc;IAC7B,KAAK,EAAE,MAAM,CAAC;IACd,IAAI,EAAE,KAAK,CAAC,SAAS,GAAG,SAAS,CAAC;IAClC,OAAO,EAAE,SAAS,GAAG,SAAS,GAAG,QAAQ,CAAC;IAC1C,QAAQ,EAAE,OAAO,CAAC;IAClB,MAAM,EAAE,MAAM,GAAG,SAAS,CAAC;IAC3B,SAAS,EAAE,OAAO,CAAC;IACnB,YAAY,EAAE,gBAAgB,GAAG,SAAS,CAAC;CAC5C;AAED,0EAA0E;AAC1E,wBAAgB,mBAAmB,CAAC,IAAI,EAAE,aAAa,CAAC,GAAG,EAAE,GAAG,EAAE,GAAG,CAAC,GAAG,cAAc,CAWtF;AAED,MAAM,WAAW,eAAe,CAAC,OAAO,SAAS,MAAM;IACrD,QAAQ,EAAE,OAAO,CAAC;IAClB,MAAM,EAAE,MAAM,GAAG,SAAS,CAAC;IAC3B,UAAU,EAAE,MAAM,OAAO,CAAC;IAC1B,UAAU,EAAE,CAAC,KAAK,EAAE,OAAO,KAAK,IAAI,CAAC;IACrC,WAAW,EAAE,CAAC,QAAQ,EAAE,OAAO,EAAE,KAAK,IAAI,CAAC;IAC3C,SAAS,EAAE,gBAAgB,CAAC,cAAc,GAAG,IAAI,CAAC,CAAC;IACnD,CAAC,EAAE,CAAC,GAAG,EAAE,MAAM,EAAE,IAAI,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,KAAK,MAAM,CAAC;IAC3D,QAAQ,CAAC,EAAE,mBAAmB,CAAC,OAAO,CAAC,CAAC;IACxC,WAAW,CAAC,EAAE,WAAW,CAAC;CAC3B;AAED,2EAA2E;AAC3E,wBAAgB,eAAe,CAAC,KAAK,EAAE,OAAO,EAAE,OAAO,SAAS,MAAM,EACpE,IAAI,EAAE,aAAa,CAAC,KAAK,EAAE,OAAO,EAAE,OAAO,CAAC,EAC5C,IAAI,EAAE,eAAe,CAAC,OAAO,CAAC,GAC7B,CAAC,IAAI,EAAE,KAAK,KAAK,OAAO,CAAC,IAAI,CAAC,CAmDhC;AAED,4EAA4E;AAC5E,wBAAgB,cAAc,CAAC,KAAK,EAClC,IAAI,EAAE,aAAa,CAAC,KAAK,EAAE,GAAG,EAAE,GAAG,CAAC,EACpC,MAAM,EAAE,cAAc,EACtB,OAAO,EAAE,OAAO,EAChB,QAAQ,EAAE,OAAO,EAAE,EACnB,WAAW,EAAE,CAAC,IAAI,EAAE,KAAK,KAAK,OAAO,CAAC,IAAI,CAAC,GAC1C,YAAY,CAAC,KAAK,CAAC,CAmBrB"}
@@ -0,0 +1,91 @@
1
+ import { getVerdict, getReason } from './decision.js';
2
+ import { resolve } from './resolve.js';
3
+ import { routeApiError } from './routeApiError.js';
4
+ import { parseApiError } from './parseApiError.js';
5
+ /** Resolve the static (hookless) ActionStatus fields from the options. */
6
+ export function resolveActionFields(opts) {
7
+ const enabledD = resolve(opts.enabled, true);
8
+ return {
9
+ label: resolve(opts.label, ''),
10
+ icon: resolve(opts.icon, undefined),
11
+ variant: resolve(opts.variant, 'default'),
12
+ disabled: !getVerdict(enabledD, true),
13
+ reason: getReason(enabledD),
14
+ invisible: resolve(opts.invisible, false),
15
+ confirmation: resolve(opts.confirmation, undefined),
16
+ };
17
+ }
18
+ /** Build the async fire (pending guard + error routing) for one action. */
19
+ export function makeFirePromise(opts, deps) {
20
+ return async (args) => {
21
+ if (deps.disabled) {
22
+ console.warn(`Action '${opts.id}': disabled — ${deps.reason ?? '(no reason)'}`);
23
+ return;
24
+ }
25
+ if (deps.getPending()) {
26
+ console.warn(`Action '${opts.id}': already pending — ignoring fire`);
27
+ return;
28
+ }
29
+ // Messages of this run: reported through the context while it runs, then
30
+ // the thrown error if it fails. Each report updates the status at once.
31
+ const messages = [];
32
+ const report = (severity) => (text) => {
33
+ messages.push({ text, severity });
34
+ deps.setMessages([...messages]);
35
+ deps.messageSink?.(text, severity);
36
+ };
37
+ const ctx = { info: report('info'), warn: report('warning'), error: report('error') };
38
+ deps.setMessages([]);
39
+ deps.setPending(true);
40
+ try {
41
+ const result = await opts.fire(args, ctx);
42
+ opts.onSuccess?.(result);
43
+ }
44
+ catch (err) {
45
+ const parsed = parseApiError(err);
46
+ const text = parsed.message ?? 'Action failed';
47
+ if (opts.errorRoute && deps.registry) {
48
+ // A routed action: routeApiError decides where the error shows (a form
49
+ // field, the inline error, or the sink).
50
+ routeApiError(err, {
51
+ route: opts.errorRoute,
52
+ form: deps.errCtxRef.current?.form,
53
+ setInlineError: deps.errCtxRef.current?.setInlineError,
54
+ t: deps.t,
55
+ showError: deps.messageSink,
56
+ }, deps.registry);
57
+ }
58
+ else {
59
+ // No route: the sink shows it, like the messages reported through ctx.
60
+ deps.messageSink?.(text, 'error');
61
+ }
62
+ messages.push({ text, severity: 'error' });
63
+ deps.setMessages([...messages]);
64
+ }
65
+ finally {
66
+ deps.setPending(false);
67
+ }
68
+ };
69
+ }
70
+ /** Assemble the public ActionStatus from resolved fields + state + fire. */
71
+ export function assembleStatus(opts, fields, pending, messages, firePromise) {
72
+ const fire = (args) => {
73
+ void firePromise(args);
74
+ };
75
+ return {
76
+ id: opts.id,
77
+ label: fields.label,
78
+ icon: fields.icon,
79
+ variant: fields.variant,
80
+ pending,
81
+ disabled: fields.disabled,
82
+ reason: fields.reason,
83
+ invisible: fields.invisible,
84
+ confirmation: fields.confirmation,
85
+ messages,
86
+ errors: messages.filter((m) => m.severity === 'error').map((m) => m.text),
87
+ fire: fire,
88
+ firePromise: firePromise,
89
+ };
90
+ }
91
+ //# sourceMappingURL=action-core.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"action-core.js","sourceRoot":"","sources":["../src/action-core.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,UAAU,EAAE,SAAS,EAAE,MAAM,eAAe,CAAC;AACtD,OAAO,EAAE,OAAO,EAAE,MAAM,cAAc,CAAC;AACvC,OAAO,EAAE,aAAa,EAAE,MAAM,oBAAoB,CAAC;AACnD,OAAO,EAAE,aAAa,EAAE,MAAM,oBAAoB,CAAC;AA8BnD,0EAA0E;AAC1E,MAAM,UAAU,mBAAmB,CAAC,IAAkC;IACpE,MAAM,QAAQ,GAAG,OAAO,CAAW,IAAI,CAAC,OAAO,EAAE,IAAI,CAAC,CAAC;IACvD,OAAO;QACL,KAAK,EAAE,OAAO,CAAC,IAAI,CAAC,KAAK,EAAE,EAAE,CAAC;QAC9B,IAAI,EAAE,OAAO,CAA8B,IAAI,CAAC,IAAI,EAAE,SAAS,CAAC;QAChE,OAAO,EAAE,OAAO,CAAmC,IAAI,CAAC,OAAO,EAAE,SAAS,CAAC;QAC3E,QAAQ,EAAE,CAAC,UAAU,CAAC,QAAQ,EAAE,IAAI,CAAC;QACrC,MAAM,EAAE,SAAS,CAAC,QAAQ,CAAC;QAC3B,SAAS,EAAE,OAAO,CAAC,IAAI,CAAC,SAAS,EAAE,KAAK,CAAC;QACzC,YAAY,EAAE,OAAO,CAA+B,IAAI,CAAC,YAAY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AAC,EAAE;QACX,KAAK,EAAE,MAAM,CAAC,KAAK;QACnB,IAAI,EAAE,MAAM,CAAC,IAAI;QACjB,OAAO,EAAE,MAAM,CAAC,OAAO;QACvB,OAAO;QACP,QAAQ,EAAE,MAAM,CAAC,QAAQ;QACzB,MAAM,EAAE,MAAM,CAAC,MAAM;QACrB,SAAS,EAAE,MAAM,CAAC,SAAS;QAC3B,YAAY,EAAE,MAAM,CAAC,YAAY;QACjC,QAAQ;QACR,MAAM,EAAE,QAAQ,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,QAAQ,KAAK,OAAO,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,IAAI,CAAC;QACzE,IAAI,EAAE,IAAmC;QACzC,WAAW,EAAE,WAAiD;KAC/D,CAAC;AACJ,CAAC"}
@@ -0,0 +1,10 @@
1
+ import type { Decision } from './types.js';
2
+ export declare const allow: (reason?: string) => Decision;
3
+ export declare const deny: (reason?: string) => Decision;
4
+ export declare const denyWithReason: (reason: string) => Decision;
5
+ export declare const getVerdict: (d: Decision | undefined, fallback: boolean) => boolean;
6
+ export declare const getReason: (d: Decision | undefined) => string | undefined;
7
+ export declare const andDecisions: (a: Decision, b: Decision) => Decision;
8
+ /** The opposite verdict, keeping the reason (a reason to disable is a reason not to enable). */
9
+ export declare const invertDecision: (d: Decision) => Decision;
10
+ //# sourceMappingURL=decision.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"decision.d.ts","sourceRoot":"","sources":["../src/decision.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,YAAY,CAAC;AAE3C,eAAO,MAAM,KAAK,GAAI,SAAS,MAAM,KAAG,QAAuC,CAAC;AAChF,eAAO,MAAM,IAAI,GAAI,SAAS,MAAM,KAAG,QAAwC,CAAC;AAChF,eAAO,MAAM,cAAc,GAAI,QAAQ,MAAM,KAAG,QAAwC,CAAC;AAEzF,eAAO,MAAM,UAAU,GAAI,GAAG,QAAQ,GAAG,SAAS,EAAE,UAAU,OAAO,KAAG,OACH,CAAC;AAEtE,eAAO,MAAM,SAAS,GAAI,GAAG,QAAQ,GAAG,SAAS,KAAG,MAAM,GAAG,SACgB,CAAC;AAE9E,eAAO,MAAM,YAAY,GAAI,GAAG,QAAQ,EAAE,GAAG,QAAQ,KAAG,QAQvD,CAAC;AAEF,gGAAgG;AAChG,eAAO,MAAM,cAAc,GAAI,GAAG,QAAQ,KAAG,QAC4B,CAAC"}
@@ -0,0 +1,17 @@
1
+ export const allow = (reason) => ({ verdict: true, reason });
2
+ export const deny = (reason) => ({ verdict: false, reason });
3
+ export const denyWithReason = (reason) => ({ verdict: false, reason });
4
+ export const getVerdict = (d, fallback) => d === undefined ? fallback : typeof d === 'boolean' ? d : d.verdict;
5
+ export const getReason = (d) => d === undefined ? undefined : typeof d === 'boolean' ? undefined : d.reason;
6
+ export const andDecisions = (a, b) => {
7
+ const av = getVerdict(a, false);
8
+ const bv = getVerdict(b, false);
9
+ if (av && bv) {
10
+ const reasons = [getReason(a), getReason(b)].filter(Boolean);
11
+ return { verdict: true, reason: reasons.join('; ') || undefined };
12
+ }
13
+ return av ? b : a;
14
+ };
15
+ /** The opposite verdict, keeping the reason (a reason to disable is a reason not to enable). */
16
+ export const invertDecision = (d) => typeof d === 'boolean' ? !d : { verdict: !d.verdict, reason: d.reason };
17
+ //# sourceMappingURL=decision.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"decision.js","sourceRoot":"","sources":["../src/decision.ts"],"names":[],"mappings":"AAEA,MAAM,CAAC,MAAM,KAAK,GAAG,CAAC,MAAe,EAAY,EAAE,CAAC,CAAC,EAAE,OAAO,EAAE,IAAI,EAAE,MAAM,EAAE,CAAC,CAAC;AAChF,MAAM,CAAC,MAAM,IAAI,GAAG,CAAC,MAAe,EAAY,EAAE,CAAC,CAAC,EAAE,OAAO,EAAE,KAAK,EAAE,MAAM,E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AG,CAAC,CAAW,EAAY,EAAE,CACtD,OAAO,CAAC,KAAK,SAAS,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,EAAE,OAAO,EAAE,CAAC,CAAC,CAAC,OAAO,EAAE,MAAM,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC"}
@@ -0,0 +1,97 @@
1
+ import type { ConfirmationSpec, Decision, ErrorRoutesRegistry, ExecutionContext, Message, ValueOrFn } from './types.js';
2
+ /**
3
+ * Fields: the value half of vultus, on the pattern of the sidedao InputFields.
4
+ * A field hook (useBoolField, later others) is built on useFieldCore by
5
+ * composition, never by inheritance. A field's value lives either inside the
6
+ * field (its own state) or outside it (the caller passes it every render);
7
+ * from outside it is changed either locally (`onChange`, e.g. a form) or by an
8
+ * immediate commit (`commit`), whose setter runs as an action.
9
+ * Design notes: unitas docs/2026-10-05-vultus-field-model-design.md.
10
+ */
11
+ /** How an immediately committing field stores a change: an action that receives the requested value. */
12
+ export interface FieldCommit<TRequest, RouteId extends string = string> {
13
+ fire: (next: TRequest, ctx: ExecutionContext) => Promise<void> | void;
14
+ /** Confirmation before committing; may depend on the requested value (e.g. only when switching off). */
15
+ confirmation?: ConfirmationSpec | ((next: TRequest) => ConfirmationSpec | undefined);
16
+ errorRoute?: RouteId;
17
+ }
18
+ /** The key of a value in `valueDescriptions`: 'true' / 'false' for booleans, the value itself for strings. */
19
+ export type ValueKey<T> = T extends boolean ? `${T}` : T extends string | number ? `${T}` : never;
20
+ interface FieldBaseOptions<TValue> {
21
+ id: string;
22
+ label?: ValueOrFn<string>;
23
+ description?: ValueOrFn<string | undefined>;
24
+ /** Shown? Default true. Use `visible` or `hidden`, not contradicting each other. */
25
+ visible?: ValueOrFn<boolean>;
26
+ hidden?: ValueOrFn<boolean>;
27
+ /** Changeable? Default true, optionally with a reason. Use `enabled` or `disabled`, not contradicting each other. */
28
+ enabled?: ValueOrFn<Decision>;
29
+ disabled?: ValueOrFn<Decision>;
30
+ /**
31
+ * What each value means right now, keyed by value (for booleans `true` / `false`, and `mixed`
32
+ * where the field can show it). Shown with the current value, next to `description`, which
33
+ * says what the field is in general.
34
+ */
35
+ valueDescriptions?: Partial<Record<ValueKey<TValue>, string>>;
36
+ }
37
+ /**
38
+ * Where the value lives, and what setting it does. Exactly one of the three. The field shows a
39
+ * `TValue` and can be asked for a `TRequest`; usually the same type, but an aggregate can show
40
+ * a state that cannot be requested (a boolean field showing 'mixed').
41
+ */
42
+ export type FieldStorage<TValue, TRequest = TValue, RouteId extends string = string> =
43
+ /** Inside the field: its own state, starting at `initialValue`. */
44
+ {
45
+ initialValue?: TValue;
46
+ value?: never;
47
+ onChange?: never;
48
+ commit?: never;
49
+ }
50
+ /** Outside, changed locally: the caller owns the value and applies `onChange`. */
51
+ | {
52
+ value: TValue;
53
+ onChange: (value: TRequest) => void;
54
+ initialValue?: never;
55
+ commit?: never;
56
+ }
57
+ /** Outside, committed immediately: `commit.fire` stores the change (pending, messages, confirmation). */
58
+ | {
59
+ value: TValue;
60
+ commit: FieldCommit<TRequest, RouteId>;
61
+ initialValue?: never;
62
+ onChange?: never;
63
+ };
64
+ export type FieldOptions<TValue, TRequest = TValue, RouteId extends string = string> = FieldBaseOptions<TValue> & FieldStorage<TValue, TRequest, RouteId>;
65
+ /** What a field widget receives: everything it shows, and the one way to change the value. */
66
+ export interface FieldControls<TValue, TRequest = TValue> {
67
+ type: string;
68
+ id: string;
69
+ label: string;
70
+ description: string | undefined;
71
+ /** What the current value means (from `valueDescriptions`). */
72
+ valueDescription: string | undefined;
73
+ visible: boolean;
74
+ enabled: boolean;
75
+ whyDisabled: string | undefined;
76
+ value: TValue;
77
+ /** Request a new value. Ignored (with a warning) when disabled or while a commit is pending. */
78
+ setValue(next: TRequest): void;
79
+ /** A commit is running. */
80
+ pending: boolean;
81
+ /** Messages of the last commit. */
82
+ messages: Message[];
83
+ /** The confirmation a widget must obtain before requesting `next`, if any. */
84
+ confirmationFor(next: TRequest): ConfirmationSpec | undefined;
85
+ }
86
+ export type FieldStorageMode = 'inside' | 'local' | 'commit';
87
+ export declare function fieldStorageMode(id: string, opts: FieldStorage<unknown, unknown, string>): FieldStorageMode;
88
+ export declare function calculateVisible(id: string, visible: boolean | undefined, hidden: boolean | undefined): boolean;
89
+ export declare function calculateEnabled(id: string, enabled: Decision | undefined, disabled: Decision | undefined): Decision;
90
+ /**
91
+ * The shared core of every field hook: label and description, visibility and
92
+ * enabled state (with reason), the storage mode, and in commit mode the setter
93
+ * as an action (its pending state and messages become the field's).
94
+ */
95
+ export declare function useFieldCore<TValue, TRequest extends TValue = TValue, RouteId extends string = string>(type: string, opts: FieldOptions<TValue, TRequest, RouteId>, registry?: ErrorRoutesRegistry<RouteId>): FieldControls<TValue, TRequest>;
96
+ export {};
97
+ //# sourceMappingURL=field.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"field.d.ts","sourceRoot":"","sources":["../src/field.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EACV,gBAAgB,EAChB,QAAQ,EACR,mBAAmB,EACnB,gBAAgB,EAChB,OAAO,EACP,SAAS,EACV,MAAM,YAAY,CAAC;AAEpB;;;;;;;;GAQG;AAEH,wGAAwG;AACxG,MAAM,WAAW,WAAW,CAAC,QAAQ,EAAE,OAAO,SAAS,MAAM,GAAG,MAAM;IACpE,IAAI,EAAE,CAAC,IAAI,EAAE,QAAQ,EAAE,GAAG,EAAE,gBAAgB,KAAK,OAAO,CAAC,IAAI,CAAC,GAAG,IAAI,CAAC;IACtE,wGAAwG;IACxG,YAAY,CAAC,EAAE,gBAAgB,GAAG,CAAC,CAAC,IAAI,EAAE,QAAQ,KAAK,gBAAgB,GAAG,SAAS,CAAC,CAAC;IACrF,UAAU,CAAC,EAAE,OAAO,CAAC;CACtB;AAED,8GAA8G;AAC9G,MAAM,MAAM,QAAQ,CAAC,CAAC,IAAI,CAAC,SAAS,OAAO,GAAG,GAAG,CAAC,EAAE,GAAG,CAAC,SAAS,MAAM,GAAG,MAAM,G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AAO,CAI/G;AAED,wBAAgB,gBAAgB,CAAC,EAAE,EAAE,MAAM,EAAE,OAAO,EAAE,QAAQ,GAAG,SAAS,EAAE,QAAQ,EAAE,QAAQ,GAAG,SAAS,GAAG,QAAQ,CAOpH;AAED;;;;GAIG;AACH,wBAAgB,YAAY,CAAC,MAAM,EAAE,QAAQ,SAAS,MAAM,GAAG,MAAM,EAAE,OAAO,SAAS,MAAM,GAAG,MAAM,EACpG,IAAI,EAAE,MAAM,EACZ,IAAI,EAAE,YAAY,CAAC,MAAM,EAAE,QAAQ,EAAE,OAAO,CAAC,EAC7C,QAAQ,CAAC,EAAE,mBAAmB,CAAC,OAAO,CAAC,GACtC,aAAa,CAAC,MAAM,EAAE,QAAQ,CAAC,CAkEjC"}
package/dist/field.js ADDED
@@ -0,0 +1,95 @@
1
+ import { useState } from 'react';
2
+ import { getReason, getVerdict, invertDecision } from './decision.js';
3
+ import { resolve } from './resolve.js';
4
+ import { useAction } from './useAction.js';
5
+ export function fieldStorageMode(id, opts) {
6
+ const { initialValue, value, onChange, commit } = opts;
7
+ if (commit && onChange)
8
+ throw new Error(`Field '${id}': "commit" and "onChange" are mutually exclusive`);
9
+ if ((commit || onChange) && initialValue !== undefined) {
10
+ throw new Error(`Field '${id}': "initialValue" is for a value inside the field; with "${commit ? 'commit' : 'onChange'}" the caller passes "value"`);
11
+ }
12
+ if (commit)
13
+ return 'commit';
14
+ if (onChange)
15
+ return 'local';
16
+ if (value !== undefined)
17
+ throw new Error(`Field '${id}': "value" needs "onChange" or "commit"`);
18
+ return 'inside';
19
+ }
20
+ export function calculateVisible(id, visible, hidden) {
21
+ if (visible === undefined)
22
+ return hidden === undefined ? true : !hidden;
23
+ if (hidden === undefined || visible !== hidden)
24
+ return visible;
25
+ throw new Error(`Field '${id}': "visible" and "hidden" contradict each other`);
26
+ }
27
+ export function calculateEnabled(id, enabled, disabled) {
28
+ if (enabled === undefined)
29
+ return disabled === undefined ? true : invertDecision(disabled);
30
+ if (disabled === undefined)
31
+ return enabled;
32
+ if (getVerdict(enabled, false) !== getVerdict(disabled, false)) {
33
+ return { verdict: getVerdict(enabled, false), reason: getReason(disabled) ?? getReason(enabled) };
34
+ }
35
+ throw new Error(`Field '${id}': "enabled" and "disabled" contradict each other`);
36
+ }
37
+ /**
38
+ * The shared core of every field hook: label and description, visibility and
39
+ * enabled state (with reason), the storage mode, and in commit mode the setter
40
+ * as an action (its pending state and messages become the field's).
41
+ */
42
+ export function useFieldCore(type, opts, registry) {
43
+ const mode = fieldStorageMode(opts.id, opts);
44
+ const [inner, setInner] = useState(opts.initialValue);
45
+ const label = resolve(opts.label, '');
46
+ const description = resolve(opts.description, undefined);
47
+ const visible = calculateVisible(opts.id, resolve(opts.visible, undefined), resolve(opts.hidden, undefined));
48
+ const enabledDecision = calculateEnabled(opts.id, resolve(opts.enabled, undefined), resolve(opts.disabled, undefined));
49
+ const enabled = getVerdict(enabledDecision, true);
50
+ const whyDisabled = enabled ? undefined : getReason(enabledDecision);
51
+ // Hooks run unconditionally; the setter action is only fired in commit mode.
52
+ const setter = useAction({
53
+ id: `${opts.id}.set`,
54
+ label,
55
+ enabled: enabledDecision,
56
+ invisible: !visible,
57
+ errorRoute: opts.commit?.errorRoute,
58
+ fire: (next, ctx) => opts.commit?.fire(next, ctx),
59
+ }, registry);
60
+ const value = mode === 'inside' ? inner : opts.value;
61
+ const pending = mode === 'commit' && setter.pending;
62
+ const valueDescription = opts.valueDescriptions?.[String(value)];
63
+ const setValue = (next) => {
64
+ if (!enabled) {
65
+ console.warn(`Field '${opts.id}': disabled — ${whyDisabled ?? '(no reason)'}`);
66
+ return;
67
+ }
68
+ if (mode === 'inside')
69
+ setInner(next);
70
+ else if (mode === 'local')
71
+ opts.onChange(next);
72
+ else
73
+ setter.fire(next);
74
+ };
75
+ const confirmationFor = (next) => {
76
+ const spec = opts.commit?.confirmation;
77
+ return typeof spec === 'function' ? spec(next) : spec;
78
+ };
79
+ return {
80
+ type,
81
+ id: opts.id,
82
+ label,
83
+ description,
84
+ valueDescription,
85
+ visible,
86
+ enabled,
87
+ whyDisabled,
88
+ value,
89
+ setValue,
90
+ pending,
91
+ messages: mode === 'commit' ? (setter.messages ?? []) : [],
92
+ confirmationFor,
93
+ };
94
+ }
95
+ //# sourceMappingURL=field.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"field.js","sourceRoot":"","sources":["../src/field.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,OAAO,CAAC;AACjC,OAAO,EAAE,SAAS,EAAE,UAAU,EAAE,cAAc,EAAE,MAAM,eAAe,CAAC;AACtE,OAAO,EAAE,OAAO,EAAE,MAAM,cAAc,CAAC;AACvC,OAAO,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAC;AAyF3C,MAAM,UAAU,gBAAgB,CAAC,EAAU,EAAE,IAA4C;IACvF,MAAM,EAAE,YAAY,EAAE,KAAK,EAAE,QAAQ,EAAE,MAAM,EAAE,GAAG,IAEjD,CAAC;IACF,IAAI,MAAM,IAAI,QAAQ;QAAE,MAAM,IAAI,KAAK,CAAC,UAAU,EAAE,mDAAmD,CAAC,CAAC;IACzG,IAAI,CAAC,MAAM,IAAI,QAAQ,CAAC,IAAI,YAAY,KAAK,SAAS,EAAE,CAAC;QACvD,MAAM,IAAI,KAAK,CAAC,UAAU,EAAE,4DAA4D,MAAM,CAAC,CAAC,CAAC,QAAQ,CAAC,CAAC,CAAC,UAAU,6BAA6B,CAAC,CAAC;IACvJ,CAAC;IACD,IAAI,MAAM;QAAE,OAAO,QAAQ,CAAC;IAC5B,IAAI,QAAQ;QAAE,OAAO,OAAO,CAAC;IAC7B,IAAI,KAAK,KAAK,SAAS;QAAE,MAAM,IAAI,KAAK,CAAC,UAAU,EAAE,yCAAyC,CAAC,CAAC;IAChG,OAAO,QAAQ,CAAC;AAClB,CAAC;AAED,MAAM,UAAU,gBAAgB,CAAC,EAAU,EAAE,OAA4B,EAAE,MAA2B;IACpG,IAAI,OAAO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,IAAc,EAAE,EAAE;QAClC,IAAI,CAAC,OAAO,EAAE,CAAC;YACb,OAAO,CAAC,IAAI,CAAC,UAAU,IAAI,CAAC,EAAE,iBAAiB,WAAW,IAAI,aAAa,EAAE,CAAC,CAAC;YAC/E,OAAO;QACT,CAAC;QACD,IAAI,IAAI,KAAK,QAAQ;YAAE,QAAQ,CAAC,IAAI,CAAC,CAAC;aACjC,IAAI,IAAI,KAAK,OAAO;YAAE,IAAI,CAAC,QAAS,CAAC,IAAI,CAAC,CAAC;;YAC1C,MAAM,CAAC,IAAiC,CAAC,IAAI,CAAC,CAAC;IACvD,CAAC,CAAC;IAEF,MAAM,eAAe,GAAG,CAAC,IAAc,EAAgC,EAAE;QACvE,MAAM,IAAI,GAAG,IAAI,CAAC,MAAM,EAAE,YAAY,CAAC;QACvC,OAAO,OAAO,IAAI,KAAK,UAAU,CAAC,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC;IACxD,CAAC,CAAC;IAEF,OAAO;QACL,IAAI;QACJ,EAAE,EAAE,IAAI,CAAC,EAAE;QACX,KAAK;QACL,WAAW;QACX,gBAAgB;QAChB,OAAO;QACP,OAAO;QACP,WAAW;QACX,KAAK;QACL,QAAQ;QACR,OAAO;QACP,QAAQ,EAAE,IAAI,KAAK,QAAQ,CAAC,CAAC,CAAC,CAAC,MAAM,CAAC,QAAQ,IAAI,EAAE,CAAC,CAAC,CAAC,CAAC,EAAE;QAC1D,eAAe;KAChB,CAAC;AACJ,CAAC"}
@@ -0,0 +1,14 @@
1
+ export * from './types.js';
2
+ export * from './decision.js';
3
+ export * from './resolve.js';
4
+ export * from './parseApiError.js';
5
+ export * from './routeApiError.js';
6
+ export { ActionErrorContext, useActionErrorCtx } from './useActionErrorCtx.js';
7
+ export { useAction } from './useAction.js';
8
+ export { useActionList } from './useActionList.js';
9
+ export { useFieldCore, fieldStorageMode, calculateVisible, calculateEnabled, type FieldCommit, type FieldControls, type FieldOptions, type FieldStorage, type FieldStorageMode, type ValueKey, } from './field.js';
10
+ export { useBoolField, type BoolFieldControls, type BoolFieldOptions } from './useBoolField.js';
11
+ export { useMixedBoolField, aggregateBool, type MixedBool, type MixedBoolFieldControls, type MixedBoolFieldOptions, } from './useMixedBoolField.js';
12
+ export { InternalLinkContext, useInternalLink, type InternalLinkComponent } from './LinkContext.js';
13
+ export { MessageSinkContext, useMessageSink, type MessageSink } from './MessageSink.js';
14
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,YAAY,CAAC;AAC3B,cAAc,eAAe,CAAC;AAC9B,cAAc,cAAc,CAAC;AAC7B,cAAc,oBAAoB,CAAC;AACnC,cAAc,oBAAoB,CAAC;AACnC,OAAO,EAAE,kBAAkB,EAAE,iBAAiB,EAAE,MAAM,wBAAwB,CAAC;AAC/E,OAAO,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAC;AAC3C,OAAO,EAAE,aAAa,EAAE,MAAM,oBAAoB,CAAC;AACnD,OAAO,EACL,YAAY,EAAE,gBAAgB,EAAE,gBAAgB,EAAE,gBAAgB,EAClE,KAAK,WAAW,EAAE,KAAK,aAAa,EAAE,KAAK,YAAY,EAAE,KAAK,YAAY,EAAE,KAAK,gBAAgB,EAAE,KAAK,QAAQ,GACjH,MAAM,YAAY,CAAC;AACpB,OAAO,EAAE,YAAY,EAAE,KAAK,iBAAiB,EAAE,KAAK,gBAAgB,EAAE,MAAM,mBAAmB,CAAC;AAChG,OAAO,EACL,iBAAiB,EAAE,aAAa,EAAE,KAAK,SAAS,EAAE,KAAK,sBAAsB,EAAE,KAAK,qBAAqB,GAC1G,MAAM,wBAAwB,CAAC;AAChC,OAAO,EAAE,mBAAmB,EAAE,eAAe,EAAE,KAAK,qBAAqB,EAAE,MAAM,kBAAkB,CAAC;AACpG,OAAO,EAAE,kBAAkB,EAAE,cAAc,EAAE,KAAK,WAAW,EAAE,MAAM,kBAAkB,CAAC"}
package/dist/index.js ADDED
@@ -0,0 +1,14 @@
1
+ export * from './types.js';
2
+ export * from './decision.js';
3
+ export * from './resolve.js';
4
+ export * from './parseApiError.js';
5
+ export * from './routeApiError.js';
6
+ export { ActionErrorContext, useActionErrorCtx } from './useActionErrorCtx.js';
7
+ export { useAction } from './useAction.js';
8
+ export { useActionList } from './useActionList.js';
9
+ export { useFieldCore, fieldStorageMode, calculateVisible, calculateEnabled, } from './field.js';
10
+ export { useBoolField } from './useBoolField.js';
11
+ export { useMixedBoolField, aggregateBool, } from './useMixedBoolField.js';
12
+ export { InternalLinkContext, useInternalLink } from './LinkContext.js';
13
+ export { MessageSinkContext, useMessageSink } from './MessageSink.js';
14
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,YAAY,CAAC;AAC3B,cAAc,eAAe,CAAC;AAC9B,cAAc,cAAc,CAAC;AAC7B,cAAc,oBAAoB,CAAC;AACnC,cAAc,oBAAoB,CAAC;AACnC,OAAO,EAAE,kBAAkB,EAAE,iBAAiB,EAAE,MAAM,wBAAwB,CAAC;AAC/E,OAAO,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAC;AAC3C,OAAO,EAAE,aAAa,EAAE,MAAM,oBAAoB,CAAC;AACnD,OAAO,EACL,YAAY,EAAE,gBAAgB,EAAE,gBAAgB,EAAE,gBAAgB,GAEnE,MAAM,YAAY,CAAC;AACpB,OAAO,EAAE,YAAY,EAAiD,MAAM,mBAAmB,CAAC;AAChG,OAAO,EACL,iBAAiB,EAAE,aAAa,GACjC,MAAM,wBAAwB,CAAC;AAChC,OAAO,EAAE,mBAAmB,EAAE,eAAe,EAA8B,MAAM,kBAAkB,CAAC;AACpG,OAAO,EAAE,kBAAkB,EAAE,cAAc,EAAoB,MAAM,kBAAkB,CAAC"}
@@ -0,0 +1,3 @@
1
+ import type { ParsedApiError } from './types.js';
2
+ export declare function parseApiError(err: unknown): ParsedApiError;
3
+ //# sourceMappingURL=parseApiError.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"parseApiError.d.ts","sourceRoot":"","sources":["../src/parseApiError.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,YAAY,CAAC;AAEjD,wBAAgB,aAAa,CAAC,GAAG,EAAE,OAAO,GAAG,cAAc,CAQ1D"}
@@ -0,0 +1,11 @@
1
+ export function parseApiError(err) {
2
+ if (typeof err !== 'object' || err === null)
3
+ return { status: 0 };
4
+ const e = err;
5
+ return {
6
+ status: e.status ?? 0,
7
+ reason: e.body?.reason,
8
+ message: e.body?.message,
9
+ };
10
+ }
11
+ //# sourceMappingURL=parseApiError.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"parseApiError.js","sourceRoot":"","sources":["../src/parseApiError.ts"],"names":[],"mappings":"AAEA,MAAM,UAAU,aAAa,CAAC,GAAY;IACxC,IAAI,OAAO,GAAG,KAAK,QAAQ,IAAI,GAAG,KAAK,IAAI;QAAE,OAAO,EAAE,MAAM,EAAE,CAAC,EAAE,CAAC;IAClE,MAAM,CAAC,GAAG,GAAwE,CAAC;IACnF,OAAO;QACL,MAAM,EAAE,CAAC,CAAC,MAAM,IAAI,CAAC;QACrB,MAAM,EAAE,CAAC,CAAC,IAAI,EAAE,MAAM;QACtB,OAAO,EAAE,CAAC,CAAC,IAAI,EAAE,OAAO;KACzB,CAAC;AACJ,CAAC"}
@@ -0,0 +1,3 @@
1
+ import type { ValueOrFn } from './types.js';
2
+ export declare function resolve<T>(v: ValueOrFn<T> | undefined, fallback: T): T;
3
+ //# sourceMappingURL=resolve.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"resolve.d.ts","sourceRoot":"","sources":["../src/resolve.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,YAAY,CAAC;AAE5C,wBAAgB,OAAO,CAAC,CAAC,EAAE,CAAC,EAAE,SAAS,CAAC,CAAC,CAAC,GAAG,SAAS,EAAE,QAAQ,EAAE,CAAC,GAAG,CAAC,CAGtE"}
@@ -0,0 +1,6 @@
1
+ export function resolve(v, fallback) {
2
+ if (v === undefined)
3
+ return fallback;
4
+ return typeof v === 'function' ? v() : v;
5
+ }
6
+ //# sourceMappingURL=resolve.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"resolve.js","sourceRoot":"","sources":["../src/resolve.ts"],"names":[],"mappings":"AAEA,MAAM,UAAU,OAAO,CAAI,CAA2B,EAAE,QAAW;IACjE,IAAI,CAAC,KAAK,SAAS;QAAE,OAAO,QAAQ,CAAC;IACrC,OAAO,OAAO,CAAC,KAAK,UAAU,CAAC,CAAC,CAAE,CAAa,EAAE,CAAC,CAAC,CAAC,CAAC,CAAC;AACxD,CAAC"}
@@ -0,0 +1,3 @@
1
+ import type { ApiErrorContext, ErrorRoutesRegistry } from './types.js';
2
+ export declare function routeApiError<RouteId extends string>(err: unknown, ctx: ApiErrorContext<RouteId>, registry: ErrorRoutesRegistry<RouteId>): void;
3
+ //# sourceMappingURL=routeApiError.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"routeApiError.d.ts","sourceRoot":"","sources":["../src/routeApiError.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,eAAe,EAAE,mBAAmB,EAAE,MAAM,YAAY,CAAC;AAEvE,wBAAgB,aAAa,CAAC,OAAO,SAAS,MAAM,EAClD,GAAG,EAAE,OAAO,EACZ,GAAG,EAAE,eAAe,CAAC,OAAO,CAAC,EAC7B,QAAQ,EAAE,mBAAmB,CAAC,OAAO,CAAC,GACrC,IAAI,CAiBN"}