@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.
Files changed (191) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +604 -2
  3. package/dist/FormErrorBoundary.d.ts +37 -0
  4. package/dist/FormErrorBoundary.d.ts.map +1 -0
  5. package/dist/FormErrorBoundary.js +54 -0
  6. package/dist/FormErrorBoundary.js.map +1 -0
  7. package/dist/FormProvider.d.ts +197 -0
  8. package/dist/FormProvider.d.ts.map +1 -0
  9. package/dist/FormProvider.js +149 -0
  10. package/dist/FormProvider.js.map +1 -0
  11. package/dist/field-error.d.ts +154 -0
  12. package/dist/field-error.d.ts.map +1 -0
  13. package/dist/field-error.js +2 -0
  14. package/dist/field-error.js.map +1 -0
  15. package/dist/field-props.d.ts +362 -0
  16. package/dist/field-props.d.ts.map +1 -0
  17. package/dist/field-props.js +64 -0
  18. package/dist/field-props.js.map +1 -0
  19. package/dist/form-context.d.ts +31 -0
  20. package/dist/form-context.d.ts.map +1 -0
  21. package/dist/form-context.js +13 -0
  22. package/dist/form-context.js.map +1 -0
  23. package/dist/form-store.d.ts +784 -0
  24. package/dist/form-store.d.ts.map +1 -0
  25. package/dist/form-store.js +2179 -0
  26. package/dist/form-store.js.map +1 -0
  27. package/dist/hints.d.ts +60 -0
  28. package/dist/hints.d.ts.map +1 -0
  29. package/dist/hints.js +158 -0
  30. package/dist/hints.js.map +1 -0
  31. package/dist/index.d.ts +57 -0
  32. package/dist/index.d.ts.map +1 -0
  33. package/dist/index.js +36 -0
  34. package/dist/index.js.map +1 -0
  35. package/dist/render/field-value.d.ts +92 -0
  36. package/dist/render/field-value.d.ts.map +1 -0
  37. package/dist/render/field-value.js +124 -0
  38. package/dist/render/field-value.js.map +1 -0
  39. package/dist/render/nodes.d.ts +303 -0
  40. package/dist/render/nodes.d.ts.map +1 -0
  41. package/dist/render/nodes.js +325 -0
  42. package/dist/render/nodes.js.map +1 -0
  43. package/dist/render/schema.d.ts +30 -0
  44. package/dist/render/schema.d.ts.map +1 -0
  45. package/dist/render/schema.js +40 -0
  46. package/dist/render/schema.js.map +1 -0
  47. package/dist/render/value-text.d.ts +59 -0
  48. package/dist/render/value-text.d.ts.map +1 -0
  49. package/dist/render/value-text.js +104 -0
  50. package/dist/render/value-text.js.map +1 -0
  51. package/dist/store/array-bindings.d.ts +110 -0
  52. package/dist/store/array-bindings.d.ts.map +1 -0
  53. package/dist/store/array-bindings.js +181 -0
  54. package/dist/store/array-bindings.js.map +1 -0
  55. package/dist/store/bindings.d.ts +12 -0
  56. package/dist/store/bindings.d.ts.map +1 -0
  57. package/dist/store/bindings.js +16 -0
  58. package/dist/store/bindings.js.map +1 -0
  59. package/dist/store/buffer-state.d.ts +42 -0
  60. package/dist/store/buffer-state.d.ts.map +1 -0
  61. package/dist/store/buffer-state.js +51 -0
  62. package/dist/store/buffer-state.js.map +1 -0
  63. package/dist/store/configure.d.ts +19 -0
  64. package/dist/store/configure.d.ts.map +1 -0
  65. package/dist/store/configure.js +28 -0
  66. package/dist/store/configure.js.map +1 -0
  67. package/dist/store/derive.d.ts +106 -0
  68. package/dist/store/derive.d.ts.map +1 -0
  69. package/dist/store/derive.js +417 -0
  70. package/dist/store/derive.js.map +1 -0
  71. package/dist/store/errors.d.ts +20 -0
  72. package/dist/store/errors.d.ts.map +1 -0
  73. package/dist/store/errors.js +101 -0
  74. package/dist/store/errors.js.map +1 -0
  75. package/dist/store/fields.d.ts +35 -0
  76. package/dist/store/fields.d.ts.map +1 -0
  77. package/dist/store/fields.js +81 -0
  78. package/dist/store/fields.js.map +1 -0
  79. package/dist/store/form-channel.d.ts +174 -0
  80. package/dist/store/form-channel.d.ts.map +1 -0
  81. package/dist/store/form-channel.js +411 -0
  82. package/dist/store/form-channel.js.map +1 -0
  83. package/dist/store/gates.d.ts +22 -0
  84. package/dist/store/gates.d.ts.map +1 -0
  85. package/dist/store/gates.js +44 -0
  86. package/dist/store/gates.js.map +1 -0
  87. package/dist/store/ids.d.ts +20 -0
  88. package/dist/store/ids.d.ts.map +1 -0
  89. package/dist/store/ids.js +28 -0
  90. package/dist/store/ids.js.map +1 -0
  91. package/dist/store/inputs.d.ts +114 -0
  92. package/dist/store/inputs.d.ts.map +1 -0
  93. package/dist/store/inputs.js +202 -0
  94. package/dist/store/inputs.js.map +1 -0
  95. package/dist/store/layout.d.ts +81 -0
  96. package/dist/store/layout.d.ts.map +1 -0
  97. package/dist/store/layout.js +285 -0
  98. package/dist/store/layout.js.map +1 -0
  99. package/dist/store/messages.d.ts +56 -0
  100. package/dist/store/messages.d.ts.map +1 -0
  101. package/dist/store/messages.js +157 -0
  102. package/dist/store/messages.js.map +1 -0
  103. package/dist/store/option-pages.d.ts +193 -0
  104. package/dist/store/option-pages.d.ts.map +1 -0
  105. package/dist/store/option-pages.js +598 -0
  106. package/dist/store/option-pages.js.map +1 -0
  107. package/dist/store/parse-print.d.ts +105 -0
  108. package/dist/store/parse-print.d.ts.map +1 -0
  109. package/dist/store/parse-print.js +415 -0
  110. package/dist/store/parse-print.js.map +1 -0
  111. package/dist/store/proposals.d.ts +114 -0
  112. package/dist/store/proposals.d.ts.map +1 -0
  113. package/dist/store/proposals.js +90 -0
  114. package/dist/store/proposals.js.map +1 -0
  115. package/dist/store/publish.d.ts +48 -0
  116. package/dist/store/publish.d.ts.map +1 -0
  117. package/dist/store/publish.js +96 -0
  118. package/dist/store/publish.js.map +1 -0
  119. package/dist/store/snapshots.d.ts +63 -0
  120. package/dist/store/snapshots.d.ts.map +1 -0
  121. package/dist/store/snapshots.js +154 -0
  122. package/dist/store/snapshots.js.map +1 -0
  123. package/dist/store/steps.d.ts +13 -0
  124. package/dist/store/steps.d.ts.map +1 -0
  125. package/dist/store/steps.js +31 -0
  126. package/dist/store/steps.js.map +1 -0
  127. package/dist/store/view.d.ts +124 -0
  128. package/dist/store/view.d.ts.map +1 -0
  129. package/dist/store/view.js +301 -0
  130. package/dist/store/view.js.map +1 -0
  131. package/dist/store/visibility.d.ts +68 -0
  132. package/dist/store/visibility.d.ts.map +1 -0
  133. package/dist/store/visibility.js +231 -0
  134. package/dist/store/visibility.js.map +1 -0
  135. package/dist/store/wizard-cursor.d.ts +43 -0
  136. package/dist/store/wizard-cursor.d.ts.map +1 -0
  137. package/dist/store/wizard-cursor.js +67 -0
  138. package/dist/store/wizard-cursor.js.map +1 -0
  139. package/dist/store/writes.d.ts +50 -0
  140. package/dist/store/writes.d.ts.map +1 -0
  141. package/dist/store/writes.js +91 -0
  142. package/dist/store/writes.js.map +1 -0
  143. package/dist/typed.d.ts +134 -0
  144. package/dist/typed.d.ts.map +1 -0
  145. package/dist/typed.js +74 -0
  146. package/dist/typed.js.map +1 -0
  147. package/dist/useAsyncOptions.d.ts +20 -0
  148. package/dist/useAsyncOptions.d.ts.map +1 -0
  149. package/dist/useAsyncOptions.js +70 -0
  150. package/dist/useAsyncOptions.js.map +1 -0
  151. package/dist/useBufferedInput.d.ts +69 -0
  152. package/dist/useBufferedInput.d.ts.map +1 -0
  153. package/dist/useBufferedInput.js +132 -0
  154. package/dist/useBufferedInput.js.map +1 -0
  155. package/dist/useField.d.ts +42 -0
  156. package/dist/useField.d.ts.map +1 -0
  157. package/dist/useField.js +63 -0
  158. package/dist/useField.js.map +1 -0
  159. package/dist/useFieldArray.d.ts +25 -0
  160. package/dist/useFieldArray.d.ts.map +1 -0
  161. package/dist/useFieldArray.js +18 -0
  162. package/dist/useFieldArray.js.map +1 -0
  163. package/dist/useForm.d.ts +20 -0
  164. package/dist/useForm.d.ts.map +1 -0
  165. package/dist/useForm.js +9 -0
  166. package/dist/useForm.js.map +1 -0
  167. package/dist/useFormState.d.ts +23 -0
  168. package/dist/useFormState.d.ts.map +1 -0
  169. package/dist/useFormState.js +11 -0
  170. package/dist/useFormState.js.map +1 -0
  171. package/dist/useGate.d.ts +15 -0
  172. package/dist/useGate.d.ts.map +1 -0
  173. package/dist/useGate.js +21 -0
  174. package/dist/useGate.js.map +1 -0
  175. package/dist/useLayout.d.ts +29 -0
  176. package/dist/useLayout.d.ts.map +1 -0
  177. package/dist/useLayout.js +59 -0
  178. package/dist/useLayout.js.map +1 -0
  179. package/dist/useMessage.d.ts +58 -0
  180. package/dist/useMessage.d.ts.map +1 -0
  181. package/dist/useMessage.js +62 -0
  182. package/dist/useMessage.js.map +1 -0
  183. package/dist/useWatch.d.ts +19 -0
  184. package/dist/useWatch.d.ts.map +1 -0
  185. package/dist/useWatch.js +17 -0
  186. package/dist/useWatch.js.map +1 -0
  187. package/dist/useWizard.d.ts +166 -0
  188. package/dist/useWizard.d.ts.map +1 -0
  189. package/dist/useWizard.js +554 -0
  190. package/dist/useWizard.js.map +1 -0
  191. package/package.json +62 -3
