@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.
Files changed (38) hide show
  1. package/dist/AppForm/createFormHook.public.d.ts +6 -3
  2. package/dist/AppForm/createFormHook.public.js +2 -4
  3. package/dist/AppForm/createFormHookTypes.public.d.ts +82 -6
  4. package/dist/AppForm/initializeAppForm.lib.js +6 -1
  5. package/dist/FieldGroup/FieldGroupApi.public.d.ts +1 -1
  6. package/dist/VueForm/Components.public.d.ts +2 -2
  7. package/dist/VueForm/formApiTypes.public.d.ts +26 -0
  8. package/dist/VueForm/formType.public.d.ts +24 -2
  9. package/dist/VueForm/useField.lib.js +2 -2
  10. package/dist/VueForm/useForm.public.d.ts +23 -1
  11. package/dist/VueForm/useForm.public.js +22 -0
  12. package/dist/index.d.ts +2 -3
  13. package/package.json +3 -4
  14. package/dist/AppForm/appFormOptions.public.d.ts +0 -14
  15. package/src/AppForm/Components.lib.ts +0 -31
  16. package/src/AppForm/VueAppFormApi.public.ts +0 -17
  17. package/src/AppForm/appFormOptions.public.ts +0 -55
  18. package/src/AppForm/componentMap.public.ts +0 -19
  19. package/src/AppForm/contexts.lib.ts +0 -31
  20. package/src/AppForm/createFormHook.public.ts +0 -32
  21. package/src/AppForm/createFormHookTypes.public.ts +0 -28
  22. package/src/AppForm/fieldComponentHelpers.lib.ts +0 -21
  23. package/src/AppForm/getFormHookHelpers.public.ts +0 -109
  24. package/src/AppForm/initializeAppForm.lib.ts +0 -18
  25. package/src/FieldGroup/FieldGroupApi.public.ts +0 -148
  26. package/src/FieldGroup/withFields.lib.ts +0 -103
  27. package/src/FieldGroup/withFields.public.ts +0 -191
  28. package/src/Subscribe.public.ts +0 -46
  29. package/src/VueForm/Components.lib.ts +0 -182
  30. package/src/VueForm/Components.public.ts +0 -451
  31. package/src/VueForm/VueFormApi.lib.ts +0 -35
  32. package/src/VueForm/fieldSubscriptions.lib.ts +0 -47
  33. package/src/VueForm/formApiTypes.public.ts +0 -32
  34. package/src/VueForm/formType.public.ts +0 -46
  35. package/src/VueForm/useField.lib.ts +0 -64
  36. package/src/VueForm/useForm.public.ts +0 -30
  37. package/src/index.ts +0 -16
  38. package/src/vueTypes.lib.ts +0 -31
