@rocapine/react-native-onboarding 1.74.1 → 1.75.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.
Files changed (50) hide show
  1. package/dist/evaluateCondition.d.ts.map +1 -1
  2. package/dist/evaluateCondition.js +103 -4
  3. package/dist/evaluateCondition.js.map +1 -1
  4. package/dist/index.d.ts +6 -0
  5. package/dist/index.d.ts.map +1 -1
  6. package/dist/index.js +25 -1
  7. package/dist/index.js.map +1 -1
  8. package/dist/onboarding-example.d.ts +235 -99
  9. package/dist/onboarding-example.d.ts.map +1 -1
  10. package/dist/onboarding-example.js +77 -0
  11. package/dist/onboarding-example.js.map +1 -1
  12. package/dist/screens/completingActions.d.ts +43 -0
  13. package/dist/screens/completingActions.d.ts.map +1 -0
  14. package/dist/screens/completingActions.js +108 -0
  15. package/dist/screens/completingActions.js.map +1 -0
  16. package/dist/screens/elementTypeRegistry.d.ts +31 -0
  17. package/dist/screens/elementTypeRegistry.d.ts.map +1 -0
  18. package/dist/screens/elementTypeRegistry.js +82 -0
  19. package/dist/screens/elementTypeRegistry.js.map +1 -0
  20. package/dist/screens/resolveRenderableStep.d.ts +42 -0
  21. package/dist/screens/resolveRenderableStep.d.ts.map +1 -0
  22. package/dist/screens/resolveRenderableStep.js +28 -0
  23. package/dist/screens/resolveRenderableStep.js.map +1 -0
  24. package/dist/screens/unknownElementTypes.d.ts +94 -0
  25. package/dist/screens/unknownElementTypes.d.ts.map +1 -0
  26. package/dist/screens/unknownElementTypes.js +141 -0
  27. package/dist/screens/unknownElementTypes.js.map +1 -0
  28. package/dist/screens/unknownKeys.d.ts +5 -2
  29. package/dist/screens/unknownKeys.d.ts.map +1 -1
  30. package/dist/screens/unknownKeys.js +7 -52
  31. package/dist/screens/unknownKeys.js.map +1 -1
  32. package/dist/steps/common.types.d.ts +84 -3
  33. package/dist/steps/common.types.d.ts.map +1 -1
  34. package/dist/steps/common.types.js.map +1 -1
  35. package/package.json +1 -1
  36. package/src/__tests__/completingActions.test.ts +139 -0
  37. package/src/__tests__/elementTypeRegistry.test.ts +48 -0
  38. package/src/__tests__/evaluateCondition.test.ts +228 -3
  39. package/src/__tests__/onboardingExampleElements.test.ts +27 -0
  40. package/src/__tests__/resolveRenderableStep.test.ts +117 -0
  41. package/src/__tests__/unknownElementTypes.test.ts +240 -0
  42. package/src/evaluateCondition.ts +107 -4
  43. package/src/index.ts +23 -0
  44. package/src/onboarding-example.ts +78 -0
  45. package/src/screens/completingActions.ts +108 -0
  46. package/src/screens/elementTypeRegistry.ts +88 -0
  47. package/src/screens/resolveRenderableStep.ts +59 -0
  48. package/src/screens/unknownElementTypes.ts +204 -0
  49. package/src/screens/unknownKeys.ts +7 -50
  50. package/src/steps/common.types.ts +84 -3
