@paragrav/rhf-utils 0.0.37 → 0.0.45

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.
@@ -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
+ };
@@ -0,0 +1,8 @@
1
+ class e extends Error {
2
+ constructor(r, o) {
3
+ super(o), this.errors = r;
4
+ }
5
+ }
6
+ export {
7
+ e as FormError
8
+ };
@@ -0,0 +1,9 @@
1
+ import { jsx as o } from "react/jsx-runtime";
2
+ import e from "./useFormWithProvider.mjs";
3
+ function f({ children: i, ...t }) {
4
+ const r = e(t);
5
+ return /* @__PURE__ */ o(r.Provider, { children: /* @__PURE__ */ o(r.Form, { children: i }) });
6
+ }
7
+ export {
8
+ f as default
9
+ };
@@ -0,0 +1,27 @@
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
12
+ }) {
13
+ return /* @__PURE__ */ r(n, { ...t, children: /* @__PURE__ */ r(
14
+ p,
15
+ {
16
+ isDev: o,
17
+ formId: m,
18
+ formRef: i,
19
+ formProps: e,
20
+ ...d,
21
+ children: f
22
+ }
23
+ ) });
24
+ }
25
+ export {
26
+ F as default
27
+ };
@@ -1,16 +1,14 @@
1
- import e from "react";
2
- import { useFormContext as u } from "react-hook-form";
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
- const { setBusyId: r } = n().children, t = e.useId();
7
- e.useEffect(() => {
8
- const o = (s) => {
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 o(!0), () => o(!1);
9
+ return e(!0), () => e(!1);
12
10
  }, []);
13
- }, i = c;
11
+ }, m = c;
14
12
  export {
15
- i as default
13
+ m as default
16
14
  };
@@ -1,12 +1,14 @@
1
- import s from "react";
2
- import { useFormState as e } from "react-hook-form";
3
- import { _useFormGroupContext as i } from "./index.mjs";
4
- const u = () => {
5
- const { isSubmitting: t } = e(), { setBusyId: o } = i().children, r = s.useId();
6
- s.useEffect(() => {
7
- o(r, t);
8
- }, [t, r, o]);
9
- }, d = u;
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
- d as default
13
+ f as default
12
14
  };
@@ -0,0 +1,21 @@
1
+ import { jsx as i } from "react/jsx-runtime";
2
+ 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";
7
+ import { _FormUtilsContextProvider as l } from "./useFormUtilsContext.mjs";
8
+ function O({
9
+ isDev: m,
10
+ formRef: o,
11
+ onSubmitSuccessfulAndReset: r,
12
+ children: t
13
+ }) {
14
+ const e = u(o);
15
+ return F(m), p(o, m, !0), s({ enabled: !!r }), a(() => {
16
+ r == null || r();
17
+ }), /* @__PURE__ */ i(l, { value: { formRef: o, requestSubmit: e }, children: t });
18
+ }
19
+ export {
20
+ O as default
21
+ };
@@ -0,0 +1,6 @@
1
+ import t from "../../../utils/createContext.mjs";
2
+ const [, o, r] = t(), s = o;
3
+ export {
4
+ r as _FormUtilsContextProvider,
5
+ s as default
6
+ };
@@ -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 s } from "react-hook-form";
2
- const r = () => {
3
- const { isSubmitting: o, isLoading: t } = s();
4
- return !!(o || t);
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
- r as default
7
+ e as default
8
8
  };
@@ -0,0 +1,30 @@
1
+ import { jsx as f } from "react/jsx-runtime";
2
+ import "react";
3
+ import d from "./context/FormProvider.mjs";
4
+ import s from "./useForm.mjs";
5
+ const n = ({
6
+ isDev: o,
7
+ rhf: e,
8
+ form: t,
9
+ utils: m
10
+ }) => {
11
+ const r = s({ isDev: o, rhf: e, form: t });
12
+ return {
13
+ ...r,
14
+ Provider: ({ children: i }) => /* @__PURE__ */ f(
15
+ d,
16
+ {
17
+ isDev: o,
18
+ formRef: r.ref,
19
+ rhf: r.context,
20
+ formId: r.id,
21
+ form: t,
22
+ utils: m,
23
+ children: i
24
+ }
25
+ )
26
+ };
27
+ }, F = n;
28
+ export {
29
+ F as default
30
+ };
package/dist/esm/main.mjs CHANGED
@@ -3,54 +3,70 @@ import { default as s } from "./errors/context/index.mjs";
3
3
  import { default as u } from "./errors/context/provider.mjs";
