@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,1565 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { createMachine as I, assign as a } from "xstate";
|
|
3
|
+
import { executeComponentAction as p } from "./actions/componentActions.js";
|
|
4
|
+
import { executePendingNavigation as f } from "./actions/navigationActions.js";
|
|
5
|
+
import { executeSaveActions as m } from "./actions/saveActions.js";
|
|
6
|
+
import { ComponentTriggerEngine as u } from "./componentTriggerEngine.js";
|
|
7
|
+
import { canNavigate as d, isPendingNextNavigation as S, isPendingPreviousNavigation as A, isPendingStepNavigation as T, hasSaveContextActions as E, shouldProceedWithNormalNavigation as O, hasSaveTriggersForNext as N } from "./guards/navigationGuards.js";
|
|
8
|
+
import { isSectionEditable as _, canExecuteSaveActions as C } from "./guards/saveGuards.js";
|
|
9
|
+
import { hasDirtyComponentsWithTriggers as v } from "./guards/triggerGuards.js";
|
|
10
|
+
import { findComponentTriggers as V } from "./helpers/triggerHelpers.js";
|
|
11
|
+
import { memoryUtils as h } from "./performance.js";
|
|
12
|
+
const W = I({
|
|
13
|
+
id: "formMachine",
|
|
14
|
+
types: {},
|
|
15
|
+
context: ({ input: e }) => ({
|
|
16
|
+
config: e.config || { id: "", title: "", steps: [] },
|
|
17
|
+
currentStepId: e.currentStepId || "",
|
|
18
|
+
currentStepIndex: e.currentStepIndex || 0,
|
|
19
|
+
data: e.data || {},
|
|
20
|
+
errors: e.errors || {},
|
|
21
|
+
dirtyFields: e.dirtyFields || {},
|
|
22
|
+
touchedFields: e.touchedFields || {},
|
|
23
|
+
isValid: e.isValid ?? !0,
|
|
24
|
+
isSubmitting: e.isSubmitting ?? !1,
|
|
25
|
+
fieldStates: e.fieldStates || {},
|
|
26
|
+
sectionBackups: e.sectionBackups || {},
|
|
27
|
+
activeActions: e.activeActions || {},
|
|
28
|
+
actionResults: e.actionResults || {},
|
|
29
|
+
activeDialog: e.activeDialog || null,
|
|
30
|
+
executingTrigger: e.executingTrigger || null,
|
|
31
|
+
pendingNavigation: e.pendingNavigation || null,
|
|
32
|
+
canNavigate: e.canNavigate ?? !0,
|
|
33
|
+
waitingForActions: e.waitingForActions ?? !1,
|
|
34
|
+
// Initialize field change validation state
|
|
35
|
+
fieldChangeState: e.fieldChangeState || {},
|
|
36
|
+
fieldValidationState: e.fieldValidationState || {
|
|
37
|
+
activeWarnings: [],
|
|
38
|
+
pendingVerifications: [],
|
|
39
|
+
verificationResults: {}
|
|
40
|
+
},
|
|
41
|
+
// Initialize component trigger-action system state
|
|
42
|
+
componentTriggerState: e.componentTriggerState || {},
|
|
43
|
+
activeComponentActions: e.activeComponentActions || {},
|
|
44
|
+
componentAlerts: e.componentAlerts || {},
|
|
45
|
+
// Enhanced original value tracking
|
|
46
|
+
componentOriginalValues: e.componentOriginalValues || {},
|
|
47
|
+
// New simplified state machine context
|
|
48
|
+
activeExecutionPlan: e.activeExecutionPlan || null,
|
|
49
|
+
executionResults: e.executionResults || {},
|
|
50
|
+
// Track completed context actions
|
|
51
|
+
contextActionCompletions: e.contextActionCompletions || {},
|
|
52
|
+
// Initialize enhanced save state tracking
|
|
53
|
+
saveState: e.saveState || {
|
|
54
|
+
saveInProgress: !1,
|
|
55
|
+
saveInitiator: null,
|
|
56
|
+
savingSection: null,
|
|
57
|
+
executionPlan: null,
|
|
58
|
+
pendingVerifications: [],
|
|
59
|
+
completedVerifications: [],
|
|
60
|
+
validationErrors: {},
|
|
61
|
+
saveStartTimestamp: null
|
|
62
|
+
}
|
|
63
|
+
}),
|
|
64
|
+
initial: "idle",
|
|
65
|
+
// Global events that should work in any state
|
|
66
|
+
on: {
|
|
67
|
+
EVALUATE_COMPONENT_TRIGGERS: {
|
|
68
|
+
actions: [
|
|
69
|
+
// Create execution plan for fieldChange context and execute if needed
|
|
70
|
+
({ context: e, event: t, self: n }) => {
|
|
71
|
+
if (t.type !== "EVALUATE_COMPONENT_TRIGGERS")
|
|
72
|
+
return;
|
|
73
|
+
const { componentId: i, value: o } = t, r = e.componentOriginalValues[i], s = !!(r?.isPopulated && r.value !== o);
|
|
74
|
+
console.log(
|
|
75
|
+
`🔥 [formMachine] EVALUATE_COMPONENT_TRIGGERS for ${i}:`,
|
|
76
|
+
{
|
|
77
|
+
value: o,
|
|
78
|
+
originalValue: r?.value,
|
|
79
|
+
isPopulated: r?.isPopulated,
|
|
80
|
+
isDirty: s,
|
|
81
|
+
hasAlerts: !!e.componentAlerts[i]?.length
|
|
82
|
+
}
|
|
83
|
+
), console.log(
|
|
84
|
+
`🔍 [formMachine] Checking alert dismissal condition for ${i}:`,
|
|
85
|
+
{
|
|
86
|
+
isDirty: s,
|
|
87
|
+
hasAlerts: !!e.componentAlerts[i]?.length,
|
|
88
|
+
alertsCount: e.componentAlerts[i]?.length,
|
|
89
|
+
allComponentAlerts: Object.keys(e.componentAlerts),
|
|
90
|
+
alertsForComponent: e.componentAlerts[i],
|
|
91
|
+
conditionMet: !s && e.componentAlerts[i]?.length
|
|
92
|
+
}
|
|
93
|
+
), !s && e.componentAlerts[i]?.length && (console.log(
|
|
94
|
+
`🧹 [formMachine] Clearing alerts for ${i} - field no longer dirty`
|
|
95
|
+
), console.log(
|
|
96
|
+
`🧹 [formMachine] Sending DISMISS_COMPONENT_ALERT for ${i}`,
|
|
97
|
+
{
|
|
98
|
+
alertsCount: e.componentAlerts[i]?.length,
|
|
99
|
+
currentState: "about to send"
|
|
100
|
+
}
|
|
101
|
+
), n.send({
|
|
102
|
+
type: "DISMISS_COMPONENT_ALERT",
|
|
103
|
+
componentId: i
|
|
104
|
+
}), console.log(
|
|
105
|
+
`🧹 [formMachine] DISMISS_COMPONENT_ALERT sent for ${i}`
|
|
106
|
+
));
|
|
107
|
+
const g = u.createExecutionPlan(
|
|
108
|
+
e.config,
|
|
109
|
+
"fieldChange",
|
|
110
|
+
e.currentStepIndex,
|
|
111
|
+
e
|
|
112
|
+
);
|
|
113
|
+
console.log(
|
|
114
|
+
`🎯 [formMachine] FieldChange execution plan for ${i}:`,
|
|
115
|
+
{
|
|
116
|
+
totalActions: g.totalActions,
|
|
117
|
+
executionsCount: g.executions.length,
|
|
118
|
+
executions: g.executions.map((c) => ({
|
|
119
|
+
componentId: c.componentId,
|
|
120
|
+
triggerId: c.trigger.id,
|
|
121
|
+
actionsCount: c.actions.length,
|
|
122
|
+
actions: c.actions.map((l) => ({
|
|
123
|
+
id: l.id,
|
|
124
|
+
type: l.type,
|
|
125
|
+
contexts: l.contexts
|
|
126
|
+
}))
|
|
127
|
+
}))
|
|
128
|
+
}
|
|
129
|
+
), g.totalActions > 0 && g.executions.forEach((c) => {
|
|
130
|
+
c.actions.forEach((l) => {
|
|
131
|
+
console.log(
|
|
132
|
+
`⚡ [formMachine] Executing fieldChange action ${l.id} for ${c.componentId}`
|
|
133
|
+
), n.send({
|
|
134
|
+
type: "TRIGGER_COMPONENT_ACTION",
|
|
135
|
+
componentId: c.componentId,
|
|
136
|
+
triggerId: c.trigger.id,
|
|
137
|
+
actionId: l.id,
|
|
138
|
+
eventType: "valueChange"
|
|
139
|
+
});
|
|
140
|
+
});
|
|
141
|
+
});
|
|
142
|
+
}
|
|
143
|
+
]
|
|
144
|
+
},
|
|
145
|
+
SET_COMPONENT_ORIGINAL_VALUE: {
|
|
146
|
+
actions: a({
|
|
147
|
+
componentOriginalValues: ({ context: e, event: t }) => ({
|
|
148
|
+
...e.componentOriginalValues,
|
|
149
|
+
[t.componentId]: {
|
|
150
|
+
value: t.value,
|
|
151
|
+
timestamp: Date.now(),
|
|
152
|
+
source: t.source || "initialized",
|
|
153
|
+
isPopulated: t.source !== "initialized"
|
|
154
|
+
}
|
|
155
|
+
}),
|
|
156
|
+
componentTriggerState: ({ context: e, event: t }) => {
|
|
157
|
+
const n = V(
|
|
158
|
+
e.config,
|
|
159
|
+
t.componentId
|
|
160
|
+
), i = { ...e.componentTriggerState };
|
|
161
|
+
return n.forEach((o) => {
|
|
162
|
+
const r = `${t.componentId}-${o.id}`;
|
|
163
|
+
i[r] ? i[r].originalValue === void 0 && (i[r] = {
|
|
164
|
+
...i[r],
|
|
165
|
+
originalValue: t.value
|
|
166
|
+
}) : i[r] = {
|
|
167
|
+
componentId: t.componentId,
|
|
168
|
+
triggerId: o.id,
|
|
169
|
+
isActive: !1,
|
|
170
|
+
originalValue: t.value,
|
|
171
|
+
lastEvaluated: Date.now()
|
|
172
|
+
};
|
|
173
|
+
}), i;
|
|
174
|
+
}
|
|
175
|
+
})
|
|
176
|
+
},
|
|
177
|
+
MARK_COMPONENT_AS_POPULATED: {
|
|
178
|
+
actions: a({
|
|
179
|
+
componentOriginalValues: ({
|
|
180
|
+
context: e,
|
|
181
|
+
event: t
|
|
182
|
+
}) => (console.log(
|
|
183
|
+
`🔧 [formMachine] MARK_COMPONENT_AS_POPULATED fixing original value for ${t.componentId}:`,
|
|
184
|
+
{
|
|
185
|
+
eventValue: t.value,
|
|
186
|
+
contextDataValue: e.data[t.componentId],
|
|
187
|
+
existingOriginalValue: e.componentOriginalValues[t.componentId]?.value,
|
|
188
|
+
isPopulated: e.componentOriginalValues[t.componentId]?.isPopulated
|
|
189
|
+
}
|
|
190
|
+
), {
|
|
191
|
+
...e.componentOriginalValues,
|
|
192
|
+
[t.componentId]: {
|
|
193
|
+
...e.componentOriginalValues[t.componentId],
|
|
194
|
+
value: t.value,
|
|
195
|
+
// Use event.value instead of currentValue from context.data
|
|
196
|
+
timestamp: Date.now(),
|
|
197
|
+
source: "api_populated",
|
|
198
|
+
isPopulated: !0
|
|
199
|
+
}
|
|
200
|
+
})
|
|
201
|
+
})
|
|
202
|
+
},
|
|
203
|
+
UPDATE_COMPONENT_ORIGINAL_VALUE: {
|
|
204
|
+
actions: [
|
|
205
|
+
a({
|
|
206
|
+
componentOriginalValues: ({
|
|
207
|
+
context: e,
|
|
208
|
+
event: t
|
|
209
|
+
}) => {
|
|
210
|
+
const n = e.data[t.componentId];
|
|
211
|
+
return console.log(
|
|
212
|
+
`🔄 [formMachine] UPDATE_COMPONENT_ORIGINAL_VALUE for ${t.componentId}:`,
|
|
213
|
+
{
|
|
214
|
+
componentId: t.componentId,
|
|
215
|
+
currentValue: n,
|
|
216
|
+
oldOriginalValue: e.componentOriginalValues[t.componentId]?.value,
|
|
217
|
+
willUpdateTo: n
|
|
218
|
+
}
|
|
219
|
+
), {
|
|
220
|
+
...e.componentOriginalValues,
|
|
221
|
+
[t.componentId]: {
|
|
222
|
+
...e.componentOriginalValues[t.componentId],
|
|
223
|
+
value: n,
|
|
224
|
+
// Update original value to current field value
|
|
225
|
+
timestamp: Date.now(),
|
|
226
|
+
source: "user_verified",
|
|
227
|
+
isPopulated: !0
|
|
228
|
+
}
|
|
229
|
+
};
|
|
230
|
+
}
|
|
231
|
+
}),
|
|
232
|
+
// Re-evaluate triggers after updating original value to clear alerts
|
|
233
|
+
({ context: e, event: t, self: n }) => {
|
|
234
|
+
console.log(
|
|
235
|
+
`🔄 [formMachine] Re-evaluating triggers after UPDATE_COMPONENT_ORIGINAL_VALUE for ${t.componentId}`
|
|
236
|
+
), n.send({
|
|
237
|
+
type: "EVALUATE_COMPONENT_TRIGGERS",
|
|
238
|
+
componentId: t.componentId,
|
|
239
|
+
value: e.data[t.componentId],
|
|
240
|
+
eventType: "valueChange"
|
|
241
|
+
});
|
|
242
|
+
}
|
|
243
|
+
]
|
|
244
|
+
}
|
|
245
|
+
},
|
|
246
|
+
states: {
|
|
247
|
+
idle: {
|
|
248
|
+
on: {
|
|
249
|
+
SET_DATA: {
|
|
250
|
+
actions: a({
|
|
251
|
+
data: ({ context: e, event: t }) => e.data[t.key] === t.value ? e.data : Object.assign({}, e.data, {
|
|
252
|
+
[t.key]: t.value
|
|
253
|
+
}),
|
|
254
|
+
dirtyFields: ({ context: e, event: t }) => e.dirtyFields[t.key] ? e.dirtyFields : Object.assign({}, e.dirtyFields, {
|
|
255
|
+
[t.key]: !0
|
|
256
|
+
})
|
|
257
|
+
})
|
|
258
|
+
},
|
|
259
|
+
SET_FIELD_STATE: {
|
|
260
|
+
actions: a({
|
|
261
|
+
fieldStates: ({ context: e, event: t }) => {
|
|
262
|
+
const n = e.fieldStates[t.componentId] || {
|
|
263
|
+
value: void 0,
|
|
264
|
+
error: null,
|
|
265
|
+
isDirty: !1,
|
|
266
|
+
isTouched: !1,
|
|
267
|
+
isValidating: !1
|
|
268
|
+
};
|
|
269
|
+
let i = !1;
|
|
270
|
+
for (const r in t.state) {
|
|
271
|
+
const s = r;
|
|
272
|
+
if (n[s] !== t.state[s]) {
|
|
273
|
+
i = !0;
|
|
274
|
+
break;
|
|
275
|
+
}
|
|
276
|
+
}
|
|
277
|
+
if (!i)
|
|
278
|
+
return e.fieldStates;
|
|
279
|
+
const o = Object.assign({}, e.fieldStates);
|
|
280
|
+
return o[t.componentId] = Object.assign(
|
|
281
|
+
{},
|
|
282
|
+
n,
|
|
283
|
+
t.state
|
|
284
|
+
), o;
|
|
285
|
+
}
|
|
286
|
+
})
|
|
287
|
+
},
|
|
288
|
+
VALIDATE_FIELD: {
|
|
289
|
+
actions: [
|
|
290
|
+
a({
|
|
291
|
+
touchedFields: ({ context: e, event: t }) => e.touchedFields[t.componentId] ? e.touchedFields : Object.assign({}, e.touchedFields, {
|
|
292
|
+
[t.componentId]: !0
|
|
293
|
+
})
|
|
294
|
+
})
|
|
295
|
+
]
|
|
296
|
+
},
|
|
297
|
+
VALIDATE_SECTION: {
|
|
298
|
+
actions: []
|
|
299
|
+
},
|
|
300
|
+
VALIDATE_STEP: {
|
|
301
|
+
actions: []
|
|
302
|
+
},
|
|
303
|
+
VALIDATE_FORM: {
|
|
304
|
+
actions: []
|
|
305
|
+
},
|
|
306
|
+
START_SECTION_EDIT: {
|
|
307
|
+
actions: a({
|
|
308
|
+
sectionBackups: ({ context: e, event: t }) => {
|
|
309
|
+
if (e.sectionBackups[t.sectionId])
|
|
310
|
+
return e.sectionBackups;
|
|
311
|
+
const n = {};
|
|
312
|
+
for (const i of t.componentIds)
|
|
313
|
+
n[i] = e.data[i];
|
|
314
|
+
return Object.assign({}, e.sectionBackups, {
|
|
315
|
+
[t.sectionId]: n
|
|
316
|
+
});
|
|
317
|
+
}
|
|
318
|
+
})
|
|
319
|
+
},
|
|
320
|
+
CANCEL_SECTION_EDIT: {
|
|
321
|
+
actions: a({
|
|
322
|
+
data: ({ context: e, event: t }) => {
|
|
323
|
+
const n = e.sectionBackups[t.sectionId];
|
|
324
|
+
if (!n) return e.data;
|
|
325
|
+
let i = !1;
|
|
326
|
+
for (const [r, s] of Object.entries(n))
|
|
327
|
+
if (e.data[r] !== s) {
|
|
328
|
+
i = !0;
|
|
329
|
+
break;
|
|
330
|
+
}
|
|
331
|
+
if (!i)
|
|
332
|
+
return e.data;
|
|
333
|
+
const o = Object.assign({}, e.data);
|
|
334
|
+
for (const [r, s] of Object.entries(n))
|
|
335
|
+
o[r] = s;
|
|
336
|
+
return o;
|
|
337
|
+
},
|
|
338
|
+
// Clear the backup after restoring
|
|
339
|
+
sectionBackups: ({ context: e, event: t }) => {
|
|
340
|
+
if (!e.sectionBackups[t.sectionId])
|
|
341
|
+
return e.sectionBackups;
|
|
342
|
+
const n = Object.assign({}, e.sectionBackups);
|
|
343
|
+
return delete n[t.sectionId], n;
|
|
344
|
+
}
|
|
345
|
+
})
|
|
346
|
+
},
|
|
347
|
+
REQUEST_NAVIGATION: {
|
|
348
|
+
target: "evaluatingNavigation",
|
|
349
|
+
actions: [
|
|
350
|
+
a({
|
|
351
|
+
pendingNavigation: ({ event: e }) => {
|
|
352
|
+
if (e.type !== "REQUEST_NAVIGATION") return null;
|
|
353
|
+
const t = {
|
|
354
|
+
type: e.navigationType
|
|
355
|
+
};
|
|
356
|
+
return e.stepId !== void 0 && (t.stepId = e.stepId), t;
|
|
357
|
+
}
|
|
358
|
+
})
|
|
359
|
+
]
|
|
360
|
+
},
|
|
361
|
+
NEXT: [
|
|
362
|
+
{
|
|
363
|
+
guard: N,
|
|
364
|
+
target: "evaluatingNavigation",
|
|
365
|
+
actions: [
|
|
366
|
+
a({
|
|
367
|
+
activeExecutionPlan: ({ context: e }) => u.createExecutionPlan(
|
|
368
|
+
e.config,
|
|
369
|
+
"save",
|
|
370
|
+
e.currentStepIndex,
|
|
371
|
+
e
|
|
372
|
+
)
|
|
373
|
+
}),
|
|
374
|
+
a({
|
|
375
|
+
pendingNavigation: { type: "next" }
|
|
376
|
+
}),
|
|
377
|
+
a({
|
|
378
|
+
pendingNavigation: null,
|
|
379
|
+
canNavigate: !1
|
|
380
|
+
})
|
|
381
|
+
]
|
|
382
|
+
},
|
|
383
|
+
{
|
|
384
|
+
// Direct navigation if no triggers need execution
|
|
385
|
+
guard: d,
|
|
386
|
+
actions: a({
|
|
387
|
+
currentStepIndex: ({ context: e }) => Math.min(
|
|
388
|
+
e.currentStepIndex + 1,
|
|
389
|
+
e.config.steps.length - 1
|
|
390
|
+
),
|
|
391
|
+
currentStepId: ({ context: e }) => {
|
|
392
|
+
const t = Math.min(
|
|
393
|
+
e.currentStepIndex + 1,
|
|
394
|
+
e.config.steps.length - 1
|
|
395
|
+
);
|
|
396
|
+
return e.config.steps[t]?.id || "";
|
|
397
|
+
},
|
|
398
|
+
pendingNavigation: null
|
|
399
|
+
})
|
|
400
|
+
},
|
|
401
|
+
{
|
|
402
|
+
// Fallback - set pending navigation and transition to evaluation state
|
|
403
|
+
target: "evaluatingNavigation",
|
|
404
|
+
actions: a({
|
|
405
|
+
pendingNavigation: { type: "next" }
|
|
406
|
+
})
|
|
407
|
+
}
|
|
408
|
+
],
|
|
409
|
+
PREVIOUS: [
|
|
410
|
+
{
|
|
411
|
+
guard: d,
|
|
412
|
+
actions: a({
|
|
413
|
+
currentStepIndex: ({ context: e }) => Math.max(e.currentStepIndex - 1, 0),
|
|
414
|
+
currentStepId: ({ context: e }) => {
|
|
415
|
+
const t = Math.max(e.currentStepIndex - 1, 0);
|
|
416
|
+
return e.config.steps[t]?.id || "";
|
|
417
|
+
},
|
|
418
|
+
pendingNavigation: null
|
|
419
|
+
})
|
|
420
|
+
},
|
|
421
|
+
{
|
|
422
|
+
// Fallback - set pending navigation and transition to evaluation state
|
|
423
|
+
target: "evaluatingNavigation",
|
|
424
|
+
actions: a({
|
|
425
|
+
pendingNavigation: { type: "previous" }
|
|
426
|
+
})
|
|
427
|
+
}
|
|
428
|
+
],
|
|
429
|
+
GO_TO_STEP: [
|
|
430
|
+
{
|
|
431
|
+
guard: d,
|
|
432
|
+
actions: a({
|
|
433
|
+
currentStepIndex: ({ context: e, event: t }) => {
|
|
434
|
+
if (t.type !== "GO_TO_STEP")
|
|
435
|
+
return e.currentStepIndex;
|
|
436
|
+
const n = e.config.steps.findIndex(
|
|
437
|
+
(i) => i.id === t.stepId
|
|
438
|
+
);
|
|
439
|
+
return n >= 0 ? n : e.currentStepIndex;
|
|
440
|
+
},
|
|
441
|
+
currentStepId: ({ context: e, event: t }) => t.type !== "GO_TO_STEP" ? e.currentStepId : t.stepId,
|
|
442
|
+
pendingNavigation: null
|
|
443
|
+
})
|
|
444
|
+
},
|
|
445
|
+
{
|
|
446
|
+
// Fallback - set pending navigation and transition to evaluation state
|
|
447
|
+
target: "evaluatingNavigation",
|
|
448
|
+
actions: a({
|
|
449
|
+
pendingNavigation: ({ event: e }) => e.type !== "GO_TO_STEP" ? null : {
|
|
450
|
+
type: "step",
|
|
451
|
+
stepId: e.stepId
|
|
452
|
+
}
|
|
453
|
+
})
|
|
454
|
+
}
|
|
455
|
+
],
|
|
456
|
+
SUBMIT: {
|
|
457
|
+
target: "submitting"
|
|
458
|
+
},
|
|
459
|
+
RESET: {
|
|
460
|
+
actions: a({
|
|
461
|
+
currentStepIndex: 0,
|
|
462
|
+
currentStepId: ({ context: e }) => e.config.steps[0]?.id || "",
|
|
463
|
+
data: {},
|
|
464
|
+
errors: {},
|
|
465
|
+
dirtyFields: {},
|
|
466
|
+
touchedFields: {},
|
|
467
|
+
isValid: !0,
|
|
468
|
+
isSubmitting: !1,
|
|
469
|
+
fieldStates: {},
|
|
470
|
+
sectionBackups: {},
|
|
471
|
+
componentTriggerState: {},
|
|
472
|
+
activeComponentActions: {},
|
|
473
|
+
componentAlerts: {},
|
|
474
|
+
activeActions: {},
|
|
475
|
+
executingTrigger: null,
|
|
476
|
+
waitingForActions: !1,
|
|
477
|
+
canNavigate: !0,
|
|
478
|
+
pendingNavigation: null,
|
|
479
|
+
activeDialog: null,
|
|
480
|
+
componentOriginalValues: {},
|
|
481
|
+
fieldChangeState: {},
|
|
482
|
+
fieldValidationState: {
|
|
483
|
+
activeWarnings: [],
|
|
484
|
+
pendingVerifications: [],
|
|
485
|
+
verificationResults: {}
|
|
486
|
+
}
|
|
487
|
+
})
|
|
488
|
+
},
|
|
489
|
+
EXECUTE_TRIGGER: {
|
|
490
|
+
target: "executingActions",
|
|
491
|
+
actions: a({
|
|
492
|
+
executingTrigger: ({ event: e }) => e.trigger,
|
|
493
|
+
waitingForActions: !0,
|
|
494
|
+
canNavigate: !1
|
|
495
|
+
})
|
|
496
|
+
},
|
|
497
|
+
EXECUTE_ACTIONS: {
|
|
498
|
+
target: "executingActions",
|
|
499
|
+
actions: a({
|
|
500
|
+
executingTrigger: ({ event: e }) => e.trigger,
|
|
501
|
+
waitingForActions: !0,
|
|
502
|
+
canNavigate: !1
|
|
503
|
+
})
|
|
504
|
+
},
|
|
505
|
+
EXECUTE_CONTEXT_ACTIONS: {
|
|
506
|
+
target: "executingContextActions",
|
|
507
|
+
actions: a({
|
|
508
|
+
activeExecutionPlan: ({ event: e }) => e.executionPlan,
|
|
509
|
+
canNavigate: !1
|
|
510
|
+
})
|
|
511
|
+
},
|
|
512
|
+
SHOW_ACTION_DIALOG: {
|
|
513
|
+
target: "showingActionDialog",
|
|
514
|
+
actions: a({
|
|
515
|
+
activeDialog: ({ event: e }) => e.dialogConfig,
|
|
516
|
+
canNavigate: !0,
|
|
517
|
+
// Reset navigation permission when showing dialog
|
|
518
|
+
waitingForActions: !1
|
|
519
|
+
// Clear action waiting state
|
|
520
|
+
})
|
|
521
|
+
},
|
|
522
|
+
SHOW_FIELD_WARNING: {
|
|
523
|
+
actions: a({
|
|
524
|
+
fieldChangeState: ({ context: e, event: t }) => t.type !== "SHOW_FIELD_WARNING" ? e.fieldChangeState : {
|
|
525
|
+
...e.fieldChangeState,
|
|
526
|
+
[t.fieldId]: {
|
|
527
|
+
...e.fieldChangeState[t.fieldId],
|
|
528
|
+
validationWarnings: [
|
|
529
|
+
...e.fieldChangeState[t.fieldId]?.validationWarnings || [],
|
|
530
|
+
{
|
|
531
|
+
id: t.warningId,
|
|
532
|
+
fieldId: t.fieldId,
|
|
533
|
+
message: t.message,
|
|
534
|
+
severity: t.warningType || "warning",
|
|
535
|
+
type: t.warningType || "warning",
|
|
536
|
+
timestamp: Date.now(),
|
|
537
|
+
dismissible: !0
|
|
538
|
+
}
|
|
539
|
+
]
|
|
540
|
+
}
|
|
541
|
+
},
|
|
542
|
+
fieldValidationState: ({ context: e, event: t }) => t.type !== "SHOW_FIELD_WARNING" ? e.fieldValidationState : {
|
|
543
|
+
...e.fieldValidationState,
|
|
544
|
+
activeWarnings: e.fieldValidationState.activeWarnings.includes(
|
|
545
|
+
t.fieldId
|
|
546
|
+
) ? e.fieldValidationState.activeWarnings : [
|
|
547
|
+
...e.fieldValidationState.activeWarnings,
|
|
548
|
+
t.fieldId
|
|
549
|
+
]
|
|
550
|
+
}
|
|
551
|
+
})
|
|
552
|
+
},
|
|
553
|
+
DISMISS_FIELD_WARNING: {
|
|
554
|
+
actions: a({
|
|
555
|
+
fieldChangeState: ({ context: e, event: t }) => {
|
|
556
|
+
const n = e.fieldChangeState[t.fieldId];
|
|
557
|
+
return n ? {
|
|
558
|
+
...e.fieldChangeState,
|
|
559
|
+
[t.fieldId]: {
|
|
560
|
+
...n,
|
|
561
|
+
validationWarnings: n.validationWarnings?.filter(
|
|
562
|
+
(i) => i.id !== t.warningId
|
|
563
|
+
) || []
|
|
564
|
+
}
|
|
565
|
+
} : e.fieldChangeState;
|
|
566
|
+
},
|
|
567
|
+
fieldValidationState: ({ context: e, event: t }) => {
|
|
568
|
+
const i = e.fieldChangeState[t.fieldId]?.validationWarnings?.length > 0;
|
|
569
|
+
return {
|
|
570
|
+
...e.fieldValidationState,
|
|
571
|
+
activeWarnings: i ? e.fieldValidationState.activeWarnings : e.fieldValidationState.activeWarnings.filter(
|
|
572
|
+
(o) => o !== t.fieldId
|
|
573
|
+
)
|
|
574
|
+
};
|
|
575
|
+
}
|
|
576
|
+
})
|
|
577
|
+
},
|
|
578
|
+
START_FIELD_VERIFICATION: {
|
|
579
|
+
actions: a({
|
|
580
|
+
fieldValidationState: ({ context: e, event: t }) => t.type !== "START_FIELD_VERIFICATION" ? e.fieldValidationState : {
|
|
581
|
+
...e.fieldValidationState,
|
|
582
|
+
pendingVerifications: e.fieldValidationState.pendingVerifications.includes(
|
|
583
|
+
t.fieldId
|
|
584
|
+
) ? e.fieldValidationState.pendingVerifications : [
|
|
585
|
+
...e.fieldValidationState.pendingVerifications,
|
|
586
|
+
t.fieldId
|
|
587
|
+
],
|
|
588
|
+
verificationResults: {
|
|
589
|
+
...e.fieldValidationState.verificationResults,
|
|
590
|
+
[t.fieldId]: {
|
|
591
|
+
status: "pending",
|
|
592
|
+
timestamp: Date.now()
|
|
593
|
+
}
|
|
594
|
+
}
|
|
595
|
+
}
|
|
596
|
+
})
|
|
597
|
+
},
|
|
598
|
+
FIELD_VERIFICATION_COMPLETE: {
|
|
599
|
+
actions: a({
|
|
600
|
+
fieldValidationState: ({
|
|
601
|
+
context: e,
|
|
602
|
+
event: t
|
|
603
|
+
}) => ({
|
|
604
|
+
...e.fieldValidationState,
|
|
605
|
+
pendingVerifications: e.fieldValidationState.pendingVerifications.filter(
|
|
606
|
+
(n) => n !== t.fieldId
|
|
607
|
+
),
|
|
608
|
+
verificationResults: {
|
|
609
|
+
...e.fieldValidationState.verificationResults,
|
|
610
|
+
[t.fieldId]: {
|
|
611
|
+
status: t.success ? "success" : "failed",
|
|
612
|
+
timestamp: Date.now(),
|
|
613
|
+
result: t.result
|
|
614
|
+
}
|
|
615
|
+
}
|
|
616
|
+
})
|
|
617
|
+
})
|
|
618
|
+
},
|
|
619
|
+
CLEAR_FIELD_CHANGES: {
|
|
620
|
+
actions: a({
|
|
621
|
+
fieldChangeState: ({ context: e, event: t }) => {
|
|
622
|
+
if (t.fieldId) {
|
|
623
|
+
const n = { ...e.fieldChangeState };
|
|
624
|
+
return delete n[t.fieldId], n;
|
|
625
|
+
} else
|
|
626
|
+
return {};
|
|
627
|
+
},
|
|
628
|
+
fieldValidationState: ({ context: e, event: t }) => t.fieldId ? {
|
|
629
|
+
...e.fieldValidationState,
|
|
630
|
+
activeWarnings: e.fieldValidationState.activeWarnings.filter(
|
|
631
|
+
(n) => n !== t.fieldId
|
|
632
|
+
),
|
|
633
|
+
pendingVerifications: e.fieldValidationState.pendingVerifications.filter(
|
|
634
|
+
(n) => n !== t.fieldId
|
|
635
|
+
),
|
|
636
|
+
verificationResults: Object.fromEntries(
|
|
637
|
+
Object.entries(
|
|
638
|
+
e.fieldValidationState.verificationResults
|
|
639
|
+
).filter(([n]) => n !== t.fieldId)
|
|
640
|
+
)
|
|
641
|
+
} : {
|
|
642
|
+
activeWarnings: [],
|
|
643
|
+
pendingVerifications: [],
|
|
644
|
+
verificationResults: {}
|
|
645
|
+
}
|
|
646
|
+
})
|
|
647
|
+
},
|
|
648
|
+
SET_COMPONENT_ORIGINAL_VALUE: {
|
|
649
|
+
actions: a({
|
|
650
|
+
componentOriginalValues: ({ context: e, event: t }) => {
|
|
651
|
+
const n = e.componentOriginalValues[t.componentId], i = {
|
|
652
|
+
value: t.value,
|
|
653
|
+
timestamp: Date.now(),
|
|
654
|
+
source: t.source || "initialized",
|
|
655
|
+
isPopulated: t.source !== "initialized"
|
|
656
|
+
};
|
|
657
|
+
return n && h.shallowEqual(n, i) ? e.componentOriginalValues : Object.assign({}, e.componentOriginalValues, {
|
|
658
|
+
[t.componentId]: i
|
|
659
|
+
});
|
|
660
|
+
}
|
|
661
|
+
})
|
|
662
|
+
},
|
|
663
|
+
TRIGGER_COMPONENT_ACTION: {
|
|
664
|
+
actions: [p]
|
|
665
|
+
},
|
|
666
|
+
SHOW_COMPONENT_ALERT: {
|
|
667
|
+
actions: a({
|
|
668
|
+
componentAlerts: ({ context: e, event: t }) => {
|
|
669
|
+
const i = (e.componentAlerts[t.componentId] || []).filter(
|
|
670
|
+
(o) => o.id !== t.alert.id
|
|
671
|
+
);
|
|
672
|
+
return {
|
|
673
|
+
...e.componentAlerts,
|
|
674
|
+
[t.componentId]: [...i, t.alert]
|
|
675
|
+
};
|
|
676
|
+
}
|
|
677
|
+
})
|
|
678
|
+
},
|
|
679
|
+
DISMISS_COMPONENT_ALERT: {
|
|
680
|
+
actions: a({
|
|
681
|
+
componentAlerts: ({ context: e, event: t }) => {
|
|
682
|
+
const n = e.componentAlerts[t.componentId] || [], i = t.alertId ? n.filter((o) => o.id !== t.alertId) : [];
|
|
683
|
+
return console.log(
|
|
684
|
+
`🧹 [formMachine] DISMISS_COMPONENT_ALERT for ${t.componentId}:`,
|
|
685
|
+
{
|
|
686
|
+
alertId: t.alertId,
|
|
687
|
+
beforeCount: n.length,
|
|
688
|
+
afterCount: i.length,
|
|
689
|
+
clearedAll: !t.alertId && n.length > 0
|
|
690
|
+
}
|
|
691
|
+
), {
|
|
692
|
+
...e.componentAlerts,
|
|
693
|
+
[t.componentId]: i
|
|
694
|
+
};
|
|
695
|
+
}
|
|
696
|
+
})
|
|
697
|
+
},
|
|
698
|
+
CLEAR_COMPONENT_ALERT: {
|
|
699
|
+
actions: a({
|
|
700
|
+
componentAlerts: ({ context: e, event: t }) => (console.log(
|
|
701
|
+
`🧹 [formMachine] CLEAR_COMPONENT_ALERT for ${t.componentId}`
|
|
702
|
+
), {
|
|
703
|
+
...e.componentAlerts,
|
|
704
|
+
[t.componentId]: []
|
|
705
|
+
})
|
|
706
|
+
})
|
|
707
|
+
},
|
|
708
|
+
START_SAVE: {
|
|
709
|
+
target: "preparingSave",
|
|
710
|
+
actions: a({
|
|
711
|
+
saveState: ({ context: e, event: t }) => t.type !== "START_SAVE" ? e.saveState : {
|
|
712
|
+
...e.saveState,
|
|
713
|
+
saveInProgress: !0,
|
|
714
|
+
saveInitiator: t.initiator,
|
|
715
|
+
savingSection: t.sectionId,
|
|
716
|
+
saveStartTimestamp: Date.now(),
|
|
717
|
+
pendingVerifications: [],
|
|
718
|
+
completedVerifications: [],
|
|
719
|
+
validationErrors: {}
|
|
720
|
+
}
|
|
721
|
+
})
|
|
722
|
+
},
|
|
723
|
+
SAVE_DIALOG_SHOWN: {
|
|
724
|
+
actions: a({
|
|
725
|
+
saveState: ({ context: e, event: t }) => t.type !== "SAVE_DIALOG_SHOWN" ? e.saveState : {
|
|
726
|
+
...e.saveState,
|
|
727
|
+
pendingVerifications: [
|
|
728
|
+
...e.saveState.pendingVerifications,
|
|
729
|
+
t.dialogId
|
|
730
|
+
]
|
|
731
|
+
}
|
|
732
|
+
})
|
|
733
|
+
}
|
|
734
|
+
}
|
|
735
|
+
},
|
|
736
|
+
// New simplified execution state for context-based triggers
|
|
737
|
+
executingContextActions: {
|
|
738
|
+
entry: [
|
|
739
|
+
// Execute all actions in the execution plan
|
|
740
|
+
({ context: e, self: t }) => {
|
|
741
|
+
const n = e.activeExecutionPlan;
|
|
742
|
+
n && (n.executions.forEach((i) => {
|
|
743
|
+
i.actions.forEach((o) => {
|
|
744
|
+
t.send({
|
|
745
|
+
type: "TRIGGER_COMPONENT_ACTION",
|
|
746
|
+
componentId: i.componentId,
|
|
747
|
+
triggerId: i.trigger.id,
|
|
748
|
+
actionId: o.id,
|
|
749
|
+
eventType: "navigationAttempt"
|
|
750
|
+
});
|
|
751
|
+
});
|
|
752
|
+
}), n.totalActions === 0 && t.send({
|
|
753
|
+
type: "CONTEXT_ACTIONS_COMPLETE",
|
|
754
|
+
results: {}
|
|
755
|
+
}));
|
|
756
|
+
}
|
|
757
|
+
],
|
|
758
|
+
on: {
|
|
759
|
+
REQUEST_NAVIGATION: {
|
|
760
|
+
actions: [
|
|
761
|
+
a({
|
|
762
|
+
pendingNavigation: ({ event: e }) => {
|
|
763
|
+
if (e.type !== "REQUEST_NAVIGATION") return null;
|
|
764
|
+
const t = {
|
|
765
|
+
type: e.navigationType
|
|
766
|
+
};
|
|
767
|
+
return e.stepId !== void 0 && (t.stepId = e.stepId), t;
|
|
768
|
+
}
|
|
769
|
+
})
|
|
770
|
+
]
|
|
771
|
+
},
|
|
772
|
+
TRIGGER_COMPONENT_ACTION: {
|
|
773
|
+
actions: [p]
|
|
774
|
+
},
|
|
775
|
+
CONTEXT_ACTIONS_COMPLETE: {
|
|
776
|
+
target: "idle",
|
|
777
|
+
actions: [
|
|
778
|
+
a({
|
|
779
|
+
activeExecutionPlan: null,
|
|
780
|
+
executionResults: ({ context: e, event: t }) => ({
|
|
781
|
+
...e.executionResults,
|
|
782
|
+
...t.results
|
|
783
|
+
})
|
|
784
|
+
}),
|
|
785
|
+
f
|
|
786
|
+
]
|
|
787
|
+
},
|
|
788
|
+
SHOW_ACTION_DIALOG: {
|
|
789
|
+
target: "showingActionDialog",
|
|
790
|
+
actions: a({
|
|
791
|
+
activeDialog: ({ event: e }) => e.dialogConfig
|
|
792
|
+
})
|
|
793
|
+
},
|
|
794
|
+
SHOW_COMPONENT_ALERT: {
|
|
795
|
+
actions: a({
|
|
796
|
+
componentAlerts: ({ context: e, event: t }) => {
|
|
797
|
+
const i = (e.componentAlerts[t.componentId] || []).filter(
|
|
798
|
+
(o) => o.id !== t.alert.id
|
|
799
|
+
);
|
|
800
|
+
return {
|
|
801
|
+
...e.componentAlerts,
|
|
802
|
+
[t.componentId]: [...i, t.alert]
|
|
803
|
+
};
|
|
804
|
+
}
|
|
805
|
+
})
|
|
806
|
+
}
|
|
807
|
+
}
|
|
808
|
+
},
|
|
809
|
+
submitting: {
|
|
810
|
+
entry: a({ isSubmitting: !0 }),
|
|
811
|
+
on: {
|
|
812
|
+
SUBMIT_SUCCESS: {
|
|
813
|
+
target: "idle",
|
|
814
|
+
actions: a({ isSubmitting: !1 })
|
|
815
|
+
},
|
|
816
|
+
SUBMIT_ERROR: {
|
|
817
|
+
target: "idle",
|
|
818
|
+
actions: a({
|
|
819
|
+
isSubmitting: !1,
|
|
820
|
+
errors: ({ context: e, event: t }) => ({
|
|
821
|
+
...e.errors,
|
|
822
|
+
_form: [t.error.message]
|
|
823
|
+
})
|
|
824
|
+
})
|
|
825
|
+
},
|
|
826
|
+
SET_COMPONENT_ORIGINAL_VALUE: {
|
|
827
|
+
actions: a({
|
|
828
|
+
componentOriginalValues: ({ context: e, event: t }) => ({
|
|
829
|
+
...e.componentOriginalValues,
|
|
830
|
+
[t.componentId]: {
|
|
831
|
+
value: t.value,
|
|
832
|
+
timestamp: Date.now(),
|
|
833
|
+
source: t.source || "initialized",
|
|
834
|
+
isPopulated: t.source !== "initialized"
|
|
835
|
+
}
|
|
836
|
+
})
|
|
837
|
+
})
|
|
838
|
+
}
|
|
839
|
+
}
|
|
840
|
+
},
|
|
841
|
+
// Enhanced execution states for step and component actions
|
|
842
|
+
executingActions: {
|
|
843
|
+
on: {
|
|
844
|
+
COMPONENT_ACTION_START: {
|
|
845
|
+
actions: a({
|
|
846
|
+
activeComponentActions: ({ context: e, event: t }) => {
|
|
847
|
+
const n = e.activeComponentActions[t.componentId] || [];
|
|
848
|
+
return {
|
|
849
|
+
...e.activeComponentActions,
|
|
850
|
+
[t.componentId]: [
|
|
851
|
+
...n,
|
|
852
|
+
{
|
|
853
|
+
actionId: t.actionId,
|
|
854
|
+
componentId: t.componentId,
|
|
855
|
+
status: "executing",
|
|
856
|
+
startTime: Date.now()
|
|
857
|
+
}
|
|
858
|
+
]
|
|
859
|
+
};
|
|
860
|
+
}
|
|
861
|
+
})
|
|
862
|
+
},
|
|
863
|
+
COMPONENT_ACTION_COMPLETE: {
|
|
864
|
+
actions: a({
|
|
865
|
+
activeComponentActions: ({ context: e, event: t }) => {
|
|
866
|
+
const n = e.activeComponentActions[t.componentId] || [];
|
|
867
|
+
return {
|
|
868
|
+
...e.activeComponentActions,
|
|
869
|
+
[t.componentId]: n.map(
|
|
870
|
+
(i) => i.actionId === t.actionId ? { ...i, status: "completed" } : i
|
|
871
|
+
)
|
|
872
|
+
};
|
|
873
|
+
}
|
|
874
|
+
})
|
|
875
|
+
},
|
|
876
|
+
COMPONENT_ACTION_FAILED: {
|
|
877
|
+
actions: a({
|
|
878
|
+
activeComponentActions: ({ context: e, event: t }) => {
|
|
879
|
+
const n = e.activeComponentActions[t.componentId] || [];
|
|
880
|
+
return {
|
|
881
|
+
...e.activeComponentActions,
|
|
882
|
+
[t.componentId]: n.map(
|
|
883
|
+
(i) => i.actionId === t.actionId ? {
|
|
884
|
+
...i,
|
|
885
|
+
status: "failed",
|
|
886
|
+
error: t.error
|
|
887
|
+
} : i
|
|
888
|
+
)
|
|
889
|
+
};
|
|
890
|
+
}
|
|
891
|
+
})
|
|
892
|
+
},
|
|
893
|
+
SHOW_COMPONENT_ALERT: {
|
|
894
|
+
actions: a({
|
|
895
|
+
componentAlerts: ({ context: e, event: t }) => {
|
|
896
|
+
const i = (e.componentAlerts[t.componentId] || []).filter(
|
|
897
|
+
(o) => o.id !== t.alert.id
|
|
898
|
+
);
|
|
899
|
+
return {
|
|
900
|
+
...e.componentAlerts,
|
|
901
|
+
[t.componentId]: [...i, t.alert]
|
|
902
|
+
};
|
|
903
|
+
}
|
|
904
|
+
})
|
|
905
|
+
},
|
|
906
|
+
ACTION_START: {
|
|
907
|
+
actions: a({
|
|
908
|
+
activeActions: ({ context: e, event: t }) => ({
|
|
909
|
+
...e.activeActions,
|
|
910
|
+
[t.actionId]: {
|
|
911
|
+
actionId: t.actionId,
|
|
912
|
+
status: "executing",
|
|
913
|
+
startTime: Date.now()
|
|
914
|
+
}
|
|
915
|
+
})
|
|
916
|
+
})
|
|
917
|
+
},
|
|
918
|
+
ACTION_SUCCESS: {
|
|
919
|
+
actions: a({
|
|
920
|
+
activeActions: ({ context: e, event: t }) => ({
|
|
921
|
+
...e.activeActions,
|
|
922
|
+
[t.actionId]: {
|
|
923
|
+
...e.activeActions[t.actionId],
|
|
924
|
+
status: "success",
|
|
925
|
+
result: t.result,
|
|
926
|
+
completedTime: Date.now()
|
|
927
|
+
}
|
|
928
|
+
})
|
|
929
|
+
})
|
|
930
|
+
},
|
|
931
|
+
ACTION_ERROR: {
|
|
932
|
+
actions: a({
|
|
933
|
+
activeActions: ({ context: e, event: t }) => ({
|
|
934
|
+
...e.activeActions,
|
|
935
|
+
[t.actionId]: {
|
|
936
|
+
...e.activeActions[t.actionId],
|
|
937
|
+
status: "error",
|
|
938
|
+
error: t.error,
|
|
939
|
+
completedTime: Date.now()
|
|
940
|
+
}
|
|
941
|
+
})
|
|
942
|
+
})
|
|
943
|
+
},
|
|
944
|
+
ACTIONS_COMPLETED: {
|
|
945
|
+
target: "executingPendingNavigation",
|
|
946
|
+
actions: a({
|
|
947
|
+
// Clear all action execution state
|
|
948
|
+
activeActions: {},
|
|
949
|
+
executingTrigger: null,
|
|
950
|
+
waitingForActions: !1,
|
|
951
|
+
canNavigate: !0,
|
|
952
|
+
// Store final results
|
|
953
|
+
actionResults: ({ context: e, event: t }) => ({
|
|
954
|
+
...e.actionResults,
|
|
955
|
+
...t.results
|
|
956
|
+
})
|
|
957
|
+
})
|
|
958
|
+
},
|
|
959
|
+
SHOW_ACTION_DIALOG: {
|
|
960
|
+
target: "showingActionDialog",
|
|
961
|
+
actions: a({
|
|
962
|
+
activeDialog: ({ event: e }) => e.dialogConfig,
|
|
963
|
+
canNavigate: !1,
|
|
964
|
+
// Block navigation until dialog is resolved
|
|
965
|
+
waitingForActions: !1
|
|
966
|
+
// Clear action waiting state
|
|
967
|
+
})
|
|
968
|
+
},
|
|
969
|
+
TRIGGER_COMPONENT_ACTION: {
|
|
970
|
+
actions: [p]
|
|
971
|
+
},
|
|
972
|
+
DISMISS_COMPONENT_ALERT: {
|
|
973
|
+
actions: a({
|
|
974
|
+
componentAlerts: ({ context: e, event: t }) => {
|
|
975
|
+
const n = e.componentAlerts[t.componentId] || [], i = t.alertId ? n.filter((o) => o.id !== t.alertId) : [];
|
|
976
|
+
return {
|
|
977
|
+
...e.componentAlerts,
|
|
978
|
+
[t.componentId]: i
|
|
979
|
+
};
|
|
980
|
+
}
|
|
981
|
+
})
|
|
982
|
+
},
|
|
983
|
+
CLEAR_COMPONENT_ALERT: {
|
|
984
|
+
actions: a({
|
|
985
|
+
componentAlerts: ({ context: e, event: t }) => ({
|
|
986
|
+
...e.componentAlerts,
|
|
987
|
+
[t.componentId]: []
|
|
988
|
+
})
|
|
989
|
+
})
|
|
990
|
+
}
|
|
991
|
+
}
|
|
992
|
+
},
|
|
993
|
+
// State for evaluating navigation and potentially executing trigger actions
|
|
994
|
+
evaluatingNavigation: {
|
|
995
|
+
entry: [],
|
|
996
|
+
always: [
|
|
997
|
+
{
|
|
998
|
+
// PRIORITY 1: Execute save context actions (including verification dialogs)
|
|
999
|
+
guard: E,
|
|
1000
|
+
target: "executingContextActions",
|
|
1001
|
+
actions: [
|
|
1002
|
+
a({
|
|
1003
|
+
activeExecutionPlan: ({ context: e }) => {
|
|
1004
|
+
console.log(
|
|
1005
|
+
"🎯 [formMachine] Creating execution plan for save context in evaluatingNavigation"
|
|
1006
|
+
);
|
|
1007
|
+
const t = u.createExecutionPlan(
|
|
1008
|
+
e.config,
|
|
1009
|
+
"save",
|
|
1010
|
+
e.currentStepIndex,
|
|
1011
|
+
e
|
|
1012
|
+
);
|
|
1013
|
+
return console.log("🎯 [formMachine] Save context execution plan:", {
|
|
1014
|
+
totalActions: t.totalActions,
|
|
1015
|
+
executionsCount: t.executions.length,
|
|
1016
|
+
executions: t.executions.map((n) => ({
|
|
1017
|
+
componentId: n.componentId,
|
|
1018
|
+
triggerId: n.trigger.id,
|
|
1019
|
+
triggerType: n.trigger.type,
|
|
1020
|
+
actionsCount: n.actions.length,
|
|
1021
|
+
actions: n.actions.map((i) => ({
|
|
1022
|
+
id: i.id,
|
|
1023
|
+
type: i.type,
|
|
1024
|
+
contexts: i.contexts
|
|
1025
|
+
}))
|
|
1026
|
+
}))
|
|
1027
|
+
}), t;
|
|
1028
|
+
}
|
|
1029
|
+
})
|
|
1030
|
+
]
|
|
1031
|
+
},
|
|
1032
|
+
{
|
|
1033
|
+
// PRIORITY 2: Check for other dirty components with triggers for step navigation
|
|
1034
|
+
guard: v,
|
|
1035
|
+
target: "executingTriggerActions",
|
|
1036
|
+
actions: [
|
|
1037
|
+
a({
|
|
1038
|
+
executingTrigger: "onStepFinish",
|
|
1039
|
+
waitingForActions: !0,
|
|
1040
|
+
canNavigate: !1
|
|
1041
|
+
}),
|
|
1042
|
+
// Execute the component trigger actions
|
|
1043
|
+
({ context: e, self: t }) => {
|
|
1044
|
+
console.log(
|
|
1045
|
+
"🎯 [formMachine] Executing dirty component trigger actions for step navigation"
|
|
1046
|
+
), u.findDirtyComponentsForNavigation(
|
|
1047
|
+
e.config,
|
|
1048
|
+
e.currentStepIndex,
|
|
1049
|
+
e,
|
|
1050
|
+
"step"
|
|
1051
|
+
).forEach(
|
|
1052
|
+
({ componentId: i, trigger: o, actions: r }) => {
|
|
1053
|
+
r.forEach((s) => {
|
|
1054
|
+
console.log(
|
|
1055
|
+
`⚡ [formMachine] Executing step navigation action ${s.id} for ${i}`
|
|
1056
|
+
), t.send({
|
|
1057
|
+
type: "TRIGGER_COMPONENT_ACTION",
|
|
1058
|
+
componentId: i,
|
|
1059
|
+
triggerId: o.id,
|
|
1060
|
+
actionId: s.id,
|
|
1061
|
+
eventType: "navigationAttempt"
|
|
1062
|
+
});
|
|
1063
|
+
});
|
|
1064
|
+
}
|
|
1065
|
+
);
|
|
1066
|
+
}
|
|
1067
|
+
]
|
|
1068
|
+
},
|
|
1069
|
+
{
|
|
1070
|
+
// PRIORITY 3: Execute step-level onStepFinish actions if this is a next navigation
|
|
1071
|
+
guard: ({ context: e }) => {
|
|
1072
|
+
if (e.pendingNavigation?.type !== "next") return !1;
|
|
1073
|
+
const t = e.config.steps[e.currentStepIndex];
|
|
1074
|
+
if (!t || !("actions" in t)) return !1;
|
|
1075
|
+
const n = t.actions || [], i = n.some(
|
|
1076
|
+
(o) => o.trigger === "onStepFinish"
|
|
1077
|
+
);
|
|
1078
|
+
return console.log(
|
|
1079
|
+
"🎯 [formMachine] Checking for step-level onStepFinish actions:",
|
|
1080
|
+
{
|
|
1081
|
+
stepIndex: e.currentStepIndex,
|
|
1082
|
+
stepId: t.id,
|
|
1083
|
+
hasFinishActions: i,
|
|
1084
|
+
stepActionsCount: n.length
|
|
1085
|
+
}
|
|
1086
|
+
), i;
|
|
1087
|
+
},
|
|
1088
|
+
target: "executingActions",
|
|
1089
|
+
actions: [
|
|
1090
|
+
a({
|
|
1091
|
+
executingTrigger: "onStepFinish",
|
|
1092
|
+
waitingForActions: !0,
|
|
1093
|
+
canNavigate: !1
|
|
1094
|
+
}),
|
|
1095
|
+
({ context: e, self: t }) => {
|
|
1096
|
+
const n = e.config.steps[e.currentStepIndex], i = n.actions || [];
|
|
1097
|
+
console.log(
|
|
1098
|
+
"🎯 [formMachine] Executing step-level onStepFinish actions:",
|
|
1099
|
+
{
|
|
1100
|
+
stepIndex: e.currentStepIndex,
|
|
1101
|
+
stepId: n.id,
|
|
1102
|
+
actionsCount: i.length
|
|
1103
|
+
}
|
|
1104
|
+
), t.send({
|
|
1105
|
+
type: "EXECUTE_ACTIONS",
|
|
1106
|
+
trigger: "onStepFinish"
|
|
1107
|
+
});
|
|
1108
|
+
}
|
|
1109
|
+
]
|
|
1110
|
+
},
|
|
1111
|
+
{
|
|
1112
|
+
// PRIORITY 4: Proceed with normal navigation evaluation
|
|
1113
|
+
guard: O,
|
|
1114
|
+
target: "executingPendingNavigation"
|
|
1115
|
+
}
|
|
1116
|
+
]
|
|
1117
|
+
},
|
|
1118
|
+
// New state for executing trigger actions
|
|
1119
|
+
executingTriggerActions: {
|
|
1120
|
+
on: {
|
|
1121
|
+
TRIGGER_COMPONENT_ACTION: {
|
|
1122
|
+
actions: [
|
|
1123
|
+
a({
|
|
1124
|
+
componentTriggerState: ({ context: e, event: t }) => ({
|
|
1125
|
+
...e.componentTriggerState,
|
|
1126
|
+
[`${t.componentId}-${t.triggerId}`]: {
|
|
1127
|
+
...e.componentTriggerState[`${t.componentId}-${t.triggerId}`],
|
|
1128
|
+
isActive: !0,
|
|
1129
|
+
lastTriggered: Date.now()
|
|
1130
|
+
}
|
|
1131
|
+
})
|
|
1132
|
+
}),
|
|
1133
|
+
a({
|
|
1134
|
+
activeComponentActions: ({ context: e, event: t }) => {
|
|
1135
|
+
const n = e.activeComponentActions[t.componentId] || [];
|
|
1136
|
+
return {
|
|
1137
|
+
...e.activeComponentActions,
|
|
1138
|
+
[t.componentId]: [
|
|
1139
|
+
...n,
|
|
1140
|
+
{
|
|
1141
|
+
actionId: t.actionId,
|
|
1142
|
+
componentId: t.componentId,
|
|
1143
|
+
status: "executing",
|
|
1144
|
+
startTime: Date.now()
|
|
1145
|
+
}
|
|
1146
|
+
]
|
|
1147
|
+
};
|
|
1148
|
+
}
|
|
1149
|
+
}),
|
|
1150
|
+
p
|
|
1151
|
+
]
|
|
1152
|
+
},
|
|
1153
|
+
TRIGGER_ACTIONS_COMPLETE: {
|
|
1154
|
+
target: "executingPendingNavigation",
|
|
1155
|
+
actions: a({
|
|
1156
|
+
executingTrigger: null,
|
|
1157
|
+
waitingForActions: !1,
|
|
1158
|
+
canNavigate: !0
|
|
1159
|
+
})
|
|
1160
|
+
},
|
|
1161
|
+
DISMISS_COMPONENT_ALERT: {
|
|
1162
|
+
actions: a({
|
|
1163
|
+
componentAlerts: ({ context: e, event: t }) => {
|
|
1164
|
+
const n = e.componentAlerts[t.componentId] || [], i = t.alertId ? n.filter((o) => o.id !== t.alertId) : [];
|
|
1165
|
+
return {
|
|
1166
|
+
...e.componentAlerts,
|
|
1167
|
+
[t.componentId]: i
|
|
1168
|
+
};
|
|
1169
|
+
}
|
|
1170
|
+
})
|
|
1171
|
+
},
|
|
1172
|
+
CLEAR_COMPONENT_ALERT: {
|
|
1173
|
+
actions: a({
|
|
1174
|
+
componentAlerts: ({ context: e, event: t }) => ({
|
|
1175
|
+
...e.componentAlerts,
|
|
1176
|
+
[t.componentId]: []
|
|
1177
|
+
})
|
|
1178
|
+
})
|
|
1179
|
+
},
|
|
1180
|
+
SHOW_ACTION_DIALOG: {
|
|
1181
|
+
target: "showingActionDialog",
|
|
1182
|
+
actions: a({
|
|
1183
|
+
activeDialog: ({ event: e }) => e.dialogConfig,
|
|
1184
|
+
canNavigate: !1,
|
|
1185
|
+
waitingForActions: !1
|
|
1186
|
+
})
|
|
1187
|
+
}
|
|
1188
|
+
}
|
|
1189
|
+
},
|
|
1190
|
+
// Enhanced pending navigation execution state
|
|
1191
|
+
executingPendingNavigation: {
|
|
1192
|
+
always: [
|
|
1193
|
+
{
|
|
1194
|
+
guard: S,
|
|
1195
|
+
target: "idle",
|
|
1196
|
+
actions: a({
|
|
1197
|
+
currentStepIndex: ({ context: e }) => Math.min(
|
|
1198
|
+
e.currentStepIndex + 1,
|
|
1199
|
+
e.config.steps.length - 1
|
|
1200
|
+
),
|
|
1201
|
+
currentStepId: ({ context: e }) => {
|
|
1202
|
+
const t = Math.min(
|
|
1203
|
+
e.currentStepIndex + 1,
|
|
1204
|
+
e.config.steps.length - 1
|
|
1205
|
+
);
|
|
1206
|
+
return e.config.steps[t]?.id || "";
|
|
1207
|
+
},
|
|
1208
|
+
pendingNavigation: null
|
|
1209
|
+
})
|
|
1210
|
+
},
|
|
1211
|
+
{
|
|
1212
|
+
guard: A,
|
|
1213
|
+
target: "idle",
|
|
1214
|
+
actions: a({
|
|
1215
|
+
currentStepIndex: ({ context: e }) => Math.max(e.currentStepIndex - 1, 0),
|
|
1216
|
+
currentStepId: ({ context: e }) => {
|
|
1217
|
+
const t = Math.max(e.currentStepIndex - 1, 0);
|
|
1218
|
+
return e.config.steps[t]?.id || "";
|
|
1219
|
+
},
|
|
1220
|
+
pendingNavigation: null
|
|
1221
|
+
})
|
|
1222
|
+
},
|
|
1223
|
+
{
|
|
1224
|
+
guard: T,
|
|
1225
|
+
target: "idle",
|
|
1226
|
+
actions: a({
|
|
1227
|
+
currentStepIndex: ({ context: e }) => {
|
|
1228
|
+
const t = e.config.steps.findIndex(
|
|
1229
|
+
(n) => n.id === e.pendingNavigation?.stepId
|
|
1230
|
+
);
|
|
1231
|
+
return t >= 0 ? t : e.currentStepIndex;
|
|
1232
|
+
},
|
|
1233
|
+
currentStepId: ({ context: e }) => e.pendingNavigation?.stepId || e.currentStepId,
|
|
1234
|
+
pendingNavigation: null,
|
|
1235
|
+
canNavigate: !0
|
|
1236
|
+
})
|
|
1237
|
+
},
|
|
1238
|
+
{
|
|
1239
|
+
target: "idle",
|
|
1240
|
+
actions: a({
|
|
1241
|
+
pendingNavigation: null,
|
|
1242
|
+
canNavigate: !0
|
|
1243
|
+
})
|
|
1244
|
+
}
|
|
1245
|
+
]
|
|
1246
|
+
},
|
|
1247
|
+
showingActionDialog: {
|
|
1248
|
+
on: {
|
|
1249
|
+
HIDE_ACTION_DIALOG: {
|
|
1250
|
+
target: "idle",
|
|
1251
|
+
actions: a({
|
|
1252
|
+
activeDialog: null,
|
|
1253
|
+
canNavigate: !0,
|
|
1254
|
+
// Allow navigation when dialog is hidden (cancelled)
|
|
1255
|
+
pendingNavigation: null
|
|
1256
|
+
// Clear pending navigation - don't proceed
|
|
1257
|
+
})
|
|
1258
|
+
},
|
|
1259
|
+
// Handle dialog verification success
|
|
1260
|
+
DIALOG_VERIFIED: {
|
|
1261
|
+
target: "executingPendingNavigation",
|
|
1262
|
+
actions: [
|
|
1263
|
+
a({
|
|
1264
|
+
activeDialog: null,
|
|
1265
|
+
canNavigate: !0
|
|
1266
|
+
// Allow navigation after successful verification
|
|
1267
|
+
}),
|
|
1268
|
+
// Handle updateOriginalValue action from verified dialog
|
|
1269
|
+
({ context: e, self: t }) => {
|
|
1270
|
+
const n = e.activeDialog;
|
|
1271
|
+
if (!n) return;
|
|
1272
|
+
const i = n;
|
|
1273
|
+
if (i.templateConfig?.onVerifiedAction?.type === "updateOriginalValue") {
|
|
1274
|
+
const o = i.componentId;
|
|
1275
|
+
o && e.data[o] !== void 0 && (console.log(
|
|
1276
|
+
`🔄 [formMachine] DIALOG_VERIFIED: Updating original value for ${o}`,
|
|
1277
|
+
{
|
|
1278
|
+
newValue: e.data[o],
|
|
1279
|
+
oldOriginalValue: e.componentOriginalValues[o]?.value
|
|
1280
|
+
}
|
|
1281
|
+
), t.send({
|
|
1282
|
+
type: "SET_COMPONENT_ORIGINAL_VALUE",
|
|
1283
|
+
componentId: o,
|
|
1284
|
+
value: e.data[o],
|
|
1285
|
+
source: "user_verified"
|
|
1286
|
+
}), t.send({
|
|
1287
|
+
type: "MARK_COMPONENT_AS_POPULATED",
|
|
1288
|
+
componentId: o,
|
|
1289
|
+
value: e.data[o]
|
|
1290
|
+
}), t.send({
|
|
1291
|
+
type: "DISMISS_COMPONENT_ALERT",
|
|
1292
|
+
componentId: o
|
|
1293
|
+
}), t.send({
|
|
1294
|
+
type: "EVALUATE_COMPONENT_TRIGGERS",
|
|
1295
|
+
componentId: o,
|
|
1296
|
+
value: e.data[o],
|
|
1297
|
+
eventType: "valueChange"
|
|
1298
|
+
}), console.log(
|
|
1299
|
+
`🔄 [formMachine] Sending RESET_FIELD_TANSTACK_STATE event for ${o}`
|
|
1300
|
+
));
|
|
1301
|
+
}
|
|
1302
|
+
}
|
|
1303
|
+
]
|
|
1304
|
+
},
|
|
1305
|
+
// Handle dialog cancellation
|
|
1306
|
+
DIALOG_CANCELLED: {
|
|
1307
|
+
target: "idle",
|
|
1308
|
+
actions: a({
|
|
1309
|
+
activeDialog: null,
|
|
1310
|
+
canNavigate: !0,
|
|
1311
|
+
// Reset navigation permission
|
|
1312
|
+
pendingNavigation: null
|
|
1313
|
+
// Clear pending navigation - don't proceed
|
|
1314
|
+
})
|
|
1315
|
+
},
|
|
1316
|
+
DIALOG_BUTTON_CLICK: {
|
|
1317
|
+
// Handle dialog button actions - will be expanded later
|
|
1318
|
+
actions: []
|
|
1319
|
+
},
|
|
1320
|
+
NEXT: [
|
|
1321
|
+
{
|
|
1322
|
+
guard: d,
|
|
1323
|
+
target: "idle",
|
|
1324
|
+
actions: a({
|
|
1325
|
+
currentStepIndex: ({ context: e }) => Math.min(
|
|
1326
|
+
e.currentStepIndex + 1,
|
|
1327
|
+
e.config.steps.length - 1
|
|
1328
|
+
),
|
|
1329
|
+
currentStepId: ({ context: e }) => {
|
|
1330
|
+
const t = Math.min(
|
|
1331
|
+
e.currentStepIndex + 1,
|
|
1332
|
+
e.config.steps.length - 1
|
|
1333
|
+
);
|
|
1334
|
+
return e.config.steps[t]?.id || "";
|
|
1335
|
+
},
|
|
1336
|
+
pendingNavigation: null
|
|
1337
|
+
})
|
|
1338
|
+
},
|
|
1339
|
+
{
|
|
1340
|
+
target: "idle",
|
|
1341
|
+
actions: a({
|
|
1342
|
+
activeDialog: null,
|
|
1343
|
+
pendingNavigation: { type: "next" }
|
|
1344
|
+
})
|
|
1345
|
+
}
|
|
1346
|
+
],
|
|
1347
|
+
PREVIOUS: [
|
|
1348
|
+
{
|
|
1349
|
+
guard: d,
|
|
1350
|
+
target: "idle",
|
|
1351
|
+
actions: a({
|
|
1352
|
+
currentStepIndex: ({ context: e }) => Math.max(e.currentStepIndex - 1, 0),
|
|
1353
|
+
currentStepId: ({ context: e }) => {
|
|
1354
|
+
const t = Math.max(e.currentStepIndex - 1, 0);
|
|
1355
|
+
return e.config.steps[t]?.id || "";
|
|
1356
|
+
},
|
|
1357
|
+
pendingNavigation: null
|
|
1358
|
+
})
|
|
1359
|
+
},
|
|
1360
|
+
{
|
|
1361
|
+
target: "idle",
|
|
1362
|
+
actions: a({
|
|
1363
|
+
activeDialog: null,
|
|
1364
|
+
pendingNavigation: { type: "previous" }
|
|
1365
|
+
})
|
|
1366
|
+
}
|
|
1367
|
+
],
|
|
1368
|
+
GO_TO_STEP: [
|
|
1369
|
+
{
|
|
1370
|
+
guard: d,
|
|
1371
|
+
target: "idle",
|
|
1372
|
+
actions: a({
|
|
1373
|
+
currentStepIndex: ({ context: e, event: t }) => {
|
|
1374
|
+
if (t.type !== "GO_TO_STEP")
|
|
1375
|
+
return e.currentStepIndex;
|
|
1376
|
+
const n = e.config.steps.findIndex(
|
|
1377
|
+
(i) => i.id === t.stepId
|
|
1378
|
+
);
|
|
1379
|
+
return n >= 0 ? n : e.currentStepIndex;
|
|
1380
|
+
},
|
|
1381
|
+
currentStepId: ({ context: e, event: t }) => t.type !== "GO_TO_STEP" ? e.currentStepId : t.stepId,
|
|
1382
|
+
pendingNavigation: null
|
|
1383
|
+
})
|
|
1384
|
+
},
|
|
1385
|
+
{
|
|
1386
|
+
target: "idle",
|
|
1387
|
+
actions: a({
|
|
1388
|
+
activeDialog: null,
|
|
1389
|
+
pendingNavigation: ({ event: e }) => ({
|
|
1390
|
+
type: "step",
|
|
1391
|
+
stepId: e.stepId
|
|
1392
|
+
})
|
|
1393
|
+
})
|
|
1394
|
+
}
|
|
1395
|
+
]
|
|
1396
|
+
}
|
|
1397
|
+
},
|
|
1398
|
+
// Enhanced Section Save Flow States
|
|
1399
|
+
preparingSave: {
|
|
1400
|
+
entry: [],
|
|
1401
|
+
always: [
|
|
1402
|
+
{
|
|
1403
|
+
// Validate save fields and create execution plan
|
|
1404
|
+
guard: C,
|
|
1405
|
+
target: "executingSaveActions",
|
|
1406
|
+
actions: a({
|
|
1407
|
+
saveState: ({ context: e }) => {
|
|
1408
|
+
const t = u.createExecutionPlan(
|
|
1409
|
+
e.config,
|
|
1410
|
+
"save",
|
|
1411
|
+
e.currentStepIndex,
|
|
1412
|
+
e
|
|
1413
|
+
);
|
|
1414
|
+
return {
|
|
1415
|
+
...e.saveState,
|
|
1416
|
+
executionPlan: t
|
|
1417
|
+
};
|
|
1418
|
+
}
|
|
1419
|
+
})
|
|
1420
|
+
},
|
|
1421
|
+
{
|
|
1422
|
+
// Validation failed or no actions to execute
|
|
1423
|
+
target: "idle",
|
|
1424
|
+
actions: [
|
|
1425
|
+
a({
|
|
1426
|
+
saveState: ({ context: e }) => ({
|
|
1427
|
+
...e.saveState,
|
|
1428
|
+
saveInProgress: !1,
|
|
1429
|
+
saveInitiator: null,
|
|
1430
|
+
savingSection: null,
|
|
1431
|
+
pendingVerifications: [],
|
|
1432
|
+
completedVerifications: [],
|
|
1433
|
+
validationErrors: {},
|
|
1434
|
+
executionPlan: null
|
|
1435
|
+
})
|
|
1436
|
+
})
|
|
1437
|
+
]
|
|
1438
|
+
}
|
|
1439
|
+
]
|
|
1440
|
+
},
|
|
1441
|
+
executingSaveActions: {
|
|
1442
|
+
entry: [m],
|
|
1443
|
+
on: {
|
|
1444
|
+
TRIGGER_COMPONENT_ACTION: {
|
|
1445
|
+
actions: [p]
|
|
1446
|
+
},
|
|
1447
|
+
SHOW_ACTION_DIALOG: {
|
|
1448
|
+
target: "awaitingVerification",
|
|
1449
|
+
actions: a({
|
|
1450
|
+
activeDialog: ({ event: e }) => e.dialogConfig
|
|
1451
|
+
})
|
|
1452
|
+
},
|
|
1453
|
+
SAVE_ACTIONS_COMPLETE: {
|
|
1454
|
+
target: "completingSave"
|
|
1455
|
+
}
|
|
1456
|
+
}
|
|
1457
|
+
},
|
|
1458
|
+
awaitingVerification: {
|
|
1459
|
+
on: {
|
|
1460
|
+
DIALOG_VERIFIED: {
|
|
1461
|
+
target: "completingSave",
|
|
1462
|
+
actions: [
|
|
1463
|
+
a({
|
|
1464
|
+
activeDialog: null,
|
|
1465
|
+
saveState: ({ context: e }) => ({
|
|
1466
|
+
...e.saveState,
|
|
1467
|
+
completedVerifications: [
|
|
1468
|
+
...e.saveState.completedVerifications,
|
|
1469
|
+
`${e.activeDialog?.templateMetadata?.componentId || "unknown"}`
|
|
1470
|
+
]
|
|
1471
|
+
})
|
|
1472
|
+
}),
|
|
1473
|
+
({ context: e, self: t }) => {
|
|
1474
|
+
e.saveState.pendingVerifications.length <= e.saveState.completedVerifications.length + 1 && t.send({
|
|
1475
|
+
type: "SAVE_ACTIONS_COMPLETE",
|
|
1476
|
+
sectionId: e.saveState.savingSection || "",
|
|
1477
|
+
results: {}
|
|
1478
|
+
});
|
|
1479
|
+
}
|
|
1480
|
+
]
|
|
1481
|
+
},
|
|
1482
|
+
DIALOG_CANCELLED: {
|
|
1483
|
+
target: "idle",
|
|
1484
|
+
actions: [
|
|
1485
|
+
a({
|
|
1486
|
+
activeDialog: null,
|
|
1487
|
+
saveState: ({ context: e }) => ({
|
|
1488
|
+
...e.saveState,
|
|
1489
|
+
saveInProgress: !1,
|
|
1490
|
+
saveInitiator: null,
|
|
1491
|
+
savingSection: null,
|
|
1492
|
+
pendingVerifications: [],
|
|
1493
|
+
completedVerifications: [],
|
|
1494
|
+
validationErrors: {},
|
|
1495
|
+
executionPlan: null
|
|
1496
|
+
})
|
|
1497
|
+
})
|
|
1498
|
+
]
|
|
1499
|
+
}
|
|
1500
|
+
}
|
|
1501
|
+
},
|
|
1502
|
+
completingSave: {
|
|
1503
|
+
entry: [],
|
|
1504
|
+
always: [
|
|
1505
|
+
{
|
|
1506
|
+
// Handle section mode transitions after successful save
|
|
1507
|
+
guard: _,
|
|
1508
|
+
target: "idle",
|
|
1509
|
+
actions: [
|
|
1510
|
+
a({
|
|
1511
|
+
saveState: ({ context: e }) => ({
|
|
1512
|
+
...e.saveState,
|
|
1513
|
+
saveInProgress: !1,
|
|
1514
|
+
saveInitiator: null,
|
|
1515
|
+
savingSection: null,
|
|
1516
|
+
pendingVerifications: [],
|
|
1517
|
+
completedVerifications: [],
|
|
1518
|
+
validationErrors: {},
|
|
1519
|
+
executionPlan: null
|
|
1520
|
+
})
|
|
1521
|
+
})
|
|
1522
|
+
]
|
|
1523
|
+
},
|
|
1524
|
+
{
|
|
1525
|
+
// Default completion
|
|
1526
|
+
target: "idle",
|
|
1527
|
+
actions: [
|
|
1528
|
+
a({
|
|
1529
|
+
saveState: ({ context: e }) => ({
|
|
1530
|
+
...e.saveState,
|
|
1531
|
+
saveInProgress: !1,
|
|
1532
|
+
saveInitiator: null,
|
|
1533
|
+
savingSection: null,
|
|
1534
|
+
pendingVerifications: [],
|
|
1535
|
+
completedVerifications: [],
|
|
1536
|
+
validationErrors: {},
|
|
1537
|
+
executionPlan: null
|
|
1538
|
+
})
|
|
1539
|
+
}),
|
|
1540
|
+
({ context: e, self: t }) => {
|
|
1541
|
+
if (e.saveState.saveInitiator === "navigation" && e.pendingNavigation)
|
|
1542
|
+
switch (e.pendingNavigation.type) {
|
|
1543
|
+
case "next":
|
|
1544
|
+
t.send({ type: "NEXT" });
|
|
1545
|
+
break;
|
|
1546
|
+
case "previous":
|
|
1547
|
+
t.send({ type: "PREVIOUS" });
|
|
1548
|
+
break;
|
|
1549
|
+
case "step":
|
|
1550
|
+
t.send({
|
|
1551
|
+
type: "GO_TO_STEP",
|
|
1552
|
+
stepId: e.pendingNavigation.stepId
|
|
1553
|
+
});
|
|
1554
|
+
break;
|
|
1555
|
+
}
|
|
1556
|
+
}
|
|
1557
|
+
]
|
|
1558
|
+
}
|
|
1559
|
+
]
|
|
1560
|
+
}
|
|
1561
|
+
}
|
|
1562
|
+
});
|
|
1563
|
+
export {
|
|
1564
|
+
W as formMachine
|
|
1565
|
+
};
|