@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
|
@@ -5,6 +5,32 @@ import { Component } from "vue";
|
|
|
5
5
|
//#region src/VueForm/formApiTypes.public.d.ts
|
|
6
6
|
type ExtendedFormApi<TFormData, TFormErrorTypes extends FormErrorTypes, TFieldComponents extends Record<string, Component>> = FormApi<TFormData, TFormErrorTypes> & VueTanStackFormComponents<TFormData, TFormErrorTypes, TFieldComponents>;
|
|
7
7
|
type VueFormApi<TFormData, TFormErrorTypes extends FormErrorTypes, TComponents extends AnyVueFormComponentMap = DefaultVueFormComponentMap> = unknown extends TComponents['formComponents'] ? ExtendedFormApi<TFormData, TFormErrorTypes, TComponents['fieldComponents']> : ExtendedFormApi<TFormData, TFormErrorTypes, TComponents['fieldComponents']> & TComponents['formComponents'];
|
|
8
|
+
/**
|
|
9
|
+
* A Vue form API whose form data and error types are erased.
|
|
10
|
+
*
|
|
11
|
+
* Use it for reusable Vue components that only need core form operations and
|
|
12
|
+
* the `Field`, `ArrayField`, `Subscribe`, or `FormGroup` components common to
|
|
13
|
+
* every Vue form. Field paths and values are not checked against a particular
|
|
14
|
+
* form shape; use `VueFormType` when a component depends on one known form.
|
|
15
|
+
*
|
|
16
|
+
* @example
|
|
17
|
+
* ```vue
|
|
18
|
+
* <script setup lang="ts">
|
|
19
|
+
* defineProps<{ form: AnyVueFormApi }>()
|
|
20
|
+
* </script>
|
|
21
|
+
*
|
|
22
|
+
* <template>
|
|
23
|
+
* <form.Subscribe
|
|
24
|
+
* :selector="(state) => state.isSubmitting"
|
|
25
|
+
* v-slot="isSubmitting"
|
|
26
|
+
* >
|
|
27
|
+
* <button type="submit" :disabled="isSubmitting">
|
|
28
|
+
* {{ isSubmitting ? 'Saving...' : 'Save' }}
|
|
29
|
+
* </button>
|
|
30
|
+
* </form.Subscribe>
|
|
31
|
+
* </template>
|
|
32
|
+
* ```
|
|
33
|
+
*/
|
|
8
34
|
type AnyVueFormApi = AnyFormApi & VueTanStackFormComponents<any, any, any>;
|
|
9
35
|
//#endregion
|
|
10
36
|
export { AnyVueFormApi, VueFormApi, type VueFormComponentMap };
|
|
@@ -4,6 +4,29 @@ import { AppFormOptions } from "../AppForm/appFormOptions.public.js";
|
|
|
4
4
|
import { AnyFormOptions, FormOptions, FormValidators, ToFormErrorTypes } from "@tanstack/form-core";
|
|
5
5
|
//#region src/VueForm/formType.public.d.ts
|
|
6
6
|
type VueFormTypeErrorTypes<TFormValidators extends FormValidators<any>, TSubmitReturn> = unknown extends TSubmitReturn ? any : ToFormErrorTypes<TFormValidators, TSubmitReturn>;
|
|
7
|
+
/**
|
|
8
|
+
* Derives the Vue form API type represented by a reusable options object.
|
|
9
|
+
*
|
|
10
|
+
* Use it to type props for components that belong to one known form shape. It
|
|
11
|
+
* preserves the inferred form data and any components registered through
|
|
12
|
+
* `appFormOptions`. Options such as `onSubmit` can be defined either in the
|
|
13
|
+
* shared options or when the form is created in the component.
|
|
14
|
+
*
|
|
15
|
+
* @example
|
|
16
|
+
* ```ts
|
|
17
|
+
* const profileOptions = formOptions({
|
|
18
|
+
* defaultValues: { name: '' },
|
|
19
|
+
* })
|
|
20
|
+
*
|
|
21
|
+
* type ProfileForm = VueFormType<typeof profileOptions>
|
|
22
|
+
*
|
|
23
|
+
* const props = defineProps<{
|
|
24
|
+
* form: ProfileForm
|
|
25
|
+
* }>()
|
|
26
|
+
* ```
|
|
27
|
+
*
|
|
28
|
+
* @typeParam TOptions - The reusable form or app-form options from which the API derives its form data, error, and registered-component types.
|
|
29
|
+
*/
|
|
7
30
|
type VueFormType<TOptions extends AnyFormOptions | AppFormOptions<any, any, any, AnyVueFormComponentMap>> = TOptions extends AppFormOptions<infer TFormData, infer TFormValidators, infer TSubmitReturn, infer TComponents> ? VueFormApi<TFormData, VueFormTypeErrorTypes<TFormValidators, TSubmitReturn>, TComponents> : TOptions extends FormOptions<infer TFormData, infer TFormValidators, infer TSubmitReturn> ? VueFormApi<TFormData, VueFormTypeErrorTypes<TFormValidators, TSubmitReturn>, DefaultVueFormComponentMap> : never;
|
|
8
31
|
//#endregion
|
|
9
32
|
export { VueFormType };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tanstack/vue-form",
|
|
3
|
-
"version": "2.0.0-alpha.
|
|
3
|
+
"version": "2.0.0-alpha.1",
|
|
4
4
|
"description": "Powerful, type-safe forms for Vue.",
|
|
5
5
|
"author": "tannerlinsley",
|
|
6
6
|
"license": "MIT",
|
|
@@ -22,12 +22,11 @@
|
|
|
22
22
|
},
|
|
23
23
|
"sideEffects": false,
|
|
24
24
|
"files": [
|
|
25
|
-
"dist"
|
|
26
|
-
"src"
|
|
25
|
+
"dist"
|
|
27
26
|
],
|
|
28
27
|
"dependencies": {
|
|
29
28
|
"@tanstack/vue-store": "^0.11.1",
|
|
30
|
-
"@tanstack/form-core": "2.0.0-alpha.
|
|
29
|
+
"@tanstack/form-core": "2.0.0-alpha.1"
|
|
31
30
|
},
|
|
32
31
|
"devDependencies": {
|
|
33
32
|
"@testing-library/vue": "^8.1.0",
|
|
@@ -1,31 +0,0 @@
|
|
|
1
|
-
import { defineComponent, provide } from 'vue'
|
|
2
|
-
import { attachVueFormComponents } from '../VueForm/Components.lib'
|
|
3
|
-
import { FieldContext, FormContext } from './contexts.lib'
|
|
4
|
-
import type { Component } from 'vue'
|
|
5
|
-
import type { AnyInternalFormApi } from '@tanstack/form-core/internals'
|
|
6
|
-
import type { AnyVueFormComponentMap } from './componentMap.public'
|
|
7
|
-
import type { VueAppFormApi } from './VueAppFormApi.public'
|
|
8
|
-
|
|
9
|
-
type AnyVueAppFormApi = VueAppFormApi<any, any, AnyVueFormComponentMap>
|
|
10
|
-
|
|
11
|
-
export 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)
|
|
31
|
-
}
|
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
import type { FormErrorTypes } from '@tanstack/form-core'
|
|
2
|
-
import type { PublicProps } from 'vue'
|
|
3
|
-
import type { VueComponentInstance } from '../vueTypes.lib'
|
|
4
|
-
import type { VueFormApi } from '../VueForm/formApiTypes.public'
|
|
5
|
-
import type { AnyVueFormComponentMap } from './componentMap.public'
|
|
6
|
-
|
|
7
|
-
export type AppFormComponent = new (
|
|
8
|
-
props: PublicProps,
|
|
9
|
-
) => VueComponentInstance<{}, { default: {} }>
|
|
10
|
-
|
|
11
|
-
export type VueAppFormApi<
|
|
12
|
-
TFormData,
|
|
13
|
-
TFormErrorTypes extends FormErrorTypes,
|
|
14
|
-
TComponents extends AnyVueFormComponentMap,
|
|
15
|
-
> = VueFormApi<TFormData, TFormErrorTypes, TComponents> & {
|
|
16
|
-
AppForm: AppFormComponent
|
|
17
|
-
}
|
|
@@ -1,55 +0,0 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
FormOptions,
|
|
3
|
-
FormValidatorData,
|
|
4
|
-
FormValidators,
|
|
5
|
-
InferUnion,
|
|
6
|
-
NullableSchemaData,
|
|
7
|
-
} from '@tanstack/form-core'
|
|
8
|
-
import type { AnyVueFormComponentMap } from './componentMap.public'
|
|
9
|
-
|
|
10
|
-
declare const componentsSymbol: unique symbol
|
|
11
|
-
|
|
12
|
-
export interface AppFormOptions<
|
|
13
|
-
TFormData,
|
|
14
|
-
TFormValidators extends FormValidators<TFormData>,
|
|
15
|
-
TSubmitReturn,
|
|
16
|
-
TComponents extends AnyVueFormComponentMap,
|
|
17
|
-
> extends FormOptions<TFormData, TFormValidators, TSubmitReturn> {
|
|
18
|
-
[componentsSymbol]: TComponents
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
export interface AppFormOptionsApi<TComponents extends AnyVueFormComponentMap> {
|
|
22
|
-
<
|
|
23
|
-
TFormData,
|
|
24
|
-
const TFormValidators extends FormValidators<TFormData>,
|
|
25
|
-
TSubmitReturn,
|
|
26
|
-
>(
|
|
27
|
-
options: FormOptions<TFormData, TFormValidators, TSubmitReturn>,
|
|
28
|
-
): AppFormOptions<TFormData, TFormValidators, TSubmitReturn, TComponents>
|
|
29
|
-
|
|
30
|
-
strictSchema: <
|
|
31
|
-
const TFormValidators extends FormValidators<any>,
|
|
32
|
-
TFormData extends FormValidatorData<TFormValidators>,
|
|
33
|
-
TSubmitReturn,
|
|
34
|
-
>(
|
|
35
|
-
options: FormOptions<TFormData, TFormValidators, TSubmitReturn>,
|
|
36
|
-
) => AppFormOptions<
|
|
37
|
-
FormValidatorData<TFormValidators>,
|
|
38
|
-
TFormValidators,
|
|
39
|
-
TSubmitReturn,
|
|
40
|
-
TComponents
|
|
41
|
-
>
|
|
42
|
-
|
|
43
|
-
looseSchema: <
|
|
44
|
-
const TFormValidators extends FormValidators<any>,
|
|
45
|
-
const TFormData extends NullableSchemaData<TFormValidators>,
|
|
46
|
-
TSubmitReturn,
|
|
47
|
-
>(
|
|
48
|
-
options: FormOptions<TFormData, TFormValidators, TSubmitReturn>,
|
|
49
|
-
) => AppFormOptions<
|
|
50
|
-
InferUnion<TFormData, FormValidatorData<TFormValidators>>,
|
|
51
|
-
TFormValidators,
|
|
52
|
-
TSubmitReturn,
|
|
53
|
-
TComponents
|
|
54
|
-
>
|
|
55
|
-
}
|
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
import type { Component } from 'vue'
|
|
2
|
-
|
|
3
|
-
export interface VueFormComponentMap<
|
|
4
|
-
TFormComponents extends Record<string, Component>,
|
|
5
|
-
TFieldComponents extends Record<string, Component>,
|
|
6
|
-
> {
|
|
7
|
-
formComponents: TFormComponents
|
|
8
|
-
fieldComponents: TFieldComponents
|
|
9
|
-
}
|
|
10
|
-
|
|
11
|
-
export type AnyVueFormComponentMap = VueFormComponentMap<
|
|
12
|
-
Record<string, Component>,
|
|
13
|
-
Record<string, Component>
|
|
14
|
-
>
|
|
15
|
-
|
|
16
|
-
export type DefaultVueFormComponentMap = VueFormComponentMap<
|
|
17
|
-
Record<never, never>,
|
|
18
|
-
Record<never, never>
|
|
19
|
-
>
|
|
@@ -1,31 +0,0 @@
|
|
|
1
|
-
import { inject } from 'vue'
|
|
2
|
-
import type { InjectionKey } from 'vue'
|
|
3
|
-
import type { AnyInternalFieldApi } from '@tanstack/form-core/internals'
|
|
4
|
-
import type { InternalVueFormApi } from '../VueForm/VueFormApi.lib'
|
|
5
|
-
|
|
6
|
-
export const FormContext = Symbol(
|
|
7
|
-
'TanStackForm.FormContext',
|
|
8
|
-
) as InjectionKey<InternalVueFormApi>
|
|
9
|
-
export const FieldContext = Symbol(
|
|
10
|
-
'TanStackForm.FieldContext',
|
|
11
|
-
) as InjectionKey<AnyInternalFieldApi>
|
|
12
|
-
|
|
13
|
-
export function useFieldContext(): AnyInternalFieldApi {
|
|
14
|
-
const field = inject(FieldContext)
|
|
15
|
-
if (field === undefined) {
|
|
16
|
-
throw new Error(
|
|
17
|
-
'TanStack Form: Field components must be used within a `form.Field` component.',
|
|
18
|
-
)
|
|
19
|
-
}
|
|
20
|
-
return field
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
export function useFormContext(): InternalVueFormApi {
|
|
24
|
-
const form = inject(FormContext)
|
|
25
|
-
if (form === undefined) {
|
|
26
|
-
throw new Error(
|
|
27
|
-
'TanStack Form: Form components must be used within a `form.AppForm` component.',
|
|
28
|
-
)
|
|
29
|
-
}
|
|
30
|
-
return form
|
|
31
|
-
}
|
|
@@ -1,32 +0,0 @@
|
|
|
1
|
-
import { useInternalForm } from '../VueForm/VueFormApi.lib'
|
|
2
|
-
import { defineFieldGroup } from '../FieldGroup/withFields.public'
|
|
3
|
-
import { createAppFormInitializer } from './initializeAppForm.lib'
|
|
4
|
-
import { useFormContext } from './contexts.lib'
|
|
5
|
-
import type { AppFormOptionsApi } from './appFormOptions.public'
|
|
6
|
-
import type { AnyVueFormComponentMap } from './componentMap.public'
|
|
7
|
-
import type {
|
|
8
|
-
AppFormHookResult,
|
|
9
|
-
UseAppFormHook,
|
|
10
|
-
} from './createFormHookTypes.public'
|
|
11
|
-
import type { FormOptions } from '@tanstack/form-core'
|
|
12
|
-
|
|
13
|
-
const appFormOptions = ((opts: unknown) => opts) as AppFormOptionsApi<any>
|
|
14
|
-
appFormOptions.strictSchema = (opts) => opts as never
|
|
15
|
-
appFormOptions.looseSchema = (opts) => opts as never
|
|
16
|
-
|
|
17
|
-
export function createFormHook<
|
|
18
|
-
const TComponents extends AnyVueFormComponentMap,
|
|
19
|
-
>(createOptions: TComponents): AppFormHookResult<TComponents> {
|
|
20
|
-
const initializeAppForm = createAppFormInitializer(createOptions)
|
|
21
|
-
|
|
22
|
-
function useExtendedForm(options: FormOptions<any, any, any>) {
|
|
23
|
-
return useInternalForm(options, initializeAppForm)
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
return {
|
|
27
|
-
useFormContext: useFormContext as never,
|
|
28
|
-
appFormOptions,
|
|
29
|
-
defineAppFieldGroup: defineFieldGroup,
|
|
30
|
-
useAppForm: useExtendedForm as never as UseAppFormHook<TComponents>,
|
|
31
|
-
}
|
|
32
|
-
}
|
|
@@ -1,28 +0,0 @@
|
|
|
1
|
-
import type { AppFormOptionsApi } from './appFormOptions.public'
|
|
2
|
-
import type { AnyVueFormComponentMap } from './componentMap.public'
|
|
3
|
-
import type { VueAppFormApi } from './VueAppFormApi.public'
|
|
4
|
-
import type { DefineFieldGroupFn } from '../FieldGroup/withFields.public'
|
|
5
|
-
import type {
|
|
6
|
-
FormOptions,
|
|
7
|
-
FormValidators,
|
|
8
|
-
ToFormErrorTypes,
|
|
9
|
-
} from '@tanstack/form-core'
|
|
10
|
-
|
|
11
|
-
export type UseAppFormHook<TComponents extends AnyVueFormComponentMap> = <
|
|
12
|
-
TFormData,
|
|
13
|
-
const TFormValidators extends FormValidators<TFormData>,
|
|
14
|
-
TSubmitReturn,
|
|
15
|
-
>(
|
|
16
|
-
options: FormOptions<TFormData, TFormValidators, TSubmitReturn>,
|
|
17
|
-
) => VueAppFormApi<
|
|
18
|
-
TFormData,
|
|
19
|
-
ToFormErrorTypes<TFormValidators, TSubmitReturn>,
|
|
20
|
-
TComponents
|
|
21
|
-
>
|
|
22
|
-
|
|
23
|
-
export interface AppFormHookResult<TComponents extends AnyVueFormComponentMap> {
|
|
24
|
-
appFormOptions: AppFormOptionsApi<TComponents>
|
|
25
|
-
defineAppFieldGroup: DefineFieldGroupFn<TComponents['fieldComponents']>
|
|
26
|
-
useAppForm: UseAppFormHook<TComponents>
|
|
27
|
-
useFormContext: () => VueAppFormApi<any, any, TComponents>
|
|
28
|
-
}
|
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
import { defineComponent, h } from 'vue'
|
|
2
|
-
import { useFieldContext } from './contexts.lib'
|
|
3
|
-
import type { Component } from 'vue'
|
|
4
|
-
|
|
5
|
-
export function wrapField(
|
|
6
|
-
component: Component,
|
|
7
|
-
fieldPropKey: string,
|
|
8
|
-
): Component {
|
|
9
|
-
return defineComponent(
|
|
10
|
-
(_props, context) => {
|
|
11
|
-
const field = useFieldContext()
|
|
12
|
-
return () =>
|
|
13
|
-
h(component, { ...context.attrs, [fieldPropKey]: field }, context.slots)
|
|
14
|
-
},
|
|
15
|
-
{ name: 'TanStackForm.FieldComponent', inheritAttrs: false },
|
|
16
|
-
)
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
export function brandComponentFactory(): (component: Component) => Component {
|
|
20
|
-
return (component) => component
|
|
21
|
-
}
|
|
@@ -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>
|