@paragrav/rhf-utils 0.0.51 → 0.0.56

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 (49) hide show
  1. package/README.md +1 -0
  2. package/dist/esm/config/index.mjs +14 -0
  3. package/dist/esm/errors/isFieldError.mjs +2 -2
  4. package/dist/esm/errors/orphan/getOrphansFromFlatFieldErrors.mjs +5 -12
  5. package/dist/esm/errors/orphan/isOrphanFormError.mjs +12 -0
  6. package/dist/esm/errors/orphan/useFormHasOrphanAndNoFieldErrors.mjs +1 -1
  7. package/dist/esm/errors/orphan/useOrphanFormErrorsMemo.mjs +1 -1
  8. package/dist/esm/errors/useFormErrorsIfAny.mjs +1 -1
  9. package/dist/esm/errors/useFormErrorsToConsole.mjs +1 -1
  10. package/dist/esm/exports.mjs +72 -74
  11. package/dist/esm/form/context/group/useFormGroupChildIsMountedTracker.mjs +5 -14
  12. package/dist/esm/form/context/group/useFormGroupChildIsSubmittingTracker.mjs +6 -11
  13. package/dist/esm/form/context/group/useFormGroupChildTracker.mjs +13 -0
  14. package/dist/esm/form/context/group/useFormOrParentIsBusy.mjs +10 -0
  15. package/dist/esm/form/useForm.mjs +28 -24
  16. package/dist/esm/form/utils/getSubmitterButtonData.mjs +2 -1
  17. package/dist/esm/submit/useResetFormOnSubmitError.mjs +11 -11
  18. package/dist/esm/submit/useSubmitFormOnChange.mjs +14 -14
  19. package/dist/types/src/config/index.d.ts +57 -0
  20. package/dist/types/src/errors/orphan/isOrphanFormError.d.ts +4 -0
  21. package/dist/types/src/exports.d.ts +3 -4
  22. package/dist/types/src/form/FormWithProviders.d.ts +3 -4
  23. package/dist/types/src/form/_Form.d.ts +10 -0
  24. package/dist/types/src/form/_FormBase.d.ts +8 -0
  25. package/dist/types/src/form/_FormProviders.d.ts +12 -0
  26. package/dist/types/src/form/context/group/useFormGroupChildIsMountedTracker.d.ts +3 -0
  27. package/dist/types/src/form/context/group/useFormGroupChildIsSubmittingTracker.d.ts +3 -0
  28. package/dist/types/src/form/context/group/useFormGroupChildTracker.d.ts +6 -0
  29. package/dist/types/src/form/context/group/useFormOrParentIsBusy.d.ts +2 -0
  30. package/dist/types/src/form/context/utils/FormUtilsContextProvider.d.ts +3 -6
  31. package/dist/types/src/form/useForm.d.ts +40 -11
  32. package/dist/types/src/main.d.ts +7 -1
  33. package/dist/types/src/submit/error/FormSubmitError.d.ts +8 -2
  34. package/dist/types/src/submit/error/setCtxErrorsByFormSubmitError.d.ts +9 -0
  35. package/dist/types/src/submit/useResetFormOnSubmitError.d.ts +3 -1
  36. package/dist/types/src/submit/useSubmitFormOnChange.d.ts +3 -1
  37. package/dist/types/src/utils/isEmptyObject.d.ts +2 -0
  38. package/package.json +13 -17
  39. package/dist/esm/errors/root/FormRootErrors.mjs +0 -14
  40. package/dist/esm/errors/root/FormRootErrorsFromContext.mjs +0 -11
  41. package/dist/esm/form/Form.mjs +0 -63
  42. package/dist/esm/form/FormBase.mjs +0 -10
  43. package/dist/esm/form/FormWithProviders.mjs +0 -10
  44. package/dist/esm/form/context/FormProvider.mjs +0 -25
  45. package/dist/esm/form/useFormWithProviders.mjs +0 -28
  46. package/dist/esm/submit/error/handleFormSubmitError.mjs +0 -12
  47. package/dist/esm/utils/fixedForwardRef.mjs +0 -7
  48. package/dist/esm/utils/useImperativeForwardedRef.mjs +0 -16
  49. /package/dist/esm/{isEmptyObject.mjs → utils/isEmptyObject.mjs} +0 -0
package/README.md ADDED
@@ -0,0 +1 @@
1
+ Readme
@@ -0,0 +1,14 @@
1
+ let o;
2
+ const n = (t) => {
3
+ o = t;
4
+ }, e = (t) => ({
5
+ ...o,
6
+ options: {
7
+ ...o == null ? void 0 : o.options,
8
+ ...t
9
+ }
10
+ });
11
+ export {
12
+ e as _getConfig,
13
+ n as setConfig
14
+ };
@@ -1,4 +1,4 @@
1
- const e = (r) => !!r.ref, o = e;
1
+ const e = (r) => !!r.ref;
2
2
  export {
3
- o as default
3
+ e as default
4
4
  };
