@paragrav/rhf-utils 0.0.112 → 0.0.114

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 (109) hide show
  1. package/README.md +47 -16
  2. package/dist/esm/client/zod/context/RhfUtilsZodForm.mjs +12 -0
  3. package/dist/esm/client/zod/context/useRhfUtilsClientForZodContext.mjs +6 -0
  4. package/dist/esm/{src/devtool → devtool}/LazyDevTool.mjs +4 -4
  5. package/dist/esm/errors/flat/FlatFieldErrorsList.mjs +17 -0
  6. package/dist/esm/errors/flat/getFlatFieldErrors.mjs +25 -0
  7. package/dist/esm/errors/message/FormErrorMessage.mjs +14 -0
  8. package/dist/esm/errors/nonfield/FormNonFieldErrorMarkerHtmlAttribute.mjs +4 -0
  9. package/dist/esm/errors/trpc/getOnSubmitTrpcClientErrorHandler.mjs +6 -0
  10. package/dist/esm/errors/trpc/trpcClientErrorToFormSubmitErrorsSchemaTransformer.mjs +34 -0
  11. package/dist/esm/exports.mjs +48 -0
  12. package/dist/esm/form/Form.mjs +102 -0
  13. package/dist/esm/{src/form → form}/RhfUtilsFormProviders.mjs +1 -1
  14. package/dist/esm/form/context/utils/RhfUtilsContextProvider.mjs +27 -0
  15. package/dist/esm/form/context/utils/useRhfUtilsContext.mjs +6 -0
  16. package/dist/esm/form/context/utils/useRhfUtilsContextRequestSubmit.mjs +9 -0
  17. package/dist/esm/{src/form → form}/useRhfUtilsForm.mjs +21 -21
  18. package/dist/esm/submit/useFormOnSubmitSuccessful.mjs +11 -0
  19. package/dist/esm/{src/submit → submit}/useSubmitFormOnChange.mjs +1 -1
  20. package/dist/esm/utils/isEmptyObject.mjs +4 -0
  21. package/dist/types/client/config/RhfUtilsClientConfig.d.ts +4 -6
  22. package/dist/types/client/zod/RhfUtilsUseFormChildrenZodProps.d.ts +2 -1
  23. package/dist/types/client/zod/consts.d.ts +4 -0
  24. package/dist/types/client/zod/context/RhfUtilsZodForm.d.ts +9 -0
  25. package/dist/types/client/zod/context/useRhfUtilsZodForm.d.ts +2 -1
  26. package/dist/types/errors/flat/getFlatFieldErrors.d.ts +3 -2
  27. package/dist/types/errors/orphan/useOrphanFormErrorsMemo.d.ts +5 -0
  28. package/dist/types/errors/trpc/getOnSubmitTrpcClientErrorHandler.d.ts +2 -2
  29. package/dist/types/exports.d.ts +4 -15
  30. package/dist/types/form/UseRhfUtilsFormChildrenProps.d.ts +7 -0
  31. package/dist/types/form/UseRhfUtilsFormOnSubmitContext.d.ts +27 -0
  32. package/dist/types/form/UseRhfUtilsFormProps.d.ts +4 -3
  33. package/dist/types/form/UseRhfUtilsFormReturn.d.ts +5 -0
  34. package/dist/types/form/context/utils/RhfUtilsContextProvider.d.ts +11 -0
  35. package/dist/types/form/context/utils/useRhfUtilsContext.d.ts +14 -0
  36. package/dist/types/form/context/utils/useRhfUtilsContextRequestSubmit.d.ts +5 -0
  37. package/dist/types/form/utils/getSubmitterButtonData.d.ts +1 -1
  38. package/dist/types/form/utils/useFormRequestSubmit.d.ts +6 -0
  39. package/package.json +3 -5
  40. package/dist/esm/src/client/zod/RhfUtilsZodForm.mjs +0 -12
  41. package/dist/esm/src/client/zod/context/useRhfUtilsClientForZodContext.mjs +0 -6
  42. package/dist/esm/src/errors/flat/FlatFieldErrorsList.mjs +0 -17
  43. package/dist/esm/src/errors/flat/getFlatFieldErrors.mjs +0 -22
  44. package/dist/esm/src/errors/flat/useFormFlatFieldErrorsMemo.mjs +0 -6
  45. package/dist/esm/src/errors/message/FormErrorMessage.mjs +0 -14
  46. package/dist/esm/src/errors/nonfield/FormNonFieldErrorMarkerHtmlAttribute.mjs +0 -4
  47. package/dist/esm/src/errors/orphan/getOrphansFromFieldErrors.mjs +0 -6
  48. package/dist/esm/src/errors/orphan/useFormHasOnlyOrphanFieldErrorsMemo.mjs +0 -10
  49. package/dist/esm/src/errors/orphan/useOrphanFormErrorsMemo.mjs +0 -14
  50. package/dist/esm/src/errors/root/getRootsFromFieldErrors.mjs +0 -6
  51. package/dist/esm/src/errors/root/useRootFormFieldErrorsMemo.mjs +0 -6
  52. package/dist/esm/src/errors/trpc/getOnSubmitTrpcClientErrorHandler.mjs +0 -7
  53. package/dist/esm/src/errors/trpc/trpcClientErrorToFormSubmitErrorsSchemaTransformer.mjs +0 -35
  54. package/dist/esm/src/errors/useFormErrorsEffect.mjs +0 -11
  55. package/dist/esm/src/errors/useFormErrorsIfAny.mjs +0 -9
  56. package/dist/esm/src/exports.mjs +0 -70
  57. package/dist/esm/src/form/Form.mjs +0 -90
  58. package/dist/esm/src/form/context/utils/FormUtilsContextProvider.mjs +0 -35
  59. package/dist/esm/src/form/context/utils/useFormUtilsContext.mjs +0 -6
  60. package/dist/esm/src/submit/useFormOnSubmitSuccessful.mjs +0 -11
  61. package/dist/esm/src/utils/isEmptyObject.mjs +0 -4
  62. /package/dist/esm/{src/client → client}/config/useRhfUtilsClientConfigContext.mjs +0 -0
  63. /package/dist/esm/{src/client → client}/index.mjs +0 -0
  64. /package/dist/esm/{src/client → client}/zod/context/RhfUtilsClientForZodContextProvider.mjs +0 -0
  65. /package/dist/esm/{src/client → client}/zod/context/useRhfUtilsZodForm.mjs +0 -0
  66. /package/dist/esm/{src/client → client}/zod/createRhfUtilsClientForZod.mjs +0 -0
  67. /package/dist/esm/{src/errors → errors}/flat/context/FlatFieldErrorsContextProvider.mjs +0 -0
  68. /package/dist/esm/{src/errors → errors}/flat/context/useFlatFieldErrorsContext.mjs +0 -0
  69. /package/dist/esm/{src/errors → errors}/flat/filterFlatFieldErrors.mjs +0 -0
  70. /package/dist/esm/{src/errors → errors}/flat/flattenFieldErrors.mjs +0 -0
  71. /package/dist/esm/{src/errors → errors}/flat/useFlatFieldErrorsOutput.mjs +0 -0
  72. /package/dist/esm/{src/errors → errors}/isFieldErrorRefd.mjs +0 -0
  73. /package/dist/esm/{src/errors → errors}/message/FormErrorMessageByPath.mjs +0 -0
  74. /package/dist/esm/{src/errors → errors}/nonfield/FormNonFieldErrorMarker.mjs +0 -0
  75. /package/dist/esm/{src/errors → errors}/nonfield/FormNonFieldErrorMarker.utils.mjs +0 -0
  76. /package/dist/esm/{src/errors → errors}/nonfield/isNonFieldErrorMarkerInDOM.mjs +0 -0
  77. /package/dist/esm/{src/errors → errors}/orphan/getIsOrphanFormErrorWithParentElement.mjs +0 -0
  78. /package/dist/esm/{src/errors → errors}/orphan/getOrphansFromFlatFieldErrors.mjs +0 -0
  79. /package/dist/esm/{src/errors → errors}/orphan/isOrphanFormError.mjs +0 -0
  80. /package/dist/esm/{src/errors → errors}/output/consoleErrors.mjs +0 -0
  81. /package/dist/esm/{src/errors → errors}/root/RootErrorsListFromFlatFieldErrorsContext.mjs +0 -0
  82. /package/dist/esm/{src/errors → errors}/root/consts.mjs +0 -0
  83. /package/dist/esm/{src/errors → errors}/root/getRootsFromFlatFieldErrors.mjs +0 -0
  84. /package/dist/esm/{src/errors → errors}/root/isFlatFieldErrorEntryPathRoot.mjs +0 -0
  85. /package/dist/esm/{src/errors → errors}/root/isFormErrorPathRoot.mjs +0 -0
  86. /package/dist/esm/{src/errors → errors}/trpc/trpcClientErrorMessageSchema.mjs +0 -0
  87. /package/dist/esm/{src/errors → errors}/useFormErrorsTransformMemo.mjs +0 -0
  88. /package/dist/esm/{src/form → form}/FormWithProviders.mjs +0 -0
  89. /package/dist/esm/{src/form → form}/_Controller.mjs +0 -0
  90. /package/dist/esm/{src/form → form}/_FormBase.mjs +0 -0
  91. /package/dist/esm/{src/form → form}/context/group/FormGroupContextProvider.mjs +0 -0
  92. /package/dist/esm/{src/form → form}/context/group/index.mjs +0 -0
  93. /package/dist/esm/{src/form → form}/context/group/useFormGroupChildIsMountedTracker.mjs +0 -0
  94. /package/dist/esm/{src/form → form}/context/group/useFormGroupChildIsSubmittingTracker.mjs +0 -0
  95. /package/dist/esm/{src/form → form}/context/group/useFormGroupChildTracker.mjs +0 -0
  96. /package/dist/esm/{src/form → form}/context/group/useFormGroupIsAnyBusy.mjs +0 -0
  97. /package/dist/esm/{src/form → form}/context/group/useFormGroupIsChildBusy.mjs +0 -0
  98. /package/dist/esm/{src/form → form}/context/group/useFormGroupIsParentBusy.mjs +0 -0
  99. /package/dist/esm/{src/form → form}/context/group/useFormGroupParentTracker.mjs +0 -0
  100. /package/dist/esm/{src/form → form}/context/group/useFormOrParentIsBusy.mjs +0 -0
  101. /package/dist/esm/{src/form → form}/useFormIsBusy.mjs +0 -0
  102. /package/dist/esm/{src/form → form}/utils/getSubmitterButtonData.mjs +0 -0
  103. /package/dist/esm/{src/errors → form/utils}/useFormRequestSubmit.mjs +0 -0
  104. /package/dist/esm/{src/submit → submit}/error/FormSubmitError.mjs +0 -0
  105. /package/dist/esm/{src/submit → submit}/error/setCtxErrorsByFormSubmitErrors.mjs +0 -0
  106. /package/dist/esm/{src/submit → submit}/useFormOnSubmitSuccessfulAndReset.mjs +0 -0
  107. /package/dist/esm/{src/submit → submit}/useResetFormOnSubmitError.mjs +0 -0
  108. /package/dist/esm/{src/submit → submit}/useResetFormOnSubmitSuccessful.mjs +0 -0
  109. /package/dist/esm/{src/utils → utils}/createContext.mjs +0 -0
