@bombillazo/rhf-plus 7.56.1-plus.3 → 7.56.3-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,7 +415,12 @@ 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 = elm;
418
+ field._f.ref = {
419
+ focus: () => elm.focus(),
420
+ select: () => elm.select(),
421
+ setCustomValidity: (message) => elm.setCustomValidity(message),
422
+ reportValidity: () => elm.reportValidity(),
423
+ };
458
424
  }
459
425
  }, [control._fields, name]);
460
426
  const field = React__default.useMemo(() => ({
@@ -720,6 +686,39 @@ var createSubject = () => {
720
686
  };
721
687
  };
722
688
 
689
+ var isPrimitive = (value) => isNullOrUndefined(value) || !isObjectType(value);
690
+
691
+ function deepEqual(object1, object2) {
692
+ if (isPrimitive(object1) || isPrimitive(object2)) {
693
+ return object1 === object2;
694
+ }
695
+ if (isDateObject(object1) && isDateObject(object2)) {
696
+ return object1.getTime() === object2.getTime();
697
+ }
698
+ const keys1 = Object.keys(object1);
699
+ const keys2 = Object.keys(object2);
700
+ if (keys1.length !== keys2.length) {
701
+ return false;
702
+ }
703
+ for (const key of keys1) {
704
+ const val1 = object1[key];
705
+ if (!keys2.includes(key)) {
706
+ return false;
707
+ }
708
+ if (key !== 'ref') {
709
+ const val2 = object2[key];
710
+ if ((isDateObject(val1) && isDateObject(val2)) ||
711
+ (isObject(val1) && isObject(val2)) ||
712
+ (Array.isArray(val1) && Array.isArray(val2))
713
+ ? !deepEqual(val1, val2)
714
+ : val1 !== val2) {
715
+ return false;
716
+ }
717
+ }
718
+ }
719
+ return true;
720
+ }
721
+
723
722
  var isEmptyObject = (value) => isObject(value) && !Object.keys(value).length;
724
723
 
725
724
  var isFileInput = (element) => element.type === 'file';
@@ -1296,7 +1295,7 @@ function createFormControl(props = {}) {
1296
1295
  };
1297
1296
  const _fields = {};
1298
1297
  let _defaultValues = isObject(_options.defaultValues) || isObject(_options.values)
1299
- ? cloneObject(_options.values || _options.defaultValues) || {}
1298
+ ? cloneObject(_options.defaultValues || _options.values) || {}
1300
1299
  : {};
1301
1300
  let _formValues = _options.shouldUnregister
1302
1301
  ? {}
@@ -2613,7 +2612,6 @@ function useFieldArray(props) {
2613
2612
  };
2614
2613
  }
2615
2614
 
2616
- const useIsomorphicLayoutEffect = typeof window !== 'undefined' ? React__default.useLayoutEffect : React__default.useEffect;
2617
2615
  /**
2618
2616
  * Custom hook to manage the entire form.
2619
2617
  *