1
- import {
2
- type DeepKeys ,
3
- type DeepValue ,
4
- FieldApi ,
5
- type FieldOptions ,
6
- type Narrow ,
1
+ import { FieldApi } from '@tanstack/form-core'
2
+ import type {
3
+ FieldState ,
4
+ DeepKeys ,
5
+ DeepValue ,
6
+ FieldOptions ,
7
+ Narrow ,
7
8
} from '@tanstack/form-core'
8
9
import { useStore } from '@tanstack/vue-store'
9
- import {
10
- type SetupContext ,
11
- defineComponent ,
12
- type Ref ,
13
- onMounted ,
14
- onUnmounted ,
15
- watch ,
16
- } from 'vue-demi'
10
+ import { defineComponent , onMounted , onUnmounted , watch } from 'vue-demi'
11
+ import type { SlotsType , SetupContext , Ref } from 'vue-demi'
17
12
import { provideFormContext , useFormContext } from './formContext'
18
13
19
14
declare module '@tanstack/form-core' {
@@ -113,11 +108,7 @@ export type FieldValue<TFormData, TField> = TFormData extends any[]
113
108
// // ^?
114
109
115
110
export type FieldComponent < TParentData , TFormData > = < TField > (
116
- fieldOptions : {
117
- children ?: (
118
- fieldApi : FieldApi < FieldValue < TParentData , TField > , TFormData > ,
119
- ) => any
120
- } & Omit <
111
+ fieldOptions : Omit <
121
112
UseFieldOptions < FieldValue < TParentData , TField > , TFormData > ,
122
113
'name' | 'index'
123
114
> &
@@ -130,7 +121,15 @@ export type FieldComponent<TParentData, TFormData> = <TField>(
130
121
name : TField extends undefined ? TField : DeepKeys < TParentData >
131
122
index ?: never
132
123
} ) ,
133
- context : SetupContext ,
124
+ context : SetupContext <
125
+ { } ,
126
+ SlotsType < {
127
+ default : {
128
+ field : FieldApi < FieldValue < TParentData , TField > , TFormData >
129
+ state : FieldState < any >
130
+ }
131
+ } >
132
+ > ,
134
133
) => any
135
134
136
135
export const Field = defineComponent (
@@ -145,7 +144,11 @@ export const Field = defineComponent(
145
144
parentFieldName : fieldApi . api . name ,
146
145
} as never )
147
146
148
- return ( ) => context . slots . default ! ( fieldApi . api , fieldApi . state . value )
147
+ return ( ) =>
148
+ context . slots . default ! ( {
149
+ field : fieldApi . api ,
150
+ state : fieldApi . state . value ,
151
+ } )
149
152
} ,
150
153
{ name : 'Field' , inheritAttrs : false } ,
151
154
)
0 commit comments