@@ -2,9 +2,9 @@ import { RhfUtilsClientConfig } from '../../client/config/RhfUtilsClientConfig';
2
2
  import { FormSubmitErrors } from '../../submit/error/FormSubmitErrors';
3
3
 
4
4
  /**
5
- * HOF that returns submit error handler for {@link RhfUtilsClientConfig.onSubmitError}.
5
+ * HOF that returns submit error handler for {@link RhfUtilsClientConfig.onUnknownSubmitError}.
6
6
  *
7
7
  * @param onError Fallback for handling non-TRPC errors.
8
8
  * @returns FormSubmitError
9
9
  */
10
- export declare const getOnSubmitTrpcClientErrorHandler: (onNotTrpcClientError: NonNullable<RhfUtilsClientConfig['onSubmitError']>) => (error: unknown) => FormSubmitErrors | undefined;
10
+ export declare const getOnSubmitTrpcClientErrorHandler: (onNotTrpcClientError: NonNullable<RhfUtilsClientConfig['onUnknownSubmitError']>) => (error: unknown) => FormSubmitErrors | undefined;
@@ -1,32 +1,21 @@
1
1
  export type { Register } from './register';
2
2
  export type { RhfUtilsClientConfig } from './client/config/RhfUtilsClientConfig';
3
3
  export { default as RhfUtilsClientForZodContextProvider } from './client/zod/context/RhfUtilsClientForZodContextProvider';
