@digiform/wizard 0.2.10 → 0.2.16
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/core/src/types/api.js +12 -0
- package/core/src/types/form-config.js +60 -0
- package/core/src/types/form-wizard-config-schema.js +113 -0
- package/core/src/types/guards.js +19 -0
- package/core/src/types/validation.js +61 -0
- package/core/src/utils/apiBodyUtils.js +95 -0
- package/features/api-integration.d.ts +2 -0
- package/features/api-integration.js +17 -0
- package/features/dialog-system.d.ts +2 -0
- package/features/dialog-system.js +9 -0
- package/features/form-runtime.d.ts +2 -0
- package/features/form-runtime.js +63 -0
- package/features/state-management.d.ts +2 -0
- package/features/state-management.js +21 -0
- package/features/trigger-action-system.d.ts +2 -0
- package/features/trigger-action-system.js +12 -0
- package/features/validation-system.d.ts +2 -0
- package/features/validation-system.js +23 -0
- package/index.js +108 -17470
- package/package.json +41 -30
- package/styles.css +1 -4
- package/ui/src/component-registry/renderComponent.js +11 -0
- package/ui/src/components/FormLayout/FormLayout.js +135 -0
- package/ui/src/components/FormLayout/FormLayout.module.css.js +20 -0
- package/ui/src/components/GridLayout/GridLayout.js +62 -0
- package/ui/src/components/GridLayout/GridLayout.module.css.js +16 -0
- package/ui/src/components/GridLayoutColumn/GridLayoutColumn.js +37 -0
- package/ui/src/components/GridLayoutColumn/GridLayoutColumn.module.css.js +10 -0
- package/ui/src/components/ProgressLoaderBar/ProgressLoaderBar.js +108 -0
- package/ui/src/components/ProgressLoaderBar/ProgressLoaderBar.module.css.js +20 -0
- package/ui/src/components/ProgressLoaderBar/useProgressAnimation.js +31 -0
- package/ui/src/components/ValidationCode/ValidationCode.js +198 -0
- package/ui/src/components/ValidationCode/ValidationCode.module.css.js +20 -0
- package/ui/src/components/alert/alert.js +30 -0
- package/ui/src/components/alert/alert.module.css.js +14 -0
- package/ui/src/components/badge/badge.js +20 -0
- package/ui/src/components/badge/badge.module.css.js +12 -0
- package/ui/src/components/box/box.js +8 -0
- package/ui/src/components/box/box.module.css.js +8 -0
- package/ui/src/components/button/button.js +25 -0
- package/ui/src/components/button/button.module.css.js +18 -0
- package/ui/src/components/card/card.js +106 -0
- package/ui/src/components/card/card.module.css.js +44 -0
- package/ui/src/components/checkbox/checkbox.js +20 -0
- package/ui/src/components/checkbox/checkbox.module.css.js +10 -0
- package/ui/src/components/dialog/dialog.js +67 -0
- package/ui/src/components/dialog/dialog.module.css.js +20 -0
- package/ui/src/components/form-header-base/form-header-base.js +59 -0
- package/ui/src/components/form-header-base/form-header-base.module.css.js +14 -0
- package/ui/src/components/input/input.js +20 -0
- package/ui/src/components/input/input.module.css.js +8 -0
- package/ui/src/components/radio-group/radio-group.js +30 -0
- package/ui/src/components/radio-group/radio-group.module.css.js +14 -0
- package/ui/src/components/select/select.js +115 -0
- package/ui/src/components/select/select.module.css.js +32 -0
- package/ui/src/components/sheet/sheet.js +71 -0
- package/ui/src/components/sheet/sheet.module.css.js +46 -0
- package/ui/src/components/textarea/textarea.js +19 -0
- package/ui/src/components/textarea/textarea.module.css.js +8 -0
- package/ui/src/design-system/components/FormFieldWrapper.js +16 -0
- package/ui/src/lib/assets/icons/Check.js +26 -0
- package/ui/src/lib/assets/icons/ChevronRight.js +26 -0
- package/ui/src/lib/error-boundaries/BaseErrorBoundary.js +155 -0
- package/ui/src/lib/error-boundaries/ComponentErrorBoundary.js +153 -0
- package/ui/src/lib/error-boundaries/FormWizardErrorBoundary.js +107 -0
- package/ui/src/lib/logger.js +106 -0
- package/ui/src/lib/providers/FormEditingContext.js +21 -0
- package/ui/src/lib/queryClient.js +26 -0
- package/ui/src/lib/types/guards.js +11 -0
- package/ui/src/lib/utils/componentUtils.js +38 -0
- package/ui/src/lib/utils/templateDialogResolver.js +85 -0
- package/ui/src/lib/utils/templateUtils.js +52 -0
- package/ui/src/theme/ThemeProvider.js +15 -0
- package/wizard/src/features/api-integration/components/EnhancedActionExecutor/EnhancedActionExecutor.js +370 -0
- package/wizard/src/features/api-integration/services/ActionExecutor.js +339 -0
- package/wizard/src/features/api-integration/services/ApiCallExecutor.js +6 -0
- package/wizard/src/features/api-integration/services/ApiCallService.js +309 -0
- package/wizard/src/features/api-integration/services/DialogExecutor.js +6 -0
- package/wizard/src/features/api-integration/services/GenericTriggerService.js +284 -0
- package/wizard/src/features/api-integration/services/NavigationExecutor.js +6 -0
- package/wizard/src/features/dialog-system/components/ActionDialog/ActionDialog.js +115 -0
- package/wizard/src/features/dialog-system/components/ActionDialog/ActionDialog.module.css.js +29 -0
- package/wizard/src/features/dialog-system/components/ConfirmationDialog/ConfirmationDialog.js +64 -0
- package/wizard/src/features/dialog-system/components/ConfirmationDialog/ConfirmationDialog.module.css.js +22 -0
- package/wizard/src/features/dialog-system/components/EmailVerificationDialog/EmailVerificationDialog.js +149 -0
- package/wizard/src/features/dialog-system/components/EmailVerificationDialog/EmailVerificationDialog.module.css.js +40 -0
- package/wizard/src/features/form-runtime/ComponentAdapterComplete/ComponentAdapterComplete.js +107 -0
- package/wizard/src/features/form-runtime/ComponentAdapterComplete/ComponentAdapterComplete.module.css.js +10 -0
- package/wizard/src/features/form-runtime/FormWizard/FormWizard.js +107 -0
- package/wizard/src/features/form-runtime/FormWizard/FormWizard.module.css.js +16 -0
- package/wizard/src/features/form-runtime/components/FormField.js +405 -0
- package/wizard/src/features/form-runtime/components/FormFooter.js +209 -0
- package/wizard/src/features/form-runtime/components/FormHeader.js +29 -0
- package/wizard/src/features/form-runtime/components/FormSection/FormSection.js +279 -0
- package/wizard/src/features/form-runtime/components/FormSection/FormSection.module.css.js +20 -0
- package/wizard/src/features/form-runtime/components/FormStep/FormStep.js +167 -0
- package/wizard/src/features/form-runtime/components/FormStep/FormStep.module.css.js +12 -0
- package/wizard/src/features/form-runtime/components/ProgressLoaderRuntime.js +88 -0
- package/wizard/src/features/form-runtime/components/StepProgressIndicator/StepProgressIndicator.js +61 -0
- package/wizard/src/features/form-runtime/components/StepProgressIndicator/StepProgressIndicator.module.css.js +34 -0
- package/wizard/src/features/form-runtime/components/displayValue/displayValue.js +21 -0
- package/wizard/src/features/form-runtime/components/displayValue/displayValue.module.css.js +10 -0
- package/wizard/src/features/form-runtime/components/renderers/DisplayModeRenderer/DisplayModeRenderer.js +28 -0
- package/wizard/src/features/form-runtime/components/renderers/DisplayModeRenderer/DisplayModeRenderer.module.css.js +8 -0
- package/wizard/src/features/form-runtime/components/renderers/InteractiveFieldRenderer/InteractiveFieldRenderer.js +56 -0
- package/wizard/src/features/form-runtime/components/renderers/InteractiveFieldRenderer/InteractiveFieldRenderer.module.css.js +8 -0
- package/wizard/src/features/form-runtime/config/configResolver.js +38 -0
- package/wizard/src/features/form-runtime/config/templateConfig.js +156 -0
- package/wizard/src/features/form-runtime/config/templateLoader.js +265 -0
- package/wizard/src/features/form-runtime/config/templateUtils.js +14 -0
- package/wizard/src/features/form-runtime/context/LoaderContext.js +36 -0
- package/wizard/src/features/form-runtime/hooks/useApiActions.js +60 -0
- package/wizard/src/features/form-runtime/hooks/useComponentTriggers.js +102 -0
- package/wizard/src/features/form-runtime/hooks/useComponentVisibility.js +18 -0
- package/wizard/src/features/form-runtime/hooks/useFieldEventHandlers.js +61 -0
- package/wizard/src/features/form-runtime/hooks/useFormContext.js +13 -0
- package/wizard/src/features/form-runtime/hooks/useFormFieldState.js +40 -0
- package/wizard/src/features/form-runtime/hooks/useValidationEvents.js +39 -0
- package/wizard/src/features/form-runtime/utils/componentDisplayValue.js +22 -0
- package/wizard/src/features/form-runtime/utils/errorUtils.js +93 -0
- package/wizard/src/features/form-runtime/utils/fieldHelpers.js +17 -0
- package/wizard/src/features/form-runtime/utils/formDataBuilder.js +10 -0
- package/wizard/src/features/form-runtime/utils/formDirtyStateSync.js +52 -0
- package/wizard/src/features/form-runtime/utils/logger.js +111 -0
- package/wizard/src/features/form-runtime/utils/validation.js +100 -0
- package/wizard/src/features/form-runtime/utils/validationUX.js +58 -0
- package/wizard/src/features/form-runtime/utils/visibilityUtils.js +77 -0
- package/wizard/src/features/state-management/machines/actions/componentActions.js +215 -0
- package/wizard/src/features/state-management/machines/actions/navigationActions.js +122 -0
- package/wizard/src/features/state-management/machines/actions/saveActions.js +101 -0
- package/wizard/src/features/state-management/machines/componentTriggerEngine.js +598 -0
- package/wizard/src/features/state-management/machines/formMachine.js +1565 -0
- package/wizard/src/features/state-management/machines/guards/navigationGuards.js +59 -0
- package/wizard/src/features/state-management/machines/guards/saveGuards.js +21 -0
- package/wizard/src/features/state-management/machines/guards/triggerGuards.js +11 -0
- package/wizard/src/features/state-management/machines/helpers/triggerHelpers.js +12 -0
- package/wizard/src/features/state-management/machines/performance.js +56 -0
- package/wizard/src/features/state-management/machines/useFormMachine.js +412 -0
- package/wizard/src/features/trigger-action-system/components/ActionLoadingIndicator/ActionLoadingIndicator.js +46 -0
- package/wizard/src/features/trigger-action-system/components/ActionLoadingIndicator/ActionLoadingIndicator.module.css.js +30 -0
- package/wizard/src/features/trigger-action-system/components/ActionManager.js +108 -0
- package/wizard/src/features/trigger-action-system/components/ComponentAlert/ComponentAlert.js +10 -0
- package/wizard/src/features/trigger-action-system/components/ComponentAlert/ComponentAlert.module.css.js +8 -0
- package/wizard/src/features/trigger-action-system/utils/GenericTriggerEngine.js +376 -0
- package/wizard/src/features/validation-system/components/ValidationDebugger.js +69 -0
- package/wizard/src/features/validation-system/validation/ActionValidation.js +234 -0
- package/wizard/src/features/validation-system/validation/SchemaBuilder.js +239 -0
- package/wizard/src/features/validation-system/validation/ValidationCache.js +76 -0
- package/wizard/src/features/validation-system/validation/ValidationEngine.js +97 -0
- package/wizard/src/features/validation-system/validation/ValidationExecutor.js +138 -0
- package/wizard/src/features/validation-system/validation/tanstackSchemaAdapter.js +17 -0
- package/wizard/src/features/validation-system/validation/validationService.js +74 -0
- package/wizard/src/renderer/wizardRenderer.js +123 -0
- package/README.md +0 -147
|
@@ -0,0 +1,234 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
/* empty css */
|
|
3
|
+
import { isTemplateDialogConfig as p } from "../../../../../ui/src/lib/types/guards.js";
|
|
4
|
+
import { resolveTemplateDialog as d } from "../../../../../ui/src/lib/utils/templateDialogResolver.js";
|
|
5
|
+
class m extends Error {
|
|
6
|
+
constructor(t, e, i, r) {
|
|
7
|
+
super(i), this.actionId = t, this.actionType = e, this.details = r, this.name = "ActionValidationError";
|
|
8
|
+
}
|
|
9
|
+
}
|
|
10
|
+
class n {
|
|
11
|
+
/**
|
|
12
|
+
* Validates a single action configuration
|
|
13
|
+
*/
|
|
14
|
+
static validateAction(t) {
|
|
15
|
+
const e = [];
|
|
16
|
+
if (t.id || e.push("Action ID is required"), t.type || e.push("Action type is required"), t.trigger || e.push("Action trigger is required"), (typeof t.order != "number" || t.order < 0) && e.push("Action order must be a non-negative number"), t.config || e.push("Action config is required"), t.config)
|
|
17
|
+
switch (t.type) {
|
|
18
|
+
case "apiCall": {
|
|
19
|
+
const i = n.validateApiCallConfig(
|
|
20
|
+
t.config
|
|
21
|
+
);
|
|
22
|
+
e.push(...i);
|
|
23
|
+
break;
|
|
24
|
+
}
|
|
25
|
+
case "showDialog": {
|
|
26
|
+
const i = n.validateDialogConfig(
|
|
27
|
+
t.config
|
|
28
|
+
);
|
|
29
|
+
e.push(...i);
|
|
30
|
+
break;
|
|
31
|
+
}
|
|
32
|
+
case "navigate": {
|
|
33
|
+
const i = n.validateNavigationConfig(
|
|
34
|
+
t.config
|
|
35
|
+
);
|
|
36
|
+
e.push(...i);
|
|
37
|
+
break;
|
|
38
|
+
}
|
|
39
|
+
default:
|
|
40
|
+
e.push(`Unknown action type: ${t.type}`);
|
|
41
|
+
}
|
|
42
|
+
if (t.conditions && t.conditions.length > 0)
|
|
43
|
+
for (const i of t.conditions)
|
|
44
|
+
i.field || e.push("Condition field is required"), i.operator || e.push("Condition operator is required");
|
|
45
|
+
return {
|
|
46
|
+
isValid: e.length === 0,
|
|
47
|
+
errors: e
|
|
48
|
+
};
|
|
49
|
+
}
|
|
50
|
+
/**
|
|
51
|
+
* Validates API call configuration
|
|
52
|
+
*/
|
|
53
|
+
static validateApiCallConfig(t) {
|
|
54
|
+
const e = [];
|
|
55
|
+
if (t.method ? ["GET", "POST", "PUT", "DELETE"].includes(t.method) || e.push("Invalid HTTP method") : e.push("HTTP method is required"), !t.url)
|
|
56
|
+
e.push("URL is required");
|
|
57
|
+
else
|
|
58
|
+
try {
|
|
59
|
+
!t.url.startsWith("/") && !t.url.startsWith("http") && e.push("URL must be a valid path or full URL");
|
|
60
|
+
} catch {
|
|
61
|
+
e.push("Invalid URL format");
|
|
62
|
+
}
|
|
63
|
+
if (t.timeout && (t.timeout < 1e3 || t.timeout > 6e4) && e.push("Timeout must be between 1000ms and 60000ms"), t.retryCount && (t.retryCount < 0 || t.retryCount > 5) && e.push("Retry count must be between 0 and 5"), t.fieldMappings)
|
|
64
|
+
for (const [i, r] of Object.entries(
|
|
65
|
+
t.fieldMappings
|
|
66
|
+
))
|
|
67
|
+
(!i || typeof i != "string") && e.push("Field mapping form field must be a non-empty string"), (!r || typeof r != "string") && e.push("Field mapping API field must be a non-empty string");
|
|
68
|
+
return e;
|
|
69
|
+
}
|
|
70
|
+
/**
|
|
71
|
+
* Validates dialog configuration - supports both direct and template-based configs
|
|
72
|
+
*/
|
|
73
|
+
static validateDialogConfig(t) {
|
|
74
|
+
const e = [];
|
|
75
|
+
if (p(t))
|
|
76
|
+
return n.validateTemplateDialogConfig(t);
|
|
77
|
+
const i = t;
|
|
78
|
+
if (i.title || e.push("Dialog title is required"), i.content || e.push("Dialog content is required"), i.type ? ["modal", "toast", "sidebar"].includes(i.type) || e.push("Invalid dialog type") : e.push("Dialog type is required"), !i.buttons || i.buttons.length === 0)
|
|
79
|
+
e.push("At least one dialog button is required");
|
|
80
|
+
else
|
|
81
|
+
for (const [r, o] of i.buttons.entries())
|
|
82
|
+
if (o.label || e.push(`Button ${r + 1} label is required`), o.variant ? ["primary", "secondary", "danger"].includes(o.variant) || e.push(`Button ${r + 1} has invalid variant`) : e.push(`Button ${r + 1} variant is required`), !o.action)
|
|
83
|
+
e.push(`Button ${r + 1} action is required`);
|
|
84
|
+
else {
|
|
85
|
+
const s = n.validateDialogButtonAction(
|
|
86
|
+
o.action,
|
|
87
|
+
r + 1
|
|
88
|
+
);
|
|
89
|
+
e.push(...s);
|
|
90
|
+
}
|
|
91
|
+
return e;
|
|
92
|
+
}
|
|
93
|
+
/**
|
|
94
|
+
* Validates template-based dialog configuration
|
|
95
|
+
*/
|
|
96
|
+
static validateTemplateDialogConfig(t) {
|
|
97
|
+
const e = [];
|
|
98
|
+
if (!t.template)
|
|
99
|
+
return e.push("Template configuration is required"), e;
|
|
100
|
+
if ((!t.template.typeId || t.template.typeId.trim() === "") && e.push("Template typeId is required"), (!t.template.config || typeof t.template.config != "object") && e.push("Template config is required and must be an object"), e.length > 0)
|
|
101
|
+
return e;
|
|
102
|
+
try {
|
|
103
|
+
const i = d(t);
|
|
104
|
+
return n.validateResolvedDialogConfig(i);
|
|
105
|
+
} catch (i) {
|
|
106
|
+
e.push(
|
|
107
|
+
`Failed to resolve template dialog: ${i.message}`
|
|
108
|
+
);
|
|
109
|
+
}
|
|
110
|
+
return e;
|
|
111
|
+
}
|
|
112
|
+
/**
|
|
113
|
+
* Validates resolved dialog configuration (after template resolution)
|
|
114
|
+
*/
|
|
115
|
+
static validateResolvedDialogConfig(t) {
|
|
116
|
+
const e = [];
|
|
117
|
+
if (t.title || e.push("Resolved dialog title is required"), t.content || e.push("Resolved dialog content is required"), t.type ? ["modal", "toast", "sidebar"].includes(t.type) || e.push("Invalid resolved dialog type") : e.push("Resolved dialog type is required"), !t.buttons || t.buttons.length === 0)
|
|
118
|
+
e.push("At least one resolved dialog button is required");
|
|
119
|
+
else
|
|
120
|
+
for (const [i, r] of t.buttons.entries())
|
|
121
|
+
r.label || e.push(`Resolved button ${i + 1} label is required`), r.variant ? ["primary", "secondary", "danger"].includes(r.variant) || e.push(`Resolved button ${i + 1} has invalid variant`) : e.push(`Resolved button ${i + 1} variant is required`), r.action || e.push(`Resolved button ${i + 1} action is required`);
|
|
122
|
+
return e;
|
|
123
|
+
}
|
|
124
|
+
/**
|
|
125
|
+
* Validates dialog button action
|
|
126
|
+
*/
|
|
127
|
+
static validateDialogButtonAction(t, e) {
|
|
128
|
+
const i = [];
|
|
129
|
+
if (!t.type)
|
|
130
|
+
return i.push(`Button ${e} action type is required`), i;
|
|
131
|
+
switch (t.type) {
|
|
132
|
+
case "navigate":
|
|
133
|
+
t.targetStep && typeof t.targetStep != "string" && i.push(
|
|
134
|
+
`Button ${e} navigation target step must be a string`
|
|
135
|
+
), t.direction && !["next", "previous"].includes(t.direction) && i.push(
|
|
136
|
+
`Button ${e} navigation direction must be 'next' or 'previous'`
|
|
137
|
+
);
|
|
138
|
+
break;
|
|
139
|
+
case "custom":
|
|
140
|
+
t.handler || i.push(
|
|
141
|
+
`Button ${e} custom action handler is required`
|
|
142
|
+
);
|
|
143
|
+
break;
|
|
144
|
+
case "close":
|
|
145
|
+
break;
|
|
146
|
+
default:
|
|
147
|
+
i.push(
|
|
148
|
+
`Button ${e} has unknown action type: ${t.type}`
|
|
149
|
+
);
|
|
150
|
+
}
|
|
151
|
+
return i;
|
|
152
|
+
}
|
|
153
|
+
/**
|
|
154
|
+
* Validates navigation configuration
|
|
155
|
+
*/
|
|
156
|
+
static validateNavigationConfig(t) {
|
|
157
|
+
const e = [];
|
|
158
|
+
return t.type ? ["next", "previous", "step"].includes(t.type) || e.push("Invalid navigation type") : e.push("Navigation type is required"), t.type === "step" && !t.targetStep && e.push("Target step is required for step navigation"), e;
|
|
159
|
+
}
|
|
160
|
+
/**
|
|
161
|
+
* Validates all actions in a step
|
|
162
|
+
*/
|
|
163
|
+
static validateStepActions(t) {
|
|
164
|
+
const e = [];
|
|
165
|
+
if (!t.actions || t.actions.length === 0)
|
|
166
|
+
return { isValid: !0, errors: [] };
|
|
167
|
+
const i = t.actions.map((s) => s.id), r = i.filter(
|
|
168
|
+
(s, a) => i.indexOf(s) !== a
|
|
169
|
+
);
|
|
170
|
+
r.length > 0 && e.push(`Duplicate action IDs found: ${r.join(", ")}`);
|
|
171
|
+
const o = /* @__PURE__ */ new Map();
|
|
172
|
+
for (const s of t.actions)
|
|
173
|
+
o.has(s.trigger) || o.set(s.trigger, []), o.get(s.trigger)?.push(s.order);
|
|
174
|
+
for (const [s, a] of o) {
|
|
175
|
+
const u = a.filter(
|
|
176
|
+
(l, f) => a.indexOf(l) !== f
|
|
177
|
+
);
|
|
178
|
+
u.length > 0 && e.push(
|
|
179
|
+
`Duplicate action orders for trigger '${s}': ${u.join(", ")}`
|
|
180
|
+
);
|
|
181
|
+
}
|
|
182
|
+
for (const s of t.actions) {
|
|
183
|
+
const a = n.validateAction(s);
|
|
184
|
+
a.isValid || e.push(`Action '${s.id}': ${a.errors.join(", ")}`);
|
|
185
|
+
}
|
|
186
|
+
return {
|
|
187
|
+
isValid: e.length === 0,
|
|
188
|
+
errors: e
|
|
189
|
+
};
|
|
190
|
+
}
|
|
191
|
+
/**
|
|
192
|
+
* Validates navigation targets exist
|
|
193
|
+
*/
|
|
194
|
+
static validateNavigationTargets(t, e) {
|
|
195
|
+
const i = [];
|
|
196
|
+
if (!t.actions)
|
|
197
|
+
return { isValid: !0, errors: [] };
|
|
198
|
+
const r = new Set(e.map((o) => o.id));
|
|
199
|
+
for (const o of t.actions) {
|
|
200
|
+
if (o.type === "navigate") {
|
|
201
|
+
const s = o.config;
|
|
202
|
+
s.type === "step" && s.targetStep && (r.has(s.targetStep) || i.push(
|
|
203
|
+
`Navigation action '${o.id}' references non-existent step: ${s.targetStep}`
|
|
204
|
+
));
|
|
205
|
+
}
|
|
206
|
+
if (o.type === "showDialog")
|
|
207
|
+
try {
|
|
208
|
+
const s = o.config;
|
|
209
|
+
let a;
|
|
210
|
+
if (p(s) ? a = d(s) : a = s, a.buttons) {
|
|
211
|
+
for (const u of a.buttons)
|
|
212
|
+
if (u.action.type === "navigate" && u.action.targetStep) {
|
|
213
|
+
const l = u.action.targetStep;
|
|
214
|
+
r.has(l) || i.push(
|
|
215
|
+
`Dialog button in action '${o.id}' references non-existent step: ${l}`
|
|
216
|
+
);
|
|
217
|
+
}
|
|
218
|
+
}
|
|
219
|
+
} catch (s) {
|
|
220
|
+
i.push(
|
|
221
|
+
`Failed to resolve dialog template in action '${o.id}': ${s.message}`
|
|
222
|
+
);
|
|
223
|
+
}
|
|
224
|
+
}
|
|
225
|
+
return {
|
|
226
|
+
isValid: i.length === 0,
|
|
227
|
+
errors: i
|
|
228
|
+
};
|
|
229
|
+
}
|
|
230
|
+
}
|
|
231
|
+
export {
|
|
232
|
+
m as ActionValidationError,
|
|
233
|
+
n as ActionValidator
|
|
234
|
+
};
|
|
@@ -0,0 +1,239 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { z as l } from "zod";
|
|
3
|
+
class d {
|
|
4
|
+
messageStyle;
|
|
5
|
+
secureValidatorConfig;
|
|
6
|
+
constructor(i = "withLabel", a) {
|
|
7
|
+
this.messageStyle = i, this.secureValidatorConfig = a;
|
|
8
|
+
}
|
|
9
|
+
/**
|
|
10
|
+
* Creates a Zod schema for a component
|
|
11
|
+
*/
|
|
12
|
+
createComponentSchema(i) {
|
|
13
|
+
console.log("🔍 [SchemaBuilder] Creating schema for component:", {
|
|
14
|
+
id: i.id,
|
|
15
|
+
type: i.type,
|
|
16
|
+
validation: i.validation
|
|
17
|
+
});
|
|
18
|
+
let a;
|
|
19
|
+
switch (i.type) {
|
|
20
|
+
case "text":
|
|
21
|
+
case "tel":
|
|
22
|
+
case "password":
|
|
23
|
+
case "textarea":
|
|
24
|
+
a = l.string();
|
|
25
|
+
break;
|
|
26
|
+
case "email":
|
|
27
|
+
console.log(
|
|
28
|
+
`🔍 [SchemaBuilder] Creating EMAIL schema for component ${i.id}`
|
|
29
|
+
), a = l.string().email("Please enter a valid email address"), console.log(
|
|
30
|
+
`✅ [SchemaBuilder] Email schema created for component ${i.id}:`,
|
|
31
|
+
{ schemaType: a.constructor.name }
|
|
32
|
+
);
|
|
33
|
+
break;
|
|
34
|
+
case "number":
|
|
35
|
+
a = l.number();
|
|
36
|
+
break;
|
|
37
|
+
case "checkbox":
|
|
38
|
+
a = l.boolean();
|
|
39
|
+
break;
|
|
40
|
+
case "date":
|
|
41
|
+
case "time":
|
|
42
|
+
case "datetime-local":
|
|
43
|
+
a = l.string();
|
|
44
|
+
break;
|
|
45
|
+
case "radioGroup":
|
|
46
|
+
case "radio":
|
|
47
|
+
case "select":
|
|
48
|
+
case "dropdown":
|
|
49
|
+
a = l.string();
|
|
50
|
+
break;
|
|
51
|
+
case "range":
|
|
52
|
+
a = l.number();
|
|
53
|
+
break;
|
|
54
|
+
case "file":
|
|
55
|
+
a = l.any();
|
|
56
|
+
break;
|
|
57
|
+
case "hidden":
|
|
58
|
+
a = l.string().optional();
|
|
59
|
+
break;
|
|
60
|
+
default:
|
|
61
|
+
a = l.any();
|
|
62
|
+
}
|
|
63
|
+
if (i.validation) {
|
|
64
|
+
const e = i.validation, r = typeof e.required == "object" && e.required !== null ? e.required : null;
|
|
65
|
+
if (r && r.value === !0) {
|
|
66
|
+
const t = r.message || "This field is required";
|
|
67
|
+
console.log(
|
|
68
|
+
`🔍 [SchemaBuilder] Applying REQUIRED validation for ${i.id}:`,
|
|
69
|
+
{
|
|
70
|
+
message: t,
|
|
71
|
+
componentType: i.type,
|
|
72
|
+
requiredRule: r
|
|
73
|
+
}
|
|
74
|
+
), i.type === "text" || i.type === "email" || i.type === "tel" || i.type === "password" || i.type === "textarea" ? (a = a.min(1, t), console.log(
|
|
75
|
+
`🔍 [SchemaBuilder] Applied .min(1) for required text field ${i.id}`
|
|
76
|
+
)) : (i.type === "radioGroup" || i.type === "radio" || i.type === "select" || i.type === "dropdown") && (a = a.refine(
|
|
77
|
+
(s) => s != null && s !== "",
|
|
78
|
+
{
|
|
79
|
+
message: t
|
|
80
|
+
}
|
|
81
|
+
), console.log(
|
|
82
|
+
`🔍 [SchemaBuilder] Applied .refine() for required selection field ${i.id}`
|
|
83
|
+
));
|
|
84
|
+
}
|
|
85
|
+
if (e.minLength) {
|
|
86
|
+
console.log(
|
|
87
|
+
`🔍 [SchemaBuilder] Processing MINLENGTH validation for ${i.id}:`,
|
|
88
|
+
{
|
|
89
|
+
validationMinLength: e.minLength,
|
|
90
|
+
rawValue: e.minLength.value,
|
|
91
|
+
valueType: typeof e.minLength.value
|
|
92
|
+
}
|
|
93
|
+
);
|
|
94
|
+
const t = typeof e.minLength.value == "string" ? Number(e.minLength.value) : e.minLength.value;
|
|
95
|
+
if (console.log(
|
|
96
|
+
`🔍 [SchemaBuilder] Converted minLength value for ${i.id}:`,
|
|
97
|
+
{
|
|
98
|
+
originalValue: e.minLength.value,
|
|
99
|
+
convertedValue: t,
|
|
100
|
+
convertedType: typeof t,
|
|
101
|
+
isValidNumber: typeof t == "number" && !Number.isNaN(t)
|
|
102
|
+
}
|
|
103
|
+
), typeof t == "number" && !Number.isNaN(t)) {
|
|
104
|
+
if (a instanceof l.ZodString) {
|
|
105
|
+
const s = e.minLength.message || `Must be at least ${t} characters`;
|
|
106
|
+
console.log(
|
|
107
|
+
`🔍 [SchemaBuilder] Applying MINLENGTH validation for ${i.id}:`,
|
|
108
|
+
{
|
|
109
|
+
minLengthValue: t,
|
|
110
|
+
message: s,
|
|
111
|
+
schemaBeforeMinLength: a._def,
|
|
112
|
+
schemaType: a.constructor.name
|
|
113
|
+
}
|
|
114
|
+
), a = a.min(t, s), console.log(
|
|
115
|
+
`🔍 [SchemaBuilder] Applied .min(${t}) for ${i.id}:`,
|
|
116
|
+
{
|
|
117
|
+
schemaAfterMinLength: a._def,
|
|
118
|
+
schemaType: a.constructor.name
|
|
119
|
+
}
|
|
120
|
+
);
|
|
121
|
+
}
|
|
122
|
+
} else
|
|
123
|
+
console.warn(
|
|
124
|
+
`[SchemaBuilder] Invalid minLength value for component: ${i.id}. Expected number, got:`,
|
|
125
|
+
e.minLength.value
|
|
126
|
+
);
|
|
127
|
+
}
|
|
128
|
+
if (e.maxLength) {
|
|
129
|
+
const t = typeof e.maxLength.value == "string" ? Number(e.maxLength.value) : e.maxLength.value;
|
|
130
|
+
if (typeof t == "number" && !Number.isNaN(t)) {
|
|
131
|
+
if (a instanceof l.ZodString) {
|
|
132
|
+
const s = e.maxLength.message || `Must be no more than ${t} characters`;
|
|
133
|
+
a = a.max(t, s);
|
|
134
|
+
}
|
|
135
|
+
} else
|
|
136
|
+
console.warn(
|
|
137
|
+
`[SchemaBuilder] Invalid maxLength value for component: ${i.id}. Expected number, got:`,
|
|
138
|
+
e.maxLength.value
|
|
139
|
+
);
|
|
140
|
+
}
|
|
141
|
+
if (e.pattern && a instanceof l.ZodString) {
|
|
142
|
+
const t = typeof e.pattern == "string" ? { value: e.pattern, message: "Invalid format" } : e.pattern;
|
|
143
|
+
if (t.value) {
|
|
144
|
+
const s = t.message || "Invalid format";
|
|
145
|
+
a = a.regex(new RegExp(t.value), s);
|
|
146
|
+
}
|
|
147
|
+
}
|
|
148
|
+
if (e.email && i.type !== "email" && a instanceof l.ZodString) {
|
|
149
|
+
const t = typeof e.email == "boolean" && e.email ? { value: !0, message: "Please enter a valid email address" } : typeof e.email == "object" && e.email !== null ? e.email : null;
|
|
150
|
+
if (t && (t.value === !0 || typeof e.email == "object" && e.email !== null && !("value" in e.email))) {
|
|
151
|
+
const n = t?.message || "Please enter a valid email address";
|
|
152
|
+
a = a.email(n);
|
|
153
|
+
}
|
|
154
|
+
}
|
|
155
|
+
if (e.email && i.type === "email" && a instanceof l.ZodString) {
|
|
156
|
+
const t = typeof e.email == "boolean" && e.email ? { message: "Please enter a valid email address" } : typeof e.email == "object" && e.email !== null ? e.email : null;
|
|
157
|
+
t && t.message && (console.log(
|
|
158
|
+
`🔍 [SchemaBuilder] Using custom email validation message for component ${i.id}:`,
|
|
159
|
+
{ customMessage: t.message }
|
|
160
|
+
), a = l.string().email(t.message));
|
|
161
|
+
}
|
|
162
|
+
if (i.type === "number" || i.type === "range") {
|
|
163
|
+
if (e.min) {
|
|
164
|
+
const t = typeof e.min == "number" ? {
|
|
165
|
+
value: e.min,
|
|
166
|
+
message: `Must be at least ${e.min}`
|
|
167
|
+
} : e.min, s = typeof t.value == "string" ? Number(t.value) : t.value;
|
|
168
|
+
if (typeof s == "number" && !Number.isNaN(s)) {
|
|
169
|
+
const n = t.message || `Must be at least ${s}`;
|
|
170
|
+
a = a.min(s, n);
|
|
171
|
+
} else
|
|
172
|
+
console.warn(
|
|
173
|
+
`[SchemaBuilder] Invalid min value for component: ${i.id}. Expected number, got:`,
|
|
174
|
+
t.value
|
|
175
|
+
);
|
|
176
|
+
}
|
|
177
|
+
if (e.max) {
|
|
178
|
+
const t = typeof e.max == "number" ? {
|
|
179
|
+
value: e.max,
|
|
180
|
+
message: `Must be no more than ${e.max}`
|
|
181
|
+
} : e.max, s = typeof t.value == "string" ? Number(t.value) : t.value;
|
|
182
|
+
if (typeof s == "number" && !Number.isNaN(s)) {
|
|
183
|
+
const n = t.message || `Must be no more than ${s}`;
|
|
184
|
+
a = a.max(s, n);
|
|
185
|
+
} else
|
|
186
|
+
console.warn(
|
|
187
|
+
`[SchemaBuilder] Invalid max value for component: ${i.id}. Expected number, got:`,
|
|
188
|
+
t.value
|
|
189
|
+
);
|
|
190
|
+
}
|
|
191
|
+
}
|
|
192
|
+
}
|
|
193
|
+
return this.isComponentRequired(i) || (a = a.optional()), a;
|
|
194
|
+
}
|
|
195
|
+
/**
|
|
196
|
+
* Creates a Zod schema for a step
|
|
197
|
+
*/
|
|
198
|
+
createStepSchema(i) {
|
|
199
|
+
const a = {};
|
|
200
|
+
return i.sections?.forEach((o) => {
|
|
201
|
+
o.components?.forEach((e) => {
|
|
202
|
+
if (e.type === "button" || e.type === "submit" || e.type === "reset" || e.type === "paragraph" || e.type === "heading" || e.type === "alert")
|
|
203
|
+
return;
|
|
204
|
+
const r = this.createComponentSchema(e);
|
|
205
|
+
a[e.id] = r;
|
|
206
|
+
});
|
|
207
|
+
}), l.object(a);
|
|
208
|
+
}
|
|
209
|
+
/**
|
|
210
|
+
* Updates the message style
|
|
211
|
+
*/
|
|
212
|
+
updateMessageStyle(i) {
|
|
213
|
+
this.messageStyle = i;
|
|
214
|
+
}
|
|
215
|
+
/**
|
|
216
|
+
* Updates the secure validator config
|
|
217
|
+
*/
|
|
218
|
+
updateSecureValidatorConfig(i) {
|
|
219
|
+
this.secureValidatorConfig = { ...this.secureValidatorConfig, ...i };
|
|
220
|
+
}
|
|
221
|
+
/**
|
|
222
|
+
* Gets the current message style
|
|
223
|
+
*/
|
|
224
|
+
getMessageStyle() {
|
|
225
|
+
return this.messageStyle;
|
|
226
|
+
}
|
|
227
|
+
/**
|
|
228
|
+
* Checks if a component is required based on its validation configuration
|
|
229
|
+
*/
|
|
230
|
+
isComponentRequired(i) {
|
|
231
|
+
if (!i.validation)
|
|
232
|
+
return !1;
|
|
233
|
+
const a = i.validation;
|
|
234
|
+
return typeof a.required == "boolean" ? a.required : typeof a.required == "object" && a.required !== null ? a.required.value === !0 : !1;
|
|
235
|
+
}
|
|
236
|
+
}
|
|
237
|
+
export {
|
|
238
|
+
d as SchemaBuilder
|
|
239
|
+
};
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
class s {
|
|
3
|
+
schemaBuilder;
|
|
4
|
+
componentSchemaCache = /* @__PURE__ */ new Map();
|
|
5
|
+
stepSchemaCache = /* @__PURE__ */ new Map();
|
|
6
|
+
constructor(e) {
|
|
7
|
+
this.schemaBuilder = e;
|
|
8
|
+
}
|
|
9
|
+
/**
|
|
10
|
+
* Gets or creates a component schema with caching
|
|
11
|
+
*/
|
|
12
|
+
getComponentSchema(e) {
|
|
13
|
+
const c = `component_${e.id}`;
|
|
14
|
+
(e.id === "text-i05t2ttw" || e.id === "radioGroup-c5q6aj4v" || e.id === "text-1759502191578-gci6gq1pm") && (console.log(
|
|
15
|
+
`🧪 [ValidationCache] CLEARING CACHE for debugging component: ${e.id}`
|
|
16
|
+
), this.componentSchemaCache.delete(c));
|
|
17
|
+
const a = this.componentSchemaCache.get(c);
|
|
18
|
+
if (a)
|
|
19
|
+
return console.log(
|
|
20
|
+
`📋 [ValidationCache] Using cached schema for ${e.id}:`,
|
|
21
|
+
{
|
|
22
|
+
cacheKey: c,
|
|
23
|
+
schemaType: a.constructor.name
|
|
24
|
+
}
|
|
25
|
+
), a;
|
|
26
|
+
console.log(
|
|
27
|
+
`🔄 [ValidationCache] Creating new schema for ${e.id}:`,
|
|
28
|
+
{
|
|
29
|
+
cacheKey: c,
|
|
30
|
+
componentType: e.type,
|
|
31
|
+
hasValidation: !!e.validation
|
|
32
|
+
}
|
|
33
|
+
);
|
|
34
|
+
const t = this.schemaBuilder.createComponentSchema(e);
|
|
35
|
+
return this.componentSchemaCache.set(c, t), t;
|
|
36
|
+
}
|
|
37
|
+
/**
|
|
38
|
+
* Gets or creates a step schema with caching
|
|
39
|
+
*/
|
|
40
|
+
getStepSchema(e) {
|
|
41
|
+
const c = `step_${e.id}`, a = this.stepSchemaCache.get(c);
|
|
42
|
+
if (a)
|
|
43
|
+
return a;
|
|
44
|
+
const t = this.schemaBuilder.createStepSchema(e);
|
|
45
|
+
return this.stepSchemaCache.set(c, t), t;
|
|
46
|
+
}
|
|
47
|
+
/**
|
|
48
|
+
* Clears all cached schemas
|
|
49
|
+
*/
|
|
50
|
+
clearCache() {
|
|
51
|
+
this.componentSchemaCache.clear(), this.stepSchemaCache.clear();
|
|
52
|
+
}
|
|
53
|
+
/**
|
|
54
|
+
* Invalidates cache when message style changes
|
|
55
|
+
*/
|
|
56
|
+
invalidateOnMessageStyleChange() {
|
|
57
|
+
this.clearCache();
|
|
58
|
+
}
|
|
59
|
+
/**
|
|
60
|
+
* Clears cache for a specific component
|
|
61
|
+
*/
|
|
62
|
+
clearComponentCache(e) {
|
|
63
|
+
const c = `component_${e}`;
|
|
64
|
+
this.componentSchemaCache.delete(c);
|
|
65
|
+
}
|
|
66
|
+
/**
|
|
67
|
+
* Clears cache for a specific step
|
|
68
|
+
*/
|
|
69
|
+
clearStepCache(e) {
|
|
70
|
+
const c = `step_${e}`;
|
|
71
|
+
this.stepSchemaCache.delete(c);
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
export {
|
|
75
|
+
s as ValidationCache
|
|
76
|
+
};
|
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { SchemaBuilder as d } from "./SchemaBuilder.js";
|
|
3
|
+
import { ValidationCache as o } from "./ValidationCache.js";
|
|
4
|
+
import { ValidationExecutor as l } from "./ValidationExecutor.js";
|
|
5
|
+
class c {
|
|
6
|
+
debounceTimers = /* @__PURE__ */ new Map();
|
|
7
|
+
debounceMs;
|
|
8
|
+
schemaBuilder;
|
|
9
|
+
validationExecutor;
|
|
10
|
+
validationCache;
|
|
11
|
+
constructor(e = {}) {
|
|
12
|
+
this.debounceMs = e.debounceMs || 300, this.schemaBuilder = new d(
|
|
13
|
+
e.messageStyle || "withLabel",
|
|
14
|
+
e.secureValidatorConfig
|
|
15
|
+
), this.validationExecutor = new l(this.schemaBuilder), this.validationCache = new o(this.schemaBuilder);
|
|
16
|
+
}
|
|
17
|
+
/**
|
|
18
|
+
* Validates a single field with debouncing
|
|
19
|
+
*/
|
|
20
|
+
async validateFieldDebounced(e, i) {
|
|
21
|
+
return new Promise((a) => {
|
|
22
|
+
const t = `field_${e.id}`;
|
|
23
|
+
if (this.debounceTimers.has(t)) {
|
|
24
|
+
const n = this.debounceTimers.get(t);
|
|
25
|
+
n && clearTimeout(n);
|
|
26
|
+
}
|
|
27
|
+
const r = setTimeout(() => {
|
|
28
|
+
const n = this.validateField(e, i);
|
|
29
|
+
this.debounceTimers.delete(t), a(n);
|
|
30
|
+
}, this.debounceMs);
|
|
31
|
+
this.debounceTimers.set(t, r);
|
|
32
|
+
});
|
|
33
|
+
}
|
|
34
|
+
/**
|
|
35
|
+
* Validates a single field immediately (synchronous)
|
|
36
|
+
*/
|
|
37
|
+
validateField(e, i) {
|
|
38
|
+
const a = this.validationCache.getComponentSchema(e);
|
|
39
|
+
return this.validationExecutor.validateFieldSync(i, a);
|
|
40
|
+
}
|
|
41
|
+
/**
|
|
42
|
+
* Validates all fields in a step
|
|
43
|
+
*/
|
|
44
|
+
async validateStep(e, i) {
|
|
45
|
+
const a = this.validationCache.getStepSchema(e);
|
|
46
|
+
return await this.validationExecutor.validateStep(i, a);
|
|
47
|
+
}
|
|
48
|
+
/**
|
|
49
|
+
* Validates an entire form
|
|
50
|
+
*/
|
|
51
|
+
async validateForm(e, i) {
|
|
52
|
+
return await this.validationExecutor.validateForm(e, i);
|
|
53
|
+
}
|
|
54
|
+
/**
|
|
55
|
+
* Creates and caches a Zod schema for a component
|
|
56
|
+
*/
|
|
57
|
+
getComponentSchema(e) {
|
|
58
|
+
return this.validationCache.getComponentSchema(e);
|
|
59
|
+
}
|
|
60
|
+
/**
|
|
61
|
+
* Creates a Zod schema for an entire step
|
|
62
|
+
*/
|
|
63
|
+
getStepSchema(e) {
|
|
64
|
+
return this.validationCache.getStepSchema(e);
|
|
65
|
+
}
|
|
66
|
+
/**
|
|
67
|
+
* Clears the schema cache (useful when component configurations change)
|
|
68
|
+
*/
|
|
69
|
+
clearCache() {
|
|
70
|
+
this.validationCache.clearCache();
|
|
71
|
+
}
|
|
72
|
+
/**
|
|
73
|
+
* Clears debounce timers
|
|
74
|
+
*/
|
|
75
|
+
cancelPendingValidations() {
|
|
76
|
+
for (const e of Array.from(this.debounceTimers.values()))
|
|
77
|
+
clearTimeout(e);
|
|
78
|
+
this.debounceTimers.clear();
|
|
79
|
+
}
|
|
80
|
+
/**
|
|
81
|
+
* Updates validation options
|
|
82
|
+
*/
|
|
83
|
+
updateOptions(e) {
|
|
84
|
+
e.messageStyle && (this.schemaBuilder.updateMessageStyle(e.messageStyle), this.validationCache.invalidateOnMessageStyleChange()), e.debounceMs !== void 0 && (this.debounceMs = e.debounceMs), e.secureValidatorConfig && (this.schemaBuilder.updateSecureValidatorConfig(
|
|
85
|
+
e.secureValidatorConfig
|
|
86
|
+
), this.validationCache.clearCache());
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
const v = new c();
|
|
90
|
+
function g(s) {
|
|
91
|
+
return new c(s);
|
|
92
|
+
}
|
|
93
|
+
export {
|
|
94
|
+
c as ValidationEngine,
|
|
95
|
+
g as createValidationEngine,
|
|
96
|
+
v as defaultValidationEngine
|
|
97
|
+
};
|