@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,83 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Per-field-type Zod validators, shared by the blocking schema deriver and the
|
|
3
|
+
* non-blocking diagnostics collector so both judge a value identically.
|
|
4
|
+
*/
|
|
5
|
+
import { z } from "zod";
|
|
6
|
+
import type { Field, NumberField, TextField, TextareaField } from "../schema/types.js";
|
|
7
|
+
|
|
8
|
+
/** Shape-only validator; accepts the type's empty value. */
|
|
9
|
+
export function baseValidator(field: Field): z.ZodTypeAny {
|
|
10
|
+
switch (field.type) {
|
|
11
|
+
case "text":
|
|
12
|
+
case "textarea":
|
|
13
|
+
case "date":
|
|
14
|
+
case "signature":
|
|
15
|
+
case "dropdown":
|
|
16
|
+
case "radio":
|
|
17
|
+
return z.union([z.literal(""), z.string()]);
|
|
18
|
+
case "number":
|
|
19
|
+
return z.union([z.null(), z.literal(""), z.number()]);
|
|
20
|
+
case "boolean":
|
|
21
|
+
return z.boolean();
|
|
22
|
+
case "checkbox":
|
|
23
|
+
return z.array(z.string());
|
|
24
|
+
case "matrix":
|
|
25
|
+
return z.record(z.string(), z.string());
|
|
26
|
+
case "file":
|
|
27
|
+
return z.union([
|
|
28
|
+
z.null(),
|
|
29
|
+
z.object({ name: z.string(), size: z.number(), type: z.string(), content: z.string() }),
|
|
30
|
+
]);
|
|
31
|
+
default:
|
|
32
|
+
return z.any();
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
function rangeMessage(nf: NumberField): string {
|
|
37
|
+
if (typeof nf.min === "number" && typeof nf.max === "number") return `Enter a number between ${nf.min} and ${nf.max}.`;
|
|
38
|
+
if (typeof nf.min === "number") return `Enter a number of at least ${nf.min}.`;
|
|
39
|
+
if (typeof nf.max === "number") return `Enter a number of at most ${nf.max}.`;
|
|
40
|
+
return "Enter a valid number.";
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
/** Base validator plus type-specific shape constraints (regex, range, length). */
|
|
44
|
+
export function constrainedValidatorFor(field: Field): z.ZodTypeAny {
|
|
45
|
+
let v = baseValidator(field);
|
|
46
|
+
|
|
47
|
+
if (field.type === "text" || field.type === "textarea") {
|
|
48
|
+
const tf = field as TextField | TextareaField;
|
|
49
|
+
if (tf.validationRegex) {
|
|
50
|
+
const message = tf.errorMessage ?? "Value does not match the required format.";
|
|
51
|
+
let re: RegExp | null = null;
|
|
52
|
+
try {
|
|
53
|
+
re = new RegExp(tf.validationRegex);
|
|
54
|
+
} catch {
|
|
55
|
+
re = null;
|
|
56
|
+
}
|
|
57
|
+
if (re) {
|
|
58
|
+
v = v.refine((val) => val === "" || (typeof val === "string" && re!.test(val)), { message });
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
if (typeof tf.maxLength === "number") {
|
|
62
|
+
v = v.refine((val) => typeof val !== "string" || val.length <= tf.maxLength!, {
|
|
63
|
+
message: `Use at most ${tf.maxLength} characters.`,
|
|
64
|
+
});
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
if (field.type === "number") {
|
|
69
|
+
const nf = field as NumberField;
|
|
70
|
+
v = v.refine(
|
|
71
|
+
(val) => {
|
|
72
|
+
if (val === null || val === "") return true;
|
|
73
|
+
if (typeof val !== "number") return true;
|
|
74
|
+
if (typeof nf.min === "number" && val < nf.min) return false;
|
|
75
|
+
if (typeof nf.max === "number" && val > nf.max) return false;
|
|
76
|
+
return true;
|
|
77
|
+
},
|
|
78
|
+
{ message: rangeMessage(nf) },
|
|
79
|
+
);
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
return v;
|
|
83
|
+
}
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Non-blocking, submit-time diagnostics for fields that are exempt from blocking
|
|
3
|
+
* validation but still emitted in the payload: disabled fields, rendered
|
|
4
|
+
* calculated fields, and non-rendered calculated fields. A value known to
|
|
5
|
+
* violate its own declared constraints must never reach a downstream consumer
|
|
6
|
+
* silently, so these travel with the payload via the second `onSubmit` argument
|
|
7
|
+
* (validation spec). Non-blocking does not mean unreported.
|
|
8
|
+
*/
|
|
9
|
+
import type { Diagnostic, FormAnswers, FormSchemaJSON } from "../schema/types.js";
|
|
10
|
+
import type { FormLogicState } from "../logic/state.js";
|
|
11
|
+
import { walkFields } from "../schema/walk.js";
|
|
12
|
+
import { isEmptyValue } from "./empty.js";
|
|
13
|
+
import { constrainedValidatorFor } from "./constrain.js";
|
|
14
|
+
|
|
15
|
+
export function collectFieldDiagnostics(
|
|
16
|
+
schema: FormSchemaJSON,
|
|
17
|
+
state: FormLogicState,
|
|
18
|
+
answers: FormAnswers,
|
|
19
|
+
): Diagnostic[] {
|
|
20
|
+
const diagnostics: Diagnostic[] = [];
|
|
21
|
+
|
|
22
|
+
walkFields(schema, ({ field, path, repeaterDepth }) => {
|
|
23
|
+
if (repeaterDepth !== 0) return;
|
|
24
|
+
if (field.type === "header" || field.type === "paragraph") return;
|
|
25
|
+
const fs = state.fields.get(field.key);
|
|
26
|
+
if (!fs) return;
|
|
27
|
+
|
|
28
|
+
// Only disabled/calculated fields are exempt-but-reported. Visible editable
|
|
29
|
+
// fields block instead, so no diagnostic here.
|
|
30
|
+
const exemptButReported = fs.disabled || fs.calculated || fs.hiddenCalculated;
|
|
31
|
+
if (!exemptButReported) return;
|
|
32
|
+
|
|
33
|
+
const value = answers[field.key];
|
|
34
|
+
|
|
35
|
+
// Required-but-empty (only meaningful when the field is required).
|
|
36
|
+
if (fs.required && isEmptyValue(field.type, value)) {
|
|
37
|
+
diagnostics.push({
|
|
38
|
+
severity: "warning",
|
|
39
|
+
code: "disabled-required-empty",
|
|
40
|
+
message: `Field "${field.key}" is required but its (disabled/derived) value is empty; it was submitted anyway.`,
|
|
41
|
+
path,
|
|
42
|
+
});
|
|
43
|
+
return;
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
// Constraint violation on a value the user cannot correct.
|
|
47
|
+
if (!isEmptyValue(field.type, value)) {
|
|
48
|
+
const validator = constrainedValidatorFor(field);
|
|
49
|
+
const result = validator.safeParse(value);
|
|
50
|
+
if (!result.success) {
|
|
51
|
+
diagnostics.push({
|
|
52
|
+
severity: "warning",
|
|
53
|
+
code: fs.calculated || fs.hiddenCalculated ? "calculated-constraint-violation" : "disabled-constraint-violation",
|
|
54
|
+
message: `Field "${field.key}" holds a value violating its constraints (${result.error.issues[0]?.message ?? "invalid"}); it was submitted anyway.`,
|
|
55
|
+
path,
|
|
56
|
+
});
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
});
|
|
60
|
+
|
|
61
|
+
return diagnostics;
|
|
62
|
+
}
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The per-type empty-value table (renderer spec) plus an `isEmpty` predicate.
|
|
3
|
+
* One definition avoids the contradiction the design's third review found: a
|
|
4
|
+
* `number` empty is `null` and a `date` empty is `""`, and validators must accept
|
|
5
|
+
* those before applying shape rejection (task 4.0).
|
|
6
|
+
*/
|
|
7
|
+
import type { AnswerValue, FieldType } from "../schema/types.js";
|
|
8
|
+
|
|
9
|
+
export function emptyValueFor(type: FieldType): AnswerValue {
|
|
10
|
+
switch (type) {
|
|
11
|
+
case "text":
|
|
12
|
+
case "textarea":
|
|
13
|
+
case "date":
|
|
14
|
+
case "signature":
|
|
15
|
+
case "dropdown":
|
|
16
|
+
case "radio":
|
|
17
|
+
return "";
|
|
18
|
+
case "number":
|
|
19
|
+
return null;
|
|
20
|
+
case "boolean":
|
|
21
|
+
return false;
|
|
22
|
+
case "checkbox":
|
|
23
|
+
return [];
|
|
24
|
+
case "matrix":
|
|
25
|
+
return {};
|
|
26
|
+
case "repeater":
|
|
27
|
+
return [];
|
|
28
|
+
case "file":
|
|
29
|
+
return null;
|
|
30
|
+
// header / paragraph contribute no value; represented as "" if ever asked.
|
|
31
|
+
default:
|
|
32
|
+
return "";
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
export function isEmptyValue(type: FieldType, value: unknown): boolean {
|
|
37
|
+
switch (type) {
|
|
38
|
+
case "number":
|
|
39
|
+
return value === null || value === undefined || value === "";
|
|
40
|
+
case "boolean":
|
|
41
|
+
// A required boolean must be affirmatively true (e.g. a consent switch).
|
|
42
|
+
return value !== true;
|
|
43
|
+
case "checkbox":
|
|
44
|
+
case "repeater":
|
|
45
|
+
return !Array.isArray(value) || value.length === 0;
|
|
46
|
+
case "matrix":
|
|
47
|
+
return !value || typeof value !== "object" || Object.keys(value as object).length === 0;
|
|
48
|
+
case "file":
|
|
49
|
+
return value === null || value === undefined;
|
|
50
|
+
default:
|
|
51
|
+
return value === "" || value === null || value === undefined;
|
|
52
|
+
}
|
|
53
|
+
}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* react-hook-form resolver bridging the derived Zod schema. Nested repeater
|
|
3
|
+
* errors are addressable at their array paths because zod issue paths
|
|
4
|
+
* (`[key, index, childKey]`) map onto RHF field names directly.
|
|
5
|
+
*/
|
|
6
|
+
import { zodResolver } from "@hookform/resolvers/zod";
|
|
7
|
+
import type { Resolver } from "react-hook-form";
|
|
8
|
+
import type { z } from "zod";
|
|
9
|
+
import type { FormAnswers } from "../schema/types.js";
|
|
10
|
+
|
|
11
|
+
export function makeResolver(zodSchema: z.ZodType<FormAnswers>): Resolver<FormAnswers> {
|
|
12
|
+
// zodResolver understands superRefine issues, including our form-level path.
|
|
13
|
+
return zodResolver(zodSchema as never) as unknown as Resolver<FormAnswers>;
|
|
14
|
+
}
|
|
@@ -0,0 +1,169 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Derive a Zod schema from a `FormSchemaJSON` and the current `FormLogicState`.
|
|
3
|
+
*
|
|
4
|
+
* Rules encoded here (validation spec):
|
|
5
|
+
* - A non-visible field is exempt from EVERY constraint (not merely required).
|
|
6
|
+
* - A disabled field (including a rendered calculated field) never blocks; its
|
|
7
|
+
* constraint violations are reported as diagnostics, delivered out of band.
|
|
8
|
+
* - `crossFieldRules` attach as a `superRefine`: a satisfied rule is a
|
|
9
|
+
* violation; its `errorMessage` marks every currently-visible, non-disabled
|
|
10
|
+
* `targetFields` entry, and otherwise surfaces form-level (summary only).
|
|
11
|
+
* - Every non-required validator accepts its type's declared empty value.
|
|
12
|
+
*/
|
|
13
|
+
import { z } from "zod";
|
|
14
|
+
import type { FormAnswers, FormSchemaJSON, RepeaterField } from "../schema/types.js";
|
|
15
|
+
import type { FormLogicState } from "../logic/state.js";
|
|
16
|
+
import { EvalContext, evaluateRule } from "../logic/cnf.js";
|
|
17
|
+
import { isEmptyValue } from "./empty.js";
|
|
18
|
+
import { constrainedValidatorFor } from "./constrain.js";
|
|
19
|
+
|
|
20
|
+
/** Form-level (unlinked) issues carry this sentinel as their sole path element. */
|
|
21
|
+
export const FORM_LEVEL_PATH = "__form__";
|
|
22
|
+
|
|
23
|
+
// ---------------------------------------------------------------------------
|
|
24
|
+
// Repeater child object validator (children have no visibility rules)
|
|
25
|
+
// ---------------------------------------------------------------------------
|
|
26
|
+
|
|
27
|
+
function repeaterChildValidator(field: RepeaterField): z.ZodTypeAny {
|
|
28
|
+
const shape: Record<string, z.ZodTypeAny> = {};
|
|
29
|
+
for (const row of field.rows ?? []) {
|
|
30
|
+
for (const col of row.columns) {
|
|
31
|
+
for (const child of col.fields) {
|
|
32
|
+
if (child.type === "header" || child.type === "paragraph") continue;
|
|
33
|
+
let cv = constrainedValidatorFor(child);
|
|
34
|
+
if (child.required) {
|
|
35
|
+
cv = cv.refine((val) => !isEmptyValue(child.type, val), {
|
|
36
|
+
message: `${child.label ?? child.key} is required.`,
|
|
37
|
+
});
|
|
38
|
+
}
|
|
39
|
+
shape[child.key] = cv;
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
let arr: z.ZodTypeAny = z.array(z.object(shape));
|
|
44
|
+
if (typeof field.minItems === "number") {
|
|
45
|
+
arr = (arr as z.ZodArray<z.ZodTypeAny>).min(field.minItems, {
|
|
46
|
+
message: `Add at least ${field.minItems} item${field.minItems === 1 ? "" : "s"}.`,
|
|
47
|
+
});
|
|
48
|
+
}
|
|
49
|
+
if (typeof field.maxItems === "number") {
|
|
50
|
+
arr = (arr as z.ZodArray<z.ZodTypeAny>).max(field.maxItems, {
|
|
51
|
+
message: `Add at most ${field.maxItems} items.`,
|
|
52
|
+
});
|
|
53
|
+
}
|
|
54
|
+
return arr;
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
// ---------------------------------------------------------------------------
|
|
58
|
+
// Whole-form schema
|
|
59
|
+
// ---------------------------------------------------------------------------
|
|
60
|
+
|
|
61
|
+
export interface DeriveOptions {
|
|
62
|
+
/** Cross-field messages that could not attach to a field, for the summary. */
|
|
63
|
+
formLevelSink?: string[];
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
export function deriveZodSchema(
|
|
67
|
+
schema: FormSchemaJSON,
|
|
68
|
+
state: FormLogicState,
|
|
69
|
+
): z.ZodType<FormAnswers> {
|
|
70
|
+
const shape: Record<string, z.ZodTypeAny> = {};
|
|
71
|
+
|
|
72
|
+
schema.pages.forEach((page) => {
|
|
73
|
+
page.sections.forEach((section) => {
|
|
74
|
+
section.rows.forEach((row) => {
|
|
75
|
+
row.columns.forEach((col) => {
|
|
76
|
+
col.fields.forEach((field) => {
|
|
77
|
+
if (field.type === "header" || field.type === "paragraph") return;
|
|
78
|
+
const fs = state.fields.get(field.key);
|
|
79
|
+
|
|
80
|
+
// Not visible OR disabled/calculated => never blocks. Accept anything.
|
|
81
|
+
if (!fs || !fs.visible || fs.disabled) {
|
|
82
|
+
shape[field.key] = z.any();
|
|
83
|
+
return;
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
if (field.type === "repeater") {
|
|
87
|
+
shape[field.key] = repeaterChildValidator(field);
|
|
88
|
+
return;
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
let v = constrainedValidatorFor(field);
|
|
92
|
+
if (fs.required) {
|
|
93
|
+
v = v.refine((val) => !isEmptyValue(field.type, val), {
|
|
94
|
+
message: `${field.label ?? field.key} is required.`,
|
|
95
|
+
});
|
|
96
|
+
}
|
|
97
|
+
shape[field.key] = v;
|
|
98
|
+
});
|
|
99
|
+
});
|
|
100
|
+
});
|
|
101
|
+
});
|
|
102
|
+
});
|
|
103
|
+
|
|
104
|
+
const object = z.object(shape).catchall(z.any());
|
|
105
|
+
|
|
106
|
+
// Cross-field rules as a refinement over the whole (retained) answers object.
|
|
107
|
+
return object.superRefine((values, ctx) => {
|
|
108
|
+
const answers = values as FormAnswers;
|
|
109
|
+
const evalCtx: EvalContext = {
|
|
110
|
+
getAnswer: (k) => (Object.prototype.hasOwnProperty.call(answers, k) ? answers[k] : undefined),
|
|
111
|
+
};
|
|
112
|
+
for (const rule of schema.crossFieldRules ?? []) {
|
|
113
|
+
if (!rule.andGroups || rule.andGroups.length === 0) continue; // inert never blocks
|
|
114
|
+
const violated = evaluateRule(rule, evalCtx).satisfied;
|
|
115
|
+
if (!violated) continue;
|
|
116
|
+
|
|
117
|
+
const attachable = (rule.targetFields ?? []).filter((key) => {
|
|
118
|
+
const fs = state.fields.get(key);
|
|
119
|
+
return fs && fs.visible && !fs.disabled;
|
|
120
|
+
});
|
|
121
|
+
|
|
122
|
+
if (attachable.length > 0) {
|
|
123
|
+
for (const key of attachable) {
|
|
124
|
+
ctx.addIssue({ code: z.ZodIssueCode.custom, message: rule.errorMessage, path: [key] });
|
|
125
|
+
}
|
|
126
|
+
} else {
|
|
127
|
+
// No addressable target: surface as a form-level (summary-only) issue.
|
|
128
|
+
ctx.addIssue({ code: z.ZodIssueCode.custom, message: rule.errorMessage, path: [FORM_LEVEL_PATH] });
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
}) as unknown as z.ZodType<FormAnswers>;
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
// ---------------------------------------------------------------------------
|
|
135
|
+
// Memoization on the derived-state signature (task 4.5)
|
|
136
|
+
// ---------------------------------------------------------------------------
|
|
137
|
+
|
|
138
|
+
/** Serialize only the visibility/required/disabled map — never answer values. */
|
|
139
|
+
export function stateSignature(state: FormLogicState): string {
|
|
140
|
+
const parts: string[] = [];
|
|
141
|
+
for (const key of [...state.fields.keys()].sort()) {
|
|
142
|
+
const f = state.fields.get(key)!;
|
|
143
|
+
parts.push(`${key}:${f.visible ? 1 : 0}${f.required ? 1 : 0}${f.disabled ? 1 : 0}`);
|
|
144
|
+
}
|
|
145
|
+
for (const key of [...state.sections.keys()].sort()) {
|
|
146
|
+
parts.push(`§${key}:${state.sections.get(key) ? 1 : 0}`);
|
|
147
|
+
}
|
|
148
|
+
return parts.join("|");
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
/** Create a deriver that rebuilds only when the state signature changes. */
|
|
152
|
+
export function createMemoizedDeriver(
|
|
153
|
+
schema: FormSchemaJSON,
|
|
154
|
+
): (state: FormLogicState) => z.ZodType<FormAnswers> {
|
|
155
|
+
let lastSig: string | null = null;
|
|
156
|
+
let cached: z.ZodType<FormAnswers> | null = null;
|
|
157
|
+
let rebuildCount = 0;
|
|
158
|
+
const deriver = (state: FormLogicState): z.ZodType<FormAnswers> => {
|
|
159
|
+
const sig = stateSignature(state);
|
|
160
|
+
if (sig !== lastSig || cached === null) {
|
|
161
|
+
cached = deriveZodSchema(schema, state);
|
|
162
|
+
lastSig = sig;
|
|
163
|
+
rebuildCount++;
|
|
164
|
+
}
|
|
165
|
+
return cached;
|
|
166
|
+
};
|
|
167
|
+
(deriver as { rebuildCount?: () => number }).rebuildCount = () => rebuildCount;
|
|
168
|
+
return deriver;
|
|
169
|
+
}
|
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
import { describe, it, expect, beforeEach } from "vitest";
|
|
2
|
+
import { readFileSync } from "node:fs";
|
|
3
|
+
import { fileURLToPath } from "node:url";
|
|
4
|
+
import { dirname, join } from "node:path";
|
|
5
|
+
import { render, screen } from "@testing-library/react";
|
|
6
|
+
import axe from "axe-core";
|
|
7
|
+
import { OpenFormsMui } from "../src/OpenFormsMui";
|
|
8
|
+
import { themeFromTokens, defaultTheme } from "../src/theme/from-tokens";
|
|
9
|
+
import type { FormSchemaJSON } from "../src/schema/types";
|
|
10
|
+
|
|
11
|
+
const here = dirname(fileURLToPath(import.meta.url));
|
|
12
|
+
const allTypes = JSON.parse(
|
|
13
|
+
readFileSync(join(here, "fixtures", "all-field-types.json"), "utf8"),
|
|
14
|
+
) as FormSchemaJSON;
|
|
15
|
+
|
|
16
|
+
async function runAxe(container: HTMLElement) {
|
|
17
|
+
// Colour-contrast cannot run without layout in jsdom; disable it and assert on
|
|
18
|
+
// the structural rules (labels, roles, names) that DO run.
|
|
19
|
+
const results = await axe.run(container, {
|
|
20
|
+
rules: { "color-contrast": { enabled: false } },
|
|
21
|
+
});
|
|
22
|
+
return results.violations.filter((v) => v.impact === "serious" || v.impact === "critical");
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
describe("token layer ports 1:1 into the default theme (task 10.0)", () => {
|
|
26
|
+
it("themeFromTokens(ui-contract.tokens.json) equals the default theme palette", () => {
|
|
27
|
+
const tokens = JSON.parse(readFileSync(join(here, "..", "mockups", "ui-contract.tokens.json"), "utf8"));
|
|
28
|
+
const fromTokens = themeFromTokens(tokens);
|
|
29
|
+
const dft = defaultTheme();
|
|
30
|
+
expect(fromTokens.palette.primary.main).toBe(dft.palette.primary.main);
|
|
31
|
+
expect(fromTokens.palette.warning.main).toBe(dft.palette.warning.main);
|
|
32
|
+
expect(fromTokens.shape.borderRadius).toBe(dft.shape.borderRadius);
|
|
33
|
+
});
|
|
34
|
+
});
|
|
35
|
+
|
|
36
|
+
describe("automated accessibility gate (tasks 10.1, 10.4)", () => {
|
|
37
|
+
let container: HTMLElement;
|
|
38
|
+
beforeEach(() => {
|
|
39
|
+
const view = render(<OpenFormsMui schema={allTypes} />);
|
|
40
|
+
container = view.container;
|
|
41
|
+
});
|
|
42
|
+
|
|
43
|
+
it("reports no serious or critical violations across all 14 field types", async () => {
|
|
44
|
+
const violations = await runAxe(container);
|
|
45
|
+
expect(violations.map((v) => `${v.id}: ${v.help}`)).toEqual([]);
|
|
46
|
+
});
|
|
47
|
+
});
|
|
48
|
+
|
|
49
|
+
describe("grouped controls expose accessible names (task 10.2)", () => {
|
|
50
|
+
it("matrix, radio and checkbox groups are labelled", () => {
|
|
51
|
+
render(<OpenFormsMui schema={allTypes} />);
|
|
52
|
+
// Radio group legend.
|
|
53
|
+
expect(screen.getByText("Preferred contact")).toBeInTheDocument();
|
|
54
|
+
// Matrix is a labelled table.
|
|
55
|
+
expect(screen.getByRole("table", { name: "Satisfaction" })).toBeInTheDocument();
|
|
56
|
+
// Repeater legend.
|
|
57
|
+
expect(screen.getByText("People")).toBeInTheDocument();
|
|
58
|
+
});
|
|
59
|
+
});
|
|
60
|
+
|
|
61
|
+
describe("signature has an accessible name and clear control (task 10.3)", () => {
|
|
62
|
+
it("exposes role img with a name and a keyboard-reachable clear button", () => {
|
|
63
|
+
render(<OpenFormsMui schema={allTypes} />);
|
|
64
|
+
expect(screen.getByRole("img", { name: /signature/i })).toBeInTheDocument();
|
|
65
|
+
expect(screen.getByRole("button", { name: "Clear" })).toBeInTheDocument();
|
|
66
|
+
});
|
|
67
|
+
});
|
|
68
|
+
|
|
69
|
+
describe("error summary uses the error surface, warnings do not (task 10.9)", () => {
|
|
70
|
+
it("a blocked submit renders an alert on the error surface", async () => {
|
|
71
|
+
const schema: FormSchemaJSON = {
|
|
72
|
+
pages: [{ sections: [{ rows: [{ columns: [{ fields: [{ type: "text", key: "r", label: "R", required: true }] }] }] }] }],
|
|
73
|
+
} as FormSchemaJSON;
|
|
74
|
+
const { container } = render(<OpenFormsMui schema={schema} />);
|
|
75
|
+
const form = container.querySelector("form")!;
|
|
76
|
+
form.requestSubmit();
|
|
77
|
+
const alert = await screen.findByRole("alert");
|
|
78
|
+
// MUI error Alert carries the error colour class; never the warning one.
|
|
79
|
+
expect(alert.className).toMatch(/MuiAlert-(standardError|colorError|filledError|outlinedError)/);
|
|
80
|
+
expect(alert.className).not.toMatch(/Warning/);
|
|
81
|
+
});
|
|
82
|
+
});
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
import { describe, it, expect } from "vitest";
|
|
2
|
+
import { execFileSync } from "node:child_process";
|
|
3
|
+
import { readdirSync, readFileSync, writeFileSync, mkdtempSync } from "node:fs";
|
|
4
|
+
import { tmpdir } from "node:os";
|
|
5
|
+
import { fileURLToPath } from "node:url";
|
|
6
|
+
import { dirname, join } from "node:path";
|
|
7
|
+
|
|
8
|
+
const here = dirname(fileURLToPath(import.meta.url));
|
|
9
|
+
const root = join(here, "..");
|
|
10
|
+
const cli = join(root, "preview", "cli.ts");
|
|
11
|
+
const tsx = join(root, "node_modules", ".bin", "tsx");
|
|
12
|
+
const fixture = join(here, "fixtures", "all-field-types.json");
|
|
13
|
+
|
|
14
|
+
function runCli(args: string[]): { status: number; stdout: string; stderr: string } {
|
|
15
|
+
try {
|
|
16
|
+
const stdout = execFileSync(tsx, [cli, ...args], { encoding: "utf8" });
|
|
17
|
+
return { status: 0, stdout, stderr: "" };
|
|
18
|
+
} catch (e) {
|
|
19
|
+
const err = e as { status?: number; stdout?: string; stderr?: string };
|
|
20
|
+
return { status: err.status ?? 1, stdout: err.stdout ?? "", stderr: err.stderr ?? "" };
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
describe("CLI diagnose (task 8.1)", () => {
|
|
25
|
+
it("reports no error findings for a clean fixture and exits 0", () => {
|
|
26
|
+
const { status, stdout } = runCli(["diagnose", fixture]);
|
|
27
|
+
expect(status).toBe(0);
|
|
28
|
+
expect(stdout).not.toContain("[ERROR]");
|
|
29
|
+
});
|
|
30
|
+
|
|
31
|
+
it("exits non-zero when a schema has an error finding (duplicate key)", () => {
|
|
32
|
+
const dir = mkdtempSync(join(tmpdir(), "ofm-"));
|
|
33
|
+
const bad = join(dir, "bad.json");
|
|
34
|
+
writeFileSync(
|
|
35
|
+
bad,
|
|
36
|
+
JSON.stringify({
|
|
37
|
+
pages: [{ sections: [{ rows: [{ columns: [{ fields: [{ type: "text", key: "d" }, { type: "text", key: "d" }] }] }] }] }],
|
|
38
|
+
}),
|
|
39
|
+
);
|
|
40
|
+
const { status, stdout } = runCli(["diagnose", bad]);
|
|
41
|
+
expect(status).toBe(1);
|
|
42
|
+
expect(stdout).toContain("duplicate-key");
|
|
43
|
+
});
|
|
44
|
+
|
|
45
|
+
it("reports invalid input clearly without a stack trace", () => {
|
|
46
|
+
const dir = mkdtempSync(join(tmpdir(), "ofm-"));
|
|
47
|
+
const bad = join(dir, "notjson.json");
|
|
48
|
+
writeFileSync(bad, "{ not valid json");
|
|
49
|
+
const { status, stderr } = runCli(["diagnose", bad]);
|
|
50
|
+
expect(status).toBe(1);
|
|
51
|
+
expect(stderr).toContain("not valid JSON");
|
|
52
|
+
expect(stderr).not.toContain("at Object.");
|
|
53
|
+
});
|
|
54
|
+
});
|
|
55
|
+
|
|
56
|
+
describe("reference renderer is excluded from the library (task 8.4)", () => {
|
|
57
|
+
it("no src/ file loads the upstream renderer CDN", () => {
|
|
58
|
+
const offenders: string[] = [];
|
|
59
|
+
const walk = (dir: string) => {
|
|
60
|
+
for (const entry of readdirSync(dir, { withFileTypes: true })) {
|
|
61
|
+
const full = join(dir, entry.name);
|
|
62
|
+
if (entry.isDirectory()) walk(full);
|
|
63
|
+
else if (/\.(ts|tsx)$/.test(entry.name)) {
|
|
64
|
+
const code = readFileSync(full, "utf8");
|
|
65
|
+
// The provenance constant may NAME the CDN base; but no src file may
|
|
66
|
+
// actually load renderer.js or reference the vanilla globals.
|
|
67
|
+
if (/renderer\.js/.test(code) || /OpenFormRenderer/.test(code)) offenders.push(full);
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
};
|
|
71
|
+
walk(join(root, "src"));
|
|
72
|
+
expect(offenders, offenders.join("\n")).toEqual([]);
|
|
73
|
+
});
|
|
74
|
+
});
|