react-hook-form 7.39.3 → 7.39.4

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.
@@ -262,16 +262,41 @@ var generateWatchOutput = (names, _names, formValues, isGlobal) => {
262
262
  return formValues;
263
263
  };
264
264
 
265
- var isFunction = (value) => typeof value === 'function';
265
+ var isPlainObject = (tempObject) => {
266
+ const prototypeCopy = tempObject.constructor && tempObject.constructor.prototype;
267
+ return (isObject(prototypeCopy) && prototypeCopy.hasOwnProperty('isPrototypeOf'));
268
+ };
266
269
 
267
- var objectHasFunction = (data) => {
268
- for (const key in data) {
269
- if (isFunction(data[key])) {
270
- return true;
270
+ var isWeb = typeof window !== 'undefined' &&
271
+ typeof window.HTMLElement !== 'undefined' &&
272
+ typeof document !== 'undefined';
273
+
274
+ function cloneObject(data) {
275
+ let copy;
276
+ const isArray = Array.isArray(data);
277
+ if (data instanceof Date) {
278
+ copy = new Date(data);
279
+ }
280
+ else if (data instanceof Set) {
281
+ copy = new Set(data);
282
+ }
283
+ else if (!(isWeb && (data instanceof Blob || data instanceof FileList)) &&
284
+ (isArray || isObject(data))) {
285
+ copy = isArray ? [] : {};
286
+ if (!Array.isArray(data) && !isPlainObject(data)) {
287
+ copy = data;
288
+ }
289
+ else {
290
+ for (const key in data) {
291
+ copy[key] = cloneObject(data[key]);
292
+ }
271
293
  }
272
294
  }
273
- return false;
274
- };
295
+ else {
296
+ return data;
297
+ }
298
+ return copy;
299
+ }
275
300
 
276
301
  /**
277
302
  * Custom hook to subscribe to field change and isolate re-rendering at the component level.
@@ -300,14 +325,11 @@ function useWatch(props) {
300
325
  callback: React.useCallback((formState) => {
301
326
  if (shouldSubscribeByName(_name.current, formState.name, exact)) {
302
327
  const fieldValues = generateWatchOutput(_name.current, control._names, formState.values || control._formValues);
303
- updateValue(isUndefined(_name.current) ||
304
- (isObject(fieldValues) && !objectHasFunction(fieldValues))
305
- ? { ...fieldValues }
306
- : Array.isArray(fieldValues)
307
- ? [...fieldValues]
308
- : isUndefined(fieldValues)
309
- ? defaultValue
310
- : fieldValues);
328
+ updateValue(isUndefined(_name.current) || !isUndefined(fieldValues)
329
+ ? cloneObject(fieldValues)
330
+ : isUndefined(fieldValues)
331
+ ? defaultValue
332
+ : fieldValues);
311
333
  }
312
334
  }, [control, exact, defaultValue]),
313
335
  });
@@ -562,6 +584,8 @@ var isBoolean = (value) => typeof value === 'boolean';
562
584
 
563
585
  var isFileInput = (element) => element.type === 'file';
564
586
 
587
+ var isFunction = (value) => typeof value === 'function';
588
+
565
589
  var isMessage = (value) => isString(value) || React.isValidElement(value);
566
590
 
567
591
  var isRadioInput = (element) => element.type === 'radio';
@@ -632,8 +656,8 @@ var validateField = async (field, inputValue, validateAllFieldCriteria, shouldUs
632
656
  }
633
657
  const inputRef = refs ? refs[0] : ref;
634
658
  const setCustomValidity = (message) => {
635
- if (shouldUseNativeValidation && isString(message)) {
636
- inputRef.setCustomValidity(message);
659
+ if (shouldUseNativeValidation && inputRef.reportValidity) {
660
+ inputRef.setCustomValidity(isBoolean(message) ? '' : message || '');
637
661
  inputRef.reportValidity();
638
662
  }
639
663
  };
@@ -804,42 +828,6 @@ function append(data, value) {
804
828
  return [...data, ...convertToArrayPayload(value)];
805
829
  }
806
830
 
807
- var isPlainObject = (tempObject) => {
808
- const prototypeCopy = tempObject.constructor && tempObject.constructor.prototype;
809
- return (isObject(prototypeCopy) && prototypeCopy.hasOwnProperty('isPrototypeOf'));
810
- };
811
-
812
- var isWeb = typeof window !== 'undefined' &&
813
- typeof window.HTMLElement !== 'undefined' &&
814
- typeof document !== 'undefined';
815
-
816
- function cloneObject(data) {
817
- let copy;
818
- const isArray = Array.isArray(data);
819
- if (data instanceof Date) {
820
- copy = new Date(data);
821
- }
822
- else if (data instanceof Set) {
823
- copy = new Set(data);
824
- }
825
- else if (!(isWeb && (data instanceof Blob || data instanceof FileList)) &&
826
- (isArray || isObject(data))) {
827
- copy = isArray ? [] : {};
828
- if (!Array.isArray(data) && !isPlainObject(data)) {
829
- copy = data;
830
- }
831
- else {
832
- for (const key in data) {
833
- copy[key] = cloneObject(data[key]);
834
- }
835
- }
836
- }
837
- else {
838
- return data;
839
- }
840
- return copy;
841
- }
842
-
843
831
  var fillEmptyArray = (value) => Array.isArray(value) ? value.map(() => undefined) : undefined;
844
832
 
845
833
  var getValidationModes = (mode) => ({
@@ -1226,6 +1214,15 @@ var isRadioOrCheckbox = (ref) => isRadioInput(ref) || isCheckBoxInput(ref);
1226
1214
 
1227
1215
  var live = (ref) => isHTMLElement(ref) && ref.isConnected;
1228
1216
 
1217
+ var objectHasFunction = (data) => {
1218
+ for (const key in data) {
1219
+ if (isFunction(data[key])) {
1220
+ return true;
1221
+ }
1222
+ }
1223
+ return false;
1224
+ };
1225
+
1229
1226
  function markFieldsDirty(data, fields = {}) {
1230
1227
  const isParentNodeArray = Array.isArray(data);
1231
1228
  if (isObject(data) || isParentNodeArray) {