@paragrav/rhf-utils 0.0.48 → 0.0.50

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 (53) hide show
  1. package/dist/assets/index-BgBykTYQ.js +40 -0
  2. package/dist/esm/errors/context/provider.mjs +11 -9
  3. package/dist/esm/errors/root/FormRootErrors.mjs +7 -7
  4. package/dist/esm/errors/root/FormRootErrorsFromContext.mjs +11 -0
  5. package/dist/esm/errors/useFormErrorsEffect.mjs +6 -6
  6. package/dist/esm/errors/useFormErrorsToConsole.mjs +17 -13
  7. package/dist/esm/{main.mjs → exports.mjs} +44 -42
  8. package/dist/esm/form/Form.mjs +40 -56
  9. package/dist/esm/form/FormWithProviders.mjs +10 -0
  10. package/dist/esm/form/context/group/useFormGroupChildIsMountedTracker.mjs +3 -1
  11. package/dist/esm/form/useForm.mjs +1 -1
  12. package/dist/esm/form/{useFormWithProvider.mjs → useFormWithProviders.mjs} +6 -6
  13. package/dist/esm/{form/FormError.mjs → submit/error/FormSubmitError.mjs} +2 -2
  14. package/dist/esm/submit/error/handleFormSubmitError.mjs +12 -0
  15. package/dist/esm/submit/useResetFormOnSubmitError.mjs +18 -0
  16. package/dist/esm/submit/useSubmitFormOnChange.mjs +1 -1
  17. package/dist/index.html +12 -0
  18. package/dist/types/errors/context/provider.d.ts +1 -1
  19. package/dist/types/errors/root/FormRootErrorsFromContext.d.ts +3 -0
  20. package/dist/types/errors/useFormErrorsIfAny.d.ts +1 -1
  21. package/dist/types/exports.d.ts +37 -0
  22. package/dist/types/form/ErrorBoundary.d.ts +15 -0
  23. package/dist/types/form/Form.d.ts +2 -2
  24. package/dist/types/form/FormWithProviders.d.ts +13 -0
  25. package/dist/types/form/{useFormWithProvider.d.ts → useFormWithProviders.d.ts} +4 -4
  26. package/dist/types/main.d.ts +1 -36
  27. package/dist/types/{form/FormError.d.ts → submit/error/FormSubmitError.d.ts} +1 -1
  28. package/dist/types/submit/error/handleFormSubmitError.d.ts +7 -0
  29. package/dist/types/submit/useResetFormOnSubmitError.d.ts +7 -0
  30. package/dist/types/submit/useSubmitFormOnChange.d.ts +1 -1
  31. package/dist/types/utils/useThrowAsyncError.d.ts +5 -0
  32. package/package.json +24 -17
  33. package/dist/esm/form/FormWithProvider.mjs +0 -9
  34. package/dist/types/errors/flat/getFlatFieldErrorsByFilter.d.ts +0 -9
  35. package/dist/types/errors/flattenFieldErrors.d.ts +0 -15
  36. package/dist/types/errors/getFlatFieldErrors.d.ts +0 -25
  37. package/dist/types/errors/orphan/getOrphanFlatFieldErrors.d.ts +0 -5
  38. package/dist/types/errors/orphan/useOrphanFormErrors.d.ts +0 -4
  39. package/dist/types/errors/orphan/useOrphanFormErrorsToConsoleError.d.ts +0 -9
  40. package/dist/types/errors/root/getRootFlatFieldErrors.d.ts +0 -8
  41. package/dist/types/errors/root/useRootFormFieldErrors.d.ts +0 -6
  42. package/dist/types/errors/root/utils.d.ts +0 -12
  43. package/dist/types/errors/useFormErrorsOnChange.d.ts +0 -7
  44. package/dist/types/errors/useFormFieldErrors.d.ts +0 -6
  45. package/dist/types/errors/useFormFlatFieldErrors.d.ts +0 -5
  46. package/dist/types/form/FormWithProvider.d.ts +0 -13
  47. package/dist/types/form/context/group/useAsFormGroupParent.d.ts +0 -7
  48. package/dist/types/form/context/parent/FormParentContextProvider.d.ts +0 -5
  49. package/dist/types/form/context/parent/index.d.ts +0 -6
  50. package/dist/types/form/context/parent/useAsFormParentState.d.ts +0 -7
  51. package/dist/types/form/context/parent/useFormParentIsBusy.d.ts +0 -7
  52. package/dist/types/form/toggle/ToggleForm.d.ts +0 -18
  53. package/dist/types/utils/createRequiredContext.d.ts +0 -8
@@ -6,69 +6,71 @@ import { default as d } from "./errors/message/FormErrorMessageByPath.mjs";
6
6
  import { default as x } from "./errors/nonfield/FormNonFieldErrorMarker.mjs";
