@azx-pbc/axiom-native 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.
- package/LICENSE +21 -0
- package/README.md +95 -2
- package/dist/configurator.d.ts +39 -0
- package/dist/configurator.d.ts.map +1 -0
- package/dist/configurator.js +420 -0
- package/dist/configurator.js.map +1 -0
- package/dist/controls.d.ts +64 -0
- package/dist/controls.d.ts.map +1 -0
- package/dist/controls.js +8 -0
- package/dist/controls.js.map +1 -0
- package/dist/copy.d.ts +216 -0
- package/dist/copy.d.ts.map +1 -0
- package/dist/copy.js +2574 -0
- package/dist/copy.js.map +1 -0
- package/dist/fields.d.ts +9 -0
- package/dist/fields.d.ts.map +1 -0
- package/dist/fields.js +1365 -0
- package/dist/fields.js.map +1 -0
- package/dist/host.d.ts +90 -0
- package/dist/host.d.ts.map +1 -0
- package/dist/host.js +8 -0
- package/dist/host.js.map +1 -0
- package/dist/index.d.ts +18 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +10 -0
- package/dist/index.js.map +1 -0
- package/dist/input-chain.d.ts +28 -0
- package/dist/input-chain.d.ts.map +1 -0
- package/dist/input-chain.js +64 -0
- package/dist/input-chain.js.map +1 -0
- package/dist/render/layout.d.ts +47 -0
- package/dist/render/layout.d.ts.map +1 -0
- package/dist/render/layout.js +8 -0
- package/dist/render/layout.js.map +1 -0
- package/dist/render/native.d.ts +85 -0
- package/dist/render/native.d.ts.map +1 -0
- package/dist/render/native.js +124 -0
- package/dist/render/native.js.map +1 -0
- package/dist/render/tree.d.ts +50 -0
- package/dist/render/tree.d.ts.map +1 -0
- package/dist/render/tree.js +636 -0
- package/dist/render/tree.js.map +1 -0
- package/dist/theme.d.ts +113 -0
- package/dist/theme.d.ts.map +1 -0
- package/dist/theme.js +211 -0
- package/dist/theme.js.map +1 -0
- package/package.json +78 -3
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 AZX, PBC. Open Source
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
CHANGED
|
@@ -1,3 +1,96 @@
|
|
|
1
|
-
#
|
|
1
|
+
# @azx-pbc/axiom-native
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
Axiom's reference React Native renderer for React 19 and React Native (`>=0.78`, verified on 0.88). One `<RenderedForm>` paints a compiled artifact's layout tree and every control in `Control`, with nine-locale copy, runtime theming (`NativeThemeProvider` and `createNativeTheme`), control and layout override seams (`ControlComponents` and `LayoutComponents`), native accessibility projection, and typed capture action ports over `@azx-pbc/axiom-react` and `@azx-pbc/axiom-runtime`.
|
|
4
|
+
|
|
5
|
+
## Install
|
|
6
|
+
|
|
7
|
+
```sh
|
|
8
|
+
pnpm add @azx-pbc/axiom-native @azx-pbc/axiom-react @azx-pbc/axiom-runtime react@^19 react-native
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
From a checkout, `pnpm install` links the workspace packages. The published package is ESM-only and peers on `react` (`^19.0.0`), `react-native` (`>=0.78.0`), and optionally `expo` (`>=53.0.0`).
|
|
12
|
+
|
|
13
|
+
The manifest states Node `>=24`; the renderer targets React Native `>=0.78` on Hermes (ES2023) with zero `Intl` calls and zero DOM or Node imports.
|
|
14
|
+
|
|
15
|
+
## Use
|
|
16
|
+
|
|
17
|
+
```tsx
|
|
18
|
+
import type { ReactElement } from 'react';
|
|
19
|
+
import { FormProvider } from '@azx-pbc/axiom-react';
|
|
20
|
+
import type { AccessEntry, CompiledSchema, WireRecord } from '@azx-pbc/axiom-runtime';
|
|
21
|
+
import {
|
|
22
|
+
ErrorSummary,
|
|
23
|
+
HostActionsContext,
|
|
24
|
+
HostCopyContext,
|
|
25
|
+
NativeThemeProvider,
|
|
26
|
+
RenderedForm,
|
|
27
|
+
createNativeTheme,
|
|
28
|
+
hostCopy,
|
|
29
|
+
} from '@azx-pbc/axiom-native';
|
|
30
|
+
import type { ControlComponents, HostActions, LayoutComponents } from '@azx-pbc/axiom-native';
|
|
31
|
+
|
|
32
|
+
declare const hostActions: HostActions;
|
|
33
|
+
declare const translate: (key: string) => string;
|
|
34
|
+
declare const customControls: ControlComponents;
|
|
35
|
+
declare const customLayout: LayoutComponents;
|
|
36
|
+
|
|
37
|
+
const darkTheme = createNativeTheme({
|
|
38
|
+
color: {
|
|
39
|
+
background: '#101216',
|
|
40
|
+
surface: '#1c2026',
|
|
41
|
+
ink: '#f5f7fa',
|
|
42
|
+
muted: '#9aa4b2',
|
|
43
|
+
border: '#323842',
|
|
44
|
+
accent: '#4dabf7',
|
|
45
|
+
},
|
|
46
|
+
});
|
|
47
|
+
|
|
48
|
+
export function Screen(props: {
|
|
49
|
+
readonly compiled: CompiledSchema;
|
|
50
|
+
readonly record: WireRecord;
|
|
51
|
+
readonly access: readonly AccessEntry[];
|
|
52
|
+
}): ReactElement {
|
|
53
|
+
const copy = hostCopy('en');
|
|
54
|
+
return (
|
|
55
|
+
<NativeThemeProvider theme={darkTheme}>
|
|
56
|
+
<HostActionsContext.Provider value={hostActions}>
|
|
57
|
+
<HostCopyContext.Provider value={copy}>
|
|
58
|
+
<FormProvider
|
|
59
|
+
compiled={props.compiled}
|
|
60
|
+
initialValues={props.record}
|
|
61
|
+
access={props.access}
|
|
62
|
+
valueDisplay={copy.display}
|
|
63
|
+
>
|
|
64
|
+
<ErrorSummary fields={props.compiled.fields} translate={translate} />
|
|
65
|
+
<RenderedForm
|
|
66
|
+
fields={props.compiled.fields}
|
|
67
|
+
translate={translate}
|
|
68
|
+
components={customControls}
|
|
69
|
+
layout={customLayout}
|
|
70
|
+
/>
|
|
71
|
+
</FormProvider>
|
|
72
|
+
</HostCopyContext.Provider>
|
|
73
|
+
</HostActionsContext.Provider>
|
|
74
|
+
</NativeThemeProvider>
|
|
75
|
+
);
|
|
76
|
+
}
|
|
77
|
+
```
|
|
78
|
+
|
|
79
|
+
## Subpath doors
|
|
80
|
+
|
|
81
|
+
- `@azx-pbc/axiom-native` exports the React Native components (`RenderedForm`, `LayoutTree`, `ErrorSummary`, `Control`, `NativeConfigurator`), runtime theming (`theme`, `createNativeTheme`, `NativeThemeContext`, `NativeThemeProvider`, `useNativeTheme`), override seams (`ControlComponentsContext`, `useControlComponents`, `LayoutComponentsContext`, `useLayoutComponents`), copy, host action ports, and native accessibility projection.
|
|
82
|
+
- `@azx-pbc/axiom-native/copy` exports the nine-locale copy catalogue (`HOST_COPY_LOCALES`, `hostCopy`, `HostCopyContext`, `useHostCopy`) without importing `react-native`.
|
|
83
|
+
- `@azx-pbc/axiom-native/projection` exports the pure accessibility and column-width projector (`toNativeProps`, `columnStyle`, `controlA11yProps`) without importing `react-native`.
|
|
84
|
+
|
|
85
|
+
## The seams
|
|
86
|
+
|
|
87
|
+
- **Runtime theming:** `theme` exposes the default light color, spacing, radius, touch-target (`44pt`), typography, and weight tokens. `createNativeTheme(overrides?, base?)` builds a complete merged `NativeTheme` without mutating `theme` or `base`, `NativeThemeProvider` composes partial overrides over any parent theme context, and `useNativeTheme()` reads the active tokens inside controls, containers, and host overrides.
|
|
88
|
+
- **Control overrides:** `ControlComponents` (supplied via `ControlComponentsContext.Provider` or the `components` prop on `RenderedForm` / `LayoutTree`) replaces individual control entries while keeping `<Control>`'s label, hint, withheld notice, and error banner intact. Custom controls receive `ControlComponentProps` (`node`, `field`, `translate`, `a11y`, `theme`, `value`, `setValue`, `trySetValue`, `error`, `required`, `disabled`, `readOnly`, `mayWrite`, `options`, `constraints`).
|
|
89
|
+
- **Layout container overrides:** `LayoutComponents` (supplied via `LayoutComponentsContext.Provider` or the `layout` prop on `RenderedForm` / `LayoutTree`) wraps or replaces any non-field container (`section`, `group`, `wizard`, `step`, `records`, `record`, `summary_card`, `heading`, `callout`, `divider`, `sop_block`, `error_summary`) with `LayoutSlotProps` (`node`, `translate`, `level`, `children`, `theme`).
|
|
90
|
+
- **Host copy:** `HostCopy` carries nine shipped languages (`en`, `es`, `pt`, `fr`, `ar`, `de`, `it`, `ru`, and `zh`), falling back to English for an unshipped locale. `HostCopy.display` formats booleans and lists for `FormProvider`'s `valueDisplay`.
|
|
91
|
+
- **Host actions:** `HostActions` supplies device capabilities the renderer does not own: `captureSignature`, `captureMedia`, `mediaSrc`, and `capturePosition`. Without a capability supplied, its control paints the recorded value read-only rather than offering an action that could only fail.
|
|
92
|
+
- **Confirmation journey:** `NativeConfigurator` and `useConfirmationStage` mount the inline confirmation journey when a document declares option availability or rule alternatives.
|
|
93
|
+
|
|
94
|
+
## What the host implements
|
|
95
|
+
|
|
96
|
+
The package renders forms and projects accessibility props; it does not store or transport data. The host owns artifact and dataset storage, draft persistence, submission queuing, authentication, file upload and media storage, signature ceremonies, and location permissions. See [`docs/integration/react-native.md`](https://github.com/AZX-PBC-OSS/axiom/blob/main/docs/integration/react-native.md) for the full React Native integration guide.
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import type { ValueDisplay, WriteProposal } from '@azx-pbc/axiom-react';
|
|
2
|
+
import type { CompiledField, CompiledSchema } from '@azx-pbc/axiom-runtime';
|
|
3
|
+
import type { ReactElement } from 'react';
|
|
4
|
+
/**
|
|
5
|
+
* Whether a document authorises an alternative, or a condition on one of its options.
|
|
6
|
+
*
|
|
7
|
+
* The journey is for the documents that declare one. This is the Web example's predicate, stated
|
|
8
|
+
* again here rather than imported: the shared module paints `<dialog>` and DOM containers, and a
|
|
9
|
+
* React Native program has no such intrinsics, so the two hosts share the protocol and not the
|
|
10
|
+
* module. Both sides are pinned by behaviour — this one by the case that mounts a document with
|
|
11
|
+
* nothing to confirm and expects no panel.
|
|
12
|
+
*/
|
|
13
|
+
export declare function declaresAlternatives(artifact: CompiledSchema): boolean;
|
|
14
|
+
/** The staged write a screen answers, held above the provider that stages it. */
|
|
15
|
+
export interface ConfirmationStage {
|
|
16
|
+
readonly proposal: WriteProposal | undefined;
|
|
17
|
+
readonly onWriteProposed: (proposal: WriteProposal) => void;
|
|
18
|
+
}
|
|
19
|
+
/**
|
|
20
|
+
* Holds the staged write the screen confirms.
|
|
21
|
+
*
|
|
22
|
+
* `FormProvider` takes the interceptor as a prop, so the state lives above it and the panel below
|
|
23
|
+
* it. The same ten lines are the Web example's `useConfirmationStage`; the two hosts share the
|
|
24
|
+
* protocol and not the module, because a device bundle carries no DOM renderer.
|
|
25
|
+
*/
|
|
26
|
+
export declare function useConfirmationStage(): ConfirmationStage;
|
|
27
|
+
/**
|
|
28
|
+
* The readiness summary and the change set waiting for an answer.
|
|
29
|
+
*
|
|
30
|
+
* It must be mounted inside the form's provider: it reads the session, stages the alternative the
|
|
31
|
+
* reader presses, and commits or declines the change set through the handle.
|
|
32
|
+
*/
|
|
33
|
+
export declare function NativeConfigurator({ stage, fields, locale, display, }: {
|
|
34
|
+
readonly stage: ConfirmationStage;
|
|
35
|
+
readonly fields: readonly CompiledField[];
|
|
36
|
+
readonly locale: string | undefined;
|
|
37
|
+
readonly display: ValueDisplay | undefined;
|
|
38
|
+
}): ReactElement;
|
|
39
|
+
//# sourceMappingURL=configurator.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"configurator.d.ts","sourceRoot":"","sources":["../src/configurator.tsx"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAY,YAAY,EAAE,aAAa,EAAE,MAAM,sBAAsB,CAAC;AAElF,OAAO,KAAK,EACV,aAAa,EACb,cAAc,EAKf,MAAM,wBAAwB,CAAC;AAChC,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,OAAO,CAAC;AAiG1C;;;;;;;;GAQG;AACH,wBAAgB,oBAAoB,CAAC,QAAQ,EAAE,cAAc,GAAG,OAAO,CAmBtE;AAED,iFAAiF;AACjF,MAAM,WAAW,iBAAiB;IAChC,QAAQ,CAAC,QAAQ,EAAE,aAAa,GAAG,SAAS,CAAC;IAC7C,QAAQ,CAAC,eAAe,EAAE,CAAC,QAAQ,EAAE,aAAa,KAAK,IAAI,CAAC;CAC7D;AAED;;;;;;GAMG;AACH,wBAAgB,oBAAoB,IAAI,iBAAiB,CAMxD;AA6DD;;;;;GAKG;AACH,wBAAgB,kBAAkB,CAAC,EACjC,KAAK,EACL,MAAM,EACN,MAAM,EACN,OAAO,GACR,EAAE;IACD,QAAQ,CAAC,KAAK,EAAE,iBAAiB,CAAC;IAClC,QAAQ,CAAC,MAAM,EAAE,SAAS,aAAa,EAAE,CAAC;IAC1C,QAAQ,CAAC,MAAM,EAAE,MAAM,GAAG,SAAS,CAAC;IACpC,QAAQ,CAAC,OAAO,EAAE,YAAY,GAAG,SAAS,CAAC;CAC5C,GAAG,YAAY,CAyKf"}
|
|
@@ -0,0 +1,420 @@
|
|
|
1
|
+
import { Fragment as _Fragment, jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { renderValueText, useForm, useFormState, useFormatMessage } from '@azx-pbc/axiom-react';
|
|
3
|
+
import { assertNever, canonicalizeRestricted, toEngineOperations } from '@azx-pbc/axiom-runtime';
|
|
4
|
+
import { useCallback, useMemo, useState } from 'react';
|
|
5
|
+
import { Pressable, StyleSheet, Text, View } from 'react-native';
|
|
6
|
+
import { useNativeTheme } from './theme.js';
|
|
7
|
+
/**
|
|
8
|
+
* The copy for the catalogues this repository ships.
|
|
9
|
+
*
|
|
10
|
+
* The three configurator documents declare `en` alone, so one entry answers them; the renderer's
|
|
11
|
+
* own sentences are the parity-gated ones in `copy.ts`, and these are the host's words for the
|
|
12
|
+
* confirmation surface only.
|
|
13
|
+
*/
|
|
14
|
+
const NATIVE_CONFIGURATOR_COPY = {
|
|
15
|
+
en: {
|
|
16
|
+
verdict: 'Readiness',
|
|
17
|
+
ready: 'Ready to submit',
|
|
18
|
+
blocked: 'Cannot be submitted',
|
|
19
|
+
undetermined: 'Waiting on a check this device cannot decide',
|
|
20
|
+
whyBlocked: 'Why this cannot be submitted yet',
|
|
21
|
+
nothingBlocks: 'Nothing blocks a submission.',
|
|
22
|
+
alternatives: 'Suggested alternatives',
|
|
23
|
+
confirmTitle: 'Confirm this change',
|
|
24
|
+
reason: 'Why this needs confirming',
|
|
25
|
+
effect: 'What committing this would change',
|
|
26
|
+
writes: 'Writes',
|
|
27
|
+
recompute: 'Recomputes',
|
|
28
|
+
adds: 'Adds',
|
|
29
|
+
clears: 'Clears',
|
|
30
|
+
pendingServer: 'the server decides this check',
|
|
31
|
+
pendingDevice: 'this device cannot decide this check yet',
|
|
32
|
+
keep: 'Keep this answer',
|
|
33
|
+
apply: 'Apply this change',
|
|
34
|
+
cancel: 'Cancel',
|
|
35
|
+
noChange: 'Nothing in the record changes.',
|
|
36
|
+
refused: () => 'The session refused this change, so nothing was saved. Reload the record, then try again.',
|
|
37
|
+
blocker: {
|
|
38
|
+
rule: 'A check fails',
|
|
39
|
+
required: 'A required answer is missing',
|
|
40
|
+
gate: 'A check stops this form',
|
|
41
|
+
cardinality: 'The row count is outside the allowed range',
|
|
42
|
+
scale: 'A reading is outside its scale',
|
|
43
|
+
media: 'A file does not meet its constraint',
|
|
44
|
+
rowCount: 'A table needs a different number of rows',
|
|
45
|
+
invalidOption: 'A chosen value is not offered',
|
|
46
|
+
unavailableOption: 'A chosen option is unavailable',
|
|
47
|
+
screen: 'A screen blocks the submission',
|
|
48
|
+
},
|
|
49
|
+
},
|
|
50
|
+
};
|
|
51
|
+
/** The copy for one locale, falling back to English for a catalogue that states none. */
|
|
52
|
+
function nativeConfiguratorCopy(locale) {
|
|
53
|
+
const entry = locale === undefined ? undefined : NATIVE_CONFIGURATOR_COPY[locale];
|
|
54
|
+
const fallback = NATIVE_CONFIGURATOR_COPY['en'];
|
|
55
|
+
if (fallback === undefined)
|
|
56
|
+
throw new Error('the configurator carries no English copy');
|
|
57
|
+
return entry ?? fallback;
|
|
58
|
+
}
|
|
59
|
+
/**
|
|
60
|
+
* Whether a document authorises an alternative, or a condition on one of its options.
|
|
61
|
+
*
|
|
62
|
+
* The journey is for the documents that declare one. This is the Web example's predicate, stated
|
|
63
|
+
* again here rather than imported: the shared module paints `<dialog>` and DOM containers, and a
|
|
64
|
+
* React Native program has no such intrinsics, so the two hosts share the protocol and not the
|
|
65
|
+
* module. Both sides are pinned by behaviour — this one by the case that mounts a document with
|
|
66
|
+
* nothing to confirm and expects no panel.
|
|
67
|
+
*/
|
|
68
|
+
export function declaresAlternatives(artifact) {
|
|
69
|
+
if ((artifact.rules ?? []).some((rule) => rule.suggests !== undefined))
|
|
70
|
+
return true;
|
|
71
|
+
let found = false;
|
|
72
|
+
const visit = (fields) => {
|
|
73
|
+
for (const field of fields) {
|
|
74
|
+
if ((field.options ?? []).some((option) => option.suggests !== undefined || option.availableWhen !== undefined)) {
|
|
75
|
+
found = true;
|
|
76
|
+
return;
|
|
77
|
+
}
|
|
78
|
+
if (field.fields !== undefined)
|
|
79
|
+
visit(field.fields);
|
|
80
|
+
if (found)
|
|
81
|
+
return;
|
|
82
|
+
}
|
|
83
|
+
};
|
|
84
|
+
visit(artifact.fields);
|
|
85
|
+
return found;
|
|
86
|
+
}
|
|
87
|
+
/**
|
|
88
|
+
* Holds the staged write the screen confirms.
|
|
89
|
+
*
|
|
90
|
+
* `FormProvider` takes the interceptor as a prop, so the state lives above it and the panel below
|
|
91
|
+
* it. The same ten lines are the Web example's `useConfirmationStage`; the two hosts share the
|
|
92
|
+
* protocol and not the module, because a device bundle carries no DOM renderer.
|
|
93
|
+
*/
|
|
94
|
+
export function useConfirmationStage() {
|
|
95
|
+
const [proposal, setProposal] = useState(undefined);
|
|
96
|
+
const onWriteProposed = useCallback((next) => {
|
|
97
|
+
setProposal(next);
|
|
98
|
+
}, []);
|
|
99
|
+
return { proposal, onWriteProposed };
|
|
100
|
+
}
|
|
101
|
+
/** The derived alternative as the latest staged write, preserving the delta's lazy read. */
|
|
102
|
+
function asStagedAlternative(target, from) {
|
|
103
|
+
return {
|
|
104
|
+
outcome: target.outcome,
|
|
105
|
+
operations: target.operations,
|
|
106
|
+
candidate: target.candidate,
|
|
107
|
+
addedBlockers: target.addedBlockers,
|
|
108
|
+
get delta() {
|
|
109
|
+
return target.delta;
|
|
110
|
+
},
|
|
111
|
+
binding: from.binding,
|
|
112
|
+
sequence: from.sequence,
|
|
113
|
+
};
|
|
114
|
+
}
|
|
115
|
+
/**
|
|
116
|
+
* One operation's identity when an alternative replaces it.
|
|
117
|
+
*
|
|
118
|
+
* Scalar writes and row removals name their exact binding. Row creation also names its payload,
|
|
119
|
+
* so composing an alternative never discards an unrelated row write; an exact duplicate is one
|
|
120
|
+
* write. Canonical values keep numeric and textual row keys distinct.
|
|
121
|
+
*/
|
|
122
|
+
function operationTarget(operation) {
|
|
123
|
+
switch (operation.kind) {
|
|
124
|
+
case 'value':
|
|
125
|
+
case 'null':
|
|
126
|
+
case 'remove':
|
|
127
|
+
return `binding\u0000${operation.ref.fieldId}\u0000${canonicalizeRestricted(operation.ref.rowKey ?? null)}`;
|
|
128
|
+
case 'append':
|
|
129
|
+
return `append\u0000${operation.fieldId}\u0000${canonicalizeRestricted(operation.value)}`;
|
|
130
|
+
case 'insert':
|
|
131
|
+
return `insert\u0000${operation.fieldId}\u0000${String(operation.index)}\u0000${canonicalizeRestricted(operation.value)}`;
|
|
132
|
+
case 'removeRow':
|
|
133
|
+
return `removeRow\u0000${operation.fieldId}\u0000${canonicalizeRestricted(operation.rowKey)}`;
|
|
134
|
+
case 'move':
|
|
135
|
+
return `move\u0000${operation.fieldId}\u0000${canonicalizeRestricted(operation.rowKey)}\u0000${String(operation.toIndex)}`;
|
|
136
|
+
case 'context':
|
|
137
|
+
return `context\u0000${operation.root}`;
|
|
138
|
+
case 'env':
|
|
139
|
+
case 'access':
|
|
140
|
+
return operation.kind;
|
|
141
|
+
default:
|
|
142
|
+
return assertNever(operation);
|
|
143
|
+
}
|
|
144
|
+
}
|
|
145
|
+
/** The label key of every declared field that states one, a record's members included. */
|
|
146
|
+
function labelsOf(fields) {
|
|
147
|
+
const labels = new Map();
|
|
148
|
+
const visit = (entries) => {
|
|
149
|
+
for (const field of entries) {
|
|
150
|
+
if (field.labelKey !== undefined)
|
|
151
|
+
labels.set(field.fieldId, field.labelKey);
|
|
152
|
+
if (field.fields !== undefined)
|
|
153
|
+
visit(field.fields);
|
|
154
|
+
}
|
|
155
|
+
};
|
|
156
|
+
visit(fields);
|
|
157
|
+
return labels;
|
|
158
|
+
}
|
|
159
|
+
/**
|
|
160
|
+
* The readiness summary and the change set waiting for an answer.
|
|
161
|
+
*
|
|
162
|
+
* It must be mounted inside the form's provider: it reads the session, stages the alternative the
|
|
163
|
+
* reader presses, and commits or declines the change set through the handle.
|
|
164
|
+
*/
|
|
165
|
+
export function NativeConfigurator({ stage, fields, locale, display, }) {
|
|
166
|
+
const form = useForm();
|
|
167
|
+
const summary = useFormState();
|
|
168
|
+
const translate = useFormatMessage(locale);
|
|
169
|
+
const activeTheme = useNativeTheme();
|
|
170
|
+
const styles = configuratorStylesFor(activeTheme);
|
|
171
|
+
const copy = nativeConfiguratorCopy(locale);
|
|
172
|
+
const labels = useMemo(() => labelsOf(fields), [fields]);
|
|
173
|
+
const label = useCallback((fieldId) => {
|
|
174
|
+
const key = labels.get(fieldId);
|
|
175
|
+
return key === undefined ? fieldId : translate(key);
|
|
176
|
+
}, [labels, translate]);
|
|
177
|
+
const [choice, setChoice] = useState(undefined);
|
|
178
|
+
const [notice, setNotice] = useState(undefined);
|
|
179
|
+
/**
|
|
180
|
+
* Derives one alternative and shows its own change set.
|
|
181
|
+
*
|
|
182
|
+
* The alternative repairs the change set that raised the confirmation, so it is applied over
|
|
183
|
+
* it; the bindings it writes itself are dropped from the staged change set, because an
|
|
184
|
+
* alternative that names one of them has decided it.
|
|
185
|
+
*/
|
|
186
|
+
const stageAlternative = useCallback((chosen, from) => {
|
|
187
|
+
const alternative = toEngineOperations(chosen.operations, 'user');
|
|
188
|
+
const decided = new Set(alternative.map(operationTarget));
|
|
189
|
+
const kept = (from?.operations ?? []).filter((operation) => !decided.has(operationTarget(operation)));
|
|
190
|
+
const proposed = form.propose([...kept, ...alternative]);
|
|
191
|
+
switch (proposed.outcome) {
|
|
192
|
+
case 'refused':
|
|
193
|
+
setNotice(copy.refused(proposed.code));
|
|
194
|
+
return;
|
|
195
|
+
case 'proposed':
|
|
196
|
+
setNotice(undefined);
|
|
197
|
+
setChoice({ proposal: proposed, from });
|
|
198
|
+
return;
|
|
199
|
+
default:
|
|
200
|
+
return assertNever(proposed);
|
|
201
|
+
}
|
|
202
|
+
}, [copy, form]);
|
|
203
|
+
const apply = useCallback((target) => {
|
|
204
|
+
// The staged sequence lets this apply retire the write the alternative replaces. A separate
|
|
205
|
+
// decline would publish once before the commit, making one accepted change two publishes.
|
|
206
|
+
const from = choice?.from;
|
|
207
|
+
const outcome = form.applyProposal(from === undefined ? target : asStagedAlternative(target, from));
|
|
208
|
+
setChoice(undefined);
|
|
209
|
+
setNotice(outcome.outcome === 'refused' ? copy.refused(outcome.code) : undefined);
|
|
210
|
+
}, [choice, copy, form]);
|
|
211
|
+
const decline = useCallback(() => {
|
|
212
|
+
if (choice?.from !== undefined)
|
|
213
|
+
form.discardProposal(choice.from);
|
|
214
|
+
else if (stage.proposal !== undefined)
|
|
215
|
+
form.discardProposal(stage.proposal);
|
|
216
|
+
setChoice(undefined);
|
|
217
|
+
setNotice(undefined);
|
|
218
|
+
}, [choice, form, stage]);
|
|
219
|
+
const staged = choice === undefined &&
|
|
220
|
+
stage.proposal !== undefined &&
|
|
221
|
+
summary.pendingProposal?.sequence === stage.proposal.sequence
|
|
222
|
+
? stage.proposal
|
|
223
|
+
: undefined;
|
|
224
|
+
return (_jsxs(View, { style: styles.panel, testID: "configurator", children: [_jsx(Text, { style: styles.heading, children: copy.verdict }), _jsx(Text, { testID: "configurator-verdict", style: styles.verdict, children: verdictWord(summary.verdict, copy) }), notice === undefined || choice !== undefined || staged !== undefined ? null : (_jsx(Text, { style: styles.danger, accessibilityRole: "alert", testID: "configurator-notice", children: notice })), summary.blockers.length === 0 ? (_jsx(Text, { style: styles.body, children: copy.nothingBlocks })) : (_jsxs(_Fragment, { children: [_jsx(Text, { style: styles.section, children: copy.whyBlocked }), summary.blockers.map((blocker, index) => (_jsxs(View, { testID: `blocker:${blocker.kind}`, children: [_jsx(Text, { style: styles.body, children: blockerSentence(blocker, copy, translate) }), staged === undefined
|
|
225
|
+
? alternativesOf(blocker).map((suggestion) => (_jsx(Pressable, { accessibilityRole: "button", accessibilityLabel: translate(suggestion.labelKey), testID: `alternative:${suggestion.labelKey}`, onPress: () => {
|
|
226
|
+
stageAlternative(suggestion, choice?.from);
|
|
227
|
+
}, style: styles.action, children: _jsx(Text, { style: styles.actionText, children: translate(suggestion.labelKey) }) }, suggestion.labelKey)))
|
|
228
|
+
: null] }, `${blocker.kind}:${String(index)}`)))] })), summary.hasDeferredChecks ? (_jsx(Text, { style: styles.pending, testID: "configurator-deferred", children: copy.pendingServer })) : null, choice === undefined && staged === undefined ? null : (_jsxs(View, { style: styles.panel, testID: "configurator-confirm", children: [_jsx(Text, { style: styles.section, children: copy.confirmTitle }), _jsx(PendingChange, { proposal: choice?.proposal ?? staged, from: choice === undefined ? staged : choice.from, copy: copy, label: label, display: display, translate: translate, styles: styles, onChoose: (suggestion, from) => {
|
|
229
|
+
stageAlternative(suggestion, from);
|
|
230
|
+
} }), notice === undefined ? null : (_jsx(Text, { style: styles.danger, accessibilityRole: "alert", children: notice })), _jsxs(View, { style: styles.actions, children: [_jsx(Pressable, { accessibilityRole: "button", accessibilityLabel: choice === undefined ? copy.keep : copy.apply, testID: "configurator-apply", onPress: () => {
|
|
231
|
+
const target = choice?.proposal ?? staged;
|
|
232
|
+
if (target !== undefined)
|
|
233
|
+
apply(target);
|
|
234
|
+
}, style: styles.action, children: _jsx(Text, { style: styles.actionText, children: choice === undefined ? copy.keep : copy.apply }) }), _jsx(Pressable, { accessibilityRole: "button", accessibilityLabel: copy.cancel, testID: "configurator-cancel", onPress: decline, style: styles.action, children: _jsx(Text, { style: styles.actionText, children: copy.cancel }) })] })] }))] }));
|
|
235
|
+
}
|
|
236
|
+
/** The alternatives one blocker offers, from the two arms an artifact may author. */
|
|
237
|
+
function alternativesOf(blocker) {
|
|
238
|
+
switch (blocker.kind) {
|
|
239
|
+
case 'rule':
|
|
240
|
+
case 'unavailableOption':
|
|
241
|
+
return blocker.suggestions ?? [];
|
|
242
|
+
case 'required':
|
|
243
|
+
case 'gate':
|
|
244
|
+
case 'cardinality':
|
|
245
|
+
case 'scale':
|
|
246
|
+
case 'media':
|
|
247
|
+
case 'rowCount':
|
|
248
|
+
case 'invalidOption':
|
|
249
|
+
case 'screen':
|
|
250
|
+
return [];
|
|
251
|
+
default:
|
|
252
|
+
return assertNever(blocker);
|
|
253
|
+
}
|
|
254
|
+
}
|
|
255
|
+
/** The change set the reader is confirming: what it writes and what it recomputes. */
|
|
256
|
+
function PendingChange({ proposal, from, copy, label, display, translate, styles, onChoose, }) {
|
|
257
|
+
if (proposal === undefined)
|
|
258
|
+
return null;
|
|
259
|
+
const trigger = from?.addedBlockers.find((blocker) => alternativesOf(blocker).length > 0);
|
|
260
|
+
const writes = proposal.operations.filter((operation) => isValueWrite(operation));
|
|
261
|
+
const delta = proposal.delta;
|
|
262
|
+
// A check that was already pending still belongs in this candidate's answer, even though the
|
|
263
|
+
// delta names only checks whose status moved.
|
|
264
|
+
const pending = proposal.candidate.report.rules.filter((result) => result.status === 'DEFERRED' || result.status === 'UNKNOWN');
|
|
265
|
+
return (_jsxs(_Fragment, { children: [trigger === undefined ? null : (_jsxs(_Fragment, { children: [_jsx(Text, { style: styles.section, children: copy.reason }), _jsx(Text, { style: styles.body, testID: "configurator-reason", children: blockerSentence(trigger, copy, translate) }), _jsx(Text, { style: styles.section, children: copy.alternatives }), alternativesOf(trigger).map((suggestion) => (_jsx(Pressable, { accessibilityRole: "button", accessibilityLabel: translate(suggestion.labelKey), testID: `alternative:${suggestion.labelKey}`, onPress: () => {
|
|
266
|
+
onChoose(suggestion, from);
|
|
267
|
+
}, style: styles.action, children: _jsx(Text, { style: styles.actionText, children: translate(suggestion.labelKey) }) }, suggestion.labelKey)))] })), _jsx(Text, { style: styles.section, children: copy.effect }), writes.length === 0 && delta.changedComputations.length === 0 ? (_jsx(Text, { style: styles.body, children: copy.noChange })) : null, writes.map((operation, index) => (_jsx(Text, { style: styles.body, children: `${copy.writes} ${label(writtenFieldOf(operation))}: ${writtenTextOf(operation, display)}` }, `${operationTarget(operation)}:${String(index)}`))), delta.changedComputations.map((change, index) => (_jsx(Text, { style: styles.body, testID: `computed:${change.fieldId}`, children: `${copy.recompute} ${label(change.fieldId)}: ${renderValueText(change.before, display)} → ${renderValueText(change.after, display)}` }, `${change.fieldId}:${String(index)}`))), delta.clearedBlockers.map((blocker, index) => (_jsx(Text, { style: styles.body, children: `${copy.clears} ${blockerSentence(blocker, copy, translate)}` }, `cleared:${String(index)}`))), delta.addedBlockers.map((blocker, index) => (_jsx(Text, { style: styles.body, children: `${copy.adds} ${blockerSentence(blocker, copy, translate)}` }, `added:${String(index)}`))), pending.map((check, index) => (_jsx(Text, { style: styles.pending, children: `${check.messageKey === undefined
|
|
268
|
+
? check.ruleId
|
|
269
|
+
: translate(check.messageKey, check.params)} — ${check.status === 'DEFERRED' ? copy.pendingServer : copy.pendingDevice}` }, `pending:${String(index)}`)))] }));
|
|
270
|
+
}
|
|
271
|
+
/** The answers a change set writes. */
|
|
272
|
+
function isValueWrite(operation) {
|
|
273
|
+
switch (operation.kind) {
|
|
274
|
+
case 'value':
|
|
275
|
+
case 'null':
|
|
276
|
+
case 'remove':
|
|
277
|
+
case 'append':
|
|
278
|
+
case 'insert':
|
|
279
|
+
case 'removeRow':
|
|
280
|
+
case 'move':
|
|
281
|
+
return true;
|
|
282
|
+
case 'context':
|
|
283
|
+
case 'env':
|
|
284
|
+
case 'access':
|
|
285
|
+
return false;
|
|
286
|
+
default:
|
|
287
|
+
return assertNever(operation);
|
|
288
|
+
}
|
|
289
|
+
}
|
|
290
|
+
/** The field one written operation names. */
|
|
291
|
+
function writtenFieldOf(operation) {
|
|
292
|
+
switch (operation.kind) {
|
|
293
|
+
case 'value':
|
|
294
|
+
case 'null':
|
|
295
|
+
case 'remove':
|
|
296
|
+
return operation.ref.fieldId;
|
|
297
|
+
case 'append':
|
|
298
|
+
case 'insert':
|
|
299
|
+
case 'removeRow':
|
|
300
|
+
case 'move':
|
|
301
|
+
return operation.fieldId;
|
|
302
|
+
case 'context':
|
|
303
|
+
case 'env':
|
|
304
|
+
case 'access':
|
|
305
|
+
throw new Error(`${operation.kind} names no field`);
|
|
306
|
+
default:
|
|
307
|
+
return assertNever(operation);
|
|
308
|
+
}
|
|
309
|
+
}
|
|
310
|
+
/** What one written operation states as its effect. */
|
|
311
|
+
function writtenTextOf(operation, display) {
|
|
312
|
+
switch (operation.kind) {
|
|
313
|
+
case 'value':
|
|
314
|
+
return renderValueText(operation.value, display);
|
|
315
|
+
case 'null':
|
|
316
|
+
case 'remove':
|
|
317
|
+
return '—';
|
|
318
|
+
case 'append':
|
|
319
|
+
case 'insert':
|
|
320
|
+
return '+1';
|
|
321
|
+
case 'removeRow':
|
|
322
|
+
return '-1';
|
|
323
|
+
case 'move':
|
|
324
|
+
return '↕';
|
|
325
|
+
case 'context':
|
|
326
|
+
case 'env':
|
|
327
|
+
case 'access':
|
|
328
|
+
return '';
|
|
329
|
+
default:
|
|
330
|
+
return assertNever(operation);
|
|
331
|
+
}
|
|
332
|
+
}
|
|
333
|
+
/** The one word a verdict reads as. */
|
|
334
|
+
function verdictWord(verdict, copy) {
|
|
335
|
+
switch (verdict) {
|
|
336
|
+
case 'SUBMIT':
|
|
337
|
+
return copy.ready;
|
|
338
|
+
case 'BLOCKED':
|
|
339
|
+
return copy.blocked;
|
|
340
|
+
case 'UNDETERMINED':
|
|
341
|
+
return copy.undetermined;
|
|
342
|
+
default:
|
|
343
|
+
return assertNever(verdict);
|
|
344
|
+
}
|
|
345
|
+
}
|
|
346
|
+
/** The sentence a blocker reads as. */
|
|
347
|
+
function blockerSentence(blocker, copy, translate) {
|
|
348
|
+
switch (blocker.kind) {
|
|
349
|
+
case 'rule':
|
|
350
|
+
case 'required':
|
|
351
|
+
case 'gate':
|
|
352
|
+
return blocker.messageKey === undefined
|
|
353
|
+
? copy.blocker[blocker.kind]
|
|
354
|
+
: translate(blocker.messageKey, blocker.params);
|
|
355
|
+
case 'unavailableOption':
|
|
356
|
+
return blocker.messageKey === undefined
|
|
357
|
+
? copy.blocker.unavailableOption
|
|
358
|
+
: translate(blocker.messageKey, blocker.params);
|
|
359
|
+
case 'screen':
|
|
360
|
+
return blocker.messageKey === undefined ? copy.blocker.screen : translate(blocker.messageKey);
|
|
361
|
+
case 'scale':
|
|
362
|
+
case 'cardinality':
|
|
363
|
+
case 'rowCount':
|
|
364
|
+
case 'media':
|
|
365
|
+
case 'invalidOption':
|
|
366
|
+
return copy.blocker[blocker.kind];
|
|
367
|
+
default:
|
|
368
|
+
return assertNever(blocker);
|
|
369
|
+
}
|
|
370
|
+
}
|
|
371
|
+
function createConfiguratorStyles(activeTheme) {
|
|
372
|
+
return StyleSheet.create({
|
|
373
|
+
panel: {
|
|
374
|
+
marginTop: activeTheme.space.section,
|
|
375
|
+
padding: activeTheme.space.medium,
|
|
376
|
+
borderWidth: 1,
|
|
377
|
+
borderColor: activeTheme.color.border,
|
|
378
|
+
borderRadius: activeTheme.radius.panel,
|
|
379
|
+
backgroundColor: activeTheme.color.surface,
|
|
380
|
+
gap: activeTheme.space.tight,
|
|
381
|
+
},
|
|
382
|
+
heading: {
|
|
383
|
+
fontSize: activeTheme.text.section,
|
|
384
|
+
fontWeight: activeTheme.weight.semibold,
|
|
385
|
+
color: activeTheme.color.ink,
|
|
386
|
+
},
|
|
387
|
+
section: {
|
|
388
|
+
marginTop: activeTheme.space.small,
|
|
389
|
+
fontSize: activeTheme.text.label,
|
|
390
|
+
fontWeight: activeTheme.weight.semibold,
|
|
391
|
+
color: activeTheme.color.ink,
|
|
392
|
+
},
|
|
393
|
+
verdict: { fontSize: activeTheme.text.body, color: activeTheme.color.ink },
|
|
394
|
+
body: { fontSize: activeTheme.text.body, color: activeTheme.color.ink },
|
|
395
|
+
pending: { fontSize: activeTheme.text.caption, color: activeTheme.color.muted },
|
|
396
|
+
danger: { fontSize: activeTheme.text.body, color: activeTheme.color.danger },
|
|
397
|
+
actions: { flexDirection: 'row', flexWrap: 'wrap', gap: activeTheme.space.small },
|
|
398
|
+
action: {
|
|
399
|
+
minHeight: activeTheme.size.target,
|
|
400
|
+
minWidth: activeTheme.size.target,
|
|
401
|
+
paddingHorizontal: activeTheme.space.medium,
|
|
402
|
+
justifyContent: 'center',
|
|
403
|
+
borderWidth: 1,
|
|
404
|
+
borderColor: activeTheme.color.accent,
|
|
405
|
+
borderRadius: activeTheme.radius.chip,
|
|
406
|
+
marginTop: activeTheme.space.tight,
|
|
407
|
+
},
|
|
408
|
+
actionText: { fontSize: activeTheme.text.body, color: activeTheme.color.accent },
|
|
409
|
+
});
|
|
410
|
+
}
|
|
411
|
+
const CONFIGURATOR_STYLES = new WeakMap();
|
|
412
|
+
function configuratorStylesFor(activeTheme) {
|
|
413
|
+
const cached = CONFIGURATOR_STYLES.get(activeTheme);
|
|
414
|
+
if (cached !== undefined)
|
|
415
|
+
return cached;
|
|
416
|
+
const created = createConfiguratorStyles(activeTheme);
|
|
417
|
+
CONFIGURATOR_STYLES.set(activeTheme, created);
|
|
418
|
+
return created;
|
|
419
|
+
}
|
|
420
|
+
//# sourceMappingURL=configurator.js.map
|