@paragrav/rhf-utils 0.0.27 → 0.0.30

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 (82) hide show
  1. package/dist/esm/errors/consoleErrors.mjs +9 -0
  2. package/dist/esm/errors/context/index.mjs +11 -0
  3. package/dist/esm/errors/context/provider.mjs +19 -0
  4. package/dist/esm/errors/flat/getFlatFieldErrors.mjs +22 -0
  5. package/dist/esm/errors/flat/useRefdFieldErrorsMemo.mjs +13 -0
  6. package/dist/esm/errors/nonfield/FormNonFieldErrorMarker.mjs +1 -1
  7. package/dist/esm/errors/nonfield/FormNonFieldErrorMarker.utils.mjs +3 -3
  8. package/dist/esm/errors/nonfield/FormNonFieldErrorMarkerHtmlAttribute.mjs +4 -0
  9. package/dist/esm/errors/orphan/getOrphanFlatFieldErrors.mjs +2 -2
  10. package/dist/esm/errors/orphan/useFormHasOrphanAndNoFieldErrors.mjs +5 -5
  11. package/dist/esm/errors/orphan/useOrphanFormErrorsMemo.mjs +14 -0
  12. package/dist/esm/errors/orphan/useOrphanFormErrorsToConsole.mjs +18 -0
  13. package/dist/esm/errors/outputErrors.mjs +8 -0
  14. package/dist/esm/errors/root/consts.mjs +4 -0
  15. package/dist/esm/errors/root/getRootFlatFieldErrors.mjs +11 -0
  16. package/dist/esm/errors/root/isFormErrorPathRoot.mjs +5 -0
  17. package/dist/esm/errors/root/useRootFormFieldErrorsMemo.mjs +6 -0
  18. package/dist/esm/errors/useFormErrorConsoleDebug.mjs +8 -6
  19. package/dist/esm/errors/{useFormErrorsOnChange.mjs → useFormErrorsMemo.mjs} +2 -2
  20. package/dist/esm/errors/useFormErrorsToConsole.mjs +21 -0
  21. package/dist/esm/errors/useFormRequestSubmit.mjs +5 -3
  22. package/dist/esm/form/context/parent/FormParentContextProvider.mjs +10 -0
  23. package/dist/esm/form/context/parent/index.mjs +6 -0
  24. package/dist/esm/form/context/parent/useAsFormParentState.mjs +14 -0
  25. package/dist/esm/form/context/parent/useFormParentIsBusy.mjs +8 -0
  26. package/dist/esm/form/useFormIsBusy.mjs +9 -0
  27. package/dist/esm/main.mjs +40 -30
  28. package/dist/esm/submit/useResetFormOnSubmitSuccessful.mjs +10 -7
  29. package/dist/esm/utils/createContext.mjs +13 -0
  30. package/dist/types/devtool/LazyDevTool.d.ts +2 -2
  31. package/dist/types/errors/consoleErrors.d.ts +13 -0
  32. package/dist/types/errors/context/index.d.ts +10 -0
  33. package/dist/types/errors/context/provider.d.ts +12 -0
  34. package/dist/types/errors/flat/flattenFieldErrors.d.ts +15 -0
  35. package/dist/types/errors/flat/getFlatFieldErrors.d.ts +25 -0
  36. package/dist/types/errors/flat/getFlatFieldErrorsByFilter.d.ts +9 -0
  37. package/dist/types/errors/flat/types.d.ts +3 -0
  38. package/dist/types/errors/flat/useFormFlatFieldErrorsMemo.d.ts +5 -0
  39. package/dist/types/errors/flat/useRefdFieldErrorsMemo.d.ts +9 -0
  40. package/dist/types/errors/nonfield/FormNonFieldErrorMarker.utils.d.ts +1 -6
  41. package/dist/types/errors/nonfield/FormNonFieldErrorMarkerHtmlAttribute.d.ts +5 -0
  42. package/dist/types/errors/orphan/getOrphanFlatFieldErrors.d.ts +1 -1
  43. package/dist/types/errors/orphan/useOrphanFormErrorsMemo.d.ts +4 -0
  44. package/dist/types/errors/orphan/useOrphanFormErrorsToConsole.d.ts +9 -0
  45. package/dist/types/errors/outputErrors.d.ts +14 -0
  46. package/dist/types/errors/root/FormRootErrors.d.ts +7 -0
  47. package/dist/types/errors/root/consts.d.ts +1 -0
  48. package/dist/types/errors/root/getRootFlatFieldErrors.d.ts +8 -0
  49. package/dist/types/errors/root/isFormErrorPathRoot.d.ts +6 -0
  50. package/dist/types/errors/root/useRootFormFieldErrorsMemo.d.ts +6 -0
  51. package/dist/types/errors/useFormErrorConsoleDebug.d.ts +1 -1
  52. package/dist/types/errors/useFormErrorsMemo.d.ts +7 -0
  53. package/dist/types/errors/useFormErrorsToConsole.d.ts +14 -0
  54. package/dist/types/form/Form.d.ts +21 -0
  55. package/dist/types/form/FormBase.d.ts +9 -0
  56. package/dist/types/form/FormError.d.ts +6 -0
  57. package/dist/types/form/context/FormProvider.d.ts +13 -0
  58. package/dist/types/form/context/parent/FormParentContextProvider.d.ts +5 -0
  59. package/dist/types/form/context/parent/index.d.ts +6 -0
  60. package/dist/types/form/context/parent/useAsFormParentState.d.ts +7 -0
  61. package/dist/types/form/context/parent/useFormParentIsBusy.d.ts +7 -0
  62. package/dist/types/form/context/utils/FormUtilsContextProvider.d.ts +12 -0
  63. package/dist/types/form/context/utils/useFormUtilsContext.d.ts +9 -0
  64. package/dist/types/form/search/FormSearch.d.ts +32 -0
  65. package/dist/types/form/search/FormSearchHiddenInputs.d.ts +13 -0
  66. package/dist/types/form/search/getNewSearchParams.d.ts +2 -0
  67. package/dist/types/form/useForm.d.ts +28 -0
  68. package/dist/types/form/useFormIsBusy.d.ts +2 -0
  69. package/dist/types/main.d.ts +10 -5
  70. package/dist/types/submit/useResetFormOnSubmitSuccessful.d.ts +1 -1
  71. package/dist/types/utils/createContext.d.ts +8 -0
  72. package/dist/types/utils/createRequiredContext.d.ts +8 -0
  73. package/dist/types/utils/fixedForwardRef.d.ts +7 -0
  74. package/dist/types/utils/useImperativeForwardedRef.d.ts +11 -0
  75. package/package.json +22 -4
  76. package/dist/esm/errors/getFlatFieldErrors.mjs +0 -22
  77. package/dist/esm/errors/orphan/useOrphanFormErrors.mjs +0 -14
  78. package/dist/esm/errors/orphan/useOrphanFormErrorsToConsoleError.mjs +0 -24
  79. package/dist/esm/errors/root/useRootFormFieldErrors.mjs +0 -6
  80. package/dist/esm/errors/root/utils.mjs +0 -11
  81. package/dist/esm/errors/useFormFieldErrors.mjs +0 -13
  82. /package/dist/esm/errors/{flattenFieldErrors.mjs → flat/flattenFieldErrors.mjs} +0 -0
