@tanstack/svelte-form 1.33.0 → 1.33.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/Field.svelte +8 -8
- package/dist/FormGroup.svelte +2 -2
- package/dist/Subscribe.svelte +2 -2
- package/dist/createForm.svelte.d.ts +6 -0
- package/dist/createForm.svelte.js +4 -2
- package/dist/index.d.ts +1 -1
- package/dist/index.js +1 -1
- package/package.json +2 -2
- package/src/Field.svelte +8 -8
- package/src/FormGroup.svelte +2 -2
- package/src/Subscribe.svelte +2 -2
- package/src/createForm.svelte.ts +42 -2
- package/src/index.ts +1 -1
package/dist/Field.svelte
CHANGED
|
@@ -8,7 +8,7 @@
|
|
|
8
8
|
type FormAsyncValidateOrFn,
|
|
9
9
|
type FormValidateOrFn,
|
|
10
10
|
} from '@tanstack/form-core'
|
|
11
|
-
import {
|
|
11
|
+
import { useSelector } from '@tanstack/svelte-store'
|
|
12
12
|
import { onMount, type Snippet } from 'svelte'
|
|
13
13
|
import type { CreateFieldOptions } from './types.js'
|
|
14
14
|
|
|
@@ -96,26 +96,26 @@
|
|
|
96
96
|
api.update(current)
|
|
97
97
|
})
|
|
98
98
|
|
|
99
|
-
const storeSub =
|
|
99
|
+
const storeSub = useSelector(api.store, (state) =>
|
|
100
100
|
options.mode === 'array'
|
|
101
101
|
? state.meta._arrayVersion || 0
|
|
102
102
|
: state.value,
|
|
103
103
|
)
|
|
104
|
-
const metaIsTouchedSub =
|
|
104
|
+
const metaIsTouchedSub = useSelector(
|
|
105
105
|
api.store,
|
|
106
106
|
(state) => state.meta.isTouched,
|
|
107
107
|
)
|
|
108
|
-
const metaIsBlurredSub =
|
|
108
|
+
const metaIsBlurredSub = useSelector(
|
|
109
109
|
api.store,
|
|
110
110
|
(state) => state.meta.isBlurred,
|
|
111
111
|
)
|
|
112
|
-
const metaIsDirtySub =
|
|
113
|
-
const metaErrorMapSub =
|
|
114
|
-
const metaErrorSourceMapSub =
|
|
112
|
+
const metaIsDirtySub = useSelector(api.store, (state) => state.meta.isDirty)
|
|
113
|
+
const metaErrorMapSub = useSelector(api.store, (state) => state.meta.errorMap)
|
|
114
|
+
const metaErrorSourceMapSub = useSelector(
|
|
115
115
|
api.store,
|
|
116
116
|
(state) => state.meta.errorSourceMap,
|
|
117
117
|
)
|
|
118
|
-
const metaIsValidatingSub =
|
|
118
|
+
const metaIsValidatingSub = useSelector(
|
|
119
119
|
api.store,
|
|
120
120
|
(state) => state.meta.isValidating,
|
|
121
121
|
)
|
package/dist/FormGroup.svelte
CHANGED
|
@@ -9,7 +9,7 @@
|
|
|
9
9
|
type FormAsyncValidateOrFn,
|
|
10
10
|
type FormValidateOrFn,
|
|
11
11
|
} from '@tanstack/form-core'
|
|
12
|
-
import {
|
|
12
|
+
import { useSelector } from '@tanstack/svelte-store'
|
|
13
13
|
import { onMount, type Snippet } from 'svelte'
|
|
14
14
|
|
|
15
15
|
export function createFormGroup<
|
|
@@ -108,7 +108,7 @@
|
|
|
108
108
|
api.update(current)
|
|
109
109
|
})
|
|
110
110
|
|
|
111
|
-
const storeSub =
|
|
111
|
+
const storeSub = useSelector(api.store)
|
|
112
112
|
Object.defineProperty(extendedApi, 'state', {
|
|
113
113
|
get() {
|
|
114
114
|
return storeSub.current
|
package/dist/Subscribe.svelte
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
<script lang="ts">
|
|
2
|
-
import {
|
|
2
|
+
import { useSelector } from '@tanstack/svelte-store'
|
|
3
3
|
|
|
4
4
|
// Don't bother typing this out, this component is only usable through a wrapper
|
|
5
5
|
interface Props {
|
|
@@ -10,7 +10,7 @@
|
|
|
10
10
|
|
|
11
11
|
let { children, store, selector = (state) => state }: Props = $props()
|
|
12
12
|
|
|
13
|
-
const value =
|
|
13
|
+
const value = useSelector(store, selector)
|
|
14
14
|
</script>
|
|
15
15
|
|
|
16
16
|
{@render children(value.current)}
|
|
@@ -5,6 +5,12 @@ import type { FieldComponent, FormGroupComponent, WithoutFunction } from './type
|
|
|
5
5
|
export interface SvelteFormApi<TParentData, TFormOnMount extends undefined | FormValidateOrFn<TParentData>, TFormOnChange extends undefined | FormValidateOrFn<TParentData>, TFormOnChangeAsync extends undefined | FormAsyncValidateOrFn<TParentData>, TFormOnBlur extends undefined | FormValidateOrFn<TParentData>, TFormOnBlurAsync extends undefined | FormAsyncValidateOrFn<TParentData>, TFormOnSubmit extends undefined | FormValidateOrFn<TParentData>, TFormOnSubmitAsync extends undefined | FormAsyncValidateOrFn<TParentData>, TFormOnDynamic extends undefined | FormValidateOrFn<TParentData>, TFormOnDynamicAsync extends undefined | FormAsyncValidateOrFn<TParentData>, TFormOnServer extends undefined | FormAsyncValidateOrFn<TParentData>, TSubmitMeta> {
|
|
6
6
|
Field: FieldComponent<TParentData, TFormOnMount, TFormOnChange, TFormOnChangeAsync, TFormOnBlur, TFormOnBlurAsync, TFormOnSubmit, TFormOnSubmitAsync, TFormOnDynamic, TFormOnDynamicAsync, TFormOnServer, TSubmitMeta>;
|
|
7
7
|
FormGroup: FormGroupComponent<TParentData, TFormOnMount, TFormOnChange, TFormOnChangeAsync, TFormOnBlur, TFormOnBlurAsync, TFormOnSubmit, TFormOnSubmitAsync, TFormOnDynamic, TFormOnDynamicAsync, TFormOnServer, TSubmitMeta>;
|
|
8
|
+
useSelector: <TSelected = NoInfer<FormState<TParentData, TFormOnMount, TFormOnChange, TFormOnChangeAsync, TFormOnBlur, TFormOnBlurAsync, TFormOnSubmit, TFormOnSubmitAsync, TFormOnDynamic, TFormOnDynamicAsync, TFormOnServer>>>(selector?: (state: NoInfer<FormState<TParentData, TFormOnMount, TFormOnChange, TFormOnChangeAsync, TFormOnBlur, TFormOnBlurAsync, TFormOnSubmit, TFormOnSubmitAsync, TFormOnDynamic, TFormOnDynamicAsync, TFormOnServer>>) => TSelected) => {
|
|
9
|
+
current: TSelected;
|
|
10
|
+
};
|
|
11
|
+
/**
|
|
12
|
+
* @deprecated Use `form.useSelector` instead.
|
|
13
|
+
*/
|
|
8
14
|
useStore: <TSelected = NoInfer<FormState<TParentData, TFormOnMount, TFormOnChange, TFormOnChangeAsync, TFormOnBlur, TFormOnBlurAsync, TFormOnSubmit, TFormOnSubmitAsync, TFormOnDynamic, TFormOnDynamicAsync, TFormOnServer>>>(selector?: (state: NoInfer<FormState<TParentData, TFormOnMount, TFormOnChange, TFormOnChangeAsync, TFormOnBlur, TFormOnBlurAsync, TFormOnSubmit, TFormOnSubmitAsync, TFormOnDynamic, TFormOnDynamicAsync, TFormOnServer>>) => TSelected) => {
|
|
9
15
|
current: TSelected;
|
|
10
16
|
};
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { FormApi } from '@tanstack/form-core';
|
|
2
|
-
import {
|
|
2
|
+
import { useSelector } from '@tanstack/svelte-store';
|
|
3
3
|
import { onMount } from 'svelte';
|
|
4
4
|
import Field from './Field.svelte';
|
|
5
5
|
import FormGroup from './FormGroup.svelte';
|
|
@@ -12,7 +12,9 @@ export function createForm(opts) {
|
|
|
12
12
|
extendedApi.Field = (internal, props) => Field(internal, { ...props, form: api });
|
|
13
13
|
// @ts-expect-error constructor definition exists only on a type level
|
|
14
14
|
extendedApi.FormGroup = (internal, props) => FormGroup(internal, { ...props, form: api });
|
|
15
|
-
extendedApi.
|
|
15
|
+
extendedApi.useSelector = (selector) => useSelector(api.store, selector);
|
|
16
|
+
/** @deprecated Use `form.useSelector` instead. */
|
|
17
|
+
extendedApi.useStore = extendedApi.useSelector;
|
|
16
18
|
// @ts-expect-error constructor definition exists only on a type level
|
|
17
19
|
extendedApi.Subscribe = (internal, props) => Subscribe(internal, { ...props, store: api.store });
|
|
18
20
|
onMount(api.mount);
|
package/dist/index.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
export * from '@tanstack/form-core';
|
|
2
|
-
export { useStore } from '@tanstack/svelte-store';
|
|
2
|
+
export { useSelector, useStore } from '@tanstack/svelte-store';
|
|
3
3
|
export { createForm, type SvelteFormApi } from './createForm.svelte.js';
|
|
4
4
|
export { default as Field, createField } from './Field.svelte';
|
|
5
5
|
export { default as FormGroup, createFormGroup } from './FormGroup.svelte';
|
package/dist/index.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
export * from '@tanstack/form-core';
|
|
2
|
-
export { useStore } from '@tanstack/svelte-store';
|
|
2
|
+
export { useSelector, useStore } from '@tanstack/svelte-store';
|
|
3
3
|
export { createForm } from './createForm.svelte.js';
|
|
4
4
|
export { default as Field, createField } from './Field.svelte';
|
|
5
5
|
export { default as FormGroup, createFormGroup } from './FormGroup.svelte';
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tanstack/svelte-form",
|
|
3
|
-
"version": "1.33.
|
|
3
|
+
"version": "1.33.1",
|
|
4
4
|
"description": "Powerful, type-safe forms for Svelte.",
|
|
5
5
|
"author": "tannerlinsley",
|
|
6
6
|
"license": "MIT",
|
|
@@ -32,7 +32,7 @@
|
|
|
32
32
|
],
|
|
33
33
|
"dependencies": {
|
|
34
34
|
"@tanstack/svelte-store": "^0.12.0",
|
|
35
|
-
"@tanstack/form-core": "1.33.
|
|
35
|
+
"@tanstack/form-core": "1.33.1"
|
|
36
36
|
},
|
|
37
37
|
"devDependencies": {
|
|
38
38
|
"@sveltejs/package": "^2.5.3",
|
package/src/Field.svelte
CHANGED
|
@@ -8,7 +8,7 @@
|
|
|
8
8
|
type FormAsyncValidateOrFn,
|
|
9
9
|
type FormValidateOrFn,
|
|
10
10
|
} from '@tanstack/form-core'
|
|
11
|
-
import {
|
|
11
|
+
import { useSelector } from '@tanstack/svelte-store'
|
|
12
12
|
import { onMount, type Snippet } from 'svelte'
|
|
13
13
|
import type { CreateFieldOptions } from './types.js'
|
|
14
14
|
|
|
@@ -96,26 +96,26 @@
|
|
|
96
96
|
api.update(current)
|
|
97
97
|
})
|
|
98
98
|
|
|
99
|
-
const storeSub =
|
|
99
|
+
const storeSub = useSelector(api.store, (state) =>
|
|
100
100
|
options.mode === 'array'
|
|
101
101
|
? state.meta._arrayVersion || 0
|
|
102
102
|
: state.value,
|
|
103
103
|
)
|
|
104
|
-
const metaIsTouchedSub =
|
|
104
|
+
const metaIsTouchedSub = useSelector(
|
|
105
105
|
api.store,
|
|
106
106
|
(state) => state.meta.isTouched,
|
|
107
107
|
)
|
|
108
|
-
const metaIsBlurredSub =
|
|
108
|
+
const metaIsBlurredSub = useSelector(
|
|
109
109
|
api.store,
|
|
110
110
|
(state) => state.meta.isBlurred,
|
|
111
111
|
)
|
|
112
|
-
const metaIsDirtySub =
|
|
113
|
-
const metaErrorMapSub =
|
|
114
|
-
const metaErrorSourceMapSub =
|
|
112
|
+
const metaIsDirtySub = useSelector(api.store, (state) => state.meta.isDirty)
|
|
113
|
+
const metaErrorMapSub = useSelector(api.store, (state) => state.meta.errorMap)
|
|
114
|
+
const metaErrorSourceMapSub = useSelector(
|
|
115
115
|
api.store,
|
|
116
116
|
(state) => state.meta.errorSourceMap,
|
|
117
117
|
)
|
|
118
|
-
const metaIsValidatingSub =
|
|
118
|
+
const metaIsValidatingSub = useSelector(
|
|
119
119
|
api.store,
|
|
120
120
|
(state) => state.meta.isValidating,
|
|
121
121
|
)
|
package/src/FormGroup.svelte
CHANGED
|
@@ -9,7 +9,7 @@
|
|
|
9
9
|
type FormAsyncValidateOrFn,
|
|
10
10
|
type FormValidateOrFn,
|
|
11
11
|
} from '@tanstack/form-core'
|
|
12
|
-
import {
|
|
12
|
+
import { useSelector } from '@tanstack/svelte-store'
|
|
13
13
|
import { onMount, type Snippet } from 'svelte'
|
|
14
14
|
|
|
15
15
|
export function createFormGroup<
|
|
@@ -108,7 +108,7 @@
|
|
|
108
108
|
api.update(current)
|
|
109
109
|
})
|
|
110
110
|
|
|
111
|
-
const storeSub =
|
|
111
|
+
const storeSub = useSelector(api.store)
|
|
112
112
|
Object.defineProperty(extendedApi, 'state', {
|
|
113
113
|
get() {
|
|
114
114
|
return storeSub.current
|
package/src/Subscribe.svelte
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
<script lang="ts">
|
|
2
|
-
import {
|
|
2
|
+
import { useSelector } from '@tanstack/svelte-store'
|
|
3
3
|
|
|
4
4
|
// Don't bother typing this out, this component is only usable through a wrapper
|
|
5
5
|
interface Props {
|
|
@@ -10,7 +10,7 @@
|
|
|
10
10
|
|
|
11
11
|
let { children, store, selector = (state) => state }: Props = $props()
|
|
12
12
|
|
|
13
|
-
const value =
|
|
13
|
+
const value = useSelector(store, selector)
|
|
14
14
|
</script>
|
|
15
15
|
|
|
16
16
|
{@render children(value.current)}
|
package/src/createForm.svelte.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { FormApi } from '@tanstack/form-core'
|
|
2
|
-
import {
|
|
2
|
+
import { useSelector } from '@tanstack/svelte-store'
|
|
3
3
|
import { onMount } from 'svelte'
|
|
4
4
|
import Field from './Field.svelte'
|
|
5
5
|
import FormGroup from './FormGroup.svelte'
|
|
@@ -64,6 +64,44 @@ export interface SvelteFormApi<
|
|
|
64
64
|
TFormOnServer,
|
|
65
65
|
TSubmitMeta
|
|
66
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
|
+
*/
|
|
67
105
|
useStore: <
|
|
68
106
|
TSelected = NoInfer<
|
|
69
107
|
FormState<
|
|
@@ -295,7 +333,9 @@ export function createForm<
|
|
|
295
333
|
// @ts-expect-error constructor definition exists only on a type level
|
|
296
334
|
extendedApi.FormGroup = (internal, props) =>
|
|
297
335
|
FormGroup(internal, { ...props, form: api as never } as never)
|
|
298
|
-
extendedApi.
|
|
336
|
+
extendedApi.useSelector = (selector) => useSelector(api.store, selector)
|
|
337
|
+
/** @deprecated Use `form.useSelector` instead. */
|
|
338
|
+
extendedApi.useStore = extendedApi.useSelector
|
|
299
339
|
// @ts-expect-error constructor definition exists only on a type level
|
|
300
340
|
extendedApi.Subscribe = (internal, props) =>
|
|
301
341
|
Subscribe(internal, { ...props, store: api.store })
|