@tanstack/svelte-table 9.0.0-alpha.9 → 9.0.0-beta.2

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 (63) hide show
  1. package/README.md +127 -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 +48 -0
  13. package/dist/createTable.svelte.js +79 -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 +17 -0
  17. package/dist/createTableState.svelte.js +27 -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 +24 -0
  23. package/dist/merge-objects.js +45 -0
  24. package/dist/reactivity.svelte.d.ts +9 -0
  25. package/dist/reactivity.svelte.js +89 -0
  26. package/dist/render-component.d.ts +66 -9
  27. package/dist/render-component.js +62 -4
  28. package/dist/static-functions.d.ts +1 -0
  29. package/dist/static-functions.js +1 -0
  30. package/dist/subscribe.d.ts +24 -0
  31. package/dist/subscribe.js +4 -0
  32. package/package.json +31 -11
  33. package/skills/svelte/client-to-server/SKILL.md +238 -0
  34. package/skills/svelte/compose-with-tanstack-form/SKILL.md +295 -0
  35. package/skills/svelte/compose-with-tanstack-pacer/SKILL.md +176 -0
  36. package/skills/svelte/compose-with-tanstack-query/SKILL.md +299 -0
  37. package/skills/svelte/compose-with-tanstack-store/SKILL.md +277 -0
  38. package/skills/svelte/compose-with-tanstack-virtual/SKILL.md +286 -0
  39. package/skills/svelte/getting-started/SKILL.md +340 -0
  40. package/skills/svelte/migrate-v8-to-v9/SKILL.md +256 -0
  41. package/skills/svelte/production-readiness/SKILL.md +256 -0
  42. package/skills/svelte/table-state/SKILL.md +441 -0
  43. package/src/AppCell.svelte +13 -0
  44. package/src/AppHeader.svelte +13 -0
  45. package/src/AppTable.svelte +11 -0
  46. package/src/FlexRender.svelte +103 -0
  47. package/src/context-keys.ts +3 -0
  48. package/src/createTable.svelte.ts +137 -0
  49. package/src/createTableHook.svelte.ts +639 -0
  50. package/src/createTableState.svelte.ts +30 -0
  51. package/src/flex-render.ts +3 -0
  52. package/src/index.ts +20 -3
  53. package/src/merge-objects.ts +79 -0
  54. package/src/reactivity.svelte.ts +118 -0
  55. package/src/render-component.ts +75 -9
  56. package/src/static-functions.ts +1 -0
  57. package/src/subscribe.ts +46 -0
  58. package/dist/flex-render.svelte +0 -35
  59. package/dist/flex-render.svelte.d.ts +0 -28
  60. package/dist/table.svelte.d.ts +0 -28
  61. package/dist/table.svelte.js +0 -87
  62. package/src/flex-render.svelte +0 -35
  63. package/src/table.svelte.ts +0 -117
