tanstack-table-vue 0.0.3
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/LICENSE +21 -0
- package/dist/components/TSTable.cjs +100 -0
- package/dist/components/TSTable.cjs.map +1 -0
- package/dist/components/TSTable.js +98 -0
- package/dist/components/TSTable.js.map +1 -0
- package/dist/index.cjs +14 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.ts +111 -0
- package/dist/index.js +4 -0
- package/dist/index.js.map +1 -0
- package/dist/shared/defineColumns.cjs +24 -0
- package/dist/shared/defineColumns.cjs.map +1 -0
- package/dist/shared/defineColumns.js +22 -0
- package/dist/shared/defineColumns.js.map +1 -0
- package/dist/shared/utils.cjs +72 -0
- package/dist/shared/utils.cjs.map +1 -0
- package/dist/shared/utils.js +70 -0
- package/dist/shared/utils.js.map +1 -0
- package/package.json +42 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2025 Evan N
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
|
@@ -0,0 +1,100 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
const vue = require('vue');
|
|
4
|
+
const vueTable = require('@tanstack/vue-table');
|
|
5
|
+
const shared_utils = require('../shared/utils.cjs');
|
|
6
|
+
|
|
7
|
+
const _hoisted_1 = { class: "p-2" };
|
|
8
|
+
const _hoisted_2 = ["colSpan"];
|
|
9
|
+
const _hoisted_3 = ["colSpan"];
|
|
10
|
+
const _sfc_main = /* @__PURE__ */ vue.defineComponent({
|
|
11
|
+
__name: "TSTable",
|
|
12
|
+
props: {
|
|
13
|
+
data: {},
|
|
14
|
+
columns: {}
|
|
15
|
+
},
|
|
16
|
+
setup(__props) {
|
|
17
|
+
const props = __props;
|
|
18
|
+
const slots = vue.useSlots();
|
|
19
|
+
const columnHelper = vueTable.createColumnHelper();
|
|
20
|
+
const tableColumns = vue.computed(() => {
|
|
21
|
+
return shared_utils.processColumns(columnHelper, props.columns, slots);
|
|
22
|
+
});
|
|
23
|
+
const table = vueTable.useVueTable({
|
|
24
|
+
get data() {
|
|
25
|
+
return props.data;
|
|
26
|
+
},
|
|
27
|
+
get columns() {
|
|
28
|
+
return tableColumns.value;
|
|
29
|
+
},
|
|
30
|
+
getCoreRowModel: vueTable.getCoreRowModel()
|
|
31
|
+
});
|
|
32
|
+
return (_ctx, _cache) => {
|
|
33
|
+
return vue.openBlock(), vue.createElementBlock("div", _hoisted_1, [
|
|
34
|
+
vue.createElementVNode("table", null, [
|
|
35
|
+
vue.createElementVNode("thead", null, [
|
|
36
|
+
(vue.openBlock(true), vue.createElementBlock(vue.Fragment, null, vue.renderList(vue.unref(table).getHeaderGroups(), (headerGroup) => {
|
|
37
|
+
return vue.openBlock(), vue.createElementBlock("tr", {
|
|
38
|
+
key: headerGroup.id
|
|
39
|
+
}, [
|
|
40
|
+
(vue.openBlock(true), vue.createElementBlock(vue.Fragment, null, vue.renderList(headerGroup.headers, (header) => {
|
|
41
|
+
return vue.openBlock(), vue.createElementBlock("th", {
|
|
42
|
+
key: header.id,
|
|
43
|
+
colSpan: header.colSpan
|
|
44
|
+
}, [
|
|
45
|
+
!header.isPlaceholder ? (vue.openBlock(), vue.createBlock(vue.unref(vueTable.FlexRender), {
|
|
46
|
+
key: 0,
|
|
47
|
+
render: header.column.columnDef.header,
|
|
48
|
+
props: header.getContext()
|
|
49
|
+
}, null, 8, ["render", "props"])) : vue.createCommentVNode("", true)
|
|
50
|
+
], 8, _hoisted_2);
|
|
51
|
+
}), 128))
|
|
52
|
+
]);
|
|
53
|
+
}), 128))
|
|
54
|
+
]),
|
|
55
|
+
vue.createElementVNode("tbody", null, [
|
|
56
|
+
(vue.openBlock(true), vue.createElementBlock(vue.Fragment, null, vue.renderList(vue.unref(table).getRowModel().rows, (row) => {
|
|
57
|
+
return vue.openBlock(), vue.createElementBlock("tr", {
|
|
58
|
+
key: row.id
|
|
59
|
+
}, [
|
|
60
|
+
(vue.openBlock(true), vue.createElementBlock(vue.Fragment, null, vue.renderList(row.getVisibleCells(), (cell) => {
|
|
61
|
+
return vue.openBlock(), vue.createElementBlock("td", {
|
|
62
|
+
key: cell.id
|
|
63
|
+
}, [
|
|
64
|
+
vue.createVNode(vue.unref(vueTable.FlexRender), {
|
|
65
|
+
render: cell.column.columnDef.cell,
|
|
66
|
+
props: cell.getContext()
|
|
67
|
+
}, null, 8, ["render", "props"])
|
|
68
|
+
]);
|
|
69
|
+
}), 128))
|
|
70
|
+
]);
|
|
71
|
+
}), 128))
|
|
72
|
+
]),
|
|
73
|
+
vue.createElementVNode("tfoot", null, [
|
|
74
|
+
(vue.openBlock(true), vue.createElementBlock(vue.Fragment, null, vue.renderList(vue.unref(table).getFooterGroups(), (footerGroup) => {
|
|
75
|
+
return vue.openBlock(), vue.createElementBlock("tr", {
|
|
76
|
+
key: footerGroup.id
|
|
77
|
+
}, [
|
|
78
|
+
(vue.openBlock(true), vue.createElementBlock(vue.Fragment, null, vue.renderList(footerGroup.headers, (header) => {
|
|
79
|
+
return vue.openBlock(), vue.createElementBlock("th", {
|
|
80
|
+
key: header.id,
|
|
81
|
+
colSpan: header.colSpan
|
|
82
|
+
}, [
|
|
83
|
+
!header.isPlaceholder ? (vue.openBlock(), vue.createBlock(vue.unref(vueTable.FlexRender), {
|
|
84
|
+
key: 0,
|
|
85
|
+
render: header.column.columnDef.footer,
|
|
86
|
+
props: header.getContext()
|
|
87
|
+
}, null, 8, ["render", "props"])) : vue.createCommentVNode("", true)
|
|
88
|
+
], 8, _hoisted_3);
|
|
89
|
+
}), 128))
|
|
90
|
+
]);
|
|
91
|
+
}), 128))
|
|
92
|
+
])
|
|
93
|
+
])
|
|
94
|
+
]);
|
|
95
|
+
};
|
|
96
|
+
}
|
|
97
|
+
});
|
|
98
|
+
|
|
99
|
+
exports._sfc_main = _sfc_main;
|
|
100
|
+
//# sourceMappingURL=TSTable.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"TSTable.cjs","sources":["../../src/components/TSTable.vue"],"sourcesContent":["<script lang=\"ts\">\nexport interface TSTableProps<TData extends object> {\n data: TData[]\n columns: ColumnDef<TData>[]\n}\n</script>\n\n<script setup lang=\"ts\" generic=\"TData extends object\">\nimport type { ColumnDef, HeaderSlotProps, CellSlotProps, FooterSlotProps } from '../shared/types'\nimport { computed, useSlots } from 'vue'\nimport { FlexRender } from '@tanstack/vue-table'\nimport {\n createColumnHelper,\n useVueTable,\n getCoreRowModel,\n} from '@tanstack/vue-table'\nimport { processColumns } from '../shared/utils';\n\nconst props = defineProps<TSTableProps<TData>>()\n\ndefineSlots<{\n [key: `cell-${string}`]: (props: CellSlotProps<TData>) => any;\n [key: `header-${string}`]: (props: HeaderSlotProps<TData>) => any;\n [key: `footer-${string}`]: (props: FooterSlotProps<TData>) => any;\n}>()\n\nconst slots = useSlots()\n\nconst columnHelper = createColumnHelper<TData>()\n\nconst tableColumns = computed(() => {\n return processColumns(columnHelper, props.columns, slots)\n})\n\nconst table = useVueTable<TData>({\n get data() {\n return props.data\n },\n get columns() {\n return tableColumns.value\n },\n getCoreRowModel: getCoreRowModel()\n})\n</script>\n\n<template>\n <div class=\"p-2\">\n <table>\n <thead>\n <tr v-for=\"headerGroup in table.getHeaderGroups()\" :key=\"headerGroup.id\">\n <th v-for=\"header in headerGroup.headers\" :key=\"header.id\" :colSpan=\"header.colSpan\">\n <FlexRender v-if=\"!header.isPlaceholder\" :render=\"header.column.columnDef.header\"\n :props=\"header.getContext()\" />\n </th>\n </tr>\n </thead>\n <tbody>\n <tr v-for=\"row in table.getRowModel().rows\" :key=\"row.id\">\n <td v-for=\"cell in row.getVisibleCells()\" :key=\"cell.id\">\n <FlexRender :render=\"cell.column.columnDef.cell\" :props=\"cell.getContext()\" />\n </td>\n </tr>\n </tbody>\n <tfoot>\n <tr v-for=\"footerGroup in table.getFooterGroups()\" :key=\"footerGroup.id\">\n <th v-for=\"header in footerGroup.headers\" :key=\"header.id\" :colSpan=\"header.colSpan\">\n <FlexRender v-if=\"!header.isPlaceholder\" :render=\"header.column.columnDef.footer\"\n :props=\"header.getContext()\" />\n </th>\n </tr>\n </tfoot>\n </table>\n </div>\n</template>"],"names":["useSlots","createColumnHelper","computed","processColumns","useVueTable","getCoreRowModel"],"mappings":";;;;;;;;;;;;;;;;AAkBA,IAAA,MAAM,KAAQ,GAAA,OAAA;AAQd,IAAA,MAAM,QAAQA,YAAS,EAAA;AAEvB,IAAA,MAAM,eAAeC,2BAA0B,EAAA;AAE/C,IAAM,MAAA,YAAA,GAAeC,aAAS,MAAM;AAClC,MAAA,OAAOC,2BAAe,CAAA,YAAA,EAAc,KAAM,CAAA,OAAA,EAAS,KAAK,CAAA;AAAA,KACzD,CAAA;AAED,IAAA,MAAM,QAAQC,oBAAmB,CAAA;AAAA,MAC/B,IAAI,IAAO,GAAA;AACT,QAAA,OAAO,KAAM,CAAA,IAAA;AAAA,OACf;AAAA,MACA,IAAI,OAAU,GAAA;AACZ,QAAA,OAAO,YAAa,CAAA,KAAA;AAAA,OACtB;AAAA,MACA,iBAAiBC,wBAAgB;AAAA,KAClC,CAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;"}
|
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
import { defineComponent, useSlots, computed, createElementBlock, openBlock, createElementVNode, Fragment, renderList, unref, createBlock, createCommentVNode, createVNode } from 'vue';
|
|
2
|
+
import { createColumnHelper, useVueTable, getCoreRowModel, FlexRender } from '@tanstack/vue-table';
|
|
3
|
+
import { p as processColumns } from '../shared/utils.js';
|
|
4
|
+
|
|
5
|
+
const _hoisted_1 = { class: "p-2" };
|
|
6
|
+
const _hoisted_2 = ["colSpan"];
|
|
7
|
+
const _hoisted_3 = ["colSpan"];
|
|
8
|
+
const _sfc_main = /* @__PURE__ */ defineComponent({
|
|
9
|
+
__name: "TSTable",
|
|
10
|
+
props: {
|
|
11
|
+
data: {},
|
|
12
|
+
columns: {}
|
|
13
|
+
},
|
|
14
|
+
setup(__props) {
|
|
15
|
+
const props = __props;
|
|
16
|
+
const slots = useSlots();
|
|
17
|
+
const columnHelper = createColumnHelper();
|
|
18
|
+
const tableColumns = computed(() => {
|
|
19
|
+
return processColumns(columnHelper, props.columns, slots);
|
|
20
|
+
});
|
|
21
|
+
const table = useVueTable({
|
|
22
|
+
get data() {
|
|
23
|
+
return props.data;
|
|
24
|
+
},
|
|
25
|
+
get columns() {
|
|
26
|
+
return tableColumns.value;
|
|
27
|
+
},
|
|
28
|
+
getCoreRowModel: getCoreRowModel()
|
|
29
|
+
});
|
|
30
|
+
return (_ctx, _cache) => {
|
|
31
|
+
return openBlock(), createElementBlock("div", _hoisted_1, [
|
|
32
|
+
createElementVNode("table", null, [
|
|
33
|
+
createElementVNode("thead", null, [
|
|
34
|
+
(openBlock(true), createElementBlock(Fragment, null, renderList(unref(table).getHeaderGroups(), (headerGroup) => {
|
|
35
|
+
return openBlock(), createElementBlock("tr", {
|
|
36
|
+
key: headerGroup.id
|
|
37
|
+
}, [
|
|
38
|
+
(openBlock(true), createElementBlock(Fragment, null, renderList(headerGroup.headers, (header) => {
|
|
39
|
+
return openBlock(), createElementBlock("th", {
|
|
40
|
+
key: header.id,
|
|
41
|
+
colSpan: header.colSpan
|
|
42
|
+
}, [
|
|
43
|
+
!header.isPlaceholder ? (openBlock(), createBlock(unref(FlexRender), {
|
|
44
|
+
key: 0,
|
|
45
|
+
render: header.column.columnDef.header,
|
|
46
|
+
props: header.getContext()
|
|
47
|
+
}, null, 8, ["render", "props"])) : createCommentVNode("", true)
|
|
48
|
+
], 8, _hoisted_2);
|
|
49
|
+
}), 128))
|
|
50
|
+
]);
|
|
51
|
+
}), 128))
|
|
52
|
+
]),
|
|
53
|
+
createElementVNode("tbody", null, [
|
|
54
|
+
(openBlock(true), createElementBlock(Fragment, null, renderList(unref(table).getRowModel().rows, (row) => {
|
|
55
|
+
return openBlock(), createElementBlock("tr", {
|
|
56
|
+
key: row.id
|
|
57
|
+
}, [
|
|
58
|
+
(openBlock(true), createElementBlock(Fragment, null, renderList(row.getVisibleCells(), (cell) => {
|
|
59
|
+
return openBlock(), createElementBlock("td", {
|
|
60
|
+
key: cell.id
|
|
61
|
+
}, [
|
|
62
|
+
createVNode(unref(FlexRender), {
|
|
63
|
+
render: cell.column.columnDef.cell,
|
|
64
|
+
props: cell.getContext()
|
|
65
|
+
}, null, 8, ["render", "props"])
|
|
66
|
+
]);
|
|
67
|
+
}), 128))
|
|
68
|
+
]);
|
|
69
|
+
}), 128))
|
|
70
|
+
]),
|
|
71
|
+
createElementVNode("tfoot", null, [
|
|
72
|
+
(openBlock(true), createElementBlock(Fragment, null, renderList(unref(table).getFooterGroups(), (footerGroup) => {
|
|
73
|
+
return openBlock(), createElementBlock("tr", {
|
|
74
|
+
key: footerGroup.id
|
|
75
|
+
}, [
|
|
76
|
+
(openBlock(true), createElementBlock(Fragment, null, renderList(footerGroup.headers, (header) => {
|
|
77
|
+
return openBlock(), createElementBlock("th", {
|
|
78
|
+
key: header.id,
|
|
79
|
+
colSpan: header.colSpan
|
|
80
|
+
}, [
|
|
81
|
+
!header.isPlaceholder ? (openBlock(), createBlock(unref(FlexRender), {
|
|
82
|
+
key: 0,
|
|
83
|
+
render: header.column.columnDef.footer,
|
|
84
|
+
props: header.getContext()
|
|
85
|
+
}, null, 8, ["render", "props"])) : createCommentVNode("", true)
|
|
86
|
+
], 8, _hoisted_3);
|
|
87
|
+
}), 128))
|
|
88
|
+
]);
|
|
89
|
+
}), 128))
|
|
90
|
+
])
|
|
91
|
+
])
|
|
92
|
+
]);
|
|
93
|
+
};
|
|
94
|
+
}
|
|
95
|
+
});
|
|
96
|
+
|
|
97
|
+
export { _sfc_main as _ };
|
|
98
|
+
//# sourceMappingURL=TSTable.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"TSTable.js","sources":["../../src/components/TSTable.vue"],"sourcesContent":["<script lang=\"ts\">\nexport interface TSTableProps<TData extends object> {\n data: TData[]\n columns: ColumnDef<TData>[]\n}\n</script>\n\n<script setup lang=\"ts\" generic=\"TData extends object\">\nimport type { ColumnDef, HeaderSlotProps, CellSlotProps, FooterSlotProps } from '../shared/types'\nimport { computed, useSlots } from 'vue'\nimport { FlexRender } from '@tanstack/vue-table'\nimport {\n createColumnHelper,\n useVueTable,\n getCoreRowModel,\n} from '@tanstack/vue-table'\nimport { processColumns } from '../shared/utils';\n\nconst props = defineProps<TSTableProps<TData>>()\n\ndefineSlots<{\n [key: `cell-${string}`]: (props: CellSlotProps<TData>) => any;\n [key: `header-${string}`]: (props: HeaderSlotProps<TData>) => any;\n [key: `footer-${string}`]: (props: FooterSlotProps<TData>) => any;\n}>()\n\nconst slots = useSlots()\n\nconst columnHelper = createColumnHelper<TData>()\n\nconst tableColumns = computed(() => {\n return processColumns(columnHelper, props.columns, slots)\n})\n\nconst table = useVueTable<TData>({\n get data() {\n return props.data\n },\n get columns() {\n return tableColumns.value\n },\n getCoreRowModel: getCoreRowModel()\n})\n</script>\n\n<template>\n <div class=\"p-2\">\n <table>\n <thead>\n <tr v-for=\"headerGroup in table.getHeaderGroups()\" :key=\"headerGroup.id\">\n <th v-for=\"header in headerGroup.headers\" :key=\"header.id\" :colSpan=\"header.colSpan\">\n <FlexRender v-if=\"!header.isPlaceholder\" :render=\"header.column.columnDef.header\"\n :props=\"header.getContext()\" />\n </th>\n </tr>\n </thead>\n <tbody>\n <tr v-for=\"row in table.getRowModel().rows\" :key=\"row.id\">\n <td v-for=\"cell in row.getVisibleCells()\" :key=\"cell.id\">\n <FlexRender :render=\"cell.column.columnDef.cell\" :props=\"cell.getContext()\" />\n </td>\n </tr>\n </tbody>\n <tfoot>\n <tr v-for=\"footerGroup in table.getFooterGroups()\" :key=\"footerGroup.id\">\n <th v-for=\"header in footerGroup.headers\" :key=\"header.id\" :colSpan=\"header.colSpan\">\n <FlexRender v-if=\"!header.isPlaceholder\" :render=\"header.column.columnDef.footer\"\n :props=\"header.getContext()\" />\n </th>\n </tr>\n </tfoot>\n </table>\n </div>\n</template>"],"names":[],"mappings":";;;;;;;;;;;;;;AAkBA,IAAA,MAAM,KAAQ,GAAA,OAAA;AAQd,IAAA,MAAM,QAAQ,QAAS,EAAA;AAEvB,IAAA,MAAM,eAAe,kBAA0B,EAAA;AAE/C,IAAM,MAAA,YAAA,GAAe,SAAS,MAAM;AAClC,MAAA,OAAO,cAAe,CAAA,YAAA,EAAc,KAAM,CAAA,OAAA,EAAS,KAAK,CAAA;AAAA,KACzD,CAAA;AAED,IAAA,MAAM,QAAQ,WAAmB,CAAA;AAAA,MAC/B,IAAI,IAAO,GAAA;AACT,QAAA,OAAO,KAAM,CAAA,IAAA;AAAA,OACf;AAAA,MACA,IAAI,OAAU,GAAA;AACZ,QAAA,OAAO,YAAa,CAAA,KAAA;AAAA,OACtB;AAAA,MACA,iBAAiB,eAAgB;AAAA,KAClC,CAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;"}
|
package/dist/index.cjs
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
4
|
+
|
|
5
|
+
const components_TSTable = require('./components/TSTable.cjs');
|
|
6
|
+
const shared_defineColumns = require('./shared/defineColumns.cjs');
|
|
7
|
+
const shared_utils = require('./shared/utils.cjs');
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
exports.TSTable = components_TSTable._sfc_main;
|
|
12
|
+
exports.defineColumns = shared_defineColumns.defineColumns;
|
|
13
|
+
exports.processColumns = shared_utils.processColumns;
|
|
14
|
+
//# sourceMappingURL=index.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.cjs","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;;;"}
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,111 @@
|
|
|
1
|
+
import { AllowedComponentProps } from 'vue';
|
|
2
|
+
import { CellContext } from '@tanstack/vue-table';
|
|
3
|
+
import { Column } from '@tanstack/vue-table';
|
|
4
|
+
import { ColumnDef as ColumnDef_2 } from '@tanstack/vue-table';
|
|
5
|
+
import { ColumnHelper } from '@tanstack/vue-table';
|
|
6
|
+
import { ComponentCustomProps } from 'vue';
|
|
7
|
+
import { HeaderContext } from '@tanstack/vue-table';
|
|
8
|
+
import { PublicProps } from 'vue';
|
|
9
|
+
import { Row } from '@tanstack/vue-table';
|
|
10
|
+
import { RowData } from '@tanstack/vue-table';
|
|
11
|
+
import { ShallowUnwrapRef } from 'vue';
|
|
12
|
+
import { Slots } from 'vue';
|
|
13
|
+
import { Table } from '@tanstack/vue-table';
|
|
14
|
+
import { VNode } from 'vue';
|
|
15
|
+
import { VNodeProps } from 'vue';
|
|
16
|
+
|
|
17
|
+
declare type __VLS_PrettifyLocal<T> = {
|
|
18
|
+
[K in keyof T]: T[K];
|
|
19
|
+
} & {};
|
|
20
|
+
|
|
21
|
+
export declare interface AccessorColumnDef {
|
|
22
|
+
id: string;
|
|
23
|
+
type?: "accessor";
|
|
24
|
+
header?: string;
|
|
25
|
+
footer?: string | ((props: any) => any);
|
|
26
|
+
cell?: (info: any) => any;
|
|
27
|
+
meta?: Record<string, any>;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
export declare interface CellSlotProps<TData extends RowData> {
|
|
31
|
+
row: Row<TData>;
|
|
32
|
+
context: CellContext<TData, unknown>;
|
|
33
|
+
value: any;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
declare type ColumnConfig<TData extends object> = {
|
|
37
|
+
id: keyof TData & string;
|
|
38
|
+
header?: string;
|
|
39
|
+
footer?: string;
|
|
40
|
+
};
|
|
41
|
+
|
|
42
|
+
export declare type ColumnDef<TData extends object> = DisplayColumnDef | AccessorColumnDef | GroupColumnDef<TData>;
|
|
43
|
+
|
|
44
|
+
export declare function defineColumns<TData extends object>(columns: (ColumnConfig<TData> | GroupConfig<TData>)[]): ColumnDef<TData>[];
|
|
45
|
+
|
|
46
|
+
export declare interface DisplayColumnDef {
|
|
47
|
+
id: string;
|
|
48
|
+
type: "display";
|
|
49
|
+
header?: string;
|
|
50
|
+
footer?: string | ((props: any) => any);
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
export declare interface FooterSlotProps<TData extends RowData> {
|
|
54
|
+
column: Column<TData>;
|
|
55
|
+
context: HeaderContext<TData, unknown>;
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
export declare interface GroupColumnDef<TData extends object> {
|
|
59
|
+
id: string;
|
|
60
|
+
type: "group";
|
|
61
|
+
header?: string;
|
|
62
|
+
footer?: string | ((props: any) => any);
|
|
63
|
+
columns: Array<ColumnDef_2<TData>>;
|
|
64
|
+
meta?: Record<string, any>;
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
declare type GroupConfig<TData extends object> = {
|
|
68
|
+
id: string;
|
|
69
|
+
header?: string;
|
|
70
|
+
footer?: string;
|
|
71
|
+
columns: ColumnConfig<TData>[];
|
|
72
|
+
};
|
|
73
|
+
|
|
74
|
+
export declare interface HeaderSlotProps<TData extends RowData> {
|
|
75
|
+
column: Column<TData>;
|
|
76
|
+
context: HeaderContext<TData, unknown>;
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
export declare const processColumns: <TData extends RowData & object>(columnHelper: ColumnHelper<TData>, columns: ColumnDef<TData>[], slots: Readonly<Slots>) => ColumnDef_2<TData>[];
|
|
80
|
+
|
|
81
|
+
export declare interface TableContext<TData extends RowData> {
|
|
82
|
+
table: Table<TData>;
|
|
83
|
+
column: Column<TData>;
|
|
84
|
+
row?: Row<TData>;
|
|
85
|
+
getValue: () => any;
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
export declare const TSTable: <TData extends object>(__VLS_props: NonNullable<Awaited<typeof __VLS_setup>>["props"], __VLS_ctx?: __VLS_PrettifyLocal<Pick<NonNullable<Awaited<typeof __VLS_setup>>, "attrs" | "emit" | "slots">>, __VLS_expose?: NonNullable<Awaited<typeof __VLS_setup>>["expose"], __VLS_setup?: Promise<{
|
|
89
|
+
props: __VLS_PrettifyLocal<Pick<Partial<{}> & Omit<{} & VNodeProps & AllowedComponentProps & ComponentCustomProps, never>, never> & TSTableProps<TData> & Partial<{}>> & PublicProps;
|
|
90
|
+
expose(exposed: ShallowUnwrapRef< {}>): void;
|
|
91
|
+
attrs: any;
|
|
92
|
+
slots: Readonly<{
|
|
93
|
+
[key: `cell-${string}`]: (props: CellSlotProps<TData>) => any;
|
|
94
|
+
[key: `header-${string}`]: (props: HeaderSlotProps<TData>) => any;
|
|
95
|
+
[key: `footer-${string}`]: (props: FooterSlotProps<TData>) => any;
|
|
96
|
+
}> & {
|
|
97
|
+
[key: `cell-${string}`]: (props: CellSlotProps<TData>) => any;
|
|
98
|
+
[key: `header-${string}`]: (props: HeaderSlotProps<TData>) => any;
|
|
99
|
+
[key: `footer-${string}`]: (props: FooterSlotProps<TData>) => any;
|
|
100
|
+
};
|
|
101
|
+
emit: {};
|
|
102
|
+
}>) => VNode & {
|
|
103
|
+
__ctx?: Awaited<typeof __VLS_setup>;
|
|
104
|
+
};
|
|
105
|
+
|
|
106
|
+
export declare interface TSTableProps<TData extends object> {
|
|
107
|
+
data: TData[];
|
|
108
|
+
columns: ColumnDef<TData>[];
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
export { }
|
package/dist/index.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;"}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
function defineColumns(columns) {
|
|
4
|
+
return columns.map((col) => {
|
|
5
|
+
if ("columns" in col) {
|
|
6
|
+
return {
|
|
7
|
+
id: col.id,
|
|
8
|
+
type: "group",
|
|
9
|
+
header: col.header,
|
|
10
|
+
footer: col.footer,
|
|
11
|
+
columns: defineColumns(col.columns)
|
|
12
|
+
};
|
|
13
|
+
}
|
|
14
|
+
return {
|
|
15
|
+
id: col.id,
|
|
16
|
+
type: "accessor",
|
|
17
|
+
header: col.header,
|
|
18
|
+
footer: col.footer
|
|
19
|
+
};
|
|
20
|
+
});
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
exports.defineColumns = defineColumns;
|
|
24
|
+
//# sourceMappingURL=defineColumns.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"defineColumns.cjs","sources":["../../src/shared/defineColumns.ts"],"sourcesContent":["import type { ColumnDef } from \"./types\";\n\ntype ColumnConfig<TData extends object> = {\n id: keyof TData & string;\n header?: string;\n footer?: string;\n};\n\ntype GroupConfig<TData extends object> = {\n id: string;\n header?: string;\n footer?: string;\n columns: ColumnConfig<TData>[];\n};\n\nexport function defineColumns<TData extends object>(\n columns: (ColumnConfig<TData> | GroupConfig<TData>)[]\n): ColumnDef<TData>[] {\n return columns.map((col): ColumnDef<TData> => {\n if (\"columns\" in col) {\n return {\n id: col.id,\n type: \"group\",\n header: col.header,\n footer: col.footer,\n columns: defineColumns(col.columns),\n };\n }\n\n return {\n id: col.id,\n type: \"accessor\",\n header: col.header,\n footer: col.footer,\n };\n });\n}\n"],"names":[],"mappings":";;AAeO,SAAS,cACd,OACoB,EAAA;AACpB,EAAO,OAAA,OAAA,CAAQ,GAAI,CAAA,CAAC,GAA0B,KAAA;AAC5C,IAAA,IAAI,aAAa,GAAK,EAAA;AACpB,MAAO,OAAA;AAAA,QACL,IAAI,GAAI,CAAA,EAAA;AAAA,QACR,IAAM,EAAA,OAAA;AAAA,QACN,QAAQ,GAAI,CAAA,MAAA;AAAA,QACZ,QAAQ,GAAI,CAAA,MAAA;AAAA,QACZ,OAAA,EAAS,aAAc,CAAA,GAAA,CAAI,OAAO;AAAA,OACpC;AAAA;AAGF,IAAO,OAAA;AAAA,MACL,IAAI,GAAI,CAAA,EAAA;AAAA,MACR,IAAM,EAAA,UAAA;AAAA,MACN,QAAQ,GAAI,CAAA,MAAA;AAAA,MACZ,QAAQ,GAAI,CAAA;AAAA,KACd;AAAA,GACD,CAAA;AACH;;;;"}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
function defineColumns(columns) {
|
|
2
|
+
return columns.map((col) => {
|
|
3
|
+
if ("columns" in col) {
|
|
4
|
+
return {
|
|
5
|
+
id: col.id,
|
|
6
|
+
type: "group",
|
|
7
|
+
header: col.header,
|
|
8
|
+
footer: col.footer,
|
|
9
|
+
columns: defineColumns(col.columns)
|
|
10
|
+
};
|
|
11
|
+
}
|
|
12
|
+
return {
|
|
13
|
+
id: col.id,
|
|
14
|
+
type: "accessor",
|
|
15
|
+
header: col.header,
|
|
16
|
+
footer: col.footer
|
|
17
|
+
};
|
|
18
|
+
});
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
export { defineColumns as d };
|
|
22
|
+
//# sourceMappingURL=defineColumns.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"defineColumns.js","sources":["../../src/shared/defineColumns.ts"],"sourcesContent":["import type { ColumnDef } from \"./types\";\n\ntype ColumnConfig<TData extends object> = {\n id: keyof TData & string;\n header?: string;\n footer?: string;\n};\n\ntype GroupConfig<TData extends object> = {\n id: string;\n header?: string;\n footer?: string;\n columns: ColumnConfig<TData>[];\n};\n\nexport function defineColumns<TData extends object>(\n columns: (ColumnConfig<TData> | GroupConfig<TData>)[]\n): ColumnDef<TData>[] {\n return columns.map((col): ColumnDef<TData> => {\n if (\"columns\" in col) {\n return {\n id: col.id,\n type: \"group\",\n header: col.header,\n footer: col.footer,\n columns: defineColumns(col.columns),\n };\n }\n\n return {\n id: col.id,\n type: \"accessor\",\n header: col.header,\n footer: col.footer,\n };\n });\n}\n"],"names":[],"mappings":"AAeO,SAAS,cACd,OACoB,EAAA;AACpB,EAAO,OAAA,OAAA,CAAQ,GAAI,CAAA,CAAC,GAA0B,KAAA;AAC5C,IAAA,IAAI,aAAa,GAAK,EAAA;AACpB,MAAO,OAAA;AAAA,QACL,IAAI,GAAI,CAAA,EAAA;AAAA,QACR,IAAM,EAAA,OAAA;AAAA,QACN,QAAQ,GAAI,CAAA,MAAA;AAAA,QACZ,QAAQ,GAAI,CAAA,MAAA;AAAA,QACZ,OAAA,EAAS,aAAc,CAAA,GAAA,CAAI,OAAO;AAAA,OACpC;AAAA;AAGF,IAAO,OAAA;AAAA,MACL,IAAI,GAAI,CAAA,EAAA;AAAA,MACR,IAAM,EAAA,UAAA;AAAA,MACN,QAAQ,GAAI,CAAA,MAAA;AAAA,MACZ,QAAQ,GAAI,CAAA;AAAA,KACd;AAAA,GACD,CAAA;AACH;;;;"}
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
const capitalize = require('lodash.capitalize');
|
|
4
|
+
|
|
5
|
+
const getHeader = (col, slots, context) => {
|
|
6
|
+
if (col.header) {
|
|
7
|
+
return col.header;
|
|
8
|
+
}
|
|
9
|
+
const slotName = `header-${col.id}`;
|
|
10
|
+
if (slots[slotName]) {
|
|
11
|
+
return slots[slotName]({
|
|
12
|
+
column: context.column,
|
|
13
|
+
context
|
|
14
|
+
});
|
|
15
|
+
}
|
|
16
|
+
return capitalize(col.id.split("-").join(" "));
|
|
17
|
+
};
|
|
18
|
+
const getFooter = (col, slots, context) => {
|
|
19
|
+
if (col.footer) {
|
|
20
|
+
return col.footer;
|
|
21
|
+
}
|
|
22
|
+
const slotName = `footer-${col.id}`;
|
|
23
|
+
if (slots[slotName]) {
|
|
24
|
+
return slots[slotName]({
|
|
25
|
+
column: context.column,
|
|
26
|
+
context
|
|
27
|
+
});
|
|
28
|
+
}
|
|
29
|
+
return void 0;
|
|
30
|
+
};
|
|
31
|
+
const getCell = (col, slots, context) => {
|
|
32
|
+
const slotName = `cell-${col.id}`;
|
|
33
|
+
if (slots[slotName]) {
|
|
34
|
+
return slots[slotName]({
|
|
35
|
+
row: context.row,
|
|
36
|
+
context,
|
|
37
|
+
value: context.getValue()
|
|
38
|
+
});
|
|
39
|
+
}
|
|
40
|
+
return context.getValue();
|
|
41
|
+
};
|
|
42
|
+
const processColumns = (columnHelper, columns, slots) => {
|
|
43
|
+
return columns.map((col) => {
|
|
44
|
+
if (col.type === "group") {
|
|
45
|
+
const groupCol = col;
|
|
46
|
+
return columnHelper.group({
|
|
47
|
+
id: groupCol.id,
|
|
48
|
+
header: (context) => getHeader(groupCol, slots, context),
|
|
49
|
+
footer: (context) => getFooter(groupCol, slots, context),
|
|
50
|
+
columns: processColumns(columnHelper, groupCol.columns, slots)
|
|
51
|
+
});
|
|
52
|
+
}
|
|
53
|
+
if (col.type === "display") {
|
|
54
|
+
return columnHelper.display({
|
|
55
|
+
id: col.id,
|
|
56
|
+
header: (context) => getHeader(col, slots, context),
|
|
57
|
+
footer: (context) => getFooter(col, slots, context),
|
|
58
|
+
cell: (context) => getCell(col, slots, context)
|
|
59
|
+
});
|
|
60
|
+
}
|
|
61
|
+
const accessorCol = col;
|
|
62
|
+
return columnHelper.accessor((row) => row[accessorCol.id], {
|
|
63
|
+
id: accessorCol.id,
|
|
64
|
+
header: (context) => getHeader(col, slots, context),
|
|
65
|
+
footer: (context) => getFooter(col, slots, context),
|
|
66
|
+
cell: (context) => getCell(col, slots, context)
|
|
67
|
+
});
|
|
68
|
+
});
|
|
69
|
+
};
|
|
70
|
+
|
|
71
|
+
exports.processColumns = processColumns;
|
|
72
|
+
//# sourceMappingURL=utils.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"utils.cjs","sources":["../../src/shared/utils.ts"],"sourcesContent":["import type {\n ColumnHelper,\n HeaderContext,\n CellContext,\n RowData,\n ColumnDef as TStackColumnDef,\n} from '@tanstack/vue-table'\nimport type { Slots } from 'vue'\nimport capitalize from 'lodash.capitalize'\nimport type {\n ColumnDef,\n AccessorColumnDef,\n GroupColumnDef,\n HeaderSlotProps,\n CellSlotProps,\n FooterSlotProps,\n} from './types'\n\nconst getHeader = <TData extends RowData & object>(\n col: ColumnDef<TData>,\n slots: Readonly<Slots>,\n context: HeaderContext<TData, unknown>,\n) => {\n if (col.header) {\n return col.header\n }\n\n const slotName = `header-${col.id}`\n\n if (slots[slotName]) {\n return slots[slotName]({\n column: context.column,\n context,\n } as HeaderSlotProps<TData>)\n }\n\n return capitalize(col.id.split('-').join(' '))\n}\n\nconst getFooter = <TData extends RowData & object>(\n col: ColumnDef<TData>,\n slots: Readonly<Slots>,\n context: HeaderContext<TData, unknown>,\n) => {\n if (col.footer) {\n return col.footer\n }\n\n const slotName = `footer-${col.id}`\n\n if (slots[slotName]) {\n return slots[slotName]({\n column: context.column,\n context,\n } as FooterSlotProps<TData>)\n }\n\n return undefined\n}\n\nconst getCell = <TData extends RowData & object>(\n col: ColumnDef<TData>,\n slots: Readonly<Slots>,\n context: CellContext<TData, unknown>,\n) => {\n const slotName = `cell-${col.id}`\n\n if (slots[slotName]) {\n return slots[slotName]({\n row: context.row,\n context,\n value: context.getValue(),\n } as CellSlotProps<TData>)\n }\n\n return context.getValue()\n}\n\nexport const processColumns = <TData extends RowData & object>(\n columnHelper: ColumnHelper<TData>,\n columns: ColumnDef<TData>[],\n slots: Readonly<Slots>,\n): TStackColumnDef<TData>[] => {\n return columns.map((col) => {\n if (col.type === 'group') {\n const groupCol = col as GroupColumnDef<TData>\n return columnHelper.group({\n id: groupCol.id,\n header: (context: HeaderContext<TData, unknown>) => getHeader(groupCol, slots, context),\n footer: (context: HeaderContext<TData, unknown>) => getFooter(groupCol, slots, context),\n columns: processColumns(columnHelper, groupCol.columns as ColumnDef<TData>[], slots),\n }) as TStackColumnDef<TData>\n }\n\n if (col.type === 'display') {\n return columnHelper.display({\n id: col.id,\n header: (context: HeaderContext<TData, unknown>) => getHeader(col, slots, context),\n footer: (context: HeaderContext<TData, unknown>) => getFooter(col, slots, context),\n cell: (context: CellContext<TData, unknown>) => getCell(col, slots, context),\n }) as TStackColumnDef<TData>\n }\n\n // For accessor columns\n const accessorCol = col as AccessorColumnDef\n return columnHelper.accessor((row) => row[accessorCol.id as keyof TData], {\n id: accessorCol.id,\n header: (context: HeaderContext<TData, unknown>) => getHeader(col, slots, context),\n footer: (context: HeaderContext<TData, unknown>) => getFooter(col, slots, context),\n cell: (context: CellContext<TData, unknown>) => getCell(col, slots, context),\n }) as TStackColumnDef<TData>\n })\n}\n"],"names":[],"mappings":";;;;AAkBA,MAAM,SAAY,GAAA,CAChB,GACA,EAAA,KAAA,EACA,OACG,KAAA;AACH,EAAA,IAAI,IA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C,OAAA,KAA2C,SAAU,CAAA,GAAA,EAAK,OAAO,OAAO,CAAA;AAAA,MACjF,MAAM,CAAC,OAAA,KAAyC,OAAQ,CAAA,GAAA,EAAK,OAAO,OAAO;AAAA,KAC5E,CAAA;AAAA,GACF,CAAA;AACH;;;;"}
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
import capitalize from 'lodash.capitalize';
|
|
2
|
+
|
|
3
|
+
const getHeader = (col, slots, context) => {
|
|
4
|
+
if (col.header) {
|
|
5
|
+
return col.header;
|
|
6
|
+
}
|
|
7
|
+
const slotName = `header-${col.id}`;
|
|
8
|
+
if (slots[slotName]) {
|
|
9
|
+
return slots[slotName]({
|
|
10
|
+
column: context.column,
|
|
11
|
+
context
|
|
12
|
+
});
|
|
13
|
+
}
|
|
14
|
+
return capitalize(col.id.split("-").join(" "));
|
|
15
|
+
};
|
|
16
|
+
const getFooter = (col, slots, context) => {
|
|
17
|
+
if (col.footer) {
|
|
18
|
+
return col.footer;
|
|
19
|
+
}
|
|
20
|
+
const slotName = `footer-${col.id}`;
|
|
21
|
+
if (slots[slotName]) {
|
|
22
|
+
return slots[slotName]({
|
|
23
|
+
column: context.column,
|
|
24
|
+
context
|
|
25
|
+
});
|
|
26
|
+
}
|
|
27
|
+
return void 0;
|
|
28
|
+
};
|
|
29
|
+
const getCell = (col, slots, context) => {
|
|
30
|
+
const slotName = `cell-${col.id}`;
|
|
31
|
+
if (slots[slotName]) {
|
|
32
|
+
return slots[slotName]({
|
|
33
|
+
row: context.row,
|
|
34
|
+
context,
|
|
35
|
+
value: context.getValue()
|
|
36
|
+
});
|
|
37
|
+
}
|
|
38
|
+
return context.getValue();
|
|
39
|
+
};
|
|
40
|
+
const processColumns = (columnHelper, columns, slots) => {
|
|
41
|
+
return columns.map((col) => {
|
|
42
|
+
if (col.type === "group") {
|
|
43
|
+
const groupCol = col;
|
|
44
|
+
return columnHelper.group({
|
|
45
|
+
id: groupCol.id,
|
|
46
|
+
header: (context) => getHeader(groupCol, slots, context),
|
|
47
|
+
footer: (context) => getFooter(groupCol, slots, context),
|
|
48
|
+
columns: processColumns(columnHelper, groupCol.columns, slots)
|
|
49
|
+
});
|
|
50
|
+
}
|
|
51
|
+
if (col.type === "display") {
|
|
52
|
+
return columnHelper.display({
|
|
53
|
+
id: col.id,
|
|
54
|
+
header: (context) => getHeader(col, slots, context),
|
|
55
|
+
footer: (context) => getFooter(col, slots, context),
|
|
56
|
+
cell: (context) => getCell(col, slots, context)
|
|
57
|
+
});
|
|
58
|
+
}
|
|
59
|
+
const accessorCol = col;
|
|
60
|
+
return columnHelper.accessor((row) => row[accessorCol.id], {
|
|
61
|
+
id: accessorCol.id,
|
|
62
|
+
header: (context) => getHeader(col, slots, context),
|
|
63
|
+
footer: (context) => getFooter(col, slots, context),
|
|
64
|
+
cell: (context) => getCell(col, slots, context)
|
|
65
|
+
});
|
|
66
|
+
});
|
|
67
|
+
};
|
|
68
|
+
|
|
69
|
+
export { processColumns as p };
|
|
70
|
+
//# sourceMappingURL=utils.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"utils.js","sources":["../../src/shared/utils.ts"],"sourcesContent":["import type {\n ColumnHelper,\n HeaderContext,\n CellContext,\n RowData,\n ColumnDef as TStackColumnDef,\n} from '@tanstack/vue-table'\nimport type { Slots } from 'vue'\nimport capitalize from 'lodash.capitalize'\nimport type {\n ColumnDef,\n AccessorColumnDef,\n GroupColumnDef,\n HeaderSlotProps,\n CellSlotProps,\n FooterSlotProps,\n} from './types'\n\nconst getHeader = <TData extends RowData & object>(\n col: ColumnDef<TData>,\n slots: Readonly<Slots>,\n context: HeaderContext<TData, unknown>,\n) => {\n if (col.header) {\n return col.header\n }\n\n const slotName = `header-${col.id}`\n\n if (slots[slotName]) {\n return slots[slotName]({\n column: context.column,\n context,\n } as HeaderSlotProps<TData>)\n }\n\n return capitalize(col.id.split('-').join(' '))\n}\n\nconst getFooter = <TData extends RowData & object>(\n col: ColumnDef<TData>,\n slots: Readonly<Slots>,\n context: HeaderContext<TData, unknown>,\n) => {\n if (col.footer) {\n return col.footer\n }\n\n const slotName = `footer-${col.id}`\n\n if (slots[slotName]) {\n return slots[slotName]({\n column: context.column,\n context,\n } as FooterSlotProps<TData>)\n }\n\n return undefined\n}\n\nconst getCell = <TData extends RowData & object>(\n col: ColumnDef<TData>,\n slots: Readonly<Slots>,\n context: CellContext<TData, unknown>,\n) => {\n const slotName = `cell-${col.id}`\n\n if (slots[slotName]) {\n return slots[slotName]({\n row: context.row,\n context,\n value: context.getValue(),\n } as CellSlotProps<TData>)\n }\n\n return context.getValue()\n}\n\nexport const processColumns = <TData extends RowData & object>(\n columnHelper: ColumnHelper<TData>,\n columns: ColumnDef<TData>[],\n slots: Readonly<Slots>,\n): TStackColumnDef<TData>[] => {\n return columns.map((col) => {\n if (col.type === 'group') {\n const groupCol = col as GroupColumnDef<TData>\n return columnHelper.group({\n id: groupCol.id,\n header: (context: HeaderContext<TData, unknown>) => getHeader(groupCol, slots, context),\n footer: (context: HeaderContext<TData, unknown>) => getFooter(groupCol, slots, context),\n columns: processColumns(columnHelper, groupCol.columns as ColumnDef<TData>[], slots),\n }) as TStackColumnDef<TData>\n }\n\n if (col.type === 'display') {\n return columnHelper.display({\n id: col.id,\n header: (context: HeaderContext<TData, unknown>) => getHeader(col, slots, context),\n footer: (context: HeaderContext<TData, unknown>) => getFooter(col, slots, context),\n cell: (context: CellContext<TData, unknown>) => getCell(col, slots, context),\n }) as TStackColumnDef<TData>\n }\n\n // For accessor columns\n const accessorCol = col as AccessorColumnDef\n return columnHelper.accessor((row) => row[accessorCol.id as keyof TData], {\n id: accessorCol.id,\n header: (context: HeaderContext<TData, unknown>) => getHeader(col, slots, context),\n footer: (context: HeaderContext<TData, unknown>) => getFooter(col, slots, context),\n cell: (context: CellContext<TData, unknown>) => getCell(col, slots, context),\n }) as TStackColumnDef<TData>\n })\n}\n"],"names":[],"mappings":";;AAkBA,MAAM,SAAY,GAAA,CAChB,GAC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A,EAAK,OAAO,OAAO,CAAA;AAAA,MACjF,QAAQ,CAAC,OAAA,KAA2C,SAAU,CAAA,GAAA,EAAK,OAAO,OAAO,CAAA;AAAA,MACjF,MAAM,CAAC,OAAA,KAAyC,OAAQ,CAAA,GAAA,EAAK,OAAO,OAAO;AAAA,KAC5E,CAAA;AAAA,GACF,CAAA;AACH;;;;"}
|
package/package.json
ADDED
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "tanstack-table-vue",
|
|
3
|
+
"version": "0.0.3",
|
|
4
|
+
"type": "module",
|
|
5
|
+
"exports": {
|
|
6
|
+
".": {
|
|
7
|
+
"types": "./dist/index.d.ts",
|
|
8
|
+
"import": "./dist/index.js",
|
|
9
|
+
"require": "./dist/index.cjs"
|
|
10
|
+
}
|
|
11
|
+
},
|
|
12
|
+
"files": [
|
|
13
|
+
"./dist"
|
|
14
|
+
],
|
|
15
|
+
"main": "./dist/index.cjs",
|
|
16
|
+
"module": "./dist/index.js",
|
|
17
|
+
"types": "./dist/index.d.ts",
|
|
18
|
+
"typings": "./dist/index.d.ts",
|
|
19
|
+
"dependencies": {
|
|
20
|
+
"@tanstack/vue-table": "^8.21.2",
|
|
21
|
+
"lodash.capitalize": "^4.2.1",
|
|
22
|
+
"vue": "^3.5.13"
|
|
23
|
+
},
|
|
24
|
+
"devDependencies": {
|
|
25
|
+
"@types/lodash.capitalize": "^4.2.9",
|
|
26
|
+
"@types/node": "^22.14.0",
|
|
27
|
+
"@vitejs/plugin-vue": "^5.2.1",
|
|
28
|
+
"@vue/tsconfig": "^0.7.0",
|
|
29
|
+
"typescript": "~5.7.2",
|
|
30
|
+
"vite": "^6.2.0",
|
|
31
|
+
"vite-plugin-dts": "^4.5.3",
|
|
32
|
+
"vue-tsc": "^2.2.4"
|
|
33
|
+
},
|
|
34
|
+
"scripts": {
|
|
35
|
+
"build": "pnpm type-check && pnpm build-only",
|
|
36
|
+
"build-only": "vite build",
|
|
37
|
+
"watch": "vite build --watch",
|
|
38
|
+
"type-check": "vue-tsc -p tsconfig.check.json --noEmit",
|
|
39
|
+
"type-gen": "vue-tsc --declaration --emitDeclarationOnly",
|
|
40
|
+
"pub:release": "pnpm publish --no-git-checks --access public"
|
|
41
|
+
}
|
|
42
|
+
}
|