@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,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,22 +0,0 @@
1
- import { FormWizardConfig } from '../../../../../core/src/index.ts';
2
- export interface SaveResult {
3
- success: boolean;
4
- error?: {
5
- message: string;
6
- code?: string;
7
- };
8
- metadata?: {
9
- filePath?: string;
10
- timestamp?: number;
11
- };
12
- }
13
- /**
14
- * Save form configuration using the pluggable save provider system
15
- * This is a self-contained function that doesn't rely on external utilities
16
- */
17
- export declare function saveFormConfig(projectId: string, wizardId: string, config: FormWizardConfig): Promise<SaveResult>;
18
- /**
19
- * Load form configuration
20
- * Companion function to saveFormConfig for loading saved forms
21
- */
22
- export declare function loadFormConfig(projectId: string, wizardId: string): Promise<FormWizardConfig | null>;
@@ -1,9 +0,0 @@
1
- import { ComponentValidation } from '../../machines/validation/validationTypes';
2
- interface ValidationBuilderProps {
3
- componentType: string;
4
- componentLabel: string;
5
- validation: ComponentValidation;
6
- onChange: (validation: ComponentValidation) => void;
7
- }
8
- export declare const ValidationBuilder: React.FC<ValidationBuilderProps>;
9
- export {};
@@ -1,2 +0,0 @@
1
- declare const _default: import('vite').UserConfig;
2
- export default _default;
@@ -1,68 +0,0 @@
1
- import { ActionFunction } from 'xstate';
2
- import { FormMachineContext, FormMachineEvents } from '../types';
3
- /**
4
- * Set form data for a specific field (optimized to reduce object spreading)
5
- */
6
- export declare const setFormData: ActionFunction<import('xstate').MachineContext, import('xstate').AnyEventObject, import('xstate').EventObject, import('xstate').NonReducibleUnknown, import('xstate').ProvidedActor, never, never, never, never>;
7
- /**
8
- * Set field state for a component (optimized to reduce deep object spreading)
9
- */
10
- export declare const setFieldState: ActionFunction<import('xstate').MachineContext, import('xstate').AnyEventObject, import('xstate').EventObject, import('xstate').NonReducibleUnknown, import('xstate').ProvidedActor, never, never, never, never>;
11
- /**
12
- * Mark field as touched during validation (optimized to avoid unnecessary updates)
13
- */
14
- export declare const markFieldTouched: ActionFunction<import('xstate').MachineContext, import('xstate').AnyEventObject, import('xstate').EventObject, import('xstate').NonReducibleUnknown, import('xstate').ProvidedActor, never, never, never, never>;
15
- /**
16
- * Set form validation errors
17
- */
18
- export declare const setFormErrors: ActionFunction<import('xstate').MachineContext, import('xstate').AnyEventObject, import('xstate').EventObject, import('xstate').NonReducibleUnknown, import('xstate').ProvidedActor, never, never, never, never>;
19
- /**
20
- * Set submission state
21
- */
22
- export declare const setSubmittingTrue: ActionFunction<import('xstate').MachineContext, import('xstate').AnyEventObject, import('xstate').EventObject, import('xstate').NonReducibleUnknown, import('xstate').ProvidedActor, never, never, never, never>;
23
- export declare const setSubmittingFalse: ActionFunction<import('xstate').MachineContext, import('xstate').AnyEventObject, import('xstate').EventObject, import('xstate').NonReducibleUnknown, import('xstate').ProvidedActor, never, never, never, never>;
24
- /**
25
- * Set form submission errors
26
- */
27
- export declare const setSubmissionError: ActionFunction<import('xstate').MachineContext, import('xstate').AnyEventObject, import('xstate').EventObject, import('xstate').NonReducibleUnknown, import('xstate').ProvidedActor, never, never, never, never>;
28
- /**
29
- * Start section editing by creating backup (optimized backup creation)
30
- */
31
- export declare const startSectionEdit: ActionFunction<import('xstate').MachineContext, import('xstate').AnyEventObject, import('xstate').EventObject, import('xstate').NonReducibleUnknown, import('xstate').ProvidedActor, never, never, never, never>;
32
- /**
33
- * Cancel section editing by restoring from backup (optimized restoration)
34
- */
35
- export declare const cancelSectionEdit: ActionFunction<any, any, import('xstate').EventObject, import('xstate').NonReducibleUnknown, import('xstate').ProvidedActor, never, never, never, never>;
36
- /**
37
- * Set field change validation warning
38
- */
39
- export declare const setFieldValidationWarning: ActionFunction<import('xstate').MachineContext, import('xstate').AnyEventObject, import('xstate').EventObject, import('xstate').NonReducibleUnknown, import('xstate').ProvidedActor, never, never, never, never>;
40
- /**
41
- * Dismiss field validation warning
42
- */
43
- export declare const dismissFieldValidationWarning: ActionFunction<any, any, import('xstate').EventObject, import('xstate').NonReducibleUnknown, import('xstate').ProvidedActor, never, never, never, never>;
44
- /**
45
- * Start field verification process
46
- */
47
- export declare const startFieldVerification: ActionFunction<import('xstate').MachineContext, import('xstate').AnyEventObject, import('xstate').EventObject, import('xstate').NonReducibleUnknown, import('xstate').ProvidedActor, never, never, never, never>;
48
- /**
49
- * Complete field verification process
50
- */
51
- export declare const completeFieldVerification: ActionFunction<import('xstate').MachineContext, import('xstate').AnyEventObject, import('xstate').EventObject, import('xstate').NonReducibleUnknown, import('xstate').ProvidedActor, never, never, never, never>;
52
- /**
53
- * Clear field changes and validation state
54
- */
55
- export declare const clearFieldChanges: ActionFunction<import('xstate').MachineContext, import('xstate').AnyEventObject, import('xstate').EventObject, import('xstate').NonReducibleUnknown, import('xstate').ProvidedActor, never, never, never, never>;
56
- /**
57
- * Update form validity based on current step
58
- */
59
- export declare const updateFormValidity: ActionFunction<import('xstate').MachineContext, import('xstate').AnyEventObject, import('xstate').EventObject, import('xstate').NonReducibleUnknown, import('xstate').ProvidedActor, never, never, never, never>;
60
- /**
61
- * Reset TanStack Form dirty state for a specific field
62
- * This action is called via event to reset TanStack Form's field meta state
63
- */
64
- export declare const resetFieldTanStackState: ({ context, event, self, }: {
65
- context: FormMachineContext;
66
- event: FormMachineEvents;
67
- self: any;
68
- }) => void;
@@ -1,34 +0,0 @@
1
- /**
2
- * Lazy loading utilities for form machine modules
3
- * Enables code splitting and reduced initial bundle size
4
- */
5
- export declare const lazyImports: {
6
- ComponentTriggerEngine: () => Promise<{
7
- createExecutionPlan: typeof import('./componentTriggerEngine').createExecutionPlan;
8
- determineTriggerContext: typeof import('./componentTriggerEngine').determineTriggerContext;
9
- evaluateComponentTriggers: typeof import('./componentTriggerEngine').evaluateComponentTriggers;
10
- findComponentTriggers: typeof import('./componentTriggerEngine').findComponentTriggers;
11
- findComponentActions: typeof import('./componentTriggerEngine').findComponentActions;
12
- getTriggersForAction: typeof import('./componentTriggerEngine').getTriggersForAction;
13
- hasComponentTriggers: typeof import('./componentTriggerEngine').hasComponentTriggers;
14
- hasComponentActions: typeof import('./componentTriggerEngine').hasComponentActions;
15
- findDirtyComponentsWithTriggers: typeof import('./componentTriggerEngine').findDirtyComponentsWithTriggers;
16
- findDirtyComponentsForNavigation: typeof import('./componentTriggerEngine').findDirtyComponentsForNavigation;
17
- }>;
18
- saveActions: () => Promise<typeof import("./actions/saveActions")>;
19
- validationActions: () => Promise<typeof import("./actions/validationActions")>;
20
- navigationGuards: () => Promise<typeof import("./guards/navigationGuards")>;
21
- triggerGuards: () => Promise<typeof import("./guards/triggerGuards")>;
22
- saveGuards: () => Promise<typeof import("./guards/saveGuards")>;
23
- };
24
- export declare const featureModules: {
25
- advancedTriggers: Promise<any>;
26
- complexValidation: Promise<any>;
27
- saveFeatures: Promise<any>;
28
- };
29
- export declare const preloadCriticalModules: () => Promise<void>;
30
- export declare const isModuleLoaded: (moduleName: keyof typeof lazyImports) => boolean;
31
- export declare const bundleMonitor: {
32
- trackModuleLoad: (moduleName: string, size?: number) => void;
33
- trackBundleSize: () => void;
34
- };
@@ -1,5 +0,0 @@
1
- export * from './validateField';
2
- export * from './validateForm';
3
- export * from './validateSection';
4
- export * from './validateStep';
5
- export * from './validationTypes';
@@ -1,2 +0,0 @@
1
- import { FormMachineContext } from '../types';
2
- export declare const validateField: (context: FormMachineContext, fieldName: string) => string | null;
@@ -1,2 +0,0 @@
1
- import { FormMachineContext } from '../types';
2
- export declare const validateForm: (context: FormMachineContext) => Record<string, string[]>;
@@ -1,2 +0,0 @@
1
- import { FormMachineContext } from '../types';
2
- export declare const validateSection: (context: FormMachineContext, sectionId: string) => Record<string, string[]>;
@@ -1,2 +0,0 @@
1
- import { FormMachineContext } from '../types';
2
- export declare const validateStep: (context: FormMachineContext, stepId: string) => Record<string, string[]>;
@@ -1 +0,0 @@
1
- export { type ComponentConfig, type ComponentValidation, DEFAULT_VALIDATION_MESSAGES, getValidationMessage, type SecureCustomValidator, type ValidationRule, } from '../../../../../../core/src/index.ts';
@@ -1,20 +0,0 @@
1
- import { FieldWarning as FieldWarningType } from '../../../../../../core/src/index.ts';
2
- import { default as React } from 'react';
3
- interface FieldWarningProps {
4
- warning: FieldWarningType;
5
- onDismiss?: (warningId: string) => void;
6
- className?: string;
7
- }
8
- export declare const FieldWarning: React.FC<FieldWarningProps>;
9
- interface FieldWarningListProps {
10
- fieldId: string;
11
- warnings: FieldWarningType[];
12
- onDismiss?: (warningId: string) => void;
13
- className?: string;
14
- }
15
- /**
16
- * Component to display multiple warnings for a field
17
- * Handles spacing and layout of multiple warnings
18
- */
19
- export declare const FieldWarningList: React.FC<FieldWarningListProps>;
20
- export default FieldWarning;
@@ -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,235 +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 m() {
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 m();
15
- if (!e) return;
16
- if (!e.isReady()) {
17
- const i = await fetch("/form.config.json");
18
- if (i.ok) {
19
- const r = (await i.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(), c = {
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 i;
90
- if (v(e)) {
91
- const a = c[e];
92
- if (!a) {
93
- const o = Object.keys(c);
94
- throw new Error(
95
- `Generic template '${e}' not found. Available generic templates: ${o.join(", ")}`
96
- );
97
- }
98
- const r = await a();
99
- i = d(
100
- r
101
- );
102
- } else if (h(e)) {
103
- await y();
104
- const a = await m();
105
- if (!a)
106
- throw new Error(
107
- `Team template '${e}' could not be loaded: template storage service is not available`
108
- );
109
- const r = await a.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
- i = d(r.data);
118
- } else {
119
- const a = c[e];
120
- if (a) {
121
- const r = await a();
122
- i = d(
123
- r
124
- );
125
- } else {
126
- const r = Object.keys(c);
127
- throw new Error(
128
- `Template '${e}' not found. Available generic templates: ${r.join(", ")}`
129
- );
130
- }
131
- }
132
- if (!i.metadata || !Array.isArray(i.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, i), i;
137
- } catch (i) {
138
- throw new Error(
139
- `Failed to load template '${e}': ${i instanceof Error ? i.message : "Unknown error"}`
140
- );
141
- }
142
- }
143
- async function E(e, i, a) {
144
- console.log(
145
- "Resolving template step:",
146
- e,
147
- "stepIndex:",
148
- a
149
- );
150
- const r = await b(e.templateId);
151
- console.log("Loaded template:", r);
152
- let o;
153
- if (r.stepsData && Array.isArray(r.stepsData) && r.stepsData.length > 0)
154
- a !== void 0 && a >= 0 && a < r.stepsData.length ? (o = r.stepsData[a], console.log(`Using template data for step ${a}:`, o)) : (o = r.stepsData[0], console.warn(
155
- `Invalid stepIndex ${a} for template, using first step`
156
- ));
157
- else
158
- throw new Error(`Template ${e.templateId} has no steps data`);
159
- const u = o.sections?.map((w) => ({
160
- ...w,
161
- components: w.components.map((t) => {
162
- const g = ((l) => `comp-${e.id}-${t.id || l}`)(t.id), s = {
163
- id: g,
164
- type: t.type,
165
- properties: {
166
- // Use properties from component.properties if it exists, otherwise fallback to root level
167
- label: t.properties?.label || t.label || "",
168
- placeholder: t.properties?.placeholder || t.placeholder || "",
169
- description: t.properties?.description || t.description || "",
170
- required: t.properties?.required || t.required || !1,
171
- disabled: t.properties?.disabled || t.disabled || !1,
172
- readOnly: t.properties?.readOnly || t.readOnly || !1,
173
- invalid: t.properties?.invalid || !1,
174
- // Add type-specific properties
175
- type: t.properties?.type || t.type,
176
- // Copy all other properties from component.properties if it exists
177
- ...t.properties && Object.keys(t.properties).reduce(
178
- (l, p) => ([
179
- "label",
180
- "placeholder",
181
- "description",
182
- "required",
183
- "disabled",
184
- "readOnly",
185
- "invalid",
186
- "type"
187
- ].includes(p) || (l[p] = t.properties[p]), l),
188
- {}
189
- )
190
- },
191
- // Copy validation if it exists
192
- ...t.validation && { validation: t.validation }
193
- }, n = e.componentOverrides?.[g];
194
- return n ? {
195
- ...s,
196
- ...n,
197
- // Merge properties deeply to allow partial property updates
198
- properties: {
199
- ...s.properties,
200
- ...n.properties
201
- },
202
- // Merge validation deeply if both exist
203
- ...s.validation && n.validation && {
204
- validation: {
205
- ...s.validation,
206
- ...n.validation
207
- }
208
- }
209
- } : s;
210
- })
211
- }));
212
- return {
213
- id: e.id,
214
- // Use the step ID from the form config
215
- title: e.title || o.title,
216
- displayTitle: o.displayTitle,
217
- showStepNumber: e.showStepNumber !== void 0 ? e.showStepNumber : o.showStepNumber,
218
- sections: u,
219
- navigation: {
220
- // Use default navigation, then template navigation if available, then step override
221
- ...i,
222
- ...o.navigation,
223
- // Cast since navigation might not exist in Omit type
224
- ...e.navigation
225
- },
226
- // Copy actions if they exist
227
- ...o.actions && {
228
- actions: o.actions
229
- }
230
- };
231
- }
232
- export {
233
- b as loadTemplate,
234
- E as resolveTemplateStep
235
- };