@@ -0,0 +1,88 @@
1
+ import { UIElementSchema } from "./types";
2
+
3
+ /**
4
+ * The element `type` names this SDK build knows, and the key sets each of them
5
+ * accepts — read off `UIElementSchema` itself at runtime rather than hardcoded,
6
+ * so nothing here can drift as elements are added.
7
+ *
8
+ * Two consumers, deliberately sharing one derivation: `unknownKeys.ts` (which
9
+ * keys it needs) and `unknownElementTypes.ts` (which *types* exist at all).
10
+ * They used to be able to disagree about what "known" means, which for a
11
+ * forward-compatibility strip is not a cosmetic risk: a type the strip thinks
12
+ * is unknown is a type the app silently refuses to render.
13
+ */
14
+ export type ElementKeySets = { topLevel: Set<string>; props: Set<string> };
15
+
16
+ const zdef = (schema: any): any => schema?._zod?.def ?? schema?._def;
17
+
18
+ // Every string literal a `type` field can hold. Variants use `z.literal("X")`;
19
+ // a `z.union([literal, literal])` is tolerated for robustness.
20
+ const literalsOf = (schema: any): string[] => {
21
+ const def = zdef(schema);
22
+ if (!def) return [];
23
+ if (def.type === "literal") {
24
+ const values = def.values ?? (def.value !== undefined ? [def.value] : []);
25
+ return values.filter((v: unknown): v is string => typeof v === "string");
26
+ }
27
+ if (def.type === "union") return (def.options ?? []).flatMap(literalsOf);
28
+ return [];
29
+ };
30
+
31
+ /**
32
+ * The derivation itself, over ANY element union — this package's, or another
33
+ * package's re-declared mirror of it.
34
+ *
35
+ * Kept schema-agnostic because the onboarding-ui package has to derive its own
36
+ * capability set rather than inherit this one's: it re-declares its own
37
+ * `UIElementSchema`, that mirror is what actually parses and renders an element
38
+ * tree, and the peer-dependency range between the two packages lets a host
39
+ * resolve different versions of them. Sharing the mechanism but not the answer
40
+ * is the point — one place that knows how to read a discriminated union, two
41
+ * honest answers about two schemas.
42
+ */
43
+ const buildElementRegistry = (schema: unknown): Map<string, ElementKeySets> => {
44
+ const built = new Map<string, ElementKeySets>();
45
+ try {
46
+ const lazyDef = zdef(schema);
47
+ const union = typeof lazyDef?.getter === "function" ? lazyDef.getter() : schema;
48
+ const options = zdef(union)?.options ?? [];
49
+ for (const option of options) {
50
+ const shape = zdef(option)?.shape;
51
+ if (!shape) continue;
52
+ const propsShape = zdef(shape.props)?.shape ?? {};
53
+ const keySets: ElementKeySets = {
54
+ topLevel: new Set(Object.keys(shape)),
55
+ props: new Set(Object.keys(propsShape)),
56
+ };
57
+ for (const typeName of literalsOf(shape.type)) built.set(typeName, keySets);
58
+ }
59
+ } catch {
60
+ // fall through to whatever was built before the failure
61
+ }
62
+ return built;
63
+ };
64
+
65
+ /**
66
+ * Every element `type` a given element union declares. EMPTY means "could not
67
+ * tell" — zod internals moved, or this is not an element union — and every
68
+ * caller must read it as "learn nothing" rather than "reject everything", which
69
+ * would blank every screen in every app.
70
+ */
71
+ export const deriveElementTypeNames = (schema: unknown): ReadonlySet<string> =>
72
+ new Set(buildElementRegistry(schema).keys());
73
+
74
+ let registry: Map<string, ElementKeySets> | null = null;
75
+
76
+ /**
77
+ * Built once, lazily, from THIS package's schema. Any shape change in zod's
78
+ * internals degrades to an EMPTY registry, read as "learn nothing" — this is a
79
+ * diagnostic and a forward-compat aid, it must never be able to break rendering.
80
+ */
81
+ export const getElementRegistry = (): Map<string, ElementKeySets> => {
82
+ if (registry) return registry;
83
+ registry = buildElementRegistry(UIElementSchema);
84
+ return registry;
85
+ };
86
+
87
+ /** Every element `type` this build can parse. Empty means "could not tell". */
88
+ export const getKnownElementTypes = (): ReadonlySet<string> => new Set(getElementRegistry().keys());
@@ -0,0 +1,59 @@
1
+ import { hasCompletingAction } from "./completingActions";
2
+ import {
3
+ collectUnknownElementTypes,
4
+ dropUnknownElementTypesInStep,
5
+ type UnknownElementType,
6
+ } from "./unknownElementTypes";
7
+
8
+ /**
9
+ * The whole render-boundary decision for element-type forward compatibility
10
+ * (#209): what to parse, what to log, and whether the renderer must supply its
11
+ * own way off the screen.
12
+ *
13
+ * It lives here rather than in the renderer because the onboarding-ui package's
14
+ * vitest runs in plain Node and cannot import `react-native` — logic decided
15
+ * there is only assertable at source level, and the escape decision is the part
16
+ * of this feature that must not be wrong.
17
+ */
18
+ export type RenderableStep<T> = {
19
+ /**
20
+ * The step to parse and render. The SAME reference as the input when nothing
21
+ * was stripped, so the common path allocates nothing and stays `useMemo`-stable.
22
+ */
23
+ step: T;
24
+ /** The elements omitted, for the log. Empty when nothing was stripped. */
25
+ omitted: UnknownElementType[];
26
+ /**
27
+ * The strip left nothing in the tree that can complete the screen, so the
28
+ * renderer must supply an escape of its own — otherwise the user sits on a
29
+ * screen with no CTA and, on a `displayProgressHeader: false` step, no back
30
+ * chevron: the dead end #209 exists to close, re-created silently.
31
+ *
32
+ * Only ever true when something WAS stripped. An authored screen with no way
33
+ * forward is an authoring bug (and the host may advance it another way, e.g. a
34
+ * custom action that navigates); injecting a CTA into shipped screens that
35
+ * have nothing to do with an unknown element type is not this feature's call.
36
+ */
37
+ needsEscape: boolean;
38
+ };
39
+
40
+ /**
41
+ * @param step A step as fetched, unparsed.
42
+ * @param known The element types the CALLER can render — the renderer's own
43
+ * capability, not this package's schema. The two are separate packages with a
44
+ * peer-dependency range between them, so their versions can legitimately
45
+ * differ, and it is what draws that must decide what is kept. An empty set
46
+ * means "could not tell" and strips nothing.
47
+ */
48
+ export const resolveRenderableStep = <T>(step: T, known?: ReadonlySet<string>): RenderableStep<T> => {
49
+ const renderable = dropUnknownElementTypesInStep(step, known);
50
+ if (renderable === step) return { step, omitted: [], needsEscape: false };
51
+
52
+ const authoredElements = (step as { payload?: { elements?: unknown } })?.payload?.elements;
53
+ const renderableElements = (renderable as { payload?: { elements?: unknown } })?.payload?.elements;
54
+ return {
55
+ step: renderable,
56
+ omitted: collectUnknownElementTypes(authoredElements, "elements", known),
57
+ needsEscape: !hasCompletingAction(renderableElements),
58
+ };
59
+ };
@@ -0,0 +1,204 @@
1
+ import { getKnownElementTypes } from "./elementTypeRegistry";
2
+
3
+ /**
4
+ * FORWARD COMPATIBILITY FOR ELEMENT TYPES (issue #209).
5
+ *
6
+ * `UIElementSchema` is a `z.discriminatedUnion("type", …)` over the element
7
+ * types *this build* knows. An element type published after an app shipped
8
+ * therefore missed every branch, and the whole `elements` array failed to
9
+ * parse — one new element type took down the entire screen, in every installed
10
+ * app pinned to an older SDK.
11
+ *
12
+ * That is worse than a blank screen. The ComposableScreen renderer parses with
13
+ * a throwing `.parse` inside `withErrorBoundary`, and that fallback has no
14
+ * interactive control; the host's back chevron lives inside `<ProgressBar>`,
15
+ * gated on the step's `displayProgressHeader`. On a header-off step there is no
16
+ * exit in either direction, because `onContinue` died with the subtree. Real
17
+ * flows have four such steps, including the entry screen and both steps before
18
+ * the paywall.
19
+ *
20
+ * The fix is a linear walk in FRONT of the schema, not a change to it:
21
+ *
22
+ * • Unknown element `type` → the element is OMITTED, with its subtree, before
23
+ * the payload is parsed. The rest of the screen renders.
24
+ * • Anything else → untouched, so a genuine data bug (a `Button` `variant`
25
+ * outside the enum, a missing `id`) still fails loudly with its exact path.
26
+ *
27
+ * OMIT is the contract, chosen to match what the codebase already does rather
28
+ * than as a new invention: `renderElement` falls through to `return null` for an
29
+ * unrecognized type, `buildAnimation` no-ops an unknown `animation.preset`, and
30
+ * an unknown *step* type already skips with a reason code
31
+ * (`OnboardingPage` → `onContinue("onboarding_screen_not_implemented")`). No
32
+ * placeholder is rendered: a box reading "unsupported" in the middle of an
33
+ * authored layout is worse than the gap it advertises, and the author cannot see
34
+ * it from Studio anyway.
35
+ *
36
+ * WHY NOT WIDEN THE SCHEMA. A non-discriminated union, or a catch-all branch
37
+ * reachable on any miss, is not an option: the discriminator is a deliberate fix
38
+ * for three data-reachable CRASHES (a 512 MB heap OOM on a real 52-node paywall,
39
+ * a `RangeError` thrown from inside zod's own error constructor, and unreadable
40
+ * `invalid_union` output) — see the comment above `UIElementSchema` in
41
+ * `./types.ts` and `__tests__/elementUnionDiscriminator.test.ts`. A fallback
42
+ * branch would also swallow real errors on KNOWN types, turning every CMS data
43
+ * bug into a silently missing element. Stripping first keeps both properties.
44
+ *
45
+ * `ScreenElementsSchema` itself stays STRICT on purpose: authoring- and
46
+ * publish-time validation (Studio, `validate-step-json`, the CLAUDE.md
47
+ * `safeParse` recipe) should keep reporting a typo'd element type as an error.
48
+ * Only the render boundaries strip.
49
+ */
50
+
51
+ /** One element omitted because this build cannot render its `type`. */
52
+ export type UnknownElementType = {
53
+ /** Location in the tree, e.g. `elements[0].children[2]`. */
54
+ path: string;
55
+ elementId: string;
56
+ /** The `type` value no variant of `UIElementSchema` declares. */
57
+ elementType: string;
58
+ };
59
+
60
+ /**
61
+ * Every element `type` this SDK build can parse and render, sorted.
62
+ *
63
+ * The capability list a publish-time gate needs (#209's "capability floor"):
64
+ * derived from `UIElementSchema`, so it is exactly what the installed build
65
+ * supports and cannot be forgotten when an element is added.
66
+ */
67
+ export const KNOWN_ELEMENT_TYPES: readonly string[] = [...getKnownElementTypes()].sort();
68
+
69
+ const isRecord = (v: unknown): v is Record<string, unknown> =>
70
+ typeof v === "object" && v !== null && !Array.isArray(v);
71
+
72
+ /**
73
+ * An empty registry means the derivation failed (zod internals moved), not that
74
+ * no element type exists. Read as "learn nothing": every element is kept and the
75
+ * schema decides, exactly as it did before this file existed. The inverse
76
+ * reading would blank every screen in every app.
77
+ */
78
+ const resolveKnown = (known?: ReadonlySet<string>): ReadonlySet<string> | null => {
79
+ const set = known ?? getKnownElementTypes();
80
+ return set.size === 0 ? null : set;
81
+ };
82
+
83
+ const isUnknownElement = (node: unknown, known: ReadonlySet<string>): boolean =>
84
+ isRecord(node) && typeof node.type === "string" && !known.has(node.type);
85
+
86
+ /**
87
+ * Strip every element whose `type` this build does not know from an `elements`
88
+ * array (recursively, through `children`).
89
+ *
90
+ * Pure, and structurally sharing: a payload with nothing unknown comes back as
91
+ * the SAME array reference, so this is free on the overwhelmingly common path
92
+ * and stays stable inside a `useMemo`. Non-array input is returned unchanged for
93
+ * the schema to reject.
94
+ *
95
+ * A node with no `type`, or a non-string one, is KEPT: that is a malformed
96
+ * payload rather than a newer element, and dropping it would hide the real error.
97
+ */
98
+ export const dropUnknownElementTypes = <T>(elements: T, known?: ReadonlySet<string>): T => {
99
+ const knownTypes = resolveKnown(known);
100
+ if (knownTypes === null || !Array.isArray(elements)) return elements;
101
+ return dropInArray(elements, knownTypes) as T;
102
+ };
103
+
104
+ const dropInArray = (elements: unknown[], known: ReadonlySet<string>): unknown[] => {
105
+ let changed = false;
106
+ const kept: unknown[] = [];
107
+ for (const node of elements) {
108
+ if (isUnknownElement(node, known)) {
109
+ // The whole subtree goes with it: `renderElement` returns null for an
110
+ // unknown type, so its children never render either.
111
+ changed = true;
112
+ continue;
113
+ }
114
+ const next = dropInNode(node, known);
115
+ if (next !== node) changed = true;
116
+ kept.push(next);
117
+ }
118
+ return changed ? kept : elements;
119
+ };
120
+
121
+ const dropInNode = (node: unknown, known: ReadonlySet<string>): unknown => {
122
+ if (!isRecord(node) || !Array.isArray(node.children)) return node;
123
+ const children = dropInArray(node.children, known);
124
+ return children === node.children ? node : { ...node, children };
125
+ };
126
+
127
+ /**
128
+ * The same strip for a whole step, for callers holding one (the ComposableScreen
129
+ * renderer parses the step, not the array). Steps without `payload.elements` —
130
+ * every non-composable step type — are returned untouched.
131
+ */
132
+ export const dropUnknownElementTypesInStep = <T>(step: T, known?: ReadonlySet<string>): T => {
133
+ if (!isRecord(step)) return step;
134
+ const payload = step.payload;
135
+ if (!isRecord(payload) || !Array.isArray(payload.elements)) return step;
136
+ const elements = dropUnknownElementTypes(payload.elements, known);
137
+ if (elements === payload.elements) return step;
138
+ return { ...step, payload: { ...payload, elements } } as T;
139
+ };
140
+
141
+ /**
142
+ * Report — rather than strip — the elements this build cannot render, so a host
143
+ * (and the dev-time payload diagnostic in `OnboardingProvider`) can say what
144
+ * went missing. An unknown parent is reported ONCE: its descendants go with it,
145
+ * and listing them would bury the one fact that matters.
146
+ */
147
+ export const collectUnknownElementTypes = (
148
+ elements: unknown,
149
+ basePath = "elements",
150
+ known?: ReadonlySet<string>
151
+ ): UnknownElementType[] => {
152
+ const knownTypes = resolveKnown(known);
153
+ if (knownTypes === null || !Array.isArray(elements)) return [];
154
+
155
+ const found: UnknownElementType[] = [];
156
+
157
+ const visit = (node: unknown, path: string): void => {
158
+ if (!isRecord(node)) return;
159
+ if (isUnknownElement(node, knownTypes)) {
160
+ found.push({
161
+ path,
162
+ elementId: typeof node.id === "string" ? node.id : "(no id)",
163
+ elementType: node.type as string,
164
+ });
165
+ return;
166
+ }
167
+ if (Array.isArray(node.children)) {
168
+ node.children.forEach((child, i) => visit(child, `${path}.children[${i}]`));
169
+ }
170
+ };
171
+
172
+ elements.forEach((element, i) => visit(element, `${basePath}[${i}]`));
173
+ return found;
174
+ };
175
+
176
+ /** Same check across a whole steps array, for a caller holding a fetched onboarding. */
177
+ export const collectUnknownElementTypesInSteps = (
178
+ steps: unknown,
179
+ known?: ReadonlySet<string>
180
+ ): UnknownElementType[] => {
181
+ if (!Array.isArray(steps)) return [];
182
+ return steps.flatMap((step, i) => {
183
+ if (!isRecord(step)) return [];
184
+ const payload = step.payload;
185
+ if (!isRecord(payload) || !Array.isArray(payload.elements)) return [];
186
+ const stepId = typeof step.id === "string" ? step.id : String(i);
187
+ return collectUnknownElementTypes(payload.elements, `step[${stepId}].elements`, known);
188
+ });
189
+ };
190
+
191
+ /** Human-readable report; returns "" when there is nothing to say. */
192
+ export const formatUnknownElementTypes = (found: UnknownElementType[]): string => {
193
+ if (found.length === 0) return "";
194
+ const lines = found.map(
195
+ (f) => ` • ${f.path} ("${f.elementId}"): element type "${f.elementType}"`
196
+ );
197
+ return (
198
+ `[onboarding] ${found.length} element${found.length === 1 ? "" : "s"} ` +
199
+ `${found.length === 1 ? "uses a type" : "use types"} this SDK build does not know, ` +
200
+ `so ${found.length === 1 ? "it is" : "they are"} omitted and the rest of the screen ` +
201
+ `renders. Upgrade to a newer @rocapine/react-native-onboarding to render ` +
202
+ `${found.length === 1 ? "it" : "them"}:\n${lines.join("\n")}`
203
+ );
204
+ };
@@ -1,4 +1,4 @@
1
- import { UIElementSchema } from "./types";
1
+ import { getElementRegistry } from "./elementTypeRegistry";
2
2
 
