@tanstack/vue-table 9.0.0-alpha.9 → 9.0.0-beta.10

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 (70) hide show
  1. package/README.md +127 -0
  2. package/dist/FlexRender.cjs +80 -0
  3. package/dist/FlexRender.cjs.map +1 -0
  4. package/dist/FlexRender.d.cts +63 -0
  5. package/dist/FlexRender.d.ts +63 -0
  6. package/dist/FlexRender.js +79 -0
  7. package/dist/FlexRender.js.map +1 -0
  8. package/dist/createTableHook.cjs +193 -0
  9. package/dist/createTableHook.cjs.map +1 -0
  10. package/dist/createTableHook.d.cts +134 -0
  11. package/dist/createTableHook.d.ts +134 -0
  12. package/dist/createTableHook.js +192 -0
  13. package/dist/createTableHook.js.map +1 -0
  14. package/dist/flex-render.cjs +5 -0
  15. package/dist/flex-render.d.cts +2 -0
  16. package/dist/flex-render.d.ts +2 -0
  17. package/dist/flex-render.js +3 -0
  18. package/dist/index.cjs +17 -0
  19. package/dist/index.d.cts +5 -0
  20. package/dist/index.d.ts +5 -0
  21. package/dist/index.js +7 -0
  22. package/dist/merge-proxy.cjs +77 -0
  23. package/dist/merge-proxy.cjs.map +1 -0
  24. package/dist/merge-proxy.js +75 -0
  25. package/dist/merge-proxy.js.map +1 -0
  26. package/dist/reactivity.cjs +64 -0
  27. package/dist/reactivity.cjs.map +1 -0
  28. package/dist/reactivity.js +64 -0
  29. package/dist/reactivity.js.map +1 -0
  30. package/dist/static-functions.cjs +9 -0
  31. package/dist/static-functions.d.cts +1 -0
  32. package/dist/static-functions.d.ts +1 -0
  33. package/dist/static-functions.js +3 -0
  34. package/dist/useTable.cjs +75 -0
  35. package/dist/useTable.cjs.map +1 -0
  36. package/dist/useTable.d.cts +42 -0
  37. package/dist/useTable.d.ts +42 -0
  38. package/dist/useTable.js +75 -0
  39. package/dist/useTable.js.map +1 -0
  40. package/package.json +31 -19
  41. package/skills/vue/client-to-server/SKILL.md +360 -0
  42. package/skills/vue/compose-with-tanstack-form/SKILL.md +369 -0
  43. package/skills/vue/compose-with-tanstack-pacer/SKILL.md +321 -0
  44. package/skills/vue/compose-with-tanstack-query/SKILL.md +383 -0
  45. package/skills/vue/compose-with-tanstack-store/SKILL.md +302 -0
  46. package/skills/vue/compose-with-tanstack-virtual/SKILL.md +344 -0
  47. package/skills/vue/getting-started/SKILL.md +415 -0
  48. package/skills/vue/migrate-v8-to-v9/SKILL.md +393 -0
  49. package/skills/vue/production-readiness/SKILL.md +278 -0
  50. package/skills/vue/table-state/SKILL.md +399 -0
  51. package/src/FlexRender.ts +138 -0
  52. package/src/createTableHook.ts +533 -0
  53. package/src/flex-render.ts +1 -0
  54. package/src/index.ts +3 -74
  55. package/src/merge-proxy.ts +66 -15
  56. package/src/reactivity.ts +89 -0
  57. package/src/static-functions.ts +1 -0
  58. package/src/useTable.ts +180 -0
  59. package/dist/cjs/index.cjs +0 -68
  60. package/dist/cjs/index.cjs.map +0 -1
  61. package/dist/cjs/index.d.cts +0 -14
  62. package/dist/cjs/merge-proxy.cjs +0 -61
  63. package/dist/cjs/merge-proxy.cjs.map +0 -1
  64. package/dist/cjs/merge-proxy.d.cts +0 -11
  65. package/dist/esm/index.d.ts +0 -14
  66. package/dist/esm/index.js +0 -63
  67. package/dist/esm/index.js.map +0 -1
  68. package/dist/esm/merge-proxy.d.ts +0 -11
  69. package/dist/esm/merge-proxy.js +0 -61
  70. package/dist/esm/merge-proxy.js.map +0 -1
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tanstack/vue-table",
3
- "version": "9.0.0-alpha.9",
3
+ "version": "9.0.0-beta.10",
4
4
  "description": "Headless UI for building powerful tables & datagrids for Vue.",