@@ -1,109 +0,0 @@
1
- import { brandComponentFactory, wrapField } from './fieldComponentHelpers.lib'
2
- import type { FieldWithValue } from '@tanstack/form-core'
3
- import type { Component, PublicProps } from 'vue'
4
- import type { VueComponentInstance } from '../vueTypes.lib'
5
-
6
- type ExactFieldBrand<out TValue> = {
7
- readonly __tanstackFieldExactType: TValue
8
- }
9
-
10
- type AcceptsFieldBrand<out TAcceptedValue> = {
11
- readonly __tanstackFieldAcceptsType: TAcceptedValue
12
- }
13
-
14
- type AnyFieldComponent = Component
15
- type PropsOf<TComponent> = TComponent extends new (...args: any[]) => {
16
- $props: infer TProps
17
- }
18
- ? Omit<TProps, keyof PublicProps>
19
- : never
20
- type FieldValuePropKeys<TProps> = {
21
- [K in keyof TProps]-?: TProps[K] extends FieldWithValue<any> ? K : never
22
- }[keyof TProps]
23
- type FieldValueFromProp<TProp> =
24
- TProp extends FieldWithValue<infer TValue> ? TValue : never
25
- type FieldValueFromComponentProp<
26
- TProps,
27
- TFieldPropKey extends keyof TProps,
28
- > = FieldValueFromProp<TProps[TFieldPropKey]>
29
- type PublicPropsReplacingField<
30
- TProps,
31
- TFieldPropKey extends keyof TProps,
32
- > = Omit<TProps, TFieldPropKey>
33
-
34
- type StrictInjectedFieldComponent<
35
- TComponent extends AnyFieldComponent,
36
- TProps = PropsOf<TComponent>,
37
- TFieldPropKey extends FieldValuePropKeys<TProps> = FieldValuePropKeys<TProps>,
38
- > = (new (
39
- props: PublicPropsReplacingField<TProps, TFieldPropKey> & PublicProps,
40
- ) => VueComponentInstance<
41
- PublicPropsReplacingField<TProps, TFieldPropKey> & Record<string, any>,
42
- {}
43
- >) &
44
- ExactFieldBrand<FieldValueFromComponentProp<TProps, TFieldPropKey>>
45
-
46
- type LooseInjectedFieldComponent<
47
- TComponent extends AnyFieldComponent,
48
- TProps = PropsOf<TComponent>,
49
- TFieldPropKey extends FieldValuePropKeys<TProps> = FieldValuePropKeys<TProps>,
50
- > = (new (
51
- props: PublicPropsReplacingField<TProps, TFieldPropKey> & PublicProps,
52
- ) => VueComponentInstance<
53
- PublicPropsReplacingField<TProps, TFieldPropKey> & Record<string, any>,
54
- {}
55
- >) &
56
- AcceptsFieldBrand<FieldValueFromComponentProp<TProps, TFieldPropKey>>
57
-
58
- type StrictBrandedFieldComponent<TComponent, TValue> = TComponent &
59
- ExactFieldBrand<TValue>
60
- type LooseBrandedFieldComponent<TComponent, TValue> = TComponent &
61
- AcceptsFieldBrand<TValue>
62
-
63
- interface FieldComponentHelper {
64
- strict: <
65
- TComponent extends AnyFieldComponent,
66
- TProps = PropsOf<TComponent>,
67
- TFieldPropKey extends FieldValuePropKeys<TProps> =
68
- FieldValuePropKeys<TProps>,
69
- >(
70
- component: TComponent,
71
- fieldPropKey: TFieldPropKey,
72
- ) => StrictInjectedFieldComponent<TComponent, TProps, TFieldPropKey>
73
- loose: <
74
- TComponent extends AnyFieldComponent,
75
- TProps = PropsOf<TComponent>,
76
- TFieldPropKey extends FieldValuePropKeys<TProps> =
77
- FieldValuePropKeys<TProps>,
78
- >(
79
- component: TComponent,
80
- fieldPropKey: TFieldPropKey,
81
- ) => LooseInjectedFieldComponent<TComponent, TProps, TFieldPropKey>
82
- }
83
-
84
- interface FieldBrandHelper {
85
- strict: <TValue>() => <TComponent extends AnyFieldComponent>(
86
- component: TComponent,
87
- ) => StrictBrandedFieldComponent<TComponent, TValue>
88
- loose: <TValue>() => <TComponent extends AnyFieldComponent>(
89
- component: TComponent,
90
- ) => LooseBrandedFieldComponent<TComponent, TValue>
91
- }
92
-
93
- export interface FormHookHelpers {
94
- fieldBrand: FieldBrandHelper
95
- fieldComponent: FieldComponentHelper
96
- }
97
-
98
- export function getFormHookHelpers(): FormHookHelpers {
99
- return {
100
- fieldComponent: {
101
- loose: wrapField as FieldComponentHelper['loose'],
102
- strict: wrapField as FieldComponentHelper['strict'],
103
- },
104
- fieldBrand: {
105
- loose: brandComponentFactory as FieldBrandHelper['loose'],
106
- strict: brandComponentFactory as FieldBrandHelper['strict'],
107
- },
108
- }
109
- }
@@ -1,18 +0,0 @@
1
- import { InternalFormApi } from '@tanstack/form-core/internals'
2
- import { attachVueAppFormComponents } from './Components.lib'
3
- import type { FormOptions } from '@tanstack/form-core'
4
- import type { InternalVueFormApi } from '../VueForm/VueFormApi.lib'
5
- import type { AnyVueFormComponentMap } from './componentMap.public'
6
-
7
- export function createAppFormInitializer<
8
- TComponents extends AnyVueFormComponentMap,
9
- >(
10
- createOptions: TComponents,
11
- ): (options: FormOptions<any, any, any>) => InternalVueFormApi {
12
- return (options) =>
13
- attachVueAppFormComponents(
14
- new InternalFormApi(options),
15
- createOptions.formComponents,
16
- createOptions.fieldComponents,
17
- ) as never
18
- }
@@ -1,148 +0,0 @@
1
- import type {
2
- DeepKeys,
3
- DeepKeysWhereValueIncludes,
4
- DeepValue,
5
- FieldValidators,
6
- FormApiArrayMethods,
7
- FormApiFieldMethods,
8
- FormErrorTypes,
9
- FormState,
10
- ToFieldError,
11
- ValidationIssue,
12
- } from '@tanstack/form-core'
13
- import type { Component, PublicProps } from 'vue'
14
- import type { ReadonlyAtom } from '@tanstack/vue-store'
15
- import type {
16
- VueFieldApi,
17
- VueFormFieldProps,
18
- VueFormSubscribeProps,
19
- } from '../VueForm/Components.public'
20
- import type { VueComponentInstance } from '../vueTypes.lib'
21
-
22
- export type FieldGroupFieldComponent<
23
- in out TFieldData,
24
- in out TFieldComponents extends Record<string, Component>,
25
- > = new <const TFieldName extends DeepKeys<TFieldData>>(
26
- props: VueFormFieldProps<
27
- TFieldData,
28
- TFieldName,
29
- DeepValue<TFieldData, TFieldName>,
30
- FieldValidators<TFieldData, TFieldName, DeepValue<TFieldData, TFieldName>>,
31
- ValidationIssue,
32
- unknown,
33
- FormErrorTypes,
34
- TFieldComponents
35
- > &
36
- PublicProps,
37
- ) => VueComponentInstance<
38
- VueFormFieldProps<
39
- TFieldData,
40
- TFieldName,
41
- DeepValue<TFieldData, TFieldName>,
42
- FieldValidators<TFieldData, TFieldName, DeepValue<TFieldData, TFieldName>>,
43
- ValidationIssue,
44
- unknown,
45
- FormErrorTypes,
46
- TFieldComponents
47
- >,
48
- {
49
- default: {
50
- field: VueFieldApi<
51
- TFieldName,
52
- DeepValue<TFieldData, TFieldName>,
53
- ToFieldError<
54
- FieldValidators<
55
- TFieldData,
56
- TFieldName,
57
- DeepValue<TFieldData, TFieldName>
58
- >,
59
- ValidationIssue,
60
- FormErrorTypes
61
- >,
62
- unknown,
63
- FormErrorTypes,
64
- TFieldComponents
65
- >
66
- }
67
- }
68
- >
69
-
70
- export type FieldGroupArrayFieldComponent<
71
- in out TFieldData,
72
- in out TFieldComponents extends Record<string, Component>,
73
- > = new <
74
- const TFieldName extends DeepKeysWhereValueIncludes<TFieldData, Array<any>>,
75
- >(
76
- props: VueFormFieldProps<
77
- TFieldData,
78
- TFieldName,
79
- DeepValue<TFieldData, TFieldName>,
80
- FieldValidators<TFieldData, TFieldName, DeepValue<TFieldData, TFieldName>>,
81
- ValidationIssue,
82
- unknown,
83
- FormErrorTypes,
84
- TFieldComponents
85
- > &
86
- PublicProps,
87
- ) => VueComponentInstance<
88
- VueFormFieldProps<
89
- TFieldData,
90
- TFieldName,
91
- DeepValue<TFieldData, TFieldName>,
92
- FieldValidators<TFieldData, TFieldName, DeepValue<TFieldData, TFieldName>>,
93
- ValidationIssue,
94
- unknown,
95
- FormErrorTypes,
96
- TFieldComponents
97
- >,
98
- {
99
- default: {
100
- field: VueFieldApi<
101
- TFieldName,
102
- DeepValue<TFieldData, TFieldName>,
103
- ToFieldError<
104
- FieldValidators<
105
- TFieldData,
106
- TFieldName,
107
- DeepValue<TFieldData, TFieldName>
108
- >,
109
- ValidationIssue,
110
- FormErrorTypes
111
- >,
112
- unknown,
113
- FormErrorTypes,
114
- TFieldComponents
115
- >
116
- }
117
- }
118
- >
119
-
120
- export type FieldGroupSubscribeProps<TSelected> = VueFormSubscribeProps<
121
- unknown,
122
- FormErrorTypes,
123
- TSelected
124
- >
125
-
126
- export type FieldGroupSubscribeComponent = new <TSelected>(
127
- props: FieldGroupSubscribeProps<TSelected> & PublicProps,
128
- ) => VueComponentInstance<
129
- FieldGroupSubscribeProps<TSelected>,
130
- { default: NoInfer<TSelected> }
131
- >
132
-
133
- export interface FieldGroupApi<
134
- in out TFieldData,
135
- in out TFieldComponents extends Record<string, Component> = Record<
136
- never,
137
- never
138
- >,
139
- >
140
- extends FormApiFieldMethods<TFieldData>, FormApiArrayMethods<TFieldData> {
141
- atom: ReadonlyAtom<TFieldData>
142
- Field: FieldGroupFieldComponent<TFieldData, TFieldComponents>
143
- ArrayField: FieldGroupArrayFieldComponent<TFieldData, TFieldComponents>
144
- Subscribe: FieldGroupSubscribeComponent
145
- }
146
-
147
- export type AnyFieldGroupApi = FieldGroupApi<any, Record<string, Component>>
148
- export type FieldGroupFormState = FormState<unknown, FormErrorTypes>
@@ -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
@@ -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