@tanstack/vue-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.
Files changed (61) hide show
  1. package/README.md +5 -1
  2. package/dist/FlexRender.d.ts +1 -2
  3. package/dist/FlexRender.js +5 -5
  4. package/dist/createTableHook.d.ts +40 -20
  5. package/dist/createTableHook.js +10 -24
  6. package/dist/experimental-worker-plugin.d.ts +1 -0
  7. package/dist/experimental-worker-plugin.js +3 -0
  8. package/dist/index.d.ts +2 -2
  9. package/dist/merge-proxy.js +1 -2
  10. package/dist/reactivity.js +3 -8
  11. package/dist/useTable.d.ts +3 -12
  12. package/dist/useTable.js +7 -11
  13. package/package.json +14 -22
  14. package/skills/create-table-hook/SKILL.md +146 -0
  15. package/skills/getting-started/SKILL.md +144 -0
  16. package/skills/migrate-v8-to-v9/SKILL.md +185 -0
  17. package/skills/table-state/SKILL.md +191 -0
  18. package/skills/with-tanstack-query/SKILL.md +127 -0
  19. package/skills/with-tanstack-virtual/SKILL.md +116 -0
  20. package/dist/FlexRender.cjs +0 -80
  21. package/dist/FlexRender.cjs.map +0 -1
  22. package/dist/FlexRender.d.cts +0 -63
  23. package/dist/FlexRender.js.map +0 -1
  24. package/dist/createTableHook.cjs +0 -194
  25. package/dist/createTableHook.cjs.map +0 -1
  26. package/dist/createTableHook.d.cts +0 -135
  27. package/dist/createTableHook.js.map +0 -1
  28. package/dist/flex-render.cjs +0 -5
  29. package/dist/flex-render.d.cts +0 -2
  30. package/dist/index.cjs +0 -17
  31. package/dist/index.d.cts +0 -5
  32. package/dist/merge-proxy.cjs +0 -77
  33. package/dist/merge-proxy.cjs.map +0 -1
  34. package/dist/merge-proxy.js.map +0 -1
  35. package/dist/reactivity.cjs +0 -64
  36. package/dist/reactivity.cjs.map +0 -1
  37. package/dist/reactivity.js.map +0 -1
  38. package/dist/static-functions.cjs +0 -9
  39. package/dist/static-functions.d.cts +0 -1
  40. package/dist/useTable.cjs +0 -76
  41. package/dist/useTable.cjs.map +0 -1
  42. package/dist/useTable.d.cts +0 -43
  43. package/dist/useTable.js.map +0 -1
  44. package/skills/vue/client-to-server/SKILL.md +0 -365
  45. package/skills/vue/compose-with-tanstack-form/SKILL.md +0 -369
  46. package/skills/vue/compose-with-tanstack-pacer/SKILL.md +0 -318
  47. package/skills/vue/compose-with-tanstack-query/SKILL.md +0 -385
  48. package/skills/vue/compose-with-tanstack-store/SKILL.md +0 -301
  49. package/skills/vue/compose-with-tanstack-virtual/SKILL.md +0 -340
  50. package/skills/vue/getting-started/SKILL.md +0 -409
  51. package/skills/vue/migrate-v8-to-v9/SKILL.md +0 -375
  52. package/skills/vue/production-readiness/SKILL.md +0 -271
  53. package/skills/vue/table-state/SKILL.md +0 -403
  54. package/src/FlexRender.ts +0 -138
  55. package/src/createTableHook.ts +0 -534
  56. package/src/flex-render.ts +0 -1
  57. package/src/index.ts +0 -4
  58. package/src/merge-proxy.ts +0 -132
  59. package/src/reactivity.ts +0 -89
  60. package/src/static-functions.ts +0 -1
  61. package/src/useTable.ts +0 -181
