es-grid-template 1.1.7 → 1.2.0
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/grid-component/ColumnsChoose.js +1 -1
- package/es/grid-component/GridStyle.js +1 -1
- package/es/grid-component/InternalTable.js +94 -107
- package/es/grid-component/TableGrid.d.ts +4 -2
- package/es/grid-component/TableGrid.js +17 -7
- package/es/grid-component/hooks/constant.js +14 -14
- package/es/grid-component/hooks/useColumns/index.d.ts +5 -3
- package/es/grid-component/hooks/useColumns/index.js +29 -1
- package/es/grid-component/hooks/utils.d.ts +6 -2
- package/es/grid-component/hooks/utils.js +44 -2
- package/es/grid-component/styles.scss +766 -701
- package/es/grid-component/table/Grid.d.ts +3 -0
- package/es/grid-component/table/Grid.js +3 -3
- package/es/grid-component/table/GridEdit.js +234 -168
- package/es/grid-component/type.d.ts +6 -2
- package/lib/grid-component/ColumnsChoose.js +1 -1
- package/lib/grid-component/GridStyle.js +1 -1
- package/lib/grid-component/InternalTable.js +92 -103
- package/lib/grid-component/TableGrid.d.ts +4 -2
- package/lib/grid-component/TableGrid.js +17 -7
- package/lib/grid-component/hooks/constant.js +14 -14
- package/lib/grid-component/hooks/useColumns/index.d.ts +5 -3
- package/lib/grid-component/hooks/useColumns/index.js +30 -1
- package/lib/grid-component/hooks/utils.d.ts +6 -2
- package/lib/grid-component/hooks/utils.js +51 -5
- package/lib/grid-component/styles.scss +766 -701
- package/lib/grid-component/table/Grid.d.ts +3 -0
- package/lib/grid-component/table/Grid.js +3 -3
- package/lib/grid-component/table/GridEdit.js +228 -164
- package/lib/grid-component/type.d.ts +6 -2
- package/package.json +105 -105
|
@@ -1,8 +1,11 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
2
|
import type { ColumnsTable, GridTableProps } from "../type";
|
|
3
|
+
import type { GetRowKey } from "../type";
|
|
3
4
|
type Props<T> = GridTableProps<T> & {
|
|
4
5
|
tableRef: any;
|
|
5
6
|
triggerChangeColumns?: (columns: ColumnsTable<T>, type: string) => void;
|
|
7
|
+
triggerChangeData?: (newData: T[], type: string) => void;
|
|
8
|
+
getRowKey: GetRowKey<T>;
|
|
6
9
|
};
|
|
7
10
|
declare const Grid: <RecordType extends object>(props: Props<RecordType>) => React.JSX.Element;
|
|
8
11
|
export default Grid;
|
|
@@ -13,12 +13,11 @@ function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return
|
|
|
13
13
|
function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" != typeof e && "function" != typeof e) return { default: e }; var t = _getRequireWildcardCache(r); if (t && t.has(e)) return t.get(e); var n = { __proto__: null }, a = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var u in e) if ("default" !== u && Object.prototype.hasOwnProperty.call(e, u)) { var i = a ? Object.getOwnPropertyDescriptor(e, u) : null; i && (i.get || i.set) ? Object.defineProperty(n, u, i) : n[u] = e[u]; } return n.default = e, t && t.set(e, n), n; }
|
|
14
14
|
// import type {ColumnsTable} from "../type";
|
|
15
15
|
|
|
16
|
-
// import {renderContent} from "../hooks/useColumns";
|
|
17
|
-
|
|
18
16
|
const Grid = props => {
|
|
19
17
|
const {
|
|
20
18
|
height,
|
|
21
19
|
style,
|
|
20
|
+
rowHoverable,
|
|
22
21
|
...rest
|
|
23
22
|
} = props;
|
|
24
23
|
return /*#__PURE__*/_react.default.createElement(_react.Fragment, null, /*#__PURE__*/_react.default.createElement(_GridStyle.GridStyle, {
|
|
@@ -30,7 +29,8 @@ const Grid = props => {
|
|
|
30
29
|
style: {
|
|
31
30
|
...style,
|
|
32
31
|
minHeight: height
|
|
33
|
-
}
|
|
32
|
+
},
|
|
33
|
+
rowHoverable: rowHoverable ?? true
|
|
34
34
|
}))));
|
|
35
35
|
};
|
|
36
36
|
var _default = exports.default = Grid;
|
|
@@ -22,9 +22,11 @@ require("dayjs/locale/vi");
|
|
|
22
22
|
var _TableGrid = _interopRequireDefault(require("../TableGrid"));
|
|
23
23
|
var _hooks = require("../hooks");
|
|
24
24
|
var _Message = _interopRequireDefault(require("../../Message/Message"));
|
|
25
|
-
var
|
|
25
|
+
var _rcMasterUi = require("rc-master-ui");
|
|
26
26
|
function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return null; var r = new WeakMap(), t = new WeakMap(); return (_getRequireWildcardCache = function (e) { return e ? t : r; })(e); }
|
|
27
27
|
function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" != typeof e && "function" != typeof e) return { default: e }; var t = _getRequireWildcardCache(r); if (t && t.has(e)) return t.get(e); var n = { __proto__: null }, a = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var u in e) if ("default" !== u && Object.prototype.hasOwnProperty.call(e, u)) { var i = a ? Object.getOwnPropertyDescriptor(e, u) : null; i && (i.get || i.set) ? Object.defineProperty(n, u, i) : n[u] = e[u]; } return n.default = e, t && t.set(e, n), n; }
|
|
28
|
+
// import Command from "../Command";
|
|
29
|
+
|
|
28
30
|
_dayjs.default.extend(_customParseFormat.default);
|
|
29
31
|
const toast = 'top-right';
|
|
30
32
|
const GridEdit = props => {
|
|
@@ -46,6 +48,7 @@ const GridEdit = props => {
|
|
|
46
48
|
style,
|
|
47
49
|
getRowKey,
|
|
48
50
|
className,
|
|
51
|
+
toolbarItems,
|
|
49
52
|
...rest
|
|
50
53
|
} = props;
|
|
51
54
|
|
|
@@ -56,11 +59,78 @@ const GridEdit = props => {
|
|
|
56
59
|
const startCell = (0, _react.useRef)(null);
|
|
57
60
|
const isSelectingRow = (0, _react.useRef)(false);
|
|
58
61
|
const rowStart = (0, _react.useRef)(null);
|
|
62
|
+
const itemsAdd = [{
|
|
63
|
+
key: '10',
|
|
64
|
+
label: '10 rows'
|
|
65
|
+
}, {
|
|
66
|
+
key: '50',
|
|
67
|
+
label: '50 rows'
|
|
68
|
+
}, {
|
|
69
|
+
key: '100',
|
|
70
|
+
label: '100 rows'
|
|
71
|
+
}];
|
|
59
72
|
const [form] = _antd.Form.useForm();
|
|
60
73
|
const [editingKey, setEditingKey] = (0, _react.useState)('');
|
|
61
74
|
const [selectedCells, setSelectedCells] = (0, _react.useState)(new Set());
|
|
62
75
|
const [rowsSelected, setRowsSelected] = (0, _react.useState)(new Set());
|
|
63
76
|
const [selectedCell, setSelectedCell] = (0, _react.useState)(null);
|
|
77
|
+
const handleAdd = item => {
|
|
78
|
+
console.log(item);
|
|
79
|
+
if (item.onClick) {
|
|
80
|
+
console.log('cccccccccccccccc');
|
|
81
|
+
} else {
|
|
82
|
+
console.log('bbbbbbbbbbbbb');
|
|
83
|
+
}
|
|
84
|
+
};
|
|
85
|
+
const handleDuplicate = () => {};
|
|
86
|
+
const handleInsertBefore = () => {};
|
|
87
|
+
const handleInsertAfter = () => {};
|
|
88
|
+
const handleDeleteAll = () => {};
|
|
89
|
+
const toolbarItemsBottom = (0, _react.useMemo)(() => {
|
|
90
|
+
return toolbarItems?.filter(it => it.position === 'Bottom').map(item => {
|
|
91
|
+
return {
|
|
92
|
+
...item,
|
|
93
|
+
template: () => {
|
|
94
|
+
return /*#__PURE__*/_react.default.createElement(_react.Fragment, null, item.key === 'ADD' && /*#__PURE__*/_react.default.createElement("div", {
|
|
95
|
+
className: (0, _classnames.default)(`be-toolbar-item ${item.className}`)
|
|
96
|
+
}, /*#__PURE__*/_react.default.createElement(_antd.Dropdown.Button, {
|
|
97
|
+
menu: {
|
|
98
|
+
items: itemsAdd,
|
|
99
|
+
onClick: () => handleAdd(item)
|
|
100
|
+
}
|
|
101
|
+
}, item.title ? t ? t(item.title) : item.title : t ? t('Add item') : 'Add item')), item.key === 'DUPLICATE' && item.visible !== false && editingKey && /*#__PURE__*/_react.default.createElement("div", {
|
|
102
|
+
className: (0, _classnames.default)(`be-toolbar-item ${item.className}`)
|
|
103
|
+
}, /*#__PURE__*/_react.default.createElement(_antd.Button, {
|
|
104
|
+
color: "green",
|
|
105
|
+
variant: 'outlined',
|
|
106
|
+
onClick: handleDuplicate,
|
|
107
|
+
className: "d-flex be-button"
|
|
108
|
+
}, item.title ? t ? t(item.title) : item.title : t ? t('Duplicate') : 'Duplicate')), item.key === 'INSERT_BEFORE' && item.visible !== false && editingKey && /*#__PURE__*/_react.default.createElement("div", {
|
|
109
|
+
className: (0, _classnames.default)(`be-toolbar-item ${item.className}`)
|
|
110
|
+
}, /*#__PURE__*/_react.default.createElement(_antd.Button, {
|
|
111
|
+
color: "green",
|
|
112
|
+
variant: 'outlined',
|
|
113
|
+
onClick: handleInsertBefore,
|
|
114
|
+
className: "d-flex be-button"
|
|
115
|
+
}, item.title ? t ? t(item.title) : item.title : t ? t('Insert item before') : 'Insert item before')), item.key === 'INSERT_AFTER' && item.visible !== false && editingKey && /*#__PURE__*/_react.default.createElement("div", {
|
|
116
|
+
className: (0, _classnames.default)(`be-toolbar-item ${item.className}`)
|
|
117
|
+
}, /*#__PURE__*/_react.default.createElement(_antd.Button, {
|
|
118
|
+
color: "green",
|
|
119
|
+
variant: 'outlined',
|
|
120
|
+
onClick: handleInsertAfter,
|
|
121
|
+
className: "d-flex be-button"
|
|
122
|
+
}, item.title ? t ? t(item.title) : item.title : t ? t('Insert item after') : 'Insert item after')), item.key === 'DELETE' && item.visible !== false && /*#__PURE__*/_react.default.createElement("div", {
|
|
123
|
+
className: (0, _classnames.default)(`be-toolbar-item ${item.className}`)
|
|
124
|
+
}, /*#__PURE__*/_react.default.createElement(_antd.Button, {
|
|
125
|
+
color: "primary",
|
|
126
|
+
variant: 'outlined',
|
|
127
|
+
onClick: handleDeleteAll,
|
|
128
|
+
className: "d-flex be-button"
|
|
129
|
+
}, item.title ? t ? t(item.title) : item.title : t ? t('Delete all item') : 'Delete all item')));
|
|
130
|
+
}
|
|
131
|
+
};
|
|
132
|
+
});
|
|
133
|
+
}, [toolbarItems]);
|
|
64
134
|
const {
|
|
65
135
|
control,
|
|
66
136
|
handleSubmit,
|
|
@@ -92,9 +162,10 @@ const GridEdit = props => {
|
|
|
92
162
|
|
|
93
163
|
if (!tableBody.contains(event.target)) {
|
|
94
164
|
setEditingKey('');
|
|
95
|
-
|
|
96
|
-
|
|
165
|
+
isSelecting.current = false;
|
|
166
|
+
startCell.current = null;
|
|
97
167
|
setSelectedCells(new Set());
|
|
168
|
+
setRowsSelected(new Set());
|
|
98
169
|
} else {}
|
|
99
170
|
}
|
|
100
171
|
};
|
|
@@ -583,175 +654,166 @@ const GridEdit = props => {
|
|
|
583
654
|
}
|
|
584
655
|
}
|
|
585
656
|
};
|
|
586
|
-
const
|
|
587
|
-
|
|
588
|
-
|
|
589
|
-
|
|
590
|
-
|
|
591
|
-
}
|
|
592
|
-
if (col.children) {
|
|
593
|
-
return {
|
|
594
|
-
...col,
|
|
595
|
-
children: addResizeHandlers(col.children, currentPath)
|
|
596
|
-
};
|
|
597
|
-
}
|
|
598
|
-
if (col.dataIndex === 'index' || col.field === 'index' || col.dataIndex === '#' || col.dataIndex === '#') {
|
|
599
|
-
return {
|
|
600
|
-
...col,
|
|
601
|
-
className: 'rc-ui-cell-editable',
|
|
602
|
-
render: (value, record, rowIndex) => {
|
|
603
|
-
return /*#__PURE__*/_react.default.createElement("div", {
|
|
604
|
-
className: (0, _classnames.default)('ui-rc_cell-content ui-rc_cell-content--index', {
|
|
605
|
-
selected: rowsSelected.has(`${rowIndex}-${colIndex}`),
|
|
606
|
-
focus: selectedCells && Array.from(selectedCells).some(item => item.startsWith(`${rowIndex}-`))
|
|
607
|
-
}),
|
|
608
|
-
onMouseDown: event => handleMouseDownColIndex(rowIndex, colIndex, event),
|
|
609
|
-
onMouseEnter: event => handleMouseEnterColIndex(rowIndex, colIndex, event),
|
|
610
|
-
onClick: () => handleClickRowHeader(rowIndex, colIndex)
|
|
611
|
-
}, /*#__PURE__*/_react.default.createElement("div", {
|
|
612
|
-
className: 'ui-rc_content'
|
|
613
|
-
}, rowIndex + 1));
|
|
614
|
-
}
|
|
615
|
-
};
|
|
616
|
-
}
|
|
617
|
-
if (col.dataIndex === 'command' || col.field === 'command') {
|
|
618
|
-
return {
|
|
619
|
-
...col,
|
|
620
|
-
title: col.headerText ?? col.title,
|
|
621
|
-
ellipsis: col.ellipsis !== false,
|
|
622
|
-
onCell: () => ({
|
|
623
|
-
className: 'ui-rc-cell-command'
|
|
624
|
-
}),
|
|
625
|
-
// render: (value: any, record: any, rowIndex: number) => {
|
|
626
|
-
render: () => {
|
|
627
|
-
return /*#__PURE__*/_react.default.createElement("div", {
|
|
628
|
-
className: (0, _classnames.default)('ui-rc-cell-command__content', {})
|
|
629
|
-
}, col.commandItems && col.commandItems?.map((item, indexComm) => {
|
|
630
|
-
if (item.visible !== false) {
|
|
631
|
-
// return (
|
|
632
|
-
// <span>{item.title}</span>
|
|
633
|
-
// )
|
|
634
|
-
|
|
635
|
-
return /*#__PURE__*/_react.default.createElement(_Command.default, {
|
|
636
|
-
key: `command-${indexComm}`,
|
|
637
|
-
item: item,
|
|
638
|
-
onClick: e => {
|
|
639
|
-
e.preventDefault();
|
|
640
|
-
// handleCommandClick({command: item, rowData: record, index: rowIndex})
|
|
641
|
-
}
|
|
642
|
-
});
|
|
643
|
-
}
|
|
644
|
-
}));
|
|
645
|
-
}
|
|
646
|
-
};
|
|
647
|
-
}
|
|
657
|
+
const convertColumns = (0, _useColumns.flatColumns)(columns).map((column, colIndex) => {
|
|
658
|
+
if (!column?.field && !column?.key) {
|
|
659
|
+
return column;
|
|
660
|
+
}
|
|
661
|
+
if (column.dataIndex === 'index' || column.field === 'index' || column.dataIndex === '#' || column.dataIndex === '#') {
|
|
648
662
|
return {
|
|
649
|
-
...
|
|
650
|
-
|
|
651
|
-
onKeyDown: event => {
|
|
652
|
-
if (event.key.length === 1 && !event.ctrlKey && !event.metaKey || event.key === 'Enter') {
|
|
653
|
-
if (!isEditing(record) && record[rowKey] !== editingKey) {
|
|
654
|
-
handleEdit(record, col, col.editType, event);
|
|
655
|
-
}
|
|
656
|
-
if (editingKey && editingKey !== '' && (rowIndex ?? 0) + 1 < dataSource.length && event.key === 'Enter') {
|
|
657
|
-
handleFocusCell((rowIndex ?? 0) + 1, colIndex, col, 'vertical', event);
|
|
658
|
-
}
|
|
659
|
-
}
|
|
660
|
-
if (event.key === 'Tab') {
|
|
661
|
-
if (colIndex + 1 !== cols.length) {
|
|
662
|
-
handleFocusCell(rowIndex, colIndex + 1, col, 'horizontal', event);
|
|
663
|
-
} else {
|
|
664
|
-
event.stopPropagation();
|
|
665
|
-
event.preventDefault();
|
|
666
|
-
}
|
|
667
|
-
}
|
|
668
|
-
if (event.key === 'ArrowRight' && colIndex + 1 !== cols.length) {
|
|
669
|
-
if (editingKey !== '') {} else {
|
|
670
|
-
handleFocusCell(rowIndex, colIndex + 1, col, 'horizontal', event);
|
|
671
|
-
}
|
|
672
|
-
}
|
|
673
|
-
if (event.key === 'ArrowLeft' && colIndex > 0) {
|
|
674
|
-
if (!col.dataIndex && !col.key || col.field === 'index' || col.field === '#' || col.dataIndex === 'index' || col.dataIndex === '#') {
|
|
675
|
-
event.stopPropagation();
|
|
676
|
-
event.preventDefault();
|
|
677
|
-
} else {
|
|
678
|
-
if (editingKey !== '') {} else {
|
|
679
|
-
handleFocusCell(rowIndex, colIndex - 1, col, 'horizontal', event);
|
|
680
|
-
}
|
|
681
|
-
}
|
|
682
|
-
}
|
|
683
|
-
if (event.key === 'ArrowDown' && (rowIndex ?? 0) + 1 < dataSource.length) {
|
|
684
|
-
handleFocusCell((rowIndex ?? 0) + 1, colIndex, col, 'vertical', event);
|
|
685
|
-
}
|
|
686
|
-
if (event.key === 'ArrowUp' && (rowIndex ?? 0) > 0) {
|
|
687
|
-
handleFocusCell((rowIndex ?? 0) - 1, colIndex, col, 'vertical', event);
|
|
688
|
-
}
|
|
689
|
-
},
|
|
690
|
-
onPaste: event => {
|
|
691
|
-
if (editingKey === '') {
|
|
692
|
-
handlePaste(event, colIndex, rowIndex);
|
|
693
|
-
event.preventDefault();
|
|
694
|
-
}
|
|
695
|
-
},
|
|
696
|
-
onCopy: e => {
|
|
697
|
-
if (editingKey === '') {
|
|
698
|
-
handleCopy(e);
|
|
699
|
-
e.preventDefault();
|
|
700
|
-
}
|
|
701
|
-
},
|
|
702
|
-
onDoubleClick: event => {
|
|
703
|
-
if (!isEditing(record) && record[rowKey] !== editingKey) {
|
|
704
|
-
handleEdit(record, col, col.editType, event);
|
|
705
|
-
}
|
|
706
|
-
},
|
|
707
|
-
// onMouseDown: (event) => {
|
|
708
|
-
// handleMouseDown(rowIndex, colIndex, event)
|
|
709
|
-
// },
|
|
710
|
-
//
|
|
711
|
-
// onMouseEnter: () => {
|
|
712
|
-
// handleMouseEnter(rowIndex, colIndex)
|
|
713
|
-
// },
|
|
714
|
-
|
|
715
|
-
onClick: () => {
|
|
716
|
-
if (record[rowKey] !== editingKey && editingKey !== '') {
|
|
717
|
-
setEditingKey('');
|
|
718
|
-
}
|
|
719
|
-
},
|
|
720
|
-
className: isEditing(record) ? 'rc-ui-cell-editable cell-editing' : 'rc-ui-cell-editable cell-editable',
|
|
721
|
-
record,
|
|
722
|
-
column: col,
|
|
723
|
-
editType: (0, _hooks.getEditType)(col, record),
|
|
724
|
-
dataIndex: col.dataIndex,
|
|
725
|
-
title: col.title,
|
|
726
|
-
'data-col-index': colIndex,
|
|
727
|
-
'data-row-index': rowIndex,
|
|
728
|
-
// colIndex: colIndex,
|
|
729
|
-
indexCol: colIndex,
|
|
730
|
-
indexRow: rowIndex,
|
|
731
|
-
editing: isEditing(record),
|
|
732
|
-
tabIndex: (rowIndex ?? 0) * columns.length + colIndex
|
|
733
|
-
}),
|
|
734
|
-
// onHeaderCell: (data) => ({
|
|
735
|
-
// ...col.onHeaderCell(),
|
|
736
|
-
// onClick: () => {
|
|
737
|
-
// handleClickColHeader(data as ColumnTable, colIndex)
|
|
738
|
-
// }
|
|
739
|
-
// }),
|
|
663
|
+
...column,
|
|
664
|
+
className: 'rc-ui-cell-editable',
|
|
740
665
|
render: (value, record, rowIndex) => {
|
|
666
|
+
const rowNumber = (0, _hooks.getRowNumber)(dataSource, record[rowKey], rowKey);
|
|
741
667
|
return /*#__PURE__*/_react.default.createElement("div", {
|
|
742
|
-
className: (0, _classnames.default)('ui-rc_cell-content', {
|
|
743
|
-
selected:
|
|
668
|
+
className: (0, _classnames.default)('ui-rc_cell-content ui-rc_cell-content--index', {
|
|
669
|
+
selected: rowsSelected.has(`${rowNumber}-${colIndex}`),
|
|
670
|
+
focus: selectedCells && Array.from(selectedCells).some(item => item.startsWith(`${rowNumber}-`))
|
|
744
671
|
}),
|
|
745
|
-
onMouseDown: event =>
|
|
746
|
-
onMouseEnter:
|
|
672
|
+
onMouseDown: event => handleMouseDownColIndex(rowNumber, colIndex, event),
|
|
673
|
+
onMouseEnter: event => handleMouseEnterColIndex(rowNumber, colIndex, event),
|
|
674
|
+
onClick: () => handleClickRowHeader(rowNumber, colIndex)
|
|
747
675
|
}, /*#__PURE__*/_react.default.createElement("div", {
|
|
748
676
|
className: 'ui-rc_content'
|
|
749
|
-
},
|
|
677
|
+
}, rowIndex + 1));
|
|
750
678
|
}
|
|
751
679
|
};
|
|
680
|
+
}
|
|
681
|
+
if ((column.key || column.field) === 'command') {
|
|
682
|
+
return {
|
|
683
|
+
...column
|
|
684
|
+
};
|
|
685
|
+
}
|
|
686
|
+
return {
|
|
687
|
+
...column,
|
|
688
|
+
// editType: getEditType(column, record),
|
|
689
|
+
onCell: (record, rowIndex) => ({
|
|
690
|
+
onKeyDown: event => {
|
|
691
|
+
if (event.key.length === 1 && !event.ctrlKey && !event.metaKey || event.key === 'Enter') {
|
|
692
|
+
if (!isEditing(record) && record[rowKey] !== editingKey) {
|
|
693
|
+
handleEdit(record, column, column.editType, event);
|
|
694
|
+
}
|
|
695
|
+
if (editingKey && editingKey !== '' && (rowIndex ?? 0) + 1 < dataSource.length && event.key === 'Enter') {
|
|
696
|
+
handleFocusCell((rowIndex ?? 0) + 1, colIndex, column, 'vertical', event);
|
|
697
|
+
}
|
|
698
|
+
}
|
|
699
|
+
if (event.key === 'Tab') {
|
|
700
|
+
if (colIndex + 1 !== columns.length) {
|
|
701
|
+
handleFocusCell(rowIndex, colIndex + 1, column, 'horizontal', event);
|
|
702
|
+
} else {
|
|
703
|
+
event.stopPropagation();
|
|
704
|
+
event.preventDefault();
|
|
705
|
+
}
|
|
706
|
+
}
|
|
707
|
+
if (event.key === 'ArrowRight' && colIndex + 1 !== columns.length) {
|
|
708
|
+
if (editingKey !== '') {} else {
|
|
709
|
+
handleFocusCell(rowIndex, colIndex + 1, column, 'horizontal', event);
|
|
710
|
+
}
|
|
711
|
+
}
|
|
712
|
+
if (event.key === 'ArrowLeft' && colIndex > 0) {
|
|
713
|
+
if (!column.dataIndex && !column.key || column.field === 'index' || column.field === '#' || column.dataIndex === 'index' || column.dataIndex === '#') {
|
|
714
|
+
event.stopPropagation();
|
|
715
|
+
event.preventDefault();
|
|
716
|
+
} else {
|
|
717
|
+
if (editingKey !== '') {} else {
|
|
718
|
+
handleFocusCell(rowIndex, colIndex - 1, column, 'horizontal', event);
|
|
719
|
+
}
|
|
720
|
+
}
|
|
721
|
+
}
|
|
722
|
+
if (event.key === 'ArrowDown' && (rowIndex ?? 0) + 1 < dataSource.length) {
|
|
723
|
+
handleFocusCell((rowIndex ?? 0) + 1, colIndex, column, 'vertical', event);
|
|
724
|
+
}
|
|
725
|
+
if (event.key === 'ArrowUp' && (rowIndex ?? 0) > 0) {
|
|
726
|
+
handleFocusCell((rowIndex ?? 0) - 1, colIndex, column, 'vertical', event);
|
|
727
|
+
}
|
|
728
|
+
},
|
|
729
|
+
onPaste: event => {
|
|
730
|
+
if (editingKey === '') {
|
|
731
|
+
handlePaste(event, colIndex, rowIndex);
|
|
732
|
+
event.preventDefault();
|
|
733
|
+
}
|
|
734
|
+
},
|
|
735
|
+
onCopy: e => {
|
|
736
|
+
if (editingKey === '') {
|
|
737
|
+
handleCopy(e);
|
|
738
|
+
e.preventDefault();
|
|
739
|
+
}
|
|
740
|
+
},
|
|
741
|
+
onDoubleClick: event => {
|
|
742
|
+
if (!isEditing(record) && record[rowKey] !== editingKey) {
|
|
743
|
+
handleEdit(record, column, (0, _hooks.getEditType)(column, record), event);
|
|
744
|
+
}
|
|
745
|
+
},
|
|
746
|
+
onClick: () => {
|
|
747
|
+
if (record[rowKey] !== editingKey && editingKey !== '') {
|
|
748
|
+
setEditingKey('');
|
|
749
|
+
}
|
|
750
|
+
},
|
|
751
|
+
className: isEditing(record) ? 'rc-ui-cell-editable cell-editing' : 'rc-ui-cell-editable cell-editable',
|
|
752
|
+
record,
|
|
753
|
+
column: column,
|
|
754
|
+
editType: (0, _hooks.getEditType)(column, record),
|
|
755
|
+
dataIndex: column.dataIndex,
|
|
756
|
+
title: column.title,
|
|
757
|
+
'data-col-index': colIndex,
|
|
758
|
+
'data-row-index': rowIndex,
|
|
759
|
+
// colIndex: colIndex,
|
|
760
|
+
indexCol: colIndex,
|
|
761
|
+
indexRow: rowIndex,
|
|
762
|
+
editing: isEditing(record),
|
|
763
|
+
tabIndex: (rowIndex ?? 0) * columns.length + colIndex
|
|
764
|
+
}),
|
|
765
|
+
render: (value, record, rowIndex) => {
|
|
766
|
+
const rowNumber = (0, _hooks.getRowNumber)(dataSource, record[rowKey], rowKey);
|
|
767
|
+
return /*#__PURE__*/_react.default.createElement("div", {
|
|
768
|
+
className: (0, _classnames.default)('ui-rc_cell-content', {
|
|
769
|
+
// selected: selectedCells.has(`${record[rowKey]}-${colIndex}`)
|
|
770
|
+
selected: selectedCells.has(`${rowNumber}-${colIndex}`)
|
|
771
|
+
}),
|
|
772
|
+
onMouseDown: event => handleMouseDown(rowNumber, colIndex, event)
|
|
773
|
+
// onMouseEnter={() => handleMouseEnter(record[rowKey], colIndex)}
|
|
774
|
+
,
|
|
775
|
+
onMouseEnter: () => handleMouseEnter(rowNumber, colIndex)
|
|
776
|
+
}, /*#__PURE__*/_react.default.createElement("div", {
|
|
777
|
+
className: 'ui-rc_content'
|
|
778
|
+
}, (0, _useColumns.renderContent)(column, value, record, rowIndex, format)));
|
|
779
|
+
}
|
|
780
|
+
};
|
|
781
|
+
});
|
|
782
|
+
const transformColumns = _react.default.useCallback(cols => {
|
|
783
|
+
// @ts-ignore
|
|
784
|
+
return cols.map(column => {
|
|
785
|
+
const find = convertColumns.find(it => it.key === column.key);
|
|
786
|
+
if (!column?.field && !column?.key) {
|
|
787
|
+
return column;
|
|
788
|
+
}
|
|
789
|
+
if (find) {
|
|
790
|
+
return {
|
|
791
|
+
...find
|
|
792
|
+
};
|
|
793
|
+
}
|
|
794
|
+
|
|
795
|
+
// Xử lý đệ quy cho children
|
|
796
|
+
if (column.children?.length) {
|
|
797
|
+
return {
|
|
798
|
+
...column,
|
|
799
|
+
children: transformColumns(column.children)
|
|
800
|
+
};
|
|
801
|
+
}
|
|
752
802
|
});
|
|
803
|
+
}, [convertColumns]);
|
|
804
|
+
const mergedColumns = _react.default.useMemo(() => transformColumns(columns ?? []), [transformColumns, columns]);
|
|
805
|
+
const bottomToolbar = () => {
|
|
806
|
+
return /*#__PURE__*/_react.default.createElement("div", null, /*#__PURE__*/_react.default.createElement(_rcMasterUi.Toolbar, {
|
|
807
|
+
style: {
|
|
808
|
+
width: '100%'
|
|
809
|
+
},
|
|
810
|
+
items: toolbarItemsBottom ?? [],
|
|
811
|
+
mode: 'scroll'
|
|
812
|
+
// onClick={({ item }) => {
|
|
813
|
+
// console.log('item', item)
|
|
814
|
+
// }}
|
|
815
|
+
}));
|
|
753
816
|
};
|
|
754
|
-
const resizableColumns = addResizeHandlers(columns);
|
|
755
817
|
return /*#__PURE__*/_react.default.createElement(_react.Fragment, null, /*#__PURE__*/_react.default.createElement(_GridStyle.GridStyle, {
|
|
756
818
|
heightTable: height,
|
|
757
819
|
style: {
|
|
@@ -783,11 +845,12 @@ const GridEdit = props => {
|
|
|
783
845
|
},
|
|
784
846
|
className: (0, _classnames.default)(className, 'grid-editable'),
|
|
785
847
|
rowKey: rowKey,
|
|
786
|
-
columns:
|
|
848
|
+
columns: mergedColumns,
|
|
787
849
|
showSorterTooltip: {
|
|
788
850
|
target: 'sorter-icon'
|
|
789
851
|
},
|
|
790
852
|
format: format,
|
|
853
|
+
toolbarItems: toolbarItems,
|
|
791
854
|
selectionSettings: selectionSettings ? {
|
|
792
855
|
...selectionSettings,
|
|
793
856
|
checkboxOnly: true
|
|
@@ -796,7 +859,8 @@ const GridEdit = props => {
|
|
|
796
859
|
...style,
|
|
797
860
|
minHeight: height
|
|
798
861
|
},
|
|
799
|
-
rowHoverable: false
|
|
862
|
+
rowHoverable: false,
|
|
863
|
+
bottomToolbar: bottomToolbar
|
|
800
864
|
}))))), /*#__PURE__*/_react.default.createElement(_reactHotToast.Toaster, {
|
|
801
865
|
position: toast,
|
|
802
866
|
toastOptions: {
|
|
@@ -3,12 +3,16 @@ import type React from "react";
|
|
|
3
3
|
import type { IOperator } from "./hooks";
|
|
4
4
|
import type { TypeFilter, TableProps as RcTableProps, TableColumnType as RcColumnType, EditType } from "rc-master-ui";
|
|
5
5
|
import type { FilterOperator, TableRowSelection } from "rc-master-ui/es/table/interface";
|
|
6
|
-
import type { ToolbarItem } from "rc-master-ui/es/toolbar";
|
|
6
|
+
import type { ToolbarItem as RcToolbarItem } from "rc-master-ui/es/toolbar";
|
|
7
7
|
import type { ItemType } from "rc-master-ui/es/menu/interface";
|
|
8
8
|
import type { FieldNames, FilterFunc } from "rc-select/es/Select";
|
|
9
9
|
import type { ColorPickerProps } from "antd";
|
|
10
10
|
export type IColumnType = "number" | "time" | "date" | "week" | "month" | "file" | "quarter" | "year" | "datetime" | "string" | "boolean" | "checkbox" | "color" | null | undefined;
|
|
11
11
|
export type AnyObject = Record<PropertyKey, any>;
|
|
12
|
+
export type ToolbarItem = Omit<RcToolbarItem, 'position'> & {
|
|
13
|
+
position?: 'Top' | 'Bottom';
|
|
14
|
+
onClick?: (args: any) => void;
|
|
15
|
+
};
|
|
12
16
|
export type SelectMode = 'checkbox' | 'radio' | undefined;
|
|
13
17
|
export type ITextAlign = 'center' | 'left' | 'right';
|
|
14
18
|
export type Frozen = 'left' | 'right' | 'Left' | 'Right';
|
|
@@ -104,7 +108,7 @@ export type ColumnType<RecordType> = Omit<RcColumnType<RecordType>, 'headerTempl
|
|
|
104
108
|
children?: ColumnType<RecordType>[];
|
|
105
109
|
};
|
|
106
110
|
export type ColumnEditType<RecordType> = Omit<ColumnType<RecordType>, 'children'> & {
|
|
107
|
-
editType?: EditType | ((rowData?:
|
|
111
|
+
editType?: EditType | ((rowData?: RecordType) => EditType);
|
|
108
112
|
disable?: boolean | ((rowData: any) => boolean);
|
|
109
113
|
isClearable?: boolean;
|
|
110
114
|
maxDate?: any;
|