@paragrav/rhf-utils 0.0.59 → 0.0.61
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/client/index.mjs +53 -0
- package/dist/esm/client/zod/context/index.mjs +6 -0
- package/dist/esm/client/zod/context/provider.mjs +11 -0
- package/dist/esm/client/zod/index.mjs +6 -0
- package/dist/esm/exports.mjs +76 -72
- package/dist/esm/form/FormWithProviders.mjs +14 -0
- package/dist/esm/form/_Form.mjs +89 -0
- package/dist/esm/form/_FormBase.mjs +14 -0
- package/dist/esm/form/_FormProviders.mjs +16 -0
- package/dist/esm/form/useForm.mjs +12 -16
- package/dist/esm/submit/error/setCtxErrorsByFormSubmitError.mjs +12 -0
- package/dist/types/src/client/config.d.ts +19 -0
- package/dist/types/src/client/context.d.ts +3 -0
- package/dist/types/src/client/index.d.ts +26 -0
- package/dist/types/src/client/zod/context/index.d.ts +8 -0
- package/dist/types/src/client/zod/context/provider.d.ts +12 -0
- package/dist/types/src/client/zod/index.d.ts +8 -0
- package/dist/types/src/exports.d.ts +6 -2
- package/dist/types/src/form/FormWithProviders.d.ts +2 -2
- package/dist/types/src/form/_Form.d.ts +2 -3
- package/dist/types/src/form/_FormProviders.d.ts +2 -3
- package/dist/types/src/form/useForm.d.ts +12 -28
- package/dist/types/src/form/useFormOptions.d.ts +28 -0
- package/package.json +12 -4
- package/dist/esm/config/index.mjs +0 -21
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
import { jsx as d } from "react/jsx-runtime";
|
|
2
|
+
import u from "../form/FormWithProviders.mjs";
|
|
3
|
+
import F from "../form/useForm.mjs";
|
|
4
|
+
const p = (t) => (r) => {
|
|
5
|
+
const e = l(
|
|
6
|
+
t,
|
|
7
|
+
r
|
|
8
|
+
);
|
|
9
|
+
return {
|
|
10
|
+
config: r,
|
|
11
|
+
useForm: (o, s) => F(
|
|
12
|
+
e(o, s)
|
|
13
|
+
),
|
|
14
|
+
FormWithProviders: P(t, r)
|
|
15
|
+
};
|
|
16
|
+
}, P = (t, r) => function({
|
|
17
|
+
schema: o,
|
|
18
|
+
children: s,
|
|
19
|
+
...m
|
|
20
|
+
}) {
|
|
21
|
+
const i = l(t, r);
|
|
22
|
+
return /* @__PURE__ */ d(
|
|
23
|
+
u,
|
|
24
|
+
{
|
|
25
|
+
...i(o, m),
|
|
26
|
+
children: s
|
|
27
|
+
}
|
|
28
|
+
);
|
|
29
|
+
}, l = (t, r) => (e, o) => {
|
|
30
|
+
var s, m, i, n, f, a, h;
|
|
31
|
+
return {
|
|
32
|
+
...o,
|
|
33
|
+
rhf: {
|
|
34
|
+
...(s = r.defaultOptions) == null ? void 0 : s.rhf,
|
|
35
|
+
...o.rhf,
|
|
36
|
+
resolver: t(e)
|
|
37
|
+
},
|
|
38
|
+
form: {
|
|
39
|
+
...o.form,
|
|
40
|
+
options: {
|
|
41
|
+
...(m = r.defaultOptions) == null ? void 0 : m.form,
|
|
42
|
+
...(i = o.form) == null ? void 0 : i.options,
|
|
43
|
+
classNames: [
|
|
44
|
+
...((f = (n = r.defaultOptions) == null ? void 0 : n.form) == null ? void 0 : f.classNames) ?? [],
|
|
45
|
+
...((h = (a = o.form) == null ? void 0 : a.options) == null ? void 0 : h.classNames) ?? []
|
|
46
|
+
]
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
};
|
|
50
|
+
};
|
|
51
|
+
export {
|
|
52
|
+
p as createRhfUtilsClient
|
|
53
|
+
};
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { jsx as e } from "react/jsx-runtime";
|
|
2
|
+
import i from "react";
|
|
3
|
+
import { createZodRhfUtilsClient as s } from "../index.mjs";
|
|
4
|
+
import { _RhfUtilsContextProvider as f } from "./index.mjs";
|
|
5
|
+
const n = ({ config: t, children: o }) => {
|
|
6
|
+
const [r] = i.useState(() => s(t));
|
|
7
|
+
return /* @__PURE__ */ e(f, { value: r, children: o });
|
|
8
|
+
}, c = n;
|
|
9
|
+
export {
|
|
10
|
+
c as default
|
|
11
|
+
};
|
package/dist/esm/exports.mjs
CHANGED
|
@@ -1,74 +1,78 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { default as s } from "./
|
|
3
|
-
import { default as
|
|
4
|
-
import { default as
|
|
5
|
-
import { default as d } from "./errors/
|
|
6
|
-
import { default as x } from "./errors/
|
|
7
|
-
import { default as n } from "./errors/
|
|
8
|
-
import { default as E } from "./errors/
|
|
9
|
-
import { default as
|
|
10
|
-
import { default as
|
|
11
|
-
import { default as y } from "./errors/orphan/
|
|
12
|
-
import { default as M } from "./errors/
|
|
13
|
-
import { default as
|
|
14
|
-
import { default as
|
|
15
|
-
import { default as
|
|
16
|
-
import { default as
|
|
17
|
-
import { default as v } from "./errors/
|
|
18
|
-
import { default as
|
|
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
|
|
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
|
|
31
|
-
import {
|
|
32
|
-
import { default as dr } from "./
|
|
33
|
-
import {
|
|
34
|
-
import { default as nr } from "./submit/
|
|
35
|
-
import { default as Er } from "./submit/
|
|
36
|
-
import { default as
|
|
1
|
+
import { createZodRhfUtilsClient as e } from "./client/zod/index.mjs";
|
|
2
|
+
import { default as s } from "./client/zod/context/index.mjs";
|
|
3
|
+
import { default as u } from "./client/zod/context/provider.mjs";
|
|
4
|
+
import { default as m } from "./devtool/LazyDevTool.mjs";
|
|
5
|
+
import { default as d } from "./errors/context/index.mjs";
|
|
6
|
+
import { default as x } from "./errors/context/provider.mjs";
|
|
7
|
+
import { default as n } from "./errors/message/FormErrorMessage.mjs";
|
|
8
|
+
import { default as E } from "./errors/message/FormErrorMessageByPath.mjs";
|
|
9
|
+
import { default as c } from "./errors/nonfield/FormNonFieldErrorMarker.mjs";
|
|
10
|
+
import { default as S } from "./errors/nonfield/FormNonFieldErrorMarkerHtmlAttribute.mjs";
|
|
11
|
+
import { default as y } from "./errors/orphan/useFormHasOrphanAndNoFieldErrors.mjs";
|
|
12
|
+
import { default as M } from "./errors/orphan/useOrphanFormErrorsMemo.mjs";
|
|
13
|
+
import { default as P } from "./errors/orphan/useOrphanFormErrorsToConsole.mjs";
|
|
14
|
+
import { default as I } from "./errors/root/useRootFormFieldErrorsMemo.mjs";
|
|
15
|
+
import { default as k } from "./errors/useFormErrorConsoleDebug.mjs";
|
|
16
|
+
import { default as B } from "./errors/useFormErrorsEffect.mjs";
|
|
17
|
+
import { default as v } from "./errors/useFormErrorsIfAny.mjs";
|
|
18
|
+
import { default as D } from "./errors/useFormErrorsMemo.mjs";
|
|
19
|
+
import { default as Z } from "./errors/useFormRequestSubmit.mjs";
|
|
20
|
+
import { default as q } from "./form/useForm.mjs";
|
|
21
|
+
import { default as L } from "./form/context/utils/FormUtilsContextProvider.mjs";
|
|
22
|
+
import { default as w } from "./form/context/utils/useFormUtilsContext.mjs";
|
|
23
|
+
import { default as K } from "./form/context/group/FormGroupContextProvider.mjs";
|
|
24
|
+
import { default as V } from "./form/context/group/useFormGroupChildIsMountedTracker.mjs";
|
|
25
|
+
import { default as X } from "./form/context/group/useFormGroupChildIsSubmittingTracker.mjs";
|
|
26
|
+
import { default as _ } from "./form/context/group/useFormGroupChildTracker.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 mr } from "./form/context/group/useFormOrParentIsBusy.mjs";
|
|
32
|
+
import { default as dr } from "./form/utils/getSubmitterButtonData.mjs";
|
|
33
|
+
import { FormSubmitError as xr } from "./submit/error/FormSubmitError.mjs";
|
|
34
|
+
import { default as nr } from "./submit/useFormOnSubmitSuccessful.mjs";
|
|
35
|
+
import { default as Er } from "./submit/useFormOnSubmitSuccessfulAndReset.mjs";
|
|
36
|
+
import { default as cr } from "./submit/useResetFormOnSubmitError.mjs";
|
|
37
|
+
import { default as Sr } from "./submit/useResetFormOnSubmitSuccessful.mjs";
|
|
38
|
+
import { default as yr } from "./submit/useSubmitFormOnChange.mjs";
|
|
37
39
|
export {
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
e as
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
40
|
+
n as FormErrorMessage,
|
|
41
|
+
E as FormErrorMessageByPath,
|
|
42
|
+
x as FormErrorsFlatContextProvider,
|
|
43
|
+
K as FormGroupContextProvider,
|
|
44
|
+
c as FormNonFieldErrorMarker,
|
|
45
|
+
S as FormNonFieldErrorMarkerHtmlAttribute,
|
|
46
|
+
xr as FormSubmitError,
|
|
47
|
+
L as FormUtilsContextProvider,
|
|
48
|
+
m as LazyDevTool,
|
|
49
|
+
u as RhfUtilsZodContextProvider,
|
|
50
|
+
e as createZodRhfUtilsClient,
|
|
51
|
+
dr as getSubmitterButtonData,
|
|
52
|
+
q as useForm,
|
|
53
|
+
k as useFormErrorConsoleDebug,
|
|
54
|
+
B as useFormErrorsEffect,
|
|
55
|
+
d as useFormErrorsFlatContext,
|
|
56
|
+
v as useFormErrorsIfAny,
|
|
57
|
+
D as useFormErrorsMemo,
|
|
58
|
+
V as useFormGroupChildIsMountedTracker,
|
|
59
|
+
X as useFormGroupChildIsSubmittingTracker,
|
|
60
|
+
_ as useFormGroupChildTracker,
|
|
61
|
+
rr as useFormGroupIsAnyBusy,
|
|
62
|
+
er as useFormGroupIsChildBusy,
|
|
63
|
+
sr as useFormGroupIsParentBusy,
|
|
64
|
+
ur as useFormGroupParentTracker,
|
|
65
|
+
y as useFormHasOrphanAndNoFieldErrors,
|
|
66
|
+
nr as useFormOnSubmitSuccessful,
|
|
67
|
+
Er as useFormOnSubmitSuccessfulAndReset,
|
|
68
|
+
mr as useFormOrParentIsBusy,
|
|
69
|
+
Z as useFormRequestSubmit,
|
|
70
|
+
w as useFormUtilsContext,
|
|
71
|
+
M as useOrphanFormErrorsMemo,
|
|
72
|
+
P as useOrphanFormErrorsToConsole,
|
|
73
|
+
Sr as useResetFormAfterSubmitSuccessful,
|
|
74
|
+
cr as useResetFormOnSubmitError,
|
|
75
|
+
s as useRhfUtilsZodContext,
|
|
76
|
+
I as useRootFormFieldErrorsMemo,
|
|
77
|
+
yr as useSubmitFormOnChange
|
|
74
78
|
};
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { jsx as o } from "react/jsx-runtime";
|
|
2
|
+
import t from "./_Form.mjs";
|
|
3
|
+
import e from "./_FormProviders.mjs";
|
|
4
|
+
import f from "./useForm.mjs";
|
|
5
|
+
function u({
|
|
6
|
+
children: m,
|
|
7
|
+
...i
|
|
8
|
+
}) {
|
|
9
|
+
const r = f(i);
|
|
10
|
+
return /* @__PURE__ */ o(e, { ...r.providerProps, children: /* @__PURE__ */ o(t, { ...r.formProps, children: m }) });
|
|
11
|
+
}
|
|
12
|
+
export {
|
|
13
|
+
u as default
|
|
14
|
+
};
|
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
import { jsxs as v, jsx as p } from "react/jsx-runtime";
|
|
2
|
+
import "react";
|
|
3
|
+
import { useFormContext as B } from "react-hook-form";
|
|
4
|
+
import N from "../devtool/LazyDevTool.mjs";
|
|
5
|
+
import { FormSubmitError as P } from "../submit/error/FormSubmitError.mjs";
|
|
6
|
+
import T from "../submit/error/setCtxErrorsByFormSubmitError.mjs";
|
|
7
|
+
import V from "../submit/useResetFormOnSubmitError.mjs";
|
|
8
|
+
import _ from "./_FormBase.mjs";
|
|
9
|
+
function A({
|
|
10
|
+
formId: x,
|
|
11
|
+
formRef: l,
|
|
12
|
+
form: t,
|
|
13
|
+
children: y
|
|
14
|
+
}) {
|
|
15
|
+
var c, b, S, o, h;
|
|
16
|
+
const a = B();
|
|
17
|
+
V({
|
|
18
|
+
disabled: !((c = t == null ? void 0 : t.options) != null && c.resetValuesOnSubmitError)
|
|
19
|
+
});
|
|
20
|
+
const C = async (i) => {
|
|
21
|
+
var n;
|
|
22
|
+
(n = t == null ? void 0 : t.options) != null && n.stopSubmitPropagation && i.stopPropagation();
|
|
23
|
+
try {
|
|
24
|
+
await a.handleSubmit(
|
|
25
|
+
g,
|
|
26
|
+
t == null ? void 0 : t.onSubmitInvalid
|
|
27
|
+
)(i);
|
|
28
|
+
} catch (s) {
|
|
29
|
+
j(s, i);
|
|
30
|
+
}
|
|
31
|
+
}, g = (i, n) => {
|
|
32
|
+
var s;
|
|
33
|
+
return (s = t == null ? void 0 : t.onSubmit) == null ? void 0 : s.call(
|
|
34
|
+
t,
|
|
35
|
+
i,
|
|
36
|
+
a,
|
|
37
|
+
n
|
|
38
|
+
);
|
|
39
|
+
}, j = (i, n) => {
|
|
40
|
+
var e, E, F;
|
|
41
|
+
const s = i instanceof P ? (
|
|
42
|
+
// consumer can manually throw FormSubmitError (e.g., manual validation)
|
|
43
|
+
i
|
|
44
|
+
) : (
|
|
45
|
+
// if error is not FormSubmitError, consumer can provide global handler
|
|
46
|
+
(E = (e = t == null ? void 0 : t.options) == null ? void 0 : e.onSubmitError) == null ? void 0 : E.call(e, i)
|
|
47
|
+
);
|
|
48
|
+
s && T(a, s), (F = t == null ? void 0 : t.onSubmitError) == null || F.call(
|
|
49
|
+
t,
|
|
50
|
+
i,
|
|
51
|
+
a,
|
|
52
|
+
n
|
|
53
|
+
);
|
|
54
|
+
}, u = {
|
|
55
|
+
formId: x,
|
|
56
|
+
formRef: l,
|
|
57
|
+
ctx: a,
|
|
58
|
+
options: t == null ? void 0 : t.options
|
|
59
|
+
}, d = (i) => {
|
|
60
|
+
var s, e;
|
|
61
|
+
const n = (e = (s = t == null ? void 0 : t.options) == null ? void 0 : s.Children) == null ? void 0 : e[i];
|
|
62
|
+
return n && /* @__PURE__ */ p(n, { ...u });
|
|
63
|
+
};
|
|
64
|
+
return /* @__PURE__ */ v(
|
|
65
|
+
_,
|
|
66
|
+
{
|
|
67
|
+
noValidate: !0,
|
|
68
|
+
style: {
|
|
69
|
+
position: "relative"
|
|
70
|
+
},
|
|
71
|
+
...t == null ? void 0 : t.props,
|
|
72
|
+
className: [(b = t == null ? void 0 : t.options) == null ? void 0 : b.classNames, ((S = t == null ? void 0 : t.props) == null ? void 0 : S.className) ?? ""].join(
|
|
73
|
+
" "
|
|
74
|
+
),
|
|
75
|
+
onSubmit: C,
|
|
76
|
+
formRef: l,
|
|
77
|
+
children: [
|
|
78
|
+
d("top"),
|
|
79
|
+
((o = t == null ? void 0 : t.options) == null ? void 0 : o.devTool) !== "disabled" && /* @__PURE__ */ p(N, { placement: "top-right", ...(h = t == null ? void 0 : t.options) == null ? void 0 : h.devTool }),
|
|
80
|
+
(t == null ? void 0 : t.Fields) && /* @__PURE__ */ p(t.Fields, { ...u }),
|
|
81
|
+
y,
|
|
82
|
+
d("bottom")
|
|
83
|
+
]
|
|
84
|
+
}
|
|
85
|
+
);
|
|
86
|
+
}
|
|
87
|
+
export {
|
|
88
|
+
A as default
|
|
89
|
+
};
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { jsxs as m, jsx as s } from "react/jsx-runtime";
|
|
2
|
+
import "react";
|
|
3
|
+
const n = ({
|
|
4
|
+
formRef: e,
|
|
5
|
+
antiCsrfToken: r,
|
|
6
|
+
children: o,
|
|
7
|
+
...t
|
|
8
|
+
}) => /* @__PURE__ */ m("form", { role: "form", ...t, ref: e, children: [
|
|
9
|
+
r && /* @__PURE__ */ s("input", { type: "hidden", name: "anticsrftoken", value: r }),
|
|
10
|
+
o
|
|
11
|
+
] }), i = n;
|
|
12
|
+
export {
|
|
13
|
+
i as default
|
|
14
|
+
};
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { jsx as r } from "react/jsx-runtime";
|
|
2
|
+
import { FormProvider as d } from "react-hook-form";
|
|
3
|
+
import n from "../errors/context/provider.mjs";
|
|
4
|
+
import l from "./context/utils/FormUtilsContextProvider.mjs";
|
|
5
|
+
function v({
|
|
6
|
+
formId: t,
|
|
7
|
+
formRef: o,
|
|
8
|
+
rhfForm: i,
|
|
9
|
+
utils: m,
|
|
10
|
+
children: e
|
|
11
|
+
}) {
|
|
12
|
+
return /* @__PURE__ */ r(d, { ...i, children: /* @__PURE__ */ r(n, { formRef: o, children: /* @__PURE__ */ r(l, { formId: t, formRef: o, ...m, children: e }) }) });
|
|
13
|
+
}
|
|
14
|
+
export {
|
|
15
|
+
v as default
|
|
16
|
+
};
|
|
@@ -1,27 +1,23 @@
|
|
|
1
|
-
import
|
|
2
|
-
import i from "react";
|
|
1
|
+
import n from "react";
|
|
3
2
|
import { useForm as u } from "react-hook-form";
|
|
4
|
-
import
|
|
5
|
-
|
|
6
|
-
const a = ({
|
|
7
|
-
schema: t,
|
|
3
|
+
import i from "../submit/useSubmitFormOnChange.mjs";
|
|
4
|
+
const l = ({
|
|
8
5
|
rhf: m,
|
|
9
6
|
form: o,
|
|
10
7
|
utils: p
|
|
11
8
|
}) => {
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
}),
|
|
17
|
-
return c(r, { disabled: !e.options.submitOnChange }), {
|
|
9
|
+
var t;
|
|
10
|
+
const s = n.useId(), e = u(m), r = n.useRef(null);
|
|
11
|
+
return i(r, {
|
|
12
|
+
disabled: !((t = o == null ? void 0 : o.options) != null && t.submitOnChange)
|
|
13
|
+
}), {
|
|
18
14
|
id: s,
|
|
19
15
|
ref: r,
|
|
20
|
-
context:
|
|
16
|
+
context: e,
|
|
21
17
|
providerProps: {
|
|
22
18
|
formId: s,
|
|
23
19
|
formRef: r,
|
|
24
|
-
rhfForm:
|
|
20
|
+
rhfForm: e,
|
|
25
21
|
utils: p
|
|
26
22
|
},
|
|
27
23
|
formProps: {
|
|
@@ -30,7 +26,7 @@ const a = ({
|
|
|
30
26
|
form: o
|
|
31
27
|
}
|
|
32
28
|
};
|
|
33
|
-
}
|
|
29
|
+
};
|
|
34
30
|
export {
|
|
35
|
-
|
|
31
|
+
l as default
|
|
36
32
|
};
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { UseFormOptions } from '../form/useFormOptions';
|
|
2
|
+
import { UseFormProps } from 'react-hook-form';
|
|
3
|
+
|
|
4
|
+
export type ClientConfig = {
|
|
5
|
+
defaultOptions?: {
|
|
6
|
+
/**
|
|
7
|
+
* Default RHF `useForm` settings.
|
|
8
|
+
*
|
|
9
|
+
* (Exposes only non-local props.)
|
|
10
|
+
*/
|
|
11
|
+
rhf?: Pick<UseFormProps, 'mode' | 'reValidateMode' | 'resetOptions' | 'context' | 'shouldFocusError' | 'shouldUnregister' | 'shouldUseNativeValidation' | 'progressive' | 'criteriaMode' | 'delayError'>;
|
|
12
|
+
/**
|
|
13
|
+
* Default global options settings.
|
|
14
|
+
*
|
|
15
|
+
* Extend this type to inject custom options/functionality via `Children` component.
|
|
16
|
+
*/
|
|
17
|
+
form?: UseFormOptions;
|
|
18
|
+
};
|
|
19
|
+
};
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
import { CreateRhfUtilsClient, ObjectSchema } from '.';
|
|
2
|
+
|
|
3
|
+
export type RhfUtilsClientContext<TObjectSchema extends ObjectSchema<TObjectSchemaInputKey, TObjectSchemaOutputKey>, TObjectSchemaInputKey extends string, TObjectSchemaOutputKey extends string> = CreateRhfUtilsClient<TObjectSchema, TObjectSchemaInputKey, TObjectSchemaOutputKey>;
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { ClientConfig } from './config';
|
|
2
|
+
import { UseFormProps, UseFormReturn } from '../form/useForm';
|
|
3
|
+
import { FormWithProvidersProps } from '../form/FormWithProviders';
|
|
4
|
+
import { FieldValues, Resolver } from 'react-hook-form';
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* Generic object schema type.
|
|
8
|
+
*/
|
|
9
|
+
export type ObjectSchema<TInputKey extends string, TOutputKey extends string> = {
|
|
10
|
+
[key in TInputKey]: FieldValues;
|
|
11
|
+
} & {
|
|
12
|
+
[key in TOutputKey]: FieldValues;
|
|
13
|
+
};
|
|
14
|
+
export type CreateRhfUtilsClient<TObjectSchema extends ObjectSchema<TObjectSchemaInputKey, TObjectSchemaOutputKey>, TObjectSchemaInputKey extends string, TObjectSchemaOutputKey extends string> = {
|
|
15
|
+
config: ClientConfig;
|
|
16
|
+
useForm: <TSchema extends TObjectSchema, TSchemaInput extends FieldValues = TSchema[TObjectSchemaInputKey], TSchemaOutput extends FieldValues = TSchema[TObjectSchemaOutputKey]>(schema: TSchema, props: UseFormProps<TSchemaInput, TSchemaOutput>) => UseFormReturn<TSchemaInput, TSchemaOutput>;
|
|
17
|
+
FormWithProviders: <TSchema extends TObjectSchema, TSchemaInput extends FieldValues = TSchema[TObjectSchemaInputKey], TSchemaOutput extends FieldValues = TSchema[TObjectSchemaOutputKey]>(props: {
|
|
18
|
+
schema: TSchema;
|
|
19
|
+
} & FormWithProvidersProps<TSchemaInput, TSchemaOutput>) => JSX.Element;
|
|
20
|
+
};
|
|
21
|
+
/**
|
|
22
|
+
* ...
|
|
23
|
+
*
|
|
24
|
+
* (We need to use generics to generate types for schema resolver.)
|
|
25
|
+
*/
|
|
26
|
+
export declare const createRhfUtilsClient: <TObjectSchema extends ObjectSchema<TObjectSchemaInputKey, TObjectSchemaOutputKey>, TObjectSchemaInputKey extends string, TObjectSchemaOutputKey extends string>(resolver: (schema: TObjectSchema) => Resolver<FieldValues, unknown>) => (config: ClientConfig) => CreateRhfUtilsClient<TObjectSchema, TObjectSchemaInputKey, TObjectSchemaOutputKey>;
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { RhfUtilsClientContext } from '../../context';
|
|
2
|
+
import { z } from 'zod';
|
|
3
|
+
import { FieldValues } from 'react-hook-form';
|
|
4
|
+
|
|
5
|
+
export type RhfUtilsZodClientContext = RhfUtilsClientContext<z.ZodObject<FieldValues>, '_input', '_output'>;
|
|
6
|
+
declare const useRhfUtilsZodContext: () => RhfUtilsZodClientContext, _RhfUtilsZodContextProvider: import('react').Provider<RhfUtilsZodClientContext | undefined>;
|
|
7
|
+
export default useRhfUtilsZodContext;
|
|
8
|
+
export { _RhfUtilsZodContextProvider as _RhfUtilsContextProvider };
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { ClientConfig } from '../../config';
|
|
2
|
+
import { default as React } from 'react';
|
|
3
|
+
|
|
4
|
+
type Props = React.PropsWithChildren<{
|
|
5
|
+
config: ClientConfig;
|
|
6
|
+
}>;
|
|
7
|
+
/**
|
|
8
|
+
* Provides a flattened version of the form errors.
|
|
9
|
+
* Allows flattening and filtering to happen once per errors change.
|
|
10
|
+
*/
|
|
11
|
+
declare const RhfUtilsZodContextProvider: React.FC<Props>;
|
|
12
|
+
export default RhfUtilsZodContextProvider;
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
import { FieldValues } from 'react-hook-form';
|
|
3
|
+
|
|
4
|
+
export declare const createZodRhfUtilsClient: (config: import('../config').ClientConfig) => import('..').CreateRhfUtilsClient<z.ZodObject<FieldValues, z.UnknownKeysParam, z.ZodTypeAny, {
|
|
5
|
+
[x: string]: any;
|
|
6
|
+
}, {
|
|
7
|
+
[x: string]: any;
|
|
8
|
+
}>, "_input", "_output">;
|
|
@@ -1,4 +1,7 @@
|
|
|
1
|
-
export {
|
|
1
|
+
export type { ClientConfig } from './client/config';
|
|
2
|
+
export { createZodRhfUtilsClient } from './client/zod';
|
|
3
|
+
export { default as useRhfUtilsZodContext } from './client/zod/context';
|
|
4
|
+
export { default as RhfUtilsZodContextProvider } from './client/zod/context/provider';
|
|
2
5
|
export { default as LazyDevTool } from './devtool/LazyDevTool';
|
|
3
6
|
export { default as useFormErrorsFlatContext } from './errors/context';
|
|
4
7
|
export { default as FormErrorsFlatContextProvider } from './errors/context/provider';
|
|
@@ -15,8 +18,9 @@ export { default as useFormErrorsEffect } from './errors/useFormErrorsEffect';
|
|
|
15
18
|
export { default as useFormErrorsIfAny } from './errors/useFormErrorsIfAny';
|
|
16
19
|
export { default as useFormErrorsMemo } from './errors/useFormErrorsMemo';
|
|
17
20
|
export { default as useFormRequestSubmit } from './errors/useFormRequestSubmit';
|
|
18
|
-
export type { UseFormFieldsProps
|
|
21
|
+
export type { UseFormFieldsProps } from './form/useForm';
|
|
19
22
|
export { default as useForm } from './form/useForm';
|
|
23
|
+
export type { UseFormOptions } from './form/useFormOptions';
|
|
20
24
|
export { default as FormUtilsContextProvider } from './form/context/utils/FormUtilsContextProvider';
|
|
21
25
|
export { default as useFormUtilsContext } from './form/context/utils/useFormUtilsContext';
|
|
22
26
|
export { default as FormGroupContextProvider } from './form/context/group/FormGroupContextProvider';
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { UseFormProps } from './useForm';
|
|
2
|
-
import { z } from 'zod';
|
|
3
2
|
import { FieldValues } from 'react-hook-form';
|
|
4
3
|
|
|
4
|
+
export type FormWithProvidersProps<TFieldValues extends FieldValues, TTransformedValues extends FieldValues> = React.PropsWithChildren<UseFormProps<TFieldValues, TTransformedValues>>;
|
|
5
5
|
/**
|
|
6
6
|
* Form providers (with utils) with immediate descendent {@link Form}.
|
|
7
7
|
* (Syntactic sugar for {@link useForm}. Use this for most applications.)
|
|
@@ -9,5 +9,5 @@ import { FieldValues } from 'react-hook-form';
|
|
|
9
9
|
* Use {@link useForm} if you need to specific nesting hierarchy.
|
|
10
10
|
* (e.g., wrapping `<tr>` with provider and nesting `<form>` within `<td>` to appease HTML rules.)
|
|
11
11
|
*/
|
|
12
|
-
declare function FormWithProviders<
|
|
12
|
+
declare function FormWithProviders<TFieldValues extends FieldValues, TTransformedValues extends FieldValues>({ children, ...props }: FormWithProvidersProps<TFieldValues, TTransformedValues>): import("react/jsx-runtime").JSX.Element;
|
|
13
13
|
export default FormWithProviders;
|
|
@@ -1,12 +1,11 @@
|
|
|
1
1
|
import { UseFormProps } from './useForm';
|
|
2
|
-
import { z } from 'zod';
|
|
3
2
|
import { FieldValues } from 'react-hook-form';
|
|
4
3
|
import { default as React } from 'react';
|
|
5
4
|
|
|
6
5
|
export type _FormSlots = 'top' | 'bottom';
|
|
7
|
-
export type _FormProps<
|
|
6
|
+
export type _FormProps<TFieldValues extends FieldValues, TTransformedValues extends FieldValues> = React.PropsWithChildren<Pick<UseFormProps<TFieldValues, TTransformedValues>, 'form'> & {
|
|
8
7
|
formId: string;
|
|
9
8
|
formRef: React.RefObject<HTMLFormElement>;
|
|
10
9
|
}>;
|
|
11
|
-
declare function _Form<
|
|
10
|
+
declare function _Form<TFieldValues extends FieldValues, TTransformedValues extends FieldValues>({ formId, formRef, form, children, }: _FormProps<TFieldValues, TTransformedValues>): import("react/jsx-runtime").JSX.Element;
|
|
12
11
|
export default _Form;
|
|
@@ -1,12 +1,11 @@
|
|
|
1
1
|
import { FormUtilsContextProviderProps } from './context/utils/FormUtilsContextProvider';
|
|
2
|
-
import { z } from 'zod';
|
|
3
2
|
import { FieldValues, UseFormReturn } from 'react-hook-form';
|
|
4
3
|
|
|
5
|
-
export type _FormProvidersProps<
|
|
4
|
+
export type _FormProvidersProps<TFieldValues extends FieldValues, TTransformedValues extends FieldValues> = React.PropsWithChildren<{
|
|
6
5
|
formId: string;
|
|
7
6
|
formRef: React.RefObject<HTMLFormElement>;
|
|
8
7
|
rhfForm: UseFormReturn<TFieldValues, unknown, TTransformedValues>;
|
|
9
8
|
utils?: FormUtilsContextProviderProps;
|
|
10
9
|
}>;
|
|
11
|
-
declare function _FormProviders<
|
|
10
|
+
declare function _FormProviders<TFieldValues extends FieldValues, TTransformedValues extends FieldValues>({ formId, formRef, rhfForm, utils, children, }: _FormProvidersProps<TFieldValues, TTransformedValues>): import("react/jsx-runtime").JSX.Element;
|
|
12
11
|
export default _FormProviders;
|
|
@@ -1,39 +1,25 @@
|
|
|
1
|
+
import { UseFormOptions } from './useFormOptions';
|
|
1
2
|
import { FormUtilsContextProviderProps } from './context/utils/FormUtilsContextProvider';
|
|
2
3
|
import { _FormProvidersProps } from './_FormProviders';
|
|
3
4
|
import { _FormProps } from './_Form';
|
|
4
|
-
import {
|
|
5
|
-
import { FieldValues, SubmitErrorHandler, UseFormProps as RhfUseFormProps, UseFormReturn } from 'react-hook-form';
|
|
5
|
+
import { FieldValues, SubmitErrorHandler, UseFormProps as RhfUseFormProps, UseFormReturn as RhfUseFormReturn } from 'react-hook-form';
|
|
6
6
|
import { default as React } from 'react';
|
|
7
|
-
import { DevtoolUIProps } from '@hookform/devtools/dist/devToolUI';
|
|
8
7
|
|
|
9
|
-
export type UseFormOptions = {
|
|
10
|
-
/** Control visibility of certain items via your own classes and styles. */
|
|
11
|
-
classNames?: string[];
|
|
12
|
-
/** Request submit via listener on form change. */
|
|
13
|
-
submitOnChange?: boolean;
|
|
14
|
-
/** Reset form values if submit throw errors. Use case: optimistic UI toggle form that submits on each change */
|
|
15
|
-
resetValuesOnSubmitError?: boolean;
|
|
16
|
-
/** Stop propagation of submit event. Useful for portals. */
|
|
17
|
-
stopSubmitPropagation?: boolean;
|
|
18
|
-
/** Control dev tool options. */
|
|
19
|
-
devTool?: DevtoolUIProps | 'disabled';
|
|
20
|
-
};
|
|
21
8
|
export type UseFormFieldsProps<TFieldValues extends FieldValues = FieldValues, TTransformedValues extends FieldValues = FieldValues> = {
|
|
22
9
|
formId: string;
|
|
23
10
|
formRef: React.RefObject<HTMLFormElement>;
|
|
24
|
-
ctx:
|
|
11
|
+
ctx: RhfUseFormReturn<TFieldValues, unknown, TTransformedValues>;
|
|
25
12
|
options?: UseFormOptions;
|
|
26
13
|
};
|
|
27
|
-
export type UseFormProps<
|
|
28
|
-
schema?: TSchema;
|
|
14
|
+
export type UseFormProps<TFieldValues extends FieldValues, TTransformedValues extends FieldValues> = {
|
|
29
15
|
/** {@link RhfUseFormProps} props for RHF's {@link useRhfForm}. */
|
|
30
16
|
rhf?: RhfUseFormProps<TFieldValues>;
|
|
31
17
|
/** {@link FormProps} props for Form. */
|
|
32
18
|
form?: {
|
|
33
19
|
Fields?: React.FC<UseFormFieldsProps<TFieldValues, TTransformedValues>>;
|
|
34
|
-
onSubmit?: (values: TTransformedValues, context:
|
|
20
|
+
onSubmit?: (values: TTransformedValues, context: RhfUseFormReturn<TFieldValues, unknown, TTransformedValues>, event: React.BaseSyntheticEvent<SubmitEvent>) => unknown | Promise<unknown>;
|
|
35
21
|
/** Submit error handler. (Only for errors not of instance `FormError`, which are handled internally.) */
|
|
36
|
-
onSubmitError?: (error: unknown, context:
|
|
22
|
+
onSubmitError?: (error: unknown, context: RhfUseFormReturn<TFieldValues, unknown, TTransformedValues>, event: React.BaseSyntheticEvent<SubmitEvent>) => void;
|
|
37
23
|
/** Submit handler when form is invalid. */
|
|
38
24
|
onSubmitInvalid?: SubmitErrorHandler<TFieldValues>;
|
|
39
25
|
options?: UseFormOptions;
|
|
@@ -50,15 +36,13 @@ export type UseFormProps<TSchema extends z.ZodObject<FieldValues>, TFieldValues
|
|
|
50
36
|
* see https://caniuse.com/?search=form%20attribute
|
|
51
37
|
* @returns Form provider and form.
|
|
52
38
|
*/
|
|
53
|
-
declare const useForm: <
|
|
54
|
-
[x: string]: any;
|
|
55
|
-
}, {
|
|
56
|
-
[x: string]: any;
|
|
57
|
-
}>, TFieldValues extends z.input<TSchema>, TTransformedValues extends z.output<TSchema>>({ schema, rhf, form, utils, }: UseFormProps<TSchema, TFieldValues, TTransformedValues>) => {
|
|
39
|
+
declare const useForm: <TFieldValues extends FieldValues, TTransformedValues extends FieldValues>({ rhf, form, utils, }: UseFormProps<TFieldValues, TTransformedValues>) => {
|
|
58
40
|
readonly id: string;
|
|
59
41
|
readonly ref: React.RefObject<HTMLFormElement>;
|
|
60
|
-
readonly context:
|
|
61
|
-
readonly providerProps: _FormProvidersProps<
|
|
62
|
-
readonly formProps: _FormProps<
|
|
42
|
+
readonly context: RhfUseFormReturn<TFieldValues, unknown, TTransformedValues>;
|
|
43
|
+
readonly providerProps: _FormProvidersProps<TFieldValues, TTransformedValues>;
|
|
44
|
+
readonly formProps: _FormProps<TFieldValues, TTransformedValues>;
|
|
63
45
|
};
|
|
64
46
|
export default useForm;
|
|
47
|
+
export type UseForm<TFieldValues extends FieldValues, TTransformedValues extends FieldValues> = typeof useForm<TFieldValues, TTransformedValues>;
|
|
48
|
+
export type UseFormReturn<TFieldValues extends FieldValues, TTransformedValues extends FieldValues> = ReturnType<UseForm<TFieldValues, TTransformedValues>>;
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { UseFormFieldsProps } from './useForm';
|
|
2
|
+
import { _FormSlots } from './_Form';
|
|
3
|
+
import { FormSubmitError } from '../submit/error/FormSubmitError';
|
|
4
|
+
import { DevtoolUIProps } from '@hookform/devtools/dist/devToolUI';
|
|
5
|
+
|
|
6
|
+
export type UseFormOptions = {
|
|
7
|
+
/** Control visibility of certain items via your own classes and styles. */
|
|
8
|
+
classNames?: string[];
|
|
9
|
+
/** Request submit via listener on form change. */
|
|
10
|
+
submitOnChange?: boolean;
|
|
11
|
+
/** Reset form values if submit throw errors. Use case: optimistic UI toggle form that submits on each change */
|
|
12
|
+
resetValuesOnSubmitError?: boolean;
|
|
13
|
+
/** Stop propagation of submit event. Useful for portals. */
|
|
14
|
+
stopSubmitPropagation?: boolean;
|
|
15
|
+
/** Control dev tool options. */
|
|
16
|
+
devTool?: DevtoolUIProps | 'disabled';
|
|
17
|
+
/**
|
|
18
|
+
* Components injected by slot.
|
|
19
|
+
*
|
|
20
|
+
* e.g., top: block navigation on dirty form.
|
|
21
|
+
* e.g., bottom: root errors list.
|
|
22
|
+
*/
|
|
23
|
+
Children?: Partial<Record<_FormSlots, React.FC<UseFormFieldsProps>>>;
|
|
24
|
+
/**
|
|
25
|
+
* Handle non-{@link FormSubmitError} errors. Optionally, return {@link FormSubmitError} to merge into context errors.
|
|
26
|
+
*/
|
|
27
|
+
onSubmitError?: (error: unknown) => FormSubmitError | undefined;
|
|
28
|
+
};
|
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.61",
|
|
6
6
|
"description": "Integration utilities for react-hook-form.",
|
|
7
7
|
"type": "module",
|
|
8
8
|
"sideEffects": false,
|
|
@@ -21,9 +21,17 @@
|
|
|
21
21
|
"default": "./dist/esm/exports.mjs",
|
|
22
22
|
"types": "./dist/types/exports.d.ts"
|
|
23
23
|
},
|
|
24
|
-
"./
|
|
25
|
-
"default": "./dist/esm/
|
|
26
|
-
"types": "./dist/types/
|
|
24
|
+
"./createZodRhfUtilsClient": {
|
|
25
|
+
"default": "./dist/esm/client/zod/createZodRhfUtilsClient.mjs",
|
|
26
|
+
"types": "./dist/types/client/zod/createZodRhfUtilsClient.d.ts"
|
|
27
|
+
},
|
|
28
|
+
"./useRhfUtilsZodContext": {
|
|
29
|
+
"default": "./dist/esm/client/zod/useRhfUtilsZodContext.mjs",
|
|
30
|
+
"types": "./dist/types/client/zod/useRhfUtilsZodContext.d.ts"
|
|
31
|
+
},
|
|
32
|
+
"./RhfUtilsZodContextProvider": {
|
|
33
|
+
"default": "./dist/esm/client/zod/RhfUtilsZodContextProvider.mjs",
|
|
34
|
+
"types": "./dist/types/client/zod/RhfUtilsZodContextProvider.d.ts"
|
|
27
35
|
},
|
|
28
36
|
"./LazyDevTool": {
|
|
29
37
|
"default": "./dist/esm/devtool/LazyDevTool.mjs",
|
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
let s;
|
|
2
|
-
const t = (e) => {
|
|
3
|
-
s = e;
|
|
4
|
-
}, l = (e) => {
|
|
5
|
-
var a;
|
|
6
|
-
return {
|
|
7
|
-
...s,
|
|
8
|
-
options: {
|
|
9
|
-
...s == null ? void 0 : s.options,
|
|
10
|
-
...e,
|
|
11
|
-
classNames: [
|
|
12
|
-
...((a = s == null ? void 0 : s.options) == null ? void 0 : a.classNames) ?? [],
|
|
13
|
-
...(e == null ? void 0 : e.classNames) ?? []
|
|
14
|
-
]
|
|
15
|
-
}
|
|
16
|
-
};
|
|
17
|
-
};
|
|
18
|
-
export {
|
|
19
|
-
l as _getConfig,
|
|
20
|
-
t as setConfig
|
|
21
|
-
};
|