Skip to content
Source
Sign inSign up
TanStack/form
Open History to see the last commit

Components.lib.ts

31 lines1.0 KB

1import { defineComponent, provide } from 'vue'
2import { attachVueFormComponents } from '../VueForm/Components.lib'
3import { FieldContext, FormContext } from './contexts.lib'
4import type { Component } from 'vue'
5import type { AnyInternalFormApi } from '@tanstack/form-core/internals'
6import type { AnyVueFormComponentMap } from './componentMap.public'
7import type { VueAppFormApi } from './VueAppFormApi.public'
8​
9type AnyVueAppFormApi = VueAppFormApi<any, any, AnyVueFormComponentMap>
10​
11export function attachVueAppFormComponents(
12 form: AnyInternalFormApi,
13 formComponents: Record<string, Component>,
14 fieldComponents: Record<string, Component>,
15): AnyVueAppFormApi {
16 const resultForm = attachVueFormComponents(
17 form,
18 fieldComponents,
19 FieldContext,
20 ) as never as AnyVueAppFormApi
21​
22 resultForm.AppForm = defineComponent(
23 (_props, { slots }) => {
24 provide(FormContext, resultForm as never)
25 return () => slots.default?.()
26 },
27 { name: 'TanStackForm.AppForm' },
28 ) as never
29​
30 return Object.assign(resultForm, formComponents)