@wizzard-packages/react 0.1.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/dist/index.js ADDED
@@ -0,0 +1,655 @@
1
+ // src/context/WizardContext.tsx
2
+ import {
3
+ createContext,
4
+ useContext,
5
+ useEffect,
6
+ useMemo,
7
+ useState,
8
+ useCallback,
9
+ useSyncExternalStore,
10
+ useRef
11
+ } from "react";
12
+ import {
13
+ WizardStore,
14
+ getByPath,
15
+ setByPath
16
+ } from "@wizzard-packages/core";
17
+ import { MemoryAdapter } from "@wizzard-packages/persistence";
18
+ import { jsx } from "react/jsx-runtime";
19
+ var WizardStateContext = createContext(void 0);
20
+ var WizardActionsContext = createContext(void 0);
21
+ var WizardStoreContext = createContext(void 0);
22
+ function WizardProvider({
23
+ config,
24
+ initialData,
25
+ initialStepId,
26
+ children
27
+ }) {
28
+ const [localConfig, setLocalConfig] = useState(config);
29
+ const storeRef = useRef(null);
30
+ if (!storeRef.current) {
31
+ storeRef.current = new WizardStore(initialData || {}, config.middlewares);
32
+ }
33
+ const isInitialized = useRef(false);
34
+ const persistenceAdapter = useMemo(() => {
35
+ return localConfig.persistence?.adapter || new MemoryAdapter();
36
+ }, [localConfig.persistence?.adapter]);
37
+ const persistenceMode = localConfig.persistence?.mode || "onStepChange";
38
+ const META_KEY = "__wizzard_meta__";
39
+ const snapshot = useSyncExternalStore(
40
+ storeRef.current.subscribe,
41
+ storeRef.current.getSnapshot
42
+ );
43
+ const {
44
+ activeSteps,
45
+ currentStepId,
46
+ history,
47
+ visitedSteps,
48
+ completedSteps,
49
+ data,
50
+ errors: _errors
51
+ } = snapshot;
52
+ const stepsMap = useMemo(() => {
53
+ const map = /* @__PURE__ */ new Map();
54
+ localConfig.steps.forEach((step) => map.set(step.id, step));
55
+ return map;
56
+ }, [localConfig.steps]);
57
+ useEffect(() => {
58
+ setLocalConfig(config);
59
+ }, [config]);
60
+ const activeStepsIndexMap = useMemo(() => {
61
+ const map = /* @__PURE__ */ new Map();
62
+ activeSteps.forEach((s, i) => map.set(s.id, i));
63
+ return map;
64
+ }, [activeSteps]);
65
+ const stateRef = useRef({
66
+ config: localConfig,
67
+ stepsMap,
68
+ activeSteps,
69
+ activeStepsIndexMap,
70
+ visitedSteps,
71
+ completedSteps,
72
+ persistenceMode,
73
+ persistenceAdapter,
74
+ currentStepId,
75
+ history
76
+ });
77
+ const validationDebounceRef = useRef(null);
78
+ useEffect(() => {
79
+ stateRef.current = {
80
+ config: localConfig,
81
+ stepsMap,
82
+ activeSteps,
83
+ activeStepsIndexMap,
84
+ visitedSteps,
85
+ completedSteps,
86
+ persistenceMode,
87
+ persistenceAdapter,
88
+ currentStepId,
89
+ history
90
+ };
91
+ });
92
+ useEffect(() => {
93
+ return () => {
94
+ if (validationDebounceRef.current) {
95
+ clearTimeout(validationDebounceRef.current);
96
+ }
97
+ };
98
+ }, []);
99
+ const trackEvent = useCallback(
100
+ (name, payload) => {
101
+ localConfig.analytics?.onEvent(name, payload);
102
+ },
103
+ [localConfig.analytics]
104
+ );
105
+ const resolveActiveStepsHelper = useCallback(
106
+ (data2) => storeRef.current.resolveActiveSteps(data2),
107
+ []
108
+ );
109
+ const validateStep = useCallback((stepId) => storeRef.current.validateStep(stepId), []);
110
+ const goToStep = useCallback(
111
+ async (stepId, providedActiveSteps, options = { validate: true }) => {
112
+ return storeRef.current.goToStep(stepId, {
113
+ validate: options.validate,
114
+ providedActiveSteps
115
+ });
116
+ },
117
+ []
118
+ );
119
+ const goToNextStep = useCallback(async () => {
120
+ const { currentStepId: currentStepId2 } = stateRef.current;
121
+ if (!currentStepId2) return;
122
+ const currentData = storeRef.current.getSnapshot().data;
123
+ const step = stepsMap.get(currentStepId2);
124
+ const shouldVal = step?.autoValidate ?? localConfig.autoValidate ?? !!step?.validationAdapter;
125
+ if (shouldVal) {
126
+ const ok = await validateStep(currentStepId2);
127
+ if (!ok) return;
128
+ }
129
+ const resolvedSteps = await resolveActiveStepsHelper(currentData);
130
+ const idx = resolvedSteps.findIndex((s) => s.id === currentStepId2);
131
+ if (idx !== -1 && idx < resolvedSteps.length - 1) {
132
+ const nextStepId = resolvedSteps[idx + 1].id;
133
+ const success = await goToStep(nextStepId, resolvedSteps, {
134
+ validate: false
135
+ });
136
+ if (success) {
137
+ const currentSnapshot = storeRef.current.getSnapshot();
138
+ if (!currentSnapshot.errorSteps.has(currentStepId2)) {
139
+ const nextComp = new Set(currentSnapshot.completedSteps);
140
+ nextComp.add(currentStepId2);
141
+ storeRef.current.dispatch({
142
+ type: "SET_COMPLETED_STEPS",
143
+ payload: { steps: nextComp }
144
+ });
145
+ }
146
+ }
147
+ }
148
+ }, [goToStep, resolveActiveStepsHelper, validateStep, stepsMap, localConfig]);
149
+ const goToPrevStep = useCallback(async () => {
150
+ const { currentStepId: currentStepId2, activeSteps: activeSteps2, activeStepsIndexMap: activeStepsIndexMap2 } = stateRef.current;
151
+ const idx = activeStepsIndexMap2.get(currentStepId2) ?? -1;
152
+ if (idx > 0) await goToStep(activeSteps2[idx - 1].id);
153
+ }, [goToStep]);
154
+ const handleStepDependencies = useCallback(
155
+ (paths, initialData2) => {
156
+ let currentData = { ...initialData2 };
157
+ const allClearedPaths = /* @__PURE__ */ new Set();
158
+ const { completedSteps: completedSteps2, visitedSteps: visitedSteps2 } = storeRef.current.getSnapshot();
159
+ const nextComp = new Set(completedSteps2);
160
+ const nextVis = new Set(visitedSteps2);
161
+ let statusChanged = false;
162
+ const processDependencies = (changedPaths) => {
163
+ const newlyClearedPaths = [];
164
+ localConfig.steps.forEach((step) => {
165
+ const isDependent = step.dependsOn?.some(
166
+ (p) => changedPaths.some(
167
+ (path) => path === p || p.startsWith(path + ".") || path.startsWith(p + ".")
168
+ )
169
+ );
170
+ if (isDependent) {
171
+ if (nextComp.delete(step.id)) {
172
+ statusChanged = true;
173
+ }
174
+ if (nextVis.delete(step.id)) {
175
+ statusChanged = true;
176
+ }
177
+ if (step.clearData) {
178
+ if (typeof step.clearData === "function") {
179
+ const patch = step.clearData(currentData, changedPaths);
180
+ Object.keys(patch).forEach((key) => {
181
+ if (currentData[key] !== patch[key]) {
182
+ currentData[key] = patch[key];
183
+ newlyClearedPaths.push(key);
184
+ allClearedPaths.add(key);
185
+ }
186
+ });
187
+ } else {
188
+ const pathsToClear = Array.isArray(step.clearData) ? step.clearData : [step.clearData];
189
+ pathsToClear.forEach((p) => {
190
+ const val = getByPath(currentData, p);
191
+ if (val !== void 0) {
192
+ currentData = setByPath(currentData, p, void 0);
193
+ newlyClearedPaths.push(p);
194
+ allClearedPaths.add(p);
195
+ }
196
+ });
197
+ }
198
+ }
199
+ }
200
+ });
201
+ if (newlyClearedPaths.length > 0) {
202
+ processDependencies(newlyClearedPaths);
203
+ }
204
+ };
205
+ processDependencies(paths);
206
+ if (statusChanged) {
207
+ storeRef.current.dispatch({
208
+ type: "SET_COMPLETED_STEPS",
209
+ payload: { steps: nextComp }
210
+ });
211
+ storeRef.current.dispatch({
212
+ type: "SET_VISITED_STEPS",
213
+ payload: { steps: nextVis }
214
+ });
215
+ }
216
+ return {
217
+ newData: currentData,
218
+ hasClearing: allClearedPaths.size > 0,
219
+ clearedPaths: Array.from(allClearedPaths)
220
+ };
221
+ },
222
+ [localConfig.steps]
223
+ );
224
+ const setData = useCallback(
225
+ (path, value, options) => {
226
+ const { stepsMap: stepsMap2, currentStepId: currentStepId2 } = stateRef.current;
227
+ const prevData = storeRef.current.getSnapshot().data;
228
+ if (getByPath(prevData, path) === value) return;
229
+ const baseData = setByPath(prevData, path, value);
230
+ const { newData, hasClearing } = handleStepDependencies([path], baseData);
231
+ if (!hasClearing) {
232
+ storeRef.current.dispatch({
233
+ type: "SET_DATA",
234
+ payload: {
235
+ path,
236
+ value,
237
+ options: { ...options, __from_set_data__: true }
238
+ }
239
+ });
240
+ } else {
241
+ storeRef.current.dispatch({
242
+ type: "UPDATE_DATA",
243
+ payload: {
244
+ data: newData,
245
+ options: { replace: true, __from_set_data__: true, path }
246
+ }
247
+ });
248
+ }
249
+ if (currentStepId2) {
250
+ storeRef.current.deleteError(currentStepId2, path);
251
+ const step = stepsMap2.get(currentStepId2);
252
+ const mode = step?.validationMode || localConfig.validationMode || "onStepChange";
253
+ if (mode === "onChange") {
254
+ const debounceMs = options?.debounceValidation ?? localConfig.validationDebounceTime ?? 300;
255
+ if (validationDebounceRef.current) {
256
+ clearTimeout(validationDebounceRef.current);
257
+ }
258
+ validationDebounceRef.current = setTimeout(() => {
259
+ validateStep(currentStepId2);
260
+ }, debounceMs);
261
+ }
262
+ }
263
+ },
264
+ [localConfig, validateStep, handleStepDependencies]
265
+ );
266
+ const updateData = useCallback(
267
+ (data2, options) => {
268
+ const prev = storeRef.current.getSnapshot().data;
269
+ const baseData = options?.replace ? data2 : { ...prev, ...data2 };
270
+ const { newData } = handleStepDependencies(Object.keys(data2), baseData);
271
+ storeRef.current.update(newData, Object.keys(data2));
272
+ if (options?.persist) {
273
+ if (storeRef.current.save) {
274
+ storeRef.current.save(storeRef.current.getSnapshot().currentStepId);
275
+ }
276
+ }
277
+ },
278
+ [handleStepDependencies]
279
+ );
280
+ const reset = useCallback(() => {
281
+ storeRef.current.setInitialData(initialData || {});
282
+ storeRef.current.update(initialData || {});
283
+ storeRef.current.updateErrors({});
284
+ storeRef.current.dispatch({
285
+ type: "SET_VISITED_STEPS",
286
+ payload: { steps: /* @__PURE__ */ new Set() }
287
+ });
288
+ storeRef.current.dispatch({
289
+ type: "SET_COMPLETED_STEPS",
290
+ payload: { steps: /* @__PURE__ */ new Set() }
291
+ });
292
+ storeRef.current.dispatch({
293
+ type: "SET_ERROR_STEPS",
294
+ payload: { steps: /* @__PURE__ */ new Set() }
295
+ });
296
+ if (activeSteps.length > 0) {
297
+ const startId = activeSteps[0].id;
298
+ storeRef.current.dispatch({
299
+ type: "SET_CURRENT_STEP_ID",
300
+ payload: { stepId: startId }
301
+ });
302
+ storeRef.current.dispatch({
303
+ type: "SET_HISTORY",
304
+ payload: { history: [startId] }
305
+ });
306
+ } else {
307
+ storeRef.current.dispatch({
308
+ type: "SET_CURRENT_STEP_ID",
309
+ payload: { stepId: "" }
310
+ });
311
+ storeRef.current.dispatch({
312
+ type: "SET_HISTORY",
313
+ payload: { history: [] }
314
+ });
315
+ }
316
+ persistenceAdapter.clear();
317
+ trackEvent("wizard_reset", { data: initialData });
318
+ }, [initialData, activeSteps, persistenceAdapter, trackEvent]);
319
+ const stateValue = useMemo(
320
+ () => ({
321
+ ...snapshot,
322
+ config: localConfig
323
+ }),
324
+ [snapshot, localConfig]
325
+ );
326
+ const actionsValue = useMemo(
327
+ () => ({
328
+ goToNextStep,
329
+ goToPrevStep,
330
+ goToStep: (sid, optionsOrUndefined, thirdArg) => {
331
+ let finalOptions = optionsOrUndefined;
332
+ if (thirdArg && optionsOrUndefined === void 0) {
333
+ finalOptions = thirdArg;
334
+ }
335
+ return goToStep(sid, void 0, finalOptions);
336
+ },
337
+ setStepData: (_stepId, data2) => {
338
+ const next = { ...storeRef.current.getSnapshot().data, ...data2 };
339
+ storeRef.current.update(next, Object.keys(data2));
340
+ },
341
+ handleStepChange: (f, v) => {
342
+ if (stateRef.current.currentStepId) setData(f, v);
343
+ },
344
+ validateStep: (sid) => validateStep(sid),
345
+ validateAll: async () => {
346
+ storeRef.current.updateMeta({ isBusy: true });
347
+ const data2 = storeRef.current.getSnapshot().data;
348
+ const active = await resolveActiveStepsHelper(data2);
349
+ const results = await Promise.all(
350
+ active.map((s) => validateStep(s.id))
351
+ );
352
+ storeRef.current.updateMeta({ isBusy: false });
353
+ return {
354
+ isValid: results.every(Boolean),
355
+ errors: storeRef.current.getSnapshot().errors
356
+ };
357
+ },
358
+ save: (ids) => {
359
+ if (ids === true) {
360
+ localConfig.steps.forEach(
361
+ (s) => storeRef.current.save(s.id)
362
+ );
363
+ } else if (!ids) {
364
+ storeRef.current.save();
365
+ } else {
366
+ (Array.isArray(ids) ? ids : [ids]).forEach((id) => storeRef.current.save(id));
367
+ }
368
+ },
369
+ clearStorage: () => persistenceAdapter.clear(),
370
+ reset,
371
+ setData,
372
+ updateData,
373
+ getData: (p, d) => getByPath(storeRef.current.getSnapshot().data, p, d),
374
+ updateConfig: (nc) => {
375
+ setLocalConfig((prev) => ({ ...prev, ...nc }));
376
+ }
377
+ }),
378
+ [
379
+ goToNextStep,
380
+ goToPrevStep,
381
+ goToStep,
382
+ validateStep,
383
+ reset,
384
+ setData,
385
+ updateData,
386
+ persistenceAdapter,
387
+ localConfig,
388
+ resolveActiveStepsHelper
389
+ ]
390
+ );
391
+ useEffect(() => {
392
+ if (!isInitialized.current) {
393
+ storeRef.current.injectPersistence(persistenceAdapter);
394
+ storeRef.current.dispatch({
395
+ type: "INIT",
396
+ payload: { data: initialData || {}, config: localConfig }
397
+ });
398
+ storeRef.current.hydrate();
399
+ isInitialized.current = true;
400
+ } else {
401
+ storeRef.current.updateMeta({ config: localConfig });
402
+ }
403
+ }, [initialData, localConfig, persistenceAdapter]);
404
+ useEffect(() => {
405
+ let isMounted = true;
406
+ const timeoutId = setTimeout(async () => {
407
+ const resolved = await resolveActiveStepsHelper(data);
408
+ if (isMounted) {
409
+ storeRef.current.dispatch({
410
+ type: "SET_ACTIVE_STEPS",
411
+ payload: { steps: resolved }
412
+ });
413
+ }
414
+ }, 200);
415
+ return () => {
416
+ isMounted = false;
417
+ clearTimeout(timeoutId);
418
+ };
419
+ }, [data, resolveActiveStepsHelper]);
420
+ const hasHydratedRef = useRef(false);
421
+ useEffect(() => {
422
+ if (hasHydratedRef.current) return;
423
+ hasHydratedRef.current = true;
424
+ const meta = persistenceAdapter.getStep(META_KEY);
425
+ if (meta) {
426
+ if (meta.currentStepId) {
427
+ storeRef.current.dispatch({
428
+ type: "SET_CURRENT_STEP_ID",
429
+ payload: { stepId: meta.currentStepId }
430
+ });
431
+ }
432
+ if (meta.visited)
433
+ storeRef.current.dispatch({
434
+ type: "SET_VISITED_STEPS",
435
+ payload: { steps: new Set(meta.visited) }
436
+ });
437
+ if (meta.completed)
438
+ storeRef.current.dispatch({
439
+ type: "SET_COMPLETED_STEPS",
440
+ payload: { steps: new Set(meta.completed) }
441
+ });
442
+ if (meta.history) {
443
+ storeRef.current.dispatch({
444
+ type: "SET_HISTORY",
445
+ payload: { history: meta.history }
446
+ });
447
+ }
448
+ }
449
+ const currentSnapshot = storeRef.current.getSnapshot();
450
+ const currentActiveSteps = currentSnapshot.activeSteps;
451
+ if (!currentSnapshot.currentStepId && currentActiveSteps.length > 0) {
452
+ const startId = initialStepId && currentActiveSteps.some((s) => s.id === initialStepId) ? initialStepId : currentActiveSteps[0].id;
453
+ storeRef.current.dispatch({
454
+ type: "SET_CURRENT_STEP_ID",
455
+ payload: { stepId: startId }
456
+ });
457
+ if (currentSnapshot.history.length === 0) {
458
+ storeRef.current.dispatch({
459
+ type: "SET_HISTORY",
460
+ payload: { history: [startId] }
461
+ });
462
+ }
463
+ const currentVisited = new Set(currentSnapshot.visitedSteps);
464
+ if (!currentVisited.has(startId)) {
465
+ currentVisited.add(startId);
466
+ storeRef.current.dispatch({
467
+ type: "SET_VISITED_STEPS",
468
+ payload: { steps: currentVisited }
469
+ });
470
+ }
471
+ }
472
+ if (currentActiveSteps.length > 0 && currentSnapshot.isLoading) {
473
+ storeRef.current.updateMeta({ isLoading: false });
474
+ }
475
+ }, [activeSteps, initialStepId, persistenceAdapter]);
476
+ return /* @__PURE__ */ jsx(WizardStoreContext.Provider, { value: storeRef.current, children: /* @__PURE__ */ jsx(WizardStateContext.Provider, { value: stateValue, children: /* @__PURE__ */ jsx(WizardActionsContext.Provider, { value: actionsValue, children }) }) });
477
+ }
478
+ function useWizardState() {
479
+ const context = useContext(WizardStateContext);
480
+ if (!context) throw new Error("useWizardState must be used within a WizardProvider");
481
+ return context;
482
+ }
483
+ function useWizardValue(path, options) {
484
+ const store = useContext(WizardStoreContext);
485
+ if (!store) throw new Error("useWizardValue must be used within a WizardProvider");
486
+ const lastStateRef = useRef(null);
487
+ const lastValueRef = useRef(null);
488
+ const getSnapshot = useCallback(() => {
489
+ const data = store.getSnapshot().data;
490
+ if (data === lastStateRef.current) return lastValueRef.current;
491
+ const value = getByPath(data, path);
492
+ if (lastValueRef.current !== void 0 && (options?.isEqual || Object.is)(lastValueRef.current, value)) {
493
+ lastStateRef.current = data;
494
+ return lastValueRef.current;
495
+ }
496
+ lastStateRef.current = data;
497
+ lastValueRef.current = value;
498
+ return value;
499
+ }, [store, path, options?.isEqual]);
500
+ return useSyncExternalStore(store.subscribe, getSnapshot);
501
+ }
502
+ function useWizardError(path) {
503
+ const store = useContext(WizardStoreContext);
504
+ if (!store) throw new Error("useWizardError must be used within a WizardProvider");
505
+ const getSnapshot = useCallback(() => {
506
+ const errors = store.getSnapshot().errors;
507
+ for (const [_, stepErrors] of Object.entries(errors)) {
508
+ const typed = stepErrors;
509
+ if (typed[path]) return typed[path];
510
+ }
511
+ return void 0;
512
+ }, [store, path]);
513
+ return useSyncExternalStore(store.subscribe, getSnapshot);
514
+ }
515
+ function useWizardSelector(selector, options) {
516
+ const store = useContext(WizardStoreContext);
517
+ if (!store) throw new Error("useWizardSelector must be used within a WizardProvider");
518
+ const lastResultRef = useRef(null);
519
+ const getSnapshot = useCallback(() => {
520
+ const full = store.getSnapshot();
521
+ const res = selector(full);
522
+ if (lastResultRef.current !== null && (options?.isEqual || Object.is)(lastResultRef.current, res)) {
523
+ return lastResultRef.current;
524
+ }
525
+ lastResultRef.current = res;
526
+ return res;
527
+ }, [store, selector, options?.isEqual]);
528
+ return useSyncExternalStore(store.subscribe, getSnapshot);
529
+ }
530
+ function useWizardActions() {
531
+ const context = useContext(WizardActionsContext);
532
+ if (!context) throw new Error("useWizardActions must be used within a WizardProvider");
533
+ return context;
534
+ }
535
+ function useWizardContext() {
536
+ const state = useWizardState();
537
+ const actions = useWizardActions();
538
+ const store = useContext(WizardStoreContext);
539
+ const data = useWizardSelector((s) => s.data);
540
+ const allErrors = useWizardSelector((s) => s.errors);
541
+ const errors = useMemo(() => {
542
+ const flat = {};
543
+ Object.values(allErrors).forEach((stepErrors) => {
544
+ Object.assign(flat, stepErrors);
545
+ });
546
+ return flat;
547
+ }, [allErrors]);
548
+ const { data: _d, errors: _e, ...stateProps } = state;
549
+ return useMemo(
550
+ () => ({
551
+ ...stateProps,
552
+ ...actions,
553
+ data,
554
+ allErrors,
555
+ errors,
556
+ store
557
+ }),
558
+ [stateProps, actions, data, allErrors, errors, store]
559
+ );
560
+ }
561
+
562
+ // src/hooks/useWizard.ts
563
+ var useWizard = () => {
564
+ return useWizardContext();
565
+ };
566
+
567
+ // src/factory.tsx
568
+ import { jsx as jsx2 } from "react/jsx-runtime";
569
+ function createWizardFactory() {
570
+ const WizardProvider2 = ({
571
+ config,
572
+ initialData,
573
+ children
574
+ }) => {
575
+ return /* @__PURE__ */ jsx2(WizardProvider, { config, initialData, children });
576
+ };
577
+ const useWizard2 = () => {
578
+ return useWizard();
579
+ };
580
+ const useWizardContext2 = () => {
581
+ return useWizardContext();
582
+ };
583
+ const useWizardValue2 = (path, options) => {
584
+ return useWizardValue(path, options);
585
+ };
586
+ const useWizardSelector2 = (selector, options) => {
587
+ return useWizardSelector(selector, options);
588
+ };
589
+ const useWizardError2 = (path) => {
590
+ return useWizardError(path);
591
+ };
592
+ const useWizardActions2 = () => {
593
+ return useWizardActions();
594
+ };
595
+ const useWizardState2 = () => {
596
+ return useWizardState();
597
+ };
598
+ const useBreadcrumbs = () => {
599
+ return useWizardState().breadcrumbs;
600
+ };
601
+ const createStep = (config) => config;
602
+ return {
603
+ WizardProvider: WizardProvider2,
604
+ useWizard: useWizard2,
605
+ useWizardContext: useWizardContext2,
606
+ useWizardValue: useWizardValue2,
607
+ useWizardSelector: useWizardSelector2,
608
+ useWizardError: useWizardError2,
609
+ useWizardActions: useWizardActions2,
610
+ useWizardState: useWizardState2,
611
+ useBreadcrumbs,
612
+ createStep
613
+ };
614
+ }
615
+
616
+ // src/components/WizardStepRenderer.tsx
617
+ import { useMemo as useMemo2, Suspense } from "react";
618
+ import { jsx as jsx3 } from "react/jsx-runtime";
619
+ var WizardStepRenderer = ({
620
+ wrapper: Wrapper,
621
+ fallback = null
622
+ }) => {
623
+ const { currentStep } = useWizardContext();
624
+ const StepComponent = useMemo2(() => {
625
+ if (!currentStep?.component) return null;
626
+ return currentStep.component;
627
+ }, [currentStep]);
628
+ if (!currentStep || !StepComponent) {
629
+ return null;
630
+ }
631
+ const content = /* @__PURE__ */ jsx3(Suspense, { fallback, children: /* @__PURE__ */ jsx3(StepComponent, {}) });
632
+ if (Wrapper) {
633
+ return /* @__PURE__ */ jsx3(Wrapper, { children: content }, currentStep.id);
634
+ }
635
+ return content;
636
+ };
637
+
638
+ // src/index.ts
639
+ import { WizardStore as WizardStore2 } from "@wizzard-packages/core";
640
+ import { loggerMiddleware } from "@wizzard-packages/middleware";
641
+ export {
642
+ WizardProvider,
643
+ WizardStepRenderer,
644
+ WizardStore2 as WizardStore,
645
+ createWizardFactory,
646
+ loggerMiddleware,
647
+ useWizard,
648
+ useWizardActions,
649
+ useWizardContext,
650
+ useWizardError,
651
+ useWizardSelector,
652
+ useWizardState,
653
+ useWizardValue
654
+ };
655
+ //# sourceMappingURL=index.js.map