3
3
  /**
4
4
  * Detection for keys placed at an element's TOP LEVEL that the schema doesn't
@@ -51,52 +51,6 @@ export type UnknownElementKey = {
51
51
  conflicts?: boolean;
52
52
  };
53
53
 
54
- type ElementKeySets = { topLevel: Set<string>; props: Set<string> };
55
-
56
- const zdef = (schema: any): any => schema?._zod?.def ?? schema?._def;
57
-
58
- // Every string literal a `type` field can hold. Most variants use
59
- // `z.literal("X")`, but the stack variant is `z.union([literal, literal])`.
60
- const literalsOf = (schema: any): string[] => {
61
- const def = zdef(schema);
62
- if (!def) return [];
63
- if (def.type === "literal") {
64
- const values = def.values ?? (def.value !== undefined ? [def.value] : []);
65
- return values.filter((v: unknown): v is string => typeof v === "string");
66
- }
67
- if (def.type === "union") return (def.options ?? []).flatMap(literalsOf);
68
- return [];
69
- };
70
-
71
- let registry: Map<string, ElementKeySets> | null = null;
72
-
73
- // Built once, lazily. Any shape change in zod's internals degrades to "no
74
- // registry", which makes the whole feature a no-op rather than a crash — this is
75
- // a diagnostic, it must never be able to break rendering.
76
- const getRegistry = (): Map<string, ElementKeySets> => {
77
- if (registry) return registry;
78
- const built = new Map<string, ElementKeySets>();
79
- try {
80
- const lazyDef = zdef(UIElementSchema);
81
- const union = typeof lazyDef?.getter === "function" ? lazyDef.getter() : UIElementSchema;
82
- const options = zdef(union)?.options ?? [];
83
- for (const option of options) {
84
- const shape = zdef(option)?.shape;
85
- if (!shape) continue;
86
- const propsShape = zdef(shape.props)?.shape ?? {};
87
- const keySets: ElementKeySets = {
88
- topLevel: new Set(Object.keys(shape)),
89
- props: new Set(Object.keys(propsShape)),
90
- };
91
- for (const typeName of literalsOf(shape.type)) built.set(typeName, keySets);
92
- }
93
- } catch {
94
- // fall through to whatever was built before the failure
95
- }
96
- registry = built;
97
- return registry;
98
- };
99
-
100
54
  const isRecord = (v: unknown): v is Record<string, unknown> =>
101
55
  typeof v === "object" && v !== null && !Array.isArray(v);
102
56
 
@@ -117,14 +71,17 @@ const valuesDiffer = (a: unknown, b: unknown): boolean => {
117
71
  * Walk an element tree and report unrecognized top-level keys.
118
72
  *
119
73
  * Elements whose `type` isn't in the schema are skipped rather than reported —
120
- * an unknown element type is a parse error the union already surfaces properly,
121
- * and guessing its key set would produce noise.
74
+ * guessing the key set of an element this build has never heard of would produce
75
+ * noise. Unknown element TYPES are their own concern, handled in
76
+ * `./unknownElementTypes.ts`: the render boundaries omit them so a screen
77
+ * published ahead of the installed SDK still renders (#209). Both files derive
78
+ * "known" from the same `./elementTypeRegistry.ts`.
122
79
  */