7
7
  import { default as i } from "./errors/nonfield/FormNonFieldErrorMarkerHtmlAttribute.mjs";
8
8
  import { default as E } from "./errors/orphan/useFormHasOrphanAndNoFieldErrors.mjs";
9
- import { default as c } from "./errors/orphan/useOrphanFormErrorsMemo.mjs";
10
- import { default as S } from "./errors/orphan/useOrphanFormErrorsToConsole.mjs";
9
+ import { default as b } from "./errors/orphan/useOrphanFormErrorsMemo.mjs";
10
+ import { default as c } from "./errors/orphan/useOrphanFormErrorsToConsole.mjs";
11
11
  import { default as P } from "./errors/root/useRootFormFieldErrorsMemo.mjs";
12
12
  import { default as v } from "./errors/useFormErrorConsoleDebug.mjs";
13
13
  import { default as G } from "./errors/useFormErrorsEffect.mjs";
14
- import { default as A } from "./errors/useFormErrorsIfAny.mjs";
15
- import { default as O } from "./errors/useFormErrorsMemo.mjs";
14
+ import { default as g } from "./errors/useFormErrorsIfAny.mjs";
15
+ import { default as I } from "./errors/useFormErrorsMemo.mjs";
16
16
  import { default as B } from "./errors/useFormRequestSubmit.mjs";
17
- import { default as R } from "./form/Form.mjs";
18
- import { FormError as N } from "./form/FormError.mjs";
19
- import { default as U } from "./form/FormWithProvider.mjs";
20
- import { default as q } from "./form/useForm.mjs";
21
- import { default as L } from "./form/useFormWithProvider.mjs";
22
- import { default as w } from "./form/context/FormProvider.mjs";
23
- import { default as K } from "./form/context/utils/FormUtilsContextProvider.mjs";
24
- import { default as V } from "./form/context/utils/useFormUtilsContext.mjs";
25
- import { default as Y } from "./form/context/group/FormGroupContextProvider.mjs";
26
- import { default as _ } from "./form/context/group/useFormGroupChildIsMountedTracker.mjs";
27
- import { default as rr } from "./form/context/group/useFormGroupChildIsSubmittingTracker.mjs";
28
- import { default as er } from "./form/context/group/useFormGroupIsAnyBusy.mjs";
29
- import { default as sr } from "./form/context/group/useFormGroupIsChildBusy.mjs";
30
- import { default as ur } from "./form/context/group/useFormGroupIsParentBusy.mjs";
31
- import { default as fr } from "./form/context/group/useFormGroupParentTracker.mjs";
32
- import { default as dr } from "./form/utils/getSubmitterButtonData.mjs";
17
+ import { default as T } from "./form/Form.mjs";
18
+ import { default as N } from "./form/FormWithProviders.mjs";
19
+ import { default as U } from "./form/useForm.mjs";
20
+ import { default as q } from "./form/useFormWithProviders.mjs";
21
+ import { default as L } from "./form/context/FormProvider.mjs";
22
+ import { default as w } from "./form/context/utils/FormUtilsContextProvider.mjs";
23
+ import { default as K } from "./form/context/utils/useFormUtilsContext.mjs";
24
+ import { default as V } from "./form/context/group/FormGroupContextProvider.mjs";
25
+ import { default as Y } from "./form/context/group/useFormGroupChildIsMountedTracker.mjs";
26
+ import { default as _ } from "./form/context/group/useFormGroupChildIsSubmittingTracker.mjs";
27
+ import { default as rr } from "./form/context/group/useFormGroupIsAnyBusy.mjs";
28
+ import { default as er } from "./form/context/group/useFormGroupIsChildBusy.mjs";
29
+ import { default as sr } from "./form/context/group/useFormGroupIsParentBusy.mjs";
30
+ import { default as ur } from "./form/context/group/useFormGroupParentTracker.mjs";
31
+ import { default as fr } from "./form/utils/getSubmitterButtonData.mjs";
32
+ import { FormSubmitError as dr } from "./submit/error/FormSubmitError.mjs";
33
33
  import { default as xr } from "./submit/useFormOnSubmitSuccessful.mjs";
34
34
  import { default as ir } from "./submit/useFormOnSubmitSuccessfulAndReset.mjs";
35
- import { default as Er } from "./submit/useResetFormOnSubmitSuccessful.mjs";
35
+ import { default as Er } from "./submit/useResetFormOnSubmitError.mjs";
36
+ import { default as br } from "./submit/useResetFormOnSubmitSuccessful.mjs";
36
37
  import { default as cr } from "./submit/useSubmitFormOnChange.mjs";
