@paragrav/rhf-utils 0.0.37 → 0.0.38
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/errors/root/FormRootErrors.mjs +14 -0
- package/dist/esm/form/Form.mjs +82 -0
- package/dist/esm/form/FormBase.mjs +10 -0
- package/dist/esm/form/FormError.mjs +8 -0
- package/dist/esm/form/context/group/useFormGroupChildIsMountedTracker.mjs +9 -11
- package/dist/esm/form/context/group/useFormGroupChildIsSubmittingTracker.mjs +12 -10
- package/dist/esm/form/useForm.mjs +31 -0
- package/dist/esm/form/useFormIsBusy.mjs +5 -5
- package/dist/esm/main.mjs +10 -8
- package/dist/esm/utils/fixedForwardRef.mjs +7 -0
- package/dist/esm/utils/useImperativeForwardedRef.mjs +16 -0
- package/dist/types/form/Form.d.ts +6 -5
- package/dist/types/form/FormWithProvider.d.ts +1 -1
- package/dist/types/form/context/FormProvider.d.ts +5 -2
- package/dist/types/form/context/group/index.d.ts +2 -0
- package/dist/types/form/context/utils/FormUtilsContextProvider.d.ts +5 -2
- package/dist/types/form/toggle/ToggleForm.d.ts +18 -0
- package/dist/types/form/useForm.d.ts +9 -10
- package/dist/types/form/useFormWithProvider.d.ts +30 -0
- package/dist/types/main.d.ts +1 -0
- package/dist/types/utils/useImperativeForwardedRef.d.ts +1 -1
- package/package.json +5 -1
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { jsx as e } from "react/jsx-runtime";
|
|
2
|
+
import l from "../../isEmptyObject.mjs";
|
|
3
|
+
const s = ({ errors: r, ...i }) => l(r) ? null : /* @__PURE__ */ e("ul", { ...i, children: Object.values(r).map((t) => /* @__PURE__ */ e(
|
|
4
|
+
"li",
|
|
5
|
+
{
|
|
6
|
+
role: "alert",
|
|
7
|
+
"aria-live": "polite",
|
|
8
|
+
children: t.message
|
|
9
|
+
},
|
|
10
|
+
JSON.stringify(t)
|
|
11
|
+
)) });
|
|
12
|
+
export {
|
|
13
|
+
s as default
|
|
14
|
+
};
|
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
import { jsxs as v, jsx as d } from "react/jsx-runtime";
|
|
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,
|
|
14
|
+
//
|
|
15
|
+
onSubmit: a,
|
|
16
|
+
onSubmitError: m,
|
|
17
|
+
onSubmitInvalid: h,
|
|
18
|
+
//
|
|
19
|
+
options: r,
|
|
20
|
+
//
|
|
21
|
+
children: y,
|
|
22
|
+
...u
|
|
23
|
+
}) {
|
|
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) => {
|
|
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
|
+
);
|
|
52
|
+
}
|
|
53
|
+
};
|
|
54
|
+
return /* @__PURE__ */ v(
|
|
55
|
+
b,
|
|
56
|
+
{
|
|
57
|
+
id: F,
|
|
58
|
+
onSubmit: E,
|
|
59
|
+
noValidate: !0,
|
|
60
|
+
...u,
|
|
61
|
+
ref: x,
|
|
62
|
+
style: {
|
|
63
|
+
position: "relative"
|
|
64
|
+
},
|
|
65
|
+
children: [
|
|
66
|
+
(r == null ? void 0 : r.devTool) !== "disabled" && /* @__PURE__ */ d(
|
|
67
|
+
w,
|
|
68
|
+
{
|
|
69
|
+
isDev: s,
|
|
70
|
+
placement: "top-right",
|
|
71
|
+
...r == null ? void 0 : r.devTool
|
|
72
|
+
}
|
|
73
|
+
),
|
|
74
|
+
y,
|
|
75
|
+
f && /* @__PURE__ */ d(P, { errors: f })
|
|
76
|
+
]
|
|
77
|
+
}
|
|
78
|
+
);
|
|
79
|
+
}
|
|
80
|
+
export {
|
|
81
|
+
A as default
|
|
82
|
+
};
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { jsxs as m, jsx as s } from "react/jsx-runtime";
|
|
2
|
+
import "react";
|
|
3
|
+
import a from "../utils/fixedForwardRef.mjs";
|
|
4
|
+
const f = ({ antiCsrfToken: r, children: o, ...e }, t) => /* @__PURE__ */ m("form", { role: "form", ...e, ref: t, children: [
|
|
5
|
+
r && /* @__PURE__ */ s("input", { type: "hidden", name: "anticsrftoken", value: r }),
|
|
6
|
+
o
|
|
7
|
+
] }), p = a(f);
|
|
8
|
+
export {
|
|
9
|
+
p as default
|
|
10
|
+
};
|
|
@@ -1,16 +1,14 @@
|
|
|
1
|
-
import
|
|
2
|
-
import {
|
|
3
|
-
import { _useFormGroupContext as n } from "./index.mjs";
|
|
1
|
+
import o from "react";
|
|
2
|
+
import { _useFormGroupContext as u } from "./index.mjs";
|
|
4
3
|
const c = () => {
|
|
5
|
-
u();
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
r(t, s);
|
|
4
|
+
const { setBusyId: r } = u().children, s = o.useId();
|
|
5
|
+
o.useEffect(() => {
|
|
6
|
+
const e = (t) => {
|
|
7
|
+
r(s, t);
|
|
10
8
|
};
|
|
11
|
-
return
|
|
9
|
+
return e(!0), () => e(!1);
|
|
12
10
|
}, []);
|
|
13
|
-
},
|
|
11
|
+
}, m = c;
|
|
14
12
|
export {
|
|
15
|
-
|
|
13
|
+
m as default
|
|
16
14
|
};
|
|
@@ -1,12 +1,14 @@
|
|
|
1
|
-
import
|
|
2
|
-
import { useFormState as
|
|
3
|
-
import { _useFormGroupContext as
|
|
4
|
-
const
|
|
5
|
-
const { isSubmitting:
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
}, [
|
|
9
|
-
|
|
1
|
+
import e from "react";
|
|
2
|
+
import { useFormState as s } from "react-hook-form";
|
|
3
|
+
import { _useFormGroupContext as u } from "./index.mjs";
|
|
4
|
+
const i = () => {
|
|
5
|
+
const { isSubmitting: o } = s(), { setBusyId: t } = u().children, r = e.useId();
|
|
6
|
+
e.useEffect(() => {
|
|
7
|
+
t(r, o);
|
|
8
|
+
}, [o, r, t]), e.useEffect(() => () => {
|
|
9
|
+
t(r, !1);
|
|
10
|
+
}, []);
|
|
11
|
+
}, f = i;
|
|
10
12
|
export {
|
|
11
|
-
|
|
13
|
+
f as default
|
|
12
14
|
};
|
|
@@ -0,0 +1,31 @@
|
|
|
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,
|
|
9
|
+
form: o
|
|
10
|
+
}) => {
|
|
11
|
+
const r = u.useId(), s = F(m), t = c();
|
|
12
|
+
return {
|
|
13
|
+
id: r,
|
|
14
|
+
ref: t,
|
|
15
|
+
context: s,
|
|
16
|
+
Form: ({ children: n }) => /* @__PURE__ */ i(
|
|
17
|
+
f,
|
|
18
|
+
{
|
|
19
|
+
...o,
|
|
20
|
+
isDev: e,
|
|
21
|
+
formId: r,
|
|
22
|
+
formRef: t,
|
|
23
|
+
onSubmit: o == null ? void 0 : o.onSubmit,
|
|
24
|
+
children: n
|
|
25
|
+
}
|
|
26
|
+
)
|
|
27
|
+
};
|
|
28
|
+
}, S = p;
|
|
29
|
+
export {
|
|
30
|
+
S as default
|
|
31
|
+
};
|
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import { useFormState as
|
|
2
|
-
const
|
|
3
|
-
const { isSubmitting:
|
|
4
|
-
return
|
|
1
|
+
import { useFormState as o } from "react-hook-form";
|
|
2
|
+
const e = () => {
|
|
3
|
+
const { isSubmitting: t, isLoading: s } = o();
|
|
4
|
+
return t || s;
|
|
5
5
|
};
|
|
6
6
|
export {
|
|
7
|
-
|
|
7
|
+
e as default
|
|
8
8
|
};
|
package/dist/esm/main.mjs
CHANGED
|
@@ -21,10 +21,11 @@ import { default as L } from "./form/context/group/useFormGroupIsAnyBusy.mjs";
|
|
|
21
21
|
import { default as w } from "./form/context/group/useFormGroupIsChildBusy.mjs";
|
|
22
22
|
import { default as K } from "./form/context/group/useFormGroupIsParentBusy.mjs";
|
|
23
23
|
import { default as U } from "./form/context/group/useFormGroupParentTracker.mjs";
|
|
24
|
-
import { default as W } from "./form/
|
|
25
|
-
import { default as Y } from "./
|
|
26
|
-
import { default as _ } from "./submit/
|
|
27
|
-
import { default as rr } from "./submit/
|
|
24
|
+
import { default as W } from "./form/useForm.mjs";
|
|
25
|
+
import { default as Y } from "./form/utils/getSubmitterButtonData.mjs";
|
|
26
|
+
import { default as _ } from "./submit/useFormOnSubmitSuccessful.mjs";
|
|
27
|
+
import { default as rr } from "./submit/useFormOnSubmitSuccessfulAndReset.mjs";
|
|
28
|
+
import { default as er } from "./submit/useResetFormOnSubmitSuccessful.mjs";
|
|
28
29
|
export {
|
|
29
30
|
f as FormErrorMessage,
|
|
30
31
|
d as FormErrorMessageByPath,
|
|
@@ -33,7 +34,8 @@ export {
|
|
|
33
34
|
F as FormNonFieldErrorMarker,
|
|
34
35
|
n as FormNonFieldErrorMarkerHtmlAttribute,
|
|
35
36
|
e as LazyDevTool,
|
|
36
|
-
|
|
37
|
+
Y as getSubmitterButtonData,
|
|
38
|
+
W as useForm,
|
|
37
39
|
G as useFormErrorConsoleDebug,
|
|
38
40
|
I as useFormErrorsEffect,
|
|
39
41
|
s as useFormErrorsFlatContext,
|
|
@@ -46,11 +48,11 @@ export {
|
|
|
46
48
|
K as useFormGroupIsParentBusy,
|
|
47
49
|
U as useFormGroupParentTracker,
|
|
48
50
|
E as useFormHasOrphanAndNoFieldErrors,
|
|
49
|
-
|
|
50
|
-
|
|
51
|
+
_ as useFormOnSubmitSuccessful,
|
|
52
|
+
rr as useFormOnSubmitSuccessfulAndReset,
|
|
51
53
|
T as useFormRequestSubmit,
|
|
52
54
|
S as useOrphanFormErrorsMemo,
|
|
53
55
|
C as useOrphanFormErrorsToConsole,
|
|
54
|
-
|
|
56
|
+
er as useResetFormAfterSubmitSuccessful,
|
|
55
57
|
h as useRootFormFieldErrorsMemo
|
|
56
58
|
};
|
|
@@ -3,10 +3,11 @@ import { FieldValues, SubmitErrorHandler, UseFormReturn } from 'react-hook-form'
|
|
|
3
3
|
import { default as React } from 'react';
|
|
4
4
|
import { DevtoolUIProps } from '@hookform/devtools/dist/devToolUI';
|
|
5
5
|
|
|
6
|
-
export type FormProps<TFieldValues extends FieldValues, TTransformedValues extends FieldValues> =
|
|
6
|
+
export type FormProps<TFieldValues extends FieldValues, TTransformedValues extends FieldValues> = React.PropsWithChildren<Pick<FormBaseProps, 'onChange'> & {
|
|
7
7
|
isDev: boolean;
|
|
8
|
-
|
|
9
|
-
|
|
8
|
+
formId?: string;
|
|
9
|
+
formRef?: React.RefObject<HTMLFormElement>;
|
|
10
|
+
onSubmit?: (values: TTransformedValues, context: UseFormReturn<TFieldValues, unknown, TTransformedValues>, event: React.BaseSyntheticEvent<SubmitEvent>) => unknown | Promise<unknown>;
|
|
10
11
|
/** Submit error handler. (Only for errors not of instance `FormError`, which are handled internally.) */
|
|
11
12
|
onSubmitError?: (error: unknown, values: TTransformedValues, context: UseFormReturn<TFieldValues, unknown, TTransformedValues>, event: React.BaseSyntheticEvent<SubmitEvent>) => void;
|
|
12
13
|
/** Submit handler when form is invalid. */
|
|
@@ -17,6 +18,6 @@ export type FormProps<TFieldValues extends FieldValues, TTransformedValues exten
|
|
|
17
18
|
devTool?: DevtoolUIProps | 'disabled';
|
|
18
19
|
};
|
|
19
20
|
className?: string;
|
|
20
|
-
}
|
|
21
|
-
declare function Form<TFieldValues extends FieldValues, TTransformedValues extends FieldValues>({ isDev, formRef, onSubmit, onSubmitError, onSubmitInvalid, options, children, ...props }: FormProps<TFieldValues, TTransformedValues>): import("react/jsx-runtime").JSX.Element;
|
|
21
|
+
}>;
|
|
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;
|
|
22
23
|
export default Form;
|
|
@@ -9,5 +9,5 @@ export type FormWithProvider<TFieldValues extends FieldValues, TTransformedValue
|
|
|
9
9
|
* Use {@link useForm} if you need to specific nesting hierarchy.
|
|
10
10
|
* (e.g., wrapping `<tr>` with provider and nesting `<form>` within `<td>` to appease HTML rules.)
|
|
11
11
|
*/
|
|
12
|
-
declare function FormWithProvider<TFieldValues extends FieldValues, TTransformedValues extends FieldValues>({
|
|
12
|
+
declare function FormWithProvider<TFieldValues extends FieldValues, TTransformedValues extends FieldValues>({ children, ...props }: FormWithProvider<TFieldValues, TTransformedValues>): import("react/jsx-runtime").JSX.Element;
|
|
13
13
|
export default FormWithProvider;
|
|
@@ -4,10 +4,13 @@ import { FieldValues, UseFormReturn } from 'react-hook-form';
|
|
|
4
4
|
|
|
5
5
|
type Props<TFieldValues extends FieldValues, // input values
|
|
6
6
|
TTransformedValues extends FieldValues> = React.PropsWithChildren<{
|
|
7
|
+
isDev: boolean;
|
|
8
|
+
formId: string;
|
|
9
|
+
formRef: React.RefObject<HTMLFormElement>;
|
|
7
10
|
rhf: UseFormReturn<TFieldValues, unknown, TTransformedValues>;
|
|
8
11
|
} & {
|
|
9
|
-
form
|
|
12
|
+
form?: Omit<FormProps<TFieldValues, TTransformedValues>, 'isDev' | 'formRef' | 'formId'>;
|
|
10
13
|
utils?: FormUtilsContextProviderProps;
|
|
11
14
|
}>;
|
|
12
|
-
declare function FormProvider<TFieldValues extends FieldValues, TTransformedValues extends FieldValues>({ rhf, form, utils, children }: Props<TFieldValues, TTransformedValues>): import("react/jsx-runtime").JSX.Element;
|
|
15
|
+
declare function FormProvider<TFieldValues extends FieldValues, TTransformedValues extends FieldValues>({ isDev, formId, formRef, rhf, form, utils, children, }: Props<TFieldValues, TTransformedValues>): import("react/jsx-runtime").JSX.Element;
|
|
13
16
|
export default FormProvider;
|
|
@@ -1,10 +1,12 @@
|
|
|
1
1
|
/// <reference types="react" />
|
|
2
2
|
export type FormGroupContext = {
|
|
3
|
+
/** Dependent forms. */
|
|
3
4
|
children: {
|
|
4
5
|
busyIds: string[];
|
|
5
6
|
busyCount: number;
|
|
6
7
|
setBusyId: (id: string, isBusy: boolean) => void;
|
|
7
8
|
};
|
|
9
|
+
/** Main form. */
|
|
8
10
|
parent: {
|
|
9
11
|
isBusy: boolean;
|
|
10
12
|
setIsBusy: (isBusy: boolean) => void;
|
|
@@ -6,7 +6,10 @@ export type FormUtilsContextProviderProps = {
|
|
|
6
6
|
onSubmitSuccessfulAndReset?: () => void;
|
|
7
7
|
};
|
|
8
8
|
type Props<TFieldValues extends FieldValues, TTransformedValues extends FieldValues> = React.PropsWithChildren<{
|
|
9
|
-
|
|
9
|
+
isDev: boolean;
|
|
10
|
+
formId: string;
|
|
11
|
+
formRef: React.RefObject<HTMLFormElement>;
|
|
12
|
+
formProps?: Omit<FormProps<TFieldValues, TTransformedValues>, 'isDev' | 'formRef' | 'formId'>;
|
|
10
13
|
} & FormUtilsContextProviderProps>;
|
|
11
|
-
declare function FormUtilsContextProvider<TFieldValues extends FieldValues, TTransformedValues extends FieldValues>({
|
|
14
|
+
declare function FormUtilsContextProvider<TFieldValues extends FieldValues, TTransformedValues extends FieldValues>({ isDev, formRef, onSubmitSuccessfulAndReset, children, }: Props<TFieldValues, TTransformedValues>): import("react/jsx-runtime").JSX.Element;
|
|
12
15
|
export default FormUtilsContextProvider;
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { UseFormWithProviderProps } from '../useFormWithProvider';
|
|
2
|
+
import { FieldValues, UseFormReturn } from 'react-hook-form';
|
|
3
|
+
import { default as React } from 'react';
|
|
4
|
+
|
|
5
|
+
type Props<TFieldValues extends FieldValues, TTransformedValues extends FieldValues> = React.PropsWithChildren<UseFormWithProviderProps<TFieldValues, TTransformedValues> & {
|
|
6
|
+
Fields: React.FC<{
|
|
7
|
+
ctx: UseFormReturn<TFieldValues, unknown, TTransformedValues>;
|
|
8
|
+
}>;
|
|
9
|
+
}>;
|
|
10
|
+
/**
|
|
11
|
+
* This form submits upon selecting a new value, and reverts (via re-render) if there is an error.
|
|
12
|
+
*
|
|
13
|
+
* The entire form is disabled while submitting.
|
|
14
|
+
*
|
|
15
|
+
* Probably not ideal to use with text inputs. Would need to implement debounce or submit on blur.
|
|
16
|
+
*/
|
|
17
|
+
declare function ToggleForm<TFieldValues extends FieldValues, TTransformedValues extends FieldValues>({ isDev, rhf, form, utils, Fields, children, }: Props<TFieldValues, TTransformedValues>): import("react/jsx-runtime").JSX.Element;
|
|
18
|
+
export default ToggleForm;
|
|
@@ -1,15 +1,13 @@
|
|
|
1
1
|
import { FormProps } from './Form';
|
|
2
|
-
import { FormUtilsContextProviderProps } from './context/utils/FormUtilsContextProvider';
|
|
3
2
|
import { FieldValues, UseFormProps as RhfUseFormProps } from 'react-hook-form';
|
|
4
3
|
import { default as React } from 'react';
|
|
5
4
|
|
|
6
5
|
export type UseFormProps<TFieldValues extends FieldValues, TTransformedValues extends FieldValues> = {
|
|
6
|
+
isDev: boolean;
|
|
7
7
|
/** {@link RhfUseFormProps} props for RHF's {@link useRhfForm}. */
|
|
8
|
-
rhf
|
|
8
|
+
rhf?: RhfUseFormProps<TFieldValues>;
|
|
9
9
|
/** {@link FormProps} props for Form. */
|
|
10
|
-
form
|
|
11
|
-
/** {@link FormUtilsContextProviderProps} props for `FormUtilsContextProvider`. */
|
|
12
|
-
utils?: FormUtilsContextProviderProps;
|
|
10
|
+
form?: Omit<FormProps<TFieldValues, TTransformedValues>, 'isDev' | 'formId' | 'formRef'>;
|
|
13
11
|
};
|
|
14
12
|
export type UseFormReturn = ReturnType<typeof useForm>;
|
|
15
13
|
/**
|
|
@@ -21,11 +19,12 @@ export type UseFormReturn = ReturnType<typeof useForm>;
|
|
|
21
19
|
* see https://caniuse.com/?search=form%20attribute
|
|
22
20
|
* @returns Form provider and form.
|
|
23
21
|
*/
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
Form: React.FC<{
|
|
22
|
+
declare const useForm: <TFieldValues extends FieldValues, TTransformedValues extends FieldValues>({ isDev, rhf, form, }: UseFormProps<TFieldValues, TTransformedValues>) => {
|
|
23
|
+
readonly id: string;
|
|
24
|
+
readonly ref: React.RefObject<HTMLFormElement>;
|
|
25
|
+
readonly context: import('react-hook-form').UseFormReturn<TFieldValues, unknown, TTransformedValues>;
|
|
26
|
+
readonly Form: React.FC<{
|
|
29
27
|
children?: React.ReactNode;
|
|
30
28
|
}>;
|
|
31
29
|
};
|
|
30
|
+
export default useForm;
|
|
@@ -0,0 +1,30 @@
|
|
|
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 UseFormWithProviderProps<TFieldValues extends FieldValues, TTransformedValues extends FieldValues> = UseFormProps<TFieldValues, TTransformedValues> & {
|
|
7
|
+
/** {@link FormUtilsContextProviderProps} props for `FormUtilsContextProvider`. */
|
|
8
|
+
utils?: FormUtilsContextProviderProps;
|
|
9
|
+
};
|
|
10
|
+
export type UseFormWithProviderReturn = ReturnType<typeof useFormWithProvider>;
|
|
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
|
+
export declare const useFormWithProvider: <TFieldValues extends FieldValues, TTransformedValues extends FieldValues>({ isDev, rhf, form, utils, }: UseFormWithProviderProps<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
|
+
};
|
package/dist/types/main.d.ts
CHANGED
|
@@ -21,6 +21,7 @@ export { default as useFormGroupIsAnyBusy } from './form/context/group/useFormGr
|
|
|
21
21
|
export { default as useFormGroupIsChildBusy } from './form/context/group/useFormGroupIsChildBusy';
|
|
22
22
|
export { default as useFormGroupIsParentBusy } from './form/context/group/useFormGroupIsParentBusy';
|
|
23
23
|
export { default as useFormGroupParentTracker } from './form/context/group/useFormGroupParentTracker';
|
|
24
|
+
export { default as useForm } from './form/useForm';
|
|
24
25
|
export { default as getSubmitterButtonData } from './form/utils/getSubmitterButtonData';
|
|
25
26
|
export { default as useFormOnSubmitSuccessful } from './submit/useFormOnSubmitSuccessful';
|
|
26
27
|
export { default as useFormOnSubmitSuccessfulAndReset } from './submit/useFormOnSubmitSuccessfulAndReset';
|
|
@@ -7,5 +7,5 @@ import { default as React } from 'react';
|
|
|
7
7
|
*
|
|
8
8
|
* @param forwardedRef Forwarded `ref` prop.
|
|
9
9
|
*/
|
|
10
|
-
declare const useImperativeForwardedRef: <TRef>(forwardedRef
|
|
10
|
+
declare const useImperativeForwardedRef: <TRef>(forwardedRef?: React.ForwardedRef<TRef>) => React.RefObject<TRef>;
|
|
11
11
|
export default useImperativeForwardedRef;
|
package/package.json
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
"name": "@paragrav/rhf-utils",
|
|
3
3
|
"author": "paragrav.dev",
|
|
4
4
|
"license": "MIT",
|
|
5
|
-
"version": "0.0.
|
|
5
|
+
"version": "0.0.38",
|
|
6
6
|
"description": "Integration utilities for react-hook-form.",
|
|
7
7
|
"type": "module",
|
|
8
8
|
"sideEffects": false,
|
|
@@ -71,6 +71,10 @@
|
|
|
71
71
|
"default": "./dist/esm/errors/root/useRootFormFieldErrors.mjs",
|
|
72
72
|
"types": "./dist/types/errors/root/useRootFormFieldErrors.d.ts"
|
|
73
73
|
},
|
|
74
|
+
"./form/useForm": {
|
|
75
|
+
"default": "./dist/esm/form/useForm.mjs",
|
|
76
|
+
"types": "./dist/types/form/useForm.d.ts"
|
|
77
|
+
},
|
|
74
78
|
"./form/context/group/FormGroupContextProvider": {
|
|
75
79
|
"default": "./dist/esm/form/context/group/FormGroupContextProvider.mjs",
|
|
76
80
|
"types": "./dist/types/form/context/group/FormGroupContextProvider.d.ts"
|