@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.
- package/dist/esm/devtool/LazyDevTool.mjs +7 -11
- package/dist/esm/env-conditions/production.mjs +4 -0
- package/dist/esm/errors/orphan/useOrphanFormErrorsToConsole.mjs +8 -9
- package/dist/esm/errors/outputErrors.mjs +5 -6
- package/dist/esm/form/Form.mjs +32 -40
- package/dist/esm/form/context/FormProvider.mjs +17 -19
- package/dist/esm/form/context/utils/FormUtilsContextProvider.mjs +10 -10
- package/dist/esm/form/useForm.mjs +14 -16
- package/dist/esm/form/useFormWithProviders.mjs +15 -17
- package/dist/types/src/devtool/LazyDevTool.d.ts +9 -0
- package/dist/types/src/env-conditions/development.d.ts +7 -0
- package/dist/types/src/env-conditions/production.d.ts +1 -0
- package/dist/types/src/errors/consoleErrors.d.ts +13 -0
- package/dist/types/src/errors/context/index.d.ts +10 -0
- package/dist/types/src/errors/context/provider.d.ts +11 -0
- package/dist/types/src/errors/flat/flattenFieldErrors.d.ts +15 -0
- package/dist/types/src/errors/flat/getFlatFieldErrors.d.ts +25 -0
- package/dist/types/src/errors/flat/types.d.ts +13 -0
- package/dist/types/src/errors/flat/useFormFlatFieldErrorsMemo.d.ts +5 -0
- package/dist/types/src/errors/flat/useRefdFieldErrorsMemo.d.ts +9 -0
- package/dist/types/src/errors/isFieldError.d.ts +7 -0
- package/dist/types/src/errors/message/FormErrorMessage.d.ts +8 -0
- package/dist/types/src/errors/message/FormErrorMessageByPath.d.ts +9 -0
- package/dist/types/src/errors/nonfield/FormNonFieldErrorMarker.d.ts +10 -0
- package/dist/types/src/errors/nonfield/FormNonFieldErrorMarker.spec.d.ts +1 -0
- package/dist/types/src/errors/nonfield/FormNonFieldErrorMarker.utils.d.ts +2 -0
- package/dist/types/src/errors/nonfield/FormNonFieldErrorMarkerHtmlAttribute.d.ts +5 -0
- package/dist/types/src/errors/nonfield/isNonFieldError.d.ts +19 -0
- package/dist/types/src/errors/orphan/getOrphansFromFieldErrors.d.ts +5 -0
- package/dist/types/src/errors/orphan/getOrphansFromFlatFieldErrors.d.ts +4 -0
- package/dist/types/src/errors/orphan/useFormHasOrphanAndNoFieldErrors.d.ts +9 -0
- package/dist/types/src/errors/orphan/useOrphanFormErrorsMemo.d.ts +4 -0
- package/dist/types/src/errors/orphan/useOrphanFormErrorsToConsole.d.ts +9 -0
- package/dist/types/src/errors/outputErrors.d.ts +13 -0
- package/dist/types/src/errors/root/FormRootErrors.d.ts +7 -0
- package/dist/types/src/errors/root/FormRootErrorsFromContext.d.ts +3 -0
- package/dist/types/src/errors/root/consts.d.ts +1 -0
- package/dist/types/src/errors/root/getRootsFromFieldErrors.d.ts +5 -0
- package/dist/types/src/errors/root/getRootsFromFlatFieldErrors.d.ts +4 -0
- package/dist/types/src/errors/root/isFormErrorPathRoot.d.ts +6 -0
- package/dist/types/src/errors/root/useRootFormFieldErrorsMemo.d.ts +6 -0
- package/dist/types/src/errors/useFormErrorConsoleDebug.d.ts +8 -0
- package/dist/types/src/errors/useFormErrorsEffect.d.ts +4 -0
- package/dist/types/src/errors/useFormErrorsIfAny.d.ts +6 -0
- package/dist/types/src/errors/useFormErrorsMemo.d.ts +7 -0
- package/dist/types/src/errors/useFormErrorsToConsole.d.ts +13 -0
- package/dist/types/src/errors/useFormRequestSubmit.d.ts +6 -0
- package/dist/types/src/exports.d.ts +37 -0
- package/dist/types/src/form/ErrorBoundary.d.ts +15 -0
- package/dist/types/src/form/Form.d.ts +29 -0
- package/dist/types/src/form/FormBase.d.ts +9 -0
- package/dist/types/src/form/FormWithProviders.d.ts +13 -0
- package/dist/types/src/form/context/FormProvider.d.ts +15 -0
- package/dist/types/src/form/context/group/FormGroupContextProvider.d.ts +5 -0
- package/dist/types/src/form/context/group/index.d.ts +15 -0
- package/dist/types/src/form/context/group/useFormGroupChildIsMountedTracker.d.ts +2 -0
- package/dist/types/src/form/context/group/useFormGroupChildIsSubmittingTracker.d.ts +2 -0
- package/dist/types/src/form/context/group/useFormGroupIsAnyBusy.d.ts +2 -0
- package/dist/types/src/form/context/group/useFormGroupIsChildBusy.d.ts +2 -0
- package/dist/types/src/form/context/group/useFormGroupIsParentBusy.d.ts +2 -0
- package/dist/types/src/form/context/group/useFormGroupParentTracker.d.ts +7 -0
- package/dist/types/src/form/context/utils/FormUtilsContextProvider.d.ts +14 -0
- package/dist/types/src/form/context/utils/useFormUtilsContext.d.ts +9 -0
- package/dist/types/src/form/search/FormSearch.d.ts +32 -0
- package/dist/types/src/form/search/FormSearchHiddenInputs.d.ts +13 -0
- package/dist/types/src/form/search/getNewSearchParams.d.ts +2 -0
- package/dist/types/src/form/useForm.d.ts +29 -0
- package/dist/types/src/form/useFormIsBusy.d.ts +2 -0
- package/dist/types/src/form/useFormOrParentIsBusy.d.ts +2 -0
- package/dist/types/src/form/useFormWithProviders.d.ts +31 -0
- package/dist/types/src/form/utils/getSubmitterButtonData.d.ts +11 -0
- package/dist/types/src/isEmptyObject.d.ts +2 -0
- package/dist/types/src/main.d.ts +1 -0
- package/dist/types/src/submit/error/FormSubmitError.d.ts +6 -0
- package/dist/types/src/submit/error/handleFormSubmitError.d.ts +7 -0
- package/dist/types/src/submit/useFormOnSubmitSuccessful.d.ts +2 -0
- package/dist/types/src/submit/useFormOnSubmitSuccessfulAndReset.d.ts +13 -0
- package/dist/types/src/submit/useResetFormOnSubmitError.d.ts +7 -0
- package/dist/types/src/submit/useResetFormOnSubmitSuccessful.d.ts +12 -0
- package/dist/types/src/submit/useSubmitFormOnChange.d.ts +4 -0
- package/dist/types/src/utils/createContext.d.ts +8 -0
- package/dist/types/src/utils/fixedForwardRef.d.ts +7 -0
- package/dist/types/src/utils/useImperativeForwardedRef.d.ts +11 -0
- package/dist/types/src/utils/useThrowAsyncError.d.ts +5 -0
- package/dist/types/src/utils/useToggle.d.ts +4 -0
- package/package.json +9 -3
|
@@ -1,16 +1,12 @@
|
|
|
1
|
-
import
|
|
2
|
-
import
|
|
3
|
-
import
|
|
4
|
-
|
|
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
|
-
)
|
|
9
|
-
|
|
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
|
-
|
|
11
|
+
p as default
|
|
16
12
|
};
|
|
@@ -1,18 +1,17 @@
|
|
|
1
1
|
import "react";
|
|
2
|
-
import
|
|
3
|
-
import
|
|
4
|
-
const
|
|
5
|
-
const o =
|
|
6
|
-
|
|
7
|
-
disabled: !
|
|
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
|
-
},
|
|
14
|
+
}, i = t;
|
|
16
15
|
export {
|
|
17
|
-
|
|
16
|
+
i as default
|
|
18
17
|
};
|
|
@@ -1,8 +1,7 @@
|
|
|
1
|
-
import
|
|
2
|
-
const
|
|
3
|
-
|
|
4
|
-
|
|
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
|
-
|
|
6
|
+
c as default
|
|
8
7
|
};
|
package/dist/esm/form/Form.mjs
CHANGED
|
@@ -1,71 +1,63 @@
|
|
|
1
|
-
import { jsxs as
|
|
1
|
+
import { jsxs as C, jsx as t } from "react/jsx-runtime";
|
|
2
2
|
import "react";
|
|
3
|
-
import { useFormContext as
|
|
4
|
-
import
|
|
5
|
-
import
|
|
6
|
-
import
|
|
7
|
-
import
|
|
8
|
-
import
|
|
9
|
-
import
|
|
10
|
-
import
|
|
11
|
-
function
|
|
12
|
-
|
|
13
|
-
|
|
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:
|
|
18
|
+
onSubmitInvalid: F,
|
|
20
19
|
//
|
|
21
20
|
options: r,
|
|
22
21
|
//
|
|
23
|
-
children:
|
|
24
|
-
...
|
|
22
|
+
children: x,
|
|
23
|
+
...g
|
|
25
24
|
}) {
|
|
26
|
-
const m =
|
|
27
|
-
|
|
28
|
-
const
|
|
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(
|
|
30
|
+
await m.handleSubmit(b, F)(e);
|
|
32
31
|
} catch (a) {
|
|
33
|
-
|
|
32
|
+
y(a, e);
|
|
34
33
|
}
|
|
35
|
-
},
|
|
34
|
+
}, b = (e, a) => d == null ? void 0 : d(
|
|
36
35
|
e,
|
|
37
36
|
m,
|
|
38
37
|
a
|
|
39
|
-
),
|
|
40
|
-
|
|
38
|
+
), y = (e, a) => {
|
|
39
|
+
V(e, m), l == null || l(e, m, a);
|
|
41
40
|
};
|
|
42
|
-
return /* @__PURE__ */
|
|
43
|
-
|
|
41
|
+
return /* @__PURE__ */ C(
|
|
42
|
+
P,
|
|
44
43
|
{
|
|
45
|
-
id:
|
|
46
|
-
onSubmit:
|
|
44
|
+
id: u,
|
|
45
|
+
onSubmit: R,
|
|
47
46
|
noValidate: !0,
|
|
48
47
|
style: {
|
|
49
48
|
position: "relative"
|
|
50
49
|
},
|
|
51
|
-
...
|
|
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
|
-
|
|
64
|
-
!(r != null && r.hideRootErrors) && /* @__PURE__ */ t(
|
|
55
|
+
x,
|
|
56
|
+
!(r != null && r.hideRootErrors) && /* @__PURE__ */ t(T, {})
|
|
65
57
|
]
|
|
66
58
|
}
|
|
67
59
|
);
|
|
68
60
|
}
|
|
69
61
|
export {
|
|
70
|
-
|
|
62
|
+
G as default
|
|
71
63
|
};
|
|
@@ -1,27 +1,25 @@
|
|
|
1
1
|
import { jsx as r } from "react/jsx-runtime";
|
|
2
|
-
import { FormProvider as
|
|
3
|
-
import
|
|
4
|
-
function
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
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(
|
|
14
|
-
|
|
12
|
+
return /* @__PURE__ */ r(f, { ...i, children: /* @__PURE__ */ r(
|
|
13
|
+
n,
|
|
15
14
|
{
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
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
|
-
|
|
24
|
+
v as default
|
|
27
25
|
};
|
|
@@ -1,20 +1,20 @@
|
|
|
1
|
-
import { jsx as
|
|
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
|
|
4
|
-
import
|
|
5
|
-
import
|
|
6
|
-
import
|
|
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:
|
|
12
|
+
children: m
|
|
13
13
|
}) {
|
|
14
|
-
const
|
|
15
|
-
return
|
|
14
|
+
const t = F(o);
|
|
15
|
+
return s(i), p(o, !0), a({ enabled: !!r }), u(() => {
|
|
16
16
|
r == null || r();
|
|
17
|
-
}), /* @__PURE__ */
|
|
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
|
|
2
|
-
import
|
|
3
|
-
import { useForm as
|
|
4
|
-
import
|
|
5
|
-
import
|
|
6
|
-
const
|
|
7
|
-
|
|
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 =
|
|
10
|
+
const r = i.useId(), m = u(e), t = F();
|
|
12
11
|
return {
|
|
13
12
|
id: r,
|
|
14
13
|
ref: t,
|
|
15
|
-
context:
|
|
16
|
-
Form: ({ children:
|
|
17
|
-
|
|
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:
|
|
22
|
+
children: s
|
|
25
23
|
}
|
|
26
24
|
)
|
|
27
25
|
};
|
|
28
|
-
},
|
|
26
|
+
}, b = f;
|
|
29
27
|
export {
|
|
30
|
-
|
|
28
|
+
b as default
|
|
31
29
|
};
|
|
@@ -1,30 +1,28 @@
|
|
|
1
|
-
import { jsx as
|
|
1
|
+
import { jsx as i } from "react/jsx-runtime";
|
|
2
2
|
import "react";
|
|
3
|
-
import
|
|
4
|
-
import
|
|
5
|
-
const
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
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 =
|
|
10
|
+
const r = f({ rhf: t, form: o });
|
|
12
11
|
return {
|
|
13
12
|
...r,
|
|
14
|
-
Provider: ({ children:
|
|
15
|
-
|
|
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:
|
|
22
|
-
utils:
|
|
23
|
-
children:
|
|
19
|
+
form: o,
|
|
20
|
+
utils: e,
|
|
21
|
+
children: m
|
|
24
22
|
}
|
|
25
23
|
)
|
|
26
24
|
};
|
|
27
|
-
},
|
|
25
|
+
}, P = d;
|
|
28
26
|
export {
|
|
29
|
-
|
|
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,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,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 @@
|
|
|
1
|
+
export {};
|
|
@@ -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,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,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 @@
|
|
|
1
|
+
export declare const FormErrorPathRoot = "root";
|