4
- export { default as useRhfUtilsClientForZodContext } from './client/zod/context/useRhfUtilsClientForZodContext';
4
+ export { default as RhfUtilsZodForm } from './client/zod/context/RhfUtilsZodForm';
5
5
  export { default as useRhfUtilsZodForm } from './client/zod/context/useRhfUtilsZodForm';
6
6
  export type { RhfUtilsUseFormChildrenZodFC } from './client/zod/RhfUtilsUseFormChildrenZodFC';
7
7
  export type { RhfUtilsUseFormChildrenZodProps } from './client/zod/RhfUtilsUseFormChildrenZodProps';
8
- export { default as RhfUtilsZodForm } from './client/zod/RhfUtilsZodForm';
9
- export { default as LazyDevTool } from './devtool/LazyDevTool';
10
8
  export { default as useFlatFieldErrorsContext } from './errors/flat/context/useFlatFieldErrorsContext';
11
- export { default as FlatFieldErrorsList } from './errors/flat/FlatFieldErrorsList';
12
- export { default as FormErrorMessage } from './errors/message/FormErrorMessage';
13
9
  export { default as FormErrorMessageByPath } from './errors/message/FormErrorMessageByPath';
14
10
  export { default as FormNonFieldErrorMarker } from './errors/nonfield/FormNonFieldErrorMarker';
15
- export { default as FormNonFieldErrorMarkerHtmlAttribute } from './errors/nonfield/FormNonFieldErrorMarkerHtmlAttribute';
16
- export { default as useFormHasOnlyOrphanFieldErrorsMemo } from './errors/orphan/useFormHasOnlyOrphanFieldErrorsMemo';
17
- export { default as useOrphanFormErrorsMemo } from './errors/orphan/useOrphanFormErrorsMemo';
18
11
  export { default as RootErrorsListFromFlatFieldErrorsContext } from './errors/root/RootErrorsListFromFlatFieldErrorsContext';
19
- export { default as useRootFormFieldErrorsMemo } from './errors/root/useRootFormFieldErrorsMemo';
20
12
  export { getOnSubmitTrpcClientErrorHandler } from './errors/trpc/getOnSubmitTrpcClientErrorHandler';
21
13
  export { trpcClientErrorToFormSubmitErrorsSchemaTransformer } from './errors/trpc/trpcClientErrorToFormSubmitErrorsSchemaTransformer';
