@bombillazo/rhf-plus 7.62.0-plus.2 → 7.62.0-plus.4
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 +6 -0
- package/dist/constants.d.ts +2 -0
- package/dist/constants.d.ts.map +1 -1
- package/dist/index.cjs.js +1 -1
- package/dist/index.cjs.js.map +1 -1
- package/dist/index.esm.mjs +92 -7
- 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/skipValidation.d.ts +5 -1
- package/dist/logic/skipValidation.d.ts.map +1 -1
- package/dist/react-server.esm.mjs +43 -7
- package/dist/react-server.esm.mjs.map +1 -1
- package/dist/types/controller.d.ts +1 -0
- package/dist/types/controller.d.ts.map +1 -1
- package/dist/types/form.d.ts +4 -0
- package/dist/types/form.d.ts.map +1 -1
- package/dist/useController.d.ts.map +1 -1
- package/dist/useForm.d.ts.map +1 -1
- package/dist/useFormState.d.ts.map +1 -1
- package/dist/utils/mergeMissingKeysAsUndefined.d.ts +2 -0
- package/dist/utils/mergeMissingKeysAsUndefined.d.ts.map +1 -0
- package/package.json +1 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"createFormControl.d.ts","sourceRoot":"","sources":["../../src/logic/createFormControl.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAaV,WAAW,EACX,YAAY,EAgBZ,YAAY,EAIZ,aAAa,EAUd,MAAM,UAAU,CAAC;AAuDlB,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,EAgBZ,YAAY,EAIZ,aAAa,EAUd,MAAM,UAAU,CAAC;AAuDlB,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,CA2kDA"}
|
|
@@ -2,6 +2,10 @@ import type { ValidationModeFlags } from '../types';
|
|
|
2
2
|
declare const _default: (isBlurEvent: boolean, isTouched: boolean, isSubmitted: boolean, reValidateMode: {
|
|
3
3
|
isOnBlur: boolean;
|
|
4
4
|
isOnChange: boolean;
|
|
5
|
-
}, mode: Partial<ValidationModeFlags
|
|
5
|
+
}, mode: Partial<ValidationModeFlags>,
|
|
6
|
+
/**
|
|
7
|
+
* Need to keep this order of parameters for backward compatibility
|
|
8
|
+
*/
|
|
9
|
+
isFocusEvent: boolean) => boolean;
|
|
6
10
|
export default _default;
|
|
7
11
|
//# sourceMappingURL=skipValidation.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"skipValidation.d.ts","sourceRoot":"","sources":["../../src/logic/skipValidation.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,UAAU,CAAC;yBAGlD,aAAa,OAAO,EACpB,WAAW,OAAO,EAClB,aAAa,OAAO,EACpB,gBAAgB;IACd,QAAQ,EAAE,OAAO,CAAC;IAClB,UAAU,EAAE,OAAO,CAAC;CACrB,EACD,MAAM,OAAO,CAAC,mBAAmB,CAAC;
|
|
1
|
+
{"version":3,"file":"skipValidation.d.ts","sourceRoot":"","sources":["../../src/logic/skipValidation.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,UAAU,CAAC;yBAGlD,aAAa,OAAO,EACpB,WAAW,OAAO,EAClB,aAAa,OAAO,EACpB,gBAAgB;IACd,QAAQ,EAAE,OAAO,CAAC;IAClB,UAAU,EAAE,OAAO,CAAC;CACrB,EACD,MAAM,OAAO,CAAC,mBAAmB,CAAC;AAClC;;GAEG;AACH,cAAc,OAAO;AAZvB,wBA6BE"}
|
|
@@ -13,7 +13,9 @@ var appendErrors = (name, validateAllFieldCriteria, errors, type, message) => va
|
|
|
13
13
|
|
|
14
14
|
const EVENTS = {
|
|
15
15
|
BLUR: 'blur',
|
|
16
|
-
FOCUS_OUT: 'focusout'
|
|
16
|
+
FOCUS_OUT: 'focusout',
|
|
17
|
+
FOCUS: 'focus',
|
|
18
|
+
FOCUS_IN: 'focusin'};
|
|
17
19
|
const VALIDATION_MODE = {
|
|
18
20
|
onBlur: 'onBlur',
|
|
19
21
|
onChange: 'onChange',
|
|
@@ -577,7 +579,15 @@ var shouldSubscribeByName = (name, signalName, exact) => !name ||
|
|
|
577
579
|
: currentName.startsWith(signalName) ||
|
|
578
580
|
signalName.startsWith(currentName)));
|
|
579
581
|
|
|
580
|
-
var skipValidation = (isBlurEvent, isTouched, isSubmitted, reValidateMode, mode
|
|
582
|
+
var skipValidation = (isBlurEvent, isTouched, isSubmitted, reValidateMode, mode,
|
|
583
|
+
/**
|
|
584
|
+
* Need to keep this order of parameters for backward compatibility
|
|
585
|
+
*/
|
|
586
|
+
isFocusEvent) => {
|
|
587
|
+
// Focus events should always skip validation
|
|
588
|
+
if (isFocusEvent) {
|
|
589
|
+
return true;
|
|
590
|
+
}
|
|
581
591
|
if (mode.isOnAll) {
|
|
582
592
|
return false;
|
|
583
593
|
}
|
|
@@ -844,6 +854,7 @@ function createFormControl(props = {}) {
|
|
|
844
854
|
isValid: false,
|
|
845
855
|
touchedFields: {},
|
|
846
856
|
dirtyFields: {},
|
|
857
|
+
focusedField: undefined,
|
|
847
858
|
validatingFields: {},
|
|
848
859
|
errors: _options.errors || {},
|
|
849
860
|
disabled: Array.isArray(_options.disabled)
|
|
@@ -877,6 +888,7 @@ function createFormControl(props = {}) {
|
|
|
877
888
|
dirtyFields: false,
|
|
878
889
|
validatingFields: false,
|
|
879
890
|
touchedFields: false,
|
|
891
|
+
focusedField: false,
|
|
880
892
|
isValidating: false,
|
|
881
893
|
isValid: false,
|
|
882
894
|
errors: false,
|
|
@@ -988,7 +1000,7 @@ function createFormControl(props = {}) {
|
|
|
988
1000
|
_state.mount && _setValid();
|
|
989
1001
|
}
|
|
990
1002
|
};
|
|
991
|
-
const updateTouchAndDirty = (name, fieldValue, isBlurEvent, shouldDirty, shouldRender) => {
|
|
1003
|
+
const updateTouchAndDirty = (name, fieldValue, isBlurEvent, isFocusEvent, shouldDirty, shouldRender) => {
|
|
992
1004
|
let shouldUpdateField = false;
|
|
993
1005
|
let isPreviousDirty = false;
|
|
994
1006
|
const output = {
|
|
@@ -1025,6 +1037,25 @@ function createFormControl(props = {}) {
|
|
|
1025
1037
|
isPreviousFieldTouched !== isBlurEvent);
|
|
1026
1038
|
}
|
|
1027
1039
|
}
|
|
1040
|
+
// Handle focus state
|
|
1041
|
+
if (isFocusEvent || isBlurEvent) {
|
|
1042
|
+
const wasPreviouslyFocused = _formState.focusedField === name;
|
|
1043
|
+
const shouldBeFocused = isFocusEvent && !isBlurEvent;
|
|
1044
|
+
if (wasPreviouslyFocused !== shouldBeFocused) {
|
|
1045
|
+
if (shouldBeFocused) {
|
|
1046
|
+
_formState.focusedField = name;
|
|
1047
|
+
}
|
|
1048
|
+
else {
|
|
1049
|
+
_formState.focusedField = undefined;
|
|
1050
|
+
}
|
|
1051
|
+
output.focusedField = _formState.focusedField;
|
|
1052
|
+
shouldUpdateField =
|
|
1053
|
+
shouldUpdateField ||
|
|
1054
|
+
((_proxyFormState.focusedField ||
|
|
1055
|
+
_proxySubscribeFormState.focusedField) &&
|
|
1056
|
+
wasPreviouslyFocused !== shouldBeFocused);
|
|
1057
|
+
}
|
|
1058
|
+
}
|
|
1028
1059
|
shouldUpdateField && shouldRender && _subjects.state.next(output);
|
|
1029
1060
|
}
|
|
1030
1061
|
return shouldUpdateField ? output : {};
|
|
@@ -1190,7 +1221,8 @@ function createFormControl(props = {}) {
|
|
|
1190
1221
|
}
|
|
1191
1222
|
}
|
|
1192
1223
|
(options.shouldDirty || options.shouldTouch) &&
|
|
1193
|
-
updateTouchAndDirty(name, fieldValue, options.shouldTouch,
|
|
1224
|
+
updateTouchAndDirty(name, fieldValue, options.shouldTouch, false, // isFocusEvent - not applicable for setValue
|
|
1225
|
+
options.shouldDirty, true);
|
|
1194
1226
|
options.shouldValidate && trigger(name);
|
|
1195
1227
|
};
|
|
1196
1228
|
const setValues = (name, value, options) => {
|
|
@@ -1279,12 +1311,13 @@ function createFormControl(props = {}) {
|
|
|
1279
1311
|
? getFieldValue(field._f)
|
|
1280
1312
|
: getEventValue(event);
|
|
1281
1313
|
const isBlurEvent = event.type === EVENTS.BLUR || event.type === EVENTS.FOCUS_OUT;
|
|
1314
|
+
const isFocusEvent = event.type === EVENTS.FOCUS || event.type === EVENTS.FOCUS_IN;
|
|
1282
1315
|
const shouldSkipValidation = (!hasValidation(field._f) &&
|
|
1283
1316
|
!_options.resolver &&
|
|
1284
1317
|
!get(_formState.errors, name) &&
|
|
1285
1318
|
!field._f.deps) ||
|
|
1286
|
-
skipValidation(isBlurEvent, get(_formState.touchedFields, name), _formState.isSubmitted, validationModeAfterSubmit, validationModeBeforeSubmit);
|
|
1287
|
-
const watched = isWatched(name, _names, isBlurEvent);
|
|
1319
|
+
skipValidation(isBlurEvent, get(_formState.touchedFields, name), _formState.isSubmitted, validationModeAfterSubmit, validationModeBeforeSubmit, isFocusEvent);
|
|
1320
|
+
const watched = isWatched(name, _names, isBlurEvent || isFocusEvent);
|
|
1288
1321
|
set(_formValues, name, fieldValue);
|
|
1289
1322
|
if (isBlurEvent) {
|
|
1290
1323
|
if (!target || !target.readOnly) {
|
|
@@ -1295,7 +1328,7 @@ function createFormControl(props = {}) {
|
|
|
1295
1328
|
else if (field._f.onChange) {
|
|
1296
1329
|
field._f.onChange(event);
|
|
1297
1330
|
}
|
|
1298
|
-
const fieldState = updateTouchAndDirty(name, fieldValue, isBlurEvent);
|
|
1331
|
+
const fieldState = updateTouchAndDirty(name, fieldValue, isBlurEvent, isFocusEvent);
|
|
1299
1332
|
const shouldRender = !isEmptyObject(fieldState) || watched;
|
|
1300
1333
|
!isBlurEvent &&
|
|
1301
1334
|
_subjects.state.next({
|
|
@@ -1409,6 +1442,7 @@ function createFormControl(props = {}) {
|
|
|
1409
1442
|
error: get((formState || _formState).errors, name),
|
|
1410
1443
|
isValidating: !!get(_formState.validatingFields, name),
|
|
1411
1444
|
isTouched: !!get((formState || _formState).touchedFields, name),
|
|
1445
|
+
isFocused: (formState || _formState).focusedField === name,
|
|
1412
1446
|
});
|
|
1413
1447
|
const clearErrors = (name) => {
|
|
1414
1448
|
name &&
|
|
@@ -1548,6 +1582,7 @@ function createFormControl(props = {}) {
|
|
|
1548
1582
|
name,
|
|
1549
1583
|
onChange,
|
|
1550
1584
|
onBlur: onChange,
|
|
1585
|
+
onFocus: onChange,
|
|
1551
1586
|
ref: (ref) => {
|
|
1552
1587
|
if (ref) {
|
|
1553
1588
|
register(name, options);
|
|
@@ -1813,6 +1848,7 @@ function createFormControl(props = {}) {
|
|
|
1813
1848
|
touchedFields: keepStateOptions.keepTouched
|
|
1814
1849
|
? _formState.touchedFields
|
|
1815
1850
|
: {},
|
|
1851
|
+
focusedField: undefined, // Always reset focused field on form reset
|
|
1816
1852
|
errors: keepStateOptions.keepErrors ? _formState.errors : {},
|
|
1817
1853
|
isSubmitSuccessful: keepStateOptions.keepIsSubmitSuccessful
|
|
1818
1854
|
? _formState.isSubmitSuccessful
|