@digiform/wizard 0.2.10 → 0.2.16
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/core/src/types/api.js +12 -0
- package/core/src/types/form-config.js +60 -0
- package/core/src/types/form-wizard-config-schema.js +113 -0
- package/core/src/types/guards.js +19 -0
- package/core/src/types/validation.js +61 -0
- package/core/src/utils/apiBodyUtils.js +95 -0
- package/features/api-integration.d.ts +2 -0
- package/features/api-integration.js +17 -0
- package/features/dialog-system.d.ts +2 -0
- package/features/dialog-system.js +9 -0
- package/features/form-runtime.d.ts +2 -0
- package/features/form-runtime.js +63 -0
- package/features/state-management.d.ts +2 -0
- package/features/state-management.js +21 -0
- package/features/trigger-action-system.d.ts +2 -0
- package/features/trigger-action-system.js +12 -0
- package/features/validation-system.d.ts +2 -0
- package/features/validation-system.js +23 -0
- package/index.js +108 -17470
- package/package.json +41 -30
- package/styles.css +1 -4
- package/ui/src/component-registry/renderComponent.js +11 -0
- package/ui/src/components/FormLayout/FormLayout.js +135 -0
- package/ui/src/components/FormLayout/FormLayout.module.css.js +20 -0
- package/ui/src/components/GridLayout/GridLayout.js +62 -0
- package/ui/src/components/GridLayout/GridLayout.module.css.js +16 -0
- package/ui/src/components/GridLayoutColumn/GridLayoutColumn.js +37 -0
- package/ui/src/components/GridLayoutColumn/GridLayoutColumn.module.css.js +10 -0
- package/ui/src/components/ProgressLoaderBar/ProgressLoaderBar.js +108 -0
- package/ui/src/components/ProgressLoaderBar/ProgressLoaderBar.module.css.js +20 -0
- package/ui/src/components/ProgressLoaderBar/useProgressAnimation.js +31 -0
- package/ui/src/components/ValidationCode/ValidationCode.js +198 -0
- package/ui/src/components/ValidationCode/ValidationCode.module.css.js +20 -0
- package/ui/src/components/alert/alert.js +30 -0
- package/ui/src/components/alert/alert.module.css.js +14 -0
- package/ui/src/components/badge/badge.js +20 -0
- package/ui/src/components/badge/badge.module.css.js +12 -0
- package/ui/src/components/box/box.js +8 -0
- package/ui/src/components/box/box.module.css.js +8 -0
- package/ui/src/components/button/button.js +25 -0
- package/ui/src/components/button/button.module.css.js +18 -0
- package/ui/src/components/card/card.js +106 -0
- package/ui/src/components/card/card.module.css.js +44 -0
- package/ui/src/components/checkbox/checkbox.js +20 -0
- package/ui/src/components/checkbox/checkbox.module.css.js +10 -0
- package/ui/src/components/dialog/dialog.js +67 -0
- package/ui/src/components/dialog/dialog.module.css.js +20 -0
- package/ui/src/components/form-header-base/form-header-base.js +59 -0
- package/ui/src/components/form-header-base/form-header-base.module.css.js +14 -0
- package/ui/src/components/input/input.js +20 -0
- package/ui/src/components/input/input.module.css.js +8 -0
- package/ui/src/components/radio-group/radio-group.js +30 -0
- package/ui/src/components/radio-group/radio-group.module.css.js +14 -0
- package/ui/src/components/select/select.js +115 -0
- package/ui/src/components/select/select.module.css.js +32 -0
- package/ui/src/components/sheet/sheet.js +71 -0
- package/ui/src/components/sheet/sheet.module.css.js +46 -0
- package/ui/src/components/textarea/textarea.js +19 -0
- package/ui/src/components/textarea/textarea.module.css.js +8 -0
- package/ui/src/design-system/components/FormFieldWrapper.js +16 -0
- package/ui/src/lib/assets/icons/Check.js +26 -0
- package/ui/src/lib/assets/icons/ChevronRight.js +26 -0
- package/ui/src/lib/error-boundaries/BaseErrorBoundary.js +155 -0
- package/ui/src/lib/error-boundaries/ComponentErrorBoundary.js +153 -0
- package/ui/src/lib/error-boundaries/FormWizardErrorBoundary.js +107 -0
- package/ui/src/lib/logger.js +106 -0
- package/ui/src/lib/providers/FormEditingContext.js +21 -0
- package/ui/src/lib/queryClient.js +26 -0
- package/ui/src/lib/types/guards.js +11 -0
- package/ui/src/lib/utils/componentUtils.js +38 -0
- package/ui/src/lib/utils/templateDialogResolver.js +85 -0
- package/ui/src/lib/utils/templateUtils.js +52 -0
- package/ui/src/theme/ThemeProvider.js +15 -0
- package/wizard/src/features/api-integration/components/EnhancedActionExecutor/EnhancedActionExecutor.js +370 -0
- package/wizard/src/features/api-integration/services/ActionExecutor.js +339 -0
- package/wizard/src/features/api-integration/services/ApiCallExecutor.js +6 -0
- package/wizard/src/features/api-integration/services/ApiCallService.js +309 -0
- package/wizard/src/features/api-integration/services/DialogExecutor.js +6 -0
- package/wizard/src/features/api-integration/services/GenericTriggerService.js +284 -0
- package/wizard/src/features/api-integration/services/NavigationExecutor.js +6 -0
- package/wizard/src/features/dialog-system/components/ActionDialog/ActionDialog.js +115 -0
- package/wizard/src/features/dialog-system/components/ActionDialog/ActionDialog.module.css.js +29 -0
- package/wizard/src/features/dialog-system/components/ConfirmationDialog/ConfirmationDialog.js +64 -0
- package/wizard/src/features/dialog-system/components/ConfirmationDialog/ConfirmationDialog.module.css.js +22 -0
- package/wizard/src/features/dialog-system/components/EmailVerificationDialog/EmailVerificationDialog.js +149 -0
- package/wizard/src/features/dialog-system/components/EmailVerificationDialog/EmailVerificationDialog.module.css.js +40 -0
- package/wizard/src/features/form-runtime/ComponentAdapterComplete/ComponentAdapterComplete.js +107 -0
- package/wizard/src/features/form-runtime/ComponentAdapterComplete/ComponentAdapterComplete.module.css.js +10 -0
- package/wizard/src/features/form-runtime/FormWizard/FormWizard.js +107 -0
- package/wizard/src/features/form-runtime/FormWizard/FormWizard.module.css.js +16 -0
- package/wizard/src/features/form-runtime/components/FormField.js +405 -0
- package/wizard/src/features/form-runtime/components/FormFooter.js +209 -0
- package/wizard/src/features/form-runtime/components/FormHeader.js +29 -0
- package/wizard/src/features/form-runtime/components/FormSection/FormSection.js +279 -0
- package/wizard/src/features/form-runtime/components/FormSection/FormSection.module.css.js +20 -0
- package/wizard/src/features/form-runtime/components/FormStep/FormStep.js +167 -0
- package/wizard/src/features/form-runtime/components/FormStep/FormStep.module.css.js +12 -0
- package/wizard/src/features/form-runtime/components/ProgressLoaderRuntime.js +88 -0
- package/wizard/src/features/form-runtime/components/StepProgressIndicator/StepProgressIndicator.js +61 -0
- package/wizard/src/features/form-runtime/components/StepProgressIndicator/StepProgressIndicator.module.css.js +34 -0
- package/wizard/src/features/form-runtime/components/displayValue/displayValue.js +21 -0
- package/wizard/src/features/form-runtime/components/displayValue/displayValue.module.css.js +10 -0
- package/wizard/src/features/form-runtime/components/renderers/DisplayModeRenderer/DisplayModeRenderer.js +28 -0
- package/wizard/src/features/form-runtime/components/renderers/DisplayModeRenderer/DisplayModeRenderer.module.css.js +8 -0
- package/wizard/src/features/form-runtime/components/renderers/InteractiveFieldRenderer/InteractiveFieldRenderer.js +56 -0
- package/wizard/src/features/form-runtime/components/renderers/InteractiveFieldRenderer/InteractiveFieldRenderer.module.css.js +8 -0
- package/wizard/src/features/form-runtime/config/configResolver.js +38 -0
- package/wizard/src/features/form-runtime/config/templateConfig.js +156 -0
- package/wizard/src/features/form-runtime/config/templateLoader.js +265 -0
- package/wizard/src/features/form-runtime/config/templateUtils.js +14 -0
- package/wizard/src/features/form-runtime/context/LoaderContext.js +36 -0
- package/wizard/src/features/form-runtime/hooks/useApiActions.js +60 -0
- package/wizard/src/features/form-runtime/hooks/useComponentTriggers.js +102 -0
- package/wizard/src/features/form-runtime/hooks/useComponentVisibility.js +18 -0
- package/wizard/src/features/form-runtime/hooks/useFieldEventHandlers.js +61 -0
- package/wizard/src/features/form-runtime/hooks/useFormContext.js +13 -0
- package/wizard/src/features/form-runtime/hooks/useFormFieldState.js +40 -0
- package/wizard/src/features/form-runtime/hooks/useValidationEvents.js +39 -0
- package/wizard/src/features/form-runtime/utils/componentDisplayValue.js +22 -0
- package/wizard/src/features/form-runtime/utils/errorUtils.js +93 -0
- package/wizard/src/features/form-runtime/utils/fieldHelpers.js +17 -0
- package/wizard/src/features/form-runtime/utils/formDataBuilder.js +10 -0
- package/wizard/src/features/form-runtime/utils/formDirtyStateSync.js +52 -0
- package/wizard/src/features/form-runtime/utils/logger.js +111 -0
- package/wizard/src/features/form-runtime/utils/validation.js +100 -0
- package/wizard/src/features/form-runtime/utils/validationUX.js +58 -0
- package/wizard/src/features/form-runtime/utils/visibilityUtils.js +77 -0
- package/wizard/src/features/state-management/machines/actions/componentActions.js +215 -0
- package/wizard/src/features/state-management/machines/actions/navigationActions.js +122 -0
- package/wizard/src/features/state-management/machines/actions/saveActions.js +101 -0
- package/wizard/src/features/state-management/machines/componentTriggerEngine.js +598 -0
- package/wizard/src/features/state-management/machines/formMachine.js +1565 -0
- package/wizard/src/features/state-management/machines/guards/navigationGuards.js +59 -0
- package/wizard/src/features/state-management/machines/guards/saveGuards.js +21 -0
- package/wizard/src/features/state-management/machines/guards/triggerGuards.js +11 -0
- package/wizard/src/features/state-management/machines/helpers/triggerHelpers.js +12 -0
- package/wizard/src/features/state-management/machines/performance.js +56 -0
- package/wizard/src/features/state-management/machines/useFormMachine.js +412 -0
- package/wizard/src/features/trigger-action-system/components/ActionLoadingIndicator/ActionLoadingIndicator.js +46 -0
- package/wizard/src/features/trigger-action-system/components/ActionLoadingIndicator/ActionLoadingIndicator.module.css.js +30 -0
- package/wizard/src/features/trigger-action-system/components/ActionManager.js +108 -0
- package/wizard/src/features/trigger-action-system/components/ComponentAlert/ComponentAlert.js +10 -0
- package/wizard/src/features/trigger-action-system/components/ComponentAlert/ComponentAlert.module.css.js +8 -0
- package/wizard/src/features/trigger-action-system/utils/GenericTriggerEngine.js +376 -0
- package/wizard/src/features/validation-system/components/ValidationDebugger.js +69 -0
- package/wizard/src/features/validation-system/validation/ActionValidation.js +234 -0
- package/wizard/src/features/validation-system/validation/SchemaBuilder.js +239 -0
- package/wizard/src/features/validation-system/validation/ValidationCache.js +76 -0
- package/wizard/src/features/validation-system/validation/ValidationEngine.js +97 -0
- package/wizard/src/features/validation-system/validation/ValidationExecutor.js +138 -0
- package/wizard/src/features/validation-system/validation/tanstackSchemaAdapter.js +17 -0
- package/wizard/src/features/validation-system/validation/validationService.js +74 -0
- package/wizard/src/renderer/wizardRenderer.js +123 -0
- package/README.md +0 -147
|
@@ -0,0 +1,209 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { jsx as f, jsxs as p } from "react/jsx-runtime";
|
|
3
|
+
import { clsx as S } from "clsx";
|
|
4
|
+
/* empty css */
|
|
5
|
+
import { useFormMachine as V } from "../../state-management/machines/useFormMachine.js";
|
|
6
|
+
import { useFormContext as y } from "../hooks/useFormContext.js";
|
|
7
|
+
import { useFormEditing as v } from "../../../../../ui/src/lib/providers/FormEditingContext.js";
|
|
8
|
+
import { Button as E } from "@rijkshuisstijl-community/components-react";
|
|
9
|
+
const M = ({
|
|
10
|
+
navigation: l,
|
|
11
|
+
children: d,
|
|
12
|
+
isDisplayOnly: a = !1,
|
|
13
|
+
onNext: g,
|
|
14
|
+
isLastStep: m = !1,
|
|
15
|
+
isDisabled: n = !1,
|
|
16
|
+
...r
|
|
17
|
+
}) => {
|
|
18
|
+
const u = () => {
|
|
19
|
+
a || n || g?.();
|
|
20
|
+
};
|
|
21
|
+
return /* @__PURE__ */ p(
|
|
22
|
+
"div",
|
|
23
|
+
{
|
|
24
|
+
className: S(
|
|
25
|
+
(n || a) && "opacity-50",
|
|
26
|
+
r.className
|
|
27
|
+
),
|
|
28
|
+
...r,
|
|
29
|
+
children: [
|
|
30
|
+
d,
|
|
31
|
+
l?.next?.enabled !== !1 && /* @__PURE__ */ f(
|
|
32
|
+
E,
|
|
33
|
+
{
|
|
34
|
+
appearance: "primary-action-button",
|
|
35
|
+
onClick: u,
|
|
36
|
+
disabled: n || a,
|
|
37
|
+
children: l?.next?.label || (m ? "Voltooien" : "Volgende")
|
|
38
|
+
}
|
|
39
|
+
)
|
|
40
|
+
]
|
|
41
|
+
}
|
|
42
|
+
);
|
|
43
|
+
}, A = ({ children: l, ...d }) => {
|
|
44
|
+
const { isEditing: a } = v(), [g, m, n] = V(), { currentStep: r, isLastStep: u } = n, { navigation: b } = r, e = y();
|
|
45
|
+
return /* @__PURE__ */ f(
|
|
46
|
+
M,
|
|
47
|
+
{
|
|
48
|
+
navigation: b,
|
|
49
|
+
onNext: async () => {
|
|
50
|
+
try {
|
|
51
|
+
const c = r.actions || [], h = c.some(
|
|
52
|
+
(s) => s.trigger === "onStepFinish"
|
|
53
|
+
);
|
|
54
|
+
if (console.log("🔍 [FormFooter] Starting form submission check:", {
|
|
55
|
+
stepId: r.id,
|
|
56
|
+
stepActions: c.length,
|
|
57
|
+
hasFinishActions: h
|
|
58
|
+
}), h) {
|
|
59
|
+
const s = Object.keys(e.state.fieldMeta).map(
|
|
60
|
+
(t) => {
|
|
61
|
+
const o = e.state.fieldMeta[t], i = e.getFieldValue(t);
|
|
62
|
+
return {
|
|
63
|
+
fieldId: t,
|
|
64
|
+
value: i,
|
|
65
|
+
isValid: o.isValid,
|
|
66
|
+
isDirty: o.isDirty,
|
|
67
|
+
isTouched: o.isTouched,
|
|
68
|
+
errors: o.errors,
|
|
69
|
+
errorCount: o.errors?.length || 0
|
|
70
|
+
};
|
|
71
|
+
}
|
|
72
|
+
);
|
|
73
|
+
if (console.log(
|
|
74
|
+
"🔍 [FormFooter] Step has finish actions - checking form state:",
|
|
75
|
+
{
|
|
76
|
+
canSubmit: e.state.canSubmit,
|
|
77
|
+
isValid: e.state.isValid,
|
|
78
|
+
isSubmitting: e.state.isSubmitting,
|
|
79
|
+
fieldCount: Object.keys(e.state.fieldMeta).length,
|
|
80
|
+
fieldAnalysis: s,
|
|
81
|
+
formErrors: e.state.formErrors
|
|
82
|
+
}
|
|
83
|
+
), console.log("📋 [FormFooter] Detailed field analysis:"), s.forEach((t, o) => {
|
|
84
|
+
console.log(` Field ${o + 1}:`, {
|
|
85
|
+
fieldId: t.fieldId,
|
|
86
|
+
value: t.value,
|
|
87
|
+
isValid: t.isValid,
|
|
88
|
+
isDirty: t.isDirty,
|
|
89
|
+
isTouched: t.isTouched,
|
|
90
|
+
errors: t.errors,
|
|
91
|
+
errorCount: t.errorCount
|
|
92
|
+
});
|
|
93
|
+
}), e.state.canSubmit)
|
|
94
|
+
await e.handleSubmit();
|
|
95
|
+
else {
|
|
96
|
+
console.log(
|
|
97
|
+
"🚫 [FormFooter] Form validation failed for step with finish actions, triggering error display:",
|
|
98
|
+
{
|
|
99
|
+
canSubmit: e.state.canSubmit,
|
|
100
|
+
isValid: e.state.isValid,
|
|
101
|
+
isSubmitting: e.state.isSubmitting,
|
|
102
|
+
fieldMeta: e.state.fieldMeta,
|
|
103
|
+
formErrors: e.state.formErrors
|
|
104
|
+
}
|
|
105
|
+
);
|
|
106
|
+
const t = Object.keys(e.state.fieldMeta).filter(
|
|
107
|
+
(o) => {
|
|
108
|
+
const i = e.state.fieldMeta[o];
|
|
109
|
+
return !i.isValid && i.errors?.length > 0;
|
|
110
|
+
}
|
|
111
|
+
);
|
|
112
|
+
t.length > 0 && (console.log(
|
|
113
|
+
`🔍 [FormFooter] Triggering error display for ${t.length} invalid fields:`,
|
|
114
|
+
t
|
|
115
|
+
), window.dispatchEvent(
|
|
116
|
+
new CustomEvent("triggerStepValidation", {
|
|
117
|
+
detail: { fieldIds: t }
|
|
118
|
+
})
|
|
119
|
+
));
|
|
120
|
+
}
|
|
121
|
+
} else {
|
|
122
|
+
const s = Object.keys(e.state.fieldMeta).map(
|
|
123
|
+
(t) => {
|
|
124
|
+
const o = e.state.fieldMeta[t], i = e.getFieldValue(t);
|
|
125
|
+
return {
|
|
126
|
+
fieldId: t,
|
|
127
|
+
value: i,
|
|
128
|
+
isValid: o.isValid,
|
|
129
|
+
isDirty: o.isDirty,
|
|
130
|
+
isTouched: o.isTouched,
|
|
131
|
+
errors: o.errors,
|
|
132
|
+
errorCount: o.errors?.length || 0
|
|
133
|
+
};
|
|
134
|
+
}
|
|
135
|
+
);
|
|
136
|
+
if (console.log(
|
|
137
|
+
"🔍 [FormFooter] Step has no finish actions - checking form state:",
|
|
138
|
+
{
|
|
139
|
+
canSubmit: e.state.canSubmit,
|
|
140
|
+
isValid: e.state.isValid,
|
|
141
|
+
isSubmitting: e.state.isSubmitting,
|
|
142
|
+
fieldCount: Object.keys(e.state.fieldMeta).length,
|
|
143
|
+
fieldAnalysis: s,
|
|
144
|
+
formErrors: e.state.formErrors
|
|
145
|
+
}
|
|
146
|
+
), console.log("📋 [FormFooter] Detailed field analysis:"), s.forEach((t, o) => {
|
|
147
|
+
console.log(` Field ${o + 1}:`, {
|
|
148
|
+
fieldId: t.fieldId,
|
|
149
|
+
value: t.value,
|
|
150
|
+
isValid: t.isValid,
|
|
151
|
+
isDirty: t.isDirty,
|
|
152
|
+
isTouched: t.isTouched,
|
|
153
|
+
errors: t.errors,
|
|
154
|
+
errorCount: t.errorCount
|
|
155
|
+
});
|
|
156
|
+
}), e.state.canSubmit) {
|
|
157
|
+
const t = e.state.values, o = {};
|
|
158
|
+
console.log("🔄 [FormFooter] Preparing form values for navigation:", {
|
|
159
|
+
formValues: t,
|
|
160
|
+
fieldIds: Object.keys(t)
|
|
161
|
+
}), Object.keys(t).forEach((i) => {
|
|
162
|
+
const F = e.getFieldValue(i);
|
|
163
|
+
o[i] = F, console.log(`🔄 [FormFooter] Prepared field ${i}:`, F);
|
|
164
|
+
}), m({
|
|
165
|
+
type: "REQUEST_NAVIGATION",
|
|
166
|
+
navigationType: "next"
|
|
167
|
+
});
|
|
168
|
+
} else {
|
|
169
|
+
console.log(
|
|
170
|
+
"🚫 [FormFooter] Form cannot be submitted (validation failed or form is submitting), triggering error display:",
|
|
171
|
+
{
|
|
172
|
+
canSubmit: e.state.canSubmit,
|
|
173
|
+
isValid: e.state.isValid,
|
|
174
|
+
isSubmitting: e.state.isSubmitting,
|
|
175
|
+
fieldMeta: e.state.fieldMeta,
|
|
176
|
+
formErrors: e.state.formErrors,
|
|
177
|
+
values: e.state.values
|
|
178
|
+
}
|
|
179
|
+
);
|
|
180
|
+
const t = Object.keys(e.state.fieldMeta).filter(
|
|
181
|
+
(o) => {
|
|
182
|
+
const i = e.state.fieldMeta[o];
|
|
183
|
+
return !i.isValid && i.errors?.length > 0;
|
|
184
|
+
}
|
|
185
|
+
);
|
|
186
|
+
t.length > 0 && (console.log(
|
|
187
|
+
`🔍 [FormFooter] Triggering error display for ${t.length} invalid fields:`,
|
|
188
|
+
t
|
|
189
|
+
), window.dispatchEvent(
|
|
190
|
+
new CustomEvent("triggerStepValidation", {
|
|
191
|
+
detail: { fieldIds: t }
|
|
192
|
+
})
|
|
193
|
+
));
|
|
194
|
+
}
|
|
195
|
+
}
|
|
196
|
+
} catch (c) {
|
|
197
|
+
console.log("🚫 [FormFooter] Form submission failed:", c);
|
|
198
|
+
}
|
|
199
|
+
},
|
|
200
|
+
isLastStep: u,
|
|
201
|
+
isDisabled: a,
|
|
202
|
+
...d,
|
|
203
|
+
children: /* @__PURE__ */ f(e.Subscribe, { children: l })
|
|
204
|
+
}
|
|
205
|
+
);
|
|
206
|
+
};
|
|
207
|
+
export {
|
|
208
|
+
A as default
|
|
209
|
+
};
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { jsx as u } from "react/jsx-runtime";
|
|
3
|
+
/* empty css */
|
|
4
|
+
import { FormHeaderBase as c } from "../../../../../ui/src/components/form-header-base/form-header-base.js";
|
|
5
|
+
import { useFormMachine as l } from "../../state-management/machines/useFormMachine.js";
|
|
6
|
+
import { useFormEditing as d } from "../../../../../ui/src/lib/providers/FormEditingContext.js";
|
|
7
|
+
const N = (t) => {
|
|
8
|
+
const { isEditing: o } = d(), [, , i] = l(), { steps: n, currentStep: e, currentStepIndex: s, previousStep: a, goToStep: m } = i, p = (r) => {
|
|
9
|
+
r === "previous" ? a() : m(r);
|
|
10
|
+
};
|
|
11
|
+
return /* @__PURE__ */ u(
|
|
12
|
+
c,
|
|
13
|
+
{
|
|
14
|
+
showStepNumber: e.showStepNumber,
|
|
15
|
+
title: e?.title || t.title,
|
|
16
|
+
stepNumber: {
|
|
17
|
+
current: s + 1,
|
|
18
|
+
total: n.length
|
|
19
|
+
},
|
|
20
|
+
navigation: e?.navigation,
|
|
21
|
+
onNavigate: p,
|
|
22
|
+
isEditing: o,
|
|
23
|
+
children: t.children
|
|
24
|
+
}
|
|
25
|
+
);
|
|
26
|
+
};
|
|
27
|
+
export {
|
|
28
|
+
N as default
|
|
29
|
+
};
|
|
@@ -0,0 +1,279 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { jsx as g, jsxs as h } from "react/jsx-runtime";
|
|
3
|
+
import { ComponentTriggerEngine as k } from "../../../state-management/machines/componentTriggerEngine.js";
|
|
4
|
+
import { useFormMachine as _ } from "../../../state-management/machines/useFormMachine.js";
|
|
5
|
+
import { clsx as D } from "clsx";
|
|
6
|
+
import { X as P, Edit as w, Check as L } from "lucide-react";
|
|
7
|
+
import { memo as M, useState as R, useMemo as x, useEffect as $, useCallback as S } from "react";
|
|
8
|
+
import u from "./FormSection.module.css.js";
|
|
9
|
+
import { useFormContext as B } from "../../hooks/useFormContext.js";
|
|
10
|
+
import U from "../FormField.js";
|
|
11
|
+
import { evaluateVisibility as G } from "../../utils/visibilityUtils.js";
|
|
12
|
+
import { Heading as q, Button as j } from "@rijkshuisstijl-community/components-react";
|
|
13
|
+
const H = M(({ section: e }) => {
|
|
14
|
+
const [a, d, p] = _(), {
|
|
15
|
+
validateSection: y,
|
|
16
|
+
validateField: C,
|
|
17
|
+
startSectionEdit: T,
|
|
18
|
+
cancelSectionEdit: F
|
|
19
|
+
} = p, m = B(), [f, E] = R(!1), N = x(() => {
|
|
20
|
+
if (!e.visibilityConditions)
|
|
21
|
+
return !0;
|
|
22
|
+
const o = a.context.data;
|
|
23
|
+
return G(e.visibilityConditions, o);
|
|
24
|
+
}, [e.visibilityConditions, a.context.data]), r = x(
|
|
25
|
+
() => ({
|
|
26
|
+
title: e.title,
|
|
27
|
+
components: e.components || [],
|
|
28
|
+
mode: e.mode || "default",
|
|
29
|
+
// Default to always-editable mode when no mode is specified
|
|
30
|
+
editText: e.editText || "Edit",
|
|
31
|
+
cancelText: e.cancelText || "Cancel",
|
|
32
|
+
saveText: e.saveText || "Save",
|
|
33
|
+
showTitle: e.showTitle ?? !0,
|
|
34
|
+
showActionLink: e.showActionLink ?? !0
|
|
35
|
+
}),
|
|
36
|
+
[e]
|
|
37
|
+
), I = x(() => {
|
|
38
|
+
const o = r.mode === "isEditable" ? "default" : r.mode;
|
|
39
|
+
return o === "readOnly" ? !0 : o === "editable" ? !f : !1;
|
|
40
|
+
}, [r.mode, f]), n = x(
|
|
41
|
+
() => r.components.map((o) => o.id),
|
|
42
|
+
[r.components]
|
|
43
|
+
), b = x(
|
|
44
|
+
() => a.context.activeDialog,
|
|
45
|
+
[a.context.activeDialog]
|
|
46
|
+
);
|
|
47
|
+
$(() => {
|
|
48
|
+
r.mode !== "editable" || !f || b && !a.context.activeDialog && (console.log(
|
|
49
|
+
"🔥 FormSection: Dialog closed, checking if verification completed"
|
|
50
|
+
), n.every((t) => {
|
|
51
|
+
const c = a.context.data[t], l = a.context.componentOriginalValues[t];
|
|
52
|
+
return c === l?.value;
|
|
53
|
+
}) && (console.log(
|
|
54
|
+
"🔥 FormSection: All fields clean after verification, clearing alerts and exiting edit mode"
|
|
55
|
+
), n.forEach((t) => {
|
|
56
|
+
d({
|
|
57
|
+
type: "CLEAR_COMPONENT_ALERT",
|
|
58
|
+
componentId: t
|
|
59
|
+
});
|
|
60
|
+
}), E(!1)));
|
|
61
|
+
}, [
|
|
62
|
+
a.context.activeDialog,
|
|
63
|
+
a.context.data,
|
|
64
|
+
a.context.componentOriginalValues,
|
|
65
|
+
n,
|
|
66
|
+
d,
|
|
67
|
+
r.mode,
|
|
68
|
+
f,
|
|
69
|
+
b
|
|
70
|
+
]);
|
|
71
|
+
const O = S(() => {
|
|
72
|
+
console.log("Start edit - creating backup for fields:", n);
|
|
73
|
+
const o = n.map((t) => ({
|
|
74
|
+
fieldId: t,
|
|
75
|
+
value: m.getFieldValue(t)
|
|
76
|
+
}));
|
|
77
|
+
console.log("Start edit - current form values:", o), n.forEach((t) => {
|
|
78
|
+
const c = m.getFieldValue(t);
|
|
79
|
+
p.setData(t, c);
|
|
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({
|
|
85
|
+
type: "SET_COMPONENT_ORIGINAL_VALUE",
|
|
86
|
+
componentId: t,
|
|
87
|
+
value: c,
|
|
88
|
+
source: "edit_start"
|
|
89
|
+
}));
|
|
90
|
+
}), T(e.id, n), E(!0);
|
|
91
|
+
}, [
|
|
92
|
+
T,
|
|
93
|
+
e.id,
|
|
94
|
+
n,
|
|
95
|
+
m,
|
|
96
|
+
p,
|
|
97
|
+
a.context.componentOriginalValues,
|
|
98
|
+
d
|
|
99
|
+
]), V = S(() => {
|
|
100
|
+
const o = a.context.sectionBackups[e.id];
|
|
101
|
+
console.log("Cancel edit - backup data:", o), console.log("Cancel edit - section fields:", n), o ? n.forEach((t) => {
|
|
102
|
+
const c = o[t], l = m.getFieldValue(t);
|
|
103
|
+
console.log(
|
|
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({
|
|
108
|
+
type: "DISMISS_COMPONENT_ALERT",
|
|
109
|
+
componentId: t
|
|
110
|
+
// Don't specify alertId to clear all alerts for this component
|
|
111
|
+
});
|
|
112
|
+
}) : console.warn("No backup data found for section:", e.id), F(e.id), E(!1);
|
|
113
|
+
}, [
|
|
114
|
+
a.context.sectionBackups,
|
|
115
|
+
e.id,
|
|
116
|
+
n,
|
|
117
|
+
m,
|
|
118
|
+
F,
|
|
119
|
+
d
|
|
120
|
+
]), A = S(async () => {
|
|
121
|
+
console.log(
|
|
122
|
+
"FormSection: Triggering validation display for fields:",
|
|
123
|
+
n
|
|
124
|
+
), n.forEach((c) => {
|
|
125
|
+
const l = new CustomEvent("triggerFieldValidation", {
|
|
126
|
+
detail: { fieldId: c, sectionId: e.id }
|
|
127
|
+
});
|
|
128
|
+
console.log(
|
|
129
|
+
`FormSection: Dispatching validation trigger for field ${c}`
|
|
130
|
+
), window.dispatchEvent(l);
|
|
131
|
+
});
|
|
132
|
+
let o = !1;
|
|
133
|
+
const t = n.map((c) => C(c));
|
|
134
|
+
await Promise.all(t);
|
|
135
|
+
for (const c of n) {
|
|
136
|
+
const l = m.getFieldMeta(c);
|
|
137
|
+
if (l.errors && l.errors.length > 0) {
|
|
138
|
+
o = !0;
|
|
139
|
+
break;
|
|
140
|
+
}
|
|
141
|
+
}
|
|
142
|
+
if (y(e.id), !o) {
|
|
143
|
+
console.log(
|
|
144
|
+
"🔄 [FormSection] Syncing current form values to XState before trigger evaluation"
|
|
145
|
+
), n.forEach((i) => {
|
|
146
|
+
const s = m.getFieldValue(i);
|
|
147
|
+
p.setData(i, s), console.log(`🔄 [FormSection] Synced field ${i}:`, s);
|
|
148
|
+
}), console.log(
|
|
149
|
+
"🎯 [FormSection] Checking for dirty fields with verification requirements"
|
|
150
|
+
);
|
|
151
|
+
const c = p.config, l = a.context.currentStepIndex, v = k.createExecutionPlan(
|
|
152
|
+
c,
|
|
153
|
+
"save",
|
|
154
|
+
l,
|
|
155
|
+
a.context
|
|
156
|
+
);
|
|
157
|
+
if (console.log("🎯 [FormSection] save execution plan:", {
|
|
158
|
+
totalActions: v.totalActions,
|
|
159
|
+
executionsCount: v.executions.length,
|
|
160
|
+
requiresUserInteraction: v.requiresUserInteraction,
|
|
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({
|
|
183
|
+
type: "TRIGGER_COMPONENT_ACTION",
|
|
184
|
+
componentId: i.componentId,
|
|
185
|
+
triggerId: i.trigger.id,
|
|
186
|
+
actionId: s.id,
|
|
187
|
+
eventType: "sectionSave"
|
|
188
|
+
});
|
|
189
|
+
});
|
|
190
|
+
});
|
|
191
|
+
return;
|
|
192
|
+
}
|
|
193
|
+
n.forEach((i) => {
|
|
194
|
+
d({
|
|
195
|
+
type: "CLEAR_COMPONENT_ALERT",
|
|
196
|
+
componentId: i
|
|
197
|
+
});
|
|
198
|
+
}), n.forEach((i) => {
|
|
199
|
+
d({
|
|
200
|
+
type: "UPDATE_COMPONENT_ORIGINAL_VALUE",
|
|
201
|
+
componentId: i
|
|
202
|
+
});
|
|
203
|
+
}), E(!1);
|
|
204
|
+
}
|
|
205
|
+
}, [
|
|
206
|
+
n,
|
|
207
|
+
C,
|
|
208
|
+
m,
|
|
209
|
+
y,
|
|
210
|
+
e.id,
|
|
211
|
+
p,
|
|
212
|
+
a.context.currentStepIndex,
|
|
213
|
+
a.context,
|
|
214
|
+
d
|
|
215
|
+
]);
|
|
216
|
+
return /* @__PURE__ */ g(
|
|
217
|
+
"div",
|
|
218
|
+
{
|
|
219
|
+
style: {
|
|
220
|
+
display: N ? "block" : "none"
|
|
221
|
+
},
|
|
222
|
+
"data-section-id": e.id,
|
|
223
|
+
"data-visible": N,
|
|
224
|
+
children: /* @__PURE__ */ h("div", { className: D("form-section", u.section), children: [
|
|
225
|
+
r.showTitle && /* @__PURE__ */ h("div", { className: u.sectionHeader, children: [
|
|
226
|
+
/* @__PURE__ */ g(q, { level: 3, children: r.title }),
|
|
227
|
+
r.mode === "editable" && r.showActionLink && /* @__PURE__ */ g("div", { children: f ? /* @__PURE__ */ h(
|
|
228
|
+
"button",
|
|
229
|
+
{
|
|
230
|
+
type: "button",
|
|
231
|
+
onClick: V,
|
|
232
|
+
className: u.cancelButton,
|
|
233
|
+
children: [
|
|
234
|
+
/* @__PURE__ */ g(P, { className: u.iconSm }),
|
|
235
|
+
r.cancelText
|
|
236
|
+
]
|
|
237
|
+
}
|
|
238
|
+
) : /* @__PURE__ */ h(
|
|
239
|
+
"button",
|
|
240
|
+
{
|
|
241
|
+
type: "button",
|
|
242
|
+
onClick: O,
|
|
243
|
+
className: u.editButton,
|
|
244
|
+
children: [
|
|
245
|
+
/* @__PURE__ */ g(w, { className: u.iconSm }),
|
|
246
|
+
r.editText
|
|
247
|
+
]
|
|
248
|
+
}
|
|
249
|
+
) })
|
|
250
|
+
] }),
|
|
251
|
+
/* @__PURE__ */ h("div", { className: u.sectionContent, children: [
|
|
252
|
+
r.components.map((o) => /* @__PURE__ */ g(
|
|
253
|
+
U,
|
|
254
|
+
{
|
|
255
|
+
component: o,
|
|
256
|
+
readOnly: I
|
|
257
|
+
},
|
|
258
|
+
o.id
|
|
259
|
+
)),
|
|
260
|
+
f && /* @__PURE__ */ g("div", { className: u.saveButtonsWrapper, children: /* @__PURE__ */ h(
|
|
261
|
+
j,
|
|
262
|
+
{
|
|
263
|
+
appearance: "primary-action-button",
|
|
264
|
+
onClick: A,
|
|
265
|
+
children: [
|
|
266
|
+
/* @__PURE__ */ g(L, { className: u.iconSm }),
|
|
267
|
+
r.saveText
|
|
268
|
+
]
|
|
269
|
+
}
|
|
270
|
+
) })
|
|
271
|
+
] })
|
|
272
|
+
] })
|
|
273
|
+
}
|
|
274
|
+
);
|
|
275
|
+
});
|
|
276
|
+
H.displayName = "FormSection";
|
|
277
|
+
export {
|
|
278
|
+
H as default
|
|
279
|
+
};
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
const t = "fb-section_5kbZU", n = "fb-sectionHeader_aVzgk", e = "fb-cancelButton_PyIZH", o = "fb-editButton_dbSFX", c = "fb-sectionContent_wTlW-", s = "fb-saveButtonsWrapper_VGuwW", i = "fb-iconSm_yLpHW", a = {
|
|
3
|
+
section: t,
|
|
4
|
+
sectionHeader: n,
|
|
5
|
+
cancelButton: e,
|
|
6
|
+
editButton: o,
|
|
7
|
+
sectionContent: c,
|
|
8
|
+
saveButtonsWrapper: s,
|
|
9
|
+
iconSm: i
|
|
10
|
+
};
|
|
11
|
+
export {
|
|
12
|
+
e as cancelButton,
|
|
13
|
+
a as default,
|
|
14
|
+
o as editButton,
|
|
15
|
+
i as iconSm,
|
|
16
|
+
s as saveButtonsWrapper,
|
|
17
|
+
t as section,
|
|
18
|
+
c as sectionContent,
|
|
19
|
+
n as sectionHeader
|
|
20
|
+
};
|