@paragrav/rhf-utils 0.65.0 → 0.67.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 +3 -2
- package/dist/tsdown/FormRelayOptions-mBqiP41Z.d.ts +29 -0
- package/dist/tsdown/FormRelaySetter-BKO0Wodf.js +192 -0
- package/dist/tsdown/RhfUtilsClientConfigType-CeOJzNAc.d.ts +212 -0
- package/dist/tsdown/RhfUtilsContextType-BFmDtONY.d.ts +81 -0
- package/dist/tsdown/index.d.ts +207 -0
- package/dist/tsdown/index.js +745 -0
- package/dist/tsdown/relay.d.ts +56 -0
- package/dist/tsdown/relay.js +71 -0
- package/dist/tsdown/trpc.d.ts +36 -0
- package/dist/tsdown/trpc.js +47 -0
- package/package.json +8 -24
- package/dist/dts/Register.d.ts +0 -16
- package/dist/dts/_exports/config.d.ts +0 -2
- package/dist/dts/_exports/errors.d.ts +0 -3
- package/dist/dts/_exports/form.d.ts +0 -7
- package/dist/dts/_exports/index.d.ts +0 -14
- package/dist/dts/_exports/relay.d.ts +0 -7
- package/dist/dts/_exports/submit.d.ts +0 -4
- package/dist/dts/_exports/trpc.d.ts +0 -2
- package/dist/dts/_exports/types.d.ts +0 -7
- package/dist/dts/_exports/zod.d.ts +0 -6
- package/dist/dts/client/config/RhfUtilsClientConfigType.d.ts +0 -71
- package/dist/dts/client/config/context/RhfUtilsClientConfigContext.d.ts +0 -3
- package/dist/dts/client/config/context/RhfUtilsClientConfigProvider.d.ts +0 -7
- package/dist/dts/client/config/context/useRhfUtilsClientConfig.d.ts +0 -1
- package/dist/dts/devtool/LazyDevTool.d.ts +0 -10
- package/dist/dts/devtool/LazyDevToolViaProviders.d.ts +0 -1
- package/dist/dts/errors/flat/FlatFieldErrorsList.d.ts +0 -6
- package/dist/dts/errors/flat/context/FlatFieldErrorsContextProvider.d.ts +0 -10
- package/dist/dts/errors/flat/context/FlatFieldErrorsOutputConfig.d.ts +0 -19
- package/dist/dts/errors/flat/context/useFlatFieldErrorsContext.d.ts +0 -11
- package/dist/dts/errors/flat/context/useFlatFieldErrorsContextHasOnlyOrphans.d.ts +0 -6
- package/dist/dts/errors/flat/context/useFlatFieldErrorsContextOutput.d.ts +0 -5
- package/dist/dts/errors/flat/filterFlatFieldErrors.d.ts +0 -7
- package/dist/dts/errors/flat/flattenFieldErrors.d.ts +0 -14
- package/dist/dts/errors/flat/getFlatFieldErrors.d.ts +0 -35
- package/dist/dts/errors/flat/types.d.ts +0 -16
- package/dist/dts/errors/getRefdFromFlatFieldErrors.d.ts +0 -1
- package/dist/dts/errors/isFieldErrorRefd.d.ts +0 -5
- package/dist/dts/errors/isFlatFieldErrorEntryRefd.d.ts +0 -5
- package/dist/dts/errors/message/FormErrorMessage.d.ts +0 -7
- package/dist/dts/errors/message/RhfUtilsFieldErrorMessage.d.ts +0 -10
- package/dist/dts/errors/nonfield/RhfUtilsNonFieldErrorMarker.d.ts +0 -13
- package/dist/dts/errors/nonfield/RhfUtilsNonFieldErrorMarker.spec.d.ts +0 -1
- package/dist/dts/errors/nonfield/RhfUtilsNonFieldErrorMarker.utils.d.ts +0 -18
- package/dist/dts/errors/nonfield/RhfUtilsNonFieldErrorMarkerHtmlAttribute.d.ts +0 -4
- package/dist/dts/errors/nonfield/isNonFieldError.d.ts +0 -17
- package/dist/dts/errors/nonfield/isNonFieldErrorMarkerInDOM.d.ts +0 -5
- package/dist/dts/errors/orphan/getIsOrphanFormErrorWithParentElement.d.ts +0 -5
- package/dist/dts/errors/orphan/getOrphansFromFlatFieldErrors.d.ts +0 -2
- package/dist/dts/errors/orphan/isOrphanFormError.d.ts +0 -2
- package/dist/dts/errors/output/consoleErrors.d.ts +0 -5
- package/dist/dts/errors/output/types.d.ts +0 -7
- package/dist/dts/errors/root/RootErrorsListFromFlatFieldErrorsContext.d.ts +0 -1
- package/dist/dts/errors/root/consts.d.ts +0 -1
- package/dist/dts/errors/root/getRootsFromFlatFieldErrors.d.ts +0 -1
- package/dist/dts/errors/root/isFlatFieldErrorEntryPathRoot.d.ts +0 -5
- package/dist/dts/errors/root/isFormErrorPathRoot.d.ts +0 -6
- package/dist/dts/errors/trpc/makeOnSubmitTrpcClientErrorHandler.d.ts +0 -9
- package/dist/dts/errors/trpc/trpcClientErrorMessageSchema.d.ts +0 -19
- package/dist/dts/errors/trpc/trpcClientErrorToFormSubmitFieldErrorsSchemaTransformer.d.ts +0 -23
- package/dist/dts/form/RHF_UseFormReturnWithoutProxiesType.d.ts +0 -15
- package/dist/dts/form/RhfUtilsFormInjectorProps.d.ts +0 -17
- package/dist/dts/form/UseRhfUtilsFormChildrenPropsType.d.ts +0 -25
- package/dist/dts/form/_Controller.d.ts +0 -4
- package/dist/dts/form/context/utils/LastSubmitStateType.d.ts +0 -1
- package/dist/dts/form/context/utils/RhfUtilsContextProvider.d.ts +0 -9
- package/dist/dts/form/context/utils/RhfUtilsContextType.d.ts +0 -12
- package/dist/dts/form/context/utils/useRhfUtilsContext.d.ts +0 -5
- package/dist/dts/form/context/utils/useRhfUtilsContextRequestSubmit.d.ts +0 -4
- package/dist/dts/form/defaults/UseRhfUtilsFormGlobalDefaults.d.ts +0 -24
- package/dist/dts/form/defaults/UseRhfUtilsFormInstanceDefaults.d.ts +0 -18
- package/dist/dts/form/defaults/UseRhfUtilsFormResolvedDefaultsType.d.ts +0 -12
- package/dist/dts/form/defaults/form/UseRhfUtilsFormInstanceFormProps.d.ts +0 -6
- package/dist/dts/form/defaults/form/getRhfUtilsFormResolvedFormProps.d.ts +0 -2
- package/dist/dts/form/defaults/form/useRhfUtilsFormResolvedFormProps.d.ts +0 -293
- package/dist/dts/form/options/RhfUtilsFormOptionsType.d.ts +0 -27
- package/dist/dts/form/options/getRhfUtilsFormResolvedOptions.d.ts +0 -2
- package/dist/dts/form/options/useRhfUtilsFormResolvedOptions.d.ts +0 -8
- package/dist/dts/form/providers/RhfUtilsFormProviders.d.ts +0 -6
- package/dist/dts/form/providers/RhfUtilsFormProvidersPropsType.d.ts +0 -17
- package/dist/dts/form/relay/FormRelayOptions.d.ts +0 -16
- package/dist/dts/form/relay/context/FormRelayContextProvider.d.ts +0 -4
- package/dist/dts/form/relay/context/useFormRelayContext.d.ts +0 -12
- package/dist/dts/form/relay/context/utils.d.ts +0 -4
- package/dist/dts/form/relay/get/FormRelayGroupType.d.ts +0 -16
- package/dist/dts/form/relay/get/grouper/context/hooks.d.ts +0 -8
- package/dist/dts/form/relay/get/grouper/context/index.d.ts +0 -5
- package/dist/dts/form/relay/get/grouper/context/provider.d.ts +0 -9
- package/dist/dts/form/relay/get/grouper/useFirstFormStateGroup.d.ts +0 -9
- package/dist/dts/form/relay/get/useFormRelay.d.ts +0 -13
- package/dist/dts/form/relay/set/FormRelaySetter.d.ts +0 -6
- package/dist/dts/form/relay/set/useFormRelaySet.d.ts +0 -2
- package/dist/dts/form/relay/types.d.ts +0 -12
- package/dist/dts/form/rhf/SafeFieldValuesType.d.ts +0 -4
- package/dist/dts/form/rhf/UseFormPropsType.d.ts +0 -4
- package/dist/dts/form/rhf/getRhfUtilsFormResolvedRhfProps.d.ts +0 -4
- package/dist/dts/form/rhf/useRhfFormWithResolvedProps.d.ts +0 -5
- package/dist/dts/form/utils/getSubmitterButtonData.d.ts +0 -6
- package/dist/dts/form/utils/useFormRequestSubmit.d.ts +0 -9
- package/dist/dts/form/utils/useHandleCancelWithCheckIfCanBe.d.ts +0 -4
- package/dist/dts/form/utils/useHandleCancelWithCheckIfCanBeViaProviders.d.ts +0 -2
- package/dist/dts/form/utils/useShouldFormBlockNavigation.d.ts +0 -24
- package/dist/dts/form/with-handlers-and-children/RhfUtilsForm.d.ts +0 -3
- package/dist/dts/form/with-handlers-and-children/RhfUtilsFormProps.d.ts +0 -42
- package/dist/dts/form/with-handlers-and-children/RhfUtilsFormPropsOnBeforeSubmitInvariants.d.ts +0 -12
- package/dist/dts/form/with-handlers-and-children/_ChildrenViaProviders.d.ts +0 -3
- package/dist/dts/form/with-handlers-and-children/_FormWithSubmitHandler.d.ts +0 -4
- package/dist/dts/form/with-handlers-and-children/_useHandleSubmit.d.ts +0 -11
- package/dist/dts/form/with-providers/RhfUtilsFormWithProviders.d.ts +0 -8
- package/dist/dts/form/with-providers/RhfUtilsFormWithProvidersProps.d.ts +0 -8
- package/dist/dts/main.d.ts +0 -1
- package/dist/dts/playwright/index.d.ts +0 -0
- package/dist/dts/playwright-ct.config.d.ts +0 -5
- package/dist/dts/resolvers/ObjectSchema.d.ts +0 -7
- package/dist/dts/resolvers/zod/RhfUtilsUseZodFormChildrenFCType.d.ts +0 -7
- package/dist/dts/resolvers/zod/RhfUtilsUseZodFormChildrenPropsType.d.ts +0 -4
- package/dist/dts/resolvers/zod/ZodTypeSafeFieldValuesType.d.ts +0 -5
- package/dist/dts/resolvers/zod/consts.d.ts +0 -4
- package/dist/dts/resolvers/zod/form/RhfUtilsZodForm.d.ts +0 -7
- package/dist/dts/resolvers/zod/getZodResolver.d.ts +0 -4
- package/dist/dts/resolvers/zod/providers/RhfUtilsZodFormProviders.d.ts +0 -8
- package/dist/dts/resolvers/zod/with-providers/RhfUtilsZodFormWithProviders.d.ts +0 -10
- package/dist/dts/submit/UseRhfUtilsFormOnSubmitContextType.d.ts +0 -23
- package/dist/dts/submit/error/FormSubmitError.d.ts +0 -6
- package/dist/dts/submit/error/FormSubmitFieldErrors.d.ts +0 -14
- package/dist/dts/submit/error/setCtxErrorsByFormSubmitFieldErrors.d.ts +0 -8
- package/dist/dts/submit/last-error/LastSubmitErrorContextProvider.d.ts +0 -4
- package/dist/dts/submit/last-error/LastSubmitErrorContextType.d.ts +0 -8
- package/dist/dts/submit/last-error/useLastSubmitError.d.ts +0 -4
- package/dist/dts/submit/last-error/useLastSubmitErrorContext.d.ts +0 -3
- package/dist/dts/submit/last-error/useLastSubmitErrorContextWith.d.ts +0 -2
- package/dist/dts/submit/useFormOnSubmitSuccessfulAndReset.d.ts +0 -13
- package/dist/dts/submit/useFormOnSubmitted.d.ts +0 -4
- package/dist/dts/submit/useResetFormOnSubmitted.d.ts +0 -35
- package/dist/dts/submit/useRhfUtilsFormOnSubmitContext.d.ts +0 -3
- package/dist/dts/submit/useSubmitFormOnChange.d.ts +0 -15
- package/dist/dts/submit/useSubmitFormOnEvent.d.ts +0 -9
- package/dist/dts/submit/useSubmitFormOnWatch.d.ts +0 -14
- package/dist/dts/utils/PassthroughChildren.d.ts +0 -7
- package/dist/dts/utils/createContext.d.ts +0 -10
- package/dist/dts/utils/fixedForwardRef.d.ts +0 -5
- package/dist/dts/utils/isEmptyObject.d.ts +0 -1
- package/dist/dts/utils/timeoutAsync.d.ts +0 -6
- package/dist/dts/utils/types.d.ts +0 -3
- package/dist/dts/utils/useDebouncedOnChangeValue.d.ts +0 -14
- package/dist/dts/utils/useImperativeForwardedRef.d.ts +0 -9
- package/dist/dts/utils/useIsFirstRender.d.ts +0 -7
- package/dist/dts/utils/useRefIfValueWasTrue.d.ts +0 -2
- package/dist/dts/utils/useToggle.d.ts +0 -2
- package/dist/dts/vite-env.d.ts +0 -1
- package/dist/esm/FormRelaySetter.mjs +0 -89
- package/dist/esm/index.mjs +0 -351
- package/dist/esm/relay.mjs +0 -49
- package/dist/esm/trpc.mjs +0 -24
|
@@ -1,42 +0,0 @@
|
|
|
1
|
-
import { SubmitErrorHandler } from 'react-hook-form';
|
|
2
|
-
import { MaybePromise } from '../../utils/types';
|
|
3
|
-
import { UseRhfUtilsFormOnSubmitContext, UseRhfUtilsFormOnSubmitErrorContext } from '../../submit/UseRhfUtilsFormOnSubmitContextType';
|
|
4
|
-
import { UseRhfUtilsFormInstanceFormProps } from '../defaults/form/UseRhfUtilsFormInstanceFormProps';
|
|
5
|
-
import { SafeFieldValues } from '../rhf/SafeFieldValuesType';
|
|
6
|
-
import { UseRhfUtilsFormChildrenProps } from '../UseRhfUtilsFormChildrenPropsType';
|
|
7
|
-
import { RhfUtilsFormPropsOnBeforeSubmitInvariants } from './RhfUtilsFormPropsOnBeforeSubmitInvariants';
|
|
8
|
-
export type RhfUtilsFormPropsGetApiValues<TTransformedValues extends SafeFieldValues, TApiValues> = (data: TTransformedValues) => TApiValues;
|
|
9
|
-
export type RhfUtilsFormProps<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> = {
|
|
10
|
-
getApiData?: TGetApiValues;
|
|
11
|
-
/** Cancellation handler -- channeled through {@link RhfUtilsClientConfig.useCanFormBeCancelled} before propagating to `Children` component. */
|
|
12
|
-
onCancel?: () => MaybePromise<void>;
|
|
13
|
-
/** Submit handler when form is invalid. */
|
|
14
|
-
onSubmitInvalid?: SubmitErrorHandler<TFieldValues>;
|
|
15
|
-
/**
|
|
16
|
-
* List of invariants to run against input/output/api data.
|
|
17
|
-
* For any and all false-y values, a {@link FormSubmitFieldErrors} will be thrown.
|
|
18
|
-
*/
|
|
19
|
-
onBeforeSubmitInvariants?: RhfUtilsFormPropsOnBeforeSubmitInvariants<TFieldValues, TTransformedValues, TApiValues>;
|
|
20
|
-
onBeforeSubmit?: (data: {
|
|
21
|
-
input: TFieldValues;
|
|
22
|
-
output: TTransformedValues;
|
|
23
|
-
api: TApiValues;
|
|
24
|
-
}, context: UseRhfUtilsFormOnSubmitContext<TFieldValues, TTransformedValues, TApiValues>, event: React.BaseSyntheticEvent<SubmitEvent>) => MaybePromise<unknown>;
|
|
25
|
-
onSubmit?: (data: {
|
|
26
|
-
input: TFieldValues;
|
|
27
|
-
output: TTransformedValues;
|
|
28
|
-
api: TApiValues;
|
|
29
|
-
}, context: UseRhfUtilsFormOnSubmitContext<TFieldValues, TTransformedValues, TApiValues>, event: React.BaseSyntheticEvent<SubmitEvent>) => MaybePromise<TOnSubmitReturnType>;
|
|
30
|
-
onSubmitSuccess?: (submitResponse: TOnSubmitReturnType, data: {
|
|
31
|
-
input: TFieldValues;
|
|
32
|
-
output: TTransformedValues;
|
|
33
|
-
api: TApiValues;
|
|
34
|
-
}, context: UseRhfUtilsFormOnSubmitContext<TFieldValues, TTransformedValues, TApiValues>, event: React.BaseSyntheticEvent<SubmitEvent>) => MaybePromise<unknown>;
|
|
35
|
-
/** Submit error handler. (Only for errors not of instance `FormError`, which are handled internally.) */
|
|
36
|
-
onSubmitError?: (error: unknown, context: UseRhfUtilsFormOnSubmitErrorContext<TFieldValues, TTransformedValues>, event: React.BaseSyntheticEvent<SubmitEvent>) => void;
|
|
37
|
-
onSubmitFinally?: () => MaybePromise<void>;
|
|
38
|
-
Children: React.FC<UseRhfUtilsFormChildrenProps<TFieldValues, TTransformedValues>>;
|
|
39
|
-
form?: UseRhfUtilsFormInstanceFormProps;
|
|
40
|
-
/** Form class attribute. */
|
|
41
|
-
className?: string;
|
|
42
|
-
};
|
package/dist/dts/form/with-handlers-and-children/RhfUtilsFormPropsOnBeforeSubmitInvariants.d.ts
DELETED
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
import { UseRhfUtilsFormOnSubmitContext } from '../../submit/UseRhfUtilsFormOnSubmitContextType';
|
|
2
|
-
import { MaybePromise } from '../../utils/types';
|
|
3
|
-
import { SafeFieldValues } from '../rhf/SafeFieldValuesType';
|
|
4
|
-
export type RhfUtilsFormPropsOnBeforeSubmitInvariants<TFieldValues extends SafeFieldValues, TTransformedValues extends SafeFieldValues, TApiValues extends undefined | SafeFieldValues> = (data: {
|
|
5
|
-
input: TFieldValues;
|
|
6
|
-
output: TTransformedValues;
|
|
7
|
-
api: TApiValues;
|
|
8
|
-
}, context: UseRhfUtilsFormOnSubmitContext<TFieldValues, TTransformedValues, TApiValues>, event: React.BaseSyntheticEvent<SubmitEvent>) => MaybePromise<{
|
|
9
|
-
field: keyof TFieldValues | keyof TApiValues;
|
|
10
|
-
message: string;
|
|
11
|
-
validate: boolean | undefined | null;
|
|
12
|
-
}[]>;
|
|
@@ -1,3 +0,0 @@
|
|
|
1
|
-
import { SafeFieldValues } from '../rhf/SafeFieldValuesType';
|
|
2
|
-
import { RhfUtilsFormProps } from './RhfUtilsFormProps';
|
|
3
|
-
export declare const RhfUtilsFormChildrenViaProviders_Internal: <TFieldValues extends SafeFieldValues, TTransformedValues extends SafeFieldValues>({ onCancel, Children, }: Pick<RhfUtilsFormProps<TFieldValues, TTransformedValues, undefined, undefined>, "Children" | "onCancel">) => import("react").JSX.Element;
|
|
@@ -1,4 +0,0 @@
|
|
|
1
|
-
import { default as React } from 'react';
|
|
2
|
-
import { SafeFieldValues } from '../rhf/SafeFieldValuesType';
|
|
3
|
-
import { RhfUtilsFormProps, RhfUtilsFormPropsGetApiValues } from './RhfUtilsFormProps';
|
|
4
|
-
export declare const RhfUtilsFormWithSubmitHandler_Internal: <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, onSubmitInvalid, onBeforeSubmitInvariants, onBeforeSubmit, onSubmit, onSubmitSuccess, onSubmitError, onSubmitFinally, form, className, children, }: React.PropsWithChildren<Pick<RhfUtilsFormProps<TFieldValues, TTransformedValues, TGetApiValues, TOnSubmitReturnType, TApiValues>, "getApiData" | "onSubmitInvalid" | "onBeforeSubmitInvariants" | "onBeforeSubmit" | "onSubmit" | "onSubmitSuccess" | "onSubmitError" | "onSubmitFinally" | "form" | "className">>) => React.JSX.Element;
|
|
@@ -1,11 +0,0 @@
|
|
|
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.SubmitEvent<HTMLFormElement>) => void);
|
|
11
|
-
export {};
|
|
@@ -1,8 +0,0 @@
|
|
|
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, relay, onCancel, onSubmitInvalid, onBeforeSubmitInvariants, onBeforeSubmit, onSubmit, onSubmitSuccess, onSubmitError, onSubmitFinally, Children, form, formId, className, }: RhfUtilsFormWithProvidersProps<TFieldValues, TTransformedValues, TGetApiValues, TOnSubmitReturnType, TApiValues>): import("react").JSX.Element;
|
|
@@ -1,8 +0,0 @@
|
|
|
1
|
-
import { Resolver } from 'react-hook-form';
|
|
2
|
-
import { Merge } from '../../utils/types';
|
|
3
|
-
import { RhfUtilsFormProvidersProps } from '../providers/RhfUtilsFormProvidersPropsType';
|
|
4
|
-
import { SafeFieldValues } from '../rhf/SafeFieldValuesType';
|
|
5
|
-
import { RhfUtilsFormProps, RhfUtilsFormPropsGetApiValues } from '../with-handlers-and-children/RhfUtilsFormProps';
|
|
6
|
-
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> = Merge<RhfUtilsFormProps<TFieldValues, TTransformedValues, TGetApiValues, TOnSubmitReturnType, TApiValues>, RhfUtilsFormProvidersProps<TFieldValues, TTransformedValues>, {
|
|
7
|
-
resolver?: Resolver<TFieldValues, unknown, TTransformedValues>;
|
|
8
|
-
}>;
|
package/dist/dts/main.d.ts
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
|
File without changes
|
|
@@ -1,7 +0,0 @@
|
|
|
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>>;
|
|
@@ -1,4 +0,0 @@
|
|
|
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>;
|
|
@@ -1,5 +0,0 @@
|
|
|
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 {};
|
|
@@ -1,7 +0,0 @@
|
|
|
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.Element;
|
|
7
|
-
export {};
|
|
@@ -1,4 +0,0 @@
|
|
|
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>;
|
|
@@ -1,8 +0,0 @@
|
|
|
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.Element;
|
|
8
|
-
export {};
|
|
@@ -1,10 +0,0 @@
|
|
|
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.Element;
|
|
10
|
-
export {};
|
|
@@ -1,23 +0,0 @@
|
|
|
1
|
-
import { UseFormReturn } from 'react-hook-form';
|
|
2
|
-
import { FormSubmitError } from './error/FormSubmitError';
|
|
3
|
-
import { FormSubmitFieldErrors } from './error/FormSubmitFieldErrors';
|
|
4
|
-
import { RhfUtilsContext } from '../form/context/utils/RhfUtilsContextType';
|
|
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: RhfUtilsContext;
|
|
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: RhfUtilsContext;
|
|
21
|
-
rhf: UseFormReturn<TFieldValues, unknown, TTransformedValues>;
|
|
22
|
-
errors?: FormSubmitFieldErrors;
|
|
23
|
-
};
|
|
@@ -1,6 +0,0 @@
|
|
|
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
|
-
}
|
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
import { FieldPath } from 'react-hook-form';
|
|
2
|
-
import { SafeFieldValues } from '../../form/rhf/SafeFieldValuesType';
|
|
3
|
-
/**
|
|
4
|
-
* Field errors structure based on RHF's `FieldErrors`.
|
|
5
|
-
*
|
|
6
|
-
* - Uses {@link SafeFieldValues} instead of more permissive `FieldValues`.
|
|
7
|
-
* - `root.<string>` keys allowed.
|
|
8
|
-
* - `root` is reserved for special use cases.
|
|
9
|
-
* - simplified `ErrorOption` value.
|
|
10
|
-
*/
|
|
11
|
-
export type FormSubmitFieldErrors<TFieldValues extends SafeFieldValues = SafeFieldValues> = Record<FieldPath<TFieldValues> | `root.${string}`, {
|
|
12
|
-
message: string;
|
|
13
|
-
type?: string;
|
|
14
|
-
}>;
|
|
@@ -1,8 +0,0 @@
|
|
|
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;
|
|
@@ -1,3 +0,0 @@
|
|
|
1
|
-
import { LastSubmitErrorContext } from './LastSubmitErrorContextType';
|
|
2
|
-
declare const _LastSubmitErrorContextProvider: import('react').Provider<LastSubmitErrorContext | undefined>, _useLastSubmitErrorContext: () => LastSubmitErrorContext;
|
|
3
|
-
export { _LastSubmitErrorContextProvider, _useLastSubmitErrorContext };
|
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
import { MaybePromise } from '../utils/types';
|
|
2
|
-
/**
|
|
3
|
-
* Calls a callback after a successful submit and after a form reset.
|
|
4
|
-
*
|
|
5
|
-
* Use this when your forms use a isDirty prompter for user action that would lose unsaved data.
|
|
6
|
-
* You must reset form before you can navigate away from page.
|
|
7
|
-
*
|
|
8
|
-
* Using RHF and following its rules, we are not able to get the state `isSubmitSuccessful=true` and `isDirty=false`.
|
|
9
|
-
* So, this has to keep track of previous state.
|
|
10
|
-
*
|
|
11
|
-
* SubmitSuccessfulAndReset = was `isSubmitSuccessful` and now `!isDirty`
|
|
12
|
-
*/
|
|
13
|
-
export declare const useFormOnSubmitSuccessfulAndReset: (callback?: (...data: unknown[]) => MaybePromise<unknown>) => void;
|
|
@@ -1,35 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Configuration options for {@link useResetFormOnSubmitted}.
|
|
3
|
-
*/
|
|
4
|
-
export type UseResetFormOnSubmittedOptions = undefined | {
|
|
5
|
-
/**
|
|
6
|
-
* Reset values on successful submit.
|
|
7
|
-
* - `defaults`: reset current values to defaults
|
|
8
|
-
* - `current`: reset defaults to current values
|
|
9
|
-
*/
|
|
10
|
-
success?: {
|
|
11
|
-
values: 'defaults' | 'current';
|
|
12
|
-
};
|
|
13
|
-
/**
|
|
14
|
-
* Reset values to defaults on submit error.
|
|
15
|
-
*/
|
|
16
|
-
error?: {
|
|
17
|
-
values: 'defaults';
|
|
18
|
-
};
|
|
19
|
-
};
|
|
20
|
-
/**
|
|
21
|
-
* Control resetting of values and (some) state (e.g., `isDirty`) after form submitted.
|
|
22
|
-
*
|
|
23
|
-
* `isDirty` and other state is reset, but submit-related state is preserved, as well as errors.
|
|
24
|
-
*
|
|
25
|
-
* Use cases:
|
|
26
|
-
* - on success:
|
|
27
|
-
* - `defaults`: reset current values to defaults (e.g., clear form)
|
|
28
|
-
* - `current`: reset defaults to current values (e.g., keep values)
|
|
29
|
-
* - on error:
|
|
30
|
-
* - reset current values to default values (e.g., submitOnChange reset)
|
|
31
|
-
*
|
|
32
|
-
* See `Rules` section: https://react-hook-form.com/api/useform/reset/
|
|
33
|
-
* Specifically: "- It's recommended to reset inside useEffect after submission."
|
|
34
|
-
*/
|
|
35
|
-
export declare const useResetFormOnSubmitted: (options: UseResetFormOnSubmittedOptions) => void;
|
|
@@ -1,3 +0,0 @@
|
|
|
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>;
|
|
@@ -1,15 +0,0 @@
|
|
|
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;
|
|
@@ -1,9 +0,0 @@
|
|
|
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;
|
|
@@ -1,14 +0,0 @@
|
|
|
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;
|
|
@@ -1,7 +0,0 @@
|
|
|
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>;
|
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
import { default as React } from 'react';
|
|
2
|
-
/**
|
|
3
|
-
* Create a strictly-typed context that throws error if no provider is found.
|
|
4
|
-
* @returns A tuple with a function to get the context and the context provider.
|
|
5
|
-
*/
|
|
6
|
-
export declare function createContext<T = unknown>(): {
|
|
7
|
-
readonly Provider: React.Provider<T | undefined>;
|
|
8
|
-
readonly useMaybe: () => T | undefined;
|
|
9
|
-
readonly useRequired: () => T & ({} | null);
|
|
10
|
-
};
|
|
@@ -1,5 +0,0 @@
|
|
|
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;
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export declare const isEmptyObject: (obj: Record<string, unknown>) => boolean;
|
|
@@ -1,3 +0,0 @@
|
|
|
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>;
|
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* React hook to debounce onChange event callback.
|
|
3
|
-
*
|
|
4
|
-
* Returns debounced state setter (uses ref internally).
|
|
5
|
-
*
|
|
6
|
-
* When debounce delay has elapsed after setting value,
|
|
7
|
-
* onChange callback is called with latest value.
|
|
8
|
-
*
|
|
9
|
-
* @returns `[setValueDebounced]`
|
|
10
|
-
*/
|
|
11
|
-
export declare const useDebouncedOnChangeValue: <TValue>({ onChange, delay, }: {
|
|
12
|
-
onChange: (value: TValue) => void;
|
|
13
|
-
delay: number;
|
|
14
|
-
}) => readonly [(value: TValue) => void];
|
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
import { default as React } from 'react';
|
|
2
|
-
/**
|
|
3
|
-
* Create a ref and point forwarded ref to it.
|
|
4
|
-
*
|
|
5
|
-
* Use case: forwarded refs are optional, but sometimes you need the ref.
|
|
6
|
-
*
|
|
7
|
-
* @param forwardedRef Forwarded `ref` prop.
|
|
8
|
-
*/
|
|
9
|
-
export declare const useImperativeForwardedRef: <TRef>(forwardedRef?: React.ForwardedRef<TRef>) => React.RefObject<TRef | null>;
|
package/dist/dts/vite-env.d.ts
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
/// <reference types="vite/client" />
|
|
@@ -1,89 +0,0 @@
|
|
|
1
|
-
import e from "react";
|
|
2
|
-
import { jsx as t } from "react/jsx-runtime";
|
|
3
|
-
import { get as n, useFormState as r } from "react-hook-form";
|
|
4
|
-
import { flatten as i } from "flat";
|
|
5
|
-
//#region src/utils/createContext.ts
|
|
6
|
-
function a() {
|
|
7
|
-
let t = e.createContext(void 0), n = () => e.useContext(t);
|
|
8
|
-
return {
|
|
9
|
-
Provider: t.Provider,
|
|
10
|
-
useMaybe: n,
|
|
11
|
-
useRequired: () => {
|
|
12
|
-
let e = n();
|
|
13
|
-
if (e === void 0) throw Error();
|
|
14
|
-
return e;
|
|
15
|
-
}
|
|
16
|
-
};
|
|
17
|
-
}
|
|
18
|
-
//#endregion
|
|
19
|
-
//#region src/form/relay/context/useFormRelayContext.ts
|
|
20
|
-
var { Provider: o, useRequired: s } = a(), c = ({ children: n }) => {
|
|
21
|
-
let [r, i] = e.useState({});
|
|
22
|
-
return /* @__PURE__ */ t(o, {
|
|
23
|
-
value: {
|
|
24
|
-
add: e.useCallback((e, t, n) => {
|
|
25
|
-
if (r[t.formId]) throw Error("Form id already exists.");
|
|
26
|
-
i((r) => ({
|
|
27
|
-
...r,
|
|
28
|
-
[t.formId]: {
|
|
29
|
-
state: e,
|
|
30
|
-
utils: t,
|
|
31
|
-
options: n
|
|
32
|
-
}
|
|
33
|
-
}));
|
|
34
|
-
}, [r]),
|
|
35
|
-
update: e.useCallback((e, t) => {
|
|
36
|
-
i((n) => {
|
|
37
|
-
let r = n[e];
|
|
38
|
-
if (!r) throw Error("Form id doesn't exist");
|
|
39
|
-
return {
|
|
40
|
-
...n,
|
|
41
|
-
[e]: {
|
|
42
|
-
...r,
|
|
43
|
-
state: t
|
|
44
|
-
}
|
|
45
|
-
};
|
|
46
|
-
});
|
|
47
|
-
}, []),
|
|
48
|
-
remove: e.useCallback((e) => {
|
|
49
|
-
i((t) => Object.fromEntries(Object.entries(t).filter(([t]) => t !== e)));
|
|
50
|
-
}, []),
|
|
51
|
-
state: r
|
|
52
|
-
},
|
|
53
|
-
children: n
|
|
54
|
-
});
|
|
55
|
-
}, { Provider: l, useRequired: u, useMaybe: d } = a(), f = (e) => Object.keys(e).length === 0, p = (e) => i(e), m = (e) => {
|
|
56
|
-
let t = p(e);
|
|
57
|
-
return Object.fromEntries(Object.keys(t).reduce((t, r) => {
|
|
58
|
-
let i = r.replace(h, "");
|
|
59
|
-
if (i === r) return t;
|
|
60
|
-
let a = n(e, i, void 0);
|
|
61
|
-
return a && t.push([i, a]), t;
|
|
62
|
-
}, []));
|
|
63
|
-
}, h = /\.(?:type|message)\b$/, g = (e) => Object.fromEntries(Object.entries(m(e)).map(([e, t]) => [e, {
|
|
64
|
-
type: t.type,
|
|
65
|
-
message: t.message,
|
|
66
|
-
hasRef: !!t.ref
|
|
67
|
-
}])), _ = (t) => {
|
|
68
|
-
if (!t) return;
|
|
69
|
-
let [n] = e.useState(t);
|
|
70
|
-
v(n), y(n);
|
|
71
|
-
}, v = (t) => {
|
|
72
|
-
let n = u(), r = s(), i = b(t);
|
|
73
|
-
e.useEffect(() => (r.add(i, n, t), () => {
|
|
74
|
-
r.remove(n.formId);
|
|
75
|
-
}), []);
|
|
76
|
-
}, y = (t) => {
|
|
77
|
-
let n = u(), r = s(), i = b(t);
|
|
78
|
-
e.useEffect(() => {
|
|
79
|
-
r.update(n.formId, i);
|
|
80
|
-
}, [i]);
|
|
81
|
-
}, b = (t) => {
|
|
82
|
-
let n = r(), i = t.select(n), a = JSON.stringify({
|
|
83
|
-
...i,
|
|
84
|
-
errors: i.errors && g(i.errors)
|
|
85
|
-
});
|
|
86
|
-
return e.useMemo(() => i, [a]);
|
|
87
|
-
}, x = ({ options: e }) => (_(e), null);
|
|
88
|
-
//#endregion
|
|
89
|
-
export { l as a, c, f as i, s as l, _ as n, u as o, m as r, d as s, x as t, a as u };
|