@@ -0,0 +1,7 @@
1
+ import { FlatFieldErrors } from '../flat/types';
2
+
3
+ type Props = React.DetailedHTMLProps<React.HTMLAttributes<HTMLUListElement>, HTMLUListElement> & {
4
+ errors: FlatFieldErrors;
5
+ };
6
+ declare const FormRootErrors: React.FC<Props>;
7
+ export default FormRootErrors;
@@ -0,0 +1 @@
1
+ export declare const FormErrorPathRoot = "root";
@@ -0,0 +1,8 @@
1
+ import { FlatFieldErrors } from '../flat/types';
2
+ import { FieldErrors } from 'react-hook-form';
3
+
4
+ /**
5
+ * Pending.
6
+ */
7
+ declare const getRootFlatFieldErrors: (errors: FieldErrors) => FlatFieldErrors;
8
+ export default getRootFlatFieldErrors;
@@ -0,0 +1,6 @@
1
+ /**
2
+ * Determine if an error path is root. (e.g., `root` or `root.nested`)
3
+ * @param path Flat path. (e.g., 'root.nested')
4
+ */
5
+ declare const isFormErrorPathRoot: (path: string) => boolean;
6
+ export default isFormErrorPathRoot;
@@ -0,0 +1,6 @@
1
+ /**
2
+ * Root field errors from form.
3
+ * These are typically displayed at the bottom of the form.
4
+ */
5
+ declare const useRootFormFieldErrorsMemo: () => import('../flat/types').FlatFieldErrors;
6
+ export default useRootFormFieldErrorsMemo;
@@ -4,5 +4,5 @@
4
4
  *
