@tanstack/vue-table 9.0.0-beta.4 → 9.0.0-beta.40
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 +1 -0
- package/dist/FlexRender.cjs +2 -3
- package/dist/FlexRender.cjs.map +1 -1
- package/dist/FlexRender.d.cts +30 -12
- package/dist/FlexRender.d.ts +30 -12
- package/dist/FlexRender.js +2 -3
- package/dist/FlexRender.js.map +1 -1
- package/dist/createTableHook.cjs +4 -9
- package/dist/createTableHook.cjs.map +1 -1
- package/dist/createTableHook.d.cts +49 -21
- package/dist/createTableHook.d.ts +49 -21
- package/dist/createTableHook.js +4 -9
- package/dist/createTableHook.js.map +1 -1
- package/dist/experimental-worker-plugin.cjs +9 -0
- package/dist/experimental-worker-plugin.d.cts +1 -0
- package/dist/experimental-worker-plugin.d.ts +1 -0
- package/dist/experimental-worker-plugin.js +3 -0
- package/dist/flex-render.d.cts +2 -2
- package/dist/flex-render.d.ts +2 -2
- package/dist/index.d.cts +3 -3
- package/dist/index.d.ts +3 -3
- package/dist/reactivity.cjs +2 -6
- package/dist/reactivity.cjs.map +1 -1
- package/dist/reactivity.js +2 -6
- package/dist/reactivity.js.map +1 -1
- package/dist/useTable.cjs +3 -7
- package/dist/useTable.cjs.map +1 -1
- package/dist/useTable.d.cts +1 -8
- package/dist/useTable.d.ts +1 -8
- package/dist/useTable.js +3 -7
- package/dist/useTable.js.map +1 -1
- package/package.json +8 -4
- package/skills/vue/client-to-server/SKILL.md +21 -26
- package/skills/vue/compose-with-tanstack-form/SKILL.md +4 -4
- package/skills/vue/compose-with-tanstack-pacer/SKILL.md +6 -3
- package/skills/vue/compose-with-tanstack-query/SKILL.md +18 -20
- package/skills/vue/compose-with-tanstack-store/SKILL.md +7 -6
- package/skills/vue/compose-with-tanstack-virtual/SKILL.md +8 -4
- package/skills/vue/getting-started/SKILL.md +55 -49
- package/skills/vue/migrate-v8-to-v9/SKILL.md +50 -32
- package/skills/vue/production-readiness/SKILL.md +28 -21
- package/skills/vue/table-state/SKILL.md +22 -26
- package/src/FlexRender.ts +28 -13
- package/src/createTableHook.ts +112 -20
- package/src/experimental-worker-plugin.ts +1 -0
- package/src/reactivity.ts +1 -2
- package/src/useTable.ts +3 -11
package/src/createTableHook.ts
CHANGED
|
@@ -4,7 +4,8 @@ import { FlexRender } from './FlexRender'
|
|
|
4
4
|
import { mergeProxy } from './merge-proxy'
|
|
5
5
|
import { useTable } from './useTable'
|
|
6
6
|
import type { TableOptionsWithReactiveData, VueTable } from './useTable'
|
|
7
|
-
import type {
|
|
7
|
+
import type { FlexRenderCell, FlexRenderHeader } from './FlexRender'
|
|
8
|
+
import type { Component, InjectionKey, PropType } from 'vue'
|
|
8
9
|
import type {
|
|
9
10
|
AccessorFn,
|
|
10
11
|
AccessorFnColumnDef,
|
|
@@ -25,7 +26,6 @@ import type {
|
|
|
25
26
|
RowData,
|
|
26
27
|
Table,
|
|
27
28
|
TableFeatures,
|
|
28
|
-
TableState,
|
|
29
29
|
} from '@tanstack/table-core'
|
|
30
30
|
|
|
31
31
|
export type ComponentType<T extends Record<string, any>> = Component<T>
|
|
@@ -212,10 +212,9 @@ export interface AppHeaderProps<
|
|
|
212
212
|
export type AppVueTable<
|
|
213
213
|
TFeatures extends TableFeatures,
|
|
214
214
|
TData extends RowData,
|
|
215
|
-
TSelected,
|
|
216
215
|
TTableComponents extends Record<string, ComponentType<any>>,
|
|
217
|
-
|
|
218
|
-
|
|
216
|
+
_TCellComponents extends Record<string, ComponentType<any>>,
|
|
217
|
+
_THeaderComponents extends Record<string, ComponentType<any>>,
|
|
219
218
|
> = VueTable<TFeatures, TData> &
|
|
220
219
|
NoInfer<TTableComponents> & {
|
|
221
220
|
AppTable: Component<AppTableProps>
|
|
@@ -225,19 +224,88 @@ export type AppVueTable<
|
|
|
225
224
|
FlexRender: typeof AppFlexRender
|
|
226
225
|
}
|
|
227
226
|
|
|
227
|
+
export interface CreateTableHookResult<
|
|
228
|
+
TFeatures extends TableFeatures,
|
|
229
|
+
TTableComponents extends Record<string, ComponentType<any>>,
|
|
230
|
+
TCellComponents extends Record<string, ComponentType<any>>,
|
|
231
|
+
THeaderComponents extends Record<string, ComponentType<any>>,
|
|
232
|
+
> {
|
|
233
|
+
/** The features object that was passed to `createTableHook`. */
|
|
234
|
+
appFeatures: TFeatures
|
|
235
|
+
/**
|
|
236
|
+
* A column helper pre-bound to `TFeatures` and the registered components, so
|
|
237
|
+
* the cell/header/footer render props expose the bound components.
|
|
238
|
+
*/
|
|
239
|
+
createAppColumnHelper: <TData extends RowData>() => AppColumnHelper<
|
|
240
|
+
TFeatures,
|
|
241
|
+
TData,
|
|
242
|
+
TCellComponents,
|
|
243
|
+
THeaderComponents
|
|
244
|
+
>
|
|
245
|
+
/**
|
|
246
|
+
* Creates a table with the `App*` wrapper components and registered
|
|
247
|
+
* `tableComponents` attached. `TData` is inferred from the `data` option.
|
|
248
|
+
*/
|
|
249
|
+
useAppTable: <TData extends RowData>(
|
|
250
|
+
tableOptions: Omit<
|
|
251
|
+
TableOptionsWithReactiveData<TFeatures, TData>,
|
|
252
|
+
'features'
|
|
253
|
+
>,
|
|
254
|
+
) => AppVueTable<
|
|
255
|
+
TFeatures,
|
|
256
|
+
TData,
|
|
257
|
+
TTableComponents,
|
|
258
|
+
TCellComponents,
|
|
259
|
+
THeaderComponents
|
|
260
|
+
>
|
|
261
|
+
/**
|
|
262
|
+
* Reads the table provided by the nearest `<table.AppTable>`. This is the same
|
|
263
|
+
* extended instance `useAppTable` returns, so the `App*` components and your
|
|
264
|
+
* `tableComponents` are available on it.
|
|
265
|
+
*/
|
|
266
|
+
useTableContext: <TData extends RowData = RowData>() => AppVueTable<
|
|
267
|
+
TFeatures,
|
|
268
|
+
TData,
|
|
269
|
+
TTableComponents,
|
|
270
|
+
TCellComponents,
|
|
271
|
+
THeaderComponents
|
|
272
|
+
>
|
|
273
|
+
/**
|
|
274
|
+
* Reads the cell provided by the nearest `<table.AppCell>`, extended with your
|
|
275
|
+
* `cellComponents` and a context-bound `FlexRender`.
|
|
276
|
+
*/
|
|
277
|
+
useCellContext: <TValue extends CellData = CellData>() => Cell<
|
|
278
|
+
TFeatures,
|
|
279
|
+
any,
|
|
280
|
+
TValue
|
|
281
|
+
> &
|
|
282
|
+
TCellComponents & { FlexRender: Component }
|
|
283
|
+
/**
|
|
284
|
+
* Reads the header provided by the nearest `<table.AppHeader>` /
|
|
285
|
+
* `<table.AppFooter>`, extended with your `headerComponents` and a
|
|
286
|
+
* context-bound `FlexRender`.
|
|
287
|
+
*/
|
|
288
|
+
useHeaderContext: <TValue extends CellData = CellData>() => Header<
|
|
289
|
+
TFeatures,
|
|
290
|
+
any,
|
|
291
|
+
TValue
|
|
292
|
+
> &
|
|
293
|
+
THeaderComponents & { FlexRender: Component }
|
|
294
|
+
}
|
|
295
|
+
|
|
228
296
|
export const AppFlexRender = defineComponent({
|
|
229
297
|
name: 'TableFlexRender',
|
|
230
298
|
props: {
|
|
231
299
|
cell: {
|
|
232
|
-
type: Object as PropType<
|
|
300
|
+
type: Object as PropType<FlexRenderCell>,
|
|
233
301
|
default: undefined,
|
|
234
302
|
},
|
|
235
303
|
header: {
|
|
236
|
-
type: Object as PropType<
|
|
304
|
+
type: Object as PropType<FlexRenderHeader>,
|
|
237
305
|
default: undefined,
|
|
238
306
|
},
|
|
239
307
|
footer: {
|
|
240
|
-
type: Object as PropType<
|
|
308
|
+
type: Object as PropType<FlexRenderHeader>,
|
|
241
309
|
default: undefined,
|
|
242
310
|
},
|
|
243
311
|
},
|
|
@@ -280,7 +348,6 @@ export const AppFlexRender = defineComponent({
|
|
|
280
348
|
* ```ts
|
|
281
349
|
* const { useAppTable, createAppColumnHelper } = createTableHook({
|
|
282
350
|
* features,
|
|
283
|
-
* rowModels: {},
|
|
284
351
|
* tableComponents: {},
|
|
285
352
|
* cellComponents: {},
|
|
286
353
|
* headerComponents: {},
|
|
@@ -302,7 +369,12 @@ export function createTableHook<
|
|
|
302
369
|
TTableComponents,
|
|
303
370
|
TCellComponents,
|
|
304
371
|
THeaderComponents
|
|
305
|
-
>)
|
|
372
|
+
>): CreateTableHookResult<
|
|
373
|
+
TFeatures,
|
|
374
|
+
TTableComponents,
|
|
375
|
+
TCellComponents,
|
|
376
|
+
THeaderComponents
|
|
377
|
+
> {
|
|
306
378
|
const TableContext = Symbol('TableContext') as InjectionKey<
|
|
307
379
|
VueTable<TFeatures, any>
|
|
308
380
|
>
|
|
@@ -327,9 +399,12 @@ export function createTableHook<
|
|
|
327
399
|
>
|
|
328
400
|
}
|
|
329
401
|
|
|
330
|
-
function useTableContext<TData extends RowData = RowData>():
|
|
402
|
+
function useTableContext<TData extends RowData = RowData>(): AppVueTable<
|
|
331
403
|
TFeatures,
|
|
332
|
-
TData
|
|
404
|
+
TData,
|
|
405
|
+
TTableComponents,
|
|
406
|
+
TCellComponents,
|
|
407
|
+
THeaderComponents
|
|
333
408
|
> {
|
|
334
409
|
const table = inject(TableContext)
|
|
335
410
|
|
|
@@ -340,14 +415,24 @@ export function createTableHook<
|
|
|
340
415
|
)
|
|
341
416
|
}
|
|
342
417
|
|
|
343
|
-
|
|
418
|
+
// The value provided by `<table.AppTable>` is the extended table (the App*
|
|
419
|
+
// wrapper components and `tableComponents` are Object.assign-ed onto the same
|
|
420
|
+
// instance `useAppTable` returns), so this asserts the runtime shape.
|
|
421
|
+
return table as unknown as AppVueTable<
|
|
422
|
+
TFeatures,
|
|
423
|
+
TData,
|
|
424
|
+
TTableComponents,
|
|
425
|
+
TCellComponents,
|
|
426
|
+
THeaderComponents
|
|
427
|
+
>
|
|
344
428
|
}
|
|
345
429
|
|
|
346
430
|
function useCellContext<TValue extends CellData = CellData>(): Cell<
|
|
347
431
|
TFeatures,
|
|
348
432
|
any,
|
|
349
433
|
TValue
|
|
350
|
-
>
|
|
434
|
+
> &
|
|
435
|
+
TCellComponents & { FlexRender: Component } {
|
|
351
436
|
const cell = inject(CellContext)
|
|
352
437
|
|
|
353
438
|
if (!cell) {
|
|
@@ -357,14 +442,18 @@ export function createTableHook<
|
|
|
357
442
|
)
|
|
358
443
|
}
|
|
359
444
|
|
|
360
|
-
|
|
445
|
+
// `<table.AppCell>` Object.assign-es `cellComponents` and `FlexRender` onto
|
|
446
|
+
// the same cell instance it provides, so this asserts the runtime shape.
|
|
447
|
+
return cell as unknown as Cell<TFeatures, any, TValue> &
|
|
448
|
+
TCellComponents & { FlexRender: Component }
|
|
361
449
|
}
|
|
362
450
|
|
|
363
451
|
function useHeaderContext<TValue extends CellData = CellData>(): Header<
|
|
364
452
|
TFeatures,
|
|
365
453
|
any,
|
|
366
454
|
TValue
|
|
367
|
-
>
|
|
455
|
+
> &
|
|
456
|
+
THeaderComponents & { FlexRender: Component } {
|
|
368
457
|
const header = inject(HeaderContext)
|
|
369
458
|
|
|
370
459
|
if (!header) {
|
|
@@ -373,7 +462,10 @@ export function createTableHook<
|
|
|
373
462
|
)
|
|
374
463
|
}
|
|
375
464
|
|
|
376
|
-
|
|
465
|
+
// `<table.AppHeader>` / `<table.AppFooter>` Object.assign `headerComponents`
|
|
466
|
+
// and `FlexRender` onto the same header instance they provide.
|
|
467
|
+
return header as unknown as Header<TFeatures, any, TValue> &
|
|
468
|
+
THeaderComponents & { FlexRender: Component }
|
|
377
469
|
}
|
|
378
470
|
|
|
379
471
|
const CellFlexRender = defineComponent({
|
|
@@ -403,12 +495,11 @@ export function createTableHook<
|
|
|
403
495
|
function useAppTable<TData extends RowData>(
|
|
404
496
|
tableOptions: Omit<
|
|
405
497
|
TableOptionsWithReactiveData<TFeatures, TData>,
|
|
406
|
-
'features'
|
|
498
|
+
'features'
|
|
407
499
|
>,
|
|
408
500
|
): AppVueTable<
|
|
409
501
|
TFeatures,
|
|
410
502
|
TData,
|
|
411
|
-
TableState<TFeatures>,
|
|
412
503
|
TTableComponents,
|
|
413
504
|
TCellComponents,
|
|
414
505
|
THeaderComponents
|
|
@@ -515,7 +606,6 @@ export function createTableHook<
|
|
|
515
606
|
}) as AppVueTable<
|
|
516
607
|
TFeatures,
|
|
517
608
|
TData,
|
|
518
|
-
TableState<TFeatures>,
|
|
519
609
|
TTableComponents,
|
|
520
610
|
TCellComponents,
|
|
521
611
|
THeaderComponents
|
|
@@ -523,6 +613,8 @@ export function createTableHook<
|
|
|
523
613
|
}
|
|
524
614
|
|
|
525
615
|
return {
|
|
616
|
+
// `TableOptionsWithReactiveData` widens `features` to allow a reactive ref,
|
|
617
|
+
// so this narrows it back to the resolved `TFeatures` for `appFeatures`.
|
|
526
618
|
appFeatures: defaultTableOptions.features as TFeatures,
|
|
527
619
|
createAppColumnHelper,
|
|
528
620
|
useAppTable,
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from '@tanstack/table-core/experimental-worker-plugin'
|
package/src/reactivity.ts
CHANGED
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import { computed, shallowRef, watch } from 'vue'
|
|
2
|
-
import { batch } from '@tanstack/store'
|
|
3
2
|
import type {
|
|
4
3
|
TableAtomOptions,
|
|
5
4
|
TableReactivityBindings,
|
|
@@ -84,6 +83,6 @@ export function vueReactivity(): TableReactivityBindings {
|
|
|
84
83
|
return refToWritableAtom(shallowRef(value) as ShallowRef<T>)
|
|
85
84
|
},
|
|
86
85
|
untrack: (fn) => fn(),
|
|
87
|
-
batch,
|
|
86
|
+
batch: (fn) => fn(),
|
|
88
87
|
}
|
|
89
88
|
}
|
package/src/useTable.ts
CHANGED
|
@@ -7,7 +7,6 @@ import type {
|
|
|
7
7
|
Table,
|
|
8
8
|
TableFeatures,
|
|
9
9
|
TableOptions,
|
|
10
|
-
TableState,
|
|
11
10
|
} from '@tanstack/table-core'
|
|
12
11
|
import type { MaybeRef, VNode } from 'vue'
|
|
13
12
|
|
|
@@ -47,13 +46,7 @@ function getReactiveOptionDeps<
|
|
|
47
46
|
export type VueTable<
|
|
48
47
|
TFeatures extends TableFeatures,
|
|
49
48
|
TData extends RowData,
|
|
50
|
-
> =
|
|
51
|
-
/**
|
|
52
|
-
* @deprecated Prefer `table.atoms.<slice>.get()` for slice snapshots, or
|
|
53
|
-
* `table.Subscribe` for explicit subscriptions. `table.store.state` is a
|
|
54
|
-
* current-value snapshot and is easy to misuse in render code.
|
|
55
|
-
*/
|
|
56
|
-
readonly store: Table<TFeatures, TData>['store']
|
|
49
|
+
> = Table<TFeatures, TData> & {
|
|
57
50
|
/** Creates a reactive render boundary. The child function reads the table
|
|
58
51
|
* atoms it needs, so Vue only tracks those atom reads.
|
|
59
52
|
*/
|
|
@@ -75,7 +68,6 @@ export type VueTable<
|
|
|
75
68
|
* const table = useTable(
|
|
76
69
|
* {
|
|
77
70
|
* features,
|
|
78
|
-
* rowModels: {},
|
|
79
71
|
* columns,
|
|
80
72
|
* data,
|
|
81
73
|
* },
|
|
@@ -103,7 +95,7 @@ export function useTable<
|
|
|
103
95
|
|
|
104
96
|
const mergedOptions = mergeProxy(tableOptions, {
|
|
105
97
|
features: {
|
|
106
|
-
|
|
98
|
+
coreReactivityFeature: reactivity,
|
|
107
99
|
...(unref(tableOptions.features) ?? {}),
|
|
108
100
|
},
|
|
109
101
|
}) as TableOptionsWithReactiveData<TFeatures, TData>
|
|
@@ -174,7 +166,7 @@ export function useTable<
|
|
|
174
166
|
table.Subscribe = (props: {
|
|
175
167
|
children: (atoms: Table<TFeatures, TData>['atoms']) => VNode | Array<VNode>
|
|
176
168
|
}) => {
|
|
177
|
-
return props.children(table.atoms)
|
|
169
|
+
return props.children(table.atoms as Table<TFeatures, TData>['atoms'])
|
|
178
170
|
}
|
|
179
171
|
|
|
180
172
|
return table
|