@digiform/wizard 0.3.1 → 0.3.3

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 (54) hide show
  1. package/features/form-runtime/components/FormFooter.d.ts +5 -0
  2. package/features/form-runtime/hooks/useValidationEvents.d.ts +0 -1
  3. package/features/form-runtime/index.d.ts +0 -1
  4. package/features/state-management/machines/formMachine.d.ts +3 -0
  5. package/features/state-management/machines/types.d.ts +4 -0
  6. package/features/state-management/machines/useFormMachine.d.ts +24 -6
  7. package/package.json +31 -15
  8. package/styles.css +1 -1
  9. package/ui/src/lib/types/guards.js +1 -5
  10. package/wizard/src/features/api-integration/services/ApiCallService.js +65 -74
  11. package/wizard/src/features/dialog-system/components/ActionDialog/ActionDialog.js +39 -43
  12. package/wizard/src/features/dialog-system/components/ConfirmationDialog/ConfirmationDialog.js +37 -41
  13. package/wizard/src/features/dialog-system/components/EmailVerificationDialog/EmailVerificationDialog.js +44 -45
  14. package/wizard/src/features/form-runtime/FormWizard/FormWizard.js +48 -95
  15. package/wizard/src/features/form-runtime/FormWizard/FormWizard.module.css.js +4 -12
  16. package/wizard/src/features/form-runtime/components/FormFooter.js +53 -184
  17. package/wizard/src/features/form-runtime/components/FormSection/FormSection.js +150 -194
  18. package/wizard/src/features/form-runtime/components/FormStep/FormStep.js +92 -108
  19. package/wizard/src/features/form-runtime/components/StepProgressIndicator/StepProgressIndicator.js +24 -30
  20. package/wizard/src/features/form-runtime/hooks/useComponentTriggers.js +44 -63
  21. package/wizard/src/features/form-runtime/hooks/useFieldEventHandlers.js +26 -40
  22. package/wizard/src/features/form-runtime/hooks/useValidationEvents.js +22 -25
  23. package/wizard/src/features/form-runtime/utils/formDirtyStateSync.js +26 -37
  24. package/wizard/src/features/form-runtime/utils/logger.js +12 -12
  25. package/wizard/src/features/state-management/machines/actions/navigationActions.js +13 -8
  26. package/wizard/src/features/state-management/machines/componentTriggerEngine.js +167 -432
  27. package/wizard/src/features/state-management/machines/formMachine.js +558 -677
  28. package/wizard/src/features/state-management/machines/useFormMachine.js +173 -191
  29. package/wizard/src/features/trigger-action-system/components/ActionManager.js +35 -86
  30. package/wizard/src/features/validation-system/validation/SchemaBuilder.js +28 -82
  31. package/wizard/src/features/validation-system/validation/ValidationCache.js +11 -27
  32. package/wizard/src/features/validation-system/validation/ValidationExecutor.js +47 -87
  33. package/core/src/types/guards.js +0 -7
  34. package/features/form-runtime/config/configResolver.d.ts +0 -14
  35. package/features/form-runtime/config/index.d.ts +0 -9
  36. package/features/form-runtime/config/templateConfig.d.ts +0 -148
  37. package/features/form-runtime/config/templateLoader.d.ts +0 -25
  38. package/features/form-runtime/config/templateUtils.d.ts +0 -12
  39. package/features/form-runtime/utils/formSaver.d.ts +0 -22
  40. package/features/state-management/components/ValidationBuilder/ValidationBuilder.d.ts +0 -9
  41. package/features/state-management/machines/__tests__/setup.d.ts +0 -0
  42. package/features/state-management/machines/__tests__/vitest.config.d.ts +0 -2
  43. package/features/state-management/machines/actions/validationActions.d.ts +0 -68
  44. package/features/state-management/machines/lazyLoading.d.ts +0 -34
  45. package/features/state-management/machines/validation/index.d.ts +0 -5
  46. package/features/state-management/machines/validation/validateField.d.ts +0 -2
  47. package/features/state-management/machines/validation/validateForm.d.ts +0 -2
  48. package/features/state-management/machines/validation/validateSection.d.ts +0 -2
  49. package/features/state-management/machines/validation/validateStep.d.ts +0 -2
  50. package/features/state-management/machines/validation/validationTypes.d.ts +0 -1
  51. package/features/trigger-action-system/components/FieldWarning/FieldWarning.d.ts +0 -20
  52. package/ui/src/lib/utils/templateUtils.js +0 -20
  53. package/wizard/src/features/form-runtime/config/configResolver.js +0 -34
  54. package/wizard/src/features/form-runtime/config/templateLoader.js +0 -235
