@paragrav/rhf-utils 0.0.38 → 0.0.48
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/esm/errors/context/provider.mjs +7 -7
- package/dist/esm/errors/flat/getFlatFieldErrors.mjs +11 -11
- package/dist/esm/errors/isFieldError.mjs +2 -2
- package/dist/esm/errors/orphan/getOrphansFromFieldErrors.mjs +9 -0
- package/dist/esm/errors/orphan/getOrphansFromFlatFieldErrors.mjs +16 -0
- package/dist/esm/errors/orphan/useOrphanFormErrorsMemo.mjs +4 -4
- package/dist/esm/errors/root/getRootsFromFieldErrors.mjs +9 -0
- package/dist/esm/errors/root/getRootsFromFlatFieldErrors.mjs +7 -0
- package/dist/esm/errors/root/useRootFormFieldErrorsMemo.mjs +1 -1
- package/dist/esm/form/Form.mjs +49 -44
- package/dist/esm/form/FormWithProvider.mjs +9 -0
- package/dist/esm/form/context/FormProvider.mjs +27 -0
- package/dist/esm/form/context/utils/FormUtilsContextProvider.mjs +21 -0
- package/dist/esm/form/context/utils/useFormUtilsContext.mjs +6 -0
- package/dist/esm/form/useFormWithProvider.mjs +30 -0
- package/dist/esm/main.mjs +58 -42
- package/dist/esm/submit/useSubmitFormOnChange.mjs +21 -0
- package/dist/esm/utils/useImperativeForwardedRef.mjs +3 -3
- package/dist/types/errors/orphan/getOrphansFromFieldErrors.d.ts +5 -0
- package/dist/types/errors/orphan/getOrphansFromFlatFieldErrors.d.ts +4 -0
- package/dist/types/errors/root/getRootsFromFieldErrors.d.ts +5 -0
- package/dist/types/errors/root/getRootsFromFlatFieldErrors.d.ts +4 -0
- package/dist/types/form/Form.d.ts +8 -1
- package/dist/types/form/useFormWithProvider.d.ts +2 -1
- package/dist/types/main.d.ts +9 -1
- package/dist/types/submit/useSubmitFormOnChange.d.ts +4 -0
- package/package.json +33 -1
- package/dist/esm/errors/nonfield/isNonFieldError.mjs +0 -5
- package/dist/esm/errors/orphan/getOrphanFlatFieldErrors.mjs +0 -20
- package/dist/esm/errors/root/getRootFlatFieldErrors.mjs +0 -11
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import { jsx as
|
|
2
|
-
import
|
|
3
|
-
import a from "../orphan/
|
|
4
|
-
import i from "../root/
|
|
1
|
+
import { jsx as n } from "react/jsx-runtime";
|
|
2
|
+
import l from "../flat/getFlatFieldErrors.mjs";
|
|
3
|
+
import a from "../orphan/getOrphansFromFlatFieldErrors.mjs";
|
|
4
|
+
import i from "../root/getRootsFromFlatFieldErrors.mjs";
|
|
5
5
|
import p from "../useFormErrorsMemo.mjs";
|
|
6
6
|
import { _FormErrorsFlatContextProvider as c } from "./index.mjs";
|
|
7
7
|
const d = ({
|
|
@@ -9,10 +9,10 @@ const d = ({
|
|
|
9
9
|
children: t
|
|
10
10
|
}) => {
|
|
11
11
|
const e = p((s) => {
|
|
12
|
-
const r =
|
|
13
|
-
return { all: r, roots: m, orphans:
|
|
12
|
+
const r = l(s), m = i(r), F = a(r, o.current);
|
|
13
|
+
return { all: r, roots: m, orphans: F };
|
|
14
14
|
});
|
|
15
|
-
return /* @__PURE__ */
|
|
15
|
+
return /* @__PURE__ */ n(c, { value: e, children: t });
|
|
16
16
|
}, C = d;
|
|
17
17
|
export {
|
|
18
18
|
C as default
|
|
@@ -1,22 +1,22 @@
|
|
|
1
|
-
import { get as
|
|
2
|
-
import
|
|
1
|
+
import { get as f } from "react-hook-form";
|
|
2
|
+
import n from "./flattenFieldErrors.mjs";
|
|
3
3
|
const p = (t) => {
|
|
4
|
-
const a =
|
|
4
|
+
const a = n(t), c = Object.keys(a);
|
|
5
5
|
return Object.fromEntries(
|
|
6
6
|
c.reduce(
|
|
7
|
-
(
|
|
8
|
-
const
|
|
9
|
-
if (
|
|
10
|
-
return
|
|
11
|
-
const
|
|
12
|
-
return
|
|
7
|
+
(e, o) => {
|
|
8
|
+
const r = o.replace(d, "");
|
|
9
|
+
if (r === o)
|
|
10
|
+
return e;
|
|
11
|
+
const s = f(t, r, void 0);
|
|
12
|
+
return s && e.push([r, s]), e;
|
|
13
13
|
},
|
|
14
14
|
[]
|
|
15
15
|
// entries
|
|
16
16
|
)
|
|
17
17
|
);
|
|
18
|
-
},
|
|
18
|
+
}, d = /\.(?:type|message)\b$/;
|
|
19
19
|
export {
|
|
20
20
|
p as default,
|
|
21
|
-
|
|
21
|
+
d as regexMaybeFieldErrorLeafNode
|
|
22
22
|
};
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import i from "../isFieldError.mjs";
|
|
2
|
+
import { hasNonFieldErrorMarkerInDOM as m } from "../nonfield/FormNonFieldErrorMarker.utils.mjs";
|
|
3
|
+
import s from "../root/isFormErrorPathRoot.mjs";
|
|
4
|
+
const n = (o, t) => Object.fromEntries(
|
|
5
|
+
Object.entries(o).filter(
|
|
6
|
+
([r, e]) => (
|
|
7
|
+
// not root path
|
|
8
|
+
!s(r) && // non-field
|
|
9
|
+
!i(e) && // does not have marker
|
|
10
|
+
!m(r, t)
|
|
11
|
+
)
|
|
12
|
+
)
|
|
13
|
+
);
|
|
14
|
+
export {
|
|
15
|
+
n as default
|
|
16
|
+
};
|
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
import "react";
|
|
2
2
|
import t from "../../isEmptyObject.mjs";
|
|
3
3
|
import e from "../useFormErrorsMemo.mjs";
|
|
4
|
-
import m from "./
|
|
5
|
-
const
|
|
4
|
+
import m from "./getOrphansFromFieldErrors.mjs";
|
|
5
|
+
const s = (r) => e((o) => {
|
|
6
6
|
if (t(o))
|
|
7
7
|
return {};
|
|
8
8
|
if (!r.current)
|
|
9
9
|
throw new Error();
|
|
10
10
|
return m(o, r.current);
|
|
11
|
-
}),
|
|
11
|
+
}), E = s;
|
|
12
12
|
export {
|
|
13
|
-
|
|
13
|
+
E as default
|
|
14
14
|
};
|
package/dist/esm/form/Form.mjs
CHANGED
|
@@ -1,82 +1,87 @@
|
|
|
1
|
-
import { jsxs as
|
|
1
|
+
import { jsxs as R, jsx as l } from "react/jsx-runtime";
|
|
2
2
|
import "react";
|
|
3
|
-
import { useFormContext as
|
|
4
|
-
import
|
|
5
|
-
import { useFormErrorsFlatContextMaybe as
|
|
6
|
-
import
|
|
7
|
-
import
|
|
8
|
-
import
|
|
9
|
-
import
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
3
|
+
import { useFormContext as i } from "react-hook-form";
|
|
4
|
+
import j from "../devtool/LazyDevTool.mjs";
|
|
5
|
+
import { useFormErrorsFlatContextMaybe as T } from "../errors/context/index.mjs";
|
|
6
|
+
import V from "../errors/root/FormRootErrors.mjs";
|
|
7
|
+
import w from "../submit/useSubmitFormOnChange.mjs";
|
|
8
|
+
import P from "../utils/useImperativeForwardedRef.mjs";
|
|
9
|
+
import z from "./FormBase.mjs";
|
|
10
|
+
import { FormError as B } from "./FormError.mjs";
|
|
11
|
+
function K({
|
|
12
|
+
isDev: F,
|
|
13
|
+
formId: y,
|
|
14
|
+
formRef: E,
|
|
15
|
+
Fields: c,
|
|
14
16
|
//
|
|
15
17
|
onSubmit: a,
|
|
16
|
-
onSubmitError:
|
|
17
|
-
onSubmitInvalid:
|
|
18
|
+
onSubmitError: t,
|
|
19
|
+
onSubmitInvalid: x,
|
|
18
20
|
//
|
|
19
21
|
options: r,
|
|
20
22
|
//
|
|
21
|
-
children:
|
|
22
|
-
...
|
|
23
|
+
children: g,
|
|
24
|
+
...s
|
|
23
25
|
}) {
|
|
24
|
-
var
|
|
25
|
-
const e =
|
|
26
|
-
|
|
26
|
+
var h;
|
|
27
|
+
const e = i(), d = P(E);
|
|
28
|
+
w(d, !!(r != null && r.submitOnChange));
|
|
29
|
+
const u = (h = T()) == null ? void 0 : h.roots, b = (m) => (r != null && r.stopSubmitPropagation && m.stopPropagation(), e.handleSubmit(
|
|
30
|
+
v,
|
|
27
31
|
// `as` required due to conditional generic
|
|
28
|
-
|
|
29
|
-
)(
|
|
32
|
+
x
|
|
33
|
+
)(m)), v = async (m, o) => {
|
|
30
34
|
try {
|
|
31
35
|
await (a == null ? void 0 : a(
|
|
32
|
-
|
|
36
|
+
m,
|
|
33
37
|
e,
|
|
34
|
-
|
|
38
|
+
o
|
|
35
39
|
));
|
|
36
|
-
} catch (
|
|
37
|
-
if (r != null && r.disableEmptyRootError || e.setError("root", {}),
|
|
38
|
-
Object.entries(
|
|
39
|
-
e.setError(
|
|
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, {
|
|
40
44
|
type: "FormError",
|
|
41
|
-
message:
|
|
45
|
+
message: O
|
|
42
46
|
});
|
|
43
47
|
});
|
|
44
48
|
return;
|
|
45
49
|
}
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
50
|
+
t == null || t(
|
|
51
|
+
f,
|
|
52
|
+
m,
|
|
49
53
|
e,
|
|
50
|
-
|
|
54
|
+
o
|
|
51
55
|
);
|
|
52
56
|
}
|
|
53
57
|
};
|
|
54
|
-
return /* @__PURE__ */
|
|
55
|
-
|
|
58
|
+
return /* @__PURE__ */ R(
|
|
59
|
+
z,
|
|
56
60
|
{
|
|
57
|
-
id:
|
|
58
|
-
onSubmit:
|
|
61
|
+
id: y,
|
|
62
|
+
onSubmit: b,
|
|
59
63
|
noValidate: !0,
|
|
60
|
-
...
|
|
61
|
-
ref:
|
|
64
|
+
...s,
|
|
65
|
+
ref: d,
|
|
62
66
|
style: {
|
|
63
67
|
position: "relative"
|
|
64
68
|
},
|
|
65
69
|
children: [
|
|
66
|
-
(r == null ? void 0 : r.devTool) !== "disabled" && /* @__PURE__ */
|
|
67
|
-
|
|
70
|
+
(r == null ? void 0 : r.devTool) !== "disabled" && /* @__PURE__ */ l(
|
|
71
|
+
j,
|
|
68
72
|
{
|
|
69
|
-
isDev:
|
|
73
|
+
isDev: F,
|
|
70
74
|
placement: "top-right",
|
|
71
75
|
...r == null ? void 0 : r.devTool
|
|
72
76
|
}
|
|
73
77
|
),
|
|
74
|
-
|
|
75
|
-
|
|
78
|
+
c && /* @__PURE__ */ l(c, { ctx: e }),
|
|
79
|
+
g,
|
|
80
|
+
u && /* @__PURE__ */ l(V, { errors: u })
|
|
76
81
|
]
|
|
77
82
|
}
|
|
78
83
|
);
|
|
79
84
|
}
|
|
80
85
|
export {
|
|
81
|
-
|
|
86
|
+
K as default
|
|
82
87
|
};
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { jsx as o } from "react/jsx-runtime";
|
|
2
|
+
import e from "./useFormWithProvider.mjs";
|
|
3
|
+
function f({ children: i, ...t }) {
|
|
4
|
+
const r = e(t);
|
|
5
|
+
return /* @__PURE__ */ o(r.Provider, { children: /* @__PURE__ */ o(r.Form, { children: i }) });
|
|
6
|
+
}
|
|
7
|
+
export {
|
|
8
|
+
f as default
|
|
9
|
+
};
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { jsx as r } from "react/jsx-runtime";
|
|
2
|
+
import { FormProvider as n } from "react-hook-form";
|
|
3
|
+
import p from "./utils/FormUtilsContextProvider.mjs";
|
|
4
|
+
function F({
|
|
5
|
+
isDev: o,
|
|
6
|
+
formId: m,
|
|
7
|
+
formRef: i,
|
|
8
|
+
rhf: t,
|
|
9
|
+
form: e,
|
|
10
|
+
utils: d,
|
|
11
|
+
children: f
|
|
12
|
+
}) {
|
|
13
|
+
return /* @__PURE__ */ r(n, { ...t, children: /* @__PURE__ */ r(
|
|
14
|
+
p,
|
|
15
|
+
{
|
|
16
|
+
isDev: o,
|
|
17
|
+
formId: m,
|
|
18
|
+
formRef: i,
|
|
19
|
+
formProps: e,
|
|
20
|
+
...d,
|
|
21
|
+
children: f
|
|
22
|
+
}
|
|
23
|
+
) });
|
|
24
|
+
}
|
|
25
|
+
export {
|
|
26
|
+
F as default
|
|
27
|
+
};
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { jsx as i } from "react/jsx-runtime";
|
|
2
|
+
import p from "../../../errors/orphan/useOrphanFormErrorsToConsole.mjs";
|
|
3
|
+
import F from "../../../errors/useFormErrorConsoleDebug.mjs";
|
|
4
|
+
import u from "../../../errors/useFormRequestSubmit.mjs";
|
|
5
|
+
import a from "../../../submit/useFormOnSubmitSuccessfulAndReset.mjs";
|
|
6
|
+
import s from "../../../submit/useResetFormOnSubmitSuccessful.mjs";
|
|
7
|
+
import { _FormUtilsContextProvider as l } from "./useFormUtilsContext.mjs";
|
|
8
|
+
function O({
|
|
9
|
+
isDev: m,
|
|
10
|
+
formRef: o,
|
|
11
|
+
onSubmitSuccessfulAndReset: r,
|
|
12
|
+
children: t
|
|
13
|
+
}) {
|
|
14
|
+
const e = u(o);
|
|
15
|
+
return F(m), p(o, m, !0), s({ enabled: !!r }), a(() => {
|
|
16
|
+
r == null || r();
|
|
17
|
+
}), /* @__PURE__ */ i(l, { value: { formRef: o, requestSubmit: e }, children: t });
|
|
18
|
+
}
|
|
19
|
+
export {
|
|
20
|
+
O as default
|
|
21
|
+
};
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { jsx as f } from "react/jsx-runtime";
|
|
2
|
+
import "react";
|
|
3
|
+
import d from "./context/FormProvider.mjs";
|
|
4
|
+
import s from "./useForm.mjs";
|
|
5
|
+
const n = ({
|
|
6
|
+
isDev: o,
|
|
7
|
+
rhf: e,
|
|
8
|
+
form: t,
|
|
9
|
+
utils: m
|
|
10
|
+
}) => {
|
|
11
|
+
const r = s({ isDev: o, rhf: e, form: t });
|
|
12
|
+
return {
|
|
13
|
+
...r,
|
|
14
|
+
Provider: ({ children: i }) => /* @__PURE__ */ f(
|
|
15
|
+
d,
|
|
16
|
+
{
|
|
17
|
+
isDev: o,
|
|
18
|
+
formRef: r.ref,
|
|
19
|
+
rhf: r.context,
|
|
20
|
+
formId: r.id,
|
|
21
|
+
form: t,
|
|
22
|
+
utils: m,
|
|
23
|
+
children: i
|
|
24
|
+
}
|
|
25
|
+
)
|
|
26
|
+
};
|
|
27
|
+
}, F = n;
|
|
28
|
+
export {
|
|
29
|
+
F as default
|
|
30
|
+
};
|
package/dist/esm/main.mjs
CHANGED
|
@@ -3,56 +3,72 @@ import { default as s } from "./errors/context/index.mjs";
|
|
|
3
3
|
import { default as u } from "./errors/context/provider.mjs";
|
|
4
4
|
import { default as f } from "./errors/message/FormErrorMessage.mjs";
|
|
5
5
|
import { default as d } from "./errors/message/FormErrorMessageByPath.mjs";
|
|
6
|
-
import { default as
|
|
7
|
-
import { default as
|
|
6
|
+
import { default as x } from "./errors/nonfield/FormNonFieldErrorMarker.mjs";
|
|
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
|
|
11
|
-
import { default as
|
|
12
|
-
import { default as
|
|
13
|
-
import { default as
|
|
14
|
-
import { default as
|
|
9
|
+
import { default as c } from "./errors/orphan/useOrphanFormErrorsMemo.mjs";
|
|
10
|
+
import { default as S } from "./errors/orphan/useOrphanFormErrorsToConsole.mjs";
|
|
11
|
+
import { default as P } from "./errors/root/useRootFormFieldErrorsMemo.mjs";
|
|
12
|
+
import { default as v } from "./errors/useFormErrorConsoleDebug.mjs";
|
|
13
|
+
import { default as G } from "./errors/useFormErrorsEffect.mjs";
|
|
14
|
+
import { default as A } from "./errors/useFormErrorsIfAny.mjs";
|
|
15
15
|
import { default as O } from "./errors/useFormErrorsMemo.mjs";
|
|
16
|
-
import { default as
|
|
17
|
-
import { default as
|
|
18
|
-
import {
|
|
19
|
-
import { default as
|
|
20
|
-
import { default as
|
|
21
|
-
import { default as
|
|
22
|
-
import { default as
|
|
23
|
-
import { default as
|
|
24
|
-
import { default as
|
|
25
|
-
import { default as Y } from "./form/
|
|
26
|
-
import { default as _ } from "./
|
|
27
|
-
import { default as rr } from "./
|
|
28
|
-
import { default as er } from "./
|
|
16
|
+
import { default as B } from "./errors/useFormRequestSubmit.mjs";
|
|
17
|
+
import { default as R } from "./form/Form.mjs";
|
|
18
|
+
import { FormError as N } from "./form/FormError.mjs";
|
|
19
|
+
import { default as U } from "./form/FormWithProvider.mjs";
|
|
20
|
+
import { default as q } from "./form/useForm.mjs";
|
|
21
|
+
import { default as L } from "./form/useFormWithProvider.mjs";
|
|
22
|
+
import { default as w } from "./form/context/FormProvider.mjs";
|
|
23
|
+
import { default as K } from "./form/context/utils/FormUtilsContextProvider.mjs";
|
|
24
|
+
import { default as V } from "./form/context/utils/useFormUtilsContext.mjs";
|
|
25
|
+
import { default as Y } from "./form/context/group/FormGroupContextProvider.mjs";
|
|
26
|
+
import { default as _ } from "./form/context/group/useFormGroupChildIsMountedTracker.mjs";
|
|
27
|
+
import { default as rr } from "./form/context/group/useFormGroupChildIsSubmittingTracker.mjs";
|
|
28
|
+
import { default as er } from "./form/context/group/useFormGroupIsAnyBusy.mjs";
|
|
29
|
+
import { default as sr } from "./form/context/group/useFormGroupIsChildBusy.mjs";
|
|
30
|
+
import { default as ur } from "./form/context/group/useFormGroupIsParentBusy.mjs";
|
|
31
|
+
import { default as fr } from "./form/context/group/useFormGroupParentTracker.mjs";
|
|
32
|
+
import { default as dr } from "./form/utils/getSubmitterButtonData.mjs";
|
|
33
|
+
import { default as xr } from "./submit/useFormOnSubmitSuccessful.mjs";
|
|
34
|
+
import { default as ir } from "./submit/useFormOnSubmitSuccessfulAndReset.mjs";
|
|
35
|
+
import { default as Er } from "./submit/useResetFormOnSubmitSuccessful.mjs";
|
|
36
|
+
import { default as cr } from "./submit/useSubmitFormOnChange.mjs";
|
|
29
37
|
export {
|
|
38
|
+
R as Form,
|
|
39
|
+
N as FormError,
|
|
30
40
|
f as FormErrorMessage,
|
|
31
41
|
d as FormErrorMessageByPath,
|
|
32
42
|
u as FormErrorsFlatContextProvider,
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
43
|
+
Y as FormGroupContextProvider,
|
|
44
|
+
x as FormNonFieldErrorMarker,
|
|
45
|
+
i as FormNonFieldErrorMarkerHtmlAttribute,
|
|
46
|
+
w as FormProvider,
|
|
47
|
+
K as FormUtilsContextProvider,
|
|
48
|
+
U as FormWithProvider,
|
|
36
49
|
e as LazyDevTool,
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
50
|
+
dr as getSubmitterButtonData,
|
|
51
|
+
q as useForm,
|
|
52
|
+
v as useFormErrorConsoleDebug,
|
|
53
|
+
G as useFormErrorsEffect,
|
|
41
54
|
s as useFormErrorsFlatContext,
|
|
42
|
-
|
|
55
|
+
A as useFormErrorsIfAny,
|
|
43
56
|
O as useFormErrorsMemo,
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
57
|
+
_ as useFormGroupChildIsMountedTracker,
|
|
58
|
+
rr as useFormGroupChildIsSubmittingTracker,
|
|
59
|
+
er as useFormGroupIsAnyBusy,
|
|
60
|
+
sr as useFormGroupIsChildBusy,
|
|
61
|
+
ur as useFormGroupIsParentBusy,
|
|
62
|
+
fr as useFormGroupParentTracker,
|
|
50
63
|
E as useFormHasOrphanAndNoFieldErrors,
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
64
|
+
xr as useFormOnSubmitSuccessful,
|
|
65
|
+
ir as useFormOnSubmitSuccessfulAndReset,
|
|
66
|
+
B as useFormRequestSubmit,
|
|
67
|
+
V as useFormUtilsContext,
|
|
68
|
+
L as useFormWithProvider,
|
|
69
|
+
c as useOrphanFormErrorsMemo,
|
|
70
|
+
S as useOrphanFormErrorsToConsole,
|
|
71
|
+
Er as useResetFormAfterSubmitSuccessful,
|
|
72
|
+
P as useRootFormFieldErrorsMemo,
|
|
73
|
+
cr as useSubmitFormOnChange
|
|
58
74
|
};
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import s from "react";
|
|
2
|
+
import u from "../errors/useFormRequestSubmit.mjs";
|
|
3
|
+
const m = (t, n) => {
|
|
4
|
+
const o = u(t);
|
|
5
|
+
s.useEffect(() => {
|
|
6
|
+
if (!n)
|
|
7
|
+
return;
|
|
8
|
+
const e = t.current;
|
|
9
|
+
if (!e)
|
|
10
|
+
throw new Error();
|
|
11
|
+
const r = () => {
|
|
12
|
+
o();
|
|
13
|
+
};
|
|
14
|
+
return e.addEventListener("change", r), () => {
|
|
15
|
+
e.removeEventListener("change", r);
|
|
16
|
+
};
|
|
17
|
+
}, []);
|
|
18
|
+
}, a = m;
|
|
19
|
+
export {
|
|
20
|
+
a as default
|
|
21
|
+
};
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import r from "react";
|
|
2
|
-
const
|
|
2
|
+
const a = (t) => {
|
|
3
3
|
const e = r.useRef(null);
|
|
4
4
|
return r.useImperativeHandle(
|
|
5
5
|
t,
|
|
@@ -10,7 +10,7 @@ const u = (t) => {
|
|
|
10
10
|
},
|
|
11
11
|
[]
|
|
12
12
|
), e;
|
|
13
|
-
};
|
|
13
|
+
}, o = a;
|
|
14
14
|
export {
|
|
15
|
-
|
|
15
|
+
o as default
|
|
16
16
|
};
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import { FlatFieldErrors } from '../flat/types';
|
|
2
|
+
import { FieldErrors } from 'react-hook-form';
|
|
3
|
+
|
|
4
|
+
declare const getOrphansFromFieldErrors: (errors: FieldErrors, parentElement: Pick<HTMLElement, 'querySelector'>) => FlatFieldErrors;
|
|
5
|
+
export default getOrphansFromFieldErrors;
|
|
@@ -7,17 +7,24 @@ export type FormProps<TFieldValues extends FieldValues, TTransformedValues exten
|
|
|
7
7
|
isDev: boolean;
|
|
8
8
|
formId?: string;
|
|
9
9
|
formRef?: React.RefObject<HTMLFormElement>;
|
|
10
|
+
Fields?: React.FC<{
|
|
11
|
+
ctx: UseFormReturn<TFieldValues, unknown, TTransformedValues>;
|
|
12
|
+
}>;
|
|
10
13
|
onSubmit?: (values: TTransformedValues, context: UseFormReturn<TFieldValues, unknown, TTransformedValues>, event: React.BaseSyntheticEvent<SubmitEvent>) => unknown | Promise<unknown>;
|
|
11
14
|
/** Submit error handler. (Only for errors not of instance `FormError`, which are handled internally.) */
|
|
12
15
|
onSubmitError?: (error: unknown, values: TTransformedValues, context: UseFormReturn<TFieldValues, unknown, TTransformedValues>, event: React.BaseSyntheticEvent<SubmitEvent>) => void;
|
|
13
16
|
/** Submit handler when form is invalid. */
|
|
14
17
|
onSubmitInvalid?: SubmitErrorHandler<TFieldValues>;
|
|
15
18
|
options?: {
|
|
19
|
+
/** Request submit via listener on form change. */
|
|
20
|
+
submitOnChange?: boolean;
|
|
21
|
+
/** Reset form values if submit throw errors. Use case: optimistic UI toggle form that submits on each change */
|
|
22
|
+
resetValuesOnSubmitError?: boolean;
|
|
16
23
|
stopSubmitPropagation?: boolean;
|
|
17
24
|
disableEmptyRootError?: boolean;
|
|
18
25
|
devTool?: DevtoolUIProps | 'disabled';
|
|
19
26
|
};
|
|
20
27
|
className?: string;
|
|
21
28
|
}>;
|
|
22
|
-
declare function Form<TFieldValues extends FieldValues, TTransformedValues extends FieldValues>({ isDev, formId, formRef, onSubmit, onSubmitError, onSubmitInvalid, options, children, ...props }: FormProps<TFieldValues, TTransformedValues>): import("react/jsx-runtime").JSX.Element;
|
|
29
|
+
declare function Form<TFieldValues extends FieldValues, TTransformedValues extends FieldValues>({ isDev, formId, formRef, Fields, onSubmit, onSubmitError, onSubmitInvalid, options, children, ...props }: FormProps<TFieldValues, TTransformedValues>): import("react/jsx-runtime").JSX.Element;
|
|
23
30
|
export default Form;
|
|
@@ -17,7 +17,7 @@ export type UseFormWithProviderReturn = ReturnType<typeof useFormWithProvider>;
|
|
|
17
17
|
* see https://caniuse.com/?search=form%20attribute
|
|
18
18
|
* @returns Form provider and form.
|
|
19
19
|
*/
|
|
20
|
-
|
|
20
|
+
declare const useFormWithProvider: <TFieldValues extends FieldValues, TTransformedValues extends FieldValues>({ isDev, rhf, form, utils, }: UseFormWithProviderProps<TFieldValues, TTransformedValues>) => {
|
|
21
21
|
readonly Provider: React.FC<{
|
|
22
22
|
children?: React.ReactNode;
|
|
23
23
|
}>;
|
|
@@ -28,3 +28,4 @@ export declare const useFormWithProvider: <TFieldValues extends FieldValues, TTr
|
|
|
28
28
|
children?: React.ReactNode;
|
|
29
29
|
}>;
|
|
30
30
|
};
|
|
31
|
+
export default useFormWithProvider;
|
package/dist/types/main.d.ts
CHANGED
|
@@ -14,6 +14,14 @@ export { default as useFormErrorsEffect } from './errors/useFormErrorsEffect';
|
|
|
14
14
|
export { default as useFormErrorsIfAny } from './errors/useFormErrorsIfAny';
|
|
15
15
|
export { default as useFormErrorsMemo } from './errors/useFormErrorsMemo';
|
|
16
16
|
export { default as useFormRequestSubmit } from './errors/useFormRequestSubmit';
|
|
17
|
+
export { default as Form } from './form/Form';
|
|
18
|
+
export { FormError } from './form/FormError';
|
|
19
|
+
export { default as FormWithProvider } from './form/FormWithProvider';
|
|
20
|
+
export { default as useForm } from './form/useForm';
|
|
21
|
+
export { default as useFormWithProvider } from './form/useFormWithProvider';
|
|
22
|
+
export { default as FormProvider } from './form/context/FormProvider';
|
|
23
|
+
export { default as FormUtilsContextProvider } from './form/context/utils/FormUtilsContextProvider';
|
|
24
|
+
export { default as useFormUtilsContext } from './form/context/utils/useFormUtilsContext';
|
|
17
25
|
export { default as FormGroupContextProvider } from './form/context/group/FormGroupContextProvider';
|
|
18
26
|
export { default as useFormGroupChildIsMountedTracker } from './form/context/group/useFormGroupChildIsMountedTracker';
|
|
19
27
|
export { default as useFormGroupChildIsSubmittingTracker } from './form/context/group/useFormGroupChildIsSubmittingTracker';
|
|
@@ -21,8 +29,8 @@ export { default as useFormGroupIsAnyBusy } from './form/context/group/useFormGr
|
|
|
21
29
|
export { default as useFormGroupIsChildBusy } from './form/context/group/useFormGroupIsChildBusy';
|
|
22
30
|
export { default as useFormGroupIsParentBusy } from './form/context/group/useFormGroupIsParentBusy';
|
|
23
31
|
export { default as useFormGroupParentTracker } from './form/context/group/useFormGroupParentTracker';
|
|
24
|
-
export { default as useForm } from './form/useForm';
|
|
25
32
|
export { default as getSubmitterButtonData } from './form/utils/getSubmitterButtonData';
|
|
26
33
|
export { default as useFormOnSubmitSuccessful } from './submit/useFormOnSubmitSuccessful';
|
|
27
34
|
export { default as useFormOnSubmitSuccessfulAndReset } from './submit/useFormOnSubmitSuccessfulAndReset';
|
|
28
35
|
export { default as useResetFormAfterSubmitSuccessful } from './submit/useResetFormOnSubmitSuccessful';
|
|
36
|
+
export { default as useSubmitFormOnChange } from './submit/useSubmitFormOnChange';
|
package/package.json
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
"name": "@paragrav/rhf-utils",
|
|
3
3
|
"author": "paragrav.dev",
|
|
4
4
|
"license": "MIT",
|
|
5
|
-
"version": "0.0.
|
|
5
|
+
"version": "0.0.48",
|
|
6
6
|
"description": "Integration utilities for react-hook-form.",
|
|
7
7
|
"type": "module",
|
|
8
8
|
"sideEffects": false,
|
|
@@ -71,10 +71,38 @@
|
|
|
71
71
|
"default": "./dist/esm/errors/root/useRootFormFieldErrors.mjs",
|
|
72
72
|
"types": "./dist/types/errors/root/useRootFormFieldErrors.d.ts"
|
|
73
73
|
},
|
|
74
|
+
"./form/Form": {
|
|
75
|
+
"default": "./dist/esm/form/Form.mjs",
|
|
76
|
+
"types": "./dist/types/form/Form.d.ts"
|
|
77
|
+
},
|
|
78
|
+
"./form/FormError": {
|
|
79
|
+
"default": "./dist/esm/form/FormError.mjs",
|
|
80
|
+
"types": "./dist/types/form/FormError.d.ts"
|
|
81
|
+
},
|
|
82
|
+
"./form/context/FormWithProvider": {
|
|
83
|
+
"default": "./dist/esm/form/context/FormWithProvider.mjs",
|
|
84
|
+
"types": "./dist/types/form/context/FormWithProvider.d.ts"
|
|
85
|
+
},
|
|
74
86
|
"./form/useForm": {
|
|
75
87
|
"default": "./dist/esm/form/useForm.mjs",
|
|
76
88
|
"types": "./dist/types/form/useForm.d.ts"
|
|
77
89
|
},
|
|
90
|
+
"./form/useFormWithProvider": {
|
|
91
|
+
"default": "./dist/esm/form/useFormWithProvider.mjs",
|
|
92
|
+
"types": "./dist/types/form/useFormWithProvider.d.ts"
|
|
93
|
+
},
|
|
94
|
+
"./form/context/FormProvider": {
|
|
95
|
+
"default": "./dist/esm/form/context/FormProvider.mjs",
|
|
96
|
+
"types": "./dist/types/form/context/FormProvider.d.ts"
|
|
97
|
+
},
|
|
98
|
+
"./form/context/FormUtilsContextProvider": {
|
|
99
|
+
"default": "./dist/esm/form/context/FormUtilsContextProvider.mjs",
|
|
100
|
+
"types": "./dist/types/form/context/FormUtilsContextProvider.d.ts"
|
|
101
|
+
},
|
|
102
|
+
"./form/context/useFormUtilsContext": {
|
|
103
|
+
"default": "./dist/esm/form/context/useFormUtilsContext.mjs",
|
|
104
|
+
"types": "./dist/types/form/context/useFormUtilsContext.d.ts"
|
|
105
|
+
},
|
|
78
106
|
"./form/context/group/FormGroupContextProvider": {
|
|
79
107
|
"default": "./dist/esm/form/context/group/FormGroupContextProvider.mjs",
|
|
80
108
|
"types": "./dist/types/form/context/group/FormGroupContextProvider.d.ts"
|
|
@@ -118,6 +146,10 @@
|
|
|
118
146
|
"./submit/useResetFormAfterSubmitSuccessful": {
|
|
119
147
|
"default": "./dist/esm/submit/useResetFormAfterSubmitSuccessful.mjs",
|
|
120
148
|
"types": "./dist/types/submit/useResetFormAfterSubmitSuccessful.d.ts"
|
|
149
|
+
},
|
|
150
|
+
"./submit/useSubmitFormOnChange": {
|
|
151
|
+
"default": "./dist/esm/submit/useSubmitFormOnChange.mjs",
|
|
152
|
+
"types": "./dist/types/submit/useSubmitFormOnChange.d.ts"
|
|
121
153
|
}
|
|
122
154
|
},
|
|
123
155
|
"scripts": {
|
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
import s from "../flat/getFlatFieldErrors.mjs";
|
|
2
|
-
import { hasNonFieldErrorMarkerInDOM as l } from "../nonfield/FormNonFieldErrorMarker.utils.mjs";
|
|
3
|
-
import m from "../nonfield/isNonFieldError.mjs";
|
|
4
|
-
import n from "../root/isFormErrorPathRoot.mjs";
|
|
5
|
-
const d = (o, t) => {
|
|
6
|
-
const e = s(o);
|
|
7
|
-
return Object.fromEntries(
|
|
8
|
-
Object.entries(e).filter(
|
|
9
|
-
([r, i]) => (
|
|
10
|
-
// not root path
|
|
11
|
-
!n(r) && // non-field
|
|
12
|
-
m(i) && // does not have marker
|
|
13
|
-
!l(r, t)
|
|
14
|
-
)
|
|
15
|
-
)
|
|
16
|
-
);
|
|
17
|
-
};
|
|
18
|
-
export {
|
|
19
|
-
d as default
|
|
20
|
-
};
|