37
38
  export {
38
- R as Form,
39
- N as FormError,
39
+ T as Form,
40
40
  f as FormErrorMessage,
41
41
  d as FormErrorMessageByPath,
42
42
  u as FormErrorsFlatContextProvider,
43
- Y as FormGroupContextProvider,
43
+ V as FormGroupContextProvider,
44
44
  x as FormNonFieldErrorMarker,
45
45
  i as FormNonFieldErrorMarkerHtmlAttribute,
46
- w as FormProvider,
47
- K as FormUtilsContextProvider,
48
- U as FormWithProvider,
46
+ L as FormProvider,
47
+ dr as FormSubmitError,
48
+ w as FormUtilsContextProvider,
49
+ N as FormWithProviders,
49
50
  e as LazyDevTool,
50
- dr as getSubmitterButtonData,
51
- q as useForm,
51
+ fr as getSubmitterButtonData,
52
+ U as useForm,
52
53
  v as useFormErrorConsoleDebug,
53
54
  G as useFormErrorsEffect,
54
55
  s as useFormErrorsFlatContext,
55
- A as useFormErrorsIfAny,
56
- O as useFormErrorsMemo,
57
- _ as useFormGroupChildIsMountedTracker,
58
- rr as useFormGroupChildIsSubmittingTracker,
59
- er as useFormGroupIsAnyBusy,
60
- sr as useFormGroupIsChildBusy,
61
- ur as useFormGroupIsParentBusy,
62
- fr as useFormGroupParentTracker,
56
+ g as useFormErrorsIfAny,
57
+ I as useFormErrorsMemo,
58
+ Y as useFormGroupChildIsMountedTracker,
59
+ _ as useFormGroupChildIsSubmittingTracker,
60
+ rr as useFormGroupIsAnyBusy,
61
+ er as useFormGroupIsChildBusy,
62
+ sr as useFormGroupIsParentBusy,
63
+ ur as useFormGroupParentTracker,
63
64
  E as useFormHasOrphanAndNoFieldErrors,
64
65
  xr as useFormOnSubmitSuccessful,
65
66
  ir as useFormOnSubmitSuccessfulAndReset,
66
67
  B as useFormRequestSubmit,
67
- V as useFormUtilsContext,
68
- L as useFormWithProvider,
69
- c as useOrphanFormErrorsMemo,
70
- S as useOrphanFormErrorsToConsole,
71
- Er as useResetFormAfterSubmitSuccessful,
68
+ K as useFormUtilsContext,
69
+ q as useFormWithProviders,
70
+ b as useOrphanFormErrorsMemo,
71
+ c as useOrphanFormErrorsToConsole,
72
+ br as useResetFormAfterSubmitSuccessful,
73
+ Er as useResetFormOnSubmitError,
72
74
  P as useRootFormFieldErrorsMemo,
73
75
  cr as useSubmitFormOnChange
74
76
  };
@@ -1,87 +1,71 @@
1
- import { jsxs as R, jsx as l } from "react/jsx-runtime";
1
+ import { jsxs as O, jsx as t } from "react/jsx-runtime";
2
2
  import "react";
3
- import { useFormContext as i } from "react-hook-form";
4
- import j from "../devtool/LazyDevTool.mjs";
5
- import { useFormErrorsFlatContextMaybe as T } from "../errors/context/index.mjs";
6
- import V from "../errors/root/FormRootErrors.mjs";
7
- import w from "../submit/useSubmitFormOnChange.mjs";
3
+ import { useFormContext as v } from "react-hook-form";
4
+ import T from "../devtool/LazyDevTool.mjs";
5
+ import V from "../errors/root/FormRootErrorsFromContext.mjs";
6
+ import j from "../submit/error/handleFormSubmitError.mjs";
7
+ import w from "../submit/useResetFormOnSubmitError.mjs";
8
+ import E from "../submit/useSubmitFormOnChange.mjs";
8
9
  import P from "../utils/useImperativeForwardedRef.mjs";
