@tanstack/svelte-form 1.33.3 → 2.0.0-alpha.0
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 +13 -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 +13 -4
- package/dist/index.js +13 -3
- package/dist/utils.lib.d.ts +1 -0
- package/dist/utils.lib.js +28 -0
- package/package.json +5 -5
- package/src/AppForm/AppForm.svelte +14 -0
- package/src/AppForm/Components.lib.ts +28 -0
- package/src/AppForm/SvelteAppFormApi.public.ts +14 -0
- package/src/AppForm/appFormOptions.public.ts +57 -0
- package/src/AppForm/componentMap.public.ts +19 -0
- package/src/AppForm/contexts.lib.ts +24 -0
- package/src/AppForm/createFormHook.public.ts +33 -0
- package/src/AppForm/createFormHookTypes.public.ts +30 -0
- package/src/AppForm/fieldComponentHelpers.lib.ts +24 -0
- package/src/AppForm/getFormHookHelpers.public.ts +82 -0
- package/src/AppForm/initializeAppForm.lib.ts +18 -0
- package/src/Components.public.ts +371 -0
- package/src/Field.svelte +125 -314
- package/src/FieldGroup/FieldGroupApi.public.ts +100 -0
- package/src/FieldGroup/withFields.lib.ts +82 -0
- package/src/FieldGroup/withFields.public.ts +179 -0
- package/src/FormGroup.svelte +81 -302
- package/src/Subscribe.svelte +18 -8
- package/src/createForm.public.ts +26 -0
- package/src/createForm.svelte.ts +62 -336
- package/src/formApiTypes.public.ts +48 -0
- package/src/formType.public.ts +46 -0
- package/src/index.ts +13 -12
- package/src/utils.lib.ts +30 -0
- 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/InnerAppField.svelte +0 -17
- package/src/createFormCreator.svelte.ts +0 -321
- 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
|
@@ -0,0 +1,179 @@
|
|
|
1
|
+
import { defineFieldGroupRuntime } from './withFields.lib'
|
|
2
|
+
import type {
|
|
3
|
+
DeepKeys,
|
|
4
|
+
DeepKeysWhereValueIncludes,
|
|
5
|
+
DeepValue,
|
|
6
|
+
FormApi,
|
|
7
|
+
} from '@tanstack/form-core'
|
|
8
|
+
import type {
|
|
9
|
+
Component,
|
|
10
|
+
ComponentConstructorOptions,
|
|
11
|
+
SvelteComponent,
|
|
12
|
+
} from 'svelte'
|
|
13
|
+
import type {
|
|
14
|
+
SvelteTanStackFormComponents,
|
|
15
|
+
WithoutFunction,
|
|
16
|
+
} from '../Components.public'
|
|
17
|
+
import type { FieldGroupApi } from './FieldGroupApi.public'
|
|
18
|
+
|
|
19
|
+
declare const fieldGroupFieldSlotValueSymbol: unique symbol
|
|
20
|
+
declare const fieldGroupFieldsSymbol: unique symbol
|
|
21
|
+
declare const fieldGroupFieldComponentsSymbol: unique symbol
|
|
22
|
+
export type FieldGroupFieldSlotMode = 'strict' | 'loose'
|
|
23
|
+
export interface FieldGroupFieldSlot<
|
|
24
|
+
out TValue,
|
|
25
|
+
out TMode extends FieldGroupFieldSlotMode = FieldGroupFieldSlotMode,
|
|
26
|
+
> {
|
|
27
|
+
readonly mode: TMode
|
|
28
|
+
readonly [fieldGroupFieldSlotValueSymbol]: TValue
|
|
29
|
+
}
|
|
30
|
+
export type AnyFieldGroupFieldSlot = FieldGroupFieldSlot<any>
|
|
31
|
+
export type StrictFieldGroupFieldSlot<TValue> = FieldGroupFieldSlot<
|
|
32
|
+
TValue,
|
|
33
|
+
'strict'
|
|
34
|
+
>
|
|
35
|
+
export type LooseFieldGroupFieldSlot<TValue> = FieldGroupFieldSlot<
|
|
36
|
+
TValue,
|
|
37
|
+
'loose'
|
|
38
|
+
>
|
|
39
|
+
export type FieldGroupFieldSlotValue<TSlot> =
|
|
40
|
+
TSlot extends FieldGroupFieldSlot<infer TValue> ? TValue : never
|
|
41
|
+
export type FieldGroupFieldSlotModeOf<TSlot> =
|
|
42
|
+
TSlot extends FieldGroupFieldSlot<any, infer TMode> ? TMode : never
|
|
43
|
+
type IsSame<TA, TB> = [TA] extends [TB]
|
|
44
|
+
? [TB] extends [TA]
|
|
45
|
+
? true
|
|
46
|
+
: false
|
|
47
|
+
: false
|
|
48
|
+
export type FieldGroupFieldSlotAllows<TSlot, TValue> =
|
|
49
|
+
TSlot extends FieldGroupFieldSlot<infer TAccepted, infer TMode>
|
|
50
|
+
? TMode extends 'strict'
|
|
51
|
+
? IsSame<TValue, TAccepted>
|
|
52
|
+
: [TValue] extends [TAccepted]
|
|
53
|
+
? true
|
|
54
|
+
: false
|
|
55
|
+
: false
|
|
56
|
+
export type FieldGroupFieldNameForSlot<
|
|
57
|
+
TData,
|
|
58
|
+
TSlot extends AnyFieldGroupFieldSlot,
|
|
59
|
+
> = {
|
|
60
|
+
[TName in DeepKeys<TData>]: FieldGroupFieldSlotAllows<
|
|
61
|
+
TSlot,
|
|
62
|
+
DeepValue<TData, TName>
|
|
63
|
+
> extends true
|
|
64
|
+
? TName
|
|
65
|
+
: never
|
|
66
|
+
}[DeepKeys<TData>]
|
|
67
|
+
export type FieldGroupFields = Record<string, AnyFieldGroupFieldSlot>
|
|
68
|
+
export type FieldGroupFieldNames<TData, TFields extends FieldGroupFields> = {
|
|
69
|
+
[TName in keyof TFields]: FieldGroupFieldNameForSlot<TData, TFields[TName]>
|
|
70
|
+
}
|
|
71
|
+
export type FieldGroupFieldData<TFields extends FieldGroupFields> = {
|
|
72
|
+
[TName in keyof TFields]: TFields[TName] extends FieldGroupFieldSlot<
|
|
73
|
+
infer TValue,
|
|
74
|
+
any
|
|
75
|
+
>
|
|
76
|
+
? TValue
|
|
77
|
+
: never
|
|
78
|
+
}
|
|
79
|
+
export type FieldGroupFieldsOf<TGroup> = TGroup extends {
|
|
80
|
+
readonly [fieldGroupFieldsSymbol]: infer TFields
|
|
81
|
+
}
|
|
82
|
+
? TFields
|
|
83
|
+
: never
|
|
84
|
+
export type SvelteFieldGroup<
|
|
85
|
+
TFields extends FieldGroupFields,
|
|
86
|
+
TFieldComponents extends Record<string, Component<any>> = Record<
|
|
87
|
+
never,
|
|
88
|
+
never
|
|
89
|
+
>,
|
|
90
|
+
> = FieldGroupApi<FieldGroupFieldData<TFields>, TFieldComponents> & {
|
|
91
|
+
readonly [fieldGroupFieldsSymbol]: TFields
|
|
92
|
+
readonly [fieldGroupFieldComponentsSymbol]: TFieldComponents
|
|
93
|
+
}
|
|
94
|
+
export type FieldGroupFieldComponentsOf<TGroup> = TGroup extends {
|
|
95
|
+
readonly [fieldGroupFieldComponentsSymbol]: infer TComponents extends Record<
|
|
96
|
+
string,
|
|
97
|
+
Component<any>
|
|
98
|
+
>
|
|
99
|
+
}
|
|
100
|
+
? TComponents
|
|
101
|
+
: never
|
|
102
|
+
export type FieldGroupForm<
|
|
103
|
+
TFieldComponents extends Record<string, Component<any>> = Record<
|
|
104
|
+
never,
|
|
105
|
+
never
|
|
106
|
+
>,
|
|
107
|
+
TFormData = any,
|
|
108
|
+
> = FormApi<TFormData, any> &
|
|
109
|
+
SvelteTanStackFormComponents<TFormData, any, TFieldComponents>
|
|
110
|
+
export type FieldGroupFieldBindingForSlot<
|
|
111
|
+
TData,
|
|
112
|
+
TSlot extends AnyFieldGroupFieldSlot,
|
|
113
|
+
> =
|
|
114
|
+
TSlot extends FieldGroupFieldSlot<infer TValue, infer TMode>
|
|
115
|
+
? TMode extends 'strict'
|
|
116
|
+
? FieldGroupFieldNameForSlot<TData, TSlot>
|
|
117
|
+
: DeepKeysWhereValueIncludes<TData, TValue>
|
|
118
|
+
: never
|
|
119
|
+
export type FieldGroupFieldBindings<
|
|
120
|
+
TFields extends FieldGroupFields,
|
|
121
|
+
TData = any,
|
|
122
|
+
> = {
|
|
123
|
+
[TName in keyof TFields]: FieldGroupFieldBindingForSlot<TData, TFields[TName]>
|
|
124
|
+
}
|
|
125
|
+
export type FieldGroupFieldBindingsOf<TGroup, TData> =
|
|
126
|
+
FieldGroupFieldsOf<TGroup> extends FieldGroupFields
|
|
127
|
+
? FieldGroupFieldBindings<FieldGroupFieldsOf<TGroup>, TData>
|
|
128
|
+
: never
|
|
129
|
+
export type FieldGroupFieldsPropName<TProps, TGroup> = {
|
|
130
|
+
[TName in keyof TProps]-?: IsSame<TProps[TName], TGroup> extends true
|
|
131
|
+
? TName
|
|
132
|
+
: never
|
|
133
|
+
}[keyof TProps]
|
|
134
|
+
|
|
135
|
+
export type FieldGroupWithFieldsFn<
|
|
136
|
+
TGroup extends { readonly [fieldGroupFieldsSymbol]: FieldGroupFields },
|
|
137
|
+
> = <
|
|
138
|
+
TProps extends object,
|
|
139
|
+
TPropName extends FieldGroupFieldsPropName<TProps, TGroup>,
|
|
140
|
+
>(
|
|
141
|
+
Component: Component<TProps>,
|
|
142
|
+
fieldsPropName: TPropName,
|
|
143
|
+
) => (new <TFormData>(
|
|
144
|
+
options: ComponentConstructorOptions<
|
|
145
|
+
Omit<TProps, TPropName | 'form'> & {
|
|
146
|
+
form: FieldGroupForm<FieldGroupFieldComponentsOf<TGroup>, TFormData>
|
|
147
|
+
} & {
|
|
148
|
+
[K in TPropName]: FieldGroupFieldBindingsOf<TGroup, TFormData>
|
|
149
|
+
}
|
|
150
|
+
>,
|
|
151
|
+
) => SvelteComponent) &
|
|
152
|
+
Component<any> &
|
|
153
|
+
WithoutFunction<Component>
|
|
154
|
+
|
|
155
|
+
export interface FieldGroupHelper {
|
|
156
|
+
strict: <TValue>() => StrictFieldGroupFieldSlot<TValue>
|
|
157
|
+
loose: <TValue>() => LooseFieldGroupFieldSlot<TValue>
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
export interface FieldGroupDefinition<
|
|
161
|
+
TFields extends FieldGroupFields,
|
|
162
|
+
TComponents extends Record<string, Component<any>>,
|
|
163
|
+
> {
|
|
164
|
+
/** The virtual field-group API injected into the bound component. */
|
|
165
|
+
fields: SvelteFieldGroup<TFields, TComponents>
|
|
166
|
+
/** Binds a component's virtual field API to concrete paths in a form. */
|
|
167
|
+
bindComponent: FieldGroupWithFieldsFn<SvelteFieldGroup<TFields, TComponents>>
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
/** Signature shared by `defineFieldGroup` and app-form field-group definers. */
|
|
171
|
+
export type DefineFieldGroupFn<
|
|
172
|
+
TComponents extends Record<string, Component<any>>,
|
|
173
|
+
> = <const TFields extends FieldGroupFields>(
|
|
174
|
+
defineFn: (helper: FieldGroupHelper) => TFields,
|
|
175
|
+
) => FieldGroupDefinition<TFields, TComponents>
|
|
176
|
+
|
|
177
|
+
/** Defines a reusable group of virtual fields. */
|
|
178
|
+
export const defineFieldGroup: DefineFieldGroupFn<Record<never, never>> =
|
|
179
|
+
defineFieldGroupRuntime as never
|
package/src/FormGroup.svelte
CHANGED
|
@@ -1,322 +1,101 @@
|
|
|
1
1
|
<script module lang="ts">
|
|
2
|
-
import {
|
|
3
|
-
|
|
4
|
-
|
|
2
|
+
import { InternalFormGroupApi } from '@tanstack/form-core/internals'
|
|
3
|
+
import { useSelector } from '@tanstack/svelte-store'
|
|
4
|
+
import { withComponentProps } from './utils.lib.js'
|
|
5
|
+
import type {
|
|
6
|
+
FormErrorTypes,
|
|
5
7
|
FormGroupApi,
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
type FormAsyncValidateOrFn,
|
|
10
|
-
type FormValidateOrFn,
|
|
8
|
+
FormGroupOptions,
|
|
9
|
+
FormGroupValidators,
|
|
10
|
+
ToFormGroupErrorTypes,
|
|
11
11
|
} from '@tanstack/form-core'
|
|
12
|
-
import {
|
|
13
|
-
import { onMount, type Snippet } from 'svelte'
|
|
12
|
+
import type { AnyInternalFormApi } from '@tanstack/form-core/internals'
|
|
14
13
|
|
|
15
14
|
export function createFormGroup<
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
| FormGroupValidateOrFn<TParentData, TName, TData>,
|
|
22
|
-
TOnChange extends
|
|
23
|
-
| undefined
|
|
24
|
-
| FormGroupValidateOrFn<TParentData, TName, TData>,
|
|
25
|
-
TOnChangeAsync extends
|
|
26
|
-
| undefined
|
|
27
|
-
| FormGroupAsyncValidateOrFn<TParentData, TName, TData>,
|
|
28
|
-
TOnBlur extends
|
|
29
|
-
| undefined
|
|
30
|
-
| FormGroupValidateOrFn<TParentData, TName, TData>,
|
|
31
|
-
TOnBlurAsync extends
|
|
32
|
-
| undefined
|
|
33
|
-
| FormGroupAsyncValidateOrFn<TParentData, TName, TData>,
|
|
34
|
-
TOnSubmit extends
|
|
35
|
-
| undefined
|
|
36
|
-
| FormGroupValidateOrFn<TParentData, TName, TData>,
|
|
37
|
-
TOnSubmitAsync extends
|
|
38
|
-
| undefined
|
|
39
|
-
| FormGroupAsyncValidateOrFn<TParentData, TName, TData>,
|
|
40
|
-
TOnDynamic extends
|
|
41
|
-
| undefined
|
|
42
|
-
| FormGroupValidateOrFn<TParentData, TName, TData>,
|
|
43
|
-
TOnDynamicAsync extends
|
|
44
|
-
| undefined
|
|
45
|
-
| FormGroupAsyncValidateOrFn<TParentData, TName, TData>,
|
|
46
|
-
TSubmitMeta,
|
|
47
|
-
TFormOnMount extends undefined | FormValidateOrFn<TParentData>,
|
|
48
|
-
TFormOnChange extends undefined | FormValidateOrFn<TParentData>,
|
|
49
|
-
TFormOnChangeAsync extends undefined | FormAsyncValidateOrFn<TParentData>,
|
|
50
|
-
TFormOnBlur extends undefined | FormValidateOrFn<TParentData>,
|
|
51
|
-
TFormOnBlurAsync extends undefined | FormAsyncValidateOrFn<TParentData>,
|
|
52
|
-
TFormOnSubmit extends undefined | FormValidateOrFn<TParentData>,
|
|
53
|
-
TFormOnSubmitAsync extends undefined | FormAsyncValidateOrFn<TParentData>,
|
|
54
|
-
TFormOnDynamic extends undefined | FormValidateOrFn<TParentData>,
|
|
55
|
-
TFormOnDynamicAsync extends undefined | FormAsyncValidateOrFn<TParentData>,
|
|
56
|
-
TFormOnServer extends undefined | FormAsyncValidateOrFn<TParentData>,
|
|
57
|
-
TParentSubmitMeta,
|
|
15
|
+
TFormData,
|
|
16
|
+
TGroupName,
|
|
17
|
+
TGroupValue,
|
|
18
|
+
const TGroupValidators extends FormGroupValidators<TGroupValue>,
|
|
19
|
+
TFormErrorTypes extends FormErrorTypes,
|
|
58
20
|
>(
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
TOnChangeAsync,
|
|
66
|
-
TOnBlur,
|
|
67
|
-
TOnBlurAsync,
|
|
68
|
-
TOnSubmit,
|
|
69
|
-
TOnSubmitAsync,
|
|
70
|
-
TOnDynamic,
|
|
71
|
-
TOnDynamicAsync,
|
|
72
|
-
TSubmitMeta,
|
|
73
|
-
TFormOnMount,
|
|
74
|
-
TFormOnChange,
|
|
75
|
-
TFormOnChangeAsync,
|
|
76
|
-
TFormOnBlur,
|
|
77
|
-
TFormOnBlurAsync,
|
|
78
|
-
TFormOnSubmit,
|
|
79
|
-
TFormOnSubmitAsync,
|
|
80
|
-
TFormOnDynamic,
|
|
81
|
-
TFormOnDynamicAsync,
|
|
82
|
-
TFormOnServer,
|
|
83
|
-
TParentSubmitMeta
|
|
21
|
+
options: () => FormGroupOptions<
|
|
22
|
+
TFormData,
|
|
23
|
+
TGroupName,
|
|
24
|
+
TGroupValue,
|
|
25
|
+
TGroupValidators,
|
|
26
|
+
TFormErrorTypes
|
|
84
27
|
>,
|
|
85
|
-
)
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
// Instantiates form group meta and removes it when unrendered
|
|
94
|
-
onMount(() => {
|
|
95
|
-
const cleanupFn = api.mount()
|
|
96
|
-
mounted = true
|
|
97
|
-
return () => {
|
|
98
|
-
cleanupFn()
|
|
99
|
-
mounted = false
|
|
100
|
-
}
|
|
101
|
-
})
|
|
28
|
+
): FormGroupApi<
|
|
29
|
+
TFormData,
|
|
30
|
+
TGroupName,
|
|
31
|
+
TGroupValue,
|
|
32
|
+
ToFormGroupErrorTypes<TGroupValidators>,
|
|
33
|
+
TFormErrorTypes
|
|
34
|
+
> {
|
|
35
|
+
const group = new InternalFormGroupApi(options() as never)
|
|
102
36
|
|
|
103
37
|
$effect.pre(() => {
|
|
104
|
-
|
|
105
|
-
// Changes to options are seen by the effect because signals inside them are picked up.
|
|
106
|
-
const current = opts()
|
|
107
|
-
if (!mounted) return
|
|
108
|
-
api.update(current)
|
|
38
|
+
group.update(options() as never)
|
|
109
39
|
})
|
|
40
|
+
$effect(() => {
|
|
41
|
+
group.mount()
|
|
42
|
+
return () => group._cleanup()
|
|
43
|
+
})
|
|
44
|
+
|
|
45
|
+
const state = useSelector(group.atom)
|
|
110
46
|
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
return
|
|
47
|
+
return new Proxy({} as typeof group, {
|
|
48
|
+
get(target, property) {
|
|
49
|
+
if (Reflect.has(target, property)) return Reflect.get(target, property)
|
|
50
|
+
if (property === 'state') return state.current
|
|
51
|
+
if (property === 'value') return state.current.values
|
|
52
|
+
const value = Reflect.get(group, property, group)
|
|
53
|
+
return typeof value === 'function' ? value.bind(group) : value
|
|
115
54
|
},
|
|
116
|
-
})
|
|
55
|
+
}) as never
|
|
56
|
+
}
|
|
117
57
|
|
|
118
|
-
|
|
58
|
+
export function attachGroupComponents(
|
|
59
|
+
group: any,
|
|
60
|
+
form: AnyInternalFormApi & Record<string, any>,
|
|
61
|
+
) {
|
|
62
|
+
group.Field = (internals: any, props: any) =>
|
|
63
|
+
form.Field(
|
|
64
|
+
internals,
|
|
65
|
+
group._getFormFieldOptions(props, withComponentProps),
|
|
66
|
+
)
|
|
67
|
+
group.ArrayField = (internals: any, props: any) =>
|
|
68
|
+
form.ArrayField(
|
|
69
|
+
internals,
|
|
70
|
+
group._getFormFieldOptions(props, withComponentProps),
|
|
71
|
+
)
|
|
72
|
+
group.Subscribe = (internals: any, props: any) =>
|
|
73
|
+
form._Subscribe(
|
|
74
|
+
internals,
|
|
75
|
+
withComponentProps(props, { source: group.atom }),
|
|
76
|
+
)
|
|
77
|
+
return group
|
|
119
78
|
}
|
|
120
79
|
</script>
|
|
121
80
|
|
|
122
|
-
<script
|
|
123
|
-
|
|
124
|
-
generics="
|
|
125
|
-
TParentData,
|
|
126
|
-
TName extends DeepKeys<TParentData>,
|
|
127
|
-
TData extends DeepValue<TParentData, TName>,
|
|
128
|
-
TOnMount extends undefined | FormGroupValidateOrFn<TParentData, TName, TData>,
|
|
129
|
-
TOnChange extends undefined | FormGroupValidateOrFn<TParentData, TName, TData>,
|
|
130
|
-
TOnChangeAsync extends
|
|
131
|
-
| undefined
|
|
132
|
-
| FormGroupAsyncValidateOrFn<TParentData, TName, TData>,
|
|
133
|
-
TOnBlur extends undefined | FormGroupValidateOrFn<TParentData, TName, TData>,
|
|
134
|
-
TOnBlurAsync extends
|
|
135
|
-
| undefined
|
|
136
|
-
| FormGroupAsyncValidateOrFn<TParentData, TName, TData>,
|
|
137
|
-
TOnSubmit extends undefined | FormGroupValidateOrFn<TParentData, TName, TData>,
|
|
138
|
-
TOnSubmitAsync extends
|
|
139
|
-
| undefined
|
|
140
|
-
| FormGroupAsyncValidateOrFn<TParentData, TName, TData>,
|
|
141
|
-
TOnDynamic extends undefined | FormGroupValidateOrFn<TParentData, TName, TData>,
|
|
142
|
-
TOnDynamicAsync extends
|
|
143
|
-
| undefined
|
|
144
|
-
| FormGroupAsyncValidateOrFn<TParentData, TName, TData>,
|
|
145
|
-
TSubmitMeta,
|
|
146
|
-
TFormOnMount extends undefined | FormValidateOrFn<TParentData>,
|
|
147
|
-
TFormOnChange extends undefined | FormValidateOrFn<TParentData>,
|
|
148
|
-
TFormOnChangeAsync extends undefined | FormAsyncValidateOrFn<TParentData>,
|
|
149
|
-
TFormOnBlur extends undefined | FormValidateOrFn<TParentData>,
|
|
150
|
-
TFormOnBlurAsync extends undefined | FormAsyncValidateOrFn<TParentData>,
|
|
151
|
-
TFormOnSubmit extends undefined | FormValidateOrFn<TParentData>,
|
|
152
|
-
TFormOnSubmitAsync extends undefined | FormAsyncValidateOrFn<TParentData>,
|
|
153
|
-
TFormOnDynamic extends undefined | FormValidateOrFn<TParentData>,
|
|
154
|
-
TFormOnDynamicAsync extends undefined | FormAsyncValidateOrFn<TParentData>,
|
|
155
|
-
TFormOnServer extends undefined | FormAsyncValidateOrFn<TParentData>,
|
|
156
|
-
TParentSubmitMeta,
|
|
157
|
-
"
|
|
158
|
-
>
|
|
159
|
-
import type { FormGroupApi as FormGroupApiType } from '@tanstack/form-core'
|
|
160
|
-
|
|
161
|
-
type Props<
|
|
162
|
-
TParentData,
|
|
163
|
-
TName extends DeepKeys<TParentData>,
|
|
164
|
-
TData extends DeepValue<TParentData, TName>,
|
|
165
|
-
TOnMount extends
|
|
166
|
-
| undefined
|
|
167
|
-
| FormGroupValidateOrFn<TParentData, TName, TData>,
|
|
168
|
-
TOnChange extends
|
|
169
|
-
| undefined
|
|
170
|
-
| FormGroupValidateOrFn<TParentData, TName, TData>,
|
|
171
|
-
TOnChangeAsync extends
|
|
172
|
-
| undefined
|
|
173
|
-
| FormGroupAsyncValidateOrFn<TParentData, TName, TData>,
|
|
174
|
-
TOnBlur extends
|
|
175
|
-
| undefined
|
|
176
|
-
| FormGroupValidateOrFn<TParentData, TName, TData>,
|
|
177
|
-
TOnBlurAsync extends
|
|
178
|
-
| undefined
|
|
179
|
-
| FormGroupAsyncValidateOrFn<TParentData, TName, TData>,
|
|
180
|
-
TOnSubmit extends
|
|
181
|
-
| undefined
|
|
182
|
-
| FormGroupValidateOrFn<TParentData, TName, TData>,
|
|
183
|
-
TOnSubmitAsync extends
|
|
184
|
-
| undefined
|
|
185
|
-
| FormGroupAsyncValidateOrFn<TParentData, TName, TData>,
|
|
186
|
-
TOnDynamic extends
|
|
187
|
-
| undefined
|
|
188
|
-
| FormGroupValidateOrFn<TParentData, TName, TData>,
|
|
189
|
-
TOnDynamicAsync extends
|
|
190
|
-
| undefined
|
|
191
|
-
| FormGroupAsyncValidateOrFn<TParentData, TName, TData>,
|
|
192
|
-
TSubmitMeta,
|
|
193
|
-
TFormOnMount extends undefined | FormValidateOrFn<TParentData>,
|
|
194
|
-
TFormOnChange extends undefined | FormValidateOrFn<TParentData>,
|
|
195
|
-
TFormOnChangeAsync extends undefined | FormAsyncValidateOrFn<TParentData>,
|
|
196
|
-
TFormOnBlur extends undefined | FormValidateOrFn<TParentData>,
|
|
197
|
-
TFormOnBlurAsync extends undefined | FormAsyncValidateOrFn<TParentData>,
|
|
198
|
-
TFormOnSubmit extends undefined | FormValidateOrFn<TParentData>,
|
|
199
|
-
TFormOnSubmitAsync extends undefined | FormAsyncValidateOrFn<TParentData>,
|
|
200
|
-
TFormOnDynamic extends undefined | FormValidateOrFn<TParentData>,
|
|
201
|
-
TFormOnDynamicAsync extends undefined | FormAsyncValidateOrFn<TParentData>,
|
|
202
|
-
TFormOnServer extends undefined | FormAsyncValidateOrFn<TParentData>,
|
|
203
|
-
TParentSubmitMeta,
|
|
204
|
-
> = {
|
|
205
|
-
children: Snippet<
|
|
206
|
-
[
|
|
207
|
-
FormGroupApiType<
|
|
208
|
-
TParentData,
|
|
209
|
-
TName,
|
|
210
|
-
TData,
|
|
211
|
-
TOnMount,
|
|
212
|
-
TOnChange,
|
|
213
|
-
TOnChangeAsync,
|
|
214
|
-
TOnBlur,
|
|
215
|
-
TOnBlurAsync,
|
|
216
|
-
TOnSubmit,
|
|
217
|
-
TOnSubmitAsync,
|
|
218
|
-
TOnDynamic,
|
|
219
|
-
TOnDynamicAsync,
|
|
220
|
-
TSubmitMeta,
|
|
221
|
-
TFormOnMount,
|
|
222
|
-
TFormOnChange,
|
|
223
|
-
TFormOnChangeAsync,
|
|
224
|
-
TFormOnBlur,
|
|
225
|
-
TFormOnBlurAsync,
|
|
226
|
-
TFormOnSubmit,
|
|
227
|
-
TFormOnSubmitAsync,
|
|
228
|
-
TFormOnDynamic,
|
|
229
|
-
TFormOnDynamicAsync,
|
|
230
|
-
TFormOnServer,
|
|
231
|
-
TParentSubmitMeta
|
|
232
|
-
>,
|
|
233
|
-
]
|
|
234
|
-
>
|
|
235
|
-
} & FormGroupApiOptions<
|
|
236
|
-
TParentData,
|
|
237
|
-
TName,
|
|
238
|
-
TData,
|
|
239
|
-
TOnMount,
|
|
240
|
-
TOnChange,
|
|
241
|
-
TOnChangeAsync,
|
|
242
|
-
TOnBlur,
|
|
243
|
-
TOnBlurAsync,
|
|
244
|
-
TOnSubmit,
|
|
245
|
-
TOnSubmitAsync,
|
|
246
|
-
TOnDynamic,
|
|
247
|
-
TOnDynamicAsync,
|
|
248
|
-
TSubmitMeta,
|
|
249
|
-
TFormOnMount,
|
|
250
|
-
TFormOnChange,
|
|
251
|
-
TFormOnChangeAsync,
|
|
252
|
-
TFormOnBlur,
|
|
253
|
-
TFormOnBlurAsync,
|
|
254
|
-
TFormOnSubmit,
|
|
255
|
-
TFormOnSubmitAsync,
|
|
256
|
-
TFormOnDynamic,
|
|
257
|
-
TFormOnDynamicAsync,
|
|
258
|
-
TFormOnServer,
|
|
259
|
-
TParentSubmitMeta
|
|
260
|
-
>
|
|
81
|
+
<script lang="ts">
|
|
82
|
+
import { untrack, type Snippet } from 'svelte'
|
|
261
83
|
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
TOnChange,
|
|
271
|
-
TOnChangeAsync,
|
|
272
|
-
TOnBlur,
|
|
273
|
-
TOnBlurAsync,
|
|
274
|
-
TOnSubmit,
|
|
275
|
-
TOnSubmitAsync,
|
|
276
|
-
TOnDynamic,
|
|
277
|
-
TOnDynamicAsync,
|
|
278
|
-
TSubmitMeta,
|
|
279
|
-
TFormOnMount,
|
|
280
|
-
TFormOnChange,
|
|
281
|
-
TFormOnChangeAsync,
|
|
282
|
-
TFormOnBlur,
|
|
283
|
-
TFormOnBlurAsync,
|
|
284
|
-
TFormOnSubmit,
|
|
285
|
-
TFormOnSubmitAsync,
|
|
286
|
-
TFormOnDynamic,
|
|
287
|
-
TFormOnDynamicAsync,
|
|
288
|
-
TFormOnServer,
|
|
289
|
-
TParentSubmitMeta
|
|
290
|
-
> = $props()
|
|
84
|
+
interface Props {
|
|
85
|
+
form: AnyInternalFormApi & Record<string, any>
|
|
86
|
+
children: Snippet<[any]>
|
|
87
|
+
name: string
|
|
88
|
+
validators?: any
|
|
89
|
+
onSubmit?: any
|
|
90
|
+
onSubmitInvalid?: any
|
|
91
|
+
}
|
|
291
92
|
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
TOnChangeAsync,
|
|
299
|
-
TOnBlur,
|
|
300
|
-
TOnBlurAsync,
|
|
301
|
-
TOnSubmit,
|
|
302
|
-
TOnSubmitAsync,
|
|
303
|
-
TOnDynamic,
|
|
304
|
-
TOnDynamicAsync,
|
|
305
|
-
TSubmitMeta,
|
|
306
|
-
TFormOnMount,
|
|
307
|
-
TFormOnChange,
|
|
308
|
-
TFormOnChangeAsync,
|
|
309
|
-
TFormOnBlur,
|
|
310
|
-
TFormOnBlurAsync,
|
|
311
|
-
TFormOnSubmit,
|
|
312
|
-
TFormOnSubmitAsync,
|
|
313
|
-
TFormOnDynamic,
|
|
314
|
-
TFormOnDynamicAsync,
|
|
315
|
-
TFormOnServer,
|
|
316
|
-
TParentSubmitMeta
|
|
317
|
-
>(() => {
|
|
318
|
-
return formGroupOptions
|
|
319
|
-
})
|
|
93
|
+
let { children, form, ...groupOptions }: Props = $props()
|
|
94
|
+
const initialForm = untrack(() => form)
|
|
95
|
+
const groupApi = attachGroupComponents(
|
|
96
|
+
createFormGroup(() => ({ ...groupOptions, form: initialForm }) as never),
|
|
97
|
+
initialForm,
|
|
98
|
+
)
|
|
320
99
|
</script>
|
|
321
100
|
|
|
322
|
-
{@render children(
|
|
101
|
+
{@render children(groupApi)}
|
package/src/Subscribe.svelte
CHANGED
|
@@ -1,16 +1,26 @@
|
|
|
1
1
|
<script lang="ts">
|
|
2
2
|
import { useSelector } from '@tanstack/svelte-store'
|
|
3
|
+
import { untrack, type Snippet } from 'svelte'
|
|
3
4
|
|
|
4
|
-
// Don't bother typing this out, this component is only usable through a wrapper
|
|
5
5
|
interface Props {
|
|
6
|
-
children: any
|
|
7
|
-
|
|
8
|
-
selector
|
|
6
|
+
children: Snippet<[any]>
|
|
7
|
+
source: any
|
|
8
|
+
selector: (state: any) => any
|
|
9
|
+
when?: (selected: any) => boolean
|
|
9
10
|
}
|
|
10
11
|
|
|
11
|
-
let {
|
|
12
|
-
|
|
13
|
-
|
|
12
|
+
let {
|
|
13
|
+
children,
|
|
14
|
+
source,
|
|
15
|
+
selector,
|
|
16
|
+
when = () => true,
|
|
17
|
+
}: Props = $props()
|
|
18
|
+
const value = useSelector(
|
|
19
|
+
untrack(() => source),
|
|
20
|
+
untrack(() => selector),
|
|
21
|
+
)
|
|
14
22
|
</script>
|
|
15
23
|
|
|
16
|
-
{
|
|
24
|
+
{#if when(value.current)}
|
|
25
|
+
{@render children(value.current)}
|
|
26
|
+
{/if}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { createInternalForm, initializeForm } from './createForm.svelte'
|
|
2
|
+
import type {
|
|
3
|
+
FormOptions,
|
|
4
|
+
FormValidators,
|
|
5
|
+
ToFormErrorTypes,
|
|
6
|
+
} from '@tanstack/form-core'
|
|
7
|
+
import type { SvelteFormApi } from './formApiTypes.public'
|
|
8
|
+
import type { DefaultSvelteFormComponentMap } from './AppForm/componentMap.public'
|
|
9
|
+
|
|
10
|
+
export type CreateForm = <
|
|
11
|
+
TFormData,
|
|
12
|
+
const TFormValidators extends FormValidators<TFormData>,
|
|
13
|
+
TSubmitReturn,
|
|
14
|
+
>(
|
|
15
|
+
options: () => FormOptions<TFormData, TFormValidators, TSubmitReturn>,
|
|
16
|
+
) => SvelteFormApi<
|
|
17
|
+
TFormData,
|
|
18
|
+
ToFormErrorTypes<TFormValidators, TSubmitReturn>,
|
|
19
|
+
DefaultSvelteFormComponentMap
|
|
20
|
+
>
|
|
21
|
+
|
|
22
|
+
function createFormImpl(options: () => FormOptions<any, any, any>) {
|
|
23
|
+
return createInternalForm(options, initializeForm)
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
export const createForm = createFormImpl as never as CreateForm
|