@azx-pbc/axiom-react 0.0.0-stage → 0.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +604 -2
- package/dist/FormErrorBoundary.d.ts +37 -0
- package/dist/FormErrorBoundary.d.ts.map +1 -0
- package/dist/FormErrorBoundary.js +54 -0
- package/dist/FormErrorBoundary.js.map +1 -0
- package/dist/FormProvider.d.ts +197 -0
- package/dist/FormProvider.d.ts.map +1 -0
- package/dist/FormProvider.js +149 -0
- package/dist/FormProvider.js.map +1 -0
- package/dist/field-error.d.ts +154 -0
- package/dist/field-error.d.ts.map +1 -0
- package/dist/field-error.js +2 -0
- package/dist/field-error.js.map +1 -0
- package/dist/field-props.d.ts +362 -0
- package/dist/field-props.d.ts.map +1 -0
- package/dist/field-props.js +64 -0
- package/dist/field-props.js.map +1 -0
- package/dist/form-context.d.ts +31 -0
- package/dist/form-context.d.ts.map +1 -0
- package/dist/form-context.js +13 -0
- package/dist/form-context.js.map +1 -0
- package/dist/form-store.d.ts +784 -0
- package/dist/form-store.d.ts.map +1 -0
- package/dist/form-store.js +2179 -0
- package/dist/form-store.js.map +1 -0
- package/dist/hints.d.ts +60 -0
- package/dist/hints.d.ts.map +1 -0
- package/dist/hints.js +158 -0
- package/dist/hints.js.map +1 -0
- package/dist/index.d.ts +57 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +36 -0
- package/dist/index.js.map +1 -0
- package/dist/render/field-value.d.ts +92 -0
- package/dist/render/field-value.d.ts.map +1 -0
- package/dist/render/field-value.js +124 -0
- package/dist/render/field-value.js.map +1 -0
- package/dist/render/nodes.d.ts +303 -0
- package/dist/render/nodes.d.ts.map +1 -0
- package/dist/render/nodes.js +325 -0
- package/dist/render/nodes.js.map +1 -0
- package/dist/render/schema.d.ts +30 -0
- package/dist/render/schema.d.ts.map +1 -0
- package/dist/render/schema.js +40 -0
- package/dist/render/schema.js.map +1 -0
- package/dist/render/value-text.d.ts +59 -0
- package/dist/render/value-text.d.ts.map +1 -0
- package/dist/render/value-text.js +104 -0
- package/dist/render/value-text.js.map +1 -0
- package/dist/store/array-bindings.d.ts +110 -0
- package/dist/store/array-bindings.d.ts.map +1 -0
- package/dist/store/array-bindings.js +181 -0
- package/dist/store/array-bindings.js.map +1 -0
- package/dist/store/bindings.d.ts +12 -0
- package/dist/store/bindings.d.ts.map +1 -0
- package/dist/store/bindings.js +16 -0
- package/dist/store/bindings.js.map +1 -0
- package/dist/store/buffer-state.d.ts +42 -0
- package/dist/store/buffer-state.d.ts.map +1 -0
- package/dist/store/buffer-state.js +51 -0
- package/dist/store/buffer-state.js.map +1 -0
- package/dist/store/configure.d.ts +19 -0
- package/dist/store/configure.d.ts.map +1 -0
- package/dist/store/configure.js +28 -0
- package/dist/store/configure.js.map +1 -0
- package/dist/store/derive.d.ts +106 -0
- package/dist/store/derive.d.ts.map +1 -0
- package/dist/store/derive.js +417 -0
- package/dist/store/derive.js.map +1 -0
- package/dist/store/errors.d.ts +20 -0
- package/dist/store/errors.d.ts.map +1 -0
- package/dist/store/errors.js +101 -0
- package/dist/store/errors.js.map +1 -0
- package/dist/store/fields.d.ts +35 -0
- package/dist/store/fields.d.ts.map +1 -0
- package/dist/store/fields.js +81 -0
- package/dist/store/fields.js.map +1 -0
- package/dist/store/form-channel.d.ts +174 -0
- package/dist/store/form-channel.d.ts.map +1 -0
- package/dist/store/form-channel.js +411 -0
- package/dist/store/form-channel.js.map +1 -0
- package/dist/store/gates.d.ts +22 -0
- package/dist/store/gates.d.ts.map +1 -0
- package/dist/store/gates.js +44 -0
- package/dist/store/gates.js.map +1 -0
- package/dist/store/ids.d.ts +20 -0
- package/dist/store/ids.d.ts.map +1 -0
- package/dist/store/ids.js +28 -0
- package/dist/store/ids.js.map +1 -0
- package/dist/store/inputs.d.ts +114 -0
- package/dist/store/inputs.d.ts.map +1 -0
- package/dist/store/inputs.js +202 -0
- package/dist/store/inputs.js.map +1 -0
- package/dist/store/layout.d.ts +81 -0
- package/dist/store/layout.d.ts.map +1 -0
- package/dist/store/layout.js +285 -0
- package/dist/store/layout.js.map +1 -0
- package/dist/store/messages.d.ts +56 -0
- package/dist/store/messages.d.ts.map +1 -0
- package/dist/store/messages.js +157 -0
- package/dist/store/messages.js.map +1 -0
- package/dist/store/option-pages.d.ts +193 -0
- package/dist/store/option-pages.d.ts.map +1 -0
- package/dist/store/option-pages.js +598 -0
- package/dist/store/option-pages.js.map +1 -0
- package/dist/store/parse-print.d.ts +105 -0
- package/dist/store/parse-print.d.ts.map +1 -0
- package/dist/store/parse-print.js +415 -0
- package/dist/store/parse-print.js.map +1 -0
- package/dist/store/proposals.d.ts +114 -0
- package/dist/store/proposals.d.ts.map +1 -0
- package/dist/store/proposals.js +90 -0
- package/dist/store/proposals.js.map +1 -0
- package/dist/store/publish.d.ts +48 -0
- package/dist/store/publish.d.ts.map +1 -0
- package/dist/store/publish.js +96 -0
- package/dist/store/publish.js.map +1 -0
- package/dist/store/snapshots.d.ts +63 -0
- package/dist/store/snapshots.d.ts.map +1 -0
- package/dist/store/snapshots.js +154 -0
- package/dist/store/snapshots.js.map +1 -0
- package/dist/store/steps.d.ts +13 -0
- package/dist/store/steps.d.ts.map +1 -0
- package/dist/store/steps.js +31 -0
- package/dist/store/steps.js.map +1 -0
- package/dist/store/view.d.ts +124 -0
- package/dist/store/view.d.ts.map +1 -0
- package/dist/store/view.js +301 -0
- package/dist/store/view.js.map +1 -0
- package/dist/store/visibility.d.ts +68 -0
- package/dist/store/visibility.d.ts.map +1 -0
- package/dist/store/visibility.js +231 -0
- package/dist/store/visibility.js.map +1 -0
- package/dist/store/wizard-cursor.d.ts +43 -0
- package/dist/store/wizard-cursor.d.ts.map +1 -0
- package/dist/store/wizard-cursor.js +67 -0
- package/dist/store/wizard-cursor.js.map +1 -0
- package/dist/store/writes.d.ts +50 -0
- package/dist/store/writes.d.ts.map +1 -0
- package/dist/store/writes.js +91 -0
- package/dist/store/writes.js.map +1 -0
- package/dist/typed.d.ts +134 -0
- package/dist/typed.d.ts.map +1 -0
- package/dist/typed.js +74 -0
- package/dist/typed.js.map +1 -0
- package/dist/useAsyncOptions.d.ts +20 -0
- package/dist/useAsyncOptions.d.ts.map +1 -0
- package/dist/useAsyncOptions.js +70 -0
- package/dist/useAsyncOptions.js.map +1 -0
- package/dist/useBufferedInput.d.ts +69 -0
- package/dist/useBufferedInput.d.ts.map +1 -0
- package/dist/useBufferedInput.js +132 -0
- package/dist/useBufferedInput.js.map +1 -0
- package/dist/useField.d.ts +42 -0
- package/dist/useField.d.ts.map +1 -0
- package/dist/useField.js +63 -0
- package/dist/useField.js.map +1 -0
- package/dist/useFieldArray.d.ts +25 -0
- package/dist/useFieldArray.d.ts.map +1 -0
- package/dist/useFieldArray.js +18 -0
- package/dist/useFieldArray.js.map +1 -0
- package/dist/useForm.d.ts +20 -0
- package/dist/useForm.d.ts.map +1 -0
- package/dist/useForm.js +9 -0
- package/dist/useForm.js.map +1 -0
- package/dist/useFormState.d.ts +23 -0
- package/dist/useFormState.d.ts.map +1 -0
- package/dist/useFormState.js +11 -0
- package/dist/useFormState.js.map +1 -0
- package/dist/useGate.d.ts +15 -0
- package/dist/useGate.d.ts.map +1 -0
- package/dist/useGate.js +21 -0
- package/dist/useGate.js.map +1 -0
- package/dist/useLayout.d.ts +29 -0
- package/dist/useLayout.d.ts.map +1 -0
- package/dist/useLayout.js +59 -0
- package/dist/useLayout.js.map +1 -0
- package/dist/useMessage.d.ts +58 -0
- package/dist/useMessage.d.ts.map +1 -0
- package/dist/useMessage.js +62 -0
- package/dist/useMessage.js.map +1 -0
- package/dist/useWatch.d.ts +19 -0
- package/dist/useWatch.d.ts.map +1 -0
- package/dist/useWatch.js +17 -0
- package/dist/useWatch.js.map +1 -0
- package/dist/useWizard.d.ts +166 -0
- package/dist/useWizard.d.ts.map +1 -0
- package/dist/useWizard.js +554 -0
- package/dist/useWizard.js.map +1 -0
- package/package.json +62 -3
package/README.md
CHANGED
|
@@ -1,3 +1,605 @@
|
|
|
1
|
-
#
|
|
1
|
+
# @azx-pbc/axiom-react
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
Headless React 19 bindings over `@azx-pbc/axiom-runtime`. One `FormProvider` opens a form session
|
|
4
|
+
over a compiled artifact, and the hooks give each control its own evaluated state — value, access,
|
|
5
|
+
visibility, enabled, required, computed value, messages and stable setters — plus the form-level
|
|
6
|
+
summary and submit/reset handle a React Hook Form user recognises. The behaviours that differ from
|
|
7
|
+
`react-hook-form`, and why, are listed under [React Hook Form parity](#react-hook-form-parity):
|
|
8
|
+
no difference is silent. The package renders nothing itself:
|
|
9
|
+
there is no control, no styling and no Document Object Model (DOM) dependency, so the same binding
|
|
10
|
+
runs on React 19 Web and React Native 0.88. It is **not** a form builder and it does not compile
|
|
11
|
+
schemas; it depends on the runtime only, and the runtime never depends on React.
|
|
12
|
+
|
|
13
|
+
## Install
|
|
14
|
+
|
|
15
|
+
```sh
|
|
16
|
+
pnpm add @azx-pbc/axiom-react react@^19
|
|
17
|
+
# or: npm install @azx-pbc/axiom-react react@^19
|
|
18
|
+
```
|
|
19
|
+
|
|
20
|
+
`react@^19` is a peer dependency. The manifest states Node `>=24`; the bindings render wherever
|
|
21
|
+
React 19 runs.
|
|
22
|
+
|
|
23
|
+
The five-minute install-to-render path, with the evaluation and publish steps around it, is
|
|
24
|
+
[`docs/integration/README.md`](https://github.com/AZX-PBC-OSS/axiom/blob/main/docs/integration/README.md).
|
|
25
|
+
|
|
26
|
+
## Quickstart
|
|
27
|
+
|
|
28
|
+
`compiled` is the artifact `@azx-pbc/axiom-compiler` produced in a build or server step; a client
|
|
29
|
+
never imports the compiler.
|
|
30
|
+
|
|
31
|
+
```tsx
|
|
32
|
+
import { FormProvider, useField, useForm, useFormState } from '@azx-pbc/axiom-react';
|
|
33
|
+
import type { AccessEntry, CompiledSchema } from '@azx-pbc/axiom-runtime';
|
|
34
|
+
import type { ReactElement } from 'react';
|
|
35
|
+
|
|
36
|
+
/** Fields a user may write. An unmentioned field resolves to `read_only`. */
|
|
37
|
+
const EDITABLE: readonly AccessEntry[] = [{ fieldId: 'f_note', access: 'read_write' }];
|
|
38
|
+
|
|
39
|
+
function NoteField(): ReactElement {
|
|
40
|
+
const field = useField('f_note');
|
|
41
|
+
if (!field.visible) return <></>;
|
|
42
|
+
return (
|
|
43
|
+
<label htmlFor={field.a11y.controlId}>
|
|
44
|
+
Note
|
|
45
|
+
<input
|
|
46
|
+
id={field.a11y.controlId}
|
|
47
|
+
value={field.text}
|
|
48
|
+
disabled={field.disabled}
|
|
49
|
+
aria-required={field.a11y.required}
|
|
50
|
+
aria-invalid={field.a11y.invalid}
|
|
51
|
+
aria-busy={field.a11y.busy}
|
|
52
|
+
aria-describedby={field.showError ? field.a11y.errorId : field.a11y.descriptionId}
|
|
53
|
+
onChange={(event) => field.onChange(event.target.value)}
|
|
54
|
+
onBlur={field.onBlur}
|
|
55
|
+
/>
|
|
56
|
+
{field.showError ? (
|
|
57
|
+
<p role="alert" id={field.a11y.errorId}>
|
|
58
|
+
{field.errors[0]?.kind}
|
|
59
|
+
</p>
|
|
60
|
+
) : null}
|
|
61
|
+
</label>
|
|
62
|
+
);
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
function Submit(): ReactElement {
|
|
66
|
+
const form = useForm();
|
|
67
|
+
const state = useFormState();
|
|
68
|
+
return (
|
|
69
|
+
<button
|
|
70
|
+
type="submit"
|
|
71
|
+
disabled={state.isSubmitting}
|
|
72
|
+
onClick={() => void form.handleSubmit(console.log)}
|
|
73
|
+
>
|
|
74
|
+
{state.isDirty ? 'Save changes' : 'Submit'}
|
|
75
|
+
</button>
|
|
76
|
+
);
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
export function NoteForm(props: { readonly compiled: CompiledSchema }): ReactElement {
|
|
80
|
+
return (
|
|
81
|
+
<FormProvider compiled={props.compiled} initialValues={{ f_note: '' }} access={EDITABLE}>
|
|
82
|
+
<NoteField />
|
|
83
|
+
<Submit />
|
|
84
|
+
</FormProvider>
|
|
85
|
+
);
|
|
86
|
+
}
|
|
87
|
+
```
|
|
88
|
+
|
|
89
|
+
A write re-renders the bindings whose published state changed: writing one line does not re-render an
|
|
90
|
+
unrelated field, while a computed total that depends on it does.
|
|
91
|
+
|
|
92
|
+
A control reads `field.text`, not `field.value`: the wire value is the union (a money amount is an
|
|
93
|
+
object, an authored empty value is `null`), while `text` is the one display answer for every domain —
|
|
94
|
+
`maskedText` beside a withheld value, a writer's value for a computed field, money in
|
|
95
|
+
its declared scale, and `''` for absent. A control that edits a non-text domain reads
|
|
96
|
+
`useFieldValue` for the tagged value.
|
|
97
|
+
|
|
98
|
+
**Interactive affordances gate on `mayWrite`.** `enabled` states the access and `enabled` rules, so
|
|
99
|
+
a writer-owned value and a `signature_ref` are `enabled` while no user write can reach them. A
|
|
100
|
+
`<select>`, checkbox or `Pressable` has no platform read-only state: when `mayWrite` is false, paint
|
|
101
|
+
the value as static text instead of an interactive control, or the write reaches `setValue` and
|
|
102
|
+
throws `WriteRefusedError` out of the change handler. A text input is the one exception only when
|
|
103
|
+
`mayWrite` is false because access is exactly `read_only`: it may stay focusable and copyable with
|
|
104
|
+
`readOnly`. Every other false answer — masked, computed, a `signature_ref`, a failed `enabled` rule
|
|
105
|
+
or a hidden binding — paints static or disabled.
|
|
106
|
+
|
|
107
|
+
**A masked binding is never an input or a buffer.** When access is `masked`, the record holds a value
|
|
108
|
+
this device may not read, so `value` is absent and `maskedText` is present: render that text and no
|
|
109
|
+
control. It is the provider's `maskedDisplay` for the field, or `''` when the host supplied none; it
|
|
110
|
+
is never derived from the value or its length. `useBufferedInput` has no value to start from and
|
|
111
|
+
every keystroke would be refused, so a control must branch on `maskedText` before choosing an input.
|
|
112
|
+
`maskedText` is the **visible placeholder**, not the whole announcement: state the withholding
|
|
113
|
+
programmatically as well — a visually-hidden sentence in the labelled value, or `aria-description` —
|
|
114
|
+
because the placeholder's characters alone do not tell a screen-reader user that a value exists and
|
|
115
|
+
is being withheld.
|
|
116
|
+
|
|
117
|
+
`field.a11y` carries the element ids the markup needs
|
|
118
|
+
(`controlId`, `errorId`, `descriptionId`), never `bindingKey`: a natural row key is user text, and an
|
|
119
|
+
HTML id may not carry the whitespace it can hold. `descriptionId` is present only when the binding
|
|
120
|
+
declares a `descriptionKey`, so a control can put it in `aria-describedby` without creating a
|
|
121
|
+
dangling IDREF. `a11y.busy` is true only while a submission that will settle a server-tier check is
|
|
122
|
+
in flight; at rest a `deferred` check is reported in `errors` rather than as a control that is
|
|
123
|
+
permanently loading.
|
|
124
|
+
|
|
125
|
+
## Public surface
|
|
126
|
+
|
|
127
|
+
| Export | What it is |
|
|
128
|
+
| ----------------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ |
|
|
129
|
+
| `FormProvider` | Component that opens one session per mount; renders its children behind a context, nothing else. |
|
|
130
|
+
| `useField(fieldId, rowKey?)` | The frozen `FieldProps` of one binding — a field, or one row of a field. |
|
|
131
|
+
| `useFormState()` | The `FormSummary`: dirty and touched bindings, validity, readiness, submit counters, errors and blockers. |
|
|
132
|
+
| `useForm()` / `useFormHandle()` | The identity-stable `FormHandle`: submit, reset, export and the session operations. It never subscribes. |
|
|
133
|
+
| `useWatch(fieldId, rowKey?)` | One binding's `ValueState`, and nothing else. |
|
|
134
|
+
| `useFieldValue(fieldId, rowKey?)` | One binding's value tagged by its declaration (`FieldValue`): `absent`, `unreadable`, `text`, `integer`, `boolean`, `money`, `timeslot`, `reference`, `list`, `record` or `opaque`, so a control branches once instead of on `typeof`. |
|
|
135
|
+
| `useSchema()` / `useFields()` / `useIdPrefix()` | The artifact the session was opened with, its field declarations, and the element-id prefix this session emits, read from the provider instead of forwarded as props. `useFields()` is the `fields` array `renderLayout` takes; `useIdPrefix()` is the value `renderErrorSummary` and a host's own markup need so their ids resolve inside this provider. |
|
|
136
|
+
| `fieldDomId` / `fieldErrorId` / `fieldDescriptionId` | The element ids a binding renders into, from `(idPrefix, bindingKey)`: the session prefix then the percent-encoded key, so two providers over one artifact never share an id and a natural row key's whitespace cannot break `htmlFor` or `aria-describedby`. A control reads them as `a11y.controlId`, `a11y.errorId` and `a11y.descriptionId` (the last only when the binding declares a description); the prefix is `useIdPrefix()`. |
|
|
137
|
+
| `useFieldArray(arrayFieldId)` | An array binding's identity-stable `rows` (`RowRef[]`), its six structural operations (`append`, `insert`, `remove`, `move`, `moveRow`, `replace`) and the `mutations` permissions. |
|
|
138
|
+
| `useBufferedInput(fieldId, format, rowKey?)` | A text control whose raw keystrokes are not the value: `text`, `dirty`, `parseKind`, `parseError` (a stable reason key), `parseErrorParams`, `setText`, `commit`, `onBlur`, `reset`. |
|
|
139
|
+
| `useAsyncOptions(fieldId, rowKey?, pageSize?)` | A host-loaded option domain: `items`, `offered`, `loading`, `resolved`, `error`, `hasMore`, `cursor`, `loadMore`, `reload`, `search` and the `basisSignature` the pages are keyed by. `pageSize` defaults to `DEFAULT_OPTION_PAGE_SIZE` (50). |
|
|
140
|
+
| `useGate(gateId?)` | The named gate, or the artifact's primary gate: `status`, `outcome`, `items`, `open`. |
|
|
141
|
+
| `useLayout()` / `useLayoutNode(nodeId, format?)` / `useSection(sectionId, format?)` | The presentation chrome, one node's `LayoutSlice`, or one section's — with `visible`, `access`, `text`, `messageKey`, `messageParams`, `readouts`, `hasErrors`, `errorCount`. `text` is the default-locale rendering; a formatter from `useFormatMessage` resolves another locale or a structured argument. |
|
|
142
|
+
| `renderLayout(input)` | The host-neutral render tree: one layout walked into sections, groups, wizard steps, controls, callouts, summary cards and repeating records — a total function of the closed layout and control unions, never of identifiers. `input` is `{ layout, fields, translate, stepId? }`; a named `stepId` narrows the wizard node to that step and states it in `RenderWizardNode.currentStepId`. The announced error summary is `renderErrorSummary`. |
|
|
143
|
+
| `renderErrorSummary(input)` | The announced error summary as one `error_summary` node, or `undefined` when nothing blocks: `{ fields, errors, translate, idPrefix }`. `idPrefix` is **required** — read it with `useIdPrefix()` — because an item that names a field and no `targetId` resolves to that field's control id under this session's prefix; `RenderErrorItem.targetId` defaults to that id, and a row-scoped reason supplies its own. A separate call so a host places the summary itself. |
|
|
144
|
+
| `renderValueText(value, valueDisplay?)` | A wire value as host-neutral text for a read-only control or summary, without reading `Intl`. `valueDisplay` is the host's port for a boolean, a list, money or a date; a boolean and a list have no English fallback. |
|
|
145
|
+
| `renderFieldText(field, valueDisplay?)` | The text a binding shows, wherever its value lives: its `maskedText`, its computed value when a writer owns it, else its value — money in its declared scale and a timeslot's date and window, without reading `Intl`. A boolean and a list need `valueDisplay`. |
|
|
146
|
+
| `useWizard(initialStepId?)` / `useStep(stepId)` | A session-scoped wizard cursor shared by every caller under one `FormProvider`, with pure next/previous helpers that skip hidden steps, and one step's visibility, index and gate. |
|
|
147
|
+
| `useMessage(key, params?)` / `useFormatMessage(locale?, formatValue?)` | Compiled ICU MF1 messages rendered with zero `Intl`, and the host's display port for dates, instants, money, timeslots and percentages. |
|
|
148
|
+
| `useDirection(locale?)` | The `'ltr' \| 'rtl'` direction of the locale the form renders, resolved through the artifact's catalogue and the runtime's vendored CLDR script map (`directionOf`). A host paints `dir`/`lang` on the element that holds the text; the library never mutates the document. |
|
|
149
|
+
| `getInputHints(control)` | Pure, module-cached Web and React Native keyboard/autofill hints for a control. |
|
|
150
|
+
| `FormProviderProps` | `compiled`, `initialValues`, optional `idPrefix` (defaults to the `useId()` this mount mints; pass one for readable ids, more than one React root, or a server-matched render), `idFactory` (the host's assigned row ids; required when the artifact declares an `assigned` array), `rowManifest` (the ids a resumed record carries), `context`, `overlay` or `access`, `redacted`, `sessionWrites`, `env`, `showErrors`, `maskedDisplay`, `valueDisplay`, `optionSources`, `cancellation`, `defer`, `onPublish`, `onWriteProposed`, `children`. |
|
|
151
|
+
| `seededIdFactory(seed)` | A deterministic `IdFactory`: `seed_1`, `seed_2`, … No clock and no random source, so a server render and the client that hydrates it mint the same assigned row ids when each builds its own factory over the same seed. The seed is the host's scope — two sessions whose records may merge must not share one. |
|
|
152
|
+
| `FieldProps` | `fieldId`, `rowKey?`, `bindingKey`, `descriptor`, `value`, `text`, `initialValue`, `access`, `visible`, `enabled`, `mayWrite`, `disabled`, `readOnly`, `required`, `computation`, `unavailableOptions?` (the option codes the record refuses or cannot decide, with the reason each stated, `ENGINE-7.1.7`), `messages`, `errors`, `readOnlyDiagnostics`, `invalid`, `showError`, `touched`, `dirty`, `maskedText`, `a11y` (`required`, `invalid`, `disabled`, `readOnly`, `controlId`, `errorId`, `descriptionId?`, `busy`), `hints`, `signature`, `setValue`, `onChange`, `setNull`, `removeValue`, `onBlur`. |
|
|
153
|
+
| `FieldError` | Union tagged `validate`, `deferred`, `required`, `invalid-value`, `access`, `gate`, `screen` or `row-key`; each member is exported with it. A `required` failure is only the runtime's decided `missing`; `undetermined` (a server-tier answer, or a value the server withheld) leaves `ready` false and never becomes a blocking field error. An `access` failure states a `masked`, `hidden` or `write_only` withholding; a `redacted` value is the server's decision, not the resolved access, so it is never reported as "not editable". A `row-key` failure is the entry a write refused because it would give two rows one identity: it is non-blocking (the record still holds the valid value) but `showError` and `a11y.invalid` announce it immediately. |
|
|
154
|
+
| `FormSummary` | `isDirty`, `dirtyFields`, `touchedFields`, `isValid`, `isSubmitted`, `isSubmitting`, `isSubmitSuccessful`, `submitCount`, `errors`, `firstErrorBindingKey`, `blockers`, `missingRequiredFields`, `hasDeferredChecks`, `ready`, `verdict`, `pendingProposal` (a value-free `sequence` and `binding` of a waiting confirmation). |
|
|
155
|
+
| `FormHandle` | `handleSubmit` (returns the submission promise), `submitHandler` (deprecated thunk), `reset`, `exportSubmission`, `getValues`, `getField`, `getState`, `batch`, `setValue`, `setNull`, `removeValue`, `setContext`, `setEnv`, `setAccess`, `explainField`, `inspectFieldDeps`, `propose`, `applyProposal`, `discardProposal`. |
|
|
156
|
+
| `InputHints` | `control`, `web` (`type`, `inputMode`, `autoComplete`), `native` (`keyboardType`, `textContentType`, `autoCapitalize`). |
|
|
157
|
+
| `FieldValue` / `RenderWizardNode` / `RenderErrorItem` | The tagged value a control branches on (`absent`, `text`, `money`, `timeslot`, …); the wizard render node whose `currentStepId` names the step the host chose; an announced error's `targetId`, the control id it links to. |
|
|
158
|
+
| `PublishTrace`, `ShowErrorsPolicy`, `FieldA11y`, `AccessSourceError` | The publish observer's trace, the reveal policy, the accessibility shape and the dual-access-source refusal. |
|
|
159
|
+
|
|
160
|
+
`AsyncOptionList` also states `resolved`, which is true for a loaded empty page as well as one
|
|
161
|
+
with items, and `readable`, which is false when a withheld dependency prevented any request.
|
|
162
|
+
|
|
163
|
+
`FormProvider` props are live: changing `overlay`/`access`, `redacted`, `sessionWrites`, `context`,
|
|
164
|
+
`env`, `showErrors` or `maskedDisplay` re-derives the session and keeps the values already
|
|
165
|
+
entered. `initialValues`, `compiled`, `idPrefix`, `idFactory`, `rowManifest`, `optionSources`,
|
|
166
|
+
`cancellation` and `defer` are read once at mount; mount a new provider (a new React `key`) to
|
|
167
|
+
start from a different record, artifact, id prefix, row identity or host option configuration. Every element id this form emits begins with the prefix, so two providers
|
|
168
|
+
over one artifact cannot collide; read it with `useIdPrefix()` when you paint
|
|
169
|
+
`renderErrorSummary` or your own markup.
|
|
170
|
+
|
|
171
|
+
The handle's `setAccess`, `setContext` and `setEnv` are event-handler operations: what they install
|
|
172
|
+
is the session's input from then on, and it survives renders that do not state that input. A prop
|
|
173
|
+
that states the same input is the authority — the imperative value yields to it.
|
|
174
|
+
|
|
175
|
+
`onWriteProposed` turns every user write into a preview: a write whose change set adds a blocker
|
|
176
|
+
that offers alternatives is staged and reported to the host instead of committed, and one that adds
|
|
177
|
+
none commits immediately. `form.propose(operations)` returns the same shape without writing
|
|
178
|
+
anything, for a change set the host derived itself. Answer a proposal with
|
|
179
|
+
`form.applyProposal(proposal)`, which commits the candidate the host was shown and records the
|
|
180
|
+
dirty and touched marks a keystroke records, or with `form.discardProposal(proposal)`, which writes
|
|
181
|
+
nothing and repaints the bindings the proposal named. One proposal is pending at a time: a newer
|
|
182
|
+
qualifying write is reported over the one it supersedes, so answer the latest, and applying a
|
|
183
|
+
proposal whose basis has since moved is refused with `STALE_BASIS`. A proposal a newer write
|
|
184
|
+
replaced, or one the host declined, is refused with `PROPOSAL_SUPERSEDED` before it reaches the
|
|
185
|
+
engine. `useFormState().pendingProposal`
|
|
186
|
+
is a value-free projection: it states the waiting `sequence` and the `binding` the write edits, never
|
|
187
|
+
its operations or candidate. The proposal to apply or discard is the one `onWriteProposed` delivered,
|
|
188
|
+
or the one `form.propose` returned.
|
|
189
|
+
|
|
190
|
+
## Arrays
|
|
191
|
+
|
|
192
|
+
`useFieldArray(fieldId)` binds one array once and returns its `rows` in order. A row reference keeps
|
|
193
|
+
its object identity while the row exists, so a React `key`, a memo boundary and the engine's baseline
|
|
194
|
+
all follow a move; the list is republished only when the ordered identity or the mutation permissions
|
|
195
|
+
change, so a keystroke in one row re-renders that row's own `useField` binding and not the list.
|
|
196
|
+
`mutations` states which of `append`, `insert`, `remove`, `move` and `replace` the container's
|
|
197
|
+
committed access and `enabled` answer permit. `append(value)` and `insert(index, value)` parse the
|
|
198
|
+
element against the array's item declaration, and a refused structural write throws the same
|
|
199
|
+
`WriteRefusedError` a value write does. `remove(rowKey)` names the row's identity, never its
|
|
200
|
+
position, so a concurrent reorder cannot delete the wrong row. `moveRow(rowKey, toIndex)` is the
|
|
201
|
+
identity-addressed move a drag handler uses when it knows the row rather than its current index;
|
|
202
|
+
`move(fromIndex, toIndex)` is the positional one. `replace(values)` is React Hook Form's `replace`:
|
|
203
|
+
the whole list in one write, through the container the engine already owns, so an `assigned` array
|
|
204
|
+
mints its ids the same way an append does. A surviving natural key keeps its `RowRef` (and the
|
|
205
|
+
failure an item rule decided about it); a dropped row retires and an added one starts fresh.
|
|
206
|
+
|
|
207
|
+
An empty array is a **present** value: a `required` rule on an array is satisfied by `[]`, because
|
|
208
|
+
`required` asks whether the record holds a value, not how many rows it holds. A form that must have
|
|
209
|
+
at least one row states that with a `validate` expression:
|
|
210
|
+
|
|
211
|
+
```jsonc
|
|
212
|
+
{
|
|
213
|
+
"ruleId": "r_lines_nonempty",
|
|
214
|
+
"kind": "validate",
|
|
215
|
+
"scope": "field",
|
|
216
|
+
"fieldId": "f_lines",
|
|
217
|
+
"severity": "block",
|
|
218
|
+
"evaluateOn": "client",
|
|
219
|
+
"messageKey": "validate.lines.nonempty",
|
|
220
|
+
"expr": {
|
|
221
|
+
"kind": "compare",
|
|
222
|
+
"op": ">",
|
|
223
|
+
"args": [
|
|
224
|
+
{ "kind": "call", "op": "count", "args": [{ "kind": "path", "path": "f_lines" }] },
|
|
225
|
+
{ "kind": "literal", "domain": "integer", "value": 0 }
|
|
226
|
+
]
|
|
227
|
+
}
|
|
228
|
+
}
|
|
229
|
+
```
|
|
230
|
+
|
|
231
|
+
A row binding is always addressed by `(fieldId, rowKey)`: `useField`, `useWatch`, `useFieldValue`
|
|
232
|
+
and `useAsyncOptions` put the row immediately after the field. `useBufferedInput` is the one
|
|
233
|
+
exception because its `format` is required and TypeScript forbids a required parameter after an
|
|
234
|
+
optional one: it is `(fieldId, format, rowKey?)`, so a row control passes
|
|
235
|
+
`useBufferedInput('f_row_value', { kind: 'phone' }, rowKey)`. `useFieldArray(fieldId)` names the
|
|
236
|
+
container, which has no row of its own.
|
|
237
|
+
|
|
238
|
+
```tsx
|
|
239
|
+
const rows = useFieldArray('f_lines');
|
|
240
|
+
rows.rows.map((row) => <RowControl key={row.bindingKey} rowKey={row.rowKey} />);
|
|
241
|
+
rows.mutations.append ? (
|
|
242
|
+
<button onClick={() => rows.append({ f_line: null })}>Add line</button>
|
|
243
|
+
) : null;
|
|
244
|
+
```
|
|
245
|
+
|
|
246
|
+
### Assigned row identity is the host's
|
|
247
|
+
|
|
248
|
+
A row of an `assigned` array is named by an id the host's `idFactory` mints — Axiom keeps the
|
|
249
|
+
manifest that orders those ids but invents none of them (`[IDENT-2.1.2]`). `FormProvider` requires
|
|
250
|
+
the factory when the artifact declares such an array and refuses to open without it
|
|
251
|
+
(`ID_FACTORY_REQUIRED`); every call must return an id that has never named a row, and the engine
|
|
252
|
+
refuses a session whose rows share one.
|
|
253
|
+
|
|
254
|
+
That is what makes two sessions composable. A constant or process-global prefix made two
|
|
255
|
+
independent sessions mint the same keys, so merging or syncing their rows attached one device's
|
|
256
|
+
value to the other's row; a host-chosen source makes each session's ids its own, and the manifest
|
|
257
|
+
— not the array position — is what reattaches a value to a row (`[IDENT-3.1.2]`). Carry each
|
|
258
|
+
array's manifest through a merge or sync and match rows by those ids, never by index; independent
|
|
259
|
+
records need distinct ids.
|
|
260
|
+
|
|
261
|
+
Two renders of one record do have to agree, or the hydrated page disagrees with the server's
|
|
262
|
+
markup and the same input seals a different `reportHash`. Build `seededIdFactory(seed)` on the
|
|
263
|
+
server and again on the client over the same seed for that: the ids are a function of the seed and
|
|
264
|
+
the ordinal alone. Create the client factory in the render that uses it, as above; StrictMode may
|
|
265
|
+
discard an opening render after a stateful factory shared across those mount attempts has advanced.
|
|
266
|
+
|
|
267
|
+
A resumed draft replays the manifest it was saved with as `rowManifest`, so its rows keep the keys
|
|
268
|
+
— and the `reportHash` — they had when it was written. Replay spends no factory ids: the supplied
|
|
269
|
+
factory must continue or change the sequence for future rows, not restart a seed that already
|
|
270
|
+
minted ids in that manifest.
|
|
271
|
+
|
|
272
|
+
## Buffered text and the parse/print contract
|
|
273
|
+
|
|
274
|
+
`useBufferedInput` owns the one text↔value contract. A control passes through text the wire cannot
|
|
275
|
+
hold — `12.`, `-`, `+`, `2026-03` — so the text is never the value: a complete entry is parsed and
|
|
276
|
+
written canonically, a partial one is kept as text, and a refused one carries a stable
|
|
277
|
+
`parseError` reason key and `parseErrorParams`, which the host translates through its own
|
|
278
|
+
catalogue. The committed wire value stays authoritative: an external update resyncs the text only
|
|
279
|
+
while the buffer was clean, and a dirty buffer is never clobbered. `dirty` compares the parsed value
|
|
280
|
+
with the committed one, so `1,200.00` typed over `1200` is clean while still showing as typed.
|
|
281
|
+
|
|
282
|
+
The formats are `decimal`, `integer`, `money`, `phone` and `date`. `money` takes its `(currency,
|
|
283
|
+
scale)` from the field declaration, which is mandatory, so a host supplies no per-field format and
|
|
284
|
+
two currencies cannot share a parser. `phone` is E.164 and `date` a civil `YYYY-MM-DD`; a spelled
|
|
285
|
+
date no civil day carries is refused rather than stored.
|
|
286
|
+
|
|
287
|
+
```tsx
|
|
288
|
+
const input = useBufferedInput('f_amount', { kind: 'money' });
|
|
289
|
+
<input
|
|
290
|
+
value={input.text}
|
|
291
|
+
onChange={(event) => input.setText(event.target.value)}
|
|
292
|
+
onKeyDown={(event) => {
|
|
293
|
+
if (event.key === 'Enter') input.commit();
|
|
294
|
+
}}
|
|
295
|
+
onBlur={input.onBlur}
|
|
296
|
+
/>;
|
|
297
|
+
{
|
|
298
|
+
input.parseError === undefined ? null : (
|
|
299
|
+
<p role="alert">{translate(input.parseError, input.parseErrorParams)}</p>
|
|
300
|
+
);
|
|
301
|
+
}
|
|
302
|
+
```
|
|
303
|
+
|
|
304
|
+
`input.onBlur` commits the entry and then records the visit, so `showErrors: 'touched'`
|
|
305
|
+
reveals the failure this control already holds. `input.commit` is Enter's answer:
|
|
306
|
+
it writes a complete entry without marking the binding touched.
|
|
307
|
+
|
|
308
|
+
## Option domains
|
|
309
|
+
|
|
310
|
+
A field declaring `optionSource: { kind: 'field', fieldId }` takes its domain from another field's
|
|
311
|
+
recorded array — the "name three things, then rank them" form. Eligibility follows the same rule
|
|
312
|
+
without a loader: the array is read as the access answer delivers it, so a source the device may not
|
|
313
|
+
read decides nothing, and a cleared list refuses every non-empty selection. The refusal surfaces once,
|
|
314
|
+
as the field's or row's `invalidValue`; the chosen value is left in the record.
|
|
315
|
+
|
|
316
|
+
A field declaring `optionSource: { kind: 'host', sourceId, dependsOn? }` names a loader the provider
|
|
317
|
+
registers in `optionSources`, keyed by `sourceId`. The loader is host code acting for the current
|
|
318
|
+
principal: the engine keys each request by the source, the resolved `dependsOn` values, the binding's
|
|
319
|
+
row identity, the session `recordDate` and the access version, and it does not filter what the API
|
|
320
|
+
returns — **the API must return only the options this principal may select** (`[ACCESS-7.1.1]`). A
|
|
321
|
+
change to any member of that basis starts exactly one load through the same path a manual `reload`
|
|
322
|
+
uses; editing one row's dependency loads that row and no sibling, and a reorder loads nothing.
|
|
323
|
+
|
|
324
|
+
`list.search(text)` publishes a combobox reader's query at the edit, dropping the previous matches
|
|
325
|
+
and aborting their request. The request carries the text trimmed and capped at 200 code points,
|
|
326
|
+
and the loader is called once it has settled for 250 ms. Supply the host's clock as `defer` on
|
|
327
|
+
`FormProvider` (`browserDefer` from `@azx-pbc/axiom-web` in a browser); a search without it is
|
|
328
|
+
refused before the pages move or a loader is called. `offered` retains the domain evidence across
|
|
329
|
+
queries, so narrowing the painted matches does not make the held value ineligible.
|
|
330
|
+
|
|
331
|
+
Staleness has one answer: `begin()` on a binding's cancellation port cancels the previous request
|
|
332
|
+
before it hands out the next signal, and a response that arrives after a newer request began — or
|
|
333
|
+
after unmount — commits nothing on either the resolve or the reject arm. `cancellation` supplies the
|
|
334
|
+
port factory if the host has its own primitive; the default is structural and needs nothing.
|
|
335
|
+
|
|
336
|
+
Eligibility is not the hook's answer. The session derives it once from the selected value and the
|
|
337
|
+
loaded domain and reports it as the field's or row's `invalidValue` (an `invalid-value` error), so a
|
|
338
|
+
selection the loader no longer offers is visible and **not wiped** (`[DATA-5.1.3]`). The binding
|
|
339
|
+
renders the items and the honest error; the host decides whether to clear the value.
|
|
340
|
+
|
|
341
|
+
## Layout, gates and steps
|
|
342
|
+
|
|
343
|
+
`useLayout()` returns the presentation channel's chrome: sections, steps, callouts and summary cards
|
|
344
|
+
with their messages, parameters and readouts. The array is identity-stable across an edit that moves
|
|
345
|
+
no visibility, message or readout, so the chrome around a form does not re-render on every keystroke.
|
|
346
|
+
`useLayoutNode(nodeId)` and `useSection(sectionId)` return a `LayoutSlice` for one node — `visible`,
|
|
347
|
+
`access` (the meet of its member fields' resolved answers), the resolved `text`, `readouts`, and the
|
|
348
|
+
visible blocking `errorCount` a collapsed accordion badge shows. A node or section the artifact does
|
|
349
|
+
not declare throws rather than rendering nothing.
|
|
350
|
+
|
|
351
|
+
`useGate(gateId?)` reads the primary gate when none is named and `undefined` when the artifact
|
|
352
|
+
declares no gate at all. The verdict is the derived state's own fold, so a badge and a submission
|
|
353
|
+
cannot disagree; `open` is a display convenience, never an authorisation.
|
|
354
|
+
|
|
355
|
+
`useWizard(initialStepId?)` reads one session-scoped cursor owned by `FormProvider`, changing it
|
|
356
|
+
only through the returned `setStepId` (which `next` and `previous` use). Every `useWizard()` caller
|
|
357
|
+
under the same provider shares one current step, one visited history and one checkpoint answer, so a
|
|
358
|
+
header and a footer that both call `useWizard()` stay in sync and a move from one moves both. The
|
|
359
|
+
first declared `initialStepId` seeds that shared cursor before any move places it; once seeded or
|
|
360
|
+
moved, later callers share the cursor as it stands. `visibleStepIds` drops hidden steps, and the
|
|
361
|
+
pure `nextVisibleStepId`/`previousVisibleStepId` answer where a move lands without moving anything: a
|
|
362
|
+
hidden middle step is skipped in both directions. `useStep(stepId)` states one step's visibility,
|
|
363
|
+
authored index and gate.
|
|
364
|
+
|
|
365
|
+
## Messages and the format-value port
|
|
366
|
+
|
|
367
|
+
`useMessage(key, params?)` and `useFormatMessage(locale?, formatValue?)` render the artifact's compiled
|
|
368
|
+
ICU MF1 messages through the runtime's own formatter, which carries its CLDR cardinal data: no host
|
|
369
|
+
locale database is read, so the same record renders the same text on Node, in a browser and on a
|
|
370
|
+
device whose ICU data differs or is absent. The locale is the resolved catalogue key, never the
|
|
371
|
+
requested tag. `useFormatMessage` also labels host data — an option loader's `labelKey`, for
|
|
372
|
+
example — so a key the catalogue does not declare renders as the key instead of throwing; one
|
|
373
|
+
unknown key a server returned must not crash the render. `useMessage` stays strict, because it is
|
|
374
|
+
only ever handed a key the artifact itself declared.
|
|
375
|
+
|
|
376
|
+
Canonical scalars interpolate as they are. A value whose wire spelling is not display text — a money
|
|
377
|
+
amount, a date, an instant, a `timeslot`, a percentage — is formatted by the host:
|
|
378
|
+
`formatValue(name, value, descriptor)` returns the text, or `undefined` for a kind this host does not
|
|
379
|
+
format, in which case the message falls back to its key rather than shipping an ISO date or a
|
|
380
|
+
minor-unit amount as prose. Wrap a date, instant or percentage so its meaning travels with it:
|
|
381
|
+
|
|
382
|
+
```tsx
|
|
383
|
+
const format = useFormatMessage('en', (name, value, kind) =>
|
|
384
|
+
kind === 'date' ? formatDate(String(value)) : kind === 'money' ? formatMoney(value) : undefined,
|
|
385
|
+
);
|
|
386
|
+
format('record.due', { when: { value: '2026-03-01', descriptor: 'date' } });
|
|
387
|
+
```
|
|
388
|
+
|
|
389
|
+
`useFormState().dirtyFields` names every binding whose _record_ value moved from the session's
|
|
390
|
+
baseline, so editing one row of an array also names that row's binding and the container it belongs
|
|
391
|
+
to. The baseline is what the record held when the session opened, not what access delivered: a
|
|
392
|
+
`masked`, `hidden` or server-redacted value that becomes readable is not an edit, and neither is a
|
|
393
|
+
computed value. `initialValue` is the baseline as this device may read it, so it is `undefined` where
|
|
394
|
+
the access answer withholds the stored value. A binding whose value this device may no longer read
|
|
395
|
+
reports `dirty: false` — it cannot compare a value it cannot see, and the projection would not carry
|
|
396
|
+
it either.
|
|
397
|
+
|
|
398
|
+
Access comes from one of two first-class shapes, never both: the host's 4-level `overlay`
|
|
399
|
+
(`{ accessVersion, defaultAccess, allowMaskedRead?, rules[] }`), which the runtime resolves, or the
|
|
400
|
+
flattened `access` projection from a host that has already resolved access per reference.
|
|
401
|
+
`FormProviderProps` is a union over those two shapes, so supplying both is a TypeScript error; a
|
|
402
|
+
JavaScript caller that supplies both still throws `AccessSourceError`
|
|
403
|
+
(`code: 'ACCESS_SOURCE_INVALID'`), because one could be the stale answer. An unmentioned field
|
|
404
|
+
resolves to the fail-closed `read_only`.
|
|
405
|
+
|
|
406
|
+
`showErrors` (`'touched' | 'always' | 'submit'`, default `'touched'`) decides when a control
|
|
407
|
+
_reveals_ a failure it already evaluated; evaluation stays live under every policy. It is the
|
|
408
|
+
display policy, not React Hook Form's `mode`: there is no evaluation mode and no
|
|
409
|
+
`reValidateMode`, because every pass evaluates. `touched` reveals it once the binding was
|
|
410
|
+
visited — a blur or a deliberate write — `always` on the first pass, and `submit` once a submit
|
|
411
|
+
was attempted, so an untouched control is never announced invalid merely because the record it
|
|
412
|
+
opened with failed
|
|
413
|
+
a rule. A write the session refused (`errors` naming `row-key`) is shown immediately under every
|
|
414
|
+
rule: it answers something the user just did rather than a rule that decided on its own. The
|
|
415
|
+
[parity table](#react-hook-form-parity) states this beside the React Hook Form answer.
|
|
416
|
+
|
|
417
|
+
`ready` and the failure lists answer different questions. `ready` is the runtime's readiness: a
|
|
418
|
+
`required` rule the device cannot settle (`undetermined`, including a value the server withheld as
|
|
419
|
+
`redacted`) leaves it false. `errors`, `isValid` and `missingRequiredFields` state only decided
|
|
420
|
+
failures: a `required` error and a `missingRequiredFields` entry exist only for `missing`, so a
|
|
421
|
+
redacted but writable field is not accused of a failure the user did not cause and still shows as
|
|
422
|
+
editable. The `access` error is likewise about the resolved access (`masked`, `hidden`,
|
|
423
|
+
`write_only`) and never about a `redacted` value.
|
|
424
|
+
|
|
425
|
+
`maskedDisplay` is the host's text beside a `masked` value, keyed by `fieldId`; it is never
|
|
426
|
+
derived from the value or its length. `valueDisplay` is the host's locale text for a boolean, a
|
|
427
|
+
list or any other value whose canonical spelling is not display text.
|
|
428
|
+
|
|
429
|
+
A control bound to one row of an array passes the row's wire-typed key:
|
|
430
|
+
`useField('f_row_value', 'row_1')`. The integer row `1` and the text row `"1"` are two bindings
|
|
431
|
+
(`[IDENT-4.1.3]`); a field declared inside an array needs a row key, and one that holds no rows
|
|
432
|
+
refuses one.
|
|
433
|
+
|
|
434
|
+
`handleSubmit(onValid, onInvalid?)` performs the submit and returns the `Promise<void>` that
|
|
435
|
+
settles when it finishes: `void form.handleSubmit(save)` in an event handler, or `await` it in
|
|
436
|
+
async code. It coalesces a submission already in flight, touches only the bindings that block,
|
|
437
|
+
gates on the engine's `verdict`, and hands `onValid` the `onHide: "exclude"` projection of
|
|
438
|
+
committed state. A signature covering a withheld value refuses that projection
|
|
439
|
+
(`SIGNATURE_COVER_EXCLUDED`) and the returned promise rejects with `isSubmitting` cleared. A
|
|
440
|
+
verdict that is not `SUBMIT` runs `onInvalid(errors, blockers)` instead: `BLOCKED` names every
|
|
441
|
+
decided reason, while `UNDETERMINED` has none to name and states the open question in
|
|
442
|
+
`useFormState().undeterminedChecks`.
|
|
443
|
+
|
|
444
|
+
The deprecated `submitHandler(onValid, onInvalid?)` returns the same call as a thunk
|
|
445
|
+
(`() => Promise<void>`) for a handler that must be passed where an event callback is expected.
|
|
446
|
+
Prefer the promise form in new code.
|
|
447
|
+
|
|
448
|
+
## React Hook Form parity
|
|
449
|
+
|
|
450
|
+
Axiom is offered as a React Hook Form-class form layer, so the behaviours a team brings from
|
|
451
|
+
`react-hook-form` are stated here rather than left to be discovered. "Matches" means the behaviour
|
|
452
|
+
is present with the same meaning under Axiom's name; "diverges" means it is deliberately different,
|
|
453
|
+
and the reason follows the table.
|
|
454
|
+
|
|
455
|
+
| Behaviour | Axiom | `react-hook-form` | Verdict |
|
|
456
|
+
| --------------------------------- | ------------------------------------------------------------------------------------------------------------------------------ | ------------------------------------------------------------------------------------ | --------------------------------------------------------------------- |
|
|
457
|
+
| Validation modes | `showErrors`: `touched` (default), `always`, `submit`. Evaluation is live under every policy. | `mode` / `reValidateMode` decide when validation _runs_. | Diverges: reveal-only policy, no evaluation mode. |
|
|
458
|
+
| Per-field errors | `useField().errors`: a tagged array (`kind`, `messageKey`, `status`, `blocking`). | `errors.field`: `{ type, message }`. | Diverges: tagged reasons, host translates the key. |
|
|
459
|
+
| Summary errors | `useFormState().errors`: the form-level blocking list, including screen reasons. | `formState.errors`: every field's error. | Diverges: per-binding errors stay on the binding. |
|
|
460
|
+
| `isDirty` / `dirtyFields` | Same meaning; `dirtyFields` is a `bindingKey[]` in declaration order. | `dirtyFields` is a nested object keyed by name. | Matches, with an array shape. |
|
|
461
|
+
| `touchedFields` | Same meaning; a `bindingKey[]`; a blur on a binding no user write reaches is a no-op. | Nested object keyed by name. | Matches, with an array shape. |
|
|
462
|
+
| `isValid` | No decided blocking field error and no blocking gate. Deliberately narrower than `verdict`. | No errors from the last validation. | Diverges: read `verdict` to gate a submission. |
|
|
463
|
+
| `isSubmitted` / `submitCount` | Same meaning: whether a submit was attempted, and how many. | Same. | Matches. |
|
|
464
|
+
| `isSubmitting` | True while a submission is in flight; a second call coalesces rather than starting one. | Same. | Matches. |
|
|
465
|
+
| `isSubmitSuccessful` | True when the last attempt reached `onValid` and it returned; cleared by the next attempt and by `reset()`. | Same. | Matches. |
|
|
466
|
+
| `reset()` / `reset(values)` | Restores the opening record, or re-baselines from `values`; clears touched, dirty, submit counters and errors; never submits. | Same, plus `keep*` options. | Matches, without `keep*`. |
|
|
467
|
+
| `getValues()` | The committed record, copied: includes hidden and `write_only` values. `exportSubmission()` is the projection to send. | The current values. | Matches, with one record per session. |
|
|
468
|
+
| `setValue` | Evaluates live, marks dirty by comparing to the baseline, never touches. The control throws a refusal; the handle returns one. | `shouldValidate` / `shouldDirty` / `shouldTouch` flags. | Diverges: one behaviour, no flags. |
|
|
469
|
+
| `handleSubmit(onValid,onInvalid)` | `onValid` only on `SUBMIT`; `onInvalid` names the blockers; in-flight coalesced; returns a `Promise<void>`. | Returns an event handler. | Diverges: await the promise; `submitHandler` keeps the handler shape. |
|
|
470
|
+
| `onInvalid` on an undecided form | Called with empty lists; the open question is `undeterminedChecks`. | Not reached by an async check that has not settled. | Diverges: `verdict` and `undeterminedChecks` carry it. |
|
|
471
|
+
| Focus first error / `setFocus` | No focus API and no DOM. `firstErrorBindingKey` names the binding; `a11y.controlId` is the element to focus. | `setFocus(name)` and focus-on-failed-submit. | Diverges: the host focuses; the binding names the target. |
|
|
472
|
+
| Arrays | `append`, `insert`, `remove(rowKey)`, `move`, `moveRow`, `replace`. Row identity survives a move; errors stay with the row. | `append`, `prepend`, `insert`, `remove(index)`, `swap`, `move`, `replace`, `update`. | Matches, minus three composites. |
|
|
473
|
+
| Deferred server check | A `deferred` error (`status: "DEFERRED"`, non-blocking) plus `hasDeferredChecks`; `a11y.busy` only while submitting. | An async validator the form awaits before `onValid`. | Diverges: the submission is the handoff, not a client wait. |
|
|
474
|
+
|
|
475
|
+
The reasons the model does not support a closer match:
|
|
476
|
+
|
|
477
|
+
- **`handleSubmit` returns the submission promise.** React Hook Form's `handleSubmit` returns an
|
|
478
|
+
event handler. Axiom returns the `Promise<void>` so a caller can await the transport it started,
|
|
479
|
+
and a handler that must be passed directly to `onSubmit` uses the deprecated `submitHandler`
|
|
480
|
+
alias for the thunk shape.
|
|
481
|
+
- **Validation modes are display, not evaluation.** The runtime derives the whole record on every
|
|
482
|
+
pass, so `invalid` and `isValid` are always current; a mode that suppressed evaluation would
|
|
483
|
+
throw that away and require a second validation engine in React. `showErrors` therefore
|
|
484
|
+
names only when a decided failure is _shown_.
|
|
485
|
+
- **Errors are tagged reasons, not `{ type, message }`.** A `validate` failure carries the
|
|
486
|
+
artifact's `messageKey` and `status`, a missing value names its binding, a gate item names the
|
|
487
|
+
gate, and a screen names the screen. There is no single `type`/`message` pair that can hold
|
|
488
|
+
those, and the library ships no words: the host translates the key.
|
|
489
|
+
- **`isValid` is not the submission gate.** A record-scope rule or an undecidable check can leave
|
|
490
|
+
`isValid` true while `verdict` is `BLOCKED` or `UNDETERMINED`. One verdict folds the report, the
|
|
491
|
+
gates and local readiness; making `isValid` a second copy of it would lose the distinction
|
|
492
|
+
between "nothing a control shows is wrong" and "this record may be submitted".
|
|
493
|
+
- **`setValue` has one behaviour.** The value is evaluated on the next pass whatever the caller
|
|
494
|
+
intended, dirty is a comparison against the record's baseline rather than a flag, and a write is
|
|
495
|
+
not a visit. Flags that suppress those would let a control render a state the record does not
|
|
496
|
+
hold. The control and the handle agree: both evaluate, both mark dirty when the value moves,
|
|
497
|
+
both reveal under `onChange`, and neither touches.
|
|
498
|
+
- **No `setFocus` and no focus-first-error.** The package renders no elements and is used on React
|
|
499
|
+
Native and Hermes as well as the web, so it cannot own a focus call. `useFormState()` names the
|
|
500
|
+
first visible binding with a blocking error (`firstErrorBindingKey`) and each binding states
|
|
501
|
+
`a11y.controlId`; a host focuses it after a failed submit. That binding is visible by
|
|
502
|
+
construction; it may be disabled by a failed `enabled` rule, and Axiom reports the blocker
|
|
503
|
+
rather than hiding it — an artifact that requires a value it also disables is a design error the
|
|
504
|
+
user cannot repair.
|
|
505
|
+
- **Arrays are identity-addressed.** `remove` names a row's key rather than its index, because a
|
|
506
|
+
key is what survives a reorder. `prepend` is `insert(0, value)`, `swap` is two `move` calls, and
|
|
507
|
+
`update(index, value)` is `remove` + `insert`; each composition keeps the identity rule visible
|
|
508
|
+
instead of adding a fourth way to name a position. `replace` is present.
|
|
509
|
+
- **A deferred check is a handoff, not a client wait.** A `server`-tier rule is reported as
|
|
510
|
+
`deferred`, the summary sets `hasDeferredChecks`, and the submission carries the open question
|
|
511
|
+
to the server, which decides again. The client never claims it passed: the binding's `errors`
|
|
512
|
+
keeps the `deferred` entry and `a11y.busy` is true only while a submission that may settle it is
|
|
513
|
+
in flight. An undecidable _requirement_ is the stronger case — `verdict` is `UNDETERMINED` and
|
|
514
|
+
`onValid` does not run.
|
|
515
|
+
|
|
516
|
+
## Text direction
|
|
517
|
+
|
|
518
|
+
`useDirection(locale?)` returns `'ltr' | 'rtl'` for the locale the form renders. It resolves the
|
|
519
|
+
request through the artifact's catalogue exactly as `useFormatMessage` does — an undeclared locale
|
|
520
|
+
falls back to the document default, and a single-locale artifact answers its one locale — then asks
|
|
521
|
+
the runtime's vendored CLDR script map (`directionOf`). The map is script-first: `ar` and `he` are
|
|
522
|
+
right-to-left, `ar-Latn` and `sd-Deva` are left-to-right, and `en-Arab` is right-to-left. No
|
|
523
|
+
`Intl` is read, so the answer is the same on Node, a browser and Hermes.
|
|
524
|
+
|
|
525
|
+
The host paints the answer; the library does not mutate the document. Put `dir` and `lang` on the
|
|
526
|
+
element that holds the text, and switch them with the same locale value the messages use:
|
|
527
|
+
|
|
528
|
+
```tsx
|
|
529
|
+
const direction = useDirection(locale);
|
|
530
|
+
return (
|
|
531
|
+
<section dir={direction} lang={locale}>
|
|
532
|
+
<RenderedForm />
|
|
533
|
+
</section>
|
|
534
|
+
);
|
|
535
|
+
```
|
|
536
|
+
|
|
537
|
+
Changing `locale` re-renders that wrapper; the `FormProvider` session and its values are not
|
|
538
|
+
remounted. A page with two forms in different directions therefore needs no document-level `dir`.
|
|
539
|
+
|
|
540
|
+
## The bindings are not a security boundary
|
|
541
|
+
|
|
542
|
+
The bindings — and the `overlay`/`access`, `redacted`, `sessionWrites` and `maskedDisplay` props —
|
|
543
|
+
only reflect an access decision the host already made. A principal can read everything the device
|
|
544
|
+
holds and submit anything it chooses, so `visible`, `readOnly`, `disabled`, `setValue`'s refusals
|
|
545
|
+
and `WriteRefusedError` are **UI consistency and presentation**, never protection or enforcement.
|
|
546
|
+
`useFormState().ready` is a client readiness answer, never a submission authorisation: the server
|
|
547
|
+
decides again. Redact on read and authorise on write in the API (`[ACCESS-7.1.1]`–`[ACCESS-7.1.6]`).
|
|
548
|
+
|
|
549
|
+
## Errors and limits
|
|
550
|
+
|
|
551
|
+
Refusals throw, never silently pass:
|
|
552
|
+
|
|
553
|
+
- A hook called outside a `FormProvider` throws; an unknown `fieldId` throws; a field declared
|
|
554
|
+
inside a record array needs a row key, and a field that holds no rows refuses one. The
|
|
555
|
+
declaration cannot check which field a binding names — the artifact is runtime data — so a row
|
|
556
|
+
key on a scalar field is a runtime refusal, not a compile error.
|
|
557
|
+
- A provider mounted with a different `compiled` artifact than the session's throws; mount a new
|
|
558
|
+
provider instead.
|
|
559
|
+
- `field.setValue` throws `WriteRefusedError` carrying the runtime's write code — `ACCESS_DENIED`
|
|
560
|
+
(including every `user` write to a `signature_ref`), `DISABLED`, `ROW_UNADDRESSABLE` or
|
|
561
|
+
`INVALID_VALUE`. `INVALID_VALUE` is a value the wire contract cannot carry (for example a number
|
|
562
|
+
where a decimal string is declared, or the half-typed decimal `"1."`); the boundary parse that
|
|
563
|
+
refused it is the error's `cause`, so the path survives the translation. Use `useBufferedInput`
|
|
564
|
+
for a text control whose keystrokes pass through such spellings; a control that calls `setValue`
|
|
565
|
+
directly must hold its own draft. A write that would give two rows one identity is the exception:
|
|
566
|
+
the record never takes it, so `setValue` returns without throwing and the binding reports a
|
|
567
|
+
non-blocking `row-key` error with `showError` and `a11y.invalid` set, which the next accepted
|
|
568
|
+
write, a structural change to its array, or a reset clears.
|
|
569
|
+
- `useAsyncOptions` on a field that declares no `host` source throws; so does `useFieldArray` on a
|
|
570
|
+
field that holds no rows, and `useLayoutNode`/`useSection` on an id the layout does not declare.
|
|
571
|
+
- `useStep` on a step id the artifact does not declare answers `{ visible: false, index: -1 }`
|
|
572
|
+
rather than throwing: a host may render a step list against an artifact that predates one step,
|
|
573
|
+
and hiding it is the safe answer.
|
|
574
|
+
- `useWizard().setStepId` on a step the artifact does not declare throws; a declared-but-hidden
|
|
575
|
+
step is accepted and the published cursor reconciles to the nearest visible step, so a host
|
|
576
|
+
never renders a blank page.
|
|
577
|
+
- An option loader that resolves a malformed page (no `items` array, an item without a `labelKey`, a
|
|
578
|
+
`nextCursor` that is neither string nor `null`) surfaces an `error` on the page list rather than
|
|
579
|
+
loading nothing silently.
|
|
580
|
+
- The handle's own `setValue`/`setNull`/`removeValue`/`batch` return the engine's tagged outcome
|
|
581
|
+
instead of throwing, for a host that branches on a refusal.
|
|
582
|
+
|
|
583
|
+
Access is fail-closed: a field the access source does not mention resolves to `read_only`, so a form
|
|
584
|
+
meant to be editable must say so.
|
|
585
|
+
|
|
586
|
+
## Environment
|
|
587
|
+
|
|
588
|
+
React 19 only. The package publishes `react-native`, `browser` and default export conditions and
|
|
589
|
+
implements `getServerSnapshot`, so it also renders during server rendering. It deliberately does
|
|
590
|
+
not depend on `react-dom` or `react-native`, does not use the DOM, and does not import the
|
|
591
|
+
compiler: the build is compiler → runtime ← react.
|
|
592
|
+
|
|
593
|
+
The hooks are written for the React Compiler: render is pure, props and state are not mutated, refs
|
|
594
|
+
are not read or written during render, and no component or hook is created during render. Oxlint
|
|
595
|
+
reports the compiler's own validation rules as errors, and both the Web and Expo examples build
|
|
596
|
+
with the compiler enabled, so the package is proven eligible for automatic memoisation rather than
|
|
597
|
+
merely free of `useMemo`.
|
|
598
|
+
|
|
599
|
+
## Links
|
|
600
|
+
|
|
601
|
+
- [Root README](https://github.com/AZX-PBC-OSS/axiom/blob/main/README.md)
|
|
602
|
+
- [Access semantics](https://github.com/AZX-PBC-OSS/axiom/blob/main/spec/semantics/access-v1.md), [rules](https://github.com/AZX-PBC-OSS/axiom/blob/main/spec/semantics/rules-v1.md)
|
|
603
|
+
and [the session contract](https://github.com/AZX-PBC-OSS/axiom/blob/main/spec/semantics/engine-v1.md)
|
|
604
|
+
- [Web example](https://github.com/AZX-PBC-OSS/axiom/tree/main/examples/web) — the generic renderer over the committed CLI-compiled fixtures
|
|
605
|
+
- [React Native example](https://github.com/AZX-PBC-OSS/axiom/tree/main/examples/mobile-rn-expo)
|