vee-validate 4.2.3 → 4.3.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.
@@ -1,5 +1,5 @@
1
1
  /**
2
- * vee-validate v4.2.3
2
+ * vee-validate v4.3.0
3
3
  * (c) 2021 Abdelrahman Awad
4
4
  * @license MIT
5
5
  */
@@ -15,6 +15,10 @@
15
15
  const isObject = (obj) => obj !== null && !!obj && typeof obj === 'object' && !Array.isArray(obj);
16
16
  function isIndex(value) {
17
17
  return Number(value) >= 0;
18
+ }
19
+ function toNumber(value) {
20
+ const n = parseFloat(value);
21
+ return isNaN(n) ? value : n;
18
22
  }
19
23
 
20
24
  const RULES = {};
@@ -42,6 +46,66 @@
42
46
  throw new Error(`Extension Error: The validator '${id}' must be a function.`);
43
47
  }
44
48
 
49
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
50
+ const normalizeChildren = (context, slotProps) => {
51
+ if (!context.slots.default) {
52
+ return context.slots.default;
53
+ }
54
+ return context.slots.default(slotProps);
55
+ };
56
+ /**
57
+ * Vue adds a `_value` prop at the moment on the input elements to store the REAL value on them, real values are different than the `value` attribute
58
+ * as they do not get casted to strings unlike `el.value` which preserves user-code behavior
59
+ */
60
+ function getBoundValue(el) {
61
+ if (hasValueBinding(el)) {
62
+ return el._value;
63
+ }
64
+ return undefined;
65
+ }
66
+ /**
67
+ * Vue adds a `_value` prop at the moment on the input elements to store the REAL value on them, real values are different than the `value` attribute
68
+ * as they do not get casted to strings unlike `el.value` which preserves user-code behavior
69
+ */
70
+ function hasValueBinding(el) {
71
+ return '_value' in el;
72
+ }
73
+
74
+ const isEvent = (evt) => {
75
+ if (!evt) {
76
+ return false;
77
+ }
78
+ if (typeof Event !== 'undefined' && isCallable(Event) && evt instanceof Event) {
79
+ return true;
80
+ }
81
+ // this is for IE and Cypress #3161
82
+ /* istanbul ignore next */
83
+ if (evt && evt.srcElement) {
84
+ return true;
85
+ }
86
+ return false;
87
+ };
88
+ function normalizeEventValue(value) {
89
+ if (!isEvent(value)) {
90
+ return value;
91
+ }
92
+ const input = value.target;
93
+ // Vue sets the current bound value on `_value` prop
94
+ // for checkboxes it it should fetch the value binding type as is (boolean instead of string)
95
+ if (hasCheckedAttr(input.type) && hasValueBinding(input)) {
96
+ return getBoundValue(input);
97
+ }
98
+ if (input.type === 'file' && input.files) {
99
+ return Array.from(input.files);
100
+ }
101
+ if (isNativeMultiSelect(input)) {
102
+ return Array.from(input.options)
103
+ .filter(opt => opt.selected && !opt.disabled)
104
+ .map(getBoundValue);
105
+ }
106
+ return input.value;
107
+ }
108
+
45
109
  function isLocator(value) {
46
110
  return isCallable(value) && !!value.__locatorRef;
47
111
  }
@@ -104,6 +168,9 @@
104
168
  */
105
169
  function shouldHaveValueBinding(tag, attrs) {
106
170
  return isNativeMultiSelectNode(tag, attrs) || isFileInputNode(tag, attrs);
171
+ }
172
+ function isFormSubmitEvent(evt) {
173
+ return isEvent(evt) && evt.target && 'submit' in evt.target;
107
174
  }
108
175
 
109
176
  function cleanupNonNestedPath(path) {
@@ -226,6 +293,20 @@
226
293
  }
227
294
  return field;
228
295
  }
296
+ /**
297
+ * Applies a mutation function on a field or field group
298
+ */
299
+ function applyFieldMutation(field, mutation, onlyFirst = false) {
300
+ if (!Array.isArray(field)) {
301
+ mutation(field);
302
+ return;
303
+ }
304
+ if (onlyFirst) {
305
+ mutation(field[0]);
306
+ return;
307
+ }
308
+ field.forEach(mutation);
309
+ }
229
310
  function resolveNextCheckboxValue(currentValue, checkedValue, uncheckedValue) {
230
311
  if (Array.isArray(currentValue)) {
231
312
  const newVal = [...currentValue];
@@ -236,66 +317,6 @@
236
317
  return currentValue === checkedValue ? uncheckedValue : checkedValue;
237
318
  }
238
319
 
239
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
240
- const normalizeChildren = (context, slotProps) => {
241
- if (!context.slots.default) {
242
- return context.slots.default;
243
- }
244
- return context.slots.default(slotProps);
245
- };
246
- /**
247
- * Vue adds a `_value` prop at the moment on the input elements to store the REAL value on them, real values are different than the `value` attribute
248
- * as they do not get casted to strings unlike `el.value` which preserves user-code behavior
249
- */
250
- function getBoundValue(el) {
251
- if (hasValueBinding(el)) {
252
- return el._value;
253
- }
254
- return undefined;
255
- }
256
- /**
257
- * Vue adds a `_value` prop at the moment on the input elements to store the REAL value on them, real values are different than the `value` attribute
258
- * as they do not get casted to strings unlike `el.value` which preserves user-code behavior
259
- */
260
- function hasValueBinding(el) {
261
- return '_value' in el;
262
- }
263
-
264
- const isEvent = (evt) => {
265
- if (!evt) {
266
- return false;
267
- }
268
- if (typeof Event !== 'undefined' && isCallable(Event) && evt instanceof Event) {
269
- return true;
270
- }
271
- // this is for IE and Cypress #3161
272
- /* istanbul ignore next */
273
- if (evt && evt.srcElement) {
274
- return true;
275
- }
276
- return false;
277
- };
278
- function normalizeEventValue(value) {
279
- if (!isEvent(value)) {
280
- return value;
281
- }
282
- const input = value.target;
283
- // Vue sets the current bound value on `_value` prop
284
- // for checkboxes it it should fetch the value binding type as is (boolean instead of string)
285
- if (hasCheckedAttr(input.type) && hasValueBinding(input)) {
286
- return getBoundValue(input);
287
- }
288
- if (input.type === 'file' && input.files) {
289
- return Array.from(input.files);
290
- }
291
- if (isNativeMultiSelect(input)) {
292
- return Array.from(input.options)
293
- .filter(opt => opt.selected && !opt.disabled)
294
- .map(getBoundValue);
295
- }
296
- return input.value;
297
- }
298
-
299
320
  /**
300
321
  * Normalizes the given rules expression.
301
322
  */
@@ -628,7 +649,7 @@
628
649
  const fid = ID_COUNTER >= Number.MAX_SAFE_INTEGER ? 0 : ++ID_COUNTER;
629
650
  const { initialValue, validateOnMount, bails, type, valueProp, label, validateOnValueUpdate, uncheckedValue, } = normalizeOptions(vue.unref(name), opts);
630
651
  const form = injectWithSelf(FormContextSymbol);
631
- const { meta, errors, errorMessage, handleBlur, handleInput, resetValidationState, setValidationState, value, checked, } = useValidationState({
652
+ const { meta, errors, errorMessage, handleBlur, handleInput, resetValidationState, setValidationState, setErrors, value, checked, } = useValidationState({
632
653
  name,
633
654
  initValue: initialValue,
634
655
  form,
@@ -637,7 +658,7 @@
637
658
  });
638
659
  const normalizedRules = vue.computed(() => {
639
660
  let rulesValue = vue.unref(rules);
640
- const schema = form === null || form === void 0 ? void 0 : form.schema;
661
+ const schema = vue.unref(form === null || form === void 0 ? void 0 : form.schema);
641
662
  if (schema && !isYupValidator(schema)) {
642
663
  rulesValue = extractRuleFromSchema(schema, vue.unref(name)) || rulesValue;
643
664
  }
@@ -650,6 +671,7 @@
650
671
  var _a, _b;
651
672
  meta.pending = true;
652
673
  let result;
674
+ meta.validated = true;
653
675
  if (!form || !form.validateSchema) {
654
676
  result = await validate(value.value, normalizedRules.value, {
655
677
  name: vue.unref(label) || vue.unref(name),
@@ -658,7 +680,7 @@
658
680
  });
659
681
  }
660
682
  else {
661
- result = (_b = (await form.validateSchema())[vue.unref(name)]) !== null && _b !== void 0 ? _b : { valid: true, errors: [] };
683
+ result = (_b = (await form.validateSchema('validated-only'))[vue.unref(name)]) !== null && _b !== void 0 ? _b : { valid: true, errors: [] };
662
684
  }
663
685
  meta.pending = false;
664
686
  return setValidationState(result);
@@ -674,7 +696,7 @@
674
696
  });
675
697
  }
676
698
  else {
677
- result = (_c = (_b = (await form.validateSchema(false))) === null || _b === void 0 ? void 0 : _b[vue.unref(name)]) !== null && _c !== void 0 ? _c : { valid: true, errors: [] };
699
+ result = (_c = (_b = (await form.validateSchema('silent'))) === null || _b === void 0 ? void 0 : _b[vue.unref(name)]) !== null && _c !== void 0 ? _c : { valid: true, errors: [] };
678
700
  }
679
701
  meta.valid = result.valid;
680
702
  }
@@ -690,7 +712,6 @@
690
712
  newValue = resolveNextCheckboxValue(value.value, vue.unref(valueProp), vue.unref(uncheckedValue));
691
713
  }
692
714
  value.value = newValue;
693
- meta.hadValueUserInteraction = true;
694
715
  if (!validateOnValueUpdate) {
695
716
  return validateWithStateMutation();
696
717
  }
@@ -741,6 +762,7 @@
741
762
  handleInput,
742
763
  setValidationState,
743
764
  setTouched,
765
+ setErrors,
744
766
  };
745
767
  vue.provide(FieldContextSymbol, field);
746
768
  if (vue.isRef(rules) && typeof vue.unref(rules) !== 'function') {
@@ -848,7 +870,6 @@
848
870
  if (!hasCheckedAttr(type)) {
849
871
  value.value = normalizeEventValue(e);
850
872
  }
851
- meta.hadValueUserInteraction = true;
852
873
  };