5
5
  "author": "Tanner Linsley",
6
6
  "license": "MIT",
@@ -18,42 +18,54 @@
18
18
  "vue",
19
19
  "table",
20
20
  "vue-table",
21
- "datagrid"
21
+ "datagrid",
22
+ "tanstack-intent"
22
23
  ],
23
24
  "type": "module",
24
- "types": "dist/esm/index.d.ts",
25
- "main": "dist/cjs/index.cjs",
26
- "module": "dist/esm/index.js",
25
+ "types": "./dist/index.d.cts",
26
+ "main": "./dist/index.cjs",
27
+ "module": "./dist/index.js",
27
28
  "exports": {
28
29
  ".": {
29
- "import": {
30
- "types": "./dist/esm/index.d.ts",
31
- "default": "./dist/esm/index.js"
32
- },
33
- "require": {
34
- "types": "./dist/cjs/index.d.cts",
35
- "default": "./dist/cjs/index.cjs"
36
- }
30
+ "import": "./dist/index.js",
31
+ "require": "./dist/index.cjs"
32
+ },
33
+ "./flex-render": {
34
+ "import": "./dist/flex-render.js",
35
+ "require": "./dist/flex-render.cjs"
36
+ },
37
+ "./static-functions": {
38
+ "import": "./dist/static-functions.js",
39
+ "require": "./dist/static-functions.cjs"
37
40
  },
38
41
  "./package.json": "./package.json"
39
42
  },
40
43
  "sideEffects": false,
41
44
  "engines": {
42
- "node": ">=12"
45
+ "node": ">=16"
43
46
  },
44
47
  "files": [
45
48
  "dist",
46
- "src"
49
+ "src",
50
+ "skills"
47
51
  ],
48
52
  "dependencies": {
49
- "@tanstack/table-core": "9.0.0-alpha.8"
53
+ "@tanstack/store": "^0.11.0",
54
+ "@tanstack/table-core": "9.0.0-beta.10"
50
55
  },
51
56
  "devDependencies": {
52
- "@vitejs/plugin-vue": "^5.0.5",
53
- "vue": "^3.4.31"
57
+ "@vitejs/plugin-vue": "^6.0.7",
58
+ "eslint-plugin-vue": "^10.9.2",
59
+ "vue": "^3.5.35"
54
60
  },
55
61
  "peerDependencies": {
56
62
  "vue": ">=3.2"
57
63
  },
58
- "scripts": {}
64
+ "scripts": {
65
+ "clean": "rimraf ./build && rimraf ./dist",
66
+ "test:eslint": "eslint ./src",
67
+ "test:types": "tsc",
68
+ "test:build": "publint --strict",
69
+ "build": "tsdown"
70
+ }
59
71
  }
