stk-table-vue 0.6.9 → 0.6.12

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.
@@ -19,6 +19,7 @@ export function useGetFixedColPosition<DT extends Record<string, any>>({ tableHe
19
19
  const colKeyStore: Record<string, number> = {};
20
20
  /** 没有 colKey 的多级表头列,使用对象引用做标识 */
21
21
  const refStore = new WeakMap<StkTableColumn<DT>, number>();
22
+ const colKeyGenValue = colKeyGen.value;
22
23
  tableHeadersForCalc.value.forEach(cols => {
23
24
  let left = 0;
24
25
  /**遍历右侧fixed时,因为left已经遍历过一次了。所以,可以拿到right遍历边界 */
@@ -26,7 +27,7 @@ export function useGetFixedColPosition<DT extends Record<string, any>>({ tableHe
26
27
  for (let i = 0; i < cols.length; i++) {
27
28
  const item = cols[i];
28
29
  if (item.fixed === 'left') {
29
- const colKey = colKeyGen.value(item);
30
+ const colKey = colKeyGenValue(item);
30
31
  if (colKey) {
31
32
  colKeyStore[colKey] = left;
32
33
  } else {
@@ -42,7 +43,7 @@ export function useGetFixedColPosition<DT extends Record<string, any>>({ tableHe
42
43
  let right = 0;
43
44
  for (let i = cols.length - 1; i >= rightStartIndex; i--) {
44
45
  const item = cols[i];
45
- const colKey = colKeyGen.value(item);
46
+ const colKey = colKeyGenValue(item);
46
47
  if (item.fixed === 'right') {
47
48
  if (colKey) {
48
49
  colKeyStore[colKey] = right;
@@ -55,7 +56,7 @@ export function useGetFixedColPosition<DT extends Record<string, any>>({ tableHe
55
56
  });
56
57
 
57
58
  return (col: StkTableColumn<any>) => {
58
- const colKey = colKeyGen.value(col);
59
+ const colKey = colKeyGenValue(col);
59
60
  return colKey ? colKeyStore[colKey] : refStore.get(col) || 0;
60
61
  };
61
62
  });
@@ -10,6 +10,8 @@ enum ScrollCodes {
10
10
  ArrowLeft = 'ArrowLeft',
11
11
  PageUp = 'PageUp',
12
12
  PageDown = 'PageDown',
13
+ Home = 'Home',
14
+ End = 'End',
13
15
  }
14
16
  /** 所有翻页按键数组 */
15
17
  const ScrollCodesValues = Object.values(ScrollCodes);
@@ -66,7 +68,7 @@ export function useKeyboardArrowScroll<DT extends Record<string, any>>(
66
68
  if (!isMouseOver) return; // 不悬浮还是要触发键盘事件的
67
69
  e.preventDefault(); // 不触发键盘默认的箭头事件
68
70
 
69
- const { scrollTop, rowHeight, containerHeight } = virtualScroll.value;
71
+ const { scrollTop, rowHeight, containerHeight, scrollHeight } = virtualScroll.value;
70
72
  const { scrollLeft } = virtualScrollX.value;
71
73
  const { headless, headerRowHeight } = props;
72
74
 
@@ -78,15 +80,19 @@ export function useKeyboardArrowScroll<DT extends Record<string, any>>(
78
80
  if (e.code === ScrollCodes.ArrowUp) {
79
81
  scrollTo(scrollTop - rowHeight, null);
80
82
  } else if (e.code === ScrollCodes.ArrowRight) {
81
- scrollTo(null, scrollLeft + rowHeight);
83
+ scrollTo(null, scrollLeft + 50);
82
84
  } else if (e.code === ScrollCodes.ArrowDown) {
83
85
  scrollTo(scrollTop + rowHeight, null);
84
86
  } else if (e.code === ScrollCodes.ArrowLeft) {
85
- scrollTo(null, scrollLeft - rowHeight);
87
+ scrollTo(null, scrollLeft - 50);
86
88
  } else if (e.code === ScrollCodes.PageUp) {
87
89
  scrollTo(scrollTop - rowHeight * bodyPageSize + headerHeight, null);
88
90
  } else if (e.code === ScrollCodes.PageDown) {
89
91
  scrollTo(scrollTop + rowHeight * bodyPageSize - headerHeight, null);
92
+ } else if (e.code === ScrollCodes.Home) {
93
+ scrollTo(0, null);
94
+ } else if (e.code === ScrollCodes.End) {
95
+ scrollTo(scrollHeight, null);
90
96
  }
91
97
  }
92
98
 
@@ -69,7 +69,7 @@ export function useThDrag<DT extends Record<string, any>>({ props, emits, colKey
69
69
  if (isEmptyValue(dragStartKey) || isEmptyValue(dragEndKey)) return;
70
70
 
71
71
  if (dragConfig.value.mode !== 'none') {
72
- const columns = [...props.columns];
72
+ const columns: StkTableColumn<any>[] = props.columns.slice();
73
73
 
74
74
  const dragStartIndex = columns.findIndex(col => colKeyGen.value(col) === dragStartKey);
75
75
  const dragEndIndex = columns.findIndex(col => colKeyGen.value(col) === dragEndKey);
@@ -93,7 +93,7 @@ export function useTrDrag({ props, emits, dataSourceCopy }: Params) {
93
93
  if (sourceIndex === endIndex) return;
94
94
 
95
95
  if (mode !== 'none') {
96
- const dataSourceTemp = [...dataSourceCopy.value];
96
+ const dataSourceTemp = dataSourceCopy.value.slice();
97
97
  const sourceRow = dataSourceTemp[sourceIndex];
98
98
  if (mode === 'swap') {
99
99
  dataSourceTemp[sourceIndex] = dataSourceTemp[endIndex];
@@ -102,7 +102,7 @@ export function useTrDrag({ props, emits, dataSourceCopy }: Params) {
102
102
  dataSourceTemp.splice(sourceIndex, 1);
103
103
  dataSourceTemp.splice(endIndex, 0, sourceRow);
104
104
  }
105
- dataSourceCopy.value = [...dataSourceTemp];
105
+ dataSourceCopy.value = dataSourceTemp;
106
106
  }
107
107
  emits('row-order-change', sourceIndex, endIndex);
108
108
  }
@@ -166,9 +166,6 @@ export function useVirtualScroll<DT extends Record<string, any>>({
166
166
  function getTableHeaderHeight() {
167
167
  const { headerRowHeight } = props;
168
168
  return headerRowHeight * tableHeaders.value.length;
169
- // if (props.virtual) {
170
- // }
171
- // return theadRef.value?.offsetHeight || 0;
172
169
  }
173
170
 
174
171
  /**
@@ -225,25 +222,26 @@ export function useVirtualScroll<DT extends Record<string, any>>({
225
222
  /** every row actual height */
226
223
  const autoRowHeightMap = new Map<UniqKey, number>();
227
224
  /** 如果行高度有变化,则要调用此方法清除保存的行高 */
228
- const setAutoHeight = (rowKey: UniqKey, height?: number | null) => {
225
+ function setAutoHeight(rowKey: UniqKey, height?: number | null) {
229
226
  if (!height) {
230
227
  autoRowHeightMap.delete(rowKey);
231
228
  } else {
232
229
  autoRowHeightMap.set(rowKey, height);
233
230
  }
234
- };
235
- const clearAllAutoHeight = () => {
231
+ }
232
+
233
+ function clearAllAutoHeight() {
236
234
  autoRowHeightMap.clear();
237
- };
235
+ }
238
236
 
239
- const getAutoRowHeight = (row: DT) => {
237
+ function getAutoRowHeight(row: DT) {
240
238
  const rowKey = String(rowKeyGen(row));
241
239
  const storedHeight = autoRowHeightMap.get(rowKey);
242
- let expectedHeight;
243
240
  if (storedHeight) {
244
241
  return storedHeight;
245
242
  }
246
- if ((expectedHeight = props.autoRowHeight?.expectedHeight)) {
243
+ const expectedHeight = props.autoRowHeight?.expectedHeight;
244
+ if (expectedHeight) {
247
245
  if (typeof expectedHeight === 'function') {
248
246
  return expectedHeight(row);
249
247
  } else {
@@ -251,9 +249,9 @@ export function useVirtualScroll<DT extends Record<string, any>>({
251
249
  }
252
250
  }
253
251
  return props.rowHeight || DEFAULT_ROW_HEIGHT;
254
- };
252
+ }
255
253
 
256
- const createGetRowHeightFn: () => (row: DT) => number = () => {
254
+ function createGetRowHeightFn(): (row: DT) => number {
257
255
  if (props.autoRowHeight) {
258
256
  return (row: DT) => getAutoRowHeight(row);
259
257
  }
@@ -263,7 +261,7 @@ export function useVirtualScroll<DT extends Record<string, any>>({
263
261
  return (row: DT) => (row.__EXPANDED_ROW__ ? expandedRowHeight : rowHeight);
264
262
  }
265
263
  return () => props.rowHeight || (DEFAULT_ROW_HEIGHT as number);
266
- };
264
+ }
267
265
 
268
266
  /** 通过滚动条位置,计算虚拟滚动的参数 */
269
267
  function updateVirtualScrollY(sTop = 0) {
@@ -368,7 +366,7 @@ export function useVirtualScroll<DT extends Record<string, any>>({
368
366
  const headerLength = tableHeaderLastValue?.length;
369
367
  if (!headerLength) return;
370
368
 
371
- const { scrollLeft } = virtualScrollX.value;
369
+ const { scrollLeft, containerWidth } = virtualScrollX.value;
372
370
  let startIndex = 0;
373
371
  let offsetLeft = 0;
374
372
  /** 列宽累加 */
@@ -398,13 +396,13 @@ export function useVirtualScroll<DT extends Record<string, any>>({
398
396
  }
399
397
  // -----
400
398
  colWidthSum = leftFirstColRestWidth;
401
- const containerWidth = virtualScrollX.value.containerWidth - leftColWidthSum;
399
+ const containerW = containerWidth - leftColWidthSum;
402
400
  let endIndex = headerLength;
403
401
  for (let colIndex = startIndex + 1; colIndex < headerLength; colIndex++) {
404
402
  const col = tableHeaderLastValue[colIndex];
405
403
  colWidthSum += getCalculatedColWidth(col);
406
404
  // 列宽大于容器宽度则停止
407
- if (colWidthSum >= containerWidth) {
405
+ if (colWidthSum >= containerW) {
408
406
  endIndex = colIndex + 1; // slice endIndex + 1
409
407
  break;
410
408
  }
@@ -16,7 +16,7 @@ export function getColWidth(col: StkTableColumn<any> | null): number {
16
16
 
17
17
  /** 获取计算后的宽度 */
18
18
  export function getCalculatedColWidth(col: PrivateStkTableColumn<any> | null) {
19
- return col?.__WIDTH__ ?? +DEFAULT_COL_WIDTH;
19
+ return (col && col.__WIDTH__) ?? +DEFAULT_COL_WIDTH;
20
20
  }
21
21
 
22
22
  /** 创建组件唯一标识 */
@@ -26,7 +26,7 @@ export function insertToOrderedArray<T extends object>(sortState: SortState<T>,
26
26
  sortConfig = { emptyToBottom: false, ...sortConfig };
27
27
  let { sortType } = sortState;
28
28
  if (!sortType) sortType = typeof newItem[dataIndex] as 'number' | 'string';
29
- const data = [...targetArray];
29
+ const data = targetArray.slice();
30
30
 
31
31
  if (!order || !data.length) {
32
32
  // 没有排序的情况,插入在最上方
@@ -146,7 +146,7 @@ export function tableSort<T extends Record<string, any>>(
146
146
  if (!dataSource?.length || !sortOption) return dataSource || [];
147
147
 
148
148
  sortConfig = { emptyToBottom: false, ...sortConfig };
149
- let targetDataSource = [...dataSource];
149
+ let targetDataSource = dataSource.slice();
150
150
  let sortField = sortOption.sortField || sortOption.dataIndex;
151
151
 
152
152
  if (!order && sortConfig.defaultSort) {
@@ -172,9 +172,9 @@ export function tableSort<T extends Record<string, any>>(
172
172
  }
173
173
 
174
174
  if (order === 'desc' || sortConfig.emptyToBottom) {
175
- targetDataSource = [...valueArr, ...emptyArr];
175
+ targetDataSource = valueArr.concat(emptyArr);
176
176
  } else {
177
- targetDataSource = [...emptyArr, ...valueArr];
177
+ targetDataSource = emptyArr.concat(valueArr);
178
178
  }
179
179
  }
180
180
  return targetDataSource;