@bombillazo/rhf-plus 7.56.1-plus.3 → 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.
- package/README.md +5 -2
- package/dist/index.cjs.js +1 -1
- package/dist/index.cjs.js.map +1 -1
- package/dist/index.esm.mjs +41 -48
- package/dist/index.esm.mjs.map +1 -1
- package/dist/index.umd.js +1 -1
- package/dist/index.umd.js.map +1 -1
- package/dist/react-server.esm.mjs +1 -1
- package/dist/react-server.esm.mjs.map +1 -1
- package/dist/useForm.d.ts.map +1 -1
- package/dist/useIsomorphicLayoutEffect.d.ts +3 -0
- package/dist/useIsomorphicLayoutEffect.d.ts.map +1 -0
- package/package.json +1 -1
- package/dist/useDeepEqualEffect.d.ts +0 -3
- package/dist/useDeepEqualEffect.d.ts.map +0 -1
package/dist/index.esm.mjs
CHANGED
|
@@ -219,47 +219,7 @@ var getProxyFormState = (formState, control, localProxyFormState, isRoot = true)
|
|
|
219
219
|
return result;
|
|
220
220
|
};
|
|
221
221
|
|
|
222
|
-
|
|
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
|
-
|
|
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
|
|
360
|
-
|
|
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,
|
|
368
|
-
}), [name,
|
|
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
|
}
|
|
@@ -720,6 +681,39 @@ var createSubject = () => {
|
|
|
720
681
|
};
|
|
721
682
|
};
|
|
722
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
|
+
|
|
723
717
|
var isEmptyObject = (value) => isObject(value) && !Object.keys(value).length;
|
|
724
718
|
|
|
725
719
|
var isFileInput = (element) => element.type === 'file';
|
|
@@ -1296,7 +1290,7 @@ function createFormControl(props = {}) {
|
|
|
1296
1290
|
};
|
|
1297
1291
|
const _fields = {};
|
|
1298
1292
|
let _defaultValues = isObject(_options.defaultValues) || isObject(_options.values)
|
|
1299
|
-
? cloneObject(_options.
|
|
1293
|
+
? cloneObject(_options.defaultValues || _options.values) || {}
|
|
1300
1294
|
: {};
|
|
1301
1295
|
let _formValues = _options.shouldUnregister
|
|
1302
1296
|
? {}
|
|
@@ -2613,7 +2607,6 @@ function useFieldArray(props) {
|
|
|
2613
2607
|
};
|
|
2614
2608
|
}
|
|
2615
2609
|
|
|
2616
|
-
const useIsomorphicLayoutEffect = typeof window !== 'undefined' ? React__default.useLayoutEffect : React__default.useEffect;
|
|
2617
2610
|
/**
|
|
2618
2611
|
* Custom hook to manage the entire form.
|
|
2619
2612
|
*
|