@paragrav/rhf-utils 0.0.48 → 0.0.51

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 (133) hide show
  1. package/dist/assets/index-BgBykTYQ.js +40 -0
  2. package/dist/esm/devtool/LazyDevTool.mjs +7 -11
  3. package/dist/esm/env-conditions/production.mjs +4 -0
  4. package/dist/esm/errors/context/provider.mjs +11 -9
  5. package/dist/esm/errors/orphan/useOrphanFormErrorsToConsole.mjs +8 -9
  6. package/dist/esm/errors/outputErrors.mjs +5 -6
  7. package/dist/esm/errors/root/FormRootErrors.mjs +7 -7
  8. package/dist/esm/errors/root/FormRootErrorsFromContext.mjs +11 -0
  9. package/dist/esm/errors/useFormErrorsEffect.mjs +6 -6
  10. package/dist/esm/errors/useFormErrorsToConsole.mjs +17 -13
  11. package/dist/esm/{main.mjs → exports.mjs} +44 -42
  12. package/dist/esm/form/Form.mjs +41 -65
  13. package/dist/esm/form/FormWithProviders.mjs +10 -0
  14. package/dist/esm/form/context/FormProvider.mjs +17 -19
  15. package/dist/esm/form/context/group/useFormGroupChildIsMountedTracker.mjs +3 -1
  16. package/dist/esm/form/context/utils/FormUtilsContextProvider.mjs +10 -10
  17. package/dist/esm/form/useForm.mjs +15 -17
  18. package/dist/esm/form/useFormWithProviders.mjs +28 -0
  19. package/dist/esm/{form/FormError.mjs → submit/error/FormSubmitError.mjs} +2 -2
  20. package/dist/esm/submit/error/handleFormSubmitError.mjs +12 -0
  21. package/dist/esm/submit/useResetFormOnSubmitError.mjs +18 -0
  22. package/dist/esm/submit/useSubmitFormOnChange.mjs +1 -1
  23. package/dist/index.html +12 -0
  24. package/dist/types/errors/context/provider.d.ts +1 -1
  25. package/dist/types/errors/root/FormRootErrorsFromContext.d.ts +3 -0
  26. package/dist/types/errors/useFormErrorsIfAny.d.ts +1 -1
  27. package/dist/types/exports.d.ts +37 -0
  28. package/dist/types/form/ErrorBoundary.d.ts +15 -0
  29. package/dist/types/form/Form.d.ts +2 -2
  30. package/dist/types/form/FormWithProviders.d.ts +13 -0
  31. package/dist/types/form/useFormWithProviders.d.ts +31 -0
  32. package/dist/types/main.d.ts +1 -36
  33. package/dist/types/src/devtool/LazyDevTool.d.ts +9 -0
  34. package/dist/types/src/env-conditions/development.d.ts +7 -0
  35. package/dist/types/src/env-conditions/production.d.ts +1 -0
  36. package/dist/types/src/errors/consoleErrors.d.ts +13 -0
  37. package/dist/types/src/errors/context/index.d.ts +10 -0
  38. package/dist/types/src/errors/context/provider.d.ts +11 -0
  39. package/dist/types/{errors → src/errors/flat}/getFlatFieldErrors.d.ts +2 -2
  40. package/dist/types/src/errors/flat/types.d.ts +13 -0
  41. package/dist/types/src/errors/flat/useFormFlatFieldErrorsMemo.d.ts +5 -0
  42. package/dist/types/src/errors/flat/useRefdFieldErrorsMemo.d.ts +9 -0
  43. package/dist/types/src/errors/isFieldError.d.ts +7 -0
  44. package/dist/types/src/errors/message/FormErrorMessage.d.ts +8 -0
  45. package/dist/types/src/errors/message/FormErrorMessageByPath.d.ts +9 -0
  46. package/dist/types/src/errors/nonfield/FormNonFieldErrorMarker.d.ts +10 -0
  47. package/dist/types/src/errors/nonfield/FormNonFieldErrorMarker.spec.d.ts +1 -0
  48. package/dist/types/src/errors/nonfield/FormNonFieldErrorMarker.utils.d.ts +2 -0
  49. package/dist/types/src/errors/nonfield/FormNonFieldErrorMarkerHtmlAttribute.d.ts +5 -0
  50. package/dist/types/src/errors/nonfield/isNonFieldError.d.ts +19 -0
  51. package/dist/types/src/errors/orphan/getOrphansFromFieldErrors.d.ts +5 -0
  52. package/dist/types/src/errors/orphan/getOrphansFromFlatFieldErrors.d.ts +4 -0
  53. package/dist/types/src/errors/orphan/useFormHasOrphanAndNoFieldErrors.d.ts +9 -0
  54. package/dist/types/src/errors/orphan/useOrphanFormErrorsMemo.d.ts +4 -0
  55. package/dist/types/src/errors/orphan/useOrphanFormErrorsToConsole.d.ts +9 -0
  56. package/dist/types/src/errors/outputErrors.d.ts +13 -0
  57. package/dist/types/src/errors/root/FormRootErrors.d.ts +7 -0
  58. package/dist/types/src/errors/root/FormRootErrorsFromContext.d.ts +3 -0
  59. package/dist/types/src/errors/root/consts.d.ts +1 -0
  60. package/dist/types/src/errors/root/getRootsFromFieldErrors.d.ts +5 -0
  61. package/dist/types/src/errors/root/getRootsFromFlatFieldErrors.d.ts +4 -0
  62. package/dist/types/src/errors/root/isFormErrorPathRoot.d.ts +6 -0
  63. package/dist/types/src/errors/root/useRootFormFieldErrorsMemo.d.ts +6 -0
  64. package/dist/types/src/errors/useFormErrorConsoleDebug.d.ts +8 -0
  65. package/dist/types/src/errors/useFormErrorsEffect.d.ts +4 -0
  66. package/dist/types/src/errors/useFormErrorsIfAny.d.ts +6 -0
  67. package/dist/types/src/errors/useFormErrorsMemo.d.ts +7 -0
  68. package/dist/types/src/errors/useFormErrorsToConsole.d.ts +13 -0
  69. package/dist/types/src/errors/useFormRequestSubmit.d.ts +6 -0
  70. package/dist/types/src/exports.d.ts +37 -0
  71. package/dist/types/src/form/ErrorBoundary.d.ts +15 -0
  72. package/dist/types/src/form/Form.d.ts +29 -0
  73. package/dist/types/src/form/FormBase.d.ts +9 -0
  74. package/dist/types/src/form/FormWithProviders.d.ts +13 -0
  75. package/dist/types/src/form/context/FormProvider.d.ts +15 -0
  76. package/dist/types/src/form/context/group/FormGroupContextProvider.d.ts +5 -0
  77. package/dist/types/src/form/context/group/index.d.ts +15 -0
  78. package/dist/types/src/form/context/group/useFormGroupChildIsMountedTracker.d.ts +2 -0
  79. package/dist/types/src/form/context/group/useFormGroupChildIsSubmittingTracker.d.ts +2 -0
  80. package/dist/types/src/form/context/group/useFormGroupIsAnyBusy.d.ts +2 -0
  81. package/dist/types/src/form/context/group/useFormGroupIsChildBusy.d.ts +2 -0
  82. package/dist/types/src/form/context/group/useFormGroupIsParentBusy.d.ts +2 -0
  83. package/dist/types/src/form/context/group/useFormGroupParentTracker.d.ts +7 -0
  84. package/dist/types/src/form/context/utils/FormUtilsContextProvider.d.ts +14 -0
  85. package/dist/types/src/form/context/utils/useFormUtilsContext.d.ts +9 -0
  86. package/dist/types/src/form/search/FormSearch.d.ts +32 -0
  87. package/dist/types/src/form/search/FormSearchHiddenInputs.d.ts +13 -0
  88. package/dist/types/src/form/search/getNewSearchParams.d.ts +2 -0
  89. package/dist/types/src/form/useForm.d.ts +29 -0
  90. package/dist/types/src/form/useFormIsBusy.d.ts +2 -0
  91. package/dist/types/src/form/useFormOrParentIsBusy.d.ts +2 -0
  92. package/dist/types/{form/useFormWithProvider.d.ts → src/form/useFormWithProviders.d.ts} +4 -4
  93. package/dist/types/src/form/utils/getSubmitterButtonData.d.ts +11 -0
  94. package/dist/types/src/isEmptyObject.d.ts +2 -0
  95. package/dist/types/src/main.d.ts +1 -0
  96. package/dist/types/{form/FormError.d.ts → src/submit/error/FormSubmitError.d.ts} +1 -1
  97. package/dist/types/src/submit/error/handleFormSubmitError.d.ts +7 -0
  98. package/dist/types/src/submit/useFormOnSubmitSuccessful.d.ts +2 -0
  99. package/dist/types/src/submit/useFormOnSubmitSuccessfulAndReset.d.ts +13 -0
  100. package/dist/types/src/submit/useResetFormOnSubmitError.d.ts +7 -0
  101. package/dist/types/src/submit/useResetFormOnSubmitSuccessful.d.ts +12 -0
  102. package/dist/types/src/submit/useSubmitFormOnChange.d.ts +4 -0
  103. package/dist/types/{utils/createRequiredContext.d.ts → src/utils/createContext.d.ts} +2 -2
  104. package/dist/types/src/utils/fixedForwardRef.d.ts +7 -0
  105. package/dist/types/src/utils/useImperativeForwardedRef.d.ts +11 -0
  106. package/dist/types/src/utils/useThrowAsyncError.d.ts +5 -0
  107. package/dist/types/src/utils/useToggle.d.ts +4 -0
  108. package/dist/types/submit/error/FormSubmitError.d.ts +6 -0
  109. package/dist/types/submit/error/handleFormSubmitError.d.ts +7 -0
  110. package/dist/types/submit/useResetFormOnSubmitError.d.ts +7 -0
  111. package/dist/types/submit/useSubmitFormOnChange.d.ts +1 -1
  112. package/dist/types/utils/useThrowAsyncError.d.ts +5 -0
  113. package/package.json +30 -17
  114. package/dist/esm/form/FormWithProvider.mjs +0 -9
  115. package/dist/esm/form/useFormWithProvider.mjs +0 -30
  116. package/dist/types/errors/flat/getFlatFieldErrorsByFilter.d.ts +0 -9
  117. package/dist/types/errors/orphan/getOrphanFlatFieldErrors.d.ts +0 -5
  118. package/dist/types/errors/orphan/useOrphanFormErrors.d.ts +0 -4
  119. package/dist/types/errors/orphan/useOrphanFormErrorsToConsoleError.d.ts +0 -9
  120. package/dist/types/errors/root/getRootFlatFieldErrors.d.ts +0 -8
  121. package/dist/types/errors/root/useRootFormFieldErrors.d.ts +0 -6
  122. package/dist/types/errors/root/utils.d.ts +0 -12
  123. package/dist/types/errors/useFormErrorsOnChange.d.ts +0 -7
  124. package/dist/types/errors/useFormFieldErrors.d.ts +0 -6
  125. package/dist/types/errors/useFormFlatFieldErrors.d.ts +0 -5
  126. package/dist/types/form/FormWithProvider.d.ts +0 -13
  127. package/dist/types/form/context/group/useAsFormGroupParent.d.ts +0 -7
  128. package/dist/types/form/context/parent/FormParentContextProvider.d.ts +0 -5
  129. package/dist/types/form/context/parent/index.d.ts +0 -6
  130. package/dist/types/form/context/parent/useAsFormParentState.d.ts +0 -7
  131. package/dist/types/form/context/parent/useFormParentIsBusy.d.ts +0 -7
  132. package/dist/types/form/toggle/ToggleForm.d.ts +0 -18
  133. /package/dist/types/{errors → src/errors/flat}/flattenFieldErrors.d.ts +0 -0
