@digiform/wizard 0.3.2 → 0.3.4

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.
@@ -5,7 +5,6 @@
5
5
  */
6
6
  export { default as ComponentAdapterComplete } from './ComponentAdapterComplete/ComponentAdapterComplete';
7
7
  export * from './components';
8
- export * from './config';
9
8
  export type { FormWizardProps } from './FormWizard/FormWizard';
10
9
  export { default as FormWizard } from './FormWizard/FormWizard';
11
10
  export * from './hooks';
@@ -442,7 +442,7 @@ export declare const useFormMachineProvider: ({ config, initialData, onSubmit, }
442
442
  type: "TRIGGER_STEP_VALIDATION";
443
443
  fieldIds: string[];
444
444
  }) => void;
445
- currentStep: import('../../../../../core/src/index.ts').FormStepConfig | import('../../../../../core/src/index.ts').TemplateStepConfig;
445
+ currentStep: import('../../../../../core/src/index.ts').FormStepConfig;
446
446
  currentStepId: string;
447
447
  currentStepIndex: number;
448
448
  data: FormData;
@@ -453,7 +453,7 @@ export declare const useFormMachineProvider: ({ config, initialData, onSubmit, }
453
453
  touchedFields: Record<string, boolean>;
454
454
  isFirstStep: boolean;
455
455
  isLastStep: boolean;
456
- steps: (import('../../../../../core/src/index.ts').FormStepConfig | import('../../../../../core/src/index.ts').TemplateStepConfig)[];
456
+ steps: import('../../../../../core/src/index.ts').FormStepConfig[];
457
457
  config: FormWizardConfig;
458
458
  validationEngine: ValidationEngine;
459
459
  findComponentById: (componentId: string) => ComponentConfig | null;
@@ -951,7 +951,7 @@ export declare const FormMachineContext: {
951
951
  type: "TRIGGER_STEP_VALIDATION";
952
952
  fieldIds: string[];
953
953
  }) => void;
954
- currentStep: import('../../../../../core/src/index.ts').FormStepConfig | import('../../../../../core/src/index.ts').TemplateStepConfig;
954
+ currentStep: import('../../../../../core/src/index.ts').FormStepConfig;
955
955
  currentStepId: string;
956
956
  currentStepIndex: number;
957
957
  data: FormData;
