@paragrav/rhf-utils 0.0.45 → 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 (69) hide show
  1. package/dist/assets/index-BgBykTYQ.js +40 -0
  2. package/dist/esm/errors/context/provider.mjs +10 -8
  3. package/dist/esm/errors/flat/getFlatFieldErrors.mjs +11 -11
  4. package/dist/esm/errors/isFieldError.mjs +2 -2
  5. package/dist/esm/errors/orphan/getOrphansFromFieldErrors.mjs +9 -0
  6. package/dist/esm/errors/orphan/getOrphansFromFlatFieldErrors.mjs +16 -0
  7. package/dist/esm/errors/orphan/useOrphanFormErrorsMemo.mjs +4 -4
  8. package/dist/esm/errors/root/FormRootErrors.mjs +7 -7
  9. package/dist/esm/errors/root/FormRootErrorsFromContext.mjs +11 -0
  10. package/dist/esm/errors/root/getRootsFromFieldErrors.mjs +9 -0
  11. package/dist/esm/errors/root/getRootsFromFlatFieldErrors.mjs +7 -0
  12. package/dist/esm/errors/root/useRootFormFieldErrorsMemo.mjs +1 -1
  13. package/dist/esm/errors/useFormErrorsEffect.mjs +6 -6
  14. package/dist/esm/errors/useFormErrorsToConsole.mjs +17 -13
  15. package/dist/esm/exports.mjs +76 -0
  16. package/dist/esm/form/Form.mjs +45 -56
  17. package/dist/esm/form/FormWithProviders.mjs +10 -0
  18. package/dist/esm/form/context/group/useFormGroupChildIsMountedTracker.mjs +3 -1
  19. package/dist/esm/form/useForm.mjs +1 -1
  20. package/dist/esm/form/{useFormWithProvider.mjs → useFormWithProviders.mjs} +6 -6
  21. package/dist/esm/{form/FormError.mjs → submit/error/FormSubmitError.mjs} +2 -2
  22. package/dist/esm/submit/error/handleFormSubmitError.mjs +12 -0
  23. package/dist/esm/submit/useResetFormOnSubmitError.mjs +18 -0
  24. package/dist/esm/submit/useSubmitFormOnChange.mjs +21 -0
  25. package/dist/index.html +12 -0
  26. package/dist/types/errors/context/provider.d.ts +1 -1
  27. package/dist/types/errors/orphan/getOrphansFromFieldErrors.d.ts +5 -0
  28. package/dist/types/errors/orphan/getOrphansFromFlatFieldErrors.d.ts +4 -0
  29. package/dist/types/errors/root/FormRootErrorsFromContext.d.ts +3 -0
  30. package/dist/types/errors/root/getRootsFromFieldErrors.d.ts +5 -0
  31. package/dist/types/errors/root/getRootsFromFlatFieldErrors.d.ts +4 -0
  32. package/dist/types/errors/useFormErrorsIfAny.d.ts +1 -1
  33. package/dist/types/exports.d.ts +37 -0
  34. package/dist/types/form/ErrorBoundary.d.ts +15 -0
  35. package/dist/types/form/Form.d.ts +10 -3
  36. package/dist/types/form/FormWithProviders.d.ts +13 -0
  37. package/dist/types/form/{useFormWithProvider.d.ts → useFormWithProviders.d.ts} +4 -4
  38. package/dist/types/main.d.ts +1 -35
  39. package/dist/types/{form/FormError.d.ts → submit/error/FormSubmitError.d.ts} +1 -1
  40. package/dist/types/submit/error/handleFormSubmitError.d.ts +7 -0
  41. package/dist/types/submit/useResetFormOnSubmitError.d.ts +7 -0
  42. package/dist/types/submit/useSubmitFormOnChange.d.ts +4 -0
  43. package/dist/types/utils/useThrowAsyncError.d.ts +5 -0
  44. package/package.json +28 -17
  45. package/dist/esm/errors/nonfield/isNonFieldError.mjs +0 -5
  46. package/dist/esm/errors/orphan/getOrphanFlatFieldErrors.mjs +0 -20
  47. package/dist/esm/errors/root/getRootFlatFieldErrors.mjs +0 -11
  48. package/dist/esm/form/FormWithProvider.mjs +0 -9
  49. package/dist/esm/main.mjs +0 -72
  50. package/dist/types/errors/flat/getFlatFieldErrorsByFilter.d.ts +0 -9
  51. package/dist/types/errors/flattenFieldErrors.d.ts +0 -15
  52. package/dist/types/errors/getFlatFieldErrors.d.ts +0 -25
  53. package/dist/types/errors/orphan/getOrphanFlatFieldErrors.d.ts +0 -5
  54. package/dist/types/errors/orphan/useOrphanFormErrors.d.ts +0 -4
  55. package/dist/types/errors/orphan/useOrphanFormErrorsToConsoleError.d.ts +0 -9
  56. package/dist/types/errors/root/getRootFlatFieldErrors.d.ts +0 -8
  57. package/dist/types/errors/root/useRootFormFieldErrors.d.ts +0 -6
  58. package/dist/types/errors/root/utils.d.ts +0 -12
  59. package/dist/types/errors/useFormErrorsOnChange.d.ts +0 -7
  60. package/dist/types/errors/useFormFieldErrors.d.ts +0 -6
  61. package/dist/types/errors/useFormFlatFieldErrors.d.ts +0 -5
  62. package/dist/types/form/FormWithProvider.d.ts +0 -13
  63. package/dist/types/form/context/group/useAsFormGroupParent.d.ts +0 -7
  64. package/dist/types/form/context/parent/FormParentContextProvider.d.ts +0 -5
  65. package/dist/types/form/context/parent/index.d.ts +0 -6
  66. package/dist/types/form/context/parent/useAsFormParentState.d.ts +0 -7
  67. package/dist/types/form/context/parent/useFormParentIsBusy.d.ts +0 -7
  68. package/dist/types/form/toggle/ToggleForm.d.ts +0 -18
  69. package/dist/types/utils/createRequiredContext.d.ts +0 -8
