@wizardkit/vue 0.0.0-stage → 1.13.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 -0
- package/README.md +244 -2
- package/dist/index.d.ts +458 -0
- package/dist/index.js +218 -0
- package/package.json +75 -3
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Georgiy Tsamaladze
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
CHANGED
|
@@ -1,3 +1,245 @@
|
|
|
1
|
-
#
|
|
1
|
+
# @wizardkit/vue
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
Vue 3 Composition API integration for the Wizard framework.
|
|
4
|
+
|
|
5
|
+
## Features
|
|
6
|
+
|
|
7
|
+
- **Vue 3 Composable** - `useWizard()` composable with reactive `ComputedRef` values
|
|
8
|
+
- **Organized API** - State grouped into logical slices (state, validation, navigation, loading, actions)
|
|
9
|
+
- **Navigation History** - `canGoBack` and `stepHistory` for history-based back navigation
|
|
10
|
+
- **Granular Composables** - Fine-grained subscriptions with `useWizardData()`, `useWizardNavigation()`, etc.
|
|
11
|
+
- **v-model Support** - `useWizardField()` for writable computed refs
|
|
12
|
+
- **Optional Provider** - `WizardProvider` for sharing state via provide/inject
|
|
13
|
+
- **Full Type Safety** - TypeScript generics for your data types
|
|
14
|
+
|
|
15
|
+
## Installation
|
|
16
|
+
|
|
17
|
+
```bash
|
|
18
|
+
npm install @wizardkit/vue @wizardkit/core
|
|
19
|
+
# or
|
|
20
|
+
pnpm add @wizardkit/vue @wizardkit/core
|
|
21
|
+
# or
|
|
22
|
+
yarn add @wizardkit/vue @wizardkit/core
|
|
23
|
+
```
|
|
24
|
+
|
|
25
|
+
## Quick Start
|
|
26
|
+
|
|
27
|
+
### Basic Usage with Composition API
|
|
28
|
+
|
|
29
|
+
```vue
|
|
30
|
+
<script setup lang="ts">
|
|
31
|
+
import { useWizard } from "@wizardkit/vue";
|
|
32
|
+
import { createLinearWizard } from "@wizardkit/core";
|
|
33
|
+
|
|
34
|
+
interface FormData {
|
|
35
|
+
name: string;
|
|
36
|
+
email: string;
|
|
37
|
+
age: number;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
const definition = createLinearWizard<FormData>({
|
|
41
|
+
id: "my-wizard",
|
|
42
|
+
steps: [
|
|
43
|
+
{ id: "personal", title: "Personal Info" },
|
|
44
|
+
{ id: "contact", title: "Contact" },
|
|
45
|
+
{ id: "review", title: "Review" },
|
|
46
|
+
],
|
|
47
|
+
});
|
|
48
|
+
|
|
49
|
+
const { state, navigation, loading, actions } = useWizard({
|
|
50
|
+
definition,
|
|
51
|
+
initialData: { name: "", email: "", age: 0 },
|
|
52
|
+
});
|
|
53
|
+
</script>
|
|
54
|
+
|
|
55
|
+
<template>
|
|
56
|
+
<div>
|
|
57
|
+
<h2>{{ state.currentStep.value?.title }}</h2>
|
|
58
|
+
|
|
59
|
+
<div v-if="state.currentStepId.value === 'personal'">
|
|
60
|
+
<input
|
|
61
|
+
:value="state.data.value.name"
|
|
62
|
+
@input="
|
|
63
|
+
actions.updateField('name', ($event.target as HTMLInputElement).value)
|
|
64
|
+
"
|
|
65
|
+
placeholder="Name"
|
|
66
|
+
/>
|
|
67
|
+
</div>
|
|
68
|
+
|
|
69
|
+
<div v-else-if="state.currentStepId.value === 'contact'">
|
|
70
|
+
<input
|
|
71
|
+
:value="state.data.value.email"
|
|
72
|
+
@input="
|
|
73
|
+
actions.updateField(
|
|
74
|
+
'email',
|
|
75
|
+
($event.target as HTMLInputElement).value,
|
|
76
|
+
)
|
|
77
|
+
"
|
|
78
|
+
placeholder="Email"
|
|
79
|
+
/>
|
|
80
|
+
</div>
|
|
81
|
+
|
|
82
|
+
<div v-else-if="state.currentStepId.value === 'review'">
|
|
83
|
+
<p>Name: {{ state.data.value.name }}</p>
|
|
84
|
+
<p>Email: {{ state.data.value.email }}</p>
|
|
85
|
+
</div>
|
|
86
|
+
|
|
87
|
+
<button
|
|
88
|
+
@click="navigation.goPrevious"
|
|
89
|
+
:disabled="!navigation.canGoPrevious.value"
|
|
90
|
+
>
|
|
91
|
+
Previous
|
|
92
|
+
</button>
|
|
93
|
+
|
|
94
|
+
<!-- On the last step goNext() completes the wizard; canGoNext is false there. -->
|
|
95
|
+
<button
|
|
96
|
+
@click="navigation.goNext()"
|
|
97
|
+
:disabled="loading.isNavigating.value"
|
|
98
|
+
>
|
|
99
|
+
{{ navigation.isLastStep.value ? "Finish" : "Next" }}
|
|
100
|
+
</button>
|
|
101
|
+
</div>
|
|
102
|
+
</template>
|
|
103
|
+
```
|
|
104
|
+
|
|
105
|
+
### Using WizardProvider for Shared State
|
|
106
|
+
|
|
107
|
+
```vue
|
|
108
|
+
<!-- App.vue -->
|
|
109
|
+
<script setup lang="ts">
|
|
110
|
+
import { WizardProvider } from "@wizardkit/vue";
|
|
111
|
+
import { createLinearWizard } from "@wizardkit/core";
|
|
112
|
+
import WizardSteps from "./WizardSteps.vue";
|
|
113
|
+
import WizardNavigation from "./WizardNavigation.vue";
|
|
114
|
+
|
|
115
|
+
const definition = createLinearWizard({
|
|
116
|
+
id: "my-wizard",
|
|
117
|
+
steps: [
|
|
118
|
+
{ id: "step1", title: "Step 1" },
|
|
119
|
+
{ id: "step2", title: "Step 2" },
|
|
120
|
+
],
|
|
121
|
+
});
|
|
122
|
+
</script>
|
|
123
|
+
|
|
124
|
+
<template>
|
|
125
|
+
<WizardProvider :definition="definition" :initialData="{ name: '' }">
|
|
126
|
+
<WizardSteps />
|
|
127
|
+
<WizardNavigation />
|
|
128
|
+
</WizardProvider>
|
|
129
|
+
</template>
|
|
130
|
+
```
|
|
131
|
+
|
|
132
|
+
```vue
|
|
133
|
+
<!-- WizardSteps.vue -->
|
|
134
|
+
<script setup lang="ts">
|
|
135
|
+
import { useWizardData, useWizardActions } from "@wizardkit/vue";
|
|
136
|
+
|
|
137
|
+
const { currentStepId, data } = useWizardData();
|
|
138
|
+
const { updateField } = useWizardActions();
|
|
139
|
+
</script>
|
|
140
|
+
|
|
141
|
+
<template>
|
|
142
|
+
<div>
|
|
143
|
+
<h2>Current: {{ currentStepId.value }}</h2>
|
|
144
|
+
<input
|
|
145
|
+
:value="data.value.name"
|
|
146
|
+
@input="updateField('name', $event.target.value)"
|
|
147
|
+
/>
|
|
148
|
+
</div>
|
|
149
|
+
</template>
|
|
150
|
+
```
|
|
151
|
+
|
|
152
|
+
```vue
|
|
153
|
+
<!-- WizardNavigation.vue -->
|
|
154
|
+
<script setup lang="ts">
|
|
155
|
+
import { useWizardLoading, useWizardNavigation } from "@wizardkit/vue";
|
|
156
|
+
|
|
157
|
+
const { canGoPrevious, isLastStep, goNext, goPrevious } = useWizardNavigation();
|
|
158
|
+
const { isNavigating } = useWizardLoading();
|
|
159
|
+
</script>
|
|
160
|
+
|
|
161
|
+
<template>
|
|
162
|
+
<!-- Top-level refs are auto-unwrapped in the template: no .value here -->
|
|
163
|
+
<div>
|
|
164
|
+
<button @click="goPrevious()" :disabled="!canGoPrevious || isNavigating">
|
|
165
|
+
Previous
|
|
166
|
+
</button>
|
|
167
|
+
<!-- On the last step goNext() completes the wizard; canGoNext is false there. -->
|
|
168
|
+
<button @click="goNext()" :disabled="isNavigating">
|
|
169
|
+
{{ isLastStep ? "Finish" : "Next" }}
|
|
170
|
+
</button>
|
|
171
|
+
</div>
|
|
172
|
+
</template>
|
|
173
|
+
```
|
|
174
|
+
|
|
175
|
+
## API Reference
|
|
176
|
+
|
|
177
|
+
### Composables
|
|
178
|
+
|
|
179
|
+
#### `useWizard(options)`
|
|
180
|
+
|
|
181
|
+
Main composable for wizard state management. Returns organized state slices.
|
|
182
|
+
|
|
183
|
+
**Parameters:**
|
|
184
|
+
|
|
185
|
+
- `definition: WizardDefinition<T>` - Wizard configuration
|
|
186
|
+
- `initialData: T` - Initial form data
|
|
187
|
+
- `context?: WizardContext` - Optional context for validators/hooks
|
|
188
|
+
- `onStateChange?: (state) => void` - State change callback
|
|
189
|
+
- `onStepEnter?: (stepId, data) => void` - Step enter callback
|
|
190
|
+
- `onStepLeave?: (stepId, data) => void` - Step leave callback
|
|
191
|
+
- `onComplete?: (data) => void` - Completion callback
|
|
192
|
+
- `onCancel?: (data) => void | Promise<void>` - Cancel callback
|
|
193
|
+
- `onReset?: () => void` - Reset callback
|
|
194
|
+
- `onError?: (error) => void` - Error callback
|
|
195
|
+
- `plugins?: WizardPlugin<T>[]` - Reference-stable plugins (read once at setup)
|
|
196
|
+
|
|
197
|
+
**Returns:**
|
|
198
|
+
|
|
199
|
+
- `state` - Current step, data, `stepStatuses`, `progress` (`ComputedRef`s)
|
|
200
|
+
- `validation` - Validation state and errors
|
|
201
|
+
- `navigation` - Navigation state and methods (`goPrevious`, `goTo`, …)
|
|
202
|
+
- `loading` - Async operation states (`isValidating`, `isSubmitting`, `isNavigating`, `isLoadingStep`)
|
|
203
|
+
- `actions` - Data mutations, `validate` / `validateAll`, `submit`, `reset` / `cancel`, `serialize` / `restore`, `preloadStep`
|
|
204
|
+
|
|
205
|
+
#### Granular Composables (require WizardProvider)
|
|
206
|
+
|
|
207
|
+
- `useWizardData<T>()` - State slice only
|
|
208
|
+
- `useWizardNavigation()` - Navigation slice only
|
|
209
|
+
- `useWizardValidation()` - Validation slice only
|
|
210
|
+
- `useWizardLoading()` - Loading slice only
|
|
211
|
+
- `useWizardActions<T>()` - Actions slice only (`validateAll`, `cancel`, …)
|
|
212
|
+
- `useWizardField(wizard, field)` or `useWizardField(field)` inside Provider - `v-model` binding
|
|
213
|
+
- `createTypedWizardProvider<T>()` - Pre-typed Provider + granular helpers
|
|
214
|
+
|
|
215
|
+
### Components
|
|
216
|
+
|
|
217
|
+
#### `WizardProvider`
|
|
218
|
+
|
|
219
|
+
Provider component for sharing wizard state via provide/inject.
|
|
220
|
+
|
|
221
|
+
**Props:** Same as `useWizard` options, plus `children`
|
|
222
|
+
|
|
223
|
+
## TypeScript Support
|
|
224
|
+
|
|
225
|
+
All composables and components are fully typed with TypeScript generics:
|
|
226
|
+
|
|
227
|
+
```typescript
|
|
228
|
+
interface MyFormData {
|
|
229
|
+
name: string;
|
|
230
|
+
email: string;
|
|
231
|
+
}
|
|
232
|
+
|
|
233
|
+
const { state, actions } = useWizard<MyFormData>({
|
|
234
|
+
definition,
|
|
235
|
+
initialData: { name: "", email: "" },
|
|
236
|
+
});
|
|
237
|
+
|
|
238
|
+
// TypeScript knows the shape of data
|
|
239
|
+
actions.updateField("name", "John"); // ✓ OK
|
|
240
|
+
actions.updateField("invalid", "value"); // ✗ Error
|
|
241
|
+
```
|
|
242
|
+
|
|
243
|
+
## License
|
|
244
|
+
|
|
245
|
+
MIT
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,458 @@
|
|
|
1
|
+
import { ComponentOptionsMixin } from 'vue';
|
|
2
|
+
import { ComponentProvideOptions } from 'vue';
|
|
3
|
+
import { ComputedRef } from 'vue';
|
|
4
|
+
import { DefineComponent } from 'vue';
|
|
5
|
+
import { ExtractPropTypes } from 'vue';
|
|
6
|
+
import { GoToOptions } from '@wizardkit/core';
|
|
7
|
+
import { LoadingState } from '@wizardkit/state';
|
|
8
|
+
import { NavigationState } from '@wizardkit/state';
|
|
9
|
+
import { PublicProps } from 'vue';
|
|
10
|
+
import { RendererElement } from 'vue';
|
|
11
|
+
import { RendererNode } from 'vue';
|
|
12
|
+
import { StateSnapshot } from '@wizardkit/state';
|
|
13
|
+
import { StepId } from '@wizardkit/core';
|
|
14
|
+
import { StepStatus } from '@wizardkit/core';
|
|
15
|
+
import { SubscriptionChannel } from '@wizardkit/state';
|
|
16
|
+
import { ValidationState } from '@wizardkit/state';
|
|
17
|
+
import { ValidationSummary } from '@wizardkit/core';
|
|
18
|
+
import { VNode } from 'vue';
|
|
19
|
+
import { WizardContext } from '@wizardkit/core';
|
|
20
|
+
import { WizardData } from '@wizardkit/core';
|
|
21
|
+
import { WizardDefinition } from '@wizardkit/core';
|
|
22
|
+
import { WizardPlugin } from '@wizardkit/core';
|
|
23
|
+
import { WizardProgress } from '@wizardkit/core';
|
|
24
|
+
import { WizardRestoreError } from '@wizardkit/core';
|
|
25
|
+
import { WizardSerializedState } from '@wizardkit/core';
|
|
26
|
+
import { WizardState } from '@wizardkit/core';
|
|
27
|
+
import { WizardStateManager } from '@wizardkit/state';
|
|
28
|
+
import { WizardStepDefinition } from '@wizardkit/core';
|
|
29
|
+
import { WritableComputedRef } from 'vue';
|
|
30
|
+
|
|
31
|
+
/** Abandon the wizard: await onCancel handlers, then reset. */
|
|
32
|
+
export declare type CancelFn = () => Promise<void>;
|
|
33
|
+
|
|
34
|
+
export declare type CanSubmitFn = () => Promise<boolean>;
|
|
35
|
+
|
|
36
|
+
/**
|
|
37
|
+
* Creates a pre-typed provider component and granular composables for a specific data type.
|
|
38
|
+
* This avoids `as any` casts at usage sites by returning already-typed versions.
|
|
39
|
+
*
|
|
40
|
+
* @example
|
|
41
|
+
* ```ts
|
|
42
|
+
* interface MyFormData extends WizardData {
|
|
43
|
+
* name: string;
|
|
44
|
+
* email: string;
|
|
45
|
+
* }
|
|
46
|
+
*
|
|
47
|
+
* const {
|
|
48
|
+
* Provider,
|
|
49
|
+
* useData,
|
|
50
|
+
* useActions,
|
|
51
|
+
* useNavigation,
|
|
52
|
+
* useValidation,
|
|
53
|
+
* useLoading,
|
|
54
|
+
* } = createTypedWizardProvider<MyFormData>();
|
|
55
|
+
* ```
|
|
56
|
+
*/
|
|
57
|
+
export declare function createTypedWizardProvider<T extends WizardData>(): {
|
|
58
|
+
Provider: DefineComponent<WizardProviderProps<T>>;
|
|
59
|
+
useData: () => UseWizardState<T>;
|
|
60
|
+
useActions: () => UseWizardActions<T>;
|
|
61
|
+
useNavigation: () => UseWizardNavigation;
|
|
62
|
+
useValidation: () => UseWizardValidation;
|
|
63
|
+
useLoading: () => UseWizardLoading;
|
|
64
|
+
};
|
|
65
|
+
|
|
66
|
+
export { LoadingState }
|
|
67
|
+
|
|
68
|
+
export { NavigationState }
|
|
69
|
+
|
|
70
|
+
export declare type ResetFn<T extends WizardData> = (data?: T) => void;
|
|
71
|
+
|
|
72
|
+
export declare type RestoreFn<T extends WizardData> = (state: WizardSerializedState<T>) => void;
|
|
73
|
+
|
|
74
|
+
export declare type SerializeFn<T extends WizardData> = () => WizardSerializedState<T>;
|
|
75
|
+
|
|
76
|
+
export declare type SetDataFn<T extends WizardData> = (data: T) => void;
|
|
77
|
+
|
|
78
|
+
export { StateSnapshot }
|
|
79
|
+
|
|
80
|
+
export declare type SubmitFn = () => Promise<void>;
|
|
81
|
+
|
|
82
|
+
export { SubscriptionChannel }
|
|
83
|
+
|
|
84
|
+
/**
|
|
85
|
+
* Helper types for individual wizard actions
|
|
86
|
+
*/
|
|
87
|
+
export declare type UpdateDataFn<T extends WizardData> = (updater: (data: T) => T) => void;
|
|
88
|
+
|
|
89
|
+
export declare type UpdateFieldFn<T extends WizardData> = <K extends keyof T>(field: K, value: T[K]) => void;
|
|
90
|
+
|
|
91
|
+
/**
|
|
92
|
+
* Vue composable for wizard state management
|
|
93
|
+
* Returns organized state slices with reactive refs and computed values
|
|
94
|
+
*/
|
|
95
|
+
declare function useWizard<T extends WizardData>(options: UseWizardOptions<T>): UseWizardReturn<T>;
|
|
96
|
+
export default useWizard;
|
|
97
|
+
export { useWizard }
|
|
98
|
+
|
|
99
|
+
/**
|
|
100
|
+
* Actions slice - data mutations and validation
|
|
101
|
+
*
|
|
102
|
+
* Data-carrying actions (`setData`, `updateData`'s return value, `updateField`,
|
|
103
|
+
* `reset(data)`, `restore(state)`) accept Vue `ref()` / `reactive()` values:
|
|
104
|
+
* reactivity is stripped (deeply) before the data reaches the machine, so a
|
|
105
|
+
* form object held in `ref()` can be passed as `formRef.value`.
|
|
106
|
+
*/
|
|
107
|
+
export declare interface UseWizardActions<T extends WizardData> {
|
|
108
|
+
updateData: UpdateDataFn<T>;
|
|
109
|
+
setData: SetDataFn<T>;
|
|
110
|
+
updateField: UpdateFieldFn<T>;
|
|
111
|
+
validate: ValidateFn;
|
|
112
|
+
validateAll: ValidateAllFn;
|
|
113
|
+
canSubmit: CanSubmitFn;
|
|
114
|
+
submit: SubmitFn;
|
|
115
|
+
reset: ResetFn<T>;
|
|
116
|
+
cancel: CancelFn;
|
|
117
|
+
serialize: SerializeFn<T>;
|
|
118
|
+
restore: RestoreFn<T>;
|
|
119
|
+
/**
|
|
120
|
+
* Loads a lazy step's implementation ahead of navigation (WIZ-013).
|
|
121
|
+
* Never rejects: meant for fire-and-forget hover/focus handlers; failures
|
|
122
|
+
* are reported by the navigation that needs the step.
|
|
123
|
+
*/
|
|
124
|
+
preloadStep: (stepId: StepId) => Promise<void>;
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
/**
|
|
128
|
+
* Composable for wizard actions
|
|
129
|
+
* Combines data mutations and submission in one place
|
|
130
|
+
*
|
|
131
|
+
* @example
|
|
132
|
+
* ```vue
|
|
133
|
+
* <script setup lang="ts">
|
|
134
|
+
* const { updateField, submit, reset } = useWizardActions<MyFormData>();
|
|
135
|
+
* </script>
|
|
136
|
+
* ```
|
|
137
|
+
*/
|
|
138
|
+
export declare function useWizardActions<T extends WizardData>(): UseWizardActions<T>;
|
|
139
|
+
|
|
140
|
+
/**
|
|
141
|
+
* Composable for wizard data state
|
|
142
|
+
* Only triggers re-renders when data or current step changes
|
|
143
|
+
*
|
|
144
|
+
* @example
|
|
145
|
+
* ```vue
|
|
146
|
+
* <script setup lang="ts">
|
|
147
|
+
* const { data, currentStepId, currentStep } = useWizardData<MyFormData>();
|
|
148
|
+
* </script>
|
|
149
|
+
* ```
|
|
150
|
+
*/
|
|
151
|
+
export declare function useWizardData<T extends WizardData>(): UseWizardState<T>;
|
|
152
|
+
|
|
153
|
+
/**
|
|
154
|
+
* Writable field binding backed by the wizard machine.
|
|
155
|
+
* Reads from wizard state and writes through `updateField()`.
|
|
156
|
+
*
|
|
157
|
+
* @example
|
|
158
|
+
* ```vue
|
|
159
|
+
* <script setup lang="ts">
|
|
160
|
+
* const email = useWizardField<{ email: string }, "email">("email");
|
|
161
|
+
* </script>
|
|
162
|
+
*
|
|
163
|
+
* <template>
|
|
164
|
+
* <input v-model="email" />
|
|
165
|
+
* </template>
|
|
166
|
+
* ```
|
|
167
|
+
*/
|
|
168
|
+
export declare function useWizardField<T extends WizardData, K extends keyof T>(field: K): WritableComputedRef<T[K]>;
|
|
169
|
+
|
|
170
|
+
/**
|
|
171
|
+
* Writable field binding for direct `useWizard()` consumers.
|
|
172
|
+
*
|
|
173
|
+
* @example
|
|
174
|
+
* ```ts
|
|
175
|
+
* const wizard = useWizard({ definition, initialData });
|
|
176
|
+
* const email = useWizardField(wizard, "email");
|
|
177
|
+
* ```
|
|
178
|
+
*/
|
|
179
|
+
export declare function useWizardField<T extends WizardData, K extends keyof T>(wizard: UseWizardReturn<T>, field: K): WritableComputedRef<T[K]>;
|
|
180
|
+
|
|
181
|
+
/**
|
|
182
|
+
* Loading slice - async operation states
|
|
183
|
+
* All values are ComputedRef since they are derived from reactive state
|
|
184
|
+
*/
|
|
185
|
+
export declare interface UseWizardLoading {
|
|
186
|
+
isValidating: ComputedRef<boolean>;
|
|
187
|
+
isSubmitting: ComputedRef<boolean>;
|
|
188
|
+
isNavigating: ComputedRef<boolean>;
|
|
189
|
+
/** A lazy step implementation is loading (WIZ-013). */
|
|
190
|
+
isLoadingStep: ComputedRef<boolean>;
|
|
191
|
+
}
|
|
192
|
+
|
|
193
|
+
/**
|
|
194
|
+
* Composable for loading states
|
|
195
|
+
* Only triggers re-renders when loading states change
|
|
196
|
+
*
|
|
197
|
+
* @example
|
|
198
|
+
* ```vue
|
|
199
|
+
* <script setup lang="ts">
|
|
200
|
+
* const { isValidating, isSubmitting, isNavigating, isLoadingStep } = useWizardLoading();
|
|
201
|
+
* </script>
|
|
202
|
+
* ```
|
|
203
|
+
*/
|
|
204
|
+
export declare function useWizardLoading(): UseWizardLoading;
|
|
205
|
+
|
|
206
|
+
export declare type UseWizardNavigation = UseWizardNavigationState & UseWizardNavigationActions;
|
|
207
|
+
|
|
208
|
+
/**
|
|
209
|
+
* Composable for navigation state and methods
|
|
210
|
+
* Only triggers re-renders when navigation state changes
|
|
211
|
+
*
|
|
212
|
+
* @example
|
|
213
|
+
* ```vue
|
|
214
|
+
* <script setup lang="ts">
|
|
215
|
+
* const { canGoNext, goNext, canGoPrevious, goPrevious } = useWizardNavigation();
|
|
216
|
+
* </script>
|
|
217
|
+
* ```
|
|
218
|
+
*/
|
|
219
|
+
export declare function useWizardNavigation(): UseWizardNavigation;
|
|
220
|
+
|
|
221
|
+
/**
|
|
222
|
+
* Navigation slice - step navigation methods
|
|
223
|
+
*/
|
|
224
|
+
export declare interface UseWizardNavigationActions {
|
|
225
|
+
goNext: () => Promise<void>;
|
|
226
|
+
goPrevious: () => Promise<void>;
|
|
227
|
+
/**
|
|
228
|
+
* @deprecated Use `goPrevious()` instead. `goBack(1)` is equivalent;
|
|
229
|
+
* for multiple steps call `goPrevious()` repeatedly.
|
|
230
|
+
*/
|
|
231
|
+
goBack: (steps?: number) => Promise<void>;
|
|
232
|
+
goTo: (stepId: StepId, options?: GoToOptions) => Promise<void>;
|
|
233
|
+
/** @deprecated Use goTo(stepId) instead */
|
|
234
|
+
goToStep: (stepId: StepId) => Promise<void>;
|
|
235
|
+
}
|
|
236
|
+
|
|
237
|
+
/**
|
|
238
|
+
* Navigation slice - step navigation capabilities
|
|
239
|
+
* All values are ComputedRef since they are derived from reactive state
|
|
240
|
+
*/
|
|
241
|
+
export declare interface UseWizardNavigationState {
|
|
242
|
+
canGoNext: ComputedRef<boolean>;
|
|
243
|
+
canGoPrevious: ComputedRef<boolean>;
|
|
244
|
+
canGoBack: ComputedRef<boolean>;
|
|
245
|
+
isFirstStep: ComputedRef<boolean>;
|
|
246
|
+
isLastStep: ComputedRef<boolean>;
|
|
247
|
+
visitedSteps: ComputedRef<StepId[]>;
|
|
248
|
+
availableSteps: ComputedRef<StepId[]>;
|
|
249
|
+
stepHistory: ComputedRef<StepId[]>;
|
|
250
|
+
}
|
|
251
|
+
|
|
252
|
+
/**
|
|
253
|
+
* Vue composable options
|
|
254
|
+
*/
|
|
255
|
+
export declare interface UseWizardOptions<T extends WizardData> {
|
|
256
|
+
/**
|
|
257
|
+
* Read ONCE at setup and captured — NOT reactive. Changing this after the
|
|
258
|
+
* composable runs has no effect (the machine is created once). To reconfigure,
|
|
259
|
+
* remount the component with a new `key`.
|
|
260
|
+
*/
|
|
261
|
+
definition: WizardDefinition<T>;
|
|
262
|
+
/**
|
|
263
|
+
* Read ONCE at setup and captured — NOT reactive. Changing this after the
|
|
264
|
+
* composable runs has no effect (the machine is created once). To reconfigure,
|
|
265
|
+
* remount the component with a new `key`.
|
|
266
|
+
*
|
|
267
|
+
* `ref()` / `reactive()` values are accepted: Vue reactivity (refs and
|
|
268
|
+
* proxies, including nested ones) is stripped to plain data before the
|
|
269
|
+
* machine deep-clones it via `structuredClone`. The unwrapped data must still
|
|
270
|
+
* be structured-cloneable (no functions, symbols, or class instances).
|
|
271
|
+
*/
|
|
272
|
+
initialData: T;
|
|
273
|
+
/**
|
|
274
|
+
* Read ONCE at setup and captured — NOT reactive. Changing this after the
|
|
275
|
+
* composable runs has no effect (the machine is created once). To reconfigure,
|
|
276
|
+
* remount the component with a new `key`.
|
|
277
|
+
*/
|
|
278
|
+
context?: WizardContext;
|
|
279
|
+
onStateChange?: (state: WizardState<T>) => void;
|
|
280
|
+
onStepEnter?: (stepId: StepId, data: T) => void;
|
|
281
|
+
onStepLeave?: (stepId: StepId, data: T) => void;
|
|
282
|
+
onComplete?: (data: T) => void;
|
|
283
|
+
onCancel?: (data: T) => void | Promise<void>;
|
|
284
|
+
onReset?: () => void;
|
|
285
|
+
onError?: (error: Error) => void;
|
|
286
|
+
onDataChange?: (prevData: T, nextData: T, changedFields: (keyof T)[]) => void;
|
|
287
|
+
/**
|
|
288
|
+
* Plugins registered once at machine creation (reference-stable — read once,
|
|
289
|
+
* NOT reactive). Define them outside setup or hoist them.
|
|
290
|
+
*/
|
|
291
|
+
plugins?: WizardPlugin<T>[];
|
|
292
|
+
}
|
|
293
|
+
|
|
294
|
+
/**
|
|
295
|
+
* Get wizard context (internal use for granular composables)
|
|
296
|
+
* @throws {Error} if used outside of WizardProvider
|
|
297
|
+
*/
|
|
298
|
+
export declare function useWizardProviderContext<T extends WizardData>(): WizardContextValue<T>;
|
|
299
|
+
|
|
300
|
+
/**
|
|
301
|
+
* Complete wizard return value with organized concerns
|
|
302
|
+
*/
|
|
303
|
+
export declare interface UseWizardReturn<T extends WizardData> {
|
|
304
|
+
state: UseWizardState<T>;
|
|
305
|
+
validation: UseWizardValidation;
|
|
306
|
+
navigation: UseWizardNavigation;
|
|
307
|
+
loading: UseWizardLoading;
|
|
308
|
+
actions: UseWizardActions<T>;
|
|
309
|
+
}
|
|
310
|
+
|
|
311
|
+
/**
|
|
312
|
+
* State slice - current step and data
|
|
313
|
+
* All values are ComputedRef since they are derived from reactive state
|
|
314
|
+
*/
|
|
315
|
+
export declare interface UseWizardState<T extends WizardData> {
|
|
316
|
+
currentStepId: ComputedRef<StepId>;
|
|
317
|
+
currentStep: ComputedRef<WizardStepDefinition<T>>;
|
|
318
|
+
data: ComputedRef<T>;
|
|
319
|
+
isCompleted: ComputedRef<boolean>;
|
|
320
|
+
stepStatuses: ComputedRef<Record<StepId, StepStatus>>;
|
|
321
|
+
progress: ComputedRef<WizardProgress>;
|
|
322
|
+
}
|
|
323
|
+
|
|
324
|
+
/**
|
|
325
|
+
* Validation slice - validation state and errors
|
|
326
|
+
* All values are ComputedRef since they are derived from reactive state
|
|
327
|
+
*/
|
|
328
|
+
export declare interface UseWizardValidation {
|
|
329
|
+
isValid: ComputedRef<boolean>;
|
|
330
|
+
validationErrors: ComputedRef<ValidationState["validationErrors"]>;
|
|
331
|
+
}
|
|
332
|
+
|
|
333
|
+
/**
|
|
334
|
+
* Composable for validation state
|
|
335
|
+
* Only triggers re-renders when validation state changes
|
|
336
|
+
*
|
|
337
|
+
* @example
|
|
338
|
+
* ```vue
|
|
339
|
+
* <script setup lang="ts">
|
|
340
|
+
* const { isValid, validationErrors } = useWizardValidation();
|
|
341
|
+
* </script>
|
|
342
|
+
* ```
|
|
343
|
+
*/
|
|
344
|
+
export declare function useWizardValidation(): UseWizardValidation;
|
|
345
|
+
|
|
346
|
+
/** Dry-run validators on every enabled step (see `actions.validateAll`). */
|
|
347
|
+
export declare type ValidateAllFn = (options?: {
|
|
348
|
+
updateStatuses?: boolean;
|
|
349
|
+
}) => Promise<ValidationSummary>;
|
|
350
|
+
|
|
351
|
+
export declare type ValidateFn = () => Promise<void>;
|
|
352
|
+
|
|
353
|
+
export { ValidationState }
|
|
354
|
+
|
|
355
|
+
/**
|
|
356
|
+
* Context for granular hooks - holds the wizard instance
|
|
357
|
+
*/
|
|
358
|
+
declare interface WizardContextValue<T extends WizardData> {
|
|
359
|
+
wizard: UseWizardReturn<T>;
|
|
360
|
+
}
|
|
361
|
+
|
|
362
|
+
export { WizardProgress }
|
|
363
|
+
|
|
364
|
+
/**
|
|
365
|
+
* Provider component for sharing wizard instance via provide/inject
|
|
366
|
+
*/
|
|
367
|
+
export declare const WizardProvider: DefineComponent< ExtractPropTypes<{
|
|
368
|
+
definition: {
|
|
369
|
+
type: () => WizardDefinition<WizardData>;
|
|
370
|
+
required: true;
|
|
371
|
+
};
|
|
372
|
+
initialData: {
|
|
373
|
+
type: () => WizardData;
|
|
374
|
+
required: true;
|
|
375
|
+
};
|
|
376
|
+
context: {
|
|
377
|
+
type: () => WizardContext;
|
|
378
|
+
default: () => {};
|
|
379
|
+
};
|
|
380
|
+
onStateChange: () => (state: WizardState<WizardData>) => void;
|
|
381
|
+
onStepEnter: () => (stepId: StepId, data: WizardData) => void;
|
|
382
|
+
onStepLeave: () => (stepId: StepId, data: WizardData) => void;
|
|
383
|
+
onComplete: () => (data: WizardData) => void;
|
|
384
|
+
onCancel: () => (data: WizardData) => void | Promise<void>;
|
|
385
|
+
onReset: () => () => void;
|
|
386
|
+
onError: () => (error: Error) => void;
|
|
387
|
+
onDataChange: () => (prevData: WizardData, nextData: WizardData, changedFields: (keyof WizardData)[]) => void;
|
|
388
|
+
plugins: () => WizardPlugin<WizardData>[];
|
|
389
|
+
}>, () => VNode<RendererNode, RendererElement, {
|
|
390
|
+
[key: string]: any;
|
|
391
|
+
}>[] | undefined, {}, {}, {}, ComponentOptionsMixin, ComponentOptionsMixin, {}, string, PublicProps, Readonly< ExtractPropTypes<{
|
|
392
|
+
definition: {
|
|
393
|
+
type: () => WizardDefinition<WizardData>;
|
|
394
|
+
required: true;
|
|
395
|
+
};
|
|
396
|
+
initialData: {
|
|
397
|
+
type: () => WizardData;
|
|
398
|
+
required: true;
|
|
399
|
+
};
|
|
400
|
+
context: {
|
|
401
|
+
type: () => WizardContext;
|
|
402
|
+
default: () => {};
|
|
403
|
+
};
|
|
404
|
+
onStateChange: () => (state: WizardState<WizardData>) => void;
|
|
405
|
+
onStepEnter: () => (stepId: StepId, data: WizardData) => void;
|
|
406
|
+
onStepLeave: () => (stepId: StepId, data: WizardData) => void;
|
|
407
|
+
onComplete: () => (data: WizardData) => void;
|
|
408
|
+
onCancel: () => (data: WizardData) => void | Promise<void>;
|
|
409
|
+
onReset: () => () => void;
|
|
410
|
+
onError: () => (error: Error) => void;
|
|
411
|
+
onDataChange: () => (prevData: WizardData, nextData: WizardData, changedFields: (keyof WizardData)[]) => void;
|
|
412
|
+
plugins: () => WizardPlugin<WizardData>[];
|
|
413
|
+
}>> & Readonly<{}>, {
|
|
414
|
+
context: WizardContext;
|
|
415
|
+
}, {}, {}, {}, string, ComponentProvideOptions, true, {}, any>;
|
|
416
|
+
|
|
417
|
+
export declare interface WizardProviderProps<T extends WizardData> {
|
|
418
|
+
/**
|
|
419
|
+
* Read ONCE at setup and captured — NOT reactive. Changing this prop after the
|
|
420
|
+
* component mounts has no effect (the machine is created once). To reconfigure,
|
|
421
|
+
* remount the provider with a new `key`.
|
|
422
|
+
*/
|
|
423
|
+
definition: WizardDefinition<T>;
|
|
424
|
+
/**
|
|
425
|
+
* Read ONCE at setup and captured — NOT reactive. Changing this prop after the
|
|
426
|
+
* component mounts has no effect (the machine is created once). To reconfigure,
|
|
427
|
+
* remount the provider with a new `key`.
|
|
428
|
+
*
|
|
429
|
+
* `ref()` / `reactive()` values are accepted: Vue reactivity (refs and
|
|
430
|
+
* proxies, including nested ones) is stripped to plain data before the
|
|
431
|
+
* machine deep-clones it via `structuredClone`. The unwrapped data must still
|
|
432
|
+
* be structured-cloneable (no functions, symbols, or class instances).
|
|
433
|
+
*/
|
|
434
|
+
initialData: T;
|
|
435
|
+
/**
|
|
436
|
+
* Read ONCE at setup and captured — NOT reactive. Changing this prop after the
|
|
437
|
+
* component mounts has no effect (the machine is created once). To reconfigure,
|
|
438
|
+
* remount the provider with a new `key`.
|
|
439
|
+
*/
|
|
440
|
+
context?: WizardContext;
|
|
441
|
+
onStateChange?: (state: WizardState<T>) => void;
|
|
442
|
+
onStepEnter?: (stepId: StepId, data: T) => void;
|
|
443
|
+
onStepLeave?: (stepId: StepId, data: T) => void;
|
|
444
|
+
onComplete?: (data: T) => void;
|
|
445
|
+
onCancel?: (data: T) => void | Promise<void>;
|
|
446
|
+
onReset?: () => void;
|
|
447
|
+
onError?: (error: Error) => void;
|
|
448
|
+
onDataChange?: (prevData: T, nextData: T, changedFields: (keyof T)[]) => void;
|
|
449
|
+
plugins?: WizardPlugin<T>[];
|
|
450
|
+
}
|
|
451
|
+
|
|
452
|
+
export { WizardRestoreError }
|
|
453
|
+
|
|
454
|
+
export { WizardSerializedState }
|
|
455
|
+
|
|
456
|
+
export { WizardStateManager }
|
|
457
|
+
|
|
458
|
+
export { }
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,218 @@
|
|
|
1
|
+
import { WizardRestoreError as e } from "@wizardkit/core";
|
|
2
|
+
import { WizardStateManager as t, createMachineAndManager as n, createWizardActions as r } from "@wizardkit/state";
|
|
3
|
+
import { computed as i, defineComponent as a, inject as o, isProxy as s, isRef as c, onScopeDispose as l, provide as u, shallowRef as d, toRaw as f, unref as p } from "vue";
|
|
4
|
+
//#region src/internal/to-raw-deep.ts
|
|
5
|
+
function m(e) {
|
|
6
|
+
let t = Object.getPrototypeOf(e);
|
|
7
|
+
return t === Object.prototype || t === null;
|
|
8
|
+
}
|
|
9
|
+
function h(e, t) {
|
|
10
|
+
return c(e) || s(e) ? !0 : typeof e != "object" || !e || t.has(e) ? !1 : (t.add(e), Array.isArray(e) ? e.some((e) => h(e, t)) : m(e) ? Reflect.ownKeys(e).some((n) => h(e[n], t)) : !1);
|
|
11
|
+
}
|
|
12
|
+
function g(e, t) {
|
|
13
|
+
let n = e;
|
|
14
|
+
for (; c(n);) n = p(n);
|
|
15
|
+
if (typeof n != "object" || !n) return n;
|
|
16
|
+
let r = f(n), i = t.get(r);
|
|
17
|
+
if (i !== void 0) return i;
|
|
18
|
+
if (Array.isArray(r)) {
|
|
19
|
+
let e = [];
|
|
20
|
+
t.set(r, e);
|
|
21
|
+
for (let n of r) e.push(g(n, t));
|
|
22
|
+
return e;
|
|
23
|
+
}
|
|
24
|
+
if (m(r)) {
|
|
25
|
+
let e = Object.getPrototypeOf(r) === null ? Object.create(null) : {};
|
|
26
|
+
t.set(r, e);
|
|
27
|
+
for (let n of Reflect.ownKeys(r)) Object.getOwnPropertyDescriptor(r, n)?.enumerable && (e[n] = g(r[n], t));
|
|
28
|
+
return e;
|
|
29
|
+
}
|
|
30
|
+
return t.set(r, r), r;
|
|
31
|
+
}
|
|
32
|
+
function _(e) {
|
|
33
|
+
return h(e, /* @__PURE__ */ new WeakSet()) ? g(e, /* @__PURE__ */ new WeakMap()) : e;
|
|
34
|
+
}
|
|
35
|
+
//#endregion
|
|
36
|
+
//#region src/use-wizard.ts
|
|
37
|
+
function v(e) {
|
|
38
|
+
let { definition: t, context: a = {}, onStateChange: o, onStepEnter: s, onStepLeave: c, onComplete: u, onCancel: f, onReset: p, onError: m, onDataChange: h, plugins: g } = e, v = d(void 0), y = {
|
|
39
|
+
onStateChange: (e) => {
|
|
40
|
+
v.value = e, o?.(e);
|
|
41
|
+
},
|
|
42
|
+
onStepEnter: s,
|
|
43
|
+
onStepLeave: c,
|
|
44
|
+
onComplete: u,
|
|
45
|
+
onCancel: f,
|
|
46
|
+
onReset: p,
|
|
47
|
+
onError: m,
|
|
48
|
+
onDataChange: h
|
|
49
|
+
}, { manager: b } = n({
|
|
50
|
+
definition: t,
|
|
51
|
+
context: a,
|
|
52
|
+
initialData: _(e.initialData),
|
|
53
|
+
getCallbacks: () => y,
|
|
54
|
+
plugins: g
|
|
55
|
+
});
|
|
56
|
+
v.value = b.getSnapshot();
|
|
57
|
+
let x = d(b.getNavigationSnapshot()), S = d(b.getLoadingSnapshot()), C = b.subscribe(() => {
|
|
58
|
+
x.value = b.getNavigationSnapshot();
|
|
59
|
+
}, "navigation"), w = b.subscribe(() => {
|
|
60
|
+
S.value = b.getLoadingSnapshot();
|
|
61
|
+
}, "loading"), T = r(b, (e) => {
|
|
62
|
+
let t = e instanceof Error ? e : Error(String(e));
|
|
63
|
+
m ? m(t) : console.error("[useWizard]", t);
|
|
64
|
+
}), E = {
|
|
65
|
+
...T,
|
|
66
|
+
updateData: (e) => T.updateData((t) => _(e(t))),
|
|
67
|
+
setData: (e) => T.setData(_(e)),
|
|
68
|
+
updateField: (e, t) => T.updateField(e, _(t)),
|
|
69
|
+
reset: (e) => T.reset(_(e)),
|
|
70
|
+
restore: (e) => T.restore(_(e))
|
|
71
|
+
};
|
|
72
|
+
return l(() => {
|
|
73
|
+
C(), w(), b.destroy();
|
|
74
|
+
}), {
|
|
75
|
+
state: {
|
|
76
|
+
currentStepId: i(() => v.value.currentStepId),
|
|
77
|
+
currentStep: i(() => t.steps[v.value.currentStepId]),
|
|
78
|
+
data: i(() => v.value.data),
|
|
79
|
+
isCompleted: i(() => v.value.isCompleted),
|
|
80
|
+
stepStatuses: i(() => v.value.stepStatuses),
|
|
81
|
+
progress: i(() => v.value.progress)
|
|
82
|
+
},
|
|
83
|
+
validation: {
|
|
84
|
+
isValid: i(() => v.value.isValid),
|
|
85
|
+
validationErrors: i(() => v.value.validationErrors)
|
|
86
|
+
},
|
|
87
|
+
navigation: {
|
|
88
|
+
canGoNext: i(() => x.value.canGoNext),
|
|
89
|
+
canGoPrevious: i(() => x.value.canGoPrevious),
|
|
90
|
+
canGoBack: i(() => x.value.canGoBack),
|
|
91
|
+
isFirstStep: i(() => x.value.isFirstStep),
|
|
92
|
+
isLastStep: i(() => x.value.isLastStep),
|
|
93
|
+
visitedSteps: i(() => x.value.visitedSteps),
|
|
94
|
+
availableSteps: i(() => x.value.availableSteps),
|
|
95
|
+
stepHistory: i(() => x.value.stepHistory),
|
|
96
|
+
goNext: E.goNext,
|
|
97
|
+
goPrevious: E.goPrevious,
|
|
98
|
+
goBack: E.goBack,
|
|
99
|
+
goTo: E.goTo,
|
|
100
|
+
goToStep: E.goToStep
|
|
101
|
+
},
|
|
102
|
+
loading: {
|
|
103
|
+
isValidating: i(() => S.value.isValidating),
|
|
104
|
+
isSubmitting: i(() => S.value.isSubmitting),
|
|
105
|
+
isNavigating: i(() => S.value.isNavigating),
|
|
106
|
+
isLoadingStep: i(() => S.value.isLoadingStep)
|
|
107
|
+
},
|
|
108
|
+
actions: {
|
|
109
|
+
updateData: E.updateData,
|
|
110
|
+
setData: E.setData,
|
|
111
|
+
updateField: E.updateField,
|
|
112
|
+
validate: E.validate,
|
|
113
|
+
validateAll: E.validateAll,
|
|
114
|
+
canSubmit: E.canSubmit,
|
|
115
|
+
submit: E.submit,
|
|
116
|
+
reset: E.reset,
|
|
117
|
+
cancel: E.cancel,
|
|
118
|
+
serialize: E.serialize,
|
|
119
|
+
restore: E.restore,
|
|
120
|
+
preloadStep: E.preloadStep
|
|
121
|
+
}
|
|
122
|
+
};
|
|
123
|
+
}
|
|
124
|
+
//#endregion
|
|
125
|
+
//#region src/wizard-provider.ts
|
|
126
|
+
var y = Symbol("wizard"), b = a({
|
|
127
|
+
name: "WizardProvider",
|
|
128
|
+
props: {
|
|
129
|
+
definition: {
|
|
130
|
+
type: Object,
|
|
131
|
+
required: !0
|
|
132
|
+
},
|
|
133
|
+
initialData: {
|
|
134
|
+
type: Object,
|
|
135
|
+
required: !0
|
|
136
|
+
},
|
|
137
|
+
context: {
|
|
138
|
+
type: Object,
|
|
139
|
+
default: () => ({})
|
|
140
|
+
},
|
|
141
|
+
onStateChange: Function,
|
|
142
|
+
onStepEnter: Function,
|
|
143
|
+
onStepLeave: Function,
|
|
144
|
+
onComplete: Function,
|
|
145
|
+
onCancel: Function,
|
|
146
|
+
onReset: Function,
|
|
147
|
+
onError: Function,
|
|
148
|
+
onDataChange: Function,
|
|
149
|
+
plugins: Array
|
|
150
|
+
},
|
|
151
|
+
setup(e, { slots: t }) {
|
|
152
|
+
return u(y, { wizard: v({
|
|
153
|
+
definition: f(e.definition),
|
|
154
|
+
initialData: f(e.initialData),
|
|
155
|
+
context: f(e.context),
|
|
156
|
+
onStateChange: e.onStateChange,
|
|
157
|
+
onStepEnter: e.onStepEnter,
|
|
158
|
+
onStepLeave: e.onStepLeave,
|
|
159
|
+
onComplete: e.onComplete,
|
|
160
|
+
onCancel: e.onCancel,
|
|
161
|
+
onReset: e.onReset,
|
|
162
|
+
onError: e.onError,
|
|
163
|
+
onDataChange: e.onDataChange,
|
|
164
|
+
plugins: e.plugins
|
|
165
|
+
}) }), () => t.default?.();
|
|
166
|
+
}
|
|
167
|
+
});
|
|
168
|
+
function x() {
|
|
169
|
+
let e = o(y);
|
|
170
|
+
if (!e) throw Error("useWizardProviderContext must be used within WizardProvider");
|
|
171
|
+
return e;
|
|
172
|
+
}
|
|
173
|
+
function S() {
|
|
174
|
+
return {
|
|
175
|
+
Provider: b,
|
|
176
|
+
useData: () => w(),
|
|
177
|
+
useActions: () => O(),
|
|
178
|
+
useNavigation: () => T(),
|
|
179
|
+
useValidation: () => E(),
|
|
180
|
+
useLoading: () => D()
|
|
181
|
+
};
|
|
182
|
+
}
|
|
183
|
+
//#endregion
|
|
184
|
+
//#region src/use-wizard-granular.ts
|
|
185
|
+
function C(e) {
|
|
186
|
+
return e || x().wizard;
|
|
187
|
+
}
|
|
188
|
+
function w() {
|
|
189
|
+
let { wizard: e } = x();
|
|
190
|
+
return e.state;
|
|
191
|
+
}
|
|
192
|
+
function T() {
|
|
193
|
+
let { wizard: e } = x();
|
|
194
|
+
return e.navigation;
|
|
195
|
+
}
|
|
196
|
+
function E() {
|
|
197
|
+
let { wizard: e } = x();
|
|
198
|
+
return e.validation;
|
|
199
|
+
}
|
|
200
|
+
function D() {
|
|
201
|
+
let { wizard: e } = x();
|
|
202
|
+
return e.loading;
|
|
203
|
+
}
|
|
204
|
+
function O() {
|
|
205
|
+
let { wizard: e } = x();
|
|
206
|
+
return e.actions;
|
|
207
|
+
}
|
|
208
|
+
function k(e, t) {
|
|
209
|
+
let n = t === void 0 ? C() : C(e), r = t === void 0 ? e : t;
|
|
210
|
+
return i({
|
|
211
|
+
get: () => n.state.data.value[r],
|
|
212
|
+
set: (e) => {
|
|
213
|
+
n.actions.updateField(r, e);
|
|
214
|
+
}
|
|
215
|
+
});
|
|
216
|
+
}
|
|
217
|
+
//#endregion
|
|
218
|
+
export { b as WizardProvider, e as WizardRestoreError, t as WizardStateManager, S as createTypedWizardProvider, v as default, v as useWizard, O as useWizardActions, w as useWizardData, k as useWizardField, D as useWizardLoading, T as useWizardNavigation, x as useWizardProviderContext, E as useWizardValidation };
|
package/package.json
CHANGED
|
@@ -1,6 +1,78 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@wizardkit/vue",
|
|
3
|
-
"version": "
|
|
4
|
-
"
|
|
5
|
-
"
|
|
3
|
+
"version": "1.13.0",
|
|
4
|
+
"description": "Headless multi-step form and wizard composables for Vue 3. Type-safe useWizard with conditional steps, validation and navigation history, powered by WizardKit.",
|
|
5
|
+
"keywords": [
|
|
6
|
+
"wizard",
|
|
7
|
+
"multi-step-form",
|
|
8
|
+
"multistep",
|
|
9
|
+
"stepper",
|
|
10
|
+
"form-wizard",
|
|
11
|
+
"onboarding",
|
|
12
|
+
"state-machine",
|
|
13
|
+
"headless",
|
|
14
|
+
"typescript",
|
|
15
|
+
"vue",
|
|
16
|
+
"vue3",
|
|
17
|
+
"composable",
|
|
18
|
+
"composition-api",
|
|
19
|
+
"vue-wizard",
|
|
20
|
+
"vue-stepper"
|
|
21
|
+
],
|
|
22
|
+
"homepage": "https://wizardkit.dev/guide/vue-integration",
|
|
23
|
+
"bugs": {
|
|
24
|
+
"url": "https://github.com/gooonzick/wizard/issues"
|
|
25
|
+
},
|
|
26
|
+
"type": "module",
|
|
27
|
+
"sideEffects": false,
|
|
28
|
+
"main": "./dist/index.js",
|
|
29
|
+
"module": "./dist/index.js",
|
|
30
|
+
"types": "./dist/index.d.ts",
|
|
31
|
+
"exports": {
|
|
32
|
+
".": {
|
|
33
|
+
"types": "./dist/index.d.ts",
|
|
34
|
+
"import": "./dist/index.js"
|
|
35
|
+
}
|
|
36
|
+
},
|
|
37
|
+
"files": [
|
|
38
|
+
"dist",
|
|
39
|
+
"README.md"
|
|
40
|
+
],
|
|
41
|
+
"peerDependencies": {
|
|
42
|
+
"vue": "^3.5.39"
|
|
43
|
+
},
|
|
44
|
+
"dependencies": {
|
|
45
|
+
"@wizardkit/core": "1.13.0",
|
|
46
|
+
"@wizardkit/state": "1.13.0"
|
|
47
|
+
},
|
|
48
|
+
"devDependencies": {
|
|
49
|
+
"@biomejs/biome": "^2.5.3",
|
|
50
|
+
"@microsoft/api-extractor": "^7.58.9",
|
|
51
|
+
"@types/node": "^26.1.1",
|
|
52
|
+
"@vitejs/plugin-vue": "^6.0.8",
|
|
53
|
+
"@vitest/coverage-v8": "^4.1.10",
|
|
54
|
+
"@vue/test-utils": "^2.4.11",
|
|
55
|
+
"happy-dom": "^20.10.6",
|
|
56
|
+
"typescript": "^6.0.3",
|
|
57
|
+
"vite": "^8.1.4",
|
|
58
|
+
"vite-plugin-dts": "^5.0.3",
|
|
59
|
+
"vitest": "^4.1.10",
|
|
60
|
+
"vue": "^3.5.39"
|
|
61
|
+
},
|
|
62
|
+
"repository": {
|
|
63
|
+
"type": "git",
|
|
64
|
+
"url": "https://github.com/gooonzick/wizard",
|
|
65
|
+
"directory": "packages/vue"
|
|
66
|
+
},
|
|
67
|
+
"publishConfig": {
|
|
68
|
+
"access": "public"
|
|
69
|
+
},
|
|
70
|
+
"scripts": {
|
|
71
|
+
"build": "vite build",
|
|
72
|
+
"typecheck": "tsc --build --verbose",
|
|
73
|
+
"test": "vitest --run",
|
|
74
|
+
"test:watch": "vitest --watch",
|
|
75
|
+
"lint": "biome check .",
|
|
76
|
+
"lint:fix": "biome check . --write"
|
|
77
|
+
}
|
|
6
78
|
}
|