@digiform/wizard 0.3.1 → 0.3.2
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/features/form-runtime/components/FormFooter.d.ts +5 -0
- package/features/form-runtime/hooks/useValidationEvents.d.ts +0 -1
- package/features/state-management/machines/formMachine.d.ts +3 -0
- package/features/state-management/machines/types.d.ts +4 -0
- package/features/state-management/machines/useFormMachine.d.ts +18 -0
- package/package.json +1 -3
- package/styles.css +1 -1
- package/wizard/src/features/api-integration/services/ApiCallService.js +65 -74
- package/wizard/src/features/dialog-system/components/ActionDialog/ActionDialog.js +39 -43
- package/wizard/src/features/dialog-system/components/ConfirmationDialog/ConfirmationDialog.js +37 -41
- package/wizard/src/features/dialog-system/components/EmailVerificationDialog/EmailVerificationDialog.js +44 -45
- package/wizard/src/features/form-runtime/FormWizard/FormWizard.js +54 -79
- package/wizard/src/features/form-runtime/components/FormFooter.js +53 -184
- package/wizard/src/features/form-runtime/components/FormSection/FormSection.js +150 -194
- package/wizard/src/features/form-runtime/components/FormStep/FormStep.js +83 -92
- package/wizard/src/features/form-runtime/components/StepProgressIndicator/StepProgressIndicator.js +24 -30
- package/wizard/src/features/form-runtime/config/templateLoader.js +48 -55
- package/wizard/src/features/form-runtime/hooks/useComponentTriggers.js +44 -63
- package/wizard/src/features/form-runtime/hooks/useFieldEventHandlers.js +26 -40
- package/wizard/src/features/form-runtime/hooks/useValidationEvents.js +22 -25
- package/wizard/src/features/form-runtime/utils/formDirtyStateSync.js +26 -37
- package/wizard/src/features/form-runtime/utils/logger.js +12 -12
- package/wizard/src/features/state-management/machines/actions/navigationActions.js +13 -8
- package/wizard/src/features/state-management/machines/componentTriggerEngine.js +167 -432
- package/wizard/src/features/state-management/machines/formMachine.js +558 -677
- package/wizard/src/features/state-management/machines/useFormMachine.js +172 -190
- package/wizard/src/features/trigger-action-system/components/ActionManager.js +35 -86
- package/wizard/src/features/validation-system/validation/SchemaBuilder.js +28 -82
- package/wizard/src/features/validation-system/validation/ValidationCache.js +11 -27
- package/wizard/src/features/validation-system/validation/ValidationExecutor.js +26 -58
- package/features/form-runtime/utils/formSaver.d.ts +0 -22
- package/features/state-management/components/ValidationBuilder/ValidationBuilder.d.ts +0 -9
- package/features/state-management/machines/__tests__/setup.d.ts +0 -0
- package/features/state-management/machines/__tests__/vitest.config.d.ts +0 -2
- package/features/state-management/machines/actions/validationActions.d.ts +0 -68
- package/features/state-management/machines/lazyLoading.d.ts +0 -34
- package/features/state-management/machines/validation/index.d.ts +0 -5
- package/features/state-management/machines/validation/validateField.d.ts +0 -2
- package/features/state-management/machines/validation/validateForm.d.ts +0 -2
- package/features/state-management/machines/validation/validateSection.d.ts +0 -2
- package/features/state-management/machines/validation/validateStep.d.ts +0 -2
- package/features/state-management/machines/validation/validationTypes.d.ts +0 -1
- package/features/trigger-action-system/components/FieldWarning/FieldWarning.d.ts +0 -20
|
@@ -1,270 +1,226 @@
|
|
|
1
1
|
"use client";
|
|
2
|
-
import { jsx as
|
|
3
|
-
import { clsx as
|
|
4
|
-
import { X as
|
|
5
|
-
import { memo as
|
|
6
|
-
import
|
|
2
|
+
import { jsx as u, jsxs as E } from "react/jsx-runtime";
|
|
3
|
+
import { clsx as _ } from "clsx";
|
|
4
|
+
import { X as k, Edit as P, Check as L } from "lucide-react";
|
|
5
|
+
import { memo as M, useState as w, useMemo as v, useEffect as D, useCallback as g } from "react";
|
|
6
|
+
import d from "./FormSection.module.css.js";
|
|
7
7
|
import { useFormContext as R } from "../../hooks/useFormContext.js";
|
|
8
|
-
import
|
|
9
|
-
import { useFormMachine as
|
|
8
|
+
import B from "../FormField.js";
|
|
9
|
+
import { useFormMachine as G } from "../../../state-management/machines/useFormMachine.js";
|
|
10
10
|
import { evaluateVisibility as U } from "../../utils/visibilityUtils.js";
|
|
11
|
-
import { ComponentTriggerEngine as
|
|
12
|
-
import { Heading as
|
|
13
|
-
const
|
|
14
|
-
const [
|
|
15
|
-
validateSection:
|
|
11
|
+
import { ComponentTriggerEngine as j } from "../../../state-management/machines/componentTriggerEngine.js";
|
|
12
|
+
import { Heading as H, Button as z } from "@rijkshuisstijl-community/components-react";
|
|
13
|
+
const W = M(({ section: t }) => {
|
|
14
|
+
const [o, r, p] = G(), {
|
|
15
|
+
validateSection: T,
|
|
16
16
|
validateField: C,
|
|
17
|
-
startSectionEdit:
|
|
18
|
-
cancelSectionEdit:
|
|
19
|
-
} = p,
|
|
20
|
-
if (!
|
|
17
|
+
startSectionEdit: N,
|
|
18
|
+
cancelSectionEdit: y
|
|
19
|
+
} = p, s = R(), [f, h] = w(!1), O = v(() => {
|
|
20
|
+
if (!t.visibilityConditions)
|
|
21
21
|
return !0;
|
|
22
|
-
const
|
|
23
|
-
return U(
|
|
24
|
-
}, [
|
|
22
|
+
const e = o.context.data;
|
|
23
|
+
return U(t.visibilityConditions, e);
|
|
24
|
+
}, [t.visibilityConditions, o.context.data]), a = v(
|
|
25
25
|
() => ({
|
|
26
|
-
title:
|
|
27
|
-
components:
|
|
28
|
-
mode:
|
|
26
|
+
title: t.title,
|
|
27
|
+
components: t.components || [],
|
|
28
|
+
mode: t.mode || "default",
|
|
29
29
|
// Default to always-editable mode when no mode is specified
|
|
30
|
-
editText:
|
|
31
|
-
cancelText:
|
|
32
|
-
saveText:
|
|
33
|
-
showTitle:
|
|
34
|
-
showActionLink:
|
|
30
|
+
editText: t.editText || "Edit",
|
|
31
|
+
cancelText: t.cancelText || "Cancel",
|
|
32
|
+
saveText: t.saveText || "Save",
|
|
33
|
+
showTitle: t.showTitle ?? !0,
|
|
34
|
+
showActionLink: t.showActionLink ?? !0
|
|
35
35
|
}),
|
|
36
|
-
[
|
|
37
|
-
),
|
|
38
|
-
const
|
|
39
|
-
return
|
|
40
|
-
}, [
|
|
41
|
-
() =>
|
|
42
|
-
[
|
|
43
|
-
),
|
|
44
|
-
() =>
|
|
45
|
-
[
|
|
36
|
+
[t]
|
|
37
|
+
), V = v(() => {
|
|
38
|
+
const e = a.mode === "isEditable" ? "default" : a.mode;
|
|
39
|
+
return e === "readOnly" ? !0 : e === "editable" ? !f : !1;
|
|
40
|
+
}, [a.mode, f]), n = v(
|
|
41
|
+
() => a.components.map((e) => e.id),
|
|
42
|
+
[a.components]
|
|
43
|
+
), S = v(
|
|
44
|
+
() => o.context.activeDialog,
|
|
45
|
+
[o.context.activeDialog]
|
|
46
46
|
);
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
}) && (console.log(
|
|
54
|
-
"🔥 FormSection: All fields clean after verification, clearing alerts and exiting edit mode"
|
|
55
|
-
), n.forEach((t) => {
|
|
56
|
-
d({
|
|
47
|
+
D(() => {
|
|
48
|
+
a.mode !== "editable" || !f || S && !o.context.activeDialog && n.every((c) => {
|
|
49
|
+
const i = o.context.data[c], m = o.context.componentOriginalValues[c];
|
|
50
|
+
return i === m?.value;
|
|
51
|
+
}) && (n.forEach((c) => {
|
|
52
|
+
r({
|
|
57
53
|
type: "CLEAR_COMPONENT_ALERT",
|
|
58
|
-
componentId:
|
|
54
|
+
componentId: c
|
|
59
55
|
});
|
|
60
|
-
}),
|
|
56
|
+
}), h(!1));
|
|
61
57
|
}, [
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
58
|
+
o.context.activeDialog,
|
|
59
|
+
o.context.data,
|
|
60
|
+
o.context.componentOriginalValues,
|
|
65
61
|
n,
|
|
66
|
-
|
|
67
|
-
|
|
62
|
+
r,
|
|
63
|
+
a.mode,
|
|
68
64
|
f,
|
|
69
|
-
|
|
65
|
+
S
|
|
70
66
|
]);
|
|
71
|
-
const
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
const
|
|
79
|
-
|
|
80
|
-
const l = a.context.componentOriginalValues[t];
|
|
81
|
-
(!l || !l.isPopulated) && (console.log(
|
|
82
|
-
`Setting original value for ${t} on edit start:`,
|
|
83
|
-
c
|
|
84
|
-
), d({
|
|
67
|
+
const I = g(() => {
|
|
68
|
+
n.map((e) => ({
|
|
69
|
+
fieldId: e,
|
|
70
|
+
value: s.getFieldValue(e)
|
|
71
|
+
})), n.forEach((e) => {
|
|
72
|
+
const c = s.getFieldValue(e);
|
|
73
|
+
p.setData(e, c);
|
|
74
|
+
const i = o.context.componentOriginalValues[e];
|
|
75
|
+
(!i || !i.isPopulated) && r({
|
|
85
76
|
type: "SET_COMPONENT_ORIGINAL_VALUE",
|
|
86
|
-
componentId:
|
|
77
|
+
componentId: e,
|
|
87
78
|
value: c,
|
|
88
79
|
source: "edit_start"
|
|
89
|
-
})
|
|
90
|
-
}),
|
|
80
|
+
});
|
|
81
|
+
}), N(t.id, n), h(!0);
|
|
91
82
|
}, [
|
|
92
|
-
|
|
93
|
-
|
|
83
|
+
N,
|
|
84
|
+
t.id,
|
|
94
85
|
n,
|
|
95
|
-
|
|
86
|
+
s,
|
|
96
87
|
p,
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
]),
|
|
100
|
-
const
|
|
101
|
-
|
|
102
|
-
const
|
|
103
|
-
|
|
104
|
-
`Restoring field ${t}: ${l} -> ${c}`
|
|
105
|
-
), c !== void 0 && m.setFieldValue(t, c), console.log(
|
|
106
|
-
`🧹 [FormSection] Dismissing alerts for field ${t} after cancel edit`
|
|
107
|
-
), d({
|
|
88
|
+
o.context.componentOriginalValues,
|
|
89
|
+
r
|
|
90
|
+
]), F = g(() => {
|
|
91
|
+
const e = o.context.sectionBackups[t.id];
|
|
92
|
+
e ? n.forEach((c) => {
|
|
93
|
+
const i = e[c];
|
|
94
|
+
s.getFieldValue(c), i !== void 0 && s.setFieldValue(c, i), r({
|
|
108
95
|
type: "DISMISS_COMPONENT_ALERT",
|
|
109
|
-
componentId:
|
|
96
|
+
componentId: c
|
|
110
97
|
// Don't specify alertId to clear all alerts for this component
|
|
111
98
|
});
|
|
112
|
-
}) : console.warn("No backup data found for section:",
|
|
99
|
+
}) : console.warn("No backup data found for section:", t.id), y(t.id), h(!1);
|
|
113
100
|
}, [
|
|
114
|
-
|
|
115
|
-
|
|
101
|
+
o.context.sectionBackups,
|
|
102
|
+
t.id,
|
|
116
103
|
n,
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
]), A =
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
), n.forEach((c) => {
|
|
125
|
-
const l = new CustomEvent("triggerFieldValidation", {
|
|
126
|
-
detail: { fieldId: c, sectionId: e.id }
|
|
104
|
+
s,
|
|
105
|
+
y,
|
|
106
|
+
r
|
|
107
|
+
]), A = g(async () => {
|
|
108
|
+
n.forEach((i) => {
|
|
109
|
+
const m = new CustomEvent("triggerFieldValidation", {
|
|
110
|
+
detail: { fieldId: i, sectionId: t.id }
|
|
127
111
|
});
|
|
128
|
-
|
|
129
|
-
`FormSection: Dispatching validation trigger for field ${c}`
|
|
130
|
-
), window.dispatchEvent(l);
|
|
112
|
+
window.dispatchEvent(m);
|
|
131
113
|
});
|
|
132
|
-
let
|
|
133
|
-
const
|
|
134
|
-
await Promise.all(
|
|
135
|
-
for (const
|
|
136
|
-
const
|
|
137
|
-
if (
|
|
138
|
-
|
|
114
|
+
let e = !1;
|
|
115
|
+
const c = n.map((i) => C(i));
|
|
116
|
+
await Promise.all(c);
|
|
117
|
+
for (const i of n) {
|
|
118
|
+
const m = s.getFieldMeta(i);
|
|
119
|
+
if (m.errors && m.errors.length > 0) {
|
|
120
|
+
e = !0;
|
|
139
121
|
break;
|
|
140
122
|
}
|
|
141
123
|
}
|
|
142
|
-
if (
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
"🎯 [FormSection] Checking for dirty fields with verification requirements"
|
|
150
|
-
);
|
|
151
|
-
const c = p.config, l = a.context.currentStepIndex, v = G.createExecutionPlan(
|
|
152
|
-
c,
|
|
124
|
+
if (T(t.id), !e) {
|
|
125
|
+
n.forEach((l) => {
|
|
126
|
+
const x = s.getFieldValue(l);
|
|
127
|
+
p.setData(l, x);
|
|
128
|
+
});
|
|
129
|
+
const i = p.config, m = o.context.currentStepIndex, b = j.createExecutionPlan(
|
|
130
|
+
i,
|
|
153
131
|
"save",
|
|
154
|
-
|
|
155
|
-
|
|
132
|
+
m,
|
|
133
|
+
o.context
|
|
156
134
|
);
|
|
157
|
-
if (
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
executions: v.executions.map((i) => ({
|
|
162
|
-
componentId: i.componentId,
|
|
163
|
-
triggerId: i.trigger.id,
|
|
164
|
-
actionsCount: i.actions.length,
|
|
165
|
-
actions: i.actions.map((s) => ({
|
|
166
|
-
id: s.id,
|
|
167
|
-
type: s.type,
|
|
168
|
-
contexts: s.contexts
|
|
169
|
-
}))
|
|
170
|
-
}))
|
|
171
|
-
}), v.totalActions > 0) {
|
|
172
|
-
v.executions.forEach((i) => {
|
|
173
|
-
i.actions.forEach((s) => {
|
|
174
|
-
console.log(
|
|
175
|
-
`🎯 [FormSection] Executing ${s.type} action for component ${i.componentId}`,
|
|
176
|
-
{
|
|
177
|
-
componentId: i.componentId,
|
|
178
|
-
triggerId: i.trigger.id,
|
|
179
|
-
actionId: s.id,
|
|
180
|
-
actionType: s.type
|
|
181
|
-
}
|
|
182
|
-
), d({
|
|
135
|
+
if (b.totalActions > 0) {
|
|
136
|
+
b.executions.forEach((l) => {
|
|
137
|
+
l.actions.forEach((x) => {
|
|
138
|
+
r({
|
|
183
139
|
type: "TRIGGER_COMPONENT_ACTION",
|
|
184
|
-
componentId:
|
|
185
|
-
triggerId:
|
|
186
|
-
actionId:
|
|
140
|
+
componentId: l.componentId,
|
|
141
|
+
triggerId: l.trigger.id,
|
|
142
|
+
actionId: x.id,
|
|
187
143
|
eventType: "sectionSave"
|
|
188
144
|
});
|
|
189
145
|
});
|
|
190
146
|
});
|
|
191
147
|
return;
|
|
192
148
|
}
|
|
193
|
-
n.forEach((
|
|
194
|
-
|
|
149
|
+
n.forEach((l) => {
|
|
150
|
+
r({
|
|
195
151
|
type: "CLEAR_COMPONENT_ALERT",
|
|
196
|
-
componentId:
|
|
152
|
+
componentId: l
|
|
197
153
|
});
|
|
198
|
-
}), n.forEach((
|
|
199
|
-
|
|
154
|
+
}), n.forEach((l) => {
|
|
155
|
+
r({
|
|
200
156
|
type: "UPDATE_COMPONENT_ORIGINAL_VALUE",
|
|
201
|
-
componentId:
|
|
157
|
+
componentId: l
|
|
202
158
|
});
|
|
203
|
-
}),
|
|
159
|
+
}), h(!1);
|
|
204
160
|
}
|
|
205
161
|
}, [
|
|
206
162
|
n,
|
|
207
163
|
C,
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
164
|
+
s,
|
|
165
|
+
T,
|
|
166
|
+
t.id,
|
|
211
167
|
p,
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
168
|
+
o.context.currentStepIndex,
|
|
169
|
+
o.context,
|
|
170
|
+
r
|
|
215
171
|
]);
|
|
216
|
-
return /* @__PURE__ */
|
|
172
|
+
return /* @__PURE__ */ u(
|
|
217
173
|
"div",
|
|
218
174
|
{
|
|
219
175
|
style: {
|
|
220
|
-
display:
|
|
176
|
+
display: O ? "block" : "none"
|
|
221
177
|
},
|
|
222
|
-
"data-section-id":
|
|
223
|
-
"data-visible":
|
|
224
|
-
children: /* @__PURE__ */
|
|
225
|
-
|
|
226
|
-
/* @__PURE__ */
|
|
227
|
-
|
|
178
|
+
"data-section-id": t.id,
|
|
179
|
+
"data-visible": O,
|
|
180
|
+
children: /* @__PURE__ */ E("div", { className: _("form-section", d.section), children: [
|
|
181
|
+
a.showTitle && /* @__PURE__ */ E("div", { className: d.sectionHeader, children: [
|
|
182
|
+
/* @__PURE__ */ u(H, { level: 3, children: a.title }),
|
|
183
|
+
a.mode === "editable" && a.showActionLink && /* @__PURE__ */ u("div", { children: f ? /* @__PURE__ */ E(
|
|
228
184
|
"button",
|
|
229
185
|
{
|
|
230
186
|
type: "button",
|
|
231
|
-
onClick:
|
|
232
|
-
className:
|
|
187
|
+
onClick: F,
|
|
188
|
+
className: d.cancelButton,
|
|
233
189
|
children: [
|
|
234
|
-
/* @__PURE__ */
|
|
235
|
-
|
|
190
|
+
/* @__PURE__ */ u(k, { className: d.iconSm }),
|
|
191
|
+
a.cancelText
|
|
236
192
|
]
|
|
237
193
|
}
|
|
238
|
-
) : /* @__PURE__ */
|
|
194
|
+
) : /* @__PURE__ */ E(
|
|
239
195
|
"button",
|
|
240
196
|
{
|
|
241
197
|
type: "button",
|
|
242
|
-
onClick:
|
|
243
|
-
className:
|
|
198
|
+
onClick: I,
|
|
199
|
+
className: d.editButton,
|
|
244
200
|
children: [
|
|
245
|
-
/* @__PURE__ */
|
|
246
|
-
|
|
201
|
+
/* @__PURE__ */ u(P, { className: d.iconSm }),
|
|
202
|
+
a.editText
|
|
247
203
|
]
|
|
248
204
|
}
|
|
249
205
|
) })
|
|
250
206
|
] }),
|
|
251
|
-
/* @__PURE__ */
|
|
252
|
-
|
|
253
|
-
|
|
207
|
+
/* @__PURE__ */ E("div", { className: d.sectionContent, children: [
|
|
208
|
+
a.components.map((e) => /* @__PURE__ */ u(
|
|
209
|
+
B,
|
|
254
210
|
{
|
|
255
|
-
component:
|
|
256
|
-
readOnly:
|
|
211
|
+
component: e,
|
|
212
|
+
readOnly: V
|
|
257
213
|
},
|
|
258
|
-
|
|
214
|
+
e.id
|
|
259
215
|
)),
|
|
260
|
-
f && /* @__PURE__ */
|
|
261
|
-
|
|
216
|
+
f && /* @__PURE__ */ u("div", { className: d.saveButtonsWrapper, children: /* @__PURE__ */ E(
|
|
217
|
+
z,
|
|
262
218
|
{
|
|
263
219
|
appearance: "primary-action-button",
|
|
264
220
|
onClick: A,
|
|
265
221
|
children: [
|
|
266
|
-
/* @__PURE__ */
|
|
267
|
-
|
|
222
|
+
/* @__PURE__ */ u(L, { className: d.iconSm }),
|
|
223
|
+
a.saveText
|
|
268
224
|
]
|
|
269
225
|
}
|
|
270
226
|
) })
|
|
@@ -273,7 +229,7 @@ const H = w(({ section: e }) => {
|
|
|
273
229
|
}
|
|
274
230
|
);
|
|
275
231
|
});
|
|
276
|
-
|
|
232
|
+
W.displayName = "FormSection";
|
|
277
233
|
export {
|
|
278
|
-
|
|
234
|
+
W as default
|
|
279
235
|
};
|