@tanstack/svelte-table 9.0.0-alpha.45 → 9.0.0-alpha.47
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/createTable.svelte.d.ts +25 -0
- package/dist/createTable.svelte.js +25 -0
- package/dist/createTableState.svelte.d.ts +15 -0
- package/dist/createTableState.svelte.js +15 -0
- package/dist/reactivity.svelte.d.ts +7 -0
- package/dist/reactivity.svelte.js +8 -0
- package/dist/render-component.d.ts +7 -5
- package/dist/render-component.js +7 -5
- package/dist/subscribe.d.ts +17 -2
- package/package.json +4 -4
- package/src/createTable.svelte.ts +25 -0
- package/src/createTableState.svelte.ts +15 -0
- package/src/reactivity.svelte.ts +8 -0
- package/src/render-component.ts +7 -5
- package/src/subscribe.ts +17 -2
|
@@ -10,4 +10,29 @@ export type SvelteTable<TFeatures extends TableFeatures, TData extends RowData,
|
|
|
10
10
|
*/
|
|
11
11
|
readonly state: Readonly<TSelected>;
|
|
12
12
|
};
|
|
13
|
+
/**
|
|
14
|
+
* Creates a Svelte 5 table instance backed by rune-aware TanStack Store atoms.
|
|
15
|
+
*
|
|
16
|
+
* The optional selector projects from `table.store`; the selected value is
|
|
17
|
+
* exposed on `table.state`. The adapter syncs options in `$effect.pre`, so
|
|
18
|
+
* reactive option getters and external `$state` values are applied before DOM
|
|
19
|
+
* updates read table APIs such as `getRowModel()`.
|
|
20
|
+
*
|
|
21
|
+
* @example
|
|
22
|
+
* ```svelte
|
|
23
|
+
* <script lang="ts">
|
|
24
|
+
* const table = createTable(
|
|
25
|
+
* {
|
|
26
|
+
* _features,
|
|
27
|
+
* _rowModels: {},
|
|
28
|
+
* columns,
|
|
29
|
+
* data,
|
|
30
|
+
* },
|
|
31
|
+
* (state) => ({ pagination: state.pagination }),
|
|
32
|
+
* )
|
|
33
|
+
* </script>
|
|
34
|
+
*
|
|
35
|
+
* {table.state.pagination.pageIndex}
|
|
36
|
+
* ```
|
|
37
|
+
*/
|
|
13
38
|
export declare function createTable<TFeatures extends TableFeatures, TData extends RowData, TSelected = TableState<TFeatures>>(tableOptions: TableOptions<TFeatures, TData>, selector?: (state: TableState<TFeatures>) => TSelected): SvelteTable<TFeatures, TData, TSelected>;
|
|
@@ -3,6 +3,31 @@ import { useSelector } from '@tanstack/svelte-store';
|
|
|
3
3
|
import { untrack } from 'svelte';
|
|
4
4
|
import { mergeObjects } from './merge-objects';
|
|
5
5
|
import { svelteReactivity } from './reactivity.svelte';
|
|
6
|
+
/**
|
|
7
|
+
* Creates a Svelte 5 table instance backed by rune-aware TanStack Store atoms.
|
|
8
|
+
*
|
|
9
|
+
* The optional selector projects from `table.store`; the selected value is
|
|
10
|
+
* exposed on `table.state`. The adapter syncs options in `$effect.pre`, so
|
|
11
|
+
* reactive option getters and external `$state` values are applied before DOM
|
|
12
|
+
* updates read table APIs such as `getRowModel()`.
|
|
13
|
+
*
|
|
14
|
+
* @example
|
|
15
|
+
* ```svelte
|
|
16
|
+
* <script lang="ts">
|
|
17
|
+
* const table = createTable(
|
|
18
|
+
* {
|
|
19
|
+
* _features,
|
|
20
|
+
* _rowModels: {},
|
|
21
|
+
* columns,
|
|
22
|
+
* data,
|
|
23
|
+
* },
|
|
24
|
+
* (state) => ({ pagination: state.pagination }),
|
|
25
|
+
* )
|
|
26
|
+
* </script>
|
|
27
|
+
*
|
|
28
|
+
* {table.state.pagination.pageIndex}
|
|
29
|
+
* ```
|
|
30
|
+
*/
|
|
6
31
|
export function createTable(tableOptions, selector) {
|
|
7
32
|
// 1. Merge reactivity into options using mergeObjects (preserves getters)
|
|
8
33
|
const mergedOptions = mergeObjects(tableOptions, {
|
|
@@ -1,2 +1,17 @@
|
|
|
1
1
|
import type { Updater } from '@tanstack/table-core';
|
|
2
|
+
/**
|
|
3
|
+
* Creates a small Svelte 5 state holder that accepts TanStack Table updaters.
|
|
4
|
+
*
|
|
5
|
+
* This is useful when a table state slice should be owned outside the table
|
|
6
|
+
* with `$state`, but still needs to accept both value and functional updater
|
|
7
|
+
* forms from `on[State]Change` callbacks.
|
|
8
|
+
*
|
|
9
|
+
* @example
|
|
10
|
+
* ```ts
|
|
11
|
+
* const [pagination, setPagination] = createTableState({
|
|
12
|
+
* pageIndex: 0,
|
|
13
|
+
* pageSize: 10,
|
|
14
|
+
* })
|
|
15
|
+
* ```
|
|
16
|
+
*/
|
|
2
17
|
export declare function createTableState<TState>(initialValue: TState): [() => TState, (updater: Updater<TState>) => void];
|
|
@@ -1,3 +1,18 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Creates a small Svelte 5 state holder that accepts TanStack Table updaters.
|
|
3
|
+
*
|
|
4
|
+
* This is useful when a table state slice should be owned outside the table
|
|
5
|
+
* with `$state`, but still needs to accept both value and functional updater
|
|
6
|
+
* forms from `on[State]Change` callbacks.
|
|
7
|
+
*
|
|
8
|
+
* @example
|
|
9
|
+
* ```ts
|
|
10
|
+
* const [pagination, setPagination] = createTableState({
|
|
11
|
+
* pageIndex: 0,
|
|
12
|
+
* pageSize: 10,
|
|
13
|
+
* })
|
|
14
|
+
* ```
|
|
15
|
+
*/
|
|
1
16
|
export function createTableState(initialValue) {
|
|
2
17
|
let value = $state(initialValue);
|
|
3
18
|
return [
|
|
@@ -1,2 +1,9 @@
|
|
|
1
1
|
import type { TableReactivityBindings } from '@tanstack/table-core/reactivity';
|
|
2
|
+
/**
|
|
3
|
+
* Creates the table-core reactivity bindings used by the Svelte adapter.
|
|
4
|
+
*
|
|
5
|
+
* Readonly table atoms are backed by `$derived.by`, writable atoms by `$state`,
|
|
6
|
+
* and subscriptions bridge through rune effects so table APIs participate in
|
|
7
|
+
* Svelte dependency tracking.
|
|
8
|
+
*/
|
|
2
9
|
export declare function svelteReactivity(): TableReactivityBindings;
|
|
@@ -14,9 +14,17 @@ function subscribeToRune(getValue, observerOrNext) {
|
|
|
14
14
|
});
|
|
15
15
|
return { unsubscribe };
|
|
16
16
|
}
|
|
17
|
+
/**
|
|
18
|
+
* Creates the table-core reactivity bindings used by the Svelte adapter.
|
|
19
|
+
*
|
|
20
|
+
* Readonly table atoms are backed by `$derived.by`, writable atoms by `$state`,
|
|
21
|
+
* and subscriptions bridge through rune effects so table APIs participate in
|
|
22
|
+
* Svelte dependency tracking.
|
|
23
|
+
*/
|
|
17
24
|
export function svelteReactivity() {
|
|
18
25
|
return {
|
|
19
26
|
createOptionsStore: true,
|
|
27
|
+
schedule: (fn) => queueMicrotask(() => fn()),
|
|
20
28
|
createReadonlyAtom: (fn, _options) => {
|
|
21
29
|
const value = $derived.by(fn);
|
|
22
30
|
return {
|
|
@@ -41,7 +41,8 @@ export declare class RenderSnippetConfig<TProps> {
|
|
|
41
41
|
constructor(snippet: Snippet<[TProps]>, params?: TProps | undefined);
|
|
42
42
|
}
|
|
43
43
|
/**
|
|
44
|
-
*
|
|
44
|
+
* Wraps a Svelte component so it can be returned from a column definition
|
|
45
|
+
* renderer such as `cell`, `header`, or `footer`.
|
|
45
46
|
*
|
|
46
47
|
* This is only to be used with Svelte Components - use `renderSnippet` for Svelte Snippets.
|
|
47
48
|
*
|
|
@@ -64,15 +65,16 @@ export declare class RenderSnippetConfig<TProps> {
|
|
|
64
65
|
*/
|
|
65
66
|
export declare const renderComponent: <TComponent extends Component<any>, TProps extends ComponentProps<TComponent>>(component: TComponent, props?: TProps) => RenderComponentConfig<TComponent>;
|
|
66
67
|
/**
|
|
67
|
-
*
|
|
68
|
+
* Wraps a Svelte snippet so it can be returned from a column definition
|
|
69
|
+
* renderer such as `cell`, `header`, or `footer`.
|
|
68
70
|
*
|
|
69
71
|
* *The snippet must only take one parameter.*
|
|
70
72
|
*
|
|
71
73
|
* This is only to be used with Snippets - use `renderComponent` for Svelte Components.
|
|
72
74
|
*
|
|
73
|
-
* @param snippet
|
|
74
|
-
* @param params
|
|
75
|
-
* @returns
|
|
75
|
+
* @param snippet The snippet to render.
|
|
76
|
+
* @param params The single parameter object passed to the snippet.
|
|
77
|
+
* @returns A `RenderSnippetConfig` consumed by the Svelte `FlexRender` component.
|
|
76
78
|
* @example
|
|
77
79
|
* ```ts
|
|
78
80
|
* // +page.svelte
|
package/dist/render-component.js
CHANGED
|
@@ -42,7 +42,8 @@ export class RenderSnippetConfig {
|
|
|
42
42
|
}
|
|
43
43
|
}
|
|
44
44
|
/**
|
|
45
|
-
*
|
|
45
|
+
* Wraps a Svelte component so it can be returned from a column definition
|
|
46
|
+
* renderer such as `cell`, `header`, or `footer`.
|
|
46
47
|
*
|
|
47
48
|
* This is only to be used with Svelte Components - use `renderSnippet` for Svelte Snippets.
|
|
48
49
|
*
|
|
@@ -65,15 +66,16 @@ export class RenderSnippetConfig {
|
|
|
65
66
|
*/
|
|
66
67
|
export const renderComponent = (component, props) => new RenderComponentConfig(component, props);
|
|
67
68
|
/**
|
|
68
|
-
*
|
|
69
|
+
* Wraps a Svelte snippet so it can be returned from a column definition
|
|
70
|
+
* renderer such as `cell`, `header`, or `footer`.
|
|
69
71
|
*
|
|
70
72
|
* *The snippet must only take one parameter.*
|
|
71
73
|
*
|
|
72
74
|
* This is only to be used with Snippets - use `renderComponent` for Svelte Components.
|
|
73
75
|
*
|
|
74
|
-
* @param snippet
|
|
75
|
-
* @param params
|
|
76
|
-
* @returns
|
|
76
|
+
* @param snippet The snippet to render.
|
|
77
|
+
* @param params The single parameter object passed to the snippet.
|
|
78
|
+
* @returns A `RenderSnippetConfig` consumed by the Svelte `FlexRender` component.
|
|
77
79
|
* @example
|
|
78
80
|
* ```ts
|
|
79
81
|
* // +page.svelte
|
package/dist/subscribe.d.ts
CHANGED
|
@@ -2,8 +2,23 @@ import { useSelector } from '@tanstack/svelte-store';
|
|
|
2
2
|
import type { Atom, ReadonlyAtom, ReadonlyStore, Store } from '@tanstack/svelte-store';
|
|
3
3
|
export type SubscribeSource<TValue> = Atom<TValue> | ReadonlyAtom<TValue> | Store<TValue> | ReadonlyStore<TValue>;
|
|
4
4
|
/**
|
|
5
|
-
*
|
|
6
|
-
*
|
|
5
|
+
* Creates a fine-grained Svelte subscription to a TanStack Store source.
|
|
6
|
+
*
|
|
7
|
+
* Pass a table atom or store and optionally project it with a selector. The
|
|
8
|
+
* returned selector store exposes `.current`, making it useful for reading
|
|
9
|
+
* focused table state outside the broad `createTable` selector.
|
|
10
|
+
*
|
|
11
|
+
* @example
|
|
12
|
+
* ```svelte
|
|
13
|
+
* <script lang="ts">
|
|
14
|
+
* const selected = subscribeTable(
|
|
15
|
+
* table.atoms.rowSelection,
|
|
16
|
+
* (rowSelection) => rowSelection[row.id],
|
|
17
|
+
* )
|
|
18
|
+
* </script>
|
|
19
|
+
*
|
|
20
|
+
* <input type="checkbox" checked={!!selected.current} />
|
|
21
|
+
* ```
|
|
7
22
|
*/
|
|
8
23
|
export declare function subscribeTable<TSourceValue>(source: SubscribeSource<TSourceValue>): ReturnType<typeof useSelector<TSourceValue>>;
|
|
9
24
|
export declare function subscribeTable<TSourceValue, TSelected>(source: SubscribeSource<TSourceValue>, selector: (state: TSourceValue) => TSelected): ReturnType<typeof useSelector<TSourceValue, TSelected>>;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tanstack/svelte-table",
|
|
3
|
-
"version": "9.0.0-alpha.
|
|
3
|
+
"version": "9.0.0-alpha.47",
|
|
4
4
|
"description": "Headless UI for building powerful tables & datagrids for Svelte.",
|
|
5
5
|
"author": "Tanner Linsley",
|
|
6
6
|
"license": "MIT",
|
|
@@ -51,14 +51,14 @@
|
|
|
51
51
|
],
|
|
52
52
|
"dependencies": {
|
|
53
53
|
"@tanstack/svelte-store": "^0.12.0",
|
|
54
|
-
"@tanstack/table-core": "9.0.0-alpha.
|
|
54
|
+
"@tanstack/table-core": "9.0.0-alpha.47"
|
|
55
55
|
},
|
|
56
56
|
"devDependencies": {
|
|
57
57
|
"@sveltejs/package": "^2.5.7",
|
|
58
|
-
"@sveltejs/vite-plugin-svelte": "^7.
|
|
58
|
+
"@sveltejs/vite-plugin-svelte": "^7.1.2",
|
|
59
59
|
"eslint-plugin-svelte": "^3.17.1",
|
|
60
60
|
"svelte": "^5.55.5",
|
|
61
|
-
"svelte-check": "^4.4.
|
|
61
|
+
"svelte-check": "^4.4.8"
|
|
62
62
|
},
|
|
63
63
|
"peerDependencies": {
|
|
64
64
|
"svelte": "^5.0.0"
|
|
@@ -27,6 +27,31 @@ export type SvelteTable<
|
|
|
27
27
|
readonly state: Readonly<TSelected>
|
|
28
28
|
}
|
|
29
29
|
|
|
30
|
+
/**
|
|
31
|
+
* Creates a Svelte 5 table instance backed by rune-aware TanStack Store atoms.
|
|
32
|
+
*
|
|
33
|
+
* The optional selector projects from `table.store`; the selected value is
|
|
34
|
+
* exposed on `table.state`. The adapter syncs options in `$effect.pre`, so
|
|
35
|
+
* reactive option getters and external `$state` values are applied before DOM
|
|
36
|
+
* updates read table APIs such as `getRowModel()`.
|
|
37
|
+
*
|
|
38
|
+
* @example
|
|
39
|
+
* ```svelte
|
|
40
|
+
* <script lang="ts">
|
|
41
|
+
* const table = createTable(
|
|
42
|
+
* {
|
|
43
|
+
* _features,
|
|
44
|
+
* _rowModels: {},
|
|
45
|
+
* columns,
|
|
46
|
+
* data,
|
|
47
|
+
* },
|
|
48
|
+
* (state) => ({ pagination: state.pagination }),
|
|
49
|
+
* )
|
|
50
|
+
* </script>
|
|
51
|
+
*
|
|
52
|
+
* {table.state.pagination.pageIndex}
|
|
53
|
+
* ```
|
|
54
|
+
*/
|
|
30
55
|
export function createTable<
|
|
31
56
|
TFeatures extends TableFeatures,
|
|
32
57
|
TData extends RowData,
|
|
@@ -1,5 +1,20 @@
|
|
|
1
1
|
import type { Updater } from '@tanstack/table-core'
|
|
2
2
|
|
|
3
|
+
/**
|
|
4
|
+
* Creates a small Svelte 5 state holder that accepts TanStack Table updaters.
|
|
5
|
+
*
|
|
6
|
+
* This is useful when a table state slice should be owned outside the table
|
|
7
|
+
* with `$state`, but still needs to accept both value and functional updater
|
|
8
|
+
* forms from `on[State]Change` callbacks.
|
|
9
|
+
*
|
|
10
|
+
* @example
|
|
11
|
+
* ```ts
|
|
12
|
+
* const [pagination, setPagination] = createTableState({
|
|
13
|
+
* pageIndex: 0,
|
|
14
|
+
* pageSize: 10,
|
|
15
|
+
* })
|
|
16
|
+
* ```
|
|
17
|
+
*/
|
|
3
18
|
export function createTableState<TState>(
|
|
4
19
|
initialValue: TState,
|
|
5
20
|
): [() => TState, (updater: Updater<TState>) => void] {
|
package/src/reactivity.svelte.ts
CHANGED
|
@@ -28,9 +28,17 @@ function subscribeToRune<T>(
|
|
|
28
28
|
return { unsubscribe }
|
|
29
29
|
}
|
|
30
30
|
|
|
31
|
+
/**
|
|
32
|
+
* Creates the table-core reactivity bindings used by the Svelte adapter.
|
|
33
|
+
*
|
|
34
|
+
* Readonly table atoms are backed by `$derived.by`, writable atoms by `$state`,
|
|
35
|
+
* and subscriptions bridge through rune effects so table APIs participate in
|
|
36
|
+
* Svelte dependency tracking.
|
|
37
|
+
*/
|
|
31
38
|
export function svelteReactivity(): TableReactivityBindings {
|
|
32
39
|
return {
|
|
33
40
|
createOptionsStore: true,
|
|
41
|
+
schedule: (fn) => queueMicrotask(() => fn()),
|
|
34
42
|
createReadonlyAtom: <T>(fn: () => T, _options?: TableAtomOptions<T>) => {
|
|
35
43
|
const value = $derived.by(fn)
|
|
36
44
|
|
package/src/render-component.ts
CHANGED
|
@@ -46,7 +46,8 @@ export class RenderSnippetConfig<TProps> {
|
|
|
46
46
|
}
|
|
47
47
|
|
|
48
48
|
/**
|
|
49
|
-
*
|
|
49
|
+
* Wraps a Svelte component so it can be returned from a column definition
|
|
50
|
+
* renderer such as `cell`, `header`, or `footer`.
|
|
50
51
|
*
|
|
51
52
|
* This is only to be used with Svelte Components - use `renderSnippet` for Svelte Snippets.
|
|
52
53
|
*
|
|
@@ -76,15 +77,16 @@ export const renderComponent = <
|
|
|
76
77
|
) => new RenderComponentConfig(component, props)
|
|
77
78
|
|
|
78
79
|
/**
|
|
79
|
-
*
|
|
80
|
+
* Wraps a Svelte snippet so it can be returned from a column definition
|
|
81
|
+
* renderer such as `cell`, `header`, or `footer`.
|
|
80
82
|
*
|
|
81
83
|
* *The snippet must only take one parameter.*
|
|
82
84
|
*
|
|
83
85
|
* This is only to be used with Snippets - use `renderComponent` for Svelte Components.
|
|
84
86
|
*
|
|
85
|
-
* @param snippet
|
|
86
|
-
* @param params
|
|
87
|
-
* @returns
|
|
87
|
+
* @param snippet The snippet to render.
|
|
88
|
+
* @param params The single parameter object passed to the snippet.
|
|
89
|
+
* @returns A `RenderSnippetConfig` consumed by the Svelte `FlexRender` component.
|
|
88
90
|
* @example
|
|
89
91
|
* ```ts
|
|
90
92
|
* // +page.svelte
|
package/src/subscribe.ts
CHANGED
|
@@ -13,8 +13,23 @@ export type SubscribeSource<TValue> =
|
|
|
13
13
|
| ReadonlyStore<TValue>
|
|
14
14
|
|
|
15
15
|
/**
|
|
16
|
-
*
|
|
17
|
-
*
|
|
16
|
+
* Creates a fine-grained Svelte subscription to a TanStack Store source.
|
|
17
|
+
*
|
|
18
|
+
* Pass a table atom or store and optionally project it with a selector. The
|
|
19
|
+
* returned selector store exposes `.current`, making it useful for reading
|
|
20
|
+
* focused table state outside the broad `createTable` selector.
|
|
21
|
+
*
|
|
22
|
+
* @example
|
|
23
|
+
* ```svelte
|
|
24
|
+
* <script lang="ts">
|
|
25
|
+
* const selected = subscribeTable(
|
|
26
|
+
* table.atoms.rowSelection,
|
|
27
|
+
* (rowSelection) => rowSelection[row.id],
|
|
28
|
+
* )
|
|
29
|
+
* </script>
|
|
30
|
+
*
|
|
31
|
+
* <input type="checkbox" checked={!!selected.current} />
|
|
32
|
+
* ```
|
|
18
33
|
*/
|
|
19
34
|
export function subscribeTable<TSourceValue>(
|
|
20
35
|
source: SubscribeSource<TSourceValue>,
|