@paragrav/rhf-utils 0.0.127 → 0.0.128
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
CHANGED
|
@@ -50,7 +50,7 @@ export const rhfUtilsClientConfig: RhfUtilsClientConfig = {
|
|
|
50
50
|
formRef, // ref
|
|
51
51
|
context, // rhf UseFormReturn
|
|
52
52
|
options, // RhfUtilsFormOptions (with any custom props)
|
|
53
|
-
Controller, // strictly-typed controller
|
|
53
|
+
Controller, // strictly-typed rhf controller
|
|
54
54
|
FormSubmitError, // strictly-typed error class
|
|
55
55
|
children, // RhfUtilsZodForm's Children instance
|
|
56
56
|
},
|
|
@@ -108,7 +108,7 @@ export const rhfUtilsClientConfig: RhfUtilsClientConfig = {
|
|
|
108
108
|
|
|
109
109
|
## Provider
|
|
110
110
|
|
|
111
|
-
And add the context provider to your stack:
|
|
111
|
+
And add the context provider to your global provider stack:
|
|
112
112
|
|
|
113
113
|
```tsx
|
|
114
114
|
<RhfUtilsClientForZodContextProvider config={rhfUtilsClientConfig}>
|
|
@@ -150,7 +150,7 @@ Currently, only `zod` is supported.
|
|
|
150
150
|
formRef, // ref
|
|
151
151
|
context, // rhf UseFormReturn
|
|
152
152
|
options, // RhfUtilsFormOptions
|
|
153
|
-
Controller, // strictly-typed controller
|
|
153
|
+
Controller, // strictly-typed rhf controller
|
|
154
154
|
FormSubmitError, // strictly-typed error class
|
|
155
155
|
}) => (
|
|
156
156
|
<>
|
|
@@ -1,20 +1,21 @@
|
|
|
1
|
-
import { jsx as
|
|
2
|
-
import
|
|
1
|
+
import { jsx as m } from "react/jsx-runtime";
|
|
2
|
+
import "react";
|
|
3
|
+
import n from "../form/FormWithProviders.mjs";
|
|
3
4
|
import l from "../form/useRhfUtilsForm.mjs";
|
|
4
5
|
import { mergeRhfUtilsClientConfigDefaultsWithUseRhfUtilsFormProps as F } from "./utils.mjs";
|
|
5
|
-
const
|
|
6
|
-
const
|
|
6
|
+
const c = (r) => (o) => {
|
|
7
|
+
const e = f(r, o);
|
|
7
8
|
return {
|
|
8
|
-
useForm: (
|
|
9
|
-
const
|
|
9
|
+
useForm: (s, t) => {
|
|
10
|
+
const i = e(s, t);
|
|
10
11
|
return {
|
|
11
|
-
...l(
|
|
12
|
-
FormWithProviders: () => /* @__PURE__ */ n
|
|
12
|
+
...l(i),
|
|
13
|
+
FormWithProviders: () => /* @__PURE__ */ m(n, { ...i })
|
|
13
14
|
};
|
|
14
15
|
},
|
|
15
16
|
FormWithProviders: u(r, o)
|
|
16
17
|
};
|
|
17
|
-
}, f = (r, o) => function(
|
|
18
|
+
}, f = (r, o) => function(s, t) {
|
|
18
19
|
return {
|
|
19
20
|
...t,
|
|
20
21
|
...F(
|
|
@@ -22,25 +23,27 @@ const p = (r) => (o) => {
|
|
|
22
23
|
t,
|
|
23
24
|
{
|
|
24
25
|
rhf: {
|
|
25
|
-
resolver: r(
|
|
26
|
+
resolver: r(s)
|
|
26
27
|
}
|
|
27
28
|
}
|
|
28
29
|
)
|
|
29
30
|
};
|
|
30
|
-
}, u = (r, o) =>
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
m
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
31
|
+
}, u = (r, o) => {
|
|
32
|
+
const e = f(r, o);
|
|
33
|
+
return function({
|
|
34
|
+
schema: t,
|
|
35
|
+
children: i,
|
|
36
|
+
...h
|
|
37
|
+
}) {
|
|
38
|
+
return /* @__PURE__ */ m(
|
|
39
|
+
n,
|
|
40
|
+
{
|
|
41
|
+
...e(t, h),
|
|
42
|
+
children: i
|
|
43
|
+
}
|
|
44
|
+
);
|
|
45
|
+
};
|
|
43
46
|
};
|
|
44
47
|
export {
|
|
45
|
-
|
|
48
|
+
c as createRhfUtilsClient
|
|
46
49
|
};
|
|
@@ -1,23 +1,28 @@
|
|
|
1
|
-
const i = (l, ...t) =>
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
1
|
+
const i = (l, ...t) => (
|
|
2
|
+
// sequentially merge each set of props into defaults
|
|
3
|
+
t.reduce(
|
|
4
|
+
(s, e) => {
|
|
5
|
+
var f, o;
|
|
6
|
+
return {
|
|
7
|
+
rhf: {
|
|
8
|
+
...s == null ? void 0 : s.rhf,
|
|
9
|
+
...e.rhf
|
|
10
|
+
},
|
|
11
|
+
utils: {
|
|
12
|
+
...s == null ? void 0 : s.utils,
|
|
13
|
+
...e.utils
|
|
14
|
+
},
|
|
15
|
+
form: {
|
|
16
|
+
...s == null ? void 0 : s.form,
|
|
17
|
+
...e.form,
|
|
18
|
+
className: [(f = s == null ? void 0 : s.form) == null ? void 0 : f.className, (o = e.form) == null ? void 0 : o.className].filter(Boolean).join(" ")
|
|
19
|
+
// stringify
|
|
20
|
+
}
|
|
21
|
+
};
|
|
22
|
+
},
|
|
23
|
+
// start with defaults
|
|
24
|
+
l
|
|
25
|
+
)
|
|
21
26
|
);
|
|
22
27
|
export {
|
|
23
28
|
i as mergeRhfUtilsClientConfigDefaultsWithUseRhfUtilsFormProps
|
|
@@ -1,9 +1,8 @@
|
|
|
1
|
-
import { jsx as
|
|
2
|
-
import {
|
|
3
|
-
function
|
|
4
|
-
|
|
5
|
-
return /* @__PURE__ */ t(e, { control: r, ...o });
|
|
1
|
+
import { jsx as o } from "react/jsx-runtime";
|
|
2
|
+
import { Controller as t } from "react-hook-form";
|
|
3
|
+
function n(r) {
|
|
4
|
+
return /* @__PURE__ */ o(t, { ...r });
|
|
6
5
|
}
|
|
7
6
|
export {
|
|
8
|
-
|
|
7
|
+
n as default
|
|
9
8
|
};
|
|
@@ -1,23 +1,36 @@
|
|
|
1
|
-
import { useFormContext as
|
|
1
|
+
import { useFormContext as n } from "react-hook-form";
|
|
2
2
|
import i from "./useFormOnSubmitted.mjs";
|
|
3
|
-
const
|
|
4
|
-
const {
|
|
5
|
-
i((
|
|
6
|
-
var
|
|
3
|
+
const p = (e) => {
|
|
4
|
+
const { getValues: s, reset: o } = n();
|
|
5
|
+
i((m) => {
|
|
6
|
+
var u;
|
|
7
7
|
if (!e) return;
|
|
8
|
-
const t = (
|
|
8
|
+
const t = (u = e[m ? "success" : "error"]) == null ? void 0 : u.values;
|
|
9
9
|
if (!t) return;
|
|
10
|
-
const
|
|
11
|
-
|
|
10
|
+
const r = t === "current", c = r ? s() : void 0;
|
|
11
|
+
o(c, {
|
|
12
12
|
// keep submit stuff for tracking relevant state (e.g., `useFormOnSubmitSuccessful`)
|
|
13
13
|
keepIsSubmitSuccessful: !0,
|
|
14
14
|
keepIsSubmitted: !0,
|
|
15
15
|
keepSubmitCount: !0,
|
|
16
|
+
/**
|
|
17
|
+
* This is necessary when setting default values to current values (lest form stop updating).
|
|
18
|
+
*
|
|
19
|
+
* Technically, we are keeping values and resetting default values to same values.
|
|
20
|
+
*
|
|
21
|
+
* Steps to repro:
|
|
22
|
+
* - RhfUtilsClientConfig with resetOnSubmitted set to success values to current
|
|
23
|
+
* - remove `keepValues` prop from reset
|
|
24
|
+
* - create valid form, submit
|
|
25
|
+
* - form values should be unchanged
|
|
26
|
+
* - unexpectedly: can no longer type into input
|
|
27
|
+
*/
|
|
28
|
+
keepValues: r,
|
|
16
29
|
// keep errors in the case of unsuccessful submit
|
|
17
30
|
keepErrors: !0
|
|
18
31
|
});
|
|
19
32
|
});
|
|
20
33
|
};
|
|
21
34
|
export {
|
|
22
|
-
|
|
35
|
+
p as default
|
|
23
36
|
};
|