@bombillazo/rhf-plus 7.68.0-plus.0 → 7.69.0-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/dist/index.cjs.js +1 -1
- package/dist/index.cjs.js.map +1 -1
- package/dist/index.esm.mjs +61 -39
- 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/react-server.esm.mjs +46 -29
- package/dist/react-server.esm.mjs.map +1 -1
- package/dist/types/fieldArray.d.ts.map +1 -1
- package/dist/types/form.d.ts +1 -0
- package/dist/types/form.d.ts.map +1 -1
- package/dist/useController.d.ts.map +1 -1
- package/dist/useFieldArray.d.ts.map +1 -1
- package/dist/useWatch.d.ts.map +1 -1
- package/dist/utils/cloneObject.d.ts.map +1 -1
- package/dist/watch.d.ts +24 -15
- package/dist/watch.d.ts.map +1 -1
- package/package.json +15 -15
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"createFormControl.d.ts","sourceRoot":"","sources":["../../src/logic/createFormControl.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAaV,WAAW,EACX,YAAY,EAiBZ,YAAY,EAIZ,aAAa,EAUd,MAAM,UAAU,CAAC;AAyDlB,wBAAgB,iBAAiB,CAC/B,YAAY,SAAS,WAAW,GAAG,WAAW,EAC9C,QAAQ,GAAG,GAAG,EACd,kBAAkB,GAAG,YAAY,EACjC,SAAS,SAAS,YAAY,GAAG,GAAG,EAEpC,KAAK,GAAE,YAAY,CACjB,YAAY,EACZ,QAAQ,EACR,kBAAkB,EAClB,SAAS,CACL,GACL,IAAI,CACL,aAAa,CAAC,YAAY,EAAE,QAAQ,EAAE,kBAAkB,EAAE,SAAS,CAAC,EACpE,WAAW,CACZ,GAAG;IACF,WAAW,EAAE,IAAI,CACf,aAAa,CAAC,YAAY,EAAE,QAAQ,EAAE,kBAAkB,EAAE,SAAS,CAAC,EACpE,WAAW,CACZ,CAAC;CACH,
|
|
1
|
+
{"version":3,"file":"createFormControl.d.ts","sourceRoot":"","sources":["../../src/logic/createFormControl.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAaV,WAAW,EACX,YAAY,EAiBZ,YAAY,EAIZ,aAAa,EAUd,MAAM,UAAU,CAAC;AAyDlB,wBAAgB,iBAAiB,CAC/B,YAAY,SAAS,WAAW,GAAG,WAAW,EAC9C,QAAQ,GAAG,GAAG,EACd,kBAAkB,GAAG,YAAY,EACjC,SAAS,SAAS,YAAY,GAAG,GAAG,EAEpC,KAAK,GAAE,YAAY,CACjB,YAAY,EACZ,QAAQ,EACR,kBAAkB,EAClB,SAAS,CACL,GACL,IAAI,CACL,aAAa,CAAC,YAAY,EAAE,QAAQ,EAAE,kBAAkB,EAAE,SAAS,CAAC,EACpE,WAAW,CACZ,GAAG;IACF,WAAW,EAAE,IAAI,CACf,aAAa,CAAC,YAAY,EAAE,QAAQ,EAAE,kBAAkB,EAAE,SAAS,CAAC,EACpE,WAAW,CACZ,CAAC;CACH,CA0yDA"}
|
|
@@ -52,29 +52,23 @@ var isWeb = typeof window !== 'undefined' &&
|
|
|
52
52
|
typeof document !== 'undefined';
|
|
53
53
|
|
|
54
54
|
function cloneObject(data) {
|
|
55
|
-
let copy;
|
|
56
|
-
const isArray = Array.isArray(data);
|
|
57
|
-
const isFileListInstance = typeof FileList !== 'undefined' ? data instanceof FileList : false;
|
|
58
55
|
if (data instanceof Date) {
|
|
59
|
-
|
|
56
|
+
return new Date(data);
|
|
60
57
|
}
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
if (!isArray && !isPlainObject(data)) {
|
|
65
|
-
copy = data;
|
|
66
|
-
}
|
|
67
|
-
else {
|
|
68
|
-
for (const key in data) {
|
|
69
|
-
if (data.hasOwnProperty(key)) {
|
|
70
|
-
copy[key] = cloneObject(data[key]);
|
|
71
|
-
}
|
|
72
|
-
}
|
|
73
|
-
}
|
|
58
|
+
const isFileListInstance = typeof FileList !== 'undefined' && data instanceof FileList;
|
|
59
|
+
if (isWeb && (data instanceof Blob || isFileListInstance)) {
|
|
60
|
+
return data;
|
|
74
61
|
}
|
|
75
|
-
|
|
62
|
+
const isArray = Array.isArray(data);
|
|
63
|
+
if (!isArray && !(isObject(data) && isPlainObject(data))) {
|
|
76
64
|
return data;
|
|
77
65
|
}
|
|
66
|
+
const copy = isArray ? [] : Object.create(Object.getPrototypeOf(data));
|
|
67
|
+
for (const key in data) {
|
|
68
|
+
if (Object.prototype.hasOwnProperty.call(data, key)) {
|
|
69
|
+
copy[key] = cloneObject(data[key]);
|
|
70
|
+
}
|
|
71
|
+
}
|
|
78
72
|
return copy;
|
|
79
73
|
}
|
|
80
74
|
|
|
@@ -887,6 +881,7 @@ function createFormControl(props = {}) {
|
|
|
887
881
|
action: false,
|
|
888
882
|
mount: false,
|
|
889
883
|
watch: false,
|
|
884
|
+
keepIsValid: false,
|
|
890
885
|
};
|
|
891
886
|
let _names = {
|
|
892
887
|
mount: new Set(),
|
|
@@ -898,7 +893,7 @@ function createFormControl(props = {}) {
|
|
|
898
893
|
};
|
|
899
894
|
let delayErrorCallback;
|
|
900
895
|
let timer = 0;
|
|
901
|
-
const
|
|
896
|
+
const defaultProxyFormState = {
|
|
902
897
|
isDirty: false,
|
|
903
898
|
isDirtySinceSubmit: false,
|
|
904
899
|
hasBeenSubmitted: false,
|
|
@@ -910,6 +905,9 @@ function createFormControl(props = {}) {
|
|
|
910
905
|
isValid: false,
|
|
911
906
|
errors: false,
|
|
912
907
|
};
|
|
908
|
+
const _proxyFormState = {
|
|
909
|
+
...defaultProxyFormState,
|
|
910
|
+
};
|
|
913
911
|
let _proxySubscribeFormState = {
|
|
914
912
|
..._proxyFormState,
|
|
915
913
|
};
|
|
@@ -926,13 +924,21 @@ function createFormControl(props = {}) {
|
|
|
926
924
|
timer = setTimeout(callback, wait);
|
|
927
925
|
};
|
|
928
926
|
const _setValid = async (shouldUpdateValid) => {
|
|
927
|
+
if (_state.keepIsValid) {
|
|
928
|
+
return;
|
|
929
|
+
}
|
|
929
930
|
if ((Array.isArray(_options.disabled) || !_options.disabled) &&
|
|
930
931
|
(_proxyFormState.isValid ||
|
|
931
932
|
_proxySubscribeFormState.isValid ||
|
|
932
933
|
shouldUpdateValid)) {
|
|
933
|
-
|
|
934
|
-
|
|
935
|
-
|
|
934
|
+
let isValid;
|
|
935
|
+
if (_options.resolver) {
|
|
936
|
+
isValid = isEmptyObject((await _runSchema()).errors);
|
|
937
|
+
_updateIsValidating();
|
|
938
|
+
}
|
|
939
|
+
else {
|
|
940
|
+
isValid = await executeBuiltInValidation(_fields, true);
|
|
941
|
+
}
|
|
936
942
|
if (isValid !== _formState.isValid) {
|
|
937
943
|
_subjects.state.next({
|
|
938
944
|
isValid,
|
|
@@ -1128,11 +1134,11 @@ function createFormControl(props = {}) {
|
|
|
1128
1134
|
const _runSchema = async (name) => {
|
|
1129
1135
|
_updateIsValidating(name, true);
|
|
1130
1136
|
const result = await _options.resolver(_formValues, _options.context, getResolverOptions(name || _names.mount, _fields, _options.criteriaMode, _options.shouldUseNativeValidation));
|
|
1131
|
-
_updateIsValidating(name);
|
|
1132
1137
|
return result;
|
|
1133
1138
|
};
|
|
1134
1139
|
const executeSchemaAndUpdateState = async (names) => {
|
|
1135
1140
|
const { errors } = await _runSchema(names);
|
|
1141
|
+
_updateIsValidating(names);
|
|
1136
1142
|
if (names) {
|
|
1137
1143
|
for (const name of names) {
|
|
1138
1144
|
const error = get(errors, name);
|
|
@@ -1458,6 +1464,7 @@ function createFormControl(props = {}) {
|
|
|
1458
1464
|
!isBlurEvent && watched && _subjects.state.next({ ..._formState });
|
|
1459
1465
|
if (_options.resolver) {
|
|
1460
1466
|
const { errors } = await _runSchema([name]);
|
|
1467
|
+
_updateIsValidating([name]);
|
|
1461
1468
|
_updateIsFieldValueUpdated(fieldValue);
|
|
1462
1469
|
if (isFieldValueUpdated) {
|
|
1463
1470
|
const previousErrorLookupResult = schemaErrorLookup(_formState.errors, _fields, name);
|
|
@@ -1609,7 +1616,10 @@ function createFormControl(props = {}) {
|
|
|
1609
1616
|
};
|
|
1610
1617
|
return _subscribe({
|
|
1611
1618
|
...props,
|
|
1612
|
-
formState:
|
|
1619
|
+
formState: {
|
|
1620
|
+
...defaultProxyFormState,
|
|
1621
|
+
...props.formState,
|
|
1622
|
+
},
|
|
1613
1623
|
});
|
|
1614
1624
|
};
|
|
1615
1625
|
const unregister = (name, options = {}) => {
|
|
@@ -1803,6 +1813,7 @@ function createFormControl(props = {}) {
|
|
|
1803
1813
|
});
|
|
1804
1814
|
if (_options.resolver) {
|
|
1805
1815
|
const { errors, values } = await _runSchema();
|
|
1816
|
+
_updateIsValidating();
|
|
1806
1817
|
_formState.errors = errors;
|
|
1807
1818
|
fieldValues = cloneObject(values);
|
|
1808
1819
|
}
|
|
@@ -1947,6 +1958,7 @@ function createFormControl(props = {}) {
|
|
|
1947
1958
|
!!keepStateOptions.keepDirtyValues ||
|
|
1948
1959
|
(!_options.shouldUnregister && !isEmptyObject(values));
|
|
1949
1960
|
_state.watch = !!_options.shouldUnregister;
|
|
1961
|
+
_state.keepIsValid = !!keepStateOptions.keepIsValid;
|
|
1950
1962
|
_state.action = false;
|
|
1951
1963
|
// Clear errors synchronously to prevent validation errors on subsequent submissions
|
|
1952
1964
|
// This fixes the issue where form.reset() causes validation errors on subsequent
|
|
@@ -1994,7 +2006,7 @@ function createFormControl(props = {}) {
|
|
|
1994
2006
|
};
|
|
1995
2007
|
const reset = (formValues, keepStateOptions) => _reset(isFunction(formValues)
|
|
1996
2008
|
? formValues(_formValues)
|
|
1997
|
-
: formValues, keepStateOptions);
|
|
2009
|
+
: formValues, { ..._options.resetOptions, ...keepStateOptions });
|
|
1998
2010
|
const setFocus = (name, options = {}) => {
|
|
1999
2011
|
const field = get(_fields, name);
|
|
2000
2012
|
const fieldReference = field && field._f;
|
|
@@ -2003,10 +2015,14 @@ function createFormControl(props = {}) {
|
|
|
2003
2015
|
? fieldReference.refs[0]
|
|
2004
2016
|
: fieldReference.ref;
|
|
2005
2017
|
if (fieldRef.focus) {
|
|
2006
|
-
|
|
2007
|
-
|
|
2008
|
-
|
|
2009
|
-
fieldRef.
|
|
2018
|
+
// Use setTimeout to ensure focus happens after any pending state updates
|
|
2019
|
+
// This fixes the issue where setFocus doesn't work immediately after setError
|
|
2020
|
+
setTimeout(() => {
|
|
2021
|
+
fieldRef.focus();
|
|
2022
|
+
options.shouldSelect &&
|
|
2023
|
+
isFunction(fieldRef.select) &&
|
|
2024
|
+
fieldRef.select();
|
|
2025
|
+
});
|
|
2010
2026
|
}
|
|
2011
2027
|
}
|
|
2012
2028
|
};
|
|
@@ -2097,6 +2113,7 @@ function createFormControl(props = {}) {
|
|
|
2097
2113
|
setError,
|
|
2098
2114
|
_subscribe,
|
|
2099
2115
|
_runSchema,
|
|
2116
|
+
_updateIsValidating,
|
|
2100
2117
|
_focusError,
|
|
2101
2118
|
_getWatch,
|
|
2102
2119
|
_getDirty,
|