@paragrav/rhf-utils 0.0.136 → 0.0.137

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 (33) hide show
  1. package/README.md +84 -63
  2. package/dist/esm/client/zod/context/RhfUtilsClientForZodContextProvider.mjs +3 -1
  3. package/dist/esm/errors/flat/getFlatFieldErrors.mjs +10 -10
  4. package/dist/esm/errors/message/RhfUtilsFieldErrorMessage.mjs +14 -0
  5. package/dist/esm/errors/orphan/isOrphanFormError.mjs +3 -3
  6. package/dist/esm/exports.mjs +32 -36
  7. package/dist/esm/form/Form.mjs +14 -14
  8. package/dist/esm/form/context/utils/RhfUtilsContextProvider.mjs +8 -8
  9. package/dist/esm/submit/error/setCtxErrorsByFormSubmitFieldErrors.mjs +12 -0
  10. package/dist/esm/utils/useDebouncedOnChangeValue.mjs +1 -1
  11. package/dist/types/client/config/RhfUtilsClientConfig.d.ts +5 -5
  12. package/dist/types/client/zod/context/RhfUtilsClientForZodContextProvider.d.ts +1 -1
  13. package/dist/types/errors/flat/flattenFieldErrors.d.ts +3 -2
  14. package/dist/types/errors/message/{FormErrorMessageByPath.d.ts → RhfUtilsFieldErrorMessage.d.ts} +2 -2
  15. package/dist/types/errors/trpc/getOnSubmitTrpcClientErrorHandler.d.ts +2 -2
  16. package/dist/types/errors/trpc/trpcClientErrorToFormSubmitFieldErrorsSchemaTransformer.d.ts +28 -0
  17. package/dist/types/exports.d.ts +1 -3
  18. package/dist/types/form/RhfUtilsFormOptions.d.ts +1 -1
  19. package/dist/types/form/UseRhfUtilsFormProps.d.ts +1 -1
  20. package/dist/types/submit/error/FormSubmitError.d.ts +3 -3
  21. package/dist/types/submit/error/{FormSubmitErrors.d.ts → FormSubmitFieldErrors.d.ts} +1 -1
  22. package/dist/types/submit/error/setCtxErrorsByFormSubmitFieldErrors.d.ts +10 -0
  23. package/dist/types/submit/useFormOnSubmitSuccessfulAndReset.d.ts +1 -1
  24. package/dist/types/submit/useFormOnSubmitted.d.ts +1 -1
  25. package/dist/types/utils/timeoutAsync.d.ts +6 -0
  26. package/package.json +1 -1
  27. package/dist/esm/errors/message/FormErrorMessageByPath.mjs +0 -14
  28. package/dist/esm/errors/trpc/getOnSubmitTrpcClientErrorHandler.mjs +0 -6
  29. package/dist/esm/errors/trpc/trpcClientErrorMessageSchema.mjs +0 -10
  30. package/dist/esm/errors/trpc/trpcClientErrorToFormSubmitErrorsSchemaTransformer.mjs +0 -34
  31. package/dist/esm/submit/error/setCtxErrorsByFormSubmitErrors.mjs +0 -12
  32. package/dist/types/errors/trpc/trpcClientErrorToFormSubmitErrorsSchemaTransformer.d.ts +0 -28
  33. package/dist/types/submit/error/setCtxErrorsByFormSubmitErrors.d.ts +0 -10
package/README.md CHANGED
@@ -2,29 +2,30 @@
2
2
 
3
3
  ## About
4
4
 
