vee-validate 4.9.5 → 4.10.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/dist/vee-validate.d.ts +30 -23
- package/dist/vee-validate.esm.js +92 -62
- package/dist/vee-validate.js +91 -61
- package/dist/vee-validate.min.js +2 -2
- package/package.json +3 -3
package/dist/vee-validate.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import * as vue from 'vue';
|
|
2
|
-
import { Ref, ComputedRef, VNode, PropType, UnwrapRef, InjectionKey } from 'vue';
|
|
2
|
+
import { MaybeRef, Ref, DeepReadonly, MaybeRefOrGetter, ComputedRef, VNode, PropType, UnwrapRef, InjectionKey } from 'vue';
|
|
3
3
|
import { PartialDeep } from 'type-fest';
|
|
4
4
|
|
|
5
5
|
type BrowserNativeObject = Date | FileList | File;
|
|
@@ -128,8 +128,8 @@ type PathValue<T, P extends Path<T> | ArrayPath<T>> = T extends any ? P extends
|
|
|
128
128
|
type Path<T> = T extends any ? PathInternal<T> : never;
|
|
129
129
|
|
|
130
130
|
type GenericObject = Record<string, any>;
|
|
131
|
-
type
|
|
132
|
-
type
|
|
131
|
+
type MaybeArray<T> = T | T[];
|
|
132
|
+
type MaybePromise<T> = T | Promise<T>;
|
|
133
133
|
type MapValuesPathsToRefs<TValues extends GenericObject, TPaths extends readonly [...MaybeRef<Path<TValues>>[]]> = {
|
|
134
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
135
|
};
|
|
@@ -270,14 +270,14 @@ interface PrivateFieldContext<TValue = unknown> {
|
|
|
270
270
|
handleReset(): void;
|
|
271
271
|
validate: FieldValidator;
|
|
272
272
|
handleChange(e: Event | unknown, shouldValidate?: boolean): void;
|
|
273
|
-
handleBlur(e?: Event): void;
|
|
273
|
+
handleBlur(e?: Event, shouldValidate?: boolean): void;
|
|
274
274
|
setState(state: Partial<FieldState<TValue>>): void;
|
|
275
275
|
setTouched(isTouched: boolean): void;
|
|
276
276
|
setErrors(message: string | string[]): void;
|
|
277
277
|
setValue(value: TValue): void;
|
|
278
278
|
}
|
|
279
279
|
type FieldContext<TValue = unknown> = Omit<PrivateFieldContext<TValue>, 'id' | 'instances'>;
|
|
280
|
-
type GenericValidateFunction<TValue = unknown> = (value: TValue, ctx: FieldValidationMetaInfo) => boolean |
|
|
280
|
+
type GenericValidateFunction<TValue = unknown> = (value: TValue, ctx: FieldValidationMetaInfo) => MaybePromise<boolean | MaybeArray<string>>;
|
|
281
281
|
interface FormState<TValues> {
|
|
282
282
|
values: PartialDeep<TValues>;
|
|
283
283
|
errors: Partial<Record<Path<TValues>, string | undefined>>;
|
|
@@ -286,11 +286,8 @@ interface FormState<TValues> {
|
|
|
286
286
|
}
|
|
287
287
|
type FormErrors<TValues extends GenericObject> = Partial<Record<Path<TValues>, string | undefined>>;
|
|
288
288
|
type FormErrorBag<TValues extends GenericObject> = Partial<Record<Path<TValues>, string[]>>;
|
|
289
|
-
interface SetFieldValueOptions {
|
|
290
|
-
force: boolean;
|
|
291
|
-
}
|
|
292
289
|
interface FormActions<TValues extends GenericObject, TOutput = TValues> {
|
|
293
|
-
setFieldValue<T extends Path<TValues>>(field: T, value: PathValue<TValues, T>,
|
|
290
|
+
setFieldValue<T extends Path<TValues>>(field: T, value: PathValue<TValues, T>, shouldValidate?: boolean): void;
|
|
294
291
|
setFieldError(field: Path<TValues>, message: string | string[] | undefined): void;
|
|
295
292
|
setErrors(fields: FormErrors<TValues>): void;
|
|
296
293
|
setValues(fields: PartialDeep<TValues>): void;
|
|
@@ -351,9 +348,7 @@ interface PrivateFormContext<TValues extends GenericObject = GenericObject, TOut
|
|
|
351
348
|
unsetPathValue<TPath extends Path<TValues>>(path: TPath): void;
|
|
352
349
|
markForUnmount(path: string): void;
|
|
353
350
|
}
|
|
354
|
-
interface BaseComponentBinds<TValue = unknown> {
|
|
355
|
-
modelValue: TValue | undefined;
|
|
356
|
-
'onUpdate:modelValue': (value: TValue) => void;
|
|
351
|
+
interface BaseComponentBinds<TValue = unknown, TModel = 'modelValue'> {
|
|
357
352
|
onBlur: () => void;
|
|
358
353
|
}
|
|
359
354
|
type PublicPathState<TValue = unknown> = Omit<PathState<TValue>, 'bails' | 'label' | 'multiple' | 'fieldsCount' | 'validate' | 'id' | 'type' | '__flags'>;
|
|
@@ -361,11 +356,13 @@ interface ComponentBindsConfig<TValue = unknown, TExtraProps extends GenericObje
|
|
|
361
356
|
mapProps: (state: PublicPathState<TValue>) => TExtraProps;
|
|
362
357
|
validateOnBlur: boolean;
|
|
363
358
|
validateOnModelUpdate: boolean;
|
|
359
|
+
model: string;
|
|
364
360
|
}
|
|
365
361
|
type LazyComponentBindsConfig<TValue = unknown, TExtraProps extends GenericObject = GenericObject> = (state: PublicPathState<TValue>) => Partial<{
|
|
366
362
|
props: TExtraProps;
|
|
367
363
|
validateOnBlur: boolean;
|
|
368
364
|
validateOnModelUpdate: boolean;
|
|
365
|
+
model: string;
|
|
369
366
|
}>;
|
|
370
367
|
interface BaseInputBinds<TValue = unknown> {
|
|
371
368
|
value: TValue | undefined;
|
|
@@ -385,11 +382,12 @@ type LazyInputBindsConfig<TValue = unknown, TExtraProps extends GenericObject =
|
|
|
385
382
|
validateOnChange: boolean;
|
|
386
383
|
validateOnInput: boolean;
|
|
387
384
|
}>;
|
|
388
|
-
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' | 'markForUnmount' | 'keepValuesOnUnmount'> {
|
|
385
|
+
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' | 'markForUnmount' | 'keepValuesOnUnmount' | 'values'> {
|
|
386
|
+
values: DeepReadonly<TValues>;
|
|
389
387
|
handleReset: () => void;
|
|
390
388
|
submitForm: (e?: unknown) => Promise<void>;
|
|
391
|
-
defineComponentBinds<TPath extends Path<TValues>, TValue = PathValue<TValues, TPath>, TExtras extends GenericObject = GenericObject>(path:
|
|
392
|
-
defineInputBinds<TPath extends Path<TValues>, TValue = PathValue<TValues, TPath>, TExtras extends GenericObject = GenericObject>(path:
|
|
389
|
+
defineComponentBinds<TPath extends Path<TValues>, TValue = PathValue<TValues, TPath>, TExtras extends GenericObject = GenericObject>(path: MaybeRefOrGetter<TPath>, config?: Partial<ComponentBindsConfig<TValue, TExtras>> | LazyComponentBindsConfig<TValue, TExtras>): Ref<BaseComponentBinds<TValue> & TExtras>;
|
|
390
|
+
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>;
|
|
393
391
|
}
|
|
394
392
|
|
|
395
393
|
interface ValidationOptions {
|
|
@@ -431,28 +429,37 @@ interface FieldOptions<TValue = unknown> {
|
|
|
431
429
|
validateOnMount?: boolean;
|
|
432
430
|
bails?: boolean;
|
|
433
431
|
type?: InputType;
|
|
432
|
+
/**
|
|
433
|
+
* @deprecated Use `checkedValue` instead.
|
|
434
|
+
*/
|
|
434
435
|
valueProp?: MaybeRef<TValue>;
|
|
435
436
|
checkedValue?: MaybeRef<TValue>;
|
|
436
437
|
uncheckedValue?: MaybeRef<TValue>;
|
|
437
438
|
label?: MaybeRef<string | undefined>;
|
|
438
439
|
controlled?: boolean;
|
|
440
|
+
/**
|
|
441
|
+
* @deprecated Use `controlled` instead, controlled is opposite of standalone.
|
|
442
|
+
*/
|
|
439
443
|
standalone?: boolean;
|
|
440
444
|
keepValueOnUnmount?: MaybeRef<boolean | undefined>;
|
|
445
|
+
/**
|
|
446
|
+
* @deprecated Pass the model prop name to `syncVModel` instead.
|
|
447
|
+
*/
|
|
441
448
|
modelPropName?: string;
|
|
442
|
-
syncVModel?: boolean;
|
|
449
|
+
syncVModel?: boolean | string;
|
|
443
450
|
form?: FormContext;
|
|
444
451
|
}
|
|
445
452
|
type RuleExpression<TValue> = string | Record<string, unknown> | GenericValidateFunction<TValue> | GenericValidateFunction<TValue>[] | TypedSchema<TValue> | YupSchema<TValue> | undefined;
|
|
446
453
|
/**
|
|
447
454
|
* Creates a field composite.
|
|
448
455
|
*/
|
|
449
|
-
declare function useField<TValue = unknown>(path:
|
|
456
|
+
declare function useField<TValue = unknown>(path: MaybeRefOrGetter<string>, rules?: MaybeRef<RuleExpression<TValue>>, opts?: Partial<FieldOptions<TValue>>): FieldContext<TValue>;
|
|
450
457
|
|
|
451
458
|
interface SharedBindingObject<TValue = any> {
|
|
452
459
|
name: string;
|
|
453
460
|
onBlur: (e: Event) => void;
|
|
454
|
-
onInput: (e: Event) => void;
|
|
455
|
-
onChange: (e: Event) => void;
|
|
461
|
+
onInput: (e: Event | unknown) => void;
|
|
462
|
+
onChange: (e: Event | unknown) => void;
|
|
456
463
|
'onUpdate:modelValue'?: ((e: TValue) => unknown) | undefined;
|
|
457
464
|
}
|
|
458
465
|
interface FieldBindingObject<TValue = any> extends SharedBindingObject<TValue> {
|
|
@@ -480,11 +487,11 @@ declare const Field: {
|
|
|
480
487
|
as?: string | Record<string, any>;
|
|
481
488
|
bails?: boolean;
|
|
482
489
|
uncheckedValue?: any;
|
|
490
|
+
modelValue?: any;
|
|
483
491
|
validateOnInput?: boolean;
|
|
484
492
|
validateOnChange?: boolean;
|
|
485
493
|
validateOnBlur?: boolean;
|
|
486
494
|
validateOnModelUpdate?: boolean;
|
|
487
|
-
modelValue?: any;
|
|
488
495
|
validateOnMount?: boolean;
|
|
489
496
|
standalone?: boolean;
|
|
490
497
|
modelModifiers?: any;
|
|
@@ -628,11 +635,11 @@ declare const Field: {
|
|
|
628
635
|
as: string | Record<string, any>;
|
|
629
636
|
bails: boolean;
|
|
630
637
|
uncheckedValue: any;
|
|
638
|
+
modelValue: any;
|
|
631
639
|
validateOnInput: boolean;
|
|
632
640
|
validateOnChange: boolean;
|
|
633
641
|
validateOnBlur: boolean;
|
|
634
642
|
validateOnModelUpdate: boolean;
|
|
635
|
-
modelValue: any;
|
|
636
643
|
validateOnMount: boolean;
|
|
637
644
|
standalone: boolean;
|
|
638
645
|
modelModifiers: any;
|
|
@@ -814,11 +821,11 @@ declare const Field: {
|
|
|
814
821
|
as: string | Record<string, any>;
|
|
815
822
|
bails: boolean;
|
|
816
823
|
uncheckedValue: any;
|
|
824
|
+
modelValue: any;
|
|
817
825
|
validateOnInput: boolean;
|
|
818
826
|
validateOnChange: boolean;
|
|
819
827
|
validateOnBlur: boolean;
|
|
820
828
|
validateOnModelUpdate: boolean;
|
|
821
|
-
modelValue: any;
|
|
822
829
|
validateOnMount: boolean;
|
|
823
830
|
standalone: boolean;
|
|
824
831
|
modelModifiers: any;
|
|
@@ -1479,7 +1486,7 @@ declare function useFieldValue<TValue = unknown>(path?: MaybeRef<string>): vue.C
|
|
|
1479
1486
|
/**
|
|
1480
1487
|
* Gives access to a form's values
|
|
1481
1488
|
*/
|
|
1482
|
-
declare function useFormValues<TValues extends Record<string, any> = Record<string, any>>(): vue.ComputedRef<Partial<TValues>>;
|
|
1489
|
+
declare function useFormValues<TValues extends Record<string, any> = Record<string, any>>(): vue.ComputedRef<vue.DeepReadonly<TValues> | Partial<TValues>>;
|
|
1483
1490
|
|
|
1484
1491
|
/**
|
|
1485
1492
|
* Gives access to all form errors
|
package/dist/vee-validate.esm.js
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* vee-validate v4.
|
|
2
|
+
* vee-validate v4.10.0
|
|
3
3
|
* (c) 2023 Abdelrahman Awad
|
|
4
4
|
* @license MIT
|
|
5
5
|
*/
|
|
6
|
-
import { getCurrentInstance, inject, warn as warn$1,
|
|
6
|
+
import { getCurrentInstance, inject, warn as warn$1, computed, toValue, unref, ref, watch, isRef, reactive, onUnmounted, nextTick, onMounted, provide, onBeforeUnmount, defineComponent, toRef, resolveDynamicComponent, h, readonly, watchEffect, shallowRef } from 'vue';
|
|
7
7
|
import { setupDevtoolsPlugin } from '@vue/devtools-api';
|
|
8
8
|
|
|
9
9
|
function isCallable(fn) {
|
|
@@ -20,9 +20,32 @@ function toNumber(value) {
|
|
|
20
20
|
const n = parseFloat(value);
|
|
21
21
|
return isNaN(n) ? value : n;
|
|
22
22
|
}
|
|
23
|
+
function isObjectLike(value) {
|
|
24
|
+
return typeof value === 'object' && value !== null;
|
|
25
|
+
}
|
|
26
|
+
function getTag(value) {
|
|
27
|
+
if (value == null) {
|
|
28
|
+
return value === undefined ? '[object Undefined]' : '[object Null]';
|
|
29
|
+
}
|
|
30
|
+
return Object.prototype.toString.call(value);
|
|
31
|
+
}
|
|
32
|
+
// Reference: https://github.com/lodash/lodash/blob/master/isPlainObject.js
|
|
33
|
+
function isPlainObject(value) {
|
|
34
|
+
if (!isObjectLike(value) || getTag(value) !== '[object Object]') {
|
|
35
|
+
return false;
|
|
36
|
+
}
|
|
37
|
+
if (Object.getPrototypeOf(value) === null) {
|
|
38
|
+
return true;
|
|
39
|
+
}
|
|
40
|
+
let proto = value;
|
|
41
|
+
while (Object.getPrototypeOf(proto) !== null) {
|
|
42
|
+
proto = Object.getPrototypeOf(proto);
|
|
43
|
+
}
|
|
44
|
+
return Object.getPrototypeOf(value) === proto;
|
|
45
|
+
}
|
|
23
46
|
function merge(target, source) {
|
|
24
47
|
Object.keys(source).forEach(key => {
|
|
25
|
-
if (
|
|
48
|
+
if (isPlainObject(source[key])) {
|
|
26
49
|
if (!target[key]) {
|
|
27
50
|
target[key] = {};
|
|
28
51
|
}
|
|
@@ -492,14 +515,8 @@ function computedDeep({ get, set }) {
|
|
|
492
515
|
});
|
|
493
516
|
return baseRef;
|
|
494
517
|
}
|
|
495
|
-
function unravel(value) {
|
|
496
|
-
if (isCallable(value)) {
|
|
497
|
-
return value();
|
|
498
|
-
}
|
|
499
|
-
return unref(value);
|
|
500
|
-
}
|
|
501
518
|
function lazyToRef(value) {
|
|
502
|
-
return computed(() =>
|
|
519
|
+
return computed(() => toValue(value));
|
|
503
520
|
}
|
|
504
521
|
function normalizeErrorItem(message) {
|
|
505
522
|
return Array.isArray(message) ? message : message ? [message] : [];
|
|
@@ -553,6 +570,12 @@ function hasValueBinding(el) {
|
|
|
553
570
|
return '_value' in el;
|
|
554
571
|
}
|
|
555
572
|
|
|
573
|
+
function parseInputValue(el) {
|
|
574
|
+
if (el.type === 'number') {
|
|
575
|
+
return el.valueAsNumber;
|
|
576
|
+
}
|
|
577
|
+
return el.value;
|
|
578
|
+
}
|
|
556
579
|
function normalizeEventValue(value) {
|
|
557
580
|
if (!isEvent(value)) {
|
|
558
581
|
return value;
|
|
@@ -578,7 +601,7 @@ function normalizeEventValue(value) {
|
|
|
578
601
|
const selectedOption = Array.from(input.options).find(opt => opt.selected);
|
|
579
602
|
return selectedOption ? getBoundValue(selectedOption) : input.value;
|
|
580
603
|
}
|
|
581
|
-
return input
|
|
604
|
+
return parseInputValue(input);
|
|
582
605
|
}
|
|
583
606
|
|
|
584
607
|
/**
|
|
@@ -741,12 +764,17 @@ async function _validate(field, value) {
|
|
|
741
764
|
for (let i = 0; i < length; i++) {
|
|
742
765
|
const rule = pipeline[i];
|
|
743
766
|
const result = await rule(value, ctx);
|
|
744
|
-
const isValid = typeof result !== 'string' && result;
|
|
767
|
+
const isValid = typeof result !== 'string' && !Array.isArray(result) && result;
|
|
745
768
|
if (isValid) {
|
|
746
769
|
continue;
|
|
747
770
|
}
|
|
748
|
-
|
|
749
|
-
|
|
771
|
+
if (Array.isArray(result)) {
|
|
772
|
+
errors.push(...result);
|
|
773
|
+
}
|
|
774
|
+
else {
|
|
775
|
+
const message = typeof result === 'string' ? result : _generateFieldError(ctx);
|
|
776
|
+
errors.push(message);
|
|
777
|
+
}
|
|
750
778
|
if (field.bails) {
|
|
751
779
|
return {
|
|
752
780
|
errors,
|
|
@@ -1501,7 +1529,7 @@ function useField(path, rules, opts) {
|
|
|
1501
1529
|
return _useField(path, rules, opts);
|
|
1502
1530
|
}
|
|
1503
1531
|
function _useField(path, rules, opts) {
|
|
1504
|
-
const { initialValue: modelValue, validateOnMount, bails, type, checkedValue, label, validateOnValueUpdate, uncheckedValue, controlled, keepValueOnUnmount,
|
|
1532
|
+
const { initialValue: modelValue, validateOnMount, bails, type, checkedValue, label, validateOnValueUpdate, uncheckedValue, controlled, keepValueOnUnmount, syncVModel, form: controlForm, } = normalizeOptions(opts);
|
|
1505
1533
|
const injectedForm = controlled ? injectWithSelf(FormContextKey) : undefined;
|
|
1506
1534
|
const form = controlForm || injectedForm;
|
|
1507
1535
|
const name = lazyToRef(path);
|
|
@@ -1529,13 +1557,16 @@ function _useField(path, rules, opts) {
|
|
|
1529
1557
|
});
|
|
1530
1558
|
const errorMessage = computed(() => errors.value[0]);
|
|
1531
1559
|
if (syncVModel) {
|
|
1532
|
-
useVModel({ value, prop:
|
|
1560
|
+
useVModel({ value, prop: syncVModel, handleChange });
|
|
1533
1561
|
}
|
|
1534
1562
|
/**
|
|
1535
1563
|
* Handles common onBlur meta update
|
|
1536
1564
|
*/
|
|
1537
|
-
const handleBlur = () => {
|
|
1565
|
+
const handleBlur = (evt, shouldValidate = false) => {
|
|
1538
1566
|
meta.touched = true;
|
|
1567
|
+
if (shouldValidate) {
|
|
1568
|
+
validateWithStateMutation();
|
|
1569
|
+
}
|
|
1539
1570
|
};
|
|
1540
1571
|
async function validateCurrentValue(mode) {
|
|
1541
1572
|
var _a, _b;
|
|
@@ -1611,10 +1642,6 @@ function _useField(path, rules, opts) {
|
|
|
1611
1642
|
}
|
|
1612
1643
|
function setValue(newValue, shouldValidate = true) {
|
|
1613
1644
|
value.value = newValue;
|
|
1614
|
-
if (!shouldValidate) {
|
|
1615
|
-
validateValidStateOnly();
|
|
1616
|
-
return;
|
|
1617
|
-
}
|
|
1618
1645
|
const validateFn = shouldValidate ? validateWithStateMutation : validateValidStateOnly;
|
|
1619
1646
|
validateFn();
|
|
1620
1647
|
}
|
|
@@ -1726,7 +1753,7 @@ function _useField(path, rules, opts) {
|
|
|
1726
1753
|
onBeforeUnmount(() => {
|
|
1727
1754
|
var _a;
|
|
1728
1755
|
const shouldKeepValue = (_a = unref(field.keepValueOnUnmount)) !== null && _a !== void 0 ? _a : unref(form.keepValuesOnUnmount);
|
|
1729
|
-
const path =
|
|
1756
|
+
const path = toValue(name);
|
|
1730
1757
|
if (shouldKeepValue || !form || flags.pendingUnmount[field.id]) {
|
|
1731
1758
|
form === null || form === void 0 ? void 0 : form.removePathState(path, id);
|
|
1732
1759
|
return;
|
|
@@ -1751,7 +1778,7 @@ function _useField(path, rules, opts) {
|
|
|
1751
1778
|
}
|
|
1752
1779
|
}
|
|
1753
1780
|
else {
|
|
1754
|
-
form.unsetPathValue(
|
|
1781
|
+
form.unsetPathValue(toValue(name));
|
|
1755
1782
|
}
|
|
1756
1783
|
form.removePathState(path, id);
|
|
1757
1784
|
});
|
|
@@ -1761,7 +1788,6 @@ function _useField(path, rules, opts) {
|
|
|
1761
1788
|
* Normalizes partial field options to include the full options
|
|
1762
1789
|
*/
|
|
1763
1790
|
function normalizeOptions(opts) {
|
|
1764
|
-
var _a;
|
|
1765
1791
|
const defaults = () => ({
|
|
1766
1792
|
initialValue: undefined,
|
|
1767
1793
|
validateOnMount: false,
|
|
@@ -1769,13 +1795,13 @@ function normalizeOptions(opts) {
|
|
|
1769
1795
|
label: undefined,
|
|
1770
1796
|
validateOnValueUpdate: true,
|
|
1771
1797
|
keepValueOnUnmount: undefined,
|
|
1772
|
-
|
|
1773
|
-
syncVModel: true,
|
|
1798
|
+
syncVModel: false,
|
|
1774
1799
|
controlled: true,
|
|
1775
1800
|
});
|
|
1776
|
-
const isVModelSynced = (
|
|
1801
|
+
const isVModelSynced = !!(opts === null || opts === void 0 ? void 0 : opts.syncVModel);
|
|
1802
|
+
const modelPropName = typeof (opts === null || opts === void 0 ? void 0 : opts.syncVModel) === 'string' ? opts.syncVModel : (opts === null || opts === void 0 ? void 0 : opts.modelPropName) || 'modelValue';
|
|
1777
1803
|
const initialValue = isVModelSynced && !('initialValue' in (opts || {}))
|
|
1778
|
-
? getCurrentModelValue(getCurrentInstance(),
|
|
1804
|
+
? getCurrentModelValue(getCurrentInstance(), modelPropName)
|
|
1779
1805
|
: opts === null || opts === void 0 ? void 0 : opts.initialValue;
|
|
1780
1806
|
if (!opts) {
|
|
1781
1807
|
return Object.assign(Object.assign({}, defaults()), { initialValue });
|
|
@@ -1783,7 +1809,9 @@ function normalizeOptions(opts) {
|
|
|
1783
1809
|
// TODO: Deprecate this in next major release
|
|
1784
1810
|
const checkedValue = 'valueProp' in opts ? opts.valueProp : opts.checkedValue;
|
|
1785
1811
|
const controlled = 'standalone' in opts ? !opts.standalone : opts.controlled;
|
|
1786
|
-
|
|
1812
|
+
const syncVModel = (opts === null || opts === void 0 ? void 0 : opts.modelPropName) || (opts === null || opts === void 0 ? void 0 : opts.syncVModel) || false;
|
|
1813
|
+
return Object.assign(Object.assign(Object.assign({}, defaults()), (opts || {})), { initialValue, controlled: controlled !== null && controlled !== void 0 ? controlled : true, checkedValue,
|
|
1814
|
+
syncVModel });
|
|
1787
1815
|
}
|
|
1788
1816
|
function useFieldWithChecked(name, rules, opts) {
|
|
1789
1817
|
const form = !(opts === null || opts === void 0 ? void 0 : opts.standalone) ? injectWithSelf(FormContextKey) : undefined;
|
|
@@ -1799,23 +1827,22 @@ function useFieldWithChecked(name, rules, opts) {
|
|
|
1799
1827
|
: isEqual(checkedVal, currentValue);
|
|
1800
1828
|
});
|
|
1801
1829
|
function handleCheckboxChange(e, shouldValidate = true) {
|
|
1802
|
-
var _a;
|
|
1830
|
+
var _a, _b;
|
|
1803
1831
|
if (checked.value === ((_a = e === null || e === void 0 ? void 0 : e.target) === null || _a === void 0 ? void 0 : _a.checked)) {
|
|
1804
1832
|
if (shouldValidate) {
|
|
1805
1833
|
field.validate();
|
|
1806
1834
|
}
|
|
1807
1835
|
return;
|
|
1808
1836
|
}
|
|
1809
|
-
const path =
|
|
1837
|
+
const path = toValue(name);
|
|
1810
1838
|
const pathState = form === null || form === void 0 ? void 0 : form.getPathState(path);
|
|
1811
1839
|
const value = normalizeEventValue(e);
|
|
1812
|
-
let newValue;
|
|
1840
|
+
let newValue = (_b = unref(checkedValue)) !== null && _b !== void 0 ? _b : value;
|
|
1813
1841
|
if (form && (pathState === null || pathState === void 0 ? void 0 : pathState.multiple) && pathState.type === 'checkbox') {
|
|
1814
|
-
newValue = resolveNextCheckboxValue(getFromPath(form.values, path) || [],
|
|
1842
|
+
newValue = resolveNextCheckboxValue(getFromPath(form.values, path) || [], newValue, undefined);
|
|
1815
1843
|
}
|
|
1816
|
-
else {
|
|
1817
|
-
|
|
1818
|
-
newValue = resolveNextCheckboxValue(unref(field.value), unref(checkedValue), unref(uncheckedValue));
|
|
1844
|
+
else if ((opts === null || opts === void 0 ? void 0 : opts.type) === 'checkbox') {
|
|
1845
|
+
newValue = resolveNextCheckboxValue(unref(field.value), newValue, unref(uncheckedValue));
|
|
1819
1846
|
}
|
|
1820
1847
|
handleChange(newValue, shouldValidate);
|
|
1821
1848
|
}
|
|
@@ -1828,13 +1855,13 @@ function useFieldWithChecked(name, rules, opts) {
|
|
|
1828
1855
|
function useVModel({ prop, value, handleChange }) {
|
|
1829
1856
|
const vm = getCurrentInstance();
|
|
1830
1857
|
/* istanbul ignore next */
|
|
1831
|
-
if (!vm) {
|
|
1858
|
+
if (!vm || !prop) {
|
|
1832
1859
|
if ((process.env.NODE_ENV !== 'production')) {
|
|
1833
1860
|
console.warn('Failed to setup model events because `useField` was not called in setup.');
|
|
1834
1861
|
}
|
|
1835
1862
|
return;
|
|
1836
1863
|
}
|
|
1837
|
-
const propName = prop
|
|
1864
|
+
const propName = typeof prop === 'string' ? prop : 'modelValue';
|
|
1838
1865
|
const emitName = `update:${propName}`;
|
|
1839
1866
|
// Component doesn't have a model prop setup (must be defined on the props)
|
|
1840
1867
|
if (!(propName in vm.props)) {
|
|
@@ -1951,6 +1978,7 @@ const FieldImpl = /** #__PURE__ */ defineComponent({
|
|
|
1951
1978
|
label,
|
|
1952
1979
|
validateOnValueUpdate: false,
|
|
1953
1980
|
keepValueOnUnmount: keepValue,
|
|
1981
|
+
syncVModel: true,
|
|
1954
1982
|
});
|
|
1955
1983
|
// If there is a v-model applied on the component we need to emit the `update:modelValue` whenever the value binding changes
|
|
1956
1984
|
const onChangeHandler = function handleChangeWithModel(e, shouldValidate = true) {
|
|
@@ -1960,13 +1988,10 @@ const FieldImpl = /** #__PURE__ */ defineComponent({
|
|
|
1960
1988
|
const sharedProps = computed(() => {
|
|
1961
1989
|
const { validateOnInput, validateOnChange, validateOnBlur, validateOnModelUpdate } = resolveValidationTriggers(props);
|
|
1962
1990
|
function baseOnBlur(e) {
|
|
1963
|
-
handleBlur(e);
|
|
1991
|
+
handleBlur(e, validateOnBlur);
|
|
1964
1992
|
if (isCallable(ctx.attrs.onBlur)) {
|
|
1965
1993
|
ctx.attrs.onBlur(e);
|
|
1966
1994
|
}
|
|
1967
|
-
if (validateOnBlur) {
|
|
1968
|
-
validateField();
|
|
1969
|
-
}
|
|
1970
1995
|
}
|
|
1971
1996
|
function baseOnInput(e) {
|
|
1972
1997
|
onChangeHandler(e, validateOnInput);
|
|
@@ -2016,7 +2041,7 @@ const FieldImpl = /** #__PURE__ */ defineComponent({
|
|
|
2016
2041
|
handleChange: onChangeHandler,
|
|
2017
2042
|
handleInput: e => onChangeHandler(e, false),
|
|
2018
2043
|
handleReset,
|
|
2019
|
-
handleBlur,
|
|
2044
|
+
handleBlur: sharedProps.value.onBlur,
|
|
2020
2045
|
setTouched,
|
|
2021
2046
|
setErrors,
|
|
2022
2047
|
};
|
|
@@ -2170,7 +2195,7 @@ function useForm(opts) {
|
|
|
2170
2195
|
const schema = opts === null || opts === void 0 ? void 0 : opts.validationSchema;
|
|
2171
2196
|
function createPathState(path, config) {
|
|
2172
2197
|
var _a, _b;
|
|
2173
|
-
const initialValue = computed(() => getFromPath(initialValues.value,
|
|
2198
|
+
const initialValue = computed(() => getFromPath(initialValues.value, toValue(path)));
|
|
2174
2199
|
const pathStateExists = pathStates.value.find(state => state.path === unref(path));
|
|
2175
2200
|
if (pathStateExists) {
|
|
2176
2201
|
if ((config === null || config === void 0 ? void 0 : config.type) === 'checkbox' || (config === null || config === void 0 ? void 0 : config.type) === 'radio') {
|
|
@@ -2187,8 +2212,8 @@ function useForm(opts) {
|
|
|
2187
2212
|
pathStateExists.__flags.pendingUnmount[id] = false;
|
|
2188
2213
|
return pathStateExists;
|
|
2189
2214
|
}
|
|
2190
|
-
const currentValue = computed(() => getFromPath(formValues,
|
|
2191
|
-
const pathValue =
|
|
2215
|
+
const currentValue = computed(() => getFromPath(formValues, toValue(path)));
|
|
2216
|
+
const pathValue = toValue(path);
|
|
2192
2217
|
const id = FIELD_ID_COUNTER++;
|
|
2193
2218
|
const state = reactive({
|
|
2194
2219
|
id,
|
|
@@ -2440,7 +2465,7 @@ function useForm(opts) {
|
|
|
2440
2465
|
/**
|
|
2441
2466
|
* Sets a single field value
|
|
2442
2467
|
*/
|
|
2443
|
-
function setFieldValue(field, value) {
|
|
2468
|
+
function setFieldValue(field, value, shouldValidate = true) {
|
|
2444
2469
|
const clonedValue = klona(value);
|
|
2445
2470
|
const path = typeof field === 'string' ? field : field.path;
|
|
2446
2471
|
const pathState = findPathState(path);
|
|
@@ -2448,6 +2473,9 @@ function useForm(opts) {
|
|
|
2448
2473
|
createPathState(path);
|
|
2449
2474
|
}
|
|
2450
2475
|
setInPath(formValues, path, clonedValue);
|
|
2476
|
+
if (shouldValidate) {
|
|
2477
|
+
validateField(path);
|
|
2478
|
+
}
|
|
2451
2479
|
}
|
|
2452
2480
|
/**
|
|
2453
2481
|
* Sets multiple fields values
|
|
@@ -2465,7 +2493,7 @@ function useForm(opts) {
|
|
|
2465
2493
|
},
|
|
2466
2494
|
set(value) {
|
|
2467
2495
|
const pathValue = unref(path);
|
|
2468
|
-
setFieldValue(pathValue, value);
|
|
2496
|
+
setFieldValue(pathValue, value, false);
|
|
2469
2497
|
pathState.validated = true;
|
|
2470
2498
|
pathState.pending = true;
|
|
2471
2499
|
validateField(pathValue).then(() => {
|
|
@@ -2501,7 +2529,7 @@ function useForm(opts) {
|
|
|
2501
2529
|
var _a;
|
|
2502
2530
|
const newValue = state && 'value' in state ? state.value : getFromPath(initialValues.value, field);
|
|
2503
2531
|
setFieldInitialValue(field, klona(newValue));
|
|
2504
|
-
setFieldValue(field, newValue);
|
|
2532
|
+
setFieldValue(field, newValue, false);
|
|
2505
2533
|
setFieldTouched(field, (_a = state === null || state === void 0 ? void 0 : state.touched) !== null && _a !== void 0 ? _a : false);
|
|
2506
2534
|
setFieldError(field, (state === null || state === void 0 ? void 0 : state.errors) || []);
|
|
2507
2535
|
}
|
|
@@ -2516,7 +2544,7 @@ function useForm(opts) {
|
|
|
2516
2544
|
var _a;
|
|
2517
2545
|
state.validated = false;
|
|
2518
2546
|
state.touched = ((_a = resetState === null || resetState === void 0 ? void 0 : resetState.touched) === null || _a === void 0 ? void 0 : _a[state.path]) || false;
|
|
2519
|
-
setFieldValue(state.path, getFromPath(newValues, state.path));
|
|
2547
|
+
setFieldValue(state.path, getFromPath(newValues, state.path), false);
|
|
2520
2548
|
setFieldError(state.path, undefined);
|
|
2521
2549
|
});
|
|
2522
2550
|
setErrors((resetState === null || resetState === void 0 ? void 0 : resetState.errors) || {});
|
|
@@ -2656,7 +2684,7 @@ function useForm(opts) {
|
|
|
2656
2684
|
});
|
|
2657
2685
|
}
|
|
2658
2686
|
function defineComponentBinds(path, config) {
|
|
2659
|
-
const pathState = findPathState(
|
|
2687
|
+
const pathState = findPathState(toValue(path)) || createPathState(path);
|
|
2660
2688
|
const evalConfig = () => (isCallable(config) ? config(omit(pathState, PRIVATE_PATH_STATE_KEYS)) : config || {});
|
|
2661
2689
|
function onBlur() {
|
|
2662
2690
|
var _a;
|
|
@@ -2675,23 +2703,25 @@ function useForm(opts) {
|
|
|
2675
2703
|
}
|
|
2676
2704
|
}
|
|
2677
2705
|
const props = computed(() => {
|
|
2678
|
-
const base = {
|
|
2679
|
-
modelValue: pathState.value,
|
|
2680
|
-
'onUpdate:modelValue': onUpdateModelValue,
|
|
2681
|
-
onBlur,
|
|
2682
|
-
};
|
|
2683
2706
|
if (isCallable(config)) {
|
|
2684
|
-
|
|
2707
|
+
const configVal = config(pathState);
|
|
2708
|
+
const model = configVal.model || 'modelValue';
|
|
2709
|
+
return Object.assign({ onBlur, [model]: pathState.value, [`onUpdate:${model}`]: onUpdateModelValue }, (configVal.props || {}));
|
|
2685
2710
|
}
|
|
2711
|
+
const model = (config === null || config === void 0 ? void 0 : config.model) || 'modelValue';
|
|
2712
|
+
const base = {
|
|
2713
|
+
[model]: pathState.value,
|
|
2714
|
+
[`onUpdate:${model}`]: onUpdateModelValue,
|
|
2715
|
+
};
|
|
2686
2716
|
if (config === null || config === void 0 ? void 0 : config.mapProps) {
|
|
2687
|
-
return Object.assign(Object.assign({}, base), config.mapProps(omit(pathState, PRIVATE_PATH_STATE_KEYS)));
|
|
2717
|
+
return Object.assign(Object.assign({ onBlur }, base), config.mapProps(omit(pathState, PRIVATE_PATH_STATE_KEYS)));
|
|
2688
2718
|
}
|
|
2689
2719
|
return base;
|
|
2690
2720
|
});
|
|
2691
2721
|
return props;
|
|
2692
2722
|
}
|
|
2693
2723
|
function defineInputBinds(path, config) {
|
|
2694
|
-
const pathState = (findPathState(
|
|
2724
|
+
const pathState = (findPathState(toValue(path)) || createPathState(path));
|
|
2695
2725
|
const evalConfig = () => (isCallable(config) ? config(omit(pathState, PRIVATE_PATH_STATE_KEYS)) : config || {});
|
|
2696
2726
|
function onBlur() {
|
|
2697
2727
|
var _a;
|
|
@@ -2736,7 +2766,7 @@ function useForm(opts) {
|
|
|
2736
2766
|
});
|
|
2737
2767
|
return props;
|
|
2738
2768
|
}
|
|
2739
|
-
return Object.assign(Object.assign({}, formCtx), { handleReset: () => resetForm(), submitForm,
|
|
2769
|
+
return Object.assign(Object.assign({}, formCtx), { values: readonly(formValues), handleReset: () => resetForm(), submitForm,
|
|
2740
2770
|
defineComponentBinds,
|
|
2741
2771
|
defineInputBinds });
|
|
2742
2772
|
}
|
|
@@ -2786,8 +2816,8 @@ function useFormInitialValues(pathsState, formValues, opts) {
|
|
|
2786
2816
|
// these only change when the user explicitly changes the initial values or when the user resets them with new values.
|
|
2787
2817
|
const originalInitialValues = ref(klona(values));
|
|
2788
2818
|
function setInitialValues(values, updateFields = false) {
|
|
2789
|
-
initialValues.value = klona(values);
|
|
2790
|
-
originalInitialValues.value = klona(values);
|
|
2819
|
+
initialValues.value = merge(klona(initialValues.value) || {}, klona(values));
|
|
2820
|
+
originalInitialValues.value = merge(klona(originalInitialValues.value) || {}, klona(values));
|
|
2791
2821
|
if (!updateFields) {
|
|
2792
2822
|
return;
|
|
2793
2823
|
}
|
package/dist/vee-validate.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* vee-validate v4.
|
|
2
|
+
* vee-validate v4.10.0
|
|
3
3
|
* (c) 2023 Abdelrahman Awad
|
|
4
4
|
* @license MIT
|
|
5
5
|
*/
|
|
@@ -23,9 +23,32 @@
|
|
|
23
23
|
const n = parseFloat(value);
|
|
24
24
|
return isNaN(n) ? value : n;
|
|
25
25
|
}
|
|
26
|
+
function isObjectLike(value) {
|
|
27
|
+
return typeof value === 'object' && value !== null;
|
|
28
|
+
}
|
|
29
|
+
function getTag(value) {
|
|
30
|
+
if (value == null) {
|
|
31
|
+
return value === undefined ? '[object Undefined]' : '[object Null]';
|
|
32
|
+
}
|
|
33
|
+
return Object.prototype.toString.call(value);
|
|
34
|
+
}
|
|
35
|
+
// Reference: https://github.com/lodash/lodash/blob/master/isPlainObject.js
|
|
36
|
+
function isPlainObject(value) {
|
|
37
|
+
if (!isObjectLike(value) || getTag(value) !== '[object Object]') {
|
|
38
|
+
return false;
|
|
39
|
+
}
|
|
40
|
+
if (Object.getPrototypeOf(value) === null) {
|
|
41
|
+
return true;
|
|
42
|
+
}
|
|
43
|
+
let proto = value;
|
|
44
|
+
while (Object.getPrototypeOf(proto) !== null) {
|
|
45
|
+
proto = Object.getPrototypeOf(proto);
|
|
46
|
+
}
|
|
47
|
+
return Object.getPrototypeOf(value) === proto;
|
|
48
|
+
}
|
|
26
49
|
function merge(target, source) {
|
|
27
50
|
Object.keys(source).forEach(key => {
|
|
28
|
-
if (
|
|
51
|
+
if (isPlainObject(source[key])) {
|
|
29
52
|
if (!target[key]) {
|
|
30
53
|
target[key] = {};
|
|
31
54
|
}
|
|
@@ -477,14 +500,8 @@
|
|
|
477
500
|
});
|
|
478
501
|
return baseRef;
|
|
479
502
|
}
|
|
480
|
-
function unravel(value) {
|
|
481
|
-
if (isCallable(value)) {
|
|
482
|
-
return value();
|
|
483
|
-
}
|
|
484
|
-
return vue.unref(value);
|
|
485
|
-
}
|
|
486
503
|
function lazyToRef(value) {
|
|
487
|
-
return vue.computed(() =>
|
|
504
|
+
return vue.computed(() => vue.toValue(value));
|
|
488
505
|
}
|
|
489
506
|
function normalizeErrorItem(message) {
|
|
490
507
|
return Array.isArray(message) ? message : message ? [message] : [];
|
|
@@ -538,6 +555,12 @@
|
|
|
538
555
|
return '_value' in el;
|
|
539
556
|
}
|
|
540
557
|
|
|
558
|
+
function parseInputValue(el) {
|
|
559
|
+
if (el.type === 'number') {
|
|
560
|
+
return el.valueAsNumber;
|
|
561
|
+
}
|
|
562
|
+
return el.value;
|
|
563
|
+
}
|
|
541
564
|
function normalizeEventValue(value) {
|
|
542
565
|
if (!isEvent(value)) {
|
|
543
566
|
return value;
|
|
@@ -563,7 +586,7 @@
|
|
|
563
586
|
const selectedOption = Array.from(input.options).find(opt => opt.selected);
|
|
564
587
|
return selectedOption ? getBoundValue(selectedOption) : input.value;
|
|
565
588
|
}
|
|
566
|
-
return input
|
|
589
|
+
return parseInputValue(input);
|
|
567
590
|
}
|
|
568
591
|
|
|
569
592
|
/**
|
|
@@ -726,12 +749,17 @@
|
|
|
726
749
|
for (let i = 0; i < length; i++) {
|
|
727
750
|
const rule = pipeline[i];
|
|
728
751
|
const result = await rule(value, ctx);
|
|
729
|
-
const isValid = typeof result !== 'string' && result;
|
|
752
|
+
const isValid = typeof result !== 'string' && !Array.isArray(result) && result;
|
|
730
753
|
if (isValid) {
|
|
731
754
|
continue;
|
|
732
755
|
}
|
|
733
|
-
|
|
734
|
-
|
|
756
|
+
if (Array.isArray(result)) {
|
|
757
|
+
errors.push(...result);
|
|
758
|
+
}
|
|
759
|
+
else {
|
|
760
|
+
const message = typeof result === 'string' ? result : _generateFieldError(ctx);
|
|
761
|
+
errors.push(message);
|
|
762
|
+
}
|
|
735
763
|
if (field.bails) {
|
|
736
764
|
return {
|
|
737
765
|
errors,
|
|
@@ -1103,7 +1131,7 @@
|
|
|
1103
1131
|
return _useField(path, rules, opts);
|
|
1104
1132
|
}
|
|
1105
1133
|
function _useField(path, rules, opts) {
|
|
1106
|
-
const { initialValue: modelValue, validateOnMount, bails, type, checkedValue, label, validateOnValueUpdate, uncheckedValue, controlled, keepValueOnUnmount,
|
|
1134
|
+
const { initialValue: modelValue, validateOnMount, bails, type, checkedValue, label, validateOnValueUpdate, uncheckedValue, controlled, keepValueOnUnmount, syncVModel, form: controlForm, } = normalizeOptions(opts);
|
|
1107
1135
|
const injectedForm = controlled ? injectWithSelf(FormContextKey) : undefined;
|
|
1108
1136
|
const form = controlForm || injectedForm;
|
|
1109
1137
|
const name = lazyToRef(path);
|
|
@@ -1131,13 +1159,16 @@
|
|
|
1131
1159
|
});
|
|
1132
1160
|
const errorMessage = vue.computed(() => errors.value[0]);
|
|
1133
1161
|
if (syncVModel) {
|
|
1134
|
-
useVModel({ value, prop:
|
|
1162
|
+
useVModel({ value, prop: syncVModel, handleChange });
|
|
1135
1163
|
}
|
|
1136
1164
|
/**
|
|
1137
1165
|
* Handles common onBlur meta update
|
|
1138
1166
|
*/
|
|
1139
|
-
const handleBlur = () => {
|
|
1167
|
+
const handleBlur = (evt, shouldValidate = false) => {
|
|
1140
1168
|
meta.touched = true;
|
|
1169
|
+
if (shouldValidate) {
|
|
1170
|
+
validateWithStateMutation();
|
|
1171
|
+
}
|
|
1141
1172
|
};
|
|
1142
1173
|
async function validateCurrentValue(mode) {
|
|
1143
1174
|
var _a, _b;
|
|
@@ -1213,10 +1244,6 @@
|
|
|
1213
1244
|
}
|
|
1214
1245
|
function setValue(newValue, shouldValidate = true) {
|
|
1215
1246
|
value.value = newValue;
|
|
1216
|
-
if (!shouldValidate) {
|
|
1217
|
-
validateValidStateOnly();
|
|
1218
|
-
return;
|
|
1219
|
-
}
|
|
1220
1247
|
const validateFn = shouldValidate ? validateWithStateMutation : validateValidStateOnly;
|
|
1221
1248
|
validateFn();
|
|
1222
1249
|
}
|
|
@@ -1309,7 +1336,7 @@
|
|
|
1309
1336
|
vue.onBeforeUnmount(() => {
|
|
1310
1337
|
var _a;
|
|
1311
1338
|
const shouldKeepValue = (_a = vue.unref(field.keepValueOnUnmount)) !== null && _a !== void 0 ? _a : vue.unref(form.keepValuesOnUnmount);
|
|
1312
|
-
const path =
|
|
1339
|
+
const path = vue.toValue(name);
|
|
1313
1340
|
if (shouldKeepValue || !form || flags.pendingUnmount[field.id]) {
|
|
1314
1341
|
form === null || form === void 0 ? void 0 : form.removePathState(path, id);
|
|
1315
1342
|
return;
|
|
@@ -1334,7 +1361,7 @@
|
|
|
1334
1361
|
}
|
|
1335
1362
|
}
|
|
1336
1363
|
else {
|
|
1337
|
-
form.unsetPathValue(
|
|
1364
|
+
form.unsetPathValue(vue.toValue(name));
|
|
1338
1365
|
}
|
|
1339
1366
|
form.removePathState(path, id);
|
|
1340
1367
|
});
|
|
@@ -1344,7 +1371,6 @@
|
|
|
1344
1371
|
* Normalizes partial field options to include the full options
|
|
1345
1372
|
*/
|
|
1346
1373
|
function normalizeOptions(opts) {
|
|
1347
|
-
var _a;
|
|
1348
1374
|
const defaults = () => ({
|
|
1349
1375
|
initialValue: undefined,
|
|
1350
1376
|
validateOnMount: false,
|
|
@@ -1352,13 +1378,13 @@
|
|
|
1352
1378
|
label: undefined,
|
|
1353
1379
|
validateOnValueUpdate: true,
|
|
1354
1380
|
keepValueOnUnmount: undefined,
|
|
1355
|
-
|
|
1356
|
-
syncVModel: true,
|
|
1381
|
+
syncVModel: false,
|
|
1357
1382
|
controlled: true,
|
|
1358
1383
|
});
|
|
1359
|
-
const isVModelSynced = (
|
|
1384
|
+
const isVModelSynced = !!(opts === null || opts === void 0 ? void 0 : opts.syncVModel);
|
|
1385
|
+
const modelPropName = typeof (opts === null || opts === void 0 ? void 0 : opts.syncVModel) === 'string' ? opts.syncVModel : (opts === null || opts === void 0 ? void 0 : opts.modelPropName) || 'modelValue';
|
|
1360
1386
|
const initialValue = isVModelSynced && !('initialValue' in (opts || {}))
|
|
1361
|
-
? getCurrentModelValue(vue.getCurrentInstance(),
|
|
1387
|
+
? getCurrentModelValue(vue.getCurrentInstance(), modelPropName)
|
|
1362
1388
|
: opts === null || opts === void 0 ? void 0 : opts.initialValue;
|
|
1363
1389
|
if (!opts) {
|
|
1364
1390
|
return Object.assign(Object.assign({}, defaults()), { initialValue });
|
|
@@ -1366,7 +1392,9 @@
|
|
|
1366
1392
|
// TODO: Deprecate this in next major release
|
|
1367
1393
|
const checkedValue = 'valueProp' in opts ? opts.valueProp : opts.checkedValue;
|
|
1368
1394
|
const controlled = 'standalone' in opts ? !opts.standalone : opts.controlled;
|
|
1369
|
-
|
|
1395
|
+
const syncVModel = (opts === null || opts === void 0 ? void 0 : opts.modelPropName) || (opts === null || opts === void 0 ? void 0 : opts.syncVModel) || false;
|
|
1396
|
+
return Object.assign(Object.assign(Object.assign({}, defaults()), (opts || {})), { initialValue, controlled: controlled !== null && controlled !== void 0 ? controlled : true, checkedValue,
|
|
1397
|
+
syncVModel });
|
|
1370
1398
|
}
|
|
1371
1399
|
function useFieldWithChecked(name, rules, opts) {
|
|
1372
1400
|
const form = !(opts === null || opts === void 0 ? void 0 : opts.standalone) ? injectWithSelf(FormContextKey) : undefined;
|
|
@@ -1382,23 +1410,22 @@
|
|
|
1382
1410
|
: isEqual(checkedVal, currentValue);
|
|
1383
1411
|
});
|
|
1384
1412
|
function handleCheckboxChange(e, shouldValidate = true) {
|
|
1385
|
-
var _a;
|
|
1413
|
+
var _a, _b;
|
|
1386
1414
|
if (checked.value === ((_a = e === null || e === void 0 ? void 0 : e.target) === null || _a === void 0 ? void 0 : _a.checked)) {
|
|
1387
1415
|
if (shouldValidate) {
|
|
1388
1416
|
field.validate();
|
|
1389
1417
|
}
|
|
1390
1418
|
return;
|
|
1391
1419
|
}
|
|
1392
|
-
const path =
|
|
1420
|
+
const path = vue.toValue(name);
|
|
1393
1421
|
const pathState = form === null || form === void 0 ? void 0 : form.getPathState(path);
|
|
1394
1422
|
const value = normalizeEventValue(e);
|
|
1395
|
-
let newValue;
|
|
1423
|
+
let newValue = (_b = vue.unref(checkedValue)) !== null && _b !== void 0 ? _b : value;
|
|
1396
1424
|
if (form && (pathState === null || pathState === void 0 ? void 0 : pathState.multiple) && pathState.type === 'checkbox') {
|
|
1397
|
-
newValue = resolveNextCheckboxValue(getFromPath(form.values, path) || [],
|
|
1425
|
+
newValue = resolveNextCheckboxValue(getFromPath(form.values, path) || [], newValue, undefined);
|
|
1398
1426
|
}
|
|
1399
|
-
else {
|
|
1400
|
-
|
|
1401
|
-
newValue = resolveNextCheckboxValue(vue.unref(field.value), vue.unref(checkedValue), vue.unref(uncheckedValue));
|
|
1427
|
+
else if ((opts === null || opts === void 0 ? void 0 : opts.type) === 'checkbox') {
|
|
1428
|
+
newValue = resolveNextCheckboxValue(vue.unref(field.value), newValue, vue.unref(uncheckedValue));
|
|
1402
1429
|
}
|
|
1403
1430
|
handleChange(newValue, shouldValidate);
|
|
1404
1431
|
}
|
|
@@ -1411,10 +1438,10 @@
|
|
|
1411
1438
|
function useVModel({ prop, value, handleChange }) {
|
|
1412
1439
|
const vm = vue.getCurrentInstance();
|
|
1413
1440
|
/* istanbul ignore next */
|
|
1414
|
-
if (!vm) {
|
|
1441
|
+
if (!vm || !prop) {
|
|
1415
1442
|
return;
|
|
1416
1443
|
}
|
|
1417
|
-
const propName = prop
|
|
1444
|
+
const propName = typeof prop === 'string' ? prop : 'modelValue';
|
|
1418
1445
|
const emitName = `update:${propName}`;
|
|
1419
1446
|
// Component doesn't have a model prop setup (must be defined on the props)
|
|
1420
1447
|
if (!(propName in vm.props)) {
|
|
@@ -1531,6 +1558,7 @@
|
|
|
1531
1558
|
label,
|
|
1532
1559
|
validateOnValueUpdate: false,
|
|
1533
1560
|
keepValueOnUnmount: keepValue,
|
|
1561
|
+
syncVModel: true,
|
|
1534
1562
|
});
|
|
1535
1563
|
// If there is a v-model applied on the component we need to emit the `update:modelValue` whenever the value binding changes
|
|
1536
1564
|
const onChangeHandler = function handleChangeWithModel(e, shouldValidate = true) {
|
|
@@ -1540,13 +1568,10 @@
|
|
|
1540
1568
|
const sharedProps = vue.computed(() => {
|
|
1541
1569
|
const { validateOnInput, validateOnChange, validateOnBlur, validateOnModelUpdate } = resolveValidationTriggers(props);
|
|
1542
1570
|
function baseOnBlur(e) {
|
|
1543
|
-
handleBlur(e);
|
|
1571
|
+
handleBlur(e, validateOnBlur);
|
|
1544
1572
|
if (isCallable(ctx.attrs.onBlur)) {
|
|
1545
1573
|
ctx.attrs.onBlur(e);
|
|
1546
1574
|
}
|
|
1547
|
-
if (validateOnBlur) {
|
|
1548
|
-
validateField();
|
|
1549
|
-
}
|
|
1550
1575
|
}
|
|
1551
1576
|
function baseOnInput(e) {
|
|
1552
1577
|
onChangeHandler(e, validateOnInput);
|
|
@@ -1596,7 +1621,7 @@
|
|
|
1596
1621
|
handleChange: onChangeHandler,
|
|
1597
1622
|
handleInput: e => onChangeHandler(e, false),
|
|
1598
1623
|
handleReset,
|
|
1599
|
-
handleBlur,
|
|
1624
|
+
handleBlur: sharedProps.value.onBlur,
|
|
1600
1625
|
setTouched,
|
|
1601
1626
|
setErrors,
|
|
1602
1627
|
};
|
|
@@ -1750,7 +1775,7 @@
|
|
|
1750
1775
|
const schema = opts === null || opts === void 0 ? void 0 : opts.validationSchema;
|
|
1751
1776
|
function createPathState(path, config) {
|
|
1752
1777
|
var _a, _b;
|
|
1753
|
-
const initialValue = vue.computed(() => getFromPath(initialValues.value,
|
|
1778
|
+
const initialValue = vue.computed(() => getFromPath(initialValues.value, vue.toValue(path)));
|
|
1754
1779
|
const pathStateExists = pathStates.value.find(state => state.path === vue.unref(path));
|
|
1755
1780
|
if (pathStateExists) {
|
|
1756
1781
|
if ((config === null || config === void 0 ? void 0 : config.type) === 'checkbox' || (config === null || config === void 0 ? void 0 : config.type) === 'radio') {
|
|
@@ -1767,8 +1792,8 @@
|
|
|
1767
1792
|
pathStateExists.__flags.pendingUnmount[id] = false;
|
|
1768
1793
|
return pathStateExists;
|
|
1769
1794
|
}
|
|
1770
|
-
const currentValue = vue.computed(() => getFromPath(formValues,
|
|
1771
|
-
const pathValue =
|
|
1795
|
+
const currentValue = vue.computed(() => getFromPath(formValues, vue.toValue(path)));
|
|
1796
|
+
const pathValue = vue.toValue(path);
|
|
1772
1797
|
const id = FIELD_ID_COUNTER++;
|
|
1773
1798
|
const state = vue.reactive({
|
|
1774
1799
|
id,
|
|
@@ -2020,7 +2045,7 @@
|
|
|
2020
2045
|
/**
|
|
2021
2046
|
* Sets a single field value
|
|
2022
2047
|
*/
|
|
2023
|
-
function setFieldValue(field, value) {
|
|
2048
|
+
function setFieldValue(field, value, shouldValidate = true) {
|
|
2024
2049
|
const clonedValue = klona(value);
|
|
2025
2050
|
const path = typeof field === 'string' ? field : field.path;
|
|
2026
2051
|
const pathState = findPathState(path);
|
|
@@ -2028,6 +2053,9 @@
|
|
|
2028
2053
|
createPathState(path);
|
|
2029
2054
|
}
|
|
2030
2055
|
setInPath(formValues, path, clonedValue);
|
|
2056
|
+
if (shouldValidate) {
|
|
2057
|
+
validateField(path);
|
|
2058
|
+
}
|
|
2031
2059
|
}
|
|
2032
2060
|
/**
|
|
2033
2061
|
* Sets multiple fields values
|
|
@@ -2045,7 +2073,7 @@
|
|
|
2045
2073
|
},
|
|
2046
2074
|
set(value) {
|
|
2047
2075
|
const pathValue = vue.unref(path);
|
|
2048
|
-
setFieldValue(pathValue, value);
|
|
2076
|
+
setFieldValue(pathValue, value, false);
|
|
2049
2077
|
pathState.validated = true;
|
|
2050
2078
|
pathState.pending = true;
|
|
2051
2079
|
validateField(pathValue).then(() => {
|
|
@@ -2081,7 +2109,7 @@
|
|
|
2081
2109
|
var _a;
|
|
2082
2110
|
const newValue = state && 'value' in state ? state.value : getFromPath(initialValues.value, field);
|
|
2083
2111
|
setFieldInitialValue(field, klona(newValue));
|
|
2084
|
-
setFieldValue(field, newValue);
|
|
2112
|
+
setFieldValue(field, newValue, false);
|
|
2085
2113
|
setFieldTouched(field, (_a = state === null || state === void 0 ? void 0 : state.touched) !== null && _a !== void 0 ? _a : false);
|
|
2086
2114
|
setFieldError(field, (state === null || state === void 0 ? void 0 : state.errors) || []);
|
|
2087
2115
|
}
|
|
@@ -2096,7 +2124,7 @@
|
|
|
2096
2124
|
var _a;
|
|
2097
2125
|
state.validated = false;
|
|
2098
2126
|
state.touched = ((_a = resetState === null || resetState === void 0 ? void 0 : resetState.touched) === null || _a === void 0 ? void 0 : _a[state.path]) || false;
|
|
2099
|
-
setFieldValue(state.path, getFromPath(newValues, state.path));
|
|
2127
|
+
setFieldValue(state.path, getFromPath(newValues, state.path), false);
|
|
2100
2128
|
setFieldError(state.path, undefined);
|
|
2101
2129
|
});
|
|
2102
2130
|
setErrors((resetState === null || resetState === void 0 ? void 0 : resetState.errors) || {});
|
|
@@ -2230,7 +2258,7 @@
|
|
|
2230
2258
|
// Provide injections
|
|
2231
2259
|
vue.provide(FormContextKey, formCtx);
|
|
2232
2260
|
function defineComponentBinds(path, config) {
|
|
2233
|
-
const pathState = findPathState(
|
|
2261
|
+
const pathState = findPathState(vue.toValue(path)) || createPathState(path);
|
|
2234
2262
|
const evalConfig = () => (isCallable(config) ? config(omit(pathState, PRIVATE_PATH_STATE_KEYS)) : config || {});
|
|
2235
2263
|
function onBlur() {
|
|
2236
2264
|
var _a;
|
|
@@ -2249,23 +2277,25 @@
|
|
|
2249
2277
|
}
|
|
2250
2278
|
}
|
|
2251
2279
|
const props = vue.computed(() => {
|
|
2252
|
-
const base = {
|
|
2253
|
-
modelValue: pathState.value,
|
|
2254
|
-
'onUpdate:modelValue': onUpdateModelValue,
|
|
2255
|
-
onBlur,
|
|
2256
|
-
};
|
|
2257
2280
|
if (isCallable(config)) {
|
|
2258
|
-
|
|
2281
|
+
const configVal = config(pathState);
|
|
2282
|
+
const model = configVal.model || 'modelValue';
|
|
2283
|
+
return Object.assign({ onBlur, [model]: pathState.value, [`onUpdate:${model}`]: onUpdateModelValue }, (configVal.props || {}));
|
|
2259
2284
|
}
|
|
2285
|
+
const model = (config === null || config === void 0 ? void 0 : config.model) || 'modelValue';
|
|
2286
|
+
const base = {
|
|
2287
|
+
[model]: pathState.value,
|
|
2288
|
+
[`onUpdate:${model}`]: onUpdateModelValue,
|
|
2289
|
+
};
|
|
2260
2290
|
if (config === null || config === void 0 ? void 0 : config.mapProps) {
|
|
2261
|
-
return Object.assign(Object.assign({}, base), config.mapProps(omit(pathState, PRIVATE_PATH_STATE_KEYS)));
|
|
2291
|
+
return Object.assign(Object.assign({ onBlur }, base), config.mapProps(omit(pathState, PRIVATE_PATH_STATE_KEYS)));
|
|
2262
2292
|
}
|
|
2263
2293
|
return base;
|
|
2264
2294
|
});
|
|
2265
2295
|
return props;
|
|
2266
2296
|
}
|
|
2267
2297
|
function defineInputBinds(path, config) {
|
|
2268
|
-
const pathState = (findPathState(
|
|
2298
|
+
const pathState = (findPathState(vue.toValue(path)) || createPathState(path));
|
|
2269
2299
|
const evalConfig = () => (isCallable(config) ? config(omit(pathState, PRIVATE_PATH_STATE_KEYS)) : config || {});
|
|
2270
2300
|
function onBlur() {
|
|
2271
2301
|
var _a;
|
|
@@ -2310,7 +2340,7 @@
|
|
|
2310
2340
|
});
|
|
2311
2341
|
return props;
|
|
2312
2342
|
}
|
|
2313
|
-
return Object.assign(Object.assign({}, formCtx), { handleReset: () => resetForm(), submitForm,
|
|
2343
|
+
return Object.assign(Object.assign({}, formCtx), { values: vue.readonly(formValues), handleReset: () => resetForm(), submitForm,
|
|
2314
2344
|
defineComponentBinds,
|
|
2315
2345
|
defineInputBinds });
|
|
2316
2346
|
}
|
|
@@ -2360,8 +2390,8 @@
|
|
|
2360
2390
|
// these only change when the user explicitly changes the initial values or when the user resets them with new values.
|
|
2361
2391
|
const originalInitialValues = vue.ref(klona(values));
|
|
2362
2392
|
function setInitialValues(values, updateFields = false) {
|
|
2363
|
-
initialValues.value = klona(values);
|
|
2364
|
-
originalInitialValues.value = klona(values);
|
|
2393
|
+
initialValues.value = merge(klona(initialValues.value) || {}, klona(values));
|
|
2394
|
+
originalInitialValues.value = merge(klona(originalInitialValues.value) || {}, klona(values));
|
|
2365
2395
|
if (!updateFields) {
|
|
2366
2396
|
return;
|
|
2367
2397
|
}
|
package/dist/vee-validate.min.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* vee-validate v4.
|
|
2
|
+
* vee-validate v4.10.0
|
|
3
3
|
* (c) 2023 Abdelrahman Awad
|
|
4
4
|
* @license MIT
|
|
5
5
|
*/
|
|
6
|
-
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports,require("vue")):"function"==typeof define&&define.amd?define(["exports","vue"],t):t((e="undefined"!=typeof globalThis?globalThis:e||self).VeeValidate={},e.Vue)}(this,(function(e,t){"use strict";function n(e){return"function"==typeof e}function r(e){return null==e}const a=e=>null!==e&&!!e&&"object"==typeof e&&!Array.isArray(e);function i(e){return Number(e)>=0}function l(e,t){return Object.keys(t).forEach((n=>{if(a(t[n]))return e[n]||(e[n]={}),void l(e[n],t[n]);e[n]=t[n]})),e}const u={};const o=Symbol("vee-validate-form"),s=Symbol("vee-validate-field-instance"),d=Symbol("Default empty value"),c="undefined"!=typeof window;function v(e){return n(e)&&!!e.__locatorRef}function f(e){return!!e&&n(e.parse)&&"VVTypedSchema"===e.__type}function p(e){return!!e&&n(e.validate)}function m(e){return"checkbox"===e||"radio"===e}function h(e){return/^\[.+\]$/i.test(e)}function y(e){return"SELECT"===e.tagName}function g(e,t){return!function(e,t){const n=![!1,null,void 0,0].includes(t.multiple)&&!Number.isNaN(t.multiple);return"select"===e&&"multiple"in t&&n}(e,t)&&"file"!==t.type&&!m(t.type)}function b(e){return O(e)&&e.target&&"submit"in e.target}function O(e){return!!e&&(!!("undefined"!=typeof Event&&n(Event)&&e instanceof Event)||!(!e||!e.srcElement))}function V(e,t){return t in e&&e[t]!==d}function F(e,t){if(e===t)return!0;if(e&&t&&"object"==typeof e&&"object"==typeof t){if(e.constructor!==t.constructor)return!1;var n,r,a;if(Array.isArray(e)){if((n=e.length)!=t.length)return!1;for(r=n;0!=r--;)if(!F(e[r],t[r]))return!1;return!0}if(e instanceof Map&&t instanceof Map){if(e.size!==t.size)return!1;for(r of e.entries())if(!t.has(r[0]))return!1;for(r of e.entries())if(!F(r[1],t.get(r[0])))return!1;return!0}if(A(e)&&A(t))return e.size===t.size&&(e.name===t.name&&(e.lastModified===t.lastModified&&e.type===t.type));if(e instanceof Set&&t instanceof Set){if(e.size!==t.size)return!1;for(r of e.entries())if(!t.has(r[0]))return!1;return!0}if(ArrayBuffer.isView(e)&&ArrayBuffer.isView(t)){if((n=e.length)!=t.length)return!1;for(r=n;0!=r--;)if(e[r]!==t[r])return!1;return!0}if(e.constructor===RegExp)return e.source===t.source&&e.flags===t.flags;if(e.valueOf!==Object.prototype.valueOf)return e.valueOf()===t.valueOf();if(e.toString!==Object.prototype.toString)return e.toString()===t.toString();if((n=(a=Object.keys(e)).length)!==Object.keys(t).length)return!1;for(r=n;0!=r--;)if(!Object.prototype.hasOwnProperty.call(t,a[r]))return!1;for(r=n;0!=r--;){var i=a[r];if(!F(e[i],t[i]))return!1}return!0}return e!=e&&t!=t}function A(e){return!!c&&e instanceof File}function j(e,t,n){"object"==typeof n.value&&(n.value=w(n.value)),n.enumerable&&!n.get&&!n.set&&n.configurable&&n.writable&&"__proto__"!==t?e[t]=n.value:Object.defineProperty(e,t,n)}function w(e){if("object"!=typeof e)return e;var t,n,r,a=0,i=Object.prototype.toString.call(e);if("[object Object]"===i?r=Object.create(e.__proto__||null):"[object Array]"===i?r=Array(e.length):"[object Set]"===i?(r=new Set,e.forEach((function(e){r.add(w(e))}))):"[object Map]"===i?(r=new Map,e.forEach((function(e,t){r.set(w(t),w(e))}))):"[object Date]"===i?r=new Date(+e):"[object RegExp]"===i?r=new RegExp(e.source,e.flags):"[object DataView]"===i?r=new e.constructor(w(e.buffer)):"[object ArrayBuffer]"===i?r=e.slice(0):"Array]"===i.slice(-6)&&(r=new e.constructor(e)),r){for(n=Object.getOwnPropertySymbols(e);a<n.length;a++)j(r,n[a],Object.getOwnPropertyDescriptor(e,n[a]));for(a=0,n=Object.getOwnPropertyNames(e);a<n.length;a++)Object.hasOwnProperty.call(r,t=n[a])&&r[t]===e[t]||j(r,t,Object.getOwnPropertyDescriptor(e,t))}return r||e}function S(e){return h(e)?e.replace(/\[|\]/gi,""):e}function E(e,t,n){if(!e)return n;if(h(t))return e[S(t)];return(t||"").split(/\.|\[(\d+)\]/).filter(Boolean).reduce(((e,t)=>{return(a(r=e)||Array.isArray(r))&&t in e?e[t]:n;var r}),e)}function k(e,t,n){if(h(t))return void(e[S(t)]=n);const a=t.split(/\.|\[(\d+)\]/).filter(Boolean);let l=e;for(let e=0;e<a.length;e++){if(e===a.length-1)return void(l[a[e]]=n);a[e]in l&&!r(l[a[e]])||(l[a[e]]=i(a[e+1])?[]:{}),l=l[a[e]]}}function I(e,t){Array.isArray(e)&&i(t)?e.splice(Number(t),1):a(e)&&delete e[t]}function C(e,t){if(h(t))return void delete e[S(t)];const n=t.split(/\.|\[(\d+)\]/).filter(Boolean);let i=e;for(let e=0;e<n.length;e++){if(e===n.length-1){I(i,n[e]);break}if(!(n[e]in i)||r(i[n[e]]))break;i=i[n[e]]}const l=n.map(((t,r)=>E(e,n.slice(0,r).join("."))));for(let t=l.length-1;t>=0;t--)u=l[t],(Array.isArray(u)?0===u.length:a(u)&&0===Object.keys(u).length)&&(0!==t?I(l[t-1],n[t-1]):I(e,n[0]));var u}function M(e){return Object.keys(e)}function B(e,n=void 0){const r=t.getCurrentInstance();return(null==r?void 0:r.provides[e])||t.inject(e,n)}function _(e){t.warn(`[vee-validate]: ${e}`)}function T(e,t,n){if(Array.isArray(e)){const n=[...e],r=n.findIndex((e=>F(e,t)));return r>=0?n.splice(r,1):n.push(t),n}return F(e,t)?n:t}function U(e,t=0){let n=null,r=[];return function(...a){return n&&window.clearTimeout(n),n=window.setTimeout((()=>{const t=e(...a);r.forEach((e=>e(t))),r=[]}),t),new Promise((e=>r.push(e)))}}function P(e,t){return a(t)&&t.number?function(e){const t=parseFloat(e);return isNaN(t)?e:t}(e):e}function R(e,t){let n;return async function(...r){const a=e(...r);n=a;const i=await a;return a!==n||(n=void 0,t(i,r)),i}}function x({get:e,set:n}){const r=t.ref(w(e()));return t.watch(e,(e=>{F(e,r.value)||(r.value=w(e))}),{deep:!0}),t.watch(r,(t=>{F(t,e())||n(w(t))}),{deep:!0}),r}function N(e){return n(e)?e():t.unref(e)}function $(e){return Array.isArray(e)?e:e?[e]:[]}function D(e){const n=B(o),r=e?t.computed((()=>null==n?void 0:n.getPathState(t.unref(e)))):void 0,a=e?void 0:t.inject(s);return a||(null==r?void 0:r.value)||_(`field with name ${t.unref(e)} was not found`),r||a}function z(e,t){const n={};for(const r in e)t.includes(r)||(n[r]=e[r]);return n}const q=(e,t,n)=>t.slots.default?"string"!=typeof e&&e?{default:()=>{var e,r;return null===(r=(e=t.slots).default)||void 0===r?void 0:r.call(e,n())}}:t.slots.default(n()):t.slots.default;function L(e){if(K(e))return e._value}function K(e){return"_value"in e}function W(e){if(!O(e))return e;const t=e.target;if(m(t.type)&&K(t))return L(t);if("file"===t.type&&t.files){const e=Array.from(t.files);return t.multiple?e:e[0]}if(y(n=t)&&n.multiple)return Array.from(t.options).filter((e=>e.selected&&!e.disabled)).map(L);var n;if(y(t)){const e=Array.from(t.options).find((e=>e.selected));return e?L(e):t.value}return t.value}function G(e){const t={};return Object.defineProperty(t,"_$$isNormalized",{value:!0,writable:!1,enumerable:!1,configurable:!1}),e?a(e)&&e._$$isNormalized?e:a(e)?Object.keys(e).reduce(((t,n)=>{const r=function(e){if(!0===e)return[];if(Array.isArray(e))return e;if(a(e))return e;return[e]}(e[n]);return!1!==e[n]&&(t[n]=X(r)),t}),t):"string"!=typeof e?t:e.split("|").reduce(((e,t)=>{const n=H(t);return n.name?(e[n.name]=X(n.params),e):e}),t):t}function X(e){const t=e=>"string"==typeof e&&"@"===e[0]?function(e){const t=t=>E(t,e)||t[e];return t.__locatorRef=e,t}(e.slice(1)):e;return Array.isArray(e)?e.map(t):e instanceof RegExp?[e]:Object.keys(e).reduce(((n,r)=>(n[r]=t(e[r]),n)),{})}const H=e=>{let t=[];const n=e.split(":")[0];return e.includes(":")&&(t=e.split(":").slice(1).join(":").split(",")),{name:n,params:t}};let J=Object.assign({},{generateMessage:({field:e})=>`${e} is not valid.`,bails:!0,validateOnBlur:!0,validateOnChange:!0,validateOnInput:!1,validateOnModelUpdate:!0});const Q=()=>J,Y=e=>{J=Object.assign(Object.assign({},J),e)};async function Z(e,t,r={}){const a=null==r?void 0:r.bails,i={name:(null==r?void 0:r.name)||"{field}",rules:t,label:null==r?void 0:r.label,bails:null==a||a,formData:(null==r?void 0:r.values)||{}},l=await async function(e,t){if(f(e.rules)||p(e.rules))return async function(e,t){const n=f(t)?t:ee(t),r=await n.parse(e),a=[];for(const e of r.errors)e.errors.length&&a.push(...e.errors);return{errors:a}}(t,e.rules);if(n(e.rules)||Array.isArray(e.rules)){const n={field:e.label||e.name,name:e.name,label:e.label,form:e.formData,value:t},r=Array.isArray(e.rules)?e.rules:[e.rules],a=r.length,i=[];for(let l=0;l<a;l++){const a=r[l],u=await a(t,n);if("string"!=typeof u&&u)continue;const o="string"==typeof u?u:ne(n);if(i.push(o),e.bails)return{errors:i}}return{errors:i}}const r=Object.assign(Object.assign({},e),{rules:G(e.rules)}),a=[],i=Object.keys(r.rules),l=i.length;for(let n=0;n<l;n++){const l=i[n],u=await te(r,t,{name:l,params:r.rules[l]});if(u.error&&(a.push(u.error),e.bails))return{errors:a}}return{errors:a}}(i,e),u=l.errors;return{errors:u,valid:!u.length}}function ee(e){return{__type:"VVTypedSchema",async parse(t){var n;try{return{output:await e.validate(t,{abortEarly:!1}),errors:[]}}catch(e){if(!function(e){return!!e&&"ValidationError"===e.name}(e))throw e;if(!(null===(n=e.inner)||void 0===n?void 0:n.length)&&e.errors.length)return{errors:[{path:e.path,errors:e.errors}]};const t=e.inner.reduce(((e,t)=>{const n=t.path||"";return e[n]||(e[n]={errors:[],path:n}),e[n].errors.push(...t.errors),e}),{});return{errors:Object.values(t)}}}}}async function te(e,t,n){const r=(a=n.name,u[a]);var a;if(!r)throw new Error(`No such validator '${n.name}' exists.`);const i=function(e,t){const n=e=>v(e)?e(t):e;if(Array.isArray(e))return e.map(n);return Object.keys(e).reduce(((t,r)=>(t[r]=n(e[r]),t)),{})}(n.params,e.formData),l={field:e.label||e.name,name:e.name,label:e.label,value:t,form:e.formData,rule:Object.assign(Object.assign({},n),{params:i})},o=await r(t,i,l);return"string"==typeof o?{error:o}:{error:o?void 0:ne(l)}}function ne(e){const t=Q().generateMessage;return t?t(e):"Field is invalid"}async function re(e,t,n){const r=M(e).map((async r=>{var a,i,l;const u=null===(a=null==n?void 0:n.names)||void 0===a?void 0:a[r],o=await Z(E(t,r),e[r],{name:(null==u?void 0:u.name)||r,label:null==u?void 0:u.label,values:t,bails:null===(l=null===(i=null==n?void 0:n.bailsMap)||void 0===i?void 0:i[r])||void 0===l||l});return Object.assign(Object.assign({},o),{path:r})}));let a=!0;const i=await Promise.all(r),l={},u={};for(const e of i)l[e.path]={valid:e.valid,errors:e.errors},e.valid||(a=!1,u[e.path]=e.errors[0]);return{valid:a,results:l,errors:u}}let ae=0;function ie(e,n){const{value:r,initialValue:a,setInitialValue:i}=function(e,n,r){const a=t.ref(t.unref(n));function i(){return r?E(r.initialValues.value,t.unref(e),t.unref(a)):t.unref(a)}function l(n){r?r.stageInitialValue(t.unref(e),n,!0):a.value=n}const u=t.computed(i);if(!r){return{value:t.ref(i()),initialValue:u,setInitialValue:l}}const o=function(e,n,r,a){if(t.isRef(e))return t.unref(e);if(void 0!==e)return e;return E(n.values,t.unref(a),t.unref(r))}(n,r,u,e);r.stageInitialValue(t.unref(e),o,!0);const s=t.computed({get:()=>E(r.values,t.unref(e)),set(n){r.setFieldValue(t.unref(e),n)}});return{value:s,initialValue:u,setInitialValue:l}}(e,n.modelValue,n.form);if(!n.form){const{errors:o,setErrors:s}=function(){const e=t.ref([]);return{errors:e,setErrors:t=>{e.value=$(t)}}}(),d=ae>=Number.MAX_SAFE_INTEGER?0:++ae,c=function(e,n,r){const a=t.reactive({touched:!1,pending:!1,valid:!0,validated:!!t.unref(r).length,initialValue:t.computed((()=>t.unref(n))),dirty:t.computed((()=>!F(t.unref(e),t.unref(n))))});return t.watch(r,(e=>{a.valid=!e.length}),{immediate:!0,flush:"sync"}),a}(r,a,o);function v(e){var t;"value"in e&&(r.value=e.value),"errors"in e&&s(e.errors),"touched"in e&&(c.touched=null!==(t=e.touched)&&void 0!==t?t:c.touched),"initialValue"in e&&i(e.initialValue)}return{id:d,path:e,value:r,initialValue:a,meta:c,flags:{pendingUnmount:{[d]:!1}},errors:o,setState:v}}const l=n.form.createPathState(e,{bails:n.bails,label:n.label,type:n.type,validate:n.validate}),u=t.computed((()=>l.errors));return{id:Array.isArray(l.id)?l.id[l.id.length-1]:l.id,path:e,value:r,errors:u,meta:l,initialValue:a,flags:l.__flags,setState:function(a){var l,u,o;"value"in a&&(r.value=a.value),"errors"in a&&(null===(l=n.form)||void 0===l||l.setFieldError(t.unref(e),a.errors)),"touched"in a&&(null===(u=n.form)||void 0===u||u.setFieldTouched(t.unref(e),null!==(o=a.touched)&&void 0!==o&&o)),"initialValue"in a&&i(a.initialValue)}}}function le(e,n,r){return m(null==r?void 0:r.type)?function(e,n,r){const a=(null==r?void 0:r.standalone)?void 0:B(o),i=null==r?void 0:r.checkedValue,l=null==r?void 0:r.uncheckedValue;function u(n){const r=n.handleChange,u=t.computed((()=>{const e=t.unref(n.value),r=t.unref(i);return Array.isArray(e)?e.findIndex((e=>F(e,r)))>=0:F(r,e)}));function o(o,s=!0){var d;if(u.value===(null===(d=null==o?void 0:o.target)||void 0===d?void 0:d.checked))return void(s&&n.validate());const c=N(e),v=null==a?void 0:a.getPathState(c),f=W(o);let p;p=a&&(null==v?void 0:v.multiple)&&"checkbox"===v.type?T(E(a.values,c)||[],f,void 0):T(t.unref(n.value),t.unref(i),t.unref(l)),r(p,s)}return Object.assign(Object.assign({},n),{checked:u,checkedValue:i,uncheckedValue:l,handleChange:o})}return u(ue(e,n,r))}(e,n,r):ue(e,n,r)}function ue(e,r,a){const{initialValue:i,validateOnMount:l,bails:u,type:c,checkedValue:m,label:h,validateOnValueUpdate:y,uncheckedValue:g,controlled:b,keepValueOnUnmount:O,modelPropName:V,syncVModel:A,form:j}=function(e){var n;const r=()=>({initialValue:void 0,validateOnMount:!1,bails:!0,label:void 0,validateOnValueUpdate:!0,keepValueOnUnmount:void 0,modelPropName:"modelValue",syncVModel:!0,controlled:!0}),a=null===(n=null==e?void 0:e.syncVModel)||void 0===n||n,i=a&&!("initialValue"in(e||{}))?oe(t.getCurrentInstance(),(null==e?void 0:e.modelPropName)||"modelValue"):null==e?void 0:e.initialValue;if(!e)return Object.assign(Object.assign({},r()),{initialValue:i});const l="valueProp"in e?e.valueProp:e.checkedValue,u="standalone"in e?!e.standalone:e.controlled;return Object.assign(Object.assign(Object.assign({},r()),e||{}),{initialValue:i,controlled:null==u||u,checkedValue:l})}(a),S=b?B(o):void 0,k=j||S,I=function(e){return t.computed((()=>N(e)))}(e),C=t.computed((()=>{if(t.unref(null==k?void 0:k.schema))return;const e=t.unref(r);return p(e)||f(e)||n(e)||Array.isArray(e)?e:G(e)})),{id:_,value:T,initialValue:U,meta:x,setState:$,errors:D,flags:z}=ie(I,{modelValue:i,form:k,bails:u,label:h,type:c,validate:C.value?H:void 0}),q=t.computed((()=>D.value[0]));A&&function({prop:e,value:n,handleChange:r}){const a=t.getCurrentInstance();if(!a)return;const i=e||"modelValue",l=`update:${i}`;if(!(i in a.props))return;t.watch(n,(e=>{F(e,oe(a,i))||a.emit(l,e)})),t.watch((()=>oe(a,i)),(e=>{if(e===d&&void 0===n.value)return;const t=e===d?void 0:e;F(t,P(n.value,a.props.modelModifiers))||r(t)}))}({value:T,prop:V,handleChange:J});async function L(e){var n,r;return(null==k?void 0:k.validateSchema)?null!==(n=(await k.validateSchema(e)).results[t.unref(I)])&&void 0!==n?n:{valid:!0,errors:[]}:C.value?Z(T.value,C.value,{name:t.unref(I),label:t.unref(h),values:null!==(r=null==k?void 0:k.values)&&void 0!==r?r:{},bails:u}):{valid:!0,errors:[]}}const K=R((async()=>(x.pending=!0,x.validated=!0,L("validated-only"))),(e=>{if(!z.pendingUnmount[te.id])return $({errors:e.errors}),x.pending=!1,x.valid=e.valid,e})),X=R((async()=>L("silent")),(e=>(x.valid=e.valid,e)));function H(e){return"silent"===(null==e?void 0:e.mode)?X():K()}function J(e,t=!0){Y(W(e),t)}function Q(e){var t;const n=e&&"value"in e?e.value:U.value;$({value:w(n),initialValue:w(n),touched:null!==(t=null==e?void 0:e.touched)&&void 0!==t&&t,errors:(null==e?void 0:e.errors)||[]}),x.pending=!1,x.validated=!1,X()}function Y(e,t=!0){if(T.value=e,!t)return void X();(t?K:X)()}t.onMounted((()=>{if(l)return K();k&&k.validateSchema||X()}));const ee=t.computed({get:()=>T.value,set(e){Y(e,y)}}),te={id:_,name:I,label:h,value:ee,meta:x,errors:D,errorMessage:q,type:c,checkedValue:m,uncheckedValue:g,bails:u,keepValueOnUnmount:O,resetField:Q,handleReset:()=>Q(),validate:H,handleChange:J,handleBlur:()=>{x.touched=!0},setState:$,setTouched:function(e){x.touched=e},setErrors:function(e){$({errors:Array.isArray(e)?e:[e]})},setValue:Y};if(t.provide(s,te),t.isRef(r)&&"function"!=typeof t.unref(r)&&t.watch(r,((e,t)=>{F(e,t)||(x.validated?K():X())}),{deep:!0}),!k)return te;const ne=t.computed((()=>{const e=C.value;return!e||n(e)||p(e)||f(e)||Array.isArray(e)?{}:Object.keys(e).reduce(((t,n)=>{const r=(a=e[n],Array.isArray(a)?a.filter(v):M(a).filter((e=>v(a[e]))).map((e=>a[e]))).map((e=>e.__locatorRef)).reduce(((e,t)=>{const n=E(k.values,t)||k.values[t];return void 0!==n&&(e[t]=n),e}),{});var a;return Object.assign(t,r),t}),{})}));return t.watch(ne,((e,t)=>{if(!Object.keys(e).length)return;!F(e,t)&&(x.validated?K():X())})),t.onBeforeUnmount((()=>{var e;const n=null!==(e=t.unref(te.keepValueOnUnmount))&&void 0!==e?e:t.unref(k.keepValuesOnUnmount),r=N(I);if(n||!k||z.pendingUnmount[te.id])return void(null==k||k.removePathState(r,_));z.pendingUnmount[te.id]=!0;const a=k.getPathState(r);if(Array.isArray(null==a?void 0:a.id)&&(null==a?void 0:a.multiple)?null==a?void 0:a.id.includes(te.id):(null==a?void 0:a.id)===te.id){if((null==a?void 0:a.multiple)&&Array.isArray(a.value)){const e=a.value.findIndex((e=>F(e,t.unref(te.checkedValue))));if(e>-1){const t=[...a.value];t.splice(e,1),k.setFieldValue(r,t)}Array.isArray(a.id)&&a.id.splice(a.id.indexOf(te.id),1)}else k.unsetPathValue(N(I));k.removePathState(r,_)}})),te}function oe(e,t){if(e)return e.props[t]}function se(e,t){let n=e.as||"";return e.as||t.slots.default||(n="input"),n}function de(e,t){return m(t.attrs.type)?V(e,"modelValue")?e.modelValue:void 0:V(e,"modelValue")?e.modelValue:t.attrs.value}const ce=t.defineComponent({name:"Field",inheritAttrs:!1,props:{as:{type:[String,Object],default:void 0},name:{type:String,required:!0},rules:{type:[Object,String,Function],default:void 0},validateOnMount:{type:Boolean,default:!1},validateOnBlur:{type:Boolean,default:void 0},validateOnChange:{type:Boolean,default:void 0},validateOnInput:{type:Boolean,default:void 0},validateOnModelUpdate:{type:Boolean,default:void 0},bails:{type:Boolean,default:()=>Q().bails},label:{type:String,default:void 0},uncheckedValue:{type:null,default:void 0},modelValue:{type:null,default:d},modelModifiers:{type:null,default:()=>({})},"onUpdate:modelValue":{type:null,default:void 0},standalone:{type:Boolean,default:!1},keepValue:{type:Boolean,default:void 0}},setup(e,r){const a=t.toRef(e,"rules"),i=t.toRef(e,"name"),l=t.toRef(e,"label"),u=t.toRef(e,"uncheckedValue"),o=t.toRef(e,"keepValue"),{errors:s,value:d,errorMessage:c,validate:v,handleChange:f,handleBlur:p,setTouched:h,resetField:y,handleReset:b,meta:O,checked:V,setErrors:F}=le(i,a,{validateOnMount:e.validateOnMount,bails:e.bails,standalone:e.standalone,type:r.attrs.type,initialValue:de(e,r),checkedValue:r.attrs.value,uncheckedValue:u,label:l,validateOnValueUpdate:!1,keepValueOnUnmount:o}),A=function(e,t=!0){f(e,t),r.emit("update:modelValue",d.value)},j=t.computed((()=>{const{validateOnInput:t,validateOnChange:a,validateOnBlur:i,validateOnModelUpdate:l}=function(e){var t,n,r,a;const{validateOnInput:i,validateOnChange:l,validateOnBlur:u,validateOnModelUpdate:o}=Q();return{validateOnInput:null!==(t=e.validateOnInput)&&void 0!==t?t:i,validateOnChange:null!==(n=e.validateOnChange)&&void 0!==n?n:l,validateOnBlur:null!==(r=e.validateOnBlur)&&void 0!==r?r:u,validateOnModelUpdate:null!==(a=e.validateOnModelUpdate)&&void 0!==a?a:o}}(e);const u={name:e.name,onBlur:function(e){p(e),n(r.attrs.onBlur)&&r.attrs.onBlur(e),i&&v()},onInput:function(e){A(e,t),n(r.attrs.onInput)&&r.attrs.onInput(e)},onChange:function(e){A(e,a),n(r.attrs.onChange)&&r.attrs.onChange(e)},"onUpdate:modelValue":e=>A(e,l)};return u})),w=t.computed((()=>{const t=Object.assign({},j.value);m(r.attrs.type)&&V&&(t.checked=V.value);return g(se(e,r),r.attrs)&&(t.value=d.value),t})),S=t.computed((()=>Object.assign(Object.assign({},j.value),{modelValue:d.value})));function E(){return{field:w.value,componentField:S.value,value:d.value,meta:O,errors:s.value,errorMessage:c.value,validate:v,resetField:y,handleChange:A,handleInput:e=>A(e,!1),handleReset:b,handleBlur:p,setTouched:h,setErrors:F}}return r.expose({setErrors:F,setTouched:h,reset:y,validate:v,handleChange:f}),()=>{const n=t.resolveDynamicComponent(se(e,r)),a=q(n,r,E);return n?t.h(n,Object.assign(Object.assign({},r.attrs),w.value),a):a}}});let ve=0;const fe=["bails","fieldsCount","id","multiple","type","validate"];function pe(e){const r=t.unref(null==e?void 0:e.initialValues)||{},a=t.unref(null==e?void 0:e.validationSchema);return a&&f(a)&&n(a.cast)?w(a.cast(r)||{}):w(r)}function me(e){var r;const a=ve++;let i=0;const u=t.ref(!1),s=t.ref(!1),d=t.ref(0),c=[],v=t.reactive(pe(e)),m=t.ref([]),h=t.ref({});function y(e,t){const n=H(e);n?(n.errors=$(t),n.valid=!n.errors.length):"string"==typeof e&&(h.value[e]=$(t))}function g(e){M(e).forEach((t=>{y(t,e[t])}))}(null==e?void 0:e.initialErrors)&&g(e.initialErrors);const O=t.computed((()=>{const e=m.value.reduce(((e,t)=>(t.errors.length&&(e[t.path]=t.errors),e)),{});return Object.assign(Object.assign({},h.value),e)})),V=t.computed((()=>M(O.value).reduce(((e,t)=>{const n=O.value[t];return(null==n?void 0:n.length)&&(e[t]=n[0]),e}),{}))),A=t.computed((()=>m.value.reduce(((e,t)=>(e[t.path]={name:t.path||"",label:t.label||""},e)),{}))),j=t.computed((()=>m.value.reduce(((e,t)=>{var n;return e[t.path]=null===(n=t.bails)||void 0===n||n,e}),{}))),S=Object.assign({},(null==e?void 0:e.initialErrors)||{}),I=null!==(r=null==e?void 0:e.keepValuesOnUnmount)&&void 0!==r&&r,{initialValues:B,originalInitialValues:_,setInitialValues:T}=function(e,n,r){const a=pe(r),i=null==r?void 0:r.initialValues,l=t.ref(a),u=t.ref(w(a));function o(t,r=!1){l.value=w(t),u.value=w(t),r&&e.value.forEach((e=>{if(e.touched)return;const t=E(l.value,e.path);k(n,e.path,w(t))}))}t.isRef(i)&&t.watch(i,(e=>{e&&o(e,!0)}),{deep:!0});return{initialValues:l,originalInitialValues:u,setInitialValues:o}}(m,v,e),P=function(e,n,r,a){const i={touched:"some",pending:"some",valid:"every"},l=t.computed((()=>!F(n,t.unref(r))));function u(){const t=e.value;return M(i).reduce(((e,n)=>{const r=i[n];return e[n]=t[r]((e=>e[n])),e}),{})}const o=t.reactive(u());return t.watchEffect((()=>{const e=u();o.touched=e.touched,o.valid=e.valid,o.pending=e.pending})),t.computed((()=>Object.assign(Object.assign({initialValues:t.unref(r)},o),{valid:o.valid&&!M(a.value).length,dirty:l.value})))}(m,v,_,V),x=t.computed((()=>m.value.reduce(((e,t)=>{const n=E(v,t.path);return k(e,t.path,n),e}),{}))),D=null==e?void 0:e.validationSchema;function q(e,n){var r,a;const l=t.computed((()=>E(B.value,N(e)))),u=m.value.find((n=>n.path===t.unref(e)));if(u){"checkbox"!==(null==n?void 0:n.type)&&"radio"!==(null==n?void 0:n.type)||(u.multiple=!0);const e=i++;return Array.isArray(u.id)?u.id.push(e):u.id=[u.id,e],u.fieldsCount++,u.__flags.pendingUnmount[e]=!1,u}const o=t.computed((()=>E(v,N(e)))),s=N(e),d=i++,c=t.reactive({id:d,path:e,touched:!1,pending:!1,valid:!0,validated:!!(null===(r=S[s])||void 0===r?void 0:r.length),initialValue:l,errors:t.shallowRef([]),bails:null!==(a=null==n?void 0:n.bails)&&void 0!==a&&a,label:null==n?void 0:n.label,type:(null==n?void 0:n.type)||"default",value:o,multiple:!1,__flags:{pendingUnmount:{[d]:!1}},fieldsCount:1,validate:null==n?void 0:n.validate,dirty:t.computed((()=>!F(t.unref(o),t.unref(l))))});return m.value.push(c),V.value[s]&&!S[s]&&t.nextTick((()=>{me(s)})),t.isRef(e)&&t.watch(e,(e=>{const n=w(o.value);t.nextTick((()=>{k(v,e,n)}))})),c}const L=U(ge,5),K=U(ge,5),G=R((async e=>"silent"===await e?L():K()),((e,[t])=>{const n=M(ne.errorBag.value);return[...new Set([...M(e.results),...m.value.map((e=>e.path)),...n])].sort().reduce(((n,r)=>{const a=r,i=H(a)||function(e){const t=m.value.filter((t=>e.startsWith(t.path)));return t.reduce(((e,t)=>e?t.path.length>e.path.length?t:e:t),void 0)}(a),l=(e.results[a]||{errors:[]}).errors,u={errors:l,valid:!l.length};return n.results[a]=u,u.valid||(n.errors[a]=u.errors[0]),i&&h.value[a]&&delete h.value[a],i?(i.valid=u.valid,"silent"===t?n:"validated-only"!==t||i.validated?(y(i,u.errors),n):n):(y(a,l),n)}),{valid:e.valid,results:{},errors:{}})}));function X(e){m.value.forEach(e)}function H(e){return"string"==typeof e?m.value.find((t=>t.path===e)):e}let J,Y=[];function Z(e){return function(t,n){return function(r){return r instanceof Event&&(r.preventDefault(),r.stopPropagation()),X((e=>e.touched=!0)),u.value=!0,d.value++,ce().then((a=>{const i=w(v);if(a.valid&&"function"==typeof t){const n=w(x.value);let l=e?n:i;return a.values&&(l=a.values),t(l,{evt:r,controlledValues:n,setErrors:g,setFieldError:y,setTouched:oe,setFieldTouched:ue,setValues:ie,setFieldValue:ae,resetForm:de,resetField:se})}a.valid||"function"!=typeof n||n({values:i,evt:r,errors:a.errors,results:a.results})})).then((e=>(u.value=!1,e)),(e=>{throw u.value=!1,e}))}}}const te=Z(!1);te.withControlled=Z(!0);const ne={formId:a,values:v,controlledValues:x,errorBag:O,errors:V,schema:D,submitCount:d,meta:P,isSubmitting:u,isValidating:s,fieldArrays:c,keepValuesOnUnmount:I,validateSchema:t.unref(D)?G:void 0,validate:ce,setFieldError:y,validateField:me,setFieldValue:ae,setValues:ie,setErrors:g,setFieldTouched:ue,setTouched:oe,resetForm:de,resetField:se,handleSubmit:te,stageInitialValue:function(t,n,r=!1){ye(t,n),k(v,t,n),r&&!(null==e?void 0:e.initialValues)&&k(_.value,t,w(n))},unsetInitialValue:he,setFieldInitialValue:ye,useFieldModel:function(e){if(!Array.isArray(e))return le(e);return e.map(le)},createPathState:q,getPathState:H,unsetPathValue:function(e){return Y.push(e),J||(J=t.nextTick((()=>{[...Y].sort().reverse().forEach((e=>{C(v,e)})),Y=[],J=null}))),J},removePathState:function(e,t){const n=m.value.findIndex((t=>t.path===e)),r=m.value[n];if(-1!==n&&r){if(r.multiple&&r.fieldsCount&&r.fieldsCount--,Array.isArray(r.id)){const e=r.id.indexOf(t);e>=0&&r.id.splice(e,1),delete r.__flags.pendingUnmount[t]}(!r.multiple||r.fieldsCount<=0)&&(m.value.splice(n,1),he(e))}},initialValues:B,getAllPathStates:()=>m.value,markForUnmount:function(e){return X((t=>{t.path.startsWith(e)&&M(t.__flags.pendingUnmount).forEach((e=>{t.__flags.pendingUnmount[e]=!0}))}))}};function ae(e,t){const n=w(t),r="string"==typeof e?e:e.path;H(r)||q(r),k(v,r,n)}function ie(e){l(v,e),c.forEach((e=>e&&e.reset()))}function le(e){const n=H(t.unref(e))||q(e);return t.computed({get:()=>n.value,set(r){const a=t.unref(e);ae(a,r),n.validated=!0,n.pending=!0,me(a).then((()=>{n.pending=!1}))}})}function ue(e,t){const n=H(e);n&&(n.touched=t)}function oe(e){M(e).forEach((t=>{ue(t,!!e[t])}))}function se(e,t){var n;const r=t&&"value"in t?t.value:E(B.value,e);ye(e,w(r)),ae(e,r),ue(e,null!==(n=null==t?void 0:t.touched)&&void 0!==n&&n),y(e,(null==t?void 0:t.errors)||[])}function de(e){const n=(null==e?void 0:e.values)?e.values:_.value;T(n),ie(n),X((t=>{var r;t.validated=!1,t.touched=(null===(r=null==e?void 0:e.touched)||void 0===r?void 0:r[t.path])||!1,ae(t.path,E(n,t.path)),y(t.path,void 0)})),g((null==e?void 0:e.errors)||{}),d.value=(null==e?void 0:e.submitCount)||0,t.nextTick((()=>{ce({mode:"silent"})}))}async function ce(e){const t=(null==e?void 0:e.mode)||"force";if("force"===t&&X((e=>e.validated=!0)),ne.validateSchema)return ne.validateSchema(t);s.value=!0;const n=await Promise.all(m.value.map((t=>t.validate?t.validate(e).then((e=>({key:t.path,valid:e.valid,errors:e.errors}))):Promise.resolve({key:t.path,valid:!0,errors:[]}))));s.value=!1;const r={},a={};for(const e of n)r[e.key]={valid:e.valid,errors:e.errors},e.errors.length&&(a[e.key]=e.errors[0]);return{valid:n.every((e=>e.valid)),results:r,errors:a}}async function me(e){const n=H(e);if(n&&(n.validated=!0),D){const{results:t}=await G("validated-only");return t[e]||{errors:[],valid:!0}}return(null==n?void 0:n.validate)?n.validate():(n||t.warn(`field with path ${e} was not found`),Promise.resolve({errors:[],valid:!0}))}function he(e){C(B.value,e)}function ye(e,t){k(B.value,e,w(t))}async function ge(){const e=t.unref(D);if(!e)return{valid:!0,results:{},errors:{}};s.value=!0;const n=p(e)||f(e)?await async function(e,t){const n=f(e)?e:ee(e),r=await n.parse(t),a={},i={};for(const e of r.errors){const t=e.errors,n=(e.path||"").replace(/\["(\d+)"\]/g,((e,t)=>`[${t}]`));a[n]={valid:!t.length,errors:t},t.length&&(i[n]=t[0])}return{valid:!r.errors.length,results:a,errors:i,values:r.value}}(e,v):await re(e,v,{names:A.value,bailsMap:j.value});return s.value=!1,n}const be=te(((e,{evt:t})=>{b(t)&&t.target.submit()}));return t.onMounted((()=>{(null==e?void 0:e.initialErrors)&&g(e.initialErrors),(null==e?void 0:e.initialTouched)&&oe(e.initialTouched),(null==e?void 0:e.validateOnMount)?ce():ne.validateSchema&&ne.validateSchema("silent")})),t.isRef(D)&&t.watch(D,(()=>{var e;null===(e=ne.validateSchema)||void 0===e||e.call(ne,"validated-only")})),t.provide(o,ne),Object.assign(Object.assign({},ne),{handleReset:()=>de(),submitForm:be,defineComponentBinds:function(e,r){const a=H(N(e))||q(e),i=()=>n(r)?r(z(a,fe)):r||{};function l(){var e;a.touched=!0;(null!==(e=i().validateOnBlur)&&void 0!==e?e:Q().validateOnBlur)&&me(a.path)}function u(e){var t;ae(a.path,e);(null!==(t=i().validateOnModelUpdate)&&void 0!==t?t:Q().validateOnModelUpdate)&&me(a.path)}return t.computed((()=>{const e={modelValue:a.value,"onUpdate:modelValue":u,onBlur:l};return n(r)?Object.assign(Object.assign({},e),r(a).props||{}):(null==r?void 0:r.mapProps)?Object.assign(Object.assign({},e),r.mapProps(z(a,fe))):e}))},defineInputBinds:function(e,r){const a=H(N(e))||q(e),i=()=>n(r)?r(z(a,fe)):r||{};function l(){var e;a.touched=!0;(null!==(e=i().validateOnBlur)&&void 0!==e?e:Q().validateOnBlur)&&me(a.path)}function u(e){var t;const n=W(e);ae(a.path,n);(null!==(t=i().validateOnInput)&&void 0!==t?t:Q().validateOnInput)&&me(a.path)}function o(e){var t;const n=W(e);ae(a.path,n);(null!==(t=i().validateOnChange)&&void 0!==t?t:Q().validateOnChange)&&me(a.path)}return t.computed((()=>{const e={value:a.value,onChange:o,onInput:u,onBlur:l};return n(r)?Object.assign(Object.assign({},e),r(z(a,fe)).attrs||{}):(null==r?void 0:r.mapAttrs)?Object.assign(Object.assign({},e),r.mapAttrs(z(a,fe))):e}))}})}const he=t.defineComponent({name:"Form",inheritAttrs:!1,props:{as:{type:String,default:"form"},validationSchema:{type:Object,default:void 0},initialValues:{type:Object,default:void 0},initialErrors:{type:Object,default:void 0},initialTouched:{type:Object,default:void 0},validateOnMount:{type:Boolean,default:!1},onSubmit:{type:Function,default:void 0},onInvalidSubmit:{type:Function,default:void 0},keepValues:{type:Boolean,default:!1}},setup(e,n){const r=t.toRef(e,"initialValues"),a=t.toRef(e,"validationSchema"),i=t.toRef(e,"keepValues"),{errors:l,errorBag:u,values:o,meta:s,isSubmitting:d,isValidating:c,submitCount:v,controlledValues:f,validate:p,validateField:m,handleReset:h,resetForm:y,handleSubmit:g,setErrors:V,setFieldError:F,setFieldValue:A,setValues:j,setFieldTouched:S,setTouched:E,resetField:k}=me({validationSchema:a.value?a:void 0,initialValues:r,initialErrors:e.initialErrors,initialTouched:e.initialTouched,validateOnMount:e.validateOnMount,keepValuesOnUnmount:i}),I=g(((e,{evt:t})=>{b(t)&&t.target.submit()}),e.onInvalidSubmit),C=e.onSubmit?g(e.onSubmit,e.onInvalidSubmit):I;function M(e){O(e)&&e.preventDefault(),h(),"function"==typeof n.attrs.onReset&&n.attrs.onReset()}function B(t,n){return g("function"!=typeof t||n?n:t,e.onInvalidSubmit)(t)}function _(){return w(o)}function T(){return w(s.value)}function U(){return w(l.value)}function P(){return{meta:s.value,errors:l.value,errorBag:u.value,values:o,isSubmitting:d.value,isValidating:c.value,submitCount:v.value,controlledValues:f.value,validate:p,validateField:m,handleSubmit:B,handleReset:h,submitForm:I,setErrors:V,setFieldError:F,setFieldValue:A,setValues:j,setFieldTouched:S,setTouched:E,resetForm:y,resetField:k,getValues:_,getMeta:T,getErrors:U}}return n.expose({setFieldError:F,setErrors:V,setFieldValue:A,setValues:j,setFieldTouched:S,setTouched:E,resetForm:y,validate:p,validateField:m,resetField:k,getValues:_,getMeta:T,getErrors:U}),function(){const r="form"===e.as?e.as:t.resolveDynamicComponent(e.as),a=q(r,n,P);if(!e.as)return a;const i="form"===e.as?{novalidate:!0}:{};return t.h(r,Object.assign(Object.assign(Object.assign({},i),n.attrs),{onSubmit:C,onReset:M}),a)}}}),ye=he;function ge(e){const n=B(o,void 0),a=t.ref([]),i=()=>{},l={fields:a,remove:i,push:i,swap:i,insert:i,update:i,replace:i,prepend:i,move:i};if(!n)return _("FieldArray requires being a child of `<Form/>` or `useForm` being called before it. Array fields may not work correctly"),l;if(!t.unref(e))return _("FieldArray requires a field path to be provided, did you forget to pass the `name` prop?"),l;const u=n.fieldArrays.find((n=>t.unref(n.path)===t.unref(e)));if(u)return u;let s=0;function d(){return E(null==n?void 0:n.values,t.unref(e),[])||[]}function c(){const e=d();Array.isArray(e)&&(a.value=e.map(((e,t)=>f(e,t,a.value))),v())}function v(){const e=a.value.length;for(let t=0;t<e;t++){const n=a.value[t];n.isFirst=0===t,n.isLast=t===e-1}}function f(i,l,u){if(u&&!r(l)&&u[l])return u[l];const o=s++,d={key:o,value:x({get(){const r=E(null==n?void 0:n.values,t.unref(e),[])||[],l=a.value.findIndex((e=>e.key===o));return-1===l?i:r[l]},set(e){const t=a.value.findIndex((e=>e.key===o));-1!==t?m(t,e):_("Attempting to update a non-existent array item")}}),isFirst:!1,isLast:!1};return d}function p(){v(),null==n||n.validate({mode:"silent"})}function m(r,a){const i=t.unref(e),l=E(null==n?void 0:n.values,i);!Array.isArray(l)||l.length-1<r||(k(n.values,`${i}[${r}]`,a),null==n||n.validate({mode:"validated-only"}))}c();const h={fields:a,remove:function(r){const i=t.unref(e),l=E(null==n?void 0:n.values,i);if(!l||!Array.isArray(l))return;const u=[...l];u.splice(r,1);const o=i+`[${r}]`;n.markForUnmount(o),n.unsetInitialValue(o),k(n.values,i,u),a.value.splice(r,1),p()},push:function(i){const l=t.unref(e),u=E(null==n?void 0:n.values,l),o=r(u)?[]:u;if(!Array.isArray(o))return;const s=[...o];s.push(i),n.stageInitialValue(l+`[${s.length-1}]`,i),k(n.values,l,s),a.value.push(f(i)),p()},swap:function(r,i){const l=t.unref(e),u=E(null==n?void 0:n.values,l);if(!Array.isArray(u)||!(r in u)||!(i in u))return;const o=[...u],s=[...a.value],d=o[r];o[r]=o[i],o[i]=d;const c=s[r];s[r]=s[i],s[i]=c,k(n.values,l,o),a.value=s,v()},insert:function(r,i){const l=t.unref(e),u=E(null==n?void 0:n.values,l);if(!Array.isArray(u)||u.length<r)return;const o=[...u],s=[...a.value];o.splice(r,0,i),s.splice(r,0,f(i)),k(n.values,l,o),a.value=s,p()},update:m,replace:function(r){const a=t.unref(e);n.stageInitialValue(a,r),k(n.values,a,r),c(),p()},prepend:function(i){const l=t.unref(e),u=E(null==n?void 0:n.values,l),o=r(u)?[]:u;if(!Array.isArray(o))return;const s=[i,...o];n.stageInitialValue(l+`[${s.length-1}]`,i),k(n.values,l,s),a.value.unshift(f(i)),p()},move:function(i,l){const u=t.unref(e),o=E(null==n?void 0:n.values,u),s=r(o)?[]:[...o];if(!Array.isArray(o)||!(i in o)||!(l in o))return;const d=[...a.value],c=d[i];d.splice(i,1),d.splice(l,0,c);const v=s[i];s.splice(i,1),s.splice(l,0,v),k(n.values,u,s),a.value=d,p()}};return n.fieldArrays.push(Object.assign({path:e,reset:c},h)),t.onBeforeUnmount((()=>{const r=n.fieldArrays.findIndex((n=>t.unref(n.path)===t.unref(e)));r>=0&&n.fieldArrays.splice(r,1)})),t.watch(d,(e=>{F(e,a.value.map((e=>e.value)))||c()})),h}const be=t.defineComponent({name:"FieldArray",inheritAttrs:!1,props:{name:{type:String,required:!0}},setup(e,n){const{push:r,remove:a,swap:i,insert:l,replace:u,update:o,prepend:s,move:d,fields:c}=ge(t.toRef(e,"name"));function v(){return{fields:c.value,push:r,remove:a,swap:i,insert:l,update:o,replace:u,prepend:s,move:d}}return n.expose({push:r,remove:a,swap:i,insert:l,update:o,replace:u,prepend:s,move:d}),()=>q(void 0,n,v)}}),Oe=t.defineComponent({name:"ErrorMessage",props:{as:{type:String,default:void 0},name:{type:String,required:!0}},setup(e,n){const r=t.inject(o,void 0),a=t.computed((()=>null==r?void 0:r.errors.value[e.name]));function i(){return{message:a.value}}return()=>{if(!a.value)return;const r=e.as?t.resolveDynamicComponent(e.as):e.as,l=q(r,n,i),u=Object.assign({role:"alert"},n.attrs);return r||!Array.isArray(l)&&l||!(null==l?void 0:l.length)?!Array.isArray(l)&&l||(null==l?void 0:l.length)?t.h(r,u,l):t.h(r||"span",u,a.value):l}}});e.ErrorMessage=Oe,e.Field=ce,e.FieldArray=be,e.FieldContextKey=s,e.Form=ye,e.FormContextKey=o,e.IS_ABSENT=d,e.configure=Y,e.defineRule=function(e,t){!function(e,t){if(n(t))return;throw new Error(`Extension Error: The validator '${e}' must be a function.`)}(e,t),u[e]=t},e.useField=le,e.useFieldArray=ge,e.useFieldError=function(e){const n=B(o),r=e?void 0:t.inject(s);return t.computed((()=>e?null==n?void 0:n.errors.value[t.unref(e)]:null==r?void 0:r.errorMessage.value))},e.useFieldValue=function(e){const n=B(o),r=e?void 0:t.inject(s);return t.computed((()=>e?E(null==n?void 0:n.values,t.unref(e)):t.unref(null==r?void 0:r.value)))},e.useForm=me,e.useFormErrors=function(){const e=B(o);return e||_("No vee-validate <Form /> or `useForm` was detected in the component tree"),t.computed((()=>(null==e?void 0:e.errors.value)||{}))},e.useFormValues=function(){const e=B(o);return e||_("No vee-validate <Form /> or `useForm` was detected in the component tree"),t.computed((()=>(null==e?void 0:e.values)||{}))},e.useIsFieldDirty=function(e){const n=D(e);return t.computed((()=>{var e,t;return!!n&&(null!==(t="meta"in n?n.meta.dirty:null===(e=null==n?void 0:n.value)||void 0===e?void 0:e.dirty)&&void 0!==t&&t)}))},e.useIsFieldTouched=function(e){const n=D(e);return t.computed((()=>{var e,t;return!!n&&(null!==(t="meta"in n?n.meta.touched:null===(e=null==n?void 0:n.value)||void 0===e?void 0:e.touched)&&void 0!==t&&t)}))},e.useIsFieldValid=function(e){const n=D(e);return t.computed((()=>{var e,t;return!!n&&(null!==(t="meta"in n?n.meta.valid:null===(e=null==n?void 0:n.value)||void 0===e?void 0:e.valid)&&void 0!==t&&t)}))},e.useIsFormDirty=function(){const e=B(o);return e||_("No vee-validate <Form /> or `useForm` was detected in the component tree"),t.computed((()=>{var t;return null!==(t=null==e?void 0:e.meta.value.dirty)&&void 0!==t&&t}))},e.useIsFormTouched=function(){const e=B(o);return e||_("No vee-validate <Form /> or `useForm` was detected in the component tree"),t.computed((()=>{var t;return null!==(t=null==e?void 0:e.meta.value.touched)&&void 0!==t&&t}))},e.useIsFormValid=function(){const e=B(o);return e||_("No vee-validate <Form /> or `useForm` was detected in the component tree"),t.computed((()=>{var t;return null!==(t=null==e?void 0:e.meta.value.valid)&&void 0!==t&&t}))},e.useIsSubmitting=function(){const e=B(o);return e||_("No vee-validate <Form /> or `useForm` was detected in the component tree"),t.computed((()=>{var t;return null!==(t=null==e?void 0:e.isSubmitting.value)&&void 0!==t&&t}))},e.useIsValidating=function(){const e=B(o);return e||_("No vee-validate <Form /> or `useForm` was detected in the component tree"),t.computed((()=>{var t;return null!==(t=null==e?void 0:e.isValidating.value)&&void 0!==t&&t}))},e.useResetForm=function(){const e=B(o);return e||_("No vee-validate <Form /> or `useForm` was detected in the component tree"),function(t){if(e)return e.resetForm(t)}},e.useSubmitCount=function(){const e=B(o);return e||_("No vee-validate <Form /> or `useForm` was detected in the component tree"),t.computed((()=>{var t;return null!==(t=null==e?void 0:e.submitCount.value)&&void 0!==t?t:0}))},e.useSubmitForm=function(e){const t=B(o);t||_("No vee-validate <Form /> or `useForm` was detected in the component tree");const n=t?t.handleSubmit(e):void 0;return function(e){if(n)return n(e)}},e.useValidateField=function(e){const n=B(o),r=e?void 0:t.inject(s);return function(){return r?r.validate():n&&e?null==n?void 0:n.validateField(t.unref(e)):(_(`field with name ${t.unref(e)} was not found`),Promise.resolve({errors:[],valid:!0}))}},e.useValidateForm=function(){const e=B(o);return e||_("No vee-validate <Form /> or `useForm` was detected in the component tree"),function(){return e?e.validate():Promise.resolve({results:{},errors:{},valid:!0})}},e.validate=Z,e.validateObject=re}));
|
|
6
|
+
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports,require("vue")):"function"==typeof define&&define.amd?define(["exports","vue"],t):t((e="undefined"!=typeof globalThis?globalThis:e||self).VeeValidate={},e.Vue)}(this,(function(e,t){"use strict";function n(e){return"function"==typeof e}function r(e){return null==e}const a=e=>null!==e&&!!e&&"object"==typeof e&&!Array.isArray(e);function l(e){return Number(e)>=0}function i(e){if(!function(e){return"object"==typeof e&&null!==e}(e)||"[object Object]"!==function(e){return null==e?void 0===e?"[object Undefined]":"[object Null]":Object.prototype.toString.call(e)}(e))return!1;if(null===Object.getPrototypeOf(e))return!0;let t=e;for(;null!==Object.getPrototypeOf(t);)t=Object.getPrototypeOf(t);return Object.getPrototypeOf(e)===t}function u(e,t){return Object.keys(t).forEach((n=>{if(i(t[n]))return e[n]||(e[n]={}),void u(e[n],t[n]);e[n]=t[n]})),e}const o={};const s=Symbol("vee-validate-form"),d=Symbol("vee-validate-field-instance"),c=Symbol("Default empty value"),v="undefined"!=typeof window;function f(e){return n(e)&&!!e.__locatorRef}function p(e){return!!e&&n(e.parse)&&"VVTypedSchema"===e.__type}function m(e){return!!e&&n(e.validate)}function h(e){return"checkbox"===e||"radio"===e}function y(e){return/^\[.+\]$/i.test(e)}function g(e){return"SELECT"===e.tagName}function b(e,t){return!function(e,t){const n=![!1,null,void 0,0].includes(t.multiple)&&!Number.isNaN(t.multiple);return"select"===e&&"multiple"in t&&n}(e,t)&&"file"!==t.type&&!h(t.type)}function V(e){return O(e)&&e.target&&"submit"in e.target}function O(e){return!!e&&(!!("undefined"!=typeof Event&&n(Event)&&e instanceof Event)||!(!e||!e.srcElement))}function j(e,t){return t in e&&e[t]!==c}function F(e,t){if(e===t)return!0;if(e&&t&&"object"==typeof e&&"object"==typeof t){if(e.constructor!==t.constructor)return!1;var n,r,a;if(Array.isArray(e)){if((n=e.length)!=t.length)return!1;for(r=n;0!=r--;)if(!F(e[r],t[r]))return!1;return!0}if(e instanceof Map&&t instanceof Map){if(e.size!==t.size)return!1;for(r of e.entries())if(!t.has(r[0]))return!1;for(r of e.entries())if(!F(r[1],t.get(r[0])))return!1;return!0}if(A(e)&&A(t))return e.size===t.size&&(e.name===t.name&&(e.lastModified===t.lastModified&&e.type===t.type));if(e instanceof Set&&t instanceof Set){if(e.size!==t.size)return!1;for(r of e.entries())if(!t.has(r[0]))return!1;return!0}if(ArrayBuffer.isView(e)&&ArrayBuffer.isView(t)){if((n=e.length)!=t.length)return!1;for(r=n;0!=r--;)if(e[r]!==t[r])return!1;return!0}if(e.constructor===RegExp)return e.source===t.source&&e.flags===t.flags;if(e.valueOf!==Object.prototype.valueOf)return e.valueOf()===t.valueOf();if(e.toString!==Object.prototype.toString)return e.toString()===t.toString();if((n=(a=Object.keys(e)).length)!==Object.keys(t).length)return!1;for(r=n;0!=r--;)if(!Object.prototype.hasOwnProperty.call(t,a[r]))return!1;for(r=n;0!=r--;){var l=a[r];if(!F(e[l],t[l]))return!1}return!0}return e!=e&&t!=t}function A(e){return!!v&&e instanceof File}function w(e,t,n){"object"==typeof n.value&&(n.value=S(n.value)),n.enumerable&&!n.get&&!n.set&&n.configurable&&n.writable&&"__proto__"!==t?e[t]=n.value:Object.defineProperty(e,t,n)}function S(e){if("object"!=typeof e)return e;var t,n,r,a=0,l=Object.prototype.toString.call(e);if("[object Object]"===l?r=Object.create(e.__proto__||null):"[object Array]"===l?r=Array(e.length):"[object Set]"===l?(r=new Set,e.forEach((function(e){r.add(S(e))}))):"[object Map]"===l?(r=new Map,e.forEach((function(e,t){r.set(S(t),S(e))}))):"[object Date]"===l?r=new Date(+e):"[object RegExp]"===l?r=new RegExp(e.source,e.flags):"[object DataView]"===l?r=new e.constructor(S(e.buffer)):"[object ArrayBuffer]"===l?r=e.slice(0):"Array]"===l.slice(-6)&&(r=new e.constructor(e)),r){for(n=Object.getOwnPropertySymbols(e);a<n.length;a++)w(r,n[a],Object.getOwnPropertyDescriptor(e,n[a]));for(a=0,n=Object.getOwnPropertyNames(e);a<n.length;a++)Object.hasOwnProperty.call(r,t=n[a])&&r[t]===e[t]||w(r,t,Object.getOwnPropertyDescriptor(e,t))}return r||e}function E(e){return y(e)?e.replace(/\[|\]/gi,""):e}function k(e,t,n){if(!e)return n;if(y(t))return e[E(t)];return(t||"").split(/\.|\[(\d+)\]/).filter(Boolean).reduce(((e,t)=>{return(a(r=e)||Array.isArray(r))&&t in e?e[t]:n;var r}),e)}function I(e,t,n){if(y(t))return void(e[E(t)]=n);const a=t.split(/\.|\[(\d+)\]/).filter(Boolean);let i=e;for(let e=0;e<a.length;e++){if(e===a.length-1)return void(i[a[e]]=n);a[e]in i&&!r(i[a[e]])||(i[a[e]]=l(a[e+1])?[]:{}),i=i[a[e]]}}function M(e,t){Array.isArray(e)&&l(t)?e.splice(Number(t),1):a(e)&&delete e[t]}function C(e,t){if(y(t))return void delete e[E(t)];const n=t.split(/\.|\[(\d+)\]/).filter(Boolean);let l=e;for(let e=0;e<n.length;e++){if(e===n.length-1){M(l,n[e]);break}if(!(n[e]in l)||r(l[n[e]]))break;l=l[n[e]]}const i=n.map(((t,r)=>k(e,n.slice(0,r).join("."))));for(let t=i.length-1;t>=0;t--)u=i[t],(Array.isArray(u)?0===u.length:a(u)&&0===Object.keys(u).length)&&(0!==t?M(i[t-1],n[t-1]):M(e,n[0]));var u}function B(e){return Object.keys(e)}function P(e,n=void 0){const r=t.getCurrentInstance();return(null==r?void 0:r.provides[e])||t.inject(e,n)}function U(e){t.warn(`[vee-validate]: ${e}`)}function _(e,t,n){if(Array.isArray(e)){const n=[...e],r=n.findIndex((e=>F(e,t)));return r>=0?n.splice(r,1):n.push(t),n}return F(e,t)?n:t}function T(e,t=0){let n=null,r=[];return function(...a){return n&&window.clearTimeout(n),n=window.setTimeout((()=>{const t=e(...a);r.forEach((e=>e(t))),r=[]}),t),new Promise((e=>r.push(e)))}}function R(e,t){return a(t)&&t.number?function(e){const t=parseFloat(e);return isNaN(t)?e:t}(e):e}function x(e,t){let n;return async function(...r){const a=e(...r);n=a;const l=await a;return a!==n||(n=void 0,t(l,r)),l}}function N({get:e,set:n}){const r=t.ref(S(e()));return t.watch(e,(e=>{F(e,r.value)||(r.value=S(e))}),{deep:!0}),t.watch(r,(t=>{F(t,e())||n(S(t))}),{deep:!0}),r}function $(e){return Array.isArray(e)?e:e?[e]:[]}function D(e){const n=P(s),r=e?t.computed((()=>null==n?void 0:n.getPathState(t.unref(e)))):void 0,a=e?void 0:t.inject(d);return a||(null==r?void 0:r.value)||U(`field with name ${t.unref(e)} was not found`),r||a}function z(e,t){const n={};for(const r in e)t.includes(r)||(n[r]=e[r]);return n}const q=(e,t,n)=>t.slots.default?"string"!=typeof e&&e?{default:()=>{var e,r;return null===(r=(e=t.slots).default)||void 0===r?void 0:r.call(e,n())}}:t.slots.default(n()):t.slots.default;function L(e){if(K(e))return e._value}function K(e){return"_value"in e}function W(e){if(!O(e))return e;const t=e.target;if(h(t.type)&&K(t))return L(t);if("file"===t.type&&t.files){const e=Array.from(t.files);return t.multiple?e:e[0]}if(g(n=t)&&n.multiple)return Array.from(t.options).filter((e=>e.selected&&!e.disabled)).map(L);var n;if(g(t)){const e=Array.from(t.options).find((e=>e.selected));return e?L(e):t.value}return function(e){return"number"===e.type?e.valueAsNumber:e.value}(t)}function G(e){const t={};return Object.defineProperty(t,"_$$isNormalized",{value:!0,writable:!1,enumerable:!1,configurable:!1}),e?a(e)&&e._$$isNormalized?e:a(e)?Object.keys(e).reduce(((t,n)=>{const r=function(e){if(!0===e)return[];if(Array.isArray(e))return e;if(a(e))return e;return[e]}(e[n]);return!1!==e[n]&&(t[n]=X(r)),t}),t):"string"!=typeof e?t:e.split("|").reduce(((e,t)=>{const n=H(t);return n.name?(e[n.name]=X(n.params),e):e}),t):t}function X(e){const t=e=>"string"==typeof e&&"@"===e[0]?function(e){const t=t=>k(t,e)||t[e];return t.__locatorRef=e,t}(e.slice(1)):e;return Array.isArray(e)?e.map(t):e instanceof RegExp?[e]:Object.keys(e).reduce(((n,r)=>(n[r]=t(e[r]),n)),{})}const H=e=>{let t=[];const n=e.split(":")[0];return e.includes(":")&&(t=e.split(":").slice(1).join(":").split(",")),{name:n,params:t}};let J=Object.assign({},{generateMessage:({field:e})=>`${e} is not valid.`,bails:!0,validateOnBlur:!0,validateOnChange:!0,validateOnInput:!1,validateOnModelUpdate:!0});const Q=()=>J,Y=e=>{J=Object.assign(Object.assign({},J),e)};async function Z(e,t,r={}){const a=null==r?void 0:r.bails,l={name:(null==r?void 0:r.name)||"{field}",rules:t,label:null==r?void 0:r.label,bails:null==a||a,formData:(null==r?void 0:r.values)||{}},i=await async function(e,t){if(p(e.rules)||m(e.rules))return async function(e,t){const n=p(t)?t:ee(t),r=await n.parse(e),a=[];for(const e of r.errors)e.errors.length&&a.push(...e.errors);return{errors:a}}(t,e.rules);if(n(e.rules)||Array.isArray(e.rules)){const n={field:e.label||e.name,name:e.name,label:e.label,form:e.formData,value:t},r=Array.isArray(e.rules)?e.rules:[e.rules],a=r.length,l=[];for(let i=0;i<a;i++){const a=r[i],u=await a(t,n);if(!("string"!=typeof u&&!Array.isArray(u)&&u)){if(Array.isArray(u))l.push(...u);else{const e="string"==typeof u?u:ne(n);l.push(e)}if(e.bails)return{errors:l}}}return{errors:l}}const r=Object.assign(Object.assign({},e),{rules:G(e.rules)}),a=[],l=Object.keys(r.rules),i=l.length;for(let n=0;n<i;n++){const i=l[n],u=await te(r,t,{name:i,params:r.rules[i]});if(u.error&&(a.push(u.error),e.bails))return{errors:a}}return{errors:a}}(l,e),u=i.errors;return{errors:u,valid:!u.length}}function ee(e){return{__type:"VVTypedSchema",async parse(t){var n;try{return{output:await e.validate(t,{abortEarly:!1}),errors:[]}}catch(e){if(!function(e){return!!e&&"ValidationError"===e.name}(e))throw e;if(!(null===(n=e.inner)||void 0===n?void 0:n.length)&&e.errors.length)return{errors:[{path:e.path,errors:e.errors}]};const t=e.inner.reduce(((e,t)=>{const n=t.path||"";return e[n]||(e[n]={errors:[],path:n}),e[n].errors.push(...t.errors),e}),{});return{errors:Object.values(t)}}}}}async function te(e,t,n){const r=(a=n.name,o[a]);var a;if(!r)throw new Error(`No such validator '${n.name}' exists.`);const l=function(e,t){const n=e=>f(e)?e(t):e;if(Array.isArray(e))return e.map(n);return Object.keys(e).reduce(((t,r)=>(t[r]=n(e[r]),t)),{})}(n.params,e.formData),i={field:e.label||e.name,name:e.name,label:e.label,value:t,form:e.formData,rule:Object.assign(Object.assign({},n),{params:l})},u=await r(t,l,i);return"string"==typeof u?{error:u}:{error:u?void 0:ne(i)}}function ne(e){const t=Q().generateMessage;return t?t(e):"Field is invalid"}async function re(e,t,n){const r=B(e).map((async r=>{var a,l,i;const u=null===(a=null==n?void 0:n.names)||void 0===a?void 0:a[r],o=await Z(k(t,r),e[r],{name:(null==u?void 0:u.name)||r,label:null==u?void 0:u.label,values:t,bails:null===(i=null===(l=null==n?void 0:n.bailsMap)||void 0===l?void 0:l[r])||void 0===i||i});return Object.assign(Object.assign({},o),{path:r})}));let a=!0;const l=await Promise.all(r),i={},u={};for(const e of l)i[e.path]={valid:e.valid,errors:e.errors},e.valid||(a=!1,u[e.path]=e.errors[0]);return{valid:a,results:i,errors:u}}let ae=0;function le(e,n){const{value:r,initialValue:a,setInitialValue:l}=function(e,n,r){const a=t.ref(t.unref(n));function l(){return r?k(r.initialValues.value,t.unref(e),t.unref(a)):t.unref(a)}function i(n){r?r.stageInitialValue(t.unref(e),n,!0):a.value=n}const u=t.computed(l);if(!r){return{value:t.ref(l()),initialValue:u,setInitialValue:i}}const o=function(e,n,r,a){if(t.isRef(e))return t.unref(e);if(void 0!==e)return e;return k(n.values,t.unref(a),t.unref(r))}(n,r,u,e);r.stageInitialValue(t.unref(e),o,!0);const s=t.computed({get:()=>k(r.values,t.unref(e)),set(n){r.setFieldValue(t.unref(e),n)}});return{value:s,initialValue:u,setInitialValue:i}}(e,n.modelValue,n.form);if(!n.form){const{errors:o,setErrors:s}=function(){const e=t.ref([]);return{errors:e,setErrors:t=>{e.value=$(t)}}}(),d=ae>=Number.MAX_SAFE_INTEGER?0:++ae,c=function(e,n,r){const a=t.reactive({touched:!1,pending:!1,valid:!0,validated:!!t.unref(r).length,initialValue:t.computed((()=>t.unref(n))),dirty:t.computed((()=>!F(t.unref(e),t.unref(n))))});return t.watch(r,(e=>{a.valid=!e.length}),{immediate:!0,flush:"sync"}),a}(r,a,o);function v(e){var t;"value"in e&&(r.value=e.value),"errors"in e&&s(e.errors),"touched"in e&&(c.touched=null!==(t=e.touched)&&void 0!==t?t:c.touched),"initialValue"in e&&l(e.initialValue)}return{id:d,path:e,value:r,initialValue:a,meta:c,flags:{pendingUnmount:{[d]:!1}},errors:o,setState:v}}const i=n.form.createPathState(e,{bails:n.bails,label:n.label,type:n.type,validate:n.validate}),u=t.computed((()=>i.errors));return{id:Array.isArray(i.id)?i.id[i.id.length-1]:i.id,path:e,value:r,errors:u,meta:i,initialValue:a,flags:i.__flags,setState:function(a){var i,u,o;"value"in a&&(r.value=a.value),"errors"in a&&(null===(i=n.form)||void 0===i||i.setFieldError(t.unref(e),a.errors)),"touched"in a&&(null===(u=n.form)||void 0===u||u.setFieldTouched(t.unref(e),null!==(o=a.touched)&&void 0!==o&&o)),"initialValue"in a&&l(a.initialValue)}}}function ie(e,n,r){return h(null==r?void 0:r.type)?function(e,n,r){const a=(null==r?void 0:r.standalone)?void 0:P(s),l=null==r?void 0:r.checkedValue,i=null==r?void 0:r.uncheckedValue;function u(n){const u=n.handleChange,o=t.computed((()=>{const e=t.unref(n.value),r=t.unref(l);return Array.isArray(e)?e.findIndex((e=>F(e,r)))>=0:F(r,e)}));function s(s,d=!0){var c,v;if(o.value===(null===(c=null==s?void 0:s.target)||void 0===c?void 0:c.checked))return void(d&&n.validate());const f=t.toValue(e),p=null==a?void 0:a.getPathState(f),m=W(s);let h=null!==(v=t.unref(l))&&void 0!==v?v:m;a&&(null==p?void 0:p.multiple)&&"checkbox"===p.type?h=_(k(a.values,f)||[],h,void 0):"checkbox"===(null==r?void 0:r.type)&&(h=_(t.unref(n.value),h,t.unref(i))),u(h,d)}return Object.assign(Object.assign({},n),{checked:o,checkedValue:l,uncheckedValue:i,handleChange:s})}return u(ue(e,n,r))}(e,n,r):ue(e,n,r)}function ue(e,r,a){const{initialValue:l,validateOnMount:i,bails:u,type:o,checkedValue:v,label:h,validateOnValueUpdate:y,uncheckedValue:g,controlled:b,keepValueOnUnmount:V,syncVModel:O,form:j}=function(e){const n=()=>({initialValue:void 0,validateOnMount:!1,bails:!0,label:void 0,validateOnValueUpdate:!0,keepValueOnUnmount:void 0,syncVModel:!1,controlled:!0}),r=!!(null==e?void 0:e.syncVModel),a="string"==typeof(null==e?void 0:e.syncVModel)?e.syncVModel:(null==e?void 0:e.modelPropName)||"modelValue",l=r&&!("initialValue"in(e||{}))?oe(t.getCurrentInstance(),a):null==e?void 0:e.initialValue;if(!e)return Object.assign(Object.assign({},n()),{initialValue:l});const i="valueProp"in e?e.valueProp:e.checkedValue,u="standalone"in e?!e.standalone:e.controlled,o=(null==e?void 0:e.modelPropName)||(null==e?void 0:e.syncVModel)||!1;return Object.assign(Object.assign(Object.assign({},n()),e||{}),{initialValue:l,controlled:null==u||u,checkedValue:i,syncVModel:o})}(a),A=b?P(s):void 0,w=j||A,E=function(e){return t.computed((()=>t.toValue(e)))}(e),I=t.computed((()=>{if(t.unref(null==w?void 0:w.schema))return;const e=t.unref(r);return m(e)||p(e)||n(e)||Array.isArray(e)?e:G(e)})),{id:M,value:C,initialValue:U,meta:_,setState:T,errors:N,flags:$}=le(E,{modelValue:l,form:w,bails:u,label:h,type:o,validate:I.value?K:void 0}),D=t.computed((()=>N.value[0]));O&&function({prop:e,value:n,handleChange:r}){const a=t.getCurrentInstance();if(!a||!e)return;const l="string"==typeof e?e:"modelValue",i=`update:${l}`;if(!(l in a.props))return;t.watch(n,(e=>{F(e,oe(a,l))||a.emit(i,e)})),t.watch((()=>oe(a,l)),(e=>{if(e===c&&void 0===n.value)return;const t=e===c?void 0:e;F(t,R(n.value,a.props.modelModifiers))||r(t)}))}({value:C,prop:O,handleChange:X});async function z(e){var n,r;return(null==w?void 0:w.validateSchema)?null!==(n=(await w.validateSchema(e)).results[t.unref(E)])&&void 0!==n?n:{valid:!0,errors:[]}:I.value?Z(C.value,I.value,{name:t.unref(E),label:t.unref(h),values:null!==(r=null==w?void 0:w.values)&&void 0!==r?r:{},bails:u}):{valid:!0,errors:[]}}const q=x((async()=>(_.pending=!0,_.validated=!0,z("validated-only"))),(e=>{if(!$.pendingUnmount[Y.id])return T({errors:e.errors}),_.pending=!1,_.valid=e.valid,e})),L=x((async()=>z("silent")),(e=>(_.valid=e.valid,e)));function K(e){return"silent"===(null==e?void 0:e.mode)?L():q()}function X(e,t=!0){J(W(e),t)}function H(e){var t;const n=e&&"value"in e?e.value:U.value;T({value:S(n),initialValue:S(n),touched:null!==(t=null==e?void 0:e.touched)&&void 0!==t&&t,errors:(null==e?void 0:e.errors)||[]}),_.pending=!1,_.validated=!1,L()}function J(e,t=!0){C.value=e;(t?q:L)()}t.onMounted((()=>{if(i)return q();w&&w.validateSchema||L()}));const Q=t.computed({get:()=>C.value,set(e){J(e,y)}}),Y={id:M,name:E,label:h,value:Q,meta:_,errors:N,errorMessage:D,type:o,checkedValue:v,uncheckedValue:g,bails:u,keepValueOnUnmount:V,resetField:H,handleReset:()=>H(),validate:K,handleChange:X,handleBlur:(e,t=!1)=>{_.touched=!0,t&&q()},setState:T,setTouched:function(e){_.touched=e},setErrors:function(e){T({errors:Array.isArray(e)?e:[e]})},setValue:J};if(t.provide(d,Y),t.isRef(r)&&"function"!=typeof t.unref(r)&&t.watch(r,((e,t)=>{F(e,t)||(_.validated?q():L())}),{deep:!0}),!w)return Y;const ee=t.computed((()=>{const e=I.value;return!e||n(e)||m(e)||p(e)||Array.isArray(e)?{}:Object.keys(e).reduce(((t,n)=>{const r=(a=e[n],Array.isArray(a)?a.filter(f):B(a).filter((e=>f(a[e]))).map((e=>a[e]))).map((e=>e.__locatorRef)).reduce(((e,t)=>{const n=k(w.values,t)||w.values[t];return void 0!==n&&(e[t]=n),e}),{});var a;return Object.assign(t,r),t}),{})}));return t.watch(ee,((e,t)=>{if(!Object.keys(e).length)return;!F(e,t)&&(_.validated?q():L())})),t.onBeforeUnmount((()=>{var e;const n=null!==(e=t.unref(Y.keepValueOnUnmount))&&void 0!==e?e:t.unref(w.keepValuesOnUnmount),r=t.toValue(E);if(n||!w||$.pendingUnmount[Y.id])return void(null==w||w.removePathState(r,M));$.pendingUnmount[Y.id]=!0;const a=w.getPathState(r);if(Array.isArray(null==a?void 0:a.id)&&(null==a?void 0:a.multiple)?null==a?void 0:a.id.includes(Y.id):(null==a?void 0:a.id)===Y.id){if((null==a?void 0:a.multiple)&&Array.isArray(a.value)){const e=a.value.findIndex((e=>F(e,t.unref(Y.checkedValue))));if(e>-1){const t=[...a.value];t.splice(e,1),w.setFieldValue(r,t)}Array.isArray(a.id)&&a.id.splice(a.id.indexOf(Y.id),1)}else w.unsetPathValue(t.toValue(E));w.removePathState(r,M)}})),Y}function oe(e,t){if(e)return e.props[t]}function se(e,t){let n=e.as||"";return e.as||t.slots.default||(n="input"),n}function de(e,t){return h(t.attrs.type)?j(e,"modelValue")?e.modelValue:void 0:j(e,"modelValue")?e.modelValue:t.attrs.value}const ce=t.defineComponent({name:"Field",inheritAttrs:!1,props:{as:{type:[String,Object],default:void 0},name:{type:String,required:!0},rules:{type:[Object,String,Function],default:void 0},validateOnMount:{type:Boolean,default:!1},validateOnBlur:{type:Boolean,default:void 0},validateOnChange:{type:Boolean,default:void 0},validateOnInput:{type:Boolean,default:void 0},validateOnModelUpdate:{type:Boolean,default:void 0},bails:{type:Boolean,default:()=>Q().bails},label:{type:String,default:void 0},uncheckedValue:{type:null,default:void 0},modelValue:{type:null,default:c},modelModifiers:{type:null,default:()=>({})},"onUpdate:modelValue":{type:null,default:void 0},standalone:{type:Boolean,default:!1},keepValue:{type:Boolean,default:void 0}},setup(e,r){const a=t.toRef(e,"rules"),l=t.toRef(e,"name"),i=t.toRef(e,"label"),u=t.toRef(e,"uncheckedValue"),o=t.toRef(e,"keepValue"),{errors:s,value:d,errorMessage:c,validate:v,handleChange:f,handleBlur:p,setTouched:m,resetField:y,handleReset:g,meta:V,checked:O,setErrors:j}=ie(l,a,{validateOnMount:e.validateOnMount,bails:e.bails,standalone:e.standalone,type:r.attrs.type,initialValue:de(e,r),checkedValue:r.attrs.value,uncheckedValue:u,label:i,validateOnValueUpdate:!1,keepValueOnUnmount:o,syncVModel:!0}),F=function(e,t=!0){f(e,t),r.emit("update:modelValue",d.value)},A=t.computed((()=>{const{validateOnInput:t,validateOnChange:a,validateOnBlur:l,validateOnModelUpdate:i}=function(e){var t,n,r,a;const{validateOnInput:l,validateOnChange:i,validateOnBlur:u,validateOnModelUpdate:o}=Q();return{validateOnInput:null!==(t=e.validateOnInput)&&void 0!==t?t:l,validateOnChange:null!==(n=e.validateOnChange)&&void 0!==n?n:i,validateOnBlur:null!==(r=e.validateOnBlur)&&void 0!==r?r:u,validateOnModelUpdate:null!==(a=e.validateOnModelUpdate)&&void 0!==a?a:o}}(e);const u={name:e.name,onBlur:function(e){p(e,l),n(r.attrs.onBlur)&&r.attrs.onBlur(e)},onInput:function(e){F(e,t),n(r.attrs.onInput)&&r.attrs.onInput(e)},onChange:function(e){F(e,a),n(r.attrs.onChange)&&r.attrs.onChange(e)},"onUpdate:modelValue":e=>F(e,i)};return u})),w=t.computed((()=>{const t=Object.assign({},A.value);h(r.attrs.type)&&O&&(t.checked=O.value);return b(se(e,r),r.attrs)&&(t.value=d.value),t})),S=t.computed((()=>Object.assign(Object.assign({},A.value),{modelValue:d.value})));function E(){return{field:w.value,componentField:S.value,value:d.value,meta:V,errors:s.value,errorMessage:c.value,validate:v,resetField:y,handleChange:F,handleInput:e=>F(e,!1),handleReset:g,handleBlur:A.value.onBlur,setTouched:m,setErrors:j}}return r.expose({setErrors:j,setTouched:m,reset:y,validate:v,handleChange:f}),()=>{const n=t.resolveDynamicComponent(se(e,r)),a=q(n,r,E);return n?t.h(n,Object.assign(Object.assign({},r.attrs),w.value),a):a}}});let ve=0;const fe=["bails","fieldsCount","id","multiple","type","validate"];function pe(e){const r=t.unref(null==e?void 0:e.initialValues)||{},a=t.unref(null==e?void 0:e.validationSchema);return a&&p(a)&&n(a.cast)?S(a.cast(r)||{}):S(r)}function me(e){var r;const a=ve++;let l=0;const i=t.ref(!1),o=t.ref(!1),d=t.ref(0),c=[],v=t.reactive(pe(e)),f=t.ref([]),h=t.ref({});function y(e,t){const n=X(e);n?(n.errors=$(t),n.valid=!n.errors.length):"string"==typeof e&&(h.value[e]=$(t))}function g(e){B(e).forEach((t=>{y(t,e[t])}))}(null==e?void 0:e.initialErrors)&&g(e.initialErrors);const b=t.computed((()=>{const e=f.value.reduce(((e,t)=>(t.errors.length&&(e[t.path]=t.errors),e)),{});return Object.assign(Object.assign({},h.value),e)})),O=t.computed((()=>B(b.value).reduce(((e,t)=>{const n=b.value[t];return(null==n?void 0:n.length)&&(e[t]=n[0]),e}),{}))),j=t.computed((()=>f.value.reduce(((e,t)=>(e[t.path]={name:t.path||"",label:t.label||""},e)),{}))),A=t.computed((()=>f.value.reduce(((e,t)=>{var n;return e[t.path]=null===(n=t.bails)||void 0===n||n,e}),{}))),w=Object.assign({},(null==e?void 0:e.initialErrors)||{}),E=null!==(r=null==e?void 0:e.keepValuesOnUnmount)&&void 0!==r&&r,{initialValues:M,originalInitialValues:P,setInitialValues:U}=function(e,n,r){const a=pe(r),l=null==r?void 0:r.initialValues,i=t.ref(a),o=t.ref(S(a));function s(t,r=!1){i.value=u(S(i.value)||{},S(t)),o.value=u(S(o.value)||{},S(t)),r&&e.value.forEach((e=>{if(e.touched)return;const t=k(i.value,e.path);I(n,e.path,S(t))}))}t.isRef(l)&&t.watch(l,(e=>{e&&s(e,!0)}),{deep:!0});return{initialValues:i,originalInitialValues:o,setInitialValues:s}}(f,v,e),_=function(e,n,r,a){const l={touched:"some",pending:"some",valid:"every"},i=t.computed((()=>!F(n,t.unref(r))));function u(){const t=e.value;return B(l).reduce(((e,n)=>{const r=l[n];return e[n]=t[r]((e=>e[n])),e}),{})}const o=t.reactive(u());return t.watchEffect((()=>{const e=u();o.touched=e.touched,o.valid=e.valid,o.pending=e.pending})),t.computed((()=>Object.assign(Object.assign({initialValues:t.unref(r)},o),{valid:o.valid&&!B(a.value).length,dirty:i.value})))}(f,v,P,O),R=t.computed((()=>f.value.reduce(((e,t)=>{const n=k(v,t.path);return I(e,t.path,n),e}),{}))),N=null==e?void 0:e.validationSchema;function D(e,n){var r,a;const i=t.computed((()=>k(M.value,t.toValue(e)))),u=f.value.find((n=>n.path===t.unref(e)));if(u){"checkbox"!==(null==n?void 0:n.type)&&"radio"!==(null==n?void 0:n.type)||(u.multiple=!0);const e=l++;return Array.isArray(u.id)?u.id.push(e):u.id=[u.id,e],u.fieldsCount++,u.__flags.pendingUnmount[e]=!1,u}const o=t.computed((()=>k(v,t.toValue(e)))),s=t.toValue(e),d=l++,c=t.reactive({id:d,path:e,touched:!1,pending:!1,valid:!0,validated:!!(null===(r=w[s])||void 0===r?void 0:r.length),initialValue:i,errors:t.shallowRef([]),bails:null!==(a=null==n?void 0:n.bails)&&void 0!==a&&a,label:null==n?void 0:n.label,type:(null==n?void 0:n.type)||"default",value:o,multiple:!1,__flags:{pendingUnmount:{[d]:!1}},fieldsCount:1,validate:null==n?void 0:n.validate,dirty:t.computed((()=>!F(t.unref(o),t.unref(i))))});return f.value.push(c),O.value[s]&&!w[s]&&t.nextTick((()=>{ce(s)})),t.isRef(e)&&t.watch(e,(e=>{const n=S(o.value);t.nextTick((()=>{I(v,e,n)}))})),c}const q=T(ye,5),L=T(ye,5),K=x((async e=>"silent"===await e?q():L()),((e,[t])=>{const n=B(te.errorBag.value);return[...new Set([...B(e.results),...f.value.map((e=>e.path)),...n])].sort().reduce(((n,r)=>{const a=r,l=X(a)||function(e){const t=f.value.filter((t=>e.startsWith(t.path)));return t.reduce(((e,t)=>e?t.path.length>e.path.length?t:e:t),void 0)}(a),i=(e.results[a]||{errors:[]}).errors,u={errors:i,valid:!i.length};return n.results[a]=u,u.valid||(n.errors[a]=u.errors[0]),l&&h.value[a]&&delete h.value[a],l?(l.valid=u.valid,"silent"===t?n:"validated-only"!==t||l.validated?(y(l,u.errors),n):n):(y(a,i),n)}),{valid:e.valid,results:{},errors:{}})}));function G(e){f.value.forEach(e)}function X(e){return"string"==typeof e?f.value.find((t=>t.path===e)):e}let H,J=[];function Y(e){return function(t,n){return function(r){return r instanceof Event&&(r.preventDefault(),r.stopPropagation()),G((e=>e.touched=!0)),i.value=!0,d.value++,de().then((a=>{const l=S(v);if(a.valid&&"function"==typeof t){const n=S(R.value);let i=e?n:l;return a.values&&(i=a.values),t(i,{evt:r,controlledValues:n,setErrors:g,setFieldError:y,setTouched:ue,setFieldTouched:ie,setValues:ae,setFieldValue:ne,resetForm:se,resetField:oe})}a.valid||"function"!=typeof n||n({values:l,evt:r,errors:a.errors,results:a.results})})).then((e=>(i.value=!1,e)),(e=>{throw i.value=!1,e}))}}}const Z=Y(!1);Z.withControlled=Y(!0);const te={formId:a,values:v,controlledValues:R,errorBag:b,errors:O,schema:N,submitCount:d,meta:_,isSubmitting:i,isValidating:o,fieldArrays:c,keepValuesOnUnmount:E,validateSchema:t.unref(N)?K:void 0,validate:de,setFieldError:y,validateField:ce,setFieldValue:ne,setValues:ae,setErrors:g,setFieldTouched:ie,setTouched:ue,resetForm:se,resetField:oe,handleSubmit:Z,stageInitialValue:function(t,n,r=!1){he(t,n),I(v,t,n),r&&!(null==e?void 0:e.initialValues)&&I(P.value,t,S(n))},unsetInitialValue:me,setFieldInitialValue:he,useFieldModel:function(e){if(!Array.isArray(e))return le(e);return e.map(le)},createPathState:D,getPathState:X,unsetPathValue:function(e){return J.push(e),H||(H=t.nextTick((()=>{[...J].sort().reverse().forEach((e=>{C(v,e)})),J=[],H=null}))),H},removePathState:function(e,t){const n=f.value.findIndex((t=>t.path===e)),r=f.value[n];if(-1!==n&&r){if(r.multiple&&r.fieldsCount&&r.fieldsCount--,Array.isArray(r.id)){const e=r.id.indexOf(t);e>=0&&r.id.splice(e,1),delete r.__flags.pendingUnmount[t]}(!r.multiple||r.fieldsCount<=0)&&(f.value.splice(n,1),me(e))}},initialValues:M,getAllPathStates:()=>f.value,markForUnmount:function(e){return G((t=>{t.path.startsWith(e)&&B(t.__flags.pendingUnmount).forEach((e=>{t.__flags.pendingUnmount[e]=!0}))}))}};function ne(e,t,n=!0){const r=S(t),a="string"==typeof e?e:e.path;X(a)||D(a),I(v,a,r),n&&ce(a)}function ae(e){u(v,e),c.forEach((e=>e&&e.reset()))}function le(e){const n=X(t.unref(e))||D(e);return t.computed({get:()=>n.value,set(r){const a=t.unref(e);ne(a,r,!1),n.validated=!0,n.pending=!0,ce(a).then((()=>{n.pending=!1}))}})}function ie(e,t){const n=X(e);n&&(n.touched=t)}function ue(e){B(e).forEach((t=>{ie(t,!!e[t])}))}function oe(e,t){var n;const r=t&&"value"in t?t.value:k(M.value,e);he(e,S(r)),ne(e,r,!1),ie(e,null!==(n=null==t?void 0:t.touched)&&void 0!==n&&n),y(e,(null==t?void 0:t.errors)||[])}function se(e){const n=(null==e?void 0:e.values)?e.values:P.value;U(n),ae(n),G((t=>{var r;t.validated=!1,t.touched=(null===(r=null==e?void 0:e.touched)||void 0===r?void 0:r[t.path])||!1,ne(t.path,k(n,t.path),!1),y(t.path,void 0)})),g((null==e?void 0:e.errors)||{}),d.value=(null==e?void 0:e.submitCount)||0,t.nextTick((()=>{de({mode:"silent"})}))}async function de(e){const t=(null==e?void 0:e.mode)||"force";if("force"===t&&G((e=>e.validated=!0)),te.validateSchema)return te.validateSchema(t);o.value=!0;const n=await Promise.all(f.value.map((t=>t.validate?t.validate(e).then((e=>({key:t.path,valid:e.valid,errors:e.errors}))):Promise.resolve({key:t.path,valid:!0,errors:[]}))));o.value=!1;const r={},a={};for(const e of n)r[e.key]={valid:e.valid,errors:e.errors},e.errors.length&&(a[e.key]=e.errors[0]);return{valid:n.every((e=>e.valid)),results:r,errors:a}}async function ce(e){const n=X(e);if(n&&(n.validated=!0),N){const{results:t}=await K("validated-only");return t[e]||{errors:[],valid:!0}}return(null==n?void 0:n.validate)?n.validate():(n||t.warn(`field with path ${e} was not found`),Promise.resolve({errors:[],valid:!0}))}function me(e){C(M.value,e)}function he(e,t){I(M.value,e,S(t))}async function ye(){const e=t.unref(N);if(!e)return{valid:!0,results:{},errors:{}};o.value=!0;const n=m(e)||p(e)?await async function(e,t){const n=p(e)?e:ee(e),r=await n.parse(t),a={},l={};for(const e of r.errors){const t=e.errors,n=(e.path||"").replace(/\["(\d+)"\]/g,((e,t)=>`[${t}]`));a[n]={valid:!t.length,errors:t},t.length&&(l[n]=t[0])}return{valid:!r.errors.length,results:a,errors:l,values:r.value}}(e,v):await re(e,v,{names:j.value,bailsMap:A.value});return o.value=!1,n}const ge=Z(((e,{evt:t})=>{V(t)&&t.target.submit()}));return t.onMounted((()=>{(null==e?void 0:e.initialErrors)&&g(e.initialErrors),(null==e?void 0:e.initialTouched)&&ue(e.initialTouched),(null==e?void 0:e.validateOnMount)?de():te.validateSchema&&te.validateSchema("silent")})),t.isRef(N)&&t.watch(N,(()=>{var e;null===(e=te.validateSchema)||void 0===e||e.call(te,"validated-only")})),t.provide(s,te),Object.assign(Object.assign({},te),{values:t.readonly(v),handleReset:()=>se(),submitForm:ge,defineComponentBinds:function(e,r){const a=X(t.toValue(e))||D(e),l=()=>n(r)?r(z(a,fe)):r||{};function i(){var e;a.touched=!0;(null!==(e=l().validateOnBlur)&&void 0!==e?e:Q().validateOnBlur)&&ce(a.path)}function u(e){var t;ne(a.path,e);(null!==(t=l().validateOnModelUpdate)&&void 0!==t?t:Q().validateOnModelUpdate)&&ce(a.path)}return t.computed((()=>{if(n(r)){const e=r(a),t=e.model||"modelValue";return Object.assign({onBlur:i,[t]:a.value,[`onUpdate:${t}`]:u},e.props||{})}const e=(null==r?void 0:r.model)||"modelValue",t={[e]:a.value,[`onUpdate:${e}`]:u};return(null==r?void 0:r.mapProps)?Object.assign(Object.assign({onBlur:i},t),r.mapProps(z(a,fe))):t}))},defineInputBinds:function(e,r){const a=X(t.toValue(e))||D(e),l=()=>n(r)?r(z(a,fe)):r||{};function i(){var e;a.touched=!0;(null!==(e=l().validateOnBlur)&&void 0!==e?e:Q().validateOnBlur)&&ce(a.path)}function u(e){var t;const n=W(e);ne(a.path,n);(null!==(t=l().validateOnInput)&&void 0!==t?t:Q().validateOnInput)&&ce(a.path)}function o(e){var t;const n=W(e);ne(a.path,n);(null!==(t=l().validateOnChange)&&void 0!==t?t:Q().validateOnChange)&&ce(a.path)}return t.computed((()=>{const e={value:a.value,onChange:o,onInput:u,onBlur:i};return n(r)?Object.assign(Object.assign({},e),r(z(a,fe)).attrs||{}):(null==r?void 0:r.mapAttrs)?Object.assign(Object.assign({},e),r.mapAttrs(z(a,fe))):e}))}})}const he=t.defineComponent({name:"Form",inheritAttrs:!1,props:{as:{type:String,default:"form"},validationSchema:{type:Object,default:void 0},initialValues:{type:Object,default:void 0},initialErrors:{type:Object,default:void 0},initialTouched:{type:Object,default:void 0},validateOnMount:{type:Boolean,default:!1},onSubmit:{type:Function,default:void 0},onInvalidSubmit:{type:Function,default:void 0},keepValues:{type:Boolean,default:!1}},setup(e,n){const r=t.toRef(e,"initialValues"),a=t.toRef(e,"validationSchema"),l=t.toRef(e,"keepValues"),{errors:i,errorBag:u,values:o,meta:s,isSubmitting:d,isValidating:c,submitCount:v,controlledValues:f,validate:p,validateField:m,handleReset:h,resetForm:y,handleSubmit:g,setErrors:b,setFieldError:j,setFieldValue:F,setValues:A,setFieldTouched:w,setTouched:E,resetField:k}=me({validationSchema:a.value?a:void 0,initialValues:r,initialErrors:e.initialErrors,initialTouched:e.initialTouched,validateOnMount:e.validateOnMount,keepValuesOnUnmount:l}),I=g(((e,{evt:t})=>{V(t)&&t.target.submit()}),e.onInvalidSubmit),M=e.onSubmit?g(e.onSubmit,e.onInvalidSubmit):I;function C(e){O(e)&&e.preventDefault(),h(),"function"==typeof n.attrs.onReset&&n.attrs.onReset()}function B(t,n){return g("function"!=typeof t||n?n:t,e.onInvalidSubmit)(t)}function P(){return S(o)}function U(){return S(s.value)}function _(){return S(i.value)}function T(){return{meta:s.value,errors:i.value,errorBag:u.value,values:o,isSubmitting:d.value,isValidating:c.value,submitCount:v.value,controlledValues:f.value,validate:p,validateField:m,handleSubmit:B,handleReset:h,submitForm:I,setErrors:b,setFieldError:j,setFieldValue:F,setValues:A,setFieldTouched:w,setTouched:E,resetForm:y,resetField:k,getValues:P,getMeta:U,getErrors:_}}return n.expose({setFieldError:j,setErrors:b,setFieldValue:F,setValues:A,setFieldTouched:w,setTouched:E,resetForm:y,validate:p,validateField:m,resetField:k,getValues:P,getMeta:U,getErrors:_}),function(){const r="form"===e.as?e.as:t.resolveDynamicComponent(e.as),a=q(r,n,T);if(!e.as)return a;const l="form"===e.as?{novalidate:!0}:{};return t.h(r,Object.assign(Object.assign(Object.assign({},l),n.attrs),{onSubmit:M,onReset:C}),a)}}}),ye=he;function ge(e){const n=P(s,void 0),a=t.ref([]),l=()=>{},i={fields:a,remove:l,push:l,swap:l,insert:l,update:l,replace:l,prepend:l,move:l};if(!n)return U("FieldArray requires being a child of `<Form/>` or `useForm` being called before it. Array fields may not work correctly"),i;if(!t.unref(e))return U("FieldArray requires a field path to be provided, did you forget to pass the `name` prop?"),i;const u=n.fieldArrays.find((n=>t.unref(n.path)===t.unref(e)));if(u)return u;let o=0;function d(){return k(null==n?void 0:n.values,t.unref(e),[])||[]}function c(){const e=d();Array.isArray(e)&&(a.value=e.map(((e,t)=>f(e,t,a.value))),v())}function v(){const e=a.value.length;for(let t=0;t<e;t++){const n=a.value[t];n.isFirst=0===t,n.isLast=t===e-1}}function f(l,i,u){if(u&&!r(i)&&u[i])return u[i];const s=o++,d={key:s,value:N({get(){const r=k(null==n?void 0:n.values,t.unref(e),[])||[],i=a.value.findIndex((e=>e.key===s));return-1===i?l:r[i]},set(e){const t=a.value.findIndex((e=>e.key===s));-1!==t?m(t,e):U("Attempting to update a non-existent array item")}}),isFirst:!1,isLast:!1};return d}function p(){v(),null==n||n.validate({mode:"silent"})}function m(r,a){const l=t.unref(e),i=k(null==n?void 0:n.values,l);!Array.isArray(i)||i.length-1<r||(I(n.values,`${l}[${r}]`,a),null==n||n.validate({mode:"validated-only"}))}c();const h={fields:a,remove:function(r){const l=t.unref(e),i=k(null==n?void 0:n.values,l);if(!i||!Array.isArray(i))return;const u=[...i];u.splice(r,1);const o=l+`[${r}]`;n.markForUnmount(o),n.unsetInitialValue(o),I(n.values,l,u),a.value.splice(r,1),p()},push:function(l){const i=t.unref(e),u=k(null==n?void 0:n.values,i),o=r(u)?[]:u;if(!Array.isArray(o))return;const s=[...o];s.push(l),n.stageInitialValue(i+`[${s.length-1}]`,l),I(n.values,i,s),a.value.push(f(l)),p()},swap:function(r,l){const i=t.unref(e),u=k(null==n?void 0:n.values,i);if(!Array.isArray(u)||!(r in u)||!(l in u))return;const o=[...u],s=[...a.value],d=o[r];o[r]=o[l],o[l]=d;const c=s[r];s[r]=s[l],s[l]=c,I(n.values,i,o),a.value=s,v()},insert:function(r,l){const i=t.unref(e),u=k(null==n?void 0:n.values,i);if(!Array.isArray(u)||u.length<r)return;const o=[...u],s=[...a.value];o.splice(r,0,l),s.splice(r,0,f(l)),I(n.values,i,o),a.value=s,p()},update:m,replace:function(r){const a=t.unref(e);n.stageInitialValue(a,r),I(n.values,a,r),c(),p()},prepend:function(l){const i=t.unref(e),u=k(null==n?void 0:n.values,i),o=r(u)?[]:u;if(!Array.isArray(o))return;const s=[l,...o];n.stageInitialValue(i+`[${s.length-1}]`,l),I(n.values,i,s),a.value.unshift(f(l)),p()},move:function(l,i){const u=t.unref(e),o=k(null==n?void 0:n.values,u),s=r(o)?[]:[...o];if(!Array.isArray(o)||!(l in o)||!(i in o))return;const d=[...a.value],c=d[l];d.splice(l,1),d.splice(i,0,c);const v=s[l];s.splice(l,1),s.splice(i,0,v),I(n.values,u,s),a.value=d,p()}};return n.fieldArrays.push(Object.assign({path:e,reset:c},h)),t.onBeforeUnmount((()=>{const r=n.fieldArrays.findIndex((n=>t.unref(n.path)===t.unref(e)));r>=0&&n.fieldArrays.splice(r,1)})),t.watch(d,(e=>{F(e,a.value.map((e=>e.value)))||c()})),h}const be=t.defineComponent({name:"FieldArray",inheritAttrs:!1,props:{name:{type:String,required:!0}},setup(e,n){const{push:r,remove:a,swap:l,insert:i,replace:u,update:o,prepend:s,move:d,fields:c}=ge(t.toRef(e,"name"));function v(){return{fields:c.value,push:r,remove:a,swap:l,insert:i,update:o,replace:u,prepend:s,move:d}}return n.expose({push:r,remove:a,swap:l,insert:i,update:o,replace:u,prepend:s,move:d}),()=>q(void 0,n,v)}}),Ve=t.defineComponent({name:"ErrorMessage",props:{as:{type:String,default:void 0},name:{type:String,required:!0}},setup(e,n){const r=t.inject(s,void 0),a=t.computed((()=>null==r?void 0:r.errors.value[e.name]));function l(){return{message:a.value}}return()=>{if(!a.value)return;const r=e.as?t.resolveDynamicComponent(e.as):e.as,i=q(r,n,l),u=Object.assign({role:"alert"},n.attrs);return r||!Array.isArray(i)&&i||!(null==i?void 0:i.length)?!Array.isArray(i)&&i||(null==i?void 0:i.length)?t.h(r,u,i):t.h(r||"span",u,a.value):i}}});e.ErrorMessage=Ve,e.Field=ce,e.FieldArray=be,e.FieldContextKey=d,e.Form=ye,e.FormContextKey=s,e.IS_ABSENT=c,e.configure=Y,e.defineRule=function(e,t){!function(e,t){if(n(t))return;throw new Error(`Extension Error: The validator '${e}' must be a function.`)}(e,t),o[e]=t},e.useField=ie,e.useFieldArray=ge,e.useFieldError=function(e){const n=P(s),r=e?void 0:t.inject(d);return t.computed((()=>e?null==n?void 0:n.errors.value[t.unref(e)]:null==r?void 0:r.errorMessage.value))},e.useFieldValue=function(e){const n=P(s),r=e?void 0:t.inject(d);return t.computed((()=>e?k(null==n?void 0:n.values,t.unref(e)):t.unref(null==r?void 0:r.value)))},e.useForm=me,e.useFormErrors=function(){const e=P(s);return e||U("No vee-validate <Form /> or `useForm` was detected in the component tree"),t.computed((()=>(null==e?void 0:e.errors.value)||{}))},e.useFormValues=function(){const e=P(s);return e||U("No vee-validate <Form /> or `useForm` was detected in the component tree"),t.computed((()=>(null==e?void 0:e.values)||{}))},e.useIsFieldDirty=function(e){const n=D(e);return t.computed((()=>{var e,t;return!!n&&(null!==(t="meta"in n?n.meta.dirty:null===(e=null==n?void 0:n.value)||void 0===e?void 0:e.dirty)&&void 0!==t&&t)}))},e.useIsFieldTouched=function(e){const n=D(e);return t.computed((()=>{var e,t;return!!n&&(null!==(t="meta"in n?n.meta.touched:null===(e=null==n?void 0:n.value)||void 0===e?void 0:e.touched)&&void 0!==t&&t)}))},e.useIsFieldValid=function(e){const n=D(e);return t.computed((()=>{var e,t;return!!n&&(null!==(t="meta"in n?n.meta.valid:null===(e=null==n?void 0:n.value)||void 0===e?void 0:e.valid)&&void 0!==t&&t)}))},e.useIsFormDirty=function(){const e=P(s);return e||U("No vee-validate <Form /> or `useForm` was detected in the component tree"),t.computed((()=>{var t;return null!==(t=null==e?void 0:e.meta.value.dirty)&&void 0!==t&&t}))},e.useIsFormTouched=function(){const e=P(s);return e||U("No vee-validate <Form /> or `useForm` was detected in the component tree"),t.computed((()=>{var t;return null!==(t=null==e?void 0:e.meta.value.touched)&&void 0!==t&&t}))},e.useIsFormValid=function(){const e=P(s);return e||U("No vee-validate <Form /> or `useForm` was detected in the component tree"),t.computed((()=>{var t;return null!==(t=null==e?void 0:e.meta.value.valid)&&void 0!==t&&t}))},e.useIsSubmitting=function(){const e=P(s);return e||U("No vee-validate <Form /> or `useForm` was detected in the component tree"),t.computed((()=>{var t;return null!==(t=null==e?void 0:e.isSubmitting.value)&&void 0!==t&&t}))},e.useIsValidating=function(){const e=P(s);return e||U("No vee-validate <Form /> or `useForm` was detected in the component tree"),t.computed((()=>{var t;return null!==(t=null==e?void 0:e.isValidating.value)&&void 0!==t&&t}))},e.useResetForm=function(){const e=P(s);return e||U("No vee-validate <Form /> or `useForm` was detected in the component tree"),function(t){if(e)return e.resetForm(t)}},e.useSubmitCount=function(){const e=P(s);return e||U("No vee-validate <Form /> or `useForm` was detected in the component tree"),t.computed((()=>{var t;return null!==(t=null==e?void 0:e.submitCount.value)&&void 0!==t?t:0}))},e.useSubmitForm=function(e){const t=P(s);t||U("No vee-validate <Form /> or `useForm` was detected in the component tree");const n=t?t.handleSubmit(e):void 0;return function(e){if(n)return n(e)}},e.useValidateField=function(e){const n=P(s),r=e?void 0:t.inject(d);return function(){return r?r.validate():n&&e?null==n?void 0:n.validateField(t.unref(e)):(U(`field with name ${t.unref(e)} was not found`),Promise.resolve({errors:[],valid:!0}))}},e.useValidateForm=function(){const e=P(s);return e||U("No vee-validate <Form /> or `useForm` was detected in the component tree"),function(){return e?e.validate():Promise.resolve({results:{},errors:{},valid:!0})}},e.validate=Z,e.validateObject=re}));
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "vee-validate",
|
|
3
|
-
"version": "4.
|
|
3
|
+
"version": "4.10.0",
|
|
4
4
|
"description": "Form Validation for Vue.js",
|
|
5
5
|
"author": "Abdelrahman Awad <logaretm1@gmail.com>",
|
|
6
6
|
"license": "MIT",
|
|
@@ -28,10 +28,10 @@
|
|
|
28
28
|
"dist/*.d.ts"
|
|
29
29
|
],
|
|
30
30
|
"peerDependencies": {
|
|
31
|
-
"vue": "^3.3.
|
|
31
|
+
"vue": "^3.3.4"
|
|
32
32
|
},
|
|
33
33
|
"dependencies": {
|
|
34
34
|
"@vue/devtools-api": "^6.5.0",
|
|
35
|
-
"type-fest": "^3.
|
|
35
|
+
"type-fest": "^3.12.0"
|
|
36
36
|
}
|
|
37
37
|
}
|