tomtaw-vxe-table 3.25.2 → 3.25.4
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/es/style.css +1 -1
- package/es/table/src/body.js +5 -7
- package/es/table/src/expand-height.js +108 -0
- package/es/table/src/methods.js +65 -18
- package/es/ui/index.js +1 -1
- package/es/ui/src/log.js +1 -1
- package/lib/index.umd.js +336 -21
- package/lib/index.umd.min.js +1 -1
- package/lib/style.css +1 -1
- package/lib/table/src/body.js +3 -7
- package/lib/table/src/body.min.js +1 -1
- package/lib/table/src/expand-height.js +118 -0
- package/lib/table/src/expand-height.min.js +1 -0
- package/lib/table/src/methods.js +13 -10
- package/lib/table/src/methods.min.js +1 -1
- package/lib/ui/index.js +1 -1
- package/lib/ui/index.min.js +1 -1
- package/lib/ui/src/log.js +1 -1
- package/lib/ui/src/log.min.js +1 -1
- package/package.json +2 -2
- package/packages/table/src/body.ts +5 -7
- package/packages/table/src/expand-height.ts +108 -0
- package/packages/table/src/methods.ts +66 -18
- package/types/all.d.ts +13 -0
- /package/es/{iconfont.1791960929606.ttf → iconfont.1792027709716.ttf} +0 -0
- /package/es/{iconfont.1791960929606.woff → iconfont.1792027709716.woff} +0 -0
- /package/es/{iconfont.1791960929606.woff2 → iconfont.1792027709716.woff2} +0 -0
- /package/lib/{iconfont.1791960929606.ttf → iconfont.1792027709716.ttf} +0 -0
- /package/lib/{iconfont.1791960929606.woff → iconfont.1792027709716.woff} +0 -0
- /package/lib/{iconfont.1791960929606.woff2 → iconfont.1792027709716.woff2} +0 -0
package/es/table/src/body.js
CHANGED
|
@@ -3,6 +3,7 @@ import { VxeUI } from '../../ui';
|
|
|
3
3
|
import { defineVxeComponent } from '../../ui/src/comp';
|
|
4
4
|
import { isEnableConf, getClass, getDefaultConfig, hasEnableConf } from '../../ui/src/utils';
|
|
5
5
|
import { getRowid, createHandleGetRowId, getCellRestHeight } from './util';
|
|
6
|
+
import { getRowExpandHeight } from './expand-height';
|
|
6
7
|
import { updateCellTitle } from '../../ui/src/dom';
|
|
7
8
|
import { getSlotVNs } from '../../ui/src/vn';
|
|
8
9
|
const { getI18n, renderer, renderEmptyElement } = VxeUI;
|
|
@@ -572,13 +573,10 @@ function renderRows(h, _vm, fixedType, isOptimizeMode, tableData, tableColumn) {
|
|
|
572
573
|
const expandOpts = $xeTable.computeExpandOpts;
|
|
573
574
|
const { height: expandHeight, padding, mode: expandMode } = expandOpts;
|
|
574
575
|
if (expandMode === 'fixed') {
|
|
575
|
-
|
|
576
|
-
|
|
577
|
-
|
|
578
|
-
|
|
579
|
-
expHeight = (currExpHeight || expandHeight || 0) + 1;
|
|
580
|
-
}
|
|
581
|
-
}
|
|
576
|
+
// 与位置及总高度计算共用同一规则;估算不改变展开内容的自然高度。
|
|
577
|
+
const expHeight = rowExpandHeightFlag || expandOpts.estimateHeight
|
|
578
|
+
? getRowExpandHeight($xeTable, row, rowRest)
|
|
579
|
+
: 0;
|
|
582
580
|
rows.push(h('tr', {
|
|
583
581
|
class: 'vxe-body--row-expanded-place',
|
|
584
582
|
key: `expand_${rowid}`,
|
|
@@ -0,0 +1,108 @@
|
|
|
1
|
+
const estimateValues = new WeakMap();
|
|
2
|
+
/** 仅缓存当前挂载的展开区。没有完整观察能力时保留同步测量路径。 */
|
|
3
|
+
export function createExpandHeightCache($table, onResize) {
|
|
4
|
+
const entries = new Map();
|
|
5
|
+
let disposed = false;
|
|
6
|
+
let queued = false;
|
|
7
|
+
const supported = typeof ResizeObserver !== 'undefined' && typeof MutationObserver !== 'undefined';
|
|
8
|
+
const observer = supported
|
|
9
|
+
? new ResizeObserver(records => {
|
|
10
|
+
let changed = false;
|
|
11
|
+
records.forEach(record => {
|
|
12
|
+
const entry = entries.get(record.target);
|
|
13
|
+
if (entry) {
|
|
14
|
+
entry.dirty = true;
|
|
15
|
+
changed = true;
|
|
16
|
+
}
|
|
17
|
+
});
|
|
18
|
+
if (changed && !queued && !disposed) {
|
|
19
|
+
queued = true;
|
|
20
|
+
$table.$nextTick(() => {
|
|
21
|
+
queued = false;
|
|
22
|
+
if (!disposed)
|
|
23
|
+
onResize();
|
|
24
|
+
});
|
|
25
|
+
}
|
|
26
|
+
})
|
|
27
|
+
: null;
|
|
28
|
+
// 内容/样式变化先失效,避免下一次滚动发生在 ResizeObserver 通知之前。
|
|
29
|
+
const mutations = supported
|
|
30
|
+
? new MutationObserver(records => {
|
|
31
|
+
entries.forEach((entry, element) => {
|
|
32
|
+
if (records.some(record => element === record.target || element.contains(record.target))) {
|
|
33
|
+
entry.dirty = true;
|
|
34
|
+
}
|
|
35
|
+
});
|
|
36
|
+
})
|
|
37
|
+
: null;
|
|
38
|
+
let container = null;
|
|
39
|
+
let width = -1;
|
|
40
|
+
$table.$once('hook:beforeDestroy', () => {
|
|
41
|
+
disposed = true;
|
|
42
|
+
if (observer)
|
|
43
|
+
observer.disconnect();
|
|
44
|
+
if (mutations)
|
|
45
|
+
mutations.disconnect();
|
|
46
|
+
entries.clear();
|
|
47
|
+
container = null;
|
|
48
|
+
});
|
|
49
|
+
return {
|
|
50
|
+
sync(element) {
|
|
51
|
+
const nextWidth = element.clientWidth;
|
|
52
|
+
if (container !== element) {
|
|
53
|
+
if (mutations) {
|
|
54
|
+
mutations.disconnect();
|
|
55
|
+
mutations.observe(element, { subtree: true, childList: true, attributes: true, characterData: true });
|
|
56
|
+
}
|
|
57
|
+
container = element;
|
|
58
|
+
width = -1;
|
|
59
|
+
}
|
|
60
|
+
entries.forEach((entry, child) => {
|
|
61
|
+
if (child.parentElement !== element) {
|
|
62
|
+
if (observer)
|
|
63
|
+
observer.unobserve(child);
|
|
64
|
+
entries.delete(child);
|
|
65
|
+
}
|
|
66
|
+
else if (nextWidth !== width) {
|
|
67
|
+
entry.dirty = true;
|
|
68
|
+
}
|
|
69
|
+
});
|
|
70
|
+
width = nextWidth;
|
|
71
|
+
},
|
|
72
|
+
measure(element, binding, scrolling) {
|
|
73
|
+
const previous = entries.get(element);
|
|
74
|
+
if (observer && scrolling && previous && previous.binding === binding && previous.height === binding.expandHeight && !previous.dirty) {
|
|
75
|
+
return previous.height;
|
|
76
|
+
}
|
|
77
|
+
const height = element.offsetHeight;
|
|
78
|
+
entries.set(element, { binding, height, dirty: false });
|
|
79
|
+
if (observer && !previous) {
|
|
80
|
+
// 旧实现不支持 box 选项时继续使用原有同步读取,不缓存滚动测量。
|
|
81
|
+
try {
|
|
82
|
+
observer.observe(element, { box: 'border-box' });
|
|
83
|
+
}
|
|
84
|
+
catch (e) {
|
|
85
|
+
entries.delete(element);
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
return height;
|
|
89
|
+
}
|
|
90
|
+
};
|
|
91
|
+
}
|
|
92
|
+
/** 估算只用于未测量的占位及滚动几何,不约束展开内容的实际 CSS 高度。 */
|
|
93
|
+
export function getRowExpandHeight($table, row, record) {
|
|
94
|
+
const options = $table.computeExpandOpts;
|
|
95
|
+
let estimatedHeight = 0;
|
|
96
|
+
if (!options.height && options.mode === 'fixed' && options.estimateHeight) {
|
|
97
|
+
const estimate = options.estimateHeight({ row, $table });
|
|
98
|
+
if (typeof estimate === 'number' && Number.isFinite(estimate) && estimate >= 0) {
|
|
99
|
+
// 例如未挂载子表的条数变化:不能继续使用旧条数的实测高度。
|
|
100
|
+
const previous = estimateValues.get(record);
|
|
101
|
+
if (previous !== undefined && previous !== estimate)
|
|
102
|
+
record.expandHeight = 0;
|
|
103
|
+
estimateValues.set(record, estimate);
|
|
104
|
+
estimatedHeight = estimate;
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
return record.expandHeight || options.height || estimatedHeight;
|
|
108
|
+
}
|
package/es/table/src/methods.js
CHANGED
|
@@ -8,6 +8,7 @@ import { getSlotVNs } from '../../ui/src/vn';
|
|
|
8
8
|
import { moveRowAnimateToTb, clearRowAnimate, moveColAnimateToLr, clearColAnimate } from '../../ui/src/anime';
|
|
9
9
|
import { createComponentLog } from '../../ui/src/log';
|
|
10
10
|
import { getCrossTableDragRowInfo } from './store';
|
|
11
|
+
import { createExpandHeightCache, getRowExpandHeight } from './expand-height';
|
|
11
12
|
const { warnLog, errLog } = createComponentLog('table');
|
|
12
13
|
const { getConfig, getI18n, renderer, formats, interceptor, createEvent, globalEvents, GLOBAL_EVENT_KEYS } = VxeUI;
|
|
13
14
|
const supportMaxRow = 5e6;
|
|
@@ -16,7 +17,10 @@ const maxYHeight = 5e6;
|
|
|
16
17
|
const maxXWidth = 5e6;
|
|
17
18
|
const sourceType = 'table';
|
|
18
19
|
// 仅合并等待同一轮 DOM 更新的展开行位置重算,不保留表格实例。
|
|
19
|
-
const pendingExpandOffsetUpdates = new
|
|
20
|
+
const pendingExpandOffsetUpdates = new WeakMap();
|
|
21
|
+
const expandHeightCaches = new WeakMap();
|
|
22
|
+
// 仅高度变化可复用前缀;排序、筛选等原有调用仍完整重建索引。
|
|
23
|
+
const rowOffsetIndexes = new WeakMap();
|
|
20
24
|
let crossTableDragRowObj = null;
|
|
21
25
|
function eqCellValue(newRow, oldRow, field) {
|
|
22
26
|
const val1 = XEUtils.get(newRow, field);
|
|
@@ -4283,7 +4287,7 @@ function updateColumnOffsetLeft($xeTable) {
|
|
|
4283
4287
|
offsetLeft += column.renderWidth;
|
|
4284
4288
|
}
|
|
4285
4289
|
}
|
|
4286
|
-
function updateRowOffsetTop($xeTable) {
|
|
4290
|
+
function updateRowOffsetTop($xeTable, dirtyIndex = 0) {
|
|
4287
4291
|
const reactData = $xeTable;
|
|
4288
4292
|
const internalData = $xeTable;
|
|
4289
4293
|
const { expandColumn } = reactData;
|
|
@@ -4292,28 +4296,41 @@ function updateRowOffsetTop($xeTable) {
|
|
|
4292
4296
|
if (!el || !el.clientWidth) {
|
|
4293
4297
|
return;
|
|
4294
4298
|
}
|
|
4295
|
-
const expandOpts = $xeTable.computeExpandOpts;
|
|
4296
4299
|
const rowOpts = $xeTable.computeRowOpts;
|
|
4297
4300
|
const cellOpts = $xeTable.computeCellOpts;
|
|
4298
4301
|
const defaultRowHeight = $xeTable.computeDefaultRowHeight;
|
|
4299
4302
|
const { handleGetRowId } = createHandleGetRowId($xeTable);
|
|
4300
|
-
|
|
4301
|
-
|
|
4303
|
+
const previous = rowOffsetIndexes.get($xeTable);
|
|
4304
|
+
let startIndex = previous && previous.rows === afterFullData && previous.cache === fullAllDataRowIdData
|
|
4305
|
+
? Math.max(0, Math.min(dirtyIndex, afterFullData.length))
|
|
4306
|
+
: 0;
|
|
4307
|
+
const firstRow = afterFullData[startIndex];
|
|
4308
|
+
const firstRest = firstRow ? fullAllDataRowIdData[handleGetRowId(firstRow)] : null;
|
|
4309
|
+
if (startIndex && (!firstRest || !Number.isFinite(firstRest.oTop)))
|
|
4310
|
+
startIndex = 0;
|
|
4311
|
+
const indexes = startIndex && previous ? previous.indexes : new Map();
|
|
4312
|
+
let offsetTop = startIndex && firstRest ? firstRest.oTop : 0;
|
|
4313
|
+
for (let rIndex = startIndex, rLen = afterFullData.length; rIndex < rLen; rIndex++) {
|
|
4302
4314
|
const row = afterFullData[rIndex];
|
|
4303
4315
|
const rowid = handleGetRowId(row);
|
|
4304
4316
|
const rowRest = fullAllDataRowIdData[rowid] || {};
|
|
4317
|
+
if (expandColumn)
|
|
4318
|
+
indexes.set(rowid, rIndex);
|
|
4305
4319
|
rowRest.oTop = offsetTop;
|
|
4306
4320
|
offsetTop += getCellRestHeight(rowRest, cellOpts, rowOpts, defaultRowHeight);
|
|
4307
4321
|
// 是否展开行
|
|
4308
4322
|
if (expandColumn && rowExpandedMaps[rowid]) {
|
|
4309
|
-
offsetTop +=
|
|
4323
|
+
offsetTop += getRowExpandHeight($xeTable, row, rowRest);
|
|
4310
4324
|
}
|
|
4311
4325
|
}
|
|
4326
|
+
rowOffsetIndexes.set($xeTable, { rows: afterFullData, cache: fullAllDataRowIdData, indexes });
|
|
4327
|
+
// 完整重算也覆盖了此前排队的高度变化,避免下一轮重复计算。
|
|
4328
|
+
pendingExpandOffsetUpdates.delete($xeTable);
|
|
4312
4329
|
}
|
|
4313
4330
|
/**
|
|
4314
4331
|
* 更新展开行样式
|
|
4315
4332
|
*/
|
|
4316
|
-
function updateRowExpandStyle($xeTable) {
|
|
4333
|
+
function updateRowExpandStyle($xeTable, forceMeasure = false) {
|
|
4317
4334
|
const reactData = $xeTable;
|
|
4318
4335
|
const internalData = $xeTable;
|
|
4319
4336
|
const { expandColumn, scrollYLoad, scrollYTop, isScrollYBig } = reactData;
|
|
@@ -4331,7 +4348,20 @@ function updateRowExpandStyle($xeTable) {
|
|
|
4331
4348
|
const rowExpandEl = $xeTable.$refs.refRowExpandElem;
|
|
4332
4349
|
const bodyScrollElem = getRefElem(elemStore['main-body-scroll']);
|
|
4333
4350
|
if (rowExpandEl && bodyScrollElem) {
|
|
4351
|
+
const previousHeightCache = expandHeightCaches.get($xeTable);
|
|
4352
|
+
const heightCache = previousHeightCache || createExpandHeightCache($xeTable, () => updateRowExpandStyle($xeTable, true));
|
|
4353
|
+
if (!previousHeightCache) {
|
|
4354
|
+
$xeTable.$once('hook:beforeDestroy', () => {
|
|
4355
|
+
pendingExpandOffsetUpdates.delete($xeTable);
|
|
4356
|
+
rowOffsetIndexes.delete($xeTable);
|
|
4357
|
+
expandHeightCaches.delete($xeTable);
|
|
4358
|
+
});
|
|
4359
|
+
}
|
|
4360
|
+
expandHeightCaches.set($xeTable, heightCache);
|
|
4361
|
+
heightCache.sync(rowExpandEl);
|
|
4334
4362
|
let isUpdateHeight = false;
|
|
4363
|
+
let dirtyIndex = Infinity;
|
|
4364
|
+
const offsetIndex = rowOffsetIndexes.get($xeTable);
|
|
4335
4365
|
const expandStyles = [];
|
|
4336
4366
|
// 先集中读取尺寸,避免每个展开区写 top 后又读取下一个展开区的布局。
|
|
4337
4367
|
XEUtils.arrayEach(rowExpandEl.children, reEl => {
|
|
@@ -4339,7 +4369,7 @@ function updateRowExpandStyle($xeTable) {
|
|
|
4339
4369
|
const rowid = expandEl.getAttribute('rowid') || '';
|
|
4340
4370
|
const rowRest = fullAllDataRowIdData[rowid];
|
|
4341
4371
|
if (rowRest) {
|
|
4342
|
-
const expandHeight = expandEl.
|
|
4372
|
+
const expandHeight = heightCache.measure(expandEl, rowRest, !!internalData.inVirtualScroll && !forceMeasure);
|
|
4343
4373
|
// 普通虚拟滚动使用缓存位置,无需为每个展开区查询主表行 DOM。
|
|
4344
4374
|
const trEl = !scrollYLoad || isScrollYBig
|
|
4345
4375
|
? bodyScrollElem.querySelector(`.vxe-body--row[rowid="${rowid}"]`)
|
|
@@ -4362,10 +4392,12 @@ function updateRowExpandStyle($xeTable) {
|
|
|
4362
4392
|
offsetTop += scrollYTop;
|
|
4363
4393
|
}
|
|
4364
4394
|
expandStyles.push({ el: expandEl, top: toCssUnit(offsetTop) });
|
|
4365
|
-
if (
|
|
4366
|
-
|
|
4367
|
-
|
|
4368
|
-
|
|
4395
|
+
if (rowRest.expandHeight !== expandHeight) {
|
|
4396
|
+
isUpdateHeight = true;
|
|
4397
|
+
const index = offsetIndex && offsetIndex.rows === internalData.afterFullData && offsetIndex.cache === fullAllDataRowIdData
|
|
4398
|
+
? offsetIndex.indexes.get(rowid)
|
|
4399
|
+
: undefined;
|
|
4400
|
+
dirtyIndex = Math.min(dirtyIndex, index === undefined ? 0 : index);
|
|
4369
4401
|
}
|
|
4370
4402
|
rowRest.expandHeight = expandHeight;
|
|
4371
4403
|
}
|
|
@@ -4377,11 +4409,19 @@ function updateRowExpandStyle($xeTable) {
|
|
|
4377
4409
|
});
|
|
4378
4410
|
if (isUpdateHeight) {
|
|
4379
4411
|
reactData.rowExpandHeightFlag++;
|
|
4380
|
-
|
|
4381
|
-
|
|
4412
|
+
const pendingIndex = pendingExpandOffsetUpdates.get($xeTable);
|
|
4413
|
+
pendingExpandOffsetUpdates.set($xeTable, Math.min(pendingIndex === undefined ? Infinity : pendingIndex, dirtyIndex));
|
|
4414
|
+
if (pendingIndex === undefined) {
|
|
4382
4415
|
$xeTable.$nextTick(() => {
|
|
4383
|
-
pendingExpandOffsetUpdates.
|
|
4384
|
-
|
|
4416
|
+
const index = pendingExpandOffsetUpdates.get($xeTable);
|
|
4417
|
+
if (index !== undefined) {
|
|
4418
|
+
pendingExpandOffsetUpdates.delete($xeTable);
|
|
4419
|
+
updateRowOffsetTop($xeTable, index);
|
|
4420
|
+
updateRowExpandStyle($xeTable);
|
|
4421
|
+
$xeTable.updateScrollYSpace();
|
|
4422
|
+
if (reactData.scrollYLoad)
|
|
4423
|
+
loadScrollYData($xeTable);
|
|
4424
|
+
}
|
|
4385
4425
|
});
|
|
4386
4426
|
}
|
|
4387
4427
|
}
|
|
@@ -7482,6 +7522,14 @@ const tableMethods = {
|
|
|
7482
7522
|
const isForce = !!reFull;
|
|
7483
7523
|
return handleLazyRecalculate($xeTable, isForce, isForce, isForce);
|
|
7484
7524
|
},
|
|
7525
|
+
refreshRowExpandHeight() {
|
|
7526
|
+
const $xeTable = this;
|
|
7527
|
+
return $xeTable.$nextTick().then(() => {
|
|
7528
|
+
updateRowExpandStyle($xeTable, true);
|
|
7529
|
+
// 等待同一轮高度变化的位置重算及其 DOM 更新。
|
|
7530
|
+
return $xeTable.$nextTick().then(() => $xeTable.$nextTick());
|
|
7531
|
+
});
|
|
7532
|
+
},
|
|
7485
7533
|
updateStyle() {
|
|
7486
7534
|
const $xeTable = this;
|
|
7487
7535
|
return updateStyle($xeTable);
|
|
@@ -12903,7 +12951,6 @@ const tableMethods = {
|
|
|
12903
12951
|
const $xeGanttView = internalData.xeGanttView;
|
|
12904
12952
|
const { startIndex } = scrollYStore;
|
|
12905
12953
|
const mouseOpts = $xeTable.computeMouseOpts;
|
|
12906
|
-
const expandOpts = $xeTable.computeExpandOpts;
|
|
12907
12954
|
const rowOpts = $xeTable.computeRowOpts;
|
|
12908
12955
|
const cellOpts = $xeTable.computeCellOpts;
|
|
12909
12956
|
const defaultRowHeight = $xeTable.computeDefaultRowHeight;
|
|
@@ -12940,7 +12987,7 @@ const tableMethods = {
|
|
|
12940
12987
|
sYHeight = (rowRest.oTop || 0) + rHeight;
|
|
12941
12988
|
// 是否展开行
|
|
12942
12989
|
if (expandColumn && rowExpandedMaps[rowid]) {
|
|
12943
|
-
sYHeight +=
|
|
12990
|
+
sYHeight += getRowExpandHeight($xeTable, lastRow, rowRest);
|
|
12944
12991
|
}
|
|
12945
12992
|
}
|
|
12946
12993
|
}
|
package/es/ui/index.js
CHANGED
package/es/ui/src/log.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { VxeUI } from '@vxe-ui/core';
|
|
2
2
|
const { log } = VxeUI;
|
|
3
|
-
const tableVersion = `table v${"3.25.
|
|
3
|
+
const tableVersion = `table v${"3.25.4"}`;
|
|
4
4
|
export function createComponentLog(name) {
|
|
5
5
|
const uiVersion = VxeUI.uiVersion ? `ui v${VxeUI.uiVersion}` : '';
|
|
6
6
|
const ganttVersion = VxeUI.ganttVersion ? `gantt v${VxeUI.ganttVersion}` : '';
|