@guozhi5658/srp-table 1.1.1 → 1.1.3

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.
@@ -4,6 +4,7 @@
4
4
  export default class SpanManager {
5
5
  private rects;
6
6
  testSkip(rowIndex: number, colIndex: number): boolean;
7
+ testSkipRange(rowIndex: number, leftIndex: number, rightIndex: number): boolean;
7
8
  stripUpwards(rowIndex: number): void;
8
9
  add(rowIndex: number, colIndex: number, colSpan: number, rowSpan: number): void;
9
10
  }
@@ -1,9 +1,20 @@
1
- import { ArtColumn } from '../../interfaces';
2
1
  import { HorizontalRenderRange, VisibleColumnDescriptor } from '../interfaces';
3
- export declare function getMaximumColSpan(params: {
4
- column: ArtColumn;
5
- colIndex: number;
2
+ export declare function getVisibleDescriptorLogicalRange(params: {
3
+ descriptor: VisibleColumnDescriptor;
4
+ fullFlatCount: number;
6
5
  leftFlatCount: number;
6
+ rightFlatCount: number;
7
7
  horizontalRenderRange: HorizontalRenderRange;
8
+ }): {
9
+ left: number;
10
+ right: number;
11
+ };
12
+ export declare function getRenderedColSpan(params: {
13
+ colIndex: number;
14
+ colSpan: number;
8
15
  visible: VisibleColumnDescriptor[];
16
+ fullFlatCount: number;
17
+ leftFlatCount: number;
18
+ rightFlatCount: number;
19
+ horizontalRenderRange: HorizontalRenderRange;
9
20
  }): number;
@@ -145,6 +145,9 @@ class SpanManager {
145
145
  testSkip(rowIndex, colIndex) {
146
146
  return this.rects.some(({ left, right, top, bottom }) => left <= colIndex && colIndex < right && top <= rowIndex && rowIndex < bottom);
147
147
  }
148
+ testSkipRange(rowIndex, leftIndex, rightIndex) {
149
+ return this.rects.some(({ left, right, top, bottom }) => left < rightIndex && leftIndex < right && top <= rowIndex && rowIndex < bottom);
150
+ }
148
151
  stripUpwards(rowIndex) {
149
152
  this.rects = this.rects.filter(rect => rect.bottom > rowIndex);
150
153
  }
@@ -906,6 +909,18 @@ const StyledArtTableWrapper = styled__default.div `
906
909
  border-bottom: none;
907
910
  }
908
911
 
912
+ th.lock-left,
913
+ th.lock-right {
914
+ background: var(--header-bgcolor);
915
+ background-clip: padding-box;
916
+ }
917
+
918
+ td.lock-left,
919
+ td.lock-right {
920
+ background: var(--bgcolor);
921
+ background-clip: padding-box;
922
+ }
923
+
909
924
  .lock-left,
910
925
  .lock-right {
911
926
  z-index: ${Z.lock};
@@ -1752,23 +1767,52 @@ class TableDOMHelper {
1752
1767
  }
1753
1768
  }
1754
1769
 
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;
1770
+ function getVisibleDescriptorLogicalRange(params) {
1771
+ const { descriptor, fullFlatCount, leftFlatCount, rightFlatCount, horizontalRenderRange } = params;
1772
+ if (descriptor.type === 'normal') {
1773
+ return { left: descriptor.colIndex, right: descriptor.colIndex + 1 };
1760
1774
  }
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);
1775
+ if (descriptor.blankSide === 'left') {
1776
+ return {
1777
+ left: leftFlatCount,
1778
+ right: leftFlatCount + horizontalRenderRange.leftIndex,
1779
+ };
1780
+ }
1781
+ return {
1782
+ left: leftFlatCount + horizontalRenderRange.rightIndex,
1783
+ right: fullFlatCount - rightFlatCount,
1784
+ };
1785
+ }
1786
+ function getRenderedColSpan(params) {
1787
+ const { colIndex, colSpan, visible, fullFlatCount, leftFlatCount, rightFlatCount, horizontalRenderRange } = params;
1788
+ const requestedRight = Math.max(colIndex + 1, Math.min(fullFlatCount, colIndex + Math.max(1, colSpan)));
1789
+ const startVisibleIndex = visible.findIndex((descriptor) => descriptor.type === 'normal' && descriptor.colIndex === colIndex);
1790
+ if (startVisibleIndex < 0) {
1791
+ return 1;
1792
+ }
1793
+ let renderedColSpan = 0;
1794
+ for (let visibleIndex = startVisibleIndex; visibleIndex < visible.length; visibleIndex++) {
1795
+ const descriptor = visible[visibleIndex];
1796
+ const range = getVisibleDescriptorLogicalRange({
1797
+ descriptor,
1798
+ fullFlatCount,
1799
+ leftFlatCount,
1800
+ rightFlatCount,
1801
+ horizontalRenderRange,
1802
+ });
1803
+ if (range.right <= colIndex) {
1804
+ continue;
1805
+ }
1806
+ if (range.left >= requestedRight) {
1807
+ break;
1808
+ }
1809
+ renderedColSpan += 1;
1767
1810
  }
1768
- return maxColSpan;
1811
+ return Math.max(1, renderedColSpan);
1769
1812
  }
1770
1813
 
1771
1814
  function HtmlTable({ tbodyHtmlTag, getRowProps, primaryKey, data, verticalRenderInfo: verInfo, horizontalRenderInfo: hozInfo, components: { Row, Cell, TableBody }, }) {
1815
+ const fullRowMergedCellZIndex = 21;
1772
1816
  const { flat, horizontalRenderRange: hoz } = hozInfo;
1773
1817
  const spanManager = new SpanManager();
1774
1818
  const fullFlatCount = flat.full.length;
@@ -1790,6 +1834,16 @@ function HtmlTable({ tbodyHtmlTag, getRowProps, primaryKey, data, verticalRender
1790
1834
  }, rowProps === null || rowProps === void 0 ? void 0 : rowProps.className);
1791
1835
  const trProps = Object.assign(Object.assign({}, rowProps), { className: rowClass, 'data-rowindex': rowIndex, children: hozInfo.visible.map((descriptor) => {
1792
1836
  if (descriptor.type === 'blank') {
1837
+ const blankSpan = getVisibleDescriptorLogicalRange({
1838
+ descriptor,
1839
+ fullFlatCount,
1840
+ leftFlatCount,
1841
+ rightFlatCount,
1842
+ horizontalRenderRange: hoz,
1843
+ });
1844
+ if (spanManager.testSkipRange(rowIndex, blankSpan.left, blankSpan.right)) {
1845
+ return null;
1846
+ }
1793
1847
  return React.createElement("td", { key: descriptor.blankSide });
1794
1848
  }
1795
1849
  return renderBodyCell(row, rowIndex, descriptor.col, descriptor.colIndex);
@@ -1830,31 +1884,46 @@ function HtmlTable({ tbodyHtmlTag, getRowProps, primaryKey, data, verticalRender
1830
1884
  }
1831
1885
  // rowSpan/colSpan 不能过大,避免 rowSpan/colSpan 影响因虚拟滚动而未渲染的单元格
1832
1886
  rowSpan = Math.min(rowSpan, verInfo.limit - rowIndex);
1833
- colSpan = Math.min(colSpan, getMaximumColSpan({
1834
- column,
1887
+ const requestedColSpan = colSpan;
1888
+ const shouldSpanAcrossRenderedRow = rowSpan === 1 && colIndex === 0 && requestedColSpan >= fullFlatCount;
1889
+ colSpan = getRenderedColSpan({
1835
1890
  colIndex,
1891
+ colSpan: requestedColSpan,
1892
+ visible: hozInfo.visible,
1893
+ fullFlatCount,
1836
1894
  leftFlatCount,
1895
+ rightFlatCount,
1837
1896
  horizontalRenderRange: hoz,
1838
- visible: hozInfo.visible,
1839
- }));
1897
+ });
1840
1898
  const hasSpan = colSpan > 1 || rowSpan > 1;
1841
1899
  if (hasSpan) {
1842
1900
  spanManager.add(rowIndex, colIndex, colSpan, rowSpan);
1843
1901
  }
1902
+ const requestedSpanRight = colIndex + requestedColSpan;
1903
+ const crossesLeftLockBoundary = colIndex < leftFlatCount && requestedSpanRight > leftFlatCount;
1904
+ const rightLockStart = fullFlatCount - rightFlatCount;
1905
+ const crossesRightLockBoundary = colIndex < rightLockStart && requestedSpanRight > rightLockStart;
1906
+ const shouldDisableStickyForSpan = hasSpan && (crossesLeftLockBoundary || crossesRightLockBoundary);
1844
1907
  const positionStyle = {};
1845
- if (colIndex < leftFlatCount) {
1846
- positionStyle.position = 'sticky';
1847
- positionStyle.left = hozInfo.stickyLeftMap.get(colIndex);
1908
+ if (!shouldDisableStickyForSpan) {
1909
+ if (colIndex < leftFlatCount) {
1910
+ positionStyle.position = 'sticky';
1911
+ positionStyle.left = hozInfo.stickyLeftMap.get(colIndex);
1912
+ }
1913
+ else if (colIndex >= rightLockStart) {
1914
+ positionStyle.position = 'sticky';
1915
+ positionStyle.right = hozInfo.stickyRightMap.get(colIndex);
1916
+ }
1848
1917
  }
1849
- else if (colIndex >= fullFlatCount - rightFlatCount) {
1850
- positionStyle.position = 'sticky';
1851
- positionStyle.right = hozInfo.stickyRightMap.get(colIndex);
1918
+ if (shouldSpanAcrossRenderedRow) {
1919
+ positionStyle.position = 'relative';
1920
+ positionStyle.zIndex = fullRowMergedCellZIndex;
1852
1921
  }
1853
1922
  const tdProps = Object.assign(Object.assign(Object.assign(Object.assign({}, cellProps), { className: cx(Classes.tableCell, cellProps.className, {
1854
1923
  first: colIndex === 0,
1855
1924
  last: colIndex + colSpan === fullFlatCount,
1856
- 'lock-left': colIndex < leftFlatCount,
1857
- 'lock-right': colIndex >= fullFlatCount - rightFlatCount,
1925
+ 'lock-left': !shouldDisableStickyForSpan && colIndex < leftFlatCount,
1926
+ 'lock-right': !shouldDisableStickyForSpan && colIndex >= rightLockStart,
1858
1927
  }) }), (hasSpan ? { colSpan, rowSpan } : null)), { style: Object.assign(Object.assign({ textAlign: column.align }, cellProps.style), positionStyle), children: cellContent });
1859
1928
  if (Cell != null && tbodyHtmlTag === 'tbody') {
1860
1929
  return React.createElement(Cell, { key: colIndex, tdProps: tdProps, row: row, rowIndex: rowIndex, column: column, colIndex: colIndex });
@@ -172,6 +172,9 @@ class SpanManager {
172
172
  testSkip(rowIndex, colIndex) {
173
173
  return this.rects.some(({ left, right, top, bottom }) => left <= colIndex && colIndex < right && top <= rowIndex && rowIndex < bottom);
174
174
  }
175
+ testSkipRange(rowIndex, leftIndex, rightIndex) {
176
+ return this.rects.some(({ left, right, top, bottom }) => left < rightIndex && leftIndex < right && top <= rowIndex && rowIndex < bottom);
177
+ }
175
178
  stripUpwards(rowIndex) {
176
179
  this.rects = this.rects.filter(rect => rect.bottom > rowIndex);
177
180
  }
@@ -933,6 +936,18 @@ const StyledArtTableWrapper = styled__default["default"].div `
933
936
  border-bottom: none;
934
937
  }
935
938
 
939
+ th.lock-left,
940
+ th.lock-right {
941
+ background: var(--header-bgcolor);
942
+ background-clip: padding-box;
943
+ }
944
+
945
+ td.lock-left,
946
+ td.lock-right {
947
+ background: var(--bgcolor);
948
+ background-clip: padding-box;
949
+ }
950
+
936
951
  .lock-left,
937
952
  .lock-right {
938
953
  z-index: ${Z.lock};
@@ -1779,23 +1794,52 @@ class TableDOMHelper {
1779
1794
  }
1780
1795
  }
1781
1796
 
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;
1797
+ function getVisibleDescriptorLogicalRange(params) {
1798
+ const { descriptor, fullFlatCount, leftFlatCount, rightFlatCount, horizontalRenderRange } = params;
1799
+ if (descriptor.type === 'normal') {
1800
+ return { left: descriptor.colIndex, right: descriptor.colIndex + 1 };
1787
1801
  }
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);
1802
+ if (descriptor.blankSide === 'left') {
1803
+ return {
1804
+ left: leftFlatCount,
1805
+ right: leftFlatCount + horizontalRenderRange.leftIndex,
1806
+ };
1807
+ }
1808
+ return {
1809
+ left: leftFlatCount + horizontalRenderRange.rightIndex,
1810
+ right: fullFlatCount - rightFlatCount,
1811
+ };
1812
+ }
1813
+ function getRenderedColSpan(params) {
1814
+ const { colIndex, colSpan, visible, fullFlatCount, leftFlatCount, rightFlatCount, horizontalRenderRange } = params;
1815
+ const requestedRight = Math.max(colIndex + 1, Math.min(fullFlatCount, colIndex + Math.max(1, colSpan)));
1816
+ const startVisibleIndex = visible.findIndex((descriptor) => descriptor.type === 'normal' && descriptor.colIndex === colIndex);
1817
+ if (startVisibleIndex < 0) {
1818
+ return 1;
1819
+ }
1820
+ let renderedColSpan = 0;
1821
+ for (let visibleIndex = startVisibleIndex; visibleIndex < visible.length; visibleIndex++) {
1822
+ const descriptor = visible[visibleIndex];
1823
+ const range = getVisibleDescriptorLogicalRange({
1824
+ descriptor,
1825
+ fullFlatCount,
1826
+ leftFlatCount,
1827
+ rightFlatCount,
1828
+ horizontalRenderRange,
1829
+ });
1830
+ if (range.right <= colIndex) {
1831
+ continue;
1832
+ }
1833
+ if (range.left >= requestedRight) {
1834
+ break;
1835
+ }
1836
+ renderedColSpan += 1;
1794
1837
  }
1795
- return maxColSpan;
1838
+ return Math.max(1, renderedColSpan);
1796
1839
  }
1797
1840
 
1798
1841
  function HtmlTable({ tbodyHtmlTag, getRowProps, primaryKey, data, verticalRenderInfo: verInfo, horizontalRenderInfo: hozInfo, components: { Row, Cell, TableBody }, }) {
1842
+ const fullRowMergedCellZIndex = 21;
1799
1843
  const { flat, horizontalRenderRange: hoz } = hozInfo;
1800
1844
  const spanManager = new SpanManager();
1801
1845
  const fullFlatCount = flat.full.length;
@@ -1817,6 +1861,16 @@ function HtmlTable({ tbodyHtmlTag, getRowProps, primaryKey, data, verticalRender
1817
1861
  }, rowProps === null || rowProps === void 0 ? void 0 : rowProps.className);
1818
1862
  const trProps = Object.assign(Object.assign({}, rowProps), { className: rowClass, 'data-rowindex': rowIndex, children: hozInfo.visible.map((descriptor) => {
1819
1863
  if (descriptor.type === 'blank') {
1864
+ const blankSpan = getVisibleDescriptorLogicalRange({
1865
+ descriptor,
1866
+ fullFlatCount,
1867
+ leftFlatCount,
1868
+ rightFlatCount,
1869
+ horizontalRenderRange: hoz,
1870
+ });
1871
+ if (spanManager.testSkipRange(rowIndex, blankSpan.left, blankSpan.right)) {
1872
+ return null;
1873
+ }
1820
1874
  return React__default["default"].createElement("td", { key: descriptor.blankSide });
1821
1875
  }
1822
1876
  return renderBodyCell(row, rowIndex, descriptor.col, descriptor.colIndex);
@@ -1857,31 +1911,46 @@ function HtmlTable({ tbodyHtmlTag, getRowProps, primaryKey, data, verticalRender
1857
1911
  }
1858
1912
  // rowSpan/colSpan 不能过大,避免 rowSpan/colSpan 影响因虚拟滚动而未渲染的单元格
1859
1913
  rowSpan = Math.min(rowSpan, verInfo.limit - rowIndex);
1860
- colSpan = Math.min(colSpan, getMaximumColSpan({
1861
- column,
1914
+ const requestedColSpan = colSpan;
1915
+ const shouldSpanAcrossRenderedRow = rowSpan === 1 && colIndex === 0 && requestedColSpan >= fullFlatCount;
1916
+ colSpan = getRenderedColSpan({
1862
1917
  colIndex,
1918
+ colSpan: requestedColSpan,
1919
+ visible: hozInfo.visible,
1920
+ fullFlatCount,
1863
1921
  leftFlatCount,
1922
+ rightFlatCount,
1864
1923
  horizontalRenderRange: hoz,
1865
- visible: hozInfo.visible,
1866
- }));
1924
+ });
1867
1925
  const hasSpan = colSpan > 1 || rowSpan > 1;
1868
1926
  if (hasSpan) {
1869
1927
  spanManager.add(rowIndex, colIndex, colSpan, rowSpan);
1870
1928
  }
1929
+ const requestedSpanRight = colIndex + requestedColSpan;
1930
+ const crossesLeftLockBoundary = colIndex < leftFlatCount && requestedSpanRight > leftFlatCount;
1931
+ const rightLockStart = fullFlatCount - rightFlatCount;
1932
+ const crossesRightLockBoundary = colIndex < rightLockStart && requestedSpanRight > rightLockStart;
1933
+ const shouldDisableStickyForSpan = hasSpan && (crossesLeftLockBoundary || crossesRightLockBoundary);
1871
1934
  const positionStyle = {};
1872
- if (colIndex < leftFlatCount) {
1873
- positionStyle.position = 'sticky';
1874
- positionStyle.left = hozInfo.stickyLeftMap.get(colIndex);
1935
+ if (!shouldDisableStickyForSpan) {
1936
+ if (colIndex < leftFlatCount) {
1937
+ positionStyle.position = 'sticky';
1938
+ positionStyle.left = hozInfo.stickyLeftMap.get(colIndex);
1939
+ }
1940
+ else if (colIndex >= rightLockStart) {
1941
+ positionStyle.position = 'sticky';
1942
+ positionStyle.right = hozInfo.stickyRightMap.get(colIndex);
1943
+ }
1875
1944
  }
1876
- else if (colIndex >= fullFlatCount - rightFlatCount) {
1877
- positionStyle.position = 'sticky';
1878
- positionStyle.right = hozInfo.stickyRightMap.get(colIndex);
1945
+ if (shouldSpanAcrossRenderedRow) {
1946
+ positionStyle.position = 'relative';
1947
+ positionStyle.zIndex = fullRowMergedCellZIndex;
1879
1948
  }
1880
1949
  const tdProps = Object.assign(Object.assign(Object.assign(Object.assign({}, cellProps), { className: cx__default["default"](Classes.tableCell, cellProps.className, {
1881
1950
  first: colIndex === 0,
1882
1951
  last: colIndex + colSpan === fullFlatCount,
1883
- 'lock-left': colIndex < leftFlatCount,
1884
- 'lock-right': colIndex >= fullFlatCount - rightFlatCount,
1952
+ 'lock-left': !shouldDisableStickyForSpan && colIndex < leftFlatCount,
1953
+ 'lock-right': !shouldDisableStickyForSpan && colIndex >= rightLockStart,
1885
1954
  }) }), (hasSpan ? { colSpan, rowSpan } : null)), { style: Object.assign(Object.assign({ textAlign: column.align }, cellProps.style), positionStyle), children: cellContent });
1886
1955
  if (Cell != null && tbodyHtmlTag === 'tbody') {
1887
1956
  return React__default["default"].createElement(Cell, { key: colIndex, tdProps: tdProps, row: row, rowIndex: rowIndex, column: column, colIndex: colIndex });
@@ -1,4 +1,4 @@
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-414f4fea.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-67cab92a.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-7f69aca0.js');
5
+ var pipeline = require('./chunks/srp-table-pipeline-f974e586.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, 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-414f4fea.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-414f4fea.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-67cab92a.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-67cab92a.esm.js';
3
3
  import React, { useState, useEffect } from 'react';
4
4
  import styled__default from 'styled-components';
5
5
  import { fromEvent } from 'rxjs';
@@ -89,14 +89,14 @@ function buildTree$1(idProp, parentIdProp, items) {
89
89
  }
90
90
  }
91
91
 
92
- function safeGetSpanRect(column, record, rowIndex, colIndex) {
92
+ function safeGetSpanRect(column, record, rowIndex, colIndex, rowCount, colCount) {
93
93
  let colSpan = 1;
94
94
  let rowSpan = 1;
95
95
  if (column.getSpanRect) {
96
96
  const value = internals.safeGetValue(column, record, rowIndex);
97
97
  const spanRect = column.getSpanRect(value, record, rowIndex);
98
- colSpan = spanRect == null ? 1 : spanRect.right - colIndex;
99
- rowSpan = spanRect == null ? 1 : spanRect.bottom - rowIndex;
98
+ colSpan = spanRect == null ? 1 : Math.max(1, Math.min(colCount, spanRect.right) - colIndex);
99
+ rowSpan = spanRect == null ? 1 : Math.max(1, Math.min(rowCount, spanRect.bottom) - rowIndex);
100
100
  }
101
101
  else {
102
102
  const cellProps = internals.safeGetCellProps(column, record, rowIndex);
@@ -107,7 +107,6 @@ function safeGetSpanRect(column, record, rowIndex, colIndex) {
107
107
  rowSpan = cellProps.rowSpan;
108
108
  }
109
109
  }
110
- // 注意这里没有考虑「rowSpan/colSpan 不能过大,避免 rowSpan/colSpan 影响因虚拟滚动而未渲染的单元格」
111
110
  return {
112
111
  top: rowIndex,
113
112
  bottom: rowIndex + rowSpan,
@@ -171,7 +170,7 @@ function exportTableAsExcel(xlsxPackage, dataSource, columns, filename) {
171
170
  if (spanManager.testSkip(rowIndex, colIndex)) {
172
171
  return null;
173
172
  }
174
- const spanRect = safeGetSpanRect(col, record, rowIndex, colIndex);
173
+ const spanRect = safeGetSpanRect(col, record, rowIndex, colIndex, dataSource.length, leafColumns.length);
175
174
  const rowSpan = spanRect.bottom - spanRect.top;
176
175
  const colSpan = spanRect.right - spanRect.left;
177
176
  if (rowSpan > 1 || colSpan > 1) {
@@ -1363,6 +1362,7 @@ function multiSelect(opts = {}) {
1363
1362
  }
1364
1363
 
1365
1364
  const rowDetailSymbol = Symbol('row-detail');
1365
+ const openEndedSpanRight$1 = Number.MAX_SAFE_INTEGER;
1366
1366
  const fallbackRenderDetail = () => (React.createElement("div", { style: { margin: '8px 24px' } },
1367
1367
  React.createElement("b", { style: { color: 'indianred' } },
1368
1368
  "\u8BBE\u7F6E ",
@@ -1423,7 +1423,6 @@ function rowDetail(opts = {}) {
1423
1423
  if (columns.length === 0) {
1424
1424
  return columns;
1425
1425
  }
1426
- const columnFlatCount = collectNodes(columns, 'leaf-only').length;
1427
1426
  const [firstCol, ...others] = columns;
1428
1427
  const render = (value, row, rowIndex) => {
1429
1428
  if (row[rowDetailMetaKey]) {
@@ -1475,8 +1474,8 @@ function rowDetail(opts = {}) {
1475
1474
  return [
1476
1475
  Object.assign(Object.assign({}, firstCol), { title: (React.createElement("div", { style: { display: 'inline-block', marginLeft: textOffset } }, internals.safeRenderHeader(firstCol))), render, getCellProps: clickArea === 'cell' ? getCellProps : firstCol.getCellProps, getSpanRect(value, row, rowIndex) {
1477
1476
  if (row[rowDetailMetaKey]) {
1478
- // detail 总是成一行
1479
- return { top: rowIndex, bottom: rowIndex + 1, left: 0, right: columnFlatCount };
1477
+ // detail 总是成一行,并且需要覆盖后续 feature 追加的列
1478
+ return { top: rowIndex, bottom: rowIndex + 1, left: 0, right: openEndedSpanRight$1 };
1480
1479
  }
1481
1480
  } }),
1482
1481
  ...others,
@@ -1580,6 +1579,7 @@ function rowPopover(opts = {}) {
1580
1579
  }
1581
1580
 
1582
1581
  const groupingMetaSymbol = Symbol('row-grouping-meta');
1582
+ const openEndedSpanRight = Number.MAX_SAFE_INTEGER;
1583
1583
  function attachGroupingMeta(row) {
1584
1584
  return Object.assign({ [groupingMetaSymbol]: { expandable: !isLeafNode(row) } }, row);
1585
1585
  }
@@ -1631,7 +1631,6 @@ function rowGrouping(opts = {}) {
1631
1631
  if (columns.length === 0) {
1632
1632
  return columns;
1633
1633
  }
1634
- const columnFlatCount = collectNodes(columns, 'leaf-only').length;
1635
1634
  const [firstCol, ...others] = columns;
1636
1635
  const render = (value, row, rowIndex) => {
1637
1636
  var _a, _b;
@@ -1680,7 +1679,7 @@ function rowGrouping(opts = {}) {
1680
1679
  getCellProps,
1681
1680
  getSpanRect(value, row, rowIndex) {
1682
1681
  if (getGroupingMeta(row).isGroupHeader) {
1683
- return { top: rowIndex, bottom: rowIndex + 1, left: 0, right: columnFlatCount };
1682
+ return { top: rowIndex, bottom: rowIndex + 1, left: 0, right: openEndedSpanRight };
1684
1683
  }
1685
1684
  } }),
1686
1685
  ...others,
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-7f69aca0.js');
5
+ var pipeline = require('./chunks/srp-table-pipeline-f974e586.js');
6
6
  var React = require('react');
7
7
  var styled = require('styled-components');
8
8
  var rxjs = require('rxjs');
@@ -117,14 +117,14 @@ function buildTree$1(idProp, parentIdProp, items) {
117
117
  }
118
118
  }
119
119
 
120
- function safeGetSpanRect(column, record, rowIndex, colIndex) {
120
+ function safeGetSpanRect(column, record, rowIndex, colIndex, rowCount, colCount) {
121
121
  let colSpan = 1;
122
122
  let rowSpan = 1;
123
123
  if (column.getSpanRect) {
124
124
  const value = pipeline.internals.safeGetValue(column, record, rowIndex);
125
125
  const spanRect = column.getSpanRect(value, record, rowIndex);
126
- colSpan = spanRect == null ? 1 : spanRect.right - colIndex;
127
- rowSpan = spanRect == null ? 1 : spanRect.bottom - rowIndex;
126
+ colSpan = spanRect == null ? 1 : Math.max(1, Math.min(colCount, spanRect.right) - colIndex);
127
+ rowSpan = spanRect == null ? 1 : Math.max(1, Math.min(rowCount, spanRect.bottom) - rowIndex);
128
128
  }
129
129
  else {
130
130
  const cellProps = pipeline.internals.safeGetCellProps(column, record, rowIndex);
@@ -135,7 +135,6 @@ function safeGetSpanRect(column, record, rowIndex, colIndex) {
135
135
  rowSpan = cellProps.rowSpan;
136
136
  }
137
137
  }
138
- // 注意这里没有考虑「rowSpan/colSpan 不能过大,避免 rowSpan/colSpan 影响因虚拟滚动而未渲染的单元格」
139
138
  return {
140
139
  top: rowIndex,
141
140
  bottom: rowIndex + rowSpan,
@@ -199,7 +198,7 @@ function exportTableAsExcel(xlsxPackage, dataSource, columns, filename) {
199
198
  if (spanManager.testSkip(rowIndex, colIndex)) {
200
199
  return null;
201
200
  }
202
- const spanRect = safeGetSpanRect(col, record, rowIndex, colIndex);
201
+ const spanRect = safeGetSpanRect(col, record, rowIndex, colIndex, dataSource.length, leafColumns.length);
203
202
  const rowSpan = spanRect.bottom - spanRect.top;
204
203
  const colSpan = spanRect.right - spanRect.left;
205
204
  if (rowSpan > 1 || colSpan > 1) {
@@ -1391,6 +1390,7 @@ function multiSelect(opts = {}) {
1391
1390
  }
1392
1391
 
1393
1392
  const rowDetailSymbol = Symbol('row-detail');
1393
+ const openEndedSpanRight$1 = Number.MAX_SAFE_INTEGER;
1394
1394
  const fallbackRenderDetail = () => (React__default["default"].createElement("div", { style: { margin: '8px 24px' } },
1395
1395
  React__default["default"].createElement("b", { style: { color: 'indianred' } },
1396
1396
  "\u8BBE\u7F6E ",
@@ -1451,7 +1451,6 @@ function rowDetail(opts = {}) {
1451
1451
  if (columns.length === 0) {
1452
1452
  return columns;
1453
1453
  }
1454
- const columnFlatCount = pipeline.collectNodes(columns, 'leaf-only').length;
1455
1454
  const [firstCol, ...others] = columns;
1456
1455
  const render = (value, row, rowIndex) => {
1457
1456
  if (row[rowDetailMetaKey]) {
@@ -1503,8 +1502,8 @@ function rowDetail(opts = {}) {
1503
1502
  return [
1504
1503
  Object.assign(Object.assign({}, firstCol), { title: (React__default["default"].createElement("div", { style: { display: 'inline-block', marginLeft: textOffset } }, pipeline.internals.safeRenderHeader(firstCol))), render, getCellProps: clickArea === 'cell' ? getCellProps : firstCol.getCellProps, getSpanRect(value, row, rowIndex) {
1505
1504
  if (row[rowDetailMetaKey]) {
1506
- // detail 总是成一行
1507
- return { top: rowIndex, bottom: rowIndex + 1, left: 0, right: columnFlatCount };
1505
+ // detail 总是成一行,并且需要覆盖后续 feature 追加的列
1506
+ return { top: rowIndex, bottom: rowIndex + 1, left: 0, right: openEndedSpanRight$1 };
1508
1507
  }
1509
1508
  } }),
1510
1509
  ...others,
@@ -1608,6 +1607,7 @@ function rowPopover(opts = {}) {
1608
1607
  }
1609
1608
 
1610
1609
  const groupingMetaSymbol = Symbol('row-grouping-meta');
1610
+ const openEndedSpanRight = Number.MAX_SAFE_INTEGER;
1611
1611
  function attachGroupingMeta(row) {
1612
1612
  return Object.assign({ [groupingMetaSymbol]: { expandable: !pipeline.isLeafNode(row) } }, row);
1613
1613
  }
@@ -1659,7 +1659,6 @@ function rowGrouping(opts = {}) {
1659
1659
  if (columns.length === 0) {
1660
1660
  return columns;
1661
1661
  }
1662
- const columnFlatCount = pipeline.collectNodes(columns, 'leaf-only').length;
1663
1662
  const [firstCol, ...others] = columns;
1664
1663
  const render = (value, row, rowIndex) => {
1665
1664
  var _a, _b;
@@ -1708,7 +1707,7 @@ function rowGrouping(opts = {}) {
1708
1707
  getCellProps,
1709
1708
  getSpanRect(value, row, rowIndex) {
1710
1709
  if (getGroupingMeta(row).isGroupHeader) {
1711
- return { top: rowIndex, bottom: rowIndex + 1, left: 0, right: columnFlatCount };
1710
+ return { top: rowIndex, bottom: rowIndex + 1, left: 0, right: openEndedSpanRight };
1712
1711
  }
1713
1712
  } }),
1714
1713
  ...others,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@guozhi5658/srp-table",
3
- "version": "1.1.1",
3
+ "version": "1.1.3",
4
4
  "description": "High-performance React table component library",
5
5
  "sideEffects": false,
6
6
  "module": "dist/srp-table.esm.js",