@paragrav/rhf-utils 0.0.92 → 0.0.94

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 (31) hide show
  1. package/dist/esm/client/config/useRhfUtilsClientConfigContext.mjs +10 -0
  2. package/dist/esm/client/index.mjs +3 -4
  3. package/dist/esm/client/zod/context/RhfUtilsClientForZodContextProvider.mjs +12 -11
  4. package/dist/esm/client/zod/context/RhfUtilsZodFormWithProviders.mjs +12 -0
  5. package/dist/esm/client/zod/context/useRhfUtilsClientForZodContext.mjs +3 -4
  6. package/dist/esm/client/zod/context/useRhfUtilsZodForm.mjs +5 -0
  7. package/dist/esm/client/zod/createRhfUtilsClientForZod.mjs +2 -2
  8. package/dist/esm/devtool/LazyDevTool.mjs +14 -7
  9. package/dist/esm/exports.mjs +80 -79
  10. package/dist/esm/form/Form.mjs +62 -55
  11. package/dist/esm/form/context/utils/FormUtilsContextProvider.mjs +28 -28
  12. package/dist/esm/form/useForm.mjs +13 -15
  13. package/dist/types/client/{config.d.ts → config/RhfUtilsClientConfig.d.ts} +9 -5
  14. package/dist/types/client/config/useRhfUtilsClientConfigContext.d.ts +5 -0
  15. package/dist/types/client/index.d.ts +2 -2
  16. package/dist/types/client/zod/context/RhfUtilsClientForZodContextProvider.d.ts +2 -2
  17. package/dist/types/client/zod/context/RhfUtilsZodFormWithProviders.d.ts +9 -0
  18. package/dist/types/client/zod/context/useRhfUtilsClientForZodContext.d.ts +2 -8
  19. package/dist/types/client/zod/context/useRhfUtilsZodForm.d.ts +9 -0
  20. package/dist/types/client/zod/createRhfUtilsClientForZod.d.ts +1 -1
  21. package/dist/types/devtool/LazyDevTool.d.ts +3 -1
  22. package/dist/types/exports.d.ts +4 -3
  23. package/dist/types/form/Form.d.ts +2 -2
  24. package/dist/types/form/_FormBase.d.ts +2 -2
  25. package/dist/types/form/useForm.d.ts +1 -3
  26. package/package.json +1 -7
  27. package/dist/esm/env-conditions/production.mjs +0 -4
  28. package/dist/types/env-conditions/development.d.ts +0 -7
  29. package/dist/types/env-conditions/production.d.ts +0 -1
  30. package/dist/types/form/_Form.d.ts +0 -11
  31. package/dist/types/form/_FormProviders.d.ts +0 -12
@@ -0,0 +1,10 @@
1
+ import t from "../../utils/createContext.mjs";
2
+ const [
3
+ o,
4
+ ,
5
+ i
6
+ ] = t();
7
+ export {
8
+ i as _RhfUtilsClientConfigContextProvider,
9
+ o as default
10
+ };
@@ -19,10 +19,9 @@ const v = (s) => (r) => {
19
19
  FormWithProviders: l(s, r)
20
20
  };