853
874
  // Updates the validation state with the validation result
854
875
  function setValidationState(result) {
@@ -871,12 +892,13 @@
871
892
  setErrors((state === null || state === void 0 ? void 0 : state.errors) || []);
872
893
  meta.touched = (_b = state === null || state === void 0 ? void 0 : state.touched) !== null && _b !== void 0 ? _b : false;
873
894
  meta.pending = false;
874
- meta.hadValueUserInteraction = false;
895
+ meta.validated = false;
875
896
  }
876
897
  return {
877
898
  meta,
878
899
  errors,
879
900
  errorMessage,
901
+ setErrors,
880
902
  setValidationState,
881
903
  resetValidationState,
882
904
  handleBlur,
@@ -893,7 +915,7 @@
893
915
  touched: false,
894
916
  pending: false,
895
917
  valid: true,
896
- hadValueUserInteraction: false,
918
+ validated: false,
897
919
  initialValue: vue.computed(() => vue.unref(initialValue)),
898
920
  dirty: vue.computed(() => {
899
921
  return !es6(currentValue.value, vue.unref(initialValue));
@@ -946,7 +968,7 @@
946
968
  errors: vue.computed(() => errors.value),
947
969
  errorMessage: vue.computed(() => errors.value[0]),
948
970
  setErrors: (messages) => {
949
- errors.value = messages;
971
+ errors.value = Array.isArray(messages) ? messages : [messages];
950
972
  },
951
973
  };
952
974
  }
@@ -1011,6 +1033,10 @@
1011
1033
  modelValue: {
1012
1034
  type: null,
1013
1035
  },
1036
+ modelModifiers: {
1037
+ type: null,
1038
+ default: () => ({}),
1039
+ },
1014
1040
  },
1015
1041
  emits: ['update:modelValue'],
