@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.
- package/dist/assets/index-BgBykTYQ.js +40 -0
- package/dist/esm/devtool/LazyDevTool.mjs +7 -11
- package/dist/esm/env-conditions/production.mjs +4 -0
- package/dist/esm/errors/context/provider.mjs +11 -9
- package/dist/esm/errors/orphan/useOrphanFormErrorsToConsole.mjs +8 -9
- package/dist/esm/errors/outputErrors.mjs +5 -6
- package/dist/esm/errors/root/FormRootErrors.mjs +7 -7
- package/dist/esm/errors/root/FormRootErrorsFromContext.mjs +11 -0
- package/dist/esm/errors/useFormErrorsEffect.mjs +6 -6
- package/dist/esm/errors/useFormErrorsToConsole.mjs +17 -13
- package/dist/esm/{main.mjs → exports.mjs} +44 -42
- package/dist/esm/form/Form.mjs +41 -65
- package/dist/esm/form/FormWithProviders.mjs +10 -0
- package/dist/esm/form/context/FormProvider.mjs +17 -19
- package/dist/esm/form/context/group/useFormGroupChildIsMountedTracker.mjs +3 -1
- package/dist/esm/form/context/utils/FormUtilsContextProvider.mjs +10 -10
- package/dist/esm/form/useForm.mjs +15 -17
- package/dist/esm/form/useFormWithProviders.mjs +28 -0
- package/dist/esm/{form/FormError.mjs → submit/error/FormSubmitError.mjs} +2 -2
- package/dist/esm/submit/error/handleFormSubmitError.mjs +12 -0
- package/dist/esm/submit/useResetFormOnSubmitError.mjs +18 -0
- package/dist/esm/submit/useSubmitFormOnChange.mjs +1 -1
- package/dist/index.html +12 -0
- package/dist/types/errors/context/provider.d.ts +1 -1
- package/dist/types/errors/root/FormRootErrorsFromContext.d.ts +3 -0
- package/dist/types/errors/useFormErrorsIfAny.d.ts +1 -1
- package/dist/types/exports.d.ts +37 -0
- package/dist/types/form/ErrorBoundary.d.ts +15 -0
- package/dist/types/form/Form.d.ts +2 -2
- package/dist/types/form/FormWithProviders.d.ts +13 -0
- package/dist/types/form/useFormWithProviders.d.ts +31 -0
- package/dist/types/main.d.ts +1 -36
- package/dist/types/src/devtool/LazyDevTool.d.ts +9 -0
- package/dist/types/src/env-conditions/development.d.ts +7 -0
- package/dist/types/src/env-conditions/production.d.ts +1 -0
- package/dist/types/src/errors/consoleErrors.d.ts +13 -0
- package/dist/types/src/errors/context/index.d.ts +10 -0
- package/dist/types/src/errors/context/provider.d.ts +11 -0
- package/dist/types/{errors → src/errors/flat}/getFlatFieldErrors.d.ts +2 -2
- package/dist/types/src/errors/flat/types.d.ts +13 -0
- package/dist/types/src/errors/flat/useFormFlatFieldErrorsMemo.d.ts +5 -0
- package/dist/types/src/errors/flat/useRefdFieldErrorsMemo.d.ts +9 -0
- package/dist/types/src/errors/isFieldError.d.ts +7 -0
- package/dist/types/src/errors/message/FormErrorMessage.d.ts +8 -0
- package/dist/types/src/errors/message/FormErrorMessageByPath.d.ts +9 -0
- package/dist/types/src/errors/nonfield/FormNonFieldErrorMarker.d.ts +10 -0
- package/dist/types/src/errors/nonfield/FormNonFieldErrorMarker.spec.d.ts +1 -0
- package/dist/types/src/errors/nonfield/FormNonFieldErrorMarker.utils.d.ts +2 -0
- package/dist/types/src/errors/nonfield/FormNonFieldErrorMarkerHtmlAttribute.d.ts +5 -0
- package/dist/types/src/errors/nonfield/isNonFieldError.d.ts +19 -0
- package/dist/types/src/errors/orphan/getOrphansFromFieldErrors.d.ts +5 -0
- package/dist/types/src/errors/orphan/getOrphansFromFlatFieldErrors.d.ts +4 -0
- package/dist/types/src/errors/orphan/useFormHasOrphanAndNoFieldErrors.d.ts +9 -0
- package/dist/types/src/errors/orphan/useOrphanFormErrorsMemo.d.ts +4 -0
- package/dist/types/src/errors/orphan/useOrphanFormErrorsToConsole.d.ts +9 -0
- package/dist/types/src/errors/outputErrors.d.ts +13 -0
- package/dist/types/src/errors/root/FormRootErrors.d.ts +7 -0
- package/dist/types/src/errors/root/FormRootErrorsFromContext.d.ts +3 -0
- package/dist/types/src/errors/root/consts.d.ts +1 -0
- package/dist/types/src/errors/root/getRootsFromFieldErrors.d.ts +5 -0
- package/dist/types/src/errors/root/getRootsFromFlatFieldErrors.d.ts +4 -0
- package/dist/types/src/errors/root/isFormErrorPathRoot.d.ts +6 -0
- package/dist/types/src/errors/root/useRootFormFieldErrorsMemo.d.ts +6 -0
- package/dist/types/src/errors/useFormErrorConsoleDebug.d.ts +8 -0
- package/dist/types/src/errors/useFormErrorsEffect.d.ts +4 -0
- package/dist/types/src/errors/useFormErrorsIfAny.d.ts +6 -0
- package/dist/types/src/errors/useFormErrorsMemo.d.ts +7 -0
- package/dist/types/src/errors/useFormErrorsToConsole.d.ts +13 -0
- package/dist/types/src/errors/useFormRequestSubmit.d.ts +6 -0
- package/dist/types/src/exports.d.ts +37 -0
- package/dist/types/src/form/ErrorBoundary.d.ts +15 -0
- package/dist/types/src/form/Form.d.ts +29 -0
- package/dist/types/src/form/FormBase.d.ts +9 -0
- package/dist/types/src/form/FormWithProviders.d.ts +13 -0
- package/dist/types/src/form/context/FormProvider.d.ts +15 -0
- package/dist/types/src/form/context/group/FormGroupContextProvider.d.ts +5 -0
- package/dist/types/src/form/context/group/index.d.ts +15 -0
- package/dist/types/src/form/context/group/useFormGroupChildIsMountedTracker.d.ts +2 -0
- package/dist/types/src/form/context/group/useFormGroupChildIsSubmittingTracker.d.ts +2 -0
- package/dist/types/src/form/context/group/useFormGroupIsAnyBusy.d.ts +2 -0
- package/dist/types/src/form/context/group/useFormGroupIsChildBusy.d.ts +2 -0
- package/dist/types/src/form/context/group/useFormGroupIsParentBusy.d.ts +2 -0
- package/dist/types/src/form/context/group/useFormGroupParentTracker.d.ts +7 -0
- package/dist/types/src/form/context/utils/FormUtilsContextProvider.d.ts +14 -0
- package/dist/types/src/form/context/utils/useFormUtilsContext.d.ts +9 -0
- package/dist/types/src/form/search/FormSearch.d.ts +32 -0
- package/dist/types/src/form/search/FormSearchHiddenInputs.d.ts +13 -0
- package/dist/types/src/form/search/getNewSearchParams.d.ts +2 -0
- package/dist/types/src/form/useForm.d.ts +29 -0
- package/dist/types/src/form/useFormIsBusy.d.ts +2 -0
- package/dist/types/src/form/useFormOrParentIsBusy.d.ts +2 -0
- package/dist/types/{form/useFormWithProvider.d.ts → src/form/useFormWithProviders.d.ts} +4 -4
- package/dist/types/src/form/utils/getSubmitterButtonData.d.ts +11 -0
- package/dist/types/src/isEmptyObject.d.ts +2 -0
- package/dist/types/src/main.d.ts +1 -0
- package/dist/types/{form/FormError.d.ts → src/submit/error/FormSubmitError.d.ts} +1 -1
- package/dist/types/src/submit/error/handleFormSubmitError.d.ts +7 -0
- package/dist/types/src/submit/useFormOnSubmitSuccessful.d.ts +2 -0
- package/dist/types/src/submit/useFormOnSubmitSuccessfulAndReset.d.ts +13 -0
- package/dist/types/src/submit/useResetFormOnSubmitError.d.ts +7 -0
- package/dist/types/src/submit/useResetFormOnSubmitSuccessful.d.ts +12 -0
- package/dist/types/src/submit/useSubmitFormOnChange.d.ts +4 -0
- package/dist/types/{utils/createRequiredContext.d.ts → src/utils/createContext.d.ts} +2 -2
- package/dist/types/src/utils/fixedForwardRef.d.ts +7 -0
- package/dist/types/src/utils/useImperativeForwardedRef.d.ts +11 -0
- package/dist/types/src/utils/useThrowAsyncError.d.ts +5 -0
- package/dist/types/src/utils/useToggle.d.ts +4 -0
- package/dist/types/submit/error/FormSubmitError.d.ts +6 -0
- package/dist/types/submit/error/handleFormSubmitError.d.ts +7 -0
- package/dist/types/submit/useResetFormOnSubmitError.d.ts +7 -0
- package/dist/types/submit/useSubmitFormOnChange.d.ts +1 -1
- package/dist/types/utils/useThrowAsyncError.d.ts +5 -0
- package/package.json +30 -17
- package/dist/esm/form/FormWithProvider.mjs +0 -9
- package/dist/esm/form/useFormWithProvider.mjs +0 -30
- package/dist/types/errors/flat/getFlatFieldErrorsByFilter.d.ts +0 -9
- package/dist/types/errors/orphan/getOrphanFlatFieldErrors.d.ts +0 -5
- package/dist/types/errors/orphan/useOrphanFormErrors.d.ts +0 -4
- package/dist/types/errors/orphan/useOrphanFormErrorsToConsoleError.d.ts +0 -9
- package/dist/types/errors/root/getRootFlatFieldErrors.d.ts +0 -8
- package/dist/types/errors/root/useRootFormFieldErrors.d.ts +0 -6
- package/dist/types/errors/root/utils.d.ts +0 -12
- package/dist/types/errors/useFormErrorsOnChange.d.ts +0 -7
- package/dist/types/errors/useFormFieldErrors.d.ts +0 -6
- package/dist/types/errors/useFormFlatFieldErrors.d.ts +0 -5
- package/dist/types/form/FormWithProvider.d.ts +0 -13
- package/dist/types/form/context/group/useAsFormGroupParent.d.ts +0 -7
- package/dist/types/form/context/parent/FormParentContextProvider.d.ts +0 -5
- package/dist/types/form/context/parent/index.d.ts +0 -6
- package/dist/types/form/context/parent/useAsFormParentState.d.ts +0 -7
- package/dist/types/form/context/parent/useFormParentIsBusy.d.ts +0 -7
- package/dist/types/form/toggle/ToggleForm.d.ts +0 -18
- /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,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;
|
|
@@ -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
|
|
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
|
|
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
|
|
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
|
|
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 @@
|
|
|
1
|
+
export {};
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { FieldPath, FieldValues } from 'react-hook-form';
|
|
2
2
|
|
|
3
|
-
export declare class
|
|
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,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;
|
|
@@ -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
|
|
8
|
-
export default
|
|
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,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>,
|
|
3
|
+
declare const useSubmitFormOnChange: (formRef: React.RefObject<HTMLFormElement>, disabled?: boolean) => void;
|
|
4
4
|
export default useSubmitFormOnChange;
|
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.
|
|
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/
|
|
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/
|
|
16
|
-
"types": "./dist/types/
|
|
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/
|
|
79
|
-
"default": "./dist/esm/form/
|
|
80
|
-
"types": "./dist/types/form/
|
|
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/
|
|
91
|
-
"default": "./dist/esm/form/
|
|
92
|
-
"types": "./dist/types/form/
|
|
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 &&
|
|
157
|
-
"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,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,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,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,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,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,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;
|
|
File without changes
|