vee-validate 4.15.1 → 5.0.0-beta.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.
@@ -1,6 +1,7 @@
1
1
  import * as vue from 'vue';
2
2
  import { MaybeRef, Ref, MaybeRefOrGetter, ComputedRef, PropType, VNode, UnwrapRef, InjectionKey } from 'vue';
3
3
  import { PartialDeep } from 'type-fest';
4
+ import { StandardSchemaV1 } from '@standard-schema/spec';
4
5
 
5
6
  type BrowserNativeObject = Date | FileList | File;
6
7
  type Primitive = null | undefined | string | number | boolean | symbol | bigint;
@@ -177,32 +178,6 @@ interface ValidationResult<TValue = unknown> {
177
178
  type FlattenAndMapPathsValidationResult<TInput extends GenericObject, TOutput extends GenericObject> = {
178
179
  [K in Path<TInput>]: ValidationResult<TOutput[K]>;
179
180
  };
180
- interface TypedSchemaError {
181
- path?: string;
182
- errors: string[];
183
- }
184
- interface TypedSchemaPathDescription {
185
- required: boolean;
186
- exists: boolean;
187
- }
188
- interface TypedSchemaContext {
189
- formData: GenericObject;
190
- }
191
- interface TypedSchema<TInput = any, TOutput = TInput> {
192
- __type: 'VVTypedSchema';
193
- parse(values: TInput, context?: TypedSchemaContext): Promise<{
194
- value?: TOutput;
195
- errors: TypedSchemaError[];
196
- }>;
197
- cast?(values: Partial<TInput>): TInput;
198
- describe?(path?: Path<TInput>): Partial<TypedSchemaPathDescription>;
199
- }
200
- type InferOutput<TSchema extends TypedSchema> = TSchema extends TypedSchema<any, infer TOutput> ? TOutput : never;
201
- type InferInput<TSchema extends TypedSchema> = TSchema extends TypedSchema<infer TInput, any> ? TInput : never;
202
- type YupSchema<TValues = any> = {
203
- __isYupSchema__: boolean;
204
- validate(value: any, options: GenericObject): Promise<any>;
205
- };
206
181
  type Locator = {
207
182
  __locatorRef: string;
208
183
  } & ((values: GenericObject) => unknown);
@@ -211,7 +186,6 @@ interface FieldMeta<TValue> {
211
186
  dirty: boolean;
212
187
  valid: boolean;
213
188
  validated: boolean;
214
- required: boolean;
215
189
  pending: boolean;
216
190
  initialValue?: TValue;
217
191
  }
@@ -244,15 +218,18 @@ interface PathStateConfig<TOutput> {
244
218
  label: MaybeRefOrGetter<string | undefined>;
245
219
  type: InputType;
246
220
  validate: FieldValidator<TOutput>;
247
- schema?: MaybeRefOrGetter<TypedSchema | undefined>;
221
+ schema?: MaybeRefOrGetter<StandardSchemaV1 | undefined>;
248
222
  }
223
+ type IssueCollection<TPath = string> = {
224
+ path: TPath;
225
+ messages: string[];
226
+ };
249
227
  interface PathState<TInput = unknown, TOutput = TInput> {
250
228
  id: number | number[];
251
229
  path: string;
252
230
  touched: boolean;
253
231
  dirty: boolean;
254
232
  valid: boolean;
255
- required: boolean;
256
233
  validated: boolean;
257
234
  pending: boolean;
258
235
  initialValue: TInput | undefined;
@@ -415,7 +392,7 @@ interface PrivateFormContext<TValues extends GenericObject = GenericObject, TOut
415
392
  controlledValues: Ref<TValues>;
416
393
  fieldArrays: PrivateFieldArrayContext[];
417
394
  submitCount: Ref<number>;
418
- schema?: MaybeRef<RawFormSchema<TValues> | TypedSchema<TValues, TOutput> | YupSchema<TValues> | undefined>;
395
+ schema?: MaybeRef<RawFormSchema<TValues> | StandardSchemaV1<TValues, TOutput> | undefined>;
419
396
  errorBag: Ref<FormErrorBag<TValues>>;
420
397
  errors: ComputedRef<FormErrors<TValues>>;
421
398
  meta: ComputedRef<FormMeta<TValues>>;
@@ -441,22 +418,6 @@ interface PrivateFormContext<TValues extends GenericObject = GenericObject, TOut
441
418
  isFieldDirty<TPath extends Path<TValues>>(path: TPath): boolean;
442
419
  isFieldValid<TPath extends Path<TValues>>(path: TPath): boolean;
443
420
  defineField<TPath extends Path<TValues>, TValue = PathValue<TValues, TPath>, TExtras extends GenericObject = GenericObject>(path: MaybeRefOrGetter<TPath>, config?: Partial<InputBindsConfig<TValue, TExtras>> | LazyInputBindsConfig<TValue, TExtras>): [Ref<TValue>, Ref<BaseFieldProps & TExtras>];
444
- /**
445
- * @deprecated use defineField instead
446
- */
447
- useFieldModel<TPath extends Path<TValues>>(path: TPath): Ref<PathValue<TValues, TPath>>;
448
- /**
449
- * @deprecated use defineField instead
450
- */
451
- useFieldModel<TPaths extends readonly [...MaybeRef<Path<TValues>>[]]>(paths: TPaths): MapValuesPathsToRefs<TValues, TPaths>;
452
- /**
453
- * @deprecated use defineField instead
454
- */
455
- defineComponentBinds<TPath extends Path<TValues>, TValue = PathValue<TValues, TPath>, TModel extends string = 'modelValue', TExtras extends GenericObject = GenericObject>(path: MaybeRefOrGetter<TPath>, config?: Partial<ComponentBindsConfig<TValue, TExtras, TModel>> | LazyComponentBindsConfig<TValue, TExtras, TModel>): Ref<BaseComponentBinds<TValue, TModel> & TExtras>;
456
- /**
457
- * @deprecated use defineField instead
458
- */
459
- defineInputBinds<TPath extends Path<TValues>, TValue = PathValue<TValues, TPath>, TExtras extends GenericObject = GenericObject>(path: MaybeRefOrGetter<TPath>, config?: Partial<InputBindsConfig<TValue, TExtras>> | LazyInputBindsConfig<TValue, TExtras>): Ref<BaseInputBinds<TValue> & TExtras>;
460
421
  }
461
422
  interface FormContext<TValues extends GenericObject = GenericObject, TOutput extends GenericObject = TValues> extends Omit<PrivateFormContext<TValues, TOutput>, 'formId' | 'schema' | 'initialValues' | 'getPathState' | 'getAllPathStates' | 'removePathState' | 'unsetPathValue' | 'validateSchema' | 'stageInitialValue' | 'setFieldInitialValue' | 'unsetInitialValue' | 'fieldArrays' | 'markForUnmount' | 'keepValuesOnUnmount' | 'values'> {
462
423
  values: TValues;
@@ -489,7 +450,7 @@ interface ValidationOptions {
489
450
  /**
490
451
  * Validates a value against the rules.
491
452
  */
492
- declare function validate<TInput, TOutput>(value: TInput, rules: string | Record<string, unknown | unknown[]> | GenericValidateFunction<TInput> | GenericValidateFunction<TInput>[] | TypedSchema<TInput, TOutput>, options?: ValidationOptions): Promise<ValidationResult<TOutput>>;
453
+ declare function validate<TInput, TOutput>(value: TInput, rules: string | Record<string, unknown | unknown[]> | GenericValidateFunction<TInput> | GenericValidateFunction<TInput>[] | StandardSchemaV1<TInput, TOutput>, options?: ValidationOptions): Promise<ValidationResult<TOutput>>;
493
454
  declare function validateObjectSchema<TValues extends GenericObject, TOutput extends GenericObject>(schema: RawFormSchema<TValues>, values: TValues | undefined, opts?: Partial<{
494
455
  names: Record<string, {
495
456
  name: string;
@@ -511,6 +472,7 @@ interface VeeValidateConfig {
511
472
  validateOnBlur: boolean;
512
473
  validateOnModelUpdate: boolean;
513
474
  }
475
+ declare const getConfig: () => VeeValidateConfig;
514
476
  declare const configure: (newConf: Partial<VeeValidateConfig>) => void;
515
477
 
516
478
  /**
@@ -531,27 +493,15 @@ interface FieldOptions<TValue = unknown> {
531
493
  validateOnMount?: boolean;
532
494
  bails?: boolean;
533
495
  type?: InputType;
534
- /**
535
- * @deprecated Use `checkedValue` instead.
536
- */
537
- valueProp?: MaybeRefOrGetter<TValue>;
538
496
  checkedValue?: MaybeRefOrGetter<TValue>;
539
497
  uncheckedValue?: MaybeRefOrGetter<TValue>;
540
498
  label?: MaybeRefOrGetter<string | undefined>;
541
499
  controlled?: boolean;
542
- /**
543
- * @deprecated Use `controlled` instead, controlled is opposite of standalone.
544
- */
545
- standalone?: boolean;
546
500
  keepValueOnUnmount?: MaybeRefOrGetter<boolean | undefined>;
547
- /**
548
- * @deprecated Pass the model prop name to `syncVModel` instead.
549
- */
550
- modelPropName?: string;
551
501
  syncVModel?: boolean | string;
552
502
  form?: FormContext;
553
503
  }
554
- type RuleExpression<TValue> = string | Record<string, unknown> | GenericValidateFunction<TValue> | GenericValidateFunction<TValue>[] | TypedSchema<TValue> | YupSchema<TValue> | undefined;
504
+ type RuleExpression<TValue> = string | Record<string, unknown> | GenericValidateFunction<TValue> | GenericValidateFunction<TValue>[] | StandardSchemaV1<TValue> | undefined;
555
505
  /**
556
506
  * Creates a field composite.
557
507
  */
@@ -638,7 +588,7 @@ declare const Field: {
638
588
  type: PropType<(e: any) => unknown>;
639
589
  default: any;
640
590
  };
641
- standalone: {
591
+ controlled: {
642
592
  type: BooleanConstructor;
643
593
  default: boolean;
644
594
  };
@@ -711,7 +661,7 @@ declare const Field: {
711
661
  type: PropType<(e: any) => unknown>;
712
662
  default: any;
713
663
  };
714
- standalone: {
664
+ controlled: {
715
665
  type: BooleanConstructor;
716
666
  default: boolean;
717
667
  };
@@ -730,7 +680,7 @@ declare const Field: {
730
680
  validateOnBlur: boolean;
731
681
  validateOnModelUpdate: boolean;
732
682
  validateOnMount: boolean;
733
- standalone: boolean;
683
+ controlled: boolean;
734
684
  modelModifiers: any;
735
685
  rules: RuleExpression<unknown>;
736
686
  'onUpdate:modelValue': (e: any) => unknown;
@@ -799,7 +749,7 @@ declare const Field: {
799
749
  type: PropType<(e: any) => unknown>;
800
750
  default: any;
801
751
  };
802
- standalone: {
752
+ controlled: {
803
753
  type: BooleanConstructor;
804
754
  default: boolean;
805
755
  };
@@ -826,7 +776,7 @@ declare const Field: {
826
776
  validateOnBlur: boolean;
827
777
  validateOnModelUpdate: boolean;
828
778
  validateOnMount: boolean;
829
- standalone: boolean;
779
+ controlled: boolean;
830
780
  modelModifiers: any;
831
781
  rules: RuleExpression<unknown>;
832
782
  'onUpdate:modelValue': (e: any) => unknown;
@@ -892,7 +842,7 @@ declare const Field: {
892
842
  type: PropType<(e: any) => unknown>;
893
843
  default: any;
894
844
  };
895
- standalone: {
845
+ controlled: {
896
846
  type: BooleanConstructor;
897
847
  default: boolean;
898
848
  };
@@ -919,7 +869,7 @@ declare const Field: {
919
869
  validateOnBlur: boolean;
920
870
  validateOnModelUpdate: boolean;
921
871
  validateOnMount: boolean;
922
- standalone: boolean;
872
+ controlled: boolean;
923
873
  modelModifiers: any;
924
874
  rules: RuleExpression<unknown>;
925
875
  'onUpdate:modelValue': (e: any) => unknown;
@@ -1354,8 +1304,8 @@ declare const ErrorMessage: {
1354
1304
  });
1355
1305
 
1356
1306
  type FormSchema<TValues extends Record<string, unknown>> = FlattenAndSetPathsType<TValues, GenericValidateFunction | string | GenericObject> | undefined;
1357
- interface FormOptions<TValues extends GenericObject, TOutput = TValues, TSchema extends TypedSchema<TValues, TOutput> | FormSchema<TValues> = FormSchema<TValues> | TypedSchema<TValues, TOutput>> {
1358
- validationSchema?: MaybeRef<TSchema extends TypedSchema ? TypedSchema<TValues, TOutput> : any>;
1307
+ interface FormOptions<TValues extends GenericObject, TOutput = TValues, TSchema extends StandardSchemaV1<TValues, TOutput> | FormSchema<TValues> = FormSchema<TValues>> {
1308
+ validationSchema?: MaybeRef<TSchema extends StandardSchemaV1 ? StandardSchemaV1<TValues, TOutput> : any>;
1359
1309
  initialValues?: PartialDeep<TValues> | undefined | null;
1360
1310
  initialErrors?: FlattenAndSetPathsType<TValues, string | undefined>;
1361
1311
  initialTouched?: FlattenAndSetPathsType<TValues, boolean>;
@@ -1363,7 +1313,7 @@ interface FormOptions<TValues extends GenericObject, TOutput = TValues, TSchema
1363
1313
  keepValuesOnUnmount?: MaybeRef<boolean>;
1364
1314
  name?: string;
1365
1315
  }
1366
- declare function useForm<TValues extends GenericObject = GenericObject, TOutput extends GenericObject = TValues, TSchema extends FormSchema<TValues> | TypedSchema<TValues, TOutput> = FormSchema<TValues> | TypedSchema<TValues, TOutput>>(opts?: FormOptions<TValues, TOutput, TSchema>): FormContext<TValues, TOutput>;
1316
+ declare function useForm<TValues extends GenericObject = GenericObject, TOutput extends GenericObject = TValues, TSchema extends FormSchema<TValues> | StandardSchemaV1<TValues, TOutput> = FormSchema<TValues>>(opts?: FormOptions<TValues, TOutput, TSchema>): FormContext<TValues, TOutput>;
1367
1317
  declare function useFormContext<TValues extends GenericObject = GenericObject, TOutput extends GenericObject = TValues>(): FormContext<TValues, TOutput>;
1368
1318
 
1369
1319
  declare function useFieldArray<TValue = unknown>(arrayPath: MaybeRefOrGetter<string>): FieldArrayContext<TValue>;
@@ -1482,4 +1432,4 @@ declare const PublicFormContextKey: InjectionKey<FormContext>;
1482
1432
  declare const FieldContextKey: InjectionKey<PrivateFieldContext<unknown>>;
1483
1433
  declare const IS_ABSENT: unique symbol;
1484
1434
 
1485
- export { type BaseComponentBinds, type BaseFieldProps, type BaseInputBinds, type ComponentBindsConfig, type ComponentFieldBindingObject, type ComponentModelBinds, type ComponentModellessBinds, type DevtoolsPluginFieldState, type DevtoolsPluginFormState, ErrorMessage, Field, FieldArray, type FieldArrayContext, type FieldBindingObject, type FieldContext, FieldContextKey, type FieldEntry, type FieldMeta, type FieldOptions, type FieldPathLookup, type FieldSlotProps, type FieldState, type FieldValidator, type FlattenAndMapPathsValidationResult, type FlattenAndSetPathsType, Form, type FormActions, type FormContext, FormContextKey, type FormErrorBag, type FormErrors, type FormMeta, type FormOptions, type FormSlotProps, type FormState, type FormValidationResult, type GenericObject, type GenericValidateFunction, IS_ABSENT, type InferInput, type InferOutput, type InputBindsConfig, type InputType, type InvalidSubmissionContext, type InvalidSubmissionHandler, type IsAny, type IsEqual, type LazyComponentBindsConfig, type LazyInputBindsConfig, type Locator, type MapValuesPathsToRefs, type MaybeArray, type MaybePromise, type Path, type PathState, type PathStateConfig, type PathValue, type PrivateFieldArrayContext, type PrivateFieldContext, type PrivateFormContext, PublicFormContextKey, type PublicPathState, type RawFormSchema, type ResetFormOpts, type RuleExpression, type SchemaValidationMode, type SubmissionContext, type SubmissionHandler, type TypedSchema, type TypedSchemaContext, type TypedSchemaError, type TypedSchemaPathDescription, type ValidationOptions$1 as ValidationOptions, type ValidationResult, type YupSchema, cleanupNonNestedPath, configure, defineRule, isNotNestedPath, normalizeRules, useField, useFieldArray, useFieldError, useFieldValue, useForm, useFormContext, useFormErrors, useFormValues, useIsFieldDirty, useIsFieldTouched, useIsFieldValid, useIsFormDirty, useIsFormTouched, useIsFormValid, useIsSubmitting, useIsValidating, useResetForm, useSetFieldError, useSetFieldTouched, useSetFieldValue, useSetFormErrors, useSetFormTouched, useSetFormValues, useSubmitCount, useSubmitForm, useValidateField, useValidateForm, validate, validateObjectSchema as validateObject };
1435
+ export { type BaseComponentBinds, type BaseFieldProps, type BaseInputBinds, type ComponentBindsConfig, type ComponentFieldBindingObject, type ComponentModelBinds, type ComponentModellessBinds, type DevtoolsPluginFieldState, type DevtoolsPluginFormState, ErrorMessage, Field, FieldArray, type FieldArrayContext, type FieldBindingObject, type FieldContext, FieldContextKey, type FieldEntry, type FieldMeta, type FieldOptions, type FieldPathLookup, type FieldSlotProps, type FieldState, type FieldValidator, type FlattenAndMapPathsValidationResult, type FlattenAndSetPathsType, Form, type FormActions, type FormContext, FormContextKey, type FormErrorBag, type FormErrors, type FormMeta, type FormOptions, type FormSlotProps, type FormState, type FormValidationResult, type GenericObject, type GenericValidateFunction, IS_ABSENT, type InputBindsConfig, type InputType, type InvalidSubmissionContext, type InvalidSubmissionHandler, type IsAny, type IsEqual, type IssueCollection, type LazyComponentBindsConfig, type LazyInputBindsConfig, type Locator, type MapValuesPathsToRefs, type MaybeArray, type MaybePromise, type Path, type PathState, type PathStateConfig, type PathValue, type PrivateFieldArrayContext, type PrivateFieldContext, type PrivateFormContext, PublicFormContextKey, type PublicPathState, type RawFormSchema, type ResetFormOpts, type RuleExpression, type SchemaValidationMode, type SubmissionContext, type SubmissionHandler, type ValidationOptions$1 as ValidationOptions, type ValidationResult, cleanupNonNestedPath, configure, defineRule, getConfig, isNotNestedPath, normalizeRules, useField, useFieldArray, useFieldError, useFieldValue, useForm, useFormContext, useFormErrors, useFormValues, useIsFieldDirty, useIsFieldTouched, useIsFieldValid, useIsFormDirty, useIsFormTouched, useIsFormValid, useIsSubmitting, useIsValidating, useResetForm, useSetFieldError, useSetFieldTouched, useSetFieldValue, useSetFormErrors, useSetFormTouched, useSetFormValues, useSubmitCount, useSubmitForm, useValidateField, useValidateForm, validate, validateObjectSchema as validateObject };