4
4
  import { default as f } from "./errors/message/FormErrorMessage.mjs";
5
5
  import { default as d } from "./errors/message/FormErrorMessageByPath.mjs";
6
- import { default as F } from "./errors/nonfield/FormNonFieldErrorMarker.mjs";
7
- import { default as n } from "./errors/nonfield/FormNonFieldErrorMarkerHtmlAttribute.mjs";
6
+ import { default as x } from "./errors/nonfield/FormNonFieldErrorMarker.mjs";
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 S } from "./errors/orphan/useOrphanFormErrorsMemo.mjs";
10
- import { default as C } from "./errors/orphan/useOrphanFormErrorsToConsole.mjs";
11
- import { default as h } from "./errors/root/useRootFormFieldErrorsMemo.mjs";
12
- import { default as G } from "./errors/useFormErrorConsoleDebug.mjs";
13
- import { default as I } from "./errors/useFormErrorsEffect.mjs";
14
- import { default as k } from "./errors/useFormErrorsIfAny.mjs";
15
- import { default as O } from "./errors/useFormErrorsMemo.mjs";
16
- import { default as T } from "./errors/useFormRequestSubmit.mjs";
17
- import { default as v } from "./form/context/group/FormGroupContextProvider.mjs";
18
- import { default as N } from "./form/context/group/useFormGroupChildIsMountedTracker.mjs";
19
- import { default as q } from "./form/context/group/useFormGroupChildIsSubmittingTracker.mjs";
20
- import { default as L } from "./form/context/group/useFormGroupIsAnyBusy.mjs";
21
- import { default as w } from "./form/context/group/useFormGroupIsChildBusy.mjs";
22
- import { default as K } from "./form/context/group/useFormGroupIsParentBusy.mjs";
23
- import { default as U } from "./form/context/group/useFormGroupParentTracker.mjs";
24
- import { default as W } from "./form/utils/getSubmitterButtonData.mjs";
25
- import { default as Y } from "./submit/useFormOnSubmitSuccessful.mjs";
26
- import { default as _ } from "./submit/useFormOnSubmitSuccessfulAndReset.mjs";
27
- import { default as rr } from "./submit/useResetFormOnSubmitSuccessful.mjs";
9
+ import { default as C } from "./errors/orphan/useOrphanFormErrorsMemo.mjs";
10
+ import { default as P } from "./errors/orphan/useOrphanFormErrorsToConsole.mjs";
11
+ import { default as b } from "./errors/root/useRootFormFieldErrorsMemo.mjs";
12
+ import { default as v } from "./errors/useFormErrorConsoleDebug.mjs";
13
+ import { default as G } from "./errors/useFormErrorsEffect.mjs";
14
+ import { default as I } from "./errors/useFormErrorsIfAny.mjs";
15
+ import { default as k } from "./errors/useFormErrorsMemo.mjs";
16
+ import { default as O } 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";
33
+ import { default as xr } from "./submit/useFormOnSubmitSuccessful.mjs";
34
+ import { default as ir } from "./submit/useFormOnSubmitSuccessfulAndReset.mjs";
35
+ import { default as Er } from "./submit/useResetFormOnSubmitSuccessful.mjs";
28
36
  export {
37
+ R as Form,
38
+ N as FormError,
29
39
  f as FormErrorMessage,
30
40
  d as FormErrorMessageByPath,
31
41
  u as FormErrorsFlatContextProvider,
32
- v as FormGroupContextProvider,
33
- F as FormNonFieldErrorMarker,
34
- n as FormNonFieldErrorMarkerHtmlAttribute,
42
+ Y as FormGroupContextProvider,
43
+ x as FormNonFieldErrorMarker,
44
+ i as FormNonFieldErrorMarkerHtmlAttribute,
45
+ w as FormProvider,
46
+ K as FormUtilsContextProvider,
47
+ U as FormWithProvider,
35
48
  e as LazyDevTool,
36
- W as getSubmitterButtonData,
37
- G as useFormErrorConsoleDebug,
38
- I as useFormErrorsEffect,
49
+ dr as getSubmitterButtonData,
50
+ q as useForm,
51
+ v as useFormErrorConsoleDebug,
52
+ G as useFormErrorsEffect,
39
53
  s as useFormErrorsFlatContext,
40
- k as useFormErrorsIfAny,
41
- O as useFormErrorsMemo,
42
- N as useFormGroupChildIsMountedTracker,
43
- q as useFormGroupChildIsSubmittingTracker,
44
- L as useFormGroupIsAnyBusy,
45
- w as useFormGroupIsChildBusy,
46
- K as useFormGroupIsParentBusy,
47
- U as useFormGroupParentTracker,
54
+ I as useFormErrorsIfAny,
55
+ k as useFormErrorsMemo,
56
+ _ as useFormGroupChildIsMountedTracker,
57
+ rr as useFormGroupChildIsSubmittingTracker,
58
+ er as useFormGroupIsAnyBusy,
59
+ sr as useFormGroupIsChildBusy,
60
+ ur as useFormGroupIsParentBusy,
61
+ fr as useFormGroupParentTracker,
48
62
  E as useFormHasOrphanAndNoFieldErrors,
49
- Y as useFormOnSubmitSuccessful,
50
- _ as useFormOnSubmitSuccessfulAndReset,
51
- T as useFormRequestSubmit,
52
- S as useOrphanFormErrorsMemo,
53
- C as useOrphanFormErrorsToConsole,
54
- rr as useResetFormAfterSubmitSuccessful,
55
- h as useRootFormFieldErrorsMemo
63
+ xr as useFormOnSubmitSuccessful,
64
+ ir as useFormOnSubmitSuccessfulAndReset,
65
+ O as useFormRequestSubmit,
66
+ V as useFormUtilsContext,
67
+ L as useFormWithProvider,
68
+ C as useOrphanFormErrorsMemo,
69
+ P as useOrphanFormErrorsToConsole,
70
+ Er as useResetFormAfterSubmitSuccessful,
71
+ b as useRootFormFieldErrorsMemo
56
72
  };