@@ -962,7 +962,7 @@ export declare const FormMachineContext: {
962
962
  touchedFields: Record<string, boolean>;
963
963
  isFirstStep: boolean;
964
964
  isLastStep: boolean;
965
- steps: (import('../../../../../core/src/index.ts').FormStepConfig | import('../../../../../core/src/index.ts').TemplateStepConfig)[];
965
+ steps: import('../../../../../core/src/index.ts').FormStepConfig[];
966
966
  config: FormWizardConfig;
967
967
  validationEngine: ValidationEngine;
968
968
  findComponentById: (componentId: string) => ComponentConfig | null;
@@ -1454,7 +1454,7 @@ export declare const useFormMachine: () => readonly [import('xstate').MachineSna
1454
1454
  type: "TRIGGER_STEP_VALIDATION";
1455
1455
  fieldIds: string[];
1456
1456
  }) => void, {
1457
- currentStep: import('../../../../../core/src/index.ts').FormStepConfig | import('../../../../../core/src/index.ts').TemplateStepConfig;
1457
+ currentStep: import('../../../../../core/src/index.ts').FormStepConfig;
1458
1458
  currentStepId: string;
1459
1459
  currentStepIndex: number;
1460
1460
  data: FormData;
@@ -1465,7 +1465,7 @@ export declare const useFormMachine: () => readonly [import('xstate').MachineSna
1465
1465
  touchedFields: Record<string, boolean>;
1466
1466
  isFirstStep: boolean;
1467
1467
  isLastStep: boolean;
1468
- steps: (import('../../../../../core/src/index.ts').FormStepConfig | import('../../../../../core/src/index.ts').TemplateStepConfig)[];
1468
+ steps: import('../../../../../core/src/index.ts').FormStepConfig[];
1469
1469
  config: FormWizardConfig;
1470
1470
  validationEngine: ValidationEngine;
1471
1471
  findComponentById: (componentId: string) => ComponentConfig | null;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@digiform/wizard",
3
- "version": "0.3.2",
3
+ "version": "0.3.4",
4
4
  "description": "React component for rendering configurable multi-step forms from a JSON config",
5
5
  "author": "VladAfanasev",
6
6
  "license": "MIT",
@@ -36,23 +36,41 @@
36
36
  "publishConfig": {
37
37
  "access": "public"
38
38
  },
39
- "dependencies": {},
40
- "peerDependencies": {
41
- "react": ">=18.0.0",
42
- "react-dom": ">=18.0.0",
43
- "xstate": "^5.0.0",
44
- "@xstate/react": "^5.0.0",
39
+ "dependencies": {
40
+ "@radix-ui/react-accordion": "^1.0.0",
41
+ "@radix-ui/react-alert-dialog": "^1.0.0",
42
+ "@radix-ui/react-checkbox": "^1.0.0",
43
+ "@radix-ui/react-context-menu": "^2.0.0",
44
+ "@radix-ui/react-dialog": "^1.0.0",
45
+ "@radix-ui/react-dropdown-menu": "^2.0.0",
46
+ "@radix-ui/react-hover-card": "^1.0.0",
47
+ "@radix-ui/react-label": "^2.0.0",
48
+ "@radix-ui/react-navigation-menu": "^1.0.0",
49
+ "@radix-ui/react-popover": "^1.0.0",
50
+ "@radix-ui/react-progress": "^1.0.0",
51
+ "@radix-ui/react-radio-group": "^1.0.0",
52
+ "@radix-ui/react-scroll-area": "^1.0.0",
53
+ "@radix-ui/react-select": "^2.0.0",
54
+ "@radix-ui/react-separator": "^1.0.0",
55
+ "@radix-ui/react-slot": "^1.0.0",
56
+ "@radix-ui/react-switch": "^1.0.0",
57
+ "@radix-ui/react-tabs": "^1.0.0",
58
+ "@radix-ui/react-toast": "^1.0.0",
59
+ "@radix-ui/react-toggle": "^1.0.0",
60
+ "@radix-ui/react-toggle-group": "^1.0.0",
61
+ "@radix-ui/react-tooltip": "^1.0.0",
45
62
  "@tanstack/react-form": "^1.0.0",
46
63
  "@tanstack/zod-form-adapter": "^0.40.0",
47
- "zod": "^3.20.0",
48
- "@radix-ui/react-checkbox": "^1.3.0",
49
- "@radix-ui/react-dialog": "^1.1.0",
50
- "@radix-ui/react-radio-group": "^1.3.0",
51
- "@radix-ui/react-select": "^2.2.0",
52
- "@radix-ui/react-slot": "^1.2.0",
64
+ "@xstate/react": "^5.0.0",
53
65
  "clsx": "^2.1.0",
54
66
  "date-fns": "^3.6.0",
55
67
  "lucide-react": "^0.462.0",
68
+ "xstate": "^5.0.0",
69
+ "zod": "^3.20.0"
70
+ },
71
+ "peerDependencies": {
72
+ "react": ">=18.0.0",
73
+ "react-dom": ">=18.0.0",
56
74
  "@rijkshuisstijl-community/components-react": ">=7.0.0"
57
75
  }
58
76
  }
@@ -1,11 +1,7 @@
1
1
  "use client";
2
2
  function t(e) {
3
- return typeof e == "object" && e !== null && "templateId" in e;
4
- }
5
- function l(e) {
6
3
  return e && typeof e.template == "object" && typeof e.template.typeId == "string";
7
4
  }
8
5
  export {
9
- l as isTemplateDialogConfig,
10
- t as isTemplateStep
6
+ t as isTemplateDialogConfig
11
7
  };
@@ -1,85 +1,63 @@
1
1
  "use client";
2
- import { jsx as r, jsxs as a } from "react/jsx-runtime";
3
- import { wizardDefaultRenderer as E } 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
- import { FormLayout as s } from "../../../../../ui/src/components/FormLayout/FormLayout.js";
6
- import { formWizardQueryClient as z } from "../../../../../ui/src/lib/queryClient.js";
7
- import { QueryClientProvider as N } from "@tanstack/react-query";
8
- import { clsx as u } from "clsx";
9
- import { memo as M, useState as h, useEffect as P, useMemo as g } from "react";
10
- import t from "./FormWizard.module.css.js";
11
- import W from "../components/FormStep/FormStep.js";
12
- import w from "../components/StepProgressIndicator/StepProgressIndicator.js";
13
- import { hasTemplateSteps as x, resolveFormWizardConfig as L } from "../config/configResolver.js";
14
- import { ThemeProvider as T, useThemeConfig as I } from "../../../../../ui/src/theme/ThemeProvider.js";
15
- import { useFormMachineProvider as R, FormMachineContext as j } from "../../state-management/machines/useFormMachine.js";
16
- import A from "../../../../../ui/src/lib/error-boundaries/FormWizardErrorBoundary.js";
17
- import { FormEditingProvider as B } from "../../../../../ui/src/lib/providers/FormEditingContext.js";
18
- import l from "../../../../../ui/src/lib/error-boundaries/ComponentErrorBoundary.js";
19
- import { ActionManager as H } from "../../trigger-action-system/components/ActionManager.js";
20
- import { registerRenderComponent as Q } from "../../../../../ui/src/component-registry/renderComponent.js";
21
- import { ValidationEngine as b } from "../../validation-system/validation/ValidationEngine.js";
22
- import { Heading as D } from "@rijkshuisstijl-community/components-react";
23
- Q(E);
24
- const v = M(
5
+ import { FormLayout as m } from "../../../../../ui/src/components/FormLayout/FormLayout.js";
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
24
  config: e,
27
- initialData: n = {},
28
- onSubmit: C,
29
- queryClient: y = z
25
+ initialData: o = {},
26
+ onSubmit: l,
27
+ queryClient: c = g
30
28
  }) => {
31
- const [i, d] = h(null), [c, f] = h(null);
32
- P(() => {
33
- (async () => {
34
- try {
35
- if (f(null), x(e)) {
36
- const o = await L(e);
37
- d(o);
38
- } else
39
- d(e);
40
- } catch (o) {
41
- f(
42
- o instanceof Error ? o.message : "Failed to resolve configuration"
43
- ), console.error("Error resolving form configuration:", o);
44
- }
45
- })();
46
- }, [e]);
47
- const p = g(() => new b({
29
+ const n = s(() => new w({
48
30
  messageStyle: e.validationMessageStyle || "withLabel"
49
- }), [e.validationMessageStyle]), S = g(() => i ? {
50
- ...i,
51
- steps: i.steps.map((m) => {
52
- const o = m;
31
+ }), [e.validationMessageStyle]), f = s(() => ({
32
+ ...e,
33
+ steps: e.steps.map((a) => {
34
+ const t = a;
53
35
  return {
54
- ...o,
55
- schema: o.schema || p.getStepSchema(o)
36
+ ...t,
37
+ schema: t.schema || n.getStepSchema(t)
56
38
  };
57
39
  })
58
- } : null, [i, p]), F = R({
59
- config: S || e,
60
- // Fallback to original config if resolution fails
61
- initialData: n,
62
- onSubmit: C
40
+ }), [e, n]), h = P({
41
+ config: f,
42
+ initialData: o,
43
+ onSubmit: l
63
44
  });
64
- return c ? /* @__PURE__ */ a("div", { className: u("form-wizard-error", t.errorState), children: [
65
- /* @__PURE__ */ r("h3", { className: t.errorHeading, children: "Configuration Error" }),
66
- /* @__PURE__ */ r("p", { children: c })
67
- ] }) : i ? /* @__PURE__ */ r(N, { client: y, children: /* @__PURE__ */ r(A, { formId: e.id, children: /* @__PURE__ */ r(B, { children: /* @__PURE__ */ a(j.Provider, { value: F, children: [
68
- /* @__PURE__ */ r(l, { componentName: "ActionManager", children: /* @__PURE__ */ r(H, {}) }),
69
- /* @__PURE__ */ a(s, { className: t.formLayout, children: [
70
- /* @__PURE__ */ r(s.Title, { children: /* @__PURE__ */ r(D, { level: 1, children: e.title }) }),
71
- /* @__PURE__ */ r(s.LeftColumn, { children: /* @__PURE__ */ r(l, { componentName: "StepProgressIndicator", children: /* @__PURE__ */ r(w, {}) }) }),
72
- /* @__PURE__ */ r(l, { componentName: "FormStep", children: /* @__PURE__ */ r(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, {}) })
73
51
  ] })
74
- ] }) }) }) }) : /* @__PURE__ */ r("div", { className: u("form-wizard-loading", t.loadingState), children: /* @__PURE__ */ r("div", { className: t.loadingPulse, children: "Loading form templates..." }) });
52
+ ] }) }) }) });
75
53
  }
