@burdenoff/microfe-govcitizenhub 2026.720.3 → 2026.720.5
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.d.ts +17 -0
- package/dist/govcitizenhub/components/DynamicFormFields.d.ts.map +1 -0
- package/dist/govcitizenhub/components/DynamicFormFields.js +101 -0
- package/dist/govcitizenhub/components/DynamicFormFields.js.map +1 -0
- package/dist/govcitizenhub/components/mobile/BottomTabNav.d.ts.map +1 -1
- package/dist/govcitizenhub/components/mobile/BottomTabNav.js +11 -8
- package/dist/govcitizenhub/components/mobile/BottomTabNav.js.map +1 -1
- package/dist/govcitizenhub/pages/applications/ApplicationsPage.d.ts.map +1 -1
- package/dist/govcitizenhub/pages/applications/ApplicationsPage.js +170 -150
- package/dist/govcitizenhub/pages/applications/ApplicationsPage.js.map +1 -1
- package/dist/govcitizenhub/pages/applications/NewApplicationPage.d.ts +9 -5
- package/dist/govcitizenhub/pages/applications/NewApplicationPage.d.ts.map +1 -1
- package/dist/govcitizenhub/pages/applications/NewApplicationPage.js +148 -244
- package/dist/govcitizenhub/pages/applications/NewApplicationPage.js.map +1 -1
- package/dist/govcitizenhub/pages/services/FormFieldBuilder.d.ts +7 -28
- package/dist/govcitizenhub/pages/services/FormFieldBuilder.d.ts.map +1 -1
- package/dist/govcitizenhub/pages/services/FormFieldBuilder.js +203 -136
- package/dist/govcitizenhub/pages/services/FormFieldBuilder.js.map +1 -1
- package/dist/govcitizenhub/pages/services/ServiceFormDialog.d.ts.map +1 -1
- package/dist/govcitizenhub/pages/services/ServiceFormDialog.js +156 -114
- package/dist/govcitizenhub/pages/services/ServiceFormDialog.js.map +1 -1
- package/dist/govcitizenhub/utils/dynamicForm.d.ts +46 -0
- package/dist/govcitizenhub/utils/dynamicForm.d.ts.map +1 -0
- package/dist/govcitizenhub/utils/dynamicForm.js +59 -0
- package/dist/govcitizenhub/utils/dynamicForm.js.map +1 -0
- package/package.json +1 -1
|
@@ -1,43 +1,44 @@
|
|
|
1
1
|
import { cn as e } from "../../utils/cn.js";
|
|
2
2
|
import { slugify as t } from "../../utils/formatters.js";
|
|
3
3
|
import { TagInput as n } from "../../components/TagInput.js";
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
6
|
-
import {
|
|
7
|
-
import {
|
|
4
|
+
import { parseFormFields as r, serializeFormFields as i } from "../../utils/dynamicForm.js";
|
|
5
|
+
import { useId as a, useState as o } from "react";
|
|
6
|
+
import { AlignLeft as s, Calendar as c, Check as l, ChevronDown as u, ChevronUp as d, GitBranch as f, GripVertical as p, Hash as m, ListChecks as h, Pencil as g, Plus as _, Trash2 as v, Type as y, UploadCloud as b } from "lucide-react";
|
|
7
|
+
import { jsx as x, jsxs as S } from "react/jsx-runtime";
|
|
8
|
+
import { Button as C, Input as w, Label as T, Select as E, SelectContent as D, SelectItem as O, SelectTrigger as k, SelectValue as A, Switch as j } from "@burdenoff/fe-libs/ui";
|
|
8
9
|
//#region src/govcitizenhub/pages/services/FormFieldBuilder.tsx
|
|
9
|
-
var
|
|
10
|
+
var M = {
|
|
10
11
|
text: {
|
|
11
12
|
label: "Text",
|
|
12
|
-
icon:
|
|
13
|
+
icon: y,
|
|
13
14
|
tone: "bg-[var(--color-accent-soft)] text-action-primary-text"
|
|
14
15
|
},
|
|
15
16
|
textarea: {
|
|
16
17
|
label: "Paragraph",
|
|
17
|
-
icon:
|
|
18
|
+
icon: s,
|
|
18
19
|
tone: "bg-[var(--color-accent-soft)] text-action-primary-text"
|
|
19
20
|
},
|
|
20
21
|
number: {
|
|
21
22
|
label: "Number",
|
|
22
|
-
icon:
|
|
23
|
+
icon: m,
|
|
23
24
|
tone: "bg-status-success-bg-subtle text-status-success-text"
|
|
24
25
|
},
|
|
25
26
|
date: {
|
|
26
27
|
label: "Date",
|
|
27
|
-
icon:
|
|
28
|
+
icon: c,
|
|
28
29
|
tone: "bg-[color-mix(in_oklab,var(--color-accent-purple)_16%,transparent)] text-[var(--color-accent-purple)]"
|
|
29
30
|
},
|
|
30
31
|
select: {
|
|
31
32
|
label: "Choice",
|
|
32
|
-
icon:
|
|
33
|
+
icon: h,
|
|
33
34
|
tone: "bg-status-warning-bg-subtle text-status-warning-text"
|
|
34
35
|
},
|
|
35
36
|
file: {
|
|
36
37
|
label: "File upload",
|
|
37
|
-
icon:
|
|
38
|
+
icon: b,
|
|
38
39
|
tone: "bg-status-warning-bg-subtle text-status-warning-text"
|
|
39
40
|
}
|
|
40
|
-
},
|
|
41
|
+
}, N = [
|
|
41
42
|
"text",
|
|
42
43
|
"textarea",
|
|
43
44
|
"number",
|
|
@@ -45,56 +46,105 @@ var k = {
|
|
|
45
46
|
"select",
|
|
46
47
|
"file"
|
|
47
48
|
];
|
|
48
|
-
function
|
|
49
|
-
|
|
50
|
-
let n = String(e ?? "").toLowerCase();
|
|
51
|
-
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";
|
|
52
|
-
}, r = (e, r) => {
|
|
53
|
-
if (!e || typeof e != "object") return null;
|
|
54
|
-
let i = e, a = String(i.label ?? i.title ?? i.name ?? i.key ?? r), o = String(i.key ?? i.name ?? i.id ?? (t(a) || r)), s = Array.isArray(i.options) ? i.options.map((e) => String(e)) : Array.isArray(i.enum) ? i.enum.map((e) => String(e)) : void 0, c = n(i.type, !!(s && s.length));
|
|
55
|
-
return {
|
|
56
|
-
key: o,
|
|
57
|
-
label: a,
|
|
58
|
-
type: c,
|
|
59
|
-
required: !!i.required,
|
|
60
|
-
...c === "select" ? { options: s ?? [] } : {}
|
|
61
|
-
};
|
|
62
|
-
};
|
|
63
|
-
if (Array.isArray(e)) return e.map((e, t) => r(e, `field_${t + 1}`)).filter((e) => !!e);
|
|
64
|
-
if (e && typeof e == "object") {
|
|
65
|
-
let t = e;
|
|
66
|
-
if (Array.isArray(t.fields)) return t.fields.map((e, t) => r(e, `field_${t + 1}`)).filter((e) => !!e);
|
|
67
|
-
if (t.properties && typeof t.properties == "object") return Object.entries(t.properties).map(([e, t]) => r({
|
|
68
|
-
...t,
|
|
69
|
-
key: e
|
|
70
|
-
}, e)).filter((e) => !!e);
|
|
71
|
-
}
|
|
72
|
-
return [];
|
|
49
|
+
function P(e) {
|
|
50
|
+
return r(e);
|
|
73
51
|
}
|
|
74
|
-
function
|
|
75
|
-
return
|
|
76
|
-
key: e.key,
|
|
77
|
-
label: e.label,
|
|
78
|
-
type: e.type,
|
|
79
|
-
required: e.required,
|
|
80
|
-
...e.type === "select" ? { options: e.options ?? [] } : {}
|
|
81
|
-
}));
|
|
52
|
+
function F(e) {
|
|
53
|
+
return i(e);
|
|
82
54
|
}
|
|
83
|
-
function
|
|
55
|
+
function I(e, n, r) {
|
|
84
56
|
let i = t(e) || `field_${r + 1}`, a = i, o = 2, s = new Set(n.filter((e, t) => t !== r).map((e) => e.key));
|
|
85
57
|
for (; s.has(a);) a = `${i}-${o++}`;
|
|
86
58
|
return a;
|
|
87
59
|
}
|
|
88
|
-
function
|
|
89
|
-
let
|
|
60
|
+
function L(e) {
|
|
61
|
+
let t = new Set(e.map((e) => e.key));
|
|
62
|
+
return e.map((e) => e.showIf && !t.has(e.showIf.fieldKey) ? {
|
|
63
|
+
...e,
|
|
64
|
+
showIf: void 0
|
|
65
|
+
} : e);
|
|
66
|
+
}
|
|
67
|
+
var R = "__none__";
|
|
68
|
+
function z({ groupId: e, index: t, field: n, priorFields: r, onChange: i }) {
|
|
69
|
+
let a = n.showIf?.fieldKey ?? R, o = r.find((e) => e.key === a);
|
|
70
|
+
return r.length === 0 ? null : /* @__PURE__ */ S("div", {
|
|
71
|
+
className: "grid gap-2 rounded-lg border border-dashed border-border-seam px-3 py-2.5",
|
|
72
|
+
children: [
|
|
73
|
+
/* @__PURE__ */ S("div", {
|
|
74
|
+
className: "flex items-center gap-1.5 text-sm text-text-primary",
|
|
75
|
+
children: [/* @__PURE__ */ x(f, {
|
|
76
|
+
className: "h-3.5 w-3.5 text-text-muted",
|
|
77
|
+
"aria-hidden": "true"
|
|
78
|
+
}), "Show only if"]
|
|
79
|
+
}),
|
|
80
|
+
/* @__PURE__ */ S("div", {
|
|
81
|
+
className: "grid gap-2 sm:grid-cols-2",
|
|
82
|
+
children: [/* @__PURE__ */ S(E, {
|
|
83
|
+
value: a,
|
|
84
|
+
onValueChange: (e) => i(e === R ? void 0 : {
|
|
85
|
+
fieldKey: e,
|
|
86
|
+
equals: ""
|
|
87
|
+
}),
|
|
88
|
+
children: [/* @__PURE__ */ x(k, {
|
|
89
|
+
"aria-label": `Condition field for ${n.label || "this field"}`,
|
|
90
|
+
children: /* @__PURE__ */ x(A, { placeholder: "No condition" })
|
|
91
|
+
}), /* @__PURE__ */ S(D, { children: [/* @__PURE__ */ x(O, {
|
|
92
|
+
value: R,
|
|
93
|
+
children: "Always show"
|
|
94
|
+
}), r.map((e) => /* @__PURE__ */ x(O, {
|
|
95
|
+
value: e.key,
|
|
96
|
+
children: e.label || e.key
|
|
97
|
+
}, e.key))] })]
|
|
98
|
+
}), o && (o.type === "select" ? /* @__PURE__ */ S(E, {
|
|
99
|
+
value: n.showIf?.equals ?? "",
|
|
100
|
+
onValueChange: (e) => i({
|
|
101
|
+
fieldKey: o.key,
|
|
102
|
+
equals: e
|
|
103
|
+
}),
|
|
104
|
+
children: [/* @__PURE__ */ x(k, {
|
|
105
|
+
id: `${e}-cond-val-${t}`,
|
|
106
|
+
"aria-label": "Required answer",
|
|
107
|
+
children: /* @__PURE__ */ x(A, { placeholder: "Equals…" })
|
|
108
|
+
}), /* @__PURE__ */ x(D, { children: (o.options ?? []).map((e) => /* @__PURE__ */ x(O, {
|
|
109
|
+
value: e,
|
|
110
|
+
children: e
|
|
111
|
+
}, e)) })]
|
|
112
|
+
}) : /* @__PURE__ */ x(w, {
|
|
113
|
+
id: `${e}-cond-val-${t}`,
|
|
114
|
+
"aria-label": "Required answer",
|
|
115
|
+
placeholder: "Equals this value…",
|
|
116
|
+
value: n.showIf?.equals ?? "",
|
|
117
|
+
onChange: (e) => i({
|
|
118
|
+
fieldKey: o.key,
|
|
119
|
+
equals: e.target.value
|
|
120
|
+
})
|
|
121
|
+
}))]
|
|
122
|
+
}),
|
|
123
|
+
o && /* @__PURE__ */ S("p", {
|
|
124
|
+
className: "text-xs text-text-muted",
|
|
125
|
+
children: [
|
|
126
|
+
"“",
|
|
127
|
+
n.label || "This field",
|
|
128
|
+
"” only appears once “",
|
|
129
|
+
o.label || o.key,
|
|
130
|
+
"” is answered “",
|
|
131
|
+
n.showIf?.equals || "…",
|
|
132
|
+
"”."
|
|
133
|
+
]
|
|
134
|
+
})
|
|
135
|
+
]
|
|
136
|
+
});
|
|
137
|
+
}
|
|
138
|
+
function B({ value: t, onChange: r, disabled: i = !1 }) {
|
|
139
|
+
let s = a(), [c, m] = o(-1), [h, y] = o(null), [b, P] = o(null), F = (e) => r(L(e)), R = () => {
|
|
90
140
|
let e = {
|
|
91
141
|
key: "",
|
|
92
142
|
label: "",
|
|
93
143
|
type: "text",
|
|
94
144
|
required: !1
|
|
95
145
|
};
|
|
96
|
-
F([...t, e]),
|
|
97
|
-
},
|
|
146
|
+
F([...t, e]), m(t.length);
|
|
147
|
+
}, B = (e, n) => {
|
|
98
148
|
F(t.map((t, r) => {
|
|
99
149
|
if (r !== e) return t;
|
|
100
150
|
let i = {
|
|
@@ -103,199 +153,216 @@ function P({ value: t, onChange: a, disabled: o = !1 }) {
|
|
|
103
153
|
};
|
|
104
154
|
return i.type === "select" ? i.options ||= [] : delete i.options, i;
|
|
105
155
|
}));
|
|
106
|
-
},
|
|
107
|
-
F(t.filter((t, n) => n !== e)),
|
|
108
|
-
},
|
|
156
|
+
}, V = (e) => {
|
|
157
|
+
F(t.filter((t, n) => n !== e)), m((t) => t === e ? -1 : t > e ? t - 1 : t);
|
|
158
|
+
}, H = (e, n) => {
|
|
109
159
|
if (n < 0 || n >= t.length || e === n) return;
|
|
110
160
|
let r = [...t], [i] = r.splice(e, 1);
|
|
111
|
-
i && r.splice(n, 0, i), F(r),
|
|
112
|
-
},
|
|
113
|
-
|
|
161
|
+
i && r.splice(n, 0, i), F(r), m((t) => t === e ? n : t);
|
|
162
|
+
}, U = (e) => {
|
|
163
|
+
h !== null && H(h, e), y(null), P(null);
|
|
114
164
|
};
|
|
115
|
-
return /* @__PURE__ */
|
|
165
|
+
return /* @__PURE__ */ S("div", {
|
|
116
166
|
className: "grid gap-2.5",
|
|
117
|
-
children: [/* @__PURE__ */
|
|
167
|
+
children: [/* @__PURE__ */ S("div", {
|
|
118
168
|
className: "flex items-center justify-between gap-3",
|
|
119
|
-
children: [/* @__PURE__ */
|
|
169
|
+
children: [/* @__PURE__ */ S("div", {
|
|
120
170
|
className: "flex items-baseline gap-2",
|
|
121
|
-
children: [/* @__PURE__ */
|
|
171
|
+
children: [/* @__PURE__ */ x(T, {
|
|
122
172
|
className: "text-sm",
|
|
123
173
|
children: "Application form fields"
|
|
124
|
-
}), /* @__PURE__ */
|
|
174
|
+
}), /* @__PURE__ */ x("span", {
|
|
125
175
|
className: "text-xs text-text-muted",
|
|
126
176
|
children: "Optional · drag to reorder"
|
|
127
177
|
})]
|
|
128
|
-
}), /* @__PURE__ */
|
|
178
|
+
}), /* @__PURE__ */ S(C, {
|
|
129
179
|
type: "button",
|
|
130
180
|
variant: "outline",
|
|
131
181
|
size: "sm",
|
|
132
|
-
onClick:
|
|
133
|
-
disabled:
|
|
182
|
+
onClick: R,
|
|
183
|
+
disabled: i,
|
|
134
184
|
"aria-label": "Add form field",
|
|
135
|
-
children: [/* @__PURE__ */
|
|
185
|
+
children: [/* @__PURE__ */ x(_, { className: "mr-1 h-4 w-4" }), " Add field"]
|
|
136
186
|
})]
|
|
137
|
-
}), t.length === 0 ? /* @__PURE__ */
|
|
187
|
+
}), t.length === 0 ? /* @__PURE__ */ S("div", {
|
|
138
188
|
className: "rounded-xl border border-dashed border-border-seam bg-bg-sunken/40 px-4 py-6 text-center",
|
|
139
|
-
children: [/* @__PURE__ */
|
|
189
|
+
children: [/* @__PURE__ */ x("p", {
|
|
140
190
|
className: "text-sm text-text-secondary",
|
|
141
191
|
children: "No custom fields yet."
|
|
142
|
-
}), /* @__PURE__ */
|
|
192
|
+
}), /* @__PURE__ */ x("p", {
|
|
143
193
|
className: "mt-0.5 text-xs text-text-muted",
|
|
144
194
|
children: "Add fields citizens must fill when they apply (name, dates, choices, uploads…)."
|
|
145
195
|
})]
|
|
146
|
-
}) : /* @__PURE__ */
|
|
196
|
+
}) : /* @__PURE__ */ x("ul", {
|
|
147
197
|
className: "grid gap-2",
|
|
148
|
-
children: t.map((r,
|
|
149
|
-
let
|
|
150
|
-
return /* @__PURE__ */
|
|
151
|
-
draggable: !
|
|
152
|
-
onDragStart: () =>
|
|
198
|
+
children: t.map((r, a) => {
|
|
199
|
+
let o = M[r.type], _ = o.icon, F = c === a;
|
|
200
|
+
return /* @__PURE__ */ S("li", {
|
|
201
|
+
draggable: !i && !F,
|
|
202
|
+
onDragStart: () => y(a),
|
|
153
203
|
onDragOver: (e) => {
|
|
154
|
-
e.preventDefault(), P(
|
|
204
|
+
e.preventDefault(), P(a);
|
|
155
205
|
},
|
|
156
206
|
onDragEnd: () => {
|
|
157
|
-
|
|
207
|
+
y(null), P(null);
|
|
158
208
|
},
|
|
159
209
|
onDrop: (e) => {
|
|
160
|
-
e.preventDefault(),
|
|
210
|
+
e.preventDefault(), U(a);
|
|
161
211
|
},
|
|
162
|
-
className: e("rounded-xl border bg-bg-surface transition-colors",
|
|
163
|
-
children: [/* @__PURE__ */
|
|
212
|
+
className: e("rounded-xl border bg-bg-surface transition-colors", b === a && h !== null && h !== a ? "border-action-primary-bg" : "border-border-seam", h === a && "opacity-60"),
|
|
213
|
+
children: [/* @__PURE__ */ S("div", {
|
|
164
214
|
className: "flex items-center gap-2 px-2.5 py-2",
|
|
165
215
|
children: [
|
|
166
|
-
/* @__PURE__ */
|
|
216
|
+
/* @__PURE__ */ x("span", {
|
|
167
217
|
"aria-hidden": "true",
|
|
168
|
-
className: e("hidden shrink-0 text-text-muted sm:inline-flex", !
|
|
169
|
-
children: /* @__PURE__ */
|
|
218
|
+
className: e("hidden shrink-0 text-text-muted sm:inline-flex", !i && !F ? "cursor-grab" : "cursor-default"),
|
|
219
|
+
children: /* @__PURE__ */ x(p, { className: "h-4 w-4" })
|
|
170
220
|
}),
|
|
171
|
-
/* @__PURE__ */
|
|
172
|
-
className: e("inline-flex size-8 shrink-0 items-center justify-center rounded-lg [&>svg]:size-4",
|
|
173
|
-
children: /* @__PURE__ */
|
|
221
|
+
/* @__PURE__ */ x("span", {
|
|
222
|
+
className: e("inline-flex size-8 shrink-0 items-center justify-center rounded-lg [&>svg]:size-4", o.tone),
|
|
223
|
+
children: /* @__PURE__ */ x(_, {})
|
|
174
224
|
}),
|
|
175
|
-
/* @__PURE__ */
|
|
225
|
+
/* @__PURE__ */ S("div", {
|
|
176
226
|
className: "min-w-0 flex-1",
|
|
177
|
-
children: [/* @__PURE__ */
|
|
227
|
+
children: [/* @__PURE__ */ S("p", {
|
|
178
228
|
className: "truncate text-sm font-medium text-text-primary",
|
|
179
|
-
children: [r.label || /* @__PURE__ */
|
|
229
|
+
children: [r.label || /* @__PURE__ */ x("span", {
|
|
180
230
|
className: "text-text-muted",
|
|
181
231
|
children: "Untitled field"
|
|
182
|
-
}), r.required && /* @__PURE__ */
|
|
232
|
+
}), r.required && /* @__PURE__ */ x("span", {
|
|
183
233
|
className: "ml-1 text-status-error-text",
|
|
184
234
|
children: "*"
|
|
185
235
|
})]
|
|
186
|
-
}), /* @__PURE__ */
|
|
236
|
+
}), /* @__PURE__ */ S("p", {
|
|
187
237
|
className: "truncate text-xs text-text-muted",
|
|
188
|
-
children: [
|
|
238
|
+
children: [
|
|
239
|
+
o.label,
|
|
240
|
+
r.type === "select" && r.options?.length ? ` · ${r.options.length} option${r.options.length === 1 ? "" : "s"}` : "",
|
|
241
|
+
r.showIf && /* @__PURE__ */ S("span", {
|
|
242
|
+
className: "ml-1 inline-flex items-center gap-0.5 text-[var(--color-accent-purple)]",
|
|
243
|
+
children: [/* @__PURE__ */ x(f, {
|
|
244
|
+
className: "inline size-3",
|
|
245
|
+
"aria-hidden": "true"
|
|
246
|
+
}), " conditional"]
|
|
247
|
+
})
|
|
248
|
+
]
|
|
189
249
|
})]
|
|
190
250
|
}),
|
|
191
|
-
/* @__PURE__ */
|
|
251
|
+
/* @__PURE__ */ S("div", {
|
|
192
252
|
className: "flex shrink-0 items-center",
|
|
193
253
|
children: [
|
|
194
|
-
/* @__PURE__ */
|
|
254
|
+
/* @__PURE__ */ x(C, {
|
|
195
255
|
type: "button",
|
|
196
256
|
variant: "ghost",
|
|
197
257
|
size: "icon-sm",
|
|
198
|
-
onClick: () =>
|
|
199
|
-
disabled:
|
|
258
|
+
onClick: () => H(a, a - 1),
|
|
259
|
+
disabled: i || a === 0,
|
|
200
260
|
"aria-label": `Move ${r.label || "field"} up`,
|
|
201
|
-
children: /* @__PURE__ */
|
|
261
|
+
children: /* @__PURE__ */ x(d, { className: "h-4 w-4" })
|
|
202
262
|
}),
|
|
203
|
-
/* @__PURE__ */
|
|
263
|
+
/* @__PURE__ */ x(C, {
|
|
204
264
|
type: "button",
|
|
205
265
|
variant: "ghost",
|
|
206
266
|
size: "icon-sm",
|
|
207
|
-
onClick: () =>
|
|
208
|
-
disabled:
|
|
267
|
+
onClick: () => H(a, a + 1),
|
|
268
|
+
disabled: i || a === t.length - 1,
|
|
209
269
|
"aria-label": `Move ${r.label || "field"} down`,
|
|
210
|
-
children: /* @__PURE__ */
|
|
270
|
+
children: /* @__PURE__ */ x(u, { className: "h-4 w-4" })
|
|
211
271
|
}),
|
|
212
|
-
/* @__PURE__ */
|
|
272
|
+
/* @__PURE__ */ x(C, {
|
|
213
273
|
type: "button",
|
|
214
274
|
variant: "ghost",
|
|
215
275
|
size: "icon-sm",
|
|
216
|
-
onClick: () =>
|
|
217
|
-
disabled:
|
|
276
|
+
onClick: () => m(F ? -1 : a),
|
|
277
|
+
disabled: i,
|
|
218
278
|
"aria-label": F ? "Close field editor" : `Edit ${r.label || "field"}`,
|
|
219
279
|
"aria-expanded": F,
|
|
220
|
-
children:
|
|
280
|
+
children: x(F ? l : g, { className: "h-4 w-4" })
|
|
221
281
|
}),
|
|
222
|
-
/* @__PURE__ */
|
|
282
|
+
/* @__PURE__ */ x(C, {
|
|
223
283
|
type: "button",
|
|
224
284
|
variant: "ghost",
|
|
225
285
|
size: "icon-sm",
|
|
226
|
-
onClick: () =>
|
|
227
|
-
disabled:
|
|
286
|
+
onClick: () => V(a),
|
|
287
|
+
disabled: i,
|
|
228
288
|
"aria-label": `Remove ${r.label || "field"}`,
|
|
229
289
|
className: "text-status-error-text hover:text-status-error-text",
|
|
230
|
-
children: /* @__PURE__ */ v
|
|
290
|
+
children: /* @__PURE__ */ x(v, { className: "h-4 w-4" })
|
|
231
291
|
})
|
|
232
292
|
]
|
|
233
293
|
})
|
|
234
294
|
]
|
|
235
|
-
}), F && /* @__PURE__ */
|
|
295
|
+
}), F && /* @__PURE__ */ S("div", {
|
|
236
296
|
className: "grid gap-3 border-t border-border-seam px-3 py-3",
|
|
237
297
|
children: [
|
|
238
|
-
/* @__PURE__ */
|
|
298
|
+
/* @__PURE__ */ S("div", {
|
|
239
299
|
className: "grid gap-3 sm:grid-cols-2",
|
|
240
|
-
children: [/* @__PURE__ */
|
|
300
|
+
children: [/* @__PURE__ */ S("div", {
|
|
241
301
|
className: "grid gap-1.5",
|
|
242
|
-
children: [/* @__PURE__ */
|
|
243
|
-
htmlFor: `${
|
|
302
|
+
children: [/* @__PURE__ */ x(T, {
|
|
303
|
+
htmlFor: `${s}-label-${a}`,
|
|
244
304
|
children: "Field label"
|
|
245
|
-
}), /* @__PURE__ */
|
|
246
|
-
id: `${
|
|
305
|
+
}), /* @__PURE__ */ x(w, {
|
|
306
|
+
id: `${s}-label-${a}`,
|
|
247
307
|
value: r.label,
|
|
248
308
|
autoFocus: !0,
|
|
249
309
|
placeholder: "e.g. Business Name",
|
|
250
|
-
onChange: (e) =>
|
|
251
|
-
onBlur: () =>
|
|
310
|
+
onChange: (e) => B(a, { label: e.target.value }),
|
|
311
|
+
onBlur: () => B(a, { key: I(r.label, t, a) })
|
|
252
312
|
})]
|
|
253
|
-
}), /* @__PURE__ */
|
|
313
|
+
}), /* @__PURE__ */ S("div", {
|
|
254
314
|
className: "grid gap-1.5",
|
|
255
|
-
children: [/* @__PURE__ */
|
|
315
|
+
children: [/* @__PURE__ */ x(T, { children: "Field type" }), /* @__PURE__ */ S(E, {
|
|
256
316
|
value: r.type,
|
|
257
|
-
onValueChange: (e) =>
|
|
258
|
-
children: [/* @__PURE__ */
|
|
317
|
+
onValueChange: (e) => B(a, { type: e }),
|
|
318
|
+
children: [/* @__PURE__ */ x(k, {
|
|
259
319
|
"aria-label": "Field type",
|
|
260
|
-
children: /* @__PURE__ */
|
|
261
|
-
}), /* @__PURE__ */
|
|
320
|
+
children: /* @__PURE__ */ x(A, {})
|
|
321
|
+
}), /* @__PURE__ */ x(D, { children: N.map((e) => /* @__PURE__ */ x(O, {
|
|
262
322
|
value: e,
|
|
263
|
-
children:
|
|
323
|
+
children: M[e].label
|
|
264
324
|
}, e)) })]
|
|
265
325
|
})]
|
|
266
326
|
})]
|
|
267
327
|
}),
|
|
268
|
-
r.type === "select" && /* @__PURE__ */
|
|
328
|
+
r.type === "select" && /* @__PURE__ */ S("div", {
|
|
269
329
|
className: "grid gap-1.5",
|
|
270
|
-
children: [/* @__PURE__ */
|
|
271
|
-
htmlFor: `${
|
|
330
|
+
children: [/* @__PURE__ */ x(T, {
|
|
331
|
+
htmlFor: `${s}-opts-${a}`,
|
|
272
332
|
children: "Choices"
|
|
273
|
-
}), /* @__PURE__ */
|
|
274
|
-
id: `${
|
|
333
|
+
}), /* @__PURE__ */ x(n, {
|
|
334
|
+
id: `${s}-opts-${a}`,
|
|
275
335
|
value: r.options ?? [],
|
|
276
|
-
onChange: (e) =>
|
|
336
|
+
onChange: (e) => B(a, { options: e }),
|
|
277
337
|
placeholder: "Add a choice and press Enter…"
|
|
278
338
|
})]
|
|
279
339
|
}),
|
|
280
|
-
/* @__PURE__ */
|
|
340
|
+
/* @__PURE__ */ S("label", {
|
|
281
341
|
className: "flex items-center justify-between gap-3 rounded-lg bg-bg-sunken/50 px-3 py-2",
|
|
282
|
-
children: [/* @__PURE__ */
|
|
342
|
+
children: [/* @__PURE__ */ x("span", {
|
|
283
343
|
className: "text-sm text-text-primary",
|
|
284
344
|
children: "Required field"
|
|
285
|
-
}), /* @__PURE__ */
|
|
345
|
+
}), /* @__PURE__ */ x(j, {
|
|
286
346
|
checked: r.required,
|
|
287
|
-
onCheckedChange: (e) =>
|
|
347
|
+
onCheckedChange: (e) => B(a, { required: e }),
|
|
288
348
|
"aria-label": "Required field"
|
|
289
349
|
})]
|
|
350
|
+
}),
|
|
351
|
+
/* @__PURE__ */ x(z, {
|
|
352
|
+
groupId: s,
|
|
353
|
+
index: a,
|
|
354
|
+
field: r,
|
|
355
|
+
priorFields: t.slice(0, a).filter((e) => e.key),
|
|
356
|
+
onChange: (e) => B(a, { showIf: e })
|
|
290
357
|
})
|
|
291
358
|
]
|
|
292
359
|
})]
|
|
293
|
-
}, `${
|
|
360
|
+
}, `${s}-${a}`);
|
|
294
361
|
})
|
|
295
362
|
})]
|
|
296
363
|
});
|
|
297
364
|
}
|
|
298
365
|
//#endregion
|
|
299
|
-
export {
|
|
366
|
+
export { B as FormFieldBuilder, F as fieldsToSchema, P as schemaToFields };
|
|
300
367
|
|
|
301
368
|
//# sourceMappingURL=FormFieldBuilder.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"FormFieldBuilder.js","names":[],"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 * ]\n *\n * This is the EXACT shape `NewApplicationPage` normalises and renders, so a field\n * added here shows up verbatim in the citizen application form. `type` is one of\n * text | textarea | number | date | select | 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} 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';\n\n/** The canonical field type set the citizen application renderer understands. */\nexport type BuilderFieldType = 'text' | 'textarea' | 'number' | 'date' | 'select' | 'file';\n\nexport interface BuilderField {\n key: string;\n label: string;\n type: BuilderFieldType;\n required: boolean;\n options?: string[];\n}\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.\n */\nexport function schemaToFields(schema: unknown): BuilderField[] {\n const coerceType = (raw: unknown, hasOptions: boolean): BuilderFieldType => {\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 const toField = (raw: unknown, fallback: string): BuilderField | 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 ?? fallback);\n const key = String(r.key ?? r.name ?? r.id ?? (slugify(label) || fallback));\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 return {\n key,\n label,\n type,\n required: Boolean(r.required),\n ...(type === 'select' ? { options: options ?? [] } : {}),\n };\n };\n\n if (Array.isArray(schema)) {\n return schema.map((f, i) => toField(f, `field_${i + 1}`)).filter((f): f is BuilderField => !!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 BuilderField => !!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 BuilderField => !!f);\n }\n }\n return [];\n}\n\n/** Serialise BuilderField[] to the array `formSchema` payload (or null when empty). */\nexport function fieldsToSchema(fields: BuilderField[]): BuilderField[] | 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 }));\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\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 const commit = (next: BuilderField[]) => onChange(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 </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 </div>\n )}\n </li>\n );\n })}\n </ul>\n )}\n </div>\n );\n}\n"],"mappings":";;;;;;;;AA+DA,IAAM,IAA0F;CAC9F,MAAM;EACJ,OAAO;EACP,MAAM;EACN,MAAM;CACR;CACA,UAAU;EACR,OAAO;EACP,MAAM;EACN,MAAM;CACR;CACA,QAAQ;EACN,OAAO;EACP,MAAM;EACN,MAAM;CACR;CACA,MAAM;EACJ,OAAO;EACP,MAAM;EACN,MAAM;CACR;CACA,QAAQ;EACN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AAET"}
|
|
1
|
+
{"version":3,"file":"FormFieldBuilder.js","names":[],"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,IAAM,IAA0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SAAS,GAAG,EAAQ,QAAQ;mBAAS;QAAc,CAAA,GAC1D,kBAAC,GAAD;SACE,IAAI,GAAG,EAAQ,QAAQ;SACvB,OAAO,EAAM,WAAW,CAAC;SACzB,WAAW,MAAS,EAAY,GAAO,EAAE,SAAS,EAAK,CAAC;SACxD,aAAY;QACb,CAAA,CACE;;OAGP,kBAAC,SAAD;QAAO,WAAU;kBAAjB,CACE,kBAAC,QAAD;SAAM,WAAU;mBAA4B;QAAoB,CAAA,GAChE,kBAAC,GAAD;SACE,SAAS,EAAM;SACf,kBAAkB,MAAY,EAAY,GAAO,EAAE,UAAU,EAAQ,CAAC;SACtE,cAAW;QACZ,CAAA,CACI;;OAEP,kBAAC,GAAD;QACW;QACF;QACA;QACP,aAAa,EAAM,MAAM,GAAG,CAAK,EAAE,QAAQ,MAAM,EAAE,GAAG;QACtD,WAAW,MAAW,EAAY,GAAO,EAAE,UAAO,CAAC;OACpD,CAAA;MACE;OAEL;OA5KG,GAAG,EAAQ,GAAG,GA4KjB;GAER,CAAC;EACC,CAAA,CAEH;;AAET"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ServiceFormDialog.d.ts","sourceRoot":"","sources":["../../../../src/govcitizenhub/pages/services/ServiceFormDialog.tsx"],"names":[],"mappings":"AACA;;;;;;;GAOG;
|
|
1
|
+
{"version":3,"file":"ServiceFormDialog.d.ts","sourceRoot":"","sources":["../../../../src/govcitizenhub/pages/services/ServiceFormDialog.tsx"],"names":[],"mappings":"AACA;;;;;;;GAOG;AAkCH,OAAO,KAAK,EAAE,UAAU,EAAkC,MAAM,aAAa,CAAC;AAgB9E,UAAU,sBAAsB;IAC9B,IAAI,EAAE,OAAO,CAAC;IACd,YAAY,EAAE,CAAC,IAAI,EAAE,OAAO,KAAK,IAAI,CAAC;IACtC,OAAO,CAAC,EAAE,UAAU,GAAG,IAAI,CAAC;IAC5B,4EAA4E;IAC5E,eAAe,CAAC,EAAE,MAAM,CAAC;IACzB,OAAO,CAAC,EAAE,CAAC,OAAO,EAAE,UAAU,KAAK,IAAI,CAAC;CACzC;AAED,wBAAgB,iBAAiB,CAAC,EAChC,IAAI,EACJ,YAAY,EACZ,OAAO,EACP,eAAe,EACf,OAAO,GACR,EAAE,sBAAsB,2CAqXxB"}
|