react-hook-form 7.76.1 → 7.78.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 +0 -11
- package/dist/constants.d.ts +1 -0
- package/dist/constants.d.ts.map +1 -1
- package/dist/index.cjs.js +1 -1
- package/dist/index.cjs.js.map +1 -1
- package/dist/index.esm.mjs +114 -59
- package/dist/index.esm.mjs.map +1 -1
- package/dist/index.umd.js +1 -1
- package/dist/index.umd.js.map +1 -1
- package/dist/logic/createFormControl.d.ts.map +1 -1
- package/dist/logic/index.d.ts +2 -3
- package/dist/logic/index.d.ts.map +1 -1
- package/dist/logic/isWatched.d.ts.map +1 -1
- package/dist/logic/skipValidation.d.ts +1 -4
- package/dist/logic/skipValidation.d.ts.map +1 -1
- package/dist/logic/updateFieldArrayRootError.d.ts.map +1 -1
- package/dist/react-server.esm.mjs +58 -19
- package/dist/react-server.esm.mjs.map +1 -1
- package/dist/types/form.d.ts +23 -3
- package/dist/types/form.d.ts.map +1 -1
- package/dist/types/utils.d.ts +1 -1
- package/dist/types/utils.d.ts.map +1 -1
- package/dist/useController.d.ts.map +1 -1
- package/dist/useFieldArray.d.ts.map +1 -1
- package/dist/useFormContext.d.ts +1 -1
- package/dist/useFormContext.d.ts.map +1 -1
- package/dist/useIsomorphicLayoutEffect.d.ts.map +1 -1
- package/dist/utils/deepEqual.d.ts.map +1 -1
- package/dist/utils/get.d.ts.map +1 -1
- package/dist/utils/index.d.ts +2 -3
- package/dist/utils/index.d.ts.map +1 -1
- package/dist/utils/set.d.ts.map +1 -1
- package/dist/utils/stringToPath.d.ts.map +1 -1
- package/package.json +17 -17
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"createFormControl.d.ts","sourceRoot":"","sources":["../../src/logic/createFormControl.ts"],"names":[],"mappings":"AAOA,OAAO,KAAK,EAcV,WAAW,EAiBX,YAAY,
|
|
1
|
+
{"version":3,"file":"createFormControl.d.ts","sourceRoot":"","sources":["../../src/logic/createFormControl.ts"],"names":[],"mappings":"AAOA,OAAO,KAAK,EAcV,WAAW,EAiBX,YAAY,EAKZ,aAAa,EAYd,MAAM,UAAU,CAAC;AAuDlB,eAAO,MAAM,kBAAkB;;;;;;;;;;;;CAY9B,CAAC;AAEF,wBAAgB,iBAAiB,CAC/B,YAAY,SAAS,WAAW,GAAG,WAAW,EAC9C,QAAQ,GAAG,GAAG,EACd,kBAAkB,GAAG,YAAY,EAEjC,KAAK,GAAE,YAAY,CAAC,YAAY,EAAE,QAAQ,EAAE,kBAAkB,CAAM,GACnE,IAAI,CACL,aAAa,CAAC,YAAY,EAAE,QAAQ,EAAE,kBAAkB,CAAC,EACzD,WAAW,CACZ,GAAG;IACF,WAAW,EAAE,IAAI,CACf,aAAa,CAAC,YAAY,EAAE,QAAQ,EAAE,kBAAkB,CAAC,EACzD,WAAW,CACZ,CAAC;CACH,CAyvDA"}
|
package/dist/logic/index.d.ts
CHANGED
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
export { appendErrors, createFormControl };
|
|
1
|
+
export { default as appendErrors } from './appendErrors';
|
|
2
|
+
export { createFormControl } from './createFormControl';
|
|
4
3
|
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/logic/index.ts"],"names":[],"mappings":"AAAA,OAAO,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/logic/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,IAAI,YAAY,EAAE,MAAM,gBAAgB,CAAC;AACzD,OAAO,EAAE,iBAAiB,EAAE,MAAM,qBAAqB,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"isWatched.d.ts","sourceRoot":"","sources":["../../src/logic/isWatched.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,iBAAiB,EAAE,KAAK,EAAE,MAAM,UAAU,CAAC;yBAGvD,MAAM,iBAAiB,EACvB,QAAQ,KAAK,EACb,cAAc,OAAO;AAHvB,
|
|
1
|
+
{"version":3,"file":"isWatched.d.ts","sourceRoot":"","sources":["../../src/logic/isWatched.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,iBAAiB,EAAE,KAAK,EAAE,MAAM,UAAU,CAAC;yBAGvD,MAAM,iBAAiB,EACvB,QAAQ,KAAK,EACb,cAAc,OAAO;AAHvB,wBAQ6E"}
|
|
@@ -1,7 +1,4 @@
|
|
|
1
1
|
import type { ValidationModeFlags } from '../types';
|
|
2
|
-
declare const _default: (isBlurEvent: boolean, isTouched: boolean, isSubmitted: boolean, reValidateMode:
|
|
3
|
-
isOnBlur: boolean;
|
|
4
|
-
isOnChange: boolean;
|
|
5
|
-
}, mode: Partial<ValidationModeFlags>) => boolean;
|
|
2
|
+
declare const _default: (isBlurEvent: boolean, isTouched: boolean, isSubmitted: boolean, reValidateMode: Pick<ValidationModeFlags, "isOnBlur" | "isOnChange">, mode: Partial<ValidationModeFlags>) => boolean;
|
|
6
3
|
export default _default;
|
|
7
4
|
//# sourceMappingURL=skipValidation.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"skipValidation.d.ts","sourceRoot":"","sources":["../../src/logic/skipValidation.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,UAAU,CAAC;yBAGlD,aAAa,OAAO,EACpB,WAAW,OAAO,EAClB,aAAa,OAAO,EACpB,gBAAgB
|
|
1
|
+
{"version":3,"file":"skipValidation.d.ts","sourceRoot":"","sources":["../../src/logic/skipValidation.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,UAAU,CAAC;yBAGlD,aAAa,OAAO,EACpB,WAAW,OAAO,EAClB,aAAa,OAAO,EACpB,gBAAgB,IAAI,CAAC,mBAAmB,EAAE,UAAU,GAAG,YAAY,CAAC,EACpE,MAAM,OAAO,CAAC,mBAAmB,CAAC;AALpC,wBAiBE"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"updateFieldArrayRootError.d.ts","sourceRoot":"","sources":["../../src/logic/updateFieldArrayRootError.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EACV,UAAU,EACV,WAAW,EACX,WAAW,EACX,iBAAiB,EAClB,MAAM,UAAU,CAAC;
|
|
1
|
+
{"version":3,"file":"updateFieldArrayRootError.d.ts","sourceRoot":"","sources":["../../src/logic/updateFieldArrayRootError.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EACV,UAAU,EACV,WAAW,EACX,WAAW,EACX,iBAAiB,EAClB,MAAM,UAAU,CAAC;yBAIF,CAAC,SAAS,WAAW,GAAG,WAAW,EACjD,QAAQ,WAAW,CAAC,CAAC,CAAC,EACtB,OAAO,OAAO,CAAC,MAAM,CAAC,MAAM,EAAE,UAAU,CAAC,CAAC,EAC1C,MAAM,iBAAiB,KACtB,WAAW,CAAC,CAAC,CAAC;AAJjB,wBAUE"}
|
|
@@ -33,6 +33,7 @@ const INPUT_VALIDATION_RULES = {
|
|
|
33
33
|
};
|
|
34
34
|
const FORM_ERROR_TYPE = 'form';
|
|
35
35
|
const ROOT_ERROR_TYPE = 'root';
|
|
36
|
+
const PROTOTYPE_KEYWORDS = ['__proto__', 'constructor', 'prototype'];
|
|
36
37
|
|
|
37
38
|
var isDateObject = (value) => value instanceof Date;
|
|
38
39
|
|
|
@@ -108,6 +109,7 @@ var createSubject = () => {
|
|
|
108
109
|
|
|
109
110
|
var isPrimitive = (value) => isNullOrUndefined(value) || !isObjectType(value);
|
|
110
111
|
|
|
112
|
+
const isEmptyObjectWithCustomPrototype = (object, keys) => keys.length === 0 && !Array.isArray(object) && !isPlainObject(object);
|
|
111
113
|
function deepEqual(object1, object2, visited = new WeakSet()) {
|
|
112
114
|
if (object1 === object2) {
|
|
113
115
|
return true;
|
|
@@ -123,6 +125,10 @@ function deepEqual(object1, object2, visited = new WeakSet()) {
|
|
|
123
125
|
if (keys1.length !== keys2.length) {
|
|
124
126
|
return false;
|
|
125
127
|
}
|
|
128
|
+
if (isEmptyObjectWithCustomPrototype(object1, keys1) ||
|
|
129
|
+
isEmptyObjectWithCustomPrototype(object2, keys2)) {
|
|
130
|
+
return Object.is(object1, object2);
|
|
131
|
+
}
|
|
126
132
|
if (visited.has(object1) || visited.has(object2)) {
|
|
127
133
|
return true;
|
|
128
134
|
}
|
|
@@ -171,13 +177,16 @@ var isKey = (value) => /^\w*$/.test(value);
|
|
|
171
177
|
|
|
172
178
|
var isUndefined = (val) => val === undefined;
|
|
173
179
|
|
|
174
|
-
var stringToPath = (input) =>
|
|
180
|
+
var stringToPath = (input) => input.split(/[.[\]'"]/g).filter(Boolean);
|
|
175
181
|
|
|
176
182
|
var get = (object, path, defaultValue) => {
|
|
177
183
|
if (!path || !isObject(object)) {
|
|
178
184
|
return defaultValue;
|
|
179
185
|
}
|
|
180
186
|
const paths = isKey(path) ? [path] : stringToPath(path);
|
|
187
|
+
if (paths.some((key) => PROTOTYPE_KEYWORDS.includes(key))) {
|
|
188
|
+
return defaultValue;
|
|
189
|
+
}
|
|
181
190
|
const result = paths.reduce((result, key) => {
|
|
182
191
|
return isNullOrUndefined(result) ? undefined : result[key];
|
|
183
192
|
}, object);
|
|
@@ -234,7 +243,7 @@ var set = (object, path, value) => {
|
|
|
234
243
|
? []
|
|
235
244
|
: {};
|
|
236
245
|
}
|
|
237
|
-
if (key
|
|
246
|
+
if (PROTOTYPE_KEYWORDS.includes(key)) {
|
|
238
247
|
return;
|
|
239
248
|
}
|
|
240
249
|
object[key] = newValue;
|
|
@@ -503,8 +512,7 @@ var isNameInFieldArray = (names, name) => name
|
|
|
503
512
|
var isWatched = (name, _names, isBlurEvent) => !isBlurEvent &&
|
|
504
513
|
(_names.watchAll ||
|
|
505
514
|
_names.watch.has(name) ||
|
|
506
|
-
[..._names.watch].some((watchName) => name.startsWith(watchName)
|
|
507
|
-
/^\.\w+/.test(name.slice(watchName.length))));
|
|
515
|
+
[..._names.watch].some((watchName) => name.startsWith(`${watchName}.`)));
|
|
508
516
|
|
|
509
517
|
const iterateFieldsByAction = (fields, action, fieldsNames, abortEarly) => {
|
|
510
518
|
for (const key of fieldsNames || Object.keys(fields)) {
|
|
@@ -607,7 +615,8 @@ var skipValidation = (isBlurEvent, isTouched, isSubmitted, reValidateMode, mode)
|
|
|
607
615
|
var unsetEmptyArray = (ref, name) => !compact(get(ref, name)).length && unset(ref, name);
|
|
608
616
|
|
|
609
617
|
var updateFieldArrayRootError = (errors, error, name) => {
|
|
610
|
-
const
|
|
618
|
+
const existingErrors = get(errors, name);
|
|
619
|
+
const fieldArrayErrors = Array.isArray(existingErrors) ? existingErrors : [];
|
|
611
620
|
set(fieldArrayErrors, ROOT_ERROR_TYPE, error[name]);
|
|
612
621
|
set(errors, name, fieldArrayErrors);
|
|
613
622
|
return errors;
|
|
@@ -1122,7 +1131,9 @@ function createFormControl(props = {}) {
|
|
|
1122
1131
|
for (const name of names) {
|
|
1123
1132
|
const error = get(errors, name);
|
|
1124
1133
|
error
|
|
1125
|
-
? _names.array.has(name) &&
|
|
1134
|
+
? _names.array.has(name) &&
|
|
1135
|
+
isObject(error) &&
|
|
1136
|
+
!Object.keys(error).some((key) => !Number.isNaN(Number(key)))
|
|
1126
1137
|
? updateFieldArrayRootError(_formState.errors, { [name]: error }, name)
|
|
1127
1138
|
: set(_formState.errors, name, error)
|
|
1128
1139
|
: unset(_formState.errors, name);
|
|
@@ -1461,13 +1472,15 @@ function createFormControl(props = {}) {
|
|
|
1461
1472
|
const { errors } = await _runSchema([name]);
|
|
1462
1473
|
_updateIsValidating([name]);
|
|
1463
1474
|
_updateIsFieldValueUpdated(fieldValue);
|
|
1464
|
-
if (isFieldValueUpdated) {
|
|
1465
|
-
|
|
1466
|
-
|
|
1467
|
-
error = errorLookupResult.error;
|
|
1468
|
-
name = errorLookupResult.name;
|
|
1469
|
-
isValid = isEmptyObject(errors);
|
|
1475
|
+
if (!isFieldValueUpdated) {
|
|
1476
|
+
!isEmptyObject(fieldState) && _subjects.state.next(fieldState);
|
|
1477
|
+
return;
|
|
1470
1478
|
}
|
|
1479
|
+
const previousErrorLookupResult = schemaErrorLookup(_formState.errors, _fields, name);
|
|
1480
|
+
const errorLookupResult = schemaErrorLookup(errors, _fields, previousErrorLookupResult.name || name);
|
|
1481
|
+
error = errorLookupResult.error;
|
|
1482
|
+
name = errorLookupResult.name;
|
|
1483
|
+
isValid = isEmptyObject(errors);
|
|
1471
1484
|
}
|
|
1472
1485
|
else {
|
|
1473
1486
|
_updateIsValidating([name], true);
|
|
@@ -1869,7 +1882,7 @@ function createFormControl(props = {}) {
|
|
|
1869
1882
|
const updatedValues = formValues ? cloneObject(formValues) : _defaultValues;
|
|
1870
1883
|
const cloneUpdatedValues = cloneObject(updatedValues);
|
|
1871
1884
|
const isEmptyResetValues = isEmptyObject(formValues);
|
|
1872
|
-
const values =
|
|
1885
|
+
const values = cloneUpdatedValues;
|
|
1873
1886
|
if (!keepStateOptions.keepDefaultValues) {
|
|
1874
1887
|
_defaultValues = updatedValues;
|
|
1875
1888
|
}
|
|
@@ -1918,11 +1931,19 @@ function createFormControl(props = {}) {
|
|
|
1918
1931
|
_fields = {};
|
|
1919
1932
|
}
|
|
1920
1933
|
}
|
|
1921
|
-
|
|
1922
|
-
|
|
1934
|
+
if (_options.shouldUnregister) {
|
|
1935
|
+
_formValues = keepStateOptions.keepDefaultValues
|
|
1923
1936
|
? cloneObject(_defaultValues)
|
|
1924
|
-
: {}
|
|
1925
|
-
|
|
1937
|
+
: {};
|
|
1938
|
+
if (keepStateOptions.keepFieldsRef) {
|
|
1939
|
+
for (const fieldName of _names.mount) {
|
|
1940
|
+
set(_formValues, fieldName, get(values, fieldName));
|
|
1941
|
+
}
|
|
1942
|
+
}
|
|
1943
|
+
}
|
|
1944
|
+
else {
|
|
1945
|
+
_formValues = cloneObject(values);
|
|
1946
|
+
}
|
|
1926
1947
|
_subjects.array.next({
|
|
1927
1948
|
values: { ...values },
|
|
1928
1949
|
});
|
|
@@ -1962,8 +1983,10 @@ function createFormControl(props = {}) {
|
|
|
1962
1983
|
? false
|
|
1963
1984
|
: keepStateOptions.keepDirty
|
|
1964
1985
|
? _formState.isDirty
|
|
1965
|
-
:
|
|
1966
|
-
|
|
1986
|
+
: keepStateOptions.keepValues
|
|
1987
|
+
? _getDirty()
|
|
1988
|
+
: !!(keepStateOptions.keepDefaultValues &&
|
|
1989
|
+
!deepEqual(formValues, _defaultValues)),
|
|
1967
1990
|
isSubmitted: keepStateOptions.keepIsSubmitted
|
|
1968
1991
|
? _formState.isSubmitted
|
|
1969
1992
|
: false,
|
|
@@ -2024,6 +2047,21 @@ function createFormControl(props = {}) {
|
|
|
2024
2047
|
isLoading: false,
|
|
2025
2048
|
});
|
|
2026
2049
|
});
|
|
2050
|
+
const resetDefaultValues = (values, options = {}) => {
|
|
2051
|
+
_defaultValues = cloneObject(values);
|
|
2052
|
+
if (!options.keepDirty) {
|
|
2053
|
+
const newDirtyFields = getDirtyFields(_defaultValues, _formValues);
|
|
2054
|
+
_formState.dirtyFields = newDirtyFields;
|
|
2055
|
+
_formState.isDirty = !isEmptyObject(newDirtyFields);
|
|
2056
|
+
}
|
|
2057
|
+
if (!options.keepIsValid) {
|
|
2058
|
+
_setValid();
|
|
2059
|
+
}
|
|
2060
|
+
_subjects.state.next({
|
|
2061
|
+
..._formState,
|
|
2062
|
+
defaultValues: _defaultValues,
|
|
2063
|
+
});
|
|
2064
|
+
};
|
|
2027
2065
|
const methods = {
|
|
2028
2066
|
control: {
|
|
2029
2067
|
register,
|
|
@@ -2092,6 +2130,7 @@ function createFormControl(props = {}) {
|
|
|
2092
2130
|
getValues,
|
|
2093
2131
|
reset,
|
|
2094
2132
|
resetField,
|
|
2133
|
+
resetDefaultValues,
|
|
2095
2134
|
clearErrors,
|
|
2096
2135
|
unregister,
|
|
2097
2136
|
setError,
|