wizzard-stepper-react 1.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.
@@ -0,0 +1,167 @@
1
+ import * as react_jsx_runtime from 'react/jsx-runtime';
2
+ import React from 'react';
3
+ import { ZodType } from 'zod';
4
+ import { Schema } from 'yup';
5
+
6
+ /**
7
+ * Validation Result Interface
8
+ */
9
+ type ValidationResult = {
10
+ isValid: boolean;
11
+ errors?: Record<string, string>;
12
+ };
13
+ /**
14
+ * Validator Adapter Interface
15
+ * TData: The type of data this validator expects
16
+ */
17
+ interface IValidatorAdapter<TData = unknown> {
18
+ validate: (data: TData) => Promise<ValidationResult> | ValidationResult;
19
+ }
20
+ /**
21
+ * Persistence Mode
22
+ * - 'onStepChange': Save when moving between steps (default)
23
+ * - 'onChange': Save on every data change (debounced)
24
+ * - 'manual': Save only when manually triggered
25
+ */
26
+ type PersistenceMode = 'onStepChange' | 'onChange' | 'manual';
27
+ /**
28
+ * Persistence Adapter Interface
29
+ */
30
+ interface IPersistenceAdapter {
31
+ saveStep: <T>(stepId: string, data: T) => void;
32
+ getStep: <T>(stepId: string) => T | undefined;
33
+ clear: () => void;
34
+ }
35
+ /**
36
+ * Step Configuration
37
+ * TStepData: Type of data for this step
38
+ * TGlobalContext: Type of the global wizard data
39
+ */
40
+ interface IStepConfig<TStepData = unknown, TGlobalContext = unknown> {
41
+ id: string;
42
+ label: string;
43
+ /**
44
+ * Predicate to determine if step should be included/visible.
45
+ * If returns false, step is strictly skipped.
46
+ */
47
+ condition?: (context: TGlobalContext) => boolean;
48
+ /**
49
+ * Adapter for validation logic
50
+ */
51
+ validationAdapter?: IValidatorAdapter<TStepData>;
52
+ /**
53
+ * Override global auto-validation setting for this step
54
+ */
55
+ autoValidate?: boolean;
56
+ }
57
+ /**
58
+ * Wizard Configuration
59
+ * T: Type of the Global Wizard Data
60
+ */
61
+ interface IWizardConfig<T = unknown> {
62
+ /**
63
+ * Array of step configurations
64
+ */
65
+ steps: IStepConfig<any, T>[];
66
+ /**
67
+ * Global auto-validation setting (default: true)
68
+ */
69
+ autoValidate?: boolean;
70
+ /**
71
+ * Persistence configuration
72
+ */
73
+ persistence?: {
74
+ mode?: PersistenceMode;
75
+ adapter?: IPersistenceAdapter;
76
+ /**
77
+ * Storage key prefix (default: 'wizard_')
78
+ */
79
+ storageKey?: string;
80
+ };
81
+ }
82
+ /**
83
+ * Core Wizard Context State
84
+ */
85
+ interface IWizardContext<T = unknown> {
86
+ currentStep: IStepConfig<any, T> | null;
87
+ currentStepIndex: number;
88
+ isFirstStep: boolean;
89
+ isLastStep: boolean;
90
+ isLoading: boolean;
91
+ /**
92
+ * Active steps (those meeting conditions)
93
+ */
94
+ activeSteps: IStepConfig<any, T>[];
95
+ /**
96
+ * Unified Wizard Data
97
+ */
98
+ wizardData: T;
99
+ /**
100
+ * Errors keyed by stepId -> field -> message
101
+ */
102
+ allErrors: Record<string, Record<string, string>>;
103
+ /**
104
+ * Steps Status
105
+ */
106
+ visitedSteps: Set<string>;
107
+ completedSteps: Set<string>;
108
+ errorSteps: Set<string>;
109
+ /**
110
+ * Navigation Actions
111
+ */
112
+ goToNextStep: () => Promise<void>;
113
+ goToPrevStep: () => void;
114
+ goToStep: (stepId: string) => void;
115
+ /**
116
+ * Data Actions
117
+ */
118
+ setStepData: (stepId: string, data: any) => void;
119
+ handleStepChange: (field: string, value: any) => void;
120
+ /**
121
+ * Validation & Persistence
122
+ */
123
+ validateStep: (stepId: string) => Promise<boolean>;
124
+ validateAll: () => Promise<boolean>;
125
+ save: () => void;
126
+ clearStorage: () => void;
127
+ }
128
+
129
+ interface WizardProviderProps<T> {
130
+ config: IWizardConfig<T>;
131
+ initialData?: T;
132
+ children: React.ReactNode;
133
+ }
134
+ declare function WizardProvider<T extends Record<string, any>>({ config, initialData, children, }: WizardProviderProps<T>): react_jsx_runtime.JSX.Element;
135
+ declare function useWizardContext<T = any>(): IWizardContext<T>;
136
+
137
+ declare const useWizard: <T = any>() => IWizardContext<T>;
138
+
139
+ declare class MemoryAdapter implements IPersistenceAdapter {
140
+ private storage;
141
+ saveStep<T>(stepId: string, data: T): void;
142
+ getStep<T>(stepId: string): T | undefined;
143
+ clear(): void;
144
+ }
145
+
146
+ declare class LocalStorageAdapter implements IPersistenceAdapter {
147
+ private prefix;
148
+ constructor(prefix?: string);
149
+ private getKey;
150
+ saveStep<T>(stepId: string, data: T): void;
151
+ getStep<T>(stepId: string): T | undefined;
152
+ clear(): void;
153
+ }
154
+
155
+ declare class ZodAdapter<T> implements IValidatorAdapter<T> {
156
+ private schema;
157
+ constructor(schema: ZodType<T>);
158
+ validate(data: T): Promise<ValidationResult>;
159
+ }
160
+
161
+ declare class YupAdapter<T> implements IValidatorAdapter<T> {
162
+ private schema;
163
+ constructor(schema: Schema<T>);
164
+ validate(data: T): Promise<ValidationResult>;
165
+ }
166
+
167
+ export { type IPersistenceAdapter, type IStepConfig, type IValidatorAdapter, type IWizardConfig, type IWizardContext, LocalStorageAdapter, MemoryAdapter, type PersistenceMode, type ValidationResult, WizardProvider, YupAdapter, ZodAdapter, useWizard, useWizardContext };