@@ -1,50 +1,49 @@
1
1
  "use client";
2
- import { jsx as e, jsxs as o } from "react/jsx-runtime";
2
+ import { jsx as e, jsxs as a } from "react/jsx-runtime";
3
3
  /* empty css */
4
4
  import { Alert as E, AlertDescription as $ } from "../../../../../../ui/src/components/alert/alert.js";
5
5
  import { Button as m } from "../../../../../../ui/src/components/button/button.js";
6
- import { Dialog as D, DialogContent as V, DialogHeader as x, DialogTitle as A, DialogDescription as L } from "../../../../../../ui/src/components/dialog/dialog.js";
6
+ import { Dialog as x, DialogContent as D, DialogHeader as V, DialogTitle as A, DialogDescription as L } from "../../../../../../ui/src/components/dialog/dialog.js";
7
7
  import { ValidationCode as P } from "../../../../../../ui/src/components/ValidationCode/ValidationCode.js";
8
8
  import { CheckCircle as _, Mail as j, AlertCircle as q } from "lucide-react";
9
- import { memo as H, useState as f, useEffect as I, useCallback as W } from "react";
9
+ import { memo as H, useState as f, useEffect as I, useCallback as O } from "react";
10
10
  import i from "./EmailVerificationDialog.module.css.js";
