@paragrav/rhf-utils 0.0.107 → 0.0.109

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 { useFormContext as C } from "react-hook-form";
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 x from "../../utils/isEmptyObject.mjs";
4
- import E from "../output/consoleErrors.mjs";
5
- import d from "./context/useFlatFieldErrorsContext.mjs";
6
- const v = () => {
7
- var p, l, t, i, u, a, r, f;
8
- const h = C(), o = F(), n = d(), m = {
9
- isDevelopment: o == null ? void 0 : o.isDevelopment,
10
- hasOrphans: !x(n.orphans)
11
- }, e = (i = (t = (l = (p = o == null ? void 0 : o.errors) == null ? void 0 : p.output) == null ? void 0 : l.console) == null ? void 0 : t.getConfig) == null ? void 0 : i.call(t, m);
12
- e && E(
13
- e.message ?? c,
14
- h.getValues(),
15
- n,
16
- e.type
17
- );
18
- const s = (f = (r = (a = (u = o == null ? void 0 : o.errors) == null ? void 0 : u.output) == null ? void 0 : a.throw) == null ? void 0 : r.getConfig) == null ? void 0 : f.call(r, m);
19
- if (s)
20
- throw new Error(typeof s == "string" ? s : c);
21
- }, c = "Form errors";
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
- v as default
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
- UseFormOptions: infer _UseFormOptions;
32
- } ? _UseFormOptions : {});
27
+ RhfUtilsFormOptions: infer _RhfUtilsFormOptions;
28
+ } ? _RhfUtilsFormOptions : {});
@@ -4,5 +4,4 @@
4
4
  * For example, `RhfUtilsFormOptions`.
5
5
  */
6
6
  export interface Register {
7
- RhfUtilsFormOptions?: never;
8
7
  }
package/package.json CHANGED
@@ -2,7 +2,7 @@
2
2
  "name": "@paragrav/rhf-utils",
3
3
  "author": "paragrav.dev",
4
4
  "license": "MIT",
5
- "version": "0.0.107",
5
+ "version": "0.0.109",
6
6
  "description": "Integration utilities for react-hook-form.",
7
7
  "type": "module",
8
8
  "sideEffects": false,