@paragrav/rhf-utils 0.0.60 → 0.0.62

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 (115) hide show
  1. package/dist/esm/client/index.mjs +53 -0
  2. package/dist/esm/client/zod/context/index.mjs +6 -0
  3. package/dist/esm/client/zod/context/provider.mjs +11 -0
  4. package/dist/esm/client/zod/index.mjs +6 -0
  5. package/dist/esm/exports.mjs +76 -72
  6. package/dist/esm/form/FormWithProviders.mjs +14 -0
  7. package/dist/esm/form/_Form.mjs +89 -0
  8. package/dist/esm/form/_FormBase.mjs +14 -0
  9. package/dist/esm/form/_FormProviders.mjs +16 -0
  10. package/dist/esm/form/useForm.mjs +12 -16
  11. package/dist/esm/submit/error/setCtxErrorsByFormSubmitError.mjs +12 -0
  12. package/dist/types/src/client/config.d.ts +19 -0
  13. package/dist/types/src/client/context.d.ts +3 -0
  14. package/dist/types/src/client/index.d.ts +26 -0
  15. package/dist/types/src/client/zod/context/index.d.ts +8 -0
  16. package/dist/types/src/client/zod/context/provider.d.ts +12 -0
  17. package/dist/types/src/client/zod/index.d.ts +8 -0
  18. package/dist/types/src/exports.d.ts +6 -2
  19. package/dist/types/src/form/FormWithProviders.d.ts +2 -2
  20. package/dist/types/src/form/_Form.d.ts +2 -3
  21. package/dist/types/src/form/_FormProviders.d.ts +2 -3
  22. package/dist/types/src/form/useForm.d.ts +12 -28
  23. package/dist/types/src/form/useFormOptions.d.ts +28 -0
  24. package/dist/types/src/main.d.ts +1 -7
  25. package/package.json +12 -4
  26. package/README.md +0 -1
  27. package/dist/assets/index-BgBykTYQ.js +0 -40
  28. package/dist/esm/config/index.mjs +0 -21
  29. package/dist/index.html +0 -12
  30. package/dist/types/devtool/LazyDevTool.d.ts +0 -11
  31. package/dist/types/errors/consoleErrors.d.ts +0 -13
  32. package/dist/types/errors/context/index.d.ts +0 -10
  33. package/dist/types/errors/context/provider.d.ts +0 -12
  34. package/dist/types/errors/flat/flattenFieldErrors.d.ts +0 -15
  35. package/dist/types/errors/flat/getFlatFieldErrors.d.ts +0 -25
  36. package/dist/types/errors/flat/types.d.ts +0 -13
  37. package/dist/types/errors/flat/useFormFlatFieldErrorsMemo.d.ts +0 -5
  38. package/dist/types/errors/flat/useRefdFieldErrorsMemo.d.ts +0 -9
  39. package/dist/types/errors/isFieldError.d.ts +0 -7
  40. package/dist/types/errors/message/FormErrorMessage.d.ts +0 -8
  41. package/dist/types/errors/message/FormErrorMessageByPath.d.ts +0 -9
  42. package/dist/types/errors/nonfield/FormNonFieldErrorMarker.d.ts +0 -10
  43. package/dist/types/errors/nonfield/FormNonFieldErrorMarker.spec.d.ts +0 -1
  44. package/dist/types/errors/nonfield/FormNonFieldErrorMarker.utils.d.ts +0 -2
  45. package/dist/types/errors/nonfield/FormNonFieldErrorMarkerHtmlAttribute.d.ts +0 -5
  46. package/dist/types/errors/nonfield/isNonFieldError.d.ts +0 -19
  47. package/dist/types/errors/orphan/getOrphansFromFieldErrors.d.ts +0 -5
  48. package/dist/types/errors/orphan/getOrphansFromFlatFieldErrors.d.ts +0 -4
  49. package/dist/types/errors/orphan/useFormHasOrphanAndNoFieldErrors.d.ts +0 -9
  50. package/dist/types/errors/orphan/useOrphanFormErrorsMemo.d.ts +0 -4
  51. package/dist/types/errors/orphan/useOrphanFormErrorsToConsole.d.ts +0 -9
  52. package/dist/types/errors/outputErrors.d.ts +0 -14
  53. package/dist/types/errors/root/FormRootErrors.d.ts +0 -7
  54. package/dist/types/errors/root/FormRootErrorsFromContext.d.ts +0 -3
  55. package/dist/types/errors/root/consts.d.ts +0 -1
  56. package/dist/types/errors/root/getRootsFromFieldErrors.d.ts +0 -5
  57. package/dist/types/errors/root/getRootsFromFlatFieldErrors.d.ts +0 -4
  58. package/dist/types/errors/root/isFormErrorPathRoot.d.ts +0 -6
  59. package/dist/types/errors/root/useRootFormFieldErrorsMemo.d.ts +0 -6
  60. package/dist/types/errors/useFormErrorConsoleDebug.d.ts +0 -8
  61. package/dist/types/errors/useFormErrorsEffect.d.ts +0 -4
  62. package/dist/types/errors/useFormErrorsIfAny.d.ts +0 -6
  63. package/dist/types/errors/useFormErrorsMemo.d.ts +0 -7
  64. package/dist/types/errors/useFormErrorsToConsole.d.ts +0 -14
  65. package/dist/types/errors/useFormRequestSubmit.d.ts +0 -6
  66. package/dist/types/exports.d.ts +0 -37
  67. package/dist/types/form/ErrorBoundary.d.ts +0 -15
  68. package/dist/types/form/Form.d.ts +0 -30
  69. package/dist/types/form/FormBase.d.ts +0 -9
  70. package/dist/types/form/FormWithProviders.d.ts +0 -13
  71. package/dist/types/form/context/FormProvider.d.ts +0 -16
  72. package/dist/types/form/context/group/FormGroupContextProvider.d.ts +0 -5
  73. package/dist/types/form/context/group/index.d.ts +0 -15
  74. package/dist/types/form/context/group/useFormGroupChildIsMountedTracker.d.ts +0 -2
  75. package/dist/types/form/context/group/useFormGroupChildIsSubmittingTracker.d.ts +0 -2
  76. package/dist/types/form/context/group/useFormGroupIsAnyBusy.d.ts +0 -2
  77. package/dist/types/form/context/group/useFormGroupIsChildBusy.d.ts +0 -2
  78. package/dist/types/form/context/group/useFormGroupIsParentBusy.d.ts +0 -2
  79. package/dist/types/form/context/group/useFormGroupParentTracker.d.ts +0 -7
  80. package/dist/types/form/context/utils/FormUtilsContextProvider.d.ts +0 -15
  81. package/dist/types/form/context/utils/useFormUtilsContext.d.ts +0 -9
  82. package/dist/types/form/search/FormSearch.d.ts +0 -32
  83. package/dist/types/form/search/FormSearchHiddenInputs.d.ts +0 -13
  84. package/dist/types/form/search/getNewSearchParams.d.ts +0 -2
  85. package/dist/types/form/useForm.d.ts +0 -30
  86. package/dist/types/form/useFormIsBusy.d.ts +0 -2
  87. package/dist/types/form/useFormOrParentIsBusy.d.ts +0 -2
  88. package/dist/types/form/useFormWithProviders.d.ts +0 -31
  89. package/dist/types/form/utils/getSubmitterButtonData.d.ts +0 -11
  90. package/dist/types/isEmptyObject.d.ts +0 -2
  91. package/dist/types/main.d.ts +0 -1
  92. package/dist/types/src/config/index.d.ts +0 -69
  93. package/dist/types/src/form/ErrorBoundary.d.ts +0 -15
  94. package/dist/types/src/form/Form.d.ts +0 -29
  95. package/dist/types/src/form/FormBase.d.ts +0 -9
  96. package/dist/types/src/form/context/FormProvider.d.ts +0 -15
  97. package/dist/types/src/form/search/FormSearch.d.ts +0 -32
  98. package/dist/types/src/form/search/FormSearchHiddenInputs.d.ts +0 -13
  99. package/dist/types/src/form/search/getNewSearchParams.d.ts +0 -2
  100. package/dist/types/src/form/useFormOrParentIsBusy.d.ts +0 -2
  101. package/dist/types/src/form/useFormWithProviders.d.ts +0 -31
  102. package/dist/types/src/isEmptyObject.d.ts +0 -2
  103. package/dist/types/src/submit/error/handleFormSubmitError.d.ts +0 -7
  104. package/dist/types/submit/error/FormSubmitError.d.ts +0 -6
  105. package/dist/types/submit/error/handleFormSubmitError.d.ts +0 -7
  106. package/dist/types/submit/useFormOnSubmitSuccessful.d.ts +0 -2
  107. package/dist/types/submit/useFormOnSubmitSuccessfulAndReset.d.ts +0 -13
  108. package/dist/types/submit/useResetFormOnSubmitError.d.ts +0 -7
  109. package/dist/types/submit/useResetFormOnSubmitSuccessful.d.ts +0 -12
  110. package/dist/types/submit/useSubmitFormOnChange.d.ts +0 -4
  111. package/dist/types/utils/createContext.d.ts +0 -8
  112. package/dist/types/utils/fixedForwardRef.d.ts +0 -7
  113. package/dist/types/utils/useImperativeForwardedRef.d.ts +0 -11
  114. package/dist/types/utils/useThrowAsyncError.d.ts +0 -5
  115. package/dist/types/utils/useToggle.d.ts +0 -4
