stk-table-vue 0.8.12 → 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.
@@ -1,4 +1,12 @@
1
- import { createElementBlock, openBlock, createElementVNode, watch, onMounted, onBeforeUnmount, ref, computed, shallowRef, onUnmounted, defineComponent, nextTick, toRaw, normalizeStyle, normalizeClass, unref, createCommentVNode, renderSlot, Fragment, renderList, createBlock, resolveDynamicComponent, toDisplayString, createTextVNode, mergeProps, withCtx, createVNode } from "vue";
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;
@@ -227,9 +249,9 @@ const DEFAULT_SORT_CONFIG = {
227
249
  sortChildren: false
228
250
  };
229
251
  const DEFAULT_ROW_ACTIVE_CONFIG = {
230
- enabled: false,
252
+ enabled: true,
231
253
  disabled: () => false,
232
- revokable: false
254
+ revokable: true
233
255
  };
234
256
  var TagType = /* @__PURE__ */ ((TagType2) => {
235
257
  TagType2[TagType2["TH"] = 0] = "TH";
@@ -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 = fixedColShadow && fixed && fixedShadowColsValue.includes(col);
487
- const classObj = {
488
- "fixed-cell--active": fixedColsValue.includes(col)
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
- classObj["fixed-cell"] = true;
493
- classObj["fixed-cell--" + fixed] = true;
514
+ classList.push("fixed-cell");
515
+ classList.push("fixed-cell--" + fixed);
494
516
  }
495
517
  if (showShadow) {
496
- classObj["fixed-cell--shadow"] = true;
518
+ classList.push("fixed-cell--shadow");
497
519
  }
498
- colMap.set(colKey(col), classObj);
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-cell-key="${pureCellKeyGen(rowKeyValue, colKeyValue)}"]`);
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,
@@ -917,17 +939,19 @@ function useMergeCells({ rowActiveProp, tableHeaderLast, rowKeyGen, colKeyGen, v
917
939
  hiddenCellMap.value = {};
918
940
  hoverRowMap.value = {};
919
941
  });
920
- function hideCells(rowKey, startIndex, count, isSelfRow = false, mergeCellKey) {
921
- for (let i = startIndex; i < startIndex + count; i++) {
922
- if (!isSelfRow || i !== startIndex) {
923
- const nextCol = tableHeaderLast.value[i];
924
- if (!nextCol) break;
925
- const nextColKey = colKeyGen.value(nextCol);
926
- if (!hiddenCellMap.value[rowKey]) hiddenCellMap.value[rowKey] = /* @__PURE__ */ new Set();
927
- hiddenCellMap.value[rowKey].add(nextColKey);
928
- }
942
+ function hideCells(rowKey, colKey, colspan, isSelfRow = false, mergeCellKey) {
943
+ const startIndex = tableHeaderLast.value.findIndex((item) => colKeyGen.value(item) === colKey);
944
+ for (let i = startIndex; i < startIndex + colspan; i++) {
929
945
  if (!hoverRowMap.value[rowKey]) hoverRowMap.value[rowKey] = /* @__PURE__ */ new Set();
930
946
  hoverRowMap.value[rowKey].add(mergeCellKey);
947
+ if (isSelfRow && i === startIndex) {
948
+ continue;
949
+ }
950
+ const nextCol = tableHeaderLast.value[i];
951
+ if (!nextCol) break;
952
+ const nextColKey = colKeyGen.value(nextCol);
953
+ if (!hiddenCellMap.value[rowKey]) hiddenCellMap.value[rowKey] = /* @__PURE__ */ new Set();
954
+ hiddenCellMap.value[rowKey].add(nextColKey);
931
955
  }
932
956
  }
933
957
  function mergeCellsWrapper(row, col, rowIndex, colIndex) {
@@ -937,26 +961,25 @@ function useMergeCells({ rowActiveProp, tableHeaderLast, rowKeyGen, colKeyGen, v
937
961
  rowspan = rowspan || 1;
938
962
  if (colspan === 1 && rowspan === 1) return;
939
963
  const rowKey = rowKeyGen(row);
940
- const colKey = colKeyGen.value(col);
941
- const curColIndex = tableHeaderLast.value.findIndex((item) => colKeyGen.value(item) === colKey);
942
964
  const curRowIndex = virtual_dataSourcePart.value.findIndex((item) => rowKeyGen(item) === rowKey);
943
- const mergedCellKey = pureCellKeyGen(rowKey, colKey);
944
965
  if (curRowIndex === -1) return;
966
+ const colKey = colKeyGen.value(col);
967
+ const mergedCellKey = pureCellKeyGen(rowKey, colKey);
945
968
  for (let i = curRowIndex; i < curRowIndex + rowspan; i++) {
946
969
  const row2 = virtual_dataSourcePart.value[i];
947
970
  if (!row2) break;
948
- hideCells(rowKeyGen(row2), curColIndex, colspan, i === curRowIndex, mergedCellKey);
971
+ hideCells(rowKeyGen(row2), colKey, colspan, i === curRowIndex, mergedCellKey);
949
972
  }
950
973
  return { colspan, rowspan };
951
974
  }
975
+ const emptySet = /* @__PURE__ */ new Set();
952
976
  function updateHoverMergedCells(rowKey) {
953
- const set = rowKey === void 0 ? null : hoverRowMap.value[rowKey];
954
- hoverMergedCells.value = set || /* @__PURE__ */ new Set();
977
+ hoverMergedCells.value = rowKey === void 0 ? emptySet : hoverRowMap.value[rowKey] || emptySet;
955
978
  }
956
979
  function updateActiveMergedCells(clear, rowKey) {
957
980
  if (!rowActiveProp.value.enabled) return;
958
981
  if (clear) {
959
- activeMergedCells.value.clear();
982
+ activeMergedCells.value = /* @__PURE__ */ new Set();
960
983
  return;
961
984
  }
962
985
  activeMergedCells.value = rowKey !== void 0 && hoverRowMap.value[rowKey] || new Set(hoverMergedCells.value);
@@ -1029,10 +1052,36 @@ function useRowExpand({ dataSourceCopy, rowKeyGen, emits }) {
1029
1052
  };
1030
1053
  }
1031
1054
  function useScrollRowByRow({ props, tableContainerRef }) {
1032
- let isMouseDown = false;
1033
1055
  let isAddListeners = false;
1034
- let lastScrollTop = 0;
1035
- const isDragScroll = ref(false);
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
+ });
1036
1085
  const onlyDragScroll = computed(() => props.scrollRowByRow === "scrollbar");
1037
1086
  const isSRBRActive = computed(() => {
1038
1087
  if (onlyDragScroll.value) {
@@ -1059,7 +1108,6 @@ function useScrollRowByRow({ props, tableContainerRef }) {
1059
1108
  if (!container) return;
1060
1109
  container.addEventListener("mousedown", handleMouseDown);
1061
1110
  container.addEventListener("mouseup", handleMouseUp);
1062
- container.addEventListener("scroll", handleScroll);
1063
1111
  isAddListeners = true;
1064
1112
  }
1065
1113
  function removeEventListener() {
@@ -1067,22 +1115,16 @@ function useScrollRowByRow({ props, tableContainerRef }) {
1067
1115
  if (!container) return;
1068
1116
  container.removeEventListener("mousedown", handleMouseDown);
1069
1117
  container.removeEventListener("mouseup", handleMouseUp);
1070
- container.removeEventListener("scroll", handleScroll);
1071
1118
  isAddListeners = false;
1072
1119
  }
1073
1120
  function handleMouseDown(e) {
1074
- isMouseDown = true;
1075
- lastScrollTop = e.target.scrollTop;
1121
+ const el = e.target;
1122
+ if (el.classList.contains("stk-table")) {
1123
+ isDragScroll.value = true;
1124
+ }
1076
1125
  }
1077
1126
  function handleMouseUp() {
1078
- isMouseDown = false;
1079
1127
  isDragScroll.value = false;
1080
- lastScrollTop = 0;
1081
- }
1082
- function handleScroll(e) {
1083
- const scrollTop = e.target.scrollTop;
1084
- if (!isMouseDown || scrollTop === lastScrollTop) return;
1085
- isDragScroll.value = true;
1086
1128
  }
1087
1129
  return { isSRBRActive, isDragScroll };
1088
1130
  }
@@ -1165,11 +1207,6 @@ function useTrDrag({ props, emits, dataSourceCopy }) {
1165
1207
  const dragRowConfig = computed(() => {
1166
1208
  return { mode: "insert", ...props.dragRowConfig };
1167
1209
  });
1168
- function getClosestTr(e) {
1169
- const target = e.target;
1170
- const tr = target == null ? void 0 : target.closest("tr");
1171
- return tr;
1172
- }
1173
1210
  function onTrDragStart(e, rowIndex) {
1174
1211
  var _a;
1175
1212
  const tr = getClosestTr(e);
@@ -1706,7 +1743,7 @@ function useVirtualScroll({
1706
1743
  };
1707
1744
  }
1708
1745
  const _hoisted_1 = { key: 0 };
1709
- const _hoisted_2 = ["data-col-key", "draggable", "rowspan", "colspan", "title", "onClick"];
1746
+ const _hoisted_2 = ["onClick"];
1710
1747
  const _hoisted_3 = ["onMousedown"];
1711
1748
  const _hoisted_4 = { class: "table-header-title" };
1712
1749
  const _hoisted_5 = ["onMousedown"];
@@ -1714,15 +1751,18 @@ const _hoisted_6 = {
1714
1751
  key: 0,
1715
1752
  class: "vt-x-left"
1716
1753
  };
1717
- const _hoisted_7 = ["id", "data-row-key", "onClick", "onDblclick", "onContextmenu", "onMouseover", "onDrop"];
1754
+ const _hoisted_7 = ["onDrop"];
1718
1755
  const _hoisted_8 = {
1719
1756
  key: 0,
1720
1757
  class: "vt-x-left"
1721
1758
  };
1722
1759
  const _hoisted_9 = ["colspan"];
1723
1760
  const _hoisted_10 = { class: "table-cell-wrapper" };
1724
- const _hoisted_11 = ["data-cell-key", "onClick", "onMousedown", "onMouseenter", "onMouseleave", "onMouseover"];
1725
- const _hoisted_12 = ["title"];
1761
+ const _hoisted_11 = ["title"];
1762
+ const _hoisted_12 = {
1763
+ key: 3,
1764
+ class: "vt-x-right"
1765
+ };
1726
1766
  const _sfc_main = /* @__PURE__ */ defineComponent({
1727
1767
  __name: "StkTable",
1728
1768
  props: {
@@ -2114,7 +2154,7 @@ const _sfc_main = /* @__PURE__ */ defineComponent({
2114
2154
  };
2115
2155
  });
2116
2156
  function getRowIndex(rowIndex) {
2117
- return rowIndex + (virtual_on.value ? virtualScroll.value.startIndex : 0);
2157
+ return rowIndex + virtualScroll.value.startIndex;
2118
2158
  }
2119
2159
  function getHeaderTitle(col) {
2120
2160
  const colKey = colKeyGen.value(col);
@@ -2123,6 +2163,83 @@ const _sfc_main = /* @__PURE__ */ defineComponent({
2123
2163
  }
2124
2164
  return col.title || "";
2125
2165
  }
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) {
2208
+ const colKey = colKeyGen.value(col);
2209
+ if (!row) {
2210
+ return {
2211
+ style: cellStyleMap.value[TagType.TD].get(colKey)
2212
+ };
2213
+ }
2214
+ const cellKey = cellKeyGen(row, col);
2215
+ const classList = [col.className, fixedColClassMap.value.get(colKey)];
2216
+ if (col.mergeCells) {
2217
+ if (hoverMergedCells.value.has(cellKey)) {
2218
+ classList.push("cell-hover");
2219
+ }
2220
+ if (activeMergedCells.value.has(cellKey)) {
2221
+ classList.push("cell-active");
2222
+ }
2223
+ }
2224
+ if (props.cellActive && currentSelectedCellKey.value === cellKey) {
2225
+ classList.push("active");
2226
+ }
2227
+ if (col.type === "seq") {
2228
+ classList.push("seq-column");
2229
+ } else if (col.type === "expand" && (row.__EXP__ ? colKeyGen.value(row.__EXP__) === colKey : false)) {
2230
+ classList.push("expanded");
2231
+ } else if (row.__T_EXP__ && col.type === "tree-node") {
2232
+ classList.push("tree-expanded");
2233
+ } else if (col.type === "dragRow") {
2234
+ classList.push("drag-row-cell");
2235
+ }
2236
+ return {
2237
+ "data-col-key": colKey,
2238
+ style: cellStyleMap.value[TagType.TD].get(colKey),
2239
+ class: classList,
2240
+ ...mergeCellsWrapper(row, col, rowIndex, colIndex)
2241
+ };
2242
+ }
2126
2243
  function onColumnSort(col, click = true, options = {}) {
2127
2244
  if (!col) {
2128
2245
  console.warn("onColumnSort: not found col:", col);
@@ -2178,8 +2295,11 @@ const _sfc_main = /* @__PURE__ */ defineComponent({
2178
2295
  emits("sort-change", col, order, toRaw(dataSourceTemp), sortConfig);
2179
2296
  }
2180
2297
  }
2181
- function onRowClick(e, row, rowIndex) {
2298
+ function onRowClick(e) {
2182
2299
  var _a, _b;
2300
+ const rowIndex = getClosestTrIndex(e);
2301
+ const row = dataSourceCopy.value[rowIndex];
2302
+ if (!row) return;
2183
2303
  emits("row-click", e, row, { rowIndex });
2184
2304
  if ((_b = (_a = rowActiveProp.value).disabled) == null ? void 0 : _b.call(_a, row)) return;
2185
2305
  const isCurrentRow = props.rowKey ? currentRowKey.value === rowKeyGen(row) : currentRow.value === row;
@@ -2193,13 +2313,19 @@ const _sfc_main = /* @__PURE__ */ defineComponent({
2193
2313
  }
2194
2314
  emits("current-change", e, row, { select: !isCurrentRow });
2195
2315
  }
2196
- function onRowDblclick(e, row, rowIndex) {
2316
+ function onRowDblclick(e) {
2317
+ const rowIndex = getClosestTrIndex(e);
2318
+ const row = dataSourceCopy.value[rowIndex];
2319
+ if (!row) return;
2197
2320
  emits("row-dblclick", e, row, { rowIndex });
2198
2321
  }
2199
2322
  function onHeaderMenu(e) {
2200
2323
  emits("header-row-menu", e);
2201
2324
  }
2202
- function onRowMenu(e, row, rowIndex) {
2325
+ function onRowMenu(e) {
2326
+ const rowIndex = getClosestTrIndex(e);
2327
+ const row = dataSourceCopy.value[rowIndex];
2328
+ if (!row) return;
2203
2329
  emits("row-menu", e, row, { rowIndex });
2204
2330
  }
2205
2331
  function triangleClick(e, row, col) {
@@ -2209,7 +2335,13 @@ const _sfc_main = /* @__PURE__ */ defineComponent({
2209
2335
  toggleTreeNode(row, col);
2210
2336
  }
2211
2337
  }
2212
- function onCellClick(e, row, col, rowIndex) {
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;
2213
2345
  if (props.cellActive) {
2214
2346
  const cellKey = cellKeyGen(row, col);
2215
2347
  const result = { row, col, select: false, rowIndex };
@@ -2223,19 +2355,31 @@ const _sfc_main = /* @__PURE__ */ defineComponent({
2223
2355
  }
2224
2356
  emits("cell-click", e, row, col, { rowIndex });
2225
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
+ }
2226
2365
  function onHeaderCellClick(e, col) {
2366
+ onColumnSort(col);
2227
2367
  emits("header-cell-click", e, col);
2228
2368
  }
2229
- function onCellMouseEnter(e, row, col) {
2369
+ function onCellMouseEnter(e) {
2370
+ const { row, col } = getCellEventData(e);
2230
2371
  emits("cell-mouseenter", e, row, col);
2231
2372
  }
2232
- function onCellMouseLeave(e, row, col) {
2373
+ function onCellMouseLeave(e) {
2374
+ const { row, col } = getCellEventData(e);
2233
2375
  emits("cell-mouseleave", e, row, col);
2234
2376
  }
2235
- function onCellMouseOver(e, row, col) {
2377
+ function onCellMouseOver(e) {
2378
+ const { row, col } = getCellEventData(e);
2236
2379
  emits("cell-mouseover", e, row, col);
2237
2380
  }
2238
- function onCellMouseDown(e, row, col, rowIndex) {
2381
+ function onCellMouseDown(e) {
2382
+ const { row, col, rowIndex } = getCellEventData(e);
2239
2383
  emits("cell-mousedown", e, row, col, { rowIndex });
2240
2384
  }
2241
2385
  function onTableWheel(e) {
@@ -2247,20 +2391,19 @@ const _sfc_main = /* @__PURE__ */ defineComponent({
2247
2391
  return;
2248
2392
  }
2249
2393
  const dom = tableContainerRef.value;
2250
- if (!dom) return;
2251
- if (!virtual_on.value && !virtualX_on.value) return;
2252
- const { containerHeight, scrollTop, scrollHeight } = virtualScroll.value;
2253
- const { containerWidth, scrollLeft, scrollWidth } = virtualScrollX.value;
2254
- const isScrollBottom = scrollHeight - containerHeight - scrollTop < 10;
2255
- const isScrollRight = scrollWidth - containerWidth - scrollLeft < 10;
2394
+ if (!virtual_on.value && !virtualX_on.value || !dom) return;
2256
2395
  const { deltaY, deltaX, shiftKey } = e;
2257
2396
  if (virtual_on.value && deltaY && !shiftKey) {
2397
+ const { containerHeight, scrollTop, scrollHeight } = virtualScroll.value;
2398
+ const isScrollBottom = scrollHeight - containerHeight - scrollTop < 10;
2258
2399
  if (deltaY > 0 && !isScrollBottom || deltaY < 0 && scrollTop > 0) {
2259
2400
  e.preventDefault();
2260
2401
  }
2261
2402
  dom.scrollTop += deltaY;
2262
2403
  }
2263
2404
  if (virtualX_on.value) {
2405
+ const { containerWidth, scrollLeft, scrollWidth } = virtualScrollX.value;
2406
+ const isScrollRight = scrollWidth - containerWidth - scrollLeft < 10;
2264
2407
  let distance = deltaX;
2265
2408
  if (shiftKey && deltaY) {
2266
2409
  distance = deltaY;
@@ -2297,12 +2440,16 @@ const _sfc_main = /* @__PURE__ */ defineComponent({
2297
2440
  emits("scroll-x", e);
2298
2441
  }
2299
2442
  }
2300
- function onTrMouseOver(_e, row) {
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];
2301
2448
  if (currentHoverRow === row) return;
2302
2449
  currentHoverRow = row;
2303
- const rowKey = rowKeyGen(row);
2450
+ const rowKey = tr.dataset.rowKey;
2304
2451
  if (props.showTrHoverClass) {
2305
- currentHoverRowKey.value = rowKey;
2452
+ currentHoverRowKey.value = rowKey || null;
2306
2453
  }
2307
2454
  if (props.rowHover) {
2308
2455
  updateHoverMergedCells(rowKey);
@@ -2579,7 +2726,17 @@ const _sfc_main = /* @__PURE__ */ defineComponent({
2579
2726
  class: normalizeClass(["stk-table-main", {
2580
2727
  "fixed-mode": props.fixedMode
2581
2728
  }]),
2582
- 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
2583
2740
  }, [
2584
2741
  !__props.headless ? (openBlock(), createElementBlock("thead", _hoisted_1, [
2585
2742
  (openBlock(true), createElementBlock(Fragment, null, renderList(tableHeaders.value, (row, rowIndex) => {
@@ -2593,31 +2750,14 @@ const _sfc_main = /* @__PURE__ */ defineComponent({
2593
2750
  style: normalizeStyle(`min-width:${unref(virtualScrollX).offsetLeft}px;width:${unref(virtualScrollX).offsetLeft}px`)
2594
2751
  }, null, 4)) : createCommentVNode("", true),
2595
2752
  (openBlock(true), createElementBlock(Fragment, null, renderList(unref(virtualX_on) && rowIndex === tableHeaders.value.length - 1 ? unref(virtualX_columnPart) : row, (col, colIndex) => {
2596
- return openBlock(), createElementBlock("th", {
2597
- key: colKeyGen.value(col),
2598
- "data-col-key": colKeyGen.value(col),
2599
- draggable: unref(isHeaderDraggable)(col) ? "true" : "false",
2600
- rowspan: unref(virtualX_on) ? 1 : col.__R_SP__,
2601
- colspan: col.__C_SP__,
2602
- style: normalizeStyle(cellStyleMap.value[unref(TagType).TH].get(colKeyGen.value(col))),
2603
- title: getHeaderTitle(col),
2604
- class: normalizeClass([
2605
- col.sorter ? "sortable" : "",
2606
- colKeyGen.value(col) === unref(sortCol) && unref(sortOrderIndex) !== 0 && "sorter-" + sortSwitchOrder[unref(sortOrderIndex)],
2607
- col.headerClassName,
2608
- unref(fixedColClassMap).get(colKeyGen.value(col))
2609
- ]),
2610
- onClick: (e) => {
2611
- onColumnSort(col);
2612
- onHeaderCellClick(e, col);
2613
- },
2614
- onDragstart: _cache[0] || (_cache[0] = //@ts-ignore
2615
- (...args) => unref(onThDragStart) && unref(onThDragStart)(...args)),
2616
- onDrop: _cache[1] || (_cache[1] = //@ts-ignore
2617
- (...args) => unref(onThDrop) && unref(onThDrop)(...args)),
2618
- onDragover: _cache[2] || (_cache[2] = //@ts-ignore
2619
- (...args) => unref(onThDragOver) && unref(onThDragOver)(...args))
2620
- }, [
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
+ }), [
2621
2761
  unref(colResizeOn)(col) && colIndex > 0 ? (openBlock(), createElementBlock("div", {
2622
2762
  key: 0,
2623
2763
  class: "table-header-resizer left",
@@ -2625,7 +2765,7 @@ const _sfc_main = /* @__PURE__ */ defineComponent({
2625
2765
  }, null, 40, _hoisted_3)) : createCommentVNode("", true),
2626
2766
  createElementVNode("div", {
2627
2767
  class: "table-header-cell-wrapper",
2628
- style: normalizeStyle({ "--row-span": unref(virtualX_on) ? 1 : col.__R_SP__ })
2768
+ style: normalizeStyle(`--row-span:${unref(virtualX_on) ? 1 : col.__R_SP__}`)
2629
2769
  }, [
2630
2770
  col.customHeaderCell ? (openBlock(), createBlock(resolveDynamicComponent(col.customHeaderCell), {
2631
2771
  key: 0,
@@ -2648,7 +2788,7 @@ const _sfc_main = /* @__PURE__ */ defineComponent({
2648
2788
  class: "table-header-resizer right",
2649
2789
  onMousedown: ($event) => unref(onThResizeMouseDown)($event, col)
2650
2790
  }, null, 40, _hoisted_5)) : createCommentVNode("", true)
2651
- ], 46, _hoisted_2);
2791
+ ], 16, _hoisted_2);
2652
2792
  }), 128)),
2653
2793
  unref(virtualX_on) ? (openBlock(), createElementBlock("th", {
2654
2794
  key: 1,
@@ -2660,12 +2800,9 @@ const _sfc_main = /* @__PURE__ */ defineComponent({
2660
2800
  ])) : createCommentVNode("", true),
2661
2801
  createElementVNode("tbody", {
2662
2802
  class: "stk-tbody-main",
2663
- onDragover: _cache[5] || (_cache[5] = //@ts-ignore
2664
- (...args) => unref(onTrDragOver) && unref(onTrDragOver)(...args)),
2665
- onDragenter: _cache[6] || (_cache[6] = //@ts-ignore
2666
- (...args) => unref(onTrDragEnter) && unref(onTrDragEnter)(...args)),
2667
- onDragend: _cache[7] || (_cache[7] = //@ts-ignore
2668
- (...args) => unref(onTrDragEnd) && unref(onTrDragEnd)(...args))
2803
+ onClick: onCellClick,
2804
+ onMousedown: onCellMouseDown,
2805
+ onMouseover: onCellMouseOver
2669
2806
  }, [
2670
2807
  unref(virtual_on) && !unref(isSRBRActive) ? (openBlock(), createElementBlock("tr", {
2671
2808
  key: 0,
@@ -2681,31 +2818,15 @@ const _sfc_main = /* @__PURE__ */ defineComponent({
2681
2818
  }), 128)) : createCommentVNode("", true)
2682
2819
  ], 4)) : createCommentVNode("", true),
2683
2820
  (openBlock(true), createElementBlock(Fragment, null, renderList(unref(virtual_dataSourcePart), (row, rowIndex) => {
2684
- var _a, _b;
2685
- return openBlock(), createElementBlock("tr", {
2686
- id: unref(stkTableId) + "-" + (__props.rowKey ? rowKeyGen(row) : getRowIndex(rowIndex)),
2821
+ return openBlock(), createElementBlock("tr", mergeProps({
2687
2822
  ref_for: true,
2688
2823
  ref_key: "trRef",
2689
2824
  ref: trRef,
2690
- key: __props.rowKey ? rowKeyGen(row) : getRowIndex(rowIndex),
2691
- "data-row-key": __props.rowKey ? rowKeyGen(row) : getRowIndex(rowIndex),
2692
- class: normalizeClass({
2693
- active: __props.rowKey ? rowKeyGen(row) === currentRowKey.value : row === currentRow.value,
2694
- hover: props.showTrHoverClass && (__props.rowKey ? rowKeyGen(row) === currentHoverRowKey.value : row === currentHoverRowKey.value),
2695
- [__props.rowClassName(row, getRowIndex(rowIndex)) || ""]: true,
2696
- expanded: row && row.__EXP__,
2697
- "expanded-row": row && row.__EXP_R__
2698
- }),
2699
- style: normalizeStyle({
2700
- "--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"
2701
- }),
2702
- onClick: ($event) => onRowClick($event, row, getRowIndex(rowIndex)),
2703
- onDblclick: ($event) => onRowDblclick($event, row, getRowIndex(rowIndex)),
2704
- onContextmenu: ($event) => onRowMenu($event, row, getRowIndex(rowIndex)),
2705
- onMouseover: ($event) => onTrMouseOver($event, row),
2706
- onMouseleave: _cache[4] || (_cache[4] = ($event) => onTrMouseLeave($event)),
2707
- onDrop: ($event) => unref(onTrDrop)($event, getRowIndex(rowIndex))
2708
- }, [
2825
+ key: rowKeyGen(row)
2826
+ }, { ref_for: true }, getTRProps(row, rowIndex), {
2827
+ onDrop: ($event) => unref(onTrDrop)($event, getRowIndex(rowIndex)),
2828
+ onMouseleave: onTrMouseLeave
2829
+ }), [
2709
2830
  unref(virtualX_on) ? (openBlock(), createElementBlock("td", _hoisted_8)) : createCommentVNode("", true),
2710
2831
  row && row.__EXP_R__ ? (openBlock(), createElementBlock("td", {
2711
2832
  key: 1,
@@ -2716,38 +2837,20 @@ const _sfc_main = /* @__PURE__ */ defineComponent({
2716
2837
  row: row.__EXP_R__,
2717
2838
  col: row.__EXP_C__
2718
2839
  }, () => {
2719
- var _a2;
2840
+ var _a;
2720
2841
  return [
2721
- createTextVNode(toDisplayString(((_a2 = row.__EXP_R__) == null ? void 0 : _a2[row.__EXP_C__.dataIndex]) ?? ""), 1)
2842
+ createTextVNode(toDisplayString(((_a = row.__EXP_R__) == null ? void 0 : _a[row.__EXP_C__.dataIndex]) ?? ""), 1)
2722
2843
  ];
2723
2844
  })
2724
2845
  ])
2725
2846
  ], 8, _hoisted_9)) : (openBlock(true), createElementBlock(Fragment, { key: 2 }, renderList(unref(virtualX_columnPart), (col, colIndex) => {
2726
- var _a2;
2847
+ var _a;
2727
2848
  return openBlock(), createElementBlock(Fragment, null, [
2728
- !((_a2 = unref(hiddenCellMap)[rowKeyGen(row)]) == null ? void 0 : _a2.has(colKeyGen.value(col))) ? (openBlock(), createElementBlock("td", mergeProps({
2729
- key: colKeyGen.value(col),
2730
- "data-cell-key": cellKeyGen(row, col),
2731
- style: cellStyleMap.value[unref(TagType).TD].get(colKeyGen.value(col)),
2732
- class: [
2733
- col.className,
2734
- unref(fixedColClassMap).get(colKeyGen.value(col)),
2735
- {
2736
- "cell-hover": col.mergeCells && unref(hoverMergedCells).has(cellKeyGen(row, col)),
2737
- "cell-active": col.mergeCells && unref(activeMergedCells).has(cellKeyGen(row, col)),
2738
- "seq-column": col.type === "seq",
2739
- active: props.cellActive && currentSelectedCellKey.value === cellKeyGen(row, col),
2740
- expanded: col.type === "expand" && (row.__EXP__ ? colKeyGen.value(row.__EXP__) === colKeyGen.value(col) : false),
2741
- "tree-expanded": col.type === "tree-node" && row.__T_EXP__,
2742
- "drag-row-cell": col.type === "dragRow"
2743
- }
2744
- ]
2745
- }, { ref_for: true }, unref(mergeCellsWrapper)(row, col, rowIndex, colIndex), {
2746
- onClick: ($event) => onCellClick($event, row, col, getRowIndex(rowIndex)),
2747
- onMousedown: ($event) => onCellMouseDown($event, row, col, getRowIndex(rowIndex)),
2748
- onMouseenter: ($event) => onCellMouseEnter($event, row, col),
2749
- onMouseleave: ($event) => onCellMouseLeave($event, row, col),
2750
- onMouseover: ($event) => onCellMouseOver($event, row, col)
2849
+ !((_a = unref(hiddenCellMap)[rowKeyGen(row)]) == null ? void 0 : _a.has(colKeyGen.value(col))) ? (openBlock(), createElementBlock("td", mergeProps({
2850
+ key: colKeyGen.value(col)
2851
+ }, { ref_for: true }, getTDProps(row, col, rowIndex, colIndex), {
2852
+ onMouseenter: onCellMouseEnter,
2853
+ onMouseleave: onCellMouseLeave
2751
2854
  }), [
2752
2855
  col.customCell ? (openBlock(), createBlock(resolveDynamicComponent(col.customCell), {
2753
2856
  key: 0,
@@ -2775,7 +2878,7 @@ const _sfc_main = /* @__PURE__ */ defineComponent({
2775
2878
  key: 1,
2776
2879
  class: "table-cell-wrapper",
2777
2880
  title: col.type !== "seq" ? row == null ? void 0 : row[col.dataIndex] : "",
2778
- style: normalizeStyle(col.type === "tree-node" ? { paddingLeft: row.__T_LV__ && row.__T_LV__ * 16 + "px" } : {})
2881
+ style: normalizeStyle(col.type === "tree-node" && row.__T_LV__ ? `padding-left:${row.__T_LV__ * 16}px` : "")
2779
2882
  }, [
2780
2883
  col.type === "seq" ? (openBlock(), createElementBlock(Fragment, { key: 0 }, [
2781
2884
  createTextVNode(toDisplayString((props.seqConfig.startIndex || 0) + getRowIndex(rowIndex) + 1), 1)
@@ -2795,11 +2898,12 @@ const _sfc_main = /* @__PURE__ */ defineComponent({
2795
2898
  ], 64)) : (openBlock(), createElementBlock(Fragment, { key: 3 }, [
2796
2899
  createTextVNode(toDisplayString((row == null ? void 0 : row[col.dataIndex]) ?? getEmptyCellText.value(col, row)), 1)
2797
2900
  ], 64))
2798
- ], 12, _hoisted_12))
2799
- ], 16, _hoisted_11)) : createCommentVNode("", true)
2901
+ ], 12, _hoisted_11))
2902
+ ], 16)) : createCommentVNode("", true)
2800
2903
  ], 64);
2801
- }), 256))
2802
- ], 46, _hoisted_7);
2904
+ }), 256)),
2905
+ unref(virtualX_on) ? (openBlock(), createElementBlock("td", _hoisted_12)) : createCommentVNode("", true)
2906
+ ], 16, _hoisted_7);
2803
2907
  }), 128)),
2804
2908
  unref(virtual_on) && !unref(isSRBRActive) ? (openBlock(), createElementBlock("tr", {
2805
2909
  key: 1,
@@ -2810,13 +2914,13 @@ const _sfc_main = /* @__PURE__ */ defineComponent({
2810
2914
  style: normalizeStyle(`height: ${SRBRBottomHeight.value}px`)
2811
2915
  }, null, 4)) : createCommentVNode("", true)
2812
2916
  ], 32)
2813
- ], 6),
2917
+ ], 38),
2814
2918
  (!dataSourceCopy.value || !dataSourceCopy.value.length) && __props.showNoData ? (openBlock(), createElementBlock("div", {
2815
2919
  key: 2,
2816
2920
  class: normalizeClass(["stk-table-no-data", { "no-data-full": __props.noDataFull }])
2817
2921
  }, [
2818
2922
  renderSlot(_ctx.$slots, "empty", {}, () => [
2819
- _cache[8] || (_cache[8] = createTextVNode("暂无数据", -1))
2923
+ _cache[7] || (_cache[7] = createTextVNode("暂无数据", -1))
2820
2924
  ])
2821
2925
  ], 2)) : createCommentVNode("", true),
2822
2926
  renderSlot(_ctx.$slots, "customBottom")