@paragrav/rhf-utils 0.0.116 → 0.0.117
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 +21 -23
- package/dist/esm/client/config/useRhfUtilsClientConfigContext.mjs +7 -8
- package/dist/esm/client/zod/context/useRhfUtilsClientForZodContext.mjs +7 -4
- package/dist/esm/errors/flat/context/FlatFieldErrorsContextProvider.mjs +13 -11
- package/dist/esm/errors/flat/context/useFlatFieldErrorsContext.mjs +6 -3
- package/dist/esm/errors/flat/context/useFlatFieldErrorsContextOutput.mjs +19 -20
- package/dist/esm/errors/getRefdFromFlatFieldErrors.mjs +8 -0
- package/dist/esm/errors/isFlatFieldErrorEntryRefd.mjs +5 -0
- package/dist/esm/form/Form.mjs +53 -57
- package/dist/esm/form/_FormBase.mjs +8 -15
- package/dist/esm/form/context/group/index.mjs +9 -9
- package/dist/esm/form/context/utils/RhfUtilsContextProvider.mjs +12 -15
- package/dist/esm/form/context/utils/useRhfUtilsContext.mjs +3 -3
- package/dist/esm/utils/createContext.mjs +10 -6
- package/dist/types/client/config/RhfUtilsClientConfig.d.ts +2 -6
- package/dist/types/client/config/useRhfUtilsClientConfigContext.d.ts +1 -1
- package/dist/types/client/zod/context/useRhfUtilsClientForZodContext.d.ts +1 -1
- package/dist/types/errors/flat/context/useFlatFieldErrorsContext.d.ts +2 -1
- package/dist/types/errors/flat/context/useFlatFieldErrorsContextOutput.d.ts +2 -2
- package/dist/types/errors/getRefdFromFlatFieldErrors.d.ts +2 -0
- package/dist/types/errors/isFlatFieldErrorEntryRefd.d.ts +1 -1
- package/dist/types/form/RhfUtilsFormOptions.d.ts +8 -4
- package/dist/types/form/_FormBase.d.ts +2 -4
- package/dist/types/form/context/group/index.d.ts +1 -1
- package/dist/types/submit/useResetFormOnSubmitSuccessful.d.ts +2 -2
- package/dist/types/utils/createContext.d.ts +6 -2
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -14,8 +14,6 @@ To configure, create a file `config.tsx` with desired configuration settings. Th
|
|
|
14
14
|
|
|
15
15
|
```tsx
|
|
16
16
|
export const rhfUtilsClientConfig: RhfUtilsClientConfig = {
|
|
17
|
-
isDevelopment: import.meta.env.DEV,
|
|
18
|
-
|
|
19
17
|
// defaults -- overridable per form instance
|
|
20
18
|
defaults: {
|
|
21
19
|
// globally relevant subset of RHF's `UseFormProps` options
|
|
@@ -25,8 +23,8 @@ export const rhfUtilsClientConfig: RhfUtilsClientConfig = {
|
|
|
25
23
|
|
|
26
24
|
// RhfUtilsFormOptions (see further below)
|
|
27
25
|
utils: {
|
|
28
|
-
// enable dev tool
|
|
29
|
-
devTool:
|
|
26
|
+
// enable dev tool on dev env
|
|
27
|
+
devTool: import.meta.env.DEV,
|
|
30
28
|
},
|
|
31
29
|
},
|
|
32
30
|
|
|
@@ -53,8 +51,8 @@ export const rhfUtilsClientConfig: RhfUtilsClientConfig = {
|
|
|
53
51
|
formRef, // ref
|
|
54
52
|
context, // rhf UseFormReturn
|
|
55
53
|
options, // RhfUtilsFormOptions
|
|
56
|
-
Controller, //
|
|
57
|
-
FormSubmitError, //
|
|
54
|
+
Controller, // strictly-typed controller
|
|
55
|
+
FormSubmitError, // strictly-typed error class
|
|
58
56
|
},
|
|
59
57
|
) => {
|
|
60
58
|
// navigation blocker (using custom option)
|
|
@@ -74,12 +72,12 @@ export const rhfUtilsClientConfig: RhfUtilsClientConfig = {
|
|
|
74
72
|
errors: {
|
|
75
73
|
output: {
|
|
76
74
|
// callback to determine when to output form context errors to console ("debug" or "error")
|
|
77
|
-
console: ({
|
|
75
|
+
console: ({ hasOrphans }) =>
|
|
78
76
|
(hasOrphans && { type: 'error' }) || // report all orphan errors
|
|
79
|
-
(
|
|
77
|
+
(import.meta.env.DEV && { type: 'debug' }), // facilitate debugging on dev
|
|
80
78
|
|
|
81
79
|
// callback to determine when to throw an error based on context
|
|
82
|
-
throw: ({
|
|
80
|
+
throw: ({ hasOrphans }) => import.meta.env.DEV && hasOrphans,
|
|
83
81
|
},
|
|
84
82
|
},
|
|
85
83
|
};
|
|
@@ -108,7 +106,7 @@ Currently, only `zod` is supported.
|
|
|
108
106
|
// submit handler
|
|
109
107
|
onSubmit={async (
|
|
110
108
|
data, // schema output
|
|
111
|
-
context, // UseRhfUtilsFormOnSubmitContext (form id, form ref, context (rhf), utils options,
|
|
109
|
+
context, // UseRhfUtilsFormOnSubmitContext (form id, form ref, context (rhf), utils options, strictly-typed FormSubmitError class)
|
|
112
110
|
event, // SubmitEvent
|
|
113
111
|
) => {
|
|
114
112
|
await authLoginService(data);
|
|
@@ -129,12 +127,12 @@ Currently, only `zod` is supported.
|
|
|
129
127
|
formRef, // ref
|
|
130
128
|
context, // rhf UseFormReturn
|
|
131
129
|
options, // RhfUtilsFormOptions
|
|
132
|
-
Controller, //
|
|
133
|
-
FormSubmitError, //
|
|
130
|
+
Controller, // strictly-typed controller
|
|
131
|
+
FormSubmitError, // strictly-typed error class
|
|
134
132
|
}) => (
|
|
135
133
|
<>
|
|
136
134
|
<Controller
|
|
137
|
-
name="email" //
|
|
135
|
+
name="email" // strictly-typed field name
|
|
138
136
|
render={({ field, formState: { isSubmitting } }) => (
|
|
139
137
|
<label>
|
|
140
138
|
Email
|
|
@@ -161,7 +159,7 @@ function Children({...}: RhfUtilsUseFormChildrenZodProps<typeof schema>) { }
|
|
|
161
159
|
|
|
162
160
|
## `FormSubmitError`
|
|
163
161
|
|
|
164
|
-
This is an `Error`-based class you can use to throw a structured error in your submit handler. It is
|
|
162
|
+
This is an `Error`-based class you can use to throw a structured error in your submit handler. It is strictly-typed, so it only allows field names in schema and `root`/`root.{string}` keys.
|
|
165
163
|
|
|
166
164
|
It uses `FormSubmitErrors` shape, which is a flat (dot notation) equivalent of RHF's `FieldErrors`.
|
|
167
165
|
|
|
@@ -192,8 +190,7 @@ These options can be set globally and/or per form.
|
|
|
192
190
|
```ts
|
|
193
191
|
type RhfUtilsFormOptions = {
|
|
194
192
|
/**
|
|
195
|
-
*
|
|
196
|
-
* (Defaults merged with individual class names.)
|
|
193
|
+
* Style via your own classes.
|
|
197
194
|
*/
|
|
198
195
|
classNames?: string[];
|
|
199
196
|
|
|
@@ -207,11 +204,12 @@ type RhfUtilsFormOptions = {
|
|
|
207
204
|
stopSubmitPropagation?: boolean;
|
|
208
205
|
|
|
209
206
|
/** Reset form after successful submit. */
|
|
210
|
-
resetFormAfterSubmitSuccessful?:
|
|
211
|
-
typeof useResetFormAfterSubmitSuccessful
|
|
212
|
-
>[0];
|
|
207
|
+
resetFormAfterSubmitSuccessful?: UseResetFormAfterSubmitSuccessfulOptions;
|
|
213
208
|
|
|
214
|
-
/**
|
|
209
|
+
/**
|
|
210
|
+
* Control dev tool options.
|
|
211
|
+
* (Lazy-loaded when truthy value supplied.)
|
|
212
|
+
*/
|
|
215
213
|
devTool?: true | Pick<DevtoolUIProps, 'placement' | 'styles'>;
|
|
216
214
|
};
|
|
217
215
|
```
|
|
@@ -261,10 +259,10 @@ Alternatively, you can use `FormErrorMessageByPath` to display error message to
|
|
|
261
259
|
|
|
262
260
|
Example use case: Field array with minimum items. (When there are no items, the error is not associated with a field and is displayed separately.)
|
|
263
261
|
|
|
264
|
-
Orphans are
|
|
262
|
+
Orphans are exposed in a few places.
|
|
265
263
|
|
|
266
|
-
- In errors outputted via console. (
|
|
267
|
-
- And `useFlatFieldErrorsContext()` hook, which returns an object with
|
|
264
|
+
- In errors outputted via console. (Configurable via `RhfUtilsClientConfig['errors']['output']`.)
|
|
265
|
+
- And `useFlatFieldErrorsContext()` hook, which returns an object with errors grouped by `all`, `fields`, `root`, and `orphans`.
|
|
268
266
|
- Boolean value from `useFlatFieldErrorsContextHasOnlyOrphans`.
|
|
269
267
|
|
|
270
268
|
`FlatFieldErrors` is a flattened, simplified version of RHF's `FieldErrors`. Keys represent field paths flattened to dot notation.
|
|
@@ -1,10 +1,9 @@
|
|
|
1
|
-
import
|
|
2
|
-
const
|
|
3
|
-
o,
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
] = t();
|
|
1
|
+
import e from "../../utils/createContext.mjs";
|
|
2
|
+
const {
|
|
3
|
+
Provider: o,
|
|
4
|
+
useMaybe: i
|
|
5
|
+
} = e();
|
|
7
6
|
export {
|
|
8
|
-
|
|
9
|
-
|
|
7
|
+
o as _RhfUtilsClientConfigContextProvider,
|
|
8
|
+
i as default
|
|
10
9
|
};
|
|
@@ -1,6 +1,9 @@
|
|
|
1
|
-
import
|
|
2
|
-
const
|
|
1
|
+
import e from "../../../utils/createContext.mjs";
|
|
2
|
+
const {
|
|
3
|
+
Provider: o,
|
|
4
|
+
useRequired: r
|
|
5
|
+
} = e();
|
|
3
6
|
export {
|
|
4
|
-
|
|
5
|
-
|
|
7
|
+
o as _RhfUtilsClientForZodContextProvider,
|
|
8
|
+
r as default
|
|
6
9
|
};
|
|
@@ -1,21 +1,23 @@
|
|
|
1
|
-
import { jsx as
|
|
1
|
+
import { jsx as s } from "react/jsx-runtime";
|
|
2
2
|
import "react";
|
|
3
3
|
import { useFormState as i } from "react-hook-form";
|
|
4
|
-
import l from "../../
|
|
5
|
-
import F from "../../
|
|
6
|
-
import a from "
|
|
7
|
-
import
|
|
8
|
-
|
|
4
|
+
import l from "../../getRefdFromFlatFieldErrors.mjs";
|
|
5
|
+
import F from "../../orphan/getOrphansFromFlatFieldErrors.mjs";
|
|
6
|
+
import a from "../../root/getRootsFromFlatFieldErrors.mjs";
|
|
7
|
+
import n from "../getFlatFieldErrors.mjs";
|
|
8
|
+
import { _FormErrorsFlatContextProvider as p } from "./useFlatFieldErrorsContext.mjs";
|
|
9
|
+
const h = ({
|
|
9
10
|
formRef: o,
|
|
10
11
|
children: t
|
|
11
12
|
}) => {
|
|
12
|
-
const { errors: e } = i(), r =
|
|
13
|
+
const { errors: e } = i(), r = n(e), m = {
|
|
13
14
|
all: r,
|
|
14
|
-
|
|
15
|
-
|
|
15
|
+
fields: l(r),
|
|
16
|
+
roots: a(r),
|
|
17
|
+
orphans: o.current ? F(r, o.current) : {}
|
|
16
18
|
};
|
|
17
|
-
return /* @__PURE__ */
|
|
19
|
+
return /* @__PURE__ */ s(p, { value: m, children: t });
|
|
18
20
|
};
|
|
19
21
|
export {
|
|
20
|
-
|
|
22
|
+
h as default
|
|
21
23
|
};
|
|
@@ -1,6 +1,9 @@
|
|
|
1
|
-
import
|
|
2
|
-
const
|
|
1
|
+
import r from "../../../utils/createContext.mjs";
|
|
2
|
+
const {
|
|
3
|
+
Provider: o,
|
|
4
|
+
useRequired: e
|
|
5
|
+
} = r(), s = e;
|
|
3
6
|
export {
|
|
4
|
-
|
|
7
|
+
o as _FormErrorsFlatContextProvider,
|
|
5
8
|
s as default
|
|
6
9
|
};
|
|
@@ -1,29 +1,28 @@
|
|
|
1
1
|
import h from "react";
|
|
2
2
|
import { useFormContext as E } from "react-hook-form";
|
|
3
|
-
import
|
|
3
|
+
import l from "../../../utils/isEmptyObject.mjs";
|
|
4
4
|
import F from "../../output/consoleErrors.mjs";
|
|
5
5
|
import x from "./useFlatFieldErrorsContext.mjs";
|
|
6
|
-
const
|
|
7
|
-
const
|
|
6
|
+
const n = (r) => {
|
|
7
|
+
const u = E(), t = x();
|
|
8
8
|
h.useEffect(() => {
|
|
9
|
-
var
|
|
10
|
-
if (
|
|
9
|
+
var m, a;
|
|
10
|
+
if (l(t.all))
|
|
11
11
|
return;
|
|
12
|
-
const
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
s.type
|
|
12
|
+
const o = {
|
|
13
|
+
hasOrphans: !l(t.orphans)
|
|
14
|
+
}, e = (m = r == null ? void 0 : r.console) == null ? void 0 : m.call(r, o);
|
|
15
|
+
e && F(
|
|
16
|
+
e.message ?? p,
|
|
17
|
+
u.getValues(),
|
|
18
|
+
t,
|
|
19
|
+
e.type
|
|
21
20
|
);
|
|
22
|
-
const
|
|
23
|
-
if (
|
|
24
|
-
throw new Error(typeof
|
|
25
|
-
}, [
|
|
26
|
-
},
|
|
21
|
+
const s = (a = r == null ? void 0 : r.throw) == null ? void 0 : a.call(r, o);
|
|
22
|
+
if (s)
|
|
23
|
+
throw new Error(typeof s == "string" ? s : p);
|
|
24
|
+
}, [t]);
|
|
25
|
+
}, p = "Form errors";
|
|
27
26
|
export {
|
|
28
|
-
|
|
27
|
+
n as default
|
|
29
28
|
};
|
package/dist/esm/form/Form.mjs
CHANGED
|
@@ -1,98 +1,94 @@
|
|
|
1
|
-
import { jsxs as
|
|
1
|
+
import { jsxs as _, jsx as d } from "react/jsx-runtime";
|
|
2
2
|
import "react";
|
|
3
|
-
import { useFormContext as
|
|
4
|
-
import
|
|
5
|
-
import
|
|
6
|
-
import { FormSubmitError as
|
|
7
|
-
import
|
|
8
|
-
import
|
|
9
|
-
import
|
|
3
|
+
import { useFormContext as v } from "react-hook-form";
|
|
4
|
+
import N from "../client/config/useRhfUtilsClientConfigContext.mjs";
|
|
5
|
+
import P from "../devtool/LazyDevTool.mjs";
|
|
6
|
+
import { FormSubmitError as x } from "../submit/error/FormSubmitError.mjs";
|
|
7
|
+
import S from "../submit/error/setCtxErrorsByFormSubmitErrors.mjs";
|
|
8
|
+
import w from "./_Controller.mjs";
|
|
9
|
+
import E from "./_FormBase.mjs";
|
|
10
10
|
function A({
|
|
11
11
|
formId: s,
|
|
12
|
-
formRef:
|
|
12
|
+
formRef: m,
|
|
13
13
|
//
|
|
14
14
|
onSubmit: c,
|
|
15
|
-
onSubmitError:
|
|
16
|
-
onSubmitInvalid:
|
|
17
|
-
Children:
|
|
15
|
+
onSubmitError: C,
|
|
16
|
+
onSubmitInvalid: b,
|
|
17
|
+
Children: h,
|
|
18
18
|
//
|
|
19
|
-
form:
|
|
19
|
+
form: p,
|
|
20
20
|
utils: o,
|
|
21
21
|
//
|
|
22
|
-
children:
|
|
22
|
+
children: i
|
|
23
23
|
}) {
|
|
24
|
-
const n =
|
|
25
|
-
o != null && o.stopSubmitPropagation &&
|
|
24
|
+
const n = v(), r = N(), j = async (t) => {
|
|
25
|
+
o != null && o.stopSubmitPropagation && t.stopPropagation();
|
|
26
26
|
try {
|
|
27
|
-
await n.handleSubmit(
|
|
28
|
-
} catch (
|
|
29
|
-
|
|
27
|
+
await n.handleSubmit(B, b)(t);
|
|
28
|
+
} catch (e) {
|
|
29
|
+
T(e, t);
|
|
30
30
|
}
|
|
31
|
-
},
|
|
32
|
-
|
|
31
|
+
}, B = (t, e) => c == null ? void 0 : c(
|
|
32
|
+
t,
|
|
33
33
|
{
|
|
34
34
|
formId: s,
|
|
35
|
-
formRef:
|
|
35
|
+
formRef: m,
|
|
36
36
|
context: n,
|
|
37
37
|
utils: o,
|
|
38
|
-
FormSubmitError:
|
|
38
|
+
FormSubmitError: x
|
|
39
39
|
},
|
|
40
|
-
|
|
41
|
-
),
|
|
42
|
-
var
|
|
43
|
-
const a =
|
|
40
|
+
e
|
|
41
|
+
), T = (t, e) => {
|
|
42
|
+
var F;
|
|
43
|
+
const a = t instanceof x ? (
|
|
44
44
|
// consumer can manually throw FormSubmitError (e.g., manual validation)
|
|
45
|
-
|
|
45
|
+
t.errors
|
|
46
46
|
) : (
|
|
47
47
|
// if error is not FormSubmitError, consumer can provide global handler
|
|
48
|
-
(
|
|
48
|
+
(F = r == null ? void 0 : r.onSubmitUnknownError) == null ? void 0 : F.call(r, t)
|
|
49
49
|
);
|
|
50
|
-
a &&
|
|
51
|
-
|
|
50
|
+
a && S(n, a), C == null || C(
|
|
51
|
+
t,
|
|
52
52
|
{
|
|
53
53
|
formId: s,
|
|
54
|
-
formRef:
|
|
54
|
+
formRef: m,
|
|
55
55
|
context: n,
|
|
56
56
|
utils: o
|
|
57
57
|
},
|
|
58
|
-
|
|
58
|
+
e
|
|
59
59
|
);
|
|
60
|
-
},
|
|
60
|
+
}, l = {
|
|
61
61
|
formId: s,
|
|
62
|
-
formRef:
|
|
62
|
+
formRef: m,
|
|
63
63
|
context: n,
|
|
64
64
|
utils: o,
|
|
65
|
-
Controller:
|
|
66
|
-
FormSubmitError:
|
|
67
|
-
},
|
|
65
|
+
Controller: w,
|
|
66
|
+
FormSubmitError: x
|
|
67
|
+
}, y = (t) => {
|
|
68
68
|
var a;
|
|
69
|
-
const
|
|
70
|
-
return
|
|
69
|
+
const e = (a = r == null ? void 0 : r.Children) == null ? void 0 : a[t];
|
|
70
|
+
return e && /* @__PURE__ */ d(e, { ...l });
|
|
71
71
|
};
|
|
72
|
-
return /* @__PURE__ */
|
|
73
|
-
|
|
72
|
+
return /* @__PURE__ */ _(
|
|
73
|
+
E,
|
|
74
74
|
{
|
|
75
75
|
noValidate: !0,
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
...m,
|
|
82
|
-
className: [o == null ? void 0 : o.classNames, m == null ? void 0 : m.className].filter(Boolean).join(" "),
|
|
83
|
-
onSubmit: F,
|
|
76
|
+
Component: r == null ? void 0 : r.FormComponent,
|
|
77
|
+
formRef: m,
|
|
78
|
+
...p,
|
|
79
|
+
className: [o == null ? void 0 : o.classNames, p == null ? void 0 : p.className].filter(Boolean).join(" "),
|
|
80
|
+
onSubmit: j,
|
|
84
81
|
children: [
|
|
85
|
-
|
|
86
|
-
(o == null ? void 0 : o.devTool) && /* @__PURE__ */
|
|
87
|
-
|
|
82
|
+
y("top"),
|
|
83
|
+
(o == null ? void 0 : o.devTool) && /* @__PURE__ */ d(
|
|
84
|
+
P,
|
|
88
85
|
{
|
|
89
|
-
isDevelopment: t == null ? void 0 : t.isDevelopment,
|
|
90
86
|
props: typeof o.devTool == "object" ? o.devTool : void 0
|
|
91
87
|
}
|
|
92
88
|
),
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
89
|
+
h && /* @__PURE__ */ d(h, { ...l }),
|
|
90
|
+
i,
|
|
91
|
+
y("bottom")
|
|
96
92
|
]
|
|
97
93
|
}
|
|
98
94
|
);
|
|
@@ -1,18 +1,11 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { jsx as m } from "react/jsx-runtime";
|
|
2
2
|
import "react";
|
|
3
|
-
const
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
}) => {
|
|
10
|
-
const n = (e == null ? void 0 : e.FormComponent) ?? "form";
|
|
11
|
-
return /* @__PURE__ */ p(n, { role: "form", ...m, ref: t, children: [
|
|
12
|
-
r && /* @__PURE__ */ s("input", { type: "hidden", name: "anticsrftoken", value: r }),
|
|
13
|
-
o
|
|
14
|
-
] });
|
|
15
|
-
};
|
|
3
|
+
const s = ({
|
|
4
|
+
formRef: o,
|
|
5
|
+
Component: r,
|
|
6
|
+
children: t,
|
|
7
|
+
...e
|
|
8
|
+
}) => /* @__PURE__ */ m(r ?? "form", { role: "form", ...e, ref: o, children: t });
|
|
16
9
|
export {
|
|
17
|
-
|
|
10
|
+
s as default
|
|
18
11
|
};
|
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
import
|
|
2
|
-
const
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
1
|
+
import e from "../../../utils/createContext.mjs";
|
|
2
|
+
const {
|
|
3
|
+
Provider: r,
|
|
4
|
+
useRequired: t,
|
|
5
|
+
useMaybe: u
|
|
6
|
+
} = e();
|
|
7
7
|
export {
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
8
|
+
r as _FormGroupContextProvider,
|
|
9
|
+
t as _useFormGroupContext,
|
|
10
|
+
u as _useFormGroupContextMaybe
|
|
11
11
|
};
|
|
@@ -1,33 +1,30 @@
|
|
|
1
|
-
import { jsx as
|
|
1
|
+
import { jsx as l } from "react/jsx-runtime";
|
|
2
2
|
import C from "../../../client/config/useRhfUtilsClientConfigContext.mjs";
|
|
3
3
|
import F from "../../../errors/flat/context/useFlatFieldErrorsContextOutput.mjs";
|
|
4
4
|
import x from "../../../submit/useFormOnSubmitSuccessfulAndReset.mjs";
|
|
5
5
|
import O from "../../../submit/useResetFormOnSubmitError.mjs";
|
|
6
6
|
import b from "../../../submit/useResetFormOnSubmitSuccessful.mjs";
|
|
7
7
|
import h from "../../../submit/useSubmitFormOnChange.mjs";
|
|
8
|
-
import { _RhfUtilsContextProvider as
|
|
9
|
-
const
|
|
10
|
-
formId:
|
|
8
|
+
import { _RhfUtilsContextProvider as d } from "./useRhfUtilsContext.mjs";
|
|
9
|
+
const M = ({
|
|
10
|
+
formId: a,
|
|
11
11
|
formRef: t,
|
|
12
|
-
onSubmitSuccessfulAndReset:
|
|
12
|
+
onSubmitSuccessfulAndReset: e,
|
|
13
13
|
options: r,
|
|
14
|
-
children:
|
|
14
|
+
children: f
|
|
15
15
|
}) => {
|
|
16
16
|
var u;
|
|
17
|
-
const
|
|
18
|
-
return F({
|
|
19
|
-
...(u = e == null ? void 0 : e.errors) == null ? void 0 : u.output,
|
|
20
|
-
isDevelopment: e == null ? void 0 : e.isDevelopment
|
|
21
|
-
}), h(t, {
|
|
17
|
+
const m = C();
|
|
18
|
+
return F((u = m == null ? void 0 : m.errors) == null ? void 0 : u.output), h(t, {
|
|
22
19
|
disabled: !(r != null && r.submitOnChange)
|
|
23
20
|
}), O({
|
|
24
21
|
disabled: !(r != null && r.resetValuesOnSubmitError)
|
|
25
22
|
}), b(
|
|
26
|
-
(r == null ? void 0 : r.resetFormAfterSubmitSuccessful) || !!
|
|
23
|
+
(r == null ? void 0 : r.resetFormAfterSubmitSuccessful) || !!e
|
|
27
24
|
), x(() => {
|
|
28
|
-
|
|
29
|
-
}), /* @__PURE__ */
|
|
25
|
+
e == null || e();
|
|
26
|
+
}), /* @__PURE__ */ l(d, { value: { formId: a, formRef: t, options: r }, children: f });
|
|
30
27
|
};
|
|
31
28
|
export {
|
|
32
|
-
|
|
29
|
+
M as default
|
|
33
30
|
};
|
|
@@ -1,13 +1,17 @@
|
|
|
1
1
|
import r from "react";
|
|
2
|
-
function
|
|
3
|
-
const
|
|
4
|
-
|
|
5
|
-
const o = e();
|
|
2
|
+
function i() {
|
|
3
|
+
const e = r.createContext(void 0), t = () => r.useContext(e), n = () => {
|
|
4
|
+
const o = t();
|
|
6
5
|
if (o === void 0)
|
|
7
6
|
throw new Error();
|
|
8
7
|
return o;
|
|
9
|
-
}
|
|
8
|
+
};
|
|
9
|
+
return {
|
|
10
|
+
Provider: e.Provider,
|
|
11
|
+
useMaybe: t,
|
|
12
|
+
useRequired: n
|
|
13
|
+
};
|
|
10
14
|
}
|
|
11
15
|
export {
|
|
12
|
-
|
|
16
|
+
i as default
|
|
13
17
|
};
|
|
@@ -11,10 +11,6 @@ import { FormSubmitErrors } from '../../submit/error/FormSubmitErrors';
|
|
|
11
11
|
* Options under `defaults` can be overridden at form level.
|
|
12
12
|
*/
|
|
13
13
|
export type RhfUtilsClientConfig = {
|
|
14
|
-
/**
|
|
15
|
-
* Some behavior is dependent on environment.
|
|
16
|
-
*/
|
|
17
|
-
isDevelopment?: boolean;
|
|
18
14
|
/**
|
|
19
15
|
* Default options for all forms. (Are overridden by form-specific options.)
|
|
20
16
|
*/
|
|
@@ -26,9 +22,9 @@ export type RhfUtilsClientConfig = {
|
|
|
26
22
|
*/
|
|
27
23
|
rhf?: Pick<UseFormProps, 'mode' | 'reValidateMode' | 'resetOptions' | 'context' | 'shouldFocusError' | 'shouldUnregister' | 'shouldUseNativeValidation' | 'progressive' | 'criteriaMode' | 'delayError'>;
|
|
28
24
|
/**
|
|
29
|
-
*
|
|
25
|
+
* Global settings and defaults.
|
|
30
26
|
*
|
|
31
|
-
* Extend this type to inject custom options/functionality via `Children` component.
|
|
27
|
+
* (Extend this type via `Register` type to inject custom options/functionality via `Children` component.)
|
|
32
28
|
*/
|
|
33
29
|
utils?: RhfUtilsFormOptions;
|
|
34
30
|
};
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { RhfUtilsClientConfig } from './RhfUtilsClientConfig';
|
|
2
2
|
|
|
3
|
-
declare const
|
|
3
|
+
declare const _RhfUtilsClientConfigContextProvider: import('react').Provider<RhfUtilsClientConfig | undefined>, useRhfUtilsClientConfigMaybeContext: () => RhfUtilsClientConfig | undefined;
|
|
4
4
|
export default useRhfUtilsClientConfigMaybeContext;
|
|
5
5
|
export { _RhfUtilsClientConfigContextProvider };
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { default as createRhfUtilsClientForZod } from '../createRhfUtilsClientForZod';
|
|
2
2
|
|
|
3
3
|
export type RhfUtilsClientForZodContext = ReturnType<typeof createRhfUtilsClientForZod>;
|
|
4
|
-
declare const
|
|
4
|
+
declare const _RhfUtilsClientForZodContextProvider: import('react').Provider<import('../..').CreateRhfUtilsClient<import('../ZodTypeFieldValues').ZodTypeFieldValues, "_input", "_output"> | undefined>, useRhfUtilsClientForZodContext: () => import('../..').CreateRhfUtilsClient<import('../ZodTypeFieldValues').ZodTypeFieldValues, "_input", "_output">;
|
|
5
5
|
export default useRhfUtilsClientForZodContext;
|
|
6
6
|
export { _RhfUtilsClientForZodContextProvider };
|
|
@@ -2,9 +2,10 @@ import { FlatFieldErrors } from '../types';
|
|
|
2
2
|
|
|
3
3
|
export type FlatFieldErrorsContext = {
|
|
4
4
|
all: FlatFieldErrors;
|
|
5
|
+
fields: FlatFieldErrors;
|
|
5
6
|
roots: FlatFieldErrors;
|
|
6
7
|
orphans: FlatFieldErrors;
|
|
7
8
|
};
|
|
8
|
-
declare const
|
|
9
|
+
declare const _FormErrorsFlatContextProvider: import('react').Provider<FlatFieldErrorsContext | undefined>, useFlatFieldErrorsContext: () => FlatFieldErrorsContext;
|
|
9
10
|
export default useFlatFieldErrorsContext;
|
|
10
11
|
export { _FormErrorsFlatContextProvider };
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { FlatFieldErrorsOutputConfig } from './FlatFieldErrorsOutputConfig';
|
|
2
2
|
|
|
3
3
|
/**
|
|
4
4
|
* Outputs (e.g., console, throw) errors based on config.
|
|
5
5
|
*/
|
|
6
|
-
declare const useFlatFieldErrorsContextOutput: (config
|
|
6
|
+
declare const useFlatFieldErrorsContextOutput: (config?: FlatFieldErrorsOutputConfig) => void;
|
|
7
7
|
export default useFlatFieldErrorsContextOutput;
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { FlatFieldErrorEntry } from './flat/types';
|
|
2
2
|
|
|
3
3
|
/**
|
|
4
|
-
*
|
|
4
|
+
* Determine if {@link FieldError} is a `ref`'d field error.
|
|
5
5
|
*/
|
|
6
6
|
declare const isFlatFieldErrorEntryRefd: ([, error]: FlatFieldErrorEntry) => boolean;
|
|
7
7
|
export default isFlatFieldErrorEntryRefd;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { DevtoolUIProps } from '@hookform/devtools/dist/devToolUI';
|
|
2
|
-
import {
|
|
2
|
+
import { UseResetFormAfterSubmitSuccessfulOptions } from '../submit/useResetFormOnSubmitSuccessful';
|
|
3
3
|
import { Register } from '../register';
|
|
4
4
|
|
|
5
5
|
/**
|
|
@@ -9,7 +9,7 @@ import { Register } from '../register';
|
|
|
9
9
|
*/
|
|
10
10
|
export type RhfUtilsFormOptions = {
|
|
11
11
|
/**
|
|
12
|
-
*
|
|
12
|
+
* Style via your own classes.
|
|
13
13
|
* (Defaults merged with individual class names.)
|
|
14
14
|
*/
|
|
15
15
|
classNames?: string[];
|
|
@@ -20,8 +20,12 @@ export type RhfUtilsFormOptions = {
|
|
|
20
20
|
/** Stop propagation of submit event. Useful for portals. */
|
|
21
21
|
stopSubmitPropagation?: boolean;
|
|
22
22
|
/** Reset form after successful submit. */
|
|
23
|
-
resetFormAfterSubmitSuccessful?:
|
|
24
|
-
/**
|
|
23
|
+
resetFormAfterSubmitSuccessful?: UseResetFormAfterSubmitSuccessfulOptions;
|
|
24
|
+
/**
|
|
25
|
+
* Control dev tool options.
|
|
26
|
+
* (Lazy-loaded when truthy value supplied.
|
|
27
|
+
* For zero bundle size in prod, be sure to check for dev environment.)
|
|
28
|
+
*/
|
|
25
29
|
devTool?: true | Pick<DevtoolUIProps, 'placement' | 'styles'>;
|
|
26
30
|
} & (Register extends {
|
|
27
31
|
RhfUtilsFormOptions: infer _RhfUtilsFormOptions;
|
|
@@ -1,10 +1,8 @@
|
|
|
1
1
|
import { default as React } from 'react';
|
|
2
|
-
import { RhfUtilsClientConfig } from '../client/config/RhfUtilsClientConfig';
|
|
3
2
|
|
|
4
3
|
export type FormBaseProps = React.PropsWithChildren<React.HTMLAttributes<HTMLFormElement>> & {
|
|
4
|
+
Component?: React.FC<React.PropsWithChildren<React.HTMLAttributes<HTMLFormElement>>>;
|
|
5
5
|
formRef: React.RefObject<HTMLFormElement>;
|
|
6
|
-
config?: RhfUtilsClientConfig;
|
|
7
|
-
antiCsrfToken?: string;
|
|
8
6
|
};
|
|
9
|
-
declare const _FormBase:
|
|
7
|
+
declare const _FormBase: React.FC<FormBaseProps>;
|
|
10
8
|
export default _FormBase;
|
|
@@ -12,4 +12,4 @@ export type FormGroupContext = {
|
|
|
12
12
|
setIsBusy: (isBusy: boolean) => void;
|
|
13
13
|
};
|
|
14
14
|
};
|
|
15
|
-
export declare const
|
|
15
|
+
export declare const _FormGroupContextProvider: import('react').Provider<FormGroupContext | undefined>, _useFormGroupContext: () => FormGroupContext, _useFormGroupContextMaybe: () => FormGroupContext | undefined;
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { KeepStateOptions } from 'react-hook-form';
|
|
2
2
|
import { SafeFieldValues } from '../form/SafeFieldValues';
|
|
3
3
|
|
|
4
|
-
type
|
|
4
|
+
export type UseResetFormAfterSubmitSuccessfulOptions = false | undefined | true | {
|
|
5
5
|
values?: undefined | SafeFieldValues | {
|
|
6
6
|
resetToCurrentValues: true;
|
|
7
7
|
};
|
|
@@ -12,5 +12,5 @@ type Options = false | undefined | true | {
|
|
|
12
12
|
* See `Rules` section: https://react-hook-form.com/api/useform/reset/
|
|
13
13
|
* Specifically: "- It's recommended to reset inside useEffect after submission."
|
|
14
14
|
*/
|
|
15
|
-
declare const useResetFormAfterSubmitSuccessful: (options:
|
|
15
|
+
declare const useResetFormAfterSubmitSuccessful: (options: UseResetFormAfterSubmitSuccessfulOptions) => void;
|
|
16
16
|
export default useResetFormAfterSubmitSuccessful;
|
|
@@ -1,8 +1,12 @@
|
|
|
1
1
|
import { default as React } from 'react';
|
|
2
2
|
|
|
3
3
|
/**
|
|
4
|
-
* Create a
|
|
4
|
+
* Create a strictly-typed context that throws error if no provider is found.
|
|
5
5
|
* @returns A tuple with a function to get the context and the context provider.
|
|
6
6
|
*/
|
|
7
|
-
declare function createContext<T = unknown>():
|
|
7
|
+
declare function createContext<T = unknown>(): {
|
|
8
|
+
readonly Provider: React.Provider<T | undefined>;
|
|
9
|
+
readonly useMaybe: () => T | undefined;
|
|
10
|
+
readonly useRequired: () => T & ({} | null);
|
|
11
|
+
};
|
|
8
12
|
export default createContext;
|