@paragrav/rhf-utils 0.0.140 → 0.0.141

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 (102) hide show
  1. package/dist/types/_exports/main.d.ts +15 -0
  2. package/dist/types/client/config/RhfUtilsClientConfig.d.ts +71 -0
  3. package/dist/types/client/config/useRhfUtilsClientConfigContext.d.ts +5 -0
  4. package/dist/types/client/context.d.ts +3 -0
  5. package/dist/types/client/index.d.ts +30 -0
  6. package/dist/types/client/utils.d.ts +13 -0
  7. package/dist/types/client/zod/RhfUtilsUseFormChildrenZodFC.d.ts +13 -0
  8. package/dist/types/client/zod/RhfUtilsUseFormChildrenZodProps.d.ts +5 -0
  9. package/dist/types/client/zod/ZodTypeFieldValues.d.ts +4 -0
  10. package/dist/types/client/zod/consts.d.ts +4 -0
  11. package/dist/types/client/zod/context/RhfUtilsClientForZodContextProvider.d.ts +8 -0
  12. package/dist/types/client/zod/context/RhfUtilsZodForm.d.ts +9 -0
  13. package/dist/types/client/zod/context/useRhfUtilsClientForZodContext.d.ts +6 -0
  14. package/dist/types/client/zod/context/useRhfUtilsZodForm.d.ts +8 -0
  15. package/dist/types/client/zod/createRhfUtilsClientForZod.d.ts +4 -0
  16. package/dist/types/devtool/LazyDevTool.d.ts +12 -0
  17. package/dist/types/errors/flat/FlatFieldErrorsList.d.ts +7 -0
  18. package/dist/types/errors/flat/context/FlatFieldErrorsContextProvider.d.ts +11 -0
  19. package/dist/types/errors/flat/context/FlatFieldErrorsOutputConfig.d.ts +20 -0
  20. package/dist/types/errors/flat/context/useFlatFieldErrorsContext.d.ts +13 -0
  21. package/dist/types/errors/flat/context/useFlatFieldErrorsContextHasOnlyOrphans.d.ts +7 -0
  22. package/dist/types/errors/flat/context/useFlatFieldErrorsContextOutput.d.ts +7 -0
  23. package/dist/types/errors/flat/filterFlatFieldErrors.d.ts +9 -0
  24. package/dist/types/errors/flat/flattenFieldErrors.d.ts +16 -0
  25. package/dist/types/errors/flat/getFlatFieldErrors.d.ts +31 -0
  26. package/dist/types/errors/flat/types.d.ts +17 -0
  27. package/dist/types/errors/getRefdFromFlatFieldErrors.d.ts +2 -0
  28. package/dist/types/errors/isFieldErrorRefd.d.ts +7 -0
  29. package/dist/types/errors/isFlatFieldErrorEntryRefd.d.ts +7 -0
  30. package/dist/types/errors/message/FormErrorMessage.d.ts +8 -0
  31. package/dist/types/errors/message/RhfUtilsFieldErrorMessage.d.ts +10 -0
  32. package/dist/types/errors/nonfield/RhfUtilsNonFieldErrorMarker.d.ts +13 -0
  33. package/dist/types/errors/nonfield/RhfUtilsNonFieldErrorMarker.spec.d.ts +1 -0
  34. package/dist/types/errors/nonfield/RhfUtilsNonFieldErrorMarker.utils.d.ts +18 -0
  35. package/dist/types/errors/nonfield/RhfUtilsNonFieldErrorMarkerHtmlAttribute.d.ts +5 -0
  36. package/dist/types/errors/nonfield/isNonFieldError.d.ts +19 -0
  37. package/dist/types/errors/nonfield/isNonFieldErrorMarkerInDOM.d.ts +6 -0
  38. package/dist/types/errors/orphan/getIsOrphanFormErrorWithParentElement.d.ts +7 -0
  39. package/dist/types/errors/orphan/getOrphansFromFlatFieldErrors.d.ts +4 -0
  40. package/dist/types/errors/orphan/isOrphanFormError.d.ts +4 -0
  41. package/dist/types/errors/output/consoleErrors.d.ts +7 -0
  42. package/dist/types/errors/output/types.d.ts +7 -0
  43. package/dist/types/errors/root/RootErrorsListFromFlatFieldErrorsContext.d.ts +2 -0
  44. package/dist/types/errors/root/consts.d.ts +1 -0
  45. package/dist/types/errors/root/getRootsFromFlatFieldErrors.d.ts +2 -0
  46. package/dist/types/errors/root/isFlatFieldErrorEntryPathRoot.d.ts +7 -0
  47. package/dist/types/errors/root/isFormErrorPathRoot.d.ts +7 -0
  48. package/dist/types/errors/trpc/makeOnSubmitTrpcClientErrorHandler.d.ts +11 -0
  49. package/dist/types/errors/trpc/trpcClientErrorMessageSchema.d.ts +24 -0
  50. package/dist/types/errors/trpc/trpcClientErrorToFormSubmitFieldErrorsSchemaTransformer.d.ts +28 -0
  51. package/dist/types/form/Form.d.ts +11 -0
  52. package/dist/types/form/FormWithProviders.d.ts +13 -0
  53. package/dist/types/form/RhfUtilsFormOptions.d.ts +29 -0
  54. package/dist/types/form/RhfUtilsFormProviders.d.ts +12 -0
  55. package/dist/types/form/SafeFieldValues.d.ts +4 -0
  56. package/dist/types/form/UseRhfUtilsFormChildrenProps.d.ts +20 -0
  57. package/dist/types/form/UseRhfUtilsFormOnSubmitContext.d.ts +27 -0
  58. package/dist/types/form/UseRhfUtilsFormProps.d.ts +23 -0
  59. package/dist/types/form/UseRhfUtilsFormReturn.d.ts +20 -0
  60. package/dist/types/form/_Controller.d.ts +6 -0
  61. package/dist/types/form/context/group/FormGroupContextProvider.d.ts +5 -0
  62. package/dist/types/form/context/group/index.d.ts +14 -0
  63. package/dist/types/form/context/group/useFormGroupChildIsMountedTracker.d.ts +5 -0
  64. package/dist/types/form/context/group/useFormGroupChildIsSubmittingTracker.d.ts +5 -0
  65. package/dist/types/form/context/group/useFormGroupChildTracker.d.ts +6 -0
  66. package/dist/types/form/context/group/useFormGroupIsAnyBusy.d.ts +2 -0
  67. package/dist/types/form/context/group/useFormGroupIsChildBusy.d.ts +2 -0
  68. package/dist/types/form/context/group/useFormGroupIsParentBusy.d.ts +2 -0
  69. package/dist/types/form/context/group/useFormGroupParentTracker.d.ts +7 -0
  70. package/dist/types/form/context/group/useFormOrParentIsBusy.d.ts +2 -0
  71. package/dist/types/form/context/utils/RhfUtilsContextProvider.d.ts +9 -0
  72. package/dist/types/form/context/utils/useRhfUtilsContext.d.ts +14 -0
  73. package/dist/types/form/context/utils/useRhfUtilsContextRequestSubmit.d.ts +5 -0
  74. package/dist/types/form/useFormIsBusy.d.ts +2 -0
  75. package/dist/types/form/useRhfUtilsForm.d.ts +16 -0
  76. package/dist/types/form/utils/getSubmitterButtonData.d.ts +8 -0
  77. package/dist/types/form/utils/useFormRequestSubmit.d.ts +11 -0
  78. package/dist/types/form/utils/useShouldFormBlockNavigation.d.ts +26 -0
  79. package/dist/types/main.d.ts +1 -15
  80. package/dist/types/register.d.ts +7 -0
  81. package/dist/types/submit/error/FormSubmitError.d.ts +7 -0
  82. package/dist/types/submit/error/FormSubmitFieldErrors.d.ts +15 -0
  83. package/dist/types/submit/error/setCtxErrorsByFormSubmitFieldErrors.d.ts +10 -0
  84. package/dist/types/submit/useFormOnSubmitSuccessfulAndReset.d.ts +15 -0
  85. package/dist/types/submit/useFormOnSubmitted.d.ts +6 -0
  86. package/dist/types/submit/useResetFormOnSubmitted.d.ts +36 -0
  87. package/dist/types/submit/useSubmitFormOnChange.d.ts +9 -0
  88. package/dist/types/utils/PassthroughChildren.d.ts +7 -0
  89. package/dist/types/utils/createContext.d.ts +12 -0
  90. package/dist/types/utils/fixedForwardRef.d.ts +7 -0
  91. package/dist/types/utils/isEmptyObject.d.ts +2 -0
  92. package/dist/types/utils/timeoutAsync.d.ts +6 -0
  93. package/dist/types/utils/types.d.ts +1 -0
  94. package/dist/types/utils/useDebouncedOnChangeValue.d.ts +14 -0
  95. package/dist/types/utils/useImperativeForwardedRef.d.ts +11 -0
  96. package/dist/types/utils/useRefIfValueWasTrue.d.ts +2 -0
  97. package/dist/types/utils/useThrowAsyncError.d.ts +5 -0
  98. package/dist/types/utils/useToggle.d.ts +4 -0
  99. package/package.json +5 -5
  100. /package/dist/types/{group.d.ts → _exports/group.d.ts} +0 -0
  101. /package/dist/types/{trpc.d.ts → _exports/trpc.d.ts} +0 -0
  102. /package/dist/types/{utils.d.ts → _exports/utils.d.ts} +0 -0
