@tanstack/svelte-form 1.33.5 → 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/AppForm/AppForm.svelte +14 -0
- package/dist/AppForm/Components.lib.d.ts +7 -0
- package/dist/AppForm/Components.lib.js +8 -0
- package/dist/AppForm/SvelteAppFormApi.public.d.ts +10 -0
- package/dist/AppForm/appFormOptions.public.d.ts +12 -0
- package/dist/AppForm/appFormOptions.public.js +1 -0
- package/dist/AppForm/componentMap.public.d.ts +7 -0
- package/dist/AppForm/componentMap.public.js +1 -0
- package/dist/AppForm/contexts.lib.d.ts +4 -0
- package/dist/AppForm/contexts.lib.js +16 -0
- package/dist/AppForm/createFormHook.public.d.ts +3 -0
- package/dist/AppForm/createFormHook.public.js +20 -0
- package/dist/AppForm/createFormHookTypes.public.d.ts +12 -0
- package/dist/AppForm/createFormHookTypes.public.js +1 -0
- package/dist/AppForm/fieldComponentHelpers.lib.d.ts +5 -0
- package/dist/AppForm/fieldComponentHelpers.lib.js +10 -0
- package/dist/AppForm/getFormHookHelpers.public.d.ts +31 -0
- package/dist/AppForm/getFormHookHelpers.public.js +13 -0
- package/dist/AppForm/initializeAppForm.lib.d.ts +4 -0
- package/dist/AppForm/initializeAppForm.lib.js +5 -0
- package/dist/Components.public.d.ts +52 -0
- package/dist/Components.public.js +1 -0
- package/dist/Field.svelte +125 -314
- package/dist/Field.svelte.d.ts +14 -30
- package/dist/FieldGroup/FieldGroupApi.public.d.ts +15 -0
- package/dist/FieldGroup/FieldGroupApi.public.js +1 -0
- package/dist/FieldGroup/withFields.lib.d.ts +5 -0
- package/dist/FieldGroup/withFields.lib.js +44 -0
- package/dist/FieldGroup/withFields.public.d.ts +70 -0
- package/dist/FieldGroup/withFields.public.js +3 -0
- package/dist/FormGroup.svelte +81 -302
- package/dist/FormGroup.svelte.d.ts +13 -30
- package/dist/Subscribe.svelte +18 -8
- package/dist/Subscribe.svelte.d.ts +5 -3
- package/dist/createForm.public.d.ts +5 -0
- package/dist/createForm.public.js +5 -0
- package/dist/createForm.svelte.d.ts +11 -27
- package/dist/createForm.svelte.js +29 -19
- package/dist/formApiTypes.public.d.ts +37 -0
- package/dist/formApiTypes.public.js +1 -0
- package/dist/formType.public.d.ts +7 -0
- package/dist/formType.public.js +1 -0
- package/dist/index.d.ts +17 -6
- package/dist/index.js +17 -5
- package/dist/utils.lib.d.ts +1 -0
- package/dist/utils.lib.js +28 -0
- package/package.json +6 -7
- package/dist/AppField.svelte +0 -19
- package/dist/AppField.svelte.d.ts +0 -10
- package/dist/AppForm.svelte +0 -16
- package/dist/InnerAppField.svelte +0 -17
- package/dist/InnerAppField.svelte.d.ts +0 -9
- package/dist/createFormCreator.svelte.d.ts +0 -26
- package/dist/createFormCreator.svelte.js +0 -51
- package/dist/types.d.ts +0 -21
- package/src/AppField.svelte +0 -19
- package/src/AppForm.svelte +0 -16
- package/src/Field.svelte +0 -341
- package/src/FormGroup.svelte +0 -322
- package/src/InnerAppField.svelte +0 -17
- package/src/Subscribe.svelte +0 -16
- package/src/context-keys.ts +0 -2
- package/src/createForm.svelte.ts +0 -350
- package/src/createFormCreator.svelte.ts +0 -321
- package/src/index.ts +0 -16
- package/src/types.ts +0 -567
- /package/dist/{AppForm.svelte.d.ts → AppForm/AppForm.svelte.d.ts} +0 -0
- /package/dist/{types.js → AppForm/SvelteAppFormApi.public.js} +0 -0
package/src/createForm.svelte.ts
DELETED
|
@@ -1,350 +0,0 @@
|
|
|
1
|
-
import { FormApi } from '@tanstack/form-core'
|
|
2
|
-
import { useSelector } from '@tanstack/svelte-store'
|
|
3
|
-
import { onMount } from 'svelte'
|
|
4
|
-
import Field from './Field.svelte'
|
|
5
|
-
import FormGroup from './FormGroup.svelte'
|
|
6
|
-
import Subscribe from './Subscribe.svelte'
|
|
7
|
-
import type {
|
|
8
|
-
Component,
|
|
9
|
-
ComponentConstructorOptions,
|
|
10
|
-
Snippet,
|
|
11
|
-
SvelteComponent,
|
|
12
|
-
} from 'svelte'
|
|
13
|
-
import type {
|
|
14
|
-
FormAsyncValidateOrFn,
|
|
15
|
-
FormOptions,
|
|
16
|
-
FormState,
|
|
17
|
-
FormValidateOrFn,
|
|
18
|
-
} from '@tanstack/form-core'
|
|
19
|
-
import type {
|
|
20
|
-
FieldComponent,
|
|
21
|
-
FormGroupComponent,
|
|
22
|
-
WithoutFunction,
|
|
23
|
-
} from './types.js'
|
|
24
|
-
|
|
25
|
-
export interface SvelteFormApi<
|
|
26
|
-
TParentData,
|
|
27
|
-
TFormOnMount extends undefined | FormValidateOrFn<TParentData>,
|
|
28
|
-
TFormOnChange extends undefined | FormValidateOrFn<TParentData>,
|
|
29
|
-
TFormOnChangeAsync extends undefined | FormAsyncValidateOrFn<TParentData>,
|
|
30
|
-
TFormOnBlur extends undefined | FormValidateOrFn<TParentData>,
|
|
31
|
-
TFormOnBlurAsync extends undefined | FormAsyncValidateOrFn<TParentData>,
|
|
32
|
-
TFormOnSubmit extends undefined | FormValidateOrFn<TParentData>,
|
|
33
|
-
TFormOnSubmitAsync extends undefined | FormAsyncValidateOrFn<TParentData>,
|
|
34
|
-
TFormOnDynamic extends undefined | FormValidateOrFn<TParentData>,
|
|
35
|
-
TFormOnDynamicAsync extends undefined | FormAsyncValidateOrFn<TParentData>,
|
|
36
|
-
TFormOnServer extends undefined | FormAsyncValidateOrFn<TParentData>,
|
|
37
|
-
TSubmitMeta,
|
|
38
|
-
> {
|
|
39
|
-
Field: FieldComponent<
|
|
40
|
-
TParentData,
|
|
41
|
-
TFormOnMount,
|
|
42
|
-
TFormOnChange,
|
|
43
|
-
TFormOnChangeAsync,
|
|
44
|
-
TFormOnBlur,
|
|
45
|
-
TFormOnBlurAsync,
|
|
46
|
-
TFormOnSubmit,
|
|
47
|
-
TFormOnSubmitAsync,
|
|
48
|
-
TFormOnDynamic,
|
|
49
|
-
TFormOnDynamicAsync,
|
|
50
|
-
TFormOnServer,
|
|
51
|
-
TSubmitMeta
|
|
52
|
-
>
|
|
53
|
-
FormGroup: FormGroupComponent<
|
|
54
|
-
TParentData,
|
|
55
|
-
TFormOnMount,
|
|
56
|
-
TFormOnChange,
|
|
57
|
-
TFormOnChangeAsync,
|
|
58
|
-
TFormOnBlur,
|
|
59
|
-
TFormOnBlurAsync,
|
|
60
|
-
TFormOnSubmit,
|
|
61
|
-
TFormOnSubmitAsync,
|
|
62
|
-
TFormOnDynamic,
|
|
63
|
-
TFormOnDynamicAsync,
|
|
64
|
-
TFormOnServer,
|
|
65
|
-
TSubmitMeta
|
|
66
|
-
>
|
|
67
|
-
useSelector: <
|
|
68
|
-
TSelected = NoInfer<
|
|
69
|
-
FormState<
|
|
70
|
-
TParentData,
|
|
71
|
-
TFormOnMount,
|
|
72
|
-
TFormOnChange,
|
|
73
|
-
TFormOnChangeAsync,
|
|
74
|
-
TFormOnBlur,
|
|
75
|
-
TFormOnBlurAsync,
|
|
76
|
-
TFormOnSubmit,
|
|
77
|
-
TFormOnSubmitAsync,
|
|
78
|
-
TFormOnDynamic,
|
|
79
|
-
TFormOnDynamicAsync,
|
|
80
|
-
TFormOnServer
|
|
81
|
-
>
|
|
82
|
-
>,
|
|
83
|
-
>(
|
|
84
|
-
selector?: (
|
|
85
|
-
state: NoInfer<
|
|
86
|
-
FormState<
|
|
87
|
-
TParentData,
|
|
88
|
-
TFormOnMount,
|
|
89
|
-
TFormOnChange,
|
|
90
|
-
TFormOnChangeAsync,
|
|
91
|
-
TFormOnBlur,
|
|
92
|
-
TFormOnBlurAsync,
|
|
93
|
-
TFormOnSubmit,
|
|
94
|
-
TFormOnSubmitAsync,
|
|
95
|
-
TFormOnDynamic,
|
|
96
|
-
TFormOnDynamicAsync,
|
|
97
|
-
TFormOnServer
|
|
98
|
-
>
|
|
99
|
-
>,
|
|
100
|
-
) => TSelected,
|
|
101
|
-
) => { current: TSelected }
|
|
102
|
-
/**
|
|
103
|
-
* @deprecated Use `form.useSelector` instead.
|
|
104
|
-
*/
|
|
105
|
-
useStore: <
|
|
106
|
-
TSelected = NoInfer<
|
|
107
|
-
FormState<
|
|
108
|
-
TParentData,
|
|
109
|
-
TFormOnMount,
|
|
110
|
-
TFormOnChange,
|
|
111
|
-
TFormOnChangeAsync,
|
|
112
|
-
TFormOnBlur,
|
|
113
|
-
TFormOnBlurAsync,
|
|
114
|
-
TFormOnSubmit,
|
|
115
|
-
TFormOnSubmitAsync,
|
|
116
|
-
TFormOnDynamic,
|
|
117
|
-
TFormOnDynamicAsync,
|
|
118
|
-
TFormOnServer
|
|
119
|
-
>
|
|
120
|
-
>,
|
|
121
|
-
>(
|
|
122
|
-
selector?: (
|
|
123
|
-
state: NoInfer<
|
|
124
|
-
FormState<
|
|
125
|
-
TParentData,
|
|
126
|
-
TFormOnMount,
|
|
127
|
-
TFormOnChange,
|
|
128
|
-
TFormOnChangeAsync,
|
|
129
|
-
TFormOnBlur,
|
|
130
|
-
TFormOnBlurAsync,
|
|
131
|
-
TFormOnSubmit,
|
|
132
|
-
TFormOnSubmitAsync,
|
|
133
|
-
TFormOnDynamic,
|
|
134
|
-
TFormOnDynamicAsync,
|
|
135
|
-
TFormOnServer
|
|
136
|
-
>
|
|
137
|
-
>,
|
|
138
|
-
) => TSelected,
|
|
139
|
-
) => { current: TSelected }
|
|
140
|
-
// This giant type allows the type
|
|
141
|
-
// - to be used as a function (which they are now in Svelte 5)
|
|
142
|
-
// - to be used as a class (which they were in Svelte 4, and which Svelte intellisense still uses for backwards compat)
|
|
143
|
-
// - to preserve the generics correctly
|
|
144
|
-
// Once Svelte intellisense no longer has/needs backwards compat, we can remove the class constructor part
|
|
145
|
-
Subscribe: (<
|
|
146
|
-
TSelected = NoInfer<
|
|
147
|
-
FormState<
|
|
148
|
-
TParentData,
|
|
149
|
-
TFormOnMount,
|
|
150
|
-
TFormOnChange,
|
|
151
|
-
TFormOnChangeAsync,
|
|
152
|
-
TFormOnBlur,
|
|
153
|
-
TFormOnBlurAsync,
|
|
154
|
-
TFormOnSubmit,
|
|
155
|
-
TFormOnSubmitAsync,
|
|
156
|
-
TFormOnDynamic,
|
|
157
|
-
TFormOnDynamicAsync,
|
|
158
|
-
TFormOnServer
|
|
159
|
-
>
|
|
160
|
-
>,
|
|
161
|
-
>(
|
|
162
|
-
internal: any,
|
|
163
|
-
props: {
|
|
164
|
-
selector?: (
|
|
165
|
-
state: NoInfer<
|
|
166
|
-
FormState<
|
|
167
|
-
TParentData,
|
|
168
|
-
TFormOnMount,
|
|
169
|
-
TFormOnChange,
|
|
170
|
-
TFormOnChangeAsync,
|
|
171
|
-
TFormOnBlur,
|
|
172
|
-
TFormOnBlurAsync,
|
|
173
|
-
TFormOnSubmit,
|
|
174
|
-
TFormOnSubmitAsync,
|
|
175
|
-
TFormOnDynamic,
|
|
176
|
-
TFormOnDynamicAsync,
|
|
177
|
-
TFormOnServer
|
|
178
|
-
>
|
|
179
|
-
>,
|
|
180
|
-
) => TSelected
|
|
181
|
-
children: Snippet<[NoInfer<TSelected>]>
|
|
182
|
-
},
|
|
183
|
-
) => {}) &
|
|
184
|
-
(new <
|
|
185
|
-
TSelected = NoInfer<
|
|
186
|
-
FormState<
|
|
187
|
-
TParentData,
|
|
188
|
-
TFormOnMount,
|
|
189
|
-
TFormOnChange,
|
|
190
|
-
TFormOnChangeAsync,
|
|
191
|
-
TFormOnBlur,
|
|
192
|
-
TFormOnBlurAsync,
|
|
193
|
-
TFormOnSubmit,
|
|
194
|
-
TFormOnSubmitAsync,
|
|
195
|
-
TFormOnDynamic,
|
|
196
|
-
TFormOnDynamicAsync,
|
|
197
|
-
TFormOnServer
|
|
198
|
-
>
|
|
199
|
-
>,
|
|
200
|
-
>(
|
|
201
|
-
opts: ComponentConstructorOptions<{
|
|
202
|
-
selector?: (
|
|
203
|
-
state: NoInfer<
|
|
204
|
-
FormState<
|
|
205
|
-
TParentData,
|
|
206
|
-
TFormOnMount,
|
|
207
|
-
TFormOnChange,
|
|
208
|
-
TFormOnChangeAsync,
|
|
209
|
-
TFormOnBlur,
|
|
210
|
-
TFormOnBlurAsync,
|
|
211
|
-
TFormOnSubmit,
|
|
212
|
-
TFormOnSubmitAsync,
|
|
213
|
-
TFormOnDynamic,
|
|
214
|
-
TFormOnDynamicAsync,
|
|
215
|
-
TFormOnServer
|
|
216
|
-
>
|
|
217
|
-
>,
|
|
218
|
-
) => TSelected
|
|
219
|
-
children: Snippet<[NoInfer<TSelected>]>
|
|
220
|
-
}>,
|
|
221
|
-
) => SvelteComponent) &
|
|
222
|
-
WithoutFunction<Component>
|
|
223
|
-
}
|
|
224
|
-
|
|
225
|
-
/**
|
|
226
|
-
* An extended version of the `FormApi` class that includes Svelte-specific functionalities from `SvelteFormApi`
|
|
227
|
-
*/
|
|
228
|
-
export type SvelteFormExtendedApi<
|
|
229
|
-
TFormData,
|
|
230
|
-
TOnMount extends undefined | FormValidateOrFn<TFormData>,
|
|
231
|
-
TOnChange extends undefined | FormValidateOrFn<TFormData>,
|
|
232
|
-
TOnChangeAsync extends undefined | FormAsyncValidateOrFn<TFormData>,
|
|
233
|
-
TOnBlur extends undefined | FormValidateOrFn<TFormData>,
|
|
234
|
-
TOnBlurAsync extends undefined | FormAsyncValidateOrFn<TFormData>,
|
|
235
|
-
TOnSubmit extends undefined | FormValidateOrFn<TFormData>,
|
|
236
|
-
TOnSubmitAsync extends undefined | FormAsyncValidateOrFn<TFormData>,
|
|
237
|
-
TOnDynamic extends undefined | FormValidateOrFn<TFormData>,
|
|
238
|
-
TOnDynamicAsync extends undefined | FormAsyncValidateOrFn<TFormData>,
|
|
239
|
-
TOnServer extends undefined | FormAsyncValidateOrFn<TFormData>,
|
|
240
|
-
TSubmitMeta,
|
|
241
|
-
> = FormApi<
|
|
242
|
-
TFormData,
|
|
243
|
-
TOnMount,
|
|
244
|
-
TOnChange,
|
|
245
|
-
TOnChangeAsync,
|
|
246
|
-
TOnBlur,
|
|
247
|
-
TOnBlurAsync,
|
|
248
|
-
TOnSubmit,
|
|
249
|
-
TOnSubmitAsync,
|
|
250
|
-
TOnDynamic,
|
|
251
|
-
TOnDynamicAsync,
|
|
252
|
-
TOnServer,
|
|
253
|
-
TSubmitMeta
|
|
254
|
-
> &
|
|
255
|
-
SvelteFormApi<
|
|
256
|
-
TFormData,
|
|
257
|
-
TOnMount,
|
|
258
|
-
TOnChange,
|
|
259
|
-
TOnChangeAsync,
|
|
260
|
-
TOnBlur,
|
|
261
|
-
TOnBlurAsync,
|
|
262
|
-
TOnSubmit,
|
|
263
|
-
TOnSubmitAsync,
|
|
264
|
-
TOnDynamic,
|
|
265
|
-
TOnDynamicAsync,
|
|
266
|
-
TOnServer,
|
|
267
|
-
TSubmitMeta
|
|
268
|
-
>
|
|
269
|
-
|
|
270
|
-
export function createForm<
|
|
271
|
-
TParentData,
|
|
272
|
-
TFormOnMount extends undefined | FormValidateOrFn<TParentData>,
|
|
273
|
-
TFormOnChange extends undefined | FormValidateOrFn<TParentData>,
|
|
274
|
-
TFormOnChangeAsync extends undefined | FormAsyncValidateOrFn<TParentData>,
|
|
275
|
-
TFormOnBlur extends undefined | FormValidateOrFn<TParentData>,
|
|
276
|
-
TFormOnBlurAsync extends undefined | FormAsyncValidateOrFn<TParentData>,
|
|
277
|
-
TFormOnSubmit extends undefined | FormValidateOrFn<TParentData>,
|
|
278
|
-
TFormOnSubmitAsync extends undefined | FormAsyncValidateOrFn<TParentData>,
|
|
279
|
-
TFormOnDynamic extends undefined | FormValidateOrFn<TParentData>,
|
|
280
|
-
TFormOnDynamicAsync extends undefined | FormAsyncValidateOrFn<TParentData>,
|
|
281
|
-
TFormOnServer extends undefined | FormAsyncValidateOrFn<TParentData>,
|
|
282
|
-
TSubmitMeta,
|
|
283
|
-
>(
|
|
284
|
-
opts?: () => FormOptions<
|
|
285
|
-
TParentData,
|
|
286
|
-
TFormOnMount,
|
|
287
|
-
TFormOnChange,
|
|
288
|
-
TFormOnChangeAsync,
|
|
289
|
-
TFormOnBlur,
|
|
290
|
-
TFormOnBlurAsync,
|
|
291
|
-
TFormOnSubmit,
|
|
292
|
-
TFormOnSubmitAsync,
|
|
293
|
-
TFormOnDynamic,
|
|
294
|
-
TFormOnDynamicAsync,
|
|
295
|
-
TFormOnServer,
|
|
296
|
-
TSubmitMeta
|
|
297
|
-
>,
|
|
298
|
-
) {
|
|
299
|
-
const options = opts?.()
|
|
300
|
-
const api = new FormApi<
|
|
301
|
-
TParentData,
|
|
302
|
-
TFormOnMount,
|
|
303
|
-
TFormOnChange,
|
|
304
|
-
TFormOnChangeAsync,
|
|
305
|
-
TFormOnBlur,
|
|
306
|
-
TFormOnBlurAsync,
|
|
307
|
-
TFormOnSubmit,
|
|
308
|
-
TFormOnSubmitAsync,
|
|
309
|
-
TFormOnDynamic,
|
|
310
|
-
TFormOnDynamicAsync,
|
|
311
|
-
TFormOnServer,
|
|
312
|
-
TSubmitMeta
|
|
313
|
-
>(options)
|
|
314
|
-
const extendedApi: typeof api &
|
|
315
|
-
SvelteFormApi<
|
|
316
|
-
TParentData,
|
|
317
|
-
TFormOnMount,
|
|
318
|
-
TFormOnChange,
|
|
319
|
-
TFormOnChangeAsync,
|
|
320
|
-
TFormOnBlur,
|
|
321
|
-
TFormOnBlurAsync,
|
|
322
|
-
TFormOnSubmit,
|
|
323
|
-
TFormOnSubmitAsync,
|
|
324
|
-
TFormOnDynamic,
|
|
325
|
-
TFormOnDynamicAsync,
|
|
326
|
-
TFormOnServer,
|
|
327
|
-
TSubmitMeta
|
|
328
|
-
> = api as never
|
|
329
|
-
|
|
330
|
-
// @ts-expect-error constructor definition exists only on a type level
|
|
331
|
-
extendedApi.Field = (internal, props) =>
|
|
332
|
-
Field(internal, { ...props, form: api as never } as never)
|
|
333
|
-
// @ts-expect-error constructor definition exists only on a type level
|
|
334
|
-
extendedApi.FormGroup = (internal, props) =>
|
|
335
|
-
FormGroup(internal, { ...props, form: api as never } as never)
|
|
336
|
-
extendedApi.useSelector = (selector) => useSelector(api.store, selector)
|
|
337
|
-
/** @deprecated Use `form.useSelector` instead. */
|
|
338
|
-
extendedApi.useStore = extendedApi.useSelector
|
|
339
|
-
// @ts-expect-error constructor definition exists only on a type level
|
|
340
|
-
extendedApi.Subscribe = (internal, props) =>
|
|
341
|
-
Subscribe(internal, { ...props, store: api.store })
|
|
342
|
-
|
|
343
|
-
onMount(api.mount)
|
|
344
|
-
|
|
345
|
-
// formApi.update should not have any side effects. Think of it like a `useRef`
|
|
346
|
-
// that we need to keep updated every render with the most up-to-date information.
|
|
347
|
-
$effect.pre(() => api.update(opts?.()))
|
|
348
|
-
|
|
349
|
-
return extendedApi
|
|
350
|
-
}
|
|
@@ -1,321 +0,0 @@
|
|
|
1
|
-
import { getContext } from 'svelte'
|
|
2
|
-
import { createForm } from './createForm.svelte'
|
|
3
|
-
import AppFormSvelte from './AppForm.svelte'
|
|
4
|
-
import AppFieldSvelte from './AppField.svelte'
|
|
5
|
-
import { fieldContextKey, formContextKey } from './context-keys.js'
|
|
6
|
-
import type {
|
|
7
|
-
AnyFieldApi,
|
|
8
|
-
AnyFormApi,
|
|
9
|
-
FieldApi,
|
|
10
|
-
FormAsyncValidateOrFn,
|
|
11
|
-
FormOptions,
|
|
12
|
-
FormValidateOrFn,
|
|
13
|
-
} from '@tanstack/form-core'
|
|
14
|
-
import type { FieldComponent } from './types.js'
|
|
15
|
-
import type { SvelteFormExtendedApi } from './createForm.svelte'
|
|
16
|
-
import type { Component, Snippet } from 'svelte'
|
|
17
|
-
|
|
18
|
-
/**
|
|
19
|
-
* TypeScript inferencing is weird.
|
|
20
|
-
*
|
|
21
|
-
* If you have:
|
|
22
|
-
*
|
|
23
|
-
* @example
|
|
24
|
-
*
|
|
25
|
-
* interface Args<T> {
|
|
26
|
-
* arg?: T
|
|
27
|
-
* }
|
|
28
|
-
*
|
|
29
|
-
* function test<T>(arg?: Partial<Args<T>>): T {
|
|
30
|
-
* return 0 as any;
|
|
31
|
-
* }
|
|
32
|
-
*
|
|
33
|
-
* const a = test({});
|
|
34
|
-
*
|
|
35
|
-
* Then `T` will default to `unknown`.
|
|
36
|
-
*
|
|
37
|
-
* However, if we change `test` to be:
|
|
38
|
-
*
|
|
39
|
-
* @example
|
|
40
|
-
*
|
|
41
|
-
* function test<T extends undefined>(arg?: Partial<Args<T>>): T;
|
|
42
|
-
*
|
|
43
|
-
* Then `T` becomes `undefined`.
|
|
44
|
-
*
|
|
45
|
-
* Here, we are checking if the passed type `T` extends `DefaultT` and **only**
|
|
46
|
-
* `DefaultT`, as if that's the case we assume that inferencing has not occured.
|
|
47
|
-
*/
|
|
48
|
-
type UnwrapOrAny<T> = [unknown] extends [T] ? any : T
|
|
49
|
-
type UnwrapDefaultOrAny<DefaultT, T> = [DefaultT] extends [T]
|
|
50
|
-
? [T] extends [DefaultT]
|
|
51
|
-
? any
|
|
52
|
-
: T
|
|
53
|
-
: T
|
|
54
|
-
|
|
55
|
-
export function createFormCreatorContexts() {
|
|
56
|
-
function useFieldContext<TData>() {
|
|
57
|
-
const field = getContext(fieldContextKey) as AnyFieldApi
|
|
58
|
-
|
|
59
|
-
// eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
|
|
60
|
-
if (!field) {
|
|
61
|
-
throw new Error(
|
|
62
|
-
'`fieldContext` only works when within a `fieldComponent` passed to `createFormCreator`',
|
|
63
|
-
)
|
|
64
|
-
}
|
|
65
|
-
|
|
66
|
-
return field as FieldApi<
|
|
67
|
-
any,
|
|
68
|
-
string,
|
|
69
|
-
TData,
|
|
70
|
-
any,
|
|
71
|
-
any,
|
|
72
|
-
any,
|
|
73
|
-
any,
|
|
74
|
-
any,
|
|
75
|
-
any,
|
|
76
|
-
any,
|
|
77
|
-
any,
|
|
78
|
-
any,
|
|
79
|
-
any,
|
|
80
|
-
any,
|
|
81
|
-
any,
|
|
82
|
-
any,
|
|
83
|
-
any,
|
|
84
|
-
any,
|
|
85
|
-
any,
|
|
86
|
-
any,
|
|
87
|
-
any,
|
|
88
|
-
any,
|
|
89
|
-
any
|
|
90
|
-
>
|
|
91
|
-
}
|
|
92
|
-
|
|
93
|
-
function useFormContext() {
|
|
94
|
-
const form = getContext(formContextKey) as AnyFormApi
|
|
95
|
-
|
|
96
|
-
// eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
|
|
97
|
-
if (!form) {
|
|
98
|
-
throw new Error(
|
|
99
|
-
'`formContext` only works when within a `formComponent` passed to `createFormCreator`',
|
|
100
|
-
)
|
|
101
|
-
}
|
|
102
|
-
|
|
103
|
-
return form as SvelteFormExtendedApi<
|
|
104
|
-
// If you need access to the form data, you need to use `withForm` instead
|
|
105
|
-
Record<string, never>,
|
|
106
|
-
any,
|
|
107
|
-
any,
|
|
108
|
-
any,
|
|
109
|
-
any,
|
|
110
|
-
any,
|
|
111
|
-
any,
|
|
112
|
-
any,
|
|
113
|
-
any,
|
|
114
|
-
any,
|
|
115
|
-
any,
|
|
116
|
-
any
|
|
117
|
-
>
|
|
118
|
-
}
|
|
119
|
-
|
|
120
|
-
return { useFieldContext, useFormContext }
|
|
121
|
-
}
|
|
122
|
-
|
|
123
|
-
interface CreateFormRuneProps<
|
|
124
|
-
TFieldComponents extends Record<string, Component<any, any>>,
|
|
125
|
-
TFormComponents extends Record<string, Component<any, any>>,
|
|
126
|
-
> {
|
|
127
|
-
fieldComponents: TFieldComponents
|
|
128
|
-
formComponents: TFormComponents
|
|
129
|
-
}
|
|
130
|
-
|
|
131
|
-
/**
|
|
132
|
-
* @private
|
|
133
|
-
*/
|
|
134
|
-
type AppFieldExtendedSvelteFormApi<
|
|
135
|
-
TFormData,
|
|
136
|
-
TOnMount extends undefined | FormValidateOrFn<TFormData>,
|
|
137
|
-
TOnChange extends undefined | FormValidateOrFn<TFormData>,
|
|
138
|
-
TOnChangeAsync extends undefined | FormAsyncValidateOrFn<TFormData>,
|
|
139
|
-
TOnBlur extends undefined | FormValidateOrFn<TFormData>,
|
|
140
|
-
TOnBlurAsync extends undefined | FormAsyncValidateOrFn<TFormData>,
|
|
141
|
-
TOnSubmit extends undefined | FormValidateOrFn<TFormData>,
|
|
142
|
-
TOnSubmitAsync extends undefined | FormAsyncValidateOrFn<TFormData>,
|
|
143
|
-
TOnDynamic extends undefined | FormValidateOrFn<TFormData>,
|
|
144
|
-
TOnDynamicAsync extends undefined | FormAsyncValidateOrFn<TFormData>,
|
|
145
|
-
TOnServer extends undefined | FormAsyncValidateOrFn<TFormData>,
|
|
146
|
-
TSubmitMeta,
|
|
147
|
-
TFieldComponents extends Record<string, Component<any, any>>,
|
|
148
|
-
TFormComponents extends Record<string, Component<any, any>>,
|
|
149
|
-
> = SvelteFormExtendedApi<
|
|
150
|
-
TFormData,
|
|
151
|
-
TOnMount,
|
|
152
|
-
TOnChange,
|
|
153
|
-
TOnChangeAsync,
|
|
154
|
-
TOnBlur,
|
|
155
|
-
TOnBlurAsync,
|
|
156
|
-
TOnSubmit,
|
|
157
|
-
TOnSubmitAsync,
|
|
158
|
-
TOnDynamic,
|
|
159
|
-
TOnDynamicAsync,
|
|
160
|
-
TOnServer,
|
|
161
|
-
TSubmitMeta
|
|
162
|
-
> &
|
|
163
|
-
NoInfer<TFormComponents> & {
|
|
164
|
-
AppField: FieldComponent<
|
|
165
|
-
TFormData,
|
|
166
|
-
TOnMount,
|
|
167
|
-
TOnChange,
|
|
168
|
-
TOnChangeAsync,
|
|
169
|
-
TOnBlur,
|
|
170
|
-
TOnBlurAsync,
|
|
171
|
-
TOnSubmit,
|
|
172
|
-
TOnSubmitAsync,
|
|
173
|
-
TOnDynamic,
|
|
174
|
-
TOnDynamicAsync,
|
|
175
|
-
TOnServer,
|
|
176
|
-
TSubmitMeta,
|
|
177
|
-
NoInfer<TFieldComponents>
|
|
178
|
-
>
|
|
179
|
-
AppForm: Component<{ children: Snippet }>
|
|
180
|
-
}
|
|
181
|
-
|
|
182
|
-
export function createFormCreator<
|
|
183
|
-
const TComponents extends Record<string, Component<any, any>>,
|
|
184
|
-
const TFormComponents extends Record<string, Component<any, any>>,
|
|
185
|
-
>({
|
|
186
|
-
fieldComponents,
|
|
187
|
-
formComponents,
|
|
188
|
-
}: CreateFormRuneProps<TComponents, TFormComponents>) {
|
|
189
|
-
function createAppForm<
|
|
190
|
-
TFormData,
|
|
191
|
-
TOnMount extends undefined | FormValidateOrFn<TFormData>,
|
|
192
|
-
TOnChange extends undefined | FormValidateOrFn<TFormData>,
|
|
193
|
-
TOnChangeAsync extends undefined | FormAsyncValidateOrFn<TFormData>,
|
|
194
|
-
TOnBlur extends undefined | FormValidateOrFn<TFormData>,
|
|
195
|
-
TOnBlurAsync extends undefined | FormAsyncValidateOrFn<TFormData>,
|
|
196
|
-
TOnSubmit extends undefined | FormValidateOrFn<TFormData>,
|
|
197
|
-
TOnSubmitAsync extends undefined | FormAsyncValidateOrFn<TFormData>,
|
|
198
|
-
TOnDynamic extends undefined | FormValidateOrFn<TFormData>,
|
|
199
|
-
TOnDynamicAsync extends undefined | FormAsyncValidateOrFn<TFormData>,
|
|
200
|
-
TOnServer extends undefined | FormAsyncValidateOrFn<TFormData>,
|
|
201
|
-
TSubmitMeta,
|
|
202
|
-
>(
|
|
203
|
-
props: () => FormOptions<
|
|
204
|
-
TFormData,
|
|
205
|
-
TOnMount,
|
|
206
|
-
TOnChange,
|
|
207
|
-
TOnChangeAsync,
|
|
208
|
-
TOnBlur,
|
|
209
|
-
TOnBlurAsync,
|
|
210
|
-
TOnSubmit,
|
|
211
|
-
TOnSubmitAsync,
|
|
212
|
-
TOnDynamic,
|
|
213
|
-
TOnDynamicAsync,
|
|
214
|
-
TOnServer,
|
|
215
|
-
TSubmitMeta
|
|
216
|
-
>,
|
|
217
|
-
): AppFieldExtendedSvelteFormApi<
|
|
218
|
-
TFormData,
|
|
219
|
-
TOnMount,
|
|
220
|
-
TOnChange,
|
|
221
|
-
TOnChangeAsync,
|
|
222
|
-
TOnBlur,
|
|
223
|
-
TOnBlurAsync,
|
|
224
|
-
TOnSubmit,
|
|
225
|
-
TOnSubmitAsync,
|
|
226
|
-
TOnDynamic,
|
|
227
|
-
TOnDynamicAsync,
|
|
228
|
-
TOnServer,
|
|
229
|
-
TSubmitMeta,
|
|
230
|
-
TComponents,
|
|
231
|
-
TFormComponents
|
|
232
|
-
> {
|
|
233
|
-
const form = createForm(props)
|
|
234
|
-
|
|
235
|
-
const AppForm = ((internal, props) => {
|
|
236
|
-
return AppFormSvelte(internal, { ...props, form })
|
|
237
|
-
}) as Component<{ children: Snippet }>
|
|
238
|
-
|
|
239
|
-
const AppField = ((internal, { children, ...fieldProps }) =>
|
|
240
|
-
AppFieldSvelte(internal, {
|
|
241
|
-
fieldProps,
|
|
242
|
-
form,
|
|
243
|
-
fieldComponents,
|
|
244
|
-
children,
|
|
245
|
-
} as never)) as FieldComponent<
|
|
246
|
-
TFormData,
|
|
247
|
-
TOnMount,
|
|
248
|
-
TOnChange,
|
|
249
|
-
TOnChangeAsync,
|
|
250
|
-
TOnBlur,
|
|
251
|
-
TOnBlurAsync,
|
|
252
|
-
TOnSubmit,
|
|
253
|
-
TOnSubmitAsync,
|
|
254
|
-
TOnDynamic,
|
|
255
|
-
TOnDynamicAsync,
|
|
256
|
-
TOnServer,
|
|
257
|
-
TSubmitMeta,
|
|
258
|
-
TComponents
|
|
259
|
-
>
|
|
260
|
-
|
|
261
|
-
const extendedForm = Object.assign(form, {
|
|
262
|
-
AppField,
|
|
263
|
-
AppForm,
|
|
264
|
-
...formComponents,
|
|
265
|
-
})
|
|
266
|
-
|
|
267
|
-
return extendedForm
|
|
268
|
-
}
|
|
269
|
-
|
|
270
|
-
function getFormType<
|
|
271
|
-
TFormData,
|
|
272
|
-
TOnMount extends undefined | FormValidateOrFn<TFormData>,
|
|
273
|
-
TOnChange extends undefined | FormValidateOrFn<TFormData>,
|
|
274
|
-
TOnChangeAsync extends undefined | FormAsyncValidateOrFn<TFormData>,
|
|
275
|
-
TOnBlur extends undefined | FormValidateOrFn<TFormData>,
|
|
276
|
-
TOnBlurAsync extends undefined | FormAsyncValidateOrFn<TFormData>,
|
|
277
|
-
TOnSubmit extends undefined | FormValidateOrFn<TFormData>,
|
|
278
|
-
TOnSubmitAsync extends undefined | FormAsyncValidateOrFn<TFormData>,
|
|
279
|
-
TOnDynamic extends undefined | FormValidateOrFn<TFormData>,
|
|
280
|
-
TOnDynamicAsync extends undefined | FormAsyncValidateOrFn<TFormData>,
|
|
281
|
-
TOnServer extends undefined | FormAsyncValidateOrFn<TFormData>,
|
|
282
|
-
TSubmitMeta,
|
|
283
|
-
>(
|
|
284
|
-
_formProps: FormOptions<
|
|
285
|
-
TFormData,
|
|
286
|
-
TOnMount,
|
|
287
|
-
TOnChange,
|
|
288
|
-
TOnChangeAsync,
|
|
289
|
-
TOnBlur,
|
|
290
|
-
TOnBlurAsync,
|
|
291
|
-
TOnSubmit,
|
|
292
|
-
TOnSubmitAsync,
|
|
293
|
-
TOnDynamic,
|
|
294
|
-
TOnDynamicAsync,
|
|
295
|
-
TOnServer,
|
|
296
|
-
TSubmitMeta
|
|
297
|
-
>,
|
|
298
|
-
): AppFieldExtendedSvelteFormApi<
|
|
299
|
-
TFormData,
|
|
300
|
-
TOnMount,
|
|
301
|
-
TOnChange,
|
|
302
|
-
TOnChangeAsync,
|
|
303
|
-
TOnBlur,
|
|
304
|
-
TOnBlurAsync,
|
|
305
|
-
TOnSubmit,
|
|
306
|
-
TOnSubmitAsync,
|
|
307
|
-
TOnDynamic,
|
|
308
|
-
TOnDynamicAsync,
|
|
309
|
-
TOnServer,
|
|
310
|
-
TSubmitMeta,
|
|
311
|
-
TComponents,
|
|
312
|
-
TFormComponents
|
|
313
|
-
> {
|
|
314
|
-
return undefined as never
|
|
315
|
-
}
|
|
316
|
-
|
|
317
|
-
return {
|
|
318
|
-
createAppForm,
|
|
319
|
-
getFormType,
|
|
320
|
-
}
|
|
321
|
-
}
|
package/src/index.ts
DELETED
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
export * from '@tanstack/form-core'
|
|
2
|
-
|
|
3
|
-
export { useSelector, useStore } from '@tanstack/svelte-store'
|
|
4
|
-
|
|
5
|
-
export { createForm, type SvelteFormApi } from './createForm.svelte.js'
|
|
6
|
-
|
|
7
|
-
export { default as Field, createField } from './Field.svelte'
|
|
8
|
-
|
|
9
|
-
export { default as FormGroup, createFormGroup } from './FormGroup.svelte'
|
|
10
|
-
|
|
11
|
-
export type { FieldComponent, FormGroupComponent } from './types.js'
|
|
12
|
-
|
|
13
|
-
export {
|
|
14
|
-
createFormCreator,
|
|
15
|
-
createFormCreatorContexts,
|
|
16
|
-
} from './createFormCreator.svelte.js'
|