@paragrav/rhf-utils 0.0.50 → 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 (86) hide show
  1. package/dist/esm/devtool/LazyDevTool.mjs +7 -11
  2. package/dist/esm/env-conditions/production.mjs +4 -0
  3. package/dist/esm/errors/orphan/useOrphanFormErrorsToConsole.mjs +8 -9
  4. package/dist/esm/errors/outputErrors.mjs +5 -6
  5. package/dist/esm/form/Form.mjs +32 -40
  6. package/dist/esm/form/context/FormProvider.mjs +17 -19
  7. package/dist/esm/form/context/utils/FormUtilsContextProvider.mjs +10 -10
  8. package/dist/esm/form/useForm.mjs +14 -16
  9. package/dist/esm/form/useFormWithProviders.mjs +15 -17
  10. package/dist/types/src/devtool/LazyDevTool.d.ts +9 -0
  11. package/dist/types/src/env-conditions/development.d.ts +7 -0
  12. package/dist/types/src/env-conditions/production.d.ts +1 -0
  13. package/dist/types/src/errors/consoleErrors.d.ts +13 -0
  14. package/dist/types/src/errors/context/index.d.ts +10 -0
  15. package/dist/types/src/errors/context/provider.d.ts +11 -0
  16. package/dist/types/src/errors/flat/flattenFieldErrors.d.ts +15 -0
  17. package/dist/types/src/errors/flat/getFlatFieldErrors.d.ts +25 -0
  18. package/dist/types/src/errors/flat/types.d.ts +13 -0
  19. package/dist/types/src/errors/flat/useFormFlatFieldErrorsMemo.d.ts +5 -0
  20. package/dist/types/src/errors/flat/useRefdFieldErrorsMemo.d.ts +9 -0
  21. package/dist/types/src/errors/isFieldError.d.ts +7 -0
  22. package/dist/types/src/errors/message/FormErrorMessage.d.ts +8 -0
  23. package/dist/types/src/errors/message/FormErrorMessageByPath.d.ts +9 -0
  24. package/dist/types/src/errors/nonfield/FormNonFieldErrorMarker.d.ts +10 -0
  25. package/dist/types/src/errors/nonfield/FormNonFieldErrorMarker.spec.d.ts +1 -0
  26. package/dist/types/src/errors/nonfield/FormNonFieldErrorMarker.utils.d.ts +2 -0
  27. package/dist/types/src/errors/nonfield/FormNonFieldErrorMarkerHtmlAttribute.d.ts +5 -0
  28. package/dist/types/src/errors/nonfield/isNonFieldError.d.ts +19 -0
  29. package/dist/types/src/errors/orphan/getOrphansFromFieldErrors.d.ts +5 -0
  30. package/dist/types/src/errors/orphan/getOrphansFromFlatFieldErrors.d.ts +4 -0
  31. package/dist/types/src/errors/orphan/useFormHasOrphanAndNoFieldErrors.d.ts +9 -0
  32. package/dist/types/src/errors/orphan/useOrphanFormErrorsMemo.d.ts +4 -0
  33. package/dist/types/src/errors/orphan/useOrphanFormErrorsToConsole.d.ts +9 -0
  34. package/dist/types/src/errors/outputErrors.d.ts +13 -0
  35. package/dist/types/src/errors/root/FormRootErrors.d.ts +7 -0
  36. package/dist/types/src/errors/root/FormRootErrorsFromContext.d.ts +3 -0
  37. package/dist/types/src/errors/root/consts.d.ts +1 -0
  38. package/dist/types/src/errors/root/getRootsFromFieldErrors.d.ts +5 -0
  39. package/dist/types/src/errors/root/getRootsFromFlatFieldErrors.d.ts +4 -0
  40. package/dist/types/src/errors/root/isFormErrorPathRoot.d.ts +6 -0
  41. package/dist/types/src/errors/root/useRootFormFieldErrorsMemo.d.ts +6 -0
  42. package/dist/types/src/errors/useFormErrorConsoleDebug.d.ts +8 -0
  43. package/dist/types/src/errors/useFormErrorsEffect.d.ts +4 -0
  44. package/dist/types/src/errors/useFormErrorsIfAny.d.ts +6 -0
  45. package/dist/types/src/errors/useFormErrorsMemo.d.ts +7 -0
  46. package/dist/types/src/errors/useFormErrorsToConsole.d.ts +13 -0
  47. package/dist/types/src/errors/useFormRequestSubmit.d.ts +6 -0
  48. package/dist/types/src/exports.d.ts +37 -0
  49. package/dist/types/src/form/ErrorBoundary.d.ts +15 -0
  50. package/dist/types/src/form/Form.d.ts +29 -0
  51. package/dist/types/src/form/FormBase.d.ts +9 -0
  52. package/dist/types/src/form/FormWithProviders.d.ts +13 -0
  53. package/dist/types/src/form/context/FormProvider.d.ts +15 -0
  54. package/dist/types/src/form/context/group/FormGroupContextProvider.d.ts +5 -0
  55. package/dist/types/src/form/context/group/index.d.ts +15 -0
  56. package/dist/types/src/form/context/group/useFormGroupChildIsMountedTracker.d.ts +2 -0
  57. package/dist/types/src/form/context/group/useFormGroupChildIsSubmittingTracker.d.ts +2 -0
  58. package/dist/types/src/form/context/group/useFormGroupIsAnyBusy.d.ts +2 -0
  59. package/dist/types/src/form/context/group/useFormGroupIsChildBusy.d.ts +2 -0
  60. package/dist/types/src/form/context/group/useFormGroupIsParentBusy.d.ts +2 -0
  61. package/dist/types/src/form/context/group/useFormGroupParentTracker.d.ts +7 -0
  62. package/dist/types/src/form/context/utils/FormUtilsContextProvider.d.ts +14 -0
  63. package/dist/types/src/form/context/utils/useFormUtilsContext.d.ts +9 -0
  64. package/dist/types/src/form/search/FormSearch.d.ts +32 -0
  65. package/dist/types/src/form/search/FormSearchHiddenInputs.d.ts +13 -0
  66. package/dist/types/src/form/search/getNewSearchParams.d.ts +2 -0
  67. package/dist/types/src/form/useForm.d.ts +29 -0
  68. package/dist/types/src/form/useFormIsBusy.d.ts +2 -0
  69. package/dist/types/src/form/useFormOrParentIsBusy.d.ts +2 -0
  70. package/dist/types/src/form/useFormWithProviders.d.ts +31 -0
  71. package/dist/types/src/form/utils/getSubmitterButtonData.d.ts +11 -0
  72. package/dist/types/src/isEmptyObject.d.ts +2 -0
  73. package/dist/types/src/main.d.ts +1 -0
  74. package/dist/types/src/submit/error/FormSubmitError.d.ts +6 -0
  75. package/dist/types/src/submit/error/handleFormSubmitError.d.ts +7 -0
  76. package/dist/types/src/submit/useFormOnSubmitSuccessful.d.ts +2 -0
  77. package/dist/types/src/submit/useFormOnSubmitSuccessfulAndReset.d.ts +13 -0
  78. package/dist/types/src/submit/useResetFormOnSubmitError.d.ts +7 -0
  79. package/dist/types/src/submit/useResetFormOnSubmitSuccessful.d.ts +12 -0
  80. package/dist/types/src/submit/useSubmitFormOnChange.d.ts +4 -0
  81. package/dist/types/src/utils/createContext.d.ts +8 -0
  82. package/dist/types/src/utils/fixedForwardRef.d.ts +7 -0
  83. package/dist/types/src/utils/useImperativeForwardedRef.d.ts +11 -0
  84. package/dist/types/src/utils/useThrowAsyncError.d.ts +5 -0
  85. package/dist/types/src/utils/useToggle.d.ts +4 -0
  86. package/package.json +9 -3