@@ -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 = TableState<TFeatures>>(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
+ };
@@ -0,0 +1,170 @@
1
+ import { getContext, setContext } from 'svelte';
2
+ import { createColumnHelper as coreCreateColumnHelper } from '@tanstack/table-core';
3
+ import { createTable } from './createTable.svelte';
4
+ import { mergeObjects } from './merge-objects';
5
+ import { cellContextKey, headerContextKey, tableContextKey, } from './context-keys.js';
6
+ import AppTableSvelte from './AppTable.svelte';
7
+ import AppCellSvelte from './AppCell.svelte';
8
+ import AppHeaderSvelte from './AppHeader.svelte';
9
+ import FlexRenderSvelte from './FlexRender.svelte';
10
+ // =============================================================================
11
+ // createTableHook Factory
12
+ // =============================================================================
13
+ /**
14
+ * Creates a custom table hook with pre-bound components for composition.
15
+ *
16
+ * This is the table equivalent of TanStack Form's `createFormHook`. It allows you to:
17
+ * - Define features, row models, and default options once, shared across all tables
18
+ * - Register reusable table, cell, and header components
19
+ * - Access table/cell/header instances via context in those components
20
+ * - Get a `createAppTable` hook that returns an extended table with App wrapper components
21
+ * - Get a `createAppColumnHelper` function pre-bound to your features
22
+ *
23
+ * @example
24
+ * ```ts
25
+ * // hooks/table.ts
26
+ * export const {
27
+ * createAppTable,
28
+ * createAppColumnHelper,
29
+ * useTableContext,
30
+ * useCellContext,
31
+ * useHeaderContext,
32
+ * } = createTableHook({
33
+ * features: tableFeatures({
34
+ * rowPaginationFeature,
35
+ * rowSortingFeature,
36
+ * columnFilteringFeature,
37
+ * }),
38
+ * rowModels: {
39
+ * paginatedRowModel: createPaginatedRowModel(),
40
+ * sortedRowModel: createSortedRowModel(sortFns),
41
+ * filteredRowModel: createFilteredRowModel(filterFns),
42
+ * },
43
+ * tableComponents: { PaginationControls, RowCount },
44
+ * cellComponents: { TextCell, NumberCell },
45
+ * headerComponents: { SortIndicator, ColumnFilter },
46
+ * })
47
+ * ```
48
+ */
49
+ export function createTableHook({ tableComponents, cellComponents, headerComponents, ...defaultTableOptions }) {
50
+ /**
51
+ * Create a column helper pre-bound to the features and components configured in this table hook.
52
+ * The cell, header, and footer contexts include pre-bound components (e.g., `cell.TextCell`).
53
+ */
54
+ function createAppColumnHelper() {
55
+ return coreCreateColumnHelper();
56
+ }
57
+ /**
58
+ * Access the table instance from within an `AppTable` wrapper.
59
+ * Use this in custom `tableComponents` passed to `createTableHook`.
60
+ * TFeatures is already known from the createTableHook call.
61
+ */
62
+ function useTableContext() {
63
+ const table = getContext(tableContextKey);
64
+ if (!table) {
65
+ throw new Error('`useTableContext` must be used within an `AppTable` component. ' +
66
+ 'Make sure your component is wrapped with `<table.AppTable>...</table.AppTable>`.');
67
+ }
68
+ return table;
69
+ }
70
+ /**
71
+ * Access the cell instance from within an `AppCell` wrapper.
72
+ * Use this in custom `cellComponents` passed to `createTableHook`.
73
+ * TFeatures is already known from the createTableHook call.
74
+ */
75
+ function useCellContext() {
76
+ const cell = getContext(cellContextKey);
77
+ if (!cell) {
78
+ throw new Error('`useCellContext` must be used within an `AppCell` component. ' +
79
+ 'Make sure your component is wrapped with `<table.AppCell cell={cell}>...</table.AppCell>`.');
80
+ }
81
+ return cell;
82
+ }
83
+ /**
84
+ * Access the header instance from within an `AppHeader` or `AppFooter` wrapper.
85
+ * Use this in custom `headerComponents` passed to `createTableHook`.
86
+ * TFeatures is already known from the createTableHook call.
87
+ */
88
+ function useHeaderContext() {
89
+ const header = getContext(headerContextKey);
90
+ if (!header) {
91
+ throw new Error('`useHeaderContext` must be used within an `AppHeader` or `AppFooter` component.');
92
+ }
93
+ return header;
94
+ }
95
+ /**
96
+ * Enhanced createTable hook that returns a table with App wrapper components
97
+ * and pre-bound tableComponents attached directly to the table object.
98
+ *
99
+ * Default options from createTableHook are automatically merged with
100
+ * the options passed here. Options passed here take precedence.
101
+ *
102
+ * TFeatures is already known from the createTableHook call; TData is inferred from the data prop.
103
+ */
104
+ function createAppTable(tableOptions, selector) {
105
+ // Merge default options with provided options (provided takes precedence)
106
+ const mergedTableOptions = mergeObjects(defaultTableOptions, tableOptions);
107
+ const table = createTable(mergedTableOptions, selector);
108
+ // Build cellComponents with FlexRender included
109
+ const cellComponentsWithFlexRender = {
110
+ FlexRender: FlexRenderSvelte,
111
+ ...(cellComponents ?? {}),
112
+ };
113
+ // Build headerComponents with FlexRender included
114
+ const headerComponentsWithFlexRender = {
115
+ FlexRender: FlexRenderSvelte,
116
+ ...(headerComponents ?? {}),
117
+ };
118
+ // Create wrapper components using the svelte-form (internal, props) => pattern.
119
+ // setContext is called in the closure — this runs during component
120
+ // initialization, so Svelte's context API works correctly.
121
+ // With keyed {#each} blocks, components are recreated on reorder,
122
+ // so context is always fresh.
123
+ const AppTable = ((internal, props) => {
124
+ setContext(tableContextKey, table);
125
+ return AppTableSvelte(internal, { ...props });
126
+ });
127
+ const AppCell = ((internal, { children, cell, ...rest }) => {
128
+ setContext(cellContextKey, cell);
129
+ return AppCellSvelte(internal, {
130
+ cell,
131
+ cellComponents: cellComponentsWithFlexRender,
132
+ children,
133
+ });
134
+ });
135
+ const AppHeader = ((internal, { children, header, ...rest }) => {
136
+ setContext(headerContextKey, header);
137
+ return AppHeaderSvelte(internal, {
138
+ header,
139
+ headerComponents: headerComponentsWithFlexRender,
140
+ children,
141
+ });
142
+ });
143
+ // AppFooter reuses AppHeaderSvelte (footers use Header type in table-core)
144
+ const AppFooter = ((internal, { children, header, ...rest }) => {
145
+ setContext(headerContextKey, header);
146
+ return AppHeaderSvelte(internal, {
147
+ header,
148
+ headerComponents: headerComponentsWithFlexRender,
149
+ children,
150
+ });
151
+ });
152
+ // Combine everything into the extended table API
153
+ return Object.assign(table, {
154
+ AppTable,
155
+ AppCell,
156
+ AppHeader,
157
+ AppFooter,
158
+ FlexRender: FlexRenderSvelte,
159
+ ...(tableComponents ?? {}),
160
+ });
161
+ }
162
+ return {
163
+ appFeatures: defaultTableOptions.features,
164
+ createAppColumnHelper,
165
+ createAppTable,
166
+ useTableContext,
167
+ useCellContext,
168
+ useHeaderContext,
169
+ };
170
+ }
@@ -0,0 +1,17 @@
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
+ */
17
+ export declare function createTableState<TState>(initialValue: TState): [() => TState, (updater: Updater<TState>) => void];
@@ -0,0 +1,27 @@
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
+ */
16
+ export function createTableState(initialValue) {
17
+ let value = $state(initialValue);
18
+ return [
19
+ () => value,
20
+ (updater) => {
21
+ if (updater instanceof Function)
22
+ value = updater(value);
23
+ else
24
+ value = updater;
25
+ },
26
+ ];
27
+ }
@@ -0,0 +1 @@
1
+ export { default as FlexRender } from './FlexRender.svelte';
@@ -0,0 +1,2 @@
1
+ /// <reference types="svelte" />
2
+ export { default as FlexRender } from './FlexRender.svelte';
package/dist/index.d.ts CHANGED
@@ -1,4 +1,9 @@
1
1
  export * from '@tanstack/table-core';
