@tanstack/svelte-table 9.0.0-alpha.33 → 9.0.0-alpha.36
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 +1 -20
- package/dist/createTable.svelte.js +1 -9
- package/dist/flex-render.d.ts +1 -0
- package/dist/flex-render.js +2 -0
- package/dist/index.d.ts +1 -1
- package/dist/index.js +1 -1
- package/dist/static-functions.d.ts +1 -0
- package/dist/static-functions.js +1 -0
- package/dist/subscribe.d.ts +9 -0
- package/dist/subscribe.js +9 -0
- package/package.json +12 -2
- package/src/createTable.svelte.ts +2 -34
- package/src/flex-render.ts +3 -0
- package/src/index.ts +1 -1
- package/src/static-functions.ts +1 -0
- package/src/subscribe.ts +23 -0
- package/dist/Subscribe.svelte +0 -45
- package/dist/Subscribe.svelte.d.ts +0 -44
- package/src/Subscribe.svelte +0 -45
|
@@ -1,24 +1,5 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
import type { Snippet } from 'svelte';
|
|
1
|
+
import type { RowData, Table, TableFeatures, TableOptions, TableState } from '@tanstack/table-core';
|
|
3
2
|
export type SvelteTable<TFeatures extends TableFeatures, TData extends RowData, TSelected = {}> = Table<TFeatures, TData> & {
|
|
4
|
-
/**
|
|
5
|
-
* A Svelte component that allows you to subscribe to the table state.
|
|
6
|
-
*
|
|
7
|
-
* This is useful for opting into state subscriptions for specific parts of the table state.
|
|
8
|
-
*
|
|
9
|
-
* @example
|
|
10
|
-
* <table.Subscribe selector={(state) => ({ rowSelection: state.rowSelection })}>
|
|
11
|
-
* {(state) => (
|
|
12
|
-
* <tr>
|
|
13
|
-
* // render the row
|
|
14
|
-
* </tr>
|
|
15
|
-
* )}
|
|
16
|
-
* </table.Subscribe>
|
|
17
|
-
*/
|
|
18
|
-
Subscribe: <TSelected>(props: {
|
|
19
|
-
selector: (state: NoInfer<TableState<TFeatures>>) => TSelected;
|
|
20
|
-
children: ((state: Readonly<TSelected>) => Snippet) | Snippet;
|
|
21
|
-
}) => any;
|
|
22
3
|
/**
|
|
23
4
|
* The selected state of the table. This state may not match the structure of `table.store.state` because it is selected by the `selector` function that you pass as the 2nd argument to `createTable`.
|
|
24
5
|
*
|
|
@@ -61,15 +61,7 @@ export function createTable(tableOptions, selector = () => ({})) {
|
|
|
61
61
|
});
|
|
62
62
|
});
|
|
63
63
|
});
|
|
64
|
-
// 9.
|
|
65
|
-
table.Subscribe = function Subscribe(props) {
|
|
66
|
-
const selected = useSelector(table.store, props.selector);
|
|
67
|
-
if (typeof props.children === 'function') {
|
|
68
|
-
return props.children(selected.current);
|
|
69
|
-
}
|
|
70
|
-
return props.children;
|
|
71
|
-
};
|
|
72
|
-
// 10. State selector
|
|
64
|
+
// 9. State selector
|
|
73
65
|
const stateStore = useSelector(table.store, selector);
|
|
74
66
|
Object.defineProperty(table, 'state', {
|
|
75
67
|
get() {
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { default as FlexRender } from './FlexRender.svelte';
|
package/dist/index.d.ts
CHANGED
|
@@ -5,5 +5,5 @@ export { createTableHook } from './createTableHook.svelte';
|
|
|
5
5
|
export type { AppCellContext, AppColumnHelper, AppHeaderContext, AppSvelteTable, CreateTableHookOptions, } from './createTableHook.svelte';
|
|
6
6
|
export { createTableState } from './createTableState.svelte';
|
|
7
7
|
export { default as FlexRender } from './FlexRender.svelte';
|
|
8
|
-
export {
|
|
8
|
+
export { subscribeTable } from './subscribe';
|
|
9
9
|
export { renderComponent, renderSnippet } from './render-component';
|
package/dist/index.js
CHANGED
|
@@ -3,5 +3,5 @@ export { createTable } from './createTable.svelte';
|
|
|
3
3
|
export { createTableHook } from './createTableHook.svelte';
|
|
4
4
|
export { createTableState } from './createTableState.svelte';
|
|
5
5
|
export { default as FlexRender } from './FlexRender.svelte';
|
|
6
|
-
export {
|
|
6
|
+
export { subscribeTable } from './subscribe';
|
|
7
7
|
export { renderComponent, renderSnippet } from './render-component';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from '@tanstack/table-core/static-functions';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from '@tanstack/table-core/static-functions';
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import type { RowData, Table, TableFeatures, TableState } from '@tanstack/table-core';
|
|
2
|
+
/**
|
|
3
|
+
* Fine-grained subscription to `table.store` using `useSelector` with shallow
|
|
4
|
+
* comparison. Call from `<script>` so the selector is contextually typed
|
|
5
|
+
* (same inference model as React’s `Subscribe` / `table.Subscribe`).
|
|
6
|
+
*/
|
|
7
|
+
export declare function subscribeTable<TFeatures extends TableFeatures, TData extends RowData, TSelected>(table: Table<TFeatures, TData>, selector: (state: TableState<TFeatures>) => TSelected): {
|
|
8
|
+
readonly current: TSelected;
|
|
9
|
+
};
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { shallow, useSelector } from '@tanstack/svelte-store';
|
|
2
|
+
/**
|
|
3
|
+
* Fine-grained subscription to `table.store` using `useSelector` with shallow
|
|
4
|
+
* comparison. Call from `<script>` so the selector is contextually typed
|
|
5
|
+
* (same inference model as React’s `Subscribe` / `table.Subscribe`).
|
|
6
|
+
*/
|
|
7
|
+
export function subscribeTable(table, selector) {
|
|
8
|
+
return useSelector(table.store, selector, { compare: shallow });
|
|
9
|
+
}
|
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.36",
|
|
4
4
|
"description": "Headless UI for building powerful tables & datagrids for Svelte.",
|
|
5
5
|
"author": "Tanner Linsley",
|
|
6
6
|
"license": "MIT",
|
|
@@ -30,6 +30,16 @@
|
|
|
30
30
|
"svelte": "./dist/index.js",
|
|
31
31
|
"import": "./dist/index.js"
|
|
32
32
|
},
|
|
33
|
+
"./static-functions": {
|
|
34
|
+
"types": "./dist/static-functions.d.ts",
|
|
35
|
+
"svelte": "./dist/static-functions.js",
|
|
36
|
+
"import": "./dist/static-functions.js"
|
|
37
|
+
},
|
|
38
|
+
"./flex-render": {
|
|
39
|
+
"types": "./dist/flex-render.d.ts",
|
|
40
|
+
"svelte": "./dist/flex-render.js",
|
|
41
|
+
"import": "./dist/flex-render.js"
|
|
42
|
+
},
|
|
33
43
|
"./package.json": "./package.json"
|
|
34
44
|
},
|
|
35
45
|
"engines": {
|
|
@@ -41,7 +51,7 @@
|
|
|
41
51
|
],
|
|
42
52
|
"dependencies": {
|
|
43
53
|
"@tanstack/svelte-store": "^0.12.0",
|
|
44
|
-
"@tanstack/table-core": "9.0.0-alpha.
|
|
54
|
+
"@tanstack/table-core": "9.0.0-alpha.36"
|
|
45
55
|
},
|
|
46
56
|
"devDependencies": {
|
|
47
57
|
"@sveltejs/package": "^2.5.7",
|
|
@@ -2,42 +2,22 @@ import {
|
|
|
2
2
|
constructReactivityFeature,
|
|
3
3
|
constructTable,
|
|
4
4
|
} from '@tanstack/table-core'
|
|
5
|
-
import { useSelector } from '@tanstack/svelte-store'
|
|
5
|
+
import { shallow, useSelector } from '@tanstack/svelte-store'
|
|
6
6
|
import { untrack } from 'svelte'
|
|
7
7
|
import { mergeObjects } from './merge-objects'
|
|
8
8
|
import type {
|
|
9
|
-
NoInfer,
|
|
10
9
|
RowData,
|
|
11
10
|
Table,
|
|
12
11
|
TableFeatures,
|
|
13
12
|
TableOptions,
|
|
14
13
|
TableState,
|
|
15
14
|
} from '@tanstack/table-core'
|
|
16
|
-
import type { Snippet } from 'svelte'
|
|
17
15
|
|
|
18
16
|
export type SvelteTable<
|
|
19
17
|
TFeatures extends TableFeatures,
|
|
20
18
|
TData extends RowData,
|
|
21
19
|
TSelected = {},
|
|
22
20
|
> = Table<TFeatures, TData> & {
|
|
23
|
-
/**
|
|
24
|
-
* A Svelte component that allows you to subscribe to the table state.
|
|
25
|
-
*
|
|
26
|
-
* This is useful for opting into state subscriptions for specific parts of the table state.
|
|
27
|
-
*
|
|
28
|
-
* @example
|
|
29
|
-
* <table.Subscribe selector={(state) => ({ rowSelection: state.rowSelection })}>
|
|
30
|
-
* {(state) => (
|
|
31
|
-
* <tr>
|
|
32
|
-
* // render the row
|
|
33
|
-
* </tr>
|
|
34
|
-
* )}
|
|
35
|
-
* </table.Subscribe>
|
|
36
|
-
*/
|
|
37
|
-
Subscribe: <TSelected>(props: {
|
|
38
|
-
selector: (state: NoInfer<TableState<TFeatures>>) => TSelected
|
|
39
|
-
children: ((state: Readonly<TSelected>) => Snippet) | Snippet
|
|
40
|
-
}) => any
|
|
41
21
|
/**
|
|
42
22
|
* The selected state of the table. This state may not match the structure of `table.store.state` because it is selected by the `selector` function that you pass as the 2nd argument to `createTable`.
|
|
43
23
|
*
|
|
@@ -138,19 +118,7 @@ export function createTable<
|
|
|
138
118
|
})
|
|
139
119
|
})
|
|
140
120
|
|
|
141
|
-
// 9.
|
|
142
|
-
table.Subscribe = function Subscribe<TSel>(props: {
|
|
143
|
-
selector: (state: TableState<TFeatures>) => TSel
|
|
144
|
-
children: ((state: Readonly<TSel>) => Snippet) | Snippet
|
|
145
|
-
}): any {
|
|
146
|
-
const selected = useSelector(table.store, props.selector)
|
|
147
|
-
if (typeof props.children === 'function') {
|
|
148
|
-
return props.children(selected.current)
|
|
149
|
-
}
|
|
150
|
-
return props.children
|
|
151
|
-
}
|
|
152
|
-
|
|
153
|
-
// 10. State selector
|
|
121
|
+
// 9. State selector
|
|
154
122
|
const stateStore = useSelector(table.store, selector)
|
|
155
123
|
|
|
156
124
|
Object.defineProperty(table, 'state', {
|
package/src/index.ts
CHANGED
|
@@ -12,5 +12,5 @@ export type {
|
|
|
12
12
|
} from './createTableHook.svelte'
|
|
13
13
|
export { createTableState } from './createTableState.svelte'
|
|
14
14
|
export { default as FlexRender } from './FlexRender.svelte'
|
|
15
|
-
export {
|
|
15
|
+
export { subscribeTable } from './subscribe'
|
|
16
16
|
export { renderComponent, renderSnippet } from './render-component'
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from '@tanstack/table-core/static-functions'
|
package/src/subscribe.ts
ADDED
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { shallow, useSelector } from '@tanstack/svelte-store'
|
|
2
|
+
import type {
|
|
3
|
+
RowData,
|
|
4
|
+
Table,
|
|
5
|
+
TableFeatures,
|
|
6
|
+
TableState,
|
|
7
|
+
} from '@tanstack/table-core'
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* Fine-grained subscription to `table.store` using `useSelector` with shallow
|
|
11
|
+
* comparison. Call from `<script>` so the selector is contextually typed
|
|
12
|
+
* (same inference model as React’s `Subscribe` / `table.Subscribe`).
|
|
13
|
+
*/
|
|
14
|
+
export function subscribeTable<
|
|
15
|
+
TFeatures extends TableFeatures,
|
|
16
|
+
TData extends RowData,
|
|
17
|
+
TSelected,
|
|
18
|
+
>(
|
|
19
|
+
table: Table<TFeatures, TData>,
|
|
20
|
+
selector: (state: TableState<TFeatures>) => TSelected,
|
|
21
|
+
) {
|
|
22
|
+
return useSelector(table.store, selector, { compare: shallow })
|
|
23
|
+
}
|
package/dist/Subscribe.svelte
DELETED
|
@@ -1,45 +0,0 @@
|
|
|
1
|
-
<script
|
|
2
|
-
lang="ts"
|
|
3
|
-
generics="TFeatures extends TableFeatures, TData extends RowData, TSelected = unknown"
|
|
4
|
-
>
|
|
5
|
-
import type {
|
|
6
|
-
NoInfer,
|
|
7
|
-
RowData,
|
|
8
|
-
TableFeatures,
|
|
9
|
-
TableState,
|
|
10
|
-
} from '@tanstack/table-core'
|
|
11
|
-
import type { Snippet } from 'svelte'
|
|
12
|
-
import type { SvelteTable } from './createTable.svelte'
|
|
13
|
-
|
|
14
|
-
type Props<
|
|
15
|
-
TFeatures extends TableFeatures,
|
|
16
|
-
TData extends RowData,
|
|
17
|
-
TSelected,
|
|
18
|
-
> = {
|
|
19
|
-
/**
|
|
20
|
-
* A function that selects a portion of the table state to subscribe to.
|
|
21
|
-
* @param state - The full table state
|
|
22
|
-
* @returns The selected portion of state
|
|
23
|
-
*/
|
|
24
|
-
selector: (state: NoInfer<TableState<TFeatures>>) => TSelected
|
|
25
|
-
/**
|
|
26
|
-
* A Svelte snippet that receives the selected state and renders content.
|
|
27
|
-
* The snippet will be called with the selected state whenever it changes.
|
|
28
|
-
*/
|
|
29
|
-
children: Snippet<[state: Readonly<TSelected>]>
|
|
30
|
-
/**
|
|
31
|
-
* The table instance to subscribe to
|
|
32
|
-
*/
|
|
33
|
-
table: SvelteTable<TFeatures, TData, unknown>
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
let { table, selector, children }: Props<TFeatures, TData, TSelected> =
|
|
37
|
-
$props()
|
|
38
|
-
</script>
|
|
39
|
-
|
|
40
|
-
<!--
|
|
41
|
-
Access table.store.state in the template (a reactive context).
|
|
42
|
-
The constructReactivityFeature interceptor makes this trigger
|
|
43
|
-
the $state-based notifier, so Svelte tracks it automatically.
|
|
44
|
-
-->
|
|
45
|
-
{@render children(selector(table.store.state as TableState<TFeatures>))}
|
|
@@ -1,44 +0,0 @@
|
|
|
1
|
-
import type { NoInfer, RowData, TableFeatures, TableState } from '@tanstack/table-core';
|
|
2
|
-
import type { Snippet } from 'svelte';
|
|
3
|
-
import type { SvelteTable } from './createTable.svelte';
|
|
4
|
-
type Props<TFeatures extends TableFeatures, TData extends RowData, TSelected> = {
|
|
5
|
-
/**
|
|
6
|
-
* A function that selects a portion of the table state to subscribe to.
|
|
7
|
-
* @param state - The full table state
|
|
8
|
-
* @returns The selected portion of state
|
|
9
|
-
*/
|
|
10
|
-
selector: (state: NoInfer<TableState<TFeatures>>) => TSelected;
|
|
11
|
-
/**
|
|
12
|
-
* A Svelte snippet that receives the selected state and renders content.
|
|
13
|
-
* The snippet will be called with the selected state whenever it changes.
|
|
14
|
-
*/
|
|
15
|
-
children: Snippet<[state: Readonly<TSelected>]>;
|
|
16
|
-
/**
|
|
17
|
-
* The table instance to subscribe to
|
|
18
|
-
*/
|
|
19
|
-
table: SvelteTable<TFeatures, TData, unknown>;
|
|
20
|
-
};
|
|
21
|
-
declare function $$render<TFeatures extends TableFeatures, TData extends RowData, TSelected = unknown>(): {
|
|
22
|
-
props: Props<TFeatures, TData, TSelected>;
|
|
23
|
-
exports: {};
|
|
24
|
-
bindings: "";
|
|
25
|
-
slots: {};
|
|
26
|
-
events: {};
|
|
27
|
-
};
|
|
28
|
-
declare class __sveltets_Render<TFeatures extends TableFeatures, TData extends RowData, TSelected = unknown> {
|
|
29
|
-
props(): ReturnType<typeof $$render<TFeatures, TData, TSelected>>['props'];
|
|
30
|
-
events(): ReturnType<typeof $$render<TFeatures, TData, TSelected>>['events'];
|
|
31
|
-
slots(): ReturnType<typeof $$render<TFeatures, TData, TSelected>>['slots'];
|
|
32
|
-
bindings(): "";
|
|
33
|
-
exports(): {};
|
|
34
|
-
}
|
|
35
|
-
interface $$IsomorphicComponent {
|
|
36
|
-
new <TFeatures extends TableFeatures, TData extends RowData, TSelected = unknown>(options: import('svelte').ComponentConstructorOptions<ReturnType<__sveltets_Render<TFeatures, TData, TSelected>['props']>>): import('svelte').SvelteComponent<ReturnType<__sveltets_Render<TFeatures, TData, TSelected>['props']>, ReturnType<__sveltets_Render<TFeatures, TData, TSelected>['events']>, ReturnType<__sveltets_Render<TFeatures, TData, TSelected>['slots']>> & {
|
|
37
|
-
$$bindings?: ReturnType<__sveltets_Render<TFeatures, TData, TSelected>['bindings']>;
|
|
38
|
-
} & ReturnType<__sveltets_Render<TFeatures, TData, TSelected>['exports']>;
|
|
39
|
-
<TFeatures extends TableFeatures, TData extends RowData, TSelected = unknown>(internal: unknown, props: ReturnType<__sveltets_Render<TFeatures, TData, TSelected>['props']> & {}): ReturnType<__sveltets_Render<TFeatures, TData, TSelected>['exports']>;
|
|
40
|
-
z_$$bindings?: ReturnType<__sveltets_Render<any, any, any>['bindings']>;
|
|
41
|
-
}
|
|
42
|
-
declare const Subscribe: $$IsomorphicComponent;
|
|
43
|
-
type Subscribe<TFeatures extends TableFeatures, TData extends RowData, TSelected = unknown> = InstanceType<typeof Subscribe<TFeatures, TData, TSelected>>;
|
|
44
|
-
export default Subscribe;
|
package/src/Subscribe.svelte
DELETED
|
@@ -1,45 +0,0 @@
|
|
|
1
|
-
<script
|
|
2
|
-
lang="ts"
|
|
3
|
-
generics="TFeatures extends TableFeatures, TData extends RowData, TSelected = unknown"
|
|
4
|
-
>
|
|
5
|
-
import type {
|
|
6
|
-
NoInfer,
|
|
7
|
-
RowData,
|
|
8
|
-
TableFeatures,
|
|
9
|
-
TableState,
|
|
10
|
-
} from '@tanstack/table-core'
|
|
11
|
-
import type { Snippet } from 'svelte'
|
|
12
|
-
import type { SvelteTable } from './createTable.svelte'
|
|
13
|
-
|
|
14
|
-
type Props<
|
|
15
|
-
TFeatures extends TableFeatures,
|
|
16
|
-
TData extends RowData,
|
|
17
|
-
TSelected,
|
|
18
|
-
> = {
|
|
19
|
-
/**
|
|
20
|
-
* A function that selects a portion of the table state to subscribe to.
|
|
21
|
-
* @param state - The full table state
|
|
22
|
-
* @returns The selected portion of state
|
|
23
|
-
*/
|
|
24
|
-
selector: (state: NoInfer<TableState<TFeatures>>) => TSelected
|
|
25
|
-
/**
|
|
26
|
-
* A Svelte snippet that receives the selected state and renders content.
|
|
27
|
-
* The snippet will be called with the selected state whenever it changes.
|
|
28
|
-
*/
|
|
29
|
-
children: Snippet<[state: Readonly<TSelected>]>
|
|
30
|
-
/**
|
|
31
|
-
* The table instance to subscribe to
|
|
32
|
-
*/
|
|
33
|
-
table: SvelteTable<TFeatures, TData, unknown>
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
let { table, selector, children }: Props<TFeatures, TData, TSelected> =
|
|
37
|
-
$props()
|
|
38
|
-
</script>
|
|
39
|
-
|
|
40
|
-
<!--
|
|
41
|
-
Access table.store.state in the template (a reactive context).
|
|
42
|
-
The constructReactivityFeature interceptor makes this trigger
|
|
43
|
-
the $state-based notifier, so Svelte tracks it automatically.
|
|
44
|
-
-->
|
|
45
|
-
{@render children(selector(table.store.state as TableState<TFeatures>))}
|