@paragrav/rhf-utils 0.0.103 → 0.0.104
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +35 -13
- package/dist/esm/client/zod/RhfUtilsZodForm.mjs +12 -0
- package/dist/esm/exports.mjs +18 -18
- package/dist/esm/form/Form.mjs +7 -7
- package/dist/types/client/zod/RhfUtilsZodForm.d.ts +8 -0
- package/dist/types/exports.d.ts +1 -1
- package/dist/types/form/useForm.d.ts +1 -1
- package/package.json +1 -1
- package/dist/esm/client/zod/context/RhfUtilsZodFormWithProviders.mjs +0 -12
package/README.md
CHANGED
|
@@ -17,10 +17,12 @@ export const config: RhfUtilsClientConfig = {
|
|
|
17
17
|
isDevelopment: import.meta.env.DEV,
|
|
18
18
|
|
|
19
19
|
defaultOptions: {
|
|
20
|
+
// UseFormProps
|
|
20
21
|
rhf: {
|
|
21
22
|
mode: 'onBlur',
|
|
22
23
|
},
|
|
23
24
|
|
|
25
|
+
// UseFormOptions
|
|
24
26
|
form: {
|
|
25
27
|
devTool: {
|
|
26
28
|
placement: 'top-right',
|
|
@@ -31,7 +33,9 @@ export const config: RhfUtilsClientConfig = {
|
|
|
31
33
|
FormComponent: Form.Root,
|
|
32
34
|
|
|
33
35
|
// transform backend error
|
|
34
|
-
onSubmitError: (
|
|
36
|
+
onSubmitError: (
|
|
37
|
+
error, // unknown
|
|
38
|
+
) => {
|
|
35
39
|
// if other error, re-throw to handle
|
|
36
40
|
if (!(error instanceof TRPCClientError)) throw error;
|
|
37
41
|
|
|
@@ -43,7 +47,9 @@ export const config: RhfUtilsClientConfig = {
|
|
|
43
47
|
},
|
|
44
48
|
|
|
45
49
|
Children: {
|
|
46
|
-
top: (
|
|
50
|
+
top: (
|
|
51
|
+
{ options }, // UseFormFieldsProps
|
|
52
|
+
) => {
|
|
47
53
|
// navigation blocker (using custom option)
|
|
48
54
|
useFormRouterBlocker(!!options?.prompter);
|
|
49
55
|
|
|
@@ -73,31 +79,47 @@ And add the context provider to your stack:
|
|
|
73
79
|
## Usage
|
|
74
80
|
|
|
75
81
|
```tsx
|
|
76
|
-
<
|
|
82
|
+
<RhfUtilsZodForm
|
|
77
83
|
schema={authLoginFormSchema}
|
|
78
|
-
onSubmit={async (data) => {
|
|
79
|
-
await authLoginService(data, { from });
|
|
80
|
-
onSuccess?.();
|
|
81
|
-
}}
|
|
82
|
-
onSubmitError={onError}
|
|
83
84
|
defaultValues={{
|
|
84
85
|
email: '',
|
|
85
86
|
}}
|
|
86
|
-
|
|
87
|
+
// submit handler
|
|
88
|
+
onSubmit={async (data) => {
|
|
89
|
+
await authLoginService(data);
|
|
90
|
+
onSuccess();
|
|
91
|
+
}}
|
|
92
|
+
// handle error declaratively (i.e., no throw/catch)
|
|
93
|
+
onSubmitError={({
|
|
94
|
+
error, // unknown
|
|
95
|
+
context, // rhf UseFormReturn
|
|
96
|
+
event, // SubmitEvent
|
|
97
|
+
}) => {
|
|
98
|
+
onError(error);
|
|
99
|
+
}}
|
|
100
|
+
// fields
|
|
101
|
+
Fields={({
|
|
102
|
+
formId, // unique id string
|
|
103
|
+
formRef, // ref
|
|
104
|
+
context, // rhf UseFormReturn
|
|
105
|
+
options, // UseFormOptions
|
|
106
|
+
Controller, // strongly-typed controlled
|
|
107
|
+
}) => (
|
|
87
108
|
<>
|
|
88
109
|
<Controller
|
|
89
110
|
name="email" // strongly-typed field name
|
|
90
|
-
render={(
|
|
91
|
-
<
|
|
92
|
-
controller={props}
|
|
111
|
+
render={({ field, formState: { isSubmitting } }) => (
|
|
112
|
+
<input
|
|
93
113
|
autoFocus
|
|
94
114
|
label="Email"
|
|
95
115
|
autoComplete="email"
|
|
116
|
+
disabled={isSubmitting}
|
|
117
|
+
{...field}
|
|
96
118
|
/>
|
|
97
119
|
)}
|
|
98
120
|
/>
|
|
99
121
|
|
|
100
|
-
<
|
|
122
|
+
<button type="submit">Login</button>
|
|
101
123
|
</>
|
|
102
124
|
)}
|
|
103
125
|
/>
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { jsx as e } from "react/jsx-runtime";
|
|
2
|
+
import i from "./context/useRhfUtilsClientForZodContext.mjs";
|
|
3
|
+
function f({
|
|
4
|
+
schema: o,
|
|
5
|
+
...t
|
|
6
|
+
}) {
|
|
7
|
+
const r = i();
|
|
8
|
+
return /* @__PURE__ */ e(r.FormWithProviders, { schema: o, ...t });
|
|
9
|
+
}
|
|
10
|
+
export {
|
|
11
|
+
f as default
|
|
12
|
+
};
|
package/dist/esm/exports.mjs
CHANGED
|
@@ -1,24 +1,24 @@
|
|
|
1
1
|
import { default as e } from "./client/zod/context/RhfUtilsClientForZodContextProvider.mjs";
|
|
2
|
-
import { default as s } from "./client/zod/context/
|
|
3
|
-
import { default as f } from "./client/zod/context/
|
|
4
|
-
import { default as m } from "./client/zod/
|
|
2
|
+
import { default as s } from "./client/zod/context/useRhfUtilsClientForZodContext.mjs";
|
|
3
|
+
import { default as f } from "./client/zod/context/useRhfUtilsZodForm.mjs";
|
|
4
|
+
import { default as m } from "./client/zod/RhfUtilsZodForm.mjs";
|
|
5
5
|
import { default as d } from "./devtool/LazyDevTool.mjs";
|
|
6
6
|
import { default as x } from "./errors/flat/context/useFlatFieldErrorsContext.mjs";
|
|
7
7
|
import { default as i } from "./errors/flat/FlatFieldErrorsList.mjs";
|
|
8
8
|
import { default as E } from "./errors/message/FormErrorMessage.mjs";
|
|
9
9
|
import { default as C } from "./errors/message/FormErrorMessageByPath.mjs";
|
|
10
10
|
import { default as G } from "./errors/nonfield/FormNonFieldErrorMarker.mjs";
|
|
11
|
-
import { default as
|
|
12
|
-
import { default as
|
|
11
|
+
import { default as c } from "./errors/nonfield/FormNonFieldErrorMarkerHtmlAttribute.mjs";
|
|
12
|
+
import { default as P } from "./errors/orphan/useFormHasOnlyOrphanFieldErrorsMemo.mjs";
|
|
13
13
|
import { default as B } from "./errors/orphan/useOrphanFormErrorsMemo.mjs";
|
|
14
14
|
import { default as b } from "./errors/root/RootErrorsListFromFlatFieldErrorsContext.mjs";
|
|
15
|
-
import { default as
|
|
16
|
-
import { default as
|
|
17
|
-
import { default as
|
|
15
|
+
import { default as S } from "./errors/root/useRootFormFieldErrorsMemo.mjs";
|
|
16
|
+
import { default as U } from "./errors/useFormErrorsEffect.mjs";
|
|
17
|
+
import { default as v } from "./errors/useFormErrorsIfAny.mjs";
|
|
18
18
|
import { default as A } from "./form/FormWithProviders.mjs";
|
|
19
19
|
import { default as D } from "./form/useForm.mjs";
|
|
20
20
|
import { default as N } from "./form/context/utils/useFormUtilsContext.mjs";
|
|
21
|
-
import { default as
|
|
21
|
+
import { default as W } from "./form/context/group/FormGroupContextProvider.mjs";
|
|
22
22
|
import { default as q } from "./form/context/group/useFormGroupChildIsMountedTracker.mjs";
|
|
23
23
|
import { default as J } from "./form/context/group/useFormGroupChildIsSubmittingTracker.mjs";
|
|
24
24
|
import { default as Q } from "./form/context/group/useFormGroupChildTracker.mjs";
|
|
@@ -34,20 +34,20 @@ export {
|
|
|
34
34
|
i as FlatFieldErrorsList,
|
|
35
35
|
E as FormErrorMessage,
|
|
36
36
|
C as FormErrorMessageByPath,
|
|
37
|
-
|
|
37
|
+
W as FormGroupContextProvider,
|
|
38
38
|
G as FormNonFieldErrorMarker,
|
|
39
|
-
|
|
39
|
+
c as FormNonFieldErrorMarkerHtmlAttribute,
|
|
40
40
|
mr as FormSubmitError,
|
|
41
41
|
A as FormWithProviders,
|
|
42
42
|
d as LazyDevTool,
|
|
43
43
|
e as RhfUtilsClientForZodContextProvider,
|
|
44
|
-
|
|
44
|
+
m as RhfUtilsZodForm,
|
|
45
45
|
b as RootErrorsListFromFlatFieldErrorsContext,
|
|
46
46
|
fr as getSubmitterButtonData,
|
|
47
47
|
x as useFlatFieldErrorsContext,
|
|
48
48
|
D as useForm,
|
|
49
|
-
|
|
50
|
-
|
|
49
|
+
U as useFormErrorsEffect,
|
|
50
|
+
v as useFormErrorsIfAny,
|
|
51
51
|
q as useFormGroupChildIsMountedTracker,
|
|
52
52
|
J as useFormGroupChildIsSubmittingTracker,
|
|
53
53
|
Q as useFormGroupChildTracker,
|
|
@@ -55,12 +55,12 @@ export {
|
|
|
55
55
|
_ as useFormGroupIsChildBusy,
|
|
56
56
|
rr as useFormGroupIsParentBusy,
|
|
57
57
|
er as useFormGroupParentTracker,
|
|
58
|
-
|
|
58
|
+
P as useFormHasOnlyOrphanFieldErrorsMemo,
|
|
59
59
|
dr as useFormOnSubmitSuccessful,
|
|
60
60
|
sr as useFormOrParentIsBusy,
|
|
61
61
|
N as useFormUtilsContext,
|
|
62
62
|
B as useOrphanFormErrorsMemo,
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
63
|
+
s as useRhfUtilsClientForZodContext,
|
|
64
|
+
f as useRhfUtilsZodForm,
|
|
65
|
+
S as useRootFormFieldErrorsMemo
|
|
66
66
|
};
|
package/dist/esm/form/Form.mjs
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { jsxs as F, jsx as
|
|
1
|
+
import { jsxs as F, jsx as c } from "react/jsx-runtime";
|
|
2
2
|
import "react";
|
|
3
3
|
import { useFormContext as _ } from "react-hook-form";
|
|
4
4
|
import j from "../client/config/useRhfUtilsClientConfigContext.mjs";
|
|
@@ -12,7 +12,7 @@ function q({
|
|
|
12
12
|
formRef: C,
|
|
13
13
|
//
|
|
14
14
|
onSubmit: d,
|
|
15
|
-
onSubmitError:
|
|
15
|
+
onSubmitError: o,
|
|
16
16
|
onSubmitInvalid: y,
|
|
17
17
|
Fields: h,
|
|
18
18
|
//
|
|
@@ -41,7 +41,7 @@ function q({
|
|
|
41
41
|
// if error is not FormSubmitError, consumer can provide global handler
|
|
42
42
|
(n = e == null ? void 0 : e.onSubmitError) == null ? void 0 : n.call(e, r)
|
|
43
43
|
);
|
|
44
|
-
m && P(l, m),
|
|
44
|
+
m && P(l, m), o == null || o(
|
|
45
45
|
r,
|
|
46
46
|
l,
|
|
47
47
|
a
|
|
@@ -49,13 +49,13 @@ function q({
|
|
|
49
49
|
}, u = {
|
|
50
50
|
formId: x,
|
|
51
51
|
formRef: C,
|
|
52
|
-
|
|
52
|
+
context: l,
|
|
53
53
|
options: t,
|
|
54
54
|
Controller: S
|
|
55
55
|
}, i = (r) => {
|
|
56
56
|
var m;
|
|
57
57
|
const a = (m = e == null ? void 0 : e.Children) == null ? void 0 : m[r];
|
|
58
|
-
return a && /* @__PURE__ */
|
|
58
|
+
return a && /* @__PURE__ */ c(a, { ...u });
|
|
59
59
|
};
|
|
60
60
|
return /* @__PURE__ */ F(
|
|
61
61
|
T,
|
|
@@ -71,7 +71,7 @@ function q({
|
|
|
71
71
|
onSubmit: b,
|
|
72
72
|
children: [
|
|
73
73
|
i("top"),
|
|
74
|
-
(t == null ? void 0 : t.devTool) !== "disabled" && /* @__PURE__ */
|
|
74
|
+
(t == null ? void 0 : t.devTool) !== "disabled" && /* @__PURE__ */ c(
|
|
75
75
|
D,
|
|
76
76
|
{
|
|
77
77
|
placement: "top-right",
|
|
@@ -79,7 +79,7 @@ function q({
|
|
|
79
79
|
...t == null ? void 0 : t.devTool
|
|
80
80
|
}
|
|
81
81
|
),
|
|
82
|
-
h && /* @__PURE__ */
|
|
82
|
+
h && /* @__PURE__ */ c(h, { ...u }),
|
|
83
83
|
f,
|
|
84
84
|
i("bottom")
|
|
85
85
|
]
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { UseFormProps } from '../../form/useForm';
|
|
2
|
+
import { ZodTypeFieldValues } from './createRhfUtilsClientForZod';
|
|
3
|
+
|
|
4
|
+
type Props<TSchema extends ZodTypeFieldValues> = {
|
|
5
|
+
schema: TSchema;
|
|
6
|
+
} & Omit<UseFormProps<TSchema['_input'], TSchema['_output']>, 'config'>;
|
|
7
|
+
declare function RhfUtilsZodForm<TSchema extends ZodTypeFieldValues>({ schema, ...props }: Props<TSchema>): import("react/jsx-runtime").JSX.Element;
|
|
8
|
+
export default RhfUtilsZodForm;
|
package/dist/types/exports.d.ts
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
export type { Register } from './register';
|
|
2
2
|
export type { RhfUtilsClientConfig } from './client/config/RhfUtilsClientConfig';
|
|
3
3
|
export { default as RhfUtilsClientForZodContextProvider } from './client/zod/context/RhfUtilsClientForZodContextProvider';
|
|
4
|
-
export { default as RhfUtilsZodFormWithProviders } from './client/zod/context/RhfUtilsZodFormWithProviders';
|
|
5
4
|
export { default as useRhfUtilsClientForZodContext } from './client/zod/context/useRhfUtilsClientForZodContext';
|
|
6
5
|
export { default as useRhfUtilsZodForm } from './client/zod/context/useRhfUtilsZodForm';
|
|
6
|
+
export { default as RhfUtilsZodForm } from './client/zod/RhfUtilsZodForm';
|
|
7
7
|
export type { UseFormFieldsZodProps } from './client/zod/UseFormFieldsZodProps';
|
|
8
8
|
export { default as LazyDevTool } from './devtool/LazyDevTool';
|
|
9
9
|
export { default as useFlatFieldErrorsContext } from './errors/flat/context/useFlatFieldErrorsContext';
|
|
@@ -10,7 +10,7 @@ import { UseFormOptions } from './useFormOptions';
|
|
|
10
10
|
export type UseFormFieldsProps<TFieldValues extends SafeFieldValues = SafeFieldValues, TTransformedValues extends SafeFieldValues = SafeFieldValues> = {
|
|
11
11
|
formId: string;
|
|
12
12
|
formRef: React.RefObject<HTMLFormElement>;
|
|
13
|
-
|
|
13
|
+
context: RhfUseFormReturn<TFieldValues, unknown, TTransformedValues>;
|
|
14
14
|
options?: UseFormOptions;
|
|
15
15
|
Controller: typeof _Controller<TFieldValues>;
|
|
16
16
|
};
|
package/package.json
CHANGED
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
import { jsx as i } from "react/jsx-runtime";
|
|
2
|
-
import e from "./useRhfUtilsClientForZodContext.mjs";
|
|
3
|
-
function f({
|
|
4
|
-
schema: o,
|
|
5
|
-
...t
|
|
6
|
-
}) {
|
|
7
|
-
const r = e();
|
|
8
|
-
return /* @__PURE__ */ i(r.FormWithProviders, { schema: o, ...t });
|
|
9
|
-
}
|
|
10
|
-
export {
|
|
11
|
-
f as default
|
|
12
|
-
};
|