szld-libs 0.2.44 → 0.2.45
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/szld-components.es.js +1841 -1834
- package/dist/szld-components.umd.js +25 -25
- package/es/components/SearchTable/index.d.ts +1 -0
- package/es/components/SearchTable/index.js +18 -6
- package/es/index.js +28 -9
- package/lib/components/SearchTable/index.d.ts +1 -0
- package/lib/components/SearchTable/index.js +17 -5
- package/lib/index.js +28 -9
- package/package.json +1 -1
|
@@ -4,6 +4,7 @@ import { CreateFormProps } from '../CreateForm';
|
|
|
4
4
|
export interface TableColumnProps<T> extends ColumnType<T> {
|
|
5
5
|
hidden?: boolean;
|
|
6
6
|
width?: number | string;
|
|
7
|
+
minWidth?: number | string;
|
|
7
8
|
}
|
|
8
9
|
export interface MTableProps<T> extends Omit<TableProps<T>, 'columns'> {
|
|
9
10
|
columns?: TableColumnProps<T>[];
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { jsxs, Fragment, jsx } from "react/jsx-runtime";
|
|
2
2
|
import { Table } from "antd";
|
|
3
3
|
import classNames from "classnames";
|
|
4
|
-
import { useState, useEffect } from "react";
|
|
4
|
+
import { useState, useEffect, useMemo } from "react";
|
|
5
5
|
import { Resizable } from "react-resizable";
|
|
6
6
|
import { getLocalStorage } from "../../utils";
|
|
7
7
|
import CreateForm from "../CreateForm";
|
|
@@ -22,12 +22,12 @@ function SearchTable(props) {
|
|
|
22
22
|
const { tableProps = {}, searchProps } = props;
|
|
23
23
|
const {
|
|
24
24
|
minColumnWidth = 200,
|
|
25
|
-
resizeable =
|
|
25
|
+
resizeable = false,
|
|
26
26
|
tableId,
|
|
27
27
|
storageKey = "szld_table_cell_width",
|
|
28
28
|
...rest
|
|
29
29
|
} = tableProps;
|
|
30
|
-
const [columns, setColumns] = useState([]);
|
|
30
|
+
const [columns, setColumns] = useState(tableProps.columns || []);
|
|
31
31
|
const getWidth = (v) => {
|
|
32
32
|
var _a, _b;
|
|
33
33
|
let width = v.width || minColumnWidth;
|
|
@@ -42,7 +42,7 @@ function SearchTable(props) {
|
|
|
42
42
|
};
|
|
43
43
|
useEffect(() => {
|
|
44
44
|
const list = tableProps.columns || [];
|
|
45
|
-
if (list.length === 0) {
|
|
45
|
+
if (list.length === 0 || !resizeable) {
|
|
46
46
|
return;
|
|
47
47
|
}
|
|
48
48
|
const result = list == null ? void 0 : list.filter((v) => !v.hidden).map((v) => {
|
|
@@ -60,10 +60,11 @@ function SearchTable(props) {
|
|
|
60
60
|
return v;
|
|
61
61
|
});
|
|
62
62
|
if (result.length > 0) {
|
|
63
|
+
result[result.length - 1].minWidth = result[result.length - 1].width;
|
|
63
64
|
result[result.length - 1].width = void 0;
|
|
64
65
|
}
|
|
65
66
|
setColumns(result);
|
|
66
|
-
}, [tableProps.columns, tableId, minColumnWidth]);
|
|
67
|
+
}, [tableProps.columns, tableId, minColumnWidth, resizeable]);
|
|
67
68
|
const handleResize = (column, size) => {
|
|
68
69
|
setColumns((prevColumns) => {
|
|
69
70
|
const list = prevColumns == null ? void 0 : prevColumns.map((v) => {
|
|
@@ -95,13 +96,24 @@ function SearchTable(props) {
|
|
|
95
96
|
},
|
|
96
97
|
...rest == null ? void 0 : rest.components
|
|
97
98
|
};
|
|
99
|
+
const scollX = useMemo(() => {
|
|
100
|
+
var _a;
|
|
101
|
+
const getWidth2 = (v) => {
|
|
102
|
+
let width = v.width || v.minWidth;
|
|
103
|
+
if (!width || typeof width === "string") {
|
|
104
|
+
width = minColumnWidth;
|
|
105
|
+
}
|
|
106
|
+
return width;
|
|
107
|
+
};
|
|
108
|
+
return (_a = columns == null ? void 0 : columns.map((v) => getWidth2(v))) == null ? void 0 : _a.reduce((a, b) => a + b, 0);
|
|
109
|
+
}, [columns, minColumnWidth]);
|
|
98
110
|
return /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
99
111
|
searchProps && /* @__PURE__ */ jsx(CreateForm, { hiddenTitle: true, ...searchProps, items: searchProps.items }),
|
|
100
112
|
/* @__PURE__ */ jsx(
|
|
101
113
|
Table,
|
|
102
114
|
{
|
|
103
115
|
scroll: {
|
|
104
|
-
x:
|
|
116
|
+
x: scollX
|
|
105
117
|
},
|
|
106
118
|
...rest,
|
|
107
119
|
components,
|
package/es/index.js
CHANGED
|
@@ -27,10 +27,16 @@ const Demo = () => {
|
|
|
27
27
|
title: "c"
|
|
28
28
|
}
|
|
29
29
|
];
|
|
30
|
-
const [list, setList] = useState(
|
|
30
|
+
const [list, setList] = useState(
|
|
31
|
+
Array(10).fill(0).map((v, i) => ({ id: i }))
|
|
32
|
+
);
|
|
31
33
|
const [current, setCurrent] = useState(1);
|
|
32
34
|
const data = [{ id: 1 }, { id: 12 }, { id: 21 }];
|
|
33
|
-
const { selectedKeys, selectedRows, setSelectedKeys } = useRowSelection({
|
|
35
|
+
const { selectedKeys, selectedRows, setSelectedKeys } = useRowSelection({
|
|
36
|
+
dataSource: list,
|
|
37
|
+
rowKey: "id",
|
|
38
|
+
defaultRows: data
|
|
39
|
+
});
|
|
34
40
|
useEffect(() => {
|
|
35
41
|
setSelectedKeys([1, 12, 21]);
|
|
36
42
|
}, []);
|
|
@@ -54,18 +60,31 @@ const Demo = () => {
|
|
|
54
60
|
{
|
|
55
61
|
dataIndex: "id",
|
|
56
62
|
title: "ID"
|
|
63
|
+
},
|
|
64
|
+
{
|
|
65
|
+
dataIndex: "a",
|
|
66
|
+
title: "a",
|
|
67
|
+
width: 200
|
|
68
|
+
},
|
|
69
|
+
{
|
|
70
|
+
dataIndex: "a2",
|
|
71
|
+
title: "a",
|
|
72
|
+
width: 200
|
|
73
|
+
},
|
|
74
|
+
{
|
|
75
|
+
dataIndex: "a3",
|
|
76
|
+
title: "a",
|
|
77
|
+
width: 200
|
|
78
|
+
},
|
|
79
|
+
{
|
|
80
|
+
dataIndex: "a4",
|
|
81
|
+
title: "a",
|
|
82
|
+
width: 400
|
|
57
83
|
}
|
|
58
84
|
],
|
|
59
85
|
dataSource: list,
|
|
60
86
|
resizeable: true,
|
|
61
87
|
rowKey: "id",
|
|
62
|
-
rowSelection: {
|
|
63
|
-
selectedRowKeys: selectedKeys,
|
|
64
|
-
preserveSelectedRowKeys: true,
|
|
65
|
-
onChange(keys) {
|
|
66
|
-
setSelectedKeys(keys);
|
|
67
|
-
}
|
|
68
|
-
},
|
|
69
88
|
pagination: {
|
|
70
89
|
total: 25,
|
|
71
90
|
current,
|
|
@@ -4,6 +4,7 @@ import { CreateFormProps } from '../CreateForm';
|
|
|
4
4
|
export interface TableColumnProps<T> extends ColumnType<T> {
|
|
5
5
|
hidden?: boolean;
|
|
6
6
|
width?: number | string;
|
|
7
|
+
minWidth?: number | string;
|
|
7
8
|
}
|
|
8
9
|
export interface MTableProps<T> extends Omit<TableProps<T>, 'columns'> {
|
|
9
10
|
columns?: TableColumnProps<T>[];
|
|
@@ -23,12 +23,12 @@ function SearchTable(props) {
|
|
|
23
23
|
const { tableProps = {}, searchProps } = props;
|
|
24
24
|
const {
|
|
25
25
|
minColumnWidth = 200,
|
|
26
|
-
resizeable =
|
|
26
|
+
resizeable = false,
|
|
27
27
|
tableId,
|
|
28
28
|
storageKey = "szld_table_cell_width",
|
|
29
29
|
...rest
|
|
30
30
|
} = tableProps;
|
|
31
|
-
const [columns, setColumns] = react.useState([]);
|
|
31
|
+
const [columns, setColumns] = react.useState(tableProps.columns || []);
|
|
32
32
|
const getWidth = (v) => {
|
|
33
33
|
var _a, _b;
|
|
34
34
|
let width = v.width || minColumnWidth;
|
|
@@ -43,7 +43,7 @@ function SearchTable(props) {
|
|
|
43
43
|
};
|
|
44
44
|
react.useEffect(() => {
|
|
45
45
|
const list = tableProps.columns || [];
|
|
46
|
-
if (list.length === 0) {
|
|
46
|
+
if (list.length === 0 || !resizeable) {
|
|
47
47
|
return;
|
|
48
48
|
}
|
|
49
49
|
const result = list == null ? void 0 : list.filter((v) => !v.hidden).map((v) => {
|
|
@@ -61,10 +61,11 @@ function SearchTable(props) {
|
|
|
61
61
|
return v;
|
|
62
62
|
});
|
|
63
63
|
if (result.length > 0) {
|
|
64
|
+
result[result.length - 1].minWidth = result[result.length - 1].width;
|
|
64
65
|
result[result.length - 1].width = void 0;
|
|
65
66
|
}
|
|
66
67
|
setColumns(result);
|
|
67
|
-
}, [tableProps.columns, tableId, minColumnWidth]);
|
|
68
|
+
}, [tableProps.columns, tableId, minColumnWidth, resizeable]);
|
|
68
69
|
const handleResize = (column, size) => {
|
|
69
70
|
setColumns((prevColumns) => {
|
|
70
71
|
const list = prevColumns == null ? void 0 : prevColumns.map((v) => {
|
|
@@ -96,13 +97,24 @@ function SearchTable(props) {
|
|
|
96
97
|
},
|
|
97
98
|
...rest == null ? void 0 : rest.components
|
|
98
99
|
};
|
|
100
|
+
const scollX = react.useMemo(() => {
|
|
101
|
+
var _a;
|
|
102
|
+
const getWidth2 = (v) => {
|
|
103
|
+
let width = v.width || v.minWidth;
|
|
104
|
+
if (!width || typeof width === "string") {
|
|
105
|
+
width = minColumnWidth;
|
|
106
|
+
}
|
|
107
|
+
return width;
|
|
108
|
+
};
|
|
109
|
+
return (_a = columns == null ? void 0 : columns.map((v) => getWidth2(v))) == null ? void 0 : _a.reduce((a, b) => a + b, 0);
|
|
110
|
+
}, [columns, minColumnWidth]);
|
|
99
111
|
return /* @__PURE__ */ jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [
|
|
100
112
|
searchProps && /* @__PURE__ */ jsxRuntime.jsx(CreateForm, { hiddenTitle: true, ...searchProps, items: searchProps.items }),
|
|
101
113
|
/* @__PURE__ */ jsxRuntime.jsx(
|
|
102
114
|
antd.Table,
|
|
103
115
|
{
|
|
104
116
|
scroll: {
|
|
105
|
-
x:
|
|
117
|
+
x: scollX
|
|
106
118
|
},
|
|
107
119
|
...rest,
|
|
108
120
|
components,
|
package/lib/index.js
CHANGED
|
@@ -28,10 +28,16 @@ const Demo = () => {
|
|
|
28
28
|
title: "c"
|
|
29
29
|
}
|
|
30
30
|
];
|
|
31
|
-
const [list, setList] = react.useState(
|
|
31
|
+
const [list, setList] = react.useState(
|
|
32
|
+
Array(10).fill(0).map((v, i) => ({ id: i }))
|
|
33
|
+
);
|
|
32
34
|
const [current, setCurrent] = react.useState(1);
|
|
33
35
|
const data = [{ id: 1 }, { id: 12 }, { id: 21 }];
|
|
34
|
-
const { selectedKeys, selectedRows, setSelectedKeys } = main.useRowSelection({
|
|
36
|
+
const { selectedKeys, selectedRows, setSelectedKeys } = main.useRowSelection({
|
|
37
|
+
dataSource: list,
|
|
38
|
+
rowKey: "id",
|
|
39
|
+
defaultRows: data
|
|
40
|
+
});
|
|
35
41
|
react.useEffect(() => {
|
|
36
42
|
setSelectedKeys([1, 12, 21]);
|
|
37
43
|
}, []);
|
|
@@ -55,18 +61,31 @@ const Demo = () => {
|
|
|
55
61
|
{
|
|
56
62
|
dataIndex: "id",
|
|
57
63
|
title: "ID"
|
|
64
|
+
},
|
|
65
|
+
{
|
|
66
|
+
dataIndex: "a",
|
|
67
|
+
title: "a",
|
|
68
|
+
width: 200
|
|
69
|
+
},
|
|
70
|
+
{
|
|
71
|
+
dataIndex: "a2",
|
|
72
|
+
title: "a",
|
|
73
|
+
width: 200
|
|
74
|
+
},
|
|
75
|
+
{
|
|
76
|
+
dataIndex: "a3",
|
|
77
|
+
title: "a",
|
|
78
|
+
width: 200
|
|
79
|
+
},
|
|
80
|
+
{
|
|
81
|
+
dataIndex: "a4",
|
|
82
|
+
title: "a",
|
|
83
|
+
width: 400
|
|
58
84
|
}
|
|
59
85
|
],
|
|
60
86
|
dataSource: list,
|
|
61
87
|
resizeable: true,
|
|
62
88
|
rowKey: "id",
|
|
63
|
-
rowSelection: {
|
|
64
|
-
selectedRowKeys: selectedKeys,
|
|
65
|
-
preserveSelectedRowKeys: true,
|
|
66
|
-
onChange(keys) {
|
|
67
|
-
setSelectedKeys(keys);
|
|
68
|
-
}
|
|
69
|
-
},
|
|
70
89
|
pagination: {
|
|
71
90
|
total: 25,
|
|
72
91
|
current,
|