react-hook-form 7.76.1 → 7.77.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 +1 @@
1
- {"version":3,"file":"createFormControl.d.ts","sourceRoot":"","sources":["../../src/logic/createFormControl.ts"],"names":[],"mappings":"AAOA,OAAO,KAAK,EAcV,WAAW,EAiBX,YAAY,EAIZ,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,CAmtDA"}
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,CAsvDA"}
@@ -1,4 +1,3 @@
1
- import appendErrors from './appendErrors';
2
- import { createFormControl } from './createFormControl';
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,YAAY,MAAM,gBAAgB,CAAC;AAC1C,OAAO,EAAE,iBAAiB,EAAE,MAAM,qBAAqB,CAAC;AAExD,OAAO,EAAE,YAAY,EAAE,iBAAiB,EAAE,CAAC"}
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,wBAYO"}
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;IACd,QAAQ,EAAE,OAAO,CAAC;IAClB,UAAU,EAAE,OAAO,CAAC;CACrB,EACD,MAAM,OAAO,CAAC,mBAAmB,CAAC;AARpC,wBAoBE"}
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;yBAKF,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,wBASE"}
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
 
@@ -171,13 +172,16 @@ var isKey = (value) => /^\w*$/.test(value);
171
172
 
172
173
  var isUndefined = (val) => val === undefined;
173
174
 
