@juantroconisf/lib 11.10.0 → 11.11.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.js +21 -13
- package/dist/index.mjs +30 -22
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -652,12 +652,15 @@ function useValidation(validationSchema, stateRef, metadataRef, setMetadata, arr
|
|
|
652
652
|
setMetadata(cleanMetadata);
|
|
653
653
|
return Promise.resolve({ isValid: true, errors: [], results: [] });
|
|
654
654
|
}, [validationSchema, metadataRef, stateRef, arrayIdentifiers, setMetadata]);
|
|
655
|
-
return
|
|
656
|
-
|
|
657
|
-
|
|
658
|
-
|
|
659
|
-
|
|
660
|
-
|
|
655
|
+
return (0, import_react3.useMemo)(
|
|
656
|
+
() => ({
|
|
657
|
+
validateField,
|
|
658
|
+
validateFields,
|
|
659
|
+
validateAll,
|
|
660
|
+
runValidation
|
|
661
|
+
}),
|
|
662
|
+
[validateField, validateFields, validateAll, runValidation]
|
|
663
|
+
);
|
|
661
664
|
}
|
|
662
665
|
|
|
663
666
|
// src/hooks/useForm/useHandlers.ts
|
|
@@ -960,11 +963,14 @@ function useHandlers(stateRef, setState, metadataRef, setMetadata, validationSch
|
|
|
960
963
|
metadataRef,
|
|
961
964
|
propsCache
|
|
962
965
|
]);
|
|
963
|
-
return
|
|
964
|
-
|
|
965
|
-
|
|
966
|
-
|
|
967
|
-
|
|
966
|
+
return (0, import_react4.useMemo)(
|
|
967
|
+
() => ({
|
|
968
|
+
on,
|
|
969
|
+
handleFieldChange,
|
|
970
|
+
createHandlers
|
|
971
|
+
}),
|
|
972
|
+
[on, handleFieldChange, createHandlers]
|
|
973
|
+
);
|
|
968
974
|
}
|
|
969
975
|
|
|
970
976
|
// src/hooks/useForm/useFormHelpers.ts
|
|
@@ -1347,6 +1353,8 @@ function useForm(schema, {
|
|
|
1347
1353
|
keepValuesPropRef.current = keepValuesProp;
|
|
1348
1354
|
const validateAllRef = (0, import_react6.useRef)(validateAll);
|
|
1349
1355
|
validateAllRef.current = validateAll;
|
|
1356
|
+
const handleResetRef = (0, import_react6.useRef)(handleReset);
|
|
1357
|
+
handleResetRef.current = handleReset;
|
|
1350
1358
|
const ControlledForm = (0, import_react6.useMemo)(() => {
|
|
1351
1359
|
return (props) => {
|
|
1352
1360
|
const { onSubmit, ...rest } = props;
|
|
@@ -1356,7 +1364,7 @@ function useForm(schema, {
|
|
|
1356
1364
|
if (!isValid) return;
|
|
1357
1365
|
onFormSubmitPropRef.current?.(stateRef.current, e);
|
|
1358
1366
|
if (resetOnSubmitRef.current) {
|
|
1359
|
-
|
|
1367
|
+
handleResetRef.current({ keepValues: keepValuesPropRef.current });
|
|
1360
1368
|
}
|
|
1361
1369
|
onSubmit?.(stateRef.current, e);
|
|
1362
1370
|
};
|
|
@@ -1369,7 +1377,7 @@ function useForm(schema, {
|
|
|
1369
1377
|
}
|
|
1370
1378
|
);
|
|
1371
1379
|
};
|
|
1372
|
-
}, [
|
|
1380
|
+
}, []);
|
|
1373
1381
|
return (0, import_react6.useMemo)(
|
|
1374
1382
|
() => ({
|
|
1375
1383
|
state,
|
package/dist/index.mjs
CHANGED
|
@@ -9,7 +9,7 @@ var NextUIError = class {
|
|
|
9
9
|
};
|
|
10
10
|
|
|
11
11
|
// src/hooks/useForm.tsx
|
|
12
|
-
import { useCallback as useCallback3, useMemo as
|
|
12
|
+
import { useCallback as useCallback3, useMemo as useMemo5, useRef as useRef2 } from "react";
|
|
13
13
|
import { Form } from "@heroui/react";
|
|
14
14
|
|
|
15
15
|
// src/hooks/useComponentLang.tsx
|
|
@@ -403,7 +403,7 @@ function useFormState(schema, arrayIdentifiers) {
|
|
|
403
403
|
}
|
|
404
404
|
|
|
405
405
|
// src/hooks/useForm/useValidation.ts
|
|
406
|
-
import { useCallback } from "react";
|
|
406
|
+
import { useCallback, useMemo as useMemo2 } from "react";
|
|
407
407
|
import { isSchema as isSchema2 } from "yup";
|
|
408
408
|
function useValidation(validationSchema, stateRef, metadataRef, setMetadata, arrayIdentifiers, ruleCache) {
|
|
409
409
|
const runValidation = useCallback(
|
|
@@ -626,16 +626,19 @@ function useValidation(validationSchema, stateRef, metadataRef, setMetadata, arr
|
|
|
626
626
|
setMetadata(cleanMetadata);
|
|
627
627
|
return Promise.resolve({ isValid: true, errors: [], results: [] });
|
|
628
628
|
}, [validationSchema, metadataRef, stateRef, arrayIdentifiers, setMetadata]);
|
|
629
|
-
return
|
|
630
|
-
|
|
631
|
-
|
|
632
|
-
|
|
633
|
-
|
|
634
|
-
|
|
629
|
+
return useMemo2(
|
|
630
|
+
() => ({
|
|
631
|
+
validateField,
|
|
632
|
+
validateFields,
|
|
633
|
+
validateAll,
|
|
634
|
+
runValidation
|
|
635
|
+
}),
|
|
636
|
+
[validateField, validateFields, validateAll, runValidation]
|
|
637
|
+
);
|
|
635
638
|
}
|
|
636
639
|
|
|
637
640
|
// src/hooks/useForm/useHandlers.ts
|
|
638
|
-
import { useCallback as useCallback2, useMemo as
|
|
641
|
+
import { useCallback as useCallback2, useMemo as useMemo3 } from "react";
|
|
639
642
|
|
|
640
643
|
// src/utils/utils.ts
|
|
641
644
|
function handleNestedChange({
|
|
@@ -851,7 +854,7 @@ function useHandlers(stateRef, setState, metadataRef, setMetadata, validationSch
|
|
|
851
854
|
},
|
|
852
855
|
[validationSchema, ruleCache, metadataRef, setMetadata, validateField, stateRef]
|
|
853
856
|
);
|
|
854
|
-
const on =
|
|
857
|
+
const on = useMemo3(() => {
|
|
855
858
|
const getCachedProps = (method, args, factory) => {
|
|
856
859
|
const data = resolveFieldData(
|
|
857
860
|
args,
|
|
@@ -934,17 +937,20 @@ function useHandlers(stateRef, setState, metadataRef, setMetadata, validationSch
|
|
|
934
937
|
metadataRef,
|
|
935
938
|
propsCache
|
|
936
939
|
]);
|
|
937
|
-
return
|
|
938
|
-
|
|
939
|
-
|
|
940
|
-
|
|
941
|
-
|
|
940
|
+
return useMemo3(
|
|
941
|
+
() => ({
|
|
942
|
+
on,
|
|
943
|
+
handleFieldChange,
|
|
944
|
+
createHandlers
|
|
945
|
+
}),
|
|
946
|
+
[on, handleFieldChange, createHandlers]
|
|
947
|
+
);
|
|
942
948
|
}
|
|
943
949
|
|
|
944
950
|
// src/hooks/useForm/useFormHelpers.ts
|
|
945
|
-
import { useMemo as
|
|
951
|
+
import { useMemo as useMemo4 } from "react";
|
|
946
952
|
function useFormHelpers(stateRef, setState, setMetadata, metadataRef, arrayIdentifiers, validationSchema, getIndex3, validateAll, validateFields, ruleCache) {
|
|
947
|
-
const helpers =
|
|
953
|
+
const helpers = useMemo4(
|
|
948
954
|
() => ({
|
|
949
955
|
addItem: (arrayKey, item, index) => {
|
|
950
956
|
setState((prev) => {
|
|
@@ -1155,7 +1161,7 @@ function useForm(schema, {
|
|
|
1155
1161
|
} = useFormState(schema, arrayIdentifiers);
|
|
1156
1162
|
useComponentLanguage();
|
|
1157
1163
|
const ruleCache = useRef2(/* @__PURE__ */ new Map());
|
|
1158
|
-
|
|
1164
|
+
useMemo5(() => {
|
|
1159
1165
|
ruleCache.current.clear();
|
|
1160
1166
|
}, [validationSchema]);
|
|
1161
1167
|
const getIndexFn = useCallback3(
|
|
@@ -1321,7 +1327,9 @@ function useForm(schema, {
|
|
|
1321
1327
|
keepValuesPropRef.current = keepValuesProp;
|
|
1322
1328
|
const validateAllRef = useRef2(validateAll);
|
|
1323
1329
|
validateAllRef.current = validateAll;
|
|
1324
|
-
const
|
|
1330
|
+
const handleResetRef = useRef2(handleReset);
|
|
1331
|
+
handleResetRef.current = handleReset;
|
|
1332
|
+
const ControlledForm = useMemo5(() => {
|
|
1325
1333
|
return (props) => {
|
|
1326
1334
|
const { onSubmit, ...rest } = props;
|
|
1327
1335
|
const handleSubmit = async (e) => {
|
|
@@ -1330,7 +1338,7 @@ function useForm(schema, {
|
|
|
1330
1338
|
if (!isValid) return;
|
|
1331
1339
|
onFormSubmitPropRef.current?.(stateRef.current, e);
|
|
1332
1340
|
if (resetOnSubmitRef.current) {
|
|
1333
|
-
|
|
1341
|
+
handleResetRef.current({ keepValues: keepValuesPropRef.current });
|
|
1334
1342
|
}
|
|
1335
1343
|
onSubmit?.(stateRef.current, e);
|
|
1336
1344
|
};
|
|
@@ -1343,8 +1351,8 @@ function useForm(schema, {
|
|
|
1343
1351
|
}
|
|
1344
1352
|
);
|
|
1345
1353
|
};
|
|
1346
|
-
}, [
|
|
1347
|
-
return
|
|
1354
|
+
}, []);
|
|
1355
|
+
return useMemo5(
|
|
1348
1356
|
() => ({
|
|
1349
1357
|
state,
|
|
1350
1358
|
setState,
|