@tanstack/vue-table 8.19.4 → 8.20.0

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.19.4",
3
+ "version": "8.20.0",
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
@@ -4,11 +4,33 @@ import {
4
4
  TableOptionsResolved,
5
5
  RowData,
6
6
  } from '@tanstack/table-core'
7
- import { h, watchEffect, ref, defineComponent } from 'vue'
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: TableOptions<TData>
51
+ options: TableOptionsWithReactiveData<TData>
30
52
  ) {
31
- const resolvedOptions: TableOptionsResolved<TData> = mergeProxy(
32
- {
33
- state: {}, // Dummy state
34
- onStateChange: () => {}, // noop
35
- renderFallbackValue: null,
36
- mergeOptions(
37
- defaultOptions: TableOptions<TData>,
38
- options: TableOptions<TData>
39
- ) {
40
- return mergeProxy(defaultOptions, options)
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
- options
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>(resolvedOptions)
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
- return mergeProxy(prev, options, {
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