@paragrav/rhf-utils 0.0.48 → 0.0.51

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 (133) hide show
  1. package/dist/assets/index-BgBykTYQ.js +40 -0
  2. package/dist/esm/devtool/LazyDevTool.mjs +7 -11
  3. package/dist/esm/env-conditions/production.mjs +4 -0
  4. package/dist/esm/errors/context/provider.mjs +11 -9
  5. package/dist/esm/errors/orphan/useOrphanFormErrorsToConsole.mjs +8 -9
  6. package/dist/esm/errors/outputErrors.mjs +5 -6
  7. package/dist/esm/errors/root/FormRootErrors.mjs +7 -7
  8. package/dist/esm/errors/root/FormRootErrorsFromContext.mjs +11 -0
  9. package/dist/esm/errors/useFormErrorsEffect.mjs +6 -6
  10. package/dist/esm/errors/useFormErrorsToConsole.mjs +17 -13
  11. package/dist/esm/{main.mjs → exports.mjs} +44 -42
  12. package/dist/esm/form/Form.mjs +41 -65
  13. package/dist/esm/form/FormWithProviders.mjs +10 -0
  14. package/dist/esm/form/context/FormProvider.mjs +17 -19
  15. package/dist/esm/form/context/group/useFormGroupChildIsMountedTracker.mjs +3 -1
  16. package/dist/esm/form/context/utils/FormUtilsContextProvider.mjs +10 -10
  17. package/dist/esm/form/useForm.mjs +15 -17
  18. package/dist/esm/form/useFormWithProviders.mjs +28 -0
  19. package/dist/esm/{form/FormError.mjs → submit/error/FormSubmitError.mjs} +2 -2
  20. package/dist/esm/submit/error/handleFormSubmitError.mjs +12 -0
  21. package/dist/esm/submit/useResetFormOnSubmitError.mjs +18 -0
  22. package/dist/esm/submit/useSubmitFormOnChange.mjs +1 -1
  23. package/dist/index.html +12 -0
  24. package/dist/types/errors/context/provider.d.ts +1 -1
  25. package/dist/types/errors/root/FormRootErrorsFromContext.d.ts +3 -0
  26. package/dist/types/errors/useFormErrorsIfAny.d.ts +1 -1
  27. package/dist/types/exports.d.ts +37 -0
  28. package/dist/types/form/ErrorBoundary.d.ts +15 -0
  29. package/dist/types/form/Form.d.ts +2 -2
  30. package/dist/types/form/FormWithProviders.d.ts +13 -0
  31. package/dist/types/form/useFormWithProviders.d.ts +31 -0
  32. package/dist/types/main.d.ts +1 -36
  33. package/dist/types/src/devtool/LazyDevTool.d.ts +9 -0
  34. package/dist/types/src/env-conditions/development.d.ts +7 -0
  35. package/dist/types/src/env-conditions/production.d.ts +1 -0
  36. package/dist/types/src/errors/consoleErrors.d.ts +13 -0
  37. package/dist/types/src/errors/context/index.d.ts +10 -0
  38. package/dist/types/src/errors/context/provider.d.ts +11 -0
  39. package/dist/types/{errors → src/errors/flat}/getFlatFieldErrors.d.ts +2 -2
  40. package/dist/types/src/errors/flat/types.d.ts +13 -0
  41. package/dist/types/src/errors/flat/useFormFlatFieldErrorsMemo.d.ts +5 -0
  42. package/dist/types/src/errors/flat/useRefdFieldErrorsMemo.d.ts +9 -0
  43. package/dist/types/src/errors/isFieldError.d.ts +7 -0
  44. package/dist/types/src/errors/message/FormErrorMessage.d.ts +8 -0
  45. package/dist/types/src/errors/message/FormErrorMessageByPath.d.ts +9 -0
  46. package/dist/types/src/errors/nonfield/FormNonFieldErrorMarker.d.ts +10 -0
  47. package/dist/types/src/errors/nonfield/FormNonFieldErrorMarker.spec.d.ts +1 -0
  48. package/dist/types/src/errors/nonfield/FormNonFieldErrorMarker.utils.d.ts +2 -0
  49. package/dist/types/src/errors/nonfield/FormNonFieldErrorMarkerHtmlAttribute.d.ts +5 -0
  50. package/dist/types/src/errors/nonfield/isNonFieldError.d.ts +19 -0
  51. package/dist/types/src/errors/orphan/getOrphansFromFieldErrors.d.ts +5 -0
  52. package/dist/types/src/errors/orphan/getOrphansFromFlatFieldErrors.d.ts +4 -0
  53. package/dist/types/src/errors/orphan/useFormHasOrphanAndNoFieldErrors.d.ts +9 -0
  54. package/dist/types/src/errors/orphan/useOrphanFormErrorsMemo.d.ts +4 -0
  55. package/dist/types/src/errors/orphan/useOrphanFormErrorsToConsole.d.ts +9 -0
  56. package/dist/types/src/errors/outputErrors.d.ts +13 -0
  57. package/dist/types/src/errors/root/FormRootErrors.d.ts +7 -0
  58. package/dist/types/src/errors/root/FormRootErrorsFromContext.d.ts +3 -0
  59. package/dist/types/src/errors/root/consts.d.ts +1 -0
  60. package/dist/types/src/errors/root/getRootsFromFieldErrors.d.ts +5 -0
  61. package/dist/types/src/errors/root/getRootsFromFlatFieldErrors.d.ts +4 -0
  62. package/dist/types/src/errors/root/isFormErrorPathRoot.d.ts +6 -0
  63. package/dist/types/src/errors/root/useRootFormFieldErrorsMemo.d.ts +6 -0
  64. package/dist/types/src/errors/useFormErrorConsoleDebug.d.ts +8 -0
  65. package/dist/types/src/errors/useFormErrorsEffect.d.ts +4 -0
  66. package/dist/types/src/errors/useFormErrorsIfAny.d.ts +6 -0
  67. package/dist/types/src/errors/useFormErrorsMemo.d.ts +7 -0
  68. package/dist/types/src/errors/useFormErrorsToConsole.d.ts +13 -0
  69. package/dist/types/src/errors/useFormRequestSubmit.d.ts +6 -0
  70. package/dist/types/src/exports.d.ts +37 -0
  71. package/dist/types/src/form/ErrorBoundary.d.ts +15 -0
  72. package/dist/types/src/form/Form.d.ts +29 -0
  73. package/dist/types/src/form/FormBase.d.ts +9 -0
  74. package/dist/types/src/form/FormWithProviders.d.ts +13 -0
  75. package/dist/types/src/form/context/FormProvider.d.ts +15 -0
  76. package/dist/types/src/form/context/group/FormGroupContextProvider.d.ts +5 -0
  77. package/dist/types/src/form/context/group/index.d.ts +15 -0
  78. package/dist/types/src/form/context/group/useFormGroupChildIsMountedTracker.d.ts +2 -0
  79. package/dist/types/src/form/context/group/useFormGroupChildIsSubmittingTracker.d.ts +2 -0
  80. package/dist/types/src/form/context/group/useFormGroupIsAnyBusy.d.ts +2 -0
  81. package/dist/types/src/form/context/group/useFormGroupIsChildBusy.d.ts +2 -0
  82. package/dist/types/src/form/context/group/useFormGroupIsParentBusy.d.ts +2 -0
  83. package/dist/types/src/form/context/group/useFormGroupParentTracker.d.ts +7 -0
  84. package/dist/types/src/form/context/utils/FormUtilsContextProvider.d.ts +14 -0
  85. package/dist/types/src/form/context/utils/useFormUtilsContext.d.ts +9 -0
  86. package/dist/types/src/form/search/FormSearch.d.ts +32 -0
  87. package/dist/types/src/form/search/FormSearchHiddenInputs.d.ts +13 -0
  88. package/dist/types/src/form/search/getNewSearchParams.d.ts +2 -0
  89. package/dist/types/src/form/useForm.d.ts +29 -0
  90. package/dist/types/src/form/useFormIsBusy.d.ts +2 -0
  91. package/dist/types/src/form/useFormOrParentIsBusy.d.ts +2 -0
  92. package/dist/types/{form/useFormWithProvider.d.ts → src/form/useFormWithProviders.d.ts} +4 -4
  93. package/dist/types/src/form/utils/getSubmitterButtonData.d.ts +11 -0
  94. package/dist/types/src/isEmptyObject.d.ts +2 -0
  95. package/dist/types/src/main.d.ts +1 -0
  96. package/dist/types/{form/FormError.d.ts → src/submit/error/FormSubmitError.d.ts} +1 -1
  97. package/dist/types/src/submit/error/handleFormSubmitError.d.ts +7 -0
  98. package/dist/types/src/submit/useFormOnSubmitSuccessful.d.ts +2 -0
  99. package/dist/types/src/submit/useFormOnSubmitSuccessfulAndReset.d.ts +13 -0
  100. package/dist/types/src/submit/useResetFormOnSubmitError.d.ts +7 -0
  101. package/dist/types/src/submit/useResetFormOnSubmitSuccessful.d.ts +12 -0
  102. package/dist/types/src/submit/useSubmitFormOnChange.d.ts +4 -0
  103. package/dist/types/{utils/createRequiredContext.d.ts → src/utils/createContext.d.ts} +2 -2
  104. package/dist/types/src/utils/fixedForwardRef.d.ts +7 -0
  105. package/dist/types/src/utils/useImperativeForwardedRef.d.ts +11 -0
  106. package/dist/types/src/utils/useThrowAsyncError.d.ts +5 -0
  107. package/dist/types/src/utils/useToggle.d.ts +4 -0
  108. package/dist/types/submit/error/FormSubmitError.d.ts +6 -0
  109. package/dist/types/submit/error/handleFormSubmitError.d.ts +7 -0
  110. package/dist/types/submit/useResetFormOnSubmitError.d.ts +7 -0
  111. package/dist/types/submit/useSubmitFormOnChange.d.ts +1 -1
  112. package/dist/types/utils/useThrowAsyncError.d.ts +5 -0
  113. package/package.json +30 -17
  114. package/dist/esm/form/FormWithProvider.mjs +0 -9
  115. package/dist/esm/form/useFormWithProvider.mjs +0 -30
  116. package/dist/types/errors/flat/getFlatFieldErrorsByFilter.d.ts +0 -9
  117. package/dist/types/errors/orphan/getOrphanFlatFieldErrors.d.ts +0 -5
  118. package/dist/types/errors/orphan/useOrphanFormErrors.d.ts +0 -4
  119. package/dist/types/errors/orphan/useOrphanFormErrorsToConsoleError.d.ts +0 -9
  120. package/dist/types/errors/root/getRootFlatFieldErrors.d.ts +0 -8
  121. package/dist/types/errors/root/useRootFormFieldErrors.d.ts +0 -6
  122. package/dist/types/errors/root/utils.d.ts +0 -12
  123. package/dist/types/errors/useFormErrorsOnChange.d.ts +0 -7
  124. package/dist/types/errors/useFormFieldErrors.d.ts +0 -6
  125. package/dist/types/errors/useFormFlatFieldErrors.d.ts +0 -5
  126. package/dist/types/form/FormWithProvider.d.ts +0 -13
  127. package/dist/types/form/context/group/useAsFormGroupParent.d.ts +0 -7
  128. package/dist/types/form/context/parent/FormParentContextProvider.d.ts +0 -5
  129. package/dist/types/form/context/parent/index.d.ts +0 -6
  130. package/dist/types/form/context/parent/useAsFormParentState.d.ts +0 -7
  131. package/dist/types/form/context/parent/useFormParentIsBusy.d.ts +0 -7
  132. package/dist/types/form/toggle/ToggleForm.d.ts +0 -18
  133. /package/dist/types/{errors → src/errors/flat}/flattenFieldErrors.d.ts +0 -0
