@tanstack/svelte-table 9.0.0-alpha.43 → 9.0.0-alpha.45

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.
@@ -1,5 +1,5 @@
1
1
  import type { RowData, Table, TableFeatures, TableOptions, TableState } from '@tanstack/table-core';
2
- export type SvelteTable<TFeatures extends TableFeatures, TData extends RowData, TSelected = {}> = Table<TFeatures, TData> & {
2
+ export type SvelteTable<TFeatures extends TableFeatures, TData extends RowData, TSelected = TableState<TFeatures>> = Table<TFeatures, TData> & {
3
3
  /**
4
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`.
5
5
  *
@@ -10,4 +10,4 @@ export type SvelteTable<TFeatures extends TableFeatures, TData extends RowData,
10
10
  */
11
11
  readonly state: Readonly<TSelected>;
12
12
  };
13
- export declare function createTable<TFeatures extends TableFeatures, TData extends RowData, TSelected = {}>(tableOptions: TableOptions<TFeatures, TData>, selector?: (state: TableState<TFeatures>) => TSelected): SvelteTable<TFeatures, TData, TSelected>;
13
+ 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,7 +3,7 @@ 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
- export function createTable(tableOptions, selector = () => ({})) {
6
+ export function createTable(tableOptions, selector) {
7
7
  // 1. Merge reactivity into options using mergeObjects (preserves getters)
8
8
  const mergedOptions = mergeObjects(tableOptions, {
9
9
  _features: {
@@ -228,7 +228,7 @@ export type AppSvelteTable<TFeatures extends TableFeatures, TData extends RowDat
228
228
  export declare function createTableHook<TFeatures extends TableFeatures, const TTableComponents extends Record<string, ComponentType<any>>, const TCellComponents extends Record<string, ComponentType<any>>, const THeaderComponents extends Record<string, ComponentType<any>>>({ tableComponents, cellComponents, headerComponents, ...defaultTableOptions }: CreateTableHookOptions<TFeatures, TTableComponents, TCellComponents, THeaderComponents>): {
229
229
  appFeatures: TFeatures;
230
230
  createAppColumnHelper: <TData extends RowData>() => AppColumnHelper<TFeatures, TData, TCellComponents, THeaderComponents>;
231
- createAppTable: <TData extends RowData, TSelected = {}>(tableOptions: Omit<TableOptions<TFeatures, TData>, "_features" | "_rowModels">, selector?: (state: TableState<TFeatures>) => TSelected) => AppSvelteTable<TFeatures, TData, TSelected, TTableComponents, TCellComponents, THeaderComponents>;
231
+ createAppTable: <TData extends RowData, TSelected = TableState<TFeatures>>(tableOptions: Omit<TableOptions<TFeatures, TData>, "_features" | "_rowModels">, selector?: (state: TableState<TFeatures>) => TSelected) => AppSvelteTable<TFeatures, TData, TSelected, TTableComponents, TCellComponents, THeaderComponents>;
232
232
  useTableContext: <TData extends RowData = RowData>() => SvelteTable<TFeatures, TData>;
233
233
  useCellContext: <TValue extends CellData = unknown>() => Cell<TFeatures, any, TValue>;
234
234
  useHeaderContext: <TValue extends CellData = unknown>() => Header<TFeatures, any, TValue>;
package/dist/index.d.ts CHANGED
@@ -5,5 +5,5 @@ export { createTableHook } from './createTableHook.svelte';
5
5
  export type { AppCellContext, AppColumnDefBase, AppColumnDefTemplate, AppColumnHelper, AppDisplayColumnDef, AppGroupColumnDef, AppHeaderContext, AppSvelteTable, ComponentType, CreateTableHookOptions, } from './createTableHook.svelte';
6
6
  export { createTableState } from './createTableState.svelte';
7
7
  export { default as FlexRender } from './FlexRender.svelte';
8
- export { subscribeTable } from './subscribe';
8
+ export { subscribeTable, type SubscribeSource } from './subscribe';
9
9
  export { renderComponent, renderSnippet } from './render-component';
@@ -1,9 +1,9 @@
1
- import type { RowData, Table, TableFeatures, TableState } from '@tanstack/table-core';
1
+ import { useSelector } from '@tanstack/svelte-store';
2
+ import type { Atom, ReadonlyAtom, ReadonlyStore, Store } from '@tanstack/svelte-store';
3
+ export type SubscribeSource<TValue> = Atom<TValue> | ReadonlyAtom<TValue> | Store<TValue> | ReadonlyStore<TValue>;
2
4
  /**
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`).
5
+ * Fine-grained subscription to a source using `useSelector` with shallow
6
+ * comparison. Omit `selector` to subscribe to the source value directly.
6
7
  */
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
- };
8
+ export declare function subscribeTable<TSourceValue>(source: SubscribeSource<TSourceValue>): ReturnType<typeof useSelector<TSourceValue>>;
9
+ export declare function subscribeTable<TSourceValue, TSelected>(source: SubscribeSource<TSourceValue>, selector: (state: TSourceValue) => TSelected): ReturnType<typeof useSelector<TSourceValue, TSelected>>;
package/dist/subscribe.js CHANGED
@@ -1,9 +1,4 @@
1
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 });
2
+ export function subscribeTable(source, selector) {
3
+ return useSelector(source, selector, { compare: shallow });
9
4
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tanstack/svelte-table",
3
- "version": "9.0.0-alpha.43",
3
+ "version": "9.0.0-alpha.45",
4
4
  "description": "Headless UI for building powerful tables & datagrids for Svelte.",
5
5
  "author": "Tanner Linsley",
6
6
  "license": "MIT",
@@ -14,7 +14,7 @@ import type {
14
14
  export type SvelteTable<
15
15
  TFeatures extends TableFeatures,
16
16
  TData extends RowData,
17
- TSelected = {},
17
+ TSelected = TableState<TFeatures>,
18
18
  > = Table<TFeatures, TData> & {
19
19
  /**
20
20
  * 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`.
@@ -30,11 +30,10 @@ export type SvelteTable<
30
30
  export function createTable<
31
31
  TFeatures extends TableFeatures,
32
32
  TData extends RowData,
33
- TSelected = {},
33
+ TSelected = TableState<TFeatures>,
34
34
  >(
35
35
  tableOptions: TableOptions<TFeatures, TData>,
36
- selector: (state: TableState<TFeatures>) => TSelected = () =>
37
- ({}) as TSelected,
36
+ selector?: (state: TableState<TFeatures>) => TSelected,
38
37
  ): SvelteTable<TFeatures, TData, TSelected> {
39
38
  // 1. Merge reactivity into options using mergeObjects (preserves getters)
40
39
  const mergedOptions = mergeObjects(tableOptions, {
@@ -523,7 +523,10 @@ export function createTableHook<
523
523
  *
524
524
  * TFeatures is already known from the createTableHook call; TData is inferred from the data prop.
525
525
  */
526
- function createAppTable<TData extends RowData, TSelected = {}>(
526
+ function createAppTable<
527
+ TData extends RowData,
528
+ TSelected = TableState<TFeatures>,
529
+ >(
527
530
  tableOptions: Omit<
528
531
  TableOptions<TFeatures, TData>,
529
532
  '_features' | '_rowModels'
package/src/index.ts CHANGED
@@ -17,5 +17,5 @@ export type {
17
17
  } from './createTableHook.svelte'
18
18
  export { createTableState } from './createTableState.svelte'
19
19
  export { default as FlexRender } from './FlexRender.svelte'
20
- export { subscribeTable } from './subscribe'
20
+ export { subscribeTable, type SubscribeSource } from './subscribe'
21
21
  export { renderComponent, renderSnippet } from './render-component'
package/src/subscribe.ts CHANGED
@@ -1,23 +1,31 @@
1
1
  import { shallow, useSelector } from '@tanstack/svelte-store'
2
2
  import type {
3
- RowData,
4
- Table,
5
- TableFeatures,
6
- TableState,
7
- } from '@tanstack/table-core'
3
+ Atom,
4
+ ReadonlyAtom,
5
+ ReadonlyStore,
6
+ Store,
7
+ } from '@tanstack/svelte-store'
8
+
9
+ export type SubscribeSource<TValue> =
10
+ | Atom<TValue>
11
+ | ReadonlyAtom<TValue>
12
+ | Store<TValue>
13
+ | ReadonlyStore<TValue>
8
14
 
9
15
  /**
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`).
16
+ * Fine-grained subscription to a source using `useSelector` with shallow
17
+ * comparison. Omit `selector` to subscribe to the source value directly.
13
18
  */
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,
19
+ export function subscribeTable<TSourceValue>(
20
+ source: SubscribeSource<TSourceValue>,
21
+ ): ReturnType<typeof useSelector<TSourceValue>>
22
+ export function subscribeTable<TSourceValue, TSelected>(
23
+ source: SubscribeSource<TSourceValue>,
24
+ selector: (state: TSourceValue) => TSelected,
25
+ ): ReturnType<typeof useSelector<TSourceValue, TSelected>>
26
+ export function subscribeTable<TSourceValue, TSelected>(
27
+ source: SubscribeSource<TSourceValue>,
28
+ selector?: (state: TSourceValue) => TSelected,
21
29
  ) {
22
- return useSelector(table.store, selector, { compare: shallow })
30
+ return useSelector(source, selector, { compare: shallow })
23
31
  }