@@ -1,30 +0,0 @@
1
- import { FormProps } from './Form';
2
- import { FieldValues, UseFormProps as RhfUseFormProps } from 'react-hook-form';
3
- import { default as React } from 'react';
4
-
5
- export type UseFormProps<TFieldValues extends FieldValues, TTransformedValues extends FieldValues> = {
6
- isDev: boolean;
7
- /** {@link RhfUseFormProps} props for RHF's {@link useRhfForm}. */
8
- rhf?: RhfUseFormProps<TFieldValues>;
9
- /** {@link FormProps} props for Form. */
10
- form?: Omit<FormProps<TFieldValues, TTransformedValues>, 'isDev' | 'formId' | 'formRef'>;
11
- };
12
- export type UseFormReturn = ReturnType<typeof useForm>;
13
- /**
14
- * Base Rhf Form hook. Use `Form` in `index.ts` for most cases.
15
- * Use this if you need to separate form components.
16
- * e.g., a form for table row due to `form` being considered invalid HTML around `tr` tags.
17
- * With this hook, you can wrap the `tr` tag with `form.Provider` and use `form.Form` inside
18
- * one of the cells. Other components can be outside form while referring to form by its id via `form` attribute.
19
- * see https://caniuse.com/?search=form%20attribute
20
- * @returns Form provider and form.
21
- */
22
- declare const useForm: <TFieldValues extends FieldValues, TTransformedValues extends FieldValues>({ isDev, rhf, form, }: UseFormProps<TFieldValues, TTransformedValues>) => {
23
- readonly id: string;
24
- readonly ref: React.RefObject<HTMLFormElement>;
25
- readonly context: import('react-hook-form').UseFormReturn<TFieldValues, unknown, TTransformedValues>;
26
- readonly Form: React.FC<{
27
- children?: React.ReactNode;
28
- }>;
29
- };
30
- export default useForm;
@@ -1,2 +0,0 @@
1
- declare const useFormIsBusy: () => boolean;
2
- export default useFormIsBusy;
@@ -1,2 +0,0 @@
1
- declare const useFormOrParentIsBusy: () => boolean;
2
- export default useFormOrParentIsBusy;
@@ -1,31 +0,0 @@
1
- import { UseFormProps } from './useForm';
2
- import { FormUtilsContextProviderProps } from './context/utils/FormUtilsContextProvider';
3
- import { FieldValues } from 'react-hook-form';
4
- import { default as React } from 'react';
5
-
6
- export type UseFormWithProvidersProps<TFieldValues extends FieldValues, TTransformedValues extends FieldValues> = UseFormProps<TFieldValues, TTransformedValues> & {
7
- /** {@link FormUtilsContextProviderProps} props for `FormUtilsContextProvider`. */
8
- utils?: FormUtilsContextProviderProps;
9
- };
10
- export type UseFormWithProvidersReturn = ReturnType<typeof useFormWithProviders>;
11
- /**
12
- * Base Rhf Form hook. Use `Form` in `index.ts` for most cases.
13
- * Use this if you need to separate form components.
14
- * e.g., a form for table row due to `form` being considered invalid HTML around `tr` tags.
15
- * With this hook, you can wrap the `tr` tag with `form.Provider` and use `form.Form` inside
16
- * one of the cells. Other components can be outside form while referring to form by its id via `form` attribute.
17
- * see https://caniuse.com/?search=form%20attribute
18
- * @returns Form provider and form.
19
- */
20
- declare const useFormWithProviders: <TFieldValues extends FieldValues, TTransformedValues extends FieldValues>({ isDev, rhf, form, utils, }: UseFormWithProvidersProps<TFieldValues, TTransformedValues>) => {
21
- readonly Provider: React.FC<{
22
- children?: React.ReactNode;
23
- }>;
24
- readonly id: string;
25
- readonly ref: React.RefObject<HTMLFormElement>;
26
- readonly context: import('react-hook-form').UseFormReturn<TFieldValues, unknown, TTransformedValues>;
27
- readonly Form: React.FC<{
28
- children?: React.ReactNode;
29
- }>;
30
- };
31
- export default useFormWithProviders;
@@ -1,11 +0,0 @@
1
- import { default as React } from 'react';
2
-
3
- /**
4
- * Get [name, value] of button/input that submitted form.
5
- * Useful when determining user intent
6
- */
7
- declare const getSubmitterButtonData: (event: React.BaseSyntheticEvent) => [
8
- name: string,
9
- value: string
10
- ] | undefined;
11
- export default getSubmitterButtonData;
@@ -1,2 +0,0 @@
1
- declare const isEmptyObject: (obj: Record<string, unknown>) => boolean;
2
- export default isEmptyObject;
@@ -1 +0,0 @@
1
- export {};
@@ -1,69 +0,0 @@
1
- import { FormSubmitError } from '../submit/error/FormSubmitError';
2
- import { UseFormFieldsProps, UseFormOptions } from '../form/useForm';
3
- import { _FormSlots } from '../form/_Form';
4
- import { UseFormProps } from 'react-hook-form';
5
-
6
- type Config = {
7
- rhf?: Pick<UseFormProps, 'mode' | 'reValidateMode' | 'resetOptions' | 'context' | 'shouldFocusError' | 'shouldUnregister' | 'shouldUseNativeValidation' | 'progressive' | 'criteriaMode' | 'delayError'>;
8
- /**
9
- * Default global options settings.
10
- *
11
- * Extend this type to inject custom options/functionality via `Children` component.
12
- */
13
- options?: UseFormOptions;
14
- /**
15
- * Components injected by slot.
16
- *
17
- * e.g., top: block navigation on dirty form.
18
- * e.g., bottom: root errors list.
19
- */
20
- Children?: Partial<Record<_FormSlots, React.FC<UseFormFieldsProps>>>;
21
- /**
22
- * Handle non-{@link FormSubmitError} errors. Optionally, return {@link FormSubmitError} to merge into context errors.
23
- */
24
- onSubmitError?: (error: unknown) => FormSubmitError | undefined;
25
- };
26
- export declare const setConfig: (config: Config) => void;
27
- export declare const _getConfig: (options?: UseFormOptions) => {
28
- options: {
29
- classNames: string[];
30
- submitOnChange?: boolean | undefined;
31
- resetValuesOnSubmitError?: boolean | undefined;
32
- stopSubmitPropagation?: boolean | undefined;
33
- devTool?: import('@hookform/devtools/dist/devToolUI').DevtoolUIProps | "disabled" | undefined;
34
- };
35
- rhf?: Pick<Partial<{
36
- mode: "onBlur" | "onChange" | "onSubmit" | "onTouched" | "all";
37
- disabled: boolean;
38
- reValidateMode: "onBlur" | "onChange" | "onSubmit";
39
- defaultValues: {
40
- [x: string]: any;
41
- } | ((payload?: unknown) => Promise<import('react-hook-form').FieldValues>);
42
- values: import('react-hook-form').FieldValues;
43
- errors: import('react-hook-form').FieldErrors<import('react-hook-form').FieldValues>;
44
- resetOptions: Partial<{
45
- keepDirtyValues: boolean;
46
- keepErrors: boolean;
47
- keepDirty: boolean;
48
- keepValues: boolean;
49
- keepDefaultValues: boolean;
50
- keepIsSubmitted: boolean;
51
- keepIsSubmitSuccessful: boolean;
52
- keepTouched: boolean;
53
- keepIsValidating: boolean;
54
- keepIsValid: boolean;
55
- keepSubmitCount: boolean;
56
- }> | undefined;
57
- resolver: import('react-hook-form').Resolver<import('react-hook-form').FieldValues, any>;
58
- context: any;
59
- shouldFocusError: boolean;
60
- shouldUnregister: boolean;
61
- shouldUseNativeValidation: boolean;
62
- progressive: boolean;
63
- criteriaMode: import('react-hook-form').CriteriaMode;
64
- delayError: number;
65
- }>, "mode" | "reValidateMode" | "resetOptions" | "context" | "shouldFocusError" | "shouldUnregister" | "shouldUseNativeValidation" | "progressive" | "criteriaMode" | "delayError"> | undefined;
66
- Children?: Partial<Record<_FormSlots, import('react').FC<UseFormFieldsProps>>> | undefined;
67
- onSubmitError?: ((error: unknown) => FormSubmitError | undefined) | undefined;
68
- };
69
- export {};
@@ -1,15 +0,0 @@
1
- import { default as React } from 'react';
2
-
3
- type Props = React.PropsWithChildren;
4
- type State = {
5
- error: null | Error;
6
- };
7
- export declare class ErrorBoundary extends React.Component<Props, State> {
8
- state: State;
9
- static getDerivedStateFromError(error: Error): {
10
- error: Error;
11
- };
12
- componentDidCatch(error: unknown, errorInfo: React.ErrorInfo): void;
13
- render(): string | number | boolean | Iterable<React.ReactNode> | import("react/jsx-runtime").JSX.Element | null | undefined;
14
- }
15
- export {};
@@ -1,29 +0,0 @@
1
- import { FormBaseProps } from './FormBase';
2
- import { FieldValues, SubmitErrorHandler, UseFormReturn } from 'react-hook-form';
3
- import { default as React } from 'react';
4
- import { DevtoolUIProps } from '@hookform/devtools/dist/devToolUI';
5
-
6
- export type FormProps<TFieldValues extends FieldValues, TTransformedValues extends FieldValues> = React.PropsWithChildren<Pick<FormBaseProps, 'onChange'> & {
7
- formId?: string;
8
- formRef?: React.RefObject<HTMLFormElement>;
9
- Fields?: React.FC<{
10
- ctx: UseFormReturn<TFieldValues, unknown, TTransformedValues>;
11
- }>;
12
- onSubmit?: (values: TTransformedValues, context: UseFormReturn<TFieldValues, unknown, TTransformedValues>, event: React.BaseSyntheticEvent<SubmitEvent>) => unknown | Promise<unknown>;
13
- /** Submit error handler. (Only for errors not of instance `FormError`, which are handled internally.) */
14
- onSubmitError?: (error: unknown, context: UseFormReturn<TFieldValues, unknown, TTransformedValues>, event: React.BaseSyntheticEvent<SubmitEvent>) => void;
15
- /** Submit handler when form is invalid. */
16
- onSubmitInvalid?: SubmitErrorHandler<TFieldValues>;
17
- options?: {
18
- hideRootErrors?: boolean;
19
- /** Request submit via listener on form change. */
20
- submitOnChange?: boolean;
21
- /** Reset form values if submit throw errors. Use case: optimistic UI toggle form that submits on each change */
22
- resetValuesOnSubmitError?: boolean;
23
- stopSubmitPropagation?: boolean;
24
- devTool?: DevtoolUIProps | 'disabled';
25
- };
26
- className?: string;
27
- }>;
28
- declare function Form<TFieldValues extends FieldValues, TTransformedValues extends FieldValues>({ formId, formRef, Fields, onSubmit, onSubmitError, onSubmitInvalid, options, children, ...props }: FormProps<TFieldValues, TTransformedValues>): import("react/jsx-runtime").JSX.Element;
29
- export default Form;
@@ -1,9 +0,0 @@
1
- import { default as React } from 'react';
2
-
3
- export type FormBaseProps = React.PropsWithoutRef<JSX.IntrinsicElements['form']> & {
4
- antiCsrfToken?: string;
5
- };
6
- declare const _default: (props: Omit<React.DetailedHTMLProps<React.FormHTMLAttributes<HTMLFormElement>, HTMLFormElement>, "ref"> & {
7
- antiCsrfToken?: string | undefined;
8
- } & React.RefAttributes<HTMLFormElement>) => React.ReactNode;
9
- export default _default;
@@ -1,15 +0,0 @@
1
- import { FormUtilsContextProviderProps } from './utils/FormUtilsContextProvider';
2
- import { FormProps } from '../Form';
3
- import { FieldValues, UseFormReturn } from 'react-hook-form';
4
-
5
- type Props<TFieldValues extends FieldValues, // input values
6
- TTransformedValues extends FieldValues> = React.PropsWithChildren<{
7
- formId: string;
8
- formRef: React.RefObject<HTMLFormElement>;
9
- rhf: UseFormReturn<TFieldValues, unknown, TTransformedValues>;
10
- } & {
11
- form?: Omit<FormProps<TFieldValues, TTransformedValues>, 'formRef' | 'formId'>;
12
- utils?: FormUtilsContextProviderProps;
13
- }>;
14
- declare function FormProvider<TFieldValues extends FieldValues, TTransformedValues extends FieldValues>({ formId, formRef, rhf, form, utils, children, }: Props<TFieldValues, TTransformedValues>): import("react/jsx-runtime").JSX.Element;
15
- export default FormProvider;
@@ -1,32 +0,0 @@
1
- import { FormBaseProps } from '../FormBase';
2
- import { z } from 'zod';
3
- import { default as React } from 'react';
4
-
5
- declare const _default: <TSchema extends z.ZodTypeAny, TSchemaOutput extends z.output<TSchema> = z.output<TSchema>>(props: Omit<FormBaseProps, "children" | "onSubmit"> & {
6
- /**
7
- * Search params schema.
8
- *
9
- * Make sure all properties are marked as `optional().catch(undefiend)` to avoid errors from parsing.
10
- */
11
- schema: TSchema;
12
- /** Current search params. */
13
- search: NoInfer<TSchemaOutput>;
14
- Fields: React.FC<{
15
- search: TSchemaOutput;
16
- isSubmitting: boolean;
17
- }>;
18
- /**
19
- * Callback to handle form submission.
20
- * @param search New search params.
21
- * @param data Sanitized form data.
22
- * @param event Form submit event.
23
- */
24
- onSubmit?: ((search: TSchemaOutput, data: TSchemaOutput, event: React.FormEvent<HTMLFormElement>) => unknown) | undefined;
25
- /**
26
- * Error handler.
27
- *
28
- * Obviates need for consumer `try/catch`.
29
- */
30
- onSubmitError?: ((error: unknown, search: TSchemaOutput, data: TSchemaOutput, event: React.FormEvent<HTMLFormElement>) => void) | undefined;
31
- } & React.RefAttributes<HTMLFormElement>) => React.ReactNode;
32
- export default _default;
@@ -1,13 +0,0 @@
1
- import { default as React } from 'react';
2
- import { Stringifiable } from 'query-string';
3
-
4
- /**
5
- * Generate hidden inputs from the current search query string.
6
- * This allows form to not require JS.
7
- */
8
- declare const FormSearchHiddenInputs: React.FC<{
9
- search: Record<string, Stringifiable>;
10
- /** Keys to ignore. i.e., they have inputs. */
11
- include: string[];
12
- }>;
13
- export default FormSearchHiddenInputs;
@@ -1,2 +0,0 @@
1
- declare const getNewSearchParams: <TSearchParams extends Record<string, unknown>>(current: TSearchParams | undefined, update: TSearchParams) => TSearchParams;
2
- export default getNewSearchParams;
@@ -1,2 +0,0 @@
1
- declare const useFormOrParentIsBusy: () => boolean;
2
- export default useFormOrParentIsBusy;
@@ -1,31 +0,0 @@
1
- import { UseFormProps } from './useForm';
2
- import { FormUtilsContextProviderProps } from './context/utils/FormUtilsContextProvider';
3
- import { FieldValues } from 'react-hook-form';
4
- import { default as React } from 'react';
5
-
6
- export type UseFormWithProvidersProps<TFieldValues extends FieldValues, TTransformedValues extends FieldValues> = UseFormProps<TFieldValues, TTransformedValues> & {
7
- /** {@link FormUtilsContextProviderProps} props for `FormUtilsContextProvider`. */
8
- utils?: FormUtilsContextProviderProps;
9
- };
10
- export type UseFormWithProvidersReturn = ReturnType<typeof useFormWithProviders>;
11
- /**
12
- * Base Rhf Form hook. Use `Form` in `index.ts` for most cases.
13
- * Use this if you need to separate form components.
14
- * e.g., a form for table row due to `form` being considered invalid HTML around `tr` tags.
15
- * With this hook, you can wrap the `tr` tag with `form.Provider` and use `form.Form` inside
16
- * one of the cells. Other components can be outside form while referring to form by its id via `form` attribute.
17
- * see https://caniuse.com/?search=form%20attribute
18
- * @returns Form provider and form.
19
- */
20
- declare const useFormWithProviders: <TFieldValues extends FieldValues, TTransformedValues extends FieldValues>({ rhf, form, utils, }: UseFormWithProvidersProps<TFieldValues, TTransformedValues>) => {
21
- readonly Provider: React.FC<{
22
- children?: React.ReactNode;
23
- }>;
24
- readonly id: string;
25
- readonly ref: React.RefObject<HTMLFormElement>;
26
- readonly context: import('react-hook-form').UseFormReturn<TFieldValues, unknown, TTransformedValues>;
27
- readonly Form: React.FC<{
28
- children?: React.ReactNode;
29
- }>;
30
- };
31
- export default useFormWithProviders;
@@ -1,2 +0,0 @@
1
- declare const isEmptyObject: (obj: Record<string, unknown>) => boolean;
2
- export default isEmptyObject;
@@ -1,7 +0,0 @@
1
- import { FieldValues, UseFormReturn } from 'react-hook-form';
2
-
3
- /**
4
- * Handle form submit error if {@link FormSubmitError}. Add items to RHF form errors.
5
- */
6
- declare const handleFormSubmitError: <TFieldValues extends FieldValues, TTransformedValues extends FieldValues>(error: unknown, ctx: UseFormReturn<TFieldValues, unknown, TTransformedValues>) => void;
7
- export default handleFormSubmitError;
@@ -1,6 +0,0 @@
1
- import { FieldPath, FieldValues } from 'react-hook-form';
2
-
3
- export declare class FormSubmitError<TFieldValues extends FieldValues = FieldValues> extends Error {
4
- errors: Partial<Record<FieldPath<TFieldValues> | `root.${string}`, string>>;
5
- constructor(errors: Partial<Record<FieldPath<TFieldValues> | `root.${string}`, string>>, message?: string);
6
- }
@@ -1,7 +0,0 @@
1
- import { FieldValues, UseFormReturn } from 'react-hook-form';
2
-
3
- /**
4
- * Handle form submit error if {@link FormSubmitError}. Add items to RHF form errors.
5
- */
6
- declare const handleFormSubmitError: <TFieldValues extends FieldValues, TTransformedValues extends FieldValues>(error: unknown, ctx: UseFormReturn<TFieldValues, unknown, TTransformedValues>) => void;
7
- export default handleFormSubmitError;
@@ -1,2 +0,0 @@
1
- declare const useFormOnSubmitSuccessful: (callback?: () => void) => void;
2
- export default useFormOnSubmitSuccessful;
@@ -1,13 +0,0 @@
1
- /**
2
- * Calls a callback after a successful submit and after a form reset.
3
- *
4
- * Use this when your forms use a isDirty prompter for user action that would lose unsaved data.
5
- * You must reset form before you can navigate away from page.
6
- *
7
- * Using RHF and following its rules, we are not able to get the state `isSubmitSuccessful=true` and `isDirty=false`.
8
- * So, this has to keep track of previous state.
9
- *
10
- * SubmitSuccessfulAndReset = was `isSubmitSuccessful` and now `!isSubmitSuccessful && !isDirty`
11
- */
12
- declare const useFormOnSubmitSuccessfulAndReset: (callback?: () => void) => void;
13
- export default useFormOnSubmitSuccessfulAndReset;
@@ -1,7 +0,0 @@
1
- /**
2
- * Handle resetting after successful submit with no server validation errors.
3
- * See `Rules` section: https://react-hook-form.com/api/useform/reset/
4
- * Specifically: "- It's recommended to reset inside useEffect after submission."
5
- */
6
- declare const useResetFormOnSubmitError: (disabled?: boolean) => void;
7
- export default useResetFormOnSubmitError;
@@ -1,12 +0,0 @@
1
- import { KeepStateOptions } from 'react-hook-form';
2
-
3
- type Options = {
4
- enabled?: boolean;
5
- } & KeepStateOptions;
6
- /**
7
- * Handle resetting after successful submit with no server validation errors.
8
- * See `Rules` section: https://react-hook-form.com/api/useform/reset/
9
- * Specifically: "- It's recommended to reset inside useEffect after submission."
10
- */
11
- declare const useResetFormAfterSubmitSuccessful: ({ enabled, ...options }: Options) => void;
12
- export default useResetFormAfterSubmitSuccessful;
@@ -1,4 +0,0 @@
1
- import { default as React } from 'react';
2
-
3
- declare const useSubmitFormOnChange: (formRef: React.RefObject<HTMLFormElement>, disabled?: boolean) => void;
4
- export default useSubmitFormOnChange;
@@ -1,8 +0,0 @@
1
- import { default as React } from 'react';
2
-
3
- /**
4
- * Create a strongly-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>(): readonly [() => T | undefined, () => T & ({} | null), React.Provider<T | undefined>];
8
- export default createContext;
@@ -1,7 +0,0 @@
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;
@@ -1,11 +0,0 @@
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;
@@ -1,5 +0,0 @@
1
- /**
2
- * React cannot handle async errors in event handlers or useEffects.
3
- */
4
- declare const useThrowAsyncError: () => (error: unknown) => void;
5
- export default useThrowAsyncError;
@@ -1,4 +0,0 @@
1
- import { default as React } from 'react';
2
-
3
- declare const useToggle: (defaultValue?: boolean) => [boolean, React.DispatchWithoutAction];
4
- export default useToggle;