@vuehookform/core 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/README.md +312 -0
- package/dist/context.d.ts +38 -0
- package/dist/context.d.ts.map +1 -0
- package/dist/core/formContext.d.ts +35 -0
- package/dist/core/formContext.d.ts.map +1 -0
- package/dist/core/useFieldArray.d.ts +9 -0
- package/dist/core/useFieldArray.d.ts.map +1 -0
- package/dist/core/useFieldRegistration.d.ts +10 -0
- package/dist/core/useFieldRegistration.d.ts.map +1 -0
- package/dist/core/useValidation.d.ts +8 -0
- package/dist/core/useValidation.d.ts.map +1 -0
- package/dist/index.d.ts +23 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/types.d.ts +290 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/useController.d.ts +64 -0
- package/dist/useController.d.ts.map +1 -0
- package/dist/useForm.d.ts +21 -0
- package/dist/useForm.d.ts.map +1 -0
- package/dist/useFormState.d.ts +40 -0
- package/dist/useFormState.d.ts.map +1 -0
- package/dist/useWatch.d.ts +41 -0
- package/dist/useWatch.d.ts.map +1 -0
- package/dist/utils/paths.d.ts +37 -0
- package/dist/utils/paths.d.ts.map +1 -0
- package/dist/vuehookform.cjs +644 -0
- package/dist/vuehookform.cjs.map +1 -0
- package/dist/vuehookform.js +637 -0
- package/dist/vuehookform.js.map +1 -0
- package/package.json +91 -0
package/dist/types.d.ts
ADDED
|
@@ -0,0 +1,290 @@
|
|
|
1
|
+
import { ComputedRef, Ref } from 'vue';
|
|
2
|
+
import { ZodType, z } from 'zod';
|
|
3
|
+
/**
|
|
4
|
+
* Validation mode determines when validation occurs
|
|
5
|
+
*/
|
|
6
|
+
export type ValidationMode = 'onSubmit' | 'onBlur' | 'onChange' | 'onTouched';
|
|
7
|
+
/**
|
|
8
|
+
* Extract the inferred type from a Zod schema
|
|
9
|
+
*/
|
|
10
|
+
export type InferSchema<T extends ZodType> = z.infer<T>;
|
|
11
|
+
/**
|
|
12
|
+
* Generate all possible paths for a nested object type
|
|
13
|
+
* e.g., { user: { name: string } } => 'user' | 'user.name'
|
|
14
|
+
*/
|
|
15
|
+
export type Path<T> = T extends object ? {
|
|
16
|
+
[K in keyof T & (string | number)]: K extends string | number ? `${K}` | `${K}.${Path<T[K]>}` : never;
|
|
17
|
+
}[keyof T & (string | number)] : never;
|
|
18
|
+
/**
|
|
19
|
+
* Get the type at a given path
|
|
20
|
+
* e.g., PathValue<{ user: { name: string } }, 'user.name'> => string
|
|
21
|
+
*/
|
|
22
|
+
export type PathValue<T, P extends string> = P extends `${infer K}.${infer Rest}` ? K extends keyof T ? Rest extends Path<T[K]> ? PathValue<T[K], Rest> : never : never : P extends keyof T ? T[P] : never;
|
|
23
|
+
/**
|
|
24
|
+
* Single field error with type and message
|
|
25
|
+
*/
|
|
26
|
+
export interface FieldError {
|
|
27
|
+
/** Error type identifier (e.g., 'required', 'minLength', 'custom') */
|
|
28
|
+
type: string;
|
|
29
|
+
/** Error message to display */
|
|
30
|
+
message: string;
|
|
31
|
+
/** Additional error types when multiple validations fail */
|
|
32
|
+
types?: Record<string, string | string[]>;
|
|
33
|
+
}
|
|
34
|
+
/**
|
|
35
|
+
* Field error value - can be a simple string (backward compatible) or structured error
|
|
36
|
+
*/
|
|
37
|
+
export type FieldErrorValue = string | FieldError;
|
|
38
|
+
/**
|
|
39
|
+
* Field error structure matching the form data structure
|
|
40
|
+
*/
|
|
41
|
+
export type FieldErrors<T> = {
|
|
42
|
+
[K in keyof T]?: T[K] extends Array<infer U> ? Array<FieldErrors<U>> | FieldErrorValue : T[K] extends object ? FieldErrors<T[K]> | FieldErrorValue : FieldErrorValue;
|
|
43
|
+
} & {
|
|
44
|
+
/** Root-level form errors */
|
|
45
|
+
root?: FieldError;
|
|
46
|
+
};
|
|
47
|
+
/**
|
|
48
|
+
* Form state tracking
|
|
49
|
+
*/
|
|
50
|
+
export interface FormState<T> {
|
|
51
|
+
/** Field validation errors */
|
|
52
|
+
errors: FieldErrors<T>;
|
|
53
|
+
/** Whether form has been modified from default values */
|
|
54
|
+
isDirty: boolean;
|
|
55
|
+
/** Whether form is currently valid (no errors) */
|
|
56
|
+
isValid: boolean;
|
|
57
|
+
/** Whether form is currently submitting */
|
|
58
|
+
isSubmitting: boolean;
|
|
59
|
+
/** Whether async default values are loading */
|
|
60
|
+
isLoading: boolean;
|
|
61
|
+
/** Record of touched field paths */
|
|
62
|
+
touchedFields: Record<string, boolean>;
|
|
63
|
+
/** Record of dirty field paths */
|
|
64
|
+
dirtyFields: Record<string, boolean>;
|
|
65
|
+
/** Number of times form has been submitted */
|
|
66
|
+
submitCount: number;
|
|
67
|
+
}
|
|
68
|
+
/**
|
|
69
|
+
* State of an individual field
|
|
70
|
+
*/
|
|
71
|
+
export interface FieldState {
|
|
72
|
+
/** Whether field value differs from default */
|
|
73
|
+
isDirty: boolean;
|
|
74
|
+
/** Whether field has been blurred */
|
|
75
|
+
isTouched: boolean;
|
|
76
|
+
/** Whether field has a validation error */
|
|
77
|
+
invalid: boolean;
|
|
78
|
+
/** The error (string for backward compatibility, or FieldError for structured errors) */
|
|
79
|
+
error?: string | FieldError;
|
|
80
|
+
}
|
|
81
|
+
/**
|
|
82
|
+
* Error option for setError()
|
|
83
|
+
*/
|
|
84
|
+
export interface ErrorOption {
|
|
85
|
+
/** Error type identifier */
|
|
86
|
+
type?: string;
|
|
87
|
+
/** Error message to display */
|
|
88
|
+
message: string;
|
|
89
|
+
}
|
|
90
|
+
/**
|
|
91
|
+
* Options for setFocus()
|
|
92
|
+
*/
|
|
93
|
+
export interface SetFocusOptions {
|
|
94
|
+
/** Whether to select the text in the input */
|
|
95
|
+
shouldSelect?: boolean;
|
|
96
|
+
}
|
|
97
|
+
/**
|
|
98
|
+
* Options for reset()
|
|
99
|
+
*/
|
|
100
|
+
export interface ResetOptions {
|
|
101
|
+
/** Keep validation errors after reset */
|
|
102
|
+
keepErrors?: boolean;
|
|
103
|
+
/** Keep dirty state after reset */
|
|
104
|
+
keepDirty?: boolean;
|
|
105
|
+
/** Keep touched state after reset */
|
|
106
|
+
keepTouched?: boolean;
|
|
107
|
+
/** Keep submit count after reset */
|
|
108
|
+
keepSubmitCount?: boolean;
|
|
109
|
+
/** Keep current default values (don't update with new values) */
|
|
110
|
+
keepDefaultValues?: boolean;
|
|
111
|
+
/** Keep isSubmitting state after reset */
|
|
112
|
+
keepIsSubmitting?: boolean;
|
|
113
|
+
}
|
|
114
|
+
/**
|
|
115
|
+
* Options for registering a field
|
|
116
|
+
*/
|
|
117
|
+
export interface RegisterOptions {
|
|
118
|
+
/** Use controlled mode (v-model) instead of uncontrolled (ref) */
|
|
119
|
+
controlled?: boolean;
|
|
120
|
+
/** Disable validation for this field */
|
|
121
|
+
disabled?: boolean;
|
|
122
|
+
/** Custom validation function */
|
|
123
|
+
validate?: (value: unknown) => string | undefined | Promise<string | undefined>;
|
|
124
|
+
/** Debounce time in ms for async validation (default: 0 = no debounce) */
|
|
125
|
+
validateDebounce?: number;
|
|
126
|
+
/** Remove field data when unmounted (overrides global shouldUnregister option) */
|
|
127
|
+
shouldUnregister?: boolean;
|
|
128
|
+
}
|
|
129
|
+
/**
|
|
130
|
+
* Return value from register() for binding to inputs
|
|
131
|
+
*/
|
|
132
|
+
export interface RegisterReturn {
|
|
133
|
+
/** Field name for form data */
|
|
134
|
+
name: string;
|
|
135
|
+
/** Ref callback for uncontrolled inputs - accepts HTMLInputElement, HTMLSelectElement, HTMLTextAreaElement, or null */
|
|
136
|
+
ref: (el: HTMLInputElement | HTMLSelectElement | HTMLTextAreaElement | null | unknown) => void;
|
|
137
|
+
/** Input handler (fires on every keystroke) */
|
|
138
|
+
onInput: (e: Event) => void;
|
|
139
|
+
/** Blur handler */
|
|
140
|
+
onBlur: (e: Event) => void;
|
|
141
|
+
/** Current value (for controlled mode) - only present when controlled: true */
|
|
142
|
+
value?: Ref<unknown>;
|
|
143
|
+
}
|
|
144
|
+
/**
|
|
145
|
+
* Field metadata for dynamic arrays
|
|
146
|
+
*/
|
|
147
|
+
export interface FieldArrayItem {
|
|
148
|
+
/** Stable key for v-for */
|
|
149
|
+
key: string;
|
|
150
|
+
/** Current index in array */
|
|
151
|
+
index: number;
|
|
152
|
+
/** Remove this item */
|
|
153
|
+
remove: () => void;
|
|
154
|
+
}
|
|
155
|
+
/**
|
|
156
|
+
* API for managing dynamic field arrays
|
|
157
|
+
*/
|
|
158
|
+
export interface FieldArray {
|
|
159
|
+
/** Current field items with metadata */
|
|
160
|
+
value: FieldArrayItem[];
|
|
161
|
+
/** Append item to end of array */
|
|
162
|
+
append: (value: unknown) => void;
|
|
163
|
+
/** Prepend item to beginning of array */
|
|
164
|
+
prepend: (value: unknown) => void;
|
|
165
|
+
/** Remove item at index */
|
|
166
|
+
remove: (index: number) => void;
|
|
167
|
+
/** Insert item at index */
|
|
168
|
+
insert: (index: number, value: unknown) => void;
|
|
169
|
+
/** Swap two items */
|
|
170
|
+
swap: (indexA: number, indexB: number) => void;
|
|
171
|
+
/** Move item from one index to another */
|
|
172
|
+
move: (from: number, to: number) => void;
|
|
173
|
+
/** Update item at index (preserves key/identity) */
|
|
174
|
+
update: (index: number, value: unknown) => void;
|
|
175
|
+
}
|
|
176
|
+
/**
|
|
177
|
+
* Async default values function type
|
|
178
|
+
*/
|
|
179
|
+
export type AsyncDefaultValues<T> = () => Promise<Partial<T>>;
|
|
180
|
+
/**
|
|
181
|
+
* Options for useForm composable
|
|
182
|
+
*/
|
|
183
|
+
export interface UseFormOptions<TSchema extends ZodType> {
|
|
184
|
+
/** Zod schema for validation */
|
|
185
|
+
schema: TSchema;
|
|
186
|
+
/** Default form values (can be a sync object or async function) */
|
|
187
|
+
defaultValues?: Partial<InferSchema<TSchema>> | AsyncDefaultValues<InferSchema<TSchema>>;
|
|
188
|
+
/** When to run validation */
|
|
189
|
+
mode?: ValidationMode;
|
|
190
|
+
/** Revalidate on change after first submit */
|
|
191
|
+
reValidateMode?: ValidationMode;
|
|
192
|
+
/** Remove field data when unmounted (default: false) */
|
|
193
|
+
shouldUnregister?: boolean;
|
|
194
|
+
}
|
|
195
|
+
/**
|
|
196
|
+
* Return value from useForm composable
|
|
197
|
+
*/
|
|
198
|
+
export interface UseFormReturn<TSchema extends ZodType> {
|
|
199
|
+
/**
|
|
200
|
+
* Register an input field
|
|
201
|
+
* @param name - Field path (e.g., 'email' or 'user.address.street')
|
|
202
|
+
* @param options - Registration options
|
|
203
|
+
*/
|
|
204
|
+
register: <TPath extends Path<InferSchema<TSchema>>>(name: TPath, options?: RegisterOptions) => RegisterReturn;
|
|
205
|
+
/**
|
|
206
|
+
* Unregister a field to clean up refs and options
|
|
207
|
+
* Call this when a field is unmounted to prevent memory leaks
|
|
208
|
+
* @param name - Field path to unregister
|
|
209
|
+
*/
|
|
210
|
+
unregister: <TPath extends Path<InferSchema<TSchema>>>(name: TPath) => void;
|
|
211
|
+
/**
|
|
212
|
+
* Handle form submission
|
|
213
|
+
* @param onValid - Callback called with valid data
|
|
214
|
+
* @param onInvalid - Optional callback called with errors
|
|
215
|
+
*/
|
|
216
|
+
handleSubmit: (onValid: (data: InferSchema<TSchema>) => void | Promise<void>, onInvalid?: (errors: FieldErrors<InferSchema<TSchema>>) => void) => (e: Event) => Promise<void>;
|
|
217
|
+
/** Reactive form state */
|
|
218
|
+
formState: ComputedRef<FormState<InferSchema<TSchema>>>;
|
|
219
|
+
/**
|
|
220
|
+
* Manage dynamic field arrays
|
|
221
|
+
* @param name - Array field path
|
|
222
|
+
*/
|
|
223
|
+
fields: <TPath extends Path<InferSchema<TSchema>>>(name: TPath) => FieldArray;
|
|
224
|
+
/**
|
|
225
|
+
* Set field value programmatically
|
|
226
|
+
* @param name - Field path
|
|
227
|
+
* @param value - New value
|
|
228
|
+
*/
|
|
229
|
+
setValue: <TPath extends Path<InferSchema<TSchema>>>(name: TPath, value: PathValue<InferSchema<TSchema>, TPath>) => void;
|
|
230
|
+
/**
|
|
231
|
+
* Get field value
|
|
232
|
+
* @param name - Field path
|
|
233
|
+
*/
|
|
234
|
+
getValue: <TPath extends Path<InferSchema<TSchema>>>(name: TPath) => PathValue<InferSchema<TSchema>, TPath> | undefined;
|
|
235
|
+
/**
|
|
236
|
+
* Reset form to default values
|
|
237
|
+
* @param values - Optional new default values
|
|
238
|
+
* @param options - Optional reset options
|
|
239
|
+
*/
|
|
240
|
+
reset: (values?: Partial<InferSchema<TSchema>>, options?: ResetOptions) => void;
|
|
241
|
+
/**
|
|
242
|
+
* Watch field value(s) reactively
|
|
243
|
+
* @param name - Field path or array of paths (optional - watches all if not provided)
|
|
244
|
+
*/
|
|
245
|
+
watch: <TPath extends Path<InferSchema<TSchema>>>(name?: TPath | TPath[]) => ComputedRef<unknown>;
|
|
246
|
+
/**
|
|
247
|
+
* Manually trigger validation
|
|
248
|
+
* @param name - Optional field path (validates all if not provided)
|
|
249
|
+
*/
|
|
250
|
+
validate: <TPath extends Path<InferSchema<TSchema>>>(name?: TPath) => Promise<boolean>;
|
|
251
|
+
/**
|
|
252
|
+
* Clear errors for specified fields or all errors
|
|
253
|
+
* @param name - Optional field path or array of paths
|
|
254
|
+
*/
|
|
255
|
+
clearErrors: <TPath extends Path<InferSchema<TSchema>>>(name?: TPath | TPath[]) => void;
|
|
256
|
+
/**
|
|
257
|
+
* Set an error for a specific field
|
|
258
|
+
* @param name - Field path or root error
|
|
259
|
+
* @param error - Error option with message
|
|
260
|
+
*/
|
|
261
|
+
setError: <TPath extends Path<InferSchema<TSchema>>>(name: TPath | 'root' | `root.${string}`, error: ErrorOption) => void;
|
|
262
|
+
/**
|
|
263
|
+
* Get all form values, a single value, or multiple values
|
|
264
|
+
* @overload Get all form values
|
|
265
|
+
* @overload Get single field value by path
|
|
266
|
+
* @overload Get multiple field values by paths array
|
|
267
|
+
*/
|
|
268
|
+
getValues: {
|
|
269
|
+
(): InferSchema<TSchema>;
|
|
270
|
+
<TPath extends Path<InferSchema<TSchema>>>(name: TPath): PathValue<InferSchema<TSchema>, TPath>;
|
|
271
|
+
<TPath extends Path<InferSchema<TSchema>>>(names: TPath[]): Partial<InferSchema<TSchema>>;
|
|
272
|
+
};
|
|
273
|
+
/**
|
|
274
|
+
* Get the state of an individual field
|
|
275
|
+
* @param name - Field path
|
|
276
|
+
*/
|
|
277
|
+
getFieldState: <TPath extends Path<InferSchema<TSchema>>>(name: TPath) => FieldState;
|
|
278
|
+
/**
|
|
279
|
+
* Manually trigger validation for specific fields or entire form
|
|
280
|
+
* @param name - Optional field path or array of paths
|
|
281
|
+
*/
|
|
282
|
+
trigger: <TPath extends Path<InferSchema<TSchema>>>(name?: TPath | TPath[]) => Promise<boolean>;
|
|
283
|
+
/**
|
|
284
|
+
* Programmatically focus a field
|
|
285
|
+
* @param name - Field path
|
|
286
|
+
* @param options - Focus options
|
|
287
|
+
*/
|
|
288
|
+
setFocus: <TPath extends Path<InferSchema<TSchema>>>(name: TPath, options?: SetFocusOptions) => void;
|
|
289
|
+
}
|
|
290
|
+
//# sourceMappingURL=types.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/lib/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,WAAW,EAAE,GAAG,EAAE,MAAM,KAAK,CAAA;AAC3C,OAAO,KAAK,EAAE,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAA;AAErC;;GAEG;AACH,MAAM,MAAM,cAAc,GAAG,UAAU,GAAG,QAAQ,GAAG,UAAU,GAAG,WAAW,CAAA;AAE7E;;GAEG;AACH,MAAM,MAAM,WAAW,CAAC,CAAC,SAAS,OAAO,IAAI,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,CAAA;AAEvD;;;GAGG;AACH,MAAM,MAAM,IAAI,CAAC,CAAC,IAAI,CAAC,SAAS,MAAM,GAClC;KACG,CAAC,IAAI,MAAM,CAAC,GAAG,CAAC,MAAM,GAAG,MAAM,CAAC,GAAG,CAAC,SAAS,MAAM,GAAG,MAAM,GACzD,GAAG,CAA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EAAE,CAAC,KAAK,SAAS,IAAI,CAAC,WAAW,CAAC,OAAO,CAAC,CAAC,EACtD,IAAI,EAAE,KAAK,KACR,UAAU,CAAA;IAEf;;;OAGG;IACH,OAAO,EAAE,CAAC,KAAK,SAAS,IAAI,CAAC,WAAW,CAAC,OAAO,CAAC,CAAC,EAChD,IAAI,CAAC,EAAE,KAAK,GAAG,KAAK,EAAE,KACnB,OAAO,CAAC,OAAO,CAAC,CAAA;IAErB;;;;OAIG;IACH,QAAQ,EAAE,CAAC,KAAK,SAAS,IAAI,CAAC,WAAW,CAAC,OAAO,CAAC,CAAC,EACjD,IAAI,EAAE,KAAK,EACX,OAAO,CAAC,EAAE,eAAe,KACtB,IAAI,CAAA;CACV"}
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
import { ComputedRef, Ref } from 'vue';
|
|
2
|
+
import { ZodType } from 'zod';
|
|
3
|
+
import { UseFormReturn, Path, PathValue, InferSchema, FieldState } from './types';
|
|
4
|
+
/**
|
|
5
|
+
* Options for useController composable
|
|
6
|
+
*/
|
|
7
|
+
export interface UseControllerOptions<TSchema extends ZodType, TPath extends Path<InferSchema<TSchema>>> {
|
|
8
|
+
/** Field name/path */
|
|
9
|
+
name: TPath;
|
|
10
|
+
/** Form control from useForm (uses context if not provided) */
|
|
11
|
+
control?: UseFormReturn<TSchema>;
|
|
12
|
+
/** Default value for the field */
|
|
13
|
+
defaultValue?: PathValue<InferSchema<TSchema>, TPath>;
|
|
14
|
+
}
|
|
15
|
+
/**
|
|
16
|
+
* Field props returned by useController
|
|
17
|
+
*/
|
|
18
|
+
export interface ControllerFieldProps<TValue> {
|
|
19
|
+
/** Current field value */
|
|
20
|
+
value: Ref<TValue>;
|
|
21
|
+
/** Field name */
|
|
22
|
+
name: string;
|
|
23
|
+
/** Change handler - call with new value */
|
|
24
|
+
onChange: (value: TValue) => void;
|
|
25
|
+
/** Blur handler */
|
|
26
|
+
onBlur: () => void;
|
|
27
|
+
/** Ref callback for the input element */
|
|
28
|
+
ref: (el: HTMLElement | null) => void;
|
|
29
|
+
}
|
|
30
|
+
/**
|
|
31
|
+
* Return value from useController
|
|
32
|
+
*/
|
|
33
|
+
export interface UseControllerReturn<TValue> {
|
|
34
|
+
/** Field props for binding to input components */
|
|
35
|
+
field: ControllerFieldProps<TValue>;
|
|
36
|
+
/** Current field state (errors, dirty, touched) */
|
|
37
|
+
fieldState: ComputedRef<FieldState>;
|
|
38
|
+
}
|
|
39
|
+
/**
|
|
40
|
+
* Hook for controlled components that need fine-grained control over field state
|
|
41
|
+
*
|
|
42
|
+
* This composable is useful for integrating with custom input components or
|
|
43
|
+
* third-party UI libraries that don't work with the standard register() approach.
|
|
44
|
+
*
|
|
45
|
+
* @example
|
|
46
|
+
* ```ts
|
|
47
|
+
* // Basic usage with context
|
|
48
|
+
* const { field, fieldState } = useController({ name: 'email' })
|
|
49
|
+
*
|
|
50
|
+
* // With explicit control
|
|
51
|
+
* const { control } = useForm({ schema })
|
|
52
|
+
* const { field, fieldState } = useController({ control, name: 'email' })
|
|
53
|
+
*
|
|
54
|
+
* // In template:
|
|
55
|
+
* // <CustomInput
|
|
56
|
+
* // :value="field.value.value"
|
|
57
|
+
* // @update:modelValue="field.onChange"
|
|
58
|
+
* // @blur="field.onBlur"
|
|
59
|
+
* // />
|
|
60
|
+
* // <span v-if="fieldState.value.error">{{ fieldState.value.error }}</span>
|
|
61
|
+
* ```
|
|
62
|
+
*/
|
|
63
|
+
export declare function useController<TSchema extends ZodType, TPath extends Path<InferSchema<TSchema>>>(options: UseControllerOptions<TSchema, TPath>): UseControllerReturn<PathValue<InferSchema<TSchema>, TPath>>;
|
|
64
|
+
//# sourceMappingURL=useController.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useController.d.ts","sourceRoot":"","sources":["../src/lib/useController.ts"],"names":[],"mappings":"AAAA,OAAO,EAAiB,KAAK,WAAW,EAAE,KAAK,GAAG,EAAE,MAAM,KAAK,CAAA;AAC/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AAO,EAAE,KAAK,CAAC,GAC5C,mBAAmB,CAAC,SAAS,CAAC,WAAW,CAAC,OAAO,CAAC,EAAE,KAAK,CAAC,CAAC,CAyD7D"}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { ZodType } from 'zod';
|
|
2
|
+
import { UseFormOptions, UseFormReturn } from './types';
|
|
3
|
+
/**
|
|
4
|
+
* Main form management composable
|
|
5
|
+
*
|
|
6
|
+
* @example
|
|
7
|
+
* ```ts
|
|
8
|
+
* const schema = z.object({
|
|
9
|
+
* email: z.email(),
|
|
10
|
+
* name: z.string().min(2)
|
|
11
|
+
* })
|
|
12
|
+
*
|
|
13
|
+
* const { register, handleSubmit, formState } = useForm({ schema })
|
|
14
|
+
*
|
|
15
|
+
* const onSubmit = (data) => {
|
|
16
|
+
* console.log(data) // { email: '...', name: '...' }
|
|
17
|
+
* }
|
|
18
|
+
* ```
|
|
19
|
+
*/
|
|
20
|
+
export declare function useForm<TSchema extends ZodType>(options: UseFormOptions<TSchema>): UseFormReturn<TSchema>;
|
|
21
|
+
//# sourceMappingURL=useForm.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useForm.d.ts","sourceRoot":"","sources":["../src/lib/useForm.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,KAAK,CAAA;AAClC,OAAO,KAAK,EACV,cAAc,EACd,aAAa,EAUd,MAAM,SAAS,CAAA;AAOhB;;;;;;;;;;;;;;;;GAgBG;AACH,wBAAgB,OAAO,CAAC,OAAO,SAAS,OAAO,EAC7C,OAAO,EAAE,cAAc,CAAC,OAAO,CAAC,GAC/B,aAAa,CAAC,OAAO,CAAC,CAuWxB"}
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import { ComputedRef } from 'vue';
|
|
2
|
+
import { ZodType } from 'zod';
|
|
3
|
+
import { UseFormReturn, FormState, InferSchema } from './types';
|
|
4
|
+
/**
|
|
5
|
+
* Keys of FormState that can be subscribed to
|
|
6
|
+
*/
|
|
7
|
+
export type FormStateKey = keyof FormState<unknown>;
|
|
8
|
+
/**
|
|
9
|
+
* Options for useFormState composable
|
|
10
|
+
*/
|
|
11
|
+
export interface UseFormStateOptions<TSchema extends ZodType> {
|
|
12
|
+
/** Form control from useForm (uses context if not provided) */
|
|
13
|
+
control?: UseFormReturn<TSchema>;
|
|
14
|
+
/** Specific state keys to subscribe to (subscribes to all if not provided) */
|
|
15
|
+
name?: FormStateKey | FormStateKey[];
|
|
16
|
+
}
|
|
17
|
+
/**
|
|
18
|
+
* Subscribe to specific form state properties
|
|
19
|
+
*
|
|
20
|
+
* This composable allows you to efficiently subscribe to only the form state
|
|
21
|
+
* properties you need, reducing unnecessary re-renders.
|
|
22
|
+
*
|
|
23
|
+
* @example
|
|
24
|
+
* ```ts
|
|
25
|
+
* // Subscribe to all form state
|
|
26
|
+
* const formState = useFormState({})
|
|
27
|
+
*
|
|
28
|
+
* // Subscribe to specific properties
|
|
29
|
+
* const { isSubmitting, errors } = useFormState({ name: ['isSubmitting', 'errors'] })
|
|
30
|
+
*
|
|
31
|
+
* // Subscribe to single property
|
|
32
|
+
* const isDirty = useFormState({ name: 'isDirty' })
|
|
33
|
+
*
|
|
34
|
+
* // With explicit control
|
|
35
|
+
* const { control } = useForm({ schema })
|
|
36
|
+
* const formState = useFormState({ control })
|
|
37
|
+
* ```
|
|
38
|
+
*/
|
|
39
|
+
export declare function useFormState<TSchema extends ZodType>(options?: UseFormStateOptions<TSchema>): ComputedRef<Partial<FormState<InferSchema<TSchema>>>>;
|
|
40
|
+
//# sourceMappingURL=useFormState.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useFormState.d.ts","sourceRoot":"","sources":["../src/lib/useFormState.ts"],"names":[],"mappings":"AAAA,OAAO,EAAY,KAAK,WAAW,EAAE,MAAM,KAAK,CAAA;AAChD,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,KAAK,CAAA;AAClC,OAAO,KAAK,EAAE,aAAa,EAAE,SAAS,EAAE,WAAW,EAAE,MAAM,SAAS,CAAA;AAGpE;;GAEG;AACH,MAAM,MAAM,YAAY,GAAG,MAAM,SAAS,CAAC,OAAO,CAAC,CAAA;AAEnD;;GAEG;AACH,MAAM,WAAW,mBAAmB,CAAC,OAAO,SAAS,OAAO;IAC1D,+DAA+D;IAC/D,OAAO,CAAC,EAAE,aAAa,CAAC,OAAO,CAAC,CAAA;IAChC,8EAA8E;IAC9E,IAAI,CAAC,EAAE,YAAY,GAAG,YAAY,EAAE,CAAA;CACrC;AAED;;;;;;;;;;;;;;;;;;;;;GAqBG;AACH,wBAAgB,YAAY,CAAC,OAAO,SAAS,OAAO,EAClD,OAAO,GAAE,mBAAmB,CAAC,OAAO,CAAM,GACzC,WAAW,CAAC,OAAO,CAAC,SAAS,CAAC,WAAW,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC,CA0BvD"}
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import { ComputedRef } from 'vue';
|
|
2
|
+
import { ZodType } from 'zod';
|
|
3
|
+
import { UseFormReturn, Path, InferSchema } from './types';
|
|
4
|
+
/**
|
|
5
|
+
* Options for useWatch composable
|
|
6
|
+
*/
|
|
7
|
+
export interface UseWatchOptions<TSchema extends ZodType, TPath extends Path<InferSchema<TSchema>>> {
|
|
8
|
+
/** Form control from useForm (uses context if not provided) */
|
|
9
|
+
control?: UseFormReturn<TSchema>;
|
|
10
|
+
/** Field path or array of paths to watch (watches all if not provided) */
|
|
11
|
+
name?: TPath | TPath[];
|
|
12
|
+
/** Default value when field is undefined */
|
|
13
|
+
defaultValue?: unknown;
|
|
14
|
+
}
|
|
15
|
+
/**
|
|
16
|
+
* Watch form field values reactively without the full form instance
|
|
17
|
+
*
|
|
18
|
+
* This composable allows you to subscribe to form value changes from any component
|
|
19
|
+
* in the tree, as long as the form context is provided via provideForm().
|
|
20
|
+
*
|
|
21
|
+
* @example
|
|
22
|
+
* ```ts
|
|
23
|
+
* // Watch a single field
|
|
24
|
+
* const email = useWatch({ name: 'email' })
|
|
25
|
+
*
|
|
26
|
+
* // Watch multiple fields
|
|
27
|
+
* const fields = useWatch({ name: ['firstName', 'lastName'] })
|
|
28
|
+
*
|
|
29
|
+
* // Watch all form values
|
|
30
|
+
* const allValues = useWatch({})
|
|
31
|
+
*
|
|
32
|
+
* // With explicit control
|
|
33
|
+
* const { control } = useForm({ schema })
|
|
34
|
+
* const email = useWatch({ control, name: 'email' })
|
|
35
|
+
*
|
|
36
|
+
* // With default value
|
|
37
|
+
* const status = useWatch({ name: 'status', defaultValue: 'pending' })
|
|
38
|
+
* ```
|
|
39
|
+
*/
|
|
40
|
+
export declare function useWatch<TSchema extends ZodType, TPath extends Path<InferSchema<TSchema>> = Path<InferSchema<TSchema>>>(options?: UseWatchOptions<TSchema, TPath>): ComputedRef<unknown>;
|
|
41
|
+
//# sourceMappingURL=useWatch.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useWatch.d.ts","sourceRoot":"","sources":["../src/lib/useWatch.ts"],"names":[],"mappings":"AAAA,OAAO,EAAY,KAAK,WAAW,EAAE,MAAM,KAAK,CAAA;AAChD,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,KAAK,CAAA;AAClC,OAAO,KAAK,EAAE,aAAa,EAAE,IAAI,EAAE,WAAW,EAAE,MAAM,SAAS,CAAA;AAI/D;;GAEG;AACH,MAAM,WAAW,eAAe,CAAC,OAAO,SAAS,OAAO,EAAE,KAAK,SAAS,IAAI,CAAC,WAAW,CAAC,OAAO,CAAC,CAAC;IAChG,+DAA+D;IAC/D,OAAO,CAAC,EAAE,aAAa,CAAC,OAAO,CAAC,CAAA;IAChC,0EAA0E;IAC1E,IAAI,CAAC,EAAE,KAAK,GAAG,KAAK,EAAE,CAAA;IACtB,4CAA4C;IAC5C,YAAY,CAAC,EAAE,OAAO,CAAA;CACvB;AAED;;;;;;;;;;;;;;;;;;;;;;;;GAwBG;AACH,wBAAgB,QAAQ,CACtB,OAAO,SAAS,OAAO,EACvB,KAAK,SAAS,IAAI,CAAC,WAAW,CAAC,OAAO,CAAC,CAAC,GAAG,IAAI,CAAC,WAAW,CAAC,OAAO,CAAC,CAAC,EACrE,OAAO,GAAE,eAAe,CAAC,OAAO,EAAE,KAAK,CAAM,GAAG,WAAW,CAAC,OAAO,CAAC,CA0BrE"}
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Get value from object using dot notation path
|
|
3
|
+
* @example get({ user: { name: 'John' } }, 'user.name') => 'John'
|
|
4
|
+
*/
|
|
5
|
+
export declare function get(obj: Record<string, unknown>, path: string): unknown;
|
|
6
|
+
/**
|
|
7
|
+
* Set value in object using dot notation path
|
|
8
|
+
* @example set({}, 'user.name', 'John') => { user: { name: 'John' } }
|
|
9
|
+
*/
|
|
10
|
+
export declare function set(obj: Record<string, unknown>, path: string, value: unknown): void;
|
|
11
|
+
/**
|
|
12
|
+
* Delete value from object using dot notation path
|
|
13
|
+
* @example unset({ user: { name: 'John' } }, 'user.name') => { user: {} }
|
|
14
|
+
*/
|
|
15
|
+
export declare function unset(obj: Record<string, unknown>, path: string): void;
|
|
16
|
+
/**
|
|
17
|
+
* Check if path exists in object
|
|
18
|
+
*/
|
|
19
|
+
export declare function has(obj: Record<string, unknown>, path: string): boolean;
|
|
20
|
+
export declare function generateId(): string;
|
|
21
|
+
/**
|
|
22
|
+
* Check if a path represents an array index
|
|
23
|
+
* @example isArrayPath('users.0') => true
|
|
24
|
+
* @example isArrayPath('users.name') => false
|
|
25
|
+
*/
|
|
26
|
+
export declare function isArrayPath(path: string): boolean;
|
|
27
|
+
/**
|
|
28
|
+
* Get parent path
|
|
29
|
+
* @example getParentPath('user.addresses.0.street') => 'user.addresses.0'
|
|
30
|
+
*/
|
|
31
|
+
export declare function getParentPath(path: string): string | undefined;
|
|
32
|
+
/**
|
|
33
|
+
* Get field name from path
|
|
34
|
+
* @example getFieldName('user.addresses.0.street') => 'street'
|
|
35
|
+
*/
|
|
36
|
+
export declare function getFieldName(path: string): string;
|
|
37
|
+
//# sourceMappingURL=paths.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"paths.d.ts","sourceRoot":"","sources":["../../src/lib/utils/paths.ts"],"names":[],"mappings":"AAAA;;;GAGG;AACH,wBAAgB,GAAG,CAAC,GAAG,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAAE,IAAI,EAAE,MAAM,GAAG,OAAO,CAcvE;AAED;;;GAGG;AACH,wBAAgB,GAAG,CAAC,GAAG,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAAE,IAAI,EAAE,MAAM,EAAE,KAAK,EAAE,OAAO,GAAG,IAAI,CAsBpF;AAED;;;GAGG;AACH,wBAAgB,KAAK,CAAC,GAAG,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAAE,IAAI,EAAE,MAAM,GAAG,IAAI,CAatE;AAED;;GAEG;AACH,wBAAgB,GAAG,CAAC,GAAG,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAAE,IAAI,EAAE,MAAM,GAAG,OAAO,CAEvE;AAMD,wBAAgB,UAAU,IAAI,MAAM,CAEnC;AAED;;;;GAIG;AACH,wBAAgB,WAAW,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAGjD;AAED;;;GAGG;AACH,wBAAgB,aAAa,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,GAAG,SAAS,CAK9D;AAED;;;GAGG;AACH,wBAAgB,YAAY,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,CAEjD"}
|