@tanstack/vue-table 8.20.2 → 8.20.4
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 +1 -1
- package/build/lib/index.esm.js +13 -9
- package/build/lib/index.esm.js.map +1 -1
- package/build/lib/index.js +12 -8
- package/build/lib/index.js.map +1 -1
- package/build/lib/index.mjs +13 -9
- package/build/lib/index.mjs.map +1 -1
- package/build/umd/index.development.js +12 -8
- 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 +1 -1
- package/src/index.ts +47 -25
package/package.json
CHANGED
package/src/index.ts
CHANGED
|
@@ -1,4 +1,9 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import {
|
|
2
|
+
TableOptions,
|
|
3
|
+
createTable,
|
|
4
|
+
RowData,
|
|
5
|
+
TableOptionsResolved,
|
|
6
|
+
} from '@tanstack/table-core'
|
|
2
7
|
import {
|
|
3
8
|
h,
|
|
4
9
|
watchEffect,
|
|
@@ -8,12 +13,13 @@ import {
|
|
|
8
13
|
unref,
|
|
9
14
|
MaybeRef,
|
|
10
15
|
watch,
|
|
16
|
+
shallowRef,
|
|
11
17
|
} from 'vue'
|
|
12
18
|
import { mergeProxy } from './merge-proxy'
|
|
13
19
|
|
|
14
20
|
export * from '@tanstack/table-core'
|
|
15
21
|
|
|
16
|
-
type TableOptionsWithReactiveData<TData extends RowData> = Omit<
|
|
22
|
+
export type TableOptionsWithReactiveData<TData extends RowData> = Omit<
|
|
17
23
|
TableOptions<TData>,
|
|
18
24
|
'data'
|
|
19
25
|
> & {
|
|
@@ -47,6 +53,8 @@ function getOptionsWithReactiveData<TData extends RowData>(
|
|
|
47
53
|
export function useVueTable<TData extends RowData>(
|
|
48
54
|
initialOptions: TableOptionsWithReactiveData<TData>
|
|
49
55
|
) {
|
|
56
|
+
const IS_REACTIVE = isRef(initialOptions.data)
|
|
57
|
+
|
|
50
58
|
const resolvedOptions = mergeProxy(
|
|
51
59
|
{
|
|
52
60
|
state: {}, // Dummy state
|
|
@@ -56,25 +64,33 @@ export function useVueTable<TData extends RowData>(
|
|
|
56
64
|
defaultOptions: TableOptions<TData>,
|
|
57
65
|
options: TableOptions<TData>
|
|
58
66
|
) {
|
|
59
|
-
return
|
|
67
|
+
return IS_REACTIVE
|
|
68
|
+
? {
|
|
69
|
+
...defaultOptions,
|
|
70
|
+
...options,
|
|
71
|
+
}
|
|
72
|
+
: mergeProxy(defaultOptions, options)
|
|
60
73
|
},
|
|
61
74
|
},
|
|
62
|
-
getOptionsWithReactiveData(initialOptions)
|
|
75
|
+
IS_REACTIVE ? getOptionsWithReactiveData(initialOptions) : initialOptions
|
|
63
76
|
)
|
|
64
77
|
|
|
65
|
-
const table = createTable<TData>(
|
|
78
|
+
const table = createTable<TData>(
|
|
79
|
+
resolvedOptions as TableOptionsResolved<TData>
|
|
80
|
+
)
|
|
66
81
|
|
|
67
82
|
// Add reactivity support
|
|
68
|
-
if (
|
|
83
|
+
if (IS_REACTIVE) {
|
|
84
|
+
const dataRef = shallowRef(initialOptions.data)
|
|
69
85
|
watch(
|
|
70
|
-
|
|
86
|
+
dataRef,
|
|
71
87
|
() => {
|
|
72
88
|
table.setState(prev => ({
|
|
73
89
|
...prev,
|
|
74
|
-
data:
|
|
90
|
+
data: dataRef.value,
|
|
75
91
|
}))
|
|
76
92
|
},
|
|
77
|
-
{ immediate: true
|
|
93
|
+
{ immediate: true }
|
|
78
94
|
)
|
|
79
95
|
}
|
|
80
96
|
|
|
@@ -87,23 +103,29 @@ export function useVueTable<TData extends RowData>(
|
|
|
87
103
|
get: (_, prop) => state.value[prop as keyof typeof state.value],
|
|
88
104
|
})
|
|
89
105
|
|
|
90
|
-
return mergeProxy(
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
106
|
+
return mergeProxy(
|
|
107
|
+
prev,
|
|
108
|
+
IS_REACTIVE
|
|
109
|
+
? getOptionsWithReactiveData(initialOptions)
|
|
110
|
+
: initialOptions,
|
|
111
|
+
{
|
|
112
|
+
// merge the initialState and `options.state`
|
|
113
|
+
// create a new proxy on each `setOptions` call
|
|
114
|
+
// and get the value from state on each property access
|
|
115
|
+
state: mergeProxy(stateProxy, initialOptions.state ?? {}),
|
|
116
|
+
// Similarly, we'll maintain both our internal state and any user-provided
|
|
117
|
+
// state.
|
|
118
|
+
onStateChange: (updater: any) => {
|
|
119
|
+
if (updater instanceof Function) {
|
|
120
|
+
state.value = updater(state.value)
|
|
121
|
+
} else {
|
|
122
|
+
state.value = updater
|
|
123
|
+
}
|
|
103
124
|
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
125
|
+
initialOptions.onStateChange?.(updater)
|
|
126
|
+
},
|
|
127
|
+
}
|
|
128
|
+
)
|
|
107
129
|
})
|
|
108
130
|
})
|
|
109
131
|
|