@@ -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,29 @@
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
+ /** {@link RhfUseFormProps} props for RHF's {@link useRhfForm}. */
7
+ rhf?: RhfUseFormProps<TFieldValues>;
8
+ /** {@link FormProps} props for Form. */
9
+ form?: Omit<FormProps<TFieldValues, TTransformedValues>, 'formId' | 'formRef'>;
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
+ declare const useForm: <TFieldValues extends FieldValues, TTransformedValues extends FieldValues>({ rhf, form, }: UseFormProps<TFieldValues, TTransformedValues>) => {
22
+ readonly id: string;
23
+ readonly ref: React.RefObject<HTMLFormElement>;
24
+ readonly context: import('react-hook-form').UseFormReturn<TFieldValues, unknown, TTransformedValues>;
25
+ readonly Form: React.FC<{
26
+ children?: React.ReactNode;
27
+ }>;
28
+ };
29
+ export default useForm;
@@ -0,0 +1,2 @@
1
+ declare const useFormIsBusy: () => boolean;
2
+ export default useFormIsBusy;
@@ -0,0 +1,2 @@
1
+ declare const useFormOrParentIsBusy: () => boolean;
2
+ export default useFormOrParentIsBusy;
@@ -3,11 +3,11 @@ import { FormUtilsContextProviderProps } from './context/utils/FormUtilsContextP
3
3
  import { FieldValues } from 'react-hook-form';
