@tanstack/react-form 1.3.2 → 1.3.4
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/start/createServerValidate.cjs +4 -5
- package/dist/cjs/start/createServerValidate.cjs.map +1 -1
- package/dist/cjs/start/getFormData.cjs +2 -3
- package/dist/cjs/start/getFormData.cjs.map +1 -1
- package/dist/cjs/start/utils.cjs +18 -3
- package/dist/cjs/start/utils.cjs.map +1 -1
- package/dist/cjs/start/utils.d.cts +3 -1
- package/dist/esm/start/createServerValidate.js +4 -5
- package/dist/esm/start/createServerValidate.js.map +1 -1
- package/dist/esm/start/getFormData.js +3 -4
- package/dist/esm/start/getFormData.js.map +1 -1
- package/dist/esm/start/utils.d.ts +3 -1
- package/dist/esm/start/utils.js +18 -3
- package/dist/esm/start/utils.js.map +1 -1
- package/package.json +6 -6
- package/src/start/createServerValidate.tsx +4 -5
- package/src/start/getFormData.tsx +6 -4
- package/src/start/utils.ts +22 -2
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
3
|
-
const decodeFormdata = require("decode-formdata");
|
|
4
3
|
const formCore = require("@tanstack/form-core");
|
|
5
4
|
const server = require("@tanstack/react-start/server");
|
|
6
|
-
const
|
|
5
|
+
const decodeFormdata = require("decode-formdata");
|
|
7
6
|
const error = require("./error.cjs");
|
|
7
|
+
const utils = require("./utils.cjs");
|
|
8
8
|
const createServerValidate = (defaultOpts) => async (formData, info) => {
|
|
9
9
|
const { onServerValidate } = defaultOpts;
|
|
10
10
|
const runValidator = async ({
|
|
@@ -38,12 +38,11 @@ const createServerValidate = (defaultOpts) => async (formData, info) => {
|
|
|
38
38
|
values: data,
|
|
39
39
|
errors: onServerErrorVal ? [onServerErrorVal] : []
|
|
40
40
|
};
|
|
41
|
-
|
|
41
|
+
utils.setInternalTanStackCookie(formState);
|
|
42
42
|
throw new error.ServerValidateError({
|
|
43
43
|
response: new Response("ok", {
|
|
44
44
|
headers: {
|
|
45
|
-
Location: referer
|
|
46
|
-
"Set-Cookie": cookie
|
|
45
|
+
Location: referer
|
|
47
46
|
},
|
|
48
47
|
status: 302
|
|
49
48
|
}),
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"createServerValidate.cjs","sources":["../../../src/start/createServerValidate.tsx"],"sourcesContent":["import {
|
|
1
|
+
{"version":3,"file":"createServerValidate.cjs","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 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 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 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 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":["isStandardSchemaValidator","standardSchemaValidators","getHeader","decode","isGlobalFormValidationError","setInternalTanStackCookie","ServerValidateError"],"mappings":";;;;;;;AA4CO,MAAM,uBACX,CAYE,gBAaF,OAAO,UAAoB,SAAwC;AAC3D,QAAA,EAAE,qBAAqB;AAE7B,QAAM,eAAe,OAAO;AAAA,IAC1B;AAAA,IACA;AAAA,EAAA,MAII;AACA,QAAAA,SAAAA,0BAA0B,gBAAgB,GAAG;AAC/C,aAAO,MAAMC,SAAyB,yBAAA;AAAA,QACpC,EAAE,OAAO,iBAAiB;AAAA,QAC1B;AAAA,MACF;AAAA,IAAA;AAEF,WAAQ,iBAAoD;AAAA,MAC1D;AAAA,MACA,QAAQ;AAAA,MACR,SAAS;AAAA,IAAA,CACV;AAAA,EACH;AAEM,QAAA,UAAUC,iBAAU,SAAS;AAE7B,QAAA,OAAOC,eAAAA,OAAO,UAAU,IAAI;AAE5B,QAAA,gBAAiB,MAAM,aAAa;AAAA,IACxC,OAAO;AAAA,IACP,kBAAkB;AAAA,EAAA,CACnB;AAEG,MAAA,CAAC,cAAsB,QAAA;AAE3B,QAAM,mBACJC,SAAAA,4BAA4B,aAAa,IACrC,cAAc,OACd;AAGN,QAAM,YAAmD;AAAA,IACvD,UAAU;AAAA,MACR,UAAU;AAAA,IACZ;AAAA,IACA,QAAQ;AAAA,IACR,QAAQ,mBAAmB,CAAC,gBAAgB,IAAI,CAAA;AAAA,EAClD;AAEAC,QAAAA,0BAA0B,SAAS;AAEnC,QAAM,IAAIC,MAAAA,oBAAoB;AAAA,IAC5B,UAAU,IAAI,SAAS,MAAM;AAAA,MAC3B,SAAS;AAAA,QACP,UAAU;AAAA,MACZ;AAAA,MACA,QAAQ;AAAA,IAAA,CACT;AAAA,IACD;AAAA,EAAA,CACD;AACH;;"}
|
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
3
|
-
const server = require("@tanstack/react-start/server");
|
|
4
3
|
const utils = require("./utils.cjs");
|
|
5
4
|
const initialFormState = {
|
|
6
5
|
errorMap: {
|
|
@@ -9,8 +8,8 @@ const initialFormState = {
|
|
|
9
8
|
errors: []
|
|
10
9
|
};
|
|
11
10
|
const getFormData = async () => {
|
|
12
|
-
const data =
|
|
13
|
-
|
|
11
|
+
const data = utils.getInternalTanStackCookie();
|
|
12
|
+
utils.deleteInternalTanStackCookie();
|
|
14
13
|
if (!data) return initialFormState;
|
|
15
14
|
return data;
|
|
16
15
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"getFormData.cjs","sources":["../../../src/start/getFormData.tsx"],"sourcesContent":["import {
|
|
1
|
+
{"version":3,"file":"getFormData.cjs","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":["getInternalTanStackCookie","deleteInternalTanStackCookie"],"mappings":";;;AAMO,MAAM,mBAAmB;AAAA,EAC9B,UAAU;AAAA,IACR,UAAU;AAAA,EACZ;AAAA,EACA,QAAQ,CAAA;AACV;AAEO,MAAM,cAAc,YAAY;AACrC,QAAM,OAAOA,MAAAA,0BAA0B;AAIVC,qCAAA;AACzB,MAAA,CAAC,KAAa,QAAA;AACX,SAAA;AACT;;;"}
|
package/dist/cjs/start/utils.cjs
CHANGED
|
@@ -1,6 +1,21 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
3
|
-
const
|
|
4
|
-
const
|
|
5
|
-
|
|
3
|
+
const server = require("@tanstack/react-start/server");
|
|
4
|
+
const devalue = require("devalue");
|
|
5
|
+
const _INTERNALS_COOKIE_NAME = "_tanstack_form_internals";
|
|
6
|
+
const setInternalTanStackCookie = (data) => {
|
|
7
|
+
const cookie = devalue.stringify(data);
|
|
8
|
+
server.setCookie(_INTERNALS_COOKIE_NAME, cookie);
|
|
9
|
+
};
|
|
10
|
+
const getInternalTanStackCookie = () => {
|
|
11
|
+
const cookie = server.getCookie(_INTERNALS_COOKIE_NAME);
|
|
12
|
+
if (!cookie) return void 0;
|
|
13
|
+
return devalue.parse(cookie);
|
|
14
|
+
};
|
|
15
|
+
const deleteInternalTanStackCookie = () => {
|
|
16
|
+
server.deleteCookie(_INTERNALS_COOKIE_NAME);
|
|
17
|
+
};
|
|
18
|
+
exports.deleteInternalTanStackCookie = deleteInternalTanStackCookie;
|
|
19
|
+
exports.getInternalTanStackCookie = getInternalTanStackCookie;
|
|
20
|
+
exports.setInternalTanStackCookie = setInternalTanStackCookie;
|
|
6
21
|
//# sourceMappingURL=utils.cjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"utils.cjs","sources":["../../../src/start/utils.ts"],"sourcesContent":["import {
|
|
1
|
+
{"version":3,"file":"utils.cjs","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":["stringify","setCookie","getCookie","parse","deleteCookie"],"mappings":";;;;AAOA,MAAM,yBAAyB;AAElB,MAAA,4BAA4B,CAAC,SAAc;AAChD,QAAA,SAASA,kBAAU,IAAI;AAC7BC,SAAA,UAAU,wBAAwB,MAAM;AAC1C;AAEO,MAAM,4BAA4B,MAAM;AACvC,QAAA,SAASC,iBAAU,sBAAsB;AAC3C,MAAA,CAAC,OAAe,QAAA;AACpB,SAAOC,QAAAA,MAAM,MAAM;AACrB;AAEO,MAAM,+BAA+B,MAAM;AAChDC,SAAAA,aAAa,sBAAsB;AACrC;;;;"}
|
|
@@ -1 +1,3 @@
|
|
|
1
|
-
export declare const
|
|
1
|
+
export declare const setInternalTanStackCookie: (data: any) => void;
|
|
2
|
+
export declare const getInternalTanStackCookie: () => any;
|
|
3
|
+
export declare const deleteInternalTanStackCookie: () => void;
|
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import { decode } from "decode-formdata";
|
|
2
1
|
import { isGlobalFormValidationError, isStandardSchemaValidator, standardSchemaValidators } from "@tanstack/form-core";
|
|
3
2
|
import { getHeader } from "@tanstack/react-start/server";
|
|
4
|
-
import {
|
|
3
|
+
import { decode } from "decode-formdata";
|
|
5
4
|
import { ServerValidateError } from "./error.js";
|
|
5
|
+
import { setInternalTanStackCookie } from "./utils.js";
|
|
6
6
|
const createServerValidate = (defaultOpts) => async (formData, info) => {
|
|
7
7
|
const { onServerValidate } = defaultOpts;
|
|
8
8
|
const runValidator = async ({
|
|
@@ -36,12 +36,11 @@ const createServerValidate = (defaultOpts) => async (formData, info) => {
|
|
|
36
36
|
values: data,
|
|
37
37
|
errors: onServerErrorVal ? [onServerErrorVal] : []
|
|
38
38
|
};
|
|
39
|
-
|
|
39
|
+
setInternalTanStackCookie(formState);
|
|
40
40
|
throw new ServerValidateError({
|
|
41
41
|
response: new Response("ok", {
|
|
42
42
|
headers: {
|
|
43
|
-
Location: referer
|
|
44
|
-
"Set-Cookie": cookie
|
|
43
|
+
Location: referer
|
|
45
44
|
},
|
|
46
45
|
status: 302
|
|
47
46
|
}),
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"createServerValidate.js","sources":["../../../src/start/createServerValidate.tsx"],"sourcesContent":["import {
|
|
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 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 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 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 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":";;;;;AA4CO,MAAM,uBACX,CAYE,gBAaF,OAAO,UAAoB,SAAwC;AAC3D,QAAA,EAAE,qBAAqB;AAE7B,QAAM,eAAe,OAAO;AAAA,IAC1B;AAAA,IACA;AAAA,EAAA,MAII;AACA,QAAA,0BAA0B,gBAAgB,GAAG;AAC/C,aAAO,MAAM,yBAAyB;AAAA,QACpC,EAAE,OAAO,iBAAiB;AAAA,QAC1B;AAAA,MACF;AAAA,IAAA;AAEF,WAAQ,iBAAoD;AAAA,MAC1D;AAAA,MACA,QAAQ;AAAA,MACR,SAAS;AAAA,IAAA,CACV;AAAA,EACH;AAEM,QAAA,UAAU,UAAU,SAAS;AAE7B,QAAA,OAAO,OAAO,UAAU,IAAI;AAE5B,QAAA,gBAAiB,MAAM,aAAa;AAAA,IACxC,OAAO;AAAA,IACP,kBAAkB;AAAA,EAAA,CACnB;AAEG,MAAA,CAAC,cAAsB,QAAA;AAE3B,QAAM,mBACJ,4BAA4B,aAAa,IACrC,cAAc,OACd;AAGN,QAAM,YAAmD;AAAA,IACvD,UAAU;AAAA,MACR,UAAU;AAAA,IACZ;AAAA,IACA,QAAQ;AAAA,IACR,QAAQ,mBAAmB,CAAC,gBAAgB,IAAI,CAAA;AAAA,EAClD;AAEA,4BAA0B,SAAS;AAEnC,QAAM,IAAI,oBAAoB;AAAA,IAC5B,UAAU,IAAI,SAAS,MAAM;AAAA,MAC3B,SAAS;AAAA,QACP,UAAU;AAAA,MACZ;AAAA,MACA,QAAQ;AAAA,IAAA,CACT;AAAA,IACD;AAAA,EAAA,CACD;AACH;"}
|
|
@@ -1,5 +1,4 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { _tanstackInternalsCookie } from "./utils.js";
|
|
1
|
+
import { getInternalTanStackCookie, deleteInternalTanStackCookie } from "./utils.js";
|
|
3
2
|
const initialFormState = {
|
|
4
3
|
errorMap: {
|
|
5
4
|
onServer: void 0
|
|
@@ -7,8 +6,8 @@ const initialFormState = {
|
|
|
7
6
|
errors: []
|
|
8
7
|
};
|
|
9
8
|
const getFormData = async () => {
|
|
10
|
-
const data =
|
|
11
|
-
|
|
9
|
+
const data = getInternalTanStackCookie();
|
|
10
|
+
deleteInternalTanStackCookie();
|
|
12
11
|
if (!data) return initialFormState;
|
|
13
12
|
return data;
|
|
14
13
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"getFormData.js","sources":["../../../src/start/getFormData.tsx"],"sourcesContent":["import {
|
|
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,EACZ;AAAA,EACA,QAAQ,CAAA;AACV;AAEO,MAAM,cAAc,YAAY;AACrC,QAAM,OAAO,0BAA0B;AAIV,+BAAA;AACzB,MAAA,CAAC,KAAa,QAAA;AACX,SAAA;AACT;"}
|
|
@@ -1 +1,3 @@
|
|
|
1
|
-
export declare const
|
|
1
|
+
export declare const setInternalTanStackCookie: (data: any) => void;
|
|
2
|
+
export declare const getInternalTanStackCookie: () => any;
|
|
3
|
+
export declare const deleteInternalTanStackCookie: () => void;
|
package/dist/esm/start/utils.js
CHANGED
|
@@ -1,6 +1,21 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
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
|
+
};
|
|
3
16
|
export {
|
|
4
|
-
|
|
17
|
+
deleteInternalTanStackCookie,
|
|
18
|
+
getInternalTanStackCookie,
|
|
19
|
+
setInternalTanStackCookie
|
|
5
20
|
};
|
|
6
21
|
//# sourceMappingURL=utils.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"utils.js","sources":["../../../src/start/utils.ts"],"sourcesContent":["import {
|
|
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;AAElB,MAAA,4BAA4B,CAAC,SAAc;AAChD,QAAA,SAAS,UAAU,IAAI;AAC7B,YAAU,wBAAwB,MAAM;AAC1C;AAEO,MAAM,4BAA4B,MAAM;AACvC,QAAA,SAAS,UAAU,sBAAsB;AAC3C,MAAA,CAAC,OAAe,QAAA;AACpB,SAAO,MAAM,MAAM;AACrB;AAEO,MAAM,+BAA+B,MAAM;AAChD,eAAa,sBAAsB;AACrC;"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tanstack/react-form",
|
|
3
|
-
"version": "1.3.
|
|
3
|
+
"version": "1.3.4",
|
|
4
4
|
"description": "Powerful, type-safe forms for React.",
|
|
5
5
|
"author": "tannerlinsley",
|
|
6
6
|
"license": "MIT",
|
|
@@ -67,21 +67,21 @@
|
|
|
67
67
|
"src"
|
|
68
68
|
],
|
|
69
69
|
"dependencies": {
|
|
70
|
-
"@remix-run/node": "^2.16.5",
|
|
71
70
|
"@tanstack/react-store": "^0.7.0",
|
|
72
71
|
"decode-formdata": "^0.9.0",
|
|
73
|
-
"
|
|
72
|
+
"devalue": "^5.1.1",
|
|
73
|
+
"@tanstack/form-core": "1.3.4"
|
|
74
74
|
},
|
|
75
75
|
"devDependencies": {
|
|
76
|
-
"@tanstack/react-start": "^1.
|
|
76
|
+
"@tanstack/react-start": "^1.116.1",
|
|
77
77
|
"@types/react": "^19.0.7",
|
|
78
78
|
"@types/react-dom": "^19.0.3",
|
|
79
79
|
"@vitejs/plugin-react": "^4.3.4",
|
|
80
|
-
"eslint-plugin-react-compiler": "19.0.0-beta-
|
|
80
|
+
"eslint-plugin-react-compiler": "19.0.0-beta-ebf51a3-20250411",
|
|
81
81
|
"react": "^19.0.0",
|
|
82
82
|
"react-dom": "^19.0.0",
|
|
83
83
|
"vinxi": "^0.5.4",
|
|
84
|
-
"vite": "^6.2.
|
|
84
|
+
"vite": "^6.2.6"
|
|
85
85
|
},
|
|
86
86
|
"peerDependencies": {
|
|
87
87
|
"@tanstack/react-start": "^1.112.0",
|
|
@@ -1,12 +1,13 @@
|
|
|
1
|
-
import { decode } from 'decode-formdata'
|
|
2
1
|
import {
|
|
3
2
|
isGlobalFormValidationError,
|
|
4
3
|
isStandardSchemaValidator,
|
|
5
4
|
standardSchemaValidators,
|
|
6
5
|
} from '@tanstack/form-core'
|
|
7
6
|
import { getHeader } from '@tanstack/react-start/server'
|
|
8
|
-
import {
|
|
7
|
+
import { decode } from 'decode-formdata'
|
|
9
8
|
import { ServerValidateError } from './error'
|
|
9
|
+
import { setInternalTanStackCookie } from './utils'
|
|
10
|
+
import type { ServerFormState } from './types'
|
|
10
11
|
import type {
|
|
11
12
|
FormAsyncValidateOrFn,
|
|
12
13
|
FormOptions,
|
|
@@ -14,7 +15,6 @@ import type {
|
|
|
14
15
|
FormValidateOrFn,
|
|
15
16
|
UnwrapFormAsyncValidateOrFn,
|
|
16
17
|
} from '@tanstack/form-core'
|
|
17
|
-
import type { ServerFormState } from './types'
|
|
18
18
|
|
|
19
19
|
interface CreateServerValidateOptions<
|
|
20
20
|
TFormData,
|
|
@@ -116,13 +116,12 @@ export const createServerValidate =
|
|
|
116
116
|
errors: onServerErrorVal ? [onServerErrorVal] : [],
|
|
117
117
|
}
|
|
118
118
|
|
|
119
|
-
|
|
119
|
+
setInternalTanStackCookie(formState)
|
|
120
120
|
|
|
121
121
|
throw new ServerValidateError({
|
|
122
122
|
response: new Response('ok', {
|
|
123
123
|
headers: {
|
|
124
124
|
Location: referer,
|
|
125
|
-
'Set-Cookie': cookie,
|
|
126
125
|
},
|
|
127
126
|
status: 302,
|
|
128
127
|
}),
|
|
@@ -1,5 +1,7 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
1
|
+
import {
|
|
2
|
+
deleteInternalTanStackCookie,
|
|
3
|
+
getInternalTanStackCookie,
|
|
4
|
+
} from './utils'
|
|
3
5
|
import type { ServerFormState } from './types'
|
|
4
6
|
|
|
5
7
|
export const initialFormState = {
|
|
@@ -10,11 +12,11 @@ export const initialFormState = {
|
|
|
10
12
|
}
|
|
11
13
|
|
|
12
14
|
export const getFormData = async () => {
|
|
13
|
-
const data = (
|
|
15
|
+
const data = getInternalTanStackCookie() as
|
|
14
16
|
| undefined
|
|
15
17
|
| ServerFormState<any, undefined>
|
|
16
18
|
// Delete the temporary cookie from the client after reading it
|
|
17
|
-
|
|
19
|
+
deleteInternalTanStackCookie()
|
|
18
20
|
if (!data) return initialFormState
|
|
19
21
|
return data
|
|
20
22
|
}
|
package/src/start/utils.ts
CHANGED
|
@@ -1,3 +1,23 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import {
|
|
2
|
+
deleteCookie,
|
|
3
|
+
getCookie,
|
|
4
|
+
setCookie,
|
|
5
|
+
} from '@tanstack/react-start/server'
|
|
6
|
+
import { parse, stringify } from 'devalue'
|
|
2
7
|
|
|
3
|
-
|
|
8
|
+
const _INTERNALS_COOKIE_NAME = '_tanstack_form_internals'
|
|
9
|
+
|
|
10
|
+
export const setInternalTanStackCookie = (data: any) => {
|
|
11
|
+
const cookie = stringify(data)
|
|
12
|
+
setCookie(_INTERNALS_COOKIE_NAME, cookie)
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
export const getInternalTanStackCookie = () => {
|
|
16
|
+
const cookie = getCookie(_INTERNALS_COOKIE_NAME)
|
|
17
|
+
if (!cookie) return undefined
|
|
18
|
+
return parse(cookie)
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
export const deleteInternalTanStackCookie = () => {
|
|
22
|
+
deleteCookie(_INTERNALS_COOKIE_NAME)
|
|
23
|
+
}
|