@tanstack/vue-table 9.0.0-alpha.10 → 9.0.0-alpha.25
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 +22 -0
- package/dist/FlexRender.cjs.map +1 -0
- package/dist/FlexRender.d.cts +13 -0
- package/dist/FlexRender.d.ts +13 -0
- package/dist/FlexRender.js +22 -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 +16 -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 +28 -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
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import { MaybeRef, VNode } from "vue";
|
|
2
|
+
import { NoInfer, RowData, Table, TableFeatures, TableOptions, TableState } from "@tanstack/table-core";
|
|
3
|
+
|
|
4
|
+
//#region src/useTable.d.ts
|
|
5
|
+
type TableOptionsWithReactiveData<TFeatures extends TableFeatures, TData extends RowData> = Omit<TableOptions<TFeatures, TData>, 'data'> & {
|
|
6
|
+
data: MaybeRef<ReadonlyArray<TData>>;
|
|
7
|
+
};
|
|
8
|
+
type VueTable<TFeatures extends TableFeatures, TData extends RowData, TSelected = {}> = Table<TFeatures, TData> & {
|
|
9
|
+
/**
|
|
10
|
+
* A Vue component that allows you to subscribe to the table state.
|
|
11
|
+
*
|
|
12
|
+
* This is useful for opting into state subscriptions for specific parts of the table state.
|
|
13
|
+
*
|
|
14
|
+
* @example
|
|
15
|
+
* <table.Subscribe selector={(state) => ({ rowSelection: state.rowSelection })}>
|
|
16
|
+
* {(state) => (
|
|
17
|
+
* <tr>
|
|
18
|
+
* // render the row
|
|
19
|
+
* </tr>
|
|
20
|
+
* )}
|
|
21
|
+
* </table.Subscribe>
|
|
22
|
+
*/
|
|
23
|
+
Subscribe: <TSelected>(props: {
|
|
24
|
+
selector: (state: NoInfer<TableState<TFeatures>>) => TSelected;
|
|
25
|
+
children: ((state: Readonly<TSelected>) => VNode | Array<VNode>) | VNode | Array<VNode>;
|
|
26
|
+
}) => VNode | Array<VNode>;
|
|
27
|
+
/**
|
|
28
|
+
* 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`.
|
|
29
|
+
*
|
|
30
|
+
* @example
|
|
31
|
+
* const table = useTable(options, (state) => ({ globalFilter: state.globalFilter })) // only globalFilter is part of the selected state
|
|
32
|
+
*
|
|
33
|
+
* console.log(table.state.globalFilter)
|
|
34
|
+
*/
|
|
35
|
+
readonly state: Readonly<TSelected>;
|
|
36
|
+
};
|
|
37
|
+
declare function useTable<TFeatures extends TableFeatures, TData extends RowData, TSelected = {}>(tableOptions: TableOptionsWithReactiveData<TFeatures, TData>, selector?: (state: TableState<TFeatures>) => TSelected): VueTable<TFeatures, TData, TSelected>;
|
|
38
|
+
//#endregion
|
|
39
|
+
export { TableOptionsWithReactiveData, VueTable, useTable };
|
|
40
|
+
//# sourceMappingURL=useTable.d.cts.map
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import { MaybeRef, VNode } from "vue";
|
|
2
|
+
import { NoInfer, RowData, Table, TableFeatures, TableOptions, TableState } from "@tanstack/table-core";
|
|
3
|
+
|
|
4
|
+
//#region src/useTable.d.ts
|
|
5
|
+
type TableOptionsWithReactiveData<TFeatures extends TableFeatures, TData extends RowData> = Omit<TableOptions<TFeatures, TData>, 'data'> & {
|
|
6
|
+
data: MaybeRef<ReadonlyArray<TData>>;
|
|
7
|
+
};
|
|
8
|
+
type VueTable<TFeatures extends TableFeatures, TData extends RowData, TSelected = {}> = Table<TFeatures, TData> & {
|
|
9
|
+
/**
|
|
10
|
+
* A Vue component that allows you to subscribe to the table state.
|
|
11
|
+
*
|
|
12
|
+
* This is useful for opting into state subscriptions for specific parts of the table state.
|
|
13
|
+
*
|
|
14
|
+
* @example
|
|
15
|
+
* <table.Subscribe selector={(state) => ({ rowSelection: state.rowSelection })}>
|
|
16
|
+
* {(state) => (
|
|
17
|
+
* <tr>
|
|
18
|
+
* // render the row
|
|
19
|
+
* </tr>
|
|
20
|
+
* )}
|
|
21
|
+
* </table.Subscribe>
|
|
22
|
+
*/
|
|
23
|
+
Subscribe: <TSelected>(props: {
|
|
24
|
+
selector: (state: NoInfer<TableState<TFeatures>>) => TSelected;
|
|
25
|
+
children: ((state: Readonly<TSelected>) => VNode | Array<VNode>) | VNode | Array<VNode>;
|
|
26
|
+
}) => VNode | Array<VNode>;
|
|
27
|
+
/**
|
|
28
|
+
* 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`.
|
|
29
|
+
*
|
|
30
|
+
* @example
|
|
31
|
+
* const table = useTable(options, (state) => ({ globalFilter: state.globalFilter })) // only globalFilter is part of the selected state
|
|
32
|
+
*
|
|
33
|
+
* console.log(table.state.globalFilter)
|
|
34
|
+
*/
|
|
35
|
+
readonly state: Readonly<TSelected>;
|
|
36
|
+
};
|
|
37
|
+
declare function useTable<TFeatures extends TableFeatures, TData extends RowData, TSelected = {}>(tableOptions: TableOptionsWithReactiveData<TFeatures, TData>, selector?: (state: TableState<TFeatures>) => TSelected): VueTable<TFeatures, TData, TSelected>;
|
|
38
|
+
//#endregion
|
|
39
|
+
export { TableOptionsWithReactiveData, VueTable, useTable };
|
|
40
|
+
//# sourceMappingURL=useTable.d.ts.map
|
package/dist/useTable.js
ADDED
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
import { mergeProxy } from "./merge-proxy.js";
|
|
2
|
+
import { isRef, ref, unref, watch, watchEffect } from "vue";
|
|
3
|
+
import { constructReactivityFeature, constructTable } from "@tanstack/table-core";
|
|
4
|
+
import { useStore } from "@tanstack/vue-store";
|
|
5
|
+
|
|
6
|
+
//#region src/useTable.ts
|
|
7
|
+
function getOptionsWithReactiveData(options) {
|
|
8
|
+
return mergeProxy(options, { data: unref(options.data) });
|
|
9
|
+
}
|
|
10
|
+
function useTable(tableOptions, selector = () => ({})) {
|
|
11
|
+
const notifier = ref(0);
|
|
12
|
+
const vueReactivityFeature = constructReactivityFeature({
|
|
13
|
+
stateNotifier: () => notifier.value,
|
|
14
|
+
optionsNotifier: () => notifier.value
|
|
15
|
+
});
|
|
16
|
+
const IS_REACTIVE = isRef(tableOptions.data);
|
|
17
|
+
const mergedOptions = {
|
|
18
|
+
...tableOptions,
|
|
19
|
+
_features: {
|
|
20
|
+
...tableOptions._features,
|
|
21
|
+
vueReactivityFeature
|
|
22
|
+
}
|
|
23
|
+
};
|
|
24
|
+
const table = constructTable(mergeProxy(IS_REACTIVE ? getOptionsWithReactiveData(mergedOptions) : mergedOptions, { mergeOptions: (defaultOptions, newOptions) => {
|
|
25
|
+
return mergeProxy(defaultOptions, newOptions);
|
|
26
|
+
} }));
|
|
27
|
+
const allState = useStore(table.store, (state) => state);
|
|
28
|
+
const allOptions = useStore(table.optionsStore, (state) => state);
|
|
29
|
+
watchEffect(() => {
|
|
30
|
+
allState.value;
|
|
31
|
+
allOptions.value;
|
|
32
|
+
notifier.value++;
|
|
33
|
+
});
|
|
34
|
+
watch(() => [IS_REACTIVE ? unref(tableOptions.data) : tableOptions.data, tableOptions], () => {
|
|
35
|
+
table.setOptions((prev) => {
|
|
36
|
+
return mergeProxy(prev, IS_REACTIVE ? getOptionsWithReactiveData(tableOptions) : tableOptions);
|
|
37
|
+
});
|
|
38
|
+
}, { immediate: true });
|
|
39
|
+
table.Subscribe = function Subscribe(props) {
|
|
40
|
+
const selected = useStore(table.store, props.selector);
|
|
41
|
+
if (typeof props.children === "function") return props.children(selected.value);
|
|
42
|
+
return props.children;
|
|
43
|
+
};
|
|
44
|
+
const stateStore = useStore(table.store, selector);
|
|
45
|
+
return {
|
|
46
|
+
...table,
|
|
47
|
+
get state() {
|
|
48
|
+
return stateStore.value;
|
|
49
|
+
}
|
|
50
|
+
};
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
//#endregion
|
|
54
|
+
export { useTable };
|
|
55
|
+
//# sourceMappingURL=useTable.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useTable.js","names":[],"sources":["../src/useTable.ts"],"sourcesContent":["import { isRef, ref, unref, watch, watchEffect } from 'vue'\nimport {\n constructReactivityFeature,\n constructTable,\n} from '@tanstack/table-core'\nimport { useStore } from '@tanstack/vue-store'\nimport { mergeProxy } from './merge-proxy'\nimport type {\n NoInfer,\n RowData,\n Table,\n TableFeatures,\n TableOptions,\n TableState,\n} from '@tanstack/table-core'\nimport type { MaybeRef, VNode } from 'vue'\n\nexport type TableOptionsWithReactiveData<\n TFeatures extends TableFeatures,\n TData extends RowData,\n> = Omit<TableOptions<TFeatures, TData>, 'data'> & {\n data: MaybeRef<ReadonlyArray<TData>>\n}\n\nfunction getOptionsWithReactiveData<\n TFeatures extends TableFeatures,\n TData extends RowData,\n>(options: TableOptionsWithReactiveData<TFeatures, TData>) {\n return mergeProxy(options, {\n data: unref(options.data),\n })\n}\n\nexport type VueTable<\n TFeatures extends TableFeatures,\n TData extends RowData,\n TSelected = {},\n> = Table<TFeatures, TData> & {\n /**\n * A Vue component that allows you to subscribe to the table state.\n *\n * This is useful for opting into state subscriptions for specific parts of the table state.\n *\n * @example\n * <table.Subscribe selector={(state) => ({ rowSelection: state.rowSelection })}>\n * {(state) => (\n * <tr>\n * // render the row\n * </tr>\n * )}\n * </table.Subscribe>\n */\n Subscribe: <TSelected>(props: {\n selector: (state: NoInfer<TableState<TFeatures>>) => TSelected\n children:\n | ((state: Readonly<TSelected>) => VNode | Array<VNode>)\n | VNode\n | Array<VNode>\n }) => VNode | Array<VNode>\n /**\n * 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`.\n *\n * @example\n * const table = useTable(options, (state) => ({ globalFilter: state.globalFilter })) // only globalFilter is part of the selected state\n *\n * console.log(table.state.globalFilter)\n */\n readonly state: Readonly<TSelected>\n}\n\nexport function useTable<\n TFeatures extends TableFeatures,\n TData extends RowData,\n TSelected = {},\n>(\n tableOptions: TableOptionsWithReactiveData<TFeatures, TData>,\n selector: (state: TableState<TFeatures>) => TSelected = () =>\n ({}) as TSelected,\n): VueTable<TFeatures, TData, TSelected> {\n const notifier = ref<number>(0)\n\n const vueReactivityFeature = constructReactivityFeature({\n stateNotifier: () => notifier.value,\n optionsNotifier: () => notifier.value,\n })\n\n const IS_REACTIVE = isRef(tableOptions.data)\n\n const mergedOptions = {\n ...tableOptions,\n _features: {\n ...tableOptions._features,\n vueReactivityFeature,\n },\n }\n\n const resolvedOptions = mergeProxy(\n IS_REACTIVE\n ? getOptionsWithReactiveData(\n mergedOptions as TableOptions<TFeatures, TData>,\n )\n : mergedOptions,\n {\n // Remove state and onStateChange - store handles it internally\n mergeOptions: (\n defaultOptions: TableOptions<TFeatures, TData>,\n newOptions: Partial<TableOptions<TFeatures, TData>>,\n ) => {\n return mergeProxy(defaultOptions, newOptions)\n },\n },\n ) as TableOptions<TFeatures, TData>\n\n const table = constructTable(resolvedOptions) as VueTable<\n TFeatures,\n TData,\n TSelected\n >\n\n const allState = useStore(table.store, (state) => state)\n const allOptions = useStore(table.optionsStore, (state) => state)\n\n watchEffect(() => {\n allState.value\n allOptions.value\n notifier.value++\n })\n\n watch(\n () =>\n [\n IS_REACTIVE ? unref(tableOptions.data) : tableOptions.data,\n tableOptions,\n ] as const,\n () => {\n table.setOptions((prev) => {\n return mergeProxy(\n prev,\n IS_REACTIVE\n ? getOptionsWithReactiveData(\n tableOptions as TableOptions<TFeatures, TData>,\n )\n : tableOptions,\n ) as TableOptions<TFeatures, TData>\n })\n },\n { immediate: true },\n )\n\n table.Subscribe = function Subscribe<TSelected>(props: {\n selector: (state: TableState<TFeatures>) => TSelected\n children:\n | ((state: Readonly<TSelected>) => VNode | Array<VNode>)\n | VNode\n | Array<VNode>\n }): VNode | Array<VNode> {\n const selected = useStore(table.store, props.selector)\n if (typeof props.children === 'function') {\n return props.children(selected.value)\n }\n return props.children\n }\n\n const stateStore = useStore(table.store, selector)\n\n return {\n ...table,\n get state() {\n return stateStore.value\n },\n } as VueTable<TFeatures, TData, TSelected>\n}\n"],"mappings":";;;;;;AAwBA,SAAS,2BAGP,SAAyD;AACzD,QAAO,WAAW,SAAS,EACzB,MAAM,MAAM,QAAQ,KAAK,EAC1B,CAAC;;AAwCJ,SAAgB,SAKd,cACA,kBACG,EAAE,GACkC;CACvC,MAAM,WAAW,IAAY,EAAE;CAE/B,MAAM,uBAAuB,2BAA2B;EACtD,qBAAqB,SAAS;EAC9B,uBAAuB,SAAS;EACjC,CAAC;CAEF,MAAM,cAAc,MAAM,aAAa,KAAK;CAE5C,MAAM,gBAAgB;EACpB,GAAG;EACH,WAAW;GACT,GAAG,aAAa;GAChB;GACD;EACF;CAmBD,MAAM,QAAQ,eAjBU,WACtB,cACI,2BACE,cACD,GACD,eACJ,EAEE,eACE,gBACA,eACG;AACH,SAAO,WAAW,gBAAgB,WAAW;IAEhD,CACF,CAE4C;CAM7C,MAAM,WAAW,SAAS,MAAM,QAAQ,UAAU,MAAM;CACxD,MAAM,aAAa,SAAS,MAAM,eAAe,UAAU,MAAM;AAEjE,mBAAkB;AAChB,WAAS;AACT,aAAW;AACX,WAAS;GACT;AAEF,aAEI,CACE,cAAc,MAAM,aAAa,KAAK,GAAG,aAAa,MACtD,aACD,QACG;AACJ,QAAM,YAAY,SAAS;AACzB,UAAO,WACL,MACA,cACI,2BACE,aACD,GACD,aACL;IACD;IAEJ,EAAE,WAAW,MAAM,CACpB;AAED,OAAM,YAAY,SAAS,UAAqB,OAMvB;EACvB,MAAM,WAAW,SAAS,MAAM,OAAO,MAAM,SAAS;AACtD,MAAI,OAAO,MAAM,aAAa,WAC5B,QAAO,MAAM,SAAS,SAAS,MAAM;AAEvC,SAAO,MAAM;;CAGf,MAAM,aAAa,SAAS,MAAM,OAAO,SAAS;AAElD,QAAO;EACL,GAAG;EACH,IAAI,QAAQ;AACV,UAAO,WAAW;;EAErB"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tanstack/vue-table",
|
|
3
|
-
"version": "9.0.0-alpha.
|
|
3
|
+
"version": "9.0.0-alpha.25",
|
|
4
4
|
"description": "Headless UI for building powerful tables & datagrids for Vue.",
|
|
5
5
|
"author": "Tanner Linsley",
|
|
6
6
|
"license": "MIT",
|
|
@@ -21,39 +21,41 @@
|
|
|
21
21
|
"datagrid"
|
|
22
22
|
],
|
|
23
23
|
"type": "module",
|
|
24
|
-
"types": "dist/
|
|
25
|
-
"main": "dist/
|
|
26
|
-
"module": "dist/
|
|
24
|
+
"types": "./dist/index.d.cts",
|
|
25
|
+
"main": "./dist/index.cjs",
|
|
26
|
+
"module": "./dist/index.js",
|
|
27
27
|
"exports": {
|
|
28
28
|
".": {
|
|
29
|
-
"import":
|
|
30
|
-
|
|
31
|
-
"default": "./dist/esm/index.js"
|
|
32
|
-
},
|
|
33
|
-
"require": {
|
|
34
|
-
"types": "./dist/cjs/index.d.cts",
|
|
35
|
-
"default": "./dist/cjs/index.cjs"
|
|
36
|
-
}
|
|
29
|
+
"import": "./dist/index.js",
|
|
30
|
+
"require": "./dist/index.cjs"
|
|
37
31
|
},
|
|
38
32
|
"./package.json": "./package.json"
|
|
39
33
|
},
|
|
40
34
|
"sideEffects": false,
|
|
41
35
|
"engines": {
|
|
42
|
-
"node": ">=
|
|
36
|
+
"node": ">=16"
|
|
43
37
|
},
|
|
44
38
|
"files": [
|
|
45
39
|
"dist",
|
|
46
40
|
"src"
|
|
47
41
|
],
|
|
48
42
|
"dependencies": {
|
|
49
|
-
"@tanstack/
|
|
43
|
+
"@tanstack/vue-store": "^0.9.3",
|
|
44
|
+
"@tanstack/table-core": "9.0.0-alpha.23"
|
|
50
45
|
},
|
|
51
46
|
"devDependencies": {
|
|
52
|
-
"@vitejs/plugin-vue": "^
|
|
53
|
-
"vue": "^
|
|
47
|
+
"@vitejs/plugin-vue": "^6.0.5",
|
|
48
|
+
"eslint-plugin-vue": "^10.8.0",
|
|
49
|
+
"vue": "^3.5.31"
|
|
54
50
|
},
|
|
55
51
|
"peerDependencies": {
|
|
56
52
|
"vue": ">=3.2"
|
|
57
53
|
},
|
|
58
|
-
"scripts": {
|
|
54
|
+
"scripts": {
|
|
55
|
+
"clean": "rimraf ./build && rimraf ./dist",
|
|
56
|
+
"test:eslint": "eslint ./src",
|
|
57
|
+
"test:types": "tsc",
|
|
58
|
+
"test:build": "publint --strict",
|
|
59
|
+
"build": "tsdown"
|
|
60
|
+
}
|
|
59
61
|
}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { defineComponent, h, isVNode } from 'vue'
|
|
2
|
+
|
|
3
|
+
export const FlexRender = defineComponent({
|
|
4
|
+
props: ['render', 'props'],
|
|
5
|
+
setup: (props: { render: any; props: any }) => {
|
|
6
|
+
return () => {
|
|
7
|
+
if (typeof props.render === 'function') {
|
|
8
|
+
const rendered = props.render(props.props)
|
|
9
|
+
|
|
10
|
+
if (isVNode(rendered)) {
|
|
11
|
+
return rendered
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
if (typeof rendered === 'function' || typeof rendered === 'object') {
|
|
15
|
+
return h(rendered, props.props)
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
return rendered
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
if (typeof props.render === 'object') {
|
|
22
|
+
return h(props.render, props.props)
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
return props.render
|
|
26
|
+
}
|
|
27
|
+
},
|
|
28
|
+
})
|