wizzard-stepper-react 1.5.1 → 1.7.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 +431 -370
- package/dist/index.cjs +375 -175
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +101 -49
- package/dist/index.d.ts +101 -49
- package/dist/index.js +373 -175
- package/dist/index.js.map +1 -1
- package/package.json +93 -88
package/dist/index.d.ts
CHANGED
|
@@ -22,6 +22,13 @@ interface IValidatorAdapter<TData = unknown> {
|
|
|
22
22
|
* - 'manual': Save only when manually triggered
|
|
23
23
|
*/
|
|
24
24
|
type PersistenceMode = 'onStepChange' | 'onChange' | 'manual';
|
|
25
|
+
/**
|
|
26
|
+
* Validation Mode
|
|
27
|
+
* - 'onChange': Validate on every data change (debounced)
|
|
28
|
+
* - 'onStepChange': Validate only when moving to next step
|
|
29
|
+
* - 'manual': Validate only when manually triggered
|
|
30
|
+
*/
|
|
31
|
+
type ValidationMode = 'onChange' | 'onStepChange' | 'manual';
|
|
25
32
|
/**
|
|
26
33
|
* Persistence Adapter Interface
|
|
27
34
|
*/
|
|
@@ -35,8 +42,8 @@ interface IPersistenceAdapter {
|
|
|
35
42
|
* TStepData: Type of data for this step
|
|
36
43
|
* TGlobalContext: Type of the global wizard data
|
|
37
44
|
*/
|
|
38
|
-
interface IStepConfig<TStepData = unknown, TGlobalContext = unknown> {
|
|
39
|
-
id:
|
|
45
|
+
interface IStepConfig<TStepData = unknown, TGlobalContext = unknown, StepId extends string = string> {
|
|
46
|
+
id: StepId;
|
|
40
47
|
label: string;
|
|
41
48
|
/**
|
|
42
49
|
* Predicate to determine if step should be included/visible.
|
|
@@ -49,8 +56,16 @@ interface IStepConfig<TStepData = unknown, TGlobalContext = unknown> {
|
|
|
49
56
|
validationAdapter?: IValidatorAdapter<TStepData>;
|
|
50
57
|
/**
|
|
51
58
|
* Override global auto-validation setting for this step
|
|
59
|
+
* @deprecated Use validationMode instead
|
|
52
60
|
*/
|
|
53
61
|
autoValidate?: boolean;
|
|
62
|
+
/**
|
|
63
|
+
* Control when validation occurs for this step.
|
|
64
|
+
* - 'onChange': Validate on every keystroke (debounced)
|
|
65
|
+
* - 'onStepChange': Validate only when attempting to leave the step
|
|
66
|
+
* - 'manual': Only validate when explicitly triggered
|
|
67
|
+
*/
|
|
68
|
+
validationMode?: ValidationMode;
|
|
54
69
|
/**
|
|
55
70
|
* Optional React Component to render for this step.
|
|
56
71
|
* Used by the <WizardStepRenderer /> component.
|
|
@@ -60,20 +75,32 @@ interface IStepConfig<TStepData = unknown, TGlobalContext = unknown> {
|
|
|
60
75
|
* Override global persistence adapter for this specific step.
|
|
61
76
|
*/
|
|
62
77
|
persistenceAdapter?: IPersistenceAdapter;
|
|
78
|
+
/**
|
|
79
|
+
* Control when persistence occurs for this specific step.
|
|
80
|
+
* - 'onStepChange': Save when moving between steps (default)
|
|
81
|
+
* - 'onChange': Save on every data change (debounced)
|
|
82
|
+
* - 'manual': Save only when manually triggered
|
|
83
|
+
*/
|
|
84
|
+
persistenceMode?: PersistenceMode;
|
|
63
85
|
}
|
|
64
86
|
/**
|
|
65
87
|
* Wizard Configuration
|
|
66
88
|
* T: Type of the Global Wizard Data
|
|
67
89
|
*/
|
|
68
|
-
interface IWizardConfig<T = unknown> {
|
|
90
|
+
interface IWizardConfig<T = unknown, StepId extends string = string> {
|
|
69
91
|
/**
|
|
70
92
|
* Array of step configurations
|
|
71
93
|
*/
|
|
72
|
-
steps: IStepConfig<unknown, T>[];
|
|
94
|
+
steps: IStepConfig<unknown, T, StepId>[];
|
|
73
95
|
/**
|
|
74
96
|
* Global auto-validation setting (default: true)
|
|
97
|
+
* @deprecated Use validationMode instead
|
|
75
98
|
*/
|
|
76
99
|
autoValidate?: boolean;
|
|
100
|
+
/**
|
|
101
|
+
* Default validation mode for all steps (default: 'onChange')
|
|
102
|
+
*/
|
|
103
|
+
validationMode?: ValidationMode;
|
|
77
104
|
/**
|
|
78
105
|
* Persistence configuration
|
|
79
106
|
*/
|
|
@@ -89,13 +116,13 @@ interface IWizardConfig<T = unknown> {
|
|
|
89
116
|
* Callback triggered when step changes.
|
|
90
117
|
* Useful for routing integration or analytics.
|
|
91
118
|
*/
|
|
92
|
-
onStepChange?: (fromStep:
|
|
119
|
+
onStepChange?: (fromStep: StepId | null, toStep: StepId, data: T) => void;
|
|
93
120
|
}
|
|
94
121
|
/**
|
|
95
122
|
* Core Wizard Context State
|
|
96
123
|
*/
|
|
97
|
-
interface IWizardContext<T = unknown> {
|
|
98
|
-
currentStep: IStepConfig<unknown, T> | null;
|
|
124
|
+
interface IWizardContext<T = unknown, StepId extends string = string> {
|
|
125
|
+
currentStep: IStepConfig<unknown, T, StepId> | null;
|
|
99
126
|
currentStepIndex: number;
|
|
100
127
|
isFirstStep: boolean;
|
|
101
128
|
isLastStep: boolean;
|
|
@@ -104,7 +131,7 @@ interface IWizardContext<T = unknown> {
|
|
|
104
131
|
/**
|
|
105
132
|
* Active steps (those meeting conditions)
|
|
106
133
|
*/
|
|
107
|
-
activeSteps: IStepConfig<unknown, T>[];
|
|
134
|
+
activeSteps: IStepConfig<unknown, T, StepId>[];
|
|
108
135
|
/**
|
|
109
136
|
* Unified Wizard Data
|
|
110
137
|
*/
|
|
@@ -116,19 +143,19 @@ interface IWizardContext<T = unknown> {
|
|
|
116
143
|
/**
|
|
117
144
|
* Steps Status
|
|
118
145
|
*/
|
|
119
|
-
visitedSteps: Set<
|
|
120
|
-
completedSteps: Set<
|
|
121
|
-
errorSteps: Set<
|
|
146
|
+
visitedSteps: Set<StepId>;
|
|
147
|
+
completedSteps: Set<StepId>;
|
|
148
|
+
errorSteps: Set<StepId>;
|
|
122
149
|
/**
|
|
123
150
|
* Navigation Actions
|
|
124
151
|
*/
|
|
125
152
|
goToNextStep: () => Promise<void>;
|
|
126
153
|
goToPrevStep: () => void;
|
|
127
|
-
goToStep: (stepId:
|
|
154
|
+
goToStep: (stepId: StepId) => Promise<boolean>;
|
|
128
155
|
/**
|
|
129
156
|
* Data Actions
|
|
130
157
|
*/
|
|
131
|
-
setStepData: (stepId:
|
|
158
|
+
setStepData: (stepId: StepId, data: unknown) => void;
|
|
132
159
|
handleStepChange: (field: string, value: unknown) => void;
|
|
133
160
|
/**
|
|
134
161
|
* Set data by path (supports dot notation and arrays, e.g., 'user.name' or 'items[0].value')
|
|
@@ -151,75 +178,84 @@ interface IWizardContext<T = unknown> {
|
|
|
151
178
|
/**
|
|
152
179
|
* Validation & Persistence
|
|
153
180
|
*/
|
|
154
|
-
validateStep: (sid:
|
|
181
|
+
validateStep: (sid: StepId) => Promise<boolean>;
|
|
155
182
|
validateAll: () => Promise<{
|
|
156
183
|
isValid: boolean;
|
|
157
184
|
errors: Record<string, Record<string, string>>;
|
|
158
185
|
}>;
|
|
159
|
-
save: () => void;
|
|
186
|
+
save: (stepIds?: StepId | StepId[] | boolean) => void;
|
|
160
187
|
clearStorage: () => void;
|
|
161
188
|
}
|
|
162
189
|
|
|
163
|
-
interface IWizardState<T = unknown> {
|
|
164
|
-
currentStep: IStepConfig<unknown, T> | null;
|
|
190
|
+
interface IWizardState<T = unknown, StepId extends string = string> {
|
|
191
|
+
currentStep: IStepConfig<unknown, T, StepId> | null;
|
|
165
192
|
currentStepIndex: number;
|
|
166
193
|
isFirstStep: boolean;
|
|
167
194
|
isLastStep: boolean;
|
|
168
195
|
isLoading: boolean;
|
|
169
196
|
isPending: boolean;
|
|
170
|
-
activeSteps: IStepConfig<unknown, T>[];
|
|
171
|
-
visitedSteps: Set<
|
|
172
|
-
completedSteps: Set<
|
|
173
|
-
errorSteps: Set<
|
|
197
|
+
activeSteps: IStepConfig<unknown, T, StepId>[];
|
|
198
|
+
visitedSteps: Set<StepId>;
|
|
199
|
+
completedSteps: Set<StepId>;
|
|
200
|
+
errorSteps: Set<StepId>;
|
|
174
201
|
store: WizardStore<T>;
|
|
175
202
|
}
|
|
176
|
-
interface IWizardActions {
|
|
203
|
+
interface IWizardActions<StepId extends string = string> {
|
|
177
204
|
goToNextStep: () => Promise<void>;
|
|
178
205
|
goToPrevStep: () => void;
|
|
179
|
-
goToStep: (stepId:
|
|
180
|
-
setStepData: (stepId:
|
|
206
|
+
goToStep: (stepId: StepId) => Promise<boolean>;
|
|
207
|
+
setStepData: (stepId: StepId, data: unknown) => void;
|
|
181
208
|
handleStepChange: (field: string, value: unknown) => void;
|
|
182
|
-
validateStep: (sid:
|
|
209
|
+
validateStep: (sid: StepId) => Promise<boolean>;
|
|
183
210
|
validateAll: () => Promise<{
|
|
184
211
|
isValid: boolean;
|
|
185
212
|
errors: Record<string, Record<string, string>>;
|
|
186
213
|
}>;
|
|
187
|
-
save: () => void;
|
|
214
|
+
save: (stepIds?: StepId | StepId[] | boolean) => void;
|
|
188
215
|
clearStorage: () => void;
|
|
189
216
|
setData: (path: string, value: unknown, options?: {
|
|
190
217
|
debounceValidation?: number;
|
|
191
218
|
}) => void;
|
|
192
219
|
updateData: (data: Partial<any>, options?: {
|
|
193
220
|
replace?: boolean;
|
|
221
|
+
persist?: boolean;
|
|
194
222
|
}) => void;
|
|
195
223
|
getData: (path: string, defaultValue?: unknown) => unknown;
|
|
196
224
|
}
|
|
197
225
|
declare class WizardStore<T> {
|
|
198
226
|
private state;
|
|
199
227
|
private listeners;
|
|
228
|
+
errorsMap: Map<string, Map<string, string>>;
|
|
200
229
|
constructor(initialData: T);
|
|
201
|
-
getSnapshot
|
|
230
|
+
getSnapshot(): {
|
|
202
231
|
data: T;
|
|
203
232
|
errors: Record<string, Record<string, string>>;
|
|
204
233
|
};
|
|
205
234
|
update(newData: T): void;
|
|
235
|
+
private syncErrors;
|
|
206
236
|
updateErrors(newErrors: Record<string, Record<string, string>>): void;
|
|
237
|
+
setStepErrors(stepId: string, errors: Record<string, string> | undefined | null): boolean;
|
|
238
|
+
deleteError(stepId: string, path: string): boolean;
|
|
207
239
|
private notify;
|
|
208
240
|
subscribe: (listener: () => void) => () => boolean;
|
|
209
241
|
}
|
|
210
|
-
interface WizardProviderProps<T> {
|
|
211
|
-
config: IWizardConfig<T>;
|
|
242
|
+
interface WizardProviderProps<T, StepId extends string> {
|
|
243
|
+
config: IWizardConfig<T, StepId>;
|
|
212
244
|
initialData?: T;
|
|
213
|
-
initialStepId?:
|
|
245
|
+
initialStepId?: StepId;
|
|
214
246
|
children: React$1.ReactNode;
|
|
215
247
|
}
|
|
216
|
-
declare function WizardProvider<T extends Record<string, any
|
|
217
|
-
declare function useWizardState<T = unknown>(): IWizardState<T>;
|
|
218
|
-
declare function useWizardValue<TValue = any>(path: string
|
|
248
|
+
declare function WizardProvider<T extends Record<string, any>, StepId extends string = string>({ config, initialData, initialStepId, children, }: WizardProviderProps<T, StepId>): react_jsx_runtime.JSX.Element;
|
|
249
|
+
declare function useWizardState<T = unknown, StepId extends string = string>(): IWizardState<T, StepId>;
|
|
250
|
+
declare function useWizardValue<TValue = any>(path: string, options?: {
|
|
251
|
+
isEqual?: (a: TValue, b: TValue) => boolean;
|
|
252
|
+
}): TValue;
|
|
219
253
|
declare function useWizardError(path: string): string | undefined;
|
|
220
|
-
declare function useWizardSelector<TSelected = any>(selector: (state: any) => TSelected
|
|
221
|
-
|
|
222
|
-
|
|
254
|
+
declare function useWizardSelector<TSelected = any>(selector: (state: any) => TSelected, options?: {
|
|
255
|
+
isEqual?: (a: TSelected, b: TSelected) => boolean;
|
|
256
|
+
}): TSelected;
|
|
257
|
+
declare function useWizardActions<StepId extends string = string>(): IWizardActions<StepId>;
|
|
258
|
+
declare function useWizardContext<T = any, StepId extends string = string>(): IWizardContext<T, StepId> & {
|
|
223
259
|
store: WizardStore<T>;
|
|
224
260
|
};
|
|
225
261
|
|
|
@@ -268,25 +304,29 @@ type PathValue<T, P extends Path<T>> = T extends any ? P extends `${infer K}.${i
|
|
|
268
304
|
*
|
|
269
305
|
* @template TSchema The shape of your wizard's global data state
|
|
270
306
|
*/
|
|
271
|
-
declare function createWizardFactory<TSchema extends Record<string, any
|
|
307
|
+
declare function createWizardFactory<TSchema extends Record<string, any>, StepId extends string = string>(): {
|
|
272
308
|
WizardProvider: ({ config, initialData, children, }: {
|
|
273
|
-
config: IWizardConfig<TSchema>;
|
|
309
|
+
config: IWizardConfig<TSchema, StepId>;
|
|
274
310
|
initialData?: Partial<TSchema>;
|
|
275
311
|
children: React$1.ReactNode;
|
|
276
312
|
}) => react_jsx_runtime.JSX.Element;
|
|
277
|
-
useWizard: () => IWizardContext<TSchema>;
|
|
278
|
-
useWizardContext: () => IWizardContext<TSchema> & {
|
|
313
|
+
useWizard: () => IWizardContext<TSchema, StepId>;
|
|
314
|
+
useWizardContext: () => IWizardContext<TSchema, StepId> & {
|
|
279
315
|
store: WizardStore<TSchema>;
|
|
280
316
|
};
|
|
281
|
-
useWizardValue: <P extends Path<TSchema>>(path: P
|
|
282
|
-
|
|
317
|
+
useWizardValue: <P extends Path<TSchema>>(path: P, options?: {
|
|
318
|
+
isEqual?: (a: PathValue<TSchema, P>, b: PathValue<TSchema, P>) => boolean;
|
|
319
|
+
}) => PathValue<TSchema, P>;
|
|
320
|
+
useWizardSelector: <TSelected>(selector: (state: TSchema) => TSelected, options?: {
|
|
321
|
+
isEqual?: (a: TSelected, b: TSelected) => boolean;
|
|
322
|
+
}) => TSelected;
|
|
283
323
|
useWizardError: <P extends Path<TSchema>>(path: P) => string | undefined;
|
|
284
|
-
useWizardActions: () => IWizardActions
|
|
285
|
-
useWizardState: () => IWizardState<
|
|
286
|
-
createStep: <TStepData = unknown>(config: IStepConfig<TStepData, TSchema>) => IStepConfig<TStepData, TSchema>;
|
|
324
|
+
useWizardActions: () => IWizardActions<StepId>;
|
|
325
|
+
useWizardState: () => IWizardState<TSchema, StepId>;
|
|
326
|
+
createStep: <TStepData = unknown>(config: IStepConfig<TStepData, TSchema, StepId>) => IStepConfig<TStepData, TSchema, StepId>;
|
|
287
327
|
};
|
|
288
328
|
|
|
289
|
-
declare const useWizard: <T = any>() => IWizardContext<T>;
|
|
329
|
+
declare const useWizard: <T = any, StepId extends string = string>() => IWizardContext<T, StepId>;
|
|
290
330
|
|
|
291
331
|
declare class MemoryAdapter implements IPersistenceAdapter {
|
|
292
332
|
private storage;
|
|
@@ -341,12 +381,24 @@ declare class YupAdapter<T> implements IValidatorAdapter<T> {
|
|
|
341
381
|
}
|
|
342
382
|
|
|
343
383
|
/**
|
|
344
|
-
*
|
|
384
|
+
* Parses a string path into an array of keys using a cache.
|
|
385
|
+
* Handles dot notation "a.b" and bracket notation "a[0].b".
|
|
386
|
+
*/
|
|
387
|
+
declare function toPath(path: string): string[];
|
|
388
|
+
/**
|
|
389
|
+
* Retrieves a value from an object by path using cached key parsing.
|
|
390
|
+
* Optimized for frequent access.
|
|
345
391
|
*/
|
|
346
392
|
declare function getByPath(obj: any, path: string, defaultValue?: unknown): unknown;
|
|
347
393
|
/**
|
|
348
|
-
* Immutably sets a value in an object by path
|
|
394
|
+
* Immutably sets a value in an object by path.
|
|
395
|
+
* iterative implementation (stack-safe and usually faster).
|
|
349
396
|
*/
|
|
350
397
|
declare function setByPath<T extends object>(obj: T, path: string, value: unknown): T;
|
|
398
|
+
/**
|
|
399
|
+
* Simple shallow equality check for objects and arrays.
|
|
400
|
+
* Useful for preventing re-renders in selectors.
|
|
401
|
+
*/
|
|
402
|
+
declare function shallowEqual(a: any, b: any): boolean;
|
|
351
403
|
|
|
352
|
-
export { type IPersistenceAdapter, type IStepConfig, type IValidatorAdapter, type IWizardActions, type IWizardConfig, type IWizardContext, type IWizardState, LocalStorageAdapter, MemoryAdapter, type PersistenceMode, type ValidationResult, WizardProvider, WizardStepRenderer, WizardStore, YupAdapter, ZodAdapter, createWizardFactory, getByPath, setByPath, useWizard, useWizardActions, useWizardContext, useWizardError, useWizardSelector, useWizardState, useWizardValue };
|
|
404
|
+
export { type IPersistenceAdapter, type IStepConfig, type IValidatorAdapter, type IWizardActions, type IWizardConfig, type IWizardContext, type IWizardState, LocalStorageAdapter, MemoryAdapter, type PersistenceMode, type ValidationMode, type ValidationResult, WizardProvider, WizardStepRenderer, WizardStore, YupAdapter, ZodAdapter, createWizardFactory, getByPath, setByPath, shallowEqual, toPath, useWizard, useWizardActions, useWizardContext, useWizardError, useWizardSelector, useWizardState, useWizardValue };
|