@paragrav/rhf-utils 0.1.0 → 0.60.0
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/README.md +260 -121
- package/dist/dts/Register.d.ts +16 -0
- package/dist/dts/_exports/config.d.ts +2 -0
- package/dist/dts/_exports/errors.d.ts +3 -0
- package/dist/dts/_exports/form.d.ts +7 -0
- package/dist/dts/_exports/index.d.ts +14 -0
- package/dist/dts/_exports/relay.d.ts +8 -0
- package/dist/dts/_exports/submit.d.ts +4 -0
- package/dist/dts/_exports/trpc.d.ts +2 -0
- package/dist/dts/_exports/types.d.ts +6 -0
- package/dist/dts/_exports/zod.d.ts +6 -0
- package/dist/dts/client/config/RhfUtilsClientConfigType.d.ts +63 -0
- package/dist/dts/client/config/context/RhfUtilsClientConfigContext.d.ts +3 -0
- package/dist/dts/client/config/context/RhfUtilsClientConfigProvider.d.ts +7 -0
- package/dist/dts/client/config/context/useRhfUtilsClientConfig.d.ts +1 -0
- package/dist/{types → dts}/devtool/LazyDevTool.d.ts +3 -4
- package/dist/dts/devtool/LazyDevToolViaProviders.d.ts +1 -0
- package/dist/{types → dts}/errors/flat/FlatFieldErrorsList.d.ts +2 -2
- package/dist/{types → dts}/errors/flat/context/FlatFieldErrorsContextProvider.d.ts +3 -3
- package/dist/{types → dts}/errors/flat/context/useFlatFieldErrorsContext.d.ts +1 -2
- package/dist/dts/errors/flat/context/useFlatFieldErrorsContextHasOnlyOrphans.d.ts +6 -0
- package/dist/{types → dts}/errors/flat/context/useFlatFieldErrorsContextOutput.d.ts +1 -2
- package/dist/dts/errors/flat/filterFlatFieldErrors.d.ts +7 -0
- package/dist/{types → dts}/errors/flat/flattenFieldErrors.d.ts +1 -2
- package/dist/{types → dts}/errors/flat/getFlatFieldErrors.d.ts +2 -1
- package/dist/dts/errors/getRefdFromFlatFieldErrors.d.ts +1 -0
- package/dist/{types → dts}/errors/isFieldErrorRefd.d.ts +1 -2
- package/dist/dts/errors/isFlatFieldErrorEntryRefd.d.ts +5 -0
- package/dist/{types → dts}/errors/message/FormErrorMessage.d.ts +2 -2
- package/dist/{types → dts}/errors/message/RhfUtilsFieldErrorMessage.d.ts +2 -2
- package/dist/{types → dts}/errors/nonfield/RhfUtilsNonFieldErrorMarker.d.ts +2 -2
- package/dist/dts/errors/nonfield/RhfUtilsNonFieldErrorMarkerHtmlAttribute.d.ts +4 -0
- package/dist/{types → dts}/errors/nonfield/isNonFieldError.d.ts +1 -2
- package/dist/dts/errors/nonfield/isNonFieldErrorMarkerInDOM.d.ts +5 -0
- package/dist/dts/errors/orphan/getIsOrphanFormErrorWithParentElement.d.ts +5 -0
- package/dist/dts/errors/orphan/getOrphansFromFlatFieldErrors.d.ts +2 -0
- package/dist/dts/errors/orphan/isOrphanFormError.d.ts +2 -0
- package/dist/dts/errors/output/consoleErrors.d.ts +5 -0
- package/dist/dts/errors/root/RootErrorsListFromFlatFieldErrorsContext.d.ts +1 -0
- package/dist/dts/errors/root/getRootsFromFlatFieldErrors.d.ts +1 -0
- package/dist/{types → dts}/errors/root/isFlatFieldErrorEntryPathRoot.d.ts +1 -2
- package/dist/{types → dts}/errors/root/isFormErrorPathRoot.d.ts +1 -2
- package/dist/{types → dts}/errors/trpc/makeOnSubmitTrpcClientErrorHandler.d.ts +2 -3
- package/dist/dts/errors/trpc/trpcClientErrorMessageSchema.d.ts +19 -0
- package/dist/dts/errors/trpc/trpcClientErrorToFormSubmitFieldErrorsSchemaTransformer.d.ts +23 -0
- package/dist/dts/form/RHF_UseFormReturnWithoutProxiesType.d.ts +15 -0
- package/dist/dts/form/RhfUtilsFormComponentPropsType.d.ts +17 -0
- package/dist/dts/form/RhfUtilsFormStateWithUtilsType.d.ts +7 -0
- package/dist/dts/form/UseRhfUtilsFormChildrenPropsType.d.ts +25 -0
- package/dist/dts/form/_Controller.d.ts +4 -0
- package/dist/dts/form/context/utils/RhfUtilsContextPropsType.d.ts +11 -0
- package/dist/dts/form/context/utils/RhfUtilsContextProvider.d.ts +9 -0
- package/dist/dts/form/context/utils/useRhfUtilsContext.d.ts +5 -0
- package/dist/dts/form/context/utils/useRhfUtilsContextRequestSubmit.d.ts +4 -0
- package/dist/dts/form/defaults/UseRhfUtilsFormGlobalDefaults.d.ts +24 -0
- package/dist/dts/form/defaults/UseRhfUtilsFormInstanceDefaults.d.ts +18 -0
- package/dist/dts/form/defaults/UseRhfUtilsFormResolvedDefaultsType.d.ts +12 -0
- package/dist/dts/form/defaults/form/UseRhfUtilsFormInstanceFormProps.d.ts +6 -0
- package/dist/dts/form/defaults/form/getRhfUtilsFormResolvedFormProps.d.ts +2 -0
- package/dist/dts/form/defaults/form/useRhfUtilsFormResolvedFormProps.d.ts +293 -0
- package/dist/{types/form/RhfUtilsFormOptions.d.ts → dts/form/options/RhfUtilsFormOptionsType.d.ts} +6 -7
- package/dist/dts/form/options/getRhfUtilsFormResolvedOptions.d.ts +2 -0
- package/dist/dts/form/options/useRhfUtilsFormResolvedOptions.d.ts +8 -0
- package/dist/dts/form/providers/RhfUtilsFormProviders.d.ts +6 -0
- package/dist/dts/form/providers/RhfUtilsFormProvidersPropsType.d.ts +15 -0
- package/dist/dts/form/rhf/UseFormPropsType.d.ts +4 -0
- package/dist/dts/form/rhf/getRhfUtilsFormResolvedRhfProps.d.ts +4 -0
- package/dist/dts/form/rhf/useRhfFormWithResolvedProps.d.ts +5 -0
- package/dist/dts/form/state/relay/FormStateRelayContextProvider.d.ts +4 -0
- package/dist/dts/form/state/relay/FormStateRelayedAggregatedType.d.ts +10 -0
- package/dist/dts/form/state/relay/FormStateRelayedItemType.d.ts +11 -0
- package/dist/dts/form/state/relay/FormStateRelayedOptionsType.d.ts +20 -0
- package/dist/dts/form/state/relay/FormStateRelayedType.d.ts +3 -0
- package/dist/dts/form/state/relay/pull/hooks.d.ts +31 -0
- package/dist/dts/form/state/relay/push/FormStateRelayPusher.d.ts +4 -0
- package/dist/dts/form/state/relay/push/useFormStateRelayPusher.d.ts +3 -0
- package/dist/dts/form/state/relay/useFormStateRelayContext.d.ts +20 -0
- package/dist/dts/form/state/relay/utils.d.ts +4 -0
- package/dist/dts/form/utils/getSubmitterButtonData.d.ts +6 -0
- package/dist/{types → dts}/form/utils/useFormRequestSubmit.d.ts +1 -2
- package/dist/dts/form/utils/useHandleCancelWithCheckIfCanBe.d.ts +4 -0
- package/dist/dts/form/utils/useHandleCancelWithCheckIfCanBeViaProviders.d.ts +2 -0
- package/dist/{types → dts}/form/utils/useShouldFormBlockNavigation.d.ts +1 -2
- package/dist/dts/form/with-handlers-and-children/RhfUtilsForm.d.ts +3 -0
- package/dist/dts/form/with-handlers-and-children/RhfUtilsFormProps.d.ts +46 -0
- package/dist/dts/form/with-handlers-and-children/_ChildrenViaProviders.d.ts +3 -0
- package/dist/dts/form/with-handlers-and-children/_FormWithSubmitHandler.d.ts +4 -0
- package/dist/dts/form/with-handlers-and-children/_useHandleSubmit.d.ts +11 -0
- package/dist/dts/form/with-providers/RhfUtilsFormWithProviders.d.ts +8 -0
- package/dist/dts/form/with-providers/RhfUtilsFormWithProvidersProps.d.ts +4 -0
- package/dist/dts/resolvers/ObjectSchema.d.ts +7 -0
- package/dist/dts/resolvers/zod/RhfUtilsUseZodFormChildrenFCType.d.ts +7 -0
- package/dist/dts/resolvers/zod/RhfUtilsUseZodFormChildrenPropsType.d.ts +4 -0
- package/dist/dts/resolvers/zod/ZodTypeSafeFieldValuesType.d.ts +5 -0
- package/dist/dts/resolvers/zod/consts.d.ts +4 -0
- package/dist/dts/resolvers/zod/form/RhfUtilsZodForm.d.ts +7 -0
- package/dist/dts/resolvers/zod/getZodResolver.d.ts +4 -0
- package/dist/dts/resolvers/zod/providers/RhfUtilsZodFormProviders.d.ts +8 -0
- package/dist/dts/resolvers/zod/with-providers/RhfUtilsZodFormWithProviders.d.ts +10 -0
- package/dist/dts/submit/UseRhfUtilsFormOnSubmitContextType.d.ts +23 -0
- package/dist/dts/submit/error/FormSubmitError.d.ts +6 -0
- package/dist/{types → dts}/submit/error/FormSubmitFieldErrors.d.ts +1 -1
- package/dist/dts/submit/error/setCtxErrorsByFormSubmitFieldErrors.d.ts +8 -0
- package/dist/dts/submit/last-error/LastSubmitErrorContextProvider.d.ts +4 -0
- package/dist/dts/submit/last-error/LastSubmitErrorContextType.d.ts +8 -0
- package/dist/dts/submit/last-error/useLastSubmitError.d.ts +4 -0
- package/dist/dts/submit/last-error/useLastSubmitErrorContext.d.ts +3 -0
- package/dist/dts/submit/last-error/useLastSubmitErrorContextWith.d.ts +2 -0
- package/dist/{types → dts}/submit/useFormOnSubmitSuccessfulAndReset.d.ts +1 -2
- package/dist/dts/submit/useFormOnSubmitted.d.ts +4 -0
- package/dist/{types → dts}/submit/useResetFormOnSubmitted.d.ts +1 -2
- package/dist/dts/submit/useRhfUtilsFormOnSubmitContext.d.ts +3 -0
- package/dist/dts/submit/useSubmitFormOnChange.d.ts +15 -0
- package/dist/dts/submit/useSubmitFormOnEvent.d.ts +9 -0
- package/dist/dts/submit/useSubmitFormOnWatch.d.ts +14 -0
- package/dist/dts/utils/PassthroughChildren.d.ts +7 -0
- package/dist/{types → dts}/utils/createContext.d.ts +1 -2
- package/dist/dts/utils/fixedForwardRef.d.ts +5 -0
- package/dist/dts/utils/isEmptyObject.d.ts +1 -0
- package/dist/dts/utils/types.d.ts +3 -0
- package/dist/{types → dts}/utils/useImperativeForwardedRef.d.ts +1 -2
- package/dist/dts/utils/useIsFirstRender.d.ts +7 -0
- package/dist/dts/utils/useRefIfValueWasTrue.d.ts +2 -0
- package/dist/dts/utils/useToggle.d.ts +2 -0
- package/dist/dts/vite-env.d.ts +1 -0
- package/dist/esm/getFlatFieldErrors.mjs +55 -0
- package/dist/esm/index.mjs +503 -390
- package/dist/esm/relay.mjs +222 -0
- package/dist/esm/trpc.mjs +8 -9
- package/package.json +91 -72
- package/LICENSE.md +0 -21
- package/dist/esm/createContext.mjs +0 -16
- package/dist/esm/group.mjs +0 -74
- package/dist/esm/useFlatFieldErrorsContext.mjs +0 -10
- package/dist/esm/utils.mjs +0 -20
- package/dist/types/_exports/group.d.ts +0 -9
- package/dist/types/_exports/index.d.ts +0 -15
- package/dist/types/_exports/trpc.d.ts +0 -2
- package/dist/types/_exports/utils.d.ts +0 -1
- package/dist/types/client/config/RhfUtilsClientConfig.d.ts +0 -70
- package/dist/types/client/config/useRhfUtilsClientConfigContext.d.ts +0 -4
- package/dist/types/client/context.d.ts +0 -2
- package/dist/types/client/index.d.ts +0 -24
- package/dist/types/client/utils.d.ts +0 -12
- package/dist/types/client/zod/RhfUtilsUseFormChildrenZodFC.d.ts +0 -12
- package/dist/types/client/zod/RhfUtilsUseFormChildrenZodProps.d.ts +0 -4
- package/dist/types/client/zod/ZodTypeFieldValues.d.ts +0 -3
- package/dist/types/client/zod/consts.d.ts +0 -4
- package/dist/types/client/zod/context/RhfUtilsClientForZodContextProvider.d.ts +0 -7
- package/dist/types/client/zod/context/RhfUtilsZodForm.d.ts +0 -8
- package/dist/types/client/zod/context/useRhfUtilsClientForZodContext.d.ts +0 -5
- package/dist/types/client/zod/context/useRhfUtilsZodForm.d.ts +0 -7
- package/dist/types/client/zod/createRhfUtilsClientForZod.d.ts +0 -3
- package/dist/types/errors/flat/context/useFlatFieldErrorsContextHasOnlyOrphans.d.ts +0 -7
- package/dist/types/errors/flat/filterFlatFieldErrors.d.ts +0 -8
- package/dist/types/errors/getRefdFromFlatFieldErrors.d.ts +0 -2
- package/dist/types/errors/isFlatFieldErrorEntryRefd.d.ts +0 -6
- package/dist/types/errors/nonfield/RhfUtilsNonFieldErrorMarkerHtmlAttribute.d.ts +0 -5
- package/dist/types/errors/nonfield/isNonFieldErrorMarkerInDOM.d.ts +0 -6
- package/dist/types/errors/orphan/getIsOrphanFormErrorWithParentElement.d.ts +0 -6
- package/dist/types/errors/orphan/getOrphansFromFlatFieldErrors.d.ts +0 -3
- package/dist/types/errors/orphan/isOrphanFormError.d.ts +0 -3
- package/dist/types/errors/output/consoleErrors.d.ts +0 -6
- package/dist/types/errors/root/RootErrorsListFromFlatFieldErrorsContext.d.ts +0 -2
- package/dist/types/errors/root/getRootsFromFlatFieldErrors.d.ts +0 -2
- package/dist/types/errors/trpc/trpcClientErrorMessageSchema.d.ts +0 -23
- package/dist/types/errors/trpc/trpcClientErrorToFormSubmitFieldErrorsSchemaTransformer.d.ts +0 -27
- package/dist/types/form/Form.d.ts +0 -10
- package/dist/types/form/FormWithProviders.d.ts +0 -12
- package/dist/types/form/RhfUtilsFormProviders.d.ts +0 -11
- package/dist/types/form/UseRhfUtilsFormChildrenProps.d.ts +0 -23
- package/dist/types/form/UseRhfUtilsFormOnSubmitContext.d.ts +0 -28
- package/dist/types/form/UseRhfUtilsFormProps.d.ts +0 -22
- package/dist/types/form/UseRhfUtilsFormReturn.d.ts +0 -19
- package/dist/types/form/_Controller.d.ts +0 -5
- package/dist/types/form/context/group/FormGroupContextProvider.d.ts +0 -4
- package/dist/types/form/context/group/index.d.ts +0 -14
- package/dist/types/form/context/group/useFormGroupChildIsMountedTracker.d.ts +0 -5
- package/dist/types/form/context/group/useFormGroupChildIsSubmittingTracker.d.ts +0 -5
- package/dist/types/form/context/group/useFormGroupChildTracker.d.ts +0 -6
- package/dist/types/form/context/group/useFormGroupIsAnyBusy.d.ts +0 -2
- package/dist/types/form/context/group/useFormGroupIsChildBusy.d.ts +0 -2
- package/dist/types/form/context/group/useFormGroupIsParentBusy.d.ts +0 -2
- package/dist/types/form/context/group/useFormGroupParentTracker.d.ts +0 -7
- package/dist/types/form/context/group/useFormOrParentIsBusy.d.ts +0 -2
- package/dist/types/form/context/utils/RhfUtilsContextProvider.d.ts +0 -8
- package/dist/types/form/context/utils/useRhfUtilsContext.d.ts +0 -13
- package/dist/types/form/context/utils/useRhfUtilsContextRequestSubmit.d.ts +0 -5
- package/dist/types/form/useFormIsBusy.d.ts +0 -2
- package/dist/types/form/useRhfUtilsForm.d.ts +0 -15
- package/dist/types/form/utils/getSubmitterButtonData.d.ts +0 -7
- package/dist/types/register.d.ts +0 -7
- package/dist/types/submit/error/FormSubmitError.d.ts +0 -6
- package/dist/types/submit/error/setCtxErrorsByFormSubmitFieldErrors.d.ts +0 -9
- package/dist/types/submit/useFormOnSubmitted.d.ts +0 -5
- package/dist/types/submit/useSubmitFormOnChange.d.ts +0 -8
- package/dist/types/utils/PassthroughChildren.d.ts +0 -7
- package/dist/types/utils/fixedForwardRef.d.ts +0 -6
- package/dist/types/utils/isEmptyObject.d.ts +0 -2
- package/dist/types/utils/types.d.ts +0 -1
- package/dist/types/utils/useRefIfValueWasTrue.d.ts +0 -2
- package/dist/types/utils/useThrowAsyncError.d.ts +0 -5
- package/dist/types/utils/useToggle.d.ts +0 -3
- /package/dist/{types → dts}/errors/flat/context/FlatFieldErrorsOutputConfig.d.ts +0 -0
- /package/dist/{types → dts}/errors/flat/types.d.ts +0 -0
- /package/dist/{types → dts}/errors/nonfield/RhfUtilsNonFieldErrorMarker.spec.d.ts +0 -0
- /package/dist/{types → dts}/errors/nonfield/RhfUtilsNonFieldErrorMarker.utils.d.ts +0 -0
- /package/dist/{types → dts}/errors/output/types.d.ts +0 -0
- /package/dist/{types → dts}/errors/root/consts.d.ts +0 -0
- /package/dist/{types/form/SafeFieldValues.d.ts → dts/form/rhf/SafeFieldValuesType.d.ts} +0 -0
- /package/dist/{types → dts}/main.d.ts +0 -0
- /package/dist/{types → dts}/utils/timeoutAsync.d.ts +0 -0
- /package/dist/{types → dts}/utils/useDebouncedOnChangeValue.d.ts +0 -0
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { SubmitErrorHandler, SubmitHandler } from 'react-hook-form';
|
|
2
|
+
import { MaybePromise } from '../../utils/types';
|
|
3
|
+
import { SafeFieldValues } from '../rhf/SafeFieldValuesType';
|
|
4
|
+
type Props<TFieldValues extends SafeFieldValues, TTransformedValues extends SafeFieldValues> = {
|
|
5
|
+
onValid: SubmitHandler<TTransformedValues>;
|
|
6
|
+
onInvalid?: SubmitErrorHandler<TFieldValues>;
|
|
7
|
+
onError: (error: unknown, event: React.BaseSyntheticEvent) => void;
|
|
8
|
+
onFinally?: () => MaybePromise<unknown>;
|
|
9
|
+
};
|
|
10
|
+
export declare const useRhfUtilsFormHandleSubmit_Internal: <TFieldValues extends SafeFieldValues, TTransformedValues extends SafeFieldValues>({ onValid, onInvalid, onError, onFinally, }: Props<TFieldValues, TTransformedValues>) => ((event: React.FormEvent<HTMLFormElement>) => void);
|
|
11
|
+
export {};
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { SafeFieldValues } from '../rhf/SafeFieldValuesType';
|
|
2
|
+
import { RhfUtilsFormPropsGetApiValues } from '../with-handlers-and-children/RhfUtilsFormProps';
|
|
3
|
+
import { RhfUtilsFormWithProvidersProps } from './RhfUtilsFormWithProvidersProps';
|
|
4
|
+
/**
|
|
5
|
+
* Form providers (with utils) with immediate descendent {@link RhfUtilsForm}.
|
|
6
|
+
* (Syntactic sugar for {@link useRhfUtilsForm}. Use this for most applications.)
|
|
7
|
+
*/
|
|
8
|
+
export declare function RhfUtilsFormWithProviders<TFieldValues extends SafeFieldValues, TTransformedValues extends SafeFieldValues, TGetApiValues extends undefined | RhfUtilsFormPropsGetApiValues<TTransformedValues, SafeFieldValues>, TOnSubmitReturnType, TApiValues extends undefined | SafeFieldValues = TGetApiValues extends RhfUtilsFormPropsGetApiValues<TTransformedValues, infer U> ? U : undefined>({ getApiData, resolver, rhf, defaultValues, options, onCancel, onSubmitInvalid, onBeforeSubmitInvariants, onBeforeSubmit, onSubmit, onSubmitSuccess, onSubmitError, onSubmitFinally, Children, form, formId, className, }: RhfUtilsFormWithProvidersProps<TFieldValues, TTransformedValues, TGetApiValues, TOnSubmitReturnType, TApiValues>): import("react/jsx-runtime").JSX.Element;
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import { RhfUtilsFormProvidersProps } from '../providers/RhfUtilsFormProvidersPropsType';
|
|
2
|
+
import { SafeFieldValues } from '../rhf/SafeFieldValuesType';
|
|
3
|
+
import { RhfUtilsFormProps, RhfUtilsFormPropsGetApiValues } from '../with-handlers-and-children/RhfUtilsFormProps';
|
|
4
|
+
export type RhfUtilsFormWithProvidersProps<TFieldValues extends SafeFieldValues, TTransformedValues extends SafeFieldValues, TGetApiValues extends undefined | RhfUtilsFormPropsGetApiValues<TTransformedValues, SafeFieldValues>, TOnSubmitReturnType, TApiValues extends undefined | SafeFieldValues = TGetApiValues extends RhfUtilsFormPropsGetApiValues<TTransformedValues, infer U> ? U : undefined> = RhfUtilsFormProvidersProps<TFieldValues, TTransformedValues> & RhfUtilsFormProps<TFieldValues, TTransformedValues, TGetApiValues, TOnSubmitReturnType, TApiValues>;
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { default as React } from 'react';
|
|
2
|
+
import { RhfUtilsUseZodFormChildrenProps } from './RhfUtilsUseZodFormChildrenPropsType';
|
|
3
|
+
import { ZodTypeSafeFieldValues } from './ZodTypeSafeFieldValuesType';
|
|
4
|
+
/**
|
|
5
|
+
* {@link React.FC} for {@link RhfUtilsUseZodFormChildrenProps}.
|
|
6
|
+
*/
|
|
7
|
+
export type RhfUtilsUseZodFormChildrenFC<TSchema extends ZodTypeSafeFieldValues, TChildrenProps = undefined> = React.FC<RhfUtilsUseZodFormChildrenProps<TSchema, TChildrenProps>>;
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import { UseRhfUtilsFormChildrenProps } from '../../form/UseRhfUtilsFormChildrenPropsType';
|
|
2
|
+
import { zodTypeInput, zodTypeOutput } from './consts';
|
|
3
|
+
import { ZodTypeSafeFieldValues } from './ZodTypeSafeFieldValuesType';
|
|
4
|
+
export type RhfUtilsUseZodFormChildrenProps<TSchema extends ZodTypeSafeFieldValues, TChildrenProps = undefined> = UseRhfUtilsFormChildrenProps<TSchema[typeof zodTypeInput], TSchema[typeof zodTypeOutput], TChildrenProps>;
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
import { SafeFieldValues } from '../../form/rhf/SafeFieldValuesType';
|
|
3
|
+
type ZodTypeOfSafeFieldValues = z.ZodType<SafeFieldValues, z.ZodObjectDef>;
|
|
4
|
+
export type ZodTypeSafeFieldValues = ZodTypeOfSafeFieldValues | z.ZodEffects<ZodTypeOfSafeFieldValues>;
|
|
5
|
+
export {};
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { SafeFieldValues } from '../../../form/rhf/SafeFieldValuesType';
|
|
2
|
+
import { RhfUtilsFormProps, RhfUtilsFormPropsGetApiValues } from '../../../form/with-handlers-and-children/RhfUtilsFormProps';
|
|
3
|
+
import { zodTypeInput, zodTypeOutput } from '../consts';
|
|
4
|
+
import { ZodTypeSafeFieldValues } from '../ZodTypeSafeFieldValuesType';
|
|
5
|
+
type Props<TSchema extends ZodTypeSafeFieldValues, TGetApiValues extends undefined | RhfUtilsFormPropsGetApiValues<TSchema[typeof zodTypeOutput], SafeFieldValues>, TOnSubmitReturnType, TApiValues extends undefined | SafeFieldValues = TGetApiValues extends RhfUtilsFormPropsGetApiValues<TSchema[typeof zodTypeOutput], infer U> ? U : undefined> = React.PropsWithChildren<RhfUtilsFormProps<TSchema[typeof zodTypeInput], TSchema[typeof zodTypeOutput], TGetApiValues, TOnSubmitReturnType, TApiValues>>;
|
|
6
|
+
export declare const RhfUtilsZodForm: <TSchema extends ZodTypeSafeFieldValues, TGetApiValues extends undefined | RhfUtilsFormPropsGetApiValues<TSchema[typeof zodTypeOutput], SafeFieldValues>, TOnSubmitReturnType, TApiValues extends undefined | SafeFieldValues = TGetApiValues extends RhfUtilsFormPropsGetApiValues<TSchema[typeof zodTypeOutput], infer U> ? U : undefined>(props: Props<TSchema, TGetApiValues, TOnSubmitReturnType, TApiValues>) => import("react/jsx-runtime").JSX.Element;
|
|
7
|
+
export {};
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import { Resolver } from 'react-hook-form';
|
|
2
|
+
import { zodTypeInput, zodTypeOutput } from './consts';
|
|
3
|
+
import { ZodTypeSafeFieldValues } from './ZodTypeSafeFieldValuesType';
|
|
4
|
+
export declare const getZodResolver: <TSchema extends ZodTypeSafeFieldValues, TFieldValues extends TSchema[typeof zodTypeInput], TTransformedValues extends TSchema[typeof zodTypeOutput]>(schema: TSchema) => Resolver<TFieldValues, unknown, TTransformedValues>;
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { RhfUtilsFormProvidersProps } from '../../../form/providers/RhfUtilsFormProvidersPropsType';
|
|
2
|
+
import { zodTypeInput, zodTypeOutput } from '../consts';
|
|
3
|
+
import { ZodTypeSafeFieldValues } from '../ZodTypeSafeFieldValuesType';
|
|
4
|
+
type Props<TSchema extends ZodTypeSafeFieldValues> = React.PropsWithChildren<{
|
|
5
|
+
schema: TSchema;
|
|
6
|
+
} & RhfUtilsFormProvidersProps<TSchema[typeof zodTypeInput], TSchema[typeof zodTypeOutput]>>;
|
|
7
|
+
export declare const RhfUtilsZodFormProviders: <TSchema extends ZodTypeSafeFieldValues>({ schema, children, ...props }: Props<TSchema>) => import("react/jsx-runtime").JSX.Element;
|
|
8
|
+
export {};
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { RhfUtilsFormProvidersProps } from '../../../form/providers/RhfUtilsFormProvidersPropsType';
|
|
2
|
+
import { SafeFieldValues } from '../../../form/rhf/SafeFieldValuesType';
|
|
3
|
+
import { RhfUtilsFormProps, RhfUtilsFormPropsGetApiValues } from '../../../form/with-handlers-and-children/RhfUtilsFormProps';
|
|
4
|
+
import { zodTypeInput, zodTypeOutput } from '../consts';
|
|
5
|
+
import { ZodTypeSafeFieldValues } from '../ZodTypeSafeFieldValuesType';
|
|
6
|
+
type Props<TSchema extends ZodTypeSafeFieldValues, TGetApiValues extends undefined | RhfUtilsFormPropsGetApiValues<TTransformedValues, SafeFieldValues>, TOnSubmitReturnType, TFieldValues extends TSchema[typeof zodTypeInput] = TSchema[typeof zodTypeInput], TTransformedValues extends TSchema[typeof zodTypeOutput] = TSchema[typeof zodTypeOutput], TApiValues extends undefined | SafeFieldValues = TGetApiValues extends RhfUtilsFormPropsGetApiValues<TTransformedValues, infer U> ? U : undefined> = React.PropsWithChildren<{
|
|
7
|
+
schema: TSchema;
|
|
8
|
+
} & Omit<RhfUtilsFormProvidersProps<TFieldValues, TTransformedValues>, 'resolver'> & RhfUtilsFormProps<TFieldValues, TTransformedValues, TGetApiValues, TOnSubmitReturnType, TApiValues>>;
|
|
9
|
+
export declare const RhfUtilsZodFormWithProviders: <TSchema extends ZodTypeSafeFieldValues, TGetApiValues extends undefined | RhfUtilsFormPropsGetApiValues<TTransformedValues, SafeFieldValues>, TOnSubmitReturnType, TFieldValues extends TSchema[typeof zodTypeInput] = TSchema[typeof zodTypeInput], TTransformedValues extends TSchema[typeof zodTypeOutput] = TSchema[typeof zodTypeOutput], TApiValues extends undefined | SafeFieldValues = TGetApiValues extends RhfUtilsFormPropsGetApiValues<TTransformedValues, infer U> ? U : undefined>({ schema, ...props }: Props<TSchema, TGetApiValues, TOnSubmitReturnType, TFieldValues, TTransformedValues, TApiValues>) => import("react/jsx-runtime").JSX.Element;
|
|
10
|
+
export {};
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { UseFormReturn } from 'react-hook-form';
|
|
2
|
+
import { FormSubmitError } from './error/FormSubmitError';
|
|
3
|
+
import { FormSubmitFieldErrors } from './error/FormSubmitFieldErrors';
|
|
4
|
+
import { RhfUtilsContextProps } from '../form/context/utils/RhfUtilsContextPropsType';
|
|
5
|
+
import { SafeFieldValues } from '../form/rhf/SafeFieldValuesType';
|
|
6
|
+
/**
|
|
7
|
+
* Props for onSubmit other than `data` and `event`.
|
|
8
|
+
*
|
|
9
|
+
* Consider keeping shape in line with `UseRhfUtilsFormChildrenProps` and `UseRhfUtilsFormReturn`.
|
|
10
|
+
*/
|
|
11
|
+
export type UseRhfUtilsFormOnSubmitContext<TFieldValues extends SafeFieldValues = SafeFieldValues, TTransformedValues extends SafeFieldValues = TFieldValues, TApiValues extends undefined | SafeFieldValues = undefined> = {
|
|
12
|
+
utils: RhfUtilsContextProps;
|
|
13
|
+
rhf: UseFormReturn<TFieldValues, unknown, TTransformedValues>;
|
|
14
|
+
FormSubmitError: typeof FormSubmitError<TFieldValues, TApiValues>;
|
|
15
|
+
};
|
|
16
|
+
/**
|
|
17
|
+
* Props for onSubmitError other than `error` and `event`.
|
|
18
|
+
*/
|
|
19
|
+
export type UseRhfUtilsFormOnSubmitErrorContext<TFieldValues extends SafeFieldValues, TTransformedValues extends SafeFieldValues> = {
|
|
20
|
+
utils: RhfUtilsContextProps;
|
|
21
|
+
rhf: UseFormReturn<TFieldValues, unknown, TTransformedValues>;
|
|
22
|
+
errors?: FormSubmitFieldErrors;
|
|
23
|
+
};
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import { SafeFieldValues } from '../../form/rhf/SafeFieldValuesType';
|
|
2
|
+
import { FormSubmitFieldErrors } from './FormSubmitFieldErrors';
|
|
3
|
+
export declare class FormSubmitError<TFieldValues extends SafeFieldValues = SafeFieldValues, TApiValues extends undefined | SafeFieldValues = undefined, TAllValues extends SafeFieldValues = TApiValues extends undefined ? TFieldValues : TFieldValues | TApiValues> extends Error {
|
|
4
|
+
errors: FormSubmitFieldErrors<TAllValues>;
|
|
5
|
+
constructor(errors: FormSubmitFieldErrors<TAllValues>, message?: string);
|
|
6
|
+
}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { SafeFieldValues } from '../../form/rhf/SafeFieldValuesType';
|
|
2
|
+
import { RHF_UseFormReturnWithoutProxies } from '../../form/RHF_UseFormReturnWithoutProxiesType';
|
|
3
|
+
import { FormSubmitFieldErrors } from './FormSubmitFieldErrors';
|
|
4
|
+
/**
|
|
5
|
+
* Handle thrown {@link FormSubmitError}.
|
|
6
|
+
* Add key/values as name/message to RHF context errors.
|
|
7
|
+
*/
|
|
8
|
+
export declare const setCtxErrorsByFormSubmitFieldErrors: <TFieldValues extends SafeFieldValues, TTransformedValues extends SafeFieldValues>(ctx: RHF_UseFormReturnWithoutProxies<TFieldValues, TTransformedValues>, errors: FormSubmitFieldErrors) => void;
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
import { LastSubmitErrorContext } from './LastSubmitErrorContextType';
|
|
2
|
+
declare const _LastSubmitErrorContextProvider: import('react').Provider<LastSubmitErrorContext | undefined>, _useLastSubmitErrorContext: () => LastSubmitErrorContext;
|
|
3
|
+
export { _LastSubmitErrorContextProvider, _useLastSubmitErrorContext };
|
|
@@ -10,5 +10,4 @@ import { MaybePromise } from '../utils/types';
|
|
|
10
10
|
*
|
|
11
11
|
* SubmitSuccessfulAndReset = was `isSubmitSuccessful` and now `!isDirty`
|
|
12
12
|
*/
|
|
13
|
-
declare const useFormOnSubmitSuccessfulAndReset: (callback?: (...data: unknown[]) => MaybePromise<unknown>) => void;
|
|
14
|
-
export default useFormOnSubmitSuccessfulAndReset;
|
|
13
|
+
export declare const useFormOnSubmitSuccessfulAndReset: (callback?: (...data: unknown[]) => MaybePromise<unknown>) => void;
|
|
@@ -32,5 +32,4 @@ export type UseResetFormOnSubmittedOptions = undefined | {
|
|
|
32
32
|
* See `Rules` section: https://react-hook-form.com/api/useform/reset/
|
|
33
33
|
* Specifically: "- It's recommended to reset inside useEffect after submission."
|
|
34
34
|
*/
|
|
35
|
-
declare const useResetFormOnSubmitted: (options: UseResetFormOnSubmittedOptions) => void;
|
|
36
|
-
export default useResetFormOnSubmitted;
|
|
35
|
+
export declare const useResetFormOnSubmitted: (options: UseResetFormOnSubmittedOptions) => void;
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
import { SafeFieldValues } from '../form/rhf/SafeFieldValuesType';
|
|
2
|
+
import { UseRhfUtilsFormOnSubmitContext } from './UseRhfUtilsFormOnSubmitContextType';
|
|
3
|
+
export declare const useRhfUtilsFormOnSubmitContext: <TFieldValues extends SafeFieldValues = SafeFieldValues, TTransformedValues extends SafeFieldValues = TFieldValues>() => UseRhfUtilsFormOnSubmitContext<TFieldValues, TTransformedValues>;
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { default as React } from 'react';
|
|
2
|
+
/**
|
|
3
|
+
* Listens for "change" event on form. (Debounce via `options` param.)
|
|
4
|
+
*
|
|
5
|
+
* Caveats:
|
|
6
|
+
* - uses DOM "change" event listener on form element via ref
|
|
7
|
+
* - in some cases, event does not trigger until input loses focus
|
|
8
|
+
* - no RHF dependency
|
|
9
|
+
*/
|
|
10
|
+
export declare const useSubmitFormOnChange: (formRef: React.RefObject<HTMLFormElement | null>, options?: {
|
|
11
|
+
/** Disable behavior. (Default behavior is enabled for sake of simplicity of general usage.) */
|
|
12
|
+
disabled?: boolean;
|
|
13
|
+
/** Milliseconds to debounce form submission. (Default is none.) */
|
|
14
|
+
debounce?: number;
|
|
15
|
+
}) => void;
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { default as React } from 'react';
|
|
2
|
+
export type UseSubmitFormOnEventDebouncedOptions = {
|
|
3
|
+
/** Milliseconds to debounce form submission. (Default is none.) */
|
|
4
|
+
debounce?: number;
|
|
5
|
+
};
|
|
6
|
+
/**
|
|
7
|
+
* Internal, shared hook to setup debounced callback for OnChange hooks.
|
|
8
|
+
*/
|
|
9
|
+
export declare const useSubmitFormOnEventDebounced: (formRef: React.RefObject<HTMLFormElement | null>, options?: UseSubmitFormOnEventDebouncedOptions) => (value: unknown) => void;
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { default as React } from 'react';
|
|
2
|
+
export type UseSubmitFormOnWatchOptions = {
|
|
3
|
+
/** Milliseconds to debounce form submission. (Default is none.) */
|
|
4
|
+
debounce: number;
|
|
5
|
+
};
|
|
6
|
+
/**
|
|
7
|
+
* Watches for changes in form values.
|
|
8
|
+
*
|
|
9
|
+
* Caveats:
|
|
10
|
+
* - uses RHF's useWatch
|
|
11
|
+
* - triggers change immediately as user types, so use sensible debounce time
|
|
12
|
+
* - does not cover uncontrolled inputs
|
|
13
|
+
*/
|
|
14
|
+
export declare const useSubmitFormOnWatch: (formRef: React.RefObject<HTMLFormElement | null>, options?: UseSubmitFormOnWatchOptions) => void;
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Component for passing-through children and ignoring props.
|
|
3
|
+
*
|
|
4
|
+
* Useful for conditional wrapping of children where conditional wrapper has props.
|
|
5
|
+
* (`React.Fragment` only allows `key` and `children`.)
|
|
6
|
+
*/
|
|
7
|
+
export declare const PassthroughChildren: React.FC<React.PropsWithChildren>;
|
|
@@ -3,9 +3,8 @@ import { default as React } from 'react';
|
|
|
3
3
|
* Create a strictly-typed context that throws error if no provider is found.
|
|
4
4
|
* @returns A tuple with a function to get the context and the context provider.
|
|
5
5
|
*/
|
|
6
|
-
declare function createContext<T = unknown>(): {
|
|
6
|
+
export declare function createContext<T = unknown>(): {
|
|
7
7
|
readonly Provider: React.Provider<T | undefined>;
|
|
8
8
|
readonly useMaybe: () => T | undefined;
|
|
9
9
|
readonly useRequired: () => T & ({} | null);
|
|
10
10
|
};
|
|
11
|
-
export default createContext;
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import { default as React } from 'react';
|
|
2
|
+
/**
|
|
3
|
+
* @see https://www.totaltypescript.com/forwardref-with-generic-components
|
|
4
|
+
*/
|
|
5
|
+
export declare function fixedForwardRef<T, P = object>(render: React.ForwardRefRenderFunction<T, React.PropsWithoutRef<P>>): (props: P & React.RefAttributes<T>) => React.ReactNode;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const isEmptyObject: (obj: Record<string, unknown>) => boolean;
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
export type MaybePromise<T> = T | Promise<T>;
|
|
2
|
+
/** Merge {@link C} into {@link B} into {@link A} (last taking highest precedence). */
|
|
3
|
+
export type Merge<A, B, C = unknown, D = unknown> = D & Omit<C, keyof D> & Omit<Omit<B, keyof C>, keyof D> & Omit<Omit<Omit<A, keyof B>, keyof C>, keyof D>;
|
|
@@ -6,5 +6,4 @@ import { default as React } from 'react';
|
|
|
6
6
|
*
|
|
7
7
|
* @param forwardedRef Forwarded `ref` prop.
|
|
8
8
|
*/
|
|
9
|
-
declare const useImperativeForwardedRef: <TRef>(forwardedRef?: React.ForwardedRef<TRef>) => React.RefObject<TRef>;
|
|
10
|
-
export default useImperativeForwardedRef;
|
|
9
|
+
export declare const useImperativeForwardedRef: <TRef>(forwardedRef?: React.ForwardedRef<TRef>) => React.RefObject<TRef | null>;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
/// <reference types="vite/client" />
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
import a from "react";
|
|
2
|
+
import { get as c } from "react-hook-form";
|
|
3
|
+
import { flatten as f } from "flat";
|
|
4
|
+
function d() {
|
|
5
|
+
const e = a.createContext(void 0), r = () => a.useContext(e), s = () => {
|
|
6
|
+
const t = r();
|
|
7
|
+
if (t === void 0) throw new Error();
|
|
8
|
+
return t;
|
|
9
|
+
};
|
|
10
|
+
return {
|
|
11
|
+
Provider: e.Provider,
|
|
12
|
+
useMaybe: r,
|
|
13
|
+
useRequired: s
|
|
14
|
+
};
|
|
15
|
+
}
|
|
16
|
+
const {
|
|
17
|
+
Provider: x,
|
|
18
|
+
useRequired: g,
|
|
19
|
+
useMaybe: E
|
|
20
|
+
} = d(), h = (e) => Object.keys(e).length === 0, u = (e) => f(e), b = (e) => {
|
|
21
|
+
const r = u(e), s = Object.keys(r);
|
|
22
|
+
return Object.fromEntries(
|
|
23
|
+
s.reduce(
|
|
24
|
+
(t, n) => {
|
|
25
|
+
const o = n.replace(
|
|
26
|
+
l,
|
|
27
|
+
""
|
|
28
|
+
);
|
|
29
|
+
if (o === n) return t;
|
|
30
|
+
const i = c(e, o, void 0);
|
|
31
|
+
return i && t.push([o, i]), t;
|
|
32
|
+
},
|
|
33
|
+
[]
|
|
34
|
+
// entries
|
|
35
|
+
)
|
|
36
|
+
);
|
|
37
|
+
}, l = /\.(?:type|message)\b$/, v = (e) => Object.fromEntries(
|
|
38
|
+
Object.entries(b(e)).map(([r, s]) => [
|
|
39
|
+
r,
|
|
40
|
+
{
|
|
41
|
+
type: s.type,
|
|
42
|
+
message: s.message
|
|
43
|
+
// strip out ref, etc. (avoid circular JSON error)
|
|
44
|
+
}
|
|
45
|
+
])
|
|
46
|
+
);
|
|
47
|
+
export {
|
|
48
|
+
x as _,
|
|
49
|
+
E as a,
|
|
50
|
+
v as b,
|
|
51
|
+
d as c,
|
|
52
|
+
b as g,
|
|
53
|
+
h as i,
|
|
54
|
+
g as u
|
|
55
|
+
};
|