@@ -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,63 @@
1
- import { jsxs as R, jsx as l } from "react/jsx-runtime";
1
+ import { jsxs as C, 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";
3
+ import { useFormContext as O } from "react-hook-form";
4
+ import v from "../devtool/LazyDevTool.mjs";
5
+ import T from "../errors/root/FormRootErrorsFromContext.mjs";
6
+ import V from "../submit/error/handleFormSubmitError.mjs";
7
+ import j from "../submit/useResetFormOnSubmitError.mjs";
7
8
  import w from "../submit/useSubmitFormOnChange.mjs";
8
- 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,
9
+ import E from "../utils/useImperativeForwardedRef.mjs";
10
+ import P from "./FormBase.mjs";
11
+ function G({
12
+ formId: u,
13
+ formRef: h,
14
+ Fields: f,
16
15
  //
17
- onSubmit: a,
18
- onSubmitError: t,
19
- onSubmitInvalid: x,
16
+ onSubmit: d,
17
+ onSubmitError: l,
18
+ onSubmitInvalid: F,
20
19
  //
21
20
  options: r,
22
21
  //
23
- children: g,
24
- ...s
22
+ children: x,
23
+ ...g
25
24
  }) {
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) => {
25
+ const m = O(), c = E(h);
26
+ w(c, !(r != null && r.submitOnChange)), j(!(r != null && r.resetValuesOnSubmitError));
27
+ const R = async (e) => {
28
+ r != null && r.stopSubmitPropagation && e.stopPropagation();
34
29
  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
- );
30
+ await m.handleSubmit(b, F)(e);
31
+ } catch (a) {
32
+ y(a, e);
56
33
  }
34
+ }, b = (e, a) => d == null ? void 0 : d(
35
+ e,
36
+ m,
37
+ a
38
+ ), y = (e, a) => {
39
+ V(e, m), l == null || l(e, m, a);
57
40
  };
