@paragrav/rhf-utils 0.0.142 → 0.0.144

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 (68) hide show
  1. package/README.md +6 -5
  2. package/dist/esm/index.mjs +19 -18
  3. package/dist/types/client/config/RhfUtilsClientConfig.d.ts +0 -1
  4. package/dist/types/client/config/useRhfUtilsClientConfigContext.d.ts +0 -1
  5. package/dist/types/client/context.d.ts +0 -1
  6. package/dist/types/client/index.d.ts +1 -2
  7. package/dist/types/client/utils.d.ts +0 -1
  8. package/dist/types/client/zod/RhfUtilsUseFormChildrenZodFC.d.ts +0 -1
  9. package/dist/types/client/zod/RhfUtilsUseFormChildrenZodProps.d.ts +0 -1
  10. package/dist/types/client/zod/ZodTypeFieldValues.d.ts +0 -1
  11. package/dist/types/client/zod/context/RhfUtilsClientForZodContextProvider.d.ts +0 -1
  12. package/dist/types/client/zod/context/RhfUtilsZodForm.d.ts +0 -1
  13. package/dist/types/client/zod/context/useRhfUtilsClientForZodContext.d.ts +0 -1
  14. package/dist/types/client/zod/context/useRhfUtilsZodForm.d.ts +1 -2
  15. package/dist/types/client/zod/createRhfUtilsClientForZod.d.ts +0 -1
  16. package/dist/types/devtool/LazyDevTool.d.ts +0 -1
  17. package/dist/types/errors/flat/FlatFieldErrorsList.d.ts +0 -1
  18. package/dist/types/errors/flat/context/FlatFieldErrorsContextProvider.d.ts +0 -1
  19. package/dist/types/errors/flat/context/FlatFieldErrorsOutputConfig.d.ts +0 -1
  20. package/dist/types/errors/flat/context/useFlatFieldErrorsContext.d.ts +0 -1
  21. package/dist/types/errors/flat/context/useFlatFieldErrorsContextOutput.d.ts +0 -1
  22. package/dist/types/errors/flat/filterFlatFieldErrors.d.ts +0 -1
  23. package/dist/types/errors/flat/flattenFieldErrors.d.ts +0 -1
  24. package/dist/types/errors/flat/getFlatFieldErrors.d.ts +0 -1
  25. package/dist/types/errors/flat/types.d.ts +0 -1
  26. package/dist/types/errors/isFieldErrorRefd.d.ts +0 -1
  27. package/dist/types/errors/isFlatFieldErrorEntryRefd.d.ts +0 -1
  28. package/dist/types/errors/message/FormErrorMessage.d.ts +0 -1
  29. package/dist/types/errors/nonfield/isNonFieldError.d.ts +0 -1
  30. package/dist/types/errors/orphan/getIsOrphanFormErrorWithParentElement.d.ts +0 -1
  31. package/dist/types/errors/orphan/getOrphansFromFlatFieldErrors.d.ts +0 -1
  32. package/dist/types/errors/orphan/isOrphanFormError.d.ts +0 -1
  33. package/dist/types/errors/output/consoleErrors.d.ts +0 -1
  34. package/dist/types/errors/root/isFlatFieldErrorEntryPathRoot.d.ts +0 -1
  35. package/dist/types/errors/trpc/makeOnSubmitTrpcClientErrorHandler.d.ts +0 -1
  36. package/dist/types/errors/trpc/trpcClientErrorMessageSchema.d.ts +0 -1
  37. package/dist/types/errors/trpc/trpcClientErrorToFormSubmitFieldErrorsSchemaTransformer.d.ts +3 -4
  38. package/dist/types/form/Form.d.ts +0 -1
  39. package/dist/types/form/FormWithProviders.d.ts +0 -1
  40. package/dist/types/form/RhfUtilsFormOptions.d.ts +0 -1
  41. package/dist/types/form/RhfUtilsFormProviders.d.ts +0 -1
  42. package/dist/types/form/UseRhfUtilsFormChildrenProps.d.ts +0 -1
  43. package/dist/types/form/UseRhfUtilsFormOnSubmitContext.d.ts +2 -1
  44. package/dist/types/form/UseRhfUtilsFormProps.d.ts +0 -1
  45. package/dist/types/form/UseRhfUtilsFormReturn.d.ts +0 -1
  46. package/dist/types/form/_Controller.d.ts +0 -1
  47. package/dist/types/form/context/group/FormGroupContextProvider.d.ts +0 -1
  48. package/dist/types/form/context/utils/RhfUtilsContextProvider.d.ts +0 -1
  49. package/dist/types/form/context/utils/useRhfUtilsContext.d.ts +0 -1
  50. package/dist/types/form/useRhfUtilsForm.d.ts +0 -1
  51. package/dist/types/form/utils/getSubmitterButtonData.d.ts +0 -1
  52. package/dist/types/form/utils/useFormRequestSubmit.d.ts +0 -1
  53. package/dist/types/form/utils/useShouldFormBlockNavigation.d.ts +0 -1
  54. package/dist/types/submit/error/FormSubmitError.d.ts +0 -1
  55. package/dist/types/submit/error/FormSubmitFieldErrors.d.ts +0 -1
  56. package/dist/types/submit/error/setCtxErrorsByFormSubmitFieldErrors.d.ts +0 -1
  57. package/dist/types/submit/useFormOnSubmitSuccessfulAndReset.d.ts +0 -1
  58. package/dist/types/submit/useFormOnSubmitted.d.ts +0 -1
  59. package/dist/types/submit/useSubmitFormOnChange.d.ts +0 -1
  60. package/dist/types/utils/createContext.d.ts +0 -1
  61. package/dist/types/utils/fixedForwardRef.d.ts +1 -2
  62. package/dist/types/utils/useImperativeForwardedRef.d.ts +0 -1
  63. package/dist/types/utils/useToggle.d.ts +0 -1
  64. package/package.json +1 -1
  65. package/dist/types/_exports/main.d.ts +0 -15
  66. package/dist/types/group.d.ts +0 -29
  67. package/dist/types/trpc.d.ts +0 -8
  68. package/dist/types/utils.d.ts +0 -5
