@wizzard-packages/react 0.1.1 → 0.3.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/README.md +283 -1
- package/dist/index.cjs +573 -89
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +127 -17
- package/dist/index.d.ts +127 -17
- package/dist/index.js +566 -88
- package/dist/index.js.map +1 -1
- package/package.json +4 -4
package/dist/index.d.ts
CHANGED
|
@@ -1,10 +1,41 @@
|
|
|
1
1
|
import * as _wizzard_packages_core from '@wizzard-packages/core';
|
|
2
|
-
import {
|
|
2
|
+
import { IWizardActions as IWizardActions$1, Path, PathValue, IWizardContext as IWizardContext$1, IWizardState, IWizardConfig, IStepConfig, IWizardStore } from '@wizzard-packages/core';
|
|
3
3
|
export { IStepConfig, IValidatorAdapter, IWizardActions, IWizardConfig, IWizardContext, IWizardState, PersistenceMode, ValidationResult, WizardMiddleware, WizardStore } from '@wizzard-packages/core';
|
|
4
4
|
import * as react_jsx_runtime from 'react/jsx-runtime';
|
|
5
5
|
import React from 'react';
|
|
6
6
|
export { loggerMiddleware } from '@wizzard-packages/middleware';
|
|
7
7
|
|
|
8
|
+
/**
|
|
9
|
+
* Handle returned by components for imperative access to the wizard.
|
|
10
|
+
*/
|
|
11
|
+
interface IWizardHandle<T = unknown, StepId extends string = string> {
|
|
12
|
+
state: IWizardState<T, StepId>;
|
|
13
|
+
actions: IWizardActions<StepId>;
|
|
14
|
+
}
|
|
15
|
+
/**
|
|
16
|
+
* React-specific actions
|
|
17
|
+
*/
|
|
18
|
+
interface IWizardActions<StepId extends string = string> extends IWizardActions$1<StepId> {
|
|
19
|
+
}
|
|
20
|
+
/**
|
|
21
|
+
* Typed actions for strongly-typed paths.
|
|
22
|
+
*/
|
|
23
|
+
type IWizardActionsTyped<T, StepId extends string = string> = Omit<IWizardActions$1<StepId>, 'setData' | 'updateData' | 'getData'> & {
|
|
24
|
+
setData: <P extends Path<T>>(path: P, value: PathValue<T, P>, options?: {
|
|
25
|
+
debounceValidation?: number;
|
|
26
|
+
}) => void;
|
|
27
|
+
updateData: (data: Partial<T>, options?: {
|
|
28
|
+
replace?: boolean;
|
|
29
|
+
persist?: boolean;
|
|
30
|
+
}) => void;
|
|
31
|
+
getData: <P extends Path<T>>(path: P, defaultValue?: PathValue<T, P>) => PathValue<T, P>;
|
|
32
|
+
};
|
|
33
|
+
/**
|
|
34
|
+
* Core Wizard Context State
|
|
35
|
+
*/
|
|
36
|
+
interface IWizardContext<T = unknown, StepId extends string = string> extends IWizardContext$1<T, StepId> {
|
|
37
|
+
}
|
|
38
|
+
|
|
8
39
|
/**
|
|
9
40
|
* createWizardFactory
|
|
10
41
|
*
|
|
@@ -13,9 +44,10 @@ export { loggerMiddleware } from '@wizzard-packages/middleware';
|
|
|
13
44
|
* @template TSchema The shape of your wizard's global data state
|
|
14
45
|
*/
|
|
15
46
|
declare function createWizardFactory<TSchema extends Record<string, any>, StepId extends string = string>(): {
|
|
16
|
-
WizardProvider: ({ config, initialData, children, }: {
|
|
47
|
+
WizardProvider: ({ config, initialData, initialStepId, children, }: {
|
|
17
48
|
config: IWizardConfig<TSchema, StepId>;
|
|
18
49
|
initialData?: Partial<TSchema>;
|
|
50
|
+
initialStepId?: StepId;
|
|
19
51
|
children: React.ReactNode;
|
|
20
52
|
}) => react_jsx_runtime.JSX.Element;
|
|
21
53
|
useWizard: () => IWizardContext$1<TSchema, StepId>;
|
|
@@ -23,11 +55,14 @@ declare function createWizardFactory<TSchema extends Record<string, any>, StepId
|
|
|
23
55
|
useWizardValue: <P extends Path<TSchema>>(path: P, options?: {
|
|
24
56
|
isEqual?: (a: PathValue<TSchema, P>, b: PathValue<TSchema, P>) => boolean;
|
|
25
57
|
}) => PathValue<TSchema, P>;
|
|
58
|
+
useWizardField: <P extends Path<TSchema>>(path: P, options?: {
|
|
59
|
+
isEqual?: (a: PathValue<TSchema, P>, b: PathValue<TSchema, P>) => boolean;
|
|
60
|
+
}) => [PathValue<TSchema, P>, (value: PathValue<TSchema, P>) => void];
|
|
26
61
|
useWizardSelector: <TSelected>(selector: (state: IWizardContext$1<TSchema, StepId>) => TSelected, options?: {
|
|
27
62
|
isEqual?: (a: TSelected, b: TSelected) => boolean;
|
|
28
63
|
}) => TSelected;
|
|
29
64
|
useWizardError: <P extends Path<TSchema>>(path: P) => string | undefined;
|
|
30
|
-
useWizardActions: () =>
|
|
65
|
+
useWizardActions: () => IWizardActionsTyped<TSchema, StepId>;
|
|
31
66
|
useWizardState: () => _wizzard_packages_core.IWizardState<TSchema, StepId>;
|
|
32
67
|
useBreadcrumbs: () => _wizzard_packages_core.IBreadcrumb<StepId>[];
|
|
33
68
|
createStep: (config: IStepConfig<TSchema, StepId>) => IStepConfig<TSchema, StepId>;
|
|
@@ -56,6 +91,12 @@ declare function useWizardState<T = unknown, StepId extends string = string>():
|
|
|
56
91
|
declare function useWizardValue<TValue = any>(path: string, options?: {
|
|
57
92
|
isEqual?: (a: TValue, b: TValue) => boolean;
|
|
58
93
|
}): TValue;
|
|
94
|
+
/**
|
|
95
|
+
* Returns a value and setter for a path (useState-like API).
|
|
96
|
+
*/
|
|
97
|
+
declare function useWizardField<T, P extends Path<T>>(path: P, options?: {
|
|
98
|
+
isEqual?: (a: PathValue<T, P>, b: PathValue<T, P>) => boolean;
|
|
99
|
+
}): [PathValue<T, P>, (value: PathValue<T, P>) => void];
|
|
59
100
|
/**
|
|
60
101
|
* Returns the first error message for a path across all steps.
|
|
61
102
|
*/
|
|
@@ -74,6 +115,37 @@ declare function useWizardActions<StepId extends string = string>(): IWizardActi
|
|
|
74
115
|
* Returns combined wizard state, actions, and derived errors.
|
|
75
116
|
*/
|
|
76
117
|
declare function useWizardContext<T = any, StepId extends string = string>(): IWizardContext$1<T, StepId>;
|
|
118
|
+
/**
|
|
119
|
+
* Returns current step config.
|
|
120
|
+
*/
|
|
121
|
+
declare function useWizardCurrentStep<T = any, StepId extends string = string>(): IStepConfig<T, StepId> | null;
|
|
122
|
+
/**
|
|
123
|
+
* Returns active steps list.
|
|
124
|
+
*/
|
|
125
|
+
declare function useWizardSteps<T = any, StepId extends string = string>(): IStepConfig<T, StepId>[];
|
|
126
|
+
/**
|
|
127
|
+
* Returns frequently-used meta state with shallow equality.
|
|
128
|
+
*/
|
|
129
|
+
declare function useWizardMeta<T = any, StepId extends string = string>(): {
|
|
130
|
+
currentStepId: "" | StepId;
|
|
131
|
+
currentStepIndex: number;
|
|
132
|
+
isFirstStep: boolean;
|
|
133
|
+
isLastStep: boolean;
|
|
134
|
+
isLoading: boolean;
|
|
135
|
+
isBusy: boolean;
|
|
136
|
+
isDirty: boolean;
|
|
137
|
+
progress: number;
|
|
138
|
+
activeStepsCount: number;
|
|
139
|
+
goToStepResult: boolean | "init" | null | undefined;
|
|
140
|
+
};
|
|
141
|
+
/**
|
|
142
|
+
* Returns all errors by step (shallow-equal).
|
|
143
|
+
*/
|
|
144
|
+
declare function useWizardAllErrors<T = any, StepId extends string = string>(): Record<StepId, Record<string, string>>;
|
|
145
|
+
/**
|
|
146
|
+
* Returns flattened errors map (path -> message).
|
|
147
|
+
*/
|
|
148
|
+
declare function useWizardFlatErrors<T = any, StepId extends string = string>(): Record<string, string>;
|
|
77
149
|
|
|
78
150
|
/**
|
|
79
151
|
* Props for rendering the current step component.
|
|
@@ -91,26 +163,64 @@ interface WizardStepRendererProps {
|
|
|
91
163
|
declare const WizardStepRenderer: React.FC<WizardStepRendererProps>;
|
|
92
164
|
|
|
93
165
|
/**
|
|
94
|
-
*
|
|
166
|
+
* Alias for useWizardContext.
|
|
95
167
|
*/
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
168
|
+
declare const useWizard: <T = any, StepId extends string = string>() => IWizardContext<T, StepId>;
|
|
169
|
+
|
|
170
|
+
interface CreateWizardStoreOptions<T, StepId extends string = string> {
|
|
171
|
+
config: IWizardConfig<T, StepId>;
|
|
172
|
+
initialData?: T;
|
|
173
|
+
initialStepId?: StepId;
|
|
174
|
+
}
|
|
175
|
+
interface WizardStoreBundle<T, StepId extends string = string> {
|
|
176
|
+
store: IWizardStore<T, StepId>;
|
|
177
|
+
actions: IWizardActionsTyped<T, StepId>;
|
|
99
178
|
}
|
|
100
179
|
/**
|
|
101
|
-
* React
|
|
180
|
+
* Create a standalone store + actions bundle without React Context.
|
|
102
181
|
*/
|
|
103
|
-
|
|
104
|
-
}
|
|
182
|
+
declare const createWizardStore: <T extends Record<string, any>, StepId extends string = string>(options: CreateWizardStoreOptions<T, StepId>) => WizardStoreBundle<T, StepId>;
|
|
105
183
|
/**
|
|
106
|
-
*
|
|
184
|
+
* Hook: read the full store snapshot without React Context.
|
|
107
185
|
*/
|
|
108
|
-
|
|
109
|
-
}
|
|
110
|
-
|
|
186
|
+
declare const useWizardStoreState: <T, StepId extends string = string>(store: IWizardStore<T, StepId>) => IWizardState<T, StepId>;
|
|
111
187
|
/**
|
|
112
|
-
*
|
|
188
|
+
* Hook: subscribe to a value path without React Context.
|
|
113
189
|
*/
|
|
114
|
-
declare const
|
|
190
|
+
declare const useWizardStoreValue: <T, P extends Path<T>>(store: IWizardStore<T, any>, path: P, options?: {
|
|
191
|
+
isEqual?: (a: PathValue<T, P>, b: PathValue<T, P>) => boolean;
|
|
192
|
+
}) => PathValue<T, P>;
|
|
193
|
+
/**
|
|
194
|
+
* Hook: value + setter for a path without React Context.
|
|
195
|
+
*/
|
|
196
|
+
declare const useWizardStoreField: <T, P extends Path<T>>(store: IWizardStore<T, any>, setData: (path: P, value: PathValue<T, P>) => void, path: P, options?: {
|
|
197
|
+
isEqual?: (a: PathValue<T, P>, b: PathValue<T, P>) => boolean;
|
|
198
|
+
}) => [PathValue<T, P>, (value: PathValue<T, P>) => void];
|
|
199
|
+
/**
|
|
200
|
+
* Hook: read the first error for a path without React Context.
|
|
201
|
+
*/
|
|
202
|
+
declare const useWizardStoreError: (store: IWizardStore<any, any>, path: string) => string | undefined;
|
|
203
|
+
/**
|
|
204
|
+
* Hook: select derived state without React Context.
|
|
205
|
+
*/
|
|
206
|
+
declare const useWizardStoreSelector: <TSelected>(store: IWizardStore<any, any>, selector: (state: any) => TSelected, options?: {
|
|
207
|
+
isEqual?: (a: TSelected, b: TSelected) => boolean;
|
|
208
|
+
}) => TSelected;
|
|
209
|
+
/**
|
|
210
|
+
* Helper: build store-bound hooks for a single store instance.
|
|
211
|
+
*/
|
|
212
|
+
declare const createWizardHooks: <T, StepId extends string = string>(store: IWizardStore<T, StepId>, actions?: IWizardActionsTyped<T, StepId>) => {
|
|
213
|
+
useWizardState: () => IWizardState<T, StepId>;
|
|
214
|
+
useWizardValue: <P extends Path<T>>(path: P, options?: {
|
|
215
|
+
isEqual?: (a: PathValue<T, P>, b: PathValue<T, P>) => boolean;
|
|
216
|
+
}) => PathValue<T, P>;
|
|
217
|
+
useWizardField: <P extends Path<T>>(path: P, options?: {
|
|
218
|
+
isEqual?: (a: PathValue<T, P>, b: PathValue<T, P>) => boolean;
|
|
219
|
+
}) => [PathValue<T, P>, (value: PathValue<T, P>) => void];
|
|
220
|
+
useWizardError: (path: string) => string | undefined;
|
|
221
|
+
useWizardSelector: <TSelected>(selector: (state: IWizardState<T, StepId>) => TSelected, options?: {
|
|
222
|
+
isEqual?: (a: TSelected, b: TSelected) => boolean;
|
|
223
|
+
}) => TSelected;
|
|
224
|
+
};
|
|
115
225
|
|
|
116
|
-
export { type IWizardHandle, WizardProvider, type WizardProviderProps, WizardStepRenderer, type WizardStepRendererProps, createWizardFactory, useWizard, useWizardActions, useWizardContext, useWizardError, useWizardSelector, useWizardState, useWizardValue };
|
|
226
|
+
export { type CreateWizardStoreOptions, type IWizardActionsTyped, type IWizardHandle, WizardProvider, type WizardProviderProps, WizardStepRenderer, type WizardStepRendererProps, type WizardStoreBundle, createWizardFactory, createWizardHooks, createWizardStore, useWizard, useWizardActions, useWizardAllErrors, useWizardContext, useWizardCurrentStep, useWizardError, useWizardField, useWizardFlatErrors, useWizardMeta, useWizardSelector, useWizardState, useWizardSteps, useWizardStoreError, useWizardStoreField, useWizardStoreSelector, useWizardStoreState, useWizardStoreValue, useWizardValue };
|