5
5
  * `console.debug()` is unlikely to trigger any automated console capture reporting.
6
6
  */
7
- declare const useFormErrorConsoleDebug: (condition: boolean) => void;
7
+ declare const useFormErrorConsoleDebug: (enabled?: boolean) => void;
8
8
  export default useFormErrorConsoleDebug;
@@ -0,0 +1,7 @@
1
+ import { FieldErrors } from 'react-hook-form';
2
+
3
+ /**
4
+ * Create memoized value from form errors.
5
+ */
6
+ declare const useFormErrorsMemo: <TReturn>(callback: (errors: FieldErrors) => TReturn) => TReturn;
7
+ export default useFormErrorsMemo;
@@ -0,0 +1,14 @@
1
+ import { FlatFieldErrors } from './flat/types';
2
+
3
+ /**
4
+ * Logs out orphan errors to console.error.
5
+ *
6
+ * When `isDev`, it will also throw an error to bring attention to dev.
7
+ */
8
+ declare const useFormErrorsToConsole: (message: string, flatErrors: FlatFieldErrors, options?: {
9
+ disabled?: boolean;
10
+ isDev?: boolean;
11
+ isError?: boolean;
12
+ data?: Record<string, unknown>;
13
+ }) => void;
14
+ export default useFormErrorsToConsole;
@@ -0,0 +1,21 @@
1
+ import { FormBaseProps } from './FormBase';
2
+ import { LazyDevToolProps } from '../devtool/LazyDevTool';
3
+ import { FieldValues, SubmitErrorHandler, UseFormReturn } from 'react-hook-form';
4
+ import { default as React } from 'react';
5
+
6
+ export type FormProps<TFieldValues extends FieldValues, TTransformedValues extends FieldValues> = Omit<FormBaseProps, 'onSubmit'> & {
7
+ isDev: boolean;
8
+ formRef: React.RefObject<HTMLFormElement>;
9
+ onSubmit: (values: TTransformedValues, context: UseFormReturn<TFieldValues, unknown, TTransformedValues>, event: React.BaseSyntheticEvent<SubmitEvent>) => unknown | Promise<unknown>;
10
+ /** Submit error handler. (Only for errors not of instance `FormError`, which are handled internally.) */
11
+ onSubmitError?: (error: unknown, values: TTransformedValues, context: UseFormReturn<TFieldValues, unknown, TTransformedValues>, event: React.BaseSyntheticEvent<SubmitEvent>) => void;
12
+ /** Submit handler when form is invalid. */
13
+ onSubmitInvalid?: SubmitErrorHandler<TFieldValues>;
14
+ options?: {
15
+ disableEmptyRootError?: boolean;
16
+ devTool?: LazyDevToolProps | 'disabled';
17
+ };
18
+ className?: string;
19
+ };
20
+ declare function Form<TFieldValues extends FieldValues, TTransformedValues extends FieldValues>({ isDev, formRef, onSubmit, onSubmitError, onSubmitInvalid, options, children, ...props }: FormProps<TFieldValues, TTransformedValues>): import("react/jsx-runtime").JSX.Element;
21
+ export default Form;
@@ -0,0 +1,9 @@
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;
@@ -0,0 +1,6 @@
1
+ import { FieldPath, FieldValues } from 'react-hook-form';
2
+
3
+ export declare class FormError<TFieldValues extends 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
+ }
@@ -0,0 +1,13 @@
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
+ ctx: UseFormReturn<TFieldValues, unknown, TTransformedValues>;
8
+ } & {
9
+ form: FormProps<TFieldValues, TTransformedValues>;
10
+ utils?: FormUtilsContextProviderProps;
11
+ }>;
12
+ declare function FormProvider<TFieldValues extends FieldValues, TTransformedValues extends FieldValues>({ ctx, form, utils, children }: Props<TFieldValues, TTransformedValues>): import("react/jsx-runtime").JSX.Element;
13
+ export default FormProvider;
@@ -0,0 +1,5 @@
1
+ import { default as React } from 'react';
2
+
3
+ type Props = React.PropsWithChildren;
4
+ declare const FormParentContextProvider: React.FC<Props>;
5
+ export default FormParentContextProvider;
@@ -0,0 +1,6 @@
1
+ /// <reference types="react" />
2
+ export type FormParentContext = {
3
+ isBusy: boolean;
4
+ setIsBusy: (isBusy: boolean) => void;
5
+ };
6
+ export declare const _useFormParentContext: () => FormParentContext | undefined, _FormParentContextProvider: import('react').Provider<FormParentContext | undefined>;
@@ -0,0 +1,7 @@
1
+ /**
2
+ * Connect specific form state as parent context.
3
+ *
4
+ * Requires usage of provider.
5
+ */
6
+ declare const useAsFormParentState: () => void;
7
+ export default useAsFormParentState;
@@ -0,0 +1,7 @@
1
+ /**
2
+ * Get parent form state, if exists.
3
+ *
4
+ * Context provider not required. (`undefined` value in this case.)
5
+ */
6
+ declare const useFormParentIsBusy: () => boolean | undefined;
7
+ export default useFormParentIsBusy;
@@ -0,0 +1,12 @@
1
+ import { FormProps } from '../../Form';
2
+ import { FieldValues } from 'react-hook-form';
3
+
4
+ export type FormUtilsContextProviderProps = {
5
+ /** Callback after successful submit, and form reset. */
6
+ onSubmitSuccessfulAndReset?: () => void;
7
+ };
8
+ type Props<TFieldValues extends FieldValues, TTransformedValues extends FieldValues> = React.PropsWithChildren<{
9
+ formProps: FormProps<TFieldValues, TTransformedValues>;
10
+ } & FormUtilsContextProviderProps>;
11
+ declare function FormUtilsContextProvider<TFieldValues extends FieldValues, TTransformedValues extends FieldValues>({ formProps, onSubmitSuccessfulAndReset, children, }: Props<TFieldValues, TTransformedValues>): import("react/jsx-runtime").JSX.Element;
12
+ export default FormUtilsContextProvider;
@@ -0,0 +1,9 @@
1
+ /// <reference types="react" />
2
+ export type FormUtilsContext = {
3
+ formRef: React.RefObject<HTMLFormElement>;
4
+ /** Callback to trigger submit manually -- e.g., on change. */
5
+ requestSubmit: HTMLFormElement['requestSubmit'];
6
+ };
7
+ declare const useFormUtilsContext: () => FormUtilsContext, _FormUtilsContextProvider: import('react').Provider<FormUtilsContext | undefined>;
8
+ export default useFormUtilsContext;
9
+ export { _FormUtilsContextProvider };
@@ -0,0 +1,32 @@
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;
@@ -0,0 +1,13 @@
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;
@@ -0,0 +1,2 @@
1
+ declare const getNewSearchParams: <TSearchParams extends Record<string, unknown>>(current: TSearchParams | undefined, update: TSearchParams) => TSearchParams;
2
+ export default getNewSearchParams;
@@ -0,0 +1,28 @@
1
+ import { FormProps } from './Form';
2
+ import { FormUtilsContextProviderProps } from './context/utils/FormUtilsContextProvider';
3
+ import { FieldValues, UseFormProps as RhfUseFormProps } from 'react-hook-form';
4
+ import { default as React } from 'react';
5
+
6
+ export type UseFormProps<TFieldValues extends FieldValues, TTransformedValues extends FieldValues> = {
7
+ rhf: RhfUseFormProps<TFieldValues>;
8
+ props: FormProps<TFieldValues, TTransformedValues>;
9
+ utils?: FormUtilsContextProviderProps;
10
+ };
11
+ export type UseFormReturn = ReturnType<typeof useForm>;
12
+ /**
13
+ * Base Rhf Form hook. Use `Form` in `index.ts` for most cases.
14
+ * Use this if you need to separate form components.
15
+ * e.g., a form for table row due to `form` being considered invalid HTML around `tr` tags.
16
+ * With this hook, you can wrap the `tr` tag with `form.Provider` and use `form.Form` inside
17
+ * one of the cells. Other components can be outside form while referring to form by its id via `form` attribute.
18
+ * see https://caniuse.com/?search=form%20attribute
19
+ * @returns Form provider and form.
20
+ */
21
+ export declare const useForm: <TFieldValues extends FieldValues, TTransformedValues extends FieldValues>({ rhf, props, utils, }: UseFormProps<TFieldValues, TTransformedValues>) => {
22
+ Provider: React.FC<{
23
+ children?: React.ReactNode;
24
+ }>;
25
+ Form: React.FC<{
26
+ children?: React.ReactNode;
27
+ }>;
28
+ };
@@ -0,0 +1,2 @@
1
+ declare const useFormIsBusy: () => boolean;
2
+ export default useFormIsBusy;
@@ -1,17 +1,22 @@
1
1
  export { default as LazyDevTool } from './devtool/LazyDevTool';
