@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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tanstack/vue-table",
3
- "version": "8.20.2",
3
+ "version": "8.20.4",
4
4
  "description": "Headless UI for building powerful tables & datagrids for Vue.",
5
5
  "author": "Tanner Linsley",
6
6
  "license": "MIT",
package/src/index.ts CHANGED
@@ -1,4 +1,9 @@
1
- import { TableOptions, createTable, RowData } from '@tanstack/table-core'
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 mergeProxy(defaultOptions, options)
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>(resolvedOptions)
78
+ const table = createTable<TData>(
79
+ resolvedOptions as TableOptionsResolved<TData>
80
+ )
66
81
 
67
82
  // Add reactivity support
68
- if (isRef(initialOptions.data)) {
83
+ if (IS_REACTIVE) {
84
+ const dataRef = shallowRef(initialOptions.data)
69
85
  watch(
70
- initialOptions.data,
86
+ dataRef,
71
87
  () => {
72
88
  table.setState(prev => ({
73
89
  ...prev,
74
- data: unref(initialOptions.data),
90
+ data: dataRef.value,
75
91
  }))
76
92
  },
77
- { immediate: true, deep: 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(prev, getOptionsWithReactiveData(initialOptions), {
91
- // merge the initialState and `options.state`
92
- // create a new proxy on each `setOptions` call
93
- // and get the value from state on each property access
94
- state: mergeProxy(stateProxy, initialOptions.state ?? {}),
95
- // Similarly, we'll maintain both our internal state and any user-provided
96
- // state.
97
- onStateChange: (updater: any) => {
98
- if (updater instanceof Function) {
99
- state.value = updater(state.value)
100
- } else {
101
- state.value = updater
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
- initialOptions.onStateChange?.(updater)
105
- },
106
- })
125
+ initialOptions.onStateChange?.(updater)
126
+ },
127
+ }
128
+ )
107
129
  })
108
130
  })
109
131