76
54
  );
77
- v.displayName = "FormWizardCore";
78
- const V = (e) => {
79
- const n = I();
80
- return /* @__PURE__ */ r(T, { config: n, children: /* @__PURE__ */ r(v, { ...e }) });
55
+ p.displayName = "FormWizardCore";
56
+ const T = (e) => {
57
+ const o = z();
58
+ return /* @__PURE__ */ r(M, { config: o, children: /* @__PURE__ */ r(p, { ...e }) });
81
59
  };
82
- V.displayName = "FormWizard";
60
+ T.displayName = "FormWizard";
83
61
  export {
84
- V as default
62
+ T as default
85
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,158 +1,151 @@
1
1
  "use client";
2
- import { jsxs as h, jsx as n, Fragment as M } from "react/jsx-runtime";
3
- import S from "./FormStep.module.css.js";
2
+ import { jsxs as f, jsx as r, Fragment as _ } from "react/jsx-runtime";
3
+ import g from "./FormStep.module.css.js";
4
4
  /* empty css */
5
- import { isTemplateStep as l } from "../../../../../../ui/src/lib/types/guards.js";
6
- import { logger as C } from "../../../../../../ui/src/lib/logger.js";
7
- import { useForm as U } from "@tanstack/react-form";
5
+ import { logger as w } from "../../../../../../ui/src/lib/logger.js";
6
+ import { useForm as I } from "@tanstack/react-form";
8
7
  import { useRef as p } from "react";
9
- import { LoaderProvider as k, useLoaderContext as W } from "../../context/LoaderContext.js";
10
- import { FormProvider as j } from "../../hooks/useFormContext.js";
11
- import { buildDefaultValues as v } from "../../utils/formDataBuilder.js";
12
- import { resetFormDirtyStateAfterApiPopulation as z } from "../../utils/formDirtyStateSync.js";
13
- import G from "../FormFooter.js";
14
- import H from "../FormHeader.js";
15
- import K from "../FormSection/FormSection.js";
16
- import { ProgressLoaderRuntime as Q } from "../ProgressLoaderRuntime.js";
17
- import { useFormMachine as X } from "../../../state-management/machines/useFormMachine.js";
18
- import { EnhancedActionExecutor as q } from "../../../api-integration/components/EnhancedActionExecutor/EnhancedActionExecutor.js";
19
- import { ValidationEngine as B } from "../../../validation-system/validation/ValidationEngine.js";
20
- const J = ({
21
- currentStep: r,
8
+ import { LoaderProvider as M, useLoaderContext as C } from "../../context/LoaderContext.js";
9
+ import { FormProvider as U } from "../../hooks/useFormContext.js";
10
+ import { buildDefaultValues as k } from "../../utils/formDataBuilder.js";
11
+ import { resetFormDirtyStateAfterApiPopulation as W } from "../../utils/formDirtyStateSync.js";
12
+ import j from "../FormFooter.js";
13
+ import z from "../FormHeader.js";
14
+ import G from "../FormSection/FormSection.js";
15
+ import { ProgressLoaderRuntime as H } from "../ProgressLoaderRuntime.js";
16
+ import { useFormMachine as K } from "../../../state-management/machines/useFormMachine.js";
17
+ import { EnhancedActionExecutor as Q } from "../../../api-integration/components/EnhancedActionExecutor/EnhancedActionExecutor.js";
18
+ import { ValidationEngine as X } from "../../../validation-system/validation/ValidationEngine.js";
19
+ const q = ({
20
+ currentStep: n,
22
21
  hasStepLoader: s,
23
- loaderConfig: o
22
+ loaderConfig: t
24
23
  }) => {
25
- const { isLoadingComplete: e } = W(), u = l(r) ? [] : r.sections || [];
26
- return /* @__PURE__ */ h("div", { className: S.stepContent, children: [
27
- s && /* @__PURE__ */ n("div", { className: S.loaderWrapper, children: /* @__PURE__ */ n(
28
- Q,
24
+ const { isLoadingComplete: o } = C(), l = n.sections || [];
25
+ return /* @__PURE__ */ f("div", { className: g.stepContent, children: [
26
+ s && /* @__PURE__ */ r("div", { className: g.loaderWrapper, children: /* @__PURE__ */ r(
27
+ H,
29
28
  {
30
29
  properties: {
31
- label: o?.label,
32
- showPercentage: o?.showPercentage ?? !0,
33
- duration: o?.duration ?? 3,
34
- size: o?.size ?? "md",
35
- variant: o?.variant ?? "default",
36
- animationSpeed: o?.animationSpeed ?? "normal",
30
+ label: t?.label,
31
+ showPercentage: t?.showPercentage ?? !0,
32
+ duration: t?.duration ?? 3,
33
+ size: t?.size ?? "md",
34
+ variant: t?.variant ?? "default",
35
+ animationSpeed: t?.animationSpeed ?? "normal",
37
36
  autoStart: !0,
38
37
  hideOnComplete: !0,
39
- onComplete: o?.completionMessage ? {
38
+ onComplete: t?.completionMessage ? {
40
39
  showMessage: {
41
40
  enabled: !0,
42
- text: o.completionMessage,
41
+ text: t.completionMessage,
43
42
  type: "success"
44
43
  }
45
44
  } : void 0
46
45
  }
47
46
  }
48
47
  ) }),
49
- (!s || e) && /* @__PURE__ */ n(M, { children: u.map((i) => /* @__PURE__ */ n(K, { section: i }, i.id)) })
48
+ (!s || o) && /* @__PURE__ */ r(_, { children: l.map((c) => /* @__PURE__ */ r(G, { section: c }, c.id)) })
50
49
  ] });
51
- }, Y = () => {
52
- const [r, s, o] = X(), { currentStep: e, config: u } = o, i = p(), d = p(), F = p(), T = u.validationMessageStyle || "withLabel";
53
- i.current || (i.current = new B({ messageStyle: T })), (!d.current || F.current !== e.id) && (l(e) ? d.current = i.current.getStepSchema({
54
- ...e,
55
- sections: []
56
- }) : d.current = i.current.getStepSchema(e), F.current = e.id);
57
- const b = { ...l(e) ? v({
58
- ...e,
59
- sections: []
60
- }) : v(e), ...o.data }, y = (t) => {
61
- (e.actions || []).length > 0 && s({ type: "EXECUTE_ACTIONS", trigger: t });
62
- }, x = p(), f = p(!1);
63
- e.id !== x.current && (e.actions || []).length > 0 && !f.current && (x.current = e.id, f.current = !0, setTimeout(() => {
64
- y("onStepLoad"), setTimeout(() => {
65
- f.current = !1;
50
+ }, B = () => {
51
+ const [n, s, t] = K(), { currentStep: o, config: l } = t, c = p(), h = p(), S = p(), A = l.validationMessageStyle || "withLabel";
52
+ c.current || (c.current = new X({ messageStyle: A })), (!h.current || S.current !== o.id) && (h.current = c.current.getStepSchema(o), S.current = o.id);
53
+ const E = { ...k(o), ...t.data }, v = (e) => {
54
+ (o.actions || []).length > 0 && s({ type: "EXECUTE_ACTIONS", trigger: e });
55
+ }, F = p(), u = p(!1);
56
+ o.id !== F.current && (o.actions || []).length > 0 && !u.current && (F.current = o.id, u.current = !0, setTimeout(() => {
57
+ v("onStepLoad"), setTimeout(() => {
58
+ u.current = !1;
66
59
  }, 1e3);
67
60
  }, 0));
68
- const L = async ({
69
- value: t
61
+ const b = async ({
62
+ value: e
70
63
  }) => {
71
- (e.actions || []).some(
72
- (g) => g.trigger === "onStepFinish"
73
- ) ? s({ type: "REQUEST_NAVIGATION", navigationType: "next" }) : o.nextStep();
74
- }, N = (t) => {
75
- }, D = (t) => {
76
- C.error("Action execution failed", { error: t.message }, t);
77
- }, O = (t) => {
78
- s({ type: "SHOW_ACTION_DIALOG", dialogConfig: t });
79
- }, V = (t) => {
80
- switch (t.type) {
64
+ (o.actions || []).some(
65
+ (d) => d.trigger === "onStepFinish"
66
+ ) ? s({ type: "REQUEST_NAVIGATION", navigationType: "next" }) : t.nextStep();
67
+ }, y = (e) => {
68
+ }, T = (e) => {
69
+ w.error("Action execution failed", { error: e.message }, e);
70
+ }, L = (e) => {
71
+ s({ type: "SHOW_ACTION_DIALOG", dialogConfig: e });
72
+ }, N = (e) => {
73
+ switch (e.type) {
81
74
  case "next":
82
- o.nextStep();
75
+ t.nextStep();
83
76
  break;
84
77
  case "previous":
85
- o.previousStep();
78
+ t.previousStep();
86
79
  break;
87
80
  case "step":
88
- t.targetStep && o.goToStep(t.targetStep);
81
+ e.targetStep && t.goToStep(e.targetStep);
89
82
  break;
90
83
  }
91
- }, m = U({
92
- defaultValues: b,
93
- onSubmit: L
94
- }), P = (t, a) => {
95
- const c = t, g = m.getFieldValue(c), _ = r.context.componentOriginalValues[c]?.value;
96
- if (g !== a) {
97
- const w = a;
98
- o.setData(c, w), m.setFieldValue(c, a);
84
+ }, m = I({
85
+ defaultValues: E,
86
+ onSubmit: b
87
+ }), D = (e, i) => {
88
+ const a = e, d = m.getFieldValue(a), V = n.context.componentOriginalValues[a]?.value;
89
+ if (d !== i) {
90
+ const P = i;
91
+ t.setData(a, P), m.setFieldValue(a, i);
99
92
  try {
100
- z(m, {
101
- updatedFields: [c],
93
+ W(m, {
94
+ updatedFields: [a],
102
95
  debug: process.env.NODE_ENV === "development"
103
96
  });
104
- } catch (I) {
105
- console.error("❌ Failed to reset dirty state:", I);
97
+ } catch (R) {
98
+ console.error("❌ Failed to reset dirty state:", R);
106
99
  }
107
100
  }
108
- _ !== a && setTimeout(() => {
101
+ V !== i && setTimeout(() => {
109
102
  s({
110
103
  type: "MARK_COMPONENT_AS_POPULATED",
111
- componentId: c,
112
- value: a
104
+ componentId: a,
105
+ value: i
113
106
  });
114
107
  }, 0);
115
- }, A = e, E = !l(e) && A.waitForLoader === !0, R = E ? A.loaderConfig : void 0;
116
- return /* @__PURE__ */ h(j, { value: m, children: [
117
- r.matches("executingActions") && (r.context.executingTrigger === "onStepLoad" || r.context.executingTrigger === "onStepFinish") && /* @__PURE__ */ n(
118
- q,
108
+ }, x = o.waitForLoader === !0, O = x ? o.loaderConfig : void 0;
109
+ return /* @__PURE__ */ f(U, { value: m, children: [
110
+ n.matches("executingActions") && (n.context.executingTrigger === "onStepLoad" || n.context.executingTrigger === "onStepFinish") && /* @__PURE__ */ r(
111
+ Q,
119
112
  {
120
- actions: e.actions || [],
121
- trigger: r.context.executingTrigger || "onStepLoad",
122
- formData: r.context.data,
123
- onComplete: N,
124
- onError: D,
125
- onFieldUpdate: P,
126
- onShowDialog: O,
127
- onNavigate: V,
113
+ actions: o.actions || [],
114
+ trigger: n.context.executingTrigger || "onStepLoad",
115
+ formData: n.context.data,
116
+ onComplete: y,
117
+ onError: T,
118
+ onFieldUpdate: D,
119
+ onShowDialog: L,
120
+ onNavigate: N,
128
121
  machineRef: {
129
122
  send: s
130
123
  }
131
124
  }
132
125
  ),
133
- /* @__PURE__ */ h(
126
+ /* @__PURE__ */ f(
134
127
  "form",
135
128
  {
136
- onSubmit: (t) => {
137
- t.preventDefault(), t.stopPropagation(), m.handleSubmit();
129
+ onSubmit: (e) => {
130
+ e.preventDefault(), e.stopPropagation(), m.handleSubmit();
138
131
  },
139
132
  children: [
140
- /* @__PURE__ */ n(H, {}),
141
- /* @__PURE__ */ n(k, { children: /* @__PURE__ */ n(
142
- J,
133
+ /* @__PURE__ */ r(z, {}),
134
+ /* @__PURE__ */ r(M, { children: /* @__PURE__ */ r(
135
+ q,
143
136
  {
144
- currentStep: e,
145
- hasStepLoader: E,
146
- loaderConfig: R
137
+ currentStep: o,
138
+ hasStepLoader: x,
139
+ loaderConfig: O
147
140
  }
148
141
  ) }),
149
- /* @__PURE__ */ n(G, { className: S.footer })
142
+ /* @__PURE__ */ r(j, { className: g.footer })
150
143
  ]
151
144
  }
152
145
  )
153
146
  ] });
154
147
  };
155
- Y.displayName = "FormStep";
148
+ B.displayName = "FormStep";
156
149
  export {
157
- Y as default
150
+ B as default
158
151
  };
@@ -31,7 +31,7 @@ const vt = ({
31
31
  ), D = g(() => i.steps, [i.steps]), L = E === 0, P = E === i.steps.length - 1, T = o(
32
32
  (t) => {
33
33
  for (const e of i.steps) {
34
- const r = "sections" in e ? e.sections : [];
34
+ const r = e.sections || [];
35
35
  for (const l of r || []) {
36
36
  const a = l.components?.find(
37
37
  (c) => c.id === t
@@ -85,7 +85,7 @@ const vt = ({
85
85
  (t) => {
86
86
  let e = !0;
87
87
  for (const r of i.steps) {
88
- const a = ("sections" in r ? r.sections : [])?.find(
88
+ const a = (r.sections || []).find(
89
89
  (c) => c.id === t
90
90
  );
91
91
  if (a) {
@@ -100,7 +100,7 @@ const vt = ({
100
100
  ), W = o(
101
101
  async (t) => {
102
102
  const e = i.steps.find((a) => a.id === t);
103
- if (!e || !("sections" in e)) return !0;
103
+ if (!e) return !0;
104
104
  const r = await d.validateStep(e, u);
105
105
  for (const [a, c] of Object.entries(
106
106
  r.fieldErrors
@@ -1,7 +1,5 @@
1
1
  "use client";
2
- /* empty css */
3
- import { isTemplateStep as c } from "../../../../../ui/src/lib/types/guards.js";
4
- class u {
2
+ class d {
5
3
  schemaBuilder;
6
4
  constructor(s) {
7
5
  this.schemaBuilder = s;
@@ -9,19 +7,19 @@ class u {
9
7
  /**
10
8
  * Validates a single field
11
9
  */
12
- async validateField(s, i) {
10
+ async validateField(s, o) {
13
11
  try {
14
- const e = await i.parseAsync(s);
12
+ const r = await o.parseAsync(s);
15
13
  return {
16
14
  isValid: !0,
17
15
  errors: [],
18
- value: e
16
+ value: r
19
17
  };
20
- } catch (e) {
21
- let r = [];
22
- return e && typeof e == "object" && "errors" in e ? r = e.errors.map((a) => a.message) : r = ["Validation failed"], {
18
+ } catch (r) {
19
+ let e = [];
20
+ return r && typeof r == "object" && "errors" in r ? e = r.errors.map((i) => i.message) : e = ["Validation failed"], {
23
21
  isValid: !1,
24
- errors: r,
22
+ errors: e,
25
23
  value: s
26
24
  };
27
25
  }
@@ -29,51 +27,51 @@ class u {
29
27
  /**
30
28
  * Validates a single field synchronously
31
29
  */
32
- validateFieldSync(s, i) {
33
- let e = s;
34
- s == null && (e = "");
30
+ validateFieldSync(s, o) {
31
+ let r = s;
32
+ s == null && (r = "");
35
33
  try {
36
- const r = i.parse(e);
34
+ const e = o.parse(r);
37
35
  return {
38
36
  isValid: !0,
39
37
  errors: [],
40
- value: r
38
+ value: e
41
39
  };
42
- } catch (r) {
40
+ } catch (e) {
43
41
  let t = [];
44
- return r && typeof r == "object" && "errors" in r ? t = r.errors.map((o) => o.message) : t = ["Validation failed"], {
42
+ return e && typeof e == "object" && "errors" in e ? t = e.errors.map((a) => a.message) : t = ["Validation failed"], {
45
43
  isValid: !1,
46
44
  errors: t,
47
- value: e
45
+ value: r
48
46
  };
49
47
  }
50
48
  }
51
49
  /**
52
50
  * Validates a step
53
51
  */
54
- async validateStep(s, i) {
52
+ async validateStep(s, o) {
55
53
  try {
56
- return await i.parseAsync(s), {
54
+ return await o.parseAsync(s), {
57
55
  isValid: !0,
58
56
  fieldErrors: {},
59
57
  generalErrors: []
60
58
  };
61
- } catch (e) {
62
- const r = {};
59
+ } catch (r) {
60
+ const e = {};
63
61
  let t = [];
64
- if (e && typeof e == "object" && "errors" in e) {
65
- const a = e;
66
- for (const o of a.errors)
67
- if (o.path.length > 0) {
68
- const l = o.path[0].toString();
69
- r[l] || (r[l] = []), r[l].push(o.message);
62
+ if (r && typeof r == "object" && "errors" in r) {
63
+ const i = r;
64
+ for (const a of i.errors)
65
+ if (a.path.length > 0) {
66
+ const l = a.path[0].toString();
67
+ e[l] || (e[l] = []), e[l].push(a.message);
70
68
  } else
71
- t.push(o.message);
69
+ t.push(a.message);
72
70
  } else
73
71
  t = ["Step validation failed"];
74
72
  return {
75
73
  isValid: !1,
76
- fieldErrors: r,
74
+ fieldErrors: e,
77
75
  generalErrors: t
78
76
  };
79
77
  }
@@ -81,26 +79,20 @@ class u {
81
79
  /**
82
80
  * Validates a form
83
81
  */
84
- async validateForm(s, i) {
85
- const e = {}, r = [];
82
+ async validateForm(s, o) {
83
+ const r = {}, e = [];
86
84
  let t = !0;
87
- for (const a of s.steps) {
88
- if (c(a)) {
89
- r.push(
90
- `Template step '${a.id}' needs to be resolved before validation`
91
- ), t = !1;
92
- continue;
93
- }
94
- const o = a, l = this.schemaBuilder.createStepSchema(o), n = await this.validateStep(i, l);
95
- n.isValid || (t = !1, Object.assign(e, n.fieldErrors), r.push(...n.generalErrors));
85
+ for (const i of s.steps) {
86
+ const a = i, l = this.schemaBuilder.createStepSchema(a), n = await this.validateStep(o, l);
87
+ n.isValid || (t = !1, Object.assign(r, n.fieldErrors), e.push(...n.generalErrors));
96
88
  }
97
89
  return {
98
90
  isValid: t,
99
- fieldErrors: e,
100
- generalErrors: r
91
+ fieldErrors: r,
92
+ generalErrors: e
101
93
  };
102
94
  }
103
95
  }
104
96
  export {
105
- u as ValidationExecutor
97
+ d as ValidationExecutor
106
98
  };
@@ -1,7 +0,0 @@
1
- "use client";
2
- function t(e) {
3
- return typeof e == "object" && e !== null && "templateId" in e;
4
- }
5
- export {
6
- t as isTemplateStep
7
- };
@@ -1,14 +0,0 @@
1
- import { FormWizardConfig } from '../../../../../core/src/index.ts';
2
- /**
3
- * Resolves a form wizard configuration, expanding any template step references
4
- * to their full step configurations
5
- */
6
- export declare function resolveFormWizardConfig(config: FormWizardConfig): Promise<FormWizardConfig>;
7
- /**
8
- * Checks if a configuration contains template step references
9
- */
10
- export declare function hasTemplateSteps(config: FormWizardConfig): boolean;
11
- /**
12
- * Gets template IDs used in a configuration
13
- */
14
- export declare function getUsedTemplateIds(config: FormWizardConfig): string[];
@@ -1,9 +0,0 @@
1
- /**
2
- * Form Runtime Configuration
3
- *
4
- * Configuration resolvers and template utilities
5
- */
6
- export * from './configResolver';
7
- export * from './templateConfig';
8
- export * from './templateLoader';
9
- export { getAvailableGenericTemplatesSync, getTemplateInfo, validateTemplateReferences, } from './templateUtils';
@@ -1,148 +0,0 @@
1
- import { FormStepConfig, TemplateStepConfig } from '../../../../../core/src/index.ts';
2
- export type TemplateType = "generic" | "team" | null;
3
- /**
4
- * Template permissions configuration
5
- */
6
- export interface TemplatePermissions {
7
- /** Can add new components to sections */
8
- canAddComponents: boolean;
9
- /** Can remove existing components */
10
- canRemoveComponents: boolean;
11
- /** Can edit component properties */
12
- canEditComponentProperties: boolean;
13
- /** Can add new sections */
14
- canAddSections: boolean;
15
- /** Can remove existing sections */
16
- canRemoveSections: boolean;
17
- /** Can edit section properties */
18
- canEditSectionProperties: boolean;
19
- /** Can edit step title */
20
- canEditStepTitle: boolean;
21
- /** Can edit navigation settings */
22
- canEditNavigation: boolean;
23
- /** Can add/edit actions */
24
- canEditActions: boolean;
25
- /** Can duplicate the step */
26
- canDuplicate: boolean;
27
- /** Can delete the step */
28
- canDelete: boolean;
29
- }
30
- /**
31
- * Template display configuration
32
- */
33
- export interface TemplateDisplayConfig {
34
- /** Template type for UI display */
35
- type: TemplateType;
36
- /** Whether template is readonly */
37
- isReadonly: boolean;
38
- /** Whether to show lock icon */
39
- showLockIcon: boolean;
40
- /** CSS classes for theme styling */
41
- themeClass: string;
42
- /** Icon color classes */
43
- iconColor: string;
44
- /** Tooltip text for locked templates */
45
- lockTooltip?: string;
46
- /** Badge text for template type */
47
- badgeText?: string;
48
- }
49
- /**
50
- * Complete template configuration
51
- */
52
- export interface TemplateConfig {
53
- permissions: TemplatePermissions;
54
- display: TemplateDisplayConfig;
55
- rules: {
56
- /** Message shown when user tries to edit locked content */
57
- lockMessage: string;
58
- /** Whether this template type supports multiple steps */
59
- supportsMultipleSteps: boolean;
60
- /** Default navigation behavior */
61
- defaultNavigation: {
62
- next: {
63
- label: string;
64
- enabled: boolean;
65
- };
66
- previous: {
67
- label: string;
68
- enabled: boolean;
69
- };
70
- };
71
- };
72
- }
73
- /**
74
- * Gets the complete template configuration for a given template ID or step
75
- */
76
- export declare function getTemplateConfig(templateIdOrStep: string | FormStepConfig | TemplateStepConfig): TemplateConfig;
77
- /**
78
- * Gets template permissions for a given template ID or step
79
- */
80
- export declare function getTemplatePermissions(templateIdOrStep: string | FormStepConfig | TemplateStepConfig): TemplatePermissions;
81
- /**
82
- * Gets template display configuration for a given template ID or step
83
- */
84
- export declare function getTemplateDisplayConfig(templateIdOrStep: string | FormStepConfig | TemplateStepConfig): TemplateDisplayConfig;
85
- /**
86
- * Checks if a specific action is allowed for a template or step
87
- */
88
- export declare function isActionAllowed(templateIdOrStep: string | FormStepConfig | TemplateStepConfig, action: keyof TemplatePermissions): boolean;
89
- /**
90
- * Checks if a step is locked for editing
91
- */
92
- export declare function isStepLocked(step: FormStepConfig | TemplateStepConfig, templateOrigin?: {
93
- templateId: string;
94
- stepIndex?: number;
95
- }): boolean;
96
- /**
97
- * Gets the lock message for a template
98
- */
99
- export declare function getLockMessage(templateIdOrStep: string | FormStepConfig | TemplateStepConfig): string;
100
- /**
101
- * Validates if a template action should be blocked and returns appropriate message
102
- */
103
- export declare function validateTemplateAction(templateIdOrStep: string | FormStepConfig | TemplateStepConfig, action: keyof TemplatePermissions): {
104
- allowed: boolean;
105
- message?: string;
106
- };
107
- /**
108
- * Gets template type from various input formats
109
- */
110
- export declare function getTemplateTypeFromInput(input: string | FormStepConfig | TemplateStepConfig): TemplateType;
111
- /**
112
- * Utility to check if input represents a generic template
113
- */
114
- export declare function isGenericTemplateInput(input: string | FormStepConfig | TemplateStepConfig): boolean;
115
- /**
116
- * Utility to check if input represents a team template
117
- */
118
- export declare function isTeamTemplateInput(input: string | FormStepConfig | TemplateStepConfig): boolean;
119
- /**
120
- * Creates a comprehensive template info object for UI components
121
- */
122
- export declare function getTemplateInfo(templateIdOrStep: string | FormStepConfig | TemplateStepConfig): {
123
- type: TemplateType;
124
- permissions: TemplatePermissions;
125
- display: TemplateDisplayConfig;
126
- rules: {
127
- /** Message shown when user tries to edit locked content */
128
- lockMessage: string;
129
- /** Whether this template type supports multiple steps */
130
- supportsMultipleSteps: boolean;
131
- /** Default navigation behavior */
132
- defaultNavigation: {
133
- next: {
134
- label: string;
135
- enabled: boolean;
136
- };
137
- previous: {
138
- label: string;
139
- enabled: boolean;
140
- };
141
- };
142
- };
143
- isLocked: boolean;
144
- canEdit: boolean;
145
- isGeneric: boolean;
146
- isTeam: boolean;
147
- isRegularStep: boolean;
148
- };
@@ -1,25 +0,0 @@
1
- import { FormStepConfig, FormTemplate, StepNavigation, TemplateStepConfig } from '../../../../../core/src/index.ts';
2
- /**
3
- * Loads a template by ID, handling both generic and team templates
4
- */
5
- export declare function loadTemplate(templateId: string): Promise<FormTemplate>;
6
- /**
7
- * Resolves a template step reference to a full FormStepConfig
8
- */
9
- export declare function resolveTemplateStep(templateStep: TemplateStepConfig, defaultNavigation?: StepNavigation, stepIndex?: number): Promise<FormStepConfig>;
10
- /**
11
- * Gets template metadata without loading the full template
12
- */
13
- export declare function getTemplateMetadata(templateId: string): Promise<import('../../../../../core/src/index.ts').TemplateMetadata>;
14
- /**
15
- * Lists available templates from both generic and team sources
16
- */
17
- export declare function getAvailableTemplates(): Promise<string[]>;
18
- /**
19
- * Lists available generic templates only (for backward compatibility)
20
- */
21
- export declare function getAvailableGenericTemplates(): string[];
22
- /**
23
- * Clears the template cache (useful for development/testing)
24
- */
25
- export declare function clearTemplateCache(): void;
@@ -1,12 +0,0 @@
1
- /**
2
- * Loader-specific template functions for form-wizard-component
3
- *
4
- * This file only contains functions that depend on the local templateLoader.
5
- * All other template utilities should be imported directly from @libs/shared/utils
6
- */
7
- export declare const getAvailableGenericTemplatesSync: () => string[];
8
- export declare const getTemplateInfo: (templateId: string) => Promise<any>;
9
- export declare const validateTemplateReferences: (config: import('../../../../../core/src/index.ts').FormWizardConfig) => Promise<{
10
- isValid: boolean;
11
- errors: string[];
12
- }>;
@@ -1,20 +0,0 @@
1
- "use client";
2
- const t = {
3
- GENERIC: "generic-",
4
- TEAM: "team-"
5
- };
6
- function n(e) {
7
- return e.startsWith(t.GENERIC) ? "generic" : e.startsWith(t.TEAM) ? "team" : null;
8
- }
9
- function r(e) {
10
- return n(e) === "generic";
11
- }
12
- function i(e) {
13
- return n(e) === "team";
14
- }
15
- export {
16
- t as TEMPLATE_PREFIXES,
17
- n as getTemplateTypeFromId,
18
- r as isGenericTemplate,
19
- i as isTeamTemplate
20
- };
@@ -1,34 +0,0 @@
1
- "use client";
2
- import { resolveTemplateStep as i } from "./templateLoader.js";
3
- import { isTemplateStep as n } from "../../../../../core/src/types/guards.js";
4
- async function m(e) {
5
- const s = {
6
- next: { label: "Next", enabled: !0 },
7
- previous: { label: "Previous", enabled: !0 }
8
- }, l = await Promise.all(
9
- e.steps.map(async (t, r) => {
10
- if (n(t)) {
11
- const a = { ...s };
12
- r === 0 && (a.previous.enabled = !1), r === e.steps.length - 1 && (a.next.label = "Submit");
13
- const o = t.stepIndex;
14
- return await i(
15
- t,
16
- a,
17
- o
18
- );
19
- }
20
- return t;
21
- })
22
- );
23
- return {
24
- ...e,
25
- steps: l
26
- };
27
- }
28
- function f(e) {
29
- return e.steps.some((s) => n(s));
30
- }
31
- export {
32
- f as hasTemplateSteps,
33
- m as resolveFormWizardConfig
34
- };
@@ -1,228 +0,0 @@
1
- "use client";
2
- /* empty css */
3
- import { isGenericTemplate as v, isTeamTemplate as h } from "../../../../../ui/src/lib/utils/templateUtils.js";
4
- async function g() {
5
- try {
6
- const { templateStorageService: e } = await import("@formbuilder/builder");
7
- return e;
8
- } catch (e) {
9
- return console.warn("Template storage service not available:", e), null;
10
- }
11
- }
12
- async function y() {
13
- try {
14
- const e = await g();
15
- if (!e) return;
16
- if (!e.isReady()) {
17
- const a = await fetch("/form.config.json");
18
- if (a.ok) {
19
- const r = (await a.json()).storage?.paths?.templates;
20
- r && await e.initialize(r);
21
- }
22
- }
23
- } catch (e) {
24
- console.warn("Failed to initialize template storage service:", e);
25
- }
26
- }
27
- function d(e) {
28
- return {
29
- metadata: e.metadata,
30
- stepsData: e.stepsData || [],
31
- // Default to empty array if no steps
32
- preview: {
33
- componentCount: e.preview?.componentCount || 0,
34
- sectionCount: e.preview?.sectionCount || 0
35
- },
36
- governance: e.governance || {
37
- approved: !1,
38
- complianceTags: [],
39
- deprecated: !1
40
- }
41
- };
42
- }
43
- const f = /* @__PURE__ */ new Map(), l = {
44
- "generic-contact-information": async () => {
45
- const e = await fetch(
46
- "/src/packages/form-wizard/admin/templates/generic/contact-information.json"
47
- );
48
- if (!e.ok)
49
- throw new Error(
50
- `Failed to fetch generic-contact-information template: ${e.status}`
51
- );
52
- return e.json();
53
- },
54
- "generic-consent-agreement": async () => {
55
- const e = await fetch(
56
- "/src/packages/form-wizard/admin/templates/generic/consent-agreement.json"
57
- );
58
- if (!e.ok)
59
- throw new Error(
60
- `Failed to fetch generic-consent-agreement template: ${e.status}`
61
- );
62
- return e.json();
63
- },
64
- "generic-feedback-form": async () => {
65
- const e = await fetch(
66
- "/src/packages/form-wizard/admin/templates/generic/feedback-form.json"
67
- );
68
- if (!e.ok)
69
- throw new Error(
70
- `Failed to fetch generic-feedback-form template: ${e.status}`
71
- );
72
- return e.json();
73
- },
74
- "generic-incident-registration": async () => {
75
- const e = await fetch(
76
- "/src/packages/form-wizard/admin/templates/generic/incident-registration.json"
77
- );
78
- if (!e.ok)
79
- throw new Error(
80
- `Failed to fetch generic-incident-registration template: ${e.status}`
81
- );
82
- return e.json();
83
- }
84
- };
85
- async function b(e) {
86
- if (f.has(e))
87
- return f.get(e);
88
- try {
89
- let a;
90
- if (v(e)) {
91
- const i = l[e];
92
- if (!i) {
93
- const s = Object.keys(l);
94
- throw new Error(
95
- `Generic template '${e}' not found. Available generic templates: ${s.join(", ")}`
96
- );
97
- }
98
- const r = await i();
99
- a = d(
100
- r
101
- );
102
- } else if (h(e)) {
103
- await y();
104
- const i = await g();
105
- if (!i)
106
- throw new Error(
107
- `Team template '${e}' could not be loaded: template storage service is not available`
108
- );
109
- const r = await i.loadTemplate(
110
- e,
111
- "team"
112
- );
113
- if (!r.success)
114
- throw new Error(
115
- `Team template '${e}' not found: ${"error" in r && r.error?.message || "Unknown error"}`
116
- );
117
- a = d(r.data);
118
- } else {
119
- const i = l[e];
120
- if (i) {
121
- const r = await i();
122
- a = d(
123
- r
124
- );
125
- } else {
126
- const r = Object.keys(l);
127
- throw new Error(
128
- `Template '${e}' not found. Available generic templates: ${r.join(", ")}`
129
- );
130
- }
131
- }
132
- if (!a.metadata || !Array.isArray(a.stepsData))
133
- throw new Error(
134
- `Invalid template structure for template: ${e}. Templates must have metadata and stepsData array.`
135
- );
136
- return f.set(e, a), a;
137
- } catch (a) {
138
- throw new Error(
139
- `Failed to load template '${e}': ${a instanceof Error ? a.message : "Unknown error"}`
140
- );
141
- }
142
- }
143
- async function E(e, a, i) {
144
- const r = await b(e.templateId);
145
- let s;
146
- if (r.stepsData && Array.isArray(r.stepsData) && r.stepsData.length > 0)
147
- i !== void 0 && i >= 0 && i < r.stepsData.length ? s = r.stepsData[i] : (s = r.stepsData[0], console.warn(
148
- `Invalid stepIndex ${i} for template, using first step`
149
- ));
150
- else
151
- throw new Error(`Template ${e.templateId} has no steps data`);
152
- const u = s.sections?.map((w) => ({
153
- ...w,
154
- components: w.components.map((t) => {
155
- const m = ((c) => `comp-${e.id}-${t.id || c}`)(t.id), o = {
156
- id: m,
157
- type: t.type,
158
- properties: {
159
- // Use properties from component.properties if it exists, otherwise fallback to root level
160
- label: t.properties?.label || t.label || "",
161
- placeholder: t.properties?.placeholder || t.placeholder || "",
162
- description: t.properties?.description || t.description || "",
163
- required: t.properties?.required || t.required || !1,
164
- disabled: t.properties?.disabled || t.disabled || !1,
165
- readOnly: t.properties?.readOnly || t.readOnly || !1,
166
- invalid: t.properties?.invalid || !1,
167
- // Add type-specific properties
168
- type: t.properties?.type || t.type,
169
- // Copy all other properties from component.properties if it exists
170
- ...t.properties && Object.keys(t.properties).reduce(
171
- (c, p) => ([
172
- "label",
173
- "placeholder",
174
- "description",
175
- "required",
176
- "disabled",
177
- "readOnly",
178
- "invalid",
179
- "type"
180
- ].includes(p) || (c[p] = t.properties[p]), c),
181
- {}
182
- )
183
- },
184
- // Copy validation if it exists
185
- ...t.validation && { validation: t.validation }
186
- }, n = e.componentOverrides?.[m];
187
- return n ? {
188
- ...o,
189
- ...n,
190
- // Merge properties deeply to allow partial property updates
191
- properties: {
192
- ...o.properties,
193
- ...n.properties
194
- },
195
- // Merge validation deeply if both exist
196
- ...o.validation && n.validation && {
197
- validation: {
198
- ...o.validation,
199
- ...n.validation
200
- }
201
- }
202
- } : o;
203
- })
204
- }));
205
- return {
206
- id: e.id,
207
- // Use the step ID from the form config
208
- title: e.title || s.title,
209
- displayTitle: s.displayTitle,
210
- showStepNumber: e.showStepNumber !== void 0 ? e.showStepNumber : s.showStepNumber,
211
- sections: u,
212
- navigation: {
213
- // Use default navigation, then template navigation if available, then step override
214
- ...a,
215
- ...s.navigation,
216
- // Cast since navigation might not exist in Omit type
217
- ...e.navigation
218
- },
219
- // Copy actions if they exist
220
- ...s.actions && {
221
- actions: s.actions
222
- }
223
- };
224
- }
225
- export {
226
- b as loadTemplate,
227
- E as resolveTemplateStep
228
- };