@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,100 +0,0 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
DeepKeys,
|
|
3
|
-
DeepKeysWhereValueIncludes,
|
|
4
|
-
DeepValue,
|
|
5
|
-
FieldValidators,
|
|
6
|
-
FormApiArrayMethods,
|
|
7
|
-
FormApiFieldMethods,
|
|
8
|
-
FormErrorTypes,
|
|
9
|
-
FormState,
|
|
10
|
-
ValidationIssue,
|
|
11
|
-
} from '@tanstack/form-core'
|
|
12
|
-
import type {
|
|
13
|
-
Component,
|
|
14
|
-
ComponentConstructorOptions,
|
|
15
|
-
SvelteComponent,
|
|
16
|
-
} from 'svelte'
|
|
17
|
-
import type {
|
|
18
|
-
SvelteFormFieldProps,
|
|
19
|
-
SvelteFormSubscribeProps,
|
|
20
|
-
WithoutFunction,
|
|
21
|
-
} from '../Components.public'
|
|
22
|
-
import type { ReadonlyAtom } from '@tanstack/svelte-store'
|
|
23
|
-
|
|
24
|
-
export type FieldGroupFieldComponent<
|
|
25
|
-
TFieldData,
|
|
26
|
-
TFieldComponents extends Record<string, Component<any>>,
|
|
27
|
-
> = (new <const TFieldName extends DeepKeys<TFieldData>>(
|
|
28
|
-
options: ComponentConstructorOptions<
|
|
29
|
-
SvelteFormFieldProps<
|
|
30
|
-
TFieldData,
|
|
31
|
-
TFieldName,
|
|
32
|
-
DeepValue<TFieldData, TFieldName>,
|
|
33
|
-
FieldValidators<
|
|
34
|
-
TFieldData,
|
|
35
|
-
TFieldName,
|
|
36
|
-
DeepValue<TFieldData, TFieldName>
|
|
37
|
-
>,
|
|
38
|
-
ValidationIssue,
|
|
39
|
-
unknown,
|
|
40
|
-
FormErrorTypes,
|
|
41
|
-
TFieldComponents
|
|
42
|
-
>
|
|
43
|
-
>,
|
|
44
|
-
) => SvelteComponent) &
|
|
45
|
-
Component<any> &
|
|
46
|
-
WithoutFunction<Component>
|
|
47
|
-
|
|
48
|
-
export type FieldGroupArrayFieldComponent<
|
|
49
|
-
TFieldData,
|
|
50
|
-
TFieldComponents extends Record<string, Component<any>>,
|
|
51
|
-
> = (new <
|
|
52
|
-
const TFieldName extends DeepKeysWhereValueIncludes<TFieldData, Array<any>>,
|
|
53
|
-
>(
|
|
54
|
-
options: ComponentConstructorOptions<
|
|
55
|
-
SvelteFormFieldProps<
|
|
56
|
-
TFieldData,
|
|
57
|
-
TFieldName,
|
|
58
|
-
DeepValue<TFieldData, TFieldName>,
|
|
59
|
-
FieldValidators<
|
|
60
|
-
TFieldData,
|
|
61
|
-
TFieldName,
|
|
62
|
-
DeepValue<TFieldData, TFieldName>
|
|
63
|
-
>,
|
|
64
|
-
ValidationIssue,
|
|
65
|
-
unknown,
|
|
66
|
-
FormErrorTypes,
|
|
67
|
-
TFieldComponents
|
|
68
|
-
>
|
|
69
|
-
>,
|
|
70
|
-
) => SvelteComponent) &
|
|
71
|
-
Component<any> &
|
|
72
|
-
WithoutFunction<Component>
|
|
73
|
-
|
|
74
|
-
export type FieldGroupSubscribeComponent = (new <TSelected>(
|
|
75
|
-
options: ComponentConstructorOptions<
|
|
76
|
-
SvelteFormSubscribeProps<unknown, FormErrorTypes, TSelected>
|
|
77
|
-
>,
|
|
78
|
-
) => SvelteComponent) &
|
|
79
|
-
Component<any> &
|
|
80
|
-
WithoutFunction<Component>
|
|
81
|
-
|
|
82
|
-
export interface FieldGroupApi<
|
|
83
|
-
TFieldData,
|
|
84
|
-
TFieldComponents extends Record<string, Component<any>> = Record<
|
|
85
|
-
never,
|
|
86
|
-
never
|
|
87
|
-
>,
|
|
88
|
-
>
|
|
89
|
-
extends FormApiFieldMethods<TFieldData>, FormApiArrayMethods<TFieldData> {
|
|
90
|
-
atom: ReadonlyAtom<TFieldData>
|
|
91
|
-
Field: FieldGroupFieldComponent<TFieldData, TFieldComponents>
|
|
92
|
-
ArrayField: FieldGroupArrayFieldComponent<TFieldData, TFieldComponents>
|
|
93
|
-
Subscribe: FieldGroupSubscribeComponent
|
|
94
|
-
}
|
|
95
|
-
|
|
96
|
-
export type AnyFieldGroupApi = FieldGroupApi<
|
|
97
|
-
any,
|
|
98
|
-
Record<string, Component<any>>
|
|
99
|
-
>
|
|
100
|
-
export type FieldGroupFormState = FormState<unknown, FormErrorTypes>
|
|
@@ -1,82 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
InternalFieldGroupApi,
|
|
3
|
-
defineFieldGroupFieldsRuntime,
|
|
4
|
-
fieldGroupHelperRuntime,
|
|
5
|
-
} from '@tanstack/form-core/internals'
|
|
6
|
-
import { withComponentProps } from '../utils.lib.js'
|
|
7
|
-
import type { Component } from 'svelte'
|
|
8
|
-
import type { InternalFieldGroupBindings } from '@tanstack/form-core/internals'
|
|
9
|
-
import type { AnyFieldGroupApi } from './FieldGroupApi.public'
|
|
10
|
-
|
|
11
|
-
function attachSvelteFieldGroupComponents(
|
|
12
|
-
group: InternalFieldGroupApi,
|
|
13
|
-
form: any,
|
|
14
|
-
): AnyFieldGroupApi {
|
|
15
|
-
const resolveProps = (props: any) =>
|
|
16
|
-
new Proxy(props, {
|
|
17
|
-
get(target, property, receiver) {
|
|
18
|
-
if (
|
|
19
|
-
property === 'name' ||
|
|
20
|
-
property === 'validators' ||
|
|
21
|
-
property === 'listeners'
|
|
22
|
-
) {
|
|
23
|
-
return Reflect.get(
|
|
24
|
-
group._getFormFieldOptions({ ...target }, withComponentProps),
|
|
25
|
-
property,
|
|
26
|
-
)
|
|
27
|
-
}
|
|
28
|
-
return Reflect.get(target, property, receiver)
|
|
29
|
-
},
|
|
30
|
-
})
|
|
31
|
-
|
|
32
|
-
return Object.assign(group, {
|
|
33
|
-
Field: (internals: any, props: any) =>
|
|
34
|
-
form.Field(internals, resolveProps(props)),
|
|
35
|
-
ArrayField: (internals: any, props: any) =>
|
|
36
|
-
form.ArrayField(internals, resolveProps(props)),
|
|
37
|
-
Subscribe: (internals: any, props: any) => form.Subscribe(internals, props),
|
|
38
|
-
}) as never
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
export function defineFieldGroupRuntime<
|
|
42
|
-
TFields extends Record<string, unknown>,
|
|
43
|
-
>(defineFieldGroupFn: (helperRuntime: any) => TFields) {
|
|
44
|
-
const fields = defineFieldGroupFieldsRuntime(
|
|
45
|
-
defineFieldGroupFn(fieldGroupHelperRuntime),
|
|
46
|
-
)
|
|
47
|
-
|
|
48
|
-
return {
|
|
49
|
-
fields,
|
|
50
|
-
bindComponent: (Component: Component<any>, fieldsPropName: string) =>
|
|
51
|
-
withFieldsRuntime(fields, Component, fieldsPropName),
|
|
52
|
-
}
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
function withFieldsRuntime(
|
|
56
|
-
fields: Record<string, unknown>,
|
|
57
|
-
Component: Component<any>,
|
|
58
|
-
fieldsPropName: string,
|
|
59
|
-
) {
|
|
60
|
-
const fieldNames = Object.keys(fields)
|
|
61
|
-
return ((internals: any, props: any) => {
|
|
62
|
-
const form = props.form
|
|
63
|
-
if (!form) {
|
|
64
|
-
throw new Error('TanStack Form: Field groups must receive a `form` prop.')
|
|
65
|
-
}
|
|
66
|
-
const api = attachSvelteFieldGroupComponents(
|
|
67
|
-
new InternalFieldGroupApi({
|
|
68
|
-
form,
|
|
69
|
-
fieldNames,
|
|
70
|
-
getBindings: () => props[fieldsPropName] as InternalFieldGroupBindings,
|
|
71
|
-
}),
|
|
72
|
-
form,
|
|
73
|
-
)
|
|
74
|
-
return Component(
|
|
75
|
-
internals,
|
|
76
|
-
withComponentProps(props, {
|
|
77
|
-
form: undefined,
|
|
78
|
-
[fieldsPropName]: api,
|
|
79
|
-
}),
|
|
80
|
-
)
|
|
81
|
-
}) as Component<any>
|
|
82
|
-
}
|
|
@@ -1,179 +0,0 @@
|
|
|
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
DELETED
|
@@ -1,101 +0,0 @@
|
|
|
1
|
-
<script module lang="ts">
|
|
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,
|
|
7
|
-
FormGroupApi,
|
|
8
|
-
FormGroupOptions,
|
|
9
|
-
FormGroupValidators,
|
|
10
|
-
ToFormGroupErrorTypes,
|
|
11
|
-
} from '@tanstack/form-core'
|
|
12
|
-
import type { AnyInternalFormApi } from '@tanstack/form-core/internals'
|
|
13
|
-
|
|
14
|
-
export function createFormGroup<
|
|
15
|
-
TFormData,
|
|
16
|
-
TGroupName,
|
|
17
|
-
TGroupValue,
|
|
18
|
-
const TGroupValidators extends FormGroupValidators<TGroupValue>,
|
|
19
|
-
TFormErrorTypes extends FormErrorTypes,
|
|
20
|
-
>(
|
|
21
|
-
options: () => FormGroupOptions<
|
|
22
|
-
TFormData,
|
|
23
|
-
TGroupName,
|
|
24
|
-
TGroupValue,
|
|
25
|
-
TGroupValidators,
|
|
26
|
-
TFormErrorTypes
|
|
27
|
-
>,
|
|
28
|
-
): FormGroupApi<
|
|
29
|
-
TFormData,
|
|
30
|
-
TGroupName,
|
|
31
|
-
TGroupValue,
|
|
32
|
-
ToFormGroupErrorTypes<TGroupValidators>,
|
|
33
|
-
TFormErrorTypes
|
|
34
|
-
> {
|
|
35
|
-
const group = new InternalFormGroupApi(options() as never)
|
|
36
|
-
|
|
37
|
-
$effect.pre(() => {
|
|
38
|
-
group.update(options() as never)
|
|
39
|
-
})
|
|
40
|
-
$effect(() => {
|
|
41
|
-
group.mount()
|
|
42
|
-
return () => group._cleanup()
|
|
43
|
-
})
|
|
44
|
-
|
|
45
|
-
const state = useSelector(group.atom)
|
|
46
|
-
|
|
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
|
|
54
|
-
},
|
|
55
|
-
}) as never
|
|
56
|
-
}
|
|
57
|
-
|
|
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
|
|
78
|
-
}
|
|
79
|
-
</script>
|
|
80
|
-
|
|
81
|
-
<script lang="ts">
|
|
82
|
-
import { untrack, type Snippet } from 'svelte'
|
|
83
|
-
|
|
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
|
-
}
|
|
92
|
-
|
|
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
|
-
)
|
|
99
|
-
</script>
|
|
100
|
-
|
|
101
|
-
{@render children(groupApi)}
|
package/src/Subscribe.svelte
DELETED
|
@@ -1,26 +0,0 @@
|
|
|
1
|
-
<script lang="ts">
|
|
2
|
-
import { useSelector } from '@tanstack/svelte-store'
|
|
3
|
-
import { untrack, type Snippet } from 'svelte'
|
|
4
|
-
|
|
5
|
-
interface Props {
|
|
6
|
-
children: Snippet<[any]>
|
|
7
|
-
source: any
|
|
8
|
-
selector: (state: any) => any
|
|
9
|
-
when?: (selected: any) => boolean
|
|
10
|
-
}
|
|
11
|
-
|
|
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
|
-
)
|
|
22
|
-
</script>
|
|
23
|
-
|
|
24
|
-
{#if when(value.current)}
|
|
25
|
-
{@render children(value.current)}
|
|
26
|
-
{/if}
|
package/src/context-keys.ts
DELETED
package/src/createForm.public.ts
DELETED
|
@@ -1,26 +0,0 @@
|
|
|
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
|
package/src/createForm.svelte.ts
DELETED
|
@@ -1,76 +0,0 @@
|
|
|
1
|
-
import { InternalFormApi } from '@tanstack/form-core/internals'
|
|
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 { withComponentProps } from './utils.lib.js'
|
|
8
|
-
import type { FormOptions } from '@tanstack/form-core'
|
|
9
|
-
import type { Component } from 'svelte'
|
|
10
|
-
import type { AnyInternalFormApi } from '@tanstack/form-core/internals'
|
|
11
|
-
import type { SvelteTanStackFormComponents } from './Components.public'
|
|
12
|
-
|
|
13
|
-
export interface InternalSvelteFormApi
|
|
14
|
-
extends AnyInternalFormApi, SvelteTanStackFormComponents<any, any, any> {
|
|
15
|
-
_Subscribe: Component<any>
|
|
16
|
-
useSelector: <TSelected = any>(
|
|
17
|
-
selector?: (state: any) => TSelected,
|
|
18
|
-
) => { readonly current: TSelected }
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
export function attachSvelteFormComponents(
|
|
22
|
-
form: AnyInternalFormApi,
|
|
23
|
-
fieldComponents: Record<string, Component<any>> | null,
|
|
24
|
-
): InternalSvelteFormApi {
|
|
25
|
-
const result = form as InternalSvelteFormApi
|
|
26
|
-
|
|
27
|
-
result.Field = ((internals: any, props: any) =>
|
|
28
|
-
Field(
|
|
29
|
-
internals,
|
|
30
|
-
withComponentProps(props, {
|
|
31
|
-
form,
|
|
32
|
-
fieldComponents: fieldComponents ?? {},
|
|
33
|
-
}),
|
|
34
|
-
)) as never
|
|
35
|
-
result.ArrayField = ((internals: any, props: any) =>
|
|
36
|
-
Field(
|
|
37
|
-
internals,
|
|
38
|
-
withComponentProps(props, {
|
|
39
|
-
form,
|
|
40
|
-
array: true,
|
|
41
|
-
fieldComponents: fieldComponents ?? {},
|
|
42
|
-
}),
|
|
43
|
-
)) as never
|
|
44
|
-
result._Subscribe = (internals, props) => Subscribe(internals, props)
|
|
45
|
-
result.Subscribe = ((internals: any, props: any) =>
|
|
46
|
-
Subscribe(
|
|
47
|
-
internals,
|
|
48
|
-
withComponentProps(props, { source: form.atom }),
|
|
49
|
-
)) as never
|
|
50
|
-
result.FormGroup = ((internals: any, props: any) =>
|
|
51
|
-
FormGroup(internals, withComponentProps(props, { form }))) as never
|
|
52
|
-
result.useSelector = ((selector?: (state: any) => any) =>
|
|
53
|
-
useSelector(form.atom, selector)) as never
|
|
54
|
-
|
|
55
|
-
return result
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
export function initializeForm(
|
|
59
|
-
options: FormOptions<any, any, any>,
|
|
60
|
-
): InternalSvelteFormApi {
|
|
61
|
-
return attachSvelteFormComponents(new InternalFormApi(options), null)
|
|
62
|
-
}
|
|
63
|
-
|
|
64
|
-
export function createInternalForm(
|
|
65
|
-
options: () => FormOptions<any, any, any>,
|
|
66
|
-
initialize: (options: FormOptions<any, any, any>) => InternalSvelteFormApi,
|
|
67
|
-
): InternalSvelteFormApi {
|
|
68
|
-
const form = initialize(options())
|
|
69
|
-
|
|
70
|
-
$effect.pre(() => {
|
|
71
|
-
form._update(options())
|
|
72
|
-
})
|
|
73
|
-
onMount(() => form.mount())
|
|
74
|
-
|
|
75
|
-
return form
|
|
76
|
-
}
|
|
@@ -1,48 +0,0 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
AnyFormApi,
|
|
3
|
-
FormApi,
|
|
4
|
-
FormErrorTypes,
|
|
5
|
-
FormState,
|
|
6
|
-
} from '@tanstack/form-core'
|
|
7
|
-
import type { Component } from 'svelte'
|
|
8
|
-
import type { SvelteTanStackFormComponents } from './Components.public'
|
|
9
|
-
import type {
|
|
10
|
-
AnySvelteFormComponentMap,
|
|
11
|
-
DefaultSvelteFormComponentMap,
|
|
12
|
-
} from './AppForm/componentMap.public'
|
|
13
|
-
|
|
14
|
-
export interface SvelteFormSelectors<
|
|
15
|
-
TFormData,
|
|
16
|
-
TFormErrorTypes extends FormErrorTypes,
|
|
17
|
-
> {
|
|
18
|
-
useSelector: <TSelected = FormState<TFormData, TFormErrorTypes>>(
|
|
19
|
-
selector?: (state: FormState<TFormData, TFormErrorTypes>) => TSelected,
|
|
20
|
-
) => { readonly current: TSelected }
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
type ExtendedFormApi<
|
|
24
|
-
TFormData,
|
|
25
|
-
TFormErrorTypes extends FormErrorTypes,
|
|
26
|
-
TFieldComponents extends Record<string, Component<any>>,
|
|
27
|
-
> = FormApi<TFormData, TFormErrorTypes> &
|
|
28
|
-
SvelteTanStackFormComponents<TFormData, TFormErrorTypes, TFieldComponents> &
|
|
29
|
-
SvelteFormSelectors<TFormData, TFormErrorTypes>
|
|
30
|
-
|
|
31
|
-
export type SvelteFormApi<
|
|
32
|
-
TFormData,
|
|
33
|
-
TFormErrorTypes extends FormErrorTypes,
|
|
34
|
-
TComponents extends AnySvelteFormComponentMap = DefaultSvelteFormComponentMap,
|
|
35
|
-
> = unknown extends TComponents['formComponents']
|
|
36
|
-
? ExtendedFormApi<TFormData, TFormErrorTypes, TComponents['fieldComponents']>
|
|
37
|
-
: ExtendedFormApi<
|
|
38
|
-
TFormData,
|
|
39
|
-
TFormErrorTypes,
|
|
40
|
-
TComponents['fieldComponents']
|
|
41
|
-
> &
|
|
42
|
-
TComponents['formComponents']
|
|
43
|
-
|
|
44
|
-
export type AnySvelteFormApi = AnyFormApi &
|
|
45
|
-
SvelteTanStackFormComponents<any, any, any> &
|
|
46
|
-
SvelteFormSelectors<any, any>
|
|
47
|
-
|
|
48
|
-
export type { SvelteFormComponentMap } from './AppForm/componentMap.public'
|
package/src/formType.public.ts
DELETED
|
@@ -1,46 +0,0 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
AnyFormOptions,
|
|
3
|
-
FormOptions,
|
|
4
|
-
FormValidators,
|
|
5
|
-
ToFormErrorTypes,
|
|
6
|
-
} from '@tanstack/form-core'
|
|
7
|
-
import type { AppFormOptions } from './AppForm/appFormOptions.public'
|
|
8
|
-
import type {
|
|
9
|
-
AnySvelteFormComponentMap,
|
|
10
|
-
DefaultSvelteFormComponentMap,
|
|
11
|
-
} from './AppForm/componentMap.public'
|
|
12
|
-
import type { SvelteFormApi } from './formApiTypes.public'
|
|
13
|
-
|
|
14
|
-
type SvelteFormTypeErrorTypes<
|
|
15
|
-
TValidators extends FormValidators<any>,
|
|
16
|
-
TSubmitReturn,
|
|
17
|
-
> = unknown extends TSubmitReturn
|
|
18
|
-
? any
|
|
19
|
-
: ToFormErrorTypes<TValidators, TSubmitReturn>
|
|
20
|
-
|
|
21
|
-
export type SvelteFormType<
|
|
22
|
-
TOptions extends
|
|
23
|
-
AnyFormOptions | AppFormOptions<any, any, any, AnySvelteFormComponentMap>,
|
|
24
|
-
> =
|
|
25
|
-
TOptions extends AppFormOptions<
|
|
26
|
-
infer TData,
|
|
27
|
-
infer TValidators,
|
|
28
|
-
infer TSubmitReturn,
|
|
29
|
-
infer TComponents
|
|
30
|
-
>
|
|
31
|
-
? SvelteFormApi<
|
|
32
|
-
TData,
|
|
33
|
-
SvelteFormTypeErrorTypes<TValidators, TSubmitReturn>,
|
|
34
|
-
TComponents
|
|
35
|
-
>
|
|
36
|
-
: TOptions extends FormOptions<
|
|
37
|
-
infer TData,
|
|
38
|
-
infer TValidators,
|
|
39
|
-
infer TSubmitReturn
|
|
40
|
-
>
|
|
41
|
-
? SvelteFormApi<
|
|
42
|
-
TData,
|
|
43
|
-
SvelteFormTypeErrorTypes<TValidators, TSubmitReturn>,
|
|
44
|
-
DefaultSvelteFormComponentMap
|
|
45
|
-
>
|
|
46
|
-
: never
|