174
- var stringToPath = (input) => compact(input.replace(/["|']|\]/g, '').split(/\.|\[/));
175
+ var stringToPath = (input) => input.split(/[.[\]'"]/g).filter(Boolean);
175
176
 
176
177
  var get = (object, path, defaultValue) => {
177
178
  if (!path || !isObject(object)) {
178
179
  return defaultValue;
179
180
  }
180
181
  const paths = isKey(path) ? [path] : stringToPath(path);
182
+ if (paths.some((key) => PROTOTYPE_KEYWORDS.includes(key))) {
183
+ return defaultValue;
184
+ }
181
185
  const result = paths.reduce((result, key) => {
182
186
  return isNullOrUndefined(result) ? undefined : result[key];
183
187
  }, object);
@@ -234,7 +238,7 @@ var set = (object, path, value) => {
234
238
  ? []
235
239
  : {};
236
240
  }
237
- if (key === '__proto__' || key === 'constructor' || key === 'prototype') {
241
+ if (PROTOTYPE_KEYWORDS.includes(key)) {
238
242
  return;
239
243
  }
240
244
  object[key] = newValue;
@@ -503,8 +507,7 @@ var isNameInFieldArray = (names, name) => name
503
507
  var isWatched = (name, _names, isBlurEvent) => !isBlurEvent &&
504
508
  (_names.watchAll ||
505
509
  _names.watch.has(name) ||
506
- [..._names.watch].some((watchName) => name.startsWith(watchName) &&
507
- /^\.\w+/.test(name.slice(watchName.length))));
510
+ [..._names.watch].some((watchName) => name.startsWith(`${watchName}.`)));
508
511
 
509
512
  const iterateFieldsByAction = (fields, action, fieldsNames, abortEarly) => {
510
513
  for (const key of fieldsNames || Object.keys(fields)) {
@@ -607,7 +610,8 @@ var skipValidation = (isBlurEvent, isTouched, isSubmitted, reValidateMode, mode)
607
610
  var unsetEmptyArray = (ref, name) => !compact(get(ref, name)).length && unset(ref, name);
608
611
 
609
612
  var updateFieldArrayRootError = (errors, error, name) => {
610
- const fieldArrayErrors = convertToArrayPayload(get(errors, name));
613
+ const existingErrors = get(errors, name);
614
+ const fieldArrayErrors = Array.isArray(existingErrors) ? existingErrors : [];
611
615
  set(fieldArrayErrors, ROOT_ERROR_TYPE, error[name]);
612
616
  set(errors, name, fieldArrayErrors);
613
617
  return errors;
@@ -1122,7 +1126,9 @@ function createFormControl(props = {}) {
1122
1126
  for (const name of names) {
1123
1127
  const error = get(errors, name);
1124
1128
  error
1125
- ? _names.array.has(name) && isObject(error)
1129
+ ? _names.array.has(name) &&
1130
+ isObject(error) &&
1131
+ !Object.keys(error).some((key) => !Number.isNaN(Number(key)))
1126
1132
  ? updateFieldArrayRootError(_formState.errors, { [name]: error }, name)
1127
1133
  : set(_formState.errors, name, error)
1128
1134
  : unset(_formState.errors, name);
@@ -1869,7 +1875,7 @@ function createFormControl(props = {}) {
1869
1875
  const updatedValues = formValues ? cloneObject(formValues) : _defaultValues;
1870
1876
  const cloneUpdatedValues = cloneObject(updatedValues);
1871
1877
  const isEmptyResetValues = isEmptyObject(formValues);
1872
- const values = isEmptyResetValues ? _defaultValues : cloneUpdatedValues;
1878
+ const values = cloneUpdatedValues;
1873
1879
  if (!keepStateOptions.keepDefaultValues) {
1874
1880
  _defaultValues = updatedValues;
1875
1881
  }
@@ -1918,11 +1924,19 @@ function createFormControl(props = {}) {
1918
1924
  _fields = {};
1919
1925
  }
1920
1926
  }
1921
- _formValues = _options.shouldUnregister
1922
- ? keepStateOptions.keepDefaultValues
1927
+ if (_options.shouldUnregister) {
1928
+ _formValues = keepStateOptions.keepDefaultValues
1923
1929
  ? cloneObject(_defaultValues)
1924
- : {}
1925
- : cloneObject(values);
1930
+ : {};
1931
+ if (keepStateOptions.keepFieldsRef) {
1932
+ for (const fieldName of _names.mount) {
1933
+ set(_formValues, fieldName, get(values, fieldName));
1934
+ }
1935
+ }
1936
+ }
1937
+ else {
1938
+ _formValues = cloneObject(values);
1939
+ }
1926
1940
  _subjects.array.next({
1927
1941
  values: { ...values },
1928
1942
  });
@@ -1962,8 +1976,10 @@ function createFormControl(props = {}) {
1962
1976
  ? false
1963
1977
  : keepStateOptions.keepDirty
1964
1978
  ? _formState.isDirty
1965
- : !!(keepStateOptions.keepDefaultValues &&
1966
- !deepEqual(formValues, _defaultValues)),
1979
+ : keepStateOptions.keepValues
1980
+ ? _getDirty()
1981
+ : !!(keepStateOptions.keepDefaultValues &&
1982
+ !deepEqual(formValues, _defaultValues)),
1967
1983
  isSubmitted: keepStateOptions.keepIsSubmitted
1968
1984
  ? _formState.isSubmitted
1969
1985
  : false,
@@ -2024,6 +2040,21 @@ function createFormControl(props = {}) {
2024
2040
  isLoading: false,
2025
2041
  });
2026
2042
  });
2043
+ const resetDefaultValues = (values, options = {}) => {
2044
+ _defaultValues = cloneObject(values);
2045
+ if (!options.keepDirty) {
2046
+ const newDirtyFields = getDirtyFields(_defaultValues, _formValues);
2047
+ _formState.dirtyFields = newDirtyFields;
2048
+ _formState.isDirty = !isEmptyObject(newDirtyFields);
2049
+ }
2050
+ if (!options.keepIsValid) {
2051
+ _setValid();
2052
+ }
2053
+ _subjects.state.next({
2054
+ ..._formState,
2055
+ defaultValues: _defaultValues,
2056
+ });
2057
+ };
2027
2058
  const methods = {
2028
2059
  control: {
2029
2060
  register,
@@ -2092,6 +2123,7 @@ function createFormControl(props = {}) {
2092
2123
  getValues,
2093
2124
  reset,
2094
2125
  resetField,
2126
+ resetDefaultValues,
2095
2127
  clearErrors,
2096
2128
  unregister,
2097
2129
  setError,