@blackbelt-technology/pi-dashboard-forms-bpmn 0.7.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/.pi/skills/bpmn-package-explorer/SKILL.md +120 -0
- package/.pi/skills/bpmn-package-explorer/assets/LICENSE.bpmn-io.txt +23 -0
- package/.pi/skills/bpmn-package-explorer/assets/VENDORED.md +90 -0
- package/.pi/skills/bpmn-package-explorer/assets/bpmn-js/bpmn-font/css/bpmn-codes.css +108 -0
- package/.pi/skills/bpmn-package-explorer/assets/bpmn-js/bpmn-font/css/bpmn-embedded.css +166 -0
- package/.pi/skills/bpmn-package-explorer/assets/bpmn-js/bpmn-font/css/bpmn.css +164 -0
- package/.pi/skills/bpmn-package-explorer/assets/bpmn-js/bpmn-font/font/bpmn.eot +0 -0
- package/.pi/skills/bpmn-package-explorer/assets/bpmn-js/bpmn-font/font/bpmn.svg +224 -0
- package/.pi/skills/bpmn-package-explorer/assets/bpmn-js/bpmn-font/font/bpmn.ttf +0 -0
- package/.pi/skills/bpmn-package-explorer/assets/bpmn-js/bpmn-font/font/bpmn.woff +0 -0
- package/.pi/skills/bpmn-package-explorer/assets/bpmn-js/bpmn-font/font/bpmn.woff2 +0 -0
- package/.pi/skills/bpmn-package-explorer/assets/bpmn-js/bpmn-navigated-viewer.production.min.js +22 -0
- package/.pi/skills/bpmn-package-explorer/assets/bpmn-js/bpmn.css +145 -0
- package/.pi/skills/bpmn-package-explorer/assets/bpmn-js/diagram-js.css +1249 -0
- package/.pi/skills/bpmn-package-explorer/assets/dmn-js/diagram-js.css +1133 -0
- package/.pi/skills/bpmn-package-explorer/assets/dmn-js/dmn-font/css/dmn-codes.css +41 -0
- package/.pi/skills/bpmn-package-explorer/assets/dmn-js/dmn-font/css/dmn-embedded.css +98 -0
- package/.pi/skills/bpmn-package-explorer/assets/dmn-js/dmn-font/css/dmn.css +97 -0
- package/.pi/skills/bpmn-package-explorer/assets/dmn-js/dmn-font/font/dmn.eot +0 -0
- package/.pi/skills/bpmn-package-explorer/assets/dmn-js/dmn-font/font/dmn.svg +90 -0
- package/.pi/skills/bpmn-package-explorer/assets/dmn-js/dmn-font/font/dmn.ttf +0 -0
- package/.pi/skills/bpmn-package-explorer/assets/dmn-js/dmn-font/font/dmn.woff +0 -0
- package/.pi/skills/bpmn-package-explorer/assets/dmn-js/dmn-font/font/dmn.woff2 +0 -0
- package/.pi/skills/bpmn-package-explorer/assets/dmn-js/dmn-js-decision-table.css +580 -0
- package/.pi/skills/bpmn-package-explorer/assets/dmn-js/dmn-js-drd.css +108 -0
- package/.pi/skills/bpmn-package-explorer/assets/dmn-js/dmn-js-literal-expression.css +165 -0
- package/.pi/skills/bpmn-package-explorer/assets/dmn-js/dmn-js-shared.css +221 -0
- package/.pi/skills/bpmn-package-explorer/assets/dmn-js/dmn-viewer.production.min.js +16 -0
- package/.pi/skills/bpmn-package-explorer/assets/lib/bpmn-pipeline.mjs +6981 -0
- package/.pi/skills/bpmn-package-explorer/assets/lib/yaml.mjs +7372 -0
- package/.pi/skills/bpmn-package-explorer/fixtures/geometry/g1-identical-bounds.bpmn +17 -0
- package/.pi/skills/bpmn-package-explorer/fixtures/geometry/g2-zero-size.bpmn +17 -0
- package/.pi/skills/bpmn-package-explorer/fixtures/geometry/g3-child-outside.bpmn +16 -0
- package/.pi/skills/bpmn-package-explorer/fixtures/geometry/g4-negative-coord.bpmn +17 -0
- package/.pi/skills/bpmn-package-explorer/fixtures/geometry/g5-overlap.bpmn +17 -0
- package/.pi/skills/bpmn-package-explorer/fixtures/measured/1-linear.bpmn +12 -0
- package/.pi/skills/bpmn-package-explorer/fixtures/measured/2-gateway.bpmn +19 -0
- package/.pi/skills/bpmn-package-explorer/fixtures/measured/3-boundary.bpmn +13 -0
- package/.pi/skills/bpmn-package-explorer/fixtures/measured/4-subprocess.bpmn +17 -0
- package/.pi/skills/bpmn-package-explorer/fixtures/measured/5-pools.bpmn +21 -0
- package/.pi/skills/bpmn-package-explorer/fixtures/measured/6-lanes-only.bpmn +16 -0
- package/.pi/skills/bpmn-package-explorer/fixtures/measured/7-loop.bpmn +13 -0
- package/.pi/skills/bpmn-package-explorer/fixtures/measured/8-long-chain.bpmn +32 -0
- package/.pi/skills/bpmn-package-explorer/fixtures/nesting/expanded-subprocess-ok.bpmn +25 -0
- package/.pi/skills/bpmn-package-explorer/fixtures/provisional/call-activity.bpmn +10 -0
- package/.pi/skills/bpmn-package-explorer/fixtures/provisional/intermediate-catch.bpmn +10 -0
- package/.pi/skills/bpmn-package-explorer/fixtures/provisional/intermediate-throw.bpmn +10 -0
- package/.pi/skills/bpmn-package-explorer/fixtures/provisional/manual-task.bpmn +10 -0
- package/.pi/skills/bpmn-package-explorer/fixtures/provisional/multi-boundary.bpmn +16 -0
- package/.pi/skills/bpmn-package-explorer/fixtures/provisional/parallel-gateway.bpmn +10 -0
- package/.pi/skills/bpmn-package-explorer/fixtures/provisional/receive-task.bpmn +10 -0
- package/.pi/skills/bpmn-package-explorer/fixtures/provisional/rule-task.bpmn +10 -0
- package/.pi/skills/bpmn-package-explorer/fixtures/provisional/script-task.bpmn +10 -0
- package/.pi/skills/bpmn-package-explorer/fixtures/provisional/send-task.bpmn +10 -0
- package/.pi/skills/bpmn-package-explorer/references/authoring-envelope.md +52 -0
- package/.pi/skills/bpmn-package-explorer/references/identifiers.md +102 -0
- package/.pi/skills/bpmn-package-explorer/references/layout-envelope.md +105 -0
- package/.pi/skills/bpmn-package-explorer/references/licensing.md +48 -0
- package/.pi/skills/bpmn-package-explorer/references/package-manifest.md +104 -0
- package/.pi/skills/bpmn-package-explorer/scripts/build-fixtures.mjs +299 -0
- package/.pi/skills/bpmn-package-explorer/scripts/demo.mjs +128 -0
- package/.pi/skills/bpmn-package-explorer/scripts/diagnostics.mjs +37 -0
- package/.pi/skills/bpmn-package-explorer/scripts/envelope.mjs +160 -0
- package/.pi/skills/bpmn-package-explorer/scripts/fixtures.mjs +140 -0
- package/.pi/skills/bpmn-package-explorer/scripts/generate-cli.mjs +31 -0
- package/.pi/skills/bpmn-package-explorer/scripts/generate.mjs +103 -0
- package/.pi/skills/bpmn-package-explorer/scripts/guard.mjs +335 -0
- package/.pi/skills/bpmn-package-explorer/scripts/harness.mjs +12 -0
- package/.pi/skills/bpmn-package-explorer/scripts/identifiers.mjs +117 -0
- package/.pi/skills/bpmn-package-explorer/scripts/ingest.mjs +95 -0
- package/.pi/skills/bpmn-package-explorer/scripts/manifest.mjs +374 -0
- package/.pi/skills/bpmn-package-explorer/scripts/pipeline.mjs +49 -0
- package/.pi/skills/bpmn-package-explorer/scripts/render.mjs +130 -0
- package/.pi/skills/bpmn-package-explorer/scripts/runguard.mjs +38 -0
- package/.pi/skills/bpmn-package-explorer/scripts/selftest-e2e.mjs +87 -0
- package/.pi/skills/bpmn-package-explorer/scripts/selftest-guard.mjs +99 -0
- package/.pi/skills/bpmn-package-explorer/scripts/selftest-manifest.mjs +170 -0
- package/.pi/skills/bpmn-package-explorer/scripts/selftest-more.mjs +87 -0
- package/.pi/skills/bpmn-package-explorer/scripts/selftest-workflow.mjs +73 -0
- package/.pi/skills/bpmn-package-explorer/scripts/selftest.mjs +57 -0
- package/.pi/skills/bpmn-package-explorer/scripts/vendor.mjs +141 -0
- package/.pi/skills/bpmn-package-explorer/scripts/view-cli.mjs +19 -0
- package/.pi/skills/bpmn-package-explorer/templates/shell.html +141 -0
- package/.pi/skills/bpmn-package-explorer/templates/viewer.js +301 -0
- package/.pi/skills/canvas-webapp/SKILL.md +104 -0
- package/.pi/skills/openforms-mui/SKILL.md +187 -0
- package/.pi/skills/openforms-mui/references/a11y.md +68 -0
- package/.pi/skills/openforms-mui/references/field-widget-map.md +64 -0
- package/.pi/skills/openforms-mui/references/hu-locale.md +45 -0
- package/.pi/skills/openforms-mui/references/logic.md +94 -0
- package/.pi/skills/openforms-mui/references/schema.md +94 -0
- package/.pi/skills/openforms-mui/references/theme-bridge.md +65 -0
- package/.pi/skills/openforms-mui/tools/canvas-serve.mjs +51 -0
- package/.pi/skills/openforms-mui/tools/demo-schema.json +80 -0
- package/.pi/skills/openforms-mui/tools/mockups/tokens.css +27 -0
- package/.pi/skills/openforms-mui/tools/mockups/ui-contract.tokens.json +16 -0
- package/.pi/skills/openforms-mui/tools/package-lock.json +5919 -0
- package/.pi/skills/openforms-mui/tools/package.json +61 -0
- package/.pi/skills/openforms-mui/tools/preview/RenderPanel.tsx +105 -0
- package/.pi/skills/openforms-mui/tools/preview/canvas-app.tsx +66 -0
- package/.pi/skills/openforms-mui/tools/preview/canvas-index.html +16 -0
- package/.pi/skills/openforms-mui/tools/preview/cli.ts +99 -0
- package/.pi/skills/openforms-mui/tools/preview/index.html +17 -0
- package/.pi/skills/openforms-mui/tools/preview/main.tsx +228 -0
- package/.pi/skills/openforms-mui/tools/preview/vite-plugin.ts +41 -0
- package/.pi/skills/openforms-mui/tools/scripts/assert-peer-deps.mjs +39 -0
- package/.pi/skills/openforms-mui/tools/src/OpenFormsMui.tsx +391 -0
- package/.pi/skills/openforms-mui/tools/src/css.d.ts +2 -0
- package/.pi/skills/openforms-mui/tools/src/fields/ErrorSummary.tsx +72 -0
- package/.pi/skills/openforms-mui/tools/src/fields/FieldRenderer.tsx +328 -0
- package/.pi/skills/openforms-mui/tools/src/fields/FieldShell.tsx +50 -0
- package/.pi/skills/openforms-mui/tools/src/fields/FileField.tsx +91 -0
- package/.pi/skills/openforms-mui/tools/src/fields/MatrixField.tsx +146 -0
- package/.pi/skills/openforms-mui/tools/src/fields/RepeaterField.tsx +82 -0
- package/.pi/skills/openforms-mui/tools/src/fields/SignatureCanvas.tsx +121 -0
- package/.pi/skills/openforms-mui/tools/src/fields/context.tsx +34 -0
- package/.pi/skills/openforms-mui/tools/src/fields/index.ts +7 -0
- package/.pi/skills/openforms-mui/tools/src/fields/label.ts +42 -0
- package/.pi/skills/openforms-mui/tools/src/fonts.ts +8 -0
- package/.pi/skills/openforms-mui/tools/src/i18n/dictionary.ts +58 -0
- package/.pi/skills/openforms-mui/tools/src/i18n/hu.ts +56 -0
- package/.pi/skills/openforms-mui/tools/src/i18n/index.ts +43 -0
- package/.pi/skills/openforms-mui/tools/src/index.ts +27 -0
- package/.pi/skills/openforms-mui/tools/src/logic/cnf.ts +206 -0
- package/.pi/skills/openforms-mui/tools/src/logic/formula.ts +285 -0
- package/.pi/skills/openforms-mui/tools/src/logic/index.ts +4 -0
- package/.pi/skills/openforms-mui/tools/src/logic/operators.ts +43 -0
- package/.pi/skills/openforms-mui/tools/src/logic/state.ts +183 -0
- package/.pi/skills/openforms-mui/tools/src/payload.ts +83 -0
- package/.pi/skills/openforms-mui/tools/src/provenance.ts +21 -0
- package/.pi/skills/openforms-mui/tools/src/schema/diagnose.ts +256 -0
- package/.pi/skills/openforms-mui/tools/src/schema/index.ts +4 -0
- package/.pi/skills/openforms-mui/tools/src/schema/normalize.ts +163 -0
- package/.pi/skills/openforms-mui/tools/src/schema/types.ts +299 -0
- package/.pi/skills/openforms-mui/tools/src/schema/walk.ts +68 -0
- package/.pi/skills/openforms-mui/tools/src/theme/from-tokens.ts +102 -0
- package/.pi/skills/openforms-mui/tools/src/theme/index.ts +1 -0
- package/.pi/skills/openforms-mui/tools/src/validation/constrain.ts +83 -0
- package/.pi/skills/openforms-mui/tools/src/validation/diagnostics.ts +62 -0
- package/.pi/skills/openforms-mui/tools/src/validation/empty.ts +53 -0
- package/.pi/skills/openforms-mui/tools/src/validation/index.ts +5 -0
- package/.pi/skills/openforms-mui/tools/src/validation/resolver.ts +14 -0
- package/.pi/skills/openforms-mui/tools/src/validation/zod-from-schema.ts +169 -0
- package/.pi/skills/openforms-mui/tools/tests/a11y.test.tsx +82 -0
- package/.pi/skills/openforms-mui/tools/tests/cli.test.ts +74 -0
- package/.pi/skills/openforms-mui/tools/tests/component.test.tsx +295 -0
- package/.pi/skills/openforms-mui/tools/tests/diagnose.test.ts +163 -0
- package/.pi/skills/openforms-mui/tools/tests/fixtures/all-field-types.json +45 -0
- package/.pi/skills/openforms-mui/tools/tests/logic.test.ts +175 -0
- package/.pi/skills/openforms-mui/tools/tests/normalize.test.ts +105 -0
- package/.pi/skills/openforms-mui/tools/tests/reference-semantics.test.ts +131 -0
- package/.pi/skills/openforms-mui/tools/tests/responsive.test.tsx +158 -0
- package/.pi/skills/openforms-mui/tools/tests/setup.ts +16 -0
- package/.pi/skills/openforms-mui/tools/tests/singleton.test.tsx +31 -0
- package/.pi/skills/openforms-mui/tools/tests/theme.test.ts +65 -0
- package/.pi/skills/openforms-mui/tools/tests/toolchain.test.ts +33 -0
- package/.pi/skills/openforms-mui/tools/tests/validation.test.ts +222 -0
- package/.pi/skills/openforms-mui/tools/tsconfig.json +21 -0
- package/.pi/skills/openforms-mui/tools/vite.canvas.config.ts +21 -0
- package/.pi/skills/openforms-mui/tools/vitest.config.ts +17 -0
- package/NOTICE +46 -0
- package/README.md +62 -0
- package/package.json +46 -0
- package/scripts/ensure-openforms-deps.mjs +38 -0
|
@@ -0,0 +1,391 @@
|
|
|
1
|
+
import type { JSX } from "react";
|
|
2
|
+
import { useCallback, useEffect, useMemo, useRef, useState } from "react";
|
|
3
|
+
import "./fonts.js"; // bundle Roboto so typography never falls back to a system face
|
|
4
|
+
import Box from "@mui/material/Box";
|
|
5
|
+
import Button from "@mui/material/Button";
|
|
6
|
+
import Grid from "@mui/material/Grid";
|
|
7
|
+
import Stack from "@mui/material/Stack";
|
|
8
|
+
import Step from "@mui/material/Step";
|
|
9
|
+
import StepLabel from "@mui/material/StepLabel";
|
|
10
|
+
import Stepper from "@mui/material/Stepper";
|
|
11
|
+
import Typography from "@mui/material/Typography";
|
|
12
|
+
import useMediaQuery from "@mui/material/useMediaQuery";
|
|
13
|
+
import { ThemeProvider, useTheme, type Theme } from "@mui/material/styles";
|
|
14
|
+
import { LocalizationProvider } from "@mui/x-date-pickers/LocalizationProvider";
|
|
15
|
+
import { AdapterDayjs } from "@mui/x-date-pickers/AdapterDayjs";
|
|
16
|
+
import { FormProvider, useForm } from "react-hook-form";
|
|
17
|
+
import type {
|
|
18
|
+
Diagnostic,
|
|
19
|
+
FormAnswers,
|
|
20
|
+
FormSchemaJSON,
|
|
21
|
+
TranslationsDictionary,
|
|
22
|
+
} from "./schema/types.js";
|
|
23
|
+
import { normalizeSchema } from "./schema/normalize.js";
|
|
24
|
+
import { diagnose } from "./schema/diagnose.js";
|
|
25
|
+
import { walkFields } from "./schema/walk.js";
|
|
26
|
+
import { resolveFormState } from "./logic/state.js";
|
|
27
|
+
import { deriveZodSchema, FORM_LEVEL_PATH } from "./validation/zod-from-schema.js";
|
|
28
|
+
import { collectFieldDiagnostics } from "./validation/diagnostics.js";
|
|
29
|
+
import { emptyValueFor } from "./validation/empty.js";
|
|
30
|
+
import { composePayload, type SubmissionMeta } from "./payload.js";
|
|
31
|
+
import { createTranslator } from "./i18n/index.js";
|
|
32
|
+
import { OpenFormsProvider, type SignatureComponentProps } from "./fields/context.js";
|
|
33
|
+
import { FieldRenderer } from "./fields/FieldRenderer.js";
|
|
34
|
+
import { ErrorSummary, type ErrorSummaryEntry } from "./fields/ErrorSummary.js";
|
|
35
|
+
import { decideMarkerMode } from "./fields/label.js";
|
|
36
|
+
|
|
37
|
+
export interface OpenFormsMuiProps<C = unknown> {
|
|
38
|
+
schema: FormSchemaJSON | Partial<FormSchemaJSON>;
|
|
39
|
+
answers?: FormAnswers;
|
|
40
|
+
readOnly?: boolean;
|
|
41
|
+
locale?: string;
|
|
42
|
+
translations?: TranslationsDictionary;
|
|
43
|
+
/** Additive: supplementary process data segregated from field answers (D13). */
|
|
44
|
+
submissionContext?: C;
|
|
45
|
+
onSubmit?: (answers: FormAnswers, meta: SubmissionMeta<C>) => void;
|
|
46
|
+
/** Receives COMPLETE form state incl. retained hidden values — not the payload. */
|
|
47
|
+
onFieldChange?: (answers: FormAnswers) => void;
|
|
48
|
+
SignatureComponent?: (props: SignatureComponentProps) => JSX.Element;
|
|
49
|
+
/** Optional theme override; when omitted the host ThemeProvider is inherited. */
|
|
50
|
+
theme?: Theme;
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
function buildInitialValues(schema: FormSchemaJSON, answers?: FormAnswers): FormAnswers {
|
|
54
|
+
const out: FormAnswers = {};
|
|
55
|
+
walkFields(schema, ({ field, repeaterDepth }) => {
|
|
56
|
+
if (repeaterDepth !== 0) return;
|
|
57
|
+
if (field.type === "header" || field.type === "paragraph") return;
|
|
58
|
+
const provided = answers?.[field.key];
|
|
59
|
+
out[field.key] = provided !== undefined ? provided : emptyValueFor(field.type);
|
|
60
|
+
});
|
|
61
|
+
return out;
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
function pageOfFieldMap(schema: FormSchemaJSON): Map<string, number> {
|
|
65
|
+
const map = new Map<string, number>();
|
|
66
|
+
schema.pages.forEach((page, pi) => {
|
|
67
|
+
page.sections.forEach((section) => {
|
|
68
|
+
section.rows.forEach((row) => {
|
|
69
|
+
row.columns.forEach((col) => {
|
|
70
|
+
col.fields.forEach((field) => {
|
|
71
|
+
if (field.type !== "header" && field.type !== "paragraph") map.set(field.key, pi);
|
|
72
|
+
});
|
|
73
|
+
});
|
|
74
|
+
});
|
|
75
|
+
});
|
|
76
|
+
});
|
|
77
|
+
return map;
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
export function OpenFormsMui<C = unknown>(props: OpenFormsMuiProps<C>): JSX.Element {
|
|
81
|
+
const {
|
|
82
|
+
schema: rawSchema,
|
|
83
|
+
answers,
|
|
84
|
+
readOnly = false,
|
|
85
|
+
locale = "en",
|
|
86
|
+
translations,
|
|
87
|
+
submissionContext,
|
|
88
|
+
onSubmit,
|
|
89
|
+
onFieldChange,
|
|
90
|
+
SignatureComponent,
|
|
91
|
+
theme,
|
|
92
|
+
} = props;
|
|
93
|
+
|
|
94
|
+
const { schema, normDiagnostics } = useMemo(() => {
|
|
95
|
+
const { schema: norm, diagnostics } = normalizeSchema(rawSchema);
|
|
96
|
+
if (translations) norm.translations = { ...norm.translations, ...translations };
|
|
97
|
+
return { schema: norm, normDiagnostics: diagnostics };
|
|
98
|
+
}, [rawSchema, translations]);
|
|
99
|
+
|
|
100
|
+
const staticDiagnostics = useMemo(() => diagnose(schema), [schema]);
|
|
101
|
+
const pageOfField = useMemo(() => pageOfFieldMap(schema), [schema]);
|
|
102
|
+
const labelByKey = useMemo(() => {
|
|
103
|
+
const m = new Map<string, string>();
|
|
104
|
+
walkFields(schema, ({ field, repeaterDepth }) => {
|
|
105
|
+
if (repeaterDepth === 0 && field.type !== "header" && field.type !== "paragraph") {
|
|
106
|
+
m.set(field.key, field.label ?? field.key);
|
|
107
|
+
}
|
|
108
|
+
});
|
|
109
|
+
return m;
|
|
110
|
+
}, [schema]);
|
|
111
|
+
|
|
112
|
+
const t = useMemo(() => createTranslator(schema.translations, locale), [schema.translations, locale]);
|
|
113
|
+
|
|
114
|
+
const form = useForm<FormAnswers>({
|
|
115
|
+
defaultValues: useMemo(() => buildInitialValues(schema, answers), [schema, answers]),
|
|
116
|
+
mode: "onSubmit",
|
|
117
|
+
shouldUnregister: false, // retain hidden field values (task 7.5)
|
|
118
|
+
});
|
|
119
|
+
const { watch, getValues, setValue, setError, clearErrors } = form;
|
|
120
|
+
|
|
121
|
+
const watched = watch();
|
|
122
|
+
const logicState = useMemo(() => resolveFormState(schema, watched), [schema, watched]);
|
|
123
|
+
const markerMode = useMemo(() => decideMarkerMode(logicState), [logicState]);
|
|
124
|
+
|
|
125
|
+
// Write calculated values back into form state so controls and payload agree.
|
|
126
|
+
const calcSignature = useMemo(() => {
|
|
127
|
+
const parts: string[] = [];
|
|
128
|
+
for (const [key, fs] of logicState.fields) {
|
|
129
|
+
if (fs.calculated) parts.push(`${key}=${String(logicState.effectiveAnswers[key])}`);
|
|
130
|
+
}
|
|
131
|
+
return parts.join("|");
|
|
132
|
+
}, [logicState]);
|
|
133
|
+
useEffect(() => {
|
|
134
|
+
for (const [key, fs] of logicState.fields) {
|
|
135
|
+
if (fs.calculated && getValues(key) !== logicState.effectiveAnswers[key]) {
|
|
136
|
+
setValue(key, logicState.effectiveAnswers[key] as never, { shouldDirty: false, shouldValidate: false });
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
140
|
+
}, [calcSignature]);
|
|
141
|
+
|
|
142
|
+
// onFieldChange receives the COMPLETE state (retained hidden values included).
|
|
143
|
+
const firstChange = useRef(true);
|
|
144
|
+
useEffect(() => {
|
|
145
|
+
if (firstChange.current) {
|
|
146
|
+
firstChange.current = false;
|
|
147
|
+
return;
|
|
148
|
+
}
|
|
149
|
+
onFieldChange?.(logicState.effectiveAnswers);
|
|
150
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
151
|
+
}, [JSON.stringify(logicState.effectiveAnswers)]);
|
|
152
|
+
|
|
153
|
+
// Reveal tracking for WCAG 4.1.3 announcements (task 7.11).
|
|
154
|
+
const prevVisible = useRef<Map<string, boolean>>(new Map());
|
|
155
|
+
const [announcement, setAnnouncement] = useState("");
|
|
156
|
+
const [revealedKeys, setRevealedKeys] = useState<Set<string>>(new Set());
|
|
157
|
+
useEffect(() => {
|
|
158
|
+
const newlyRevealed: string[] = [];
|
|
159
|
+
for (const [key, fs] of logicState.fields) {
|
|
160
|
+
const was = prevVisible.current.get(key);
|
|
161
|
+
if (was === false && fs.visible) newlyRevealed.push(key);
|
|
162
|
+
prevVisible.current.set(key, fs.visible);
|
|
163
|
+
}
|
|
164
|
+
if (newlyRevealed.length > 0) {
|
|
165
|
+
setRevealedKeys((s) => new Set([...s, ...newlyRevealed]));
|
|
166
|
+
const labels = newlyRevealed.map((k) => t.text(labelByKey.get(k), k) || k);
|
|
167
|
+
setAnnouncement(t.ui.revealedAnnouncement(labels.join(", ")));
|
|
168
|
+
}
|
|
169
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
170
|
+
}, [logicState]);
|
|
171
|
+
|
|
172
|
+
const [summary, setSummary] = useState<ErrorSummaryEntry[]>([]);
|
|
173
|
+
const [currentPage, setCurrentPage] = useState(0);
|
|
174
|
+
const pages = schema.pages;
|
|
175
|
+
const multiPage = pages.length > 1;
|
|
176
|
+
|
|
177
|
+
const themeCtx = useTheme();
|
|
178
|
+
const narrow = useMediaQuery(themeCtx.breakpoints.down("md"));
|
|
179
|
+
|
|
180
|
+
const collectIssues = useCallback(
|
|
181
|
+
(
|
|
182
|
+
snapshot: FormAnswers,
|
|
183
|
+
): { blocked: boolean; entries: ErrorSummaryEntry[]; snapState: ReturnType<typeof resolveFormState> } => {
|
|
184
|
+
// ONE snapshot drives validation, cross-field eval and payload (task 7.4d).
|
|
185
|
+
const snapState = resolveFormState(schema, snapshot);
|
|
186
|
+
const effective = snapState.effectiveAnswers;
|
|
187
|
+
const entries: ErrorSummaryEntry[] = [];
|
|
188
|
+
|
|
189
|
+
// Duplicate keys block and never reach onSubmit (tasks 7.4f, 7.4j).
|
|
190
|
+
const dup = staticDiagnostics.filter((d) => d.code === "duplicate-key");
|
|
191
|
+
if (dup.length > 0) {
|
|
192
|
+
for (const d of dup) entries.push({ message: d.message });
|
|
193
|
+
return { blocked: true, entries, snapState };
|
|
194
|
+
}
|
|
195
|
+
|
|
196
|
+
const zodSchema = deriveZodSchema(schema, snapState);
|
|
197
|
+
const result = zodSchema.safeParse(effective);
|
|
198
|
+
clearErrors();
|
|
199
|
+
if (!result.success) {
|
|
200
|
+
const seen = new Set<string>();
|
|
201
|
+
for (const issue of result.error.issues) {
|
|
202
|
+
if (issue.path[0] === FORM_LEVEL_PATH) {
|
|
203
|
+
if (!seen.has(issue.message)) {
|
|
204
|
+
entries.push({ message: issue.message });
|
|
205
|
+
seen.add(issue.message);
|
|
206
|
+
}
|
|
207
|
+
continue;
|
|
208
|
+
}
|
|
209
|
+
const name = issue.path.join(".");
|
|
210
|
+
setError(name as never, { type: "validate", message: issue.message });
|
|
211
|
+
const dedupeKey = `${name}:${issue.message}`;
|
|
212
|
+
if (!seen.has(dedupeKey)) {
|
|
213
|
+
entries.push({ message: issue.message, fieldName: String(issue.path[0]) });
|
|
214
|
+
seen.add(dedupeKey);
|
|
215
|
+
}
|
|
216
|
+
}
|
|
217
|
+
return { blocked: true, entries, snapState };
|
|
218
|
+
}
|
|
219
|
+
return { blocked: false, entries: [], snapState };
|
|
220
|
+
},
|
|
221
|
+
[schema, staticDiagnostics, clearErrors, setError],
|
|
222
|
+
);
|
|
223
|
+
|
|
224
|
+
const handleSubmit = useCallback(
|
|
225
|
+
(e: React.FormEvent) => {
|
|
226
|
+
e.preventDefault();
|
|
227
|
+
if (readOnly) return; // no payload under readOnly (task 7.4g)
|
|
228
|
+
const snapshot = getValues();
|
|
229
|
+
const { blocked, entries, snapState } = collectIssues(snapshot);
|
|
230
|
+
if (blocked) {
|
|
231
|
+
setSummary(entries);
|
|
232
|
+
return; // onSubmit NOT invoked (task 7.4j)
|
|
233
|
+
}
|
|
234
|
+
setSummary([]);
|
|
235
|
+
const payload = composePayload(schema, snapState, snapState.effectiveAnswers);
|
|
236
|
+
const runDiagnostics: Diagnostic[] = [
|
|
237
|
+
...normDiagnostics,
|
|
238
|
+
...collectFieldDiagnostics(schema, snapState, snapState.effectiveAnswers),
|
|
239
|
+
];
|
|
240
|
+
onSubmit?.(payload, { submissionContext, diagnostics: runDiagnostics });
|
|
241
|
+
},
|
|
242
|
+
[readOnly, getValues, collectIssues, schema, normDiagnostics, onSubmit, submissionContext],
|
|
243
|
+
);
|
|
244
|
+
|
|
245
|
+
const goNext = useCallback(() => {
|
|
246
|
+
if (readOnly) {
|
|
247
|
+
setCurrentPage((p) => Math.min(p + 1, pages.length - 1));
|
|
248
|
+
return;
|
|
249
|
+
}
|
|
250
|
+
const snapshot = getValues();
|
|
251
|
+
const { entries } = collectIssues(snapshot);
|
|
252
|
+
// Block advance only on errors belonging to the current page (task 7.3).
|
|
253
|
+
const pageErrors = entries.filter((en) => !en.fieldName || pageOfField.get(en.fieldName) === currentPage);
|
|
254
|
+
const blockingHere = entries.filter((en) => en.fieldName && pageOfField.get(en.fieldName) === currentPage);
|
|
255
|
+
if (blockingHere.length > 0) {
|
|
256
|
+
setSummary(pageErrors);
|
|
257
|
+
return;
|
|
258
|
+
}
|
|
259
|
+
setSummary([]);
|
|
260
|
+
setCurrentPage((p) => Math.min(p + 1, pages.length - 1));
|
|
261
|
+
}, [readOnly, getValues, collectIssues, pageOfField, currentPage, pages.length]);
|
|
262
|
+
|
|
263
|
+
const goBack = useCallback(() => {
|
|
264
|
+
setSummary([]);
|
|
265
|
+
setCurrentPage((p) => Math.max(p - 1, 0));
|
|
266
|
+
}, []);
|
|
267
|
+
|
|
268
|
+
const page = pages[currentPage];
|
|
269
|
+
|
|
270
|
+
const inner = (
|
|
271
|
+
<LocalizationProvider dateAdapter={AdapterDayjs}>
|
|
272
|
+
<OpenFormsProvider
|
|
273
|
+
value={{ t, readOnly, state: logicState, SignatureComponent, markerMode }}
|
|
274
|
+
>
|
|
275
|
+
<FormProvider {...form}>
|
|
276
|
+
<Box component="form" onSubmit={handleSubmit} noValidate>
|
|
277
|
+
{schema.formTitle && (
|
|
278
|
+
<Typography variant="h5" component="h1" gutterBottom>
|
|
279
|
+
{t.text(schema.formTitle, "formTitle")}
|
|
280
|
+
</Typography>
|
|
281
|
+
)}
|
|
282
|
+
{schema.formDescription && (
|
|
283
|
+
<Typography variant="body1" color="text.secondary" sx={{ mb: 2 }}>
|
|
284
|
+
{t.text(schema.formDescription, "formDescription")}
|
|
285
|
+
</Typography>
|
|
286
|
+
)}
|
|
287
|
+
|
|
288
|
+
{markerMode === "all-required" && (
|
|
289
|
+
<Typography variant="body2" color="text.secondary" sx={{ mb: 2 }}>
|
|
290
|
+
{t.ui.allFieldsRequired}
|
|
291
|
+
</Typography>
|
|
292
|
+
)}
|
|
293
|
+
|
|
294
|
+
{!readOnly && <ErrorSummary title={t.ui.errorSummaryTitle} entries={summary} />}
|
|
295
|
+
|
|
296
|
+
{multiPage && (
|
|
297
|
+
<Stepper
|
|
298
|
+
activeStep={currentPage}
|
|
299
|
+
alternativeLabel={!narrow}
|
|
300
|
+
orientation={narrow ? "vertical" : "horizontal"}
|
|
301
|
+
sx={{ mb: 3 }}
|
|
302
|
+
>
|
|
303
|
+
{pages.map((p, i) => (
|
|
304
|
+
<Step key={p.pageId ?? i}>
|
|
305
|
+
<StepLabel>{t.text(p.title, `page-${i}`) || `Page ${i + 1}`}</StepLabel>
|
|
306
|
+
</Step>
|
|
307
|
+
))}
|
|
308
|
+
</Stepper>
|
|
309
|
+
)}
|
|
310
|
+
|
|
311
|
+
{page.sections.map((section, si) => {
|
|
312
|
+
const sid = section.sectionId ?? `p${currentPage}-s${si}`;
|
|
313
|
+
if (logicState.sections.get(sid) === false) return null;
|
|
314
|
+
return (
|
|
315
|
+
<Box key={sid} sx={{ mb: 3 }}>
|
|
316
|
+
{section.title && (
|
|
317
|
+
<Typography variant="h6" component="h2" gutterBottom>
|
|
318
|
+
{t.text(section.title, sid)}
|
|
319
|
+
</Typography>
|
|
320
|
+
)}
|
|
321
|
+
{section.rows.map((row, ri) => (
|
|
322
|
+
<Grid container spacing={2} key={row.rowId ?? ri}>
|
|
323
|
+
{row.columns.map((col, ci) => (
|
|
324
|
+
<Grid key={col.columnId ?? ci} size={{ xs: 12, md: (col.width ?? 12) as number }}>
|
|
325
|
+
{col.fields.map((field, fi) => {
|
|
326
|
+
const fs = logicState.fields.get(field.key);
|
|
327
|
+
const isStatic = field.type === "header" || field.type === "paragraph";
|
|
328
|
+
if (!isStatic && fs && !fs.visible) return null;
|
|
329
|
+
return (
|
|
330
|
+
<FieldRenderer
|
|
331
|
+
key={field.id ?? `${field.key}-${fi}`}
|
|
332
|
+
field={field}
|
|
333
|
+
revealed={revealedKeys.has(field.key)}
|
|
334
|
+
/>
|
|
335
|
+
);
|
|
336
|
+
})}
|
|
337
|
+
</Grid>
|
|
338
|
+
))}
|
|
339
|
+
</Grid>
|
|
340
|
+
))}
|
|
341
|
+
</Box>
|
|
342
|
+
);
|
|
343
|
+
})}
|
|
344
|
+
|
|
345
|
+
{!readOnly && (
|
|
346
|
+
<Stack
|
|
347
|
+
direction={{ xs: "column", sm: "row" }}
|
|
348
|
+
spacing={2}
|
|
349
|
+
sx={{ mt: 2, justifyContent: "space-between" }}
|
|
350
|
+
>
|
|
351
|
+
{multiPage && currentPage > 0 ? (
|
|
352
|
+
<Button variant="outlined" onClick={goBack}>
|
|
353
|
+
{t.ui.previous}
|
|
354
|
+
</Button>
|
|
355
|
+
) : (
|
|
356
|
+
<span />
|
|
357
|
+
)}
|
|
358
|
+
{multiPage && currentPage < pages.length - 1 ? (
|
|
359
|
+
<Button variant="contained" onClick={goNext}>
|
|
360
|
+
{t.ui.next}
|
|
361
|
+
</Button>
|
|
362
|
+
) : (
|
|
363
|
+
<Button type="submit" variant="contained">
|
|
364
|
+
{t.ui.submit}
|
|
365
|
+
</Button>
|
|
366
|
+
)}
|
|
367
|
+
</Stack>
|
|
368
|
+
)}
|
|
369
|
+
|
|
370
|
+
{/* Polite live region for conditional reveals (task 7.11). */}
|
|
371
|
+
<Box
|
|
372
|
+
aria-live="polite"
|
|
373
|
+
sx={{
|
|
374
|
+
position: "absolute",
|
|
375
|
+
width: 1,
|
|
376
|
+
height: 1,
|
|
377
|
+
overflow: "hidden",
|
|
378
|
+
clip: "rect(0 0 0 0)",
|
|
379
|
+
whiteSpace: "nowrap",
|
|
380
|
+
}}
|
|
381
|
+
>
|
|
382
|
+
{announcement}
|
|
383
|
+
</Box>
|
|
384
|
+
</Box>
|
|
385
|
+
</FormProvider>
|
|
386
|
+
</OpenFormsProvider>
|
|
387
|
+
</LocalizationProvider>
|
|
388
|
+
);
|
|
389
|
+
|
|
390
|
+
return theme ? <ThemeProvider theme={theme}>{inner}</ThemeProvider> : inner;
|
|
391
|
+
}
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
import type { JSX } from "react";
|
|
2
|
+
import { useEffect, useRef } from "react";
|
|
3
|
+
import Alert from "@mui/material/Alert";
|
|
4
|
+
import AlertTitle from "@mui/material/AlertTitle";
|
|
5
|
+
import Link from "@mui/material/Link";
|
|
6
|
+
import List from "@mui/material/List";
|
|
7
|
+
import ListItem from "@mui/material/ListItem";
|
|
8
|
+
import Typography from "@mui/material/Typography";
|
|
9
|
+
|
|
10
|
+
export interface ErrorSummaryEntry {
|
|
11
|
+
message: string;
|
|
12
|
+
/** Field name/id to focus on activation; absent for form-level problems. */
|
|
13
|
+
fieldName?: string;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
/**
|
|
17
|
+
* Linked error summary shown above the form on a blocked submit/advance. It
|
|
18
|
+
* receives focus when it appears (so a keyboard/AT user is told why the form did
|
|
19
|
+
* not advance), each linked entry moves focus to its field, and an entry with no
|
|
20
|
+
* reachable control reads as a form-level problem rather than a dead link.
|
|
21
|
+
*/
|
|
22
|
+
export function ErrorSummary({
|
|
23
|
+
title,
|
|
24
|
+
entries,
|
|
25
|
+
}: {
|
|
26
|
+
title: string;
|
|
27
|
+
entries: ErrorSummaryEntry[];
|
|
28
|
+
}): JSX.Element | null {
|
|
29
|
+
const ref = useRef<HTMLDivElement | null>(null);
|
|
30
|
+
useEffect(() => {
|
|
31
|
+
if (entries.length > 0) ref.current?.focus();
|
|
32
|
+
}, [entries]);
|
|
33
|
+
|
|
34
|
+
if (entries.length === 0) return null;
|
|
35
|
+
|
|
36
|
+
const focusField = (fieldName: string) => {
|
|
37
|
+
const el =
|
|
38
|
+
document.getElementById(fieldName) ??
|
|
39
|
+
document.querySelector<HTMLElement>(`[data-field-key="${fieldName}"] input, [data-field-key="${fieldName}"] textarea, [data-field-key="${fieldName}"] [tabindex]`);
|
|
40
|
+
if (el) {
|
|
41
|
+
el.focus();
|
|
42
|
+
el.scrollIntoView({ block: "center", behavior: "smooth" });
|
|
43
|
+
}
|
|
44
|
+
};
|
|
45
|
+
|
|
46
|
+
return (
|
|
47
|
+
<Alert severity="error" ref={ref} tabIndex={-1} sx={{ mb: 3 }} role="alert">
|
|
48
|
+
<AlertTitle>{title}</AlertTitle>
|
|
49
|
+
<List dense disablePadding>
|
|
50
|
+
{entries.map((e, i) => (
|
|
51
|
+
<ListItem key={i} disablePadding sx={{ display: "list-item", listStyle: "disc", ml: 3 }}>
|
|
52
|
+
{e.fieldName ? (
|
|
53
|
+
<Link
|
|
54
|
+
component="button"
|
|
55
|
+
type="button"
|
|
56
|
+
underline="always"
|
|
57
|
+
onClick={() => focusField(e.fieldName!)}
|
|
58
|
+
sx={{ textAlign: "left" }}
|
|
59
|
+
>
|
|
60
|
+
{e.message}
|
|
61
|
+
</Link>
|
|
62
|
+
) : (
|
|
63
|
+
<Typography component="span" variant="body2">
|
|
64
|
+
{e.message}
|
|
65
|
+
</Typography>
|
|
66
|
+
)}
|
|
67
|
+
</ListItem>
|
|
68
|
+
))}
|
|
69
|
+
</List>
|
|
70
|
+
</Alert>
|
|
71
|
+
);
|
|
72
|
+
}
|