@guozhi5658/srp-table 1.1.2 → 1.1.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/dist/base-table/helpers/SpanManager.d.ts +1 -0
- package/dist/base-table/helpers/getMaximumColSpan.d.ts +15 -4
- package/dist/chunks/{srp-table-pipeline-4c320be5.js → srp-table-pipeline-6f4336b2.js} +98 -24
- package/dist/chunks/{srp-table-pipeline-88f44dd3.esm.js → srp-table-pipeline-eab4ee87.esm.js} +98 -24
- package/dist/common-views.d.ts +2 -0
- package/dist/interfaces.d.ts +10 -0
- package/dist/pipeline/features/__tests__/filterMode.test.d.ts +1 -0
- package/dist/pipeline/features/filterMode.d.ts +34 -0
- package/dist/pipeline/features/filterModeUtils.d.ts +10 -0
- package/dist/pipeline/features/index.d.ts +1 -0
- package/dist/srp-table-pivot.esm.js +1 -1
- package/dist/srp-table-pivot.js +1 -1
- package/dist/srp-table.esm.js +292 -12
- package/dist/srp-table.js +291 -11
- package/package.json +1 -1
|
@@ -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
|
|
4
|
-
|
|
5
|
-
|
|
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;
|
|
@@ -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
|
-
|
|
1783
|
-
|
|
1784
|
-
|
|
1785
|
-
|
|
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
|
-
|
|
1789
|
-
|
|
1790
|
-
|
|
1791
|
-
|
|
1792
|
-
|
|
1793
|
-
|
|
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 Math.max(1,
|
|
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
|
-
|
|
1861
|
-
|
|
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
|
-
|
|
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 (
|
|
1873
|
-
|
|
1874
|
-
|
|
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
|
-
|
|
1877
|
-
positionStyle.position = '
|
|
1878
|
-
positionStyle.
|
|
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 >=
|
|
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 });
|
|
@@ -2341,6 +2410,10 @@ function InfoIcon(props) {
|
|
|
2341
2410
|
React__default["default"].createElement("path", { d: "M8.5 11L8.5 6.5 6.5 6.5 6.5 7.5 7.5 7.5 7.5 11 6 11 6 12 10 12 10 11zM8 3.5c-.4 0-.8.3-.8.8S7.6 5 8 5c.4 0 .8-.3.8-.8S8.4 3.5 8 3.5z" }),
|
|
2342
2411
|
React__default["default"].createElement("path", { d: "M8,15c-3.9,0-7-3.1-7-7s3.1-7,7-7s7,3.1,7,7S11.9,15,8,15z M8,2C4.7,2,2,4.7,2,8s2.7,6,6,6s6-2.7,6-6S11.3,2,8,2z" })));
|
|
2343
2412
|
}
|
|
2413
|
+
function FilterIcon(props) {
|
|
2414
|
+
return (React__default["default"].createElement("svg", Object.assign({ focusable: "false", preserveAspectRatio: "xMidYMid meet", fill: "currentColor", width: "16", height: "16", viewBox: "0 0 16 16" }, props),
|
|
2415
|
+
React__default["default"].createElement("path", { d: "M2 3.25c0-.69.56-1.25 1.25-1.25h9.5c.69 0 1.25.56 1.25 1.25 0 .31-.12.61-.33.84L9.5 8.58V12a1 1 0 0 1-.45.83l-1.8 1.2A.75.75 0 0 1 6 13.4V8.58L2.33 4.09A1.25 1.25 0 0 1 2 3.25zm1.53.25L7.2 8v4.01l.8-.54V8l3.67-4.5H3.53z" })));
|
|
2416
|
+
}
|
|
2344
2417
|
function CaretRightIcon(props) {
|
|
2345
2418
|
return (React__default["default"].createElement("svg", Object.assign({ focusable: "false", preserveAspectRatio: "xMidYMid meet", fill: "currentColor", width: "16", height: "16", viewBox: "0 0 32 32" }, props),
|
|
2346
2419
|
React__default["default"].createElement("path", { d: "M12 8L22 16 12 24z" })));
|
|
@@ -2353,6 +2426,7 @@ const icons = {
|
|
|
2353
2426
|
Loading: LoadingIcon,
|
|
2354
2427
|
CaretDown: CaretDownIcon,
|
|
2355
2428
|
CaretRight: CaretRightIcon,
|
|
2429
|
+
Filter: FilterIcon,
|
|
2356
2430
|
Info: InfoIcon,
|
|
2357
2431
|
};
|
|
2358
2432
|
|
package/dist/chunks/{srp-table-pipeline-88f44dd3.esm.js → srp-table-pipeline-eab4ee87.esm.js}
RENAMED
|
@@ -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
|
-
|
|
1756
|
-
|
|
1757
|
-
|
|
1758
|
-
|
|
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
|
-
|
|
1762
|
-
|
|
1763
|
-
|
|
1764
|
-
|
|
1765
|
-
|
|
1766
|
-
|
|
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 Math.max(1,
|
|
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
|
-
|
|
1834
|
-
|
|
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
|
-
|
|
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 (
|
|
1846
|
-
|
|
1847
|
-
|
|
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
|
-
|
|
1850
|
-
positionStyle.position = '
|
|
1851
|
-
positionStyle.
|
|
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 >=
|
|
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 });
|
|
@@ -2314,6 +2383,10 @@ function InfoIcon(props) {
|
|
|
2314
2383
|
React.createElement("path", { d: "M8.5 11L8.5 6.5 6.5 6.5 6.5 7.5 7.5 7.5 7.5 11 6 11 6 12 10 12 10 11zM8 3.5c-.4 0-.8.3-.8.8S7.6 5 8 5c.4 0 .8-.3.8-.8S8.4 3.5 8 3.5z" }),
|
|
2315
2384
|
React.createElement("path", { d: "M8,15c-3.9,0-7-3.1-7-7s3.1-7,7-7s7,3.1,7,7S11.9,15,8,15z M8,2C4.7,2,2,4.7,2,8s2.7,6,6,6s6-2.7,6-6S11.3,2,8,2z" })));
|
|
2316
2385
|
}
|
|
2386
|
+
function FilterIcon(props) {
|
|
2387
|
+
return (React.createElement("svg", Object.assign({ focusable: "false", preserveAspectRatio: "xMidYMid meet", fill: "currentColor", width: "16", height: "16", viewBox: "0 0 16 16" }, props),
|
|
2388
|
+
React.createElement("path", { d: "M2 3.25c0-.69.56-1.25 1.25-1.25h9.5c.69 0 1.25.56 1.25 1.25 0 .31-.12.61-.33.84L9.5 8.58V12a1 1 0 0 1-.45.83l-1.8 1.2A.75.75 0 0 1 6 13.4V8.58L2.33 4.09A1.25 1.25 0 0 1 2 3.25zm1.53.25L7.2 8v4.01l.8-.54V8l3.67-4.5H3.53z" })));
|
|
2389
|
+
}
|
|
2317
2390
|
function CaretRightIcon(props) {
|
|
2318
2391
|
return (React.createElement("svg", Object.assign({ focusable: "false", preserveAspectRatio: "xMidYMid meet", fill: "currentColor", width: "16", height: "16", viewBox: "0 0 32 32" }, props),
|
|
2319
2392
|
React.createElement("path", { d: "M12 8L22 16 12 24z" })));
|
|
@@ -2326,6 +2399,7 @@ const icons = {
|
|
|
2326
2399
|
Loading: LoadingIcon,
|
|
2327
2400
|
CaretDown: CaretDownIcon,
|
|
2328
2401
|
CaretRight: CaretRightIcon,
|
|
2402
|
+
Filter: FilterIcon,
|
|
2329
2403
|
Info: InfoIcon,
|
|
2330
2404
|
};
|
|
2331
2405
|
|
package/dist/common-views.d.ts
CHANGED
|
@@ -15,12 +15,14 @@ interface IconProps extends React.SVGProps<SVGElement> {
|
|
|
15
15
|
}
|
|
16
16
|
declare function CaretDownIcon(props: IconProps): JSX.Element;
|
|
17
17
|
declare function InfoIcon(props: IconProps): JSX.Element;
|
|
18
|
+
declare function FilterIcon(props: IconProps): JSX.Element;
|
|
18
19
|
declare function CaretRightIcon(props: IconProps): JSX.Element;
|
|
19
20
|
declare function LoadingIcon(props: IconProps): JSX.Element;
|
|
20
21
|
export declare const icons: {
|
|
21
22
|
Loading: typeof LoadingIcon;
|
|
22
23
|
CaretDown: typeof CaretDownIcon;
|
|
23
24
|
CaretRight: typeof CaretRightIcon;
|
|
25
|
+
Filter: typeof FilterIcon;
|
|
24
26
|
Info: typeof InfoIcon;
|
|
25
27
|
};
|
|
26
28
|
export {};
|
package/dist/interfaces.d.ts
CHANGED
|
@@ -1,6 +1,14 @@
|
|
|
1
1
|
import React, { ReactNode } from 'react';
|
|
2
2
|
export type ArtColumnAlign = 'left' | 'center' | 'right';
|
|
3
3
|
export type CellProps = React.TdHTMLAttributes<HTMLTableCellElement>;
|
|
4
|
+
export interface ArtColumnFilterProps {
|
|
5
|
+
/** 是否展示搜索输入框,默认为 true */
|
|
6
|
+
showSearch?: boolean;
|
|
7
|
+
/** 自定义筛选条件 */
|
|
8
|
+
filterOptions?(inputValue: string, record: any): boolean;
|
|
9
|
+
/** 预置的筛选项列表 */
|
|
10
|
+
dataSource?: string[];
|
|
11
|
+
}
|
|
4
12
|
export interface ArtColumnStaticPart {
|
|
5
13
|
/** 列的名称 */
|
|
6
14
|
name: string;
|
|
@@ -22,6 +30,8 @@ export interface ArtColumnStaticPart {
|
|
|
22
30
|
features?: {
|
|
23
31
|
[key: string]: any;
|
|
24
32
|
};
|
|
33
|
+
/** 表头筛选配置 */
|
|
34
|
+
filterProps?: ArtColumnFilterProps;
|
|
25
35
|
}
|
|
26
36
|
export interface ArtColumnDynamicPart {
|
|
27
37
|
/** 自定义取数方法 */
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import React, { ReactNode } from 'react';
|
|
2
|
+
import { ArtColumn } from '../../interfaces';
|
|
3
|
+
import { TablePipeline } from '../pipeline';
|
|
4
|
+
import { FilterDataItem } from './filterModeUtils';
|
|
5
|
+
export type { FilterDataItem } from './filterModeUtils';
|
|
6
|
+
export interface FilterModeFeatureOptions {
|
|
7
|
+
/** (非受控用法) 默认的筛选条件 */
|
|
8
|
+
defaultFilterData?: FilterDataItem[];
|
|
9
|
+
/** (受控用法) 当前筛选条件 */
|
|
10
|
+
filterData?: FilterDataItem[];
|
|
11
|
+
/** 更新筛选条件的回调函数 */
|
|
12
|
+
onChangeFilterData?(nextFilterData: FilterDataItem[]): void;
|
|
13
|
+
/** 是否保持 dataSource 不变 */
|
|
14
|
+
keepDataSource?: boolean;
|
|
15
|
+
/** 弹层组件属性 */
|
|
16
|
+
popoverProps?: any;
|
|
17
|
+
/** 自定义筛选表头 */
|
|
18
|
+
FilterHeaderCell?: React.ComponentType<FilterHeaderCellProps>;
|
|
19
|
+
}
|
|
20
|
+
export interface FilterHeaderCellProps {
|
|
21
|
+
filterModeOptions: {
|
|
22
|
+
keepDataSource: boolean;
|
|
23
|
+
};
|
|
24
|
+
children: ReactNode;
|
|
25
|
+
column: ArtColumn;
|
|
26
|
+
filterValue: string;
|
|
27
|
+
active: boolean;
|
|
28
|
+
open: boolean;
|
|
29
|
+
setOpen(nextOpen: boolean): void;
|
|
30
|
+
filterPanel: ReactNode;
|
|
31
|
+
Popover: React.ComponentType<any>;
|
|
32
|
+
popoverProps?: any;
|
|
33
|
+
}
|
|
34
|
+
export declare function filterMode(opts?: FilterModeFeatureOptions): (pipeline: TablePipeline) => TablePipeline;
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { ArtColumn } from '../../interfaces';
|
|
2
|
+
export type FilterDataItem = {
|
|
3
|
+
code: string;
|
|
4
|
+
filterValue: any;
|
|
5
|
+
};
|
|
6
|
+
export declare function normalizeFilterData(filterData: FilterDataItem[]): FilterDataItem[];
|
|
7
|
+
export declare function updateFilterData(filterData: FilterDataItem[], code: string, nextFilterValue: any): FilterDataItem[];
|
|
8
|
+
export declare function getFilterableColumns(columns: ArtColumn[]): ArtColumn[];
|
|
9
|
+
export declare function filterDataSourceByFilterData(dataSource: any[], columns: ArtColumn[], filterData: FilterDataItem[]): any[];
|
|
10
|
+
export declare function resolveFilterDataSource(dataSource: any[], columns: ArtColumn[], filterData: FilterDataItem[], keepDataSource?: boolean): any[];
|
|
@@ -4,6 +4,7 @@ export { columnHover, ColumnHoverFeatureOptions } from './columnHover';
|
|
|
4
4
|
export { columnRangeHover, ColumnRangeHoverFeatureOptions } from './columnRangeHover';
|
|
5
5
|
export { columnResize, ColumnResizeFeatureOptions } from './columnResize';
|
|
6
6
|
export { fillRemainingWidth } from './fillRemainingWidth';
|
|
7
|
+
export { filterMode, FilterDataItem, FilterHeaderCellProps, FilterModeFeatureOptions } from './filterMode';
|
|
7
8
|
export { multiSelect, MultiSelectFeatureOptions } from './multiSelect';
|
|
8
9
|
export { rowDetail, RowDetailFeatureOptions } from './rowDetail';
|
|
9
10
|
export { rowPopover, RowPopoverFeatureOptions } from './rowPopover';
|
|
@@ -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-
|
|
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-eab4ee87.esm.js';
|
|
2
2
|
import React from 'react';
|
|
3
3
|
import { noop } from 'rxjs';
|
|
4
4
|
import styled__default from 'styled-components';
|
package/dist/srp-table-pivot.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-
|
|
5
|
+
var pipeline = require('./chunks/srp-table-pipeline-6f4336b2.js');
|
|
6
6
|
var React = require('react');
|
|
7
7
|
var rxjs = require('rxjs');
|
|
8
8
|
var styled = require('styled-components');
|
package/dist/srp-table.esm.js
CHANGED
|
@@ -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-
|
|
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-
|
|
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-eab4ee87.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-eab4ee87.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) {
|
|
@@ -1228,6 +1227,286 @@ function fillRemainingWidth() {
|
|
|
1228
1227
|
};
|
|
1229
1228
|
}
|
|
1230
1229
|
|
|
1230
|
+
function normalizeFilterData(filterData) {
|
|
1231
|
+
const filterMap = new Map();
|
|
1232
|
+
for (const item of filterData !== null && filterData !== void 0 ? filterData : []) {
|
|
1233
|
+
if (item == null || typeof item.code !== 'string' || item.code.length === 0) {
|
|
1234
|
+
continue;
|
|
1235
|
+
}
|
|
1236
|
+
if (isBlankFilterValue$1(item.filterValue)) {
|
|
1237
|
+
filterMap.delete(item.code);
|
|
1238
|
+
continue;
|
|
1239
|
+
}
|
|
1240
|
+
filterMap.set(item.code, {
|
|
1241
|
+
code: item.code,
|
|
1242
|
+
filterValue: stringifyFilterValue$1(item.filterValue),
|
|
1243
|
+
});
|
|
1244
|
+
}
|
|
1245
|
+
return Array.from(filterMap.values());
|
|
1246
|
+
}
|
|
1247
|
+
function updateFilterData(filterData, code, nextFilterValue) {
|
|
1248
|
+
const nextFilterData = normalizeFilterData(filterData).filter((item) => item.code !== code);
|
|
1249
|
+
if (isBlankFilterValue$1(nextFilterValue)) {
|
|
1250
|
+
return nextFilterData;
|
|
1251
|
+
}
|
|
1252
|
+
nextFilterData.push({
|
|
1253
|
+
code,
|
|
1254
|
+
filterValue: stringifyFilterValue$1(nextFilterValue),
|
|
1255
|
+
});
|
|
1256
|
+
return nextFilterData;
|
|
1257
|
+
}
|
|
1258
|
+
function getFilterableColumns(columns) {
|
|
1259
|
+
return collectNodes(columns, 'leaf-only').filter((column) => column.code != null && column.filterProps != null);
|
|
1260
|
+
}
|
|
1261
|
+
function filterDataSourceByFilterData(dataSource, columns, filterData) {
|
|
1262
|
+
const activeFilterData = normalizeFilterData(filterData);
|
|
1263
|
+
if (activeFilterData.length === 0) {
|
|
1264
|
+
return dataSource;
|
|
1265
|
+
}
|
|
1266
|
+
const filterColumnsMap = new Map(columns.map((column) => [column.code, column]));
|
|
1267
|
+
return dataSource.filter((record) => {
|
|
1268
|
+
return activeFilterData.every(({ code, filterValue }) => {
|
|
1269
|
+
const column = filterColumnsMap.get(code);
|
|
1270
|
+
if (column == null) {
|
|
1271
|
+
return true;
|
|
1272
|
+
}
|
|
1273
|
+
return matchFilterValue(column, stringifyFilterValue$1(filterValue), record);
|
|
1274
|
+
});
|
|
1275
|
+
});
|
|
1276
|
+
}
|
|
1277
|
+
function matchFilterValue(column, filterValue, record) {
|
|
1278
|
+
var _a;
|
|
1279
|
+
if (isBlankFilterValue$1(filterValue)) {
|
|
1280
|
+
return true;
|
|
1281
|
+
}
|
|
1282
|
+
const customFilter = (_a = column.filterProps) === null || _a === void 0 ? void 0 : _a.filterOptions;
|
|
1283
|
+
if (typeof customFilter === 'function') {
|
|
1284
|
+
return customFilter(filterValue, record);
|
|
1285
|
+
}
|
|
1286
|
+
const rawValue = record === null || record === void 0 ? void 0 : record[column.code];
|
|
1287
|
+
if (rawValue == null) {
|
|
1288
|
+
return false;
|
|
1289
|
+
}
|
|
1290
|
+
return String(rawValue).toLowerCase().includes(filterValue.toLowerCase());
|
|
1291
|
+
}
|
|
1292
|
+
function isBlankFilterValue$1(value) {
|
|
1293
|
+
return stringifyFilterValue$1(value).trim() === '';
|
|
1294
|
+
}
|
|
1295
|
+
function stringifyFilterValue$1(value) {
|
|
1296
|
+
if (value == null) {
|
|
1297
|
+
return '';
|
|
1298
|
+
}
|
|
1299
|
+
return typeof value === 'string' ? value : String(value);
|
|
1300
|
+
}
|
|
1301
|
+
|
|
1302
|
+
const FilterHeaderShell = styled__default.div `
|
|
1303
|
+
display: flex;
|
|
1304
|
+
align-items: center;
|
|
1305
|
+
`;
|
|
1306
|
+
const FilterTrigger = styled__default.button `
|
|
1307
|
+
display: inline-flex;
|
|
1308
|
+
align-items: center;
|
|
1309
|
+
justify-content: center;
|
|
1310
|
+
width: 20px;
|
|
1311
|
+
height: 20px;
|
|
1312
|
+
margin-left: 4px;
|
|
1313
|
+
padding: 0;
|
|
1314
|
+
border: none;
|
|
1315
|
+
background: transparent;
|
|
1316
|
+
color: ${(props) => (props.active ? '#23A3FF' : '#8c8c8c')};
|
|
1317
|
+
cursor: pointer;
|
|
1318
|
+
|
|
1319
|
+
&:hover {
|
|
1320
|
+
color: ${(props) => (props.active ? '#23A3FF' : '#595959')};
|
|
1321
|
+
}
|
|
1322
|
+
`;
|
|
1323
|
+
const FilterPanel = styled__default.div `
|
|
1324
|
+
width: 160px;
|
|
1325
|
+
padding: 8px 8px 6px;
|
|
1326
|
+
box-sizing: border-box;
|
|
1327
|
+
color: #262626;
|
|
1328
|
+
font-size: 12px;
|
|
1329
|
+
line-height: 1.5;
|
|
1330
|
+
`;
|
|
1331
|
+
const FilterInput = styled__default.input `
|
|
1332
|
+
width: 100%;
|
|
1333
|
+
height: 28px;
|
|
1334
|
+
padding: 0 8px;
|
|
1335
|
+
box-sizing: border-box;
|
|
1336
|
+
border: 1px solid #d9d9d9;
|
|
1337
|
+
border-radius: 5px;
|
|
1338
|
+
outline: none;
|
|
1339
|
+
font-size: 12px;
|
|
1340
|
+
line-height: 1.5;
|
|
1341
|
+
|
|
1342
|
+
&:focus {
|
|
1343
|
+
border-color: #23a3ff;
|
|
1344
|
+
}
|
|
1345
|
+
`;
|
|
1346
|
+
const FilterOptionList = styled__default.div `
|
|
1347
|
+
max-height: 136px;
|
|
1348
|
+
margin-top: 6px;
|
|
1349
|
+
overflow: auto;
|
|
1350
|
+
`;
|
|
1351
|
+
const FilterOptionButton = styled__default.button `
|
|
1352
|
+
width: 100%;
|
|
1353
|
+
min-height: 28px;
|
|
1354
|
+
margin-top: 4px;
|
|
1355
|
+
padding: 3px 8px;
|
|
1356
|
+
box-sizing: border-box;
|
|
1357
|
+
border: 1px solid ${(props) => (props.active ? '#23A3FF' : '#e8e8e8')};
|
|
1358
|
+
border-radius: 5px;
|
|
1359
|
+
background: ${(props) => (props.active ? 'rgba(35, 163, 255, 0.12)' : '#fff')};
|
|
1360
|
+
color: #262626;
|
|
1361
|
+
font-size: 12px;
|
|
1362
|
+
line-height: 1.5;
|
|
1363
|
+
text-align: left;
|
|
1364
|
+
cursor: pointer;
|
|
1365
|
+
`;
|
|
1366
|
+
const FilterActionRow = styled__default.div `
|
|
1367
|
+
display: flex;
|
|
1368
|
+
justify-content: flex-end;
|
|
1369
|
+
gap: 4px;
|
|
1370
|
+
margin-top: 6px;
|
|
1371
|
+
`;
|
|
1372
|
+
const FilterActionButton = styled__default.button `
|
|
1373
|
+
min-width: 44px;
|
|
1374
|
+
height: 26px;
|
|
1375
|
+
padding: 0 8px;
|
|
1376
|
+
box-sizing: border-box;
|
|
1377
|
+
border: 1px solid ${(props) => (props.primary ? '#23A3FF' : '#d9d9d9')};
|
|
1378
|
+
border-radius: 999px;
|
|
1379
|
+
background: ${(props) => (props.primary ? '#23A3FF' : '#fff')};
|
|
1380
|
+
color: ${(props) => (props.primary ? '#fff' : '#262626')};
|
|
1381
|
+
font-size: 12px;
|
|
1382
|
+
line-height: 1;
|
|
1383
|
+
cursor: pointer;
|
|
1384
|
+
`;
|
|
1385
|
+
const FilterEmptyState = styled__default.div `
|
|
1386
|
+
margin-top: 8px;
|
|
1387
|
+
color: #8c8c8c;
|
|
1388
|
+
font-size: 12px;
|
|
1389
|
+
line-height: 1.5;
|
|
1390
|
+
`;
|
|
1391
|
+
const stateKey$1 = 'filterMode';
|
|
1392
|
+
function filterMode(opts = {}) {
|
|
1393
|
+
return function filterModeStep(pipeline) {
|
|
1394
|
+
var _a, _b, _c, _d;
|
|
1395
|
+
const inputFilterData = (_c = (_b = (_a = opts.filterData) !== null && _a !== void 0 ? _a : pipeline.getStateAtKey(stateKey$1)) !== null && _b !== void 0 ? _b : opts.defaultFilterData) !== null && _c !== void 0 ? _c : [];
|
|
1396
|
+
const filterData = normalizeFilterData(inputFilterData);
|
|
1397
|
+
const Popover = pipeline.ctx.components.Popover;
|
|
1398
|
+
const columns = pipeline.getColumns();
|
|
1399
|
+
const filterableColumns = getFilterableColumns(columns);
|
|
1400
|
+
if (filterableColumns.length === 0) {
|
|
1401
|
+
return pipeline;
|
|
1402
|
+
}
|
|
1403
|
+
if (Popover == null) {
|
|
1404
|
+
throw new Error('使用 filterMode 之前需要设置 pipeline.ctx.components.Popover');
|
|
1405
|
+
}
|
|
1406
|
+
const onChangeFilterData = (nextFilterData) => {
|
|
1407
|
+
var _a;
|
|
1408
|
+
const normalized = normalizeFilterData(nextFilterData);
|
|
1409
|
+
(_a = opts.onChangeFilterData) === null || _a === void 0 ? void 0 : _a.call(opts, normalized);
|
|
1410
|
+
pipeline.setStateAtKey(stateKey$1, normalized);
|
|
1411
|
+
};
|
|
1412
|
+
if (!opts.keepDataSource) {
|
|
1413
|
+
pipeline.dataSource(filterDataSourceByFilterData(pipeline.getDataSource(), filterableColumns, filterData));
|
|
1414
|
+
}
|
|
1415
|
+
pipeline.columns(processColumns(columns, {
|
|
1416
|
+
filterData,
|
|
1417
|
+
onChangeFilterData,
|
|
1418
|
+
Popover,
|
|
1419
|
+
popoverProps: opts.popoverProps,
|
|
1420
|
+
keepDataSource: Boolean(opts.keepDataSource),
|
|
1421
|
+
FilterHeaderCell: (_d = opts.FilterHeaderCell) !== null && _d !== void 0 ? _d : DefaultFilterHeaderCell,
|
|
1422
|
+
}));
|
|
1423
|
+
return pipeline;
|
|
1424
|
+
};
|
|
1425
|
+
}
|
|
1426
|
+
function stringifyFilterValue(value) {
|
|
1427
|
+
if (value == null) {
|
|
1428
|
+
return '';
|
|
1429
|
+
}
|
|
1430
|
+
return typeof value === 'string' ? value : String(value);
|
|
1431
|
+
}
|
|
1432
|
+
function isBlankFilterValue(value) {
|
|
1433
|
+
return stringifyFilterValue(value).trim() === '';
|
|
1434
|
+
}
|
|
1435
|
+
function processColumns(columns, { filterData, onChangeFilterData, Popover, popoverProps, keepDataSource, FilterHeaderCell, }) {
|
|
1436
|
+
const filterMap = new Map(filterData.map((item) => [item.code, stringifyFilterValue(item.filterValue)]));
|
|
1437
|
+
return columns.map(dfs);
|
|
1438
|
+
function dfs(col) {
|
|
1439
|
+
var _a;
|
|
1440
|
+
const result = Object.assign({}, col);
|
|
1441
|
+
if (isLeafNode(col) && col.code && col.filterProps) {
|
|
1442
|
+
const filterValue = (_a = filterMap.get(col.code)) !== null && _a !== void 0 ? _a : '';
|
|
1443
|
+
result.title = (React.createElement(ManagedFilterHeader, { Popover: Popover, FilterHeaderCell: FilterHeaderCell, column: col, filterModeOptions: { keepDataSource }, filterValue: filterValue, popoverProps: popoverProps, onChangeFilterValue: (nextFilterValue) => {
|
|
1444
|
+
onChangeFilterData(updateFilterData(filterData, col.code, nextFilterValue));
|
|
1445
|
+
} }, internals.safeRenderHeader(col)));
|
|
1446
|
+
}
|
|
1447
|
+
if (!isLeafNode(col)) {
|
|
1448
|
+
result.children = col.children.map(dfs);
|
|
1449
|
+
}
|
|
1450
|
+
return result;
|
|
1451
|
+
}
|
|
1452
|
+
}
|
|
1453
|
+
function ManagedFilterHeader({ Popover, FilterHeaderCell, column, filterModeOptions, filterValue, popoverProps, onChangeFilterValue, children, }) {
|
|
1454
|
+
var _a, _b, _c;
|
|
1455
|
+
const [open, setOpen] = useState(false);
|
|
1456
|
+
const [draftValue, setDraftValue] = useState(filterValue);
|
|
1457
|
+
useEffect(() => {
|
|
1458
|
+
setDraftValue(filterValue);
|
|
1459
|
+
}, [filterValue]);
|
|
1460
|
+
const showSearch = ((_a = column.filterProps) === null || _a === void 0 ? void 0 : _a.showSearch) !== false;
|
|
1461
|
+
const options = (_c = (_b = column.filterProps) === null || _b === void 0 ? void 0 : _b.dataSource) !== null && _c !== void 0 ? _c : [];
|
|
1462
|
+
const active = !isBlankFilterValue(filterValue);
|
|
1463
|
+
const visibleOptions = options.filter((item) => {
|
|
1464
|
+
if (!showSearch || isBlankFilterValue(draftValue)) {
|
|
1465
|
+
return true;
|
|
1466
|
+
}
|
|
1467
|
+
return item.toLowerCase().includes(draftValue.toLowerCase());
|
|
1468
|
+
});
|
|
1469
|
+
const filterPanel = (React.createElement(FilterPanel, { onClick: (event) => {
|
|
1470
|
+
event.stopPropagation();
|
|
1471
|
+
} },
|
|
1472
|
+
showSearch ? (React.createElement(FilterInput, { value: draftValue, placeholder: `筛选${column.name}`, onChange: (event) => {
|
|
1473
|
+
event.stopPropagation();
|
|
1474
|
+
setDraftValue(event.target.value);
|
|
1475
|
+
}, onClick: (event) => {
|
|
1476
|
+
event.stopPropagation();
|
|
1477
|
+
} })) : null,
|
|
1478
|
+
options.length > 0 ? (React.createElement(FilterOptionList, null, visibleOptions.map((item) => (React.createElement(FilterOptionButton, { key: item, type: "button", active: draftValue === item, onClick: (event) => {
|
|
1479
|
+
event.stopPropagation();
|
|
1480
|
+
setDraftValue(item);
|
|
1481
|
+
} }, item))))) : null,
|
|
1482
|
+
!showSearch && options.length === 0 ? React.createElement(FilterEmptyState, null, "\u5F53\u524D\u5217\u6CA1\u6709\u53EF\u9009\u7684\u9884\u7F6E\u7B5B\u9009\u9879\u3002") : null,
|
|
1483
|
+
showSearch && options.length > 0 && visibleOptions.length === 0 ? React.createElement(FilterEmptyState, null, "\u6CA1\u6709\u5339\u914D\u7684\u9884\u7F6E\u7B5B\u9009\u9879\u3002") : null,
|
|
1484
|
+
React.createElement(FilterActionRow, null,
|
|
1485
|
+
React.createElement(FilterActionButton, { type: "button", onClick: (event) => {
|
|
1486
|
+
event.stopPropagation();
|
|
1487
|
+
setDraftValue('');
|
|
1488
|
+
onChangeFilterValue('');
|
|
1489
|
+
setOpen(false);
|
|
1490
|
+
} }, "\u91CD\u7F6E"),
|
|
1491
|
+
React.createElement(FilterActionButton, { primary: true, type: "button", onClick: (event) => {
|
|
1492
|
+
event.stopPropagation();
|
|
1493
|
+
onChangeFilterValue(draftValue);
|
|
1494
|
+
setOpen(false);
|
|
1495
|
+
} }, "\u786E\u8BA4"))));
|
|
1496
|
+
return (React.createElement(FilterHeaderCell, { Popover: Popover, column: column, filterModeOptions: filterModeOptions, filterPanel: filterPanel, filterValue: filterValue, active: active, open: open, setOpen: setOpen, popoverProps: popoverProps }, children));
|
|
1497
|
+
}
|
|
1498
|
+
function DefaultFilterHeaderCell({ Popover, children, column, filterPanel, active, open, setOpen, popoverProps, }) {
|
|
1499
|
+
const justifyContent = column.align === 'right' ? 'flex-end' : column.align === 'center' ? 'center' : 'flex-start';
|
|
1500
|
+
return (React.createElement(FilterHeaderShell, { style: { justifyContent } },
|
|
1501
|
+
children,
|
|
1502
|
+
React.createElement(Popover, Object.assign({ visible: open, content: filterPanel }, popoverProps),
|
|
1503
|
+
React.createElement(FilterTrigger, { active: active, type: "button", "aria-label": `筛选${column.name}`, onClick: (event) => {
|
|
1504
|
+
event.stopPropagation();
|
|
1505
|
+
setOpen(!open);
|
|
1506
|
+
} },
|
|
1507
|
+
React.createElement(icons.Filter, null)))));
|
|
1508
|
+
}
|
|
1509
|
+
|
|
1231
1510
|
function multiSelect(opts = {}) {
|
|
1232
1511
|
return function multiSelectStep(pipeline) {
|
|
1233
1512
|
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l;
|
|
@@ -1363,6 +1642,7 @@ function multiSelect(opts = {}) {
|
|
|
1363
1642
|
}
|
|
1364
1643
|
|
|
1365
1644
|
const rowDetailSymbol = Symbol('row-detail');
|
|
1645
|
+
const openEndedSpanRight$1 = Number.MAX_SAFE_INTEGER;
|
|
1366
1646
|
const fallbackRenderDetail = () => (React.createElement("div", { style: { margin: '8px 24px' } },
|
|
1367
1647
|
React.createElement("b", { style: { color: 'indianred' } },
|
|
1368
1648
|
"\u8BBE\u7F6E ",
|
|
@@ -1423,7 +1703,6 @@ function rowDetail(opts = {}) {
|
|
|
1423
1703
|
if (columns.length === 0) {
|
|
1424
1704
|
return columns;
|
|
1425
1705
|
}
|
|
1426
|
-
const columnFlatCount = collectNodes(columns, 'leaf-only').length;
|
|
1427
1706
|
const [firstCol, ...others] = columns;
|
|
1428
1707
|
const render = (value, row, rowIndex) => {
|
|
1429
1708
|
if (row[rowDetailMetaKey]) {
|
|
@@ -1475,8 +1754,8 @@ function rowDetail(opts = {}) {
|
|
|
1475
1754
|
return [
|
|
1476
1755
|
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
1756
|
if (row[rowDetailMetaKey]) {
|
|
1478
|
-
// detail
|
|
1479
|
-
return { top: rowIndex, bottom: rowIndex + 1, left: 0, right:
|
|
1757
|
+
// detail 总是成一行,并且需要覆盖后续 feature 追加的列
|
|
1758
|
+
return { top: rowIndex, bottom: rowIndex + 1, left: 0, right: openEndedSpanRight$1 };
|
|
1480
1759
|
}
|
|
1481
1760
|
} }),
|
|
1482
1761
|
...others,
|
|
@@ -1580,6 +1859,7 @@ function rowPopover(opts = {}) {
|
|
|
1580
1859
|
}
|
|
1581
1860
|
|
|
1582
1861
|
const groupingMetaSymbol = Symbol('row-grouping-meta');
|
|
1862
|
+
const openEndedSpanRight = Number.MAX_SAFE_INTEGER;
|
|
1583
1863
|
function attachGroupingMeta(row) {
|
|
1584
1864
|
return Object.assign({ [groupingMetaSymbol]: { expandable: !isLeafNode(row) } }, row);
|
|
1585
1865
|
}
|
|
@@ -1631,7 +1911,6 @@ function rowGrouping(opts = {}) {
|
|
|
1631
1911
|
if (columns.length === 0) {
|
|
1632
1912
|
return columns;
|
|
1633
1913
|
}
|
|
1634
|
-
const columnFlatCount = collectNodes(columns, 'leaf-only').length;
|
|
1635
1914
|
const [firstCol, ...others] = columns;
|
|
1636
1915
|
const render = (value, row, rowIndex) => {
|
|
1637
1916
|
var _a, _b;
|
|
@@ -1680,7 +1959,7 @@ function rowGrouping(opts = {}) {
|
|
|
1680
1959
|
getCellProps,
|
|
1681
1960
|
getSpanRect(value, row, rowIndex) {
|
|
1682
1961
|
if (getGroupingMeta(row).isGroupHeader) {
|
|
1683
|
-
return { top: rowIndex, bottom: rowIndex + 1, left: 0, right:
|
|
1962
|
+
return { top: rowIndex, bottom: rowIndex + 1, left: 0, right: openEndedSpanRight };
|
|
1684
1963
|
}
|
|
1685
1964
|
} }),
|
|
1686
1965
|
...others,
|
|
@@ -2346,6 +2625,7 @@ var index = /*#__PURE__*/Object.freeze({
|
|
|
2346
2625
|
columnRangeHover: columnRangeHover,
|
|
2347
2626
|
columnResize: columnResize,
|
|
2348
2627
|
fillRemainingWidth: fillRemainingWidth,
|
|
2628
|
+
filterMode: filterMode,
|
|
2349
2629
|
multiSelect: multiSelect,
|
|
2350
2630
|
rowDetail: rowDetail,
|
|
2351
2631
|
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-
|
|
5
|
+
var pipeline = require('./chunks/srp-table-pipeline-6f4336b2.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) {
|
|
@@ -1256,6 +1255,286 @@ function fillRemainingWidth() {
|
|
|
1256
1255
|
};
|
|
1257
1256
|
}
|
|
1258
1257
|
|
|
1258
|
+
function normalizeFilterData(filterData) {
|
|
1259
|
+
const filterMap = new Map();
|
|
1260
|
+
for (const item of filterData !== null && filterData !== void 0 ? filterData : []) {
|
|
1261
|
+
if (item == null || typeof item.code !== 'string' || item.code.length === 0) {
|
|
1262
|
+
continue;
|
|
1263
|
+
}
|
|
1264
|
+
if (isBlankFilterValue$1(item.filterValue)) {
|
|
1265
|
+
filterMap.delete(item.code);
|
|
1266
|
+
continue;
|
|
1267
|
+
}
|
|
1268
|
+
filterMap.set(item.code, {
|
|
1269
|
+
code: item.code,
|
|
1270
|
+
filterValue: stringifyFilterValue$1(item.filterValue),
|
|
1271
|
+
});
|
|
1272
|
+
}
|
|
1273
|
+
return Array.from(filterMap.values());
|
|
1274
|
+
}
|
|
1275
|
+
function updateFilterData(filterData, code, nextFilterValue) {
|
|
1276
|
+
const nextFilterData = normalizeFilterData(filterData).filter((item) => item.code !== code);
|
|
1277
|
+
if (isBlankFilterValue$1(nextFilterValue)) {
|
|
1278
|
+
return nextFilterData;
|
|
1279
|
+
}
|
|
1280
|
+
nextFilterData.push({
|
|
1281
|
+
code,
|
|
1282
|
+
filterValue: stringifyFilterValue$1(nextFilterValue),
|
|
1283
|
+
});
|
|
1284
|
+
return nextFilterData;
|
|
1285
|
+
}
|
|
1286
|
+
function getFilterableColumns(columns) {
|
|
1287
|
+
return pipeline.collectNodes(columns, 'leaf-only').filter((column) => column.code != null && column.filterProps != null);
|
|
1288
|
+
}
|
|
1289
|
+
function filterDataSourceByFilterData(dataSource, columns, filterData) {
|
|
1290
|
+
const activeFilterData = normalizeFilterData(filterData);
|
|
1291
|
+
if (activeFilterData.length === 0) {
|
|
1292
|
+
return dataSource;
|
|
1293
|
+
}
|
|
1294
|
+
const filterColumnsMap = new Map(columns.map((column) => [column.code, column]));
|
|
1295
|
+
return dataSource.filter((record) => {
|
|
1296
|
+
return activeFilterData.every(({ code, filterValue }) => {
|
|
1297
|
+
const column = filterColumnsMap.get(code);
|
|
1298
|
+
if (column == null) {
|
|
1299
|
+
return true;
|
|
1300
|
+
}
|
|
1301
|
+
return matchFilterValue(column, stringifyFilterValue$1(filterValue), record);
|
|
1302
|
+
});
|
|
1303
|
+
});
|
|
1304
|
+
}
|
|
1305
|
+
function matchFilterValue(column, filterValue, record) {
|
|
1306
|
+
var _a;
|
|
1307
|
+
if (isBlankFilterValue$1(filterValue)) {
|
|
1308
|
+
return true;
|
|
1309
|
+
}
|
|
1310
|
+
const customFilter = (_a = column.filterProps) === null || _a === void 0 ? void 0 : _a.filterOptions;
|
|
1311
|
+
if (typeof customFilter === 'function') {
|
|
1312
|
+
return customFilter(filterValue, record);
|
|
1313
|
+
}
|
|
1314
|
+
const rawValue = record === null || record === void 0 ? void 0 : record[column.code];
|
|
1315
|
+
if (rawValue == null) {
|
|
1316
|
+
return false;
|
|
1317
|
+
}
|
|
1318
|
+
return String(rawValue).toLowerCase().includes(filterValue.toLowerCase());
|
|
1319
|
+
}
|
|
1320
|
+
function isBlankFilterValue$1(value) {
|
|
1321
|
+
return stringifyFilterValue$1(value).trim() === '';
|
|
1322
|
+
}
|
|
1323
|
+
function stringifyFilterValue$1(value) {
|
|
1324
|
+
if (value == null) {
|
|
1325
|
+
return '';
|
|
1326
|
+
}
|
|
1327
|
+
return typeof value === 'string' ? value : String(value);
|
|
1328
|
+
}
|
|
1329
|
+
|
|
1330
|
+
const FilterHeaderShell = styled__default["default"].div `
|
|
1331
|
+
display: flex;
|
|
1332
|
+
align-items: center;
|
|
1333
|
+
`;
|
|
1334
|
+
const FilterTrigger = styled__default["default"].button `
|
|
1335
|
+
display: inline-flex;
|
|
1336
|
+
align-items: center;
|
|
1337
|
+
justify-content: center;
|
|
1338
|
+
width: 20px;
|
|
1339
|
+
height: 20px;
|
|
1340
|
+
margin-left: 4px;
|
|
1341
|
+
padding: 0;
|
|
1342
|
+
border: none;
|
|
1343
|
+
background: transparent;
|
|
1344
|
+
color: ${(props) => (props.active ? '#23A3FF' : '#8c8c8c')};
|
|
1345
|
+
cursor: pointer;
|
|
1346
|
+
|
|
1347
|
+
&:hover {
|
|
1348
|
+
color: ${(props) => (props.active ? '#23A3FF' : '#595959')};
|
|
1349
|
+
}
|
|
1350
|
+
`;
|
|
1351
|
+
const FilterPanel = styled__default["default"].div `
|
|
1352
|
+
width: 160px;
|
|
1353
|
+
padding: 8px 8px 6px;
|
|
1354
|
+
box-sizing: border-box;
|
|
1355
|
+
color: #262626;
|
|
1356
|
+
font-size: 12px;
|
|
1357
|
+
line-height: 1.5;
|
|
1358
|
+
`;
|
|
1359
|
+
const FilterInput = styled__default["default"].input `
|
|
1360
|
+
width: 100%;
|
|
1361
|
+
height: 28px;
|
|
1362
|
+
padding: 0 8px;
|
|
1363
|
+
box-sizing: border-box;
|
|
1364
|
+
border: 1px solid #d9d9d9;
|
|
1365
|
+
border-radius: 5px;
|
|
1366
|
+
outline: none;
|
|
1367
|
+
font-size: 12px;
|
|
1368
|
+
line-height: 1.5;
|
|
1369
|
+
|
|
1370
|
+
&:focus {
|
|
1371
|
+
border-color: #23a3ff;
|
|
1372
|
+
}
|
|
1373
|
+
`;
|
|
1374
|
+
const FilterOptionList = styled__default["default"].div `
|
|
1375
|
+
max-height: 136px;
|
|
1376
|
+
margin-top: 6px;
|
|
1377
|
+
overflow: auto;
|
|
1378
|
+
`;
|
|
1379
|
+
const FilterOptionButton = styled__default["default"].button `
|
|
1380
|
+
width: 100%;
|
|
1381
|
+
min-height: 28px;
|
|
1382
|
+
margin-top: 4px;
|
|
1383
|
+
padding: 3px 8px;
|
|
1384
|
+
box-sizing: border-box;
|
|
1385
|
+
border: 1px solid ${(props) => (props.active ? '#23A3FF' : '#e8e8e8')};
|
|
1386
|
+
border-radius: 5px;
|
|
1387
|
+
background: ${(props) => (props.active ? 'rgba(35, 163, 255, 0.12)' : '#fff')};
|
|
1388
|
+
color: #262626;
|
|
1389
|
+
font-size: 12px;
|
|
1390
|
+
line-height: 1.5;
|
|
1391
|
+
text-align: left;
|
|
1392
|
+
cursor: pointer;
|
|
1393
|
+
`;
|
|
1394
|
+
const FilterActionRow = styled__default["default"].div `
|
|
1395
|
+
display: flex;
|
|
1396
|
+
justify-content: flex-end;
|
|
1397
|
+
gap: 4px;
|
|
1398
|
+
margin-top: 6px;
|
|
1399
|
+
`;
|
|
1400
|
+
const FilterActionButton = styled__default["default"].button `
|
|
1401
|
+
min-width: 44px;
|
|
1402
|
+
height: 26px;
|
|
1403
|
+
padding: 0 8px;
|
|
1404
|
+
box-sizing: border-box;
|
|
1405
|
+
border: 1px solid ${(props) => (props.primary ? '#23A3FF' : '#d9d9d9')};
|
|
1406
|
+
border-radius: 999px;
|
|
1407
|
+
background: ${(props) => (props.primary ? '#23A3FF' : '#fff')};
|
|
1408
|
+
color: ${(props) => (props.primary ? '#fff' : '#262626')};
|
|
1409
|
+
font-size: 12px;
|
|
1410
|
+
line-height: 1;
|
|
1411
|
+
cursor: pointer;
|
|
1412
|
+
`;
|
|
1413
|
+
const FilterEmptyState = styled__default["default"].div `
|
|
1414
|
+
margin-top: 8px;
|
|
1415
|
+
color: #8c8c8c;
|
|
1416
|
+
font-size: 12px;
|
|
1417
|
+
line-height: 1.5;
|
|
1418
|
+
`;
|
|
1419
|
+
const stateKey$1 = 'filterMode';
|
|
1420
|
+
function filterMode(opts = {}) {
|
|
1421
|
+
return function filterModeStep(pipeline) {
|
|
1422
|
+
var _a, _b, _c, _d;
|
|
1423
|
+
const inputFilterData = (_c = (_b = (_a = opts.filterData) !== null && _a !== void 0 ? _a : pipeline.getStateAtKey(stateKey$1)) !== null && _b !== void 0 ? _b : opts.defaultFilterData) !== null && _c !== void 0 ? _c : [];
|
|
1424
|
+
const filterData = normalizeFilterData(inputFilterData);
|
|
1425
|
+
const Popover = pipeline.ctx.components.Popover;
|
|
1426
|
+
const columns = pipeline.getColumns();
|
|
1427
|
+
const filterableColumns = getFilterableColumns(columns);
|
|
1428
|
+
if (filterableColumns.length === 0) {
|
|
1429
|
+
return pipeline;
|
|
1430
|
+
}
|
|
1431
|
+
if (Popover == null) {
|
|
1432
|
+
throw new Error('使用 filterMode 之前需要设置 pipeline.ctx.components.Popover');
|
|
1433
|
+
}
|
|
1434
|
+
const onChangeFilterData = (nextFilterData) => {
|
|
1435
|
+
var _a;
|
|
1436
|
+
const normalized = normalizeFilterData(nextFilterData);
|
|
1437
|
+
(_a = opts.onChangeFilterData) === null || _a === void 0 ? void 0 : _a.call(opts, normalized);
|
|
1438
|
+
pipeline.setStateAtKey(stateKey$1, normalized);
|
|
1439
|
+
};
|
|
1440
|
+
if (!opts.keepDataSource) {
|
|
1441
|
+
pipeline.dataSource(filterDataSourceByFilterData(pipeline.getDataSource(), filterableColumns, filterData));
|
|
1442
|
+
}
|
|
1443
|
+
pipeline.columns(processColumns(columns, {
|
|
1444
|
+
filterData,
|
|
1445
|
+
onChangeFilterData,
|
|
1446
|
+
Popover,
|
|
1447
|
+
popoverProps: opts.popoverProps,
|
|
1448
|
+
keepDataSource: Boolean(opts.keepDataSource),
|
|
1449
|
+
FilterHeaderCell: (_d = opts.FilterHeaderCell) !== null && _d !== void 0 ? _d : DefaultFilterHeaderCell,
|
|
1450
|
+
}));
|
|
1451
|
+
return pipeline;
|
|
1452
|
+
};
|
|
1453
|
+
}
|
|
1454
|
+
function stringifyFilterValue(value) {
|
|
1455
|
+
if (value == null) {
|
|
1456
|
+
return '';
|
|
1457
|
+
}
|
|
1458
|
+
return typeof value === 'string' ? value : String(value);
|
|
1459
|
+
}
|
|
1460
|
+
function isBlankFilterValue(value) {
|
|
1461
|
+
return stringifyFilterValue(value).trim() === '';
|
|
1462
|
+
}
|
|
1463
|
+
function processColumns(columns, { filterData, onChangeFilterData, Popover, popoverProps, keepDataSource, FilterHeaderCell, }) {
|
|
1464
|
+
const filterMap = new Map(filterData.map((item) => [item.code, stringifyFilterValue(item.filterValue)]));
|
|
1465
|
+
return columns.map(dfs);
|
|
1466
|
+
function dfs(col) {
|
|
1467
|
+
var _a;
|
|
1468
|
+
const result = Object.assign({}, col);
|
|
1469
|
+
if (pipeline.isLeafNode(col) && col.code && col.filterProps) {
|
|
1470
|
+
const filterValue = (_a = filterMap.get(col.code)) !== null && _a !== void 0 ? _a : '';
|
|
1471
|
+
result.title = (React__default["default"].createElement(ManagedFilterHeader, { Popover: Popover, FilterHeaderCell: FilterHeaderCell, column: col, filterModeOptions: { keepDataSource }, filterValue: filterValue, popoverProps: popoverProps, onChangeFilterValue: (nextFilterValue) => {
|
|
1472
|
+
onChangeFilterData(updateFilterData(filterData, col.code, nextFilterValue));
|
|
1473
|
+
} }, pipeline.internals.safeRenderHeader(col)));
|
|
1474
|
+
}
|
|
1475
|
+
if (!pipeline.isLeafNode(col)) {
|
|
1476
|
+
result.children = col.children.map(dfs);
|
|
1477
|
+
}
|
|
1478
|
+
return result;
|
|
1479
|
+
}
|
|
1480
|
+
}
|
|
1481
|
+
function ManagedFilterHeader({ Popover, FilterHeaderCell, column, filterModeOptions, filterValue, popoverProps, onChangeFilterValue, children, }) {
|
|
1482
|
+
var _a, _b, _c;
|
|
1483
|
+
const [open, setOpen] = React.useState(false);
|
|
1484
|
+
const [draftValue, setDraftValue] = React.useState(filterValue);
|
|
1485
|
+
React.useEffect(() => {
|
|
1486
|
+
setDraftValue(filterValue);
|
|
1487
|
+
}, [filterValue]);
|
|
1488
|
+
const showSearch = ((_a = column.filterProps) === null || _a === void 0 ? void 0 : _a.showSearch) !== false;
|
|
1489
|
+
const options = (_c = (_b = column.filterProps) === null || _b === void 0 ? void 0 : _b.dataSource) !== null && _c !== void 0 ? _c : [];
|
|
1490
|
+
const active = !isBlankFilterValue(filterValue);
|
|
1491
|
+
const visibleOptions = options.filter((item) => {
|
|
1492
|
+
if (!showSearch || isBlankFilterValue(draftValue)) {
|
|
1493
|
+
return true;
|
|
1494
|
+
}
|
|
1495
|
+
return item.toLowerCase().includes(draftValue.toLowerCase());
|
|
1496
|
+
});
|
|
1497
|
+
const filterPanel = (React__default["default"].createElement(FilterPanel, { onClick: (event) => {
|
|
1498
|
+
event.stopPropagation();
|
|
1499
|
+
} },
|
|
1500
|
+
showSearch ? (React__default["default"].createElement(FilterInput, { value: draftValue, placeholder: `筛选${column.name}`, onChange: (event) => {
|
|
1501
|
+
event.stopPropagation();
|
|
1502
|
+
setDraftValue(event.target.value);
|
|
1503
|
+
}, onClick: (event) => {
|
|
1504
|
+
event.stopPropagation();
|
|
1505
|
+
} })) : null,
|
|
1506
|
+
options.length > 0 ? (React__default["default"].createElement(FilterOptionList, null, visibleOptions.map((item) => (React__default["default"].createElement(FilterOptionButton, { key: item, type: "button", active: draftValue === item, onClick: (event) => {
|
|
1507
|
+
event.stopPropagation();
|
|
1508
|
+
setDraftValue(item);
|
|
1509
|
+
} }, item))))) : null,
|
|
1510
|
+
!showSearch && options.length === 0 ? React__default["default"].createElement(FilterEmptyState, null, "\u5F53\u524D\u5217\u6CA1\u6709\u53EF\u9009\u7684\u9884\u7F6E\u7B5B\u9009\u9879\u3002") : null,
|
|
1511
|
+
showSearch && options.length > 0 && visibleOptions.length === 0 ? React__default["default"].createElement(FilterEmptyState, null, "\u6CA1\u6709\u5339\u914D\u7684\u9884\u7F6E\u7B5B\u9009\u9879\u3002") : null,
|
|
1512
|
+
React__default["default"].createElement(FilterActionRow, null,
|
|
1513
|
+
React__default["default"].createElement(FilterActionButton, { type: "button", onClick: (event) => {
|
|
1514
|
+
event.stopPropagation();
|
|
1515
|
+
setDraftValue('');
|
|
1516
|
+
onChangeFilterValue('');
|
|
1517
|
+
setOpen(false);
|
|
1518
|
+
} }, "\u91CD\u7F6E"),
|
|
1519
|
+
React__default["default"].createElement(FilterActionButton, { primary: true, type: "button", onClick: (event) => {
|
|
1520
|
+
event.stopPropagation();
|
|
1521
|
+
onChangeFilterValue(draftValue);
|
|
1522
|
+
setOpen(false);
|
|
1523
|
+
} }, "\u786E\u8BA4"))));
|
|
1524
|
+
return (React__default["default"].createElement(FilterHeaderCell, { Popover: Popover, column: column, filterModeOptions: filterModeOptions, filterPanel: filterPanel, filterValue: filterValue, active: active, open: open, setOpen: setOpen, popoverProps: popoverProps }, children));
|
|
1525
|
+
}
|
|
1526
|
+
function DefaultFilterHeaderCell({ Popover, children, column, filterPanel, active, open, setOpen, popoverProps, }) {
|
|
1527
|
+
const justifyContent = column.align === 'right' ? 'flex-end' : column.align === 'center' ? 'center' : 'flex-start';
|
|
1528
|
+
return (React__default["default"].createElement(FilterHeaderShell, { style: { justifyContent } },
|
|
1529
|
+
children,
|
|
1530
|
+
React__default["default"].createElement(Popover, Object.assign({ visible: open, content: filterPanel }, popoverProps),
|
|
1531
|
+
React__default["default"].createElement(FilterTrigger, { active: active, type: "button", "aria-label": `筛选${column.name}`, onClick: (event) => {
|
|
1532
|
+
event.stopPropagation();
|
|
1533
|
+
setOpen(!open);
|
|
1534
|
+
} },
|
|
1535
|
+
React__default["default"].createElement(pipeline.icons.Filter, null)))));
|
|
1536
|
+
}
|
|
1537
|
+
|
|
1259
1538
|
function multiSelect(opts = {}) {
|
|
1260
1539
|
return function multiSelectStep(pipeline$1) {
|
|
1261
1540
|
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l;
|
|
@@ -1391,6 +1670,7 @@ function multiSelect(opts = {}) {
|
|
|
1391
1670
|
}
|
|
1392
1671
|
|
|
1393
1672
|
const rowDetailSymbol = Symbol('row-detail');
|
|
1673
|
+
const openEndedSpanRight$1 = Number.MAX_SAFE_INTEGER;
|
|
1394
1674
|
const fallbackRenderDetail = () => (React__default["default"].createElement("div", { style: { margin: '8px 24px' } },
|
|
1395
1675
|
React__default["default"].createElement("b", { style: { color: 'indianred' } },
|
|
1396
1676
|
"\u8BBE\u7F6E ",
|
|
@@ -1451,7 +1731,6 @@ function rowDetail(opts = {}) {
|
|
|
1451
1731
|
if (columns.length === 0) {
|
|
1452
1732
|
return columns;
|
|
1453
1733
|
}
|
|
1454
|
-
const columnFlatCount = pipeline.collectNodes(columns, 'leaf-only').length;
|
|
1455
1734
|
const [firstCol, ...others] = columns;
|
|
1456
1735
|
const render = (value, row, rowIndex) => {
|
|
1457
1736
|
if (row[rowDetailMetaKey]) {
|
|
@@ -1503,8 +1782,8 @@ function rowDetail(opts = {}) {
|
|
|
1503
1782
|
return [
|
|
1504
1783
|
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
1784
|
if (row[rowDetailMetaKey]) {
|
|
1506
|
-
// detail
|
|
1507
|
-
return { top: rowIndex, bottom: rowIndex + 1, left: 0, right:
|
|
1785
|
+
// detail 总是成一行,并且需要覆盖后续 feature 追加的列
|
|
1786
|
+
return { top: rowIndex, bottom: rowIndex + 1, left: 0, right: openEndedSpanRight$1 };
|
|
1508
1787
|
}
|
|
1509
1788
|
} }),
|
|
1510
1789
|
...others,
|
|
@@ -1608,6 +1887,7 @@ function rowPopover(opts = {}) {
|
|
|
1608
1887
|
}
|
|
1609
1888
|
|
|
1610
1889
|
const groupingMetaSymbol = Symbol('row-grouping-meta');
|
|
1890
|
+
const openEndedSpanRight = Number.MAX_SAFE_INTEGER;
|
|
1611
1891
|
function attachGroupingMeta(row) {
|
|
1612
1892
|
return Object.assign({ [groupingMetaSymbol]: { expandable: !pipeline.isLeafNode(row) } }, row);
|
|
1613
1893
|
}
|
|
@@ -1659,7 +1939,6 @@ function rowGrouping(opts = {}) {
|
|
|
1659
1939
|
if (columns.length === 0) {
|
|
1660
1940
|
return columns;
|
|
1661
1941
|
}
|
|
1662
|
-
const columnFlatCount = pipeline.collectNodes(columns, 'leaf-only').length;
|
|
1663
1942
|
const [firstCol, ...others] = columns;
|
|
1664
1943
|
const render = (value, row, rowIndex) => {
|
|
1665
1944
|
var _a, _b;
|
|
@@ -1708,7 +1987,7 @@ function rowGrouping(opts = {}) {
|
|
|
1708
1987
|
getCellProps,
|
|
1709
1988
|
getSpanRect(value, row, rowIndex) {
|
|
1710
1989
|
if (getGroupingMeta(row).isGroupHeader) {
|
|
1711
|
-
return { top: rowIndex, bottom: rowIndex + 1, left: 0, right:
|
|
1990
|
+
return { top: rowIndex, bottom: rowIndex + 1, left: 0, right: openEndedSpanRight };
|
|
1712
1991
|
}
|
|
1713
1992
|
} }),
|
|
1714
1993
|
...others,
|
|
@@ -2374,6 +2653,7 @@ var index = /*#__PURE__*/Object.freeze({
|
|
|
2374
2653
|
columnRangeHover: columnRangeHover,
|
|
2375
2654
|
columnResize: columnResize,
|
|
2376
2655
|
fillRemainingWidth: fillRemainingWidth,
|
|
2656
|
+
filterMode: filterMode,
|
|
2377
2657
|
multiSelect: multiSelect,
|
|
2378
2658
|
rowDetail: rowDetail,
|
|
2379
2659
|
rowPopover: rowPopover,
|