21
21
  }, d = (s, r) => function(n, o) {
22
- var t, e, m, u, f;
22
+ var t, e, m, f, u;
23
23
  return {
24
24
  ...o,
25
- config: r,
26
25
  rhf: {
27
26
  ...(t = r.defaultOptions) == null ? void 0 : t.rhf,
28
27
  ...o.rhf,
@@ -32,8 +31,8 @@ const v = (s) => (r) => {
32
31
  ...(e = r.defaultOptions) == null ? void 0 : e.form,
33
32
  ...o.options,
34
33
  classNames: [
35
- ...((u = (m = r.defaultOptions) == null ? void 0 : m.form) == null ? void 0 : u.classNames) ?? [],
36
- ...((f = o.options) == null ? void 0 : f.classNames) ?? []
34
+ ...((f = (m = r.defaultOptions) == null ? void 0 : m.form) == null ? void 0 : f.classNames) ?? [],
35
+ ...((u = o.options) == null ? void 0 : u.classNames) ?? []
37
36
  ]
38
37
  }
39
38
  };
@@ -1,14 +1,15 @@
1
- import { jsx as e } from "react/jsx-runtime";
2
- import i from "react";
3
- import n from "../createRhfUtilsClientForZod.mjs";
4
- import { _RhfUtilsClientForZodContextProvider as l } from "./useRhfUtilsClientForZodContext.mjs";
5
- const s = ({
6
- config: t,
7
- children: o
1
+ import { jsx as o } from "react/jsx-runtime";
2
+ import e from "react";
3
+ import { _RhfUtilsClientConfigContextProvider as l } from "../../config/useRhfUtilsClientConfigContext.mjs";
4
+ import f from "../createRhfUtilsClientForZod.mjs";
5
+ import { _RhfUtilsClientForZodContextProvider as s } from "./useRhfUtilsClientForZodContext.mjs";
6
+ const d = ({
7
+ config: r,
8
+ children: i
8
9
  }) => {
9
- const [r] = i.useState(() => n(t));
10
- return /* @__PURE__ */ e(l, { value: r, children: o });
11
- }, a = s;
10
+ const [t] = e.useState(r), [n] = e.useState(() => f(t));
11
+ return /* @__PURE__ */ o(l, { value: t, children: /* @__PURE__ */ o(s, { value: n, children: i }) });
12
+ }, p = d;
12
13
  export {
13
- a as default
14
+ p as default
14
15
  };
@@ -0,0 +1,12 @@
1
+ import { jsx as i } from "react/jsx-runtime";
2
+ import e from "./useRhfUtilsClientForZodContext.mjs";
3
+ function f({
4
+ schema: o,
5
+ form: t
6
+ }) {
7
+ const r = e();
8
+ return /* @__PURE__ */ i(r.FormWithProviders, { schema: o, ...t });
9
+ }
10
+ export {
11
+ f as default
12
+ };
@@ -1,7 +1,6 @@
1
- import s from "../../../utils/createContext.mjs";
2
- const [, t, n] = s(), i = t, l = (o, e) => t().useForm(o, e);
1
+ import t from "../../../utils/createContext.mjs";
2
+ const [, o, n] = t(), r = o;
3
3
  export {
4
4
  n as _RhfUtilsClientForZodContextProvider,
5
- i as default,
6
- l as useRhfUtilsZodForm
5
+ r as default
7
6
  };
@@ -0,0 +1,5 @@
1
+ import s from "./useRhfUtilsClientForZodContext.mjs";
2
+ const e = (o, t) => s().useForm(o, t), f = e;
3
+ export {
4
+ f as default
5
+ };
@@ -1,7 +1,7 @@
1
1
  import { zodResolver as t } from "@hookform/resolvers/zod";
2
2
  import "zod";
3
3
  import { createRhfUtilsClient as o } from "../index.mjs";
4
- const e = o(t), s = e;
4
+ const l = o(t);
5
5
  export {
6
- s as default
6
+ l as default
7
7
  };
@@ -1,12 +1,19 @@
1
- import "react/jsx-runtime";
2
- import t from "react";
3
- import "react-hook-form";
4
- t.lazy(
1
+ import { jsx as t } from "react/jsx-runtime";
2
+ import e from "react";
3
+ import { useFormContext as n } from "react-hook-form";
4
+ const a = e.lazy(
5
5
  () => import("@hookform/devtools").then((o) => ({
6
6
  default: o.DevTool
7
7
  }))
8
- );
9
- const e = (o) => null, p = e;
8
+ ), s = ({
9
+ isDevelopment: o,
10
+ ...l
11
+ }) => {
12
+ if (!o)
13
+ return null;
14
+ const { control: r } = n();
15
+ return /* @__PURE__ */ t(e.Suspense, { fallback: null, children: /* @__PURE__ */ t(a, { control: r, ...l }) });
16
+ }, u = s;
10
17
  export {
11
- p as default
18
+ u as default
12
19
  };
@@ -1,89 +1,90 @@
1
1
  import { default as e } from "./client/zod/context/RhfUtilsClientForZodContextProvider.mjs";
2
- import { default as s, useRhfUtilsZodForm as a } from "./client/zod/context/useRhfUtilsClientForZodContext.mjs";
3
- import { default as f } from "./client/zod/createRhfUtilsClientForZod.mjs";
4
- import { default as l } from "./devtool/LazyDevTool.mjs";
5
- import { default as p } from "./errors/flat/context/FlatFieldErrorsContextProvider.mjs";
6
- import { default as F } from "./errors/flat/context/useFlatFieldErrorsContext.mjs";
7
- import { default as n } from "./errors/flat/FlatFieldErrorsList.mjs";
8
- import { default as C } from "./errors/message/FormErrorMessage.mjs";
9
- import { default as c } from "./errors/message/FormErrorMessageByPath.mjs";
10
- import { default as b } from "./errors/nonfield/FormNonFieldErrorMarker.mjs";
11
- import { default as R } from "./errors/nonfield/FormNonFieldErrorMarkerHtmlAttribute.mjs";
12
- import { default as M } from "./errors/orphan/useFormHasOnlyOrphanFieldErrorsMemo.mjs";
2
+ import { default as s } from "./client/zod/context/RhfUtilsZodFormWithProviders.mjs";
3
+ import { default as u } from "./client/zod/context/useRhfUtilsClientForZodContext.mjs";
4
+ import { default as m } from "./client/zod/context/useRhfUtilsZodForm.mjs";
5
+ import { default as d } from "./devtool/LazyDevTool.mjs";
6
+ import { default as x } from "./errors/flat/context/FlatFieldErrorsContextProvider.mjs";
7
+ import { default as i } from "./errors/flat/context/useFlatFieldErrorsContext.mjs";
8
+ import { default as E } from "./errors/flat/FlatFieldErrorsList.mjs";
9
+ import { default as h } from "./errors/message/FormErrorMessage.mjs";
10
+ import { default as b } from "./errors/message/FormErrorMessageByPath.mjs";
11
+ import { default as P } from "./errors/nonfield/FormNonFieldErrorMarker.mjs";
12
+ import { default as y } from "./errors/nonfield/FormNonFieldErrorMarkerHtmlAttribute.mjs";
13
+ import { default as O } from "./errors/orphan/useFormHasOnlyOrphanFieldErrorsMemo.mjs";
13
14
  import { default as G } from "./errors/orphan/useOrphanFormErrorsMemo.mjs";
14
- import { default as I } from "./errors/orphan/useOrphanFormErrorsToConsole.mjs";
15
- import { default as g } from "./errors/root/RootErrorsListFromFlatFieldErrorsContext.mjs";
16
- import { default as B } from "./errors/root/useRootFormFieldErrorsMemo.mjs";
17
- import { default as A } from "./errors/useFormErrorConsoleDebug.mjs";
18
- import { default as D } from "./errors/useFormErrorsEffect.mjs";
19
- import { default as H } from "./errors/useFormErrorsIfAny.mjs";
15
+ import { default as T } from "./errors/orphan/useOrphanFormErrorsToConsole.mjs";
16
+ import { default as k } from "./errors/root/RootErrorsListFromFlatFieldErrorsContext.mjs";
17
+ import { default as U } from "./errors/root/useRootFormFieldErrorsMemo.mjs";
18
+ import { default as Z } from "./errors/useFormErrorConsoleDebug.mjs";
19
+ import { default as L } from "./errors/useFormErrorsEffect.mjs";
20
+ import { default as N } from "./errors/useFormErrorsIfAny.mjs";
20
21
  import { default as q } from "./errors/useFormErrorsTransformMemo.mjs";
21
- import { default as W } from "./errors/useFormRequestSubmit.mjs";
22
- import { default as w } from "./form/Form.mjs";
23
- import { default as K } from "./form/FormProviders.mjs";
24
- import { default as V } from "./form/FormWithProviders.mjs";
25
- import { default as Y } from "./form/useForm.mjs";
26
- import { default as $ } from "./form/context/utils/FormUtilsContextProvider.mjs";
27
- import { default as or } from "./form/context/utils/useFormUtilsContext.mjs";
28
- import { default as tr } from "./form/context/group/FormGroupContextProvider.mjs";
29
- import { default as ar } from "./form/context/group/useFormGroupChildIsMountedTracker.mjs";
30
- import { default as fr } from "./form/context/group/useFormGroupChildIsSubmittingTracker.mjs";
31
- import { default as lr } from "./form/context/group/useFormGroupChildTracker.mjs";
32
- import { default as pr } from "./form/context/group/useFormGroupIsAnyBusy.mjs";
33
- import { default as Fr } from "./form/context/group/useFormGroupIsChildBusy.mjs";
34
- import { default as nr } from "./form/context/group/useFormGroupIsParentBusy.mjs";
35
- import { default as Cr } from "./form/context/group/useFormGroupParentTracker.mjs";
36
- import { default as cr } from "./form/context/group/useFormOrParentIsBusy.mjs";
37
- import { default as br } from "./form/utils/getSubmitterButtonData.mjs";
38
- import { FormSubmitError as Rr } from "./submit/error/FormSubmitError.mjs";
39
- import { default as Mr } from "./submit/useFormOnSubmitSuccessful.mjs";
22
+ import { default as j } from "./errors/useFormRequestSubmit.mjs";
23
+ import { default as J } from "./form/Form.mjs";
24
+ import { default as Q } from "./form/FormProviders.mjs";
25
+ import { default as X } from "./form/FormWithProviders.mjs";
26
+ import { default as _ } from "./form/useForm.mjs";
27
+ import { default as rr } from "./form/context/utils/FormUtilsContextProvider.mjs";
28
+ import { default as er } from "./form/context/utils/useFormUtilsContext.mjs";
29
+ import { default as sr } from "./form/context/group/FormGroupContextProvider.mjs";
30
+ import { default as ur } from "./form/context/group/useFormGroupChildIsMountedTracker.mjs";
31
+ import { default as mr } from "./form/context/group/useFormGroupChildIsSubmittingTracker.mjs";
32
+ import { default as dr } from "./form/context/group/useFormGroupChildTracker.mjs";
33
+ import { default as xr } from "./form/context/group/useFormGroupIsAnyBusy.mjs";
34
+ import { default as ir } from "./form/context/group/useFormGroupIsChildBusy.mjs";
35
+ import { default as Er } from "./form/context/group/useFormGroupIsParentBusy.mjs";
36
+ import { default as hr } from "./form/context/group/useFormGroupParentTracker.mjs";
37
+ import { default as br } from "./form/context/group/useFormOrParentIsBusy.mjs";
38
+ import { default as Pr } from "./form/utils/getSubmitterButtonData.mjs";
39
+ import { FormSubmitError as yr } from "./submit/error/FormSubmitError.mjs";
40
+ import { default as Or } from "./submit/useFormOnSubmitSuccessful.mjs";
40
41
  import { default as Gr } from "./submit/useFormOnSubmitSuccessfulAndReset.mjs";
41
- import { default as Ir } from "./submit/useResetFormOnSubmitError.mjs";
42
- import { default as gr } from "./submit/useResetFormOnSubmitSuccessful.mjs";
43
- import { default as Br } from "./submit/useSubmitFormOnChange.mjs";
42
+ import { default as Tr } from "./submit/useResetFormOnSubmitError.mjs";
43
+ import { default as kr } from "./submit/useResetFormOnSubmitSuccessful.mjs";
44
+ import { default as Ur } from "./submit/useSubmitFormOnChange.mjs";
44
45
  export {
45
- p as FlatFieldErrorsContextProvider,
46
- n as FlatFieldErrorsList,
47
- w as Form,
48
- C as FormErrorMessage,
49
- c as FormErrorMessageByPath,
50
- tr as FormGroupContextProvider,
51
- b as FormNonFieldErrorMarker,
52
- R as FormNonFieldErrorMarkerHtmlAttribute,
53
- K as FormProviders,
54
- Rr as FormSubmitError,
55
- $ as FormUtilsContextProvider,
56
- V as FormWithProviders,
57
- l as LazyDevTool,
46
+ x as FlatFieldErrorsContextProvider,
47
+ E as FlatFieldErrorsList,
48
+ J as Form,
49
+ h as FormErrorMessage,
50
+ b as FormErrorMessageByPath,
51
+ sr as FormGroupContextProvider,
52
+ P as FormNonFieldErrorMarker,
53
+ y as FormNonFieldErrorMarkerHtmlAttribute,
54
+ Q as FormProviders,
55
+ yr as FormSubmitError,
56
+ rr as FormUtilsContextProvider,
57
+ X as FormWithProviders,
58
+ d as LazyDevTool,
58
59
  e as RhfUtilsClientForZodContextProvider,
59
- g as RootErrorsListFromFlatFieldErrorsContext,
60
- f as createRhfUtilsClientForZod,
61
- br as getSubmitterButtonData,
62
- F as useFlatFieldErrorsContext,
63
- Y as useForm,
64
- A as useFormErrorConsoleDebug,
65
- D as useFormErrorsEffect,
66
- H as useFormErrorsIfAny,
60
+ s as RhfUtilsZodFormWithProviders,
61
+ k as RootErrorsListFromFlatFieldErrorsContext,
62
+ Pr as getSubmitterButtonData,
63
+ i as useFlatFieldErrorsContext,
64
+ _ as useForm,
65
+ Z as useFormErrorConsoleDebug,
66
+ L as useFormErrorsEffect,
67
+ N as useFormErrorsIfAny,
67
68
  q as useFormErrorsTransformMemo,
68
- ar as useFormGroupChildIsMountedTracker,
69
- fr as useFormGroupChildIsSubmittingTracker,
70
- lr as useFormGroupChildTracker,
71
- pr as useFormGroupIsAnyBusy,
72
- Fr as useFormGroupIsChildBusy,
73
- nr as useFormGroupIsParentBusy,
74
- Cr as useFormGroupParentTracker,
75
- M as useFormHasOnlyOrphanFieldErrorsMemo,
76
- Mr as useFormOnSubmitSuccessful,
69
+ ur as useFormGroupChildIsMountedTracker,
70
+ mr as useFormGroupChildIsSubmittingTracker,
71
+ dr as useFormGroupChildTracker,
72
+ xr as useFormGroupIsAnyBusy,
73
+ ir as useFormGroupIsChildBusy,
74
+ Er as useFormGroupIsParentBusy,
75
+ hr as useFormGroupParentTracker,
76
+ O as useFormHasOnlyOrphanFieldErrorsMemo,
77
+ Or as useFormOnSubmitSuccessful,
77
78
  Gr as useFormOnSubmitSuccessfulAndReset,
78
- cr as useFormOrParentIsBusy,
79
- W as useFormRequestSubmit,
80
- or as useFormUtilsContext,
79
+ br as useFormOrParentIsBusy,
80
+ j as useFormRequestSubmit,
81
+ er as useFormUtilsContext,
81
82
  G as useOrphanFormErrorsMemo,
82
- I as useOrphanFormErrorsToConsole,
83
- gr as useResetFormAfterSubmitSuccessful,
84
- Ir as useResetFormOnSubmitError,
85
- s as useRhfUtilsClientForZodContext,
86
- a as useRhfUtilsZodForm,
87
- B as useRootFormFieldErrorsMemo,
88
- Br as useSubmitFormOnChange
83
+ T as useOrphanFormErrorsToConsole,
84
+ kr as useResetFormAfterSubmitSuccessful,
85
+ Tr as useResetFormOnSubmitError,
86
+ u as useRhfUtilsClientForZodContext,
87
+ m as useRhfUtilsZodForm,
88
+ U as useRootFormFieldErrorsMemo,
89
+ Ur as useSubmitFormOnChange
89
90
  };
@@ -1,84 +1,91 @@
1
- import { jsxs as S, jsx as C } from "react/jsx-runtime";
1
+ import { jsxs as F, jsx as o } from "react/jsx-runtime";
2
2
  import "react";
3
- import { useFormContext as T } from "react-hook-form";
4
- import v from "../devtool/LazyDevTool.mjs";
5
- import { FormSubmitError as E } from "../submit/error/FormSubmitError.mjs";
6
- import V from "../submit/error/setCtxErrorsByFormSubmitError.mjs";
7
- import w from "./_Controller.mjs";
8
- import z from "./_FormBase.mjs";
9
- function J({
10
- formId: B,
11
- formRef: u,
3
+ import { useFormContext as _ } from "react-hook-form";
4
+ import j from "../client/config/useRhfUtilsClientConfigContext.mjs";
5
+ import D from "../devtool/LazyDevTool.mjs";
6
+ import { FormSubmitError as N } from "../submit/error/FormSubmitError.mjs";
7
+ import P from "../submit/error/setCtxErrorsByFormSubmitError.mjs";
8
+ import S from "./_Controller.mjs";
9
+ import T from "./_FormBase.mjs";
10
+ function q({
11
+ formId: n,
12
+ formRef: C,
12
13
  //
13
- onSubmit: s,
14
- onSubmitError: h,
15
- onSubmitInvalid: F,
16
- Fields: x,
14
+ onSubmit: d,
15
+ onSubmitError: c,
16
+ onSubmitInvalid: y,
17
+ Fields: h,
17
18
  //
18
- form: d,
19
- options: r,
20
- config: a,
19
+ form: s,
20
+ options: t,
21
21
  //
22
- children: _
22
+ children: f
23
23
  }) {
24
- const l = T(), j = async (t) => {
25
- r != null && r.stopSubmitPropagation && t.stopPropagation();
24
+ const l = _(), e = j(), b = async (r) => {
25
+ t != null && t.stopSubmitPropagation && r.stopPropagation();
26
26
  try {
27
- await l.handleSubmit(N, F)(t);
28
- } catch (e) {
29
- P(e, t);
27
+ await l.handleSubmit(v, y)(r);
28
+ } catch (a) {
29
+ B(a, r);
30
30
  }
31
- }, N = (t, e) => s == null ? void 0 : s(
32
- t,
31
+ }, v = (r, a) => d == null ? void 0 : d(
32
+ r,
33
33
  l,
34
- e
35
- ), P = (t, e) => {
36
- var b;
37
- const m = t instanceof E ? (
34
+ a
35
+ ), B = (r, a) => {
36
+ var x;
37
+ const m = r instanceof N ? (
38
38
  // consumer can manually throw FormSubmitError (e.g., manual validation)
39
- t
39
+ r
40
40
  ) : (
41
41
  // if error is not FormSubmitError, consumer can provide global handler
42
- (b = a == null ? void 0 : a.onSubmitError) == null ? void 0 : b.call(a, t)
42
+ (x = e == null ? void 0 : e.onSubmitError) == null ? void 0 : x.call(e, r)
43
43
  );
44
- m && V(l, m), h == null || h(
45
- t,
44
+ m && P(l, m), c == null || c(
45
+ r,
46
46
  l,
47
- e
47
+ a
48
48
  );
49
- }, y = {
50
- formId: B,
51
- formRef: u,
49
+ }, i = {
50
+ formId: n,
51
+ formRef: C,
52
52
  ctx: l,
53
- options: r,
54
- Controller: w
55
- }, c = (t) => {
53
+ options: t,
54
+ Controller: S
55
+ }, u = (r) => {
56
56
  var m;
57
- const e = (m = a == null ? void 0 : a.Children) == null ? void 0 : m[t];
58
- return e && /* @__PURE__ */ C(e, { ...y });
57
+ const a = (m = e == null ? void 0 : e.Children) == null ? void 0 : m[r];
58
+ return a && /* @__PURE__ */ o(a, { ...i });
59
59
  };
60
- return /* @__PURE__ */ S(
61
- z,
60
+ return /* @__PURE__ */ F(
61
+ T,
62
62
  {
63
63
  noValidate: !0,
64
64
  style: {
65
65
  position: "relative"
66
66
  },
67
- config: a,
68
- formRef: u,
69
- ...d,
70
- className: [r == null ? void 0 : r.classNames, d == null ? void 0 : d.className].filter(Boolean).join(" "),
71
- onSubmit: j,
67
+ config: e,
68
+ formRef: C,
69
+ ...s,
70
+ className: [t == null ? void 0 : t.classNames, s == null ? void 0 : s.className].filter(Boolean).join(" "),
71
+ onSubmit: b,
72
72
  children: [
73
- c("top"),
74
- (r == null ? void 0 : r.devTool) !== "disabled" && /* @__PURE__ */ C(v, { placement: "top-right", ...r == null ? void 0 : r.devTool }),
75
- x && /* @__PURE__ */ C(x, { ...y }),
76
- _,
77
- c("bottom")
73
+ u("top"),
74
+ (t == null ? void 0 : t.devTool) !== "disabled" && /* @__PURE__ */ o(
75
+ D,
76
+ {
77
+ placement: "top-right",
78
+ isDevelopment: e == null ? void 0 : e.isDevelopment,
79
+ ...t == null ? void 0 : t.devTool
80
+ }
81
+ ),
82
+ h && /* @__PURE__ */ o(h, { ...i }),
83
+ f,
84
+ u("bottom")
78
85
  ]
79
86
  }
80
87
  );
81
88
  }
82
89
  export {
83
- J as default
90
+ q as default
84
91
  };
@@ -1,42 +1,42 @@
1
- import { jsx as l } from "react/jsx-runtime";
2
- import { isDevelopment as t } from "../../../env-conditions/production.mjs";
3
- import b from "../../../errors/orphan/useOrphanFormErrorsToConsole.mjs";
4
- import C from "../../../errors/useFormErrorConsoleDebug.mjs";
1
+ import { jsx as b } from "react/jsx-runtime";
2
+ import C from "../../../client/config/useRhfUtilsClientConfigContext.mjs";
3
+ import t from "../../../errors/orphan/useOrphanFormErrorsToConsole.mjs";
4
+ import f from "../../../errors/useFormErrorConsoleDebug.mjs";
5
5
  import O from "../../../errors/useFormRequestSubmit.mjs";
6
- import f from "../../../submit/useFormOnSubmitSuccessfulAndReset.mjs";
7
- import E from "../../../submit/useResetFormOnSubmitError.mjs";
8
- import d from "../../../submit/useResetFormOnSubmitSuccessful.mjs";
9
- import h from "../../../submit/useSubmitFormOnChange.mjs";
10
- import { _FormUtilsContextProvider as o } from "./useFormUtilsContext.mjs";
11
- function s({
12
- formId: u,
13
- formRef: m,
14
- onSubmitSuccessfulAndReset: e,
6
+ import E from "../../../submit/useFormOnSubmitSuccessfulAndReset.mjs";
7
+ import d from "../../../submit/useResetFormOnSubmitError.mjs";
8
+ import h from "../../../submit/useResetFormOnSubmitSuccessful.mjs";
9
+ import x from "../../../submit/useSubmitFormOnChange.mjs";
10
+ import { _FormUtilsContextProvider as g } from "./useFormUtilsContext.mjs";
11
+ function M({
12
+ formId: l,
13
+ formRef: e,
14
+ onSubmitSuccessfulAndReset: m,
15
15
  options: r,
16
16
  children: a
17
17
  }) {
18
- const F = O(m);
19
- return C(
20
- t
21
- ), b(
22
- m,
18
+ const u = C(), F = O(e);
19
+ return f(
20
+ (u == null ? void 0 : u.isDevelopment) && !(r != null && r.disableFormErrorConsoleDebug)
21
+ ), t(
22
+ e,
23
23
  !(r != null && r.disableOrphanFormErrorsToConsole)
24
- ), h(m, {
24
+ ), x(e, {
25
25
  disabled: !(r != null && r.submitOnChange)
26
- }), E({
26
+ }), d({
27
27
  disabled: !(r != null && r.resetValuesOnSubmitError)
28
- }), d(
29
- (r == null ? void 0 : r.resetFormAfterSubmitSuccessful) || !!e
30
- ), f(() => {
31
- e == null || e();
32
- }), /* @__PURE__ */ l(
33
- o,
28
+ }), h(
29
+ (r == null ? void 0 : r.resetFormAfterSubmitSuccessful) || !!m
30
+ ), E(() => {
31
+ m == null || m();
32
+ }), /* @__PURE__ */ b(
33
+ g,
34
34
  {
35
- value: { formId: u, formRef: m, requestSubmit: F, options: r },
35
+ value: { formId: l, formRef: e, requestSubmit: F, options: r },
36
36
  children: a
37
37
  }
38
38
  );
39
39
  }
40
40
  export {
41
- s as default
41
+ M as default
42
42
  };
@@ -1,19 +1,18 @@
1
1
  import m from "react";
2
- import { useForm as F } from "react-hook-form";
3
- import { FormSubmitError as a } from "../submit/error/FormSubmitError.mjs";
4
- const P = ({
2
+ import { useForm as d } from "react-hook-form";
3
+ import { FormSubmitError as F } from "../submit/error/FormSubmitError.mjs";
4
+ const a = ({
5
5
  onSubmit: t,
6
6
  onSubmitError: e,
7
7
  onSubmitInvalid: f,
8
8
  defaultValues: n,
9
9
  Fields: p,
10
- config: u,
11
- rhf: c,
12
- form: i,
13
- options: d
10
+ rhf: u,
11
+ form: c,
12
+ options: i
14
13
  }) => {
15
- const o = m.useId(), s = F({
16
- ...c,
14
+ const o = m.useId(), s = d({
15
+ ...u,
17
16
  defaultValues: n
18
17
  }), r = m.useRef(null);
19
18
  return {
@@ -24,7 +23,7 @@ const P = ({
24
23
  formId: o,
25
24
  formRef: r,
26
25
  rhfForm: s,
27
- options: d
26
+ options: i
28
27
  },
29
28
  formProps: {
30
29
  Fields: p,
@@ -33,12 +32,11 @@ const P = ({
33
32
  onSubmitInvalid: f,
34
33
  formId: o,
35
34
  formRef: r,
36
- config: u,
37
- form: i
35
+ form: c
38
36
  },
39
- FormSubmitError: a
37
+ FormSubmitError: F
40
38
  };
41
- }, $ = P;
39
+ }, I = a;
42
40
  export {
43
- $ as default
41
+ I as default
44
42
  };
@@ -1,10 +1,14 @@
1
1
  import { UseFormProps } from 'react-hook-form';
2
- import { FormChildrenSlots } from '../form/Form';
3
- import { UseFormFieldsProps } from '../form/useForm';
4
- import { UseFormOptions } from '../form/useFormOptions';
5
- import { FormSubmitError } from '../submit/error/FormSubmitError';
2
+ import { FormChildrenSlots } from '../../form/Form';
3
+ import { UseFormFieldsProps } from '../../form/useForm';
4
+ import { UseFormOptions } from '../../form/useFormOptions';
5
+ import { FormSubmitError } from '../../submit/error/FormSubmitError';
6
6
 
7
- export type ClientConfig = {
7
+ export type RhfUtilsClientConfig = {
8
+ /**
9
+ * Some behavior is dependent on environment. (e.g., console logging errors in dev)
10
+ */
11
+ isDevelopment?: boolean;
8
12
  /**
9
13
  * Default options for all forms. (Are overridden by form-specific options.)
10
14
  */
@@ -0,0 +1,5 @@
1
+ import { RhfUtilsClientConfig } from './RhfUtilsClientConfig';
2
+
3
+ declare const useRhfUtilsClientConfigMaybeContext: () => RhfUtilsClientConfig | undefined, _RhfUtilsClientConfigContextProvider: import('react').Provider<RhfUtilsClientConfig | undefined>;
4
+ export default useRhfUtilsClientConfigMaybeContext;
5
+ export { _RhfUtilsClientConfigContextProvider };
@@ -1,5 +1,5 @@
1
1
  import { Resolver } from 'react-hook-form';
2
- import { ClientConfig } from './config';
2
+ import { RhfUtilsClientConfig } from './config/RhfUtilsClientConfig';
3
3
  import { FormWithProvidersProps } from '../form/FormWithProviders';
4
4
  import { SafeFieldValues } from '../form/SafeFieldValues';
5
5
  import { UseFormProps, UseFormReturn } from '../form/useForm';
@@ -25,4 +25,4 @@ export type CreateRhfUtilsClient<TObjectSchema extends ObjectSchema<TObjectSchem
25
25
  *
26
26
  * (We need to use generics to generate types for schema resolver.)
27
27
  */
28
- export declare const createRhfUtilsClient: <TObjectSchema extends ObjectSchema<TObjectSchemaInputKey, TObjectSchemaOutputKey>, TObjectSchemaInputKey extends string, TObjectSchemaOutputKey extends string>(resolver: (schema: TObjectSchema) => Resolver<SafeFieldValues, unknown>) => (config: ClientConfig) => CreateRhfUtilsClient<TObjectSchema, TObjectSchemaInputKey, TObjectSchemaOutputKey>;
28
+ export declare const createRhfUtilsClient: <TObjectSchema extends ObjectSchema<TObjectSchemaInputKey, TObjectSchemaOutputKey>, TObjectSchemaInputKey extends string, TObjectSchemaOutputKey extends string>(resolver: (schema: TObjectSchema) => Resolver<SafeFieldValues, unknown>) => (config: RhfUtilsClientConfig) => CreateRhfUtilsClient<TObjectSchema, TObjectSchemaInputKey, TObjectSchemaOutputKey>;
@@ -1,8 +1,8 @@
1
1
  import { default as React } from 'react';
2
- import { ClientConfig } from '../../config';
2
+ import { RhfUtilsClientConfig } from '../../config/RhfUtilsClientConfig';
3
3
 
4
4
  type Props = React.PropsWithChildren<{
5
- config: ClientConfig;
5
+ config: RhfUtilsClientConfig;
6
6
  }>;
7
7
  declare const RhfUtilsClientForZodContextProvider: React.FC<Props>;
8
8
  export default RhfUtilsClientForZodContextProvider;
@@ -0,0 +1,9 @@
1
+ import { UseFormProps } from '../../../form/useForm';
2
+ import { ZodTypeFieldValues } from '../createRhfUtilsClientForZod';
3
+
4
+ type Props<TSchema extends ZodTypeFieldValues> = {
5
+ schema: TSchema;
6
+ form: Omit<UseFormProps<TSchema['_input'], TSchema['_output']>, 'config'>;
7
+ };
8
+ declare function RhfUtilsZodFormWithProviders<TSchema extends ZodTypeFieldValues>({ schema, form, }: Props<TSchema>): import("react/jsx-runtime").JSX.Element;
9
+ export default RhfUtilsZodFormWithProviders;
@@ -1,12 +1,6 @@
1
- import { UseFormProps } from '../../../form/useForm';
2
- import { default as createRhfUtilsClientForZod, ZodTypeFieldValues } from '../createRhfUtilsClientForZod';
1
+ import { default as createRhfUtilsClientForZod } from '../createRhfUtilsClientForZod';
3
2
 
4
3
  export type RhfUtilsClientForZodContext = ReturnType<typeof createRhfUtilsClientForZod>;
5
- declare const useRhfUtilsClientForZodContext: () => import('../..').CreateRhfUtilsClient<ZodTypeFieldValues, "_input", "_output">, _RhfUtilsClientForZodContextProvider: import('react').Provider<import('../..').CreateRhfUtilsClient<ZodTypeFieldValues, "_input", "_output"> | undefined>;
4
+ declare const useRhfUtilsClientForZodContext: () => import('../..').CreateRhfUtilsClient<import('../createRhfUtilsClientForZod').ZodTypeFieldValues, "_input", "_output">, _RhfUtilsClientForZodContextProvider: import('react').Provider<import('../..').CreateRhfUtilsClient<import('../createRhfUtilsClientForZod').ZodTypeFieldValues, "_input", "_output"> | undefined>;
6
5
  export default useRhfUtilsClientForZodContext;
7
6
  export { _RhfUtilsClientForZodContextProvider };
8
- export declare const useRhfUtilsZodForm: <TSchema extends ZodTypeFieldValues>(schema: TSchema, form: Omit<UseFormProps<TSchema['_input'], TSchema['_output']>, 'config'>) => import('../../../form/useForm').UseFormReturn<TSchema["_input"], TSchema["_output"]> & {
9
- FormWithProviders: import('react').FC<{
10
- children?: import('react').ReactNode;
11
- }>;
12
- };
@@ -0,0 +1,9 @@
1
+ import { UseFormProps } from '../../../form/useForm';
2
+ import { ZodTypeFieldValues } from '../createRhfUtilsClientForZod';
3
+
4
+ declare const useRhfUtilsZodForm: <TSchema extends ZodTypeFieldValues>(schema: TSchema, form: Omit<UseFormProps<TSchema['_input'], TSchema['_output']>, 'config'>) => import('../../../form/useForm').UseFormReturn<TSchema["_input"], TSchema["_output"]> & {
5
+ FormWithProviders: import('react').FC<{
6
+ children?: import('react').ReactNode;
7
+ }>;
8
+ };
9
+ export default useRhfUtilsZodForm;
@@ -2,5 +2,5 @@ import { z } from 'zod';
2
2
  import { SafeFieldValues } from '../../form/SafeFieldValues';
3
3
 
4
4
  export type ZodTypeFieldValues = z.ZodType<SafeFieldValues>;
5
- declare const createRhfUtilsClientForZod: (config: import('../config').ClientConfig) => import('..').CreateRhfUtilsClient<ZodTypeFieldValues, "_input", "_output">;
5
+ declare const createRhfUtilsClientForZod: (config: import('../config/RhfUtilsClientConfig').RhfUtilsClientConfig) => import('..').CreateRhfUtilsClient<ZodTypeFieldValues, "_input", "_output">;
6
6
  export default createRhfUtilsClientForZod;
@@ -1,7 +1,9 @@
1
1
  import { DevtoolUIProps } from '@hookform/devtools/dist/devToolUI';
2
2
  import { default as React } from 'react';
3
3
 
4
- export type LazyDevToolProps = Omit<DevtoolUIProps, 'control'>;
4
+ export type LazyDevToolProps = Omit<DevtoolUIProps, 'control'> & {
5
+ isDevelopment?: boolean;
6
+ };
5
7
  /**
6
8
  * Lazy-loaded RHF DevTool.
7
9
  */
@@ -1,8 +1,9 @@
1
1
  export type { Register } from './register';
2
- export type { ClientConfig } from './client/config';
2
+ export type { RhfUtilsClientConfig } from './client/config/RhfUtilsClientConfig';
3
3
  export { default as RhfUtilsClientForZodContextProvider } from './client/zod/context/RhfUtilsClientForZodContextProvider';
4
- export { default as useRhfUtilsClientForZodContext, useRhfUtilsZodForm, } from './client/zod/context/useRhfUtilsClientForZodContext';
5
- export { default as createRhfUtilsClientForZod } from './client/zod/createRhfUtilsClientForZod';
4
+ export { default as RhfUtilsZodFormWithProviders } from './client/zod/context/RhfUtilsZodFormWithProviders';
5
+ export { default as useRhfUtilsClientForZodContext } from './client/zod/context/useRhfUtilsClientForZodContext';
6
+ export { default as useRhfUtilsZodForm } from './client/zod/context/useRhfUtilsZodForm';
6
7
  export { default as LazyDevTool } from './devtool/LazyDevTool';
7
8
  export { default as FlatFieldErrorsContextProvider } from './errors/flat/context/FlatFieldErrorsContextProvider';
8
9
  export { default as useFlatFieldErrorsContext } from './errors/flat/context/useFlatFieldErrorsContext';
@@ -6,6 +6,6 @@ export type FormChildrenSlots = 'top' | 'bottom';
6
6
  export type FormProps<TFieldValues extends SafeFieldValues, TTransformedValues extends SafeFieldValues> = React.PropsWithChildren<{
7
7
  formId: string;
8
8
  formRef: React.RefObject<HTMLFormElement>;
9
- } & Pick<UseFormProps<TFieldValues, TTransformedValues>, 'onSubmit' | 'onSubmitError' | 'onSubmitInvalid' | 'Fields' | 'form' | 'options' | 'config'>>;
10
- declare function _Form<TFieldValues extends SafeFieldValues, TTransformedValues extends SafeFieldValues>({ formId, formRef, onSubmit, onSubmitError, onSubmitInvalid, Fields, form, options, config, children, }: FormProps<TFieldValues, TTransformedValues>): import("react/jsx-runtime").JSX.Element;
9
+ } & Pick<UseFormProps<TFieldValues, TTransformedValues>, 'onSubmit' | 'onSubmitError' | 'onSubmitInvalid' | 'Fields' | 'form' | 'options'>>;
10
+ declare function _Form<TFieldValues extends SafeFieldValues, TTransformedValues extends SafeFieldValues>({ formId, formRef, onSubmit, onSubmitError, onSubmitInvalid, Fields, form, options, children, }: FormProps<TFieldValues, TTransformedValues>): import("react/jsx-runtime").JSX.Element;
11
11
  export default _Form;
@@ -1,9 +1,9 @@
1
1
  import { default as React } from 'react';
2
- import { ClientConfig } from '../client/config';
2
+ import { RhfUtilsClientConfig } from '../client/config/RhfUtilsClientConfig';
3
3
 
4
4
  export type FormBaseProps = React.PropsWithChildren<React.HTMLAttributes<HTMLFormElement>> & {
5
- config?: ClientConfig;
6
5
  formRef: React.RefObject<HTMLFormElement>;
6
+ config?: RhfUtilsClientConfig;
7
7
  antiCsrfToken?: string;
8
8
  };
9
9
  declare const _FormBase: ({ config, formRef, antiCsrfToken, children, ...props }: FormBaseProps) => import("react/jsx-runtime").JSX.Element;
@@ -1,6 +1,5 @@
1
1
  import { default as React } from 'react';
2
2
  import { SubmitErrorHandler, UseFormProps as RhfUseFormProps, UseFormReturn as RhfUseFormReturn } from 'react-hook-form';
3
- import { ClientConfig } from '../client/config';
4
3
  import { FormSubmitError } from '../submit/error/FormSubmitError';
5
4
  import { default as _Controller } from './_Controller';
6
5
  import { FormProps } from './Form';
@@ -23,7 +22,6 @@ export type UseFormProps<TFieldValues extends SafeFieldValues, TTransformedValue
23
22
  onSubmitInvalid?: SubmitErrorHandler<TFieldValues>;
24
23
  defaultValues?: RhfUseFormProps<TFieldValues>['defaultValues'];
25
24
  Fields?: React.FC<UseFormFieldsProps<TFieldValues, TTransformedValues>>;
26
- config?: ClientConfig;
27
25
  /** {@link RhfUseFormProps} props for RHF's {@link useRhfForm}. */
28
26
  rhf?: Omit<RhfUseFormProps<TFieldValues>, 'defaultValues'>;
29
27
  /** {@link FormProps} props for Form. */
@@ -47,6 +45,6 @@ export type UseFormReturn<TFieldValues extends SafeFieldValues, TTransformedValu
47
45
  * see https://caniuse.com/?search=form%20attribute
48
46
  * @returns Form provider and form.
49
47
  */
50
- declare const useForm: <TFieldValues extends SafeFieldValues, TTransformedValues extends SafeFieldValues>({ onSubmit, onSubmitError, onSubmitInvalid, defaultValues, Fields, config, rhf, form, options, }: UseFormProps<TFieldValues, TTransformedValues>) => UseFormReturn<TFieldValues, TTransformedValues>;
48
+ declare const useForm: <TFieldValues extends SafeFieldValues, TTransformedValues extends SafeFieldValues>({ onSubmit, onSubmitError, onSubmitInvalid, defaultValues, Fields, rhf, form, options, }: UseFormProps<TFieldValues, TTransformedValues>) => UseFormReturn<TFieldValues, TTransformedValues>;
51
49
  export default useForm;
52
50
  export type UseForm<TFieldValues extends SafeFieldValues, TTransformedValues extends SafeFieldValues> = typeof useForm<TFieldValues, TTransformedValues>;
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.92",
5
+ "version": "0.0.94",
6
6
  "description": "Integration utilities for react-hook-form.",
7
7
  "type": "module",
8
8
  "sideEffects": false,
@@ -19,12 +19,6 @@
19
19
  }
20
20
  }
21
21
  },
22
- "imports": {
23
- "#is-development": {
24
- "development": "./src/env-conditions/development.ts",
25
- "default": "./src/env-conditions/production.ts"
26
- }
27
- },
28
22
  "peerDependencies": {
29
23
  "@hookform/devtools": "4",
30
24
  "@hookform/resolvers": "3",
@@ -1,4 +0,0 @@
1
- const e = !1;
2
- export {
3
- e as isDevelopment
4
- };
@@ -1,7 +0,0 @@
1
- /**
2
- * Determined whether env is dev via `imports`.
3
- *
4
- * Technique borrowed from react-error-boundary {@link https://github.com/bvaughn/react-error-boundary/blob/master/package.json}.
5
- * Assign `boolean` type to avoid `@typescript-eslint/no-unnecessary-condition`.
6
- */
7
- export declare const isDevelopment: boolean;
@@ -1 +0,0 @@
1
- export declare const isDevelopment: boolean;
@@ -1,11 +0,0 @@
1
- import { UseFormProps } from './useForm';
2
- import { SafeFieldValues } from './SafeFieldValues';
3
- import { default as React } from 'react';
4
-
5
- export type _FormSlots = 'top' | 'bottom';
6
- export type _FormProps<TFieldValues extends SafeFieldValues, TTransformedValues extends SafeFieldValues> = React.PropsWithChildren<{
7
- formId: string;
8
- formRef: React.RefObject<HTMLFormElement>;
9
- } & Pick<UseFormProps<TFieldValues, TTransformedValues>, 'onSubmit' | 'onSubmitError' | 'onSubmitInvalid' | 'Fields' | 'form' | 'options' | 'config'>>;
10
- declare function _Form<TFieldValues extends SafeFieldValues, TTransformedValues extends SafeFieldValues>({ formId, formRef, onSubmit, onSubmitError, onSubmitInvalid, Fields, form, options, config, children, }: _FormProps<TFieldValues, TTransformedValues>): import("react/jsx-runtime").JSX.Element;
11
- export default _Form;
@@ -1,12 +0,0 @@
1
- import { UseFormOptions } from './useFormOptions';
2
- import { SafeFieldValues } from './SafeFieldValues';
3
- import { UseFormReturn } from 'react-hook-form';
4
-
5
- export type _FormProvidersProps<TFieldValues extends SafeFieldValues, TTransformedValues extends SafeFieldValues> = React.PropsWithChildren<{
6
- formId: string;
7
- formRef: React.RefObject<HTMLFormElement>;
8
- rhfForm: UseFormReturn<TFieldValues, unknown, TTransformedValues>;
9
- options?: UseFormOptions;
10
- }>;
11
- declare function _FormProviders<TFieldValues extends SafeFieldValues, TTransformedValues extends SafeFieldValues>({ formId, formRef, rhfForm, options, children, }: _FormProvidersProps<TFieldValues, TTransformedValues>): import("react/jsx-runtime").JSX.Element;
12
- export default _FormProviders;