@paragrav/rhf-utils 0.0.133 → 0.0.135
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.
- package/LICENSE.md +21 -0
- package/README.md +62 -38
- package/dist/esm/client/utils.mjs +21 -12
- package/dist/esm/client/utils.mjs.map +1 -1
- package/dist/esm/errors/message/FormErrorMessageByPath.mjs +2 -2
- package/dist/esm/errors/message/FormErrorMessageByPath.mjs.map +1 -1
- package/dist/esm/form/Form.mjs +34 -34
- package/dist/esm/form/Form.mjs.map +1 -1
- package/dist/types/client/config/RhfUtilsClientConfig.d.ts +7 -2
- package/dist/types/form/RhfUtilsFormOptions.d.ts +1 -1
- package/package.json +5 -1
package/LICENSE.md
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2024-present paragrav.dev
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
CHANGED
|
@@ -4,20 +4,27 @@
|
|
|
4
4
|
|
|
5
5
|
Integration and utility library for [react-hook-form](https://www.react-hook-form.com/).
|
|
6
6
|
|
|
7
|
-
If you have multiple forms and would like a more declarative API to manage their behavior
|
|
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.
|
|
8
8
|
|
|
9
9
|
## Features
|
|
10
10
|
|
|
11
11
|
- built with and for [TypeScript](https://www.typescriptlang.org/)
|
|
12
|
-
- global
|
|
13
|
-
-
|
|
12
|
+
- global configuration, such as:
|
|
13
|
+
- injecting your own hooks and UI (`FormChildrenWrapper`)
|
|
14
|
+
- server error transformation (`onSubmitErrorUnknown`)
|
|
15
|
+
- FieldErrors logging/throwing (`RhfUtilsClientConfig.FieldErrors`)
|
|
16
|
+
- extendable options type (`RhfUtilsFormOptions`)
|
|
17
|
+
- form-specific overrides
|
|
14
18
|
- schema-typed Controller component
|
|
15
19
|
- schema-typed FormSubmitError class
|
|
16
|
-
-
|
|
17
|
-
- flatter `FieldErrors` structure (
|
|
20
|
+
- throw in submit handler to add errors to RHF context and fail submit
|
|
21
|
+
- simpler/flatter `FieldErrors` structure (`FlatFieldErrors`)
|
|
22
|
+
- context groups errors into `all`, `fields`, `roots`, and `orphans` (`useFlatFieldErrorsContext`)
|
|
23
|
+
- `FormErrorMessageByPath` for displaying error message
|
|
18
24
|
- `zod` support
|
|
19
|
-
-
|
|
20
|
-
-
|
|
25
|
+
- including input/output types for transformations
|
|
26
|
+
- safer `FieldValues` type (`SafeFieldValues`)
|
|
27
|
+
- 3.3kB min+gzip core functionality (excluding [peer dependencies](#peer-dependencies))
|
|
21
28
|
|
|
22
29
|
## Install
|
|
23
30
|
|
|
@@ -65,8 +72,8 @@ export const rhfUtilsClientConfig: RhfUtilsClientConfig = {
|
|
|
65
72
|
formRef, // ref
|
|
66
73
|
context, // rhf UseFormReturn
|
|
67
74
|
options, // RhfUtilsFormOptions (with any custom props)
|
|
68
|
-
Controller, //
|
|
69
|
-
FormSubmitError, //
|
|
75
|
+
Controller, // rhf controller (SafeFieldValues-typed; no schema at this level)
|
|
76
|
+
FormSubmitError, // error class (SafeFieldValues-typed; no schema at this level)
|
|
70
77
|
children, // RhfUtilsZodForm's Children instance
|
|
71
78
|
},
|
|
72
79
|
) => {
|
|
@@ -147,7 +154,7 @@ Currently, only `zod` is supported.
|
|
|
147
154
|
// submit handler
|
|
148
155
|
onSubmit={async (
|
|
149
156
|
data, // schema output
|
|
150
|
-
context, // UseRhfUtilsFormOnSubmitContext (id, ref, rhf context, utils options,
|
|
157
|
+
context, // UseRhfUtilsFormOnSubmitContext (id, ref, rhf context, utils options, schema-typed FormSubmitError class)
|
|
151
158
|
event, // SubmitEvent
|
|
152
159
|
) => {
|
|
153
160
|
await loginService(data);
|
|
@@ -168,12 +175,12 @@ Currently, only `zod` is supported.
|
|
|
168
175
|
formRef, // ref
|
|
169
176
|
context, // rhf UseFormReturn
|
|
170
177
|
options, // RhfUtilsFormOptions
|
|
171
|
-
Controller, //
|
|
172
|
-
FormSubmitError, //
|
|
178
|
+
Controller, // schema-typed rhf controller
|
|
179
|
+
FormSubmitError, // schema-typed error class
|
|
173
180
|
}) => (
|
|
174
181
|
<>
|
|
175
182
|
<Controller
|
|
176
|
-
name="email" //
|
|
183
|
+
name="email" // schema-typed field name
|
|
177
184
|
render={({ field, formState: { isSubmitting } }) => (
|
|
178
185
|
<label>
|
|
179
186
|
Email
|
|
@@ -214,12 +221,12 @@ Currently, only `zod` is supported.
|
|
|
214
221
|
If you prefer to define your `Children` component as standalone:
|
|
215
222
|
|
|
216
223
|
```tsx
|
|
217
|
-
const Children: RhfUtilsUseFormChildrenZodFC<typeof schema> = ({
|
|
224
|
+
const Children: RhfUtilsUseFormChildrenZodFC<typeof schema> = ({...}) => { };
|
|
218
225
|
|
|
219
226
|
function Children({...}: RhfUtilsUseFormChildrenZodProps<typeof schema>) { }
|
|
220
227
|
```
|
|
221
228
|
|
|
222
|
-
## Component Hierarchy
|
|
229
|
+
## Form Component Hierarchy
|
|
223
230
|
|
|
224
231
|
```tsx
|
|
225
232
|
<ReactHookForm.FormProvider>
|
|
@@ -235,9 +242,9 @@ function Children({...}: RhfUtilsUseFormChildrenZodProps<typeof schema>) { }
|
|
|
235
242
|
|
|
236
243
|
## `FormSubmitError`
|
|
237
244
|
|
|
238
|
-
This is an `Error
|
|
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`.
|
|
239
246
|
|
|
240
|
-
It
|
|
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.
|
|
241
248
|
|
|
242
249
|
Example:
|
|
243
250
|
|
|
@@ -255,7 +262,7 @@ Example:
|
|
|
255
262
|
/>
|
|
256
263
|
```
|
|
257
264
|
|
|
258
|
-
Any non-`FormSubmitError`
|
|
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.
|
|
259
266
|
|
|
260
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.)
|
|
261
268
|
|
|
@@ -265,7 +272,7 @@ These options can be set globally and/or per form.
|
|
|
265
272
|
|
|
266
273
|
```ts
|
|
267
274
|
type RhfUtilsFormOptions = {
|
|
268
|
-
/** Stop propagation of submit event.
|
|
275
|
+
/** Stop propagation of submit event. */
|
|
269
276
|
stopSubmitPropagation?: boolean;
|
|
270
277
|
|
|
271
278
|
/** Request submit via listener on form change. */
|
|
@@ -286,7 +293,7 @@ type RhfUtilsFormOptions = {
|
|
|
286
293
|
};
|
|
287
294
|
```
|
|
288
295
|
|
|
289
|
-
If you need access to options deeper in component structure, use `useRhfUtilsContext` to receive `RhfUtilsContext` object, which includes `formId`, `formRef`, and `options` settings.
|
|
296
|
+
If you need access to options deeper in your component structure, use `useRhfUtilsContext` to receive `RhfUtilsContext` object, which includes `formId`, `formRef`, and `options` settings.
|
|
290
297
|
|
|
291
298
|
Use `useRhfUtilsContextRequestSubmit` hook to get `requestSubmit` function for current form ref in context. This is useful when you need to trigger form submission programatically.
|
|
292
299
|
|
|
@@ -307,39 +314,56 @@ declare module '@paragrav/rhf-utils' {
|
|
|
307
314
|
}
|
|
308
315
|
```
|
|
309
316
|
|
|
310
|
-
## Errors
|
|
317
|
+
## Field Errors
|
|
311
318
|
|
|
312
|
-
|
|
319
|
+
### FlatFieldErrors
|
|
320
|
+
|
|
321
|
+
`FlatFieldErrors` type is a flattened, simplified version of RHF's `FieldErrors`. Keys represent flattened, dot-notation field paths.
|
|
313
322
|
|
|
314
323
|
Use `useFlatFieldErrorsContext()` hook, which returns an object with errors grouped by `all`, `fields`, `roots`, `orphans` records, and `hasErrors` and `hasErrors` and `hasOrphans` booleans.
|
|
315
324
|
|
|
316
|
-
|
|
325
|
+
### Output
|
|
326
|
+
|
|
327
|
+
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).
|
|
317
328
|
|
|
318
329
|
### Orphan Errors
|
|
319
330
|
|
|
320
|
-
The concept of orphan errors is any error that is not being shown to user.
|
|
331
|
+
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.)
|
|
321
332
|
|
|
322
|
-
|
|
333
|
+
More technically, an "orphan" is any form state error that meets ALL of the following criteria:
|
|
323
334
|
|
|
324
|
-
- not a root error -- e
|
|
325
|
-
-
|
|
326
|
-
- has no
|
|
335
|
+
- not a root error -- i.e., `root` and `root.${string}` paths
|
|
336
|
+
- these are assumed to be listed for users somewhere
|
|
337
|
+
- has no `ref` -- RHF includes `ref` to the associated input for each error (when applicable)
|
|
338
|
+
- these are assumed to be shown next to their input fields
|
|
339
|
+
- has no marker in DOM (i.e., `FormNonFieldErrorMarker`)
|
|
340
|
+
- see section further below for more information
|
|
327
341
|
|
|
328
|
-
|
|
342
|
+
Detected orphans can be accessed via any of the following:
|
|
329
343
|
|
|
330
|
-
|
|
344
|
+
- via `RhfUtilsClientConfig.FieldErrors.output`; e.g.:
|
|
345
|
+
- console log to facilitate debugging on development
|
|
346
|
+
- console error to facilitate reporting on production (via your own error reporting service)
|
|
347
|
+
- throw error for developer during development
|
|
348
|
+
- `useFlatFieldErrorsContext()` hook
|
|
349
|
+
- returns an object with list of errors grouped by `all`, `fields` (with `ref`), `roots`, `orphans` records, and includes computed booleans `hasErrors` and `hasOrphans`
|
|
350
|
+
- boolean value from `useFlatFieldErrorsContextHasOnlyOrphans`
|
|
331
351
|
|
|
332
|
-
|
|
333
|
-
<FormErrorMessageByPath path="street.address" />
|
|
334
|
-
```
|
|
352
|
+
### FormNonFieldErrorMarker
|
|
335
353
|
|
|
336
|
-
|
|
354
|
+
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.)
|
|
337
355
|
|
|
338
|
-
|
|
356
|
+
#### When is the marker required?
|
|
339
357
|
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
358
|
+
For example, a field array with a minimum number of items -- e.g., `items: z.array(...).min(1)`.
|
|
359
|
+
|
|
360
|
+
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`.
|
|
361
|
+
|
|
362
|
+
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.
|
|
363
|
+
|
|
364
|
+
```tsx
|
|
365
|
+
<FormErrorMessageByPath path="items" />
|
|
366
|
+
```
|
|
343
367
|
|
|
344
368
|
## Form Groups
|
|
345
369
|
|
|
@@ -1,30 +1,39 @@
|
|
|
1
|
-
const
|
|
1
|
+
const u = (n, ...r) => (
|
|
2
2
|
// sequentially merge each set of props into defaults
|
|
3
|
-
|
|
4
|
-
(
|
|
5
|
-
var
|
|
3
|
+
r.reduce(
|
|
4
|
+
(t, e) => {
|
|
5
|
+
var s, i, l, m, o, f;
|
|
6
6
|
return {
|
|
7
7
|
rhf: {
|
|
8
|
-
...
|
|
8
|
+
...t == null ? void 0 : t.rhf,
|
|
9
9
|
...e.rhf
|
|
10
10
|
},
|
|
11
11
|
utils: {
|
|
12
|
-
...
|
|
13
|
-
...e.utils
|
|
12
|
+
...t == null ? void 0 : t.utils,
|
|
13
|
+
...e.utils,
|
|
14
|
+
// manual merges
|
|
15
|
+
// eslint-disable-next-line @typescript-eslint/prefer-nullish-coalescing -- false positive
|
|
16
|
+
...(((s = t == null ? void 0 : t.utils) == null ? void 0 : s.resetOnSubmitted) || ((i = e.utils) == null ? void 0 : i.resetOnSubmitted)) && {
|
|
17
|
+
resetOnSubmitted: {
|
|
18
|
+
...(l = t == null ? void 0 : t.utils) == null ? void 0 : l.resetOnSubmitted,
|
|
19
|
+
...(m = e.utils) == null ? void 0 : m.resetOnSubmitted
|
|
20
|
+
}
|
|
21
|
+
}
|
|
14
22
|
},
|
|
15
23
|
form: {
|
|
16
|
-
...
|
|
24
|
+
...t == null ? void 0 : t.form,
|
|
17
25
|
...e.form,
|
|
18
|
-
|
|
19
|
-
|
|
26
|
+
// manual merges
|
|
27
|
+
className: [(o = t == null ? void 0 : t.form) == null ? void 0 : o.className, (f = e.form) == null ? void 0 : f.className].filter(Boolean).join(" ") || void 0
|
|
28
|
+
// stringify (replace empty string with undefined)
|
|
20
29
|
}
|
|
21
30
|
};
|
|
22
31
|
},
|
|
23
32
|
// start with defaults
|
|
24
|
-
|
|
33
|
+
n
|
|
25
34
|
)
|
|
26
35
|
);
|
|
27
36
|
export {
|
|
28
|
-
|
|
37
|
+
u as mergeRhfUtilsClientConfigDefaultsWithUseRhfUtilsFormProps
|
|
29
38
|
};
|
|
30
39
|
//# sourceMappingURL=utils.mjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"utils.mjs","sources":["../../../src/client/utils.ts"],"sourcesContent":["import type { RhfUtilsFormOptions } from '@/form/RhfUtilsFormOptions';\nimport type { SafeFieldValues } from '@/form/SafeFieldValues';\nimport type { UseRhfUtilsFormProps } from '@/form/UseRhfUtilsFormProps';\n\nimport type { RhfUtilsClientConfig } from './config/RhfUtilsClientConfig';\n\n/**\n * Merge {@link RhfUtilsClientConfig.defaults} with array of {@link UseRhfUtilsFormProps}'s overrides.\n */\nexport const mergeRhfUtilsClientConfigDefaultsWithUseRhfUtilsFormProps = <\n TFieldValues extends SafeFieldValues,\n TTransformedValues extends SafeFieldValues,\n>(\n defaults: RhfUtilsClientConfig['defaults'],\n ...props: Pick<\n UseRhfUtilsFormProps<TFieldValues, TTransformedValues>,\n 'rhf' | 'utils' | 'form'\n >[]\n) =>\n // sequentially merge each set of props into defaults\n props.reduce(\n (acc, curr) => ({\n rhf: {\n ...acc?.rhf,\n ...curr.rhf,\n },\n\n utils: {\n ...acc?.utils,\n ...curr.utils,\n } satisfies RhfUtilsFormOptions,\n\n form: {\n ...acc?.form,\n ...curr.form,\n className
|
|
1
|
+
{"version":3,"file":"utils.mjs","sources":["../../../src/client/utils.ts"],"sourcesContent":["import type { RhfUtilsFormOptions } from '@/form/RhfUtilsFormOptions';\nimport type { SafeFieldValues } from '@/form/SafeFieldValues';\nimport type { UseRhfUtilsFormProps } from '@/form/UseRhfUtilsFormProps';\n\nimport type { RhfUtilsClientConfig } from './config/RhfUtilsClientConfig';\n\n/**\n * Merge {@link RhfUtilsClientConfig.defaults} with array of {@link UseRhfUtilsFormProps}'s overrides.\n */\nexport const mergeRhfUtilsClientConfigDefaultsWithUseRhfUtilsFormProps = <\n TFieldValues extends SafeFieldValues,\n TTransformedValues extends SafeFieldValues,\n>(\n defaults: RhfUtilsClientConfig['defaults'],\n ...props: Pick<\n UseRhfUtilsFormProps<TFieldValues, TTransformedValues>,\n 'rhf' | 'utils' | 'form'\n >[]\n) =>\n // sequentially merge each set of props into defaults\n props.reduce(\n (acc, curr) => ({\n rhf: {\n ...acc?.rhf,\n ...curr.rhf,\n },\n\n utils: {\n ...acc?.utils,\n ...curr.utils,\n\n // manual merges\n\n // eslint-disable-next-line @typescript-eslint/prefer-nullish-coalescing -- false positive\n ...((acc?.utils?.resetOnSubmitted || curr.utils?.resetOnSubmitted) && {\n resetOnSubmitted: {\n ...acc?.utils?.resetOnSubmitted,\n ...curr.utils?.resetOnSubmitted,\n },\n }),\n } satisfies RhfUtilsFormOptions,\n\n form: {\n ...acc?.form,\n ...curr.form,\n\n // manual merges\n\n className:\n [acc?.form?.className, curr.form?.className]\n .filter(Boolean) // filter out falsy values\n .join(' ') || undefined, // stringify (replace empty string with undefined)\n },\n }),\n\n // start with defaults\n defaults,\n );\n"],"names":["mergeRhfUtilsClientConfigDefaultsWithUseRhfUtilsFormProps","defaults","props","acc","curr","_a","_b","_c","_d","_e","_f"],"mappings":"AASa,MAAAA,IAA4D,CAIvEC,MACGC;AAAA;AAAA,EAMHA,EAAM;AAAA,IACJ,CAACC,GAAKC,MAAU;AAZP,UAAAC,GAAAC,GAAAC,GAAAC,GAAAC,GAAAC;AAYO;AAAA,QACd,KAAK;AAAA,UACH,GAAGP,KAAA,gBAAAA,EAAK;AAAA,UACR,GAAGC,EAAK;AAAA,QACV;AAAA,QAEA,OAAO;AAAA,UACL,GAAGD,KAAA,gBAAAA,EAAK;AAAA,UACR,GAAGC,EAAK;AAAA;AAAA;AAAA,UAKR,MAAKC,IAAAF,KAAA,gBAAAA,EAAK,UAAL,gBAAAE,EAAY,uBAAoBC,IAAAF,EAAK,UAAL,gBAAAE,EAAY,sBAAqB;AAAA,YACpE,kBAAkB;AAAA,cAChB,IAAGC,IAAAJ,KAAA,gBAAAA,EAAK,UAAL,gBAAAI,EAAY;AAAA,cACf,IAAGC,IAAAJ,EAAK,UAAL,gBAAAI,EAAY;AAAA,YACjB;AAAA,UACF;AAAA,QACF;AAAA,QAEA,MAAM;AAAA,UACJ,GAAGL,KAAA,gBAAAA,EAAK;AAAA,UACR,GAAGC,EAAK;AAAA;AAAA,UAIR,WACE,EAACK,IAAAN,KAAA,gBAAAA,EAAK,SAAL,gBAAAM,EAAW,YAAWC,IAAAN,EAAK,SAAL,gBAAAM,EAAW,SAAS,EACxC,OAAO,OAAO,EACd,KAAK,GAAG,KAAK;AAAA;AAAA,QACpB;AAAA,MAAA;AAAA;AAAA;AAAA,IAIFT;AAAA,EACF;AAAA;"}
|
|
@@ -5,8 +5,8 @@ import c from "./FormErrorMessage.mjs";
|
|
|
5
5
|
const f = ({ path: o, Component: s }) => {
|
|
6
6
|
const { errors: t } = g(), r = i(t, o, void 0), m = s ?? c;
|
|
7
7
|
return r != null && r.message ? /* @__PURE__ */ n(a, { children: [
|
|
8
|
-
/* @__PURE__ */ e(
|
|
9
|
-
/* @__PURE__ */ e(
|
|
8
|
+
/* @__PURE__ */ e(m, { message: r.message }),
|
|
9
|
+
/* @__PURE__ */ e(F, { path: o })
|
|
10
10
|
] }) : null;
|
|
11
11
|
}, E = f;
|
|
12
12
|
export {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"FormErrorMessageByPath.mjs","sources":["../../../../src/errors/message/FormErrorMessageByPath.tsx"],"sourcesContent":["import type { FieldError } from 'react-hook-form';\nimport { get, useFormState } from 'react-hook-form';\n\nimport FormNonFieldErrorMarker from '../nonfield/FormNonFieldErrorMarker';\n\nimport FormErrorMessage from './FormErrorMessage';\n\ntype Props = {\n /** Field name as flat path. (e.g., \"address.street\") */\n path: string;\n /** Optional component to use to display message. (Defaults to {@link FormErrorMessage}) */\n Component?: React.FC<{ message: string }>;\n};\n\nconst FormErrorMessageByPath: React.FC<Props> = ({ path, Component }) => {\n const { errors } = useFormState();\n\n const error = get(errors, path, undefined) as FieldError | undefined;\n\n const _Component = Component ?? FormErrorMessage;\n\n if (!error?.message) return null;\n\n return (\n <>\n {/* marker (only required for non-root non-field errors) */}\n <FormNonFieldErrorMarker path={path} />\n
|
|
1
|
+
{"version":3,"file":"FormErrorMessageByPath.mjs","sources":["../../../../src/errors/message/FormErrorMessageByPath.tsx"],"sourcesContent":["import type { FieldError } from 'react-hook-form';\nimport { get, useFormState } from 'react-hook-form';\n\nimport FormNonFieldErrorMarker from '../nonfield/FormNonFieldErrorMarker';\n\nimport FormErrorMessage from './FormErrorMessage';\n\ntype Props = {\n /** Field name as flat path. (e.g., \"address.street\") */\n path: string;\n /** Optional component to use to display message. (Defaults to {@link FormErrorMessage}) */\n Component?: React.FC<{ message: string }>;\n};\n\nconst FormErrorMessageByPath: React.FC<Props> = ({ path, Component }) => {\n const { errors } = useFormState();\n\n const error = get(errors, path, undefined) as FieldError | undefined;\n\n const _Component = Component ?? FormErrorMessage;\n\n if (!error?.message) return null;\n\n return (\n <>\n {/* error message */}\n <_Component message={error.message} />\n\n {/* marker (only required for non-root non-field errors) */}\n <FormNonFieldErrorMarker path={path} />\n </>\n );\n};\n\nexport default FormErrorMessageByPath;\n"],"names":["FormErrorMessageByPath","path","Component","errors","useFormState","error","get","_Component","FormErrorMessage","jsxs","Fragment","jsx","FormNonFieldErrorMarker","FormErrorMessageByPath$1"],"mappings":";;;;AAcA,MAAMA,IAA0C,CAAC,EAAE,MAAAC,GAAM,WAAAC,QAAgB;AACjE,QAAA,EAAE,QAAAC,MAAWC,KAEbC,IAAQC,EAAIH,GAAQF,GAAM,MAAS,GAEnCM,IAAaL,KAAaM;AAE5B,SAACH,KAAA,QAAAA,EAAO,UAKR,gBAAAI,EAAAC,GAAA,EAAA,UAAA;AAAA,IAAC,gBAAAC,EAAAJ,GAAA,EAAW,SAASF,EAAM,QAAS,CAAA;AAAA,IAGpC,gBAAAM,EAACC,KAAwB,MAAAX,GAAY;AAAA,EACvC,EAAA,CAAA,IAT0B;AAW9B,GAEAY,IAAeb;"}
|
package/dist/esm/form/Form.mjs
CHANGED
|
@@ -1,87 +1,87 @@
|
|
|
1
|
-
import { jsx as
|
|
1
|
+
import { jsx as c, jsxs as j } from "react/jsx-runtime";
|
|
2
2
|
import "react";
|
|
3
|
-
import { useFormContext as
|
|
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
|
|
6
|
+
import { FormSubmitError as d } from "../submit/error/FormSubmitError.mjs";
|
|
7
7
|
import S from "../submit/error/setCtxErrorsByFormSubmitErrors.mjs";
|
|
8
8
|
import U from "../utils/PassthroughChildren.mjs";
|
|
9
|
-
import
|
|
10
|
-
function
|
|
11
|
-
formId:
|
|
12
|
-
formRef:
|
|
9
|
+
import _ from "./_Controller.mjs";
|
|
10
|
+
function G({
|
|
11
|
+
formId: m,
|
|
12
|
+
formRef: p,
|
|
13
13
|
//
|
|
14
14
|
onSubmit: a,
|
|
15
|
-
onSubmitError:
|
|
16
|
-
onSubmitInvalid:
|
|
15
|
+
onSubmitError: s,
|
|
16
|
+
onSubmitInvalid: x,
|
|
17
17
|
Children: l,
|
|
18
18
|
//
|
|
19
19
|
form: F,
|
|
20
20
|
utils: r
|
|
21
21
|
}) {
|
|
22
|
-
const e =
|
|
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,
|
|
25
|
+
await e.handleSubmit(f, x)(o);
|
|
26
26
|
} catch (n) {
|
|
27
|
-
|
|
27
|
+
P(n, o);
|
|
28
28
|
}
|
|
29
29
|
}, f = (o, n) => a == null ? void 0 : a(
|
|
30
30
|
o,
|
|
31
31
|
{
|
|
32
|
-
formId:
|
|
33
|
-
formRef:
|
|
32
|
+
formId: m,
|
|
33
|
+
formRef: p,
|
|
34
34
|
context: e,
|
|
35
35
|
utils: r,
|
|
36
|
-
FormSubmitError:
|
|
36
|
+
FormSubmitError: d
|
|
37
37
|
},
|
|
38
38
|
n
|
|
39
|
-
),
|
|
40
|
-
var
|
|
41
|
-
const C = o instanceof
|
|
39
|
+
), P = (o, n) => {
|
|
40
|
+
var i;
|
|
41
|
+
const C = o instanceof d ? (
|
|
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),
|
|
48
|
+
C && S(e, C), s == null || s(
|
|
49
49
|
o,
|
|
50
50
|
{
|
|
51
|
-
formId:
|
|
52
|
-
formRef:
|
|
51
|
+
formId: m,
|
|
52
|
+
formRef: p,
|
|
53
53
|
context: e,
|
|
54
54
|
utils: r
|
|
55
55
|
},
|
|
56
56
|
n
|
|
57
57
|
);
|
|
58
|
-
},
|
|
59
|
-
formId:
|
|
60
|
-
formRef:
|
|
58
|
+
}, h = {
|
|
59
|
+
formId: m,
|
|
60
|
+
formRef: p,
|
|
61
61
|
context: e,
|
|
62
62
|
utils: r,
|
|
63
|
-
Controller:
|
|
64
|
-
FormSubmitError:
|
|
65
|
-
}, v = (t == null ? void 0 : t.FormComponent) ?? "form",
|
|
66
|
-
return /* @__PURE__ */
|
|
63
|
+
Controller: _,
|
|
64
|
+
FormSubmitError: d
|
|
65
|
+
}, b = h, v = (t == null ? void 0 : t.FormComponent) ?? "form", T = (t == null ? void 0 : t.FormChildrenWrapper) ?? U;
|
|
66
|
+
return /* @__PURE__ */ c(
|
|
67
67
|
v,
|
|
68
68
|
{
|
|
69
69
|
...F,
|
|
70
|
-
ref:
|
|
70
|
+
ref: p,
|
|
71
71
|
onSubmit: (o) => void y(o),
|
|
72
|
-
children: /* @__PURE__ */ T
|
|
73
|
-
(r == null ? void 0 : r.devTool) && /* @__PURE__ */
|
|
72
|
+
children: /* @__PURE__ */ j(T, { ...b, children: [
|
|
73
|
+
(r == null ? void 0 : r.devTool) && /* @__PURE__ */ c(
|
|
74
74
|
E,
|
|
75
75
|
{
|
|
76
76
|
props: typeof r.devTool == "object" ? r.devTool : void 0
|
|
77
77
|
}
|
|
78
78
|
),
|
|
79
|
-
/* @__PURE__ */
|
|
79
|
+
/* @__PURE__ */ c(l, { ...h })
|
|
80
80
|
] })
|
|
81
81
|
}
|
|
82
82
|
);
|
|
83
83
|
}
|
|
84
84
|
export {
|
|
85
|
-
|
|
85
|
+
G as default
|
|
86
86
|
};
|
|
87
87
|
//# sourceMappingURL=Form.mjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Form.mjs","sources":["../../../src/form/Form.tsx"],"sourcesContent":["import React from 'react';\nimport type { UseFormHandleSubmit } from 'react-hook-form';\nimport { useFormContext } from 'react-hook-form';\n\nimport useRhfUtilsClientConfigMaybeContext from '@/client/config/useRhfUtilsClientConfigContext';\n\nimport LazyDevTool from '@/devtool/LazyDevTool';\n\nimport { FormSubmitError } from '@/submit/error/FormSubmitError';\nimport setCtxErrorsByFormSubmitErrors from '@/submit/error/setCtxErrorsByFormSubmitErrors';\n\nimport PassthroughChildren from '@/utils/PassthroughChildren';\n\nimport _Controller from './_Controller';\nimport type { SafeFieldValues } from './SafeFieldValues';\nimport type { UseRhfUtilsFormChildrenProps } from './UseRhfUtilsFormChildrenProps';\nimport type {\n UseRhfUtilsFormOnSubmitContext,\n UseRhfUtilsFormOnSubmitErrorContext,\n} from './UseRhfUtilsFormOnSubmitContext';\nimport type { UseRhfUtilsFormProps } from './UseRhfUtilsFormProps';\n\nexport type FormChildrenSlots = 'top' | 'bottom';\n\nexport type FormProps<\n TFieldValues extends SafeFieldValues,\n TTransformedValues extends SafeFieldValues,\n> = {\n formId: string;\n formRef: React.RefObject<HTMLFormElement>;\n} & Pick<\n UseRhfUtilsFormProps<TFieldValues, TTransformedValues>,\n | 'onSubmit'\n | 'onSubmitError'\n | 'onSubmitInvalid'\n //\n | 'Children'\n //\n | 'form'\n | 'utils'\n>;\n\nfunction _Form<\n TFieldValues extends SafeFieldValues,\n TTransformedValues extends SafeFieldValues,\n>({\n formId,\n formRef,\n //\n onSubmit,\n onSubmitError,\n onSubmitInvalid,\n Children,\n //\n form,\n utils,\n}: FormProps<TFieldValues, TTransformedValues>) {\n const rhfContext = useFormContext<\n TFieldValues,\n unknown,\n TTransformedValues\n >();\n\n const config = useRhfUtilsClientConfigMaybeContext();\n\n // handlers\n\n const handleSubmit = async (event: React.FormEvent<HTMLFormElement>) => {\n // cannot stop propagation in handleSubmitValid, b/c it receives a different event object\n if (utils?.stopSubmitPropagation) event.stopPropagation();\n\n try {\n await rhfContext.handleSubmit(handleSubmitValid, onSubmitInvalid)(event);\n } catch (error) {\n handleSubmitError(error, event);\n }\n };\n\n const handleSubmitValid = ((\n data: TTransformedValues,\n event?: React.BaseSyntheticEvent,\n ) => {\n return onSubmit?.(\n data,\n {\n formId,\n formRef,\n context: rhfContext,\n utils,\n FormSubmitError: FormSubmitError<TFieldValues>,\n } satisfies UseRhfUtilsFormOnSubmitContext<\n TFieldValues,\n TTransformedValues\n >,\n event as React.BaseSyntheticEvent<SubmitEvent>, // `as` required due to conditional generic\n );\n }) as Parameters<UseFormHandleSubmit<TFieldValues, TTransformedValues>>[0];\n\n const handleSubmitError = (\n error: unknown,\n event: React.BaseSyntheticEvent,\n ) => {\n // get `FormSubmitErrors`, if possible\n const formSubmitErrors =\n error instanceof FormSubmitError\n ? // consumer can manually throw FormSubmitError (e.g., manual validation)\n (error as FormSubmitError).errors // `as` to avoid `<any>`\n : // if error is not FormSubmitError, consumer can provide global handler\n config?.onSubmitErrorUnknown?.(error);\n\n if (formSubmitErrors)\n setCtxErrorsByFormSubmitErrors(rhfContext, formSubmitErrors);\n\n onSubmitError?.(\n error,\n {\n formId,\n formRef,\n context: rhfContext,\n utils,\n } satisfies UseRhfUtilsFormOnSubmitErrorContext<\n TFieldValues,\n TTransformedValues\n >,\n event as React.BaseSyntheticEvent<SubmitEvent>, // `as` required due to conditional generic\n );\n };\n\n const childrenProps: UseRhfUtilsFormChildrenProps<\n TFieldValues,\n TTransformedValues\n > = {\n formId,\n formRef,\n context: rhfContext,\n utils,\n Controller: _Controller<TFieldValues>,\n FormSubmitError: FormSubmitError<TFieldValues>,\n };\n\n const FormComponent = config?.FormComponent ?? 'form';\n\n const FormChildrenWrapper =\n config?.FormChildrenWrapper ?? PassthroughChildren;\n\n return (\n <FormComponent\n {...form}\n ref={formRef}\n onSubmit={(e) => void handleSubmit(e)}\n >\n <FormChildrenWrapper {...
|
|
1
|
+
{"version":3,"file":"Form.mjs","sources":["../../../src/form/Form.tsx"],"sourcesContent":["import React from 'react';\nimport type { UseFormHandleSubmit } from 'react-hook-form';\nimport { useFormContext } from 'react-hook-form';\n\nimport type { RhfUtilsFormChildrenWrapperProps } from '@/client/config/RhfUtilsClientConfig';\nimport useRhfUtilsClientConfigMaybeContext from '@/client/config/useRhfUtilsClientConfigContext';\n\nimport LazyDevTool from '@/devtool/LazyDevTool';\n\nimport { FormSubmitError } from '@/submit/error/FormSubmitError';\nimport setCtxErrorsByFormSubmitErrors from '@/submit/error/setCtxErrorsByFormSubmitErrors';\n\nimport PassthroughChildren from '@/utils/PassthroughChildren';\n\nimport _Controller from './_Controller';\nimport type { SafeFieldValues } from './SafeFieldValues';\nimport type { UseRhfUtilsFormChildrenProps } from './UseRhfUtilsFormChildrenProps';\nimport type {\n UseRhfUtilsFormOnSubmitContext,\n UseRhfUtilsFormOnSubmitErrorContext,\n} from './UseRhfUtilsFormOnSubmitContext';\nimport type { UseRhfUtilsFormProps } from './UseRhfUtilsFormProps';\n\nexport type FormChildrenSlots = 'top' | 'bottom';\n\nexport type FormProps<\n TFieldValues extends SafeFieldValues,\n TTransformedValues extends SafeFieldValues,\n> = {\n formId: string;\n formRef: React.RefObject<HTMLFormElement>;\n} & Pick<\n UseRhfUtilsFormProps<TFieldValues, TTransformedValues>,\n | 'onSubmit'\n | 'onSubmitError'\n | 'onSubmitInvalid'\n //\n | 'Children'\n //\n | 'form'\n | 'utils'\n>;\n\nfunction _Form<\n TFieldValues extends SafeFieldValues,\n TTransformedValues extends SafeFieldValues,\n>({\n formId,\n formRef,\n //\n onSubmit,\n onSubmitError,\n onSubmitInvalid,\n Children,\n //\n form,\n utils,\n}: FormProps<TFieldValues, TTransformedValues>) {\n const rhfContext = useFormContext<\n TFieldValues,\n unknown,\n TTransformedValues\n >();\n\n const config = useRhfUtilsClientConfigMaybeContext();\n\n // handlers\n\n const handleSubmit = async (event: React.FormEvent<HTMLFormElement>) => {\n // cannot stop propagation in handleSubmitValid, b/c it receives a different event object\n if (utils?.stopSubmitPropagation) event.stopPropagation();\n\n try {\n await rhfContext.handleSubmit(handleSubmitValid, onSubmitInvalid)(event);\n } catch (error) {\n handleSubmitError(error, event);\n }\n };\n\n const handleSubmitValid = ((\n data: TTransformedValues,\n event?: React.BaseSyntheticEvent,\n ) => {\n return onSubmit?.(\n data,\n {\n formId,\n formRef,\n context: rhfContext,\n utils,\n FormSubmitError: FormSubmitError<TFieldValues>,\n } satisfies UseRhfUtilsFormOnSubmitContext<\n TFieldValues,\n TTransformedValues\n >,\n event as React.BaseSyntheticEvent<SubmitEvent>, // `as` required due to conditional generic\n );\n }) as Parameters<UseFormHandleSubmit<TFieldValues, TTransformedValues>>[0];\n\n const handleSubmitError = (\n error: unknown,\n event: React.BaseSyntheticEvent,\n ) => {\n // get `FormSubmitErrors`, if possible\n const formSubmitErrors =\n error instanceof FormSubmitError\n ? // consumer can manually throw FormSubmitError (e.g., manual validation)\n (error as FormSubmitError).errors // `as` to avoid `<any>`\n : // if error is not FormSubmitError, consumer can provide global handler\n config?.onSubmitErrorUnknown?.(error);\n\n if (formSubmitErrors)\n setCtxErrorsByFormSubmitErrors(rhfContext, formSubmitErrors);\n\n onSubmitError?.(\n error,\n {\n formId,\n formRef,\n context: rhfContext,\n utils,\n } satisfies UseRhfUtilsFormOnSubmitErrorContext<\n TFieldValues,\n TTransformedValues\n >,\n event as React.BaseSyntheticEvent<SubmitEvent>, // `as` required due to conditional generic\n );\n };\n\n const childrenProps: UseRhfUtilsFormChildrenProps<\n TFieldValues,\n TTransformedValues\n > = {\n formId,\n formRef,\n context: rhfContext,\n utils,\n Controller: _Controller<TFieldValues>,\n FormSubmitError: FormSubmitError<TFieldValues>,\n };\n\n // children wrapper is not specific to schema (not possible)\n const childrenWrapperProps =\n childrenProps as RhfUtilsFormChildrenWrapperProps;\n\n const FormComponent = config?.FormComponent ?? 'form';\n\n const FormChildrenWrapper =\n config?.FormChildrenWrapper ?? PassthroughChildren;\n\n return (\n <FormComponent\n {...form}\n ref={formRef}\n onSubmit={(e) => void handleSubmit(e)}\n >\n <FormChildrenWrapper {...childrenWrapperProps}>\n {utils?.devTool && (\n <LazyDevTool\n props={\n typeof utils.devTool === 'object' ? utils.devTool : undefined\n }\n />\n )}\n\n <Children {...childrenProps} />\n </FormChildrenWrapper>\n </FormComponent>\n );\n}\n\nexport default _Form;\n"],"names":["_Form","formId","formRef","onSubmit","onSubmitError","onSubmitInvalid","Children","form","utils","rhfContext","useFormContext","config","useRhfUtilsClientConfigMaybeContext","handleSubmit","event","handleSubmitValid","error","handleSubmitError","data","FormSubmitError","formSubmitErrors","_a","setCtxErrorsByFormSubmitErrors","childrenProps","_Controller","childrenWrapperProps","FormComponent","FormChildrenWrapper","PassthroughChildren","jsx","e","jsxs","LazyDevTool"],"mappings":";;;;;;;;;AA2CA,SAASA,EAGP;AAAA,EACA,QAAAC;AAAA,EACA,SAAAC;AAAA;AAAA,EAEA,UAAAC;AAAA,EACA,eAAAC;AAAA,EACA,iBAAAC;AAAA,EACA,UAAAC;AAAA;AAAA,EAEA,MAAAC;AAAA,EACA,OAAAC;AACF,GAAgD;AAC9C,QAAMC,IAAaC,KAMbC,IAASC,KAITC,IAAe,OAAOC,MAA4C;AAElE,IAAAN,KAAA,QAAAA,EAAO,yBAAuBM,EAAM,gBAAgB;AAEpD,QAAA;AACF,YAAML,EAAW,aAAaM,GAAmBV,CAAe,EAAES,CAAK;AAAA,aAChEE,GAAO;AACd,MAAAC,EAAkBD,GAAOF,CAAK;AAAA,IAChC;AAAA,EAAA,GAGIC,IAAqB,CACzBG,GACAJ,MAEOX,KAAA,gBAAAA;AAAA,IACLe;AAAA,IACA;AAAA,MACE,QAAAjB;AAAA,MACA,SAAAC;AAAA,MACA,SAASO;AAAA,MACT,OAAAD;AAAA,MACA,iBAAAW;AAAA,IACF;AAAA,IAIAL;AAAA,KAIEG,IAAoB,CACxBD,GACAF,MACG;;AAEH,UAAMM,IACJJ,aAAiBG;AAAA;AAAA,MAEZH,EAA0B;AAAA;AAAA;AAAA,OAE3BK,IAAAV,KAAA,gBAAAA,EAAQ,yBAAR,gBAAAU,EAAA,KAAAV,GAA+BK;AAAA;AAEjC,IAAAI,KACFE,EAA+Bb,GAAYW,CAAgB,GAE7DhB,KAAA,QAAAA;AAAA,MACEY;AAAA,MACA;AAAA,QACE,QAAAf;AAAA,QACA,SAAAC;AAAA,QACA,SAASO;AAAA,QACT,OAAAD;AAAA,MACF;AAAA,MAIAM;AAAA;AAAA,EACF,GAGIS,IAGF;AAAA,IACF,QAAAtB;AAAA,IACA,SAAAC;AAAA,IACA,SAASO;AAAA,IACT,OAAAD;AAAA,IACA,YAAYgB;AAAA,IACZ,iBAAAL;AAAA,EAAA,GAIIM,IACJF,GAEIG,KAAgBf,KAAA,gBAAAA,EAAQ,kBAAiB,QAEzCgB,KACJhB,KAAA,gBAAAA,EAAQ,wBAAuBiB;AAG/B,SAAA,gBAAAC;AAAA,IAACH;AAAA,IAAA;AAAA,MACE,GAAGnB;AAAA,MACJ,KAAKL;AAAA,MACL,UAAU,CAAC4B,MAAM,KAAKjB,EAAaiB,CAAC;AAAA,MAEpC,UAAA,gBAAAC,EAACJ,GAAqB,EAAA,GAAGF,GACtB,UAAA;AAAA,SAAAjB,KAAA,gBAAAA,EAAO,YACN,gBAAAqB;AAAA,UAACG;AAAA,UAAA;AAAA,YACC,OACE,OAAOxB,EAAM,WAAY,WAAWA,EAAM,UAAU;AAAA,UAAA;AAAA,QAExD;AAAA,QAGF,gBAAAqB,EAACvB,GAAU,EAAA,GAAGiB,GAAe;AAAA,MAAA,GAC/B;AAAA,IAAA;AAAA,EAAA;AAGN;"}
|
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import { UseFormProps } from 'react-hook-form';
|
|
2
2
|
import { FlatFieldErrorsOutputConfig } from '../../errors/flat/context/FlatFieldErrorsOutputConfig';
|
|
3
3
|
import { RhfUtilsFormOptions } from '../../form/RhfUtilsFormOptions';
|
|
4
|
-
import { SafeFieldValues } from '../../form/SafeFieldValues';
|
|
5
4
|
import { UseRhfUtilsFormChildrenProps } from '../../form/UseRhfUtilsFormChildrenProps';
|
|
6
5
|
import { FormSubmitErrors } from '../../submit/error/FormSubmitErrors';
|
|
7
6
|
|
|
@@ -41,11 +40,13 @@ export type RhfUtilsClientConfig = {
|
|
|
41
40
|
/**
|
|
42
41
|
* Wrap all form bodies with your own hooks, components, etc.
|
|
43
42
|
*
|
|
43
|
+
* (NOTE: not schema-typed as not possible at this level)
|
|
44
|
+
*
|
|
44
45
|
* Use cases:
|
|
45
46
|
* - custom hooks/behaviors based on `options`
|
|
46
47
|
* - shared header, footer
|
|
47
48
|
*/
|
|
48
|
-
FormChildrenWrapper?:
|
|
49
|
+
FormChildrenWrapper?: (props: RhfUtilsFormChildrenWrapperProps) => React.ReactNode;
|
|
49
50
|
/**
|
|
50
51
|
* Global submit error handler when/if submit handler throws an error other than {@link FormSubmitError}.
|
|
51
52
|
*
|
|
@@ -64,3 +65,7 @@ export type RhfUtilsClientConfig = {
|
|
|
64
65
|
output?: FlatFieldErrorsOutputConfig;
|
|
65
66
|
};
|
|
66
67
|
};
|
|
68
|
+
/**
|
|
69
|
+
* Non-schema-typed version of `UseRhfUtilsFormChildrenProps` for global config.
|
|
70
|
+
*/
|
|
71
|
+
export type RhfUtilsFormChildrenWrapperProps = React.PropsWithChildren<UseRhfUtilsFormChildrenProps>;
|
|
@@ -8,7 +8,7 @@ import { Register } from '../register';
|
|
|
8
8
|
* Can be extended using {@link Register.RhfUtilsFormOptions}.
|
|
9
9
|
*/
|
|
10
10
|
export type RhfUtilsFormOptions = {
|
|
11
|
-
/** Stop propagation of submit event.
|
|
11
|
+
/** Stop propagation of submit event. */
|
|
12
12
|
stopSubmitPropagation?: boolean;
|
|
13
13
|
/** Request submit via listener on form change. */
|
|
14
14
|
submitOnChange?: boolean;
|
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.
|
|
5
|
+
"version": "0.0.135",
|
|
6
6
|
"description": "Integration utilities for react-hook-form.",
|
|
7
7
|
"type": "module",
|
|
8
8
|
"sideEffects": false,
|
|
@@ -30,6 +30,10 @@
|
|
|
30
30
|
"react-hook-form": "7",
|
|
31
31
|
"zod": "3"
|
|
32
32
|
},
|
|
33
|
+
"resolutions": {
|
|
34
|
+
"@playwright/experimental-ct-react": "1.44.1",
|
|
35
|
+
"@playwright/test": "1.44.1"
|
|
36
|
+
},
|
|
33
37
|
"repository": {
|
|
34
38
|
"type": "git",
|
|
35
39
|
"url": "git+https://github.com/paragrav/rhf-utils.git"
|