@paragrav/rhf-utils 0.0.85 → 0.0.86

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.
@@ -1,81 +1,83 @@
1
- import { jsxs as T, jsx as u } from "react/jsx-runtime";
1
+ import { jsxs as S, jsx as C } from "react/jsx-runtime";
2
2
  import "react";
3
- import { useFormContext as _ } from "react-hook-form";
3
+ import { useFormContext as T } from "react-hook-form";
4
4
  import v from "../devtool/LazyDevTool.mjs";
5
5
  import { FormSubmitError as E } from "../submit/error/FormSubmitError.mjs";
6
6
  import V from "../submit/error/setCtxErrorsByFormSubmitError.mjs";
7
- import w from "./_FormBase.mjs";
8
- function H({
7
+ import w from "./_Controller.mjs";
8
+ import z from "./_FormBase.mjs";
9
+ function I({
9
10
  formId: B,
10
- formRef: x,
11
+ formRef: u,
11
12
  //
12
13
  onSubmit: s,
13
14
  onSubmitError: h,
14
15
  onSubmitInvalid: F,
15
- Fields: C,
16
+ Fields: x,
16
17
  //
17
18
  form: d,
18
- options: a,
19
- config: t,
19
+ options: r,
20
+ config: a,
20
21
  //
21
- children: j
22
+ children: _
22
23
  }) {
23
- const l = _(), N = async (r) => {
24
- a != null && a.stopSubmitPropagation && r.stopPropagation();
24
+ const l = T(), j = async (t) => {
25
+ r != null && r.stopSubmitPropagation && t.stopPropagation();
25
26
  try {
26
- await l.handleSubmit(P, F)(r);
27
+ await l.handleSubmit(N, F)(t);
27
28
  } catch (e) {
28
- S(e, r);
29
+ P(e, t);
29
30
  }
30
- }, P = (r, e) => s == null ? void 0 : s(
31
- r,
31
+ }, N = (t, e) => s == null ? void 0 : s(
32
+ t,
32
33
  l,
33
34
  e
34
- ), S = (r, e) => {
35
+ ), P = (t, e) => {
35
36
  var b;
36
- const m = r instanceof E ? (
37
+ const m = t instanceof E ? (
37
38
  // consumer can manually throw FormSubmitError (e.g., manual validation)
38
- r
39
+ t
39
40
  ) : (
40
41
  // if error is not FormSubmitError, consumer can provide global handler
41
- (b = t == null ? void 0 : t.onSubmitError) == null ? void 0 : b.call(t, r)
42
+ (b = a == null ? void 0 : a.onSubmitError) == null ? void 0 : b.call(a, t)
42
43
  );
43
44
  m && V(l, m), h == null || h(
44
- r,
45
+ t,
45
46
  l,
46
47
  e
47
48
  );
48
49
  }, c = {
49
50
  formId: B,
50
- formRef: x,
51
+ formRef: u,
51
52
  ctx: l,
52
- options: a
53
- }, y = (r) => {
53
+ options: r,
54
+ Controller: w
55
+ }, y = (t) => {
54
56
  var m;
55
- const e = (m = t == null ? void 0 : t.Children) == null ? void 0 : m[r];
56
- return e && /* @__PURE__ */ u(e, { ...c });
57
+ const e = (m = a == null ? void 0 : a.Children) == null ? void 0 : m[t];
58
+ return e && /* @__PURE__ */ C(e, { ...c });
57
59
  };
58
- return /* @__PURE__ */ T(
59
- w,
60
+ return /* @__PURE__ */ S(
61
+ z,
60
62
  {
61
63
  noValidate: !0,
62
64
  style: {
63
65
  position: "relative"
64
66
  },
65
67
  ...d,
66
- className: [a == null ? void 0 : a.classNames, d == null ? void 0 : d.className].filter(Boolean).join(" "),
67
- onSubmit: N,
68
- formRef: x,
68
+ className: [r == null ? void 0 : r.classNames, d == null ? void 0 : d.className].filter(Boolean).join(" "),
69
+ onSubmit: j,
70
+ formRef: u,
69
71
  children: [
70
72
  y("top"),
71
- (a == null ? void 0 : a.devTool) !== "disabled" && /* @__PURE__ */ u(v, { placement: "top-right", ...a == null ? void 0 : a.devTool }),
72
- C && /* @__PURE__ */ u(C, { ...c }),
73
- j,
73
+ (r == null ? void 0 : r.devTool) !== "disabled" && /* @__PURE__ */ C(v, { placement: "top-right", ...r == null ? void 0 : r.devTool }),
74
+ x && /* @__PURE__ */ C(x, { ...c }),
75
+ _,
74
76
  y("bottom")
75
77
  ]
76
78
  }
77
79
  );
78
80
  }
79
81
  export {
80
- H as default
82
+ I as default
81
83
  };
@@ -0,0 +1,9 @@
1
+ import { jsx as t } from "react/jsx-runtime";
2
+ import { useFormContext as n, Controller as e } from "react-hook-form";
3
+ function f(o) {
4
+ const { control: r } = n();
5
+ return /* @__PURE__ */ t(e, { control: r, ...o });
6
+ }
7
+ export {
8
+ f as default
9
+ };
@@ -1,21 +1,21 @@
1
- import t from "react";
2
- import { useForm as a } from "react-hook-form";
3
- import { FormSubmitError as l } from "../submit/error/FormSubmitError.mjs";
4
- const E = ({
5
- onSubmit: e,
6
- onSubmitError: m,
1
+ import m from "react";
2
+ import { useForm as F } from "react-hook-form";
3
+ import { FormSubmitError as a } from "../submit/error/FormSubmitError.mjs";
4
+ const I = ({
5
+ onSubmit: t,
6
+ onSubmitError: e,
7
7
  onSubmitInvalid: f,
8
- defaultValues: n,
9
- Fields: p,
8
+ defaultValues: p,
9
+ Fields: n,
10
10
  config: u,
11
11
  rhf: c,
12
12
  form: i,
13
13
  options: d
14
14
  }) => {
15
- const r = t.useId(), s = a({
15
+ const r = m.useId(), s = F({
16
16
  ...c,
17
- defaultValues: n
18
- }), o = t.useRef(null);
17
+ defaultValues: p
18
+ }), o = m.useRef(null);
19
19
  return {
20
20
  id: r,
21
21
  ref: o,
@@ -27,19 +27,18 @@ const E = ({
27
27
  options: d
28
28
  },
29
29
  formProps: {
30
- Fields: p,
31
- onSubmit: e,
32
- onSubmitError: m,
30
+ Fields: n,
31
+ onSubmit: t,
32
+ onSubmitError: e,
33
33
  onSubmitInvalid: f,
34
34
  formId: r,
35
35
  formRef: o,
36
36
  config: u,
37
37
  form: i
38
38
  },
39
- SubmitError: class extends l {
40
- }
39
+ FormSubmitError: a
41
40
  };
42
41
  };
43
42
  export {
44
- E as default
43
+ I as default
45
44
  };
@@ -17,7 +17,7 @@ export type CreateRhfUtilsClient<TObjectSchema extends ObjectSchema<TObjectSchem
17
17
  NonNullable<UseFormPropsForm['onSubmit']>,
18
18
  UseFormPropsForm['onSubmitError'],
19
19
  UseFormPropsForm['onSubmitInvalid']
20
- ], defaultValues: UseFormPropsForm['defaultValues'], Fields: UseFormPropsForm['Fields'], props: UseFormProps<TSchemaInput, TSchemaOutput>) => UseFormReturn<TSchemaInput, TSchemaOutput>;
20
+ ], defaultValues: UseFormPropsForm['defaultValues'], Fields: UseFormPropsForm['Fields'], props?: UseFormProps<TSchemaInput, TSchemaOutput>) => UseFormReturn<TSchemaInput, TSchemaOutput>;
21
21
  FormWithProviders: <TSchema extends TObjectSchema, TSchemaInput extends SafeFieldValues = TSchema[TObjectSchemaInputKey], TSchemaOutput extends SafeFieldValues = TSchema[TObjectSchemaOutputKey]>(props: {
22
22
  schema: TSchema;
23
23
  } & FormWithProvidersProps<TSchemaInput, TSchemaOutput>) => JSX.Element;
@@ -0,0 +1,6 @@
1
+ import { SafeFieldValues } from './SafeFieldValues';
2
+ import { ControllerProps, FieldPath } from 'react-hook-form';
3
+
4
+ export type _ControllerProps<TFieldValues extends SafeFieldValues, TName extends FieldPath<TFieldValues> = FieldPath<TFieldValues>> = Omit<ControllerProps<TFieldValues, TName>, 'control'>;
5
+ declare function _Controller<TFieldValues extends SafeFieldValues, TName extends FieldPath<TFieldValues> = FieldPath<TFieldValues>>(props: _ControllerProps<TFieldValues, TName>): import("react/jsx-runtime").JSX.Element;
6
+ export default _Controller;
@@ -2,6 +2,8 @@ import { UseFormOptions } from './useFormOptions';
2
2
  import { SafeFieldValues } from './SafeFieldValues';
3
3
  import { FormProvidersProps } from './FormProviders';
4
4
  import { FormProps } from './Form';
5
+ import { default as _Controller } from './_Controller';
6
+ import { FormSubmitError } from '../submit/error/FormSubmitError';
5
7
  import { ClientConfig } from '../client/config';
6
8
  import { SubmitErrorHandler, UseFormProps as RhfUseFormProps, UseFormReturn as RhfUseFormReturn } from 'react-hook-form';
7
9
  import { default as React } from 'react';
@@ -11,6 +13,7 @@ export type UseFormFieldsProps<TFieldValues extends SafeFieldValues = SafeFieldV
11
13
  formRef: React.RefObject<HTMLFormElement>;
12
14
  ctx: RhfUseFormReturn<TFieldValues, unknown, TTransformedValues>;
13
15
  options?: UseFormOptions;
16
+ Controller: typeof _Controller<TFieldValues>;
14
17
  };
15
18
  export type UseFormProps<TFieldValues extends SafeFieldValues, TTransformedValues extends SafeFieldValues> = {
16
19
  onSubmit?: (values: TTransformedValues, context: RhfUseFormReturn<TFieldValues, unknown, TTransformedValues>, event: React.BaseSyntheticEvent<SubmitEvent>) => unknown | Promise<unknown>;
@@ -27,6 +30,14 @@ export type UseFormProps<TFieldValues extends SafeFieldValues, TTransformedValue
27
30
  form?: React.PropsWithoutRef<JSX.IntrinsicElements['form']>;
28
31
  options?: UseFormOptions;
29
32
  };
33
+ export type UseFormReturn<TFieldValues extends SafeFieldValues, TTransformedValues extends SafeFieldValues> = {
34
+ id: string;
35
+ ref: React.RefObject<HTMLFormElement>;
36
+ context: RhfUseFormReturn<TFieldValues, unknown, TTransformedValues>;
37
+ providerProps: FormProvidersProps<TFieldValues, TTransformedValues>;
38
+ formProps: FormProps<TFieldValues, TTransformedValues>;
39
+ FormSubmitError: typeof FormSubmitError<TFieldValues>;
40
+ };
30
41
  /**
31
42
  * Core Rhf Form hook. Use `Form` in `index.ts` for most cases.
32
43
  * Use this if you need to separate form components.
@@ -36,30 +47,6 @@ export type UseFormProps<TFieldValues extends SafeFieldValues, TTransformedValue
36
47
  * see https://caniuse.com/?search=form%20attribute
37
48
  * @returns Form provider and form.
38
49
  */
39
- declare const useForm: <TFieldValues extends SafeFieldValues, TTransformedValues extends SafeFieldValues>({ onSubmit, onSubmitError, onSubmitInvalid, defaultValues, Fields, config, rhf, form, options, }: UseFormProps<TFieldValues, TTransformedValues>) => {
40
- readonly id: string;
41
- readonly ref: React.RefObject<HTMLFormElement>;
42
- readonly context: RhfUseFormReturn<TFieldValues, unknown, TTransformedValues>;
43
- readonly providerProps: FormProvidersProps<TFieldValues, TTransformedValues>;
44
- readonly formProps: FormProps<TFieldValues, TTransformedValues>;
45
- readonly SubmitError: {
46
- new (errors: Record<`root.${string}` | import('react-hook-form').Path<TFieldValues>, {
47
- type?: string | undefined;
48
- message: string;
49
- }>, message?: string | undefined): {
50
- errors: Record<`root.${string}` | import('react-hook-form').Path<TFieldValues>, {
51
- type?: string | undefined;
52
- message: string;
53
- }>;
54
- name: string;
55
- message: string;
56
- stack?: string | undefined;
57
- };
58
- captureStackTrace(targetObject: object, constructorOpt?: Function | undefined): void;
59
- prepareStackTrace?: ((err: Error, stackTraces: NodeJS.CallSite[]) => any) | undefined;
60
- stackTraceLimit: number;
61
- };
62
- };
50
+ declare const useForm: <TFieldValues extends SafeFieldValues, TTransformedValues extends SafeFieldValues>({ onSubmit, onSubmitError, onSubmitInvalid, defaultValues, Fields, config, rhf, form, options, }: UseFormProps<TFieldValues, TTransformedValues>) => UseFormReturn<TFieldValues, TTransformedValues>;
63
51
  export default useForm;
64
52
  export type UseForm<TFieldValues extends SafeFieldValues, TTransformedValues extends SafeFieldValues> = typeof useForm<TFieldValues, TTransformedValues>;
65
- export type UseFormReturn<TFieldValues extends SafeFieldValues, TTransformedValues extends SafeFieldValues> = ReturnType<UseForm<TFieldValues, TTransformedValues>>;
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.85",
5
+ "version": "0.0.86",
6
6
  "description": "Integration utilities for react-hook-form.",
7
7
  "type": "module",
8
8
  "sideEffects": false,