2
+ export { default as useFormErrorsFlatContext } from './errors/context';
3
+ export { default as FormErrorsFlatContextProvider } from './errors/context/provider';
2
4
  export { default as FormErrorMessage } from './errors/message/FormErrorMessage';
3
5
  export { default as FormErrorMessageByPath } from './errors/message/FormErrorMessageByPath';
4
6
  export { default as FormNonFieldErrorMarker } from './errors/nonfield/FormNonFieldErrorMarker';
5
- export { default as FormNonFieldErrorMarkerHtmlAttribute } from './errors/nonfield/FormNonFieldErrorMarker.utils';
7
+ export { default as FormNonFieldErrorMarkerHtmlAttribute } from './errors/nonfield/FormNonFieldErrorMarkerHtmlAttribute';
6
8
  export { default as useFormHasOrphanAndNoFieldErrors } from './errors/orphan/useFormHasOrphanAndNoFieldErrors';
7
- export { default as useOrphanFormErrors } from './errors/orphan/useOrphanFormErrors';
8
- export { default as useOrphanFormErrorsToConsoleError } from './errors/orphan/useOrphanFormErrorsToConsoleError';
9
- export { default as useRootFormFieldErrors } from './errors/root/useRootFormFieldErrors';
9
+ export { default as useOrphanFormErrorsMemo } from './errors/orphan/useOrphanFormErrorsMemo';
10
+ export { default as useOrphanFormErrorsToConsole } from './errors/orphan/useOrphanFormErrorsToConsole';
11
+ export { default as useRootFormFieldErrorsMemo } from './errors/root/useRootFormFieldErrorsMemo';
10
12
  export { default as useFormErrorConsoleDebug } from './errors/useFormErrorConsoleDebug';
