@hzab/edit-table 0.1.3-alpha.0 → 0.1.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +1 -0
- package/package.json +1 -1
- package/src/Template/GetBaseTemplate.tsx +6 -1
- package/src/Template/NumberCellTemplate/index.tsx +11 -19
- package/src/Template/TextCellTemplate/index.tsx +6 -20
- package/src/common/WidthWrapHoc.tsx +2 -1
- package/src/index.less +25 -0
- package/src/index.tsx +19 -11
package/CHANGELOG.md
CHANGED
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { useMemo } from "react";
|
|
2
2
|
import { getVal } from "@hzab/list-render/src/common/utils";
|
|
3
3
|
export const GetBaseTemplate = (props) => {
|
|
4
|
-
const { pattern, cell, componentProps, Com } = props;
|
|
4
|
+
const { pattern, cell, componentProps, Com, cellRender } = props;
|
|
5
5
|
|
|
6
6
|
const echoValue = useMemo(() => {
|
|
7
7
|
if (!cell?.getField) {
|
|
@@ -12,6 +12,11 @@ export const GetBaseTemplate = (props) => {
|
|
|
12
12
|
{ [cell?.getField && cell?.getField().name]: cell.text },
|
|
13
13
|
);
|
|
14
14
|
}, [cell]);
|
|
15
|
+
if (cellRender && cellRender(props)) {
|
|
16
|
+
const Slot = cellRender;
|
|
17
|
+
return <Slot {...props}></Slot>;
|
|
18
|
+
}
|
|
19
|
+
|
|
15
20
|
return (
|
|
16
21
|
<div className="base-hoc">
|
|
17
22
|
{pattern == "readPretty" ? (
|
|
@@ -1,24 +1,16 @@
|
|
|
1
1
|
import { Input } from "antd";
|
|
2
|
-
import "
|
|
2
|
+
import { GetBaseTemplate } from "../GetBaseTemplate";
|
|
3
|
+
import "./index.less";
|
|
3
4
|
const NumberCellTemplate = (props: any) => {
|
|
4
|
-
const { pattern, cell, componentProps } = props;
|
|
5
5
|
return (
|
|
6
|
-
<
|
|
7
|
-
{
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
if (input) {
|
|
15
|
-
input.focus();
|
|
16
|
-
}
|
|
17
|
-
}}
|
|
18
|
-
{...componentProps}
|
|
19
|
-
/>
|
|
20
|
-
)}
|
|
21
|
-
</div>
|
|
6
|
+
<GetBaseTemplate
|
|
7
|
+
{...props}
|
|
8
|
+
componentProps={{
|
|
9
|
+
...props?.componentProps,
|
|
10
|
+
type: "number",
|
|
11
|
+
}}
|
|
12
|
+
Com={Input}
|
|
13
|
+
></GetBaseTemplate>
|
|
22
14
|
);
|
|
23
15
|
};
|
|
24
|
-
export default NumberCellTemplate
|
|
16
|
+
export default NumberCellTemplate;
|
|
@@ -1,22 +1,8 @@
|
|
|
1
|
-
import "
|
|
1
|
+
import { Input } from "antd";
|
|
2
|
+
import { GetBaseTemplate } from "../GetBaseTemplate";
|
|
3
|
+
import "./index.less";
|
|
4
|
+
|
|
2
5
|
const TextCellTemplate = (props: any) => {
|
|
3
|
-
|
|
4
|
-
return (
|
|
5
|
-
<div className="text-cell-template">
|
|
6
|
-
{pattern == "readPretty" ? (
|
|
7
|
-
<div>{cell?.text}</div>
|
|
8
|
-
) : (
|
|
9
|
-
<input
|
|
10
|
-
className="rg-input"
|
|
11
|
-
ref={(input) => {
|
|
12
|
-
if (input) {
|
|
13
|
-
input.focus();
|
|
14
|
-
}
|
|
15
|
-
}}
|
|
16
|
-
{...componentProps}
|
|
17
|
-
/>
|
|
18
|
-
)}
|
|
19
|
-
</div>
|
|
20
|
-
);
|
|
6
|
+
return <GetBaseTemplate {...props} Com={Input}></GetBaseTemplate>;
|
|
21
7
|
};
|
|
22
|
-
export default TextCellTemplate
|
|
8
|
+
export default TextCellTemplate;
|
|
@@ -33,7 +33,7 @@ interface DIProps {
|
|
|
33
33
|
isInEditMode?: boolean;
|
|
34
34
|
}
|
|
35
35
|
|
|
36
|
-
export const WidthWrapHoc = (WrapComponent: any) => {
|
|
36
|
+
export const WidthWrapHoc = (WrapComponent: any, props = {}) => {
|
|
37
37
|
class createBaseCellTemplate implements CellTemplate<BaseCell> {
|
|
38
38
|
getCompatibleCell(uncertainCell: Uncertain<BaseCell>): Compatible<BaseCell> {
|
|
39
39
|
let values: any;
|
|
@@ -196,6 +196,7 @@ export const WidthWrapHoc = (WrapComponent: any) => {
|
|
|
196
196
|
}}
|
|
197
197
|
>
|
|
198
198
|
<WrapComponent
|
|
199
|
+
{...props}
|
|
199
200
|
onPointerDown={(e) => e.stopPropagation()}
|
|
200
201
|
componentProps={{
|
|
201
202
|
style: { width: "100%", display: "flex", alignItems: "center" },
|
package/src/index.less
CHANGED
|
@@ -4,6 +4,14 @@
|
|
|
4
4
|
max-height: 100vh;
|
|
5
5
|
padding-bottom: 16px;
|
|
6
6
|
|
|
7
|
+
.ant-input-affix-wrapper-focused,
|
|
8
|
+
.ant-input-affix-wrapper:focus {
|
|
9
|
+
box-shadow: none;
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
.rg-input {
|
|
13
|
+
border: none;
|
|
14
|
+
}
|
|
7
15
|
|
|
8
16
|
|
|
9
17
|
|
|
@@ -21,6 +29,10 @@
|
|
|
21
29
|
z-index: 2;
|
|
22
30
|
}
|
|
23
31
|
|
|
32
|
+
// .rg-header-cell {
|
|
33
|
+
// z-index: 99;
|
|
34
|
+
// }
|
|
35
|
+
|
|
24
36
|
.rg-partial-area {
|
|
25
37
|
z-index: 3;
|
|
26
38
|
|
|
@@ -76,4 +88,17 @@
|
|
|
76
88
|
.rg-pane-left,
|
|
77
89
|
.rg-pane-right {
|
|
78
90
|
z-index: 10 !important;
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
.custom-highlights-row {
|
|
94
|
+
background: #E9F8FF;
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
.rg-pane-top {
|
|
98
|
+
z-index: 9 !important;
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
.shadow-top-left-corner,
|
|
102
|
+
.shadow-top-right-corner {
|
|
103
|
+
z-index: 11 !important;
|
|
79
104
|
}
|
package/src/index.tsx
CHANGED
|
@@ -65,6 +65,8 @@ function CellEditTable(props: CellEditTableProps, ref: any) {
|
|
|
65
65
|
const [expandKeys, setExpandKeys] = useState<any>([]);
|
|
66
66
|
const [headerCustomTemplate, setHeaderCustomTemplate] = useState<any>([]);
|
|
67
67
|
const [highlights, setHighlights] = useState([]);
|
|
68
|
+
const highlightsRowIdRef = useRef();
|
|
69
|
+
|
|
68
70
|
const gridRef = useRef<any>();
|
|
69
71
|
const currentCell = useRef<any>();
|
|
70
72
|
|
|
@@ -88,6 +90,14 @@ function CellEditTable(props: CellEditTableProps, ref: any) {
|
|
|
88
90
|
setNewDataSource(dataSource);
|
|
89
91
|
}, [dataSource]);
|
|
90
92
|
|
|
93
|
+
/** 判断当前选中行是否还存在 */
|
|
94
|
+
useEffect(() => {
|
|
95
|
+
const validRowIds = rows.map((r) => r.rowId);
|
|
96
|
+
if (!validRowIds?.includes(highlightsRowIdRef.current)) {
|
|
97
|
+
setHighlights([]);
|
|
98
|
+
}
|
|
99
|
+
}, [rows]);
|
|
100
|
+
|
|
91
101
|
/**将数组转为对象 */
|
|
92
102
|
const handleArrayToObj = (item) => {
|
|
93
103
|
const record = item?.cells?.[0]?.record;
|
|
@@ -203,10 +213,7 @@ function CellEditTable(props: CellEditTableProps, ref: any) {
|
|
|
203
213
|
text: String(cellItem || ""),
|
|
204
214
|
value: cellItem,
|
|
205
215
|
selectedValue: cellItem || "",
|
|
206
|
-
style:
|
|
207
|
-
columnsItem?.type == "rowSelection"
|
|
208
|
-
? { display: "flex", justifyContent: "center" }
|
|
209
|
-
: { color: cellItem == 0 ? "#CACDD7" : "" },
|
|
216
|
+
style: columnsItem?.type == "rowSelection" ? { display: "flex", justifyContent: "center" } : {},
|
|
210
217
|
...((onRow && onRow(item, index, ind)) || {}),
|
|
211
218
|
...((columnsItem?.onCell && columnsItem?.onCell(item, index, ind)) || {}),
|
|
212
219
|
...(columnsItem?.cellProps || {}),
|
|
@@ -291,8 +298,8 @@ function CellEditTable(props: CellEditTableProps, ref: any) {
|
|
|
291
298
|
const mergeTemplate: any = { ...(antdComponents || {}), ...(customComponents || {}), ...childAntdComponent };
|
|
292
299
|
const newMergeTemplate: any = {};
|
|
293
300
|
for (let key in mergeTemplate) {
|
|
294
|
-
const NewCom = (
|
|
295
|
-
return <GetBaseTemplate {...props} Com={mergeTemplate[key]} />;
|
|
301
|
+
const NewCom = (newComProps) => {
|
|
302
|
+
return <GetBaseTemplate {...newComProps} {...props} Com={mergeTemplate[key]} />;
|
|
296
303
|
};
|
|
297
304
|
newMergeTemplate[key] = WidthWrapHoc(NewCom);
|
|
298
305
|
}
|
|
@@ -397,6 +404,7 @@ function CellEditTable(props: CellEditTableProps, ref: any) {
|
|
|
397
404
|
className: "custom-highlights-row",
|
|
398
405
|
borderColor: "transparent",
|
|
399
406
|
}));
|
|
407
|
+
highlightsRowIdRef.current = cell?.rowId;
|
|
400
408
|
setHighlights(list);
|
|
401
409
|
};
|
|
402
410
|
|
|
@@ -417,15 +425,15 @@ function CellEditTable(props: CellEditTableProps, ref: any) {
|
|
|
417
425
|
onFocusLocationChanging={(cell: any) => {
|
|
418
426
|
const datatypeId = cell?.columnId + cell?.rowId;
|
|
419
427
|
(window as any).gridEditId = datatypeId;
|
|
420
|
-
if (["_$actions", "rowSelection", "ExpandListTemplate"]?.includes(cell?.columnId)) {
|
|
421
|
-
return false;
|
|
422
|
-
}
|
|
423
428
|
if (typeof cell?.rowId == "string" && cell?.rowId?.indexOf("header-") > -1) {
|
|
424
429
|
return false;
|
|
425
430
|
}
|
|
426
431
|
if (reactGridProps?.isRowHighlights && cell?.columnId) {
|
|
427
432
|
onHightsRow(cell, rows);
|
|
428
433
|
}
|
|
434
|
+
if (["_$actions", "rowSelection", "ExpandListTemplate"]?.includes(cell?.columnId)) {
|
|
435
|
+
return false;
|
|
436
|
+
}
|
|
429
437
|
if (reactGridProps?.onFocusLocationChanging) {
|
|
430
438
|
return reactGridProps?.onFocusLocationChanging(cell, rows);
|
|
431
439
|
}
|
|
@@ -439,8 +447,8 @@ function CellEditTable(props: CellEditTableProps, ref: any) {
|
|
|
439
447
|
...headerCustomTemplate,
|
|
440
448
|
_$actions: WidthWrapHoc(ActionDom),
|
|
441
449
|
rowSelection: WidthWrapHoc(CheckBoxDom),
|
|
442
|
-
Input: WidthWrapHoc(TextTemplate),
|
|
443
|
-
Number: WidthWrapHoc(NumberTemplate),
|
|
450
|
+
// Input: WidthWrapHoc(TextTemplate,props),
|
|
451
|
+
Number: WidthWrapHoc(NumberTemplate, props),
|
|
444
452
|
}}
|
|
445
453
|
/>
|
|
446
454
|
{dataSource?.length <= 0 && (
|