@@ -1,16 +1,12 @@
1
- import { jsx as t } from "react/jsx-runtime";
2
- import e from "react";
3
- import { useFormContext as n } from "react-hook-form";
4
- const a = e.lazy(
1
+ import "react/jsx-runtime";
2
+ import t from "react";
3
+ import "react-hook-form";
4
+ t.lazy(
5
5
  () => import("@hookform/devtools").then((o) => ({
6
6
  default: o.DevTool
7
7
  }))
8
- ), s = ({ isDev: o, ...l }) => {
9
- if (!o)
10
- return null;
11
- const { control: r } = n();
12
- return /* @__PURE__ */ t(e.Suspense, { fallback: null, children: /* @__PURE__ */ t(a, { control: r, ...l }) });
13
- }, u = s;
8
+ );
9
+ const e = (o) => null, p = e;
14
10
  export {
15
- u as default
11
+ p as default
16
12
  };
@@ -0,0 +1,4 @@
1
+ const e = !1;
2
+ export {
3
+ e as isDevelopment
4
+ };
@@ -1,18 +1,17 @@
1
1
  import "react";
2
- import n from "../useFormErrorsToConsole.mjs";
3
- import t from "./useOrphanFormErrorsMemo.mjs";
4
- const a = (r, s, e) => {
5
- const o = t(r);
6
- n("Orphan errors detected!", o, {
7
- disabled: !e,
8
- isDev: s,
2
+ import e from "../useFormErrorsToConsole.mjs";
3
+ import n from "./useOrphanFormErrorsMemo.mjs";
4
+ const t = (r, s) => {
5
+ const o = n(r);
6
+ e("Orphan errors detected!", o, {
7
+ disabled: !s,
9
8
  isError: !0,
10
9
  data: {
11
10
  location: window.location,
12
11
  orphans: o
13
12
  }
14
13
  });
15
- }, d = a;
14
+ }, i = t;
16
15
  export {
17
- d as default
16
+ i as default
18
17
  };
@@ -1,8 +1,7 @@
1
- import t from "./consoleErrors.mjs";
2
- const c = (u, E, r) => {
3
- if (t(u, E, r), r != null && r.isDev && r.isError)
4
- throw new Error(u);
5
- }, f = c;
1
+ import s from "./consoleErrors.mjs";
2
+ const u = (o, r, t) => {
3
+ s(o, r, t);
4
+ }, c = u;
6
5
  export {
7
- f as default
6
+ c as default
8
7
  };
@@ -1,71 +1,63 @@
1
- import { jsxs as O, jsx as t } from "react/jsx-runtime";
1
+ import { jsxs as C, jsx as t } from "react/jsx-runtime";
2
2
  import "react";
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,
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";
8
+ import w from "../submit/useSubmitFormOnChange.mjs";
9
+ import E from "../utils/useImperativeForwardedRef.mjs";
10
+ import P from "./FormBase.mjs";
11
+ function G({
12
+ formId: u,
13
+ formRef: h,
15
14
  Fields: f,
16
15
  //
17
16
  onSubmit: d,
18
17
  onSubmitError: l,
19
- onSubmitInvalid: x,
18
+ onSubmitInvalid: F,
20
19
  //
21
20
  options: r,
22
21
  //
23
- children: g,
24
- ...R
22
+ children: x,
23
+ ...g
25
24
  }) {
26
- const m = v(), c = P(F);
27
- E(c, !(r != null && r.submitOnChange)), w(!(r != null && r.resetValuesOnSubmitError));
28
- const b = async (e) => {
25
+ const m = O(), c = E(h);
26
+ w(c, !(r != null && r.submitOnChange)), j(!(r != null && r.resetValuesOnSubmitError));
27
+ const R = async (e) => {
29
28
  r != null && r.stopSubmitPropagation && e.stopPropagation();
30
29
  try {
31
- await m.handleSubmit(y, x)(e);
30
+ await m.handleSubmit(b, F)(e);
32
31
  } catch (a) {
33
- C(a, e);
32
+ y(a, e);
34
33
  }
35
- }, y = (e, a) => d == null ? void 0 : d(
34
+ }, b = (e, a) => d == null ? void 0 : d(
36
35
  e,
37
36
  m,
38
37
  a
39
- ), C = (e, a) => {
40
- j(e, m), l == null || l(e, m, a);
38
+ ), y = (e, a) => {
39
+ V(e, m), l == null || l(e, m, a);
41
40
  };
42
- return /* @__PURE__ */ O(
43
- S,
41
+ return /* @__PURE__ */ C(
42
+ P,
44
43
  {
45
- id: h,
46
- onSubmit: b,
44
+ id: u,
45
+ onSubmit: R,
47
46
  noValidate: !0,
48
47
  style: {
49
48
  position: "relative"
50
49
  },
51
- ...R,
50
+ ...g,
52
51
  ref: c,
53
52
  children: [
54
- (r == null ? void 0 : r.devTool) !== "disabled" && /* @__PURE__ */ t(
55
- T,
56
- {
57
- isDev: u,
58
- placement: "top-right",
59
- ...r == null ? void 0 : r.devTool
60
- }
61
- ),
53
+ (r == null ? void 0 : r.devTool) !== "disabled" && /* @__PURE__ */ t(v, { placement: "top-right", ...r == null ? void 0 : r.devTool }),
62
54
  f && /* @__PURE__ */ t(f, { ctx: m }),
63
- g,
64
- !(r != null && r.hideRootErrors) && /* @__PURE__ */ t(V, {})
55
+ x,
56
+ !(r != null && r.hideRootErrors) && /* @__PURE__ */ t(T, {})
65
57
  ]
66
58
  }
67
59
  );
68
60
  }
69
61
  export {
70
- H as default
62
+ G as default
71
63
  };
@@ -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
  };
@@ -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
- isDev: e,
20
18
  formId: r,
21
19
  formRef: t,
22
20
  onSubmit: o == null ? void 0 : o.onSubmit,
23
21
  ...o,
24
- children: n
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
  };
@@ -1,30 +1,28 @@
1
- import { jsx as s } from "react/jsx-runtime";
1
+ import { jsx as i } from "react/jsx-runtime";
2
2
  import "react";
3
- import f from "./context/FormProvider.mjs";
4
- import d from "./useForm.mjs";
5
- const n = ({
6
- isDev: o,
7
- rhf: e,
8
- form: t,
9
- utils: m
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
10
9
  }) => {
11
- const r = d({ isDev: o, rhf: e, form: t });
10
+ const r = f({ rhf: t, form: o });
12
11
  return {
13
12
  ...r,
14
- Provider: ({ children: i }) => /* @__PURE__ */ s(
15
- f,
13
+ Provider: ({ children: m }) => /* @__PURE__ */ i(
14
+ s,
16
15
  {
17
- isDev: o,
18
16
  formRef: r.ref,
19
17
  rhf: r.context,
20
18
  formId: r.id,
21
- form: t,
22
- utils: m,
23
- children: i
19
+ form: o,
20
+ utils: e,
21
+ children: m
24
22
  }
25
23
  )
26
24
  };
27
- }, F = n;
25
+ }, P = d;
28
26
  export {
29
- F as default
27
+ P as default
30
28
  };
@@ -0,0 +1,9 @@
1
+ import { default as React } from 'react';
2
+ import { DevtoolUIProps } from '@hookform/devtools/dist/devToolUI';
3
+
4
+ export type LazyDevToolProps = Omit<DevtoolUIProps, 'control'>;
5
+ /**
6
+ * Lazy-loaded RHF DevTool.
7
+ */
8
+ declare const LazyDevTool: React.FC<LazyDevToolProps>;
9
+ export default LazyDevTool;
@@ -0,0 +1,7 @@
1
+ /**
2
+ * Determined whether env is dev via `imports`.
3
+ *
4
+ * Technique borrowed from react-error-boundary {@link https://github.com/bvaughn/react-error-boundary/blob/master/package.json}.
5
+ * Assign `boolean` type to avoid `@typescript-eslint/no-unnecessary-condition`.
6
+ */
7
+ export declare const isDevelopment: boolean;
@@ -0,0 +1 @@
1
+ export declare const isDevelopment: boolean;
@@ -0,0 +1,13 @@
1
+ import { FieldErrors, FieldValues } from 'react-hook-form';
2
+
3
+ /**
4
+ * Output form values and errors to console.
5
+ */
6
+ declare const consoleErrors: (message: string, form: {
7
+ values: FieldValues;
8
+ errors: FieldErrors;
9
+ }, options?: {
10
+ other?: Record<string, unknown>;
11
+ isError?: boolean;
12
+ }) => void;
13
+ export default consoleErrors;
@@ -0,0 +1,10 @@
1
+ import { FlatFieldErrors } from '../flat/types';
2
+
3
+ export type FormErrorsFlatContext = {
4
+ all: FlatFieldErrors;
5
+ roots: FlatFieldErrors;
6
+ orphans: FlatFieldErrors;
7
+ };
8
+ declare const useFormErrorsFlatContextMaybe: () => FormErrorsFlatContext | undefined, useFormErrorsFlatContext: () => FormErrorsFlatContext, _FormErrorsFlatContextProvider: import('react').Provider<FormErrorsFlatContext | undefined>;
9
+ export default useFormErrorsFlatContext;
10
+ export { _FormErrorsFlatContextProvider, useFormErrorsFlatContextMaybe };
@@ -0,0 +1,11 @@
1
+ /// <reference types="react" />
2
+ type Props = React.PropsWithChildren<{
3
+ formRef: React.RefObject<HTMLFormElement>;
4
+ outputErrors?: boolean;
5
+ }>;
6
+ /**
7
+ * Provides a flattened version of the form errors.
8
+ * Allows flattening and filtering to happen once per errors change.
9
+ */
10
+ declare const FormErrorsFlatContextProvider: React.FC<Props>;
11
+ export default FormErrorsFlatContextProvider;
@@ -0,0 +1,15 @@
1
+ import { FieldErrors } from 'react-hook-form';
2
+
3
+ /**
4
+ * Only flattens a {@link FieldErrors} object.
5
+ * @returns e.g.,
6
+ * ```
7
+ * {
8
+ * "address.street.type": "too_short",
9
+ * "address.street.ref.value": "123",
10
+ * "address.street.message": "Required."
11
+ * }
12
+ * ```
13
+ */
14
+ declare const flattenFieldErrors: (errors: FieldErrors) => Record<string, unknown>;
15
+ export default flattenFieldErrors;
@@ -0,0 +1,25 @@
1
+ import { FlatFieldErrors } from './types';
2
+ import { FieldErrors } from 'react-hook-form';
3
+
4
+ /**
5
+ * Get {@link FlatFieldErrors} from {@link FieldErrors}.
6
+ * This makes it easy to work with potentially deeply-nested {@link FieldErrors}.
7
+ *
8
+ * @param errors {@link FieldErrors} object.
9
+ * @returns FlatFieldErrors object.
10
+ *
11
+ * e.g.,
12
+ * ```
13
+ * [ "address.street", { "address.street": { type: "too_short", ref: { value: "123" }, message: "Required." } } ]
14
+ * ```
15
+ */
16
+ declare const getFlatFieldErrors: (errors: FieldErrors) => FlatFieldErrors;
17
+ export default getFlatFieldErrors;
18
+ /**
19
+ * Regular expression to maybe match the end of a leaf node path.
20
+ *
21
+ * i.e., `name.type`, `address.street.message`
22
+ *
23
+ * iow: dot [?: non-capturing]("type" | "message")[\b word boundary][$ end of string]
24
+ */
25
+ export declare const regexMaybeFieldErrorLeafNode: RegExp;
@@ -0,0 +1,13 @@
1
+ import { FieldError } from 'react-hook-form';
2
+
3
+ /**
4
+ * Flattened field errors object.
5
+ *
6
+ * @example
7
+ * ```ts
8
+ * {
9
+ * 'address.street': FieldError
10
+ * }
11
+ * ```
12
+ */
13
+ export type FlatFieldErrors = Record<string, FieldError>;
@@ -0,0 +1,5 @@
1
+ /**
2
+ * Use {@link FieldErrors} as {@link FlatFieldErrors}.
3
+ */
4
+ declare const useFormFlatFieldErrorsMemo: () => import('./types').FlatFieldErrors;
5
+ export default useFormFlatFieldErrorsMemo;
@@ -0,0 +1,9 @@
1
+ import { FlatFieldErrors } from './types';
2
+ import { FieldErrors } from 'react-hook-form';
3
+
4
+ /**
5
+ * Use errors with refs.
6
+ */
7
+ declare const useRefdFieldErrorsMemo: () => FlatFieldErrors;
8
+ export default useRefdFieldErrorsMemo;
9
+ export declare const getFlatFieldFormErrors: (errors: FieldErrors) => FlatFieldErrors;
@@ -0,0 +1,7 @@
1
+ import { FieldError } from 'react-hook-form';
2
+
3
+ /**
4
+ * Determine if {@link FieldError} is a field error (i.e., has `ref`).
5
+ */
6
+ declare const isFieldError: (error: FieldError) => boolean;
7
+ export default isFieldError;
@@ -0,0 +1,8 @@
1
+ import { default as React } from 'react';
2
+
3
+ type Props = {
4
+ message: string;
5
+ className?: string;
6
+ };
7
+ declare const FormErrorMessage: React.FC<Props>;
8
+ export default FormErrorMessage;
@@ -0,0 +1,9 @@
1
+ /// <reference types="react" />
2
+ type Props = {
3
+ name: string;
4
+ Component?: React.FC<{
5
+ message: string;
6
+ }>;
7
+ };
8
+ declare const FormErrorMessageByPath: React.FC<Props>;
9
+ export default FormErrorMessageByPath;
@@ -0,0 +1,10 @@
1
+ /// <reference types="react" />
2
+ type Props = {
3
+ /** Flat field name. (e.g., `address.street`) */
4
+ path: string;
5
+ };
6
+ /**
7
+ * Empty, hidden marker to indicate a non-field/non-root error is being displayed to user.
8
+ */
9
+ declare const FormNonFieldErrorMarker: React.FC<Props>;
10
+ export default FormNonFieldErrorMarker;
@@ -0,0 +1,2 @@
1
+ export declare const getFormNonFieldErrorMarkerQuerySelector: (path: string) => string;
2
+ export declare const hasNonFieldErrorMarkerInDOM: (path: string, parentElement: Pick<HTMLElement, 'querySelector'>) => boolean;
@@ -0,0 +1,5 @@
1
+ /**
2
+ * HTML data attribute for {@link FormNonFieldErrorMarker}.
3
+ */
4
+ declare const FormNonFieldErrorMarkerHtmlAttribute = "data-paragrav-rhf-utils-nonfield-error-marker-path";
5
+ export default FormNonFieldErrorMarkerHtmlAttribute;
@@ -0,0 +1,19 @@
1
+ import { FieldError } from 'react-hook-form';
2
+
3
+ /**
4
+ * Determine if {@link FieldError} is a non-field error (i.e., has no `ref`).
5
+ *
6
+ * A non-field error has no association to an input via {@link FieldError.ref}.
7
+ *
8
+ * These fall into one of two categories:
9
+ * - Root, which are typically displayed to user at bottom/top of form.
10
+ * - Non-root, which fall into two main sub-sets:
11
+ * - Non-orphan (displayed -- typically manually)
12
+ * - e.g., array min/max validation
13
+ * - Orphan (undisplayed), which are typically caused by one of the following cases:
14
+ * - The input is missing.
15
+ * - The schema is incorrect.
16
+ * - The error is not displayed to user with `FormErrorNonFieldMarker`.
17
+ */
18
+ declare const isNonFieldError: (error: FieldError) => boolean;
19
+ export default isNonFieldError;
@@ -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,9 @@
1
+ /**
2
+ * Determined if there are orphan errors and no field errors.
3
+ * (May be useful when reporting or displaying a specific message to user.)
4
+ * RHF doesn't seem to have any other mechanism to indicate a failed submit but to `setErrors()`.
5
+ * Therefore, we have no way of distinguishing between "placeholder" root error and actual error.
6
+ * (e.g., "Please fix form errors above." vs "Start date must be less than end date.")
7
+ */
8
+ declare const useFormHasOrphanAndNoFieldErrors: (formRef: React.RefObject<HTMLFormElement>) => boolean;
9
+ export default useFormHasOrphanAndNoFieldErrors;
@@ -0,0 +1,4 @@
1
+ import { default as React } from 'react';
2
+
3
+ declare const useOrphanFormErrorsMemo: (formRef: React.RefObject<HTMLFormElement>) => import('../flat/types').FlatFieldErrors;
4
+ export default useOrphanFormErrorsMemo;
@@ -0,0 +1,9 @@
1
+ import { default as React } from 'react';
2
+
3
+ /**
4
+ * Logs out orphan errors to console.error.
5
+ *
6
+ * In development, it will also throw an error to bring attention to dev.
7
+ */
8
+ declare const useOrphanFormErrorsToConsole: (formRef: React.RefObject<HTMLFormElement>, enabled?: boolean) => void;
9
+ export default useOrphanFormErrorsToConsole;
@@ -0,0 +1,13 @@
1
+ import { FieldErrors, FieldValues } from 'react-hook-form';
2
+
3
+ /**
4
+ * Output form values and errors to console and throw in dev.
5
+ */
6
+ declare const outputErrors: (message: string, form: {
7
+ values: FieldValues;
8
+ errors: FieldErrors;
9
+ }, options?: {
10
+ other?: Record<string, unknown>;
11
+ isError?: boolean;
12
+ }) => void;
13
+ export default outputErrors;
@@ -0,0 +1,7 @@
1
+ import { FlatFieldErrors } from '../flat/types';
2
+
3
+ type Props = React.DetailedHTMLProps<React.HTMLAttributes<HTMLUListElement>, HTMLUListElement> & {
4
+ errors: FlatFieldErrors;
5
+ };
6
+ declare const FormRootErrors: React.FC<Props>;
7
+ export default FormRootErrors;
@@ -0,0 +1,3 @@
1
+ /// <reference types="react" />
2
+ declare const FormRootErrorsFromContext: React.FC;
3
+ export default FormRootErrorsFromContext;
@@ -0,0 +1 @@
1
+ export declare const FormErrorPathRoot = "root";
@@ -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;