vee-validate 4.15.0 → 5.0.0-beta.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +178 -178
- package/dist/vee-validate.cjs +100 -116
- package/dist/vee-validate.d.ts +44 -50
- package/dist/vee-validate.iife.js +100 -116
- package/dist/vee-validate.iife.prod.js.mjs +3 -3
- package/dist/vee-validate.mjs +101 -117
- package/package.json +3 -1
package/dist/vee-validate.cjs
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* vee-validate
|
|
3
|
-
* (c)
|
|
2
|
+
* vee-validate v5.0.0-beta.0
|
|
3
|
+
* (c) 2025 Abdelrahman Awad
|
|
4
4
|
* @license MIT
|
|
5
5
|
*/
|
|
6
6
|
'use strict';
|
|
@@ -164,11 +164,8 @@ const isClient = typeof window !== 'undefined';
|
|
|
164
164
|
function isLocator(value) {
|
|
165
165
|
return isCallable(value) && !!value.__locatorRef;
|
|
166
166
|
}
|
|
167
|
-
function
|
|
168
|
-
return
|
|
169
|
-
}
|
|
170
|
-
function isYupValidator(value) {
|
|
171
|
-
return !!value && isCallable(value.validate);
|
|
167
|
+
function isStandardSchema(value) {
|
|
168
|
+
return isObject(value) && '~standard' in value;
|
|
172
169
|
}
|
|
173
170
|
function hasCheckedAttr(type) {
|
|
174
171
|
return type === 'checkbox' || type === 'radio';
|
|
@@ -312,14 +309,16 @@ function isEqual(a, b) {
|
|
|
312
309
|
return a.valueOf() === b.valueOf();
|
|
313
310
|
if (a.toString !== Object.prototype.toString)
|
|
314
311
|
return a.toString() === b.toString();
|
|
312
|
+
// Remove undefined values before object comparison
|
|
313
|
+
a = normalizeObject(a);
|
|
314
|
+
b = normalizeObject(b);
|
|
315
315
|
keys = Object.keys(a);
|
|
316
|
-
length = keys.length
|
|
317
|
-
if (length !== Object.keys(b).length
|
|
316
|
+
length = keys.length;
|
|
317
|
+
if (length !== Object.keys(b).length)
|
|
318
318
|
return false;
|
|
319
|
-
for (i = length; i-- !== 0;)
|
|
319
|
+
for (i = length; i-- !== 0;)
|
|
320
320
|
if (!Object.prototype.hasOwnProperty.call(b, keys[i]))
|
|
321
321
|
return false;
|
|
322
|
-
}
|
|
323
322
|
for (i = length; i-- !== 0;) {
|
|
324
323
|
// eslint-disable-next-line no-var
|
|
325
324
|
var key = keys[i];
|
|
@@ -331,15 +330,13 @@ function isEqual(a, b) {
|
|
|
331
330
|
// true if both NaN, false otherwise
|
|
332
331
|
return a !== a && b !== b;
|
|
333
332
|
}
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
}
|
|
342
|
-
return result;
|
|
333
|
+
/**
|
|
334
|
+
* Returns a new object where keys with an `undefined` value are removed.
|
|
335
|
+
*
|
|
336
|
+
* @param a object to normalize
|
|
337
|
+
*/
|
|
338
|
+
function normalizeObject(a) {
|
|
339
|
+
return Object.fromEntries(Object.entries(a).filter(([, value]) => value !== undefined));
|
|
343
340
|
}
|
|
344
341
|
function isFile(a) {
|
|
345
342
|
if (!isClient) {
|
|
@@ -348,6 +345,27 @@ function isFile(a) {
|
|
|
348
345
|
return a instanceof File;
|
|
349
346
|
}
|
|
350
347
|
|
|
348
|
+
// src/getDotPath/getDotPath.ts
|
|
349
|
+
function getDotPath(issue) {
|
|
350
|
+
if (issue.path?.length) {
|
|
351
|
+
let dotPath = "";
|
|
352
|
+
for (const item of issue.path) {
|
|
353
|
+
const key = typeof item === "object" ? item.key : item;
|
|
354
|
+
if (typeof key === "string" || typeof key === "number") {
|
|
355
|
+
if (dotPath) {
|
|
356
|
+
dotPath += `.${key}`;
|
|
357
|
+
} else {
|
|
358
|
+
dotPath += key;
|
|
359
|
+
}
|
|
360
|
+
} else {
|
|
361
|
+
return null;
|
|
362
|
+
}
|
|
363
|
+
}
|
|
364
|
+
return dotPath;
|
|
365
|
+
}
|
|
366
|
+
return null;
|
|
367
|
+
}
|
|
368
|
+
|
|
351
369
|
function cleanupNonNestedPath(path) {
|
|
352
370
|
if (isNotNestedPath(path)) {
|
|
353
371
|
return path.replace(/\[|\]/gi, '');
|
|
@@ -563,6 +581,31 @@ function debounceNextTick(inner) {
|
|
|
563
581
|
return new Promise(resolve => resolves.push(resolve));
|
|
564
582
|
};
|
|
565
583
|
}
|
|
584
|
+
function _combineIssueItems(items, getPath) {
|
|
585
|
+
const issueMap = {};
|
|
586
|
+
for (const item of items) {
|
|
587
|
+
const path = getPath(item);
|
|
588
|
+
if (!issueMap[path]) {
|
|
589
|
+
issueMap[path] = {
|
|
590
|
+
path,
|
|
591
|
+
messages: [],
|
|
592
|
+
};
|
|
593
|
+
}
|
|
594
|
+
if ('messages' in item) {
|
|
595
|
+
issueMap[path].messages.push(...item.messages);
|
|
596
|
+
}
|
|
597
|
+
else {
|
|
598
|
+
issueMap[path].messages.push(item.message);
|
|
599
|
+
}
|
|
600
|
+
}
|
|
601
|
+
return Object.values(issueMap);
|
|
602
|
+
}
|
|
603
|
+
/**
|
|
604
|
+
* Aggregates standard schema issues by path.
|
|
605
|
+
*/
|
|
606
|
+
function combineStandardIssues(issues) {
|
|
607
|
+
return _combineIssueItems(issues, issue => { var _a; return (issue.path ? (_a = getDotPath(issue)) !== null && _a !== void 0 ? _a : '' : ''); });
|
|
608
|
+
}
|
|
566
609
|
|
|
567
610
|
function normalizeChildren(tag, context, slotProps) {
|
|
568
611
|
if (!context.slots.default) {
|
|
@@ -769,8 +812,8 @@ async function validate(value, rules, options = {}) {
|
|
|
769
812
|
*/
|
|
770
813
|
async function _validate(field, value) {
|
|
771
814
|
const rules = field.rules;
|
|
772
|
-
if (
|
|
773
|
-
return
|
|
815
|
+
if (isStandardSchema(rules)) {
|
|
816
|
+
return validateFieldWithStandardSchema(value, Object.assign(Object.assign({}, field), { rules }));
|
|
774
817
|
}
|
|
775
818
|
// if a generic function or chain of generic functions
|
|
776
819
|
if (isCallable(rules) || Array.isArray(rules)) {
|
|
@@ -832,58 +875,24 @@ async function _validate(field, value) {
|
|
|
832
875
|
errors,
|
|
833
876
|
};
|
|
834
877
|
}
|
|
835
|
-
function isYupError(err) {
|
|
836
|
-
return !!err && err.name === 'ValidationError';
|
|
837
|
-
}
|
|
838
|
-
function yupToTypedSchema(yupSchema) {
|
|
839
|
-
const schema = {
|
|
840
|
-
__type: 'VVTypedSchema',
|
|
841
|
-
async parse(values, context) {
|
|
842
|
-
var _a;
|
|
843
|
-
try {
|
|
844
|
-
const output = await yupSchema.validate(values, { abortEarly: false, context: (context === null || context === void 0 ? void 0 : context.formData) || {} });
|
|
845
|
-
return {
|
|
846
|
-
output,
|
|
847
|
-
errors: [],
|
|
848
|
-
};
|
|
849
|
-
}
|
|
850
|
-
catch (err) {
|
|
851
|
-
// Yup errors have a name prop one them.
|
|
852
|
-
// https://github.com/jquense/yup#validationerrorerrors-string--arraystring-value-any-path-string
|
|
853
|
-
if (!isYupError(err)) {
|
|
854
|
-
throw err;
|
|
855
|
-
}
|
|
856
|
-
if (!((_a = err.inner) === null || _a === void 0 ? void 0 : _a.length) && err.errors.length) {
|
|
857
|
-
return { errors: [{ path: err.path, errors: err.errors }] };
|
|
858
|
-
}
|
|
859
|
-
const errors = err.inner.reduce((acc, curr) => {
|
|
860
|
-
const path = curr.path || '';
|
|
861
|
-
if (!acc[path]) {
|
|
862
|
-
acc[path] = { errors: [], path };
|
|
863
|
-
}
|
|
864
|
-
acc[path].errors.push(...curr.errors);
|
|
865
|
-
return acc;
|
|
866
|
-
}, {});
|
|
867
|
-
return { errors: Object.values(errors) };
|
|
868
|
-
}
|
|
869
|
-
},
|
|
870
|
-
};
|
|
871
|
-
return schema;
|
|
872
|
-
}
|
|
873
878
|
/**
|
|
874
879
|
* Handles yup validation
|
|
875
880
|
*/
|
|
876
|
-
async function
|
|
877
|
-
const
|
|
878
|
-
|
|
881
|
+
async function validateFieldWithStandardSchema(value, context) {
|
|
882
|
+
const result = await context.rules['~standard'].validate(value);
|
|
883
|
+
if (!result.issues) {
|
|
884
|
+
return {
|
|
885
|
+
value: result.value,
|
|
886
|
+
errors: [],
|
|
887
|
+
};
|
|
888
|
+
}
|
|
879
889
|
const messages = [];
|
|
880
|
-
for (const error of result.
|
|
881
|
-
if (error.
|
|
882
|
-
messages.push(
|
|
890
|
+
for (const error of result.issues) {
|
|
891
|
+
if (error.message) {
|
|
892
|
+
messages.push(error.message);
|
|
883
893
|
}
|
|
884
894
|
}
|
|
885
895
|
return {
|
|
886
|
-
value: result.value,
|
|
887
896
|
errors: messages,
|
|
888
897
|
};
|
|
889
898
|
}
|
|
@@ -939,27 +948,33 @@ function fillTargetValues(params, crossTable) {
|
|
|
939
948
|
return acc;
|
|
940
949
|
}, {});
|
|
941
950
|
}
|
|
942
|
-
async function
|
|
943
|
-
const
|
|
944
|
-
const validationResult = await typedSchema.parse(klona(values), { formData: klona(values) });
|
|
951
|
+
async function validateStandardSchema(schema, values) {
|
|
952
|
+
const validationResult = await schema['~standard'].validate(klona(values));
|
|
945
953
|
const results = {};
|
|
946
954
|
const errors = {};
|
|
947
|
-
|
|
948
|
-
|
|
949
|
-
|
|
950
|
-
|
|
951
|
-
|
|
952
|
-
|
|
955
|
+
if (!validationResult.issues) {
|
|
956
|
+
return {
|
|
957
|
+
valid: true,
|
|
958
|
+
results: {},
|
|
959
|
+
errors: {},
|
|
960
|
+
values: validationResult.value,
|
|
961
|
+
source: 'schema',
|
|
962
|
+
};
|
|
963
|
+
}
|
|
964
|
+
const combinedIssues = combineStandardIssues(validationResult.issues || []);
|
|
965
|
+
for (const error of combinedIssues) {
|
|
966
|
+
const messages = error.messages;
|
|
967
|
+
const path = error.path;
|
|
953
968
|
results[path] = { valid: !messages.length, errors: messages };
|
|
954
969
|
if (messages.length) {
|
|
955
970
|
errors[path] = messages[0];
|
|
956
971
|
}
|
|
957
972
|
}
|
|
958
973
|
return {
|
|
959
|
-
valid: !
|
|
974
|
+
valid: !combinedIssues.length,
|
|
960
975
|
results,
|
|
961
976
|
errors,
|
|
962
|
-
values:
|
|
977
|
+
values: undefined,
|
|
963
978
|
source: 'schema',
|
|
964
979
|
};
|
|
965
980
|
}
|
|
@@ -1004,7 +1019,7 @@ function useFieldState(path, init) {
|
|
|
1004
1019
|
if (!init.form) {
|
|
1005
1020
|
const { errors, setErrors } = createFieldErrors();
|
|
1006
1021
|
const id = ID_COUNTER >= Number.MAX_SAFE_INTEGER ? 0 : ++ID_COUNTER;
|
|
1007
|
-
const meta = createFieldMeta(value, initialValue, errors
|
|
1022
|
+
const meta = createFieldMeta(value, initialValue, errors);
|
|
1008
1023
|
function setState(state) {
|
|
1009
1024
|
var _a;
|
|
1010
1025
|
if ('value' in state) {
|
|
@@ -1036,7 +1051,6 @@ function useFieldState(path, init) {
|
|
|
1036
1051
|
label: init.label,
|
|
1037
1052
|
type: init.type,
|
|
1038
1053
|
validate: init.validate,
|
|
1039
|
-
schema: init.schema,
|
|
1040
1054
|
});
|
|
1041
1055
|
const errors = vue.computed(() => state.errors);
|
|
1042
1056
|
function setState(state) {
|
|
@@ -1132,13 +1146,11 @@ function resolveModelValue(modelValue, form, initialValue, path) {
|
|
|
1132
1146
|
/**
|
|
1133
1147
|
* Creates meta flags state and some associated effects with them
|
|
1134
1148
|
*/
|
|
1135
|
-
function createFieldMeta(currentValue, initialValue, errors
|
|
1136
|
-
const isRequired = vue.computed(() => { var _a, _b, _c; return (_c = (_b = (_a = vue.toValue(schema)) === null || _a === void 0 ? void 0 : _a.describe) === null || _b === void 0 ? void 0 : _b.call(_a).required) !== null && _c !== void 0 ? _c : false; });
|
|
1149
|
+
function createFieldMeta(currentValue, initialValue, errors) {
|
|
1137
1150
|
const meta = vue.reactive({
|
|
1138
1151
|
touched: false,
|
|
1139
1152
|
pending: false,
|
|
1140
1153
|
valid: true,
|
|
1141
|
-
required: isRequired,
|
|
1142
1154
|
validated: !!vue.unref(errors).length,
|
|
1143
1155
|
initialValue: vue.computed(() => vue.unref(initialValue)),
|
|
1144
1156
|
dirty: vue.computed(() => {
|
|
@@ -1186,15 +1198,11 @@ function _useField(path, rules, opts) {
|
|
|
1186
1198
|
return undefined;
|
|
1187
1199
|
}
|
|
1188
1200
|
const rulesValue = vue.unref(rules);
|
|
1189
|
-
if (
|
|
1190
|
-
isTypedSchema(rulesValue) ||
|
|
1191
|
-
isCallable(rulesValue) ||
|
|
1192
|
-
Array.isArray(rulesValue)) {
|
|
1201
|
+
if (isStandardSchema(rulesValue) || isCallable(rulesValue) || Array.isArray(rulesValue)) {
|
|
1193
1202
|
return rulesValue;
|
|
1194
1203
|
}
|
|
1195
1204
|
return normalizeRules(rulesValue);
|
|
1196
1205
|
});
|
|
1197
|
-
const isTyped = !isCallable(validator.value) && isTypedSchema(vue.toValue(rules));
|
|
1198
1206
|
const { id, value, initialValue, meta, setState, errors, flags } = useFieldState(name, {
|
|
1199
1207
|
modelValue,
|
|
1200
1208
|
form,
|
|
@@ -1202,7 +1210,6 @@ function _useField(path, rules, opts) {
|
|
|
1202
1210
|
label,
|
|
1203
1211
|
type,
|
|
1204
1212
|
validate: validator.value ? validate$1 : undefined,
|
|
1205
|
-
schema: isTyped ? rules : undefined,
|
|
1206
1213
|
});
|
|
1207
1214
|
const errorMessage = vue.computed(() => errors.value[0]);
|
|
1208
1215
|
if (syncVModel) {
|
|
@@ -1354,12 +1361,8 @@ function _useField(path, rules, opts) {
|
|
|
1354
1361
|
// extract cross-field dependencies in a computed prop
|
|
1355
1362
|
const dependencies = vue.computed(() => {
|
|
1356
1363
|
const rulesVal = validator.value;
|
|
1357
|
-
// is falsy, a function schema or a
|
|
1358
|
-
if (!rulesVal ||
|
|
1359
|
-
isCallable(rulesVal) ||
|
|
1360
|
-
isYupValidator(rulesVal) ||
|
|
1361
|
-
isTypedSchema(rulesVal) ||
|
|
1362
|
-
Array.isArray(rulesVal)) {
|
|
1364
|
+
// is falsy, a function schema or a standard schema
|
|
1365
|
+
if (!rulesVal || isCallable(rulesVal) || isStandardSchema(rulesVal) || Array.isArray(rulesVal)) {
|
|
1363
1366
|
return {};
|
|
1364
1367
|
}
|
|
1365
1368
|
return Object.keys(rulesVal).reduce((acc, rule) => {
|
|
@@ -1734,10 +1737,6 @@ const PRIVATE_PATH_STATE_KEYS = ['bails', 'fieldsCount', 'id', 'multiple', 'type
|
|
|
1734
1737
|
function resolveInitialValues(opts) {
|
|
1735
1738
|
const givenInitial = (opts === null || opts === void 0 ? void 0 : opts.initialValues) || {};
|
|
1736
1739
|
const providedValues = Object.assign({}, vue.toValue(givenInitial));
|
|
1737
|
-
const schema = vue.unref(opts === null || opts === void 0 ? void 0 : opts.validationSchema);
|
|
1738
|
-
if (schema && isTypedSchema(schema) && isCallable(schema.cast)) {
|
|
1739
|
-
return klona(schema.cast(providedValues) || {});
|
|
1740
|
-
}
|
|
1741
1740
|
return klona(providedValues);
|
|
1742
1741
|
}
|
|
1743
1742
|
function useForm(opts) {
|
|
@@ -1872,19 +1871,6 @@ function useForm(opts) {
|
|
|
1872
1871
|
if (unsetBatchIndex !== -1) {
|
|
1873
1872
|
UNSET_BATCH.splice(unsetBatchIndex, 1);
|
|
1874
1873
|
}
|
|
1875
|
-
const isRequired = vue.computed(() => {
|
|
1876
|
-
var _a, _b, _c, _d;
|
|
1877
|
-
const schemaValue = vue.toValue(schema);
|
|
1878
|
-
if (isTypedSchema(schemaValue)) {
|
|
1879
|
-
return (_b = (_a = schemaValue.describe) === null || _a === void 0 ? void 0 : _a.call(schemaValue, vue.toValue(path)).required) !== null && _b !== void 0 ? _b : false;
|
|
1880
|
-
}
|
|
1881
|
-
// Path own schema
|
|
1882
|
-
const configSchemaValue = vue.toValue(config === null || config === void 0 ? void 0 : config.schema);
|
|
1883
|
-
if (isTypedSchema(configSchemaValue)) {
|
|
1884
|
-
return (_d = (_c = configSchemaValue.describe) === null || _c === void 0 ? void 0 : _c.call(configSchemaValue).required) !== null && _d !== void 0 ? _d : false;
|
|
1885
|
-
}
|
|
1886
|
-
return false;
|
|
1887
|
-
});
|
|
1888
1874
|
const id = FIELD_ID_COUNTER++;
|
|
1889
1875
|
const state = vue.reactive({
|
|
1890
1876
|
id,
|
|
@@ -1893,7 +1879,6 @@ function useForm(opts) {
|
|
|
1893
1879
|
pending: false,
|
|
1894
1880
|
valid: true,
|
|
1895
1881
|
validated: !!((_a = initialErrors[pathValue]) === null || _a === void 0 ? void 0 : _a.length),
|
|
1896
|
-
required: isRequired,
|
|
1897
1882
|
initialValue,
|
|
1898
1883
|
errors: vue.shallowRef([]),
|
|
1899
1884
|
bails: (_b = config === null || config === void 0 ? void 0 : config.bails) !== null && _b !== void 0 ? _b : false,
|
|
@@ -2306,7 +2291,6 @@ function useForm(opts) {
|
|
|
2306
2291
|
function resetForm(resetState, opts) {
|
|
2307
2292
|
let newValues = klona((resetState === null || resetState === void 0 ? void 0 : resetState.values) ? resetState.values : originalInitialValues.value);
|
|
2308
2293
|
newValues = (opts === null || opts === void 0 ? void 0 : opts.force) ? newValues : merge(originalInitialValues.value, newValues);
|
|
2309
|
-
newValues = isTypedSchema(schema) && isCallable(schema.cast) ? schema.cast(newValues) : newValues;
|
|
2310
2294
|
setInitialValues(newValues, { force: opts === null || opts === void 0 ? void 0 : opts.force });
|
|
2311
2295
|
mutateAllPathState(state => {
|
|
2312
2296
|
var _a;
|
|
@@ -2419,8 +2403,8 @@ function useForm(opts) {
|
|
|
2419
2403
|
return { valid: true, results: {}, errors: {}, source: 'none' };
|
|
2420
2404
|
}
|
|
2421
2405
|
isValidating.value = true;
|
|
2422
|
-
const formResult =
|
|
2423
|
-
? await
|
|
2406
|
+
const formResult = isStandardSchema(schemaValue)
|
|
2407
|
+
? await validateStandardSchema(schemaValue, formValues)
|
|
2424
2408
|
: await validateObjectSchema(schemaValue, formValues, {
|
|
2425
2409
|
names: fieldNames.value,
|
|
2426
2410
|
bailsMap: fieldBailsMap.value,
|
package/dist/vee-validate.d.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import * as vue from 'vue';
|
|
2
2
|
import { MaybeRef, Ref, MaybeRefOrGetter, ComputedRef, PropType, VNode, UnwrapRef, InjectionKey } from 'vue';
|
|
3
3
|
import { PartialDeep } from 'type-fest';
|
|
4
|
+
import { StandardSchemaV1 } from '@standard-schema/spec';
|
|
4
5
|
|
|
5
6
|
type BrowserNativeObject = Date | FileList | File;
|
|
6
7
|
type Primitive = null | undefined | string | number | boolean | symbol | bigint;
|
|
@@ -59,24 +60,41 @@ type AnyIsEqual<T1, T2> = T1 extends T2 ? (IsEqual<T1, T2> extends true ? true :
|
|
|
59
60
|
*/
|
|
60
61
|
type TupleKeys<T extends ReadonlyArray<any>> = Exclude<keyof T, keyof any[]>;
|
|
61
62
|
/**
|
|
62
|
-
* Helper type
|
|
63
|
-
*
|
|
64
|
-
*
|
|
63
|
+
* Helper type to construct tuple key paths and recurse into its elements.
|
|
64
|
+
*
|
|
65
|
+
* See {@link Path}
|
|
66
|
+
*/
|
|
67
|
+
type PathInternalTuple<TValue extends ReadonlyArray<any>, TraversedTypes> = {
|
|
68
|
+
[Key in TupleKeys<TValue> & string]: `[${Key}]` | `[${Key}]${PathInternal<TValue[Key], TraversedTypes, false>}`;
|
|
69
|
+
}[TupleKeys<TValue> & string];
|
|
70
|
+
/**
|
|
71
|
+
* Helper type to construct array key paths and recurse into its elements.
|
|
72
|
+
*
|
|
73
|
+
* See {@link Path}
|
|
74
|
+
*/
|
|
75
|
+
type PathInternalArray<TValue extends ReadonlyArray<any>, TraversedTypes> = `[${ArrayKey}]` | `[${ArrayKey}]${PathInternal<TValue[ArrayKey], TraversedTypes, false>}`;
|
|
76
|
+
/**
|
|
77
|
+
* Helper type to construct object key paths and recurse into its nested values.
|
|
78
|
+
*
|
|
79
|
+
* See {@link Path}
|
|
80
|
+
*/
|
|
81
|
+
type PathInternalObject<TValue, TraversedTypes, First extends boolean> = {
|
|
82
|
+
[Key in keyof TValue & string]: First extends true ? `${Key}` | `${Key}${PathInternal<TValue[Key], TraversedTypes, false>}` : `.${Key}` | `.${Key}${PathInternal<TValue[Key], TraversedTypes, false>}`;
|
|
83
|
+
}[keyof TValue & string];
|
|
84
|
+
/**
|
|
85
|
+
* Helper type to construct nested any object key paths.
|
|
65
86
|
*
|
|
66
87
|
* See {@link Path}
|
|
67
88
|
*/
|
|
68
|
-
type
|
|
89
|
+
type PathInternalAny = `.${string}` | `[${string}]` | `[${string}].${string}`;
|
|
69
90
|
/**
|
|
70
91
|
* Helper type for recursively constructing paths through a type.
|
|
71
|
-
*
|
|
92
|
+
*
|
|
93
|
+
* This obscures internal type params TraversedTypes and First from ed contract.
|
|
72
94
|
*
|
|
73
95
|
* See {@link Path}
|
|
74
96
|
*/
|
|
75
|
-
type PathInternal<
|
|
76
|
-
[K in TupleKeys<T>]-?: PathImpl<K & string, T[K], TraversedTypes>;
|
|
77
|
-
}[TupleKeys<T>] : PathImpl<ArrayKey, V, TraversedTypes> : {
|
|
78
|
-
[K in keyof T]-?: PathImpl<K & string, T[K], TraversedTypes>;
|
|
79
|
-
}[keyof T];
|
|
97
|
+
type PathInternal<TValue, TraversedTypes, First extends boolean> = TValue extends Primitive | BrowserNativeObject ? IsAny<TValue> extends true ? PathInternalAny : never : TValue extends ReadonlyArray<any> ? true extends AnyIsEqual<TraversedTypes, TValue> ? never : IsTuple<TValue> extends true ? PathInternalTuple<TValue, TraversedTypes | TValue> : PathInternalArray<TValue, TraversedTypes | TValue> : TValue extends Record<string, any> ? PathInternalObject<TValue, TraversedTypes | TValue, First> : '';
|
|
80
98
|
/**
|
|
81
99
|
* Helper type for recursively constructing paths through a type.
|
|
82
100
|
* This actually constructs the strings and recurses into nested
|
|
@@ -125,7 +143,7 @@ type PathValue<T, P extends Path<T> | ArrayPath<T>> = T extends any ? P extends
|
|
|
125
143
|
* Path<{foo: {bar: string}}> = 'foo' | 'foo.bar'
|
|
126
144
|
* ```
|
|
127
145
|
*/
|
|
128
|
-
type Path<T> = T extends any ? PathInternal<T> : never;
|
|
146
|
+
type Path<T> = T extends any ? PathInternal<T, T, true> & string : never;
|
|
129
147
|
|
|
130
148
|
type GenericObject = Record<string, any>;
|
|
131
149
|
type MaybeArray<T> = T | T[];
|
|
@@ -160,32 +178,6 @@ interface ValidationResult<TValue = unknown> {
|
|
|
160
178
|
type FlattenAndMapPathsValidationResult<TInput extends GenericObject, TOutput extends GenericObject> = {
|
|
161
179
|
[K in Path<TInput>]: ValidationResult<TOutput[K]>;
|
|
162
180
|
};
|
|
163
|
-
interface TypedSchemaError {
|
|
164
|
-
path?: string;
|
|
165
|
-
errors: string[];
|
|
166
|
-
}
|
|
167
|
-
interface TypedSchemaPathDescription {
|
|
168
|
-
required: boolean;
|
|
169
|
-
exists: boolean;
|
|
170
|
-
}
|
|
171
|
-
interface TypedSchemaContext {
|
|
172
|
-
formData: GenericObject;
|
|
173
|
-
}
|
|
174
|
-
interface TypedSchema<TInput = any, TOutput = TInput> {
|
|
175
|
-
__type: 'VVTypedSchema';
|
|
176
|
-
parse(values: TInput, context?: TypedSchemaContext): Promise<{
|
|
177
|
-
value?: TOutput;
|
|
178
|
-
errors: TypedSchemaError[];
|
|
179
|
-
}>;
|
|
180
|
-
cast?(values: Partial<TInput>): TInput;
|
|
181
|
-
describe?(path?: Path<TInput>): Partial<TypedSchemaPathDescription>;
|
|
182
|
-
}
|
|
183
|
-
type InferOutput<TSchema extends TypedSchema> = TSchema extends TypedSchema<any, infer TOutput> ? TOutput : never;
|
|
184
|
-
type InferInput<TSchema extends TypedSchema> = TSchema extends TypedSchema<infer TInput, any> ? TInput : never;
|
|
185
|
-
type YupSchema<TValues = any> = {
|
|
186
|
-
__isYupSchema__: boolean;
|
|
187
|
-
validate(value: any, options: GenericObject): Promise<any>;
|
|
188
|
-
};
|
|
189
181
|
type Locator = {
|
|
190
182
|
__locatorRef: string;
|
|
191
183
|
} & ((values: GenericObject) => unknown);
|
|
@@ -194,7 +186,6 @@ interface FieldMeta<TValue> {
|
|
|
194
186
|
dirty: boolean;
|
|
195
187
|
valid: boolean;
|
|
196
188
|
validated: boolean;
|
|
197
|
-
required: boolean;
|
|
198
189
|
pending: boolean;
|
|
199
190
|
initialValue?: TValue;
|
|
200
191
|
}
|
|
@@ -227,15 +218,18 @@ interface PathStateConfig<TOutput> {
|
|
|
227
218
|
label: MaybeRefOrGetter<string | undefined>;
|
|
228
219
|
type: InputType;
|
|
229
220
|
validate: FieldValidator<TOutput>;
|
|
230
|
-
schema?: MaybeRefOrGetter<
|
|
221
|
+
schema?: MaybeRefOrGetter<StandardSchemaV1 | undefined>;
|
|
231
222
|
}
|
|
223
|
+
type IssueCollection<TPath = string> = {
|
|
224
|
+
path: TPath;
|
|
225
|
+
messages: string[];
|
|
226
|
+
};
|
|
232
227
|
interface PathState<TInput = unknown, TOutput = TInput> {
|
|
233
228
|
id: number | number[];
|
|
234
229
|
path: string;
|
|
235
230
|
touched: boolean;
|
|
236
231
|
dirty: boolean;
|
|
237
232
|
valid: boolean;
|
|
238
|
-
required: boolean;
|
|
239
233
|
validated: boolean;
|
|
240
234
|
pending: boolean;
|
|
241
235
|
initialValue: TInput | undefined;
|
|
@@ -305,8 +299,8 @@ interface FormState<TValues> {
|
|
|
305
299
|
touched: Partial<Record<Path<TValues>, boolean>>;
|
|
306
300
|
submitCount: number;
|
|
307
301
|
}
|
|
308
|
-
type FormErrors<TValues extends GenericObject> = Partial<Record<Path<TValues
|
|
309
|
-
type FormErrorBag<TValues extends GenericObject> = Partial<Record<Path<TValues
|
|
302
|
+
type FormErrors<TValues extends GenericObject> = Partial<Record<Path<TValues> | '', string | undefined>>;
|
|
303
|
+
type FormErrorBag<TValues extends GenericObject> = Partial<Record<Path<TValues> | '', string[]>>;
|
|
310
304
|
interface ResetFormOpts {
|
|
311
305
|
force: boolean;
|
|
312
306
|
}
|
|
@@ -398,7 +392,7 @@ interface PrivateFormContext<TValues extends GenericObject = GenericObject, TOut
|
|
|
398
392
|
controlledValues: Ref<TValues>;
|
|
399
393
|
fieldArrays: PrivateFieldArrayContext[];
|
|
400
394
|
submitCount: Ref<number>;
|
|
401
|
-
schema?: MaybeRef<RawFormSchema<TValues> |
|
|
395
|
+
schema?: MaybeRef<RawFormSchema<TValues> | StandardSchemaV1<TValues, TOutput> | undefined>;
|
|
402
396
|
errorBag: Ref<FormErrorBag<TValues>>;
|
|
403
397
|
errors: ComputedRef<FormErrors<TValues>>;
|
|
404
398
|
meta: ComputedRef<FormMeta<TValues>>;
|
|
@@ -472,7 +466,7 @@ interface ValidationOptions {
|
|
|
472
466
|
/**
|
|
473
467
|
* Validates a value against the rules.
|
|
474
468
|
*/
|
|
475
|
-
declare function validate<TInput, TOutput>(value: TInput, rules: string | Record<string, unknown | unknown[]> | GenericValidateFunction<TInput> | GenericValidateFunction<TInput>[] |
|
|
469
|
+
declare function validate<TInput, TOutput>(value: TInput, rules: string | Record<string, unknown | unknown[]> | GenericValidateFunction<TInput> | GenericValidateFunction<TInput>[] | StandardSchemaV1<TInput, TOutput>, options?: ValidationOptions): Promise<ValidationResult<TOutput>>;
|
|
476
470
|
declare function validateObjectSchema<TValues extends GenericObject, TOutput extends GenericObject>(schema: RawFormSchema<TValues>, values: TValues | undefined, opts?: Partial<{
|
|
477
471
|
names: Record<string, {
|
|
478
472
|
name: string;
|
|
@@ -534,7 +528,7 @@ interface FieldOptions<TValue = unknown> {
|
|
|
534
528
|
syncVModel?: boolean | string;
|
|
535
529
|
form?: FormContext;
|
|
536
530
|
}
|
|
537
|
-
type RuleExpression<TValue> = string | Record<string, unknown> | GenericValidateFunction<TValue> | GenericValidateFunction<TValue>[] |
|
|
531
|
+
type RuleExpression<TValue> = string | Record<string, unknown> | GenericValidateFunction<TValue> | GenericValidateFunction<TValue>[] | StandardSchemaV1<TValue> | undefined;
|
|
538
532
|
/**
|
|
539
533
|
* Creates a field composite.
|
|
540
534
|
*/
|
|
@@ -1337,8 +1331,8 @@ declare const ErrorMessage: {
|
|
|
1337
1331
|
});
|
|
1338
1332
|
|
|
1339
1333
|
type FormSchema<TValues extends Record<string, unknown>> = FlattenAndSetPathsType<TValues, GenericValidateFunction | string | GenericObject> | undefined;
|
|
1340
|
-
interface FormOptions<TValues extends GenericObject, TOutput = TValues, TSchema extends
|
|
1341
|
-
validationSchema?: MaybeRef<TSchema extends
|
|
1334
|
+
interface FormOptions<TValues extends GenericObject, TOutput = TValues, TSchema extends StandardSchemaV1<TValues, TOutput> | FormSchema<TValues> = FormSchema<TValues>> {
|
|
1335
|
+
validationSchema?: MaybeRef<TSchema extends StandardSchemaV1 ? StandardSchemaV1<TValues, TOutput> : any>;
|
|
1342
1336
|
initialValues?: PartialDeep<TValues> | undefined | null;
|
|
1343
1337
|
initialErrors?: FlattenAndSetPathsType<TValues, string | undefined>;
|
|
1344
1338
|
initialTouched?: FlattenAndSetPathsType<TValues, boolean>;
|
|
@@ -1346,7 +1340,7 @@ interface FormOptions<TValues extends GenericObject, TOutput = TValues, TSchema
|
|
|
1346
1340
|
keepValuesOnUnmount?: MaybeRef<boolean>;
|
|
1347
1341
|
name?: string;
|
|
1348
1342
|
}
|
|
1349
|
-
declare function useForm<TValues extends GenericObject = GenericObject, TOutput extends GenericObject = TValues, TSchema extends FormSchema<TValues> |
|
|
1343
|
+
declare function useForm<TValues extends GenericObject = GenericObject, TOutput extends GenericObject = TValues, TSchema extends FormSchema<TValues> | StandardSchemaV1<TValues, TOutput> = FormSchema<TValues>>(opts?: FormOptions<TValues, TOutput, TSchema>): FormContext<TValues, TOutput>;
|
|
1350
1344
|
declare function useFormContext<TValues extends GenericObject = GenericObject, TOutput extends GenericObject = TValues>(): FormContext<TValues, TOutput>;
|
|
1351
1345
|
|
|
1352
1346
|
declare function useFieldArray<TValue = unknown>(arrayPath: MaybeRefOrGetter<string>): FieldArrayContext<TValue>;
|
|
@@ -1421,7 +1415,7 @@ declare function useFormValues<TValues extends Record<string, any> = Record<stri
|
|
|
1421
1415
|
/**
|
|
1422
1416
|
* Gives access to all form errors
|
|
1423
1417
|
*/
|
|
1424
|
-
declare function useFormErrors<TValues extends Record<string, unknown> = Record<string, unknown>>(): vue.ComputedRef<Partial<Record<Path<TValues>, string>>>;
|
|
1418
|
+
declare function useFormErrors<TValues extends Record<string, unknown> = Record<string, unknown>>(): vue.ComputedRef<Partial<Record<"" | Path<TValues>, string>>>;
|
|
1425
1419
|
|
|
1426
1420
|
/**
|
|
1427
1421
|
* Gives access to a single field error
|
|
@@ -1465,4 +1459,4 @@ declare const PublicFormContextKey: InjectionKey<FormContext>;
|
|
|
1465
1459
|
declare const FieldContextKey: InjectionKey<PrivateFieldContext<unknown>>;
|
|
1466
1460
|
declare const IS_ABSENT: unique symbol;
|
|
1467
1461
|
|
|
1468
|
-
export { type BaseComponentBinds, type BaseFieldProps, type BaseInputBinds, type ComponentBindsConfig, type ComponentFieldBindingObject, type ComponentModelBinds, type ComponentModellessBinds, type DevtoolsPluginFieldState, type DevtoolsPluginFormState, ErrorMessage, Field, FieldArray, type FieldArrayContext, type FieldBindingObject, type FieldContext, FieldContextKey, type FieldEntry, type FieldMeta, type FieldOptions, type FieldPathLookup, type FieldSlotProps, type FieldState, type FieldValidator, type FlattenAndMapPathsValidationResult, type FlattenAndSetPathsType, Form, type FormActions, type FormContext, FormContextKey, type FormErrorBag, type FormErrors, type FormMeta, type FormOptions, type FormSlotProps, type FormState, type FormValidationResult, type GenericObject, type GenericValidateFunction, IS_ABSENT, type
|
|
1462
|
+
export { type BaseComponentBinds, type BaseFieldProps, type BaseInputBinds, type ComponentBindsConfig, type ComponentFieldBindingObject, type ComponentModelBinds, type ComponentModellessBinds, type DevtoolsPluginFieldState, type DevtoolsPluginFormState, ErrorMessage, Field, FieldArray, type FieldArrayContext, type FieldBindingObject, type FieldContext, FieldContextKey, type FieldEntry, type FieldMeta, type FieldOptions, type FieldPathLookup, type FieldSlotProps, type FieldState, type FieldValidator, type FlattenAndMapPathsValidationResult, type FlattenAndSetPathsType, Form, type FormActions, type FormContext, FormContextKey, type FormErrorBag, type FormErrors, type FormMeta, type FormOptions, type FormSlotProps, type FormState, type FormValidationResult, type GenericObject, type GenericValidateFunction, IS_ABSENT, type InputBindsConfig, type InputType, type InvalidSubmissionContext, type InvalidSubmissionHandler, type IsAny, type IsEqual, type IssueCollection, type LazyComponentBindsConfig, type LazyInputBindsConfig, type Locator, type MapValuesPathsToRefs, type MaybeArray, type MaybePromise, type Path, type PathState, type PathStateConfig, type PathValue, type PrivateFieldArrayContext, type PrivateFieldContext, type PrivateFormContext, PublicFormContextKey, type PublicPathState, type RawFormSchema, type ResetFormOpts, type RuleExpression, type SchemaValidationMode, type SubmissionContext, type SubmissionHandler, type ValidationOptions$1 as ValidationOptions, type ValidationResult, cleanupNonNestedPath, configure, defineRule, isNotNestedPath, normalizeRules, useField, useFieldArray, useFieldError, useFieldValue, useForm, useFormContext, useFormErrors, useFormValues, useIsFieldDirty, useIsFieldTouched, useIsFieldValid, useIsFormDirty, useIsFormTouched, useIsFormValid, useIsSubmitting, useIsValidating, useResetForm, useSetFieldError, useSetFieldTouched, useSetFieldValue, useSetFormErrors, useSetFormTouched, useSetFormValues, useSubmitCount, useSubmitForm, useValidateField, useValidateForm, validate, validateObjectSchema as validateObject };
|