9
- import z from "./FormBase.mjs";
10
- import { FormError as B } from "./FormError.mjs";
11
- function K({
12
- isDev: F,
13
- formId: y,
14
- formRef: E,
15
- Fields: c,
10
+ import S from "./FormBase.mjs";
11
+ function H({
12
+ isDev: u,
13
+ formId: h,
14
+ formRef: F,
15
+ Fields: f,
16
16
  //
17
- onSubmit: a,
18
- onSubmitError: t,
17
+ onSubmit: d,
18
+ onSubmitError: l,
19
19
  onSubmitInvalid: x,
20
20
  //
21
21
  options: r,
22
22
  //
23
23
  children: g,
24
- ...s
24
+ ...R
25
25
  }) {
26
- var h;
27
- const e = i(), d = P(E);
28
- w(d, !!(r != null && r.submitOnChange));
29
- const u = (h = T()) == null ? void 0 : h.roots, b = (m) => (r != null && r.stopSubmitPropagation && m.stopPropagation(), e.handleSubmit(
30
- v,
31
- // `as` required due to conditional generic
32
- x
33
- )(m)), v = async (m, o) => {
26
+ const m = v(), c = P(F);
27
+ E(c, !(r != null && r.submitOnChange)), w(!(r != null && r.resetValuesOnSubmitError));
28
+ const b = async (e) => {
29
+ r != null && r.stopSubmitPropagation && e.stopPropagation();
34
30
  try {
35
- await (a == null ? void 0 : a(
36
- m,
37
- e,
38
- o
39
- ));
40
- } catch (f) {
41
- if (r != null && r.disableEmptyRootError || e.setError("root", {}), r != null && r.resetValuesOnSubmitError && e.reset(void 0), f instanceof B) {
42
- Object.entries(f.errors).forEach(([C, O]) => {
43
- e.setError(C, {
44
- type: "FormError",
45
- message: O
46
- });
47
- });
48
- return;
49
- }
50
- t == null || t(
51
- f,
52
- m,
53
- e,
54
- o
55
- );
31
+ await m.handleSubmit(y, x)(e);
32
+ } catch (a) {
33
+ C(a, e);
56
34
  }
35
+ }, y = (e, a) => d == null ? void 0 : d(
36
+ e,
37
+ m,
38
+ a
39
+ ), C = (e, a) => {
40
+ j(e, m), l == null || l(e, m, a);
57
41
  };
58
- return /* @__PURE__ */ R(
59
- z,
42
+ return /* @__PURE__ */ O(
43
+ S,
60
44
  {
61
- id: y,
45
+ id: h,
62
46
  onSubmit: b,
63
47
  noValidate: !0,
64
- ...s,
65
- ref: d,
66
48
  style: {
67
49
  position: "relative"
68
50
  },
51
+ ...R,
52
+ ref: c,
69
53
  children: [
70
- (r == null ? void 0 : r.devTool) !== "disabled" && /* @__PURE__ */ l(
71
- j,
54
+ (r == null ? void 0 : r.devTool) !== "disabled" && /* @__PURE__ */ t(
55
+ T,
72
56
  {
73
- isDev: F,
57
+ isDev: u,
74
58
  placement: "top-right",
75
59
  ...r == null ? void 0 : r.devTool
76
60
  }
77
61
  ),
78
- c && /* @__PURE__ */ l(c, { ctx: e }),
62
+ f && /* @__PURE__ */ t(f, { ctx: m }),
79
63
  g,
80
- u && /* @__PURE__ */ l(V, { errors: u })
64
+ !(r != null && r.hideRootErrors) && /* @__PURE__ */ t(V, {})
81
65
  ]
82
66
  }
83
67
  );
84
68
  }
85
69
  export {
86
- K as default
70
+ H as default
87
71
  };
@@ -0,0 +1,10 @@
1
+ import { jsx as o } from "react/jsx-runtime";
2
+ import i from "../errors/context/provider.mjs";
3
+ import m from "./useFormWithProviders.mjs";
4
+ function s({ children: e, ...t }) {
5
+ const r = m(t);
6
+ return /* @__PURE__ */ o(r.Provider, { children: /* @__PURE__ */ o(i, { formRef: r.ref, children: /* @__PURE__ */ o(r.Form, { children: e }) }) });
7
+ }
8
+ export {
9
+ s as default
10
+ };
@@ -6,7 +6,9 @@ const c = () => {
6
6
  const e = (t) => {
7
7
  r(s, t);
8
8
  };
9
- return e(!0), () => e(!1);
9
+ return e(!0), () => {
10
+ e(!1);
11
+ };
10
12
  }, []);
11
13
  }, m = c;
12
14
  export {
@@ -16,11 +16,11 @@ const p = ({
16
16
  Form: ({ children: n }) => /* @__PURE__ */ i(
17
17
  f,
18
18
  {
19
- ...o,
20
19
  isDev: e,
21
20
  formId: r,
22
21
  formRef: t,
23
22
  onSubmit: o == null ? void 0 : o.onSubmit,
23
+ ...o,
24
24
  children: n
25
25
  }
26
26
  )
@@ -1,18 +1,18 @@
1
- import { jsx as f } from "react/jsx-runtime";
1
+ import { jsx as s } from "react/jsx-runtime";
2
2
  import "react";
3
- import d from "./context/FormProvider.mjs";
4
- import s from "./useForm.mjs";
3
+ import f from "./context/FormProvider.mjs";
4
+ import d from "./useForm.mjs";
5
5
  const n = ({
6
6
  isDev: o,
7
7
  rhf: e,
8
8
  form: t,
9
9
  utils: m
10
10
  }) => {
11
- const r = s({ isDev: o, rhf: e, form: t });
11
+ const r = d({ isDev: o, rhf: e, form: t });
12
12
  return {
13
13
  ...r,
14
- Provider: ({ children: i }) => /* @__PURE__ */ f(
15
- d,
14
+ Provider: ({ children: i }) => /* @__PURE__ */ s(
15
+ f,
16
16
  {
17
17
  isDev: o,
18
18
  formRef: r.ref,
@@ -1,8 +1,8 @@
1
- class e extends Error {
1
+ class t extends Error {
2
2
  constructor(r, o) {
3
3
  super(o), this.errors = r;
4
4
  }
5
5
  }
6
6
  export {
7
- e as FormError
7
+ t as FormSubmitError
8
8
  };
@@ -0,0 +1,12 @@
1
+ import { FormSubmitError as m } from "./FormSubmitError.mjs";
2
+ const n = (r, o) => {
3
+ r instanceof m && Object.entries(r.errors).forEach(([t, e]) => {
4
+ o.setError(t, {
5
+ type: "FormSubmitError",
6
+ message: e
7
+ });
8
+ });
9
+ };
10
+ export {
11
+ n as default
12
+ };
@@ -0,0 +1,18 @@
1
+ import i from "react";
2
+ import { useFormContext as m, useFormState as n } from "react-hook-form";
3
+ const f = (t) => {
4
+ const { reset: r } = m(), { isSubmitting: e, isSubmitSuccessful: u, isSubmitted: o, submitCount: s } = n();
5
+ i.useEffect(() => {
6
+ t || e || u || o && s !== 0 && r(void 0);
7
+ }, [
8
+ t,
9
+ e,
10
+ u,
11
+ o,
12
+ r,
13
+ s
14
+ ]);
15
+ }, b = f;
16
+ export {
17
+ b as default
18
+ };
@@ -3,7 +3,7 @@ import u from "../errors/useFormRequestSubmit.mjs";
3
3
  const m = (t, n) => {
4
4
  const o = u(t);
5
5
  s.useEffect(() => {
6
- if (!n)
6
+ if (n)
7
7
  return;
8
8
  const e = t.current;
9
9
  if (!e)
@@ -0,0 +1,12 @@
1
+ <!doctype html>
2
+ <html lang="en">
3
+ <head>
4
+ <meta charset="UTF-8" />
5
+ <meta name="viewport" content="width=device-width, initial-scale=1.0" />
6
+ <title>Playground</title>
7
+ <script type="module" crossorigin src="/assets/index-BgBykTYQ.js"></script>
8
+ </head>
9
+ <body>
10
+ <div id="root"></div>
11
+ </body>
12
+ </html>
@@ -1,6 +1,6 @@
1
1
  /// <reference types="react" />
2
2
  type Props = React.PropsWithChildren<{
3
- formRef: React.MutableRefObject<HTMLFormElement>;
3
+ formRef: React.RefObject<HTMLFormElement>;
4
4
  isDev?: boolean;
5
5
  outputErrors?: boolean;
6
6
  }>;
@@ -0,0 +1,3 @@
1
+ /// <reference types="react" />
2
+ declare const FormRootErrorsFromContext: React.FC;
3
+ export default FormRootErrorsFromContext;
@@ -2,5 +2,5 @@
2
2
  * Returns errors only if there are errors.
3
3
  * Allows simple typeguard without `isEmpty` dependency.
4
4
  */
5
- declare const useFormErrorsIfAny: () => false | import('react-hook-form').FieldErrors<import("react-hook-form").FieldValues>;
5
+ declare const useFormErrorsIfAny: () => false | import('react-hook-form').FieldErrors<import('react-hook-form').FieldValues>;
6
6
  export default useFormErrorsIfAny;
@@ -0,0 +1,37 @@
1
+ export { default as LazyDevTool } from './devtool/LazyDevTool';
2
+ export { default as useFormErrorsFlatContext } from './errors/context';
3
+ export { default as FormErrorsFlatContextProvider } from './errors/context/provider';
4
+ export { default as FormErrorMessage } from './errors/message/FormErrorMessage';
5
+ export { default as FormErrorMessageByPath } from './errors/message/FormErrorMessageByPath';
6
+ export { default as FormNonFieldErrorMarker } from './errors/nonfield/FormNonFieldErrorMarker';
7
+ export { default as FormNonFieldErrorMarkerHtmlAttribute } from './errors/nonfield/FormNonFieldErrorMarkerHtmlAttribute';
8
+ export { default as useFormHasOrphanAndNoFieldErrors } from './errors/orphan/useFormHasOrphanAndNoFieldErrors';
9
+ export { default as useOrphanFormErrorsMemo } from './errors/orphan/useOrphanFormErrorsMemo';
10
+ export { default as useOrphanFormErrorsToConsole } from './errors/orphan/useOrphanFormErrorsToConsole';
11
+ export { default as useRootFormFieldErrorsMemo } from './errors/root/useRootFormFieldErrorsMemo';
12
+ export { default as useFormErrorConsoleDebug } from './errors/useFormErrorConsoleDebug';
13
+ export { default as useFormErrorsEffect } from './errors/useFormErrorsEffect';
14
+ export { default as useFormErrorsIfAny } from './errors/useFormErrorsIfAny';
15
+ export { default as useFormErrorsMemo } from './errors/useFormErrorsMemo';
16
+ export { default as useFormRequestSubmit } from './errors/useFormRequestSubmit';
17
+ export { default as Form } from './form/Form';
18
+ export { default as FormWithProviders } from './form/FormWithProviders';
19
+ export { default as useForm } from './form/useForm';
20
+ export { default as useFormWithProviders } from './form/useFormWithProviders';
21
+ export { default as FormProvider } from './form/context/FormProvider';
22
+ export { default as FormUtilsContextProvider } from './form/context/utils/FormUtilsContextProvider';
23
+ export { default as useFormUtilsContext } from './form/context/utils/useFormUtilsContext';
24
+ export { default as FormGroupContextProvider } from './form/context/group/FormGroupContextProvider';
25
+ export { default as useFormGroupChildIsMountedTracker } from './form/context/group/useFormGroupChildIsMountedTracker';
26
+ export { default as useFormGroupChildIsSubmittingTracker } from './form/context/group/useFormGroupChildIsSubmittingTracker';
27
+ export { default as useFormGroupIsAnyBusy } from './form/context/group/useFormGroupIsAnyBusy';
28
+ export { default as useFormGroupIsChildBusy } from './form/context/group/useFormGroupIsChildBusy';
29
+ export { default as useFormGroupIsParentBusy } from './form/context/group/useFormGroupIsParentBusy';
30
+ export { default as useFormGroupParentTracker } from './form/context/group/useFormGroupParentTracker';
31
+ export { default as getSubmitterButtonData } from './form/utils/getSubmitterButtonData';
32
+ export { FormSubmitError } from './submit/error/FormSubmitError';
33
+ export { default as useFormOnSubmitSuccessful } from './submit/useFormOnSubmitSuccessful';
34
+ export { default as useFormOnSubmitSuccessfulAndReset } from './submit/useFormOnSubmitSuccessfulAndReset';
35
+ export { default as useResetFormOnSubmitError } from './submit/useResetFormOnSubmitError';
36
+ export { default as useResetFormAfterSubmitSuccessful } from './submit/useResetFormOnSubmitSuccessful';
37
+ export { default as useSubmitFormOnChange } from './submit/useSubmitFormOnChange';
@@ -0,0 +1,15 @@
1
+ import { default as React } from 'react';
2
+
3
+ type Props = React.PropsWithChildren;
4
+ type State = {
5
+ error: null | Error;
6
+ };
7
+ export declare class ErrorBoundary extends React.Component<Props, State> {
8
+ state: State;
9
+ static getDerivedStateFromError(error: Error): {
10
+ error: Error;
11
+ };
12
+ componentDidCatch(error: unknown, errorInfo: React.ErrorInfo): void;
13
+ render(): string | number | boolean | Iterable<React.ReactNode> | import("react/jsx-runtime").JSX.Element | null | undefined;
14
+ }
15
+ export {};
@@ -12,16 +12,16 @@ export type FormProps<TFieldValues extends FieldValues, TTransformedValues exten
12
12
  }>;
13
13
  onSubmit?: (values: TTransformedValues, context: UseFormReturn<TFieldValues, unknown, TTransformedValues>, event: React.BaseSyntheticEvent<SubmitEvent>) => unknown | Promise<unknown>;
14
14
  /** Submit error handler. (Only for errors not of instance `FormError`, which are handled internally.) */
15
- onSubmitError?: (error: unknown, values: TTransformedValues, context: UseFormReturn<TFieldValues, unknown, TTransformedValues>, event: React.BaseSyntheticEvent<SubmitEvent>) => void;
15
+ onSubmitError?: (error: unknown, context: UseFormReturn<TFieldValues, unknown, TTransformedValues>, event: React.BaseSyntheticEvent<SubmitEvent>) => void;
16
16
  /** Submit handler when form is invalid. */
17
17
  onSubmitInvalid?: SubmitErrorHandler<TFieldValues>;
18
18
  options?: {
19
+ hideRootErrors?: boolean;
19
20
  /** Request submit via listener on form change. */
20
21
  submitOnChange?: boolean;
21
22
  /** Reset form values if submit throw errors. Use case: optimistic UI toggle form that submits on each change */
22
23
  resetValuesOnSubmitError?: boolean;
23
24
  stopSubmitPropagation?: boolean;
24
- disableEmptyRootError?: boolean;
25
25
  devTool?: DevtoolUIProps | 'disabled';
26
26
  };
27
27
  className?: string;
@@ -0,0 +1,13 @@
1
+ import { UseFormProps } from './useForm';
2
+ import { FieldValues } from 'react-hook-form';
3
+
4
+ export type FormWithProviders<TFieldValues extends FieldValues, TTransformedValues extends FieldValues> = React.PropsWithChildren<UseFormProps<TFieldValues, TTransformedValues>>;
5
+ /**
6
+ * {@link FormProvider} (and utils) with immediate descendent {@link Form}.
7
+ * (Syntactic sugar for {@link useForm}. Use this for most applications.)
8
+ *
9
+ * Use {@link useForm} if you need to specific nesting hierarchy.
10
+ * (e.g., wrapping `<tr>` with provider and nesting `<form>` within `<td>` to appease HTML rules.)
11
+ */
12
+ declare function FormWithProviders<TFieldValues extends FieldValues, TTransformedValues extends FieldValues>({ children, ...props }: FormWithProviders<TFieldValues, TTransformedValues>): import("react/jsx-runtime").JSX.Element;
13
+ export default FormWithProviders;
@@ -3,11 +3,11 @@ import { FormUtilsContextProviderProps } from './context/utils/FormUtilsContextP
3
3
  import { FieldValues } from 'react-hook-form';
4
4
  import { default as React } from 'react';
5
5
 
6
- export type UseFormWithProviderProps<TFieldValues extends FieldValues, TTransformedValues extends FieldValues> = UseFormProps<TFieldValues, TTransformedValues> & {
6
+ export type UseFormWithProvidersProps<TFieldValues extends FieldValues, TTransformedValues extends FieldValues> = UseFormProps<TFieldValues, TTransformedValues> & {
7
7
  /** {@link FormUtilsContextProviderProps} props for `FormUtilsContextProvider`. */
8
8
  utils?: FormUtilsContextProviderProps;
9
9
  };
10
- export type UseFormWithProviderReturn = ReturnType<typeof useFormWithProvider>;
10
+ export type UseFormWithProvidersReturn = ReturnType<typeof useFormWithProviders>;
11
11
  /**
12
12
  * Base Rhf Form hook. Use `Form` in `index.ts` for most cases.
13
13
  * Use this if you need to separate form components.
@@ -17,7 +17,7 @@ export type UseFormWithProviderReturn = ReturnType<typeof useFormWithProvider>;
17
17
  * see https://caniuse.com/?search=form%20attribute
18
18
  * @returns Form provider and form.
19
19
  */
20
- declare const useFormWithProvider: <TFieldValues extends FieldValues, TTransformedValues extends FieldValues>({ isDev, rhf, form, utils, }: UseFormWithProviderProps<TFieldValues, TTransformedValues>) => {
20
+ declare const useFormWithProviders: <TFieldValues extends FieldValues, TTransformedValues extends FieldValues>({ isDev, rhf, form, utils, }: UseFormWithProvidersProps<TFieldValues, TTransformedValues>) => {
21
21
  readonly Provider: React.FC<{
22
22
  children?: React.ReactNode;
23
23
  }>;
@@ -28,4 +28,4 @@ declare const useFormWithProvider: <TFieldValues extends FieldValues, TTransform
28
28
  children?: React.ReactNode;
29
29
  }>;
30
30
  };
31
- export default useFormWithProvider;
31
+ export default useFormWithProviders;
@@ -1,36 +1 @@
1
- export { default as LazyDevTool } from './devtool/LazyDevTool';
2
- export { default as useFormErrorsFlatContext } from './errors/context';
3
- export { default as FormErrorsFlatContextProvider } from './errors/context/provider';
4
- export { default as FormErrorMessage } from './errors/message/FormErrorMessage';
5
- export { default as FormErrorMessageByPath } from './errors/message/FormErrorMessageByPath';
6
- export { default as FormNonFieldErrorMarker } from './errors/nonfield/FormNonFieldErrorMarker';
7
- export { default as FormNonFieldErrorMarkerHtmlAttribute } from './errors/nonfield/FormNonFieldErrorMarkerHtmlAttribute';
8
- export { default as useFormHasOrphanAndNoFieldErrors } from './errors/orphan/useFormHasOrphanAndNoFieldErrors';
9
- export { default as useOrphanFormErrorsMemo } from './errors/orphan/useOrphanFormErrorsMemo';
10
- export { default as useOrphanFormErrorsToConsole } from './errors/orphan/useOrphanFormErrorsToConsole';
11
- export { default as useRootFormFieldErrorsMemo } from './errors/root/useRootFormFieldErrorsMemo';
12
- export { default as useFormErrorConsoleDebug } from './errors/useFormErrorConsoleDebug';
13
- export { default as useFormErrorsEffect } from './errors/useFormErrorsEffect';
14
- export { default as useFormErrorsIfAny } from './errors/useFormErrorsIfAny';
15
- export { default as useFormErrorsMemo } from './errors/useFormErrorsMemo';
16
- export { default as useFormRequestSubmit } from './errors/useFormRequestSubmit';
17
- export { default as Form } from './form/Form';
18
- export { FormError } from './form/FormError';
19
- export { default as FormWithProvider } from './form/FormWithProvider';
20
- export { default as useForm } from './form/useForm';
21
- export { default as useFormWithProvider } from './form/useFormWithProvider';
22
- export { default as FormProvider } from './form/context/FormProvider';
23
- export { default as FormUtilsContextProvider } from './form/context/utils/FormUtilsContextProvider';
24
- export { default as useFormUtilsContext } from './form/context/utils/useFormUtilsContext';
25
- export { default as FormGroupContextProvider } from './form/context/group/FormGroupContextProvider';
26
- export { default as useFormGroupChildIsMountedTracker } from './form/context/group/useFormGroupChildIsMountedTracker';
27
- export { default as useFormGroupChildIsSubmittingTracker } from './form/context/group/useFormGroupChildIsSubmittingTracker';
28
- export { default as useFormGroupIsAnyBusy } from './form/context/group/useFormGroupIsAnyBusy';
29
- export { default as useFormGroupIsChildBusy } from './form/context/group/useFormGroupIsChildBusy';
30
- export { default as useFormGroupIsParentBusy } from './form/context/group/useFormGroupIsParentBusy';
31
- export { default as useFormGroupParentTracker } from './form/context/group/useFormGroupParentTracker';
32
- export { default as getSubmitterButtonData } from './form/utils/getSubmitterButtonData';
33
- export { default as useFormOnSubmitSuccessful } from './submit/useFormOnSubmitSuccessful';
34
- export { default as useFormOnSubmitSuccessfulAndReset } from './submit/useFormOnSubmitSuccessfulAndReset';
35
- export { default as useResetFormAfterSubmitSuccessful } from './submit/useResetFormOnSubmitSuccessful';
36
- export { default as useSubmitFormOnChange } from './submit/useSubmitFormOnChange';
1
+ export {};
@@ -1,6 +1,6 @@
1
1
  import { FieldPath, FieldValues } from 'react-hook-form';
2
2
 
3
- export declare class FormError<TFieldValues extends FieldValues> extends Error {
3
+ export declare class FormSubmitError<TFieldValues extends FieldValues = FieldValues> extends Error {
4
4
  errors: Partial<Record<FieldPath<TFieldValues> | `root.${string}`, string>>;
5
5
  constructor(errors: Partial<Record<FieldPath<TFieldValues> | `root.${string}`, string>>, message?: string);
6
6
  }
@@ -0,0 +1,7 @@
1
+ import { FieldValues, UseFormReturn } from 'react-hook-form';
2
+
3
+ /**
4
+ * Handle form submit error if {@link FormSubmitError}. Add items to RHF form errors.
5
+ */
6
+ declare const handleFormSubmitError: <TFieldValues extends FieldValues, TTransformedValues extends FieldValues>(error: unknown, ctx: UseFormReturn<TFieldValues, unknown, TTransformedValues>) => void;
7
+ export default handleFormSubmitError;
@@ -0,0 +1,7 @@
1
+ /**
2
+ * Handle resetting after successful submit with no server validation errors.
3
+ * See `Rules` section: https://react-hook-form.com/api/useform/reset/
4
+ * Specifically: "- It's recommended to reset inside useEffect after submission."
5
+ */
6
+ declare const useResetFormOnSubmitError: (disabled?: boolean) => void;
7
+ export default useResetFormOnSubmitError;
@@ -1,4 +1,4 @@
1
1
  import { default as React } from 'react';
2
2
 
3
- declare const useSubmitFormOnChange: (formRef: React.RefObject<HTMLFormElement>, enabled: boolean) => void;
3
+ declare const useSubmitFormOnChange: (formRef: React.RefObject<HTMLFormElement>, disabled?: boolean) => void;
4
4
  export default useSubmitFormOnChange;
@@ -0,0 +1,5 @@
1
+ /**
2
+ * React cannot handle async errors in event handlers or useEffects.
3
+ */
4
+ declare const useThrowAsyncError: () => (error: unknown) => void;
5
+ export default useThrowAsyncError;