@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.
Files changed (27) hide show
  1. package/README.md +21 -23
  2. package/dist/esm/client/config/useRhfUtilsClientConfigContext.mjs +7 -8
  3. package/dist/esm/client/zod/context/useRhfUtilsClientForZodContext.mjs +7 -4
  4. package/dist/esm/errors/flat/context/FlatFieldErrorsContextProvider.mjs +13 -11
  5. package/dist/esm/errors/flat/context/useFlatFieldErrorsContext.mjs +6 -3
  6. package/dist/esm/errors/flat/context/useFlatFieldErrorsContextOutput.mjs +19 -20
  7. package/dist/esm/errors/getRefdFromFlatFieldErrors.mjs +8 -0
  8. package/dist/esm/errors/isFlatFieldErrorEntryRefd.mjs +5 -0
  9. package/dist/esm/form/Form.mjs +53 -57
  10. package/dist/esm/form/_FormBase.mjs +8 -15
  11. package/dist/esm/form/context/group/index.mjs +9 -9
  12. package/dist/esm/form/context/utils/RhfUtilsContextProvider.mjs +12 -15
  13. package/dist/esm/form/context/utils/useRhfUtilsContext.mjs +3 -3
  14. package/dist/esm/utils/createContext.mjs +10 -6
  15. package/dist/types/client/config/RhfUtilsClientConfig.d.ts +2 -6
  16. package/dist/types/client/config/useRhfUtilsClientConfigContext.d.ts +1 -1
  17. package/dist/types/client/zod/context/useRhfUtilsClientForZodContext.d.ts +1 -1
  18. package/dist/types/errors/flat/context/useFlatFieldErrorsContext.d.ts +2 -1
  19. package/dist/types/errors/flat/context/useFlatFieldErrorsContextOutput.d.ts +2 -2
  20. package/dist/types/errors/getRefdFromFlatFieldErrors.d.ts +2 -0
  21. package/dist/types/errors/isFlatFieldErrorEntryRefd.d.ts +1 -1
  22. package/dist/types/form/RhfUtilsFormOptions.d.ts +8 -4
  23. package/dist/types/form/_FormBase.d.ts +2 -4
  24. package/dist/types/form/context/group/index.d.ts +1 -1
  25. package/dist/types/submit/useResetFormOnSubmitSuccessful.d.ts +2 -2
  26. package/dist/types/utils/createContext.d.ts +6 -2
  27. 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: true,
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, // strongly-typed controller
57
- FormSubmitError, // strongly-typed error class
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: ({ isDevelopment, hasOrphans }) =>
75
+ console: ({ hasOrphans }) =>
78
76
  (hasOrphans && { type: 'error' }) || // report all orphan errors
