@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.
Files changed (164) hide show
  1. package/.pi/skills/bpmn-package-explorer/SKILL.md +120 -0
  2. package/.pi/skills/bpmn-package-explorer/assets/LICENSE.bpmn-io.txt +23 -0
  3. package/.pi/skills/bpmn-package-explorer/assets/VENDORED.md +90 -0
  4. package/.pi/skills/bpmn-package-explorer/assets/bpmn-js/bpmn-font/css/bpmn-codes.css +108 -0
  5. package/.pi/skills/bpmn-package-explorer/assets/bpmn-js/bpmn-font/css/bpmn-embedded.css +166 -0
  6. package/.pi/skills/bpmn-package-explorer/assets/bpmn-js/bpmn-font/css/bpmn.css +164 -0
  7. package/.pi/skills/bpmn-package-explorer/assets/bpmn-js/bpmn-font/font/bpmn.eot +0 -0
  8. package/.pi/skills/bpmn-package-explorer/assets/bpmn-js/bpmn-font/font/bpmn.svg +224 -0
  9. package/.pi/skills/bpmn-package-explorer/assets/bpmn-js/bpmn-font/font/bpmn.ttf +0 -0
  10. package/.pi/skills/bpmn-package-explorer/assets/bpmn-js/bpmn-font/font/bpmn.woff +0 -0
  11. package/.pi/skills/bpmn-package-explorer/assets/bpmn-js/bpmn-font/font/bpmn.woff2 +0 -0
  12. package/.pi/skills/bpmn-package-explorer/assets/bpmn-js/bpmn-navigated-viewer.production.min.js +22 -0
  13. package/.pi/skills/bpmn-package-explorer/assets/bpmn-js/bpmn.css +145 -0
  14. package/.pi/skills/bpmn-package-explorer/assets/bpmn-js/diagram-js.css +1249 -0
  15. package/.pi/skills/bpmn-package-explorer/assets/dmn-js/diagram-js.css +1133 -0
  16. package/.pi/skills/bpmn-package-explorer/assets/dmn-js/dmn-font/css/dmn-codes.css +41 -0
  17. package/.pi/skills/bpmn-package-explorer/assets/dmn-js/dmn-font/css/dmn-embedded.css +98 -0
  18. package/.pi/skills/bpmn-package-explorer/assets/dmn-js/dmn-font/css/dmn.css +97 -0
  19. package/.pi/skills/bpmn-package-explorer/assets/dmn-js/dmn-font/font/dmn.eot +0 -0
  20. package/.pi/skills/bpmn-package-explorer/assets/dmn-js/dmn-font/font/dmn.svg +90 -0
  21. package/.pi/skills/bpmn-package-explorer/assets/dmn-js/dmn-font/font/dmn.ttf +0 -0
  22. package/.pi/skills/bpmn-package-explorer/assets/dmn-js/dmn-font/font/dmn.woff +0 -0
  23. package/.pi/skills/bpmn-package-explorer/assets/dmn-js/dmn-font/font/dmn.woff2 +0 -0
  24. package/.pi/skills/bpmn-package-explorer/assets/dmn-js/dmn-js-decision-table.css +580 -0
  25. package/.pi/skills/bpmn-package-explorer/assets/dmn-js/dmn-js-drd.css +108 -0
  26. package/.pi/skills/bpmn-package-explorer/assets/dmn-js/dmn-js-literal-expression.css +165 -0
  27. package/.pi/skills/bpmn-package-explorer/assets/dmn-js/dmn-js-shared.css +221 -0
  28. package/.pi/skills/bpmn-package-explorer/assets/dmn-js/dmn-viewer.production.min.js +16 -0
  29. package/.pi/skills/bpmn-package-explorer/assets/lib/bpmn-pipeline.mjs +6981 -0
  30. package/.pi/skills/bpmn-package-explorer/assets/lib/yaml.mjs +7372 -0
  31. package/.pi/skills/bpmn-package-explorer/fixtures/geometry/g1-identical-bounds.bpmn +17 -0
  32. package/.pi/skills/bpmn-package-explorer/fixtures/geometry/g2-zero-size.bpmn +17 -0
  33. package/.pi/skills/bpmn-package-explorer/fixtures/geometry/g3-child-outside.bpmn +16 -0
  34. package/.pi/skills/bpmn-package-explorer/fixtures/geometry/g4-negative-coord.bpmn +17 -0
  35. package/.pi/skills/bpmn-package-explorer/fixtures/geometry/g5-overlap.bpmn +17 -0
  36. package/.pi/skills/bpmn-package-explorer/fixtures/measured/1-linear.bpmn +12 -0
  37. package/.pi/skills/bpmn-package-explorer/fixtures/measured/2-gateway.bpmn +19 -0
  38. package/.pi/skills/bpmn-package-explorer/fixtures/measured/3-boundary.bpmn +13 -0
  39. package/.pi/skills/bpmn-package-explorer/fixtures/measured/4-subprocess.bpmn +17 -0
  40. package/.pi/skills/bpmn-package-explorer/fixtures/measured/5-pools.bpmn +21 -0
  41. package/.pi/skills/bpmn-package-explorer/fixtures/measured/6-lanes-only.bpmn +16 -0
  42. package/.pi/skills/bpmn-package-explorer/fixtures/measured/7-loop.bpmn +13 -0
  43. package/.pi/skills/bpmn-package-explorer/fixtures/measured/8-long-chain.bpmn +32 -0
  44. package/.pi/skills/bpmn-package-explorer/fixtures/nesting/expanded-subprocess-ok.bpmn +25 -0
  45. package/.pi/skills/bpmn-package-explorer/fixtures/provisional/call-activity.bpmn +10 -0
  46. package/.pi/skills/bpmn-package-explorer/fixtures/provisional/intermediate-catch.bpmn +10 -0
  47. package/.pi/skills/bpmn-package-explorer/fixtures/provisional/intermediate-throw.bpmn +10 -0
  48. package/.pi/skills/bpmn-package-explorer/fixtures/provisional/manual-task.bpmn +10 -0
  49. package/.pi/skills/bpmn-package-explorer/fixtures/provisional/multi-boundary.bpmn +16 -0
  50. package/.pi/skills/bpmn-package-explorer/fixtures/provisional/parallel-gateway.bpmn +10 -0
  51. package/.pi/skills/bpmn-package-explorer/fixtures/provisional/receive-task.bpmn +10 -0
  52. package/.pi/skills/bpmn-package-explorer/fixtures/provisional/rule-task.bpmn +10 -0
  53. package/.pi/skills/bpmn-package-explorer/fixtures/provisional/script-task.bpmn +10 -0
  54. package/.pi/skills/bpmn-package-explorer/fixtures/provisional/send-task.bpmn +10 -0
  55. package/.pi/skills/bpmn-package-explorer/references/authoring-envelope.md +52 -0
  56. package/.pi/skills/bpmn-package-explorer/references/identifiers.md +102 -0
  57. package/.pi/skills/bpmn-package-explorer/references/layout-envelope.md +105 -0
  58. package/.pi/skills/bpmn-package-explorer/references/licensing.md +48 -0
  59. package/.pi/skills/bpmn-package-explorer/references/package-manifest.md +104 -0
  60. package/.pi/skills/bpmn-package-explorer/scripts/build-fixtures.mjs +299 -0
  61. package/.pi/skills/bpmn-package-explorer/scripts/demo.mjs +128 -0
  62. package/.pi/skills/bpmn-package-explorer/scripts/diagnostics.mjs +37 -0
  63. package/.pi/skills/bpmn-package-explorer/scripts/envelope.mjs +160 -0
  64. package/.pi/skills/bpmn-package-explorer/scripts/fixtures.mjs +140 -0
  65. package/.pi/skills/bpmn-package-explorer/scripts/generate-cli.mjs +31 -0
  66. package/.pi/skills/bpmn-package-explorer/scripts/generate.mjs +103 -0
  67. package/.pi/skills/bpmn-package-explorer/scripts/guard.mjs +335 -0
  68. package/.pi/skills/bpmn-package-explorer/scripts/harness.mjs +12 -0
  69. package/.pi/skills/bpmn-package-explorer/scripts/identifiers.mjs +117 -0
  70. package/.pi/skills/bpmn-package-explorer/scripts/ingest.mjs +95 -0
  71. package/.pi/skills/bpmn-package-explorer/scripts/manifest.mjs +374 -0
  72. package/.pi/skills/bpmn-package-explorer/scripts/pipeline.mjs +49 -0
  73. package/.pi/skills/bpmn-package-explorer/scripts/render.mjs +130 -0
  74. package/.pi/skills/bpmn-package-explorer/scripts/runguard.mjs +38 -0
  75. package/.pi/skills/bpmn-package-explorer/scripts/selftest-e2e.mjs +87 -0
  76. package/.pi/skills/bpmn-package-explorer/scripts/selftest-guard.mjs +99 -0
  77. package/.pi/skills/bpmn-package-explorer/scripts/selftest-manifest.mjs +170 -0
  78. package/.pi/skills/bpmn-package-explorer/scripts/selftest-more.mjs +87 -0
  79. package/.pi/skills/bpmn-package-explorer/scripts/selftest-workflow.mjs +73 -0
  80. package/.pi/skills/bpmn-package-explorer/scripts/selftest.mjs +57 -0
  81. package/.pi/skills/bpmn-package-explorer/scripts/vendor.mjs +141 -0
  82. package/.pi/skills/bpmn-package-explorer/scripts/view-cli.mjs +19 -0
  83. package/.pi/skills/bpmn-package-explorer/templates/shell.html +141 -0
  84. package/.pi/skills/bpmn-package-explorer/templates/viewer.js +301 -0
  85. package/.pi/skills/canvas-webapp/SKILL.md +104 -0
  86. package/.pi/skills/openforms-mui/SKILL.md +187 -0
  87. package/.pi/skills/openforms-mui/references/a11y.md +68 -0
  88. package/.pi/skills/openforms-mui/references/field-widget-map.md +64 -0
  89. package/.pi/skills/openforms-mui/references/hu-locale.md +45 -0
  90. package/.pi/skills/openforms-mui/references/logic.md +94 -0
  91. package/.pi/skills/openforms-mui/references/schema.md +94 -0
  92. package/.pi/skills/openforms-mui/references/theme-bridge.md +65 -0
  93. package/.pi/skills/openforms-mui/tools/canvas-serve.mjs +51 -0
  94. package/.pi/skills/openforms-mui/tools/demo-schema.json +80 -0
  95. package/.pi/skills/openforms-mui/tools/mockups/tokens.css +27 -0
  96. package/.pi/skills/openforms-mui/tools/mockups/ui-contract.tokens.json +16 -0
  97. package/.pi/skills/openforms-mui/tools/package-lock.json +5919 -0
  98. package/.pi/skills/openforms-mui/tools/package.json +61 -0
  99. package/.pi/skills/openforms-mui/tools/preview/RenderPanel.tsx +105 -0
  100. package/.pi/skills/openforms-mui/tools/preview/canvas-app.tsx +66 -0
  101. package/.pi/skills/openforms-mui/tools/preview/canvas-index.html +16 -0
  102. package/.pi/skills/openforms-mui/tools/preview/cli.ts +99 -0
  103. package/.pi/skills/openforms-mui/tools/preview/index.html +17 -0
  104. package/.pi/skills/openforms-mui/tools/preview/main.tsx +228 -0
  105. package/.pi/skills/openforms-mui/tools/preview/vite-plugin.ts +41 -0
  106. package/.pi/skills/openforms-mui/tools/scripts/assert-peer-deps.mjs +39 -0
  107. package/.pi/skills/openforms-mui/tools/src/OpenFormsMui.tsx +391 -0
  108. package/.pi/skills/openforms-mui/tools/src/css.d.ts +2 -0
  109. package/.pi/skills/openforms-mui/tools/src/fields/ErrorSummary.tsx +72 -0
  110. package/.pi/skills/openforms-mui/tools/src/fields/FieldRenderer.tsx +328 -0
  111. package/.pi/skills/openforms-mui/tools/src/fields/FieldShell.tsx +50 -0
  112. package/.pi/skills/openforms-mui/tools/src/fields/FileField.tsx +91 -0
  113. package/.pi/skills/openforms-mui/tools/src/fields/MatrixField.tsx +146 -0
  114. package/.pi/skills/openforms-mui/tools/src/fields/RepeaterField.tsx +82 -0
  115. package/.pi/skills/openforms-mui/tools/src/fields/SignatureCanvas.tsx +121 -0
  116. package/.pi/skills/openforms-mui/tools/src/fields/context.tsx +34 -0
  117. package/.pi/skills/openforms-mui/tools/src/fields/index.ts +7 -0
  118. package/.pi/skills/openforms-mui/tools/src/fields/label.ts +42 -0
  119. package/.pi/skills/openforms-mui/tools/src/fonts.ts +8 -0
  120. package/.pi/skills/openforms-mui/tools/src/i18n/dictionary.ts +58 -0
  121. package/.pi/skills/openforms-mui/tools/src/i18n/hu.ts +56 -0
  122. package/.pi/skills/openforms-mui/tools/src/i18n/index.ts +43 -0
  123. package/.pi/skills/openforms-mui/tools/src/index.ts +27 -0
  124. package/.pi/skills/openforms-mui/tools/src/logic/cnf.ts +206 -0
  125. package/.pi/skills/openforms-mui/tools/src/logic/formula.ts +285 -0
  126. package/.pi/skills/openforms-mui/tools/src/logic/index.ts +4 -0
  127. package/.pi/skills/openforms-mui/tools/src/logic/operators.ts +43 -0
  128. package/.pi/skills/openforms-mui/tools/src/logic/state.ts +183 -0
  129. package/.pi/skills/openforms-mui/tools/src/payload.ts +83 -0
  130. package/.pi/skills/openforms-mui/tools/src/provenance.ts +21 -0
  131. package/.pi/skills/openforms-mui/tools/src/schema/diagnose.ts +256 -0
  132. package/.pi/skills/openforms-mui/tools/src/schema/index.ts +4 -0
  133. package/.pi/skills/openforms-mui/tools/src/schema/normalize.ts +163 -0
  134. package/.pi/skills/openforms-mui/tools/src/schema/types.ts +299 -0
  135. package/.pi/skills/openforms-mui/tools/src/schema/walk.ts +68 -0
  136. package/.pi/skills/openforms-mui/tools/src/theme/from-tokens.ts +102 -0
  137. package/.pi/skills/openforms-mui/tools/src/theme/index.ts +1 -0
  138. package/.pi/skills/openforms-mui/tools/src/validation/constrain.ts +83 -0
  139. package/.pi/skills/openforms-mui/tools/src/validation/diagnostics.ts +62 -0
  140. package/.pi/skills/openforms-mui/tools/src/validation/empty.ts +53 -0
  141. package/.pi/skills/openforms-mui/tools/src/validation/index.ts +5 -0
  142. package/.pi/skills/openforms-mui/tools/src/validation/resolver.ts +14 -0
  143. package/.pi/skills/openforms-mui/tools/src/validation/zod-from-schema.ts +169 -0
  144. package/.pi/skills/openforms-mui/tools/tests/a11y.test.tsx +82 -0
  145. package/.pi/skills/openforms-mui/tools/tests/cli.test.ts +74 -0
  146. package/.pi/skills/openforms-mui/tools/tests/component.test.tsx +295 -0
  147. package/.pi/skills/openforms-mui/tools/tests/diagnose.test.ts +163 -0
  148. package/.pi/skills/openforms-mui/tools/tests/fixtures/all-field-types.json +45 -0
  149. package/.pi/skills/openforms-mui/tools/tests/logic.test.ts +175 -0
  150. package/.pi/skills/openforms-mui/tools/tests/normalize.test.ts +105 -0
  151. package/.pi/skills/openforms-mui/tools/tests/reference-semantics.test.ts +131 -0
  152. package/.pi/skills/openforms-mui/tools/tests/responsive.test.tsx +158 -0
  153. package/.pi/skills/openforms-mui/tools/tests/setup.ts +16 -0
  154. package/.pi/skills/openforms-mui/tools/tests/singleton.test.tsx +31 -0
  155. package/.pi/skills/openforms-mui/tools/tests/theme.test.ts +65 -0
  156. package/.pi/skills/openforms-mui/tools/tests/toolchain.test.ts +33 -0
  157. package/.pi/skills/openforms-mui/tools/tests/validation.test.ts +222 -0
  158. package/.pi/skills/openforms-mui/tools/tsconfig.json +21 -0
  159. package/.pi/skills/openforms-mui/tools/vite.canvas.config.ts +21 -0
  160. package/.pi/skills/openforms-mui/tools/vitest.config.ts +17 -0
  161. package/NOTICE +46 -0
  162. package/README.md +62 -0
  163. package/package.json +46 -0
  164. package/scripts/ensure-openforms-deps.mjs +38 -0
