stk-table-vue 0.8.8 → 0.8.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.
- package/lib/src/StkTable/StkTable.vue.d.ts +753 -749
- package/lib/src/StkTable/const.d.ts +36 -33
- package/lib/src/StkTable/types/index.d.ts +270 -263
- package/lib/src/StkTable/useMergeCells.d.ts +8 -8
- package/lib/stk-table-vue.js +2849 -2839
- package/package.json +1 -1
- package/src/StkTable/StkTable.vue +62 -45
- package/src/StkTable/const.ts +7 -1
- package/src/StkTable/types/index.ts +14 -6
- package/src/StkTable/useMergeCells.ts +12 -19
- package/src/StkTable/useRowExpand.ts +4 -4
- package/src/StkTable/useTree.ts +13 -17
package/package.json
CHANGED
|
@@ -20,7 +20,7 @@
|
|
|
20
20
|
'cell-hover': props.cellHover,
|
|
21
21
|
'cell-active': props.cellActive,
|
|
22
22
|
'row-hover': props.rowHover,
|
|
23
|
-
'row-active':
|
|
23
|
+
'row-active': rowActiveProp.enabled,
|
|
24
24
|
'text-overflow': props.showOverflow,
|
|
25
25
|
'header-text-overflow': props.showHeaderOverflow,
|
|
26
26
|
'fixed-relative-mode': isRelativeMode,
|
|
@@ -115,7 +115,7 @@
|
|
|
115
115
|
active: rowKey ? rowKeyGen(row) === currentRowKey : row === currentRow,
|
|
116
116
|
hover: props.showTrHoverClass && (rowKey ? rowKeyGen(row) === currentHoverRowKey : row === currentHoverRowKey),
|
|
117
117
|
[rowClassName(row, getRowIndex(rowIndex)) || '']: true,
|
|
118
|
-
expanded: row?.
|
|
118
|
+
expanded: row?.__EXP__,
|
|
119
119
|
'expanded-row': row && row.__EXPANDED_ROW__,
|
|
120
120
|
}"
|
|
121
121
|
:style="{
|
|
@@ -152,9 +152,8 @@
|
|
|
152
152
|
'cell-active': col.mergeCells && activeMergedCells.has(cellKeyGen(row, col)),
|
|
153
153
|
'seq-column': col.type === 'seq',
|
|
154
154
|
active: props.cellActive && currentSelectedCellKey === cellKeyGen(row, col),
|
|
155
|
-
expanded:
|
|
156
|
-
|
|
157
|
-
'tree-expanded': col.type === 'tree-node' && row.__T_EXPANDED__,
|
|
155
|
+
expanded: col.type === 'expand' && (row.__EXP__ ? colKeyGen(row.__EXP__) === colKeyGen(col) : false),
|
|
156
|
+
'tree-expanded': col.type === 'tree-node' && row.__T_EXP__,
|
|
158
157
|
'drag-row-cell': col.type === 'dragRow',
|
|
159
158
|
},
|
|
160
159
|
]"
|
|
@@ -179,8 +178,8 @@
|
|
|
179
178
|
:rowIndex="getRowIndex(rowIndex)"
|
|
180
179
|
:colIndex="colIndex"
|
|
181
180
|
:cellValue="row && row[col.dataIndex]"
|
|
182
|
-
:expanded="(row && row.
|
|
183
|
-
:tree-expanded="(row && row.
|
|
181
|
+
:expanded="(row && row.__EXP__) || null"
|
|
182
|
+
:tree-expanded="(row && row.__T_EXP__) || null"
|
|
184
183
|
>
|
|
185
184
|
<template #stkFoldIcon>
|
|
186
185
|
<TriangleIcon></TriangleIcon>
|
|
@@ -253,7 +252,14 @@ import { CSSProperties, computed, nextTick, onMounted, ref, shallowRef, toRaw, w
|
|
|
253
252
|
import DragHandle from './components/DragHandle.vue';
|
|
254
253
|
import SortIcon from './components/SortIcon.vue';
|
|
255
254
|
import TriangleIcon from './components/TriangleIcon.vue';
|
|
256
|
-
import {
|
|
255
|
+
import {
|
|
256
|
+
CELL_KEY_SEPARATE,
|
|
257
|
+
DEFAULT_ROW_ACTIVE_CONFIG,
|
|
258
|
+
DEFAULT_ROW_HEIGHT,
|
|
259
|
+
DEFAULT_SMOOTH_SCROLL,
|
|
260
|
+
DEFAULT_SORT_CONFIG,
|
|
261
|
+
IS_LEGACY_MODE,
|
|
262
|
+
} from './const';
|
|
257
263
|
import {
|
|
258
264
|
AutoRowHeightConfig,
|
|
259
265
|
ColResizableConfig,
|
|
@@ -264,6 +270,7 @@ import {
|
|
|
264
270
|
Order,
|
|
265
271
|
PrivateRowDT,
|
|
266
272
|
PrivateStkTableColumn,
|
|
273
|
+
RowActiveOption,
|
|
267
274
|
SeqConfig,
|
|
268
275
|
SortConfig,
|
|
269
276
|
SortOption,
|
|
@@ -328,8 +335,10 @@ const props = withDefaults(
|
|
|
328
335
|
/** 是否高亮鼠标悬浮的行 */
|
|
329
336
|
rowHover?: boolean;
|
|
330
337
|
/** 是否高亮选中的行 */
|
|
331
|
-
rowActive?: boolean
|
|
332
|
-
/**
|
|
338
|
+
rowActive?: boolean | RowActiveOption<DT>;
|
|
339
|
+
/**
|
|
340
|
+
* @deprecated
|
|
341
|
+
*/
|
|
333
342
|
rowCurrentRevokable?: boolean;
|
|
334
343
|
/** 表头行高。default = rowHeight */
|
|
335
344
|
headerRowHeight?: number | string | null;
|
|
@@ -446,7 +455,7 @@ const props = withDefaults(
|
|
|
446
455
|
rowHeight: DEFAULT_ROW_HEIGHT,
|
|
447
456
|
autoRowHeight: false,
|
|
448
457
|
rowHover: true,
|
|
449
|
-
rowActive:
|
|
458
|
+
rowActive: () => DEFAULT_ROW_ACTIVE_CONFIG,
|
|
450
459
|
rowCurrentRevokable: true,
|
|
451
460
|
headerRowHeight: DEFAULT_ROW_HEIGHT,
|
|
452
461
|
virtual: false,
|
|
@@ -706,6 +715,19 @@ const isTreeData = computed(() => {
|
|
|
706
715
|
return props.columns.some(col => col.type === 'tree-node');
|
|
707
716
|
});
|
|
708
717
|
|
|
718
|
+
const rowActiveProp = computed<Required<RowActiveOption<DT>>>(() => {
|
|
719
|
+
const { rowActive } = props;
|
|
720
|
+
if (typeof rowActive === 'boolean') {
|
|
721
|
+
return {
|
|
722
|
+
...DEFAULT_ROW_ACTIVE_CONFIG,
|
|
723
|
+
enabled: rowActive ?? true,
|
|
724
|
+
revokable: Boolean(props.rowCurrentRevokable),
|
|
725
|
+
};
|
|
726
|
+
} else {
|
|
727
|
+
return { ...DEFAULT_ROW_ACTIVE_CONFIG, ...rowActive };
|
|
728
|
+
}
|
|
729
|
+
});
|
|
730
|
+
|
|
709
731
|
const dataSourceCopy = shallowRef<DT[]>([]);
|
|
710
732
|
|
|
711
733
|
const rowKeyGenComputed = computed(() => {
|
|
@@ -786,7 +808,7 @@ const {
|
|
|
786
808
|
updateHoverMergedCells,
|
|
787
809
|
activeMergedCells,
|
|
788
810
|
updateActiveMergedCells,
|
|
789
|
-
} = useMergeCells({
|
|
811
|
+
} = useMergeCells({ rowActiveProp, tableHeaderLast, rowKeyGen, colKeyGen, virtual_dataSourcePart });
|
|
790
812
|
|
|
791
813
|
const getFixedColPosition = useGetFixedColPosition({ colKeyGen, tableHeadersForCalc });
|
|
792
814
|
|
|
@@ -1040,7 +1062,7 @@ function dealColumns() {
|
|
|
1040
1062
|
*/
|
|
1041
1063
|
function rowKeyGen(row: DT | null | undefined) {
|
|
1042
1064
|
if (!row) return row;
|
|
1043
|
-
let key = rowKeyGenCache.get(row) || (row as PrivateRowDT).
|
|
1065
|
+
let key = rowKeyGenCache.get(row) || (row as PrivateRowDT).__ROW_K__;
|
|
1044
1066
|
if (!key) {
|
|
1045
1067
|
key = rowKeyGenComputed.value(row);
|
|
1046
1068
|
|
|
@@ -1164,7 +1186,7 @@ function onColumnSort(col: StkTableColumn<DT> | undefined | null, click = true,
|
|
|
1164
1186
|
dataSourceCopy.value = isTreeData.value ? flatTreeData(dataSourceTemp) : dataSourceTemp;
|
|
1165
1187
|
}
|
|
1166
1188
|
}
|
|
1167
|
-
//
|
|
1189
|
+
// only emit sort-change event when click
|
|
1168
1190
|
if (click || options.emit) {
|
|
1169
1191
|
emits('sort-change', col, order, toRaw(dataSourceTemp), sortConfig);
|
|
1170
1192
|
}
|
|
@@ -1172,20 +1194,15 @@ function onColumnSort(col: StkTableColumn<DT> | undefined | null, click = true,
|
|
|
1172
1194
|
|
|
1173
1195
|
function onRowClick(e: MouseEvent, row: DT, rowIndex: number) {
|
|
1174
1196
|
emits('row-click', e, row, { rowIndex });
|
|
1197
|
+
if (rowActiveProp.value.disabled?.(row)) return;
|
|
1175
1198
|
const isCurrentRow = props.rowKey ? currentRowKey.value === rowKeyGen(row) : currentRow.value === row;
|
|
1176
1199
|
if (isCurrentRow) {
|
|
1177
|
-
if (!
|
|
1178
|
-
// 不可取消
|
|
1200
|
+
if (!rowActiveProp.value.revokable) {
|
|
1179
1201
|
return;
|
|
1180
1202
|
}
|
|
1181
|
-
|
|
1182
|
-
currentRow.value = void 0;
|
|
1183
|
-
currentRowKey.value = void 0;
|
|
1184
|
-
updateActiveMergedCells(true);
|
|
1203
|
+
setCurrentRow(void 0, { silent: true });
|
|
1185
1204
|
} else {
|
|
1186
|
-
|
|
1187
|
-
currentRowKey.value = rowKeyGen(row);
|
|
1188
|
-
updateActiveMergedCells();
|
|
1205
|
+
setCurrentRow(row, { silent: true });
|
|
1189
1206
|
}
|
|
1190
1207
|
emits('current-change', e, row, { select: !isCurrentRow });
|
|
1191
1208
|
}
|
|
@@ -1283,50 +1300,47 @@ function onCellMouseDown(e: MouseEvent, row: DT, col: StkTableColumn<DT>, rowInd
|
|
|
1283
1300
|
}
|
|
1284
1301
|
|
|
1285
1302
|
/**
|
|
1286
|
-
*
|
|
1303
|
+
* proxy scroll, prevent white screen
|
|
1287
1304
|
* @param e
|
|
1288
1305
|
*/
|
|
1289
1306
|
function onTableWheel(e: WheelEvent) {
|
|
1290
1307
|
if (props.smoothScroll) {
|
|
1291
1308
|
return;
|
|
1292
1309
|
}
|
|
1310
|
+
// if is resizing, not allow scroll
|
|
1293
1311
|
if (isColResizing.value) {
|
|
1294
|
-
// 正在调整列宽时,不允许用户滚动
|
|
1295
1312
|
e.stopPropagation();
|
|
1296
1313
|
return;
|
|
1297
1314
|
}
|
|
1298
|
-
// #region ---- 控制滚动,防止出现白屏--
|
|
1299
1315
|
const dom = tableContainerRef.value;
|
|
1300
1316
|
if (!dom) return;
|
|
1317
|
+
if (!virtual_on.value && !virtualX_on.value) return;
|
|
1318
|
+
|
|
1301
1319
|
const { containerHeight, scrollTop, scrollHeight } = virtualScroll.value;
|
|
1302
1320
|
const { containerWidth, scrollLeft, scrollWidth } = virtualScrollX.value;
|
|
1303
|
-
/** 是否滚动在下面 */
|
|
1304
1321
|
const isScrollBottom = scrollHeight - containerHeight - scrollTop < 10;
|
|
1305
|
-
/** 是否滚动在右侧 */
|
|
1306
1322
|
const isScrollRight = scrollWidth - containerWidth - scrollLeft < 10;
|
|
1307
|
-
const { deltaY, deltaX } = e;
|
|
1323
|
+
const { deltaY, deltaX, shiftKey } = e;
|
|
1308
1324
|
|
|
1309
|
-
|
|
1310
|
-
* 只有虚拟滚动时,才要用 wheel 代理scroll,防止滚动过快导致的白屏。
|
|
1311
|
-
* 滚动条在边界情况时,not preventDefault 。因为会阻塞父级滚动条滚动。
|
|
1312
|
-
*/
|
|
1313
|
-
if (virtual_on.value && deltaY) {
|
|
1325
|
+
if (virtual_on.value && deltaY && !shiftKey) {
|
|
1314
1326
|
if ((deltaY > 0 && !isScrollBottom) || (deltaY < 0 && scrollTop > 0)) {
|
|
1315
|
-
e.preventDefault();
|
|
1327
|
+
e.preventDefault(); // parent element scroll
|
|
1316
1328
|
}
|
|
1317
1329
|
dom.scrollTop += deltaY;
|
|
1318
1330
|
}
|
|
1319
|
-
if (virtualX_on.value
|
|
1320
|
-
|
|
1331
|
+
if (virtualX_on.value) {
|
|
1332
|
+
let distance = deltaX;
|
|
1333
|
+
if (shiftKey && deltaY) {
|
|
1334
|
+
distance = deltaY;
|
|
1335
|
+
}
|
|
1336
|
+
if ((distance > 0 && !isScrollRight) || (distance < 0 && scrollLeft > 0)) {
|
|
1321
1337
|
e.preventDefault();
|
|
1322
1338
|
}
|
|
1323
|
-
dom.scrollLeft +=
|
|
1339
|
+
dom.scrollLeft += distance;
|
|
1324
1340
|
}
|
|
1325
|
-
//#endregion
|
|
1326
1341
|
}
|
|
1327
1342
|
|
|
1328
1343
|
/**
|
|
1329
|
-
* 滚动条监听
|
|
1330
1344
|
* @param e scrollEvent
|
|
1331
1345
|
*/
|
|
1332
1346
|
function onTableScroll(e: Event) {
|
|
@@ -1393,12 +1407,13 @@ function onTrMouseLeave(e: MouseEvent) {
|
|
|
1393
1407
|
* @param {boolean} option.silent if set true not emit `current-change`. default:false
|
|
1394
1408
|
* @param {boolean} option.deep if set true, deep search in children. default:false
|
|
1395
1409
|
*/
|
|
1396
|
-
function setCurrentRow(rowKeyOrRow: string | undefined | DT, option = { silent: false, deep: false }) {
|
|
1397
|
-
if (!dataSourceCopy.value.length) return;
|
|
1410
|
+
function setCurrentRow(rowKeyOrRow: string | undefined | DT, option: { silent?: boolean; deep?: boolean } = { silent: false, deep: false }) {
|
|
1398
1411
|
const select = rowKeyOrRow !== void 0;
|
|
1412
|
+
const currentRowTemp = currentRow.value;
|
|
1399
1413
|
if (!select) {
|
|
1400
1414
|
currentRow.value = void 0;
|
|
1401
1415
|
currentRowKey.value = void 0;
|
|
1416
|
+
updateActiveMergedCells(true);
|
|
1402
1417
|
} else if (typeof rowKeyOrRow === 'string') {
|
|
1403
1418
|
const findRowByKey = (data: DT[], key: string): DT | null => {
|
|
1404
1419
|
for (let i = 0; i < data.length; i++) {
|
|
@@ -1416,19 +1431,21 @@ function setCurrentRow(rowKeyOrRow: string | undefined | DT, option = { silent:
|
|
|
1416
1431
|
return null;
|
|
1417
1432
|
};
|
|
1418
1433
|
|
|
1419
|
-
|
|
1434
|
+
currentRowKey.value = rowKeyOrRow;
|
|
1435
|
+
updateActiveMergedCells(false, currentRowKey.value);
|
|
1436
|
+
const row = findRowByKey(dataSourceCopy.value || [], rowKeyOrRow);
|
|
1420
1437
|
if (!row) {
|
|
1421
1438
|
console.warn('setCurrentRow failed.rowKey:', rowKeyOrRow);
|
|
1422
1439
|
return;
|
|
1423
1440
|
}
|
|
1424
1441
|
currentRow.value = row;
|
|
1425
|
-
currentRowKey.value = rowKeyOrRow;
|
|
1426
1442
|
} else {
|
|
1427
1443
|
currentRow.value = rowKeyOrRow;
|
|
1428
1444
|
currentRowKey.value = rowKeyGen(rowKeyOrRow);
|
|
1445
|
+
updateActiveMergedCells(false, currentRowKey.value);
|
|
1429
1446
|
}
|
|
1430
1447
|
if (!option.silent) {
|
|
1431
|
-
emits('current-change', /** no Event */ null, currentRow.value, { select });
|
|
1448
|
+
emits('current-change', /** no Event */ null, select ? currentRow.value : currentRowTemp, { select });
|
|
1432
1449
|
}
|
|
1433
1450
|
}
|
|
1434
1451
|
|
package/src/StkTable/const.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { SortConfig } from './types';
|
|
1
|
+
import { RowActiveOption, SortConfig } from './types';
|
|
2
2
|
import { getBrowsersVersion } from './utils';
|
|
3
3
|
|
|
4
4
|
export const DEFAULT_COL_WIDTH = '100';
|
|
@@ -42,3 +42,9 @@ export const DEFAULT_SORT_CONFIG = {
|
|
|
42
42
|
stringLocaleCompare: false,
|
|
43
43
|
sortChildren: false,
|
|
44
44
|
} satisfies SortConfig<any>;
|
|
45
|
+
|
|
46
|
+
export const DEFAULT_ROW_ACTIVE_CONFIG: Required<RowActiveOption<any>> = {
|
|
47
|
+
enabled: false,
|
|
48
|
+
disabled: () => false,
|
|
49
|
+
revokable: false,
|
|
50
|
+
};
|
|
@@ -17,7 +17,7 @@ export type CustomCellProps<T extends Record<string, any>> = {
|
|
|
17
17
|
* - 不展开: null
|
|
18
18
|
* - 展开: 返回column配置
|
|
19
19
|
*/
|
|
20
|
-
expanded?: PrivateRowDT['
|
|
20
|
+
expanded?: PrivateRowDT['__EXP__'];
|
|
21
21
|
};
|
|
22
22
|
|
|
23
23
|
export type CustomHeaderCellProps<T extends Record<string, any>> = {
|
|
@@ -139,25 +139,25 @@ export type PrivateRowDT = {
|
|
|
139
139
|
/**
|
|
140
140
|
* Only expanded row will add this key
|
|
141
141
|
*
|
|
142
|
-
* If user define the `
|
|
142
|
+
* If user define the `__ROW_K__` in table data, this value will be used as the row key
|
|
143
143
|
* @private
|
|
144
144
|
*/
|
|
145
|
-
|
|
145
|
+
__ROW_K__?: string;
|
|
146
146
|
/**
|
|
147
147
|
* if row expanded
|
|
148
148
|
* @private
|
|
149
149
|
*/
|
|
150
|
-
|
|
150
|
+
__EXP__?: StkTableColumn<any> | null;
|
|
151
151
|
/**
|
|
152
152
|
* if tree node row expanded
|
|
153
153
|
* @private
|
|
154
154
|
*/
|
|
155
|
-
|
|
155
|
+
__T_EXP__?: boolean;
|
|
156
156
|
/**
|
|
157
157
|
* tree parent key
|
|
158
158
|
* @private
|
|
159
159
|
*/
|
|
160
|
-
|
|
160
|
+
__T_P_K__?: UniqKey;
|
|
161
161
|
/**
|
|
162
162
|
* tree level
|
|
163
163
|
* @private
|
|
@@ -284,3 +284,11 @@ export type RowKeyGen = (row: any) => UniqKey;
|
|
|
284
284
|
export type ColKeyGen = ComputedRef<(col: StkTableColumn<any>) => UniqKey>;
|
|
285
285
|
|
|
286
286
|
export type CellKeyGen = (row: any, col: StkTableColumn<any>) => string;
|
|
287
|
+
|
|
288
|
+
export type RowActiveOption<DT> = {
|
|
289
|
+
enabled?: boolean;
|
|
290
|
+
/** disabled row active */
|
|
291
|
+
disabled?: (row: DT) => boolean;
|
|
292
|
+
/** current row again click can revoke active */
|
|
293
|
+
revokable?: boolean;
|
|
294
|
+
};
|
|
@@ -1,20 +1,14 @@
|
|
|
1
|
-
import { ref, ShallowRef, watch } from 'vue';
|
|
2
|
-
import { ColKeyGen, MergeCellsParam, PrivateStkTableColumn, RowKeyGen, UniqKey } from './types';
|
|
1
|
+
import { Ref, ref, ShallowRef, watch } from 'vue';
|
|
2
|
+
import { ColKeyGen, MergeCellsParam, PrivateStkTableColumn, RowActiveOption, RowKeyGen, UniqKey } from './types';
|
|
3
3
|
import { pureCellKeyGen } from './utils';
|
|
4
4
|
type Options = {
|
|
5
|
-
|
|
5
|
+
rowActiveProp: Ref<RowActiveOption<any>>;
|
|
6
6
|
tableHeaderLast: ShallowRef<PrivateStkTableColumn<any>[]>;
|
|
7
7
|
rowKeyGen: RowKeyGen;
|
|
8
8
|
colKeyGen: ColKeyGen;
|
|
9
9
|
virtual_dataSourcePart: ShallowRef<any[]>;
|
|
10
|
-
}
|
|
11
|
-
export function useMergeCells({
|
|
12
|
-
props,
|
|
13
|
-
tableHeaderLast,
|
|
14
|
-
rowKeyGen,
|
|
15
|
-
colKeyGen,
|
|
16
|
-
virtual_dataSourcePart,
|
|
17
|
-
}:Options ) {
|
|
10
|
+
};
|
|
11
|
+
export function useMergeCells({ rowActiveProp, tableHeaderLast, rowKeyGen, colKeyGen, virtual_dataSourcePart }: Options) {
|
|
18
12
|
/**
|
|
19
13
|
* which cell need be hidden
|
|
20
14
|
* - key: rowKey
|
|
@@ -33,13 +27,12 @@ export function useMergeCells({
|
|
|
33
27
|
/** click current row , which rowspan cells should be highlight */
|
|
34
28
|
const activeMergedCells = ref(new Set<string>());
|
|
35
29
|
|
|
36
|
-
|
|
37
30
|
watch([virtual_dataSourcePart, tableHeaderLast], () => {
|
|
38
31
|
hiddenCellMap.value = {};
|
|
39
32
|
hoverRowMap.value = {};
|
|
40
33
|
});
|
|
41
34
|
|
|
42
|
-
/**
|
|
35
|
+
/**
|
|
43
36
|
* abstract the logic of hiding cells
|
|
44
37
|
*/
|
|
45
38
|
function hideCells(rowKey: UniqKey, startIndex: number, count: number, isSelfRow = false, mergeCellKey: string) {
|
|
@@ -84,14 +77,14 @@ export function useMergeCells({
|
|
|
84
77
|
if (colspan === 1 && rowspan === 1) return;
|
|
85
78
|
|
|
86
79
|
const rowKey = rowKeyGen(row);
|
|
87
|
-
|
|
80
|
+
|
|
88
81
|
const colKey = colKeyGen.value(col);
|
|
89
82
|
const curColIndex = tableHeaderLast.value.findIndex(item => colKeyGen.value(item) === colKey);
|
|
90
83
|
const curRowIndex = virtual_dataSourcePart.value.findIndex(item => rowKeyGen(item) === rowKey);
|
|
91
84
|
const mergedCellKey = pureCellKeyGen(rowKey, colKey);
|
|
92
85
|
|
|
93
86
|
if (curRowIndex === -1) return;
|
|
94
|
-
|
|
87
|
+
|
|
95
88
|
for (let i = curRowIndex; i < curRowIndex + rowspan; i++) {
|
|
96
89
|
const row = virtual_dataSourcePart.value[i];
|
|
97
90
|
if (!row) break;
|
|
@@ -106,13 +99,13 @@ export function useMergeCells({
|
|
|
106
99
|
hoverMergedCells.value = set || new Set();
|
|
107
100
|
}
|
|
108
101
|
|
|
109
|
-
function updateActiveMergedCells(clear?: boolean) {
|
|
110
|
-
if (!
|
|
102
|
+
function updateActiveMergedCells(clear?: boolean, rowKey?: UniqKey) {
|
|
103
|
+
if (!rowActiveProp.value.enabled) return;
|
|
111
104
|
if (clear) {
|
|
112
105
|
activeMergedCells.value.clear();
|
|
113
|
-
|
|
114
|
-
activeMergedCells.value = new Set(hoverMergedCells.value);
|
|
106
|
+
return;
|
|
115
107
|
}
|
|
108
|
+
activeMergedCells.value = (rowKey !== void 0 && hoverRowMap.value[rowKey]) || new Set(hoverMergedCells.value);
|
|
116
109
|
}
|
|
117
110
|
|
|
118
111
|
return {
|
|
@@ -9,7 +9,7 @@ type Option<DT extends Record<string, any>> = {
|
|
|
9
9
|
};
|
|
10
10
|
|
|
11
11
|
export function useRowExpand({ dataSourceCopy, rowKeyGen, emits }: Option<DT>) {
|
|
12
|
-
const expandedKey = '
|
|
12
|
+
const expandedKey = '__EXP__';
|
|
13
13
|
|
|
14
14
|
function isExpanded(row: DT, col?: StkTableColumn<DT> | null) {
|
|
15
15
|
return row?.[expandedKey] === col ? !row?.[expandedKey] : true;
|
|
@@ -45,7 +45,7 @@ export function useRowExpand({ dataSourceCopy, rowKeyGen, emits }: Option<DT>) {
|
|
|
45
45
|
// delete other expanded row below the target row
|
|
46
46
|
for (let i = index + 1; i < tempData.length; i++) {
|
|
47
47
|
const item: PrivateRowDT = tempData[i];
|
|
48
|
-
const rowKey = item.
|
|
48
|
+
const rowKey = item.__ROW_K__;
|
|
49
49
|
if (rowKey?.startsWith(EXPANDED_ROW_KEY_PREFIX)) {
|
|
50
50
|
tempData.splice(i, 1);
|
|
51
51
|
i--;
|
|
@@ -64,7 +64,7 @@ export function useRowExpand({ dataSourceCopy, rowKeyGen, emits }: Option<DT>) {
|
|
|
64
64
|
if (expand) {
|
|
65
65
|
// insert new expanded row
|
|
66
66
|
const newExpandRow: ExpandedRow = {
|
|
67
|
-
|
|
67
|
+
__ROW_K__: EXPANDED_ROW_KEY_PREFIX + rowKey,
|
|
68
68
|
__EXPANDED_ROW__: row,
|
|
69
69
|
__EXPANDED_COL__: col,
|
|
70
70
|
};
|
|
@@ -72,7 +72,7 @@ export function useRowExpand({ dataSourceCopy, rowKeyGen, emits }: Option<DT>) {
|
|
|
72
72
|
}
|
|
73
73
|
|
|
74
74
|
if (row) {
|
|
75
|
-
row.
|
|
75
|
+
row.__EXP__ = expand ? col : null;
|
|
76
76
|
}
|
|
77
77
|
|
|
78
78
|
dataSourceCopy.value = tempData;
|
package/src/StkTable/useTree.ts
CHANGED
|
@@ -14,7 +14,7 @@ export function useTree({ props, dataSourceCopy, rowKeyGen, emits }: Option<DT>)
|
|
|
14
14
|
|
|
15
15
|
/** click expended icon to toggle expand row */
|
|
16
16
|
function toggleTreeNode(row: DT, col: any) {
|
|
17
|
-
const expand = row ? !row.
|
|
17
|
+
const expand = row ? !row.__T_EXP__ : false;
|
|
18
18
|
privateSetTreeExpand(row, { expand, col, isClick: true });
|
|
19
19
|
}
|
|
20
20
|
|
|
@@ -47,7 +47,7 @@ export function useTree({ props, dataSourceCopy, rowKeyGen, emits }: Option<DT>)
|
|
|
47
47
|
const level = row.__T_LV__ || 0;
|
|
48
48
|
let expanded = option?.expand;
|
|
49
49
|
if (expanded === void 0) {
|
|
50
|
-
expanded = !row.
|
|
50
|
+
expanded = !row.__T_EXP__;
|
|
51
51
|
}
|
|
52
52
|
if (expanded) {
|
|
53
53
|
const children = expandNode(row, level);
|
|
@@ -73,13 +73,13 @@ export function useTree({ props, dataSourceCopy, rowKeyGen, emits }: Option<DT>)
|
|
|
73
73
|
}
|
|
74
74
|
|
|
75
75
|
function setNodeExpanded(row: DT, expanded: boolean, level?: number, parent?: DT) {
|
|
76
|
-
row.
|
|
76
|
+
row.__T_EXP__ = expanded;
|
|
77
77
|
if (level !== void 0) {
|
|
78
78
|
row.__T_LV__ = level;
|
|
79
79
|
}
|
|
80
|
-
if (parent) {
|
|
81
|
-
|
|
82
|
-
}
|
|
80
|
+
// if (parent) {
|
|
81
|
+
// row.__T_P_K__ = rowKeyGen(parent);
|
|
82
|
+
// }
|
|
83
83
|
}
|
|
84
84
|
|
|
85
85
|
/**
|
|
@@ -94,23 +94,19 @@ export function useTree({ props, dataSourceCopy, rowKeyGen, emits }: Option<DT>)
|
|
|
94
94
|
for (let i = 0; i < data.length; i++) {
|
|
95
95
|
const item = data[i];
|
|
96
96
|
result.push(item);
|
|
97
|
-
const isExpanded = Boolean(item.
|
|
97
|
+
const isExpanded = Boolean(item.__T_EXP__);
|
|
98
98
|
setNodeExpanded(item, isExpanded, level, parent);
|
|
99
99
|
if (!isExpanded) {
|
|
100
100
|
if (defaultExpandAll) {
|
|
101
101
|
setNodeExpanded(item, true);
|
|
102
102
|
} else {
|
|
103
|
-
if (defaultExpandLevel) {
|
|
104
|
-
|
|
105
|
-
setNodeExpanded(item, true);
|
|
106
|
-
}
|
|
103
|
+
if (defaultExpandLevel && level < defaultExpandLevel) {
|
|
104
|
+
setNodeExpanded(item, true);
|
|
107
105
|
}
|
|
108
|
-
if (defaultExpandKeys) {
|
|
109
|
-
|
|
110
|
-
setNodeExpanded(item, true);
|
|
111
|
-
}
|
|
106
|
+
if (defaultExpandKeys?.includes(rowKeyGen(item))) {
|
|
107
|
+
setNodeExpanded(item, true);
|
|
112
108
|
}
|
|
113
|
-
if (!item.
|
|
109
|
+
if (!item.__T_EXP__) {
|
|
114
110
|
continue;
|
|
115
111
|
}
|
|
116
112
|
}
|
|
@@ -127,7 +123,7 @@ export function useTree({ props, dataSourceCopy, rowKeyGen, emits }: Option<DT>)
|
|
|
127
123
|
row.children.forEach((child: DT) => {
|
|
128
124
|
result.push(child);
|
|
129
125
|
const childLv = level + 1;
|
|
130
|
-
if (child.
|
|
126
|
+
if (child.__T_EXP__ && child.children) {
|
|
131
127
|
const res = expandNode(child, childLv);
|
|
132
128
|
result = result.concat(res);
|
|
133
129
|
} else {
|