@tanstack/vue-table 9.0.0-beta.51 → 9.0.0-beta.53

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 (50) hide show
  1. package/dist/FlexRender.d.ts +1 -2
  2. package/dist/FlexRender.js +1 -2
  3. package/dist/createTableHook.d.ts +1 -2
  4. package/dist/createTableHook.js +1 -2
  5. package/dist/merge-proxy.js +1 -2
  6. package/dist/reactivity.js +1 -2
  7. package/dist/useTable.d.ts +1 -2
  8. package/dist/useTable.js +1 -2
  9. package/package.json +7 -22
  10. package/skills/create-table-hook/SKILL.md +2 -2
  11. package/skills/getting-started/SKILL.md +2 -2
  12. package/skills/migrate-v8-to-v9/SKILL.md +2 -2
  13. package/skills/table-state/SKILL.md +2 -2
  14. package/skills/with-tanstack-query/SKILL.md +2 -2
  15. package/skills/with-tanstack-virtual/SKILL.md +2 -2
  16. package/dist/FlexRender.cjs +0 -79
  17. package/dist/FlexRender.cjs.map +0 -1
  18. package/dist/FlexRender.d.cts +0 -63
  19. package/dist/FlexRender.js.map +0 -1
  20. package/dist/createTableHook.cjs +0 -189
  21. package/dist/createTableHook.cjs.map +0 -1
  22. package/dist/createTableHook.d.cts +0 -162
  23. package/dist/createTableHook.js.map +0 -1
  24. package/dist/experimental-worker-plugin.cjs +0 -9
  25. package/dist/experimental-worker-plugin.d.cts +0 -1
  26. package/dist/flex-render.cjs +0 -5
  27. package/dist/flex-render.d.cts +0 -2
  28. package/dist/index.cjs +0 -17
  29. package/dist/index.d.cts +0 -5
  30. package/dist/merge-proxy.cjs +0 -77
  31. package/dist/merge-proxy.cjs.map +0 -1
  32. package/dist/merge-proxy.js.map +0 -1
  33. package/dist/reactivity.cjs +0 -60
  34. package/dist/reactivity.cjs.map +0 -1
  35. package/dist/reactivity.js.map +0 -1
  36. package/dist/static-functions.cjs +0 -9
  37. package/dist/static-functions.d.cts +0 -1
  38. package/dist/useTable.cjs +0 -72
  39. package/dist/useTable.cjs.map +0 -1
  40. package/dist/useTable.d.cts +0 -36
  41. package/dist/useTable.js.map +0 -1
  42. package/src/FlexRender.ts +0 -138
  43. package/src/createTableHook.ts +0 -625
  44. package/src/experimental-worker-plugin.ts +0 -1
  45. package/src/flex-render.ts +0 -1
  46. package/src/index.ts +0 -4
  47. package/src/merge-proxy.ts +0 -132
  48. package/src/reactivity.ts +0 -88
  49. package/src/static-functions.ts +0 -1
  50. package/src/useTable.ts +0 -173
