@paragrav/rhf-utils 0.0.139 → 0.0.140
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/README.md +20 -2
- package/dist/esm/group.mjs +74 -0
- package/dist/esm/{exports.mjs → main.mjs} +161 -163
- package/dist/esm/trpc.mjs +41 -0
- package/dist/esm/useFlatFieldErrorsContext.mjs +10 -0
- package/dist/esm/utils.mjs +20 -0
- package/dist/types/group.d.ts +9 -0
- package/dist/types/main.d.ts +15 -1
- package/dist/types/trpc.d.ts +2 -0
- package/dist/types/utils.d.ts +1 -0
- package/package.json +19 -7
- package/dist/esm/form/context/group/exports.mjs +0 -74
- package/dist/types/client/config/RhfUtilsClientConfig.d.ts +0 -71
- package/dist/types/client/config/useRhfUtilsClientConfigContext.d.ts +0 -5
- package/dist/types/client/context.d.ts +0 -3
- package/dist/types/client/index.d.ts +0 -30
- package/dist/types/client/utils.d.ts +0 -13
- package/dist/types/client/zod/RhfUtilsUseFormChildrenZodFC.d.ts +0 -13
- package/dist/types/client/zod/RhfUtilsUseFormChildrenZodProps.d.ts +0 -5
- package/dist/types/client/zod/ZodTypeFieldValues.d.ts +0 -4
- package/dist/types/client/zod/consts.d.ts +0 -4
- package/dist/types/client/zod/context/RhfUtilsClientForZodContextProvider.d.ts +0 -8
- package/dist/types/client/zod/context/RhfUtilsZodForm.d.ts +0 -9
- package/dist/types/client/zod/context/useRhfUtilsClientForZodContext.d.ts +0 -6
- package/dist/types/client/zod/context/useRhfUtilsZodForm.d.ts +0 -8
- package/dist/types/client/zod/createRhfUtilsClientForZod.d.ts +0 -4
- package/dist/types/devtool/LazyDevTool.d.ts +0 -12
- package/dist/types/errors/flat/FlatFieldErrorsList.d.ts +0 -7
- package/dist/types/errors/flat/context/FlatFieldErrorsContextProvider.d.ts +0 -11
- package/dist/types/errors/flat/context/FlatFieldErrorsOutputConfig.d.ts +0 -20
- package/dist/types/errors/flat/context/useFlatFieldErrorsContext.d.ts +0 -13
- package/dist/types/errors/flat/context/useFlatFieldErrorsContextHasOnlyOrphans.d.ts +0 -7
- package/dist/types/errors/flat/context/useFlatFieldErrorsContextOutput.d.ts +0 -7
- package/dist/types/errors/flat/filterFlatFieldErrors.d.ts +0 -9
- package/dist/types/errors/flat/flattenFieldErrors.d.ts +0 -16
- package/dist/types/errors/flat/getFlatFieldErrors.d.ts +0 -32
- package/dist/types/errors/flat/types.d.ts +0 -17
- package/dist/types/errors/getRefdFromFlatFieldErrors.d.ts +0 -2
- package/dist/types/errors/isFieldErrorRefd.d.ts +0 -7
- package/dist/types/errors/isFlatFieldErrorEntryRefd.d.ts +0 -7
- package/dist/types/errors/message/FormErrorMessage.d.ts +0 -8
- package/dist/types/errors/message/RhfUtilsFieldErrorMessage.d.ts +0 -10
- package/dist/types/errors/nonfield/RhfUtilsNonFieldErrorMarker.d.ts +0 -13
- package/dist/types/errors/nonfield/RhfUtilsNonFieldErrorMarker.spec.d.ts +0 -1
- package/dist/types/errors/nonfield/RhfUtilsNonFieldErrorMarker.utils.d.ts +0 -18
- package/dist/types/errors/nonfield/RhfUtilsNonFieldErrorMarkerHtmlAttribute.d.ts +0 -5
- package/dist/types/errors/nonfield/isNonFieldError.d.ts +0 -19
- package/dist/types/errors/nonfield/isNonFieldErrorMarkerInDOM.d.ts +0 -6
- package/dist/types/errors/orphan/getIsOrphanFormErrorWithParentElement.d.ts +0 -7
- package/dist/types/errors/orphan/getOrphansFromFlatFieldErrors.d.ts +0 -4
- package/dist/types/errors/orphan/isOrphanFormError.d.ts +0 -4
- package/dist/types/errors/output/consoleErrors.d.ts +0 -7
- package/dist/types/errors/output/types.d.ts +0 -7
- package/dist/types/errors/root/RootErrorsListFromFlatFieldErrorsContext.d.ts +0 -2
- package/dist/types/errors/root/consts.d.ts +0 -1
- package/dist/types/errors/root/getRootsFromFlatFieldErrors.d.ts +0 -2
- package/dist/types/errors/root/isFlatFieldErrorEntryPathRoot.d.ts +0 -7
- package/dist/types/errors/root/isFormErrorPathRoot.d.ts +0 -7
- package/dist/types/errors/trpc/getOnSubmitTrpcClientErrorHandler.d.ts +0 -11
- package/dist/types/errors/trpc/trpcClientErrorMessageSchema.d.ts +0 -24
- package/dist/types/errors/trpc/trpcClientErrorToFormSubmitFieldErrorsSchemaTransformer.d.ts +0 -28
- package/dist/types/exports.d.ts +0 -15
- package/dist/types/form/Form.d.ts +0 -11
- package/dist/types/form/FormWithProviders.d.ts +0 -13
- package/dist/types/form/RhfUtilsFormOptions.d.ts +0 -29
- package/dist/types/form/RhfUtilsFormProviders.d.ts +0 -12
- package/dist/types/form/SafeFieldValues.d.ts +0 -4
- package/dist/types/form/UseRhfUtilsFormChildrenProps.d.ts +0 -20
- package/dist/types/form/UseRhfUtilsFormOnSubmitContext.d.ts +0 -27
- package/dist/types/form/UseRhfUtilsFormProps.d.ts +0 -23
- package/dist/types/form/UseRhfUtilsFormReturn.d.ts +0 -20
- package/dist/types/form/_Controller.d.ts +0 -6
- package/dist/types/form/context/group/FormGroupContextProvider.d.ts +0 -5
- package/dist/types/form/context/group/exports.d.ts +0 -9
- package/dist/types/form/context/group/index.d.ts +0 -14
- package/dist/types/form/context/group/useFormGroupChildIsMountedTracker.d.ts +0 -5
- package/dist/types/form/context/group/useFormGroupChildIsSubmittingTracker.d.ts +0 -5
- package/dist/types/form/context/group/useFormGroupChildTracker.d.ts +0 -6
- package/dist/types/form/context/group/useFormGroupIsAnyBusy.d.ts +0 -2
- package/dist/types/form/context/group/useFormGroupIsChildBusy.d.ts +0 -2
- package/dist/types/form/context/group/useFormGroupIsParentBusy.d.ts +0 -2
- package/dist/types/form/context/group/useFormGroupParentTracker.d.ts +0 -7
- package/dist/types/form/context/group/useFormOrParentIsBusy.d.ts +0 -2
- package/dist/types/form/context/utils/RhfUtilsContextProvider.d.ts +0 -9
- package/dist/types/form/context/utils/useRhfUtilsContext.d.ts +0 -14
- package/dist/types/form/context/utils/useRhfUtilsContextRequestSubmit.d.ts +0 -5
- package/dist/types/form/useFormIsBusy.d.ts +0 -2
- package/dist/types/form/useRhfUtilsForm.d.ts +0 -16
- package/dist/types/form/utils/getSubmitterButtonData.d.ts +0 -8
- package/dist/types/form/utils/useFormRequestSubmit.d.ts +0 -11
- package/dist/types/form/utils/useShouldFormBlockNavigation.d.ts +0 -26
- package/dist/types/register.d.ts +0 -7
- package/dist/types/submit/error/FormSubmitError.d.ts +0 -7
- package/dist/types/submit/error/FormSubmitFieldErrors.d.ts +0 -15
- package/dist/types/submit/error/setCtxErrorsByFormSubmitFieldErrors.d.ts +0 -10
- package/dist/types/submit/useFormOnSubmitSuccessfulAndReset.d.ts +0 -15
- package/dist/types/submit/useFormOnSubmitted.d.ts +0 -6
- package/dist/types/submit/useResetFormOnSubmitted.d.ts +0 -36
- package/dist/types/submit/useSubmitFormOnChange.d.ts +0 -9
- package/dist/types/utils/PassthroughChildren.d.ts +0 -7
- package/dist/types/utils/createContext.d.ts +0 -12
- package/dist/types/utils/fixedForwardRef.d.ts +0 -7
- package/dist/types/utils/isEmptyObject.d.ts +0 -2
- package/dist/types/utils/timeoutAsync.d.ts +0 -6
- package/dist/types/utils/types.d.ts +0 -1
- package/dist/types/utils/useDebouncedOnChangeValue.d.ts +0 -14
- package/dist/types/utils/useImperativeForwardedRef.d.ts +0 -11
- package/dist/types/utils/useRefIfValueWasTrue.d.ts +0 -2
- package/dist/types/utils/useThrowAsyncError.d.ts +0 -5
- package/dist/types/utils/useToggle.d.ts +0 -4
- /package/dist/esm/{createContext-Jzs0Nsql.js → createContext.mjs} +0 -0
package/README.md
CHANGED
|
@@ -24,7 +24,7 @@ Integration and utility library for [react-hook-form](https://www.react-hook-for
|
|
|
24
24
|
- context groups errors into `all`, `fields`, `roots`, and `orphans` (`useFlatFieldErrorsContext`)
|
|
25
25
|
- safer `FieldValues` type (`SafeFieldValues`)
|
|
26
26
|
- `zod` support, including input/output types for transformations
|
|
27
|
-
- ~3.
|
|
27
|
+
- ~3.2kB min+gzip core (excluding [peer dependencies](#peer-dependencies))
|
|
28
28
|
|
|
29
29
|
## Install
|
|
30
30
|
|
|
@@ -381,7 +381,9 @@ You should incorporate `RhfUtilsNonFieldErrorMarker` into your own component lib
|
|
|
381
381
|
|
|
382
382
|
_If you include the marker in bulk error lists, it will defeat the purpose of the marker. Only use marker for individual errors. Therefore, if you are ONLY listing a summary of all errors, without individual displays, you will need to use the marker manually._
|
|
383
383
|
|
|
384
|
-
##
|
|
384
|
+
## Other Features
|
|
385
|
+
|
|
386
|
+
### Form Groups _(0.65kB min+gzip)_
|
|
385
387
|
|
|
386
388
|
Sometimes you need to group multiple forms together.
|
|
387
389
|
|
|
@@ -406,6 +408,22 @@ In children forms, there are two options. You can choose to consider form "busy"
|
|
|
406
408
|
|
|
407
409
|
Both hooks return `boolean` value indicating whether parent form is busy.
|
|
408
410
|
|
|
411
|
+
### TRPC.io Utils _(0.41kB min+gzip)_
|
|
412
|
+
|
|
413
|
+
#### `trpcClientErrorToFormSubmitFieldErrorsSchemaTransformer`
|
|
414
|
+
|
|
415
|
+
`zod`-based schema for transforming `TRPCClientErrorLike<AnyRouter>` server errors to `FormSubmitFieldErrors`.
|
|
416
|
+
|
|
417
|
+
#### `makeOnSubmitTrpcClientErrorHandler`
|
|
418
|
+
|
|
419
|
+
HOF to make a `onSubmitErrorUnknown` handler for TRPC.io server errors (with fallback callback for non-TRPC errors).
|
|
420
|
+
|
|
421
|
+
```ts
|
|
422
|
+
onSubmitErrorUnknown: makeOnSubmitTrpcClientErrorHandler((error) => {
|
|
423
|
+
// non-trpc error
|
|
424
|
+
}),
|
|
425
|
+
```
|
|
426
|
+
|
|
409
427
|
## Other
|
|
410
428
|
|
|
411
429
|
### SafeFieldValues
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
import { jsx as F } from "react/jsx-runtime";
|
|
2
|
+
import t from "react";
|
|
3
|
+
import { c as f } from "./createContext.mjs";
|
|
4
|
+
import { useFormState as i } from "react-hook-form";
|
|
5
|
+
const {
|
|
6
|
+
Provider: h,
|
|
7
|
+
useRequired: c,
|
|
8
|
+
useMaybe: u
|
|
9
|
+
} = f(), v = ({ children: s }) => {
|
|
10
|
+
const [e, r] = t.useState([]), d = e.length, B = t.useCallback((o, I) => {
|
|
11
|
+
r(
|
|
12
|
+
(n) => I ? (
|
|
13
|
+
// add to array
|
|
14
|
+
[...n, o]
|
|
15
|
+
) : (
|
|
16
|
+
// remove from array
|
|
17
|
+
n.filter((C) => C !== o)
|
|
18
|
+
)
|
|
19
|
+
);
|
|
20
|
+
}, []), [l, p] = t.useState(!1);
|
|
21
|
+
return /* @__PURE__ */ F(h, { value: {
|
|
22
|
+
children: {
|
|
23
|
+
busyCount: d,
|
|
24
|
+
busyIds: e,
|
|
25
|
+
setBusyId: B
|
|
26
|
+
},
|
|
27
|
+
parent: {
|
|
28
|
+
isBusy: l,
|
|
29
|
+
setIsBusy: p
|
|
30
|
+
}
|
|
31
|
+
}, children: s });
|
|
32
|
+
}, a = (s) => {
|
|
33
|
+
const { setBusyId: e } = c().children, r = t.useId();
|
|
34
|
+
t.useEffect(() => {
|
|
35
|
+
e(r, s);
|
|
36
|
+
}, [s, r, e]), t.useEffect(() => () => {
|
|
37
|
+
e(r, !1);
|
|
38
|
+
}, []);
|
|
39
|
+
}, y = () => {
|
|
40
|
+
const s = u();
|
|
41
|
+
return !!(s != null && s.parent.isBusy);
|
|
42
|
+
}, T = () => (a(!0), y()), E = () => {
|
|
43
|
+
const { isSubmitting: s } = i();
|
|
44
|
+
return a(s), y();
|
|
45
|
+
}, M = () => {
|
|
46
|
+
const s = u();
|
|
47
|
+
return !!(s != null && s.children.busyCount) || !!(s != null && s.parent.isBusy);
|
|
48
|
+
}, G = () => {
|
|
49
|
+
const s = u();
|
|
50
|
+
return !!(s != null && s.children.busyCount);
|
|
51
|
+
}, m = () => {
|
|
52
|
+
const { isSubmitting: s, isLoading: e } = i();
|
|
53
|
+
return s || e;
|
|
54
|
+
}, _ = () => {
|
|
55
|
+
const s = m(), { setIsBusy: e } = c().parent;
|
|
56
|
+
return t.useEffect(() => {
|
|
57
|
+
e(s);
|
|
58
|
+
}, [e, s]), G();
|
|
59
|
+
}, x = () => {
|
|
60
|
+
var r;
|
|
61
|
+
const s = m(), e = (r = u()) == null ? void 0 : r.parent.isBusy;
|
|
62
|
+
return !!(s || e);
|
|
63
|
+
};
|
|
64
|
+
export {
|
|
65
|
+
v as FormGroupContextProvider,
|
|
66
|
+
T as useFormGroupChildIsMountedTracker,
|
|
67
|
+
E as useFormGroupChildIsSubmittingTracker,
|
|
68
|
+
a as useFormGroupChildTracker,
|
|
69
|
+
M as useFormGroupIsAnyBusy,
|
|
70
|
+
G as useFormGroupIsChildBusy,
|
|
71
|
+
y as useFormGroupIsParentBusy,
|
|
72
|
+
_ as useFormGroupParentTracker,
|
|
73
|
+
x as useFormOrParentIsBusy
|
|
74
|
+
};
|