@bombillazo/rhf-plus 7.59.0-plus.0 → 7.60.0-plus.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.
@@ -40,9 +40,6 @@ function cloneObject(data) {
40
40
  if (data instanceof Date) {
41
41
  copy = new Date(data);
42
42
  }
43
- else if (data instanceof Set) {
44
- copy = new Set(data);
45
- }
46
43
  else if (!(isWeb && (data instanceof Blob || isFileListInstance)) &&
47
44
  (isArray || isObject(data))) {
48
45
  copy = isArray ? [] : {};
@@ -291,7 +288,8 @@ var generateWatchOutput = (names, _names, formValues, isGlobal, defaultValue) =>
291
288
  return get(formValues, names, defaultValue);
292
289
  }
293
290
  if (Array.isArray(names)) {
294
- return names.map((fieldName) => (isGlobal && _names.watch.add(fieldName), get(formValues, fieldName)));
291
+ return names.map((fieldName) => (isGlobal && _names.watch.add(fieldName),
292
+ get(formValues, fieldName)));
295
293
  }
296
294
  isGlobal && (_names.watchAll = true);
297
295
  return formValues;
@@ -1332,7 +1330,7 @@ function createFormControl(props = {}) {
1332
1330
  disabled: _options.disabled || false,
1333
1331
  metadata: _options.defaultMetadata || {},
1334
1332
  };
1335
- const _fields = {};
1333
+ let _fields = {};
1336
1334
  let _defaultValues = isObject(_options.defaultValues) || isObject(_options.values)
1337
1335
  ? cloneObject(_options.defaultValues || _options.values) || {}
1338
1336
  : {};
@@ -2179,15 +2177,20 @@ function createFormControl(props = {}) {
2179
2177
  }
2180
2178
  }
2181
2179
  }
2182
- for (const fieldName of _names.mount) {
2183
- const value = get(values, fieldName, get(_defaultValues, fieldName));
2184
- if (!isUndefined(value)) {
2185
- set(values, fieldName, value);
2180
+ if (keepStateOptions.keepFieldsRef) {
2181
+ for (const fieldName of _names.mount) {
2186
2182
  setValue(fieldName, get(values, fieldName));
2187
2183
  }
2188
2184
  }
2185
+ else {
2186
+ _fields = {};
2187
+ }
2189
2188
  }
2190
- _formValues = cloneObject(values);
2189
+ _formValues = _options.shouldUnregister
2190
+ ? keepStateOptions.keepDefaultValues
2191
+ ? cloneObject(_defaultValues)
2192
+ : {}
2193
+ : cloneObject(values);
2191
2194
  _subjects.array.next({
2192
2195
  values: { ...values },
2193
2196
  });
@@ -2833,7 +2836,10 @@ function useForm(props = {}) {
2833
2836
  }, [control, formState.isDirty]);
2834
2837
  React__default.useEffect(() => {
2835
2838
  if (props.values && !deepEqual(props.values, _values.current)) {
2836
- control._reset(props.values, control._options.resetOptions);
2839
+ control._reset(props.values, {
2840
+ keepFieldsRef: true,
2841
+ ...control._options.resetOptions,
2842
+ });
2837
2843
  _values.current = props.values;
2838
2844
  updateFormState((state) => ({ ...state }));
2839
2845
  }