@tanstack/vue-table 9.0.0-alpha.10 → 9.0.0-alpha.26
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/README.md +117 -0
- package/dist/FlexRender.cjs +73 -0
- package/dist/FlexRender.cjs.map +1 -0
- package/dist/FlexRender.d.cts +46 -0
- package/dist/FlexRender.d.ts +46 -0
- package/dist/FlexRender.js +72 -0
- package/dist/FlexRender.js.map +1 -0
- package/dist/createTableHook.cjs +216 -0
- package/dist/createTableHook.cjs.map +1 -0
- package/dist/createTableHook.d.cts +121 -0
- package/dist/createTableHook.d.ts +121 -0
- package/dist/createTableHook.js +215 -0
- package/dist/createTableHook.js.map +1 -0
- package/dist/index.cjs +17 -0
- package/dist/index.d.cts +5 -0
- package/dist/index.d.ts +5 -0
- package/dist/index.js +7 -0
- package/dist/merge-proxy.cjs +57 -0
- package/dist/merge-proxy.cjs.map +1 -0
- package/dist/merge-proxy.js +56 -0
- package/dist/merge-proxy.js.map +1 -0
- package/dist/useTable.cjs +55 -0
- package/dist/useTable.cjs.map +1 -0
- package/dist/useTable.d.cts +40 -0
- package/dist/useTable.d.ts +40 -0
- package/dist/useTable.js +55 -0
- package/dist/useTable.js.map +1 -0
- package/package.json +19 -17
- package/src/FlexRender.ts +109 -0
- package/src/createTableHook.ts +576 -0
- package/src/index.ts +3 -74
- package/src/merge-proxy.ts +10 -10
- package/src/useTable.ts +172 -0
- package/dist/cjs/index.cjs +0 -68
- package/dist/cjs/index.cjs.map +0 -1
- package/dist/cjs/index.d.cts +0 -14
- package/dist/cjs/merge-proxy.cjs +0 -61
- package/dist/cjs/merge-proxy.cjs.map +0 -1
- package/dist/cjs/merge-proxy.d.cts +0 -11
- package/dist/esm/index.d.ts +0 -14
- package/dist/esm/index.js +0 -63
- package/dist/esm/index.js.map +0 -1
- package/dist/esm/merge-proxy.d.ts +0 -11
- package/dist/esm/merge-proxy.js +0 -61
- package/dist/esm/merge-proxy.js.map +0 -1
package/src/useTable.ts
ADDED
|
@@ -0,0 +1,172 @@
|
|
|
1
|
+
import { isRef, ref, unref, watch, watchEffect } from 'vue'
|
|
2
|
+
import {
|
|
3
|
+
constructReactivityFeature,
|
|
4
|
+
constructTable,
|
|
5
|
+
} from '@tanstack/table-core'
|
|
6
|
+
import { useStore } from '@tanstack/vue-store'
|
|
7
|
+
import { mergeProxy } from './merge-proxy'
|
|
8
|
+
import type {
|
|
9
|
+
NoInfer,
|
|
10
|
+
RowData,
|
|
11
|
+
Table,
|
|
12
|
+
TableFeatures,
|
|
13
|
+
TableOptions,
|
|
14
|
+
TableState,
|
|
15
|
+
} from '@tanstack/table-core'
|
|
16
|
+
import type { MaybeRef, VNode } from 'vue'
|
|
17
|
+
|
|
18
|
+
export type TableOptionsWithReactiveData<
|
|
19
|
+
TFeatures extends TableFeatures,
|
|
20
|
+
TData extends RowData,
|
|
21
|
+
> = Omit<TableOptions<TFeatures, TData>, 'data'> & {
|
|
22
|
+
data: MaybeRef<ReadonlyArray<TData>>
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
function getOptionsWithReactiveData<
|
|
26
|
+
TFeatures extends TableFeatures,
|
|
27
|
+
TData extends RowData,
|
|
28
|
+
>(options: TableOptionsWithReactiveData<TFeatures, TData>) {
|
|
29
|
+
return mergeProxy(options, {
|
|
30
|
+
data: unref(options.data),
|
|
31
|
+
})
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
export type VueTable<
|
|
35
|
+
TFeatures extends TableFeatures,
|
|
36
|
+
TData extends RowData,
|
|
37
|
+
TSelected = {},
|
|
38
|
+
> = Table<TFeatures, TData> & {
|
|
39
|
+
/**
|
|
40
|
+
* A Vue component that allows you to subscribe to the table state.
|
|
41
|
+
*
|
|
42
|
+
* This is useful for opting into state subscriptions for specific parts of the table state.
|
|
43
|
+
*
|
|
44
|
+
* @example
|
|
45
|
+
* <table.Subscribe selector={(state) => ({ rowSelection: state.rowSelection })}>
|
|
46
|
+
* {(state) => (
|
|
47
|
+
* <tr>
|
|
48
|
+
* // render the row
|
|
49
|
+
* </tr>
|
|
50
|
+
* )}
|
|
51
|
+
* </table.Subscribe>
|
|
52
|
+
*/
|
|
53
|
+
Subscribe: <TSelected>(props: {
|
|
54
|
+
selector: (state: NoInfer<TableState<TFeatures>>) => TSelected
|
|
55
|
+
children:
|
|
56
|
+
| ((state: Readonly<TSelected>) => VNode | Array<VNode>)
|
|
57
|
+
| VNode
|
|
58
|
+
| Array<VNode>
|
|
59
|
+
}) => VNode | Array<VNode>
|
|
60
|
+
/**
|
|
61
|
+
* The selected state of the table. This state may not match the structure of `table.store.state` because it is selected by the `selector` function that you pass as the 2nd argument to `useTable`.
|
|
62
|
+
*
|
|
63
|
+
* @example
|
|
64
|
+
* const table = useTable(options, (state) => ({ globalFilter: state.globalFilter })) // only globalFilter is part of the selected state
|
|
65
|
+
*
|
|
66
|
+
* console.log(table.state.globalFilter)
|
|
67
|
+
*/
|
|
68
|
+
readonly state: Readonly<TSelected>
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
export function useTable<
|
|
72
|
+
TFeatures extends TableFeatures,
|
|
73
|
+
TData extends RowData,
|
|
74
|
+
TSelected = {},
|
|
75
|
+
>(
|
|
76
|
+
tableOptions: TableOptionsWithReactiveData<TFeatures, TData>,
|
|
77
|
+
selector: (state: TableState<TFeatures>) => TSelected = () =>
|
|
78
|
+
({}) as TSelected,
|
|
79
|
+
): VueTable<TFeatures, TData, TSelected> {
|
|
80
|
+
const notifier = ref<number>(0)
|
|
81
|
+
|
|
82
|
+
const vueReactivityFeature = constructReactivityFeature({
|
|
83
|
+
stateNotifier: () => notifier.value,
|
|
84
|
+
optionsNotifier: () => notifier.value,
|
|
85
|
+
})
|
|
86
|
+
|
|
87
|
+
const IS_REACTIVE = isRef(tableOptions.data)
|
|
88
|
+
|
|
89
|
+
const mergedOptions = {
|
|
90
|
+
...tableOptions,
|
|
91
|
+
_features: {
|
|
92
|
+
...tableOptions._features,
|
|
93
|
+
vueReactivityFeature,
|
|
94
|
+
},
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
const resolvedOptions = mergeProxy(
|
|
98
|
+
IS_REACTIVE
|
|
99
|
+
? getOptionsWithReactiveData(
|
|
100
|
+
mergedOptions as TableOptions<TFeatures, TData>,
|
|
101
|
+
)
|
|
102
|
+
: mergedOptions,
|
|
103
|
+
{
|
|
104
|
+
// Remove state and onStateChange - store handles it internally
|
|
105
|
+
mergeOptions: (
|
|
106
|
+
defaultOptions: TableOptions<TFeatures, TData>,
|
|
107
|
+
newOptions: Partial<TableOptions<TFeatures, TData>>,
|
|
108
|
+
) => {
|
|
109
|
+
return mergeProxy(defaultOptions, newOptions)
|
|
110
|
+
},
|
|
111
|
+
},
|
|
112
|
+
) as TableOptions<TFeatures, TData>
|
|
113
|
+
|
|
114
|
+
const table = constructTable(resolvedOptions) as VueTable<
|
|
115
|
+
TFeatures,
|
|
116
|
+
TData,
|
|
117
|
+
TSelected
|
|
118
|
+
>
|
|
119
|
+
|
|
120
|
+
const allState = useStore(table.store, (state) => state)
|
|
121
|
+
const allOptions = useStore(table.optionsStore, (state) => state)
|
|
122
|
+
|
|
123
|
+
watchEffect(() => {
|
|
124
|
+
allState.value
|
|
125
|
+
allOptions.value
|
|
126
|
+
notifier.value++
|
|
127
|
+
})
|
|
128
|
+
|
|
129
|
+
watch(
|
|
130
|
+
() =>
|
|
131
|
+
[
|
|
132
|
+
IS_REACTIVE ? unref(tableOptions.data) : tableOptions.data,
|
|
133
|
+
tableOptions,
|
|
134
|
+
] as const,
|
|
135
|
+
() => {
|
|
136
|
+
table.setOptions((prev) => {
|
|
137
|
+
return mergeProxy(
|
|
138
|
+
prev,
|
|
139
|
+
IS_REACTIVE
|
|
140
|
+
? getOptionsWithReactiveData(
|
|
141
|
+
tableOptions as TableOptions<TFeatures, TData>,
|
|
142
|
+
)
|
|
143
|
+
: tableOptions,
|
|
144
|
+
) as TableOptions<TFeatures, TData>
|
|
145
|
+
})
|
|
146
|
+
},
|
|
147
|
+
{ immediate: true },
|
|
148
|
+
)
|
|
149
|
+
|
|
150
|
+
table.Subscribe = function Subscribe<TSelected>(props: {
|
|
151
|
+
selector: (state: TableState<TFeatures>) => TSelected
|
|
152
|
+
children:
|
|
153
|
+
| ((state: Readonly<TSelected>) => VNode | Array<VNode>)
|
|
154
|
+
| VNode
|
|
155
|
+
| Array<VNode>
|
|
156
|
+
}): VNode | Array<VNode> {
|
|
157
|
+
const selected = useStore(table.store, props.selector)
|
|
158
|
+
if (typeof props.children === 'function') {
|
|
159
|
+
return props.children(selected.value)
|
|
160
|
+
}
|
|
161
|
+
return props.children
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
const stateStore = useStore(table.store, selector)
|
|
165
|
+
|
|
166
|
+
return {
|
|
167
|
+
...table,
|
|
168
|
+
get state() {
|
|
169
|
+
return stateStore.value
|
|
170
|
+
},
|
|
171
|
+
} as VueTable<TFeatures, TData, TSelected>
|
|
172
|
+
}
|
package/dist/cjs/index.cjs
DELETED
|
@@ -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
|
package/dist/cjs/index.cjs.map
DELETED
|
@@ -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;;;;;;;;;"}
|
package/dist/cjs/index.d.cts
DELETED
|
@@ -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>;
|
package/dist/cjs/merge-proxy.cjs
DELETED
|
@@ -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 {};
|
package/dist/esm/index.d.ts
DELETED
|
@@ -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>;
|
package/dist/esm/index.js
DELETED
|
@@ -1,63 +0,0 @@
|
|
|
1
|
-
import { _createTable } from "@tanstack/table-core";
|
|
2
|
-
export * from "@tanstack/table-core";
|
|
3
|
-
import { defineComponent, h, ref, watchEffect } from "vue";
|
|
4
|
-
import { mergeProxy } from "./merge-proxy.js";
|
|
5
|
-
const FlexRender = defineComponent({
|
|
6
|
-
props: ["render", "props"],
|
|
7
|
-
setup: (props) => {
|
|
8
|
-
return () => {
|
|
9
|
-
if (typeof props.render === "function" || typeof props.render === "object") {
|
|
10
|
-
return h(props.render, props.props);
|
|
11
|
-
}
|
|
12
|
-
return props.render;
|
|
13
|
-
};
|
|
14
|
-
}
|
|
15
|
-
});
|
|
16
|
-
function useTable(options) {
|
|
17
|
-
const resolvedOptions = mergeProxy(
|
|
18
|
-
{
|
|
19
|
-
state: {},
|
|
20
|
-
// Dummy state
|
|
21
|
-
onStateChange: () => {
|
|
22
|
-
},
|
|
23
|
-
// noop
|
|
24
|
-
renderFallbackValue: null,
|
|
25
|
-
mergeOptions(defaultOptions, options2) {
|
|
26
|
-
return mergeProxy(defaultOptions, options2);
|
|
27
|
-
}
|
|
28
|
-
},
|
|
29
|
-
options
|
|
30
|
-
);
|
|
31
|
-
const table = _createTable(resolvedOptions);
|
|
32
|
-
const state = ref(table.initialState);
|
|
33
|
-
watchEffect(() => {
|
|
34
|
-
table.setOptions((prev) => {
|
|
35
|
-
const stateProxy = new Proxy({}, {
|
|
36
|
-
get: (_, prop) => state.value[prop]
|
|
37
|
-
});
|
|
38
|
-
return mergeProxy(prev, options, {
|
|
39
|
-
// merge the initialState and `options.state`
|
|
40
|
-
// create a new proxy on each `setOptions` call
|
|
41
|
-
// and get the value from state on each property access
|
|
42
|
-
state: mergeProxy(stateProxy, options.state ?? {}),
|
|
43
|
-
// Similarly, we'll maintain both our internal state and any user-provided
|
|
44
|
-
// state.
|
|
45
|
-
onStateChange: (updater) => {
|
|
46
|
-
var _a;
|
|
47
|
-
if (updater instanceof Function) {
|
|
48
|
-
state.value = updater(state.value);
|
|
49
|
-
} else {
|
|
50
|
-
state.value = updater;
|
|
51
|
-
}
|
|
52
|
-
(_a = options.onStateChange) == null ? void 0 : _a.call(options, updater);
|
|
53
|
-
}
|
|
54
|
-
});
|
|
55
|
-
});
|
|
56
|
-
});
|
|
57
|
-
return table;
|
|
58
|
-
}
|
|
59
|
-
export {
|
|
60
|
-
FlexRender,
|
|
61
|
-
useTable
|
|
62
|
-
};
|
|
63
|
-
//# sourceMappingURL=index.js.map
|
package/dist/esm/index.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","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":["options"],"mappings":";;;;AAWO,MAAM,aAAa,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,eAAO,EAAE,MAAM,QAAQ,MAAM,KAAK;AAAA,MACpC;AAEA,aAAO,MAAM;AAAA,IAAA;AAAA,EAEjB;AACF,CAAC;AAEM,SAAS,SAAgC,SAA8B;AAC5E,QAAM,kBAA+C;AAAA,IACnD;AAAA,MACE,OAAO,CAAC;AAAA;AAAA,MACR,eAAe,MAAM;AAAA,MAAC;AAAA;AAAA,MACtB,qBAAqB;AAAA,MACrB,aACE,gBACAA,UACA;AACO,eAAA,WAAW,gBAAgBA,QAAO;AAAA,MAC3C;AAAA,IACF;AAAA,IACA;AAAA,EAAA;AAGI,QAAA,QAAQ,aAAoB,eAAe;AAE3C,QAAA,QAAQ,IAAI,MAAM,YAAY;AAEpC,cAAY,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,aAAA,WAAW,MAAM,SAAS;AAAA;AAAA;AAAA;AAAA,QAI/B,OAAO,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,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 {};
|
package/dist/esm/merge-proxy.js
DELETED
|
@@ -1,61 +0,0 @@
|
|
|
1
|
-
function trueFn() {
|
|
2
|
-
return true;
|
|
3
|
-
}
|
|
4
|
-
const $PROXY = Symbol("merge-proxy");
|
|
5
|
-
const propTraps = {
|
|
6
|
-
get(_, property, receiver) {
|
|
7
|
-
if (property === $PROXY) return receiver;
|
|
8
|
-
return _.get(property);
|
|
9
|
-
},
|
|
10
|
-
has(_, property) {
|
|
11
|
-
return _.has(property);
|
|
12
|
-
},
|
|
13
|
-
set: trueFn,
|
|
14
|
-
deleteProperty: trueFn,
|
|
15
|
-
getOwnPropertyDescriptor(_, property) {
|
|
16
|
-
return {
|
|
17
|
-
configurable: true,
|
|
18
|
-
enumerable: true,
|
|
19
|
-
get() {
|
|
20
|
-
return _.get(property);
|
|
21
|
-
},
|
|
22
|
-
set: trueFn,
|
|
23
|
-
deleteProperty: trueFn
|
|
24
|
-
};
|
|
25
|
-
},
|
|
26
|
-
ownKeys(_) {
|
|
27
|
-
return _.keys();
|
|
28
|
-
}
|
|
29
|
-
};
|
|
30
|
-
function resolveSource(s) {
|
|
31
|
-
return "value" in s ? s.value : s;
|
|
32
|
-
}
|
|
33
|
-
function mergeProxy(...sources) {
|
|
34
|
-
return new Proxy(
|
|
35
|
-
{
|
|
36
|
-
get(property) {
|
|
37
|
-
for (let i = sources.length - 1; i >= 0; i--) {
|
|
38
|
-
const v = resolveSource(sources[i])[property];
|
|
39
|
-
if (v !== void 0) return v;
|
|
40
|
-
}
|
|
41
|
-
},
|
|
42
|
-
has(property) {
|
|
43
|
-
for (let i = sources.length - 1; i >= 0; i--) {
|
|
44
|
-
if (property in resolveSource(sources[i])) return true;
|
|
45
|
-
}
|
|
46
|
-
return false;
|
|
47
|
-
},
|
|
48
|
-
keys() {
|
|
49
|
-
const keys = [];
|
|
50
|
-
for (let i = 0; i < sources.length; i++)
|
|
51
|
-
keys.push(...Object.keys(resolveSource(sources[i])));
|
|
52
|
-
return [...Array.from(new Set(keys))];
|
|
53
|
-
}
|
|
54
|
-
},
|
|
55
|
-
propTraps
|
|
56
|
-
);
|
|
57
|
-
}
|
|
58
|
-
export {
|
|
59
|
-
mergeProxy
|
|
60
|
-
};
|
|
61
|
-
//# sourceMappingURL=merge-proxy.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"merge-proxy.js","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;"}
|