@littlepress/renderer-web 0.0.0-stage → 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +202 -0
- package/NOTICE +20 -0
- package/README.md +229 -2
- package/dist/answer/answerComponents.d.ts +107 -0
- package/dist/answer/answerComponents.js +637 -0
- package/dist/answer/download.d.ts +63 -0
- package/dist/answer/download.js +109 -0
- package/dist/answer/downloadExport.d.ts +44 -0
- package/dist/answer/downloadExport.js +266 -0
- package/dist/answer/hostValues.d.ts +28 -0
- package/dist/answer/hostValues.js +379 -0
- package/dist/answer/mapComponent.d.ts +6 -0
- package/dist/answer/mapComponent.js +213 -0
- package/dist/answer/math.d.ts +57 -0
- package/dist/answer/math.js +168 -0
- package/dist/answer/surfaceStream.d.ts +51 -0
- package/dist/answer/surfaceStream.js +260 -0
- package/dist/answer/tableLayout.d.ts +42 -0
- package/dist/answer/tableLayout.js +89 -0
- package/dist/controls/ActionFeedback.d.ts +5 -0
- package/dist/controls/ActionFeedback.js +43 -0
- package/dist/controls/actionDispatch.d.ts +51 -0
- package/dist/controls/actionDispatch.js +211 -0
- package/dist/controls/actionOutcome.generated.d.ts +64 -0
- package/dist/controls/actionOutcome.generated.js +64 -0
- package/dist/controls/calculationPublisher.d.ts +14 -0
- package/dist/controls/calculationPublisher.js +6 -0
- package/dist/controls/calculations.d.ts +20 -0
- package/dist/controls/calculations.generated.d.ts +73 -0
- package/dist/controls/calculations.generated.js +85 -0
- package/dist/controls/calculations.js +208 -0
- package/dist/controls/controlState.d.ts +84 -0
- package/dist/controls/controlState.js +256 -0
- package/dist/controls/fieldMessages.d.ts +41 -0
- package/dist/controls/fieldMessages.js +81 -0
- package/dist/controls/fieldValidation.d.ts +19 -0
- package/dist/controls/fieldValidation.js +98 -0
- package/dist/controls/formComponents.d.ts +23 -0
- package/dist/controls/formComponents.js +738 -0
- package/dist/controls/formProgress.d.ts +63 -0
- package/dist/controls/formProgress.js +122 -0
- package/dist/controls/inputDrafts.d.ts +55 -0
- package/dist/controls/inputDrafts.js +183 -0
- package/dist/controls/inputValidation.d.ts +33 -0
- package/dist/controls/inputValidation.js +119 -0
- package/dist/controls/localWrites.d.ts +9 -0
- package/dist/controls/localWrites.js +29 -0
- package/dist/core/A2uiSurface.d.ts +13 -0
- package/dist/core/A2uiSurface.js +15 -0
- package/dist/core/AtlasIcon.d.ts +18 -0
- package/dist/core/AtlasIcon.js +22 -0
- package/dist/core/AtlasMedia.d.ts +22 -0
- package/dist/core/AtlasMedia.js +45 -0
- package/dist/core/Carousel.d.ts +61 -0
- package/dist/core/Carousel.js +183 -0
- package/dist/core/CoreMedia.d.ts +19 -0
- package/dist/core/CoreMedia.js +25 -0
- package/dist/core/FoundationA2uiSurface.d.ts +86 -0
- package/dist/core/FoundationA2uiSurface.js +440 -0
- package/dist/core/ImagePreview.d.ts +42 -0
- package/dist/core/ImagePreview.js +73 -0
- package/dist/core/LucideIcon.d.ts +19 -0
- package/dist/core/LucideIcon.js +42 -0
- package/dist/core/SurfaceLink.d.ts +35 -0
- package/dist/core/SurfaceLink.js +60 -0
- package/dist/core/appearance/aegis.d.ts +49 -0
- package/dist/core/appearance/aegis.js +34 -0
- package/dist/core/appearance/colour.d.ts +24 -0
- package/dist/core/appearance/colour.js +103 -0
- package/dist/core/appearance/css.d.ts +17 -0
- package/dist/core/appearance/css.js +153 -0
- package/dist/core/appearance/presets.generated.d.ts +4 -0
- package/dist/core/appearance/presets.generated.js +1184 -0
- package/dist/core/appearance/react.d.ts +29 -0
- package/dist/core/appearance/react.js +110 -0
- package/dist/core/appearance/resolve.d.ts +76 -0
- package/dist/core/appearance/resolve.js +127 -0
- package/dist/core/appearance/textScale.d.ts +11 -0
- package/dist/core/appearance/textScale.js +51 -0
- package/dist/core/appearance/theme.d.ts +138 -0
- package/dist/core/appearance/theme.js +274 -0
- package/dist/core/baseComponents.d.ts +53 -0
- package/dist/core/baseComponents.js +480 -0
- package/dist/core/binding.d.ts +46 -0
- package/dist/core/binding.js +118 -0
- package/dist/core/bundle.d.ts +23 -0
- package/dist/core/bundle.js +75 -0
- package/dist/core/catalog/catalog-index.generated.d.ts +44 -0
- package/dist/core/catalog/catalog-index.generated.js +79 -0
- package/dist/core/catalog/icons.generated.d.ts +6 -0
- package/dist/core/catalog/icons.generated.js +1788 -0
- package/dist/core/catalog.d.ts +6 -0
- package/dist/core/catalog.generated.d.ts +50 -0
- package/dist/core/catalog.generated.js +2174 -0
- package/dist/core/catalog.js +8 -0
- package/dist/core/chartRows.d.ts +7 -0
- package/dist/core/chartRows.js +38 -0
- package/dist/core/component-support.d.ts +39 -0
- package/dist/core/component-support.js +127 -0
- package/dist/core/components/actions.d.ts +4 -0
- package/dist/core/components/actions.js +21 -0
- package/dist/core/components/cards.d.ts +9 -0
- package/dist/core/components/cards.js +227 -0
- package/dist/core/components/charts.d.ts +18 -0
- package/dist/core/components/charts.js +412 -0
- package/dist/core/components/comparisonTable.d.ts +50 -0
- package/dist/core/components/comparisonTable.js +89 -0
- package/dist/core/components/content.d.ts +13 -0
- package/dist/core/components/content.js +108 -0
- package/dist/core/components/seriesCharts.d.ts +531 -0
- package/dist/core/components/seriesCharts.js +1053 -0
- package/dist/core/components/stepFlow.d.ts +7 -0
- package/dist/core/components/stepFlow.js +13 -0
- package/dist/core/components.full.d.ts +10 -0
- package/dist/core/components.full.js +41 -0
- package/dist/core/context.d.ts +207 -0
- package/dist/core/context.js +172 -0
- package/dist/core/coverage.d.ts +30 -0
- package/dist/core/coverage.js +93 -0
- package/dist/core/foundation.d.ts +21 -0
- package/dist/core/foundation.js +22 -0
- package/dist/core/fullTheme.d.ts +5 -0
- package/dist/core/fullTheme.js +9 -0
- package/dist/core/iconNodes.generated.d.ts +7 -0
- package/dist/core/iconNodes.generated.js +5 -0
- package/dist/core/lucideIcons.d.ts +5 -0
- package/dist/core/lucideIcons.js +7 -0
- package/dist/core/messages.d.ts +111 -0
- package/dist/core/messages.js +134 -0
- package/dist/core/pointer.d.ts +17 -0
- package/dist/core/pointer.js +104 -0
- package/dist/core/registry.d.ts +12 -0
- package/dist/core/registry.js +114 -0
- package/dist/core/runtime.d.ts +8 -0
- package/dist/core/runtime.js +6 -0
- package/dist/core/state.d.ts +73 -0
- package/dist/core/state.js +274 -0
- package/dist/core/surfaceMotion.d.ts +5 -0
- package/dist/core/surfaceMotion.js +46 -0
- package/dist/core/theme.d.ts +5 -0
- package/dist/core/theme.js +7 -0
- package/dist/core/useSurfaceImage.d.ts +20 -0
- package/dist/core/useSurfaceImage.js +65 -0
- package/dist/graph/RelationshipGraph.d.ts +14 -0
- package/dist/graph/RelationshipGraph.js +206 -0
- package/dist/graph/model.d.ts +20 -0
- package/dist/graph/model.js +36 -0
- package/dist/graph/program/assets.d.ts +3 -0
- package/dist/graph/program/assets.js +3 -0
- package/dist/graph/program/bridge.d.ts +6 -0
- package/dist/graph/program/bridge.generated.d.ts +136 -0
- package/dist/graph/program/bridge.generated.js +1 -0
- package/dist/graph/program/bridge.js +24 -0
- package/dist/graph/program/bridge.schema.json +717 -0
- package/dist/graph/program/bridgeValidator.cjs +2 -0
- package/dist/graph/program/bridgeValidator.d.cts +4 -0
- package/dist/graph/program/runner.d.ts +1 -0
- package/dist/graph/program/runner.html +2193 -0
- package/dist/graph/program/runner.js +157 -0
- package/dist/graph/program/runtime-manifest.json +1 -0
- package/dist/graph/program/view.d.ts +11 -0
- package/dist/graph/program/view.js +210 -0
- package/dist/graph/program/worker.d.ts +1 -0
- package/dist/graph/program/worker.js +2186 -0
- package/dist/index.d.ts +20 -0
- package/dist/index.js +45 -0
- package/dist/internal/dsh.d.ts +4 -0
- package/dist/internal/dsh.js +3 -0
- package/dist/internal/relationship-graph.d.ts +4 -0
- package/dist/internal/relationship-graph.js +7202 -0
- package/dist/page/layoutComponents.d.ts +6 -0
- package/dist/page/layoutComponents.js +123 -0
- package/dist/page/layoutGeometry.d.ts +68 -0
- package/dist/page/layoutGeometry.js +174 -0
- package/dist/page/pageFormat.d.ts +34 -0
- package/dist/page/pageFormat.js +119 -0
- package/dist/page/printFit.d.ts +81 -0
- package/dist/page/printFit.js +338 -0
- package/dist/react/index.d.ts +5 -0
- package/dist/react/index.js +2 -0
- package/dist/report/locate.d.ts +42 -0
- package/dist/report/locate.js +34 -0
- package/dist/styles/renderer.css +4580 -0
- package/licenses/LUCIDE-LICENSE.txt +43 -0
- package/licenses/QUICKJS-EMSCRIPTEN-LICENSE.txt +21 -0
- package/licenses/QUICKJS-VARIANT-LICENSE.txt +47 -0
- package/package.json +68 -3
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* One form's validation over its current values, read by everything that asks whether the form
|
|
3
|
+
* is done: the required-field progress line, the submit button's muted state and description,
|
|
4
|
+
* and the submit itself (a click or Enter). Values are read from the binding's data model, which
|
|
5
|
+
* already holds the user's local drafts.
|
|
6
|
+
*
|
|
7
|
+
* A control counts when it is drawn and can be edited: one hidden by its own or an ancestor's
|
|
8
|
+
* `visible` is not drawn, and a disabled one is never checked (as in HTML constraint
|
|
9
|
+
* validation). Compose (`StaticFormProgress.kt`) and SwiftUI (`StaticFormProgress.swift`) count
|
|
10
|
+
* the same way; `contracts/fixtures/renderer/form-progress.json` is the shared case table.
|
|
11
|
+
*/
|
|
12
|
+
import { type BindingContext, type ValueFunction } from "../core/binding.ts";
|
|
13
|
+
import { type A2uiComponent } from "../core/messages.ts";
|
|
14
|
+
import type { A2uiSurfaceState } from "../core/state.ts";
|
|
15
|
+
export type FormFieldCheck = {
|
|
16
|
+
componentId: string;
|
|
17
|
+
/** The field's draft identity, the `data-a2ui-field` of its wrapper. */
|
|
18
|
+
key: string;
|
|
19
|
+
required: boolean;
|
|
20
|
+
error: {
|
|
21
|
+
errorCode: string;
|
|
22
|
+
message: string;
|
|
23
|
+
} | null;
|
|
24
|
+
};
|
|
25
|
+
export type FormValidation = {
|
|
26
|
+
/** Every counted control, in reading order. */
|
|
27
|
+
fields: readonly FormFieldCheck[];
|
|
28
|
+
/** Required controls that are counted (N). */
|
|
29
|
+
requiredTotal: number;
|
|
30
|
+
/** Of those, the ones whose value passes (X). */
|
|
31
|
+
requiredDone: number;
|
|
32
|
+
/** The first counted control, required or not, whose value fails: a submit stops on it. */
|
|
33
|
+
firstInvalid: FormFieldCheck | null;
|
|
34
|
+
};
|
|
35
|
+
/**
|
|
36
|
+
* Whether a control is marked and announced as required. A control its author disabled is
|
|
37
|
+
* never checked or counted, so it is not required either; one held only for a while (the answer
|
|
38
|
+
* streams, the Host disabled the form, a submit runs) keeps its mark, since it will be counted.
|
|
39
|
+
*/
|
|
40
|
+
export declare function requiredShown(component: A2uiComponent): boolean;
|
|
41
|
+
/**
|
|
42
|
+
* Checks every counted control under `form` against its current value. `binding` is the form's
|
|
43
|
+
* own binding (its row, inside a repeated template) over the drafted data model, and `itemId`
|
|
44
|
+
* the form's row identity.
|
|
45
|
+
*/
|
|
46
|
+
export declare function validateForm(state: A2uiSurfaceState, form: A2uiComponent, binding: BindingContext, ancestors: readonly string[], itemId?: string, functions?: Readonly<Record<string, ValueFunction>>): FormValidation;
|
|
47
|
+
/**
|
|
48
|
+
* The submit button: `unavailable` is truly disabled (the answer streams, the Host disabled the
|
|
49
|
+
* form, a submit is running or paused); `incomplete` is a working button drawn muted while
|
|
50
|
+
* required fields are left; `ready` otherwise.
|
|
51
|
+
*/
|
|
52
|
+
export type FormSubmitState = "unavailable" | "incomplete" | "ready";
|
|
53
|
+
export declare function formSubmitState(available: boolean, validation: FormValidation): FormSubmitState;
|
|
54
|
+
export type FormProgressCopy = {
|
|
55
|
+
/** Drawn above the controls: the count of required fields done. */
|
|
56
|
+
shown: string;
|
|
57
|
+
/** Read and announced instead of `shown`, which a screen reader would read as a fraction or date. */
|
|
58
|
+
spoken: string;
|
|
59
|
+
};
|
|
60
|
+
/** The progress line, in the surface language (Chinese, else English). */
|
|
61
|
+
export declare function formProgressCopy(done: number, total: number, locale: unknown): FormProgressCopy;
|
|
62
|
+
/** The submit button's description while required fields are missing. */
|
|
63
|
+
export declare function requiredFieldsLeftCopy(left: number, locale: unknown): string;
|
|
@@ -0,0 +1,122 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* One form's validation over its current values, read by everything that asks whether the form
|
|
3
|
+
* is done: the required-field progress line, the submit button's muted state and description,
|
|
4
|
+
* and the submit itself (a click or Enter). Values are read from the binding's data model, which
|
|
5
|
+
* already holds the user's local drafts.
|
|
6
|
+
*
|
|
7
|
+
* A control counts when it is drawn and can be edited: one hidden by its own or an ancestor's
|
|
8
|
+
* `visible` is not drawn, and a disabled one is never checked (as in HTML constraint
|
|
9
|
+
* validation). Compose (`StaticFormProgress.kt`) and SwiftUI (`StaticFormProgress.swift`) count
|
|
10
|
+
* the same way; `contracts/fixtures/renderer/form-progress.json` is the shared case table.
|
|
11
|
+
*/
|
|
12
|
+
import { readBindingPointer, resolveBoolean, resolveString, resolveValue } from "../core/binding.js";
|
|
13
|
+
import { legacyFoundationComponentAliases } from "../core/catalog.js";
|
|
14
|
+
import { isChildTemplate } from "../core/messages.js";
|
|
15
|
+
import { readPointer } from "../core/pointer.js";
|
|
16
|
+
import { isChineseLanguage } from "./fieldMessages.js";
|
|
17
|
+
import { renderedFieldKey, validateControlValue } from "./inputDrafts.js";
|
|
18
|
+
const controls = new Set(["lp.input-field", "lp.select", "lp.checkbox", "lp.choice-group", "lp.slider"]);
|
|
19
|
+
const canonical = (name) => legacyFoundationComponentAliases[name] ?? name;
|
|
20
|
+
/**
|
|
21
|
+
* Whether a control is marked and announced as required. A control its author disabled is
|
|
22
|
+
* never checked or counted, so it is not required either; one held only for a while (the answer
|
|
23
|
+
* streams, the Host disabled the form, a submit runs) keeps its mark, since it will be counted.
|
|
24
|
+
*/
|
|
25
|
+
export function requiredShown(component) {
|
|
26
|
+
return component.required === true && component.disabled !== true;
|
|
27
|
+
}
|
|
28
|
+
/** The value a control shows, read the way the control reads it. */
|
|
29
|
+
function controlValue(component, binding, functions) {
|
|
30
|
+
const path = component.valuePath;
|
|
31
|
+
const bound = readPointer(binding.dataModel, path);
|
|
32
|
+
switch (canonical(component.component)) {
|
|
33
|
+
case "lp.input-field":
|
|
34
|
+
return typeof bound === "string" || typeof bound === "number" ? String(bound) : "";
|
|
35
|
+
case "lp.select":
|
|
36
|
+
return typeof bound === "string" ? bound : "";
|
|
37
|
+
case "lp.checkbox":
|
|
38
|
+
return bound === true;
|
|
39
|
+
case "lp.choice-group":
|
|
40
|
+
return component.multiple === true
|
|
41
|
+
? Array.isArray(bound) ? bound.filter((entry) => typeof entry === "string") : []
|
|
42
|
+
: typeof bound === "string" ? bound : "";
|
|
43
|
+
default: {
|
|
44
|
+
const min = resolveValue(component.min, binding, functions);
|
|
45
|
+
return typeof bound === "number" && Number.isFinite(bound) ? bound : typeof min === "number" ? min : 0;
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
/**
|
|
50
|
+
* Checks every counted control under `form` against its current value. `binding` is the form's
|
|
51
|
+
* own binding (its row, inside a repeated template) over the drafted data model, and `itemId`
|
|
52
|
+
* the form's row identity.
|
|
53
|
+
*/
|
|
54
|
+
export function validateForm(state, form, binding, ancestors, itemId, functions) {
|
|
55
|
+
const fields = [];
|
|
56
|
+
function visit(id, binding, itemId, path) {
|
|
57
|
+
const component = state.components[id];
|
|
58
|
+
if (!component || path.includes(id) || path.length >= 32)
|
|
59
|
+
return;
|
|
60
|
+
if (component.visible !== undefined && resolveBoolean(component.visible, binding, functions) === false)
|
|
61
|
+
return;
|
|
62
|
+
if (controls.has(canonical(component.component))) {
|
|
63
|
+
const label = resolveString(component.label, binding, functions);
|
|
64
|
+
const drawn = typeof component.valuePath === "string" && component.valuePath.startsWith("/data/") && Boolean(label);
|
|
65
|
+
if (!drawn || component.disabled === true)
|
|
66
|
+
return;
|
|
67
|
+
const required = component.required === true && canonical(component.component) !== "lp.slider";
|
|
68
|
+
const error = validateControlValue(component, binding, controlValue(component, binding, functions), functions, state.dataModel);
|
|
69
|
+
fields.push({ componentId: id, key: renderedFieldKey(state, path, component, itemId), required, error });
|
|
70
|
+
return;
|
|
71
|
+
}
|
|
72
|
+
const next = [...path, id];
|
|
73
|
+
const children = component.children;
|
|
74
|
+
if (Array.isArray(children)) {
|
|
75
|
+
for (const child of children)
|
|
76
|
+
if (typeof child === "string")
|
|
77
|
+
visit(child, binding, itemId, next);
|
|
78
|
+
}
|
|
79
|
+
else if (isChildTemplate(children)) {
|
|
80
|
+
const rows = resolveValue({ path: children.path }, binding, functions);
|
|
81
|
+
const base = readBindingPointer({ path: children.path }, binding);
|
|
82
|
+
const template = state.components[children.componentId];
|
|
83
|
+
if (!Array.isArray(rows) || !base || !template)
|
|
84
|
+
return;
|
|
85
|
+
rows.forEach((_row, index) => {
|
|
86
|
+
const rowBinding = { ...binding, itemPointer: `${base}/${index}` };
|
|
87
|
+
const declared = resolveValue(template.itemId, rowBinding, functions);
|
|
88
|
+
visit(children.componentId, rowBinding, typeof declared === "string" && declared.trim() ? declared : undefined, next);
|
|
89
|
+
});
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
const self = [...ancestors, form.id];
|
|
93
|
+
if (Array.isArray(form.children)) {
|
|
94
|
+
for (const child of form.children)
|
|
95
|
+
if (typeof child === "string")
|
|
96
|
+
visit(child, binding, itemId, self);
|
|
97
|
+
}
|
|
98
|
+
const required = fields.filter((field) => field.required);
|
|
99
|
+
return {
|
|
100
|
+
fields,
|
|
101
|
+
requiredTotal: required.length,
|
|
102
|
+
requiredDone: required.filter((field) => field.error === null).length,
|
|
103
|
+
firstInvalid: fields.find((field) => field.error !== null) ?? null,
|
|
104
|
+
};
|
|
105
|
+
}
|
|
106
|
+
export function formSubmitState(available, validation) {
|
|
107
|
+
if (!available)
|
|
108
|
+
return "unavailable";
|
|
109
|
+
return validation.requiredDone < validation.requiredTotal ? "incomplete" : "ready";
|
|
110
|
+
}
|
|
111
|
+
/** The progress line, in the surface language (Chinese, else English). */
|
|
112
|
+
export function formProgressCopy(done, total, locale) {
|
|
113
|
+
return isChineseLanguage(locale)
|
|
114
|
+
? { shown: `必填 ${done}/${total}`, spoken: `必填项已完成 ${done} 项,共 ${total} 项` }
|
|
115
|
+
: { shown: `Required ${done}/${total}`, spoken: `${done} of ${total} required fields done` };
|
|
116
|
+
}
|
|
117
|
+
/** The submit button's description while required fields are missing. */
|
|
118
|
+
export function requiredFieldsLeftCopy(left, locale) {
|
|
119
|
+
if (isChineseLanguage(locale))
|
|
120
|
+
return `还有 ${left} 项必填`;
|
|
121
|
+
return left === 1 ? "1 required field left" : `${left} required fields left`;
|
|
122
|
+
}
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
/** Keep edited fields by declared identity when a refreshed data model changes paths. */
|
|
2
|
+
import type { CalculationFailure } from "./calculations.ts";
|
|
3
|
+
import { type BindingContext, type ValueFunction } from "../core/binding.ts";
|
|
4
|
+
import { type A2uiComponent } from "../core/messages.ts";
|
|
5
|
+
import type { A2uiSurfaceState } from "../core/state.ts";
|
|
6
|
+
import type { A2uiInputChange } from "../core/context.ts";
|
|
7
|
+
export type InputDraft = {
|
|
8
|
+
key: string;
|
|
9
|
+
change: A2uiInputChange;
|
|
10
|
+
formKey: string | null;
|
|
11
|
+
};
|
|
12
|
+
export type DraftConflict = {
|
|
13
|
+
key: string;
|
|
14
|
+
change: A2uiInputChange;
|
|
15
|
+
formKey: string | null;
|
|
16
|
+
};
|
|
17
|
+
/** A form's identity: its component, and the row it repeats in. */
|
|
18
|
+
export declare const formKeyOf: (formId: string, itemId?: string) => string;
|
|
19
|
+
/**
|
|
20
|
+
* The draft identity of a rendered field: its declared `fieldId` within the nearest enclosing
|
|
21
|
+
* form, and its row. It equals the key `reconcileInputDrafts` gives the field's conflict.
|
|
22
|
+
*/
|
|
23
|
+
export declare function renderedFieldKey(state: A2uiSurfaceState, ancestors: readonly string[], component: A2uiComponent, itemId?: string): string;
|
|
24
|
+
/**
|
|
25
|
+
* The choices a select or choice group can hold now: its enabled options, plus disabled
|
|
26
|
+
* ones the Host's current value already holds. Foundation accepts a disabled option as a
|
|
27
|
+
* Host value (`catalog/controls.py`), so the Host may keep one; a user cannot add one.
|
|
28
|
+
*/
|
|
29
|
+
export declare function availableChoices(component: A2uiComponent, binding: BindingContext, functions?: Readonly<Record<string, ValueFunction>>, hostData?: unknown): ReadonlySet<string>;
|
|
30
|
+
/**
|
|
31
|
+
* The one validity check for a control's value. Every control shows it, sets it as the
|
|
32
|
+
* native custom validity (so a form submit stops on it and focuses the field), and reports
|
|
33
|
+
* it through `onInputChange`. `hostData` is the Host's current data model, which decides
|
|
34
|
+
* the disabled choices the Host keeps.
|
|
35
|
+
*/
|
|
36
|
+
export declare function validateControlValue(component: A2uiComponent, binding: BindingContext, value: unknown, functions?: Readonly<Record<string, ValueFunction>>, hostData?: unknown): {
|
|
37
|
+
errorCode: string;
|
|
38
|
+
message: string;
|
|
39
|
+
} | null;
|
|
40
|
+
/** A multiple-choice toggle replaces any choice the group can no longer hold, so the user's action always resolves it. */
|
|
41
|
+
export declare function toggleAvailableChoice(component: A2uiComponent, binding: BindingContext, current: readonly string[], value: string, checked: boolean, functions?: Readonly<Record<string, ValueFunction>>, hostData?: unknown): string[];
|
|
42
|
+
/** Only readers of an invalid field are prevented from calculating. Other content stays usable. */
|
|
43
|
+
export declare function calculationInputErrors(state: A2uiSurfaceState, dataModel: unknown, blockedPaths: ReadonlySet<string>, functions?: Readonly<Record<string, ValueFunction>>): ReadonlyMap<string, CalculationFailure>;
|
|
44
|
+
export declare function createInputDraft(state: A2uiSurfaceState, change: A2uiInputChange, functions?: Readonly<Record<string, ValueFunction>>): InputDraft | null;
|
|
45
|
+
export declare function reconcileInputDrafts(state: A2uiSurfaceState | null, drafts: Readonly<Record<string, InputDraft>>, functions?: Readonly<Record<string, ValueFunction>>): {
|
|
46
|
+
dataModel: unknown;
|
|
47
|
+
conflicts: DraftConflict[];
|
|
48
|
+
blockedInputPaths: ReadonlySet<string>;
|
|
49
|
+
blockedFormKeys: ReadonlySet<string>;
|
|
50
|
+
};
|
|
51
|
+
/**
|
|
52
|
+
* The drafts left when the user discards the stale ones. Those fields show the Host's current
|
|
53
|
+
* values again, which is the way out when no available choice is left to pick.
|
|
54
|
+
*/
|
|
55
|
+
export declare function discardStaleDrafts(drafts: Readonly<Record<string, InputDraft>>, conflicts: readonly DraftConflict[]): Record<string, InputDraft>;
|
|
@@ -0,0 +1,183 @@
|
|
|
1
|
+
import { fieldErrorMessage, fieldMessageWithLabel, surfaceLanguage } from "./fieldMessages.js";
|
|
2
|
+
import { readBindingPointer, resolveString, resolveValue } from "../core/binding.js";
|
|
3
|
+
import { isChildTemplate } from "../core/messages.js";
|
|
4
|
+
import { legacyFoundationComponentAliases } from "../core/catalog.js";
|
|
5
|
+
import { normalizeControlOptions, toggleChoiceValue } from "./controlState.js";
|
|
6
|
+
import { validateFieldValue } from "./fieldValidation.js";
|
|
7
|
+
import { readPointer, writePointer } from "../core/pointer.js";
|
|
8
|
+
const forms = new Set(["lp.form", "LPForm_Default"]);
|
|
9
|
+
const identity = (scope, fieldId, itemId) => JSON.stringify([scope, fieldId, itemId ?? null]);
|
|
10
|
+
/** A form's identity: its component, and the row it repeats in. */
|
|
11
|
+
export const formKeyOf = (formId, itemId) => JSON.stringify([formId, itemId ?? null]);
|
|
12
|
+
/**
|
|
13
|
+
* The draft identity of a rendered field: its declared `fieldId` within the nearest enclosing
|
|
14
|
+
* form, and its row. It equals the key `reconcileInputDrafts` gives the field's conflict.
|
|
15
|
+
*/
|
|
16
|
+
export function renderedFieldKey(state, ancestors, component, itemId) {
|
|
17
|
+
let formId;
|
|
18
|
+
for (const id of ancestors)
|
|
19
|
+
if (forms.has(state.components[id]?.component ?? ""))
|
|
20
|
+
formId = id;
|
|
21
|
+
return identity(formId ?? component.id, typeof component.fieldId === "string" ? component.fieldId : component.id, itemId);
|
|
22
|
+
}
|
|
23
|
+
function fieldsIn(state, functions) {
|
|
24
|
+
const fields = [];
|
|
25
|
+
function walk(id, binding, itemId, formId, formKey, disabled, ancestors) {
|
|
26
|
+
const component = state.components[id];
|
|
27
|
+
if (!component || ancestors.includes(id) || ancestors.length >= 32 || state.deleted)
|
|
28
|
+
return;
|
|
29
|
+
const fieldId = typeof component.fieldId === "string" ? component.fieldId : component.id;
|
|
30
|
+
const scope = forms.has(component.component) ? component.id : formId;
|
|
31
|
+
const scopeKey = forms.has(component.component) ? formKeyOf(component.id, itemId) : formKey;
|
|
32
|
+
const unavailable = disabled || component.disabled === true;
|
|
33
|
+
const path = typeof component.valuePath === "string" ? component.valuePath : null;
|
|
34
|
+
if (path?.startsWith("/data/")) {
|
|
35
|
+
fields.push({ key: identity(scope ?? component.id, fieldId, itemId), path, componentId: component.id, fieldId, itemId, disabled: unavailable, formKey: scopeKey, component, binding });
|
|
36
|
+
}
|
|
37
|
+
const next = [...ancestors, id];
|
|
38
|
+
if (Array.isArray(component.children)) {
|
|
39
|
+
for (const child of component.children)
|
|
40
|
+
if (typeof child === "string")
|
|
41
|
+
walk(child, binding, itemId, scope, scopeKey, unavailable, next);
|
|
42
|
+
}
|
|
43
|
+
else if (isChildTemplate(component.children)) {
|
|
44
|
+
const children = component.children;
|
|
45
|
+
const rows = resolveValue({ path: children.path }, binding, functions);
|
|
46
|
+
const base = readBindingPointer({ path: children.path }, binding);
|
|
47
|
+
const template = state.components[children.componentId];
|
|
48
|
+
if (!Array.isArray(rows) || !base || !template)
|
|
49
|
+
return;
|
|
50
|
+
rows.forEach((_row, index) => {
|
|
51
|
+
const rowBinding = { ...binding, itemPointer: `${base}/${index}` };
|
|
52
|
+
const declaredId = resolveValue(template.itemId, rowBinding, functions);
|
|
53
|
+
const rowId = typeof declaredId === "string" && declaredId.trim() ? declaredId : undefined;
|
|
54
|
+
walk(children.componentId, rowBinding, rowId, scope, scopeKey, unavailable, next);
|
|
55
|
+
});
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
if (state.rootComponentId)
|
|
59
|
+
walk(state.rootComponentId, { dataModel: state.dataModel, itemPointer: null }, undefined, null, null, false, []);
|
|
60
|
+
return fields;
|
|
61
|
+
}
|
|
62
|
+
const controlKinds = {
|
|
63
|
+
"lp.input-field": "lp.input-field",
|
|
64
|
+
"lp.select": "lp.select",
|
|
65
|
+
"lp.checkbox": "lp.checkbox",
|
|
66
|
+
"lp.choice-group": "lp.choice-group",
|
|
67
|
+
"lp.slider": "lp.slider",
|
|
68
|
+
};
|
|
69
|
+
/**
|
|
70
|
+
* The choices a select or choice group can hold now: its enabled options, plus disabled
|
|
71
|
+
* ones the Host's current value already holds. Foundation accepts a disabled option as a
|
|
72
|
+
* Host value (`catalog/controls.py`), so the Host may keep one; a user cannot add one.
|
|
73
|
+
*/
|
|
74
|
+
export function availableChoices(component, binding, functions, hostData = binding.dataModel) {
|
|
75
|
+
const held = typeof component.valuePath === "string" ? readPointer(hostData, component.valuePath) : undefined;
|
|
76
|
+
const kept = Array.isArray(held) ? held : [held];
|
|
77
|
+
return new Set(normalizeControlOptions(resolveValue(component.options, binding, functions))
|
|
78
|
+
.filter(option => !option.disabled || kept.includes(option.value))
|
|
79
|
+
.map(option => option.value));
|
|
80
|
+
}
|
|
81
|
+
/**
|
|
82
|
+
* The one validity check for a control's value. Every control shows it, sets it as the
|
|
83
|
+
* native custom validity (so a form submit stops on it and focuses the field), and reports
|
|
84
|
+
* it through `onInputChange`. `hostData` is the Host's current data model, which decides
|
|
85
|
+
* the disabled choices the Host keeps.
|
|
86
|
+
*/
|
|
87
|
+
export function validateControlValue(component, binding, value, functions, hostData = binding.dataModel) {
|
|
88
|
+
const kind = controlKinds[legacyFoundationComponentAliases[component.component] ?? component.component];
|
|
89
|
+
if (!kind || component.disabled === true)
|
|
90
|
+
return null;
|
|
91
|
+
const props = { ...component };
|
|
92
|
+
if (kind === "lp.slider") {
|
|
93
|
+
for (const key of ["min", "max", "step"])
|
|
94
|
+
props[key] = resolveValue(component[key], binding, functions);
|
|
95
|
+
}
|
|
96
|
+
const local = validateFieldValue(kind, props, value);
|
|
97
|
+
if (local)
|
|
98
|
+
return local;
|
|
99
|
+
if (kind !== "lp.select" && kind !== "lp.choice-group")
|
|
100
|
+
return null;
|
|
101
|
+
const available = availableChoices(component, binding, functions, hostData);
|
|
102
|
+
const values = Array.isArray(value) ? value : value === "" ? [] : [value];
|
|
103
|
+
if (values.every(entry => typeof entry === "string" && available.has(entry)))
|
|
104
|
+
return null;
|
|
105
|
+
return { errorCode: "draft_unavailable", message: "This selection is no longer available. Choose another option or clear the selection." };
|
|
106
|
+
}
|
|
107
|
+
/** A multiple-choice toggle replaces any choice the group can no longer hold, so the user's action always resolves it. */
|
|
108
|
+
export function toggleAvailableChoice(component, binding, current, value, checked, functions, hostData = binding.dataModel) {
|
|
109
|
+
const available = availableChoices(component, binding, functions, hostData);
|
|
110
|
+
return toggleChoiceValue(current.filter(entry => available.has(entry)), value, checked);
|
|
111
|
+
}
|
|
112
|
+
// A value the control can no longer hold after a refresh: a withdrawn choice, or a slider
|
|
113
|
+
// position outside a new range. The user cannot produce either, so only a refresh does.
|
|
114
|
+
const staleValueCodes = new Set(["draft_unavailable", "invalid_slider_value"]);
|
|
115
|
+
/**
|
|
116
|
+
* Whether a saved edit is a stale draft conflict: its field is gone, disabled or ambiguous,
|
|
117
|
+
* or the field can no longer hold the edited value. This is the only thing that pauses a
|
|
118
|
+
* form or an action; ordinary validity never does.
|
|
119
|
+
*/
|
|
120
|
+
function isStaleDraft(field, value, hostData, functions) {
|
|
121
|
+
if (!field || field.disabled)
|
|
122
|
+
return true;
|
|
123
|
+
const error = validateControlValue(field.component, field.binding, value, functions, hostData);
|
|
124
|
+
return error !== null && staleValueCodes.has(error.errorCode);
|
|
125
|
+
}
|
|
126
|
+
/** Only readers of an invalid field are prevented from calculating. Other content stays usable. */
|
|
127
|
+
export function calculationInputErrors(state, dataModel, blockedPaths, functions) {
|
|
128
|
+
const errors = new Map();
|
|
129
|
+
for (const path of blockedPaths)
|
|
130
|
+
errors.set(path, { kind: "calculation-error", code: "invalid_input", path });
|
|
131
|
+
for (const field of fieldsIn({ ...state, dataModel }, functions)) {
|
|
132
|
+
const invalid = validateControlValue(field.component, field.binding, readPointer(dataModel, field.path), functions, state.dataModel);
|
|
133
|
+
if (!invalid)
|
|
134
|
+
continue;
|
|
135
|
+
const label = resolveString(field.component.label, field.binding, functions);
|
|
136
|
+
const locale = surfaceLanguage(state.rendererHints);
|
|
137
|
+
const message = fieldMessageWithLabel(label, fieldErrorMessage(invalid, field.component, locale), locale);
|
|
138
|
+
errors.set(field.path, { kind: "calculation-error", code: "invalid_input", path: field.path, message });
|
|
139
|
+
}
|
|
140
|
+
return errors;
|
|
141
|
+
}
|
|
142
|
+
export function createInputDraft(state, change, functions) {
|
|
143
|
+
const fields = fieldsIn(state, functions);
|
|
144
|
+
const matches = fields.filter(field => field.componentId === change.componentId && field.fieldId === change.fieldId && field.path === change.path && field.itemId === change.itemId);
|
|
145
|
+
const field = matches.length === 1 ? matches[0] : undefined;
|
|
146
|
+
if (!field || field.disabled || fields.filter(other => other.key === field.key).length !== 1)
|
|
147
|
+
return null;
|
|
148
|
+
return { key: field.key, change, formKey: field.formKey };
|
|
149
|
+
}
|
|
150
|
+
export function reconcileInputDrafts(state, drafts, functions) {
|
|
151
|
+
const fields = state ? fieldsIn(state, functions) : [];
|
|
152
|
+
let dataModel = state?.dataModel ?? {};
|
|
153
|
+
const conflicts = [];
|
|
154
|
+
const blockedInputPaths = new Set(), blockedFormKeys = new Set();
|
|
155
|
+
for (const [key, draft] of Object.entries(drafts)) {
|
|
156
|
+
const matches = fields.filter(field => field.key === key);
|
|
157
|
+
const field = matches.length === 1 ? matches[0] : undefined;
|
|
158
|
+
// A mounted, enabled field keeps the user's value until they replace or clear it.
|
|
159
|
+
if (field && !field.disabled)
|
|
160
|
+
dataModel = writePointer(dataModel, field.path, draft.change.value);
|
|
161
|
+
if (!isStaleDraft(field, draft.change.value, state?.dataModel, functions))
|
|
162
|
+
continue;
|
|
163
|
+
const formKey = field?.formKey ?? draft.formKey;
|
|
164
|
+
conflicts.push({ key, change: { ...draft.change, path: field?.path ?? draft.change.path }, formKey });
|
|
165
|
+
// Current field paths follow stable item identity; an old row index may now name another row.
|
|
166
|
+
for (const match of matches)
|
|
167
|
+
blockedInputPaths.add(match.path);
|
|
168
|
+
if (!matches.length && draft.change.itemId === undefined && state && !fields.some(other => other.path === draft.change.path) && readPointer(state.dataModel, draft.change.path) !== undefined) {
|
|
169
|
+
blockedInputPaths.add(draft.change.path);
|
|
170
|
+
}
|
|
171
|
+
if (formKey)
|
|
172
|
+
blockedFormKeys.add(formKey);
|
|
173
|
+
}
|
|
174
|
+
return { dataModel, conflicts, blockedInputPaths, blockedFormKeys };
|
|
175
|
+
}
|
|
176
|
+
/**
|
|
177
|
+
* The drafts left when the user discards the stale ones. Those fields show the Host's current
|
|
178
|
+
* values again, which is the way out when no available choice is left to pick.
|
|
179
|
+
*/
|
|
180
|
+
export function discardStaleDrafts(drafts, conflicts) {
|
|
181
|
+
const stale = new Set(conflicts.map(conflict => conflict.key));
|
|
182
|
+
return Object.fromEntries(Object.entries(drafts).filter(([key]) => !stale.has(key)));
|
|
183
|
+
}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
export declare const inputValidationProfiles: readonly ["none", "email", "url", "phone-e164", "phone-sg", "phone-cn", "phone-us", "phone-gb", "iso-date", "number", "integer", "host"];
|
|
2
|
+
export type InputValidationProfile = (typeof inputValidationProfiles)[number];
|
|
3
|
+
export type InputValidationErrorCode = "required" | "invalid_email" | "invalid_url" | "invalid_phone_e164" | "invalid_phone_sg" | "invalid_phone_cn" | "invalid_phone_us" | "invalid_phone_gb" | "invalid_iso_date" | "invalid_time" | "invalid_datetime" | "invalid_number" | "invalid_integer";
|
|
4
|
+
export type InputValidationResult = {
|
|
5
|
+
valid: boolean;
|
|
6
|
+
errorCode: InputValidationErrorCode | null;
|
|
7
|
+
};
|
|
8
|
+
export declare function isInputValidationProfile(value: unknown): value is InputValidationProfile;
|
|
9
|
+
/**
|
|
10
|
+
* Calendar arithmetic rather than `Date.UTC`, which maps years 0-99 onto 1900-1999.
|
|
11
|
+
* The Compose and SwiftUI renderers implement the same rule; the shared cases live in
|
|
12
|
+
* `contracts/fixtures/renderer/field-validation.json`.
|
|
13
|
+
*/
|
|
14
|
+
export declare function isIsoDate(value: string): boolean;
|
|
15
|
+
/** `HH:MM`, `HH:MM:SS` or `HH:MM:SS.mmm`, the forms a native time input produces. */
|
|
16
|
+
export declare function isIsoTime(value: string): boolean;
|
|
17
|
+
/**
|
|
18
|
+
* A plain decimal number. `Number()` also accepts hex, binary and `Infinity`, which a
|
|
19
|
+
* native renderer would have to copy parser by parser, so the rule is spelled out.
|
|
20
|
+
*/
|
|
21
|
+
export declare function isDecimalNumber(value: string): boolean;
|
|
22
|
+
/**
|
|
23
|
+
* An http(s) URL with a host and no whitespace. WHATWG `new URL()` also repairs input
|
|
24
|
+
* (`http:example.com`, spaces in a path), which native URL parsers do not reproduce.
|
|
25
|
+
*/
|
|
26
|
+
export declare function isHttpUrl(value: string): boolean;
|
|
27
|
+
export declare function validateInputValue(value: string, options?: {
|
|
28
|
+
profile?: InputValidationProfile;
|
|
29
|
+
required?: boolean;
|
|
30
|
+
}): InputValidationResult;
|
|
31
|
+
/** Integer drafts keep their original text; conversion never accepts a partial parse. */
|
|
32
|
+
export declare function isSafeIntegerText(value: string): boolean;
|
|
33
|
+
export declare function inputValidationMessage(errorCode: InputValidationErrorCode): string;
|
|
@@ -0,0 +1,119 @@
|
|
|
1
|
+
export const inputValidationProfiles = [
|
|
2
|
+
"none",
|
|
3
|
+
"email",
|
|
4
|
+
"url",
|
|
5
|
+
"phone-e164",
|
|
6
|
+
"phone-sg",
|
|
7
|
+
"phone-cn",
|
|
8
|
+
"phone-us",
|
|
9
|
+
"phone-gb",
|
|
10
|
+
"iso-date",
|
|
11
|
+
"number",
|
|
12
|
+
"integer",
|
|
13
|
+
"host",
|
|
14
|
+
];
|
|
15
|
+
export function isInputValidationProfile(value) {
|
|
16
|
+
return typeof value === "string" && inputValidationProfiles.includes(value);
|
|
17
|
+
}
|
|
18
|
+
function result(errorCode) {
|
|
19
|
+
return { valid: errorCode === null, errorCode };
|
|
20
|
+
}
|
|
21
|
+
function compactPhone(value) {
|
|
22
|
+
const compact = value.trim().replace(/[\s().-]/g, "");
|
|
23
|
+
return /^\+?\d+$/.test(compact) ? compact : null;
|
|
24
|
+
}
|
|
25
|
+
/**
|
|
26
|
+
* Calendar arithmetic rather than `Date.UTC`, which maps years 0-99 onto 1900-1999.
|
|
27
|
+
* The Compose and SwiftUI renderers implement the same rule; the shared cases live in
|
|
28
|
+
* `contracts/fixtures/renderer/field-validation.json`.
|
|
29
|
+
*/
|
|
30
|
+
export function isIsoDate(value) {
|
|
31
|
+
const match = /^(\d{4})-(\d{2})-(\d{2})$/.exec(value);
|
|
32
|
+
if (!match)
|
|
33
|
+
return false;
|
|
34
|
+
const year = Number(match[1]);
|
|
35
|
+
const month = Number(match[2]);
|
|
36
|
+
const day = Number(match[3]);
|
|
37
|
+
if (month < 1 || month > 12)
|
|
38
|
+
return false;
|
|
39
|
+
const leap = year % 400 === 0 || (year % 4 === 0 && year % 100 !== 0);
|
|
40
|
+
const daysInMonth = month === 2 ? (leap ? 29 : 28) : [4, 6, 9, 11].includes(month) ? 30 : 31;
|
|
41
|
+
return day >= 1 && day <= daysInMonth;
|
|
42
|
+
}
|
|
43
|
+
/** `HH:MM`, `HH:MM:SS` or `HH:MM:SS.mmm`, the forms a native time input produces. */
|
|
44
|
+
export function isIsoTime(value) {
|
|
45
|
+
return /^(?:[01]\d|2[0-3]):[0-5]\d(?::[0-5]\d(?:\.\d{1,3})?)?$/.test(value);
|
|
46
|
+
}
|
|
47
|
+
/**
|
|
48
|
+
* A plain decimal number. `Number()` also accepts hex, binary and `Infinity`, which a
|
|
49
|
+
* native renderer would have to copy parser by parser, so the rule is spelled out.
|
|
50
|
+
*/
|
|
51
|
+
export function isDecimalNumber(value) {
|
|
52
|
+
return /^[+-]?(?:\d+(?:\.\d*)?|\.\d+)(?:[eE][+-]?\d+)?$/.test(value) && Number.isFinite(Number(value));
|
|
53
|
+
}
|
|
54
|
+
/**
|
|
55
|
+
* An http(s) URL with a host and no whitespace. WHATWG `new URL()` also repairs input
|
|
56
|
+
* (`http:example.com`, spaces in a path), which native URL parsers do not reproduce.
|
|
57
|
+
*/
|
|
58
|
+
export function isHttpUrl(value) {
|
|
59
|
+
return /^https?:\/\/[^\s/?#]+(?:[/?#]\S*)?$/i.test(value);
|
|
60
|
+
}
|
|
61
|
+
export function validateInputValue(value, options = {}) {
|
|
62
|
+
const trimmed = value.trim();
|
|
63
|
+
if (trimmed.length === 0)
|
|
64
|
+
return result(options.required ? "required" : null);
|
|
65
|
+
const profile = options.profile ?? "none";
|
|
66
|
+
if (profile === "none" || profile === "host")
|
|
67
|
+
return result(null);
|
|
68
|
+
if (profile === "email") {
|
|
69
|
+
return result(/^[^\s@]+@[^\s@]+\.[^\s@]{2,}$/.test(trimmed) ? null : "invalid_email");
|
|
70
|
+
}
|
|
71
|
+
if (profile === "url")
|
|
72
|
+
return result(isHttpUrl(trimmed) ? null : "invalid_url");
|
|
73
|
+
if (profile === "iso-date")
|
|
74
|
+
return result(isIsoDate(trimmed) ? null : "invalid_iso_date");
|
|
75
|
+
if (profile === "integer")
|
|
76
|
+
return result(isSafeIntegerText(value) ? null : "invalid_integer");
|
|
77
|
+
if (profile === "number")
|
|
78
|
+
return result(isDecimalNumber(trimmed) ? null : "invalid_number");
|
|
79
|
+
const phone = compactPhone(trimmed);
|
|
80
|
+
if (profile === "phone-e164") {
|
|
81
|
+
return result(phone !== null && /^\+[1-9]\d{7,14}$/.test(phone) ? null : "invalid_phone_e164");
|
|
82
|
+
}
|
|
83
|
+
if (profile === "phone-sg") {
|
|
84
|
+
const local = phone?.startsWith("+65") ? phone.slice(3) : phone?.length === 10 && phone.startsWith("65") ? phone.slice(2) : phone;
|
|
85
|
+
return result(local !== null && /^[3689]\d{7}$/.test(local) ? null : "invalid_phone_sg");
|
|
86
|
+
}
|
|
87
|
+
if (profile === "phone-cn") {
|
|
88
|
+
const local = phone?.startsWith("+86") ? phone.slice(3) : phone?.length === 13 && phone.startsWith("86") ? phone.slice(2) : phone;
|
|
89
|
+
return result(local !== null && /^1[3-9]\d{9}$/.test(local) ? null : "invalid_phone_cn");
|
|
90
|
+
}
|
|
91
|
+
if (profile === "phone-us") {
|
|
92
|
+
const local = phone?.startsWith("+1") ? phone.slice(2) : phone?.length === 11 && phone.startsWith("1") ? phone.slice(1) : phone;
|
|
93
|
+
return result(local !== null && /^[2-9]\d{2}[2-9]\d{6}$/.test(local) ? null : "invalid_phone_us");
|
|
94
|
+
}
|
|
95
|
+
const validGb = phone !== null && (/^\+44\d{10}$/.test(phone) || /^0\d{10}$/.test(phone));
|
|
96
|
+
return result(validGb ? null : "invalid_phone_gb");
|
|
97
|
+
}
|
|
98
|
+
/** Integer drafts keep their original text; conversion never accepts a partial parse. */
|
|
99
|
+
export function isSafeIntegerText(value) {
|
|
100
|
+
return value.length <= 512 && /^[+-]?[0-9]+$/.test(value) && Number.isSafeInteger(Number(value));
|
|
101
|
+
}
|
|
102
|
+
export function inputValidationMessage(errorCode) {
|
|
103
|
+
const messages = {
|
|
104
|
+
required: "This field is required.",
|
|
105
|
+
invalid_email: "Enter a valid email address.",
|
|
106
|
+
invalid_url: "Enter a valid http or https URL.",
|
|
107
|
+
invalid_phone_e164: "Enter a phone number with country code, such as +65 9123 4567.",
|
|
108
|
+
invalid_phone_sg: "Enter a valid Singapore phone number.",
|
|
109
|
+
invalid_phone_cn: "Enter a valid mainland China phone number.",
|
|
110
|
+
invalid_phone_us: "Enter a valid US phone number.",
|
|
111
|
+
invalid_phone_gb: "Enter a valid UK phone number.",
|
|
112
|
+
invalid_iso_date: "Enter a valid date.",
|
|
113
|
+
invalid_time: "Enter a valid time.",
|
|
114
|
+
invalid_datetime: "Enter a valid date and time.",
|
|
115
|
+
invalid_number: "Enter a valid number.",
|
|
116
|
+
invalid_integer: "Enter a whole number without spaces, decimals or an exponent.",
|
|
117
|
+
};
|
|
118
|
+
return messages[errorCode];
|
|
119
|
+
}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import type { InputDraft } from "./inputDrafts.ts";
|
|
2
|
+
/** Whether one JSON Pointer is the other, or lies above or below it. */
|
|
3
|
+
export declare function pathsOverlap(a: string, b: string): boolean;
|
|
4
|
+
/** The local overrides left after the user edits the field at `path`. */
|
|
5
|
+
export declare function overridesAfterEdit(overrides: Readonly<Record<string, unknown>>, path: string): Readonly<Record<string, unknown>>;
|
|
6
|
+
/** The input drafts left after a local action writes `path`. */
|
|
7
|
+
export declare function draftsAfterLocalWrite(drafts: Readonly<Record<string, InputDraft>>, path: string): Readonly<Record<string, InputDraft>>;
|
|
8
|
+
/** `model` with the local overrides written over it. */
|
|
9
|
+
export declare function applyLocalOverrides(model: unknown, overrides: Readonly<Record<string, unknown>>): unknown;
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import { writePointer } from "../core/pointer.js";
|
|
2
|
+
/*
|
|
3
|
+
* A surface keeps two kinds of local writes on top of the Host's data model: input drafts (what
|
|
4
|
+
* the user typed or picked) and local overrides (what `setValue` and `toggleLocalFlag` wrote).
|
|
5
|
+
* Whichever was written last at a path wins, for what the field shows and what a form submits:
|
|
6
|
+
* a user edit after a `setValue` replaces it, and a later `setValue` replaces an earlier edit.
|
|
7
|
+
* So each write clears the other kind at every path it overlaps (the same path, above or below).
|
|
8
|
+
*/
|
|
9
|
+
/** Whether one JSON Pointer is the other, or lies above or below it. */
|
|
10
|
+
export function pathsOverlap(a, b) {
|
|
11
|
+
return a === b || b.startsWith(`${a}/`) || a.startsWith(`${b}/`);
|
|
12
|
+
}
|
|
13
|
+
/** The local overrides left after the user edits the field at `path`. */
|
|
14
|
+
export function overridesAfterEdit(overrides, path) {
|
|
15
|
+
const kept = Object.entries(overrides).filter(([target]) => !pathsOverlap(target, path));
|
|
16
|
+
return kept.length === Object.keys(overrides).length ? overrides : Object.fromEntries(kept);
|
|
17
|
+
}
|
|
18
|
+
/** The input drafts left after a local action writes `path`. */
|
|
19
|
+
export function draftsAfterLocalWrite(drafts, path) {
|
|
20
|
+
const kept = Object.entries(drafts).filter(([, draft]) => !pathsOverlap(draft.change.path, path));
|
|
21
|
+
return kept.length === Object.keys(drafts).length ? drafts : Object.fromEntries(kept);
|
|
22
|
+
}
|
|
23
|
+
/** `model` with the local overrides written over it. */
|
|
24
|
+
export function applyLocalOverrides(model, overrides) {
|
|
25
|
+
let result = model;
|
|
26
|
+
for (const [path, value] of Object.entries(overrides))
|
|
27
|
+
result = writePointer(result, path, value);
|
|
28
|
+
return result;
|
|
29
|
+
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { type A2uiSurfaceHandle, type A2uiSurfaceProps as FoundationA2uiSurfaceProps } from "./runtime.tsx";
|
|
2
|
+
export declare const rendererRegistry: Readonly<Record<string, import("./context.ts").ComponentRenderer>>;
|
|
3
|
+
export declare const rendererPrintMetadata: Readonly<{
|
|
4
|
+
[k: string]: {
|
|
5
|
+
printMode: "fill" | "rows" | "fixed" | "prose" | undefined;
|
|
6
|
+
};
|
|
7
|
+
}>;
|
|
8
|
+
export type A2uiSurfaceProps = Omit<FoundationA2uiSurfaceProps, "registry" | "stylePacks" | "componentMetadata">;
|
|
9
|
+
/**
|
|
10
|
+
* Complete composition root: Foundation runtime plus every public component. A `ref`
|
|
11
|
+
* reaches Foundation's `A2uiSurfaceHandle` unchanged.
|
|
12
|
+
*/
|
|
13
|
+
export declare const A2uiSurface: import("react").ForwardRefExoticComponent<A2uiSurfaceProps & import("react").RefAttributes<A2uiSurfaceHandle>>;
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
+
import { forwardRef } from "react";
|
|
3
|
+
import { A2uiSurface as FoundationA2uiSurface, composeRendererRegistries, foundationRendererRegistry, } from "./runtime.js";
|
|
4
|
+
import { rendererStylePacks } from "./fullTheme.js";
|
|
5
|
+
import { rendererCatalog } from "./catalog/catalog-index.generated.js";
|
|
6
|
+
import { semanticRendererRegistry } from "./components.full.js";
|
|
7
|
+
export const rendererRegistry = composeRendererRegistries(foundationRendererRegistry, semanticRendererRegistry);
|
|
8
|
+
export const rendererPrintMetadata = Object.freeze(Object.fromEntries(rendererCatalog.map((entry) => [entry.component, { printMode: entry.printSize?.mode }])));
|
|
9
|
+
/**
|
|
10
|
+
* Complete composition root: Foundation runtime plus every public component. A `ref`
|
|
11
|
+
* reaches Foundation's `A2uiSurfaceHandle` unchanged.
|
|
12
|
+
*/
|
|
13
|
+
export const A2uiSurface = forwardRef(function A2uiSurface(props, ref) {
|
|
14
|
+
return (_jsx(FoundationA2uiSurface, { ...props, ref: ref, registry: rendererRegistry, stylePacks: rendererStylePacks, componentMetadata: rendererPrintMetadata }));
|
|
15
|
+
});
|