11
13
  export { default as useFormErrorsEffect } from './errors/useFormErrorsEffect';
12
14
  export { default as useFormErrorsIfAny } from './errors/useFormErrorsIfAny';
13
- export { default as useFormErrorsOnChange } from './errors/useFormErrorsOnChange';
15
+ export { default as useFormErrorsMemo } from './errors/useFormErrorsMemo';
14
16
  export { default as useFormRequestSubmit } from './errors/useFormRequestSubmit';
17
+ export { default as FormParentContextProvider } from './form/context/parent/FormParentContextProvider';
18
+ export { default as useAsFormParentState } from './form/context/parent/useAsFormParentState';
19
+ export { default as useFormParentIsBusy } from './form/context/parent/useFormParentIsBusy';
15
20
  export { default as useFormOnSubmitSuccessful } from './submit/useFormOnSubmitSuccessful';
16
21
  export { default as useFormOnSubmitSuccessfulAndReset } from './submit/useFormOnSubmitSuccessfulAndReset';
17
22
  export { default as useResetFormAfterSubmitSuccessful } from './submit/useResetFormOnSubmitSuccessful';
@@ -8,5 +8,5 @@ type Options = {
8
8
  * See `Rules` section: https://react-hook-form.com/api/useform/reset/
9
9
  * Specifically: "- It's recommended to reset inside useEffect after submission."
10
10
  */
11
- declare const useResetFormAfterSubmitSuccessful: (options?: Options) => void;
11
+ declare const useResetFormAfterSubmitSuccessful: ({ enabled, ...options }: Options) => void;
12
12
  export default useResetFormAfterSubmitSuccessful;
@@ -0,0 +1,8 @@
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;
@@ -0,0 +1,8 @@
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 createRequiredContext<T = unknown>(): readonly [() => T & ({} | null), React.Provider<T | undefined>];
8
+ export default createRequiredContext;
@@ -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,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> | undefined) => React.RefObject<TRef>;
11
+ export default useImperativeForwardedRef;
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.27",
5
+ "version": "0.0.30",
6
6
  "description": "Integration utilities for react-hook-form.",
