@digiform/wizard 0.3.0 → 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.
Files changed (89) hide show
  1. package/core/src/types/guards.js +0 -12
  2. package/core/src/utils/apiBodyUtils.js +43 -75
  3. package/features/form-runtime/components/FormFooter.d.ts +5 -0
  4. package/features/form-runtime/hooks/useValidationEvents.d.ts +0 -1
  5. package/features/state-management/machines/formMachine.d.ts +3 -0
  6. package/features/state-management/machines/types.d.ts +4 -0
  7. package/features/state-management/machines/useFormMachine.d.ts +18 -0
  8. package/index.d.ts +2 -8
  9. package/index.js +2 -108
  10. package/package.json +1 -30
  11. package/styles.css +1 -1
  12. package/ui/src/lib/utils/templateUtils.js +11 -43
  13. package/wizard/src/features/api-integration/services/ApiCallService.js +65 -74
  14. package/wizard/src/features/dialog-system/components/ActionDialog/ActionDialog.js +39 -43
  15. package/wizard/src/features/dialog-system/components/ConfirmationDialog/ConfirmationDialog.js +37 -41
  16. package/wizard/src/features/dialog-system/components/EmailVerificationDialog/EmailVerificationDialog.js +44 -45
  17. package/wizard/src/features/form-runtime/FormWizard/FormWizard.js +56 -78
  18. package/wizard/src/features/form-runtime/components/FormField.js +28 -28
  19. package/wizard/src/features/form-runtime/components/FormFooter.js +53 -184
  20. package/wizard/src/features/form-runtime/components/FormSection/FormSection.js +152 -196
  21. package/wizard/src/features/form-runtime/components/FormStep/FormStep.js +82 -91
  22. package/wizard/src/features/form-runtime/components/StepProgressIndicator/StepProgressIndicator.js +24 -30
  23. package/wizard/src/features/form-runtime/config/configResolver.js +10 -14
  24. package/wizard/src/features/form-runtime/config/templateLoader.js +71 -108
  25. package/wizard/src/features/form-runtime/hooks/useComponentTriggers.js +45 -88
  26. package/wizard/src/features/form-runtime/hooks/useFieldEventHandlers.js +27 -41
  27. package/wizard/src/features/form-runtime/hooks/useFormFieldState.js +5 -5
  28. package/wizard/src/features/form-runtime/hooks/useValidationEvents.js +22 -25
  29. package/wizard/src/features/form-runtime/utils/errorUtils.js +31 -42
  30. package/wizard/src/features/form-runtime/utils/formDirtyStateSync.js +26 -37
  31. package/wizard/src/features/form-runtime/utils/logger.js +12 -12
  32. package/wizard/src/features/form-runtime/utils/validationUX.js +14 -55
  33. package/wizard/src/features/state-management/machines/actions/navigationActions.js +13 -8
  34. package/wizard/src/features/state-management/machines/componentTriggerEngine.js +167 -432
  35. package/wizard/src/features/state-management/machines/formMachine.js +558 -677
  36. package/wizard/src/features/state-management/machines/useFormMachine.js +172 -190
  37. package/wizard/src/features/trigger-action-system/components/ActionManager.js +35 -86
  38. package/wizard/src/features/validation-system/validation/SchemaBuilder.js +28 -82
  39. package/wizard/src/features/validation-system/validation/ValidationCache.js +11 -27
  40. package/wizard/src/features/validation-system/validation/ValidationEngine.js +24 -29
  41. package/wizard/src/features/validation-system/validation/ValidationExecutor.js +26 -58
  42. package/FormWizard.d.ts +0 -10
  43. package/core/src/types/api.js +0 -12
  44. package/core/src/types/form-config.js +0 -60
  45. package/core/src/types/form-wizard-config-schema.js +0 -113
  46. package/core/src/types/validation.js +0 -61
  47. package/features/api-integration.d.ts +0 -2
  48. package/features/api-integration.js +0 -17
  49. package/features/dialog-system.d.ts +0 -2
  50. package/features/dialog-system.js +0 -9
  51. package/features/form-runtime/utils/formSaver.d.ts +0 -22
  52. package/features/form-runtime.d.ts +0 -2
  53. package/features/form-runtime.js +0 -63
  54. package/features/index.d.ts +0 -11
  55. package/features/state-management/components/ValidationBuilder/ValidationBuilder.d.ts +0 -9
  56. package/features/state-management/machines/__tests__/setup.d.ts +0 -0
  57. package/features/state-management/machines/__tests__/vitest.config.d.ts +0 -2
  58. package/features/state-management/machines/actions/validationActions.d.ts +0 -68
  59. package/features/state-management/machines/lazyLoading.d.ts +0 -34
  60. package/features/state-management/machines/validation/index.d.ts +0 -5
  61. package/features/state-management/machines/validation/validateField.d.ts +0 -2
  62. package/features/state-management/machines/validation/validateForm.d.ts +0 -2
  63. package/features/state-management/machines/validation/validateSection.d.ts +0 -2
  64. package/features/state-management/machines/validation/validateStep.d.ts +0 -2
  65. package/features/state-management/machines/validation/validationTypes.d.ts +0 -1
  66. package/features/state-management.d.ts +0 -2
  67. package/features/state-management.js +0 -21
  68. package/features/trigger-action-system/components/FieldWarning/FieldWarning.d.ts +0 -20
  69. package/features/trigger-action-system.d.ts +0 -2
  70. package/features/trigger-action-system.js +0 -12
  71. package/features/validation-system.d.ts +0 -2
  72. package/features/validation-system.js +0 -23
  73. package/styles/index.d.ts +0 -0
  74. package/ui/src/components/badge/badge.js +0 -20
  75. package/ui/src/components/badge/badge.module.css.js +0 -12
  76. package/wizard/src/features/api-integration/services/ActionExecutor.js +0 -339
  77. package/wizard/src/features/api-integration/services/ApiCallExecutor.js +0 -6
  78. package/wizard/src/features/api-integration/services/DialogExecutor.js +0 -6
  79. package/wizard/src/features/api-integration/services/GenericTriggerService.js +0 -284
  80. package/wizard/src/features/api-integration/services/NavigationExecutor.js +0 -6
  81. package/wizard/src/features/form-runtime/config/templateConfig.js +0 -156
  82. package/wizard/src/features/form-runtime/config/templateUtils.js +0 -14
  83. package/wizard/src/features/form-runtime/utils/validation.js +0 -100
  84. package/wizard/src/features/trigger-action-system/components/ActionLoadingIndicator/ActionLoadingIndicator.js +0 -46
  85. package/wizard/src/features/trigger-action-system/components/ActionLoadingIndicator/ActionLoadingIndicator.module.css.js +0 -30
  86. package/wizard/src/features/trigger-action-system/utils/GenericTriggerEngine.js +0 -376
  87. package/wizard/src/features/validation-system/components/ValidationDebugger.js +0 -69
  88. package/wizard/src/features/validation-system/validation/tanstackSchemaAdapter.js +0 -17
  89. package/wizard/src/features/validation-system/validation/validationService.js +0 -74