@@ -1,16 +1,9 @@
1
- import i from "../isFieldError.mjs";
2
- import { hasNonFieldErrorMarkerInDOM as m } from "../nonfield/FormNonFieldErrorMarker.utils.mjs";
3
- import s from "../root/isFormErrorPathRoot.mjs";
4
- const n = (o, t) => Object.fromEntries(
5
- Object.entries(o).filter(
6
- ([r, e]) => (
7
- // not root path
8
- !s(r) && // non-field
9
- !i(e) && // does not have marker
10
- !m(r, t)
11
- )
1
+ import s from "./isOrphanFormError.mjs";
2
+ const a = (r, t) => Object.fromEntries(
3
+ Object.entries(r).filter(
4
+ ([e, o]) => s(e, o, t)
12
5
  )
13
6
  );
14
7
  export {
15
- n as default
8
+ a as default
16
9
  };
@@ -0,0 +1,12 @@
1
+ import m from "../isFieldError.mjs";
2
+ import { hasNonFieldErrorMarkerInDOM as t } from "../nonfield/FormNonFieldErrorMarker.utils.mjs";
3
+ import s from "../root/isFormErrorPathRoot.mjs";
4
+ const n = (r, o, i) => (
5
+ // not root path
6
+ !s(r) && // non-field
7
+ !m(o) && // does not have marker
8
+ !t(r, i)
9
+ );
10
+ export {
11
+ n as default
12
+ };
@@ -1,4 +1,4 @@
1
- import r from "../../isEmptyObject.mjs";
1
+ import r from "../../utils/isEmptyObject.mjs";
2
2
  import t from "../flat/useRefdFieldErrorsMemo.mjs";
3
3
  import m from "./useOrphanFormErrorsMemo.mjs";
4
4
  const n = (o) => {
@@ -1,5 +1,5 @@
1
1
  import "react";
2
- import t from "../../isEmptyObject.mjs";
2
+ import t from "../../utils/isEmptyObject.mjs";
3
3
  import e from "../useFormErrorsMemo.mjs";
4
4
  import m from "./getOrphansFromFieldErrors.mjs";
5
5
  const s = (r) => e((o) => {
@@ -1,5 +1,5 @@
1
1
  import { useFormState as o } from "react-hook-form";
2
- import s from "../isEmptyObject.mjs";
2
+ import s from "../utils/isEmptyObject.mjs";
3
3
  const t = () => {
4
4
  const { errors: r } = o();
5
5
  return s(r) ? !1 : r;
@@ -1,6 +1,6 @@
1
1
  import a from "react";
2
2
  import { useFormContext as l, useFormState as E } from "react-hook-form";
3
- import c from "../isEmptyObject.mjs";
3
+ import c from "../utils/isEmptyObject.mjs";
4
4
  import d from "./outputErrors.mjs";
5
5
  const h = (e, f, r) => {
6
6
  const { getValues: m } = l(), { errors: u } = E();
@@ -1,76 +1,74 @@
1
- import { default as e } from "./devtool/LazyDevTool.mjs";
2
- import { default as s } from "./errors/context/index.mjs";
3
- import { default as u } from "./errors/context/provider.mjs";
4
- import { default as f } from "./errors/message/FormErrorMessage.mjs";
5
- import { default as d } from "./errors/message/FormErrorMessageByPath.mjs";
6
- import { default as x } from "./errors/nonfield/FormNonFieldErrorMarker.mjs";
7
- import { default as i } from "./errors/nonfield/FormNonFieldErrorMarkerHtmlAttribute.mjs";
8
- import { default as E } from "./errors/orphan/useFormHasOrphanAndNoFieldErrors.mjs";
9
- import { default as b } from "./errors/orphan/useOrphanFormErrorsMemo.mjs";
10
- import { default as c } from "./errors/orphan/useOrphanFormErrorsToConsole.mjs";
11
- import { default as P } 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 g } from "./errors/useFormErrorsIfAny.mjs";
15
- import { default as I } from "./errors/useFormErrorsMemo.mjs";
16
- import { default as B } from "./errors/useFormRequestSubmit.mjs";
17
- import { default as T } from "./form/Form.mjs";
18
- import { default as N } from "./form/FormWithProviders.mjs";
19
- import { default as U } from "./form/useForm.mjs";
20
- import { default as q } from "./form/useFormWithProviders.mjs";
21
- import { default as L } from "./form/context/FormProvider.mjs";
22
- import { default as w } from "./form/context/utils/FormUtilsContextProvider.mjs";
23
- import { default as K } from "./form/context/utils/useFormUtilsContext.mjs";
24
- import { default as V } from "./form/context/group/FormGroupContextProvider.mjs";
25
- import { default as Y } from "./form/context/group/useFormGroupChildIsMountedTracker.mjs";
26
- import { default as _ } from "./form/context/group/useFormGroupChildIsSubmittingTracker.mjs";
27
- import { default as rr } from "./form/context/group/useFormGroupIsAnyBusy.mjs";
28
- import { default as er } from "./form/context/group/useFormGroupIsChildBusy.mjs";
29
- import { default as sr } from "./form/context/group/useFormGroupIsParentBusy.mjs";
30
- import { default as ur } from "./form/context/group/useFormGroupParentTracker.mjs";
31
- import { default as fr } from "./form/utils/getSubmitterButtonData.mjs";
32
- import { FormSubmitError as dr } from "./submit/error/FormSubmitError.mjs";
33
- import { default as xr } from "./submit/useFormOnSubmitSuccessful.mjs";
34
- import { default as ir } from "./submit/useFormOnSubmitSuccessfulAndReset.mjs";
35
- import { default as Er } from "./submit/useResetFormOnSubmitError.mjs";
36
- import { default as br } from "./submit/useResetFormOnSubmitSuccessful.mjs";
37
- import { default as cr } from "./submit/useSubmitFormOnChange.mjs";
1
+ import { setConfig as e } from "./config/index.mjs";
2
+ import { default as s } from "./devtool/LazyDevTool.mjs";
3
+ import { default as a } from "./errors/context/index.mjs";
4
+ import { default as f } from "./errors/context/provider.mjs";
5
+ import { default as d } from "./errors/message/FormErrorMessage.mjs";
6
+ import { default as x } from "./errors/message/FormErrorMessageByPath.mjs";
7
+ import { default as n } from "./errors/nonfield/FormNonFieldErrorMarker.mjs";
8
+ import { default as E } from "./errors/nonfield/FormNonFieldErrorMarkerHtmlAttribute.mjs";
9
+ import { default as S } from "./errors/orphan/useFormHasOrphanAndNoFieldErrors.mjs";
10
+ import { default as c } from "./errors/orphan/useOrphanFormErrorsMemo.mjs";
11
+ import { default as y } from "./errors/orphan/useOrphanFormErrorsToConsole.mjs";
12
+ import { default as M } from "./errors/root/useRootFormFieldErrorsMemo.mjs";
13
+ import { default as g } from "./errors/useFormErrorConsoleDebug.mjs";
14
+ import { default as P } from "./errors/useFormErrorsEffect.mjs";
15
+ import { default as A } from "./errors/useFormErrorsIfAny.mjs";
16
+ import { default as T } from "./errors/useFormErrorsMemo.mjs";
17
+ import { default as v } from "./errors/useFormRequestSubmit.mjs";
18
+ import { default as N } from "./form/useForm.mjs";
19
+ import { default as U } from "./form/context/utils/FormUtilsContextProvider.mjs";
20
+ import { default as z } from "./form/context/utils/useFormUtilsContext.mjs";
21
+ import { default as j } from "./form/context/group/FormGroupContextProvider.mjs";
22
+ import { default as J } from "./form/context/group/useFormGroupChildIsMountedTracker.mjs";
23
+ import { default as Q } from "./form/context/group/useFormGroupChildIsSubmittingTracker.mjs";
24
+ import { default as W } from "./form/context/group/useFormGroupChildTracker.mjs";
25
+ import { default as Y } from "./form/context/group/useFormGroupIsAnyBusy.mjs";
26
+ import { default as _ } from "./form/context/group/useFormGroupIsChildBusy.mjs";
27
+ import { default as rr } from "./form/context/group/useFormGroupIsParentBusy.mjs";
28
+ import { default as er } from "./form/context/group/useFormGroupParentTracker.mjs";
29
+ import { default as sr } from "./form/context/group/useFormOrParentIsBusy.mjs";
30
+ import { default as ar } from "./form/utils/getSubmitterButtonData.mjs";
31
+ import { FormSubmitError as fr } from "./submit/error/FormSubmitError.mjs";
32
+ import { default as dr } from "./submit/useFormOnSubmitSuccessful.mjs";
33
+ import { default as xr } from "./submit/useFormOnSubmitSuccessfulAndReset.mjs";
34
+ import { default as nr } from "./submit/useResetFormOnSubmitError.mjs";
35
+ import { default as Er } from "./submit/useResetFormOnSubmitSuccessful.mjs";
36
+ import { default as Sr } from "./submit/useSubmitFormOnChange.mjs";
38
37
  export {
39
- T as Form,
40
- f as FormErrorMessage,
41
- d as FormErrorMessageByPath,
42
- u as FormErrorsFlatContextProvider,
43
- V as FormGroupContextProvider,
44
- x as FormNonFieldErrorMarker,
45
- i as FormNonFieldErrorMarkerHtmlAttribute,
46
- L as FormProvider,
47
- dr as FormSubmitError,
48
- w as FormUtilsContextProvider,
49
- N as FormWithProviders,
50
- e as LazyDevTool,
51
- fr as getSubmitterButtonData,
52
- U as useForm,
53
- v as useFormErrorConsoleDebug,
54
- G as useFormErrorsEffect,
55
- s as useFormErrorsFlatContext,
56
- g as useFormErrorsIfAny,
57
- I as useFormErrorsMemo,
58
- Y as useFormGroupChildIsMountedTracker,
59
- _ as useFormGroupChildIsSubmittingTracker,
60
- rr as useFormGroupIsAnyBusy,
61
- er as useFormGroupIsChildBusy,
62
- sr as useFormGroupIsParentBusy,
63
- ur as useFormGroupParentTracker,
64
- E as useFormHasOrphanAndNoFieldErrors,
65
- xr as useFormOnSubmitSuccessful,
66
- ir as useFormOnSubmitSuccessfulAndReset,
67
- B as useFormRequestSubmit,
68
- K as useFormUtilsContext,
69
- q as useFormWithProviders,
70
- b as useOrphanFormErrorsMemo,
71
- c as useOrphanFormErrorsToConsole,
72
- br as useResetFormAfterSubmitSuccessful,
73
- Er as useResetFormOnSubmitError,
74
- P as useRootFormFieldErrorsMemo,
75
- cr as useSubmitFormOnChange
38
+ d as FormErrorMessage,
39
+ x as FormErrorMessageByPath,
40
+ f as FormErrorsFlatContextProvider,
41
+ j as FormGroupContextProvider,
42
+ n as FormNonFieldErrorMarker,
43
+ E as FormNonFieldErrorMarkerHtmlAttribute,
44
+ fr as FormSubmitError,
45
+ U as FormUtilsContextProvider,
46
+ s as LazyDevTool,
47
+ ar as getSubmitterButtonData,
48
+ e as setConfig,
49
+ N as useForm,
50
+ g as useFormErrorConsoleDebug,
51
+ P as useFormErrorsEffect,
52
+ a as useFormErrorsFlatContext,
53
+ A as useFormErrorsIfAny,
54
+ T as useFormErrorsMemo,
55
+ J as useFormGroupChildIsMountedTracker,
56
+ Q as useFormGroupChildIsSubmittingTracker,
57
+ W as useFormGroupChildTracker,
58
+ Y as useFormGroupIsAnyBusy,
59
+ _ as useFormGroupIsChildBusy,
60
+ rr as useFormGroupIsParentBusy,
61
+ er as useFormGroupParentTracker,
62
+ S as useFormHasOrphanAndNoFieldErrors,
63
+ dr as useFormOnSubmitSuccessful,
64
+ xr as useFormOnSubmitSuccessfulAndReset,
65
+ sr as useFormOrParentIsBusy,
66
+ v as useFormRequestSubmit,
67
+ z as useFormUtilsContext,
68
+ c as useOrphanFormErrorsMemo,
69
+ y as useOrphanFormErrorsToConsole,
70
+ Er as useResetFormAfterSubmitSuccessful,
71
+ nr as useResetFormOnSubmitError,
72
+ M as useRootFormFieldErrorsMemo,
73
+ Sr as useSubmitFormOnChange
76
74
  };
@@ -1,16 +1,7 @@
1
- import o from "react";
2
- import { _useFormGroupContext as u } from "./index.mjs";
3
- const c = () => {
4
- const { setBusyId: r } = u().children, s = o.useId();
5
- o.useEffect(() => {
6
- const e = (t) => {
7
- r(s, t);
8
- };
9
- return e(!0), () => {
10
- e(!1);
11
- };
12
- }, []);
13
- }, m = c;
1
+ import r from "./useFormGroupChildTracker.mjs";
2
+ const o = () => {
3
+ r(!0);
4
+ }, u = o;
14
5
  export {
15
- m as default
6
+ u as default
16
7
  };
@@ -1,14 +1,9 @@
1
- import e from "react";
2
- import { useFormState as s } from "react-hook-form";
3
- import { _useFormGroupContext as u } from "./index.mjs";
1
+ import { useFormState as o } from "react-hook-form";
2
+ import t from "./useFormGroupChildTracker.mjs";
4
3
  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;
4
+ const { isSubmitting: r } = o();
5
+ t(r);
6
+ }, u = i;
12
7
  export {
13
- f as default
8
+ u as default
14
9
  };
@@ -0,0 +1,13 @@
1
+ import o from "react";
2
+ import { _useFormGroupContext as t } from "./index.mjs";
3
+ const u = (s) => {
4
+ const { setBusyId: e } = t().children, r = o.useId();
5
+ o.useEffect(() => {
6
+ e(r, s);
7
+ }, [s, r, e]), o.useEffect(() => () => {
8
+ e(r, !1);
9
+ }, []);
10
+ }, d = u;
11
+ export {
12
+ d as default
13
+ };
@@ -0,0 +1,10 @@
1
+ import t from "../../useFormIsBusy.mjs";
2
+ import { _useFormGroupContextMaybe as e } from "./index.mjs";
3
+ const u = () => {
4
+ var s;
5
+ const r = t(), o = (s = e()) == null ? void 0 : s.parent.isBusy;
6
+ return !!(r || o);
7
+ }, a = u;
8
+ export {
9
+ a as default
10
+ };
@@ -1,29 +1,33 @@
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";
1
+ import n from "react";
2
+ import { useForm as p } from "react-hook-form";
3
+ import u from "../submit/useSubmitFormOnChange.mjs";
4
+ import { _getConfig as c } from "../config/index.mjs";
6
5
  const f = ({
7
- rhf: e,
8
- form: o
6
+ rhf: m,
7
+ form: o,
8
+ utils: i
9
9
  }) => {
10
- const r = i.useId(), m = u(e), t = F();
11
- return {
12
- id: r,
13
- ref: t,
14
- context: m,
15
- Form: ({ children: s }) => /* @__PURE__ */ n(
16
- c,
17
- {
18
- formId: r,
19
- formRef: t,
20
- onSubmit: o == null ? void 0 : o.onSubmit,
21
- ...o,
22
- children: s
23
- }
24
- )
10
+ const t = c(o == null ? void 0 : o.options), s = n.useId(), e = p({
11
+ ...t.rhf,
12
+ ...m
13
+ }), r = n.useRef(null);
14
+ return u(r, { disabled: !t.options.submitOnChange }), {
15
+ id: s,
16
+ ref: r,
17
+ context: e,
18
+ providerProps: {
19
+ formId: s,
20
+ formRef: r,
21
+ rhfForm: e,
22
+ utils: i
23
+ },
24
+ formProps: {
25
+ formId: s,
26
+ formRef: r,
27
+ form: o
28
+ }
25
29
  };
26
- }, b = f;
30
+ }, P = f;
27
31
  export {
28
- b as default
32
+ P as default
29
33
  };
@@ -1,6 +1,7 @@
1
1
  import "react";
2
2
  const e = (t) => {
3
- if (t.nativeEvent instanceof SubmitEvent && (t.nativeEvent.submitter instanceof HTMLButtonElement || t.nativeEvent.submitter instanceof HTMLInputElement) && t.nativeEvent.submitter.name)
3
+ if (t.nativeEvent instanceof SubmitEvent && !(!(t.nativeEvent.submitter instanceof HTMLButtonElement) && // not button
4
+ !(t.nativeEvent.submitter instanceof HTMLInputElement)) && t.nativeEvent.submitter.name)
4
5
  return [
5
6
  t.nativeEvent.submitter.name,
6
7
  t.nativeEvent.submitter.value
@@ -1,18 +1,18 @@
1
- import i from "react";
2
- import { useFormContext as m, useFormState as n } from "react-hook-form";
3
- const f = (t) => {
4
- const { reset: r } = m(), { isSubmitting: e, isSubmitSuccessful: u, isSubmitted: o, submitCount: s } = n();
5
- i.useEffect(() => {
6
- t || e || u || o && s !== 0 && r(void 0);
1
+ import f from "react";
2
+ import { useFormContext as n, useFormState as o } from "react-hook-form";
3
+ const c = (t) => {
4
+ const e = !!(t != null && t.disabled), { reset: r } = n(), { isSubmitting: u, isSubmitSuccessful: s, isSubmitted: i, submitCount: m } = o();
5
+ f.useEffect(() => {
6
+ e || u || s || i && m !== 0 && r();
7
7
  }, [
8
- t,
9
8
  e,
10
9
  u,
11
- o,
10
+ s,
11
+ i,
12
12
  r,
13
- s
13
+ m
14
14
  ]);
15
- }, b = f;
15
+ }, a = c;
16
16
  export {
17
- b as default
17
+ a as default
18
18
  };
@@ -1,21 +1,21 @@
1
- import s from "react";
2
- import u from "../errors/useFormRequestSubmit.mjs";
3
- const m = (t, n) => {
4
- const o = u(t);
5
- s.useEffect(() => {
6
- if (n)
1
+ import m from "react";
2
+ import s from "../errors/useFormRequestSubmit.mjs";
3
+ const a = (t, e) => {
4
+ const u = s(t);
5
+ m.useEffect(() => {
6
+ if (e != null && e.disabled)
7
7
  return;
8
- const e = t.current;
9
- if (!e)
8
+ const r = t.current;
9
+ if (!r)
10
10
  throw new Error();
11
- const r = () => {
12
- o();
11
+ const n = () => {
12
+ u();
13
13
  };
14
- return e.addEventListener("change", r), () => {
15
- e.removeEventListener("change", r);
14
+ return r.addEventListener("change", n), () => {
15
+ r.removeEventListener("change", n);
16
16
  };
17
17
  }, []);
18
- }, a = m;
18
+ }, i = a;
19
19
  export {
20
- a as default
20
+ i as default
21
21
  };
@@ -0,0 +1,57 @@
1
+ import { FormSubmitError } from '../submit/error/FormSubmitError';
2
+ import { UseFormOptions } from '../form/useForm';
3
+ import { FieldValues, UseFormProps, UseFormStateReturn } from 'react-hook-form';
4
+
5
+ type Config = {
6
+ rhf?: Pick<UseFormProps, 'mode' | 'reValidateMode' | 'resetOptions' | 'context' | 'shouldFocusError' | 'shouldUnregister' | 'shouldUseNativeValidation' | 'progressive' | 'criteriaMode' | 'delayError'>;
7
+ options?: UseFormOptions;
8
+ /**
9
+ * Handle non-{@link FormSubmitError} errors. Optionally, return {@link FormSubmitError} to merge into context errors.
10
+ */
11
+ onSubmitError?: (error: unknown) => FormSubmitError | undefined;
12
+ Prompter?: React.FC<UseFormStateReturn<FieldValues>>;
13
+ };
14
+ export declare const setConfig: (config: Config) => void;
15
+ export declare const _getConfig: (options?: UseFormOptions) => {
16
+ options: {
17
+ hideRootErrorsList?: boolean | undefined;
18
+ submitOnChange?: boolean | undefined;
19
+ resetValuesOnSubmitError?: boolean | undefined;
20
+ stopSubmitPropagation?: boolean | undefined;
21
+ devTool?: import('@hookform/devtools/dist/devToolUI').DevtoolUIProps | "disabled" | undefined;
22
+ };
23
+ rhf?: Pick<Partial<{
24
+ mode: "onBlur" | "onChange" | "onSubmit" | "onTouched" | "all";
25
+ disabled: boolean;
26
+ reValidateMode: "onBlur" | "onChange" | "onSubmit";
27
+ defaultValues: {
28
+ [x: string]: any;
29
+ } | ((payload?: unknown) => Promise<FieldValues>);
30
+ values: FieldValues;
31
+ errors: import('react-hook-form').FieldErrors<FieldValues>;
32
+ resetOptions: Partial<{
33
+ keepDirtyValues: boolean;
34
+ keepErrors: boolean;
35
+ keepDirty: boolean;
36
+ keepValues: boolean;
37
+ keepDefaultValues: boolean;
38
+ keepIsSubmitted: boolean;
39
+ keepIsSubmitSuccessful: boolean;
40
+ keepTouched: boolean;
41
+ keepIsValidating: boolean;
42
+ keepIsValid: boolean;
43
+ keepSubmitCount: boolean;
44
+ }> | undefined;
45
+ resolver: import('react-hook-form').Resolver<FieldValues, any>;
46
+ context: any;
47
+ shouldFocusError: boolean;
48
+ shouldUnregister: boolean;
49
+ shouldUseNativeValidation: boolean;
50
+ progressive: boolean;
51
+ criteriaMode: import('react-hook-form').CriteriaMode;
52
+ delayError: number;
53
+ }>, "mode" | "reValidateMode" | "resetOptions" | "context" | "shouldFocusError" | "shouldUnregister" | "shouldUseNativeValidation" | "progressive" | "criteriaMode" | "delayError"> | undefined;
54
+ onSubmitError?: ((error: unknown) => FormSubmitError | undefined) | undefined;
55
+ Prompter?: import('react').FC<UseFormStateReturn<FieldValues>> | undefined;
56
+ };
57
+ export {};
@@ -0,0 +1,4 @@
1
+ import { FieldError } from 'react-hook-form';
2
+
3
+ declare const isOrphanFormError: (path: string, error: FieldError, parentElement: Pick<HTMLElement, 'querySelector'>) => boolean;
4
+ export default isOrphanFormError;
@@ -1,3 +1,4 @@
1
+ export { setConfig } from './config';
1
2
  export { default as LazyDevTool } from './devtool/LazyDevTool';
2
3
  export { default as useFormErrorsFlatContext } from './errors/context';
3
4
  export { default as FormErrorsFlatContextProvider } from './errors/context/provider';
@@ -14,20 +15,18 @@ export { default as useFormErrorsEffect } from './errors/useFormErrorsEffect';
14
15
  export { default as useFormErrorsIfAny } from './errors/useFormErrorsIfAny';
15
16
  export { default as useFormErrorsMemo } from './errors/useFormErrorsMemo';
16
17
  export { default as useFormRequestSubmit } from './errors/useFormRequestSubmit';
17
- export { default as Form } from './form/Form';
18
- export { default as FormWithProviders } from './form/FormWithProviders';
19
18
  export { default as useForm } from './form/useForm';
20
- export { default as useFormWithProviders } from './form/useFormWithProviders';
21
- export { default as FormProvider } from './form/context/FormProvider';
22
19
  export { default as FormUtilsContextProvider } from './form/context/utils/FormUtilsContextProvider';
23
20
  export { default as useFormUtilsContext } from './form/context/utils/useFormUtilsContext';
24
21
  export { default as FormGroupContextProvider } from './form/context/group/FormGroupContextProvider';
25
22
  export { default as useFormGroupChildIsMountedTracker } from './form/context/group/useFormGroupChildIsMountedTracker';
26
23
  export { default as useFormGroupChildIsSubmittingTracker } from './form/context/group/useFormGroupChildIsSubmittingTracker';
24
+ export { default as useFormGroupChildTracker } from './form/context/group/useFormGroupChildTracker';
27
25
  export { default as useFormGroupIsAnyBusy } from './form/context/group/useFormGroupIsAnyBusy';
28
26
  export { default as useFormGroupIsChildBusy } from './form/context/group/useFormGroupIsChildBusy';
29
27
  export { default as useFormGroupIsParentBusy } from './form/context/group/useFormGroupIsParentBusy';
30
28
  export { default as useFormGroupParentTracker } from './form/context/group/useFormGroupParentTracker';
29
+ export { default as useFormOrParentIsBusy } from './form/context/group/useFormOrParentIsBusy';
31
30
  export { default as getSubmitterButtonData } from './form/utils/getSubmitterButtonData';
32
31
  export { FormSubmitError } from './submit/error/FormSubmitError';
33
32
  export { default as useFormOnSubmitSuccessful } from './submit/useFormOnSubmitSuccessful';
@@ -1,13 +1,12 @@
1
1
  import { UseFormProps } from './useForm';
2
- import { FieldValues } from 'react-hook-form';
2
+ import { z } from 'zod';
3
3
 
4
- export type FormWithProviders<TFieldValues extends FieldValues, TTransformedValues extends FieldValues> = React.PropsWithChildren<UseFormProps<TFieldValues, TTransformedValues>>;
5
4
  /**
6
- * {@link FormProvider} (and utils) with immediate descendent {@link Form}.
5
+ * Form providers (with utils) with immediate descendent {@link Form}.
7
6
  * (Syntactic sugar for {@link useForm}. Use this for most applications.)
8
7
  *
9
8
  * Use {@link useForm} if you need to specific nesting hierarchy.
10
9
  * (e.g., wrapping `<tr>` with provider and nesting `<form>` within `<td>` to appease HTML rules.)
11
10
  */
12
- declare function FormWithProviders<TFieldValues extends FieldValues, TTransformedValues extends FieldValues>({ children, ...props }: FormWithProviders<TFieldValues, TTransformedValues>): import("react/jsx-runtime").JSX.Element;
11
+ declare function FormWithProviders<TSchema extends z.SomeZodObject, TFieldValues extends z.input<TSchema>, TTransformedValues extends z.output<TSchema>>({ children, ...props }: React.PropsWithChildren<UseFormProps<TSchema, TFieldValues, TTransformedValues>>): import("react/jsx-runtime").JSX.Element;
13
12
  export default FormWithProviders;
@@ -0,0 +1,10 @@
1
+ import { UseFormProps } from './useForm';
2
+ import { z } from 'zod';
3
+ import { default as React } from 'react';
4
+
5
+ export type _FormProps<TSchema extends z.SomeZodObject, TFieldValues extends z.input<TSchema>, TTransformedValues extends z.output<TSchema>> = React.PropsWithChildren<Pick<UseFormProps<TSchema, TFieldValues, TTransformedValues>, 'form'> & {
6
+ formId: string;
7
+ formRef: React.RefObject<HTMLFormElement>;
8
+ }>;
9
+ declare function _Form<TSchema extends z.SomeZodObject, TFieldValues extends z.input<TSchema>, TTransformedValues extends z.output<TSchema>>({ formId, formRef, form, children, }: _FormProps<TSchema, TFieldValues, TTransformedValues>): import("react/jsx-runtime").JSX.Element;
10
+ export default _Form;
@@ -0,0 +1,8 @@
1
+ import { default as React } from 'react';
2
+
3
+ export type FormBaseProps = React.PropsWithoutRef<JSX.IntrinsicElements['form']> & {
4
+ formRef: React.RefObject<HTMLFormElement>;
5
+ antiCsrfToken?: string;
6
+ };
7
+ declare const _FormBase: ({ formRef, antiCsrfToken, children, ...props }: FormBaseProps) => import("react/jsx-runtime").JSX.Element;
8
+ export default _FormBase;
@@ -0,0 +1,12 @@
1
+ import { FormUtilsContextProviderProps } from './context/utils/FormUtilsContextProvider';
2
+ import { z } from 'zod';
3
+ import { UseFormReturn } from 'react-hook-form';
4
+
5
+ export type _FormProvidersProps<TSchema extends z.SomeZodObject, TFieldValues extends z.input<TSchema>, TTransformedValues extends z.output<TSchema>> = React.PropsWithChildren<{
6
+ formId: string;
7
+ formRef: React.RefObject<HTMLFormElement>;
8
+ rhfForm: UseFormReturn<TFieldValues, unknown, TTransformedValues>;
9
+ utils?: FormUtilsContextProviderProps;
10
+ }>;
11
+ declare function _FormProviders<TSchema extends z.SomeZodObject, TFieldValues extends z.input<TSchema>, TTransformedValues extends z.output<TSchema>>({ formId, formRef, rhfForm, utils, children, }: _FormProvidersProps<TSchema, TFieldValues, TTransformedValues>): import("react/jsx-runtime").JSX.Element;
12
+ export default _FormProviders;
@@ -1,2 +1,5 @@
1
+ /**
2
+ * Mark "child" form as "busy" when mounted.
3
+ */
1
4
  declare const useFormGroupChildIsMountedTracker: () => void;
2
5
  export default useFormGroupChildIsMountedTracker;
@@ -1,2 +1,5 @@
1
+ /**
2
+ * Mark "child" form as "busy" when submitting.
3
+ */
1
4
  declare const useFormGroupChildIsSubmittingTracker: () => void;
2
5
  export default useFormGroupChildIsSubmittingTracker;
@@ -0,0 +1,6 @@
1
+ /**
2
+ * Mark "child" form as "busy" via arbitrary boolean.
3
+ * Automatically marks as "not busy" on dismount.
4
+ */
5
+ declare const useFormGroupChildTracker: (track: boolean) => void;
6
+ export default useFormGroupChildTracker;
@@ -0,0 +1,2 @@
1
+ declare const useFormOrParentIsBusy: () => boolean;
2
+ export default useFormOrParentIsBusy;
@@ -1,14 +1,11 @@
1
- import { FormProps } from '../../Form';
2
- import { FieldValues } from 'react-hook-form';
3
-
1
+ /// <reference types="react" />
4
2
  export type FormUtilsContextProviderProps = {
5
3
  /** Callback after successful submit, and form reset. */
6
4
  onSubmitSuccessfulAndReset?: () => void;
7
5
  };
8
- type Props<TFieldValues extends FieldValues, TTransformedValues extends FieldValues> = React.PropsWithChildren<{
6
+ type Props = React.PropsWithChildren<{
9
7
  formId: string;
10
8
  formRef: React.RefObject<HTMLFormElement>;
11
- formProps?: Omit<FormProps<TFieldValues, TTransformedValues>, 'formRef' | 'formId'>;
12
9
  } & FormUtilsContextProviderProps>;
13
- declare function FormUtilsContextProvider<TFieldValues extends FieldValues, TTransformedValues extends FieldValues>({ formRef, onSubmitSuccessfulAndReset, children, }: Props<TFieldValues, TTransformedValues>): import("react/jsx-runtime").JSX.Element;
10
+ declare function FormUtilsContextProvider({ formRef, onSubmitSuccessfulAndReset, children, }: Props): import("react/jsx-runtime").JSX.Element;
14
11
  export default FormUtilsContextProvider;
@@ -1,16 +1,46 @@
1
- import { FormProps } from './Form';
2
- import { FieldValues, UseFormProps as RhfUseFormProps } from 'react-hook-form';
1
+ import { FormUtilsContextProviderProps } from './context/utils/FormUtilsContextProvider';
2
+ import { _FormProvidersProps } from './_FormProviders';
3
+ import { _FormProps } from './_Form';
4
+ import { z } from 'zod';
5
+ import { SubmitErrorHandler, UseFormProps as RhfUseFormProps, UseFormReturn } from 'react-hook-form';
3
6
  import { default as React } from 'react';
7
+ import { DevtoolUIProps } from '@hookform/devtools/dist/devToolUI';
4
8
 
5
- export type UseFormProps<TFieldValues extends FieldValues, TTransformedValues extends FieldValues> = {
9
+ export type UseFormOptions = {
10
+ /** */
11
+ hideRootErrorsList?: boolean;
12
+ /** Request submit via listener on form change. */
13
+ submitOnChange?: boolean;
14
+ /** Reset form values if submit throw errors. Use case: optimistic UI toggle form that submits on each change */
15
+ resetValuesOnSubmitError?: boolean;
16
+ stopSubmitPropagation?: boolean;
17
+ devTool?: DevtoolUIProps | 'disabled';
18
+ };
19
+ export type UseFormFieldProps<TSchema extends z.SomeZodObject, TFieldValues extends z.input<TSchema>, TTransformedValues extends z.output<TSchema>> = {
20
+ formId: string;
21
+ formRef: React.RefObject<HTMLFormElement>;
22
+ ctx: UseFormReturn<TFieldValues, unknown, TTransformedValues>;
23
+ options?: UseFormOptions;
24
+ };
25
+ export type UseFormProps<TSchema extends z.SomeZodObject, TFieldValues extends z.input<TSchema>, TTransformedValues extends z.output<TSchema>> = {
26
+ schema?: TSchema;
6
27
  /** {@link RhfUseFormProps} props for RHF's {@link useRhfForm}. */
7
28
  rhf?: RhfUseFormProps<TFieldValues>;
8
29
  /** {@link FormProps} props for Form. */
9
- form?: Omit<FormProps<TFieldValues, TTransformedValues>, 'formId' | 'formRef'>;
30
+ form?: {
31
+ Fields?: React.FC<UseFormFieldProps<TSchema, TFieldValues, TTransformedValues>>;
32
+ onSubmit?: (values: TTransformedValues, context: UseFormReturn<TFieldValues, unknown, TTransformedValues>, event: React.BaseSyntheticEvent<SubmitEvent>) => unknown | Promise<unknown>;
33
+ /** Submit error handler. (Only for errors not of instance `FormError`, which are handled internally.) */
34
+ onSubmitError?: (error: unknown, context: UseFormReturn<TFieldValues, unknown, TTransformedValues>, event: React.BaseSyntheticEvent<SubmitEvent>) => void;
35
+ /** Submit handler when form is invalid. */
36
+ onSubmitInvalid?: SubmitErrorHandler<TFieldValues>;
37
+ options?: UseFormOptions;
38
+ props?: React.PropsWithoutRef<JSX.IntrinsicElements['form']>;
39
+ };
40
+ utils?: FormUtilsContextProviderProps;
10
41
  };
11
- export type UseFormReturn = ReturnType<typeof useForm>;
12
42
  /**
13
- * Base Rhf Form hook. Use `Form` in `index.ts` for most cases.
43
+ * Core Rhf Form hook. Use `Form` in `index.ts` for most cases.
14
44
  * Use this if you need to separate form components.
15
45
  * e.g., a form for table row due to `form` being considered invalid HTML around `tr` tags.
16
46
  * With this hook, you can wrap the `tr` tag with `form.Provider` and use `form.Form` inside
@@ -18,12 +48,11 @@ export type UseFormReturn = ReturnType<typeof useForm>;
18
48
  * see https://caniuse.com/?search=form%20attribute
19
49
  * @returns Form provider and form.
20
50
  */
21
- declare const useForm: <TFieldValues extends FieldValues, TTransformedValues extends FieldValues>({ rhf, form, }: UseFormProps<TFieldValues, TTransformedValues>) => {
51
+ declare const useForm: <TSchema extends z.SomeZodObject, TFieldValues extends z.input<TSchema>, TTransformedValues extends z.output<TSchema>>({ rhf, form, utils, }: UseFormProps<TSchema, TFieldValues, TTransformedValues>) => {
22
52
  readonly id: string;
23
53
  readonly ref: React.RefObject<HTMLFormElement>;
24
- readonly context: import('react-hook-form').UseFormReturn<TFieldValues, unknown, TTransformedValues>;
25
- readonly Form: React.FC<{
26
- children?: React.ReactNode;
27
- }>;
54
+ readonly context: UseFormReturn<TFieldValues, unknown, TTransformedValues>;
55
+ readonly providerProps: _FormProvidersProps<TSchema, TFieldValues, TTransformedValues>;
56
+ readonly formProps: _FormProps<TSchema, TFieldValues, TTransformedValues>;
28
57
  };
29
58
  export default useForm;
@@ -1 +1,7 @@
1
- export {};
1
+ import { default as React } from 'react';
2
+
3
+ type Props = {
4
+ error: boolean;
5
+ };
6
+ declare const ToggleFormSpec: React.FC<Props>;
7
+ export default ToggleFormSpec;
@@ -1,6 +1,12 @@
1
1
  import { FieldPath, FieldValues } from 'react-hook-form';
2
2
 
3
3
  export declare class FormSubmitError<TFieldValues extends FieldValues = FieldValues> extends Error {
4
- errors: Partial<Record<FieldPath<TFieldValues> | `root.${string}`, string>>;
5
- constructor(errors: Partial<Record<FieldPath<TFieldValues> | `root.${string}`, string>>, message?: string);
4
+ errors: Record<FieldPath<TFieldValues> | `root.${string}`, {
5
+ type?: string;
6
+ message: string;
7
+ }>;
8
+ constructor(errors: Record<FieldPath<TFieldValues> | `root.${string}`, {
9
+ type?: string;
10
+ message: string;
11
+ }>, message?: string);
6
12
  }
@@ -0,0 +1,9 @@
1
+ import { FormSubmitError } from './FormSubmitError';
2
+ import { FieldValues, UseFormReturn } from 'react-hook-form';
3
+
4
+ /**
5
+ * Handle thrown {@link FormSubmitError}.
6
+ * Add key/values as name/message to RHF context errors.
7
+ */
8
+ declare const setCtxErrorsByFormSubmitError: <TFieldValues extends FieldValues, TTransformedValues extends FieldValues>(ctx: UseFormReturn<TFieldValues, unknown, TTransformedValues>, error: FormSubmitError<any>) => void;
9
+ export default setCtxErrorsByFormSubmitError;
@@ -3,5 +3,7 @@
3
3
  * See `Rules` section: https://react-hook-form.com/api/useform/reset/
4
4
  * Specifically: "- It's recommended to reset inside useEffect after submission."
5
5
  */
6
- declare const useResetFormOnSubmitError: (disabled?: boolean) => void;
6
+ declare const useResetFormOnSubmitError: (options?: {
7
+ disabled?: boolean;
8
+ }) => void;
7
9
  export default useResetFormOnSubmitError;
@@ -1,4 +1,6 @@
1
1
  import { default as React } from 'react';
2
2
 
3
- declare const useSubmitFormOnChange: (formRef: React.RefObject<HTMLFormElement>, disabled?: boolean) => void;
3
+ declare const useSubmitFormOnChange: (formRef: React.RefObject<HTMLFormElement>, options?: {
4
+ disabled?: boolean;
5
+ }) => void;
4
6
  export default useSubmitFormOnChange;
@@ -0,0 +1,2 @@
1
+ declare const isEmptyObject: (obj: Record<string, unknown>) => boolean;
2
+ export default isEmptyObject;
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.51",
5
+ "version": "0.0.56",
6
6
  "description": "Integration utilities for react-hook-form.",
7
7
  "type": "module",
8
8
  "sideEffects": false,
@@ -21,6 +21,10 @@
21
21
  "default": "./dist/esm/exports.mjs",
22
22
  "types": "./dist/types/exports.d.ts"
23
23
  },
24
+ "./setConfig": {
25
+ "default": "./dist/esm/setConfig.mjs",
26
+ "types": "./dist/types/setConfig.d.ts"
27
+ },
24
28
  "./LazyDevTool": {
25
29
  "default": "./dist/esm/devtool/LazyDevTool.mjs",
26
30
  "types": "./dist/types/devtool/LazyDevTool.d.ts"
@@ -77,26 +81,10 @@
77
81
  "default": "./dist/esm/errors/root/useRootFormFieldErrors.mjs",
78
82
  "types": "./dist/types/errors/root/useRootFormFieldErrors.d.ts"
79
83
  },
80
- "./form/Form": {
81
- "default": "./dist/esm/form/Form.mjs",
82
- "types": "./dist/types/form/Form.d.ts"
83
- },
84
- "./form/context/FormWithProviders": {
85
- "default": "./dist/esm/form/context/FormWithProviders.mjs",
86
- "types": "./dist/types/form/context/FormWithProviders.d.ts"
87
- },
88
84
  "./form/useForm": {
89
85
  "default": "./dist/esm/form/useForm.mjs",
90
86
  "types": "./dist/types/form/useForm.d.ts"
91
87
  },
92
- "./form/useFormWithProviders": {
93
- "default": "./dist/esm/form/useFormWithProviders.mjs",
94
- "types": "./dist/types/form/useFormWithProviders.d.ts"
95
- },
96
- "./form/context/FormProvider": {
97
- "default": "./dist/esm/form/context/FormProvider.mjs",
98
- "types": "./dist/types/form/context/FormProvider.d.ts"
99
- },
100
88
  "./form/context/FormUtilsContextProvider": {
101
89
  "default": "./dist/esm/form/context/FormUtilsContextProvider.mjs",
102
90
  "types": "./dist/types/form/context/FormUtilsContextProvider.d.ts"
@@ -113,10 +101,18 @@
113
101
  "default": "./dist/esm/form/context/group/useFormGroupParentTracker.mjs",
114
102
  "types": "./dist/types/form/context/group/useFormGroupParentTracker.d.ts"
115
103
  },
104
+ "./form/context/group/useFormOrParentIsBusy": {
105
+ "default": "./dist/esm/form/context/group/useFormOrParentIsBusy.mjs",
106
+ "types": "./dist/types/form/context/group/useFormOrParentIsBusy.d.ts"
107
+ },
116
108
  "./form/context/group/useFormGroupChildIsSubmittingTracker": {
117
109
  "default": "./dist/esm/form/context/group/useFormGroupChildIsSubmittingTracker.mjs",
118
110
  "types": "./dist/types/form/context/group/useFormGroupChildIsSubmittingTracker.d.ts"
119
111
  },
112
+ "./form/context/group/useFormGroupChildTracker": {
113
+ "default": "./dist/esm/form/context/group/useFormGroupChildTracker.mjs",
114
+ "types": "./dist/types/form/context/group/useFormGroupChildTracker.d.ts"
115
+ },
120
116
  "./form/context/group/useFormGroupChildIsMountedTracker": {
121
117
  "default": "./dist/esm/form/context/group/useFormGroupChildIsMountedTracker.mjs",
122
118
  "types": "./dist/types/form/context/group/useFormGroupChildIsMountedTracker.d.ts"
@@ -1,14 +0,0 @@
1
- import { jsx as t } from "react/jsx-runtime";
2
- import i from "../../isEmptyObject.mjs";
3
- const l = ({ errors: r, ...e }) => i(r) ? null : /* @__PURE__ */ t("ul", { ...e, children: Object.values(r).map((o) => /* @__PURE__ */ t(
4
- "li",
5
- {
6
- role: "alert",
7
- "aria-live": "polite",
8
- children: o.message
9
- },
10
- JSON.stringify(o)
11
- )) }), n = l;
12
- export {
13
- n as default
14
- };
@@ -1,11 +0,0 @@
1
- import { jsx as t } from "react/jsx-runtime";
2
- import { useFormErrorsFlatContextMaybe as s } from "../context/index.mjs";
3
- import m from "./FormRootErrors.mjs";
4
- const u = () => {
5
- var o;
6
- const r = (o = s()) == null ? void 0 : o.roots;
7
- return r ? /* @__PURE__ */ t(m, { errors: r }) : null;
8
- };
9
- export {
10
- u as default
11
- };
@@ -1,63 +0,0 @@
1
- import { jsxs as C, jsx as t } from "react/jsx-runtime";
2
- import "react";
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,
14
- Fields: f,
15
- //
16
- onSubmit: d,
17
- onSubmitError: l,
18
- onSubmitInvalid: F,
19
- //
20
- options: r,
21
- //
22
- children: x,
23
- ...g
24
- }) {
25
- const m = O(), c = E(h);
26
- w(c, !(r != null && r.submitOnChange)), j(!(r != null && r.resetValuesOnSubmitError));
27
- const R = async (e) => {
28
- r != null && r.stopSubmitPropagation && e.stopPropagation();
29
- try {
30
- await m.handleSubmit(b, F)(e);
31
- } catch (a) {
32
- y(a, e);
33
- }
34
- }, b = (e, a) => d == null ? void 0 : d(
35
- e,
36
- m,
37
- a
38
- ), y = (e, a) => {
39
- V(e, m), l == null || l(e, m, a);
40
- };
41
- return /* @__PURE__ */ C(
42
- P,
43
- {
44
- id: u,
45
- onSubmit: R,
46
- noValidate: !0,
47
- style: {
48
- position: "relative"
49
- },
50
- ...g,
51
- ref: c,
52
- children: [
53
- (r == null ? void 0 : r.devTool) !== "disabled" && /* @__PURE__ */ t(v, { placement: "top-right", ...r == null ? void 0 : r.devTool }),
54
- f && /* @__PURE__ */ t(f, { ctx: m }),
55
- x,
56
- !(r != null && r.hideRootErrors) && /* @__PURE__ */ t(T, {})
57
- ]
58
- }
59
- );
60
- }
61
- export {
62
- G as default
63
- };
@@ -1,10 +0,0 @@
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,10 +0,0 @@
1
- import { jsx as o } from "react/jsx-runtime";
2
- import i from "../errors/context/provider.mjs";
3
- import m from "./useFormWithProviders.mjs";
4
- function s({ children: e, ...t }) {
5
- const r = m(t);
6
- return /* @__PURE__ */ o(r.Provider, { children: /* @__PURE__ */ o(i, { formRef: r.ref, children: /* @__PURE__ */ o(r.Form, { children: e }) }) });
7
- }
8
- export {
9
- s as default
10
- };
@@ -1,25 +0,0 @@
1
- import { jsx as r } from "react/jsx-runtime";
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
11
- }) {
12
- return /* @__PURE__ */ r(f, { ...i, children: /* @__PURE__ */ r(
13
- n,
14
- {
15
- formId: o,
16
- formRef: m,
17
- formProps: t,
18
- ...e,
19
- children: d
20
- }
21
- ) });
22
- }
23
- export {
24
- v as default
25
- };
@@ -1,28 +0,0 @@
1
- import { jsx as i } from "react/jsx-runtime";
2
- import "react";
3
- import s from "./context/FormProvider.mjs";
4
- import f from "./useForm.mjs";
5
- const d = ({
6
- rhf: t,
7
- form: o,
8
- utils: e
9
- }) => {
10
- const r = f({ rhf: t, form: o });
11
- return {
12
- ...r,
13
- Provider: ({ children: m }) => /* @__PURE__ */ i(
14
- s,
15
- {
16
- formRef: r.ref,
17
- rhf: r.context,
18
- formId: r.id,
19
- form: o,
20
- utils: e,
21
- children: m
22
- }
23
- )
24
- };
25
- }, P = d;
26
- export {
27
- P as default
28
- };
@@ -1,12 +0,0 @@
1
- import { FormSubmitError as m } from "./FormSubmitError.mjs";
2
- const n = (r, o) => {
3
- r instanceof m && Object.entries(r.errors).forEach(([t, e]) => {
4
- o.setError(t, {
5
- type: "FormSubmitError",
6
- message: e
7
- });
8
- });
9
- };
10
- export {
11
- n as default
12
- };
@@ -1,7 +0,0 @@
1
- import e from "react";
2
- function o(r) {
3
- return e.forwardRef(r);
4
- }
5
- export {
6
- o as default
7
- };
@@ -1,16 +0,0 @@
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
- };