package/src/reactivity.ts DELETED
@@ -1,89 +0,0 @@
1
- import { computed, shallowRef, watch } from 'vue'
2
- import { batch } from '@tanstack/store'
3
- import type {
4
- TableAtomOptions,
5
- TableReactivityBindings,
6
- } from '@tanstack/table-core/reactivity'
7
- import type {
8
- Atom,
9
- Observer,
10
- ReadonlyAtom,
11
- Subscription,
12
- } from '@tanstack/store'
13
- import type { ComputedRef, ShallowRef } from 'vue'
14
-
15
- function observerToCallback<T>(
16
- observerOrNext: Observer<T> | ((value: T) => void),
17
- ): (value: T) => void {
18
- return typeof observerOrNext === 'function'
19
- ? observerOrNext
20
- : (value) => observerOrNext.next?.(value)
21
- }
22
-
23
- function refToReadonlyAtom<T>(
24
- source: ComputedRef<T> | ShallowRef<T>,
25
- ): ReadonlyAtom<T> {
26
- return Object.assign(source, {
27
- get: () => source.value,
28
- subscribe: ((observerOrNext: Observer<T> | ((value: T) => void)) => {
29
- const stop = watch(source, observerToCallback(observerOrNext), {
30
- flush: 'sync',
31
- })
32
- return { unsubscribe: stop }
33
- }) as ReadonlyAtom<T>['subscribe'],
34
- })
35
- }
36
-
37
- function refToWritableAtom<T>(source: ShallowRef<T>): Atom<T> {
38
- return Object.assign(source, {
39
- set: (updater: T | ((prevVal: T) => T)) => {
40
- source.value =
41
- typeof updater === 'function'
42
- ? (updater as (prevVal: T) => T)(source.value)
43
- : updater
44
- },
45
- get: () => source.value,
46
- subscribe: ((observerOrNext: Observer<T> | ((value: T) => void)) => {
47
- const stop = watch(source, observerToCallback(observerOrNext), {
48
- flush: 'sync',
49
- })
50
- return { unsubscribe: stop }
51
- }) as Atom<T>['subscribe'],
52
- })
53
- }
54
-
55
- /**
56
- * Creates the table-core reactivity bindings used by the Vue adapter.
57
- *
58
- * Table state atoms are backed by TanStack Store atoms. The options store stays
59
- * framework-native because row-model APIs read `table.options` directly during
60
- * render. Readonly table atoms bridge Store dependency tracking into Vue computed
61
- * refs.
62
- */
63
- export function vueReactivity(): TableReactivityBindings {
64
- const subscriptions = new Set<Subscription>()
65
-
66
- return {
67
- createOptionsStore: true,
68
- wrapExternalAtoms: true,
69
- addSubscription: (subscription) => {
70
- subscriptions.add(subscription)
71
- },
72
- unmount: () => {
73
- subscriptions.forEach((s) => s.unsubscribe())
74
- subscriptions.clear()
75
- },
76
- schedule: (fn) => queueMicrotask(() => fn()),
77
- createReadonlyAtom: <T>(fn: () => T, _options?: TableAtomOptions<T>) => {
78
- return refToReadonlyAtom(computed(() => fn()))
79
- },
80
- createWritableAtom: <T>(
81
- value: T,
82
- _options?: TableAtomOptions<T>,
83
- ): Atom<T> => {
84
- return refToWritableAtom(shallowRef(value) as ShallowRef<T>)
85
- },
86
- untrack: (fn) => fn(),
87
- batch,
88
- }
89
- }
@@ -1 +0,0 @@
1
- export * from '@tanstack/table-core/static-functions'
package/src/useTable.ts DELETED
@@ -1,181 +0,0 @@
1
- import { getCurrentScope, onScopeDispose, unref, watch } from 'vue'
2
- import { constructTable } from '@tanstack/table-core'
3
- import { flatMerge, mergeProxy } from './merge-proxy'
4
- import { vueReactivity } from './reactivity'
5
- import type {
6
- RowData,
7
- Table,
8
- TableFeatures,
9
- TableOptions,
10
- TableState,
11
- } from '@tanstack/table-core'
12
- import type { MaybeRef, VNode } from 'vue'
13
-
14
- export type TableOptionsWithReactiveData<
15
- TFeatures extends TableFeatures,
16
- TData extends RowData,
17
- > = {
18
- [K in keyof TableOptions<TFeatures, TData>]: K extends 'data'
19
- ? MaybeRef<ReadonlyArray<TData>>
20
- : MaybeRef<TableOptions<TFeatures, TData>[K]>
21
- }
22
-
23
- function getOptionsWithReactiveValues<
24
- TFeatures extends TableFeatures,
25
- TData extends RowData,
26
- >(options: TableOptionsWithReactiveData<TFeatures, TData>) {
27
- const resolvedOptions: Record<string, unknown> = {}
28
-
29
- for (const key of Object.keys(options)) {
30
- resolvedOptions[key] = unref(
31
- options[key as keyof TableOptionsWithReactiveData<TFeatures, TData>],
32
- )
33
- }
34
-
35
- return mergeProxy(options, resolvedOptions)
36
- }
37
-
38
- function getReactiveOptionDeps<
39
- TFeatures extends TableFeatures,
40
- TData extends RowData,
41
- >(options: TableOptionsWithReactiveData<TFeatures, TData>) {
42
- return Object.keys(options).map((key) =>
43
- unref(options[key as keyof TableOptionsWithReactiveData<TFeatures, TData>]),
44
- )
45
- }
46
-
47
- export type VueTable<
48
- TFeatures extends TableFeatures,
49
- TData extends RowData,
50
- > = Omit<Table<TFeatures, TData>, 'store'> & {
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']
57
- /** Creates a reactive render boundary. The child function reads the table
58
- * atoms it needs, so Vue only tracks those atom reads.
59
- */
60
- Subscribe: (props: {
61
- children: (atoms: Table<TFeatures, TData>['atoms']) => VNode | Array<VNode>
62
- }) => VNode | Array<VNode>
63
- }
64
-
65
- /**
66
- * Creates a Vue table instance backed by Vue-aware TanStack Store atoms.
67
- *
68
- * Table options may contain Vue refs or computed values. The adapter unwraps
69
- * those reactive inputs, watches them with synchronous flushing, and keeps the
70
- * table options in sync. Use `table.Subscribe` or native Vue computed values
71
- * around `table.atoms.<slice>.get()` for selected reactive reads.
72
- *
73
- * @example
74
- * ```ts
75
- * const table = useTable(
76
- * {
77
- * features,
78
- * rowModels: {},
79
- * columns,
80
- * data,
81
- * },
82
- * )
83
- * ```
84
- */
85
- export function useTable<
86
- TFeatures extends TableFeatures,
87
- TData extends RowData,
88
- >(
89
- tableOptions:
90
- | TableOptions<TFeatures, TData>
91
- | TableOptionsWithReactiveData<TFeatures, TData>,
92
- ): VueTable<TFeatures, TData> {
93
- const syncTableOptions = (
94
- table: Table<TFeatures, TData>,
95
- options: TableOptionsWithReactiveData<TFeatures, TData>,
96
- ) => {
97
- table.setOptions((prev) =>
98
- flatMerge(prev, getOptionsWithReactiveValues(options)),
99
- )
100
- }
101
-
102
- const reactivity = vueReactivity()
103
-
104
- const mergedOptions = mergeProxy(tableOptions, {
105
- features: {
106
- coreReativityFeature: reactivity,
107
- ...(unref(tableOptions.features) ?? {}),
108
- },
109
- }) as TableOptionsWithReactiveData<TFeatures, TData>
110
-
111
- const resolvedOptions = mergeProxy(
112
- getOptionsWithReactiveValues(mergedOptions),
113
- {
114
- // Remove state and onStateChange - store handles it internally
115
- mergeOptions: (
116
- defaultOptions: TableOptions<TFeatures, TData>,
117
- newOptions: Partial<TableOptions<TFeatures, TData>>,
118
- ) => {
119
- return flatMerge(defaultOptions, newOptions)
120
- },
121
- },
122
- ) as TableOptions<TFeatures, TData>
123
-
124
- const coreTable = constructTable(resolvedOptions)
125
- const table = coreTable as unknown as VueTable<TFeatures, TData>
126
-
127
- if (getCurrentScope()) {
128
- onScopeDispose(() => reactivity.unmount?.())
129
- }
130
-
131
- watch(
132
- () => getReactiveOptionDeps(mergedOptions),
133
- () => {
134
- syncTableOptions(coreTable, mergedOptions)
135
- },
136
- { immediate: true },
137
- )
138
-
139
- watch(
140
- () => {
141
- const controlledState = unref(tableOptions.state) as
142
- | Record<string, unknown>
143
- | undefined
144
- const controlledAtoms = unref(tableOptions.atoms) as
145
- | Record<string, unknown>
146
- | undefined
147
-
148
- if (!controlledState) {
149
- return []
150
- }
151
-
152
- const controlledValues: Array<unknown> = []
153
-
154
- for (const key of Object.keys(table.initialState)) {
155
- if (!(key in controlledState) || controlledAtoms?.[key] !== undefined) {
156
- continue
157
- }
158
-
159
- // Reading only controlled state slices here lets Vue subscribe to
160
- // getters/computed values that are passed through `options.state`.
161
- controlledValues.push(controlledState[key])
162
- }
163
-
164
- return controlledValues
165
- },
166
- (controlledValues) => {
167
- if (controlledValues.length > 0) {
168
- syncTableOptions(coreTable, mergedOptions)
169
- }
170
- },
171
- { immediate: true },
172
- )
173
-
174
- table.Subscribe = (props: {
175
- children: (atoms: Table<TFeatures, TData>['atoms']) => VNode | Array<VNode>
176
- }) => {
177
- return props.children(table.atoms)
178
- }
179
-
180
- return table
181
- }