1016
1042
  setup(props, ctx) {
@@ -1018,7 +1044,7 @@
1018
1044
  const name = vue.toRef(props, 'name');
1019
1045
  const label = vue.toRef(props, 'label');
1020
1046
  const uncheckedValue = vue.toRef(props, 'uncheckedValue');
1021
- const { errors, value, errorMessage, validate: validateField, handleChange, handleBlur, handleInput, setTouched, resetField, handleReset, meta, checked, } = useField(name, rules, {
1047
+ const { errors, value, errorMessage, validate: validateField, handleChange, handleBlur, handleInput, setTouched, resetField, handleReset, meta, checked, setErrors, } = useField(name, rules, {
1022
1048
  validateOnMount: props.validateOnMount,
1023
1049
  bails: props.bails,
1024
1050
  type: ctx.attrs.type,
@@ -1088,12 +1114,13 @@
1088
1114
  handleReset,
1089
1115
  handleBlur,
1090
1116
  setTouched,
1117
+ setErrors,
1091
1118
  };
1092
1119
  });
1093
1120
  if ('modelValue' in props) {
1094
1121
  const modelValue = vue.toRef(props, 'modelValue');
1095
1122
  vue.watch(modelValue, newModelValue => {
1096
- if (newModelValue !== value.value) {
1123
+ if (newModelValue !== applyModifiers(value.value, props.modelModifiers)) {
1097
1124
  value.value = newModelValue;
1098
1125
  validateField();
1099
1126
  }
@@ -1125,6 +1152,12 @@
1125
1152
  validateOnBlur: (_c = props.validateOnBlur) !== null && _c !== void 0 ? _c : validateOnBlur,
1126
1153
  validateOnModelUpdate: (_d = props.validateOnModelUpdate) !== null && _d !== void 0 ? _d : validateOnModelUpdate,
1127
1154
  };
1155
+ }
1156
+ function applyModifiers(value, modifiers) {
1157
+ if (modifiers.number) {
1158
+ return toNumber(value);
1159
+ }
1160
+ return value;
1128
1161
  }
1129
1162
 
1130
1163
  function useForm(opts) {
@@ -1237,11 +1270,7 @@
1237
1270
  if (!fieldInstance) {
1238
1271
  return;
1239
1272
  }
1240
- if (Array.isArray(fieldInstance)) {
1241
- fieldInstance.forEach(f => f.setTouched(isTouched));
1242
- return;
1243
- }
1244
- fieldInstance.setTouched(isTouched);
1273
+ applyFieldMutation(fieldInstance, f => f.setTouched(isTouched));
1245
1274
  }
1246
1275
  /**
1247
1276
  * Sets the touched meta state on multiple fields
@@ -1334,7 +1363,7 @@
1334
1363
  return acc;
1335
1364
  }
1336
1365
  if (formCtx.validateSchema) {
1337
- return formCtx.validateSchema(true).then(results => {
1366
+ return formCtx.validateSchema('force').then(results => {
1338
1367
  return keysOf(results)
1339
1368
  .map(r => ({ key: r, errors: results[r].errors }))
1340
1369
  .reduce(resultReducer, { errors: {}, valid: true });
@@ -1400,6 +1429,7 @@
1400
1429
  setInPath(formValues, path, value);
1401
1430
  setInPath(initialValues.value, path, value);
1402
1431
  }
1432
+ const schema = opts === null || opts === void 0 ? void 0 : opts.validationSchema;
1403
1433
  const formCtx = {
1404
1434
  register: registerField,
1405
1435
  unregister: unregisterField,
@@ -1407,11 +1437,11 @@
1407
1437
  values: formValues,
1408
1438
  setFieldErrorBag,
1409
1439
  errorBag,
1410
- schema: opts === null || opts === void 0 ? void 0 : opts.validationSchema,
1440
+ schema,
1411
1441
  submitCount,
1412
- validateSchema: isYupValidator(opts === null || opts === void 0 ? void 0 : opts.validationSchema)
1413
- ? (shouldMutate = false) => {
1414
- return validateYupSchema(formCtx, shouldMutate);
1442
+ validateSchema: isYupValidator(vue.unref(schema))
1443
+ ? mode => {
1444
+ return validateYupSchema(formCtx, mode);
1415
1445
  }
1416
1446
  : undefined,
1417
1447
  validate,
@@ -1435,9 +1465,8 @@
1435
1465
  }, {});
1436
1466
  });
1437
1467
  const submitForm = handleSubmit((_, { evt }) => {
1438
- var _a, _b;
1439
- if (evt) {
1440
- (_b = (_a = evt === null || evt === void 0 ? void 0 : evt.target) === null || _a === void 0 ? void 0 : _a.submit) === null || _b === void 0 ? void 0 : _b.call(_a);
1468
+ if (isFormSubmitEvent(evt)) {
1469
+ evt.target.submit();
1441
1470
  }
1442
1471
  });
1443
1472
  // Trigger initial validation
@@ -1456,9 +1485,15 @@
1456
1485
  // otherwise run initial silent validation through schema if available
1457
1486
  // the useField should skip their own silent validation if a yup schema is present
1458
1487
  if (formCtx.validateSchema) {
1459
- formCtx.validateSchema(false);
1488
+ formCtx.validateSchema('silent');
1460
1489
  }
1461
1490
  });
1491
+ if (vue.isRef(schema)) {
1492
+ vue.watch(schema, () => {
1493
+ var _a;
1494
+ (_a = formCtx.validateSchema) === null || _a === void 0 ? void 0 : _a.call(formCtx, 'validated-only');
1495
+ });
1496
+ }
1462
1497
  // Provide injections
1463
1498
  vue.provide(FormContextSymbol, formCtx);
1464
1499
  vue.provide(FormErrorsSymbol, errors);
@@ -1503,8 +1538,8 @@
1503
1538
  return Object.assign(Object.assign({ initialValues: vue.unref(initialValues) }, flags), { dirty: isDirty.value });
1504
1539
  });
1505
1540
  }
1506
- async function validateYupSchema(form, shouldMutate = false) {
1507
- const errors = await form.schema
1541
+ async function validateYupSchema(form, mode) {
1542
+ const errors = await vue.unref(form.schema)
1508
1543
  .validate(form.values, { abortEarly: false })
1509
1544
  .then(() => [])
1510
1545
  .catch((err) => {
@@ -1530,24 +1565,15 @@
1530
1565
  valid: !messages.length,
1531
1566
  };
1532
1567
  result[fieldId] = fieldResult;
1533
- const hadInteraction = Array.isArray(field)
1534
- ? field.some(f => f.meta.hadValueUserInteraction)
1535
- : field.meta.hadValueUserInteraction;
1536
- if (!shouldMutate && !hadInteraction) {
1537
- // Update the valid flag regardless to keep it accurate
1538
- if (Array.isArray(field)) {
1539
- field.forEach(f => (f.meta.valid = fieldResult.valid));
1540
- }
1541
- else {
1542
- field.meta.valid = fieldResult.valid;
1543
- }
1568
+ if (mode === 'silent') {
1569
+ applyFieldMutation(field, f => (f.meta.valid = fieldResult.valid));
1544
1570
  return result;
1545
1571
  }
1546
- if (Array.isArray(field)) {
1547
- field[0].setValidationState(fieldResult);
1572
+ const wasValidated = Array.isArray(field) ? field.some(f => f.meta.validated) : field.meta.validated;
1573
+ if (mode === 'validated-only' && !wasValidated) {
1548
1574
  return result;
1549
1575
  }
1550
- field.setValidationState(fieldResult);
1576
+ applyFieldMutation(field, f => f.setValidationState(fieldResult), true);
1551
1577
  return result;
1552
1578
  }, {});
1553
1579
  return aggregatedResult;
@@ -1566,14 +1592,14 @@
1566
1592
  if (!updateFields) {
1567
1593
  return;
1568
1594
  }
1569
- // update the non-interacted-by-user fields
1595
+ // update the pristine non-touched fields
1570
1596
  // those are excluded because it's unlikely you want to change the form values using initial values
1571
1597
  // we mostly watch them for API population or newly inserted fields
1572
1598
  // if the user API is taking too much time before user interaction they should consider disabling or hiding their inputs until the values are ready
1573
- const isSafeToUpdate = (f) => f.meta.hadValueUserInteraction;
1599
+ const hadInteraction = (f) => f.meta.touched;
1574
1600
  keysOf(fields.value).forEach(fieldPath => {
1575
1601
  const field = fields.value[fieldPath];
1576
- const touchedByUser = Array.isArray(field) ? field.some(isSafeToUpdate) : isSafeToUpdate(field);
1602
+ const touchedByUser = Array.isArray(field) ? field.some(hadInteraction) : hadInteraction(field);
1577
1603
  if (touchedByUser) {
1578
1604
  return;
1579
1605
  }
@@ -1656,8 +1682,9 @@
1656
1682
  },
1657
1683
  setup(props, ctx) {
1658
1684
  const initialValues = vue.toRef(props, 'initialValues');
1685
+ const validationSchema = vue.toRef(props, 'validationSchema');
1659
1686
  const { errors, values, meta, isSubmitting, submitCount, validate, validateField, handleReset, resetForm, handleSubmit, submitForm, setErrors, setFieldError, setFieldValue, setValues, setFieldTouched, setTouched, } = useForm({
1660
- validationSchema: props.validationSchema,
1687
+ validationSchema: validationSchema.value ? validationSchema : undefined,
1661
1688
  initialValues,
1662
1689
  initialErrors: props.initialErrors,
1663
1690
  initialTouched: props.initialTouched,
@@ -1,6 +1,6 @@
1
1
  /**
2
- * vee-validate v4.2.3
2
+ * vee-validate v4.3.0
3
3
  * (c) 2021 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 r(e){return"function"==typeof e}const n=e=>null!==e&&!!e&&"object"==typeof e&&!Array.isArray(e);function a(e){return Number(e)>=0}const i={};function u(e){return r(e)&&!!e.__locatorRef}function o(e){return!!e&&r(e.validate)}function l(e){return"checkbox"===e||"radio"===e}function s(e){return/^\[.+\]$/i.test(e)}function d(e,t){return function(e,t){const r=![!1,null,void 0,0].includes(t.multiple)&&!Number.isNaN(t.multiple);return"select"===e&&"multiple"in t&&r}(e,t)||function(e,t){return function(e){return["input","textarea","select"].includes(e)}(e)&&"file"===t.type}(e,t)}function c(e){return s(e)?e.replace(/\[|\]/gi,""):e}function v(e,t){if(!e)return;if(s(t))return e[c(t)];return t.split(/\.|\[(\d+)\]/).filter(Boolean).reduce(((e,t)=>{if((n(r=e)||Array.isArray(r))&&t in e)return e[t];var r}),e)}function f(e,t,r){if(s(t))return void(e[c(t)]=r);const n=t.split(/\.|\[(\d+)\]/).filter(Boolean);let i=e;for(let e=0;e<n.length;e++){if(e===n.length-1)return void(i[n[e]]=r);n[e]in i||(i[n[e]]=a(n[e+1])?[]:{}),i=i[n[e]]}}function m(e,t){Array.isArray(e)&&a(t)?e.splice(Number(t),1):n(e)&&delete e[t]}function p(e,t){if(s(t))return void delete e[c(t)];const r=t.split(/\.|\[(\d+)\]/).filter(Boolean);let a=e;for(let e=0;e<r.length;e++){if(e===r.length-1){m(a,r[e]);break}if(!(r[e]in a))break;a=a[r[e]]}const i=r.map(((t,n)=>v(e,r.slice(0,n).join("."))));for(let t=i.length-1;t>=0;t--)u=i[t],(Array.isArray(u)?0===u.length:n(u)&&0===Object.keys(u).length)&&(0!==t?m(i[t-1],r[t-1]):m(e,r[0]));var u}function h(e){return Object.keys(e)}function y(e,r){const n=t.getCurrentInstance();return t.inject(e,(null==n?void 0:n.provides[e])||r)}function g(e){t.warn(`[vee-validate]: ${e}`)}function b(e){return Array.isArray(e)?e[0]:e}function F(e,t,r){if(Array.isArray(e)){const r=[...e],n=r.indexOf(t);return n>=0?r.splice(n,1):r.push(t),r}return e===t?r:t}const O=(e,t)=>e.slots.default?e.slots.default(t):e.slots.default;function V(e){if(E(e))return e._value}function E(e){return"_value"in e}const A=e=>!!e&&(!!("undefined"!=typeof Event&&r(Event)&&e instanceof Event)||!(!e||!e.srcElement));function S(e){if(!A(e))return e;const t=e.target;return l(t.type)&&E(t)?V(t):"file"===t.type&&t.files?Array.from(t.files):"SELECT"===(r=t).tagName&&r.multiple?Array.from(t.options).filter((e=>e.selected&&!e.disabled)).map(V):t.value;var r}function j(e){const t={};return Object.defineProperty(t,"_$$isNormalized",{value:!0,writable:!1,enumerable:!1,configurable:!1}),e?n(e)&&e._$$isNormalized?e:n(e)?Object.keys(e).reduce(((t,r)=>{const a=function(e){if(!0===e)return[];if(Array.isArray(e))return e;if(n(e))return e;return[e]}(e[r]);return!1!==e[r]&&(t[r]=w(a)),t}),t):"string"!=typeof e?t:e.split("|").reduce(((e,t)=>{const r=B(t);return r.name?(e[r.name]=w(r.params),e):e}),t):t}function w(e){const t=e=>"string"==typeof e&&"@"===e[0]?function(e){const t=t=>v(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(((r,n)=>(r[n]=t(e[n]),r)),{})}const B=e=>{let t=[];const r=e.split(":")[0];return e.includes(":")&&(t=e.split(":").slice(1).join(":").split(",")),{name:r,params:t}};let I=Object.assign({},{generateMessage:({field:e})=>`${e} is not valid.`,bails:!0,validateOnBlur:!0,validateOnChange:!0,validateOnInput:!1,validateOnModelUpdate:!0});const M=()=>I,k=e=>{I=Object.assign(Object.assign({},I),e)};async function T(e,t,n={}){const a=null==n?void 0:n.bails,i={name:(null==n?void 0:n.name)||"{field}",rules:t,bails:null==a||a,formData:(null==n?void 0:n.values)||{}},u=(await async function(e,t){if(o(e.rules))return async function(e,t,r){var n;return{errors:await t.validate(e,{abortEarly:null===(n=r.bails)||void 0===n||n}).then((()=>[])).catch((e=>{if("ValidationError"===e.name)return e.errors;throw e}))}}(t,e.rules,{bails:e.bails});if(r(e.rules)){const r={field:e.name,form:e.formData,value:t},n=await e.rules(t,r),a="string"!=typeof n&&n,i="string"==typeof n?n:R(r);return{errors:a?[]:[i]}}const n=Object.assign(Object.assign({},e),{rules:j(e.rules)}),a=[],i=Object.keys(n.rules),u=i.length;for(let r=0;r<u;r++){const u=i[r],o=await C(n,t,{name:u,params:n.rules[u]});if(o.error&&(a.push(o.error),e.bails))return{errors:a}}return{errors:a}}(i,e)).errors;return{errors:u,valid:!u.length}}async function C(e,t,r){const n=(a=r.name,i[a]);var a;if(!n)throw new Error(`No such validator '${r.name}' exists.`);const o=function(e,t){const r=e=>u(e)?e(t):e;if(Array.isArray(e))return e.map(r);return Object.keys(e).reduce(((t,n)=>(t[n]=r(e[n]),t)),{})}(r.params,e.formData),l={field:e.name,value:t,form:e.formData,rule:Object.assign(Object.assign({},r),{params:o})},s=await n(t,o,l);return"string"==typeof s?{error:s}:{error:s?void 0:R(l)}}function R(e){const t=M().generateMessage;return t?t(e):"Field is invalid"}var x=function e(t,r){if(t===r)return!0;if(t&&r&&"object"==typeof t&&"object"==typeof r){if(t.constructor!==r.constructor)return!1;var n,a,i;if(Array.isArray(t)){if((n=t.length)!=r.length)return!1;for(a=n;0!=a--;)if(!e(t[a],r[a]))return!1;return!0}if(t instanceof Map&&r instanceof Map){if(t.size!==r.size)return!1;for(a of t.entries())if(!r.has(a[0]))return!1;for(a of t.entries())if(!e(a[1],r.get(a[0])))return!1;return!0}if(t instanceof Set&&r instanceof Set){if(t.size!==r.size)return!1;for(a of t.entries())if(!r.has(a[0]))return!1;return!0}if(ArrayBuffer.isView(t)&&ArrayBuffer.isView(r)){if((n=t.length)!=r.length)return!1;for(a=n;0!=a--;)if(t[a]!==r[a])return!1;return!0}if(t.constructor===RegExp)return t.source===r.source&&t.flags===r.flags;if(t.valueOf!==Object.prototype.valueOf)return t.valueOf()===r.valueOf();if(t.toString!==Object.prototype.toString)return t.toString()===r.toString();if((n=(i=Object.keys(t)).length)!==Object.keys(r).length)return!1;for(a=n;0!=a--;)if(!Object.prototype.hasOwnProperty.call(r,i[a]))return!1;for(a=n;0!=a--;){var u=i[a];if(!e(t[u],r[u]))return!1}return!0}return t!=t&&r!=r};const N=Symbol("vee-validate-form"),U=Symbol("vee-validate-form-errors"),$=Symbol("vee-validate-form-initial-values"),P=Symbol("vee-validate-field-instance");let _=0;function D(e,n,a){const i=_>=Number.MAX_SAFE_INTEGER?0:++_,{initialValue:s,validateOnMount:d,bails:c,type:f,valueProp:m,label:p,validateOnValueUpdate:g,uncheckedValue:b}=function(e,t){const r=()=>({initialValue:void 0,validateOnMount:!1,bails:!0,rules:"",label:e,validateOnValueUpdate:!0});if(!t)return r();return Object.assign(Object.assign({},r()),t||{})}(t.unref(e),a),O=y(N),{meta:V,errors:E,errorMessage:A,handleBlur:w,handleInput:B,resetValidationState:I,setValidationState:M,value:k,checked:C}=function({name:e,initValue:r,form:n,type:a,valueProp:i}){const{errors:u,errorMessage:o,setErrors:s}=function(e,r){if(!r){const e=t.ref([]);return{errors:t.computed((()=>e.value)),errorMessage:t.computed((()=>e.value[0])),setErrors:t=>{e.value=t}}}const n=t.computed((()=>r.errorBag.value[t.unref(e)]||[]));return{errors:n,errorMessage:t.computed((()=>n.value[0])),setErrors:n=>{r.setFieldErrorBag(t.unref(e),n)}}}(e,n),d=y($,void 0),c=t.computed((()=>{var n;return null!==(n=v(t.unref(d),t.unref(e)))&&void 0!==n?n:t.unref(r)})),f=function(e,r,n){if(!n)return t.ref(t.unref(e));n.stageInitialValue(t.unref(r),t.unref(e));return t.computed({get:()=>v(n.values,t.unref(r)),set(e){n.setFieldValue(t.unref(r),e)}})}(c,e,n),m=function(e,r,n){const a=t.reactive({touched:!1,pending:!1,valid:!0,hadValueUserInteraction:!1,initialValue:t.computed((()=>t.unref(e))),dirty:t.computed((()=>!x(r.value,t.unref(e))))});return t.watch(n,(e=>{a.valid=!e.length}),{immediate:!0,flush:"sync"}),a}(c,f,u),p=l(a)?t.computed((()=>Array.isArray(f.value)?f.value.includes(t.unref(i)):t.unref(i)===f.value)):void 0,h=()=>{m.touched=!0},g=e=>{l(a)||(f.value=S(e)),m.hadValueUserInteraction=!0};function b(e){return s(e.errors),e}function F(a){var i,u;const o=t.unref(e),l=a&&"value"in a?a.value:null!==(i=v(t.unref(d),o))&&void 0!==i?i:r;n?n.setFieldValue(o,l,{force:!0}):f.value=l,s((null==a?void 0:a.errors)||[]),m.touched=null!==(u=null==a?void 0:a.touched)&&void 0!==u&&u,m.pending=!1,m.hadValueUserInteraction=!1}return{meta:m,errors:u,errorMessage:o,setValidationState:b,resetValidationState:F,handleBlur:h,handleInput:g,value:f,checked:p}}({name:e,initValue:s,form:O,type:f,valueProp:m}),R=t.computed((()=>{let a=t.unref(n);const i=null==O?void 0:O.schema;return i&&!o(i)&&(a=function(e,t){if(!e)return;return e[t]}(i,t.unref(e))||a),o(a)||r(a)?a:j(a)}));async function U(){var r,n;let a;return V.pending=!0,a=O&&O.validateSchema?null!==(n=(await O.validateSchema())[t.unref(e)])&&void 0!==n?n:{valid:!0,errors:[]}:await T(k.value,R.value,{name:t.unref(p)||t.unref(e),values:null!==(r=null==O?void 0:O.values)&&void 0!==r?r:{},bails:c}),V.pending=!1,M(a)}async function D(){var r,n,a;let i;i=O&&O.validateSchema?null!==(a=null===(n=await O.validateSchema(!1))||void 0===n?void 0:n[t.unref(e)])&&void 0!==a?a:{valid:!0,errors:[]}:await T(k.value,R.value,{name:t.unref(p)||t.unref(e),values:null!==(r=null==O?void 0:O.values)&&void 0!==r?r:{},bails:c}),V.valid=i.valid}let z;function q(){z=t.watch(k,g?U:D,{deep:!0})}function G(e){null==z||z(),I(e),q()}t.onMounted((()=>{if(d)return U();O&&O.validateSchema||D()})),q();const L={idx:-1,fid:i,name:e,value:k,meta:V,errors:E,errorMessage:A,type:f,valueProp:m,uncheckedValue:b,checked:C,resetField:G,handleReset:()=>G(),validate:U,handleChange:e=>{var r,n;if(C&&C.value===(null===(n=null===(r=e)||void 0===r?void 0:r.target)||void 0===n?void 0:n.checked))return;let a=S(e);return C&&"checkbox"===f&&!O&&(a=F(k.value,t.unref(m),t.unref(b))),k.value=a,V.hadValueUserInteraction=!0,g?void 0:U()},handleBlur:w,handleInput:B,setValidationState:M,setTouched:function(e){V.touched=e}};if(t.provide(P,L),t.isRef(n)&&"function"!=typeof t.unref(n)&&t.watch(n,((e,t)=>{if(!x(e,t))return U()}),{deep:!0}),!O)return L;O.register(L),t.onBeforeUnmount((()=>{O.unregister(L)}));const X=t.computed((()=>{const e=R.value;return!e||r(e)||o(e)?{}:Object.keys(e).reduce(((t,r)=>{const n=(a=e[r],Array.isArray(a)?a.filter(u):h(a).filter((e=>u(a[e]))).map((e=>a[e]))).map((e=>e.__locatorRef)).reduce(((e,t)=>{const r=v(O.values,t)||O.values[t];return void 0!==r&&(e[t]=r),e}),{});var a;return Object.assign(t,n),t}),{})}));return t.watch(X,((e,t)=>{if(!Object.keys(e).length)return;!x(e,t)&&(V.dirty?U():D())})),L}const z=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:()=>M().bails},label:{type:String,default:void 0},uncheckedValue:{type:null,default:void 0},modelValue:{type:null}},emits:["update:modelValue"],setup(e,r){const n=t.toRef(e,"rules"),a=t.toRef(e,"name"),i=t.toRef(e,"label"),u=t.toRef(e,"uncheckedValue"),{errors:o,value:s,errorMessage:c,validate:v,handleChange:f,handleBlur:m,handleInput:p,setTouched:h,resetField:y,handleReset:g,meta:b,checked:F}=D(a,n,{validateOnMount:e.validateOnMount,bails:e.bails,type:r.attrs.type,initialValue:l(r.attrs.type)||"modelValue"in e?e.modelValue:r.attrs.value,valueProp:r.attrs.value,uncheckedValue:u,label:i,validateOnValueUpdate:!1}),V="modelValue"in e?function(e){f(e),r.emit("update:modelValue",s.value)}:f,E="modelValue"in e?function(e){p(e),r.emit("update:modelValue",s.value)}:p,A=t.computed((()=>{const{validateOnInput:t,validateOnChange:n,validateOnBlur:a,validateOnModelUpdate:i}=function(e){var t,r,n,a;const{validateOnInput:i,validateOnChange:u,validateOnBlur:o,validateOnModelUpdate:l}=M();return{validateOnInput:null!==(t=e.validateOnInput)&&void 0!==t?t:i,validateOnChange:null!==(r=e.validateOnChange)&&void 0!==r?r:u,validateOnBlur:null!==(n=e.validateOnBlur)&&void 0!==n?n:o,validateOnModelUpdate:null!==(a=e.validateOnModelUpdate)&&void 0!==a?a:l}}(e),u=[m,r.attrs.onBlur,a?v:void 0].filter(Boolean),o=[E,t?V:void 0,r.attrs.onInput].filter(Boolean),c=[E,n?V:void 0,r.attrs.onChange].filter(Boolean),f={name:e.name,onBlur:u,onInput:o,onChange:c};i&&(f["onUpdate:modelValue"]=[V]),l(r.attrs.type)&&F?f.checked=F.value:f.value=s.value;return d(q(e,r),r.attrs)&&delete f.value,f})),S=t.computed((()=>({field:A.value,value:s.value,meta:b,errors:o.value,errorMessage:c.value,validate:v,resetField:y,handleChange:V,handleInput:E,handleReset:g,handleBlur:m,setTouched:h})));if("modelValue"in e){const r=t.toRef(e,"modelValue");t.watch(r,(e=>{e!==s.value&&(s.value=e,v())}))}return()=>{const n=t.resolveDynamicComponent(q(e,r)),a=O(r,S.value);return n?t.h(n,Object.assign(Object.assign({},r.attrs),A.value),a):a}}});function q(e,t){let r=e.as||"";return e.as||t.slots.default||(r="input"),r}function G(e){const r=t.ref([]),n=t.ref(!1),a=t.computed((()=>r.value.reduce(((e,r)=>{const n=t.unref(r.name);if(!e[n])return e[n]=r,r.idx=-1,e;const a=e[n];Array.isArray(a)||(a.idx=0,e[n]=[a]);const i=e[n];return r.idx=i.length,i.push(r),e}),{}))),i=t.ref(0),u=t.reactive({}),l={},{errorBag:s,setErrorBag:d,setFieldErrorBag:c}=function(e){const r=t.ref({});function n(e,t){r.value[e]=Array.isArray(t)?t:t?[t]:[]}function a(e){h(e).forEach((t=>{n(t,e[t])}))}e&&a(e);return{errorBag:r,setErrorBag:a,setFieldErrorBag:n}}(null==e?void 0:e.initialErrors),m=t.computed((()=>h(s.value).reduce(((e,t)=>{const r=s.value[t];return r&&r.length&&(e[t]=r[0]),e}),{}))),{readonlyInitialValues:y,initialValues:g,setInitialValues:b}=function(e,r,n){const a=t.ref(t.unref(n)||{}),i=t.computed((()=>a.value));function u(t,n=!1){if(a.value=Object.assign(Object.assign({},a.value),t),!n)return;const i=e=>e.meta.hadValueUserInteraction;h(e.value).forEach((t=>{const n=e.value[t];if(Array.isArray(n)?n.some(i):i(n))return;const u=v(a.value,t);f(r,t,u)}))}t.isRef(n)&&t.watch(n,(e=>{u(e,!0)}),{deep:!0});return t.provide($,i),{readonlyInitialValues:i,initialValues:a,setInitialValues:u}}(a,u,null==e?void 0:e.initialValues),O=function(e,r,n){const a={touched:"some",pending:"some",valid:"every"},i=t.computed((()=>!x(r,t.unref(n))));return t.computed((()=>{const r=h(a).reduce(((t,r)=>{const n=a[r];return t[r]=e.value[n]((e=>e.meta[r])),t}),{});return Object.assign(Object.assign({initialValues:t.unref(n)},r),{dirty:i.value})}))}(r,u,y);function V(e,t){c(e,t)}function E(e){d(e)}function A(e,r,{force:n}={force:!1}){var i;const o=a.value[e];if(Array.isArray(o)&&"checkbox"===(null===(i=o[0])||void 0===i?void 0:i.type)&&!Array.isArray(r)){const t=F(v(u,e)||[],r,void 0);return f(u,e,t),void o.forEach((e=>{l[e.fid]=t}))}let s=r;Array.isArray(o)||"checkbox"!==(null==o?void 0:o.type)||n||(s=F(v(u,e),r,t.unref(o.uncheckedValue))),f(u,e,s),o&&Array.isArray(o)?o.forEach((e=>{l[e.fid]=s})):o&&(l[o.fid]=s)}function S(e){h(e).forEach((t=>{A(t,e[t])}))}function j(e,t){const r=a.value[e];r&&(Array.isArray(r)?r.forEach((e=>e.setTouched(t))):r.setTouched(t))}function w(e){h(e).forEach((t=>{j(t,!!e[t])}))}const B=e=>{(null==e?void 0:e.values)&&b(e.values),r.value.forEach((e=>e.resetField())),(null==e?void 0:e.touched)&&w(e.touched),(null==e?void 0:e.errors)&&E(e.errors),i.value=(null==e?void 0:e.submitCount)||0};async function I(){function e(e,t){return t.errors.length?(e.valid=!1,e.errors[t.key]=t.errors[0],e):e}if(T.validateSchema)return T.validateSchema(!0).then((t=>h(t).map((e=>({key:e,errors:t[e].errors}))).reduce(e,{errors:{},valid:!0})));return(await Promise.all(r.value.map((e=>e.validate().then((r=>({key:t.unref(e.name),errors:r.errors}))))))).reduce(e,{errors:{},valid:!0})}async function M(e){const r=a.value[e];return r?Array.isArray(r)?r.map((e=>e.validate()))[0]:r.validate():(t.warn(`field with name ${e} was not found`),Promise.resolve({errors:[],valid:!0}))}const k=e=>function(t){return t instanceof Event&&(t.preventDefault(),t.stopPropagation()),n.value=!0,i.value++,I().then((r=>{if(r.valid&&"function"==typeof e)return e(C.value,{evt:t,setErrors:E,setFieldError:V,setTouched:w,setFieldTouched:j,setValues:S,setFieldValue:A,resetForm:B})})).then((()=>{n.value=!1}),(e=>{throw n.value=!1,e}))};const T={register:function(e){r.value.push(e),t.isRef(e.name)&&(l[e.fid]=e.value.value,t.watch(e.name,(t=>{A(t,l[e.fid])}),{flush:"post"}))},unregister:function(e){var n,a;const i=r.value.indexOf(e);if(-1===i)return;r.value.splice(i,1);const o=e.fid;t.nextTick((()=>{delete l[o]}));const s=t.unref(e.name);if(-1===e.idx){if(r.value.find((e=>t.unref(e.name)===s)))return;return p(u,s),void p(g.value,s)}const d=null===(a=null===(n=v(u,s))||void 0===n?void 0:n.indexOf)||void 0===a?void 0:a.call(n,t.unref(e.valueProp));void 0!==d?-1!==d&&(Array.isArray(u[s])?p(u,`${s}.${d}`):(p(u,s),p(g.value,s))):p(u,s)},fieldsById:a,values:u,setFieldErrorBag:c,errorBag:s,schema:null==e?void 0:e.validationSchema,submitCount:i,validateSchema:o(null==e?void 0:e.validationSchema)?(e=!1)=>async function(e,t=!1){const r=await e.schema.validate(e.values,{abortEarly:!1}).then((()=>[])).catch((e=>{if("ValidationError"!==e.name)throw e;return e.inner||[]})),n=e.fieldsById.value||{},a=r.reduce(((e,t)=>(e[t.path]=t,e)),{});return h(n).reduce(((e,r)=>{const i=n[r],u=(a[r]||{errors:[]}).errors,o={errors:u,valid:!u.length};e[r]=o;const l=Array.isArray(i)?i.some((e=>e.meta.hadValueUserInteraction)):i.meta.hadValueUserInteraction;return t||l?Array.isArray(i)?(i[0].setValidationState(o),e):(i.setValidationState(o),e):(Array.isArray(i)?i.forEach((e=>e.meta.valid=o.valid)):i.meta.valid=o.valid,e)}),{})}(T,e):void 0,validate:I,validateField:M,setFieldValue:A,setValues:S,setErrors:E,setFieldError:V,setFieldTouched:j,setTouched:w,resetForm:B,meta:O,isSubmitting:n,handleSubmit:k,stageInitialValue:function(e,t){f(u,e,t),f(g.value,e,t)}},C=t.computed((()=>r.value.reduce(((e,r)=>(f(e,t.unref(r.name),t.unref(r.value)),e)),{}))),R=k(((e,{evt:t})=>{var r,n;t&&(null===(n=null===(r=null==t?void 0:t.target)||void 0===r?void 0:r.submit)||void 0===n||n.call(r))}));return t.onMounted((()=>{(null==e?void 0:e.initialErrors)&&E(e.initialErrors),(null==e?void 0:e.initialTouched)&&w(e.initialTouched),(null==e?void 0:e.validateOnMount)?I():T.validateSchema&&T.validateSchema(!1)})),t.provide(N,T),t.provide(U,m),{errors:m,meta:O,values:u,isSubmitting:n,submitCount:i,validate:I,validateField:M,handleReset:()=>B(),resetForm:B,handleSubmit:k,submitForm:R,setFieldError:V,setErrors:E,setFieldValue:A,setValues:S,setFieldTouched:j,setTouched:w}}const L=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}},setup(e,r){const n=t.toRef(e,"initialValues"),{errors:a,values:i,meta:u,isSubmitting:o,submitCount:l,validate:s,validateField:d,handleReset:c,resetForm:v,handleSubmit:f,submitForm:m,setErrors:p,setFieldError:h,setFieldValue:y,setValues:g,setFieldTouched:b,setTouched:F}=G({validationSchema:e.validationSchema,initialValues:n,initialErrors:e.initialErrors,initialTouched:e.initialTouched,validateOnMount:e.validateOnMount}),V=e.onSubmit?f(e.onSubmit):m;function E(e){A(e)&&e.preventDefault(),c(),"function"==typeof r.attrs.onReset&&r.attrs.onReset()}function S(e,t){return f("function"!=typeof e||t?t:e)(e)}const j=t.computed((()=>({meta:u.value,errors:a.value,values:i,isSubmitting:o.value,submitCount:l.value,validate:s,validateField:d,handleSubmit:S,handleReset:c,submitForm:m,setErrors:p,setFieldError:h,setFieldValue:y,setValues:g,setFieldTouched:b,setTouched:F,resetForm:v})));return function(){"setErrors"in this||(this.setFieldError=h,this.setErrors=p,this.setFieldValue=y,this.setValues=g,this.setFieldTouched=b,this.setTouched=F,this.resetForm=v,this.validate=s,this.validateField=d);const n=O(r,j.value);if(!e.as)return n;const a="form"===e.as?{novalidate:!0}:{};return t.h("form"===e.as?e.as:t.resolveDynamicComponent(e.as),Object.assign(Object.assign(Object.assign({},a),r.attrs),{onSubmit:V,onReset:E}),n)}}}),X=t.defineComponent({props:{as:{type:String,default:void 0},name:{type:String,required:!0}},setup(e,r){const n=t.inject(U,void 0),a=t.computed((()=>null==n?void 0:n.value[e.name]));return()=>{if(!a.value)return;const n=O(r,{message:a.value}),i=e.as?t.resolveDynamicComponent(e.as):e.as,u=Object.assign({role:"alert"},r.attrs);return!i&&(null==n?void 0:n.length)?n:(null==n?void 0:n.length)?t.h(i,u,n):t.h(i||"span",u,a.value)}}});e.ErrorMessage=X,e.Field=z,e.Form=L,e.configure=k,e.defineRule=function(e,t){!function(e,t){if(r(t))return;throw new Error(`Extension Error: The validator '${e}' must be a function.`)}(e,t),i[e]=t},e.useField=D,e.useFieldError=function(e){const r=y(U),n=e?void 0:t.inject(P);return t.computed((()=>{var a;return e?null===(a=null==r?void 0:r.value)||void 0===a?void 0:a[t.unref(e)]:null==n?void 0:n.errorMessage.value}))},e.useFieldValue=function(e){const r=y(N),n=e?void 0:t.inject(P);return t.computed((()=>{var a;return e?v(null==r?void 0:r.values,t.unref(e)):null===(a=null==n?void 0:n.value)||void 0===a?void 0:a.value}))},e.useForm=G,e.useFormErrors=function(){const e=y(U);return e||g("No vee-validate <Form /> or `useForm` was detected in the component tree"),e||t.computed((()=>({})))},e.useFormValues=function(){const e=y(N);return e||g("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 r=y(N);let n=e?void 0:t.inject(P);return t.computed((()=>(e&&(n=b(null==r?void 0:r.fieldsById.value[t.unref(e)])),n?n.meta.dirty:(g(`field with name ${t.unref(e)} was not found`),!1))))},e.useIsFieldTouched=function(e){const r=y(N);let n=e?void 0:t.inject(P);return t.computed((()=>(e&&(n=b(null==r?void 0:r.fieldsById.value[t.unref(e)])),n?n.meta.touched:(g(`field with name ${t.unref(e)} was not found`),!1))))},e.useIsFieldValid=function(e){const r=y(N);let n=e?void 0:t.inject(P);return t.computed((()=>(e&&(n=b(null==r?void 0:r.fieldsById.value[t.unref(e)])),n?n.meta.valid:(g(`field with name ${t.unref(e)} was not found`),!1))))},e.useIsFormDirty=function(){const e=y(N);return e||g("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=y(N);return e||g("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=y(N);return e||g("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=y(N);return e||g("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.useResetForm=function(){const e=y(N);return e||g("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=y(N);return e||g("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=y(N);t||g("No vee-validate <Form /> or `useForm` was detected in the component tree");const r=t?t.handleSubmit(e):void 0;return function(e){if(r)return r(e)}},e.useValidateField=function(e){const r=y(N);let n=e?void 0:t.inject(P);return function(){return e&&(n=b(null==r?void 0:r.fieldsById.value[t.unref(e)])),n?n.validate():(g(`field with name ${t.unref(e)} was not found`),Promise.resolve({errors:[],valid:!0}))}},e.useValidateForm=function(){const e=y(N);return e||g("No vee-validate <Form /> or `useForm` was detected in the component tree"),function(){return e?e.validate():Promise.resolve({errors:{},valid:!0})}},e.validate=T,Object.defineProperty(e,"__esModule",{value:!0})}));
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 r(e){return"function"==typeof e}const n=e=>null!==e&&!!e&&"object"==typeof e&&!Array.isArray(e);function a(e){return Number(e)>=0}const i={};const u=(e,t)=>e.slots.default?e.slots.default(t):e.slots.default;function o(e){if(l(e))return e._value}function l(e){return"_value"in e}const s=e=>!!e&&(!!("undefined"!=typeof Event&&r(Event)&&e instanceof Event)||!(!e||!e.srcElement));function d(e){if(!s(e))return e;const t=e.target;return f(t.type)&&l(t)?o(t):"file"===t.type&&t.files?Array.from(t.files):"SELECT"===(r=t).tagName&&r.multiple?Array.from(t.options).filter((e=>e.selected&&!e.disabled)).map(o):t.value;var r}function c(e){return r(e)&&!!e.__locatorRef}function v(e){return!!e&&r(e.validate)}function f(e){return"checkbox"===e||"radio"===e}function m(e){return/^\[.+\]$/i.test(e)}function p(e,t){return function(e,t){const r=![!1,null,void 0,0].includes(t.multiple)&&!Number.isNaN(t.multiple);return"select"===e&&"multiple"in t&&r}(e,t)||function(e,t){return function(e){return["input","textarea","select"].includes(e)}(e)&&"file"===t.type}(e,t)}function h(e){return m(e)?e.replace(/\[|\]/gi,""):e}function y(e,t){if(!e)return;if(m(t))return e[h(t)];return t.split(/\.|\[(\d+)\]/).filter(Boolean).reduce(((e,t)=>{if((n(r=e)||Array.isArray(r))&&t in e)return e[t];var r}),e)}function g(e,t,r){if(m(t))return void(e[h(t)]=r);const n=t.split(/\.|\[(\d+)\]/).filter(Boolean);let i=e;for(let e=0;e<n.length;e++){if(e===n.length-1)return void(i[n[e]]=r);n[e]in i||(i[n[e]]=a(n[e+1])?[]:{}),i=i[n[e]]}}function b(e,t){Array.isArray(e)&&a(t)?e.splice(Number(t),1):n(e)&&delete e[t]}function F(e,t){if(m(t))return void delete e[h(t)];const r=t.split(/\.|\[(\d+)\]/).filter(Boolean);let a=e;for(let e=0;e<r.length;e++){if(e===r.length-1){b(a,r[e]);break}if(!(r[e]in a))break;a=a[r[e]]}const i=r.map(((t,n)=>y(e,r.slice(0,n).join("."))));for(let t=i.length-1;t>=0;t--)u=i[t],(Array.isArray(u)?0===u.length:n(u)&&0===Object.keys(u).length)&&(0!==t?b(i[t-1],r[t-1]):b(e,r[0]));var u}function O(e){return Object.keys(e)}function V(e,r){const n=t.getCurrentInstance();return t.inject(e,(null==n?void 0:n.provides[e])||r)}function E(e){t.warn(`[vee-validate]: ${e}`)}function S(e){return Array.isArray(e)?e[0]:e}function A(e,t,r=!1){Array.isArray(e)?r?t(e[0]):e.forEach(t):t(e)}function j(e,t,r){if(Array.isArray(e)){const r=[...e],n=r.indexOf(t);return n>=0?r.splice(n,1):r.push(t),r}return e===t?r:t}function w(e){const t={};return Object.defineProperty(t,"_$$isNormalized",{value:!0,writable:!1,enumerable:!1,configurable:!1}),e?n(e)&&e._$$isNormalized?e:n(e)?Object.keys(e).reduce(((t,r)=>{const a=function(e){if(!0===e)return[];if(Array.isArray(e))return e;if(n(e))return e;return[e]}(e[r]);return!1!==e[r]&&(t[r]=B(a)),t}),t):"string"!=typeof e?t:e.split("|").reduce(((e,t)=>{const r=M(t);return r.name?(e[r.name]=B(r.params),e):e}),t):t}function B(e){const t=e=>"string"==typeof e&&"@"===e[0]?function(e){const t=t=>y(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(((r,n)=>(r[n]=t(e[n]),r)),{})}const M=e=>{let t=[];const r=e.split(":")[0];return e.includes(":")&&(t=e.split(":").slice(1).join(":").split(",")),{name:r,params:t}};let I=Object.assign({},{generateMessage:({field:e})=>`${e} is not valid.`,bails:!0,validateOnBlur:!0,validateOnChange:!0,validateOnInput:!1,validateOnModelUpdate:!0});const k=()=>I,T=e=>{I=Object.assign(Object.assign({},I),e)};async function R(e,t,n={}){const a=null==n?void 0:n.bails,i={name:(null==n?void 0:n.name)||"{field}",rules:t,bails:null==a||a,formData:(null==n?void 0:n.values)||{}},u=(await async function(e,t){if(v(e.rules))return async function(e,t,r){var n;return{errors:await t.validate(e,{abortEarly:null===(n=r.bails)||void 0===n||n}).then((()=>[])).catch((e=>{if("ValidationError"===e.name)return e.errors;throw e}))}}(t,e.rules,{bails:e.bails});if(r(e.rules)){const r={field:e.name,form:e.formData,value:t},n=await e.rules(t,r),a="string"!=typeof n&&n,i="string"==typeof n?n:N(r);return{errors:a?[]:[i]}}const n=Object.assign(Object.assign({},e),{rules:w(e.rules)}),a=[],i=Object.keys(n.rules),u=i.length;for(let r=0;r<u;r++){const u=i[r],o=await C(n,t,{name:u,params:n.rules[u]});if(o.error&&(a.push(o.error),e.bails))return{errors:a}}return{errors:a}}(i,e)).errors;return{errors:u,valid:!u.length}}async function C(e,t,r){const n=(a=r.name,i[a]);var a;if(!n)throw new Error(`No such validator '${r.name}' exists.`);const u=function(e,t){const r=e=>c(e)?e(t):e;if(Array.isArray(e))return e.map(r);return Object.keys(e).reduce(((t,n)=>(t[n]=r(e[n]),t)),{})}(r.params,e.formData),o={field:e.name,value:t,form:e.formData,rule:Object.assign(Object.assign({},r),{params:u})},l=await n(t,u,o);return"string"==typeof l?{error:l}:{error:l?void 0:N(o)}}function N(e){const t=k().generateMessage;return t?t(e):"Field is invalid"}var x=function e(t,r){if(t===r)return!0;if(t&&r&&"object"==typeof t&&"object"==typeof r){if(t.constructor!==r.constructor)return!1;var n,a,i;if(Array.isArray(t)){if((n=t.length)!=r.length)return!1;for(a=n;0!=a--;)if(!e(t[a],r[a]))return!1;return!0}if(t instanceof Map&&r instanceof Map){if(t.size!==r.size)return!1;for(a of t.entries())if(!r.has(a[0]))return!1;for(a of t.entries())if(!e(a[1],r.get(a[0])))return!1;return!0}if(t instanceof Set&&r instanceof Set){if(t.size!==r.size)return!1;for(a of t.entries())if(!r.has(a[0]))return!1;return!0}if(ArrayBuffer.isView(t)&&ArrayBuffer.isView(r)){if((n=t.length)!=r.length)return!1;for(a=n;0!=a--;)if(t[a]!==r[a])return!1;return!0}if(t.constructor===RegExp)return t.source===r.source&&t.flags===r.flags;if(t.valueOf!==Object.prototype.valueOf)return t.valueOf()===r.valueOf();if(t.toString!==Object.prototype.toString)return t.toString()===r.toString();if((n=(i=Object.keys(t)).length)!==Object.keys(r).length)return!1;for(a=n;0!=a--;)if(!Object.prototype.hasOwnProperty.call(r,i[a]))return!1;for(a=n;0!=a--;){var u=i[a];if(!e(t[u],r[u]))return!1}return!0}return t!=t&&r!=r};const $=Symbol("vee-validate-form"),P=Symbol("vee-validate-form-errors"),_=Symbol("vee-validate-form-initial-values"),D=Symbol("vee-validate-field-instance");let U=0;function z(e,n,a){const i=U>=Number.MAX_SAFE_INTEGER?0:++U,{initialValue:u,validateOnMount:o,bails:l,type:s,valueProp:m,label:p,validateOnValueUpdate:h,uncheckedValue:g}=function(e,t){const r=()=>({initialValue:void 0,validateOnMount:!1,bails:!0,rules:"",label:e,validateOnValueUpdate:!0});if(!t)return r();return Object.assign(Object.assign({},r()),t||{})}(t.unref(e),a),b=V($),{meta:F,errors:E,errorMessage:S,handleBlur:A,handleInput:B,resetValidationState:M,setValidationState:I,setErrors:k,value:T,checked:C}=function({name:e,initValue:r,form:n,type:a,valueProp:i}){const{errors:u,errorMessage:o,setErrors:l}=function(e,r){if(!r){const e=t.ref([]);return{errors:t.computed((()=>e.value)),errorMessage:t.computed((()=>e.value[0])),setErrors:t=>{e.value=Array.isArray(t)?t:[t]}}}const n=t.computed((()=>r.errorBag.value[t.unref(e)]||[]));return{errors:n,errorMessage:t.computed((()=>n.value[0])),setErrors:n=>{r.setFieldErrorBag(t.unref(e),n)}}}(e,n),s=V(_,void 0),c=t.computed((()=>{var n;return null!==(n=y(t.unref(s),t.unref(e)))&&void 0!==n?n:t.unref(r)})),v=function(e,r,n){if(!n)return t.ref(t.unref(e));n.stageInitialValue(t.unref(r),t.unref(e));return t.computed({get:()=>y(n.values,t.unref(r)),set(e){n.setFieldValue(t.unref(r),e)}})}(c,e,n),m=function(e,r,n){const a=t.reactive({touched:!1,pending:!1,valid:!0,validated:!1,initialValue:t.computed((()=>t.unref(e))),dirty:t.computed((()=>!x(r.value,t.unref(e))))});return t.watch(n,(e=>{a.valid=!e.length}),{immediate:!0,flush:"sync"}),a}(c,v,u),p=f(a)?t.computed((()=>Array.isArray(v.value)?v.value.includes(t.unref(i)):t.unref(i)===v.value)):void 0,h=()=>{m.touched=!0};function g(e){return l(e.errors),e}function b(a){var i,u;const o=t.unref(e),d=a&&"value"in a?a.value:null!==(i=y(t.unref(s),o))&&void 0!==i?i:r;n?n.setFieldValue(o,d,{force:!0}):v.value=d,l((null==a?void 0:a.errors)||[]),m.touched=null!==(u=null==a?void 0:a.touched)&&void 0!==u&&u,m.pending=!1,m.validated=!1}return{meta:m,errors:u,errorMessage:o,setErrors:l,setValidationState:g,resetValidationState:b,handleBlur:h,handleInput:e=>{f(a)||(v.value=d(e))},value:v,checked:p}}({name:e,initValue:u,form:b,type:s,valueProp:m}),N=t.computed((()=>{let a=t.unref(n);const i=t.unref(null==b?void 0:b.schema);return i&&!v(i)&&(a=function(e,t){if(!e)return;return e[t]}(i,t.unref(e))||a),v(a)||r(a)?a:w(a)}));async function P(){var r,n;let a;return F.pending=!0,F.validated=!0,a=b&&b.validateSchema?null!==(n=(await b.validateSchema("validated-only"))[t.unref(e)])&&void 0!==n?n:{valid:!0,errors:[]}:await R(T.value,N.value,{name:t.unref(p)||t.unref(e),values:null!==(r=null==b?void 0:b.values)&&void 0!==r?r:{},bails:l}),F.pending=!1,I(a)}async function z(){var r,n,a;let i;i=b&&b.validateSchema?null!==(a=null===(n=await b.validateSchema("silent"))||void 0===n?void 0:n[t.unref(e)])&&void 0!==a?a:{valid:!0,errors:[]}:await R(T.value,N.value,{name:t.unref(p)||t.unref(e),values:null!==(r=null==b?void 0:b.values)&&void 0!==r?r:{},bails:l}),F.valid=i.valid}let q;function G(){q=t.watch(T,h?P:z,{deep:!0})}function L(e){null==q||q(),M(e),G()}t.onMounted((()=>{if(o)return P();b&&b.validateSchema||z()})),G();const X={idx:-1,fid:i,name:e,value:T,meta:F,errors:E,errorMessage:S,type:s,valueProp:m,uncheckedValue:g,checked:C,resetField:L,handleReset:()=>L(),validate:P,handleChange:e=>{var r,n;if(C&&C.value===(null===(n=null===(r=e)||void 0===r?void 0:r.target)||void 0===n?void 0:n.checked))return;let a=d(e);return C&&"checkbox"===s&&!b&&(a=j(T.value,t.unref(m),t.unref(g))),T.value=a,h?void 0:P()},handleBlur:A,handleInput:B,setValidationState:I,setTouched:function(e){F.touched=e},setErrors:k};if(t.provide(D,X),t.isRef(n)&&"function"!=typeof t.unref(n)&&t.watch(n,((e,t)=>{if(!x(e,t))return P()}),{deep:!0}),!b)return X;b.register(X),t.onBeforeUnmount((()=>{b.unregister(X)}));const H=t.computed((()=>{const e=N.value;return!e||r(e)||v(e)?{}:Object.keys(e).reduce(((t,r)=>{const n=(a=e[r],Array.isArray(a)?a.filter(c):O(a).filter((e=>c(a[e]))).map((e=>a[e]))).map((e=>e.__locatorRef)).reduce(((e,t)=>{const r=y(b.values,t)||b.values[t];return void 0!==r&&(e[t]=r),e}),{});var a;return Object.assign(t,n),t}),{})}));return t.watch(H,((e,t)=>{if(!Object.keys(e).length)return;!x(e,t)&&(F.dirty?P():z())})),X}const q=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:()=>k().bails},label:{type:String,default:void 0},uncheckedValue:{type:null,default:void 0},modelValue:{type:null},modelModifiers:{type:null,default:()=>({})}},emits:["update:modelValue"],setup(e,r){const n=t.toRef(e,"rules"),a=t.toRef(e,"name"),i=t.toRef(e,"label"),o=t.toRef(e,"uncheckedValue"),{errors:l,value:s,errorMessage:d,validate:c,handleChange:v,handleBlur:m,handleInput:h,setTouched:y,resetField:g,handleReset:b,meta:F,checked:O,setErrors:V}=z(a,n,{validateOnMount:e.validateOnMount,bails:e.bails,type:r.attrs.type,initialValue:f(r.attrs.type)||"modelValue"in e?e.modelValue:r.attrs.value,valueProp:r.attrs.value,uncheckedValue:o,label:i,validateOnValueUpdate:!1}),E="modelValue"in e?function(e){v(e),r.emit("update:modelValue",s.value)}:v,S="modelValue"in e?function(e){h(e),r.emit("update:modelValue",s.value)}:h,A=t.computed((()=>{const{validateOnInput:t,validateOnChange:n,validateOnBlur:a,validateOnModelUpdate:i}=function(e){var t,r,n,a;const{validateOnInput:i,validateOnChange:u,validateOnBlur:o,validateOnModelUpdate:l}=k();return{validateOnInput:null!==(t=e.validateOnInput)&&void 0!==t?t:i,validateOnChange:null!==(r=e.validateOnChange)&&void 0!==r?r:u,validateOnBlur:null!==(n=e.validateOnBlur)&&void 0!==n?n:o,validateOnModelUpdate:null!==(a=e.validateOnModelUpdate)&&void 0!==a?a:l}}(e),u=[m,r.attrs.onBlur,a?c:void 0].filter(Boolean),o=[S,t?E:void 0,r.attrs.onInput].filter(Boolean),l=[S,n?E:void 0,r.attrs.onChange].filter(Boolean),d={name:e.name,onBlur:u,onInput:o,onChange:l};i&&(d["onUpdate:modelValue"]=[E]),f(r.attrs.type)&&O?d.checked=O.value:d.value=s.value;return p(G(e,r),r.attrs)&&delete d.value,d})),j=t.computed((()=>({field:A.value,value:s.value,meta:F,errors:l.value,errorMessage:d.value,validate:c,resetField:g,handleChange:E,handleInput:S,handleReset:b,handleBlur:m,setTouched:y,setErrors:V})));if("modelValue"in e){const r=t.toRef(e,"modelValue");t.watch(r,(t=>{t!==function(e,t){if(t.number)return function(e){const t=parseFloat(e);return isNaN(t)?e:t}(e);return e}(s.value,e.modelModifiers)&&(s.value=t,c())}))}return()=>{const n=t.resolveDynamicComponent(G(e,r)),a=u(r,j.value);return n?t.h(n,Object.assign(Object.assign({},r.attrs),A.value),a):a}}});function G(e,t){let r=e.as||"";return e.as||t.slots.default||(r="input"),r}function L(e){const r=t.ref([]),n=t.ref(!1),a=t.computed((()=>r.value.reduce(((e,r)=>{const n=t.unref(r.name);if(!e[n])return e[n]=r,r.idx=-1,e;const a=e[n];Array.isArray(a)||(a.idx=0,e[n]=[a]);const i=e[n];return r.idx=i.length,i.push(r),e}),{}))),i=t.ref(0),u=t.reactive({}),o={},{errorBag:l,setErrorBag:d,setFieldErrorBag:c}=function(e){const r=t.ref({});function n(e,t){r.value[e]=Array.isArray(t)?t:t?[t]:[]}function a(e){O(e).forEach((t=>{n(t,e[t])}))}e&&a(e);return{errorBag:r,setErrorBag:a,setFieldErrorBag:n}}(null==e?void 0:e.initialErrors),f=t.computed((()=>O(l.value).reduce(((e,t)=>{const r=l.value[t];return r&&r.length&&(e[t]=r[0]),e}),{}))),{readonlyInitialValues:m,initialValues:p,setInitialValues:h}=function(e,r,n){const a=t.ref(t.unref(n)||{}),i=t.computed((()=>a.value));function u(t,n=!1){if(a.value=Object.assign(Object.assign({},a.value),t),!n)return;const i=e=>e.meta.touched;O(e.value).forEach((t=>{const n=e.value[t];if(Array.isArray(n)?n.some(i):i(n))return;const u=y(a.value,t);g(r,t,u)}))}t.isRef(n)&&t.watch(n,(e=>{u(e,!0)}),{deep:!0});return t.provide(_,i),{readonlyInitialValues:i,initialValues:a,setInitialValues:u}}(a,u,null==e?void 0:e.initialValues),b=function(e,r,n){const a={touched:"some",pending:"some",valid:"every"},i=t.computed((()=>!x(r,t.unref(n))));return t.computed((()=>{const r=O(a).reduce(((t,r)=>{const n=a[r];return t[r]=e.value[n]((e=>e.meta[r])),t}),{});return Object.assign(Object.assign({initialValues:t.unref(n)},r),{dirty:i.value})}))}(r,u,m);function V(e,t){c(e,t)}function E(e){d(e)}function S(e,r,{force:n}={force:!1}){var i;const l=a.value[e];if(Array.isArray(l)&&"checkbox"===(null===(i=l[0])||void 0===i?void 0:i.type)&&!Array.isArray(r)){const t=j(y(u,e)||[],r,void 0);return g(u,e,t),void l.forEach((e=>{o[e.fid]=t}))}let s=r;Array.isArray(l)||"checkbox"!==(null==l?void 0:l.type)||n||(s=j(y(u,e),r,t.unref(l.uncheckedValue))),g(u,e,s),l&&Array.isArray(l)?l.forEach((e=>{o[e.fid]=s})):l&&(o[l.fid]=s)}function w(e){O(e).forEach((t=>{S(t,e[t])}))}function B(e,t){const r=a.value[e];r&&A(r,(e=>e.setTouched(t)))}function M(e){O(e).forEach((t=>{B(t,!!e[t])}))}const I=e=>{(null==e?void 0:e.values)&&h(e.values),r.value.forEach((e=>e.resetField())),(null==e?void 0:e.touched)&&M(e.touched),(null==e?void 0:e.errors)&&E(e.errors),i.value=(null==e?void 0:e.submitCount)||0};async function k(){function e(e,t){return t.errors.length?(e.valid=!1,e.errors[t.key]=t.errors[0],e):e}if(N.validateSchema)return N.validateSchema("force").then((t=>O(t).map((e=>({key:e,errors:t[e].errors}))).reduce(e,{errors:{},valid:!0})));return(await Promise.all(r.value.map((e=>e.validate().then((r=>({key:t.unref(e.name),errors:r.errors}))))))).reduce(e,{errors:{},valid:!0})}async function T(e){const r=a.value[e];return r?Array.isArray(r)?r.map((e=>e.validate()))[0]:r.validate():(t.warn(`field with name ${e} was not found`),Promise.resolve({errors:[],valid:!0}))}const R=e=>function(t){return t instanceof Event&&(t.preventDefault(),t.stopPropagation()),n.value=!0,i.value++,k().then((r=>{if(r.valid&&"function"==typeof e)return e(D.value,{evt:t,setErrors:E,setFieldError:V,setTouched:M,setFieldTouched:B,setValues:w,setFieldValue:S,resetForm:I})})).then((()=>{n.value=!1}),(e=>{throw n.value=!1,e}))};const C=null==e?void 0:e.validationSchema,N={register:function(e){r.value.push(e),t.isRef(e.name)&&(o[e.fid]=e.value.value,t.watch(e.name,(t=>{S(t,o[e.fid])}),{flush:"post"}))},unregister:function(e){var n,a;const i=r.value.indexOf(e);if(-1===i)return;r.value.splice(i,1);const l=e.fid;t.nextTick((()=>{delete o[l]}));const s=t.unref(e.name);if(-1===e.idx){if(r.value.find((e=>t.unref(e.name)===s)))return;return F(u,s),void F(p.value,s)}const d=null===(a=null===(n=y(u,s))||void 0===n?void 0:n.indexOf)||void 0===a?void 0:a.call(n,t.unref(e.valueProp));void 0!==d?-1!==d&&(Array.isArray(u[s])?F(u,`${s}.${d}`):(F(u,s),F(p.value,s))):F(u,s)},fieldsById:a,values:u,setFieldErrorBag:c,errorBag:l,schema:C,submitCount:i,validateSchema:v(t.unref(C))?e=>async function(e,r){const n=await t.unref(e.schema).validate(e.values,{abortEarly:!1}).then((()=>[])).catch((e=>{if("ValidationError"!==e.name)throw e;return e.inner||[]})),a=e.fieldsById.value||{},i=n.reduce(((e,t)=>(e[t.path]=t,e)),{});return O(a).reduce(((e,t)=>{const n=a[t],u=(i[t]||{errors:[]}).errors,o={errors:u,valid:!u.length};if(e[t]=o,"silent"===r)return A(n,(e=>e.meta.valid=o.valid)),e;const l=Array.isArray(n)?n.some((e=>e.meta.validated)):n.meta.validated;return"validated-only"!==r||l?(A(n,(e=>e.setValidationState(o)),!0),e):e}),{})}(N,e):void 0,validate:k,validateField:T,setFieldValue:S,setValues:w,setErrors:E,setFieldError:V,setFieldTouched:B,setTouched:M,resetForm:I,meta:b,isSubmitting:n,handleSubmit:R,stageInitialValue:function(e,t){g(u,e,t),g(p.value,e,t)}},D=t.computed((()=>r.value.reduce(((e,r)=>(g(e,t.unref(r.name),t.unref(r.value)),e)),{}))),U=R(((e,{evt:t})=>{(function(e){return s(e)&&e.target&&"submit"in e.target})(t)&&t.target.submit()}));return t.onMounted((()=>{(null==e?void 0:e.initialErrors)&&E(e.initialErrors),(null==e?void 0:e.initialTouched)&&M(e.initialTouched),(null==e?void 0:e.validateOnMount)?k():N.validateSchema&&N.validateSchema("silent")})),t.isRef(C)&&t.watch(C,(()=>{var e;null===(e=N.validateSchema)||void 0===e||e.call(N,"validated-only")})),t.provide($,N),t.provide(P,f),{errors:f,meta:b,values:u,isSubmitting:n,submitCount:i,validate:k,validateField:T,handleReset:()=>I(),resetForm:I,handleSubmit:R,submitForm:U,setFieldError:V,setErrors:E,setFieldValue:S,setValues:w,setFieldTouched:B,setTouched:M}}const X=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}},setup(e,r){const n=t.toRef(e,"initialValues"),a=t.toRef(e,"validationSchema"),{errors:i,values:o,meta:l,isSubmitting:d,submitCount:c,validate:v,validateField:f,handleReset:m,resetForm:p,handleSubmit:h,submitForm:y,setErrors:g,setFieldError:b,setFieldValue:F,setValues:O,setFieldTouched:V,setTouched:E}=L({validationSchema:a.value?a:void 0,initialValues:n,initialErrors:e.initialErrors,initialTouched:e.initialTouched,validateOnMount:e.validateOnMount}),S=e.onSubmit?h(e.onSubmit):y;function A(e){s(e)&&e.preventDefault(),m(),"function"==typeof r.attrs.onReset&&r.attrs.onReset()}function j(e,t){return h("function"!=typeof e||t?t:e)(e)}const w=t.computed((()=>({meta:l.value,errors:i.value,values:o,isSubmitting:d.value,submitCount:c.value,validate:v,validateField:f,handleSubmit:j,handleReset:m,submitForm:y,setErrors:g,setFieldError:b,setFieldValue:F,setValues:O,setFieldTouched:V,setTouched:E,resetForm:p})));return function(){"setErrors"in this||(this.setFieldError=b,this.setErrors=g,this.setFieldValue=F,this.setValues=O,this.setFieldTouched=V,this.setTouched=E,this.resetForm=p,this.validate=v,this.validateField=f);const n=u(r,w.value);if(!e.as)return n;const a="form"===e.as?{novalidate:!0}:{};return t.h("form"===e.as?e.as:t.resolveDynamicComponent(e.as),Object.assign(Object.assign(Object.assign({},a),r.attrs),{onSubmit:S,onReset:A}),n)}}}),H=t.defineComponent({props:{as:{type:String,default:void 0},name:{type:String,required:!0}},setup(e,r){const n=t.inject(P,void 0),a=t.computed((()=>null==n?void 0:n.value[e.name]));return()=>{if(!a.value)return;const n=u(r,{message:a.value}),i=e.as?t.resolveDynamicComponent(e.as):e.as,o=Object.assign({role:"alert"},r.attrs);return!i&&(null==n?void 0:n.length)?n:(null==n?void 0:n.length)?t.h(i,o,n):t.h(i||"span",o,a.value)}}});e.ErrorMessage=H,e.Field=q,e.Form=X,e.configure=T,e.defineRule=function(e,t){!function(e,t){if(r(t))return;throw new Error(`Extension Error: The validator '${e}' must be a function.`)}(e,t),i[e]=t},e.useField=z,e.useFieldError=function(e){const r=V(P),n=e?void 0:t.inject(D);return t.computed((()=>{var a;return e?null===(a=null==r?void 0:r.value)||void 0===a?void 0:a[t.unref(e)]:null==n?void 0:n.errorMessage.value}))},e.useFieldValue=function(e){const r=V($),n=e?void 0:t.inject(D);return t.computed((()=>{var a;return e?y(null==r?void 0:r.values,t.unref(e)):null===(a=null==n?void 0:n.value)||void 0===a?void 0:a.value}))},e.useForm=L,e.useFormErrors=function(){const e=V(P);return e||E("No vee-validate <Form /> or `useForm` was detected in the component tree"),e||t.computed((()=>({})))},e.useFormValues=function(){const e=V($);return e||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 r=V($);let n=e?void 0:t.inject(D);return t.computed((()=>(e&&(n=S(null==r?void 0:r.fieldsById.value[t.unref(e)])),n?n.meta.dirty:(E(`field with name ${t.unref(e)} was not found`),!1))))},e.useIsFieldTouched=function(e){const r=V($);let n=e?void 0:t.inject(D);return t.computed((()=>(e&&(n=S(null==r?void 0:r.fieldsById.value[t.unref(e)])),n?n.meta.touched:(E(`field with name ${t.unref(e)} was not found`),!1))))},e.useIsFieldValid=function(e){const r=V($);let n=e?void 0:t.inject(D);return t.computed((()=>(e&&(n=S(null==r?void 0:r.fieldsById.value[t.unref(e)])),n?n.meta.valid:(E(`field with name ${t.unref(e)} was not found`),!1))))},e.useIsFormDirty=function(){const e=V($);return e||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=V($);return e||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=V($);return e||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=V($);return e||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.useResetForm=function(){const e=V($);return e||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=V($);return e||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=V($);t||E("No vee-validate <Form /> or `useForm` was detected in the component tree");const r=t?t.handleSubmit(e):void 0;return function(e){if(r)return r(e)}},e.useValidateField=function(e){const r=V($);let n=e?void 0:t.inject(D);return function(){return e&&(n=S(null==r?void 0:r.fieldsById.value[t.unref(e)])),n?n.validate():(E(`field with name ${t.unref(e)} was not found`),Promise.resolve({errors:[],valid:!0}))}},e.useValidateForm=function(){const e=V($);return e||E("No vee-validate <Form /> or `useForm` was detected in the component tree"),function(){return e?e.validate():Promise.resolve({errors:{},valid:!0})}},e.validate=R,Object.defineProperty(e,"__esModule",{value:!0})}));
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "vee-validate",
3
- "version": "4.2.3",
3
+ "version": "4.3.0",
4
4
  "description": "Form Validation for Vue.js",
5
5
  "author": "Abdelrahman Awad <logaretm1@gmail.com>",
6
6
  "license": "MIT",
@@ -26,5 +26,5 @@
26
26
  "peerDependencies": {
27
27
  "vue": "^3.0.0"
28
28
  },
29
- "gitHead": "85649d9bf57199b3b29087253228172fd4b76087"
29
+ "gitHead": "c5e12a92e4b903f0ee44c970fdd538c64675ca66"
30
30
  }