@paragrav/rhf-utils 0.0.107 → 0.0.108
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
|
@@ -68,6 +68,18 @@ export const config: RhfUtilsClientConfig = {
|
|
|
68
68
|
</>
|
|
69
69
|
),
|
|
70
70
|
},
|
|
71
|
+
|
|
72
|
+
errors: {
|
|
73
|
+
output: {
|
|
74
|
+
// callback to determine when to output form context errors to console ("debug" or "error")
|
|
75
|
+
console: ({ isDevelopment, hasOrphans }) =>
|
|
76
|
+
(hasOrphans && { type: 'error' }) || // report orphan errors early
|
|
77
|
+
(isDevelopment && { type: 'debug' }), // facilitate debugging on dev
|
|
78
|
+
|
|
79
|
+
// callback to determine when to throw an error based on context
|
|
80
|
+
throw: ({ isDevelopment, hasOrphans }) => isDevelopment && hasOrphans,
|
|
81
|
+
},
|
|
82
|
+
},
|
|
71
83
|
};
|
|
72
84
|
```
|
|
73
85
|
|
|
@@ -155,12 +167,6 @@ type RhfUtilsFormOptions = {
|
|
|
155
167
|
/** Stop propagation of submit event. Useful for portals. */
|
|
156
168
|
stopSubmitPropagation?: boolean;
|
|
157
169
|
|
|
158
|
-
/** Disable `console.debug` of field errors in dev. */
|
|
159
|
-
disableFormErrorConsoleDebug?: boolean;
|
|
160
|
-
|
|
161
|
-
/** Disable `console.error` of orphan field errors. */
|
|
162
|
-
disableOrphanFormErrorsToConsole?: boolean;
|
|
163
|
-
|
|
164
170
|
/** Reset form after successful submit. */
|
|
165
171
|
resetFormAfterSubmitSuccessful?: Parameters<
|
|
166
172
|
typeof useResetFormAfterSubmitSuccessful
|
|
@@ -1,24 +1,30 @@
|
|
|
1
|
-
import
|
|
1
|
+
import h from "react";
|
|
2
|
+
import { useFormContext as E } from "react-hook-form";
|
|
2
3
|
import F from "../../client/config/useRhfUtilsClientConfigContext.mjs";
|
|
3
|
-
import
|
|
4
|
-
import
|
|
5
|
-
import
|
|
6
|
-
const
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
n
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
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";
|
|
22
28
|
export {
|
|
23
|
-
|
|
29
|
+
D as default
|
|
24
30
|
};
|
|
@@ -5,6 +5,11 @@ import { RhfUtilsFormOptions } from '../../form/RhfUtilsFormOptions';
|
|
|
5
5
|
import { UseFormFieldsProps } from '../../form/useForm';
|
|
6
6
|
import { FormSubmitErrors } from '../../submit/error/FormSubmitErrors';
|
|
7
7
|
|
|
8
|
+
/**
|
|
9
|
+
* Client configuration object.
|
|
10
|
+
*
|
|
11
|
+
* Options under `defaults` can be overridden at form level.
|
|
12
|
+
*/
|
|
8
13
|
export type RhfUtilsClientConfig = {
|
|
9
14
|
/**
|
|
10
15
|
* Some behavior is dependent on environment.
|
|
@@ -66,18 +71,14 @@ export type RhfUtilsClientConfig = {
|
|
|
66
71
|
* - console.debug errors in development environment.
|
|
67
72
|
* - console.error certain errors in production environment.
|
|
68
73
|
*/
|
|
69
|
-
console?:
|
|
70
|
-
getConfig?: (context: RhfUtilsErrorsOutputConfigContext) => RhfUtilsErrorsOutputConsoleConfig | null;
|
|
71
|
-
};
|
|
74
|
+
console?: (context: RhfUtilsErrorsOutputConfigContext) => RhfUtilsErrorsOutputConsoleConfig | null | false | undefined;
|
|
72
75
|
/**
|
|
73
76
|
* Configure how/if errors should be thrown.
|
|
74
77
|
*
|
|
75
78
|
* Example use case:
|
|
76
79
|
* - bring attention to certain errors in development environment.
|
|
77
80
|
*/
|
|
78
|
-
throw?:
|
|
79
|
-
getConfig?: (context: RhfUtilsErrorsOutputConfigContext) => true | string | false;
|
|
80
|
-
};
|
|
81
|
+
throw?: (context: RhfUtilsErrorsOutputConfigContext) => true | string | false | undefined;
|
|
81
82
|
};
|
|
82
83
|
};
|
|
83
84
|
};
|
|
@@ -19,14 +19,10 @@ export type RhfUtilsFormOptions = {
|
|
|
19
19
|
resetValuesOnSubmitError?: boolean;
|
|
20
20
|
/** Stop propagation of submit event. Useful for portals. */
|
|
21
21
|
stopSubmitPropagation?: boolean;
|
|
22
|
-
/** Disable `console.debug` of field errors in dev. */
|
|
23
|
-
disableFormErrorConsoleDebug?: boolean;
|
|
24
|
-
/** Disable `console.error` of orphan field errors. */
|
|
25
|
-
disableOrphanFormErrorsToConsole?: boolean;
|
|
26
22
|
/** Reset form after successful submit. */
|
|
27
23
|
resetFormAfterSubmitSuccessful?: Parameters<typeof useResetFormAfterSubmitSuccessful>[0];
|
|
28
24
|
/** Control dev tool options. */
|
|
29
25
|
devTool?: Pick<DevtoolUIProps, 'placement' | 'styles'> | 'disabled';
|
|
30
26
|
} & (Register extends {
|
|
31
|
-
|
|
32
|
-
} ?
|
|
27
|
+
RhfUtilsFormOptions: infer _RhfUtilsFormOptions;
|
|
28
|
+
} ? _RhfUtilsFormOptions : {});
|