@@ -0,0 +1,417 @@
1
+ import { assertNever, sameWireValue } from '@azx-pbc/axiom-runtime';
2
+ import { fieldDescriptionId, fieldDomId, fieldErrorId } from '../field-props.js';
3
+ import { getInputHints } from '../hints.js';
4
+ import { renderFieldText } from '../render/value-text.js';
5
+ import { bindingErrors } from './errors.js';
6
+ import { showsErrorOf, visibleErrorsOf } from './visibility.js';
7
+ /**
8
+ * Maps one engine binding state to the props a control renders.
9
+ *
10
+ * The engine owns visibility, access, delivery, the computed value and the messages; this adds
11
+ * only what a session and a host own — the value's move from its baseline, the touch flag, the
12
+ * display rule and the input hints — so there is no second classifier and no second access
13
+ * resolver here.
14
+ */
15
+ export function deriveFieldProps(context) {
16
+ const { state, view, display, visibility, writers } = context;
17
+ const value = state.value.kind === 'value' ? state.value.value : undefined;
18
+ const engineErrors = bindingErrors(state);
19
+ // A refused entry is not a fact about the record, so it is appended to the derived list
20
+ // rather than cached with the engine state: the record the binding shows is still valid.
21
+ const errors = view.refusal === undefined
22
+ ? engineErrors
23
+ : {
24
+ errors: Object.freeze([...engineErrors.errors, view.refusal]),
25
+ readOnlyDiagnostics: engineErrors.readOnlyDiagnostics,
26
+ invalid: engineErrors.invalid,
27
+ };
28
+ const readOnly = state.access === 'read_only';
29
+ // `read_only` is announced with `readOnly`, not `disabled`: a disabled input leaves the tab
30
+ // order and cannot be copied, which is not what a value the user is meant to read should do.
31
+ // `enabled` still states "may accept a user write"; `disabled` states the element attribute.
32
+ const disabled = !state.enabled && !readOnly;
33
+ const invalid = errors.invalid;
34
+ const visibleErrors = visibleErrorsOf(state, view, display.reveal, visibility);
35
+ const showError = showsErrorOf(visibleErrors);
36
+ // Masked is the one access state with no value to bind at all, so the binding states the text
37
+ // to render in its place: an input (or a buffer) would show an empty control, and every
38
+ // keystroke would be refused.
39
+ const maskedText = state.access === 'masked' ? (display.maskedDisplay?.[state.fieldId] ?? '') : undefined;
40
+ return {
41
+ fieldId: state.fieldId,
42
+ ...(state.rowKey === undefined ? {} : { rowKey: state.rowKey }),
43
+ bindingKey: context.bindingKey,
44
+ descriptor: context.descriptor,
45
+ value,
46
+ text: renderFieldText({ value, maskedText, computation: state.computation, descriptor: context.descriptor }, display.valueDisplay),
47
+ initialValue: view.initialValue,
48
+ access: state.access,
49
+ visible: state.visible,
50
+ enabled: state.enabled,
51
+ // The runtime answers fillability once: the write predicate plus the facts the engine
52
+ // refuses before it and visibility. A control gating an affordance on this cannot offer a
53
+ // write the session would refuse.
54
+ mayWrite: state.fillable,
55
+ disabled,
56
+ readOnly,
57
+ required: state.required,
58
+ ...(state.cardinality === undefined || state.cardinality.kind === 'undetermined'
59
+ ? {}
60
+ : {
61
+ rowCount: state.cardinality.count,
62
+ ...(state.cardinality.kind === 'belowMin'
63
+ ? {
64
+ countViolation: {
65
+ kind: 'belowMin',
66
+ count: state.cardinality.count,
67
+ limit: state.cardinality.minItems,
68
+ },
69
+ }
70
+ : state.cardinality.kind === 'aboveMax'
71
+ ? {
72
+ countViolation: {
73
+ kind: 'aboveMax',
74
+ count: state.cardinality.count,
75
+ limit: state.cardinality.maxItems,
76
+ },
77
+ }
78
+ : {}),
79
+ }),
80
+ computation: state.computation,
81
+ ...(state.unavailableOptions === undefined
82
+ ? {}
83
+ : { unavailableOptions: state.unavailableOptions }),
84
+ messages: state.messages,
85
+ errors: errors.errors,
86
+ visibleErrors,
87
+ readOnlyDiagnostics: errors.readOnlyDiagnostics,
88
+ invalid,
89
+ showError,
90
+ touched: view.touched,
91
+ dirty: dirtyOf(state, view),
92
+ maskedText,
93
+ withheld: state.value.kind === 'withheld',
94
+ ...(state.value.kind === 'withheld' ? { withheldReason: state.value.reason } : {}),
95
+ a11y: a11yOf(
96
+ // A requirement the reader cannot act on is not marked: a value the record withholds is
97
+ // the tier that holds it to settle. A session-written `write_only` value is settled too;
98
+ // only the genuinely empty arm asks this reader for an answer.
99
+ state.required &&
100
+ state.value.kind !== 'withheld' &&
101
+ !(state.access === 'write_only' &&
102
+ state.value.kind === 'value' &&
103
+ state.value.value !== null), showError, disabled, readOnly, display.idPrefix, context.bindingKey, state.descriptionKey !== undefined, busyOf(state, view.submitting)),
104
+ hints: hintsOf(state),
105
+ signature: context.signature,
106
+ setValue: writers.setValue,
107
+ onChange: writers.setValue,
108
+ setNull: writers.setNull,
109
+ removeValue: writers.removeValue,
110
+ onBlur: writers.onBlur,
111
+ };
112
+ }
113
+ /**
114
+ * Whether a binding's value moved from the session's baseline, with `empty()` semantics.
115
+ *
116
+ * The comparison is against the value the *record* held, which no access answer can change: a
117
+ * value that becomes readable was always there, so widening a mask over an untouched record is
118
+ * not an edit. A value a writer owns is derived from the record rather than entered in it, so it
119
+ * is never an edit either. A value this device may not read is one it cannot compare — and one
120
+ * the submission projection would not carry — so it is reported as unmoved rather than guessed at.
121
+ */
122
+ export function dirtyOf(state, view) {
123
+ if (state.systemComputed)
124
+ return false;
125
+ switch (state.value.kind) {
126
+ case 'value':
127
+ return !sameHeld(state.value.value, view.initialHeld);
128
+ case 'absent':
129
+ return !isEmptyHeld(view.initialHeld);
130
+ case 'withheld':
131
+ return false;
132
+ }
133
+ }
134
+ /** `empty()` treats the authored `null` and an absent value as one empty state. */
135
+ function isEmptyHeld(value) {
136
+ return value === undefined || value === null;
137
+ }
138
+ /** Whether two held values state the same fact; `empty()` semantics, then wire equality. */
139
+ function sameHeld(left, right) {
140
+ if (isEmptyHeld(left) || isEmptyHeld(right))
141
+ return isEmptyHeld(left) && isEmptyHeld(right);
142
+ return sameWireValue(left, right);
143
+ }
144
+ /** The hint table is the only control-to-hint authority; this only remembers the answer. */
145
+ function hintsOf(state) {
146
+ return getInputHints(state.control);
147
+ }
148
+ /** Whether two derivations say the same thing, so a re-derivation keeps the props identity. */
149
+ export function sameFieldProps(left, right) {
150
+ return (left.fieldId === right.fieldId &&
151
+ left.rowKey === right.rowKey &&
152
+ left.bindingKey === right.bindingKey &&
153
+ left.descriptor === right.descriptor &&
154
+ sameWireValue(left.value, right.value) &&
155
+ left.text === right.text &&
156
+ sameWireValue(left.initialValue, right.initialValue) &&
157
+ left.access === right.access &&
158
+ left.visible === right.visible &&
159
+ left.enabled === right.enabled &&
160
+ left.mayWrite === right.mayWrite &&
161
+ left.disabled === right.disabled &&
162
+ left.readOnly === right.readOnly &&
163
+ left.required === right.required &&
164
+ sameUnavailableOptions(left.unavailableOptions, right.unavailableOptions) &&
165
+ sameComputation(left.computation, right.computation) &&
166
+ sameMessages(left.messages, right.messages) &&
167
+ sameFieldErrors(left.errors, right.errors) &&
168
+ sameFieldErrors(left.visibleErrors, right.visibleErrors) &&
169
+ sameFieldErrors(left.readOnlyDiagnostics, right.readOnlyDiagnostics) &&
170
+ left.invalid === right.invalid &&
171
+ left.showError === right.showError &&
172
+ left.touched === right.touched &&
173
+ left.dirty === right.dirty &&
174
+ left.maskedText === right.maskedText &&
175
+ left.withheld === right.withheld &&
176
+ left.withheldReason === right.withheldReason &&
177
+ sameA11y(left.a11y, right.a11y) &&
178
+ left.hints === right.hints &&
179
+ left.setValue === right.setValue &&
180
+ left.onChange === right.onChange &&
181
+ left.setNull === right.setNull &&
182
+ left.removeValue === right.removeValue &&
183
+ left.onBlur === right.onBlur);
184
+ }
185
+ /**
186
+ * Whether two availability answers state the same refusal.
187
+ *
188
+ * The list is the binding's only sign that an option the domain offers may not be chosen, so a
189
+ * column that changed while every other published fact stayed put still has to replace the props
190
+ * object: reusing the previous one would keep a control painting the option as offered.
191
+ */
192
+ function sameUnavailableOptions(left, right) {
193
+ if (left === undefined || right === undefined)
194
+ return left === right;
195
+ return (left.length === right.length &&
196
+ left.every((option, index) => {
197
+ const other = right[index];
198
+ return (other !== undefined &&
199
+ option.code === other.code &&
200
+ option.state === other.state &&
201
+ option.messageKey === other.messageKey &&
202
+ option.cause === other.cause &&
203
+ sameWireParams(option.params, other.params));
204
+ }));
205
+ }
206
+ /** Whether two computed values state the same fact; the engine's own union, exhaustively. */
207
+ function sameComputation(left, right) {
208
+ switch (left.kind) {
209
+ case 'none':
210
+ return right.kind === 'none';
211
+ case 'withheld':
212
+ return right.kind === 'withheld';
213
+ case 'value':
214
+ return right.kind === 'value' && sameWireValue(left.value, right.value);
215
+ case 'undetermined':
216
+ return right.kind === 'undetermined' && left.status === right.status;
217
+ }
218
+ }
219
+ /**
220
+ * One frozen object per combination of the four attributes a control sets.
221
+ *
222
+ * The ids and the busy flag are per binding and are added beside the cached combination rather
223
+ * than inside it: six identities multiplied by every row would be a cache with the record's
224
+ * cardinality. `sameA11y` compares the whole shape by value, so a fresh wrapper does not replace
225
+ * a binding's props on every pass — the identity the sibling-render test pins is the props
226
+ * object, and this keeps it decided by the facts rather than by allocation.
227
+ */
228
+ const A11Y = Array.from({ length: 16 }, (_, bits) => Object.freeze({
229
+ required: (bits & 1) !== 0,
230
+ invalid: (bits & 2) !== 0,
231
+ disabled: (bits & 4) !== 0,
232
+ readOnly: (bits & 8) !== 0,
233
+ }));
234
+ function a11yOf(required, invalid, disabled, readOnly, idPrefix, bindingKey, hasDescription, busy) {
235
+ const index = (required ? 1 : 0) | (invalid ? 2 : 0) | (disabled ? 4 : 0) | (readOnly ? 8 : 0);
236
+ // The index is a bitmask over four booleans, so every value is one of the sixteen entries.
237
+ const base = A11Y[index];
238
+ if (base === undefined)
239
+ throw new Error('unreachable a11y combination');
240
+ return {
241
+ required: base.required,
242
+ invalid: base.invalid,
243
+ disabled: base.disabled,
244
+ readOnly: base.readOnly,
245
+ controlId: fieldDomId(idPrefix, bindingKey),
246
+ errorId: fieldErrorId(idPrefix, bindingKey),
247
+ // A binding that declares no description renders no element, so naming an id for one would
248
+ // make every `aria-describedby` that used it a dangling IDREF.
249
+ ...(hasDescription ? { descriptionId: fieldDescriptionId(idPrefix, bindingKey) } : {}),
250
+ busy,
251
+ };
252
+ }
253
+ /** Whether two a11y answers state the same relations, so the cached props keep their identity. */
254
+ function sameA11y(left, right) {
255
+ return (left.controlId === right.controlId &&
256
+ left.errorId === right.errorId &&
257
+ left.descriptionId === right.descriptionId &&
258
+ left.busy === right.busy &&
259
+ left.required === right.required &&
260
+ left.invalid === right.invalid &&
261
+ left.disabled === right.disabled &&
262
+ left.readOnly === right.readOnly);
263
+ }
264
+ /**
265
+ * Whether `aria-busy` should announce this control.
266
+ *
267
+ * A deferred failure is the server's handoff, not a refusal, and at rest the device is not
268
+ * waiting for anything: announcing it as busy made a client artifact's controls look like they
269
+ * were loading forever. The one moment the answer really is in flight is a submission that may
270
+ * settle the check, so that is the only state reported. The readiness summary counts the same
271
+ * deferred fact once for the form in `hasDeferredChecks`.
272
+ */
273
+ function busyOf(state, submitting) {
274
+ return submitting && state.messages.some((message) => message.status === 'DEFERRED');
275
+ }
276
+ /** Whether two message lists state the same failures; a new engine rebuilds the arrays. */
277
+ function sameMessages(left, right) {
278
+ return (left.length === right.length &&
279
+ left.every((message, index) => {
280
+ const other = right[index];
281
+ return other !== undefined && sameMessage(message, other);
282
+ }));
283
+ }
284
+ function sameMessage(left, right) {
285
+ return (left.ruleId === right.ruleId &&
286
+ left.severity === right.severity &&
287
+ left.status === right.status &&
288
+ left.messageKey === right.messageKey &&
289
+ sameWireParams(left.params, right.params));
290
+ }
291
+ /** Whether two message parameter sets state the same arguments, at any depth. */
292
+ export function sameWireParams(left, right) {
293
+ if (left === undefined || right === undefined)
294
+ return left === right;
295
+ const keys = Object.keys(left);
296
+ if (keys.length !== Object.keys(right).length)
297
+ return false;
298
+ return keys.every((key) => sameWireValue(left[key], right[key]));
299
+ }
300
+ /** Whether two evaluated alternatives state the same operations and concrete values. */
301
+ export function sameSuggestions(left, right) {
302
+ if (left === undefined || right === undefined)
303
+ return left === right;
304
+ return (left.length === right.length &&
305
+ left.every((suggestion, index) => {
306
+ const other = right[index];
307
+ return (other !== undefined &&
308
+ suggestion.labelKey === other.labelKey &&
309
+ suggestion.disabledReason === other.disabledReason &&
310
+ sameSuggestedOperations(suggestion.operations, other.operations));
311
+ }));
312
+ }
313
+ function sameSuggestedOperations(left, right) {
314
+ return (left.length === right.length &&
315
+ left.every((operation, index) => {
316
+ const other = right[index];
317
+ return other !== undefined && sameSuggestedOperation(operation, other);
318
+ }));
319
+ }
320
+ function sameSuggestedOperation(left, right) {
321
+ if (left.kind !== right.kind)
322
+ return false;
323
+ switch (left.kind) {
324
+ case 'value':
325
+ return (right.kind === 'value' &&
326
+ sameFieldRef(left.ref, right.ref) &&
327
+ sameWireValue(left.value, right.value));
328
+ case 'null':
329
+ case 'remove':
330
+ return ((right.kind === 'null' || right.kind === 'remove') && sameFieldRef(left.ref, right.ref));
331
+ case 'append':
332
+ return (right.kind === 'append' &&
333
+ left.fieldId === right.fieldId &&
334
+ sameWireParams(left.row, right.row));
335
+ case 'removeRow':
336
+ return (right.kind === 'removeRow' && left.fieldId === right.fieldId && left.rowKey === right.rowKey);
337
+ default:
338
+ return assertNever(left);
339
+ }
340
+ }
341
+ function sameFieldRef(left, right) {
342
+ return left.fieldId === right.fieldId && left.rowKey === right.rowKey;
343
+ }
344
+ /** Whether two media limits name the same admitted types or the same byte bound. */
345
+ export function sameMediaLimit(left, right) {
346
+ if (typeof left === 'number' || typeof right === 'number')
347
+ return left === right;
348
+ return left.length === right.length && left.every((entry, index) => entry === right[index]);
349
+ }
350
+ /** Whether two derived error lists state the same reasons, which a new engine rebuilds. */
351
+ export function sameFieldErrors(left, right) {
352
+ return (left.length === right.length &&
353
+ left.every((error, index) => {
354
+ const other = right[index];
355
+ return other !== undefined && sameError(error, other);
356
+ }));
357
+ }
358
+ function sameError(left, right) {
359
+ switch (left.kind) {
360
+ case 'validate':
361
+ case 'deferred':
362
+ return (right.kind === left.kind &&
363
+ left.blocking === right.blocking &&
364
+ left.severity === right.severity &&
365
+ left.status === right.status &&
366
+ left.messageKey === right.messageKey &&
367
+ left.ruleId === right.ruleId &&
368
+ sameWireParams(left.params, right.params));
369
+ case 'required':
370
+ return (right.kind === 'required' &&
371
+ left.missing === right.missing &&
372
+ left.fieldId === right.fieldId &&
373
+ left.rowKey === right.rowKey &&
374
+ left.messageKey === right.messageKey &&
375
+ sameWireParams(left.params, right.params));
376
+ case 'invalid-value':
377
+ return right.kind === 'invalid-value' && left.code === right.code;
378
+ case 'cardinality':
379
+ return (right.kind === 'cardinality' &&
380
+ left.bound === right.bound &&
381
+ left.count === right.count &&
382
+ left.limit === right.limit);
383
+ case 'access':
384
+ return right.kind === 'access' && left.access === right.access;
385
+ case 'gate':
386
+ return (right.kind === 'gate' &&
387
+ left.gateId === right.gateId &&
388
+ left.itemId === right.itemId &&
389
+ left.messageKey === right.messageKey &&
390
+ sameWireParams(left.params, right.params));
391
+ case 'screen':
392
+ return (right.kind === 'screen' &&
393
+ left.screenId === right.screenId &&
394
+ left.messageKey === right.messageKey &&
395
+ left.outcome === right.outcome &&
396
+ sameScreenReasons(left.reasons, right.reasons));
397
+ case 'row-key':
398
+ return right.kind === 'row-key' && left.rowKey === right.rowKey && left.code === right.code;
399
+ }
400
+ }
401
+ /**
402
+ * Whether two screens state the same reasons, in the same order, with the same bindings.
403
+ *
404
+ * Exported because `sameFormSummary` compares the same value; a weaker comparator beside this
405
+ * one would let two screens a reader sees as different compare equal in the memo.
406
+ */
407
+ export function sameScreenReasons(left, right) {
408
+ return (left.length === right.length &&
409
+ left.every((reason, index) => {
410
+ const other = right[index];
411
+ return (other !== undefined &&
412
+ reason.code === other.code &&
413
+ reason.messageKey === other.messageKey &&
414
+ sameWireParams(reason.params, other.params));
415
+ }));
416
+ }
417
+ //# sourceMappingURL=derive.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"derive.js","sourceRoot":"","sources":["../../src/store/derive.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,aAAa,EAAE,MAAM,wBAAwB,CAAC;AAYpE,OAAO,EAAE,kBAAkB,EAAE,UAAU,EAAE,YAAY,EAAE,MAAM,mBAAmB,CAAC;AAGjF,OAAO,EAAE,aAAa,EAAE,MAAM,aAAa,CAAC;AAE5C,OAAO,EAAE,eAAe,EAAE,MAAM,yBAAyB,CAAC;AAE1D,OAAO,EAAE,aAAa,EAAE,MAAM,aAAa,CAAC;AAG5C,OAAO,EAAE,YAAY,EAAE,eAAe,EAAE,MAAM,iBAAiB,CAAC;AAqEhE;;;;;;;GAOG;AACH,MAAM,UAAU,gBAAgB,CAAC,OAAsB;IACrD,MAAM,EAAE,KAAK,EAAE,IAAI,EAAE,OAAO,EAAE,UAAU,EAAE,OAAO,EAAE,GAAG,OAAO,CAAC;IAC9D,MAAM,KAAK,GAAG,KAAK,CAAC,KAAK,CAAC,IAAI,KAAK,OAAO,CAAC,CAAC,CAAC,KAAK,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC,CAAC,SAAS,CAAC;IAC3E,MAAM,YAAY,GAAG,aAAa,CAAC,KAAK,CAAC,CAAC;IAC1C,wFAAwF;IACxF,yFAAyF;IACzF,MAAM,MAAM,GACV,IAAI,CAAC,OAAO,KAAK,SAAS;QACxB,CAAC,CAAC,YAAY;QACd,CAAC,CAAC;YACE,MAAM,EAAE,MAAM,CAAC,MAAM,CAAC,CAAC,GAAG,YAAY,CAAC,MAAM,EAAE,IAAI,CAAC,OAAO,CAAC,CAAC;YAC7D,mBAAmB,EAAE,YAAY,CAAC,mBAAmB;YACrD,OAAO,EAAE,YAAY,CAAC,OAAO;SAC9B,CAAC;I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AE9B,OAAO,CACL,IAAI,CAAC,MAAM,KAAK,KAAK,CAAC,MAAM;QAC5B,IAAI,CAAC,KAAK,CAAC,CAAC,MAAM,EAAE,KAAK,EAAE,EAAE;YAC3B,MAAM,KAAK,GAAG,KAAK,CAAC,KAAK,CAAC,CAAC;YAC3B,OAAO,CACL,KAAK,KAAK,SAAS;gBACnB,MAAM,CAAC,IAAI,KAAK,KAAK,CAAC,IAAI;gBAC1B,MAAM,CAAC,UAAU,KAAK,KAAK,CAAC,UAAU;gBACtC,cAAc,CAAC,MAAM,CAAC,MAAM,EAAE,KAAK,CAAC,MAAM,CAAC,CAC5C,CAAC;QACJ,CAAC,CAAC,CACH,CAAC;AACJ,CAAC","sourcesContent":["import { assertNever, sameWireValue } from '@azx-pbc/axiom-runtime';\nimport type {\n CompiledField,\n EngineFieldState,\n FieldMessage,\n FieldRef,\n EvaluatedSuggestion,\n ScreenReason,\n SuggestedOperation,\n UnavailableOption,\n WireValue,\n} from '@azx-pbc/axiom-runtime';\nimport { fieldDescriptionId, fieldDomId, fieldErrorId } from '../field-props.js';\nimport type { FieldA11y, FieldProps } from '../field-props.js';\nimport type { FieldError } from '../field-error.js';\nimport { getInputHints } from '../hints.js';\nimport type { InputHints } from '../hints.js';\nimport { renderFieldText } from '../render/value-text.js';\nimport type { ValueDisplay } from '../render/value-text.js';\nimport { bindingErrors } from './errors.js';\nimport type { RowKeyFieldError } from '../field-error.js';\nimport type { BindingVisibility, ShowErrorsPolicy } from './visibility.js';\nimport { showsErrorOf, visibleErrorsOf } from './visibility.js';\n\n/** The display-only inputs a provider supplies; none of them reaches an evaluation. */\nexport interface DisplayOptions {\n /** When a decided failure is painted; the one policy that governs every binding. */\n readonly reveal: ShowErrorsPolicy;\n readonly maskedDisplay: Readonly<Record<string, string>> | undefined;\n /**\n * The host's display formatter for a value a control shows but does not edit.\n *\n * It answers the text a boolean, a list, a money amount or any other value reads as in the\n * host's locale. The library ships no words of its own: without this port a boolean and a list\n * render as empty text rather than as the English `true`/`false` or a comma-joined list.\n */\n readonly valueDisplay: ValueDisplay | undefined;\n /**\n * The prefix every element id this session emits begins with.\n *\n * It is what keeps two providers over one artifact from emitting the same `id`, `htmlFor` and\n * `aria-describedby` values: `bindingKey` is identical in both, so the session has to state\n * its own identity. `FormProvider` settles it once per mount — the host's `idPrefix` when it\n * names one, `useId()` otherwise — and the store carries it on every display it derives, so\n * the id of a binding never depends on which pass or which hook read it.\n */\n readonly idPrefix: string;\n}\n\n/** The session facts the engine does not own, per binding. */\nexport interface BindingView {\n /** Whether the user has visited this binding: a blur, or a deliberate write. */\n readonly touched: boolean;\n /** Whether an explicit blur recorded the visit, which the legacy `onBlur` mode reads. */\n readonly blurred: boolean;\n /** Whether the user deliberately wrote this binding. */\n readonly changed: boolean;\n /** Whether a submit has been attempted in this session. */\n readonly submitted: boolean;\n /** Whether a submission is in flight, the state `aria-busy` announces for a deferred binding. */\n readonly submitting: boolean;\n /** The last entry the session refused because it would break row identity. */\n readonly refusal: RowKeyFieldError | undefined;\n /** The failures this binding has already painted, which stay painted while they are true. */\n readonly revealed: ReadonlySet<string>;\n /** The value the device was delivered at the baseline, which `initialValue` reports. */\n readonly initialValue: WireValue | undefined;\n /** The value the *record* held at the baseline; `dirty` compares against this one. */\n readonly initialHeld: WireValue | undefined;\n}\n\n/** The stable callbacks one binding's control is handed. */\nexport interface BindingWriters {\n readonly setValue: (value: WireValue) => void;\n readonly setNull: () => void;\n readonly removeValue: () => void;\n readonly onBlur: () => void;\n}\n\n/** Everything one binding's props are derived from. */\nexport interface DeriveContext {\n readonly state: EngineFieldState;\n readonly descriptor: CompiledField;\n readonly bindingKey: string;\n readonly view: BindingView;\n readonly display: DisplayOptions;\n readonly visibility: BindingVisibility;\n readonly writers: BindingWriters;\n readonly signature: string;\n}\n\n/**\n * Maps one engine binding state to the props a control renders.\n *\n * The engine owns visibility, access, delivery, the computed value and the messages; this adds\n * only what a session and a host own — the value's move from its baseline, the touch flag, the\n * display rule and the input hints — so there is no second classifier and no second access\n * resolver here.\n */\nexport function deriveFieldProps(context: DeriveContext): FieldProps {\n const { state, view, display, visibility, writers } = context;\n const value = state.value.kind === 'value' ? state.value.value : undefined;\n const engineErrors = bindingErrors(state);\n // A refused entry is not a fact about the record, so it is appended to the derived list\n // rather than cached with the engine state: the record the binding shows is still valid.\n const errors =\n view.refusal === undefined\n ? engineErrors\n : {\n errors: Object.freeze([...engineErrors.errors, view.refusal]),\n readOnlyDiagnostics: engineErrors.readOnlyDiagnostics,\n invalid: engineErrors.invalid,\n };\n const readOnly = state.access === 'read_only';\n // `read_only` is announced with `readOnly`, not `disabled`: a disabled input leaves the tab\n // order and cannot be copied, which is not what a value the user is meant to read should do.\n // `enabled` still states \"may accept a user write\"; `disabled` states the element attribute.\n const disabled = !state.enabled && !readOnly;\n const invalid = errors.invalid;\n const visibleErrors = visibleErrorsOf(state, view, display.reveal, visibility);\n const showError = showsErrorOf(visibleErrors);\n // Masked is the one access state with no value to bind at all, so the binding states the text\n // to render in its place: an input (or a buffer) would show an empty control, and every\n // keystroke would be refused.\n const maskedText =\n state.access === 'masked' ? (display.maskedDisplay?.[state.fieldId] ?? '') : undefined;\n return {\n fieldId: state.fieldId,\n ...(state.rowKey === undefined ? {} : { rowKey: state.rowKey }),\n bindingKey: context.bindingKey,\n descriptor: context.descriptor,\n value,\n text: renderFieldText(\n { value, maskedText, computation: state.computation, descriptor: context.descriptor },\n display.valueDisplay,\n ),\n initialValue: view.initialValue,\n access: state.access,\n visible: state.visible,\n enabled: state.enabled,\n // The runtime answers fillability once: the write predicate plus the facts the engine\n // refuses before it and visibility. A control gating an affordance on this cannot offer a\n // write the session would refuse.\n mayWrite: state.fillable,\n disabled,\n readOnly,\n required: state.required,\n ...(state.cardinality === undefined || state.cardinality.kind === 'undetermined'\n ? {}\n : {\n rowCount: state.cardinality.count,\n ...(state.cardinality.kind === 'belowMin'\n ? {\n countViolation: {\n kind: 'belowMin' as const,\n count: state.cardinality.count,\n limit: state.cardinality.minItems,\n },\n }\n : state.cardinality.kind === 'aboveMax'\n ? {\n countViolation: {\n kind: 'aboveMax' as const,\n count: state.cardinality.count,\n limit: state.cardinality.maxItems,\n },\n }\n : {}),\n }),\n computation: state.computation,\n ...(state.unavailableOptions === undefined\n ? {}\n : { unavailableOptions: state.unavailableOptions }),\n messages: state.messages,\n errors: errors.errors,\n visibleErrors,\n readOnlyDiagnostics: errors.readOnlyDiagnostics,\n invalid,\n showError,\n touched: view.touched,\n dirty: dirtyOf(state, view),\n maskedText,\n withheld: state.value.kind === 'withheld',\n ...(state.value.kind === 'withheld' ? { withheldReason: state.value.reason } : {}),\n a11y: a11yOf(\n // A requirement the reader cannot act on is not marked: a value the record withholds is\n // the tier that holds it to settle. A session-written `write_only` value is settled too;\n // only the genuinely empty arm asks this reader for an answer.\n state.required &&\n state.value.kind !== 'withheld' &&\n !(\n state.access === 'write_only' &&\n state.value.kind === 'value' &&\n state.value.value !== null\n ),\n showError,\n disabled,\n readOnly,\n display.idPrefix,\n context.bindingKey,\n state.descriptionKey !== undefined,\n busyOf(state, view.submitting),\n ),\n hints: hintsOf(state),\n signature: context.signature,\n setValue: writers.setValue,\n onChange: writers.setValue,\n setNull: writers.setNull,\n removeValue: writers.removeValue,\n onBlur: writers.onBlur,\n };\n}\n\n/**\n * Whether a binding's value moved from the session's baseline, with `empty()` semantics.\n *\n * The comparison is against the value the *record* held, which no access answer can change: a\n * value that becomes readable was always there, so widening a mask over an untouched record is\n * not an edit. A value a writer owns is derived from the record rather than entered in it, so it\n * is never an edit either. A value this device may not read is one it cannot compare — and one\n * the submission projection would not carry — so it is reported as unmoved rather than guessed at.\n */\nexport function dirtyOf(state: EngineFieldState, view: BindingView): boolean {\n if (state.systemComputed) return false;\n switch (state.value.kind) {\n case 'value':\n return !sameHeld(state.value.value, view.initialHeld);\n case 'absent':\n return !isEmptyHeld(view.initialHeld);\n case 'withheld':\n return false;\n }\n}\n\n/** `empty()` treats the authored `null` and an absent value as one empty state. */\nfunction isEmptyHeld(value: WireValue | undefined): boolean {\n return value === undefined || value === null;\n}\n\n/** Whether two held values state the same fact; `empty()` semantics, then wire equality. */\nfunction sameHeld(left: WireValue | undefined, right: WireValue | undefined): boolean {\n if (isEmptyHeld(left) || isEmptyHeld(right)) return isEmptyHeld(left) && isEmptyHeld(right);\n return sameWireValue(left, right);\n}\n\n/** The hint table is the only control-to-hint authority; this only remembers the answer. */\nfunction hintsOf(state: EngineFieldState): InputHints {\n return getInputHints(state.control);\n}\n\n/** Whether two derivations say the same thing, so a re-derivation keeps the props identity. */\nexport function sameFieldProps(left: FieldProps, right: FieldProps): boolean {\n return (\n left.fieldId === right.fieldId &&\n left.rowKey === right.rowKey &&\n left.bindingKey === right.bindingKey &&\n left.descriptor === right.descriptor &&\n sameWireValue(left.value, right.value) &&\n left.text === right.text &&\n sameWireValue(left.initialValue, right.initialValue) &&\n left.access === right.access &&\n left.visible === right.visible &&\n left.enabled === right.enabled &&\n left.mayWrite === right.mayWrite &&\n left.disabled === right.disabled &&\n left.readOnly === right.readOnly &&\n left.required === right.required &&\n sameUnavailableOptions(left.unavailableOptions, right.unavailableOptions) &&\n sameComputation(left.computation, right.computation) &&\n sameMessages(left.messages, right.messages) &&\n sameFieldErrors(left.errors, right.errors) &&\n sameFieldErrors(left.visibleErrors, right.visibleErrors) &&\n sameFieldErrors(left.readOnlyDiagnostics, right.readOnlyDiagnostics) &&\n left.invalid === right.invalid &&\n left.showError === right.showError &&\n left.touched === right.touched &&\n left.dirty === right.dirty &&\n left.maskedText === right.maskedText &&\n left.withheld === right.withheld &&\n left.withheldReason === right.withheldReason &&\n sameA11y(left.a11y, right.a11y) &&\n left.hints === right.hints &&\n left.setValue === right.setValue &&\n left.onChange === right.onChange &&\n left.setNull === right.setNull &&\n left.removeValue === right.removeValue &&\n left.onBlur === right.onBlur\n );\n}\n\n/**\n * Whether two availability answers state the same refusal.\n *\n * The list is the binding's only sign that an option the domain offers may not be chosen, so a\n * column that changed while every other published fact stayed put still has to replace the props\n * object: reusing the previous one would keep a control painting the option as offered.\n */\nfunction sameUnavailableOptions(\n left: readonly UnavailableOption[] | undefined,\n right: readonly UnavailableOption[] | undefined,\n): boolean {\n if (left === undefined || right === undefined) return left === right;\n return (\n left.length === right.length &&\n left.every((option, index) => {\n const other = right[index];\n return (\n other !== undefined &&\n option.code === other.code &&\n option.state === other.state &&\n option.messageKey === other.messageKey &&\n option.cause === other.cause &&\n sameWireParams(option.params, other.params)\n );\n })\n );\n}\n\n/** Whether two computed values state the same fact; the engine's own union, exhaustively. */\nfunction sameComputation(\n left: FieldProps['computation'],\n right: FieldProps['computation'],\n): boolean {\n switch (left.kind) {\n case 'none':\n return right.kind === 'none';\n case 'withheld':\n return right.kind === 'withheld';\n case 'value':\n return right.kind === 'value' && sameWireValue(left.value, right.value);\n case 'undetermined':\n return right.kind === 'undetermined' && left.status === right.status;\n }\n}\n\n/**\n * One frozen object per combination of the four attributes a control sets.\n *\n * The ids and the busy flag are per binding and are added beside the cached combination rather\n * than inside it: six identities multiplied by every row would be a cache with the record's\n * cardinality. `sameA11y` compares the whole shape by value, so a fresh wrapper does not replace\n * a binding's props on every pass — the identity the sibling-render test pins is the props\n * object, and this keeps it decided by the facts rather than by allocation.\n */\nconst A11Y: readonly A11yBase[] = Array.from({ length: 16 }, (_, bits) =>\n Object.freeze({\n required: (bits & 1) !== 0,\n invalid: (bits & 2) !== 0,\n disabled: (bits & 4) !== 0,\n readOnly: (bits & 8) !== 0,\n }),\n);\n\nfunction a11yOf(\n required: boolean,\n invalid: boolean,\n disabled: boolean,\n readOnly: boolean,\n idPrefix: string,\n bindingKey: string,\n hasDescription: boolean,\n busy: boolean,\n): FieldA11y {\n const index = (required ? 1 : 0) | (invalid ? 2 : 0) | (disabled ? 4 : 0) | (readOnly ? 8 : 0);\n // The index is a bitmask over four booleans, so every value is one of the sixteen entries.\n const base = A11Y[index];\n if (base === undefined) throw new Error('unreachable a11y combination');\n return {\n required: base.required,\n invalid: base.invalid,\n disabled: base.disabled,\n readOnly: base.readOnly,\n controlId: fieldDomId(idPrefix, bindingKey),\n errorId: fieldErrorId(idPrefix, bindingKey),\n // A binding that declares no description renders no element, so naming an id for one would\n // make every `aria-describedby` that used it a dangling IDREF.\n ...(hasDescription ? { descriptionId: fieldDescriptionId(idPrefix, bindingKey) } : {}),\n busy,\n };\n}\n\n/** The four cached attributes; the ids and the busy flag come from the binding. */\ntype A11yBase = Omit<FieldA11y, 'controlId' | 'errorId' | 'descriptionId' | 'busy'>;\n\n/** Whether two a11y answers state the same relations, so the cached props keep their identity. */\nfunction sameA11y(left: FieldA11y, right: FieldA11y): boolean {\n return (\n left.controlId === right.controlId &&\n left.errorId === right.errorId &&\n left.descriptionId === right.descriptionId &&\n left.busy === right.busy &&\n left.required === right.required &&\n left.invalid === right.invalid &&\n left.disabled === right.disabled &&\n left.readOnly === right.readOnly\n );\n}\n\n/**\n * Whether `aria-busy` should announce this control.\n *\n * A deferred failure is the server's handoff, not a refusal, and at rest the device is not\n * waiting for anything: announcing it as busy made a client artifact's controls look like they\n * were loading forever. The one moment the answer really is in flight is a submission that may\n * settle the check, so that is the only state reported. The readiness summary counts the same\n * deferred fact once for the form in `hasDeferredChecks`.\n */\nfunction busyOf(state: EngineFieldState, submitting: boolean): boolean {\n return submitting && state.messages.some((message) => message.status === 'DEFERRED');\n}\n\n/** Whether two message lists state the same failures; a new engine rebuilds the arrays. */\nfunction sameMessages(left: readonly FieldMessage[], right: readonly FieldMessage[]): boolean {\n return (\n left.length === right.length &&\n left.every((message, index) => {\n const other = right[index];\n return other !== undefined && sameMessage(message, other);\n })\n );\n}\n\nfunction sameMessage(left: FieldMessage, right: FieldMessage): boolean {\n return (\n left.ruleId === right.ruleId &&\n left.severity === right.severity &&\n left.status === right.status &&\n left.messageKey === right.messageKey &&\n sameWireParams(left.params, right.params)\n );\n}\n\n/** Whether two message parameter sets state the same arguments, at any depth. */\nexport function sameWireParams(\n left: Readonly<Record<string, WireValue>> | undefined,\n right: Readonly<Record<string, WireValue>> | undefined,\n): boolean {\n if (left === undefined || right === undefined) return left === right;\n const keys = Object.keys(left);\n if (keys.length !== Object.keys(right).length) return false;\n return keys.every((key) => sameWireValue(left[key], right[key]));\n}\n\n/** Whether two evaluated alternatives state the same operations and concrete values. */\nexport function sameSuggestions(\n left: readonly EvaluatedSuggestion[] | undefined,\n right: readonly EvaluatedSuggestion[] | undefined,\n): boolean {\n if (left === undefined || right === undefined) return left === right;\n return (\n left.length === right.length &&\n left.every((suggestion, index) => {\n const other = right[index];\n return (\n other !== undefined &&\n suggestion.labelKey === other.labelKey &&\n suggestion.disabledReason === other.disabledReason &&\n sameSuggestedOperations(suggestion.operations, other.operations)\n );\n })\n );\n}\n\nfunction sameSuggestedOperations(\n left: readonly SuggestedOperation[],\n right: readonly SuggestedOperation[],\n): boolean {\n return (\n left.length === right.length &&\n left.every((operation, index) => {\n const other = right[index];\n return other !== undefined && sameSuggestedOperation(operation, other);\n })\n );\n}\n\nfunction sameSuggestedOperation(left: SuggestedOperation, right: SuggestedOperation): boolean {\n if (left.kind !== right.kind) return false;\n switch (left.kind) {\n case 'value':\n return (\n right.kind === 'value' &&\n sameFieldRef(left.ref, right.ref) &&\n sameWireValue(left.value, right.value)\n );\n case 'null':\n case 'remove':\n return (\n (right.kind === 'null' || right.kind === 'remove') && sameFieldRef(left.ref, right.ref)\n );\n case 'append':\n return (\n right.kind === 'append' &&\n left.fieldId === right.fieldId &&\n sameWireParams(left.row, right.row)\n );\n case 'removeRow':\n return (\n right.kind === 'removeRow' && left.fieldId === right.fieldId && left.rowKey === right.rowKey\n );\n default:\n return assertNever(left);\n }\n}\n\nfunction sameFieldRef(left: FieldRef, right: FieldRef): boolean {\n return left.fieldId === right.fieldId && left.rowKey === right.rowKey;\n}\n\n/** Whether two media limits name the same admitted types or the same byte bound. */\nexport function sameMediaLimit(\n left: readonly string[] | number,\n right: readonly string[] | number,\n): boolean {\n if (typeof left === 'number' || typeof right === 'number') return left === right;\n return left.length === right.length && left.every((entry, index) => entry === right[index]);\n}\n\n/** Whether two derived error lists state the same reasons, which a new engine rebuilds. */\nexport function sameFieldErrors(\n left: readonly FieldError[],\n right: readonly FieldError[],\n): boolean {\n return (\n left.length === right.length &&\n left.every((error, index) => {\n const other = right[index];\n return other !== undefined && sameError(error, other);\n })\n );\n}\n\nfunction sameError(left: FieldError, right: FieldError): boolean {\n switch (left.kind) {\n case 'validate':\n case 'deferred':\n return (\n right.kind === left.kind &&\n left.blocking === right.blocking &&\n left.severity === right.severity &&\n left.status === right.status &&\n left.messageKey === right.messageKey &&\n left.ruleId === right.ruleId &&\n sameWireParams(left.params, right.params)\n );\n case 'required':\n return (\n right.kind === 'required' &&\n left.missing === right.missing &&\n left.fieldId === right.fieldId &&\n left.rowKey === right.rowKey &&\n left.messageKey === right.messageKey &&\n sameWireParams(left.params, right.params)\n );\n case 'invalid-value':\n return right.kind === 'invalid-value' && left.code === right.code;\n case 'cardinality':\n return (\n right.kind === 'cardinality' &&\n left.bound === right.bound &&\n left.count === right.count &&\n left.limit === right.limit\n );\n case 'access':\n return right.kind === 'access' && left.access === right.access;\n case 'gate':\n return (\n right.kind === 'gate' &&\n left.gateId === right.gateId &&\n left.itemId === right.itemId &&\n left.messageKey === right.messageKey &&\n sameWireParams(left.params, right.params)\n );\n case 'screen':\n return (\n right.kind === 'screen' &&\n left.screenId === right.screenId &&\n left.messageKey === right.messageKey &&\n left.outcome === right.outcome &&\n sameScreenReasons(left.reasons, right.reasons)\n );\n case 'row-key':\n return right.kind === 'row-key' && left.rowKey === right.rowKey && left.code === right.code;\n }\n}\n\n/**\n * Whether two screens state the same reasons, in the same order, with the same bindings.\n *\n * Exported because `sameFormSummary` compares the same value; a weaker comparator beside this\n * one would let two screens a reader sees as different compare equal in the memo.\n */\nexport function sameScreenReasons(\n left: readonly ScreenReason[],\n right: readonly ScreenReason[],\n): boolean {\n return (\n left.length === right.length &&\n left.every((reason, index) => {\n const other = right[index];\n return (\n other !== undefined &&\n reason.code === other.code &&\n reason.messageKey === other.messageKey &&\n sameWireParams(reason.params, other.params)\n );\n })\n );\n}\n"]}
@@ -0,0 +1,20 @@
1
+ import type { EngineFieldState } from '@azx-pbc/axiom-runtime';
2
+ import type { FieldError } from '../field-error.js';
3
+ /** What one binding's errors say, with the read-only subset a display groups out. */
4
+ interface BindingErrors {
5
+ readonly errors: readonly FieldError[];
6
+ /** The errors of a `read_only` or `masked` binding, which a control shows beside itself. */
7
+ readonly readOnlyDiagnostics: readonly FieldError[];
8
+ /** Whether any error stops a submission on this device. */
9
+ readonly invalid: boolean;
10
+ }
11
+ /**
12
+ * Derives one binding's errors from the engine's frozen state.
13
+ *
14
+ * Memoised by the state object, which the engine hands back unchanged while a binding's facts
15
+ * hold, so a control that reads its errors twice reads the same arrays and its published props
16
+ * keep their identity across an unrelated write.
17
+ */
18
+ export declare function bindingErrors(state: EngineFieldState): BindingErrors;
19
+ export {};
20
+ //# sourceMappingURL=errors.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"errors.d.ts","sourceRoot":"","sources":["../../src/store/errors.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,wBAAwB,CAAC;AAC/D,OAAO,KAAK,EAEV,UAAU,EAGX,MAAM,mBAAmB,CAAC;AAE3B,qFAAqF;AACrF,UAAU,aAAa;IACrB,QAAQ,CAAC,MAAM,EAAE,SAAS,UAAU,EAAE,CAAC;IACvC,4FAA4F;IAC5F,QAAQ,CAAC,mBAAmB,EAAE,SAAS,UAAU,EAAE,CAAC;IACpD,2DAA2D;IAC3D,QAAQ,CAAC,OAAO,EAAE,OAAO,CAAC;CAC3B;AAID;;;;;;GAMG;AACH,wBAAgB,aAAa,CAAC,KAAK,EAAE,gBAAgB,GAAG,aAAa,CAgGpE"}
@@ -0,0 +1,101 @@
1
+ import { OPTION_NO_LONGER_ELIGIBLE } from '@azx-pbc/axiom-runtime';
2
+ const CACHE = new WeakMap();
3
+ /**
4
+ * Derives one binding's errors from the engine's frozen state.
5
+ *
6
+ * Memoised by the state object, which the engine hands back unchanged while a binding's facts
7
+ * hold, so a control that reads its errors twice reads the same arrays and its published props
8
+ * keep their identity across an unrelated write.
9
+ */
10
+ export function bindingErrors(state) {
11
+ const cached = CACHE.get(state);
12
+ if (cached !== undefined)
13
+ return cached;
14
+ const errors = [];
15
+ for (const message of state.messages) {
16
+ errors.push(Object.freeze({
17
+ kind: message.status === 'DEFERRED' ? 'deferred' : 'validate',
18
+ // Only a decided `FAIL` is a failure a control announces. A server-tier check that has
19
+ // not run is a handoff, and an `UNKNOWN` result is a check the device could not decide
20
+ // (`RULES-2.1.1`): both leave `invalid` false, so `showError` stays false and the form's
21
+ // undetermined state is reported once, by the summary and `verdict`.
22
+ blocking: message.severity === 'block' && message.status === 'FAIL',
23
+ severity: message.severity,
24
+ status: message.status,
25
+ messageKey: message.messageKey,
26
+ ruleId: message.ruleId,
27
+ ...(message.params === undefined ? {} : { params: message.params }),
28
+ }));
29
+ }
30
+ // Only the decided `missing` is the user's failure. `undetermined` covers a server-tier
31
+ // answer this device cannot settle and a value the server withheld on purpose (`redacted`):
32
+ // it leaves the form unready, but it is not a blocking reason the user can act on, and
33
+ // announcing it as `required` accused the user of a value the server chose not to send.
34
+ if (state.visible && state.required && state.missingRequired === 'missing') {
35
+ const rowName = state.rowKey !== undefined &&
36
+ (state.rowAddressing === 'natural' || state.rowAddressing === 'value')
37
+ ? String(state.rowKey)
38
+ : undefined;
39
+ errors.push(Object.freeze({
40
+ kind: 'required',
41
+ blocking: true,
42
+ status: 'FAIL',
43
+ missing: 'missing',
44
+ fieldId: state.fieldId,
45
+ ...(state.rowKey === undefined ? {} : { rowKey: state.rowKey }),
46
+ ...(rowName === undefined ? {} : { rowName }),
47
+ ...(state.requiredMessageKey === undefined ? {} : { messageKey: state.requiredMessageKey }),
48
+ ...(state.requiredParams === undefined ? {} : { params: state.requiredParams }),
49
+ }));
50
+ }
51
+ // A count outside the declared range is a decided refusal with no artifact sentence: like a
52
+ // missing required value, the host writes the text, and the error carries both numbers.
53
+ if (state.visible &&
54
+ state.cardinality !== undefined &&
55
+ (state.cardinality.kind === 'belowMin' || state.cardinality.kind === 'aboveMax')) {
56
+ errors.push(Object.freeze({
57
+ kind: 'cardinality',
58
+ blocking: true,
59
+ status: 'FAIL',
60
+ bound: state.cardinality.kind === 'belowMin' ? 'minItems' : 'maxItems',
61
+ count: state.cardinality.count,
62
+ limit: state.cardinality.kind === 'belowMin'
63
+ ? state.cardinality.minItems
64
+ : state.cardinality.maxItems,
65
+ }));
66
+ }
67
+ if (state.invalidValue !== undefined) {
68
+ const invalid = Object.freeze({
69
+ kind: 'invalid-value',
70
+ code: OPTION_NO_LONGER_ELIGIBLE,
71
+ blocking: true,
72
+ status: 'FAIL',
73
+ });
74
+ errors.push(invalid);
75
+ }
76
+ // The access error states that access withholds the value — `masked`, `hidden` or
77
+ // `write_only`. A `redacted` value is withheld by the *server*, not by the resolved access,
78
+ // and on a writable binding the user can still act; saying "not editable" there was false.
79
+ if (state.value.kind === 'withheld' && state.value.reason !== 'redacted') {
80
+ const withheld = Object.freeze({
81
+ kind: 'access',
82
+ blocking: false,
83
+ access: state.access,
84
+ });
85
+ errors.push(withheld);
86
+ }
87
+ const readOnly = state.access === 'read_only' || state.access === 'masked';
88
+ const derived = Object.freeze({
89
+ errors: Object.freeze(errors),
90
+ readOnlyDiagnostics: readOnly
91
+ ? Object.freeze(errors.filter(isRuleError))
92
+ : Object.freeze([]),
93
+ invalid: errors.some((error) => error.blocking),
94
+ });
95
+ CACHE.set(state, derived);
96
+ return derived;
97
+ }
98
+ function isRuleError(error) {
99
+ return error.kind === 'validate' || error.kind === 'deferred';
100
+ }
101
+ //# sourceMappingURL=errors.js.map