7
7
  "type": "module",
8
8
  "sideEffects": false,
@@ -71,6 +71,18 @@
71
71
  "default": "./dist/esm/errors/root/useRootFormFieldErrors.mjs",
72
72
  "types": "./dist/types/errors/root/useRootFormFieldErrors.d.ts"
73
73
  },
74
+ "./form/context/parent/FormParentContextProvider": {
75
+ "default": "./dist/esm/form/context/parent/FormParentContextProvider.mjs",
76
+ "types": "./dist/types/form/context/parent/FormParentContextProvider.d.ts"
77
+ },
78
+ "./form/context/parent/useAsFormParentState": {
79
+ "default": "./dist/esm/form/context/parent/useAsFormParentState.mjs",
80
+ "types": "./dist/types/form/context/parent/useAsFormParentState.d.ts"
81
+ },
82
+ "./form/context/parent/useFormParentIsBusy": {
83
+ "default": "./dist/esm/form/context/parent/useFormParentIsBusy.mjs",
84
+ "types": "./dist/types/form/context/parent/useFormParentIsBusy.d.ts"
85
+ },
74
86
  "./submit/useFormOnSubmitSuccessful": {
75
87
  "default": "./dist/esm/submit/useFormOnSubmitSuccessful.mjs",
76
88
  "types": "./dist/types/submit/useFormOnSubmitSuccessful.d.ts"
@@ -99,6 +111,7 @@
99
111
  },
100
112
  "peerDependencies": {
101
113
  "flat": "^6",
114
+ "query-string": "^9",
102
115
  "react": "^18",
103
116
  "react-hook-form": "^7"
104
117
  },
@@ -109,6 +122,7 @@
109
122
  "@rollup/plugin-typescript": "^11.1.6",
110
123
  "@types/node": "^18.19.26",
111
124
  "@types/react": "^18.2.69",
