@azx-pbc/axiom-react 0.0.0-stage → 0.0.6

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 (191) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +604 -2
  3. package/dist/FormErrorBoundary.d.ts +37 -0
  4. package/dist/FormErrorBoundary.d.ts.map +1 -0
  5. package/dist/FormErrorBoundary.js +54 -0
  6. package/dist/FormErrorBoundary.js.map +1 -0
  7. package/dist/FormProvider.d.ts +197 -0
  8. package/dist/FormProvider.d.ts.map +1 -0
  9. package/dist/FormProvider.js +149 -0
  10. package/dist/FormProvider.js.map +1 -0
  11. package/dist/field-error.d.ts +154 -0
  12. package/dist/field-error.d.ts.map +1 -0
  13. package/dist/field-error.js +2 -0
  14. package/dist/field-error.js.map +1 -0
  15. package/dist/field-props.d.ts +362 -0
  16. package/dist/field-props.d.ts.map +1 -0
  17. package/dist/field-props.js +64 -0
  18. package/dist/field-props.js.map +1 -0
  19. package/dist/form-context.d.ts +31 -0
  20. package/dist/form-context.d.ts.map +1 -0
  21. package/dist/form-context.js +13 -0
  22. package/dist/form-context.js.map +1 -0
  23. package/dist/form-store.d.ts +784 -0
  24. package/dist/form-store.d.ts.map +1 -0
  25. package/dist/form-store.js +2179 -0
  26. package/dist/form-store.js.map +1 -0
  27. package/dist/hints.d.ts +60 -0
  28. package/dist/hints.d.ts.map +1 -0
  29. package/dist/hints.js +158 -0
  30. package/dist/hints.js.map +1 -0
  31. package/dist/index.d.ts +57 -0
  32. package/dist/index.d.ts.map +1 -0
  33. package/dist/index.js +36 -0
  34. package/dist/index.js.map +1 -0
  35. package/dist/render/field-value.d.ts +92 -0
  36. package/dist/render/field-value.d.ts.map +1 -0
  37. package/dist/render/field-value.js +124 -0
  38. package/dist/render/field-value.js.map +1 -0
  39. package/dist/render/nodes.d.ts +303 -0
  40. package/dist/render/nodes.d.ts.map +1 -0
  41. package/dist/render/nodes.js +325 -0
  42. package/dist/render/nodes.js.map +1 -0
  43. package/dist/render/schema.d.ts +30 -0
  44. package/dist/render/schema.d.ts.map +1 -0
  45. package/dist/render/schema.js +40 -0
  46. package/dist/render/schema.js.map +1 -0
  47. package/dist/render/value-text.d.ts +59 -0
  48. package/dist/render/value-text.d.ts.map +1 -0
  49. package/dist/render/value-text.js +104 -0
  50. package/dist/render/value-text.js.map +1 -0
  51. package/dist/store/array-bindings.d.ts +110 -0
  52. package/dist/store/array-bindings.d.ts.map +1 -0
  53. package/dist/store/array-bindings.js +181 -0
  54. package/dist/store/array-bindings.js.map +1 -0
  55. package/dist/store/bindings.d.ts +12 -0
  56. package/dist/store/bindings.d.ts.map +1 -0
  57. package/dist/store/bindings.js +16 -0
  58. package/dist/store/bindings.js.map +1 -0
  59. package/dist/store/buffer-state.d.ts +42 -0
  60. package/dist/store/buffer-state.d.ts.map +1 -0
  61. package/dist/store/buffer-state.js +51 -0
  62. package/dist/store/buffer-state.js.map +1 -0
  63. package/dist/store/configure.d.ts +19 -0
  64. package/dist/store/configure.d.ts.map +1 -0
  65. package/dist/store/configure.js +28 -0
  66. package/dist/store/configure.js.map +1 -0
  67. package/dist/store/derive.d.ts +106 -0
  68. package/dist/store/derive.d.ts.map +1 -0
  69. package/dist/store/derive.js +417 -0
  70. package/dist/store/derive.js.map +1 -0
  71. package/dist/store/errors.d.ts +20 -0
  72. package/dist/store/errors.d.ts.map +1 -0
  73. package/dist/store/errors.js +101 -0
  74. package/dist/store/errors.js.map +1 -0
  75. package/dist/store/fields.d.ts +35 -0
  76. package/dist/store/fields.d.ts.map +1 -0
  77. package/dist/store/fields.js +81 -0
  78. package/dist/store/fields.js.map +1 -0
  79. package/dist/store/form-channel.d.ts +174 -0
  80. package/dist/store/form-channel.d.ts.map +1 -0
  81. package/dist/store/form-channel.js +411 -0
  82. package/dist/store/form-channel.js.map +1 -0
  83. package/dist/store/gates.d.ts +22 -0
  84. package/dist/store/gates.d.ts.map +1 -0
  85. package/dist/store/gates.js +44 -0
  86. package/dist/store/gates.js.map +1 -0
  87. package/dist/store/ids.d.ts +20 -0
  88. package/dist/store/ids.d.ts.map +1 -0
  89. package/dist/store/ids.js +28 -0
  90. package/dist/store/ids.js.map +1 -0
  91. package/dist/store/inputs.d.ts +114 -0
  92. package/dist/store/inputs.d.ts.map +1 -0
  93. package/dist/store/inputs.js +202 -0
  94. package/dist/store/inputs.js.map +1 -0
  95. package/dist/store/layout.d.ts +81 -0
  96. package/dist/store/layout.d.ts.map +1 -0
  97. package/dist/store/layout.js +285 -0
  98. package/dist/store/layout.js.map +1 -0
  99. package/dist/store/messages.d.ts +56 -0
  100. package/dist/store/messages.d.ts.map +1 -0
  101. package/dist/store/messages.js +157 -0
  102. package/dist/store/messages.js.map +1 -0
  103. package/dist/store/option-pages.d.ts +193 -0
  104. package/dist/store/option-pages.d.ts.map +1 -0
  105. package/dist/store/option-pages.js +598 -0
  106. package/dist/store/option-pages.js.map +1 -0
  107. package/dist/store/parse-print.d.ts +105 -0
  108. package/dist/store/parse-print.d.ts.map +1 -0
  109. package/dist/store/parse-print.js +415 -0
  110. package/dist/store/parse-print.js.map +1 -0
  111. package/dist/store/proposals.d.ts +114 -0
  112. package/dist/store/proposals.d.ts.map +1 -0
  113. package/dist/store/proposals.js +90 -0
  114. package/dist/store/proposals.js.map +1 -0
  115. package/dist/store/publish.d.ts +48 -0
  116. package/dist/store/publish.d.ts.map +1 -0
  117. package/dist/store/publish.js +96 -0
  118. package/dist/store/publish.js.map +1 -0
  119. package/dist/store/snapshots.d.ts +63 -0
  120. package/dist/store/snapshots.d.ts.map +1 -0
  121. package/dist/store/snapshots.js +154 -0
  122. package/dist/store/snapshots.js.map +1 -0
  123. package/dist/store/steps.d.ts +13 -0
  124. package/dist/store/steps.d.ts.map +1 -0
  125. package/dist/store/steps.js +31 -0
  126. package/dist/store/steps.js.map +1 -0
  127. package/dist/store/view.d.ts +124 -0
  128. package/dist/store/view.d.ts.map +1 -0
  129. package/dist/store/view.js +301 -0
  130. package/dist/store/view.js.map +1 -0
  131. package/dist/store/visibility.d.ts +68 -0
  132. package/dist/store/visibility.d.ts.map +1 -0
  133. package/dist/store/visibility.js +231 -0
  134. package/dist/store/visibility.js.map +1 -0
  135. package/dist/store/wizard-cursor.d.ts +43 -0
  136. package/dist/store/wizard-cursor.d.ts.map +1 -0
  137. package/dist/store/wizard-cursor.js +67 -0
  138. package/dist/store/wizard-cursor.js.map +1 -0
  139. package/dist/store/writes.d.ts +50 -0
  140. package/dist/store/writes.d.ts.map +1 -0
  141. package/dist/store/writes.js +91 -0
  142. package/dist/store/writes.js.map +1 -0
  143. package/dist/typed.d.ts +134 -0
  144. package/dist/typed.d.ts.map +1 -0
  145. package/dist/typed.js +74 -0
  146. package/dist/typed.js.map +1 -0
  147. package/dist/useAsyncOptions.d.ts +20 -0
  148. package/dist/useAsyncOptions.d.ts.map +1 -0
  149. package/dist/useAsyncOptions.js +70 -0
  150. package/dist/useAsyncOptions.js.map +1 -0
  151. package/dist/useBufferedInput.d.ts +69 -0
  152. package/dist/useBufferedInput.d.ts.map +1 -0
  153. package/dist/useBufferedInput.js +132 -0
  154. package/dist/useBufferedInput.js.map +1 -0
  155. package/dist/useField.d.ts +42 -0
  156. package/dist/useField.d.ts.map +1 -0
  157. package/dist/useField.js +63 -0
  158. package/dist/useField.js.map +1 -0
  159. package/dist/useFieldArray.d.ts +25 -0
  160. package/dist/useFieldArray.d.ts.map +1 -0
  161. package/dist/useFieldArray.js +18 -0
  162. package/dist/useFieldArray.js.map +1 -0
  163. package/dist/useForm.d.ts +20 -0
  164. package/dist/useForm.d.ts.map +1 -0
  165. package/dist/useForm.js +9 -0
  166. package/dist/useForm.js.map +1 -0
  167. package/dist/useFormState.d.ts +23 -0
  168. package/dist/useFormState.d.ts.map +1 -0
  169. package/dist/useFormState.js +11 -0
  170. package/dist/useFormState.js.map +1 -0
  171. package/dist/useGate.d.ts +15 -0
  172. package/dist/useGate.d.ts.map +1 -0
  173. package/dist/useGate.js +21 -0
  174. package/dist/useGate.js.map +1 -0
  175. package/dist/useLayout.d.ts +29 -0
  176. package/dist/useLayout.d.ts.map +1 -0
  177. package/dist/useLayout.js +59 -0
  178. package/dist/useLayout.js.map +1 -0
  179. package/dist/useMessage.d.ts +58 -0
  180. package/dist/useMessage.d.ts.map +1 -0
  181. package/dist/useMessage.js +62 -0
  182. package/dist/useMessage.js.map +1 -0
  183. package/dist/useWatch.d.ts +19 -0
  184. package/dist/useWatch.d.ts.map +1 -0
  185. package/dist/useWatch.js +17 -0
  186. package/dist/useWatch.js.map +1 -0
  187. package/dist/useWizard.d.ts +166 -0
  188. package/dist/useWizard.d.ts.map +1 -0
  189. package/dist/useWizard.js +554 -0
  190. package/dist/useWizard.js.map +1 -0
  191. package/package.json +62 -3