@@ -0,0 +1,360 @@
1
+ ---
2
+ name: vue/client-to-server
3
+ description: >
4
+ Convert a client-side `@tanstack/vue-table` to server-side. Set `manualPagination` /
5
+ `manualSorting` / `manualFiltering` / `manualGrouping` / `manualExpanding` for whichever
6
+ slices the server owns; omit the matching row model factory from `tableFeatures` (don't ship
7
+ `paginatedRowModel` when the server paginates); supply `rowCount` so `table.getPageCount()`
8
+ works; own the relevant state slices via either external atoms (`@tanstack/vue-store`
9
+ `createAtom` + `options.atoms`) or `state` + `on[State]Change` with getter wrappers. Key any
10
+ data fetch (TanStack Query / fetch / rxResource alternative) on the controlled state and use
11
+ `placeholderData: keepPreviousData` (or equivalent) to avoid a 0-rows flash between pages.
12
+ type: lifecycle
13
+ library: tanstack-table
14
+ framework: vue
15
+ library_version: '9.0.0-alpha.48'
16
+ requires:
17
+ - state-management
18
+ - pagination
19
+ - filtering
20
+ - sorting
21
+ sources:
22
+ - examples/vue/basic-external-atoms/
23
+ - examples/vue/basic-external-state/
24
+ - examples/vue/with-tanstack-query/
25
+ - docs/framework/vue/guide/table-state.md
26
+ ---
27
+
28
+ # Client-to-Server Conversion (Vue)
29
+
30
+ ## Dependencies
31
+
32
+ ```bash
33
+ pnpm add @tanstack/vue-table @tanstack/vue-store
34
+ # Recommended fetch layer:
35
+ pnpm add @tanstack/vue-query
36
+ ```
37
+
38
+ External atoms (`@tanstack/vue-store`) are recommended for server-managed slices. They cut the
39
+ `on[State]Change` plumbing entirely — the table writes to the atom; the query keys on the atom.
40
+
41
+ ## Setup — minimal server-paginated table
42
+
43
+ ```vue
44
+ <script setup lang="ts">
45
+ import { computed, ref, watchEffect } from 'vue'
46
+ import { createAtom, useSelector } from '@tanstack/vue-store'
47
+ import { keepPreviousData, useQuery } from '@tanstack/vue-query'
48
+ import {
49
+ FlexRender,
50
+ createColumnHelper,
51
+ rowPaginationFeature,
52
+ tableFeatures,
53
+ useTable,
54
+ type PaginationState,
55
+ } from '@tanstack/vue-table'
56
+ import { fetchPeople } from './api'
57
+
58
+ type Person = { firstName: string; lastName: string; age: number }
59
+
60
+ const features = tableFeatures({ rowPaginationFeature })
61
+ const columnHelper = createColumnHelper<typeof features, Person>()
62
+ const columns = columnHelper.columns([
63
+ columnHelper.accessor('firstName', { header: 'First' }),
64
+ columnHelper.accessor('lastName', { header: 'Last' }),
65
+ columnHelper.accessor('age', { header: 'Age' }),
66
+ ])
67
+
68
+ // 1) Own pagination in an external atom. Cheap for the table to write through.
69
+ const paginationAtom = createAtom<PaginationState>({
70
+ pageIndex: 0,
71
+ pageSize: 10,
72
+ })
73
+ const pagination = useSelector(paginationAtom)
74
+
75
+ // 2) Key the query on the atom value. table.setPageIndex(...) writes to the atom
76
+ // → useSelector re-evaluates → useQuery refetches.
77
+ const dataQuery = useQuery(() => ({
78
+ queryKey: ['people', pagination.value],
79
+ queryFn: () => fetchPeople(pagination.value),
80
+ placeholderData: keepPreviousData, // avoid "0 rows" flash between pages
81
+ }))
82
+
83
+ const tableData = computed<Person[]>(() => dataQuery.data.value?.rows ?? [])
84
+ const rowCount = ref(0)
85
+ watchEffect(() => {
86
+ const next = dataQuery.data.value?.rowCount
87
+ if (next != null) rowCount.value = next // keep last known total for pager UI
88
+ })
89
+
90
+ // 3) Manual pagination + `rowCount`. No paginatedRowModel in features — server paginates.
91
+ const table = useTable({
92
+ features,
93
+ columns,
94
+ data: tableData,
95
+ rowCount,
96
+ atoms: { pagination: paginationAtom },
97
+ manualPagination: true,
98
+ })
99
+ </script>
100
+ ```
101
+
102
+ Source: `examples/vue/with-tanstack-query/src/App.tsx`, `examples/vue/basic-external-atoms/`.
103
+
104
+ ## Core Patterns
105
+
106
+ ### 1. The `manual*` flag + factory omission pair
107
+
108
+ Pick which slices live server-side and flip the matching `manual*` flag. **Also omit the
109
+ matching row model factory from `tableFeatures`** — otherwise the table re-processes
110
+ server-processed rows.
111
+
112
+ | Server owns | Set | Omit from `tableFeatures` |
113
+ | ----------- | ------------------------ | ------------------------- |
114
+ | Pagination | `manualPagination: true` | `paginatedRowModel` |
115
+ | Sorting | `manualSorting: true` | `sortedRowModel` |
116
+ | Filtering | `manualFiltering: true` | `filteredRowModel` |
117
+ | Grouping | `manualGrouping: true` | `groupedRowModel` |
118
+ | Expanding | `manualExpanding: true` | `expandedRowModel` |
119
+
120
+ Column visibility / ordering / pinning / row selection are client-side state and stay as-is.
121
+
122
+ ### 2. `rowCount` so `getPageCount()` works
123
+
124
+ Without `rowCount`, `getPageCount()` falls back to `Math.ceil(data.length / pageSize)` — i.e.
125
+ `1` if the server already paginated. The pager locks at "Page 1 of 1".
126
+
127
+ ```ts
128
+ useTable({
129
+ features,
130
+ columns,
131
+ data: tableData,
132
+ rowCount: dataQuery.data.value?.rowCount, // or a stable ref/computed
133
+ atoms: { pagination: paginationAtom },
134
+ manualPagination: true,
135
+ })
136
+ ```
137
+
138
+ If `rowCount` isn't immediately available, hold the last known value in a `ref` and update via
139
+ `watchEffect` so the pager doesn't reset to 0 during refetches.
140
+
141
+ ### 3. Two state-ownership shapes (pick one per slice)
142
+
143
+ **External atoms (recommended with Query).** Table writes through to the atom. No
144
+ `on[State]Change` needed.
145
+
146
+ ```ts
147
+ const paginationAtom = createAtom<PaginationState>({
148
+ pageIndex: 0,
149
+ pageSize: 10,
150
+ })
151
+ useTable({
152
+ features,
153
+ columns,
154
+ data,
155
+ rowCount,
156
+ atoms: { pagination: paginationAtom },
157
+ manualPagination: true,
158
+ })
159
+ ```
160
+
161
+ **Classic `state` + `on[State]Change` with getters.** Required when migrating from v8 or
162
+ integrating with existing Vue ref-based state. Each slice must be a getter so Vue tracks
163
+ `.value`.
164
+
165
+ ```ts
166
+ const pagination = ref<PaginationState>({ pageIndex: 0, pageSize: 10 })
167
+
168
+ useTable({
169
+ features,
170
+ columns,
171
+ data,
172
+ rowCount,
173
+ state: {
174
+ get pagination() {
175
+ return pagination.value
176
+ },
177
+ },
178
+ onPaginationChange: (u) => {
179
+ pagination.value = typeof u === 'function' ? u(pagination.value) : u
180
+ },
181
+ manualPagination: true,
182
+ })
183
+ ```
184
+
185
+ **Precedence:** `atoms[slice]` > `state[slice]` > internal `baseAtoms[slice]`. Don't pass the
186
+ same slice through both — the atoms wins silently.
187
+
188
+ ### 4. Cache keys must include controlled state
189
+
190
+ ```ts
191
+ const sortingAtom = createAtom<SortingState>([])
192
+ const paginationAtom = createAtom<PaginationState>({
193
+ pageIndex: 0,
194
+ pageSize: 10,
195
+ })
196
+ const sorting = useSelector(sortingAtom)
197
+ const pagination = useSelector(paginationAtom)
198
+
199
+ const dataQuery = useQuery(() => ({
200
+ queryKey: [
201
+ 'people',
202
+ { sorting: sorting.value, pagination: pagination.value },
203
+ ],
204
+ queryFn: () =>
205
+ fetchPeople({ sorting: sorting.value, pagination: pagination.value }),
206
+ placeholderData: keepPreviousData,
207
+ }))
208
+ ```
209
+
210
+ If pagination/sort/filter aren't in `queryKey`, Query won't refetch when the user clicks a
211
+ pager button — the buttons "do nothing" from the user's POV.
212
+
213
+ ### 5. Mixed client + server features still work
214
+
215
+ Column visibility, ordering, pinning, and row selection are client state — they don't depend
216
+ on the row model and continue to function with `manualPagination`/`manualSorting`/`manualFiltering`.
217
+ You can have a server-paginated table where the user pins or hides columns locally.
218
+
219
+ ## Common Mistakes
220
+
221
+ ### Forgetting `manualPagination` / `manualSorting` / `manualFiltering` (CRITICAL)
222
+
223
+ The table double-processes server-processed rows. If the server returned page 2 of 50,
224
+ the table will paginate that 10-row slice again and show "Page 1 of 1".
225
+
226
+ ```ts
227
+ // ❌
228
+ useTable({
229
+ features,
230
+ columns,
231
+ data: serverPage.rows,
232
+ rowCount,
233
+ atoms: { pagination: paginationAtom },
234
+ // missing: manualPagination: true
235
+ })
236
+ ```
237
+
238
+ ### Leaving `paginatedRowModel` registered when server paginates (CRITICAL)
239
+
240
+ ```ts
241
+ // ❌ Factory ships for nothing AND the table re-paginates server-sliced data.
242
+ const features = tableFeatures({
243
+ rowPaginationFeature,
244
+ paginatedRowModel: createPaginatedRowModel(),
245
+ })
246
+
247
+ // ✅ Omit the factory when the server paginates; keep the feature for its API.
248
+ const features = tableFeatures({ rowPaginationFeature })
249
+ ```
250
+
251
+ Same applies to `sortedRowModel`, `filteredRowModel`, `groupedRowModel`, `expandedRowModel`
252
+ when the server owns the slice.
253
+
254
+ ### Omitting `rowCount` (CRITICAL)
255
+
256
+ `getPageCount()` returns `1` if the server already paginated. The pager UI locks at
257
+ "Page 1 of 1" and users can't navigate.
258
+
259
+ ### Passing `state.pagination` without `onPaginationChange` (CRITICAL)
260
+
261
+ ```ts
262
+ // ❌ table.setPageIndex(2) is a no-op — no writeback handler.
263
+ const pagination = ref({ pageIndex: 0, pageSize: 10 })
264
+ useTable({
265
+ features,
266
+ columns,
267
+ data,
268
+ rowCount,
269
+ state: {
270
+ get pagination() {
271
+ return pagination.value
272
+ },
273
+ },
274
+ manualPagination: true,
275
+ })
276
+
277
+ // ✅ Either pair `state` with `on[State]Change`, OR use `atoms`.
278
+ ```
279
+
280
+ ### Mixing `state.pagination` AND `atoms.pagination` for the same slice (HIGH)
281
+
282
+ ```ts
283
+ useTable({
284
+ // ...
285
+ state: {
286
+ get pagination() {
287
+ return localPagination.value
288
+ },
289
+ }, // silently ignored
290
+ onPaginationChange: setLocalPagination, // silently ignored
291
+ atoms: { pagination: paginationAtom }, // wins
292
+ })
293
+ ```
294
+
295
+ Atoms beat `state`; the `state` plumbing is dead but lingering in the code. Pick one mechanism.
296
+
297
+ ### Forgetting to include controlled state in `queryKey` (CRITICAL)
298
+
299
+ ```ts
300
+ // ❌ Never refetches when pagination changes.
301
+ useQuery(() => ({
302
+ queryKey: ['people'],
303
+ queryFn: () => fetchPeople(pagination.value),
304
+ }))
305
+
306
+ // ✅
307
+ useQuery(() => ({
308
+ queryKey: ['people', pagination.value],
309
+ queryFn: () => fetchPeople(pagination.value),
310
+ }))
311
+ ```
312
+
313
+ ### Skipping `placeholderData: keepPreviousData` (HIGH)
314
+
315
+ Between fetches the table collapses to 0 rows, the row container collapses, and scroll
316
+ position jumps. `keepPreviousData` keeps the previous page visible during the refetch.
317
+
318
+ ### Passing a raw `ref` to `state.pagination` without a getter (CRITICAL — Vue-specific)
319
+
320
+ ```ts
321
+ // ❌ Vue can't track .value changes on the captured ref object.
322
+ state: { pagination: pagination }
323
+
324
+ // ✅
325
+ state: { get pagination() { return pagination.value } }
326
+ ```
327
+
328
+ ### Hand-rolling sort/page state instead of using the API (CRITICAL — #1 AI tell)
329
+
330
+ ```ts
331
+ // ❌ Manual state machine.
332
+ const pageIndex = ref(0)
333
+ const next = () => {
334
+ pageIndex.value++
335
+ refetch()
336
+ }
337
+
338
+ // ✅ Built-ins.
339
+ table.nextPage()
340
+ table.setPageIndex(0)
341
+ table.setSorting([{ id: 'age', desc: true }])
342
+ table.setColumnFilters(/* ... */)
343
+ ```
344
+
345
+ ### "API missing" because the feature isn't in `features` (CRITICAL — v9-specific)
346
+
347
+ Server-side pagination still needs `rowPaginationFeature` in `tableFeatures({...})` — that's
348
+ what surfaces `table.setPageIndex`, `table.nextPage`, `table.getPageCount`. The row model
349
+ factory (`paginatedRowModel`) is what you omit; the feature stays.
350
+
351
+ ```ts
352
+ const features = tableFeatures({ rowPaginationFeature }) // ✅ even with manualPagination
353
+ ```
354
+
355
+ ## See Also
356
+
357
+ - `tanstack-table/vue/compose-with-tanstack-query` — the Query-specific wiring
358
+ - `tanstack-table/vue/compose-with-tanstack-store` — external atoms in depth
359
+ - `tanstack-table/vue/table-state` — getter rule, atom precedence
360
+ - `tanstack-table/table-core/pagination` — `manualPagination` / `rowCount` semantics