@tanstack/react-form 0.19.3 → 0.19.5
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/createFormFactory.d.cts +3 -2
- package/dist/cjs/types.d.cts +2 -1
- package/dist/cjs/useField.d.cts +4 -5
- package/dist/cjs/useForm.d.cts +5 -6
- package/dist/cjs/useIsomorphicLayoutEffect.d.cts +1 -1
- package/dist/cjs/useTransform.d.cts +2 -1
- package/dist/cjs/validateFormData.d.cts +2 -1
- package/dist/esm/createFormFactory.d.ts +3 -2
- package/dist/esm/types.d.ts +2 -1
- package/dist/esm/useField.d.ts +4 -5
- package/dist/esm/useForm.d.ts +5 -6
- package/dist/esm/useIsomorphicLayoutEffect.d.ts +1 -1
- package/dist/esm/useTransform.d.ts +2 -1
- package/dist/esm/validateFormData.d.ts +2 -1
- package/package.json +5 -16
- package/src/tests/useField.test.tsx +57 -0
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { Field, useField } from './useField.cjs';
|
|
2
|
-
import
|
|
3
|
-
import
|
|
2
|
+
import { ValidateFormData } from './validateFormData.cjs';
|
|
3
|
+
import { FormApi, FormOptions, Validator } from '@tanstack/form-core';
|
|
4
|
+
|
|
4
5
|
export type FormFactory<TFormData, TFormValidator extends Validator<TFormData, unknown> | undefined = undefined> = {
|
|
5
6
|
useForm: (opts?: FormOptions<TFormData, TFormValidator>) => FormApi<TFormData, TFormValidator>;
|
|
6
7
|
useField: typeof useField;
|
package/dist/cjs/types.d.cts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import
|
|
1
|
+
import { DeepKeys, DeepValue, FieldApiOptions, Validator } from '@tanstack/form-core';
|
|
2
|
+
|
|
2
3
|
export type UseFieldOptions<TParentData, TName extends DeepKeys<TParentData>, TFieldValidator extends Validator<DeepValue<TParentData, TName>, unknown> | undefined = undefined, TFormValidator extends Validator<TParentData, unknown> | undefined = undefined, TData extends DeepValue<TParentData, TName> = DeepValue<TParentData, TName>> = FieldApiOptions<TParentData, TName, TFieldValidator, TFormValidator, TData> & {
|
|
3
4
|
mode?: 'value' | 'array';
|
|
4
5
|
};
|
package/dist/cjs/useField.d.cts
CHANGED
|
@@ -1,8 +1,7 @@
|
|
|
1
|
-
|
|
2
|
-
import
|
|
3
|
-
import {
|
|
4
|
-
|
|
5
|
-
import type { DeepKeys, DeepValue, Validator } from '@tanstack/form-core';
|
|
1
|
+
import { default as React } from 'rehackt';
|
|
2
|
+
import { FieldApi, DeepKeys, DeepValue, Validator } from '@tanstack/form-core';
|
|
3
|
+
import { UseFieldOptions } from './types.cjs';
|
|
4
|
+
|
|
6
5
|
declare module '@tanstack/form-core' {
|
|
7
6
|
interface FieldApi<TParentData, TName extends DeepKeys<TParentData>, TFieldValidator extends Validator<DeepValue<TParentData, TName>, unknown> | undefined = undefined, TFormValidator extends Validator<TParentData, unknown> | undefined = undefined, TData extends DeepValue<TParentData, TName> = DeepValue<TParentData, TName>> {
|
|
8
7
|
Field: FieldComponent<TParentData, TFormValidator>;
|
package/dist/cjs/useForm.d.cts
CHANGED
|
@@ -1,9 +1,8 @@
|
|
|
1
|
-
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
5
|
-
|
|
6
|
-
import type { FormOptions, FormState, Validator } from '@tanstack/form-core';
|
|
1
|
+
import { FormApi, FormOptions, FormState, Validator } from '@tanstack/form-core';
|
|
2
|
+
import { ReactNode } from 'rehackt';
|
|
3
|
+
import { FieldComponent, UseField } from './useField.cjs';
|
|
4
|
+
import { NoInfer } from '@tanstack/react-store';
|
|
5
|
+
|
|
7
6
|
declare module '@tanstack/form-core' {
|
|
8
7
|
interface FormApi<TFormData, TFormValidator> {
|
|
9
8
|
Field: FieldComponent<TFormData, TFormValidator>;
|
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import
|
|
1
|
+
import { FormApi, Validator } from '@tanstack/form-core';
|
|
2
|
+
|
|
2
3
|
export declare function useTransform<TFormData, TFormValidator extends Validator<TFormData, unknown> | undefined = undefined>(fn: (formBase: FormApi<TFormData, TFormValidator>) => FormApi<TFormData, TFormValidator>, deps: unknown[]): {
|
|
3
4
|
fn: (formBase: FormApi<TFormData, TFormValidator>) => FormApi<TFormData, TFormValidator>;
|
|
4
5
|
deps: unknown[];
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { decode } from 'decode-formdata';
|
|
2
|
-
import
|
|
2
|
+
import { FormApi, FormOptions, ValidationError, Validator } from '@tanstack/form-core';
|
|
3
|
+
|
|
3
4
|
type OnServerValidateFn<TFormData> = (props: {
|
|
4
5
|
value: TFormData;
|
|
5
6
|
}) => ValidationError;
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { Field, useField } from './useField.js';
|
|
2
|
-
import
|
|
3
|
-
import
|
|
2
|
+
import { ValidateFormData } from './validateFormData.js';
|
|
3
|
+
import { FormApi, FormOptions, Validator } from '@tanstack/form-core';
|
|
4
|
+
|
|
4
5
|
export type FormFactory<TFormData, TFormValidator extends Validator<TFormData, unknown> | undefined = undefined> = {
|
|
5
6
|
useForm: (opts?: FormOptions<TFormData, TFormValidator>) => FormApi<TFormData, TFormValidator>;
|
|
6
7
|
useField: typeof useField;
|
package/dist/esm/types.d.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import
|
|
1
|
+
import { DeepKeys, DeepValue, FieldApiOptions, Validator } from '@tanstack/form-core';
|
|
2
|
+
|
|
2
3
|
export type UseFieldOptions<TParentData, TName extends DeepKeys<TParentData>, TFieldValidator extends Validator<DeepValue<TParentData, TName>, unknown> | undefined = undefined, TFormValidator extends Validator<TParentData, unknown> | undefined = undefined, TData extends DeepValue<TParentData, TName> = DeepValue<TParentData, TName>> = FieldApiOptions<TParentData, TName, TFieldValidator, TFormValidator, TData> & {
|
|
3
4
|
mode?: 'value' | 'array';
|
|
4
5
|
};
|
package/dist/esm/useField.d.ts
CHANGED
|
@@ -1,8 +1,7 @@
|
|
|
1
|
-
|
|
2
|
-
import
|
|
3
|
-
import {
|
|
4
|
-
|
|
5
|
-
import type { DeepKeys, DeepValue, Validator } from '@tanstack/form-core';
|
|
1
|
+
import { default as React } from 'rehackt';
|
|
2
|
+
import { FieldApi, DeepKeys, DeepValue, Validator } from '@tanstack/form-core';
|
|
3
|
+
import { UseFieldOptions } from './types.js';
|
|
4
|
+
|
|
6
5
|
declare module '@tanstack/form-core' {
|
|
7
6
|
interface FieldApi<TParentData, TName extends DeepKeys<TParentData>, TFieldValidator extends Validator<DeepValue<TParentData, TName>, unknown> | undefined = undefined, TFormValidator extends Validator<TParentData, unknown> | undefined = undefined, TData extends DeepValue<TParentData, TName> = DeepValue<TParentData, TName>> {
|
|
8
7
|
Field: FieldComponent<TParentData, TFormValidator>;
|
package/dist/esm/useForm.d.ts
CHANGED
|
@@ -1,9 +1,8 @@
|
|
|
1
|
-
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
5
|
-
|
|
6
|
-
import type { FormOptions, FormState, Validator } from '@tanstack/form-core';
|
|
1
|
+
import { FormApi, FormOptions, FormState, Validator } from '@tanstack/form-core';
|
|
2
|
+
import { ReactNode } from 'rehackt';
|
|
3
|
+
import { FieldComponent, UseField } from './useField.js';
|
|
4
|
+
import { NoInfer } from '@tanstack/react-store';
|
|
5
|
+
|
|
7
6
|
declare module '@tanstack/form-core' {
|
|
8
7
|
interface FormApi<TFormData, TFormValidator> {
|
|
9
8
|
Field: FieldComponent<TFormData, TFormValidator>;
|
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import
|
|
1
|
+
import { FormApi, Validator } from '@tanstack/form-core';
|
|
2
|
+
|
|
2
3
|
export declare function useTransform<TFormData, TFormValidator extends Validator<TFormData, unknown> | undefined = undefined>(fn: (formBase: FormApi<TFormData, TFormValidator>) => FormApi<TFormData, TFormValidator>, deps: unknown[]): {
|
|
3
4
|
fn: (formBase: FormApi<TFormData, TFormValidator>) => FormApi<TFormData, TFormValidator>;
|
|
4
5
|
deps: unknown[];
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { decode } from 'decode-formdata';
|
|
2
|
-
import
|
|
2
|
+
import { FormApi, FormOptions, ValidationError, Validator } from '@tanstack/form-core';
|
|
3
|
+
|
|
3
4
|
type OnServerValidateFn<TFormData> = (props: {
|
|
4
5
|
value: TFormData;
|
|
5
6
|
}) => ValidationError;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tanstack/react-form",
|
|
3
|
-
"version": "0.19.
|
|
3
|
+
"version": "0.19.5",
|
|
4
4
|
"description": "Powerful, type-safe forms for React.",
|
|
5
5
|
"author": "tannerlinsley",
|
|
6
6
|
"license": "MIT",
|
|
@@ -37,28 +37,17 @@
|
|
|
37
37
|
"@types/react-dom": "^18.2.19",
|
|
38
38
|
"@vitejs/plugin-react": "^4.2.1",
|
|
39
39
|
"react": "^18.2.0",
|
|
40
|
-
"react-dom": "^18.2.0"
|
|
40
|
+
"react-dom": "^18.2.0",
|
|
41
|
+
"vite": "^5.0.10"
|
|
41
42
|
},
|
|
42
43
|
"dependencies": {
|
|
43
44
|
"@tanstack/react-store": "^0.3.1",
|
|
44
45
|
"decode-formdata": "^0.4.0",
|
|
45
46
|
"rehackt": "^0.0.3",
|
|
46
|
-
"@tanstack/form-core": "0.19.
|
|
47
|
+
"@tanstack/form-core": "0.19.5"
|
|
47
48
|
},
|
|
48
49
|
"peerDependencies": {
|
|
49
50
|
"react": "^17.0.0 || ^18.0.0"
|
|
50
51
|
},
|
|
51
|
-
"scripts": {
|
|
52
|
-
"clean": "rimraf ./dist && rimraf ./coverage",
|
|
53
|
-
"test:eslint": "eslint --ext .ts,.tsx ./src",
|
|
54
|
-
"test:types:versions49": "node ../../node_modules/typescript49/lib/tsc.js --project tsconfig.legacy.json",
|
|
55
|
-
"test:types:versions50": "node ../../node_modules/typescript50/lib/tsc.js --project tsconfig.50.json",
|
|
56
|
-
"test:types:versions51": "node ../../node_modules/typescript51/lib/tsc.js",
|
|
57
|
-
"test:types:versions52": "tsc",
|
|
58
|
-
"test:types": "pnpm run \"/^test:types:versions.*/\"",
|
|
59
|
-
"test:lib": "vitest",
|
|
60
|
-
"test:lib:dev": "pnpm run test:lib --watch",
|
|
61
|
-
"test:build": "publint --strict",
|
|
62
|
-
"build": "vite build"
|
|
63
|
-
}
|
|
52
|
+
"scripts": {}
|
|
64
53
|
}
|
|
@@ -900,4 +900,61 @@ describe('useField', () => {
|
|
|
900
900
|
expect(queryByText('Test')).not.toBeInTheDocument()
|
|
901
901
|
expect(await findByText('User')).toBeInTheDocument()
|
|
902
902
|
})
|
|
903
|
+
|
|
904
|
+
it('should validate async on submit without debounce', async () => {
|
|
905
|
+
type Person = {
|
|
906
|
+
firstName: string
|
|
907
|
+
lastName: string
|
|
908
|
+
}
|
|
909
|
+
const mockFn = vi.fn()
|
|
910
|
+
const error = 'Please enter a different value'
|
|
911
|
+
const formFactory = createFormFactory<Person>()
|
|
912
|
+
|
|
913
|
+
function Comp() {
|
|
914
|
+
const form = formFactory.useForm({
|
|
915
|
+
defaultValues: {
|
|
916
|
+
firstName: '',
|
|
917
|
+
lastName: '',
|
|
918
|
+
},
|
|
919
|
+
validators: {
|
|
920
|
+
onChangeAsyncDebounceMs: 1000000,
|
|
921
|
+
onChangeAsync: async () => {
|
|
922
|
+
mockFn()
|
|
923
|
+
await sleep(10)
|
|
924
|
+
return error
|
|
925
|
+
},
|
|
926
|
+
},
|
|
927
|
+
})
|
|
928
|
+
const errors = form.useStore((s) => s.errors)
|
|
929
|
+
|
|
930
|
+
return (
|
|
931
|
+
<>
|
|
932
|
+
<form.Field
|
|
933
|
+
name="firstName"
|
|
934
|
+
defaultMeta={{ isTouched: true }}
|
|
935
|
+
children={(field) => (
|
|
936
|
+
<div>
|
|
937
|
+
<input
|
|
938
|
+
data-testid="fieldinput"
|
|
939
|
+
name={field.name}
|
|
940
|
+
value={field.state.value}
|
|
941
|
+
onBlur={field.handleBlur}
|
|
942
|
+
onChange={(e) => field.handleChange(e.target.value)}
|
|
943
|
+
/>
|
|
944
|
+
<p>{errors}</p>
|
|
945
|
+
</div>
|
|
946
|
+
)}
|
|
947
|
+
/>
|
|
948
|
+
<button onClick={form.handleSubmit}>Submit</button>
|
|
949
|
+
</>
|
|
950
|
+
)
|
|
951
|
+
}
|
|
952
|
+
|
|
953
|
+
const { getByRole, getByText } = render(<Comp />)
|
|
954
|
+
await user.click(getByRole('button', { name: 'Submit' }))
|
|
955
|
+
|
|
956
|
+
expect(mockFn).toHaveBeenCalledTimes(1)
|
|
957
|
+
await waitFor(() => getByText(error))
|
|
958
|
+
expect(getByText(error)).toBeInTheDocument()
|
|
959
|
+
})
|
|
903
960
|
})
|