package/README.md CHANGED
@@ -69,7 +69,7 @@ export const rhfUtilsClientConfig: RhfUtilsClientConfig = {
69
69
  // optional form component (defaults to primitive HTML form)
70
70
  FormComponent: Form.Root,
71
71
 
72
- // optional wrapper to inject your own hooks and components
72
+ // optional wrapper component to inject your own hooks and components
73
73
  // around all RhfUtilsZodForm instances
74
74
  FormChildrenWrapper: (
75
75
  // UseRhfUtilsFormChildrenProps
@@ -93,7 +93,7 @@ export const rhfUtilsClientConfig: RhfUtilsClientConfig = {
93
93
 
94
94
  return (
95
95
  <>
96
- {/* RhfUtilsZodForm.Children outlet (see "Component Hierarchy" section) */}
96
+ {/* RhfUtilsZodForm.Children "outlet" (see "Component Hierarchy" section) */}
97
97
  {children}
98
98
 
99
99
  {/* root errors list */}
@@ -103,7 +103,7 @@ export const rhfUtilsClientConfig: RhfUtilsClientConfig = {
103
103
  },
104
104
 
105
105
  // non-FormSubmitError thrown in onSubmit
106
- // use case: handle and transform error data for frontend
106
+ // use case: handle and transform server error data for frontend
107
107
  onSubmitErrorUnknown: (
108
108
  error, // unknown
109
109
  ) => {
@@ -166,7 +166,7 @@ Currently, only `zod` is supported.
166
166
  // handle error declaratively (i.e., no throw/catch)
167
167
  onSubmitError={({
168
168
  error, // unknown
169
- context, // UseRhfUtilsFormOnSubmitErrorContext (id, ref, rhf context, utils options)
169
+ context, // UseRhfUtilsFormOnSubmitErrorContext (id, ref, rhf context, utils options, `FormSubmitFieldErrors` from `onSubmitErrorUnknown`)
170
170
  event, // SubmitEvent
171
171
  }) => {
172
172
  props.onError(error);
@@ -309,8 +309,9 @@ import '@paragrav/rhf-utils';
309
309
  declare module '@paragrav/rhf-utils' {
310
310
  export interface Register {
311
311
  RhfUtilsFormOptions: {
312
- /** Enable user prompt to confirm navigating away from dirty form. */
312
+ /** Custom props for your custom hooks/behaviors. */
313
313
  enableMyOptionalFormHook?: boolean;
314
+ configMyOptionalFormHook?: MyCustomFormHookConfig;
314
315
  };
315
316
  }
316
317
  }
@@ -1,6 +1,6 @@
1
1
  import { jsx as i, Fragment as B, jsxs as Z } from "react/jsx-runtime";
2
2
  import a from "react";
3
- import { c as E } from "./createContext.mjs";
3
+ import { c as C } from "./createContext.mjs";
4
4
  import { zodResolver as I } from "@hookform/resolvers/zod";
5
5
  import { useFormContext as b, Controller as L, get as z, useFormState as x, FormProvider as A, useForm as $ } from "react-hook-form";
6
6
  import { i as O, _ as H, u as g } from "./useFlatFieldErrorsContext.mjs";
@@ -8,7 +8,7 @@ import { flatten as Q } from "flat";
8
8
  const {
9
9
  Provider: G,
10
10
  useMaybe: _
11
- } = E(), J = a.lazy(
11
+ } = C(), J = a.lazy(
12
12
  () => import("@hookform/devtools").then((r) => ({
13
13
  default: r.DevTool
14
14
  }))
@@ -51,11 +51,11 @@ function er({
51
51
  const m = b(), d = _(), c = async (h) => {
52
52
  u != null && u.stopSubmitPropagation && h.stopPropagation();
53
53
  try {
54
- await m.handleSubmit(v, s)(h);
54
+ await m.handleSubmit(p, s)(h);
55
55
  } catch (f) {
56
- p(f, h);
56
+ P(f, h);
57
57
  }
58
- }, v = (h, f) => e == null ? void 0 : e(
58
+ }, p = (h, f) => e == null ? void 0 : e(
59
59
  h,
60
60
  {
61
61
  formId: r,
@@ -65,33 +65,34 @@ function er({
65
65
  FormSubmitError: F
66
66
  },
67
67
  f
68
- ), p = (h, f) => {
68
+ ), P = (h, f) => {
69
69
  var y;
70
- const R = h instanceof F ? (
70
+ const E = h instanceof F ? (
71
71
  // consumer can manually throw FormSubmitError (e.g., manual validation)
72
72
  h.errors
73
73
  ) : (
74
74
  // if error is not FormSubmitError, consumer can provide global handler
75
75
  (y = d == null ? void 0 : d.onSubmitErrorUnknown) == null ? void 0 : y.call(d, h)
76
76
  );
77
- R && X(m, R), o == null || o(
77
+ E && X(m, E), o == null || o(
78
78
  h,
79
79
  {
80
80
  formId: r,
81
81
  formRef: t,
82
82
  context: m,
83
- utils: u
83
+ utils: u,
84
+ errors: E
84
85
  },
85
86
  f
86
87
  );
87
- }, P = {
88
+ }, R = {
88
89
  formId: r,
89
90
  formRef: t,
90
91
  context: m,
91
92
  utils: u,
92
93
  Controller: rr,
93
94
  FormSubmitError: F
94
- }, V = P, N = (d == null ? void 0 : d.FormComponent) ?? "form", q = (d == null ? void 0 : d.FormChildrenWrapper) ?? Y;
95
+ }, V = R, N = (d == null ? void 0 : d.FormComponent) ?? "form", q = (d == null ? void 0 : d.FormChildrenWrapper) ?? Y;
95
96
  return /* @__PURE__ */ i(
96
97
  N,
97
98
  {
@@ -106,18 +107,18 @@ function er({
106
107
  props: typeof (u == null ? void 0 : u.devTool) == "object" ? u.devTool : void 0
107
108
  }
108
109
  ),
109
- /* @__PURE__ */ i(n, { ...P })
110
+ /* @__PURE__ */ i(n, { ...R })
110
111
  ] })
111
112
  }
112
113
  );
113
114
  }
114
- const C = (r) => (t) => (
115
+ const v = (r) => (t) => (
115
116
  // re-create object from entries
116
117
  Object.fromEntries(
117
118
  // break down to entries
118
119
  Object.entries(t).filter(r)
119
120
  )
120
- ), k = (r) => !!r.ref, tr = ([, r]) => k(r), or = C(
121
+ ), k = (r) => !!r.ref, tr = ([, r]) => k(r), or = v(
121
122
  tr
122
123
  ), W = "data-rhfutils-nonfield-error-marker-path", sr = (r, t) => (
123
124
  // list of selector variants
@@ -144,9 +145,9 @@ const C = (r) => (t) => (
144
145
  !k(t) && // non-root
145
146
  !j(r) && // not marked in DOM
146
147
  !ur(r, e)
147
- ), ir = (r) => ([t, e]) => lr(t, e, r), dr = (r, t) => C(
148
+ ), ir = (r) => ([t, e]) => lr(t, e, r), dr = (r, t) => v(
148
149
  ir(t)
149
- )(r), ar = ([r]) => j(r), mr = C(
150
+ )(r), ar = ([r]) => j(r), mr = v(
150
151
  ar
151
152
  ), hr = (r) => Q(r), cr = (r) => {
152
153
  const t = hr(r), e = Object.keys(t);
@@ -289,7 +290,7 @@ const C = (r) => (t) => (
289
290
  n.removeEventListener("change", l);
290
291
  };
291
292
  }, []);
292
- }, { Provider: Sr, useRequired: Ur } = E(), Zr = Ur, xr = ({
293
+ }, { Provider: Sr, useRequired: Ur } = C(), Zr = Ur, xr = ({
293
294
  formId: r,
294
295
  formRef: t,
295
296
  options: e,
@@ -438,7 +439,7 @@ const _r = (r, ...t) => (
438
439
  }, jr = kr(I), {
439
440
  Provider: wr,
440
441
  useRequired: D
441
- } = E(), Ir = ({
442
+ } = C(), Ir = ({
442
443
  config: r,
443
444
  children: t
444
445
  }) => {
@@ -3,7 +3,6 @@ import { FlatFieldErrorsOutputConfig } from '../../errors/flat/context/FlatField
3
3
  import { RhfUtilsFormOptions } from '../../form/RhfUtilsFormOptions';
4
4
  import { UseRhfUtilsFormChildrenProps } from '../../form/UseRhfUtilsFormChildrenProps';
5
5
  import { FormSubmitFieldErrors } from '../../submit/error/FormSubmitFieldErrors';
6
-
7
6
  /**
8
7
  * Client configuration object.
9
8
  *
@@ -1,5 +1,4 @@
1
1
  import { RhfUtilsClientConfig } from './RhfUtilsClientConfig';
2
-
3
2
  declare const _RhfUtilsClientConfigContextProvider: import('react').Provider<RhfUtilsClientConfig | undefined>, useRhfUtilsClientConfigMaybeContext: () => RhfUtilsClientConfig | undefined;
4
3
  export default useRhfUtilsClientConfigMaybeContext;
5
4
  export { _RhfUtilsClientConfigContextProvider };
@@ -1,3 +1,2 @@
1
1
  import { CreateRhfUtilsClient, ObjectSchema } from '.';
2
-
3
2
  export type RhfUtilsClientContext<TObjectSchema extends ObjectSchema<TObjectSchemaInputKey, TObjectSchemaOutputKey>, TObjectSchemaInputKey extends string, TObjectSchemaOutputKey extends string> = CreateRhfUtilsClient<TObjectSchema, TObjectSchemaInputKey, TObjectSchemaOutputKey>;
@@ -5,7 +5,6 @@ import { FormWithProvidersProps } from '../form/FormWithProviders';
5
5
  import { SafeFieldValues } from '../form/SafeFieldValues';
6
6
  import { UseRhfUtilsFormProps } from '../form/UseRhfUtilsFormProps';
7
7
  import { UseRhfUtilsFormReturn } from '../form/UseRhfUtilsFormReturn';
8
-
9
8
  /**
10
9
  * Generic object schema type.
11
10
  */
@@ -15,7 +14,7 @@ export type ObjectSchema<TInputKey extends string, TOutputKey extends string> =
15
14
  [key in TOutputKey]: SafeFieldValues;
16
15
  };
17
16
  export type CreateRhfUtilsClient<TObjectSchema extends ObjectSchema<TObjectSchemaInputKey, TObjectSchemaOutputKey>, TObjectSchemaInputKey extends string, TObjectSchemaOutputKey extends string> = {
18
- useForm: <TSchema extends TObjectSchema, TSchemaInput extends SafeFieldValues = TSchema[TObjectSchemaInputKey], TSchemaOutput extends SafeFieldValues = TSchema[TObjectSchemaOutputKey], UseRhfUtilsFormPropsForm extends UseRhfUtilsFormProps<TSchemaInput, TSchemaOutput> = UseRhfUtilsFormProps<TSchemaInput, TSchemaOutput>>(schema: TSchema, form: UseRhfUtilsFormPropsForm) => UseRhfUtilsFormReturn<TSchemaInput, TSchemaOutput> & {
17
+ useForm: <TSchema extends TObjectSchema, TSchemaInput extends SafeFieldValues = TSchema[TObjectSchemaInputKey], TSchemaOutput extends SafeFieldValues = TSchema[TObjectSchemaOutputKey]>(schema: TSchema, form: UseRhfUtilsFormProps<TSchemaInput, TSchemaOutput>) => UseRhfUtilsFormReturn<TSchemaInput, TSchemaOutput> & {
19
18
  FormWithProviders: React.FC<React.PropsWithChildren>;
20
19
  };
21
20
  FormWithProviders: <TSchema extends TObjectSchema, TSchemaInput extends SafeFieldValues = TSchema[TObjectSchemaInputKey], TSchemaOutput extends SafeFieldValues = TSchema[TObjectSchemaOutputKey]>(props: {
@@ -2,7 +2,6 @@ import { RhfUtilsFormOptions } from '../form/RhfUtilsFormOptions';
2
2
  import { SafeFieldValues } from '../form/SafeFieldValues';
3
3
  import { UseRhfUtilsFormProps } from '../form/UseRhfUtilsFormProps';
4
4
  import { RhfUtilsClientConfig } from './config/RhfUtilsClientConfig';
5
-
6
5
  /**
7
6
  * Merge {@link RhfUtilsClientConfig.defaults} with array of {@link UseRhfUtilsFormProps}'s overrides.
8
7
  */
@@ -1,7 +1,6 @@
1
1
  import { default as React } from 'react';
2
2
  import { RhfUtilsUseFormChildrenZodProps } from './RhfUtilsUseFormChildrenZodProps';
3
3
  import { ZodTypeFieldValues } from './ZodTypeFieldValues';
4
-
5
4
  /**
6
5
  * {@link React.FC} for {@link RhfUtilsUseFormChildrenZodProps}.
7
6
  *
@@ -1,5 +1,4 @@
1
1
  import { UseRhfUtilsFormChildrenProps } from '../../form/UseRhfUtilsFormChildrenProps';
2
2
  import { zodTypeInput, zodTypeOutput } from './consts';
3
3
  import { ZodTypeFieldValues } from './ZodTypeFieldValues';
4
-
5
4
  export type RhfUtilsUseFormChildrenZodProps<TSchema extends ZodTypeFieldValues> = UseRhfUtilsFormChildrenProps<TSchema[typeof zodTypeInput], TSchema[typeof zodTypeOutput]>;
@@ -1,4 +1,3 @@
1
1
  import { z } from 'zod';
2
2
  import { SafeFieldValues } from '../../form/SafeFieldValues';
3
-
4
3
  export type ZodTypeFieldValues = z.ZodType<SafeFieldValues>;
@@ -1,6 +1,5 @@
1
1
  import { default as React } from 'react';
2
2
  import { RhfUtilsClientConfig } from '../../config/RhfUtilsClientConfig';
3
-
4
3
  type Props = React.PropsWithChildren<{
5
4
  config?: RhfUtilsClientConfig;
6
5
  }>;
@@ -1,7 +1,6 @@
1
1
  import { UseRhfUtilsFormProps } from '../../../form/UseRhfUtilsFormProps';
2
2
  import { zodTypeInput, zodTypeOutput } from '../consts';
3
3
  import { ZodTypeFieldValues } from '../ZodTypeFieldValues';
4
-
5
4
  type Props<TSchema extends ZodTypeFieldValues> = {
6
5
  schema: TSchema;
7
6
  } & UseRhfUtilsFormProps<TSchema[typeof zodTypeInput], TSchema[typeof zodTypeOutput]>;
@@ -1,5 +1,4 @@
1
1
  import { default as createRhfUtilsClientForZod } from '../createRhfUtilsClientForZod';
2
-
3
2
  export type RhfUtilsClientForZodContext = ReturnType<typeof createRhfUtilsClientForZod>;
4
3
  declare const _RhfUtilsClientForZodContextProvider: import('react').Provider<import('../..').CreateRhfUtilsClient<import('../ZodTypeFieldValues').ZodTypeFieldValues, "_input", "_output"> | undefined>, useRhfUtilsClientForZodContext: () => import('../..').CreateRhfUtilsClient<import('../ZodTypeFieldValues').ZodTypeFieldValues, "_input", "_output">;
5
4
  export default useRhfUtilsClientForZodContext;
@@ -1,8 +1,7 @@
1
1
  import { UseRhfUtilsFormProps } from '../../../form/UseRhfUtilsFormProps';
2
2
  import { zodTypeInput, zodTypeOutput } from '../consts';
3
3
  import { ZodTypeFieldValues } from '../ZodTypeFieldValues';
4
-
5
4
  declare const useRhfUtilsZodForm: <TSchema extends ZodTypeFieldValues>(schema: TSchema, form: UseRhfUtilsFormProps<TSchema[typeof zodTypeInput], TSchema[typeof zodTypeOutput]>) => import('../../../form/UseRhfUtilsFormReturn').UseRhfUtilsFormReturn<TSchema["_input"], TSchema["_output"]> & {
6
- FormWithProviders: import('react').FC<import('react').PropsWithChildren>;
5
+ FormWithProviders: React.FC<React.PropsWithChildren>;
7
6
  };
8
7
  export default useRhfUtilsZodForm;
@@ -1,4 +1,3 @@
1
1
  import { ZodTypeFieldValues } from './ZodTypeFieldValues';
2
-
3
2
  declare const createRhfUtilsClientForZod: (config: import('../config/RhfUtilsClientConfig').RhfUtilsClientConfig) => import('..').CreateRhfUtilsClient<ZodTypeFieldValues, "_input", "_output">;
4
3
  export default createRhfUtilsClientForZod;
@@ -1,6 +1,5 @@
1
1
  import { DevtoolUIProps } from '@hookform/devtools/dist/devToolUI';
2
2
  import { default as React } from 'react';
3
-
4
3
  type LazyDevToolProps = {
5
4
  enabled?: boolean;
6
5
  props?: Omit<DevtoolUIProps, 'control'>;
@@ -1,5 +1,4 @@
1
1
  import { FlatFieldErrors } from './types';
2
-
3
2
  export type Props = {
4
3
  errors: FlatFieldErrors | null | undefined;
5
4
  };
@@ -1,5 +1,4 @@
1
1
  import { default as React } from 'react';
2
-
3
2
  type Props = React.PropsWithChildren<{
4
3
  formRef: React.RefObject<HTMLFormElement>;
5
4
  }>;
@@ -1,6 +1,5 @@
1
1
  import { RhfUtilsErrorsOutputConsoleConfig } from '../../output/types';
2
2
  import { FlatFieldErrorsContext } from './useFlatFieldErrorsContext';
3
-
4
3
  export type FlatFieldErrorsOutputConfig = {
5
4
  /**
6
5
  * Configure how/if errors should be outputted to console.
@@ -1,5 +1,4 @@
1
1
  import { FlatFieldErrors } from '../types';
2
-
3
2
  export type FlatFieldErrorsContext = {
4
3
  all: FlatFieldErrors;
5
4
  fields: FlatFieldErrors;
@@ -1,5 +1,4 @@
1
1
  import { FlatFieldErrorsOutputConfig } from './FlatFieldErrorsOutputConfig';
2
-
3
2
  /**
4
3
  * Outputs (e.g., console, throw) errors based on config.
5
4
  */
@@ -1,5 +1,4 @@
1
1
  import { FlatFieldErrorEntry, FlatFieldErrors } from './types';
2
-
3
2
  /**
4
3
  * Filter {@link FlatFieldErrors} by a predicate.
5
4
  *
@@ -1,5 +1,4 @@
1
1
  import { FieldErrors } from 'react-hook-form';
2
-
3
2
  /**
4
3
  * Flatten a {@link FieldErrors} object.
5
4
  *
@@ -1,6 +1,5 @@
1
1
  import { FieldErrors } from 'react-hook-form';
2
2
  import { FlatFieldErrors } from './types';
3
-
4
3
  /**
5
4
  * Get {@link FlatFieldErrors} from {@link FieldErrors}.
6
5
  * This makes it easy to work with potentially deeply-nested {@link FieldErrors}.
@@ -1,5 +1,4 @@
1
1
  import { FieldError } from 'react-hook-form';
2
-
3
2
  /**
4
3
  * Flattened field errors object.
5
4
  *
@@ -1,5 +1,4 @@
1
1
  import { FieldError } from 'react-hook-form';
2
-
3
2
  /**
4
3
  * Determine if {@link FieldError} is a `ref`'d field error.
5
4
  */
@@ -1,5 +1,4 @@
1
1
  import { FlatFieldErrorEntry } from './flat/types';
2
-
3
2
  /**
4
3
  * Determine if {@link FieldError} is a `ref`'d field error.
5
4
  */
@@ -1,5 +1,4 @@
1
1
  import { default as React } from 'react';
2
-
3
2
  type Props = {
4
3
  message: string;
5
4
  className?: string;
@@ -1,5 +1,4 @@
1
1
  import { FieldError } from 'react-hook-form';
2
-
3
2
  /**
4
3
  * Determine if {@link FieldError} is a non-field error (i.e., has no `ref`).
5
4
  *
@@ -1,5 +1,4 @@
1
1
  import { FlatFieldErrorEntry } from '../flat/types';
2
-
3
2
  /**
4
3
  * Util wrapper for {@link isOrphanFormError} for usage with {@link FlatFieldErrorEntry}.
5
4
  */
@@ -1,4 +1,3 @@
1
1
  import { FlatFieldErrors } from '../flat/types';
2
-
3
2
  declare const getOrphansFromFlatFieldErrors: (errors: FlatFieldErrors, parentElement: Pick<HTMLElement, "querySelector">) => FlatFieldErrors;
4
3
  export default getOrphansFromFlatFieldErrors;
@@ -1,4 +1,3 @@
1
1
  import { FieldError } from 'react-hook-form';
2
-
3
2
  declare const isOrphanFormError: (path: string, error: FieldError, parentElement: Pick<HTMLElement, "querySelector">) => boolean;
4
3
  export default isOrphanFormError;
@@ -1,5 +1,4 @@
1
1
  import { SafeFieldValues } from '../../form/SafeFieldValues';
2
-
3
2
  /**
4
3
  * Output form values and errors to console.
5
4
  */
@@ -1,5 +1,4 @@
1
1
  import { FlatFieldErrorEntry } from '../flat/types';
2
-
3
2
  /**
4
3
  * Util wrapper for {@link isFormErrorPathRoot} for usage with {@link FlatFieldErrorEntry}.
5
4
  */
@@ -1,6 +1,5 @@
1
1
  import { RhfUtilsClientConfig } from '../../client/config/RhfUtilsClientConfig';
2
2
  import { FormSubmitFieldErrors } from '../../submit/error/FormSubmitFieldErrors';
3
-
4
3
  /**
5
4
  * HOF that returns submit error handler for {@link RhfUtilsClientConfig.onSubmitErrorUnknown}.
6
5
  *
@@ -1,5 +1,4 @@
1
1
  import { z } from 'zod';
2
-
3
2
  /**
4
3
  * Schema for {@link TRPCClientError} message.
5
4
  *
@@ -1,12 +1,11 @@
1
1
  import { TRPCClientErrorLike } from '@trpc/client';
2
- import { AnyRouter } from '@trpc/server';
2
+ import { AnyTRPCRouter } from '@trpc/server';
3
3
  import { z } from 'zod';
4
4
  import { FormSubmitFieldErrors } from '../../submit/error/FormSubmitFieldErrors';
5
-
6
5
  /**
7
6
  * Schema that transforms {@link TRPCClientError} to RHF {@link FormSubmitFieldErrors}.
8
7
  */
9
- declare const trpcClientErrorToFormSubmitFieldErrorsSchemaTransformer: z.ZodEffects<z.ZodEffects<z.ZodPipeline<z.ZodEffects<z.ZodEffects<z.ZodType<TRPCClientErrorLike<AnyRouter>, z.ZodTypeDef, TRPCClientErrorLike<AnyRouter>>, string, TRPCClientErrorLike<AnyRouter>>, unknown, TRPCClientErrorLike<AnyRouter>>, z.ZodArray<z.ZodObject<{
8
+ declare const trpcClientErrorToFormSubmitFieldErrorsSchemaTransformer: z.ZodEffects<z.ZodEffects<z.ZodPipeline<z.ZodEffects<z.ZodEffects<z.ZodType<TRPCClientErrorLike<AnyTRPCRouter>, z.ZodTypeDef, TRPCClientErrorLike<AnyTRPCRouter>>, string, TRPCClientErrorLike<AnyTRPCRouter>>, unknown, TRPCClientErrorLike<AnyTRPCRouter>>, z.ZodArray<z.ZodObject<{
10
9
  validation: z.ZodString;
11
10
  code: z.ZodString;
12
11
  message: z.ZodString;
@@ -24,5 +23,5 @@ declare const trpcClientErrorToFormSubmitFieldErrorsSchemaTransformer: z.ZodEffe
24
23
  }>, "many">>, (readonly [string, {
25
24
  type: string;
26
25
  message: string;
27
- }])[], TRPCClientErrorLike<AnyRouter>>, FormSubmitFieldErrors, TRPCClientErrorLike<AnyRouter>>;
26
+ }])[], TRPCClientErrorLike<AnyTRPCRouter>>, FormSubmitFieldErrors, TRPCClientErrorLike<AnyTRPCRouter>>;
28
27
  export default trpcClientErrorToFormSubmitFieldErrorsSchemaTransformer;
@@ -1,7 +1,6 @@
1
1
  import { default as React } from 'react';
2
2
  import { SafeFieldValues } from './SafeFieldValues';
3
3
  import { UseRhfUtilsFormProps } from './UseRhfUtilsFormProps';
4
-
5
4
  export type FormChildrenSlots = 'top' | 'bottom';
6
5
  export type FormProps<TFieldValues extends SafeFieldValues, TTransformedValues extends SafeFieldValues> = {
7
6
  formId: string;
@@ -1,6 +1,5 @@
1
1
  import { SafeFieldValues } from './SafeFieldValues';
2
2
  import { UseRhfUtilsFormProps } from './UseRhfUtilsFormProps';
3
-
4
3
  export type FormWithProvidersProps<TFieldValues extends SafeFieldValues, TTransformedValues extends SafeFieldValues> = React.PropsWithChildren<UseRhfUtilsFormProps<TFieldValues, TTransformedValues>>;
5
4
  /**
6
5
  * Form providers (with utils) with immediate descendent {@link Form}.
@@ -1,7 +1,6 @@
1
1
  import { DevtoolUIProps } from '@hookform/devtools/dist/devToolUI';
2
2
  import { UseResetFormOnSubmittedOptions } from '../submit/useResetFormOnSubmitted';
3
3
  import { Register } from '../register';
4
-
5
4
  /**
6
5
  * Options for enabling utils functionality provided by this library.
7
6
  *
@@ -1,7 +1,6 @@
1
1
  import { UseFormReturn } from 'react-hook-form';
2
2
  import { RhfUtilsFormOptions } from './RhfUtilsFormOptions';
3
3
  import { SafeFieldValues } from './SafeFieldValues';
4
-
5
4
  export type RhfUtilsFormProvidersProps<TFieldValues extends SafeFieldValues, TTransformedValues extends SafeFieldValues> = React.PropsWithChildren<{
6
5
  formId: string;
7
6
  formRef: React.RefObject<HTMLFormElement>;
@@ -4,7 +4,6 @@ import { FormSubmitError } from '../submit/error/FormSubmitError';
4
4
  import { default as _Controller } from './_Controller';
5
5
  import { RhfUtilsFormOptions } from './RhfUtilsFormOptions';
6
6
  import { SafeFieldValues } from './SafeFieldValues';
7
-
8
7
  /**
9
8
  * Component props for `Children`.
10
9
  *
@@ -1,9 +1,9 @@
1
1
  import { default as React } from 'react';
2
2
  import { UseFormReturn } from 'react-hook-form';
3
3
  import { FormSubmitError } from '../submit/error/FormSubmitError';
4
+ import { FormSubmitFieldErrors } from '../submit/error/FormSubmitFieldErrors';
4
5
  import { RhfUtilsFormOptions } from './RhfUtilsFormOptions';
5
6
  import { SafeFieldValues } from './SafeFieldValues';
6
-
7
7
  /**
8
8
  * Props for onSubmit other than `data` and `event`.
9
9
  *
@@ -24,4 +24,5 @@ export type UseRhfUtilsFormOnSubmitErrorContext<TFieldValues extends SafeFieldVa
24
24
  formRef: React.RefObject<HTMLFormElement>;
25
25
  context: UseFormReturn<TFieldValues, unknown, TTransformedValues>;
26
26
  utils?: RhfUtilsFormOptions;
27
+ errors?: FormSubmitFieldErrors;
27
28
  };
@@ -5,7 +5,6 @@ import { RhfUtilsFormOptions } from './RhfUtilsFormOptions';
5
5
  import { SafeFieldValues } from './SafeFieldValues';
6
6
  import { UseRhfUtilsFormChildrenProps } from './UseRhfUtilsFormChildrenProps';
7
7
  import { UseRhfUtilsFormOnSubmitContext, UseRhfUtilsFormOnSubmitErrorContext } from './UseRhfUtilsFormOnSubmitContext';
8
-
9
8
  export type UseRhfUtilsFormProps<TFieldValues extends SafeFieldValues, TTransformedValues extends SafeFieldValues> = {
10
9
  defaultValues?: UseFormProps<TFieldValues>['defaultValues'];
11
10
  onSubmit?: (values: TTransformedValues, context: UseRhfUtilsFormOnSubmitContext<TFieldValues, TTransformedValues>, event: React.BaseSyntheticEvent<SubmitEvent>) => MaybePromise<unknown>;
@@ -4,7 +4,6 @@ import { FormSubmitError } from '../submit/error/FormSubmitError';
4
4
  import { FormProps } from './Form';
5
5
  import { RhfUtilsFormProvidersProps } from './RhfUtilsFormProviders';
6
6
  import { SafeFieldValues } from './SafeFieldValues';
7
-
8
7
  /**
9
8
  * Return type for `useRhfUtilsForm`.
10
9
  *
@@ -1,6 +1,5 @@
1
1
  import { ControllerProps, FieldPath } from 'react-hook-form';
2
2
  import { SafeFieldValues } from './SafeFieldValues';
3
-
4
3
  export type _ControllerProps<TFieldValues extends SafeFieldValues, TName extends FieldPath<TFieldValues> = FieldPath<TFieldValues>> = Omit<ControllerProps<TFieldValues, TName>, 'control'>;
5
4
  declare function _Controller<TFieldValues extends SafeFieldValues, TName extends FieldPath<TFieldValues> = FieldPath<TFieldValues>>(props: _ControllerProps<TFieldValues, TName>): import("react/jsx-runtime").JSX.Element;
6
5
  export default _Controller;
@@ -1,5 +1,4 @@
1
1
  import { default as React } from 'react';
2
-
3
2
  type Props = React.PropsWithChildren;
4
3
  declare const FormGroupContextProvider: React.FC<Props>;
5
4
  export default FormGroupContextProvider;
@@ -1,5 +1,4 @@
1
1
  import { RhfUtilsFormOptions } from '../../RhfUtilsFormOptions';
2
-
3
2
  type Props = React.PropsWithChildren<{
4
3
  formId: string;
5
4
  formRef: React.RefObject<HTMLFormElement>;
@@ -1,5 +1,4 @@
1
1
  import { RhfUtilsFormOptions } from '../../RhfUtilsFormOptions';
2
-
3
2
  export type RhfUtilsContext = {
4
3
  formId: string;
5
4
  formRef: React.RefObject<HTMLFormElement>;
@@ -1,7 +1,6 @@
1
1
  import { SafeFieldValues } from './SafeFieldValues';
2
2
  import { UseRhfUtilsFormProps } from './UseRhfUtilsFormProps';
3
3
  import { UseRhfUtilsFormReturn } from './UseRhfUtilsFormReturn';
4
-
5
4
  /**
6
5
  * Core Rhf Form hook. Use `Form` in `index.ts` for most cases.
7
6
  * Use this if you need to separate form components.
@@ -1,5 +1,4 @@
1
1
  import { default as React } from 'react';
2
-
3
2
  /**
4
3
  * Get [name, value] tuple of button/input that submitted form.
5
4
  * Useful when determining user intent
@@ -1,5 +1,4 @@
1
1
  import { default as React } from 'react';
2
-
3
2
  /**
4
3
  * Get callback to trigger submit manually on form.
5
4
  *
@@ -1,5 +1,4 @@
1
1
  import { FieldValues, FormState } from 'react-hook-form';
2
-
3
2
  export type UseShouldFormBlockNavigationOptions = {
4
3
  disabled?: boolean;
5
4
  /**
@@ -1,6 +1,5 @@
1
1
  import { SafeFieldValues } from '../../form/SafeFieldValues';
2
2
  import { FormSubmitFieldErrors } from './FormSubmitFieldErrors';
3
-
4
3
  export declare class FormSubmitError<TFieldValues extends SafeFieldValues = SafeFieldValues> extends Error {
5
4
  errors: FormSubmitFieldErrors<TFieldValues>;
6
5
  constructor(errors: FormSubmitFieldErrors<TFieldValues>, message?: string);
@@ -1,6 +1,5 @@
1
1
  import { FieldPath } from 'react-hook-form';
2
2
  import { SafeFieldValues } from '../../form/SafeFieldValues';
3
-
4
3
  /**
5
4
  * Field errors structure based on RHF's `FieldErrors`.
6
5
  *
@@ -1,7 +1,6 @@
1
1
  import { UseFormReturn } from 'react-hook-form';
2
2
  import { SafeFieldValues } from '../../form/SafeFieldValues';
3
3
  import { FormSubmitFieldErrors } from './FormSubmitFieldErrors';
4
-
5
4
  /**
6
5
  * Handle thrown {@link FormSubmitError}.
7
6
  * Add key/values as name/message to RHF context errors.
@@ -1,5 +1,4 @@
1
1
  import { MaybePromise } from '../utils/types';
2
-
3
2
  /**
4
3
  * Calls a callback after a successful submit and after a form reset.
5
4
  *
@@ -1,5 +1,4 @@
1
1
  import { MaybePromise } from '../utils/types';
2
-
3
2
  declare const useFormOnSubmitted: (callback?: (success: boolean) => MaybePromise<unknown>, options?: {
4
3
  successful?: boolean;
5
4
  }) => void;
@@ -1,5 +1,4 @@
1
1
  import { default as React } from 'react';
2
-
3
2
  declare const useSubmitFormOnChange: (formRef: React.RefObject<HTMLFormElement>, options?: {
4
3
  /** Disable behavior. (Default behavior is enabled for sake of simplicity of general usage.) */
5
4
  disabled?: boolean;
@@ -1,5 +1,4 @@
1
1
  import { default as React } from 'react';
2
-
3
2
  /**
4
3
  * Create a strictly-typed context that throws error if no provider is found.
5
4
  * @returns A tuple with a function to get the context and the context provider.
@@ -1,7 +1,6 @@
1
1
  import { default as React } from 'react';
2
-
3
2
  /**
4
3
  * @see https://www.totaltypescript.com/forwardref-with-generic-components
5
4
  */
6
- declare function fixedForwardRef<T, P = object>(render: (props: P, ref: React.Ref<T>) => React.ReactNode): (props: P & React.RefAttributes<T>) => React.ReactNode;
5
+ declare function fixedForwardRef<T, P = object>(render: React.ForwardRefRenderFunction<T, React.PropsWithoutRef<P>>): (props: P & React.RefAttributes<T>) => React.ReactNode;
7
6
  export default fixedForwardRef;
@@ -1,5 +1,4 @@
1
1
  import { default as React } from 'react';
2
-
3
2
  /**
4
3
  * Create a ref and point forwarded ref to it.
5
4
  *
@@ -1,4 +1,3 @@
1
1
  import { default as React } from 'react';
2
-
3
2
  declare const useToggle: (defaultValue?: boolean) => [boolean, React.DispatchWithoutAction];
4
3
  export default useToggle;
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.142",
5
+ "version": "0.0.144",
6
6
  "description": "Integration utilities for react-hook-form.",
7
7
  "type": "module",
8
8
  "sideEffects": false,
@@ -1,15 +0,0 @@
1
- export type { Register } from '../register';
2
- export type { RhfUtilsClientConfig } from '../client/config/RhfUtilsClientConfig';
3
- export { default as RhfUtilsClientForZodContextProvider } from '../client/zod/context/RhfUtilsClientForZodContextProvider';
4
- export { default as RhfUtilsZodForm } from '../client/zod/context/RhfUtilsZodForm';
5
- export { default as useRhfUtilsZodForm } from '../client/zod/context/useRhfUtilsZodForm';
6
- export type { RhfUtilsUseFormChildrenZodFC } from '../client/zod/RhfUtilsUseFormChildrenZodFC';
7
- export type { RhfUtilsUseFormChildrenZodProps } from '../client/zod/RhfUtilsUseFormChildrenZodProps';
8
- export { default as useFlatFieldErrorsContext } from '../errors/flat/context/useFlatFieldErrorsContext';
9
- export { default as useFlatFieldErrorsContextHasOnlyOrphans } from '../errors/flat/context/useFlatFieldErrorsContextHasOnlyOrphans';
10
- export { default as RhfUtilsNonFieldErrorMarker } from '../errors/nonfield/RhfUtilsNonFieldErrorMarker';
11
- export type { RhfUtilsFormOptions } from '../form/RhfUtilsFormOptions';
12
- export type { SafeFieldValues } from '../form/SafeFieldValues';
13
- export type { UseRhfUtilsFormChildrenProps } from '../form/UseRhfUtilsFormChildrenProps';
14
- export { default as useRhfUtilsContext } from '../form/context/utils/useRhfUtilsContext';
15
- export { FormSubmitError } from '../submit/error/FormSubmitError';
@@ -1,29 +0,0 @@
1
- import { default as FormGroupContextProvider } from '../form/context/group/FormGroupContextProvider';
2
- import { default as useFormGroupChildIsMountedTracker } from '../form/context/group/useFormGroupChildIsMountedTracker';
3
- import { default as useFormGroupChildIsSubmittingTracker } from '../form/context/group/useFormGroupChildIsSubmittingTracker';
4
- import { default as useFormGroupChildTracker } from '../form/context/group/useFormGroupChildTracker';
5
- import { default as useFormGroupIsAnyBusy } from '../form/context/group/useFormGroupIsAnyBusy';
6
- import { default as useFormGroupIsChildBusy } from '../form/context/group/useFormGroupIsChildBusy';
7
- import { default as useFormGroupIsParentBusy } from '../form/context/group/useFormGroupIsParentBusy';
8
- import { default as useFormGroupParentTracker } from '../form/context/group/useFormGroupParentTracker';
9
- import { default as useFormOrParentIsBusy } from '../form/context/group/useFormOrParentIsBusy';
10
-
11
- export { FormGroupContextProvider }
12
-
13
- export { useFormGroupChildIsMountedTracker }
14
-
15
- export { useFormGroupChildIsSubmittingTracker }
16
-
17
- export { useFormGroupChildTracker }
18
-
19
- export { useFormGroupIsAnyBusy }
20
-
21
- export { useFormGroupIsChildBusy }
22
-
23
- export { useFormGroupIsParentBusy }
24
-
25
- export { useFormGroupParentTracker }
26
-
27
- export { useFormOrParentIsBusy }
28
-
29
- export { }
@@ -1,8 +0,0 @@
1
- import { default as makeOnSubmitTrpcClientErrorHandler } from '../errors/trpc/makeOnSubmitTrpcClientErrorHandler';
2
- import { default as trpcClientErrorToFormSubmitFieldErrorsSchemaTransformer } from '../errors/trpc/trpcClientErrorToFormSubmitFieldErrorsSchemaTransformer';
3
-
4
- export { makeOnSubmitTrpcClientErrorHandler }
5
-
6
- export { trpcClientErrorToFormSubmitFieldErrorsSchemaTransformer }
7
-
8
- export { }
@@ -1,5 +0,0 @@
1
- import { default as RootErrorsListFromFlatFieldErrorsContext } from '../errors/root/RootErrorsListFromFlatFieldErrorsContext';
2
-
3
- export { RootErrorsListFromFlatFieldErrorsContext }
4
-
5
- export { }