@@ -1,132 +0,0 @@
1
- function trueFn() {
2
- return true
3
- }
4
-
5
- const $PROXY = Symbol('merge-proxy')
6
- const $SOURCES = Symbol('merge-proxy-sources')
7
-
8
- // https://github.com/solidjs/solid/blob/c20ca4fd8c36bc0522fedb2c7f38a110b7ee2663/packages/solid/src/render/component.ts#L51-L118
9
- const propTraps: ProxyHandler<{
10
- get: (k: string | number | symbol) => any
11
- has: (k: string | number | symbol) => boolean
12
- keys: () => Array<string>
13
- sources: Array<any>
14
- }> = {
15
- get(_, property, receiver) {
16
- if (property === $PROXY) return receiver
17
- if (property === $SOURCES) return _.sources
18
- return _.get(property)
19
- },
20
- has(_, property) {
21
- return _.has(property)
22
- },
23
- set: trueFn,
24
- deleteProperty: trueFn,
25
- getOwnPropertyDescriptor(_, property) {
26
- return {
27
- configurable: true,
28
- enumerable: true,
29
- get() {
30
- return _.get(property)
31
- },
32
- set: trueFn,
33
- deleteProperty: trueFn,
34
- }
35
- },
36
- ownKeys(_) {
37
- return _.keys()
38
- },
39
- }
40
-
41
- type UnboxLazy<T> = T extends () => infer U ? U : T
42
- type BoxedTupleTypes<T extends Array<any>> = {
43
- [P in keyof T]: [UnboxLazy<T[P]>]
44
- }[Exclude<keyof T, keyof Array<any>>]
45
- type UnionToIntersection<T> = (T extends any ? (k: T) => void : never) extends (
46
- k: infer I,
47
- ) => void
48
- ? I
49
- : never
50
- type UnboxIntersection<T> = T extends { 0: infer U } ? U : never
51
- type MergeProxy<T extends Array<any>> = UnboxIntersection<
52
- UnionToIntersection<BoxedTupleTypes<T>>
53
- >
54
-
55
- function resolveSource(s: any) {
56
- return s && typeof s === 'object' && 'value' in s ? s.value : s
57
- }
58
-
59
- export function mergeProxy<T extends Array<any>>(...sources: T): MergeProxy<T>
60
- export function mergeProxy(...sources: any): any {
61
- const flattenedSources = sources.flatMap((source: any) => {
62
- if (
63
- typeof source === 'object' &&
64
- source !== null &&
65
- $SOURCES in source &&
66
- Array.isArray(source[$SOURCES])
67
- ) {
68
- return source[$SOURCES]
69
- }
70
-
71
- return [source]
72
- })
73
-
74
- return new Proxy(
75
- {
76
- sources: flattenedSources,
77
- get(property: string | number | symbol) {
78
- for (let i = flattenedSources.length - 1; i >= 0; i--) {
79
- const v = resolveSource(flattenedSources[i])[property]
80
- if (v !== undefined) return v
81
- }
82
- },
83
- has(property: string | number | symbol) {
84
- for (let i = flattenedSources.length - 1; i >= 0; i--) {
85
- if (property in resolveSource(flattenedSources[i])) return true
86
- }
87
- return false
88
- },
89
- keys() {
90
- const keys = []
91
- for (const source of flattenedSources)
92
- keys.push(...Object.keys(resolveSource(source)))
93
- return [...Array.from(new Set(keys))]
94
- },
95
- },
96
- propTraps,
97
- )
98
- }
99
-
100
- /**
101
- * Merges objects together by eagerly resolving all values into a flat object.
102
- *
103
- * Unlike `mergeProxy`, this does not preserve lazy proxy getters. Use this for
104
- * repeated option update paths so each merge produces a plain object instead
105
- * of accumulating a longer source list over time.
106
- */
107
- export function flatMerge<T>(source: T): T
108
- export function flatMerge<T, U>(source: T, source1: U): T & U
109
- export function flatMerge<T, U, V>(source: T, source1: U, source2: V): T & U & V
110
- export function flatMerge<T, U, V, W>(
111
- source: T,
112
- source1: U,
113
- source2: V,
114
- source3: W,
115
- ): T & U & V & W
116
- export function flatMerge(...sources: any): any {
117
- const result: Record<PropertyKey, unknown> = {}
118
-
119
- for (let source of sources) {
120
- source = resolveSource(source)
121
- if (!source) continue
122
-
123
- for (const key of Reflect.ownKeys(source)) {
124
- const value = (source as Record<PropertyKey, unknown>)[key]
125
- if (value !== undefined) {
126
- result[key] = value
127
- }
128
- }
129
- }
130
-
131
- return result
132
- }
package/src/reactivity.ts DELETED
@@ -1,88 +0,0 @@
1
- import { computed, shallowRef, watch } from 'vue'
2
- import type {
3
- TableAtomOptions,
4
- TableReactivityBindings,
5
- } from '@tanstack/table-core/reactivity'
6
- import type {
7
- Atom,
8
- Observer,
9
- ReadonlyAtom,
10
- Subscription,
11
- } from '@tanstack/store'
12
- import type { ComputedRef, ShallowRef } from 'vue'
13
-
14
- function observerToCallback<T>(
15
- observerOrNext: Observer<T> | ((value: T) => void),
16
- ): (value: T) => void {
17
- return typeof observerOrNext === 'function'
18
- ? observerOrNext
19
- : (value) => observerOrNext.next?.(value)
20
- }
21
-
22
- function refToReadonlyAtom<T>(
23
- source: ComputedRef<T> | ShallowRef<T>,
24
- ): ReadonlyAtom<T> {
25
- return Object.assign(source, {
26
- get: () => source.value,
27
- subscribe: ((observerOrNext: Observer<T> | ((value: T) => void)) => {
28
- const stop = watch(source, observerToCallback(observerOrNext), {
29
- flush: 'sync',
30
- })
31
- return { unsubscribe: stop }
32
- }) as ReadonlyAtom<T>['subscribe'],
33
- })
34
- }
35
-
36
- function refToWritableAtom<T>(source: ShallowRef<T>): Atom<T> {
37
- return Object.assign(source, {
38
- set: (updater: T | ((prevVal: T) => T)) => {
39
- source.value =
40
- typeof updater === 'function'
41
- ? (updater as (prevVal: T) => T)(source.value)
42
- : updater
43
- },
44
- get: () => source.value,
45
- subscribe: ((observerOrNext: Observer<T> | ((value: T) => void)) => {
46
- const stop = watch(source, observerToCallback(observerOrNext), {
47
- flush: 'sync',
48
- })
49
- return { unsubscribe: stop }
50
- }) as Atom<T>['subscribe'],
51
- })
52
- }
53
-
54
- /**
55
- * Creates the table-core reactivity bindings used by the Vue adapter.
56
- *
57
- * Table state atoms are backed by TanStack Store atoms. The options store stays
58
- * framework-native because row-model APIs read `table.options` directly during
59
- * render. Readonly table atoms bridge Store dependency tracking into Vue computed
60
- * refs.
61
- */
62
- export function vueReactivity(): TableReactivityBindings {
63
- const subscriptions = new Set<Subscription>()
64
-
65
- return {
66
- createOptionsStore: true,
67
- wrapExternalAtoms: true,
68
- addSubscription: (subscription) => {
69
- subscriptions.add(subscription)
70
- },
71
- unmount: () => {
72
- subscriptions.forEach((s) => s.unsubscribe())
73
- subscriptions.clear()
74
- },
75
- schedule: (fn) => queueMicrotask(() => fn()),
76
- createReadonlyAtom: <T>(fn: () => T, _options?: TableAtomOptions<T>) => {
77
- return refToReadonlyAtom(computed(() => fn()))
78
- },
79
- createWritableAtom: <T>(
80
- value: T,
81
- _options?: TableAtomOptions<T>,
82
- ): Atom<T> => {
83
- return refToWritableAtom(shallowRef(value) as ShallowRef<T>)
84
- },
85
- untrack: (fn) => fn(),
86
- batch: (fn) => fn(),
87
- }
88
- }
@@ -1 +0,0 @@
1
- export * from '@tanstack/table-core/static-functions'
package/src/useTable.ts DELETED
@@ -1,173 +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
- } from '@tanstack/table-core'
11
- import type { MaybeRef, VNode } from 'vue'
12
-
13
- export type TableOptionsWithReactiveData<
14
- TFeatures extends TableFeatures,
15
- TData extends RowData,
16
- > = {
17
- [K in keyof TableOptions<TFeatures, TData>]: K extends 'data'
18
- ? MaybeRef<ReadonlyArray<TData>>
19
- : MaybeRef<TableOptions<TFeatures, TData>[K]>
20
- }
21
-
22
- function getOptionsWithReactiveValues<
23
- TFeatures extends TableFeatures,
24
- TData extends RowData,
25
- >(options: TableOptionsWithReactiveData<TFeatures, TData>) {
26
- const resolvedOptions: Record<string, unknown> = {}
27
-
28
- for (const key of Object.keys(options)) {
29
- resolvedOptions[key] = unref(
30
- options[key as keyof TableOptionsWithReactiveData<TFeatures, TData>],
31
- )
32
- }
33
-
34
- return mergeProxy(options, resolvedOptions)
35
- }
36
-
37
- function getReactiveOptionDeps<
38
- TFeatures extends TableFeatures,
39
- TData extends RowData,
40
- >(options: TableOptionsWithReactiveData<TFeatures, TData>) {
41
- return Object.keys(options).map((key) =>
42
- unref(options[key as keyof TableOptionsWithReactiveData<TFeatures, TData>]),
43
- )
44
- }
45
-
46
- export type VueTable<
47
- TFeatures extends TableFeatures,
48
- TData extends RowData,
49
- > = Table<TFeatures, TData> & {
50
- /** Creates a reactive render boundary. The child function reads the table
51
- * atoms it needs, so Vue only tracks those atom reads.
52
- */
53
- Subscribe: (props: {
54
- children: (atoms: Table<TFeatures, TData>['atoms']) => VNode | Array<VNode>
55
- }) => VNode | Array<VNode>
56
- }
57
-
58
- /**
59
- * Creates a Vue table instance backed by Vue-aware TanStack Store atoms.
60
- *
61
- * Table options may contain Vue refs or computed values. The adapter unwraps
62
- * those reactive inputs, watches them with synchronous flushing, and keeps the
63
- * table options in sync. Use `table.Subscribe` or native Vue computed values
64
- * around `table.atoms.<slice>.get()` for selected reactive reads.
65
- *
66
- * @example
67
- * ```ts
68
- * const table = useTable(
69
- * {
70
- * features,
71
- * columns,
72
- * data,
73
- * },
74
- * )
75
- * ```
76
- */
77
- export function useTable<
78
- TFeatures extends TableFeatures,
79
- TData extends RowData,
80
- >(
81
- tableOptions:
82
- | TableOptions<TFeatures, TData>
83
- | TableOptionsWithReactiveData<TFeatures, TData>,
84
- ): VueTable<TFeatures, TData> {
85
- const syncTableOptions = (
86
- table: Table<TFeatures, TData>,
87
- options: TableOptionsWithReactiveData<TFeatures, TData>,
88
- ) => {
89
- table.setOptions((prev) =>
90
- flatMerge(prev, getOptionsWithReactiveValues(options)),
91
- )
92
- }
93
-
94
- const reactivity = vueReactivity()
95
-
96
- const mergedOptions = mergeProxy(tableOptions, {
97
- features: {
98
- coreReactivityFeature: reactivity,
99
- ...(unref(tableOptions.features) ?? {}),
100
- },
101
- }) as TableOptionsWithReactiveData<TFeatures, TData>
102
-
103
- const resolvedOptions = mergeProxy(
104
- getOptionsWithReactiveValues(mergedOptions),
105
- {
106
- // Remove state and onStateChange - store handles it internally
107
- mergeOptions: (
108
- defaultOptions: TableOptions<TFeatures, TData>,
109
- newOptions: Partial<TableOptions<TFeatures, TData>>,
110
- ) => {
111
- return flatMerge(defaultOptions, newOptions)
112
- },
113
- },
114
- ) as TableOptions<TFeatures, TData>
115
-
116
- const coreTable = constructTable(resolvedOptions)
117
- const table = coreTable as unknown as VueTable<TFeatures, TData>
118
-
119
- if (getCurrentScope()) {
120
- onScopeDispose(() => reactivity.unmount?.())
121
- }
122
-
123
- watch(
124
- () => getReactiveOptionDeps(mergedOptions),
125
- () => {
126
- syncTableOptions(coreTable, mergedOptions)
127
- },
128
- { immediate: true },
129
- )
130
-
131
- watch(
132
- () => {
133
- const controlledState = unref(tableOptions.state) as
134
- | Record<string, unknown>
135
- | undefined
136
- const controlledAtoms = unref(tableOptions.atoms) as
137
- | Record<string, unknown>
138
- | undefined
139
-
140
- if (!controlledState) {
141
- return []
142
- }
143
-
144
- const controlledValues: Array<unknown> = []
145
-
146
- for (const key of Object.keys(table.initialState)) {
147
- if (!(key in controlledState) || controlledAtoms?.[key] !== undefined) {
148
- continue
149
- }
150
-
151
- // Reading only controlled state slices here lets Vue subscribe to
152
- // getters/computed values that are passed through `options.state`.
153
- controlledValues.push(controlledState[key])
154
- }
155
-
156
- return controlledValues
157
- },
158
- (controlledValues) => {
159
- if (controlledValues.length > 0) {
160
- syncTableOptions(coreTable, mergedOptions)
161
- }
162
- },
163
- { immediate: true },
164
- )
165
-
166
- table.Subscribe = (props: {
167
- children: (atoms: Table<TFeatures, TData>['atoms']) => VNode | Array<VNode>
168
- }) => {
169
- return props.children(table.atoms as Table<TFeatures, TData>['atoms'])
170
- }
171
-
172
- return table
173
- }