@@ -0,0 +1,15 @@
1
+ import type { GateView } from './store/gates.js';
2
+ /**
3
+ * One gate's state: the named gate, or the artifact's primary gate when none is named.
4
+ *
5
+ * The verdict is the derived state's own fold — `status`, `outcome` and the items it decided —
6
+ * so a badge cannot disagree with what a submission will face. `open` is a display
7
+ * convenience, never the decision: a host gates on `useFormState().verdict`, which weighs this
8
+ * gate together with the report and readiness, and the server decides again (`[ACCESS-7.1.1]`).
9
+ *
10
+ * A field set that declares no gate and names none answers `undefined` rather than inventing
11
+ * an open one. A gate a host names but the artifact does not declare is refused, because the
12
+ * call states which gate it means.
13
+ */
14
+ export declare function useGate(gateId?: string): GateView | undefined;
15
+ //# sourceMappingURL=useGate.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"useGate.d.ts","sourceRoot":"","sources":["../src/useGate.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,kBAAkB,CAAC;AAGjD;;;;;;;;;;;GAWG;AACH,wBAAgB,OAAO,CAAC,MAAM,CAAC,EAAE,MAAM,GAAG,QAAQ,GAAG,SAAS,CAY7D"}
@@ -0,0 +1,21 @@
1
+ import { useCallback, useSyncExternalStore } from 'react';
2
+ import { useFormSession } from './useField.js';
3
+ /**
4
+ * One gate's state: the named gate, or the artifact's primary gate when none is named.
5
+ *
6
+ * The verdict is the derived state's own fold — `status`, `outcome` and the items it decided —
7
+ * so a badge cannot disagree with what a submission will face. `open` is a display
8
+ * convenience, never the decision: a host gates on `useFormState().verdict`, which weighs this
9
+ * gate together with the report and readiness, and the server decides again (`[ACCESS-7.1.1]`).
10
+ *
11
+ * A field set that declares no gate and names none answers `undefined` rather than inventing
12
+ * an open one. A gate a host names but the artifact does not declare is refused, because the
13
+ * call states which gate it means.
14
+ */
15
+ export function useGate(gateId) {
16
+ const { store, candidate } = useFormSession('useGate');
17
+ const subscribe = useCallback((onStoreChange) => store.subscribeLayout(onStoreChange), [store]);
18
+ const getSnapshot = useCallback(() => store.gateView(store.isCurrentCandidate(candidate) ? candidate : undefined, gateId), [store, candidate, gateId]);
19
+ return useSyncExternalStore(subscribe, getSnapshot, getSnapshot);
20
+ }
21
+ //# sourceMappingURL=useGate.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"useGate.js","sourceRoot":"","sources":["../src/useGate.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,oBAAoB,EAAE,MAAM,OAAO,CAAC;AAE1D,OAAO,EAAE,cAAc,EAAE,MAAM,eAAe,CAAC;AAE/C;;;;;;;;;;;GAWG;AACH,MAAM,UAAU,OAAO,CAAC,MAAe;IACrC,MAAM,EAAE,KAAK,EAAE,SAAS,EAAE,GAAG,cAAc,CAAC,SAAS,CAAC,CAAC;IACvD,MAAM,SAAS,GAAG,WAAW,CAC3B,CAAC,aAAyB,EAAgB,EAAE,CAAC,KAAK,CAAC,eAAe,CAAC,aAAa,CAAC,EACjF,CAAC,KAAK,CAAC,CACR,CAAC;IACF,MAAM,WAAW,GAAG,WAAW,CAC7B,GAAyB,EAAE,CACzB,KAAK,CAAC,QAAQ,CAAC,KAAK,CAAC,kBAAkB,CAAC,SAAS,CAAC,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,SAAS,EAAE,MAAM,CAAC,EACrF,CAAC,KAAK,EAAE,SAAS,EAAE,MAAM,CAAC,CAC3B,CAAC;IACF,OAAO,oBAAoB,CAAC,SAAS,EAAE,WAAW,EAAE,WAAW,CAAC,CAAC;AACnE,CAAC","sourcesContent":["import { useCallback, useSyncExternalStore } from 'react';\nimport type { GateView } from './store/gates.js';\nimport { useFormSession } from './useField.js';\n\n/**\n * One gate's state: the named gate, or the artifact's primary gate when none is named.\n *\n * The verdict is the derived state's own fold — `status`, `outcome` and the items it decided —\n * so a badge cannot disagree with what a submission will face. `open` is a display\n * convenience, never the decision: a host gates on `useFormState().verdict`, which weighs this\n * gate together with the report and readiness, and the server decides again (`[ACCESS-7.1.1]`).\n *\n * A field set that declares no gate and names none answers `undefined` rather than inventing\n * an open one. A gate a host names but the artifact does not declare is refused, because the\n * call states which gate it means.\n */\nexport function useGate(gateId?: string): GateView | undefined {\n const { store, candidate } = useFormSession('useGate');\n const subscribe = useCallback(\n (onStoreChange: () => void): (() => void) => store.subscribeLayout(onStoreChange),\n [store],\n );\n const getSnapshot = useCallback(\n (): GateView | undefined =>\n store.gateView(store.isCurrentCandidate(candidate) ? candidate : undefined, gateId),\n [store, candidate, gateId],\n );\n return useSyncExternalStore(subscribe, getSnapshot, getSnapshot);\n}\n"]}
@@ -0,0 +1,29 @@
1
+ import type { LayoutNodeView } from '@azx-pbc/axiom-runtime';
2
+ import type { LayoutSlice } from './store/layout.js';
3
+ import type { MessageFormatter } from './store/messages.js';
4
+ /**
5
+ * The form's layout chrome: visible sections, their resolved titles and summary readouts.
6
+ *
7
+ * The array is identity-stable: an edit that moves no visibility, message or readout returns
8
+ * the object a consumer already rendered, so five unrelated keystrokes do not re-render the
9
+ * chrome around the form. Visibility fails open in the presentation channel, so chrome a
10
+ * record cannot decide stays visible rather than disappearing.
11
+ */
12
+ export declare function useLayout(): readonly LayoutNodeView[];
13
+ /**
14
+ * One layout node's slice: its visibility, the resolved text, its readouts and the error facts
15
+ * a collapsed container needs.
16
+ *
17
+ * `access` is the meet of the member fields' resolved answers, so a section's badge and the
18
+ * controls inside it cannot disagree. The errors are the visible, blocking ones: a failure the
19
+ * host may not show is not one an accordion badge can name.
20
+ *
21
+ * `text` is the artifact's default-locale rendering. A host with another locale, or with the
22
+ * display port a structured argument needs, passes its formatter from `useFormatMessage`; the
23
+ * slice then states the same message `renderLayout`'s `translate` does. `messageKey` and
24
+ * `messageParams` stay on the slice for a host that formats outside the hook.
25
+ */
26
+ export declare function useLayoutNode(nodeId: string, format?: MessageFormatter): LayoutSlice;
27
+ /** One layout section's slice, by the anchor its `sectionId` states. */
28
+ export declare function useSection(sectionId: string, format?: MessageFormatter): LayoutSlice;
29
+ //# sourceMappingURL=useLayout.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"useLayout.d.ts","sourceRoot":"","sources":["../src/useLayout.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,wBAAwB,CAAC;AAC7D,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAC;AACrD,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,qBAAqB,CAAC;AAG5D;;;;;;;GAOG;AACH,wBAAgB,SAAS,IAAI,SAAS,cAAc,EAAE,CAYrD;AAED;;;;;;;;;;;;GAYG;AACH,wBAAgB,aAAa,CAAC,MAAM,EAAE,MAAM,EAAE,MAAM,CAAC,EAAE,gBAAgB,GAAG,WAAW,CAYpF;AAED,wEAAwE;AACxE,wBAAgB,UAAU,CAAC,SAAS,EAAE,MAAM,EAAE,MAAM,CAAC,EAAE,gBAAgB,GAAG,WAAW,CAYpF"}
@@ -0,0 +1,59 @@
1
+ import { useCallback, useMemo, useSyncExternalStore } from 'react';
2
+ import { useFormSession } from './useField.js';
3
+ /**
4
+ * The form's layout chrome: visible sections, their resolved titles and summary readouts.
5
+ *
6
+ * The array is identity-stable: an edit that moves no visibility, message or readout returns
7
+ * the object a consumer already rendered, so five unrelated keystrokes do not re-render the
8
+ * chrome around the form. Visibility fails open in the presentation channel, so chrome a
9
+ * record cannot decide stays visible rather than disappearing.
10
+ */
11
+ export function useLayout() {
12
+ const { store, candidate } = useFormSession('useLayout');
13
+ const subscribe = useCallback((onStoreChange) => store.subscribeLayout(onStoreChange), [store]);
14
+ const getSnapshot = useCallback(() => store.layoutViews(store.isCurrentCandidate(candidate) ? candidate : undefined), [store, candidate]);
15
+ return useSyncExternalStore(subscribe, getSnapshot, getSnapshot);
16
+ }
17
+ /**
18
+ * One layout node's slice: its visibility, the resolved text, its readouts and the error facts
19
+ * a collapsed container needs.
20
+ *
21
+ * `access` is the meet of the member fields' resolved answers, so a section's badge and the
22
+ * controls inside it cannot disagree. The errors are the visible, blocking ones: a failure the
23
+ * host may not show is not one an accordion badge can name.
24
+ *
25
+ * `text` is the artifact's default-locale rendering. A host with another locale, or with the
26
+ * display port a structured argument needs, passes its formatter from `useFormatMessage`; the
27
+ * slice then states the same message `renderLayout`'s `translate` does. `messageKey` and
28
+ * `messageParams` stay on the slice for a host that formats outside the hook.
29
+ */
30
+ export function useLayoutNode(nodeId, format) {
31
+ const { store, candidate } = useFormSession('useLayoutNode');
32
+ const subscribe = useCallback((onStoreChange) => store.subscribeLayout(onStoreChange), [store]);
33
+ const getSnapshot = useCallback(() => store.layoutNode(store.isCurrentCandidate(candidate) ? candidate : undefined, nodeId), [store, candidate, nodeId]);
34
+ return useTranslated(useSyncExternalStore(subscribe, getSnapshot, getSnapshot), format);
35
+ }
36
+ /** One layout section's slice, by the anchor its `sectionId` states. */
37
+ export function useSection(sectionId, format) {
38
+ const { store, candidate } = useFormSession('useSection');
39
+ const subscribe = useCallback((onStoreChange) => store.subscribeLayout(onStoreChange), [store]);
40
+ const getSnapshot = useCallback(() => store.layoutSection(store.isCurrentCandidate(candidate) ? candidate : undefined, sectionId), [store, candidate, sectionId]);
41
+ return useTranslated(useSyncExternalStore(subscribe, getSnapshot, getSnapshot), format);
42
+ }
43
+ /**
44
+ * The slice with `text` rendered by the host's formatter, or the slice itself when it already
45
+ * states the same text.
46
+ *
47
+ * The result is memoised on the committed slice and the formatter: a formatter is normally
48
+ * `useFormatMessage`'s stable answer, so an unrelated publish keeps the identity a consumer
49
+ * already rendered.
50
+ */
51
+ function useTranslated(slice, format) {
52
+ return useMemo(() => {
53
+ if (format === undefined || slice.messageKey === undefined)
54
+ return slice;
55
+ const text = format(slice.messageKey, slice.messageParams);
56
+ return text === slice.text ? slice : { ...slice, text };
57
+ }, [slice, format]);
58
+ }
59
+ //# sourceMappingURL=useLayout.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"useLayout.js","sourceRoot":"","sources":["../src/useLayout.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,OAAO,EAAE,oBAAoB,EAAE,MAAM,OAAO,CAAC;AAInE,OAAO,EAAE,cAAc,EAAE,MAAM,eAAe,CAAC;AAE/C;;;;;;;GAOG;AACH,MAAM,UAAU,SAAS;IACvB,MAAM,EAAE,KAAK,EAAE,SAAS,EAAE,GAAG,cAAc,CAAC,WAAW,CAAC,CAAC;IACzD,MAAM,SAAS,GAAG,WAAW,CAC3B,CAAC,aAAyB,EAAgB,EAAE,CAAC,KAAK,CAAC,eAAe,CAAC,aAAa,CAAC,EACjF,CAAC,KAAK,CAAC,CACR,CAAC;IACF,MAAM,WAAW,GAAG,WAAW,CAC7B,GAA8B,EAAE,CAC9B,KAAK,CAAC,WAAW,CAAC,KAAK,CAAC,kBAAkB,CAAC,SAAS,CAAC,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,SAAS,CAAC,EAChF,CAAC,KAAK,EAAE,SAAS,CAAC,CACnB,CAAC;IACF,OAAO,oBAAoB,CAAC,SAAS,EAAE,WAAW,EAAE,WAAW,CAAC,CAAC;AACnE,CAAC;AAED;;;;;;;;;;;;GAYG;AACH,MAAM,UAAU,aAAa,CAAC,MAAc,EAAE,MAAyB;IACrE,MAAM,EAAE,KAAK,EAAE,SAA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EAAE,MAAoC;IAC7E,OAAO,OAAO,CAAC,GAAG,EAAE;QAClB,IAAI,MAAM,KAAK,SAAS,IAAI,KAAK,CAAC,UAAU,KAAK,SAAS;YAAE,OAAO,KAAK,CAAC;QACzE,MAAM,IAAI,GAAG,MAAM,CAAC,KAAK,CAAC,UAAU,EAAE,KAAK,CAAC,aAAa,CAAC,CAAC;QAC3D,OAAO,IAAI,KAAK,KAAK,CAAC,IAAI,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,EAAE,GAAG,KAAK,EAAE,IAAI,EAAE,CAAC;IAC1D,CAAC,EAAE,CAAC,KAAK,EAAE,MAAM,CAAC,CAAC,CAAC;AACtB,CAAC","sourcesContent":["import { useCallback, useMemo, useSyncExternalStore } from 'react';\nimport type { LayoutNodeView } from '@azx-pbc/axiom-runtime';\nimport type { LayoutSlice } from './store/layout.js';\nimport type { MessageFormatter } from './store/messages.js';\nimport { useFormSession } from './useField.js';\n\n/**\n * The form's layout chrome: visible sections, their resolved titles and summary readouts.\n *\n * The array is identity-stable: an edit that moves no visibility, message or readout returns\n * the object a consumer already rendered, so five unrelated keystrokes do not re-render the\n * chrome around the form. Visibility fails open in the presentation channel, so chrome a\n * record cannot decide stays visible rather than disappearing.\n */\nexport function useLayout(): readonly LayoutNodeView[] {\n const { store, candidate } = useFormSession('useLayout');\n const subscribe = useCallback(\n (onStoreChange: () => void): (() => void) => store.subscribeLayout(onStoreChange),\n [store],\n );\n const getSnapshot = useCallback(\n (): readonly LayoutNodeView[] =>\n store.layoutViews(store.isCurrentCandidate(candidate) ? candidate : undefined),\n [store, candidate],\n );\n return useSyncExternalStore(subscribe, getSnapshot, getSnapshot);\n}\n\n/**\n * One layout node's slice: its visibility, the resolved text, its readouts and the error facts\n * a collapsed container needs.\n *\n * `access` is the meet of the member fields' resolved answers, so a section's badge and the\n * controls inside it cannot disagree. The errors are the visible, blocking ones: a failure the\n * host may not show is not one an accordion badge can name.\n *\n * `text` is the artifact's default-locale rendering. A host with another locale, or with the\n * display port a structured argument needs, passes its formatter from `useFormatMessage`; the\n * slice then states the same message `renderLayout`'s `translate` does. `messageKey` and\n * `messageParams` stay on the slice for a host that formats outside the hook.\n */\nexport function useLayoutNode(nodeId: string, format?: MessageFormatter): LayoutSlice {\n const { store, candidate } = useFormSession('useLayoutNode');\n const subscribe = useCallback(\n (onStoreChange: () => void): (() => void) => store.subscribeLayout(onStoreChange),\n [store],\n );\n const getSnapshot = useCallback(\n (): LayoutSlice =>\n store.layoutNode(store.isCurrentCandidate(candidate) ? candidate : undefined, nodeId),\n [store, candidate, nodeId],\n );\n return useTranslated(useSyncExternalStore(subscribe, getSnapshot, getSnapshot), format);\n}\n\n/** One layout section's slice, by the anchor its `sectionId` states. */\nexport function useSection(sectionId: string, format?: MessageFormatter): LayoutSlice {\n const { store, candidate } = useFormSession('useSection');\n const subscribe = useCallback(\n (onStoreChange: () => void): (() => void) => store.subscribeLayout(onStoreChange),\n [store],\n );\n const getSnapshot = useCallback(\n (): LayoutSlice =>\n store.layoutSection(store.isCurrentCandidate(candidate) ? candidate : undefined, sectionId),\n [store, candidate, sectionId],\n );\n return useTranslated(useSyncExternalStore(subscribe, getSnapshot, getSnapshot), format);\n}\n\n/**\n * The slice with `text` rendered by the host's formatter, or the slice itself when it already\n * states the same text.\n *\n * The result is memoised on the committed slice and the formatter: a formatter is normally\n * `useFormatMessage`'s stable answer, so an unrelated publish keeps the identity a consumer\n * already rendered.\n */\nfunction useTranslated(slice: LayoutSlice, format: MessageFormatter | undefined): LayoutSlice {\n return useMemo(() => {\n if (format === undefined || slice.messageKey === undefined) return slice;\n const text = format(slice.messageKey, slice.messageParams);\n return text === slice.text ? slice : { ...slice, text };\n }, [slice, format]);\n}\n"]}
@@ -0,0 +1,58 @@
1
+ import type { Direction } from '@azx-pbc/axiom-runtime';
2
+ import type { FormatValue, MessageArgument, MessageFormatter } from './store/messages.js';
3
+ /**
4
+ * One message from the artifact's catalogue, rendered with the runtime's own ICU MF1 fold.
5
+ *
6
+ * The locale is the document's own: a message compiled for a catalogue key is rendered under
7
+ * that key's plural rules, and no host locale database is read, so the same record renders the
8
+ * same text on Node, in a browser and on a device whose ICU data differs. A canonical scalar
9
+ * renders as it is; a value whose wire spelling is not display text — a money amount, a date,
10
+ * an instant, a `timeslot`, a percentage — needs the host's formatter, and this hook has none,
11
+ * so that message falls back to its key rather than showing a wire spelling as prose. Use
12
+ * `useFormatMessage` when the host formats those values.
13
+ */
14
+ export declare function useMessage(key: string, params?: Readonly<Record<string, MessageArgument>>): string;
15
+ /**
16
+ * A formatter bound to one artifact and one requested locale, with the host's display port.
17
+ *
18
+ * `formatValue(name, value, descriptor)` answers the text a message interpolates, or
19
+ * `undefined` for a kind this host does not format. Structured values that no formatter
20
+ * answers fall back to the message key, so a host never ships a raw ISO date or a minor-unit
21
+ * amount as though it were display text.
22
+ *
23
+ * A key the catalogue does not declare renders as the key rather than throwing: this hook is
24
+ * also how a host labels an option a server returned, and one unknown `labelKey` must not
25
+ * crash the render that shows it. `useMessage` stays strict, because it is only ever handed a
26
+ * key the artifact itself declared.
27
+ */
28
+ export declare function useFormatMessage(locale?: string, formatValue?: FormatValue): MessageFormatter;
29
+ /**
30
+ * The text direction of the locale this form renders.
31
+ *
32
+ * `locale` is the host's request, resolved through the artifact's own catalogue exactly as a
33
+ * message is: an undeclared request falls back to the document default, and a single-locale
34
+ * artifact answers its one locale. The answer is the `dir` a host paints on the element that
35
+ * holds the text; the library never mutates `document.documentElement`.
36
+ *
37
+ * Call it beside `useFormatMessage(locale)` so the direction and the words always describe the
38
+ * same locale. Changing `locale` re-renders the caller and leaves the form session and its values
39
+ * in place. Prefer `useLocaleAttributes` when the host also needs the resolved language tag.
40
+ */
41
+ export declare function useDirection(locale?: string): Direction;
42
+ /**
43
+ * The language and direction of the locale this form renders, resolved together.
44
+ *
45
+ * `lang` is the catalogue key the request resolved to, never the host's spelling, so the
46
+ * language a screen reader voices and the direction the text runs in always describe the
47
+ * same entry: `fr-CA` against an `en` and `fr` catalogue voices `fr` left to right, and
48
+ * `ar-EG` voices `ar` right to left. The resolution is the same one `useDirection` and
49
+ * `formatCatalogueMessage` use, so all three agree. A request no catalogue answers falls back
50
+ * to the request itself for `lang`, the way `useDirection` falls back for `dir`, and the host
51
+ * paints both facts on the element that holds the text.
52
+ */
53
+ export interface LocaleAttributes {
54
+ readonly lang: string;
55
+ readonly dir: Direction;
56
+ }
57
+ export declare function useLocaleAttributes(locale?: string): LocaleAttributes;
58
+ //# sourceMappingURL=useMessage.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"useMessage.d.ts","sourceRoot":"","sources":["../src/useMessage.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,wBAAwB,CAAC;AAExD,OAAO,KAAK,EAAE,WAAW,EAAE,eAAe,EAAE,gBAAgB,EAAE,MAAM,qBAAqB,CAAC;AAG1F;;;;;;;;;;GAUG;AACH,wBAAgB,UAAU,CACxB,GAAG,EAAE,MAAM,EACX,MAAM,CAAC,EAAE,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,eAAe,CAAC,CAAC,GACjD,MAAM,CAGR;AAED;;;;;;;;;;;;GAYG;AACH,wBAAgB,gBAAgB,CAAC,MAAM,CAAC,EAAE,MAAM,EAAE,WAAW,CAAC,EAAE,WAAW,GAAG,gBAAgB,CAM7F;AAED;;;;;;;;;;;GAWG;AACH,wBAAgB,YAAY,CAAC,MAAM,CAAC,EAAE,MAAM,GAAG,SAAS,CAKvD;AAED;;;;;;;;;;GAUG;AACH,MAAM,WAAW,gBAAgB;IAC/B,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB,QAAQ,CAAC,GAAG,EAAE,SAAS,CAAC;CACzB;AAED,wBAAgB,mBAAmB,CAAC,MAAM,CAAC,EAAE,MAAM,GAAG,gBAAgB,CAMrE"}
@@ -0,0 +1,62 @@
1
+ import { useMemo } from 'react';
2
+ import { directionOf, resolveSchemaLocale } from '@azx-pbc/axiom-runtime';
3
+ import { hostMessageFormatter, messageFormatter } from './store/messages.js';
4
+ import { useFormSession } from './useField.js';
5
+ /**
6
+ * One message from the artifact's catalogue, rendered with the runtime's own ICU MF1 fold.
7
+ *
8
+ * The locale is the document's own: a message compiled for a catalogue key is rendered under
9
+ * that key's plural rules, and no host locale database is read, so the same record renders the
10
+ * same text on Node, in a browser and on a device whose ICU data differs. A canonical scalar
11
+ * renders as it is; a value whose wire spelling is not display text — a money amount, a date,
12
+ * an instant, a `timeslot`, a percentage — needs the host's formatter, and this hook has none,
13
+ * so that message falls back to its key rather than showing a wire spelling as prose. Use
14
+ * `useFormatMessage` when the host formats those values.
15
+ */
16
+ export function useMessage(key, params) {
17
+ const { store } = useFormSession('useMessage');
18
+ return messageFormatter(store.compiled, undefined)(key, params);
19
+ }
20
+ /**
21
+ * A formatter bound to one artifact and one requested locale, with the host's display port.
22
+ *
23
+ * `formatValue(name, value, descriptor)` answers the text a message interpolates, or
24
+ * `undefined` for a kind this host does not format. Structured values that no formatter
25
+ * answers fall back to the message key, so a host never ships a raw ISO date or a minor-unit
26
+ * amount as though it were display text.
27
+ *
28
+ * A key the catalogue does not declare renders as the key rather than throwing: this hook is
29
+ * also how a host labels an option a server returned, and one unknown `labelKey` must not
30
+ * crash the render that shows it. `useMessage` stays strict, because it is only ever handed a
31
+ * key the artifact itself declared.
32
+ */
33
+ export function useFormatMessage(locale, formatValue) {
34
+ const { store } = useFormSession('useFormatMessage');
35
+ return useMemo(() => hostMessageFormatter(store.compiled, locale, formatValue), [store, locale, formatValue]);
36
+ }
37
+ /**
38
+ * The text direction of the locale this form renders.
39
+ *
40
+ * `locale` is the host's request, resolved through the artifact's own catalogue exactly as a
41
+ * message is: an undeclared request falls back to the document default, and a single-locale
42
+ * artifact answers its one locale. The answer is the `dir` a host paints on the element that
43
+ * holds the text; the library never mutates `document.documentElement`.
44
+ *
45
+ * Call it beside `useFormatMessage(locale)` so the direction and the words always describe the
46
+ * same locale. Changing `locale` re-renders the caller and leaves the form session and its values
47
+ * in place. Prefer `useLocaleAttributes` when the host also needs the resolved language tag.
48
+ */
49
+ export function useDirection(locale) {
50
+ const { store } = useFormSession('useDirection');
51
+ const requested = locale ?? store.compiled.defaultLocale ?? store.compiled.locales?.[0];
52
+ const resolution = resolveSchemaLocale(store.compiled, requested);
53
+ return directionOf(resolution.ok ? resolution.locale : (requested ?? ''));
54
+ }
55
+ export function useLocaleAttributes(locale) {
56
+ const { store } = useFormSession('useLocaleAttributes');
57
+ const requested = locale ?? store.compiled.defaultLocale ?? store.compiled.locales?.[0] ?? 'en';
58
+ const resolution = resolveSchemaLocale(store.compiled, requested);
59
+ const resolved = resolution.ok ? resolution.locale : requested.replaceAll('_', '-');
60
+ return { lang: resolved, dir: directionOf(resolved) };
61
+ }
62
+ //# sourceMappingURL=useMessage.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"useMessage.js","sourceRoot":"","sources":["../src/useMessage.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,OAAO,CAAC;AAChC,OAAO,EAAE,WAAW,EAAE,mBAAmB,EAAE,MAAM,wBAAwB,CAAC;AAE1E,OAAO,EAAE,oBAAoB,EAAE,gBAAgB,EAAE,MAAM,qBAAqB,CAAC;AAE7E,OAAO,EAAE,cAAc,EAAE,MAAM,eAAe,CAAC;AAE/C;;;;;;;;;;GAUG;AACH,MAAM,UAAU,UAAU,CACxB,GAAW,EACX,MAAkD;IAElD,MAAM,EAAE,KAAK,EAAE,GAAG,cAAc,CAAC,YAAY,CAAC,CAAC;IAC/C,OAAO,gBAAgB,CAAC,KAAK,CAAC,QAAQ,EAAE,SAAS,CAAC,CAAC,GAAG,EAAE,MAAM,CAAC,CAAC;AAClE,CAAC;AAED;;;;;;;;;;;;GAYG;AACH,MAAM,UAAU,gBAAgB,CAAC,MAAe,EAAE,WAAyB;IACzE,MAAM,EAAE,KAAK,EAAE,GAAG,cAAc,CAAC,kBAAkB,CAAC,CAAC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AAQ,CAAC,EAAE,CAAC;AACxD,CAAC","sourcesContent":["import { useMemo } from 'react';\nimport { directionOf, resolveSchemaLocale } from '@azx-pbc/axiom-runtime';\nimport type { Direction } from '@azx-pbc/axiom-runtime';\nimport { hostMessageFormatter, messageFormatter } from './store/messages.js';\nimport type { FormatValue, MessageArgument, MessageFormatter } from './store/messages.js';\nimport { useFormSession } from './useField.js';\n\n/**\n * One message from the artifact's catalogue, rendered with the runtime's own ICU MF1 fold.\n *\n * The locale is the document's own: a message compiled for a catalogue key is rendered under\n * that key's plural rules, and no host locale database is read, so the same record renders the\n * same text on Node, in a browser and on a device whose ICU data differs. A canonical scalar\n * renders as it is; a value whose wire spelling is not display text — a money amount, a date,\n * an instant, a `timeslot`, a percentage — needs the host's formatter, and this hook has none,\n * so that message falls back to its key rather than showing a wire spelling as prose. Use\n * `useFormatMessage` when the host formats those values.\n */\nexport function useMessage(\n key: string,\n params?: Readonly<Record<string, MessageArgument>>,\n): string {\n const { store } = useFormSession('useMessage');\n return messageFormatter(store.compiled, undefined)(key, params);\n}\n\n/**\n * A formatter bound to one artifact and one requested locale, with the host's display port.\n *\n * `formatValue(name, value, descriptor)` answers the text a message interpolates, or\n * `undefined` for a kind this host does not format. Structured values that no formatter\n * answers fall back to the message key, so a host never ships a raw ISO date or a minor-unit\n * amount as though it were display text.\n *\n * A key the catalogue does not declare renders as the key rather than throwing: this hook is\n * also how a host labels an option a server returned, and one unknown `labelKey` must not\n * crash the render that shows it. `useMessage` stays strict, because it is only ever handed a\n * key the artifact itself declared.\n */\nexport function useFormatMessage(locale?: string, formatValue?: FormatValue): MessageFormatter {\n const { store } = useFormSession('useFormatMessage');\n return useMemo(\n () => hostMessageFormatter(store.compiled, locale, formatValue),\n [store, locale, formatValue],\n );\n}\n\n/**\n * The text direction of the locale this form renders.\n *\n * `locale` is the host's request, resolved through the artifact's own catalogue exactly as a\n * message is: an undeclared request falls back to the document default, and a single-locale\n * artifact answers its one locale. The answer is the `dir` a host paints on the element that\n * holds the text; the library never mutates `document.documentElement`.\n *\n * Call it beside `useFormatMessage(locale)` so the direction and the words always describe the\n * same locale. Changing `locale` re-renders the caller and leaves the form session and its values\n * in place. Prefer `useLocaleAttributes` when the host also needs the resolved language tag.\n */\nexport function useDirection(locale?: string): Direction {\n const { store } = useFormSession('useDirection');\n const requested = locale ?? store.compiled.defaultLocale ?? store.compiled.locales?.[0];\n const resolution = resolveSchemaLocale(store.compiled, requested);\n return directionOf(resolution.ok ? resolution.locale : (requested ?? ''));\n}\n\n/**\n * The language and direction of the locale this form renders, resolved together.\n *\n * `lang` is the catalogue key the request resolved to, never the host's spelling, so the\n * language a screen reader voices and the direction the text runs in always describe the\n * same entry: `fr-CA` against an `en` and `fr` catalogue voices `fr` left to right, and\n * `ar-EG` voices `ar` right to left. The resolution is the same one `useDirection` and\n * `formatCatalogueMessage` use, so all three agree. A request no catalogue answers falls back\n * to the request itself for `lang`, the way `useDirection` falls back for `dir`, and the host\n * paints both facts on the element that holds the text.\n */\nexport interface LocaleAttributes {\n readonly lang: string;\n readonly dir: Direction;\n}\n\nexport function useLocaleAttributes(locale?: string): LocaleAttributes {\n const { store } = useFormSession('useLocaleAttributes');\n const requested = locale ?? store.compiled.defaultLocale ?? store.compiled.locales?.[0] ?? 'en';\n const resolution = resolveSchemaLocale(store.compiled, requested);\n const resolved = resolution.ok ? resolution.locale : requested.replaceAll('_', '-');\n return { lang: resolved, dir: directionOf(resolved) };\n}\n"]}
@@ -0,0 +1,19 @@
1
+ import type { ArtifactShape, FieldIdsOf, TypedArtifact, ValueState } from '@azx-pbc/axiom-runtime';
2
+ import type { FieldBindingArgs, TypedValueState } from './typed.js';
3
+ /**
4
+ * One binding's value, and nothing else.
5
+ *
6
+ * A control that reads only the value subscribes to the value alone: an edit to another field,
7
+ * or a change that only moves a message, leaves the returned object identical and re-renders
8
+ * nothing. A value the resolved access withholds is a `withheld` state with its reason — never
9
+ * the plaintext, and never the host's mask text.
10
+ *
11
+ * Two doors share this hook. The typed door takes the artifact `defineDocument` returns and
12
+ * accepts only a declared field id; a row key is stated exactly where the declaration holds
13
+ * rows, and the `value` arm carries the declared wire value. The untyped door —
14
+ * `useWatch(fieldId, rowKey)` — is unchanged, for a host that holds a runtime artifact and
15
+ * names no types. Both read the same value, and the runtime judges both.
16
+ */
17
+ export declare function useWatch<Shape extends ArtifactShape, Id extends FieldIdsOf<Shape>>(definition: TypedArtifact<Shape>, fieldId: Id, ...rowKey: FieldBindingArgs<Shape, Id>): TypedValueState<Shape, Id>;
18
+ export declare function useWatch(fieldId: string, rowKey?: string | number): ValueState;
19
+ //# sourceMappingURL=useWatch.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"useWatch.d.ts","sourceRoot":"","sources":["../src/useWatch.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,aAAa,EAAE,UAAU,EAAE,aAAa,EAAE,UAAU,EAAE,MAAM,wBAAwB,CAAC;AAEnG,OAAO,KAAK,EAAE,gBAAgB,EAAE,eAAe,EAAE,MAAM,YAAY,CAAC;AAEpE;;;;;;;;;;;;;GAaG;AACH,wBAAgB,QAAQ,CAAC,KAAK,SAAS,aAAa,EAAE,EAAE,SAAS,UAAU,CAAC,KAAK,CAAC,EAChF,UAAU,EAAE,aAAa,CAAC,KAAK,CAAC,EAChC,OAAO,EAAE,EAAE,EACX,GAAG,MAAM,EAAE,gBAAgB,CAAC,KAAK,EAAE,EAAE,CAAC,GACrC,eAAe,CAAC,KAAK,EAAE,EAAE,CAAC,CAAC;AAC9B,wBAAgB,QAAQ,CAAC,OAAO,EAAE,MAAM,EAAE,MAAM,CAAC,EAAE,MAAM,GAAG,MAAM,GAAG,UAAU,CAAC"}
@@ -0,0 +1,17 @@
1
+ import { useCallback, useSyncExternalStore } from 'react';
2
+ import { useFormSessionFor } from './useField.js';
3
+ export function useWatch(definitionOrFieldId, fieldIdOrRowKey, rowKey) {
4
+ const typed = typeof definitionOrFieldId !== 'string';
5
+ const fieldId = typed ? fieldIdOrRowKey : definitionOrFieldId;
6
+ const bindingRowKey = typed ? rowKey : fieldIdOrRowKey;
7
+ if (typeof fieldId !== 'string') {
8
+ throw new Error('@azx-pbc/axiom-react: useWatch must name a field id');
9
+ }
10
+ const { store, candidate } = useFormSessionFor(typed ? definitionOrFieldId : undefined, 'useWatch');
11
+ const subscribe = useCallback((onStoreChange) => store.subscribe(fieldId, bindingRowKey, onStoreChange), [store, fieldId, bindingRowKey]);
12
+ const getSnapshot = useCallback(() => store.isCurrentCandidate(candidate)
13
+ ? store.getCandidateValueState(candidate, fieldId, bindingRowKey)
14
+ : store.getValueState(fieldId, bindingRowKey), [store, fieldId, bindingRowKey, candidate]);
15
+ return useSyncExternalStore(subscribe, getSnapshot, getSnapshot);
16
+ }
17
+ //# sourceMappingURL=useWatch.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"useWatch.js","sourceRoot":"","sources":["../src/useWatch.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,oBAAoB,EAAE,MAAM,OAAO,CAAC;AAE1D,OAAO,EAAE,iBAAiB,EAAE,MAAM,eAAe,CAAC;AAuBlD,MAAM,UAAU,QAAQ,CACtB,mBAA0D,EAC1D,eAAiC,EACjC,MAAwB;IAExB,MAAM,KAAK,GAAG,OAAO,mBAAmB,KAAK,QAAQ,CAAC;IACtD,MAAM,OAAO,GAAG,KAAK,CAAC,CAAC,CAAC,eAAe,CAAC,CAAC,CAAC,mBAAmB,CAAC;IAC9D,MAAM,aAAa,GAAG,KAAK,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,eAAe,CAAC;IACvD,IAAI,OAAO,OAAO,KAAK,QAAQ,EAAE,CAAC;QAChC,MAAM,IAAI,KAAK,CAAC,qDAAqD,CAAC,CAAC;IACzE,CAAC;IACD,MAAM,EAAE,KAAK,EAAE,SAAS,EAAE,GAAG,iBAAiB,CAC5C,KAAK,CAAC,CAAC,CAAC,mBAAmB,CAAC,CAAC,CAAC,SAAS,EACvC,UAAU,CACX,CAAC;IACF,MAAM,SAAS,GAAG,WAAW,CAC3B,CAAC,aAAyB,EAAgB,EAAE,CAC1C,KAAK,CAAC,SAAS,CAAC,OAAO,EAAE,aAAa,EAAE,aAAa,CAAC,EACxD,CAAC,KAAK,EAAE,OAAO,EAAE,aAAa,CAAC,CAChC,CAAC;IACF,MAAM,WAAW,GAAG,WAAW,CAC7B,GAAe,EAAE,CACf,KAAK,CAAC,kBAAkB,CAAC,SAAS,CAAC;QACjC,CAAC,CAAC,KAAK,CAAC,sBAAsB,CAAC,SAAS,EAAE,OAAO,EAAE,aAAa,CAAC;QACjE,CAAC,CAAC,KAAK,CAAC,aAAa,CAAC,OAAO,EAAE,aAAa,CAAC,EACjD,CAAC,KAAK,EAAE,OAAO,EAAE,aAAa,EAAE,SAAS,CAAC,CAC3C,CAAC;IACF,OAAO,oBAAoB,CAAC,SAAS,EAAE,WAAW,EAAE,WAAW,CAAC,CAAC;AACnE,CAAC","sourcesContent":["import { useCallback, useSyncExternalStore } from 'react';\nimport type { ArtifactShape, FieldIdsOf, TypedArtifact, ValueState } from '@azx-pbc/axiom-runtime';\nimport { useFormSessionFor } from './useField.js';\nimport type { FieldBindingArgs, TypedValueState } from './typed.js';\n\n/**\n * One binding's value, and nothing else.\n *\n * A control that reads only the value subscribes to the value alone: an edit to another field,\n * or a change that only moves a message, leaves the returned object identical and re-renders\n * nothing. A value the resolved access withholds is a `withheld` state with its reason — never\n * the plaintext, and never the host's mask text.\n *\n * Two doors share this hook. The typed door takes the artifact `defineDocument` returns and\n * accepts only a declared field id; a row key is stated exactly where the declaration holds\n * rows, and the `value` arm carries the declared wire value. The untyped door —\n * `useWatch(fieldId, rowKey)` — is unchanged, for a host that holds a runtime artifact and\n * names no types. Both read the same value, and the runtime judges both.\n */\nexport function useWatch<Shape extends ArtifactShape, Id extends FieldIdsOf<Shape>>(\n definition: TypedArtifact<Shape>,\n fieldId: Id,\n ...rowKey: FieldBindingArgs<Shape, Id>\n): TypedValueState<Shape, Id>;\nexport function useWatch(fieldId: string, rowKey?: string | number): ValueState;\nexport function useWatch(\n definitionOrFieldId: TypedArtifact<ArtifactShape> | string,\n fieldIdOrRowKey?: string | number,\n rowKey?: string | number,\n): ValueState {\n const typed = typeof definitionOrFieldId !== 'string';\n const fieldId = typed ? fieldIdOrRowKey : definitionOrFieldId;\n const bindingRowKey = typed ? rowKey : fieldIdOrRowKey;\n if (typeof fieldId !== 'string') {\n throw new Error('@azx-pbc/axiom-react: useWatch must name a field id');\n }\n const { store, candidate } = useFormSessionFor(\n typed ? definitionOrFieldId : undefined,\n 'useWatch',\n );\n const subscribe = useCallback(\n (onStoreChange: () => void): (() => void) =>\n store.subscribe(fieldId, bindingRowKey, onStoreChange),\n [store, fieldId, bindingRowKey],\n );\n const getSnapshot = useCallback(\n (): ValueState =>\n store.isCurrentCandidate(candidate)\n ? store.getCandidateValueState(candidate, fieldId, bindingRowKey)\n : store.getValueState(fieldId, bindingRowKey),\n [store, fieldId, bindingRowKey, candidate],\n );\n return useSyncExternalStore(subscribe, getSnapshot, getSnapshot);\n}\n"]}
@@ -0,0 +1,166 @@
1
+ import type { FormBlocker, WireValue } from '@azx-pbc/axiom-runtime';
2
+ import type { GateView } from './store/gates.js';
3
+ /**
4
+ * How one checkpoint reads in the wizard bar.
5
+ *
6
+ * `current` is the cursor's own page and outranks the others: the page a reader is on is the
7
+ * current one even while it still needs repair, and `problemCount` states that repair. A page
8
+ * that is not current is `blocked` while any visible field it places has a readiness reason,
9
+ * `complete` once the reader has been there and it is clean, and `unvisited` before then.
10
+ */
11
+ export type StepStatus = 'complete' | 'current' | 'unvisited' | 'blocked';
12
+ /** One visible step as the checkpoint bar reads it, in presentation order. */
13
+ export interface WizardStep {
14
+ readonly stepId: string;
15
+ /** The message key the step's title is written under. */
16
+ readonly titleKey: string;
17
+ /** Position among the visible steps; zero based. */
18
+ readonly index: number;
19
+ readonly status: StepStatus;
20
+ /**
21
+ * How many reasons stand in the way of this page: the readiness blockers whose field this
22
+ * step places, plus the failing items of the gate the step itself declares. A hidden step and
23
+ * a hidden field contribute none.
24
+ */
25
+ readonly problemCount: number;
26
+ }
27
+ /**
28
+ * One reason the current page cannot be left.
29
+ *
30
+ * A field problem wraps the same `StepBlocker` `useStep` publishes, so a footer cannot state a
31
+ * count the checkpoint bar disagrees with. A gate problem is the step's own gate, which names
32
+ * no field and therefore never appears in a field's list.
33
+ */
34
+ export type WizardProblem = {
35
+ readonly kind: 'field';
36
+ readonly blocker: StepBlocker;
37
+ } | {
38
+ readonly kind: 'gate';
39
+ readonly gateId: string;
40
+ readonly itemId: string;
41
+ readonly messageKey: string;
42
+ readonly params?: Readonly<Record<string, WireValue>>;
43
+ };
44
+ /** A branching flow's cursor, its checkpoints, and the pure moves a host may ask of it. */
45
+ export interface Wizard {
46
+ /** Every step id in authored order, hidden ones included. */
47
+ readonly stepIds: readonly string[];
48
+ /** The steps a predicate or gate currently shows, in order. */
49
+ readonly visibleStepIds: readonly string[];
50
+ /** The visible checkpoints, with their derived status and problem count. */
51
+ readonly steps: readonly WizardStep[];
52
+ /** The cursor: the step the host asked for, or the first visible one before it is placed. */
53
+ readonly stepId: string | undefined;
54
+ /**
55
+ * Whether the cursor may leave its page.
56
+ *
57
+ * It answers only for the current page: a reader who went back to a clean page may go forward
58
+ * again even when a later page is still untouched. A cursored page with no visible step at all
59
+ * cannot advance.
60
+ */
61
+ readonly canAdvance: boolean;
62
+ /** The reasons the current page blocks, in summary order; empty when `canAdvance`. */
63
+ readonly blockedBy: readonly WizardProblem[];
64
+ readonly setStepId: (stepId: string) => void;
65
+ /**
66
+ * Moves to the first visible step after the cursor, and refuses without throwing when
67
+ * `canAdvance` is false. A refusal is user intent, not a programmer error.
68
+ */
69
+ readonly next: () => void;
70
+ /** Moves to the first visible step before the cursor. */
71
+ readonly previous: () => void;
72
+ /** Where `next` would land from `from`, without moving. */
73
+ readonly nextVisibleStepId: (from: string) => string | undefined;
74
+ /** Where `previous` would land from `from`, without moving. */
75
+ readonly previousVisibleStepId: (from: string) => string | undefined;
76
+ }
77
+ /**
78
+ * A wizard's cursor and its checkpoints, host-owned: the engine holds no step state.
79
+ *
80
+ * The cursor changes only through the returned setter (which `next` and `previous` use), so a
81
+ * value edit can never move the user to another page. Hidden steps are skipped in both
82
+ * directions: with the middle step hidden, next from step one is step three and previous from
83
+ * step three is step one.
84
+ *
85
+ * A step that becomes hidden after the cursor was placed on it is not rendered: the published
86
+ * cursor reconciles to the nearest visible step (the next one, then the previous, then the
87
+ * first) so a host never renders a blank page. `setStepId` refuses an id the artifact does not
88
+ * declare, and accepts a declared-but-hidden one, which the same reconciliation then moves.
89
+ *
90
+ * The checkpoint facts are derived from the same summary `useFormState` publishes and the same
91
+ * `useStep` blocker filter, so the bar, the footer and the form-level readiness cannot disagree.
92
+ * "Visited" is the session's own history: a step becomes visited when the cursor lands on it,
93
+ * which is why a clean page reads `complete` after the reader leaves it and not before.
94
+ */
95
+ export declare function useWizard(initialStepId?: string): Wizard;
96
+ /**
97
+ * A blocking reason the summary states against a field this step places.
98
+ *
99
+ * It is the summary's own entry, narrowed to the kinds that name a field: `gate` items,
100
+ * `screen` failures and a record-scope rule that names no field are the form's reasons, not a
101
+ * page's, so a step never claims them. Item and row failures keep the member's `fieldId` and
102
+ * the row's key, exactly as `useFormState().blockers` states them; `messageKey` is the sentence
103
+ * the host already renders, absent only where the artifact declared none (a cardinality
104
+ * refusal, or a `required` rule that left the sentence to the host).
105
+ */
106
+ export type StepBlocker = Extract<FormBlocker, {
107
+ readonly kind: 'rule';
108
+ } | {
109
+ readonly kind: 'required';
110
+ } | {
111
+ readonly kind: 'cardinality';
112
+ } | {
113
+ readonly kind: 'media';
114
+ } | {
115
+ readonly kind: 'rowCount';
116
+ } | {
117
+ readonly kind: 'invalidOption';
118
+ } | {
119
+ readonly kind: 'unavailableOption';
120
+ }> & {
121
+ readonly fieldId: string;
122
+ };
123
+ /** One step's own facts: where it sits, whether it shows, and what stands in its way. */
124
+ export interface StepState {
125
+ readonly stepId: string;
126
+ readonly visible: boolean;
127
+ /** Position in authored order; `-1` for a step the artifact does not declare. */
128
+ readonly index: number;
129
+ readonly gateId: string | undefined;
130
+ readonly gate: GateView | undefined;
131
+ /**
132
+ * The summary's blocking reasons whose field this step places.
133
+ *
134
+ * A field counts as placed when the step places it, its array container or a record that
135
+ * holds it, so a row member's failure belongs to the page an adopter actually painted. A
136
+ * hidden step states none: nothing on it is a page the user can complete.
137
+ */
138
+ readonly blockers: readonly StepBlocker[];
139
+ /**
140
+ * Whether the current page may be left: no field blocker here, and the step's own gate — when
141
+ * it declares one — is not blocking. A step that declares no gate is judged by its fields
142
+ * alone; the primary gate is never borrowed. A hidden step is never ready. This is a
143
+ * navigation answer from the summary's local readiness, not the submission verdict the server
144
+ * re-derives.
145
+ */
146
+ readonly ready: boolean;
147
+ }
148
+ /**
149
+ * One wizard step, by the id the layout states.
150
+ *
151
+ * `blockers` and `ready` are derived from the same summary `useFormState` publishes and the
152
+ * same gate `useGate` presents, so a page cannot disagree with the form-level badge: the list
153
+ * is `summary.blockers` filtered by the fields this step's subtree places, never a second
154
+ * readiness rule. The placement is static per artifact, so it is read once; the filter walks
155
+ * only the fields in this step, and the per-summary index and per-step answer are memoised
156
+ * against the summary object, so an unrelated keystroke costs no scan and a publish that moved
157
+ * no summary fact reuses both.
158
+ *
159
+ * The gate is read from the same derived state `useGate` presents, so a step's gate and the
160
+ * form-level badge cannot disagree. The step's own visibility is the presentation channel's
161
+ * answer: a hidden step is skipped by the wizard's moves and never rendered by a host that
162
+ * checks it, and a hidden page reports `ready: false` with no blockers because there is no
163
+ * page to leave.
164
+ */
165
+ export declare function useStep(stepId: string): StepState;
166
+ //# sourceMappingURL=useWizard.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"useWizard.d.ts","sourceRoot":"","sources":["../src/useWizard.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAEV,WAAW,EAGX,SAAS,EACV,MAAM,wBAAwB,CAAC;A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