@tanstack/vue-table 9.0.0-alpha.9 → 9.0.0-beta.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.
Files changed (70) hide show
  1. package/README.md +127 -0
  2. package/dist/FlexRender.cjs +80 -0
  3. package/dist/FlexRender.cjs.map +1 -0
  4. package/dist/FlexRender.d.cts +45 -0
  5. package/dist/FlexRender.d.ts +45 -0
  6. package/dist/FlexRender.js +79 -0
  7. package/dist/FlexRender.js.map +1 -0
  8. package/dist/createTableHook.cjs +234 -0
  9. package/dist/createTableHook.cjs.map +1 -0
  10. package/dist/createTableHook.d.cts +138 -0
  11. package/dist/createTableHook.d.ts +138 -0
  12. package/dist/createTableHook.js +233 -0
  13. package/dist/createTableHook.js.map +1 -0
  14. package/dist/flex-render.cjs +5 -0
  15. package/dist/flex-render.d.cts +2 -0
  16. package/dist/flex-render.d.ts +2 -0
  17. package/dist/flex-render.js +3 -0
  18. package/dist/index.cjs +17 -0
  19. package/dist/index.d.cts +5 -0
  20. package/dist/index.d.ts +5 -0
  21. package/dist/index.js +7 -0
  22. package/dist/merge-proxy.cjs +77 -0
  23. package/dist/merge-proxy.cjs.map +1 -0
  24. package/dist/merge-proxy.js +75 -0
  25. package/dist/merge-proxy.js.map +1 -0
  26. package/dist/reactivity.cjs +73 -0
  27. package/dist/reactivity.cjs.map +1 -0
  28. package/dist/reactivity.js +73 -0
  29. package/dist/reactivity.js.map +1 -0
  30. package/dist/static-functions.cjs +9 -0
  31. package/dist/static-functions.d.cts +1 -0
  32. package/dist/static-functions.d.ts +1 -0
  33. package/dist/static-functions.js +3 -0
  34. package/dist/useTable.cjs +83 -0
  35. package/dist/useTable.cjs.map +1 -0
  36. package/dist/useTable.d.cts +76 -0
  37. package/dist/useTable.d.ts +76 -0
  38. package/dist/useTable.js +83 -0
  39. package/dist/useTable.js.map +1 -0
  40. package/package.json +31 -19
  41. package/skills/vue/client-to-server/SKILL.md +365 -0
  42. package/skills/vue/compose-with-tanstack-form/SKILL.md +369 -0
  43. package/skills/vue/compose-with-tanstack-pacer/SKILL.md +318 -0
  44. package/skills/vue/compose-with-tanstack-query/SKILL.md +385 -0
  45. package/skills/vue/compose-with-tanstack-store/SKILL.md +301 -0
  46. package/skills/vue/compose-with-tanstack-virtual/SKILL.md +340 -0
  47. package/skills/vue/getting-started/SKILL.md +409 -0
  48. package/skills/vue/migrate-v8-to-v9/SKILL.md +375 -0
  49. package/skills/vue/production-readiness/SKILL.md +271 -0
  50. package/skills/vue/table-state/SKILL.md +403 -0
  51. package/src/FlexRender.ts +123 -0
  52. package/src/createTableHook.ts +597 -0
  53. package/src/flex-render.ts +1 -0
  54. package/src/index.ts +3 -74
  55. package/src/merge-proxy.ts +66 -15
  56. package/src/reactivity.ts +115 -0
  57. package/src/static-functions.ts +1 -0
  58. package/src/useTable.ts +251 -0
  59. package/dist/cjs/index.cjs +0 -68
  60. package/dist/cjs/index.cjs.map +0 -1
  61. package/dist/cjs/index.d.cts +0 -14
  62. package/dist/cjs/merge-proxy.cjs +0 -61
  63. package/dist/cjs/merge-proxy.cjs.map +0 -1
  64. package/dist/cjs/merge-proxy.d.cts +0 -11
  65. package/dist/esm/index.d.ts +0 -14
  66. package/dist/esm/index.js +0 -63
  67. package/dist/esm/index.js.map +0 -1
  68. package/dist/esm/merge-proxy.d.ts +0 -11
  69. package/dist/esm/merge-proxy.js +0 -61
  70. package/dist/esm/merge-proxy.js.map +0 -1
@@ -3,15 +3,18 @@ function trueFn() {
3
3
  }
4
4
 
5
5
  const $PROXY = Symbol('merge-proxy')
6
+ const $SOURCES = Symbol('merge-proxy-sources')
6
7
 
7
8
  // https://github.com/solidjs/solid/blob/c20ca4fd8c36bc0522fedb2c7f38a110b7ee2663/packages/solid/src/render/component.ts#L51-L118
