@tanstack/svelte-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.
- package/dist/AppForm/createFormHook.public.d.ts +6 -3
- package/dist/AppForm/createFormHook.public.js +2 -4
- package/dist/AppForm/createFormHookTypes.public.d.ts +81 -5
- package/dist/AppForm/initializeAppForm.lib.d.ts +11 -3
- package/dist/AppForm/initializeAppForm.lib.js +11 -1
- package/dist/Components.public.d.ts +2 -2
- package/dist/Field.svelte +8 -5
- package/dist/FieldGroup/FieldGroupApi.public.d.ts +1 -1
- package/dist/createForm.public.d.ts +23 -1
- package/dist/createForm.public.js +22 -0
- package/dist/createForm.svelte.d.ts +2 -2
- package/dist/formApiTypes.public.d.ts +24 -0
- package/dist/formType.public.d.ts +1 -2
- package/dist/index.d.ts +4 -3
- package/dist/index.js +4 -3
- package/package.json +3 -4
- package/dist/AppForm/appFormOptions.public.d.ts +0 -12
- package/dist/AppForm/appFormOptions.public.js +0 -1
- package/src/AppForm/AppForm.svelte +0 -14
- package/src/AppForm/Components.lib.ts +0 -28
- package/src/AppForm/SvelteAppFormApi.public.ts +0 -14
- package/src/AppForm/appFormOptions.public.ts +0 -57
- package/src/AppForm/componentMap.public.ts +0 -19
- package/src/AppForm/contexts.lib.ts +0 -24
- package/src/AppForm/createFormHook.public.ts +0 -33
- package/src/AppForm/createFormHookTypes.public.ts +0 -30
- package/src/AppForm/fieldComponentHelpers.lib.ts +0 -24
- package/src/AppForm/getFormHookHelpers.public.ts +0 -82
- package/src/AppForm/initializeAppForm.lib.ts +0 -18
- package/src/Components.public.ts +0 -371
- package/src/Field.svelte +0 -152
- package/src/FieldGroup/FieldGroupApi.public.ts +0 -100
- package/src/FieldGroup/withFields.lib.ts +0 -82
- package/src/FieldGroup/withFields.public.ts +0 -179
- package/src/FormGroup.svelte +0 -101
- package/src/Subscribe.svelte +0 -26
- package/src/context-keys.ts +0 -2
- package/src/createForm.public.ts +0 -26
- package/src/createForm.svelte.ts +0 -76
- package/src/formApiTypes.public.ts +0 -48
- package/src/formType.public.ts +0 -46
- package/src/index.ts +0 -17
- package/src/utils.lib.ts +0 -30
|
@@ -1,24 +0,0 @@
|
|
|
1
|
-
import { withComponentProps } from '../utils.lib.js'
|
|
2
|
-
import { useFieldContext } from './contexts.lib'
|
|
3
|
-
import type { Component } from 'svelte'
|
|
4
|
-
|
|
5
|
-
type AnyFieldComponent = Component<any>
|
|
6
|
-
|
|
7
|
-
export function wrapField(
|
|
8
|
-
Component: AnyFieldComponent,
|
|
9
|
-
fieldPropKey: string,
|
|
10
|
-
): AnyFieldComponent {
|
|
11
|
-
return ((internals: any, props: any) =>
|
|
12
|
-
Component(
|
|
13
|
-
internals,
|
|
14
|
-
withComponentProps(props, {
|
|
15
|
-
[fieldPropKey]: useFieldContext(),
|
|
16
|
-
}),
|
|
17
|
-
)) as AnyFieldComponent
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
export function brandComponentFactory(): (
|
|
21
|
-
component: AnyFieldComponent,
|
|
22
|
-
) => AnyFieldComponent {
|
|
23
|
-
return (component) => component
|
|
24
|
-
}
|
|
@@ -1,82 +0,0 @@
|
|
|
1
|
-
import { brandComponentFactory, wrapField } from './fieldComponentHelpers.lib'
|
|
2
|
-
import type { Component, ComponentProps } from 'svelte'
|
|
3
|
-
import type { FieldWithValue } from '@tanstack/form-core'
|
|
4
|
-
|
|
5
|
-
type ExactFieldBrand<out TValue> = {
|
|
6
|
-
readonly __tanstackFieldExactType: TValue
|
|
7
|
-
}
|
|
8
|
-
type AcceptsFieldBrand<out TAcceptedValue> = {
|
|
9
|
-
readonly __tanstackFieldAcceptsType: TAcceptedValue
|
|
10
|
-
}
|
|
11
|
-
type AnyFieldComponent = Component<any>
|
|
12
|
-
type PropsOf<TComponent extends AnyFieldComponent> = ComponentProps<TComponent>
|
|
13
|
-
type FieldValuePropKeys<TProps> = {
|
|
14
|
-
[K in keyof TProps]-?: TProps[K] extends FieldWithValue<any> ? K : never
|
|
15
|
-
}[keyof TProps]
|
|
16
|
-
type FieldValueFromProp<TProp> =
|
|
17
|
-
TProp extends FieldWithValue<infer TValue> ? TValue : never
|
|
18
|
-
type PublicPropsReplacingField<
|
|
19
|
-
TProps,
|
|
20
|
-
TFieldPropKey extends keyof TProps,
|
|
21
|
-
> = Omit<TProps, TFieldPropKey>
|
|
22
|
-
|
|
23
|
-
type StrictInjectedFieldComponent<
|
|
24
|
-
TComponent extends AnyFieldComponent,
|
|
25
|
-
TProps = PropsOf<TComponent>,
|
|
26
|
-
TFieldPropKey extends FieldValuePropKeys<TProps> = FieldValuePropKeys<TProps>,
|
|
27
|
-
> = Component<PublicPropsReplacingField<TProps, TFieldPropKey>> &
|
|
28
|
-
ExactFieldBrand<FieldValueFromProp<TProps[TFieldPropKey]>>
|
|
29
|
-
type LooseInjectedFieldComponent<
|
|
30
|
-
TComponent extends AnyFieldComponent,
|
|
31
|
-
TProps = PropsOf<TComponent>,
|
|
32
|
-
TFieldPropKey extends FieldValuePropKeys<TProps> = FieldValuePropKeys<TProps>,
|
|
33
|
-
> = Component<PublicPropsReplacingField<TProps, TFieldPropKey>> &
|
|
34
|
-
AcceptsFieldBrand<FieldValueFromProp<TProps[TFieldPropKey]>>
|
|
35
|
-
|
|
36
|
-
interface FieldComponentHelper {
|
|
37
|
-
strict: <
|
|
38
|
-
TComponent extends AnyFieldComponent,
|
|
39
|
-
TProps = PropsOf<TComponent>,
|
|
40
|
-
TFieldPropKey extends FieldValuePropKeys<TProps> =
|
|
41
|
-
FieldValuePropKeys<TProps>,
|
|
42
|
-
>(
|
|
43
|
-
Component: TComponent,
|
|
44
|
-
fieldPropKey: TFieldPropKey,
|
|
45
|
-
) => StrictInjectedFieldComponent<TComponent, TProps, TFieldPropKey>
|
|
46
|
-
loose: <
|
|
47
|
-
TComponent extends AnyFieldComponent,
|
|
48
|
-
TProps = PropsOf<TComponent>,
|
|
49
|
-
TFieldPropKey extends FieldValuePropKeys<TProps> =
|
|
50
|
-
FieldValuePropKeys<TProps>,
|
|
51
|
-
>(
|
|
52
|
-
Component: TComponent,
|
|
53
|
-
fieldPropKey: TFieldPropKey,
|
|
54
|
-
) => LooseInjectedFieldComponent<TComponent, TProps, TFieldPropKey>
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
interface FieldBrandHelper {
|
|
58
|
-
strict: <TValue>() => <TComponent extends AnyFieldComponent>(
|
|
59
|
-
component: TComponent,
|
|
60
|
-
) => TComponent & ExactFieldBrand<TValue>
|
|
61
|
-
loose: <TValue>() => <TComponent extends AnyFieldComponent>(
|
|
62
|
-
component: TComponent,
|
|
63
|
-
) => TComponent & AcceptsFieldBrand<TValue>
|
|
64
|
-
}
|
|
65
|
-
|
|
66
|
-
export interface FormHookHelpers {
|
|
67
|
-
fieldBrand: FieldBrandHelper
|
|
68
|
-
fieldComponent: FieldComponentHelper
|
|
69
|
-
}
|
|
70
|
-
|
|
71
|
-
export function getFormHookHelpers(): FormHookHelpers {
|
|
72
|
-
return {
|
|
73
|
-
fieldComponent: {
|
|
74
|
-
strict: wrapField as FieldComponentHelper['strict'],
|
|
75
|
-
loose: wrapField as FieldComponentHelper['loose'],
|
|
76
|
-
},
|
|
77
|
-
fieldBrand: {
|
|
78
|
-
strict: brandComponentFactory as FieldBrandHelper['strict'],
|
|
79
|
-
loose: brandComponentFactory as FieldBrandHelper['loose'],
|
|
80
|
-
},
|
|
81
|
-
}
|
|
82
|
-
}
|
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
import { InternalFormApi } from '@tanstack/form-core/internals'
|
|
2
|
-
import { attachSvelteAppFormComponents } from './Components.lib'
|
|
3
|
-
import type { FormOptions } from '@tanstack/form-core'
|
|
4
|
-
import type { InternalSvelteFormApi } from '../createForm.svelte.js'
|
|
5
|
-
import type { AnySvelteFormComponentMap } from './componentMap.public'
|
|
6
|
-
|
|
7
|
-
export function createAppFormInitializer<
|
|
8
|
-
TComponents extends AnySvelteFormComponentMap,
|
|
9
|
-
>(
|
|
10
|
-
createOptions: TComponents,
|
|
11
|
-
): (options: FormOptions<any, any, any>) => InternalSvelteFormApi {
|
|
12
|
-
return (options) =>
|
|
13
|
-
attachSvelteAppFormComponents(
|
|
14
|
-
new InternalFormApi(options),
|
|
15
|
-
createOptions.formComponents,
|
|
16
|
-
createOptions.fieldComponents,
|
|
17
|
-
) as never
|
|
18
|
-
}
|
package/src/Components.public.ts
DELETED
|
@@ -1,371 +0,0 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
DeepKeys,
|
|
3
|
-
DeepKeysWhereValueIncludes,
|
|
4
|
-
DeepValue,
|
|
5
|
-
FieldApi,
|
|
6
|
-
FieldApiOptions,
|
|
7
|
-
FieldValidators,
|
|
8
|
-
FormErrorTypes,
|
|
9
|
-
FormGroupApi,
|
|
10
|
-
FormGroupOptions,
|
|
11
|
-
FormGroupState,
|
|
12
|
-
FormGroupValidators,
|
|
13
|
-
FormState,
|
|
14
|
-
ToFieldError,
|
|
15
|
-
ToFormGroupErrorTypes,
|
|
16
|
-
} from '@tanstack/form-core'
|
|
17
|
-
import type {
|
|
18
|
-
Component,
|
|
19
|
-
ComponentConstructorOptions,
|
|
20
|
-
Snippet,
|
|
21
|
-
SvelteComponent,
|
|
22
|
-
} from 'svelte'
|
|
23
|
-
|
|
24
|
-
export type WithoutFunction<T> = {
|
|
25
|
-
[K in keyof T as T[K] extends Function ? never : K]: T[K]
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
type ExactFieldBrand<out TValue> = {
|
|
29
|
-
readonly __tanstackFieldExactType: TValue
|
|
30
|
-
}
|
|
31
|
-
type AcceptsFieldBrand<out TAcceptedValue> = {
|
|
32
|
-
readonly __tanstackFieldAcceptsType: TAcceptedValue
|
|
33
|
-
}
|
|
34
|
-
type CompatibleFieldKey<TKey, TComponent, TTargetValue> =
|
|
35
|
-
TComponent extends ExactFieldBrand<infer TExact>
|
|
36
|
-
? [TExact] extends [TTargetValue]
|
|
37
|
-
? [TTargetValue] extends [TExact]
|
|
38
|
-
? TKey
|
|
39
|
-
: never
|
|
40
|
-
: never
|
|
41
|
-
: TComponent extends AcceptsFieldBrand<infer TLoose>
|
|
42
|
-
? [TTargetValue] extends [TLoose]
|
|
43
|
-
? TKey
|
|
44
|
-
: never
|
|
45
|
-
: TKey
|
|
46
|
-
type FilteredFieldComponents<
|
|
47
|
-
TFieldComponents extends Record<string, Component<any>>,
|
|
48
|
-
TTargetValue,
|
|
49
|
-
> = {
|
|
50
|
-
[
|
|
51
|
-
K in keyof TFieldComponents as CompatibleFieldKey<
|
|
52
|
-
K,
|
|
53
|
-
TFieldComponents[K],
|
|
54
|
-
TTargetValue
|
|
55
|
-
>
|
|
56
|
-
]: TFieldComponents[K]
|
|
57
|
-
}
|
|
58
|
-
type FieldComponentsMatchingType<
|
|
59
|
-
TFieldComponents extends Record<string, Component<any>>,
|
|
60
|
-
TTargetValue,
|
|
61
|
-
> = unknown extends TTargetValue
|
|
62
|
-
? TFieldComponents
|
|
63
|
-
: string extends keyof TFieldComponents
|
|
64
|
-
? TFieldComponents
|
|
65
|
-
: FilteredFieldComponents<TFieldComponents, TTargetValue>
|
|
66
|
-
|
|
67
|
-
export type SvelteFieldApi<
|
|
68
|
-
TFieldName,
|
|
69
|
-
TFieldValue,
|
|
70
|
-
TFieldError,
|
|
71
|
-
TFormData,
|
|
72
|
-
TFormErrorTypes extends FormErrorTypes,
|
|
73
|
-
TFieldComponents extends Record<string, Component<any>>,
|
|
74
|
-
> = FieldApi<TFieldName, TFieldValue, TFieldError, TFormData, TFormErrorTypes> &
|
|
75
|
-
FieldComponentsMatchingType<TFieldComponents, TFieldValue>
|
|
76
|
-
|
|
77
|
-
interface SvelteSubscribeProps<TSourceData, TSelected> {
|
|
78
|
-
selector: (state: TSourceData) => TSelected
|
|
79
|
-
when?: (selected: NoInfer<TSelected>) => boolean
|
|
80
|
-
children: Snippet<[NoInfer<TSelected>]>
|
|
81
|
-
}
|
|
82
|
-
|
|
83
|
-
export type SvelteFormSubscribeProps<
|
|
84
|
-
TFormData,
|
|
85
|
-
TFormErrorTypes extends FormErrorTypes,
|
|
86
|
-
TSelected,
|
|
87
|
-
> = SvelteSubscribeProps<FormState<TFormData, TFormErrorTypes>, TSelected>
|
|
88
|
-
|
|
89
|
-
export type SvelteFormSubscribeComponent<
|
|
90
|
-
TFormData,
|
|
91
|
-
TFormErrorTypes extends FormErrorTypes,
|
|
92
|
-
> = (new <TSelected>(
|
|
93
|
-
options: ComponentConstructorOptions<
|
|
94
|
-
SvelteFormSubscribeProps<TFormData, TFormErrorTypes, TSelected>
|
|
95
|
-
>,
|
|
96
|
-
) => SvelteComponent) &
|
|
97
|
-
Component<any> &
|
|
98
|
-
WithoutFunction<Component>
|
|
99
|
-
|
|
100
|
-
export interface SvelteFormFieldProps<
|
|
101
|
-
TFieldData,
|
|
102
|
-
TFieldName,
|
|
103
|
-
TFieldValue,
|
|
104
|
-
TFieldValidators extends FieldValidators<TFieldData, TFieldName, TFieldValue>,
|
|
105
|
-
TGroupFieldError,
|
|
106
|
-
TFormData,
|
|
107
|
-
TFormErrorTypes extends FormErrorTypes,
|
|
108
|
-
TFieldComponents extends Record<string, Component<any>>,
|
|
109
|
-
> extends FieldApiOptions<
|
|
110
|
-
TFieldData,
|
|
111
|
-
TFieldName,
|
|
112
|
-
TFieldValue,
|
|
113
|
-
TFieldValidators,
|
|
114
|
-
TGroupFieldError,
|
|
115
|
-
TFormData,
|
|
116
|
-
TFormErrorTypes
|
|
117
|
-
> {
|
|
118
|
-
children: Snippet<
|
|
119
|
-
[
|
|
120
|
-
SvelteFieldApi<
|
|
121
|
-
TFieldName,
|
|
122
|
-
TFieldValue,
|
|
123
|
-
ToFieldError<
|
|
124
|
-
NoInfer<TFieldValidators>,
|
|
125
|
-
TGroupFieldError,
|
|
126
|
-
TFormErrorTypes
|
|
127
|
-
>,
|
|
128
|
-
TFormData,
|
|
129
|
-
TFormErrorTypes,
|
|
130
|
-
TFieldComponents
|
|
131
|
-
>,
|
|
132
|
-
]
|
|
133
|
-
>
|
|
134
|
-
}
|
|
135
|
-
|
|
136
|
-
export type SvelteFormFieldComponent<
|
|
137
|
-
TFormData,
|
|
138
|
-
TFormErrorTypes extends FormErrorTypes,
|
|
139
|
-
TFieldComponents extends Record<string, Component<any>>,
|
|
140
|
-
> = (new <
|
|
141
|
-
TFieldName extends DeepKeys<TFormData>,
|
|
142
|
-
const TFieldValidators extends FieldValidators<
|
|
143
|
-
TFormData,
|
|
144
|
-
TFieldName,
|
|
145
|
-
DeepValue<TFormData, TFieldName>
|
|
146
|
-
>,
|
|
147
|
-
>(
|
|
148
|
-
options: ComponentConstructorOptions<
|
|
149
|
-
SvelteFormFieldProps<
|
|
150
|
-
TFormData,
|
|
151
|
-
TFieldName,
|
|
152
|
-
DeepValue<TFormData, TFieldName>,
|
|
153
|
-
TFieldValidators,
|
|
154
|
-
never,
|
|
155
|
-
TFormData,
|
|
156
|
-
TFormErrorTypes,
|
|
157
|
-
TFieldComponents
|
|
158
|
-
>
|
|
159
|
-
>,
|
|
160
|
-
) => SvelteComponent) &
|
|
161
|
-
Component<any> &
|
|
162
|
-
WithoutFunction<Component>
|
|
163
|
-
|
|
164
|
-
export type SvelteFormArrayFieldComponent<
|
|
165
|
-
TFormData,
|
|
166
|
-
TFormErrorTypes extends FormErrorTypes,
|
|
167
|
-
TFieldComponents extends Record<string, Component<any>>,
|
|
168
|
-
> = (new <
|
|
169
|
-
TFieldName extends DeepKeysWhereValueIncludes<TFormData, Array<any>>,
|
|
170
|
-
const TFieldValidators extends FieldValidators<
|
|
171
|
-
TFormData,
|
|
172
|
-
TFieldName,
|
|
173
|
-
DeepValue<TFormData, TFieldName>
|
|
174
|
-
>,
|
|
175
|
-
>(
|
|
176
|
-
options: ComponentConstructorOptions<
|
|
177
|
-
SvelteFormFieldProps<
|
|
178
|
-
TFormData,
|
|
179
|
-
TFieldName,
|
|
180
|
-
DeepValue<TFormData, TFieldName>,
|
|
181
|
-
TFieldValidators,
|
|
182
|
-
never,
|
|
183
|
-
TFormData,
|
|
184
|
-
TFormErrorTypes,
|
|
185
|
-
TFieldComponents
|
|
186
|
-
>
|
|
187
|
-
>,
|
|
188
|
-
) => SvelteComponent) &
|
|
189
|
-
Component<any> &
|
|
190
|
-
WithoutFunction<Component>
|
|
191
|
-
|
|
192
|
-
export type SvelteFormGroupSubscribeComponent<
|
|
193
|
-
TGroupValue,
|
|
194
|
-
TGroupErrorTypes extends FormErrorTypes,
|
|
195
|
-
> = (new <TSelected>(
|
|
196
|
-
options: ComponentConstructorOptions<
|
|
197
|
-
SvelteSubscribeProps<
|
|
198
|
-
FormGroupState<TGroupValue, TGroupErrorTypes>,
|
|
199
|
-
TSelected
|
|
200
|
-
>
|
|
201
|
-
>,
|
|
202
|
-
) => SvelteComponent) &
|
|
203
|
-
Component<any> &
|
|
204
|
-
WithoutFunction<Component>
|
|
205
|
-
|
|
206
|
-
export type SvelteFormGroupFieldComponent<
|
|
207
|
-
TFormData,
|
|
208
|
-
TGroupValue,
|
|
209
|
-
TGroupErrorTypes extends FormErrorTypes,
|
|
210
|
-
TFormErrorTypes extends FormErrorTypes,
|
|
211
|
-
TFieldComponents extends Record<string, Component<any>>,
|
|
212
|
-
> = (new <
|
|
213
|
-
TFieldName extends DeepKeys<TGroupValue>,
|
|
214
|
-
const TFieldValidators extends FieldValidators<
|
|
215
|
-
TGroupValue,
|
|
216
|
-
TFieldName,
|
|
217
|
-
DeepValue<TGroupValue, TFieldName>
|
|
218
|
-
>,
|
|
219
|
-
>(
|
|
220
|
-
options: ComponentConstructorOptions<
|
|
221
|
-
SvelteFormFieldProps<
|
|
222
|
-
TGroupValue,
|
|
223
|
-
TFieldName,
|
|
224
|
-
DeepValue<TGroupValue, TFieldName>,
|
|
225
|
-
TFieldValidators,
|
|
226
|
-
TGroupErrorTypes['fieldError'],
|
|
227
|
-
TFormData,
|
|
228
|
-
TFormErrorTypes,
|
|
229
|
-
TFieldComponents
|
|
230
|
-
>
|
|
231
|
-
>,
|
|
232
|
-
) => SvelteComponent) &
|
|
233
|
-
Component<any> &
|
|
234
|
-
WithoutFunction<Component>
|
|
235
|
-
|
|
236
|
-
export type SvelteFormGroupArrayFieldComponent<
|
|
237
|
-
TFormData,
|
|
238
|
-
TGroupValue,
|
|
239
|
-
TGroupErrorTypes extends FormErrorTypes,
|
|
240
|
-
TFormErrorTypes extends FormErrorTypes,
|
|
241
|
-
TFieldComponents extends Record<string, Component<any>>,
|
|
242
|
-
> = (new <
|
|
243
|
-
TFieldName extends DeepKeysWhereValueIncludes<TGroupValue, Array<any>>,
|
|
244
|
-
const TFieldValidators extends FieldValidators<
|
|
245
|
-
TGroupValue,
|
|
246
|
-
TFieldName,
|
|
247
|
-
DeepValue<TGroupValue, TFieldName>
|
|
248
|
-
>,
|
|
249
|
-
>(
|
|
250
|
-
options: ComponentConstructorOptions<
|
|
251
|
-
SvelteFormFieldProps<
|
|
252
|
-
TGroupValue,
|
|
253
|
-
TFieldName,
|
|
254
|
-
DeepValue<TGroupValue, TFieldName>,
|
|
255
|
-
TFieldValidators,
|
|
256
|
-
TGroupErrorTypes['fieldError'],
|
|
257
|
-
TFormData,
|
|
258
|
-
TFormErrorTypes,
|
|
259
|
-
TFieldComponents
|
|
260
|
-
>
|
|
261
|
-
>,
|
|
262
|
-
) => SvelteComponent) &
|
|
263
|
-
Component<any> &
|
|
264
|
-
WithoutFunction<Component>
|
|
265
|
-
|
|
266
|
-
export interface SvelteFormGroupApi<
|
|
267
|
-
TFormData,
|
|
268
|
-
TGroupName,
|
|
269
|
-
TGroupValue,
|
|
270
|
-
TGroupErrorTypes extends FormErrorTypes,
|
|
271
|
-
TFormErrorTypes extends FormErrorTypes,
|
|
272
|
-
TFieldComponents extends Record<string, Component<any>>,
|
|
273
|
-
> extends FormGroupApi<
|
|
274
|
-
TFormData,
|
|
275
|
-
TGroupName,
|
|
276
|
-
TGroupValue,
|
|
277
|
-
TGroupErrorTypes,
|
|
278
|
-
TFormErrorTypes
|
|
279
|
-
> {
|
|
280
|
-
Field: SvelteFormGroupFieldComponent<
|
|
281
|
-
TFormData,
|
|
282
|
-
TGroupValue,
|
|
283
|
-
TGroupErrorTypes,
|
|
284
|
-
TFormErrorTypes,
|
|
285
|
-
TFieldComponents
|
|
286
|
-
>
|
|
287
|
-
ArrayField: SvelteFormGroupArrayFieldComponent<
|
|
288
|
-
TFormData,
|
|
289
|
-
TGroupValue,
|
|
290
|
-
TGroupErrorTypes,
|
|
291
|
-
TFormErrorTypes,
|
|
292
|
-
TFieldComponents
|
|
293
|
-
>
|
|
294
|
-
Subscribe: SvelteFormGroupSubscribeComponent<TGroupValue, TGroupErrorTypes>
|
|
295
|
-
}
|
|
296
|
-
|
|
297
|
-
export interface SvelteFormGroupProps<
|
|
298
|
-
TFormData,
|
|
299
|
-
TGroupName,
|
|
300
|
-
TGroupValue,
|
|
301
|
-
TGroupValidators extends FormGroupValidators<TGroupValue>,
|
|
302
|
-
TFormErrorTypes extends FormErrorTypes,
|
|
303
|
-
TFieldComponents extends Record<string, Component<any>>,
|
|
304
|
-
> extends Omit<
|
|
305
|
-
FormGroupOptions<
|
|
306
|
-
TFormData,
|
|
307
|
-
TGroupName,
|
|
308
|
-
TGroupValue,
|
|
309
|
-
TGroupValidators,
|
|
310
|
-
TFormErrorTypes
|
|
311
|
-
>,
|
|
312
|
-
'form'
|
|
313
|
-
> {
|
|
314
|
-
children: Snippet<
|
|
315
|
-
[
|
|
316
|
-
SvelteFormGroupApi<
|
|
317
|
-
TFormData,
|
|
318
|
-
TGroupName,
|
|
319
|
-
TGroupValue,
|
|
320
|
-
ToFormGroupErrorTypes<NoInfer<TGroupValidators>>,
|
|
321
|
-
TFormErrorTypes,
|
|
322
|
-
TFieldComponents
|
|
323
|
-
>,
|
|
324
|
-
]
|
|
325
|
-
>
|
|
326
|
-
}
|
|
327
|
-
|
|
328
|
-
export type SvelteFormGroupComponent<
|
|
329
|
-
TFormData,
|
|
330
|
-
TFormErrorTypes extends FormErrorTypes,
|
|
331
|
-
TFieldComponents extends Record<string, Component<any>>,
|
|
332
|
-
> = (new <
|
|
333
|
-
TGroupName extends DeepKeys<TFormData>,
|
|
334
|
-
TGroupValue extends DeepValue<TFormData, TGroupName>,
|
|
335
|
-
const TGroupValidators extends FormGroupValidators<TGroupValue>,
|
|
336
|
-
>(
|
|
337
|
-
options: ComponentConstructorOptions<
|
|
338
|
-
SvelteFormGroupProps<
|
|
339
|
-
TFormData,
|
|
340
|
-
TGroupName,
|
|
341
|
-
TGroupValue,
|
|
342
|
-
TGroupValidators,
|
|
343
|
-
TFormErrorTypes,
|
|
344
|
-
TFieldComponents
|
|
345
|
-
>
|
|
346
|
-
>,
|
|
347
|
-
) => SvelteComponent) &
|
|
348
|
-
Component<any> &
|
|
349
|
-
WithoutFunction<Component>
|
|
350
|
-
|
|
351
|
-
export interface SvelteTanStackFormComponents<
|
|
352
|
-
TFormData,
|
|
353
|
-
TFormErrorTypes extends FormErrorTypes,
|
|
354
|
-
TFieldComponents extends Record<string, Component<any>> = Record<
|
|
355
|
-
never,
|
|
356
|
-
never
|
|
357
|
-
>,
|
|
358
|
-
> {
|
|
359
|
-
Field: SvelteFormFieldComponent<TFormData, TFormErrorTypes, TFieldComponents>
|
|
360
|
-
ArrayField: SvelteFormArrayFieldComponent<
|
|
361
|
-
TFormData,
|
|
362
|
-
TFormErrorTypes,
|
|
363
|
-
TFieldComponents
|
|
364
|
-
>
|
|
365
|
-
Subscribe: SvelteFormSubscribeComponent<TFormData, TFormErrorTypes>
|
|
366
|
-
FormGroup: SvelteFormGroupComponent<
|
|
367
|
-
TFormData,
|
|
368
|
-
TFormErrorTypes,
|
|
369
|
-
TFieldComponents
|
|
370
|
-
>
|
|
371
|
-
}
|
package/src/Field.svelte
DELETED
|
@@ -1,152 +0,0 @@
|
|
|
1
|
-
<script module lang="ts">
|
|
2
|
-
import { shallow, useSelector } from '@tanstack/svelte-store'
|
|
3
|
-
import type {
|
|
4
|
-
FieldApi,
|
|
5
|
-
FieldApiOptions,
|
|
6
|
-
FieldValidators,
|
|
7
|
-
FormErrorTypes,
|
|
8
|
-
ToFieldError,
|
|
9
|
-
} from '@tanstack/form-core'
|
|
10
|
-
import type {
|
|
11
|
-
AnyInternalFieldApi,
|
|
12
|
-
AnyInternalFormApi,
|
|
13
|
-
InternalBaseFieldMeta,
|
|
14
|
-
} from '@tanstack/form-core/internals'
|
|
15
|
-
|
|
16
|
-
interface InternalFieldOptions
|
|
17
|
-
extends FieldApiOptions<any, any, any, any, any, any, any> {
|
|
18
|
-
form: AnyInternalFormApi
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
function useDynamicFieldSelector<TSelected>(
|
|
22
|
-
getField: () => AnyInternalFieldApi,
|
|
23
|
-
selector: (field: AnyInternalFieldApi) => TSelected,
|
|
24
|
-
) {
|
|
25
|
-
let selected = $state.raw(selector(getField()))
|
|
26
|
-
|
|
27
|
-
$effect(() => {
|
|
28
|
-
const field = getField()
|
|
29
|
-
const update = () => {
|
|
30
|
-
const next = selector(field)
|
|
31
|
-
if (!shallow(selected, next)) selected = next
|
|
32
|
-
}
|
|
33
|
-
update()
|
|
34
|
-
const subscription = field.atom.subscribe(update)
|
|
35
|
-
return () => subscription.unsubscribe()
|
|
36
|
-
})
|
|
37
|
-
|
|
38
|
-
return {
|
|
39
|
-
get current() {
|
|
40
|
-
return selected
|
|
41
|
-
},
|
|
42
|
-
}
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
export function createField<
|
|
46
|
-
TFieldData,
|
|
47
|
-
TFieldName,
|
|
48
|
-
TFieldValue,
|
|
49
|
-
const TFieldValidators extends FieldValidators<
|
|
50
|
-
TFieldData,
|
|
51
|
-
TFieldName,
|
|
52
|
-
TFieldValue
|
|
53
|
-
>,
|
|
54
|
-
TGroupFieldError,
|
|
55
|
-
TFormData,
|
|
56
|
-
TFormErrorTypes extends FormErrorTypes,
|
|
57
|
-
>(
|
|
58
|
-
options: () =>
|
|
59
|
-
& FieldApiOptions<
|
|
60
|
-
TFieldData,
|
|
61
|
-
TFieldName,
|
|
62
|
-
TFieldValue,
|
|
63
|
-
TFieldValidators,
|
|
64
|
-
TGroupFieldError,
|
|
65
|
-
TFormData,
|
|
66
|
-
TFormErrorTypes
|
|
67
|
-
>
|
|
68
|
-
& { form: AnyInternalFormApi },
|
|
69
|
-
array = false,
|
|
70
|
-
): FieldApi<
|
|
71
|
-
TFieldName,
|
|
72
|
-
TFieldValue,
|
|
73
|
-
ToFieldError<TFieldValidators, TGroupFieldError, TFormErrorTypes>,
|
|
74
|
-
TFormData,
|
|
75
|
-
TFormErrorTypes
|
|
76
|
-
> {
|
|
77
|
-
const initialForm = options().form
|
|
78
|
-
const resetVersion = useSelector(initialForm._atoms.resetVersion)
|
|
79
|
-
const fieldApi = $derived.by(() => {
|
|
80
|
-
resetVersion.current
|
|
81
|
-
const current = options()
|
|
82
|
-
return current.form._getOrCreateFieldApi({
|
|
83
|
-
...current,
|
|
84
|
-
name: current.name,
|
|
85
|
-
} as never)
|
|
86
|
-
})
|
|
87
|
-
|
|
88
|
-
$effect.pre(() => {
|
|
89
|
-
fieldApi._update(options() as InternalFieldOptions)
|
|
90
|
-
})
|
|
91
|
-
|
|
92
|
-
$effect(() => fieldApi._register())
|
|
93
|
-
|
|
94
|
-
const selected = useDynamicFieldSelector(
|
|
95
|
-
() => fieldApi,
|
|
96
|
-
(array
|
|
97
|
-
? (field) => ({
|
|
98
|
-
length: field.value.length,
|
|
99
|
-
version: (field.meta as InternalBaseFieldMeta)._arrayVersion,
|
|
100
|
-
})
|
|
101
|
-
: (field) => ({ value: field.value, meta: field.meta })) as (
|
|
102
|
-
field: AnyInternalFieldApi,
|
|
103
|
-
) => any,
|
|
104
|
-
)
|
|
105
|
-
|
|
106
|
-
return new Proxy({} as AnyInternalFieldApi, {
|
|
107
|
-
get(target, property) {
|
|
108
|
-
if (Reflect.has(target, property)) return Reflect.get(target, property)
|
|
109
|
-
const field = fieldApi
|
|
110
|
-
const state = selected.current
|
|
111
|
-
if (property === 'value') {
|
|
112
|
-
return array ? field.value : (state as any).value
|
|
113
|
-
}
|
|
114
|
-
if (property === 'meta') {
|
|
115
|
-
return array ? field.meta : (state as any).meta
|
|
116
|
-
}
|
|
117
|
-
if (property === 'errors') {
|
|
118
|
-
return array ? field.errors : (state as any).meta.errors
|
|
119
|
-
}
|
|
120
|
-
const value = Reflect.get(field, property, field)
|
|
121
|
-
return typeof value === 'function' ? value.bind(field) : value
|
|
122
|
-
},
|
|
123
|
-
}) as never
|
|
124
|
-
}
|
|
125
|
-
</script>
|
|
126
|
-
|
|
127
|
-
<script lang="ts">
|
|
128
|
-
import { setContext, untrack, type Snippet } from 'svelte'
|
|
129
|
-
import { fieldContextKey } from './context-keys.js'
|
|
130
|
-
|
|
131
|
-
interface Props extends InternalFieldOptions {
|
|
132
|
-
array?: boolean
|
|
133
|
-
children: Snippet<[any]>
|
|
134
|
-
fieldComponents?: Record<string, any>
|
|
135
|
-
}
|
|
136
|
-
|
|
137
|
-
let {
|
|
138
|
-
children,
|
|
139
|
-
array = false,
|
|
140
|
-
fieldComponents = {},
|
|
141
|
-
...fieldOptions
|
|
142
|
-
}: Props = $props()
|
|
143
|
-
|
|
144
|
-
const fieldApi = createField(
|
|
145
|
-
() => fieldOptions,
|
|
146
|
-
untrack(() => array),
|
|
147
|
-
)
|
|
148
|
-
Object.assign(fieldApi, untrack(() => fieldComponents))
|
|
149
|
-
setContext(fieldContextKey, fieldApi)
|
|
150
|
-
</script>
|
|
151
|
-
|
|
152
|
-
{@render children(fieldApi)}
|