@tanstack/vue-form 2.0.0-alpha.0 → 2.0.0-alpha.1
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/VueForm/formApiTypes.public.d.ts +26 -0
- package/dist/VueForm/formType.public.d.ts +23 -0
- package/package.json +3 -4
- 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,103 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
InternalFieldGroupApi,
|
|
3
|
-
defineFieldGroupFieldsRuntime,
|
|
4
|
-
fieldGroupHelperRuntime,
|
|
5
|
-
} from '@tanstack/form-core/internals'
|
|
6
|
-
import { computed, defineComponent, h } from 'vue'
|
|
7
|
-
import type { Component } from 'vue'
|
|
8
|
-
import type {
|
|
9
|
-
AnyFieldApiOptions,
|
|
10
|
-
InternalFieldGroupBindings,
|
|
11
|
-
} from '@tanstack/form-core/internals'
|
|
12
|
-
import type { AnyFieldGroupApi } from './FieldGroupApi.public'
|
|
13
|
-
|
|
14
|
-
function attachVueFieldGroupComponents(
|
|
15
|
-
group: InternalFieldGroupApi,
|
|
16
|
-
form: any,
|
|
17
|
-
): AnyFieldGroupApi {
|
|
18
|
-
const forwardField = (component: Component, name: string) =>
|
|
19
|
-
defineComponent(
|
|
20
|
-
(_props, context) => {
|
|
21
|
-
const resolved = computed(() => {
|
|
22
|
-
const options = {
|
|
23
|
-
...context.attrs,
|
|
24
|
-
} as unknown as AnyFieldApiOptions
|
|
25
|
-
return group._getFormFieldOptions(options, (base, overrides) => ({
|
|
26
|
-
...base,
|
|
27
|
-
...overrides,
|
|
28
|
-
}))
|
|
29
|
-
})
|
|
30
|
-
return () => h(component, resolved.value as never, context.slots)
|
|
31
|
-
},
|
|
32
|
-
{ name, inheritAttrs: false },
|
|
33
|
-
)
|
|
34
|
-
|
|
35
|
-
const Field = forwardField(form.Field, 'TanStackForm.FieldGroup.Field')
|
|
36
|
-
const ArrayField = forwardField(
|
|
37
|
-
form.ArrayField,
|
|
38
|
-
'TanStackForm.FieldGroup.ArrayField',
|
|
39
|
-
)
|
|
40
|
-
const Subscribe = defineComponent(
|
|
41
|
-
(_props, context) => () =>
|
|
42
|
-
h(form.Subscribe, { ...context.attrs } as never, context.slots),
|
|
43
|
-
{ name: 'TanStackForm.FieldGroup.Subscribe', inheritAttrs: false },
|
|
44
|
-
)
|
|
45
|
-
|
|
46
|
-
return Object.assign(group, {
|
|
47
|
-
Field,
|
|
48
|
-
ArrayField,
|
|
49
|
-
Subscribe,
|
|
50
|
-
}) as never
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
export function defineFieldGroupRuntime<
|
|
54
|
-
TFields extends Record<string, unknown>,
|
|
55
|
-
>(defineFieldGroupFn: (helperRuntime: any) => TFields) {
|
|
56
|
-
const fields = defineFieldGroupFieldsRuntime(
|
|
57
|
-
defineFieldGroupFn(fieldGroupHelperRuntime),
|
|
58
|
-
)
|
|
59
|
-
|
|
60
|
-
return {
|
|
61
|
-
fields,
|
|
62
|
-
bindComponent: (component: Component, fieldsPropName: string) =>
|
|
63
|
-
withFieldsRuntime(fields, component, fieldsPropName),
|
|
64
|
-
}
|
|
65
|
-
}
|
|
66
|
-
|
|
67
|
-
function withFieldsRuntime(
|
|
68
|
-
fields: Record<string, unknown>,
|
|
69
|
-
component: Component,
|
|
70
|
-
fieldsPropName: string,
|
|
71
|
-
) {
|
|
72
|
-
const fieldNames = Object.keys(fields)
|
|
73
|
-
|
|
74
|
-
return defineComponent(
|
|
75
|
-
(_props, context) => {
|
|
76
|
-
const form = context.attrs.form as any
|
|
77
|
-
if (!form) {
|
|
78
|
-
throw new Error(
|
|
79
|
-
'TanStack Form: Field groups must receive a `form` prop.',
|
|
80
|
-
)
|
|
81
|
-
}
|
|
82
|
-
|
|
83
|
-
const fieldGroupApi = attachVueFieldGroupComponents(
|
|
84
|
-
new InternalFieldGroupApi({
|
|
85
|
-
form,
|
|
86
|
-
fieldNames,
|
|
87
|
-
getBindings: () =>
|
|
88
|
-
context.attrs[fieldsPropName] as InternalFieldGroupBindings,
|
|
89
|
-
}),
|
|
90
|
-
form,
|
|
91
|
-
)
|
|
92
|
-
|
|
93
|
-
return () => {
|
|
94
|
-
const componentProps = { ...context.attrs }
|
|
95
|
-
delete componentProps.form
|
|
96
|
-
delete componentProps[fieldsPropName]
|
|
97
|
-
componentProps[fieldsPropName] = fieldGroupApi
|
|
98
|
-
return h(component, componentProps, context.slots)
|
|
99
|
-
}
|
|
100
|
-
},
|
|
101
|
-
{ name: 'TanStackForm.FieldGroup', inheritAttrs: false },
|
|
102
|
-
)
|
|
103
|
-
}
|
|
@@ -1,191 +0,0 @@
|
|
|
1
|
-
import { defineFieldGroupRuntime } from './withFields.lib'
|
|
2
|
-
import type {
|
|
3
|
-
DeepKeys,
|
|
4
|
-
DeepKeysWhereValueIncludes,
|
|
5
|
-
DeepValue,
|
|
6
|
-
FormApi,
|
|
7
|
-
} from '@tanstack/form-core'
|
|
8
|
-
import type { Component, PublicProps } from 'vue'
|
|
9
|
-
import type { VueTanStackFormComponents } from '../VueForm/Components.public'
|
|
10
|
-
import type { FieldGroupApi } from './FieldGroupApi.public'
|
|
11
|
-
import type { VueComponentInstance } from '../vueTypes.lib'
|
|
12
|
-
|
|
13
|
-
declare const fieldGroupFieldSlotValueSymbol: unique symbol
|
|
14
|
-
declare const fieldGroupFieldsSymbol: unique symbol
|
|
15
|
-
|
|
16
|
-
export type FieldGroupFieldSlotMode = 'strict' | 'loose'
|
|
17
|
-
export interface FieldGroupFieldSlot<
|
|
18
|
-
out TValue,
|
|
19
|
-
out TMode extends FieldGroupFieldSlotMode = FieldGroupFieldSlotMode,
|
|
20
|
-
> {
|
|
21
|
-
readonly mode: TMode
|
|
22
|
-
readonly [fieldGroupFieldSlotValueSymbol]: TValue
|
|
23
|
-
}
|
|
24
|
-
export type AnyFieldGroupFieldSlot = FieldGroupFieldSlot<any>
|
|
25
|
-
export type StrictFieldGroupFieldSlot<TValue> = FieldGroupFieldSlot<
|
|
26
|
-
TValue,
|
|
27
|
-
'strict'
|
|
28
|
-
>
|
|
29
|
-
export type LooseFieldGroupFieldSlot<TValue> = FieldGroupFieldSlot<
|
|
30
|
-
TValue,
|
|
31
|
-
'loose'
|
|
32
|
-
>
|
|
33
|
-
export type FieldGroupFieldSlotValue<TSlot> =
|
|
34
|
-
TSlot extends FieldGroupFieldSlot<infer TValue> ? TValue : never
|
|
35
|
-
export type FieldGroupFieldSlotModeOf<TSlot> =
|
|
36
|
-
TSlot extends FieldGroupFieldSlot<any, infer TMode> ? TMode : never
|
|
37
|
-
|
|
38
|
-
type IsSame<TTypeA, TTypeB> = [TTypeA] extends [TTypeB]
|
|
39
|
-
? [TTypeB] extends [TTypeA]
|
|
40
|
-
? true
|
|
41
|
-
: false
|
|
42
|
-
: false
|
|
43
|
-
|
|
44
|
-
export type FieldGroupFieldSlotAllows<TSlot, TValue> =
|
|
45
|
-
TSlot extends FieldGroupFieldSlot<infer TAcceptedValue, infer TMode>
|
|
46
|
-
? TMode extends 'strict'
|
|
47
|
-
? IsSame<TValue, TAcceptedValue>
|
|
48
|
-
: [TValue] extends [TAcceptedValue]
|
|
49
|
-
? true
|
|
50
|
-
: false
|
|
51
|
-
: false
|
|
52
|
-
|
|
53
|
-
export type FieldGroupFieldNameForSlot<
|
|
54
|
-
TFieldData,
|
|
55
|
-
TSlot extends AnyFieldGroupFieldSlot,
|
|
56
|
-
> = {
|
|
57
|
-
[TFieldName in DeepKeys<TFieldData>]: FieldGroupFieldSlotAllows<
|
|
58
|
-
TSlot,
|
|
59
|
-
DeepValue<TFieldData, TFieldName>
|
|
60
|
-
> extends true
|
|
61
|
-
? TFieldName
|
|
62
|
-
: never
|
|
63
|
-
}[DeepKeys<TFieldData>]
|
|
64
|
-
|
|
65
|
-
export type FieldGroupFields = Record<string, AnyFieldGroupFieldSlot>
|
|
66
|
-
export type FieldGroupFieldNames<
|
|
67
|
-
TFieldData,
|
|
68
|
-
TFields extends FieldGroupFields,
|
|
69
|
-
> = {
|
|
70
|
-
[TFieldName in keyof TFields]: FieldGroupFieldNameForSlot<
|
|
71
|
-
TFieldData,
|
|
72
|
-
TFields[TFieldName]
|
|
73
|
-
>
|
|
74
|
-
}
|
|
75
|
-
export type FieldGroupFieldData<TFields extends FieldGroupFields> = {
|
|
76
|
-
[
|
|
77
|
-
TFieldName in keyof TFields
|
|
78
|
-
]: TFields[TFieldName] extends FieldGroupFieldSlot<infer TValue, any>
|
|
79
|
-
? TValue
|
|
80
|
-
: never
|
|
81
|
-
}
|
|
82
|
-
export type FieldGroupFieldsOf<TFieldGroup> = TFieldGroup extends {
|
|
83
|
-
readonly [fieldGroupFieldsSymbol]: infer TFields
|
|
84
|
-
}
|
|
85
|
-
? TFields
|
|
86
|
-
: never
|
|
87
|
-
|
|
88
|
-
export type VueFieldGroup<
|
|
89
|
-
TFields extends FieldGroupFields,
|
|
90
|
-
TFieldComponents extends Record<string, Component> = Record<never, never>,
|
|
91
|
-
> = FieldGroupApi<FieldGroupFieldData<TFields>, TFieldComponents> & {
|
|
92
|
-
readonly [fieldGroupFieldsSymbol]: TFields
|
|
93
|
-
}
|
|
94
|
-
export type FieldGroupFieldComponentsOf<TFieldGroup> =
|
|
95
|
-
TFieldGroup extends VueFieldGroup<any, infer TFieldComponents>
|
|
96
|
-
? TFieldComponents
|
|
97
|
-
: never
|
|
98
|
-
export type FieldGroupForm<
|
|
99
|
-
TFieldComponents extends Record<string, Component> = Record<never, never>,
|
|
100
|
-
TFormData = any,
|
|
101
|
-
> = FormApi<TFormData, any> &
|
|
102
|
-
VueTanStackFormComponents<TFormData, any, TFieldComponents>
|
|
103
|
-
|
|
104
|
-
export type FieldGroupFieldBindingForSlot<
|
|
105
|
-
TFormData,
|
|
106
|
-
TSlot extends AnyFieldGroupFieldSlot,
|
|
107
|
-
> =
|
|
108
|
-
TSlot extends FieldGroupFieldSlot<infer TValue, infer TMode>
|
|
109
|
-
? TMode extends 'strict'
|
|
110
|
-
? FieldGroupFieldNameForSlot<TFormData, TSlot>
|
|
111
|
-
: DeepKeysWhereValueIncludes<TFormData, TValue>
|
|
112
|
-
: never
|
|
113
|
-
export type FieldGroupFieldBindings<
|
|
114
|
-
TFields extends FieldGroupFields,
|
|
115
|
-
TFormData = any,
|
|
116
|
-
> = {
|
|
117
|
-
[TFieldName in keyof TFields]: FieldGroupFieldBindingForSlot<
|
|
118
|
-
TFormData,
|
|
119
|
-
TFields[TFieldName]
|
|
120
|
-
>
|
|
121
|
-
}
|
|
122
|
-
export type FieldGroupFieldBindingsOf<TFieldGroup, TFormData> =
|
|
123
|
-
FieldGroupFieldsOf<TFieldGroup> extends FieldGroupFields
|
|
124
|
-
? FieldGroupFieldBindings<FieldGroupFieldsOf<TFieldGroup>, TFormData>
|
|
125
|
-
: never
|
|
126
|
-
export type FieldGroupFieldsPropName<
|
|
127
|
-
TProps,
|
|
128
|
-
TFieldGroup extends VueFieldGroup<any, any>,
|
|
129
|
-
> = {
|
|
130
|
-
[TPropName in keyof TProps]-?: IsSame<
|
|
131
|
-
TProps[TPropName],
|
|
132
|
-
TFieldGroup
|
|
133
|
-
> extends true
|
|
134
|
-
? TPropName
|
|
135
|
-
: never
|
|
136
|
-
}[keyof TProps]
|
|
137
|
-
|
|
138
|
-
export type FieldGroupWithFieldsFn<
|
|
139
|
-
TFieldGroup extends VueFieldGroup<any, any>,
|
|
140
|
-
> = <TProps extends object, const TFieldsPropName extends PropertyKey>(
|
|
141
|
-
component: Component & (new (props: TProps & PublicProps) => any),
|
|
142
|
-
fieldsPropName: TFieldsPropName &
|
|
143
|
-
FieldGroupFieldsPropName<TProps, TFieldGroup>,
|
|
144
|
-
) => new <TFormData>(
|
|
145
|
-
props: Omit<TProps, TFieldsPropName | 'form'> & {
|
|
146
|
-
form: FieldGroupForm<FieldGroupFieldComponentsOf<TFieldGroup>, TFormData>
|
|
147
|
-
} & {
|
|
148
|
-
[TPropName in TFieldsPropName]: FieldGroupFieldBindingsOf<
|
|
149
|
-
TFieldGroup,
|
|
150
|
-
TFormData
|
|
151
|
-
>
|
|
152
|
-
} & PublicProps,
|
|
153
|
-
) => VueComponentInstance<
|
|
154
|
-
Omit<TProps, TFieldsPropName | 'form'> & {
|
|
155
|
-
form: FieldGroupForm<FieldGroupFieldComponentsOf<TFieldGroup>, TFormData>
|
|
156
|
-
} & {
|
|
157
|
-
[TPropName in TFieldsPropName]: FieldGroupFieldBindingsOf<
|
|
158
|
-
TFieldGroup,
|
|
159
|
-
TFormData
|
|
160
|
-
>
|
|
161
|
-
} & Record<string, any>,
|
|
162
|
-
{}
|
|
163
|
-
>
|
|
164
|
-
|
|
165
|
-
export interface FieldGroupHelper {
|
|
166
|
-
strict: <TValue>() => StrictFieldGroupFieldSlot<TValue>
|
|
167
|
-
loose: <TValue>() => LooseFieldGroupFieldSlot<TValue>
|
|
168
|
-
}
|
|
169
|
-
|
|
170
|
-
export interface FieldGroupDefinition<
|
|
171
|
-
TFields extends FieldGroupFields,
|
|
172
|
-
TFieldComponents extends Record<string, Component>,
|
|
173
|
-
> {
|
|
174
|
-
/** The virtual field-group API injected into the bound component. */
|
|
175
|
-
fields: VueFieldGroup<TFields, TFieldComponents>
|
|
176
|
-
/** Binds a component's virtual field API to concrete paths in a form. */
|
|
177
|
-
bindComponent: FieldGroupWithFieldsFn<
|
|
178
|
-
VueFieldGroup<TFields, TFieldComponents>
|
|
179
|
-
>
|
|
180
|
-
}
|
|
181
|
-
|
|
182
|
-
/** Signature shared by `defineFieldGroup` and app-form field-group definers. */
|
|
183
|
-
export type DefineFieldGroupFn<
|
|
184
|
-
TFieldComponents extends Record<string, Component>,
|
|
185
|
-
> = <const TFields extends FieldGroupFields>(
|
|
186
|
-
defineFn: (helper: FieldGroupHelper) => TFields,
|
|
187
|
-
) => FieldGroupDefinition<TFields, TFieldComponents>
|
|
188
|
-
|
|
189
|
-
/** Defines a reusable group of virtual fields. */
|
|
190
|
-
export const defineFieldGroup: DefineFieldGroupFn<Record<never, never>> =
|
|
191
|
-
defineFieldGroupRuntime as never
|
package/src/Subscribe.public.ts
DELETED
|
@@ -1,46 +0,0 @@
|
|
|
1
|
-
import { shallow, useSelector } from '@tanstack/vue-store'
|
|
2
|
-
import { defineComponent } from 'vue'
|
|
3
|
-
import type {
|
|
4
|
-
Atom,
|
|
5
|
-
ReadonlyAtom,
|
|
6
|
-
ReadonlyStore,
|
|
7
|
-
Store,
|
|
8
|
-
} from '@tanstack/vue-store'
|
|
9
|
-
import type { VueComponentWithSlots } from './vueTypes.lib'
|
|
10
|
-
|
|
11
|
-
export type SubscribeSource<TValue> =
|
|
12
|
-
Atom<TValue> | ReadonlyAtom<TValue> | Store<TValue> | ReadonlyStore<TValue>
|
|
13
|
-
|
|
14
|
-
export interface SubscribeProps<in out TSourceData, in out TSelected> {
|
|
15
|
-
source: SubscribeSource<TSourceData>
|
|
16
|
-
selector: (state: TSourceData) => TSelected
|
|
17
|
-
when?: (selected: NoInfer<TSelected>) => boolean
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
export type SubscribeComponent = new <TSourceData, const TSelected>(
|
|
21
|
-
props: SubscribeProps<TSourceData, TSelected>,
|
|
22
|
-
) => InstanceType<
|
|
23
|
-
VueComponentWithSlots<
|
|
24
|
-
SubscribeProps<TSourceData, TSelected>,
|
|
25
|
-
{ default: NoInfer<TSelected> }
|
|
26
|
-
>
|
|
27
|
-
>
|
|
28
|
-
|
|
29
|
-
const SubscribeImpl = defineComponent<SubscribeProps<any, any>>(
|
|
30
|
-
(props, { slots }) => {
|
|
31
|
-
const selected = useSelector(props.source, props.selector, {
|
|
32
|
-
compare: shallow,
|
|
33
|
-
})
|
|
34
|
-
|
|
35
|
-
return () => {
|
|
36
|
-
if (props.when?.(selected.value) === false) return null
|
|
37
|
-
return slots.default?.(selected.value)
|
|
38
|
-
}
|
|
39
|
-
},
|
|
40
|
-
{
|
|
41
|
-
name: 'TanStackForm.Subscribe',
|
|
42
|
-
props: ['source', 'selector', 'when'],
|
|
43
|
-
},
|
|
44
|
-
)
|
|
45
|
-
|
|
46
|
-
export const Subscribe = SubscribeImpl as never as SubscribeComponent
|
|
@@ -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
|
-
}
|