@tanstack/vue-table 8.20.1 → 8.20.2

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.1",
3
+ "version": "8.20.2",
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,9 +1,4 @@
1
- import {
2
- TableOptions,
3
- createTable,
4
- TableOptionsResolved,
5
- RowData,
6
- } from '@tanstack/table-core'
1
+ import { TableOptions, createTable, RowData } from '@tanstack/table-core'
7
2
  import {
8
3
  h,
9
4
  watchEffect,
@@ -12,6 +7,7 @@ import {
12
7
  isRef,
13
8
  unref,
14
9
  MaybeRef,
10
+ watch,
15
11
  } from 'vue'
16
12
  import { mergeProxy } from './merge-proxy'
17
13
 
@@ -24,13 +20,6 @@ type TableOptionsWithReactiveData<TData extends RowData> = Omit<
24
20
  data: MaybeRef<TData[]>
25
21
  }
26
22
 
27
- type TableOptionsResolvedWithReactiveData<TData extends RowData> = Omit<
28
- TableOptionsResolved<TData>,
29
- 'data'
30
- > & {
31
- data: MaybeRef<TData[]>
32
- }
33
-
34
23
  export const FlexRender = defineComponent({
35
24
  props: ['render', 'props'],
36
25
  setup: (props: { render: any; props: any }) => {
@@ -47,33 +36,48 @@ export const FlexRender = defineComponent({
47
36
  },
48
37
  })
49
38
 
50
- export function useVueTable<TData extends RowData>(
39
+ function getOptionsWithReactiveData<TData extends RowData>(
51
40
  options: TableOptionsWithReactiveData<TData>
52
41
  ) {
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
- },
42
+ return mergeProxy(options, {
43
+ data: unref(options.data),
44
+ })
45
+ }
46
+
47
+ export function useVueTable<TData extends RowData>(
48
+ initialOptions: TableOptionsWithReactiveData<TData>
49
+ ) {
50
+ const resolvedOptions = mergeProxy(
51
+ {
52
+ state: {}, // Dummy state
53
+ onStateChange: () => {}, // noop
54
+ renderFallbackValue: null,
55
+ mergeOptions(
56
+ defaultOptions: TableOptions<TData>,
57
+ options: TableOptions<TData>
58
+ ) {
59
+ return mergeProxy(defaultOptions, options)
65
60
  },
66
- options
67
- )
61
+ },
62
+ getOptionsWithReactiveData(initialOptions)
63
+ )
64
+
65
+ const table = createTable<TData>(resolvedOptions)
68
66
 
69
- // Add support for reactivity
70
- if (isRef(options.data)) {
71
- resolvedOptions.data = unref(options.data)
67
+ // Add reactivity support
68
+ if (isRef(initialOptions.data)) {
69
+ watch(
70
+ initialOptions.data,
71
+ () => {
72
+ table.setState(prev => ({
73
+ ...prev,
74
+ data: unref(initialOptions.data),
75
+ }))
76
+ },
77
+ { immediate: true, deep: true }
78
+ )
72
79
  }
73
80
 
74
- const table = createTable<TData>(
75
- resolvedOptions as TableOptionsResolved<TData>
76
- )
77
81
  // can't use `reactive` because update needs to be immutable
78
82
  const state = ref(table.initialState)
79
83
 
@@ -83,11 +87,11 @@ export function useVueTable<TData extends RowData>(
83
87
  get: (_, prop) => state.value[prop as keyof typeof state.value],
84
88
  })
85
89
 
86
- const newOptions = mergeProxy(prev, options, {
90
+ return mergeProxy(prev, getOptionsWithReactiveData(initialOptions), {
87
91
  // merge the initialState and `options.state`
88
92
  // create a new proxy on each `setOptions` call
89
93
  // and get the value from state on each property access
90
- state: mergeProxy(stateProxy, options.state ?? {}),
94
+ state: mergeProxy(stateProxy, initialOptions.state ?? {}),
91
95
  // Similarly, we'll maintain both our internal state and any user-provided
92
96
  // state.
93
97
  onStateChange: (updater: any) => {
@@ -97,19 +101,9 @@ export function useVueTable<TData extends RowData>(
97
101
  state.value = updater
98
102
  }
99
103
 
100
- options.onStateChange?.(updater)
104
+ initialOptions.onStateChange?.(updater)
101
105
  },
102
106
  })
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
113
107
  })
114
108
  })
115
109