stk-table-vue 0.6.12 → 0.6.14

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1061,7 +1061,7 @@ function useVirtualScroll({
1061
1061
  const virtualScroll = ref({
1062
1062
  containerHeight: 0,
1063
1063
  rowHeight: props.rowHeight,
1064
- pageSize: 10,
1064
+ pageSize: 0,
1065
1065
  startIndex: 0,
1066
1066
  endIndex: 0,
1067
1067
  offsetTop: 0,
@@ -1080,7 +1080,7 @@ function useVirtualScroll({
1080
1080
  return tableHeaderLast.value.some((col) => col.type === "expand");
1081
1081
  });
1082
1082
  const virtual_on = computed(() => {
1083
- return props.virtual && dataSourceCopy.value.length > virtualScroll.value.pageSize * 2;
1083
+ return props.virtual && dataSourceCopy.value.length > virtualScroll.value.pageSize;
1084
1084
  });
1085
1085
  const virtual_dataSourcePart = computed(() => {
1086
1086
  if (!virtual_on.value) return dataSourceCopy.value;
@@ -1089,7 +1089,8 @@ function useVirtualScroll({
1089
1089
  });
1090
1090
  const virtual_offsetBottom = computed(() => {
1091
1091
  if (!virtual_on.value) return 0;
1092
- const { startIndex, rowHeight } = virtualScroll.value;
1092
+ const { startIndex } = virtualScroll.value;
1093
+ const rowHeight = getRowHeightFn.value();
1093
1094
  return (dataSourceCopy.value.length - startIndex - virtual_dataSourcePart.value.length) * rowHeight;
1094
1095
  });
1095
1096
  const virtualX_on = computed(() => {
@@ -1126,9 +1127,22 @@ function useVirtualScroll({
1126
1127
  }
1127
1128
  return width;
1128
1129
  });
1130
+ const getRowHeightFn = computed(() => {
1131
+ var _a;
1132
+ let rowHeightFn = () => props.rowHeight || DEFAULT_ROW_HEIGHT;
1133
+ if (props.autoRowHeight) {
1134
+ const tempRowHeightFn = rowHeightFn;
1135
+ rowHeightFn = (row) => getAutoRowHeight(row) || tempRowHeightFn(row);
1136
+ }
1137
+ if (hasExpandCol.value) {
1138
+ const expandedRowHeight = (_a = props.expandConfig) == null ? void 0 : _a.height;
1139
+ const tempRowHeightFn = rowHeightFn;
1140
+ rowHeightFn = (row) => row && row.__EXPANDED_ROW__ && expandedRowHeight || tempRowHeightFn(row);
1141
+ }
1142
+ return rowHeightFn;
1143
+ });
1129
1144
  function getTableHeaderHeight() {
1130
- const { headerRowHeight } = props;
1131
- return headerRowHeight * tableHeaders.value.length;
1145
+ return props.headerRowHeight * tableHeaders.value.length;
1132
1146
  }
1133
1147
  function initVirtualScroll(height) {
1134
1148
  initVirtualScrollY(height);
@@ -1140,10 +1154,9 @@ function useVirtualScroll({
1140
1154
  console.warn("initVirtualScrollY: height must be a number");
1141
1155
  height = 0;
1142
1156
  }
1143
- if (!virtual_on.value) return;
1144
1157
  const { offsetHeight, scrollHeight } = tableContainerRef.value || {};
1145
1158
  let scrollTop = ((_a = tableContainerRef.value) == null ? void 0 : _a.scrollTop) || 0;
1146
- const { rowHeight } = virtualScroll.value;
1159
+ const rowHeight = getRowHeightFn.value(props.dataSource[0]);
1147
1160
  const containerHeight = height || offsetHeight || DEFAULT_TABLE_HEIGHT;
1148
1161
  const { headless } = props;
1149
1162
  let pageSize = Math.ceil(containerHeight / rowHeight);
@@ -1180,7 +1193,8 @@ function useVirtualScroll({
1180
1193
  }
1181
1194
  function getAutoRowHeight(row) {
1182
1195
  var _a;
1183
- const rowKey = String(rowKeyGen(row));
1196
+ if (!row) return;
1197
+ const rowKey = rowKeyGen(row);
1184
1198
  const storedHeight = autoRowHeightMap.get(rowKey);
1185
1199
  if (storedHeight) {
1186
1200
  return storedHeight;
@@ -1193,32 +1207,19 @@ function useVirtualScroll({
1193
1207
  return expectedHeight;
1194
1208
  }
1195
1209
  }
1196
- return props.rowHeight || DEFAULT_ROW_HEIGHT;
1197
- }
1198
- function createGetRowHeightFn() {
1199
- var _a;
1200
- if (props.autoRowHeight) {
1201
- return (row) => getAutoRowHeight(row);
1202
- }
1203
- if (hasExpandCol.value) {
1204
- const { rowHeight } = virtualScroll.value;
1205
- const expandedRowHeight = ((_a = props.expandConfig) == null ? void 0 : _a.height) || rowHeight;
1206
- return (row) => row.__EXPANDED_ROW__ ? expandedRowHeight : rowHeight;
1207
- }
1208
- return () => props.rowHeight || DEFAULT_ROW_HEIGHT;
1209
1210
  }
1210
1211
  function updateVirtualScrollY(sTop = 0) {
1211
1212
  var _a;
1212
- const { rowHeight, pageSize, scrollTop, startIndex: oldStartIndex, endIndex: oldEndIndex } = virtualScroll.value;
1213
+ const { pageSize, scrollTop, startIndex: oldStartIndex, endIndex: oldEndIndex } = virtualScroll.value;
1213
1214
  virtualScroll.value.scrollTop = sTop;
1214
1215
  if (!virtual_on.value) {
1215
1216
  return;
1216
1217
  }
1217
1218
  const dataSourceCopyTemp = dataSourceCopy.value;
1219
+ const rowHeight = getRowHeightFn.value(dataSourceCopyTemp[0]);
1218
1220
  const { autoRowHeight, stripe, optimizeVue2Scroll } = props;
1219
1221
  let startIndex = 0;
1220
1222
  let autoRowHeightTop = 0;
1221
- let getRowHeight = null;
1222
1223
  const dataLength = dataSourceCopyTemp.length;
1223
1224
  if (autoRowHeight || hasExpandCol.value) {
1224
1225
  if (autoRowHeight) {
@@ -1228,9 +1229,8 @@ function useVirtualScroll({
1228
1229
  autoRowHeightMap.set(rowKey, tr.offsetHeight);
1229
1230
  });
1230
1231
  }
1231
- getRowHeight = createGetRowHeightFn();
1232
1232
  for (let i = 0; i < dataLength; i++) {
1233
- const height = getRowHeight(dataSourceCopyTemp[i]);
1233
+ const height = getRowHeightFn.value(dataSourceCopyTemp[i]);
1234
1234
  autoRowHeightTop += height;
1235
1235
  if (autoRowHeightTop >= sTop) {
1236
1236
  startIndex = i;
@@ -1245,7 +1245,7 @@ function useVirtualScroll({
1245
1245
  if (stripe && startIndex > 0 && startIndex % 2) {
1246
1246
  startIndex -= 1;
1247
1247
  if (autoRowHeight || hasExpandCol.value) {
1248
- const height = getRowHeight(dataSourceCopyTemp[startIndex]);
1248
+ const height = getRowHeightFn.value(dataSourceCopyTemp[startIndex]);
1249
1249
  autoRowHeightTop -= height;
1250
1250
  }
1251
1251
  }
@@ -1698,6 +1698,9 @@ const _sfc_main = /* @__PURE__ */ defineComponent({
1698
1698
  [TagType.TD]: tdMap
1699
1699
  };
1700
1700
  });
1701
+ function getRowIndex(rowIndex) {
1702
+ return rowIndex + (virtual_on ? virtualScroll.value.startIndex : 0);
1703
+ }
1701
1704
  function getHeaderTitle(col) {
1702
1705
  const colKey = colKeyGen.value(col);
1703
1706
  if (props.hideHeaderTitle === true || Array.isArray(props.hideHeaderTitle) && props.hideHeaderTitle.includes(colKey)) {
@@ -1758,8 +1761,8 @@ const _sfc_main = /* @__PURE__ */ defineComponent({
1758
1761
  emits("sort-change", col, order, toRaw(dataSourceCopy.value), sortConfig);
1759
1762
  }
1760
1763
  }
1761
- function onRowClick(e, row) {
1762
- emits("row-click", e, row);
1764
+ function onRowClick(e, row, rowIndex) {
1765
+ emits("row-click", e, row, { rowIndex });
1763
1766
  const isCurrentRow = props.rowKey ? currentRowKey.value === rowKeyGen(row) : currentRow.value === row;
1764
1767
  if (isCurrentRow) {
1765
1768
  if (!props.rowCurrentRevokable) {
@@ -1773,22 +1776,22 @@ const _sfc_main = /* @__PURE__ */ defineComponent({
1773
1776
  }
1774
1777
  emits("current-change", e, row, { select: !isCurrentRow });
1775
1778
  }
1776
- function onRowDblclick(e, row) {
1777
- emits("row-dblclick", e, row);
1779
+ function onRowDblclick(e, row, rowIndex) {
1780
+ emits("row-dblclick", e, row, { rowIndex });
1778
1781
  }
1779
1782
  function onHeaderMenu(e) {
1780
1783
  emits("header-row-menu", e);
1781
1784
  }
1782
- function onRowMenu(e, row) {
1783
- emits("row-menu", e, row);
1785
+ function onRowMenu(e, row, rowIndex) {
1786
+ emits("row-menu", e, row, { rowIndex });
1784
1787
  }
1785
- function onCellClick(e, row, col) {
1788
+ function onCellClick(e, row, col, rowIndex) {
1786
1789
  if (col.type === "expand") {
1787
1790
  toggleExpandRow(row, col);
1788
1791
  }
1789
1792
  if (props.cellActive) {
1790
1793
  const cellKey = cellKeyGen(row, col);
1791
- const result = { row, col, select: false };
1794
+ const result = { row, col, select: false, rowIndex };
1792
1795
  if (props.selectedCellRevokable && currentSelectedCellKey.value === cellKey) {
1793
1796
  currentSelectedCellKey.value = void 0;
1794
1797
  } else {
@@ -1797,7 +1800,7 @@ const _sfc_main = /* @__PURE__ */ defineComponent({
1797
1800
  }
1798
1801
  emits("cell-selected", e, result);
1799
1802
  }
1800
- emits("cell-click", e, row, col);
1803
+ emits("cell-click", e, row, col, { rowIndex });
1801
1804
  }
1802
1805
  function onHeaderCellClick(e, col) {
1803
1806
  emits("header-cell-click", e, col);
@@ -1811,8 +1814,8 @@ const _sfc_main = /* @__PURE__ */ defineComponent({
1811
1814
  function onCellMouseOver(e, row, col) {
1812
1815
  emits("cell-mouseover", e, row, col);
1813
1816
  }
1814
- function onCellMouseDown(e, row, col) {
1815
- emits("cell-mousedown", e, row, col);
1817
+ function onCellMouseDown(e, row, col, rowIndex) {
1818
+ emits("cell-mousedown", e, row, col, { rowIndex });
1816
1819
  }
1817
1820
  function onTableWheel(e) {
1818
1821
  if (props.smoothScroll) {
@@ -2262,27 +2265,27 @@ const _sfc_main = /* @__PURE__ */ defineComponent({
2262
2265
  (openBlock(true), createElementBlock(Fragment, null, renderList(unref(virtual_dataSourcePart), (row, rowIndex) => {
2263
2266
  var _a, _b;
2264
2267
  return openBlock(), createElementBlock("tr", {
2265
- id: unref(stkTableId) + "-" + (_ctx.rowKey ? rowKeyGen(row) : (unref(virtual_on) ? unref(virtualScroll).startIndex : 0) + rowIndex),
2268
+ id: unref(stkTableId) + "-" + (_ctx.rowKey ? rowKeyGen(row) : getRowIndex(rowIndex)),
2266
2269
  ref_for: true,
2267
2270
  ref_key: "trRef",
2268
2271
  ref: trRef,
2269
- key: _ctx.rowKey ? rowKeyGen(row) : (unref(virtual_on) ? unref(virtualScroll).startIndex : 0) + rowIndex,
2270
- "data-row-key": _ctx.rowKey ? rowKeyGen(row) : (unref(virtual_on) ? unref(virtualScroll).startIndex : 0) + rowIndex,
2272
+ key: _ctx.rowKey ? rowKeyGen(row) : getRowIndex(rowIndex),
2273
+ "data-row-key": _ctx.rowKey ? rowKeyGen(row) : getRowIndex(rowIndex),
2271
2274
  class: normalizeClass({
2272
2275
  active: _ctx.rowKey ? rowKeyGen(row) === currentRowKey.value : row === currentRow.value,
2273
2276
  hover: props.showTrHoverClass && (_ctx.rowKey ? rowKeyGen(row) === currentHoverRowKey.value : row === currentHoverRowKey.value),
2274
- [_ctx.rowClassName(row, (unref(virtual_on) ? unref(virtualScroll).startIndex : 0) + rowIndex)]: true,
2277
+ [_ctx.rowClassName(row, getRowIndex(rowIndex))]: true,
2275
2278
  expanded: row == null ? void 0 : row.__EXPANDED__,
2276
2279
  "expanded-row": row && row.__EXPANDED_ROW__
2277
2280
  }),
2278
2281
  style: normalizeStyle({
2279
2282
  "--row-height": row && row.__EXPANDED_ROW__ && props.virtual && ((_a = props.expandConfig) == null ? void 0 : _a.height) && ((_b = props.expandConfig) == null ? void 0 : _b.height) + "px"
2280
2283
  }),
2281
- onClick: (e) => onRowClick(e, row),
2282
- onDblclick: (e) => onRowDblclick(e, row),
2283
- onContextmenu: (e) => onRowMenu(e, row),
2284
+ onClick: (e) => onRowClick(e, row, getRowIndex(rowIndex)),
2285
+ onDblclick: (e) => onRowDblclick(e, row, getRowIndex(rowIndex)),
2286
+ onContextmenu: (e) => onRowMenu(e, row, getRowIndex(rowIndex)),
2284
2287
  onMouseover: (e) => onTrMouseOver(e, row),
2285
- onDrop: (e) => unref(onTrDrop)(e, (unref(virtual_on) ? unref(virtualScroll).startIndex : 0) + rowIndex)
2288
+ onDrop: (e) => unref(onTrDrop)(e, getRowIndex(rowIndex))
2286
2289
  }, [
2287
2290
  unref(virtualX_on) ? (openBlock(), createElementBlock("td", _hoisted_7)) : createCommentVNode("", true),
2288
2291
  row && row.__EXPANDED_ROW__ ? (openBlock(), createElementBlock("td", {
@@ -2312,12 +2315,12 @@ const _sfc_main = /* @__PURE__ */ defineComponent({
2312
2315
  "seq-column": col.type === "seq",
2313
2316
  active: currentSelectedCellKey.value === cellKeyGen(row, col),
2314
2317
  "expand-cell": col.type === "expand",
2315
- expanded: col.type === "expand" && colKeyGen.value(row == null ? void 0 : row.__EXPANDED__) === colKeyGen.value(col),
2318
+ expanded: col.type === "expand" && (row.__EXPANDED__ ? colKeyGen.value(row.__EXPANDED__) === colKeyGen.value(col) : false),
2316
2319
  "drag-row-cell": col.type === "dragRow"
2317
2320
  }
2318
2321
  ]),
2319
- onClick: (e) => onCellClick(e, row, col),
2320
- onMousedown: (e) => onCellMouseDown(e, row, col),
2322
+ onClick: (e) => onCellClick(e, row, col, getRowIndex(rowIndex)),
2323
+ onMousedown: (e) => onCellMouseDown(e, row, col, getRowIndex(rowIndex)),
2321
2324
  onMouseenter: (e) => onCellMouseEnter(e, row, col),
2322
2325
  onMouseleave: (e) => onCellMouseLeave(e, row, col),
2323
2326
  onMouseover: (e) => onCellMouseOver(e, row, col)
@@ -2327,20 +2330,20 @@ const _sfc_main = /* @__PURE__ */ defineComponent({
2327
2330
  class: "table-cell-wrapper",
2328
2331
  col,
2329
2332
  row,
2330
- rowIndex: (unref(virtual_on) ? unref(virtualScroll).startIndex : 0) + rowIndex,
2333
+ rowIndex: getRowIndex(rowIndex),
2331
2334
  colIndex,
2332
- cellValue: row == null ? void 0 : row[col.dataIndex],
2333
- expanded: (row == null ? void 0 : row.__EXPANDED__) || null
2335
+ cellValue: row && row[col.dataIndex],
2336
+ expanded: row && row.__EXPANDED__ || null
2334
2337
  }, null, 8, ["col", "row", "rowIndex", "colIndex", "cellValue", "expanded"])) : (openBlock(), createElementBlock("div", {
2335
2338
  key: 1,
2336
2339
  class: normalizeClass(["table-cell-wrapper", { "expanded-cell-wrapper": col.type === "expand" }]),
2337
2340
  title: col.type !== "seq" ? row == null ? void 0 : row[col.dataIndex] : ""
2338
2341
  }, [
2339
2342
  col.type === "seq" ? (openBlock(), createElementBlock(Fragment, { key: 0 }, [
2340
- createTextVNode(toDisplayString((props.seqConfig.startIndex || 0) + (unref(virtual_on) ? unref(virtualScroll).startIndex : 0) + rowIndex + 1), 1)
2343
+ createTextVNode(toDisplayString((props.seqConfig.startIndex || 0) + getRowIndex(rowIndex) + 1), 1)
2341
2344
  ], 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 }, [
2342
2345
  createVNode(DragHandle, {
2343
- onDragstart: (e) => unref(onTrDragStart)(e, (unref(virtual_on) ? unref(virtualScroll).startIndex : 0) + rowIndex)
2346
+ onDragstart: (e) => unref(onTrDragStart)(e, getRowIndex(rowIndex))
2344
2347
  }, null, 8, ["onDragstart"]),
2345
2348
  createElementVNode("span", null, toDisplayString((row == null ? void 0 : row[col.dataIndex]) ?? ""), 1)
2346
2349
  ], 64)) : (openBlock(), createElementBlock(Fragment, { key: 3 }, [
package/package.json CHANGED
@@ -1,75 +1,76 @@
1
- {
2
- "name": "stk-table-vue",
3
- "version": "0.6.12",
4
- "description": "Simple realtime virtual table for vue3 and vue2.7",
5
- "main": "./lib/stk-table-vue.js",
6
- "types": "./lib/src/StkTable/index.d.ts",
7
- "packageManager": "pnpm@10.7.0",
8
- "directories": {
9
- "test": "test"
10
- },
11
- "type": "module",
12
- "scripts": {
13
- "dev": "vite",
14
- "build": "vite build",
15
- "test": "vitest",
16
- "docs:dev": "vitepress dev docs-src",
17
- "docs:build": "vitepress build docs-src",
18
- "docs:preview": "vitepress preview docs-src",
19
- "docs:update": "cp -rf ./docs-src/.vitepress/dist/* ./docs"
20
- },
21
- "keywords": [
22
- "virtual table",
23
- "vue",
24
- "vue2",
25
- "vue3",
26
- "highlight",
27
- "sticky",
28
- "virtual",
29
- "table",
30
- "list"
31
- ],
32
- "files": [
33
- "lib",
34
- "src"
35
- ],
36
- "author": "japlus",
37
- "repository": {
38
- "type": "git",
39
- "url": "https://github.com/ja-plus/stk-table-vue"
40
- },
41
- "license": "MIT",
42
- "devDependencies": {
43
- "@types/d3-interpolate": "^3.0.4",
44
- "@types/mockjs": "^1.0.10",
45
- "@types/node": "^20.12.10",
46
- "@typescript-eslint/eslint-plugin": "^7.7.0",
47
- "@typescript-eslint/parser": "^7.7.0",
48
- "@vitejs/plugin-vue": "^5.1.4",
49
- "@vue/test-utils": "2.4.4",
50
- "eslint": "^8.57.0",
51
- "eslint-config-prettier": "^9.1.0",
52
- "eslint-plugin-html": "^8.1.0",
53
- "eslint-plugin-prettier": "^5.1.3",
54
- "eslint-plugin-vue": "^9.25.0",
55
- "happy-dom": "^12.10.3",
56
- "less": "^4.2.0",
57
- "mitt": "^3.0.1",
58
- "mockjs": "^1.1.0",
59
- "postcss": "^8.4.47",
60
- "postcss-discard-comments": "^6.0.2",
61
- "postcss-preset-env": "^9.5.11",
62
- "prettier": "^3.2.5",
63
- "typescript": "^5.4.5",
64
- "vite": "^5.4.10",
65
- "vite-plugin-dts": "3.9.1",
66
- "vitepress": "^1.5.0",
67
- "vitepress-demo-plugin": "^1.3.1",
68
- "vitest": "^2.1.3",
69
- "vue": "^3.5.12",
70
- "vue-eslint-parser": "^9.4.2"
71
- },
72
- "dependencies": {
73
- "d3-interpolate": "^3.0.1"
74
- }
1
+ {
2
+ "name": "stk-table-vue",
3
+ "version": "0.6.14",
4
+ "description": "Simple realtime virtual table for vue3 and vue2.7",
5
+ "main": "./lib/stk-table-vue.js",
6
+ "types": "./lib/src/StkTable/index.d.ts",
7
+ "packageManager": "pnpm@10.7.0",
8
+ "directories": {
9
+ "test": "test"
10
+ },
11
+ "type": "module",
12
+ "scripts": {
13
+ "dev": "vite",
14
+ "build": "vite build",
15
+ "test": "vitest",
16
+ "docs:dev": "vitepress dev docs-src",
17
+ "docs:build": "vitepress build docs-src",
18
+ "docs:preview": "vitepress preview docs-src",
19
+ "docs:update": "cp -rf ./docs-src/.vitepress/dist/* ./docs"
20
+ },
21
+ "keywords": [
22
+ "virtual table",
23
+ "vue",
24
+ "vue2",
25
+ "vue3",
26
+ "highlight",
27
+ "sticky",
28
+ "virtual",
29
+ "table",
30
+ "list"
31
+ ],
32
+ "files": [
33
+ "lib",
34
+ "src"
35
+ ],
36
+ "author": "japlus",
37
+ "repository": {
38
+ "type": "git",
39
+ "url": "https://github.com/ja-plus/stk-table-vue"
40
+ },
41
+ "license": "MIT",
42
+ "devDependencies": {
43
+ "@types/d3-interpolate": "^3.0.4",
44
+ "@types/mockjs": "^1.0.10",
45
+ "@types/node": "^20.12.10",
46
+ "@typescript-eslint/eslint-plugin": "^7.7.0",
47
+ "@typescript-eslint/parser": "^7.7.0",
48
+ "@vitejs/plugin-vue": "^5.1.4",
49
+ "@vue/test-utils": "2.4.4",
50
+ "eslint": "^8.57.0",
51
+ "eslint-config-prettier": "^9.1.0",
52
+ "eslint-plugin-html": "^8.1.0",
53
+ "eslint-plugin-prettier": "^5.1.3",
54
+ "eslint-plugin-vue": "^9.25.0",
55
+ "happy-dom": "^12.10.3",
56
+ "less": "^4.2.0",
57
+ "mitt": "^3.0.1",
58
+ "mockjs": "^1.1.0",
59
+ "postcss": "^8.4.47",
60
+ "postcss-discard-comments": "^6.0.2",
61
+ "postcss-preset-env": "^9.5.11",
62
+ "prettier": "^3.2.5",
63
+ "typescript": "^5.4.5",
64
+ "vite": "^5.4.10",
65
+ "vite-plugin-dts": "3.9.1",
66
+ "vitepress": "^1.5.0",
67
+ "vitepress-demo-plugin": "^1.3.1",
68
+ "vitepress-plugin-llms": "^1.1.3",
69
+ "vitest": "^2.1.3",
70
+ "vue": "^3.5.12",
71
+ "vue-eslint-parser": "^9.4.2"
72
+ },
73
+ "dependencies": {
74
+ "d3-interpolate": "^3.0.1"
75
+ }
75
76
  }