22
- export { default as useFormErrorsEffect } from './errors/useFormErrorsEffect';
23
- export { default as useFormErrorsIfAny } from './errors/useFormErrorsIfAny';
24
- export { default as FormWithProviders } from './form/FormWithProviders';
25
14
  export type { RhfUtilsFormOptions } from './form/RhfUtilsFormOptions';
26
15
  export type { SafeFieldValues } from './form/SafeFieldValues';
27
- export { default as useRhfUtilsForm } from './form/useRhfUtilsForm';
28
16
  export type { UseRhfUtilsFormChildrenProps } from './form/UseRhfUtilsFormChildrenProps';
29
- export { default as useFormUtilsContext } from './form/context/utils/useFormUtilsContext';
17
+ export { default as useRhfUtilsContext } from './form/context/utils/useRhfUtilsContext';
18
+ export { default as useRhfUtilsContextRequestSubmit } from './form/context/utils/useRhfUtilsContextRequestSubmit';
30
19
  export { default as FormGroupContextProvider } from './form/context/group/FormGroupContextProvider';
31
20
  export { default as useFormGroupChildIsMountedTracker } from './form/context/group/useFormGroupChildIsMountedTracker';
32
21
  export { default as useFormGroupChildIsSubmittingTracker } from './form/context/group/useFormGroupChildIsSubmittingTracker';
@@ -37,5 +26,5 @@ export { default as useFormGroupIsParentBusy } from './form/context/group/useFor
37
26
  export { default as useFormGroupParentTracker } from './form/context/group/useFormGroupParentTracker';
38
27
  export { default as useFormOrParentIsBusy } from './form/context/group/useFormOrParentIsBusy';
39
28
  export { default as getSubmitterButtonData } from './form/utils/getSubmitterButtonData';
29
+ export { default as useFormRequestSubmit } from './form/utils/useFormRequestSubmit';
40
30
  export { FormSubmitError } from './submit/error/FormSubmitError';
41
- export { default as useFormOnSubmitSuccessful } from './submit/useFormOnSubmitSuccessful';
@@ -1,13 +1,20 @@
1
1
  import { default as React } from 'react';
2
2
  import { UseFormReturn } from 'react-hook-form';
3
+ import { FormSubmitError } from '../submit/error/FormSubmitError';
3
4
  import { default as _Controller } from './_Controller';
4
5
  import { RhfUtilsFormOptions } from './RhfUtilsFormOptions';
5
6
  import { SafeFieldValues } from './SafeFieldValues';
6
7
 
8
+ /**
9
+ * Component props for `Children`.
10
+ *
11
+ * Consider keeping shape in line with `UseRhfUtilsFormOnSubmitProps` and `UseRhfUtilsFormReturn`.
12
+ */
7
13
  export type UseRhfUtilsFormChildrenProps<TFieldValues extends SafeFieldValues = SafeFieldValues, TTransformedValues extends SafeFieldValues = SafeFieldValues> = {
8
14
  formId: string;
9
15
  formRef: React.RefObject<HTMLFormElement>;
10
16
  context: UseFormReturn<TFieldValues, unknown, TTransformedValues>;
11
17
  utils?: RhfUtilsFormOptions;
12
18
  Controller: typeof _Controller<TFieldValues>;
19
+ FormSubmitError: typeof FormSubmitError<TFieldValues>;
13
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
+ };
@@ -1,13 +1,14 @@
1
1
  import { default as React } from 'react';
2
- import { SubmitErrorHandler, UseFormProps, UseFormReturn } from 'react-hook-form';
2
+ import { SubmitErrorHandler, UseFormProps } from 'react-hook-form';
3
3
  import { RhfUtilsFormOptions } from './RhfUtilsFormOptions';
4
4
  import { SafeFieldValues } from './SafeFieldValues';
5
5
  import { UseRhfUtilsFormChildrenProps } from './UseRhfUtilsFormChildrenProps';
6
+ import { UseRhfUtilsFormOnSubmitContext, UseRhfUtilsFormOnSubmitErrorContext } from './UseRhfUtilsFormOnSubmitContext';
6
7
 
