@tanstack/vue-table 8.19.4 → 8.20.1
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/build/lib/index.d.ts +5 -1
- package/build/lib/index.esm.js +16 -2
- package/build/lib/index.esm.js.map +1 -1
- package/build/lib/index.js +15 -1
- package/build/lib/index.js.map +1 -1
- package/build/lib/index.mjs +16 -2
- package/build/lib/index.mjs.map +1 -1
- package/build/umd/index.development.js +16 -2
- package/build/umd/index.development.js.map +1 -1
- package/build/umd/index.production.js +1 -1
- package/build/umd/index.production.js.map +1 -1
- package/package.json +2 -2
- package/src/index.ts +57 -17
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tanstack/vue-table",
|
|
3
|
-
"version": "8.
|
|
3
|
+
"version": "8.20.1",
|
|
4
4
|
"description": "Headless UI for building powerful tables & datagrids for Vue.",
|
|
5
5
|
"author": "Tanner Linsley",
|
|
6
6
|
"license": "MIT",
|
|
@@ -42,7 +42,7 @@
|
|
|
42
42
|
"src"
|
|
43
43
|
],
|
|
44
44
|
"dependencies": {
|
|
45
|
-
"@tanstack/table-core": "8.
|
|
45
|
+
"@tanstack/table-core": "8.20.1"
|
|
46
46
|
},
|
|
47
47
|
"devDependencies": {
|
|
48
48
|
"vue": "^3.4.31"
|
package/src/index.ts
CHANGED
|
@@ -4,11 +4,33 @@ import {
|
|
|
4
4
|
TableOptionsResolved,
|
|
5
5
|
RowData,
|
|
6
6
|
} from '@tanstack/table-core'
|
|
7
|
-
import {
|
|
7
|
+
import {
|
|
8
|
+
h,
|
|
9
|
+
watchEffect,
|
|
10
|
+
ref,
|
|
11
|
+
defineComponent,
|
|
12
|
+
isRef,
|
|
13
|
+
unref,
|
|
14
|
+
MaybeRef,
|
|
15
|
+
} from 'vue'
|
|
8
16
|
import { mergeProxy } from './merge-proxy'
|
|
9
17
|
|
|
10
18
|
export * from '@tanstack/table-core'
|
|
11
19
|
|
|
20
|
+
type TableOptionsWithReactiveData<TData extends RowData> = Omit<
|
|
21
|
+
TableOptions<TData>,
|
|
22
|
+
'data'
|
|
23
|
+
> & {
|
|
24
|
+
data: MaybeRef<TData[]>
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
type TableOptionsResolvedWithReactiveData<TData extends RowData> = Omit<
|
|
28
|
+
TableOptionsResolved<TData>,
|
|
29
|
+
'data'
|
|
30
|
+
> & {
|
|
31
|
+
data: MaybeRef<TData[]>
|
|
32
|
+
}
|
|
33
|
+
|
|
12
34
|
export const FlexRender = defineComponent({
|
|
13
35
|
props: ['render', 'props'],
|
|
14
36
|
setup: (props: { render: any; props: any }) => {
|
|
@@ -26,24 +48,32 @@ export const FlexRender = defineComponent({
|
|
|
26
48
|
})
|
|
27
49
|
|
|
28
50
|
export function useVueTable<TData extends RowData>(
|
|
29
|
-
options:
|
|
51
|
+
options: TableOptionsWithReactiveData<TData>
|
|
30
52
|
) {
|
|
31
|
-
const resolvedOptions:
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
53
|
+
const resolvedOptions: TableOptionsResolvedWithReactiveData<TData> =
|
|
54
|
+
mergeProxy(
|
|
55
|
+
{
|
|
56
|
+
state: {}, // Dummy state
|
|
57
|
+
onStateChange: () => {}, // noop
|
|
58
|
+
renderFallbackValue: null,
|
|
59
|
+
mergeOptions(
|
|
60
|
+
defaultOptions: TableOptions<TData>,
|
|
61
|
+
options: TableOptions<TData>
|
|
62
|
+
) {
|
|
63
|
+
return mergeProxy(defaultOptions, options)
|
|
64
|
+
},
|
|
41
65
|
},
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
66
|
+
options
|
|
67
|
+
)
|
|
68
|
+
|
|
69
|
+
// Add support for reactivity
|
|
70
|
+
if (isRef(options.data)) {
|
|
71
|
+
resolvedOptions.data = unref(options.data)
|
|
72
|
+
}
|
|
45
73
|
|
|
46
|
-
const table = createTable<TData>(
|
|
74
|
+
const table = createTable<TData>(
|
|
75
|
+
resolvedOptions as TableOptionsResolved<TData>
|
|
76
|
+
)
|
|
47
77
|
// can't use `reactive` because update needs to be immutable
|
|
48
78
|
const state = ref(table.initialState)
|
|
49
79
|
|
|
@@ -53,7 +83,7 @@ export function useVueTable<TData extends RowData>(
|
|
|
53
83
|
get: (_, prop) => state.value[prop as keyof typeof state.value],
|
|
54
84
|
})
|
|
55
85
|
|
|
56
|
-
|
|
86
|
+
const newOptions = mergeProxy(prev, options, {
|
|
57
87
|
// merge the initialState and `options.state`
|
|
58
88
|
// create a new proxy on each `setOptions` call
|
|
59
89
|
// and get the value from state on each property access
|
|
@@ -70,6 +100,16 @@ export function useVueTable<TData extends RowData>(
|
|
|
70
100
|
options.onStateChange?.(updater)
|
|
71
101
|
},
|
|
72
102
|
})
|
|
103
|
+
|
|
104
|
+
// Add support for reactivity
|
|
105
|
+
if (isRef(options.data)) {
|
|
106
|
+
return {
|
|
107
|
+
...newOptions,
|
|
108
|
+
data: unref(options.data),
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
return newOptions
|
|
73
113
|
})
|
|
74
114
|
})
|
|
75
115
|
|