react-hook-form 7.31.1 → 7.32.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 +17 -0
- package/dist/index.cjs.js +1 -1
- package/dist/index.cjs.js.map +1 -1
- package/dist/index.esm.mjs +28 -23
- 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/logic/createFormControl.d.ts.map +1 -1
- package/dist/logic/focusFieldBy.d.ts +2 -2
- package/dist/logic/focusFieldBy.d.ts.map +1 -1
- package/dist/logic/generateWatchOutput.d.ts +1 -1
- package/dist/logic/generateWatchOutput.d.ts.map +1 -1
- package/dist/logic/getCheckboxValue.d.ts +1 -1
- package/dist/logic/getCheckboxValue.d.ts.map +1 -1
- package/dist/logic/getProxyFormState.d.ts +1 -1
- package/dist/logic/getProxyFormState.d.ts.map +1 -1
- package/dist/logic/getRadioValue.d.ts +1 -1
- package/dist/logic/getRadioValue.d.ts.map +1 -1
- package/dist/logic/getResolverOptions.d.ts +1 -1
- package/dist/logic/getResolverOptions.d.ts.map +1 -1
- package/dist/logic/getRuleValue.d.ts +1 -1
- package/dist/logic/getRuleValue.d.ts.map +1 -1
- package/dist/logic/getValueAndMessage.d.ts +1 -1
- package/dist/logic/getValueAndMessage.d.ts.map +1 -1
- package/dist/logic/isWatched.d.ts +1 -1
- package/dist/logic/isWatched.d.ts.map +1 -1
- package/dist/logic/shouldRenderFormState.d.ts +1 -1
- package/dist/logic/shouldRenderFormState.d.ts.map +1 -1
- package/dist/logic/shouldSubscribeByName.d.ts +1 -1
- package/dist/logic/shouldSubscribeByName.d.ts.map +1 -1
- package/dist/logic/validateField.d.ts +1 -1
- package/dist/logic/validateField.d.ts.map +1 -1
- package/dist/types/form.d.ts +6 -6
- package/dist/types/form.d.ts.map +1 -1
- package/dist/utils/cloneObject.d.ts.map +1 -1
- package/dist/utils/getValidationModes.d.ts +2 -1
- package/dist/utils/getValidationModes.d.ts.map +1 -1
- package/dist/utils/isHTMLElement.d.ts.map +1 -1
- package/dist/utils/remove.d.ts +1 -1
- package/dist/utils/remove.d.ts.map +1 -1
- package/package.json +14 -13
package/dist/index.esm.mjs
CHANGED
@@ -558,6 +558,10 @@ function append(data, value) {
|
|
558
558
|
return [...data, ...convertToArrayPayload(value)];
|
559
559
|
}
|
560
560
|
|
561
|
+
var isWeb = typeof window !== 'undefined' &&
|
562
|
+
typeof window.HTMLElement !== 'undefined' &&
|
563
|
+
typeof document !== 'undefined';
|
564
|
+
|
561
565
|
function cloneObject(data) {
|
562
566
|
let copy;
|
563
567
|
const isArray = Array.isArray(data);
|
@@ -567,16 +571,15 @@ function cloneObject(data) {
|
|
567
571
|
else if (data instanceof Set) {
|
568
572
|
copy = new Set(data);
|
569
573
|
}
|
570
|
-
else if (
|
571
|
-
|
572
|
-
}
|
573
|
-
else if (globalThis.FileList && data instanceof FileList) {
|
574
|
-
copy = data;
|
575
|
-
}
|
576
|
-
else if (isArray || isObject(data)) {
|
574
|
+
else if (!(isWeb && (data instanceof Blob || data instanceof FileList)) &&
|
575
|
+
(isArray || isObject(data))) {
|
577
576
|
copy = isArray ? [] : {};
|
578
577
|
for (const key in data) {
|
579
|
-
|
578
|
+
if (isFunction(data[key])) {
|
579
|
+
copy = data;
|
580
|
+
break;
|
581
|
+
}
|
582
|
+
copy[key] = cloneObject(data[key]);
|
580
583
|
}
|
581
584
|
}
|
582
585
|
else {
|
@@ -939,7 +942,11 @@ var isBoolean = (value) => typeof value === 'boolean';
|
|
939
942
|
|
940
943
|
var isFileInput = (element) => element.type === 'file';
|
941
944
|
|
942
|
-
var isHTMLElement = (value) =>
|
945
|
+
var isHTMLElement = (value) => {
|
946
|
+
const owner = value ? value.ownerDocument : 0;
|
947
|
+
const ElementClass = owner && owner.defaultView ? owner.defaultView.HTMLElement : HTMLElement;
|
948
|
+
return value instanceof ElementClass;
|
949
|
+
};
|
943
950
|
|
944
951
|
var isMultipleSelect = (element) => element.type === `select-multiple`;
|
945
952
|
|
@@ -947,10 +954,6 @@ var isRadioInput = (element) => element.type === 'radio';
|
|
947
954
|
|
948
955
|
var isRadioOrCheckbox = (ref) => isRadioInput(ref) || isCheckBoxInput(ref);
|
949
956
|
|
950
|
-
var isWeb = typeof window !== 'undefined' &&
|
951
|
-
typeof window.HTMLElement !== 'undefined' &&
|
952
|
-
typeof document !== 'undefined';
|
953
|
-
|
954
957
|
var live = (ref) => isHTMLElement(ref) && ref.isConnected;
|
955
958
|
|
956
959
|
function markFieldsDirty(data, fields = {}) {
|
@@ -1383,9 +1386,9 @@ function createFormControl(props = {}) {
|
|
1383
1386
|
const validationModeBeforeSubmit = getValidationModes(_options.mode);
|
1384
1387
|
const validationModeAfterSubmit = getValidationModes(_options.reValidateMode);
|
1385
1388
|
const shouldDisplayAllAssociatedErrors = _options.criteriaMode === VALIDATION_MODE.all;
|
1386
|
-
const debounce = (callback
|
1389
|
+
const debounce = (callback) => (wait) => {
|
1387
1390
|
clearTimeout(timer);
|
1388
|
-
timer = window.setTimeout(
|
1391
|
+
timer = window.setTimeout(callback, wait);
|
1389
1392
|
};
|
1390
1393
|
const _updateValid = async (shouldSkipRender) => {
|
1391
1394
|
let isValid = false;
|
@@ -1485,13 +1488,13 @@ function createFormControl(props = {}) {
|
|
1485
1488
|
isFieldDirty && shouldRender && _subjects.state.next(output);
|
1486
1489
|
return isFieldDirty ? output : {};
|
1487
1490
|
};
|
1488
|
-
const shouldRenderByError = async (
|
1491
|
+
const shouldRenderByError = async (name, isValid, error, fieldState) => {
|
1489
1492
|
const previousFieldError = get(_formState.errors, name);
|
1490
1493
|
const shouldUpdateValid = _proxyFormState.isValid && _formState.isValid !== isValid;
|
1491
1494
|
if (props.delayError && error) {
|
1492
1495
|
delayErrorCallback =
|
1493
|
-
delayErrorCallback || debounce(updateErrors,
|
1494
|
-
delayErrorCallback(
|
1496
|
+
delayErrorCallback || debounce(() => updateErrors(name, error));
|
1497
|
+
delayErrorCallback(props.delayError);
|
1495
1498
|
}
|
1496
1499
|
else {
|
1497
1500
|
clearTimeout(timer);
|
@@ -1499,10 +1502,9 @@ function createFormControl(props = {}) {
|
|
1499
1502
|
? set(_formState.errors, name, error)
|
1500
1503
|
: unset(_formState.errors, name);
|
1501
1504
|
}
|
1502
|
-
if ((
|
1505
|
+
if ((error ? !deepEqual(previousFieldError, error) : previousFieldError) ||
|
1503
1506
|
!isEmptyObject(fieldState) ||
|
1504
|
-
shouldUpdateValid)
|
1505
|
-
!shouldSkipRender) {
|
1507
|
+
shouldUpdateValid) {
|
1506
1508
|
const updatedFormState = {
|
1507
1509
|
...fieldState,
|
1508
1510
|
...(shouldUpdateValid ? { isValid } : {}),
|
@@ -1704,6 +1706,7 @@ function createFormControl(props = {}) {
|
|
1704
1706
|
set(_formValues, name, fieldValue);
|
1705
1707
|
if (isBlurEvent) {
|
1706
1708
|
field._f.onBlur && field._f.onBlur(event);
|
1709
|
+
delayErrorCallback && delayErrorCallback(0);
|
1707
1710
|
}
|
1708
1711
|
else if (field._f.onChange) {
|
1709
1712
|
field._f.onChange(event);
|
@@ -1738,7 +1741,7 @@ function createFormControl(props = {}) {
|
|
1738
1741
|
}
|
1739
1742
|
field._f.deps &&
|
1740
1743
|
trigger(field._f.deps);
|
1741
|
-
shouldRenderByError(
|
1744
|
+
shouldRenderByError(name, isValid, error, fieldState);
|
1742
1745
|
}
|
1743
1746
|
};
|
1744
1747
|
const trigger = async (name, options = {}) => {
|
@@ -2067,7 +2070,9 @@ function createFormControl(props = {}) {
|
|
2067
2070
|
? _formState.isDirty
|
2068
2071
|
: !!(keepStateOptions.keepDefaultValues &&
|
2069
2072
|
!deepEqual(formValues, _defaultValues)),
|
2070
|
-
isSubmitted:
|
2073
|
+
isSubmitted: keepStateOptions.keepIsSubmitted
|
2074
|
+
? _formState.isSubmitted
|
2075
|
+
: false,
|
2071
2076
|
dirtyFields: keepStateOptions.keepDirty || keepStateOptions.keepDirtyValues
|
2072
2077
|
? _formState.dirtyFields
|
2073
2078
|
: keepStateOptions.keepDefaultValues && formValues
|