vee-validate 4.8.6 → 4.9.1
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 +1 -0
- package/dist/vee-validate.d.ts +266 -73
- package/dist/vee-validate.esm.js +672 -581
- package/dist/vee-validate.js +556 -495
- package/dist/vee-validate.min.js +2 -2
- package/package.json +3 -2
package/README.md
CHANGED
|
@@ -168,6 +168,7 @@ You are welcome to contribute to this project, but before you do, please make su
|
|
|
168
168
|
|
|
169
169
|
- Inspired by Laravel's [validation syntax](https://laravel.com/docs/5.4/validation)
|
|
170
170
|
- v4 API Inspired by [Formik's](https://github.com/formium/formik)
|
|
171
|
+
- Nested path types by [react-hook-form](https://github.com/react-hook-form/react-hook-form)
|
|
171
172
|
- Logo by [Baianat](https://github.com/baianat)
|
|
172
173
|
|
|
173
174
|
## Emeriti
|
package/dist/vee-validate.d.ts
CHANGED
|
@@ -1,5 +1,141 @@
|
|
|
1
1
|
import * as vue from 'vue';
|
|
2
2
|
import { Ref, ComputedRef, PropType, VNode, UnwrapRef, InjectionKey } from 'vue';
|
|
3
|
+
import { PartialDeep } from 'type-fest';
|
|
4
|
+
|
|
5
|
+
type BrowserNativeObject = Date | FileList | File;
|
|
6
|
+
type Primitive = null | undefined | string | number | boolean | symbol | bigint;
|
|
7
|
+
/**
|
|
8
|
+
* Checks whether the type is any
|
|
9
|
+
* See {@link https://stackoverflow.com/a/49928360/3406963}
|
|
10
|
+
* @typeParam T - type which may be any
|
|
11
|
+
* ```
|
|
12
|
+
* IsAny<any> = true
|
|
13
|
+
* IsAny<string> = false
|
|
14
|
+
* ```
|
|
15
|
+
*/
|
|
16
|
+
type IsAny<T> = 0 extends 1 & T ? true : false;
|
|
17
|
+
/**
|
|
18
|
+
* Checks whether T1 can be exactly (mutually) assigned to T2
|
|
19
|
+
* @typeParam T1 - type to check
|
|
20
|
+
* @typeParam T2 - type to check against
|
|
21
|
+
* ```
|
|
22
|
+
* IsEqual<string, string> = true
|
|
23
|
+
* IsEqual<'foo', 'foo'> = true
|
|
24
|
+
* IsEqual<string, number> = false
|
|
25
|
+
* IsEqual<string, number> = false
|
|
26
|
+
* IsEqual<string, 'foo'> = false
|
|
27
|
+
* IsEqual<'foo', string> = false
|
|
28
|
+
* IsEqual<'foo' | 'bar', 'foo'> = boolean // 'foo' is assignable, but 'bar' is not (true | false) -> boolean
|
|
29
|
+
* ```
|
|
30
|
+
*/
|
|
31
|
+
type IsEqual<T1, T2> = T1 extends T2 ? (<G>() => G extends T1 ? 1 : 2) extends <G>() => G extends T2 ? 1 : 2 ? true : false : false;
|
|
32
|
+
/**
|
|
33
|
+
* Type to query whether an array type T is a tuple type.
|
|
34
|
+
* @typeParam T - type which may be an array or tuple
|
|
35
|
+
* @example
|
|
36
|
+
* ```
|
|
37
|
+
* IsTuple<[number]> = true
|
|
38
|
+
* IsTuple<number[]> = false
|
|
39
|
+
* ```
|
|
40
|
+
*/
|
|
41
|
+
type IsTuple<T extends ReadonlyArray<any>> = number extends T['length'] ? false : true;
|
|
42
|
+
/**
|
|
43
|
+
* Type which can be used to index an array or tuple type.
|
|
44
|
+
*/
|
|
45
|
+
type ArrayKey = number;
|
|
46
|
+
/**
|
|
47
|
+
* Helper function to break apart T1 and check if any are equal to T2
|
|
48
|
+
*
|
|
49
|
+
* See {@link IsEqual}
|
|
50
|
+
*/
|
|
51
|
+
type AnyIsEqual<T1, T2> = T1 extends T2 ? (IsEqual<T1, T2> extends true ? true : never) : never;
|
|
52
|
+
/**
|
|
53
|
+
* Type which given a tuple type returns its own keys, i.e. only its indices.
|
|
54
|
+
* @typeParam T - tuple type
|
|
55
|
+
* @example
|
|
56
|
+
* ```
|
|
57
|
+
* TupleKeys<[number, string]> = '0' | '1'
|
|
58
|
+
* ```
|
|
59
|
+
*/
|
|
60
|
+
type TupleKeys<T extends ReadonlyArray<any>> = Exclude<keyof T, keyof any[]>;
|
|
61
|
+
/**
|
|
62
|
+
* Helper type for recursively constructing paths through a type.
|
|
63
|
+
* This actually constructs the strings and recurses into nested
|
|
64
|
+
* object types.
|
|
65
|
+
*
|
|
66
|
+
* See {@link Path}
|
|
67
|
+
*/
|
|
68
|
+
type PathImpl<K extends string | number, V, TraversedTypes> = V extends Primitive | BrowserNativeObject ? `${K}` : true extends AnyIsEqual<TraversedTypes, V> ? `${K}` : `${K}` | `${K}.${PathInternal<V, TraversedTypes | V>}`;
|
|
69
|
+
/**
|
|
70
|
+
* Helper type for recursively constructing paths through a type.
|
|
71
|
+
* This obscures the internal type param TraversedTypes from ed contract.
|
|
72
|
+
*
|
|
73
|
+
* See {@link Path}
|
|
74
|
+
*/
|
|
75
|
+
type PathInternal<T, TraversedTypes = T> = T extends ReadonlyArray<infer V> ? IsTuple<T> extends true ? {
|
|
76
|
+
[K in TupleKeys<T>]-?: PathImpl<K & string, T[K], TraversedTypes>;
|
|
77
|
+
}[TupleKeys<T>] : PathImpl<ArrayKey, V, TraversedTypes> : {
|
|
78
|
+
[K in keyof T]-?: PathImpl<K & string, T[K], TraversedTypes>;
|
|
79
|
+
}[keyof T];
|
|
80
|
+
/**
|
|
81
|
+
* Helper type for recursively constructing paths through a type.
|
|
82
|
+
* This actually constructs the strings and recurses into nested
|
|
83
|
+
* object types.
|
|
84
|
+
*
|
|
85
|
+
* See {@link ArrayPath}
|
|
86
|
+
*/
|
|
87
|
+
type ArrayPathImpl<K extends string | number, V, TraversedTypes> = V extends Primitive | BrowserNativeObject ? IsAny<V> extends true ? string : never : V extends ReadonlyArray<infer U> ? U extends Primitive | BrowserNativeObject ? IsAny<V> extends true ? string : never : true extends AnyIsEqual<TraversedTypes, V> ? never : `${K}` | `${K}.${ArrayPathInternal<V, TraversedTypes | V>}` : true extends AnyIsEqual<TraversedTypes, V> ? never : `${K}.${ArrayPathInternal<V, TraversedTypes | V>}`;
|
|
88
|
+
/**
|
|
89
|
+
* Helper type for recursively constructing paths through a type.
|
|
90
|
+
* This obscures the internal type param TraversedTypes from ed contract.
|
|
91
|
+
*
|
|
92
|
+
* See {@link ArrayPath}
|
|
93
|
+
*/
|
|
94
|
+
type ArrayPathInternal<T, TraversedTypes = T> = T extends ReadonlyArray<infer V> ? IsTuple<T> extends true ? {
|
|
95
|
+
[K in TupleKeys<T>]-?: ArrayPathImpl<K & string, T[K], TraversedTypes>;
|
|
96
|
+
}[TupleKeys<T>] : ArrayPathImpl<ArrayKey, V, TraversedTypes> : {
|
|
97
|
+
[K in keyof T]-?: ArrayPathImpl<K & string, T[K], TraversedTypes>;
|
|
98
|
+
}[keyof T];
|
|
99
|
+
/**
|
|
100
|
+
* Type which eagerly collects all paths through a type which point to an array
|
|
101
|
+
* type.
|
|
102
|
+
* @typeParam T - type which should be introspected.
|
|
103
|
+
* @example
|
|
104
|
+
* ```
|
|
105
|
+
* Path<{foo: {bar: string[], baz: number[]}}> = 'foo.bar' | 'foo.baz'
|
|
106
|
+
* ```
|
|
107
|
+
*/
|
|
108
|
+
type ArrayPath<T> = T extends any ? ArrayPathInternal<T> : never;
|
|
109
|
+
/**
|
|
110
|
+
* Type to evaluate the type which the given path points to.
|
|
111
|
+
* @typeParam T - deeply nested type which is indexed by the path
|
|
112
|
+
* @typeParam P - path into the deeply nested type
|
|
113
|
+
* @example
|
|
114
|
+
* ```
|
|
115
|
+
* PathValue<{foo: {bar: string}}, 'foo.bar'> = string
|
|
116
|
+
* PathValue<[number, string], '1'> = string
|
|
117
|
+
* ```
|
|
118
|
+
*/
|
|
119
|
+
type PathValue<T, P extends Path<T> | ArrayPath<T>> = T extends any ? P extends `${infer K}.${infer R}` ? K extends keyof T ? R extends Path<T[K]> ? PathValue<T[K], R> : never : K extends `${ArrayKey}` ? T extends ReadonlyArray<infer V> ? PathValue<V, R & Path<V>> : never : never : P extends keyof T ? T[P] : P extends `${ArrayKey}` ? T extends ReadonlyArray<infer V> ? V : never : never : never;
|
|
120
|
+
/**
|
|
121
|
+
* Type which eagerly collects all paths through a type
|
|
122
|
+
* @typeParam T - type which should be introspected
|
|
123
|
+
* @example
|
|
124
|
+
* ```
|
|
125
|
+
* Path<{foo: {bar: string}}> = 'foo' | 'foo.bar'
|
|
126
|
+
* ```
|
|
127
|
+
*/
|
|
128
|
+
type Path<T> = T extends any ? PathInternal<T> : never;
|
|
129
|
+
|
|
130
|
+
type GenericObject = Record<string, any>;
|
|
131
|
+
type MaybeRef<T> = Ref<T> | T;
|
|
132
|
+
type MaybeRefOrLazy<T> = MaybeRef<T> | (() => T);
|
|
133
|
+
type MapValuesPathsToRefs<TValues extends GenericObject, TPaths extends readonly [...MaybeRef<Path<TValues>>[]]> = {
|
|
134
|
+
readonly [K in keyof TPaths]: TPaths[K] extends MaybeRef<infer TKey> ? TKey extends Path<TValues> ? Ref<PathValue<TValues, TKey>> : Ref<unknown> : Ref<unknown>;
|
|
135
|
+
};
|
|
136
|
+
type FlattenAndSetPathsType<TRecord, TType> = {
|
|
137
|
+
[K in Path<TRecord>]: TType;
|
|
138
|
+
};
|
|
3
139
|
|
|
4
140
|
interface FieldValidationMetaInfo {
|
|
5
141
|
field: string;
|
|
@@ -16,7 +152,6 @@ type ValidationRuleFunction<TValue = unknown, TParams = unknown[] | Record<strin
|
|
|
16
152
|
type SimpleValidationRuleFunction<TValue = unknown, TParams = unknown[] | Record<string, unknown>> = (value: TValue, params: TParams) => boolean | string | Promise<boolean | string>;
|
|
17
153
|
type ValidationMessageGenerator = (ctx: FieldValidationMetaInfo) => string;
|
|
18
154
|
|
|
19
|
-
type GenericFormValues = Record<string, any>;
|
|
20
155
|
interface ValidationResult {
|
|
21
156
|
errors: string[];
|
|
22
157
|
valid: boolean;
|
|
@@ -35,10 +170,8 @@ interface TypedSchema<TInput = any, TOutput = TInput> {
|
|
|
35
170
|
}
|
|
36
171
|
type YupSchema<TValues = any> = {
|
|
37
172
|
__isYupSchema__: boolean;
|
|
38
|
-
validate(value: any, options:
|
|
173
|
+
validate(value: any, options: GenericObject): Promise<any>;
|
|
39
174
|
};
|
|
40
|
-
type MaybeRef<T> = Ref<T> | T;
|
|
41
|
-
type MaybeRefOrLazy<T> = MaybeRef<T> | (() => T);
|
|
42
175
|
interface FieldMeta<TValue> {
|
|
43
176
|
touched: boolean;
|
|
44
177
|
dirty: boolean;
|
|
@@ -47,7 +180,7 @@ interface FieldMeta<TValue> {
|
|
|
47
180
|
pending: boolean;
|
|
48
181
|
initialValue?: TValue;
|
|
49
182
|
}
|
|
50
|
-
interface FormMeta<TValues extends
|
|
183
|
+
interface FormMeta<TValues extends GenericObject> {
|
|
51
184
|
touched: boolean;
|
|
52
185
|
dirty: boolean;
|
|
53
186
|
valid: boolean;
|
|
@@ -60,6 +193,7 @@ interface FieldState<TValue = unknown> {
|
|
|
60
193
|
touched: boolean;
|
|
61
194
|
errors: string[];
|
|
62
195
|
}
|
|
196
|
+
type InputType = 'checkbox' | 'radio' | 'default';
|
|
63
197
|
/**
|
|
64
198
|
* validated-only: only mutate the previously validated fields
|
|
65
199
|
* silent: do not mutate any field
|
|
@@ -69,6 +203,31 @@ type SchemaValidationMode = 'validated-only' | 'silent' | 'force';
|
|
|
69
203
|
interface ValidationOptions$1 {
|
|
70
204
|
mode: SchemaValidationMode;
|
|
71
205
|
}
|
|
206
|
+
type FieldValidator = (opts?: Partial<ValidationOptions$1>) => Promise<ValidationResult>;
|
|
207
|
+
interface PathStateConfig {
|
|
208
|
+
bails: boolean;
|
|
209
|
+
label: MaybeRef<string | undefined>;
|
|
210
|
+
type: InputType;
|
|
211
|
+
validate: FieldValidator;
|
|
212
|
+
}
|
|
213
|
+
interface PathState<TValue = unknown> {
|
|
214
|
+
id: number | number[];
|
|
215
|
+
path: string;
|
|
216
|
+
touched: boolean;
|
|
217
|
+
dirty: boolean;
|
|
218
|
+
valid: boolean;
|
|
219
|
+
validated: boolean;
|
|
220
|
+
pending: boolean;
|
|
221
|
+
initialValue: TValue | undefined;
|
|
222
|
+
value: TValue | undefined;
|
|
223
|
+
errors: string[];
|
|
224
|
+
bails: boolean;
|
|
225
|
+
label: string | undefined;
|
|
226
|
+
type: InputType;
|
|
227
|
+
multiple: boolean;
|
|
228
|
+
fieldsCount: number;
|
|
229
|
+
validate?: FieldValidator;
|
|
230
|
+
}
|
|
72
231
|
interface FieldEntry<TValue = unknown> {
|
|
73
232
|
value: TValue;
|
|
74
233
|
key: string | number;
|
|
@@ -106,7 +265,7 @@ interface PrivateFieldContext<TValue = unknown> {
|
|
|
106
265
|
checked?: Ref<boolean>;
|
|
107
266
|
resetField(state?: Partial<FieldState<TValue>>): void;
|
|
108
267
|
handleReset(): void;
|
|
109
|
-
validate
|
|
268
|
+
validate: FieldValidator;
|
|
110
269
|
handleChange(e: Event | unknown, shouldValidate?: boolean): void;
|
|
111
270
|
handleBlur(e?: Event): void;
|
|
112
271
|
setState(state: Partial<FieldState<TValue>>): void;
|
|
@@ -117,55 +276,51 @@ interface PrivateFieldContext<TValue = unknown> {
|
|
|
117
276
|
type FieldContext<TValue = unknown> = Omit<PrivateFieldContext<TValue>, 'id' | 'instances'>;
|
|
118
277
|
type GenericValidateFunction<TValue = unknown> = (value: TValue, ctx: FieldValidationMetaInfo) => boolean | string | Promise<boolean | string>;
|
|
119
278
|
interface FormState<TValues> {
|
|
120
|
-
values: TValues
|
|
121
|
-
errors: Partial<Record<
|
|
122
|
-
touched: Partial<Record<
|
|
279
|
+
values: PartialDeep<TValues>;
|
|
280
|
+
errors: Partial<Record<Path<TValues>, string | undefined>>;
|
|
281
|
+
touched: Partial<Record<Path<TValues>, boolean>>;
|
|
123
282
|
submitCount: number;
|
|
124
283
|
}
|
|
125
|
-
type FormErrors<TValues extends
|
|
126
|
-
type FormErrorBag<TValues extends
|
|
284
|
+
type FormErrors<TValues extends GenericObject> = Partial<Record<Path<TValues>, string | undefined>>;
|
|
285
|
+
type FormErrorBag<TValues extends GenericObject> = Partial<Record<Path<TValues>, string[]>>;
|
|
127
286
|
interface SetFieldValueOptions {
|
|
128
287
|
force: boolean;
|
|
129
288
|
}
|
|
130
|
-
interface FormActions<TValues extends
|
|
131
|
-
setFieldValue<T extends
|
|
132
|
-
setFieldError(field:
|
|
289
|
+
interface FormActions<TValues extends GenericObject, TOutput = TValues> {
|
|
290
|
+
setFieldValue<T extends Path<TValues>>(field: T, value: PathValue<TValues, T>, opts?: Partial<SetFieldValueOptions>): void;
|
|
291
|
+
setFieldError(field: Path<TValues>, message: string | string[] | undefined): void;
|
|
133
292
|
setErrors(fields: FormErrors<TValues>): void;
|
|
134
|
-
setValues
|
|
135
|
-
setFieldTouched(field:
|
|
136
|
-
setTouched(fields: Partial<Record<
|
|
293
|
+
setValues(fields: PartialDeep<TValues>): void;
|
|
294
|
+
setFieldTouched(field: Path<TValues>, isTouched: boolean): void;
|
|
295
|
+
setTouched(fields: Partial<Record<Path<TValues>, boolean>>): void;
|
|
137
296
|
resetForm(state?: Partial<FormState<TValues>>): void;
|
|
138
|
-
resetField(field:
|
|
297
|
+
resetField(field: Path<TValues>, state?: Partial<FieldState>): void;
|
|
139
298
|
}
|
|
140
299
|
interface FormValidationResult<TValues, TOutput = TValues> {
|
|
141
300
|
valid: boolean;
|
|
142
|
-
results: Partial<Record<
|
|
143
|
-
errors: Partial<Record<
|
|
301
|
+
results: Partial<Record<Path<TValues>, ValidationResult>>;
|
|
302
|
+
errors: Partial<Record<Path<TValues>, string>>;
|
|
144
303
|
values?: TOutput;
|
|
145
304
|
}
|
|
146
|
-
interface SubmissionContext<TValues extends
|
|
305
|
+
interface SubmissionContext<TValues extends GenericObject = GenericObject> extends FormActions<TValues> {
|
|
147
306
|
evt?: Event;
|
|
148
307
|
controlledValues: Partial<TValues>;
|
|
149
308
|
}
|
|
150
|
-
type SubmissionHandler<TValues extends
|
|
151
|
-
interface InvalidSubmissionContext<TValues extends
|
|
309
|
+
type SubmissionHandler<TValues extends GenericObject = GenericObject, TOutput = TValues, TReturn = unknown> = (values: TOutput, ctx: SubmissionContext<TValues>) => TReturn;
|
|
310
|
+
interface InvalidSubmissionContext<TValues extends GenericObject = GenericObject> {
|
|
152
311
|
values: TValues;
|
|
153
312
|
evt?: Event;
|
|
154
|
-
errors: Partial<Record<
|
|
155
|
-
results: Partial<Record<
|
|
313
|
+
errors: Partial<Record<Path<TValues>, string>>;
|
|
314
|
+
results: Partial<Record<Path<TValues>, ValidationResult>>;
|
|
156
315
|
}
|
|
157
|
-
type InvalidSubmissionHandler<TValues extends
|
|
158
|
-
type RawFormSchema<TValues> = Record<
|
|
159
|
-
type
|
|
160
|
-
|
|
161
|
-
[K in keyof T]: T[K] extends MaybeRef<infer TKey> ? TKey extends keyof TValues ? Ref<TValues[TKey]> : Ref<unknown> : Ref<unknown>;
|
|
162
|
-
};
|
|
163
|
-
type HandleSubmitFactory<TValues extends GenericFormValues, TOutput extends TValues = TValues> = <TReturn = unknown>(cb: SubmissionHandler<TValues, TOutput, TReturn>, onSubmitValidationErrorCb?: InvalidSubmissionHandler<TValues>) => (e?: Event) => Promise<TReturn | undefined>;
|
|
164
|
-
interface PrivateFormContext<TValues extends GenericFormValues = GenericFormValues, TOutput extends TValues = TValues> extends FormActions<TValues> {
|
|
316
|
+
type InvalidSubmissionHandler<TValues extends GenericObject = GenericObject> = (ctx: InvalidSubmissionContext<TValues>) => void;
|
|
317
|
+
type RawFormSchema<TValues> = Record<Path<TValues>, string | GenericValidateFunction | GenericObject>;
|
|
318
|
+
type HandleSubmitFactory<TValues extends GenericObject, TOutput = TValues> = <TReturn = unknown>(cb: SubmissionHandler<TValues, TOutput, TReturn>, onSubmitValidationErrorCb?: InvalidSubmissionHandler<TValues>) => (e?: Event) => Promise<TReturn | undefined>;
|
|
319
|
+
interface PrivateFormContext<TValues extends GenericObject = GenericObject, TOutput = TValues> extends FormActions<TValues> {
|
|
165
320
|
formId: number;
|
|
166
321
|
values: TValues;
|
|
322
|
+
initialValues: Ref<Partial<TValues>>;
|
|
167
323
|
controlledValues: Ref<TValues>;
|
|
168
|
-
fieldsByPath: Ref<FieldPathLookup>;
|
|
169
324
|
fieldArrays: PrivateFieldArrayContext[];
|
|
170
325
|
submitCount: Ref<number>;
|
|
171
326
|
schema?: MaybeRef<RawFormSchema<TValues> | TypedSchema<TValues, TOutput> | YupSchema<TValues> | undefined>;
|
|
@@ -175,23 +330,61 @@ interface PrivateFormContext<TValues extends GenericFormValues = GenericFormValu
|
|
|
175
330
|
isSubmitting: Ref<boolean>;
|
|
176
331
|
keepValuesOnUnmount: MaybeRef<boolean>;
|
|
177
332
|
validateSchema?: (mode: SchemaValidationMode) => Promise<FormValidationResult<TValues, TOutput>>;
|
|
178
|
-
validate(opts?: Partial<ValidationOptions$1>): Promise<FormValidationResult<TValues>>;
|
|
179
|
-
validateField(field:
|
|
180
|
-
setFieldErrorBag(field: string, messages: string | string[]): void;
|
|
333
|
+
validate(opts?: Partial<ValidationOptions$1>): Promise<FormValidationResult<TValues, TOutput>>;
|
|
334
|
+
validateField(field: Path<TValues>): Promise<ValidationResult>;
|
|
181
335
|
stageInitialValue(path: string, value: unknown, updateOriginal?: boolean): void;
|
|
182
336
|
unsetInitialValue(path: string): void;
|
|
183
|
-
register(field: PrivateFieldContext): void;
|
|
184
|
-
unregister(field: PrivateFieldContext): void;
|
|
185
337
|
handleSubmit: HandleSubmitFactory<TValues, TOutput> & {
|
|
186
338
|
withControlled: HandleSubmitFactory<TValues, TOutput>;
|
|
187
339
|
};
|
|
188
340
|
setFieldInitialValue(path: string, value: unknown): void;
|
|
189
|
-
useFieldModel<TPath extends
|
|
190
|
-
useFieldModel<
|
|
341
|
+
useFieldModel<TPath extends Path<TValues>>(path: TPath): Ref<PathValue<TValues, TPath>>;
|
|
342
|
+
useFieldModel<TPaths extends readonly [...MaybeRef<Path<TValues>>[]]>(paths: TPaths): MapValuesPathsToRefs<TValues, TPaths>;
|
|
343
|
+
createPathState<TPath extends Path<TValues>>(path: MaybeRef<TPath>, config?: Partial<PathStateConfig>): PathState<PathValue<TValues, TPath>>;
|
|
344
|
+
getPathState<TPath extends Path<TValues>>(path: TPath): PathState<PathValue<TValues, TPath>> | undefined;
|
|
345
|
+
getAllPathStates(): PathState[];
|
|
346
|
+
removePathState<TPath extends Path<TValues>>(path: TPath): void;
|
|
347
|
+
unsetPathValue<TPath extends Path<TValues>>(path: TPath): void;
|
|
191
348
|
}
|
|
192
|
-
interface
|
|
349
|
+
interface BaseComponentBinds<TValue = unknown> {
|
|
350
|
+
modelValue: TValue | undefined;
|
|
351
|
+
'onUpdate:modelValue': (value: TValue) => void;
|
|
352
|
+
onBlur: () => void;
|
|
353
|
+
}
|
|
354
|
+
type PublicPathState<TValue = unknown> = Omit<PathState<TValue>, 'bails' | 'label' | 'multiple' | 'fieldsCount' | 'validate' | 'id' | 'type'>;
|
|
355
|
+
interface ComponentBindsConfig<TValue = unknown, TExtraProps extends GenericObject = GenericObject> {
|
|
356
|
+
mapProps: (state: PublicPathState<TValue>) => TExtraProps;
|
|
357
|
+
validateOnBlur: boolean;
|
|
358
|
+
validateOnModelUpdate: boolean;
|
|
359
|
+
}
|
|
360
|
+
type LazyComponentBindsConfig<TValue = unknown, TExtraProps extends GenericObject = GenericObject> = (state: PublicPathState<TValue>) => Partial<{
|
|
361
|
+
props: TExtraProps;
|
|
362
|
+
validateOnBlur: boolean;
|
|
363
|
+
validateOnModelUpdate: boolean;
|
|
364
|
+
}>;
|
|
365
|
+
interface BaseInputBinds<TValue = unknown> {
|
|
366
|
+
value: TValue | undefined;
|
|
367
|
+
onBlur: (e: Event) => void;
|
|
368
|
+
onChange: (e: Event) => void;
|
|
369
|
+
onInput: (e: Event) => void;
|
|
370
|
+
}
|
|
371
|
+
interface InputBindsConfig<TValue = unknown, TExtraProps extends GenericObject = GenericObject> {
|
|
372
|
+
mapAttrs: (state: PublicPathState<TValue>) => TExtraProps;
|
|
373
|
+
validateOnBlur: boolean;
|
|
374
|
+
validateOnChange: boolean;
|
|
375
|
+
validateOnInput: boolean;
|
|
376
|
+
}
|
|
377
|
+
type LazyInputBindsConfig<TValue = unknown, TExtraProps extends GenericObject = GenericObject> = (state: PublicPathState<TValue>) => Partial<{
|
|
378
|
+
attrs: TExtraProps;
|
|
379
|
+
validateOnBlur: boolean;
|
|
380
|
+
validateOnChange: boolean;
|
|
381
|
+
validateOnInput: boolean;
|
|
382
|
+
}>;
|
|
383
|
+
interface FormContext<TValues extends GenericObject = GenericObject, TOutput = TValues> extends Omit<PrivateFormContext<TValues, TOutput>, 'formId' | 'schema' | 'initialValues' | 'getPathState' | 'getAllPathStates' | 'removePathState' | 'unsetPathValue' | 'validateSchema' | 'stageInitialValue' | 'setFieldInitialValue' | 'unsetInitialValue' | 'fieldArrays' | 'keepValuesOnUnmount'> {
|
|
193
384
|
handleReset: () => void;
|
|
194
385
|
submitForm: (e?: unknown) => Promise<void>;
|
|
386
|
+
defineComponentBinds<TPath extends Path<TValues>, TValue = PathValue<TValues, TPath>, TExtras extends GenericObject = GenericObject>(path: MaybeRefOrLazy<TPath>, config?: Partial<ComponentBindsConfig<TValue, TExtras>> | LazyComponentBindsConfig<TValue, TExtras>): Ref<BaseComponentBinds<TValue> & TExtras>;
|
|
387
|
+
defineInputBinds<TPath extends Path<TValues>, TValue = PathValue<TValues, TPath>, TExtras extends GenericObject = GenericObject>(path: MaybeRefOrLazy<TPath>, config?: Partial<InputBindsConfig<TValue, TExtras>> | LazyInputBindsConfig<TValue, TExtras>): Ref<BaseInputBinds<TValue> & TExtras>;
|
|
195
388
|
}
|
|
196
389
|
|
|
197
390
|
interface ValidationOptions {
|
|
@@ -232,7 +425,7 @@ interface FieldOptions<TValue = unknown> {
|
|
|
232
425
|
validateOnValueUpdate: boolean;
|
|
233
426
|
validateOnMount?: boolean;
|
|
234
427
|
bails?: boolean;
|
|
235
|
-
type?:
|
|
428
|
+
type?: InputType;
|
|
236
429
|
valueProp?: MaybeRef<TValue>;
|
|
237
430
|
checkedValue?: MaybeRef<TValue>;
|
|
238
431
|
uncheckedValue?: MaybeRef<TValue>;
|
|
@@ -250,13 +443,13 @@ type RuleExpression<TValue> = string | Record<string, unknown> | GenericValidate
|
|
|
250
443
|
*/
|
|
251
444
|
declare function useField<TValue = unknown>(path: MaybeRefOrLazy<string>, rules?: MaybeRef<RuleExpression<TValue>>, opts?: Partial<FieldOptions<TValue>>): FieldContext<TValue>;
|
|
252
445
|
|
|
253
|
-
interface FieldBindingObject<TValue =
|
|
446
|
+
interface FieldBindingObject<TValue = any> {
|
|
254
447
|
name: string;
|
|
255
|
-
onBlur: (e: Event) =>
|
|
256
|
-
onInput: (e: Event) =>
|
|
257
|
-
onChange: (e: Event) =>
|
|
448
|
+
onBlur: (e: Event) => void;
|
|
449
|
+
onInput: (e: Event) => void;
|
|
450
|
+
onChange: (e: Event) => void;
|
|
258
451
|
'onUpdate:modelValue'?: ((e: TValue) => unknown) | undefined;
|
|
259
|
-
value?:
|
|
452
|
+
value?: TValue;
|
|
260
453
|
checked?: boolean;
|
|
261
454
|
}
|
|
262
455
|
interface FieldSlotProps<TValue = unknown> extends Pick<FieldContext, 'validate' | 'resetField' | 'handleChange' | 'handleReset' | 'handleBlur' | 'setTouched' | 'setErrors'> {
|
|
@@ -655,23 +848,23 @@ declare const Field: {
|
|
|
655
848
|
type FormSlotProps = UnwrapRef<Pick<FormContext, 'meta' | 'errors' | 'errorBag' | 'values' | 'isSubmitting' | 'submitCount' | 'validate' | 'validateField' | 'handleReset' | 'setErrors' | 'setFieldError' | 'setFieldValue' | 'setValues' | 'setFieldTouched' | 'setTouched' | 'resetForm' | 'resetField' | 'controlledValues'>> & {
|
|
656
849
|
handleSubmit: (evt: Event | SubmissionHandler, onSubmit?: SubmissionHandler) => Promise<unknown>;
|
|
657
850
|
submitForm(evt?: Event): void;
|
|
658
|
-
getValues<TValues extends
|
|
659
|
-
getMeta<TValues extends
|
|
660
|
-
getErrors<TValues extends
|
|
851
|
+
getValues<TValues extends GenericObject = GenericObject>(): TValues;
|
|
852
|
+
getMeta<TValues extends GenericObject = GenericObject>(): FormMeta<TValues>;
|
|
853
|
+
getErrors<TValues extends GenericObject = GenericObject>(): FormErrors<TValues>;
|
|
661
854
|
};
|
|
662
855
|
declare const Form: {
|
|
663
856
|
new (...args: any[]): {
|
|
664
857
|
$: vue.ComponentInternalInstance;
|
|
665
858
|
$data: {};
|
|
666
859
|
$props: Partial<{
|
|
667
|
-
onSubmit: SubmissionHandler
|
|
860
|
+
onSubmit: SubmissionHandler;
|
|
668
861
|
as: string;
|
|
669
862
|
initialValues: Record<string, any>;
|
|
670
863
|
validateOnMount: boolean;
|
|
671
864
|
validationSchema: Record<string, any>;
|
|
672
865
|
initialErrors: Record<string, any>;
|
|
673
866
|
initialTouched: Record<string, any>;
|
|
674
|
-
onInvalidSubmit: InvalidSubmissionHandler
|
|
867
|
+
onInvalidSubmit: InvalidSubmissionHandler;
|
|
675
868
|
keepValues: boolean;
|
|
676
869
|
}> & Omit<Readonly<vue.ExtractPropTypes<{
|
|
677
870
|
as: {
|
|
@@ -699,11 +892,11 @@ declare const Form: {
|
|
|
699
892
|
default: boolean;
|
|
700
893
|
};
|
|
701
894
|
onSubmit: {
|
|
702
|
-
type: PropType<SubmissionHandler
|
|
895
|
+
type: PropType<SubmissionHandler>;
|
|
703
896
|
default: any;
|
|
704
897
|
};
|
|
705
898
|
onInvalidSubmit: {
|
|
706
|
-
type: PropType<InvalidSubmissionHandler
|
|
899
|
+
type: PropType<InvalidSubmissionHandler>;
|
|
707
900
|
default: any;
|
|
708
901
|
};
|
|
709
902
|
keepValues: {
|
|
@@ -750,11 +943,11 @@ declare const Form: {
|
|
|
750
943
|
default: boolean;
|
|
751
944
|
};
|
|
752
945
|
onSubmit: {
|
|
753
|
-
type: PropType<SubmissionHandler
|
|
946
|
+
type: PropType<SubmissionHandler>;
|
|
754
947
|
default: any;
|
|
755
948
|
};
|
|
756
949
|
onInvalidSubmit: {
|
|
757
|
-
type: PropType<InvalidSubmissionHandler
|
|
950
|
+
type: PropType<InvalidSubmissionHandler>;
|
|
758
951
|
default: any;
|
|
759
952
|
};
|
|
760
953
|
keepValues: {
|
|
@@ -770,14 +963,14 @@ declare const Form: {
|
|
|
770
963
|
[key: string]: any;
|
|
771
964
|
}>[];
|
|
772
965
|
}, unknown, {}, {}, vue.ComponentOptionsMixin, vue.ComponentOptionsMixin, {}, string, {
|
|
773
|
-
onSubmit: SubmissionHandler
|
|
966
|
+
onSubmit: SubmissionHandler;
|
|
774
967
|
as: string;
|
|
775
968
|
initialValues: Record<string, any>;
|
|
776
969
|
validateOnMount: boolean;
|
|
777
970
|
validationSchema: Record<string, any>;
|
|
778
971
|
initialErrors: Record<string, any>;
|
|
779
972
|
initialTouched: Record<string, any>;
|
|
780
|
-
onInvalidSubmit: InvalidSubmissionHandler
|
|
973
|
+
onInvalidSubmit: InvalidSubmissionHandler;
|
|
781
974
|
keepValues: boolean;
|
|
782
975
|
}, {}, string> & {
|
|
783
976
|
beforeCreate?: (() => void) | (() => void)[];
|
|
@@ -825,11 +1018,11 @@ declare const Form: {
|
|
|
825
1018
|
default: boolean;
|
|
826
1019
|
};
|
|
827
1020
|
onSubmit: {
|
|
828
|
-
type: PropType<SubmissionHandler
|
|
1021
|
+
type: PropType<SubmissionHandler>;
|
|
829
1022
|
default: any;
|
|
830
1023
|
};
|
|
831
1024
|
onInvalidSubmit: {
|
|
832
|
-
type: PropType<InvalidSubmissionHandler
|
|
1025
|
+
type: PropType<InvalidSubmissionHandler>;
|
|
833
1026
|
default: any;
|
|
834
1027
|
};
|
|
835
1028
|
keepValues: {
|
|
@@ -874,11 +1067,11 @@ declare const Form: {
|
|
|
874
1067
|
default: boolean;
|
|
875
1068
|
};
|
|
876
1069
|
onSubmit: {
|
|
877
|
-
type: PropType<SubmissionHandler
|
|
1070
|
+
type: PropType<SubmissionHandler>;
|
|
878
1071
|
default: any;
|
|
879
1072
|
};
|
|
880
1073
|
onInvalidSubmit: {
|
|
881
|
-
type: PropType<InvalidSubmissionHandler
|
|
1074
|
+
type: PropType<InvalidSubmissionHandler>;
|
|
882
1075
|
default: any;
|
|
883
1076
|
};
|
|
884
1077
|
keepValues: {
|
|
@@ -894,14 +1087,14 @@ declare const Form: {
|
|
|
894
1087
|
[key: string]: any;
|
|
895
1088
|
}>[];
|
|
896
1089
|
}, unknown, {}, {}, vue.ComponentOptionsMixin, vue.ComponentOptionsMixin, {}, string, {
|
|
897
|
-
onSubmit: SubmissionHandler
|
|
1090
|
+
onSubmit: SubmissionHandler;
|
|
898
1091
|
as: string;
|
|
899
1092
|
initialValues: Record<string, any>;
|
|
900
1093
|
validateOnMount: boolean;
|
|
901
1094
|
validationSchema: Record<string, any>;
|
|
902
1095
|
initialErrors: Record<string, any>;
|
|
903
1096
|
initialTouched: Record<string, any>;
|
|
904
|
-
onInvalidSubmit: InvalidSubmissionHandler
|
|
1097
|
+
onInvalidSubmit: InvalidSubmissionHandler;
|
|
905
1098
|
keepValues: boolean;
|
|
906
1099
|
}, {}, string> & vue.VNodeProps & vue.AllowedComponentProps & vue.ComponentCustomProps & (new () => {
|
|
907
1100
|
setFieldError: FormContext['setFieldError'];
|
|
@@ -1133,16 +1326,16 @@ declare const ErrorMessage: {
|
|
|
1133
1326
|
};
|
|
1134
1327
|
});
|
|
1135
1328
|
|
|
1136
|
-
type FormSchema<TValues
|
|
1137
|
-
interface FormOptions<TValues extends
|
|
1329
|
+
type FormSchema<TValues extends Record<string, unknown>> = FlattenAndSetPathsType<TValues, GenericValidateFunction | string | GenericObject> | undefined;
|
|
1330
|
+
interface FormOptions<TValues extends GenericObject, TOutput = TValues, TSchema extends TypedSchema<TValues, TOutput> | FormSchema<TValues> = FormSchema<TValues> | TypedSchema<TValues, TOutput>> {
|
|
1138
1331
|
validationSchema?: MaybeRef<TSchema extends TypedSchema ? TypedSchema<TValues, TOutput> : any>;
|
|
1139
|
-
initialValues?: MaybeRef<
|
|
1140
|
-
initialErrors?:
|
|
1141
|
-
initialTouched?:
|
|
1332
|
+
initialValues?: MaybeRef<PartialDeep<TValues>>;
|
|
1333
|
+
initialErrors?: FlattenAndSetPathsType<TValues, string | undefined>;
|
|
1334
|
+
initialTouched?: FlattenAndSetPathsType<TValues, boolean>;
|
|
1142
1335
|
validateOnMount?: boolean;
|
|
1143
1336
|
keepValuesOnUnmount?: MaybeRef<boolean>;
|
|
1144
1337
|
}
|
|
1145
|
-
declare function useForm<TValues extends
|
|
1338
|
+
declare function useForm<TValues extends GenericObject = GenericObject, TOutput = TValues, TSchema extends FormSchema<TValues> | TypedSchema<TValues, TOutput> = FormSchema<TValues> | TypedSchema<TValues, TOutput>>(opts?: FormOptions<TValues, TOutput, TSchema>): FormContext<TValues, TOutput>;
|
|
1146
1339
|
|
|
1147
1340
|
declare function useFieldArray<TValue = unknown>(arrayPath: MaybeRef<string>): FieldArrayContext<TValue>;
|
|
1148
1341
|
|
|
@@ -1211,7 +1404,7 @@ declare function useFormValues<TValues extends Record<string, any> = Record<stri
|
|
|
1211
1404
|
/**
|
|
1212
1405
|
* Gives access to all form errors
|
|
1213
1406
|
*/
|
|
1214
|
-
declare function useFormErrors<TValues extends Record<string, unknown> = Record<string, unknown>>(): vue.ComputedRef<Partial<Record<
|
|
1407
|
+
declare function useFormErrors<TValues extends Record<string, unknown> = Record<string, unknown>>(): vue.ComputedRef<Partial<Record<Path<TValues>, string>>>;
|
|
1215
1408
|
|
|
1216
1409
|
/**
|
|
1217
1410
|
* Gives access to a single field error
|
|
@@ -1224,4 +1417,4 @@ declare const FormContextKey: InjectionKey<PrivateFormContext>;
|
|
|
1224
1417
|
declare const FieldContextKey: InjectionKey<PrivateFieldContext<unknown>>;
|
|
1225
1418
|
declare const IS_ABSENT: any;
|
|
1226
1419
|
|
|
1227
|
-
export { ErrorMessage, Field, FieldArray, FieldArrayContext, FieldContext, FieldContextKey, FieldEntry, FieldMeta, FieldOptions, FieldState, Form, FormActions, FormContext, FormContextKey, FormMeta, FormOptions, FormState, FormValidationResult, GenericValidateFunction, IS_ABSENT, InvalidSubmissionContext, InvalidSubmissionHandler, RawFormSchema, RuleExpression, SubmissionContext, SubmissionHandler, TypedSchema, TypedSchemaError, ValidationOptions$1 as ValidationOptions, ValidationResult, configure, defineRule, useField, useFieldArray, useFieldError, useFieldValue, useForm, useFormErrors, useFormValues, useIsFieldDirty, useIsFieldTouched, useIsFieldValid, useIsFormDirty, useIsFormTouched, useIsFormValid, useIsSubmitting, useResetForm, useSubmitCount, useSubmitForm, useValidateField, useValidateForm, validate, validateObjectSchema as validateObject };
|
|
1420
|
+
export { ComponentBindsConfig, ErrorMessage, Field, FieldArray, FieldArrayContext, FieldContext, FieldContextKey, FieldEntry, FieldMeta, FieldOptions, FieldState, Form, FormActions, FormContext, FormContextKey, FormMeta, FormOptions, FormState, FormValidationResult, GenericValidateFunction, IS_ABSENT, InputBindsConfig, InvalidSubmissionContext, InvalidSubmissionHandler, LazyComponentBindsConfig, LazyInputBindsConfig, Path, PublicPathState as PathState, RawFormSchema, RuleExpression, SubmissionContext, SubmissionHandler, TypedSchema, TypedSchemaError, ValidationOptions$1 as ValidationOptions, ValidationResult, configure, defineRule, useField, useFieldArray, useFieldError, useFieldValue, useForm, useFormErrors, useFormValues, useIsFieldDirty, useIsFieldTouched, useIsFieldValid, useIsFormDirty, useIsFormTouched, useIsFormValid, useIsSubmitting, useResetForm, useSubmitCount, useSubmitForm, useValidateField, useValidateForm, validate, validateObjectSchema as validateObject };
|