@tanstack/vue-form 2.0.0-alpha.0 → 2.0.0-alpha.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/AppForm/createFormHook.public.d.ts +6 -3
- package/dist/AppForm/createFormHook.public.js +2 -4
- package/dist/AppForm/createFormHookTypes.public.d.ts +82 -6
- package/dist/AppForm/initializeAppForm.lib.js +6 -1
- package/dist/FieldGroup/FieldGroupApi.public.d.ts +1 -1
- package/dist/VueForm/Components.public.d.ts +2 -2
- package/dist/VueForm/formApiTypes.public.d.ts +26 -0
- package/dist/VueForm/formType.public.d.ts +24 -2
- package/dist/VueForm/useField.lib.js +2 -2
- package/dist/VueForm/useForm.public.d.ts +23 -1
- package/dist/VueForm/useForm.public.js +22 -0
- package/dist/index.d.ts +2 -3
- package/package.json +3 -4
- package/dist/AppForm/appFormOptions.public.d.ts +0 -14
- package/src/AppForm/Components.lib.ts +0 -31
- package/src/AppForm/VueAppFormApi.public.ts +0 -17
- package/src/AppForm/appFormOptions.public.ts +0 -55
- package/src/AppForm/componentMap.public.ts +0 -19
- package/src/AppForm/contexts.lib.ts +0 -31
- package/src/AppForm/createFormHook.public.ts +0 -32
- package/src/AppForm/createFormHookTypes.public.ts +0 -28
- package/src/AppForm/fieldComponentHelpers.lib.ts +0 -21
- package/src/AppForm/getFormHookHelpers.public.ts +0 -109
- package/src/AppForm/initializeAppForm.lib.ts +0 -18
- package/src/FieldGroup/FieldGroupApi.public.ts +0 -148
- package/src/FieldGroup/withFields.lib.ts +0 -103
- package/src/FieldGroup/withFields.public.ts +0 -191
- package/src/Subscribe.public.ts +0 -46
- package/src/VueForm/Components.lib.ts +0 -182
- package/src/VueForm/Components.public.ts +0 -451
- package/src/VueForm/VueFormApi.lib.ts +0 -35
- package/src/VueForm/fieldSubscriptions.lib.ts +0 -47
- package/src/VueForm/formApiTypes.public.ts +0 -32
- package/src/VueForm/formType.public.ts +0 -46
- package/src/VueForm/useField.lib.ts +0 -64
- package/src/VueForm/useForm.public.ts +0 -30
- package/src/index.ts +0 -16
- package/src/vueTypes.lib.ts +0 -31
|
@@ -1,182 +0,0 @@
|
|
|
1
|
-
import { shallow, useSelector } from '@tanstack/vue-store'
|
|
2
|
-
import { InternalFormGroupApi } from '@tanstack/form-core/internals'
|
|
3
|
-
import {
|
|
4
|
-
defineComponent,
|
|
5
|
-
h,
|
|
6
|
-
onMounted,
|
|
7
|
-
onUnmounted,
|
|
8
|
-
provide,
|
|
9
|
-
watchEffect,
|
|
10
|
-
} from 'vue'
|
|
11
|
-
import { Subscribe } from '../Subscribe.public'
|
|
12
|
-
import {
|
|
13
|
-
createArrayFieldSubscription,
|
|
14
|
-
createValueFieldSubscription,
|
|
15
|
-
} from './fieldSubscriptions.lib'
|
|
16
|
-
import { useField } from './useField.lib'
|
|
17
|
-
import type { Component, InjectionKey, Slots } from 'vue'
|
|
18
|
-
import type {
|
|
19
|
-
AnyFieldApiOptions,
|
|
20
|
-
AnyInternalFieldApi,
|
|
21
|
-
AnyInternalFormApi,
|
|
22
|
-
InternalFormGroupApi as InternalFormGroupApiType,
|
|
23
|
-
} from '@tanstack/form-core/internals'
|
|
24
|
-
import type { InternalVueFormApi } from './VueFormApi.lib'
|
|
25
|
-
|
|
26
|
-
export function attachVueFormComponents(
|
|
27
|
-
form: AnyInternalFormApi,
|
|
28
|
-
fieldComponents: Record<string, Component> | null,
|
|
29
|
-
fieldContext?: InjectionKey<AnyInternalFieldApi>,
|
|
30
|
-
): InternalVueFormApi {
|
|
31
|
-
const resultForm = form as InternalVueFormApi
|
|
32
|
-
resultForm.Field = createFieldComponent(
|
|
33
|
-
form,
|
|
34
|
-
fieldComponents,
|
|
35
|
-
false,
|
|
36
|
-
fieldContext,
|
|
37
|
-
) as never
|
|
38
|
-
resultForm.ArrayField = createFieldComponent(
|
|
39
|
-
form,
|
|
40
|
-
fieldComponents,
|
|
41
|
-
true,
|
|
42
|
-
fieldContext,
|
|
43
|
-
) as never
|
|
44
|
-
resultForm.Subscribe = createSubscribeComponent(form) as never
|
|
45
|
-
resultForm.FormGroup = createFormGroupComponent(resultForm) as never
|
|
46
|
-
return resultForm
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
function createFieldComponent(
|
|
50
|
-
form: AnyInternalFormApi,
|
|
51
|
-
fieldComponents: Record<string, Component> | null,
|
|
52
|
-
array: boolean,
|
|
53
|
-
fieldContext?: InjectionKey<AnyInternalFieldApi>,
|
|
54
|
-
) {
|
|
55
|
-
return defineComponent(
|
|
56
|
-
(_props, context) => {
|
|
57
|
-
const options = () => ({ ...context.attrs, form }) as never
|
|
58
|
-
const fieldApi = useField(options, fieldComponents)
|
|
59
|
-
const selection = array
|
|
60
|
-
? createArrayFieldSubscription(fieldApi)
|
|
61
|
-
: createValueFieldSubscription(fieldApi)
|
|
62
|
-
|
|
63
|
-
if (fieldContext) {
|
|
64
|
-
// Field APIs are stable for a mounted name. Supplying the current API
|
|
65
|
-
// mirrors Vue v1 composition components while the parent subscription
|
|
66
|
-
// handles state-driven renders.
|
|
67
|
-
provide(fieldContext, fieldApi.value)
|
|
68
|
-
}
|
|
69
|
-
|
|
70
|
-
return () => {
|
|
71
|
-
void selection.value
|
|
72
|
-
return context.slots.default?.({ field: fieldApi.value })
|
|
73
|
-
}
|
|
74
|
-
},
|
|
75
|
-
{
|
|
76
|
-
name: array ? 'TanStackForm.ArrayField' : 'TanStackForm.Field',
|
|
77
|
-
inheritAttrs: false,
|
|
78
|
-
},
|
|
79
|
-
)
|
|
80
|
-
}
|
|
81
|
-
|
|
82
|
-
function createSubscribeComponent(form: AnyInternalFormApi) {
|
|
83
|
-
return defineComponent(
|
|
84
|
-
(_props, context) => () =>
|
|
85
|
-
h(
|
|
86
|
-
Subscribe as never,
|
|
87
|
-
{ ...context.attrs, source: form.atom } as never,
|
|
88
|
-
context.slots,
|
|
89
|
-
),
|
|
90
|
-
{
|
|
91
|
-
name: 'TanStackForm.Subscribe',
|
|
92
|
-
inheritAttrs: false,
|
|
93
|
-
},
|
|
94
|
-
)
|
|
95
|
-
}
|
|
96
|
-
|
|
97
|
-
function createFormGroupComponent(form: InternalVueFormApi) {
|
|
98
|
-
return defineComponent(
|
|
99
|
-
(_props, context) => {
|
|
100
|
-
const options = () => ({ ...context.attrs, form })
|
|
101
|
-
const group = attachVueFormGroupComponents(
|
|
102
|
-
new InternalFormGroupApi(options() as never),
|
|
103
|
-
form,
|
|
104
|
-
)
|
|
105
|
-
|
|
106
|
-
watchEffect(() => group.update(options() as never))
|
|
107
|
-
|
|
108
|
-
let mounted = false
|
|
109
|
-
onMounted(() => {
|
|
110
|
-
mounted = true
|
|
111
|
-
group.mount()
|
|
112
|
-
})
|
|
113
|
-
onUnmounted(() => {
|
|
114
|
-
if (mounted) group._cleanup()
|
|
115
|
-
})
|
|
116
|
-
|
|
117
|
-
const state = useSelector(group.atom, (value) => value, {
|
|
118
|
-
compare: shallow,
|
|
119
|
-
})
|
|
120
|
-
|
|
121
|
-
return () => {
|
|
122
|
-
void state.value
|
|
123
|
-
return context.slots.default?.({ group })
|
|
124
|
-
}
|
|
125
|
-
},
|
|
126
|
-
{
|
|
127
|
-
name: 'TanStackForm.FormGroup',
|
|
128
|
-
inheritAttrs: false,
|
|
129
|
-
},
|
|
130
|
-
)
|
|
131
|
-
}
|
|
132
|
-
|
|
133
|
-
function forwardToField(
|
|
134
|
-
component: Component,
|
|
135
|
-
group: InternalFormGroupApiType<any, any, any, any, any>,
|
|
136
|
-
) {
|
|
137
|
-
return defineComponent(
|
|
138
|
-
(_props, context) => () => {
|
|
139
|
-
const options = { ...context.attrs } as unknown as AnyFieldApiOptions
|
|
140
|
-
return h(
|
|
141
|
-
component,
|
|
142
|
-
group._getFormFieldOptions(options, (base, overrides) => ({
|
|
143
|
-
...base,
|
|
144
|
-
...overrides,
|
|
145
|
-
})) as never,
|
|
146
|
-
context.slots,
|
|
147
|
-
)
|
|
148
|
-
},
|
|
149
|
-
{ inheritAttrs: false },
|
|
150
|
-
)
|
|
151
|
-
}
|
|
152
|
-
|
|
153
|
-
function attachVueFormGroupComponents(
|
|
154
|
-
group: InternalFormGroupApiType<any, any, any, any, any>,
|
|
155
|
-
form: InternalVueFormApi,
|
|
156
|
-
) {
|
|
157
|
-
type GroupWithComponents = InternalFormGroupApiType<
|
|
158
|
-
any,
|
|
159
|
-
any,
|
|
160
|
-
any,
|
|
161
|
-
any,
|
|
162
|
-
any
|
|
163
|
-
> & {
|
|
164
|
-
Field: Component
|
|
165
|
-
ArrayField: Component
|
|
166
|
-
Subscribe: Component
|
|
167
|
-
}
|
|
168
|
-
|
|
169
|
-
const resultGroup = group as GroupWithComponents
|
|
170
|
-
resultGroup.Field = forwardToField(form.Field as never, group)
|
|
171
|
-
resultGroup.ArrayField = forwardToField(form.ArrayField as never, group)
|
|
172
|
-
resultGroup.Subscribe = defineComponent(
|
|
173
|
-
(_props, context) => () =>
|
|
174
|
-
h(
|
|
175
|
-
Subscribe as never,
|
|
176
|
-
{ ...context.attrs, source: group.atom } as never,
|
|
177
|
-
context.slots as Slots,
|
|
178
|
-
),
|
|
179
|
-
{ name: 'TanStackForm.FormGroup.Subscribe', inheritAttrs: false },
|
|
180
|
-
)
|
|
181
|
-
return resultGroup
|
|
182
|
-
}
|
|
@@ -1,451 +0,0 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
DeepKeys,
|
|
3
|
-
DeepKeysWhereValueIncludes,
|
|
4
|
-
DeepValue,
|
|
5
|
-
FieldApi,
|
|
6
|
-
FieldApiOptions,
|
|
7
|
-
FieldValidators,
|
|
8
|
-
FormErrorTypes,
|
|
9
|
-
FormGroupApi,
|
|
10
|
-
FormGroupOptions,
|
|
11
|
-
FormGroupState,
|
|
12
|
-
FormGroupValidators,
|
|
13
|
-
FormState,
|
|
14
|
-
ToFieldError,
|
|
15
|
-
ToFormGroupErrorTypes,
|
|
16
|
-
} from '@tanstack/form-core'
|
|
17
|
-
import type { Component, PublicProps } from 'vue'
|
|
18
|
-
import type { VueComponentInstance } from '../vueTypes.lib'
|
|
19
|
-
|
|
20
|
-
declare const fieldComponentsType: unique symbol
|
|
21
|
-
|
|
22
|
-
type ExactFieldBrand<out TValue> = {
|
|
23
|
-
readonly __tanstackFieldExactType: TValue
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
type AcceptsFieldBrand<out TAcceptedValue> = {
|
|
27
|
-
readonly __tanstackFieldAcceptsType: TAcceptedValue
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
type CompatibleFieldKey<TKey, TComponent, TTargetValue> =
|
|
31
|
-
TComponent extends ExactFieldBrand<infer TExact>
|
|
32
|
-
? [TExact] extends [TTargetValue]
|
|
33
|
-
? [TTargetValue] extends [TExact]
|
|
34
|
-
? TKey
|
|
35
|
-
: never
|
|
36
|
-
: never
|
|
37
|
-
: TComponent extends AcceptsFieldBrand<infer TLoose>
|
|
38
|
-
? [TTargetValue] extends [TLoose]
|
|
39
|
-
? TKey
|
|
40
|
-
: never
|
|
41
|
-
: TKey
|
|
42
|
-
|
|
43
|
-
type FilteredFieldComponents<
|
|
44
|
-
TFieldComponents extends Record<string, Component>,
|
|
45
|
-
TTargetValue,
|
|
46
|
-
> = {
|
|
47
|
-
[
|
|
48
|
-
K in keyof TFieldComponents as CompatibleFieldKey<
|
|
49
|
-
K,
|
|
50
|
-
TFieldComponents[K],
|
|
51
|
-
TTargetValue
|
|
52
|
-
>
|
|
53
|
-
]: TFieldComponents[K]
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
type FieldComponentsMatchingType<
|
|
57
|
-
TFieldComponents extends Record<string, Component>,
|
|
58
|
-
TTargetValue,
|
|
59
|
-
> = unknown extends TTargetValue
|
|
60
|
-
? TFieldComponents
|
|
61
|
-
: string extends keyof TFieldComponents
|
|
62
|
-
? TFieldComponents
|
|
63
|
-
: FilteredFieldComponents<TFieldComponents, TTargetValue>
|
|
64
|
-
|
|
65
|
-
export type VueFieldApi<
|
|
66
|
-
TFieldName,
|
|
67
|
-
TFieldValue,
|
|
68
|
-
TFieldError,
|
|
69
|
-
TFormData,
|
|
70
|
-
TFormErrorTypes extends FormErrorTypes,
|
|
71
|
-
TFieldComponents extends Record<string, Component>,
|
|
72
|
-
> = FieldApi<TFieldName, TFieldValue, TFieldError, TFormData, TFormErrorTypes> &
|
|
73
|
-
FieldComponentsMatchingType<TFieldComponents, TFieldValue>
|
|
74
|
-
|
|
75
|
-
interface VueSubscribeProps<in out TSourceData, in out TSelected> {
|
|
76
|
-
selector: (state: TSourceData) => TSelected
|
|
77
|
-
when?: (selected: NoInfer<TSelected>) => boolean
|
|
78
|
-
}
|
|
79
|
-
|
|
80
|
-
export type VueFormSubscribeProps<
|
|
81
|
-
TFormData,
|
|
82
|
-
TFormErrorTypes extends FormErrorTypes,
|
|
83
|
-
TSelected,
|
|
84
|
-
> = VueSubscribeProps<FormState<TFormData, TFormErrorTypes>, TSelected>
|
|
85
|
-
|
|
86
|
-
export type VueFormSubscribeComponent<
|
|
87
|
-
in out TFormData,
|
|
88
|
-
in out TFormErrorTypes extends FormErrorTypes,
|
|
89
|
-
> = new <TSelected>(
|
|
90
|
-
props: VueFormSubscribeProps<TFormData, TFormErrorTypes, TSelected> &
|
|
91
|
-
PublicProps,
|
|
92
|
-
) => VueComponentInstance<
|
|
93
|
-
VueFormSubscribeProps<TFormData, TFormErrorTypes, TSelected>,
|
|
94
|
-
{ default: NoInfer<TSelected> }
|
|
95
|
-
>
|
|
96
|
-
|
|
97
|
-
export interface VueFormFieldProps<
|
|
98
|
-
in out TFieldData,
|
|
99
|
-
in out TFieldName,
|
|
100
|
-
in out TFieldValue,
|
|
101
|
-
in out TFieldValidators extends FieldValidators<
|
|
102
|
-
TFieldData,
|
|
103
|
-
TFieldName,
|
|
104
|
-
TFieldValue
|
|
105
|
-
>,
|
|
106
|
-
in out TGroupFieldError,
|
|
107
|
-
in out TFormData,
|
|
108
|
-
in out TFormErrorTypes extends FormErrorTypes,
|
|
109
|
-
in out TFieldComponents extends Record<string, Component>,
|
|
110
|
-
> extends FieldApiOptions<
|
|
111
|
-
TFieldData,
|
|
112
|
-
TFieldName,
|
|
113
|
-
TFieldValue,
|
|
114
|
-
TFieldValidators,
|
|
115
|
-
TGroupFieldError,
|
|
116
|
-
TFormData,
|
|
117
|
-
TFormErrorTypes
|
|
118
|
-
> {
|
|
119
|
-
readonly [fieldComponentsType]?: TFieldComponents
|
|
120
|
-
}
|
|
121
|
-
|
|
122
|
-
export type VueFormFieldComponent<
|
|
123
|
-
in out TFormData,
|
|
124
|
-
in out TFormErrorTypes extends FormErrorTypes,
|
|
125
|
-
in out TFieldComponents extends Record<string, Component>,
|
|
126
|
-
> = new <
|
|
127
|
-
TFieldName extends DeepKeys<TFormData>,
|
|
128
|
-
const TFieldValidators extends FieldValidators<
|
|
129
|
-
TFormData,
|
|
130
|
-
TFieldName,
|
|
131
|
-
DeepValue<TFormData, TFieldName>
|
|
132
|
-
>,
|
|
133
|
-
>(
|
|
134
|
-
props: VueFormFieldProps<
|
|
135
|
-
TFormData,
|
|
136
|
-
TFieldName,
|
|
137
|
-
DeepValue<TFormData, TFieldName>,
|
|
138
|
-
TFieldValidators,
|
|
139
|
-
never,
|
|
140
|
-
TFormData,
|
|
141
|
-
TFormErrorTypes,
|
|
142
|
-
TFieldComponents
|
|
143
|
-
> &
|
|
144
|
-
PublicProps,
|
|
145
|
-
) => VueComponentInstance<
|
|
146
|
-
VueFormFieldProps<
|
|
147
|
-
TFormData,
|
|
148
|
-
TFieldName,
|
|
149
|
-
DeepValue<TFormData, TFieldName>,
|
|
150
|
-
TFieldValidators,
|
|
151
|
-
never,
|
|
152
|
-
TFormData,
|
|
153
|
-
TFormErrorTypes,
|
|
154
|
-
TFieldComponents
|
|
155
|
-
>,
|
|
156
|
-
{
|
|
157
|
-
default: {
|
|
158
|
-
field: VueFieldApi<
|
|
159
|
-
TFieldName,
|
|
160
|
-
DeepValue<TFormData, TFieldName>,
|
|
161
|
-
ToFieldError<NoInfer<TFieldValidators>, never, TFormErrorTypes>,
|
|
162
|
-
TFormData,
|
|
163
|
-
TFormErrorTypes,
|
|
164
|
-
TFieldComponents
|
|
165
|
-
>
|
|
166
|
-
}
|
|
167
|
-
}
|
|
168
|
-
>
|
|
169
|
-
|
|
170
|
-
export type VueFormArrayFieldComponent<
|
|
171
|
-
in out TFormData,
|
|
172
|
-
in out TFormErrorTypes extends FormErrorTypes,
|
|
173
|
-
in out TFieldComponents extends Record<string, Component>,
|
|
174
|
-
> = new <
|
|
175
|
-
TFieldName extends DeepKeysWhereValueIncludes<TFormData, Array<any>>,
|
|
176
|
-
const TFieldValidators extends FieldValidators<
|
|
177
|
-
TFormData,
|
|
178
|
-
TFieldName,
|
|
179
|
-
DeepValue<TFormData, TFieldName>
|
|
180
|
-
>,
|
|
181
|
-
>(
|
|
182
|
-
props: VueFormFieldProps<
|
|
183
|
-
TFormData,
|
|
184
|
-
TFieldName,
|
|
185
|
-
DeepValue<TFormData, TFieldName>,
|
|
186
|
-
TFieldValidators,
|
|
187
|
-
never,
|
|
188
|
-
TFormData,
|
|
189
|
-
TFormErrorTypes,
|
|
190
|
-
TFieldComponents
|
|
191
|
-
> &
|
|
192
|
-
PublicProps,
|
|
193
|
-
) => VueComponentInstance<
|
|
194
|
-
VueFormFieldProps<
|
|
195
|
-
TFormData,
|
|
196
|
-
TFieldName,
|
|
197
|
-
DeepValue<TFormData, TFieldName>,
|
|
198
|
-
TFieldValidators,
|
|
199
|
-
never,
|
|
200
|
-
TFormData,
|
|
201
|
-
TFormErrorTypes,
|
|
202
|
-
TFieldComponents
|
|
203
|
-
>,
|
|
204
|
-
{
|
|
205
|
-
default: {
|
|
206
|
-
field: VueFieldApi<
|
|
207
|
-
TFieldName,
|
|
208
|
-
DeepValue<TFormData, TFieldName>,
|
|
209
|
-
ToFieldError<NoInfer<TFieldValidators>, never, TFormErrorTypes>,
|
|
210
|
-
TFormData,
|
|
211
|
-
TFormErrorTypes,
|
|
212
|
-
TFieldComponents
|
|
213
|
-
>
|
|
214
|
-
}
|
|
215
|
-
}
|
|
216
|
-
>
|
|
217
|
-
|
|
218
|
-
export type VueFormGroupSubscribeProps<
|
|
219
|
-
TGroupValue,
|
|
220
|
-
TGroupErrorTypes extends FormErrorTypes,
|
|
221
|
-
TSelected,
|
|
222
|
-
> = VueSubscribeProps<FormGroupState<TGroupValue, TGroupErrorTypes>, TSelected>
|
|
223
|
-
|
|
224
|
-
export type VueFormGroupSubscribeComponent<
|
|
225
|
-
in out TGroupValue,
|
|
226
|
-
in out TGroupErrorTypes extends FormErrorTypes,
|
|
227
|
-
> = new <TSelected>(
|
|
228
|
-
props: VueFormGroupSubscribeProps<TGroupValue, TGroupErrorTypes, TSelected> &
|
|
229
|
-
PublicProps,
|
|
230
|
-
) => VueComponentInstance<
|
|
231
|
-
VueFormGroupSubscribeProps<TGroupValue, TGroupErrorTypes, TSelected>,
|
|
232
|
-
{ default: NoInfer<TSelected> }
|
|
233
|
-
>
|
|
234
|
-
|
|
235
|
-
export type VueFormGroupFieldComponent<
|
|
236
|
-
in out TFormData,
|
|
237
|
-
in out TGroupValue,
|
|
238
|
-
in out TGroupErrorTypes extends FormErrorTypes,
|
|
239
|
-
in out TFormErrorTypes extends FormErrorTypes,
|
|
240
|
-
in out TFieldComponents extends Record<string, Component>,
|
|
241
|
-
> = new <
|
|
242
|
-
TFieldName extends DeepKeys<TGroupValue>,
|
|
243
|
-
const TFieldValidators extends FieldValidators<
|
|
244
|
-
TGroupValue,
|
|
245
|
-
TFieldName,
|
|
246
|
-
DeepValue<TGroupValue, TFieldName>
|
|
247
|
-
>,
|
|
248
|
-
>(
|
|
249
|
-
props: VueFormFieldProps<
|
|
250
|
-
TGroupValue,
|
|
251
|
-
TFieldName,
|
|
252
|
-
DeepValue<TGroupValue, TFieldName>,
|
|
253
|
-
TFieldValidators,
|
|
254
|
-
TGroupErrorTypes['fieldError'],
|
|
255
|
-
TFormData,
|
|
256
|
-
TFormErrorTypes,
|
|
257
|
-
TFieldComponents
|
|
258
|
-
> &
|
|
259
|
-
PublicProps,
|
|
260
|
-
) => VueComponentInstance<
|
|
261
|
-
VueFormFieldProps<
|
|
262
|
-
TGroupValue,
|
|
263
|
-
TFieldName,
|
|
264
|
-
DeepValue<TGroupValue, TFieldName>,
|
|
265
|
-
TFieldValidators,
|
|
266
|
-
TGroupErrorTypes['fieldError'],
|
|
267
|
-
TFormData,
|
|
268
|
-
TFormErrorTypes,
|
|
269
|
-
TFieldComponents
|
|
270
|
-
>,
|
|
271
|
-
{
|
|
272
|
-
default: {
|
|
273
|
-
field: VueFieldApi<
|
|
274
|
-
TFieldName,
|
|
275
|
-
DeepValue<TGroupValue, TFieldName>,
|
|
276
|
-
ToFieldError<
|
|
277
|
-
NoInfer<TFieldValidators>,
|
|
278
|
-
TGroupErrorTypes['fieldError'],
|
|
279
|
-
TFormErrorTypes
|
|
280
|
-
>,
|
|
281
|
-
TFormData,
|
|
282
|
-
TFormErrorTypes,
|
|
283
|
-
TFieldComponents
|
|
284
|
-
>
|
|
285
|
-
}
|
|
286
|
-
}
|
|
287
|
-
>
|
|
288
|
-
|
|
289
|
-
export type VueFormGroupArrayFieldComponent<
|
|
290
|
-
in out TFormData,
|
|
291
|
-
in out TGroupValue,
|
|
292
|
-
in out TGroupErrorTypes extends FormErrorTypes,
|
|
293
|
-
in out TFormErrorTypes extends FormErrorTypes,
|
|
294
|
-
in out TFieldComponents extends Record<string, Component>,
|
|
295
|
-
> = new <
|
|
296
|
-
TFieldName extends DeepKeysWhereValueIncludes<TGroupValue, Array<any>>,
|
|
297
|
-
const TFieldValidators extends FieldValidators<
|
|
298
|
-
TGroupValue,
|
|
299
|
-
TFieldName,
|
|
300
|
-
DeepValue<TGroupValue, TFieldName>
|
|
301
|
-
>,
|
|
302
|
-
>(
|
|
303
|
-
props: VueFormFieldProps<
|
|
304
|
-
TGroupValue,
|
|
305
|
-
TFieldName,
|
|
306
|
-
DeepValue<TGroupValue, TFieldName>,
|
|
307
|
-
TFieldValidators,
|
|
308
|
-
TGroupErrorTypes['fieldError'],
|
|
309
|
-
TFormData,
|
|
310
|
-
TFormErrorTypes,
|
|
311
|
-
TFieldComponents
|
|
312
|
-
> &
|
|
313
|
-
PublicProps,
|
|
314
|
-
) => VueComponentInstance<
|
|
315
|
-
VueFormFieldProps<
|
|
316
|
-
TGroupValue,
|
|
317
|
-
TFieldName,
|
|
318
|
-
DeepValue<TGroupValue, TFieldName>,
|
|
319
|
-
TFieldValidators,
|
|
320
|
-
TGroupErrorTypes['fieldError'],
|
|
321
|
-
TFormData,
|
|
322
|
-
TFormErrorTypes,
|
|
323
|
-
TFieldComponents
|
|
324
|
-
>,
|
|
325
|
-
{
|
|
326
|
-
default: {
|
|
327
|
-
field: VueFieldApi<
|
|
328
|
-
TFieldName,
|
|
329
|
-
DeepValue<TGroupValue, TFieldName>,
|
|
330
|
-
ToFieldError<
|
|
331
|
-
NoInfer<TFieldValidators>,
|
|
332
|
-
TGroupErrorTypes['fieldError'],
|
|
333
|
-
TFormErrorTypes
|
|
334
|
-
>,
|
|
335
|
-
TFormData,
|
|
336
|
-
TFormErrorTypes,
|
|
337
|
-
TFieldComponents
|
|
338
|
-
>
|
|
339
|
-
}
|
|
340
|
-
}
|
|
341
|
-
>
|
|
342
|
-
|
|
343
|
-
export interface VueFormGroupApi<
|
|
344
|
-
in out TFormData,
|
|
345
|
-
in out TGroupName,
|
|
346
|
-
in out TGroupValue,
|
|
347
|
-
in out TGroupErrorTypes extends FormErrorTypes,
|
|
348
|
-
in out TFormErrorTypes extends FormErrorTypes,
|
|
349
|
-
in out TFieldComponents extends Record<string, Component>,
|
|
350
|
-
> extends FormGroupApi<
|
|
351
|
-
TFormData,
|
|
352
|
-
TGroupName,
|
|
353
|
-
TGroupValue,
|
|
354
|
-
TGroupErrorTypes,
|
|
355
|
-
TFormErrorTypes
|
|
356
|
-
> {
|
|
357
|
-
Field: VueFormGroupFieldComponent<
|
|
358
|
-
TFormData,
|
|
359
|
-
TGroupValue,
|
|
360
|
-
TGroupErrorTypes,
|
|
361
|
-
TFormErrorTypes,
|
|
362
|
-
TFieldComponents
|
|
363
|
-
>
|
|
364
|
-
ArrayField: VueFormGroupArrayFieldComponent<
|
|
365
|
-
TFormData,
|
|
366
|
-
TGroupValue,
|
|
367
|
-
TGroupErrorTypes,
|
|
368
|
-
TFormErrorTypes,
|
|
369
|
-
TFieldComponents
|
|
370
|
-
>
|
|
371
|
-
Subscribe: VueFormGroupSubscribeComponent<TGroupValue, TGroupErrorTypes>
|
|
372
|
-
}
|
|
373
|
-
|
|
374
|
-
export interface VueFormGroupProps<
|
|
375
|
-
in out TFormData,
|
|
376
|
-
in out TGroupName,
|
|
377
|
-
in out TGroupValue,
|
|
378
|
-
in out TGroupValidators extends FormGroupValidators<TGroupValue>,
|
|
379
|
-
in out TFormErrorTypes extends FormErrorTypes,
|
|
380
|
-
in out TFieldComponents extends Record<string, Component>,
|
|
381
|
-
> extends Omit<
|
|
382
|
-
FormGroupOptions<
|
|
383
|
-
TFormData,
|
|
384
|
-
TGroupName,
|
|
385
|
-
TGroupValue,
|
|
386
|
-
TGroupValidators,
|
|
387
|
-
TFormErrorTypes
|
|
388
|
-
>,
|
|
389
|
-
'form'
|
|
390
|
-
> {
|
|
391
|
-
readonly [fieldComponentsType]?: TFieldComponents
|
|
392
|
-
}
|
|
393
|
-
|
|
394
|
-
export type VueFormGroupComponent<
|
|
395
|
-
in out TFormData,
|
|
396
|
-
in out TFormErrorTypes extends FormErrorTypes,
|
|
397
|
-
in out TFieldComponents extends Record<string, Component>,
|
|
398
|
-
> = new <
|
|
399
|
-
TGroupName extends DeepKeys<TFormData>,
|
|
400
|
-
TGroupValue extends DeepValue<TFormData, TGroupName>,
|
|
401
|
-
const TGroupValidators extends FormGroupValidators<TGroupValue>,
|
|
402
|
-
>(
|
|
403
|
-
props: VueFormGroupProps<
|
|
404
|
-
TFormData,
|
|
405
|
-
TGroupName,
|
|
406
|
-
TGroupValue,
|
|
407
|
-
TGroupValidators,
|
|
408
|
-
TFormErrorTypes,
|
|
409
|
-
TFieldComponents
|
|
410
|
-
> &
|
|
411
|
-
PublicProps,
|
|
412
|
-
) => VueComponentInstance<
|
|
413
|
-
VueFormGroupProps<
|
|
414
|
-
TFormData,
|
|
415
|
-
TGroupName,
|
|
416
|
-
TGroupValue,
|
|
417
|
-
TGroupValidators,
|
|
418
|
-
TFormErrorTypes,
|
|
419
|
-
TFieldComponents
|
|
420
|
-
>,
|
|
421
|
-
{
|
|
422
|
-
default: {
|
|
423
|
-
group: VueFormGroupApi<
|
|
424
|
-
TFormData,
|
|
425
|
-
TGroupName,
|
|
426
|
-
TGroupValue,
|
|
427
|
-
ToFormGroupErrorTypes<NoInfer<TGroupValidators>>,
|
|
428
|
-
TFormErrorTypes,
|
|
429
|
-
TFieldComponents
|
|
430
|
-
>
|
|
431
|
-
}
|
|
432
|
-
}
|
|
433
|
-
>
|
|
434
|
-
|
|
435
|
-
export interface VueTanStackFormComponents<
|
|
436
|
-
in out TFormData,
|
|
437
|
-
in out TFormErrorTypes extends FormErrorTypes,
|
|
438
|
-
in out TFieldComponents extends Record<string, Component> = Record<
|
|
439
|
-
never,
|
|
440
|
-
never
|
|
441
|
-
>,
|
|
442
|
-
> {
|
|
443
|
-
Field: VueFormFieldComponent<TFormData, TFormErrorTypes, TFieldComponents>
|
|
444
|
-
ArrayField: VueFormArrayFieldComponent<
|
|
445
|
-
TFormData,
|
|
446
|
-
TFormErrorTypes,
|
|
447
|
-
TFieldComponents
|
|
448
|
-
>
|
|
449
|
-
Subscribe: VueFormSubscribeComponent<TFormData, TFormErrorTypes>
|
|
450
|
-
FormGroup: VueFormGroupComponent<TFormData, TFormErrorTypes, TFieldComponents>
|
|
451
|
-
}
|
|
@@ -1,35 +0,0 @@
|
|
|
1
|
-
import { InternalFormApi } from '@tanstack/form-core/internals'
|
|
2
|
-
import { onMounted, onUnmounted, useId, watchEffect } from 'vue'
|
|
3
|
-
import { attachVueFormComponents } from './Components.lib'
|
|
4
|
-
import type { AnyInternalFormApi } from '@tanstack/form-core/internals'
|
|
5
|
-
import type { FormOptions } from '@tanstack/form-core'
|
|
6
|
-
import type { VueTanStackFormComponents } from './Components.public'
|
|
7
|
-
|
|
8
|
-
export interface InternalVueFormApi
|
|
9
|
-
extends AnyInternalFormApi, VueTanStackFormComponents<any, any, any> {}
|
|
10
|
-
|
|
11
|
-
export function initializeForm(
|
|
12
|
-
options: FormOptions<any, any, any>,
|
|
13
|
-
): InternalVueFormApi {
|
|
14
|
-
return attachVueFormComponents(new InternalFormApi(options), null)
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
export function useInternalForm(
|
|
18
|
-
options: FormOptions<any, any, any>,
|
|
19
|
-
initializeFn: (options: FormOptions<any, any, any>) => InternalVueFormApi,
|
|
20
|
-
) {
|
|
21
|
-
const vueFormId = useId()
|
|
22
|
-
const resolveOptions = () =>
|
|
23
|
-
options.formId === undefined ? { ...options, formId: vueFormId } : options
|
|
24
|
-
const form = initializeFn(resolveOptions())
|
|
25
|
-
|
|
26
|
-
watchEffect(() => form._update(resolveOptions()))
|
|
27
|
-
|
|
28
|
-
let unmount: (() => void) | undefined
|
|
29
|
-
onMounted(() => {
|
|
30
|
-
unmount = form.mount()
|
|
31
|
-
})
|
|
32
|
-
onUnmounted(() => unmount?.())
|
|
33
|
-
|
|
34
|
-
return form
|
|
35
|
-
}
|
|
@@ -1,47 +0,0 @@
|
|
|
1
|
-
import { shallow } from '@tanstack/vue-store'
|
|
2
|
-
import { shallowRef, toRaw, watch } from 'vue'
|
|
3
|
-
import type { ShallowRef } from 'vue'
|
|
4
|
-
import type {
|
|
5
|
-
AnyInternalFieldApi,
|
|
6
|
-
InternalBaseFieldMeta,
|
|
7
|
-
} from '@tanstack/form-core/internals'
|
|
8
|
-
|
|
9
|
-
function createFieldSelection<TSelected>(
|
|
10
|
-
fieldApi: ShallowRef<AnyInternalFieldApi>,
|
|
11
|
-
selector: (field: AnyInternalFieldApi) => TSelected,
|
|
12
|
-
) {
|
|
13
|
-
const selected = shallowRef(selector(fieldApi.value)) as ShallowRef<TSelected>
|
|
14
|
-
|
|
15
|
-
watch(
|
|
16
|
-
fieldApi,
|
|
17
|
-
(field, _previous, onCleanup) => {
|
|
18
|
-
selected.value = selector(field)
|
|
19
|
-
const subscription = field.atom.subscribe(() => {
|
|
20
|
-
const next = selector(field)
|
|
21
|
-
if (!shallow(toRaw(selected.value), next)) selected.value = next
|
|
22
|
-
})
|
|
23
|
-
onCleanup(() => subscription.unsubscribe())
|
|
24
|
-
},
|
|
25
|
-
{ immediate: true, flush: 'sync' },
|
|
26
|
-
)
|
|
27
|
-
|
|
28
|
-
return selected
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
export function createValueFieldSubscription(
|
|
32
|
-
fieldApi: ShallowRef<AnyInternalFieldApi>,
|
|
33
|
-
) {
|
|
34
|
-
return createFieldSelection(fieldApi, (field) => ({
|
|
35
|
-
value: field.value,
|
|
36
|
-
meta: field.meta,
|
|
37
|
-
}))
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
export function createArrayFieldSubscription(
|
|
41
|
-
fieldApi: ShallowRef<AnyInternalFieldApi>,
|
|
42
|
-
) {
|
|
43
|
-
return createFieldSelection(fieldApi, (field) => ({
|
|
44
|
-
length: field.value.length,
|
|
45
|
-
version: (field.meta as InternalBaseFieldMeta)._arrayVersion,
|
|
46
|
-
}))
|
|
47
|
-
}
|