@@ -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;
@@ -0,0 +1,11 @@
1
+ import { default as React } from 'react';
2
+ import { SafeFieldValues } from './SafeFieldValues';
3
+ import { UseRhfUtilsFormProps } from './UseRhfUtilsFormProps';
4
+
5
+ export type FormChildrenSlots = 'top' | 'bottom';
6
+ export type FormProps<TFieldValues extends SafeFieldValues, TTransformedValues extends SafeFieldValues> = {
7
+ formId: string;
8
+ formRef: React.RefObject<HTMLFormElement>;
9
+ } & Pick<UseRhfUtilsFormProps<TFieldValues, TTransformedValues>, 'onSubmit' | 'onSubmitError' | 'onSubmitInvalid' | 'Children' | 'form' | 'utils'>;
10
+ declare function _Form<TFieldValues extends SafeFieldValues, TTransformedValues extends SafeFieldValues>({ formId, formRef, onSubmit, onSubmitError, onSubmitInvalid, Children, form, utils, }: FormProps<TFieldValues, TTransformedValues>): import("react/jsx-runtime").JSX.Element;
11
+ export default _Form;
@@ -0,0 +1,13 @@
1
+ import { SafeFieldValues } from './SafeFieldValues';
2
+ import { UseRhfUtilsFormProps } from './UseRhfUtilsFormProps';
3
+
4
+ export type FormWithProvidersProps<TFieldValues extends SafeFieldValues, TTransformedValues extends SafeFieldValues> = React.PropsWithChildren<UseRhfUtilsFormProps<TFieldValues, TTransformedValues>>;
5
+ /**
6
+ * Form providers (with utils) with immediate descendent {@link Form}.
7
+ * (Syntactic sugar for {@link useRhfUtilsForm}. Use this for most applications.)
8
+ *
9
+ * Use {@link useRhfUtilsForm} if you need to specific nesting hierarchy.
10
+ * (e.g., wrapping `<tr>` with provider and nesting `<form>` within `<td>` to appease HTML rules.)
11
+ */
12
+ declare function FormWithProviders<TFieldValues extends SafeFieldValues, TTransformedValues extends SafeFieldValues>(props: FormWithProvidersProps<TFieldValues, TTransformedValues>): import("react/jsx-runtime").JSX.Element;
13
+ export default FormWithProviders;
@@ -0,0 +1,29 @@
1
+ import { DevtoolUIProps } from '@hookform/devtools/dist/devToolUI';
2
+ import { UseResetFormOnSubmittedOptions } from '../submit/useResetFormOnSubmitted';
3
+ import { Register } from '../register';
4
+
5
+ /**
6
+ * Options for enabling utils functionality provided by this library.
7
+ *
8
+ * Can be extended using {@link Register.RhfUtilsFormOptions}.
9
+ */
10
+ export type RhfUtilsFormOptions = {
11
+ /** Stop propagation of submit event. */
12
+ stopSubmitPropagation?: boolean;
13
+ /**
14
+ * Request submit via listener on form change.
15
+ * - `true` to submit on any change.
16
+ * - number to debounce in milliseconds.
17
+ */
18
+ submitOnChange?: boolean | number;
19
+ /** Reset form values and state (e.g., `isDirty`) after submit -- on success and/or error. */
20
+ resetOnSubmitted?: UseResetFormOnSubmittedOptions;
21
+ /**
22
+ * Control dev tool options.
23
+ * (Lazy-loaded when truthy value supplied.
24
+ * For zero bundle size in prod, be sure to check for dev environment.)
25
+ */
26
+ devTool?: boolean | Pick<DevtoolUIProps, 'placement' | 'styles'>;
27
+ } & (Register extends {
28
+ RhfUtilsFormOptions: infer _RhfUtilsFormOptions;
29
+ } ? _RhfUtilsFormOptions : {});
@@ -0,0 +1,12 @@
1
+ import { UseFormReturn } from 'react-hook-form';
2
+ import { RhfUtilsFormOptions } from './RhfUtilsFormOptions';
3
+ import { SafeFieldValues } from './SafeFieldValues';
4
+
5
+ export type RhfUtilsFormProvidersProps<TFieldValues extends SafeFieldValues, TTransformedValues extends SafeFieldValues> = React.PropsWithChildren<{
6
+ formId: string;
7
+ formRef: React.RefObject<HTMLFormElement>;
8
+ rhfForm: UseFormReturn<TFieldValues, unknown, TTransformedValues>;
9
+ utils?: RhfUtilsFormOptions;
10
+ }>;
11
+ declare function RhfUtilsFormProviders<TFieldValues extends SafeFieldValues, TTransformedValues extends SafeFieldValues>({ formId, formRef, rhfForm, utils, children, }: RhfUtilsFormProvidersProps<TFieldValues, TTransformedValues>): import("react/jsx-runtime").JSX.Element;
12
+ export default RhfUtilsFormProviders;
@@ -0,0 +1,4 @@
1
+ /**
2
+ * Equivalent to RHF's `FieldValues` except for `unknown` (instead of `any`) value.
3
+ */
4
+ export type SafeFieldValues = Record<string, unknown>;
@@ -0,0 +1,20 @@
1
+ import { default as React } from 'react';
2
+ import { UseFormReturn } from 'react-hook-form';
3
+ import { FormSubmitError } from '../submit/error/FormSubmitError';
4
+ import { default as _Controller } from './_Controller';
5
+ import { RhfUtilsFormOptions } from './RhfUtilsFormOptions';
6
+ import { SafeFieldValues } from './SafeFieldValues';
7
+
8
+ /**
9
+ * Component props for `Children`.
10
+ *
11
+ * Consider keeping shape in line with `UseRhfUtilsFormOnSubmitProps` and `UseRhfUtilsFormReturn`.
12
+ */
13
+ export type UseRhfUtilsFormChildrenProps<TFieldValues extends SafeFieldValues = SafeFieldValues, TTransformedValues extends SafeFieldValues = SafeFieldValues> = {
14
+ formId: string;
15
+ formRef: React.RefObject<HTMLFormElement>;
16
+ context: UseFormReturn<TFieldValues, unknown, TTransformedValues>;
17
+ utils?: RhfUtilsFormOptions;
18
+ Controller: typeof _Controller<TFieldValues>;
19
+ FormSubmitError: typeof FormSubmitError<TFieldValues>;
20
+ };
@@ -0,0 +1,27 @@
1
+ import { default as React } from 'react';
2
+ import { UseFormReturn } from 'react-hook-form';
3
+ import { FormSubmitError } from '../submit/error/FormSubmitError';
4
+ import { RhfUtilsFormOptions } from './RhfUtilsFormOptions';
5
+ import { SafeFieldValues } from './SafeFieldValues';
6
+
7
+ /**
8
+ * Props for onSubmit other than `data` and `event`.
9
+ *
10
+ * Consider keeping shape in line with `UseRhfUtilsFormChildrenProps` and `UseRhfUtilsFormReturn`.
11
+ */
12
+ export type UseRhfUtilsFormOnSubmitContext<TFieldValues extends SafeFieldValues = SafeFieldValues, TTransformedValues extends SafeFieldValues = SafeFieldValues> = {
13
+ formId: string;
14
+ formRef: React.RefObject<HTMLFormElement>;
15
+ context: UseFormReturn<TFieldValues, unknown, TTransformedValues>;
16
+ utils?: RhfUtilsFormOptions;
17
+ FormSubmitError: typeof FormSubmitError<TFieldValues>;
18
+ };
19
+ /**
20
+ * Props for onSubmitError other than `error` and `event`.
21
+ */
22
+ export type UseRhfUtilsFormOnSubmitErrorContext<TFieldValues extends SafeFieldValues = SafeFieldValues, TTransformedValues extends SafeFieldValues = SafeFieldValues> = {
23
+ formId: string;
24
+ formRef: React.RefObject<HTMLFormElement>;
25
+ context: UseFormReturn<TFieldValues, unknown, TTransformedValues>;
26
+ utils?: RhfUtilsFormOptions;
27
+ };
@@ -0,0 +1,23 @@
1
+ import { default as React } from 'react';
2
+ import { SubmitErrorHandler, UseFormProps } from 'react-hook-form';
3
+ import { MaybePromise } from '../utils/types';
4
+ import { RhfUtilsFormOptions } from './RhfUtilsFormOptions';
5
+ import { SafeFieldValues } from './SafeFieldValues';
6
+ import { UseRhfUtilsFormChildrenProps } from './UseRhfUtilsFormChildrenProps';
7
+ import { UseRhfUtilsFormOnSubmitContext, UseRhfUtilsFormOnSubmitErrorContext } from './UseRhfUtilsFormOnSubmitContext';
8
+
9
+ export type UseRhfUtilsFormProps<TFieldValues extends SafeFieldValues, TTransformedValues extends SafeFieldValues> = {
10
+ defaultValues?: UseFormProps<TFieldValues>['defaultValues'];
11
+ onSubmit?: (values: TTransformedValues, context: UseRhfUtilsFormOnSubmitContext<TFieldValues, TTransformedValues>, event: React.BaseSyntheticEvent<SubmitEvent>) => MaybePromise<unknown>;
12
+ /** Submit error handler. (Only for errors not of instance `FormError`, which are handled internally.) */
13
+ onSubmitError?: (error: unknown, context: UseRhfUtilsFormOnSubmitErrorContext<TFieldValues, TTransformedValues>, event: React.BaseSyntheticEvent<SubmitEvent>) => void;
14
+ /** Submit handler when form is invalid. */
15
+ onSubmitInvalid?: SubmitErrorHandler<TFieldValues>;
16
+ Children: React.FC<UseRhfUtilsFormChildrenProps<TFieldValues, TTransformedValues>>;
17
+ /** {@link RhfUseFormProps} props for RHF's {@link useForm}. */
18
+ rhf?: Omit<UseFormProps<TFieldValues>, 'defaultValues'>;
19
+ /** {@link RhfUtilsFormOptions} to enabled utils functionality. */
20
+ utils?: RhfUtilsFormOptions;
21
+ /** {@link FormProps} props for Form. */
22
+ form?: Omit<React.PropsWithoutRef<JSX.IntrinsicElements['form']>, 'onSubmit'>;
23
+ };
@@ -0,0 +1,20 @@
1
+ import { default as React } from 'react';
2
+ import { UseFormReturn } from 'react-hook-form';
3
+ import { FormSubmitError } from '../submit/error/FormSubmitError';
4
+ import { FormProps } from './Form';
5
+ import { RhfUtilsFormProvidersProps } from './RhfUtilsFormProviders';
6
+ import { SafeFieldValues } from './SafeFieldValues';
7
+
8
+ /**
9
+ * Return type for `useRhfUtilsForm`.
10
+ *
11
+ * Consider keeping shape in line with `UseRhfUtilsFormChildrenProps` and `UseRhfUtilsFormOnSubmitProps`.
12
+ */
13
+ export type UseRhfUtilsFormReturn<TFieldValues extends SafeFieldValues, TTransformedValues extends SafeFieldValues> = {
14
+ id: string;
15
+ ref: React.RefObject<HTMLFormElement>;
16
+ context: UseFormReturn<TFieldValues, unknown, TTransformedValues>;
17
+ providerProps: RhfUtilsFormProvidersProps<TFieldValues, TTransformedValues>;
18
+ formProps: FormProps<TFieldValues, TTransformedValues>;
19
+ FormSubmitError: typeof FormSubmitError<TFieldValues>;
20
+ };
@@ -0,0 +1,6 @@
1
+ import { ControllerProps, FieldPath } from 'react-hook-form';
2
+ import { SafeFieldValues } from './SafeFieldValues';
3
+
4
+ export type _ControllerProps<TFieldValues extends SafeFieldValues, TName extends FieldPath<TFieldValues> = FieldPath<TFieldValues>> = Omit<ControllerProps<TFieldValues, TName>, 'control'>;
5
+ declare function _Controller<TFieldValues extends SafeFieldValues, TName extends FieldPath<TFieldValues> = FieldPath<TFieldValues>>(props: _ControllerProps<TFieldValues, TName>): import("react/jsx-runtime").JSX.Element;
6
+ export default _Controller;
@@ -0,0 +1,5 @@
1
+ import { default as React } from 'react';
2
+
3
+ type Props = React.PropsWithChildren;
4
+ declare const FormGroupContextProvider: React.FC<Props>;
5
+ export default FormGroupContextProvider;
@@ -0,0 +1,14 @@
1
+ export type FormGroupContext = {
2
+ /** Dependent forms. */
3
+ children: {
4
+ busyIds: string[];
5
+ busyCount: number;
6
+ setBusyId: (id: string, isBusy: boolean) => void;
7
+ };
8
+ /** Main form. */
9
+ parent: {
10
+ isBusy: boolean;
11
+ setIsBusy: (isBusy: boolean) => void;
12
+ };
13
+ };
14
+ export declare const _FormGroupContextProvider: import('react').Provider<FormGroupContext | undefined>, _useFormGroupContext: () => FormGroupContext, _useFormGroupContextMaybe: () => FormGroupContext | undefined;
@@ -0,0 +1,5 @@
1
+ /**
2
+ * Mark "child" form as "busy" when mounted.
3
+ */
4
+ declare const useFormGroupChildIsMountedTracker: () => boolean;
5
+ export default useFormGroupChildIsMountedTracker;
@@ -0,0 +1,5 @@
1
+ /**
2
+ * Mark "child" form as "busy" when submitting.
3
+ */
4
+ declare const useFormGroupChildIsSubmittingTracker: () => boolean;
5
+ export default useFormGroupChildIsSubmittingTracker;
@@ -0,0 +1,6 @@
1
+ /**
2
+ * Mark "child" form as "busy" via arbitrary boolean.
3
+ * Automatically marks as "not busy" on dismount.
4
+ */
5
+ declare const useFormGroupChildTracker: (track: boolean) => void;
6
+ export default useFormGroupChildTracker;
@@ -0,0 +1,2 @@
1
+ declare const useFormGroupIsAnyBusy: () => boolean;
2
+ export default useFormGroupIsAnyBusy;
@@ -0,0 +1,2 @@
1
+ declare const useFormGroupIsChildBusy: () => boolean;
2
+ export default useFormGroupIsChildBusy;
@@ -0,0 +1,2 @@
1
+ declare const useFormGroupIsParentBusy: () => boolean;
2
+ export default useFormGroupIsParentBusy;
@@ -0,0 +1,7 @@
1
+ /**
2
+ * Connect specific form state as parent context.
3
+ *
4
+ * Requires usage of provider.
5
+ */
6
+ declare const useFormGroupParentTracker: () => boolean;
7
+ export default useFormGroupParentTracker;
@@ -0,0 +1,2 @@
1
+ declare const useFormOrParentIsBusy: () => boolean;
2
+ export default useFormOrParentIsBusy;
@@ -0,0 +1,9 @@
1
+ import { RhfUtilsFormOptions } from '../../RhfUtilsFormOptions';
2
+
3
+ type Props = React.PropsWithChildren<{
4
+ formId: string;
5
+ formRef: React.RefObject<HTMLFormElement>;
6
+ options?: RhfUtilsFormOptions;
7
+ }>;
8
+ declare const RhfUtilsContextProvider: React.FC<Props>;
9
+ export default RhfUtilsContextProvider;
@@ -0,0 +1,14 @@
1
+ import { RhfUtilsFormOptions } from '../../RhfUtilsFormOptions';
2
+
3
+ export type RhfUtilsContext = {
4
+ formId: string;
5
+ formRef: React.RefObject<HTMLFormElement>;
6
+ options: RhfUtilsFormOptions | undefined;
7
+ };
8
+ declare const _RhfUtilsContextProvider: import('react').Provider<RhfUtilsContext | undefined>;
9
+ /**
10
+ * Use utils from the current form context.
11
+ */
12
+ declare const useRhfUtilsContext: () => RhfUtilsContext;
13
+ export default useRhfUtilsContext;
14
+ export { _RhfUtilsContextProvider };
@@ -0,0 +1,5 @@
1
+ /**
2
+ * Get `requestSubmit` function from the form ref'd in current context.
3
+ */
4
+ declare const useRhfUtilsContextRequestSubmit: () => (submitter?: HTMLElement | null) => void;
5
+ export default useRhfUtilsContextRequestSubmit;
@@ -0,0 +1,2 @@
1
+ declare const useFormIsBusy: () => boolean;
2
+ export default useFormIsBusy;
@@ -0,0 +1,16 @@
1
+ import { SafeFieldValues } from './SafeFieldValues';
2
+ import { UseRhfUtilsFormProps } from './UseRhfUtilsFormProps';
3
+ import { UseRhfUtilsFormReturn } from './UseRhfUtilsFormReturn';
4
+
5
+ /**
6
+ * Core Rhf Form hook. Use `Form` in `index.ts` for most cases.
7
+ * Use this if you need to separate form components.
8
+ * e.g., a form for table row due to `form` being considered invalid HTML around `tr` tags.
9
+ * With this hook, you can wrap the `tr` tag with `form.Provider` and use `form.Form` inside
10
+ * one of the cells. Other components can be outside form while referring to form by its id via `form` attribute.
11
+ * see https://caniuse.com/?search=form%20attribute
12
+ * @returns Form provider and form.
13
+ */
14
+ declare const useRhfUtilsForm: <TFieldValues extends SafeFieldValues, TTransformedValues extends SafeFieldValues>({ defaultValues, onSubmit, onSubmitError, onSubmitInvalid, Children, rhf, form, utils, }: UseRhfUtilsFormProps<TFieldValues, TTransformedValues>) => UseRhfUtilsFormReturn<TFieldValues, TTransformedValues>;
15
+ export default useRhfUtilsForm;
16
+ export type UseRhfUtilsForm<TFieldValues extends SafeFieldValues, TTransformedValues extends SafeFieldValues> = typeof useRhfUtilsForm<TFieldValues, TTransformedValues>;
@@ -0,0 +1,8 @@
1
+ import { default as React } from 'react';
2
+
3
+ /**
4
+ * Get [name, value] tuple of button/input that submitted form.
5
+ * Useful when determining user intent
6
+ */
7
+ declare const getSubmitterButtonData: (event: React.BaseSyntheticEvent) => [name: string, value: string] | undefined;
8
+ export default getSubmitterButtonData;
@@ -0,0 +1,11 @@
1
+ import { default as React } from 'react';
2
+
3
+ /**
4
+ * Get callback to trigger submit manually on form.
5
+ *
6
+ * Note: `submitter` is optional, but is required to be a submit button.
7
+ *
8
+ * @link https://developer.mozilla.org/docs/Web/API/HTMLFormElement/requestSubmit
9
+ */
10
+ declare const useFormRequestSubmit: (ref: React.RefObject<HTMLFormElement>) => HTMLFormElement["requestSubmit"];
11
+ export default useFormRequestSubmit;
@@ -0,0 +1,26 @@
1
+ import { FieldValues, FormState } from 'react-hook-form';
2
+
3
+ export type UseShouldFormBlockNavigationOptions = {
4
+ disabled?: boolean;
5
+ /**
6
+ * Block navigation while submitting.
7
+ * (In other words, will always block when `isDirty`.)
8
+ *
9
+ * NOTE: Be sure to use with `UseResetFormOnSubmittedOptions` configuration
10
+ * to mark form state as not `isDirty` after successful submit.
11
+ *
12
+ * This options is recommended because it prohibits possible
13
+ * user-triggered navigation during prolonged request.
14
+ */
15
+ blockWhenSubmitting?: boolean;
16
+ };
17
+ /**
18
+ * Returns `boolean` value when the form should block navigation.
19
+ *
20
+ * By default, return `true` when the form is submitting or is not dirty.
21
+ *
22
+ * Evaluates to `true` when `enabled` and `isDirty` except when `isSubmitting` and `isValid`,
23
+ * because we don't want to block navigation when the form is submitting and valid.
24
+ */
25
+ declare const useShouldFormBlockNavigation: ({ isDirty, isSubmitting }: FormState<FieldValues>, options?: UseShouldFormBlockNavigationOptions) => boolean;
26
+ export default useShouldFormBlockNavigation;
@@ -1,15 +1 @@
1
- export type { Register } from '../register';
2
- export type { RhfUtilsClientConfig } from '../client/config/RhfUtilsClientConfig';
3
- export { default as RhfUtilsClientForZodContextProvider } from '../client/zod/context/RhfUtilsClientForZodContextProvider';
4
- export { default as RhfUtilsZodForm } from '../client/zod/context/RhfUtilsZodForm';
5
- export { default as useRhfUtilsZodForm } from '../client/zod/context/useRhfUtilsZodForm';
6
- export type { RhfUtilsUseFormChildrenZodFC } from '../client/zod/RhfUtilsUseFormChildrenZodFC';
7
- export type { RhfUtilsUseFormChildrenZodProps } from '../client/zod/RhfUtilsUseFormChildrenZodProps';
8
- export { default as useFlatFieldErrorsContext } from '../errors/flat/context/useFlatFieldErrorsContext';
9
- export { default as useFlatFieldErrorsContextHasOnlyOrphans } from '../errors/flat/context/useFlatFieldErrorsContextHasOnlyOrphans';
10
- export { default as RhfUtilsNonFieldErrorMarker } from '../errors/nonfield/RhfUtilsNonFieldErrorMarker';
11
- export type { RhfUtilsFormOptions } from '../form/RhfUtilsFormOptions';
12
- export type { SafeFieldValues } from '../form/SafeFieldValues';
13
- export type { UseRhfUtilsFormChildrenProps } from '../form/UseRhfUtilsFormChildrenProps';
14
- export { default as useRhfUtilsContext } from '../form/context/utils/useRhfUtilsContext';
15
- export { FormSubmitError } from '../submit/error/FormSubmitError';
1
+ export {};
@@ -0,0 +1,7 @@
1
+ /**
2
+ * Use this to extend internal types.
3
+ *
4
+ * For example, `RhfUtilsFormOptions`.
5
+ */
6
+ export interface Register {
7
+ }
@@ -0,0 +1,7 @@
1
+ import { SafeFieldValues } from '../../form/SafeFieldValues';
2
+ import { FormSubmitFieldErrors } from './FormSubmitFieldErrors';
3
+
4
+ export declare class FormSubmitError<TFieldValues extends SafeFieldValues = SafeFieldValues> extends Error {
5
+ errors: FormSubmitFieldErrors<TFieldValues>;
6
+ constructor(errors: FormSubmitFieldErrors<TFieldValues>, message?: string);
7
+ }
@@ -0,0 +1,15 @@
1
+ import { FieldPath } from 'react-hook-form';
2
+ import { SafeFieldValues } from '../../form/SafeFieldValues';
3
+
4
+ /**
5
+ * Field errors structure based on RHF's `FieldErrors`.
6
+ *
7
+ * - Uses {@link SafeFieldValues} instead of more permissive `FieldValues`.
8
+ * - `root.<string>` keys allowed.
9
+ * - `root` is reserved for special use cases.
10
+ * - simplified `ErrorOption` value.
11
+ */
12
+ export type FormSubmitFieldErrors<TFieldValues extends SafeFieldValues = SafeFieldValues> = Record<FieldPath<TFieldValues> | `root.${string}`, {
13
+ type?: string;
14
+ message: string;
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;
@@ -0,0 +1,15 @@
1
+ import { MaybePromise } from '../utils/types';
2
+
3
+ /**
4
+ * Calls a callback after a successful submit and after a form reset.
5
+ *
6
+ * Use this when your forms use a isDirty prompter for user action that would lose unsaved data.
7
+ * You must reset form before you can navigate away from page.
8
+ *
9
+ * Using RHF and following its rules, we are not able to get the state `isSubmitSuccessful=true` and `isDirty=false`.
10
+ * So, this has to keep track of previous state.
11
+ *
12
+ * SubmitSuccessfulAndReset = was `isSubmitSuccessful` and now `!isDirty`
13
+ */
14
+ declare const useFormOnSubmitSuccessfulAndReset: (callback?: (...data: unknown[]) => MaybePromise<unknown>) => void;
15
+ export default useFormOnSubmitSuccessfulAndReset;
@@ -0,0 +1,6 @@
1
+ import { MaybePromise } from '../utils/types';
2
+
3
+ declare const useFormOnSubmitted: (callback?: (success: boolean) => MaybePromise<unknown>, options?: {
4
+ successful?: boolean;
5
+ }) => void;
6
+ export default useFormOnSubmitted;
@@ -0,0 +1,36 @@
1
+ /**
2
+ * Configuration options for {@link useResetFormOnSubmitted}.
3
+ */
4
+ export type UseResetFormOnSubmittedOptions = undefined | {
5
+ /**
6
+ * Reset values on successful submit.
7
+ * - `defaults`: reset current values to defaults
8
+ * - `current`: reset defaults to current values
9
+ */
10
+ success?: {
11
+ values: 'defaults' | 'current';
12
+ };
13
+ /**
14
+ * Reset values to defaults on submit error.
15
+ */
16
+ error?: {
17
+ values: 'defaults';
18
+ };
19
+ };
20
+ /**
21
+ * Control resetting of values and (some) state (e.g., `isDirty`) after form submitted.
22
+ *
23
+ * `isDirty` and other state is reset, but submit-related state is preserved, as well as errors.
24
+ *
25
+ * Use cases:
26
+ * - on success:
27
+ * - `defaults`: reset current values to defaults (e.g., clear form)
28
+ * - `current`: reset defaults to current values (e.g., keep values)
29
+ * - on error:
30
+ * - reset current values to default values (e.g., submitOnChange reset)
31
+ *
32
+ * See `Rules` section: https://react-hook-form.com/api/useform/reset/
33
+ * Specifically: "- It's recommended to reset inside useEffect after submission."
34
+ */
35
+ declare const useResetFormOnSubmitted: (options: UseResetFormOnSubmittedOptions) => void;
36
+ export default useResetFormOnSubmitted;
@@ -0,0 +1,9 @@
1
+ import { default as React } from 'react';
2
+
3
+ declare const useSubmitFormOnChange: (formRef: React.RefObject<HTMLFormElement>, options?: {
4
+ /** Disable behavior. (Default behavior is enabled for sake of simplicity of general usage.) */
5
+ disabled?: boolean;
6
+ /** Milliseconds to debounce form submission. (Default is none.) */
7
+ debounce?: number;
8
+ }) => void;
9
+ export default useSubmitFormOnChange;
@@ -0,0 +1,7 @@
1
+ /**
2
+ * Component for simply passing through children.
3
+ *
4
+ * (Useful for conditional wrapping of children.)
5
+ */
6
+ declare const PassthroughChildren: React.FC<React.PropsWithChildren>;
7
+ export default PassthroughChildren;
@@ -0,0 +1,12 @@
1
+ import { default as React } from 'react';
2
+
3
+ /**
4
+ * Create a strictly-typed context that throws error if no provider is found.
5
+ * @returns A tuple with a function to get the context and the context provider.
6
+ */
7
+ declare function createContext<T = unknown>(): {
8
+ readonly Provider: React.Provider<T | undefined>;
9
+ readonly useMaybe: () => T | undefined;
10
+ readonly useRequired: () => T & ({} | null);
11
+ };
12
+ export default createContext;
@@ -0,0 +1,7 @@
1
+ import { default as React } from 'react';
2
+
3
+ /**
4
+ * @see https://www.totaltypescript.com/forwardref-with-generic-components
5
+ */
6
+ declare function fixedForwardRef<T, P = object>(render: (props: P, ref: React.Ref<T>) => React.ReactNode): (props: P & React.RefAttributes<T>) => React.ReactNode;
7
+ export default fixedForwardRef;
@@ -0,0 +1,2 @@
1
+ declare const isEmptyObject: (obj: Record<string, unknown>) => boolean;
2
+ export default isEmptyObject;
@@ -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>;
@@ -0,0 +1 @@
1
+ export type MaybePromise<T> = T | Promise<T>;
@@ -0,0 +1,14 @@
1
+ /**
2
+ * React hook to debounce onChange event callback.
3
+ *
4
+ * Returns debounced state setter (uses ref internally).
5
+ *
6
+ * When debounce delay has elapsed after setting value,
7
+ * onChange callback is called with latest value.
8
+ *
9
+ * @returns `[setValueDebounced]`
10
+ */
11
+ export declare const useDebouncedOnChangeValue: <TValue>({ onChange, delay, }: {
12
+ onChange: (value: TValue) => void;
13
+ delay: number;
14
+ }) => readonly [(value: TValue) => void];
@@ -0,0 +1,11 @@
1
+ import { default as React } from 'react';
2
+
3
+ /**
4
+ * Create a ref and point forwarded ref to it.
5
+ *
6
+ * Use case: forwarded refs are optional, but sometimes you need the ref.
7
+ *
8
+ * @param forwardedRef Forwarded `ref` prop.
9
+ */
10
+ declare const useImperativeForwardedRef: <TRef>(forwardedRef?: React.ForwardedRef<TRef>) => React.RefObject<TRef>;
11
+ export default useImperativeForwardedRef;
@@ -0,0 +1,2 @@
1
+ declare const useRefIfValueWasTrue: (value: boolean) => readonly [boolean, () => void];
2
+ export default useRefIfValueWasTrue;
@@ -0,0 +1,5 @@
1
+ /**
2
+ * React cannot handle async errors in event handlers or useEffects.
3
+ */
4
+ declare const useThrowAsyncError: () => (error: unknown) => void;
5
+ export default useThrowAsyncError;
@@ -0,0 +1,4 @@
1
+ import { default as React } from 'react';
2
+
3
+ declare const useToggle: (defaultValue?: boolean) => [boolean, React.DispatchWithoutAction];
4
+ export default useToggle;