@tanstack/vue-form 0.3.2 → 0.3.4
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/build/legacy/createFormFactory.d.cts +1 -0
- package/build/legacy/createFormFactory.d.ts +1 -0
- package/build/legacy/index.d.cts +2 -1
- package/build/legacy/index.d.ts +2 -1
- package/build/legacy/types.cjs.map +1 -1
- package/build/legacy/types.d.cts +6 -3
- package/build/legacy/types.d.ts +6 -3
- package/build/legacy/useField.cjs +5 -2
- package/build/legacy/useField.cjs.map +1 -1
- package/build/legacy/useField.d.cts +23 -17
- package/build/legacy/useField.d.ts +23 -17
- package/build/legacy/useField.js +8 -3
- package/build/legacy/useField.js.map +1 -1
- package/build/legacy/useForm.cjs.map +1 -1
- package/build/legacy/useForm.d.cts +2 -1
- package/build/legacy/useForm.d.ts +2 -1
- package/build/legacy/useForm.js.map +1 -1
- package/build/lib/createFormFactory.d.ts +8 -0
- package/build/lib/createFormFactory.js +12 -0
- package/build/lib/formContext.d.ts +11 -0
- package/build/lib/formContext.js +12 -0
- package/build/lib/index.d.ts +5 -0
- package/build/lib/index.js +5 -0
- package/build/lib/tests/useField.test.d.ts +2 -0
- package/build/lib/tests/useField.test.jsx +109 -0
- package/build/lib/tests/useForm.test.d.ts +2 -0
- package/build/lib/tests/useForm.test.jsx +71 -0
- package/build/lib/tests/utils.d.ts +1 -0
- package/build/lib/tests/utils.js +5 -0
- package/build/lib/types.d.ts +4 -0
- package/build/lib/types.js +1 -0
- package/build/lib/useField.d.ts +42 -0
- package/build/lib/useField.jsx +41 -0
- package/build/lib/useForm.d.ts +19 -0
- package/build/lib/useForm.jsx +35 -0
- package/build/modern/createFormFactory.d.cts +1 -0
- package/build/modern/createFormFactory.d.ts +1 -0
- package/build/modern/index.d.cts +2 -1
- package/build/modern/index.d.ts +2 -1
- package/build/modern/types.cjs.map +1 -1
- package/build/modern/types.d.cts +6 -3
- package/build/modern/types.d.ts +6 -3
- package/build/modern/useField.cjs +5 -2
- package/build/modern/useField.cjs.map +1 -1
- package/build/modern/useField.d.cts +23 -17
- package/build/modern/useField.d.ts +23 -17
- package/build/modern/useField.js +8 -3
- package/build/modern/useField.js.map +1 -1
- package/build/modern/useForm.cjs.map +1 -1
- package/build/modern/useForm.d.cts +2 -1
- package/build/modern/useForm.d.ts +2 -1
- package/build/modern/useForm.js.map +1 -1
- package/package.json +2 -2
- package/src/types.ts +8 -2
- package/src/useField.tsx +74 -67
- package/src/useForm.tsx +1 -2
package/package.json
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
{
|
2
2
|
"name": "@tanstack/vue-form",
|
3
|
-
"version": "0.3.
|
3
|
+
"version": "0.3.4",
|
4
4
|
"description": "Powerful, type-safe forms for Vue.",
|
5
5
|
"author": "tannerlinsley",
|
6
6
|
"license": "MIT",
|
@@ -45,7 +45,7 @@
|
|
45
45
|
"@tanstack/store": "0.1.3",
|
46
46
|
"@tanstack/vue-store": "0.1.3",
|
47
47
|
"vue-demi": "^0.14.6",
|
48
|
-
"@tanstack/form-core": "0.3.
|
48
|
+
"@tanstack/form-core": "0.3.4"
|
49
49
|
},
|
50
50
|
"devDependencies": {
|
51
51
|
"@vue/composition-api": "1.7.2",
|
package/src/types.ts
CHANGED
@@ -1,3 +1,9 @@
|
|
1
|
-
|
1
|
+
import type { FieldOptions, DeepKeys } from '@tanstack/form-core'
|
2
2
|
|
3
|
-
export type
|
3
|
+
export type UseFieldOptions<
|
4
|
+
TData,
|
5
|
+
TFormData,
|
6
|
+
TName = unknown extends TFormData ? string : DeepKeys<TFormData>,
|
7
|
+
> = FieldOptions<TData, TFormData, TName> & {
|
8
|
+
mode?: 'value' | 'array'
|
9
|
+
}
|
package/src/useField.tsx
CHANGED
@@ -1,28 +1,22 @@
|
|
1
|
-
import {
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
DeepValue,
|
6
|
-
FieldOptions,
|
7
|
-
Narrow,
|
1
|
+
import {
|
2
|
+
FieldApi,
|
3
|
+
type FieldApiOptions,
|
4
|
+
type FormApi,
|
8
5
|
} from '@tanstack/form-core'
|
6
|
+
import type { DeepKeys, DeepValue, Narrow } from '@tanstack/form-core'
|
9
7
|
import { useStore } from '@tanstack/vue-store'
|
10
8
|
import { defineComponent, onMounted, onUnmounted, watch } from 'vue-demi'
|
11
9
|
import type { SlotsType, SetupContext, Ref } from 'vue-demi'
|
12
10
|
import { provideFormContext, useFormContext } from './formContext'
|
11
|
+
import type { UseFieldOptions } from './types'
|
13
12
|
|
14
13
|
declare module '@tanstack/form-core' {
|
15
14
|
// eslint-disable-next-line no-shadow
|
16
|
-
interface FieldApi<
|
17
|
-
Field: FieldComponent<
|
15
|
+
interface FieldApi<_TData, TFormData, Opts, TData> {
|
16
|
+
Field: FieldComponent<TFormData, TData>
|
18
17
|
}
|
19
18
|
}
|
20
19
|
|
21
|
-
export interface UseFieldOptions<TData, TFormData>
|
22
|
-
extends FieldOptions<TData, TFormData> {
|
23
|
-
mode?: 'value' | 'array'
|
24
|
-
}
|
25
|
-
|
26
20
|
export type UseField<TFormData> = <TField extends DeepKeys<TFormData>>(
|
27
21
|
opts?: { name: Narrow<TField> } & UseFieldOptions<
|
28
22
|
DeepValue<TFormData, TField>,
|
@@ -30,25 +24,45 @@ export type UseField<TFormData> = <TField extends DeepKeys<TFormData>>(
|
|
30
24
|
>,
|
31
25
|
) => FieldApi<DeepValue<TFormData, TField>, TFormData>
|
32
26
|
|
33
|
-
export function useField<
|
34
|
-
|
27
|
+
export function useField<
|
28
|
+
TData,
|
29
|
+
TFormData,
|
30
|
+
TName extends unknown extends TFormData
|
31
|
+
? string
|
32
|
+
: DeepKeys<TFormData> = unknown extends TFormData
|
33
|
+
? string
|
34
|
+
: DeepKeys<TFormData>,
|
35
|
+
>(
|
36
|
+
opts: UseFieldOptions<TData, TFormData, TName>,
|
35
37
|
): {
|
36
|
-
api: FieldApi<
|
37
|
-
|
38
|
+
api: FieldApi<
|
39
|
+
TData,
|
40
|
+
TFormData,
|
41
|
+
Omit<typeof opts, 'onMount'> & {
|
42
|
+
form: FormApi<TFormData>
|
43
|
+
}
|
44
|
+
>
|
45
|
+
state: Readonly<
|
46
|
+
Ref<
|
47
|
+
FieldApi<
|
48
|
+
TData,
|
49
|
+
TFormData,
|
50
|
+
Omit<typeof opts, 'onMount'> & {
|
51
|
+
form: FormApi<TFormData>
|
52
|
+
}
|
53
|
+
>['state']
|
54
|
+
>
|
55
|
+
>
|
38
56
|
} {
|
39
57
|
// Get the form API either manually or from context
|
40
58
|
const { formApi, parentFieldName } = useFormContext()
|
41
59
|
|
42
60
|
const fieldApi = (() => {
|
43
|
-
const
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
)
|
48
|
-
.filter((d) => d !== undefined)
|
49
|
-
.join('.')
|
50
|
-
|
51
|
-
const api = new FieldApi({ ...opts, form: formApi, name: name as never })
|
61
|
+
const api = new FieldApi({
|
62
|
+
...opts,
|
63
|
+
form: formApi,
|
64
|
+
name: opts.name,
|
65
|
+
} as never)
|
52
66
|
|
53
67
|
api.Field = Field as never
|
54
68
|
|
@@ -77,56 +91,49 @@ export function useField<TData, TFormData>(
|
|
77
91
|
return { api: fieldApi, state: fieldState } as never
|
78
92
|
}
|
79
93
|
|
80
|
-
// export type FieldValue<TFormData, TField> = TFormData extends any[]
|
81
|
-
// ? TField extends `[${infer TIndex extends number | 'i'}].${infer TRest}`
|
82
|
-
// ? DeepValue<TFormData[TIndex extends 'i' ? number : TIndex], TRest>
|
83
|
-
// : TField extends `[${infer TIndex extends number | 'i'}]`
|
84
|
-
// ? TFormData[TIndex extends 'i' ? number : TIndex]
|
85
|
-
// : never
|
86
|
-
// : TField extends `${infer TPrefix}[${infer TIndex extends
|
87
|
-
// | number
|
88
|
-
// | 'i'}].${infer TRest}`
|
89
|
-
// ? DeepValue<
|
90
|
-
// DeepValue<TFormData, TPrefix>[TIndex extends 'i' ? number : TIndex],
|
91
|
-
// TRest
|
92
|
-
// >
|
93
|
-
// : TField extends `${infer TPrefix}[${infer TIndex extends number | 'i'}]`
|
94
|
-
// ? DeepValue<TFormData, TPrefix>[TIndex extends 'i' ? number : TIndex]
|
95
|
-
// : DeepValue<TFormData, TField>
|
96
|
-
|
97
94
|
export type FieldValue<TFormData, TField> = TFormData extends any[]
|
98
95
|
? unknown extends TField
|
99
96
|
? TFormData[number]
|
100
97
|
: DeepValue<TFormData[number], TField>
|
101
98
|
: DeepValue<TFormData, TField>
|
102
99
|
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
|
100
|
+
type FieldComponentProps<
|
101
|
+
TParentData,
|
102
|
+
TFormData,
|
103
|
+
TField,
|
104
|
+
TName extends unknown extends TFormData ? string : DeepKeys<TFormData>,
|
105
|
+
> = (TParentData extends any[]
|
106
|
+
? {
|
107
|
+
name?: TName
|
108
|
+
index: number
|
109
|
+
}
|
110
|
+
: {
|
111
|
+
name: TName
|
112
|
+
index?: never
|
113
|
+
}) &
|
114
|
+
Omit<UseFieldOptions<TField, TFormData, TName>, 'name' | 'index'>
|
115
|
+
|
116
|
+
export type FieldComponent<TParentData, TFormData> = <
|
117
|
+
// Type of the field
|
118
|
+
TField,
|
119
|
+
// Name of the field
|
120
|
+
TName extends unknown extends TFormData ? string : DeepKeys<TFormData>,
|
121
|
+
>(
|
122
|
+
fieldOptions: FieldComponentProps<TParentData, TFormData, TField, TName>,
|
124
123
|
context: SetupContext<
|
125
124
|
{},
|
126
125
|
SlotsType<{
|
127
126
|
default: {
|
128
|
-
field: FieldApi<
|
129
|
-
|
127
|
+
field: FieldApi<
|
128
|
+
TField,
|
129
|
+
TFormData,
|
130
|
+
FieldApiOptions<TField, TFormData, TName>
|
131
|
+
>
|
132
|
+
state: FieldApi<
|
133
|
+
TField,
|
134
|
+
TFormData,
|
135
|
+
FieldApiOptions<TField, TFormData, TName>
|
136
|
+
>['state']
|
130
137
|
}
|
131
138
|
}>
|
132
139
|
>,
|
package/src/useForm.tsx
CHANGED
@@ -1,5 +1,5 @@
|
|
1
1
|
import { FormApi, type FormState, type FormOptions } from '@tanstack/form-core'
|
2
|
-
import { useStore } from '@tanstack/vue-store'
|
2
|
+
import { type NoInfer, useStore } from '@tanstack/vue-store'
|
3
3
|
import { type UseField, type FieldComponent, Field, useField } from './useField'
|
4
4
|
import { provideFormContext } from './formContext'
|
5
5
|
import {
|
@@ -8,7 +8,6 @@ import {
|
|
8
8
|
type SetupContext,
|
9
9
|
defineComponent,
|
10
10
|
} from 'vue-demi'
|
11
|
-
import type { NoInfer } from './types'
|
12
11
|
|
13
12
|
declare module '@tanstack/form-core' {
|
14
13
|
// eslint-disable-next-line no-shadow
|