58
- return /* @__PURE__ */ R(
59
- z,
41
+ return /* @__PURE__ */ C(
42
+ P,
60
43
  {
61
- id: y,
62
- onSubmit: b,
44
+ id: u,
45
+ onSubmit: R,
63
46
  noValidate: !0,
64
- ...s,
65
- ref: d,
66
47
  style: {
67
48
  position: "relative"
68
49
  },
50
+ ...g,
51
+ ref: c,
69
52
  children: [
70
- (r == null ? void 0 : r.devTool) !== "disabled" && /* @__PURE__ */ l(
71
- j,
72
- {
73
- isDev: F,
74
- placement: "top-right",
75
- ...r == null ? void 0 : r.devTool
76
- }
77
- ),
78
- c && /* @__PURE__ */ l(c, { ctx: e }),
79
- g,
80
- u && /* @__PURE__ */ l(V, { errors: u })
53
+ (r == null ? void 0 : r.devTool) !== "disabled" && /* @__PURE__ */ t(v, { placement: "top-right", ...r == null ? void 0 : r.devTool }),
54
+ f && /* @__PURE__ */ t(f, { ctx: m }),
55
+ x,
56
+ !(r != null && r.hideRootErrors) && /* @__PURE__ */ t(T, {})
81
57
  ]
82
58
  }
83
59
  );
84
60
  }