@@ -0,0 +1,183 @@
1
+ /**
2
+ * Whole-form logic state derived from a schema and the current answers.
3
+ *
4
+ * This is the single place that combines: calculated-field recomputation,
5
+ * section visibility, and per-field visibility/required/disabled resolution
6
+ * (a field is visible only when both its own rule state and its section are
7
+ * visible). Repeater child fields are intentionally excluded — the upstream
8
+ * renderer never evaluates rule state for them (see the inert-repeater-child
9
+ * diagnostic).
10
+ */
11
+ import type {
12
+ AnswerValue,
13
+ Diagnostic,
14
+ FormAnswers,
15
+ FormSchemaJSON,
16
+ NumberField,
17
+ } from "../schema/types.js";
18
+ import { walkFields } from "../schema/walk.js";
19
+ import { evaluateFormula } from "./formula.js";
20
+ import { EvalContext, RuleEvaluation, evaluateRule, resolveProperty } from "./cnf.js";
21
+
22
+ export interface FieldLogicState {
23
+ key: string;
24
+ /** Effective visibility: own visibility rule AND containing section. */
25
+ visible: boolean;
26
+ required: boolean;
27
+ disabled: boolean;
28
+ /** True for a `number` field with `isCalculated: true`. */
29
+ calculated: boolean;
30
+ /** For a calculated field, whether `isVisibleOnForm` is false. */
31
+ hiddenCalculated: boolean;
32
+ type: string;
33
+ sectionId: string;
34
+ }
35
+
36
+ export interface FormLogicState {
37
+ /** Top-level fields only, keyed by field `key`. */
38
+ fields: Map<string, FieldLogicState>;
39
+ /** sectionId -> visible. */
40
+ sections: Map<string, boolean>;
41
+ /** Answers with calculated values filled in. */
42
+ effectiveAnswers: FormAnswers;
43
+ diagnostics: Diagnostic[];
44
+ }
45
+
46
+ /** Recompute calculated `number` fields to a fixed point. */
47
+ export function computeCalculatedValues(
48
+ schema: FormSchemaJSON,
49
+ answers: FormAnswers,
50
+ ): { answers: FormAnswers; diagnostics: Diagnostic[] } {
51
+ const out: FormAnswers = { ...answers };
52
+ const diagnostics: Diagnostic[] = [];
53
+ const calc: Array<{ field: NumberField; path: string }> = [];
54
+ walkFields(schema, ({ field, path, repeaterDepth }) => {
55
+ if (repeaterDepth === 0 && field.type === "number" && field.isCalculated && field.formulaExpression) {
56
+ calc.push({ field, path });
57
+ }
58
+ });
59
+ if (calc.length === 0) return { answers: out, diagnostics };
60
+
61
+ const resolveRef = (key: string): number => {
62
+ const v = out[key];
63
+ const n = typeof v === "number" ? v : Number(v);
64
+ return Number.isFinite(n) ? n : 0;
65
+ };
66
+
67
+ // Fixed-point: at most calc.length + 1 passes resolves any acyclic chain.
68
+ const maxPasses = calc.length + 1;
69
+ for (let pass = 0; pass < maxPasses; pass++) {
70
+ let changed = false;
71
+ for (const { field } of calc) {
72
+ const result = evaluateFormula(field.formulaExpression!, resolveRef);
73
+ if (out[field.key] !== result.value) {
74
+ out[field.key] = result.value;
75
+ changed = true;
76
+ }
77
+ if (pass === 0 && result.error) {
78
+ diagnostics.push({
79
+ severity: "warning",
80
+ code: "unparseable-formula",
81
+ message: `Calculated field "${field.key}" formula did not evaluate (${result.error}); using 0.`,
82
+ path: field.key,
83
+ });
84
+ }
85
+ }
86
+ if (!changed) break;
87
+ }
88
+ return { answers: out, diagnostics };
89
+ }
90
+
91
+ /** Compute the full logic state for a schema and answers. */
92
+ export function resolveFormState(schema: FormSchemaJSON, answers: FormAnswers): FormLogicState {
93
+ const { answers: effectiveAnswers, diagnostics } = computeCalculatedValues(schema, answers);
94
+
95
+ const ctx: EvalContext = {
96
+ getAnswer: (key: string): AnswerValue | undefined =>
97
+ Object.prototype.hasOwnProperty.call(effectiveAnswers, key) ? effectiveAnswers[key] : undefined,
98
+ };
99
+
100
+ const sections = new Map<string, boolean>();
101
+ schema.pages.forEach((page, pi) => {
102
+ page.sections.forEach((section, si) => {
103
+ const id = section.sectionId ?? `p${pi}-s${si}`;
104
+ const visible = resolveProperty(true, section.conditionalRules, "visibility", ctx);
105
+ sections.set(id, visible);
106
+ });
107
+ });
108
+
109
+ const fields = new Map<string, FieldLogicState>();
110
+ schema.pages.forEach((page, pi) => {
111
+ page.sections.forEach((section, si) => {
112
+ const sectionId = section.sectionId ?? `p${pi}-s${si}`;
113
+ const sectionVisible = sections.get(sectionId) ?? true;
114
+ section.rows.forEach((row) => {
115
+ row.columns.forEach((col) => {
116
+ col.fields.forEach((field) => {
117
+ if (field.type === "header" || field.type === "paragraph") return;
118
+ const ownVisible = resolveProperty(true, field.conditionalRules, "visibility", ctx);
119
+ const calculated = field.type === "number" && !!field.isCalculated;
120
+ const hiddenCalculated = calculated && (field as NumberField).isVisibleOnForm === false;
121
+ fields.set(field.key, {
122
+ key: field.key,
123
+ type: field.type,
124
+ sectionId,
125
+ visible: ownVisible && sectionVisible,
126
+ required: resolveProperty(!!field.required, field.conditionalRules, "required", ctx),
127
+ // A calculated field is not user-editable; treat as disabled for input.
128
+ disabled: calculated || resolveProperty(!!field.disabled, field.conditionalRules, "disabled", ctx),
129
+ calculated,
130
+ hiddenCalculated,
131
+ });
132
+ });
133
+ });
134
+ });
135
+ });
136
+ });
137
+
138
+ return { fields, sections, effectiveAnswers, diagnostics };
139
+ }
140
+
141
+ /** Inspectable per-rule evaluation for the debug panel (task 3.13). */
142
+ export interface RuleExplanation {
143
+ ownerKey: string;
144
+ kind: "field-visibility" | "field-required" | "field-disabled" | "section-visibility" | "cross-field";
145
+ targetProperty?: string;
146
+ evaluation: RuleEvaluation;
147
+ }
148
+
149
+ export function explainRules(schema: FormSchemaJSON, answers: FormAnswers): RuleExplanation[] {
150
+ const { answers: effectiveAnswers } = computeCalculatedValues(schema, answers);
151
+ const ctx: EvalContext = {
152
+ getAnswer: (key) =>
153
+ Object.prototype.hasOwnProperty.call(effectiveAnswers, key) ? effectiveAnswers[key] : undefined,
154
+ };
155
+ const out: RuleExplanation[] = [];
156
+
157
+ schema.pages.forEach((page, pi) => {
158
+ page.sections.forEach((section, si) => {
159
+ const sid = section.sectionId ?? `p${pi}-s${si}`;
160
+ for (const rule of section.conditionalRules ?? []) {
161
+ out.push({ ownerKey: sid, kind: "section-visibility", targetProperty: "visibility", evaluation: evaluateRule(rule, ctx) });
162
+ }
163
+ });
164
+ });
165
+
166
+ walkFields(schema, ({ field, repeaterDepth }) => {
167
+ if (repeaterDepth !== 0) return;
168
+ for (const rule of field.conditionalRules ?? []) {
169
+ out.push({
170
+ ownerKey: field.key,
171
+ kind: `field-${rule.targetProperty}` as RuleExplanation["kind"],
172
+ targetProperty: rule.targetProperty,
173
+ evaluation: evaluateRule(rule, ctx),
174
+ });
175
+ }
176
+ });
177
+
178
+ (schema.crossFieldRules ?? []).forEach((rule) => {
179
+ out.push({ ownerKey: rule.id ?? "cross", kind: "cross-field", evaluation: evaluateRule(rule, ctx) });
180
+ });
181
+
182
+ return out;
183
+ }
@@ -0,0 +1,83 @@
1
+ /**
2
+ * Payload composition — the contract the design's three review rounds converged
3
+ * on (D13). The submitted answers object reflects *applicability*, not rendering:
4
+ *
5
+ * - A non-visible field (own rule OR hidden section) is omitted; its value is
6
+ * retained in form state elsewhere, not here.
7
+ * - A disabled field is applicable and IS included.
8
+ * - A calculated `isVisibleOnForm:false` field is included when effectively
9
+ * visible; omission wins when it also sits in a hidden branch.
10
+ * - Every applicable field contributes its type's empty value rather than
11
+ * `undefined`, so no key is dropped by JSON serialisation.
12
+ * - A repeater contributes exactly one top-level array; each row carries every
13
+ * child key (empty-value table, so a `number` child is `null`); no child key
14
+ * appears at top level.
15
+ */
16
+ import type { AnswerValue, Field, FormAnswers, FormSchemaJSON, RepeaterField } from "./schema/types.js";
17
+ import type { FormLogicState } from "./logic/state.js";
18
+ import { emptyValueFor } from "./validation/empty.js";
19
+
20
+ function repeaterChildFields(field: RepeaterField): Field[] {
21
+ return (field.rows ?? []).flatMap((r) => r.columns.flatMap((c) => c.fields));
22
+ }
23
+
24
+ function composeRepeater(field: RepeaterField, value: unknown): AnswerValue {
25
+ const children = repeaterChildFields(field).filter(
26
+ (c) => c.type !== "header" && c.type !== "paragraph",
27
+ );
28
+ const rows = Array.isArray(value) ? value : [];
29
+ return rows.map((row) => {
30
+ const out: Record<string, AnswerValue> = {};
31
+ const source = (row ?? {}) as Record<string, unknown>;
32
+ for (const child of children) {
33
+ const v = source[child.key];
34
+ out[child.key] = v === undefined ? emptyValueFor(child.type) : (v as AnswerValue);
35
+ }
36
+ return out;
37
+ });
38
+ }
39
+
40
+ /**
41
+ * Compose the submitted payload from a submission snapshot. `answers` must be
42
+ * the snapshot's effective answers (calculated values already filled in).
43
+ */
44
+ export function composePayload(
45
+ schema: FormSchemaJSON,
46
+ state: FormLogicState,
47
+ answers: FormAnswers,
48
+ ): FormAnswers {
49
+ const payload: FormAnswers = {};
50
+
51
+ schema.pages.forEach((page) => {
52
+ page.sections.forEach((section) => {
53
+ section.rows.forEach((row) => {
54
+ row.columns.forEach((col) => {
55
+ col.fields.forEach((field) => {
56
+ if (field.type === "header" || field.type === "paragraph") return;
57
+ const fs = state.fields.get(field.key);
58
+ // Omission wins: a non-visible field never appears, whether hidden by
59
+ // its own rule, a hidden section, or a hidden branch around a
60
+ // calculated isVisibleOnForm:false field.
61
+ if (!fs || !fs.visible) return;
62
+
63
+ if (field.type === "repeater") {
64
+ payload[field.key] = composeRepeater(field, answers[field.key]);
65
+ return;
66
+ }
67
+
68
+ const raw = answers[field.key];
69
+ payload[field.key] = raw === undefined ? emptyValueFor(field.type) : raw;
70
+ });
71
+ });
72
+ });
73
+ });
74
+ });
75
+
76
+ return payload;
77
+ }
78
+
79
+ /** The second `onSubmit` argument: segregated context + run diagnostics (D13). */
80
+ export interface SubmissionMeta<C = unknown> {
81
+ submissionContext?: C;
82
+ diagnostics: import("./schema/types.js").Diagnostic[];
83
+ }
@@ -0,0 +1,21 @@
1
+ /**
2
+ * Single source of truth for upstream provenance.
3
+ *
4
+ * OpenForms is re-implemented here from its published `SCHEMA_REFERENCE.md` and
5
+ * observed semantics; no upstream renderer or builder source is copied into this
6
+ * skill. This constant is consumed by both the attribution text in `SKILL.md`
7
+ * tooling and the preview harness `--reference` mode, so the pinned version is
8
+ * declared exactly once.
9
+ */
10
+ export const UPSTREAM_PROVENANCE = {
11
+ /** Upstream GitHub repository the schema contract is derived from. */
12
+ repository: "henriquefps/open-forms",
13
+ /** Pinned reference version. `--reference` mode loads exactly this tag. */
14
+ version: "1.0.7",
15
+ /** Upstream licence. No upstream source is vendored; this is attribution only. */
16
+ license: "Apache-2.0",
17
+ /** jsDelivr base used by `--reference` mode to load the vanilla renderer. */
18
+ referenceCdnBase: "https://cdn.jsdelivr.net/gh/henriquefps/open-forms@1.0.7",
19
+ } as const;
20
+
21
+ export type UpstreamProvenance = typeof UPSTREAM_PROVENANCE;
@@ -0,0 +1,256 @@
1
+ /**
2
+ * Authoring-time schema diagnostics.
3
+ *
4
+ * Returns a machine-readable list of findings, each carrying a severity, a
5
+ * stable code, a human message, and a path locating the offending node.
6
+ * `diagnose` operates on a normalized schema (call `normalizeSchema` first) but
7
+ * tolerates a raw one.
8
+ */
9
+ import type { Condition, ConditionalRule, Diagnostic, FormSchemaJSON } from "./types.js";
10
+ import { collectFieldKeys, walkFields } from "./walk.js";
11
+ import { isRecognisedOperator } from "../logic/operators.js";
12
+ import { checkFormulaParses } from "../logic/formula.js";
13
+
14
+ function eachCondition(
15
+ rules: ConditionalRule[] | undefined,
16
+ fn: (c: Condition, groupEmpty: boolean, andGroupsEmpty: boolean, rule: ConditionalRule) => void,
17
+ ): void {
18
+ for (const rule of rules ?? []) {
19
+ if (!rule.andGroups || rule.andGroups.length === 0) {
20
+ fn({ dependentFieldKey: "", operator: "equals" }, false, true, rule);
21
+ continue;
22
+ }
23
+ for (const group of rule.andGroups) {
24
+ if (!group.conditions || group.conditions.length === 0) {
25
+ fn({ dependentFieldKey: "", operator: "equals" }, true, false, rule);
26
+ continue;
27
+ }
28
+ for (const c of group.conditions) fn(c, false, false, rule);
29
+ }
30
+ }
31
+ }
32
+
33
+ /** Produce all findings for a schema. */
34
+ export function diagnose(schema: FormSchemaJSON): Diagnostic[] {
35
+ const findings: Diagnostic[] = [];
36
+ const knownKeys = new Set(collectFieldKeys(schema));
37
+ const keyTypes = new Map<string, string>();
38
+ walkFields(schema, ({ field }) => {
39
+ if (field.type !== "header" && field.type !== "paragraph") keyTypes.set(field.key, field.type);
40
+ });
41
+
42
+ // ---- duplicate field keys ------------------------------------------------
43
+ const keyPaths = new Map<string, string[]>();
44
+ walkFields(schema, ({ field, path }) => {
45
+ if (field.type === "header" || field.type === "paragraph") return;
46
+ const arr = keyPaths.get(field.key) ?? [];
47
+ arr.push(path);
48
+ keyPaths.set(field.key, arr);
49
+ });
50
+ for (const [key, paths] of keyPaths) {
51
+ if (paths.length > 1) {
52
+ findings.push({
53
+ severity: "error",
54
+ code: "duplicate-key",
55
+ message: `Duplicate field key "${key}" declared at ${paths.length} locations: ${paths.join(", ")}.`,
56
+ path: paths[0],
57
+ });
58
+ }
59
+ }
60
+
61
+ // ---- per-field structural + rule diagnostics -----------------------------
62
+ walkFields(schema, ({ field, path, repeaterDepth }) => {
63
+ // repeater / matrix nested inside a repeater
64
+ if (repeaterDepth >= 1 && field.type === "repeater") {
65
+ findings.push({
66
+ severity: "error",
67
+ code: "repeater-in-repeater",
68
+ message: `Repeater "${field.key}" is nested inside another repeater, which is unsupported.`,
69
+ path,
70
+ });
71
+ }
72
+ if (repeaterDepth >= 1 && field.type === "matrix") {
73
+ findings.push({
74
+ severity: "error",
75
+ code: "matrix-in-repeater",
76
+ message: `Matrix "${field.key}" is nested inside a repeater, which is unsupported.`,
77
+ path,
78
+ });
79
+ }
80
+
81
+ // conditionalRules on a field nested inside a repeater are inert upstream
82
+ if (repeaterDepth >= 1 && field.conditionalRules && field.conditionalRules.length > 0) {
83
+ findings.push({
84
+ severity: "warning",
85
+ code: "inert-repeater-child-rule",
86
+ message: `Field "${field.key}" declares conditionalRules inside a repeater; the upstream renderer evaluates rule state for the repeater itself but not its child fields, so the rule has no effect.`,
87
+ path,
88
+ });
89
+ }
90
+
91
+ // optionsType: "api"
92
+ if (
93
+ (field.type === "dropdown" || field.type === "radio" || field.type === "checkbox") &&
94
+ field.optionsType === "api"
95
+ ) {
96
+ findings.push({
97
+ severity: "warning",
98
+ code: "options-api-unsupported",
99
+ message: `Field "${field.key}" uses optionsType "api"; remote option loading is not supported, so it renders disabled with an empty option list.`,
100
+ path,
101
+ });
102
+ }
103
+
104
+ // number-only flags
105
+ if (field.type === "number") {
106
+ if (field.isVisibleOnForm === false && !field.isCalculated) {
107
+ findings.push({
108
+ severity: "warning",
109
+ code: "isvisibleonform-without-calculated",
110
+ message: `Field "${field.key}" sets isVisibleOnForm:false without isCalculated:true; the flag is inert and the field renders normally.`,
111
+ path,
112
+ });
113
+ }
114
+ if (field.isCalculated && field.formulaExpression) {
115
+ const err = checkFormulaParses(field.formulaExpression);
116
+ if (err) {
117
+ findings.push({
118
+ severity: "warning",
119
+ code: "unparseable-formula",
120
+ message: `Field "${field.key}" has an unparseable formulaExpression (${err}); it will evaluate to 0.`,
121
+ path,
122
+ });
123
+ }
124
+ }
125
+ }
126
+
127
+ // rule conditions
128
+ eachCondition(field.conditionalRules, (c, groupEmpty, andGroupsEmpty, rule) =>
129
+ diagnoseCondition(findings, path, field.key, knownKeys, keyTypes, c, groupEmpty, andGroupsEmpty, rule.targetProperty),
130
+ );
131
+ });
132
+
133
+ // ---- section rules -------------------------------------------------------
134
+ schema.pages.forEach((page, pi) => {
135
+ page.sections.forEach((section, si) => {
136
+ const spath = `pages[${pi}].sections[${si}]`;
137
+ eachCondition(section.conditionalRules, (c, groupEmpty, andGroupsEmpty, rule) =>
138
+ diagnoseCondition(findings, spath, section.sectionId ?? spath, knownKeys, keyTypes, c, groupEmpty, andGroupsEmpty, rule.targetProperty),
139
+ );
140
+ });
141
+ });
142
+
143
+ // ---- cross-field rules ---------------------------------------------------
144
+ (schema.crossFieldRules ?? []).forEach((rule, ri) => {
145
+ const rpath = `crossFieldRules[${ri}]`;
146
+ if (rule.andGroups) {
147
+ if (rule.andGroups.length === 0 && !rule.expression) {
148
+ findings.push({
149
+ severity: "warning",
150
+ code: "empty-and-groups",
151
+ message: `Cross-field rule "${rule.id ?? ri}" declares andGroups:[]; it can never be satisfied and never blocks.`,
152
+ path: rpath,
153
+ });
154
+ }
155
+ rule.andGroups.forEach((group, gi) => {
156
+ if (!group.conditions || group.conditions.length === 0) {
157
+ findings.push({
158
+ severity: "warning",
159
+ code: "empty-condition-group",
160
+ message: `Cross-field rule "${rule.id ?? ri}" group ${gi} has no conditions; the rule can never be satisfied.`,
161
+ path: `${rpath}.andGroups[${gi}]`,
162
+ });
163
+ }
164
+ (group.conditions ?? []).forEach((c) =>
165
+ diagnoseCondition(findings, rpath, rule.id ?? String(ri), knownKeys, keyTypes, c, false, false, undefined),
166
+ );
167
+ });
168
+ }
169
+ // dangling targetFields
170
+ for (const t of rule.targetFields ?? []) {
171
+ if (!knownKeys.has(t)) {
172
+ findings.push({
173
+ severity: "error",
174
+ code: "dangling-target-field",
175
+ message: `Cross-field rule "${rule.id ?? ri}" targets "${t}", which no field defines.`,
176
+ path: rpath,
177
+ });
178
+ }
179
+ }
180
+ });
181
+
182
+ return findings;
183
+ }
184
+
185
+ function diagnoseCondition(
186
+ findings: Diagnostic[],
187
+ path: string,
188
+ ownerKey: string,
189
+ knownKeys: Set<string>,
190
+ keyTypes: Map<string, string>,
191
+ c: Condition,
192
+ groupEmpty: boolean,
193
+ andGroupsEmpty: boolean,
194
+ targetProperty: string | undefined,
195
+ ): void {
196
+ if (andGroupsEmpty) {
197
+ findings.push({
198
+ severity: "warning",
199
+ code: "empty-and-groups",
200
+ message:
201
+ `Rule on "${ownerKey}" declares andGroups:[]; it can never be satisfied.` +
202
+ (targetProperty === "visibility" ? " Its visibility target is therefore always hidden." : ""),
203
+ path,
204
+ });
205
+ return;
206
+ }
207
+ if (groupEmpty) {
208
+ findings.push({
209
+ severity: "warning",
210
+ code: "empty-condition-group",
211
+ message: `Rule on "${ownerKey}" has a condition group with no conditions; the rule can never be satisfied.`,
212
+ path,
213
+ });
214
+ return;
215
+ }
216
+
217
+ // unrecognised operator
218
+ if (typeof c.operator === "string" && !isRecognisedOperator(c.operator)) {
219
+ findings.push({
220
+ severity: "warning",
221
+ code: "unrecognised-operator",
222
+ message: `Rule on "${ownerKey}" uses unrecognised operator "${c.operator}"; it will be evaluated as equality.`,
223
+ path,
224
+ });
225
+ }
226
+
227
+ // contains/notContains on a checkbox
228
+ if (c.operator === "contains" || c.operator === "notContains") {
229
+ if (keyTypes.get(c.dependentFieldKey) === "checkbox") {
230
+ findings.push({
231
+ severity: "warning",
232
+ code: "contains-on-checkbox",
233
+ message: `Rule on "${ownerKey}" applies "${c.operator}" to checkbox "${c.dependentFieldKey}"; it operates on the joined string, not array membership.`,
234
+ path,
235
+ });
236
+ }
237
+ }
238
+
239
+ // dangling dependent/compare references
240
+ if (c.dependentFieldKey && !knownKeys.has(c.dependentFieldKey)) {
241
+ findings.push({
242
+ severity: "error",
243
+ code: "dangling-dependent-field",
244
+ message: `Rule on "${ownerKey}" references dependentFieldKey "${c.dependentFieldKey}", which no field defines.`,
245
+ path,
246
+ });
247
+ }
248
+ if (c.compareMode === "field" && c.compareToFieldKey && !knownKeys.has(c.compareToFieldKey)) {
249
+ findings.push({
250
+ severity: "error",
251
+ code: "dangling-compare-field",
252
+ message: `Rule on "${ownerKey}" references compareToFieldKey "${c.compareToFieldKey}", which no field defines.`,
253
+ path,
254
+ });
255
+ }
256
+ }
@@ -0,0 +1,4 @@
1
+ export * from "./types.js";
2
+ export * from "./normalize.js";
3
+ export * from "./diagnose.js";
4
+ export { walkFields, collectFieldKeys } from "./walk.js";