@tanstack/svelte-table 9.0.0-alpha.4 → 9.0.0-alpha.42

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.
Files changed (53) hide show
  1. package/README.md +117 -0
  2. package/dist/AppCell.svelte +13 -0
  3. package/dist/AppCell.svelte.d.ts +9 -0
  4. package/dist/AppHeader.svelte +13 -0
  5. package/dist/AppHeader.svelte.d.ts +9 -0
  6. package/dist/AppTable.svelte +11 -0
  7. package/dist/AppTable.svelte.d.ts +7 -0
  8. package/dist/FlexRender.svelte +103 -0
  9. package/dist/FlexRender.svelte.d.ts +51 -0
  10. package/dist/context-keys.d.ts +3 -0
  11. package/dist/context-keys.js +3 -0
  12. package/dist/createTable.svelte.d.ts +13 -0
  13. package/dist/createTable.svelte.js +54 -0
  14. package/dist/createTableHook.svelte.d.ts +235 -0
  15. package/dist/createTableHook.svelte.js +170 -0
  16. package/dist/createTableState.svelte.d.ts +2 -0
  17. package/dist/createTableState.svelte.js +12 -0
  18. package/dist/flex-render.d.ts +1 -0
  19. package/dist/flex-render.js +2 -0
  20. package/dist/index.d.ts +8 -3
  21. package/dist/index.js +6 -3
  22. package/dist/merge-objects.d.ts +8 -0
  23. package/dist/merge-objects.js +29 -0
  24. package/dist/reactivity.svelte.d.ts +2 -0
  25. package/dist/reactivity.svelte.js +45 -0
  26. package/dist/render-component.d.ts +64 -9
  27. package/dist/render-component.js +60 -4
  28. package/dist/static-functions.d.ts +1 -0
  29. package/dist/static-functions.js +1 -0
  30. package/dist/subscribe.d.ts +9 -0
  31. package/dist/subscribe.js +9 -0
  32. package/package.json +27 -9
  33. package/src/AppCell.svelte +13 -0
  34. package/src/AppHeader.svelte +13 -0
  35. package/src/AppTable.svelte +11 -0
  36. package/src/FlexRender.svelte +103 -0
  37. package/src/context-keys.ts +3 -0
  38. package/src/createTable.svelte.ts +103 -0
  39. package/src/createTableHook.svelte.ts +636 -0
  40. package/src/createTableState.svelte.ts +15 -0
  41. package/src/flex-render.ts +3 -0
  42. package/src/index.ts +20 -3
  43. package/src/merge-objects.ts +43 -0
  44. package/src/reactivity.svelte.ts +64 -0
  45. package/src/render-component.ts +74 -10
  46. package/src/static-functions.ts +1 -0
  47. package/src/subscribe.ts +23 -0
  48. package/dist/flex-render.svelte +0 -35
  49. package/dist/flex-render.svelte.d.ts +0 -28
  50. package/dist/table.svelte.d.ts +0 -28
  51. package/dist/table.svelte.js +0 -87
  52. package/src/flex-render.svelte +0 -35
  53. package/src/table.svelte.ts +0 -117
