stk-table-vue 0.6.8 → 0.6.10

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,4 @@
1
- import { openBlock, createElementBlock, createElementVNode, watch, onMounted, onBeforeUnmount, ref, computed, shallowRef, defineComponent, nextTick, toRaw, normalizeClass, unref, normalizeStyle, createCommentVNode, Fragment, renderList, createBlock, resolveDynamicComponent, toDisplayString, renderSlot, createVNode, createTextVNode } from "vue";
1
+ import { createElementBlock, openBlock, createElementVNode, watch, onMounted, onBeforeUnmount, ref, computed, shallowRef, defineComponent, nextTick, toRaw, normalizeStyle, normalizeClass, unref, createCommentVNode, renderSlot, Fragment, renderList, createBlock, resolveDynamicComponent, toDisplayString, createTextVNode, createVNode } from "vue";
2
2
  import { interpolateRgb } from "d3-interpolate";
3
3
  const _export_sfc = (sfc, props) => {
4
4
  const target = sfc.__vccOpts || sfc;
@@ -59,7 +59,7 @@ function insertToOrderedArray(sortState, newItem, targetArray, sortConfig = {})
59
59
  sortConfig = { emptyToBottom: false, ...sortConfig };
60
60
  let { sortType } = sortState;
61
61
  if (!sortType) sortType = typeof newItem[dataIndex];
62
- const data = [...targetArray];
62
+ const data = targetArray.slice();
63
63
  if (!order || !data.length) {
64
64
  data.unshift(newItem);
65
65
  return data;
@@ -125,7 +125,7 @@ function separatedData(sortOption, targetDataSource, isNumber) {
125
125
  function tableSort(sortOption, order, dataSource, sortConfig = {}) {
126
126
  if (!(dataSource == null ? void 0 : dataSource.length) || !sortOption) return dataSource || [];
127
127
  sortConfig = { emptyToBottom: false, ...sortConfig };
128
- let targetDataSource = [...dataSource];
128
+ let targetDataSource = dataSource.slice();
129
129
  let sortField = sortOption.sortField || sortOption.dataIndex;
130
130
  if (!order && sortConfig.defaultSort) {
131
131
  order = sortConfig.defaultSort.order;
@@ -145,9 +145,9 @@ function tableSort(sortOption, order, dataSource, sortConfig = {}) {
145
145
  valueArr.sort((a, b) => strCompare(b[sortField], a[sortField], isNumber, sortConfig.stringLocaleCompare));
146
146
  }
147
147
  if (order === "desc" || sortConfig.emptyToBottom) {
148
- targetDataSource = [...valueArr, ...emptyArr];
148
+ targetDataSource = valueArr.concat(emptyArr);
149
149
  } else {
150
- targetDataSource = [...emptyArr, ...valueArr];
150
+ targetDataSource = emptyArr.concat(valueArr);
151
151
  }
152
152
  }
153
153
  return targetDataSource;
@@ -197,6 +197,7 @@ const IS_LEGACY_MODE = _chromeVersion < 56 || _firefoxVersion < 59;
197
197
  const DEFAULT_SMOOTH_SCROLL = _chromeVersion < 85;
198
198
  const STK_ID_PREFIX = "stk";
199
199
  const EXPANDED_ROW_KEY_PREFIX = "expanded-";
200
+ const CELL_KEY_SEPARATE = "--";
200
201
  var TagType = /* @__PURE__ */ ((TagType2) => {
201
202
  TagType2[TagType2["TH"] = 0] = "TH";
202
203
  TagType2[TagType2["TD"] = 1] = "TD";
@@ -283,7 +284,7 @@ function getColWidth(col) {
283
284
  return parseInt(val);
284
285
  }
285
286
  function getCalculatedColWidth(col) {
286
- return (col == null ? void 0 : col.__WIDTH__) ?? +DEFAULT_COL_WIDTH;
287
+ return (col && col.__WIDTH__) ?? 100;
287
288
  }
288
289
  function createStkTableId() {
289
290
  let id = window.__STK_TB_ID_COUNT__;
@@ -338,7 +339,8 @@ function useColResize({
338
339
  const { left } = tableContainerRef.value.getBoundingClientRect();
339
340
  const tableHeaderLastValue = tableHeaderLast.value;
340
341
  let revertMoveX = false;
341
- const colIndex = tableHeaderLastValue.findIndex((it) => colKeyGen.value(it) === colKeyGen.value(col));
342
+ const colKey = colKeyGen.value;
343
+ const colIndex = tableHeaderLastValue.findIndex((it) => colKey(it) === colKey(col));
342
344
  const fixedIndex = fixedCols.value.indexOf(col);
343
345
  const isFixed = fixedIndex !== -1;
344
346
  if (leftHandle) {
@@ -394,10 +396,11 @@ function useColResize({
394
396
  const moveX = revertMoveX ? startX - clientX : clientX - startX;
395
397
  let width = getCalculatedColWidth(lastCol) + moveX;
396
398
  if (width < props.colMinWidth) width = props.colMinWidth;
397
- const curCol = tableHeaderLast.value.find((it) => colKeyGen.value(it) === colKeyGen.value(lastCol));
399
+ const colKey = colKeyGen.value;
400
+ const curCol = tableHeaderLast.value.find((it) => colKey(it) === colKey(lastCol));
398
401
  if (!curCol) return;
399
402
  curCol.width = width + "px";
400
- emits("update:columns", [...props.columns]);
403
+ emits("update:columns", props.columns.slice());
401
404
  emits("col-resize", { ...curCol });
402
405
  if (colResizeIndicatorRef.value) {
403
406
  const style = colResizeIndicatorRef.value.style;
@@ -441,38 +444,39 @@ function useFixedCol({
441
444
  const fixedColClassMap = computed(() => {
442
445
  const colMap = /* @__PURE__ */ new Map();
443
446
  const fixedShadowColsValue = fixedShadowCols.value;
447
+ const fixedColsValue = fixedCols.value;
448
+ const colKey = colKeyGen.value;
449
+ const fixedColShadow = props.fixedColShadow;
444
450
  tableHeaders.value.forEach((cols) => {
445
451
  cols.forEach((col) => {
446
- const showShadow = props.fixedColShadow && col.fixed && fixedShadowColsValue.includes(col);
452
+ const fixed = col.fixed;
453
+ const showShadow = fixedColShadow && fixed && fixedShadowColsValue.includes(col);
447
454
  const classObj = {
448
- "fixed-cell": col.fixed,
449
- ["fixed-cell--" + col.fixed]: col.fixed,
450
- "fixed-cell--shadow": showShadow,
451
- ["fixed-cell--active"]: fixedCols.value.includes(col)
455
+ "fixed-cell--active": fixedColsValue.includes(col)
452
456
  // 表示该列正在被固定
453
457
  };
454
- colMap.set(colKeyGen.value(col), classObj);
458
+ if (fixed) {
459
+ classObj["fixed-cell"] = true;
460
+ classObj["fixed-cell--" + fixed] = true;
461
+ }
462
+ if (showShadow) {
463
+ classObj["fixed-cell--shadow"] = true;
464
+ }
465
+ colMap.set(colKey(col), classObj);
455
466
  });
456
467
  });
457
468
  return colMap;
458
469
  });
459
470
  function updateFixedShadow(virtualScrollX) {
460
471
  const fixedColsTemp = [];
472
+ const getFixedColPositionValue = getFixedColPosition.value;
461
473
  let clientWidth, scrollLeft;
462
474
  if (virtualScrollX == null ? void 0 : virtualScrollX.value) {
463
- const {
464
- containerWidth: cw,
465
- /* scrollWidth: sw, */
466
- scrollLeft: sl
467
- } = virtualScrollX.value;
475
+ const { containerWidth: cw, scrollLeft: sl } = virtualScrollX.value;
468
476
  clientWidth = cw;
469
477
  scrollLeft = sl;
470
478
  } else {
471
- const {
472
- clientWidth: cw,
473
- /* scrollWidth: sw, */
474
- scrollLeft: sl
475
- } = tableContainerRef.value;
479
+ const { clientWidth: cw, scrollLeft: sl } = tableContainerRef.value;
476
480
  clientWidth = cw;
477
481
  scrollLeft = sl;
478
482
  }
@@ -481,7 +485,7 @@ function useFixedCol({
481
485
  tableHeadersForCalc.value.forEach((row, level) => {
482
486
  let left = 0;
483
487
  row.forEach((col) => {
484
- const position = getFixedColPosition.value(col);
488
+ const position = getFixedColPositionValue(col);
485
489
  const isFixedLeft = col.fixed === "left";
486
490
  const isFixedRight = col.fixed === "right";
487
491
  if (isFixedLeft && position + scrollLeft > left) {
@@ -498,7 +502,7 @@ function useFixedCol({
498
502
  });
499
503
  });
500
504
  if (props.fixedColShadow) {
501
- fixedShadowCols.value = [...leftShadowCol, ...rightShadowCol].filter(Boolean);
505
+ fixedShadowCols.value = leftShadowCol.concat(rightShadowCol).filter(Boolean);
502
506
  }
503
507
  fixedCols.value = fixedColsTemp;
504
508
  }
@@ -524,17 +528,17 @@ function useFixedStyle({
524
528
  const { fixed } = col;
525
529
  if (tagType === TagType.TD && !fixed) return null;
526
530
  const style = {};
531
+ const { headerRowHeight, rowHeight } = props;
527
532
  const isFixedLeft = fixed === "left";
533
+ const { scrollLeft, scrollWidth, offsetLeft, containerWidth } = virtualScrollX.value;
534
+ const scrollRight = scrollWidth - containerWidth - scrollLeft;
528
535
  if (tagType === TagType.TH) {
529
536
  if (isRelativeMode.value) {
530
537
  style.top = virtualScroll.value.scrollTop + "px";
531
538
  } else {
532
- const rowHeight = props.headerRowHeight ?? props.rowHeight;
533
- style.top = depth * rowHeight + "px";
539
+ style.top = depth * (headerRowHeight ?? rowHeight) + "px";
534
540
  }
535
541
  }
536
- const { scrollLeft, scrollWidth, offsetLeft, containerWidth } = virtualScrollX.value;
537
- const scrollRight = scrollWidth - containerWidth - scrollLeft;
538
542
  if (fixed === "left" || fixed === "right") {
539
543
  if (isRelativeMode.value) {
540
544
  if (isFixedLeft) {
@@ -559,13 +563,14 @@ function useGetFixedColPosition({ tableHeadersForCalc, colKeyGen }) {
559
563
  const getFixedColPosition = computed(() => {
560
564
  const colKeyStore = {};
561
565
  const refStore = /* @__PURE__ */ new WeakMap();
566
+ const colKeyGenValue = colKeyGen.value;
562
567
  tableHeadersForCalc.value.forEach((cols) => {
563
568
  let left = 0;
564
569
  let rightStartIndex = 0;
565
570
  for (let i = 0; i < cols.length; i++) {
566
571
  const item = cols[i];
567
572
  if (item.fixed === "left") {
568
- const colKey = colKeyGen.value(item);
573
+ const colKey = colKeyGenValue(item);
569
574
  if (colKey) {
570
575
  colKeyStore[colKey] = left;
571
576
  } else {
@@ -580,7 +585,7 @@ function useGetFixedColPosition({ tableHeadersForCalc, colKeyGen }) {
580
585
  let right = 0;
581
586
  for (let i = cols.length - 1; i >= rightStartIndex; i--) {
582
587
  const item = cols[i];
583
- const colKey = colKeyGen.value(item);
588
+ const colKey = colKeyGenValue(item);
584
589
  if (item.fixed === "right") {
585
590
  if (colKey) {
586
591
  colKeyStore[colKey] = right;
@@ -592,7 +597,7 @@ function useGetFixedColPosition({ tableHeadersForCalc, colKeyGen }) {
592
597
  }
593
598
  });
594
599
  return (col) => {
595
- const colKey = colKeyGen.value(col);
600
+ const colKey = colKeyGenValue(col);
596
601
  return colKey ? colKeyStore[colKey] : refStore.get(col) || 0;
597
602
  };
598
603
  });
@@ -919,7 +924,7 @@ function useThDrag({ props, emits, colKeyGen }) {
919
924
  function handleColOrderChange(dragStartKey, dragEndKey) {
920
925
  if (isEmptyValue(dragStartKey) || isEmptyValue(dragEndKey)) return;
921
926
  if (dragConfig.value.mode !== "none") {
922
- const columns = [...props.columns];
927
+ const columns = props.columns.slice();
923
928
  const dragStartIndex = columns.findIndex((col) => colKeyGen.value(col) === dragStartKey);
924
929
  const dragEndIndex = columns.findIndex((col) => colKeyGen.value(col) === dragEndKey);
925
930
  if (dragStartIndex === -1 || dragEndIndex === -1) return;
@@ -1014,7 +1019,7 @@ function useTrDrag({ props, emits, dataSourceCopy }) {
1014
1019
  const endIndex = rowIndex;
1015
1020
  if (sourceIndex === endIndex) return;
1016
1021
  if (mode !== "none") {
1017
- const dataSourceTemp = [...dataSourceCopy.value];
1022
+ const dataSourceTemp = dataSourceCopy.value.slice();
1018
1023
  const sourceRow = dataSourceTemp[sourceIndex];
1019
1024
  if (mode === "swap") {
1020
1025
  dataSourceTemp[sourceIndex] = dataSourceTemp[endIndex];
@@ -1023,7 +1028,7 @@ function useTrDrag({ props, emits, dataSourceCopy }) {
1023
1028
  dataSourceTemp.splice(sourceIndex, 1);
1024
1029
  dataSourceTemp.splice(endIndex, 0, sourceRow);
1025
1030
  }
1026
- dataSourceCopy.value = [...dataSourceTemp];
1031
+ dataSourceCopy.value = dataSourceTemp;
1027
1032
  }
1028
1033
  emits("row-order-change", sourceIndex, endIndex);
1029
1034
  }
@@ -1157,25 +1162,25 @@ function useVirtualScroll({
1157
1162
  }
1158
1163
  let vue2ScrollYTimeout = null;
1159
1164
  const autoRowHeightMap = /* @__PURE__ */ new Map();
1160
- const setAutoHeight = (rowKey, height) => {
1165
+ function setAutoHeight(rowKey, height) {
1161
1166
  if (!height) {
1162
1167
  autoRowHeightMap.delete(rowKey);
1163
1168
  } else {
1164
1169
  autoRowHeightMap.set(rowKey, height);
1165
1170
  }
1166
- };
1167
- const clearAllAutoHeight = () => {
1171
+ }
1172
+ function clearAllAutoHeight() {
1168
1173
  autoRowHeightMap.clear();
1169
- };
1170
- const getAutoRowHeight = (row) => {
1174
+ }
1175
+ function getAutoRowHeight(row) {
1171
1176
  var _a;
1172
1177
  const rowKey = String(rowKeyGen(row));
1173
1178
  const storedHeight = autoRowHeightMap.get(rowKey);
1174
- let expectedHeight;
1175
1179
  if (storedHeight) {
1176
1180
  return storedHeight;
1177
1181
  }
1178
- if (expectedHeight = (_a = props.autoRowHeight) == null ? void 0 : _a.expectedHeight) {
1182
+ const expectedHeight = (_a = props.autoRowHeight) == null ? void 0 : _a.expectedHeight;
1183
+ if (expectedHeight) {
1179
1184
  if (typeof expectedHeight === "function") {
1180
1185
  return expectedHeight(row);
1181
1186
  } else {
@@ -1183,8 +1188,8 @@ function useVirtualScroll({
1183
1188
  }
1184
1189
  }
1185
1190
  return props.rowHeight || DEFAULT_ROW_HEIGHT;
1186
- };
1187
- const createGetRowHeightFn = () => {
1191
+ }
1192
+ function createGetRowHeightFn() {
1188
1193
  var _a;
1189
1194
  if (props.autoRowHeight) {
1190
1195
  return (row) => getAutoRowHeight(row);
@@ -1195,7 +1200,7 @@ function useVirtualScroll({
1195
1200
  return (row) => row.__EXPANDED_ROW__ ? expandedRowHeight : rowHeight;
1196
1201
  }
1197
1202
  return () => props.rowHeight || DEFAULT_ROW_HEIGHT;
1198
- };
1203
+ }
1199
1204
  function updateVirtualScrollY(sTop = 0) {
1200
1205
  var _a;
1201
1206
  const { rowHeight, pageSize, scrollTop, startIndex: oldStartIndex, endIndex: oldEndIndex } = virtualScroll.value;
@@ -1270,7 +1275,7 @@ function useVirtualScroll({
1270
1275
  const tableHeaderLastValue = tableHeaderLast.value;
1271
1276
  const headerLength = tableHeaderLastValue == null ? void 0 : tableHeaderLastValue.length;
1272
1277
  if (!headerLength) return;
1273
- const { scrollLeft } = virtualScrollX.value;
1278
+ const { scrollLeft, containerWidth } = virtualScrollX.value;
1274
1279
  let startIndex = 0;
1275
1280
  let offsetLeft = 0;
1276
1281
  let colWidthSum = 0;
@@ -1293,12 +1298,12 @@ function useVirtualScroll({
1293
1298
  }
1294
1299
  }
1295
1300
  colWidthSum = leftFirstColRestWidth;
1296
- const containerWidth = virtualScrollX.value.containerWidth - leftColWidthSum;
1301
+ const containerW = containerWidth - leftColWidthSum;
1297
1302
  let endIndex = headerLength;
1298
1303
  for (let colIndex = startIndex + 1; colIndex < headerLength; colIndex++) {
1299
1304
  const col = tableHeaderLastValue[colIndex];
1300
1305
  colWidthSum += getCalculatedColWidth(col);
1301
- if (colWidthSum >= containerWidth) {
1306
+ if (colWidthSum >= containerW) {
1302
1307
  endIndex = colIndex + 1;
1303
1308
  break;
1304
1309
  }
@@ -1335,31 +1340,23 @@ function useVirtualScroll({
1335
1340
  };
1336
1341
  }
1337
1342
  const _hoisted_1 = ["data-col-key", "draggable", "rowspan", "colspan", "title", "onClick"];
1338
- const _hoisted_2 = {
1339
- key: 1,
1340
- class: "table-header-title"
1341
- };
1343
+ const _hoisted_2 = ["onMousedown"];
1342
1344
  const _hoisted_3 = { class: "table-header-title" };
1343
- const _hoisted_4 = {
1344
- key: 3,
1345
- class: "table-header-sorter"
1346
- };
1347
- const _hoisted_5 = ["onMousedown"];
1348
- const _hoisted_6 = ["onMousedown"];
1349
- const _hoisted_7 = {
1345
+ const _hoisted_4 = ["onMousedown"];
1346
+ const _hoisted_5 = {
1350
1347
  key: 0,
1351
1348
  class: "vt-x-left"
1352
1349
  };
1353
- const _hoisted_8 = ["id", "data-row-key", "onClick", "onDblclick", "onContextmenu", "onMouseover", "onDrop"];
1354
- const _hoisted_9 = {
1350
+ const _hoisted_6 = ["id", "data-row-key", "onClick", "onDblclick", "onContextmenu", "onMouseover", "onDrop"];
1351
+ const _hoisted_7 = {
1355
1352
  key: 0,
1356
1353
  class: "vt-x-left"
1357
1354
  };
1358
- const _hoisted_10 = ["colspan"];
1359
- const _hoisted_11 = { class: "table-cell-wrapper" };
1360
- const _hoisted_12 = ["data-cell-key", "onClick", "onMouseenter", "onMouseleave", "onMouseover"];
1361
- const _hoisted_13 = ["title"];
1362
- const _hoisted_14 = { key: 1 };
1355
+ const _hoisted_8 = ["colspan"];
1356
+ const _hoisted_9 = { class: "table-cell-wrapper" };
1357
+ const _hoisted_10 = ["data-cell-key", "onClick", "onMousedown", "onMouseenter", "onMouseleave", "onMouseover"];
1358
+ const _hoisted_11 = ["title"];
1359
+ const _hoisted_12 = { key: 1 };
1363
1360
  const _sfc_main = /* @__PURE__ */ defineComponent({
1364
1361
  __name: "StkTable",
1365
1362
  props: {
@@ -1410,9 +1407,10 @@ const _sfc_main = /* @__PURE__ */ defineComponent({
1410
1407
  expandConfig: { default: () => ({}) },
1411
1408
  dragRowConfig: { default: () => ({}) },
1412
1409
  cellFixedMode: { default: "sticky" },
1413
- smoothScroll: { type: Boolean, default: DEFAULT_SMOOTH_SCROLL }
1410
+ smoothScroll: { type: Boolean, default: DEFAULT_SMOOTH_SCROLL },
1411
+ scrollRowByRow: { type: Boolean, default: false }
1414
1412
  },
1415
- emits: ["sort-change", "row-click", "current-change", "cell-selected", "row-dblclick", "header-row-menu", "row-menu", "cell-click", "cell-mouseenter", "cell-mouseleave", "cell-mouseover", "header-cell-click", "scroll", "scroll-x", "col-order-change", "th-drag-start", "th-drop", "row-order-change", "col-resize", "toggle-row-expand", "update:columns"],
1413
+ emits: ["sort-change", "row-click", "current-change", "cell-selected", "row-dblclick", "header-row-menu", "row-menu", "cell-click", "cell-mouseenter", "cell-mouseleave", "cell-mouseover", "cell-mousedown", "header-cell-click", "scroll", "scroll-x", "col-order-change", "th-drag-start", "th-drop", "row-order-change", "col-resize", "toggle-row-expand", "update:columns"],
1416
1414
  setup(__props, { expose: __expose, emit: __emit }) {
1417
1415
  const stkTableId = createStkTableId();
1418
1416
  const props = __props;
@@ -1431,21 +1429,31 @@ const _sfc_main = /* @__PURE__ */ defineComponent({
1431
1429
  let sortOrderIndex = ref(0);
1432
1430
  const sortSwitchOrder = [null, "desc", "asc"];
1433
1431
  const tableHeaders = shallowRef([]);
1434
- const tableHeaderLast = shallowRef([]);
1435
1432
  const tableHeadersForCalc = shallowRef([]);
1436
- const dataSourceCopy = shallowRef([...props.dataSource]);
1433
+ const tableHeaderLast = computed(() => tableHeadersForCalc.value.at(-1) || []);
1434
+ const dataSourceCopy = shallowRef(props.dataSource.slice());
1435
+ const rowKeyGenComputed = computed(() => {
1436
+ const { rowKey } = props;
1437
+ if (typeof rowKey === "function") {
1438
+ return (row) => rowKey(row);
1439
+ } else {
1440
+ return (row) => row[rowKey];
1441
+ }
1442
+ });
1437
1443
  const colKeyGen = computed(() => {
1438
- if (typeof props.colKey === "function") {
1439
- return (col) => props.colKey(col);
1444
+ const { colKey } = props;
1445
+ if (typeof colKey === "function") {
1446
+ return (col) => colKey(col);
1440
1447
  } else {
1441
- return (col) => col ? col[props.colKey] : null;
1448
+ return (col) => col[colKey];
1442
1449
  }
1443
1450
  });
1444
1451
  const getEmptyCellText = computed(() => {
1445
- if (typeof props.emptyCellText === "string") {
1446
- return () => props.emptyCellText;
1452
+ const { emptyCellText } = props;
1453
+ if (typeof emptyCellText === "string") {
1454
+ return () => emptyCellText;
1447
1455
  } else {
1448
- return (col, row) => props.emptyCellText({ row, col });
1456
+ return (col, row) => emptyCellText({ row, col });
1449
1457
  }
1450
1458
  });
1451
1459
  const rowKeyGenStore = /* @__PURE__ */ new WeakMap();
@@ -1546,17 +1554,16 @@ const _sfc_main = /* @__PURE__ */ defineComponent({
1546
1554
  if (dataSourceCopy.value.length !== val.length) {
1547
1555
  needInitVirtualScrollY = true;
1548
1556
  }
1549
- dataSourceCopy.value = [...val];
1557
+ dataSourceCopy.value = val.slice();
1550
1558
  if (needInitVirtualScrollY) {
1551
1559
  nextTick(() => initVirtualScrollY());
1552
1560
  }
1553
- if (sortCol.value) {
1554
- const column = tableHeaderLast.value.find((it) => colKeyGen.value(it) === sortCol.value);
1561
+ const sortColValue = sortCol.value;
1562
+ if (sortColValue) {
1563
+ const colKey = colKeyGen.value;
1564
+ const column = tableHeaderLast.value.find((it) => colKey(it) === sortColValue);
1555
1565
  onColumnSort(column, false);
1556
1566
  }
1557
- },
1558
- {
1559
- deep: false
1560
1567
  }
1561
1568
  );
1562
1569
  watch(
@@ -1591,12 +1598,11 @@ const _sfc_main = /* @__PURE__ */ defineComponent({
1591
1598
  centerCol.push(col);
1592
1599
  }
1593
1600
  });
1594
- copyColumn = [...leftCol, ...centerCol, ...rightCol];
1601
+ copyColumn = leftCol.concat(centerCol).concat(rightCol);
1595
1602
  }
1596
1603
  const maxDeep = howDeepTheHeader(copyColumn);
1597
- const tempHeaderLast = [];
1598
1604
  if (maxDeep > 0 && props.virtualX) {
1599
- console.error("多级表头不支持横向虚拟滚动");
1605
+ console.error("StkTableVue:多级表头不支持横向虚拟滚动!");
1600
1606
  }
1601
1607
  for (let i = 0; i <= maxDeep; i++) {
1602
1608
  tableHeadersTemp[i] = [];
@@ -1621,7 +1627,6 @@ const _sfc_main = /* @__PURE__ */ defineComponent({
1621
1627
  tableHeadersForCalcTemp[depth].push(col);
1622
1628
  } else {
1623
1629
  colWidth = getColWidth(col);
1624
- tempHeaderLast.push(col);
1625
1630
  for (let i = depth; i <= maxDeep; i++) {
1626
1631
  tableHeadersForCalcTemp[i].push(col);
1627
1632
  }
@@ -1643,18 +1648,13 @@ const _sfc_main = /* @__PURE__ */ defineComponent({
1643
1648
  }
1644
1649
  flat(copyColumn, null);
1645
1650
  tableHeaders.value = tableHeadersTemp;
1646
- tableHeaderLast.value = tempHeaderLast;
1647
1651
  tableHeadersForCalc.value = tableHeadersForCalcTemp;
1648
1652
  }
1649
1653
  function rowKeyGen(row) {
1650
1654
  if (!row) return row;
1651
- let key = rowKeyGenStore.get(row);
1655
+ let key = rowKeyGenStore.get(row) || row.__ROW_KEY__;
1652
1656
  if (!key) {
1653
- if (row.__ROW_KEY__) {
1654
- key = row.__ROW_KEY__;
1655
- } else {
1656
- key = typeof props.rowKey === "function" ? props.rowKey(row) : row[props.rowKey];
1657
- }
1657
+ key = rowKeyGenComputed.value(row);
1658
1658
  if (key === void 0) {
1659
1659
  key = Math.random().toString();
1660
1660
  }
@@ -1663,35 +1663,28 @@ const _sfc_main = /* @__PURE__ */ defineComponent({
1663
1663
  return key;
1664
1664
  }
1665
1665
  function cellKeyGen(row, col) {
1666
- return rowKeyGen(row) + "--" + colKeyGen.value(col);
1666
+ return rowKeyGen(row) + CELL_KEY_SEPARATE + colKeyGen.value(col);
1667
1667
  }
1668
1668
  const cellStyleMap = computed(() => {
1669
1669
  const thMap = /* @__PURE__ */ new Map();
1670
1670
  const tdMap = /* @__PURE__ */ new Map();
1671
+ const { virtualX, colResizable } = props;
1671
1672
  tableHeaders.value.forEach((cols, depth) => {
1672
1673
  cols.forEach((col) => {
1673
1674
  const colKey = colKeyGen.value(col);
1674
- const width = props.virtualX ? getCalculatedColWidth(col) + "px" : transformWidthToStr(col.width);
1675
+ const width = virtualX ? getCalculatedColWidth(col) + "px" : transformWidthToStr(col.width);
1675
1676
  const style = {
1676
1677
  width
1677
1678
  };
1678
- if (props.colResizable) {
1679
+ if (colResizable) {
1679
1680
  style.minWidth = width;
1680
1681
  style.maxWidth = width;
1681
1682
  } else {
1682
1683
  style.minWidth = transformWidthToStr(col.minWidth) ?? width;
1683
1684
  style.maxWidth = transformWidthToStr(col.maxWidth) ?? width;
1684
1685
  }
1685
- thMap.set(colKey, {
1686
- ...style,
1687
- ...getFixedStyle(TagType.TH, col, depth),
1688
- textAlign: col.headerAlign
1689
- });
1690
- tdMap.set(colKey, {
1691
- ...style,
1692
- ...getFixedStyle(TagType.TD, col, depth),
1693
- textAlign: col.align
1694
- });
1686
+ thMap.set(colKey, Object.assign({ textAlign: col.headerAlign }, style, getFixedStyle(TagType.TH, col, depth)));
1687
+ tdMap.set(colKey, Object.assign({ textAlign: col.align }, style, getFixedStyle(TagType.TD, col, depth), { textAlign: col.align }));
1695
1688
  });
1696
1689
  });
1697
1690
  return {
@@ -1708,7 +1701,7 @@ const _sfc_main = /* @__PURE__ */ defineComponent({
1708
1701
  }
1709
1702
  function onColumnSort(col, click = true, options = {}) {
1710
1703
  if (!col) {
1711
- console.warn("onColumnSort: col is not found");
1704
+ console.warn("onColumnSort: not found col:", col);
1712
1705
  return;
1713
1706
  }
1714
1707
  if (!col.sorter && click) {
@@ -1725,6 +1718,7 @@ const _sfc_main = /* @__PURE__ */ defineComponent({
1725
1718
  let order = sortSwitchOrder[sortOrderIndex.value];
1726
1719
  const sortConfig = { ...props.sortConfig, ...col.sortConfig };
1727
1720
  const defaultSort = sortConfig.defaultSort;
1721
+ const colKeyGenValue = colKeyGen.value;
1728
1722
  if (!order && defaultSort) {
1729
1723
  const colKey2 = defaultSort.key || defaultSort.dataIndex;
1730
1724
  if (!colKey2) {
@@ -1736,7 +1730,7 @@ const _sfc_main = /* @__PURE__ */ defineComponent({
1736
1730
  sortCol.value = colKey2;
1737
1731
  col = null;
1738
1732
  for (const row of tableHeaders.value) {
1739
- const c = row.find((item) => colKeyGen.value(item) === colKey2);
1733
+ const c = row.find((item) => colKeyGenValue(item) === colKey2);
1740
1734
  if (c) {
1741
1735
  col = c;
1742
1736
  break;
@@ -1762,12 +1756,11 @@ const _sfc_main = /* @__PURE__ */ defineComponent({
1762
1756
  }
1763
1757
  currentRow.value = void 0;
1764
1758
  currentRowKey.value = void 0;
1765
- emits("current-change", e, row, { select: false });
1766
1759
  } else {
1767
1760
  currentRow.value = row;
1768
1761
  currentRowKey.value = rowKeyGen(row);
1769
- emits("current-change", e, row, { select: true });
1770
1762
  }
1763
+ emits("current-change", e, row, { select: !isCurrentRow });
1771
1764
  }
1772
1765
  function onRowDblclick(e, row) {
1773
1766
  emits("row-dblclick", e, row);
@@ -1779,15 +1772,19 @@ const _sfc_main = /* @__PURE__ */ defineComponent({
1779
1772
  emits("row-menu", e, row);
1780
1773
  }
1781
1774
  function onCellClick(e, row, col) {
1775
+ if (col.type === "expand") {
1776
+ toggleExpandRow(row, col);
1777
+ }
1782
1778
  if (props.cellActive) {
1783
1779
  const cellKey = cellKeyGen(row, col);
1780
+ const result = { row, col, select: false };
1784
1781
  if (props.selectedCellRevokable && currentSelectedCellKey.value === cellKey) {
1785
1782
  currentSelectedCellKey.value = void 0;
1786
- emits("cell-selected", e, { select: false, row, col });
1787
1783
  } else {
1788
1784
  currentSelectedCellKey.value = cellKey;
1789
- emits("cell-selected", e, { select: true, row, col });
1785
+ result.select = true;
1790
1786
  }
1787
+ emits("cell-selected", e, result);
1791
1788
  }
1792
1789
  emits("cell-click", e, row, col);
1793
1790
  }
@@ -1803,6 +1800,9 @@ const _sfc_main = /* @__PURE__ */ defineComponent({
1803
1800
  function onCellMouseOver(e, row, col) {
1804
1801
  emits("cell-mouseover", e, row, col);
1805
1802
  }
1803
+ function onCellMouseDown(e, row, col) {
1804
+ emits("cell-mousedown", e, row, col);
1805
+ }
1806
1806
  function onTableWheel(e) {
1807
1807
  if (props.smoothScroll) {
1808
1808
  return;
@@ -1834,7 +1834,7 @@ const _sfc_main = /* @__PURE__ */ defineComponent({
1834
1834
  function onTableScroll(e) {
1835
1835
  if (!(e == null ? void 0 : e.target)) return;
1836
1836
  const { scrollTop, scrollLeft } = e.target;
1837
- const { scrollTop: vScrollTop } = virtualScroll.value;
1837
+ const { scrollTop: vScrollTop, startIndex, endIndex } = virtualScroll.value;
1838
1838
  const { scrollLeft: vScrollLeft } = virtualScrollX.value;
1839
1839
  const isYScroll = scrollTop !== vScrollTop;
1840
1840
  const isXScroll = scrollLeft !== vScrollLeft;
@@ -1849,10 +1849,8 @@ const _sfc_main = /* @__PURE__ */ defineComponent({
1849
1849
  }
1850
1850
  updateFixedShadow(virtualScrollX);
1851
1851
  }
1852
- const { startIndex, endIndex } = virtualScroll.value;
1853
- const data = { startIndex, endIndex };
1854
1852
  if (isYScroll) {
1855
- emits("scroll", e, data);
1853
+ emits("scroll", e, { startIndex, endIndex });
1856
1854
  }
1857
1855
  if (isXScroll) {
1858
1856
  emits("scroll-x", e);
@@ -1909,8 +1907,9 @@ const _sfc_main = /* @__PURE__ */ defineComponent({
1909
1907
  const newOption = { silent: true, sortOption: null, sort: true, ...option };
1910
1908
  sortCol.value = colKey;
1911
1909
  sortOrderIndex.value = sortSwitchOrder.indexOf(order);
1910
+ const colKeyGenValue = colKeyGen.value;
1912
1911
  if (newOption.sort && ((_a = dataSourceCopy.value) == null ? void 0 : _a.length)) {
1913
- const column = newOption.sortOption || tableHeaderLast.value.find((it) => colKeyGen.value(it) === sortCol.value);
1912
+ const column = newOption.sortOption || tableHeaderLast.value.find((it) => colKeyGenValue(it) === sortCol.value);
1914
1913
  if (column) onColumnSort(column, false, { force: option.force ?? true, emit: !newOption.silent });
1915
1914
  else console.warn("Can not find column by key:", sortCol.value);
1916
1915
  }
@@ -1919,7 +1918,7 @@ const _sfc_main = /* @__PURE__ */ defineComponent({
1919
1918
  function resetSorter() {
1920
1919
  sortCol.value = void 0;
1921
1920
  sortOrderIndex.value = 0;
1922
- dataSourceCopy.value = [...props.dataSource];
1921
+ dataSourceCopy.value = props.dataSource.slice();
1923
1922
  }
1924
1923
  function scrollTo(top = 0, left = 0) {
1925
1924
  if (!tableContainerRef.value) return;
@@ -1945,7 +1944,7 @@ const _sfc_main = /* @__PURE__ */ defineComponent({
1945
1944
  } else {
1946
1945
  rowKey = rowKeyGen(rowKeyOrRow);
1947
1946
  }
1948
- const tempData = [...dataSourceCopy.value];
1947
+ const tempData = dataSourceCopy.value.slice();
1949
1948
  const index = tempData.findIndex((it) => rowKeyGen(it) === rowKey);
1950
1949
  if (index === -1) {
1951
1950
  console.warn("expandRow failed.rowKey:", rowKey);
@@ -2116,7 +2115,8 @@ const _sfc_main = /* @__PURE__ */ defineComponent({
2116
2115
  "text-overflow": props.showOverflow,
2117
2116
  "header-text-overflow": props.showHeaderOverflow,
2118
2117
  "fixed-relative-mode": isRelativeMode.value,
2119
- "auto-row-height": props.autoRowHeight
2118
+ "auto-row-height": props.autoRowHeight,
2119
+ "scroll-row-by-row": props.scrollRowByRow
2120
2120
  }]),
2121
2121
  style: normalizeStyle({
2122
2122
  "--row-height": props.autoRowHeight ? void 0 : unref(virtualScroll).rowHeight + "px",
@@ -2127,8 +2127,13 @@ const _sfc_main = /* @__PURE__ */ defineComponent({
2127
2127
  onScroll: onTableScroll,
2128
2128
  onWheel: onTableWheel
2129
2129
  }, [
2130
- _ctx.colResizable ? (openBlock(), createElementBlock("div", {
2130
+ props.scrollRowByRow && _ctx.virtual ? (openBlock(), createElementBlock("div", {
2131
2131
  key: 0,
2132
+ class: "row-by-row-table-height",
2133
+ style: normalizeStyle({ height: dataSourceCopy.value.length * unref(virtualScroll).rowHeight + "px" })
2134
+ }, null, 4)) : createCommentVNode("", true),
2135
+ _ctx.colResizable ? (openBlock(), createElementBlock("div", {
2136
+ key: 1,
2132
2137
  ref_key: "colResizeIndicatorRef",
2133
2138
  ref: colResizeIndicatorRef,
2134
2139
  class: "column-resize-indicator"
@@ -2180,6 +2185,11 @@ const _sfc_main = /* @__PURE__ */ defineComponent({
2180
2185
  onDragover: _cache[2] || (_cache[2] = //@ts-ignore
2181
2186
  (...args) => unref(onThDragOver) && unref(onThDragOver)(...args))
2182
2187
  }, [
2188
+ unref(colResizeOn)(col) && colIndex > 0 ? (openBlock(), createElementBlock("div", {
2189
+ key: 0,
2190
+ class: "table-header-resizer left",
2191
+ onMousedown: (e) => unref(onThResizeMouseDown)(e, col, true)
2192
+ }, null, 40, _hoisted_2)) : createCommentVNode("", true),
2183
2193
  createElementVNode("div", {
2184
2194
  class: "table-header-cell-wrapper",
2185
2195
  style: normalizeStyle({ "--row-span": unref(virtualX_on) ? 1 : col.rowSpan })
@@ -2189,26 +2199,22 @@ const _sfc_main = /* @__PURE__ */ defineComponent({
2189
2199
  col,
2190
2200
  colIndex,
2191
2201
  rowIndex
2192
- }, null, 8, ["col", "colIndex", "rowIndex"])) : col.type === "seq" ? (openBlock(), createElementBlock("span", _hoisted_2, toDisplayString(col.title), 1)) : renderSlot(_ctx.$slots, "tableHeader", {
2193
- key: 2,
2202
+ }, null, 8, ["col", "colIndex", "rowIndex"])) : renderSlot(_ctx.$slots, "tableHeader", {
2203
+ key: 1,
2194
2204
  col
2195
2205
  }, () => [
2196
2206
  createElementVNode("span", _hoisted_3, toDisplayString(col.title), 1)
2197
2207
  ]),
2198
- col.sorter ? (openBlock(), createElementBlock("span", _hoisted_4, [
2199
- createVNode(SortIcon)
2200
- ])) : createCommentVNode("", true),
2201
- unref(colResizeOn)(col) && colIndex > 0 ? (openBlock(), createElementBlock("div", {
2202
- key: 4,
2203
- class: "table-header-resizer left",
2204
- onMousedown: (e) => unref(onThResizeMouseDown)(e, col, true)
2205
- }, null, 40, _hoisted_5)) : createCommentVNode("", true),
2206
- unref(colResizeOn)(col) ? (openBlock(), createElementBlock("div", {
2207
- key: 5,
2208
- class: "table-header-resizer right",
2209
- onMousedown: (e) => unref(onThResizeMouseDown)(e, col)
2210
- }, null, 40, _hoisted_6)) : createCommentVNode("", true)
2211
- ], 4)
2208
+ col.sorter ? (openBlock(), createBlock(SortIcon, {
2209
+ key: 2,
2210
+ class: "table-header-sorter"
2211
+ })) : createCommentVNode("", true)
2212
+ ], 4),
2213
+ unref(colResizeOn)(col) ? (openBlock(), createElementBlock("div", {
2214
+ key: 1,
2215
+ class: "table-header-resizer right",
2216
+ onMousedown: (e) => unref(onThResizeMouseDown)(e, col)
2217
+ }, null, 40, _hoisted_4)) : createCommentVNode("", true)
2212
2218
  ], 46, _hoisted_1);
2213
2219
  }), 128)),
2214
2220
  unref(virtualX_on) ? (openBlock(), createElementBlock("th", {
@@ -2228,12 +2234,12 @@ const _sfc_main = /* @__PURE__ */ defineComponent({
2228
2234
  onDragend: _cache[6] || (_cache[6] = //@ts-ignore
2229
2235
  (...args) => unref(onTrDragEnd) && unref(onTrDragEnd)(...args))
2230
2236
  }, [
2231
- unref(virtual_on) ? (openBlock(), createElementBlock("tr", {
2237
+ unref(virtual_on) && !props.scrollRowByRow ? (openBlock(), createElementBlock("tr", {
2232
2238
  key: 0,
2233
2239
  style: normalizeStyle(`height:${unref(virtualScroll).offsetTop}px`),
2234
2240
  class: "padding-top-tr"
2235
2241
  }, [
2236
- unref(virtualX_on) && _ctx.fixedMode && _ctx.headless ? (openBlock(), createElementBlock("td", _hoisted_7)) : createCommentVNode("", true),
2242
+ unref(virtualX_on) && _ctx.fixedMode && _ctx.headless ? (openBlock(), createElementBlock("td", _hoisted_5)) : createCommentVNode("", true),
2237
2243
  _ctx.fixedMode && _ctx.headless ? (openBlock(true), createElementBlock(Fragment, { key: 1 }, renderList(unref(virtualX_columnPart), (col) => {
2238
2244
  return openBlock(), createElementBlock("td", {
2239
2245
  key: colKeyGen.value(col),
@@ -2266,12 +2272,12 @@ const _sfc_main = /* @__PURE__ */ defineComponent({
2266
2272
  onMouseover: (e) => onTrMouseOver(e, row),
2267
2273
  onDrop: (e) => unref(onTrDrop)(e, (unref(virtual_on) ? unref(virtualScroll).startIndex : 0) + rowIndex)
2268
2274
  }, [
2269
- unref(virtualX_on) ? (openBlock(), createElementBlock("td", _hoisted_9)) : createCommentVNode("", true),
2275
+ unref(virtualX_on) ? (openBlock(), createElementBlock("td", _hoisted_7)) : createCommentVNode("", true),
2270
2276
  row && row.__EXPANDED_ROW__ ? (openBlock(), createElementBlock("td", {
2271
2277
  key: 1,
2272
2278
  colspan: unref(virtualX_columnPart).length
2273
2279
  }, [
2274
- createElementVNode("div", _hoisted_11, [
2280
+ createElementVNode("div", _hoisted_9, [
2275
2281
  renderSlot(_ctx.$slots, "expand", {
2276
2282
  row: row.__EXPANDED_ROW__,
2277
2283
  col: row.__EXPANDED_COL__
@@ -2282,7 +2288,7 @@ const _sfc_main = /* @__PURE__ */ defineComponent({
2282
2288
  ];
2283
2289
  })
2284
2290
  ])
2285
- ], 8, _hoisted_10)) : (openBlock(true), createElementBlock(Fragment, { key: 2 }, renderList(unref(virtualX_columnPart), (col, colIndex) => {
2291
+ ], 8, _hoisted_8)) : (openBlock(true), createElementBlock(Fragment, { key: 2 }, renderList(unref(virtualX_columnPart), (col, colIndex) => {
2286
2292
  return openBlock(), createElementBlock("td", {
2287
2293
  key: colKeyGen.value(col),
2288
2294
  "data-cell-key": cellKeyGen(row, col),
@@ -2298,10 +2304,8 @@ const _sfc_main = /* @__PURE__ */ defineComponent({
2298
2304
  "drag-row-cell": col.type === "dragRow"
2299
2305
  }
2300
2306
  ]),
2301
- onClick: (e) => {
2302
- col.type === "expand" && toggleExpandRow(row, col);
2303
- onCellClick(e, row, col);
2304
- },
2307
+ onClick: (e) => onCellClick(e, row, col),
2308
+ onMousedown: (e) => onCellMouseDown(e, row, col),
2305
2309
  onMouseenter: (e) => onCellMouseEnter(e, row, col),
2306
2310
  onMouseleave: (e) => onCellMouseLeave(e, row, col),
2307
2311
  onMouseover: (e) => onCellMouseOver(e, row, col)
@@ -2322,7 +2326,7 @@ const _sfc_main = /* @__PURE__ */ defineComponent({
2322
2326
  }, [
2323
2327
  col.type === "seq" ? (openBlock(), createElementBlock(Fragment, { key: 0 }, [
2324
2328
  createTextVNode(toDisplayString((props.seqConfig.startIndex || 0) + (unref(virtual_on) ? unref(virtualScroll).startIndex : 0) + rowIndex + 1), 1)
2325
- ], 64)) : col.type === "expand" ? (openBlock(), createElementBlock("span", _hoisted_14, toDisplayString((row == null ? void 0 : row[col.dataIndex]) ?? ""), 1)) : col.type === "dragRow" ? (openBlock(), createElementBlock(Fragment, { key: 2 }, [
2329
+ ], 64)) : col.type === "expand" ? (openBlock(), createElementBlock("span", _hoisted_12, toDisplayString((row == null ? void 0 : row[col.dataIndex]) ?? ""), 1)) : col.type === "dragRow" ? (openBlock(), createElementBlock(Fragment, { key: 2 }, [
2326
2330
  createVNode(DragHandle, {
2327
2331
  onDragstart: (e) => unref(onTrDragStart)(e, (unref(virtual_on) ? unref(virtualScroll).startIndex : 0) + rowIndex)
2328
2332
  }, null, 8, ["onDragstart"]),
@@ -2330,19 +2334,19 @@ const _sfc_main = /* @__PURE__ */ defineComponent({
2330
2334
  ], 64)) : (openBlock(), createElementBlock(Fragment, { key: 3 }, [
2331
2335
  createTextVNode(toDisplayString((row == null ? void 0 : row[col.dataIndex]) ?? getEmptyCellText.value(col, row)), 1)
2332
2336
  ], 64))
2333
- ], 10, _hoisted_13))
2334
- ], 46, _hoisted_12);
2337
+ ], 10, _hoisted_11))
2338
+ ], 46, _hoisted_10);
2335
2339
  }), 128))
2336
- ], 46, _hoisted_8);
2340
+ ], 46, _hoisted_6);
2337
2341
  }), 128)),
2338
- unref(virtual_on) ? (openBlock(), createElementBlock("tr", {
2342
+ unref(virtual_on) && !props.scrollRowByRow ? (openBlock(), createElementBlock("tr", {
2339
2343
  key: 1,
2340
2344
  style: normalizeStyle(`height: ${unref(virtual_offsetBottom)}px`)
2341
2345
  }, null, 4)) : createCommentVNode("", true)
2342
2346
  ], 32)
2343
2347
  ], 6),
2344
2348
  (!dataSourceCopy.value || !dataSourceCopy.value.length) && _ctx.showNoData ? (openBlock(), createElementBlock("div", {
2345
- key: 1,
2349
+ key: 2,
2346
2350
  class: normalizeClass(["stk-table-no-data", { "no-data-full": _ctx.noDataFull }])
2347
2351
  }, [
2348
2352
  renderSlot(_ctx.$slots, "empty", {}, () => [