@tanstack/react-form 0.39.0 → 0.39.2
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/index.cjs +5 -0
- package/dist/cjs/index.cjs.map +1 -1
- package/dist/cjs/index.d.cts +1 -0
- package/dist/cjs/useForm.cjs.map +1 -1
- package/dist/cjs/useForm.d.cts +1 -9
- package/dist/esm/index.d.ts +1 -0
- package/dist/esm/index.js +2 -0
- package/dist/esm/index.js.map +1 -1
- package/dist/esm/useForm.d.ts +1 -9
- package/dist/esm/useForm.js.map +1 -1
- package/package.json +4 -4
- package/src/index.ts +2 -0
- package/src/useForm.tsx +1 -11
package/dist/cjs/index.cjs
CHANGED
|
@@ -1,9 +1,14 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
3
3
|
const formCore = require("@tanstack/form-core");
|
|
4
|
+
const reactStore = require("@tanstack/react-store");
|
|
4
5
|
const useForm = require("./useForm.cjs");
|
|
5
6
|
const useField = require("./useField.cjs");
|
|
6
7
|
const useTransform = require("./useTransform.cjs");
|
|
8
|
+
Object.defineProperty(exports, "useStore", {
|
|
9
|
+
enumerable: true,
|
|
10
|
+
get: () => reactStore.useStore
|
|
11
|
+
});
|
|
7
12
|
exports.useForm = useForm.useForm;
|
|
8
13
|
exports.Field = useField.Field;
|
|
9
14
|
exports.useField = useField.useField;
|
package/dist/cjs/index.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.cjs","sources":[],"sourcesContent":[],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.cjs","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;"}
|
package/dist/cjs/index.d.cts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
export * from '@tanstack/form-core';
|
|
2
|
+
export { useStore } from '@tanstack/react-store';
|
|
2
3
|
export type { ReactFormApi, ReactFormExtendedApi } from './useForm.cjs';
|
|
3
4
|
export { useForm } from './useForm.cjs';
|
|
4
5
|
export type { UseField, FieldComponent } from './useField.cjs';
|
package/dist/cjs/useForm.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useForm.cjs","sources":["../../src/useForm.tsx"],"sourcesContent":["import { FormApi, functionalUpdate } from '@tanstack/form-core'\nimport { useStore } from '@tanstack/react-store'\nimport React, { useState } from 'react'\nimport { Field } from './useField'\nimport { useIsomorphicLayoutEffect } from './useIsomorphicLayoutEffect'\nimport type { PropsWithChildren, ReactNode } from 'react'\nimport type { FieldComponent
|
|
1
|
+
{"version":3,"file":"useForm.cjs","sources":["../../src/useForm.tsx"],"sourcesContent":["import { FormApi, functionalUpdate } from '@tanstack/form-core'\nimport { useStore } from '@tanstack/react-store'\nimport React, { useState } from 'react'\nimport { Field } from './useField'\nimport { useIsomorphicLayoutEffect } from './useIsomorphicLayoutEffect'\nimport type { PropsWithChildren, ReactNode } from 'react'\nimport type { FieldComponent } from './useField'\nimport type { NoInfer } from '@tanstack/react-store'\nimport type { FormOptions, FormState, Validator } from '@tanstack/form-core'\n\n/**\n * Fields that are added onto the `FormAPI` from `@tanstack/form-core` and returned from `useForm`\n */\nexport interface ReactFormApi<\n TFormData,\n TFormValidator extends Validator<TFormData, unknown> | undefined = undefined,\n> {\n /**\n * A React component to render form fields. With this, you can render and manage individual form fields.\n */\n Field: FieldComponent<TFormData, TFormValidator>\n /**\n * A `Subscribe` function that allows you to listen and react to changes in the form's state. It's especially useful when you need to execute side effects or render specific components in response to state updates.\n */\n Subscribe: <TSelected = NoInfer<FormState<TFormData>>>(props: {\n selector?: (state: NoInfer<FormState<TFormData>>) => TSelected\n children: ((state: NoInfer<TSelected>) => ReactNode) | ReactNode\n }) => ReactNode\n}\n\n/**\n * An extended version of the `FormApi` class that includes React-specific functionalities from `ReactFormApi`\n */\nexport type ReactFormExtendedApi<\n TFormData,\n TFormValidator extends Validator<TFormData, unknown> | undefined = undefined,\n> = FormApi<TFormData, TFormValidator> & ReactFormApi<TFormData, TFormValidator>\n\nfunction LocalSubscribe({\n form,\n selector,\n children,\n}: PropsWithChildren<{\n form: FormApi<any, any>\n selector: (state: FormState<any>) => FormState<any>\n}>) {\n const data = useStore(form.store, selector)\n\n return functionalUpdate(children, data)\n}\n\n/**\n * A custom React Hook that returns an extended instance of the `FormApi` class.\n *\n * This API encapsulates all the necessary functionalities related to the form. It allows you to manage form state, handle submissions, and interact with form fields\n */\nexport function useForm<\n TFormData,\n TFormValidator extends Validator<TFormData, unknown> | undefined = undefined,\n>(opts?: FormOptions<TFormData, TFormValidator>) {\n const [formApi] = useState(() => {\n const api = new FormApi<TFormData, TFormValidator>(opts)\n\n const extendedApi: ReactFormExtendedApi<TFormData, TFormValidator> =\n api as never\n extendedApi.Field = function APIField(props) {\n return <Field {...props} form={api} />\n }\n extendedApi.Subscribe = (props: any) => {\n return (\n <LocalSubscribe\n form={api}\n selector={props.selector}\n children={props.children}\n />\n )\n }\n\n return extendedApi\n })\n\n useIsomorphicLayoutEffect(formApi.mount, [])\n\n useStore(formApi.store, (state) => state.isSubmitting)\n\n /**\n * formApi.update should not have any side effects. Think of it like a `useRef`\n * that we need to keep updated every render with the most up-to-date information.\n */\n useIsomorphicLayoutEffect(() => {\n formApi.update(opts)\n })\n\n return formApi\n}\n"],"names":["useStore","functionalUpdate","useState","FormApi","jsx","Field","useIsomorphicLayoutEffect"],"mappings":";;;;;;;;AAsCA,SAAS,eAAe;AAAA,EACtB;AAAA,EACA;AAAA,EACA;AACF,GAGI;AACF,QAAM,OAAOA,WAAA,SAAS,KAAK,OAAO,QAAQ;AAEnC,SAAAC,SAAA,iBAAiB,UAAU,IAAI;AACxC;AAOO,SAAS,QAGd,MAA+C;AAC/C,QAAM,CAAC,OAAO,IAAIC,MAAAA,SAAS,MAAM;AACzB,UAAA,MAAM,IAAIC,SAAA,QAAmC,IAAI;AAEvD,UAAM,cACJ;AACU,gBAAA,QAAQ,SAAS,SAAS,OAAO;AAC3C,aAAQC,2BAAAA,IAAAC,SAAAA,OAAA,EAAO,GAAG,OAAO,MAAM,KAAK;AAAA,IACtC;AACY,gBAAA,YAAY,CAAC,UAAe;AAEpC,aAAAD,2BAAA;AAAA,QAAC;AAAA,QAAA;AAAA,UACC,MAAM;AAAA,UACN,UAAU,MAAM;AAAA,UAChB,UAAU,MAAM;AAAA,QAAA;AAAA,MAClB;AAAA,IAEJ;AAEO,WAAA;AAAA,EAAA,CACR;AAEyBE,sDAAA,QAAQ,OAAO,EAAE;AAE3CN,aAAA,SAAS,QAAQ,OAAO,CAAC,UAAU,MAAM,YAAY;AAMrDM,4BAAAA,0BAA0B,MAAM;AAC9B,YAAQ,OAAO,IAAI;AAAA,EAAA,CACpB;AAEM,SAAA;AACT;;"}
|
package/dist/cjs/useForm.d.cts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { FormApi, FormOptions, FormState, Validator } from '@tanstack/form-core';
|
|
2
2
|
import { ReactNode } from 'react';
|
|
3
|
-
import { FieldComponent
|
|
3
|
+
import { FieldComponent } from './useField.cjs';
|
|
4
4
|
import { NoInfer } from '@tanstack/react-store';
|
|
5
5
|
/**
|
|
6
6
|
* Fields that are added onto the `FormAPI` from `@tanstack/form-core` and returned from `useForm`
|
|
@@ -10,14 +10,6 @@ export interface ReactFormApi<TFormData, TFormValidator extends Validator<TFormD
|
|
|
10
10
|
* A React component to render form fields. With this, you can render and manage individual form fields.
|
|
11
11
|
*/
|
|
12
12
|
Field: FieldComponent<TFormData, TFormValidator>;
|
|
13
|
-
/**
|
|
14
|
-
* A custom React hook that provides functionalities related to individual form fields. It gives you access to field values, errors, and allows you to set or update field values.
|
|
15
|
-
*/
|
|
16
|
-
useField: UseField<TFormData, TFormValidator>;
|
|
17
|
-
/**
|
|
18
|
-
* A `useStore` hook that connects to the internal store of the form. It can be used to access the form's current state or any other related state information. You can optionally pass in a selector function to cherry-pick specific parts of the state
|
|
19
|
-
*/
|
|
20
|
-
useStore: <TSelected = NoInfer<FormState<TFormData>>>(selector?: (state: NoInfer<FormState<TFormData>>) => TSelected) => TSelected;
|
|
21
13
|
/**
|
|
22
14
|
* A `Subscribe` function that allows you to listen and react to changes in the form's state. It's especially useful when you need to execute side effects or render specific components in response to state updates.
|
|
23
15
|
*/
|
package/dist/esm/index.d.ts
CHANGED
package/dist/esm/index.js
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
export * from "@tanstack/form-core";
|
|
2
|
+
import { useStore } from "@tanstack/react-store";
|
|
2
3
|
import { useForm } from "./useForm.js";
|
|
3
4
|
import { Field, useField } from "./useField.js";
|
|
4
5
|
import { useTransform } from "./useTransform.js";
|
|
@@ -6,6 +7,7 @@ export {
|
|
|
6
7
|
Field,
|
|
7
8
|
useField,
|
|
8
9
|
useForm,
|
|
10
|
+
useStore,
|
|
9
11
|
useTransform
|
|
10
12
|
};
|
|
11
13
|
//# sourceMappingURL=index.js.map
|
package/dist/esm/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sources":[],"sourcesContent":[],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;"}
|
package/dist/esm/useForm.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { FormApi, FormOptions, FormState, Validator } from '@tanstack/form-core';
|
|
2
2
|
import { ReactNode } from 'react';
|
|
3
|
-
import { FieldComponent
|
|
3
|
+
import { FieldComponent } from './useField.js';
|
|
4
4
|
import { NoInfer } from '@tanstack/react-store';
|
|
5
5
|
/**
|
|
6
6
|
* Fields that are added onto the `FormAPI` from `@tanstack/form-core` and returned from `useForm`
|
|
@@ -10,14 +10,6 @@ export interface ReactFormApi<TFormData, TFormValidator extends Validator<TFormD
|
|
|
10
10
|
* A React component to render form fields. With this, you can render and manage individual form fields.
|
|
11
11
|
*/
|
|
12
12
|
Field: FieldComponent<TFormData, TFormValidator>;
|
|
13
|
-
/**
|
|
14
|
-
* A custom React hook that provides functionalities related to individual form fields. It gives you access to field values, errors, and allows you to set or update field values.
|
|
15
|
-
*/
|
|
16
|
-
useField: UseField<TFormData, TFormValidator>;
|
|
17
|
-
/**
|
|
18
|
-
* A `useStore` hook that connects to the internal store of the form. It can be used to access the form's current state or any other related state information. You can optionally pass in a selector function to cherry-pick specific parts of the state
|
|
19
|
-
*/
|
|
20
|
-
useStore: <TSelected = NoInfer<FormState<TFormData>>>(selector?: (state: NoInfer<FormState<TFormData>>) => TSelected) => TSelected;
|
|
21
13
|
/**
|
|
22
14
|
* A `Subscribe` function that allows you to listen and react to changes in the form's state. It's especially useful when you need to execute side effects or render specific components in response to state updates.
|
|
23
15
|
*/
|
package/dist/esm/useForm.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useForm.js","sources":["../../src/useForm.tsx"],"sourcesContent":["import { FormApi, functionalUpdate } from '@tanstack/form-core'\nimport { useStore } from '@tanstack/react-store'\nimport React, { useState } from 'react'\nimport { Field } from './useField'\nimport { useIsomorphicLayoutEffect } from './useIsomorphicLayoutEffect'\nimport type { PropsWithChildren, ReactNode } from 'react'\nimport type { FieldComponent
|
|
1
|
+
{"version":3,"file":"useForm.js","sources":["../../src/useForm.tsx"],"sourcesContent":["import { FormApi, functionalUpdate } from '@tanstack/form-core'\nimport { useStore } from '@tanstack/react-store'\nimport React, { useState } from 'react'\nimport { Field } from './useField'\nimport { useIsomorphicLayoutEffect } from './useIsomorphicLayoutEffect'\nimport type { PropsWithChildren, ReactNode } from 'react'\nimport type { FieldComponent } from './useField'\nimport type { NoInfer } from '@tanstack/react-store'\nimport type { FormOptions, FormState, Validator } from '@tanstack/form-core'\n\n/**\n * Fields that are added onto the `FormAPI` from `@tanstack/form-core` and returned from `useForm`\n */\nexport interface ReactFormApi<\n TFormData,\n TFormValidator extends Validator<TFormData, unknown> | undefined = undefined,\n> {\n /**\n * A React component to render form fields. With this, you can render and manage individual form fields.\n */\n Field: FieldComponent<TFormData, TFormValidator>\n /**\n * A `Subscribe` function that allows you to listen and react to changes in the form's state. It's especially useful when you need to execute side effects or render specific components in response to state updates.\n */\n Subscribe: <TSelected = NoInfer<FormState<TFormData>>>(props: {\n selector?: (state: NoInfer<FormState<TFormData>>) => TSelected\n children: ((state: NoInfer<TSelected>) => ReactNode) | ReactNode\n }) => ReactNode\n}\n\n/**\n * An extended version of the `FormApi` class that includes React-specific functionalities from `ReactFormApi`\n */\nexport type ReactFormExtendedApi<\n TFormData,\n TFormValidator extends Validator<TFormData, unknown> | undefined = undefined,\n> = FormApi<TFormData, TFormValidator> & ReactFormApi<TFormData, TFormValidator>\n\nfunction LocalSubscribe({\n form,\n selector,\n children,\n}: PropsWithChildren<{\n form: FormApi<any, any>\n selector: (state: FormState<any>) => FormState<any>\n}>) {\n const data = useStore(form.store, selector)\n\n return functionalUpdate(children, data)\n}\n\n/**\n * A custom React Hook that returns an extended instance of the `FormApi` class.\n *\n * This API encapsulates all the necessary functionalities related to the form. It allows you to manage form state, handle submissions, and interact with form fields\n */\nexport function useForm<\n TFormData,\n TFormValidator extends Validator<TFormData, unknown> | undefined = undefined,\n>(opts?: FormOptions<TFormData, TFormValidator>) {\n const [formApi] = useState(() => {\n const api = new FormApi<TFormData, TFormValidator>(opts)\n\n const extendedApi: ReactFormExtendedApi<TFormData, TFormValidator> =\n api as never\n extendedApi.Field = function APIField(props) {\n return <Field {...props} form={api} />\n }\n extendedApi.Subscribe = (props: any) => {\n return (\n <LocalSubscribe\n form={api}\n selector={props.selector}\n children={props.children}\n />\n )\n }\n\n return extendedApi\n })\n\n useIsomorphicLayoutEffect(formApi.mount, [])\n\n useStore(formApi.store, (state) => state.isSubmitting)\n\n /**\n * formApi.update should not have any side effects. Think of it like a `useRef`\n * that we need to keep updated every render with the most up-to-date information.\n */\n useIsomorphicLayoutEffect(() => {\n formApi.update(opts)\n })\n\n return formApi\n}\n"],"names":[],"mappings":";;;;;;AAsCA,SAAS,eAAe;AAAA,EACtB;AAAA,EACA;AAAA,EACA;AACF,GAGI;AACF,QAAM,OAAO,SAAS,KAAK,OAAO,QAAQ;AAEnC,SAAA,iBAAiB,UAAU,IAAI;AACxC;AAOO,SAAS,QAGd,MAA+C;AAC/C,QAAM,CAAC,OAAO,IAAI,SAAS,MAAM;AACzB,UAAA,MAAM,IAAI,QAAmC,IAAI;AAEvD,UAAM,cACJ;AACU,gBAAA,QAAQ,SAAS,SAAS,OAAO;AAC3C,aAAQ,oBAAA,OAAA,EAAO,GAAG,OAAO,MAAM,KAAK;AAAA,IACtC;AACY,gBAAA,YAAY,CAAC,UAAe;AAEpC,aAAA;AAAA,QAAC;AAAA,QAAA;AAAA,UACC,MAAM;AAAA,UACN,UAAU,MAAM;AAAA,UAChB,UAAU,MAAM;AAAA,QAAA;AAAA,MAClB;AAAA,IAEJ;AAEO,WAAA;AAAA,EAAA,CACR;AAEyB,4BAAA,QAAQ,OAAO,EAAE;AAE3C,WAAS,QAAQ,OAAO,CAAC,UAAU,MAAM,YAAY;AAMrD,4BAA0B,MAAM;AAC9B,YAAQ,OAAO,IAAI;AAAA,EAAA,CACpB;AAEM,SAAA;AACT;"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tanstack/react-form",
|
|
3
|
-
"version": "0.39.
|
|
3
|
+
"version": "0.39.2",
|
|
4
4
|
"description": "Powerful, type-safe forms for React.",
|
|
5
5
|
"author": "tannerlinsley",
|
|
6
6
|
"license": "MIT",
|
|
@@ -67,10 +67,10 @@
|
|
|
67
67
|
"src"
|
|
68
68
|
],
|
|
69
69
|
"dependencies": {
|
|
70
|
-
"@remix-run/node": "^2.
|
|
71
|
-
"@tanstack/react-store": "^0.
|
|
70
|
+
"@remix-run/node": "^2.15.0",
|
|
71
|
+
"@tanstack/react-store": "^0.6.1",
|
|
72
72
|
"decode-formdata": "^0.8.0",
|
|
73
|
-
"@tanstack/form-core": "0.39.
|
|
73
|
+
"@tanstack/form-core": "0.39.1"
|
|
74
74
|
},
|
|
75
75
|
"devDependencies": {
|
|
76
76
|
"@tanstack/start": "^1.81.1",
|
package/src/index.ts
CHANGED
package/src/useForm.tsx
CHANGED
|
@@ -4,7 +4,7 @@ import React, { useState } from 'react'
|
|
|
4
4
|
import { Field } from './useField'
|
|
5
5
|
import { useIsomorphicLayoutEffect } from './useIsomorphicLayoutEffect'
|
|
6
6
|
import type { PropsWithChildren, ReactNode } from 'react'
|
|
7
|
-
import type { FieldComponent
|
|
7
|
+
import type { FieldComponent } from './useField'
|
|
8
8
|
import type { NoInfer } from '@tanstack/react-store'
|
|
9
9
|
import type { FormOptions, FormState, Validator } from '@tanstack/form-core'
|
|
10
10
|
|
|
@@ -19,16 +19,6 @@ export interface ReactFormApi<
|
|
|
19
19
|
* A React component to render form fields. With this, you can render and manage individual form fields.
|
|
20
20
|
*/
|
|
21
21
|
Field: FieldComponent<TFormData, TFormValidator>
|
|
22
|
-
/**
|
|
23
|
-
* A custom React hook that provides functionalities related to individual form fields. It gives you access to field values, errors, and allows you to set or update field values.
|
|
24
|
-
*/
|
|
25
|
-
useField: UseField<TFormData, TFormValidator>
|
|
26
|
-
/**
|
|
27
|
-
* A `useStore` hook that connects to the internal store of the form. It can be used to access the form's current state or any other related state information. You can optionally pass in a selector function to cherry-pick specific parts of the state
|
|
28
|
-
*/
|
|
29
|
-
useStore: <TSelected = NoInfer<FormState<TFormData>>>(
|
|
30
|
-
selector?: (state: NoInfer<FormState<TFormData>>) => TSelected,
|
|
31
|
-
) => TSelected
|
|
32
22
|
/**
|
|
33
23
|
* A `Subscribe` function that allows you to listen and react to changes in the form's state. It's especially useful when you need to execute side effects or render specific components in response to state updates.
|
|
34
24
|
*/
|