@guozhi5658/srp-table 1.0.0 → 1.1.0

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.
@@ -0,0 +1,9 @@
1
+ import { ArtColumn } from '../../interfaces';
2
+ import { HorizontalRenderRange, VisibleColumnDescriptor } from '../interfaces';
3
+ export declare function getMaximumColSpan(params: {
4
+ column: ArtColumn;
5
+ colIndex: number;
6
+ leftFlatCount: number;
7
+ horizontalRenderRange: HorizontalRenderRange;
8
+ visible: VisibleColumnDescriptor[];
9
+ }): number;
@@ -7,6 +7,38 @@ import * as styled from 'styled-components';
7
7
  import styled__default, { css } from 'styled-components';
8
8
  import ResizeObserver from 'resize-observer-polyfill';
9
9
 
10
+ /******************************************************************************
11
+ Copyright (c) Microsoft Corporation.
12
+
13
+ Permission to use, copy, modify, and/or distribute this software for any
14
+ purpose with or without fee is hereby granted.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
17
+ REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
18
+ AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
19
+ INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
20
+ LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
21
+ OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
22
+ PERFORMANCE OF THIS SOFTWARE.
23
+ ***************************************************************************** */
24
+
25
+ function __rest(s, e) {
26
+ var t = {};
27
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
28
+ t[p] = s[p];
29
+ if (s != null && typeof Object.getOwnPropertySymbols === "function")
30
+ for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
31
+ if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
32
+ t[p[i]] = s[p[i]];
33
+ }
34
+ return t;
35
+ }
36
+
37
+ typeof SuppressedError === "function" ? SuppressedError : function (error, suppressed, message) {
38
+ var e = new Error(message);
39
+ return e.name = "SuppressedError", e.error = error, e.suppressed = suppressed, e;
40
+ };
41
+
10
42
  function isLeafNode(node) {
11
43
  return node.children == null || node.children.length === 0;
12
44
  }
@@ -227,6 +259,47 @@ function mergeCellProps(base, extra) {
227
259
  return result;
228
260
  }
229
261
 
262
+ const FEATURE_KEY = 'fillRemainingWidth';
263
+ function isFillRemainingWidthColumn(column) {
264
+ var _a;
265
+ return Boolean((_a = column === null || column === void 0 ? void 0 : column.features) === null || _a === void 0 ? void 0 : _a[FEATURE_KEY]);
266
+ }
267
+ function getColumnLogicWidth(column) {
268
+ var _a;
269
+ return isFillRemainingWidthColumn(column) ? 0 : (_a = column.width) !== null && _a !== void 0 ? _a : 0;
270
+ }
271
+ function takeFillRemainingWidthColumn(columns) {
272
+ const fillIndex = columns.findIndex(isFillRemainingWidthColumn);
273
+ if (fillIndex < 0) {
274
+ return { columns, fillColumn: null };
275
+ }
276
+ return {
277
+ columns: columns.filter((_, index) => index !== fillIndex),
278
+ fillColumn: columns[fillIndex],
279
+ };
280
+ }
281
+ function appendFillRemainingWidthColumn(columns, extra = {}) {
282
+ const normalized = columns.filter((column) => !isFillRemainingWidthColumn(column));
283
+ const fillColumn = createFillRemainingWidthColumn(extra);
284
+ let rightLockStart = normalized.length;
285
+ while (rightLockStart > 0 && isLockColumn(normalized[rightLockStart - 1])) {
286
+ rightLockStart -= 1;
287
+ }
288
+ return [...normalized.slice(0, rightLockStart), fillColumn, ...normalized.slice(rightLockStart)];
289
+ }
290
+ function createFillRemainingWidthColumn(extra = {}) {
291
+ const { features } = extra, rest = __rest(extra, ["features"]);
292
+ return Object.assign(Object.assign({ name: '', title: '' }, rest), { lock: false, width: undefined, getValue() {
293
+ return '';
294
+ }, features: Object.assign(Object.assign({ noExport: true }, features), { [FEATURE_KEY]: true }) });
295
+ }
296
+ function isLockColumn(column) {
297
+ if (isLeafNode(column)) {
298
+ return Boolean(column.lock);
299
+ }
300
+ return Boolean(column.lock || column.children.some(isLockColumn));
301
+ }
302
+
230
303
  /** styled-components 类库的版本,srp-table 同时支持 v3 和 v5 */
231
304
  const STYLED_VERSION = styled.createGlobalStyle != null ? 'v5' : 'v3';
232
305
  const STYLED_REF_PROP = STYLED_VERSION === 'v3' ? 'innerRef' : 'ref';