125
+ "@types/react-dom": "^18.2.23",
112
126
  "@typescript-eslint/eslint-plugin": "^7.3.1",
113
127
  "@typescript-eslint/parser": "^7.3.1",
114
128
  "@vitejs/plugin-react": "^4.2.1",
@@ -145,9 +159,13 @@
145
159
  },
146
160
  "homepage": "https://github.com/paragrav/rhf-utils",
147
161
  "keywords": [
148
- "react-hook-form",
149
- "zod",
162
+ "integration",
150
163
  "form",
151
- "react"
164
+ "forms",
165
+ "react",
166
+ "react-hook-form",
167
+ "utilities",
168
+ "utils",
169
+ "zod"
152
170
  ]
153
171
  }
@@ -1,22 +0,0 @@
1
- import { get as f } from "react-hook-form";
2
- import n from "./flattenFieldErrors.mjs";
3
- const p = (t) => {
4
- const a = n(t), c = Object.keys(a);
5
- return Object.fromEntries(
6
- c.reduce(
7
- (e, o) => {
8
- const r = o.replace(d, "");
9
- if (r === o)
10
- return e;
11
- const s = f(t, r, void 0);
12
- return s && e.push([r, s]), e;
13
- },
14
- []
15
- // entries
16
- )
17
- );
18
- }, d = /\.(?:type|message)\b$/;
19
- export {
20
- p as default,
21
- d as regexMaybeFieldErrorLeafNode
22
- };
@@ -1,14 +0,0 @@
1
- import "react";
2
- import t from "../../isEmptyObject.mjs";
3
- import e from "../useFormErrorsOnChange.mjs";
4
- import n from "./getOrphanFlatFieldErrors.mjs";
5
- const m = (r) => e((o) => {
6
- if (t(o))
7
- return {};
8
- if (!r.current)
9
- throw new Error();
10
- return n(o, r.current);
11
- }), a = m;
12
- export {
13
- a as default
14
- };
@@ -1,24 +0,0 @@
1
- import n from "react";
2
- import { useFormContext as m, useFormState as a } from "react-hook-form";
3
- import c from "../../isEmptyObject.mjs";
4
- import p from "./useOrphanFormErrors.mjs";
5
- const u = (o, e) => {
6
- const { getValues: s } = m(), { errors: t } = a(), r = p(o);
7
- n.useEffect(() => {
8
- if (!c(r) && (console.error(
9
- "useOrphanFormErrorsToConsoleError",
10
- // include debugging details
11
- {
12
- location: window.location,
13
- values: s(),
14
- // form values
15
- errors: t,
16
- orphans: r
17
- }
18
- ), e))
19
- throw new Error("Orphan errors detected");
20
- }, [r]);
21
- }, h = u;
22
- export {
23
- h as default
24
- };
@@ -1,6 +0,0 @@
1
- import o from "../useFormErrorsOnChange.mjs";
2
- import { getRootFlatFieldErrors as r } from "./utils.mjs";
3
- const t = () => o(r), m = t;
4
- export {
5
- m as default
6
- };
@@ -1,11 +0,0 @@
1
- import s from "../getFlatFieldErrors.mjs";
2
- const t = "root", i = (r) => r === t || r.startsWith(t + "."), n = (r) => {
3
- const o = s(r);
4
- return Object.fromEntries(
5
- Object.entries(o).filter(([e]) => i(e))
6
- );
7
- };
8
- export {
9
- n as getRootFlatFieldErrors,
10
- i as isFormErrorPathRoot
11
- };
@@ -1,13 +0,0 @@
1
- import t from "./getFlatFieldErrors.mjs";
2
- import s from "./isFieldError.mjs";
3
- import i from "./useFormErrorsOnChange.mjs";
4
- const f = () => i(l), l = (r) => {
5
- const o = t(r);
6
- return Object.fromEntries(
7
- Object.entries(o).filter(([, e]) => s(e))
8
- );
9
- };
10
- export {
11
- f as default,
12
- l as getFlatFieldFormErrors
13
- };