@@ -0,0 +1,7 @@
1
+ import e from "react";
2
+ function o(r) {
3
+ return e.forwardRef(r);
4
+ }
5
+ export {
6
+ o as default
7
+ };
@@ -0,0 +1,16 @@
1
+ import r from "react";
2
+ const a = (t) => {
3
+ const e = r.useRef(null);
4
+ return r.useImperativeHandle(
5
+ t,
6
+ () => {
7
+ if (!e.current)
8
+ throw new Error();
9
+ return e.current;
10
+ },
11
+ []
12
+ ), e;
13
+ }, o = a;
14
+ export {
15
+ o as default
16
+ };
@@ -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> = Omit<FormBaseProps, 'onSubmit'> & {
6
+ export type FormProps<TFieldValues extends FieldValues, TTransformedValues extends FieldValues> = React.PropsWithChildren<Pick<FormBaseProps, 'onChange'> & {
7
7
  isDev: boolean;
8
- formRef: React.RefObject<HTMLFormElement>;
9
- onSubmit: (values: TTransformedValues, context: UseFormReturn<TFieldValues, unknown, TTransformedValues>, event: React.BaseSyntheticEvent<SubmitEvent>) => unknown | Promise<unknown>;
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>({ rhf, form, children }: FormWithProvider<TFieldValues, TTransformedValues>): import("react/jsx-runtime").JSX.Element;
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: FormProps<TFieldValues, TTransformedValues>;
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
- formProps: FormProps<TFieldValues, TTransformedValues>;
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>({ formProps, onSubmitSuccessfulAndReset, children, }: Props<TFieldValues, TTransformedValues>): import("react/jsx-runtime").JSX.Element;
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: RhfUseFormProps<TFieldValues>;
8
+ rhf?: RhfUseFormProps<TFieldValues>;
9
9
  /** {@link FormProps} props for Form. */
10
- form: FormProps<TFieldValues, TTransformedValues>;
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
- export declare const useForm: <TFieldValues extends FieldValues, TTransformedValues extends FieldValues>({ rhf, form, utils, }: UseFormProps<TFieldValues, TTransformedValues>) => {
25
- Provider: React.FC<{
26
- children?: React.ReactNode;
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,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 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
+ 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
+ };
31
+ export default useFormWithProvider;
@@ -14,6 +14,14 @@ export { default as useFormErrorsEffect } from './errors/useFormErrorsEffect';
14
14
  export { default as useFormErrorsIfAny } from './errors/useFormErrorsIfAny';
15
15
  export { default as useFormErrorsMemo } from './errors/useFormErrorsMemo';
16
16
  export { default as useFormRequestSubmit } from './errors/useFormRequestSubmit';
17
+ export { default as Form } from './form/Form';
18
+ export { FormError } from './form/FormError';
19
+ export { default as FormWithProvider } from './form/FormWithProvider';
20
+ export { default as useForm } from './form/useForm';
21
+ export { default as useFormWithProvider } from './form/useFormWithProvider';
22
+ export { default as FormProvider } from './form/context/FormProvider';
23
+ export { default as FormUtilsContextProvider } from './form/context/utils/FormUtilsContextProvider';
24
+ export { default as useFormUtilsContext } from './form/context/utils/useFormUtilsContext';
17
25
  export { default as FormGroupContextProvider } from './form/context/group/FormGroupContextProvider';
18
26
  export { default as useFormGroupChildIsMountedTracker } from './form/context/group/useFormGroupChildIsMountedTracker';
19
27
  export { default as useFormGroupChildIsSubmittingTracker } from './form/context/group/useFormGroupChildIsSubmittingTracker';
@@ -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: React.ForwardedRef<TRef> | undefined) => React.RefObject<TRef>;
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.37",
5
+ "version": "0.0.45",
6
6
  "description": "Integration utilities for react-hook-form.",
7
7
  "type": "module",
8
8
  "sideEffects": false,
@@ -71,6 +71,38 @@
71
71
  "default": "./dist/esm/errors/root/useRootFormFieldErrors.mjs",
72
72
  "types": "./dist/types/errors/root/useRootFormFieldErrors.d.ts"
73
73
  },
74
+ "./form/Form": {
75
+ "default": "./dist/esm/form/Form.mjs",
76
+ "types": "./dist/types/form/Form.d.ts"
77
+ },
78
+ "./form/FormError": {
79
+ "default": "./dist/esm/form/FormError.mjs",
80
+ "types": "./dist/types/form/FormError.d.ts"
81
+ },
82
+ "./form/context/FormWithProvider": {
83
+ "default": "./dist/esm/form/context/FormWithProvider.mjs",
84
+ "types": "./dist/types/form/context/FormWithProvider.d.ts"
85
+ },
86
+ "./form/useForm": {
87
+ "default": "./dist/esm/form/useForm.mjs",
88
+ "types": "./dist/types/form/useForm.d.ts"
89
+ },
90
+ "./form/useFormWithProvider": {
91
+ "default": "./dist/esm/form/useFormWithProvider.mjs",
92
+ "types": "./dist/types/form/useFormWithProvider.d.ts"
93
+ },
94
+ "./form/context/FormProvider": {
95
+ "default": "./dist/esm/form/context/FormProvider.mjs",
96
+ "types": "./dist/types/form/context/FormProvider.d.ts"
97
+ },
98
+ "./form/context/FormUtilsContextProvider": {
99
+ "default": "./dist/esm/form/context/FormUtilsContextProvider.mjs",
100
+ "types": "./dist/types/form/context/FormUtilsContextProvider.d.ts"
101
+ },
102
+ "./form/context/useFormUtilsContext": {
103
+ "default": "./dist/esm/form/context/useFormUtilsContext.mjs",
104
+ "types": "./dist/types/form/context/useFormUtilsContext.d.ts"
105
+ },
74
106
  "./form/context/group/FormGroupContextProvider": {
75
107
  "default": "./dist/esm/form/context/group/FormGroupContextProvider.mjs",
76
108
  "types": "./dist/types/form/context/group/FormGroupContextProvider.d.ts"