7
8
  export type UseRhfUtilsFormProps<TFieldValues extends SafeFieldValues, TTransformedValues extends SafeFieldValues> = {
8
- onSubmit?: (values: TTransformedValues, context: UseFormReturn<TFieldValues, unknown, TTransformedValues>, event: React.BaseSyntheticEvent<SubmitEvent>) => unknown | Promise<unknown>;
9
+ onSubmit?: (values: TTransformedValues, context: UseRhfUtilsFormOnSubmitContext<TFieldValues, TTransformedValues>, event: React.BaseSyntheticEvent<SubmitEvent>) => unknown | Promise<unknown>;
9
10
  /** Submit error handler. (Only for errors not of instance `FormError`, which are handled internally.) */
10
- onSubmitError?: (error: unknown, context: UseFormReturn<TFieldValues, unknown, TTransformedValues>, event: React.BaseSyntheticEvent<SubmitEvent>) => void;
11
+ onSubmitError?: (error: unknown, context: UseRhfUtilsFormOnSubmitErrorContext<TFieldValues, TTransformedValues>, event: React.BaseSyntheticEvent<SubmitEvent>) => void;
11
12
  /** Submit handler when form is invalid. */
12
13
  onSubmitInvalid?: SubmitErrorHandler<TFieldValues>;
13
14
  defaultValues?: UseFormProps<TFieldValues>['defaultValues'];
@@ -5,6 +5,11 @@ import { FormProps } from './Form';
5
5
  import { RhfUtilsFormProvidersProps } from './RhfUtilsFormProviders';
6
6
  import { SafeFieldValues } from './SafeFieldValues';
7
7
 
8
+ /**
9
+ * Return type for `useRhfUtilsForm`.
10
+ *
11
+ * Consider keeping shape in line with `UseRhfUtilsFormChildrenProps` and `UseRhfUtilsFormOnSubmitProps`.
12
+ */
8
13
  export type UseRhfUtilsFormReturn<TFieldValues extends SafeFieldValues, TTransformedValues extends SafeFieldValues> = {
9
14
  id: string;
10
15
  ref: React.RefObject<HTMLFormElement>;
@@ -0,0 +1,11 @@
1
+ import { RhfUtilsFormOptions } from '../../RhfUtilsFormOptions';
2
+
3
+ type Props = React.PropsWithChildren<{
4
+ formId: string;
5
+ formRef: React.RefObject<HTMLFormElement>;
6
+ /** Callback after successful submit, and form reset. */
7
+ onSubmitSuccessfulAndReset?: () => void;
8
+ options?: RhfUtilsFormOptions;
9
+ }>;
10
+ declare function RhfUtilsContextProvider({ formId, formRef, onSubmitSuccessfulAndReset, options, children, }: Props): import("react/jsx-runtime").JSX.Element;
11
+ 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 | undefined) => void;
5
+ export default useRhfUtilsContextRequestSubmit;
@@ -1,7 +1,7 @@
1
1
  import { default as React } from 'react';
2
2
 
3
3
  /**
4
- * Get [name, value] of button/input that submitted form.
4
+ * Get [name, value] tuple of button/input that submitted form.
5
5
  * Useful when determining user intent
6
6
  */
7
7
  declare const getSubmitterButtonData: (event: React.BaseSyntheticEvent) => [
@@ -0,0 +1,6 @@
1
+ /**
2
+ * Get callback to trigger submit manually on form.
3
+ * @link https://developer.mozilla.org/docs/Web/API/HTMLFormElement/requestSubmit
4
+ */
5
+ declare const useFormRequestSubmit: (ref: React.RefObject<HTMLFormElement>) => HTMLFormElement['requestSubmit'];
6
+ export default useFormRequestSubmit;
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.112",
5
+ "version": "0.0.114",
6
6
  "description": "Integration utilities for react-hook-form.",
7
7
  "type": "module",
8
8
  "sideEffects": false,
@@ -22,16 +22,14 @@
22
22
  "peerDependencies": {
23
23
  "@hookform/devtools": "4",
24
24
  "@hookform/resolvers": "3",
25
+ "@trpc/client": "next",
26
+ "@trpc/server": "next",
25
27
  "flat": "6",
26
28
  "react": "18",
27
29
  "react-dom": "18",
28
30
  "react-hook-form": "7",
29
31
  "zod": "3"
30
32
  },
31
- "optionalDependencies": {
32
- "@trpc/client": "next",
33
- "@trpc/server": "next"
34
- },
35
33
  "repository": {
36
34
  "type": "git",
37
35
  "url": "git+https://github.com/paragrav/rhf-utils.git"
@@ -1,12 +0,0 @@
1
- import { jsx as e } from "react/jsx-runtime";
2
- import i from "./context/useRhfUtilsClientForZodContext.mjs";
3
- function f({
4
- schema: o,
5
- ...t
6
- }) {
7
- const r = i();
8
- return /* @__PURE__ */ e(r.FormWithProviders, { schema: o, ...t });
9
- }
10
- export {
11
- f as default
12
- };
@@ -1,6 +0,0 @@
1
- import t from "../../../utils/createContext.mjs";
2
- const [, o, n] = t(), r = o;
3
- export {
4
- n as _RhfUtilsClientForZodContextProvider,
5
- r as default
6
- };
@@ -1,17 +0,0 @@
1
- import { jsx as e } from "react/jsx-runtime";
2
- import l from "../../utils/isEmptyObject.mjs";
3
- const a = ({ errors: t }) => {
4
- if (t && !l(t))
5
- return /* @__PURE__ */ e("ul", { children: Object.values(t).map((r, i) => /* @__PURE__ */ e(
6
- "li",
7
- {
8
- role: "alert",
9
- "aria-live": "polite",
10
- children: r.message
11
- },
12
- i
13
- )) });
14
- }, m = a;
15
- export {
16
- m as default
17
- };
@@ -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,6 +0,0 @@
1
- import r from "../useFormErrorsTransformMemo.mjs";
2
- import o from "./getFlatFieldErrors.mjs";
3
- const s = () => r(o);
4
- export {
5
- s as default
6
- };
@@ -1,14 +0,0 @@
1
- import { jsx as e } from "react/jsx-runtime";
2
- import "react";
3
- const s = ({ message: r, className: o }) => /* @__PURE__ */ e(
4
- "p",
5
- {
6
- role: "alert",
7
- "aria-live": "polite",
8
- className: o,
9
- children: r
10
- }
11
- ), i = s;
12
- export {
13
- i as default
14
- };
@@ -1,4 +0,0 @@
1
- const r = "data-paragrav-rhf-utils-nonfield-error-marker-path", t = r;
2
- export {
3
- t as default
4
- };
@@ -1,6 +0,0 @@
1
- import t from "../flat/getFlatFieldErrors.mjs";
2
- import e from "./getOrphansFromFlatFieldErrors.mjs";
3
- const a = (r, o) => e(t(r), o);
4
- export {
5
- a as default
6
- };
@@ -1,10 +0,0 @@
1
- import s from "../../utils/isEmptyObject.mjs";
2
- import t from "../flat/useFormFlatFieldErrorsMemo.mjs";
3
- import m from "./useOrphanFormErrorsMemo.mjs";
4
- const n = (o) => {
5
- const e = t(), r = m(o);
6
- return s(r) ? !1 : Object.keys(e).length !== Object.keys(r).length;
7
- }, i = n;
8
- export {
9
- i as default
10
- };
@@ -1,14 +0,0 @@
1
- import "react";
2
- import t from "../../utils/isEmptyObject.mjs";
3
- import m from "../useFormErrorsTransformMemo.mjs";
4
- import e from "./getOrphansFromFieldErrors.mjs";
5
- const s = (r) => m((o) => {
6
- if (t(o))
7
- return {};
8
- if (!r.current)
9
- throw new Error();
10
- return e(o, r.current);
11
- }), a = s;
12
- export {
13
- a as default
14
- };
@@ -1,6 +0,0 @@
1
- import o from "../flat/getFlatFieldErrors.mjs";
2
- import t from "./getRootsFromFlatFieldErrors.mjs";
3
- const F = (r) => t(o(r));
4
- export {
5
- F as default
6
- };
@@ -1,6 +0,0 @@
1
- import o from "../useFormErrorsTransformMemo.mjs";
2
- import r from "./getRootsFromFieldErrors.mjs";
3
- const e = () => o(r), t = e;
4
- export {
5
- t as default
6
- };
@@ -1,7 +0,0 @@
1
- import { TRPCClientError as o } from "../../../node_modules/.pnpm/@trpc_client@11.0.0-rc.390_@trpc_server@11.0.0-rc.390/node_modules/@trpc/client/dist/TRPCClientError.mjs";
2
- import "../../../node_modules/.pnpm/@trpc_server@11.0.0-rc.390/node_modules/@trpc/server/dist/unstable-core-do-not-import/rootConfig.mjs";
3
- import { trpcClientErrorToFormSubmitErrorsSchemaTransformer as n } from "./trpcClientErrorToFormSubmitErrorsSchemaTransformer.mjs";
4
- const p = (t) => (r) => r instanceof o ? n.parse(r) : t(r);
5
- export {
6
- p as getOnSubmitTrpcClientErrorHandler
7
- };
@@ -1,35 +0,0 @@
1
- import { TRPCClientError as e } from "../../../node_modules/.pnpm/@trpc_client@11.0.0-rc.390_@trpc_server@11.0.0-rc.390/node_modules/@trpc/client/dist/TRPCClientError.mjs";
2
- import "../../../node_modules/.pnpm/@trpc_server@11.0.0-rc.390/node_modules/@trpc/server/dist/unstable-core-do-not-import/rootConfig.mjs";
3
- import { z as o } from "zod";
4
- import { trpcClientErrorMessageSchema as m } from "./trpcClientErrorMessageSchema.mjs";
5
- const p = o.custom(
6
- (r) => r instanceof e
7
- // check instance type
8
- ).transform((r) => r.message).transform((r) => {
9
- try {
10
- return JSON.parse(r);
11
- } catch {
12
- return [
13
- {
14
- validation: "root",
15
- code: "server",
16
- message: r,
17
- path: ["root"]
18
- }
19
- ];
20
- }
21
- }).pipe(o.array(m)).transform(
22
- (r) => r.map(
23
- (t) => [
24
- t.path.join("."),
25
- // flatten path (e.g., "street.name")
26
- {
27
- type: t.code,
28
- message: t.message
29
- }
30
- ]
31
- )
32
- ).transform((r) => Object.fromEntries(r));
33
- export {
34
- p as trpcClientErrorToFormSubmitErrorsSchemaTransformer
35
- };
@@ -1,11 +0,0 @@
1
- import t from "react";
2
- import { useFormState as e } from "react-hook-form";
3
- const s = (o) => {
4
- const { errors: r } = e();
5
- t.useEffect(() => {
6
- o(r);
7
- }, [r]);
8
- }, m = s;
9
- export {
10
- m as default
11
- };
@@ -1,9 +0,0 @@
1
- import { useFormState as o } from "react-hook-form";
2
- import s from "../utils/isEmptyObject.mjs";
3
- const t = () => {
4
- const { errors: r } = o();
5
- return s(r) ? !1 : r;
6
- }, f = t;
7
- export {
8
- f as default
9
- };
@@ -1,70 +0,0 @@
1
- import { default as e } from "./client/zod/context/RhfUtilsClientForZodContextProvider.mjs";
2
- import { default as s } from "./client/zod/context/useRhfUtilsClientForZodContext.mjs";
3
- import { default as f } from "./client/zod/context/useRhfUtilsZodForm.mjs";
4
- import { default as u } from "./client/zod/RhfUtilsZodForm.mjs";
5
- import { default as d } from "./devtool/LazyDevTool.mjs";
6
- import { default as x } from "./errors/flat/context/useFlatFieldErrorsContext.mjs";
7
- import { default as i } from "./errors/flat/FlatFieldErrorsList.mjs";
8
- import { default as E } from "./errors/message/FormErrorMessage.mjs";
9
- import { default as C } from "./errors/message/FormErrorMessageByPath.mjs";
10
- import { default as y } from "./errors/nonfield/FormNonFieldErrorMarker.mjs";
11
- import { default as M } from "./errors/nonfield/FormNonFieldErrorMarkerHtmlAttribute.mjs";
12
- import { default as T } from "./errors/orphan/useFormHasOnlyOrphanFieldErrorsMemo.mjs";
13
- import { default as I } from "./errors/orphan/useOrphanFormErrorsMemo.mjs";
14
- import { default as R } from "./errors/root/RootErrorsListFromFlatFieldErrorsContext.mjs";
15
- import { default as B } from "./errors/root/useRootFormFieldErrorsMemo.mjs";
16
- import { getOnSubmitTrpcClientErrorHandler as U } from "./errors/trpc/getOnSubmitTrpcClientErrorHandler.mjs";
17
- import { trpcClientErrorToFormSubmitErrorsSchemaTransformer as v } from "./errors/trpc/trpcClientErrorToFormSubmitErrorsSchemaTransformer.mjs";
18
- import { default as A } from "./errors/useFormErrorsEffect.mjs";
19
- import { default as L } from "./errors/useFormErrorsIfAny.mjs";
20
- import { default as N } from "./form/FormWithProviders.mjs";
21
- import { default as W } from "./form/useRhfUtilsForm.mjs";
22
- import { default as q } from "./form/context/utils/useFormUtilsContext.mjs";
23
- import { default as J } from "./form/context/group/FormGroupContextProvider.mjs";
24
- import { default as Q } from "./form/context/group/useFormGroupChildIsMountedTracker.mjs";
25
- import { default as X } from "./form/context/group/useFormGroupChildIsSubmittingTracker.mjs";
26
- import { default as _ } from "./form/context/group/useFormGroupChildTracker.mjs";
27
- import { default as rr } from "./form/context/group/useFormGroupIsAnyBusy.mjs";
28
- import { default as er } from "./form/context/group/useFormGroupIsChildBusy.mjs";
29
- import { default as sr } from "./form/context/group/useFormGroupIsParentBusy.mjs";
30
- import { default as fr } from "./form/context/group/useFormGroupParentTracker.mjs";
31
- import { default as ur } from "./form/context/group/useFormOrParentIsBusy.mjs";
32
- import { default as dr } from "./form/utils/getSubmitterButtonData.mjs";
33
- import { FormSubmitError as xr } from "./submit/error/FormSubmitError.mjs";
34
- import { default as ir } from "./submit/useFormOnSubmitSuccessful.mjs";
35
- export {
36
- i as FlatFieldErrorsList,
37
- E as FormErrorMessage,
38
- C as FormErrorMessageByPath,
39
- J as FormGroupContextProvider,
40
- y as FormNonFieldErrorMarker,
41
- M as FormNonFieldErrorMarkerHtmlAttribute,
42
- xr as FormSubmitError,
43
- N as FormWithProviders,
44
- d as LazyDevTool,
45
- e as RhfUtilsClientForZodContextProvider,
46
- u as RhfUtilsZodForm,
47
- R as RootErrorsListFromFlatFieldErrorsContext,
48
- U as getOnSubmitTrpcClientErrorHandler,
49
- dr as getSubmitterButtonData,
50
- v as trpcClientErrorToFormSubmitErrorsSchemaTransformer,
51
- x as useFlatFieldErrorsContext,
52
- A as useFormErrorsEffect,
53
- L as useFormErrorsIfAny,
54
- Q as useFormGroupChildIsMountedTracker,
55
- X as useFormGroupChildIsSubmittingTracker,
56
- _ as useFormGroupChildTracker,
57
- rr as useFormGroupIsAnyBusy,
58
- er as useFormGroupIsChildBusy,
59
- sr as useFormGroupIsParentBusy,
60
- fr as useFormGroupParentTracker,
61
- T as useFormHasOnlyOrphanFieldErrorsMemo,
62
- ir as useFormOnSubmitSuccessful,
63
- ur as useFormOrParentIsBusy,
64
- q as useFormUtilsContext,
65
- I as useOrphanFormErrorsMemo,
66
- s as useRhfUtilsClientForZodContext,
67
- W as useRhfUtilsForm,
68
- f as useRhfUtilsZodForm,
69
- B as useRootFormFieldErrorsMemo
70
- };
@@ -1,90 +0,0 @@
1
- import { jsxs as j, jsx as d } from "react/jsx-runtime";
2
- import "react";
3
- import { useFormContext as B } from "react-hook-form";
4
- import T from "../client/config/useRhfUtilsClientConfigContext.mjs";
5
- import _ from "../devtool/LazyDevTool.mjs";
6
- import { FormSubmitError as D } from "../submit/error/FormSubmitError.mjs";
7
- import N from "../submit/error/setCtxErrorsByFormSubmitErrors.mjs";
8
- import P from "./_Controller.mjs";
9
- import S from "./_FormBase.mjs";
10
- function A({
11
- formId: x,
12
- formRef: c,
13
- //
14
- onSubmit: p,
15
- onSubmitError: s,
16
- onSubmitInvalid: y,
17
- Children: l,
18
- //
19
- form: m,
20
- utils: o,
21
- //
22
- children: f
23
- }) {
24
- const a = B(), t = T(), v = async (e) => {
25
- o != null && o.stopSubmitPropagation && e.stopPropagation();
26
- try {
27
- await a.handleSubmit(b, y)(e);
28
- } catch (r) {
29
- F(r, e);
30
- }
31
- }, b = (e, r) => p == null ? void 0 : p(
32
- e,
33
- a,
34
- r
35
- ), F = (e, r) => {
36
- var h;
37
- const n = e instanceof D ? (
38
- // consumer can manually throw FormSubmitError (e.g., manual validation)
39
- e.errors
40
- ) : (
41
- // if error is not FormSubmitError, consumer can provide global handler
42
- (h = t == null ? void 0 : t.onSubmitError) == null ? void 0 : h.call(t, e)
43
- );
44
- n && N(a, n), s == null || s(
45
- e,
46
- a,
47
- r
48
- );
49
- }, i = {
50
- formId: x,
51
- formRef: c,
52
- context: a,
53
- utils: o,
54
- Controller: P
55
- }, C = (e) => {
56
- var n;
57
- const r = (n = t == null ? void 0 : t.Children) == null ? void 0 : n[e];
58
- return r && /* @__PURE__ */ d(r, { ...i });
59
- };
60
- return /* @__PURE__ */ j(
61
- S,
62
- {
63
- noValidate: !0,
64
- style: {
65
- position: "relative"
66
- },
67
- config: t,
68
- formRef: c,
69
- ...m,
70
- className: [o == null ? void 0 : o.classNames, m == null ? void 0 : m.className].filter(Boolean).join(" "),
71
- onSubmit: v,
72
- children: [
73
- C("top"),
74
- (o == null ? void 0 : o.devTool) && /* @__PURE__ */ d(
75
- _,
76
- {
77
- isDevelopment: t == null ? void 0 : t.isDevelopment,
78
- props: typeof o.devTool == "object" ? o.devTool : void 0
79
- }
80
- ),
81
- l && /* @__PURE__ */ d(l, { ...i }),
82
- f,
83
- C("bottom")
84
- ]
85
- }
86
- );
87
- }
88
- export {
89
- A as default
90
- };
@@ -1,35 +0,0 @@
1
- import { jsx as a } from "react/jsx-runtime";
2
- import l from "../../../errors/flat/useFlatFieldErrorsOutput.mjs";
3
- import b from "../../../errors/useFormRequestSubmit.mjs";
4
- import f from "../../../submit/useFormOnSubmitSuccessfulAndReset.mjs";
5
- import O from "../../../submit/useResetFormOnSubmitError.mjs";
6
- import i from "../../../submit/useResetFormOnSubmitSuccessful.mjs";
7
- import d from "../../../submit/useSubmitFormOnChange.mjs";
8
- import { _FormUtilsContextProvider as x } from "./useFormUtilsContext.mjs";
9
- function j({
10
- formId: t,
11
- formRef: e,
12
- onSubmitSuccessfulAndReset: m,
13
- options: r,
14
- children: u
15
- }) {
16
- const F = b(e);
17
- return l(), d(e, {
18
- disabled: !(r != null && r.submitOnChange)
19
- }), O({
20
- disabled: !(r != null && r.resetValuesOnSubmitError)
21
- }), i(
22
- (r == null ? void 0 : r.resetFormAfterSubmitSuccessful) || !!m
23
- ), f(() => {
24
- m == null || m();
25
- }), /* @__PURE__ */ a(
26
- x,
27
- {
28
- value: { formId: t, formRef: e, requestSubmit: F, options: r },
29
- children: u
30
- }
31
- );
32
- }
33
- export {
34
- j as default
35
- };
@@ -1,6 +0,0 @@
1
- import t from "../../../utils/createContext.mjs";
2
- const [, o, r] = t(), s = o;
3
- export {
4
- r as _FormUtilsContextProvider,
5
- s as default
6
- };