@@ -358,7 +431,7 @@ function processColumns(columns, defaultColumnWidth) {
358
431
  function dfs(columns) {
359
432
  const result = [];
360
433
  for (let column of columns) {
361
- if (column.width == null) {
434
+ if (column.width == null && !isFillRemainingWidthColumn(column)) {
362
435
  if (defaultColumnWidth != null) {
363
436
  column = Object.assign(Object.assign({}, column), { width: defaultColumnWidth });
364
437
  }
@@ -407,20 +480,21 @@ function getLeftNestedLockCount(columns) {
407
480
  }
408
481
  }
409
482
  }
410
- function getHorizontalRenderRange({ offsetX, maxRenderWidth, flat, useVirtual, }) {
483
+ function getHorizontalRenderRange({ offsetX, maxRenderWidth, center, useVirtual, }) {
411
484
  if (!useVirtual.horizontal) {
412
- return { leftIndex: 0, leftBlank: 0, rightIndex: flat.full.length, rightBlank: 0 };
485
+ return { leftIndex: 0, leftBlank: 0, rightIndex: center.length, rightBlank: 0 };
413
486
  }
414
487
  let leftIndex = 0;
415
488
  let centerCount = 0;
416
489
  let leftBlank = 0;
417
490
  let centerRenderWidth = 0;
418
491
  const overscannedOffsetX = Math.max(0, offsetX - OVERSCAN_SIZE);
419
- while (leftIndex < flat.center.length) {
420
- const col = flat.center[leftIndex];
421
- if (col.width + leftBlank < overscannedOffsetX) {
492
+ while (leftIndex < center.length) {
493
+ const col = center[leftIndex];
494
+ const colWidth = getColumnLogicWidth(col);
495
+ if (colWidth + leftBlank < overscannedOffsetX) {
422
496
  leftIndex += 1;
423
- leftBlank += col.width;
497
+ leftBlank += colWidth;
424
498
  }
425
499
  else {
426
500
  break;
@@ -428,18 +502,19 @@ function getHorizontalRenderRange({ offsetX, maxRenderWidth, flat, useVirtual, }
428
502
  }
429
503
  // 考虑 over scan 之后,中间部分的列至少需要渲染的宽度
430
504
  const minCenterRenderWidth = maxRenderWidth + (overscannedOffsetX - leftBlank) + 2 * OVERSCAN_SIZE;
431
- while (leftIndex + centerCount < flat.center.length) {
432
- const col = flat.center[leftIndex + centerCount];
433
- if (col.width + centerRenderWidth < minCenterRenderWidth) {
434
- centerRenderWidth += col.width;
505
+ while (leftIndex + centerCount < center.length) {
506
+ const col = center[leftIndex + centerCount];
507
+ const colWidth = getColumnLogicWidth(col);
508
+ if (colWidth + centerRenderWidth < minCenterRenderWidth) {
509
+ centerRenderWidth += colWidth;
435
510
  centerCount += 1;
436
511
  }
437
512
  else {
438
513
  break;
439
514
  }
440
515
  }
441
- const rightBlankCount = flat.center.length - leftIndex - centerCount;
442
- const rightBlank = sum(flat.center.slice(flat.center.length - rightBlankCount).map((col) => col.width));
516
+ const rightBlankCount = center.length - leftIndex - centerCount;
517
+ const rightBlank = sum(center.slice(center.length - rightBlankCount).map(getColumnLogicWidth));
443
518
  return {
444
519
  leftIndex: leftIndex,
445
520
  leftBlank,
@@ -455,6 +530,7 @@ function calculateRenderInfo(table) {
455
530
  const columns = processColumns(columnsProp, defaultColumnWidth);
456
531
  const leftNestedLockCount = getLeftNestedLockCount(columns);
457
532
  const fullFlat = collectNodes(columns, 'leaf-only');
533
+ const { columns: fullFlatWithoutFill } = takeFillRemainingWidthColumn(fullFlat);
458
534
  let flat;
459
535
  let nested;
460
536
  let useVirtual;
@@ -468,7 +544,7 @@ function calculateRenderInfo(table) {
468
544
  const rightNestedLockCount = getLeftNestedLockCount(columns.slice().reverse());
469
545
  const centerNested = columns.slice(leftNestedLockCount, columns.length - rightNestedLockCount);
470
546
  const rightNested = columns.slice(columns.length - rightNestedLockCount);
471
- const shouldEnableHozVirtual = fullFlat.length >= hozVirtualThreshold && fullFlat.every((col) => col.width != null);
547
+ const shouldEnableHozVirtual = fullFlat.length >= hozVirtualThreshold && fullFlatWithoutFill.every((col) => col.width != null);
472
548
  const shouldEnableVerVirtual = dataSourceProp.length >= verVirtualThreshold;
473
549
  useVirtual = {
474
550
  horizontal: resolveVirtualEnabled(typeof useVirtualProp === 'object' ? useVirtualProp.horizontal : useVirtualProp, shouldEnableHozVirtual),
@@ -488,16 +564,22 @@ function calculateRenderInfo(table) {
488
564
  center: centerNested,
489
565
  };
490
566
  }
491
- const horizontalRenderRange = getHorizontalRenderRange({ maxRenderWidth, offsetX, useVirtual, flat });
567
+ const { columns: centerFlat, fillColumn: centerFillColumn } = takeFillRemainingWidthColumn(flat.center);
568
+ const horizontalRenderRange = getHorizontalRenderRange({ maxRenderWidth, offsetX, useVirtual, center: centerFlat });
492
569
  const verticalRenderRange = table.getVerticalRenderRange(useVirtual);
493
570
  const { leftBlank, leftIndex, rightBlank, rightIndex } = horizontalRenderRange;
494
571
  const unfilteredVisibleColumnDescriptors = [
495
572
  ...flat.left.map((col, i) => ({ type: 'normal', col, colIndex: i })),
496
573
  leftBlank > 0 && { type: 'blank', blankSide: 'left', width: leftBlank },
497
- ...flat.center
574
+ ...centerFlat
498
575
  .slice(leftIndex, rightIndex)
499
576
  .map((col, i) => ({ type: 'normal', col, colIndex: flat.left.length + leftIndex + i })),
500
577
  rightBlank > 0 && { type: 'blank', blankSide: 'right', width: rightBlank },
578
+ centerFillColumn && {
579
+ type: 'normal',
580
+ col: centerFillColumn,
581
+ colIndex: fullFlat.indexOf(centerFillColumn),
582
+ },
501
583
  ...flat.right.map((col, i) => ({ type: 'normal', col, colIndex: flat.full.length - flat.right.length + i })),
502
584
  ];
503
585
  const visibleColumnDescriptors = unfilteredVisibleColumnDescriptors.filter(Boolean);
@@ -508,16 +590,16 @@ function calculateRenderInfo(table) {
508
590
  let stickyLeft = 0;
509
591
  for (let i = 0; i < leftFlatCount; i++) {
510
592
  stickyLeftMap.set(i, stickyLeft);
511
- stickyLeft += flat.full[i].width;
593
+ stickyLeft += getColumnLogicWidth(flat.full[i]);
512
594
  }
513
595
  const stickyRightMap = new Map();
514
596
  let stickyRight = 0;
515
597
  for (let i = 0; i < rightFlatCount; i++) {
516
598
  stickyRightMap.set(fullFlatCount - 1 - i, stickyRight);
517
- stickyRight += flat.full[fullFlatCount - 1 - i].width;
599
+ stickyRight += getColumnLogicWidth(flat.full[fullFlatCount - 1 - i]);
518
600
  }
519
- const leftLockTotalWidth = sum(flat.left.map((col) => col.width));
520
- const rightLockTotalWidth = sum(flat.right.map((col) => col.width));
601
+ const leftLockTotalWidth = sum(flat.left.map(getColumnLogicWidth));
602
+ const rightLockTotalWidth = sum(flat.right.map(getColumnLogicWidth));
521
603
  return {
522
604
  horizontalRenderRange,
523
605
  verticalRenderRange,
@@ -1045,8 +1127,12 @@ function attachColIndex(inputNested, colIndexOffset) {
1045
1127
  function calculateHeaderRenderInfo({ flat, nested, horizontalRenderRange: hoz, useVirtual }, rowCount) {
1046
1128
  if (useVirtual.header) {
1047
1129
  const leftPart = calculateLeveledAndFlat(attachColIndex(nested.left, 0), rowCount);
1048
- const filtered = filterNestedCenter(nested.center, hoz, flat.left.length);
1130
+ const { columns: centerNested, fillColumn } = takeFillRemainingWidthColumn(nested.center);
1131
+ const filtered = filterNestedCenter(centerNested, hoz, flat.left.length);
1049
1132
  const centerPart = calculateLeveledAndFlat(filtered, rowCount);
1133
+ const fillPart = fillColumn == null
1134
+ ? { flat: [], leveled: range(rowCount).map(() => []) }
1135
+ : calculateLeveledAndFlat(attachColIndex([fillColumn], flat.left.length + flat.center.length - 1), rowCount);
1050
1136
  const rightPart = calculateLeveledAndFlat(attachColIndex(nested.right, flat.left.length + flat.center.length), rowCount);
1051
1137
  return {
1052
1138
  flat: [
@@ -1054,6 +1140,7 @@ function calculateHeaderRenderInfo({ flat, nested, horizontalRenderRange: hoz, u
1054
1140
  { type: 'blank', width: hoz.leftBlank, blankSide: 'left' },
1055
1141
  ...centerPart.flat,
1056
1142
  { type: 'blank', width: hoz.rightBlank, blankSide: 'right' },
1143
+ ...fillPart.flat,
1057
1144
  ...rightPart.flat,
1058
1145
  ],
1059
1146
  leveled: range(rowCount).map((depth) => [
@@ -1061,6 +1148,7 @@ function calculateHeaderRenderInfo({ flat, nested, horizontalRenderRange: hoz, u
1061
1148
  { type: 'blank', width: hoz.leftBlank, blankSide: 'left' },
1062
1149
  ...centerPart.leveled[depth],
1063
1150
  { type: 'blank', width: hoz.rightBlank, blankSide: 'right' },
1151
+ ...fillPart.leveled[depth],
1064
1152
  ...rightPart.leveled[depth],
1065
1153
  ]),
1066
1154
  };
@@ -1664,6 +1752,22 @@ class TableDOMHelper {
1664
1752
  }
1665
1753
  }
1666
1754
 
1755
+ const colSpanUpperBoundDisabled = Number.POSITIVE_INFINITY;
1756
+ function getMaximumColSpan(params) {
1757
+ const { column, colIndex, leftFlatCount, horizontalRenderRange, visible } = params;
1758
+ if (isFillRemainingWidthColumn(column)) {
1759
+ return colSpanUpperBoundDisabled;
1760
+ }
1761
+ let maxColSpan = leftFlatCount + horizontalRenderRange.rightIndex - colIndex;
1762
+ const visibleFillDescriptor = visible.find((descriptor) => descriptor.type === 'normal' && isFillRemainingWidthColumn(descriptor.col));
1763
+ const visibleFillColumnIndex = visibleFillDescriptor != null && visibleFillDescriptor.type === 'normal' ? visibleFillDescriptor.colIndex : undefined;
1764
+ // fill 列只有在当前渲染窗口已经覆盖到 center 尾部时,才能安全参与跨列合并
1765
+ if (visibleFillColumnIndex != null && horizontalRenderRange.rightBlank === 0 && colIndex < visibleFillColumnIndex) {
1766
+ maxColSpan = Math.max(maxColSpan, visibleFillColumnIndex + 1 - colIndex);
1767
+ }
1768
+ return maxColSpan;
1769
+ }
1770
+
1667
1771
  function HtmlTable({ tbodyHtmlTag, getRowProps, primaryKey, data, verticalRenderInfo: verInfo, horizontalRenderInfo: hozInfo, components: { Row, Cell, TableBody }, }) {
1668
1772
  const { flat, horizontalRenderRange: hoz } = hozInfo;
1669
1773
  const spanManager = new SpanManager();
@@ -1726,7 +1830,13 @@ function HtmlTable({ tbodyHtmlTag, getRowProps, primaryKey, data, verticalRender
1726
1830
  }
1727
1831
  // rowSpan/colSpan 不能过大,避免 rowSpan/colSpan 影响因虚拟滚动而未渲染的单元格
1728
1832
  rowSpan = Math.min(rowSpan, verInfo.limit - rowIndex);
1729
- colSpan = Math.min(colSpan, leftFlatCount + hoz.rightIndex - colIndex);
1833
+ colSpan = Math.min(colSpan, getMaximumColSpan({
1834
+ column,
1835
+ colIndex,
1836
+ leftFlatCount,
1837
+ horizontalRenderRange: hoz,
1838
+ visible: hozInfo.visible,
1839
+ }));
1730
1840
  const hasSpan = colSpan > 1 || rowSpan > 1;
1731
1841
  if (hasSpan) {
1732
1842
  spanManager.add(rowIndex, colIndex, colSpan, rowSpan);
@@ -2145,7 +2255,7 @@ class BaseTable extends React.Component {
2145
2255
  const { needRenderLock } = this.state;
2146
2256
  const { flat, hasLockColumn } = this.lastInfo;
2147
2257
  if (hasLockColumn) {
2148
- const sumOfColWidth = sum(flat.full.map((col) => col.width));
2258
+ const sumOfColWidth = sum(flat.full.map(getColumnLogicWidth));
2149
2259
  const nextNeedRenderLock = sumOfColWidth > this.domHelper.artTable.clientWidth;
2150
2260
  if (needRenderLock !== nextNeedRenderLock) {
2151
2261
  this.setState({ needRenderLock: nextNeedRenderLock });
@@ -2175,38 +2285,6 @@ BaseTable.defaultProps = {
2175
2285
  dataSource: [],
2176
2286
  };
2177
2287
 
2178
- /******************************************************************************
2179
- Copyright (c) Microsoft Corporation.
2180
-
2181
- Permission to use, copy, modify, and/or distribute this software for any
2182
- purpose with or without fee is hereby granted.
2183
-
2184
- THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
2185
- REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
2186
- AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
2187
- INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
2188
- LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
2189
- OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
2190
- PERFORMANCE OF THIS SOFTWARE.
2191
- ***************************************************************************** */
2192
-
2193
- function __rest(s, e) {
2194
- var t = {};
2195
- for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
2196
- t[p] = s[p];
2197
- if (s != null && typeof Object.getOwnPropertySymbols === "function")
2198
- for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
2199
- if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
2200
- t[p[i]] = s[p[i]];
2201
- }
2202
- return t;
2203
- }
2204
-
2205
- typeof SuppressedError === "function" ? SuppressedError : function (error, suppressed, message) {
2206
- var e = new Error(message);
2207
- return e.name = "SuppressedError", e.error = error, e.suppressed = suppressed, e;
2208
- };
2209
-
2210
2288
  const InlineFlexCell = styled__default.div `
2211
2289
  display: inline-flex;
2212
2290
  align-items: center;
@@ -2514,4 +2592,4 @@ function useTablePipeline(ctx) {
2514
2592
  return new TablePipeline({ state, setState, ctx });
2515
2593
  }
2516
2594
 
2517
- export { BaseTable as B, Classes as C, ExpansionCell as E, InlineFlexCell as I, SpanManager as S, TablePipeline as T, __rest as _, internals as a, icons as b, collectNodes as c, always as d, arrayUtils as e, flatMap as f, getTreeDepth as g, treeMetaSymbol as h, isLeafNode as i, groupBy2 as j, fromEntries as k, mergeCellProps as m, treeMode as t, useTablePipeline as u };
2595
+ export { BaseTable as B, Classes as C, ExpansionCell as E, InlineFlexCell as I, SpanManager as S, TablePipeline as T, __rest as _, internals as a, appendFillRemainingWidthColumn as b, collectNodes as c, icons as d, always as e, flatMap as f, getTreeDepth as g, arrayUtils as h, isLeafNode as i, treeMode as j, treeMetaSymbol as k, groupBy2 as l, mergeCellProps as m, fromEntries as n, takeFillRemainingWidthColumn as t, useTablePipeline as u };
@@ -10,21 +10,21 @@ var ResizeObserver = require('resize-observer-polyfill');
10
10
  function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
11
11
 
12
12
  function _interopNamespace(e) {
13
- if (e && e.__esModule) return e;
14
- var n = Object.create(null);
15
- if (e) {
16
- Object.keys(e).forEach(function (k) {
17
- if (k !== 'default') {
18
- var d = Object.getOwnPropertyDescriptor(e, k);
19
- Object.defineProperty(n, k, d.get ? d : {
20
- enumerable: true,
21
- get: function () { return e[k]; }
13
+ if (e && e.__esModule) return e;
14
+ var n = Object.create(null);
15
+ if (e) {
16
+ Object.keys(e).forEach(function (k) {
17
+ if (k !== 'default') {
18
+ var d = Object.getOwnPropertyDescriptor(e, k);
19
+ Object.defineProperty(n, k, d.get ? d : {
20
+ enumerable: true,
21
+ get: function () { return e[k]; }
22
+ });
23
+ }
22
24
  });
23
- }
24
- });
25
- }
26
- n["default"] = e;
27
- return Object.freeze(n);
25
+ }
26
+ n["default"] = e;
27
+ return Object.freeze(n);
28
28
  }
29
29
 
30
30
  var cx__default = /*#__PURE__*/_interopDefaultLegacy(cx);
@@ -34,6 +34,38 @@ var styled__namespace = /*#__PURE__*/_interopNamespace(styled);
34
34
  var styled__default = /*#__PURE__*/_interopDefaultLegacy(styled);
35
35
  var ResizeObserver__default = /*#__PURE__*/_interopDefaultLegacy(ResizeObserver);
36
36
 
37
+ /******************************************************************************
38
+ Copyright (c) Microsoft Corporation.
39
+
40
+ Permission to use, copy, modify, and/or distribute this software for any
41
+ purpose with or without fee is hereby granted.
42
+
43
+ THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
44
+ REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
45
+ AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
46
+ INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
47
+ LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
48
+ OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
49
+ PERFORMANCE OF THIS SOFTWARE.
50
+ ***************************************************************************** */
51
+
52
+ function __rest(s, e) {
53
+ var t = {};
54
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
55
+ t[p] = s[p];
56
+ if (s != null && typeof Object.getOwnPropertySymbols === "function")
57
+ for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
58
+ if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
59
+ t[p[i]] = s[p[i]];
60
+ }
61
+ return t;
62
+ }
63
+
64
+ typeof SuppressedError === "function" ? SuppressedError : function (error, suppressed, message) {
65
+ var e = new Error(message);
66
+ return e.name = "SuppressedError", e.error = error, e.suppressed = suppressed, e;
67
+ };
68
+
37
69
  function isLeafNode(node) {
38
70
  return node.children == null || node.children.length === 0;
39
71
  }
@@ -254,6 +286,47 @@ function mergeCellProps(base, extra) {
254
286
  return result;
255
287
  }
256
288
 
289
+ const FEATURE_KEY = 'fillRemainingWidth';
290
+ function isFillRemainingWidthColumn(column) {
291
+ var _a;
292
+ return Boolean((_a = column === null || column === void 0 ? void 0 : column.features) === null || _a === void 0 ? void 0 : _a[FEATURE_KEY]);
293
+ }
294
+ function getColumnLogicWidth(column) {
295
+ var _a;
296
+ return isFillRemainingWidthColumn(column) ? 0 : (_a = column.width) !== null && _a !== void 0 ? _a : 0;
297
+ }
298
+ function takeFillRemainingWidthColumn(columns) {
299
+ const fillIndex = columns.findIndex(isFillRemainingWidthColumn);
300
+ if (fillIndex < 0) {
301
+ return { columns, fillColumn: null };
302
+ }
303
+ return {
304
+ columns: columns.filter((_, index) => index !== fillIndex),
305
+ fillColumn: columns[fillIndex],
306
+ };
307
+ }
308
+ function appendFillRemainingWidthColumn(columns, extra = {}) {
309
+ const normalized = columns.filter((column) => !isFillRemainingWidthColumn(column));
310
+ const fillColumn = createFillRemainingWidthColumn(extra);
311
+ let rightLockStart = normalized.length;
312
+ while (rightLockStart > 0 && isLockColumn(normalized[rightLockStart - 1])) {
313
+ rightLockStart -= 1;
314
+ }
315
+ return [...normalized.slice(0, rightLockStart), fillColumn, ...normalized.slice(rightLockStart)];
316
+ }
317
+ function createFillRemainingWidthColumn(extra = {}) {
318
+ const { features } = extra, rest = __rest(extra, ["features"]);
319
+ return Object.assign(Object.assign({ name: '', title: '' }, rest), { lock: false, width: undefined, getValue() {
320
+ return '';
321
+ }, features: Object.assign(Object.assign({ noExport: true }, features), { [FEATURE_KEY]: true }) });
322
+ }
323
+ function isLockColumn(column) {
324
+ if (isLeafNode(column)) {
325
+ return Boolean(column.lock);
326
+ }
327
+ return Boolean(column.lock || column.children.some(isLockColumn));
328
+ }
329
+
257
330
  /** styled-components 类库的版本,srp-table 同时支持 v3 和 v5 */
258
331
  const STYLED_VERSION = styled__namespace.createGlobalStyle != null ? 'v5' : 'v3';
259
332
  const STYLED_REF_PROP = STYLED_VERSION === 'v3' ? 'innerRef' : 'ref';
@@ -385,7 +458,7 @@ function processColumns(columns, defaultColumnWidth) {
385
458
  function dfs(columns) {
386
459
  const result = [];
387
460
  for (let column of columns) {
388
- if (column.width == null) {
461
+ if (column.width == null && !isFillRemainingWidthColumn(column)) {
389
462
  if (defaultColumnWidth != null) {
390
463
  column = Object.assign(Object.assign({}, column), { width: defaultColumnWidth });
391
464
  }
@@ -434,20 +507,21 @@ function getLeftNestedLockCount(columns) {
434
507
  }
435
508
  }
436
509
  }
437
- function getHorizontalRenderRange({ offsetX, maxRenderWidth, flat, useVirtual, }) {
510
+ function getHorizontalRenderRange({ offsetX, maxRenderWidth, center, useVirtual, }) {
438
511
  if (!useVirtual.horizontal) {
439
- return { leftIndex: 0, leftBlank: 0, rightIndex: flat.full.length, rightBlank: 0 };
512
+ return { leftIndex: 0, leftBlank: 0, rightIndex: center.length, rightBlank: 0 };
440
513
  }
441
514
  let leftIndex = 0;
442
515
  let centerCount = 0;
443
516
  let leftBlank = 0;
444
517
  let centerRenderWidth = 0;
445
518
  const overscannedOffsetX = Math.max(0, offsetX - OVERSCAN_SIZE);
446
- while (leftIndex < flat.center.length) {
447
- const col = flat.center[leftIndex];
448
- if (col.width + leftBlank < overscannedOffsetX) {
519
+ while (leftIndex < center.length) {
520
+ const col = center[leftIndex];
521
+ const colWidth = getColumnLogicWidth(col);
522
+ if (colWidth + leftBlank < overscannedOffsetX) {
449
523
  leftIndex += 1;
450
- leftBlank += col.width;
524
+ leftBlank += colWidth;
451
525
  }
452
526
  else {
453
527
  break;
@@ -455,18 +529,19 @@ function getHorizontalRenderRange({ offsetX, maxRenderWidth, flat, useVirtual, }
455
529
  }
456
530
  // 考虑 over scan 之后,中间部分的列至少需要渲染的宽度
457
531
  const minCenterRenderWidth = maxRenderWidth + (overscannedOffsetX - leftBlank) + 2 * OVERSCAN_SIZE;
458
- while (leftIndex + centerCount < flat.center.length) {
459
- const col = flat.center[leftIndex + centerCount];
460
- if (col.width + centerRenderWidth < minCenterRenderWidth) {
461
- centerRenderWidth += col.width;
532
+ while (leftIndex + centerCount < center.length) {
533
+ const col = center[leftIndex + centerCount];
534
+ const colWidth = getColumnLogicWidth(col);
535
+ if (colWidth + centerRenderWidth < minCenterRenderWidth) {
536
+ centerRenderWidth += colWidth;
462
537
  centerCount += 1;
463
538
  }
464
539
  else {
465
540
  break;
466
541
  }
467
542
  }
468
- const rightBlankCount = flat.center.length - leftIndex - centerCount;
469
- const rightBlank = sum(flat.center.slice(flat.center.length - rightBlankCount).map((col) => col.width));
543
+ const rightBlankCount = center.length - leftIndex - centerCount;
544
+ const rightBlank = sum(center.slice(center.length - rightBlankCount).map(getColumnLogicWidth));
470
545
  return {
471
546
  leftIndex: leftIndex,
472
547
  leftBlank,
@@ -482,6 +557,7 @@ function calculateRenderInfo(table) {
482
557
  const columns = processColumns(columnsProp, defaultColumnWidth);
483
558
  const leftNestedLockCount = getLeftNestedLockCount(columns);
484
559
  const fullFlat = collectNodes(columns, 'leaf-only');
560
+ const { columns: fullFlatWithoutFill } = takeFillRemainingWidthColumn(fullFlat);
485
561
  let flat;
486
562
  let nested;
487
563
  let useVirtual;
@@ -495,7 +571,7 @@ function calculateRenderInfo(table) {
495
571
  const rightNestedLockCount = getLeftNestedLockCount(columns.slice().reverse());
496
572
  const centerNested = columns.slice(leftNestedLockCount, columns.length - rightNestedLockCount);
497
573
  const rightNested = columns.slice(columns.length - rightNestedLockCount);
498
- const shouldEnableHozVirtual = fullFlat.length >= hozVirtualThreshold && fullFlat.every((col) => col.width != null);
574
+ const shouldEnableHozVirtual = fullFlat.length >= hozVirtualThreshold && fullFlatWithoutFill.every((col) => col.width != null);
499
575
  const shouldEnableVerVirtual = dataSourceProp.length >= verVirtualThreshold;
500
576
  useVirtual = {
501
577
  horizontal: resolveVirtualEnabled(typeof useVirtualProp === 'object' ? useVirtualProp.horizontal : useVirtualProp, shouldEnableHozVirtual),
@@ -515,16 +591,22 @@ function calculateRenderInfo(table) {
515
591
  center: centerNested,
516
592
  };
517
593
  }
518
- const horizontalRenderRange = getHorizontalRenderRange({ maxRenderWidth, offsetX, useVirtual, flat });
594
+ const { columns: centerFlat, fillColumn: centerFillColumn } = takeFillRemainingWidthColumn(flat.center);
595
+ const horizontalRenderRange = getHorizontalRenderRange({ maxRenderWidth, offsetX, useVirtual, center: centerFlat });
519
596
  const verticalRenderRange = table.getVerticalRenderRange(useVirtual);
520
597
  const { leftBlank, leftIndex, rightBlank, rightIndex } = horizontalRenderRange;
521
598
  const unfilteredVisibleColumnDescriptors = [
522
599
  ...flat.left.map((col, i) => ({ type: 'normal', col, colIndex: i })),
523
600
  leftBlank > 0 && { type: 'blank', blankSide: 'left', width: leftBlank },
524
- ...flat.center
601
+ ...centerFlat
525
602
  .slice(leftIndex, rightIndex)
526
603
  .map((col, i) => ({ type: 'normal', col, colIndex: flat.left.length + leftIndex + i })),
527
604
  rightBlank > 0 && { type: 'blank', blankSide: 'right', width: rightBlank },
605
+ centerFillColumn && {
606
+ type: 'normal',
607
+ col: centerFillColumn,
608
+ colIndex: fullFlat.indexOf(centerFillColumn),
609
+ },
528
610
  ...flat.right.map((col, i) => ({ type: 'normal', col, colIndex: flat.full.length - flat.right.length + i })),
529
611
  ];
530
612
  const visibleColumnDescriptors = unfilteredVisibleColumnDescriptors.filter(Boolean);
@@ -535,16 +617,16 @@ function calculateRenderInfo(table) {
535
617
  let stickyLeft = 0;
536
618
  for (let i = 0; i < leftFlatCount; i++) {
537
619
  stickyLeftMap.set(i, stickyLeft);
538
- stickyLeft += flat.full[i].width;
620
+ stickyLeft += getColumnLogicWidth(flat.full[i]);
539
621
  }
540
622
  const stickyRightMap = new Map();
541
623
  let stickyRight = 0;
542
624
  for (let i = 0; i < rightFlatCount; i++) {
543
625
  stickyRightMap.set(fullFlatCount - 1 - i, stickyRight);
544
- stickyRight += flat.full[fullFlatCount - 1 - i].width;
626
+ stickyRight += getColumnLogicWidth(flat.full[fullFlatCount - 1 - i]);
545
627
  }
546
- const leftLockTotalWidth = sum(flat.left.map((col) => col.width));
547
- const rightLockTotalWidth = sum(flat.right.map((col) => col.width));
628
+ const leftLockTotalWidth = sum(flat.left.map(getColumnLogicWidth));
629
+ const rightLockTotalWidth = sum(flat.right.map(getColumnLogicWidth));
548
630
  return {
549
631
  horizontalRenderRange,
550
632
  verticalRenderRange,
@@ -1072,8 +1154,12 @@ function attachColIndex(inputNested, colIndexOffset) {
1072
1154
  function calculateHeaderRenderInfo({ flat, nested, horizontalRenderRange: hoz, useVirtual }, rowCount) {
1073
1155
  if (useVirtual.header) {
1074
1156
  const leftPart = calculateLeveledAndFlat(attachColIndex(nested.left, 0), rowCount);
1075
- const filtered = filterNestedCenter(nested.center, hoz, flat.left.length);
1157
+ const { columns: centerNested, fillColumn } = takeFillRemainingWidthColumn(nested.center);
1158
+ const filtered = filterNestedCenter(centerNested, hoz, flat.left.length);
1076
1159
  const centerPart = calculateLeveledAndFlat(filtered, rowCount);
1160
+ const fillPart = fillColumn == null
1161
+ ? { flat: [], leveled: range(rowCount).map(() => []) }
1162
+ : calculateLeveledAndFlat(attachColIndex([fillColumn], flat.left.length + flat.center.length - 1), rowCount);
1077
1163
  const rightPart = calculateLeveledAndFlat(attachColIndex(nested.right, flat.left.length + flat.center.length), rowCount);
1078
1164
  return {
1079
1165
  flat: [
@@ -1081,6 +1167,7 @@ function calculateHeaderRenderInfo({ flat, nested, horizontalRenderRange: hoz, u
1081
1167
  { type: 'blank', width: hoz.leftBlank, blankSide: 'left' },
1082
1168
  ...centerPart.flat,
1083
1169
  { type: 'blank', width: hoz.rightBlank, blankSide: 'right' },
1170
+ ...fillPart.flat,
1084
1171
  ...rightPart.flat,
1085
1172
  ],
1086
1173
  leveled: range(rowCount).map((depth) => [
@@ -1088,6 +1175,7 @@ function calculateHeaderRenderInfo({ flat, nested, horizontalRenderRange: hoz, u
1088
1175
  { type: 'blank', width: hoz.leftBlank, blankSide: 'left' },
1089
1176
  ...centerPart.leveled[depth],
1090
1177
  { type: 'blank', width: hoz.rightBlank, blankSide: 'right' },
1178
+ ...fillPart.leveled[depth],
1091
1179
  ...rightPart.leveled[depth],
1092
1180
  ]),
1093
1181
  };
@@ -1691,6 +1779,22 @@ class TableDOMHelper {
1691
1779
  }
1692
1780
  }
1693
1781
 
1782
+ const colSpanUpperBoundDisabled = Number.POSITIVE_INFINITY;
1783
+ function getMaximumColSpan(params) {
1784
+ const { column, colIndex, leftFlatCount, horizontalRenderRange, visible } = params;
1785
+ if (isFillRemainingWidthColumn(column)) {
1786
+ return colSpanUpperBoundDisabled;
1787
+ }
1788
+ let maxColSpan = leftFlatCount + horizontalRenderRange.rightIndex - colIndex;
1789
+ const visibleFillDescriptor = visible.find((descriptor) => descriptor.type === 'normal' && isFillRemainingWidthColumn(descriptor.col));
1790
+ const visibleFillColumnIndex = visibleFillDescriptor != null && visibleFillDescriptor.type === 'normal' ? visibleFillDescriptor.colIndex : undefined;
1791
+ // fill 列只有在当前渲染窗口已经覆盖到 center 尾部时,才能安全参与跨列合并
1792
+ if (visibleFillColumnIndex != null && horizontalRenderRange.rightBlank === 0 && colIndex < visibleFillColumnIndex) {
1793
+ maxColSpan = Math.max(maxColSpan, visibleFillColumnIndex + 1 - colIndex);
1794
+ }
1795
+ return maxColSpan;
1796
+ }
1797
+
1694
1798
  function HtmlTable({ tbodyHtmlTag, getRowProps, primaryKey, data, verticalRenderInfo: verInfo, horizontalRenderInfo: hozInfo, components: { Row, Cell, TableBody }, }) {
1695
1799
  const { flat, horizontalRenderRange: hoz } = hozInfo;
1696
1800
  const spanManager = new SpanManager();
@@ -1753,7 +1857,13 @@ function HtmlTable({ tbodyHtmlTag, getRowProps, primaryKey, data, verticalRender
1753
1857
  }
1754
1858
  // rowSpan/colSpan 不能过大,避免 rowSpan/colSpan 影响因虚拟滚动而未渲染的单元格
1755
1859
  rowSpan = Math.min(rowSpan, verInfo.limit - rowIndex);
1756
- colSpan = Math.min(colSpan, leftFlatCount + hoz.rightIndex - colIndex);
1860
+ colSpan = Math.min(colSpan, getMaximumColSpan({
1861
+ column,
1862
+ colIndex,
1863
+ leftFlatCount,
1864
+ horizontalRenderRange: hoz,
1865
+ visible: hozInfo.visible,
1866
+ }));
1757
1867
  const hasSpan = colSpan > 1 || rowSpan > 1;
1758
1868
  if (hasSpan) {
1759
1869
  spanManager.add(rowIndex, colIndex, colSpan, rowSpan);
@@ -2172,7 +2282,7 @@ class BaseTable extends React__default["default"].Component {
2172
2282
  const { needRenderLock } = this.state;
2173
2283
  const { flat, hasLockColumn } = this.lastInfo;
2174
2284
  if (hasLockColumn) {
2175
- const sumOfColWidth = sum(flat.full.map((col) => col.width));
2285
+ const sumOfColWidth = sum(flat.full.map(getColumnLogicWidth));
2176
2286
  const nextNeedRenderLock = sumOfColWidth > this.domHelper.artTable.clientWidth;
2177
2287
  if (needRenderLock !== nextNeedRenderLock) {
2178
2288
  this.setState({ needRenderLock: nextNeedRenderLock });
@@ -2202,38 +2312,6 @@ BaseTable.defaultProps = {
2202
2312
  dataSource: [],
2203
2313
  };
2204
2314
 
2205
- /******************************************************************************
2206
- Copyright (c) Microsoft Corporation.
2207
-
2208
- Permission to use, copy, modify, and/or distribute this software for any
2209
- purpose with or without fee is hereby granted.
2210
-
2211
- THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
2212
- REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
2213
- AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
2214
- INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
2215
- LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
2216
- OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
2217
- PERFORMANCE OF THIS SOFTWARE.
2218
- ***************************************************************************** */
2219
-
2220
- function __rest(s, e) {
2221
- var t = {};
2222
- for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
2223
- t[p] = s[p];
2224
- if (s != null && typeof Object.getOwnPropertySymbols === "function")
2225
- for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
2226
- if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
2227
- t[p[i]] = s[p[i]];
2228
- }
2229
- return t;
2230
- }
2231
-
2232
- typeof SuppressedError === "function" ? SuppressedError : function (error, suppressed, message) {
2233
- var e = new Error(message);
2234
- return e.name = "SuppressedError", e.error = error, e.suppressed = suppressed, e;
2235
- };
2236
-
2237
2315
  const InlineFlexCell = styled__default["default"].div `
2238
2316
  display: inline-flex;
2239
2317
  align-items: center;
@@ -2549,6 +2627,7 @@ exports.SpanManager = SpanManager;
2549
2627
  exports.TablePipeline = TablePipeline;
2550
2628
  exports.__rest = __rest;
2551
2629
  exports.always = always;
2630
+ exports.appendFillRemainingWidthColumn = appendFillRemainingWidthColumn;
2552
2631
  exports.arrayUtils = arrayUtils;
2553
2632
  exports.collectNodes = collectNodes;
2554
2633
  exports.flatMap = flatMap;
@@ -2559,6 +2638,7 @@ exports.icons = icons;
2559
2638
  exports.internals = internals;
2560
2639
  exports.isLeafNode = isLeafNode;
2561
2640
  exports.mergeCellProps = mergeCellProps;
2641
+ exports.takeFillRemainingWidthColumn = takeFillRemainingWidthColumn;
2562
2642
  exports.treeMetaSymbol = treeMetaSymbol;
2563
2643
  exports.treeMode = treeMode;
2564
2644
  exports.useTablePipeline = useTablePipeline;
@@ -0,0 +1,9 @@
1
+ import { ArtColumn } from './interfaces';
2
+ export declare function isFillRemainingWidthColumn(column: Pick<ArtColumn, 'features'> | null | undefined): boolean;
3
+ export declare function getColumnLogicWidth(column: ArtColumn): number;
4
+ export declare function takeFillRemainingWidthColumn<T extends ArtColumn>(columns: T[]): {
5
+ columns: T[];
6
+ fillColumn: T;
7
+ };
8
+ export declare function appendFillRemainingWidthColumn(columns: ArtColumn[], extra?: Partial<ArtColumn>): ArtColumn[];
9
+ export declare function createFillRemainingWidthColumn(extra?: Partial<ArtColumn>): ArtColumn;
@@ -0,0 +1,2 @@
1
+ import { TablePipeline } from '../pipeline';
2
+ export declare function fillRemainingWidth(): (pipeline: TablePipeline) => TablePipeline;
@@ -3,6 +3,7 @@ export { buildTree } from './buildTree';
3
3
  export { columnHover, ColumnHoverFeatureOptions } from './columnHover';
4
4
  export { columnRangeHover, ColumnRangeHoverFeatureOptions } from './columnRangeHover';
5
5
  export { columnResize, ColumnResizeFeatureOptions } from './columnResize';
6
+ export { fillRemainingWidth } from './fillRemainingWidth';
6
7
  export { multiSelect, MultiSelectFeatureOptions } from './multiSelect';
7
8
  export { rowDetail, RowDetailFeatureOptions } from './rowDetail';
8
9
  export { rowPopover, RowPopoverFeatureOptions } from './rowPopover';
@@ -1,4 +1,4 @@
1
- import { j as groupBy2, d as always, i as isLeafNode, k as fromEntries, b as icons, g as getTreeDepth, _ as __rest, B as BaseTable, T as TablePipeline, t as treeMode } from './chunks/srp-table-pipeline-cc27a3d4.esm.js';
1
+ import { l as groupBy2, e as always, i as isLeafNode, n as fromEntries, d as icons, g as getTreeDepth, _ as __rest, B as BaseTable, T as TablePipeline, j as treeMode } from './chunks/srp-table-pipeline-0b26f8d2.esm.js';
2
2
  import React from 'react';
3
3
  import { noop } from 'rxjs';
4
4
  import styled__default from 'styled-components';
@@ -2,7 +2,7 @@
2
2
 
3
3
  Object.defineProperty(exports, '__esModule', { value: true });
4
4
 
5
- var pipeline = require('./chunks/srp-table-pipeline-93090855.js');
5
+ var pipeline = require('./chunks/srp-table-pipeline-8dff19ec.js');
6
6
  var React = require('react');
7
7
  var rxjs = require('rxjs');
8
8
  var styled = require('styled-components');
@@ -1,5 +1,5 @@
1
- import { f as flatMap, g as getTreeDepth, i as isLeafNode, c as collectNodes, a as internals, S as SpanManager, C as Classes, m as mergeCellProps, _ as __rest, b as icons, d as always, e as arrayUtils, I as InlineFlexCell, E as ExpansionCell, t as treeMode, h as treeMetaSymbol } from './chunks/srp-table-pipeline-cc27a3d4.esm.js';
2
- export { B as BaseTable, C as Classes, T as TablePipeline, c as collectNodes, g as getTreeDepth, j as groupBy2, a as internals, i as isLeafNode, m as mergeCellProps, u as useTablePipeline } from './chunks/srp-table-pipeline-cc27a3d4.esm.js';
1
+ import { f as flatMap, g as getTreeDepth, i as isLeafNode, c as collectNodes, a as internals, S as SpanManager, C as Classes, b as appendFillRemainingWidthColumn, m as mergeCellProps, _ as __rest, d as icons, t as takeFillRemainingWidthColumn, e as always, h as arrayUtils, I as InlineFlexCell, E as ExpansionCell, j as treeMode, k as treeMetaSymbol } from './chunks/srp-table-pipeline-0b26f8d2.esm.js';
2
+ export { B as BaseTable, C as Classes, T as TablePipeline, c as collectNodes, g as getTreeDepth, l as groupBy2, a as internals, i as isLeafNode, m as mergeCellProps, u as useTablePipeline } from './chunks/srp-table-pipeline-0b26f8d2.esm.js';
3
3
  import React, { useState, useEffect } from 'react';
4
4
  import styled__default from 'styled-components';
5
5
  import { fromEvent } from 'rxjs';
@@ -554,24 +554,21 @@ function useAutoWidthTransform(tableRef, options, deps) {
554
554
  const expanderVisibility = (_a = options === null || options === void 0 ? void 0 : options.expanderVisibility) !== null && _a !== void 0 ? _a : 'visible';
555
555
  return {
556
556
  columns: (options === null || options === void 0 ? void 0 : options.appendExpander)
557
- ? columns.concat([
558
- {
559
- name: '',
560
- headerCellProps: {
561
- className: AUTO_WIDTH_EXPANDER_CLS,
562
- style: {
563
- background: expanderVisibility === 'hidden' ? 'var(--bgcolor)' : undefined,
564
- border: expanderVisibility === 'hidden' ? 'none' : undefined,
565
- },
566
- },
567
- getCellProps() {
568
- return {
569
- className: AUTO_WIDTH_EXPANDER_CLS,
570
- style: { visibility: expanderVisibility },
571
- };
557
+ ? appendFillRemainingWidthColumn(columns, {
558
+ headerCellProps: {
559
+ className: AUTO_WIDTH_EXPANDER_CLS,
560
+ style: {
561
+ background: expanderVisibility === 'hidden' ? 'var(--bgcolor)' : undefined,
562
+ border: expanderVisibility === 'hidden' ? 'none' : undefined,
572
563
  },
573
564
  },
574
- ])
565
+ getCellProps() {
566
+ return {
567
+ className: AUTO_WIDTH_EXPANDER_CLS,
568
+ style: { visibility: expanderVisibility },
569
+ };
570
+ },
571
+ })
575
572
  : columns,
576
573
  dataSource,
577
574
  };
@@ -1150,7 +1147,8 @@ function columnResize(opts = {}) {
1150
1147
  return function columnResizeFeature(pipeline) {
1151
1148
  var _a, _b, _c;
1152
1149
  const sizes = (_c = (_b = (_a = opts.sizes) !== null && _a !== void 0 ? _a : pipeline.getStateAtKey(stateKey)) !== null && _b !== void 0 ? _b : opts.defaultSizes) !== null && _c !== void 0 ? _c : [];
1153
- const leafColumns = collectNodes(pipeline.getColumns(), 'leaf-only');
1150
+ const { columns, fillColumn } = takeFillRemainingWidthColumn(pipeline.getColumns());
1151
+ const leafColumns = collectNodes(columns, 'leaf-only');
1154
1152
  leafColumns.forEach((col, colIndex) => {
1155
1153
  if (sizes[colIndex] == null) {
1156
1154
  if (typeof col.width === 'number') {
@@ -1208,7 +1206,7 @@ function columnResize(opts = {}) {
1208
1206
  },
1209
1207
  });
1210
1208
  };
1211
- return pipeline.mapColumns(makeRecursiveMapper((col, { startIndex, endIndex }) => {
1209
+ const resizedColumns = makeRecursiveMapper((col, { startIndex, endIndex }) => {
1212
1210
  const prevTitle = internals.safeRenderHeader(col);
1213
1211
  return Object.assign(Object.assign({}, col), { width: sizes[startIndex], title: (React.createElement(React.Fragment, null,
1214
1212
  prevTitle,
@@ -1218,7 +1216,14 @@ function columnResize(opts = {}) {
1218
1216
  position: 'relative',
1219
1217
  },
1220
1218
  }) });
1221
- }));
1219
+ })(columns);
1220
+ return pipeline.columns(fillColumn == null ? resizedColumns : appendFillRemainingWidthColumn(resizedColumns, fillColumn));
1221
+ };
1222
+ }
1223
+
1224
+ function fillRemainingWidth() {
1225
+ return function fillRemainingWidthStep(pipeline) {
1226
+ return pipeline.columns(appendFillRemainingWidthColumn(pipeline.getColumns()));
1222
1227
  };
1223
1228
  }
1224
1229
 
@@ -2337,6 +2342,7 @@ var index = /*#__PURE__*/Object.freeze({
2337
2342
  columnHover: columnHover,
2338
2343
  columnRangeHover: columnRangeHover,
2339
2344
  columnResize: columnResize,
2345
+ fillRemainingWidth: fillRemainingWidth,
2340
2346
  multiSelect: multiSelect,
2341
2347
  rowDetail: rowDetail,
2342
2348
  rowPopover: rowPopover,
package/dist/srp-table.js CHANGED
@@ -2,7 +2,7 @@
2
2
 
3
3
  Object.defineProperty(exports, '__esModule', { value: true });
4
4
 
5
- var pipeline = require('./chunks/srp-table-pipeline-93090855.js');
5
+ var pipeline = require('./chunks/srp-table-pipeline-8dff19ec.js');
6
6
  var React = require('react');
7
7
  var styled = require('styled-components');
8
8
  var rxjs = require('rxjs');
@@ -582,24 +582,21 @@ function useAutoWidthTransform(tableRef, options, deps) {
582
582
  const expanderVisibility = (_a = options === null || options === void 0 ? void 0 : options.expanderVisibility) !== null && _a !== void 0 ? _a : 'visible';
583
583
  return {
584
584
  columns: (options === null || options === void 0 ? void 0 : options.appendExpander)
585
- ? columns.concat([
586
- {
587
- name: '',
588
- headerCellProps: {
589
- className: AUTO_WIDTH_EXPANDER_CLS,
590
- style: {
591
- background: expanderVisibility === 'hidden' ? 'var(--bgcolor)' : undefined,
592
- border: expanderVisibility === 'hidden' ? 'none' : undefined,
593
- },
594
- },
595
- getCellProps() {
596
- return {
597
- className: AUTO_WIDTH_EXPANDER_CLS,
598
- style: { visibility: expanderVisibility },
599
- };
585
+ ? pipeline.appendFillRemainingWidthColumn(columns, {
586
+ headerCellProps: {
587
+ className: AUTO_WIDTH_EXPANDER_CLS,
588
+ style: {
589
+ background: expanderVisibility === 'hidden' ? 'var(--bgcolor)' : undefined,
590
+ border: expanderVisibility === 'hidden' ? 'none' : undefined,
600
591
  },
601
592
  },
602
- ])
593
+ getCellProps() {
594
+ return {
595
+ className: AUTO_WIDTH_EXPANDER_CLS,
596
+ style: { visibility: expanderVisibility },
597
+ };
598
+ },
599
+ })
603
600
  : columns,
604
601
  dataSource,
605
602
  };
@@ -1178,7 +1175,8 @@ function columnResize(opts = {}) {
1178
1175
  return function columnResizeFeature(pipeline$1) {
1179
1176
  var _a, _b, _c;
1180
1177
  const sizes = (_c = (_b = (_a = opts.sizes) !== null && _a !== void 0 ? _a : pipeline$1.getStateAtKey(stateKey)) !== null && _b !== void 0 ? _b : opts.defaultSizes) !== null && _c !== void 0 ? _c : [];
1181
- const leafColumns = pipeline.collectNodes(pipeline$1.getColumns(), 'leaf-only');
1178
+ const { columns, fillColumn } = pipeline.takeFillRemainingWidthColumn(pipeline$1.getColumns());
1179
+ const leafColumns = pipeline.collectNodes(columns, 'leaf-only');
1182
1180
  leafColumns.forEach((col, colIndex) => {
1183
1181
  if (sizes[colIndex] == null) {
1184
1182
  if (typeof col.width === 'number') {
@@ -1236,7 +1234,7 @@ function columnResize(opts = {}) {
1236
1234
  },
1237
1235
  });
1238
1236
  };
1239
- return pipeline$1.mapColumns(makeRecursiveMapper((col, { startIndex, endIndex }) => {
1237
+ const resizedColumns = makeRecursiveMapper((col, { startIndex, endIndex }) => {
1240
1238
  const prevTitle = pipeline.internals.safeRenderHeader(col);
1241
1239
  return Object.assign(Object.assign({}, col), { width: sizes[startIndex], title: (React__default["default"].createElement(React__default["default"].Fragment, null,
1242
1240
  prevTitle,
@@ -1246,7 +1244,14 @@ function columnResize(opts = {}) {
1246
1244
  position: 'relative',
1247
1245
  },
1248
1246
  }) });
1249
- }));
1247
+ })(columns);
1248
+ return pipeline$1.columns(fillColumn == null ? resizedColumns : pipeline.appendFillRemainingWidthColumn(resizedColumns, fillColumn));
1249
+ };
1250
+ }
1251
+
1252
+ function fillRemainingWidth() {
1253
+ return function fillRemainingWidthStep(pipeline$1) {
1254
+ return pipeline$1.columns(pipeline.appendFillRemainingWidthColumn(pipeline$1.getColumns()));
1250
1255
  };
1251
1256
  }
1252
1257
 
@@ -2365,6 +2370,7 @@ var index = /*#__PURE__*/Object.freeze({
2365
2370
  columnHover: columnHover,
2366
2371
  columnRangeHover: columnRangeHover,
2367
2372
  columnResize: columnResize,
2373
+ fillRemainingWidth: fillRemainingWidth,
2368
2374
  multiSelect: multiSelect,
2369
2375
  rowDetail: rowDetail,
2370
2376
  rowPopover: rowPopover,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@guozhi5658/srp-table",
3
- "version": "1.0.0",
3
+ "version": "1.1.0",
4
4
  "description": "High-performance React table component library",
5
5
  "sideEffects": false,
6
6
  "module": "dist/srp-table.esm.js",
package/readme.md CHANGED
@@ -93,6 +93,34 @@ export function PipelineDemo({ columns, dataSource }) {
93
93
  }
94
94
  ```
95
95
 
96
+ ### Fill Remaining Width
97
+
98
+ Use `features.fillRemainingWidth()` when you want fixed-width columns to keep their original widths as the container grows. Instead of stretching existing columns proportionally, the table appends a blank column on the right to absorb the remaining space.
99
+
100
+ ```tsx
101
+ import { BaseTable, features, useTablePipeline } from '@guozhi5658/srp-table'
102
+
103
+ export function FixedWidthDemo({ columns, dataSource }) {
104
+ const pipeline = useTablePipeline()
105
+
106
+ const tableProps = pipeline
107
+ .input({ columns, dataSource })
108
+ .primaryKey('id')
109
+ .use(features.fillRemainingWidth())
110
+ .getProps()
111
+
112
+ return (
113
+ <BaseTable
114
+ {...tableProps}
115
+ defaultColumnWidth={140}
116
+ isStickyHeader
117
+ />
118
+ )
119
+ }
120
+ ```
121
+
122
+ This feature is designed for the pipeline path and works with `defaultColumnWidth`, locked columns, and the table's built-in virtualization logic.
123
+
96
124
  ## Playground
97
125
 
98
126
  Run the local playground to develop and validate new features against the built-in flat, tree, and row-detail mock datasets: