@tanstack/react-form 1.23.9 → 1.26.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/dist/cjs/createFormHook.cjs +1 -0
- package/dist/cjs/createFormHook.cjs.map +1 -1
- package/dist/cjs/index.cjs +0 -2
- package/dist/cjs/index.cjs.map +1 -1
- package/dist/cjs/index.d.cts +0 -1
- package/dist/cjs/types.d.cts +2 -1
- package/dist/cjs/useField.cjs +6 -3
- package/dist/cjs/useField.cjs.map +1 -1
- package/dist/cjs/useFieldGroup.cjs +1 -0
- package/dist/cjs/useFieldGroup.cjs.map +1 -1
- package/dist/cjs/useForm.cjs +1 -0
- package/dist/cjs/useForm.cjs.map +1 -1
- package/dist/esm/createFormHook.js +1 -0
- package/dist/esm/createFormHook.js.map +1 -1
- package/dist/esm/index.d.ts +0 -1
- package/dist/esm/index.js +1 -3
- package/dist/esm/index.js.map +1 -1
- package/dist/esm/types.d.ts +2 -1
- package/dist/esm/useField.js +7 -4
- package/dist/esm/useField.js.map +1 -1
- package/dist/esm/useFieldGroup.js +1 -0
- package/dist/esm/useFieldGroup.js.map +1 -1
- package/dist/esm/useForm.js +1 -0
- package/dist/esm/useForm.js.map +1 -1
- package/package.json +4 -38
- package/src/createFormHook.tsx +1 -0
- package/src/index.ts +0 -1
- package/src/types.ts +21 -0
- package/src/useField.tsx +15 -4
- package/src/useFieldGroup.tsx +2 -0
- package/src/useForm.tsx +2 -0
- package/dist/cjs/nextjs/createServerValidate.cjs +0 -51
- package/dist/cjs/nextjs/createServerValidate.cjs.map +0 -1
- package/dist/cjs/nextjs/createServerValidate.d.cts +0 -9
- package/dist/cjs/nextjs/error.cjs +0 -11
- package/dist/cjs/nextjs/error.cjs.map +0 -1
- package/dist/cjs/nextjs/error.d.cts +0 -10
- package/dist/cjs/nextjs/index.cjs +0 -15
- package/dist/cjs/nextjs/index.cjs.map +0 -1
- package/dist/cjs/nextjs/index.d.cts +0 -4
- package/dist/cjs/nextjs/types.d.cts +0 -2
- package/dist/cjs/remix/createServerValidate.cjs +0 -51
- package/dist/cjs/remix/createServerValidate.cjs.map +0 -1
- package/dist/cjs/remix/createServerValidate.d.cts +0 -9
- package/dist/cjs/remix/error.cjs +0 -11
- package/dist/cjs/remix/error.cjs.map +0 -1
- package/dist/cjs/remix/error.d.cts +0 -10
- package/dist/cjs/remix/index.cjs +0 -15
- package/dist/cjs/remix/index.cjs.map +0 -1
- package/dist/cjs/remix/index.d.cts +0 -4
- package/dist/cjs/remix/types.d.cts +0 -2
- package/dist/cjs/start/createServerValidate.cjs +0 -53
- package/dist/cjs/start/createServerValidate.cjs.map +0 -1
- package/dist/cjs/start/createServerValidate.d.cts +0 -7
- package/dist/cjs/start/error.cjs +0 -12
- package/dist/cjs/start/error.cjs.map +0 -1
- package/dist/cjs/start/error.d.cts +0 -12
- package/dist/cjs/start/getFormData.cjs +0 -18
- package/dist/cjs/start/getFormData.cjs.map +0 -1
- package/dist/cjs/start/getFormData.d.cts +0 -13
- package/dist/cjs/start/index.cjs +0 -10
- package/dist/cjs/start/index.cjs.map +0 -1
- package/dist/cjs/start/index.d.cts +0 -4
- package/dist/cjs/start/types.d.cts +0 -2
- package/dist/cjs/start/utils.cjs +0 -21
- package/dist/cjs/start/utils.cjs.map +0 -1
- package/dist/cjs/start/utils.d.cts +0 -3
- package/dist/cjs/useTransform.cjs +0 -10
- package/dist/cjs/useTransform.cjs.map +0 -1
- package/dist/cjs/useTransform.d.cts +0 -2
- package/dist/esm/nextjs/createServerValidate.d.ts +0 -9
- package/dist/esm/nextjs/createServerValidate.js +0 -51
- package/dist/esm/nextjs/createServerValidate.js.map +0 -1
- package/dist/esm/nextjs/error.d.ts +0 -10
- package/dist/esm/nextjs/error.js +0 -11
- package/dist/esm/nextjs/error.js.map +0 -1
- package/dist/esm/nextjs/index.d.ts +0 -4
- package/dist/esm/nextjs/index.js +0 -9
- package/dist/esm/nextjs/index.js.map +0 -1
- package/dist/esm/nextjs/types.d.ts +0 -2
- package/dist/esm/remix/createServerValidate.d.ts +0 -9
- package/dist/esm/remix/createServerValidate.js +0 -51
- package/dist/esm/remix/createServerValidate.js.map +0 -1
- package/dist/esm/remix/error.d.ts +0 -10
- package/dist/esm/remix/error.js +0 -11
- package/dist/esm/remix/error.js.map +0 -1
- package/dist/esm/remix/index.d.ts +0 -4
- package/dist/esm/remix/index.js +0 -9
- package/dist/esm/remix/index.js.map +0 -1
- package/dist/esm/remix/types.d.ts +0 -2
- package/dist/esm/start/createServerValidate.d.ts +0 -7
- package/dist/esm/start/createServerValidate.js +0 -53
- package/dist/esm/start/createServerValidate.js.map +0 -1
- package/dist/esm/start/error.d.ts +0 -12
- package/dist/esm/start/error.js +0 -12
- package/dist/esm/start/error.js.map +0 -1
- package/dist/esm/start/getFormData.d.ts +0 -13
- package/dist/esm/start/getFormData.js +0 -18
- package/dist/esm/start/getFormData.js.map +0 -1
- package/dist/esm/start/index.d.ts +0 -4
- package/dist/esm/start/index.js +0 -10
- package/dist/esm/start/index.js.map +0 -1
- package/dist/esm/start/types.d.ts +0 -2
- package/dist/esm/start/utils.d.ts +0 -3
- package/dist/esm/start/utils.js +0 -21
- package/dist/esm/start/utils.js.map +0 -1
- package/dist/esm/useTransform.d.ts +0 -2
- package/dist/esm/useTransform.js +0 -10
- package/dist/esm/useTransform.js.map +0 -1
- package/src/nextjs/createServerValidate.ts +0 -134
- package/src/nextjs/error.ts +0 -25
- package/src/nextjs/index.ts +0 -5
- package/src/nextjs/types.ts +0 -21
- package/src/remix/createServerValidate.ts +0 -134
- package/src/remix/error.ts +0 -25
- package/src/remix/index.ts +0 -5
- package/src/remix/types.ts +0 -21
- package/src/start/createServerValidate.tsx +0 -138
- package/src/start/error.ts +0 -28
- package/src/start/getFormData.tsx +0 -22
- package/src/start/index.ts +0 -4
- package/src/start/types.ts +0 -21
- package/src/start/utils.ts +0 -23
- package/src/useTransform.ts +0 -17
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"createServerValidate.js","sources":["../../../src/start/createServerValidate.tsx"],"sourcesContent":["import {\n isGlobalFormValidationError,\n isStandardSchemaValidator,\n standardSchemaValidators,\n} from '@tanstack/form-core'\nimport { getHeader } from '@tanstack/react-start/server'\nimport { decode } from 'decode-formdata'\nimport { ServerValidateError } from './error'\nimport { setInternalTanStackCookie } from './utils'\nimport type { ServerFormState } from './types'\nimport type {\n FormAsyncValidateOrFn,\n FormOptions,\n FormValidateAsyncFn,\n FormValidateOrFn,\n UnwrapFormAsyncValidateOrFn,\n} from '@tanstack/form-core'\n\ninterface CreateServerValidateOptions<\n TFormData,\n TOnMount extends undefined | FormValidateOrFn<TFormData>,\n TOnChange extends undefined | FormValidateOrFn<TFormData>,\n TOnChangeAsync extends undefined | FormAsyncValidateOrFn<TFormData>,\n TOnBlur extends undefined | FormValidateOrFn<TFormData>,\n TOnBlurAsync extends undefined | FormAsyncValidateOrFn<TFormData>,\n TOnSubmit extends undefined | FormValidateOrFn<TFormData>,\n TOnSubmitAsync extends undefined | FormAsyncValidateOrFn<TFormData>,\n TOnDynamic extends undefined | FormValidateOrFn<TFormData>,\n TOnDynamicAsync extends undefined | FormAsyncValidateOrFn<TFormData>,\n TOnServer extends undefined | FormAsyncValidateOrFn<TFormData>,\n TSubmitMeta,\n> extends FormOptions<\n TFormData,\n TOnMount,\n TOnChange,\n TOnChangeAsync,\n TOnBlur,\n TOnBlurAsync,\n TOnSubmit,\n TOnSubmitAsync,\n TOnDynamic,\n TOnDynamicAsync,\n TOnServer,\n TSubmitMeta\n > {\n onServerValidate: TOnServer\n}\n\nexport const createServerValidate =\n <\n TFormData,\n TOnMount extends undefined | FormValidateOrFn<TFormData>,\n TOnChange extends undefined | FormValidateOrFn<TFormData>,\n TOnChangeAsync extends undefined | FormAsyncValidateOrFn<TFormData>,\n TOnBlur extends undefined | FormValidateOrFn<TFormData>,\n TOnBlurAsync extends undefined | FormAsyncValidateOrFn<TFormData>,\n TOnSubmit extends undefined | FormValidateOrFn<TFormData>,\n TOnSubmitAsync extends undefined | FormAsyncValidateOrFn<TFormData>,\n TOnDynamic extends undefined | FormValidateOrFn<TFormData>,\n TOnDynamicAsync extends undefined | FormAsyncValidateOrFn<TFormData>,\n TOnServer extends undefined | FormAsyncValidateOrFn<TFormData>,\n TSubmitMeta,\n >(\n defaultOpts: CreateServerValidateOptions<\n TFormData,\n TOnMount,\n TOnChange,\n TOnChangeAsync,\n TOnBlur,\n TOnBlurAsync,\n TOnSubmit,\n TOnSubmitAsync,\n TOnDynamic,\n TOnDynamicAsync,\n TOnServer,\n TSubmitMeta\n >,\n ) =>\n async (formData: FormData, info?: Parameters<typeof decode>[1]) => {\n const { onServerValidate } = defaultOpts\n\n const runValidator = async ({\n value,\n validationSource,\n }: {\n value: TFormData\n validationSource: 'form'\n }) => {\n if (isStandardSchemaValidator(onServerValidate)) {\n return await standardSchemaValidators.validateAsync(\n { value, validationSource },\n onServerValidate,\n )\n }\n return (onServerValidate as FormValidateAsyncFn<TFormData>)({\n value,\n signal: undefined as never,\n formApi: undefined as never,\n })\n }\n\n const referer = getHeader('referer')!\n\n const data = decode(formData, info) as never as TFormData\n\n const onServerError = (await runValidator({\n value: data,\n validationSource: 'form',\n })) as UnwrapFormAsyncValidateOrFn<TOnServer> | undefined\n\n if (!onServerError) return data\n\n const onServerErrorVal = (\n isGlobalFormValidationError(onServerError)\n ? onServerError.form\n : onServerError\n ) as UnwrapFormAsyncValidateOrFn<TOnServer>\n\n const formState: ServerFormState<TFormData, TOnServer> = {\n errorMap: {\n onServer: onServerError,\n },\n values: data,\n errors: onServerErrorVal ? [onServerErrorVal] : [],\n }\n\n setInternalTanStackCookie(formState)\n\n throw new ServerValidateError({\n response: new Response('ok', {\n headers: {\n Location: referer,\n },\n status: 302,\n }),\n formState: formState,\n })\n }\n"],"names":[],"mappings":";;;;;AAgDO,MAAM,uBACX,CAcE,gBAeF,OAAO,UAAoB,SAAwC;AACjE,QAAM,EAAE,qBAAqB;AAE7B,QAAM,eAAe,OAAO;AAAA,IAC1B;AAAA,IACA;AAAA,EAAA,MAII;AACJ,QAAI,0BAA0B,gBAAgB,GAAG;AAC/C,aAAO,MAAM,yBAAyB;AAAA,QACpC,EAAE,OAAO,iBAAA;AAAA,QACT;AAAA,MAAA;AAAA,IAEJ;AACA,WAAQ,iBAAoD;AAAA,MAC1D;AAAA,MACA,QAAQ;AAAA,MACR,SAAS;AAAA,IAAA,CACV;AAAA,EACH;AAEA,QAAM,UAAU,UAAU,SAAS;AAEnC,QAAM,OAAO,OAAO,UAAU,IAAI;AAElC,QAAM,gBAAiB,MAAM,aAAa;AAAA,IACxC,OAAO;AAAA,IACP,kBAAkB;AAAA,EAAA,CACnB;AAED,MAAI,CAAC,cAAe,QAAO;AAE3B,QAAM,mBACJ,4BAA4B,aAAa,IACrC,cAAc,OACd;AAGN,QAAM,YAAmD;AAAA,IACvD,UAAU;AAAA,MACR,UAAU;AAAA,IAAA;AAAA,IAEZ,QAAQ;AAAA,IACR,QAAQ,mBAAmB,CAAC,gBAAgB,IAAI,CAAA;AAAA,EAAC;AAGnD,4BAA0B,SAAS;AAEnC,QAAM,IAAI,oBAAoB;AAAA,IAC5B,UAAU,IAAI,SAAS,MAAM;AAAA,MAC3B,SAAS;AAAA,QACP,UAAU;AAAA,MAAA;AAAA,MAEZ,QAAQ;AAAA,IAAA,CACT;AAAA,IACD;AAAA,EAAA,CACD;AACH;"}
|
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
import { ServerFormState } from './types.js';
|
|
2
|
-
import { FormAsyncValidateOrFn } from '@tanstack/form-core';
|
|
3
|
-
interface ServerValidateErrorState<TFormData, TOnServer extends undefined | FormAsyncValidateOrFn<TFormData>> {
|
|
4
|
-
formState: ServerFormState<TFormData, TOnServer>;
|
|
5
|
-
response: Response;
|
|
6
|
-
}
|
|
7
|
-
export declare class ServerValidateError<TFormData, TOnServer extends undefined | FormAsyncValidateOrFn<TFormData>> extends Error implements ServerValidateErrorState<TFormData, TOnServer> {
|
|
8
|
-
formState: ServerFormState<TFormData, TOnServer>;
|
|
9
|
-
response: Response;
|
|
10
|
-
constructor(options: ServerValidateErrorState<TFormData, TOnServer>);
|
|
11
|
-
}
|
|
12
|
-
export {};
|
package/dist/esm/start/error.js
DELETED
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
class ServerValidateError extends Error {
|
|
2
|
-
constructor(options) {
|
|
3
|
-
super("Your form has errors. Please check the fields and try again.");
|
|
4
|
-
this.name = "ServerValidateError";
|
|
5
|
-
this.response = options.response;
|
|
6
|
-
this.formState = options.formState;
|
|
7
|
-
}
|
|
8
|
-
}
|
|
9
|
-
export {
|
|
10
|
-
ServerValidateError
|
|
11
|
-
};
|
|
12
|
-
//# sourceMappingURL=error.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"error.js","sources":["../../../src/start/error.ts"],"sourcesContent":["import type { ServerFormState } from './types'\nimport type { FormAsyncValidateOrFn } from '@tanstack/form-core'\n\ninterface ServerValidateErrorState<\n TFormData,\n TOnServer extends undefined | FormAsyncValidateOrFn<TFormData>,\n> {\n formState: ServerFormState<TFormData, TOnServer>\n response: Response\n}\n\nexport class ServerValidateError<\n TFormData,\n TOnServer extends undefined | FormAsyncValidateOrFn<TFormData>,\n >\n extends Error\n implements ServerValidateErrorState<TFormData, TOnServer>\n{\n formState: ServerFormState<TFormData, TOnServer>\n response: Response\n\n constructor(options: ServerValidateErrorState<TFormData, TOnServer>) {\n super('Your form has errors. Please check the fields and try again.')\n this.name = 'ServerValidateError'\n this.response = options.response\n this.formState = options.formState\n }\n}\n"],"names":[],"mappings":"AAWO,MAAM,4BAIH,MAEV;AAAA,EAIE,YAAY,SAAyD;AACnE,UAAM,8DAA8D;AACpE,SAAK,OAAO;AACZ,SAAK,WAAW,QAAQ;AACxB,SAAK,YAAY,QAAQ;AAAA,EAC3B;AACF;"}
|
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
import { ServerFormState } from './types.js';
|
|
2
|
-
export declare const initialFormState: {
|
|
3
|
-
errorMap: {
|
|
4
|
-
onServer: undefined;
|
|
5
|
-
};
|
|
6
|
-
errors: never[];
|
|
7
|
-
};
|
|
8
|
-
export declare const getFormData: () => Promise<{
|
|
9
|
-
errorMap: {
|
|
10
|
-
onServer: undefined;
|
|
11
|
-
};
|
|
12
|
-
errors: never[];
|
|
13
|
-
} | ServerFormState<any, undefined>>;
|
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
import { getInternalTanStackCookie, deleteInternalTanStackCookie } from "./utils.js";
|
|
2
|
-
const initialFormState = {
|
|
3
|
-
errorMap: {
|
|
4
|
-
onServer: void 0
|
|
5
|
-
},
|
|
6
|
-
errors: []
|
|
7
|
-
};
|
|
8
|
-
const getFormData = async () => {
|
|
9
|
-
const data = getInternalTanStackCookie();
|
|
10
|
-
deleteInternalTanStackCookie();
|
|
11
|
-
if (!data) return initialFormState;
|
|
12
|
-
return data;
|
|
13
|
-
};
|
|
14
|
-
export {
|
|
15
|
-
getFormData,
|
|
16
|
-
initialFormState
|
|
17
|
-
};
|
|
18
|
-
//# sourceMappingURL=getFormData.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"getFormData.js","sources":["../../../src/start/getFormData.tsx"],"sourcesContent":["import {\n deleteInternalTanStackCookie,\n getInternalTanStackCookie,\n} from './utils'\nimport type { ServerFormState } from './types'\n\nexport const initialFormState = {\n errorMap: {\n onServer: undefined,\n },\n errors: [],\n}\n\nexport const getFormData = async () => {\n const data = getInternalTanStackCookie() as\n | undefined\n | ServerFormState<any, undefined>\n // Delete the temporary cookie from the client after reading it\n deleteInternalTanStackCookie()\n if (!data) return initialFormState\n return data\n}\n"],"names":[],"mappings":";AAMO,MAAM,mBAAmB;AAAA,EAC9B,UAAU;AAAA,IACR,UAAU;AAAA,EAAA;AAAA,EAEZ,QAAQ,CAAA;AACV;AAEO,MAAM,cAAc,YAAY;AACrC,QAAM,OAAO,0BAAA;AAIb,+BAAA;AACA,MAAI,CAAC,KAAM,QAAO;AAClB,SAAO;AACT;"}
|
package/dist/esm/start/index.js
DELETED
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
import { createServerValidate } from "./createServerValidate.js";
|
|
2
|
-
import { getFormData, initialFormState } from "./getFormData.js";
|
|
3
|
-
import { ServerValidateError } from "./error.js";
|
|
4
|
-
export {
|
|
5
|
-
ServerValidateError,
|
|
6
|
-
createServerValidate,
|
|
7
|
-
getFormData,
|
|
8
|
-
initialFormState
|
|
9
|
-
};
|
|
10
|
-
//# sourceMappingURL=index.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;"}
|
|
@@ -1,2 +0,0 @@
|
|
|
1
|
-
import { FormAsyncValidateOrFn, FormState } from '@tanstack/form-core';
|
|
2
|
-
export type ServerFormState<TFormData, TOnServer extends undefined | FormAsyncValidateOrFn<TFormData>> = Pick<FormState<TFormData, undefined, undefined, undefined, undefined, undefined, undefined, undefined, undefined, undefined, TOnServer>, 'values' | 'errors' | 'errorMap'>;
|
package/dist/esm/start/utils.js
DELETED
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
import { setCookie, getCookie, deleteCookie } from "@tanstack/react-start/server";
|
|
2
|
-
import { stringify, parse } from "devalue";
|
|
3
|
-
const _INTERNALS_COOKIE_NAME = "_tanstack_form_internals";
|
|
4
|
-
const setInternalTanStackCookie = (data) => {
|
|
5
|
-
const cookie = stringify(data);
|
|
6
|
-
setCookie(_INTERNALS_COOKIE_NAME, cookie);
|
|
7
|
-
};
|
|
8
|
-
const getInternalTanStackCookie = () => {
|
|
9
|
-
const cookie = getCookie(_INTERNALS_COOKIE_NAME);
|
|
10
|
-
if (!cookie) return void 0;
|
|
11
|
-
return parse(cookie);
|
|
12
|
-
};
|
|
13
|
-
const deleteInternalTanStackCookie = () => {
|
|
14
|
-
deleteCookie(_INTERNALS_COOKIE_NAME);
|
|
15
|
-
};
|
|
16
|
-
export {
|
|
17
|
-
deleteInternalTanStackCookie,
|
|
18
|
-
getInternalTanStackCookie,
|
|
19
|
-
setInternalTanStackCookie
|
|
20
|
-
};
|
|
21
|
-
//# sourceMappingURL=utils.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"utils.js","sources":["../../../src/start/utils.ts"],"sourcesContent":["import {\n deleteCookie,\n getCookie,\n setCookie,\n} from '@tanstack/react-start/server'\nimport { parse, stringify } from 'devalue'\n\nconst _INTERNALS_COOKIE_NAME = '_tanstack_form_internals'\n\nexport const setInternalTanStackCookie = (data: any) => {\n const cookie = stringify(data)\n setCookie(_INTERNALS_COOKIE_NAME, cookie)\n}\n\nexport const getInternalTanStackCookie = () => {\n const cookie = getCookie(_INTERNALS_COOKIE_NAME)\n if (!cookie) return undefined\n return parse(cookie)\n}\n\nexport const deleteInternalTanStackCookie = () => {\n deleteCookie(_INTERNALS_COOKIE_NAME)\n}\n"],"names":[],"mappings":";;AAOA,MAAM,yBAAyB;AAExB,MAAM,4BAA4B,CAAC,SAAc;AACtD,QAAM,SAAS,UAAU,IAAI;AAC7B,YAAU,wBAAwB,MAAM;AAC1C;AAEO,MAAM,4BAA4B,MAAM;AAC7C,QAAM,SAAS,UAAU,sBAAsB;AAC/C,MAAI,CAAC,OAAQ,QAAO;AACpB,SAAO,MAAM,MAAM;AACrB;AAEO,MAAM,+BAA+B,MAAM;AAChD,eAAa,sBAAsB;AACrC;"}
|
package/dist/esm/useTransform.js
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"useTransform.js","sources":["../../src/useTransform.ts"],"sourcesContent":["import type {\n AnyFormApi,\n FormApi,\n FormAsyncValidateOrFn,\n FormTransform,\n FormValidateOrFn,\n} from '@tanstack/form-core'\n\nexport function useTransform(\n fn: (formBase: AnyFormApi) => AnyFormApi,\n deps: unknown[],\n): FormTransform<any, any, any, any, any, any, any, any, any, any, any, any> {\n return {\n fn,\n deps,\n }\n}\n"],"names":[],"mappings":"AAQO,SAAS,aACd,IACA,MAC2E;AAC3E,SAAO;AAAA,IACL;AAAA,IACA;AAAA,EAAA;AAEJ;"}
|
|
@@ -1,134 +0,0 @@
|
|
|
1
|
-
import { decode } from 'decode-formdata'
|
|
2
|
-
import {
|
|
3
|
-
isGlobalFormValidationError,
|
|
4
|
-
isStandardSchemaValidator,
|
|
5
|
-
standardSchemaValidators,
|
|
6
|
-
} from '@tanstack/form-core'
|
|
7
|
-
import { ServerValidateError } from './error'
|
|
8
|
-
import type {
|
|
9
|
-
FormAsyncValidateOrFn,
|
|
10
|
-
FormOptions,
|
|
11
|
-
FormValidateAsyncFn,
|
|
12
|
-
FormValidateOrFn,
|
|
13
|
-
UnwrapFormAsyncValidateOrFn,
|
|
14
|
-
} from '@tanstack/form-core'
|
|
15
|
-
import type { ServerFormState } from './types'
|
|
16
|
-
|
|
17
|
-
interface CreateServerValidateOptions<
|
|
18
|
-
TFormData,
|
|
19
|
-
TOnMount extends undefined | FormValidateOrFn<TFormData>,
|
|
20
|
-
TOnChange extends undefined | FormValidateOrFn<TFormData>,
|
|
21
|
-
TOnChangeAsync extends undefined | FormAsyncValidateOrFn<TFormData>,
|
|
22
|
-
TOnBlur extends undefined | FormValidateOrFn<TFormData>,
|
|
23
|
-
TOnBlurAsync extends undefined | FormAsyncValidateOrFn<TFormData>,
|
|
24
|
-
TOnSubmit extends undefined | FormValidateOrFn<TFormData>,
|
|
25
|
-
TOnSubmitAsync extends undefined | FormAsyncValidateOrFn<TFormData>,
|
|
26
|
-
TOnDynamic extends undefined | FormValidateOrFn<TFormData>,
|
|
27
|
-
TOnDynamicAsync extends undefined | FormAsyncValidateOrFn<TFormData>,
|
|
28
|
-
TOnServer extends undefined | FormAsyncValidateOrFn<TFormData>,
|
|
29
|
-
TSubmitMeta,
|
|
30
|
-
> extends FormOptions<
|
|
31
|
-
TFormData,
|
|
32
|
-
TOnMount,
|
|
33
|
-
TOnChange,
|
|
34
|
-
TOnChangeAsync,
|
|
35
|
-
TOnBlur,
|
|
36
|
-
TOnBlurAsync,
|
|
37
|
-
TOnSubmit,
|
|
38
|
-
TOnSubmitAsync,
|
|
39
|
-
TOnDynamic,
|
|
40
|
-
TOnDynamicAsync,
|
|
41
|
-
TOnServer,
|
|
42
|
-
TSubmitMeta
|
|
43
|
-
> {
|
|
44
|
-
onServerValidate: TOnServer
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
export const createServerValidate =
|
|
48
|
-
<
|
|
49
|
-
TFormData,
|
|
50
|
-
TOnMount extends undefined | FormValidateOrFn<TFormData>,
|
|
51
|
-
TOnChange extends undefined | FormValidateOrFn<TFormData>,
|
|
52
|
-
TOnChangeAsync extends undefined | FormAsyncValidateOrFn<TFormData>,
|
|
53
|
-
TOnBlur extends undefined | FormValidateOrFn<TFormData>,
|
|
54
|
-
TOnBlurAsync extends undefined | FormAsyncValidateOrFn<TFormData>,
|
|
55
|
-
TOnSubmit extends undefined | FormValidateOrFn<TFormData>,
|
|
56
|
-
TOnSubmitAsync extends undefined | FormAsyncValidateOrFn<TFormData>,
|
|
57
|
-
TOnDynamic extends undefined | FormValidateOrFn<TFormData>,
|
|
58
|
-
TOnDynamicAsync extends undefined | FormAsyncValidateOrFn<TFormData>,
|
|
59
|
-
TOnServer extends undefined | FormAsyncValidateOrFn<TFormData>,
|
|
60
|
-
TSubmitMeta,
|
|
61
|
-
>(
|
|
62
|
-
defaultOpts: CreateServerValidateOptions<
|
|
63
|
-
TFormData,
|
|
64
|
-
TOnMount,
|
|
65
|
-
TOnChange,
|
|
66
|
-
TOnChangeAsync,
|
|
67
|
-
TOnBlur,
|
|
68
|
-
TOnBlurAsync,
|
|
69
|
-
TOnSubmit,
|
|
70
|
-
TOnSubmitAsync,
|
|
71
|
-
TOnDynamic,
|
|
72
|
-
TOnDynamicAsync,
|
|
73
|
-
TOnServer,
|
|
74
|
-
TSubmitMeta
|
|
75
|
-
>,
|
|
76
|
-
) =>
|
|
77
|
-
async (formData: FormData, info?: Parameters<typeof decode>[1]) => {
|
|
78
|
-
const { onServerValidate } = defaultOpts
|
|
79
|
-
|
|
80
|
-
const runValidator = async ({
|
|
81
|
-
value,
|
|
82
|
-
validationSource,
|
|
83
|
-
}: {
|
|
84
|
-
value: TFormData
|
|
85
|
-
validationSource: 'form'
|
|
86
|
-
}) => {
|
|
87
|
-
if (isStandardSchemaValidator(onServerValidate)) {
|
|
88
|
-
return await standardSchemaValidators.validateAsync(
|
|
89
|
-
{ value, validationSource },
|
|
90
|
-
onServerValidate,
|
|
91
|
-
)
|
|
92
|
-
}
|
|
93
|
-
return (onServerValidate as FormValidateAsyncFn<TFormData>)({
|
|
94
|
-
value,
|
|
95
|
-
signal: undefined as never,
|
|
96
|
-
formApi: undefined as never,
|
|
97
|
-
})
|
|
98
|
-
}
|
|
99
|
-
|
|
100
|
-
const values = decode(formData, info) as never as TFormData
|
|
101
|
-
|
|
102
|
-
const onServerError = (await runValidator({
|
|
103
|
-
value: values,
|
|
104
|
-
validationSource: 'form',
|
|
105
|
-
})) as UnwrapFormAsyncValidateOrFn<TOnServer> | undefined
|
|
106
|
-
|
|
107
|
-
if (!onServerError) return values
|
|
108
|
-
|
|
109
|
-
const onServerErrorVal = (
|
|
110
|
-
isGlobalFormValidationError(onServerError)
|
|
111
|
-
? onServerError.form
|
|
112
|
-
: onServerError
|
|
113
|
-
) as UnwrapFormAsyncValidateOrFn<TOnServer>
|
|
114
|
-
|
|
115
|
-
const formState: ServerFormState<TFormData, TOnServer> = {
|
|
116
|
-
errorMap: {
|
|
117
|
-
onServer: onServerError,
|
|
118
|
-
},
|
|
119
|
-
values,
|
|
120
|
-
errors: onServerErrorVal ? [onServerErrorVal] : [],
|
|
121
|
-
}
|
|
122
|
-
|
|
123
|
-
throw new ServerValidateError({
|
|
124
|
-
formState,
|
|
125
|
-
})
|
|
126
|
-
}
|
|
127
|
-
|
|
128
|
-
export const initialFormState: ServerFormState<any, undefined> = {
|
|
129
|
-
errorMap: {
|
|
130
|
-
onServer: undefined,
|
|
131
|
-
},
|
|
132
|
-
values: undefined,
|
|
133
|
-
errors: [],
|
|
134
|
-
}
|
package/src/nextjs/error.ts
DELETED
|
@@ -1,25 +0,0 @@
|
|
|
1
|
-
import type { ServerFormState } from './types'
|
|
2
|
-
import type { FormAsyncValidateOrFn } from '@tanstack/form-core'
|
|
3
|
-
|
|
4
|
-
interface ServerValidateErrorState<
|
|
5
|
-
TFormData,
|
|
6
|
-
TOnServer extends undefined | FormAsyncValidateOrFn<TFormData>,
|
|
7
|
-
> {
|
|
8
|
-
formState: ServerFormState<TFormData, TOnServer>
|
|
9
|
-
}
|
|
10
|
-
|
|
11
|
-
export class ServerValidateError<
|
|
12
|
-
TFormData,
|
|
13
|
-
TOnServer extends undefined | FormAsyncValidateOrFn<TFormData>,
|
|
14
|
-
>
|
|
15
|
-
extends Error
|
|
16
|
-
implements ServerValidateErrorState<TFormData, TOnServer>
|
|
17
|
-
{
|
|
18
|
-
formState: ServerFormState<TFormData, TOnServer>
|
|
19
|
-
|
|
20
|
-
constructor(options: ServerValidateErrorState<TFormData, TOnServer>) {
|
|
21
|
-
super('Your form has errors. Please check the fields and try again.')
|
|
22
|
-
this.name = 'ServerValidateError'
|
|
23
|
-
this.formState = options.formState
|
|
24
|
-
}
|
|
25
|
-
}
|
package/src/nextjs/index.ts
DELETED
package/src/nextjs/types.ts
DELETED
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
import type { FormAsyncValidateOrFn, FormState } from '@tanstack/form-core'
|
|
2
|
-
|
|
3
|
-
export type ServerFormState<
|
|
4
|
-
TFormData,
|
|
5
|
-
TOnServer extends undefined | FormAsyncValidateOrFn<TFormData>,
|
|
6
|
-
> = Pick<
|
|
7
|
-
FormState<
|
|
8
|
-
TFormData,
|
|
9
|
-
undefined,
|
|
10
|
-
undefined,
|
|
11
|
-
undefined,
|
|
12
|
-
undefined,
|
|
13
|
-
undefined,
|
|
14
|
-
undefined,
|
|
15
|
-
undefined,
|
|
16
|
-
undefined,
|
|
17
|
-
undefined,
|
|
18
|
-
TOnServer
|
|
19
|
-
>,
|
|
20
|
-
'values' | 'errors' | 'errorMap'
|
|
21
|
-
>
|
|
@@ -1,134 +0,0 @@
|
|
|
1
|
-
import { decode } from 'decode-formdata'
|
|
2
|
-
import {
|
|
3
|
-
isGlobalFormValidationError,
|
|
4
|
-
isStandardSchemaValidator,
|
|
5
|
-
standardSchemaValidators,
|
|
6
|
-
} from '@tanstack/form-core'
|
|
7
|
-
import { ServerValidateError } from './error'
|
|
8
|
-
import type {
|
|
9
|
-
FormAsyncValidateOrFn,
|
|
10
|
-
FormOptions,
|
|
11
|
-
FormValidateAsyncFn,
|
|
12
|
-
FormValidateOrFn,
|
|
13
|
-
UnwrapFormAsyncValidateOrFn,
|
|
14
|
-
} from '@tanstack/form-core'
|
|
15
|
-
import type { ServerFormState } from './types'
|
|
16
|
-
|
|
17
|
-
interface CreateServerValidateOptions<
|
|
18
|
-
TFormData,
|
|
19
|
-
TOnMount extends undefined | FormValidateOrFn<TFormData>,
|
|
20
|
-
TOnChange extends undefined | FormValidateOrFn<TFormData>,
|
|
21
|
-
TOnChangeAsync extends undefined | FormAsyncValidateOrFn<TFormData>,
|
|
22
|
-
TOnBlur extends undefined | FormValidateOrFn<TFormData>,
|
|
23
|
-
TOnBlurAsync extends undefined | FormAsyncValidateOrFn<TFormData>,
|
|
24
|
-
TOnSubmit extends undefined | FormValidateOrFn<TFormData>,
|
|
25
|
-
TOnSubmitAsync extends undefined | FormAsyncValidateOrFn<TFormData>,
|
|
26
|
-
TOnDynamic extends undefined | FormValidateOrFn<TFormData>,
|
|
27
|
-
TOnDynamicAsync extends undefined | FormAsyncValidateOrFn<TFormData>,
|
|
28
|
-
TOnServer extends undefined | FormAsyncValidateOrFn<TFormData>,
|
|
29
|
-
TSubmitMeta,
|
|
30
|
-
> extends FormOptions<
|
|
31
|
-
TFormData,
|
|
32
|
-
TOnMount,
|
|
33
|
-
TOnChange,
|
|
34
|
-
TOnChangeAsync,
|
|
35
|
-
TOnBlur,
|
|
36
|
-
TOnBlurAsync,
|
|
37
|
-
TOnSubmit,
|
|
38
|
-
TOnSubmitAsync,
|
|
39
|
-
TOnDynamic,
|
|
40
|
-
TOnDynamicAsync,
|
|
41
|
-
TOnServer,
|
|
42
|
-
TSubmitMeta
|
|
43
|
-
> {
|
|
44
|
-
onServerValidate: TOnServer
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
export const createServerValidate =
|
|
48
|
-
<
|
|
49
|
-
TFormData,
|
|
50
|
-
TOnMount extends undefined | FormValidateOrFn<TFormData>,
|
|
51
|
-
TOnChange extends undefined | FormValidateOrFn<TFormData>,
|
|
52
|
-
TOnChangeAsync extends undefined | FormAsyncValidateOrFn<TFormData>,
|
|
53
|
-
TOnBlur extends undefined | FormValidateOrFn<TFormData>,
|
|
54
|
-
TOnBlurAsync extends undefined | FormAsyncValidateOrFn<TFormData>,
|
|
55
|
-
TOnSubmit extends undefined | FormValidateOrFn<TFormData>,
|
|
56
|
-
TOnSubmitAsync extends undefined | FormAsyncValidateOrFn<TFormData>,
|
|
57
|
-
TOnDynamic extends undefined | FormValidateOrFn<TFormData>,
|
|
58
|
-
TOnDynamicAsync extends undefined | FormAsyncValidateOrFn<TFormData>,
|
|
59
|
-
TOnServer extends undefined | FormAsyncValidateOrFn<TFormData>,
|
|
60
|
-
TSubmitMeta,
|
|
61
|
-
>(
|
|
62
|
-
defaultOpts: CreateServerValidateOptions<
|
|
63
|
-
TFormData,
|
|
64
|
-
TOnMount,
|
|
65
|
-
TOnChange,
|
|
66
|
-
TOnChangeAsync,
|
|
67
|
-
TOnBlur,
|
|
68
|
-
TOnBlurAsync,
|
|
69
|
-
TOnSubmit,
|
|
70
|
-
TOnSubmitAsync,
|
|
71
|
-
TOnDynamic,
|
|
72
|
-
TOnDynamicAsync,
|
|
73
|
-
TOnServer,
|
|
74
|
-
TSubmitMeta
|
|
75
|
-
>,
|
|
76
|
-
) =>
|
|
77
|
-
async (formData: FormData, info?: Parameters<typeof decode>[1]) => {
|
|
78
|
-
const { onServerValidate } = defaultOpts
|
|
79
|
-
|
|
80
|
-
const runValidator = async ({
|
|
81
|
-
value,
|
|
82
|
-
validationSource,
|
|
83
|
-
}: {
|
|
84
|
-
value: TFormData
|
|
85
|
-
validationSource: 'form'
|
|
86
|
-
}) => {
|
|
87
|
-
if (isStandardSchemaValidator(onServerValidate)) {
|
|
88
|
-
return await standardSchemaValidators.validateAsync(
|
|
89
|
-
{ value, validationSource },
|
|
90
|
-
onServerValidate,
|
|
91
|
-
)
|
|
92
|
-
}
|
|
93
|
-
return (onServerValidate as FormValidateAsyncFn<TFormData>)({
|
|
94
|
-
value,
|
|
95
|
-
signal: undefined as never,
|
|
96
|
-
formApi: undefined as never,
|
|
97
|
-
})
|
|
98
|
-
}
|
|
99
|
-
|
|
100
|
-
const values = decode(formData, info) as never as TFormData
|
|
101
|
-
|
|
102
|
-
const onServerError = (await runValidator({
|
|
103
|
-
value: values,
|
|
104
|
-
validationSource: 'form',
|
|
105
|
-
})) as UnwrapFormAsyncValidateOrFn<TOnServer> | undefined
|
|
106
|
-
|
|
107
|
-
if (!onServerError) return values
|
|
108
|
-
|
|
109
|
-
const onServerErrorVal = (
|
|
110
|
-
isGlobalFormValidationError(onServerError)
|
|
111
|
-
? onServerError.form
|
|
112
|
-
: onServerError
|
|
113
|
-
) as UnwrapFormAsyncValidateOrFn<TOnServer>
|
|
114
|
-
|
|
115
|
-
const formState: ServerFormState<TFormData, TOnServer> = {
|
|
116
|
-
errorMap: {
|
|
117
|
-
onServer: onServerError,
|
|
118
|
-
},
|
|
119
|
-
values,
|
|
120
|
-
errors: onServerErrorVal ? [onServerErrorVal] : [],
|
|
121
|
-
}
|
|
122
|
-
|
|
123
|
-
throw new ServerValidateError({
|
|
124
|
-
formState,
|
|
125
|
-
})
|
|
126
|
-
}
|
|
127
|
-
|
|
128
|
-
export const initialFormState: ServerFormState<any, undefined> = {
|
|
129
|
-
errorMap: {
|
|
130
|
-
onServer: undefined,
|
|
131
|
-
},
|
|
132
|
-
values: undefined,
|
|
133
|
-
errors: [],
|
|
134
|
-
}
|
package/src/remix/error.ts
DELETED
|
@@ -1,25 +0,0 @@
|
|
|
1
|
-
import type { ServerFormState } from './types'
|
|
2
|
-
import type { FormAsyncValidateOrFn } from '@tanstack/form-core'
|
|
3
|
-
|
|
4
|
-
interface ServerValidateErrorState<
|
|
5
|
-
TFormData,
|
|
6
|
-
TOnServer extends undefined | FormAsyncValidateOrFn<TFormData>,
|
|
7
|
-
> {
|
|
8
|
-
formState: ServerFormState<TFormData, TOnServer>
|
|
9
|
-
}
|
|
10
|
-
|
|
11
|
-
export class ServerValidateError<
|
|
12
|
-
TFormData,
|
|
13
|
-
TOnServer extends undefined | FormAsyncValidateOrFn<TFormData>,
|
|
14
|
-
>
|
|
15
|
-
extends Error
|
|
16
|
-
implements ServerValidateErrorState<TFormData, TOnServer>
|
|
17
|
-
{
|
|
18
|
-
formState: ServerFormState<TFormData, TOnServer>
|
|
19
|
-
|
|
20
|
-
constructor(options: ServerValidateErrorState<TFormData, TOnServer>) {
|
|
21
|
-
super('Your form has errors. Please check the fields and try again.')
|
|
22
|
-
this.name = 'ServerValidateError'
|
|
23
|
-
this.formState = options.formState
|
|
24
|
-
}
|
|
25
|
-
}
|
package/src/remix/index.ts
DELETED
package/src/remix/types.ts
DELETED
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
import type { FormAsyncValidateOrFn, FormState } from '@tanstack/form-core'
|
|
2
|
-
|
|
3
|
-
export type ServerFormState<
|
|
4
|
-
TFormData,
|
|
5
|
-
TOnServer extends undefined | FormAsyncValidateOrFn<TFormData>,
|
|
6
|
-
> = Pick<
|
|
7
|
-
FormState<
|
|
8
|
-
TFormData,
|
|
9
|
-
undefined,
|
|
10
|
-
undefined,
|
|
11
|
-
undefined,
|
|
12
|
-
undefined,
|
|
13
|
-
undefined,
|
|
14
|
-
undefined,
|
|
15
|
-
undefined,
|
|
16
|
-
undefined,
|
|
17
|
-
undefined,
|
|
18
|
-
TOnServer
|
|
19
|
-
>,
|
|
20
|
-
'values' | 'errors' | 'errorMap'
|
|
21
|
-
>
|