@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,301 @@
1
+ import { isRecord, sameWireValue } from '@azx-pbc/axiom-runtime';
2
+ import { bindingKey } from './bindings.js';
3
+ export class SessionView {
4
+ /** Bindings an explicit blur recorded, keyed by the reference the summary can re-derive. */
5
+ touched = new Map();
6
+ /** Bindings a user write recorded because the value actually moved from where it was. */
7
+ edited = new Map();
8
+ /** Bindings a deliberate user write recorded, so a display rule can tell an edit from an opening value. */
9
+ changed = new Map();
10
+ /** The last refused entry per binding, kept until that binding or its array moves again. */
11
+ refusals = new Map();
12
+ /**
13
+ * The failures this session has already painted, per binding.
14
+ *
15
+ * A key is removed only when the failure it names is corrected (or the session resets), so a
16
+ * failure that is still true never flickers out because a sibling operand was cleared. The set
17
+ * object is replaced only when its members change, because it is part of the published binding
18
+ * view's identity.
19
+ */
20
+ revealed = new Map();
21
+ baselines = new Map();
22
+ views = new Map();
23
+ submitting = false;
24
+ /**
25
+ * Re-baselines every binding from committed state; a reset starts a new comparison.
26
+ *
27
+ * The baseline records both what the device may read and what the record held, because they
28
+ * answer different questions: `initialValue` reports the former, and `dirty` asks whether the
29
+ * *record* moved, which no access answer can cause.
30
+ */
31
+ capture(form, held) {
32
+ const baselines = new Map();
33
+ for (const field of form.fields) {
34
+ const key = bindingKey(field.fieldId, undefined);
35
+ baselines.set(key, { visible: delivered(field.value), held: held.get(key) });
36
+ for (const row of field.rows ?? []) {
37
+ const rowKey = bindingKey(field.fieldId, row.rowKey);
38
+ baselines.set(rowKey, { visible: delivered(row.value), held: held.get(rowKey) });
39
+ }
40
+ }
41
+ this.baselines = baselines;
42
+ this.touched = new Map();
43
+ this.edited = new Map();
44
+ this.changed = new Map();
45
+ this.refusals.clear();
46
+ this.revealed.clear();
47
+ this.views.clear();
48
+ }
49
+ /** What one binding held at the baseline; a binding the record gained since holds nothing. */
50
+ baselineOf(key) {
51
+ return this.baselines.get(key) ?? NO_BASELINE;
52
+ }
53
+ /**
54
+ * One binding's view, reusing the cached object while every fact it states holds.
55
+ *
56
+ * `submitted` comes from the session's submit count rather than a second flag here, so the
57
+ * control and the form summary cannot disagree about whether a submit was attempted.
58
+ */
59
+ viewFor(key, submitted) {
60
+ const cached = this.views.get(key);
61
+ const blurred = this.touched.has(key);
62
+ const edited = this.edited.has(key);
63
+ const changed = this.changed.has(key);
64
+ const touched = blurred || edited;
65
+ const baseline = this.baselineOf(key);
66
+ const refusal = this.refusals.get(key);
67
+ const revealed = this.revealedOf(key);
68
+ if (cached !== undefined &&
69
+ cached.touched === touched &&
70
+ cached.blurred === blurred &&
71
+ cached.changed === changed &&
72
+ cached.submitted === submitted &&
73
+ cached.submitting === this.submitting &&
74
+ cached.refusal === refusal &&
75
+ cached.revealed === revealed &&
76
+ sameWireValue(cached.initialValue, baseline.visible) &&
77
+ sameWireValue(cached.initialHeld, baseline.held)) {
78
+ return cached;
79
+ }
80
+ const view = Object.freeze({
81
+ touched,
82
+ blurred,
83
+ changed,
84
+ submitted,
85
+ submitting: this.submitting,
86
+ refusal,
87
+ revealed,
88
+ initialValue: baseline.visible,
89
+ initialHeld: baseline.held,
90
+ });
91
+ this.views.set(key, view);
92
+ return view;
93
+ }
94
+ /** Whether the user has visited or deliberately changed this binding. */
95
+ isAnswered(key) {
96
+ return this.touched.has(key) || this.edited.has(key);
97
+ }
98
+ /** Records that one control lost focus; the caller has already refused a no-op blur. */
99
+ markTouched(key, ref) {
100
+ if (this.touched.has(key))
101
+ return;
102
+ this.touched.set(key, ref);
103
+ this.views.delete(key);
104
+ }
105
+ /** Records that one deliberate write moved this binding's value from what it held. */
106
+ markEdited(key, ref) {
107
+ if (this.edited.has(key))
108
+ return;
109
+ this.edited.set(key, ref);
110
+ this.views.delete(key);
111
+ }
112
+ /** Records that the user wrote this binding, so `onChange` can reveal a failure it evaluated. */
113
+ markChanged(key, ref) {
114
+ if (this.changed.has(key))
115
+ return;
116
+ this.changed.set(key, ref);
117
+ this.views.delete(key);
118
+ }
119
+ /** Keeps the entry the session refused, so the control can announce why it did not take. */
120
+ markRefused(key, refusal) {
121
+ this.refusals.set(key, refusal);
122
+ }
123
+ /** Forgets a refusal the binding's next successful write answered. */
124
+ clearRefused(key) {
125
+ this.refusals.delete(key);
126
+ }
127
+ /** Forgets every refusal: a structural change moves the rows they were about. */
128
+ clearRefusals() {
129
+ this.refusals.clear();
130
+ }
131
+ /** States whether a submission is in flight, the one fact `aria-busy` may announce. */
132
+ setSubmitting(submitting) {
133
+ this.submitting = submitting;
134
+ }
135
+ /**
136
+ * Drops every fact one binding held. A row the record no longer addresses is not read again,
137
+ * and the view holds the value it showed at the session baseline; a row that returns re-derives
138
+ * it.
139
+ *
140
+ * The session facts go with the view. `touched` and `changed` are sets the user grows by using
141
+ * a control, and nothing else ever removes an entry: a list that churns rows an operator edits
142
+ * would otherwise keep one string per row it has ever shown, for the life of the session. The
143
+ * facts are equally meaningless for a key that no longer names a row — a returning row is a new
144
+ * row, and carrying its predecessor's baseline would make `dirty` compare it against a value it
145
+ * never held.
146
+ */
147
+ retire(key) {
148
+ this.views.delete(key);
149
+ this.touched.delete(key);
150
+ this.edited.delete(key);
151
+ this.changed.delete(key);
152
+ this.refusals.delete(key);
153
+ this.revealed.delete(key);
154
+ this.baselines.delete(key);
155
+ }
156
+ /** How many binding views the cache retains, so a churned list can be counted. */
157
+ retained() {
158
+ return this.views.size;
159
+ }
160
+ /** How many bindings are recorded as touched, so a churned list can count what it left. */
161
+ touchedCount() {
162
+ return this.touched.size;
163
+ }
164
+ /** How many bindings are recorded as changed, so a churned list can count what it left. */
165
+ changedCount() {
166
+ return this.changed.size;
167
+ }
168
+ /** Records the bindings a failed submit named, so their failures are revealed. */
169
+ markTouchedAll(refs) {
170
+ for (const ref of refs)
171
+ this.markTouched(bindingKey(ref.fieldId, ref.rowKey), ref);
172
+ }
173
+ /** Every touched binding, in binding-key order so the summary is a stable value. */
174
+ touchedBindings() {
175
+ return [...this.touched.keys()].sort();
176
+ }
177
+ /** Every binding the user has visited or deliberately changed, in stable key order. */
178
+ answeredBindings() {
179
+ const keys = new Set([...this.touched.keys(), ...this.edited.keys()]);
180
+ return [...keys].sort();
181
+ }
182
+ /** The failures one binding has already painted, or the shared empty set. */
183
+ revealedOf(key) {
184
+ return this.revealed.get(key)?.keys ?? NO_REVEALED;
185
+ }
186
+ /** Replaces one binding's painted-failure set, keeping its identity while the members hold. */
187
+ setRevealed(ref, keys) {
188
+ const key = bindingKey(ref.fieldId, ref.rowKey);
189
+ const previous = this.revealed.get(key);
190
+ if (keys.size === 0) {
191
+ if (previous === undefined)
192
+ return;
193
+ this.revealed.delete(key);
194
+ this.views.delete(key);
195
+ return;
196
+ }
197
+ if (previous !== undefined && sameKeys(previous.keys, keys))
198
+ return;
199
+ this.revealed.set(key, { ref, keys: Object.freeze(new Set(keys)) });
200
+ this.views.delete(key);
201
+ }
202
+ /**
203
+ * The bindings whose reveal state a reconciliation must revisit: everything the user has
204
+ * answered and everything already painted. A binding outside both sets cannot start painting a
205
+ * failure without one of these facts changing first.
206
+ */
207
+ revealCandidates() {
208
+ const refs = new Map();
209
+ for (const [key, ref] of this.touched)
210
+ refs.set(key, ref);
211
+ for (const [key, ref] of this.edited)
212
+ refs.set(key, ref);
213
+ for (const [key, ref] of this.changed)
214
+ refs.set(key, ref);
215
+ for (const [key, entry] of this.revealed)
216
+ refs.set(key, entry.ref);
217
+ return [...refs].map(([key, ref]) => ({ key, ref }));
218
+ }
219
+ }
220
+ /** The value one classification delivers, or `undefined` when this device may not read it. */
221
+ function delivered(value) {
222
+ return value.kind === 'value' ? value.value : undefined;
223
+ }
224
+ const NO_BASELINE = Object.freeze({ visible: undefined, held: undefined });
225
+ /** The shared empty reveal set, so a binding with nothing painted keeps one identity. */
226
+ const NO_REVEALED = Object.freeze(new Set());
227
+ /** Whether two reveal sets state the same failure identities. */
228
+ function sameKeys(left, right) {
229
+ if (left === right)
230
+ return true;
231
+ if (left.size !== right.size)
232
+ return false;
233
+ for (const key of left)
234
+ if (!right.has(key))
235
+ return false;
236
+ return true;
237
+ }
238
+ /**
239
+ * The value the record holds at every binding, keyed by binding key.
240
+ *
241
+ * This is the baseline `dirty` compares against, and it is read from the record rather than from
242
+ * the delivery projection because the two answer different questions: a `masked` value is absent
243
+ * from what the device may read and present in the record, and only the record says whether the
244
+ * user changed anything. A row is located by its wire-typed key in the array's committed order,
245
+ * so a move re-keys nothing.
246
+ */
247
+ export function heldValuesOf(record, form, facts) {
248
+ const held = new Map();
249
+ // Index each array container's `addressableRows` once per capture so the container and its
250
+ // members resolve each row's position in O(1) instead of scanning `form.fields` and the key
251
+ // list on every row.
252
+ const rowIndexByArray = new Map();
253
+ for (const field of form.fields) {
254
+ const keys = field.addressableRows;
255
+ if (keys === undefined || keys.length === 0)
256
+ continue;
257
+ const indexByKey = new Map();
258
+ for (let index = 0; index < keys.length; index += 1) {
259
+ const key = keys[index];
260
+ if (key !== undefined && !indexByKey.has(key))
261
+ indexByKey.set(key, index);
262
+ }
263
+ rowIndexByArray.set(field.fieldId, indexByKey);
264
+ }
265
+ for (const field of form.fields) {
266
+ const fact = facts.get(field.fieldId);
267
+ if (fact === undefined)
268
+ continue;
269
+ if (fact.arrayContainerId === undefined) {
270
+ held.set(bindingKey(field.fieldId, undefined), valueAt(record, fact.path));
271
+ }
272
+ const rows = field.rows;
273
+ if (rows === undefined || rows.length === 0)
274
+ continue;
275
+ const arrayId = fact.arrayContainerId ?? field.fieldId;
276
+ const arrayFacts = facts.get(arrayId);
277
+ const keyIndex = rowIndexByArray.get(arrayId);
278
+ const elements = arrayFacts === undefined ? undefined : valueAt(record, arrayFacts.path);
279
+ for (const row of rows) {
280
+ const index = keyIndex?.get(row.rowKey);
281
+ const element = index === undefined || !Array.isArray(elements) ? undefined : elements[index];
282
+ // A row binding of the array itself is the element; a member's row binding is that
283
+ // member inside the row, and a member of a row is addressed by its own `fieldId`.
284
+ held.set(bindingKey(field.fieldId, row.rowKey), element === undefined || fact.arrayContainerId === undefined
285
+ ? element
286
+ : valueAt(element, [field.fieldId]));
287
+ }
288
+ }
289
+ return held;
290
+ }
291
+ /** The value at one record path, or `undefined` where the record holds none. */
292
+ function valueAt(value, path) {
293
+ let current = value;
294
+ for (const segment of path) {
295
+ if (!isRecord(current) || !Object.hasOwn(current, segment))
296
+ return undefined;
297
+ current = current[segment];
298
+ }
299
+ return current;
300
+ }
301
+ //# sourceMappingURL=view.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"view.js","sourceRoot":"","sources":["../../src/store/view.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,aAAa,EAAE,MAAM,wBAAwB,CAAC;AAGjE,OAAO,EAAE,UAAU,EAAE,MAAM,eAAe,CAAC;AAqB3C,MAAM,OAAO,WAAW;IACtB,4FAA4F;IACpF,OAAO,GAAG,IAAI,GAAG,EAAoB,CAAC;IAC9C,yFAAyF;IACjF,MAAM,GAAG,IAAI,GAAG,EAAoB,CAAC;IAC7C,2GAA2G;IACnG,OAAO,GAAG,IAAI,GAAG,EAAoB,CAAC;IAC9C,4FAA4F;IAC3E,QAAQ,GAAG,IAAI,GAAG,EAA4B,CAAC;IAChE;;;;;;;OAOG;IACc,QAAQ,GAAG,IAAI,GAAG,EAAyB,CAAC;IACrD,SAAS,GAAG,IAAI,GAAG,EAAo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C;YACxC,MAAM,OAAO,GAAG,KAAK,KAAK,SAAS,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,QAAQ,CAAC,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,QAAQ,CAAC,KAAK,CAAC,CAAC;YAC9F,mFAAmF;YACnF,kFAAkF;YAClF,IAAI,CAAC,GAAG,CACN,UAAU,CAAC,KAAK,CAAC,OAAO,EAAE,GAAG,CAAC,MAAM,CAAC,EACrC,OAAO,KAAK,SAAS,IAAI,IAAI,CAAC,gBAAgB,KAAK,SAAS;gBAC1D,CAAC,CAAC,OAAO;gBACT,CAAC,CAAC,OAAO,CAAC,OAAO,EAAE,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,CACtC,CAAC;QACJ,CAAC;IACH,CAAC;IACD,OAAO,IAAI,CAAC;AACd,CAAC;AAED,gFAAgF;AAChF,SAAS,OAAO,CAAC,KAA4B,EAAE,IAAuB;IACpE,IAAI,OAAO,GAAG,KAAK,CAAC;IACpB,KAAK,MAAM,OAAO,IAAI,IAAI,EAAE,CAAC;QAC3B,IAAI,CAAC,QAAQ,CAAC,OAAO,CAAC,IAAI,CAAC,MAAM,CAAC,MAAM,CAAC,OAAO,EAAE,OAAO,CAAC;YAAE,OAAO,SAAS,CAAC;QAC7E,OAAO,GAAG,OAAO,CAAC,OAAO,CAAC,CAAC;IAC7B,CAAC;IACD,OAAO,OAAO,CAAC;AACjB,CAAC","sourcesContent":["import { isRecord, sameWireValue } from '@azx-pbc/axiom-runtime';\nimport type { FieldRef, FormState, ValueState, WireValue } from '@azx-pbc/axiom-runtime';\nimport type { RowKeyFieldError } from '../field-error.js';\nimport { bindingKey } from './bindings.js';\nimport type { BindingView } from './derive.js';\nimport type { FieldFacts } from './fields.js';\n\n/**\n * The session facts the engine does not own: what the user has touched, what a submit has\n * attempted, and the baseline `dirty` is measured from.\n *\n * Baselines are keyed by binding key — the field plus the row's wire-typed identity — so moving\n * a row never dirties it, and the integer row `1` and the text row `\"1\"` never share a baseline.\n * A view object is replaced only when the facts it states change, which is what keeps a blur on\n * one row from replacing every other row's props.\n */\n/** What one binding held at the session's baseline: what the device could read, and the record. */\nexport interface Baseline {\n /** The value the device was delivered, which is what `initialValue` reports. */\n readonly visible: WireValue | undefined;\n /** The value the record held. `dirty` compares against this, so access cannot move it. */\n readonly held: WireValue | undefined;\n}\n\nexport class SessionView {\n /** Bindings an explicit blur recorded, keyed by the reference the summary can re-derive. */\n private touched = new Map<string, FieldRef>();\n /** Bindings a user write recorded because the value actually moved from where it was. */\n private edited = new Map<string, FieldRef>();\n /** Bindings a deliberate user write recorded, so a display rule can tell an edit from an opening value. */\n private changed = new Map<string, FieldRef>();\n /** The last refused entry per binding, kept until that binding or its array moves again. */\n private readonly refusals = new Map<string, RowKeyFieldError>();\n /**\n * The failures this session has already painted, per binding.\n *\n * A key is removed only when the failure it names is corrected (or the session resets), so a\n * failure that is still true never flickers out because a sibling operand was cleared. The set\n * object is replaced only when its members change, because it is part of the published binding\n * view's identity.\n */\n private readonly revealed = new Map<string, RevealedEntry>();\n private baselines = new Map<string, Baseline>();\n private readonly views = new Map<string, BindingView>();\n private submitting = false;\n\n /**\n * Re-baselines every binding from committed state; a reset starts a new comparison.\n *\n * The baseline records both what the device may read and what the record held, because they\n * answer different questions: `initialValue` reports the former, and `dirty` asks whether the\n * *record* moved, which no access answer can cause.\n */\n capture(form: FormState, held: ReadonlyMap<string, WireValue | undefined>): void {\n const baselines = new Map<string, Baseline>();\n for (const field of form.fields) {\n const key = bindingKey(field.fieldId, undefined);\n baselines.set(key, { visible: delivered(field.value), held: held.get(key) });\n for (const row of field.rows ?? []) {\n const rowKey = bindingKey(field.fieldId, row.rowKey);\n baselines.set(rowKey, { visible: delivered(row.value), held: held.get(rowKey) });\n }\n }\n this.baselines = baselines;\n this.touched = new Map();\n this.edited = new Map();\n this.changed = new Map();\n this.refusals.clear();\n this.revealed.clear();\n this.views.clear();\n }\n\n /** What one binding held at the baseline; a binding the record gained since holds nothing. */\n baselineOf(key: string): Baseline {\n return this.baselines.get(key) ?? NO_BASELINE;\n }\n\n /**\n * One binding's view, reusing the cached object while every fact it states holds.\n *\n * `submitted` comes from the session's submit count rather than a second flag here, so the\n * control and the form summary cannot disagree about whether a submit was attempted.\n */\n viewFor(key: string, submitted: boolean): BindingView {\n const cached = this.views.get(key);\n const blurred = this.touched.has(key);\n const edited = this.edited.has(key);\n const changed = this.changed.has(key);\n const touched = blurred || edited;\n const baseline = this.baselineOf(key);\n const refusal = this.refusals.get(key);\n const revealed = this.revealedOf(key);\n if (\n cached !== undefined &&\n cached.touched === touched &&\n cached.blurred === blurred &&\n cached.changed === changed &&\n cached.submitted === submitted &&\n cached.submitting === this.submitting &&\n cached.refusal === refusal &&\n cached.revealed === revealed &&\n sameWireValue(cached.initialValue, baseline.visible) &&\n sameWireValue(cached.initialHeld, baseline.held)\n ) {\n return cached;\n }\n const view: BindingView = Object.freeze({\n touched,\n blurred,\n changed,\n submitted,\n submitting: this.submitting,\n refusal,\n revealed,\n initialValue: baseline.visible,\n initialHeld: baseline.held,\n });\n this.views.set(key, view);\n return view;\n }\n\n /** Whether the user has visited or deliberately changed this binding. */\n isAnswered(key: string): boolean {\n return this.touched.has(key) || this.edited.has(key);\n }\n\n /** Records that one control lost focus; the caller has already refused a no-op blur. */\n markTouched(key: string, ref: FieldRef): void {\n if (this.touched.has(key)) return;\n this.touched.set(key, ref);\n this.views.delete(key);\n }\n\n /** Records that one deliberate write moved this binding's value from what it held. */\n markEdited(key: string, ref: FieldRef): void {\n if (this.edited.has(key)) return;\n this.edited.set(key, ref);\n this.views.delete(key);\n }\n\n /** Records that the user wrote this binding, so `onChange` can reveal a failure it evaluated. */\n markChanged(key: string, ref: FieldRef): void {\n if (this.changed.has(key)) return;\n this.changed.set(key, ref);\n this.views.delete(key);\n }\n\n /** Keeps the entry the session refused, so the control can announce why it did not take. */\n markRefused(key: string, refusal: RowKeyFieldError): void {\n this.refusals.set(key, refusal);\n }\n\n /** Forgets a refusal the binding's next successful write answered. */\n clearRefused(key: string): void {\n this.refusals.delete(key);\n }\n\n /** Forgets every refusal: a structural change moves the rows they were about. */\n clearRefusals(): void {\n this.refusals.clear();\n }\n\n /** States whether a submission is in flight, the one fact `aria-busy` may announce. */\n setSubmitting(submitting: boolean): void {\n this.submitting = submitting;\n }\n\n /**\n * Drops every fact one binding held. A row the record no longer addresses is not read again,\n * and the view holds the value it showed at the session baseline; a row that returns re-derives\n * it.\n *\n * The session facts go with the view. `touched` and `changed` are sets the user grows by using\n * a control, and nothing else ever removes an entry: a list that churns rows an operator edits\n * would otherwise keep one string per row it has ever shown, for the life of the session. The\n * facts are equally meaningless for a key that no longer names a row — a returning row is a new\n * row, and carrying its predecessor's baseline would make `dirty` compare it against a value it\n * never held.\n */\n retire(key: string): void {\n this.views.delete(key);\n this.touched.delete(key);\n this.edited.delete(key);\n this.changed.delete(key);\n this.refusals.delete(key);\n this.revealed.delete(key);\n this.baselines.delete(key);\n }\n\n /** How many binding views the cache retains, so a churned list can be counted. */\n retained(): number {\n return this.views.size;\n }\n\n /** How many bindings are recorded as touched, so a churned list can count what it left. */\n touchedCount(): number {\n return this.touched.size;\n }\n\n /** How many bindings are recorded as changed, so a churned list can count what it left. */\n changedCount(): number {\n return this.changed.size;\n }\n\n /** Records the bindings a failed submit named, so their failures are revealed. */\n markTouchedAll(refs: readonly FieldRef[]): void {\n for (const ref of refs) this.markTouched(bindingKey(ref.fieldId, ref.rowKey), ref);\n }\n\n /** Every touched binding, in binding-key order so the summary is a stable value. */\n touchedBindings(): readonly string[] {\n return [...this.touched.keys()].sort();\n }\n\n /** Every binding the user has visited or deliberately changed, in stable key order. */\n answeredBindings(): readonly string[] {\n const keys = new Set([...this.touched.keys(), ...this.edited.keys()]);\n return [...keys].sort();\n }\n\n /** The failures one binding has already painted, or the shared empty set. */\n revealedOf(key: string): ReadonlySet<string> {\n return this.revealed.get(key)?.keys ?? NO_REVEALED;\n }\n\n /** Replaces one binding's painted-failure set, keeping its identity while the members hold. */\n setRevealed(ref: FieldRef, keys: ReadonlySet<string>): void {\n const key = bindingKey(ref.fieldId, ref.rowKey);\n const previous = this.revealed.get(key);\n if (keys.size === 0) {\n if (previous === undefined) return;\n this.revealed.delete(key);\n this.views.delete(key);\n return;\n }\n if (previous !== undefined && sameKeys(previous.keys, keys)) return;\n this.revealed.set(key, { ref, keys: Object.freeze(new Set(keys)) });\n this.views.delete(key);\n }\n\n /**\n * The bindings whose reveal state a reconciliation must revisit: everything the user has\n * answered and everything already painted. A binding outside both sets cannot start painting a\n * failure without one of these facts changing first.\n */\n revealCandidates(): readonly { readonly key: string; readonly ref: FieldRef }[] {\n const refs = new Map<string, FieldRef>();\n for (const [key, ref] of this.touched) refs.set(key, ref);\n for (const [key, ref] of this.edited) refs.set(key, ref);\n for (const [key, ref] of this.changed) refs.set(key, ref);\n for (const [key, entry] of this.revealed) refs.set(key, entry.ref);\n return [...refs].map(([key, ref]) => ({ key, ref }));\n }\n}\n\n/** The value one classification delivers, or `undefined` when this device may not read it. */\nfunction delivered(value: ValueState): WireValue | undefined {\n return value.kind === 'value' ? value.value : undefined;\n}\n\nconst NO_BASELINE: Baseline = Object.freeze({ visible: undefined, held: undefined });\n\n/** The painted failures of one binding, with the reference the reconciler re-reads. */\ninterface RevealedEntry {\n readonly ref: FieldRef;\n readonly keys: ReadonlySet<string>;\n}\n\n/** The shared empty reveal set, so a binding with nothing painted keeps one identity. */\nconst NO_REVEALED: ReadonlySet<string> = Object.freeze(new Set<string>());\n\n/** Whether two reveal sets state the same failure identities. */\nfunction sameKeys(left: ReadonlySet<string>, right: ReadonlySet<string>): boolean {\n if (left === right) return true;\n if (left.size !== right.size) return false;\n for (const key of left) if (!right.has(key)) return false;\n return true;\n}\n\n/**\n * The value the record holds at every binding, keyed by binding key.\n *\n * This is the baseline `dirty` compares against, and it is read from the record rather than from\n * the delivery projection because the two answer different questions: a `masked` value is absent\n * from what the device may read and present in the record, and only the record says whether the\n * user changed anything. A row is located by its wire-typed key in the array's committed order,\n * so a move re-keys nothing.\n */\nexport function heldValuesOf(\n record: Readonly<Record<string, WireValue>>,\n form: FormState,\n facts: ReadonlyMap<string, FieldFacts>,\n): ReadonlyMap<string, WireValue | undefined> {\n const held = new Map<string, WireValue | undefined>();\n // Index each array container's `addressableRows` once per capture so the container and its\n // members resolve each row's position in O(1) instead of scanning `form.fields` and the key\n // list on every row.\n const rowIndexByArray = new Map<string, ReadonlyMap<string | number, number>>();\n for (const field of form.fields) {\n const keys = field.addressableRows;\n if (keys === undefined || keys.length === 0) continue;\n const indexByKey = new Map<string | number, number>();\n for (let index = 0; index < keys.length; index += 1) {\n const key = keys[index];\n if (key !== undefined && !indexByKey.has(key)) indexByKey.set(key, index);\n }\n rowIndexByArray.set(field.fieldId, indexByKey);\n }\n for (const field of form.fields) {\n const fact = facts.get(field.fieldId);\n if (fact === undefined) continue;\n if (fact.arrayContainerId === undefined) {\n held.set(bindingKey(field.fieldId, undefined), valueAt(record, fact.path));\n }\n const rows = field.rows;\n if (rows === undefined || rows.length === 0) continue;\n const arrayId = fact.arrayContainerId ?? field.fieldId;\n const arrayFacts = facts.get(arrayId);\n const keyIndex = rowIndexByArray.get(arrayId);\n const elements = arrayFacts === undefined ? undefined : valueAt(record, arrayFacts.path);\n for (const row of rows) {\n const index = keyIndex?.get(row.rowKey);\n const element = index === undefined || !Array.isArray(elements) ? undefined : elements[index];\n // A row binding of the array itself is the element; a member's row binding is that\n // member inside the row, and a member of a row is addressed by its own `fieldId`.\n held.set(\n bindingKey(field.fieldId, row.rowKey),\n element === undefined || fact.arrayContainerId === undefined\n ? element\n : valueAt(element, [field.fieldId]),\n );\n }\n }\n return held;\n}\n\n/** The value at one record path, or `undefined` where the record holds none. */\nfunction valueAt(value: WireValue | undefined, path: readonly string[]): WireValue | undefined {\n let current = value;\n for (const segment of path) {\n if (!isRecord(current) || !Object.hasOwn(current, segment)) return undefined;\n current = current[segment];\n }\n return current;\n}\n"]}
@@ -0,0 +1,68 @@
1
+ import type { Engine, EngineFieldState, FieldRef } from '@azx-pbc/axiom-runtime';
2
+ import type { FieldError } from '../field-error.js';
3
+ import type { BindingView } from './derive.js';
4
+ import type { FieldFacts } from './fields.js';
5
+ /**
6
+ * When a control reveals the failures the engine already decided.
7
+ *
8
+ * The engine evaluates on every pass in every policy; this decides only what is painted. A policy
9
+ * is presentation and never a verdict: `BLOCKED` stays `BLOCKED` while its reasons are still
10
+ * hidden, and a submission is refused by the same `verdict` the engine computed.
11
+ */
12
+ export type ShowErrorsPolicy =
13
+ /** A failure appears once the user has visited this binding and no operand is still unanswered. */
14
+ 'touched'
15
+ /** Every decided failure is painted as soon as the engine states it. */
16
+ | 'always'
17
+ /** Nothing is painted until a submission is attempted; afterwards everything is. */
18
+ | 'submit';
19
+ /** The policy a provider that does not state one uses. */
20
+ export declare const DEFAULT_POLICY: ShowErrorsPolicy;
21
+ /**
22
+ * What one binding's visibility derivation needs besides the engine's own state.
23
+ *
24
+ * `incompleteRules` names the rules on this binding that read an operand the user has not
25
+ * supplied; `revealedErrors` is the sticky set of failures this binding has already painted.
26
+ * Both are precomputed because they depend on other bindings and on session history, and both
27
+ * are carried by identity so an unchanged answer does not replace the published props.
28
+ */
29
+ export interface BindingVisibility {
30
+ readonly incompleteRules: ReadonlySet<string>;
31
+ readonly revealedErrors: ReadonlySet<string>;
32
+ }
33
+ /** The visibility of a binding with nothing missing and nothing revealed yet. */
34
+ export declare const NO_VISIBILITY: BindingVisibility;
35
+ /**
36
+ * The stable identity of one failure inside a binding.
37
+ *
38
+ * It is the reason, not the whole state: two decisions of the same rule name the same failure,
39
+ * so a sticky reveal survives a new parameter value while the failure itself holds. A corrected
40
+ * failure removes the key, which is what lets a later, different failure be judged afresh.
41
+ */
42
+ export declare function errorKey(error: FieldError): string;
43
+ /**
44
+ * The failures one control paints, in artifact order.
45
+ *
46
+ * This is the presentation list, not the engine's fact list: `FieldProps.errors` keeps stating
47
+ * every reason the record has, while this states the reasons the user is being told about now.
48
+ * A hidden binding paints nothing. A refused entry answers something the user just did and is
49
+ * shown immediately; a warning is informational and is not deferred by the policy; access
50
+ * diagnostics and undecided checks are never failures a control announces.
51
+ */
52
+ export declare function visibleErrorsOf(state: EngineFieldState, view: BindingView, policy: ShowErrorsPolicy, visibility: BindingVisibility): readonly FieldError[];
53
+ /** Whether any painted failure makes the control announce itself as invalid. */
54
+ export declare function showsErrorOf(visible: readonly FieldError[]): boolean;
55
+ /** The rule ids on one binding whose operands are not all supplied.
56
+ *
57
+ * A rule is incomplete when its own answer is not `FAIL` (`UNKNOWN`/`DEFERRED`) or when it reads
58
+ * a field that holds no value and that the user has neither visited nor written. Absence is the
59
+ * same empty the record contract states: `absent`, or the authored `null`. A computed value is
60
+ * never a question for the user, and a read this derivation cannot address (a row member read
61
+ * by a field-scope rule) is not treated as missing rather than guessed at.
62
+ */
63
+ export declare function incompleteRulesOf(engine: Engine, facts: ReadonlyMap<string, FieldFacts>, ruleReads: ReadonlyMap<string, readonly FieldRef[]>, state: EngineFieldState, rowKey: string | number | undefined, isAnswered: (key: string) => boolean): ReadonlySet<string>;
64
+ /** Whether one rule's operands are complete, from the rule id a summary blocker names. */
65
+ export declare function ruleBlockComplete(engine: Engine, facts: ReadonlyMap<string, FieldFacts>, ruleReads: ReadonlyMap<string, readonly FieldRef[]>, ruleId: string, isAnswered: (key: string) => boolean): boolean;
66
+ /** Whether one set of rule ids states the same members as another. */
67
+ export declare function sameIdSet(left: ReadonlySet<string>, right: ReadonlySet<string>): boolean;
68
+ //# sourceMappingURL=visibility.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"visibility.d.ts","sourceRoot":"","sources":["../../src/store/visibility.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,EAAE,gBAAgB,EAAE,QAAQ,EAAE,MAAM,wBAAwB,CAAC;AACjF,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,mBAAmB,CAAC;AAGpD,OAAO,KAAK,EAAE,WAAW,EAAE,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,iBAAiB,CAC/B,MAAM,EAAE,MAAM,EACd,KAAK,EAAE,WAAW,CAAC,MAAM,EAAE,UAAU,CAAC,EACtC,SAAS,EAAE,WAAW,CAAC,MAAM,EAAE,SAAS,QAAQ,EAAE,CAAC,EACnD,MAAM,EAAE,MAAM,EACd,UAAU,EAAE,CAAC,GAAG,EAAE,MAAM,KAAK,OAAO,GACnC,OAAO,CAaT;AAwCD,sEAAsE;AACtE,wBAAgB,SAAS,CAAC,IAAI,EAAE,WAAW,CAAC,MAAM,CAAC,EAAE,KAAK,EAAE,WAAW,CAAC,MAAM,CAAC,GAAG,OAAO,CAKxF"}
@@ -0,0 +1,231 @@
1
+ import { bindingKey } from './bindings.js';
2
+ import { bindingErrors } from './errors.js';
3
+ /** The policy a provider that does not state one uses. */
4
+ export const DEFAULT_POLICY = 'touched';
5
+ /** The empty set every binding without a missing operand shares, so identity is stable. */
6
+ const EMPTY = Object.freeze(new Set());
7
+ /** The visibility of a binding with nothing missing and nothing revealed yet. */
8
+ export const NO_VISIBILITY = Object.freeze({
9
+ incompleteRules: EMPTY,
10
+ revealedErrors: EMPTY,
11
+ });
12
+ /**
13
+ * The stable identity of one failure inside a binding.
14
+ *
15
+ * It is the reason, not the whole state: two decisions of the same rule name the same failure,
16
+ * so a sticky reveal survives a new parameter value while the failure itself holds. A corrected
17
+ * failure removes the key, which is what lets a later, different failure be judged afresh.
18
+ */
19
+ export function errorKey(error) {
20
+ switch (error.kind) {
21
+ case 'validate':
22
+ case 'deferred':
23
+ return `${error.kind}:${error.ruleId}:${error.messageKey}`;
24
+ case 'required':
25
+ return `required:${error.fieldId}@${String(error.rowKey ?? '')}`;
26
+ case 'cardinality':
27
+ return `cardinality:${error.bound}`;
28
+ case 'invalid-value':
29
+ return `invalid-value:${error.code}`;
30
+ case 'access':
31
+ return `access:${error.access}`;
32
+ case 'gate':
33
+ return `gate:${error.gateId}:${error.itemId}:${error.messageKey}`;
34
+ case 'screen':
35
+ return `screen:${error.screenId}:${error.outcome}`;
36
+ case 'row-key':
37
+ return `row-key:${error.code}:${String(error.rowKey)}`;
38
+ }
39
+ }
40
+ /**
41
+ * Whether this failure is hidden because the user has not supplied what the rule reads.
42
+ *
43
+ * A rule whose answer is `UNKNOWN` or `DEFERRED` is undecided, not failed: the engine already
44
+ * declines to call it blocking, and naming it would state an outcome no pass reached. A decided
45
+ * failure is still incomplete when a field it reads is empty and untouched — the message would
46
+ * accuse the user of a fact they have not had the chance to supply.
47
+ */
48
+ function isIncomplete(error, visibility) {
49
+ if (error.kind !== 'validate')
50
+ return false;
51
+ if (error.status !== 'FAIL')
52
+ return true;
53
+ return visibility.incompleteRules.has(error.ruleId);
54
+ }
55
+ /** Whether a decided blocking failure is old enough to paint under this binding's policy. */
56
+ function revealGate(error, view, policy, visibility) {
57
+ switch (policy) {
58
+ case 'always':
59
+ return true;
60
+ case 'submit':
61
+ return view.submitted || visibility.revealedErrors.has(errorKey(error));
62
+ case 'touched':
63
+ // A failure already painted stays painted until it is corrected (it is no longer in the
64
+ // list then) or the session is reset. Without that, clearing a sibling operand would make
65
+ // a sentence the user already saw disappear and reappear around their next keystroke.
66
+ return (visibility.revealedErrors.has(errorKey(error)) ||
67
+ (view.touched && !isIncomplete(error, visibility)));
68
+ }
69
+ }
70
+ /**
71
+ * The failures one control paints, in artifact order.
72
+ *
73
+ * This is the presentation list, not the engine's fact list: `FieldProps.errors` keeps stating
74
+ * every reason the record has, while this states the reasons the user is being told about now.
75
+ * A hidden binding paints nothing. A refused entry answers something the user just did and is
76
+ * shown immediately; a warning is informational and is not deferred by the policy; access
77
+ * diagnostics and undecided checks are never failures a control announces.
78
+ */
79
+ export function visibleErrorsOf(state, view, policy, visibility) {
80
+ if (!state.visible)
81
+ return EMPTY_ERRORS;
82
+ const engineErrors = bindingErrors(state);
83
+ const visible = [];
84
+ for (const error of engineErrors.errors) {
85
+ switch (error.kind) {
86
+ case 'access':
87
+ case 'deferred':
88
+ break;
89
+ case 'validate':
90
+ // A status other than `FAIL` is an open question, not a failure. A warning is shown as
91
+ // soon as it exists: it is a note, not an accusation, and hiding it until the user
92
+ // touches the field would lose information they may act on before editing.
93
+ if (error.status !== 'FAIL')
94
+ break;
95
+ if (error.severity === 'warn' || revealGate(error, view, policy, visibility)) {
96
+ visible.push(error);
97
+ }
98
+ break;
99
+ case 'required':
100
+ case 'cardinality':
101
+ case 'invalid-value':
102
+ if (revealGate(error, view, policy, visibility))
103
+ visible.push(error);
104
+ break;
105
+ case 'gate':
106
+ case 'screen':
107
+ case 'row-key':
108
+ // Gate and screen reasons are form-level and the summary states them; a refused entry
109
+ // is appended below from the session, because it is not an engine fact.
110
+ break;
111
+ }
112
+ }
113
+ if (view.refusal !== undefined)
114
+ visible.push(view.refusal);
115
+ return visible.length === 0 ? EMPTY_ERRORS : Object.freeze(visible);
116
+ }
117
+ /** A stable empty list, so a binding with nothing to paint keeps its props identity. */
118
+ const EMPTY_ERRORS = Object.freeze([]);
119
+ /** Whether any painted failure makes the control announce itself as invalid. */
120
+ export function showsErrorOf(visible) {
121
+ return visible.some((error) => error.blocking || error.kind === 'row-key');
122
+ }
123
+ /** The rule ids on one binding whose operands are not all supplied.
124
+ *
125
+ * A rule is incomplete when its own answer is not `FAIL` (`UNKNOWN`/`DEFERRED`) or when it reads
126
+ * a field that holds no value and that the user has neither visited nor written. Absence is the
127
+ * same empty the record contract states: `absent`, or the authored `null`. A computed value is
128
+ * never a question for the user, and a read this derivation cannot address (a row member read
129
+ * by a field-scope rule) is not treated as missing rather than guessed at.
130
+ */
131
+ export function incompleteRulesOf(engine, facts, ruleReads, state, rowKey, isAnswered) {
132
+ if (state.messages.length === 0)
133
+ return EMPTY;
134
+ let incomplete;
135
+ for (const message of state.messages) {
136
+ const ruleId = message.ruleId;
137
+ if (message.status !== 'FAIL') {
138
+ incomplete ??= new Set();
139
+ incomplete.add(ruleId);
140
+ continue;
141
+ }
142
+ const reads = ruleReads.get(ruleId);
143
+ if (reads === undefined)
144
+ continue;
145
+ for (const read of reads) {
146
+ const ref = readRefOf(read.fieldId, rowKey, facts);
147
+ if (ref === undefined)
148
+ continue;
149
+ if (isAnswered(bindingKey(ref.fieldId, ref.rowKey)))
150
+ continue;
151
+ const readState = readStateOf(engine, ref);
152
+ if (readState === undefined)
153
+ continue;
154
+ // A writer owns a computed value: its absence is an answer the device produced, not a
155
+ // question the user has been asked, so it is never "not supplied yet".
156
+ if (readState.systemComputed)
157
+ continue;
158
+ if (!isEmptyValue(readState))
159
+ continue;
160
+ incomplete ??= new Set();
161
+ incomplete.add(ruleId);
162
+ break;
163
+ }
164
+ }
165
+ return incomplete === undefined ? EMPTY : incomplete;
166
+ }
167
+ /** Whether one rule's operands are complete, from the rule id a summary blocker names. */
168
+ export function ruleBlockComplete(engine, facts, ruleReads, ruleId, isAnswered) {
169
+ const reads = ruleReads.get(ruleId);
170
+ if (reads === undefined)
171
+ return true;
172
+ for (const read of reads) {
173
+ const ref = readRefOf(read.fieldId, undefined, facts);
174
+ if (ref === undefined)
175
+ continue;
176
+ if (isAnswered(bindingKey(ref.fieldId, ref.rowKey)))
177
+ continue;
178
+ const readState = readStateOf(engine, ref);
179
+ if (readState === undefined || readState.systemComputed)
180
+ continue;
181
+ if (!isEmptyValue(readState))
182
+ continue;
183
+ return false;
184
+ }
185
+ return true;
186
+ }
187
+ /**
188
+ * The binding a read names.
189
+ *
190
+ * A read of a member is per row, so it follows the row the message belongs to. A read of an item
191
+ * member from a field-scope rule has no row to follow and is left unresolved; a container read is
192
+ * always the field itself, even inside an item rule.
193
+ */
194
+ function readRefOf(readFieldId, rowKey, facts) {
195
+ const readFacts = facts.get(readFieldId);
196
+ if (readFacts === undefined)
197
+ return undefined;
198
+ if (readFacts.arrayContainerId === undefined)
199
+ return { fieldId: readFieldId };
200
+ if (rowKey === undefined)
201
+ return undefined;
202
+ return { fieldId: readFieldId, rowKey };
203
+ }
204
+ /** One binding's state, or `undefined` when committed state no longer addresses it. */
205
+ function readStateOf(engine, ref) {
206
+ try {
207
+ return engine.getField(ref.fieldId, ref.rowKey);
208
+ }
209
+ catch {
210
+ // A row that commits after the message was derived is a read this derivation cannot answer.
211
+ // Treating it as absent would suppress a failure; treating it as present leaves the engine's
212
+ // verdict untouched. The latter is the only safe reading for a presentation gate.
213
+ return undefined;
214
+ }
215
+ }
216
+ /** `empty()` semantics for a state: an absence, or the authored empty value. */
217
+ function isEmptyValue(state) {
218
+ return (state.value.kind === 'absent' || (state.value.kind === 'value' && state.value.value === null));
219
+ }
220
+ /** Whether one set of rule ids states the same members as another. */
221
+ export function sameIdSet(left, right) {
222
+ if (left === right)
223
+ return true;
224
+ if (left.size !== right.size)
225
+ return false;
226
+ for (const value of left)
227
+ if (!right.has(value))
228
+ return false;
229
+ return true;
230
+ }
231
+ //# sourceMappingURL=visibility.js.map