4
4
  import { default as React } from 'react';
5
5
 
6
- export type UseFormWithProviderProps<TFieldValues extends FieldValues, TTransformedValues extends FieldValues> = UseFormProps<TFieldValues, TTransformedValues> & {
6
+ export type UseFormWithProvidersProps<TFieldValues extends FieldValues, TTransformedValues extends FieldValues> = UseFormProps<TFieldValues, TTransformedValues> & {
7
7
  /** {@link FormUtilsContextProviderProps} props for `FormUtilsContextProvider`. */
8
8
  utils?: FormUtilsContextProviderProps;
9
9
  };
10
- export type UseFormWithProviderReturn = ReturnType<typeof useFormWithProvider>;
10
+ export type UseFormWithProvidersReturn = ReturnType<typeof useFormWithProviders>;
11
11
  /**
12
12
  * Base Rhf Form hook. Use `Form` in `index.ts` for most cases.
13
13
  * Use this if you need to separate form components.
@@ -17,7 +17,7 @@ export type UseFormWithProviderReturn = ReturnType<typeof useFormWithProvider>;
17
17
  * see https://caniuse.com/?search=form%20attribute
18
18
  * @returns Form provider and form.
19
19
  */
20
- declare const useFormWithProvider: <TFieldValues extends FieldValues, TTransformedValues extends FieldValues>({ isDev, rhf, form, utils, }: UseFormWithProviderProps<TFieldValues, TTransformedValues>) => {
20
+ declare const useFormWithProviders: <TFieldValues extends FieldValues, TTransformedValues extends FieldValues>({ rhf, form, utils, }: UseFormWithProvidersProps<TFieldValues, TTransformedValues>) => {
21
21
  readonly Provider: React.FC<{
22
22
  children?: React.ReactNode;
23
23
  }>;
@@ -28,4 +28,4 @@ declare const useFormWithProvider: <TFieldValues extends FieldValues, TTransform
28
28
  children?: React.ReactNode;
29
29
  }>;
30
30
  };
31
- export default useFormWithProvider;
31
+ export default useFormWithProviders;
@@ -0,0 +1,11 @@
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;
@@ -0,0 +1,2 @@
1
+ declare const isEmptyObject: (obj: Record<string, unknown>) => boolean;
2
+ export default isEmptyObject;
@@ -0,0 +1 @@
1
+ export {};
@@ -1,6 +1,6 @@
1
1
  import { FieldPath, FieldValues } from 'react-hook-form';
2
2
 
3
- export declare class FormError<TFieldValues extends FieldValues> extends Error {
3
+ export declare class FormSubmitError<TFieldValues extends FieldValues = FieldValues> extends Error {
4
4
  errors: Partial<Record<FieldPath<TFieldValues> | `root.${string}`, string>>;
5
5
  constructor(errors: Partial<Record<FieldPath<TFieldValues> | `root.${string}`, string>>, message?: string);
6
6
  }
@@ -0,0 +1,7 @@
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;
@@ -0,0 +1,2 @@
1
+ declare const useFormOnSubmitSuccessful: (callback?: () => void) => void;
2
+ export default useFormOnSubmitSuccessful;
@@ -0,0 +1,13 @@
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;
@@ -0,0 +1,7 @@
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;
@@ -0,0 +1,12 @@
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;
@@ -0,0 +1,4 @@
1
+ import { default as React } from 'react';
2
+
3
+ declare const useSubmitFormOnChange: (formRef: React.RefObject<HTMLFormElement>, disabled?: boolean) => void;
4
+ export default useSubmitFormOnChange;
@@ -4,5 +4,5 @@ import { default as React } from 'react';
4
4
  * Create a strongly-typed context that throws error if no provider is found.
5
5
  * @returns A tuple with a function to get the context and the context provider.
6
6
  */
7
- declare function createRequiredContext<T = unknown>(): readonly [() => T & ({} | null), React.Provider<T | undefined>];
8
- export default createRequiredContext;
7
+ declare function createContext<T = unknown>(): readonly [() => T | undefined, () => T & ({} | null), React.Provider<T | undefined>];
8
+ 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,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,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;
@@ -0,0 +1,6 @@
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
+ }
@@ -0,0 +1,7 @@
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;
@@ -0,0 +1,7 @@
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,4 +1,4 @@
1
1
  import { default as React } from 'react';
2
2
 
3
- declare const useSubmitFormOnChange: (formRef: React.RefObject<HTMLFormElement>, enabled: boolean) => void;
3
+ declare const useSubmitFormOnChange: (formRef: React.RefObject<HTMLFormElement>, disabled?: boolean) => void;
4
4
  export default useSubmitFormOnChange;
@@ -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;
package/package.json CHANGED
@@ -2,18 +2,24 @@
2
2
  "name": "@paragrav/rhf-utils",
3
3
  "author": "paragrav.dev",
4
4
  "license": "MIT",
5
- "version": "0.0.48",
5
+ "version": "0.0.51",
6
6
  "description": "Integration utilities for react-hook-form.",
7
7
  "type": "module",
8
8
  "sideEffects": false,
9
9
  "files": [
10
10
  "dist"
11
11
  ],
12
- "module": "./dist/esm/main.mjs",
12
+ "module": "./dist/esm/exports.mjs",
13
+ "imports": {
14
+ "#is-development": {
15
+ "development": "./src/env-conditions/development.ts",
16
+ "default": "./src/env-conditions/production.ts"
17
+ }
18
+ },
13
19
  "exports": {
14
20
  ".": {
15
- "default": "./dist/esm/main.mjs",
16
- "types": "./dist/types/main.d.ts"
21
+ "default": "./dist/esm/exports.mjs",
22
+ "types": "./dist/types/exports.d.ts"
17
23
  },
18
24
  "./LazyDevTool": {
19
25
  "default": "./dist/esm/devtool/LazyDevTool.mjs",
@@ -75,21 +81,17 @@
75
81
  "default": "./dist/esm/form/Form.mjs",
76
82
  "types": "./dist/types/form/Form.d.ts"
77
83
  },
78
- "./form/FormError": {
79
- "default": "./dist/esm/form/FormError.mjs",
80
- "types": "./dist/types/form/FormError.d.ts"
81
- },
82
- "./form/context/FormWithProvider": {
83
- "default": "./dist/esm/form/context/FormWithProvider.mjs",
84
- "types": "./dist/types/form/context/FormWithProvider.d.ts"
84
+ "./form/context/FormWithProviders": {
85
+ "default": "./dist/esm/form/context/FormWithProviders.mjs",
86
+ "types": "./dist/types/form/context/FormWithProviders.d.ts"
85
87
  },
86
88
  "./form/useForm": {
87
89
  "default": "./dist/esm/form/useForm.mjs",
88
90
  "types": "./dist/types/form/useForm.d.ts"
89
91
  },
90
- "./form/useFormWithProvider": {
91
- "default": "./dist/esm/form/useFormWithProvider.mjs",
92
- "types": "./dist/types/form/useFormWithProvider.d.ts"
92
+ "./form/useFormWithProviders": {
93
+ "default": "./dist/esm/form/useFormWithProviders.mjs",
94
+ "types": "./dist/types/form/useFormWithProviders.d.ts"
93
95
  },
94
96
  "./form/context/FormProvider": {
95
97
  "default": "./dist/esm/form/context/FormProvider.mjs",
@@ -139,10 +141,18 @@
139
141
  "default": "./dist/esm/submit/useFormOnSubmitSuccessful.mjs",
140
142
  "types": "./dist/types/submit/useFormOnSubmitSuccessful.d.ts"
141
143
  },
144
+ "./submit/error/FormSubmitError": {
145
+ "default": "./dist/esm/submit/error/FormSubmitError.mjs",
146
+ "types": "./dist/types/submit/error/FormSubmitError.d.ts"
147
+ },
142
148
  "./submit/useFormOnSubmitSuccessfulAndReset": {
143
149
  "default": "./dist/esm/submit/useFormOnSubmitSuccessfulAndReset.mjs",
144
150
  "types": "./dist/types/submit/useFormOnSubmitSuccessfulAndReset.d.ts"
145
151
  },
152
+ "./submit/useResetFormOnSubmitError": {
153
+ "default": "./dist/esm/submit/useResetFormOnSubmitError.mjs",
154
+ "types": "./dist/types/submit/useResetFormOnSubmitError.d.ts"
155
+ },
146
156
  "./submit/useResetFormAfterSubmitSuccessful": {
147
157
  "default": "./dist/esm/submit/useResetFormAfterSubmitSuccessful.mjs",
148
158
  "types": "./dist/types/submit/useResetFormAfterSubmitSuccessful.d.ts"
@@ -153,17 +163,19 @@
153
163
  }
154
164
  },
155
165
  "scripts": {
156
- "build": "npm install && npm run validate && npm run build:esm",
157
- "build:esm": "vite build",
166
+ "build": "npm install && npm run validate && vite build",
167
+ "build:dev": "vite build --config vite.config.dev.ts",
168
+ "dev": "vite --config vite.config.dev.ts",
158
169
  "lint": "eslint --ignore-path ./.gitignore --ext ts,tsx --report-unused-disable-directives --max-warnings 0 .",
159
170
  "preinstall": "npx only-allow npm",
160
171
  "prepare": "husky",
161
172
  "prepublishOnly": "npm run build",
173
+ "preview": "vite preview --config vite.config.dev.ts",
162
174
  "test": "vitest",
163
175
  "test:ct": "playwright test -c playwright-ct.config.ts",
164
176
  "test:ct:ui": "playwright test -c playwright-ct.config.ts --ui",
165
177
  "tsc": "tsc",
166
- "validate": "npm run tsc & npm run lint & npm run test & npm run test:ct"
178
+ "validate": "cross-env CI=1 npm run tsc & npm run lint & npm run test & npm run test:ct"
167
179
  },
168
180
  "peerDependencies": {
169
181
  "@hookform/devtools": "^4",
@@ -182,6 +194,7 @@
182
194
  "@typescript-eslint/eslint-plugin": "^7.3.1",
183
195
  "@typescript-eslint/parser": "^7.3.1",
184
196
  "@vitejs/plugin-react": "^4.2.1",
197
+ "cross-env": "^7.0.3",
185
198
  "eslint": "^8.57.0",
186
199
  "eslint-config-prettier": "^9.1.0",
187
200
  "eslint-plugin-import": "^2.29.1",
@@ -1,9 +0,0 @@
1
- import { jsx as o } from "react/jsx-runtime";
2
- import e from "./useFormWithProvider.mjs";
3
- function f({ children: i, ...t }) {
4
- const r = e(t);
5
- return /* @__PURE__ */ o(r.Provider, { children: /* @__PURE__ */ o(r.Form, { children: i }) });
6
- }
7
- export {
8
- f as default
9
- };
@@ -1,30 +0,0 @@
1
- import { jsx as f } from "react/jsx-runtime";
2
- import "react";
3
- import d from "./context/FormProvider.mjs";
4
- import s from "./useForm.mjs";
5
- const n = ({
6
- isDev: o,
7
- rhf: e,
8
- form: t,
9
- utils: m
10
- }) => {
11
- const r = s({ isDev: o, rhf: e, form: t });
12
- return {
13
- ...r,
14
- Provider: ({ children: i }) => /* @__PURE__ */ f(
15
- d,
16
- {
17
- isDev: o,
18
- formRef: r.ref,
19
- rhf: r.context,
20
- formId: r.id,
21
- form: t,
22
- utils: m,
23
- children: i
24
- }
25
- )
26
- };
27
- }, F = n;
28
- export {
29
- F as default
30
- };
@@ -1,9 +0,0 @@
1
- import { FieldError, FieldErrors } from 'react-hook-form';
2
-
3
- /**
4
- * Get flat field errors filtered by supplied predicate.
5
- */
6
- declare const getFlatFieldErrorsByFilter: (errors: FieldErrors, predicate: (entry: [string, FieldError]) => boolean) => {
7
- [k: string]: FieldError;
8
- };
9
- export default getFlatFieldErrorsByFilter;
@@ -1,5 +0,0 @@
1
- import { FlatFieldErrors } from '../flat/types';
2
- import { FieldErrors } from 'react-hook-form';
3
-
4
- declare const getOrphanFlatFieldErrors: (errors: FieldErrors, parentElement: Pick<HTMLElement, 'querySelector'>) => FlatFieldErrors;
5
- export default getOrphanFlatFieldErrors;
@@ -1,4 +0,0 @@
1
- import { default as React } from 'react';
2
-
3
- declare const useOrphanFormErrors: (formRef: React.RefObject<HTMLFormElement>) => import('../getFlatFieldErrors').FlatFieldErrors;
4
- export default useOrphanFormErrors;
@@ -1,9 +0,0 @@
1
- import { default as React } from 'react';
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 useOrphanFormErrorsToConsoleError: (formRef: React.RefObject<HTMLFormElement>, isDev?: boolean) => void;
9
- export default useOrphanFormErrorsToConsoleError;
@@ -1,8 +0,0 @@
1
- import { FlatFieldErrors } from '../flat/types';
2
- import { FieldErrors } from 'react-hook-form';
3
-
4
- /**
5
- * Generate {@link FlatFieldErrors} object from {@link FieldErrors}.
6
- */
7
- declare const getRootFlatFieldErrors: (errors: FieldErrors) => FlatFieldErrors;
8
- export default getRootFlatFieldErrors;
@@ -1,6 +0,0 @@
1
- /**
2
- * Root field errors from form.
3
- * These are typically displayed at the bottom of the form.
4
- */
5
- declare const useRootFormFieldErrors: () => import('../getFlatFieldErrors').FlatFieldErrors;
6
- export default useRootFormFieldErrors;
@@ -1,12 +0,0 @@
1
- import { FlatFieldErrors } from '../getFlatFieldErrors';
2
- import { FieldErrors } from 'react-hook-form';
3
-
4
- /**
5
- * Determine if an error path is root. (e.g., `root` or `root.nested`)
6
- * @param path Flat path. (e.g., 'root.nested')
7
- */
8
- export declare const isFormErrorPathRoot: (path: string) => boolean;
9
- /**
10
- *
11
- */
12
- export declare const getRootFlatFieldErrors: (errors: FieldErrors) => FlatFieldErrors;
@@ -1,7 +0,0 @@
1
- import { FieldErrors } from 'react-hook-form';
2
-
3
- /**
4
- * Provide a callback to call when RHF errors change.
5
- */
6
- declare const useFormErrorsOnChange: <TReturn>(callback: (errors: FieldErrors) => TReturn) => TReturn;
7
- export default useFormErrorsOnChange;
@@ -1,6 +0,0 @@
1
- import { FlatFieldErrors } from './getFlatFieldErrors';
2
- import { FieldErrors } from 'react-hook-form';
3
-
4
- declare const useFormFieldErrors: () => FlatFieldErrors;
5
- export default useFormFieldErrors;
6
- export declare const getFlatFieldFormErrors: (errors: FieldErrors) => FlatFieldErrors;
@@ -1,5 +0,0 @@
1
- /**
2
- * Use {@link FieldErrors} as {@link FlatFieldErrors}.
3
- */
4
- declare const useFormFlatFieldErrors: () => import('./getFlatFieldErrors').FlatFieldErrors;
5
- export default useFormFlatFieldErrors;
@@ -1,13 +0,0 @@
1
- import { UseFormProps } from './useForm';
2
- import { FieldValues } from 'react-hook-form';
3
-
4
- export type FormWithProvider<TFieldValues extends FieldValues, TTransformedValues extends FieldValues> = React.PropsWithChildren<UseFormProps<TFieldValues, TTransformedValues>>;
5
- /**
6
- * {@link FormProvider} (and utils) with immediate descendent {@link Form}.
7
- * (Syntactic sugar for {@link useForm}. Use this for most applications.)
8
- *
9
- * Use {@link useForm} 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 FormWithProvider<TFieldValues extends FieldValues, TTransformedValues extends FieldValues>({ children, ...props }: FormWithProvider<TFieldValues, TTransformedValues>): import("react/jsx-runtime").JSX.Element;
13
- export default FormWithProvider;
@@ -1,7 +0,0 @@
1
- /**
2
- * Connect specific form state as parent context.
3
- *
4
- * Requires usage of provider.
5
- */
6
- declare const useAsFormGroupParent: () => void;
7
- export default useAsFormGroupParent;
@@ -1,5 +0,0 @@
1
- import { default as React } from 'react';
2
-
3
- type Props = React.PropsWithChildren;
4
- declare const FormParentContextProvider: React.FC<Props>;
5
- export default FormParentContextProvider;
@@ -1,6 +0,0 @@
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>;
@@ -1,7 +0,0 @@
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;
@@ -1,7 +0,0 @@
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;
@@ -1,18 +0,0 @@
1
- import { UseFormWithProviderProps } from '../useFormWithProvider';
2
- import { FieldValues, UseFormReturn } from 'react-hook-form';
3
- import { default as React } from 'react';
4
-
5
- type Props<TFieldValues extends FieldValues, TTransformedValues extends FieldValues> = React.PropsWithChildren<UseFormWithProviderProps<TFieldValues, TTransformedValues> & {
6
- Fields: React.FC<{
7
- ctx: UseFormReturn<TFieldValues, unknown, TTransformedValues>;
8
- }>;
9
- }>;
10
- /**
11
- * This form submits upon selecting a new value, and reverts (via re-render) if there is an error.
12
- *
13
- * The entire form is disabled while submitting.
14
- *
15
- * Probably not ideal to use with text inputs. Would need to implement debounce or submit on blur.
16
- */
17
- declare function ToggleForm<TFieldValues extends FieldValues, TTransformedValues extends FieldValues>({ isDev, rhf, form, utils, Fields, children, }: Props<TFieldValues, TTransformedValues>): import("react/jsx-runtime").JSX.Element;
18
- export default ToggleForm;