79
- (isDevelopment && { type: 'debug' }), // facilitate debugging on dev
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: ({ isDevelopment, hasOrphans }) => isDevelopment && hasOrphans,
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, strongly-typed FormSubmitError class)
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, // strongly-typed controller
133
- FormSubmitError, // strongly-typed error class
130
+ Controller, // strictly-typed controller
131
+ FormSubmitError, // strictly-typed error class
134
132
  }) => (
135
133
  <>
136
134
  <Controller
137
- name="email" // strongly-typed field name
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 strongly-typed, so it only allows field names in schema and `root`/`root.{string}` keys.
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
- * Control visibility of certain items via your own classes and styles.
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?: Parameters<
211
- typeof useResetFormAfterSubmitSuccessful
212
- >[0];
207
+ resetFormAfterSubmitSuccessful?: UseResetFormAfterSubmitSuccessfulOptions;
213
208
 
214
- /** Control dev tool options. (Lazy-loaded when `isDevelopment` is `true` and truthy value supplied. Zero bundle size in prod.) */
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 optionally exposed in a few places.
262
+ Orphans are exposed in a few places.
265
263
 
266
- - In errors outputted via console. (Configured via `RhfUtilsClientConfig['errors']['output']`.)
267
- - And `useFlatFieldErrorsContext()` hook, which returns an object with divided into `all`, `root`, and `orphans` errors.
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 t from "../../utils/createContext.mjs";
2
- const [
3
- o,
4
- ,
5
- i
6
- ] = t();
1
+ import e from "../../utils/createContext.mjs";
2
+ const {
3
+ Provider: o,
4
+ useMaybe: i
5
+ } = e();
7
6
  export {
8
- i as _RhfUtilsClientConfigContextProvider,
9
- o as default
7
+ o as _RhfUtilsClientConfigContextProvider,
8
+ i as default
10
9
  };
@@ -1,6 +1,9 @@
1
- import t from "../../../utils/createContext.mjs";
2
- const [, e, r] = t();
1
+ import e from "../../../utils/createContext.mjs";
2
+ const {
3
+ Provider: o,
4
+ useRequired: r
5
+ } = e();
3
6
  export {
4
- r as _RhfUtilsClientForZodContextProvider,
5
- e as default
7
+ o as _RhfUtilsClientForZodContextProvider,
8
+ r as default
6
9
  };
@@ -1,21 +1,23 @@
1
- import { jsx as m } from "react/jsx-runtime";
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 "../../orphan/getOrphansFromFlatFieldErrors.mjs";
5
- import F from "../../root/getRootsFromFlatFieldErrors.mjs";
6
- import a from "../getFlatFieldErrors.mjs";
7
- import { _FormErrorsFlatContextProvider as n } from "./useFlatFieldErrorsContext.mjs";
8
- const g = ({
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 = a(e), s = {
13
+ const { errors: e } = i(), r = n(e), m = {
13
14
  all: r,
14
- roots: F(r),
15
- orphans: o.current ? l(r, o.current) : {}
15
+ fields: l(r),
16
+ roots: a(r),
17
+ orphans: o.current ? F(r, o.current) : {}
16
18
  };
17
- return /* @__PURE__ */ m(n, { value: s, children: t });
19
+ return /* @__PURE__ */ s(p, { value: m, children: t });
18
20
  };
19
21
  export {
20
- g as default
22
+ h as default
21
23
  };
@@ -1,6 +1,9 @@
1
- import t from "../../../utils/createContext.mjs";
2
- const [, r, e] = t(), s = r;
1
+ import r from "../../../utils/createContext.mjs";
2
+ const {
3
+ Provider: o,
4
+ useRequired: e
5
+ } = r(), s = e;
3
6
  export {
4
- e as _FormErrorsFlatContextProvider,
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 c from "../../../utils/isEmptyObject.mjs";
3
+ import l from "../../../utils/isEmptyObject.mjs";
4
4
  import F from "../../output/consoleErrors.mjs";
5
5
  import x from "./useFlatFieldErrorsContext.mjs";
6
- const g = (e) => {
7
- const i = E(), o = x();
6
+ const n = (r) => {
7
+ const u = E(), t = x();
8
8
  h.useEffect(() => {
9
- var p, r, l, u, t, a;
10
- if (c(o.all))
9
+ var m, a;
10
+ if (l(t.all))
11
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
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 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";
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
- g as default
27
+ n as default
29
28
  };
@@ -0,0 +1,8 @@
1
+ import r from "./flat/filterFlatFieldErrors.mjs";
2
+ import t from "./isFlatFieldErrorEntryRefd.mjs";
3
+ const l = r(
4
+ t
5
+ );
6
+ export {
7
+ l as default
8
+ };
@@ -0,0 +1,5 @@
1
+ import e from "./isFieldErrorRefd.mjs";
2
+ const t = ([, r]) => e(r);
3
+ export {
4
+ t as default
5
+ };
@@ -1,98 +1,94 @@
1
- import { jsxs as T, jsx as l } from "react/jsx-runtime";
1
+ import { jsxs as _, jsx as d } from "react/jsx-runtime";
2
2
  import "react";
3
- import { useFormContext as _ } from "react-hook-form";
4
- import D from "../client/config/useRhfUtilsClientConfigContext.mjs";
5
- import N from "../devtool/LazyDevTool.mjs";
6
- import { FormSubmitError as C } from "../submit/error/FormSubmitError.mjs";
7
- import P from "../submit/error/setCtxErrorsByFormSubmitErrors.mjs";
8
- import S from "./_Controller.mjs";
9
- import w from "./_FormBase.mjs";
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: p,
12
+ formRef: m,
13
13
  //
14
14
  onSubmit: c,
15
- onSubmitError: d,
16
- onSubmitInvalid: v,
17
- Children: x,
15
+ onSubmitError: C,
16
+ onSubmitInvalid: b,
17
+ Children: h,
18
18
  //
19
- form: m,
19
+ form: p,
20
20
  utils: o,
21
21
  //
22
- children: b
22
+ children: i
23
23
  }) {
24
- const n = _(), t = D(), F = async (e) => {
25
- o != null && o.stopSubmitPropagation && e.stopPropagation();
24
+ const n = v(), r = N(), j = async (t) => {
25
+ o != null && o.stopSubmitPropagation && t.stopPropagation();
26
26
  try {
27
- await n.handleSubmit(j, v)(e);
28
- } catch (r) {
29
- B(r, e);
27
+ await n.handleSubmit(B, b)(t);
28
+ } catch (e) {
29
+ T(e, t);
30
30
  }
31
- }, j = (e, r) => c == null ? void 0 : c(
32
- e,
31
+ }, B = (t, e) => c == null ? void 0 : c(
32
+ t,
33
33
  {
34
34
  formId: s,
35
- formRef: p,
35
+ formRef: m,
36
36
  context: n,
37
37
  utils: o,
38
- FormSubmitError: C
38
+ FormSubmitError: x
39
39
  },
40
- r
41
- ), B = (e, r) => {
42
- var y;
43
- const a = e instanceof C ? (
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
- e.errors
45
+ t.errors
46
46
  ) : (
47
47
  // if error is not FormSubmitError, consumer can provide global handler
48
- (y = t == null ? void 0 : t.onSubmitUnknownError) == null ? void 0 : y.call(t, e)
48
+ (F = r == null ? void 0 : r.onSubmitUnknownError) == null ? void 0 : F.call(r, t)
49
49
  );
50
- a && P(n, a), d == null || d(
51
- e,
50
+ a && S(n, a), C == null || C(
51
+ t,
52
52
  {
53
53
  formId: s,
54
- formRef: p,
54
+ formRef: m,
55
55
  context: n,
56
56
  utils: o
57
57
  },
58
- r
58
+ e
59
59
  );
60
- }, h = {
60
+ }, l = {
61
61
  formId: s,
62
- formRef: p,
62
+ formRef: m,
63
63
  context: n,
64
64
  utils: o,
65
- Controller: S,
66
- FormSubmitError: C
67
- }, i = (e) => {
65
+ Controller: w,
66
+ FormSubmitError: x
67
+ }, y = (t) => {
68
68
  var a;
69
- const r = (a = t == null ? void 0 : t.Children) == null ? void 0 : a[e];
70
- return r && /* @__PURE__ */ l(r, { ...h });
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__ */ T(
73
- w,
72
+ return /* @__PURE__ */ _(
73
+ E,
74
74
  {
75
75
  noValidate: !0,
76
- style: {
77
- position: "relative"
78
- },
79
- config: t,
80
- formRef: p,
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
- i("top"),
86
- (o == null ? void 0 : o.devTool) && /* @__PURE__ */ l(
87
- N,
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
- x && /* @__PURE__ */ l(x, { ...h }),
94
- b,
95
- i("bottom")
89
+ h && /* @__PURE__ */ d(h, { ...l }),
90
+ i,
91
+ y("bottom")
96
92
  ]
97
93
  }
98
94
  );
@@ -1,18 +1,11 @@
1
- import { jsxs as p, jsx as s } from "react/jsx-runtime";
1
+ import { jsx as m } from "react/jsx-runtime";
2
2
  import "react";
3
- const l = ({
4
- config: e,
5
- formRef: t,
6
- antiCsrfToken: r,
7
- children: o,
8
- ...m
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
- l as default
10
+ s as default
18
11
  };
@@ -1,11 +1,11 @@
1
- import o from "../../../utils/createContext.mjs";
2
- const [
3
- t,
4
- e,
5
- m
6
- ] = o();
1
+ import e from "../../../utils/createContext.mjs";
2
+ const {
3
+ Provider: r,
4
+ useRequired: t,
5
+ useMaybe: u
6
+ } = e();
7
7
  export {
8
- m as _FormGroupContextProvider,
9
- e as _useFormGroupContext,
10
- t as _useFormGroupContextMaybe
8
+ r as _FormGroupContextProvider,
9
+ t as _useFormGroupContext,
10
+ u as _useFormGroupContextMaybe
11
11
  };
@@ -1,33 +1,30 @@
1
- import { jsx as f } from "react/jsx-runtime";
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 v } from "./useRhfUtilsContext.mjs";
9
- const y = ({
10
- formId: l,
8
+ import { _RhfUtilsContextProvider as d } from "./useRhfUtilsContext.mjs";
9
+ const M = ({
10
+ formId: a,
11
11
  formRef: t,
12
- onSubmitSuccessfulAndReset: m,
12
+ onSubmitSuccessfulAndReset: e,
13
13
  options: r,
14
- children: a
14
+ children: f
15
15
  }) => {
16
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, {
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) || !!m
23
+ (r == null ? void 0 : r.resetFormAfterSubmitSuccessful) || !!e
27
24
  ), x(() => {
28
- m == null || m();
29
- }), /* @__PURE__ */ f(v, { value: { formId: l, formRef: t, options: r }, children: a });
25
+ e == null || e();
26
+ }), /* @__PURE__ */ l(d, { value: { formId: a, formRef: t, options: r }, children: f });
30
27
  };
31
28
  export {
32
- y as default
29
+ M as default
33
30
  };
@@ -1,6 +1,6 @@
1
1
  import t from "../../../utils/createContext.mjs";
2
- const [, e, n] = t(), o = e, f = o;
2
+ const { Provider: r, useRequired: e } = t(), o = e, i = o;
3
3
  export {
4
- n as _RhfUtilsContextProvider,
5
- f as default
4
+ r as _RhfUtilsContextProvider,
5
+ i as default
6
6
  };
@@ -1,13 +1,17 @@
1
1
  import r from "react";
2
- function u() {
3
- const t = r.createContext(void 0), e = () => r.useContext(t);
4
- return [e, () => {
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
- }, t.Provider];
8
+ };
9
+ return {
10
+ Provider: e.Provider,
11
+ useMaybe: t,
12
+ useRequired: n
13
+ };
10
14
  }
11
15
  export {
12
- u as default
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
- * Default global options settings.
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 useRhfUtilsClientConfigMaybeContext: () => RhfUtilsClientConfig | undefined, _RhfUtilsClientConfigContextProvider: import('react').Provider<RhfUtilsClientConfig | undefined>;
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 useRhfUtilsClientForZodContext: () => import('../..').CreateRhfUtilsClient<import('../ZodTypeFieldValues').ZodTypeFieldValues, "_input", "_output">, _RhfUtilsClientForZodContextProvider: import('react').Provider<import('../..').CreateRhfUtilsClient<import('../ZodTypeFieldValues').ZodTypeFieldValues, "_input", "_output"> | undefined>;
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 useFlatFieldErrorsContext: () => FlatFieldErrorsContext, _FormErrorsFlatContextProvider: import('react').Provider<FlatFieldErrorsContext | undefined>;
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 { RhfUtilsClientConfig } from '../../../client/config/RhfUtilsClientConfig';
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: RhfUtilsClientConfig) => void;
6
+ declare const useFlatFieldErrorsContextOutput: (config?: FlatFieldErrorsOutputConfig) => void;
7
7
  export default useFlatFieldErrorsContextOutput;
@@ -0,0 +1,2 @@
1
+ declare const getRefdFromFlatFieldErrors: (errors: import('./flat/types').FlatFieldErrors) => import('./flat/types').FlatFieldErrors;
2
+ export default getRefdFromFlatFieldErrors;
@@ -1,7 +1,7 @@
1
1
  import { FlatFieldErrorEntry } from './flat/types';
2
2
 
3
3
  /**
4
- * Util wrapper for {@link isFieldErrorRefd} for usage with {@link FlatFieldErrorEntry}.
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 { default as useResetFormAfterSubmitSuccessful } from '../submit/useResetFormOnSubmitSuccessful';
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
- * Control visibility of certain items via your own classes and styles.
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?: Parameters<typeof useResetFormAfterSubmitSuccessful>[0];
24
- /** Control dev tool options. (Lazy-loaded when `isDevelopment` is `true` and truthy value supplied. Zero bundle size in prod.) */
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: ({ config, formRef, antiCsrfToken, children, ...props }: FormBaseProps) => import("react/jsx-runtime").JSX.Element;
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 _useFormGroupContextMaybe: () => FormGroupContext | undefined, _useFormGroupContext: () => FormGroupContext, _FormGroupContextProvider: import('react').Provider<FormGroupContext | undefined>;
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 Options = false | undefined | true | {
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: Options) => void;
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 strongly-typed context that throws error if no provider is found.
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>(): readonly [() => T | undefined, () => T & ({} | null), React.Provider<T | undefined>];
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;
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.116",
5
+ "version": "0.0.117",
6
6
  "description": "Integration utilities for react-hook-form.",
7
7
  "type": "module",
8
8
  "sideEffects": false,