5
- Integration and utility library for [react-hook-form](https://www.react-hook-form.com/).
6
-
7
- If you have multiple forms and would like a more declarative API to manage their behavior via global and form-level options, including transformation of backend errors, and debugging field errors.
5
+ Integration and utility library for [react-hook-form](https://www.react-hook-form.com/) and [zod](https://www.npmjs.com/package/zod). Declaratively configure your forms via global and form-level options.
8
6
 
9
7
  ## Features
10
8
 
11
- - [TypeScript](https://www.typescriptlang.org/)-first
12
- - global configuration, such as:
13
- - injecting your own hooks and UI (`FormChildrenWrapper`)
9
+ - TypeScript-first
10
+ - global configuration (`RhfUtilsClientConfig`)
11
+ - RHF (`UseFormProps`) and utilities (`RhfUtilsFormOptions`) options defaults
12
+ - inject your own hooks and UI (`FormChildrenWrapper`)
14
13
  - server error transformation (`onSubmitErrorUnknown`)
15
- - FieldErrors logging/throwing (`RhfUtilsClientConfig.FieldErrors`)
16
- - extendable options type (`RhfUtilsFormOptions`)
17
- - form-specific overrides
18
- - schema-typed Controller component
19
- - schema-typed FormSubmitError class
20
- - throw in submit handler to add errors to RHF context and fail submit
14
+ - RHF `FormState.errors` logging/throwing (`RhfUtilsClientConfig.fieldErrors`)
15
+ - form-level configuration (`RhfUtilsZodForm`)
16
+ - RHF and utilities options overrides
17
+ - extendable utilities options type (`RhfUtilsFormOptions`)
18
+ - throw error (`FormSubmitError`) in submit handler to add errors to RHF context and fail submit
19
+ - handle submit error (`onSubmitError`)
20
+ - dependency injection for children (`RhfUtilsZodForm.Children`), including:
21
+ - formId, formRef, RHF context, utilities options
22
+ - schema-typed Controller component and FormSubmitError class
21
23
  - simpler/flatter `FieldErrors` structure (`FlatFieldErrors`)
22
24
  - context groups errors into `all`, `fields`, `roots`, and `orphans` (`useFlatFieldErrorsContext`)
23
- - `FormErrorMessageByPath` for displaying error message
24
- - `zod` support
25
- - including input/output types for transformations
25
+ - `RhfUtilsFieldErrorMessage` for displaying error message
26
26
  - safer `FieldValues` type (`SafeFieldValues`)
27
- - 3.3kB min+gzip core functionality (excluding [peer dependencies](#peer-dependencies))
27
+ - `zod` support, including input/output types for transformations
28
+ - ~3.9kB min+gzip (excluding [peer dependencies](#peer-dependencies))
28
29
 
29
30
  ## Install
30
31
 
@@ -34,9 +35,15 @@ pnpm install @paragrav/rhf-utils # pnpm
34
35
  yarn add @paragrav/rhf-utils # yarn
35
36
  ```
36
37
 
38
+ ## Quick Start
39
+
40
+ - 🔗 [Config](#config) (`RhfUtilsClientConfig`): define your desired global config (optional)
41
+ - 🔗 [Provider](#provider) (`RhfUtilsClientForZodContextProvider`): add to your global stack
42
+ - 🔗 [Form](#form) (`RhfUtilsZodForm`): use for your forms
43
+
37
44
  ## Config
38
45
 
39
- To configure, create a file like `config.tsx` with desired configuration settings. This is global configuration across all forms, some of which can be overridden at the form level.
46
+ Create a config (`RhfUtilsClientConfig`) object with desired global and default options. This is global configuration across all forms, some of which can be overridden at the form level.
40
47
 
41
48
  ```tsx
42
49
  export const rhfUtilsClientConfig: RhfUtilsClientConfig = {
@@ -77,10 +84,12 @@ export const rhfUtilsClientConfig: RhfUtilsClientConfig = {
77
84
  children, // RhfUtilsZodForm's Children instance
78
85
  },
79
86
  ) => {
80
- // your own hooks/behaviors controlled via custom option props
87
+ useMyGlobalFormHook();
88
+
89
+ // form-level control of your own hooks/behaviors via custom option props
81
90
  // (see "Extend RhfUtilsFormOptions" section for more info)
82
- useMyFormNavigationPrompt({
83
- enabled: !!options?.enableMyFormNavigationPrompt,
91
+ useMyOptionalFormHook({
92
+ enabled: !!options?.enableMyOptionalFormHook,
84
93
  });
85
94
 
86
95
  return (
@@ -99,18 +108,13 @@ export const rhfUtilsClientConfig: RhfUtilsClientConfig = {
99
108
  onSubmitErrorUnknown: (
100
109
  error, // unknown
101
110
  ) => {
102
- // return FormSubmitErrors object to be merged to RHF context errors
111
+ // return FormSubmitFieldErrors object to be merged to RHF context errors
103
112
  if (isMyServerError(error))
104
- return transformMyServerErrorToFormSubmitErrors(error);
105
-
106
- // if other error
107
- return {
108
- root: { type: 'server', message: 'There was a problem.' },
109
- } satisfies FormSubmitErrors;
113
+ return transformMyServerErrorToFormSubmitFieldErrors(error);
110
114
  },
111
115
 
112
- // rhfContext.formState.errors output for debugging
113
- FieldErrors: {
116
+ // RHF FormState.errors output for debugging
117
+ fieldErrors: {
114
118
  // callbacks to determine when to output information about field errors
115
119
  // provided `FlatFieldErrorsContext` (all, fields, roots, orphans, hasOrphans)
116
120
  // (See "Orphan Errors" section below for more info.)
@@ -133,7 +137,7 @@ export const rhfUtilsClientConfig: RhfUtilsClientConfig = {
133
137
 
134
138
  ## Provider
135
139
 
136
- And add the context provider to your global provider stack:
140
+ Add the context provider to your global provider stack.
137
141
 
138
142
  ```tsx
139
143
  <RhfUtilsClientForZodContextProvider config={rhfUtilsClientConfig}>
@@ -185,7 +189,7 @@ Currently, only `zod` is supported.
185
189
  <label>
186
190
  Email
187
191
  <input {...field} disabled={isSubmitting} />
188
- <FormErrorMessageByPath path={field.name} />
192
+ <RhfUtilsFieldErrorMessage path={field.name} />
189
193
  </label>
190
194
  )}
191
195
  />
@@ -199,13 +203,9 @@ Currently, only `zod` is supported.
199
203
  }}
200
204
  utils={{
201
205
  submitOnChange: true,
202
- resetOnSubmitted: {
203
- onSuccess: { values: 'current' },
204
- onError: { values: 'defaults' },
205
- },
206
206
  // custom option props
207
207
  // (see "Extend RhfUtilsFormOptions" section)
208
- enableMyFormNavigationPrompt: true,
208
+ enableMyOptionalFormHook: true,
209
209
  }}
210
210
  form={{
211
211
  // class names are merged together with global defaults
@@ -242,18 +242,17 @@ function Children({...}: RhfUtilsUseFormChildrenZodProps<typeof schema>) { }
242
242
 
243
243
  ## `FormSubmitError`
244
244
 
245
- This is an extended `Error` class that you can use to throw a structured error in your submit handler. It uses `FormSubmitErrors` (with an "s") type's structure, which is a flat, simplified version of RHF's `FieldErrors`.
245
+ This is an `Error`-based class that you can use to throw a schema-typed error in your submit handler.
246
246
 
247
- It differs from `FlatFieldError` only in that it is narrower. Namely, it is schema-typed, so it allows field names from your schema and `root.${string}` keys. And only `type` (optional) and `message` props for error.
247
+ (Internally, it uses `FormSubmitFieldErrors` type's structure, which is a flat, simplified version of RHF's `FieldErrors`. It differs from `FlatFieldError` only in that it is narrower. It allows field names from your schema and `root.${string}` keys. And only `type` (optional) and `message` props for error.)
248
248
 
249
- Example:
249
+ ### Example
250
250
 
251
251
  ```tsx
252
252
  <RhfUtilsZodForm
253
253
  onSubmit={async (data, { FormSubmitError }) => {
254
254
  if (isProblem(data))
255
255
  throw new FormSubmitError({
256
- root: { message: 'There was a problem with the form.' },
257
256
  'street.address': { message: 'Street address invalid.' },
258
257
  });
259
258
 
@@ -262,9 +261,9 @@ Example:
262
261
  />
263
262
  ```
264
263
 
265
- Any non-`FormSubmitError` error thrown from your submit handler (e.g., fetch/axios error) can be transformed by `RhfUtilsClientConfig`'s `onSubmitErrorUnknown` callback. This takes an `unknown` error and can return a `FormSubmitErrors` object, which is merged into RHF's form state errors.
264
+ Any non-`FormSubmitError` error thrown from your submit handler (e.g., fetch/axios error) can be transformed by `RhfUtilsClientConfig`'s `onSubmitErrorUnknown` callback. This takes an `unknown` error and can return a `FormSubmitFieldErrors` object, which is merged into RHF's form state errors.
266
265
 
267
- Most common use case will be transforming backend errors to frontend shape. (You can use `getOnSubmitTrpcClientErrorHandler` HOF provided by this library for TRPC backends.)
266
+ Most common use case will be transforming backend errors to frontend shape.
268
267
 
269
268
  ## `RhfUtilsFormOptions`
270
269
 
@@ -312,7 +311,7 @@ declare module '@paragrav/rhf-utils' {
312
311
  export interface Register {
313
312
  RhfUtilsFormOptions: {
314
313
  /** Enable user prompt to confirm navigating away from dirty form. */
315
- enableMyFormNavigationPrompt?: boolean;
314
+ enableMyOptionalFormHook?: boolean;
316
315
  };
317
316
  }
318
317
  }
@@ -328,47 +327,67 @@ Use `useFlatFieldErrorsContext()` hook, which returns an object with errors grou
328
327
 
329
328
  ### Output
330
329
 
331
- For the purposes of debugging and/or logging, you can configure when form state errors are outputted (i.e., console log and/or thrown) via `RhfUtilsClientConfig` (example at the top).
330
+ For the purposes of debugging and/or logging, you can configure when form state errors are outputted (i.e., console and/or thrown) via `RhfUtilsClientConfig.fieldErrors.output` (example at the top).
332
331
 
333
332
  ### Orphan Errors
334
333
 
335
- The concept of "orphan" errors is any field error that is not being shown to user. (For example, a field in a schema that is prohibiting users from submitting a valid form.)
334
+ The concept of an "orphan" error is any errant schema property that could prohibit users from submitting a valid form because its input is missing or non-existent.
335
+
336
+ Programatically, an "orphan" is any form state error that meets ALL of the following criteria:
337
+
338
+ - non-field -- i.e., no RHF-supplied `ref` on `FieldError` object
339
+ - non-root -- i.e., not `root` or `root.${string}` path
340
+ - no corresponding "marker" in DOM (i.e., `FormNonFieldErrorMarker`)
341
+
342
+ This is because:
343
+
344
+ - field errors (with `ref`s) are assumed to be displayed next to their respective input
345
+ - root errors (non-field, without `ref`s) are assumed to always be listed for display
346
+ - all other errors must be marked as displayed to distinguish from being an orphan
336
347
 
337
- More technically, an "orphan" is any form state error that meets ALL of the following criteria:
348
+ _See [FormNonFieldErrorMarker](#formnonfielderrormarker) section below for more information about when and why marker is needed._
338
349
 
339
- - not a root error -- i.e., `root` and `root.${string}` paths
340
- - these are assumed to be listed for users somewhere
341
- - has no `ref` -- RHF includes `ref` to the associated input for each error (when applicable)
342
- - these are assumed to be shown next to their input fields
343
- - has no marker in DOM (i.e., `FormNonFieldErrorMarker`)
344
- - see section further below for more information
350
+ #### Using orphan errors
345
351
 
346
352
  Detected orphans can be accessed via any of the following:
347
353
 
348
- - via `RhfUtilsClientConfig.FieldErrors.output`; e.g.:
349
- - console log to facilitate debugging on development
350
- - console error to facilitate reporting on production (via your own error reporting service)
351
- - throw error for developer during development
354
+ - `RhfUtilsClientConfig.fieldErrors.output` -- e.g., config per environment:
355
+ - _development_: `throw` to facilitate discovery and debugging
356
+ - _production_: `console.error` to facilitate reporting
352
357
  - `useFlatFieldErrorsContext()` hook
353
358
  - returns an object with list of errors grouped by `all`, `fields` (with `ref`), `roots`, `orphans` records, and includes computed booleans `hasErrors` and `hasOrphans`
354
359
  - boolean value from `useFlatFieldErrorsContextHasOnlyOrphans`
355
360
 
356
361
  ### FormNonFieldErrorMarker
357
362
 
358
- To get accurate orphan detection, you must use `FormNonFieldErrorMarker` in all errors you are displaying to user. (Technically, "root" errors and field errors with a `ref` do not need the marker, because those do not match the first two criteria of an orphan (as listed above). But there is no harm in including it consistently for all error displayed.)
363
+ _If you don't need orphan detection, you can skip this section. By default, orphan detection still occurs but doesn't otherwise do anything._
359
364
 
360
- #### When is the marker required?
365
+ To get accurate orphan detection, you must use `FormNonFieldErrorMarker` when displaying any non-root non-field errors. (Example further below.)
361
366
 
362
- For example, a field array with a minimum number of items -- e.g., `items: z.array(...).min(1)`.
367
+ There is little harm in including it consistently for all individual errors displayed. (DOM traversal to find marker only occurs if error is non-field AND non-root, which is not typical.)
363
368
 
364
- When there are zero items, the error is not "root" and is not associated with a specific field. Therefore, in order to NOT detect this as an orphan, it must be "marked" as displayed using `FormNonFieldErrorMarker`.
369
+ #### When is the marker required? _(example of non-root non-field error)_
365
370
 
366
- You can incorporate `FormNonFieldErrorMarker` into your own component library, or use this library's `FormErrorMessageByPath` to display error message to user, which includes this marker.
371
+ A typical example is a field array with a required minimum number of items -- e.g., `items: z.array(...).min(1)`.
372
+
373
+ When there are zero items, the error is non-field and non-root. You would probably display this error (manually) near the field array, using something like RHF's [`ErrorMessage`](https://www.react-hook-form.com/api/useformstate/errormessage/) component.
374
+
375
+ In order to NOT detect this as an orphan, it must be explicitly "marked" as displayed using `FormNonFieldErrorMarker`.
376
+
377
+ You can incorporate `FormNonFieldErrorMarker` into your own component library, or use this library's `RhfUtilsFieldErrorMessage` to display error message to user, which includes this marker.
367
378
 
368
379
  ```tsx
369
- <FormErrorMessageByPath path="items" />
380
+ <RhfUtilsFieldErrorMessage path="items" />
370
381
  ```
371
382
 
383
+ Uncommon, but if you are ONLY listing a summary of all errors, without individual displays, you will need to use the marker manually.
384
+
385
+ ```tsx
386
+ <FormNonFieldErrorMarker path="items" />
387
+ ```
388
+
389
+ _If you include the marker for error lists, it will defeat the purpose of the marker. Only use marker for individual errors._
390
+
372
391
  ## Form Groups
373
392
 
374
393
  Sometimes you need to group multiple forms together.
@@ -396,9 +415,11 @@ Both hooks return `boolean` value indicating whether parent form is busy.
396
415
 
397
416
  ## Other
398
417
 
418
+ ### SafeFieldValues
419
+
399
420
  This library uses `SafeFieldValues` type which uses `unknown` instead of `any`.
400
421
 
401
- #### Peer dependencies:
422
+ ### Peer dependencies
402
423
 
403
424
  - [react](https://www.npmjs.com/package/react)
404
425
  - [react-dom](https://www.npmjs.com/package/react-dom)
@@ -7,7 +7,9 @@ const d = ({
7
7
  config: r,
8
8
  children: i
9
9
  }) => {
10
- const [t] = e.useState(r), [n] = e.useState(() => f(t));
10
+ const [t] = e.useState(r), [n] = e.useState(
11
+ () => f(t ?? {})
12
+ );
11
13
  return /* @__PURE__ */ o(l, { value: t, children: /* @__PURE__ */ o(s, { value: n, children: i }) });
12
14
  }, p = d;
13
15
  export {
@@ -1,24 +1,24 @@
1
- import { get as c } from "react-hook-form";
2
- import n from "./flattenFieldErrors.mjs";
3
- const u = (t) => {
4
- const s = n(t), a = Object.keys(s);
1
+ import { get as d } from "react-hook-form";
2
+ import a from "./flattenFieldErrors.mjs";
3
+ const b = (t) => {
4
+ const s = a(t), n = Object.keys(s);
5
5
  return Object.fromEntries(
6
- a.reduce(
6
+ n.reduce(
7
7
  (e, o) => {
8
8
  const r = o.replace(
9
- d,
9
+ i,
10
10
  ""
11
11
  );
12
12
  if (r === o) return e;
13
- const f = c(t, r, void 0);
13
+ const f = d(t, r, void 0);
14
14
  return f && e.push([r, f]), e;
15
15
  },
16
16
  []
17
17
  // entries
18
18
  )
19
19
  );
20
- }, d = /\.(?:type|message)\b$/;
20
+ }, i = /\.(?:type|message)\b$/;
21
21
  export {
22
- u as default,
23
- d as regexMaybeFieldErrorLeafNodeSuffix
22
+ b as default,
23
+ i as regexMaybeFieldErrorLeafNodeSuffix
24
24
  };
@@ -0,0 +1,14 @@
1
+ import { jsxs as n, Fragment as i, jsx as o } from "react/jsx-runtime";
2
+ import { useFormState as a, get as l } from "react-hook-form";
3
+ import f from "../nonfield/FormNonFieldErrorMarker.mjs";
4
+ import g from "./FormErrorMessage.mjs";
5
+ const F = ({ path: e, Component: s }) => {
6
+ const { errors: t } = a(), r = l(t, e, void 0), m = s ?? g;
7
+ return r != null && r.message ? /* @__PURE__ */ n(i, { children: [
8
+ /* @__PURE__ */ o(m, { message: r.message }),
9
+ /* @__PURE__ */ o(f, { path: e })
10
+ ] }) : null;
11
+ }, E = F;
12
+ export {
13
+ E as default
14
+ };
@@ -2,9 +2,9 @@ import m from "../isFieldErrorRefd.mjs";
2
2
  import t from "../nonfield/isNonFieldErrorMarkerInDOM.mjs";
3
3
  import e from "../root/isFormErrorPathRoot.mjs";
4
4
  const d = (r, o, i) => (
5
- // not root path
6
- !e(r) && // non-field
7
- !m(o) && // not marked in DOM
5
+ // non-field
6
+ !m(o) && // non-root
7
+ !e(r) && // not marked in DOM
8
8
  !t(r, i)
9
9
  );
10
10
  export {
@@ -1,50 +1,46 @@
1
1
  import { default as e } from "./client/zod/context/RhfUtilsClientForZodContextProvider.mjs";
2
- import { default as a } from "./client/zod/context/RhfUtilsZodForm.mjs";
2
+ import { default as s } from "./client/zod/context/RhfUtilsZodForm.mjs";
3
3
  import { default as u } from "./client/zod/context/useRhfUtilsZodForm.mjs";
4
4
  import { default as m } from "./errors/flat/context/useFlatFieldErrorsContext.mjs";
5
5
  import { default as d } from "./errors/flat/context/useFlatFieldErrorsContextHasOnlyOrphans.mjs";
6
- import { default as x } from "./errors/message/FormErrorMessageByPath.mjs";
6
+ import { default as x } from "./errors/message/RhfUtilsFieldErrorMessage.mjs";
7
7
  import { default as F } from "./errors/nonfield/FormNonFieldErrorMarker.mjs";
8
8
  import { default as C } from "./errors/root/RootErrorsListFromFlatFieldErrorsContext.mjs";
9
- import { default as E } from "./errors/trpc/getOnSubmitTrpcClientErrorHandler.mjs";
10
- import { default as R } from "./errors/trpc/trpcClientErrorToFormSubmitErrorsSchemaTransformer.mjs";
11
- import { default as b } from "./form/context/utils/useRhfUtilsContext.mjs";
12
- import { default as y } from "./form/context/utils/useRhfUtilsContextRequestSubmit.mjs";
13
- import { default as B } from "./form/context/group/FormGroupContextProvider.mjs";
14
- import { default as P } from "./form/context/group/useFormGroupChildIsMountedTracker.mjs";
15
- import { default as U } from "./form/context/group/useFormGroupChildIsSubmittingTracker.mjs";
16
- import { default as O } from "./form/context/group/useFormGroupChildTracker.mjs";
17
- import { default as Z } from "./form/context/group/useFormGroupIsAnyBusy.mjs";
18
- import { default as v } from "./form/context/group/useFormGroupIsChildBusy.mjs";
19
- import { default as A } from "./form/context/group/useFormGroupIsParentBusy.mjs";
20
- import { default as L } from "./form/context/group/useFormGroupParentTracker.mjs";
21
- import { default as j } from "./form/context/group/useFormOrParentIsBusy.mjs";
22
- import { default as z } from "./form/utils/getSubmitterButtonData.mjs";
23
- import { default as K } from "./form/utils/useFormRequestSubmit.mjs";
24
- import { FormSubmitError as V } from "./submit/error/FormSubmitError.mjs";
9
+ import { default as R } from "./form/context/utils/useRhfUtilsContext.mjs";
10
+ import { default as E } from "./form/context/utils/useRhfUtilsContextRequestSubmit.mjs";
11
+ import { default as I } from "./form/context/group/FormGroupContextProvider.mjs";
12
+ import { default as b } from "./form/context/group/useFormGroupChildIsMountedTracker.mjs";
13
+ import { default as B } from "./form/context/group/useFormGroupChildIsSubmittingTracker.mjs";
14
+ import { default as S } from "./form/context/group/useFormGroupChildTracker.mjs";
15
+ import { default as T } from "./form/context/group/useFormGroupIsAnyBusy.mjs";
16
+ import { default as M } from "./form/context/group/useFormGroupIsChildBusy.mjs";
17
+ import { default as Z } from "./form/context/group/useFormGroupIsParentBusy.mjs";
18
+ import { default as v } from "./form/context/group/useFormGroupParentTracker.mjs";
19
+ import { default as D } from "./form/context/group/useFormOrParentIsBusy.mjs";
20
+ import { default as L } from "./form/utils/getSubmitterButtonData.mjs";
21
+ import { default as j } from "./form/utils/useFormRequestSubmit.mjs";
22
+ import { FormSubmitError as z } from "./submit/error/FormSubmitError.mjs";
25
23
  export {
26
- x as FormErrorMessageByPath,
27
- B as FormGroupContextProvider,
24
+ I as FormGroupContextProvider,
28
25
  F as FormNonFieldErrorMarker,
29
- V as FormSubmitError,
26
+ z as FormSubmitError,
30
27
  e as RhfUtilsClientForZodContextProvider,
31
- a as RhfUtilsZodForm,
28
+ x as RhfUtilsFieldErrorMessage,
29
+ s as RhfUtilsZodForm,
32
30
  C as RootErrorsListFromFlatFieldErrorsContext,
33
- E as getOnSubmitTrpcClientErrorHandler,
34
- z as getSubmitterButtonData,
35
- R as trpcClientErrorToFormSubmitErrorsSchemaTransformer,
31
+ L as getSubmitterButtonData,
36
32
  m as useFlatFieldErrorsContext,
37
33
  d as useFlatFieldErrorsContextHasOnlyOrphans,
38
- P as useFormGroupChildIsMountedTracker,
39
- U as useFormGroupChildIsSubmittingTracker,
40
- O as useFormGroupChildTracker,
41
- Z as useFormGroupIsAnyBusy,
42
- v as useFormGroupIsChildBusy,
43
- A as useFormGroupIsParentBusy,
44
- L as useFormGroupParentTracker,
45
- j as useFormOrParentIsBusy,
46
- K as useFormRequestSubmit,
47
- b as useRhfUtilsContext,
48
- y as useRhfUtilsContextRequestSubmit,
34
+ b as useFormGroupChildIsMountedTracker,
35
+ B as useFormGroupChildIsSubmittingTracker,
36
+ S as useFormGroupChildTracker,
37
+ T as useFormGroupIsAnyBusy,
38
+ M as useFormGroupIsChildBusy,
39
+ Z as useFormGroupIsParentBusy,
40
+ v as useFormGroupParentTracker,
41
+ D as useFormOrParentIsBusy,
42
+ j as useFormRequestSubmit,
43
+ R as useRhfUtilsContext,
44
+ E as useRhfUtilsContextRequestSubmit,
49
45
  u as useRhfUtilsZodForm
50
46
  };
@@ -1,10 +1,10 @@
1
- import { jsx as c, jsxs as j } from "react/jsx-runtime";
1
+ import { jsx as s, jsxs as j } from "react/jsx-runtime";
2
2
  import "react";
3
3
  import { useFormContext as W } from "react-hook-form";
4
4
  import w from "../client/config/useRhfUtilsClientConfigContext.mjs";
5
5
  import E from "../devtool/LazyDevTool.mjs";
6
- import { FormSubmitError as d } from "../submit/error/FormSubmitError.mjs";
7
- import S from "../submit/error/setCtxErrorsByFormSubmitErrors.mjs";
6
+ import { FormSubmitError as c } from "../submit/error/FormSubmitError.mjs";
7
+ import S from "../submit/error/setCtxErrorsByFormSubmitFieldErrors.mjs";
8
8
  import U from "../utils/PassthroughChildren.mjs";
9
9
  import _ from "./_Controller.mjs";
10
10
  function G({
@@ -12,9 +12,9 @@ function G({
12
12
  formRef: p,
13
13
  //
14
14
  onSubmit: a,
15
- onSubmitError: s,
16
- onSubmitInvalid: x,
17
- Children: l,
15
+ onSubmitError: d,
16
+ onSubmitInvalid: l,
17
+ Children: x,
18
18
  //
19
19
  form: F,
20
20
  utils: r
@@ -22,7 +22,7 @@ function G({
22
22
  const e = W(), t = w(), y = async (o) => {
23
23
  r != null && r.stopSubmitPropagation && o.stopPropagation();
24
24
  try {
25
- await e.handleSubmit(f, x)(o);
25
+ await e.handleSubmit(f, l)(o);
26
26
  } catch (n) {
27
27
  P(n, o);
28
28
  }
@@ -33,19 +33,19 @@ function G({
33
33
  formRef: p,
34
34
  context: e,
35
35
  utils: r,
36
- FormSubmitError: d
36
+ FormSubmitError: c
37
37
  },
38
38
  n
39
39
  ), P = (o, n) => {
40
40
  var i;
41
- const C = o instanceof d ? (
41
+ const C = o instanceof c ? (
42
42
  // consumer can manually throw FormSubmitError (e.g., manual validation)
43
43
  o.errors
44
44
  ) : (
45
45
  // if error is not FormSubmitError, consumer can provide global handler
46
46
  (i = t == null ? void 0 : t.onSubmitErrorUnknown) == null ? void 0 : i.call(t, o)
47
47
  );
48
- C && S(e, C), s == null || s(
48
+ C && S(e, C), d == null || d(
49
49
  o,
50
50
  {
51
51
  formId: m,
@@ -61,22 +61,22 @@ function G({
61
61
  context: e,
62
62
  utils: r,
63
63
  Controller: _,
64
- FormSubmitError: d
64
+ FormSubmitError: c
65
65
  }, b = h, v = (t == null ? void 0 : t.FormComponent) ?? "form", T = (t == null ? void 0 : t.FormChildrenWrapper) ?? U;
66
- return /* @__PURE__ */ c(
66
+ return /* @__PURE__ */ s(
67
67
  v,
68
68
  {
69
69
  ...F,
70
70
  ref: p,
71
71
  onSubmit: (o) => void y(o),
72
72
  children: /* @__PURE__ */ j(T, { ...b, children: [
73
- (r == null ? void 0 : r.devTool) && /* @__PURE__ */ c(
73
+ (r == null ? void 0 : r.devTool) && /* @__PURE__ */ s(
74
74
  E,
75
75
  {
76
76
  props: typeof r.devTool == "object" ? r.devTool : void 0
77
77
  }
78
78
  ),
79
- /* @__PURE__ */ c(l, { ...h })
79
+ /* @__PURE__ */ s(x, { ...h })
80
80
  ] })
81
81
  }
82
82
  );
@@ -1,23 +1,23 @@
1
- import { jsx as l } from "react/jsx-runtime";
2
- import d from "../../../client/config/useRhfUtilsClientConfigContext.mjs";
3
- import f from "../../../errors/flat/context/useFlatFieldErrorsContextOutput.mjs";
1
+ import { jsx as f } from "react/jsx-runtime";
2
+ import l from "../../../client/config/useRhfUtilsClientConfigContext.mjs";
3
+ import d from "../../../errors/flat/context/useFlatFieldErrorsContextOutput.mjs";
4
4
  import b from "../../../submit/useResetFormOnSubmitted.mjs";
5
5
  import C from "../../../submit/useSubmitFormOnChange.mjs";
6
6
  import { _RhfUtilsContextProvider as h } from "./useRhfUtilsContext.mjs";
7
- const n = ({
7
+ const v = ({
8
8
  formId: u,
9
9
  formRef: t,
10
10
  options: e,
11
11
  children: a
12
12
  }) => {
13
13
  var m;
14
- const r = d();
15
- return f((m = r == null ? void 0 : r.FieldErrors) == null ? void 0 : m.output), C(t, {
14
+ const r = l();
15
+ return d((m = r == null ? void 0 : r.fieldErrors) == null ? void 0 : m.output), C(t, {
16
16
  // check for false/undefined
17
17
  disabled: ((e == null ? void 0 : e.submitOnChange) ?? !1) === !1,
18
18
  debounce: typeof (e == null ? void 0 : e.submitOnChange) == "number" ? e.submitOnChange : void 0
19
- }), b(e == null ? void 0 : e.resetOnSubmitted), /* @__PURE__ */ l(h, { value: { formId: u, formRef: t, options: e }, children: a });
19
+ }), b(e == null ? void 0 : e.resetOnSubmitted), /* @__PURE__ */ f(h, { value: { formId: u, formRef: t, options: e }, children: a });
20
20
  };
21
21
  export {
22
- n as default
22
+ v as default
23
23
  };
@@ -0,0 +1,12 @@
1
+ const s = (r, t) => {
2
+ Object.entries(t).forEach(([e, o]) => {
3
+ r.setError(e, {
4
+ type: "FormSubmitFieldError",
5
+ // default
6
+ ...o
7
+ });
8
+ });
9
+ };
10
+ export {
11
+ s as default
12
+ };
@@ -9,7 +9,7 @@ const a = ({
9
9
  e.current && clearTimeout(e.current.timer);
10
10
  };
11
11
  return r.useEffect(
12
- // return clear fn
12
+ // return timeout clearer
13
13
  () => t,
14
14
  []
15
15
  ), [(o) => {
@@ -2,7 +2,7 @@ import { UseFormProps } from 'react-hook-form';
2
2
  import { FlatFieldErrorsOutputConfig } from '../../errors/flat/context/FlatFieldErrorsOutputConfig';
3
3
  import { RhfUtilsFormOptions } from '../../form/RhfUtilsFormOptions';
4
4
  import { UseRhfUtilsFormChildrenProps } from '../../form/UseRhfUtilsFormChildrenProps';
5
- import { FormSubmitErrors } from '../../submit/error/FormSubmitErrors';
5
+ import { FormSubmitFieldErrors } from '../../submit/error/FormSubmitFieldErrors';
6
6
 
7
7
  /**
8
8
  * Client configuration object.
@@ -51,14 +51,14 @@ export type RhfUtilsClientConfig = {
51
51
  * Global submit error handler when/if submit handler throws an error other than {@link FormSubmitError}.
52
52
  *
53
53
  * Example use case:
54
- * - transform API errors to {@link FormSubmitErrors}.
54
+ * - transform API errors to {@link FormSubmitFieldErrors}.
55
55
  *
56
56
  * @returns
57
- * - if {@link FormSubmitErrors}: merge into context errors.
57
+ * - if {@link FormSubmitFieldErrors}: merge into context errors.
58
58
  * - if `undefined`: do nothing.
59
59
  */
60
- onSubmitErrorUnknown?: (error: unknown) => FormSubmitErrors | undefined;
61
- FieldErrors?: {
60
+ onSubmitErrorUnknown?: (error: unknown) => FormSubmitFieldErrors | undefined;
61
+ fieldErrors?: {
62
62
  /**
63
63
  * Configure how/if errors should be outputted.
64
64
  */
@@ -2,7 +2,7 @@ import { default as React } from 'react';
2
2
  import { RhfUtilsClientConfig } from '../../config/RhfUtilsClientConfig';
3
3
 
4
4
  type Props = React.PropsWithChildren<{
5
- config: RhfUtilsClientConfig;
5
+ config?: RhfUtilsClientConfig;
6
6
  }>;
7
7
  declare const RhfUtilsClientForZodContextProvider: React.FC<Props>;
8
8
  export default RhfUtilsClientForZodContextProvider;
@@ -1,9 +1,10 @@
1
1
  import { FieldErrors } from 'react-hook-form';
2
2
 
3
3
  /**
4
- * Only flattens a {@link FieldErrors} object.
4
+ * Flatten a {@link FieldErrors} object.
5
+ *
5
6
  * @returns e.g.,
6
- * ```
7
+ * ```ts
7
8
  * {
8
9
  * "address.street.type": "too_short",
9
10
  * "address.street.ref.value": "123",
@@ -6,5 +6,5 @@ type Props = {
6
6
  message: string;
7
7
  }>;
8
8
  };
9
- declare const FormErrorMessageByPath: React.FC<Props>;
10
- export default FormErrorMessageByPath;
9
+ declare const RhfUtilsFieldErrorMessage: React.FC<Props>;
10
+ export default RhfUtilsFieldErrorMessage;
@@ -1,5 +1,5 @@
1
1
  import { RhfUtilsClientConfig } from '../../client/config/RhfUtilsClientConfig';
2
- import { FormSubmitErrors } from '../../submit/error/FormSubmitErrors';
2
+ import { FormSubmitFieldErrors } from '../../submit/error/FormSubmitFieldErrors';
3
3
 
4
4
  /**
5
5
  * HOF that returns submit error handler for {@link RhfUtilsClientConfig.onSubmitErrorUnknown}.
@@ -7,5 +7,5 @@ import { FormSubmitErrors } from '../../submit/error/FormSubmitErrors';
7
7
  * @param onError Fallback for handling non-TRPC errors.
8
8
  * @returns FormSubmitError
9
9
  */
10
- declare const getOnSubmitTrpcClientErrorHandler: (onNotTrpcClientError: NonNullable<RhfUtilsClientConfig["onSubmitErrorUnknown"]>) => (error: unknown) => FormSubmitErrors | undefined;
10
+ declare const getOnSubmitTrpcClientErrorHandler: (onNotTrpcClientError: NonNullable<RhfUtilsClientConfig["onSubmitErrorUnknown"]>) => (error: unknown) => FormSubmitFieldErrors | undefined;
11
11
  export default getOnSubmitTrpcClientErrorHandler;
@@ -0,0 +1,28 @@
1
+ import { TRPCClientErrorLike } from '@trpc/client';
2
+ import { AnyRouter } from '@trpc/server';
3
+ import { z } from 'zod';
4
+ import { FormSubmitFieldErrors } from '../../submit/error/FormSubmitFieldErrors';
5
+
6
+ /**
7
+ * Schema that transforms {@link TRPCClientError} to RHF {@link FormSubmitFieldErrors}.
8
+ */
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<{
10
+ validation: z.ZodString;
11
+ code: z.ZodString;
12
+ message: z.ZodString;
13
+ path: z.ZodArray<z.ZodString, "many">;
14
+ }, "strip", z.ZodTypeAny, {
15
+ message: string;
16
+ code: string;
17
+ path: string[];
18
+ validation: string;
19
+ }, {
20
+ message: string;
21
+ code: string;
22
+ path: string[];
23
+ validation: string;
24
+ }>, "many">>, (readonly [string, {
25
+ type: string;
26
+ message: string;
27
+ }])[], TRPCClientErrorLike<AnyRouter>>, FormSubmitFieldErrors, TRPCClientErrorLike<AnyRouter>>;
28
+ export default trpcClientErrorToFormSubmitFieldErrorsSchemaTransformer;
@@ -7,11 +7,9 @@ export type { RhfUtilsUseFormChildrenZodFC } from './client/zod/RhfUtilsUseFormC
7
7
  export type { RhfUtilsUseFormChildrenZodProps } from './client/zod/RhfUtilsUseFormChildrenZodProps';
8
8
  export { default as useFlatFieldErrorsContext } from './errors/flat/context/useFlatFieldErrorsContext';
9
9
  export { default as useFlatFieldErrorsContextHasOnlyOrphans } from './errors/flat/context/useFlatFieldErrorsContextHasOnlyOrphans';
10
- export { default as FormErrorMessageByPath } from './errors/message/FormErrorMessageByPath';
10
+ export { default as RhfUtilsFieldErrorMessage } from './errors/message/RhfUtilsFieldErrorMessage';
11
11
  export { default as FormNonFieldErrorMarker } from './errors/nonfield/FormNonFieldErrorMarker';
12
12
  export { default as RootErrorsListFromFlatFieldErrorsContext } from './errors/root/RootErrorsListFromFlatFieldErrorsContext';
13
- export { default as getOnSubmitTrpcClientErrorHandler } from './errors/trpc/getOnSubmitTrpcClientErrorHandler';
14
- export { default as trpcClientErrorToFormSubmitErrorsSchemaTransformer } from './errors/trpc/trpcClientErrorToFormSubmitErrorsSchemaTransformer';
15
13
  export type { RhfUtilsFormOptions } from './form/RhfUtilsFormOptions';
16
14
  export type { SafeFieldValues } from './form/SafeFieldValues';
17
15
  export type { UseRhfUtilsFormChildrenProps } from './form/UseRhfUtilsFormChildrenProps';
@@ -23,7 +23,7 @@ export type RhfUtilsFormOptions = {
23
23
  * (Lazy-loaded when truthy value supplied.
24
24
  * For zero bundle size in prod, be sure to check for dev environment.)
25
25
  */
26
- devTool?: true | Pick<DevtoolUIProps, 'placement' | 'styles'>;
26
+ devTool?: boolean | Pick<DevtoolUIProps, 'placement' | 'styles'>;
27
27
  } & (Register extends {
28
28
  RhfUtilsFormOptions: infer _RhfUtilsFormOptions;
29
29
  } ? _RhfUtilsFormOptions : {});
@@ -1,6 +1,6 @@
1
- import { MaybePromise } from '@trpc/server/unstable-core-do-not-import';
2
1
  import { default as React } from 'react';
3
2
  import { SubmitErrorHandler, UseFormProps } from 'react-hook-form';
3
+ import { MaybePromise } from '../utils/types';
4
4
  import { RhfUtilsFormOptions } from './RhfUtilsFormOptions';
5
5
  import { SafeFieldValues } from './SafeFieldValues';
6
6
  import { UseRhfUtilsFormChildrenProps } from './UseRhfUtilsFormChildrenProps';
@@ -1,7 +1,7 @@
1
1
  import { SafeFieldValues } from '../../form/SafeFieldValues';
2
- import { FormSubmitErrors } from './FormSubmitErrors';
2
+ import { FormSubmitFieldErrors } from './FormSubmitFieldErrors';
3
3
 
4
4
  export declare class FormSubmitError<TFieldValues extends SafeFieldValues = SafeFieldValues> extends Error {
5
- errors: FormSubmitErrors<TFieldValues>;
6
- constructor(errors: FormSubmitErrors<TFieldValues>, message?: string);
5
+ errors: FormSubmitFieldErrors<TFieldValues>;
6
+ constructor(errors: FormSubmitFieldErrors<TFieldValues>, message?: string);
7
7
  }
@@ -9,7 +9,7 @@ import { SafeFieldValues } from '../../form/SafeFieldValues';
9
9
  * - `root` is reserved for special use cases.
10
10
  * - simplified `ErrorOption` value.
11
11
  */
12
- export type FormSubmitErrors<TFieldValues extends SafeFieldValues = SafeFieldValues> = Record<FieldPath<TFieldValues> | `root.${string}`, {
12
+ export type FormSubmitFieldErrors<TFieldValues extends SafeFieldValues = SafeFieldValues> = Record<FieldPath<TFieldValues> | `root.${string}`, {
13
13
  type?: string;
14
14
  message: string;
15
15
  }>;
@@ -0,0 +1,10 @@
1
+ import { UseFormReturn } from 'react-hook-form';
2
+ import { SafeFieldValues } from '../../form/SafeFieldValues';
3
+ import { FormSubmitFieldErrors } from './FormSubmitFieldErrors';
4
+
5
+ /**
6
+ * Handle thrown {@link FormSubmitError}.
7
+ * Add key/values as name/message to RHF context errors.
8
+ */
9
+ declare const setCtxErrorsByFormSubmitFieldErrors: <TFieldValues extends SafeFieldValues, TTransformedValues extends SafeFieldValues>(ctx: UseFormReturn<TFieldValues, unknown, TTransformedValues>, errors: FormSubmitFieldErrors) => void;
10
+ export default setCtxErrorsByFormSubmitFieldErrors;
@@ -1,4 +1,4 @@
1
- import { MaybePromise } from '@trpc/server/unstable-core-do-not-import';
1
+ import { MaybePromise } from '../utils/types';
2
2
 
3
3
  /**
4
4
  * Calls a callback after a successful submit and after a form reset.
@@ -1,4 +1,4 @@
1
- import { MaybePromise } from '@trpc/server/unstable-core-do-not-import';
1
+ import { MaybePromise } from '../utils/types';
2
2
 
3
3
  declare const useFormOnSubmitted: (callback?: (success: boolean) => MaybePromise<unknown>, options?: {
4
4
  successful?: boolean;
@@ -0,0 +1,6 @@
1
+ /**
2
+ * Awaitable `setTimeout`.
3
+ * @param timeout milliseconds
4
+ * @returns `Promise<void>`
5
+ */
6
+ export declare const timeoutAsync: (timeout: number) => Promise<void>;
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.136",
5
+ "version": "0.0.137",
6
6
  "description": "Integration utilities for react-hook-form.",
7
7
  "type": "module",
8
8
  "sideEffects": false,
@@ -1,14 +0,0 @@
1
- import { jsxs as n, Fragment as a, jsx as e } from "react/jsx-runtime";
2
- import { useFormState as g, get as i } from "react-hook-form";
3
- import F from "../nonfield/FormNonFieldErrorMarker.mjs";
4
- import c from "./FormErrorMessage.mjs";
5
- const f = ({ path: o, Component: s }) => {
6
- const { errors: t } = g(), r = i(t, o, void 0), m = s ?? c;
7
- return r != null && r.message ? /* @__PURE__ */ n(a, { children: [
8
- /* @__PURE__ */ e(m, { message: r.message }),
9
- /* @__PURE__ */ e(F, { path: o })
10
- ] }) : null;
11
- }, E = f;
12
- export {
13
- E as default
14
- };
@@ -1,6 +0,0 @@
1
- import { TRPCClientError as n } from "@trpc/client";
2
- import e from "./trpcClientErrorToFormSubmitErrorsSchemaTransformer.mjs";
3
- const o = (t) => (r) => r instanceof n ? e.parse(r) : t(r), a = o;
4
- export {
5
- a as default
6
- };
@@ -1,10 +0,0 @@
1
- import { z as r } from "zod";
2
- const a = r.object({
3
- validation: r.string(),
4
- code: r.string(),
5
- message: r.string(),
6
- path: r.array(r.string())
7
- });
8
- export {
9
- a as default
10
- };
@@ -1,34 +0,0 @@
1
- import { TRPCClientError as o } from "@trpc/client";
2
- import { z as e } from "zod";
3
- import a from "./trpcClientErrorMessageSchema.mjs";
4
- const i = e.custom(
5
- (r) => r instanceof o
6
- // check instance type
7
- ).transform((r) => r.message).transform((r) => {
8
- try {
9
- return JSON.parse(r);
10
- } catch {
11
- return [
12
- {
13
- validation: "root",
14
- code: "server",
15
- message: r,
16
- path: ["root"]
17
- }
18
- ];
19
- }
20
- }).pipe(e.array(a)).transform(
21
- (r) => r.map(
22
- (t) => [
23
- t.path.join("."),
24
- // flatten path (e.g., "street.name")
25
- {
26
- type: t.code,
27
- message: t.message
28
- }
29
- ]
30
- )
31
- ).transform((r) => Object.fromEntries(r));
32
- export {
33
- i as default
34
- };
@@ -1,12 +0,0 @@
1
- const s = (r, t) => {
2
- Object.entries(t).forEach(([o, e]) => {
3
- r.setError(o, {
4
- type: "FormSubmitError",
5
- // default
6
- ...e
7
- });
8
- });
9
- };
10
- export {
11
- s as default
12
- };
@@ -1,28 +0,0 @@
1
- import { TRPCClientErrorLike } from '@trpc/client';
2
- import { AnyRouter } from '@trpc/server';
3
- import { z } from 'zod';
4
- import { FormSubmitErrors } from '../../submit/error/FormSubmitErrors';
5
-
6
- /**
7
- * Schema that transforms {@link TRPCClientError} to RHF {@link FormSubmitErrors}.
8
- */
9
- declare const trpcClientErrorToFormSubmitErrorsSchemaTransformer: 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<{
10
- validation: z.ZodString;
11
- code: z.ZodString;
12
- message: z.ZodString;
13
- path: z.ZodArray<z.ZodString, "many">;
14
- }, "strip", z.ZodTypeAny, {
15
- message: string;
16
- code: string;
17
- path: string[];
18
- validation: string;
19
- }, {
20
- message: string;
21
- code: string;
22
- path: string[];
23
- validation: string;
24
- }>, "many">>, (readonly [string, {
25
- type: string;
26
- message: string;
27
- }])[], TRPCClientErrorLike<AnyRouter>>, FormSubmitErrors, TRPCClientErrorLike<AnyRouter>>;
28
- export default trpcClientErrorToFormSubmitErrorsSchemaTransformer;
@@ -1,10 +0,0 @@
1
- import { UseFormReturn } from 'react-hook-form';
2
- import { SafeFieldValues } from '../../form/SafeFieldValues';
3
- import { FormSubmitErrors } from './FormSubmitErrors';
4
-
5
- /**
6
- * Handle thrown {@link FormSubmitError}.
7
- * Add key/values as name/message to RHF context errors.
8
- */
9
- declare const setCtxErrorsByFormSubmitErrors: <TFieldValues extends SafeFieldValues, TTransformedValues extends SafeFieldValues>(ctx: UseFormReturn<TFieldValues, unknown, TTransformedValues>, errors: FormSubmitErrors) => void;
10
- export default setCtxErrorsByFormSubmitErrors;