123
80
  export const collectUnknownElementKeys = (
124
81
  elements: unknown,
125
82
  basePath = "elements"
126
83
  ): UnknownElementKey[] => {
127
- const known = getRegistry();
84
+ const known = getElementRegistry();
128
85
  if (known.size === 0 || !Array.isArray(elements)) return [];
129
86
 
130
87
  const found: UnknownElementKey[] = [];
@@ -71,9 +71,90 @@ export type SetVariableButtonAction = {
71
71
  value: string;
72
72
  label?: string;
73
73
  /**
74
- * When `"expression"`, `value` is parsed as an arithmetic expression with
75
- * `{{var}}` references, numeric literals, and `+ - * /` (parens supported).
76
- * On parse failure, falls back to plain interpolation (string).
74
+ * When `"expression"`, `value` is parsed as an expression over `{{var}}`
75
+ * references, numeric literals, quoted string literals, `+ - * /` (parens
76
+ * supported) and a small function stdlib:
77
+ *
78
+ * - numeric — `min(a, b, ...)`, `max(a, b, ...)`, `abs(a)`,
79
+ * `round(a[, digits])`, `clamp(a, lo, hi)`
80
+ * - dates — `addDays(date, n)`, `format(date, spec[, locale])`. `date` is an
81
+ * ISO string (what `DatePicker` stores) or the `"now"` sentinel `DatePicker`
82
+ * already accepts. `spec` is the `DatePicker` `format` prop's Intl
83
+ * vocabulary: a bare `dateStyle` name (`"medium"`) or `key:value` pairs
84
+ * (`"weekday:long, month:short, day:numeric"`). Not a token language —
85
+ * there is no `YYYY-MM-DD`.
86
+ * - listing — `list(x[, conjunction])` ("A, B and C"), `join(x[, separator])`,
87
+ * `count(x)`, `plural(n, one, other)`. `x` is an untagged multi-select
88
+ * variable (the JSON `string[]` `CheckboxGroup` writes); member LABELS are
89
+ * used when present, matching interpolation's label-first precedence. A
90
+ * scalar answer counts as one member, also by its label. Two things are not
91
+ * lists and fail the call rather than counting as one: a variable holding a
92
+ * number (`count({{age}})` — `plural({{age}}, ...)` is what you wanted),
93
+ * and a value that parses as JSON and is NOT a `string[]` (`"[1,2,3]"`,
94
+ * `{"a":1}`).
95
+ *
96
+ * **This runs at press time only.** Actions have no mount/appear hook and
97
+ * `Text mode: "expression"` interpolates rather than evaluating, so a
98
+ * headline needing a computed value must have it written to a variable by an
99
+ * earlier press (typically the previous screen's Continue) and then simply
100
+ * interpolated.
101
+ *
102
+ * A quoted literal's CONTENTS interpolate, so `{{var}}` means the same thing
103
+ * everywhere in the template: `list({{goals}}) + " for {{name}}"` reads
104
+ * "… for Ada" rather than emitting the braces to the user.
105
+ *
106
+ * A template with no function call falls back to plain interpolation on parse
107
+ * failure (so `"Hello {{name}}"` still works). A template that *attempts* a
108
+ * call and fails stores the empty string and warns, rather than writing the
109
+ * unevaluated source text into a variable a headline would display verbatim.
110
+ *
111
+ * An **absent** variable reads as numeric 0 wherever it is data — which is
112
+ * what makes increment-before-seed arithmetic and `count()` on a skipped
113
+ * screen work — but is refused wherever it is configuration: a `clamp` bound
114
+ * or a `round` digit count, where a typo'd variable name would otherwise
115
+ * produce a plausible constant (`clamp({{score}}, {{floor}}, {{ceiling}})`
116
+ * reported 0 for a score of 42). The taint follows the value, so it also
117
+ * refuses one that reached a bound through arithmetic or a function
118
+ * (`addDays({{d}}, {{weeks}} * 7)`), but is dropped where the result could
119
+ * have come from an untainted argument: `max({{trialDays}}, 7)` is an
120
+ * explicit default and is honoured, as is `max({{seeded_zero}}, {{absent}})`.
121
+ * A `{{ref}}` inside a quoted LITERAL is guarded the same way when it is
122
+ * configuration: `list`'s conjunction, `join`'s separator, `format`'s spec
123
+ * and its LOCALE, and BOTH `plural` forms. `join({{goals}}, "{{sep}}")` with
124
+ * `sep` unset used to run the members together, and `"en{{sfx}}"` as a locale
125
+ * resolved to the valid `"en"` and silently swapped a date's day and month.
126
+ * `plural` checks its count and both forms — both forms because an absent
127
+ * reference in a form is an authoring error whichever one the count selects,
128
+ * and the count because otherwise an unseeded one picks a form silently and
129
+ * `plural` launders it onward.
130
+ *
131
+ * Two known limits, both deliberate. **`count()` does not taint** — a real
132
+ * zero is what `count({{skipped}})` should give on a screen the user never
133
+ * filled in, and the shipped `plural(count({{goals}}), …)` pattern depends
134
+ * on it — so wrapping a name in `count()` defeats the guard, and
135
+ * `round({{pct}}, count({{digits}}))` answers rather than failing.
136
+ * And **`asDate` accepts any `Date.parse`-able string**,
137
+ * including a bare integer, which no taint can reach because the numbers
138
+ * involved are seeded.
139
+ * "Attempts a call" means a **stdlib name** sits in front of a `(` whose
140
+ * contents could actually be arguments. A bare word BETWEEN the parens makes
141
+ * them punctuation instead, and an unglued `(` after an UNKNOWN identifier
142
+ * is not a call, so the English optional-plural idiom survives:
143
+ * `"{{n}} day(s)"` reads "3 day(s)", `"{{n}} min(s) left"` reads
144
+ * "3 min(s) left", `"Goals ({{n}})"` reads "Goals (2)". A STDLIB name is
145
+ * called glued or not — `"max (2) options"` blanks — so prose starting with
146
+ * one needs `valueMode: "literal"`. A stdlib name DOES outrank bare words outside its own parens,
147
+ * so `list({{goals}}) and more` fails loudly — **there is no implicit
148
+ * concatenation**, and prose beside a call must be joined with `+ "…"`. That
149
+ * is the one rule an author has to know to avoid a blank headline.
150
+ *
151
+ * Two residues, both warned about at runtime: an unknown name glued to a `(`
152
+ * with no bare word anywhere is taken as a misspelled call, so `"Save(50)"`
153
+ * and `"Total({{n}})"` blank (write them with a space); and a template that
154
+ * is nothing but a stdlib call with a bare-word argument — `count(goals)`,
155
+ * the braces forgotten — keeps its text but warns, because it cannot be told
156
+ * apart from `min(s)`.
157
+ *
77
158
  * Defaults to `"literal"` — `value` stored verbatim.
78
159
  */
79
160
  valueMode?: "literal" | "expression";