8
9
  const propTraps: ProxyHandler<{
9
10
  get: (k: string | number | symbol) => any
10
11
  has: (k: string | number | symbol) => boolean
11
- keys: () => string[]
12
+ keys: () => Array<string>
13
+ sources: Array<any>
12
14
  }> = {
13
15
  get(_, property, receiver) {
14
16
  if (property === $PROXY) return receiver
17
+ if (property === $SOURCES) return _.sources
15
18
  return _.get(property)
16
19
  },
17
20
  has(_, property) {
@@ -36,46 +39,94 @@ const propTraps: ProxyHandler<{
36
39
  }
37
40
 
38
41
  type UnboxLazy<T> = T extends () => infer U ? U : T
39
- type BoxedTupleTypes<T extends any[]> = {
42
+ type BoxedTupleTypes<T extends Array<any>> = {
40
43
  [P in keyof T]: [UnboxLazy<T[P]>]
41
- }[Exclude<keyof T, keyof any[]>]
42
- type UnionToIntersection<U> = (U extends any ? (k: U) => void : never) extends (
43
- k: infer I
44
+ }[Exclude<keyof T, keyof Array<any>>]
45
+ type UnionToIntersection<T> = (T extends any ? (k: T) => void : never) extends (
46
+ k: infer I,
44
47
  ) => void
45
48
  ? I
46
49
  : never
47
50
  type UnboxIntersection<T> = T extends { 0: infer U } ? U : never
48
- type MergeProxy<T extends any[]> = UnboxIntersection<
51
+ type MergeProxy<T extends Array<any>> = UnboxIntersection<
49
52
  UnionToIntersection<BoxedTupleTypes<T>>
50
53
  >
51
54
 
52
55
  function resolveSource(s: any) {
53
- return 'value' in s ? s.value : s
56
+ return s && typeof s === 'object' && 'value' in s ? s.value : s
54
57
  }
55
58
 
56
- export function mergeProxy<T extends any[]>(...sources: T): MergeProxy<T>
59
+ export function mergeProxy<T extends Array<any>>(...sources: T): MergeProxy<T>
57
60
  export function mergeProxy(...sources: any): any {
61
+ const flattenedSources = sources.flatMap((source: any) => {
62
+ if (
63
+ typeof source === 'object' &&
64
+ source !== null &&
65
+ $SOURCES in source &&
66
+ Array.isArray(source[$SOURCES])
67
+ ) {
68
+ return source[$SOURCES]
69
+ }
70
+
71
+ return [source]
72
+ })
73
+
58
74
  return new Proxy(
59
75
  {
76
+ sources: flattenedSources,
60
77
  get(property: string | number | symbol) {
61
- for (let i = sources.length - 1; i >= 0; i--) {
62
- const v = resolveSource(sources[i])[property]
78
+ for (let i = flattenedSources.length - 1; i >= 0; i--) {
79
+ const v = resolveSource(flattenedSources[i])[property]
63
80
  if (v !== undefined) return v
64
81
  }
65
82
  },
66
83
  has(property: string | number | symbol) {
67
- for (let i = sources.length - 1; i >= 0; i--) {
68
- if (property in resolveSource(sources[i])) return true
84
+ for (let i = flattenedSources.length - 1; i >= 0; i--) {
85
+ if (property in resolveSource(flattenedSources[i])) return true
69
86
  }
70
87
  return false
71
88
  },
72
89
  keys() {
73
90
  const keys = []
74
- for (let i = 0; i < sources.length; i++)
75
- keys.push(...Object.keys(resolveSource(sources[i])))
91
+ for (const source of flattenedSources)
92
+ keys.push(...Object.keys(resolveSource(source)))
76
93
  return [...Array.from(new Set(keys))]
77
94
  },
78
95
  },
79
- propTraps
96
+ propTraps,
80
97
  )
81
98
  }
99
+
100
+ /**
101
+ * Merges objects together by eagerly resolving all values into a flat object.
102
+ *
103
+ * Unlike `mergeProxy`, this does not preserve lazy proxy getters. Use this for
104
+ * repeated option update paths so each merge produces a plain object instead
105
+ * of accumulating a longer source list over time.
106
+ */
107
+ export function flatMerge<T>(source: T): T
108
+ export function flatMerge<T, U>(source: T, source1: U): T & U
109
+ export function flatMerge<T, U, V>(source: T, source1: U, source2: V): T & U & V
110
+ export function flatMerge<T, U, V, W>(
111
+ source: T,
112
+ source1: U,
113
+ source2: V,
114
+ source3: W,
115
+ ): T & U & V & W
116
+ export function flatMerge(...sources: any): any {
117
+ const result: Record<PropertyKey, unknown> = {}
118
+
119
+ for (let source of sources) {
120
+ source = resolveSource(source)
121
+ if (!source) continue
122
+
123
+ for (const key of Reflect.ownKeys(source)) {
124
+ const value = (source as Record<PropertyKey, unknown>)[key]
125
+ if (value !== undefined) {
126
+ result[key] = value
127
+ }
128
+ }
129
+ }
130
+
131
+ return result
132
+ }
@@ -0,0 +1,115 @@
1
+ import {
2
+ computed,
3
+ getCurrentScope,
4
+ onScopeDispose,
5
+ shallowRef,
6
+ watch,
7
+ } from 'vue'
8
+ import { batch, createAtom } from '@tanstack/vue-store'
9
+ import type {
10
+ TableAtomOptions,
11
+ TableReactivityBindings,
12
+ } from '@tanstack/table-core/reactivity'
13
+ import type { Atom, Observer, ReadonlyAtom } from '@tanstack/vue-store'
14
+ import type { ComputedRef, ShallowRef } from 'vue'
15
+
16
+ const optionsStoreDebugName = 'table/optionsStore'
17
+
18
+ function observerToCallback<T>(
19
+ observerOrNext: Observer<T> | ((value: T) => void),
20
+ ): (value: T) => void {
21
+ return typeof observerOrNext === 'function'
22
+ ? observerOrNext
23
+ : (value) => observerOrNext.next?.(value)
24
+ }
25
+
26
+ function refToReadonlyAtom<T>(
27
+ source: ComputedRef<T> | ShallowRef<T>,
28
+ ): ReadonlyAtom<T> {
29
+ return Object.assign(source, {
30
+ get: () => source.value,
31
+ subscribe: ((observerOrNext: Observer<T> | ((value: T) => void)) => {
32
+ const stop = watch(source, observerToCallback(observerOrNext), {
33
+ flush: 'sync',
34
+ })
35
+ return { unsubscribe: stop }
36
+ }) as ReadonlyAtom<T>['subscribe'],
37
+ })
38
+ }
39
+
40
+ function refToWritableAtom<T>(source: ShallowRef<T>): Atom<T> {
41
+ return Object.assign(source, {
42
+ set: (updater: T | ((prevVal: T) => T)) => {
43
+ source.value =
44
+ typeof updater === 'function'
45
+ ? (updater as (prevVal: T) => T)(source.value)
46
+ : updater
47
+ },
48
+ get: () => source.value,
49
+ subscribe: ((observerOrNext: Observer<T> | ((value: T) => void)) => {
50
+ const stop = watch(source, observerToCallback(observerOrNext), {
51
+ flush: 'sync',
52
+ })
53
+ return { unsubscribe: stop }
54
+ }) as Atom<T>['subscribe'],
55
+ })
56
+ }
57
+
58
+ /**
59
+ * Creates the table-core reactivity bindings used by the Vue adapter.
60
+ *
61
+ * Table state atoms are backed by TanStack Store atoms. The options store stays
62
+ * framework-native because row-model APIs read `table.options` directly during
63
+ * render. Readonly table atoms bridge Store dependency tracking into Vue computed
64
+ * refs.
65
+ */
66
+ export function vueReactivity(): TableReactivityBindings {
67
+ return {
68
+ createOptionsStore: true,
69
+ wrapExternalAtoms: false,
70
+ addSubscription: () => {
71
+ throw new Error(
72
+ 'Feature not supported in current reactivity implementation',
73
+ )
74
+ },
75
+ unmount: () => {
76
+ throw new Error(
77
+ 'Feature not supported in current reactivity implementation',
78
+ )
79
+ },
80
+ schedule: (fn) => queueMicrotask(() => fn()),
81
+ createReadonlyAtom: <T>(fn: () => T, _options?: TableAtomOptions<T>) => {
82
+ const storeAtom = createAtom(() => fn(), {
83
+ compare: _options?.compare,
84
+ })
85
+ const version = shallowRef(0)
86
+ const subscription = storeAtom.subscribe(() => {
87
+ version.value += 1
88
+ })
89
+ if (getCurrentScope()) {
90
+ onScopeDispose(() => subscription.unsubscribe())
91
+ }
92
+
93
+ return refToReadonlyAtom(
94
+ computed(() => {
95
+ version.value
96
+ return storeAtom.get()
97
+ }),
98
+ )
99
+ },
100
+ createWritableAtom: <T>(
101
+ value: T,
102
+ _options?: TableAtomOptions<T>,
103
+ ): Atom<T> => {
104
+ if (_options?.debugName === optionsStoreDebugName) {
105
+ return refToWritableAtom(shallowRef(value) as ShallowRef<T>)
106
+ }
107
+
108
+ return createAtom(value, {
109
+ compare: _options?.compare,
110
+ })
111
+ },
112
+ untrack: (fn) => fn(),
113
+ batch,
114
+ }
115
+ }
@@ -0,0 +1 @@
1
+ export * from '@tanstack/table-core/static-functions'
@@ -0,0 +1,251 @@
1
+ import { unref, watch } from 'vue'
2
+ import { constructTable } from '@tanstack/table-core'
3
+ import { shallow, useSelector } from '@tanstack/vue-store'
4
+ import { flatMerge, mergeProxy } from './merge-proxy'
5
+ import { vueReactivity } from './reactivity'
6
+ import type {
7
+ Atom,
8
+ ReadonlyAtom,
9
+ ReadonlyStore,
10
+ Store,
11
+ } from '@tanstack/vue-store'
12
+ import type {
13
+ NoInfer,
14
+ RowData,
15
+ Table,
16
+ TableFeatures,
17
+ TableOptions,
18
+ TableState,
19
+ } from '@tanstack/table-core'
20
+ import type { MaybeRef, VNode } from 'vue'
21
+
22
+ export type SubscribeSource<TValue> =
23
+ | Atom<TValue>
24
+ | ReadonlyAtom<TValue>
25
+ | Store<TValue>
26
+ | ReadonlyStore<TValue>
27
+
28
+ export type TableOptionsWithReactiveData<
29
+ TFeatures extends TableFeatures,
30
+ TData extends RowData,
31
+ > = {
32
+ [K in keyof TableOptions<TFeatures, TData>]: K extends 'data'
33
+ ? MaybeRef<ReadonlyArray<TData>>
34
+ : MaybeRef<TableOptions<TFeatures, TData>[K]>
35
+ }
36
+
37
+ function getOptionsWithReactiveValues<
38
+ TFeatures extends TableFeatures,
39
+ TData extends RowData,
40
+ >(options: TableOptionsWithReactiveData<TFeatures, TData>) {
41
+ const resolvedOptions: Record<string, unknown> = {}
42
+
43
+ for (const key of Object.keys(options)) {
44
+ resolvedOptions[key] = unref(
45
+ options[key as keyof TableOptionsWithReactiveData<TFeatures, TData>],
46
+ )
47
+ }
48
+
49
+ return mergeProxy(options, resolvedOptions)
50
+ }
51
+
52
+ function getReactiveOptionDeps<
53
+ TFeatures extends TableFeatures,
54
+ TData extends RowData,
55
+ >(options: TableOptionsWithReactiveData<TFeatures, TData>) {
56
+ return Object.keys(options).map((key) =>
57
+ unref(options[key as keyof TableOptionsWithReactiveData<TFeatures, TData>]),
58
+ )
59
+ }
60
+
61
+ export type VueTable<
62
+ TFeatures extends TableFeatures,
63
+ TData extends RowData,
64
+ TSelected = TableState<TFeatures>,
65
+ > = Omit<Table<TFeatures, TData>, 'store'> & {
66
+ /**
67
+ * @deprecated Prefer `table.state` for render reads,
68
+ * `table.atoms.<slice>.get()` for slice snapshots, or
69
+ * `table.Subscribe` / `useSelector(table.store, selector)` for explicit
70
+ * subscriptions. `table.store.state` is a current-value snapshot and is easy
71
+ * to misuse in render code.
72
+ */
73
+ readonly store: Table<TFeatures, TData>['store']
74
+ /**
75
+ * Store mode: `selector` required. Source mode: pass `source` (atom or store); omit
76
+ * `selector` for the whole value (identity), or pass `selector` to project. Split
77
+ * overloads so source-only infers `TSourceValue` for `children` (see React `Subscribe`).
78
+ */
79
+ Subscribe: {
80
+ <TSourceValue>(props: {
81
+ source: SubscribeSource<TSourceValue>
82
+ selector?: undefined
83
+ children:
84
+ | ((state: Readonly<TSourceValue>) => VNode | Array<VNode>)
85
+ | VNode
86
+ | Array<VNode>
87
+ }): VNode | Array<VNode>
88
+ <TSourceValue, TSubSelected>(props: {
89
+ source: SubscribeSource<TSourceValue>
90
+ selector: (state: TSourceValue) => TSubSelected
91
+ children:
92
+ | ((state: Readonly<TSubSelected>) => VNode | Array<VNode>)
93
+ | VNode
94
+ | Array<VNode>
95
+ }): VNode | Array<VNode>
96
+ <TSubSelected>(props: {
97
+ selector: (state: NoInfer<TableState<TFeatures>>) => TSubSelected
98
+ children:
99
+ | ((state: Readonly<TSubSelected>) => VNode | Array<VNode>)
100
+ | VNode
101
+ | Array<VNode>
102
+ }): VNode | Array<VNode>
103
+ }
104
+ /**
105
+ * The selected state of the table. This state may not match the structure of
106
+ * the full table state because it is selected by the selector function that
107
+ * you pass as the 2nd argument to `useTable`.
108
+ *
109
+ * @example
110
+ * const table = useTable(options, (state) => ({ globalFilter: state.globalFilter })) // only globalFilter is part of the selected state
111
+ *
112
+ * console.log(table.state.globalFilter)
113
+ */
114
+ readonly state: Readonly<TSelected>
115
+ }
116
+
117
+ /**
118
+ * Creates a Vue table instance backed by Vue-aware TanStack Store atoms.
119
+ *
120
+ * Table options may contain Vue refs or computed values. The adapter unwraps
121
+ * those reactive inputs, watches them with synchronous flushing, and keeps the
122
+ * table options in sync. The optional selector projects from `table.store` and
123
+ * exposes the selected value on `table.state`.
124
+ *
125
+ * @example
126
+ * ```ts
127
+ * const table = useTable(
128
+ * {
129
+ * features,
130
+ * rowModels: {},
131
+ * columns,
132
+ * data,
133
+ * },
134
+ * (state) => ({ pagination: state.pagination }),
135
+ * )
136
+ *
137
+ * table.state.pagination
138
+ * ```
139
+ */
140
+ export function useTable<
141
+ TFeatures extends TableFeatures,
142
+ TData extends RowData,
143
+ TSelected = TableState<TFeatures>,
144
+ >(
145
+ tableOptions:
146
+ | TableOptions<TFeatures, TData>
147
+ | TableOptionsWithReactiveData<TFeatures, TData>,
148
+ selector?: (state: TableState<TFeatures>) => TSelected,
149
+ ): VueTable<TFeatures, TData, TSelected> {
150
+ const syncTableOptions = (
151
+ table: Table<TFeatures, TData>,
152
+ options: TableOptionsWithReactiveData<TFeatures, TData>,
153
+ ) => {
154
+ table.setOptions((prev) =>
155
+ flatMerge(prev, getOptionsWithReactiveValues(options)),
156
+ )
157
+ }
158
+
159
+ const mergedOptions = mergeProxy(tableOptions, {
160
+ features: {
161
+ coreReativityFeature: vueReactivity(),
162
+ ...(unref(tableOptions.features) ?? {}),
163
+ },
164
+ }) as TableOptionsWithReactiveData<TFeatures, TData>
165
+
166
+ const resolvedOptions = mergeProxy(
167
+ getOptionsWithReactiveValues(mergedOptions),
168
+ {
169
+ // Remove state and onStateChange - store handles it internally
170
+ mergeOptions: (
171
+ defaultOptions: TableOptions<TFeatures, TData>,
172
+ newOptions: Partial<TableOptions<TFeatures, TData>>,
173
+ ) => {
174
+ return flatMerge(defaultOptions, newOptions)
175
+ },
176
+ },
177
+ ) as TableOptions<TFeatures, TData>
178
+
179
+ const coreTable = constructTable(resolvedOptions)
180
+ const table = coreTable as unknown as VueTable<TFeatures, TData, TSelected>
181
+
182
+ watch(
183
+ () => getReactiveOptionDeps(mergedOptions),
184
+ () => {
185
+ syncTableOptions(coreTable, mergedOptions)
186
+ },
187
+ { immediate: true },
188
+ )
189
+
190
+ watch(
191
+ () => {
192
+ const controlledState = unref(tableOptions.state) as
193
+ | Record<string, unknown>
194
+ | undefined
195
+ const controlledAtoms = unref(tableOptions.atoms) as
196
+ | Record<string, unknown>
197
+ | undefined
198
+
199
+ if (!controlledState) {
200
+ return []
201
+ }
202
+
203
+ const controlledValues: Array<unknown> = []
204
+
205
+ for (const key of Object.keys(table.initialState)) {
206
+ if (!(key in controlledState) || controlledAtoms?.[key] !== undefined) {
207
+ continue
208
+ }
209
+
210
+ // Reading only controlled state slices here lets Vue subscribe to
211
+ // getters/computed values that are passed through `options.state`.
212
+ controlledValues.push(controlledState[key])
213
+ }
214
+
215
+ return controlledValues
216
+ },
217
+ (controlledValues) => {
218
+ if (controlledValues.length > 0) {
219
+ syncTableOptions(coreTable, mergedOptions)
220
+ }
221
+ },
222
+ { immediate: true },
223
+ )
224
+
225
+ table.Subscribe = ((props: {
226
+ source?: SubscribeSource<unknown>
227
+ selector?: ((state: unknown) => unknown) | undefined
228
+ children:
229
+ | ((state: Readonly<unknown>) => VNode | Array<VNode>)
230
+ | VNode
231
+ | Array<VNode>
232
+ }) => {
233
+ const source = props.source ?? table.store
234
+ const selected = useSelector(source as never, props.selector as never, {
235
+ compare: shallow,
236
+ })
237
+ if (typeof props.children === 'function') {
238
+ return props.children(selected.value as Readonly<unknown>)
239
+ }
240
+ return props.children
241
+ }) as VueTable<TFeatures, TData, TSelected>['Subscribe']
242
+
243
+ const stateStore = useSelector(table.store, selector)
244
+
245
+ return {
246
+ ...table,
247
+ get state() {
248
+ return stateStore.value
249
+ },
250
+ }
251
+ }
@@ -1,68 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
3
- const tableCore = require("@tanstack/table-core");
4
- const vue = require("vue");
5
- const mergeProxy = require("./merge-proxy.cjs");
6
- const FlexRender = vue.defineComponent({
7
- props: ["render", "props"],
8
- setup: (props) => {
9
- return () => {
10
- if (typeof props.render === "function" || typeof props.render === "object") {
11
- return vue.h(props.render, props.props);
12
- }
13
- return props.render;
14
- };
15
- }
16
- });
17
- function useTable(options) {
18
- const resolvedOptions = mergeProxy.mergeProxy(
19
- {
20
- state: {},
21
- // Dummy state
22
- onStateChange: () => {
23
- },
24
- // noop
25
- renderFallbackValue: null,
26
- mergeOptions(defaultOptions, options2) {
27
- return mergeProxy.mergeProxy(defaultOptions, options2);
28
- }
29
- },
30
- options
31
- );
32
- const table = tableCore._createTable(resolvedOptions);
33
- const state = vue.ref(table.initialState);
34
- vue.watchEffect(() => {
35
- table.setOptions((prev) => {
36
- const stateProxy = new Proxy({}, {
37
- get: (_, prop) => state.value[prop]
38
- });
39
- return mergeProxy.mergeProxy(prev, options, {
40
- // merge the initialState and `options.state`
41
- // create a new proxy on each `setOptions` call
42
- // and get the value from state on each property access
43
- state: mergeProxy.mergeProxy(stateProxy, options.state ?? {}),
44
- // Similarly, we'll maintain both our internal state and any user-provided
45
- // state.
46
- onStateChange: (updater) => {
47
- var _a;
48
- if (updater instanceof Function) {
49
- state.value = updater(state.value);
50
- } else {
51
- state.value = updater;
52
- }
53
- (_a = options.onStateChange) == null ? void 0 : _a.call(options, updater);
54
- }
55
- });
56
- });
57
- });
58
- return table;
59
- }
60
- exports.FlexRender = FlexRender;
61
- exports.useTable = useTable;
62
- Object.keys(tableCore).forEach((k) => {
63
- if (k !== "default" && !Object.prototype.hasOwnProperty.call(exports, k)) Object.defineProperty(exports, k, {
64
- enumerable: true,
65
- get: () => tableCore[k]
66
- });
67
- });
68
- //# sourceMappingURL=index.cjs.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.cjs","sources":["../../src/index.ts"],"sourcesContent":["import {\n TableOptions,\n _createTable,\n TableOptionsResolved,\n RowData,\n} from '@tanstack/table-core'\nimport { h, watchEffect, ref, defineComponent } from 'vue'\nimport { mergeProxy } from './merge-proxy'\n\nexport * from '@tanstack/table-core'\n\nexport const FlexRender = defineComponent({\n props: ['render', 'props'],\n setup: (props: { render: any; props: any }) => {\n return () => {\n if (\n typeof props.render === 'function' ||\n typeof props.render === 'object'\n ) {\n return h(props.render, props.props)\n }\n\n return props.render\n }\n },\n})\n\nexport function useTable<TData extends RowData>(options: TableOptions<TData>) {\n const resolvedOptions: TableOptionsResolved<TData> = mergeProxy(\n {\n state: {}, // Dummy state\n onStateChange: () => {}, // noop\n renderFallbackValue: null,\n mergeOptions(\n defaultOptions: TableOptions<TData>,\n options: TableOptions<TData>\n ) {\n return mergeProxy(defaultOptions, options)\n },\n },\n options\n )\n\n const table = _createTable<TData>(resolvedOptions)\n // can't use `reactive` because update needs to be immutable\n const state = ref(table.initialState)\n\n watchEffect(() => {\n table.setOptions(prev => {\n const stateProxy = new Proxy({} as typeof state.value, {\n get: (_, prop) => state.value[prop as keyof typeof state.value],\n })\n\n return mergeProxy(prev, options, {\n // merge the initialState and `options.state`\n // create a new proxy on each `setOptions` call\n // and get the value from state on each property access\n state: mergeProxy(stateProxy, options.state ?? {}),\n // Similarly, we'll maintain both our internal state and any user-provided\n // state.\n onStateChange: (updater: any) => {\n if (updater instanceof Function) {\n state.value = updater(state.value)\n } else {\n state.value = updater\n }\n\n options.onStateChange?.(updater)\n },\n })\n })\n })\n\n return table\n}\n"],"names":["defineComponent","h","mergeProxy","options","_createTable","ref","watchEffect"],"mappings":";;;;;AAWO,MAAM,aAAaA,IAAAA,gBAAgB;AAAA,EACxC,OAAO,CAAC,UAAU,OAAO;AAAA,EACzB,OAAO,CAAC,UAAuC;AAC7C,WAAO,MAAM;AACX,UACE,OAAO,MAAM,WAAW,cACxB,OAAO,MAAM,WAAW,UACxB;AACA,eAAOC,IAAE,EAAA,MAAM,QAAQ,MAAM,KAAK;AAAA,MACpC;AAEA,aAAO,MAAM;AAAA,IAAA;AAAA,EAEjB;AACF,CAAC;AAEM,SAAS,SAAgC,SAA8B;AAC5E,QAAM,kBAA+CC,WAAA;AAAA,IACnD;AAAA,MACE,OAAO,CAAC;AAAA;AAAA,MACR,eAAe,MAAM;AAAA,MAAC;AAAA;AAAA,MACtB,qBAAqB;AAAA,MACrB,aACE,gBACAC,UACA;AACO,eAAAD,WAAA,WAAW,gBAAgBC,QAAO;AAAA,MAC3C;AAAA,IACF;AAAA,IACA;AAAA,EAAA;AAGI,QAAA,QAAQC,uBAAoB,eAAe;AAE3C,QAAA,QAAQC,IAAAA,IAAI,MAAM,YAAY;AAEpCC,MAAAA,YAAY,MAAM;AAChB,UAAM,WAAW,CAAQ,SAAA;AACvB,YAAM,aAAa,IAAI,MAAM,IAA0B;AAAA,QACrD,KAAK,CAAC,GAAG,SAAS,MAAM,MAAM,IAAgC;AAAA,MAAA,CAC/D;AAEM,aAAAJ,WAAA,WAAW,MAAM,SAAS;AAAA;AAAA;AAAA;AAAA,QAI/B,OAAOA,WAAAA,WAAW,YAAY,QAAQ,SAAS,CAAA,CAAE;AAAA;AAAA;AAAA,QAGjD,eAAe,CAAC,YAAiB;;AAC/B,cAAI,mBAAmB,UAAU;AACzB,kBAAA,QAAQ,QAAQ,MAAM,KAAK;AAAA,UAAA,OAC5B;AACL,kBAAM,QAAQ;AAAA,UAChB;AAEA,wBAAQ,kBAAR,iCAAwB;AAAA,QAC1B;AAAA,MAAA,CACD;AAAA,IAAA,CACF;AAAA,EAAA,CACF;AAEM,SAAA;AACT;;;;;;;;;"}
@@ -1,14 +0,0 @@
1
- import { TableOptions, RowData } from '@tanstack/table-core';
2
-
3
- export * from '@tanstack/table-core';
4
- export declare const FlexRender: import('vue').DefineComponent<Readonly<{
5
- props?: any;
6
- render?: any;
7
- }>, () => any, unknown, {}, {}, import('vue').ComponentOptionsMixin, import('vue').ComponentOptionsMixin, {}, string, import('vue').PublicProps, Readonly<import('vue').ExtractPropTypes<Readonly<{
8
- props?: any;
9
- render?: any;
10
- }>>>, {
11
- readonly props?: any;
12
- readonly render?: any;
13
- }, {}>;
14
- export declare function useTable<TData extends RowData>(options: TableOptions<TData>): import('@tanstack/table-core').Table<TData>;
@@ -1,61 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
3
- function trueFn() {
4
- return true;
5
- }
6
- const $PROXY = Symbol("merge-proxy");
7
- const propTraps = {
8
- get(_, property, receiver) {
9
- if (property === $PROXY) return receiver;
10
- return _.get(property);
11
- },
12
- has(_, property) {
13
- return _.has(property);
14
- },
15
- set: trueFn,
16
- deleteProperty: trueFn,
17
- getOwnPropertyDescriptor(_, property) {
18
- return {
19
- configurable: true,
20
- enumerable: true,
21
- get() {
22
- return _.get(property);
23
- },
24
- set: trueFn,
25
- deleteProperty: trueFn
26
- };
27
- },
28
- ownKeys(_) {
29
- return _.keys();
30
- }
31
- };
32
- function resolveSource(s) {
33
- return "value" in s ? s.value : s;
34
- }
35
- function mergeProxy(...sources) {
36
- return new Proxy(
37
- {
38
- get(property) {
39
- for (let i = sources.length - 1; i >= 0; i--) {
40
- const v = resolveSource(sources[i])[property];
41
- if (v !== void 0) return v;
42
- }
43
- },
44
- has(property) {
45
- for (let i = sources.length - 1; i >= 0; i--) {
46
- if (property in resolveSource(sources[i])) return true;
47
- }
48
- return false;
49
- },
50
- keys() {
51
- const keys = [];
52
- for (let i = 0; i < sources.length; i++)
53
- keys.push(...Object.keys(resolveSource(sources[i])));
54
- return [...Array.from(new Set(keys))];
55
- }
56
- },
57
- propTraps
58
- );
59
- }
60
- exports.mergeProxy = mergeProxy;
61
- //# sourceMappingURL=merge-proxy.cjs.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"merge-proxy.cjs","sources":["../../src/merge-proxy.ts"],"sourcesContent":["function trueFn() {\n return true\n}\n\nconst $PROXY = Symbol('merge-proxy')\n\n// https://github.com/solidjs/solid/blob/c20ca4fd8c36bc0522fedb2c7f38a110b7ee2663/packages/solid/src/render/component.ts#L51-L118\nconst propTraps: ProxyHandler<{\n get: (k: string | number | symbol) => any\n has: (k: string | number | symbol) => boolean\n keys: () => string[]\n}> = {\n get(_, property, receiver) {\n if (property === $PROXY) return receiver\n return _.get(property)\n },\n has(_, property) {\n return _.has(property)\n },\n set: trueFn,\n deleteProperty: trueFn,\n getOwnPropertyDescriptor(_, property) {\n return {\n configurable: true,\n enumerable: true,\n get() {\n return _.get(property)\n },\n set: trueFn,\n deleteProperty: trueFn,\n }\n },\n ownKeys(_) {\n return _.keys()\n },\n}\n\ntype UnboxLazy<T> = T extends () => infer U ? U : T\ntype BoxedTupleTypes<T extends any[]> = {\n [P in keyof T]: [UnboxLazy<T[P]>]\n}[Exclude<keyof T, keyof any[]>]\ntype UnionToIntersection<U> = (U extends any ? (k: U) => void : never) extends (\n k: infer I\n) => void\n ? I\n : never\ntype UnboxIntersection<T> = T extends { 0: infer U } ? U : never\ntype MergeProxy<T extends any[]> = UnboxIntersection<\n UnionToIntersection<BoxedTupleTypes<T>>\n>\n\nfunction resolveSource(s: any) {\n return 'value' in s ? s.value : s\n}\n\nexport function mergeProxy<T extends any[]>(...sources: T): MergeProxy<T>\nexport function mergeProxy(...sources: any): any {\n return new Proxy(\n {\n get(property: string | number | symbol) {\n for (let i = sources.length - 1; i >= 0; i--) {\n const v = resolveSource(sources[i])[property]\n if (v !== undefined) return v\n }\n },\n has(property: string | number | symbol) {\n for (let i = sources.length - 1; i >= 0; i--) {\n if (property in resolveSource(sources[i])) return true\n }\n return false\n },\n keys() {\n const keys = []\n for (let i = 0; i < sources.length; i++)\n keys.push(...Object.keys(resolveSource(sources[i])))\n return [...Array.from(new Set(keys))]\n },\n },\n propTraps\n )\n}\n"],"names":[],"mappings":";;AAAA,SAAS,SAAS;AACT,SAAA;AACT;AAEA,MAAM,SAAS,OAAO,aAAa;AAGnC,MAAM,YAID;AAAA,EACH,IAAI,GAAG,UAAU,UAAU;AACrB,QAAA,aAAa,OAAe,QAAA;AACzB,WAAA,EAAE,IAAI,QAAQ;AAAA,EACvB;AAAA,EACA,IAAI,GAAG,UAAU;AACR,WAAA,EAAE,IAAI,QAAQ;AAAA,EACvB;AAAA,EACA,KAAK;AAAA,EACL,gBAAgB;AAAA,EAChB,yBAAyB,GAAG,UAAU;AAC7B,WAAA;AAAA,MACL,cAAc;AAAA,MACd,YAAY;AAAA,MACZ,MAAM;AACG,eAAA,EAAE,IAAI,QAAQ;AAAA,MACvB;AAAA,MACA,KAAK;AAAA,MACL,gBAAgB;AAAA,IAAA;AAAA,EAEpB;AAAA,EACA,QAAQ,GAAG;AACT,WAAO,EAAE;EACX;AACF;AAgBA,SAAS,cAAc,GAAQ;AACtB,SAAA,WAAW,IAAI,EAAE,QAAQ;AAClC;AAGO,SAAS,cAAc,SAAmB;AAC/C,SAAO,IAAI;AAAA,IACT;AAAA,MACE,IAAI,UAAoC;AACtC,iBAAS,IAAI,QAAQ,SAAS,GAAG,KAAK,GAAG,KAAK;AAC5C,gBAAM,IAAI,cAAc,QAAQ,CAAC,CAAC,EAAE,QAAQ;AACxC,cAAA,MAAM,OAAkB,QAAA;AAAA,QAC9B;AAAA,MACF;AAAA,MACA,IAAI,UAAoC;AACtC,iBAAS,IAAI,QAAQ,SAAS,GAAG,KAAK,GAAG,KAAK;AAC5C,cAAI,YAAY,cAAc,QAAQ,CAAC,CAAC,EAAU,QAAA;AAAA,QACpD;AACO,eAAA;AAAA,MACT;AAAA,MACA,OAAO;AACL,cAAM,OAAO,CAAA;AACb,iBAAS,IAAI,GAAG,IAAI,QAAQ,QAAQ;AAC7B,eAAA,KAAK,GAAG,OAAO,KAAK,cAAc,QAAQ,CAAC,CAAC,CAAC,CAAC;AAC9C,eAAA,CAAC,GAAG,MAAM,KAAK,IAAI,IAAI,IAAI,CAAC,CAAC;AAAA,MACtC;AAAA,IACF;AAAA,IACA;AAAA,EAAA;AAEJ;;"}
@@ -1,11 +0,0 @@
1
- type UnboxLazy<T> = T extends () => infer U ? U : T;
2
- type BoxedTupleTypes<T extends any[]> = {
3
- [P in keyof T]: [UnboxLazy<T[P]>];
4
- }[Exclude<keyof T, keyof any[]>];
5
- type UnionToIntersection<U> = (U extends any ? (k: U) => void : never) extends (k: infer I) => void ? I : never;
6
- type UnboxIntersection<T> = T extends {
7
- 0: infer U;
8
- } ? U : never;
9
- type MergeProxy<T extends any[]> = UnboxIntersection<UnionToIntersection<BoxedTupleTypes<T>>>;
10
- export declare function mergeProxy<T extends any[]>(...sources: T): MergeProxy<T>;
11
- export {};
@@ -1,14 +0,0 @@
1
- import { TableOptions, RowData } from '@tanstack/table-core';
2
-
3
- export * from '@tanstack/table-core';
4
- export declare const FlexRender: import('vue').DefineComponent<Readonly<{
5
- props?: any;
6
- render?: any;
7
- }>, () => any, unknown, {}, {}, import('vue').ComponentOptionsMixin, import('vue').ComponentOptionsMixin, {}, string, import('vue').PublicProps, Readonly<import('vue').ExtractPropTypes<Readonly<{
8
- props?: any;
9
- render?: any;
10
- }>>>, {
11
- readonly props?: any;
12
- readonly render?: any;
13
- }, {}>;
14
- export declare function useTable<TData extends RowData>(options: TableOptions<TData>): import('@tanstack/table-core').Table<TData>;