@@ -1,21 +1,25 @@
1
1
  import a from "react";
2
- import { useFormContext as c, useFormState as l } from "react-hook-form";
3
- import E from "../isEmptyObject.mjs";
2
+ import { useFormContext as l, useFormState as E } from "react-hook-form";
3
+ import c from "../isEmptyObject.mjs";
4
4
  import d from "./outputErrors.mjs";
5
- const v = (e, m, r) => {
6
- const { getValues: f } = c(), { errors: u } = l();
5
+ const h = (e, f, r) => {
6
+ const { getValues: m } = l(), { errors: u } = E();
7
7
  a.useEffect(() => {
8
- if (!(r != null && r.disabled) && !E(m) && (d(e, { values: f(), errors: u }, r), console[r != null && r.isError ? "error" : "debug"](e, {
9
- form: {
10
- values: f(),
11
- // form values
12
- errors: u
13
- },
14
- other: r == null ? void 0 : r.data
15
- }), r != null && r.isError))
8
+ if (!(r != null && r.disabled) && !c(f) && (d(e, { values: m(), errors: u }, r), console[r != null && r.isError ? "error" : "debug"](
9
+ "useFormErrorsToConsole",
10
+ e,
11
+ {
12
+ form: {
13
+ values: m(),
14
+ // form values
15
+ errors: u
16
+ },
17
+ other: r == null ? void 0 : r.data
18
+ }
19
+ ), r != null && r.isError))
16
20
  throw new Error(e);
17
21
  }, [u]);
18
22
  };
19
23
  export {
20
- v as default
24
+ h as default
21
25
  };
@@ -0,0 +1,76 @@
1
+ import { default as e } from "./devtool/LazyDevTool.mjs";
2
+ import { default as s } from "./errors/context/index.mjs";
3
+ import { default as u } from "./errors/context/provider.mjs";
4
+ import { default as f } from "./errors/message/FormErrorMessage.mjs";
5
+ import { default as d } from "./errors/message/FormErrorMessageByPath.mjs";
6
+ import { default as x } from "./errors/nonfield/FormNonFieldErrorMarker.mjs";
7
+ import { default as i } from "./errors/nonfield/FormNonFieldErrorMarkerHtmlAttribute.mjs";
8
+ import { default as E } from "./errors/orphan/useFormHasOrphanAndNoFieldErrors.mjs";
9
+ import { default as b } from "./errors/orphan/useOrphanFormErrorsMemo.mjs";
10
+ import { default as c } from "./errors/orphan/useOrphanFormErrorsToConsole.mjs";
11
+ import { default as P } from "./errors/root/useRootFormFieldErrorsMemo.mjs";
12
+ import { default as v } from "./errors/useFormErrorConsoleDebug.mjs";
13
+ import { default as G } from "./errors/useFormErrorsEffect.mjs";
14
+ import { default as g } from "./errors/useFormErrorsIfAny.mjs";
15
+ import { default as I } from "./errors/useFormErrorsMemo.mjs";
16
+ import { default as B } from "./errors/useFormRequestSubmit.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
+ import { default as xr } from "./submit/useFormOnSubmitSuccessful.mjs";
34
+ import { default as ir } from "./submit/useFormOnSubmitSuccessfulAndReset.mjs";
35
+ import { default as Er } from "./submit/useResetFormOnSubmitError.mjs";
36
+ import { default as br } from "./submit/useResetFormOnSubmitSuccessful.mjs";
37
+ import { default as cr } from "./submit/useSubmitFormOnChange.mjs";
38
+ export {
39
+ T as Form,
40
+ f as FormErrorMessage,
41
+ d as FormErrorMessageByPath,
42
+ u as FormErrorsFlatContextProvider,
43
+ V as FormGroupContextProvider,
44
+ x as FormNonFieldErrorMarker,
45
+ i as FormNonFieldErrorMarkerHtmlAttribute,
46
+ L as FormProvider,
47
+ dr as FormSubmitError,
48
+ w as FormUtilsContextProvider,
49
+ N as FormWithProviders,
50
+ e as LazyDevTool,
51
+ fr as getSubmitterButtonData,
52
+ U as useForm,
53
+ v as useFormErrorConsoleDebug,
54
+ G as useFormErrorsEffect,
55
+ s as useFormErrorsFlatContext,
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,
64
+ E as useFormHasOrphanAndNoFieldErrors,
65
+ xr as useFormOnSubmitSuccessful,
66
+ ir as useFormOnSubmitSuccessfulAndReset,
67
+ B as useFormRequestSubmit,
68
+ K as useFormUtilsContext,
69
+ q as useFormWithProviders,
70
+ b as useOrphanFormErrorsMemo,
71
+ c as useOrphanFormErrorsToConsole,
72
+ br as useResetFormAfterSubmitSuccessful,
73
+ Er as useResetFormOnSubmitError,
74
+ P as useRootFormFieldErrorsMemo,
75
+ cr as useSubmitFormOnChange
76
+ };
@@ -1,82 +1,71 @@
1
- import { jsxs as v, jsx as d } from "react/jsx-runtime";
1
+ import { jsxs as O, jsx as t } from "react/jsx-runtime";
2
2
  import "react";
3
- import { useFormContext as T } from "react-hook-form";
4
- import w from "../devtool/LazyDevTool.mjs";
5
- import { useFormErrorsFlatContextMaybe as C } from "../errors/context/index.mjs";
6
- import P from "../errors/root/FormRootErrors.mjs";
7
- import V from "../utils/useImperativeForwardedRef.mjs";
8
- import b from "./FormBase.mjs";
9
- import { FormError as p } from "./FormError.mjs";
10
- function A({
11
- isDev: s,
12
- formId: F,
13
- formRef: i,
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";
9
+ import P from "../utils/useImperativeForwardedRef.mjs";
10
+ import S from "./FormBase.mjs";
11
+ function H({
12
+ isDev: u,
13
+ formId: h,
14
+ formRef: F,
15
+ Fields: f,
14
16
  //
15
- onSubmit: a,
16
- onSubmitError: m,
17
- onSubmitInvalid: h,
17
+ onSubmit: d,
18
+ onSubmitError: l,
19
+ onSubmitInvalid: x,
18
20
  //
19
21
  options: r,
20
22
  //
21
- children: y,
22
- ...u
23
+ children: g,
24
+ ...R
23
25
  }) {
24
- var l;
25
- const e = T(), x = V(i), f = (l = C()) == null ? void 0 : l.roots, E = (t) => (r != null && r.stopSubmitPropagation && t.stopPropagation(), e.handleSubmit(
26
- R,
27
- // `as` required due to conditional generic
28
- h
29
- )(t)), R = async (t, c) => {
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();
30
30
  try {
31
- await (a == null ? void 0 : a(
32
- t,
33
- e,
34
- c
35
- ));
36
- } catch (o) {
37
- if (r != null && r.disableEmptyRootError || e.setError("root", {}), o instanceof p) {
38
- Object.entries(o.errors).forEach(([g, j]) => {
39
- e.setError(g, {
40
- type: "FormError",
41
- message: j
42
- });
43
- });
44
- return;
45
- }
46
- m == null || m(
47
- o,
48
- t,
49
- e,
50
- c
51
- );
31
+ await m.handleSubmit(y, x)(e);
32
+ } catch (a) {
33
+ C(a, e);
52
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);
53
41
  };
54
- return /* @__PURE__ */ v(
55
- b,
42
+ return /* @__PURE__ */ O(
43
+ S,
56
44
  {
57
- id: F,
58
- onSubmit: E,
45
+ id: h,
46
+ onSubmit: b,
59
47
  noValidate: !0,
60
- ...u,
61
- ref: x,
62
48
  style: {
63
49
  position: "relative"
64
50
  },
51
+ ...R,
52
+ ref: c,
65
53
  children: [
66
- (r == null ? void 0 : r.devTool) !== "disabled" && /* @__PURE__ */ d(
67
- w,
54
+ (r == null ? void 0 : r.devTool) !== "disabled" && /* @__PURE__ */ t(
55
+ T,
68
56
  {
69
- isDev: s,
57
+ isDev: u,
70
58
  placement: "top-right",
71
59
  ...r == null ? void 0 : r.devTool
72
60
  }
73
61
  ),
74
- y,
75
- f && /* @__PURE__ */ d(P, { errors: f })
62
+ f && /* @__PURE__ */ t(f, { ctx: m }),
63
+ g,
64
+ !(r != null && r.hideRootErrors) && /* @__PURE__ */ t(V, {})
76
65
  ]
77
66
  }
78
67
  );
79
68
  }
80
69
  export {
81
- A as default
70
+ H as default
82
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
+ };
@@ -0,0 +1,21 @@
1
+ import s from "react";
2
+ import u from "../errors/useFormRequestSubmit.mjs";
3
+ const m = (t, n) => {
4
+ const o = u(t);
5
+ s.useEffect(() => {
6
+ if (n)
7
+ return;
8
+ const e = t.current;
9
+ if (!e)
10
+ throw new Error();
11
+ const r = () => {
12
+ o();
13
+ };
14
+ return e.addEventListener("change", r), () => {
15
+ e.removeEventListener("change", r);
16
+ };
17
+ }, []);
18
+ }, a = m;
19
+ export {
20
+ a as default
21
+ };
@@ -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,5 @@
1
+ import { FlatFieldErrors } from '../flat/types';
2
+ import { FieldErrors } from 'react-hook-form';
3
+
4
+ declare const getOrphansFromFieldErrors: (errors: FieldErrors, parentElement: Pick<HTMLElement, 'querySelector'>) => FlatFieldErrors;
5
+ export default getOrphansFromFieldErrors;
@@ -0,0 +1,4 @@
1
+ import { FlatFieldErrors } from '../flat/types';
2
+
3
+ declare const getOrphansFromFlatFieldErrors: (errors: FlatFieldErrors, parentElement: Pick<HTMLElement, 'querySelector'>) => FlatFieldErrors;
4
+ export default getOrphansFromFlatFieldErrors;
@@ -0,0 +1,3 @@
1
+ /// <reference types="react" />
2
+ declare const FormRootErrorsFromContext: React.FC;
3
+ export default FormRootErrorsFromContext;
@@ -0,0 +1,5 @@
1
+ import { FlatFieldErrors } from '../flat/types';
2
+ import { FieldErrors } from 'react-hook-form';
3
+
4
+ declare const getRootsFromFieldErrors: (errors: FieldErrors) => FlatFieldErrors;
5
+ export default getRootsFromFieldErrors;
@@ -0,0 +1,4 @@
1
+ import { FlatFieldErrors } from '../flat/types';
2
+
3
+ declare const getRootsFromFlatFieldErrors: (errors: FlatFieldErrors) => FlatFieldErrors;
4
+ export default getRootsFromFlatFieldErrors;
@@ -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 {};
@@ -7,17 +7,24 @@ export type FormProps<TFieldValues extends FieldValues, TTransformedValues exten
7
7
  isDev: boolean;
8
8
  formId?: string;
9
9
  formRef?: React.RefObject<HTMLFormElement>;
10
+ Fields?: React.FC<{
11
+ ctx: UseFormReturn<TFieldValues, unknown, TTransformedValues>;
12
+ }>;
10
13
  onSubmit?: (values: TTransformedValues, context: UseFormReturn<TFieldValues, unknown, TTransformedValues>, event: React.BaseSyntheticEvent<SubmitEvent>) => unknown | Promise<unknown>;
11
14
  /** Submit error handler. (Only for errors not of instance `FormError`, which are handled internally.) */
12
- 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;
13
16
  /** Submit handler when form is invalid. */
14
17
  onSubmitInvalid?: SubmitErrorHandler<TFieldValues>;
15
18
  options?: {
19
+ hideRootErrors?: boolean;
20
+ /** Request submit via listener on form change. */
21
+ submitOnChange?: boolean;
22
+ /** Reset form values if submit throw errors. Use case: optimistic UI toggle form that submits on each change */
23
+ resetValuesOnSubmitError?: boolean;
16
24
  stopSubmitPropagation?: boolean;
17
- disableEmptyRootError?: boolean;
18
25
  devTool?: DevtoolUIProps | 'disabled';
19
26
  };
20
27
  className?: string;
21
28
  }>;
22
- declare function Form<TFieldValues extends FieldValues, TTransformedValues extends FieldValues>({ isDev, formId, formRef, onSubmit, onSubmitError, onSubmitInvalid, options, children, ...props }: FormProps<TFieldValues, TTransformedValues>): import("react/jsx-runtime").JSX.Element;
29
+ declare function Form<TFieldValues extends FieldValues, TTransformedValues extends FieldValues>({ isDev, formId, formRef, Fields, onSubmit, onSubmitError, onSubmitInvalid, options, children, ...props }: FormProps<TFieldValues, TTransformedValues>): import("react/jsx-runtime").JSX.Element;
23
30
  export default Form;
@@ -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,35 +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';
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;
@@ -0,0 +1,4 @@
1
+ import { default as React } from 'react';
2
+
3
+ declare const useSubmitFormOnChange: (formRef: React.RefObject<HTMLFormElement>, disabled?: boolean) => void;
4
+ export default useSubmitFormOnChange;