@@ -1,270 +1,226 @@
1
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,
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
+ import { useFormContext as R } from "../../hooks/useFormContext.js";
8
+ import B from "../FormField.js";
9
+ import { useFormMachine as G } from "../../../state-management/machines/useFormMachine.js";
10
+ import { evaluateVisibility as U } from "../../utils/visibilityUtils.js";
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: T,
18
- cancelSectionEdit: F
19
- } = p, m = B(), [f, E] = R(!1), N = x(() => {
20
- if (!e.visibilityConditions)
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 o = a.context.data;
23
- return G(e.visibilityConditions, o);
24
- }, [e.visibilityConditions, a.context.data]), r = x(
22
+ const e = o.context.data;
23
+ return U(t.visibilityConditions, e);
24
+ }, [t.visibilityConditions, o.context.data]), a = v(
25
25
  () => ({
26
- title: e.title,
27
- components: e.components || [],
28
- mode: e.mode || "default",
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: e.editText || "Edit",
31
- cancelText: e.cancelText || "Cancel",
32
- saveText: e.saveText || "Save",
33
- showTitle: e.showTitle ?? !0,
34
- showActionLink: e.showActionLink ?? !0
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
- [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]
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
- 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({
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: t
54
+ componentId: c
59
55
  });
60
- }), E(!1)));
56
+ }), h(!1));
61
57
  }, [
62
- a.context.activeDialog,
63
- a.context.data,
64
- a.context.componentOriginalValues,
58
+ o.context.activeDialog,
59
+ o.context.data,
60
+ o.context.componentOriginalValues,
65
61
  n,
66
- d,
67
- r.mode,
62
+ r,
63
+ a.mode,
68
64
  f,
69
- b
65
+ S
70
66
  ]);
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({
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: t,
77
+ componentId: e,
87
78
  value: c,
88
79
  source: "edit_start"
89
- }));
90
- }), T(e.id, n), E(!0);
80
+ });
81
+ }), N(t.id, n), h(!0);
91
82
  }, [
92
- T,
93
- e.id,
83
+ N,
84
+ t.id,
94
85
  n,
95
- m,
86
+ s,
96
87
  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({
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: t
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:", e.id), F(e.id), E(!1);
99
+ }) : console.warn("No backup data found for section:", t.id), y(t.id), h(!1);
113
100
  }, [
114
- a.context.sectionBackups,
115
- e.id,
101
+ o.context.sectionBackups,
102
+ t.id,
116
103
  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 }
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
- console.log(
129
- `FormSection: Dispatching validation trigger for field ${c}`
130
- ), window.dispatchEvent(l);
112
+ window.dispatchEvent(m);
131
113
  });
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;
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 (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,
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
- l,
155
- a.context
132
+ m,
133
+ o.context
156
134
  );
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({
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: i.componentId,
185
- triggerId: i.trigger.id,
186
- actionId: s.id,
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((i) => {
194
- d({
149
+ n.forEach((l) => {
150
+ r({
195
151
  type: "CLEAR_COMPONENT_ALERT",
196
- componentId: i
152
+ componentId: l
197
153
  });
198
- }), n.forEach((i) => {
199
- d({
154
+ }), n.forEach((l) => {
155
+ r({
200
156
  type: "UPDATE_COMPONENT_ORIGINAL_VALUE",
201
- componentId: i
157
+ componentId: l
202
158
  });
203
- }), E(!1);
159
+ }), h(!1);
204
160
  }
205
161
  }, [
206
162
  n,
207
163
  C,
208
- m,
209
- y,
210
- e.id,
164
+ s,
165
+ T,
166
+ t.id,
211
167
  p,
212
- a.context.currentStepIndex,
213
- a.context,
214
- d
168
+ o.context.currentStepIndex,
169
+ o.context,
170
+ r
215
171
  ]);
216
- return /* @__PURE__ */ g(
172
+ return /* @__PURE__ */ u(
217
173
  "div",
218
174
  {
219
175
  style: {
220
- display: N ? "block" : "none"
176
+ display: O ? "block" : "none"
221
177
  },
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(
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: V,
232
- className: u.cancelButton,
187
+ onClick: F,
188
+ className: d.cancelButton,
233
189
  children: [
234
- /* @__PURE__ */ g(P, { className: u.iconSm }),
235
- r.cancelText
190
+ /* @__PURE__ */ u(k, { className: d.iconSm }),
191
+ a.cancelText
236
192
  ]
237
193
  }
238
- ) : /* @__PURE__ */ h(
194
+ ) : /* @__PURE__ */ E(
239
195
  "button",
240
196
  {
241
197
  type: "button",
242
- onClick: O,
243
- className: u.editButton,
198
+ onClick: I,
199
+ className: d.editButton,
244
200
  children: [
245
- /* @__PURE__ */ g(w, { className: u.iconSm }),
246
- r.editText
201
+ /* @__PURE__ */ u(P, { className: d.iconSm }),
202
+ a.editText
247
203
  ]
248
204
  }
249
205
  ) })
250
206
  ] }),
251
- /* @__PURE__ */ h("div", { className: u.sectionContent, children: [
252
- r.components.map((o) => /* @__PURE__ */ g(
253
- U,
207
+ /* @__PURE__ */ E("div", { className: d.sectionContent, children: [
208
+ a.components.map((e) => /* @__PURE__ */ u(
209
+ B,
254
210
  {
255
- component: o,
256
- readOnly: I
211
+ component: e,
212
+ readOnly: V
257
213
  },
258
- o.id
214
+ e.id
259
215
  )),
260
- f && /* @__PURE__ */ g("div", { className: u.saveButtonsWrapper, children: /* @__PURE__ */ h(
261
- j,
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__ */ g(L, { className: u.iconSm }),
267
- r.saveText
222
+ /* @__PURE__ */ u(L, { className: d.iconSm }),
223
+ a.saveText
268
224
  ]
269
225
  }
270
226
  ) })
@@ -273,7 +229,7 @@ const H = M(({ section: e }) => {
273
229
  }
274
230
  );
275
231
  });
276
- H.displayName = "FormSection";
232
+ W.displayName = "FormSection";
277
233
  export {
278
- H as default
234
+ W as default
279
235
  };