stk-table-vue 0.6.13 → 0.6.14
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.
|
@@ -646,12 +646,12 @@ declare const __VLS_component: import('vue').DefineComponent<import('vue').Extra
|
|
|
646
646
|
maxWidth: string;
|
|
647
647
|
sortConfig: SortConfig<DT>;
|
|
648
648
|
rowHeight: number;
|
|
649
|
-
headerRowHeight: number | null;
|
|
650
649
|
headless: boolean;
|
|
651
650
|
autoRowHeight: boolean | AutoRowHeightConfig<DT>;
|
|
652
651
|
stripe: boolean;
|
|
653
652
|
optimizeVue2Scroll: boolean;
|
|
654
653
|
rowKey: UniqKeyProp;
|
|
654
|
+
headerRowHeight: number | null;
|
|
655
655
|
colKey: UniqKeyProp;
|
|
656
656
|
fixedMode: boolean;
|
|
657
657
|
theme: "light" | "dark";
|
|
@@ -211,7 +211,7 @@ export type HeaderDragConfig<DT extends Record<string, any> = any> = boolean | {
|
|
|
211
211
|
};
|
|
212
212
|
export type AutoRowHeightConfig<DT> = {
|
|
213
213
|
/** Estimated row height */
|
|
214
|
-
expectedHeight?: number | ((row: DT
|
|
214
|
+
expectedHeight?: number | ((row: DT) => number);
|
|
215
215
|
};
|
|
216
216
|
export type ColResizableConfig<DT extends Record<string, any>> = {
|
|
217
217
|
disabled: (col: StkTableColumn<DT>) => boolean;
|
package/lib/stk-table-vue.js
CHANGED
|
@@ -1061,7 +1061,7 @@ function useVirtualScroll({
|
|
|
1061
1061
|
const virtualScroll = ref({
|
|
1062
1062
|
containerHeight: 0,
|
|
1063
1063
|
rowHeight: props.rowHeight,
|
|
1064
|
-
pageSize:
|
|
1064
|
+
pageSize: 0,
|
|
1065
1065
|
startIndex: 0,
|
|
1066
1066
|
endIndex: 0,
|
|
1067
1067
|
offsetTop: 0,
|
|
@@ -1080,7 +1080,7 @@ function useVirtualScroll({
|
|
|
1080
1080
|
return tableHeaderLast.value.some((col) => col.type === "expand");
|
|
1081
1081
|
});
|
|
1082
1082
|
const virtual_on = computed(() => {
|
|
1083
|
-
return props.virtual && dataSourceCopy.value.length > virtualScroll.value.pageSize
|
|
1083
|
+
return props.virtual && dataSourceCopy.value.length > virtualScroll.value.pageSize;
|
|
1084
1084
|
});
|
|
1085
1085
|
const virtual_dataSourcePart = computed(() => {
|
|
1086
1086
|
if (!virtual_on.value) return dataSourceCopy.value;
|
|
@@ -1089,7 +1089,8 @@ function useVirtualScroll({
|
|
|
1089
1089
|
});
|
|
1090
1090
|
const virtual_offsetBottom = computed(() => {
|
|
1091
1091
|
if (!virtual_on.value) return 0;
|
|
1092
|
-
const { startIndex
|
|
1092
|
+
const { startIndex } = virtualScroll.value;
|
|
1093
|
+
const rowHeight = getRowHeightFn.value();
|
|
1093
1094
|
return (dataSourceCopy.value.length - startIndex - virtual_dataSourcePart.value.length) * rowHeight;
|
|
1094
1095
|
});
|
|
1095
1096
|
const virtualX_on = computed(() => {
|
|
@@ -1126,9 +1127,22 @@ function useVirtualScroll({
|
|
|
1126
1127
|
}
|
|
1127
1128
|
return width;
|
|
1128
1129
|
});
|
|
1130
|
+
const getRowHeightFn = computed(() => {
|
|
1131
|
+
var _a;
|
|
1132
|
+
let rowHeightFn = () => props.rowHeight || DEFAULT_ROW_HEIGHT;
|
|
1133
|
+
if (props.autoRowHeight) {
|
|
1134
|
+
const tempRowHeightFn = rowHeightFn;
|
|
1135
|
+
rowHeightFn = (row) => getAutoRowHeight(row) || tempRowHeightFn(row);
|
|
1136
|
+
}
|
|
1137
|
+
if (hasExpandCol.value) {
|
|
1138
|
+
const expandedRowHeight = (_a = props.expandConfig) == null ? void 0 : _a.height;
|
|
1139
|
+
const tempRowHeightFn = rowHeightFn;
|
|
1140
|
+
rowHeightFn = (row) => row && row.__EXPANDED_ROW__ && expandedRowHeight || tempRowHeightFn(row);
|
|
1141
|
+
}
|
|
1142
|
+
return rowHeightFn;
|
|
1143
|
+
});
|
|
1129
1144
|
function getTableHeaderHeight() {
|
|
1130
|
-
|
|
1131
|
-
return headerRowHeight * tableHeaders.value.length;
|
|
1145
|
+
return props.headerRowHeight * tableHeaders.value.length;
|
|
1132
1146
|
}
|
|
1133
1147
|
function initVirtualScroll(height) {
|
|
1134
1148
|
initVirtualScrollY(height);
|
|
@@ -1140,10 +1154,9 @@ function useVirtualScroll({
|
|
|
1140
1154
|
console.warn("initVirtualScrollY: height must be a number");
|
|
1141
1155
|
height = 0;
|
|
1142
1156
|
}
|
|
1143
|
-
if (!virtual_on.value) return;
|
|
1144
1157
|
const { offsetHeight, scrollHeight } = tableContainerRef.value || {};
|
|
1145
1158
|
let scrollTop = ((_a = tableContainerRef.value) == null ? void 0 : _a.scrollTop) || 0;
|
|
1146
|
-
const
|
|
1159
|
+
const rowHeight = getRowHeightFn.value(props.dataSource[0]);
|
|
1147
1160
|
const containerHeight = height || offsetHeight || DEFAULT_TABLE_HEIGHT;
|
|
1148
1161
|
const { headless } = props;
|
|
1149
1162
|
let pageSize = Math.ceil(containerHeight / rowHeight);
|
|
@@ -1180,7 +1193,8 @@ function useVirtualScroll({
|
|
|
1180
1193
|
}
|
|
1181
1194
|
function getAutoRowHeight(row) {
|
|
1182
1195
|
var _a;
|
|
1183
|
-
|
|
1196
|
+
if (!row) return;
|
|
1197
|
+
const rowKey = rowKeyGen(row);
|
|
1184
1198
|
const storedHeight = autoRowHeightMap.get(rowKey);
|
|
1185
1199
|
if (storedHeight) {
|
|
1186
1200
|
return storedHeight;
|
|
@@ -1193,32 +1207,19 @@ function useVirtualScroll({
|
|
|
1193
1207
|
return expectedHeight;
|
|
1194
1208
|
}
|
|
1195
1209
|
}
|
|
1196
|
-
return props.rowHeight || DEFAULT_ROW_HEIGHT;
|
|
1197
|
-
}
|
|
1198
|
-
function createGetRowHeightFn() {
|
|
1199
|
-
var _a;
|
|
1200
|
-
if (props.autoRowHeight) {
|
|
1201
|
-
return (row) => getAutoRowHeight(row);
|
|
1202
|
-
}
|
|
1203
|
-
if (hasExpandCol.value) {
|
|
1204
|
-
const { rowHeight } = virtualScroll.value;
|
|
1205
|
-
const expandedRowHeight = ((_a = props.expandConfig) == null ? void 0 : _a.height) || rowHeight;
|
|
1206
|
-
return (row) => row.__EXPANDED_ROW__ ? expandedRowHeight : rowHeight;
|
|
1207
|
-
}
|
|
1208
|
-
return () => props.rowHeight || DEFAULT_ROW_HEIGHT;
|
|
1209
1210
|
}
|
|
1210
1211
|
function updateVirtualScrollY(sTop = 0) {
|
|
1211
1212
|
var _a;
|
|
1212
|
-
const {
|
|
1213
|
+
const { pageSize, scrollTop, startIndex: oldStartIndex, endIndex: oldEndIndex } = virtualScroll.value;
|
|
1213
1214
|
virtualScroll.value.scrollTop = sTop;
|
|
1214
1215
|
if (!virtual_on.value) {
|
|
1215
1216
|
return;
|
|
1216
1217
|
}
|
|
1217
1218
|
const dataSourceCopyTemp = dataSourceCopy.value;
|
|
1219
|
+
const rowHeight = getRowHeightFn.value(dataSourceCopyTemp[0]);
|
|
1218
1220
|
const { autoRowHeight, stripe, optimizeVue2Scroll } = props;
|
|
1219
1221
|
let startIndex = 0;
|
|
1220
1222
|
let autoRowHeightTop = 0;
|
|
1221
|
-
let getRowHeight = null;
|
|
1222
1223
|
const dataLength = dataSourceCopyTemp.length;
|
|
1223
1224
|
if (autoRowHeight || hasExpandCol.value) {
|
|
1224
1225
|
if (autoRowHeight) {
|
|
@@ -1228,9 +1229,8 @@ function useVirtualScroll({
|
|
|
1228
1229
|
autoRowHeightMap.set(rowKey, tr.offsetHeight);
|
|
1229
1230
|
});
|
|
1230
1231
|
}
|
|
1231
|
-
getRowHeight = createGetRowHeightFn();
|
|
1232
1232
|
for (let i = 0; i < dataLength; i++) {
|
|
1233
|
-
const height =
|
|
1233
|
+
const height = getRowHeightFn.value(dataSourceCopyTemp[i]);
|
|
1234
1234
|
autoRowHeightTop += height;
|
|
1235
1235
|
if (autoRowHeightTop >= sTop) {
|
|
1236
1236
|
startIndex = i;
|
|
@@ -1245,7 +1245,7 @@ function useVirtualScroll({
|
|
|
1245
1245
|
if (stripe && startIndex > 0 && startIndex % 2) {
|
|
1246
1246
|
startIndex -= 1;
|
|
1247
1247
|
if (autoRowHeight || hasExpandCol.value) {
|
|
1248
|
-
const height =
|
|
1248
|
+
const height = getRowHeightFn.value(dataSourceCopyTemp[startIndex]);
|
|
1249
1249
|
autoRowHeightTop -= height;
|
|
1250
1250
|
}
|
|
1251
1251
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "stk-table-vue",
|
|
3
|
-
"version": "0.6.
|
|
3
|
+
"version": "0.6.14",
|
|
4
4
|
"description": "Simple realtime virtual table for vue3 and vue2.7",
|
|
5
5
|
"main": "./lib/stk-table-vue.js",
|
|
6
6
|
"types": "./lib/src/StkTable/index.d.ts",
|
|
@@ -65,6 +65,7 @@
|
|
|
65
65
|
"vite-plugin-dts": "3.9.1",
|
|
66
66
|
"vitepress": "^1.5.0",
|
|
67
67
|
"vitepress-demo-plugin": "^1.3.1",
|
|
68
|
+
"vitepress-plugin-llms": "^1.1.3",
|
|
68
69
|
"vitest": "^2.1.3",
|
|
69
70
|
"vue": "^3.5.12",
|
|
70
71
|
"vue-eslint-parser": "^9.4.2"
|
|
@@ -231,7 +231,7 @@ export type HeaderDragConfig<DT extends Record<string, any> = any> =
|
|
|
231
231
|
|
|
232
232
|
export type AutoRowHeightConfig<DT> = {
|
|
233
233
|
/** Estimated row height */
|
|
234
|
-
expectedHeight?: number | ((row: DT
|
|
234
|
+
expectedHeight?: number | ((row: DT) => number);
|
|
235
235
|
};
|
|
236
236
|
|
|
237
237
|
export type ColResizableConfig<DT extends Record<string, any>> = {
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { Ref, ShallowRef, computed, ref } from 'vue';
|
|
2
2
|
import { DEFAULT_ROW_HEIGHT, DEFAULT_TABLE_HEIGHT, DEFAULT_TABLE_WIDTH } from './const';
|
|
3
|
-
import { StkTableColumn, UniqKey } from './types';
|
|
3
|
+
import { AutoRowHeightConfig, StkTableColumn, UniqKey } from './types';
|
|
4
4
|
import { getCalculatedColWidth } from './utils/constRefUtils';
|
|
5
5
|
|
|
6
6
|
type Option<DT extends Record<string, any>> = {
|
|
@@ -71,7 +71,7 @@ export function useVirtualScroll<DT extends Record<string, any>>({
|
|
|
71
71
|
const virtualScroll = ref<VirtualScrollStore>({
|
|
72
72
|
containerHeight: 0,
|
|
73
73
|
rowHeight: props.rowHeight,
|
|
74
|
-
pageSize:
|
|
74
|
+
pageSize: 0,
|
|
75
75
|
startIndex: 0,
|
|
76
76
|
endIndex: 0,
|
|
77
77
|
offsetTop: 0,
|
|
@@ -96,7 +96,7 @@ export function useVirtualScroll<DT extends Record<string, any>>({
|
|
|
96
96
|
|
|
97
97
|
/** 是否虚拟滚动标志 */
|
|
98
98
|
const virtual_on = computed(() => {
|
|
99
|
-
return props.virtual && dataSourceCopy.value.length > virtualScroll.value.pageSize
|
|
99
|
+
return props.virtual && dataSourceCopy.value.length > virtualScroll.value.pageSize;
|
|
100
100
|
});
|
|
101
101
|
|
|
102
102
|
const virtual_dataSourcePart = computed(() => {
|
|
@@ -107,7 +107,8 @@ export function useVirtualScroll<DT extends Record<string, any>>({
|
|
|
107
107
|
|
|
108
108
|
const virtual_offsetBottom = computed(() => {
|
|
109
109
|
if (!virtual_on.value) return 0;
|
|
110
|
-
const { startIndex
|
|
110
|
+
const { startIndex } = virtualScroll.value;
|
|
111
|
+
const rowHeight = getRowHeightFn.value();
|
|
111
112
|
return (dataSourceCopy.value.length - startIndex - virtual_dataSourcePart.value.length) * rowHeight;
|
|
112
113
|
});
|
|
113
114
|
|
|
@@ -162,10 +163,22 @@ export function useVirtualScroll<DT extends Record<string, any>>({
|
|
|
162
163
|
return width;
|
|
163
164
|
});
|
|
164
165
|
|
|
165
|
-
|
|
166
|
+
const getRowHeightFn = computed(() => {
|
|
167
|
+
let rowHeightFn: (row?: DT) => number = () => props.rowHeight || DEFAULT_ROW_HEIGHT;
|
|
168
|
+
if (props.autoRowHeight) {
|
|
169
|
+
const tempRowHeightFn = rowHeightFn;
|
|
170
|
+
rowHeightFn = (row?: DT) => getAutoRowHeight(row) || tempRowHeightFn(row);
|
|
171
|
+
}
|
|
172
|
+
if (hasExpandCol.value) {
|
|
173
|
+
const expandedRowHeight = props.expandConfig?.height;
|
|
174
|
+
const tempRowHeightFn = rowHeightFn;
|
|
175
|
+
rowHeightFn = (row?: DT) => (row && row.__EXPANDED_ROW__ && expandedRowHeight) || tempRowHeightFn(row);
|
|
176
|
+
}
|
|
177
|
+
return rowHeightFn;
|
|
178
|
+
});
|
|
179
|
+
|
|
166
180
|
function getTableHeaderHeight() {
|
|
167
|
-
|
|
168
|
-
return headerRowHeight * tableHeaders.value.length;
|
|
181
|
+
return props.headerRowHeight * tableHeaders.value.length;
|
|
169
182
|
}
|
|
170
183
|
|
|
171
184
|
/**
|
|
@@ -186,11 +199,10 @@ export function useVirtualScroll<DT extends Record<string, any>>({
|
|
|
186
199
|
console.warn('initVirtualScrollY: height must be a number');
|
|
187
200
|
height = 0;
|
|
188
201
|
}
|
|
189
|
-
if (!virtual_on.value) return;
|
|
190
202
|
const { offsetHeight, scrollHeight } = tableContainerRef.value || {};
|
|
191
203
|
let scrollTop = tableContainerRef.value?.scrollTop || 0;
|
|
192
204
|
|
|
193
|
-
const
|
|
205
|
+
const rowHeight = getRowHeightFn.value(props.dataSource[0]);
|
|
194
206
|
const containerHeight = height || offsetHeight || DEFAULT_TABLE_HEIGHT;
|
|
195
207
|
const { headless } = props;
|
|
196
208
|
let pageSize = Math.ceil(containerHeight / rowHeight);
|
|
@@ -234,13 +246,14 @@ export function useVirtualScroll<DT extends Record<string, any>>({
|
|
|
234
246
|
autoRowHeightMap.clear();
|
|
235
247
|
}
|
|
236
248
|
|
|
237
|
-
function getAutoRowHeight(row
|
|
238
|
-
|
|
249
|
+
function getAutoRowHeight(row?: DT) {
|
|
250
|
+
if (!row) return;
|
|
251
|
+
const rowKey = rowKeyGen(row);
|
|
239
252
|
const storedHeight = autoRowHeightMap.get(rowKey);
|
|
240
253
|
if (storedHeight) {
|
|
241
254
|
return storedHeight;
|
|
242
255
|
}
|
|
243
|
-
const expectedHeight = props.autoRowHeight?.expectedHeight;
|
|
256
|
+
const expectedHeight: AutoRowHeightConfig<DT>['expectedHeight'] = props.autoRowHeight?.expectedHeight;
|
|
244
257
|
if (expectedHeight) {
|
|
245
258
|
if (typeof expectedHeight === 'function') {
|
|
246
259
|
return expectedHeight(row);
|
|
@@ -248,24 +261,11 @@ export function useVirtualScroll<DT extends Record<string, any>>({
|
|
|
248
261
|
return expectedHeight;
|
|
249
262
|
}
|
|
250
263
|
}
|
|
251
|
-
return props.rowHeight || DEFAULT_ROW_HEIGHT;
|
|
252
|
-
}
|
|
253
|
-
|
|
254
|
-
function createGetRowHeightFn(): (row: DT) => number {
|
|
255
|
-
if (props.autoRowHeight) {
|
|
256
|
-
return (row: DT) => getAutoRowHeight(row);
|
|
257
|
-
}
|
|
258
|
-
if (hasExpandCol.value) {
|
|
259
|
-
const { rowHeight } = virtualScroll.value;
|
|
260
|
-
const expandedRowHeight: number = props.expandConfig?.height || rowHeight;
|
|
261
|
-
return (row: DT) => (row.__EXPANDED_ROW__ ? expandedRowHeight : rowHeight);
|
|
262
|
-
}
|
|
263
|
-
return () => props.rowHeight || (DEFAULT_ROW_HEIGHT as number);
|
|
264
264
|
}
|
|
265
265
|
|
|
266
266
|
/** 通过滚动条位置,计算虚拟滚动的参数 */
|
|
267
267
|
function updateVirtualScrollY(sTop = 0) {
|
|
268
|
-
const {
|
|
268
|
+
const { pageSize, scrollTop, startIndex: oldStartIndex, endIndex: oldEndIndex } = virtualScroll.value;
|
|
269
269
|
// 先更新滚动条位置记录,其他地方有依赖。(stripe 时ArrowUp/Down滚动依赖)
|
|
270
270
|
virtualScroll.value.scrollTop = sTop;
|
|
271
271
|
|
|
@@ -275,11 +275,11 @@ export function useVirtualScroll<DT extends Record<string, any>>({
|
|
|
275
275
|
}
|
|
276
276
|
|
|
277
277
|
const dataSourceCopyTemp = dataSourceCopy.value;
|
|
278
|
+
const rowHeight = getRowHeightFn.value(dataSourceCopyTemp[0]);
|
|
278
279
|
const { autoRowHeight, stripe, optimizeVue2Scroll } = props;
|
|
279
280
|
|
|
280
281
|
let startIndex = 0;
|
|
281
282
|
let autoRowHeightTop = 0;
|
|
282
|
-
let getRowHeight: ReturnType<typeof createGetRowHeightFn> | null = null;
|
|
283
283
|
const dataLength = dataSourceCopyTemp.length;
|
|
284
284
|
|
|
285
285
|
if (autoRowHeight || hasExpandCol.value) {
|
|
@@ -291,10 +291,8 @@ export function useVirtualScroll<DT extends Record<string, any>>({
|
|
|
291
291
|
});
|
|
292
292
|
}
|
|
293
293
|
|
|
294
|
-
getRowHeight = createGetRowHeightFn();
|
|
295
|
-
|
|
296
294
|
for (let i = 0; i < dataLength; i++) {
|
|
297
|
-
const height =
|
|
295
|
+
const height = getRowHeightFn.value(dataSourceCopyTemp[i]);
|
|
298
296
|
autoRowHeightTop += height;
|
|
299
297
|
if (autoRowHeightTop >= sTop) {
|
|
300
298
|
startIndex = i;
|
|
@@ -312,7 +310,7 @@ export function useVirtualScroll<DT extends Record<string, any>>({
|
|
|
312
310
|
// 斑马纹情况下,每滚动偶数行才加载。防止斑马纹错位。
|
|
313
311
|
startIndex -= 1; // 奇数-1变成偶数
|
|
314
312
|
if (autoRowHeight || hasExpandCol.value) {
|
|
315
|
-
const height =
|
|
313
|
+
const height = getRowHeightFn.value(dataSourceCopyTemp[startIndex]);
|
|
316
314
|
autoRowHeightTop -= height;
|
|
317
315
|
}
|
|
318
316
|
}
|