@paragrav/rhf-utils 0.0.48 → 0.0.51
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/assets/index-BgBykTYQ.js +40 -0
- package/dist/esm/devtool/LazyDevTool.mjs +7 -11
- package/dist/esm/env-conditions/production.mjs +4 -0
- package/dist/esm/errors/context/provider.mjs +11 -9
- package/dist/esm/errors/orphan/useOrphanFormErrorsToConsole.mjs +8 -9
- package/dist/esm/errors/outputErrors.mjs +5 -6
- package/dist/esm/errors/root/FormRootErrors.mjs +7 -7
- package/dist/esm/errors/root/FormRootErrorsFromContext.mjs +11 -0
- package/dist/esm/errors/useFormErrorsEffect.mjs +6 -6
- package/dist/esm/errors/useFormErrorsToConsole.mjs +17 -13
- package/dist/esm/{main.mjs → exports.mjs} +44 -42
- package/dist/esm/form/Form.mjs +41 -65
- package/dist/esm/form/FormWithProviders.mjs +10 -0
- package/dist/esm/form/context/FormProvider.mjs +17 -19
- package/dist/esm/form/context/group/useFormGroupChildIsMountedTracker.mjs +3 -1
- package/dist/esm/form/context/utils/FormUtilsContextProvider.mjs +10 -10
- package/dist/esm/form/useForm.mjs +15 -17
- package/dist/esm/form/useFormWithProviders.mjs +28 -0
- package/dist/esm/{form/FormError.mjs → submit/error/FormSubmitError.mjs} +2 -2
- package/dist/esm/submit/error/handleFormSubmitError.mjs +12 -0
- package/dist/esm/submit/useResetFormOnSubmitError.mjs +18 -0
- package/dist/esm/submit/useSubmitFormOnChange.mjs +1 -1
- package/dist/index.html +12 -0
- package/dist/types/errors/context/provider.d.ts +1 -1
- package/dist/types/errors/root/FormRootErrorsFromContext.d.ts +3 -0
- package/dist/types/errors/useFormErrorsIfAny.d.ts +1 -1
- package/dist/types/exports.d.ts +37 -0
- package/dist/types/form/ErrorBoundary.d.ts +15 -0
- package/dist/types/form/Form.d.ts +2 -2
- package/dist/types/form/FormWithProviders.d.ts +13 -0
- package/dist/types/form/useFormWithProviders.d.ts +31 -0
- package/dist/types/main.d.ts +1 -36
- package/dist/types/src/devtool/LazyDevTool.d.ts +9 -0
- package/dist/types/src/env-conditions/development.d.ts +7 -0
- package/dist/types/src/env-conditions/production.d.ts +1 -0
- package/dist/types/src/errors/consoleErrors.d.ts +13 -0
- package/dist/types/src/errors/context/index.d.ts +10 -0
- package/dist/types/src/errors/context/provider.d.ts +11 -0
- package/dist/types/{errors → src/errors/flat}/getFlatFieldErrors.d.ts +2 -2
- package/dist/types/src/errors/flat/types.d.ts +13 -0
- package/dist/types/src/errors/flat/useFormFlatFieldErrorsMemo.d.ts +5 -0
- package/dist/types/src/errors/flat/useRefdFieldErrorsMemo.d.ts +9 -0
- package/dist/types/src/errors/isFieldError.d.ts +7 -0
- package/dist/types/src/errors/message/FormErrorMessage.d.ts +8 -0
- package/dist/types/src/errors/message/FormErrorMessageByPath.d.ts +9 -0
- package/dist/types/src/errors/nonfield/FormNonFieldErrorMarker.d.ts +10 -0
- package/dist/types/src/errors/nonfield/FormNonFieldErrorMarker.spec.d.ts +1 -0
- package/dist/types/src/errors/nonfield/FormNonFieldErrorMarker.utils.d.ts +2 -0
- package/dist/types/src/errors/nonfield/FormNonFieldErrorMarkerHtmlAttribute.d.ts +5 -0
- package/dist/types/src/errors/nonfield/isNonFieldError.d.ts +19 -0
- package/dist/types/src/errors/orphan/getOrphansFromFieldErrors.d.ts +5 -0
- package/dist/types/src/errors/orphan/getOrphansFromFlatFieldErrors.d.ts +4 -0
- package/dist/types/src/errors/orphan/useFormHasOrphanAndNoFieldErrors.d.ts +9 -0
- package/dist/types/src/errors/orphan/useOrphanFormErrorsMemo.d.ts +4 -0
- package/dist/types/src/errors/orphan/useOrphanFormErrorsToConsole.d.ts +9 -0
- package/dist/types/src/errors/outputErrors.d.ts +13 -0
- package/dist/types/src/errors/root/FormRootErrors.d.ts +7 -0
- package/dist/types/src/errors/root/FormRootErrorsFromContext.d.ts +3 -0
- package/dist/types/src/errors/root/consts.d.ts +1 -0
- package/dist/types/src/errors/root/getRootsFromFieldErrors.d.ts +5 -0
- package/dist/types/src/errors/root/getRootsFromFlatFieldErrors.d.ts +4 -0
- package/dist/types/src/errors/root/isFormErrorPathRoot.d.ts +6 -0
- package/dist/types/src/errors/root/useRootFormFieldErrorsMemo.d.ts +6 -0
- package/dist/types/src/errors/useFormErrorConsoleDebug.d.ts +8 -0
- package/dist/types/src/errors/useFormErrorsEffect.d.ts +4 -0
- package/dist/types/src/errors/useFormErrorsIfAny.d.ts +6 -0
- package/dist/types/src/errors/useFormErrorsMemo.d.ts +7 -0
- package/dist/types/src/errors/useFormErrorsToConsole.d.ts +13 -0
- package/dist/types/src/errors/useFormRequestSubmit.d.ts +6 -0
- package/dist/types/src/exports.d.ts +37 -0
- package/dist/types/src/form/ErrorBoundary.d.ts +15 -0
- package/dist/types/src/form/Form.d.ts +29 -0
- package/dist/types/src/form/FormBase.d.ts +9 -0
- package/dist/types/src/form/FormWithProviders.d.ts +13 -0
- package/dist/types/src/form/context/FormProvider.d.ts +15 -0
- package/dist/types/src/form/context/group/FormGroupContextProvider.d.ts +5 -0
- package/dist/types/src/form/context/group/index.d.ts +15 -0
- package/dist/types/src/form/context/group/useFormGroupChildIsMountedTracker.d.ts +2 -0
- package/dist/types/src/form/context/group/useFormGroupChildIsSubmittingTracker.d.ts +2 -0
- package/dist/types/src/form/context/group/useFormGroupIsAnyBusy.d.ts +2 -0
- package/dist/types/src/form/context/group/useFormGroupIsChildBusy.d.ts +2 -0
- package/dist/types/src/form/context/group/useFormGroupIsParentBusy.d.ts +2 -0
- package/dist/types/src/form/context/group/useFormGroupParentTracker.d.ts +7 -0
- package/dist/types/src/form/context/utils/FormUtilsContextProvider.d.ts +14 -0
- package/dist/types/src/form/context/utils/useFormUtilsContext.d.ts +9 -0
- package/dist/types/src/form/search/FormSearch.d.ts +32 -0
- package/dist/types/src/form/search/FormSearchHiddenInputs.d.ts +13 -0
- package/dist/types/src/form/search/getNewSearchParams.d.ts +2 -0
- package/dist/types/src/form/useForm.d.ts +29 -0
- package/dist/types/src/form/useFormIsBusy.d.ts +2 -0
- package/dist/types/src/form/useFormOrParentIsBusy.d.ts +2 -0
- package/dist/types/{form/useFormWithProvider.d.ts → src/form/useFormWithProviders.d.ts} +4 -4
- package/dist/types/src/form/utils/getSubmitterButtonData.d.ts +11 -0
- package/dist/types/src/isEmptyObject.d.ts +2 -0
- package/dist/types/src/main.d.ts +1 -0
- package/dist/types/{form/FormError.d.ts → src/submit/error/FormSubmitError.d.ts} +1 -1
- package/dist/types/src/submit/error/handleFormSubmitError.d.ts +7 -0
- package/dist/types/src/submit/useFormOnSubmitSuccessful.d.ts +2 -0
- package/dist/types/src/submit/useFormOnSubmitSuccessfulAndReset.d.ts +13 -0
- package/dist/types/src/submit/useResetFormOnSubmitError.d.ts +7 -0
- package/dist/types/src/submit/useResetFormOnSubmitSuccessful.d.ts +12 -0
- package/dist/types/src/submit/useSubmitFormOnChange.d.ts +4 -0
- package/dist/types/{utils/createRequiredContext.d.ts → src/utils/createContext.d.ts} +2 -2
- package/dist/types/src/utils/fixedForwardRef.d.ts +7 -0
- package/dist/types/src/utils/useImperativeForwardedRef.d.ts +11 -0
- package/dist/types/src/utils/useThrowAsyncError.d.ts +5 -0
- package/dist/types/src/utils/useToggle.d.ts +4 -0
- package/dist/types/submit/error/FormSubmitError.d.ts +6 -0
- package/dist/types/submit/error/handleFormSubmitError.d.ts +7 -0
- package/dist/types/submit/useResetFormOnSubmitError.d.ts +7 -0
- package/dist/types/submit/useSubmitFormOnChange.d.ts +1 -1
- package/dist/types/utils/useThrowAsyncError.d.ts +5 -0
- package/package.json +30 -17
- package/dist/esm/form/FormWithProvider.mjs +0 -9
- package/dist/esm/form/useFormWithProvider.mjs +0 -30
- package/dist/types/errors/flat/getFlatFieldErrorsByFilter.d.ts +0 -9
- package/dist/types/errors/orphan/getOrphanFlatFieldErrors.d.ts +0 -5
- package/dist/types/errors/orphan/useOrphanFormErrors.d.ts +0 -4
- package/dist/types/errors/orphan/useOrphanFormErrorsToConsoleError.d.ts +0 -9
- package/dist/types/errors/root/getRootFlatFieldErrors.d.ts +0 -8
- package/dist/types/errors/root/useRootFormFieldErrors.d.ts +0 -6
- package/dist/types/errors/root/utils.d.ts +0 -12
- package/dist/types/errors/useFormErrorsOnChange.d.ts +0 -7
- package/dist/types/errors/useFormFieldErrors.d.ts +0 -6
- package/dist/types/errors/useFormFlatFieldErrors.d.ts +0 -5
- package/dist/types/form/FormWithProvider.d.ts +0 -13
- package/dist/types/form/context/group/useAsFormGroupParent.d.ts +0 -7
- package/dist/types/form/context/parent/FormParentContextProvider.d.ts +0 -5
- package/dist/types/form/context/parent/index.d.ts +0 -6
- package/dist/types/form/context/parent/useAsFormParentState.d.ts +0 -7
- package/dist/types/form/context/parent/useFormParentIsBusy.d.ts +0 -7
- package/dist/types/form/toggle/ToggleForm.d.ts +0 -18
- /package/dist/types/{errors → src/errors/flat}/flattenFieldErrors.d.ts +0 -0
|
@@ -6,69 +6,71 @@ import { default as d } from "./errors/message/FormErrorMessageByPath.mjs";
|
|
|
6
6
|
import { default as x } from "./errors/nonfield/FormNonFieldErrorMarker.mjs";
|
|
7
7
|
import { default as i } from "./errors/nonfield/FormNonFieldErrorMarkerHtmlAttribute.mjs";
|
|
8
8
|
import { default as E } from "./errors/orphan/useFormHasOrphanAndNoFieldErrors.mjs";
|
|
9
|
-
import { default as
|
|
10
|
-
import { default as
|
|
9
|
+
import { default as b } from "./errors/orphan/useOrphanFormErrorsMemo.mjs";
|
|
10
|
+
import { default as c } from "./errors/orphan/useOrphanFormErrorsToConsole.mjs";
|
|
11
11
|
import { default as P } from "./errors/root/useRootFormFieldErrorsMemo.mjs";
|
|
12
12
|
import { default as v } from "./errors/useFormErrorConsoleDebug.mjs";
|
|
13
13
|
import { default as G } from "./errors/useFormErrorsEffect.mjs";
|
|
14
|
-
import { default as
|
|
15
|
-
import { default as
|
|
14
|
+
import { default as g } from "./errors/useFormErrorsIfAny.mjs";
|
|
15
|
+
import { default as I } from "./errors/useFormErrorsMemo.mjs";
|
|
16
16
|
import { default as B } from "./errors/useFormRequestSubmit.mjs";
|
|
17
|
-
import { default as
|
|
18
|
-
import {
|
|
19
|
-
import { default as U } from "./form/
|
|
20
|
-
import { default as q } from "./form/
|
|
21
|
-
import { default as L } from "./form/
|
|
22
|
-
import { default as w } from "./form/context/
|
|
23
|
-
import { default as K } from "./form/context/utils/
|
|
24
|
-
import { default as V } from "./form/context/
|
|
25
|
-
import { default as Y } from "./form/context/group/
|
|
26
|
-
import { default as _ } from "./form/context/group/
|
|
27
|
-
import { default as rr } from "./form/context/group/
|
|
28
|
-
import { default as er } from "./form/context/group/
|
|
29
|
-
import { default as sr } from "./form/context/group/
|
|
30
|
-
import { default as ur } from "./form/context/group/
|
|
31
|
-
import { default as fr } from "./form/
|
|
32
|
-
import {
|
|
17
|
+
import { default as T } from "./form/Form.mjs";
|
|
18
|
+
import { default as N } from "./form/FormWithProviders.mjs";
|
|
19
|
+
import { default as U } from "./form/useForm.mjs";
|
|
20
|
+
import { default as q } from "./form/useFormWithProviders.mjs";
|
|
21
|
+
import { default as L } from "./form/context/FormProvider.mjs";
|
|
22
|
+
import { default as w } from "./form/context/utils/FormUtilsContextProvider.mjs";
|
|
23
|
+
import { default as K } from "./form/context/utils/useFormUtilsContext.mjs";
|
|
24
|
+
import { default as V } from "./form/context/group/FormGroupContextProvider.mjs";
|
|
25
|
+
import { default as Y } from "./form/context/group/useFormGroupChildIsMountedTracker.mjs";
|
|
26
|
+
import { default as _ } from "./form/context/group/useFormGroupChildIsSubmittingTracker.mjs";
|
|
27
|
+
import { default as rr } from "./form/context/group/useFormGroupIsAnyBusy.mjs";
|
|
28
|
+
import { default as er } from "./form/context/group/useFormGroupIsChildBusy.mjs";
|
|
29
|
+
import { default as sr } from "./form/context/group/useFormGroupIsParentBusy.mjs";
|
|
30
|
+
import { default as ur } from "./form/context/group/useFormGroupParentTracker.mjs";
|
|
31
|
+
import { default as fr } from "./form/utils/getSubmitterButtonData.mjs";
|
|
32
|
+
import { FormSubmitError as dr } from "./submit/error/FormSubmitError.mjs";
|
|
33
33
|
import { default as xr } from "./submit/useFormOnSubmitSuccessful.mjs";
|
|
34
34
|
import { default as ir } from "./submit/useFormOnSubmitSuccessfulAndReset.mjs";
|
|
35
|
-
import { default as Er } from "./submit/
|
|
35
|
+
import { default as Er } from "./submit/useResetFormOnSubmitError.mjs";
|
|
36
|
+
import { default as br } from "./submit/useResetFormOnSubmitSuccessful.mjs";
|
|
36
37
|
import { default as cr } from "./submit/useSubmitFormOnChange.mjs";
|
|
37
38
|
export {
|
|
38
|
-
|
|
39
|
-
N as FormError,
|
|
39
|
+
T as Form,
|
|
40
40
|
f as FormErrorMessage,
|
|
41
41
|
d as FormErrorMessageByPath,
|
|
42
42
|
u as FormErrorsFlatContextProvider,
|
|
43
|
-
|
|
43
|
+
V as FormGroupContextProvider,
|
|
44
44
|
x as FormNonFieldErrorMarker,
|
|
45
45
|
i as FormNonFieldErrorMarkerHtmlAttribute,
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
46
|
+
L as FormProvider,
|
|
47
|
+
dr as FormSubmitError,
|
|
48
|
+
w as FormUtilsContextProvider,
|
|
49
|
+
N as FormWithProviders,
|
|
49
50
|
e as LazyDevTool,
|
|
50
|
-
|
|
51
|
-
|
|
51
|
+
fr as getSubmitterButtonData,
|
|
52
|
+
U as useForm,
|
|
52
53
|
v as useFormErrorConsoleDebug,
|
|
53
54
|
G as useFormErrorsEffect,
|
|
54
55
|
s as useFormErrorsFlatContext,
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
56
|
+
g as useFormErrorsIfAny,
|
|
57
|
+
I as useFormErrorsMemo,
|
|
58
|
+
Y as useFormGroupChildIsMountedTracker,
|
|
59
|
+
_ as useFormGroupChildIsSubmittingTracker,
|
|
60
|
+
rr as useFormGroupIsAnyBusy,
|
|
61
|
+
er as useFormGroupIsChildBusy,
|
|
62
|
+
sr as useFormGroupIsParentBusy,
|
|
63
|
+
ur as useFormGroupParentTracker,
|
|
63
64
|
E as useFormHasOrphanAndNoFieldErrors,
|
|
64
65
|
xr as useFormOnSubmitSuccessful,
|
|
65
66
|
ir as useFormOnSubmitSuccessfulAndReset,
|
|
66
67
|
B as useFormRequestSubmit,
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
68
|
+
K as useFormUtilsContext,
|
|
69
|
+
q as useFormWithProviders,
|
|
70
|
+
b as useOrphanFormErrorsMemo,
|
|
71
|
+
c as useOrphanFormErrorsToConsole,
|
|
72
|
+
br as useResetFormAfterSubmitSuccessful,
|
|
73
|
+
Er as useResetFormOnSubmitError,
|
|
72
74
|
P as useRootFormFieldErrorsMemo,
|
|
73
75
|
cr as useSubmitFormOnChange
|
|
74
76
|
};
|
package/dist/esm/form/Form.mjs
CHANGED
|
@@ -1,87 +1,63 @@
|
|
|
1
|
-
import { jsxs as
|
|
1
|
+
import { jsxs as C, jsx as t } from "react/jsx-runtime";
|
|
2
2
|
import "react";
|
|
3
|
-
import { useFormContext as
|
|
4
|
-
import
|
|
5
|
-
import
|
|
6
|
-
import V from "../
|
|
3
|
+
import { useFormContext as O } from "react-hook-form";
|
|
4
|
+
import v from "../devtool/LazyDevTool.mjs";
|
|
5
|
+
import T from "../errors/root/FormRootErrorsFromContext.mjs";
|
|
6
|
+
import V from "../submit/error/handleFormSubmitError.mjs";
|
|
7
|
+
import j from "../submit/useResetFormOnSubmitError.mjs";
|
|
7
8
|
import w from "../submit/useSubmitFormOnChange.mjs";
|
|
8
|
-
import
|
|
9
|
-
import
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
formRef: E,
|
|
15
|
-
Fields: c,
|
|
9
|
+
import E from "../utils/useImperativeForwardedRef.mjs";
|
|
10
|
+
import P from "./FormBase.mjs";
|
|
11
|
+
function G({
|
|
12
|
+
formId: u,
|
|
13
|
+
formRef: h,
|
|
14
|
+
Fields: f,
|
|
16
15
|
//
|
|
17
|
-
onSubmit:
|
|
18
|
-
onSubmitError:
|
|
19
|
-
onSubmitInvalid:
|
|
16
|
+
onSubmit: d,
|
|
17
|
+
onSubmitError: l,
|
|
18
|
+
onSubmitInvalid: F,
|
|
20
19
|
//
|
|
21
20
|
options: r,
|
|
22
21
|
//
|
|
23
|
-
children:
|
|
24
|
-
...
|
|
22
|
+
children: x,
|
|
23
|
+
...g
|
|
25
24
|
}) {
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
v,
|
|
31
|
-
// `as` required due to conditional generic
|
|
32
|
-
x
|
|
33
|
-
)(m)), v = async (m, o) => {
|
|
25
|
+
const m = O(), c = E(h);
|
|
26
|
+
w(c, !(r != null && r.submitOnChange)), j(!(r != null && r.resetValuesOnSubmitError));
|
|
27
|
+
const R = async (e) => {
|
|
28
|
+
r != null && r.stopSubmitPropagation && e.stopPropagation();
|
|
34
29
|
try {
|
|
35
|
-
await (
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
o
|
|
39
|
-
));
|
|
40
|
-
} catch (f) {
|
|
41
|
-
if (r != null && r.disableEmptyRootError || e.setError("root", {}), r != null && r.resetValuesOnSubmitError && e.reset(void 0), f instanceof B) {
|
|
42
|
-
Object.entries(f.errors).forEach(([C, O]) => {
|
|
43
|
-
e.setError(C, {
|
|
44
|
-
type: "FormError",
|
|
45
|
-
message: O
|
|
46
|
-
});
|
|
47
|
-
});
|
|
48
|
-
return;
|
|
49
|
-
}
|
|
50
|
-
t == null || t(
|
|
51
|
-
f,
|
|
52
|
-
m,
|
|
53
|
-
e,
|
|
54
|
-
o
|
|
55
|
-
);
|
|
30
|
+
await m.handleSubmit(b, F)(e);
|
|
31
|
+
} catch (a) {
|
|
32
|
+
y(a, e);
|
|
56
33
|
}
|
|
34
|
+
}, b = (e, a) => d == null ? void 0 : d(
|
|
35
|
+
e,
|
|
36
|
+
m,
|
|
37
|
+
a
|
|
38
|
+
), y = (e, a) => {
|
|
39
|
+
V(e, m), l == null || l(e, m, a);
|
|
57
40
|
};
|
|
58
|
-
return /* @__PURE__ */
|
|
59
|
-
|
|
41
|
+
return /* @__PURE__ */ C(
|
|
42
|
+
P,
|
|
60
43
|
{
|
|
61
|
-
id:
|
|
62
|
-
onSubmit:
|
|
44
|
+
id: u,
|
|
45
|
+
onSubmit: R,
|
|
63
46
|
noValidate: !0,
|
|
64
|
-
...s,
|
|
65
|
-
ref: d,
|
|
66
47
|
style: {
|
|
67
48
|
position: "relative"
|
|
68
49
|
},
|
|
50
|
+
...g,
|
|
51
|
+
ref: c,
|
|
69
52
|
children: [
|
|
70
|
-
(r == null ? void 0 : r.devTool) !== "disabled" && /* @__PURE__ */
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
placement: "top-right",
|
|
75
|
-
...r == null ? void 0 : r.devTool
|
|
76
|
-
}
|
|
77
|
-
),
|
|
78
|
-
c && /* @__PURE__ */ l(c, { ctx: e }),
|
|
79
|
-
g,
|
|
80
|
-
u && /* @__PURE__ */ l(V, { errors: u })
|
|
53
|
+
(r == null ? void 0 : r.devTool) !== "disabled" && /* @__PURE__ */ t(v, { placement: "top-right", ...r == null ? void 0 : r.devTool }),
|
|
54
|
+
f && /* @__PURE__ */ t(f, { ctx: m }),
|
|
55
|
+
x,
|
|
56
|
+
!(r != null && r.hideRootErrors) && /* @__PURE__ */ t(T, {})
|
|
81
57
|
]
|
|
82
58
|
}
|
|
83
59
|
);
|
|
84
60
|
}
|
|
85
61
|
export {
|
|
86
|
-
|
|
62
|
+
G as default
|
|
87
63
|
};
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { jsx as o } from "react/jsx-runtime";
|
|
2
|
+
import i from "../errors/context/provider.mjs";
|
|
3
|
+
import m from "./useFormWithProviders.mjs";
|
|
4
|
+
function s({ children: e, ...t }) {
|
|
5
|
+
const r = m(t);
|
|
6
|
+
return /* @__PURE__ */ o(r.Provider, { children: /* @__PURE__ */ o(i, { formRef: r.ref, children: /* @__PURE__ */ o(r.Form, { children: e }) }) });
|
|
7
|
+
}
|
|
8
|
+
export {
|
|
9
|
+
s as default
|
|
10
|
+
};
|
|
@@ -1,27 +1,25 @@
|
|
|
1
1
|
import { jsx as r } from "react/jsx-runtime";
|
|
2
|
-
import { FormProvider as
|
|
3
|
-
import
|
|
4
|
-
function
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
children: f
|
|
2
|
+
import { FormProvider as f } from "react-hook-form";
|
|
3
|
+
import n from "./utils/FormUtilsContextProvider.mjs";
|
|
4
|
+
function v({
|
|
5
|
+
formId: o,
|
|
6
|
+
formRef: m,
|
|
7
|
+
rhf: i,
|
|
8
|
+
form: t,
|
|
9
|
+
utils: e,
|
|
10
|
+
children: d
|
|
12
11
|
}) {
|
|
13
|
-
return /* @__PURE__ */ r(
|
|
14
|
-
|
|
12
|
+
return /* @__PURE__ */ r(f, { ...i, children: /* @__PURE__ */ r(
|
|
13
|
+
n,
|
|
15
14
|
{
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
children: f
|
|
15
|
+
formId: o,
|
|
16
|
+
formRef: m,
|
|
17
|
+
formProps: t,
|
|
18
|
+
...e,
|
|
19
|
+
children: d
|
|
22
20
|
}
|
|
23
21
|
) });
|
|
24
22
|
}
|
|
25
23
|
export {
|
|
26
|
-
|
|
24
|
+
v as default
|
|
27
25
|
};
|
|
@@ -1,20 +1,20 @@
|
|
|
1
|
-
import { jsx as
|
|
1
|
+
import { jsx as e } from "react/jsx-runtime";
|
|
2
|
+
import { isDevelopment as i } from "../../../env-conditions/production.mjs";
|
|
2
3
|
import p from "../../../errors/orphan/useOrphanFormErrorsToConsole.mjs";
|
|
3
|
-
import
|
|
4
|
-
import
|
|
5
|
-
import
|
|
6
|
-
import
|
|
4
|
+
import s from "../../../errors/useFormErrorConsoleDebug.mjs";
|
|
5
|
+
import F from "../../../errors/useFormRequestSubmit.mjs";
|
|
6
|
+
import u from "../../../submit/useFormOnSubmitSuccessfulAndReset.mjs";
|
|
7
|
+
import a from "../../../submit/useResetFormOnSubmitSuccessful.mjs";
|
|
7
8
|
import { _FormUtilsContextProvider as l } from "./useFormUtilsContext.mjs";
|
|
8
9
|
function O({
|
|
9
|
-
isDev: m,
|
|
10
10
|
formRef: o,
|
|
11
11
|
onSubmitSuccessfulAndReset: r,
|
|
12
|
-
children:
|
|
12
|
+
children: m
|
|
13
13
|
}) {
|
|
14
|
-
const
|
|
15
|
-
return
|
|
14
|
+
const t = F(o);
|
|
15
|
+
return s(i), p(o, !0), a({ enabled: !!r }), u(() => {
|
|
16
16
|
r == null || r();
|
|
17
|
-
}), /* @__PURE__ */
|
|
17
|
+
}), /* @__PURE__ */ e(l, { value: { formRef: o, requestSubmit: t }, children: m });
|
|
18
18
|
}
|
|
19
19
|
export {
|
|
20
20
|
O as default
|
|
@@ -1,31 +1,29 @@
|
|
|
1
|
-
import { jsx as
|
|
2
|
-
import
|
|
3
|
-
import { useForm as
|
|
4
|
-
import
|
|
5
|
-
import
|
|
6
|
-
const
|
|
7
|
-
|
|
8
|
-
rhf: m,
|
|
1
|
+
import { jsx as n } from "react/jsx-runtime";
|
|
2
|
+
import i from "react";
|
|
3
|
+
import { useForm as u } from "react-hook-form";
|
|
4
|
+
import F from "../utils/useImperativeForwardedRef.mjs";
|
|
5
|
+
import c from "./Form.mjs";
|
|
6
|
+
const f = ({
|
|
7
|
+
rhf: e,
|
|
9
8
|
form: o
|
|
10
9
|
}) => {
|
|
11
|
-
const r =
|
|
10
|
+
const r = i.useId(), m = u(e), t = F();
|
|
12
11
|
return {
|
|
13
12
|
id: r,
|
|
14
13
|
ref: t,
|
|
15
|
-
context:
|
|
16
|
-
Form: ({ children:
|
|
17
|
-
|
|
14
|
+
context: m,
|
|
15
|
+
Form: ({ children: s }) => /* @__PURE__ */ n(
|
|
16
|
+
c,
|
|
18
17
|
{
|
|
19
|
-
...o,
|
|
20
|
-
isDev: e,
|
|
21
18
|
formId: r,
|
|
22
19
|
formRef: t,
|
|
23
20
|
onSubmit: o == null ? void 0 : o.onSubmit,
|
|
24
|
-
|
|
21
|
+
...o,
|
|
22
|
+
children: s
|
|
25
23
|
}
|
|
26
24
|
)
|
|
27
25
|
};
|
|
28
|
-
},
|
|
26
|
+
}, b = f;
|
|
29
27
|
export {
|
|
30
|
-
|
|
28
|
+
b as default
|
|
31
29
|
};
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { jsx as i } from "react/jsx-runtime";
|
|
2
|
+
import "react";
|
|
3
|
+
import s from "./context/FormProvider.mjs";
|
|
4
|
+
import f from "./useForm.mjs";
|
|
5
|
+
const d = ({
|
|
6
|
+
rhf: t,
|
|
7
|
+
form: o,
|
|
8
|
+
utils: e
|
|
9
|
+
}) => {
|
|
10
|
+
const r = f({ rhf: t, form: o });
|
|
11
|
+
return {
|
|
12
|
+
...r,
|
|
13
|
+
Provider: ({ children: m }) => /* @__PURE__ */ i(
|
|
14
|
+
s,
|
|
15
|
+
{
|
|
16
|
+
formRef: r.ref,
|
|
17
|
+
rhf: r.context,
|
|
18
|
+
formId: r.id,
|
|
19
|
+
form: o,
|
|
20
|
+
utils: e,
|
|
21
|
+
children: m
|
|
22
|
+
}
|
|
23
|
+
)
|
|
24
|
+
};
|
|
25
|
+
}, P = d;
|
|
26
|
+
export {
|
|
27
|
+
P as default
|
|
28
|
+
};
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { FormSubmitError as m } from "./FormSubmitError.mjs";
|
|
2
|
+
const n = (r, o) => {
|
|
3
|
+
r instanceof m && Object.entries(r.errors).forEach(([t, e]) => {
|
|
4
|
+
o.setError(t, {
|
|
5
|
+
type: "FormSubmitError",
|
|
6
|
+
message: e
|
|
7
|
+
});
|
|
8
|
+
});
|
|
9
|
+
};
|
|
10
|
+
export {
|
|
11
|
+
n as default
|
|
12
|
+
};
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import i from "react";
|
|
2
|
+
import { useFormContext as m, useFormState as n } from "react-hook-form";
|
|
3
|
+
const f = (t) => {
|
|
4
|
+
const { reset: r } = m(), { isSubmitting: e, isSubmitSuccessful: u, isSubmitted: o, submitCount: s } = n();
|
|
5
|
+
i.useEffect(() => {
|
|
6
|
+
t || e || u || o && s !== 0 && r(void 0);
|
|
7
|
+
}, [
|
|
8
|
+
t,
|
|
9
|
+
e,
|
|
10
|
+
u,
|
|
11
|
+
o,
|
|
12
|
+
r,
|
|
13
|
+
s
|
|
14
|
+
]);
|
|
15
|
+
}, b = f;
|
|
16
|
+
export {
|
|
17
|
+
b as default
|
|
18
|
+
};
|
package/dist/index.html
ADDED
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
<!doctype html>
|
|
2
|
+
<html lang="en">
|
|
3
|
+
<head>
|
|
4
|
+
<meta charset="UTF-8" />
|
|
5
|
+
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
|
6
|
+
<title>Playground</title>
|
|
7
|
+
<script type="module" crossorigin src="/assets/index-BgBykTYQ.js"></script>
|
|
8
|
+
</head>
|
|
9
|
+
<body>
|
|
10
|
+
<div id="root"></div>
|
|
11
|
+
</body>
|
|
12
|
+
</html>
|
|
@@ -2,5 +2,5 @@
|
|
|
2
2
|
* Returns errors only if there are errors.
|
|
3
3
|
* Allows simple typeguard without `isEmpty` dependency.
|
|
4
4
|
*/
|
|
5
|
-
declare const useFormErrorsIfAny: () => false | import('react-hook-form').FieldErrors<import(
|
|
5
|
+
declare const useFormErrorsIfAny: () => false | import('react-hook-form').FieldErrors<import('react-hook-form').FieldValues>;
|
|
6
6
|
export default useFormErrorsIfAny;
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
export { default as LazyDevTool } from './devtool/LazyDevTool';
|
|
2
|
+
export { default as useFormErrorsFlatContext } from './errors/context';
|
|
3
|
+
export { default as FormErrorsFlatContextProvider } from './errors/context/provider';
|
|
4
|
+
export { default as FormErrorMessage } from './errors/message/FormErrorMessage';
|
|
5
|
+
export { default as FormErrorMessageByPath } from './errors/message/FormErrorMessageByPath';
|
|
6
|
+
export { default as FormNonFieldErrorMarker } from './errors/nonfield/FormNonFieldErrorMarker';
|
|
7
|
+
export { default as FormNonFieldErrorMarkerHtmlAttribute } from './errors/nonfield/FormNonFieldErrorMarkerHtmlAttribute';
|
|
8
|
+
export { default as useFormHasOrphanAndNoFieldErrors } from './errors/orphan/useFormHasOrphanAndNoFieldErrors';
|
|
9
|
+
export { default as useOrphanFormErrorsMemo } from './errors/orphan/useOrphanFormErrorsMemo';
|
|
10
|
+
export { default as useOrphanFormErrorsToConsole } from './errors/orphan/useOrphanFormErrorsToConsole';
|
|
11
|
+
export { default as useRootFormFieldErrorsMemo } from './errors/root/useRootFormFieldErrorsMemo';
|
|
12
|
+
export { default as useFormErrorConsoleDebug } from './errors/useFormErrorConsoleDebug';
|
|
13
|
+
export { default as useFormErrorsEffect } from './errors/useFormErrorsEffect';
|
|
14
|
+
export { default as useFormErrorsIfAny } from './errors/useFormErrorsIfAny';
|
|
15
|
+
export { default as useFormErrorsMemo } from './errors/useFormErrorsMemo';
|
|
16
|
+
export { default as useFormRequestSubmit } from './errors/useFormRequestSubmit';
|
|
17
|
+
export { default as Form } from './form/Form';
|
|
18
|
+
export { default as FormWithProviders } from './form/FormWithProviders';
|
|
19
|
+
export { default as useForm } from './form/useForm';
|
|
20
|
+
export { default as useFormWithProviders } from './form/useFormWithProviders';
|
|
21
|
+
export { default as FormProvider } from './form/context/FormProvider';
|
|
22
|
+
export { default as FormUtilsContextProvider } from './form/context/utils/FormUtilsContextProvider';
|
|
23
|
+
export { default as useFormUtilsContext } from './form/context/utils/useFormUtilsContext';
|
|
24
|
+
export { default as FormGroupContextProvider } from './form/context/group/FormGroupContextProvider';
|
|
25
|
+
export { default as useFormGroupChildIsMountedTracker } from './form/context/group/useFormGroupChildIsMountedTracker';
|
|
26
|
+
export { default as useFormGroupChildIsSubmittingTracker } from './form/context/group/useFormGroupChildIsSubmittingTracker';
|
|
27
|
+
export { default as useFormGroupIsAnyBusy } from './form/context/group/useFormGroupIsAnyBusy';
|
|
28
|
+
export { default as useFormGroupIsChildBusy } from './form/context/group/useFormGroupIsChildBusy';
|
|
29
|
+
export { default as useFormGroupIsParentBusy } from './form/context/group/useFormGroupIsParentBusy';
|
|
30
|
+
export { default as useFormGroupParentTracker } from './form/context/group/useFormGroupParentTracker';
|
|
31
|
+
export { default as getSubmitterButtonData } from './form/utils/getSubmitterButtonData';
|
|
32
|
+
export { FormSubmitError } from './submit/error/FormSubmitError';
|
|
33
|
+
export { default as useFormOnSubmitSuccessful } from './submit/useFormOnSubmitSuccessful';
|
|
34
|
+
export { default as useFormOnSubmitSuccessfulAndReset } from './submit/useFormOnSubmitSuccessfulAndReset';
|
|
35
|
+
export { default as useResetFormOnSubmitError } from './submit/useResetFormOnSubmitError';
|
|
36
|
+
export { default as useResetFormAfterSubmitSuccessful } from './submit/useResetFormOnSubmitSuccessful';
|
|
37
|
+
export { default as useSubmitFormOnChange } from './submit/useSubmitFormOnChange';
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { default as React } from 'react';
|
|
2
|
+
|
|
3
|
+
type Props = React.PropsWithChildren;
|
|
4
|
+
type State = {
|
|
5
|
+
error: null | Error;
|
|
6
|
+
};
|
|
7
|
+
export declare class ErrorBoundary extends React.Component<Props, State> {
|
|
8
|
+
state: State;
|
|
9
|
+
static getDerivedStateFromError(error: Error): {
|
|
10
|
+
error: Error;
|
|
11
|
+
};
|
|
12
|
+
componentDidCatch(error: unknown, errorInfo: React.ErrorInfo): void;
|
|
13
|
+
render(): string | number | boolean | Iterable<React.ReactNode> | import("react/jsx-runtime").JSX.Element | null | undefined;
|
|
14
|
+
}
|
|
15
|
+
export {};
|
|
@@ -12,16 +12,16 @@ export type FormProps<TFieldValues extends FieldValues, TTransformedValues exten
|
|
|
12
12
|
}>;
|
|
13
13
|
onSubmit?: (values: TTransformedValues, context: UseFormReturn<TFieldValues, unknown, TTransformedValues>, event: React.BaseSyntheticEvent<SubmitEvent>) => unknown | Promise<unknown>;
|
|
14
14
|
/** Submit error handler. (Only for errors not of instance `FormError`, which are handled internally.) */
|
|
15
|
-
onSubmitError?: (error: unknown,
|
|
15
|
+
onSubmitError?: (error: unknown, context: UseFormReturn<TFieldValues, unknown, TTransformedValues>, event: React.BaseSyntheticEvent<SubmitEvent>) => void;
|
|
16
16
|
/** Submit handler when form is invalid. */
|
|
17
17
|
onSubmitInvalid?: SubmitErrorHandler<TFieldValues>;
|
|
18
18
|
options?: {
|
|
19
|
+
hideRootErrors?: boolean;
|
|
19
20
|
/** Request submit via listener on form change. */
|
|
20
21
|
submitOnChange?: boolean;
|
|
21
22
|
/** Reset form values if submit throw errors. Use case: optimistic UI toggle form that submits on each change */
|
|
22
23
|
resetValuesOnSubmitError?: boolean;
|
|
23
24
|
stopSubmitPropagation?: boolean;
|
|
24
|
-
disableEmptyRootError?: boolean;
|
|
25
25
|
devTool?: DevtoolUIProps | 'disabled';
|
|
26
26
|
};
|
|
27
27
|
className?: string;
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { UseFormProps } from './useForm';
|
|
2
|
+
import { FieldValues } from 'react-hook-form';
|
|
3
|
+
|
|
4
|
+
export type FormWithProviders<TFieldValues extends FieldValues, TTransformedValues extends FieldValues> = React.PropsWithChildren<UseFormProps<TFieldValues, TTransformedValues>>;
|
|
5
|
+
/**
|
|
6
|
+
* {@link FormProvider} (and utils) with immediate descendent {@link Form}.
|
|
7
|
+
* (Syntactic sugar for {@link useForm}. Use this for most applications.)
|
|
8
|
+
*
|
|
9
|
+
* Use {@link useForm} if you need to specific nesting hierarchy.
|
|
10
|
+
* (e.g., wrapping `<tr>` with provider and nesting `<form>` within `<td>` to appease HTML rules.)
|
|
11
|
+
*/
|
|
12
|
+
declare function FormWithProviders<TFieldValues extends FieldValues, TTransformedValues extends FieldValues>({ children, ...props }: FormWithProviders<TFieldValues, TTransformedValues>): import("react/jsx-runtime").JSX.Element;
|
|
13
|
+
export default FormWithProviders;
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { UseFormProps } from './useForm';
|
|
2
|
+
import { FormUtilsContextProviderProps } from './context/utils/FormUtilsContextProvider';
|
|
3
|
+
import { FieldValues } from 'react-hook-form';
|
|
4
|
+
import { default as React } from 'react';
|
|
5
|
+
|
|
6
|
+
export type UseFormWithProvidersProps<TFieldValues extends FieldValues, TTransformedValues extends FieldValues> = UseFormProps<TFieldValues, TTransformedValues> & {
|
|
7
|
+
/** {@link FormUtilsContextProviderProps} props for `FormUtilsContextProvider`. */
|
|
8
|
+
utils?: FormUtilsContextProviderProps;
|
|
9
|
+
};
|
|
10
|
+
export type UseFormWithProvidersReturn = ReturnType<typeof useFormWithProviders>;
|
|
11
|
+
/**
|
|
12
|
+
* Base Rhf Form hook. Use `Form` in `index.ts` for most cases.
|
|
13
|
+
* Use this if you need to separate form components.
|
|
14
|
+
* e.g., a form for table row due to `form` being considered invalid HTML around `tr` tags.
|
|
15
|
+
* With this hook, you can wrap the `tr` tag with `form.Provider` and use `form.Form` inside
|
|
16
|
+
* one of the cells. Other components can be outside form while referring to form by its id via `form` attribute.
|
|
17
|
+
* see https://caniuse.com/?search=form%20attribute
|
|
18
|
+
* @returns Form provider and form.
|
|
19
|
+
*/
|
|
20
|
+
declare const useFormWithProviders: <TFieldValues extends FieldValues, TTransformedValues extends FieldValues>({ isDev, rhf, form, utils, }: UseFormWithProvidersProps<TFieldValues, TTransformedValues>) => {
|
|
21
|
+
readonly Provider: React.FC<{
|
|
22
|
+
children?: React.ReactNode;
|
|
23
|
+
}>;
|
|
24
|
+
readonly id: string;
|
|
25
|
+
readonly ref: React.RefObject<HTMLFormElement>;
|
|
26
|
+
readonly context: import('react-hook-form').UseFormReturn<TFieldValues, unknown, TTransformedValues>;
|
|
27
|
+
readonly Form: React.FC<{
|
|
28
|
+
children?: React.ReactNode;
|
|
29
|
+
}>;
|
|
30
|
+
};
|
|
31
|
+
export default useFormWithProviders;
|