@bombillazo/rhf-plus 7.56.1-plus.2 → 7.56.2-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.
@@ -219,47 +219,7 @@ var getProxyFormState = (formState, control, localProxyFormState, isRoot = true)
219
219
  return result;
220
220
  };
221
221
 
222
- var isPrimitive = (value) => isNullOrUndefined(value) || !isObjectType(value);
223
-
224
- function deepEqual(object1, object2) {
225
- if (isPrimitive(object1) || isPrimitive(object2)) {
226
- return object1 === object2;
227
- }
228
- if (isDateObject(object1) && isDateObject(object2)) {
229
- return object1.getTime() === object2.getTime();
230
- }
231
- const keys1 = Object.keys(object1);
232
- const keys2 = Object.keys(object2);
233
- if (keys1.length !== keys2.length) {
234
- return false;
235
- }
236
- for (const key of keys1) {
237
- const val1 = object1[key];
238
- if (!keys2.includes(key)) {
239
- return false;
240
- }
241
- if (key !== 'ref') {
242
- const val2 = object2[key];
243
- if ((isDateObject(val1) && isDateObject(val2)) ||
244
- (isObject(val1) && isObject(val2)) ||
245
- (Array.isArray(val1) && Array.isArray(val2))
246
- ? !deepEqual(val1, val2)
247
- : val1 !== val2) {
248
- return false;
249
- }
250
- }
251
- }
252
- return true;
253
- }
254
-
255
- const useDeepEqualEffect = (effect, deps) => {
256
- const ref = React.useRef(deps);
257
- if (!deepEqual(deps, ref.current)) {
258
- ref.current = deps;
259
- }
260
- // eslint-disable-next-line react-hooks/exhaustive-deps
261
- React.useEffect(effect, ref.current);
262
- };
222
+ const useIsomorphicLayoutEffect = typeof window !== 'undefined' ? React.useLayoutEffect : React.useEffect;
263
223
 
264
224
  /**
265
225
  * This custom hook allows you to subscribe to each form state, and isolate the re-render at the custom hook level. It has its scope in terms of form state subscription, so it would not affect other useFormState and useForm. Using this hook can reduce the re-render impact on large and complex form application.
@@ -305,7 +265,7 @@ function useFormState(props) {
305
265
  isValid: false,
306
266
  errors: false,
307
267
  });
308
- useDeepEqualEffect(() => control._subscribe({
268
+ useIsomorphicLayoutEffect(() => control._subscribe({
309
269
  name: name,
310
270
  formState: _localProxyFormState.current,
311
271
  exact,
@@ -356,16 +316,17 @@ var generateWatchOutput = (names, _names, formValues, isGlobal, defaultValue) =>
356
316
  function useWatch(props) {
357
317
  const methods = useFormContext();
358
318
  const { control = methods.control, name, defaultValue, disabled, exact, } = props || {};
359
- const [value, updateValue] = React__default.useState(control._getWatch(name, defaultValue));
360
- useDeepEqualEffect(() => control._subscribe({
319
+ const _defaultValue = React__default.useRef(defaultValue);
320
+ const [value, updateValue] = React__default.useState(control._getWatch(name, _defaultValue.current));
321
+ useIsomorphicLayoutEffect(() => control._subscribe({
361
322
  name: name,
362
323
  formState: {
363
324
  values: true,
364
325
  },
365
326
  exact,
366
327
  callback: (formState) => !disabled &&
367
- updateValue(generateWatchOutput(name, control._names, formState.values || control._formValues, false, defaultValue)),
368
- }), [name, defaultValue, disabled, exact]);
328
+ updateValue(generateWatchOutput(name, control._names, formState.values || control._formValues, false, _defaultValue.current)),
329
+ }), [name, control, disabled, exact]);
369
330
  React__default.useEffect(() => control._removeUnmounted());
370
331
  return value;
371
332
  }
@@ -454,12 +415,7 @@ function useController(props) {
454
415
  const ref = React__default.useCallback((elm) => {
455
416
  const field = get(control._fields, name);
456
417
  if (field && elm) {
457
- field._f.ref = {
458
- focus: () => elm.focus(),
459
- select: () => elm.select(),
460
- setCustomValidity: (message) => elm.setCustomValidity(message),
461
- reportValidity: () => elm.reportValidity(),
462
- };
418
+ field._f.ref = elm;
463
419
  }
464
420
  }, [control._fields, name]);
465
421
  const field = React__default.useMemo(() => ({
@@ -725,6 +681,39 @@ var createSubject = () => {
725
681
  };
726
682
  };
727
683
 
684
+ var isPrimitive = (value) => isNullOrUndefined(value) || !isObjectType(value);
685
+
686
+ function deepEqual(object1, object2) {
687
+ if (isPrimitive(object1) || isPrimitive(object2)) {
688
+ return object1 === object2;
689
+ }
690
+ if (isDateObject(object1) && isDateObject(object2)) {
691
+ return object1.getTime() === object2.getTime();
692
+ }
693
+ const keys1 = Object.keys(object1);
694
+ const keys2 = Object.keys(object2);
695
+ if (keys1.length !== keys2.length) {
696
+ return false;
697
+ }
698
+ for (const key of keys1) {
699
+ const val1 = object1[key];
700
+ if (!keys2.includes(key)) {
701
+ return false;
702
+ }
703
+ if (key !== 'ref') {
704
+ const val2 = object2[key];
705
+ if ((isDateObject(val1) && isDateObject(val2)) ||
706
+ (isObject(val1) && isObject(val2)) ||
707
+ (Array.isArray(val1) && Array.isArray(val2))
708
+ ? !deepEqual(val1, val2)
709
+ : val1 !== val2) {
710
+ return false;
711
+ }
712
+ }
713
+ }
714
+ return true;
715
+ }
716
+
728
717
  var isEmptyObject = (value) => isObject(value) && !Object.keys(value).length;
729
718
 
730
719
  var isFileInput = (element) => element.type === 'file';
@@ -1301,7 +1290,7 @@ function createFormControl(props = {}) {
1301
1290
  };
1302
1291
  const _fields = {};
1303
1292
  let _defaultValues = isObject(_options.defaultValues) || isObject(_options.values)
1304
- ? cloneObject(_options.values || _options.defaultValues) || {}
1293
+ ? cloneObject(_options.defaultValues || _options.values) || {}
1305
1294
  : {};
1306
1295
  let _formValues = _options.shouldUnregister
1307
1296
  ? {}
@@ -2618,7 +2607,6 @@ function useFieldArray(props) {
2618
2607
  };
2619
2608
  }
2620
2609
 
2621
- const useIsomorphicLayoutEffect = typeof window !== 'undefined' ? React__default.useLayoutEffect : React__default.useEffect;
2622
2610
  /**
2623
2611
  * Custom hook to manage the entire form.
2624
2612
  *