@burdenoff/microfe-govcitizenhub 2026.1114.1 → 2026.1123.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/govcitizenhub/components/DynamicFormFields.js +60 -46
- package/dist/govcitizenhub/components/DynamicFormFields.js.map +1 -1
- package/dist/govcitizenhub/pages/services/FormFieldBuilder.js +183 -155
- package/dist/govcitizenhub/pages/services/FormFieldBuilder.js.map +1 -1
- package/dist/govcitizenhub/utils/dynamicForm.d.ts +10 -0
- package/dist/govcitizenhub/utils/dynamicForm.js +50 -30
- package/dist/govcitizenhub/utils/dynamicForm.js.map +1 -1
- package/package.json +12 -9
|
@@ -1,56 +1,70 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { visibleFormSections as e } from "../utils/dynamicForm.js";
|
|
2
2
|
import { cn as t } from "../utils/cn.js";
|
|
3
3
|
import { CheckCircle2 as n, Loader2 as r, UploadCloud as i } from "lucide-react";
|
|
4
4
|
import { jsx as a, jsxs as o } from "react/jsx-runtime";
|
|
5
5
|
import { Input as s, Label as c, Select as l, SelectContent as u, SelectItem as d, SelectTrigger as f, SelectValue as p, Textarea as m } from "@burdenoff/fe-libs/ui";
|
|
6
6
|
// src/govcitizenhub/components/DynamicFormFields.tsx
|
|
7
7
|
function h({ fields: n, values: r, onChange: i, fileNames: h = {}, uploadingKey: _ = null, onFileSelect: v, disabled: y = !1, previewMode: b = !1, idPrefix: x = "f" }) {
|
|
8
|
-
let S =
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
children: " *"
|
|
20
|
-
})]
|
|
21
|
-
}), e.type === "textarea" ? /* @__PURE__ */ a(m, {
|
|
22
|
-
id: S,
|
|
23
|
-
value: r[e.key] ?? "",
|
|
24
|
-
onChange: (t) => i(e.key, t.target.value),
|
|
25
|
-
disabled: y,
|
|
26
|
-
rows: 3
|
|
27
|
-
}) : e.type === "select" ? /* @__PURE__ */ o(l, {
|
|
28
|
-
value: r[e.key] ?? "",
|
|
29
|
-
onValueChange: (t) => i(e.key, t),
|
|
30
|
-
disabled: y,
|
|
31
|
-
children: [/* @__PURE__ */ a(f, {
|
|
32
|
-
id: S,
|
|
33
|
-
"aria-label": e.label,
|
|
34
|
-
children: /* @__PURE__ */ a(p, { placeholder: "Select…" })
|
|
35
|
-
}), /* @__PURE__ */ a(u, { children: (e.options ?? []).map((e) => /* @__PURE__ */ a(d, {
|
|
36
|
-
value: e,
|
|
37
|
-
children: e
|
|
38
|
-
}, e)) })]
|
|
39
|
-
}) : e.type === "file" ? /* @__PURE__ */ a(g, {
|
|
40
|
-
id: S,
|
|
41
|
-
label: e.label,
|
|
42
|
-
fileName: h[e.key],
|
|
43
|
-
uploading: _ === e.key,
|
|
44
|
-
disabled: y || b,
|
|
45
|
-
onSelect: (t) => v?.(e.key, t)
|
|
46
|
-
}) : /* @__PURE__ */ a(s, {
|
|
47
|
-
id: S,
|
|
48
|
-
type: e.type === "number" ? "number" : e.type === "date" ? "date" : "text",
|
|
49
|
-
value: r[e.key] ?? "",
|
|
50
|
-
onChange: (t) => i(e.key, t.target.value),
|
|
51
|
-
disabled: y
|
|
8
|
+
let S = e(n, r);
|
|
9
|
+
if (S.length === 0) return null;
|
|
10
|
+
let C = (e) => {
|
|
11
|
+
let n = e.type === "textarea" || e.type === "file" ? "sm:col-span-2" : "", S = `${x}-${e.key}`;
|
|
12
|
+
return /* @__PURE__ */ o("div", {
|
|
13
|
+
className: t("grid gap-1.5", n),
|
|
14
|
+
children: [/* @__PURE__ */ o(c, {
|
|
15
|
+
htmlFor: S,
|
|
16
|
+
children: [e.label, e.required && /* @__PURE__ */ a("span", {
|
|
17
|
+
className: "text-status-error-text",
|
|
18
|
+
children: " *"
|
|
52
19
|
})]
|
|
53
|
-
}, e.
|
|
20
|
+
}), e.type === "textarea" ? /* @__PURE__ */ a(m, {
|
|
21
|
+
id: S,
|
|
22
|
+
value: r[e.key] ?? "",
|
|
23
|
+
onChange: (t) => i(e.key, t.target.value),
|
|
24
|
+
disabled: y,
|
|
25
|
+
rows: 3
|
|
26
|
+
}) : e.type === "select" ? /* @__PURE__ */ o(l, {
|
|
27
|
+
value: r[e.key] ?? "",
|
|
28
|
+
onValueChange: (t) => i(e.key, t),
|
|
29
|
+
disabled: y,
|
|
30
|
+
children: [/* @__PURE__ */ a(f, {
|
|
31
|
+
id: S,
|
|
32
|
+
"aria-label": e.label,
|
|
33
|
+
children: /* @__PURE__ */ a(p, { placeholder: "Select…" })
|
|
34
|
+
}), /* @__PURE__ */ a(u, { children: (e.options ?? []).map((e) => /* @__PURE__ */ a(d, {
|
|
35
|
+
value: e,
|
|
36
|
+
children: e
|
|
37
|
+
}, e)) })]
|
|
38
|
+
}) : e.type === "file" ? /* @__PURE__ */ a(g, {
|
|
39
|
+
id: S,
|
|
40
|
+
label: e.label,
|
|
41
|
+
fileName: h[e.key],
|
|
42
|
+
uploading: _ === e.key,
|
|
43
|
+
disabled: y || b,
|
|
44
|
+
onSelect: (t) => v?.(e.key, t)
|
|
45
|
+
}) : /* @__PURE__ */ a(s, {
|
|
46
|
+
id: S,
|
|
47
|
+
type: e.type === "number" ? "number" : e.type === "date" ? "date" : "text",
|
|
48
|
+
value: r[e.key] ?? "",
|
|
49
|
+
onChange: (t) => i(e.key, t.target.value),
|
|
50
|
+
disabled: y
|
|
51
|
+
})]
|
|
52
|
+
}, e.key);
|
|
53
|
+
};
|
|
54
|
+
return /* @__PURE__ */ a("div", {
|
|
55
|
+
className: "grid gap-6",
|
|
56
|
+
children: S.map(({ start: e, label: t, fields: n }) => {
|
|
57
|
+
let r = /* @__PURE__ */ a("div", {
|
|
58
|
+
className: "grid gap-4 sm:grid-cols-2",
|
|
59
|
+
children: n.map(C)
|
|
60
|
+
}, e);
|
|
61
|
+
return t ? /* @__PURE__ */ o("fieldset", {
|
|
62
|
+
className: "min-w-0",
|
|
63
|
+
children: [/* @__PURE__ */ a("legend", {
|
|
64
|
+
className: "mb-3 text-sm font-semibold text-text-primary",
|
|
65
|
+
children: t
|
|
66
|
+
}), r]
|
|
67
|
+
}, e) : r;
|
|
54
68
|
})
|
|
55
69
|
});
|
|
56
70
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"DynamicFormFields.js","names":["DynamicFormFields","
|
|
1
|
+
{"version":3,"file":"DynamicFormFields.js","names":["DynamicFormFields","sections","visibleFormSections","fields","values","renderField","spanFull","field","fieldId","idPrefix","cn","Label","Textarea","onChange","e","Select","v","SelectTrigger","SelectValue","SelectContent","SelectItem","opt","FileFieldControl","fileNames","uploadingKey","disabled","previewMode","onFileSelect","list","Input","sectionFields","fieldGrid","start","label","id","uploading","Loader2","fileName","CheckCircle2","UploadCloud","onSelect"],"sources":["../../../src/govcitizenhub/components/DynamicFormFields.tsx"],"sourcesContent":["/**\n * DynamicFormFields — renders a service's dynamic `formSchema` fields.\n * @module govcitizenhub/components\n *\n * The single renderer shared by the citizen-facing `NewApplicationPage` and the\n * no-code service builder's live preview (`ServiceFormDialog`) so a field an\n * agency author sees in preview is pixel-for-pixel what a citizen fills in —\n * including conditional (`showIf`) visibility (BOFF-4540).\n */\n\nimport {\n Input,\n Label,\n Textarea,\n Select,\n SelectContent,\n SelectItem,\n SelectTrigger,\n SelectValue,\n} from '@burdenoff/fe-libs/ui';\nimport { CheckCircle2, Loader2, UploadCloud } from 'lucide-react';\n\nimport { visibleFormSections, type DynamicFormField } from '../utils/dynamicForm';\nimport { cn } from '../utils/cn';\n\nexport interface DynamicFormFieldsProps {\n fields: DynamicFormField[];\n values: Record<string, string>;\n onChange: (key: string, value: string) => void;\n /** For `file` fields: the human filename to display (the value itself holds the file id). */\n fileNames?: Record<string, string>;\n uploadingKey?: string | null;\n onFileSelect?: (key: string, files: FileList | null) => void;\n disabled?: boolean;\n /** Preview mode (inside the builder): file uploads are shown but inert. */\n previewMode?: boolean;\n idPrefix?: string;\n}\n\nexport function DynamicFormFields({\n fields,\n values,\n onChange,\n fileNames = {},\n uploadingKey = null,\n onFileSelect,\n disabled = false,\n previewMode = false,\n idPrefix = 'f',\n}: DynamicFormFieldsProps) {\n const sections = visibleFormSections(fields, values);\n\n if (sections.length === 0) return null;\n\n const renderField = (field: DynamicFormField) => {\n const spanFull = field.type === 'textarea' || field.type === 'file' ? 'sm:col-span-2' : '';\n const fieldId = `${idPrefix}-${field.key}`;\n return (\n <div key={field.key} className={cn('grid gap-1.5', spanFull)}>\n <Label htmlFor={fieldId}>\n {field.label}\n {field.required && <span className=\"text-status-error-text\"> *</span>}\n </Label>\n {field.type === 'textarea' ? (\n <Textarea\n id={fieldId}\n value={values[field.key] ?? ''}\n onChange={(e) => onChange(field.key, e.target.value)}\n disabled={disabled}\n rows={3}\n />\n ) : field.type === 'select' ? (\n <Select\n value={values[field.key] ?? ''}\n onValueChange={(v) => onChange(field.key, v)}\n disabled={disabled}\n >\n <SelectTrigger id={fieldId} aria-label={field.label}>\n <SelectValue placeholder=\"Select…\" />\n </SelectTrigger>\n <SelectContent>\n {(field.options ?? []).map((opt) => (\n <SelectItem key={opt} value={opt}>\n {opt}\n </SelectItem>\n ))}\n </SelectContent>\n </Select>\n ) : field.type === 'file' ? (\n <FileFieldControl\n id={fieldId}\n label={field.label}\n fileName={fileNames[field.key]}\n uploading={uploadingKey === field.key}\n disabled={disabled || previewMode}\n onSelect={(list) => onFileSelect?.(field.key, list)}\n />\n ) : (\n <Input\n id={fieldId}\n type={field.type === 'number' ? 'number' : field.type === 'date' ? 'date' : 'text'}\n value={values[field.key] ?? ''}\n onChange={(e) => onChange(field.key, e.target.value)}\n disabled={disabled}\n />\n )}\n </div>\n );\n };\n\n return (\n <div className=\"grid gap-6\">\n {sections.map(({ start, label, fields: sectionFields }) => {\n const fieldGrid = (\n <div key={start} className=\"grid gap-4 sm:grid-cols-2\">\n {sectionFields.map(renderField)}\n </div>\n );\n return label ? (\n <fieldset key={start} className=\"min-w-0\">\n <legend className=\"mb-3 text-sm font-semibold text-text-primary\">{label}</legend>\n {fieldGrid}\n </fieldset>\n ) : (\n fieldGrid\n );\n })}\n </div>\n );\n}\n\n/** A click/drag upload control for a dynamic `file` form field. */\nfunction FileFieldControl({\n id,\n label,\n fileName,\n uploading,\n disabled,\n onSelect,\n}: {\n id: string;\n label: string;\n fileName?: string;\n uploading: boolean;\n disabled?: boolean;\n onSelect: (files: FileList | null) => void;\n}) {\n return (\n <label\n htmlFor={id}\n className={cn(\n 'flex items-center gap-3 rounded-xl border-2 border-dashed border-border-seam bg-bg-sunken/40 px-4 py-4 transition-colors',\n disabled ? 'cursor-not-allowed opacity-70' : 'cursor-pointer hover:border-border-strong',\n uploading && 'cursor-wait opacity-70'\n )}\n >\n <span className=\"inline-flex size-9 shrink-0 items-center justify-center rounded-full bg-[var(--color-accent-soft)] text-action-primary-text\">\n {uploading ? (\n <Loader2 className=\"size-5 animate-spin\" aria-hidden=\"true\" />\n ) : fileName ? (\n <CheckCircle2 className=\"size-5 text-status-success-text\" aria-hidden=\"true\" />\n ) : (\n <UploadCloud className=\"size-5\" aria-hidden=\"true\" />\n )}\n </span>\n <span className=\"min-w-0 flex-1\">\n <span className=\"block truncate text-sm font-medium text-text-primary\">\n {uploading ? 'Uploading…' : fileName ? fileName : 'Click to upload or drag & drop'}\n </span>\n <span className=\"mt-0.5 block text-xs text-text-muted\">\n {fileName ? 'Uploaded · click to replace' : 'PDF, JPG or PNG'}\n </span>\n </span>\n <input\n id={id}\n type=\"file\"\n className=\"sr-only\"\n aria-label={`Upload ${label}`}\n disabled={disabled || uploading}\n onChange={(e) => {\n onSelect(e.target.files);\n e.target.value = '';\n }}\n />\n </label>\n );\n}\n"],"mappings":";;;;;;AAuCA,SAAgBA,EAAkB,EAChC,WACA,WACA,aACA,eAAY,CAAC,GACb,kBAAe,MACf,iBACA,cAAW,IACX,iBAAc,IACd,cAAW,OACc;CACzB,IAAMC,IAAWC,EA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U;IACV,cAAY,UAAUJ;IACtB,UAAUR,KAAYU;IACtB,WAAW,MAAM;KAEf,AADAK,EAAS,EAAE,OAAO,KAAK,GACvB,EAAE,OAAO,QAAQ;IACnB;GACD,CAAA;EACI;;AAEX"}
|
|
@@ -1,44 +1,45 @@
|
|
|
1
1
|
import { TagInput as e } from "../../components/TagInput.js";
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
6
|
-
import {
|
|
7
|
-
import {
|
|
8
|
-
import {
|
|
2
|
+
import { useTr as t } from "../../../shared/hooks/useTr.js";
|
|
3
|
+
import { slugify as n } from "../../utils/formatters.js";
|
|
4
|
+
import { cn as r } from "../../utils/cn.js";
|
|
5
|
+
import { normalizeFormSection as i, parseFormFields as a, serializeFormFields as o } from "../../utils/dynamicForm.js";
|
|
6
|
+
import { useId as s, useState as c } from "react";
|
|
7
|
+
import { AlignLeft as l, Calendar as u, Check as d, ChevronDown as f, ChevronUp as p, GitBranch as m, GripVertical as h, Hash as g, ListChecks as _, Pencil as v, Plus as y, Trash2 as b, Type as x, UploadCloud as S } from "lucide-react";
|
|
8
|
+
import { jsx as C, jsxs as w } from "react/jsx-runtime";
|
|
9
|
+
import { Button as T, Input as E, Label as D, Select as O, SelectContent as k, SelectItem as A, SelectTrigger as j, SelectValue as M, Switch as N } from "@burdenoff/fe-libs/ui";
|
|
9
10
|
// src/govcitizenhub/pages/services/FormFieldBuilder.tsx
|
|
10
|
-
var
|
|
11
|
+
var P = {
|
|
11
12
|
text: {
|
|
12
13
|
label: "Text",
|
|
13
|
-
icon:
|
|
14
|
+
icon: x,
|
|
14
15
|
tone: "bg-[var(--color-accent-soft)] text-action-primary-text"
|
|
15
16
|
},
|
|
16
17
|
textarea: {
|
|
17
18
|
label: "Paragraph",
|
|
18
|
-
icon:
|
|
19
|
+
icon: l,
|
|
19
20
|
tone: "bg-[var(--color-accent-soft)] text-action-primary-text"
|
|
20
21
|
},
|
|
21
22
|
number: {
|
|
22
23
|
label: "Number",
|
|
23
|
-
icon:
|
|
24
|
+
icon: g,
|
|
24
25
|
tone: "bg-status-success-bg-subtle text-status-success-text"
|
|
25
26
|
},
|
|
26
27
|
date: {
|
|
27
28
|
label: "Date",
|
|
28
|
-
icon:
|
|
29
|
+
icon: u,
|
|
29
30
|
tone: "bg-[color-mix(in_oklab,var(--color-accent-purple)_16%,transparent)] text-[var(--color-accent-purple)]"
|
|
30
31
|
},
|
|
31
32
|
select: {
|
|
32
33
|
label: "Choice",
|
|
33
|
-
icon:
|
|
34
|
+
icon: _,
|
|
34
35
|
tone: "bg-status-warning-bg-subtle text-status-warning-text"
|
|
35
36
|
},
|
|
36
37
|
file: {
|
|
37
38
|
label: "File upload",
|
|
38
|
-
icon:
|
|
39
|
+
icon: S,
|
|
39
40
|
tone: "bg-status-warning-bg-subtle text-status-warning-text"
|
|
40
41
|
}
|
|
41
|
-
},
|
|
42
|
+
}, F = [
|
|
42
43
|
"text",
|
|
43
44
|
"textarea",
|
|
44
45
|
"number",
|
|
@@ -46,70 +47,70 @@ var M = {
|
|
|
46
47
|
"select",
|
|
47
48
|
"file"
|
|
48
49
|
];
|
|
49
|
-
function
|
|
50
|
-
return
|
|
50
|
+
function I(e) {
|
|
51
|
+
return a(e);
|
|
51
52
|
}
|
|
52
|
-
function
|
|
53
|
-
return
|
|
53
|
+
function L(e) {
|
|
54
|
+
return o(e);
|
|
54
55
|
}
|
|
55
|
-
function
|
|
56
|
-
let i =
|
|
56
|
+
function R(e, t, r) {
|
|
57
|
+
let i = n(e) || `field_${r + 1}`, a = i, o = 2, s = new Set(t.filter((e, t) => t !== r).map((e) => e.key));
|
|
57
58
|
for (; s.has(a);) a = `${i}-${o++}`;
|
|
58
59
|
return a;
|
|
59
60
|
}
|
|
60
|
-
function
|
|
61
|
+
function z(e) {
|
|
61
62
|
let t = new Set(e.map((e) => e.key));
|
|
62
63
|
return e.map((e) => e.showIf && !t.has(e.showIf.fieldKey) ? {
|
|
63
64
|
...e,
|
|
64
65
|
showIf: void 0
|
|
65
66
|
} : e);
|
|
66
67
|
}
|
|
67
|
-
var
|
|
68
|
-
function
|
|
69
|
-
let a = n.showIf?.fieldKey ??
|
|
70
|
-
return r.length === 0 ? null : /* @__PURE__ */
|
|
68
|
+
var B = "__none__";
|
|
69
|
+
function V({ groupId: e, index: t, field: n, priorFields: r, onChange: i }) {
|
|
70
|
+
let a = n.showIf?.fieldKey ?? B, o = r.find((e) => e.key === a);
|
|
71
|
+
return r.length === 0 ? null : /* @__PURE__ */ w("div", {
|
|
71
72
|
className: "grid gap-2 rounded-lg border border-dashed border-border-seam px-3 py-2.5",
|
|
72
73
|
children: [
|
|
73
|
-
/* @__PURE__ */
|
|
74
|
+
/* @__PURE__ */ w("div", {
|
|
74
75
|
className: "flex items-center gap-1.5 text-sm text-text-primary",
|
|
75
|
-
children: [/* @__PURE__ */
|
|
76
|
+
children: [/* @__PURE__ */ C(m, {
|
|
76
77
|
className: "h-3.5 w-3.5 text-text-muted",
|
|
77
78
|
"aria-hidden": "true"
|
|
78
79
|
}), "Show only if"]
|
|
79
80
|
}),
|
|
80
|
-
/* @__PURE__ */
|
|
81
|
+
/* @__PURE__ */ w("div", {
|
|
81
82
|
className: "grid gap-2 sm:grid-cols-2",
|
|
82
|
-
children: [/* @__PURE__ */
|
|
83
|
+
children: [/* @__PURE__ */ w(O, {
|
|
83
84
|
value: a,
|
|
84
|
-
onValueChange: (e) => i(e ===
|
|
85
|
+
onValueChange: (e) => i(e === B ? void 0 : {
|
|
85
86
|
fieldKey: e,
|
|
86
87
|
equals: ""
|
|
87
88
|
}),
|
|
88
|
-
children: [/* @__PURE__ */
|
|
89
|
+
children: [/* @__PURE__ */ C(j, {
|
|
89
90
|
"aria-label": `Condition field for ${n.label || "this field"}`,
|
|
90
|
-
children: /* @__PURE__ */
|
|
91
|
-
}), /* @__PURE__ */
|
|
92
|
-
value:
|
|
91
|
+
children: /* @__PURE__ */ C(M, { placeholder: "No condition" })
|
|
92
|
+
}), /* @__PURE__ */ w(k, { children: [/* @__PURE__ */ C(A, {
|
|
93
|
+
value: B,
|
|
93
94
|
children: "Always show"
|
|
94
|
-
}), r.map((e) => /* @__PURE__ */
|
|
95
|
+
}), r.map((e) => /* @__PURE__ */ C(A, {
|
|
95
96
|
value: e.key,
|
|
96
97
|
children: e.label || e.key
|
|
97
98
|
}, e.key))] })]
|
|
98
|
-
}), o && (o.type === "select" ? /* @__PURE__ */
|
|
99
|
+
}), o && (o.type === "select" ? /* @__PURE__ */ w(O, {
|
|
99
100
|
value: n.showIf?.equals ?? "",
|
|
100
101
|
onValueChange: (e) => i({
|
|
101
102
|
fieldKey: o.key,
|
|
102
103
|
equals: e
|
|
103
104
|
}),
|
|
104
|
-
children: [/* @__PURE__ */
|
|
105
|
+
children: [/* @__PURE__ */ C(j, {
|
|
105
106
|
id: `${e}-cond-val-${t}`,
|
|
106
107
|
"aria-label": "Required answer",
|
|
107
|
-
children: /* @__PURE__ */
|
|
108
|
-
}), /* @__PURE__ */
|
|
108
|
+
children: /* @__PURE__ */ C(M, { placeholder: "Equals…" })
|
|
109
|
+
}), /* @__PURE__ */ C(k, { children: (o.options ?? []).map((e) => /* @__PURE__ */ C(A, {
|
|
109
110
|
value: e,
|
|
110
111
|
children: e
|
|
111
112
|
}, e)) })]
|
|
112
|
-
}) : /* @__PURE__ */
|
|
113
|
+
}) : /* @__PURE__ */ C(E, {
|
|
113
114
|
id: `${e}-cond-val-${t}`,
|
|
114
115
|
"aria-label": "Required answer",
|
|
115
116
|
placeholder: "Equals this value…",
|
|
@@ -120,7 +121,7 @@ function z({ groupId: e, index: t, field: n, priorFields: r, onChange: i }) {
|
|
|
120
121
|
})
|
|
121
122
|
}))]
|
|
122
123
|
}),
|
|
123
|
-
o && /* @__PURE__ */
|
|
124
|
+
o && /* @__PURE__ */ w("p", {
|
|
124
125
|
className: "text-xs text-text-muted",
|
|
125
126
|
children: [
|
|
126
127
|
"“",
|
|
@@ -135,112 +136,113 @@ function z({ groupId: e, index: t, field: n, priorFields: r, onChange: i }) {
|
|
|
135
136
|
]
|
|
136
137
|
});
|
|
137
138
|
}
|
|
138
|
-
function
|
|
139
|
-
let s =
|
|
139
|
+
function H({ value: n, onChange: a, disabled: o = !1 }) {
|
|
140
|
+
let l = t(), u = s(), g = new Set(n.map((e) => i(e.section)).filter((e) => e !== void 0)), [_, x] = c(-1), [S, I] = c(null), [L, B] = c(null), H = (e) => a(z(e)), U = () => {
|
|
140
141
|
let e = {
|
|
141
142
|
key: "",
|
|
142
143
|
label: "",
|
|
143
144
|
type: "text",
|
|
144
145
|
required: !1
|
|
145
146
|
};
|
|
146
|
-
|
|
147
|
-
},
|
|
148
|
-
|
|
149
|
-
if (r !== e) return
|
|
147
|
+
H([...n, e]), x(n.length);
|
|
148
|
+
}, W = (e, t) => {
|
|
149
|
+
H(n.map((n, r) => {
|
|
150
|
+
if (r !== e) return n;
|
|
150
151
|
let i = {
|
|
151
|
-
...
|
|
152
|
-
...
|
|
152
|
+
...n,
|
|
153
|
+
...t
|
|
153
154
|
};
|
|
154
155
|
return i.type === "select" ? i.options ||= [] : delete i.options, i;
|
|
155
156
|
}));
|
|
156
|
-
},
|
|
157
|
-
|
|
158
|
-
},
|
|
159
|
-
if (
|
|
160
|
-
let r = [...
|
|
161
|
-
i && r.splice(
|
|
162
|
-
},
|
|
163
|
-
|
|
157
|
+
}, G = (e) => {
|
|
158
|
+
H(n.filter((t, n) => n !== e)), x((t) => t === e ? -1 : t > e ? t - 1 : t);
|
|
159
|
+
}, K = (e, t) => {
|
|
160
|
+
if (t < 0 || t >= n.length || e === t) return;
|
|
161
|
+
let r = [...n], [i] = r.splice(e, 1);
|
|
162
|
+
i && r.splice(t, 0, i), H(r), x((n) => n === e ? t : n);
|
|
163
|
+
}, q = (e) => {
|
|
164
|
+
S !== null && K(S, e), I(null), B(null);
|
|
164
165
|
};
|
|
165
|
-
return /* @__PURE__ */
|
|
166
|
+
return /* @__PURE__ */ w("div", {
|
|
166
167
|
className: "grid gap-2.5",
|
|
167
|
-
children: [/* @__PURE__ */
|
|
168
|
+
children: [/* @__PURE__ */ w("div", {
|
|
168
169
|
className: "flex items-center justify-between gap-3",
|
|
169
|
-
children: [/* @__PURE__ */
|
|
170
|
+
children: [/* @__PURE__ */ w("div", {
|
|
170
171
|
className: "flex items-baseline gap-2",
|
|
171
|
-
children: [/* @__PURE__ */
|
|
172
|
+
children: [/* @__PURE__ */ C(D, {
|
|
172
173
|
className: "text-sm",
|
|
173
174
|
children: "Application form fields"
|
|
174
|
-
}), /* @__PURE__ */
|
|
175
|
+
}), /* @__PURE__ */ C("span", {
|
|
175
176
|
className: "text-xs text-text-muted",
|
|
176
177
|
children: "Optional · drag to reorder"
|
|
177
178
|
})]
|
|
178
|
-
}), /* @__PURE__ */
|
|
179
|
+
}), /* @__PURE__ */ w(T, {
|
|
179
180
|
type: "button",
|
|
180
181
|
variant: "outline",
|
|
181
182
|
size: "sm",
|
|
182
|
-
onClick:
|
|
183
|
-
disabled:
|
|
183
|
+
onClick: U,
|
|
184
|
+
disabled: o,
|
|
184
185
|
"aria-label": "Add form field",
|
|
185
|
-
children: [/* @__PURE__ */
|
|
186
|
+
children: [/* @__PURE__ */ C(y, { className: "mr-1 h-4 w-4" }), " Add field"]
|
|
186
187
|
})]
|
|
187
|
-
}),
|
|
188
|
+
}), n.length === 0 ? /* @__PURE__ */ w("div", {
|
|
188
189
|
className: "rounded-xl border border-dashed border-border-seam bg-bg-sunken/40 px-4 py-6 text-center",
|
|
189
|
-
children: [/* @__PURE__ */
|
|
190
|
+
children: [/* @__PURE__ */ C("p", {
|
|
190
191
|
className: "text-sm text-text-secondary",
|
|
191
192
|
children: "No custom fields yet."
|
|
192
|
-
}), /* @__PURE__ */
|
|
193
|
+
}), /* @__PURE__ */ C("p", {
|
|
193
194
|
className: "mt-0.5 text-xs text-text-muted",
|
|
194
195
|
children: "Add fields citizens must fill when they apply (name, dates, choices, uploads…)."
|
|
195
196
|
})]
|
|
196
|
-
}) : /* @__PURE__ */
|
|
197
|
+
}) : /* @__PURE__ */ C("ul", {
|
|
197
198
|
className: "grid gap-2",
|
|
198
|
-
children:
|
|
199
|
-
let
|
|
200
|
-
return /* @__PURE__ */
|
|
201
|
-
draggable: !
|
|
202
|
-
onDragStart: () =>
|
|
199
|
+
children: n.map((t, a) => {
|
|
200
|
+
let s = P[t.type], c = s.icon, y = _ === a, z = L === a && S !== null && S !== a, H = i(t.section);
|
|
201
|
+
return /* @__PURE__ */ w("li", {
|
|
202
|
+
draggable: !o && !y,
|
|
203
|
+
onDragStart: () => I(a),
|
|
203
204
|
onDragOver: (e) => {
|
|
204
|
-
e.preventDefault(),
|
|
205
|
+
e.preventDefault(), B(a);
|
|
205
206
|
},
|
|
206
207
|
onDragEnd: () => {
|
|
207
|
-
|
|
208
|
+
I(null), B(null);
|
|
208
209
|
},
|
|
209
210
|
onDrop: (e) => {
|
|
210
|
-
e.preventDefault(),
|
|
211
|
+
e.preventDefault(), q(a);
|
|
211
212
|
},
|
|
212
|
-
className:
|
|
213
|
-
children: [/* @__PURE__ */
|
|
213
|
+
className: r("rounded-xl border bg-bg-surface transition-colors", z ? "border-action-primary-bg" : "border-border-seam", S === a && "opacity-60"),
|
|
214
|
+
children: [/* @__PURE__ */ w("div", {
|
|
214
215
|
className: "flex items-center gap-2 px-2.5 py-2",
|
|
215
216
|
children: [
|
|
216
|
-
/* @__PURE__ */
|
|
217
|
+
/* @__PURE__ */ C("span", {
|
|
217
218
|
"aria-hidden": "true",
|
|
218
|
-
className:
|
|
219
|
-
children: /* @__PURE__ */
|
|
219
|
+
className: r("hidden shrink-0 text-text-muted sm:inline-flex", !o && !y ? "cursor-grab" : "cursor-default"),
|
|
220
|
+
children: /* @__PURE__ */ C(h, { className: "h-4 w-4" })
|
|
220
221
|
}),
|
|
221
|
-
/* @__PURE__ */
|
|
222
|
-
className:
|
|
223
|
-
children: /* @__PURE__ */
|
|
222
|
+
/* @__PURE__ */ C("span", {
|
|
223
|
+
className: r("inline-flex size-8 shrink-0 items-center justify-center rounded-lg [&>svg]:size-4", s.tone),
|
|
224
|
+
children: /* @__PURE__ */ C(c, {})
|
|
224
225
|
}),
|
|
225
|
-
/* @__PURE__ */
|
|
226
|
+
/* @__PURE__ */ w("div", {
|
|
226
227
|
className: "min-w-0 flex-1",
|
|
227
|
-
children: [/* @__PURE__ */
|
|
228
|
+
children: [/* @__PURE__ */ w("p", {
|
|
228
229
|
className: "truncate text-sm font-medium text-text-primary",
|
|
229
|
-
children: [
|
|
230
|
+
children: [t.label || /* @__PURE__ */ C("span", {
|
|
230
231
|
className: "text-text-muted",
|
|
231
232
|
children: "Untitled field"
|
|
232
|
-
}),
|
|
233
|
+
}), t.required && /* @__PURE__ */ C("span", {
|
|
233
234
|
className: "ml-1 text-status-error-text",
|
|
234
235
|
children: "*"
|
|
235
236
|
})]
|
|
236
|
-
}), /* @__PURE__ */
|
|
237
|
+
}), /* @__PURE__ */ w("p", {
|
|
237
238
|
className: "truncate text-xs text-text-muted",
|
|
238
239
|
children: [
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
240
|
+
s.label,
|
|
241
|
+
t.type === "select" && t.options?.length ? ` · ${t.options.length} option${t.options.length === 1 ? "" : "s"}` : "",
|
|
242
|
+
H && /* @__PURE__ */ w("span", { children: [" · ", H] }),
|
|
243
|
+
t.showIf && /* @__PURE__ */ w("span", {
|
|
242
244
|
className: "ml-1 inline-flex items-center gap-0.5 text-[var(--color-accent-purple)]",
|
|
243
|
-
children: [/* @__PURE__ */
|
|
245
|
+
children: [/* @__PURE__ */ C(m, {
|
|
244
246
|
className: "inline size-3",
|
|
245
247
|
"aria-hidden": "true"
|
|
246
248
|
}), " conditional"]
|
|
@@ -248,120 +250,146 @@ function B({ value: t, onChange: r, disabled: i = !1 }) {
|
|
|
248
250
|
]
|
|
249
251
|
})]
|
|
250
252
|
}),
|
|
251
|
-
/* @__PURE__ */
|
|
253
|
+
/* @__PURE__ */ w("div", {
|
|
252
254
|
className: "flex shrink-0 items-center",
|
|
253
255
|
children: [
|
|
254
|
-
/* @__PURE__ */
|
|
256
|
+
/* @__PURE__ */ C(T, {
|
|
255
257
|
type: "button",
|
|
256
258
|
variant: "ghost",
|
|
257
259
|
size: "icon-sm",
|
|
258
|
-
onClick: () =>
|
|
259
|
-
disabled:
|
|
260
|
-
"aria-label": `Move ${
|
|
261
|
-
children: /* @__PURE__ */
|
|
260
|
+
onClick: () => K(a, a - 1),
|
|
261
|
+
disabled: o || a === 0,
|
|
262
|
+
"aria-label": `Move ${t.label || "field"} up`,
|
|
263
|
+
children: /* @__PURE__ */ C(p, { className: "h-4 w-4" })
|
|
262
264
|
}),
|
|
263
|
-
/* @__PURE__ */
|
|
265
|
+
/* @__PURE__ */ C(T, {
|
|
264
266
|
type: "button",
|
|
265
267
|
variant: "ghost",
|
|
266
268
|
size: "icon-sm",
|
|
267
|
-
onClick: () =>
|
|
268
|
-
disabled:
|
|
269
|
-
"aria-label": `Move ${
|
|
270
|
-
children: /* @__PURE__ */
|
|
269
|
+
onClick: () => K(a, a + 1),
|
|
270
|
+
disabled: o || a === n.length - 1,
|
|
271
|
+
"aria-label": `Move ${t.label || "field"} down`,
|
|
272
|
+
children: /* @__PURE__ */ C(f, { className: "h-4 w-4" })
|
|
271
273
|
}),
|
|
272
|
-
/* @__PURE__ */
|
|
274
|
+
/* @__PURE__ */ C(T, {
|
|
273
275
|
type: "button",
|
|
274
276
|
variant: "ghost",
|
|
275
277
|
size: "icon-sm",
|
|
276
|
-
onClick: () =>
|
|
277
|
-
disabled:
|
|
278
|
-
"aria-label":
|
|
279
|
-
"aria-expanded":
|
|
280
|
-
children:
|
|
278
|
+
onClick: () => x(y ? -1 : a),
|
|
279
|
+
disabled: o,
|
|
280
|
+
"aria-label": y ? "Close field editor" : `Edit ${t.label || "field"}`,
|
|
281
|
+
"aria-expanded": y,
|
|
282
|
+
children: C(y ? d : v, { className: "h-4 w-4" })
|
|
281
283
|
}),
|
|
282
|
-
/* @__PURE__ */
|
|
284
|
+
/* @__PURE__ */ C(T, {
|
|
283
285
|
type: "button",
|
|
284
286
|
variant: "ghost",
|
|
285
287
|
size: "icon-sm",
|
|
286
|
-
onClick: () =>
|
|
287
|
-
disabled:
|
|
288
|
-
"aria-label": `Remove ${
|
|
288
|
+
onClick: () => G(a),
|
|
289
|
+
disabled: o,
|
|
290
|
+
"aria-label": `Remove ${t.label || "field"}`,
|
|
289
291
|
className: "text-status-error-text hover:text-status-error-text",
|
|
290
|
-
children: /* @__PURE__ */
|
|
292
|
+
children: /* @__PURE__ */ C(b, { className: "h-4 w-4" })
|
|
291
293
|
})
|
|
292
294
|
]
|
|
293
295
|
})
|
|
294
296
|
]
|
|
295
|
-
}),
|
|
297
|
+
}), y && /* @__PURE__ */ w("div", {
|
|
296
298
|
className: "grid gap-3 border-t border-border-seam px-3 py-3",
|
|
297
299
|
children: [
|
|
298
|
-
/* @__PURE__ */
|
|
300
|
+
/* @__PURE__ */ w("div", {
|
|
299
301
|
className: "grid gap-3 sm:grid-cols-2",
|
|
300
|
-
children: [/* @__PURE__ */
|
|
302
|
+
children: [/* @__PURE__ */ w("div", {
|
|
301
303
|
className: "grid gap-1.5",
|
|
302
|
-
children: [/* @__PURE__ */
|
|
303
|
-
htmlFor: `${
|
|
304
|
+
children: [/* @__PURE__ */ C(D, {
|
|
305
|
+
htmlFor: `${u}-label-${a}`,
|
|
304
306
|
children: "Field label"
|
|
305
|
-
}), /* @__PURE__ */
|
|
306
|
-
id: `${
|
|
307
|
-
value:
|
|
307
|
+
}), /* @__PURE__ */ C(E, {
|
|
308
|
+
id: `${u}-label-${a}`,
|
|
309
|
+
value: t.label,
|
|
308
310
|
autoFocus: !0,
|
|
309
311
|
placeholder: "e.g. Business Name",
|
|
310
|
-
onChange: (e) =>
|
|
311
|
-
onBlur: () =>
|
|
312
|
+
onChange: (e) => W(a, { label: e.target.value }),
|
|
313
|
+
onBlur: () => W(a, { key: R(t.label, n, a) })
|
|
312
314
|
})]
|
|
313
|
-
}), /* @__PURE__ */
|
|
315
|
+
}), /* @__PURE__ */ w("div", {
|
|
314
316
|
className: "grid gap-1.5",
|
|
315
|
-
children: [/* @__PURE__ */
|
|
316
|
-
value:
|
|
317
|
-
onValueChange: (e) =>
|
|
318
|
-
children: [/* @__PURE__ */
|
|
317
|
+
children: [/* @__PURE__ */ C(D, { children: "Field type" }), /* @__PURE__ */ w(O, {
|
|
318
|
+
value: t.type,
|
|
319
|
+
onValueChange: (e) => W(a, { type: e }),
|
|
320
|
+
children: [/* @__PURE__ */ C(j, {
|
|
319
321
|
"aria-label": "Field type",
|
|
320
|
-
children: /* @__PURE__ */
|
|
321
|
-
}), /* @__PURE__ */
|
|
322
|
+
children: /* @__PURE__ */ C(M, {})
|
|
323
|
+
}), /* @__PURE__ */ C(k, { children: F.map((e) => /* @__PURE__ */ C(A, {
|
|
322
324
|
value: e,
|
|
323
|
-
children:
|
|
325
|
+
children: P[e].label
|
|
324
326
|
}, e)) })]
|
|
325
327
|
})]
|
|
326
328
|
})]
|
|
327
329
|
}),
|
|
328
|
-
|
|
330
|
+
/* @__PURE__ */ w("div", {
|
|
331
|
+
className: "grid gap-1.5",
|
|
332
|
+
children: [
|
|
333
|
+
/* @__PURE__ */ C(D, {
|
|
334
|
+
htmlFor: `${u}-section-${a}`,
|
|
335
|
+
children: l("govcitizenhub.services.formBuilder.section", "Section")
|
|
336
|
+
}),
|
|
337
|
+
/* @__PURE__ */ C(E, {
|
|
338
|
+
id: `${u}-section-${a}`,
|
|
339
|
+
list: `${u}-section-names`,
|
|
340
|
+
value: t.section ?? "",
|
|
341
|
+
disabled: o,
|
|
342
|
+
"aria-describedby": `${u}-section-help`,
|
|
343
|
+
onChange: (e) => W(a, { section: e.target.value })
|
|
344
|
+
}),
|
|
345
|
+
/* @__PURE__ */ C("datalist", {
|
|
346
|
+
id: `${u}-section-names`,
|
|
347
|
+
children: Array.from(g, (e) => /* @__PURE__ */ C("option", { value: e }, e))
|
|
348
|
+
}),
|
|
349
|
+
/* @__PURE__ */ C("p", {
|
|
350
|
+
id: `${u}-section-help`,
|
|
351
|
+
className: "text-xs text-text-muted",
|
|
352
|
+
children: l("govcitizenhub.services.formBuilder.sectionHelp", "Use the same section name for adjacent fields to group them, or leave it blank.")
|
|
353
|
+
})
|
|
354
|
+
]
|
|
355
|
+
}),
|
|
356
|
+
t.type === "select" && /* @__PURE__ */ w("div", {
|
|
329
357
|
className: "grid gap-1.5",
|
|
330
|
-
children: [/* @__PURE__ */
|
|
331
|
-
htmlFor: `${
|
|
358
|
+
children: [/* @__PURE__ */ C(D, {
|
|
359
|
+
htmlFor: `${u}-opts-${a}`,
|
|
332
360
|
children: "Choices"
|
|
333
|
-
}), /* @__PURE__ */
|
|
334
|
-
id: `${
|
|
335
|
-
value:
|
|
336
|
-
onChange: (e) =>
|
|
361
|
+
}), /* @__PURE__ */ C(e, {
|
|
362
|
+
id: `${u}-opts-${a}`,
|
|
363
|
+
value: t.options ?? [],
|
|
364
|
+
onChange: (e) => W(a, { options: e }),
|
|
337
365
|
placeholder: "Add a choice and press Enter…"
|
|
338
366
|
})]
|
|
339
367
|
}),
|
|
340
|
-
/* @__PURE__ */
|
|
368
|
+
/* @__PURE__ */ w("label", {
|
|
341
369
|
className: "flex items-center justify-between gap-3 rounded-lg bg-bg-sunken/50 px-3 py-2",
|
|
342
|
-
children: [/* @__PURE__ */
|
|
370
|
+
children: [/* @__PURE__ */ C("span", {
|
|
343
371
|
className: "text-sm text-text-primary",
|
|
344
372
|
children: "Required field"
|
|
345
|
-
}), /* @__PURE__ */
|
|
346
|
-
checked:
|
|
347
|
-
onCheckedChange: (e) =>
|
|
373
|
+
}), /* @__PURE__ */ C(N, {
|
|
374
|
+
checked: t.required,
|
|
375
|
+
onCheckedChange: (e) => W(a, { required: e }),
|
|
348
376
|
"aria-label": "Required field"
|
|
349
377
|
})]
|
|
350
378
|
}),
|
|
351
|
-
/* @__PURE__ */
|
|
352
|
-
groupId:
|
|
379
|
+
/* @__PURE__ */ C(V, {
|
|
380
|
+
groupId: u,
|
|
353
381
|
index: a,
|
|
354
|
-
field:
|
|
355
|
-
priorFields:
|
|
356
|
-
onChange: (e) =>
|
|
382
|
+
field: t,
|
|
383
|
+
priorFields: n.slice(0, a).filter((e) => e.key),
|
|
384
|
+
onChange: (e) => W(a, { showIf: e })
|
|
357
385
|
})
|
|
358
386
|
]
|
|
359
387
|
})]
|
|
360
|
-
}, `${
|
|
388
|
+
}, `${u}-${a}`);
|
|
361
389
|
})
|
|
362
390
|
})]
|
|
363
391
|
});
|
|
364
392
|
}
|
|
365
|
-
export {
|
|
393
|
+
export { H as FormFieldBuilder, L as fieldsToSchema, I as schemaToFields };
|
|
366
394
|
|
|
367
395
|
//# sourceMappingURL=FormFieldBuilder.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"FormFieldBuilder.js","names":["TYPE_META","Type","AlignLeft","Hash","Calendar","ListChecks","UploadCloud","TYPE_ORDER","schemaToFields","parseFormFields","schema","fieldsToSchema","serializeFormFields","fields","uniqueKey","base","slugify","label","selfIndex","candidate","n","taken","existing","i","f","pruneDanglingConditions","keys","NO_CONDITION","ConditionalRuleEditor","sourceKey","field","source","priorFields","GitBranch","Select","onChange","v","SelectTrigger","SelectValue","SelectContent","SelectItem","groupId","index","opt","Input","FormFieldBuilder","useId","editingIndex","setEditingIndex","useState","dragIndex","setDragIndex","overIndex","setOverIndex","commit","next","addField","value","updateField","merged","patch","removeField","cur","move","to","from","moved","onDrop","target","Label","Button","Plus","meta","Icon","isEditing","disabled","cn","GripVertical","ChevronUp","ChevronDown","jsx","Check","Pencil","Trash2","t","TagInput","opts","Switch","checked"],"sources":["../../../../src/govcitizenhub/pages/services/FormFieldBuilder.tsx"],"sourcesContent":["/**\n * FormFieldBuilder — a no-code builder for a service's application form fields.\n * @module govcitizenhub/pages/services\n *\n * Edits the ordered list of dynamic form fields that a citizen fills when applying\n * for a service. The output is written to the service `formSchema` JSON as a plain\n * ARRAY of field objects:\n *\n * [\n * { \"key\": \"business_name\", \"label\": \"Business Name\", \"type\": \"text\", \"required\": true },\n * { \"key\": \"turnover\", \"label\": \"Annual Turnover\", \"type\": \"number\", \"required\": false },\n * { \"key\": \"category\", \"label\": \"Category\", \"type\": \"select\", \"required\": true,\n * \"options\": [\"Retail\", \"Wholesale\"] },\n * { \"key\": \"gst_number\", \"label\": \"GST Number\", \"type\": \"text\", \"required\": true,\n * \"showIf\": { \"fieldKey\": \"category\", \"equals\": \"Wholesale\" } }\n * ]\n *\n * This is the EXACT shape `NewApplicationPage` normalises and renders (via the\n * shared {@link parseFormFields}/{@link isFieldVisible} helpers in\n * `utils/dynamicForm`), so a field added here — including a conditional\n * `showIf` eligibility rule (BOFF-4540) — shows up verbatim in the citizen\n * application form. `type` is one of text | textarea | number | date | select |\n * file; `options` applies to select.\n */\n\nimport { useId, useState, type DragEvent } from 'react';\nimport {\n Type,\n AlignLeft,\n Hash,\n Calendar,\n ListChecks,\n UploadCloud,\n GripVertical,\n Pencil,\n Trash2,\n Plus,\n Check,\n ChevronUp,\n ChevronDown,\n GitBranch,\n} from 'lucide-react';\nimport {\n Button,\n Input,\n Label,\n Switch,\n Select,\n SelectContent,\n SelectItem,\n SelectTrigger,\n SelectValue,\n} from '@burdenoff/fe-libs/ui';\n\nimport { TagInput } from '../../components/TagInput';\nimport { slugify } from '../../utils/formatters';\nimport { cn } from '../../utils/cn';\nimport {\n parseFormFields,\n serializeFormFields,\n type DynamicFieldCondition,\n type DynamicFieldType,\n type DynamicFormField,\n} from '../../utils/dynamicForm';\n\n/** The canonical field type set the citizen application renderer understands. */\nexport type BuilderFieldType = DynamicFieldType;\n\n/** Alias kept for call-site readability; identical shape to the shared DynamicFormField. */\nexport type BuilderField = DynamicFormField;\n\nconst TYPE_META: Record<BuilderFieldType, { label: string; icon: typeof Type; tone: string }> = {\n text: {\n label: 'Text',\n icon: Type,\n tone: 'bg-[var(--color-accent-soft)] text-action-primary-text',\n },\n textarea: {\n label: 'Paragraph',\n icon: AlignLeft,\n tone: 'bg-[var(--color-accent-soft)] text-action-primary-text',\n },\n number: {\n label: 'Number',\n icon: Hash,\n tone: 'bg-status-success-bg-subtle text-status-success-text',\n },\n date: {\n label: 'Date',\n icon: Calendar,\n tone: 'bg-[color-mix(in_oklab,var(--color-accent-purple)_16%,transparent)] text-[var(--color-accent-purple)]',\n },\n select: {\n label: 'Choice',\n icon: ListChecks,\n tone: 'bg-status-warning-bg-subtle text-status-warning-text',\n },\n file: {\n label: 'File upload',\n icon: UploadCloud,\n tone: 'bg-status-warning-bg-subtle text-status-warning-text',\n },\n};\n\nconst TYPE_ORDER: BuilderFieldType[] = ['text', 'textarea', 'number', 'date', 'select', 'file'];\n\ninterface FormFieldBuilderProps {\n value: BuilderField[];\n onChange: (fields: BuilderField[]) => void;\n disabled?: boolean;\n}\n\n/**\n * Coerce an opaque `formSchema` JSON into the editable BuilderField[] shape. Kept\n * tolerant so a service authored elsewhere (or as a json-schema `{ properties }`)\n * still opens cleanly in the builder. Delegates to the shared {@link parseFormFields}\n * so the builder and the citizen-facing renderer never drift on what a schema means.\n */\nexport function schemaToFields(schema: unknown): BuilderField[] {\n return parseFormFields(schema);\n}\n\n/** Serialise BuilderField[] to the array `formSchema` payload (or null when empty). */\nexport function fieldsToSchema(fields: BuilderField[]): BuilderField[] | null {\n return serializeFormFields(fields);\n}\n\n/** Ensure a unique machine key derived from the label. */\nfunction uniqueKey(label: string, existing: BuilderField[], selfIndex: number): string {\n const base = slugify(label) || `field_${selfIndex + 1}`;\n let candidate = base;\n let n = 2;\n const taken = new Set(existing.filter((_, i) => i !== selfIndex).map((f) => f.key));\n while (taken.has(candidate)) candidate = `${base}-${n++}`;\n return candidate;\n}\n\n/** Drop any `showIf` that points at a field key no longer present (e.g. after a remove/rename). */\nfunction pruneDanglingConditions(fields: BuilderField[]): BuilderField[] {\n const keys = new Set(fields.map((f) => f.key));\n return fields.map((f) =>\n f.showIf && !keys.has(f.showIf.fieldKey) ? { ...f, showIf: undefined } : f\n );\n}\n\nconst NO_CONDITION = '__none__';\n\n/**\n * Eligibility/conditional-visibility editor (BOFF-4540): lets an author say\n * \"only show this field when an earlier field equals a given answer\" —\n * persisted as `field.showIf`. Only fields positioned before the field being\n * edited (and already given a real key) are offered as the dependency, which\n * keeps authoring simple and prevents the builder itself from creating a\n * circular dependency.\n */\nfunction ConditionalRuleEditor({\n groupId,\n index,\n field,\n priorFields,\n onChange,\n}: {\n groupId: string;\n index: number;\n field: BuilderField;\n priorFields: BuilderField[];\n onChange: (showIf: DynamicFieldCondition | undefined) => void;\n}) {\n const sourceKey = field.showIf?.fieldKey ?? NO_CONDITION;\n const source = priorFields.find((f) => f.key === sourceKey);\n\n if (priorFields.length === 0) return null;\n\n return (\n <div className=\"grid gap-2 rounded-lg border border-dashed border-border-seam px-3 py-2.5\">\n <div className=\"flex items-center gap-1.5 text-sm text-text-primary\">\n <GitBranch className=\"h-3.5 w-3.5 text-text-muted\" aria-hidden=\"true\" />\n Show only if\n </div>\n <div className=\"grid gap-2 sm:grid-cols-2\">\n <Select\n value={sourceKey}\n onValueChange={(v) =>\n onChange(v === NO_CONDITION ? undefined : { fieldKey: v, equals: '' })\n }\n >\n <SelectTrigger aria-label={`Condition field for ${field.label || 'this field'}`}>\n <SelectValue placeholder=\"No condition\" />\n </SelectTrigger>\n <SelectContent>\n <SelectItem value={NO_CONDITION}>Always show</SelectItem>\n {priorFields.map((f) => (\n <SelectItem key={f.key} value={f.key}>\n {f.label || f.key}\n </SelectItem>\n ))}\n </SelectContent>\n </Select>\n\n {source &&\n (source.type === 'select' ? (\n <Select\n value={field.showIf?.equals ?? ''}\n onValueChange={(v) => onChange({ fieldKey: source.key, equals: v })}\n >\n <SelectTrigger id={`${groupId}-cond-val-${index}`} aria-label=\"Required answer\">\n <SelectValue placeholder=\"Equals…\" />\n </SelectTrigger>\n <SelectContent>\n {(source.options ?? []).map((opt) => (\n <SelectItem key={opt} value={opt}>\n {opt}\n </SelectItem>\n ))}\n </SelectContent>\n </Select>\n ) : (\n <Input\n id={`${groupId}-cond-val-${index}`}\n aria-label=\"Required answer\"\n placeholder=\"Equals this value…\"\n value={field.showIf?.equals ?? ''}\n onChange={(e) => onChange({ fieldKey: source.key, equals: e.target.value })}\n />\n ))}\n </div>\n {source && (\n <p className=\"text-xs text-text-muted\">\n “{field.label || 'This field'}” only appears once “\n {source.label || source.key}” is answered “\n {field.showIf?.equals || '…'}”.\n </p>\n )}\n </div>\n );\n}\n\nexport function FormFieldBuilder({ value, onChange, disabled = false }: FormFieldBuilderProps) {\n const groupId = useId();\n const [editingIndex, setEditingIndex] = useState<number>(-1);\n const [dragIndex, setDragIndex] = useState<number | null>(null);\n const [overIndex, setOverIndex] = useState<number | null>(null);\n\n // Every commit prunes `showIf` conditions that no longer point at a real field key —\n // covers removal and label-driven key renames (the key is only finalised on blur) so a\n // condition can never silently reference a key that no longer exists.\n const commit = (next: BuilderField[]) => onChange(pruneDanglingConditions(next));\n\n const addField = () => {\n const next: BuilderField = { key: '', label: '', type: 'text', required: false };\n commit([...value, next]);\n setEditingIndex(value.length);\n };\n\n const updateField = (index: number, patch: Partial<BuilderField>) => {\n commit(\n value.map((f, i) => {\n if (i !== index) return f;\n const merged = { ...f, ...patch };\n if (merged.type !== 'select') delete merged.options;\n else if (!merged.options) merged.options = [];\n return merged;\n })\n );\n };\n\n const removeField = (index: number) => {\n commit(value.filter((_, i) => i !== index));\n setEditingIndex((cur) => (cur === index ? -1 : cur > index ? cur - 1 : cur));\n };\n\n const move = (from: number, to: number) => {\n if (to < 0 || to >= value.length || from === to) return;\n const next = [...value];\n const [moved] = next.splice(from, 1);\n if (moved) next.splice(to, 0, moved);\n commit(next);\n setEditingIndex((cur) => (cur === from ? to : cur));\n };\n\n const onDrop = (target: number) => {\n if (dragIndex !== null) move(dragIndex, target);\n setDragIndex(null);\n setOverIndex(null);\n };\n\n return (\n <div className=\"grid gap-2.5\">\n <div className=\"flex items-center justify-between gap-3\">\n <div className=\"flex items-baseline gap-2\">\n <Label className=\"text-sm\">Application form fields</Label>\n <span className=\"text-xs text-text-muted\">Optional · drag to reorder</span>\n </div>\n <Button\n type=\"button\"\n variant=\"outline\"\n size=\"sm\"\n onClick={addField}\n disabled={disabled}\n aria-label=\"Add form field\"\n >\n <Plus className=\"mr-1 h-4 w-4\" /> Add field\n </Button>\n </div>\n\n {value.length === 0 ? (\n <div className=\"rounded-xl border border-dashed border-border-seam bg-bg-sunken/40 px-4 py-6 text-center\">\n <p className=\"text-sm text-text-secondary\">No custom fields yet.</p>\n <p className=\"mt-0.5 text-xs text-text-muted\">\n Add fields citizens must fill when they apply (name, dates, choices, uploads…).\n </p>\n </div>\n ) : (\n <ul className=\"grid gap-2\">\n {value.map((field, index) => {\n const meta = TYPE_META[field.type];\n const Icon = meta.icon;\n const isEditing = editingIndex === index;\n const isOver = overIndex === index && dragIndex !== null && dragIndex !== index;\n return (\n <li\n key={`${groupId}-${index}`}\n draggable={!disabled && !isEditing}\n onDragStart={() => setDragIndex(index)}\n onDragOver={(e: DragEvent) => {\n e.preventDefault();\n setOverIndex(index);\n }}\n onDragEnd={() => {\n setDragIndex(null);\n setOverIndex(null);\n }}\n onDrop={(e) => {\n e.preventDefault();\n onDrop(index);\n }}\n className={cn(\n 'rounded-xl border bg-bg-surface transition-colors',\n isOver ? 'border-action-primary-bg' : 'border-border-seam',\n dragIndex === index && 'opacity-60'\n )}\n >\n {/* Summary row */}\n <div className=\"flex items-center gap-2 px-2.5 py-2\">\n <span\n aria-hidden=\"true\"\n className={cn(\n 'hidden shrink-0 text-text-muted sm:inline-flex',\n !disabled && !isEditing ? 'cursor-grab' : 'cursor-default'\n )}\n >\n <GripVertical className=\"h-4 w-4\" />\n </span>\n <span\n className={cn(\n 'inline-flex size-8 shrink-0 items-center justify-center rounded-lg [&>svg]:size-4',\n meta.tone\n )}\n >\n <Icon />\n </span>\n <div className=\"min-w-0 flex-1\">\n <p className=\"truncate text-sm font-medium text-text-primary\">\n {field.label || <span className=\"text-text-muted\">Untitled field</span>}\n {field.required && <span className=\"ml-1 text-status-error-text\">*</span>}\n </p>\n <p className=\"truncate text-xs text-text-muted\">\n {meta.label}\n {field.type === 'select' && field.options?.length\n ? ` · ${field.options.length} option${field.options.length === 1 ? '' : 's'}`\n : ''}\n {field.showIf && (\n <span className=\"ml-1 inline-flex items-center gap-0.5 text-[var(--color-accent-purple)]\">\n <GitBranch className=\"inline size-3\" aria-hidden=\"true\" /> conditional\n </span>\n )}\n </p>\n </div>\n <div className=\"flex shrink-0 items-center\">\n <Button\n type=\"button\"\n variant=\"ghost\"\n size=\"icon-sm\"\n onClick={() => move(index, index - 1)}\n disabled={disabled || index === 0}\n aria-label={`Move ${field.label || 'field'} up`}\n >\n <ChevronUp className=\"h-4 w-4\" />\n </Button>\n <Button\n type=\"button\"\n variant=\"ghost\"\n size=\"icon-sm\"\n onClick={() => move(index, index + 1)}\n disabled={disabled || index === value.length - 1}\n aria-label={`Move ${field.label || 'field'} down`}\n >\n <ChevronDown className=\"h-4 w-4\" />\n </Button>\n <Button\n type=\"button\"\n variant=\"ghost\"\n size=\"icon-sm\"\n onClick={() => setEditingIndex(isEditing ? -1 : index)}\n disabled={disabled}\n aria-label={\n isEditing ? 'Close field editor' : `Edit ${field.label || 'field'}`\n }\n aria-expanded={isEditing}\n >\n {isEditing ? <Check className=\"h-4 w-4\" /> : <Pencil className=\"h-4 w-4\" />}\n </Button>\n <Button\n type=\"button\"\n variant=\"ghost\"\n size=\"icon-sm\"\n onClick={() => removeField(index)}\n disabled={disabled}\n aria-label={`Remove ${field.label || 'field'}`}\n className=\"text-status-error-text hover:text-status-error-text\"\n >\n <Trash2 className=\"h-4 w-4\" />\n </Button>\n </div>\n </div>\n\n {/* Inline editor */}\n {isEditing && (\n <div className=\"grid gap-3 border-t border-border-seam px-3 py-3\">\n <div className=\"grid gap-3 sm:grid-cols-2\">\n <div className=\"grid gap-1.5\">\n <Label htmlFor={`${groupId}-label-${index}`}>Field label</Label>\n <Input\n id={`${groupId}-label-${index}`}\n value={field.label}\n autoFocus\n placeholder=\"e.g. Business Name\"\n onChange={(e) => updateField(index, { label: e.target.value })}\n onBlur={() =>\n updateField(index, { key: uniqueKey(field.label, value, index) })\n }\n />\n </div>\n <div className=\"grid gap-1.5\">\n <Label>Field type</Label>\n <Select\n value={field.type}\n onValueChange={(v) => updateField(index, { type: v as BuilderFieldType })}\n >\n <SelectTrigger aria-label=\"Field type\">\n <SelectValue />\n </SelectTrigger>\n <SelectContent>\n {TYPE_ORDER.map((t) => (\n <SelectItem key={t} value={t}>\n {TYPE_META[t].label}\n </SelectItem>\n ))}\n </SelectContent>\n </Select>\n </div>\n </div>\n\n {field.type === 'select' && (\n <div className=\"grid gap-1.5\">\n <Label htmlFor={`${groupId}-opts-${index}`}>Choices</Label>\n <TagInput\n id={`${groupId}-opts-${index}`}\n value={field.options ?? []}\n onChange={(opts) => updateField(index, { options: opts })}\n placeholder=\"Add a choice and press Enter…\"\n />\n </div>\n )}\n\n <label className=\"flex items-center justify-between gap-3 rounded-lg bg-bg-sunken/50 px-3 py-2\">\n <span className=\"text-sm text-text-primary\">Required field</span>\n <Switch\n checked={field.required}\n onCheckedChange={(checked) => updateField(index, { required: checked })}\n aria-label=\"Required field\"\n />\n </label>\n\n <ConditionalRuleEditor\n groupId={groupId}\n index={index}\n field={field}\n priorFields={value.slice(0, index).filter((f) => f.key)}\n onChange={(showIf) => updateField(index, { showIf })}\n />\n </div>\n )}\n </li>\n );\n })}\n </ul>\n )}\n </div>\n );\n}\n"],"mappings":";;;;;;;;;AAuEA,IAAMA,IAA0F;CAC9F,MAAM;EACJ,OAAO;EACP,MAAMC;EACN,MAAM;CACR;CACA,UAAU;EACR,OAAO;EACP,MAAMC;EACN,MAAM;CACR;CACA,QAAQ;EACN,OAAO;EACP,MAAMC;EACN,MAAM;CACR;CACA,MAAM;EACJ,OAAO;EACP,MAAMC;EACN,MAAM;CACR;CACA,QAAQ;EACN,OAAO;EACP,MAAMC;EACN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;EACC,CAAA,CAEH;;AAET"}
|
|
1
|
+
{"version":3,"file":"FormFieldBuilder.js","names":["TYPE_META","Type","AlignLeft","Hash","Calendar","ListChecks","UploadCloud","TYPE_ORDER","schemaToFields","parseFormFields","schema","fieldsToSchema","serializeFormFields","fields","uniqueKey","base","slugify","label","selfIndex","candidate","n","taken","existing","i","f","pruneDanglingConditions","keys","NO_CONDITION","ConditionalRuleEditor","sourceKey","field","source","priorFields","GitBranch","Select","onChange","v","SelectTrigger","SelectValue","SelectContent","SelectItem","groupId","index","opt","Input","FormFieldBuilder","tr","useTr","useId","sectionNames","value","normalizeFormSection","section","editingIndex","setEditingIndex","useState","dragIndex","setDragIndex","overIndex","setOverIndex","commit","next","addField","updateField","merged","patch","removeField","cur","move","to","from","moved","onDrop","target","Label","Button","Plus","meta","Icon","isEditing","isOver","disabled","cn","GripVertical","ChevronUp","ChevronDown","jsx","Check","Pencil","Trash2","t","name","TagInput","opts","Switch","checked"],"sources":["../../../../src/govcitizenhub/pages/services/FormFieldBuilder.tsx"],"sourcesContent":["/**\n * FormFieldBuilder — a no-code builder for a service's application form fields.\n * @module govcitizenhub/pages/services\n *\n * Edits the ordered list of dynamic form fields that a citizen fills when applying\n * for a service. The output is written to the service `formSchema` JSON as a plain\n * ARRAY of field objects:\n *\n * [\n * { \"key\": \"business_name\", \"label\": \"Business Name\", \"type\": \"text\", \"required\": true },\n * { \"key\": \"turnover\", \"label\": \"Annual Turnover\", \"type\": \"number\", \"required\": false },\n * { \"key\": \"category\", \"label\": \"Category\", \"type\": \"select\", \"required\": true,\n * \"options\": [\"Retail\", \"Wholesale\"] },\n * { \"key\": \"gst_number\", \"label\": \"GST Number\", \"type\": \"text\", \"required\": true,\n * \"showIf\": { \"fieldKey\": \"category\", \"equals\": \"Wholesale\" } }\n * ]\n *\n * This is the EXACT shape `NewApplicationPage` normalises and renders (via the\n * shared {@link parseFormFields}/{@link isFieldVisible} helpers in\n * `utils/dynamicForm`), so a field added here — including a conditional\n * `showIf` eligibility rule (BOFF-4540) — shows up verbatim in the citizen\n * application form. `type` is one of text | textarea | number | date | select |\n * file; `options` applies to select.\n */\n\nimport { useId, useState, type DragEvent } from 'react';\nimport {\n Type,\n AlignLeft,\n Hash,\n Calendar,\n ListChecks,\n UploadCloud,\n GripVertical,\n Pencil,\n Trash2,\n Plus,\n Check,\n ChevronUp,\n ChevronDown,\n GitBranch,\n} from 'lucide-react';\nimport {\n Button,\n Input,\n Label,\n Switch,\n Select,\n SelectContent,\n SelectItem,\n SelectTrigger,\n SelectValue,\n} from '@burdenoff/fe-libs/ui';\n\nimport { TagInput } from '../../components/TagInput';\nimport { useTr } from '../../../shared/hooks/useTr';\nimport { slugify } from '../../utils/formatters';\nimport { cn } from '../../utils/cn';\nimport {\n normalizeFormSection,\n parseFormFields,\n serializeFormFields,\n type DynamicFieldCondition,\n type DynamicFieldType,\n type DynamicFormField,\n} from '../../utils/dynamicForm';\n\n/** The canonical field type set the citizen application renderer understands. */\nexport type BuilderFieldType = DynamicFieldType;\n\n/** Alias kept for call-site readability; identical shape to the shared DynamicFormField. */\nexport type BuilderField = DynamicFormField;\n\nconst TYPE_META: Record<BuilderFieldType, { label: string; icon: typeof Type; tone: string }> = {\n text: {\n label: 'Text',\n icon: Type,\n tone: 'bg-[var(--color-accent-soft)] text-action-primary-text',\n },\n textarea: {\n label: 'Paragraph',\n icon: AlignLeft,\n tone: 'bg-[var(--color-accent-soft)] text-action-primary-text',\n },\n number: {\n label: 'Number',\n icon: Hash,\n tone: 'bg-status-success-bg-subtle text-status-success-text',\n },\n date: {\n label: 'Date',\n icon: Calendar,\n tone: 'bg-[color-mix(in_oklab,var(--color-accent-purple)_16%,transparent)] text-[var(--color-accent-purple)]',\n },\n select: {\n label: 'Choice',\n icon: ListChecks,\n tone: 'bg-status-warning-bg-subtle text-status-warning-text',\n },\n file: {\n label: 'File upload',\n icon: UploadCloud,\n tone: 'bg-status-warning-bg-subtle text-status-warning-text',\n },\n};\n\nconst TYPE_ORDER: BuilderFieldType[] = ['text', 'textarea', 'number', 'date', 'select', 'file'];\n\ninterface FormFieldBuilderProps {\n value: BuilderField[];\n onChange: (fields: BuilderField[]) => void;\n disabled?: boolean;\n}\n\n/**\n * Coerce an opaque `formSchema` JSON into the editable BuilderField[] shape. Kept\n * tolerant so a service authored elsewhere (or as a json-schema `{ properties }`)\n * still opens cleanly in the builder. Delegates to the shared {@link parseFormFields}\n * so the builder and the citizen-facing renderer never drift on what a schema means.\n */\nexport function schemaToFields(schema: unknown): BuilderField[] {\n return parseFormFields(schema);\n}\n\n/** Serialise BuilderField[] to the array `formSchema` payload (or null when empty). */\nexport function fieldsToSchema(fields: BuilderField[]): BuilderField[] | null {\n return serializeFormFields(fields);\n}\n\n/** Ensure a unique machine key derived from the label. */\nfunction uniqueKey(label: string, existing: BuilderField[], selfIndex: number): string {\n const base = slugify(label) || `field_${selfIndex + 1}`;\n let candidate = base;\n let n = 2;\n const taken = new Set(existing.filter((_, i) => i !== selfIndex).map((f) => f.key));\n while (taken.has(candidate)) candidate = `${base}-${n++}`;\n return candidate;\n}\n\n/** Drop any `showIf` that points at a field key no longer present (e.g. after a remove/rename). */\nfunction pruneDanglingConditions(fields: BuilderField[]): BuilderField[] {\n const keys = new Set(fields.map((f) => f.key));\n return fields.map((f) =>\n f.showIf && !keys.has(f.showIf.fieldKey) ? { ...f, showIf: undefined } : f\n );\n}\n\nconst NO_CONDITION = '__none__';\n\n/**\n * Eligibility/conditional-visibility editor (BOFF-4540): lets an author say\n * \"only show this field when an earlier field equals a given answer\" —\n * persisted as `field.showIf`. Only fields positioned before the field being\n * edited (and already given a real key) are offered as the dependency, which\n * keeps authoring simple and prevents the builder itself from creating a\n * circular dependency.\n */\nfunction ConditionalRuleEditor({\n groupId,\n index,\n field,\n priorFields,\n onChange,\n}: {\n groupId: string;\n index: number;\n field: BuilderField;\n priorFields: BuilderField[];\n onChange: (showIf: DynamicFieldCondition | undefined) => void;\n}) {\n const sourceKey = field.showIf?.fieldKey ?? NO_CONDITION;\n const source = priorFields.find((f) => f.key === sourceKey);\n\n if (priorFields.length === 0) return null;\n\n return (\n <div className=\"grid gap-2 rounded-lg border border-dashed border-border-seam px-3 py-2.5\">\n <div className=\"flex items-center gap-1.5 text-sm text-text-primary\">\n <GitBranch className=\"h-3.5 w-3.5 text-text-muted\" aria-hidden=\"true\" />\n Show only if\n </div>\n <div className=\"grid gap-2 sm:grid-cols-2\">\n <Select\n value={sourceKey}\n onValueChange={(v) =>\n onChange(v === NO_CONDITION ? undefined : { fieldKey: v, equals: '' })\n }\n >\n <SelectTrigger aria-label={`Condition field for ${field.label || 'this field'}`}>\n <SelectValue placeholder=\"No condition\" />\n </SelectTrigger>\n <SelectContent>\n <SelectItem value={NO_CONDITION}>Always show</SelectItem>\n {priorFields.map((f) => (\n <SelectItem key={f.key} value={f.key}>\n {f.label || f.key}\n </SelectItem>\n ))}\n </SelectContent>\n </Select>\n\n {source &&\n (source.type === 'select' ? (\n <Select\n value={field.showIf?.equals ?? ''}\n onValueChange={(v) => onChange({ fieldKey: source.key, equals: v })}\n >\n <SelectTrigger id={`${groupId}-cond-val-${index}`} aria-label=\"Required answer\">\n <SelectValue placeholder=\"Equals…\" />\n </SelectTrigger>\n <SelectContent>\n {(source.options ?? []).map((opt) => (\n <SelectItem key={opt} value={opt}>\n {opt}\n </SelectItem>\n ))}\n </SelectContent>\n </Select>\n ) : (\n <Input\n id={`${groupId}-cond-val-${index}`}\n aria-label=\"Required answer\"\n placeholder=\"Equals this value…\"\n value={field.showIf?.equals ?? ''}\n onChange={(e) => onChange({ fieldKey: source.key, equals: e.target.value })}\n />\n ))}\n </div>\n {source && (\n <p className=\"text-xs text-text-muted\">\n “{field.label || 'This field'}” only appears once “\n {source.label || source.key}” is answered “\n {field.showIf?.equals || '…'}”.\n </p>\n )}\n </div>\n );\n}\n\nexport function FormFieldBuilder({ value, onChange, disabled = false }: FormFieldBuilderProps) {\n const tr = useTr();\n const groupId = useId();\n const sectionNames = new Set(\n value\n .map((field) => normalizeFormSection(field.section))\n .filter((section) => section !== undefined)\n );\n const [editingIndex, setEditingIndex] = useState<number>(-1);\n const [dragIndex, setDragIndex] = useState<number | null>(null);\n const [overIndex, setOverIndex] = useState<number | null>(null);\n\n // Every commit prunes `showIf` conditions that no longer point at a real field key —\n // covers removal and label-driven key renames (the key is only finalised on blur) so a\n // condition can never silently reference a key that no longer exists.\n const commit = (next: BuilderField[]) => onChange(pruneDanglingConditions(next));\n\n const addField = () => {\n const next: BuilderField = { key: '', label: '', type: 'text', required: false };\n commit([...value, next]);\n setEditingIndex(value.length);\n };\n\n const updateField = (index: number, patch: Partial<BuilderField>) => {\n commit(\n value.map((f, i) => {\n if (i !== index) return f;\n const merged = { ...f, ...patch };\n if (merged.type !== 'select') delete merged.options;\n else if (!merged.options) merged.options = [];\n return merged;\n })\n );\n };\n\n const removeField = (index: number) => {\n commit(value.filter((_, i) => i !== index));\n setEditingIndex((cur) => (cur === index ? -1 : cur > index ? cur - 1 : cur));\n };\n\n const move = (from: number, to: number) => {\n if (to < 0 || to >= value.length || from === to) return;\n const next = [...value];\n const [moved] = next.splice(from, 1);\n if (moved) next.splice(to, 0, moved);\n commit(next);\n setEditingIndex((cur) => (cur === from ? to : cur));\n };\n\n const onDrop = (target: number) => {\n if (dragIndex !== null) move(dragIndex, target);\n setDragIndex(null);\n setOverIndex(null);\n };\n\n return (\n <div className=\"grid gap-2.5\">\n <div className=\"flex items-center justify-between gap-3\">\n <div className=\"flex items-baseline gap-2\">\n <Label className=\"text-sm\">Application form fields</Label>\n <span className=\"text-xs text-text-muted\">Optional · drag to reorder</span>\n </div>\n <Button\n type=\"button\"\n variant=\"outline\"\n size=\"sm\"\n onClick={addField}\n disabled={disabled}\n aria-label=\"Add form field\"\n >\n <Plus className=\"mr-1 h-4 w-4\" /> Add field\n </Button>\n </div>\n\n {value.length === 0 ? (\n <div className=\"rounded-xl border border-dashed border-border-seam bg-bg-sunken/40 px-4 py-6 text-center\">\n <p className=\"text-sm text-text-secondary\">No custom fields yet.</p>\n <p className=\"mt-0.5 text-xs text-text-muted\">\n Add fields citizens must fill when they apply (name, dates, choices, uploads…).\n </p>\n </div>\n ) : (\n <ul className=\"grid gap-2\">\n {value.map((field, index) => {\n const meta = TYPE_META[field.type];\n const Icon = meta.icon;\n const isEditing = editingIndex === index;\n const isOver = overIndex === index && dragIndex !== null && dragIndex !== index;\n const section = normalizeFormSection(field.section);\n return (\n <li\n key={`${groupId}-${index}`}\n draggable={!disabled && !isEditing}\n onDragStart={() => setDragIndex(index)}\n onDragOver={(e: DragEvent) => {\n e.preventDefault();\n setOverIndex(index);\n }}\n onDragEnd={() => {\n setDragIndex(null);\n setOverIndex(null);\n }}\n onDrop={(e) => {\n e.preventDefault();\n onDrop(index);\n }}\n className={cn(\n 'rounded-xl border bg-bg-surface transition-colors',\n isOver ? 'border-action-primary-bg' : 'border-border-seam',\n dragIndex === index && 'opacity-60'\n )}\n >\n {/* Summary row */}\n <div className=\"flex items-center gap-2 px-2.5 py-2\">\n <span\n aria-hidden=\"true\"\n className={cn(\n 'hidden shrink-0 text-text-muted sm:inline-flex',\n !disabled && !isEditing ? 'cursor-grab' : 'cursor-default'\n )}\n >\n <GripVertical className=\"h-4 w-4\" />\n </span>\n <span\n className={cn(\n 'inline-flex size-8 shrink-0 items-center justify-center rounded-lg [&>svg]:size-4',\n meta.tone\n )}\n >\n <Icon />\n </span>\n <div className=\"min-w-0 flex-1\">\n <p className=\"truncate text-sm font-medium text-text-primary\">\n {field.label || <span className=\"text-text-muted\">Untitled field</span>}\n {field.required && <span className=\"ml-1 text-status-error-text\">*</span>}\n </p>\n <p className=\"truncate text-xs text-text-muted\">\n {meta.label}\n {field.type === 'select' && field.options?.length\n ? ` · ${field.options.length} option${field.options.length === 1 ? '' : 's'}`\n : ''}\n {section && <span> · {section}</span>}\n {field.showIf && (\n <span className=\"ml-1 inline-flex items-center gap-0.5 text-[var(--color-accent-purple)]\">\n <GitBranch className=\"inline size-3\" aria-hidden=\"true\" /> conditional\n </span>\n )}\n </p>\n </div>\n <div className=\"flex shrink-0 items-center\">\n <Button\n type=\"button\"\n variant=\"ghost\"\n size=\"icon-sm\"\n onClick={() => move(index, index - 1)}\n disabled={disabled || index === 0}\n aria-label={`Move ${field.label || 'field'} up`}\n >\n <ChevronUp className=\"h-4 w-4\" />\n </Button>\n <Button\n type=\"button\"\n variant=\"ghost\"\n size=\"icon-sm\"\n onClick={() => move(index, index + 1)}\n disabled={disabled || index === value.length - 1}\n aria-label={`Move ${field.label || 'field'} down`}\n >\n <ChevronDown className=\"h-4 w-4\" />\n </Button>\n <Button\n type=\"button\"\n variant=\"ghost\"\n size=\"icon-sm\"\n onClick={() => setEditingIndex(isEditing ? -1 : index)}\n disabled={disabled}\n aria-label={\n isEditing ? 'Close field editor' : `Edit ${field.label || 'field'}`\n }\n aria-expanded={isEditing}\n >\n {isEditing ? <Check className=\"h-4 w-4\" /> : <Pencil className=\"h-4 w-4\" />}\n </Button>\n <Button\n type=\"button\"\n variant=\"ghost\"\n size=\"icon-sm\"\n onClick={() => removeField(index)}\n disabled={disabled}\n aria-label={`Remove ${field.label || 'field'}`}\n className=\"text-status-error-text hover:text-status-error-text\"\n >\n <Trash2 className=\"h-4 w-4\" />\n </Button>\n </div>\n </div>\n\n {/* Inline editor */}\n {isEditing && (\n <div className=\"grid gap-3 border-t border-border-seam px-3 py-3\">\n <div className=\"grid gap-3 sm:grid-cols-2\">\n <div className=\"grid gap-1.5\">\n <Label htmlFor={`${groupId}-label-${index}`}>Field label</Label>\n <Input\n id={`${groupId}-label-${index}`}\n value={field.label}\n autoFocus\n placeholder=\"e.g. Business Name\"\n onChange={(e) => updateField(index, { label: e.target.value })}\n onBlur={() =>\n updateField(index, { key: uniqueKey(field.label, value, index) })\n }\n />\n </div>\n <div className=\"grid gap-1.5\">\n <Label>Field type</Label>\n <Select\n value={field.type}\n onValueChange={(v) => updateField(index, { type: v as BuilderFieldType })}\n >\n <SelectTrigger aria-label=\"Field type\">\n <SelectValue />\n </SelectTrigger>\n <SelectContent>\n {TYPE_ORDER.map((t) => (\n <SelectItem key={t} value={t}>\n {TYPE_META[t].label}\n </SelectItem>\n ))}\n </SelectContent>\n </Select>\n </div>\n </div>\n\n <div className=\"grid gap-1.5\">\n <Label htmlFor={`${groupId}-section-${index}`}>\n {tr('govcitizenhub.services.formBuilder.section', 'Section')}\n </Label>\n <Input\n id={`${groupId}-section-${index}`}\n list={`${groupId}-section-names`}\n value={field.section ?? ''}\n disabled={disabled}\n aria-describedby={`${groupId}-section-help`}\n onChange={(e) => updateField(index, { section: e.target.value })}\n />\n <datalist id={`${groupId}-section-names`}>\n {Array.from(sectionNames, (name) => (\n <option key={name} value={name} />\n ))}\n </datalist>\n <p id={`${groupId}-section-help`} className=\"text-xs text-text-muted\">\n {tr(\n 'govcitizenhub.services.formBuilder.sectionHelp',\n 'Use the same section name for adjacent fields to group them, or leave it blank.'\n )}\n </p>\n </div>\n\n {field.type === 'select' && (\n <div className=\"grid gap-1.5\">\n <Label htmlFor={`${groupId}-opts-${index}`}>Choices</Label>\n <TagInput\n id={`${groupId}-opts-${index}`}\n value={field.options ?? []}\n onChange={(opts) => updateField(index, { options: opts })}\n placeholder=\"Add a choice and press Enter…\"\n />\n </div>\n )}\n\n <label className=\"flex items-center justify-between gap-3 rounded-lg bg-bg-sunken/50 px-3 py-2\">\n <span className=\"text-sm text-text-primary\">Required field</span>\n <Switch\n checked={field.required}\n onCheckedChange={(checked) => updateField(index, { required: checked })}\n aria-label=\"Required field\"\n />\n </label>\n\n <ConditionalRuleEditor\n groupId={groupId}\n index={index}\n field={field}\n priorFields={value.slice(0, index).filter((f) => f.key)}\n onChange={(showIf) => updateField(index, { showIf })}\n />\n </div>\n )}\n </li>\n );\n })}\n </ul>\n )}\n </div>\n );\n}\n"],"mappings":";;;;;;;;;;AAyEA,IAAMA,IAA0F;CAC9F,MAAM;EACJ,OAAO;EACP,MAAMC;EACN,MAAM;CACR;CACA,UAAU;EACR,OAAO;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,YAAD;UAAU,IAAI,GAAGD,EAAQ;UACtB,UAAA,MAAM,KAAKQ,IAAe,MACzB,kBAAC,UAAD,EAAmB,OAAO0C,EAAO,GAApBA,CAAoB,CAClC;SACO,CAAA;SACV,kBAAC,KAAD;UAAG,IAAI,GAAGlD,EAAQ;UAAgB,WAAU;UACzC,UAAAK,EACC,kDACA,iFACF;SACC,CAAA;QACA;;OAEJhB,EAAM,SAAS,YACd,kBAAC,OAAD;QAAK,WAAU;QAAf,UAAA,CACE,kBAAC4C,GAAD;SAAO,SAAS,GAAGjC,EAAQ,QAAQC;SAAS,UAAA;QAAc,CAAA,GAC1D,kBAACkD,GAAD;SACE,IAAI,GAAGnD,EAAQ,QAAQC;SACvB,OAAOZ,EAAM,WAAW,CAAC;SACzB,WAAW,MAASiC,EAAYrB,GAAO,EAAE,SAASmD,EAAK,CAAC;SACxD,aAAY;QACb,CAAA,CACE;;OAGP,kBAAC,SAAD;QAAO,WAAU;QAAjB,UAAA,CACE,kBAAC,QAAD;SAAM,WAAU;SAA4B,UAAA;QAAoB,CAAA,GAChE,kBAACC,GAAD;SACE,SAAShE,EAAM;SACf,kBAAkB,MAAYiC,EAAYrB,GAAO,EAAE,UAAUqD,EAAQ,CAAC;SACtE,cAAW;QACZ,CAAA,CACI;;OAEP,kBAACnE,GAAD;QACW;QACF;QACA;QACP,aAAasB,EAAM,MAAM,GAAGR,CAAK,CAAC,CAAC,QAAQ,MAAMlB,EAAE,GAAG;QACtD,WAAW,MAAWuC,EAAYrB,GAAO,EAAE,UAAO,CAAC;OACpD,CAAA;MACE;KAEL,CAAA,CAAA;IAtMG,GAAA,GAAGD,EAAQ,GAAGC,GAsMjB;GAER,CAAC;EACC,CAAA,CAEH;;AAET"}
|
|
@@ -23,7 +23,9 @@ export interface DynamicFormField {
|
|
|
23
23
|
required: boolean;
|
|
24
24
|
options?: string[];
|
|
25
25
|
showIf?: DynamicFieldCondition;
|
|
26
|
+
section?: string;
|
|
26
27
|
}
|
|
28
|
+
export declare function normalizeFormSection(value: unknown): string | undefined;
|
|
27
29
|
/**
|
|
28
30
|
* Coerce an opaque `formSchema` JSON into the canonical DynamicFormField[] shape.
|
|
29
31
|
* Kept tolerant so a schema authored elsewhere (bare array, `{ fields }`, or a
|
|
@@ -43,3 +45,11 @@ export declare function serializeFormFields(fields: DynamicFormField[]): Dynamic
|
|
|
43
45
|
* (fail-open) rather than recursing forever.
|
|
44
46
|
*/
|
|
45
47
|
export declare function isFieldVisible(field: DynamicFormField, values: Record<string, string>, allFields: DynamicFormField[], seen?: ReadonlySet<string>): boolean;
|
|
48
|
+
interface VisibleFormSection {
|
|
49
|
+
start: number;
|
|
50
|
+
label?: string;
|
|
51
|
+
fields: DynamicFormField[];
|
|
52
|
+
}
|
|
53
|
+
/** Group adjacent fields in schema order. A section with no visible fields is omitted. */
|
|
54
|
+
export declare function visibleFormSections(fields: DynamicFormField[], values: Record<string, string>): VisibleFormSection[];
|
|
55
|
+
export {};
|
|
@@ -1,9 +1,12 @@
|
|
|
1
1
|
// src/govcitizenhub/utils/dynamicForm.ts
|
|
2
|
-
function e(e
|
|
2
|
+
function e(e) {
|
|
3
|
+
return typeof e == "string" && e.trim() || void 0;
|
|
4
|
+
}
|
|
5
|
+
function t(e, t) {
|
|
3
6
|
let n = String(e ?? "").toLowerCase();
|
|
4
7
|
return t || n === "select" || n === "choice" || n === "enum" ? "select" : n.includes("area") || n === "textarea" || n === "multiline" || n === "paragraph" ? "textarea" : n === "number" || n === "integer" || n === "float" ? "number" : n === "date" || n === "datetime" ? "date" : n === "file" || n === "upload" ? "file" : "text";
|
|
5
8
|
}
|
|
6
|
-
function
|
|
9
|
+
function n(e) {
|
|
7
10
|
if (!e || typeof e != "object") return;
|
|
8
11
|
let t = e, n = typeof t.fieldKey == "string" ? t.fieldKey : void 0, r = typeof t.equals == "string" ? t.equals : void 0;
|
|
9
12
|
if (n && r !== void 0) return {
|
|
@@ -11,48 +14,65 @@ function t(e) {
|
|
|
11
14
|
equals: r
|
|
12
15
|
};
|
|
13
16
|
}
|
|
14
|
-
function
|
|
15
|
-
if (!
|
|
16
|
-
let
|
|
17
|
+
function r(r, i) {
|
|
18
|
+
if (!r || typeof r != "object") return null;
|
|
19
|
+
let a = r, o = String(a.label ?? a.title ?? a.name ?? a.key ?? i), s = String(a.key ?? a.name ?? a.id ?? i), c = Array.isArray(a.options) ? a.options.map((e) => String(e)) : Array.isArray(a.enum) ? a.enum.map((e) => String(e)) : void 0, l = t(a.type, !!(c && c.length)), u = n(a.showIf), d = e(a.section);
|
|
17
20
|
return {
|
|
18
|
-
key:
|
|
19
|
-
label:
|
|
20
|
-
type:
|
|
21
|
-
required: !!
|
|
22
|
-
...
|
|
23
|
-
...
|
|
21
|
+
key: s,
|
|
22
|
+
label: o,
|
|
23
|
+
type: l,
|
|
24
|
+
required: !!a.required,
|
|
25
|
+
...l === "select" ? { options: c ?? [] } : {},
|
|
26
|
+
...u ? { showIf: u } : {},
|
|
27
|
+
...d ? { section: d } : {}
|
|
24
28
|
};
|
|
25
29
|
}
|
|
26
|
-
function
|
|
27
|
-
if (Array.isArray(e)) return e.map((e, t) =>
|
|
30
|
+
function i(e) {
|
|
31
|
+
if (Array.isArray(e)) return e.map((e, t) => r(e, `field_${t + 1}`)).filter((e) => !!e);
|
|
28
32
|
if (e && typeof e == "object") {
|
|
29
33
|
let t = e;
|
|
30
|
-
if (Array.isArray(t.fields)) return t.fields.map((e, t) =>
|
|
31
|
-
if (t.properties && typeof t.properties == "object") return Object.entries(t.properties).map(([e, t]) =>
|
|
34
|
+
if (Array.isArray(t.fields)) return t.fields.map((e, t) => r(e, `field_${t + 1}`)).filter((e) => !!e);
|
|
35
|
+
if (t.properties && typeof t.properties == "object") return Object.entries(t.properties).map(([e, t]) => r({
|
|
32
36
|
...t,
|
|
33
37
|
key: e
|
|
34
38
|
}, e)).filter((e) => !!e);
|
|
35
39
|
}
|
|
36
40
|
return [];
|
|
37
41
|
}
|
|
38
|
-
function
|
|
39
|
-
return
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
}
|
|
48
|
-
|
|
42
|
+
function a(t) {
|
|
43
|
+
return t.length === 0 ? null : t.map((t) => {
|
|
44
|
+
let n = e(t.section);
|
|
45
|
+
return {
|
|
46
|
+
key: t.key,
|
|
47
|
+
label: t.label,
|
|
48
|
+
type: t.type,
|
|
49
|
+
required: t.required,
|
|
50
|
+
...t.type === "select" ? { options: t.options ?? [] } : {},
|
|
51
|
+
...t.showIf ? { showIf: t.showIf } : {},
|
|
52
|
+
...n ? { section: n } : {}
|
|
53
|
+
};
|
|
54
|
+
});
|
|
55
|
+
}
|
|
56
|
+
function o(e, t, n, r = /* @__PURE__ */ new Set()) {
|
|
49
57
|
let i = e.showIf;
|
|
50
58
|
if (!i || r.has(e.key)) return !0;
|
|
51
|
-
let
|
|
52
|
-
if (!
|
|
59
|
+
let a = n.find((e) => e.key === i.fieldKey);
|
|
60
|
+
if (!a) return !0;
|
|
53
61
|
let s = new Set(r);
|
|
54
|
-
return s.add(e.key), !a
|
|
62
|
+
return s.add(e.key), !o(a, t, n, s) || (t[i.fieldKey] ?? "") === i.equals;
|
|
63
|
+
}
|
|
64
|
+
function s(t, n) {
|
|
65
|
+
let r = [], i;
|
|
66
|
+
for (let [a, s] of t.entries()) {
|
|
67
|
+
let c = e(s.section);
|
|
68
|
+
i && i.label === c || (i = {
|
|
69
|
+
start: a,
|
|
70
|
+
label: c,
|
|
71
|
+
fields: []
|
|
72
|
+
}, r.push(i)), o(s, n, t) && i.fields.push(s);
|
|
73
|
+
}
|
|
74
|
+
return r.filter(({ fields: e }) => e.length > 0);
|
|
55
75
|
}
|
|
56
|
-
export {
|
|
76
|
+
export { o as isFieldVisible, e as normalizeFormSection, i as parseFormFields, a as serializeFormFields, s as visibleFormSections };
|
|
57
77
|
|
|
58
78
|
//# sourceMappingURL=dynamicForm.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"dynamicForm.js","names":["coerceType","t","raw","hasOptions","coerceCondition","r","fieldKey","equals","toField","label","fallbackKey","key","options","o","type","showIf","parseFormFields","schema","f","i","obj","v","serializeFormFields","fields","isFieldVisible","condition","field","seen","source","allFields","nextSeen","values"],"sources":["../../../src/govcitizenhub/utils/dynamicForm.ts"],"sourcesContent":["/**\n * Shared dynamic-form parsing/visibility logic for a service's `formSchema`.\n * @module govcitizenhub/utils/dynamicForm\n *\n * Single source of truth for the array `formSchema` shape produced by the\n * no-code service builder (`FormFieldBuilder`) and consumed by the citizen\n * application form (`NewApplicationPage`) and the builder's own live preview\n * (`DynamicFormFields` used inside `ServiceFormDialog`). Keeping the parse +\n * visibility logic in one place (rather than duplicated per page, as it was\n * before BOFF-4540) means the builder's preview can never drift from what a\n * citizen actually sees.\n */\n\nexport type DynamicFieldType = 'text' | 'textarea' | 'number' | 'date' | 'select' | 'file';\n\n/** A field is only rendered/required when the referenced earlier field equals this value. */\nexport interface DynamicFieldCondition {\n fieldKey: string;\n equals: string;\n}\n\nexport interface DynamicFormField {\n key: string;\n label: string;\n type: DynamicFieldType;\n required: boolean;\n options?: string[];\n showIf?: DynamicFieldCondition;\n}\n\nfunction coerceType(raw: unknown, hasOptions: boolean): DynamicFieldType {\n const t = String(raw ?? '').toLowerCase();\n if (hasOptions || t === 'select' || t === 'choice' || t === 'enum') return 'select';\n if (t.includes('area') || t === 'textarea' || t === 'multiline' || t === 'paragraph')\n return 'textarea';\n if (t === 'number' || t === 'integer' || t === 'float') return 'number';\n if (t === 'date' || t === 'datetime') return 'date';\n if (t === 'file' || t === 'upload') return 'file';\n return 'text';\n}\n\nfunction coerceCondition(raw: unknown): DynamicFieldCondition | undefined {\n if (!raw || typeof raw !== 'object') return undefined;\n const r = raw as Record<string, unknown>;\n const fieldKey = typeof r.fieldKey === 'string' ? r.fieldKey : undefined;\n const equals = typeof r.equals === 'string' ? r.equals : undefined;\n if (!fieldKey || equals === undefined) return undefined;\n return { fieldKey, equals };\n}\n\nfunction toField(raw: unknown, fallbackKey: string): DynamicFormField | null {\n if (!raw || typeof raw !== 'object') return null;\n const r = raw as Record<string, unknown>;\n const label = String(r.label ?? r.title ?? r.name ?? r.key ?? fallbackKey);\n const key = String(r.key ?? r.name ?? r.id ?? fallbackKey);\n const options = Array.isArray(r.options)\n ? r.options.map((o) => String(o))\n : Array.isArray(r.enum)\n ? r.enum.map((o) => String(o))\n : undefined;\n const type = coerceType(r.type, Boolean(options && options.length));\n const showIf = coerceCondition(r.showIf);\n return {\n key,\n label,\n type,\n required: Boolean(r.required),\n ...(type === 'select' ? { options: options ?? [] } : {}),\n ...(showIf ? { showIf } : {}),\n };\n}\n\n/**\n * Coerce an opaque `formSchema` JSON into the canonical DynamicFormField[] shape.\n * Kept tolerant so a schema authored elsewhere (bare array, `{ fields }`, or a\n * json-schema-ish `{ properties }`) still parses.\n */\nexport function parseFormFields(schema: unknown): DynamicFormField[] {\n if (Array.isArray(schema)) {\n return schema\n .map((f, i) => toField(f, `field_${i + 1}`))\n .filter((f): f is DynamicFormField => !!f);\n }\n if (schema && typeof schema === 'object') {\n const obj = schema as Record<string, unknown>;\n if (Array.isArray(obj.fields)) {\n return obj.fields\n .map((f, i) => toField(f, `field_${i + 1}`))\n .filter((f): f is DynamicFormField => !!f);\n }\n if (obj.properties && typeof obj.properties === 'object') {\n return Object.entries(obj.properties as Record<string, unknown>)\n .map(([key, v]) => toField({ ...(v as object), key }, key))\n .filter((f): f is DynamicFormField => !!f);\n }\n }\n return [];\n}\n\n/** Serialise DynamicFormField[] back to the array `formSchema` payload (or null when empty). */\nexport function serializeFormFields(fields: DynamicFormField[]): DynamicFormField[] | null {\n if (fields.length === 0) return null;\n return fields.map((f) => ({\n key: f.key,\n label: f.label,\n type: f.type,\n required: f.required,\n ...(f.type === 'select' ? { options: f.options ?? [] } : {}),\n ...(f.showIf ? { showIf: f.showIf } : {}),\n }));\n}\n\n/**\n * Whether `field` should be shown/required given the current answer set.\n * A field with no `showIf` is always visible. A field whose condition\n * references a field that is itself hidden, missing, or was removed from the\n * schema is treated as visible (fail-open) so authoring mistakes never trap a\n * citizen behind an invisible required field. `seen` guards against a cyclic\n * `showIf` chain (e.g. two fields conditionally depending on each other after\n * being reordered in the builder) — a cycle is also treated as visible\n * (fail-open) rather than recursing forever.\n */\nexport function isFieldVisible(\n field: DynamicFormField,\n values: Record<string, string>,\n allFields: DynamicFormField[],\n seen: ReadonlySet<string> = new Set()\n): boolean {\n const condition = field.showIf;\n if (!condition) return true;\n if (seen.has(field.key)) return true;\n const source = allFields.find((f) => f.key === condition.fieldKey);\n if (!source) return true;\n const nextSeen = new Set(seen);\n nextSeen.add(field.key);\n if (!isFieldVisible(source, values, allFields, nextSeen)) return true;\n return (values[condition.fieldKey] ?? '') === condition.equals;\n}\n"],"mappings":";AA8BA,SAASA,EAAW,GAAc,GAAuC;CACvE,IAAMC,IAAI,OAAOC,KAAO,EAAE,CAAC,CAAC,YAAY;CAOxC,OANIC,KAAcF,MAAM,YAAYA,MAAM,YAAYA,MAAM,SAAe,WACvEA,EAAE,SAAS,MAAM,KAAKA,MAAM,cAAcA,MAAM,eAAeA,MAAM,cAChE,aACLA,MAAM,YAAYA,MAAM,aAAaA,MAAM,UAAgB,WAC3DA,MAAM,UAAUA,MAAM,aAAmB,SACzCA,MAAM,UAAUA,MAAM,WAAiB,SACpC;AACT;AAEA,SAASG,EAAgB,GAAiD;CACxE,IAAI,CAACF,KAAO,OAAOA,KAAQ,UAAU;CACrC,IAAMG,IAAIH,GACJI,IAAW,OAAOD,EAAE,YAAa,WAAWA,EAAE,WAAW,KAAA,GACzDE,IAAS,OAAOF,EAAE,UAAW,WAAWA,EAAE,SAAS,KAAA;CACzD,IAAKC,KAAYC,MAAW,KAAA,GAC5B,OAAO;EAAE;EAAU;CAAO;AAC5B;AAEA,SAASC,EAAQ,GAAc,GAA8C;CAC3E,IAAI,CAACN,KAAO,OAAOA,KAAQ,UAAU,OAAO;CAC5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C,CAACO,CAAC;CAE/C;CACA,OAAO,CAAC;AACV;AAGA,SAAgBI,EAAoB,GAAuD;CAEzF,OADIC,EAAO,WAAW,IAAU,OACzBA,EAAO,KAAK,OAAO;EACxB,KAAKL,EAAE;EACP,OAAOA,EAAE;EACT,MAAMA,EAAE;EACR,UAAUA,EAAE;EACZ,GAAIA,EAAE,SAAS,WAAW,EAAE,SAASA,EAAE,WAAW,CAAC,EAAE,IAAI,CAAC;EAC1D,GAAIA,EAAE,SAAS,EAAE,QAAQA,EAAE,OAAO,IAAI,CAAC;CACzC,EAAE;AACJ;AAYA,SAAgBM,EACd,GACA,GACA,GACA,oBAA4B,IAAI,IAAI,GAC3B;CACT,IAAMC,IAAYC,EAAM;CAExB,IADI,CAACD,KACDE,EAAK,IAAID,EAAM,GAAG,GAAG,OAAO;CAChC,IAAME,IAASC,EAAU,MAAM,MAAMX,EAAE,QAAQO,EAAU,QAAQ;CACjE,IAAI,CAACG,GAAQ,OAAO;CACpB,IAAME,IAAW,IAAI,IAAIH,CAAI;CAG7B,OAFAG,EAAS,IAAIJ,EAAM,GAAG,GACtB,CAAKF,EAAeI,GAAQG,GAAQF,GAAWC,CAAQ,MAC/CC,EAAON,EAAU,aAAa,QAAQA,EAAU;AAC1D"}
|
|
1
|
+
{"version":3,"file":"dynamicForm.js","names":["normalizeFormSection","value","coerceType","t","raw","hasOptions","coerceCondition","r","fieldKey","equals","toField","label","fallbackKey","key","options","o","type","showIf","section","parseFormFields","schema","f","i","obj","v","serializeFormFields","fields","isFieldVisible","condition","field","seen","source","allFields","nextSeen","values","visibleFormSections","sections","current","index","visibleFields"],"sources":["../../../src/govcitizenhub/utils/dynamicForm.ts"],"sourcesContent":["/**\n * Shared dynamic-form parsing/visibility logic for a service's `formSchema`.\n * @module govcitizenhub/utils/dynamicForm\n *\n * Single source of truth for the array `formSchema` shape produced by the\n * no-code service builder (`FormFieldBuilder`) and consumed by the citizen\n * application form (`NewApplicationPage`) and the builder's own live preview\n * (`DynamicFormFields` used inside `ServiceFormDialog`). Keeping the parse +\n * visibility logic in one place (rather than duplicated per page, as it was\n * before BOFF-4540) means the builder's preview can never drift from what a\n * citizen actually sees.\n */\n\nexport type DynamicFieldType = 'text' | 'textarea' | 'number' | 'date' | 'select' | 'file';\n\n/** A field is only rendered/required when the referenced earlier field equals this value. */\nexport interface DynamicFieldCondition {\n fieldKey: string;\n equals: string;\n}\n\nexport interface DynamicFormField {\n key: string;\n label: string;\n type: DynamicFieldType;\n required: boolean;\n options?: string[];\n showIf?: DynamicFieldCondition;\n section?: string;\n}\n\nexport function normalizeFormSection(value: unknown): string | undefined {\n return typeof value === 'string' ? value.trim() || undefined : undefined;\n}\n\nfunction coerceType(raw: unknown, hasOptions: boolean): DynamicFieldType {\n const t = String(raw ?? '').toLowerCase();\n if (hasOptions || t === 'select' || t === 'choice' || t === 'enum') return 'select';\n if (t.includes('area') || t === 'textarea' || t === 'multiline' || t === 'paragraph')\n return 'textarea';\n if (t === 'number' || t === 'integer' || t === 'float') return 'number';\n if (t === 'date' || t === 'datetime') return 'date';\n if (t === 'file' || t === 'upload') return 'file';\n return 'text';\n}\n\nfunction coerceCondition(raw: unknown): DynamicFieldCondition | undefined {\n if (!raw || typeof raw !== 'object') return undefined;\n const r = raw as Record<string, unknown>;\n const fieldKey = typeof r.fieldKey === 'string' ? r.fieldKey : undefined;\n const equals = typeof r.equals === 'string' ? r.equals : undefined;\n if (!fieldKey || equals === undefined) return undefined;\n return { fieldKey, equals };\n}\n\nfunction toField(raw: unknown, fallbackKey: string): DynamicFormField | null {\n if (!raw || typeof raw !== 'object') return null;\n const r = raw as Record<string, unknown>;\n const label = String(r.label ?? r.title ?? r.name ?? r.key ?? fallbackKey);\n const key = String(r.key ?? r.name ?? r.id ?? fallbackKey);\n const options = Array.isArray(r.options)\n ? r.options.map((o) => String(o))\n : Array.isArray(r.enum)\n ? r.enum.map((o) => String(o))\n : undefined;\n const type = coerceType(r.type, Boolean(options && options.length));\n const showIf = coerceCondition(r.showIf);\n const section = normalizeFormSection(r.section);\n return {\n key,\n label,\n type,\n required: Boolean(r.required),\n ...(type === 'select' ? { options: options ?? [] } : {}),\n ...(showIf ? { showIf } : {}),\n ...(section ? { section } : {}),\n };\n}\n\n/**\n * Coerce an opaque `formSchema` JSON into the canonical DynamicFormField[] shape.\n * Kept tolerant so a schema authored elsewhere (bare array, `{ fields }`, or a\n * json-schema-ish `{ properties }`) still parses.\n */\nexport function parseFormFields(schema: unknown): DynamicFormField[] {\n if (Array.isArray(schema)) {\n return schema\n .map((f, i) => toField(f, `field_${i + 1}`))\n .filter((f): f is DynamicFormField => !!f);\n }\n if (schema && typeof schema === 'object') {\n const obj = schema as Record<string, unknown>;\n if (Array.isArray(obj.fields)) {\n return obj.fields\n .map((f, i) => toField(f, `field_${i + 1}`))\n .filter((f): f is DynamicFormField => !!f);\n }\n if (obj.properties && typeof obj.properties === 'object') {\n return Object.entries(obj.properties as Record<string, unknown>)\n .map(([key, v]) => toField({ ...(v as object), key }, key))\n .filter((f): f is DynamicFormField => !!f);\n }\n }\n return [];\n}\n\n/** Serialise DynamicFormField[] back to the array `formSchema` payload (or null when empty). */\nexport function serializeFormFields(fields: DynamicFormField[]): DynamicFormField[] | null {\n if (fields.length === 0) return null;\n return fields.map((f) => {\n const section = normalizeFormSection(f.section);\n return {\n key: f.key,\n label: f.label,\n type: f.type,\n required: f.required,\n ...(f.type === 'select' ? { options: f.options ?? [] } : {}),\n ...(f.showIf ? { showIf: f.showIf } : {}),\n ...(section ? { section } : {}),\n };\n });\n}\n\n/**\n * Whether `field` should be shown/required given the current answer set.\n * A field with no `showIf` is always visible. A field whose condition\n * references a field that is itself hidden, missing, or was removed from the\n * schema is treated as visible (fail-open) so authoring mistakes never trap a\n * citizen behind an invisible required field. `seen` guards against a cyclic\n * `showIf` chain (e.g. two fields conditionally depending on each other after\n * being reordered in the builder) — a cycle is also treated as visible\n * (fail-open) rather than recursing forever.\n */\nexport function isFieldVisible(\n field: DynamicFormField,\n values: Record<string, string>,\n allFields: DynamicFormField[],\n seen: ReadonlySet<string> = new Set()\n): boolean {\n const condition = field.showIf;\n if (!condition) return true;\n if (seen.has(field.key)) return true;\n const source = allFields.find((f) => f.key === condition.fieldKey);\n if (!source) return true;\n const nextSeen = new Set(seen);\n nextSeen.add(field.key);\n if (!isFieldVisible(source, values, allFields, nextSeen)) return true;\n return (values[condition.fieldKey] ?? '') === condition.equals;\n}\n\ninterface VisibleFormSection {\n start: number;\n label?: string;\n fields: DynamicFormField[];\n}\n\n/** Group adjacent fields in schema order. A section with no visible fields is omitted. */\nexport function visibleFormSections(\n fields: DynamicFormField[],\n values: Record<string, string>\n): VisibleFormSection[] {\n const sections: VisibleFormSection[] = [];\n let current: VisibleFormSection | undefined;\n\n for (const [index, field] of fields.entries()) {\n const label = normalizeFormSection(field.section);\n if (!current || current.label !== label) {\n current = { start: index, label, fields: [] };\n sections.push(current);\n }\n if (isFieldVisible(field, values, fields)) current.fields.push(field);\n }\n\n return sections.filter(({ fields: visibleFields }) => visibleFields.length > 0);\n}\n"],"mappings":";AA+BA,SAAgBA,EAAqB,GAAoC;CACvE,OAAO,OAAOC,KAAU,YAAWA,EAAM,KAAK,KAAK,KAAA;AACrD;AAEA,SAASC,EAAW,GAAc,GAAuC;CACvE,IAAMC,IAAI,OAAOC,KAAO,EAAE,CAAC,CAAC,YAAY;CAOxC,OANIC,KAAcF,MAAM,YAAYA,MAAM,YAAYA,MAAM,SAAe,WACvEA,EAAE,SAAS,MAAM,KAAKA,MAAM,cAAcA,MAAM,eAAeA,MAAM,cAChE,aACLA,MAAM,YAAYA,MAAM,aAAaA,MAAM,UAAgB,WAC3DA,MAAM,UAAUA,MAAM,aAAmB,SACzCA,MAAM,UAAUA,MAAM,WAAiB,SACpC;AACT;AAEA,SAASG,EAAgB,GAAiD;CACxE,IAAI,CAACF,KAAO,OAAOA,KAAQ,UAAU;CACrC,IAAMG,IAAIH,GACJI,IAAW,OAAOD,EAAE,YAAa,WAAWA,EAAE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IAAMC,IAAiC,CAAC,GACpCC;CAEJ,KAAK,IAAM,CAACC,GAAOT,MAAUH,EAAO,QAAQ,GAAG;EAC7C,IAAMf,IAAQX,EAAqB6B,EAAM,OAAO;EAKhD,AAJKQ,KAAWA,EAAQ,UAAU1B,MAChC,IAAU;GAAE,OAAO2B;GAAO;GAAO,QAAQ,CAAC;EAAE,GAC5CF,EAAS,KAAKC,CAAO,IAEnBV,EAAeE,GAAOK,GAAQR,CAAM,KAAGW,EAAQ,OAAO,KAAKR,CAAK;CACtE;CAEA,OAAOO,EAAS,QAAQ,EAAE,QAAQG,QAAoBA,EAAc,SAAS,CAAC;AAChF"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@burdenoff/microfe-govcitizenhub",
|
|
3
|
-
"version": "2026.
|
|
3
|
+
"version": "2026.1123.1",
|
|
4
4
|
"description": "Burdenoff GovCitizenHub Microfrontend",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"files": [
|
|
@@ -67,13 +67,13 @@
|
|
|
67
67
|
},
|
|
68
68
|
"devDependencies": {
|
|
69
69
|
"@burdenoff/toolchain": "2026.1107.14",
|
|
70
|
-
"@graphql-codegen/add": "^
|
|
71
|
-
"@graphql-codegen/cli": "^
|
|
72
|
-
"@graphql-codegen/import-types-preset": "^
|
|
73
|
-
"@graphql-codegen/schema-ast": "^
|
|
74
|
-
"@graphql-codegen/typescript": "^
|
|
75
|
-
"@graphql-codegen/typescript-operations": "^
|
|
76
|
-
"@graphql-codegen/typescript-react-apollo": "^
|
|
70
|
+
"@graphql-codegen/add": "^8.0.0",
|
|
71
|
+
"@graphql-codegen/cli": "^8.0.0",
|
|
72
|
+
"@graphql-codegen/import-types-preset": "^5.0.0",
|
|
73
|
+
"@graphql-codegen/schema-ast": "^7.0.0",
|
|
74
|
+
"@graphql-codegen/typescript": "^7.0.1",
|
|
75
|
+
"@graphql-codegen/typescript-operations": "^7.0.1",
|
|
76
|
+
"@graphql-codegen/typescript-react-apollo": "^6.0.1",
|
|
77
77
|
"@storybook/addon-essentials": "^8.6.19",
|
|
78
78
|
"@storybook/addon-interactions": "^8.6.19",
|
|
79
79
|
"@storybook/react": "^8.6.19",
|
|
@@ -121,7 +121,10 @@
|
|
|
121
121
|
"yaml": ">=2.8.3",
|
|
122
122
|
"picomatch": ">=2.3.2",
|
|
123
123
|
"immutable": ">=3.8.3",
|
|
124
|
-
"minimatch": ">=3.1.3"
|
|
124
|
+
"minimatch": ">=3.1.3",
|
|
125
|
+
"glob@^10.0.0": "14.0.4",
|
|
126
|
+
"uuid@^8.0.0": "11.1.1",
|
|
127
|
+
"uuid@^9.0.0": "11.1.1"
|
|
125
128
|
},
|
|
126
129
|
"packageManager": "bun@1.4.4",
|
|
127
130
|
"engines": {
|