@paragrav/rhf-utils 0.72.0 → 0.74.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 +83 -52
- package/dist/tsdown/{FormRelayOptions-k7OaoAqV.d.ts → FormRelayOptions-B5CknIkX.d.ts} +2 -3
- package/dist/tsdown/FormRelayOptions-B5CknIkX.d.ts.map +1 -0
- package/dist/tsdown/{FormRelaySetter-BKO0Wodf.js → FormRelaySetter-CLkDwgfH.js} +9 -4
- package/dist/tsdown/FormRelaySetter-CLkDwgfH.js.map +1 -0
- package/dist/tsdown/{RhfUtilsClientConfigType-BaedoEQY.d.ts → RhfUtilsClientConfigType-CRy_vYef.d.ts} +62 -12
- package/dist/tsdown/RhfUtilsClientConfigType-CRy_vYef.d.ts.map +1 -0
- package/dist/tsdown/{RhfUtilsContextType-DwlvEWjd.d.ts → RhfUtilsContextType-DBOvBnPF.d.ts} +12 -20
- package/dist/tsdown/RhfUtilsContextType-DBOvBnPF.d.ts.map +1 -0
- package/dist/tsdown/index.d.ts +29 -45
- package/dist/tsdown/index.d.ts.map +1 -1
- package/dist/tsdown/index.js +64 -43
- package/dist/tsdown/index.js.map +1 -1
- package/dist/tsdown/relay.d.ts +4 -4
- package/dist/tsdown/relay.d.ts.map +1 -1
- package/dist/tsdown/relay.js +1 -1
- package/dist/tsdown/trpc.d.ts +1 -2
- package/dist/tsdown/trpc.d.ts.map +1 -1
- package/package.json +21 -31
- package/dist/tsdown/FormRelayOptions-k7OaoAqV.d.ts.map +0 -1
- package/dist/tsdown/FormRelaySetter-BKO0Wodf.js.map +0 -1
- package/dist/tsdown/RhfUtilsClientConfigType-BaedoEQY.d.ts.map +0 -1
- package/dist/tsdown/RhfUtilsContextType-DwlvEWjd.d.ts.map +0 -1
package/dist/tsdown/index.d.ts
CHANGED
|
@@ -1,10 +1,9 @@
|
|
|
1
|
-
import { a as
|
|
2
|
-
import { a as UseRhfUtilsFormOnSubmitContext, c as FormSubmitFieldErrors, i as MaybePromise, l as
|
|
3
|
-
import { t as FormRelayOptions } from "./FormRelayOptions-
|
|
1
|
+
import { a as Register, i as RhfUtilsFormOptions, n as RhfUtilsContextProviderProps, r as SafeFieldValues, t as RhfUtilsContext } from "./RhfUtilsContextType-DBOvBnPF.js";
|
|
2
|
+
import { a as UseRhfUtilsFormOnSubmitContext, c as LastSubmitStatus, d as FormSubmitFieldErrors, f as RhfUseFormInstanceProps, i as MaybePromise, l as LastSubmitError, n as RhfUtilsClientConfigFormOutletProps, o as UseRhfUtilsFormOnSubmitErrorContext, p as useFlatFieldErrorsContext, r as _Controller, s as LastSubmitContextRead, t as RhfUtilsClientConfig, u as FormSubmitError } from "./RhfUtilsClientConfigType-CRy_vYef.js";
|
|
3
|
+
import { t as FormRelayOptions } from "./FormRelayOptions-B5CknIkX.js";
|
|
4
4
|
import React$1 from "react";
|
|
5
5
|
import { Resolver, SubmitErrorHandler, UseFormProps, UseFormReturn } from "react-hook-form";
|
|
6
6
|
import { z } from "zod";
|
|
7
|
-
|
|
8
7
|
//#region src/client/config/context/RhfUtilsClientConfigProvider.d.ts
|
|
9
8
|
type Props$4 = React$1.PropsWithChildren<{
|
|
10
9
|
config?: RhfUtilsClientConfig;
|
|
@@ -21,7 +20,8 @@ declare const useFlatFieldErrorsContextHasOnlyOrphans: () => boolean;
|
|
|
21
20
|
//#endregion
|
|
22
21
|
//#region src/errors/nonfield/RhfUtilsNonFieldErrorMarker.d.ts
|
|
23
22
|
type Props$3 = {
|
|
24
|
-
/** Flat field name. (e.g., `address.street`) */
|
|
23
|
+
/** Flat field name. (e.g., `address.street`) */
|
|
24
|
+
path: string;
|
|
25
25
|
};
|
|
26
26
|
/**
|
|
27
27
|
* Empty, hidden marker to indicate a non-field/non-root error is being displayed to user.
|
|
@@ -33,9 +33,7 @@ type Props$3 = {
|
|
|
33
33
|
declare const RhfUtilsNonFieldErrorMarker: React.FC<Props$3>;
|
|
34
34
|
//#endregion
|
|
35
35
|
//#region src/form/context/utils/useRhfUtilsContext.d.ts
|
|
36
|
-
declare const _RhfUtilsContextProvider: import("react").Provider<
|
|
37
|
-
lastSubmitStateRef: import("react").RefObject<LastSubmitState>;
|
|
38
|
-
}, useRhfUtilsMaybeContext: () => RhfUtilsContext | undefined;
|
|
36
|
+
declare const _RhfUtilsContextProvider: import("react").Provider<RhfUtilsContextProviderProps | undefined>, useRhfUtilsContext: () => RhfUtilsContextProviderProps, useRhfUtilsMaybeContext: () => RhfUtilsContextProviderProps | undefined;
|
|
39
37
|
//#endregion
|
|
40
38
|
//#region src/form/RHF_UseFormReturnWithoutProxiesType.d.ts
|
|
41
39
|
/**
|
|
@@ -65,8 +63,8 @@ type UseRhfUtilsFormChildrenProps<TFieldValues extends SafeFieldValues, TTransfo
|
|
|
65
63
|
FormSubmitError: typeof FormSubmitError<TFieldValues>;
|
|
66
64
|
} & {
|
|
67
65
|
onCancel?: () => MaybePromise<void>;
|
|
68
|
-
}
|
|
69
|
-
(TProps extends undefined ? {
|
|
66
|
+
} // cancel
|
|
67
|
+
& (TProps extends undefined ? {
|
|
70
68
|
props?: undefined;
|
|
71
69
|
} : {
|
|
72
70
|
props: TProps;
|
|
@@ -82,11 +80,10 @@ type UseRhfUtilsFormChildrenProps<TFieldValues extends SafeFieldValues, TTransfo
|
|
|
82
80
|
*/
|
|
83
81
|
declare const useFormRequestSubmit: (ref: React$1.RefObject<HTMLFormElement | null>) => HTMLFormElement["requestSubmit"];
|
|
84
82
|
//#endregion
|
|
85
|
-
//#region src/submit/last
|
|
86
|
-
declare const
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
} | undefined;
|
|
83
|
+
//#region src/submit/last/context/useLastSubmitContext.d.ts
|
|
84
|
+
declare const useLastSubmit: () => LastSubmitContextRead;
|
|
85
|
+
declare const useLastSubmitStatus: () => import("react").RefObject<LastSubmitStatus>;
|
|
86
|
+
declare const useLastSubmitError: () => LastSubmitError | undefined;
|
|
90
87
|
//#endregion
|
|
91
88
|
//#region src/form/defaults/form/UseRhfUtilsFormInstanceFormProps.d.ts
|
|
92
89
|
type DataAttributes = Record<`data-${string}`, string>;
|
|
@@ -106,9 +103,11 @@ type RhfUtilsFormPropsOnBeforeSubmitInvariants<TFieldValues extends SafeFieldVal
|
|
|
106
103
|
//#endregion
|
|
107
104
|
//#region src/form/with-handlers-and-children/RhfUtilsFormProps.d.ts
|
|
108
105
|
type RhfUtilsFormPropsGetApiValues<TTransformedValues extends SafeFieldValues, TApiValues> = (data: TTransformedValues) => TApiValues;
|
|
109
|
-
type RhfUtilsFormProps<TFieldValues extends SafeFieldValues, TTransformedValues extends SafeFieldValues, TGetApiValues extends undefined | RhfUtilsFormPropsGetApiValues<TTransformedValues, SafeFieldValues>, TOnSubmitReturnType, TApiValues extends undefined | SafeFieldValues =
|
|
110
|
-
getApiData?: TGetApiValues;
|
|
111
|
-
|
|
106
|
+
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> = {
|
|
107
|
+
getApiData?: TGetApiValues;
|
|
108
|
+
/** Cancellation handler -- channeled through {@link RhfUtilsClientConfig.useCanFormBeCancelled} before propagating to `Children` component. */
|
|
109
|
+
onCancel?: () => MaybePromise<void>;
|
|
110
|
+
/** Submit handler when form is invalid. */
|
|
112
111
|
onSubmitInvalid?: SubmitErrorHandler<TFieldValues>;
|
|
113
112
|
/**
|
|
114
113
|
* List of invariants to run against input/output/api data.
|
|
@@ -129,11 +128,13 @@ type RhfUtilsFormProps<TFieldValues extends SafeFieldValues, TTransformedValues
|
|
|
129
128
|
input: TFieldValues;
|
|
130
129
|
output: TTransformedValues;
|
|
131
130
|
api: TApiValues;
|
|
132
|
-
}, context: UseRhfUtilsFormOnSubmitContext<TFieldValues, TTransformedValues, TApiValues>, event: React.BaseSyntheticEvent<SubmitEvent>) => MaybePromise<unknown>;
|
|
131
|
+
}, context: UseRhfUtilsFormOnSubmitContext<TFieldValues, TTransformedValues, TApiValues>, event: React.BaseSyntheticEvent<SubmitEvent>) => MaybePromise<unknown>;
|
|
132
|
+
/** Submit error handler. (Only for errors not of instance `FormError`, which are handled internally.) */
|
|
133
133
|
onSubmitError?: (error: unknown, context: UseRhfUtilsFormOnSubmitErrorContext<TFieldValues, TTransformedValues>, event: React.BaseSyntheticEvent<SubmitEvent>) => void;
|
|
134
134
|
onSubmitFinally?: () => MaybePromise<void>;
|
|
135
135
|
Children: React.FC<UseRhfUtilsFormChildrenProps<TFieldValues, TTransformedValues>>;
|
|
136
|
-
form?: UseRhfUtilsFormInstanceFormProps;
|
|
136
|
+
form?: UseRhfUtilsFormInstanceFormProps;
|
|
137
|
+
/** Form class attribute. */
|
|
137
138
|
className?: string;
|
|
138
139
|
};
|
|
139
140
|
//#endregion
|
|
@@ -148,15 +149,16 @@ type ZodTypeOfSafeFieldValues = z.ZodType<SafeFieldValues, z.ZodObjectDef>;
|
|
|
148
149
|
type ZodTypeSafeFieldValues = ZodTypeOfSafeFieldValues | z.ZodEffects<ZodTypeOfSafeFieldValues>;
|
|
149
150
|
//#endregion
|
|
150
151
|
//#region src/resolvers/zod/form/RhfUtilsZodForm.d.ts
|
|
151
|
-
type Props$2<TSchema extends ZodTypeSafeFieldValues, TGetApiValues extends undefined | RhfUtilsFormPropsGetApiValues<TSchema[typeof zodTypeOutput], SafeFieldValues>, TOnSubmitReturnType, TApiValues extends undefined | SafeFieldValues =
|
|
152
|
-
declare const RhfUtilsZodForm: <TSchema extends ZodTypeSafeFieldValues, TGetApiValues extends undefined | RhfUtilsFormPropsGetApiValues<TSchema[typeof zodTypeOutput], SafeFieldValues>, TOnSubmitReturnType, TApiValues extends undefined | SafeFieldValues =
|
|
152
|
+
type Props$2<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>>;
|
|
153
|
+
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$2<TSchema, TGetApiValues, TOnSubmitReturnType, TApiValues>) => import("react").JSX.Element;
|
|
153
154
|
//#endregion
|
|
154
155
|
//#region src/form/providers/RhfUtilsFormProvidersPropsType.d.ts
|
|
155
156
|
/**
|
|
156
157
|
* RhfUtils form providers props.
|
|
157
158
|
*/
|
|
158
159
|
type RhfUtilsFormProvidersProps<TFieldValues extends SafeFieldValues, TTransformedValues extends SafeFieldValues> = {
|
|
159
|
-
/** Globally-unique form id. (Used in DOM. Auto-generated if not supplied.) */
|
|
160
|
+
/** Globally-unique form id. (Used in DOM. Auto-generated if not supplied.) */
|
|
161
|
+
formId?: string;
|
|
160
162
|
resolver?: Resolver<TFieldValues, unknown, TTransformedValues>;
|
|
161
163
|
rhf?: RhfUseFormInstanceProps<TFieldValues, TTransformedValues>;
|
|
162
164
|
defaultValues?: UseFormProps<TFieldValues, unknown, TTransformedValues>['defaultValues'];
|
|
@@ -168,20 +170,13 @@ type RhfUtilsFormProvidersProps<TFieldValues extends SafeFieldValues, TTransform
|
|
|
168
170
|
type Props$1<TSchema extends ZodTypeSafeFieldValues> = React.PropsWithChildren<{
|
|
169
171
|
schema: TSchema;
|
|
170
172
|
} & RhfUtilsFormProvidersProps<TSchema[typeof zodTypeInput], TSchema[typeof zodTypeOutput]>>;
|
|
171
|
-
declare const RhfUtilsZodFormProviders: <TSchema extends ZodTypeSafeFieldValues>({
|
|
172
|
-
schema,
|
|
173
|
-
children,
|
|
174
|
-
...props
|
|
175
|
-
}: Props$1<TSchema>) => import("react").JSX.Element;
|
|
173
|
+
declare const RhfUtilsZodFormProviders: <TSchema extends ZodTypeSafeFieldValues>({ schema, children, ...props }: Props$1<TSchema>) => import("react").JSX.Element;
|
|
176
174
|
//#endregion
|
|
177
175
|
//#region src/resolvers/zod/with-providers/RhfUtilsZodFormWithProviders.d.ts
|
|
178
|
-
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 =
|
|
176
|
+
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<{
|
|
179
177
|
schema: TSchema;
|
|
180
178
|
} & Omit<RhfUtilsFormProvidersProps<TFieldValues, TTransformedValues>, 'resolver'> & RhfUtilsFormProps<TFieldValues, TTransformedValues, TGetApiValues, TOnSubmitReturnType, TApiValues>>;
|
|
181
|
-
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 =
|
|
182
|
-
schema,
|
|
183
|
-
...props
|
|
184
|
-
}: Props<TSchema, TGetApiValues, TOnSubmitReturnType, TFieldValues, TTransformedValues, TApiValues>) => import("react").JSX.Element;
|
|
179
|
+
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;
|
|
185
180
|
//#endregion
|
|
186
181
|
//#region src/resolvers/zod/RhfUtilsUseZodFormChildrenPropsType.d.ts
|
|
187
182
|
type RhfUtilsUseZodFormChildrenProps<TSchema extends ZodTypeSafeFieldValues, TChildrenProps = undefined> = UseRhfUtilsFormChildrenProps<TSchema[typeof zodTypeInput], TSchema[typeof zodTypeOutput], TChildrenProps>;
|
|
@@ -192,16 +187,5 @@ type RhfUtilsUseZodFormChildrenProps<TSchema extends ZodTypeSafeFieldValues, TCh
|
|
|
192
187
|
*/
|
|
193
188
|
type RhfUtilsUseZodFormChildrenFC<TSchema extends ZodTypeSafeFieldValues, TChildrenProps = undefined> = React$1.FC<RhfUtilsUseZodFormChildrenProps<TSchema, TChildrenProps>>;
|
|
194
189
|
//#endregion
|
|
195
|
-
|
|
196
|
-
/**
|
|
197
|
-
* @license @paragrav/rhf-utils
|
|
198
|
-
*
|
|
199
|
-
* Copyright (c) 2024-present paragrav.dev
|
|
200
|
-
*
|
|
201
|
-
* This source code is licensed under the MIT license found in the
|
|
202
|
-
* LICENSE file in the root directory of this source tree.
|
|
203
|
-
*/
|
|
204
|
-
|
|
205
|
-
//#endregion
|
|
206
|
-
export { FormSubmitError, type FormSubmitFieldErrors, type Register, type RhfUtilsClientConfig, RhfUtilsClientConfigProvider, type RhfUtilsFormInjectorProps, type RhfUtilsFormOptions, RhfUtilsNonFieldErrorMarker, type RhfUtilsUseZodFormChildrenFC, type RhfUtilsUseZodFormChildrenProps, RhfUtilsZodForm, RhfUtilsZodFormProviders, RhfUtilsZodFormWithProviders, type SafeFieldValues, type RHF_UseFormReturnWithoutProxies as UseFormReturnWithoutProxies, type UseRhfUtilsFormChildrenProps, type UseRhfUtilsFormOnSubmitContext, type UseRhfUtilsFormOnSubmitErrorContext, type ZodTypeSafeFieldValues, useFlatFieldErrorsContext, useFlatFieldErrorsContextHasOnlyOrphans, useFormRequestSubmit, useLastSubmitError, useRhfUtilsContext };
|
|
190
|
+
export { FormSubmitError, type FormSubmitFieldErrors, type Register, type RhfUtilsClientConfig, type RhfUtilsClientConfigFormOutletProps, RhfUtilsClientConfigProvider, type RhfUtilsFormOptions, RhfUtilsNonFieldErrorMarker, type RhfUtilsUseZodFormChildrenFC, type RhfUtilsUseZodFormChildrenProps, RhfUtilsZodForm, RhfUtilsZodFormProviders, RhfUtilsZodFormWithProviders, type SafeFieldValues, type RHF_UseFormReturnWithoutProxies as UseFormReturnWithoutProxies, type UseRhfUtilsFormChildrenProps, type UseRhfUtilsFormOnSubmitContext, type UseRhfUtilsFormOnSubmitErrorContext, type ZodTypeSafeFieldValues, useFlatFieldErrorsContext, useFlatFieldErrorsContextHasOnlyOrphans, useFormRequestSubmit, useLastSubmit, useLastSubmitError, useLastSubmitStatus, useRhfUtilsContext };
|
|
207
191
|
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","names":[],"sources":["../../src/client/config/context/RhfUtilsClientConfigProvider.tsx","../../src/errors/flat/context/useFlatFieldErrorsContextHasOnlyOrphans.ts","../../src/errors/nonfield/RhfUtilsNonFieldErrorMarker.tsx","../../src/form/context/utils/useRhfUtilsContext.tsx","../../src/form/RHF_UseFormReturnWithoutProxiesType.ts","../../src/form/UseRhfUtilsFormChildrenPropsType.ts","../../src/form/utils/useFormRequestSubmit.ts","../../src/submit/last
|
|
1
|
+
{"version":3,"file":"index.d.ts","names":[],"sources":["../../src/client/config/context/RhfUtilsClientConfigProvider.tsx","../../src/errors/flat/context/useFlatFieldErrorsContextHasOnlyOrphans.ts","../../src/errors/nonfield/RhfUtilsNonFieldErrorMarker.tsx","../../src/form/context/utils/useRhfUtilsContext.tsx","../../src/form/RHF_UseFormReturnWithoutProxiesType.ts","../../src/form/UseRhfUtilsFormChildrenPropsType.ts","../../src/form/utils/useFormRequestSubmit.ts","../../src/submit/last/context/useLastSubmitContext.ts","../../src/form/defaults/form/UseRhfUtilsFormInstanceFormProps.ts","../../src/form/with-handlers-and-children/RhfUtilsFormPropsOnBeforeSubmitInvariants.ts","../../src/form/with-handlers-and-children/RhfUtilsFormProps.ts","../../src/resolvers/zod/consts.ts","../../src/resolvers/zod/ZodTypeSafeFieldValuesType.ts","../../src/resolvers/zod/form/RhfUtilsZodForm.tsx","../../src/form/providers/RhfUtilsFormProvidersPropsType.ts","../../src/resolvers/zod/providers/RhfUtilsZodFormProviders.tsx","../../src/resolvers/zod/with-providers/RhfUtilsZodFormWithProviders.tsx","../../src/resolvers/zod/RhfUtilsUseZodFormChildrenPropsType.ts","../../src/resolvers/zod/RhfUtilsUseZodFormChildrenFCType.ts"],"mappings":";;;;;;;KAQK,UAAQ,QAAM;EACjB,SAAS;;cAGE,8BAA8B,QAAM,GAAG;;;;;;;;cCHvC;;;KCPR;;EAEH;;;;;;;;;cAUW,6BAA6B,MAAM,GAAG;;;cCTvC,0CAAwB,SAEx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2B,cAAc,mCAI3C,kBACE,cACA,oBACA,eACA,qBACA;cAIO,+BACX,gBAAgB,wBAChB,kCAEI,8BAA8B,oBAAoB,kBACtD,qBACA,qBAAqB,eAAe,gBAClC,eAAe,eACjB,2BAA2B,eAAe,iBACxC,eAAe,gBACjB,+BAA+B,kBAC7B,sBAAsB,8BACpB,0BACM,KAEJ,iBAEN,WAAA,SAGC,MACD,SACA,eACA,qBACA,cACA,oBACA,gCACD,IAAA;;;KCpEW,gCACV,gBAAgB,wBAChB,8BACE,6BACF,eAAe,eACf,eAAe,gBACf;;;;;;KCHU,6BACV,gBAAgB,wBAChB,8BACE,QAAM,GAAG,gCAAgC,SAAS"}
|
package/dist/tsdown/index.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { a as _RhfUtilsContextProvider, c as FormRelayContextProvider, i as isEmptyObject, o as useRhfUtilsContext, r as getFlatFieldErrors, t as FormRelaySetter, u as createContext } from "./FormRelaySetter-
|
|
1
|
+
import { a as _RhfUtilsContextProvider, c as FormRelayContextProvider, i as isEmptyObject, o as useRhfUtilsContext, r as getFlatFieldErrors, t as FormRelaySetter, u as createContext } from "./FormRelaySetter-CLkDwgfH.js";
|
|
2
2
|
import React from "react";
|
|
3
3
|
import { jsx, jsxs } from "react/jsx-runtime";
|
|
4
4
|
import { Controller, FormProvider, useForm, useFormContext, useFormState, useWatch } from "react-hook-form";
|
|
@@ -81,11 +81,17 @@ var FormSubmitError = class extends Error {
|
|
|
81
81
|
}
|
|
82
82
|
};
|
|
83
83
|
//#endregion
|
|
84
|
-
//#region src/submit/last
|
|
85
|
-
const { Provider:
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
84
|
+
//#region src/submit/last/context/useLastSubmitContext.ts
|
|
85
|
+
const { Provider: _LastSubmitContextProvider, useRequired: _useLastSubmitContext } = createContext();
|
|
86
|
+
const useLastSubmit = () => {
|
|
87
|
+
const lastSubmit = _useLastSubmitContext();
|
|
88
|
+
return {
|
|
89
|
+
statusRef: lastSubmit.status.ref,
|
|
90
|
+
error: lastSubmit.error.state
|
|
91
|
+
};
|
|
92
|
+
};
|
|
93
|
+
const useLastSubmitStatus = () => useLastSubmit().statusRef;
|
|
94
|
+
const useLastSubmitError = () => useLastSubmit().error;
|
|
89
95
|
//#endregion
|
|
90
96
|
//#region src/devtool/LazyDevTool.tsx
|
|
91
97
|
const LazyRhfDevTool = React.lazy(() => import("@hookform/devtools").then((res) => ({ default: res.DevTool })));
|
|
@@ -118,6 +124,7 @@ const useRhfUtilsClientConfig = () => {
|
|
|
118
124
|
const useRhfUtilsFormOnSubmitContext = () => {
|
|
119
125
|
return {
|
|
120
126
|
utils: useRhfUtilsContext(),
|
|
127
|
+
lastSubmit: useLastSubmit(),
|
|
121
128
|
rhf: useFormContext(),
|
|
122
129
|
FormSubmitError
|
|
123
130
|
};
|
|
@@ -126,11 +133,12 @@ const useRhfUtilsFormOnSubmitContext = () => {
|
|
|
126
133
|
//#region src/form/utils/useHandleCancelWithCheckIfCanBe.ts
|
|
127
134
|
const useHandleCancelWithCheckIfCanBe = (onCancel, useCanFormBeCancelled, formOnSubmitContext) => {
|
|
128
135
|
const canFormBeCancelled = useCanFormBeCancelled?.();
|
|
129
|
-
|
|
136
|
+
const handleCancelWithCheck = async () => {
|
|
130
137
|
if (!onCancel) return;
|
|
131
138
|
if (await Promise.resolve(canFormBeCancelled?.(formOnSubmitContext)) === false) return;
|
|
132
139
|
return Promise.resolve(onCancel());
|
|
133
140
|
};
|
|
141
|
+
return handleCancelWithCheck;
|
|
134
142
|
};
|
|
135
143
|
//#endregion
|
|
136
144
|
//#region src/form/utils/useHandleCancelWithCheckIfCanBeViaProviders.ts
|
|
@@ -186,15 +194,15 @@ const useRhfUtilsFormResolvedFormProps = (formProps, id, surfaced) => {
|
|
|
186
194
|
};
|
|
187
195
|
};
|
|
188
196
|
//#endregion
|
|
189
|
-
//#region src/submit/last
|
|
197
|
+
//#region src/submit/last/context/useLastSubmitErrorContextWith.ts
|
|
190
198
|
const useLastSubmitErrorContextWith = (handleSubmit) => {
|
|
191
|
-
const ctx =
|
|
199
|
+
const ctx = _useLastSubmitContext();
|
|
192
200
|
return async function(event) {
|
|
193
201
|
try {
|
|
194
|
-
ctx.reset();
|
|
202
|
+
ctx.error.reset();
|
|
195
203
|
return await handleSubmit(event);
|
|
196
204
|
} catch (error) {
|
|
197
|
-
ctx.set(error, event);
|
|
205
|
+
ctx.error.set(error, event);
|
|
198
206
|
throw error;
|
|
199
207
|
}
|
|
200
208
|
};
|
|
@@ -203,15 +211,16 @@ const useLastSubmitErrorContextWith = (handleSubmit) => {
|
|
|
203
211
|
//#region src/form/with-handlers-and-children/_useHandleSubmit.ts
|
|
204
212
|
const useRhfUtilsFormHandleSubmit_Internal = ({ onValid, onInvalid, onError, onFinally }) => {
|
|
205
213
|
const rhfContext = useFormContext();
|
|
206
|
-
const { options
|
|
214
|
+
const { options } = useRhfUtilsContext();
|
|
215
|
+
const lastSubmitStatusRef = useLastSubmitStatus();
|
|
207
216
|
const handleSubmitWithLastSubmitError = useLastSubmitErrorContextWith(rhfContext.handleSubmit(onValid, onInvalid));
|
|
208
217
|
return (event) => {
|
|
209
|
-
|
|
218
|
+
lastSubmitStatusRef.current = "submitting";
|
|
210
219
|
if (options.stopSubmitPropagation) event.stopPropagation();
|
|
211
220
|
Promise.resolve(handleSubmitWithLastSubmitError(event)).then(() => {
|
|
212
|
-
|
|
221
|
+
lastSubmitStatusRef.current = "success";
|
|
213
222
|
}).catch((error) => {
|
|
214
|
-
|
|
223
|
+
lastSubmitStatusRef.current = "error";
|
|
215
224
|
onError(error, event);
|
|
216
225
|
}).finally(() => {
|
|
217
226
|
onFinally?.();
|
|
@@ -224,6 +233,7 @@ const RhfUtilsFormWithSubmitHandler_Internal = ({ getApiData, onSubmitInvalid, o
|
|
|
224
233
|
const rhfContext = useFormContext();
|
|
225
234
|
const utils = useRhfUtilsContext();
|
|
226
235
|
const config = useRhfUtilsClientConfig();
|
|
236
|
+
const lastSubmit = useLastSubmit();
|
|
227
237
|
const resolvedFormProps = useRhfUtilsFormResolvedFormProps(form, utils.formId, { className });
|
|
228
238
|
const handleSubmitValid = async (data, event) => {
|
|
229
239
|
const datas = {
|
|
@@ -231,23 +241,25 @@ const RhfUtilsFormWithSubmitHandler_Internal = ({ getApiData, onSubmitInvalid, o
|
|
|
231
241
|
output: data,
|
|
232
242
|
api: getApiData?.(data)
|
|
233
243
|
};
|
|
234
|
-
const
|
|
244
|
+
const onSubmitContext = {
|
|
235
245
|
utils,
|
|
246
|
+
lastSubmit,
|
|
236
247
|
rhf: rhfContext,
|
|
237
248
|
FormSubmitError
|
|
238
249
|
};
|
|
239
250
|
const submitEvent = event;
|
|
240
|
-
if (onBeforeSubmitInvariants) await handleOnSubmitInvariants(onBeforeSubmitInvariants, datas,
|
|
241
|
-
await Promise.resolve(onBeforeSubmit?.(datas,
|
|
242
|
-
const submitResponse = await Promise.resolve(onSubmit?.(datas,
|
|
243
|
-
|
|
244
|
-
await Promise.resolve(onSubmitSuccess?.(submitResponse, datas,
|
|
251
|
+
if (onBeforeSubmitInvariants) await handleOnSubmitInvariants(onBeforeSubmitInvariants, datas, onSubmitContext, submitEvent);
|
|
252
|
+
await Promise.resolve(onBeforeSubmit?.(datas, onSubmitContext, submitEvent));
|
|
253
|
+
const submitResponse = await Promise.resolve(onSubmit?.(datas, onSubmitContext, submitEvent));
|
|
254
|
+
lastSubmit.statusRef.current = "success";
|
|
255
|
+
await Promise.resolve(onSubmitSuccess?.(submitResponse, datas, onSubmitContext, submitEvent));
|
|
245
256
|
};
|
|
246
257
|
function handleSubmitError(error, event) {
|
|
247
258
|
const formSubmitErrors = error instanceof FormSubmitError ? error.errors : config.onSubmitErrorUnknown?.(error);
|
|
248
259
|
if (formSubmitErrors) setCtxErrorsByFormSubmitFieldErrors(rhfContext, formSubmitErrors);
|
|
249
260
|
onSubmitError?.(error, {
|
|
250
261
|
utils,
|
|
262
|
+
lastSubmit,
|
|
251
263
|
errors: formSubmitErrors,
|
|
252
264
|
rhf: rhfContext
|
|
253
265
|
}, event);
|
|
@@ -260,19 +272,25 @@ const RhfUtilsFormWithSubmitHandler_Internal = ({ getApiData, onSubmitInvalid, o
|
|
|
260
272
|
});
|
|
261
273
|
const Outlet = React.useCallback(() => children, []);
|
|
262
274
|
/** FormComponent props -- general, non-form-, non-schema-specific. */
|
|
263
|
-
const
|
|
275
|
+
const formHooksProps = {
|
|
264
276
|
...utils,
|
|
265
277
|
rhf: rhfContext,
|
|
278
|
+
lastSubmit
|
|
279
|
+
};
|
|
280
|
+
config.useFormHooks?.(formHooksProps);
|
|
281
|
+
/** FormComponent props -- general, non-form-, non-schema-specific. */
|
|
282
|
+
const formInjectorProps = {
|
|
283
|
+
...formHooksProps,
|
|
284
|
+
Outlet,
|
|
266
285
|
Controller: _Controller,
|
|
267
|
-
FormSubmitError
|
|
268
|
-
Outlet
|
|
286
|
+
FormSubmitError
|
|
269
287
|
};
|
|
270
288
|
return /* @__PURE__ */ jsx(config.FormComponent ?? "form", {
|
|
271
289
|
...resolvedFormProps,
|
|
272
290
|
id: utils.formId,
|
|
273
291
|
ref: utils.formRef,
|
|
274
292
|
onSubmit: handleSubmit,
|
|
275
|
-
children: config.
|
|
293
|
+
children: config.FormOutlet ? /* @__PURE__ */ jsx(config.FormOutlet, { ...formInjectorProps }) : children
|
|
276
294
|
});
|
|
277
295
|
};
|
|
278
296
|
const handleOnSubmitInvariants = async (onBeforeSubmitInvariants, data, context, event) => {
|
|
@@ -395,20 +413,23 @@ const FlatFieldErrorsContextProvider = ({ formRef, children }) => {
|
|
|
395
413
|
});
|
|
396
414
|
};
|
|
397
415
|
//#endregion
|
|
398
|
-
//#region src/submit/last
|
|
399
|
-
const
|
|
400
|
-
const [
|
|
401
|
-
return /* @__PURE__ */ jsx(
|
|
416
|
+
//#region src/submit/last/context/LastSubmitContextProvider.tsx
|
|
417
|
+
const LastSubmitContextProvider = ({ children }) => {
|
|
418
|
+
const [error, setError] = React.useState();
|
|
419
|
+
return /* @__PURE__ */ jsx(_LastSubmitContextProvider, {
|
|
402
420
|
value: {
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
421
|
+
status: { ref: React.useRef(null) },
|
|
422
|
+
error: {
|
|
423
|
+
state: error,
|
|
424
|
+
reset: () => {
|
|
425
|
+
setError(void 0);
|
|
426
|
+
},
|
|
427
|
+
set: (error, event) => {
|
|
428
|
+
setError({
|
|
429
|
+
error,
|
|
430
|
+
event
|
|
431
|
+
});
|
|
432
|
+
}
|
|
412
433
|
}
|
|
413
434
|
},
|
|
414
435
|
children
|
|
@@ -492,7 +513,8 @@ const useResetFormOnSubmitted = (options) => {
|
|
|
492
513
|
const whichValues = options[success ? "success" : "error"]?.values;
|
|
493
514
|
if (!whichValues) return;
|
|
494
515
|
const keepValues = whichValues === "current";
|
|
495
|
-
|
|
516
|
+
const values = keepValues ? getValues() : void 0;
|
|
517
|
+
reset(values, {
|
|
496
518
|
keepIsSubmitSuccessful: true,
|
|
497
519
|
keepIsSubmitted: true,
|
|
498
520
|
keepSubmitCount: true,
|
|
@@ -627,8 +649,7 @@ const RhfUtilsContextProvider = ({ formId, formRef, options, children }) => {
|
|
|
627
649
|
value: {
|
|
628
650
|
formId,
|
|
629
651
|
formRef,
|
|
630
|
-
options
|
|
631
|
-
lastSubmitStateRef: React.useRef(null)
|
|
652
|
+
options
|
|
632
653
|
},
|
|
633
654
|
children
|
|
634
655
|
});
|
|
@@ -676,7 +697,7 @@ function RhfUtilsFormProviders({ formId, rhf, resolver, defaultValues, options,
|
|
|
676
697
|
formId: id,
|
|
677
698
|
formRef,
|
|
678
699
|
options: resolvedOptions,
|
|
679
|
-
children: [/* @__PURE__ */ jsx(FormRelaySetter, { options: relay }), /* @__PURE__ */ jsx(
|
|
700
|
+
children: [/* @__PURE__ */ jsx(FormRelaySetter, { options: relay }), /* @__PURE__ */ jsx(LastSubmitContextProvider, { children })]
|
|
680
701
|
})
|
|
681
702
|
})
|
|
682
703
|
});
|
|
@@ -742,6 +763,6 @@ const RhfUtilsZodFormWithProviders = ({ schema, ...props }) => /* @__PURE__ */ j
|
|
|
742
763
|
* LICENSE file in the root directory of this source tree.
|
|
743
764
|
*/
|
|
744
765
|
//#endregion
|
|
745
|
-
export { FormSubmitError, RhfUtilsClientConfigProvider, RhfUtilsNonFieldErrorMarker, RhfUtilsZodForm, RhfUtilsZodFormProviders, RhfUtilsZodFormWithProviders, useFlatFieldErrorsContext, useFlatFieldErrorsContextHasOnlyOrphans, useFormRequestSubmit, useLastSubmitError, useRhfUtilsContext };
|
|
766
|
+
export { FormSubmitError, RhfUtilsClientConfigProvider, RhfUtilsNonFieldErrorMarker, RhfUtilsZodForm, RhfUtilsZodFormProviders, RhfUtilsZodFormWithProviders, useFlatFieldErrorsContext, useFlatFieldErrorsContextHasOnlyOrphans, useFormRequestSubmit, useLastSubmit, useLastSubmitError, useLastSubmitStatus, useRhfUtilsContext };
|
|
746
767
|
|
|
747
768
|
//# sourceMappingURL=index.js.map
|