stk-table-vue 0.8.13 → 0.8.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.
- package/README.md +9 -17
- package/lib/src/StkTable/StkTable.vue.d.ts +3 -1
- package/lib/src/StkTable/utils/index.d.ts +3 -0
- package/lib/stk-table-vue.js +217 -139
- package/lib/style.css +8 -2
- package/package.json +3 -1
- package/src/StkTable/StkTable.vue +133 -121
- package/src/StkTable/style.less +0 -2
- package/src/StkTable/useFixedCol.ts +10 -8
- package/src/StkTable/useHighlight.ts +1 -1
- package/src/StkTable/useMergeCells.ts +4 -7
- package/src/StkTable/useScrollRowByRow.ts +53 -18
- package/src/StkTable/useTrDrag.ts +1 -6
- package/src/StkTable/utils/index.ts +16 -0
package/lib/stk-table-vue.js
CHANGED
|
@@ -1,4 +1,12 @@
|
|
|
1
|
-
|
|
1
|
+
/**
|
|
2
|
+
* name: stk-table-vue
|
|
3
|
+
* version: v0.8.13
|
|
4
|
+
* description: High performance realtime virtual table for vue3 and vue2.7
|
|
5
|
+
* author: japlus
|
|
6
|
+
* homepage: https://ja-plus.github.io/stk-table-vue/
|
|
7
|
+
* license: MIT
|
|
8
|
+
*/
|
|
9
|
+
import { createElementBlock, openBlock, createElementVNode, watch, onMounted, onBeforeUnmount, ref, computed, shallowRef, customRef, onUnmounted, defineComponent, nextTick, toRaw, normalizeStyle, normalizeClass, unref, createCommentVNode, renderSlot, Fragment, renderList, mergeProps, createBlock, resolveDynamicComponent, toDisplayString, createTextVNode, withCtx, createVNode } from "vue";
|
|
2
10
|
const _export_sfc = (sfc, props) => {
|
|
3
11
|
const target = sfc.__vccOpts || sfc;
|
|
4
12
|
for (const [key, val] of props) {
|
|
@@ -203,6 +211,20 @@ function getBrowsersVersion(browserName) {
|
|
|
203
211
|
function pureCellKeyGen(rowKey, colKey) {
|
|
204
212
|
return rowKey + CELL_KEY_SEPARATE + colKey;
|
|
205
213
|
}
|
|
214
|
+
function getClosestTr(e) {
|
|
215
|
+
const target = e.target;
|
|
216
|
+
const tr = target == null ? void 0 : target.closest("tr");
|
|
217
|
+
return tr;
|
|
218
|
+
}
|
|
219
|
+
function getClosestTrIndex(e) {
|
|
220
|
+
const tr = getClosestTr(e);
|
|
221
|
+
if (!tr) return -1;
|
|
222
|
+
return Number(tr.dataset.rowI);
|
|
223
|
+
}
|
|
224
|
+
function getClosestColKey(e) {
|
|
225
|
+
var _a, _b;
|
|
226
|
+
return (_b = (_a = e.target) == null ? void 0 : _a.closest("td")) == null ? void 0 : _b.dataset.colKey;
|
|
227
|
+
}
|
|
206
228
|
const DEFAULT_COL_WIDTH = "100";
|
|
207
229
|
const DEFAULT_TABLE_HEIGHT = 100;
|
|
208
230
|
const DEFAULT_TABLE_WIDTH = 200;
|
|
@@ -483,19 +505,19 @@ function useFixedCol({
|
|
|
483
505
|
tableHeaders.value.forEach((cols) => {
|
|
484
506
|
cols.forEach((col) => {
|
|
485
507
|
const fixed = col.fixed;
|
|
486
|
-
const showShadow =
|
|
487
|
-
const
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
}
|
|
508
|
+
const showShadow = fixed && fixedColShadow && fixedShadowColsValue.includes(col);
|
|
509
|
+
const classList = [];
|
|
510
|
+
if (fixedColsValue.includes(col)) {
|
|
511
|
+
classList.push("fixed-cell--active");
|
|
512
|
+
}
|
|
491
513
|
if (fixed) {
|
|
492
|
-
|
|
493
|
-
|
|
514
|
+
classList.push("fixed-cell");
|
|
515
|
+
classList.push("fixed-cell--" + fixed);
|
|
494
516
|
}
|
|
495
517
|
if (showShadow) {
|
|
496
|
-
|
|
518
|
+
classList.push("fixed-cell--shadow");
|
|
497
519
|
}
|
|
498
|
-
colMap.set(colKey(col),
|
|
520
|
+
colMap.set(colKey(col), classList);
|
|
499
521
|
});
|
|
500
522
|
});
|
|
501
523
|
return colMap;
|
|
@@ -686,7 +708,7 @@ function useHighlight({ props, stkTableId, tableContainerRef }) {
|
|
|
686
708
|
}
|
|
687
709
|
function setHighlightDimCell(rowKeyValue, colKeyValue, option = {}) {
|
|
688
710
|
var _a;
|
|
689
|
-
const cellEl = (_a = tableContainerRef.value) == null ? void 0 : _a.querySelector(`[data-
|
|
711
|
+
const cellEl = (_a = tableContainerRef.value) == null ? void 0 : _a.querySelector(`[data-row-key="${rowKeyValue}"] [data-col-key="${colKeyValue}"]`);
|
|
690
712
|
if (!cellEl) return;
|
|
691
713
|
const { className, method, duration, keyframe } = {
|
|
692
714
|
className: HIGHLIGHT_CELL_CLASS,
|
|
@@ -920,10 +942,8 @@ function useMergeCells({ rowActiveProp, tableHeaderLast, rowKeyGen, colKeyGen, v
|
|
|
920
942
|
function hideCells(rowKey, colKey, colspan, isSelfRow = false, mergeCellKey) {
|
|
921
943
|
const startIndex = tableHeaderLast.value.findIndex((item) => colKeyGen.value(item) === colKey);
|
|
922
944
|
for (let i = startIndex; i < startIndex + colspan; i++) {
|
|
923
|
-
if (!
|
|
924
|
-
|
|
925
|
-
hoverRowMap.value[rowKey].add(mergeCellKey);
|
|
926
|
-
}
|
|
945
|
+
if (!hoverRowMap.value[rowKey]) hoverRowMap.value[rowKey] = /* @__PURE__ */ new Set();
|
|
946
|
+
hoverRowMap.value[rowKey].add(mergeCellKey);
|
|
927
947
|
if (isSelfRow && i === startIndex) {
|
|
928
948
|
continue;
|
|
929
949
|
}
|
|
@@ -959,7 +979,7 @@ function useMergeCells({ rowActiveProp, tableHeaderLast, rowKeyGen, colKeyGen, v
|
|
|
959
979
|
function updateActiveMergedCells(clear, rowKey) {
|
|
960
980
|
if (!rowActiveProp.value.enabled) return;
|
|
961
981
|
if (clear) {
|
|
962
|
-
activeMergedCells.value
|
|
982
|
+
activeMergedCells.value = /* @__PURE__ */ new Set();
|
|
963
983
|
return;
|
|
964
984
|
}
|
|
965
985
|
activeMergedCells.value = rowKey !== void 0 && hoverRowMap.value[rowKey] || new Set(hoverMergedCells.value);
|
|
@@ -1032,10 +1052,36 @@ function useRowExpand({ dataSourceCopy, rowKeyGen, emits }) {
|
|
|
1032
1052
|
};
|
|
1033
1053
|
}
|
|
1034
1054
|
function useScrollRowByRow({ props, tableContainerRef }) {
|
|
1035
|
-
let isMouseDown = false;
|
|
1036
1055
|
let isAddListeners = false;
|
|
1037
|
-
|
|
1038
|
-
|
|
1056
|
+
const isDragScroll = customRef((track, trigger) => {
|
|
1057
|
+
let value = false;
|
|
1058
|
+
let debounceTimer = 0;
|
|
1059
|
+
return {
|
|
1060
|
+
get() {
|
|
1061
|
+
track();
|
|
1062
|
+
return value;
|
|
1063
|
+
},
|
|
1064
|
+
set(newValue) {
|
|
1065
|
+
if (value && !newValue) {
|
|
1066
|
+
if (debounceTimer) {
|
|
1067
|
+
window.clearTimeout(debounceTimer);
|
|
1068
|
+
}
|
|
1069
|
+
debounceTimer = window.setTimeout(() => {
|
|
1070
|
+
value = newValue;
|
|
1071
|
+
trigger();
|
|
1072
|
+
debounceTimer = 0;
|
|
1073
|
+
}, 300);
|
|
1074
|
+
} else {
|
|
1075
|
+
if (debounceTimer) {
|
|
1076
|
+
window.clearTimeout(debounceTimer);
|
|
1077
|
+
debounceTimer = 0;
|
|
1078
|
+
}
|
|
1079
|
+
value = newValue;
|
|
1080
|
+
trigger();
|
|
1081
|
+
}
|
|
1082
|
+
}
|
|
1083
|
+
};
|
|
1084
|
+
});
|
|
1039
1085
|
const onlyDragScroll = computed(() => props.scrollRowByRow === "scrollbar");
|
|
1040
1086
|
const isSRBRActive = computed(() => {
|
|
1041
1087
|
if (onlyDragScroll.value) {
|
|
@@ -1062,7 +1108,6 @@ function useScrollRowByRow({ props, tableContainerRef }) {
|
|
|
1062
1108
|
if (!container) return;
|
|
1063
1109
|
container.addEventListener("mousedown", handleMouseDown);
|
|
1064
1110
|
container.addEventListener("mouseup", handleMouseUp);
|
|
1065
|
-
container.addEventListener("scroll", handleScroll);
|
|
1066
1111
|
isAddListeners = true;
|
|
1067
1112
|
}
|
|
1068
1113
|
function removeEventListener() {
|
|
@@ -1070,22 +1115,16 @@ function useScrollRowByRow({ props, tableContainerRef }) {
|
|
|
1070
1115
|
if (!container) return;
|
|
1071
1116
|
container.removeEventListener("mousedown", handleMouseDown);
|
|
1072
1117
|
container.removeEventListener("mouseup", handleMouseUp);
|
|
1073
|
-
container.removeEventListener("scroll", handleScroll);
|
|
1074
1118
|
isAddListeners = false;
|
|
1075
1119
|
}
|
|
1076
1120
|
function handleMouseDown(e) {
|
|
1077
|
-
|
|
1078
|
-
|
|
1121
|
+
const el = e.target;
|
|
1122
|
+
if (el.classList.contains("stk-table")) {
|
|
1123
|
+
isDragScroll.value = true;
|
|
1124
|
+
}
|
|
1079
1125
|
}
|
|
1080
1126
|
function handleMouseUp() {
|
|
1081
|
-
isMouseDown = false;
|
|
1082
1127
|
isDragScroll.value = false;
|
|
1083
|
-
lastScrollTop = 0;
|
|
1084
|
-
}
|
|
1085
|
-
function handleScroll(e) {
|
|
1086
|
-
const scrollTop = e.target.scrollTop;
|
|
1087
|
-
if (!isMouseDown || scrollTop === lastScrollTop) return;
|
|
1088
|
-
isDragScroll.value = true;
|
|
1089
1128
|
}
|
|
1090
1129
|
return { isSRBRActive, isDragScroll };
|
|
1091
1130
|
}
|
|
@@ -1168,11 +1207,6 @@ function useTrDrag({ props, emits, dataSourceCopy }) {
|
|
|
1168
1207
|
const dragRowConfig = computed(() => {
|
|
1169
1208
|
return { mode: "insert", ...props.dragRowConfig };
|
|
1170
1209
|
});
|
|
1171
|
-
function getClosestTr(e) {
|
|
1172
|
-
const target = e.target;
|
|
1173
|
-
const tr = target == null ? void 0 : target.closest("tr");
|
|
1174
|
-
return tr;
|
|
1175
|
-
}
|
|
1176
1210
|
function onTrDragStart(e, rowIndex) {
|
|
1177
1211
|
var _a;
|
|
1178
1212
|
const tr = getClosestTr(e);
|
|
@@ -1709,7 +1743,7 @@ function useVirtualScroll({
|
|
|
1709
1743
|
};
|
|
1710
1744
|
}
|
|
1711
1745
|
const _hoisted_1 = { key: 0 };
|
|
1712
|
-
const _hoisted_2 = ["
|
|
1746
|
+
const _hoisted_2 = ["onClick"];
|
|
1713
1747
|
const _hoisted_3 = ["onMousedown"];
|
|
1714
1748
|
const _hoisted_4 = { class: "table-header-title" };
|
|
1715
1749
|
const _hoisted_5 = ["onMousedown"];
|
|
@@ -1717,15 +1751,18 @@ const _hoisted_6 = {
|
|
|
1717
1751
|
key: 0,
|
|
1718
1752
|
class: "vt-x-left"
|
|
1719
1753
|
};
|
|
1720
|
-
const _hoisted_7 = ["
|
|
1754
|
+
const _hoisted_7 = ["onDrop"];
|
|
1721
1755
|
const _hoisted_8 = {
|
|
1722
1756
|
key: 0,
|
|
1723
1757
|
class: "vt-x-left"
|
|
1724
1758
|
};
|
|
1725
1759
|
const _hoisted_9 = ["colspan"];
|
|
1726
1760
|
const _hoisted_10 = { class: "table-cell-wrapper" };
|
|
1727
|
-
const _hoisted_11 = ["
|
|
1728
|
-
const _hoisted_12 =
|
|
1761
|
+
const _hoisted_11 = ["title"];
|
|
1762
|
+
const _hoisted_12 = {
|
|
1763
|
+
key: 3,
|
|
1764
|
+
class: "vt-x-right"
|
|
1765
|
+
};
|
|
1729
1766
|
const _sfc_main = /* @__PURE__ */ defineComponent({
|
|
1730
1767
|
__name: "StkTable",
|
|
1731
1768
|
props: {
|
|
@@ -2117,7 +2154,7 @@ const _sfc_main = /* @__PURE__ */ defineComponent({
|
|
|
2117
2154
|
};
|
|
2118
2155
|
});
|
|
2119
2156
|
function getRowIndex(rowIndex) {
|
|
2120
|
-
return rowIndex +
|
|
2157
|
+
return rowIndex + virtualScroll.value.startIndex;
|
|
2121
2158
|
}
|
|
2122
2159
|
function getHeaderTitle(col) {
|
|
2123
2160
|
const colKey = colKeyGen.value(col);
|
|
@@ -2126,7 +2163,48 @@ const _sfc_main = /* @__PURE__ */ defineComponent({
|
|
|
2126
2163
|
}
|
|
2127
2164
|
return col.title || "";
|
|
2128
2165
|
}
|
|
2129
|
-
function
|
|
2166
|
+
function getTRProps(row, index) {
|
|
2167
|
+
var _a, _b;
|
|
2168
|
+
const rowIndex = getRowIndex(index);
|
|
2169
|
+
const rowKey = rowKeyGen(row);
|
|
2170
|
+
let classStr = props.rowClassName(row, rowIndex) || " " + ((row == null ? void 0 : row.__EXP__) ? "expanded" : "") + " " + ((row == null ? void 0 : row.__EXP_R__) ? "expanded-row" : "");
|
|
2171
|
+
if (currentRowKey.value === rowKey || row === currentRow.value) {
|
|
2172
|
+
classStr += " active";
|
|
2173
|
+
}
|
|
2174
|
+
if (props.showTrHoverClass && (rowKey === currentHoverRowKey.value || row === currentHoverRow)) {
|
|
2175
|
+
classStr += " hover";
|
|
2176
|
+
}
|
|
2177
|
+
const result = {
|
|
2178
|
+
id: stkTableId + "-" + rowKey,
|
|
2179
|
+
"data-row-key": rowKey,
|
|
2180
|
+
"data-row-i": rowIndex,
|
|
2181
|
+
class: classStr,
|
|
2182
|
+
style: ""
|
|
2183
|
+
};
|
|
2184
|
+
const needRowHeight = (row == null ? void 0 : row.__EXP_R__) && props.virtual && ((_a = props.expandConfig) == null ? void 0 : _a.height);
|
|
2185
|
+
if (needRowHeight) {
|
|
2186
|
+
result.style = `--row-height: ${(_b = props.expandConfig) == null ? void 0 : _b.height}px`;
|
|
2187
|
+
}
|
|
2188
|
+
return result;
|
|
2189
|
+
}
|
|
2190
|
+
function getTHProps(col) {
|
|
2191
|
+
const colKey = colKeyGen.value(col);
|
|
2192
|
+
return {
|
|
2193
|
+
"data-col-key": colKey,
|
|
2194
|
+
draggable: Boolean(isHeaderDraggable(col)),
|
|
2195
|
+
rowspan: virtualX_on.value ? 1 : col.__R_SP__,
|
|
2196
|
+
colspan: col.__C_SP__,
|
|
2197
|
+
style: cellStyleMap.value[TagType.TH].get(colKey),
|
|
2198
|
+
title: getHeaderTitle(col),
|
|
2199
|
+
class: [
|
|
2200
|
+
col.sorter ? "sortable" : "",
|
|
2201
|
+
colKey === sortCol.value && sortOrderIndex.value !== 0 && "sorter-" + sortSwitchOrder[sortOrderIndex.value],
|
|
2202
|
+
col.headerClassName,
|
|
2203
|
+
fixedColClassMap.value.get(colKey)
|
|
2204
|
+
]
|
|
2205
|
+
};
|
|
2206
|
+
}
|
|
2207
|
+
function getTDProps(row, col, rowIndex, colIndex) {
|
|
2130
2208
|
const colKey = colKeyGen.value(col);
|
|
2131
2209
|
if (!row) {
|
|
2132
2210
|
return {
|
|
@@ -2134,7 +2212,7 @@ const _sfc_main = /* @__PURE__ */ defineComponent({
|
|
|
2134
2212
|
};
|
|
2135
2213
|
}
|
|
2136
2214
|
const cellKey = cellKeyGen(row, col);
|
|
2137
|
-
const classList = [col.className, fixedColClassMap.value.get(
|
|
2215
|
+
const classList = [col.className, fixedColClassMap.value.get(colKey)];
|
|
2138
2216
|
if (col.mergeCells) {
|
|
2139
2217
|
if (hoverMergedCells.value.has(cellKey)) {
|
|
2140
2218
|
classList.push("cell-hover");
|
|
@@ -2148,17 +2226,18 @@ const _sfc_main = /* @__PURE__ */ defineComponent({
|
|
|
2148
2226
|
}
|
|
2149
2227
|
if (col.type === "seq") {
|
|
2150
2228
|
classList.push("seq-column");
|
|
2151
|
-
} else if (col.type === "expand" && (row.__EXP__ ? colKeyGen.value(row.__EXP__) ===
|
|
2229
|
+
} else if (col.type === "expand" && (row.__EXP__ ? colKeyGen.value(row.__EXP__) === colKey : false)) {
|
|
2152
2230
|
classList.push("expanded");
|
|
2153
|
-
} else if (col.type === "tree-node"
|
|
2231
|
+
} else if (row.__T_EXP__ && col.type === "tree-node") {
|
|
2154
2232
|
classList.push("tree-expanded");
|
|
2155
2233
|
} else if (col.type === "dragRow") {
|
|
2156
2234
|
classList.push("drag-row-cell");
|
|
2157
2235
|
}
|
|
2158
2236
|
return {
|
|
2159
|
-
"data-
|
|
2237
|
+
"data-col-key": colKey,
|
|
2160
2238
|
style: cellStyleMap.value[TagType.TD].get(colKey),
|
|
2161
|
-
class: classList
|
|
2239
|
+
class: classList,
|
|
2240
|
+
...mergeCellsWrapper(row, col, rowIndex, colIndex)
|
|
2162
2241
|
};
|
|
2163
2242
|
}
|
|
2164
2243
|
function onColumnSort(col, click = true, options = {}) {
|
|
@@ -2216,8 +2295,11 @@ const _sfc_main = /* @__PURE__ */ defineComponent({
|
|
|
2216
2295
|
emits("sort-change", col, order, toRaw(dataSourceTemp), sortConfig);
|
|
2217
2296
|
}
|
|
2218
2297
|
}
|
|
2219
|
-
function onRowClick(e
|
|
2298
|
+
function onRowClick(e) {
|
|
2220
2299
|
var _a, _b;
|
|
2300
|
+
const rowIndex = getClosestTrIndex(e);
|
|
2301
|
+
const row = dataSourceCopy.value[rowIndex];
|
|
2302
|
+
if (!row) return;
|
|
2221
2303
|
emits("row-click", e, row, { rowIndex });
|
|
2222
2304
|
if ((_b = (_a = rowActiveProp.value).disabled) == null ? void 0 : _b.call(_a, row)) return;
|
|
2223
2305
|
const isCurrentRow = props.rowKey ? currentRowKey.value === rowKeyGen(row) : currentRow.value === row;
|
|
@@ -2231,13 +2313,19 @@ const _sfc_main = /* @__PURE__ */ defineComponent({
|
|
|
2231
2313
|
}
|
|
2232
2314
|
emits("current-change", e, row, { select: !isCurrentRow });
|
|
2233
2315
|
}
|
|
2234
|
-
function onRowDblclick(e
|
|
2316
|
+
function onRowDblclick(e) {
|
|
2317
|
+
const rowIndex = getClosestTrIndex(e);
|
|
2318
|
+
const row = dataSourceCopy.value[rowIndex];
|
|
2319
|
+
if (!row) return;
|
|
2235
2320
|
emits("row-dblclick", e, row, { rowIndex });
|
|
2236
2321
|
}
|
|
2237
2322
|
function onHeaderMenu(e) {
|
|
2238
2323
|
emits("header-row-menu", e);
|
|
2239
2324
|
}
|
|
2240
|
-
function onRowMenu(e
|
|
2325
|
+
function onRowMenu(e) {
|
|
2326
|
+
const rowIndex = getClosestTrIndex(e);
|
|
2327
|
+
const row = dataSourceCopy.value[rowIndex];
|
|
2328
|
+
if (!row) return;
|
|
2241
2329
|
emits("row-menu", e, row, { rowIndex });
|
|
2242
2330
|
}
|
|
2243
2331
|
function triangleClick(e, row, col) {
|
|
@@ -2247,7 +2335,13 @@ const _sfc_main = /* @__PURE__ */ defineComponent({
|
|
|
2247
2335
|
toggleTreeNode(row, col);
|
|
2248
2336
|
}
|
|
2249
2337
|
}
|
|
2250
|
-
function onCellClick(e
|
|
2338
|
+
function onCellClick(e) {
|
|
2339
|
+
const rowIndex = getClosestTrIndex(e);
|
|
2340
|
+
const row = dataSourceCopy.value[rowIndex];
|
|
2341
|
+
if (!row) return;
|
|
2342
|
+
const colKey = getClosestColKey(e);
|
|
2343
|
+
const col = tableHeaderLast.value.find((item) => colKeyGen.value(item) === colKey);
|
|
2344
|
+
if (!col) return;
|
|
2251
2345
|
if (props.cellActive) {
|
|
2252
2346
|
const cellKey = cellKeyGen(row, col);
|
|
2253
2347
|
const result = { row, col, select: false, rowIndex };
|
|
@@ -2261,19 +2355,31 @@ const _sfc_main = /* @__PURE__ */ defineComponent({
|
|
|
2261
2355
|
}
|
|
2262
2356
|
emits("cell-click", e, row, col, { rowIndex });
|
|
2263
2357
|
}
|
|
2358
|
+
function getCellEventData(e) {
|
|
2359
|
+
const rowIndex = getClosestTrIndex(e) || 0;
|
|
2360
|
+
const row = dataSourceCopy.value[rowIndex];
|
|
2361
|
+
const colKey = getClosestColKey(e);
|
|
2362
|
+
const col = tableHeaderLast.value.find((item) => colKeyGen.value(item) === colKey);
|
|
2363
|
+
return { row, col, rowIndex };
|
|
2364
|
+
}
|
|
2264
2365
|
function onHeaderCellClick(e, col) {
|
|
2366
|
+
onColumnSort(col);
|
|
2265
2367
|
emits("header-cell-click", e, col);
|
|
2266
2368
|
}
|
|
2267
|
-
function onCellMouseEnter(e
|
|
2369
|
+
function onCellMouseEnter(e) {
|
|
2370
|
+
const { row, col } = getCellEventData(e);
|
|
2268
2371
|
emits("cell-mouseenter", e, row, col);
|
|
2269
2372
|
}
|
|
2270
|
-
function onCellMouseLeave(e
|
|
2373
|
+
function onCellMouseLeave(e) {
|
|
2374
|
+
const { row, col } = getCellEventData(e);
|
|
2271
2375
|
emits("cell-mouseleave", e, row, col);
|
|
2272
2376
|
}
|
|
2273
|
-
function onCellMouseOver(e
|
|
2377
|
+
function onCellMouseOver(e) {
|
|
2378
|
+
const { row, col } = getCellEventData(e);
|
|
2274
2379
|
emits("cell-mouseover", e, row, col);
|
|
2275
2380
|
}
|
|
2276
|
-
function onCellMouseDown(e
|
|
2381
|
+
function onCellMouseDown(e) {
|
|
2382
|
+
const { row, col, rowIndex } = getCellEventData(e);
|
|
2277
2383
|
emits("cell-mousedown", e, row, col, { rowIndex });
|
|
2278
2384
|
}
|
|
2279
2385
|
function onTableWheel(e) {
|
|
@@ -2285,20 +2391,19 @@ const _sfc_main = /* @__PURE__ */ defineComponent({
|
|
|
2285
2391
|
return;
|
|
2286
2392
|
}
|
|
2287
2393
|
const dom = tableContainerRef.value;
|
|
2288
|
-
if (!dom) return;
|
|
2289
|
-
if (!virtual_on.value && !virtualX_on.value) return;
|
|
2290
|
-
const { containerHeight, scrollTop, scrollHeight } = virtualScroll.value;
|
|
2291
|
-
const { containerWidth, scrollLeft, scrollWidth } = virtualScrollX.value;
|
|
2292
|
-
const isScrollBottom = scrollHeight - containerHeight - scrollTop < 10;
|
|
2293
|
-
const isScrollRight = scrollWidth - containerWidth - scrollLeft < 10;
|
|
2394
|
+
if (!virtual_on.value && !virtualX_on.value || !dom) return;
|
|
2294
2395
|
const { deltaY, deltaX, shiftKey } = e;
|
|
2295
2396
|
if (virtual_on.value && deltaY && !shiftKey) {
|
|
2397
|
+
const { containerHeight, scrollTop, scrollHeight } = virtualScroll.value;
|
|
2398
|
+
const isScrollBottom = scrollHeight - containerHeight - scrollTop < 10;
|
|
2296
2399
|
if (deltaY > 0 && !isScrollBottom || deltaY < 0 && scrollTop > 0) {
|
|
2297
2400
|
e.preventDefault();
|
|
2298
2401
|
}
|
|
2299
2402
|
dom.scrollTop += deltaY;
|
|
2300
2403
|
}
|
|
2301
2404
|
if (virtualX_on.value) {
|
|
2405
|
+
const { containerWidth, scrollLeft, scrollWidth } = virtualScrollX.value;
|
|
2406
|
+
const isScrollRight = scrollWidth - containerWidth - scrollLeft < 10;
|
|
2302
2407
|
let distance = deltaX;
|
|
2303
2408
|
if (shiftKey && deltaY) {
|
|
2304
2409
|
distance = deltaY;
|
|
@@ -2335,12 +2440,16 @@ const _sfc_main = /* @__PURE__ */ defineComponent({
|
|
|
2335
2440
|
emits("scroll-x", e);
|
|
2336
2441
|
}
|
|
2337
2442
|
}
|
|
2338
|
-
function onTrMouseOver(
|
|
2443
|
+
function onTrMouseOver(e) {
|
|
2444
|
+
const tr = getClosestTr(e);
|
|
2445
|
+
if (!tr) return;
|
|
2446
|
+
const rowIndex = Number(tr.dataset.rowI);
|
|
2447
|
+
const row = dataSourceCopy.value[rowIndex];
|
|
2339
2448
|
if (currentHoverRow === row) return;
|
|
2340
2449
|
currentHoverRow = row;
|
|
2341
|
-
const rowKey =
|
|
2450
|
+
const rowKey = tr.dataset.rowKey;
|
|
2342
2451
|
if (props.showTrHoverClass) {
|
|
2343
|
-
currentHoverRowKey.value = rowKey;
|
|
2452
|
+
currentHoverRowKey.value = rowKey || null;
|
|
2344
2453
|
}
|
|
2345
2454
|
if (props.rowHover) {
|
|
2346
2455
|
updateHoverMergedCells(rowKey);
|
|
@@ -2617,7 +2726,17 @@ const _sfc_main = /* @__PURE__ */ defineComponent({
|
|
|
2617
2726
|
class: normalizeClass(["stk-table-main", {
|
|
2618
2727
|
"fixed-mode": props.fixedMode
|
|
2619
2728
|
}]),
|
|
2620
|
-
style: normalizeStyle({ width: __props.width, minWidth: __props.minWidth, maxWidth: __props.maxWidth })
|
|
2729
|
+
style: normalizeStyle({ width: __props.width, minWidth: __props.minWidth, maxWidth: __props.maxWidth }),
|
|
2730
|
+
onDragover: _cache[4] || (_cache[4] = //@ts-ignore
|
|
2731
|
+
(...args) => unref(onTrDragOver) && unref(onTrDragOver)(...args)),
|
|
2732
|
+
onDragenter: _cache[5] || (_cache[5] = //@ts-ignore
|
|
2733
|
+
(...args) => unref(onTrDragEnter) && unref(onTrDragEnter)(...args)),
|
|
2734
|
+
onDragend: _cache[6] || (_cache[6] = //@ts-ignore
|
|
2735
|
+
(...args) => unref(onTrDragEnd) && unref(onTrDragEnd)(...args)),
|
|
2736
|
+
onClick: onRowClick,
|
|
2737
|
+
onDblclick: onRowDblclick,
|
|
2738
|
+
onContextmenu: onRowMenu,
|
|
2739
|
+
onMouseover: onTrMouseOver
|
|
2621
2740
|
}, [
|
|
2622
2741
|
!__props.headless ? (openBlock(), createElementBlock("thead", _hoisted_1, [
|
|
2623
2742
|
(openBlock(true), createElementBlock(Fragment, null, renderList(tableHeaders.value, (row, rowIndex) => {
|
|
@@ -2631,31 +2750,14 @@ const _sfc_main = /* @__PURE__ */ defineComponent({
|
|
|
2631
2750
|
style: normalizeStyle(`min-width:${unref(virtualScrollX).offsetLeft}px;width:${unref(virtualScrollX).offsetLeft}px`)
|
|
2632
2751
|
}, null, 4)) : createCommentVNode("", true),
|
|
2633
2752
|
(openBlock(true), createElementBlock(Fragment, null, renderList(unref(virtualX_on) && rowIndex === tableHeaders.value.length - 1 ? unref(virtualX_columnPart) : row, (col, colIndex) => {
|
|
2634
|
-
return openBlock(), createElementBlock("th", {
|
|
2635
|
-
key: colKeyGen.value(col)
|
|
2636
|
-
|
|
2637
|
-
|
|
2638
|
-
|
|
2639
|
-
|
|
2640
|
-
|
|
2641
|
-
|
|
2642
|
-
class: normalizeClass([
|
|
2643
|
-
col.sorter ? "sortable" : "",
|
|
2644
|
-
colKeyGen.value(col) === unref(sortCol) && unref(sortOrderIndex) !== 0 && "sorter-" + sortSwitchOrder[unref(sortOrderIndex)],
|
|
2645
|
-
col.headerClassName,
|
|
2646
|
-
unref(fixedColClassMap).get(colKeyGen.value(col))
|
|
2647
|
-
]),
|
|
2648
|
-
onClick: (e) => {
|
|
2649
|
-
onColumnSort(col);
|
|
2650
|
-
onHeaderCellClick(e, col);
|
|
2651
|
-
},
|
|
2652
|
-
onDragstart: _cache[0] || (_cache[0] = //@ts-ignore
|
|
2653
|
-
(...args) => unref(onThDragStart) && unref(onThDragStart)(...args)),
|
|
2654
|
-
onDrop: _cache[1] || (_cache[1] = //@ts-ignore
|
|
2655
|
-
(...args) => unref(onThDrop) && unref(onThDrop)(...args)),
|
|
2656
|
-
onDragover: _cache[2] || (_cache[2] = //@ts-ignore
|
|
2657
|
-
(...args) => unref(onThDragOver) && unref(onThDragOver)(...args))
|
|
2658
|
-
}, [
|
|
2753
|
+
return openBlock(), createElementBlock("th", mergeProps({
|
|
2754
|
+
key: colKeyGen.value(col)
|
|
2755
|
+
}, { ref_for: true }, getTHProps(col), {
|
|
2756
|
+
onClick: (e) => onHeaderCellClick(e, col),
|
|
2757
|
+
onDragstart: _cache[0] || (_cache[0] = ($event) => __props.headerDrag ? unref(onThDragStart) : void 0),
|
|
2758
|
+
onDrop: _cache[1] || (_cache[1] = ($event) => __props.headerDrag ? unref(onThDrop) : void 0),
|
|
2759
|
+
onDragover: _cache[2] || (_cache[2] = ($event) => __props.headerDrag ? unref(onThDragOver) : void 0)
|
|
2760
|
+
}), [
|
|
2659
2761
|
unref(colResizeOn)(col) && colIndex > 0 ? (openBlock(), createElementBlock("div", {
|
|
2660
2762
|
key: 0,
|
|
2661
2763
|
class: "table-header-resizer left",
|
|
@@ -2663,7 +2765,7 @@ const _sfc_main = /* @__PURE__ */ defineComponent({
|
|
|
2663
2765
|
}, null, 40, _hoisted_3)) : createCommentVNode("", true),
|
|
2664
2766
|
createElementVNode("div", {
|
|
2665
2767
|
class: "table-header-cell-wrapper",
|
|
2666
|
-
style: normalizeStyle(
|
|
2768
|
+
style: normalizeStyle(`--row-span:${unref(virtualX_on) ? 1 : col.__R_SP__}`)
|
|
2667
2769
|
}, [
|
|
2668
2770
|
col.customHeaderCell ? (openBlock(), createBlock(resolveDynamicComponent(col.customHeaderCell), {
|
|
2669
2771
|
key: 0,
|
|
@@ -2686,7 +2788,7 @@ const _sfc_main = /* @__PURE__ */ defineComponent({
|
|
|
2686
2788
|
class: "table-header-resizer right",
|
|
2687
2789
|
onMousedown: ($event) => unref(onThResizeMouseDown)($event, col)
|
|
2688
2790
|
}, null, 40, _hoisted_5)) : createCommentVNode("", true)
|
|
2689
|
-
],
|
|
2791
|
+
], 16, _hoisted_2);
|
|
2690
2792
|
}), 128)),
|
|
2691
2793
|
unref(virtualX_on) ? (openBlock(), createElementBlock("th", {
|
|
2692
2794
|
key: 1,
|
|
@@ -2698,12 +2800,9 @@ const _sfc_main = /* @__PURE__ */ defineComponent({
|
|
|
2698
2800
|
])) : createCommentVNode("", true),
|
|
2699
2801
|
createElementVNode("tbody", {
|
|
2700
2802
|
class: "stk-tbody-main",
|
|
2701
|
-
|
|
2702
|
-
|
|
2703
|
-
|
|
2704
|
-
(...args) => unref(onTrDragEnter) && unref(onTrDragEnter)(...args)),
|
|
2705
|
-
onDragend: _cache[7] || (_cache[7] = //@ts-ignore
|
|
2706
|
-
(...args) => unref(onTrDragEnd) && unref(onTrDragEnd)(...args))
|
|
2803
|
+
onClick: onCellClick,
|
|
2804
|
+
onMousedown: onCellMouseDown,
|
|
2805
|
+
onMouseover: onCellMouseOver
|
|
2707
2806
|
}, [
|
|
2708
2807
|
unref(virtual_on) && !unref(isSRBRActive) ? (openBlock(), createElementBlock("tr", {
|
|
2709
2808
|
key: 0,
|
|
@@ -2719,31 +2818,15 @@ const _sfc_main = /* @__PURE__ */ defineComponent({
|
|
|
2719
2818
|
}), 128)) : createCommentVNode("", true)
|
|
2720
2819
|
], 4)) : createCommentVNode("", true),
|
|
2721
2820
|
(openBlock(true), createElementBlock(Fragment, null, renderList(unref(virtual_dataSourcePart), (row, rowIndex) => {
|
|
2722
|
-
|
|
2723
|
-
return openBlock(), createElementBlock("tr", {
|
|
2724
|
-
id: unref(stkTableId) + "-" + (__props.rowKey ? rowKeyGen(row) : getRowIndex(rowIndex)),
|
|
2821
|
+
return openBlock(), createElementBlock("tr", mergeProps({
|
|
2725
2822
|
ref_for: true,
|
|
2726
2823
|
ref_key: "trRef",
|
|
2727
2824
|
ref: trRef,
|
|
2728
|
-
key:
|
|
2729
|
-
|
|
2730
|
-
|
|
2731
|
-
|
|
2732
|
-
|
|
2733
|
-
[__props.rowClassName(row, getRowIndex(rowIndex)) || ""]: true,
|
|
2734
|
-
expanded: row && row.__EXP__,
|
|
2735
|
-
"expanded-row": row && row.__EXP_R__
|
|
2736
|
-
}),
|
|
2737
|
-
style: normalizeStyle({
|
|
2738
|
-
"--row-height": row && row.__EXP_R__ && props.virtual && ((_a = props.expandConfig) == null ? void 0 : _a.height) && ((_b = props.expandConfig) == null ? void 0 : _b.height) + "px"
|
|
2739
|
-
}),
|
|
2740
|
-
onClick: ($event) => onRowClick($event, row, getRowIndex(rowIndex)),
|
|
2741
|
-
onDblclick: ($event) => onRowDblclick($event, row, getRowIndex(rowIndex)),
|
|
2742
|
-
onContextmenu: ($event) => onRowMenu($event, row, getRowIndex(rowIndex)),
|
|
2743
|
-
onMouseover: ($event) => onTrMouseOver($event, row),
|
|
2744
|
-
onMouseleave: _cache[4] || (_cache[4] = ($event) => onTrMouseLeave($event)),
|
|
2745
|
-
onDrop: ($event) => unref(onTrDrop)($event, getRowIndex(rowIndex))
|
|
2746
|
-
}, [
|
|
2825
|
+
key: rowKeyGen(row)
|
|
2826
|
+
}, { ref_for: true }, getTRProps(row, rowIndex), {
|
|
2827
|
+
onDrop: ($event) => unref(onTrDrop)($event, getRowIndex(rowIndex)),
|
|
2828
|
+
onMouseleave: onTrMouseLeave
|
|
2829
|
+
}), [
|
|
2747
2830
|
unref(virtualX_on) ? (openBlock(), createElementBlock("td", _hoisted_8)) : createCommentVNode("", true),
|
|
2748
2831
|
row && row.__EXP_R__ ? (openBlock(), createElementBlock("td", {
|
|
2749
2832
|
key: 1,
|
|
@@ -2754,26 +2837,20 @@ const _sfc_main = /* @__PURE__ */ defineComponent({
|
|
|
2754
2837
|
row: row.__EXP_R__,
|
|
2755
2838
|
col: row.__EXP_C__
|
|
2756
2839
|
}, () => {
|
|
2757
|
-
var
|
|
2840
|
+
var _a;
|
|
2758
2841
|
return [
|
|
2759
|
-
createTextVNode(toDisplayString(((
|
|
2842
|
+
createTextVNode(toDisplayString(((_a = row.__EXP_R__) == null ? void 0 : _a[row.__EXP_C__.dataIndex]) ?? ""), 1)
|
|
2760
2843
|
];
|
|
2761
2844
|
})
|
|
2762
2845
|
])
|
|
2763
2846
|
], 8, _hoisted_9)) : (openBlock(true), createElementBlock(Fragment, { key: 2 }, renderList(unref(virtualX_columnPart), (col, colIndex) => {
|
|
2764
|
-
var
|
|
2847
|
+
var _a;
|
|
2765
2848
|
return openBlock(), createElementBlock(Fragment, null, [
|
|
2766
|
-
!((
|
|
2849
|
+
!((_a = unref(hiddenCellMap)[rowKeyGen(row)]) == null ? void 0 : _a.has(colKeyGen.value(col))) ? (openBlock(), createElementBlock("td", mergeProps({
|
|
2767
2850
|
key: colKeyGen.value(col)
|
|
2768
|
-
}, { ref_for: true }, {
|
|
2769
|
-
|
|
2770
|
-
|
|
2771
|
-
}, {
|
|
2772
|
-
onClick: ($event) => onCellClick($event, row, col, getRowIndex(rowIndex)),
|
|
2773
|
-
onMousedown: ($event) => onCellMouseDown($event, row, col, getRowIndex(rowIndex)),
|
|
2774
|
-
onMouseenter: ($event) => onCellMouseEnter($event, row, col),
|
|
2775
|
-
onMouseleave: ($event) => onCellMouseLeave($event, row, col),
|
|
2776
|
-
onMouseover: ($event) => onCellMouseOver($event, row, col)
|
|
2851
|
+
}, { ref_for: true }, getTDProps(row, col, rowIndex, colIndex), {
|
|
2852
|
+
onMouseenter: onCellMouseEnter,
|
|
2853
|
+
onMouseleave: onCellMouseLeave
|
|
2777
2854
|
}), [
|
|
2778
2855
|
col.customCell ? (openBlock(), createBlock(resolveDynamicComponent(col.customCell), {
|
|
2779
2856
|
key: 0,
|
|
@@ -2801,7 +2878,7 @@ const _sfc_main = /* @__PURE__ */ defineComponent({
|
|
|
2801
2878
|
key: 1,
|
|
2802
2879
|
class: "table-cell-wrapper",
|
|
2803
2880
|
title: col.type !== "seq" ? row == null ? void 0 : row[col.dataIndex] : "",
|
|
2804
|
-
style: normalizeStyle(col.type === "tree-node"
|
|
2881
|
+
style: normalizeStyle(col.type === "tree-node" && row.__T_LV__ ? `padding-left:${row.__T_LV__ * 16}px` : "")
|
|
2805
2882
|
}, [
|
|
2806
2883
|
col.type === "seq" ? (openBlock(), createElementBlock(Fragment, { key: 0 }, [
|
|
2807
2884
|
createTextVNode(toDisplayString((props.seqConfig.startIndex || 0) + getRowIndex(rowIndex) + 1), 1)
|
|
@@ -2821,11 +2898,12 @@ const _sfc_main = /* @__PURE__ */ defineComponent({
|
|
|
2821
2898
|
], 64)) : (openBlock(), createElementBlock(Fragment, { key: 3 }, [
|
|
2822
2899
|
createTextVNode(toDisplayString((row == null ? void 0 : row[col.dataIndex]) ?? getEmptyCellText.value(col, row)), 1)
|
|
2823
2900
|
], 64))
|
|
2824
|
-
], 12,
|
|
2825
|
-
], 16
|
|
2901
|
+
], 12, _hoisted_11))
|
|
2902
|
+
], 16)) : createCommentVNode("", true)
|
|
2826
2903
|
], 64);
|
|
2827
|
-
}), 256))
|
|
2828
|
-
|
|
2904
|
+
}), 256)),
|
|
2905
|
+
unref(virtualX_on) ? (openBlock(), createElementBlock("td", _hoisted_12)) : createCommentVNode("", true)
|
|
2906
|
+
], 16, _hoisted_7);
|
|
2829
2907
|
}), 128)),
|
|
2830
2908
|
unref(virtual_on) && !unref(isSRBRActive) ? (openBlock(), createElementBlock("tr", {
|
|
2831
2909
|
key: 1,
|
|
@@ -2836,13 +2914,13 @@ const _sfc_main = /* @__PURE__ */ defineComponent({
|
|
|
2836
2914
|
style: normalizeStyle(`height: ${SRBRBottomHeight.value}px`)
|
|
2837
2915
|
}, null, 4)) : createCommentVNode("", true)
|
|
2838
2916
|
], 32)
|
|
2839
|
-
],
|
|
2917
|
+
], 38),
|
|
2840
2918
|
(!dataSourceCopy.value || !dataSourceCopy.value.length) && __props.showNoData ? (openBlock(), createElementBlock("div", {
|
|
2841
2919
|
key: 2,
|
|
2842
2920
|
class: normalizeClass(["stk-table-no-data", { "no-data-full": __props.noDataFull }])
|
|
2843
2921
|
}, [
|
|
2844
2922
|
renderSlot(_ctx.$slots, "empty", {}, () => [
|
|
2845
|
-
_cache[
|
|
2923
|
+
_cache[7] || (_cache[7] = createTextVNode("暂无数据", -1))
|
|
2846
2924
|
])
|
|
2847
2925
|
], 2)) : createCommentVNode("", true),
|
|
2848
2926
|
renderSlot(_ctx.$slots, "customBottom")
|
package/lib/style.css
CHANGED
|
@@ -1,3 +1,11 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* name: stk-table-vue
|
|
3
|
+
* version: v0.8.13
|
|
4
|
+
* description: High performance realtime virtual table for vue3 and vue2.7
|
|
5
|
+
* author: japlus
|
|
6
|
+
* homepage: https://ja-plus.github.io/stk-table-vue/
|
|
7
|
+
* license: MIT
|
|
8
|
+
*/
|
|
1
9
|
@keyframes stk-table-dim{
|
|
2
10
|
from{
|
|
3
11
|
background-color:var(--highlight-color);
|
|
@@ -242,8 +250,6 @@
|
|
|
242
250
|
.stk-table .vt-x-left,
|
|
243
251
|
.stk-table .vt-x-right{
|
|
244
252
|
padding:0;
|
|
245
|
-
background:none;
|
|
246
|
-
pointer-events:none;
|
|
247
253
|
}
|
|
248
254
|
.stk-table .column-resize-indicator{
|
|
249
255
|
width:0;
|