85
61
  export {
86
- K as default
62
+ G as default
87
63
  };
@@ -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
+ };
@@ -1,27 +1,25 @@
1
1
  import { jsx as r } from "react/jsx-runtime";
2
- import { FormProvider as n } from "react-hook-form";
3
- import p from "./utils/FormUtilsContextProvider.mjs";
4
- function F({
5
- isDev: o,
6
- formId: m,
7
- formRef: i,
8
- rhf: t,
9
- form: e,
10
- utils: d,
11
- children: f
2
+ import { FormProvider as f } from "react-hook-form";
3
+ import n from "./utils/FormUtilsContextProvider.mjs";
4
+ function v({
5
+ formId: o,
6
+ formRef: m,
7
+ rhf: i,
8
+ form: t,
9
+ utils: e,
10
+ children: d
12
11
  }) {
13
- return /* @__PURE__ */ r(n, { ...t, children: /* @__PURE__ */ r(
14
- p,
12
+ return /* @__PURE__ */ r(f, { ...i, children: /* @__PURE__ */ r(
13
+ n,
15
14
  {
16
- isDev: o,
17
- formId: m,
18
- formRef: i,
19
- formProps: e,
20
- ...d,
21
- children: f
15
+ formId: o,
16
+ formRef: m,
17
+ formProps: t,
18
+ ...e,
19
+ children: d
22
20
  }
23
21
  ) });
24
22
  }
25
23
  export {
26
- F as default
24
+ v as default
27
25
  };
@@ -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 {
@@ -1,20 +1,20 @@
1
- import { jsx as i } from "react/jsx-runtime";
1
+ import { jsx as e } from "react/jsx-runtime";
2
+ import { isDevelopment as i } from "../../../env-conditions/production.mjs";
2
3
  import p from "../../../errors/orphan/useOrphanFormErrorsToConsole.mjs";
3
- import F from "../../../errors/useFormErrorConsoleDebug.mjs";
4
- import u from "../../../errors/useFormRequestSubmit.mjs";
5
- import a from "../../../submit/useFormOnSubmitSuccessfulAndReset.mjs";
6
- import s from "../../../submit/useResetFormOnSubmitSuccessful.mjs";
4
+ import s from "../../../errors/useFormErrorConsoleDebug.mjs";
5
+ import F from "../../../errors/useFormRequestSubmit.mjs";
6
+ import u from "../../../submit/useFormOnSubmitSuccessfulAndReset.mjs";
7
+ import a from "../../../submit/useResetFormOnSubmitSuccessful.mjs";
7
8
  import { _FormUtilsContextProvider as l } from "./useFormUtilsContext.mjs";
8
9
  function O({
9
- isDev: m,
10
10
  formRef: o,
11
11
  onSubmitSuccessfulAndReset: r,
12
- children: t
12
+ children: m
13
13
  }) {
14
- const e = u(o);
15
- return F(m), p(o, m, !0), s({ enabled: !!r }), a(() => {
14
+ const t = F(o);
15
+ return s(i), p(o, !0), a({ enabled: !!r }), u(() => {
16
16
  r == null || r();
17
- }), /* @__PURE__ */ i(l, { value: { formRef: o, requestSubmit: e }, children: t });
17
+ }), /* @__PURE__ */ e(l, { value: { formRef: o, requestSubmit: t }, children: m });
18
18
  }
19
19
  export {
20
20
  O as default
@@ -1,31 +1,29 @@
1
- import { jsx as i } from "react/jsx-runtime";
2
- import u from "react";
3
- import { useForm as F } from "react-hook-form";
4
- import c from "../utils/useImperativeForwardedRef.mjs";
5
- import f from "./Form.mjs";
6
- const p = ({
7
- isDev: e,
8
- rhf: m,
1
+ import { jsx as n } from "react/jsx-runtime";
2
+ import i from "react";
3
+ import { useForm as u } from "react-hook-form";
4
+ import F from "../utils/useImperativeForwardedRef.mjs";
5
+ import c from "./Form.mjs";
6
+ const f = ({
7
+ rhf: e,
9
8
  form: o
10
9
  }) => {
11
- const r = u.useId(), s = F(m), t = c();
10
+ const r = i.useId(), m = u(e), t = F();
12
11
  return {
13
12
  id: r,
14
13
  ref: t,
15
- context: s,
16
- Form: ({ children: n }) => /* @__PURE__ */ i(
17
- f,
14
+ context: m,
15
+ Form: ({ children: s }) => /* @__PURE__ */ n(
16
+ c,
18
17
  {
19
- ...o,
20
- isDev: e,
21
18
  formId: r,
22
19
  formRef: t,
23
20
  onSubmit: o == null ? void 0 : o.onSubmit,
24
- children: n
21
+ ...o,
22
+ children: s
25
23
  }
26
24
  )
27
25
  };
28
- }, S = p;
26
+ }, b = f;
29
27
  export {
30
- S as default
28
+ b as default
31
29
  };
@@ -0,0 +1,28 @@
1
+ import { jsx as i } from "react/jsx-runtime";
2
+ import "react";
3
+ import s from "./context/FormProvider.mjs";
4
+ import f from "./useForm.mjs";
5
+ const d = ({
6
+ rhf: t,
7
+ form: o,
8
+ utils: e
9
+ }) => {
10
+ const r = f({ rhf: t, form: o });
11
+ return {
12
+ ...r,
13
+ Provider: ({ children: m }) => /* @__PURE__ */ i(
14
+ s,
15
+ {
16
+ formRef: r.ref,
17
+ rhf: r.context,
18
+ formId: r.id,
19
+ form: o,
20
+ utils: e,
21
+ children: m
22
+ }
23
+ )
24
+ };
25
+ }, P = d;
26
+ export {
27
+ P as default
28
+ };
@@ -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;
@@ -0,0 +1,31 @@
1
+ import { UseFormProps } from './useForm';
2
+ import { FormUtilsContextProviderProps } from './context/utils/FormUtilsContextProvider';
3
+ import { FieldValues } from 'react-hook-form';
4
+ import { default as React } from 'react';
5
+
6
+ export type UseFormWithProvidersProps<TFieldValues extends FieldValues, TTransformedValues extends FieldValues> = UseFormProps<TFieldValues, TTransformedValues> & {
7
+ /** {@link FormUtilsContextProviderProps} props for `FormUtilsContextProvider`. */
8
+ utils?: FormUtilsContextProviderProps;
9
+ };
10
+ export type UseFormWithProvidersReturn = ReturnType<typeof useFormWithProviders>;
11
+ /**
12
+ * Base Rhf Form hook. Use `Form` in `index.ts` for most cases.
13
+ * Use this if you need to separate form components.
14
+ * e.g., a form for table row due to `form` being considered invalid HTML around `tr` tags.
15
+ * With this hook, you can wrap the `tr` tag with `form.Provider` and use `form.Form` inside
16
+ * one of the cells. Other components can be outside form while referring to form by its id via `form` attribute.
17
+ * see https://caniuse.com/?search=form%20attribute
18
+ * @returns Form provider and form.
19
+ */
20
+ declare const useFormWithProviders: <TFieldValues extends FieldValues, TTransformedValues extends FieldValues>({ isDev, rhf, form, utils, }: UseFormWithProvidersProps<TFieldValues, TTransformedValues>) => {
21
+ readonly Provider: React.FC<{
22
+ children?: React.ReactNode;
23
+ }>;
24
+ readonly id: string;
25
+ readonly ref: React.RefObject<HTMLFormElement>;
26
+ readonly context: import('react-hook-form').UseFormReturn<TFieldValues, unknown, TTransformedValues>;
27
+ readonly Form: React.FC<{
28
+ children?: React.ReactNode;
29
+ }>;
30
+ };
31
+ export default useFormWithProviders;