@tanstack/svelte-table 9.0.0-beta.7 → 9.0.0-beta.70
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/README.md +5 -1
- package/dist/FlexRender.svelte +15 -1
- package/dist/createTable.svelte.d.ts +26 -36
- package/dist/createTable.svelte.js +27 -32
- package/dist/createTableHook.svelte.d.ts +51 -18
- package/dist/createTableHook.svelte.js +18 -10
- package/dist/experimental-worker-plugin.d.ts +1 -0
- package/dist/experimental-worker-plugin.js +1 -0
- package/dist/index.d.ts +1 -2
- package/dist/index.js +0 -1
- package/dist/reactivity.svelte.d.ts +3 -1
- package/dist/reactivity.svelte.js +6 -1
- package/dist/render-component.js +4 -0
- package/package.json +16 -9
- package/skills/create-table-hook/SKILL.md +168 -0
- package/skills/getting-started/SKILL.md +172 -0
- package/skills/migrate-v8-to-v9/SKILL.md +201 -0
- package/skills/table-state/SKILL.md +262 -0
- package/skills/with-tanstack-query/SKILL.md +149 -0
- package/skills/with-tanstack-virtual/SKILL.md +150 -0
- package/dist/subscribe.d.ts +0 -24
- package/dist/subscribe.js +0 -4
- package/skills/svelte/client-to-server/SKILL.md +0 -238
- package/skills/svelte/compose-with-tanstack-form/SKILL.md +0 -295
- package/skills/svelte/compose-with-tanstack-pacer/SKILL.md +0 -176
- package/skills/svelte/compose-with-tanstack-query/SKILL.md +0 -299
- package/skills/svelte/compose-with-tanstack-store/SKILL.md +0 -277
- package/skills/svelte/compose-with-tanstack-virtual/SKILL.md +0 -286
- package/skills/svelte/getting-started/SKILL.md +0 -340
- package/skills/svelte/migrate-v8-to-v9/SKILL.md +0 -256
- package/skills/svelte/production-readiness/SKILL.md +0 -256
- package/skills/svelte/table-state/SKILL.md +0 -441
- package/src/AppCell.svelte +0 -13
- package/src/AppHeader.svelte +0 -13
- package/src/AppTable.svelte +0 -11
- package/src/FlexRender.svelte +0 -103
- package/src/context-keys.ts +0 -3
- package/src/createTable.svelte.ts +0 -137
- package/src/createTableHook.svelte.ts +0 -639
- package/src/createTableState.svelte.ts +0 -30
- package/src/flex-render.ts +0 -3
- package/src/global.d.ts +0 -1
- package/src/index.ts +0 -21
- package/src/merge-objects.ts +0 -79
- package/src/reactivity.svelte.ts +0 -118
- package/src/render-component.ts +0 -107
- package/src/static-functions.ts +0 -1
- package/src/subscribe.ts +0 -46
|
@@ -1,137 +0,0 @@
|
|
|
1
|
-
import { constructTable } from '@tanstack/table-core'
|
|
2
|
-
import { useSelector } from '@tanstack/svelte-store'
|
|
3
|
-
import { untrack } from 'svelte'
|
|
4
|
-
import { flatMerge, mergeObjects } from './merge-objects'
|
|
5
|
-
import { svelteReactivity } from './reactivity.svelte'
|
|
6
|
-
import type {
|
|
7
|
-
RowData,
|
|
8
|
-
Table,
|
|
9
|
-
TableFeatures,
|
|
10
|
-
TableOptions,
|
|
11
|
-
TableState,
|
|
12
|
-
} from '@tanstack/table-core'
|
|
13
|
-
|
|
14
|
-
export type SvelteTable<
|
|
15
|
-
TFeatures extends TableFeatures,
|
|
16
|
-
TData extends RowData,
|
|
17
|
-
TSelected = TableState<TFeatures>,
|
|
18
|
-
> = Omit<Table<TFeatures, TData>, 'store'> & {
|
|
19
|
-
/**
|
|
20
|
-
* @deprecated Prefer `table.state` for render reads,
|
|
21
|
-
* `table.atoms.<slice>.get()` for slice snapshots, or
|
|
22
|
-
* `useSelector(table.store, selector)` for explicit subscriptions.
|
|
23
|
-
* `table.store.state` is a current-value snapshot and is easy to misuse in
|
|
24
|
-
* render code.
|
|
25
|
-
*/
|
|
26
|
-
readonly store: Table<TFeatures, TData>['store']
|
|
27
|
-
/**
|
|
28
|
-
* The selected state of the table. This state may not match the structure of
|
|
29
|
-
* the full table state because it is selected by the selector function that
|
|
30
|
-
* you pass as the 2nd argument to `createTable`.
|
|
31
|
-
*
|
|
32
|
-
* @example
|
|
33
|
-
* const table = createTable(options, (state) => ({ globalFilter: state.globalFilter })) // only globalFilter is part of the selected state
|
|
34
|
-
*
|
|
35
|
-
* console.log(table.state.globalFilter)
|
|
36
|
-
*/
|
|
37
|
-
readonly state: Readonly<TSelected>
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
/**
|
|
41
|
-
* Creates a Svelte 5 table instance backed by rune-aware TanStack Store atoms.
|
|
42
|
-
*
|
|
43
|
-
* The optional selector projects from `table.store`; the selected value is
|
|
44
|
-
* exposed on `table.state`. The adapter syncs options in `$effect.pre`, so
|
|
45
|
-
* reactive option getters and external `$state` values are applied before DOM
|
|
46
|
-
* updates read table APIs such as `getRowModel()`.
|
|
47
|
-
*
|
|
48
|
-
* @example
|
|
49
|
-
* ```svelte
|
|
50
|
-
* <script lang="ts">
|
|
51
|
-
* const table = createTable(
|
|
52
|
-
* {
|
|
53
|
-
* features,
|
|
54
|
-
* rowModels: {},
|
|
55
|
-
* columns,
|
|
56
|
-
* data,
|
|
57
|
-
* },
|
|
58
|
-
* (state) => ({ pagination: state.pagination }),
|
|
59
|
-
* )
|
|
60
|
-
* </script>
|
|
61
|
-
*
|
|
62
|
-
* {table.state.pagination.pageIndex}
|
|
63
|
-
* ```
|
|
64
|
-
*/
|
|
65
|
-
export function createTable<
|
|
66
|
-
TFeatures extends TableFeatures,
|
|
67
|
-
TData extends RowData,
|
|
68
|
-
TSelected = TableState<TFeatures>,
|
|
69
|
-
>(
|
|
70
|
-
tableOptions: TableOptions<TFeatures, TData>,
|
|
71
|
-
selector?: (state: TableState<TFeatures>) => TSelected,
|
|
72
|
-
): SvelteTable<TFeatures, TData, TSelected> {
|
|
73
|
-
// 1. Merge reactivity into options using mergeObjects (preserves getters)
|
|
74
|
-
const mergedOptions = mergeObjects(tableOptions, {
|
|
75
|
-
features: {
|
|
76
|
-
coreReativityFeature: svelteReactivity(),
|
|
77
|
-
...tableOptions.features,
|
|
78
|
-
},
|
|
79
|
-
}) as TableOptions<TFeatures, TData>
|
|
80
|
-
|
|
81
|
-
// 2. Set up resolved options with mergeOptions handler
|
|
82
|
-
const resolvedOptions = mergeObjects(
|
|
83
|
-
{
|
|
84
|
-
mergeOptions: (
|
|
85
|
-
defaultOptions: TableOptions<TFeatures, TData>,
|
|
86
|
-
newOptions: Partial<TableOptions<TFeatures, TData>>,
|
|
87
|
-
) => {
|
|
88
|
-
return flatMerge(defaultOptions, newOptions)
|
|
89
|
-
},
|
|
90
|
-
},
|
|
91
|
-
mergedOptions,
|
|
92
|
-
) as TableOptions<TFeatures, TData>
|
|
93
|
-
|
|
94
|
-
// 3. Construct table
|
|
95
|
-
const table = constructTable(resolvedOptions) as unknown as SvelteTable<
|
|
96
|
-
TFeatures,
|
|
97
|
-
TData,
|
|
98
|
-
TSelected
|
|
99
|
-
>
|
|
100
|
-
|
|
101
|
-
// 4. Sync options reactively. When controlled state changes (e.g., $state
|
|
102
|
-
// inside createTableState), the effect re-runs and calls setOptions.
|
|
103
|
-
// Use $effect.pre so the table sees updated options BEFORE the DOM renders,
|
|
104
|
-
// ensuring getRowModel() returns current data (not stale, one-frame-behind data).
|
|
105
|
-
// The reactive reads (state getters, data getter) happen OUTSIDE untrack
|
|
106
|
-
// so they become dependencies. The setOptions call is INSIDE untrack so
|
|
107
|
-
// option writes do not subscribe this effect to table internals.
|
|
108
|
-
$effect.pre(() => {
|
|
109
|
-
// Read reactive getters to create $effect dependencies on external state
|
|
110
|
-
const state: Record<string, unknown> | undefined = mergedOptions.state
|
|
111
|
-
if (state) {
|
|
112
|
-
for (const key in state) {
|
|
113
|
-
void state[key]
|
|
114
|
-
}
|
|
115
|
-
}
|
|
116
|
-
void mergedOptions.data
|
|
117
|
-
|
|
118
|
-
untrack(() => {
|
|
119
|
-
table.setOptions((prev) => {
|
|
120
|
-
return flatMerge(prev, mergedOptions)
|
|
121
|
-
})
|
|
122
|
-
})
|
|
123
|
-
})
|
|
124
|
-
|
|
125
|
-
// 5. State selector
|
|
126
|
-
const stateStore = useSelector(table.store, selector)
|
|
127
|
-
|
|
128
|
-
Object.defineProperty(table, 'state', {
|
|
129
|
-
get() {
|
|
130
|
-
return stateStore.current
|
|
131
|
-
},
|
|
132
|
-
configurable: true,
|
|
133
|
-
enumerable: true,
|
|
134
|
-
})
|
|
135
|
-
|
|
136
|
-
return table
|
|
137
|
-
}
|