2
- export { default as FlexRender } from './flex-render.svelte';
3
- export { renderComponent } from './render-component';
4
- export { createTable } from './table.svelte';
2
+ export { createTable } from './createTable.svelte';
3
+ export type { SvelteTable } from './createTable.svelte';
4
+ export { createTableHook } from './createTableHook.svelte';
5
+ export type { AppCellContext, AppColumnDefBase, AppColumnDefTemplate, AppColumnHelper, AppDisplayColumnDef, AppGroupColumnDef, AppHeaderContext, AppSvelteTable, ComponentType, CreateTableHookOptions, } from './createTableHook.svelte';
6
+ export { createTableState } from './createTableState.svelte';
7
+ export { default as FlexRender } from './FlexRender.svelte';
8
+ export { subscribeTable, type SubscribeSource } from './subscribe';
9
+ export { renderComponent, renderSnippet } from './render-component';
package/dist/index.js CHANGED
@@ -1,4 +1,7 @@
1
1
  export * from '@tanstack/table-core';
2
- export { default as FlexRender } from './flex-render.svelte';
3
- export { renderComponent } from './render-component';
4
- export { createTable } from './table.svelte';
2
+ export { createTable } from './createTable.svelte';
3
+ export { createTableHook } from './createTableHook.svelte';
4
+ export { createTableState } from './createTableState.svelte';
5
+ export { default as FlexRender } from './FlexRender.svelte';
6
+ export { subscribeTable } from './subscribe';
7
+ export { renderComponent, renderSnippet } from './render-component';
@@ -0,0 +1,24 @@
1
+ /**
2
+ * Merges objects together while keeping their getters alive.
3
+ * Taken from SolidJS: {https://github.com/solidjs/solid/blob/24abc825c0996fd2bc8c1de1491efe9a7e743aff/packages/solid/src/server/rendering.ts#L82-L115}
4
+ * */
5
+ export declare function mergeObjects<T>(source: T): T;
6
+ export declare function mergeObjects<T, U>(source: T, source1: U): T & U;
7
+ export declare function mergeObjects<T, U, V>(source: T, source1: U, source2: V): T & U & V;
8
+ export declare function mergeObjects<T, U, V, W>(source: T, source1: U, source2: V, source3: W): T & U & V & W;
9
+ /**
10
+ * Merges objects together by eagerly resolving all values into a flat object.
11
+ *
12
+ * Unlike `mergeObjects`, this does NOT preserve getters — values are read once
13
+ * and stored as plain data properties. This prevents the getter-chain
14
+ * accumulation that causes O(N) lookups when the result is repeatedly passed
15
+ * back as a source in subsequent merges (e.g., inside `$effect.pre` loops).
16
+ *
17
+ * Later sources take precedence; `undefined` values do not override.
18
+ *
19
+ * @see https://github.com/TanStack/table/issues/6235
20
+ */
21
+ export declare function flatMerge<T>(source: T): T;
22
+ export declare function flatMerge<T, U>(source: T, source1: U): T & U;
23
+ export declare function flatMerge<T, U, V>(source: T, source1: U, source2: V): T & U & V;
24
+ export declare function flatMerge<T, U, V, W>(source: T, source1: U, source2: V, source3: W): T & U & V & W;
@@ -0,0 +1,45 @@
1
+ export function mergeObjects(...sources) {
2
+ const target = {};
3
+ for (let source of sources) {
4
+ if (typeof source === 'function')
5
+ source = source();
6
+ if (source) {
7
+ const descriptors = Object.getOwnPropertyDescriptors(source);
8
+ for (const key in descriptors) {
9
+ if (key in target)
10
+ continue;
11
+ Object.defineProperty(target, key, {
12
+ enumerable: true,
13
+ get() {
14
+ for (let i = sources.length - 1; i >= 0; i--) {
15
+ let v, s = sources[i];
16
+ if (typeof s === 'function')
17
+ s = s();
18
+ // eslint-disable-next-line prefer-const
19
+ v = (s || {})[key];
20
+ if (v !== undefined)
21
+ return v;
22
+ }
23
+ },
24
+ });
25
+ }
26
+ }
27
+ }
28
+ return target;
29
+ }
30
+ export function flatMerge(...sources) {
31
+ const result = {};
32
+ for (let source of sources) {
33
+ if (typeof source === 'function')
34
+ source = source();
35
+ if (!source)
36
+ continue;
37
+ for (const key of Reflect.ownKeys(source)) {
38
+ const value = source[key];
39
+ if (value !== undefined) {
40
+ result[key] = value;
41
+ }
42
+ }
43
+ }
44
+ return result;
45
+ }
@@ -0,0 +1,9 @@
1
+ import type { TableReactivityBindings } from '@tanstack/table-core/reactivity';
2
+ /**
3
+ * Creates the table-core reactivity bindings used by the Svelte adapter.
4
+ *
5
+ * Table state atoms are backed by TanStack Store atoms. The options store stays
6
+ * framework-native because row-model APIs read `table.options` directly during
7
+ * render. Readonly table atoms bridge Store dependency tracking into `$derived.by`.
8
+ */
9
+ export declare function svelteReactivity(): TableReactivityBindings;
@@ -0,0 +1,89 @@
1
+ import { untrack } from 'svelte';
2
+ import { batch, createAtom } from '@tanstack/svelte-store';
3
+ const optionsStoreDebugName = 'table/optionsStore';
4
+ function observerToCallback(observerOrNext) {
5
+ return typeof observerOrNext === 'function'
6
+ ? observerOrNext
7
+ : (value) => observerOrNext.next?.(value);
8
+ }
9
+ function subscribeToRune(getValue, observerOrNext) {
10
+ const callback = observerToCallback(observerOrNext);
11
+ const unsubscribe = $effect.root(() => {
12
+ $effect(() => {
13
+ const value = getValue();
14
+ untrack(() => callback(value));
15
+ });
16
+ });
17
+ return { unsubscribe };
18
+ }
19
+ function createRuneWritableAtom(initialValue) {
20
+ let value = $state(initialValue);
21
+ return {
22
+ set: (updater) => {
23
+ value =
24
+ typeof updater === 'function'
25
+ ? updater(value)
26
+ : updater;
27
+ },
28
+ get: () => value,
29
+ subscribe: ((observerOrNext) => {
30
+ return subscribeToRune(() => value, observerOrNext);
31
+ }),
32
+ };
33
+ }
34
+ /**
35
+ * Creates the table-core reactivity bindings used by the Svelte adapter.
36
+ *
37
+ * Table state atoms are backed by TanStack Store atoms. The options store stays
38
+ * framework-native because row-model APIs read `table.options` directly during
39
+ * render. Readonly table atoms bridge Store dependency tracking into `$derived.by`.
40
+ */
41
+ export function svelteReactivity() {
42
+ return {
43
+ createOptionsStore: true,
44
+ wrapExternalAtoms: false,
45
+ addSubscription: () => {
46
+ throw new Error('Feature not supported in current reactivity implementation');
47
+ },
48
+ unmount: () => {
49
+ throw new Error('Feature not supported in current reactivity implementation');
50
+ },
51
+ schedule: (fn) => queueMicrotask(() => fn()),
52
+ createReadonlyAtom: (fn, _options) => {
53
+ const storeAtom = createAtom(() => fn(), {
54
+ compare: _options?.compare,
55
+ });
56
+ let version = $state(0);
57
+ $effect(() => {
58
+ const subscription = storeAtom.subscribe(() => {
59
+ version += 1;
60
+ });
61
+ return () => subscription.unsubscribe();
62
+ });
63
+ const value = $derived.by(() => {
64
+ version;
65
+ return storeAtom.get();
66
+ });
67
+ return {
68
+ get: () => {
69
+ const currentValue = storeAtom.get();
70
+ value;
71
+ return currentValue;
72
+ },
73
+ subscribe: ((observerOrNext) => {
74
+ return subscribeToRune(() => value, observerOrNext);
75
+ }),
76
+ };
77
+ },
78
+ createWritableAtom: (initialValue, _options) => {
79
+ if (_options?.debugName === optionsStoreDebugName) {
80
+ return createRuneWritableAtom(initialValue);
81
+ }
82
+ return createAtom(initialValue, {
83
+ compare: _options?.compare,
84
+ });
85
+ },
86
+ untrack: untrack,
87
+ batch,
88
+ };
89
+ }