@tanstack/react-form 0.42.1 → 0.43.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/nextjs/createServerValidate.cjs +18 -10
- package/dist/cjs/nextjs/createServerValidate.cjs.map +1 -1
- package/dist/cjs/nextjs/createServerValidate.d.cts +5 -9
- package/dist/cjs/nextjs/error.cjs.map +1 -1
- package/dist/cjs/nextjs/error.d.cts +6 -5
- package/dist/cjs/nextjs/types.d.cts +2 -2
- package/dist/cjs/remix/createServerValidate.cjs +18 -10
- package/dist/cjs/remix/createServerValidate.cjs.map +1 -1
- package/dist/cjs/remix/createServerValidate.d.cts +5 -9
- package/dist/cjs/remix/error.cjs.map +1 -1
- package/dist/cjs/remix/error.d.cts +6 -5
- package/dist/cjs/remix/types.d.cts +2 -2
- package/dist/cjs/start/createServerValidate.cjs +21 -12
- package/dist/cjs/start/createServerValidate.cjs.map +1 -1
- package/dist/cjs/start/createServerValidate.d.cts +4 -10
- package/dist/cjs/start/error.cjs.map +1 -1
- package/dist/cjs/start/error.d.cts +6 -5
- package/dist/cjs/start/getFormData.cjs +4 -5
- package/dist/cjs/start/getFormData.cjs.map +1 -1
- package/dist/cjs/start/getFormData.d.cts +2 -3
- package/dist/cjs/start/types.d.cts +2 -2
- package/dist/cjs/types.d.cts +2 -2
- package/dist/cjs/useField.cjs.map +1 -1
- package/dist/cjs/useField.d.cts +10 -10
- package/dist/cjs/useForm.cjs.map +1 -1
- package/dist/cjs/useForm.d.cts +7 -7
- package/dist/cjs/useTransform.cjs.map +1 -1
- package/dist/cjs/useTransform.d.cts +2 -2
- package/dist/esm/nextjs/createServerValidate.d.ts +5 -9
- package/dist/esm/nextjs/createServerValidate.js +18 -10
- package/dist/esm/nextjs/createServerValidate.js.map +1 -1
- package/dist/esm/nextjs/error.d.ts +6 -5
- package/dist/esm/nextjs/error.js.map +1 -1
- package/dist/esm/nextjs/types.d.ts +2 -2
- package/dist/esm/remix/createServerValidate.d.ts +5 -9
- package/dist/esm/remix/createServerValidate.js +18 -10
- package/dist/esm/remix/createServerValidate.js.map +1 -1
- package/dist/esm/remix/error.d.ts +6 -5
- package/dist/esm/remix/error.js.map +1 -1
- package/dist/esm/remix/types.d.ts +2 -2
- package/dist/esm/start/createServerValidate.d.ts +4 -10
- package/dist/esm/start/createServerValidate.js +21 -12
- package/dist/esm/start/createServerValidate.js.map +1 -1
- package/dist/esm/start/error.d.ts +6 -5
- package/dist/esm/start/error.js.map +1 -1
- package/dist/esm/start/getFormData.d.ts +2 -3
- package/dist/esm/start/getFormData.js +4 -5
- package/dist/esm/start/getFormData.js.map +1 -1
- package/dist/esm/start/types.d.ts +2 -2
- package/dist/esm/types.d.ts +2 -2
- package/dist/esm/useField.d.ts +10 -10
- package/dist/esm/useField.js.map +1 -1
- package/dist/esm/useForm.d.ts +7 -7
- package/dist/esm/useForm.js.map +1 -1
- package/dist/esm/useTransform.d.ts +2 -2
- package/dist/esm/useTransform.js.map +1 -1
- package/package.json +16 -11
- package/src/nextjs/createServerValidate.ts +71 -43
- package/src/nextjs/error.ts +13 -6
- package/src/nextjs/types.ts +16 -3
- package/src/remix/createServerValidate.ts +71 -43
- package/src/remix/error.ts +13 -6
- package/src/remix/types.ts +16 -3
- package/src/start/createServerValidate.tsx +73 -47
- package/src/start/error.ts +13 -6
- package/src/start/getFormData.tsx +6 -6
- package/src/start/types.ts +16 -3
- package/src/types.ts +42 -12
- package/src/useField.tsx +295 -58
- package/src/useForm.tsx +132 -14
- package/src/useTransform.ts +38 -4
package/src/useField.tsx
CHANGED
|
@@ -2,20 +2,42 @@ import React, { useMemo, useState } from 'react'
|
|
|
2
2
|
import { useStore } from '@tanstack/react-store'
|
|
3
3
|
import { FieldApi, functionalUpdate } from '@tanstack/form-core'
|
|
4
4
|
import { useIsomorphicLayoutEffect } from './useIsomorphicLayoutEffect'
|
|
5
|
+
import type {
|
|
6
|
+
DeepKeys,
|
|
7
|
+
DeepValue,
|
|
8
|
+
FieldAsyncValidateOrFn,
|
|
9
|
+
FieldValidateOrFn,
|
|
10
|
+
FormAsyncValidateOrFn,
|
|
11
|
+
FormValidateOrFn,
|
|
12
|
+
} from '@tanstack/form-core'
|
|
5
13
|
import type { FunctionComponent, ReactNode } from 'react'
|
|
6
14
|
import type { UseFieldOptions } from './types'
|
|
7
|
-
import type { DeepKeys, DeepValue, Validator } from '@tanstack/form-core'
|
|
8
15
|
|
|
9
16
|
interface ReactFieldApi<
|
|
10
17
|
TParentData,
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
18
|
+
TFormOnMount extends undefined | FormValidateOrFn<TParentData>,
|
|
19
|
+
TFormOnChange extends undefined | FormValidateOrFn<TParentData>,
|
|
20
|
+
TFormOnChangeAsync extends undefined | FormAsyncValidateOrFn<TParentData>,
|
|
21
|
+
TFormOnBlur extends undefined | FormValidateOrFn<TParentData>,
|
|
22
|
+
TFormOnBlurAsync extends undefined | FormAsyncValidateOrFn<TParentData>,
|
|
23
|
+
TFormOnSubmit extends undefined | FormValidateOrFn<TParentData>,
|
|
24
|
+
TFormOnSubmitAsync extends undefined | FormAsyncValidateOrFn<TParentData>,
|
|
25
|
+
TFormOnServer extends undefined | FormAsyncValidateOrFn<TParentData>,
|
|
14
26
|
> {
|
|
15
27
|
/**
|
|
16
28
|
* A pre-bound and type-safe sub-field component using this field as a root.
|
|
17
29
|
*/
|
|
18
|
-
Field: FieldComponent<
|
|
30
|
+
Field: FieldComponent<
|
|
31
|
+
TParentData,
|
|
32
|
+
TFormOnMount,
|
|
33
|
+
TFormOnChange,
|
|
34
|
+
TFormOnChangeAsync,
|
|
35
|
+
TFormOnBlur,
|
|
36
|
+
TFormOnBlurAsync,
|
|
37
|
+
TFormOnSubmit,
|
|
38
|
+
TFormOnSubmitAsync,
|
|
39
|
+
TFormOnServer
|
|
40
|
+
>
|
|
19
41
|
}
|
|
20
42
|
|
|
21
43
|
/**
|
|
@@ -25,21 +47,74 @@ interface ReactFieldApi<
|
|
|
25
47
|
*/
|
|
26
48
|
export type UseField<
|
|
27
49
|
TParentData,
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
50
|
+
TFormOnMount extends undefined | FormValidateOrFn<TParentData>,
|
|
51
|
+
TFormOnChange extends undefined | FormValidateOrFn<TParentData>,
|
|
52
|
+
TFormOnChangeAsync extends undefined | FormAsyncValidateOrFn<TParentData>,
|
|
53
|
+
TFormOnBlur extends undefined | FormValidateOrFn<TParentData>,
|
|
54
|
+
TFormOnBlurAsync extends undefined | FormAsyncValidateOrFn<TParentData>,
|
|
55
|
+
TFormOnSubmit extends undefined | FormValidateOrFn<TParentData>,
|
|
56
|
+
TFormOnSubmitAsync extends undefined | FormAsyncValidateOrFn<TParentData>,
|
|
57
|
+
TFormOnServer extends undefined | FormAsyncValidateOrFn<TParentData>,
|
|
31
58
|
> = <
|
|
32
59
|
TName extends DeepKeys<TParentData>,
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
60
|
+
TData extends DeepValue<TParentData, TName>,
|
|
61
|
+
TOnMount extends undefined | FieldValidateOrFn<TParentData, TName, TData>,
|
|
62
|
+
TOnChange extends undefined | FieldValidateOrFn<TParentData, TName, TData>,
|
|
63
|
+
TOnChangeAsync extends
|
|
64
|
+
| undefined
|
|
65
|
+
| FieldAsyncValidateOrFn<TParentData, TName, TData>,
|
|
66
|
+
TOnBlur extends undefined | FieldValidateOrFn<TParentData, TName, TData>,
|
|
67
|
+
TOnBlurAsync extends
|
|
68
|
+
| undefined
|
|
69
|
+
| FieldAsyncValidateOrFn<TParentData, TName, TData>,
|
|
70
|
+
TOnSubmit extends undefined | FieldValidateOrFn<TParentData, TName, TData>,
|
|
71
|
+
TOnSubmitAsync extends
|
|
72
|
+
| undefined
|
|
73
|
+
| FieldAsyncValidateOrFn<TParentData, TName, TData>,
|
|
37
74
|
>(
|
|
38
75
|
opts: Omit<
|
|
39
|
-
UseFieldOptions<
|
|
76
|
+
UseFieldOptions<
|
|
77
|
+
TParentData,
|
|
78
|
+
TName,
|
|
79
|
+
TData,
|
|
80
|
+
TOnMount,
|
|
81
|
+
TOnChange,
|
|
82
|
+
TOnChangeAsync,
|
|
83
|
+
TOnBlur,
|
|
84
|
+
TOnBlurAsync,
|
|
85
|
+
TOnSubmit,
|
|
86
|
+
TOnSubmitAsync,
|
|
87
|
+
TFormOnMount,
|
|
88
|
+
TFormOnChange,
|
|
89
|
+
TFormOnChangeAsync,
|
|
90
|
+
TFormOnBlur,
|
|
91
|
+
TFormOnBlurAsync,
|
|
92
|
+
TFormOnSubmit,
|
|
93
|
+
TFormOnSubmitAsync,
|
|
94
|
+
TFormOnServer
|
|
95
|
+
>,
|
|
40
96
|
'form'
|
|
41
97
|
>,
|
|
42
|
-
) => FieldApi<
|
|
98
|
+
) => FieldApi<
|
|
99
|
+
TParentData,
|
|
100
|
+
TName,
|
|
101
|
+
TData,
|
|
102
|
+
TOnMount,
|
|
103
|
+
TOnChange,
|
|
104
|
+
TOnChangeAsync,
|
|
105
|
+
TOnBlur,
|
|
106
|
+
TOnBlurAsync,
|
|
107
|
+
TOnSubmit,
|
|
108
|
+
TOnSubmitAsync,
|
|
109
|
+
TFormOnMount,
|
|
110
|
+
TFormOnChange,
|
|
111
|
+
TFormOnChangeAsync,
|
|
112
|
+
TFormOnBlur,
|
|
113
|
+
TFormOnBlurAsync,
|
|
114
|
+
TFormOnSubmit,
|
|
115
|
+
TFormOnSubmitAsync,
|
|
116
|
+
TFormOnServer
|
|
117
|
+
>
|
|
43
118
|
|
|
44
119
|
/**
|
|
45
120
|
* A hook for managing a field in a form.
|
|
@@ -50,20 +125,48 @@ export type UseField<
|
|
|
50
125
|
export function useField<
|
|
51
126
|
TParentData,
|
|
52
127
|
TName extends DeepKeys<TParentData>,
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
|
58
|
-
|
|
|
59
|
-
|
|
128
|
+
TData extends DeepValue<TParentData, TName>,
|
|
129
|
+
TOnMount extends undefined | FieldValidateOrFn<TParentData, TName, TData>,
|
|
130
|
+
TOnChange extends undefined | FieldValidateOrFn<TParentData, TName, TData>,
|
|
131
|
+
TOnChangeAsync extends
|
|
132
|
+
| undefined
|
|
133
|
+
| FieldAsyncValidateOrFn<TParentData, TName, TData>,
|
|
134
|
+
TOnBlur extends undefined | FieldValidateOrFn<TParentData, TName, TData>,
|
|
135
|
+
TOnBlurAsync extends
|
|
136
|
+
| undefined
|
|
137
|
+
| FieldAsyncValidateOrFn<TParentData, TName, TData>,
|
|
138
|
+
TOnSubmit extends undefined | FieldValidateOrFn<TParentData, TName, TData>,
|
|
139
|
+
TOnSubmitAsync extends
|
|
140
|
+
| undefined
|
|
141
|
+
| FieldAsyncValidateOrFn<TParentData, TName, TData>,
|
|
142
|
+
TFormOnMount extends undefined | FormValidateOrFn<TParentData>,
|
|
143
|
+
TFormOnChange extends undefined | FormValidateOrFn<TParentData>,
|
|
144
|
+
TFormOnChangeAsync extends undefined | FormAsyncValidateOrFn<TParentData>,
|
|
145
|
+
TFormOnBlur extends undefined | FormValidateOrFn<TParentData>,
|
|
146
|
+
TFormOnBlurAsync extends undefined | FormAsyncValidateOrFn<TParentData>,
|
|
147
|
+
TFormOnSubmit extends undefined | FormValidateOrFn<TParentData>,
|
|
148
|
+
TFormOnSubmitAsync extends undefined | FormAsyncValidateOrFn<TParentData>,
|
|
149
|
+
TFormOnServer extends undefined | FormAsyncValidateOrFn<TParentData>,
|
|
60
150
|
>(
|
|
61
151
|
opts: UseFieldOptions<
|
|
62
152
|
TParentData,
|
|
63
153
|
TName,
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
154
|
+
TData,
|
|
155
|
+
TOnMount,
|
|
156
|
+
TOnChange,
|
|
157
|
+
TOnChangeAsync,
|
|
158
|
+
TOnBlur,
|
|
159
|
+
TOnBlurAsync,
|
|
160
|
+
TOnSubmit,
|
|
161
|
+
TOnSubmitAsync,
|
|
162
|
+
TFormOnMount,
|
|
163
|
+
TFormOnChange,
|
|
164
|
+
TFormOnChangeAsync,
|
|
165
|
+
TFormOnBlur,
|
|
166
|
+
TFormOnBlurAsync,
|
|
167
|
+
TFormOnSubmit,
|
|
168
|
+
TFormOnSubmitAsync,
|
|
169
|
+
TFormOnServer
|
|
67
170
|
>,
|
|
68
171
|
) {
|
|
69
172
|
const [fieldApi] = useState(() => {
|
|
@@ -73,8 +176,18 @@ export function useField<
|
|
|
73
176
|
name: opts.name,
|
|
74
177
|
})
|
|
75
178
|
|
|
76
|
-
const extendedApi: typeof api &
|
|
77
|
-
|
|
179
|
+
const extendedApi: typeof api &
|
|
180
|
+
ReactFieldApi<
|
|
181
|
+
TParentData,
|
|
182
|
+
TFormOnMount,
|
|
183
|
+
TFormOnChange,
|
|
184
|
+
TFormOnChangeAsync,
|
|
185
|
+
TFormOnBlur,
|
|
186
|
+
TFormOnBlurAsync,
|
|
187
|
+
TFormOnSubmit,
|
|
188
|
+
TFormOnSubmitAsync,
|
|
189
|
+
TFormOnServer
|
|
190
|
+
> = api as never
|
|
78
191
|
|
|
79
192
|
extendedApi.Field = Field as never
|
|
80
193
|
|
|
@@ -109,39 +222,101 @@ export function useField<
|
|
|
109
222
|
type FieldComponentProps<
|
|
110
223
|
TParentData,
|
|
111
224
|
TName extends DeepKeys<TParentData>,
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
|
117
|
-
|
|
|
118
|
-
|
|
225
|
+
TData extends DeepValue<TParentData, TName>,
|
|
226
|
+
TOnMount extends undefined | FieldValidateOrFn<TParentData, TName, TData>,
|
|
227
|
+
TOnChange extends undefined | FieldValidateOrFn<TParentData, TName, TData>,
|
|
228
|
+
TOnChangeAsync extends
|
|
229
|
+
| undefined
|
|
230
|
+
| FieldAsyncValidateOrFn<TParentData, TName, TData>,
|
|
231
|
+
TOnBlur extends undefined | FieldValidateOrFn<TParentData, TName, TData>,
|
|
232
|
+
TOnBlurAsync extends
|
|
233
|
+
| undefined
|
|
234
|
+
| FieldAsyncValidateOrFn<TParentData, TName, TData>,
|
|
235
|
+
TOnSubmit extends undefined | FieldValidateOrFn<TParentData, TName, TData>,
|
|
236
|
+
TOnSubmitAsync extends
|
|
237
|
+
| undefined
|
|
238
|
+
| FieldAsyncValidateOrFn<TParentData, TName, TData>,
|
|
239
|
+
TFormOnMount extends undefined | FormValidateOrFn<TParentData>,
|
|
240
|
+
TFormOnChange extends undefined | FormValidateOrFn<TParentData>,
|
|
241
|
+
TFormOnChangeAsync extends undefined | FormAsyncValidateOrFn<TParentData>,
|
|
242
|
+
TFormOnBlur extends undefined | FormValidateOrFn<TParentData>,
|
|
243
|
+
TFormOnBlurAsync extends undefined | FormAsyncValidateOrFn<TParentData>,
|
|
244
|
+
TFormOnSubmit extends undefined | FormValidateOrFn<TParentData>,
|
|
245
|
+
TFormOnSubmitAsync extends undefined | FormAsyncValidateOrFn<TParentData>,
|
|
246
|
+
TFormOnServer extends undefined | FormAsyncValidateOrFn<TParentData>,
|
|
119
247
|
> = {
|
|
120
248
|
children: (
|
|
121
249
|
fieldApi: FieldApi<
|
|
122
250
|
TParentData,
|
|
123
251
|
TName,
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
252
|
+
TData,
|
|
253
|
+
TOnMount,
|
|
254
|
+
TOnChange,
|
|
255
|
+
TOnChangeAsync,
|
|
256
|
+
TOnBlur,
|
|
257
|
+
TOnBlurAsync,
|
|
258
|
+
TOnSubmit,
|
|
259
|
+
TOnSubmitAsync,
|
|
260
|
+
TFormOnMount,
|
|
261
|
+
TFormOnChange,
|
|
262
|
+
TFormOnChangeAsync,
|
|
263
|
+
TFormOnBlur,
|
|
264
|
+
TFormOnBlurAsync,
|
|
265
|
+
TFormOnSubmit,
|
|
266
|
+
TFormOnSubmitAsync,
|
|
267
|
+
TFormOnServer
|
|
127
268
|
>,
|
|
128
269
|
) => ReactNode
|
|
129
|
-
} & UseFieldOptions<
|
|
270
|
+
} & UseFieldOptions<
|
|
271
|
+
TParentData,
|
|
272
|
+
TName,
|
|
273
|
+
TData,
|
|
274
|
+
TOnMount,
|
|
275
|
+
TOnChange,
|
|
276
|
+
TOnChangeAsync,
|
|
277
|
+
TOnBlur,
|
|
278
|
+
TOnBlurAsync,
|
|
279
|
+
TOnSubmit,
|
|
280
|
+
TOnSubmitAsync,
|
|
281
|
+
TFormOnMount,
|
|
282
|
+
TFormOnChange,
|
|
283
|
+
TFormOnChangeAsync,
|
|
284
|
+
TFormOnBlur,
|
|
285
|
+
TFormOnBlurAsync,
|
|
286
|
+
TFormOnSubmit,
|
|
287
|
+
TFormOnSubmitAsync,
|
|
288
|
+
TFormOnServer
|
|
289
|
+
>
|
|
130
290
|
|
|
131
291
|
/**
|
|
132
292
|
* A type alias representing a field component for a specific form data type.
|
|
133
293
|
*/
|
|
134
294
|
export type FieldComponent<
|
|
135
295
|
TParentData,
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
296
|
+
TFormOnMount extends undefined | FormValidateOrFn<TParentData>,
|
|
297
|
+
TFormOnChange extends undefined | FormValidateOrFn<TParentData>,
|
|
298
|
+
TFormOnChangeAsync extends undefined | FormAsyncValidateOrFn<TParentData>,
|
|
299
|
+
TFormOnBlur extends undefined | FormValidateOrFn<TParentData>,
|
|
300
|
+
TFormOnBlurAsync extends undefined | FormAsyncValidateOrFn<TParentData>,
|
|
301
|
+
TFormOnSubmit extends undefined | FormValidateOrFn<TParentData>,
|
|
302
|
+
TFormOnSubmitAsync extends undefined | FormAsyncValidateOrFn<TParentData>,
|
|
303
|
+
TFormOnServer extends undefined | FormAsyncValidateOrFn<TParentData>,
|
|
139
304
|
> = <
|
|
140
305
|
TName extends DeepKeys<TParentData>,
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
306
|
+
TData extends DeepValue<TParentData, TName>,
|
|
307
|
+
TOnMount extends undefined | FieldValidateOrFn<TParentData, TName, TData>,
|
|
308
|
+
TOnChange extends undefined | FieldValidateOrFn<TParentData, TName, TData>,
|
|
309
|
+
TOnChangeAsync extends
|
|
310
|
+
| undefined
|
|
311
|
+
| FieldAsyncValidateOrFn<TParentData, TName, TData>,
|
|
312
|
+
TOnBlur extends undefined | FieldValidateOrFn<TParentData, TName, TData>,
|
|
313
|
+
TOnBlurAsync extends
|
|
314
|
+
| undefined
|
|
315
|
+
| FieldAsyncValidateOrFn<TParentData, TName, TData>,
|
|
316
|
+
TOnSubmit extends undefined | FieldValidateOrFn<TParentData, TName, TData>,
|
|
317
|
+
TOnSubmitAsync extends
|
|
318
|
+
| undefined
|
|
319
|
+
| FieldAsyncValidateOrFn<TParentData, TName, TData>,
|
|
145
320
|
>({
|
|
146
321
|
children,
|
|
147
322
|
...fieldOptions
|
|
@@ -149,9 +324,22 @@ export type FieldComponent<
|
|
|
149
324
|
FieldComponentProps<
|
|
150
325
|
TParentData,
|
|
151
326
|
TName,
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
327
|
+
TData,
|
|
328
|
+
TOnMount,
|
|
329
|
+
TOnChange,
|
|
330
|
+
TOnChangeAsync,
|
|
331
|
+
TOnBlur,
|
|
332
|
+
TOnBlurAsync,
|
|
333
|
+
TOnSubmit,
|
|
334
|
+
TOnSubmitAsync,
|
|
335
|
+
TFormOnMount,
|
|
336
|
+
TFormOnChange,
|
|
337
|
+
TFormOnChangeAsync,
|
|
338
|
+
TFormOnBlur,
|
|
339
|
+
TFormOnBlurAsync,
|
|
340
|
+
TFormOnSubmit,
|
|
341
|
+
TFormOnSubmitAsync,
|
|
342
|
+
TFormOnServer
|
|
155
343
|
>,
|
|
156
344
|
'form'
|
|
157
345
|
>) => ReactNode
|
|
@@ -164,22 +352,50 @@ export type FieldComponent<
|
|
|
164
352
|
export const Field = (<
|
|
165
353
|
TParentData,
|
|
166
354
|
TName extends DeepKeys<TParentData>,
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
|
172
|
-
|
|
|
173
|
-
|
|
355
|
+
TData extends DeepValue<TParentData, TName>,
|
|
356
|
+
TOnMount extends undefined | FieldValidateOrFn<TParentData, TName, TData>,
|
|
357
|
+
TOnChange extends undefined | FieldValidateOrFn<TParentData, TName, TData>,
|
|
358
|
+
TOnChangeAsync extends
|
|
359
|
+
| undefined
|
|
360
|
+
| FieldAsyncValidateOrFn<TParentData, TName, TData>,
|
|
361
|
+
TOnBlur extends undefined | FieldValidateOrFn<TParentData, TName, TData>,
|
|
362
|
+
TOnBlurAsync extends
|
|
363
|
+
| undefined
|
|
364
|
+
| FieldAsyncValidateOrFn<TParentData, TName, TData>,
|
|
365
|
+
TOnSubmit extends undefined | FieldValidateOrFn<TParentData, TName, TData>,
|
|
366
|
+
TOnSubmitAsync extends
|
|
367
|
+
| undefined
|
|
368
|
+
| FieldAsyncValidateOrFn<TParentData, TName, TData>,
|
|
369
|
+
TFormOnMount extends undefined | FormValidateOrFn<TParentData>,
|
|
370
|
+
TFormOnChange extends undefined | FormValidateOrFn<TParentData>,
|
|
371
|
+
TFormOnChangeAsync extends undefined | FormAsyncValidateOrFn<TParentData>,
|
|
372
|
+
TFormOnBlur extends undefined | FormValidateOrFn<TParentData>,
|
|
373
|
+
TFormOnBlurAsync extends undefined | FormAsyncValidateOrFn<TParentData>,
|
|
374
|
+
TFormOnSubmit extends undefined | FormValidateOrFn<TParentData>,
|
|
375
|
+
TFormOnSubmitAsync extends undefined | FormAsyncValidateOrFn<TParentData>,
|
|
376
|
+
TFormOnServer extends undefined | FormAsyncValidateOrFn<TParentData>,
|
|
174
377
|
>({
|
|
175
378
|
children,
|
|
176
379
|
...fieldOptions
|
|
177
380
|
}: FieldComponentProps<
|
|
178
381
|
TParentData,
|
|
179
382
|
TName,
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
383
|
+
TData,
|
|
384
|
+
TOnMount,
|
|
385
|
+
TOnChange,
|
|
386
|
+
TOnChangeAsync,
|
|
387
|
+
TOnBlur,
|
|
388
|
+
TOnBlurAsync,
|
|
389
|
+
TOnSubmit,
|
|
390
|
+
TOnSubmitAsync,
|
|
391
|
+
TFormOnMount,
|
|
392
|
+
TFormOnChange,
|
|
393
|
+
TFormOnChangeAsync,
|
|
394
|
+
TFormOnBlur,
|
|
395
|
+
TFormOnBlurAsync,
|
|
396
|
+
TFormOnSubmit,
|
|
397
|
+
TFormOnSubmitAsync,
|
|
398
|
+
TFormOnServer
|
|
183
399
|
>): ReactNode => {
|
|
184
400
|
const fieldApi = useField(fieldOptions as any)
|
|
185
401
|
|
|
@@ -194,4 +410,25 @@ export const Field = (<
|
|
|
194
410
|
[children, fieldApi, fieldApi.state.value, fieldApi.state.meta],
|
|
195
411
|
)
|
|
196
412
|
return (<>{jsxToDisplay}</>) as never
|
|
197
|
-
}) satisfies FunctionComponent<
|
|
413
|
+
}) satisfies FunctionComponent<
|
|
414
|
+
FieldComponentProps<
|
|
415
|
+
any,
|
|
416
|
+
any,
|
|
417
|
+
any,
|
|
418
|
+
any,
|
|
419
|
+
any,
|
|
420
|
+
any,
|
|
421
|
+
any,
|
|
422
|
+
any,
|
|
423
|
+
any,
|
|
424
|
+
any,
|
|
425
|
+
any,
|
|
426
|
+
any,
|
|
427
|
+
any,
|
|
428
|
+
any,
|
|
429
|
+
any,
|
|
430
|
+
any,
|
|
431
|
+
any,
|
|
432
|
+
any
|
|
433
|
+
>
|
|
434
|
+
>
|
package/src/useForm.tsx
CHANGED
|
@@ -3,27 +3,79 @@ import { useStore } from '@tanstack/react-store'
|
|
|
3
3
|
import React, { useState } from 'react'
|
|
4
4
|
import { Field } from './useField'
|
|
5
5
|
import { useIsomorphicLayoutEffect } from './useIsomorphicLayoutEffect'
|
|
6
|
+
import type {
|
|
7
|
+
AnyFormApi,
|
|
8
|
+
AnyFormState,
|
|
9
|
+
FormAsyncValidateOrFn,
|
|
10
|
+
FormOptions,
|
|
11
|
+
FormState,
|
|
12
|
+
FormValidateOrFn,
|
|
13
|
+
} from '@tanstack/form-core'
|
|
6
14
|
import type { PropsWithChildren, ReactNode } from 'react'
|
|
7
15
|
import type { FieldComponent } from './useField'
|
|
8
16
|
import type { NoInfer } from '@tanstack/react-store'
|
|
9
|
-
import type { FormOptions, FormState, Validator } from '@tanstack/form-core'
|
|
10
17
|
|
|
11
18
|
/**
|
|
12
19
|
* Fields that are added onto the `FormAPI` from `@tanstack/form-core` and returned from `useForm`
|
|
13
20
|
*/
|
|
14
21
|
export interface ReactFormApi<
|
|
15
22
|
TFormData,
|
|
16
|
-
|
|
23
|
+
TOnMount extends undefined | FormValidateOrFn<TFormData>,
|
|
24
|
+
TOnChange extends undefined | FormValidateOrFn<TFormData>,
|
|
25
|
+
TOnChangeAsync extends undefined | FormAsyncValidateOrFn<TFormData>,
|
|
26
|
+
TOnBlur extends undefined | FormValidateOrFn<TFormData>,
|
|
27
|
+
TOnBlurAsync extends undefined | FormAsyncValidateOrFn<TFormData>,
|
|
28
|
+
TOnSubmit extends undefined | FormValidateOrFn<TFormData>,
|
|
29
|
+
TOnSubmitAsync extends undefined | FormAsyncValidateOrFn<TFormData>,
|
|
30
|
+
TOnServer extends undefined | FormAsyncValidateOrFn<TFormData>,
|
|
17
31
|
> {
|
|
18
32
|
/**
|
|
19
33
|
* A React component to render form fields. With this, you can render and manage individual form fields.
|
|
20
34
|
*/
|
|
21
|
-
Field: FieldComponent<
|
|
35
|
+
Field: FieldComponent<
|
|
36
|
+
TFormData,
|
|
37
|
+
TOnMount,
|
|
38
|
+
TOnChange,
|
|
39
|
+
TOnChangeAsync,
|
|
40
|
+
TOnBlur,
|
|
41
|
+
TOnBlurAsync,
|
|
42
|
+
TOnSubmit,
|
|
43
|
+
TOnSubmitAsync,
|
|
44
|
+
TOnServer
|
|
45
|
+
>
|
|
22
46
|
/**
|
|
23
47
|
* 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.
|
|
24
48
|
*/
|
|
25
|
-
Subscribe: <
|
|
26
|
-
|
|
49
|
+
Subscribe: <
|
|
50
|
+
TSelected = NoInfer<
|
|
51
|
+
FormState<
|
|
52
|
+
TFormData,
|
|
53
|
+
TOnMount,
|
|
54
|
+
TOnChange,
|
|
55
|
+
TOnChangeAsync,
|
|
56
|
+
TOnBlur,
|
|
57
|
+
TOnBlurAsync,
|
|
58
|
+
TOnSubmit,
|
|
59
|
+
TOnSubmitAsync,
|
|
60
|
+
TOnServer
|
|
61
|
+
>
|
|
62
|
+
>,
|
|
63
|
+
>(props: {
|
|
64
|
+
selector?: (
|
|
65
|
+
state: NoInfer<
|
|
66
|
+
FormState<
|
|
67
|
+
TFormData,
|
|
68
|
+
TOnMount,
|
|
69
|
+
TOnChange,
|
|
70
|
+
TOnChangeAsync,
|
|
71
|
+
TOnBlur,
|
|
72
|
+
TOnBlurAsync,
|
|
73
|
+
TOnSubmit,
|
|
74
|
+
TOnSubmitAsync,
|
|
75
|
+
TOnServer
|
|
76
|
+
>
|
|
77
|
+
>,
|
|
78
|
+
) => TSelected
|
|
27
79
|
children: ((state: NoInfer<TSelected>) => ReactNode) | ReactNode
|
|
28
80
|
}) => ReactNode
|
|
29
81
|
}
|
|
@@ -33,16 +85,44 @@ export interface ReactFormApi<
|
|
|
33
85
|
*/
|
|
34
86
|
export type ReactFormExtendedApi<
|
|
35
87
|
TFormData,
|
|
36
|
-
|
|
37
|
-
|
|
88
|
+
TOnMount extends undefined | FormValidateOrFn<TFormData>,
|
|
89
|
+
TOnChange extends undefined | FormValidateOrFn<TFormData>,
|
|
90
|
+
TOnChangeAsync extends undefined | FormAsyncValidateOrFn<TFormData>,
|
|
91
|
+
TOnBlur extends undefined | FormValidateOrFn<TFormData>,
|
|
92
|
+
TOnBlurAsync extends undefined | FormAsyncValidateOrFn<TFormData>,
|
|
93
|
+
TOnSubmit extends undefined | FormValidateOrFn<TFormData>,
|
|
94
|
+
TOnSubmitAsync extends undefined | FormAsyncValidateOrFn<TFormData>,
|
|
95
|
+
TOnServer extends undefined | FormAsyncValidateOrFn<TFormData>,
|
|
96
|
+
> = FormApi<
|
|
97
|
+
TFormData,
|
|
98
|
+
TOnMount,
|
|
99
|
+
TOnChange,
|
|
100
|
+
TOnChangeAsync,
|
|
101
|
+
TOnBlur,
|
|
102
|
+
TOnBlurAsync,
|
|
103
|
+
TOnSubmit,
|
|
104
|
+
TOnSubmitAsync,
|
|
105
|
+
TOnServer
|
|
106
|
+
> &
|
|
107
|
+
ReactFormApi<
|
|
108
|
+
TFormData,
|
|
109
|
+
TOnMount,
|
|
110
|
+
TOnChange,
|
|
111
|
+
TOnChangeAsync,
|
|
112
|
+
TOnBlur,
|
|
113
|
+
TOnBlurAsync,
|
|
114
|
+
TOnSubmit,
|
|
115
|
+
TOnSubmitAsync,
|
|
116
|
+
TOnServer
|
|
117
|
+
>
|
|
38
118
|
|
|
39
119
|
function LocalSubscribe({
|
|
40
120
|
form,
|
|
41
121
|
selector,
|
|
42
122
|
children,
|
|
43
123
|
}: PropsWithChildren<{
|
|
44
|
-
form:
|
|
45
|
-
selector: (state:
|
|
124
|
+
form: AnyFormApi
|
|
125
|
+
selector: (state: AnyFormState) => AnyFormState
|
|
46
126
|
}>) {
|
|
47
127
|
const data = useStore(form.store, selector)
|
|
48
128
|
|
|
@@ -56,13 +136,51 @@ function LocalSubscribe({
|
|
|
56
136
|
*/
|
|
57
137
|
export function useForm<
|
|
58
138
|
TFormData,
|
|
59
|
-
|
|
60
|
-
|
|
139
|
+
TOnMount extends undefined | FormValidateOrFn<TFormData>,
|
|
140
|
+
TOnChange extends undefined | FormValidateOrFn<TFormData>,
|
|
141
|
+
TOnChangeAsync extends undefined | FormAsyncValidateOrFn<TFormData>,
|
|
142
|
+
TOnBlur extends undefined | FormValidateOrFn<TFormData>,
|
|
143
|
+
TOnBlurAsync extends undefined | FormAsyncValidateOrFn<TFormData>,
|
|
144
|
+
TOnSubmit extends undefined | FormValidateOrFn<TFormData>,
|
|
145
|
+
TOnSubmitAsync extends undefined | FormAsyncValidateOrFn<TFormData>,
|
|
146
|
+
TOnServer extends undefined | FormAsyncValidateOrFn<TFormData>,
|
|
147
|
+
>(
|
|
148
|
+
opts?: FormOptions<
|
|
149
|
+
TFormData,
|
|
150
|
+
TOnMount,
|
|
151
|
+
TOnChange,
|
|
152
|
+
TOnChangeAsync,
|
|
153
|
+
TOnBlur,
|
|
154
|
+
TOnBlurAsync,
|
|
155
|
+
TOnSubmit,
|
|
156
|
+
TOnSubmitAsync,
|
|
157
|
+
TOnServer
|
|
158
|
+
>,
|
|
159
|
+
) {
|
|
61
160
|
const [formApi] = useState(() => {
|
|
62
|
-
const api = new FormApi<
|
|
161
|
+
const api = new FormApi<
|
|
162
|
+
TFormData,
|
|
163
|
+
TOnMount,
|
|
164
|
+
TOnChange,
|
|
165
|
+
TOnChangeAsync,
|
|
166
|
+
TOnBlur,
|
|
167
|
+
TOnBlurAsync,
|
|
168
|
+
TOnSubmit,
|
|
169
|
+
TOnSubmitAsync,
|
|
170
|
+
TOnServer
|
|
171
|
+
>(opts)
|
|
63
172
|
|
|
64
|
-
const extendedApi: ReactFormExtendedApi<
|
|
65
|
-
|
|
173
|
+
const extendedApi: ReactFormExtendedApi<
|
|
174
|
+
TFormData,
|
|
175
|
+
TOnMount,
|
|
176
|
+
TOnChange,
|
|
177
|
+
TOnChangeAsync,
|
|
178
|
+
TOnBlur,
|
|
179
|
+
TOnBlurAsync,
|
|
180
|
+
TOnSubmit,
|
|
181
|
+
TOnSubmitAsync,
|
|
182
|
+
TOnServer
|
|
183
|
+
> = api as never
|
|
66
184
|
extendedApi.Field = function APIField(props) {
|
|
67
185
|
return <Field {...props} form={api} />
|
|
68
186
|
}
|
package/src/useTransform.ts
CHANGED
|
@@ -1,12 +1,46 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type {
|
|
2
|
+
FormApi,
|
|
3
|
+
FormAsyncValidateOrFn,
|
|
4
|
+
FormTransform,
|
|
5
|
+
FormValidateOrFn,
|
|
6
|
+
} from '@tanstack/form-core'
|
|
2
7
|
|
|
3
8
|
export function useTransform<
|
|
4
9
|
TFormData,
|
|
5
|
-
|
|
10
|
+
TOnMount extends undefined | FormValidateOrFn<TFormData>,
|
|
11
|
+
TOnChange extends undefined | FormValidateOrFn<TFormData>,
|
|
12
|
+
TOnChangeAsync extends undefined | FormAsyncValidateOrFn<TFormData>,
|
|
13
|
+
TOnBlur extends undefined | FormValidateOrFn<TFormData>,
|
|
14
|
+
TOnBlurAsync extends undefined | FormAsyncValidateOrFn<TFormData>,
|
|
15
|
+
TOnSubmit extends undefined | FormValidateOrFn<TFormData>,
|
|
16
|
+
TOnSubmitAsync extends undefined | FormAsyncValidateOrFn<TFormData>,
|
|
17
|
+
TOnServer extends undefined | FormAsyncValidateOrFn<TFormData>,
|
|
6
18
|
>(
|
|
7
|
-
fn: (
|
|
19
|
+
fn: (
|
|
20
|
+
formBase: FormApi<any, any, any, any, any, any, any, any, any>,
|
|
21
|
+
) => FormApi<
|
|
22
|
+
TFormData,
|
|
23
|
+
TOnMount,
|
|
24
|
+
TOnChange,
|
|
25
|
+
TOnChangeAsync,
|
|
26
|
+
TOnBlur,
|
|
27
|
+
TOnBlurAsync,
|
|
28
|
+
TOnSubmit,
|
|
29
|
+
TOnSubmitAsync,
|
|
30
|
+
TOnServer
|
|
31
|
+
>,
|
|
8
32
|
deps: unknown[],
|
|
9
|
-
): FormTransform<
|
|
33
|
+
): FormTransform<
|
|
34
|
+
TFormData,
|
|
35
|
+
TOnMount,
|
|
36
|
+
TOnChange,
|
|
37
|
+
TOnChangeAsync,
|
|
38
|
+
TOnBlur,
|
|
39
|
+
TOnBlurAsync,
|
|
40
|
+
TOnSubmit,
|
|
41
|
+
TOnSubmitAsync,
|
|
42
|
+
TOnServer
|
|
43
|
+
> {
|
|
10
44
|
return {
|
|
11
45
|
fn,
|
|
12
46
|
deps,
|