wizzard-stepper-react 1.7.1 → 2.0.0
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/LICENSE +21 -21
- package/README.md +158 -431
- package/dist/index.cjs +1 -954
- package/dist/index.d.cts +309 -63
- package/dist/index.d.ts +309 -63
- package/dist/index.js +1 -921
- package/package.json +98 -93
- package/dist/index.cjs.map +0 -1
- package/dist/index.js.map +0 -1
package/dist/index.js
CHANGED
|
@@ -1,921 +1 @@
|
|
|
1
|
-
var __defProp = Object.defineProperty;
|
|
2
|
-
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
3
|
-
var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
|
|
4
|
-
|
|
5
|
-
// src/context/WizardContext.tsx
|
|
6
|
-
import {
|
|
7
|
-
createContext,
|
|
8
|
-
useContext,
|
|
9
|
-
useEffect,
|
|
10
|
-
useMemo,
|
|
11
|
-
useState,
|
|
12
|
-
useCallback,
|
|
13
|
-
useSyncExternalStore,
|
|
14
|
-
useRef,
|
|
15
|
-
useTransition
|
|
16
|
-
} from "react";
|
|
17
|
-
|
|
18
|
-
// src/adapters/persistence/MemoryAdapter.ts
|
|
19
|
-
var MemoryAdapter = class {
|
|
20
|
-
constructor() {
|
|
21
|
-
__publicField(this, "storage", {});
|
|
22
|
-
}
|
|
23
|
-
saveStep(stepId, data) {
|
|
24
|
-
this.storage[stepId] = data;
|
|
25
|
-
}
|
|
26
|
-
getStep(stepId) {
|
|
27
|
-
return this.storage[stepId];
|
|
28
|
-
}
|
|
29
|
-
clear() {
|
|
30
|
-
this.storage = {};
|
|
31
|
-
}
|
|
32
|
-
};
|
|
33
|
-
|
|
34
|
-
// src/utils/data.ts
|
|
35
|
-
var pathCache = /* @__PURE__ */ new Map();
|
|
36
|
-
function toPath(path) {
|
|
37
|
-
if (!path) return [];
|
|
38
|
-
if (pathCache.has(path)) {
|
|
39
|
-
return pathCache.get(path);
|
|
40
|
-
}
|
|
41
|
-
let keys;
|
|
42
|
-
if (path.includes("[")) {
|
|
43
|
-
keys = path.replace(/\[(\d+)\]/g, ".$1").split(".").filter(Boolean);
|
|
44
|
-
} else {
|
|
45
|
-
keys = path.split(".").filter(Boolean);
|
|
46
|
-
}
|
|
47
|
-
pathCache.set(path, keys);
|
|
48
|
-
return keys;
|
|
49
|
-
}
|
|
50
|
-
function getByPath(obj, path, defaultValue) {
|
|
51
|
-
if (!path || obj === void 0 || obj === null) return defaultValue ?? obj;
|
|
52
|
-
if (!path.includes(".") && !path.includes("[")) {
|
|
53
|
-
const val = obj[path];
|
|
54
|
-
return val !== void 0 ? val : defaultValue;
|
|
55
|
-
}
|
|
56
|
-
const keys = toPath(path);
|
|
57
|
-
let result = obj;
|
|
58
|
-
for (let i = 0; i < keys.length; i++) {
|
|
59
|
-
if (result === void 0 || result === null) return defaultValue;
|
|
60
|
-
result = result[keys[i]];
|
|
61
|
-
}
|
|
62
|
-
return result !== void 0 ? result : defaultValue;
|
|
63
|
-
}
|
|
64
|
-
function setByPath(obj, path, value) {
|
|
65
|
-
if (!path) return value;
|
|
66
|
-
if (!path.includes(".") && !path.includes("[")) {
|
|
67
|
-
if (Array.isArray(obj)) {
|
|
68
|
-
const copy = [...obj];
|
|
69
|
-
copy[path] = value;
|
|
70
|
-
return copy;
|
|
71
|
-
}
|
|
72
|
-
return { ...obj, [path]: value };
|
|
73
|
-
}
|
|
74
|
-
const keys = toPath(path);
|
|
75
|
-
if (keys.length === 0) return value;
|
|
76
|
-
const root = Array.isArray(obj) ? [...obj] : { ...obj };
|
|
77
|
-
let current = root;
|
|
78
|
-
for (let i = 0; i < keys.length - 1; i++) {
|
|
79
|
-
const key = keys[i];
|
|
80
|
-
const nextKey = keys[i + 1];
|
|
81
|
-
const existing = current[key];
|
|
82
|
-
let nextLevel;
|
|
83
|
-
if (existing && typeof existing === "object") {
|
|
84
|
-
nextLevel = Array.isArray(existing) ? [...existing] : { ...existing };
|
|
85
|
-
} else {
|
|
86
|
-
const isNumeric = /^\d+$/.test(nextKey);
|
|
87
|
-
nextLevel = isNumeric ? [] : {};
|
|
88
|
-
}
|
|
89
|
-
current[key] = nextLevel;
|
|
90
|
-
current = nextLevel;
|
|
91
|
-
}
|
|
92
|
-
const lastKey = keys[keys.length - 1];
|
|
93
|
-
current[lastKey] = value;
|
|
94
|
-
return root;
|
|
95
|
-
}
|
|
96
|
-
function shallowEqual(a, b) {
|
|
97
|
-
if (Object.is(a, b)) return true;
|
|
98
|
-
if (typeof a !== "object" || a === null || typeof b !== "object" || b === null) {
|
|
99
|
-
return false;
|
|
100
|
-
}
|
|
101
|
-
const keysA = Object.keys(a);
|
|
102
|
-
const keysB = Object.keys(b);
|
|
103
|
-
if (keysA.length !== keysB.length) return false;
|
|
104
|
-
for (let i = 0; i < keysA.length; i++) {
|
|
105
|
-
const key = keysA[i];
|
|
106
|
-
if (!Object.prototype.hasOwnProperty.call(b, key) || !Object.is(a[key], b[key])) {
|
|
107
|
-
return false;
|
|
108
|
-
}
|
|
109
|
-
}
|
|
110
|
-
return true;
|
|
111
|
-
}
|
|
112
|
-
|
|
113
|
-
// src/context/WizardContext.tsx
|
|
114
|
-
import { jsx } from "react/jsx-runtime";
|
|
115
|
-
var WizardStateContext = createContext(
|
|
116
|
-
void 0
|
|
117
|
-
);
|
|
118
|
-
var WizardActionsContext = createContext(
|
|
119
|
-
void 0
|
|
120
|
-
);
|
|
121
|
-
var WizardStore = class {
|
|
122
|
-
constructor(initialData) {
|
|
123
|
-
__publicField(this, "state");
|
|
124
|
-
__publicField(this, "listeners", /* @__PURE__ */ new Set());
|
|
125
|
-
__publicField(this, "errorsMap", /* @__PURE__ */ new Map());
|
|
126
|
-
__publicField(this, "subscribe", (listener) => {
|
|
127
|
-
this.listeners.add(listener);
|
|
128
|
-
return () => this.listeners.delete(listener);
|
|
129
|
-
});
|
|
130
|
-
this.state = {
|
|
131
|
-
data: initialData,
|
|
132
|
-
errors: {}
|
|
133
|
-
};
|
|
134
|
-
}
|
|
135
|
-
getSnapshot() {
|
|
136
|
-
return this.state;
|
|
137
|
-
}
|
|
138
|
-
update(newData) {
|
|
139
|
-
this.state = { ...this.state, data: newData };
|
|
140
|
-
this.notify();
|
|
141
|
-
}
|
|
142
|
-
// Sync internal Map to external Object (for backward compat)
|
|
143
|
-
syncErrors() {
|
|
144
|
-
const newErrorsObj = {};
|
|
145
|
-
for (const [stepId, fieldErrors] of this.errorsMap.entries()) {
|
|
146
|
-
if (fieldErrors.size > 0) {
|
|
147
|
-
newErrorsObj[stepId] = Object.fromEntries(fieldErrors);
|
|
148
|
-
}
|
|
149
|
-
}
|
|
150
|
-
this.state = { ...this.state, errors: newErrorsObj };
|
|
151
|
-
this.notify();
|
|
152
|
-
}
|
|
153
|
-
// Update from Object (Legacy/State setter)
|
|
154
|
-
updateErrors(newErrors) {
|
|
155
|
-
this.errorsMap.clear();
|
|
156
|
-
for (const [stepId, fieldErrors] of Object.entries(newErrors)) {
|
|
157
|
-
const stepMap = /* @__PURE__ */ new Map();
|
|
158
|
-
for (const [field, msg] of Object.entries(fieldErrors)) {
|
|
159
|
-
stepMap.set(field, msg);
|
|
160
|
-
}
|
|
161
|
-
if (stepMap.size > 0) this.errorsMap.set(stepId, stepMap);
|
|
162
|
-
}
|
|
163
|
-
this.state = { ...this.state, errors: newErrors };
|
|
164
|
-
this.notify();
|
|
165
|
-
}
|
|
166
|
-
// Optimize: Update Step Errors directly (O(1) Map updated, then Sync)
|
|
167
|
-
setStepErrors(stepId, errors) {
|
|
168
|
-
if (!errors || Object.keys(errors).length === 0) {
|
|
169
|
-
if (this.errorsMap.has(stepId)) {
|
|
170
|
-
this.errorsMap.delete(stepId);
|
|
171
|
-
this.syncErrors();
|
|
172
|
-
return true;
|
|
173
|
-
}
|
|
174
|
-
return false;
|
|
175
|
-
}
|
|
176
|
-
const stepMap = /* @__PURE__ */ new Map();
|
|
177
|
-
for (const [field, msg] of Object.entries(errors)) {
|
|
178
|
-
stepMap.set(field, msg);
|
|
179
|
-
}
|
|
180
|
-
this.errorsMap.set(stepId, stepMap);
|
|
181
|
-
this.syncErrors();
|
|
182
|
-
return true;
|
|
183
|
-
}
|
|
184
|
-
// Fast Delete (O(1))
|
|
185
|
-
deleteError(stepId, path) {
|
|
186
|
-
const stepErrors = this.errorsMap.get(stepId);
|
|
187
|
-
if (!stepErrors) return false;
|
|
188
|
-
if (stepErrors.has(path)) {
|
|
189
|
-
stepErrors.delete(path);
|
|
190
|
-
if (stepErrors.size === 0) {
|
|
191
|
-
this.errorsMap.delete(stepId);
|
|
192
|
-
}
|
|
193
|
-
this.syncErrors();
|
|
194
|
-
return true;
|
|
195
|
-
}
|
|
196
|
-
return false;
|
|
197
|
-
}
|
|
198
|
-
notify() {
|
|
199
|
-
this.listeners.forEach((l) => l());
|
|
200
|
-
}
|
|
201
|
-
};
|
|
202
|
-
function WizardProvider({
|
|
203
|
-
config,
|
|
204
|
-
initialData,
|
|
205
|
-
initialStepId,
|
|
206
|
-
children
|
|
207
|
-
}) {
|
|
208
|
-
const [currentStepId, setCurrentStepId] = useState("");
|
|
209
|
-
const currentStepIdRef = useRef(currentStepId);
|
|
210
|
-
useEffect(() => {
|
|
211
|
-
currentStepIdRef.current = currentStepId;
|
|
212
|
-
}, [currentStepId]);
|
|
213
|
-
const [visitedSteps, setVisitedSteps] = useState(/* @__PURE__ */ new Set());
|
|
214
|
-
const [completedSteps, setCompletedSteps] = useState(/* @__PURE__ */ new Set());
|
|
215
|
-
const [errorSteps, setErrorSteps] = useState(/* @__PURE__ */ new Set());
|
|
216
|
-
const [, setAllErrorsState] = useState({});
|
|
217
|
-
const [isLoading, setIsLoading] = useState(true);
|
|
218
|
-
const [isPending, startTransition] = useTransition();
|
|
219
|
-
const storeRef = useRef(new WizardStore(initialData || {}));
|
|
220
|
-
const persistenceAdapter = useMemo(() => {
|
|
221
|
-
return config.persistence?.adapter || new MemoryAdapter();
|
|
222
|
-
}, [config.persistence?.adapter]);
|
|
223
|
-
const persistenceMode = config.persistence?.mode || "onStepChange";
|
|
224
|
-
const stepsMap = useMemo(() => {
|
|
225
|
-
const map = /* @__PURE__ */ new Map();
|
|
226
|
-
config.steps.forEach((step) => map.set(step.id, step));
|
|
227
|
-
return map;
|
|
228
|
-
}, [config.steps]);
|
|
229
|
-
const lastActiveStepsRef = useRef([]);
|
|
230
|
-
const activeSteps = useSyncExternalStore(
|
|
231
|
-
storeRef.current.subscribe,
|
|
232
|
-
useCallback(() => {
|
|
233
|
-
const currentData = storeRef.current.getSnapshot().data;
|
|
234
|
-
const nextActiveSteps = config.steps.filter((step) => {
|
|
235
|
-
if (step.condition) {
|
|
236
|
-
return step.condition(currentData);
|
|
237
|
-
}
|
|
238
|
-
return true;
|
|
239
|
-
});
|
|
240
|
-
const prevIds = lastActiveStepsRef.current.map((s) => s.id).join(".");
|
|
241
|
-
const nextIds = nextActiveSteps.map((s) => s.id).join(".");
|
|
242
|
-
if (prevIds === nextIds && lastActiveStepsRef.current.length > 0) {
|
|
243
|
-
return lastActiveStepsRef.current;
|
|
244
|
-
}
|
|
245
|
-
lastActiveStepsRef.current = nextActiveSteps;
|
|
246
|
-
return nextActiveSteps;
|
|
247
|
-
}, [config.steps])
|
|
248
|
-
);
|
|
249
|
-
const activeStepsIndexMap = useMemo(() => {
|
|
250
|
-
const map = /* @__PURE__ */ new Map();
|
|
251
|
-
activeSteps.forEach((s, i) => map.set(s.id, i));
|
|
252
|
-
return map;
|
|
253
|
-
}, [activeSteps]);
|
|
254
|
-
useEffect(() => {
|
|
255
|
-
if (!currentStepId && activeSteps.length > 0) {
|
|
256
|
-
if (initialStepId) {
|
|
257
|
-
const target = activeSteps.find((s) => s.id === initialStepId);
|
|
258
|
-
if (target) {
|
|
259
|
-
setCurrentStepId(target.id);
|
|
260
|
-
} else {
|
|
261
|
-
setCurrentStepId(activeSteps[0].id);
|
|
262
|
-
}
|
|
263
|
-
} else {
|
|
264
|
-
setCurrentStepId(activeSteps[0].id);
|
|
265
|
-
}
|
|
266
|
-
setIsLoading(false);
|
|
267
|
-
}
|
|
268
|
-
}, [activeSteps, currentStepId, initialStepId]);
|
|
269
|
-
const stateRef = useRef({
|
|
270
|
-
config,
|
|
271
|
-
stepsMap,
|
|
272
|
-
activeSteps,
|
|
273
|
-
activeStepsIndexMap,
|
|
274
|
-
visitedSteps,
|
|
275
|
-
completedSteps,
|
|
276
|
-
persistenceMode,
|
|
277
|
-
persistenceAdapter,
|
|
278
|
-
currentStepId
|
|
279
|
-
});
|
|
280
|
-
stateRef.current = {
|
|
281
|
-
config,
|
|
282
|
-
stepsMap,
|
|
283
|
-
activeSteps,
|
|
284
|
-
activeStepsIndexMap,
|
|
285
|
-
visitedSteps,
|
|
286
|
-
completedSteps,
|
|
287
|
-
persistenceMode,
|
|
288
|
-
persistenceAdapter,
|
|
289
|
-
currentStepId
|
|
290
|
-
};
|
|
291
|
-
const currentStep = useMemo(
|
|
292
|
-
() => stepsMap.get(currentStepId) || null,
|
|
293
|
-
[stepsMap, currentStepId]
|
|
294
|
-
);
|
|
295
|
-
const currentStepIndex = useMemo(
|
|
296
|
-
() => activeStepsIndexMap.get(currentStepId) ?? -1,
|
|
297
|
-
[activeStepsIndexMap, currentStepId]
|
|
298
|
-
);
|
|
299
|
-
const isFirstStep = currentStepIndex === 0;
|
|
300
|
-
const isLastStep = currentStepIndex === activeSteps.length - 1;
|
|
301
|
-
const META_KEY = "__wizzard_meta__";
|
|
302
|
-
const hydrate = useCallback(() => {
|
|
303
|
-
setIsLoading(true);
|
|
304
|
-
const { persistenceAdapter: persistenceAdapter2, config: config2 } = stateRef.current;
|
|
305
|
-
const metaFn = persistenceAdapter2.getStep(META_KEY);
|
|
306
|
-
if (metaFn) {
|
|
307
|
-
if (metaFn.currentStepId) setCurrentStepId(metaFn.currentStepId);
|
|
308
|
-
if (metaFn.visited) setVisitedSteps(new Set(metaFn.visited));
|
|
309
|
-
if (metaFn.completed) setCompletedSteps(new Set(metaFn.completed));
|
|
310
|
-
}
|
|
311
|
-
const loadedData = {};
|
|
312
|
-
config2.steps.forEach((step) => {
|
|
313
|
-
const stepData = persistenceAdapter2.getStep(step.id);
|
|
314
|
-
if (stepData) {
|
|
315
|
-
Object.assign(loadedData, stepData);
|
|
316
|
-
}
|
|
317
|
-
});
|
|
318
|
-
if (Object.keys(loadedData).length > 0) {
|
|
319
|
-
const currentData = storeRef.current.getSnapshot().data;
|
|
320
|
-
const newData = { ...currentData, ...loadedData };
|
|
321
|
-
storeRef.current.update(newData);
|
|
322
|
-
}
|
|
323
|
-
setIsLoading(false);
|
|
324
|
-
}, []);
|
|
325
|
-
useEffect(() => {
|
|
326
|
-
hydrate();
|
|
327
|
-
}, [hydrate]);
|
|
328
|
-
const saveData = useCallback(
|
|
329
|
-
(mode, stepId, data) => {
|
|
330
|
-
const { stepsMap: stepsMap2, persistenceAdapter: persistenceAdapter2, persistenceMode: globalMode } = stateRef.current;
|
|
331
|
-
const stepConfig = stepsMap2.get(stepId);
|
|
332
|
-
const stepAdapter = stepConfig?.persistenceAdapter;
|
|
333
|
-
const stepMode = stepConfig?.persistenceMode;
|
|
334
|
-
const adapterToUse = stepAdapter || persistenceAdapter2;
|
|
335
|
-
const modeToUse = stepMode || globalMode;
|
|
336
|
-
if (mode === modeToUse || mode === "manual") {
|
|
337
|
-
adapterToUse.saveStep(stepId, data);
|
|
338
|
-
}
|
|
339
|
-
},
|
|
340
|
-
[]
|
|
341
|
-
);
|
|
342
|
-
const validationTimeoutRef = useRef(
|
|
343
|
-
null
|
|
344
|
-
);
|
|
345
|
-
const validateStep = useCallback(
|
|
346
|
-
async (stepId, data) => {
|
|
347
|
-
const { stepsMap: stepsMap2 } = stateRef.current;
|
|
348
|
-
const step = stepsMap2.get(stepId);
|
|
349
|
-
if (!step || !step.validationAdapter) {
|
|
350
|
-
return true;
|
|
351
|
-
}
|
|
352
|
-
const result = await step.validationAdapter.validate(data);
|
|
353
|
-
if (result.isValid) {
|
|
354
|
-
const changed = storeRef.current.setStepErrors(stepId, null);
|
|
355
|
-
if (changed) {
|
|
356
|
-
setAllErrorsState(storeRef.current.getSnapshot().errors);
|
|
357
|
-
setErrorSteps((prev) => {
|
|
358
|
-
const next = new Set(prev);
|
|
359
|
-
next.delete(stepId);
|
|
360
|
-
return next;
|
|
361
|
-
});
|
|
362
|
-
}
|
|
363
|
-
return true;
|
|
364
|
-
} else {
|
|
365
|
-
storeRef.current.setStepErrors(stepId, result.errors || null);
|
|
366
|
-
setAllErrorsState(storeRef.current.getSnapshot().errors);
|
|
367
|
-
setErrorSteps((prev) => {
|
|
368
|
-
const next = new Set(prev);
|
|
369
|
-
next.add(stepId);
|
|
370
|
-
return next;
|
|
371
|
-
});
|
|
372
|
-
return false;
|
|
373
|
-
}
|
|
374
|
-
},
|
|
375
|
-
[]
|
|
376
|
-
);
|
|
377
|
-
const setStepData = useCallback(
|
|
378
|
-
(stepId, data) => {
|
|
379
|
-
const { persistenceMode: persistenceMode2 } = stateRef.current;
|
|
380
|
-
const prevData = storeRef.current.getSnapshot().data;
|
|
381
|
-
const newData = { ...prevData, ...data };
|
|
382
|
-
storeRef.current.update(newData);
|
|
383
|
-
const stepConfig = stateRef.current.stepsMap.get(stepId);
|
|
384
|
-
const effectiveMode = stepConfig?.persistenceMode || persistenceMode2;
|
|
385
|
-
if (effectiveMode === "onChange") {
|
|
386
|
-
saveData("onChange", stepId, newData);
|
|
387
|
-
}
|
|
388
|
-
},
|
|
389
|
-
[saveData]
|
|
390
|
-
);
|
|
391
|
-
const setData = useCallback(
|
|
392
|
-
(path, value, options) => {
|
|
393
|
-
const { persistenceMode: persistenceMode2, stepsMap: stepsMap2 } = stateRef.current;
|
|
394
|
-
const prevData = storeRef.current.getSnapshot().data;
|
|
395
|
-
const currentValue = getByPath(prevData, path);
|
|
396
|
-
if (currentValue === value) return;
|
|
397
|
-
const newData = setByPath(prevData, path, value);
|
|
398
|
-
storeRef.current.update(newData);
|
|
399
|
-
const activeStepId = stateRef.current.currentStepId;
|
|
400
|
-
const stepConfig = stepsMap2.get(activeStepId);
|
|
401
|
-
if (activeStepId) {
|
|
402
|
-
const wasDeleted = storeRef.current.deleteError(activeStepId, path);
|
|
403
|
-
if (wasDeleted) {
|
|
404
|
-
if (!storeRef.current.errorsMap.has(activeStepId)) {
|
|
405
|
-
setErrorSteps((prev) => {
|
|
406
|
-
const next = new Set(prev);
|
|
407
|
-
next.delete(activeStepId);
|
|
408
|
-
return next;
|
|
409
|
-
});
|
|
410
|
-
}
|
|
411
|
-
}
|
|
412
|
-
}
|
|
413
|
-
if (activeStepId && storeRef.current.getSnapshot().errors[activeStepId]) {
|
|
414
|
-
startTransition(() => {
|
|
415
|
-
setAllErrorsState(storeRef.current.getSnapshot().errors);
|
|
416
|
-
});
|
|
417
|
-
}
|
|
418
|
-
const { config: config2 } = stateRef.current;
|
|
419
|
-
const mode = stepConfig?.validationMode ?? config2.validationMode ?? "onStepChange";
|
|
420
|
-
if (mode === "onChange") {
|
|
421
|
-
if (options?.debounceValidation) {
|
|
422
|
-
if (validationTimeoutRef.current)
|
|
423
|
-
clearTimeout(validationTimeoutRef.current);
|
|
424
|
-
validationTimeoutRef.current = setTimeout(() => {
|
|
425
|
-
try {
|
|
426
|
-
if (activeStepId) {
|
|
427
|
-
validateStep(activeStepId, newData).catch((err) => {
|
|
428
|
-
console.error("[Wizard] Debounced validation failed:", err);
|
|
429
|
-
});
|
|
430
|
-
}
|
|
431
|
-
} catch (e) {
|
|
432
|
-
console.error("[Wizard] Error starting validation:", e);
|
|
433
|
-
}
|
|
434
|
-
}, options.debounceValidation);
|
|
435
|
-
} else {
|
|
436
|
-
if (activeStepId) validateStep(activeStepId, newData);
|
|
437
|
-
}
|
|
438
|
-
}
|
|
439
|
-
const effectivePersistenceMode = stepConfig?.persistenceMode ?? persistenceMode2;
|
|
440
|
-
if (effectivePersistenceMode === "onChange" && activeStepId) {
|
|
441
|
-
saveData("onChange", activeStepId, newData);
|
|
442
|
-
}
|
|
443
|
-
},
|
|
444
|
-
[saveData, validateStep]
|
|
445
|
-
);
|
|
446
|
-
const updateData = useCallback(
|
|
447
|
-
(data, options) => {
|
|
448
|
-
const { config: config2 } = stateRef.current;
|
|
449
|
-
const prevData = storeRef.current.getSnapshot().data;
|
|
450
|
-
const newData = options?.replace ? data : { ...prevData, ...data };
|
|
451
|
-
storeRef.current.update(newData);
|
|
452
|
-
if (options?.persist) {
|
|
453
|
-
config2.steps.forEach((step) => {
|
|
454
|
-
saveData("manual", step.id, newData);
|
|
455
|
-
});
|
|
456
|
-
}
|
|
457
|
-
},
|
|
458
|
-
[saveData]
|
|
459
|
-
);
|
|
460
|
-
const getData = useCallback((path, defaultValue) => {
|
|
461
|
-
return getByPath(storeRef.current.getSnapshot().data, path, defaultValue);
|
|
462
|
-
}, []);
|
|
463
|
-
const handleStepChange = useCallback(
|
|
464
|
-
(field, value) => {
|
|
465
|
-
const { currentStepId: currentStepId2 } = stateRef.current;
|
|
466
|
-
if (!currentStepId2) return;
|
|
467
|
-
setData(field, value);
|
|
468
|
-
},
|
|
469
|
-
[setData]
|
|
470
|
-
);
|
|
471
|
-
const validateAll = useCallback(async () => {
|
|
472
|
-
const { activeSteps: activeSteps2 } = stateRef.current;
|
|
473
|
-
const currentData = storeRef.current.getSnapshot().data;
|
|
474
|
-
const validationResults = await Promise.all(
|
|
475
|
-
activeSteps2.map((step) => validateStep(step.id, currentData))
|
|
476
|
-
);
|
|
477
|
-
const isValid = validationResults.every(Boolean);
|
|
478
|
-
const finalErrors = storeRef.current.getSnapshot().errors;
|
|
479
|
-
return { isValid, errors: finalErrors };
|
|
480
|
-
}, [validateStep]);
|
|
481
|
-
const goToStep = useCallback(
|
|
482
|
-
async (stepId) => {
|
|
483
|
-
const {
|
|
484
|
-
activeStepsIndexMap: activeStepsIndexMap2,
|
|
485
|
-
currentStepId: currentStepId2,
|
|
486
|
-
config: config2,
|
|
487
|
-
persistenceMode: persistenceMode2,
|
|
488
|
-
visitedSteps: visitedSteps2,
|
|
489
|
-
completedSteps: completedSteps2,
|
|
490
|
-
persistenceAdapter: persistenceAdapter2,
|
|
491
|
-
stepsMap: stepsMap2
|
|
492
|
-
} = stateRef.current;
|
|
493
|
-
const targetIndex = activeStepsIndexMap2.get(stepId) ?? -1;
|
|
494
|
-
if (targetIndex === -1) return false;
|
|
495
|
-
const currentData = storeRef.current.getSnapshot().data;
|
|
496
|
-
const currentStepIndex2 = activeStepsIndexMap2.get(currentStepId2) ?? -1;
|
|
497
|
-
const currentStep2 = stepsMap2.get(currentStepId2);
|
|
498
|
-
if (targetIndex > currentStepIndex2) {
|
|
499
|
-
const shouldValidate = currentStep2?.autoValidate ?? config2.autoValidate ?? false;
|
|
500
|
-
if (shouldValidate && currentStepId2) {
|
|
501
|
-
const isValid = await validateStep(currentStepId2, currentData);
|
|
502
|
-
if (!isValid) return false;
|
|
503
|
-
}
|
|
504
|
-
}
|
|
505
|
-
if (currentStep2 && currentStepId2) {
|
|
506
|
-
const effectivePersistenceMode = currentStep2.persistenceMode ?? persistenceMode2;
|
|
507
|
-
if (effectivePersistenceMode === "onStepChange") {
|
|
508
|
-
saveData("onStepChange", currentStepId2, currentData);
|
|
509
|
-
}
|
|
510
|
-
}
|
|
511
|
-
const nextVisited = new Set(visitedSteps2);
|
|
512
|
-
if (currentStepId2) nextVisited.add(currentStepId2);
|
|
513
|
-
setVisitedSteps(nextVisited);
|
|
514
|
-
setCurrentStepId(stepId);
|
|
515
|
-
if (persistenceMode2 !== "manual") {
|
|
516
|
-
persistenceAdapter2.saveStep(META_KEY, {
|
|
517
|
-
currentStepId: stepId,
|
|
518
|
-
visited: Array.from(nextVisited),
|
|
519
|
-
completed: Array.from(completedSteps2)
|
|
520
|
-
});
|
|
521
|
-
}
|
|
522
|
-
if (config2.onStepChange) {
|
|
523
|
-
config2.onStepChange(currentStepId2 || null, stepId, currentData);
|
|
524
|
-
}
|
|
525
|
-
window.scrollTo(0, 0);
|
|
526
|
-
return true;
|
|
527
|
-
},
|
|
528
|
-
[saveData, validateStep]
|
|
529
|
-
);
|
|
530
|
-
const goToNextStep = useCallback(async () => {
|
|
531
|
-
const { activeSteps: activeSteps2, activeStepsIndexMap: activeStepsIndexMap2, currentStepId: currentStepId2, completedSteps: completedSteps2, persistenceMode: persistenceMode2 } = stateRef.current;
|
|
532
|
-
const currentStepIndex2 = activeStepsIndexMap2.get(currentStepId2) ?? -1;
|
|
533
|
-
if (currentStepIndex2 === -1 || currentStepIndex2 === activeSteps2.length - 1) return;
|
|
534
|
-
const nextStep = activeSteps2[currentStepIndex2 + 1];
|
|
535
|
-
if (nextStep) {
|
|
536
|
-
const success = await goToStep(nextStep.id);
|
|
537
|
-
if (success) {
|
|
538
|
-
const nextCompleted = new Set(completedSteps2).add(currentStepId2);
|
|
539
|
-
setCompletedSteps(nextCompleted);
|
|
540
|
-
if (persistenceMode2 !== "manual") {
|
|
541
|
-
persistenceAdapter.saveStep(META_KEY, {
|
|
542
|
-
currentStepId: nextStep.id,
|
|
543
|
-
visited: Array.from(new Set(visitedSteps).add(currentStepId2)),
|
|
544
|
-
completed: Array.from(nextCompleted)
|
|
545
|
-
});
|
|
546
|
-
}
|
|
547
|
-
}
|
|
548
|
-
}
|
|
549
|
-
}, [goToStep]);
|
|
550
|
-
const goToPrevStep = useCallback(() => {
|
|
551
|
-
const { activeSteps: activeSteps2, activeStepsIndexMap: activeStepsIndexMap2, currentStepId: currentStepId2 } = stateRef.current;
|
|
552
|
-
const currentStepIndex2 = activeStepsIndexMap2.get(currentStepId2) ?? -1;
|
|
553
|
-
if (currentStepIndex2 <= 0) return;
|
|
554
|
-
const prevStep = activeSteps2[currentStepIndex2 - 1];
|
|
555
|
-
if (prevStep) {
|
|
556
|
-
goToStep(prevStep.id);
|
|
557
|
-
}
|
|
558
|
-
}, [goToStep]);
|
|
559
|
-
const clearStorage = useCallback(() => {
|
|
560
|
-
stateRef.current.persistenceAdapter.clear();
|
|
561
|
-
}, []);
|
|
562
|
-
const save = useCallback(
|
|
563
|
-
(stepIds) => {
|
|
564
|
-
const { config: config2, currentStepId: currentStepId2 } = stateRef.current;
|
|
565
|
-
const data = storeRef.current.getSnapshot().data;
|
|
566
|
-
if (stepIds === true) {
|
|
567
|
-
config2.steps.forEach((step) => {
|
|
568
|
-
saveData("manual", step.id, data);
|
|
569
|
-
});
|
|
570
|
-
return;
|
|
571
|
-
}
|
|
572
|
-
if (!stepIds) {
|
|
573
|
-
if (currentStepId2) {
|
|
574
|
-
saveData("manual", currentStepId2, data);
|
|
575
|
-
}
|
|
576
|
-
return;
|
|
577
|
-
}
|
|
578
|
-
const ids = Array.isArray(stepIds) ? stepIds : [stepIds];
|
|
579
|
-
ids.forEach((id) => {
|
|
580
|
-
saveData("manual", id, data);
|
|
581
|
-
});
|
|
582
|
-
},
|
|
583
|
-
[saveData]
|
|
584
|
-
);
|
|
585
|
-
const stateValue = useMemo(
|
|
586
|
-
() => ({
|
|
587
|
-
currentStep,
|
|
588
|
-
currentStepIndex,
|
|
589
|
-
isFirstStep,
|
|
590
|
-
isLastStep,
|
|
591
|
-
isLoading,
|
|
592
|
-
isPending,
|
|
593
|
-
activeSteps,
|
|
594
|
-
visitedSteps,
|
|
595
|
-
completedSteps,
|
|
596
|
-
errorSteps,
|
|
597
|
-
store: storeRef.current
|
|
598
|
-
}),
|
|
599
|
-
[
|
|
600
|
-
currentStep,
|
|
601
|
-
currentStepIndex,
|
|
602
|
-
isFirstStep,
|
|
603
|
-
isLastStep,
|
|
604
|
-
isLoading,
|
|
605
|
-
isPending,
|
|
606
|
-
activeSteps,
|
|
607
|
-
visitedSteps,
|
|
608
|
-
completedSteps,
|
|
609
|
-
errorSteps
|
|
610
|
-
]
|
|
611
|
-
);
|
|
612
|
-
const actionsValue = useMemo(
|
|
613
|
-
() => ({
|
|
614
|
-
goToNextStep,
|
|
615
|
-
goToPrevStep,
|
|
616
|
-
goToStep,
|
|
617
|
-
setStepData,
|
|
618
|
-
handleStepChange,
|
|
619
|
-
validateStep: (sid) => validateStep(sid, storeRef.current.getSnapshot().data),
|
|
620
|
-
validateAll,
|
|
621
|
-
save,
|
|
622
|
-
clearStorage,
|
|
623
|
-
setData,
|
|
624
|
-
updateData,
|
|
625
|
-
getData
|
|
626
|
-
}),
|
|
627
|
-
[
|
|
628
|
-
goToNextStep,
|
|
629
|
-
goToPrevStep,
|
|
630
|
-
goToStep,
|
|
631
|
-
setStepData,
|
|
632
|
-
handleStepChange,
|
|
633
|
-
validateStep,
|
|
634
|
-
validateAll,
|
|
635
|
-
save,
|
|
636
|
-
clearStorage,
|
|
637
|
-
setData,
|
|
638
|
-
updateData,
|
|
639
|
-
getData
|
|
640
|
-
]
|
|
641
|
-
);
|
|
642
|
-
return /* @__PURE__ */ jsx(WizardStateContext.Provider, { value: stateValue, children: /* @__PURE__ */ jsx(WizardActionsContext.Provider, { value: actionsValue, children }) });
|
|
643
|
-
}
|
|
644
|
-
function useWizardState() {
|
|
645
|
-
const context = useContext(WizardStateContext);
|
|
646
|
-
if (!context) {
|
|
647
|
-
throw new Error("useWizardState must be used within a WizardProvider");
|
|
648
|
-
}
|
|
649
|
-
return context;
|
|
650
|
-
}
|
|
651
|
-
function useWizardValue(path, options) {
|
|
652
|
-
const { store } = useWizardState();
|
|
653
|
-
const lastStateRef = useRef(null);
|
|
654
|
-
const lastValueRef = useRef(null);
|
|
655
|
-
const isEqual = options?.isEqual || Object.is;
|
|
656
|
-
const getSnapshot = useCallback(() => {
|
|
657
|
-
const fullState = store.getSnapshot();
|
|
658
|
-
const data = fullState.data;
|
|
659
|
-
if (data === lastStateRef.current) {
|
|
660
|
-
return lastValueRef.current;
|
|
661
|
-
}
|
|
662
|
-
const value = getByPath(data, path);
|
|
663
|
-
if (lastValueRef.current !== void 0 && isEqual(lastValueRef.current, value)) {
|
|
664
|
-
lastStateRef.current = data;
|
|
665
|
-
return lastValueRef.current;
|
|
666
|
-
}
|
|
667
|
-
lastStateRef.current = data;
|
|
668
|
-
lastValueRef.current = value;
|
|
669
|
-
return value;
|
|
670
|
-
}, [store, path, isEqual]);
|
|
671
|
-
return useSyncExternalStore(store.subscribe, getSnapshot);
|
|
672
|
-
}
|
|
673
|
-
function useWizardError(path) {
|
|
674
|
-
const { store } = useWizardState();
|
|
675
|
-
const lastStateRef = useRef(null);
|
|
676
|
-
const lastValueRef = useRef(null);
|
|
677
|
-
const getSnapshot = useCallback(() => {
|
|
678
|
-
const fullState = store.getSnapshot();
|
|
679
|
-
const errors = fullState.errors;
|
|
680
|
-
if (errors === lastStateRef.current) {
|
|
681
|
-
return lastValueRef.current;
|
|
682
|
-
}
|
|
683
|
-
let foundError;
|
|
684
|
-
Object.values(errors).forEach((stepErrors) => {
|
|
685
|
-
const typedStepErrors = stepErrors;
|
|
686
|
-
if (typedStepErrors[path]) foundError = typedStepErrors[path];
|
|
687
|
-
});
|
|
688
|
-
lastStateRef.current = errors;
|
|
689
|
-
lastValueRef.current = foundError;
|
|
690
|
-
return foundError;
|
|
691
|
-
}, [store, path]);
|
|
692
|
-
return useSyncExternalStore(store.subscribe, getSnapshot);
|
|
693
|
-
}
|
|
694
|
-
function useWizardSelector(selector, options) {
|
|
695
|
-
const { store } = useWizardState();
|
|
696
|
-
const lastStateRef = useRef(null);
|
|
697
|
-
const lastResultRef = useRef(null);
|
|
698
|
-
const isEqual = options?.isEqual || Object.is;
|
|
699
|
-
const getSnapshot = useCallback(() => {
|
|
700
|
-
const fullState = store.getSnapshot();
|
|
701
|
-
if (fullState === lastStateRef.current) {
|
|
702
|
-
return lastResultRef.current;
|
|
703
|
-
}
|
|
704
|
-
const result = selector(fullState.data);
|
|
705
|
-
if (lastResultRef.current !== null && isEqual(lastResultRef.current, result)) {
|
|
706
|
-
lastStateRef.current = fullState;
|
|
707
|
-
return lastResultRef.current;
|
|
708
|
-
}
|
|
709
|
-
lastStateRef.current = fullState;
|
|
710
|
-
lastResultRef.current = result;
|
|
711
|
-
return result;
|
|
712
|
-
}, [store, selector, isEqual]);
|
|
713
|
-
return useSyncExternalStore(store.subscribe, getSnapshot);
|
|
714
|
-
}
|
|
715
|
-
function useWizardActions() {
|
|
716
|
-
const context = useContext(WizardActionsContext);
|
|
717
|
-
if (!context) {
|
|
718
|
-
throw new Error("useWizardActions must be used within a WizardProvider");
|
|
719
|
-
}
|
|
720
|
-
return context;
|
|
721
|
-
}
|
|
722
|
-
function useWizardContext() {
|
|
723
|
-
const state = useWizardState();
|
|
724
|
-
const actions = useWizardActions();
|
|
725
|
-
const wizardData = useWizardSelector((s) => s);
|
|
726
|
-
const allErrors = useSyncExternalStore(state.store.subscribe, () => state.store.getSnapshot().errors);
|
|
727
|
-
return useMemo(
|
|
728
|
-
() => ({
|
|
729
|
-
...state,
|
|
730
|
-
...actions,
|
|
731
|
-
wizardData,
|
|
732
|
-
allErrors
|
|
733
|
-
}),
|
|
734
|
-
[state, actions, wizardData, allErrors]
|
|
735
|
-
);
|
|
736
|
-
}
|
|
737
|
-
|
|
738
|
-
// src/components/WizardStepRenderer.tsx
|
|
739
|
-
import { useMemo as useMemo2 } from "react";
|
|
740
|
-
import { jsx as jsx2 } from "react/jsx-runtime";
|
|
741
|
-
var WizardStepRenderer = ({
|
|
742
|
-
wrapper: Wrapper
|
|
743
|
-
}) => {
|
|
744
|
-
const { currentStep } = useWizardContext();
|
|
745
|
-
const StepComponent = useMemo2(() => {
|
|
746
|
-
if (!currentStep?.component) return null;
|
|
747
|
-
return currentStep.component;
|
|
748
|
-
}, [currentStep]);
|
|
749
|
-
if (!currentStep || !StepComponent) {
|
|
750
|
-
return null;
|
|
751
|
-
}
|
|
752
|
-
const content = /* @__PURE__ */ jsx2(StepComponent, {});
|
|
753
|
-
if (Wrapper) {
|
|
754
|
-
return /* @__PURE__ */ jsx2(Wrapper, { children: content }, currentStep.id);
|
|
755
|
-
}
|
|
756
|
-
return content;
|
|
757
|
-
};
|
|
758
|
-
|
|
759
|
-
// src/hooks/useWizard.ts
|
|
760
|
-
var useWizard = () => {
|
|
761
|
-
return useWizardContext();
|
|
762
|
-
};
|
|
763
|
-
|
|
764
|
-
// src/factory.tsx
|
|
765
|
-
import { jsx as jsx3 } from "react/jsx-runtime";
|
|
766
|
-
function createWizardFactory() {
|
|
767
|
-
const WizardProvider2 = ({
|
|
768
|
-
config,
|
|
769
|
-
initialData,
|
|
770
|
-
children
|
|
771
|
-
}) => {
|
|
772
|
-
return /* @__PURE__ */ jsx3(
|
|
773
|
-
WizardProvider,
|
|
774
|
-
{
|
|
775
|
-
config,
|
|
776
|
-
initialData,
|
|
777
|
-
children
|
|
778
|
-
}
|
|
779
|
-
);
|
|
780
|
-
};
|
|
781
|
-
const useWizard2 = () => {
|
|
782
|
-
return useWizard();
|
|
783
|
-
};
|
|
784
|
-
const useWizardContext2 = () => {
|
|
785
|
-
return useWizardContext();
|
|
786
|
-
};
|
|
787
|
-
const useWizardValue2 = (path, options) => {
|
|
788
|
-
return useWizardValue(path, options);
|
|
789
|
-
};
|
|
790
|
-
const useWizardSelector2 = (selector, options) => {
|
|
791
|
-
return useWizardSelector(selector, options);
|
|
792
|
-
};
|
|
793
|
-
const useWizardError2 = (path) => {
|
|
794
|
-
return useWizardError(path);
|
|
795
|
-
};
|
|
796
|
-
const useWizardActions2 = () => {
|
|
797
|
-
return useWizardActions();
|
|
798
|
-
};
|
|
799
|
-
const useWizardState2 = () => {
|
|
800
|
-
return useWizardState();
|
|
801
|
-
};
|
|
802
|
-
const createStep = (config) => config;
|
|
803
|
-
return {
|
|
804
|
-
WizardProvider: WizardProvider2,
|
|
805
|
-
useWizard: useWizard2,
|
|
806
|
-
useWizardContext: useWizardContext2,
|
|
807
|
-
useWizardValue: useWizardValue2,
|
|
808
|
-
useWizardSelector: useWizardSelector2,
|
|
809
|
-
useWizardError: useWizardError2,
|
|
810
|
-
useWizardActions: useWizardActions2,
|
|
811
|
-
useWizardState: useWizardState2,
|
|
812
|
-
createStep
|
|
813
|
-
};
|
|
814
|
-
}
|
|
815
|
-
|
|
816
|
-
// src/adapters/persistence/LocalStorageAdapter.ts
|
|
817
|
-
var LocalStorageAdapter = class {
|
|
818
|
-
constructor(prefix = "wizard_") {
|
|
819
|
-
__publicField(this, "prefix");
|
|
820
|
-
this.prefix = prefix;
|
|
821
|
-
}
|
|
822
|
-
getKey(stepId) {
|
|
823
|
-
return `${this.prefix}${stepId}`;
|
|
824
|
-
}
|
|
825
|
-
saveStep(stepId, data) {
|
|
826
|
-
if (typeof window === "undefined") return;
|
|
827
|
-
try {
|
|
828
|
-
localStorage.setItem(this.getKey(stepId), JSON.stringify(data));
|
|
829
|
-
} catch (error) {
|
|
830
|
-
console.warn("LocalStorageAdapter: Failed to save step", error);
|
|
831
|
-
}
|
|
832
|
-
}
|
|
833
|
-
getStep(stepId) {
|
|
834
|
-
if (typeof window === "undefined") return void 0;
|
|
835
|
-
try {
|
|
836
|
-
const item = localStorage.getItem(this.getKey(stepId));
|
|
837
|
-
return item ? JSON.parse(item) : void 0;
|
|
838
|
-
} catch (error) {
|
|
839
|
-
console.warn("LocalStorageAdapter: Failed to get step", error);
|
|
840
|
-
return void 0;
|
|
841
|
-
}
|
|
842
|
-
}
|
|
843
|
-
clear() {
|
|
844
|
-
if (typeof window === "undefined") return;
|
|
845
|
-
Object.keys(localStorage).forEach((key) => {
|
|
846
|
-
if (key.startsWith(this.prefix)) {
|
|
847
|
-
localStorage.removeItem(key);
|
|
848
|
-
}
|
|
849
|
-
});
|
|
850
|
-
}
|
|
851
|
-
};
|
|
852
|
-
|
|
853
|
-
// src/adapters/validation/ZodAdapter.ts
|
|
854
|
-
var ZodAdapter = class {
|
|
855
|
-
constructor(schema) {
|
|
856
|
-
__publicField(this, "schema");
|
|
857
|
-
this.schema = schema;
|
|
858
|
-
}
|
|
859
|
-
async validate(data) {
|
|
860
|
-
const result = await this.schema.safeParseAsync(data);
|
|
861
|
-
if (result.success) {
|
|
862
|
-
return { isValid: true };
|
|
863
|
-
}
|
|
864
|
-
const errors = {};
|
|
865
|
-
if (result.error) {
|
|
866
|
-
result.error.issues.forEach((err) => {
|
|
867
|
-
const path = err.path.join(".");
|
|
868
|
-
errors[path] = err.message;
|
|
869
|
-
});
|
|
870
|
-
}
|
|
871
|
-
return { isValid: false, errors };
|
|
872
|
-
}
|
|
873
|
-
};
|
|
874
|
-
|
|
875
|
-
// src/adapters/validation/YupAdapter.ts
|
|
876
|
-
var YupAdapter = class {
|
|
877
|
-
constructor(schema) {
|
|
878
|
-
__publicField(this, "schema");
|
|
879
|
-
this.schema = schema;
|
|
880
|
-
}
|
|
881
|
-
async validate(data) {
|
|
882
|
-
try {
|
|
883
|
-
await this.schema.validate(data, { abortEarly: false });
|
|
884
|
-
return { isValid: true };
|
|
885
|
-
} catch (err) {
|
|
886
|
-
if (err && typeof err === "object" && "inner" in err) {
|
|
887
|
-
const yupError = err;
|
|
888
|
-
const errors = {};
|
|
889
|
-
yupError.inner.forEach((error) => {
|
|
890
|
-
if (error.path) {
|
|
891
|
-
errors[error.path] = error.message;
|
|
892
|
-
}
|
|
893
|
-
});
|
|
894
|
-
return { isValid: false, errors };
|
|
895
|
-
}
|
|
896
|
-
throw err;
|
|
897
|
-
}
|
|
898
|
-
}
|
|
899
|
-
};
|
|
900
|
-
export {
|
|
901
|
-
LocalStorageAdapter,
|
|
902
|
-
MemoryAdapter,
|
|
903
|
-
WizardProvider,
|
|
904
|
-
WizardStepRenderer,
|
|
905
|
-
WizardStore,
|
|
906
|
-
YupAdapter,
|
|
907
|
-
ZodAdapter,
|
|
908
|
-
createWizardFactory,
|
|
909
|
-
getByPath,
|
|
910
|
-
setByPath,
|
|
911
|
-
shallowEqual,
|
|
912
|
-
toPath,
|
|
913
|
-
useWizard,
|
|
914
|
-
useWizardActions,
|
|
915
|
-
useWizardContext,
|
|
916
|
-
useWizardError,
|
|
917
|
-
useWizardSelector,
|
|
918
|
-
useWizardState,
|
|
919
|
-
useWizardValue
|
|
920
|
-
};
|
|
921
|
-
//# sourceMappingURL=index.js.map
|
|
1
|
+
var Me=Object.defineProperty;var De=(n,e,t)=>e in n?Me(n,e,{enumerable:!0,configurable:!0,writable:!0,value:t}):n[e]=t;var m=(n,e,t)=>De(n,typeof e!="symbol"?e+"":e,t);import{createContext as oe,useContext as L,useEffect as J,useMemo as B,useState as Oe,useCallback as z,useSyncExternalStore as Z,useRef as M}from"react";var ne=new Map;function Ie(n){if(!n)return[];if(ne.has(n))return ne.get(n);let e;return n.includes("[")?e=n.replace(/\[(\d+)\]/g,".$1").split(".").filter(Boolean):e=n.split(".").filter(Boolean),ne.set(n,e),e}function k(n,e,t){if(!e||n===void 0||n===null)return t??n;if(!e.includes(".")&&!e.includes("[")){let c=n[e];return c!==void 0?c:t}let i=Ie(e),s=n;for(let c=0;c<i.length;c++){if(s==null)return t;s=s[i[c]]}return s!==void 0?s:t}function j(n,e,t){if(!e)return t;if(!e.includes(".")&&!e.includes("[")){if(Array.isArray(n)){let p=[...n];return p[e]=t,p}return{...n,[e]:t}}let i=Ie(e);if(i.length===0)return t;let s=Array.isArray(n)?[...n]:{...n},c=s;for(let p=0;p<i.length-1;p++){let g=i[p],I=i[p+1],l=c[g],T;l&&typeof l=="object"?T=Array.isArray(l)?[...l]:{...l}:T=/^\d+$/.test(I)?[]:{},c[g]=T,c=T}let r=i[i.length-1];return c[r]=t,s}function $e(n,e){if(Object.is(n,e))return!0;if(typeof n!="object"||n===null||typeof e!="object"||e===null)return!1;let t=Object.keys(n),i=Object.keys(e);if(t.length!==i.length)return!1;for(let s=0;s<t.length;s++){let c=t[s];if(!Object.prototype.hasOwnProperty.call(e,c)||!Object.is(n[c],e[c]))return!1}return!0}var K=class{constructor(e,t=[]){m(this,"initialData");m(this,"dirtyFields",new Set);m(this,"state");m(this,"listeners",new Set);m(this,"actionListeners",new Set);m(this,"errorsMap",new Map);m(this,"middlewareChain");m(this,"getSnapshot",()=>this.state);m(this,"subscribe",e=>(this.listeners.add(e),()=>this.listeners.delete(e)));this.initialData=JSON.parse(JSON.stringify(e)),this.state={data:e,errors:{},isDirty:!1,dirtyFields:this.dirtyFields,visitedSteps:new Set,completedSteps:new Set,errorSteps:new Set,currentStep:null,currentStepId:"",currentStepIndex:0,isFirstStep:!0,isLastStep:!1,isLoading:!0,isPending:!1,isBusy:!1,activeSteps:[],history:[],busySteps:new Set,progress:0,activeStepsCount:0,breadcrumbs:[],config:{}},this.middlewareChain=this.setupMiddlewares(t)}subscribeToActions(e){return this.actionListeners.add(e),()=>this.actionListeners.delete(e)}notifyActions(e){this.actionListeners.forEach(t=>t(e))}setupMiddlewares(e){let t={getState:()=>this.state.data,getSnapshot:()=>this.getSnapshot(),dispatch:s=>this.dispatch(s)};return e.map(s=>s(t)).reduceRight((s,c)=>c(s),this.internalDispatch.bind(this))}dispatch(e){this.middlewareChain(e)}internalDispatch(e){switch(this.notifyActions(e),e.type){case"INIT":this.initialData=JSON.parse(JSON.stringify(e.payload.data));let t=e.payload.config.steps.filter(i=>!i.condition);this.state={...this.state,data:e.payload.data,config:e.payload.config,activeSteps:t,activeStepsCount:t.length},this.notify();break;case"SET_CURRENT_STEP_ID":this.state={...this.state,currentStepId:e.payload.stepId},this.notify();break;case"SET_HISTORY":this.state={...this.state,history:e.payload.history},this.notify();break;case"SET_ACTIVE_STEPS":this.state={...this.state,activeSteps:e.payload.steps,activeStepsCount:e.payload.steps.length},this.notify();break;case"SET_DATA":this.updateDataByPath(e.payload.path,e.payload.value,e.payload.options);break;case"UPDATE_DATA":this.updateBulkData(e.payload.data,e.payload.options);break;case"GO_TO_STEP":break;case"VALIDATE_START":break;case"VALIDATE_END":break;case"SET_STEP_ERRORS":this.setStepErrors(e.payload.stepId,e.payload.errors);break;case"RESET":this.setInitialData(e.payload.data);break;case"SET_ERROR_STEPS":this.state={...this.state,errorSteps:e.payload.steps};break}this.syncDerivedState(),this.notify()}updateDataByPath(e,t,i){let s=j(this.state.data,e,t);s!==this.state.data&&this.update(s,e)}updateBulkData(e,t){let i;t?.replace?i=e:(i=JSON.parse(JSON.stringify(this.state.data)),Object.assign(i,e)),this.update(i,Object.keys(e))}update(e,t){t&&(Array.isArray(t)?t:[t]).forEach(s=>{let c=k(this.initialData,s),r=k(e,s);JSON.stringify(c)!==JSON.stringify(r)?this.dirtyFields.add(s):this.dirtyFields.delete(s)}),this.state={...this.state,data:e,isDirty:this.dirtyFields.size>0,dirtyFields:new Set(this.dirtyFields)},this.notify()}updateMeta(e){this.state={...this.state,...e},this.syncDerivedState(),this.notify()}syncDerivedState(){let{activeSteps:e,currentStepId:t,visitedSteps:i,completedSteps:s,errorSteps:c}=this.state,r=Math.max(0,e.findIndex(I=>I.id===t)),p=e[r]||null,g=e.map(I=>{let l="upcoming";return I.id===t?l="current":c.has(I.id)?l="error":s.has(I.id)?l="completed":i.has(I.id)&&(l="visited"),{id:I.id,label:I.label,status:l}});this.state={...this.state,currentStep:p,currentStepIndex:r,isFirstStep:r===0,isLastStep:e.length>0&&r===e.length-1,progress:e.length>0?Math.round((r+1)/e.length*100):0,breadcrumbs:g}}setInitialData(e){this.initialData=JSON.parse(JSON.stringify(e)),this.dirtyFields.clear(),this.state={...this.state,data:e,isDirty:!1,dirtyFields:new Set},this.notify()}syncErrors(){let e={};for(let[t,i]of this.errorsMap.entries())i.size>0&&(e[t]=Object.fromEntries(i));this.state={...this.state,errors:e},this.notify()}updateErrors(e){this.errorsMap.clear();for(let[t,i]of Object.entries(e)){let s=new Map;for(let[c,r]of Object.entries(i))s.set(c,r);s.size>0&&this.errorsMap.set(t,s)}this.state={...this.state,errors:e},this.notify()}setStepErrors(e,t){if(!t||Object.keys(t).length===0)return this.errorsMap.has(e)?(this.errorsMap.delete(e),this.syncErrors(),!0):!1;let i=new Map;for(let[s,c]of Object.entries(t))i.set(s,c);return this.errorsMap.set(e,i),this.syncErrors(),!0}deleteError(e,t){let i=this.errorsMap.get(e);return i&&i.has(t)?(i.delete(t),i.size===0&&this.errorsMap.delete(e),this.syncErrors(),!0):!1}notify(){this.listeners.forEach(e=>e())}};var $=class{constructor(){m(this,"storage",{})}saveStep(e,t){this.storage[e]=t}getStep(e){return this.storage[e]}clear(){this.storage={}}};import{jsx as ie}from"react/jsx-runtime";var xe=oe(void 0),ve=oe(void 0),Y=oe(void 0);function be({config:n,initialData:e,initialStepId:t,children:i}){let[s,c]=Oe(n),r=M(new K(e||{},n.middlewares)),p=M(!1),g=B(()=>s.persistence?.adapter||new $,[s.persistence?.adapter]),I=s.persistence?.mode||"onStepChange",l="__wizzard_meta__",T=Z(a=>r.current.subscribe(a),()=>r.current.getSnapshot()),{activeSteps:b,currentStepId:U,history:pe,visitedSteps:le,completedSteps:ue,data:Se,errors:{}}=T,D=B(()=>{let a=new Map;return s.steps.forEach(d=>a.set(d.id,d)),a},[s.steps]);J(()=>{c(n)},[n]);let fe=B(()=>{let a=new Map;return b.forEach((d,o)=>a.set(d.id,o)),a},[b]),w=M({config:s,stepsMap:D,activeSteps:b,activeStepsIndexMap:fe,visitedSteps:le,completedSteps:ue,persistenceMode:I,persistenceAdapter:g,currentStepId:U,history:pe});J(()=>{w.current={config:s,stepsMap:D,activeSteps:b,activeStepsIndexMap:fe,visitedSteps:le,completedSteps:ue,persistenceMode:I,persistenceAdapter:g,currentStepId:U,history:pe}});let O=z((a,d)=>{s.analytics?.onEvent(a,d)},[s.analytics]),W=z((a,d,o)=>{let{stepsMap:f,persistenceAdapter:S,persistenceMode:y}=w.current,E=f.get(d),x=E?.persistenceAdapter||S,h=E?.persistenceMode||y;(a===h||a==="manual")&&x.saveStep(d,o)},[]),_=z(async a=>{r.current.updateMeta({isBusy:!0});try{return(await Promise.all(s.steps.map(async o=>{if(!o.condition)return{step:o,ok:!0};let f=new Set(r.current.getSnapshot().busySteps);f.add(o.id),r.current.updateMeta({busySteps:f,isBusy:!0});try{let S=o.condition(a||{},r.current.getSnapshot()),y=S instanceof Promise?await S:S;return{step:o,ok:y}}catch(S){return console.error(`[Wizard] Condition failed for ${o.id}:`,S),{step:o,ok:!1}}finally{let S=r.current.getSnapshot(),y=new Set(S.busySteps);y.delete(o.id),r.current.updateMeta({busySteps:y,isBusy:y.size>0})}}))).filter(o=>o.ok).map(o=>o.step)}finally{r.current.getSnapshot().busySteps.size===0&&r.current.updateMeta({isBusy:!1})}},[s.steps]),A=z(async(a,d)=>{let o=D.get(a);if(!o||!o.validationAdapter)return!0;r.current.dispatch({type:"VALIDATE_START",payload:{stepId:a}});let f=new Set(r.current.getSnapshot().busySteps);f.add(a),r.current.updateMeta({busySteps:f,isBusy:!0});try{let S=await o.validationAdapter.validate(d);if(S.isValid){r.current.setStepErrors(a,null);let y=new Set(r.current.getSnapshot().errorSteps);return y.delete(a),r.current.dispatch({type:"SET_ERROR_STEPS",payload:{steps:y}}),!0}else{r.current.setStepErrors(a,S.errors||null),O("validation_error",{stepId:a,errors:S.errors,timestamp:Date.now()});let y=new Set(r.current.getSnapshot().errorSteps);return y.add(a),r.current.dispatch({type:"SET_ERROR_STEPS",payload:{steps:y}}),!1}}finally{let S=new Set(r.current.getSnapshot().busySteps);S.delete(a),r.current.updateMeta({busySteps:S,isBusy:S.size>0}),r.current.dispatch({type:"VALIDATE_END",payload:{stepId:a,result:{isValid:!0}}})}},[D,O]),V=z(async(a,d)=>{let{currentStepId:o,config:f,persistenceMode:S,persistenceAdapter:y,stepsMap:E}=w.current,x=r.current.getSnapshot().data,h=f.steps,R=h.findIndex(P=>P.id===o),F=h.findIndex(P=>P.id===a);if(F>R&&o){let P=E.get(o);if((P?.autoValidate??f.autoValidate??!!P?.validationAdapter)&&!await A(o,x))return!1}r.current.updateMeta({isBusy:!0});try{if(!(d||await _(x)).find(ae=>ae.id===a))return!1;let q=E.get(o);if(q?.beforeLeave){let ae=r.current.getSnapshot(),ke=F>R?"next":"prev";if(await q.beforeLeave(x,ke,ae)===!1)return!1}o&&(q?.persistenceMode||S)==="onStepChange"&&W("onStepChange",o,x);let re=r.current.getSnapshot(),se=new Set(re.visitedSteps);o&&se.add(o),r.current.dispatch({type:"SET_VISITED_STEPS",payload:{steps:se}}),r.current.dispatch({type:"SET_CURRENT_STEP_ID",payload:{stepId:a}});let me=[...re.history,a];return r.current.dispatch({type:"SET_HISTORY",payload:{history:me}}),S!=="manual"&&y.saveStep(l,{currentStepId:a,visited:Array.from(se),completed:Array.from(re.completedSteps),history:me}),f.onStepChange&&f.onStepChange(o||null,a,x),O("step_change",{from:o||null,to:a,timestamp:Date.now()}),window.scrollTo(0,0),!0}finally{r.current.updateMeta({isBusy:!1})}},[_,A,W,O]),ye=z(async()=>{let{currentStepId:a}=w.current;if(!a)return;let d=r.current.getSnapshot().data,o=D.get(a);if((o?.autoValidate??s.autoValidate??!!o?.validationAdapter)&&!await A(a,d))return;let S=await _(d),y=S.findIndex(E=>E.id===a);if(y!==-1&&y<S.length-1){let E=S[y+1].id;if(await V(E,S)){let h=new Set(r.current.getSnapshot().completedSteps);h.add(a),r.current.dispatch({type:"SET_COMPLETED_STEPS",payload:{steps:h}})}}},[V,_,A,D]),ge=z(()=>{let{currentStepId:a,activeSteps:d,activeStepsIndexMap:o}=w.current,f=o.get(a)??-1;f>0&&V(d[f-1].id)},[V]),te=z((a,d,o)=>{let{persistenceMode:f,stepsMap:S,currentStepId:y}=w.current,E=r.current.getSnapshot().data;if(k(E,a)===d)return;let x=j(E,a,d);if(s.steps.forEach(h=>{if(h.dependsOn?.some(R=>a===R||a.startsWith(R+"."))){let R=new Set(r.current.getSnapshot().completedSteps);R.delete(h.id)&&r.current.dispatch({type:"SET_COMPLETED_STEPS",payload:{steps:R}});let F=new Set(r.current.getSnapshot().visitedSteps);F.delete(h.id)&&r.current.dispatch({type:"SET_VISITED_STEPS",payload:{steps:F}}),h.clearData&&(typeof h.clearData=="function"?x={...x,...h.clearData(x)}:(Array.isArray(h.clearData)?h.clearData:[h.clearData]).forEach(P=>{x=j(x,P,void 0)}))}}),r.current.dispatch({type:"SET_DATA",payload:{path:a,value:d,options:o}}),y){r.current.deleteError(y,a);let h=S.get(y);(h?.validationMode||s.validationMode||"onStepChange")==="onChange"&&A(y,x),(h?.persistenceMode||f)==="onChange"&&W("onChange",y,x)}},[s,A,W]),he=z((a,d)=>{let o=r.current.getSnapshot().data,f=d?.replace?a:{...o,...a};r.current.update(f,Object.keys(a)),d?.persist&&s.steps.forEach(S=>W("manual",S.id,f))},[s.steps,W]),Te=z(()=>{if(r.current.setInitialData(e||{}),r.current.update(e||{}),r.current.updateErrors({}),r.current.dispatch({type:"SET_VISITED_STEPS",payload:{steps:new Set}}),r.current.dispatch({type:"SET_COMPLETED_STEPS",payload:{steps:new Set}}),r.current.dispatch({type:"SET_ERROR_STEPS",payload:{steps:new Set}}),b.length>0){let a=b[0].id;r.current.dispatch({type:"SET_CURRENT_STEP_ID",payload:{stepId:a}}),r.current.dispatch({type:"SET_HISTORY",payload:{history:[a]}})}else r.current.dispatch({type:"SET_CURRENT_STEP_ID",payload:{stepId:""}}),r.current.dispatch({type:"SET_HISTORY",payload:{history:[]}});g.clear(),O("wizard_reset",{data:e})},[e,b,g,O]),Re=B(()=>({...T,config:s}),[T,s]),Ce=B(()=>({goToNextStep:ye,goToPrevStep:ge,goToStep:V,setStepData:(a,d)=>{let o={...r.current.getSnapshot().data,...d};r.current.update(o,Object.keys(d))},handleStepChange:(a,d)=>{w.current.currentStepId&&te(a,d)},validateStep:a=>A(a,r.current.getSnapshot().data),validateAll:async()=>{r.current.updateMeta({isBusy:!0});let a=r.current.getSnapshot().data,d=await _(a),o=await Promise.all(d.map(f=>A(f.id,a)));return r.current.updateMeta({isBusy:!1}),{isValid:o.every(Boolean),errors:r.current.getSnapshot().errors}},save:a=>{let d=r.current.getSnapshot().data;a===!0?s.steps.forEach(o=>W("manual",o.id,d)):a?(Array.isArray(a)?a:[a]).forEach(o=>W("manual",o,d)):w.current.currentStepId&&W("manual",w.current.currentStepId,d)},clearStorage:()=>g.clear(),reset:Te,setData:te,updateData:he,getData:(a,d)=>k(r.current.getSnapshot().data,a,d),updateConfig:a=>c(d=>({...d,...a}))}),[ye,ge,V,A,Te,te,he,g,s.steps,W]);return J(()=>{p.current?r.current.updateMeta({config:s}):(r.current.dispatch({type:"INIT",payload:{data:e||{},config:s}}),p.current=!0)},[e,s]),J(()=>{let a=!0;return(async()=>{let o=await _(Se);a&&r.current.dispatch({type:"SET_ACTIVE_STEPS",payload:{steps:o}})})(),()=>{a=!1}},[Se,_]),J(()=>{let a=g.getStep(l);a&&(a.currentStepId&&r.current.dispatch({type:"SET_CURRENT_STEP_ID",payload:{stepId:a.currentStepId}}),a.visited&&r.current.dispatch({type:"SET_VISITED_STEPS",payload:{steps:new Set(a.visited)}}),a.completed&&r.current.dispatch({type:"SET_COMPLETED_STEPS",payload:{steps:new Set(a.completed)}}),a.history&&r.current.dispatch({type:"SET_HISTORY",payload:{history:a.history}}));let d=r.current.getSnapshot(),o=d.activeSteps;if(!U&&o.length>0){let f=t&&o.some(S=>S.id===t)?t:o[0].id;r.current.dispatch({type:"SET_CURRENT_STEP_ID",payload:{stepId:f}}),d.history.length===0&&r.current.dispatch({type:"SET_HISTORY",payload:{history:[f]}}),r.current.updateMeta({isLoading:!1})}},[b,t,U,g]),ie(Y.Provider,{value:r.current,children:ie(xe.Provider,{value:Re,children:ie(ve.Provider,{value:Ce,children:i})})})}function G(){let n=L(xe);if(!n)throw new Error("useWizardState must be used within a WizardProvider");return n}function Ee(n,e){let t=L(Y);if(!t)throw new Error("useWizardValue must be used within a WizardProvider");let i=M(null),s=M(null),c=z(()=>{let r=t.getSnapshot().data;if(r===i.current)return s.current;let p=k(r,n);return s.current!==void 0&&(e?.isEqual||Object.is)(s.current,p)?(i.current=r,s.current):(i.current=r,s.current=p,p)},[t,n,e?.isEqual]);return Z(t.subscribe,c)}function ze(n){let e=L(Y);if(!e)throw new Error("useWizardError must be used within a WizardProvider");let t=z(()=>{let i=e.getSnapshot().errors;for(let[s,c]of Object.entries(i)){let r=c;if(r[n])return r[n];if(n.startsWith(s+".")&&r[s])return r[s];let p=n.split(".").pop();if(p&&r[p])return r[p]}},[e,n]);return Z(e.subscribe,t)}function X(n,e){let t=L(Y);if(!t)throw new Error("useWizardSelector must be used within a WizardProvider");let i=M(null),s=M(null),c=z(()=>{let r=t.getSnapshot();if(r===i.current)return s.current;let p=n(r);return s.current!==null&&(e?.isEqual||Object.is)(s.current,p)?(i.current=r,s.current):(i.current=r,s.current=p,p)},[t,n,e?.isEqual]);return Z(t.subscribe,c)}function de(){let n=L(ve);if(!n)throw new Error("useWizardActions must be used within a WizardProvider");return n}function C(){let n=G(),e=de(),t=L(Y),i=X(g=>g.data),s=X(g=>g.errors),{data:c,errors:r,...p}=n;return B(()=>({...p,...e,wizardData:i,allErrors:s,data:i,errors:s,store:t}),[p,e,i,s,t])}import{useMemo as Ve,Suspense as Be}from"react";import{jsx as ce}from"react/jsx-runtime";var Le=({wrapper:n,fallback:e=null})=>{let{currentStep:t}=C(),i=Ve(()=>t?.component?t.component:null,[t]);if(!t||!i)return null;let s=ce(Be,{fallback:e,children:ce(i,{})});return n?ce(n,{children:s},t.id):s};var We=()=>C();import{jsx as Fe}from"react/jsx-runtime";function Ne(){return{WizardProvider:({config:l,initialData:T,children:b})=>Fe(be,{config:l,initialData:T,children:b}),useWizard:()=>We(),useWizardContext:()=>C(),useWizardValue:(l,T)=>Ee(l,T),useWizardSelector:(l,T)=>X(l,T),useWizardError:l=>ze(l),useWizardActions:()=>de(),useWizardState:()=>G(),useBreadcrumbs:()=>G().breadcrumbs,createStep:l=>l}}var we=class{constructor(e="wizard_"){m(this,"prefix");this.prefix=e}getKey(e){return`${this.prefix}${e}`}saveStep(e,t){if(!(typeof window>"u"))try{localStorage.setItem(this.getKey(e),JSON.stringify(t))}catch(i){console.warn("LocalStorageAdapter: Failed to save step",i)}}getStep(e){if(!(typeof window>"u"))try{let t=localStorage.getItem(this.getKey(e));return t?JSON.parse(t):void 0}catch(t){console.warn("LocalStorageAdapter: Failed to get step",t);return}}clear(){typeof window>"u"||Object.keys(localStorage).forEach(e=>{e.startsWith(this.prefix)&&localStorage.removeItem(e)})}};var Ae=class{constructor(e){m(this,"schema");this.schema=e}async validate(e){let t=await this.schema.safeParseAsync(e);if(t.success)return{isValid:!0};let i={};return t.error&&t.error.issues.forEach(s=>{let c=s.path.join(".");i[c]=s.message}),{isValid:!1,errors:i}}};var Pe=class{constructor(e){m(this,"schema");this.schema=e}async validate(e){try{return await this.schema.validate(e,{abortEarly:!1}),{isValid:!0}}catch(t){if(t&&typeof t=="object"&&"inner"in t){let i=t,s={};return i.inner.forEach(c=>{c.path&&(s[c.path]=c.message)}),{isValid:!1,errors:s}}throw t}}};var je=n=>e=>t=>{console.group(`Wizard Action: ${t.type}`),console.log("Action payload:",t.payload),console.log("State before:",n.getSnapshot());let i=e(t);return console.log("State after:",n.getSnapshot()),console.groupEnd(),i};var Je=n=>{if(typeof window>"u"||!window.__REDUX_DEVTOOLS_EXTENSION__)return t=>i=>t(i);let e=window.__REDUX_DEVTOOLS_EXTENSION__.connect({name:"Wizard Stepper React"});return e.init(n.getSnapshot()),t=>i=>{let s=t(i);return e.send(i,n.getSnapshot()),s}};import{useState as ee,useEffect as Ye}from"react";import{jsx as u,jsxs as v}from"react/jsx-runtime";function He(){let[n,e]=ee(!1),[t,i]=ee("state"),{wizardData:s,allErrors:c,store:r,...p}=C(),[g,I]=ee([]);return Ye(()=>r?r.subscribeToActions(T=>{I(b=>[{timestamp:Date.now(),action:T,state:r.getSnapshot()},...b].slice(0,50))}):void 0,[r]),n?v("div",{style:{position:"fixed",bottom:"20px",right:"20px",width:"400px",height:"500px",backgroundColor:"rgba(15, 23, 42, 0.9)",backdropFilter:"blur(12px)",borderRadius:"16px",border:"1px solid rgba(255, 255, 255, 0.1)",boxShadow:"0 10px 40px rgba(0,0,0,0.5)",zIndex:9999,display:"flex",flexDirection:"column",color:"#e2e8f0",fontFamily:"Inter, sans-serif",overflow:"hidden"},children:[v("div",{style:{padding:"12px 16px",borderBottom:"1px solid rgba(255, 255, 255, 0.1)",display:"flex",justifyContent:"space-between",alignItems:"center",background:"rgba(255, 255, 255, 0.03)"},children:[u("span",{style:{fontWeight:600,fontSize:"14px"},children:"Wizard DevTools"}),u("button",{onClick:()=>e(!1),style:{background:"none",border:"none",color:"#94a3b8",cursor:"pointer",fontSize:"18px"},children:"\xD7"})]}),u("div",{style:{display:"flex",borderBottom:"1px solid rgba(255, 255, 255, 0.1)",background:"rgba(255, 255, 255, 0.02)"},children:["state","actions","errors"].map(l=>u("button",{onClick:()=>i(l),style:{flex:1,padding:"10px",background:t===l?"rgba(37, 99, 235, 0.2)":"none",border:"none",color:t===l?"#60a5fa":"#94a3b8",borderBottom:t===l?"2px solid #3b82f6":"none",cursor:"pointer",fontSize:"12px",textTransform:"capitalize",fontWeight:t===l?600:400},children:l},l))}),v("div",{style:{flex:1,overflowY:"auto",padding:"16px",fontSize:"12px"},children:[t==="state"&&v("div",{children:[v(Q,{title:"Navigation",children:[u(N,{label:"Current Step",value:p.currentStepId}),u(N,{label:"Index",value:p.currentStepIndex}),u(N,{label:"Progress",value:`${p.progress}%`}),u(N,{label:"Total Steps",value:p.activeStepsCount}),u(N,{label:"Is Loading",value:String(p.isLoading)}),u(N,{label:"Is Busy",value:String(p.isBusy)})]}),u(Q,{title:"History",children:u("div",{style:{color:"#94a3b8"},children:p.history.join(" \u2192 ")||"Empty"})}),u(Q,{title:"Data",children:u(H,{data:s})}),u(Q,{title:"Meta",children:u(H,{data:{visited:Array.from(p.visitedSteps),completed:Array.from(p.completedSteps),busy:Array.from(p.busySteps)}})})]}),t==="errors"&&u("div",{children:Object.keys(c).length===0?u("div",{style:{color:"#94a3b8",textAlign:"center",marginTop:"20px"},children:"No active errors"}):u(H,{data:c})}),t==="actions"&&u("div",{style:{display:"flex",flexDirection:"column",gap:"8px"},children:g.length===0?u("div",{style:{color:"#94a3b8",textAlign:"center",marginTop:"20px"},children:"No actions recorded yet"}):g.map((l,T)=>u(Ue,{log:l},l.timestamp+T))})]}),v("div",{style:{padding:"8px 16px",fontSize:"10px",color:"#64748b",borderTop:"1px solid rgba(255, 255, 255, 0.1)",background:"rgba(255, 255, 255, 0.02)",display:"flex",justifyContent:"space-between"},children:[v("span",{children:["v",globalThis.process?.env?.VERSION||"2.0.0"]}),u("span",{children:"Strict Mode: Active"})]})]}):u("button",{onClick:()=>e(!0),style:{position:"fixed",bottom:"20px",right:"20px",zIndex:9999,padding:"10px 15px",borderRadius:"50px",background:"rgba(37, 99, 235, 0.9)",color:"white",border:"none",boxShadow:"0 4px 15px rgba(0,0,0,0.2)",cursor:"pointer",fontWeight:"bold",fontSize:"12px",backdropFilter:"blur(5px)"},children:"Wizard DevTools"})}var Ue=({log:n})=>{let[e,t]=ee(!1),i=new Date(n.timestamp).toLocaleTimeString();return v("div",{style:{background:"rgba(255, 255, 255, 0.05)",borderRadius:"8px",overflow:"hidden",border:"1px solid rgba(255, 255, 255, 0.05)"},children:[v("div",{onClick:()=>t(!e),style:{padding:"8px 12px",display:"flex",justifyContent:"space-between",cursor:"pointer",alignItems:"center"},children:[v("div",{style:{display:"flex",gap:"8px",alignItems:"center"},children:[u("span",{style:{color:"#64748b",fontSize:"10px"},children:i}),u("span",{style:{color:"#60a5fa",fontWeight:600},children:n.action.type})]}),u("span",{style:{color:"#475569",transform:e?"rotate(180deg)":"none",transition:"transform 0.2s"},children:"\u25BE"})]}),e&&v("div",{style:{padding:"0 12px 12px 12px",borderTop:"1px solid rgba(255, 255, 255, 0.05)"},children:[v("div",{style:{marginTop:"8px"},children:[u("div",{style:{color:"#94a3b8",marginBottom:"4px",fontSize:"10px"},children:"Payload:"}),u(H,{data:n.action.payload})]}),v("div",{style:{marginTop:"8px"},children:[u("div",{style:{color:"#94a3b8",marginBottom:"4px",fontSize:"10px"},children:"State after:"}),u(H,{data:n.state})]})]})]})},Q=({title:n,children:e})=>v("div",{style:{marginBottom:"20px"},children:[u("h4",{style:{margin:"0 0 8px 0",color:"#3b82f6",fontSize:"11px",textTransform:"uppercase",letterSpacing:"0.05em"},children:n}),e]}),N=({label:n,value:e})=>v("div",{style:{display:"flex",justifyContent:"space-between",marginBottom:"4px"},children:[v("span",{style:{color:"#94a3b8"},children:[n,":"]}),u("span",{style:{color:"#f8fafc",fontWeight:500},children:e})]}),H=({data:n})=>u("pre",{style:{background:"rgba(0, 0, 0, 0.3)",padding:"10px",borderRadius:"8px",overflowX:"auto",color:"#60a5fa",border:"1px solid rgba(255, 255, 255, 0.05)",margin:0},children:JSON.stringify(n,(t,i)=>i instanceof Set?Array.from(i):i,2)});export{we as LocalStorageAdapter,$ as MemoryAdapter,He as WizardDevTools,be as WizardProvider,Le as WizardStepRenderer,Pe as YupAdapter,Ae as ZodAdapter,Ne as createWizardFactory,Je as devToolsMiddleware,k as getByPath,je as loggerMiddleware,j as setByPath,$e as shallowEqual,Ie as toPath,We as useWizard,de as useWizardActions,C as useWizardContext,ze as useWizardError,X as useWizardSelector,G as useWizardState,Ee as useWizardValue};
|