@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.
- 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
|
@@ -0,0 +1,303 @@
|
|
|
1
|
+
import type { CompiledField, Control, LayoutNodeView, LayoutTone, WireValue } from '@azx-pbc/axiom-runtime';
|
|
2
|
+
import type { InputHints } from '../hints.js';
|
|
3
|
+
/**
|
|
4
|
+
* The host-neutral render tree: one layout walked into the nodes a host paints.
|
|
5
|
+
*
|
|
6
|
+
* The tree is a total function of the closed layout and control unions. A node states what it
|
|
7
|
+
* is — a section, a container, a control, an error — and never which document it came from, so
|
|
8
|
+
* one renderer paints any artifact and a host's adapter chooses markup, not structure. Text is
|
|
9
|
+
* resolved before the tree is built: the caller passes the message formatter for the locale it
|
|
10
|
+
* renders, so a locale switch re-translates the chrome without recompiling the artifact.
|
|
11
|
+
*
|
|
12
|
+
* Field leaves name their binding (`fieldId`, `rowKey`) because a control must bind to a
|
|
13
|
+
* session; the adapter reads that binding with `useField` and never compares the identifier to
|
|
14
|
+
* anything. Everything the tree exposes is derived from the declarations the layout places.
|
|
15
|
+
*/
|
|
16
|
+
/** Resolves one compiled message key for the locale being rendered. */
|
|
17
|
+
export type RenderTranslate = (key: string, params?: Readonly<Record<string, WireValue>>) => string;
|
|
18
|
+
/** One heading level a host may paint; the layout's depth decides it. */
|
|
19
|
+
export type RenderHeadingLevel = 2 | 3 | 4 | 5 | 6;
|
|
20
|
+
/** One read-only label/value pair a summary card shows. */
|
|
21
|
+
export interface RenderReadout {
|
|
22
|
+
readonly label: string;
|
|
23
|
+
/** The value the presentation channel decided, or absent when it could not decide one. */
|
|
24
|
+
readonly value?: WireValue;
|
|
25
|
+
}
|
|
26
|
+
/**
|
|
27
|
+
* One control leaf, or one member of a record container.
|
|
28
|
+
*
|
|
29
|
+
* The declaration travels whole because a control needs its options, its items, its signature
|
|
30
|
+
* coverage and a money amount's own domain to be rendered at all.
|
|
31
|
+
*/
|
|
32
|
+
export interface RenderControlNode {
|
|
33
|
+
readonly kind: 'field';
|
|
34
|
+
readonly nodeId: string;
|
|
35
|
+
readonly fieldId: string;
|
|
36
|
+
readonly control: Control;
|
|
37
|
+
readonly declaration: CompiledField;
|
|
38
|
+
readonly label: string;
|
|
39
|
+
readonly description?: string;
|
|
40
|
+
readonly placeholder?: string;
|
|
41
|
+
/** How many of its parent's columns the control spans. */
|
|
42
|
+
readonly colSpan: number;
|
|
43
|
+
readonly hints: InputHints;
|
|
44
|
+
}
|
|
45
|
+
/** A repeating record: the container's facts plus one control or container per declared member. */
|
|
46
|
+
export interface RenderRecordsNode {
|
|
47
|
+
readonly kind: 'records';
|
|
48
|
+
readonly nodeId: string;
|
|
49
|
+
readonly fieldId: string;
|
|
50
|
+
readonly label: string;
|
|
51
|
+
readonly description?: string;
|
|
52
|
+
readonly colSpan: number;
|
|
53
|
+
readonly members: readonly RenderMemberNode[];
|
|
54
|
+
/**
|
|
55
|
+
* The member that names a natural row, absent when the host assigns row keys.
|
|
56
|
+
*
|
|
57
|
+
* An adapter that offers "add row" needs it: the value a new row starts from must carry the
|
|
58
|
+
* identity the record already keys by, and the host is the only layer that can write one.
|
|
59
|
+
*/
|
|
60
|
+
readonly naturalKey?: string;
|
|
61
|
+
}
|
|
62
|
+
/**
|
|
63
|
+
* One non-repeating record placed as a group: the record's label and its members' controls.
|
|
64
|
+
*
|
|
65
|
+
* A single record has exactly one instance, so nothing about the array machinery applies: there
|
|
66
|
+
* is no row key, no add or remove, and no per-row binding. Each member is a control bound by its
|
|
67
|
+
* own declared `fieldId` — the identifier the reader already resolves for an expression member
|
|
68
|
+
* path such as `f_vehicle.f_vin` — so its value lives inside the container's value without a
|
|
69
|
+
* second spelling. The record's own `visible` rule and access answer reach its members through
|
|
70
|
+
* the same visibility index a rule reads, so a placement that hides the record paints none of
|
|
71
|
+
* them; its `onHide` policy decides the submission as it does for any hidden container.
|
|
72
|
+
*/
|
|
73
|
+
export interface RenderRecordNode {
|
|
74
|
+
readonly kind: 'record';
|
|
75
|
+
readonly nodeId: string;
|
|
76
|
+
readonly fieldId: string;
|
|
77
|
+
readonly label: string;
|
|
78
|
+
readonly description?: string;
|
|
79
|
+
readonly colSpan: number;
|
|
80
|
+
readonly members: readonly RenderMemberNode[];
|
|
81
|
+
}
|
|
82
|
+
/**
|
|
83
|
+
* One member of a record or record array: a control, or a container that is itself a member.
|
|
84
|
+
*
|
|
85
|
+
* A container member is not a tree node placed by the layout; it is a declared member whose
|
|
86
|
+
* value lives inside its parent's value. It carries the same node kinds a placed container does,
|
|
87
|
+
* so an adapter recurses into it instead of refusing a document the compiler admitted.
|
|
88
|
+
*/
|
|
89
|
+
type RenderMemberNode = RenderControlNode | RenderRecordNode | RenderRecordsNode;
|
|
90
|
+
interface RenderContainerBase {
|
|
91
|
+
readonly nodeId: string;
|
|
92
|
+
readonly sectionId?: string;
|
|
93
|
+
readonly description?: string;
|
|
94
|
+
readonly level: RenderHeadingLevel;
|
|
95
|
+
readonly children: readonly RenderNode[];
|
|
96
|
+
}
|
|
97
|
+
/** A titled section: the layout's top-level container, or one nested inside another. */
|
|
98
|
+
export interface RenderSectionNode extends RenderContainerBase {
|
|
99
|
+
readonly kind: 'section';
|
|
100
|
+
readonly title: string;
|
|
101
|
+
readonly columns: number;
|
|
102
|
+
readonly collapsible: boolean;
|
|
103
|
+
readonly defaultExpanded?: boolean;
|
|
104
|
+
}
|
|
105
|
+
/**
|
|
106
|
+
* A grouping inside a section or step.
|
|
107
|
+
*
|
|
108
|
+
* Its title is optional because a group's `titleKey` is: the metaschema requires one on a
|
|
109
|
+
* section, step, heading, SOP block and summary card, and lets a group state none. A host
|
|
110
|
+
* paints no heading for it then, rather than a heading with no name.
|
|
111
|
+
*/
|
|
112
|
+
export interface RenderGroupNode extends RenderContainerBase {
|
|
113
|
+
readonly kind: 'group';
|
|
114
|
+
readonly title?: string;
|
|
115
|
+
readonly columns: number;
|
|
116
|
+
readonly collapsible: boolean;
|
|
117
|
+
readonly defaultExpanded?: boolean;
|
|
118
|
+
}
|
|
119
|
+
/** One page of a branching flow. The host's wizard cursor decides which one is shown. */
|
|
120
|
+
export interface RenderStepNode extends RenderContainerBase {
|
|
121
|
+
readonly kind: 'step';
|
|
122
|
+
readonly stepId: string;
|
|
123
|
+
readonly title: string;
|
|
124
|
+
readonly columns: number;
|
|
125
|
+
}
|
|
126
|
+
/**
|
|
127
|
+
* The flow that holds the steps; at most one is declared, at the top level.
|
|
128
|
+
*
|
|
129
|
+
* The host owns the cursor, so the tree states it: `currentStepId` is the step the caller named
|
|
130
|
+
* in `RenderLayoutInput.stepId`, and `children` then holds that step alone. Without a named step
|
|
131
|
+
* the children are every visible step in authored order and `currentStepId` is absent, which is
|
|
132
|
+
* what a host painting its own step list wants.
|
|
133
|
+
*/
|
|
134
|
+
export interface RenderWizardNode {
|
|
135
|
+
readonly kind: 'wizard';
|
|
136
|
+
readonly nodeId: string;
|
|
137
|
+
readonly currentStepId?: string;
|
|
138
|
+
readonly children: readonly RenderStepNode[];
|
|
139
|
+
}
|
|
140
|
+
/** A decorative title with optional supporting text. */
|
|
141
|
+
export interface RenderHeadingNode {
|
|
142
|
+
readonly kind: 'heading';
|
|
143
|
+
readonly nodeId: string;
|
|
144
|
+
readonly level: RenderHeadingLevel;
|
|
145
|
+
readonly title: string;
|
|
146
|
+
readonly body?: string;
|
|
147
|
+
}
|
|
148
|
+
/** Presentation-only emphasis. */
|
|
149
|
+
export interface RenderCalloutNode {
|
|
150
|
+
readonly kind: 'callout';
|
|
151
|
+
readonly nodeId: string;
|
|
152
|
+
readonly tone: LayoutTone;
|
|
153
|
+
readonly title?: string;
|
|
154
|
+
readonly body: string;
|
|
155
|
+
}
|
|
156
|
+
/** A horizontal rule. */
|
|
157
|
+
export interface RenderDividerNode {
|
|
158
|
+
readonly kind: 'divider';
|
|
159
|
+
readonly nodeId: string;
|
|
160
|
+
}
|
|
161
|
+
/** Standard operating procedure text. */
|
|
162
|
+
export interface RenderSopBlockNode {
|
|
163
|
+
readonly kind: 'sop_block';
|
|
164
|
+
readonly nodeId: string;
|
|
165
|
+
/**
|
|
166
|
+
* The heading level the block's title is painted at.
|
|
167
|
+
*
|
|
168
|
+
* The layout walk already knows the depth: a block placed inside a section is one level below
|
|
169
|
+
* it. An adapter that hard-codes a level skips one on every document whose chrome sits at a
|
|
170
|
+
* depth other than the one it guessed (`WCAG 1.3.1`, `2.4.10`), so the tree states it.
|
|
171
|
+
*/
|
|
172
|
+
readonly level: RenderHeadingLevel;
|
|
173
|
+
readonly title: string;
|
|
174
|
+
readonly body?: string;
|
|
175
|
+
}
|
|
176
|
+
/** A read-only summary: decided readouts plus declared fields a host reads live. */
|
|
177
|
+
export interface RenderSummaryCardNode {
|
|
178
|
+
readonly kind: 'summary_card';
|
|
179
|
+
readonly nodeId: string;
|
|
180
|
+
/** The heading level the card's title is painted at, from where the layout placed the card. */
|
|
181
|
+
readonly level: RenderHeadingLevel;
|
|
182
|
+
readonly title: string;
|
|
183
|
+
readonly body?: string;
|
|
184
|
+
readonly readouts: readonly RenderReadout[];
|
|
185
|
+
readonly fields: readonly {
|
|
186
|
+
readonly fieldId: string;
|
|
187
|
+
readonly label: string;
|
|
188
|
+
}[];
|
|
189
|
+
}
|
|
190
|
+
/** One reason a submit is blocked, with the field it names where the artifact names one. */
|
|
191
|
+
export interface RenderErrorItem {
|
|
192
|
+
readonly fieldId?: string;
|
|
193
|
+
readonly label?: string;
|
|
194
|
+
readonly message: string;
|
|
195
|
+
/**
|
|
196
|
+
* The element this item is about, so the announcement can be a set of links to the controls it
|
|
197
|
+
* names rather than a list a reader has to search the page for.
|
|
198
|
+
*
|
|
199
|
+
* An element id, as `field.a11y.controlId` states it: `bindingKey` itself may carry whitespace
|
|
200
|
+
* from a natural row key, so a row-scoped failure passes `fieldDomId(idPrefix, bindingKey)`,
|
|
201
|
+
* and every id carries the session prefix. When the caller names none, the field's control id
|
|
202
|
+
* under `RenderErrorSummaryInput.idPrefix` is used. A reason about the record rather than a
|
|
203
|
+
* field points at the announcement itself, `error_summary`.
|
|
204
|
+
*/
|
|
205
|
+
readonly targetId: string;
|
|
206
|
+
}
|
|
207
|
+
/** The announced summary of every blocking reason, painted above the form. */
|
|
208
|
+
export interface RenderErrorSummaryNode {
|
|
209
|
+
readonly kind: 'error_summary';
|
|
210
|
+
readonly nodeId: string;
|
|
211
|
+
readonly items: readonly RenderErrorItem[];
|
|
212
|
+
}
|
|
213
|
+
/** One node of the host-neutral render tree. */
|
|
214
|
+
export type RenderNode = RenderSectionNode | RenderGroupNode | RenderWizardNode | RenderStepNode | RenderControlNode | RenderRecordsNode | RenderRecordNode | RenderHeadingNode | RenderCalloutNode | RenderDividerNode | RenderSopBlockNode | RenderSummaryCardNode | RenderErrorSummaryNode;
|
|
215
|
+
/** One blocking reason, already resolved to the text this locale renders. */
|
|
216
|
+
export interface RenderErrorInput {
|
|
217
|
+
readonly fieldId?: string;
|
|
218
|
+
/** The element id the item is about; defaults to the field's control id under the session prefix. */
|
|
219
|
+
readonly targetId?: string;
|
|
220
|
+
readonly message: string;
|
|
221
|
+
}
|
|
222
|
+
/** Everything one layout walk reads. */
|
|
223
|
+
export interface RenderLayoutInput {
|
|
224
|
+
readonly layout: readonly LayoutNodeView[];
|
|
225
|
+
readonly fields: readonly CompiledField[];
|
|
226
|
+
readonly translate: RenderTranslate;
|
|
227
|
+
/**
|
|
228
|
+
* The wizard step on the screen, when the host has one.
|
|
229
|
+
*
|
|
230
|
+
* Named, the wizard node carries that step alone and states it in `currentStepId`, so a
|
|
231
|
+
* paint-the-tree adapter needs no lookup of its own. A step the presentation channel hid (or an
|
|
232
|
+
* id the artifact never declared) is ignored rather than emptying the wizard: the caller gets
|
|
233
|
+
* every visible step, which is the safe answer for a cursor that outlived its step.
|
|
234
|
+
*/
|
|
235
|
+
readonly stepId?: string;
|
|
236
|
+
}
|
|
237
|
+
/** Everything the announced error summary is built from. */
|
|
238
|
+
export interface RenderErrorSummaryInput {
|
|
239
|
+
/** The blocking reasons, in the order the session reports them. */
|
|
240
|
+
readonly errors: readonly RenderErrorInput[];
|
|
241
|
+
readonly fields: readonly CompiledField[];
|
|
242
|
+
readonly translate: RenderTranslate;
|
|
243
|
+
/**
|
|
244
|
+
* The prefix the form session's controls use, from `useIdPrefix()`.
|
|
245
|
+
*
|
|
246
|
+
* An item that names a field and no explicit `targetId` is an element id on the page, and the
|
|
247
|
+
* only correct one is the control's own (`field.a11y.controlId`), which begins with this
|
|
248
|
+
* prefix. Passing it is what keeps the announcement pointing inside its own provider: two forms
|
|
249
|
+
* over one artifact declare the same field ids, so a summary built from `fieldId` alone links a
|
|
250
|
+
* reader to the first form's control. A row-scoped reason still supplies its own `targetId`,
|
|
251
|
+
* because the tree does not know the row.
|
|
252
|
+
*/
|
|
253
|
+
readonly idPrefix: string;
|
|
254
|
+
/**
|
|
255
|
+
* The id the summary element itself carries.
|
|
256
|
+
*
|
|
257
|
+
* A reason about the record rather than a field has nowhere else to point, so an item links at
|
|
258
|
+
* this element. A host that renders the summary passes the id it gave that element; without it
|
|
259
|
+
* the item links at `error_summary`, which is the documented default and not an element a host
|
|
260
|
+
* is obliged to create.
|
|
261
|
+
*/
|
|
262
|
+
readonly summaryId?: string;
|
|
263
|
+
}
|
|
264
|
+
/**
|
|
265
|
+
* The announced summary of every blocking reason, or nothing when none blocks.
|
|
266
|
+
*
|
|
267
|
+
* It is built apart from the layout walk, and on purpose: a reason appears and disappears on
|
|
268
|
+
* almost every keystroke, while the tree it sits above is stable. A host renders this beside the
|
|
269
|
+
* tree, so a keystroke that adds a failure re-renders the announcement and not the form.
|
|
270
|
+
*/
|
|
271
|
+
export declare function renderErrorSummary(input: RenderErrorSummaryInput): RenderErrorSummaryNode | undefined;
|
|
272
|
+
/**
|
|
273
|
+
* The first `row_<n>` key the current rows do not already hold.
|
|
274
|
+
*
|
|
275
|
+
* The key is derived from the record rather than from a counter in a component: a wizard unmounts
|
|
276
|
+
* the step it is not painting, so component state starts again at one while the rows it already
|
|
277
|
+
* appended are still in the record. The engine refuses a duplicate natural key, and a refusal
|
|
278
|
+
* thrown from a handler would leave the counter repeating itself on every later click.
|
|
279
|
+
*/
|
|
280
|
+
export declare function freeNaturalKey(rows: readonly {
|
|
281
|
+
readonly rowKey: string | number;
|
|
282
|
+
}[]): string;
|
|
283
|
+
/**
|
|
284
|
+
* A row's accessible and visible name, falling back to the container label and 1-based position.
|
|
285
|
+
*
|
|
286
|
+
* `rowName` is resolved by the runtime from the declaration's addressing (`natural` and `value`
|
|
287
|
+
* rows carry their key text; `assigned` rows carry `undefined`). Keys minted by `freeNaturalKey`
|
|
288
|
+
* (`row_1`, `row_2`, …) fall back to the positional label so newly added natural-key rows never
|
|
289
|
+
* speak raw placeholder ids on either web or native.
|
|
290
|
+
*/
|
|
291
|
+
export declare function renderRowName(label: string, rowName: string | undefined, index: number): string;
|
|
292
|
+
/**
|
|
293
|
+
* Walks one layout into the render tree a host paints.
|
|
294
|
+
*
|
|
295
|
+
* Every visible node contributes exactly one tree node of a kind the closed grammar names, and
|
|
296
|
+
* the walk is exhaustive: a layout kind added to the grammar fails typecheck here rather than
|
|
297
|
+
* disappearing from the screen. A hidden node contributes nothing. The tree is a pure function
|
|
298
|
+
* of the layout, the declarations and the formatter, so a host that memoises it keeps the same
|
|
299
|
+
* node objects — and the same child renders — across a value edit that moves no chrome.
|
|
300
|
+
*/
|
|
301
|
+
export declare function renderLayout(input: RenderLayoutInput): readonly RenderNode[];
|
|
302
|
+
export {};
|
|
303
|
+
//# sourceMappingURL=nodes.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"nodes.d.ts","sourceRoot":"","sources":["../../src/render/nodes.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,aAAa,EACb,OAAO,EACP,cAAc,EACd,UAAU,EACV,SAAS,EACV,MAAM,wBAAwB,CAAC;AAGhC,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AAG9C;;;;;;;;;;;;GAYG;AAEH,uEAAuE;AACvE,MAAM,MAAM,eAAe,GAAG,CAAC,GAAG,EAAE,MAAM,EAAE,MAAM,CAAC,EAAE,QAAQ,CAAC,MA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AgB,cAAc,CAAC,IAAI,EAAE,SAAS;IAAE,QAAQ,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM,CAAA;CAAE,EAAE,GAAG,MAAM,CAO5F;AAYD;;;;;;;GAOG;AACH,wBAAgB,aAAa,CAAC,KAAK,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,GAAG,SAAS,EAAE,KAAK,EAAE,MAAM,GAAG,MAAM,CAI/F;AAED;;;;;;;;GAQG;AACH,wBAAgB,YAAY,CAAC,KAAK,EAAE,iBAAiB,GAAG,SAAS,UAAU,EAAE,CAM5E"}
|
|
@@ -0,0 +1,325 @@
|
|
|
1
|
+
import { assertNever } from '@azx-pbc/axiom-runtime';
|
|
2
|
+
import { getInputHints } from '../hints.js';
|
|
3
|
+
import { fieldDomId } from '../field-props.js';
|
|
4
|
+
/** The declaration one identifier names, including a member nested in a record or array. */
|
|
5
|
+
function indexDeclarations(fields) {
|
|
6
|
+
const index = new Map();
|
|
7
|
+
const visit = (declarations) => {
|
|
8
|
+
for (const declaration of declarations) {
|
|
9
|
+
index.set(declaration.fieldId, declaration);
|
|
10
|
+
if (declaration.fields !== undefined)
|
|
11
|
+
visit(declaration.fields);
|
|
12
|
+
}
|
|
13
|
+
};
|
|
14
|
+
visit(fields);
|
|
15
|
+
return index;
|
|
16
|
+
}
|
|
17
|
+
/** The next heading level below `level`, clamped to the last level a heading has. */
|
|
18
|
+
function deeper(level) {
|
|
19
|
+
switch (level) {
|
|
20
|
+
case 2:
|
|
21
|
+
return 3;
|
|
22
|
+
case 3:
|
|
23
|
+
return 4;
|
|
24
|
+
case 4:
|
|
25
|
+
return 5;
|
|
26
|
+
case 5:
|
|
27
|
+
case 6:
|
|
28
|
+
return 6;
|
|
29
|
+
default:
|
|
30
|
+
return assertNever(level);
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
/** A declared control, defaulting to plain text for a scalar that states none. */
|
|
34
|
+
function controlOf(declaration) {
|
|
35
|
+
return declaration.control ?? 'text';
|
|
36
|
+
}
|
|
37
|
+
/** The optional members of a compiled declaration, spelled once for the tree. */
|
|
38
|
+
function chromeOf(declaration, translate) {
|
|
39
|
+
return {
|
|
40
|
+
...(declaration.descriptionKey === undefined
|
|
41
|
+
? {}
|
|
42
|
+
: { description: translate(declaration.descriptionKey) }),
|
|
43
|
+
...(declaration.placeholderKey === undefined
|
|
44
|
+
? {}
|
|
45
|
+
: { placeholder: translate(declaration.placeholderKey) }),
|
|
46
|
+
};
|
|
47
|
+
}
|
|
48
|
+
function controlNode(nodeId, declaration, colSpan, translate) {
|
|
49
|
+
const control = controlOf(declaration);
|
|
50
|
+
return {
|
|
51
|
+
kind: 'field',
|
|
52
|
+
nodeId,
|
|
53
|
+
fieldId: declaration.fieldId,
|
|
54
|
+
control,
|
|
55
|
+
declaration,
|
|
56
|
+
label: labelOf(declaration, translate),
|
|
57
|
+
colSpan,
|
|
58
|
+
hints: getInputHints(control),
|
|
59
|
+
...chromeOf(declaration, translate),
|
|
60
|
+
};
|
|
61
|
+
}
|
|
62
|
+
/**
|
|
63
|
+
* One declared member as a tree node: a control, a single record, or a repeating record.
|
|
64
|
+
*
|
|
65
|
+
* A member declaration is not placed by the layout, so its node id is derived from its parent's
|
|
66
|
+
* and its span is the one cell it occupies. A member that is itself a container recurses through
|
|
67
|
+
* `containerMembers`; a valid artifact therefore has no shape that reaches `renderLayout` and
|
|
68
|
+
* throws.
|
|
69
|
+
*/
|
|
70
|
+
function memberNode(nodeId, declaration, colSpan, translate) {
|
|
71
|
+
if (declaration.fields === undefined) {
|
|
72
|
+
return controlNode(nodeId, declaration, colSpan, translate);
|
|
73
|
+
}
|
|
74
|
+
if (declaration.primitive === 'array') {
|
|
75
|
+
return {
|
|
76
|
+
kind: 'records',
|
|
77
|
+
nodeId,
|
|
78
|
+
fieldId: declaration.fieldId,
|
|
79
|
+
label: labelOf(declaration, translate),
|
|
80
|
+
colSpan,
|
|
81
|
+
members: containerMembers(nodeId, declaration.fields, translate),
|
|
82
|
+
...(declaration.rowKey?.mode === 'natural' && declaration.rowKey.fieldId !== undefined
|
|
83
|
+
? { naturalKey: declaration.rowKey.fieldId }
|
|
84
|
+
: {}),
|
|
85
|
+
...chromeOf(declaration, translate),
|
|
86
|
+
};
|
|
87
|
+
}
|
|
88
|
+
if (declaration.primitive === 'record') {
|
|
89
|
+
return {
|
|
90
|
+
kind: 'record',
|
|
91
|
+
nodeId,
|
|
92
|
+
fieldId: declaration.fieldId,
|
|
93
|
+
label: labelOf(declaration, translate),
|
|
94
|
+
colSpan,
|
|
95
|
+
members: containerMembers(nodeId, declaration.fields, translate),
|
|
96
|
+
...chromeOf(declaration, translate),
|
|
97
|
+
};
|
|
98
|
+
}
|
|
99
|
+
// A container of any other primitive is not a shape the grammar declares; refusing it here
|
|
100
|
+
// keeps the tree total if a hand-built artifact carries one.
|
|
101
|
+
throw new Error(`@azx-pbc/axiom-react: the layout places the ${declaration.primitive} ${declaration.fieldId} at ${nodeId}, which declares members but is neither a record nor an array`);
|
|
102
|
+
}
|
|
103
|
+
/** A declaration's label, or its identifier when the document states no label key. */
|
|
104
|
+
function labelOf(declaration, translate) {
|
|
105
|
+
return declaration.labelKey === undefined ? declaration.fieldId : translate(declaration.labelKey);
|
|
106
|
+
}
|
|
107
|
+
/** One node per declared member of a container, recursing into a container member. */
|
|
108
|
+
function containerMembers(nodeId, members, translate) {
|
|
109
|
+
return members.map((member, index) => memberNode(`${nodeId}.members[${String(index)}]`, member, 1, translate));
|
|
110
|
+
}
|
|
111
|
+
/** One placed field: a control, a single record's members, or a repeating record's members. */
|
|
112
|
+
function fieldNode(view, declarations, translate) {
|
|
113
|
+
const declaration = declarations.get(view.fieldId);
|
|
114
|
+
if (declaration === undefined) {
|
|
115
|
+
throw new Error(`@azx-pbc/axiom-react: the layout places ${view.fieldId} at ${view.nodeId}, and the artifact declares no such field`);
|
|
116
|
+
}
|
|
117
|
+
return memberNode(view.nodeId, declaration, view.colSpan, translate);
|
|
118
|
+
}
|
|
119
|
+
/** One node's tree, or `undefined` when the presentation channel hid it. */
|
|
120
|
+
function nodeOf(view, level, declarations, translate, stepId) {
|
|
121
|
+
if (!view.visible)
|
|
122
|
+
return undefined;
|
|
123
|
+
const children = (nodes, childLevel) => nodes.flatMap((child) => {
|
|
124
|
+
const node = nodeOf(child, childLevel, declarations, translate, stepId);
|
|
125
|
+
return node === undefined ? [] : [node];
|
|
126
|
+
});
|
|
127
|
+
switch (view.kind) {
|
|
128
|
+
case 'section':
|
|
129
|
+
return {
|
|
130
|
+
kind: 'section',
|
|
131
|
+
nodeId: view.nodeId,
|
|
132
|
+
...(view.sectionId === undefined ? {} : { sectionId: view.sectionId }),
|
|
133
|
+
title: translate(view.titleKey),
|
|
134
|
+
...(view.descriptionKey === undefined
|
|
135
|
+
? {}
|
|
136
|
+
: { description: translate(view.descriptionKey) }),
|
|
137
|
+
level,
|
|
138
|
+
columns: view.columns,
|
|
139
|
+
collapsible: view.collapsible,
|
|
140
|
+
...(view.defaultExpanded === undefined ? {} : { defaultExpanded: view.defaultExpanded }),
|
|
141
|
+
children: children(view.children, deeper(level)),
|
|
142
|
+
};
|
|
143
|
+
case 'group':
|
|
144
|
+
return {
|
|
145
|
+
kind: 'group',
|
|
146
|
+
nodeId: view.nodeId,
|
|
147
|
+
...(view.titleKey === undefined ? {} : { title: translate(view.titleKey) }),
|
|
148
|
+
...(view.descriptionKey === undefined
|
|
149
|
+
? {}
|
|
150
|
+
: { description: translate(view.descriptionKey) }),
|
|
151
|
+
level,
|
|
152
|
+
columns: view.columns,
|
|
153
|
+
collapsible: view.collapsible,
|
|
154
|
+
...(view.defaultExpanded === undefined ? {} : { defaultExpanded: view.defaultExpanded }),
|
|
155
|
+
children: children(view.children, deeper(level)),
|
|
156
|
+
};
|
|
157
|
+
case 'wizard': {
|
|
158
|
+
const steps = view.children.flatMap((step) => {
|
|
159
|
+
const node = nodeOf(step, 2, declarations, translate, stepId);
|
|
160
|
+
return node !== undefined && node.kind === 'step' ? [node] : [];
|
|
161
|
+
});
|
|
162
|
+
// A named step that is present narrows the wizard to it; one that is absent (hidden by the
|
|
163
|
+
// presentation channel, or retired from the artifact) leaves every visible step in place.
|
|
164
|
+
const current = stepId === undefined ? undefined : steps.find((step) => step.stepId === stepId);
|
|
165
|
+
return {
|
|
166
|
+
kind: 'wizard',
|
|
167
|
+
nodeId: view.nodeId,
|
|
168
|
+
...(current === undefined ? {} : { currentStepId: current.stepId }),
|
|
169
|
+
children: current === undefined ? steps : [current],
|
|
170
|
+
};
|
|
171
|
+
}
|
|
172
|
+
case 'step':
|
|
173
|
+
return {
|
|
174
|
+
kind: 'step',
|
|
175
|
+
nodeId: view.nodeId,
|
|
176
|
+
...(view.sectionId === undefined ? {} : { sectionId: view.sectionId }),
|
|
177
|
+
stepId: view.stepId,
|
|
178
|
+
title: translate(view.titleKey),
|
|
179
|
+
...(view.descriptionKey === undefined
|
|
180
|
+
? {}
|
|
181
|
+
: { description: translate(view.descriptionKey) }),
|
|
182
|
+
level,
|
|
183
|
+
columns: view.columns,
|
|
184
|
+
children: children(view.children, deeper(level)),
|
|
185
|
+
};
|
|
186
|
+
case 'field':
|
|
187
|
+
return fieldNode(view, declarations, translate);
|
|
188
|
+
case 'heading':
|
|
189
|
+
return {
|
|
190
|
+
kind: 'heading',
|
|
191
|
+
nodeId: view.nodeId,
|
|
192
|
+
level,
|
|
193
|
+
title: translate(view.titleKey),
|
|
194
|
+
...(view.textKey === undefined ? {} : { body: translate(view.textKey) }),
|
|
195
|
+
};
|
|
196
|
+
case 'callout':
|
|
197
|
+
return {
|
|
198
|
+
kind: 'callout',
|
|
199
|
+
nodeId: view.nodeId,
|
|
200
|
+
tone: view.tone,
|
|
201
|
+
...(view.titleKey === undefined ? {} : { title: translate(view.titleKey) }),
|
|
202
|
+
body: translate(view.textKey, view.params),
|
|
203
|
+
};
|
|
204
|
+
case 'divider':
|
|
205
|
+
return { kind: 'divider', nodeId: view.nodeId };
|
|
206
|
+
case 'sop_block':
|
|
207
|
+
return {
|
|
208
|
+
kind: 'sop_block',
|
|
209
|
+
nodeId: view.nodeId,
|
|
210
|
+
level,
|
|
211
|
+
title: translate(view.titleKey),
|
|
212
|
+
...(view.textKey === undefined ? {} : { body: translate(view.textKey, view.params) }),
|
|
213
|
+
};
|
|
214
|
+
case 'summary_card':
|
|
215
|
+
return {
|
|
216
|
+
kind: 'summary_card',
|
|
217
|
+
nodeId: view.nodeId,
|
|
218
|
+
level,
|
|
219
|
+
title: translate(view.titleKey),
|
|
220
|
+
...(view.textKey === undefined ? {} : { body: translate(view.textKey, view.params) }),
|
|
221
|
+
readouts: (view.readouts ?? []).map((readout) => ({
|
|
222
|
+
label: translate(readout.labelKey),
|
|
223
|
+
...(readout.value === undefined ? {} : { value: readout.value }),
|
|
224
|
+
})),
|
|
225
|
+
fields: (view.fields ?? []).flatMap((fieldId) => {
|
|
226
|
+
const declaration = declarations.get(fieldId);
|
|
227
|
+
return declaration === undefined
|
|
228
|
+
? []
|
|
229
|
+
: [{ fieldId, label: labelOf(declaration, translate) }];
|
|
230
|
+
}),
|
|
231
|
+
};
|
|
232
|
+
default:
|
|
233
|
+
return assertNever(view);
|
|
234
|
+
}
|
|
235
|
+
}
|
|
236
|
+
/**
|
|
237
|
+
* The announced summary of every blocking reason, or nothing when none blocks.
|
|
238
|
+
*
|
|
239
|
+
* It is built apart from the layout walk, and on purpose: a reason appears and disappears on
|
|
240
|
+
* almost every keystroke, while the tree it sits above is stable. A host renders this beside the
|
|
241
|
+
* tree, so a keystroke that adds a failure re-renders the announcement and not the form.
|
|
242
|
+
*/
|
|
243
|
+
export function renderErrorSummary(input) {
|
|
244
|
+
if (input.errors.length === 0)
|
|
245
|
+
return undefined;
|
|
246
|
+
const declarations = indexDeclarations(input.fields);
|
|
247
|
+
return {
|
|
248
|
+
kind: 'error_summary',
|
|
249
|
+
nodeId: 'error_summary',
|
|
250
|
+
items: input.errors.map((error) => {
|
|
251
|
+
// The element the item is about: the caller's when it knows the row, else the control the
|
|
252
|
+
// field is painted as (`fieldDomId` under this session's prefix), else the announcement
|
|
253
|
+
// itself for a reason about the record.
|
|
254
|
+
const targetId = error.targetId ??
|
|
255
|
+
(error.fieldId === undefined
|
|
256
|
+
? (input.summaryId ?? 'error_summary')
|
|
257
|
+
: fieldDomId(input.idPrefix, error.fieldId));
|
|
258
|
+
if (error.fieldId === undefined)
|
|
259
|
+
return { message: error.message, targetId };
|
|
260
|
+
const declaration = declarations.get(error.fieldId);
|
|
261
|
+
return {
|
|
262
|
+
fieldId: error.fieldId,
|
|
263
|
+
message: error.message,
|
|
264
|
+
targetId,
|
|
265
|
+
...(declaration === undefined ? {} : { label: labelOf(declaration, input.translate) }),
|
|
266
|
+
};
|
|
267
|
+
}),
|
|
268
|
+
};
|
|
269
|
+
}
|
|
270
|
+
/**
|
|
271
|
+
* The first `row_<n>` key the current rows do not already hold.
|
|
272
|
+
*
|
|
273
|
+
* The key is derived from the record rather than from a counter in a component: a wizard unmounts
|
|
274
|
+
* the step it is not painting, so component state starts again at one while the rows it already
|
|
275
|
+
* appended are still in the record. The engine refuses a duplicate natural key, and a refusal
|
|
276
|
+
* thrown from a handler would leave the counter repeating itself on every later click.
|
|
277
|
+
*/
|
|
278
|
+
export function freeNaturalKey(rows) {
|
|
279
|
+
const taken = new Set(rows.map((row) => String(row.rowKey)));
|
|
280
|
+
// The search starts at one, not at the row count: rows may hold authored natural keys
|
|
281
|
+
// (`kitchen`, `garage`), so `row_1` can be free while the list already holds two rows.
|
|
282
|
+
let candidate = 1;
|
|
283
|
+
while (taken.has(`row_${String(candidate)}`))
|
|
284
|
+
candidate += 1;
|
|
285
|
+
return `row_${String(candidate)}`;
|
|
286
|
+
}
|
|
287
|
+
/**
|
|
288
|
+
* Whether a natural-key string is one `freeNaturalKey` minted rather than text the reader authored.
|
|
289
|
+
*
|
|
290
|
+
* Kept beside `freeNaturalKey` so the minting convention and its display fallback share one owner
|
|
291
|
+
* across web and native adapters.
|
|
292
|
+
*/
|
|
293
|
+
function isGeneratedNaturalKey(value) {
|
|
294
|
+
return /^row_\d+$/u.test(value);
|
|
295
|
+
}
|
|
296
|
+
/**
|
|
297
|
+
* A row's accessible and visible name, falling back to the container label and 1-based position.
|
|
298
|
+
*
|
|
299
|
+
* `rowName` is resolved by the runtime from the declaration's addressing (`natural` and `value`
|
|
300
|
+
* rows carry their key text; `assigned` rows carry `undefined`). Keys minted by `freeNaturalKey`
|
|
301
|
+
* (`row_1`, `row_2`, …) fall back to the positional label so newly added natural-key rows never
|
|
302
|
+
* speak raw placeholder ids on either web or native.
|
|
303
|
+
*/
|
|
304
|
+
export function renderRowName(label, rowName, index) {
|
|
305
|
+
return rowName === undefined || rowName === '' || isGeneratedNaturalKey(rowName)
|
|
306
|
+
? `${label} ${String(index + 1)}`
|
|
307
|
+
: rowName;
|
|
308
|
+
}
|
|
309
|
+
/**
|
|
310
|
+
* Walks one layout into the render tree a host paints.
|
|
311
|
+
*
|
|
312
|
+
* Every visible node contributes exactly one tree node of a kind the closed grammar names, and
|
|
313
|
+
* the walk is exhaustive: a layout kind added to the grammar fails typecheck here rather than
|
|
314
|
+
* disappearing from the screen. A hidden node contributes nothing. The tree is a pure function
|
|
315
|
+
* of the layout, the declarations and the formatter, so a host that memoises it keeps the same
|
|
316
|
+
* node objects — and the same child renders — across a value edit that moves no chrome.
|
|
317
|
+
*/
|
|
318
|
+
export function renderLayout(input) {
|
|
319
|
+
const declarations = indexDeclarations(input.fields);
|
|
320
|
+
return input.layout.flatMap((view) => {
|
|
321
|
+
const node = nodeOf(view, 2, declarations, input.translate, input.stepId);
|
|
322
|
+
return node === undefined ? [] : [node];
|
|
323
|
+
});
|
|
324
|
+
}
|
|
325
|
+
//# sourceMappingURL=nodes.js.map
|