@paragrav/rhf-utils 0.0.114 → 0.0.116
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 +12 -6
- package/dist/esm/errors/flat/context/FlatFieldErrorsContextProvider.mjs +12 -14
- package/dist/esm/errors/flat/context/useFlatFieldErrorsContext.mjs +3 -8
- package/dist/esm/errors/flat/context/useFlatFieldErrorsContextHasOnlyOrphans.mjs +10 -0
- package/dist/esm/errors/flat/context/useFlatFieldErrorsContextOutput.mjs +29 -0
- package/dist/esm/exports.mjs +40 -38
- package/dist/esm/form/Form.mjs +1 -1
- package/dist/esm/form/context/utils/RhfUtilsContextProvider.mjs +23 -17
- package/dist/types/client/config/RhfUtilsClientConfig.d.ts +3 -19
- package/dist/types/errors/flat/context/FlatFieldErrorsContextProvider.d.ts +2 -1
- package/dist/types/errors/flat/context/FlatFieldErrorsOutputConfig.d.ts +19 -0
- package/dist/types/errors/flat/context/useFlatFieldErrorsContext.d.ts +2 -2
- package/dist/types/errors/flat/context/useFlatFieldErrorsContextHasOnlyOrphans.d.ts +7 -0
- package/dist/types/errors/flat/context/useFlatFieldErrorsContextOutput.d.ts +7 -0
- package/dist/types/errors/trpc/getOnSubmitTrpcClientErrorHandler.d.ts +2 -2
- package/dist/types/exports.d.ts +1 -0
- package/dist/types/form/context/utils/RhfUtilsContextProvider.d.ts +1 -1
- package/package.json +1 -1
- package/dist/esm/errors/flat/useFlatFieldErrorsOutput.mjs +0 -30
- package/dist/esm/errors/useFormErrorsTransformMemo.mjs +0 -12
package/README.md
CHANGED
|
@@ -33,8 +33,9 @@ export const rhfUtilsClientConfig: RhfUtilsClientConfig = {
|
|
|
33
33
|
// optional (defaults to primitive HTML form)
|
|
34
34
|
FormComponent: Form.Root,
|
|
35
35
|
|
|
36
|
-
//
|
|
37
|
-
|
|
36
|
+
// non-FormSubmitError throw in onSubmit
|
|
37
|
+
// use case: transform backend error
|
|
38
|
+
onSubmitUnknownError: (
|
|
38
39
|
error, // unknown
|
|
39
40
|
) => {
|
|
40
41
|
// if other error, re-throw to handle in ErrorBoundary
|
|
@@ -96,7 +97,7 @@ And add the context provider to your stack:
|
|
|
96
97
|
|
|
97
98
|
Currently, only `zod` is supported.
|
|
98
99
|
|
|
99
|
-
##
|
|
100
|
+
## Form
|
|
100
101
|
|
|
101
102
|
```tsx
|
|
102
103
|
<RhfUtilsZodForm
|
|
@@ -160,7 +161,7 @@ function Children({...}: RhfUtilsUseFormChildrenZodProps<typeof schema>) { }
|
|
|
160
161
|
|
|
161
162
|
## `FormSubmitError`
|
|
162
163
|
|
|
163
|
-
This is
|
|
164
|
+
This is an `Error`-based class you can use to throw a structured error in your submit handler. It is strongly-typed, so it only allows field names in schema and `root`/`root.{string}` keys.
|
|
164
165
|
|
|
165
166
|
It uses `FormSubmitErrors` shape, which is a flat (dot notation) equivalent of RHF's `FieldErrors`.
|
|
166
167
|
|
|
@@ -174,11 +175,15 @@ Example:
|
|
|
174
175
|
root: { message: 'There was a problem with the form.' },
|
|
175
176
|
'street.address': { message: 'Street address invalid.' },
|
|
176
177
|
});
|
|
178
|
+
|
|
179
|
+
await post('/backend');
|
|
177
180
|
}}
|
|
178
181
|
/>
|
|
179
182
|
```
|
|
180
183
|
|
|
181
|
-
Any non-`FormSubmitError`s thrown from submit handler can be transformed by `RhfUtilsClientConfig`'s `
|
|
184
|
+
Any non-`FormSubmitError`s thrown from submit handler (e.g., fetch/axios error) can be transformed by `RhfUtilsClientConfig`'s `onSubmitUnknownError` callback. This takes an `unknown` error and can return a `FormSubmitErrors` object, which is merged in RHF's context errors.
|
|
185
|
+
|
|
186
|
+
Most common use case will be transforming backend errors to frontend shape. (You can use `getOnSubmitTrpcClientErrorHandler` HOF for TRPC backends.)
|
|
182
187
|
|
|
183
188
|
## `RhfUtilsFormOptions`
|
|
184
189
|
|
|
@@ -258,8 +263,9 @@ Example use case: Field array with minimum items. (When there are no items, the
|
|
|
258
263
|
|
|
259
264
|
Orphans are optionally exposed in a few places.
|
|
260
265
|
|
|
261
|
-
- In errors outputted via console.
|
|
266
|
+
- In errors outputted via console. (Configured via `RhfUtilsClientConfig['errors']['output']`.)
|
|
262
267
|
- And `useFlatFieldErrorsContext()` hook, which returns an object with divided into `all`, `root`, and `orphans` errors.
|
|
268
|
+
- Boolean value from `useFlatFieldErrorsContextHasOnlyOrphans`.
|
|
263
269
|
|
|
264
270
|
`FlatFieldErrors` is a flattened, simplified version of RHF's `FieldErrors`. Keys represent field paths flattened to dot notation.
|
|
265
271
|
|
|
@@ -1,23 +1,21 @@
|
|
|
1
|
-
import { jsx as
|
|
1
|
+
import { jsx as m } from "react/jsx-runtime";
|
|
2
|
+
import "react";
|
|
3
|
+
import { useFormState as i } from "react-hook-form";
|
|
2
4
|
import l from "../../orphan/getOrphansFromFlatFieldErrors.mjs";
|
|
3
5
|
import F from "../../root/getRootsFromFlatFieldErrors.mjs";
|
|
4
|
-
import a from "
|
|
5
|
-
import i from "../getFlatFieldErrors.mjs";
|
|
6
|
+
import a from "../getFlatFieldErrors.mjs";
|
|
6
7
|
import { _FormErrorsFlatContextProvider as n } from "./useFlatFieldErrorsContext.mjs";
|
|
7
|
-
const
|
|
8
|
+
const g = ({
|
|
8
9
|
formRef: o,
|
|
9
10
|
children: t
|
|
10
11
|
}) => {
|
|
11
|
-
const e = a(
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
};
|
|
18
|
-
});
|
|
19
|
-
return /* @__PURE__ */ s(n, { value: e, children: t });
|
|
12
|
+
const { errors: e } = i(), r = a(e), s = {
|
|
13
|
+
all: r,
|
|
14
|
+
roots: F(r),
|
|
15
|
+
orphans: o.current ? l(r, o.current) : {}
|
|
16
|
+
};
|
|
17
|
+
return /* @__PURE__ */ m(n, { value: s, children: t });
|
|
20
18
|
};
|
|
21
19
|
export {
|
|
22
|
-
|
|
20
|
+
g as default
|
|
23
21
|
};
|
|
@@ -1,11 +1,6 @@
|
|
|
1
1
|
import t from "../../../utils/createContext.mjs";
|
|
2
|
-
const [
|
|
3
|
-
o,
|
|
4
|
-
r,
|
|
5
|
-
s
|
|
6
|
-
] = t(), a = r;
|
|
2
|
+
const [, r, e] = t(), s = r;
|
|
7
3
|
export {
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
o as useFlatFieldErrorsContextMaybe
|
|
4
|
+
e as _FormErrorsFlatContextProvider,
|
|
5
|
+
s as default
|
|
11
6
|
};
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import t from "react";
|
|
2
|
+
import s from "../../../utils/isEmptyObject.mjs";
|
|
3
|
+
import e from "./useFlatFieldErrorsContext.mjs";
|
|
4
|
+
const n = () => {
|
|
5
|
+
const r = e();
|
|
6
|
+
return t.useMemo(() => s(r.orphans) ? !1 : Object.keys(r.orphans).length === Object.keys(r.all).length, [r]);
|
|
7
|
+
}, O = n;
|
|
8
|
+
export {
|
|
9
|
+
O as default
|
|
10
|
+
};
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import h from "react";
|
|
2
|
+
import { useFormContext as E } from "react-hook-form";
|
|
3
|
+
import c from "../../../utils/isEmptyObject.mjs";
|
|
4
|
+
import F from "../../output/consoleErrors.mjs";
|
|
5
|
+
import x from "./useFlatFieldErrorsContext.mjs";
|
|
6
|
+
const g = (e) => {
|
|
7
|
+
const i = E(), o = x();
|
|
8
|
+
h.useEffect(() => {
|
|
9
|
+
var p, r, l, u, t, a;
|
|
10
|
+
if (c(o.all))
|
|
11
|
+
return;
|
|
12
|
+
const m = {
|
|
13
|
+
isDevelopment: e.isDevelopment,
|
|
14
|
+
hasOrphans: !c(o.orphans)
|
|
15
|
+
}, s = (l = (r = (p = e.errors) == null ? void 0 : p.output) == null ? void 0 : r.console) == null ? void 0 : l.call(r, m);
|
|
16
|
+
s && F(
|
|
17
|
+
s.message ?? f,
|
|
18
|
+
i.getValues(),
|
|
19
|
+
o,
|
|
20
|
+
s.type
|
|
21
|
+
);
|
|
22
|
+
const n = (a = (t = (u = e.errors) == null ? void 0 : u.output) == null ? void 0 : t.throw) == null ? void 0 : a.call(t, m);
|
|
23
|
+
if (n)
|
|
24
|
+
throw new Error(typeof n == "string" ? n : f);
|
|
25
|
+
}, [o]);
|
|
26
|
+
}, f = "Form errors";
|
|
27
|
+
export {
|
|
28
|
+
g as default
|
|
29
|
+
};
|
package/dist/esm/exports.mjs
CHANGED
|
@@ -2,47 +2,49 @@ import { default as e } from "./client/zod/context/RhfUtilsClientForZodContextPr
|
|
|
2
2
|
import { default as s } from "./client/zod/context/RhfUtilsZodForm.mjs";
|
|
3
3
|
import { default as u } from "./client/zod/context/useRhfUtilsZodForm.mjs";
|
|
4
4
|
import { default as m } from "./errors/flat/context/useFlatFieldErrorsContext.mjs";
|
|
5
|
-
import { default as d } from "./errors/
|
|
6
|
-
import { default as x } from "./errors/
|
|
7
|
-
import { default as F } from "./errors/
|
|
8
|
-
import {
|
|
9
|
-
import {
|
|
10
|
-
import {
|
|
11
|
-
import { default as b } from "./form/context/utils/
|
|
12
|
-
import { default as
|
|
13
|
-
import { default as B } from "./form/context/group/
|
|
14
|
-
import { default as P } from "./form/context/group/
|
|
15
|
-
import { default as U } from "./form/context/group/
|
|
16
|
-
import { default as
|
|
17
|
-
import { default as
|
|
18
|
-
import { default as
|
|
19
|
-
import { default as
|
|
20
|
-
import { default as L } from "./form/context/group/
|
|
21
|
-
import { default as j } from "./form/
|
|
22
|
-
import { default as z } from "./form/utils/
|
|
23
|
-
import {
|
|
5
|
+
import { default as d } from "./errors/flat/context/useFlatFieldErrorsContextHasOnlyOrphans.mjs";
|
|
6
|
+
import { default as x } from "./errors/message/FormErrorMessageByPath.mjs";
|
|
7
|
+
import { default as F } from "./errors/nonfield/FormNonFieldErrorMarker.mjs";
|
|
8
|
+
import { default as C } from "./errors/root/RootErrorsListFromFlatFieldErrorsContext.mjs";
|
|
9
|
+
import { getOnSubmitTrpcClientErrorHandler as E } from "./errors/trpc/getOnSubmitTrpcClientErrorHandler.mjs";
|
|
10
|
+
import { trpcClientErrorToFormSubmitErrorsSchemaTransformer as R } from "./errors/trpc/trpcClientErrorToFormSubmitErrorsSchemaTransformer.mjs";
|
|
11
|
+
import { default as b } from "./form/context/utils/useRhfUtilsContext.mjs";
|
|
12
|
+
import { default as y } from "./form/context/utils/useRhfUtilsContextRequestSubmit.mjs";
|
|
13
|
+
import { default as B } from "./form/context/group/FormGroupContextProvider.mjs";
|
|
14
|
+
import { default as P } from "./form/context/group/useFormGroupChildIsMountedTracker.mjs";
|
|
15
|
+
import { default as U } from "./form/context/group/useFormGroupChildIsSubmittingTracker.mjs";
|
|
16
|
+
import { default as O } from "./form/context/group/useFormGroupChildTracker.mjs";
|
|
17
|
+
import { default as Z } from "./form/context/group/useFormGroupIsAnyBusy.mjs";
|
|
18
|
+
import { default as v } from "./form/context/group/useFormGroupIsChildBusy.mjs";
|
|
19
|
+
import { default as A } from "./form/context/group/useFormGroupIsParentBusy.mjs";
|
|
20
|
+
import { default as L } from "./form/context/group/useFormGroupParentTracker.mjs";
|
|
21
|
+
import { default as j } from "./form/context/group/useFormOrParentIsBusy.mjs";
|
|
22
|
+
import { default as z } from "./form/utils/getSubmitterButtonData.mjs";
|
|
23
|
+
import { default as K } from "./form/utils/useFormRequestSubmit.mjs";
|
|
24
|
+
import { FormSubmitError as V } from "./submit/error/FormSubmitError.mjs";
|
|
24
25
|
export {
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
26
|
+
x as FormErrorMessageByPath,
|
|
27
|
+
B as FormGroupContextProvider,
|
|
28
|
+
F as FormNonFieldErrorMarker,
|
|
29
|
+
V as FormSubmitError,
|
|
29
30
|
e as RhfUtilsClientForZodContextProvider,
|
|
30
31
|
s as RhfUtilsZodForm,
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
32
|
+
C as RootErrorsListFromFlatFieldErrorsContext,
|
|
33
|
+
E as getOnSubmitTrpcClientErrorHandler,
|
|
34
|
+
z as getSubmitterButtonData,
|
|
35
|
+
R as trpcClientErrorToFormSubmitErrorsSchemaTransformer,
|
|
35
36
|
m as useFlatFieldErrorsContext,
|
|
36
|
-
|
|
37
|
-
P as
|
|
38
|
-
U as
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
L as
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
b as
|
|
37
|
+
d as useFlatFieldErrorsContextHasOnlyOrphans,
|
|
38
|
+
P as useFormGroupChildIsMountedTracker,
|
|
39
|
+
U as useFormGroupChildIsSubmittingTracker,
|
|
40
|
+
O as useFormGroupChildTracker,
|
|
41
|
+
Z as useFormGroupIsAnyBusy,
|
|
42
|
+
v as useFormGroupIsChildBusy,
|
|
43
|
+
A as useFormGroupIsParentBusy,
|
|
44
|
+
L as useFormGroupParentTracker,
|
|
45
|
+
j as useFormOrParentIsBusy,
|
|
46
|
+
K as useFormRequestSubmit,
|
|
47
|
+
b as useRhfUtilsContext,
|
|
48
|
+
y as useRhfUtilsContextRequestSubmit,
|
|
47
49
|
u as useRhfUtilsZodForm
|
|
48
50
|
};
|
package/dist/esm/form/Form.mjs
CHANGED
|
@@ -45,7 +45,7 @@ function A({
|
|
|
45
45
|
e.errors
|
|
46
46
|
) : (
|
|
47
47
|
// if error is not FormSubmitError, consumer can provide global handler
|
|
48
|
-
(y = t == null ? void 0 : t.
|
|
48
|
+
(y = t == null ? void 0 : t.onSubmitUnknownError) == null ? void 0 : y.call(t, e)
|
|
49
49
|
);
|
|
50
50
|
a && P(n, a), d == null || d(
|
|
51
51
|
e,
|
|
@@ -1,27 +1,33 @@
|
|
|
1
1
|
import { jsx as f } from "react/jsx-runtime";
|
|
2
|
-
import
|
|
3
|
-
import
|
|
4
|
-
import
|
|
5
|
-
import O from "../../../submit/
|
|
6
|
-
import b from "../../../submit/
|
|
7
|
-
import
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
2
|
+
import C from "../../../client/config/useRhfUtilsClientConfigContext.mjs";
|
|
3
|
+
import F from "../../../errors/flat/context/useFlatFieldErrorsContextOutput.mjs";
|
|
4
|
+
import x from "../../../submit/useFormOnSubmitSuccessfulAndReset.mjs";
|
|
5
|
+
import O from "../../../submit/useResetFormOnSubmitError.mjs";
|
|
6
|
+
import b from "../../../submit/useResetFormOnSubmitSuccessful.mjs";
|
|
7
|
+
import h from "../../../submit/useSubmitFormOnChange.mjs";
|
|
8
|
+
import { _RhfUtilsContextProvider as v } from "./useRhfUtilsContext.mjs";
|
|
9
|
+
const y = ({
|
|
10
|
+
formId: l,
|
|
11
|
+
formRef: t,
|
|
11
12
|
onSubmitSuccessfulAndReset: m,
|
|
12
13
|
options: r,
|
|
13
14
|
children: a
|
|
14
|
-
}) {
|
|
15
|
-
|
|
15
|
+
}) => {
|
|
16
|
+
var u;
|
|
17
|
+
const e = C();
|
|
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, {
|
|
16
22
|
disabled: !(r != null && r.submitOnChange)
|
|
17
|
-
}),
|
|
23
|
+
}), O({
|
|
18
24
|
disabled: !(r != null && r.resetValuesOnSubmitError)
|
|
19
|
-
}),
|
|
25
|
+
}), b(
|
|
20
26
|
(r == null ? void 0 : r.resetFormAfterSubmitSuccessful) || !!m
|
|
21
|
-
),
|
|
27
|
+
), x(() => {
|
|
22
28
|
m == null || m();
|
|
23
|
-
}), /* @__PURE__ */ f(
|
|
24
|
-
}
|
|
29
|
+
}), /* @__PURE__ */ f(v, { value: { formId: l, formRef: t, options: r }, children: a });
|
|
30
|
+
};
|
|
25
31
|
export {
|
|
26
|
-
|
|
32
|
+
y as default
|
|
27
33
|
};
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { UseFormProps } from 'react-hook-form';
|
|
2
|
-
import {
|
|
2
|
+
import { FlatFieldErrorsOutputConfig } from '../../errors/flat/context/FlatFieldErrorsOutputConfig';
|
|
3
3
|
import { FormChildrenSlots } from '../../form/Form';
|
|
4
4
|
import { RhfUtilsFormOptions } from '../../form/RhfUtilsFormOptions';
|
|
5
5
|
import { UseRhfUtilsFormChildrenProps } from '../../form/UseRhfUtilsFormChildrenProps';
|
|
@@ -48,7 +48,7 @@ export type RhfUtilsClientConfig = {
|
|
|
48
48
|
* - if {@link FormSubmitErrors}: merge into context errors.
|
|
49
49
|
* - if `undefined`: do nothing.
|
|
50
50
|
*/
|
|
51
|
-
|
|
51
|
+
onSubmitUnknownError?: (error: unknown) => FormSubmitErrors | undefined;
|
|
52
52
|
/**
|
|
53
53
|
* Components injected by slot across all forms.
|
|
54
54
|
* (Per-form injection can be done via `Children` prop.)
|
|
@@ -61,22 +61,6 @@ export type RhfUtilsClientConfig = {
|
|
|
61
61
|
/**
|
|
62
62
|
* Configure how/if errors should be outputted.
|
|
63
63
|
*/
|
|
64
|
-
output?:
|
|
65
|
-
/**
|
|
66
|
-
* Configure how/if errors should be outputted to console.
|
|
67
|
-
*
|
|
68
|
-
* Example use cases:
|
|
69
|
-
* - console.debug errors in development environment.
|
|
70
|
-
* - console.error certain errors in production environment.
|
|
71
|
-
*/
|
|
72
|
-
console?: (context: RhfUtilsErrorsOutputConfigContext) => RhfUtilsErrorsOutputConsoleConfig | null | false | undefined;
|
|
73
|
-
/**
|
|
74
|
-
* Configure how/if errors should be thrown.
|
|
75
|
-
*
|
|
76
|
-
* Example use case:
|
|
77
|
-
* - bring attention to certain errors in development environment.
|
|
78
|
-
*/
|
|
79
|
-
throw?: (context: RhfUtilsErrorsOutputConfigContext) => true | string | false | undefined;
|
|
80
|
-
};
|
|
64
|
+
output?: FlatFieldErrorsOutputConfig;
|
|
81
65
|
};
|
|
82
66
|
};
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { RhfUtilsErrorsOutputConfigContext, RhfUtilsErrorsOutputConsoleConfig } from '../../output/types';
|
|
2
|
+
|
|
3
|
+
export type FlatFieldErrorsOutputConfig = {
|
|
4
|
+
/**
|
|
5
|
+
* Configure how/if errors should be outputted to console.
|
|
6
|
+
*
|
|
7
|
+
* Example use cases:
|
|
8
|
+
* - console.debug errors in development environment.
|
|
9
|
+
* - console.error certain errors in production environment.
|
|
10
|
+
*/
|
|
11
|
+
console?: (context: RhfUtilsErrorsOutputConfigContext) => RhfUtilsErrorsOutputConsoleConfig | null | false | undefined;
|
|
12
|
+
/**
|
|
13
|
+
* Configure how/if errors should be thrown.
|
|
14
|
+
*
|
|
15
|
+
* Example use case:
|
|
16
|
+
* - bring attention to certain errors in development environment.
|
|
17
|
+
*/
|
|
18
|
+
throw?: (context: RhfUtilsErrorsOutputConfigContext) => true | string | false | undefined;
|
|
19
|
+
};
|
|
@@ -5,6 +5,6 @@ export type FlatFieldErrorsContext = {
|
|
|
5
5
|
roots: FlatFieldErrors;
|
|
6
6
|
orphans: FlatFieldErrors;
|
|
7
7
|
};
|
|
8
|
-
declare const
|
|
8
|
+
declare const useFlatFieldErrorsContext: () => FlatFieldErrorsContext, _FormErrorsFlatContextProvider: import('react').Provider<FlatFieldErrorsContext | undefined>;
|
|
9
9
|
export default useFlatFieldErrorsContext;
|
|
10
|
-
export { _FormErrorsFlatContextProvider
|
|
10
|
+
export { _FormErrorsFlatContextProvider };
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { RhfUtilsClientConfig } from '../../../client/config/RhfUtilsClientConfig';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Outputs (e.g., console, throw) errors based on config.
|
|
5
|
+
*/
|
|
6
|
+
declare const useFlatFieldErrorsContextOutput: (config: RhfUtilsClientConfig) => void;
|
|
7
|
+
export default useFlatFieldErrorsContextOutput;
|
|
@@ -2,9 +2,9 @@ import { RhfUtilsClientConfig } from '../../client/config/RhfUtilsClientConfig';
|
|
|
2
2
|
import { FormSubmitErrors } from '../../submit/error/FormSubmitErrors';
|
|
3
3
|
|
|
4
4
|
/**
|
|
5
|
-
* HOF that returns submit error handler for {@link RhfUtilsClientConfig.
|
|
5
|
+
* HOF that returns submit error handler for {@link RhfUtilsClientConfig.onSubmitUnknownError}.
|
|
6
6
|
*
|
|
7
7
|
* @param onError Fallback for handling non-TRPC errors.
|
|
8
8
|
* @returns FormSubmitError
|
|
9
9
|
*/
|
|
10
|
-
export declare const getOnSubmitTrpcClientErrorHandler: (onNotTrpcClientError: NonNullable<RhfUtilsClientConfig['
|
|
10
|
+
export declare const getOnSubmitTrpcClientErrorHandler: (onNotTrpcClientError: NonNullable<RhfUtilsClientConfig['onSubmitUnknownError']>) => (error: unknown) => FormSubmitErrors | undefined;
|
package/dist/types/exports.d.ts
CHANGED
|
@@ -6,6 +6,7 @@ export { default as useRhfUtilsZodForm } from './client/zod/context/useRhfUtilsZ
|
|
|
6
6
|
export type { RhfUtilsUseFormChildrenZodFC } from './client/zod/RhfUtilsUseFormChildrenZodFC';
|
|
7
7
|
export type { RhfUtilsUseFormChildrenZodProps } from './client/zod/RhfUtilsUseFormChildrenZodProps';
|
|
8
8
|
export { default as useFlatFieldErrorsContext } from './errors/flat/context/useFlatFieldErrorsContext';
|
|
9
|
+
export { default as useFlatFieldErrorsContextHasOnlyOrphans } from './errors/flat/context/useFlatFieldErrorsContextHasOnlyOrphans';
|
|
9
10
|
export { default as FormErrorMessageByPath } from './errors/message/FormErrorMessageByPath';
|
|
10
11
|
export { default as FormNonFieldErrorMarker } from './errors/nonfield/FormNonFieldErrorMarker';
|
|
11
12
|
export { default as RootErrorsListFromFlatFieldErrorsContext } from './errors/root/RootErrorsListFromFlatFieldErrorsContext';
|
|
@@ -7,5 +7,5 @@ type Props = React.PropsWithChildren<{
|
|
|
7
7
|
onSubmitSuccessfulAndReset?: () => void;
|
|
8
8
|
options?: RhfUtilsFormOptions;
|
|
9
9
|
}>;
|
|
10
|
-
declare
|
|
10
|
+
declare const RhfUtilsContextProvider: React.FC<Props>;
|
|
11
11
|
export default RhfUtilsContextProvider;
|
package/package.json
CHANGED
|
@@ -1,30 +0,0 @@
|
|
|
1
|
-
import h from "react";
|
|
2
|
-
import { useFormContext as E } from "react-hook-form";
|
|
3
|
-
import F from "../../client/config/useRhfUtilsClientConfigContext.mjs";
|
|
4
|
-
import i from "../../utils/isEmptyObject.mjs";
|
|
5
|
-
import x from "../output/consoleErrors.mjs";
|
|
6
|
-
import C from "./context/useFlatFieldErrorsContext.mjs";
|
|
7
|
-
const D = () => {
|
|
8
|
-
const c = E(), t = F(), r = C();
|
|
9
|
-
h.useEffect(() => {
|
|
10
|
-
var p, o, l, u, e, a;
|
|
11
|
-
if (i(r.all))
|
|
12
|
-
return;
|
|
13
|
-
const n = {
|
|
14
|
-
isDevelopment: t == null ? void 0 : t.isDevelopment,
|
|
15
|
-
hasOrphans: !i(r.orphans)
|
|
16
|
-
}, s = (l = (o = (p = t == null ? void 0 : t.errors) == null ? void 0 : p.output) == null ? void 0 : o.console) == null ? void 0 : l.call(o, n);
|
|
17
|
-
s && x(
|
|
18
|
-
s.message ?? f,
|
|
19
|
-
c.getValues(),
|
|
20
|
-
r,
|
|
21
|
-
s.type
|
|
22
|
-
);
|
|
23
|
-
const m = (a = (e = (u = t == null ? void 0 : t.errors) == null ? void 0 : u.output) == null ? void 0 : e.throw) == null ? void 0 : a.call(e, n);
|
|
24
|
-
if (m)
|
|
25
|
-
throw new Error(typeof m == "string" ? m : f);
|
|
26
|
-
}, [r]);
|
|
27
|
-
}, f = "Form errors";
|
|
28
|
-
export {
|
|
29
|
-
D as default
|
|
30
|
-
};
|