11
- const Y = H(
11
+ const W = H(
12
12
  ({
13
13
  config: h,
14
- formData: z,
15
- onButtonClick: g,
16
- onClose: F,
17
- isOpen: u
14
+ formData: Y,
15
+ onButtonClick: u,
16
+ onClose: z,
17
+ isOpen: C
18
18
  }) => {
19
- console.log("🔥 EmailVerificationDialog rendering!", { isOpen: u, config: h });
20
- const t = h.templateMetadata, [c, C] = f(""), [n, r] = f("idle"), [p, l] = f(""), [d, v] = f(0), [b, k] = f(0);
19
+ const t = h.templateMetadata, [c, p] = f(""), [n, s] = f("idle"), [g, l] = f(""), [d, v] = f(0), [b, k] = f(0);
21
20
  I(() => {
22
21
  if (d > 0) {
23
- const a = setTimeout(() => v(d - 1), 1e3);
24
- return () => clearTimeout(a);
22
+ const o = setTimeout(() => v(d - 1), 1e3);
23
+ return () => clearTimeout(o);
25
24
  }
26
25
  }, [d]);
27
- const N = W(async () => {
28
- r("verifying");
29
- const a = b + 1;
30
- k(a);
26
+ const N = O(async () => {
27
+ s("verifying");
28
+ const o = b + 1;
29
+ k(o);
31
30
  try {
32
- if (await new Promise((s) => setTimeout(s, 1500)), c === "123456" || c === "000000" || c === "111111")
33
- r("success");
31
+ if (await new Promise((r) => setTimeout(r, 1500)), c === "123456" || c === "000000" || c === "111111")
32
+ s("success");
34
33
  else {
35
- const s = t?.maxAttempts;
36
- if (s && a >= s)
37
- r("blocked"), l(
34
+ const r = t?.maxAttempts;
35
+ if (r && o >= r)
36
+ s("blocked"), l(
38
37
  "Maximum verification attempts exceeded. Please request a new verification code."
39
38
  );
40
39
  else {
41
- r("error");
42
- const M = s ? s - a : null, R = t?.errorMessage || "Invalid code. Please try again.", S = M ? ` (${M} attempts remaining)` : "";
40
+ s("error");
41
+ const M = r ? r - o : null, R = t?.errorMessage || "Invalid code. Please try again.", S = M ? ` (${M} attempts remaining)` : "";
43
42
  l(R + S);
44
43
  }
45
44
  }
46
45
  } catch {
47
- r("error"), l(
46
+ s("error"), l(
48
47
  t?.errorMessage || "Verification failed. Please try again."
49
48
  );
50
49
  }
@@ -53,18 +52,18 @@ const Y = H(
53
52
  t?.errorMessage,
54
53
  t?.maxAttempts,
55
54
  b
56
- ]), w = (a) => {
57
- C(a), (n === "error" || n === "blocked") && (r("idle"), l(""));
58
- }, T = (a) => {
59
- console.log("completedCode", a), t?.enableAutoSubmit && n === "idle" && N();
55
+ ]), w = (o) => {
56
+ p(o), (n === "error" || n === "blocked") && (s("idle"), l(""));
57
+ }, T = (o) => {
58
+ t?.enableAutoSubmit && n === "idle" && N();
60
59
  }, y = () => {
61
- v(t?.resendTimer || 60), C(""), r("idle"), l(""), k(0);
60
+ v(t?.resendTimer || 60), p(""), s("idle"), l(""), k(0);
62
61
  }, B = () => {
63
- g({ type: "close" });
62
+ u({ type: "close" });
64
63
  };
65
- return n === "success" ? /* @__PURE__ */ e(D, { open: u, onOpenChange: () => !1, children: /* @__PURE__ */ o(V, { className: i.dialogContent, children: [
66
- /* @__PURE__ */ o(x, { children: [
67
- /* @__PURE__ */ o("div", { className: i.headerRow, children: [
64
+ return n === "success" ? /* @__PURE__ */ e(x, { open: C, onOpenChange: () => !1, children: /* @__PURE__ */ a(D, { className: i.dialogContent, children: [
65
+ /* @__PURE__ */ a(V, { children: [
66
+ /* @__PURE__ */ a("div", { className: i.headerRow, children: [
68
67
  /* @__PURE__ */ e(_, { className: `${i.iconMd} ${i.iconSuccess}` }),
69
68
  /* @__PURE__ */ e(A, { children: t?.successTitle || "Verification Successful" })
70
69
  ] }),
@@ -73,7 +72,7 @@ const Y = H(
73
72
  /* @__PURE__ */ e("div", { className: i.successButtonRow, children: /* @__PURE__ */ e(
74
73
  m,
75
74
  {
76
- onClick: () => g(
75
+ onClick: () => u(
77
76
  t?.onVerifiedAction || {
78
77
  type: "navigate",
79
78
  direction: "next"
@@ -83,16 +82,16 @@ const Y = H(
83
82
  children: t?.continueButtonLabel || "Continue"
84
83
  }
85
84
  ) })
86
- ] }) }) : /* @__PURE__ */ e(D, { open: u, onOpenChange: () => !1, children: /* @__PURE__ */ o(V, { className: i.dialogContent, children: [
87
- /* @__PURE__ */ o(x, { children: [
88
- /* @__PURE__ */ o("div", { className: i.headerRow, children: [
85
+ ] }) }) : /* @__PURE__ */ e(x, { open: C, onOpenChange: () => !1, children: /* @__PURE__ */ a(D, { className: i.dialogContent, children: [
86
+ /* @__PURE__ */ a(V, { children: [
87
+ /* @__PURE__ */ a("div", { className: i.headerRow, children: [
89
88
  /* @__PURE__ */ e(j, { className: `${i.iconMd} ${i.iconMail}` }),
90
89
  /* @__PURE__ */ e(A, { children: h.title })
91
90
  ] }),
92
91
  /* @__PURE__ */ e(L, { children: h.content })
93
92
  ] }),
94
- /* @__PURE__ */ o("div", { className: i.formContent, children: [
95
- /* @__PURE__ */ o("div", { className: i.codeSection, children: [
93
+ /* @__PURE__ */ a("div", { className: i.formContent, children: [
94
+ /* @__PURE__ */ a("div", { className: i.codeSection, children: [
96
95
  /* @__PURE__ */ e("div", { className: i.codeLabel, children: "Verification Code" }),
97
96
  /* @__PURE__ */ e("div", { className: i.codeCenter, children: /* @__PURE__ */ e(
98
97
  P,
@@ -105,9 +104,9 @@ const Y = H(
105
104
  }
106
105
  ) })
107
106
  ] }),
108
- (n === "error" || n === "blocked") && p && /* @__PURE__ */ o(E, { variant: "destructive", children: [
107
+ (n === "error" || n === "blocked") && g && /* @__PURE__ */ a(E, { variant: "destructive", children: [
109
108
  /* @__PURE__ */ e(q, { className: i.iconSm }),
110
- /* @__PURE__ */ e($, { children: p })
109
+ /* @__PURE__ */ e($, { children: g })
111
110
  ] }),
112
111
  t?.enableResend && n !== "blocked" && /* @__PURE__ */ e("div", { className: i.resendText, children: d > 0 ? `Resend code in ${d}s` : /* @__PURE__ */ e(
113
112
  m,
@@ -128,7 +127,7 @@ const Y = H(
128
127
  }
129
128
  ) })
130
129
  ] }),
131
- /* @__PURE__ */ o("div", { className: i.footerButtonRow, children: [
130
+ /* @__PURE__ */ a("div", { className: i.footerButtonRow, children: [
132
131
  /* @__PURE__ */ e(m, { variant: "secondary", onClick: B, children: t?.cancelButtonLabel || "Cancel" }),
133
132
  /* @__PURE__ */ e(
134
133
  m,
@@ -142,8 +141,8 @@ const Y = H(
142
141
  ] }) });
143
142
  }
144
143
  );
145
- Y.displayName = "EmailVerificationDialog";
144
+ W.displayName = "EmailVerificationDialog";
146
145
  export {
147
- Y as EmailVerificationDialog,
148
- Y as default
146
+ W as EmailVerificationDialog,
147
+ W as default
149
148
  };
@@ -1,110 +1,63 @@
1
1
  "use client";
2
- import { jsx as e, jsxs as l } from "react/jsx-runtime";
3
- import { wizardDefaultRenderer as z } from "../../../renderer/wizardRenderer.js";
2
+ import { jsx as r, jsxs as d } from "react/jsx-runtime";
3
+ import { wizardDefaultRenderer as u } from "../../../renderer/wizardRenderer.js";
4
4
  /* empty css */
5
5
  import { FormLayout as m } from "../../../../../ui/src/components/FormLayout/FormLayout.js";
6
- import { formWizardQueryClient as E } from "../../../../../ui/src/lib/queryClient.js";
7
- import { QueryClientProvider as M } from "@tanstack/react-query";
8
- import { clsx as g } from "clsx";
9
- import { memo as N, useState as h, useEffect as w, useMemo as u } from "react";
10
- import n from "./FormWizard.module.css.js";
11
- import W from "../components/FormStep/FormStep.js";
12
- import L from "../components/StepProgressIndicator/StepProgressIndicator.js";
13
- import { hasTemplateSteps as P, resolveFormWizardConfig as T } from "../config/configResolver.js";
14
- import { ThemeProvider as I, useThemeConfig as x } from "../../../../../ui/src/theme/ThemeProvider.js";
15
- import { useFormMachineProvider as b, FormMachineContext as U } from "../../state-management/machines/useFormMachine.js";
16
- import j from "../../../../../ui/src/lib/error-boundaries/FormWizardErrorBoundary.js";
17
- import { FormEditingProvider as O } from "../../../../../ui/src/lib/providers/FormEditingContext.js";
18
- import s from "../../../../../ui/src/lib/error-boundaries/ComponentErrorBoundary.js";
19
- import { ActionManager as R } from "../../trigger-action-system/components/ActionManager.js";
20
- import { registerRenderComponent as V } from "../../../../../ui/src/component-registry/renderComponent.js";
21
- import { ValidationEngine as k } from "../../validation-system/validation/ValidationEngine.js";
22
- import { Heading as A } from "@rijkshuisstijl-community/components-react";
23
- V(z);
24
- const v = N(
6
+ import { formWizardQueryClient as g } from "../../../../../ui/src/lib/queryClient.js";
7
+ import { QueryClientProvider as y } from "@tanstack/react-query";
8
+ import { memo as C, useMemo as s } from "react";
9
+ import F from "./FormWizard.module.css.js";
10
+ import v from "../components/FormStep/FormStep.js";
11
+ import S from "../components/StepProgressIndicator/StepProgressIndicator.js";
12
+ import { ThemeProvider as M, useThemeConfig as z } from "../../../../../ui/src/theme/ThemeProvider.js";
13
+ import { useFormMachineProvider as P, FormMachineContext as N } from "../../state-management/machines/useFormMachine.js";
14
+ import W from "../../../../../ui/src/lib/error-boundaries/FormWizardErrorBoundary.js";
15
+ import { FormEditingProvider as E } from "../../../../../ui/src/lib/providers/FormEditingContext.js";
16
+ import i from "../../../../../ui/src/lib/error-boundaries/ComponentErrorBoundary.js";
17
+ import { ActionManager as x } from "../../trigger-action-system/components/ActionManager.js";
18
+ import { registerRenderComponent as L } from "../../../../../ui/src/component-registry/renderComponent.js";
19
+ import { ValidationEngine as w } from "../../validation-system/validation/ValidationEngine.js";
20
+ import { Heading as I } from "@rijkshuisstijl-community/components-react";
21
+ L(u);
22
+ const p = C(
25
23
  ({
26
- config: r,
27
- initialData: a = {},
28
- onSubmit: C,
29
- queryClient: y = E
24
+ config: e,
25
+ initialData: o = {},
26
+ onSubmit: l,
27
+ queryClient: c = g
30
28
  }) => {
31
- console.log(
32
- "🏁 [FormWizard] FormWizardCore component MOUNTING with config:",
33
- {
34
- configId: r.id,
35
- configTitle: r.title,
36
- stepCount: r.steps?.length,
37
- validationMessageStyle: r.validationMessageStyle,
38
- hasInitialData: Object.keys(a).length > 0
39
- }
40
- ), typeof window < "u" && setTimeout(() => {
41
- console.log(
42
- "🚨 [FormWizard] MOUNTED SUCCESSFULLY - Check console for detailed logs"
43
- );
44
- }, 100);
45
- const [t, d] = h(null), [c, f] = h(null);
46
- w(() => {
47
- (async () => {
48
- try {
49
- if (f(null), P(r)) {
50
- const o = await T(r);
51
- d(o);
52
- } else
53
- d(r);
54
- } catch (o) {
55
- f(
56
- o instanceof Error ? o.message : "Failed to resolve configuration"
57
- ), console.error("Error resolving form configuration:", o);
58
- }
59
- })();
60
- }, [r]);
61
- const p = u(() => {
62
- console.log(
63
- "🚀 [FormWizard] Creating ValidationEngine with messageStyle:",
64
- r.validationMessageStyle || "withLabel"
65
- );
66
- const i = new k({
67
- messageStyle: r.validationMessageStyle || "withLabel"
68
- });
69
- return console.log("✅ [FormWizard] ValidationEngine created:", {
70
- engine: !!i,
71
- validateField: typeof i.validateField,
72
- messageStyle: r.validationMessageStyle || "withLabel"
73
- }), i;
74
- }, [r.validationMessageStyle]), S = u(() => t ? {
75
- ...t,
76
- steps: t.steps.map((i) => {
77
- const o = i;
29
+ const n = s(() => new w({
30
+ messageStyle: e.validationMessageStyle || "withLabel"
31
+ }), [e.validationMessageStyle]), f = s(() => ({
32
+ ...e,
33
+ steps: e.steps.map((a) => {
34
+ const t = a;
78
35
  return {
79
- ...o,
80
- schema: o.schema || p.getStepSchema(o)
36
+ ...t,
37
+ schema: t.schema || n.getStepSchema(t)
81
38
  };
82
39
  })
83
- } : null, [t, p]), F = b({
84
- config: S || r,
85
- // Fallback to original config if resolution fails
86
- initialData: a,
87
- onSubmit: C
40
+ }), [e, n]), h = P({
41
+ config: f,
42
+ initialData: o,
43
+ onSubmit: l
88
44
  });
89
- return c ? /* @__PURE__ */ l("div", { className: g("form-wizard-error", n.errorState), children: [
90
- /* @__PURE__ */ e("h3", { className: n.errorHeading, children: "Configuration Error" }),
91
- /* @__PURE__ */ e("p", { children: c })
92
- ] }) : t ? /* @__PURE__ */ e(M, { client: y, children: /* @__PURE__ */ e(j, { formId: r.id, children: /* @__PURE__ */ e(O, { children: /* @__PURE__ */ l(U.Provider, { value: F, children: [
93
- /* @__PURE__ */ e(s, { componentName: "ActionManager", children: /* @__PURE__ */ e(R, {}) }),
94
- /* @__PURE__ */ l(m, { className: n.formLayout, children: [
95
- /* @__PURE__ */ e(m.Title, { children: /* @__PURE__ */ e(A, { level: 1, children: r.title }) }),
96
- /* @__PURE__ */ e(m.LeftColumn, { children: /* @__PURE__ */ e(s, { componentName: "StepProgressIndicator", children: /* @__PURE__ */ e(L, {}) }) }),
97
- /* @__PURE__ */ e(s, { componentName: "FormStep", children: /* @__PURE__ */ e(W, {}) })
45
+ return /* @__PURE__ */ r(y, { client: c, children: /* @__PURE__ */ r(W, { formId: e.id, children: /* @__PURE__ */ r(E, { children: /* @__PURE__ */ d(N.Provider, { value: h, children: [
46
+ /* @__PURE__ */ r(i, { componentName: "ActionManager", children: /* @__PURE__ */ r(x, {}) }),
47
+ /* @__PURE__ */ d(m, { className: F.formLayout, children: [
48
+ /* @__PURE__ */ r(m.Title, { children: /* @__PURE__ */ r(I, { level: 1, children: e.title }) }),
49
+ /* @__PURE__ */ r(m.LeftColumn, { children: /* @__PURE__ */ r(i, { componentName: "StepProgressIndicator", children: /* @__PURE__ */ r(S, {}) }) }),
50
+ /* @__PURE__ */ r(i, { componentName: "FormStep", children: /* @__PURE__ */ r(v, {}) })
98
51
  ] })
99
- ] }) }) }) }) : /* @__PURE__ */ e("div", { className: g("form-wizard-loading", n.loadingState), children: /* @__PURE__ */ e("div", { className: n.loadingPulse, children: "Loading form templates..." }) });
52
+ ] }) }) }) });
100
53
  }
101
54
  );
102
- v.displayName = "FormWizardCore";
103
- const B = (r) => {
104
- const a = x();
105
- return /* @__PURE__ */ e(I, { config: a, children: /* @__PURE__ */ e(v, { ...r }) });
55
+ p.displayName = "FormWizardCore";
56
+ const T = (e) => {
57
+ const o = z();
58
+ return /* @__PURE__ */ r(M, { config: o, children: /* @__PURE__ */ r(p, { ...e }) });
106
59
  };
107
- B.displayName = "FormWizard";
60
+ T.displayName = "FormWizard";
108
61
  export {
109
- B as default
62
+ T as default
110
63
  };
@@ -1,16 +1,8 @@
1
1
  "use client";
2
- const o = "fb-errorState_khSRW", t = "fb-errorHeading_dGdN2", e = "fb-loadingState_Pdhds", r = "fb-loadingPulse_QIw08", a = "fb-formLayout_JzC8E", n = {
3
- errorState: o,
4
- errorHeading: t,
5
- loadingState: e,
6
- loadingPulse: r,
7
- formLayout: a
2
+ const o = "fb-formLayout_JzC8E", t = {
3
+ formLayout: o
8
4
  };
9
5
  export {
10
- n as default,
11
- t as errorHeading,
12
- o as errorState,
13
- a as formLayout,
14
- r as loadingPulse,
15
- e as loadingState
6
+ t as default,
7
+ o as formLayout
16
8
  };
@@ -1,209 +1,78 @@
1
1
  "use client";
2
- import { jsx as f, jsxs as p } from "react/jsx-runtime";
3
- import { clsx as S } from "clsx";
2
+ import { jsx as h, jsxs as F } from "react/jsx-runtime";
3
+ import { clsx as b } from "clsx";
4
4
  /* empty css */
5
- import { useFormContext as V } from "../hooks/useFormContext.js";
6
- import { useFormEditing as y } from "../../../../../ui/src/lib/providers/FormEditingContext.js";
7
- import { useFormMachine as v } from "../../state-management/machines/useFormMachine.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,
5
+ import { useFormContext as S } from "../hooks/useFormContext.js";
6
+ import { useFormEditing as g } from "../../../../../ui/src/lib/providers/FormEditingContext.js";
7
+ import { useFormMachine as N } from "../../state-management/machines/useFormMachine.js";
8
+ import { Button as A } from "@rijkshuisstijl-community/components-react";
9
+ const I = ({
10
+ navigation: r,
11
+ children: a,
12
+ isDisplayOnly: e = !1,
13
+ onNext: c,
14
+ isLastStep: p = !1,
15
15
  isDisabled: n = !1,
16
- ...r
16
+ labels: i,
17
+ ...o
17
18
  }) => {
18
- const u = () => {
19
- a || n || g?.();
20
- };
21
- return /* @__PURE__ */ p(
19
+ const l = () => {
20
+ e || n || c?.();
21
+ }, m = r?.next?.label || (p ? i?.finish ?? "Voltooien" : i?.next ?? "Volgende");
22
+ return /* @__PURE__ */ F(
22
23
  "div",
23
24
  {
24
- className: S(
25
- (n || a) && "opacity-50",
26
- r.className
25
+ className: b(
26
+ (n || e) && "opacity-50",
27
+ o.className
27
28
  ),
28
- ...r,
29
+ ...o,
29
30
  children: [
30
- d,
31
- l?.next?.enabled !== !1 && /* @__PURE__ */ f(
32
- E,
31
+ a,
32
+ r?.next?.enabled !== !1 && /* @__PURE__ */ h(
33
+ A,
33
34
  {
34
35
  appearance: "primary-action-button",
35
- onClick: u,
36
- disabled: n || a,
37
- children: l?.next?.label || (m ? "Voltooien" : "Volgende")
36
+ onClick: l,
37
+ disabled: n || e,
38
+ children: m
38
39
  }
39
40
  )
40
41
  ]
41
42
  }
42
43
  );
43
- }, A = ({ children: l, ...d }) => {
44
- const { isEditing: a } = y(), [g, m, n] = v(), { currentStep: r, isLastStep: u } = n, { navigation: b } = r, e = V();
45
- return /* @__PURE__ */ f(
46
- M,
44
+ }, k = ({ children: r, labels: a, ...e }) => {
45
+ const { isEditing: c } = g(), [p, n, i] = N(), { currentStep: o, isLastStep: l, nextStep: m } = i, { navigation: u } = o, s = S(), x = () => {
46
+ const d = Object.keys(s.state.fieldMeta).filter((f) => {
47
+ const t = s.state.fieldMeta[f];
48
+ return !t.isValid && t.errors?.length > 0;
49
+ });
50
+ d.length > 0 && n({ type: "TRIGGER_STEP_VALIDATION", fieldIds: d });
51
+ };
52
+ return /* @__PURE__ */ h(
53
+ I,
47
54
  {
48
- navigation: b,
55
+ navigation: u,
49
56
  onNext: async () => {
57
+ if (!s.state.canSubmit) {
58
+ x();
59
+ return;
60
+ }
61
+ const f = (o.actions ?? []).some((t) => t.trigger === "onStepFinish");
50
62
  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);
63
+ f ? await s.handleSubmit() : m();
64
+ } catch (t) {
65
+ console.error("Form submission failed:", t);
198
66
  }
199
67
  },
200
- isLastStep: u,
201
- isDisabled: a,
202
- ...d,
203
- children: /* @__PURE__ */ f(e.Subscribe, { children: l })
68
+ isLastStep: l,
69
+ isDisabled: c,
70
+ labels: a,
71
+ ...e,
72
+ children: /* @__PURE__ */ h(s.Subscribe, { children: r })
204
73
  }
205
74
  );
206
75
  };
207
76
  export {
208
- A as default
77
+ k as default
209
78
  };