react-hook-form 7.80.0 → 7.81.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":"AAMA,OAAO,KAAK,EAcV,WAAW,EAiBX,YAAY,EAKZ,aAAa,EAYd,MAAM,UAAU,CAAC;AAyDlB,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,CA0yDA"}
1
+ {"version":3,"file":"createFormControl.d.ts","sourceRoot":"","sources":["../../src/logic/createFormControl.ts"],"names":[],"mappings":"AAMA,OAAO,KAAK,EAcV,WAAW,EAiBX,YAAY,EAKZ,aAAa,EAYd,MAAM,UAAU,CAAC;AA0DlB,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,CA2zDA"}
@@ -182,6 +182,24 @@ function extractFormValues(fieldsState, formValues) {
182
182
  return values;
183
183
  }
184
184
 
185
+ const flatten = (obj) => {
186
+ const output = {};
187
+ for (const key of Object.keys(obj)) {
188
+ if (isObjectType(obj[key]) &&
189
+ obj[key] !== null &&
190
+ !isDateObject(obj[key])) {
191
+ const nested = flatten(obj[key]);
192
+ for (const nestedKey of Object.keys(nested)) {
193
+ output[`${key}.${nestedKey}`] = nested[nestedKey];
194
+ }
195
+ }
196
+ else {
197
+ output[key] = obj[key];
198
+ }
199
+ }
200
+ return output;
201
+ };
202
+
185
203
  const IS_KEY_RE = /^\w*$/;
186
204
  var isKey = (value) => IS_KEY_RE.test(value);
187
205
 
@@ -293,6 +311,9 @@ function unset(object, path) {
293
311
  : isKey(path)
294
312
  ? [path]
295
313
  : stringToPath(path);
314
+ if (paths.some((segment) => PROTOTYPE_KEYWORDS.includes(String(segment)))) {
315
+ return object;
316
+ }
296
317
  const childObject = paths.length === 1 ? object : baseGet(object, paths);
297
318
  const index = paths.length - 1;
298
319
  const key = paths[index];
@@ -620,7 +641,7 @@ var shouldSubscribeByName = (name, signalName, exact) => !name ||
620
641
  name === signalName ||
621
642
  convertToArrayPayload(name).some((currentName) => currentName &&
622
643
  (exact
623
- ? currentName === signalName
644
+ ? currentName === signalName || currentName.startsWith(signalName + '.')
624
645
  : currentName.startsWith(signalName) ||
625
646
  signalName.startsWith(currentName)));
626
647
 
@@ -1431,8 +1452,11 @@ function createFormControl(props = {}) {
1431
1452
  ..._formValues,
1432
1453
  ...updatedFormValues,
1433
1454
  };
1455
+ const flattenedUpdates = flatten(updatedFormValues);
1434
1456
  for (const fieldName of _names.mount) {
1435
- _setValue(fieldName, get(updatedFormValues, fieldName), options, true, true);
1457
+ if (fieldName in flattenedUpdates) {
1458
+ _setValue(fieldName, flattenedUpdates[fieldName], options, true, true);
1459
+ }
1436
1460
  }
1437
1461
  _subjects.state.next({
1438
1462
  ..._formState,
@@ -2024,6 +2048,8 @@ function createFormControl(props = {}) {
2024
2048
  values: { ...values },
2025
2049
  });
2026
2050
  _subjects.state.next({
2051
+ name: undefined,
2052
+ type: undefined,
2027
2053
  values: { ...values },
2028
2054
  });
2029
2055
  }
@@ -2106,9 +2132,15 @@ function createFormControl(props = {}) {
2106
2132
  }
2107
2133
  };
2108
2134
  const _setFormState = (updatedFormState) => {
2135
+ // `name`, `type`, and `values` describe the event that produced this
2136
+ // update, not the form's persisted state (they aren't part of
2137
+ // `FormState`). Merging them in would leak a stale `name`/`type` from
2138
+ // one event into a later, unrelated notification that doesn't specify
2139
+ // its own.
2140
+ const { name, type, values, ...formState } = updatedFormState;
2109
2141
  _formState = {
2110
2142
  ..._formState,
2111
- ...updatedFormState,
2143
+ ...formState,
2112
2144
  };
2113
2145
  };
2114
2146
  const _resetDefaultValues = () => isFunction(_options.defaultValues) &&