@guozhi5658/srp-table 1.1.3 → 1.1.5
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/__tests__/empty.test.d.ts +1 -0
- package/dist/chunks/{srp-table-pipeline-67cab92a.esm.js → srp-table-pipeline-0c8b9684.esm.js} +34 -1
- package/dist/chunks/{srp-table-pipeline-f974e586.js → srp-table-pipeline-68f4025a.js} +34 -1
- package/dist/common-views.d.ts +2 -0
- package/dist/interfaces.d.ts +10 -0
- package/dist/pipeline/features/__tests__/columnResize.test.d.ts +1 -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 +357 -34
- package/dist/srp-table.js +355 -32
- package/package.json +2 -1
- package/readme.md +50 -58
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
package/dist/chunks/{srp-table-pipeline-67cab92a.esm.js → srp-table-pipeline-0c8b9684.esm.js}
RENAMED
|
@@ -1022,8 +1022,36 @@ const StyledArtTableWrapper = styled__default.div `
|
|
|
1022
1022
|
//#endregion
|
|
1023
1023
|
`;
|
|
1024
1024
|
|
|
1025
|
+
/** 内联的空状态插图(原 img.alicdn.com 上的同一张 SVG),避免渲染空表格时发起外部网络请求 */
|
|
1026
|
+
function EmptyImage() {
|
|
1027
|
+
return (React.createElement("svg", { className: "empty-image", role: "img", "aria-label": "empty-image", width: "50", height: "50", viewBox: "0 0 50 50" },
|
|
1028
|
+
React.createElement("defs", null,
|
|
1029
|
+
React.createElement("path", { d: "M.008 3.68v23.456l17.808-4.963.366-22.165L.008 3.68z", id: "srp-empty-a" }),
|
|
1030
|
+
React.createElement("linearGradient", { x1: "33.757%", y1: "68.854%", x2: "80.209%", y2: "31.388%", id: "srp-empty-b" },
|
|
1031
|
+
React.createElement("stop", { stopColor: "#7B8594", stopOpacity: ".2", offset: "0%" }),
|
|
1032
|
+
React.createElement("stop", { stopColor: "#8C96A5", stopOpacity: ".4", offset: "100%" })),
|
|
1033
|
+
React.createElement("linearGradient", { x1: "50%", y1: "60.911%", x2: "50%", y2: "0%", id: "srp-empty-c" },
|
|
1034
|
+
React.createElement("stop", { stopColor: "#B0B8C2", stopOpacity: ".2", offset: "0%" }),
|
|
1035
|
+
React.createElement("stop", { stopColor: "#8992A1", stopOpacity: ".2", offset: "100%" }))),
|
|
1036
|
+
React.createElement("g", { fill: "none", fillRule: "evenodd" },
|
|
1037
|
+
React.createElement("circle", { fillOpacity: ".04", fill: "#1F3858", cx: "25", cy: "25", r: "25" }),
|
|
1038
|
+
React.createElement("path", { d: "M25.052 21.613v23.455l17.807-4.963.366-22.164-18.173 3.672z", fill: "#E0E4E9", opacity: ".96" }),
|
|
1039
|
+
React.createElement("use", { fill: "#E0E4E9", xlinkHref: "#srp-empty-a", transform: "translate(25.043 17.933)" }),
|
|
1040
|
+
React.createElement("path", { fill: "#E0E4E9", d: "M5.38 19.338V40.83l19.767 4.27-.131-23.426z" }),
|
|
1041
|
+
React.createElement("path", { fill: "url(#srp-empty-b)", opacity: ".6", transform: "matrix(1 0 0 -1 5 48.762)", d: "M.456 7.927L0 28.729l19.39-2.121V3.783z" }),
|
|
1042
|
+
React.createElement("path", { fill: "url(#srp-empty-c)", d: "M19.493 5.517v23.38l18.357-5.018.578-22.15z", transform: "translate(5 16.25)" }),
|
|
1043
|
+
React.createElement("path", { fill: "#A4AFBF", opacity: ".8", d: "M5.102 19.467l17.003-3.184 21.336 1.702-18.35 3.67z" }),
|
|
1044
|
+
React.createElement("path", { fill: "#9EA7B3", opacity: ".8", d: "M22.105 21.654v-5.37l21.336 1.7-18.35 3.67z" }),
|
|
1045
|
+
React.createElement("path", { fill: "#F3F4F5", d: "M25.058 21.663l6.152 8.96 18.376-5.081-6.147-7.562z" }),
|
|
1046
|
+
React.createElement("path", { fill: "#FFF", opacity: ".1", d: "M49.586 25.542L43.44 17.98l-18.381 3.683 6.152 8.96z" }),
|
|
1047
|
+
React.createElement("path", { fill: "#F3F4F5", d: "M5.121 19.47l-4.51 8.165 20.125 3.38 4.304-9.355z" }),
|
|
1048
|
+
React.createElement("path", { fill: "#FFF", opacity: ".1", d: "M20.736 31.016l4.304-9.356-19.919-2.19-4.51 8.165z" }),
|
|
1049
|
+
React.createElement("path", { d: "M7.465.327s.31 7.984 5.255 10.119c4.946 2.134 10.727-1.347 10.727-1.347s-7.445-3.635-8.152-6.672c-4.63.725-7.83-2.1-7.83-2.1z", fill: "#FFF" }),
|
|
1050
|
+
React.createElement("path", { d: "M8.369 5.029s2.201 2.844 5.68 2.54c1.816 2.823 7.532 2.462 7.532 2.462s-4.541 2.134-8.043.988c-3.503-1.145-5.17-5.99-5.17-5.99z", fill: "#CFD4DB" }),
|
|
1051
|
+
React.createElement("path", { d: "M33.426 9.209c.877.466 3.192.205 4.399-.207-.512.963-1.56 2.314-2.757 3.614-.755.82-2.013 1.64-3.18 2.009-1.898.165-3.603-.37-3.603-.37s3.509-1.977 5.14-5.046z", fill: "#FFF" }))));
|
|
1052
|
+
}
|
|
1025
1053
|
const DefaultEmptyContent = React.memo(() => (React.createElement(React.Fragment, null,
|
|
1026
|
-
React.createElement(
|
|
1054
|
+
React.createElement(EmptyImage, null),
|
|
1027
1055
|
React.createElement("div", { className: "empty-tips" },
|
|
1028
1056
|
"\u6CA1\u6709\u7B26\u5408\u67E5\u8BE2\u6761\u4EF6\u7684\u6570\u636E",
|
|
1029
1057
|
React.createElement("br", null),
|
|
@@ -2383,6 +2411,10 @@ function InfoIcon(props) {
|
|
|
2383
2411
|
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" }),
|
|
2384
2412
|
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" })));
|
|
2385
2413
|
}
|
|
2414
|
+
function FilterIcon(props) {
|
|
2415
|
+
return (React.createElement("svg", Object.assign({ focusable: "false", preserveAspectRatio: "xMidYMid meet", fill: "currentColor", width: "16", height: "16", viewBox: "0 0 16 16" }, props),
|
|
2416
|
+
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" })));
|
|
2417
|
+
}
|
|
2386
2418
|
function CaretRightIcon(props) {
|
|
2387
2419
|
return (React.createElement("svg", Object.assign({ focusable: "false", preserveAspectRatio: "xMidYMid meet", fill: "currentColor", width: "16", height: "16", viewBox: "0 0 32 32" }, props),
|
|
2388
2420
|
React.createElement("path", { d: "M12 8L22 16 12 24z" })));
|
|
@@ -2395,6 +2427,7 @@ const icons = {
|
|
|
2395
2427
|
Loading: LoadingIcon,
|
|
2396
2428
|
CaretDown: CaretDownIcon,
|
|
2397
2429
|
CaretRight: CaretRightIcon,
|
|
2430
|
+
Filter: FilterIcon,
|
|
2398
2431
|
Info: InfoIcon,
|
|
2399
2432
|
};
|
|
2400
2433
|
|
|
@@ -1049,8 +1049,36 @@ const StyledArtTableWrapper = styled__default["default"].div `
|
|
|
1049
1049
|
//#endregion
|
|
1050
1050
|
`;
|
|
1051
1051
|
|
|
1052
|
+
/** 内联的空状态插图(原 img.alicdn.com 上的同一张 SVG),避免渲染空表格时发起外部网络请求 */
|
|
1053
|
+
function EmptyImage() {
|
|
1054
|
+
return (React__default["default"].createElement("svg", { className: "empty-image", role: "img", "aria-label": "empty-image", width: "50", height: "50", viewBox: "0 0 50 50" },
|
|
1055
|
+
React__default["default"].createElement("defs", null,
|
|
1056
|
+
React__default["default"].createElement("path", { d: "M.008 3.68v23.456l17.808-4.963.366-22.165L.008 3.68z", id: "srp-empty-a" }),
|
|
1057
|
+
React__default["default"].createElement("linearGradient", { x1: "33.757%", y1: "68.854%", x2: "80.209%", y2: "31.388%", id: "srp-empty-b" },
|
|
1058
|
+
React__default["default"].createElement("stop", { stopColor: "#7B8594", stopOpacity: ".2", offset: "0%" }),
|
|
1059
|
+
React__default["default"].createElement("stop", { stopColor: "#8C96A5", stopOpacity: ".4", offset: "100%" })),
|
|
1060
|
+
React__default["default"].createElement("linearGradient", { x1: "50%", y1: "60.911%", x2: "50%", y2: "0%", id: "srp-empty-c" },
|
|
1061
|
+
React__default["default"].createElement("stop", { stopColor: "#B0B8C2", stopOpacity: ".2", offset: "0%" }),
|
|
1062
|
+
React__default["default"].createElement("stop", { stopColor: "#8992A1", stopOpacity: ".2", offset: "100%" }))),
|
|
1063
|
+
React__default["default"].createElement("g", { fill: "none", fillRule: "evenodd" },
|
|
1064
|
+
React__default["default"].createElement("circle", { fillOpacity: ".04", fill: "#1F3858", cx: "25", cy: "25", r: "25" }),
|
|
1065
|
+
React__default["default"].createElement("path", { d: "M25.052 21.613v23.455l17.807-4.963.366-22.164-18.173 3.672z", fill: "#E0E4E9", opacity: ".96" }),
|
|
1066
|
+
React__default["default"].createElement("use", { fill: "#E0E4E9", xlinkHref: "#srp-empty-a", transform: "translate(25.043 17.933)" }),
|
|
1067
|
+
React__default["default"].createElement("path", { fill: "#E0E4E9", d: "M5.38 19.338V40.83l19.767 4.27-.131-23.426z" }),
|
|
1068
|
+
React__default["default"].createElement("path", { fill: "url(#srp-empty-b)", opacity: ".6", transform: "matrix(1 0 0 -1 5 48.762)", d: "M.456 7.927L0 28.729l19.39-2.121V3.783z" }),
|
|
1069
|
+
React__default["default"].createElement("path", { fill: "url(#srp-empty-c)", d: "M19.493 5.517v23.38l18.357-5.018.578-22.15z", transform: "translate(5 16.25)" }),
|
|
1070
|
+
React__default["default"].createElement("path", { fill: "#A4AFBF", opacity: ".8", d: "M5.102 19.467l17.003-3.184 21.336 1.702-18.35 3.67z" }),
|
|
1071
|
+
React__default["default"].createElement("path", { fill: "#9EA7B3", opacity: ".8", d: "M22.105 21.654v-5.37l21.336 1.7-18.35 3.67z" }),
|
|
1072
|
+
React__default["default"].createElement("path", { fill: "#F3F4F5", d: "M25.058 21.663l6.152 8.96 18.376-5.081-6.147-7.562z" }),
|
|
1073
|
+
React__default["default"].createElement("path", { fill: "#FFF", opacity: ".1", d: "M49.586 25.542L43.44 17.98l-18.381 3.683 6.152 8.96z" }),
|
|
1074
|
+
React__default["default"].createElement("path", { fill: "#F3F4F5", d: "M5.121 19.47l-4.51 8.165 20.125 3.38 4.304-9.355z" }),
|
|
1075
|
+
React__default["default"].createElement("path", { fill: "#FFF", opacity: ".1", d: "M20.736 31.016l4.304-9.356-19.919-2.19-4.51 8.165z" }),
|
|
1076
|
+
React__default["default"].createElement("path", { d: "M7.465.327s.31 7.984 5.255 10.119c4.946 2.134 10.727-1.347 10.727-1.347s-7.445-3.635-8.152-6.672c-4.63.725-7.83-2.1-7.83-2.1z", fill: "#FFF" }),
|
|
1077
|
+
React__default["default"].createElement("path", { d: "M8.369 5.029s2.201 2.844 5.68 2.54c1.816 2.823 7.532 2.462 7.532 2.462s-4.541 2.134-8.043.988c-3.503-1.145-5.17-5.99-5.17-5.99z", fill: "#CFD4DB" }),
|
|
1078
|
+
React__default["default"].createElement("path", { d: "M33.426 9.209c.877.466 3.192.205 4.399-.207-.512.963-1.56 2.314-2.757 3.614-.755.82-2.013 1.64-3.18 2.009-1.898.165-3.603-.37-3.603-.37s3.509-1.977 5.14-5.046z", fill: "#FFF" }))));
|
|
1079
|
+
}
|
|
1052
1080
|
const DefaultEmptyContent = React__default["default"].memo(() => (React__default["default"].createElement(React__default["default"].Fragment, null,
|
|
1053
|
-
React__default["default"].createElement(
|
|
1081
|
+
React__default["default"].createElement(EmptyImage, null),
|
|
1054
1082
|
React__default["default"].createElement("div", { className: "empty-tips" },
|
|
1055
1083
|
"\u6CA1\u6709\u7B26\u5408\u67E5\u8BE2\u6761\u4EF6\u7684\u6570\u636E",
|
|
1056
1084
|
React__default["default"].createElement("br", null),
|
|
@@ -2410,6 +2438,10 @@ function InfoIcon(props) {
|
|
|
2410
2438
|
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" }),
|
|
2411
2439
|
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" })));
|
|
2412
2440
|
}
|
|
2441
|
+
function FilterIcon(props) {
|
|
2442
|
+
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),
|
|
2443
|
+
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" })));
|
|
2444
|
+
}
|
|
2413
2445
|
function CaretRightIcon(props) {
|
|
2414
2446
|
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),
|
|
2415
2447
|
React__default["default"].createElement("path", { d: "M12 8L22 16 12 24z" })));
|
|
@@ -2422,6 +2454,7 @@ const icons = {
|
|
|
2422
2454
|
Loading: LoadingIcon,
|
|
2423
2455
|
CaretDown: CaretDownIcon,
|
|
2424
2456
|
CaretRight: CaretRightIcon,
|
|
2457
|
+
Filter: FilterIcon,
|
|
2425
2458
|
Info: InfoIcon,
|
|
2426
2459
|
};
|
|
2427
2460
|
|
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 @@
|
|
|
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-0c8b9684.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-68f4025a.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,6 +1,6 @@
|
|
|
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-
|
|
3
|
-
import React, { useState, useEffect } from 'react';
|
|
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-0c8b9684.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-0c8b9684.esm.js';
|
|
3
|
+
import React, { useState, useEffect, useRef } from 'react';
|
|
4
4
|
import styled__default from 'styled-components';
|
|
5
5
|
import { fromEvent } from 'rxjs';
|
|
6
6
|
import * as op from 'rxjs/operators';
|
|
@@ -1124,6 +1124,7 @@ const ResizeHandle = styled__default.span `
|
|
|
1124
1124
|
right: -5px;
|
|
1125
1125
|
width: 10px;
|
|
1126
1126
|
cursor: col-resize;
|
|
1127
|
+
touch-action: none;
|
|
1127
1128
|
z-index: 1;
|
|
1128
1129
|
transition: background-color 200ms;
|
|
1129
1130
|
|
|
@@ -1137,6 +1138,20 @@ const ResizeHandle = styled__default.span `
|
|
|
1137
1138
|
}};
|
|
1138
1139
|
}
|
|
1139
1140
|
`;
|
|
1141
|
+
/** 把手在卸载时结束仍在进行的拖拽,避免遗留 window 监听与 user-select 状态 */
|
|
1142
|
+
function ColumnResizeHandle(_a) {
|
|
1143
|
+
var { onStartResize } = _a, rest = __rest(_a, ["onStartResize"]);
|
|
1144
|
+
const stopRef = useRef();
|
|
1145
|
+
useEffect(() => () => { var _a; return (_a = stopRef.current) === null || _a === void 0 ? void 0 : _a.call(stopRef, false); }, []);
|
|
1146
|
+
return (React.createElement(ResizeHandle, Object.assign({}, rest, { onPointerDown: (e) => {
|
|
1147
|
+
if (e.button !== 0 || stopRef.current) {
|
|
1148
|
+
return;
|
|
1149
|
+
}
|
|
1150
|
+
stopRef.current = onStartResize(e, () => {
|
|
1151
|
+
stopRef.current = undefined;
|
|
1152
|
+
});
|
|
1153
|
+
} })));
|
|
1154
|
+
}
|
|
1140
1155
|
function columnResize(opts = {}) {
|
|
1141
1156
|
var _a, _b, _c, _d;
|
|
1142
1157
|
const stateKey = 'columnResize';
|
|
@@ -1164,26 +1179,24 @@ function columnResize(opts = {}) {
|
|
|
1164
1179
|
pipeline.setStateAtKey(stateKey, nextSizes);
|
|
1165
1180
|
(_a = opts.onChangeSizes) === null || _a === void 0 ? void 0 : _a.call(opts, nextSizes);
|
|
1166
1181
|
};
|
|
1167
|
-
const
|
|
1182
|
+
const computeSizes = (startIndex, endIndex, deltaSum) => {
|
|
1183
|
+
const nextSizes = sizes.slice();
|
|
1184
|
+
const sizeSum = sizes.slice(startIndex, endIndex).reduce((sum, s) => sum + s, 0);
|
|
1185
|
+
let deltaRemaining = deltaSum;
|
|
1186
|
+
for (let colIndex = startIndex; colIndex < endIndex - 1; colIndex++) {
|
|
1187
|
+
const startSize = sizes[colIndex];
|
|
1188
|
+
// 将每一列的宽度变化量 都四舍五入至 整数,不然看起来非常难受
|
|
1189
|
+
const colDelta = Math.round(deltaSum * (startSize / sizeSum));
|
|
1190
|
+
nextSizes[colIndex] = clamp(minSize, startSize + colDelta, maxSize);
|
|
1191
|
+
deltaRemaining -= colDelta;
|
|
1192
|
+
}
|
|
1193
|
+
// 因为前面的列宽都进行了四舍五入,最后一列的变化量需要使用 deltaRemaining 以避免误差
|
|
1194
|
+
nextSizes[endIndex - 1] = clamp(minSize, sizes[endIndex - 1] + deltaRemaining, maxSize);
|
|
1195
|
+
return nextSizes;
|
|
1196
|
+
};
|
|
1197
|
+
const startResize = (startIndex, endIndex, e, onFinish) => {
|
|
1168
1198
|
const startX = e.clientX;
|
|
1169
|
-
const target = e.
|
|
1170
|
-
const nextSizes$ = fromEvent(window, 'mousemove').pipe(op.takeUntil(fromEvent(window, 'mouseup')), op.map((e) => {
|
|
1171
|
-
const movingX = e.clientX;
|
|
1172
|
-
const nextSizes = sizes.slice();
|
|
1173
|
-
const deltaSum = movingX - startX;
|
|
1174
|
-
const sizeSum = sizes.slice(startIndex, endIndex).reduce((sum, s) => sum + s, 0);
|
|
1175
|
-
let deltaRemaining = deltaSum;
|
|
1176
|
-
for (let colIndex = startIndex; colIndex < endIndex - 1; colIndex++) {
|
|
1177
|
-
const startSize = sizes[colIndex];
|
|
1178
|
-
// 将每一列的宽度变化量 都四舍五入至 整数,不然看起来非常难受
|
|
1179
|
-
const colDelta = Math.round(deltaSum * (startSize / sizeSum));
|
|
1180
|
-
nextSizes[colIndex] = clamp(minSize, startSize + colDelta, maxSize);
|
|
1181
|
-
deltaRemaining -= colDelta;
|
|
1182
|
-
}
|
|
1183
|
-
// 因为前面的列宽都进行了四舍五入,最后一列的变化量需要使用 deltaRemaining 以避免误差
|
|
1184
|
-
nextSizes[endIndex - 1] = clamp(minSize, sizes[endIndex - 1] + deltaRemaining, maxSize);
|
|
1185
|
-
return nextSizes;
|
|
1186
|
-
}));
|
|
1199
|
+
const target = e.currentTarget;
|
|
1187
1200
|
let prevUserSelect = '';
|
|
1188
1201
|
let docElemStyle;
|
|
1189
1202
|
if (disableUserSelectWhenResizing) {
|
|
@@ -1194,23 +1207,52 @@ function columnResize(opts = {}) {
|
|
|
1194
1207
|
if (opts.handleActiveBackground) {
|
|
1195
1208
|
target.style.background = opts.handleActiveBackground;
|
|
1196
1209
|
}
|
|
1197
|
-
|
|
1198
|
-
|
|
1199
|
-
|
|
1200
|
-
|
|
1201
|
-
|
|
1202
|
-
|
|
1203
|
-
|
|
1204
|
-
|
|
1205
|
-
|
|
1206
|
-
}
|
|
1207
|
-
}
|
|
1210
|
+
// 拖动过程中每帧最多提交一次列宽,松手时补交最后一次
|
|
1211
|
+
let pending = null;
|
|
1212
|
+
let frame = 0;
|
|
1213
|
+
const flush = () => {
|
|
1214
|
+
frame = 0;
|
|
1215
|
+
if (pending != null) {
|
|
1216
|
+
const nextSizes = pending;
|
|
1217
|
+
pending = null;
|
|
1218
|
+
onChangeSizes(nextSizes);
|
|
1219
|
+
}
|
|
1220
|
+
};
|
|
1221
|
+
const onMove = (ev) => {
|
|
1222
|
+
pending = computeSizes(startIndex, endIndex, ev.clientX - startX);
|
|
1223
|
+
if (frame === 0) {
|
|
1224
|
+
frame = requestAnimationFrame(flush);
|
|
1225
|
+
}
|
|
1226
|
+
};
|
|
1227
|
+
const stop = (commit) => {
|
|
1228
|
+
window.removeEventListener('pointermove', onMove);
|
|
1229
|
+
window.removeEventListener('pointerup', onEnd);
|
|
1230
|
+
window.removeEventListener('pointercancel', onEnd);
|
|
1231
|
+
cancelAnimationFrame(frame);
|
|
1232
|
+
if (commit) {
|
|
1233
|
+
flush();
|
|
1234
|
+
}
|
|
1235
|
+
if (disableUserSelectWhenResizing) {
|
|
1236
|
+
docElemStyle.userSelect = prevUserSelect;
|
|
1237
|
+
}
|
|
1238
|
+
if (opts.handleActiveBackground) {
|
|
1239
|
+
target.style.background = '';
|
|
1240
|
+
}
|
|
1241
|
+
};
|
|
1242
|
+
const onEnd = () => {
|
|
1243
|
+
stop(true);
|
|
1244
|
+
onFinish();
|
|
1245
|
+
};
|
|
1246
|
+
window.addEventListener('pointermove', onMove);
|
|
1247
|
+
window.addEventListener('pointerup', onEnd);
|
|
1248
|
+
window.addEventListener('pointercancel', onEnd);
|
|
1249
|
+
return stop;
|
|
1208
1250
|
};
|
|
1209
1251
|
const resizedColumns = makeRecursiveMapper((col, { startIndex, endIndex }) => {
|
|
1210
1252
|
const prevTitle = internals.safeRenderHeader(col);
|
|
1211
1253
|
return Object.assign(Object.assign({}, col), { width: sizes[startIndex], title: (React.createElement(React.Fragment, null,
|
|
1212
1254
|
prevTitle,
|
|
1213
|
-
React.createElement(
|
|
1255
|
+
React.createElement(ColumnResizeHandle, { className: "resize-handle", "var-handleBackground": opts.handleBackground, "var-handleHoverBackground": opts.handleHoverBackground, onStartResize: (e, onFinish) => startResize(startIndex, endIndex, e, onFinish) }))), headerCellProps: mergeCellProps(col.headerCellProps, {
|
|
1214
1256
|
style: {
|
|
1215
1257
|
overflow: 'visible',
|
|
1216
1258
|
position: 'relative',
|
|
@@ -1227,6 +1269,286 @@ function fillRemainingWidth() {
|
|
|
1227
1269
|
};
|
|
1228
1270
|
}
|
|
1229
1271
|
|
|
1272
|
+
function normalizeFilterData(filterData) {
|
|
1273
|
+
const filterMap = new Map();
|
|
1274
|
+
for (const item of filterData !== null && filterData !== void 0 ? filterData : []) {
|
|
1275
|
+
if (item == null || typeof item.code !== 'string' || item.code.length === 0) {
|
|
1276
|
+
continue;
|
|
1277
|
+
}
|
|
1278
|
+
if (isBlankFilterValue$1(item.filterValue)) {
|
|
1279
|
+
filterMap.delete(item.code);
|
|
1280
|
+
continue;
|
|
1281
|
+
}
|
|
1282
|
+
filterMap.set(item.code, {
|
|
1283
|
+
code: item.code,
|
|
1284
|
+
filterValue: stringifyFilterValue$1(item.filterValue),
|
|
1285
|
+
});
|
|
1286
|
+
}
|
|
1287
|
+
return Array.from(filterMap.values());
|
|
1288
|
+
}
|
|
1289
|
+
function updateFilterData(filterData, code, nextFilterValue) {
|
|
1290
|
+
const nextFilterData = normalizeFilterData(filterData).filter((item) => item.code !== code);
|
|
1291
|
+
if (isBlankFilterValue$1(nextFilterValue)) {
|
|
1292
|
+
return nextFilterData;
|
|
1293
|
+
}
|
|
1294
|
+
nextFilterData.push({
|
|
1295
|
+
code,
|
|
1296
|
+
filterValue: stringifyFilterValue$1(nextFilterValue),
|
|
1297
|
+
});
|
|
1298
|
+
return nextFilterData;
|
|
1299
|
+
}
|
|
1300
|
+
function getFilterableColumns(columns) {
|
|
1301
|
+
return collectNodes(columns, 'leaf-only').filter((column) => column.code != null && column.filterProps != null);
|
|
1302
|
+
}
|
|
1303
|
+
function filterDataSourceByFilterData(dataSource, columns, filterData) {
|
|
1304
|
+
const activeFilterData = normalizeFilterData(filterData);
|
|
1305
|
+
if (activeFilterData.length === 0) {
|
|
1306
|
+
return dataSource;
|
|
1307
|
+
}
|
|
1308
|
+
const filterColumnsMap = new Map(columns.map((column) => [column.code, column]));
|
|
1309
|
+
return dataSource.filter((record) => {
|
|
1310
|
+
return activeFilterData.every(({ code, filterValue }) => {
|
|
1311
|
+
const column = filterColumnsMap.get(code);
|
|
1312
|
+
if (column == null) {
|
|
1313
|
+
return true;
|
|
1314
|
+
}
|
|
1315
|
+
return matchFilterValue(column, stringifyFilterValue$1(filterValue), record);
|
|
1316
|
+
});
|
|
1317
|
+
});
|
|
1318
|
+
}
|
|
1319
|
+
function matchFilterValue(column, filterValue, record) {
|
|
1320
|
+
var _a;
|
|
1321
|
+
if (isBlankFilterValue$1(filterValue)) {
|
|
1322
|
+
return true;
|
|
1323
|
+
}
|
|
1324
|
+
const customFilter = (_a = column.filterProps) === null || _a === void 0 ? void 0 : _a.filterOptions;
|
|
1325
|
+
if (typeof customFilter === 'function') {
|
|
1326
|
+
return customFilter(filterValue, record);
|
|
1327
|
+
}
|
|
1328
|
+
const rawValue = record === null || record === void 0 ? void 0 : record[column.code];
|
|
1329
|
+
if (rawValue == null) {
|
|
1330
|
+
return false;
|
|
1331
|
+
}
|
|
1332
|
+
return String(rawValue).toLowerCase().includes(filterValue.toLowerCase());
|
|
1333
|
+
}
|
|
1334
|
+
function isBlankFilterValue$1(value) {
|
|
1335
|
+
return stringifyFilterValue$1(value).trim() === '';
|
|
1336
|
+
}
|
|
1337
|
+
function stringifyFilterValue$1(value) {
|
|
1338
|
+
if (value == null) {
|
|
1339
|
+
return '';
|
|
1340
|
+
}
|
|
1341
|
+
return typeof value === 'string' ? value : String(value);
|
|
1342
|
+
}
|
|
1343
|
+
|
|
1344
|
+
const FilterHeaderShell = styled__default.div `
|
|
1345
|
+
display: flex;
|
|
1346
|
+
align-items: center;
|
|
1347
|
+
`;
|
|
1348
|
+
const FilterTrigger = styled__default.button `
|
|
1349
|
+
display: inline-flex;
|
|
1350
|
+
align-items: center;
|
|
1351
|
+
justify-content: center;
|
|
1352
|
+
width: 20px;
|
|
1353
|
+
height: 20px;
|
|
1354
|
+
margin-left: 4px;
|
|
1355
|
+
padding: 0;
|
|
1356
|
+
border: none;
|
|
1357
|
+
background: transparent;
|
|
1358
|
+
color: ${(props) => (props.active ? '#23A3FF' : '#8c8c8c')};
|
|
1359
|
+
cursor: pointer;
|
|
1360
|
+
|
|
1361
|
+
&:hover {
|
|
1362
|
+
color: ${(props) => (props.active ? '#23A3FF' : '#595959')};
|
|
1363
|
+
}
|
|
1364
|
+
`;
|
|
1365
|
+
const FilterPanel = styled__default.div `
|
|
1366
|
+
width: 160px;
|
|
1367
|
+
padding: 8px 8px 6px;
|
|
1368
|
+
box-sizing: border-box;
|
|
1369
|
+
color: #262626;
|
|
1370
|
+
font-size: 12px;
|
|
1371
|
+
line-height: 1.5;
|
|
1372
|
+
`;
|
|
1373
|
+
const FilterInput = styled__default.input `
|
|
1374
|
+
width: 100%;
|
|
1375
|
+
height: 28px;
|
|
1376
|
+
padding: 0 8px;
|
|
1377
|
+
box-sizing: border-box;
|
|
1378
|
+
border: 1px solid #d9d9d9;
|
|
1379
|
+
border-radius: 5px;
|
|
1380
|
+
outline: none;
|
|
1381
|
+
font-size: 12px;
|
|
1382
|
+
line-height: 1.5;
|
|
1383
|
+
|
|
1384
|
+
&:focus {
|
|
1385
|
+
border-color: #23a3ff;
|
|
1386
|
+
}
|
|
1387
|
+
`;
|
|
1388
|
+
const FilterOptionList = styled__default.div `
|
|
1389
|
+
max-height: 136px;
|
|
1390
|
+
margin-top: 6px;
|
|
1391
|
+
overflow: auto;
|
|
1392
|
+
`;
|
|
1393
|
+
const FilterOptionButton = styled__default.button `
|
|
1394
|
+
width: 100%;
|
|
1395
|
+
min-height: 28px;
|
|
1396
|
+
margin-top: 4px;
|
|
1397
|
+
padding: 3px 8px;
|
|
1398
|
+
box-sizing: border-box;
|
|
1399
|
+
border: 1px solid ${(props) => (props.active ? '#23A3FF' : '#e8e8e8')};
|
|
1400
|
+
border-radius: 5px;
|
|
1401
|
+
background: ${(props) => (props.active ? 'rgba(35, 163, 255, 0.12)' : '#fff')};
|
|
1402
|
+
color: #262626;
|
|
1403
|
+
font-size: 12px;
|
|
1404
|
+
line-height: 1.5;
|
|
1405
|
+
text-align: left;
|
|
1406
|
+
cursor: pointer;
|
|
1407
|
+
`;
|
|
1408
|
+
const FilterActionRow = styled__default.div `
|
|
1409
|
+
display: flex;
|
|
1410
|
+
justify-content: flex-end;
|
|
1411
|
+
gap: 4px;
|
|
1412
|
+
margin-top: 6px;
|
|
1413
|
+
`;
|
|
1414
|
+
const FilterActionButton = styled__default.button `
|
|
1415
|
+
min-width: 44px;
|
|
1416
|
+
height: 26px;
|
|
1417
|
+
padding: 0 8px;
|
|
1418
|
+
box-sizing: border-box;
|
|
1419
|
+
border: 1px solid ${(props) => (props.primary ? '#23A3FF' : '#d9d9d9')};
|
|
1420
|
+
border-radius: 999px;
|
|
1421
|
+
background: ${(props) => (props.primary ? '#23A3FF' : '#fff')};
|
|
1422
|
+
color: ${(props) => (props.primary ? '#fff' : '#262626')};
|
|
1423
|
+
font-size: 12px;
|
|
1424
|
+
line-height: 1;
|
|
1425
|
+
cursor: pointer;
|
|
1426
|
+
`;
|
|
1427
|
+
const FilterEmptyState = styled__default.div `
|
|
1428
|
+
margin-top: 8px;
|
|
1429
|
+
color: #8c8c8c;
|
|
1430
|
+
font-size: 12px;
|
|
1431
|
+
line-height: 1.5;
|
|
1432
|
+
`;
|
|
1433
|
+
const stateKey$1 = 'filterMode';
|
|
1434
|
+
function filterMode(opts = {}) {
|
|
1435
|
+
return function filterModeStep(pipeline) {
|
|
1436
|
+
var _a, _b, _c, _d;
|
|
1437
|
+
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 : [];
|
|
1438
|
+
const filterData = normalizeFilterData(inputFilterData);
|
|
1439
|
+
const Popover = pipeline.ctx.components.Popover;
|
|
1440
|
+
const columns = pipeline.getColumns();
|
|
1441
|
+
const filterableColumns = getFilterableColumns(columns);
|
|
1442
|
+
if (filterableColumns.length === 0) {
|
|
1443
|
+
return pipeline;
|
|
1444
|
+
}
|
|
1445
|
+
if (Popover == null) {
|
|
1446
|
+
throw new Error('使用 filterMode 之前需要设置 pipeline.ctx.components.Popover');
|
|
1447
|
+
}
|
|
1448
|
+
const onChangeFilterData = (nextFilterData) => {
|
|
1449
|
+
var _a;
|
|
1450
|
+
const normalized = normalizeFilterData(nextFilterData);
|
|
1451
|
+
(_a = opts.onChangeFilterData) === null || _a === void 0 ? void 0 : _a.call(opts, normalized);
|
|
1452
|
+
pipeline.setStateAtKey(stateKey$1, normalized);
|
|
1453
|
+
};
|
|
1454
|
+
if (!opts.keepDataSource) {
|
|
1455
|
+
pipeline.dataSource(filterDataSourceByFilterData(pipeline.getDataSource(), filterableColumns, filterData));
|
|
1456
|
+
}
|
|
1457
|
+
pipeline.columns(processColumns(columns, {
|
|
1458
|
+
filterData,
|
|
1459
|
+
onChangeFilterData,
|
|
1460
|
+
Popover,
|
|
1461
|
+
popoverProps: opts.popoverProps,
|
|
1462
|
+
keepDataSource: Boolean(opts.keepDataSource),
|
|
1463
|
+
FilterHeaderCell: (_d = opts.FilterHeaderCell) !== null && _d !== void 0 ? _d : DefaultFilterHeaderCell,
|
|
1464
|
+
}));
|
|
1465
|
+
return pipeline;
|
|
1466
|
+
};
|
|
1467
|
+
}
|
|
1468
|
+
function stringifyFilterValue(value) {
|
|
1469
|
+
if (value == null) {
|
|
1470
|
+
return '';
|
|
1471
|
+
}
|
|
1472
|
+
return typeof value === 'string' ? value : String(value);
|
|
1473
|
+
}
|
|
1474
|
+
function isBlankFilterValue(value) {
|
|
1475
|
+
return stringifyFilterValue(value).trim() === '';
|
|
1476
|
+
}
|
|
1477
|
+
function processColumns(columns, { filterData, onChangeFilterData, Popover, popoverProps, keepDataSource, FilterHeaderCell, }) {
|
|
1478
|
+
const filterMap = new Map(filterData.map((item) => [item.code, stringifyFilterValue(item.filterValue)]));
|
|
1479
|
+
return columns.map(dfs);
|
|
1480
|
+
function dfs(col) {
|
|
1481
|
+
var _a;
|
|
1482
|
+
const result = Object.assign({}, col);
|
|
1483
|
+
if (isLeafNode(col) && col.code && col.filterProps) {
|
|
1484
|
+
const filterValue = (_a = filterMap.get(col.code)) !== null && _a !== void 0 ? _a : '';
|
|
1485
|
+
result.title = (React.createElement(ManagedFilterHeader, { Popover: Popover, FilterHeaderCell: FilterHeaderCell, column: col, filterModeOptions: { keepDataSource }, filterValue: filterValue, popoverProps: popoverProps, onChangeFilterValue: (nextFilterValue) => {
|
|
1486
|
+
onChangeFilterData(updateFilterData(filterData, col.code, nextFilterValue));
|
|
1487
|
+
} }, internals.safeRenderHeader(col)));
|
|
1488
|
+
}
|
|
1489
|
+
if (!isLeafNode(col)) {
|
|
1490
|
+
result.children = col.children.map(dfs);
|
|
1491
|
+
}
|
|
1492
|
+
return result;
|
|
1493
|
+
}
|
|
1494
|
+
}
|
|
1495
|
+
function ManagedFilterHeader({ Popover, FilterHeaderCell, column, filterModeOptions, filterValue, popoverProps, onChangeFilterValue, children, }) {
|
|
1496
|
+
var _a, _b, _c;
|
|
1497
|
+
const [open, setOpen] = useState(false);
|
|
1498
|
+
const [draftValue, setDraftValue] = useState(filterValue);
|
|
1499
|
+
useEffect(() => {
|
|
1500
|
+
setDraftValue(filterValue);
|
|
1501
|
+
}, [filterValue]);
|
|
1502
|
+
const showSearch = ((_a = column.filterProps) === null || _a === void 0 ? void 0 : _a.showSearch) !== false;
|
|
1503
|
+
const options = (_c = (_b = column.filterProps) === null || _b === void 0 ? void 0 : _b.dataSource) !== null && _c !== void 0 ? _c : [];
|
|
1504
|
+
const active = !isBlankFilterValue(filterValue);
|
|
1505
|
+
const visibleOptions = options.filter((item) => {
|
|
1506
|
+
if (!showSearch || isBlankFilterValue(draftValue)) {
|
|
1507
|
+
return true;
|
|
1508
|
+
}
|
|
1509
|
+
return item.toLowerCase().includes(draftValue.toLowerCase());
|
|
1510
|
+
});
|
|
1511
|
+
const filterPanel = (React.createElement(FilterPanel, { onClick: (event) => {
|
|
1512
|
+
event.stopPropagation();
|
|
1513
|
+
} },
|
|
1514
|
+
showSearch ? (React.createElement(FilterInput, { value: draftValue, placeholder: `筛选${column.name}`, onChange: (event) => {
|
|
1515
|
+
event.stopPropagation();
|
|
1516
|
+
setDraftValue(event.target.value);
|
|
1517
|
+
}, onClick: (event) => {
|
|
1518
|
+
event.stopPropagation();
|
|
1519
|
+
} })) : null,
|
|
1520
|
+
options.length > 0 ? (React.createElement(FilterOptionList, null, visibleOptions.map((item) => (React.createElement(FilterOptionButton, { key: item, type: "button", active: draftValue === item, onClick: (event) => {
|
|
1521
|
+
event.stopPropagation();
|
|
1522
|
+
setDraftValue(item);
|
|
1523
|
+
} }, item))))) : null,
|
|
1524
|
+
!showSearch && options.length === 0 ? React.createElement(FilterEmptyState, null, "\u5F53\u524D\u5217\u6CA1\u6709\u53EF\u9009\u7684\u9884\u7F6E\u7B5B\u9009\u9879\u3002") : null,
|
|
1525
|
+
showSearch && options.length > 0 && visibleOptions.length === 0 ? React.createElement(FilterEmptyState, null, "\u6CA1\u6709\u5339\u914D\u7684\u9884\u7F6E\u7B5B\u9009\u9879\u3002") : null,
|
|
1526
|
+
React.createElement(FilterActionRow, null,
|
|
1527
|
+
React.createElement(FilterActionButton, { type: "button", onClick: (event) => {
|
|
1528
|
+
event.stopPropagation();
|
|
1529
|
+
setDraftValue('');
|
|
1530
|
+
onChangeFilterValue('');
|
|
1531
|
+
setOpen(false);
|
|
1532
|
+
} }, "\u91CD\u7F6E"),
|
|
1533
|
+
React.createElement(FilterActionButton, { primary: true, type: "button", onClick: (event) => {
|
|
1534
|
+
event.stopPropagation();
|
|
1535
|
+
onChangeFilterValue(draftValue);
|
|
1536
|
+
setOpen(false);
|
|
1537
|
+
} }, "\u786E\u8BA4"))));
|
|
1538
|
+
return (React.createElement(FilterHeaderCell, { Popover: Popover, column: column, filterModeOptions: filterModeOptions, filterPanel: filterPanel, filterValue: filterValue, active: active, open: open, setOpen: setOpen, popoverProps: popoverProps }, children));
|
|
1539
|
+
}
|
|
1540
|
+
function DefaultFilterHeaderCell({ Popover, children, column, filterPanel, active, open, setOpen, popoverProps, }) {
|
|
1541
|
+
const justifyContent = column.align === 'right' ? 'flex-end' : column.align === 'center' ? 'center' : 'flex-start';
|
|
1542
|
+
return (React.createElement(FilterHeaderShell, { style: { justifyContent } },
|
|
1543
|
+
children,
|
|
1544
|
+
React.createElement(Popover, Object.assign({ visible: open, content: filterPanel }, popoverProps),
|
|
1545
|
+
React.createElement(FilterTrigger, { active: active, type: "button", "aria-label": `筛选${column.name}`, onClick: (event) => {
|
|
1546
|
+
event.stopPropagation();
|
|
1547
|
+
setOpen(!open);
|
|
1548
|
+
} },
|
|
1549
|
+
React.createElement(icons.Filter, null)))));
|
|
1550
|
+
}
|
|
1551
|
+
|
|
1230
1552
|
function multiSelect(opts = {}) {
|
|
1231
1553
|
return function multiSelectStep(pipeline) {
|
|
1232
1554
|
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l;
|
|
@@ -2345,6 +2667,7 @@ var index = /*#__PURE__*/Object.freeze({
|
|
|
2345
2667
|
columnRangeHover: columnRangeHover,
|
|
2346
2668
|
columnResize: columnResize,
|
|
2347
2669
|
fillRemainingWidth: fillRemainingWidth,
|
|
2670
|
+
filterMode: filterMode,
|
|
2348
2671
|
multiSelect: multiSelect,
|
|
2349
2672
|
rowDetail: rowDetail,
|
|
2350
2673
|
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-68f4025a.js');
|
|
6
6
|
var React = require('react');
|
|
7
7
|
var styled = require('styled-components');
|
|
8
8
|
var rxjs = require('rxjs');
|
|
@@ -1152,6 +1152,7 @@ const ResizeHandle = styled__default["default"].span `
|
|
|
1152
1152
|
right: -5px;
|
|
1153
1153
|
width: 10px;
|
|
1154
1154
|
cursor: col-resize;
|
|
1155
|
+
touch-action: none;
|
|
1155
1156
|
z-index: 1;
|
|
1156
1157
|
transition: background-color 200ms;
|
|
1157
1158
|
|
|
@@ -1165,6 +1166,20 @@ const ResizeHandle = styled__default["default"].span `
|
|
|
1165
1166
|
}};
|
|
1166
1167
|
}
|
|
1167
1168
|
`;
|
|
1169
|
+
/** 把手在卸载时结束仍在进行的拖拽,避免遗留 window 监听与 user-select 状态 */
|
|
1170
|
+
function ColumnResizeHandle(_a) {
|
|
1171
|
+
var { onStartResize } = _a, rest = pipeline.__rest(_a, ["onStartResize"]);
|
|
1172
|
+
const stopRef = React.useRef();
|
|
1173
|
+
React.useEffect(() => () => { var _a; return (_a = stopRef.current) === null || _a === void 0 ? void 0 : _a.call(stopRef, false); }, []);
|
|
1174
|
+
return (React__default["default"].createElement(ResizeHandle, Object.assign({}, rest, { onPointerDown: (e) => {
|
|
1175
|
+
if (e.button !== 0 || stopRef.current) {
|
|
1176
|
+
return;
|
|
1177
|
+
}
|
|
1178
|
+
stopRef.current = onStartResize(e, () => {
|
|
1179
|
+
stopRef.current = undefined;
|
|
1180
|
+
});
|
|
1181
|
+
} })));
|
|
1182
|
+
}
|
|
1168
1183
|
function columnResize(opts = {}) {
|
|
1169
1184
|
var _a, _b, _c, _d;
|
|
1170
1185
|
const stateKey = 'columnResize';
|
|
@@ -1192,26 +1207,24 @@ function columnResize(opts = {}) {
|
|
|
1192
1207
|
pipeline$1.setStateAtKey(stateKey, nextSizes);
|
|
1193
1208
|
(_a = opts.onChangeSizes) === null || _a === void 0 ? void 0 : _a.call(opts, nextSizes);
|
|
1194
1209
|
};
|
|
1195
|
-
const
|
|
1210
|
+
const computeSizes = (startIndex, endIndex, deltaSum) => {
|
|
1211
|
+
const nextSizes = sizes.slice();
|
|
1212
|
+
const sizeSum = sizes.slice(startIndex, endIndex).reduce((sum, s) => sum + s, 0);
|
|
1213
|
+
let deltaRemaining = deltaSum;
|
|
1214
|
+
for (let colIndex = startIndex; colIndex < endIndex - 1; colIndex++) {
|
|
1215
|
+
const startSize = sizes[colIndex];
|
|
1216
|
+
// 将每一列的宽度变化量 都四舍五入至 整数,不然看起来非常难受
|
|
1217
|
+
const colDelta = Math.round(deltaSum * (startSize / sizeSum));
|
|
1218
|
+
nextSizes[colIndex] = clamp(minSize, startSize + colDelta, maxSize);
|
|
1219
|
+
deltaRemaining -= colDelta;
|
|
1220
|
+
}
|
|
1221
|
+
// 因为前面的列宽都进行了四舍五入,最后一列的变化量需要使用 deltaRemaining 以避免误差
|
|
1222
|
+
nextSizes[endIndex - 1] = clamp(minSize, sizes[endIndex - 1] + deltaRemaining, maxSize);
|
|
1223
|
+
return nextSizes;
|
|
1224
|
+
};
|
|
1225
|
+
const startResize = (startIndex, endIndex, e, onFinish) => {
|
|
1196
1226
|
const startX = e.clientX;
|
|
1197
|
-
const target = e.
|
|
1198
|
-
const nextSizes$ = rxjs.fromEvent(window, 'mousemove').pipe(op__namespace.takeUntil(rxjs.fromEvent(window, 'mouseup')), op__namespace.map((e) => {
|
|
1199
|
-
const movingX = e.clientX;
|
|
1200
|
-
const nextSizes = sizes.slice();
|
|
1201
|
-
const deltaSum = movingX - startX;
|
|
1202
|
-
const sizeSum = sizes.slice(startIndex, endIndex).reduce((sum, s) => sum + s, 0);
|
|
1203
|
-
let deltaRemaining = deltaSum;
|
|
1204
|
-
for (let colIndex = startIndex; colIndex < endIndex - 1; colIndex++) {
|
|
1205
|
-
const startSize = sizes[colIndex];
|
|
1206
|
-
// 将每一列的宽度变化量 都四舍五入至 整数,不然看起来非常难受
|
|
1207
|
-
const colDelta = Math.round(deltaSum * (startSize / sizeSum));
|
|
1208
|
-
nextSizes[colIndex] = clamp(minSize, startSize + colDelta, maxSize);
|
|
1209
|
-
deltaRemaining -= colDelta;
|
|
1210
|
-
}
|
|
1211
|
-
// 因为前面的列宽都进行了四舍五入,最后一列的变化量需要使用 deltaRemaining 以避免误差
|
|
1212
|
-
nextSizes[endIndex - 1] = clamp(minSize, sizes[endIndex - 1] + deltaRemaining, maxSize);
|
|
1213
|
-
return nextSizes;
|
|
1214
|
-
}));
|
|
1227
|
+
const target = e.currentTarget;
|
|
1215
1228
|
let prevUserSelect = '';
|
|
1216
1229
|
let docElemStyle;
|
|
1217
1230
|
if (disableUserSelectWhenResizing) {
|
|
@@ -1222,23 +1235,52 @@ function columnResize(opts = {}) {
|
|
|
1222
1235
|
if (opts.handleActiveBackground) {
|
|
1223
1236
|
target.style.background = opts.handleActiveBackground;
|
|
1224
1237
|
}
|
|
1225
|
-
|
|
1226
|
-
|
|
1227
|
-
|
|
1228
|
-
|
|
1229
|
-
|
|
1230
|
-
|
|
1231
|
-
|
|
1232
|
-
|
|
1233
|
-
|
|
1234
|
-
}
|
|
1235
|
-
}
|
|
1238
|
+
// 拖动过程中每帧最多提交一次列宽,松手时补交最后一次
|
|
1239
|
+
let pending = null;
|
|
1240
|
+
let frame = 0;
|
|
1241
|
+
const flush = () => {
|
|
1242
|
+
frame = 0;
|
|
1243
|
+
if (pending != null) {
|
|
1244
|
+
const nextSizes = pending;
|
|
1245
|
+
pending = null;
|
|
1246
|
+
onChangeSizes(nextSizes);
|
|
1247
|
+
}
|
|
1248
|
+
};
|
|
1249
|
+
const onMove = (ev) => {
|
|
1250
|
+
pending = computeSizes(startIndex, endIndex, ev.clientX - startX);
|
|
1251
|
+
if (frame === 0) {
|
|
1252
|
+
frame = requestAnimationFrame(flush);
|
|
1253
|
+
}
|
|
1254
|
+
};
|
|
1255
|
+
const stop = (commit) => {
|
|
1256
|
+
window.removeEventListener('pointermove', onMove);
|
|
1257
|
+
window.removeEventListener('pointerup', onEnd);
|
|
1258
|
+
window.removeEventListener('pointercancel', onEnd);
|
|
1259
|
+
cancelAnimationFrame(frame);
|
|
1260
|
+
if (commit) {
|
|
1261
|
+
flush();
|
|
1262
|
+
}
|
|
1263
|
+
if (disableUserSelectWhenResizing) {
|
|
1264
|
+
docElemStyle.userSelect = prevUserSelect;
|
|
1265
|
+
}
|
|
1266
|
+
if (opts.handleActiveBackground) {
|
|
1267
|
+
target.style.background = '';
|
|
1268
|
+
}
|
|
1269
|
+
};
|
|
1270
|
+
const onEnd = () => {
|
|
1271
|
+
stop(true);
|
|
1272
|
+
onFinish();
|
|
1273
|
+
};
|
|
1274
|
+
window.addEventListener('pointermove', onMove);
|
|
1275
|
+
window.addEventListener('pointerup', onEnd);
|
|
1276
|
+
window.addEventListener('pointercancel', onEnd);
|
|
1277
|
+
return stop;
|
|
1236
1278
|
};
|
|
1237
1279
|
const resizedColumns = makeRecursiveMapper((col, { startIndex, endIndex }) => {
|
|
1238
1280
|
const prevTitle = pipeline.internals.safeRenderHeader(col);
|
|
1239
1281
|
return Object.assign(Object.assign({}, col), { width: sizes[startIndex], title: (React__default["default"].createElement(React__default["default"].Fragment, null,
|
|
1240
1282
|
prevTitle,
|
|
1241
|
-
React__default["default"].createElement(
|
|
1283
|
+
React__default["default"].createElement(ColumnResizeHandle, { className: "resize-handle", "var-handleBackground": opts.handleBackground, "var-handleHoverBackground": opts.handleHoverBackground, onStartResize: (e, onFinish) => startResize(startIndex, endIndex, e, onFinish) }))), headerCellProps: pipeline.mergeCellProps(col.headerCellProps, {
|
|
1242
1284
|
style: {
|
|
1243
1285
|
overflow: 'visible',
|
|
1244
1286
|
position: 'relative',
|
|
@@ -1255,6 +1297,286 @@ function fillRemainingWidth() {
|
|
|
1255
1297
|
};
|
|
1256
1298
|
}
|
|
1257
1299
|
|
|
1300
|
+
function normalizeFilterData(filterData) {
|
|
1301
|
+
const filterMap = new Map();
|
|
1302
|
+
for (const item of filterData !== null && filterData !== void 0 ? filterData : []) {
|
|
1303
|
+
if (item == null || typeof item.code !== 'string' || item.code.length === 0) {
|
|
1304
|
+
continue;
|
|
1305
|
+
}
|
|
1306
|
+
if (isBlankFilterValue$1(item.filterValue)) {
|
|
1307
|
+
filterMap.delete(item.code);
|
|
1308
|
+
continue;
|
|
1309
|
+
}
|
|
1310
|
+
filterMap.set(item.code, {
|
|
1311
|
+
code: item.code,
|
|
1312
|
+
filterValue: stringifyFilterValue$1(item.filterValue),
|
|
1313
|
+
});
|
|
1314
|
+
}
|
|
1315
|
+
return Array.from(filterMap.values());
|
|
1316
|
+
}
|
|
1317
|
+
function updateFilterData(filterData, code, nextFilterValue) {
|
|
1318
|
+
const nextFilterData = normalizeFilterData(filterData).filter((item) => item.code !== code);
|
|
1319
|
+
if (isBlankFilterValue$1(nextFilterValue)) {
|
|
1320
|
+
return nextFilterData;
|
|
1321
|
+
}
|
|
1322
|
+
nextFilterData.push({
|
|
1323
|
+
code,
|
|
1324
|
+
filterValue: stringifyFilterValue$1(nextFilterValue),
|
|
1325
|
+
});
|
|
1326
|
+
return nextFilterData;
|
|
1327
|
+
}
|
|
1328
|
+
function getFilterableColumns(columns) {
|
|
1329
|
+
return pipeline.collectNodes(columns, 'leaf-only').filter((column) => column.code != null && column.filterProps != null);
|
|
1330
|
+
}
|
|
1331
|
+
function filterDataSourceByFilterData(dataSource, columns, filterData) {
|
|
1332
|
+
const activeFilterData = normalizeFilterData(filterData);
|
|
1333
|
+
if (activeFilterData.length === 0) {
|
|
1334
|
+
return dataSource;
|
|
1335
|
+
}
|
|
1336
|
+
const filterColumnsMap = new Map(columns.map((column) => [column.code, column]));
|
|
1337
|
+
return dataSource.filter((record) => {
|
|
1338
|
+
return activeFilterData.every(({ code, filterValue }) => {
|
|
1339
|
+
const column = filterColumnsMap.get(code);
|
|
1340
|
+
if (column == null) {
|
|
1341
|
+
return true;
|
|
1342
|
+
}
|
|
1343
|
+
return matchFilterValue(column, stringifyFilterValue$1(filterValue), record);
|
|
1344
|
+
});
|
|
1345
|
+
});
|
|
1346
|
+
}
|
|
1347
|
+
function matchFilterValue(column, filterValue, record) {
|
|
1348
|
+
var _a;
|
|
1349
|
+
if (isBlankFilterValue$1(filterValue)) {
|
|
1350
|
+
return true;
|
|
1351
|
+
}
|
|
1352
|
+
const customFilter = (_a = column.filterProps) === null || _a === void 0 ? void 0 : _a.filterOptions;
|
|
1353
|
+
if (typeof customFilter === 'function') {
|
|
1354
|
+
return customFilter(filterValue, record);
|
|
1355
|
+
}
|
|
1356
|
+
const rawValue = record === null || record === void 0 ? void 0 : record[column.code];
|
|
1357
|
+
if (rawValue == null) {
|
|
1358
|
+
return false;
|
|
1359
|
+
}
|
|
1360
|
+
return String(rawValue).toLowerCase().includes(filterValue.toLowerCase());
|
|
1361
|
+
}
|
|
1362
|
+
function isBlankFilterValue$1(value) {
|
|
1363
|
+
return stringifyFilterValue$1(value).trim() === '';
|
|
1364
|
+
}
|
|
1365
|
+
function stringifyFilterValue$1(value) {
|
|
1366
|
+
if (value == null) {
|
|
1367
|
+
return '';
|
|
1368
|
+
}
|
|
1369
|
+
return typeof value === 'string' ? value : String(value);
|
|
1370
|
+
}
|
|
1371
|
+
|
|
1372
|
+
const FilterHeaderShell = styled__default["default"].div `
|
|
1373
|
+
display: flex;
|
|
1374
|
+
align-items: center;
|
|
1375
|
+
`;
|
|
1376
|
+
const FilterTrigger = styled__default["default"].button `
|
|
1377
|
+
display: inline-flex;
|
|
1378
|
+
align-items: center;
|
|
1379
|
+
justify-content: center;
|
|
1380
|
+
width: 20px;
|
|
1381
|
+
height: 20px;
|
|
1382
|
+
margin-left: 4px;
|
|
1383
|
+
padding: 0;
|
|
1384
|
+
border: none;
|
|
1385
|
+
background: transparent;
|
|
1386
|
+
color: ${(props) => (props.active ? '#23A3FF' : '#8c8c8c')};
|
|
1387
|
+
cursor: pointer;
|
|
1388
|
+
|
|
1389
|
+
&:hover {
|
|
1390
|
+
color: ${(props) => (props.active ? '#23A3FF' : '#595959')};
|
|
1391
|
+
}
|
|
1392
|
+
`;
|
|
1393
|
+
const FilterPanel = styled__default["default"].div `
|
|
1394
|
+
width: 160px;
|
|
1395
|
+
padding: 8px 8px 6px;
|
|
1396
|
+
box-sizing: border-box;
|
|
1397
|
+
color: #262626;
|
|
1398
|
+
font-size: 12px;
|
|
1399
|
+
line-height: 1.5;
|
|
1400
|
+
`;
|
|
1401
|
+
const FilterInput = styled__default["default"].input `
|
|
1402
|
+
width: 100%;
|
|
1403
|
+
height: 28px;
|
|
1404
|
+
padding: 0 8px;
|
|
1405
|
+
box-sizing: border-box;
|
|
1406
|
+
border: 1px solid #d9d9d9;
|
|
1407
|
+
border-radius: 5px;
|
|
1408
|
+
outline: none;
|
|
1409
|
+
font-size: 12px;
|
|
1410
|
+
line-height: 1.5;
|
|
1411
|
+
|
|
1412
|
+
&:focus {
|
|
1413
|
+
border-color: #23a3ff;
|
|
1414
|
+
}
|
|
1415
|
+
`;
|
|
1416
|
+
const FilterOptionList = styled__default["default"].div `
|
|
1417
|
+
max-height: 136px;
|
|
1418
|
+
margin-top: 6px;
|
|
1419
|
+
overflow: auto;
|
|
1420
|
+
`;
|
|
1421
|
+
const FilterOptionButton = styled__default["default"].button `
|
|
1422
|
+
width: 100%;
|
|
1423
|
+
min-height: 28px;
|
|
1424
|
+
margin-top: 4px;
|
|
1425
|
+
padding: 3px 8px;
|
|
1426
|
+
box-sizing: border-box;
|
|
1427
|
+
border: 1px solid ${(props) => (props.active ? '#23A3FF' : '#e8e8e8')};
|
|
1428
|
+
border-radius: 5px;
|
|
1429
|
+
background: ${(props) => (props.active ? 'rgba(35, 163, 255, 0.12)' : '#fff')};
|
|
1430
|
+
color: #262626;
|
|
1431
|
+
font-size: 12px;
|
|
1432
|
+
line-height: 1.5;
|
|
1433
|
+
text-align: left;
|
|
1434
|
+
cursor: pointer;
|
|
1435
|
+
`;
|
|
1436
|
+
const FilterActionRow = styled__default["default"].div `
|
|
1437
|
+
display: flex;
|
|
1438
|
+
justify-content: flex-end;
|
|
1439
|
+
gap: 4px;
|
|
1440
|
+
margin-top: 6px;
|
|
1441
|
+
`;
|
|
1442
|
+
const FilterActionButton = styled__default["default"].button `
|
|
1443
|
+
min-width: 44px;
|
|
1444
|
+
height: 26px;
|
|
1445
|
+
padding: 0 8px;
|
|
1446
|
+
box-sizing: border-box;
|
|
1447
|
+
border: 1px solid ${(props) => (props.primary ? '#23A3FF' : '#d9d9d9')};
|
|
1448
|
+
border-radius: 999px;
|
|
1449
|
+
background: ${(props) => (props.primary ? '#23A3FF' : '#fff')};
|
|
1450
|
+
color: ${(props) => (props.primary ? '#fff' : '#262626')};
|
|
1451
|
+
font-size: 12px;
|
|
1452
|
+
line-height: 1;
|
|
1453
|
+
cursor: pointer;
|
|
1454
|
+
`;
|
|
1455
|
+
const FilterEmptyState = styled__default["default"].div `
|
|
1456
|
+
margin-top: 8px;
|
|
1457
|
+
color: #8c8c8c;
|
|
1458
|
+
font-size: 12px;
|
|
1459
|
+
line-height: 1.5;
|
|
1460
|
+
`;
|
|
1461
|
+
const stateKey$1 = 'filterMode';
|
|
1462
|
+
function filterMode(opts = {}) {
|
|
1463
|
+
return function filterModeStep(pipeline) {
|
|
1464
|
+
var _a, _b, _c, _d;
|
|
1465
|
+
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 : [];
|
|
1466
|
+
const filterData = normalizeFilterData(inputFilterData);
|
|
1467
|
+
const Popover = pipeline.ctx.components.Popover;
|
|
1468
|
+
const columns = pipeline.getColumns();
|
|
1469
|
+
const filterableColumns = getFilterableColumns(columns);
|
|
1470
|
+
if (filterableColumns.length === 0) {
|
|
1471
|
+
return pipeline;
|
|
1472
|
+
}
|
|
1473
|
+
if (Popover == null) {
|
|
1474
|
+
throw new Error('使用 filterMode 之前需要设置 pipeline.ctx.components.Popover');
|
|
1475
|
+
}
|
|
1476
|
+
const onChangeFilterData = (nextFilterData) => {
|
|
1477
|
+
var _a;
|
|
1478
|
+
const normalized = normalizeFilterData(nextFilterData);
|
|
1479
|
+
(_a = opts.onChangeFilterData) === null || _a === void 0 ? void 0 : _a.call(opts, normalized);
|
|
1480
|
+
pipeline.setStateAtKey(stateKey$1, normalized);
|
|
1481
|
+
};
|
|
1482
|
+
if (!opts.keepDataSource) {
|
|
1483
|
+
pipeline.dataSource(filterDataSourceByFilterData(pipeline.getDataSource(), filterableColumns, filterData));
|
|
1484
|
+
}
|
|
1485
|
+
pipeline.columns(processColumns(columns, {
|
|
1486
|
+
filterData,
|
|
1487
|
+
onChangeFilterData,
|
|
1488
|
+
Popover,
|
|
1489
|
+
popoverProps: opts.popoverProps,
|
|
1490
|
+
keepDataSource: Boolean(opts.keepDataSource),
|
|
1491
|
+
FilterHeaderCell: (_d = opts.FilterHeaderCell) !== null && _d !== void 0 ? _d : DefaultFilterHeaderCell,
|
|
1492
|
+
}));
|
|
1493
|
+
return pipeline;
|
|
1494
|
+
};
|
|
1495
|
+
}
|
|
1496
|
+
function stringifyFilterValue(value) {
|
|
1497
|
+
if (value == null) {
|
|
1498
|
+
return '';
|
|
1499
|
+
}
|
|
1500
|
+
return typeof value === 'string' ? value : String(value);
|
|
1501
|
+
}
|
|
1502
|
+
function isBlankFilterValue(value) {
|
|
1503
|
+
return stringifyFilterValue(value).trim() === '';
|
|
1504
|
+
}
|
|
1505
|
+
function processColumns(columns, { filterData, onChangeFilterData, Popover, popoverProps, keepDataSource, FilterHeaderCell, }) {
|
|
1506
|
+
const filterMap = new Map(filterData.map((item) => [item.code, stringifyFilterValue(item.filterValue)]));
|
|
1507
|
+
return columns.map(dfs);
|
|
1508
|
+
function dfs(col) {
|
|
1509
|
+
var _a;
|
|
1510
|
+
const result = Object.assign({}, col);
|
|
1511
|
+
if (pipeline.isLeafNode(col) && col.code && col.filterProps) {
|
|
1512
|
+
const filterValue = (_a = filterMap.get(col.code)) !== null && _a !== void 0 ? _a : '';
|
|
1513
|
+
result.title = (React__default["default"].createElement(ManagedFilterHeader, { Popover: Popover, FilterHeaderCell: FilterHeaderCell, column: col, filterModeOptions: { keepDataSource }, filterValue: filterValue, popoverProps: popoverProps, onChangeFilterValue: (nextFilterValue) => {
|
|
1514
|
+
onChangeFilterData(updateFilterData(filterData, col.code, nextFilterValue));
|
|
1515
|
+
} }, pipeline.internals.safeRenderHeader(col)));
|
|
1516
|
+
}
|
|
1517
|
+
if (!pipeline.isLeafNode(col)) {
|
|
1518
|
+
result.children = col.children.map(dfs);
|
|
1519
|
+
}
|
|
1520
|
+
return result;
|
|
1521
|
+
}
|
|
1522
|
+
}
|
|
1523
|
+
function ManagedFilterHeader({ Popover, FilterHeaderCell, column, filterModeOptions, filterValue, popoverProps, onChangeFilterValue, children, }) {
|
|
1524
|
+
var _a, _b, _c;
|
|
1525
|
+
const [open, setOpen] = React.useState(false);
|
|
1526
|
+
const [draftValue, setDraftValue] = React.useState(filterValue);
|
|
1527
|
+
React.useEffect(() => {
|
|
1528
|
+
setDraftValue(filterValue);
|
|
1529
|
+
}, [filterValue]);
|
|
1530
|
+
const showSearch = ((_a = column.filterProps) === null || _a === void 0 ? void 0 : _a.showSearch) !== false;
|
|
1531
|
+
const options = (_c = (_b = column.filterProps) === null || _b === void 0 ? void 0 : _b.dataSource) !== null && _c !== void 0 ? _c : [];
|
|
1532
|
+
const active = !isBlankFilterValue(filterValue);
|
|
1533
|
+
const visibleOptions = options.filter((item) => {
|
|
1534
|
+
if (!showSearch || isBlankFilterValue(draftValue)) {
|
|
1535
|
+
return true;
|
|
1536
|
+
}
|
|
1537
|
+
return item.toLowerCase().includes(draftValue.toLowerCase());
|
|
1538
|
+
});
|
|
1539
|
+
const filterPanel = (React__default["default"].createElement(FilterPanel, { onClick: (event) => {
|
|
1540
|
+
event.stopPropagation();
|
|
1541
|
+
} },
|
|
1542
|
+
showSearch ? (React__default["default"].createElement(FilterInput, { value: draftValue, placeholder: `筛选${column.name}`, onChange: (event) => {
|
|
1543
|
+
event.stopPropagation();
|
|
1544
|
+
setDraftValue(event.target.value);
|
|
1545
|
+
}, onClick: (event) => {
|
|
1546
|
+
event.stopPropagation();
|
|
1547
|
+
} })) : null,
|
|
1548
|
+
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) => {
|
|
1549
|
+
event.stopPropagation();
|
|
1550
|
+
setDraftValue(item);
|
|
1551
|
+
} }, item))))) : null,
|
|
1552
|
+
!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,
|
|
1553
|
+
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,
|
|
1554
|
+
React__default["default"].createElement(FilterActionRow, null,
|
|
1555
|
+
React__default["default"].createElement(FilterActionButton, { type: "button", onClick: (event) => {
|
|
1556
|
+
event.stopPropagation();
|
|
1557
|
+
setDraftValue('');
|
|
1558
|
+
onChangeFilterValue('');
|
|
1559
|
+
setOpen(false);
|
|
1560
|
+
} }, "\u91CD\u7F6E"),
|
|
1561
|
+
React__default["default"].createElement(FilterActionButton, { primary: true, type: "button", onClick: (event) => {
|
|
1562
|
+
event.stopPropagation();
|
|
1563
|
+
onChangeFilterValue(draftValue);
|
|
1564
|
+
setOpen(false);
|
|
1565
|
+
} }, "\u786E\u8BA4"))));
|
|
1566
|
+
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));
|
|
1567
|
+
}
|
|
1568
|
+
function DefaultFilterHeaderCell({ Popover, children, column, filterPanel, active, open, setOpen, popoverProps, }) {
|
|
1569
|
+
const justifyContent = column.align === 'right' ? 'flex-end' : column.align === 'center' ? 'center' : 'flex-start';
|
|
1570
|
+
return (React__default["default"].createElement(FilterHeaderShell, { style: { justifyContent } },
|
|
1571
|
+
children,
|
|
1572
|
+
React__default["default"].createElement(Popover, Object.assign({ visible: open, content: filterPanel }, popoverProps),
|
|
1573
|
+
React__default["default"].createElement(FilterTrigger, { active: active, type: "button", "aria-label": `筛选${column.name}`, onClick: (event) => {
|
|
1574
|
+
event.stopPropagation();
|
|
1575
|
+
setOpen(!open);
|
|
1576
|
+
} },
|
|
1577
|
+
React__default["default"].createElement(pipeline.icons.Filter, null)))));
|
|
1578
|
+
}
|
|
1579
|
+
|
|
1258
1580
|
function multiSelect(opts = {}) {
|
|
1259
1581
|
return function multiSelectStep(pipeline$1) {
|
|
1260
1582
|
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l;
|
|
@@ -2373,6 +2695,7 @@ var index = /*#__PURE__*/Object.freeze({
|
|
|
2373
2695
|
columnRangeHover: columnRangeHover,
|
|
2374
2696
|
columnResize: columnResize,
|
|
2375
2697
|
fillRemainingWidth: fillRemainingWidth,
|
|
2698
|
+
filterMode: filterMode,
|
|
2376
2699
|
multiSelect: multiSelect,
|
|
2377
2700
|
rowDetail: rowDetail,
|
|
2378
2701
|
rowPopover: rowPopover,
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@guozhi5658/srp-table",
|
|
3
|
-
"version": "1.1.
|
|
3
|
+
"version": "1.1.5",
|
|
4
4
|
"description": "High-performance React table component library",
|
|
5
5
|
"sideEffects": false,
|
|
6
6
|
"module": "dist/srp-table.esm.js",
|
|
@@ -46,6 +46,7 @@
|
|
|
46
46
|
"devDependencies": {
|
|
47
47
|
"@babel/core": "^7.12.3",
|
|
48
48
|
"@babel/preset-env": "^7.12.1",
|
|
49
|
+
"@babel/preset-react": "^7.29.7",
|
|
49
50
|
"@babel/preset-typescript": "^7.12.1",
|
|
50
51
|
"@rollup/plugin-node-resolve": "^11.2.0",
|
|
51
52
|
"@rollup/plugin-typescript": "^12.3.0",
|
package/readme.md
CHANGED
|
@@ -11,30 +11,53 @@
|
|
|
11
11
|
[node-url]: http://nodejs.org/download/
|
|
12
12
|
[download-image]: https://img.shields.io/npm/dm/%40guozhi5658%2Fsrp-table.svg?style=flat-square
|
|
13
13
|
[download-url]: https://www.npmjs.com/package/@guozhi5658/srp-table
|
|
14
|
-
[license-image]: https://img.shields.io/npm/l/%40guozhi5658%2Fsrp-table.svg
|
|
14
|
+
[license-image]: https://img.shields.io/npm/l/%40guozhi5658%2Fsrp-table.svg?style=flat-square
|
|
15
15
|
|
|
16
|
-
|
|
16
|
+
**`@guozhi5658/srp-table`** is a high-performance React table library for data-heavy UIs. It is **forked from** [alibaba/ali-react-table](https://github.com/alibaba/ali-react-table) and keeps the MIT model; retain upstream attribution when redistributing or modifying the codebase.
|
|
17
17
|
|
|
18
|
-
|
|
19
|
-
- composable enhancement through `pipeline` and feature plugins
|
|
18
|
+
## Architecture
|
|
20
19
|
|
|
21
|
-
|
|
20
|
+
| Layer | Role |
|
|
21
|
+
|-------|------|
|
|
22
|
+
| **`BaseTable`** | Rendering core: horizontal/vertical virtualization, left/right locked columns, sticky header/footer, row height management. |
|
|
23
|
+
| **`TablePipeline` + `features`** | Composable enhancements to `columns`, `dataSource`, row props, selection, tree shape, sorting, filters, etc., before props reach `<BaseTable />`. |
|
|
22
24
|
|
|
23
|
-
|
|
25
|
+
Integration styles:
|
|
24
26
|
|
|
25
|
-
|
|
27
|
+
- Pass props directly to **`BaseTable`**
|
|
28
|
+
- Chain **`.use(features.xxx(...))`** on a pipeline, then **`<BaseTable {...pipeline.getProps()} />`**
|
|
26
29
|
|
|
27
|
-
|
|
30
|
+
A legacy **`transforms`** API still exists for compatibility; **new capabilities belong in `pipeline/features`**, not in `transforms`.
|
|
31
|
+
|
|
32
|
+
Pivot / cross-table scenarios use the subpath package:
|
|
33
|
+
|
|
34
|
+
```bash
|
|
35
|
+
npm install @guozhi5658/srp-table
|
|
36
|
+
# import from '@guozhi5658/srp-table/pivot'
|
|
37
|
+
```
|
|
38
|
+
|
|
39
|
+
## Pipeline features (overview)
|
|
40
|
+
|
|
41
|
+
Sixteen features live under `features` and are composed with `pipeline.use(features.xxx(...))`. Several require UI components via **`ctx.components`** (e.g. Checkbox, Radio, Popover).
|
|
42
|
+
|
|
43
|
+
| Group | Features |
|
|
44
|
+
|-------|----------|
|
|
45
|
+
| Selection | `multiSelect`, `singleSelect`, `treeSelect` |
|
|
46
|
+
| Tree | `treeMode`, `buildTree` |
|
|
47
|
+
| Expand / group | `rowDetail`, `rowGrouping` |
|
|
48
|
+
| Column UX | `columnHover`, `columnRangeHover`, `columnResize`, `sort`, `tips`, `filterMode` |
|
|
49
|
+
| Layout | `fillRemainingWidth`, `autoRowSpan` |
|
|
50
|
+
| Row | `rowPopover` |
|
|
51
|
+
|
|
52
|
+
For descriptions, `ctx.components` dependencies, and engineering constraints, see **[AGENTS.md](./AGENTS.md)** (Chinese, detailed). **[CLAUDE.md](./CLAUDE.md)** is a shorter English checklist for agents working in this repo.
|
|
28
53
|
|
|
29
54
|
## Highlights
|
|
30
55
|
|
|
31
|
-
-
|
|
32
|
-
-
|
|
33
|
-
-
|
|
34
|
-
-
|
|
35
|
-
-
|
|
36
|
-
- pluggable renderers and component slots for customization
|
|
37
|
-
- pivot table entry for cross-table and cross-tree-table scenarios
|
|
56
|
+
- Virtualized rows and columns for large datasets
|
|
57
|
+
- Sticky header/footer, left/right locked columns
|
|
58
|
+
- Tree rows, row detail, grouping, sorting, resizing, filters, and other pipeline-driven behavior
|
|
59
|
+
- Customizable slots: `BaseTableProps.components`, column render hooks, pipeline `ctx.components`
|
|
60
|
+
- **`@guozhi5658/srp-table/pivot`**: cross-table and cross-tree-table built on the same `BaseTable` core
|
|
38
61
|
|
|
39
62
|
## Installation
|
|
40
63
|
|
|
@@ -42,7 +65,9 @@ The fork keeps the original MIT licensing model. Please retain the upstream attr
|
|
|
42
65
|
npm install @guozhi5658/srp-table
|
|
43
66
|
```
|
|
44
67
|
|
|
45
|
-
|
|
68
|
+
Peer dependency: **React** `^16.8.0 || ^17.0.1 || ^18.0.0`.
|
|
69
|
+
|
|
70
|
+
## Quick start
|
|
46
71
|
|
|
47
72
|
### BaseTable
|
|
48
73
|
|
|
@@ -93,60 +118,27 @@ export function PipelineDemo({ columns, dataSource }) {
|
|
|
93
118
|
}
|
|
94
119
|
```
|
|
95
120
|
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
Use `features.fillRemainingWidth()` when you want fixed-width columns to keep their original widths as the container grows. Instead of stretching existing columns proportionally, the table appends a blank column on the right to absorb the remaining space.
|
|
99
|
-
|
|
100
|
-
```tsx
|
|
101
|
-
import { BaseTable, features, useTablePipeline } from '@guozhi5658/srp-table'
|
|
102
|
-
|
|
103
|
-
export function FixedWidthDemo({ columns, dataSource }) {
|
|
104
|
-
const pipeline = useTablePipeline()
|
|
105
|
-
|
|
106
|
-
const tableProps = pipeline
|
|
107
|
-
.input({ columns, dataSource })
|
|
108
|
-
.primaryKey('id')
|
|
109
|
-
.use(features.fillRemainingWidth())
|
|
110
|
-
.getProps()
|
|
111
|
-
|
|
112
|
-
return (
|
|
113
|
-
<BaseTable
|
|
114
|
-
{...tableProps}
|
|
115
|
-
defaultColumnWidth={140}
|
|
116
|
-
isStickyHeader
|
|
117
|
-
/>
|
|
118
|
-
)
|
|
119
|
-
}
|
|
120
|
-
```
|
|
121
|
-
|
|
122
|
-
This feature is designed for the pipeline path and works with `defaultColumnWidth`, locked columns, and the table's built-in virtualization logic.
|
|
121
|
+
You can combine multiple `.use(...)` calls; **order matters** when features append or rewrite columns. See **AGENTS.md** for full-row span and lock-column caveats.
|
|
123
122
|
|
|
124
123
|
## Playground
|
|
125
124
|
|
|
126
|
-
Run the local playground to develop and validate new features against the built-in flat, tree, and row-detail mock datasets:
|
|
127
|
-
|
|
128
125
|
```bash
|
|
129
126
|
npm install
|
|
130
|
-
npm run playground
|
|
127
|
+
npm run playground # dev server (e.g. port 3100)
|
|
131
128
|
```
|
|
132
129
|
|
|
133
|
-
The playground is
|
|
130
|
+
The playground is a Vite app for flat, tree, row-detail, grouped-header, and merged-cell scenarios—useful for layout, sticky behavior, and virtualization checks. For library development, this repo pins **Node 22.x** via **Volta** (see `package.json`).
|
|
134
131
|
|
|
135
|
-
## Build
|
|
132
|
+
## Build & compatibility
|
|
136
133
|
|
|
137
134
|
```bash
|
|
138
|
-
npm run build
|
|
135
|
+
npm run build # Rollup → dist/
|
|
136
|
+
npm run playground:build
|
|
137
|
+
npm run verify:react-compat # React 16 / 17 / 18 smoke script
|
|
139
138
|
```
|
|
140
139
|
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
- `dist/srp-table.js`
|
|
144
|
-
- `dist/srp-table.esm.js`
|
|
145
|
-
- `dist/srp-table.d.ts`
|
|
146
|
-
- `dist/srp-table-pivot.js`
|
|
147
|
-
- `dist/srp-table-pivot.esm.js`
|
|
148
|
-
- `dist/srp-table-pivot.d.ts`
|
|
140
|
+
Artifacts under `dist/` include `srp-table` and `srp-table-pivot` entry bundles and `.d.ts` files (see **Build** list in **AGENTS.md** if you need exact filenames).
|
|
149
141
|
|
|
150
142
|
## License
|
|
151
143
|
|
|
152
|
-
MIT. This fork is based on [alibaba/ali-react-table](https://github.com/alibaba/ali-react-table)
|
|
144
|
+
MIT. This fork is based on [alibaba/ali-react-table](https://github.com/alibaba/ali-react-table); preserve upstream attribution.
|