es-grid-template 1.7.23 → 1.7.25
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/es/index.d.ts +1 -0
- package/es/index.js +3 -1
- package/es/table-component/ColumnsChoose.d.ts +13 -0
- package/es/table-component/ColumnsChoose.js +206 -0
- package/es/table-component/ContextMenu.d.ts +20 -0
- package/es/table-component/ContextMenu.js +75 -0
- package/es/table-component/InternalTable.d.ts +9 -0
- package/es/table-component/InternalTable.js +308 -0
- package/es/table-component/TableContainer.d.ts +31 -0
- package/es/table-component/TableContainer.js +249 -0
- package/es/table-component/TableContainerEdit.d.ts +31 -0
- package/es/table-component/TableContainerEdit.js +1301 -0
- package/es/table-component/body/EditableCell.d.ts +16 -0
- package/es/table-component/body/EditableCell.js +1039 -0
- package/es/table-component/body/TableBody.d.ts +19 -0
- package/es/table-component/body/TableBody.js +64 -0
- package/es/table-component/body/TableBodyCell.d.ts +12 -0
- package/es/table-component/body/TableBodyCell.js +149 -0
- package/es/table-component/body/TableBodyCellEdit.d.ts +16 -0
- package/es/table-component/body/TableBodyCellEdit.js +931 -0
- package/es/table-component/body/TableBodyRow.d.ts +21 -0
- package/es/table-component/body/TableBodyRow.js +151 -0
- package/es/table-component/components/ControlCheckbox.d.ts +13 -0
- package/es/table-component/components/ControlCheckbox.js +84 -0
- package/es/table-component/components/EditForm/EditForm.d.ts +27 -0
- package/es/table-component/components/EditForm/EditForm.js +395 -0
- package/es/table-component/components/EditForm/index.d.ts +1 -0
- package/es/table-component/components/EditForm/index.js +1 -0
- package/es/table-component/components/InputControl/InputControl.d.ts +27 -0
- package/es/table-component/components/InputControl/InputControl.js +121 -0
- package/es/table-component/components/InputControl/index.d.ts +1 -0
- package/es/table-component/components/InputControl/index.js +1 -0
- package/es/table-component/components/async-select/index.d.ts +11 -0
- package/es/table-component/components/async-select/index.js +41 -0
- package/es/table-component/components/async-table-select/index.d.ts +11 -0
- package/es/table-component/components/async-table-select/index.js +44 -0
- package/es/table-component/components/checkbox-control/index.d.ts +13 -0
- package/es/table-component/components/checkbox-control/index.js +40 -0
- package/es/table-component/components/checkbox-filter/CheckboxFilter.d.ts +18 -0
- package/es/table-component/components/checkbox-filter/CheckboxFilter.js +240 -0
- package/es/table-component/components/checkbox-filter/FilterSearch.d.ts +12 -0
- package/es/table-component/components/checkbox-filter/FilterSearch.js +36 -0
- package/es/table-component/components/command/Command.d.ts +10 -0
- package/es/table-component/components/command/Command.js +33 -0
- package/es/table-component/components/number/index.d.ts +10 -0
- package/es/table-component/components/number/index.js +42 -0
- package/es/table-component/components/number-range/index.d.ts +11 -0
- package/es/table-component/components/number-range/index.js +66 -0
- package/es/table-component/features/operator.d.ts +24 -0
- package/es/table-component/features/operator.js +62 -0
- package/es/table-component/footer/TableFooter.d.ts +13 -0
- package/es/table-component/footer/TableFooter.js +33 -0
- package/es/table-component/footer/TableFooterCell.d.ts +10 -0
- package/es/table-component/footer/TableFooterCell.js +66 -0
- package/es/table-component/footer/TableFooterRow.d.ts +14 -0
- package/es/table-component/footer/TableFooterRow.js +73 -0
- package/es/table-component/header/TableHead.d.ts +14 -0
- package/es/table-component/header/TableHead.js +60 -0
- package/es/table-component/header/TableHeadCell.d.ts +14 -0
- package/es/table-component/header/TableHeadCell.js +343 -0
- package/es/table-component/header/TableHeadRow.d.ts +16 -0
- package/es/table-component/header/TableHeadRow.js +76 -0
- package/es/table-component/header/renderFilter.d.ts +20 -0
- package/es/table-component/header/renderFilter.js +281 -0
- package/es/table-component/hook/constant.d.ts +73 -0
- package/es/table-component/hook/constant.js +240 -0
- package/es/table-component/hook/useColumns.d.ts +9 -0
- package/es/table-component/hook/useColumns.js +169 -0
- package/es/table-component/hook/useFilterOperator.d.ts +7 -0
- package/es/table-component/hook/useFilterOperator.js +33 -0
- package/es/table-component/hook/utils.d.ts +133 -0
- package/es/table-component/hook/utils.js +1870 -0
- package/es/table-component/index.d.ts +5 -0
- package/es/table-component/index.js +2 -0
- package/es/table-component/style.scss +1129 -0
- package/es/table-component/table/Grid.d.ts +24 -0
- package/es/table-component/table/Grid.js +234 -0
- package/es/table-component/type.d.ts +513 -0
- package/es/table-component/type.js +1 -0
- package/es/table-component/useContext.d.ts +74 -0
- package/es/table-component/useContext.js +15 -0
- package/lib/index.d.ts +1 -0
- package/lib/index.js +8 -1
- package/lib/table-component/ColumnsChoose.d.ts +13 -0
- package/lib/table-component/ColumnsChoose.js +216 -0
- package/lib/table-component/ContextMenu.d.ts +20 -0
- package/lib/table-component/ContextMenu.js +85 -0
- package/lib/table-component/InternalTable.d.ts +9 -0
- package/lib/table-component/InternalTable.js +313 -0
- package/lib/table-component/TableContainer.d.ts +31 -0
- package/lib/table-component/TableContainer.js +257 -0
- package/lib/table-component/TableContainerEdit.d.ts +31 -0
- package/lib/table-component/TableContainerEdit.js +1310 -0
- package/lib/table-component/body/EditableCell.d.ts +16 -0
- package/lib/table-component/body/EditableCell.js +1041 -0
- package/lib/table-component/body/TableBody.d.ts +19 -0
- package/lib/table-component/body/TableBody.js +72 -0
- package/lib/table-component/body/TableBodyCell.d.ts +12 -0
- package/lib/table-component/body/TableBodyCell.js +158 -0
- package/lib/table-component/body/TableBodyCellEdit.d.ts +16 -0
- package/lib/table-component/body/TableBodyCellEdit.js +938 -0
- package/lib/table-component/body/TableBodyRow.d.ts +21 -0
- package/lib/table-component/body/TableBodyRow.js +158 -0
- package/lib/table-component/components/ControlCheckbox.d.ts +13 -0
- package/lib/table-component/components/ControlCheckbox.js +92 -0
- package/lib/table-component/components/EditForm/EditForm.d.ts +27 -0
- package/lib/table-component/components/EditForm/EditForm.js +406 -0
- package/lib/table-component/components/EditForm/index.d.ts +1 -0
- package/lib/table-component/components/EditForm/index.js +16 -0
- package/lib/table-component/components/InputControl/InputControl.d.ts +27 -0
- package/lib/table-component/components/InputControl/InputControl.js +131 -0
- package/lib/table-component/components/InputControl/index.d.ts +1 -0
- package/lib/table-component/components/InputControl/index.js +16 -0
- package/lib/table-component/components/async-select/index.d.ts +11 -0
- package/lib/table-component/components/async-select/index.js +49 -0
- package/lib/table-component/components/async-table-select/index.d.ts +11 -0
- package/lib/table-component/components/async-table-select/index.js +53 -0
- package/lib/table-component/components/checkbox-control/index.d.ts +13 -0
- package/lib/table-component/components/checkbox-control/index.js +48 -0
- package/lib/table-component/components/checkbox-filter/CheckboxFilter.d.ts +18 -0
- package/lib/table-component/components/checkbox-filter/CheckboxFilter.js +249 -0
- package/lib/table-component/components/checkbox-filter/FilterSearch.d.ts +12 -0
- package/lib/table-component/components/checkbox-filter/FilterSearch.js +44 -0
- package/lib/table-component/components/command/Command.d.ts +10 -0
- package/lib/table-component/components/command/Command.js +42 -0
- package/lib/table-component/components/number/index.d.ts +10 -0
- package/lib/table-component/components/number/index.js +50 -0
- package/lib/table-component/components/number-range/index.d.ts +11 -0
- package/lib/table-component/components/number-range/index.js +74 -0
- package/lib/table-component/features/operator.d.ts +24 -0
- package/lib/table-component/features/operator.js +67 -0
- package/lib/table-component/footer/TableFooter.d.ts +13 -0
- package/lib/table-component/footer/TableFooter.js +42 -0
- package/lib/table-component/footer/TableFooterCell.d.ts +10 -0
- package/lib/table-component/footer/TableFooterCell.js +76 -0
- package/lib/table-component/footer/TableFooterRow.d.ts +14 -0
- package/lib/table-component/footer/TableFooterRow.js +81 -0
- package/lib/table-component/header/TableHead.d.ts +14 -0
- package/lib/table-component/header/TableHead.js +69 -0
- package/lib/table-component/header/TableHeadCell.d.ts +14 -0
- package/lib/table-component/header/TableHeadCell.js +352 -0
- package/lib/table-component/header/TableHeadRow.d.ts +16 -0
- package/lib/table-component/header/TableHeadRow.js +84 -0
- package/lib/table-component/header/renderFilter.d.ts +20 -0
- package/lib/table-component/header/renderFilter.js +291 -0
- package/lib/table-component/hook/constant.d.ts +73 -0
- package/lib/table-component/hook/constant.js +247 -0
- package/lib/table-component/hook/useColumns.d.ts +9 -0
- package/lib/table-component/hook/useColumns.js +180 -0
- package/lib/table-component/hook/useFilterOperator.d.ts +7 -0
- package/lib/table-component/hook/useFilterOperator.js +40 -0
- package/lib/table-component/hook/utils.d.ts +133 -0
- package/lib/table-component/hook/utils.js +1969 -0
- package/lib/table-component/index.d.ts +5 -0
- package/lib/table-component/index.js +9 -0
- package/lib/table-component/style.scss +1129 -0
- package/lib/table-component/table/Grid.d.ts +24 -0
- package/lib/table-component/table/Grid.js +236 -0
- package/lib/table-component/type.d.ts +513 -0
- package/lib/table-component/type.js +5 -0
- package/lib/table-component/useContext.d.ts +74 -0
- package/lib/table-component/useContext.js +21 -0
- package/package.json +4 -2
package/es/index.d.ts
CHANGED
|
@@ -16,3 +16,4 @@ export { default as Splitter } from './splitter';
|
|
|
16
16
|
export type { SplitterProps } from './splitter';
|
|
17
17
|
export { default as Collapse } from './collapse';
|
|
18
18
|
export type { CollapsePanelProps, CollapseProps } from './collapse';
|
|
19
|
+
export { default as TableComponent } from './table-component';
|
package/es/index.js
CHANGED
|
@@ -6,4 +6,6 @@ export { default as Select } from "./select";
|
|
|
6
6
|
export { default as DateRangePicker } from "./date-range-picker";
|
|
7
7
|
export { default as DatePicker } from "./datepicker";
|
|
8
8
|
export { default as Splitter } from "./splitter";
|
|
9
|
-
export { default as Collapse } from "./collapse";
|
|
9
|
+
export { default as Collapse } from "./collapse";
|
|
10
|
+
export { default as TableComponent } from "./table-component";
|
|
11
|
+
// export type { ColumnsTable, TableProps, ColumnTable, CommandItem, ToolbarItem, ContextMenuItem } from './table-component';
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import React from "react";
|
|
2
|
+
import type { ColumnsTable, ColumnTable } from "./type";
|
|
3
|
+
import type { ColumnDef } from "@tanstack/react-table";
|
|
4
|
+
export type IColumnsChoose<RecordType> = {
|
|
5
|
+
columns: ColumnDef<RecordType>[];
|
|
6
|
+
originColumns: ColumnTable[];
|
|
7
|
+
columnsGroup?: string[];
|
|
8
|
+
triggerChangeColumns?: (columns: ColumnsTable<RecordType>, keys: string[], type: string) => void;
|
|
9
|
+
t?: any;
|
|
10
|
+
triggerChangeKeys?: any;
|
|
11
|
+
columnHidden: any;
|
|
12
|
+
};
|
|
13
|
+
export declare const ColumnsChoose: <RecordType extends object>(props: IColumnsChoose<RecordType>) => React.JSX.Element;
|
|
@@ -0,0 +1,206 @@
|
|
|
1
|
+
import useMergedState from "rc-util/es/hooks/useMergedState";
|
|
2
|
+
import React, { Fragment, useState } from "react";
|
|
3
|
+
import styled from "styled-components";
|
|
4
|
+
import { Button, Input, Popover, Tooltip } from "antd";
|
|
5
|
+
import { SettingOutlined } from "@ant-design/icons";
|
|
6
|
+
import Tree from "rc-master-ui/es/tree";
|
|
7
|
+
import SearchOutlined from "@ant-design/icons/SearchOutlined";
|
|
8
|
+
import { convertColumnsToTreeData, getVisibleColumnKeys1, updateColumns1 } from "./hook/utils";
|
|
9
|
+
const BoxAction = styled.div.withConfig({
|
|
10
|
+
displayName: "BoxAction",
|
|
11
|
+
componentId: "es-grid-template__sc-jfujqh-0"
|
|
12
|
+
})(["border-top:1px solid #c4c4c4;padding-top:.75rem;display:flex;justify-content:end;gap:10px;.btn-action{background:none !important;border:none !important;&.btn-action-submit{color:#df4318;&:disabled{background-color:#f0f0f0 !important;}&:hover{color:#df4318 !important;}}&:hover{background-color:#f0f0f0 !important;}}"]);
|
|
13
|
+
export const ColumnsChoose = props => {
|
|
14
|
+
const {
|
|
15
|
+
columns: propsColumns,
|
|
16
|
+
originColumns,
|
|
17
|
+
columnHidden,
|
|
18
|
+
triggerChangeColumns,
|
|
19
|
+
// triggerChangeKeys,
|
|
20
|
+
t,
|
|
21
|
+
columnsGroup
|
|
22
|
+
} = props;
|
|
23
|
+
const treeColumns = React.useMemo(() => {
|
|
24
|
+
return convertColumnsToTreeData(propsColumns, columnsGroup);
|
|
25
|
+
}, [propsColumns, columnsGroup]);
|
|
26
|
+
const defaultSelectedKeys = React.useMemo(() => {
|
|
27
|
+
const defaultColumns = originColumns.filter(it => it.field && it.showInColumnChoose !== false && !columnsGroup?.includes(it.field));
|
|
28
|
+
const aa = Object.keys(columnHidden);
|
|
29
|
+
return getVisibleColumnKeys1(defaultColumns).filter(it => !aa.includes(it));
|
|
30
|
+
}, [columnHidden, columnsGroup, originColumns]);
|
|
31
|
+
const [mergedSelectedKeys, setMergedSelectedKeys] = useMergedState(defaultSelectedKeys && defaultSelectedKeys.length ? defaultSelectedKeys : undefined, {
|
|
32
|
+
value: undefined
|
|
33
|
+
});
|
|
34
|
+
const [clicked, setClicked] = useState(false);
|
|
35
|
+
const [autoExpandParent, setAutoExpandParent] = useState(true);
|
|
36
|
+
|
|
37
|
+
// const treeData = useMemo(() => {
|
|
38
|
+
// const loop = (data: TreeDataNode[]): TreeDataNode[] =>
|
|
39
|
+
// data.map((item) => {
|
|
40
|
+
// const strTitle = item.title as string;
|
|
41
|
+
// const index = strTitle.indexOf(searchValue);
|
|
42
|
+
// const beforeStr = strTitle.substring(0, index);
|
|
43
|
+
// const afterStr = strTitle.slice(index + searchValue.length);
|
|
44
|
+
// const title =
|
|
45
|
+
// index > -1 ? (
|
|
46
|
+
// <span key={item.key}>
|
|
47
|
+
// {beforeStr}
|
|
48
|
+
// <span className="site-tree-search-value">{searchValue}</span>
|
|
49
|
+
// {afterStr}
|
|
50
|
+
// </span>
|
|
51
|
+
// ) : (
|
|
52
|
+
// <span key={item.key}>{strTitle}</span>
|
|
53
|
+
// );
|
|
54
|
+
// if (item.children) {
|
|
55
|
+
// return { title, key: item.key, children: loop(item.children) };
|
|
56
|
+
// }
|
|
57
|
+
//
|
|
58
|
+
// return {
|
|
59
|
+
// title,
|
|
60
|
+
// key: item.key,
|
|
61
|
+
// };
|
|
62
|
+
// });
|
|
63
|
+
//
|
|
64
|
+
// // return loop(defaultData);
|
|
65
|
+
// return loop(columns as any);
|
|
66
|
+
// }, [searchValue, columns]);
|
|
67
|
+
|
|
68
|
+
const hide = () => {
|
|
69
|
+
setClicked(false);
|
|
70
|
+
};
|
|
71
|
+
const handleClickChange = open => {
|
|
72
|
+
setClicked(open);
|
|
73
|
+
};
|
|
74
|
+
const onExpand = () => {
|
|
75
|
+
// setExpandedKeys(newExpandedKeys)
|
|
76
|
+
setAutoExpandParent(false);
|
|
77
|
+
};
|
|
78
|
+
|
|
79
|
+
// const getParentKey = (key: React.Key, tree: TreeDataNode[]): React.Key => {
|
|
80
|
+
// let parentKey: React.Key
|
|
81
|
+
// for (let i = 0; i < tree.length; i++) {
|
|
82
|
+
// const node = tree[i]
|
|
83
|
+
// if (node.children) {
|
|
84
|
+
// if (node.children.some((item) => item.key === key)) {
|
|
85
|
+
// parentKey = node.key
|
|
86
|
+
// } else if (getParentKey(key, node.children)) {
|
|
87
|
+
// parentKey = getParentKey(key, node.children)
|
|
88
|
+
// }
|
|
89
|
+
// }
|
|
90
|
+
// }
|
|
91
|
+
// return parentKey!
|
|
92
|
+
// }
|
|
93
|
+
|
|
94
|
+
// const onChange = (e: React.ChangeEvent<HTMLInputElement>) => {
|
|
95
|
+
const onChange = () => {
|
|
96
|
+
// const { value } = e.target
|
|
97
|
+
// const newExpandedKeys = dataList
|
|
98
|
+
// .map((item) => {
|
|
99
|
+
// if (item.title.indexOf(value) > -1) {
|
|
100
|
+
// return getParentKey(item.key, defaultData)
|
|
101
|
+
// }
|
|
102
|
+
// return null
|
|
103
|
+
// })
|
|
104
|
+
// .filter((item, i, self): item is React.Key => !!(item && self.indexOf(item) === i))
|
|
105
|
+
// setExpandedKeys(newExpandedKeys)
|
|
106
|
+
|
|
107
|
+
// setSearchValue(value)
|
|
108
|
+
setAutoExpandParent(true);
|
|
109
|
+
};
|
|
110
|
+
const onCheck = keys => {
|
|
111
|
+
// setSelectedKeys(keys)
|
|
112
|
+
// setIsManualUpdate(true)
|
|
113
|
+
setMergedSelectedKeys(keys);
|
|
114
|
+
};
|
|
115
|
+
const handleAccept = () => {
|
|
116
|
+
const rs1 = updateColumns1(originColumns, mergedSelectedKeys ?? []);
|
|
117
|
+
triggerChangeColumns?.(rs1, mergedSelectedKeys ?? [], 'columnChoose');
|
|
118
|
+
hide();
|
|
119
|
+
};
|
|
120
|
+
const handleCancel = () => {
|
|
121
|
+
setMergedSelectedKeys(defaultSelectedKeys);
|
|
122
|
+
hide();
|
|
123
|
+
};
|
|
124
|
+
return /*#__PURE__*/React.createElement(Fragment, null, /*#__PURE__*/React.createElement(Popover, {
|
|
125
|
+
placement: 'bottomLeft',
|
|
126
|
+
content: /*#__PURE__*/React.createElement("div", {
|
|
127
|
+
style: {
|
|
128
|
+
minWidth: 250,
|
|
129
|
+
maxWidth: 320
|
|
130
|
+
}
|
|
131
|
+
}, /*#__PURE__*/React.createElement(Input, {
|
|
132
|
+
style: {
|
|
133
|
+
marginBottom: 8
|
|
134
|
+
},
|
|
135
|
+
placeholder: t ? t("Search") : 'Search',
|
|
136
|
+
prefix: /*#__PURE__*/React.createElement(SearchOutlined, null),
|
|
137
|
+
onChange: onChange
|
|
138
|
+
}), /*#__PURE__*/React.createElement(Tree, {
|
|
139
|
+
onExpand: onExpand
|
|
140
|
+
// expandedKeys={expandedKeys}
|
|
141
|
+
,
|
|
142
|
+
autoExpandParent: autoExpandParent
|
|
143
|
+
// treeData={treeData}
|
|
144
|
+
// treeData={columns.filter((it) => !columnsGroup?.includes(it.field as string))}
|
|
145
|
+
,
|
|
146
|
+
treeData: treeColumns,
|
|
147
|
+
defaultExpandAll: true,
|
|
148
|
+
checkable: true
|
|
149
|
+
// onSelect={(keys, info) => {
|
|
150
|
+
// const key = info.node.key
|
|
151
|
+
//
|
|
152
|
+
// const find = findItemByKey(columns, 'key', key)
|
|
153
|
+
//
|
|
154
|
+
// // const tmpColumn
|
|
155
|
+
//
|
|
156
|
+
// // if (selectedKeys.includes(key as string)) {
|
|
157
|
+
// // const rssss = findKeyPath(columns, key as string)
|
|
158
|
+
// // const rs = selectedKeys.filter(item => !rssss.includes(item));
|
|
159
|
+
// //
|
|
160
|
+
// // setSelectedKeys(rs)
|
|
161
|
+
// // } else {
|
|
162
|
+
//
|
|
163
|
+
// // const rs = [...selectedKeys, keys[0]]
|
|
164
|
+
//
|
|
165
|
+
// // setSelectedKeys(keys)
|
|
166
|
+
// // }
|
|
167
|
+
// }}
|
|
168
|
+
,
|
|
169
|
+
onCheck: keys => onCheck(keys),
|
|
170
|
+
multiple: true
|
|
171
|
+
// checkedKeys={selectedKeys}
|
|
172
|
+
,
|
|
173
|
+
checkedKeys: mergedSelectedKeys || defaultSelectedKeys
|
|
174
|
+
|
|
175
|
+
// defaultCheckedKeys={selectedKeys}
|
|
176
|
+
,
|
|
177
|
+
defaultCheckedKeys: defaultSelectedKeys,
|
|
178
|
+
selectedKeys: []
|
|
179
|
+
|
|
180
|
+
// height={window.innerHeight - 200}
|
|
181
|
+
,
|
|
182
|
+
height: window.innerHeight / 2 > 450 ? 450 : window.innerHeight / 2 - 110
|
|
183
|
+
// style={{height: 300}}
|
|
184
|
+
}), /*#__PURE__*/React.createElement(BoxAction, {
|
|
185
|
+
className: 'px-1'
|
|
186
|
+
}, /*#__PURE__*/React.createElement(Button
|
|
187
|
+
// className={classnames('btn-action btn-action-submit', {
|
|
188
|
+
// // disable: !columns.find((item) => item.visible !== false || item.visible)
|
|
189
|
+
// })}
|
|
190
|
+
, {
|
|
191
|
+
onClick: handleAccept
|
|
192
|
+
// disabled={!columns.find((item) => item.visible !== false || item.visible)}
|
|
193
|
+
}, t ? t('OK') : 'OK'), /*#__PURE__*/React.createElement(Button, {
|
|
194
|
+
className: 'btn-action btn-action-cancel',
|
|
195
|
+
onClick: handleCancel
|
|
196
|
+
}, t ? t('Cancel') : 'Cancel'))),
|
|
197
|
+
trigger: "click",
|
|
198
|
+
open: clicked,
|
|
199
|
+
onOpenChange: handleClickChange,
|
|
200
|
+
arrow: false,
|
|
201
|
+
zIndex: 1065
|
|
202
|
+
}, /*#__PURE__*/React.createElement(Tooltip, {
|
|
203
|
+
arrow: false,
|
|
204
|
+
title: 'Cài đặt'
|
|
205
|
+
}, /*#__PURE__*/React.createElement(SettingOutlined, null))));
|
|
206
|
+
};
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import * as React from "react";
|
|
2
|
+
import type { ContextInfo } from "./type";
|
|
3
|
+
import type { ContextMenuItem } from "./type";
|
|
4
|
+
export declare const findItemByKey: (array: any[], key: string, value: any) => any;
|
|
5
|
+
type Props<RecordType> = {
|
|
6
|
+
rowData: RecordType | null;
|
|
7
|
+
contextMenuItems: ContextMenuItem[];
|
|
8
|
+
contextMenuClick?: (args: ContextInfo<RecordType>) => void;
|
|
9
|
+
open: boolean;
|
|
10
|
+
menuRef?: any;
|
|
11
|
+
setOpen: (open: boolean) => void;
|
|
12
|
+
pos: {
|
|
13
|
+
x: number | undefined;
|
|
14
|
+
y: number | undefined;
|
|
15
|
+
viewportWidth: number;
|
|
16
|
+
viewportHeight: number;
|
|
17
|
+
};
|
|
18
|
+
};
|
|
19
|
+
declare const ContextMenu: <RecordType extends object>(props: Props<RecordType>) => React.JSX.Element;
|
|
20
|
+
export default ContextMenu;
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
import * as React from "react";
|
|
2
|
+
// import type { MenuProps } from "antd";
|
|
3
|
+
import { Dropdown, Menu } from "antd";
|
|
4
|
+
export const findItemByKey = (array, key, value) => {
|
|
5
|
+
for (let i = 0; i < array.length; i++) {
|
|
6
|
+
const item = array[i];
|
|
7
|
+
if (item[key] === value) {
|
|
8
|
+
return item;
|
|
9
|
+
}
|
|
10
|
+
if (item.children && item.children.length > 0) {
|
|
11
|
+
const foundInChildren = findItemByKey(item.children, key, value);
|
|
12
|
+
if (foundInChildren) {
|
|
13
|
+
return foundInChildren;
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
return null;
|
|
18
|
+
};
|
|
19
|
+
const ContextMenu = props => {
|
|
20
|
+
const {
|
|
21
|
+
menuRef,
|
|
22
|
+
open,
|
|
23
|
+
setOpen,
|
|
24
|
+
pos,
|
|
25
|
+
contextMenuClick,
|
|
26
|
+
contextMenuItems,
|
|
27
|
+
rowData
|
|
28
|
+
} = props;
|
|
29
|
+
return /*#__PURE__*/React.createElement(Dropdown, {
|
|
30
|
+
placement: 'topRight',
|
|
31
|
+
open: open,
|
|
32
|
+
overlayClassName: 'be-popup-container',
|
|
33
|
+
overlayStyle: {
|
|
34
|
+
left: `${pos.x}px`,
|
|
35
|
+
top: `${pos.y}px`
|
|
36
|
+
},
|
|
37
|
+
dropdownRender: () => {
|
|
38
|
+
return /*#__PURE__*/React.createElement("div", {
|
|
39
|
+
ref: menuRef
|
|
40
|
+
}, /*#__PURE__*/React.createElement(Menu, {
|
|
41
|
+
items: contextMenuItems,
|
|
42
|
+
style: {
|
|
43
|
+
minWidth: 200,
|
|
44
|
+
maxHeight: pos.viewportHeight - 20,
|
|
45
|
+
width: 'fit-content'
|
|
46
|
+
},
|
|
47
|
+
rootClassName: 'popup-context-menu'
|
|
48
|
+
// rootClassName={'be-popup-container'}
|
|
49
|
+
,
|
|
50
|
+
|
|
51
|
+
onClick: e => {
|
|
52
|
+
setOpen(false);
|
|
53
|
+
contextMenuClick?.({
|
|
54
|
+
rowInfo: {
|
|
55
|
+
rowData
|
|
56
|
+
},
|
|
57
|
+
event: e.domEvent,
|
|
58
|
+
item: {
|
|
59
|
+
...findItemByKey(contextMenuItems, 'key', e.key),
|
|
60
|
+
id: e.key
|
|
61
|
+
}
|
|
62
|
+
});
|
|
63
|
+
|
|
64
|
+
// if (!open) {
|
|
65
|
+
// document.addEventListener(`click`, function onClickOutside() {
|
|
66
|
+
// setOpen(false);
|
|
67
|
+
// document.removeEventListener(`click`, onClickOutside);
|
|
68
|
+
// });
|
|
69
|
+
// }
|
|
70
|
+
}
|
|
71
|
+
}));
|
|
72
|
+
}
|
|
73
|
+
}, /*#__PURE__*/React.createElement(React.Fragment, null));
|
|
74
|
+
};
|
|
75
|
+
export default ContextMenu;
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import 'react-resizable/css/styles.css';
|
|
3
|
+
import 'dayjs/locale/es';
|
|
4
|
+
import 'dayjs/locale/vi';
|
|
5
|
+
import './style.scss';
|
|
6
|
+
import type { TableProps } from './type';
|
|
7
|
+
export declare const SELECTION_COLUMN: {};
|
|
8
|
+
declare const InternalTable: <RecordType extends object>(props: TableProps<RecordType>) => React.JSX.Element;
|
|
9
|
+
export default InternalTable;
|
|
@@ -0,0 +1,308 @@
|
|
|
1
|
+
import _extends from "@babel/runtime/helpers/esm/extends";
|
|
2
|
+
import customParseFormat from 'dayjs/plugin/customParseFormat';
|
|
3
|
+
import React, { Fragment, useState } from 'react';
|
|
4
|
+
import 'react-resizable/css/styles.css';
|
|
5
|
+
import dayjs from 'dayjs';
|
|
6
|
+
import 'dayjs/locale/es';
|
|
7
|
+
import 'dayjs/locale/vi';
|
|
8
|
+
|
|
9
|
+
// import en from "rc-master-ui/es/date-picker/locale/en_US"
|
|
10
|
+
// import vi from "rc-master-ui/es/date-picker/locale/vi_VN"
|
|
11
|
+
|
|
12
|
+
// import enDr from "rc-master-ui/es/locales/en_US"
|
|
13
|
+
// import viDr from "rc-master-ui/es/locales/vi_VN"
|
|
14
|
+
|
|
15
|
+
// import type { PickerLocale } from "rc-master-ui/es/date-picker/generatePicker"
|
|
16
|
+
|
|
17
|
+
import "./style.scss";
|
|
18
|
+
|
|
19
|
+
// import Swal from "sweetalert2"
|
|
20
|
+
// import withReactContent from "sweetalert2-react-content"
|
|
21
|
+
// import { Tooltip } from "react-tooltip"
|
|
22
|
+
|
|
23
|
+
import { faker } from '@faker-js/faker';
|
|
24
|
+
import useMergedState from "rc-util/es/hooks/useMergedState";
|
|
25
|
+
// import InfiniteTable from './table/InfiniteTable'
|
|
26
|
+
// import GridEdit from './table/GridEdit'
|
|
27
|
+
import Grid from "./table/Grid";
|
|
28
|
+
// import { Group } from 'becoxy-icons'
|
|
29
|
+
|
|
30
|
+
import { Tooltip } from 'react-tooltip';
|
|
31
|
+
import ContextMenu from "./ContextMenu";
|
|
32
|
+
import { addRowIdArray, convertToObj,
|
|
33
|
+
// convertFilters,
|
|
34
|
+
filterDataByColumns, flatColumns2,
|
|
35
|
+
// filterDataByColumns,
|
|
36
|
+
getAllRowKey, getDiffent2Array, getFixedFields, getInvisibleColumns, groupArrayByColumns } from "./hook/utils";
|
|
37
|
+
// import GridEdit from './table/GridEdit'
|
|
38
|
+
import { convertToTanStackColumns } from "./hook/useColumns";
|
|
39
|
+
// import { columns111 } from '../test-2/columns'
|
|
40
|
+
|
|
41
|
+
dayjs.extend(customParseFormat);
|
|
42
|
+
|
|
43
|
+
// const MySwal = withReactContent(Swal)
|
|
44
|
+
|
|
45
|
+
// const ASCEND = 'ascend'
|
|
46
|
+
// const DESCEND = 'descend'
|
|
47
|
+
|
|
48
|
+
export const SELECTION_COLUMN = {};
|
|
49
|
+
const InternalTable = props => {
|
|
50
|
+
const {
|
|
51
|
+
t,
|
|
52
|
+
// columns: propsColumns,
|
|
53
|
+
columns,
|
|
54
|
+
lang,
|
|
55
|
+
locale,
|
|
56
|
+
dataSource,
|
|
57
|
+
editAble,
|
|
58
|
+
format,
|
|
59
|
+
groupAble,
|
|
60
|
+
groupSetting,
|
|
61
|
+
groupColumns,
|
|
62
|
+
infiniteScroll,
|
|
63
|
+
// wrapSettings,
|
|
64
|
+
// onFilter,
|
|
65
|
+
// expandable,
|
|
66
|
+
contextMenuItems: propContextMenuItems,
|
|
67
|
+
contextMenuHidden,
|
|
68
|
+
contextMenuClick,
|
|
69
|
+
contextMenuOpen,
|
|
70
|
+
...rest
|
|
71
|
+
} = props;
|
|
72
|
+
const id = React.useMemo(() => {
|
|
73
|
+
return faker.string.alpha(20);
|
|
74
|
+
}, []);
|
|
75
|
+
const rowKey = 'rowId';
|
|
76
|
+
const prefix = 'ui-rc';
|
|
77
|
+
const getWindowSize = () => {
|
|
78
|
+
const {
|
|
79
|
+
innerWidth,
|
|
80
|
+
innerHeight
|
|
81
|
+
} = window;
|
|
82
|
+
return {
|
|
83
|
+
innerWidth,
|
|
84
|
+
innerHeight
|
|
85
|
+
};
|
|
86
|
+
};
|
|
87
|
+
const [windowSize, setWindowSize] = useState(getWindowSize());
|
|
88
|
+
React.useEffect(() => {
|
|
89
|
+
const handleWindowResize = () => {
|
|
90
|
+
setWindowSize(getWindowSize());
|
|
91
|
+
};
|
|
92
|
+
window.addEventListener('resize', handleWindowResize);
|
|
93
|
+
return () => {
|
|
94
|
+
window.removeEventListener('resize', handleWindowResize);
|
|
95
|
+
};
|
|
96
|
+
}, []);
|
|
97
|
+
|
|
98
|
+
// const local = lang && lang === 'en' ? en : vi
|
|
99
|
+
// const dateRangeLocale = lang && lang === 'en' ? enDr : viDr
|
|
100
|
+
|
|
101
|
+
// const buddhistLocale: PickerLocale = {
|
|
102
|
+
// ...local,
|
|
103
|
+
// lang: {
|
|
104
|
+
// ...local.lang
|
|
105
|
+
// }
|
|
106
|
+
// }
|
|
107
|
+
|
|
108
|
+
const menuRef = React.useRef(null);
|
|
109
|
+
const viewportWidth = windowSize.innerWidth;
|
|
110
|
+
const viewportHeight = windowSize.innerHeight;
|
|
111
|
+
const [menuVisible, setMenuVisible] = React.useState(false);
|
|
112
|
+
const [selectedRowData, setSelectedRowData] = React.useState(null);
|
|
113
|
+
const [position, setPosition] = React.useState({
|
|
114
|
+
x: 0,
|
|
115
|
+
y: 0,
|
|
116
|
+
viewportWidth,
|
|
117
|
+
viewportHeight
|
|
118
|
+
});
|
|
119
|
+
|
|
120
|
+
// const [tooltipContent, setTooltipContent] = useState<any>('')
|
|
121
|
+
|
|
122
|
+
const [filterStates, setFilterState] = React.useState(null);
|
|
123
|
+
const [sorterStates, setSorterStates] = React.useState([]);
|
|
124
|
+
const [expanded, setExpanded] = React.useState({});
|
|
125
|
+
const convertData = React.useMemo(() => {
|
|
126
|
+
if (groupAble && groupSetting && groupSetting.client !== false) {
|
|
127
|
+
return groupArrayByColumns(dataSource, groupColumns);
|
|
128
|
+
}
|
|
129
|
+
return addRowIdArray(dataSource);
|
|
130
|
+
}, [dataSource, groupAble, groupColumns, groupSetting]);
|
|
131
|
+
const mergedColumns = React.useMemo(() => {
|
|
132
|
+
return convertToTanStackColumns({
|
|
133
|
+
t,
|
|
134
|
+
columns,
|
|
135
|
+
// expanded,
|
|
136
|
+
// setExpanded,
|
|
137
|
+
// expandable,
|
|
138
|
+
format,
|
|
139
|
+
editAble
|
|
140
|
+
});
|
|
141
|
+
|
|
142
|
+
// return convertToTanStackColumns<RecordType>(columns, expanded, setExpanded, expandable)
|
|
143
|
+
}, [t, columns, format, editAble]);
|
|
144
|
+
console.log('mergedColumns', mergedColumns);
|
|
145
|
+
const columnPinning = React.useMemo(() => {
|
|
146
|
+
return {
|
|
147
|
+
left: getFixedFields(columns, 'left'),
|
|
148
|
+
right: getFixedFields(columns, 'right')
|
|
149
|
+
};
|
|
150
|
+
}, [columns]);
|
|
151
|
+
|
|
152
|
+
// ========================= Keys =========================
|
|
153
|
+
const [mergedFilterKeys, setMergedFilterKeys] = useMergedState(getAllRowKey(convertData), {
|
|
154
|
+
value: undefined
|
|
155
|
+
});
|
|
156
|
+
const mergedData = React.useMemo(() => {
|
|
157
|
+
return filterDataByColumns(convertData, filterStates, sorterStates, mergedFilterKeys);
|
|
158
|
+
}, [convertData, filterStates, mergedFilterKeys, sorterStates]);
|
|
159
|
+
const columnVisibility = React.useMemo(() => {
|
|
160
|
+
return getInvisibleColumns(columns);
|
|
161
|
+
}, [columns]);
|
|
162
|
+
const [columnsHiddenKeys, setColumnsHiddenKeys] = useMergedState(undefined, {
|
|
163
|
+
value: undefined
|
|
164
|
+
});
|
|
165
|
+
const triggerChangeColumns = (cols, keys) => {
|
|
166
|
+
const aa = flatColumns2(columns).map(it => it.field);
|
|
167
|
+
const rsss = getDiffent2Array(aa, keys);
|
|
168
|
+
setColumnsHiddenKeys(rsss);
|
|
169
|
+
};
|
|
170
|
+
const contextMenuItems = React.useMemo(() => {
|
|
171
|
+
if (typeof contextMenuHidden === 'function' && propContextMenuItems && selectedRowData) {
|
|
172
|
+
const hiddenItems = contextMenuHidden({
|
|
173
|
+
rowInfo: {
|
|
174
|
+
rowData: selectedRowData
|
|
175
|
+
}
|
|
176
|
+
});
|
|
177
|
+
return propContextMenuItems.filter(item => !hiddenItems.includes(item?.key));
|
|
178
|
+
}
|
|
179
|
+
if (contextMenuHidden && typeof contextMenuHidden !== 'function' && propContextMenuItems) {
|
|
180
|
+
return propContextMenuItems.filter(item => !contextMenuHidden.includes(item?.key));
|
|
181
|
+
}
|
|
182
|
+
return propContextMenuItems;
|
|
183
|
+
}, [propContextMenuItems, contextMenuHidden, selectedRowData]);
|
|
184
|
+
|
|
185
|
+
// const [columns, setColumns] = React.useState<any[]>([])
|
|
186
|
+
|
|
187
|
+
// React.useEffect(() => {
|
|
188
|
+
// setColumns(propsColumns)
|
|
189
|
+
// }, [propsColumns])
|
|
190
|
+
|
|
191
|
+
// const triggerFilter = (queries: any[]) => {
|
|
192
|
+
|
|
193
|
+
// if (onFilter) {
|
|
194
|
+
// onFilter?.(convertFilters(queries))
|
|
195
|
+
// } else {
|
|
196
|
+
|
|
197
|
+
// setFilterState(convertFilters(queries))
|
|
198
|
+
|
|
199
|
+
// const b = filterDataByColumns(convertData, convertFilters(queries), [], [])
|
|
200
|
+
|
|
201
|
+
// setMergedFilterKeys(getAllRowKey(b))
|
|
202
|
+
|
|
203
|
+
// }
|
|
204
|
+
// }
|
|
205
|
+
|
|
206
|
+
const onContextMenu = data => event => {
|
|
207
|
+
event.preventDefault(); // Ngăn chặn menu mặc định của trình duyệt
|
|
208
|
+
|
|
209
|
+
setSelectedRowData(data);
|
|
210
|
+
contextMenuOpen?.({
|
|
211
|
+
rowInfo: {
|
|
212
|
+
rowData: data
|
|
213
|
+
},
|
|
214
|
+
event
|
|
215
|
+
});
|
|
216
|
+
setMenuVisible(true);
|
|
217
|
+
|
|
218
|
+
// Đợi DOM cập nhật và lấy kích thước menu
|
|
219
|
+
setTimeout(() => {
|
|
220
|
+
const menuElement = menuRef.current; // Lấy menu từ DOM
|
|
221
|
+
const menuWidth = menuElement?.offsetWidth || 200; // Mặc định 200px nếu chưa render
|
|
222
|
+
const menuHeight = menuElement?.offsetHeight; // Mặc định 450px nếu chưa render
|
|
223
|
+
|
|
224
|
+
// Điều chỉnh vị trí menu
|
|
225
|
+
let x = event.clientX;
|
|
226
|
+
let y = event.clientY;
|
|
227
|
+
if (x + menuWidth > viewportWidth) {
|
|
228
|
+
x = x - menuWidth - 10; // Cách cạnh phải 10px
|
|
229
|
+
}
|
|
230
|
+
if (y + menuHeight > viewportHeight) {
|
|
231
|
+
if (y < menuHeight) {
|
|
232
|
+
y = 10;
|
|
233
|
+
} else {
|
|
234
|
+
y = y - 10 - menuHeight; // Cách cạnh dưới 10px
|
|
235
|
+
}
|
|
236
|
+
}
|
|
237
|
+
setPosition(prevState => ({
|
|
238
|
+
...prevState,
|
|
239
|
+
x,
|
|
240
|
+
y
|
|
241
|
+
}));
|
|
242
|
+
}, 100);
|
|
243
|
+
if (!menuVisible) {
|
|
244
|
+
document.addEventListener(`click`, function onClickOutside(e) {
|
|
245
|
+
const element = e.target;
|
|
246
|
+
const menuContainer = document.querySelector('.popup-context-menu');
|
|
247
|
+
const isInsideContainer = element.closest('.popup-context-menu') && menuContainer;
|
|
248
|
+
if (isInsideContainer) {
|
|
249
|
+
return;
|
|
250
|
+
}
|
|
251
|
+
setMenuVisible(false);
|
|
252
|
+
setPosition(prevState => ({
|
|
253
|
+
...prevState,
|
|
254
|
+
x: undefined,
|
|
255
|
+
y: undefined
|
|
256
|
+
}));
|
|
257
|
+
document.removeEventListener(`click`, onClickOutside);
|
|
258
|
+
});
|
|
259
|
+
}
|
|
260
|
+
};
|
|
261
|
+
|
|
262
|
+
// const TableComponent = infiniteScroll ? InfiniteTable : (groupAble ? Group : editAble ? GridEdit : Grid)
|
|
263
|
+
// const TableComponent = Grid
|
|
264
|
+
|
|
265
|
+
return /*#__PURE__*/React.createElement(Fragment, null, /*#__PURE__*/React.createElement(Grid, _extends({}, rest, {
|
|
266
|
+
t: t,
|
|
267
|
+
id: id,
|
|
268
|
+
prefix: prefix,
|
|
269
|
+
originData: convertData,
|
|
270
|
+
dataSource: mergedData,
|
|
271
|
+
locale: locale,
|
|
272
|
+
format: format
|
|
273
|
+
// columns={columns111 as any}
|
|
274
|
+
,
|
|
275
|
+
columns: mergedColumns,
|
|
276
|
+
propsColumns: columns,
|
|
277
|
+
rowKey: rowKey,
|
|
278
|
+
groupSetting: groupSetting,
|
|
279
|
+
groupAble: groupAble,
|
|
280
|
+
groupColumns: groupColumns,
|
|
281
|
+
columnPinning: columnPinning,
|
|
282
|
+
columnHidden: columnsHiddenKeys ? convertToObj(columnsHiddenKeys) : columnVisibility,
|
|
283
|
+
triggerFilter: setFilterState,
|
|
284
|
+
triggerSorter: setSorterStates,
|
|
285
|
+
setMergedFilterKeys: setMergedFilterKeys,
|
|
286
|
+
mergedFilterKeys: mergedFilterKeys,
|
|
287
|
+
expanded: expanded,
|
|
288
|
+
onContextMenu: onContextMenu,
|
|
289
|
+
contextMenuItems: contextMenuItems,
|
|
290
|
+
editAble: editAble,
|
|
291
|
+
triggerChangeColumns: triggerChangeColumns,
|
|
292
|
+
setExpanded: setExpanded
|
|
293
|
+
})), menuVisible && /*#__PURE__*/React.createElement(ContextMenu, {
|
|
294
|
+
open: menuVisible,
|
|
295
|
+
pos: position,
|
|
296
|
+
setOpen: setMenuVisible,
|
|
297
|
+
menuRef: menuRef,
|
|
298
|
+
contextMenuItems: contextMenuItems,
|
|
299
|
+
contextMenuClick: contextMenuClick,
|
|
300
|
+
rowData: selectedRowData
|
|
301
|
+
}), /*#__PURE__*/React.createElement(Tooltip, {
|
|
302
|
+
id: `${id}-tooltip-content`,
|
|
303
|
+
style: {
|
|
304
|
+
zIndex: 1999
|
|
305
|
+
}
|
|
306
|
+
}));
|
|
307
|
+
};
|
|
308
|
+
export default InternalTable;
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import type { Dispatch, SetStateAction } from 'react';
|
|
2
|
+
import React from 'react';
|
|
3
|
+
import type { ColumnDef, Table } from '@tanstack/react-table';
|
|
4
|
+
import type { ColumnsTable, TableProps } from './type';
|
|
5
|
+
type TableContainerProps<T> = Omit<TableProps<T>, 'columns'> & {
|
|
6
|
+
table: Table<T>;
|
|
7
|
+
prefix: string;
|
|
8
|
+
id: string;
|
|
9
|
+
rowKey: any;
|
|
10
|
+
originData: T[];
|
|
11
|
+
setIsSelectionChange: Dispatch<SetStateAction<{
|
|
12
|
+
isChange: boolean;
|
|
13
|
+
type: string;
|
|
14
|
+
rowData: T;
|
|
15
|
+
}>>;
|
|
16
|
+
setSorterChange: Dispatch<SetStateAction<boolean>>;
|
|
17
|
+
setFilterChange: Dispatch<SetStateAction<boolean>>;
|
|
18
|
+
onContextMenu?: (data: T) => (event: any) => void;
|
|
19
|
+
tableHeight?: number;
|
|
20
|
+
triggerPaste?: (pastedRows: T[], pastedColumnsArray: string[], newData: T[], copyRows: T[]) => void;
|
|
21
|
+
mergedFilterKeys?: any;
|
|
22
|
+
setMergedFilterKeys?: any;
|
|
23
|
+
setExpanded?: any;
|
|
24
|
+
expanded?: any;
|
|
25
|
+
columns: ColumnDef<T>[];
|
|
26
|
+
propsColumns: ColumnsTable;
|
|
27
|
+
triggerChangeColumns: any;
|
|
28
|
+
columnHidden: any;
|
|
29
|
+
};
|
|
30
|
+
declare const TableContainer: <RecordType extends object>(props: TableContainerProps<RecordType>) => React.JSX.Element;
|
|
31
|
+
export default TableContainer;
|