package/README.md ADDED
@@ -0,0 +1,117 @@
1
+ <div align="center">
2
+ <img src="./media/header_table.png" alt="TanStack Table">
3
+ </div>
4
+
5
+ <br />
6
+
7
+ <div align="center">
8
+ <a href="https://npmjs.com/package/@tanstack/react-table" target="\_parent">
9
+ <img alt="npm downloads" src="https://img.shields.io/npm/dm/@tanstack/react-table.svg" />
10
+ </a>
11
+ <a href="https://github.com/tanstack/table" target="\_parent">
12
+ <img alt="github stars" src="https://img.shields.io/github/stars/tanstack/react-table.svg?style=social&label=Star" />
13
+ </a>
14
+ <a href="https://bundlephobia.com/result?p=@tanstack/react-table@latest" target="\_parent">
15
+ <img alt="bundle size" src="https://badgen.net/bundlephobia/minzip/@tanstack/react-table@latest" />
16
+ </a>
17
+ </div>
18
+
19
+ <div align="center">
20
+ <a href="#badge">
21
+ <img alt="semantic-release" src="https://img.shields.io/badge/%20%20%F0%9F%93%A6%F0%9F%9A%80-semantic--release-e10079.svg">
22
+ </a>
23
+ <a href="https://bestofjs.org/projects/tanstack-table"><img alt="Best of JS" src="https://img.shields.io/endpoint?url=https://bestofjs-serverless.now.sh/api/project-badge?fullName=TanStack%2Ftable%26since=daily" /></a>
24
+ <a href="https://twitter.com/tan_stack"><img src="https://img.shields.io/twitter/follow/tan_stack.svg?style=social" alt="Follow @TanStack"/></a>
25
+ </div>
26
+
27
+ ### [Become a Sponsor!](https://github.com/sponsors/tannerlinsley/)
28
+
29
+ </div>
30
+
31
+ # TanStack Table
32
+
33
+ > [!NOTE]
34
+ > You may know TanStack Table by the adapter names:
35
+ >
36
+ > - [Angular Table](https://tanstack.com/table/alpha/docs/framework/angular/angular-table)
37
+ > - [Lit Table](https://tanstack.com/table/alpha/docs/framework/lit/lit-table)
38
+ > - [React Table](https://tanstack.com/table/alpha/docs/framework/react/react-table)
39
+ > - [Solid Table](https://tanstack.com/table/alpha/docs/framework/solid/solid-table)
40
+ > - [Svelte Table](https://tanstack.com/table/alpha/docs/framework/svelte/svelte-table)
41
+ > - [Vue Table](https://tanstack.com/table/alpha/docs/framework/vue/vue-table)
42
+
43
+ A headless table library for building powerful datagrids with full control over markup, styles, and behavior.
44
+
45
+ - Framework‑agnostic core with bindings for React, Vue & Solid
46
+ - 100% customizable — bring your own UI, components, and styles
47
+ - Sorting, filtering, grouping, aggregation & row selection
48
+ - Lightweight, virtualizable & server‑side friendly
49
+
50
+ ### <a href="https://tanstack.com/table">Read the Docs →</a>
51
+
52
+ ## Get Involved
53
+
54
+ - We welcome issues and pull requests!
55
+ - Participate in [GitHub discussions](https://github.com/TanStack/table/discussions)
56
+ - Chat with the community on [Discord](https://discord.com/invite/WrRKjPJ)
57
+ - See [CONTRIBUTING.md](./CONTRIBUTING.md) for setup instructions
58
+
59
+ ## Partners
60
+
61
+ <table align="center">
62
+ <tr>
63
+ <td>
64
+ <a href="https://www.coderabbit.ai/?via=tanstack&dub_id=aCcEEdAOqqutX6OS">
65
+ <picture>
66
+ <source media="(prefers-color-scheme: dark)" srcset="https://tanstack.com/assets/coderabbit-dark-CMcuvjEy.svg" height="40" />
67
+ <source media="(prefers-color-scheme: light)" srcset="https://tanstack.com/assets/coderabbit-light-DVMJ2jHi.svg" height="40" />
68
+ <img src="https://tanstack.com/assets/coderabbit-light-DVMJ2jHi.svg" height="40" alt="CodeRabbit" />
69
+ </picture>
70
+ </a>
71
+ </td>
72
+ <td padding="20">
73
+ <a href="https://www.cloudflare.com?utm_source=tanstack">
74
+ <picture>
75
+ <source media="(prefers-color-scheme: dark)" srcset="https://tanstack.com/assets/cloudflare-white-DQDB7UaL.svg" height="60" />
76
+ <source media="(prefers-color-scheme: light)" srcset="https://tanstack.com/assets/cloudflare-black-CPufaW0B.svg" height="60" />
77
+ <img src="https://tanstack.com/assets/cloudflare-black-CPufaW0B.svg" height="60" alt="Cloudflare" />
78
+ </picture>
79
+ </a>
80
+ </td>
81
+ <td>
82
+ <a href="https://ag-grid.com/react-data-grid/?utm_source=reacttable&utm_campaign=githubreacttable" style="display: flex; align-items: center; border: none;">
83
+ <picture>
84
+ <source media="(prefers-color-scheme: dark)" srcset="./media/ag-grid-dark.svg" height="40" />
85
+ <source media="(prefers-color-scheme: light)" srcset="./media/ag-grid-light.svg" height="40" />
86
+ <img src="https://raw.githubusercontent.com/tannerlinsley/files/master/partners/ag-grid.svg" height="60" alt="AG Grid" />
87
+ </picture>
88
+ </a>
89
+ </td>
90
+ </tr>
91
+ </table>
92
+
93
+ <div align="center">
94
+ <img src="./media/partner_logo.svg" alt="Table & you?" height="65">
95
+ <p>
96
+ We're looking for TanStack Table Partners to join our mission! Partner with us to push the boundaries of TanStack Table and build amazing things together.
97
+ </p>
98
+ <a href="mailto:partners@tanstack.com?subject=TanStack Table Partnership"><b>LET'S CHAT</b></a>
99
+ </div>
100
+
101
+ ## Explore the TanStack Ecosystem
102
+
103
+ - <a href="https://github.com/tanstack/config"><b>TanStack Config</b></a> – Tooling for JS/TS packages
104
+ - <a href="https://github.com/tanstack/db"><b>TanStack DB</b></a> – Reactive sync client store
105
+ - <a href="https://github.com/tanstack/devtools"><b>TanStack DevTools</b></a> – Unified devtools panel
106
+ - <a href="https://github.com/tanstack/form"><b>TanStack Form</b></a> – Type‑safe form state
107
+ - <a href="https://github.com/tanstack/pacer"><b>TanStack Pacer</b></a> – Debouncing, throttling, batching <br/>
108
+ - <a href="https://github.com/tanstack/query"><b>TanStack Query</b></a> – Async state & caching
109
+ - <a href="https://github.com/tanstack/ranger"><b>TanStack Ranger</b></a> – Range & slider primitives
110
+ - <a href="https://github.com/tanstack/router"><b>TanStack Router</b></a> – Type‑safe routing, caching & URL state
111
+ - <a href="https://github.com/tanstack/router"><b>TanStack Start</b></a> – Full‑stack SSR & streaming
112
+ - <a href="https://github.com/tanstack/store"><b>TanStack Store</b></a> – Reactive data store
113
+ - <a href="https://github.com/tanstack/virtual"><b>TanStack Virtual</b></a> – Virtualized rendering
114
+
115
+ … and more at <a href="https://tanstack.com"><b>TanStack.com »</b></a>
116
+
117
+ <!-- USE THE FORCE LUKE -->
@@ -0,0 +1,13 @@
1
+ <script lang="ts">
2
+ import type { Snippet } from 'svelte'
3
+
4
+ interface Props {
5
+ cell: any
6
+ cellComponents: any
7
+ children: Snippet<[any]>
8
+ }
9
+
10
+ let { children, cell, cellComponents }: Props = $props()
11
+ </script>
12
+
13
+ {@render children?.(Object.assign(cell, cellComponents))}
@@ -0,0 +1,9 @@
1
+ import type { Snippet } from 'svelte';
2
+ interface Props {
3
+ cell: any;
4
+ cellComponents: any;
5
+ children: Snippet<[any]>;
6
+ }
7
+ declare const AppCell: import("svelte").Component<Props, {}, "">;
8
+ type AppCell = ReturnType<typeof AppCell>;
9
+ export default AppCell;
@@ -0,0 +1,13 @@
1
+ <script lang="ts">
2
+ import type { Snippet } from 'svelte'
3
+
4
+ interface Props {
5
+ header: any
6
+ headerComponents: any
7
+ children: Snippet<[any]>
8
+ }
9
+
10
+ let { children, header, headerComponents }: Props = $props()
11
+ </script>
12
+
13
+ {@render children?.(Object.assign(header, headerComponents))}
@@ -0,0 +1,9 @@
1
+ import type { Snippet } from 'svelte';
2
+ interface Props {
3
+ header: any;
4
+ headerComponents: any;
5
+ children: Snippet<[any]>;
6
+ }
7
+ declare const AppHeader: import("svelte").Component<Props, {}, "">;
8
+ type AppHeader = ReturnType<typeof AppHeader>;
9
+ export default AppHeader;
@@ -0,0 +1,11 @@
1
+ <script lang="ts">
2
+ import type { Snippet } from 'svelte'
3
+
4
+ interface Props {
5
+ children: Snippet
6
+ }
7
+
8
+ let { children }: Props = $props()
9
+ </script>
10
+
11
+ {@render children?.()}
@@ -0,0 +1,7 @@
1
+ import type { Snippet } from 'svelte';
2
+ interface Props {
3
+ children: Snippet;
4
+ }
5
+ declare const AppTable: import("svelte").Component<Props, {}, "">;
6
+ type AppTable = ReturnType<typeof AppTable>;
7
+ export default AppTable;
@@ -0,0 +1,103 @@
1
+ <script
2
+ lang="ts"
3
+ generics="TFeatures extends TableFeatures, TData extends RowData, TValue extends CellData"
4
+ >
5
+ import { isFunction } from '@tanstack/table-core'
6
+ import {
7
+ RenderComponentConfig,
8
+ RenderSnippetConfig,
9
+ } from './render-component'
10
+ import type {
11
+ Cell,
12
+ CellContext,
13
+ CellData,
14
+ ColumnDefTemplate,
15
+ Header,
16
+ HeaderContext,
17
+ RowData,
18
+ TableFeatures,
19
+ } from '@tanstack/table-core'
20
+
21
+ type Props =
22
+ | {
23
+ /** The cell or header field of the current cell's column definition. */
24
+ content?: ColumnDefTemplate<
25
+ | HeaderContext<TFeatures, TData, TValue>
26
+ | CellContext<TFeatures, TData, TValue>
27
+ >
28
+ /** The result of the `getContext()` function of the header or cell */
29
+ context:
30
+ | HeaderContext<TFeatures, TData, TValue>
31
+ | CellContext<TFeatures, TData, TValue>
32
+ cell?: never
33
+ header?: never
34
+ footer?: never
35
+ }
36
+ | {
37
+ cell: Cell<TFeatures, TData, TValue>
38
+ content?: never
39
+ context?: never
40
+ header?: never
41
+ footer?: never
42
+ }
43
+ | {
44
+ header: Header<TFeatures, TData, TValue>
45
+ content?: never
46
+ context?: never
47
+ cell?: never
48
+ footer?: never
49
+ }
50
+ | {
51
+ footer: Header<TFeatures, TData, TValue>
52
+ content?: never
53
+ context?: never
54
+ cell?: never
55
+ header?: never
56
+ }
57
+
58
+ let props: Props = $props()
59
+
60
+ // Resolve content and context from either the new cell/header/footer props
61
+ // or the legacy content/context props.
62
+ const resolved = $derived.by(() => {
63
+ if ('cell' in props && props.cell) {
64
+ return {
65
+ content: props.cell.column.columnDef.cell,
66
+ context: props.cell.getContext(),
67
+ }
68
+ }
69
+ if ('header' in props && props.header) {
70
+ return {
71
+ content: props.header.column.columnDef.header,
72
+ context: props.header.getContext(),
73
+ }
74
+ }
75
+ if ('footer' in props && props.footer) {
76
+ return {
77
+ content: props.footer.column.columnDef.footer,
78
+ context: props.footer.getContext(),
79
+ }
80
+ }
81
+ return {
82
+ content: props.content,
83
+ context: props.context,
84
+ }
85
+ })
86
+
87
+ // Compute the render result reactively
88
+ const result = $derived(
89
+ isFunction(resolved.content)
90
+ ? resolved.content(resolved.context as any)
91
+ : undefined,
92
+ )
93
+ </script>
94
+
95
+ {#if typeof resolved.content === 'string'}
96
+ {resolved.content}
97
+ {:else if result instanceof RenderComponentConfig}
98
+ <result.component {...result.props} />
99
+ {:else if result instanceof RenderSnippetConfig}
100
+ {@render result.snippet(result.params)}
101
+ {:else if result !== undefined}
102
+ {result}
103
+ {/if}
@@ -0,0 +1,51 @@
1
+ import type { Cell, CellContext, CellData, ColumnDefTemplate, Header, HeaderContext, RowData, TableFeatures } from '@tanstack/table-core';
2
+ declare function $$render<TFeatures extends TableFeatures, TData extends RowData, TValue extends CellData>(): {
3
+ props: {
4
+ /** The cell or header field of the current cell's column definition. */
5
+ content?: ColumnDefTemplate<HeaderContext<TFeatures, TData, TValue> | CellContext<TFeatures, TData, TValue>>;
6
+ /** The result of the `getContext()` function of the header or cell */
7
+ context: HeaderContext<TFeatures, TData, TValue> | CellContext<TFeatures, TData, TValue>;
8
+ cell?: never;
9
+ header?: never;
10
+ footer?: never;
11
+ } | {
12
+ cell: Cell<TFeatures, TData, TValue>;
13
+ content?: never;
14
+ context?: never;
15
+ header?: never;
16
+ footer?: never;
17
+ } | {
18
+ header: Header<TFeatures, TData, TValue>;
19
+ content?: never;
20
+ context?: never;
21
+ cell?: never;
22
+ footer?: never;
23
+ } | {
24
+ footer: Header<TFeatures, TData, TValue>;
25
+ content?: never;
26
+ context?: never;
27
+ cell?: never;
28
+ header?: never;
29
+ };
30
+ exports: {};
31
+ bindings: "";
32
+ slots: {};
33
+ events: {};
34
+ };
35
+ declare class __sveltets_Render<TFeatures extends TableFeatures, TData extends RowData, TValue extends CellData> {
36
+ props(): ReturnType<typeof $$render<TFeatures, TData, TValue>>['props'];
37
+ events(): ReturnType<typeof $$render<TFeatures, TData, TValue>>['events'];
38
+ slots(): ReturnType<typeof $$render<TFeatures, TData, TValue>>['slots'];
39
+ bindings(): "";
40
+ exports(): {};
41
+ }
42
+ interface $$IsomorphicComponent {
43
+ new <TFeatures extends TableFeatures, TData extends RowData, TValue extends CellData>(options: import('svelte').ComponentConstructorOptions<ReturnType<__sveltets_Render<TFeatures, TData, TValue>['props']>>): import('svelte').SvelteComponent<ReturnType<__sveltets_Render<TFeatures, TData, TValue>['props']>, ReturnType<__sveltets_Render<TFeatures, TData, TValue>['events']>, ReturnType<__sveltets_Render<TFeatures, TData, TValue>['slots']>> & {
44
+ $$bindings?: ReturnType<__sveltets_Render<TFeatures, TData, TValue>['bindings']>;
45
+ } & ReturnType<__sveltets_Render<TFeatures, TData, TValue>['exports']>;
46
+ <TFeatures extends TableFeatures, TData extends RowData, TValue extends CellData>(internal: unknown, props: ReturnType<__sveltets_Render<TFeatures, TData, TValue>['props']> & {}): ReturnType<__sveltets_Render<TFeatures, TData, TValue>['exports']>;
47
+ z_$$bindings?: ReturnType<__sveltets_Render<any, any, any>['bindings']>;
48
+ }
49
+ declare const FlexRender: $$IsomorphicComponent;
50
+ type FlexRender<TFeatures extends TableFeatures, TData extends RowData, TValue extends CellData> = InstanceType<typeof FlexRender<TFeatures, TData, TValue>>;
51
+ export default FlexRender;
@@ -0,0 +1,3 @@
1
+ export declare const tableContextKey = "__tanstack_table_context_key";
2
+ export declare const cellContextKey = "__tanstack_cell_context_key";
3
+ export declare const headerContextKey = "__tanstack_header_context_key";
@@ -0,0 +1,3 @@
1
+ export const tableContextKey = '__tanstack_table_context_key';
2
+ export const cellContextKey = '__tanstack_cell_context_key';
3
+ export const headerContextKey = '__tanstack_header_context_key';
@@ -0,0 +1,13 @@
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> & {
3
+ /**
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
+ *
6
+ * @example
7
+ * const table = createTable(options, (state) => ({ globalFilter: state.globalFilter })) // only globalFilter is part of the selected state
8
+ *
9
+ * console.log(table.state.globalFilter)
10
+ */
11
+ readonly state: Readonly<TSelected>;
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>;
@@ -0,0 +1,54 @@
1
+ import { constructTable } from '@tanstack/table-core';
2
+ import { useSelector } from '@tanstack/svelte-store';
3
+ import { untrack } from 'svelte';
4
+ import { mergeObjects } from './merge-objects';
5
+ import { svelteReactivity } from './reactivity.svelte';
6
+ export function createTable(tableOptions, selector = () => ({})) {
7
+ // 1. Merge reactivity into options using mergeObjects (preserves getters)
8
+ const mergedOptions = mergeObjects(tableOptions, {
9
+ _features: {
10
+ coreReativityFeature: svelteReactivity(),
11
+ ...tableOptions._features,
12
+ },
13
+ });
14
+ // 2. Set up resolved options with mergeOptions handler
15
+ const resolvedOptions = mergeObjects({
16
+ mergeOptions: (defaultOptions, newOptions) => {
17
+ return mergeObjects(defaultOptions, newOptions);
18
+ },
19
+ }, mergedOptions);
20
+ // 3. Construct table
21
+ const table = constructTable(resolvedOptions);
22
+ // 4. Sync options reactively. When controlled state changes (e.g., $state
23
+ // inside createTableState), the effect re-runs and calls setOptions.
24
+ // Use $effect.pre so the table sees updated options BEFORE the DOM renders,
25
+ // ensuring getRowModel() returns current data (not stale, one-frame-behind data).
26
+ // The reactive reads (state getters, data getter) happen OUTSIDE untrack
27
+ // so they become dependencies. The setOptions call is INSIDE untrack so
28
+ // option writes do not subscribe this effect to table internals.
29
+ $effect.pre(() => {
30
+ // Read reactive getters to create $effect dependencies on external state
31
+ const state = mergedOptions.state;
32
+ if (state) {
33
+ for (const key in state) {
34
+ void state[key];
35
+ }
36
+ }
37
+ void mergedOptions.data;
38
+ untrack(() => {
39
+ table.setOptions((prev) => {
40
+ return mergeObjects(prev, mergedOptions);
41
+ });
42
+ });
43
+ });
44
+ // 5. State selector
45
+ const stateStore = useSelector(table.store, selector);
46
+ Object.defineProperty(table, 'state', {
47
+ get() {
48
+ return stateStore.current;
49
+ },
50
+ configurable: true,
51
+ enumerable: true,
52
+ });
53
+ return table;
54
+ }
@@ -0,0 +1,235 @@
1
+ import FlexRenderSvelte from './FlexRender.svelte';
2
+ import type { SvelteTable } from './createTable.svelte';
3
+ import type { Component, Snippet } from 'svelte';
4
+ import type { AccessorFn, AccessorFnColumnDef, AccessorKeyColumnDef, Cell, CellContext, CellData, Column, ColumnDef, DeepKeys, DeepValue, DisplayColumnDef, GroupColumnDef, Header, IdentifiedColumnDef, NoInfer, Row, RowData, Table, TableFeatures, TableOptions, TableState } from '@tanstack/table-core';
5
+ export type ComponentType<T extends Record<string, any>> = Component<T>;
6
+ /**
7
+ * Enhanced CellContext with pre-bound cell components.
8
+ * The `cell` property includes the registered cellComponents.
9
+ */
10
+ export type AppCellContext<TFeatures extends TableFeatures, TData extends RowData, TValue extends CellData, TCellComponents extends Record<string, ComponentType<any>>> = {
11
+ cell: Cell<TFeatures, TData, TValue> & TCellComponents & {
12
+ FlexRender: typeof FlexRenderSvelte;
13
+ };
14
+ column: Column<TFeatures, TData, TValue>;
15
+ getValue: CellContext<TFeatures, TData, TValue>['getValue'];
16
+ renderValue: CellContext<TFeatures, TData, TValue>['renderValue'];
17
+ row: Row<TFeatures, TData>;
18
+ table: Table<TFeatures, TData>;
19
+ };
20
+ /**
21
+ * Enhanced HeaderContext with pre-bound header components.
22
+ * The `header` property includes the registered headerComponents.
23
+ */
24
+ export type AppHeaderContext<TFeatures extends TableFeatures, TData extends RowData, TValue extends CellData, THeaderComponents extends Record<string, ComponentType<any>>> = {
25
+ column: Column<TFeatures, TData, TValue>;
26
+ header: Header<TFeatures, TData, TValue> & THeaderComponents & {
27
+ FlexRender: typeof FlexRenderSvelte;
28
+ };
29
+ table: Table<TFeatures, TData>;
30
+ };
31
+ /**
32
+ * Template type for column definitions that can be a string or a function.
33
+ */
34
+ export type AppColumnDefTemplate<TProps extends object> = string | ((props: TProps) => any);
35
+ /**
36
+ * Enhanced column definition base with pre-bound components in cell/header/footer contexts.
37
+ */
38
+ export type AppColumnDefBase<TFeatures extends TableFeatures, TData extends RowData, TValue extends CellData, TCellComponents extends Record<string, ComponentType<any>>, THeaderComponents extends Record<string, ComponentType<any>>> = Omit<IdentifiedColumnDef<TFeatures, TData, TValue>, 'cell' | 'header' | 'footer'> & {
39
+ cell?: AppColumnDefTemplate<AppCellContext<TFeatures, TData, TValue, TCellComponents>>;
40
+ header?: AppColumnDefTemplate<AppHeaderContext<TFeatures, TData, TValue, THeaderComponents>>;
41
+ footer?: AppColumnDefTemplate<AppHeaderContext<TFeatures, TData, TValue, THeaderComponents>>;
42
+ };
43
+ /**
44
+ * Enhanced display column definition with pre-bound components.
45
+ */
46
+ export type AppDisplayColumnDef<TFeatures extends TableFeatures, TData extends RowData, TCellComponents extends Record<string, ComponentType<any>>, THeaderComponents extends Record<string, ComponentType<any>>> = Omit<DisplayColumnDef<TFeatures, TData, unknown>, 'cell' | 'header' | 'footer'> & {
47
+ cell?: AppColumnDefTemplate<AppCellContext<TFeatures, TData, unknown, TCellComponents>>;
48
+ header?: AppColumnDefTemplate<AppHeaderContext<TFeatures, TData, unknown, THeaderComponents>>;
49
+ footer?: AppColumnDefTemplate<AppHeaderContext<TFeatures, TData, unknown, THeaderComponents>>;
50
+ };
51
+ /**
52
+ * Enhanced group column definition with pre-bound components.
53
+ */
54
+ export type AppGroupColumnDef<TFeatures extends TableFeatures, TData extends RowData, TCellComponents extends Record<string, ComponentType<any>>, THeaderComponents extends Record<string, ComponentType<any>>> = Omit<GroupColumnDef<TFeatures, TData, unknown>, 'cell' | 'header' | 'footer' | 'columns'> & {
55
+ cell?: AppColumnDefTemplate<AppCellContext<TFeatures, TData, unknown, TCellComponents>>;
56
+ header?: AppColumnDefTemplate<AppHeaderContext<TFeatures, TData, unknown, THeaderComponents>>;
57
+ footer?: AppColumnDefTemplate<AppHeaderContext<TFeatures, TData, unknown, THeaderComponents>>;
58
+ columns?: Array<ColumnDef<TFeatures, TData, unknown>>;
59
+ };
60
+ /**
61
+ * Enhanced column helper with pre-bound components in cell/header/footer contexts.
62
+ * This enables TypeScript to know about the registered components when defining columns.
63
+ */
64
+ export type AppColumnHelper<TFeatures extends TableFeatures, TData extends RowData, TCellComponents extends Record<string, ComponentType<any>>, THeaderComponents extends Record<string, ComponentType<any>>> = {
65
+ /**
66
+ * Creates a data column definition with an accessor key or function.
67
+ * The cell, header, and footer contexts include pre-bound components.
68
+ */
69
+ accessor: <TAccessor extends AccessorFn<TData> | DeepKeys<TData>, TValue extends TAccessor extends AccessorFn<TData, infer TReturn> ? TReturn : TAccessor extends DeepKeys<TData> ? DeepValue<TData, TAccessor> : never>(accessor: TAccessor, column: TAccessor extends AccessorFn<TData> ? AppColumnDefBase<TFeatures, TData, TValue, TCellComponents, THeaderComponents> & {
70
+ id: string;
71
+ } : AppColumnDefBase<TFeatures, TData, TValue, TCellComponents, THeaderComponents>) => TAccessor extends AccessorFn<TData> ? AccessorFnColumnDef<TFeatures, TData, TValue> : AccessorKeyColumnDef<TFeatures, TData, TValue>;
72
+ /**
73
+ * Wraps an array of column definitions to preserve each column's individual TValue type.
74
+ */
75
+ columns: <TColumns extends ReadonlyArray<ColumnDef<TFeatures, TData, any>>>(columns: [...TColumns]) => Array<ColumnDef<TFeatures, TData, any>> & [...TColumns];
76
+ /**
77
+ * Creates a display column definition for non-data columns.
78
+ * The cell, header, and footer contexts include pre-bound components.
79
+ */
80
+ display: (column: AppDisplayColumnDef<TFeatures, TData, TCellComponents, THeaderComponents>) => DisplayColumnDef<TFeatures, TData, unknown>;
81
+ /**
82
+ * Creates a group column definition with nested child columns.
83
+ * The cell, header, and footer contexts include pre-bound components.
84
+ */
85
+ group: (column: AppGroupColumnDef<TFeatures, TData, TCellComponents, THeaderComponents>) => GroupColumnDef<TFeatures, TData, unknown>;
86
+ };
87
+ /**
88
+ * Options for creating a table hook with pre-bound components and default table options.
89
+ * Extends all TableOptions except 'columns' | 'data' | 'store' | 'state' | 'initialState'.
90
+ */
91
+ export type CreateTableHookOptions<TFeatures extends TableFeatures, TTableComponents extends Record<string, ComponentType<any>>, TCellComponents extends Record<string, ComponentType<any>>, THeaderComponents extends Record<string, ComponentType<any>>> = Omit<TableOptions<TFeatures, any>, 'columns' | 'data' | 'store' | 'state' | 'initialState'> & {
92
+ /**
93
+ * Table-level components that need access to the table instance.
94
+ * These are available directly on the table object returned by createAppTable.
95
+ * Use `useTableContext()` inside these components.
96
+ * @example { PaginationControls, GlobalFilter, RowCount }
97
+ */
98
+ tableComponents?: TTableComponents;
99
+ /**
100
+ * Cell-level components that need access to the cell instance.
101
+ * These are available on the cell object passed to AppCell's children.
102
+ * Use `useCellContext()` inside these components.
103
+ * @example { TextCell, NumberCell, DateCell, CurrencyCell }
104
+ */
105
+ cellComponents?: TCellComponents;
106
+ /**
107
+ * Header-level components that need access to the header instance.
108
+ * These are available on the header object passed to AppHeader/AppFooter's children.
109
+ * Use `useHeaderContext()` inside these components.
110
+ * @example { SortIndicator, ColumnFilter, ResizeHandle }
111
+ */
112
+ headerComponents?: THeaderComponents;
113
+ };
114
+ /**
115
+ * Extended table API returned by createAppTable with all App wrapper components.
116
+ */
117
+ export type AppSvelteTable<TFeatures extends TableFeatures, TData extends RowData, TSelected, TTableComponents extends Record<string, ComponentType<any>>, TCellComponents extends Record<string, ComponentType<any>>, THeaderComponents extends Record<string, ComponentType<any>>> = SvelteTable<TFeatures, TData, TSelected> & NoInfer<TTableComponents> & {
118
+ /**
119
+ * Root wrapper component that provides table context.
120
+ * @example
121
+ * ```svelte
122
+ * <table.AppTable>
123
+ * <table>...</table>
124
+ * </table.AppTable>
125
+ * ```
126
+ */
127
+ AppTable: Component<{
128
+ children: Snippet;
129
+ }>;
130
+ /**
131
+ * Wraps a cell and provides cell context with pre-bound cellComponents.
132
+ * @example
133
+ * ```svelte
134
+ * <table.AppCell cell={cell}>
135
+ * {#snippet children(c)}
136
+ * <td><c.TextCell /></td>
137
+ * {/snippet}
138
+ * </table.AppCell>
139
+ * ```
140
+ */
141
+ AppCell: Component<{
142
+ cell: Cell<TFeatures, TData, any>;
143
+ children: Snippet<[
144
+ Cell<TFeatures, TData, any> & NoInfer<TCellComponents> & {
145
+ FlexRender: typeof FlexRenderSvelte;
146
+ }
147
+ ]>;
148
+ }>;
149
+ /**
150
+ * Wraps a header and provides header context with pre-bound headerComponents.
151
+ * @example
152
+ * ```svelte
153
+ * <table.AppHeader header={header}>
154
+ * {#snippet children(h)}
155
+ * <th><h.SortIndicator /></th>
156
+ * {/snippet}
157
+ * </table.AppHeader>
158
+ * ```
159
+ */
160
+ AppHeader: Component<{
161
+ header: Header<TFeatures, TData, any>;
162
+ children: Snippet<[
163
+ Header<TFeatures, TData, any> & NoInfer<THeaderComponents> & {
164
+ FlexRender: typeof FlexRenderSvelte;
165
+ }
166
+ ]>;
167
+ }>;
168
+ /**
169
+ * Wraps a footer and provides header context with pre-bound headerComponents.
170
+ * @example
171
+ * ```svelte
172
+ * <table.AppFooter header={footer}>
173
+ * {#snippet children(f)}
174
+ * <td><f.FlexRender /></td>
175
+ * {/snippet}
176
+ * </table.AppFooter>
177
+ * ```
178
+ */
179
+ AppFooter: Component<{
180
+ header: Header<TFeatures, TData, any>;
181
+ children: Snippet<[
182
+ Header<TFeatures, TData, any> & NoInfer<THeaderComponents> & {
183
+ FlexRender: typeof FlexRenderSvelte;
184
+ }
185
+ ]>;
186
+ }>;
187
+ /**
188
+ * Convenience FlexRender component attached to the table instance.
189
+ */
190
+ FlexRender: typeof FlexRenderSvelte;
191
+ };
192
+ /**
193
+ * Creates a custom table hook with pre-bound components for composition.
194
+ *
195
+ * This is the table equivalent of TanStack Form's `createFormHook`. It allows you to:
196
+ * - Define features, row models, and default options once, shared across all tables
197
+ * - Register reusable table, cell, and header components
198
+ * - Access table/cell/header instances via context in those components
199
+ * - Get a `createAppTable` hook that returns an extended table with App wrapper components
200
+ * - Get a `createAppColumnHelper` function pre-bound to your features
201
+ *
202
+ * @example
203
+ * ```ts
204
+ * // hooks/table.ts
205
+ * export const {
206
+ * createAppTable,
207
+ * createAppColumnHelper,
208
+ * useTableContext,
209
+ * useCellContext,
210
+ * useHeaderContext,
211
+ * } = createTableHook({
212
+ * _features: tableFeatures({
213
+ * rowPaginationFeature,
214
+ * rowSortingFeature,
215
+ * columnFilteringFeature,
216
+ * }),
217
+ * _rowModels: {
218
+ * paginatedRowModel: createPaginatedRowModel(),
219
+ * sortedRowModel: createSortedRowModel(sortFns),
220
+ * filteredRowModel: createFilteredRowModel(filterFns),
221
+ * },
222
+ * tableComponents: { PaginationControls, RowCount },
223
+ * cellComponents: { TextCell, NumberCell },
224
+ * headerComponents: { SortIndicator, ColumnFilter },
225
+ * })
226
+ * ```
227
+ */
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
+ appFeatures: TFeatures;
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>;
232
+ useTableContext: <TData extends RowData = RowData>() => SvelteTable<TFeatures, TData>;
233
+ useCellContext: <TValue extends CellData = unknown>() => Cell<TFeatures, any, TValue>;
234
+ useHeaderContext: <TValue extends CellData = unknown>() => Header<TFeatures, any, TValue>;
235
+ };