es-grid-template 1.7.22 → 1.7.24
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/GridStyle.js +1 -1
- package/es/grid-component/InternalTable.js +5 -1
- package/es/grid-component/TableGrid.js +2 -2
- package/es/index.d.ts +1 -0
- package/es/index.js +3 -1
- package/es/table-component/ColumnsChoose.d.ts +10 -0
- package/es/table-component/ColumnsChoose.js +557 -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 +295 -0
- package/es/table-component/TableContainer.d.ts +22 -0
- package/es/table-component/TableContainer.js +130 -0
- package/es/table-component/TableContainerEdit.d.ts +28 -0
- package/es/table-component/TableContainerEdit.js +1211 -0
- package/es/table-component/body/EditableCell.d.ts +16 -0
- package/es/table-component/body/EditableCell.js +1036 -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 +10 -0
- package/es/table-component/body/TableBodyCell.js +139 -0
- package/es/table-component/body/TableBodyCellEdit.d.ts +15 -0
- package/es/table-component/body/TableBodyCellEdit.js +814 -0
- package/es/table-component/body/TableBodyRow.d.ts +21 -0
- package/es/table-component/body/TableBodyRow.js +146 -0
- package/es/table-component/components/ControlCheckbox.d.ts +13 -0
- package/es/table-component/components/ControlCheckbox.js +87 -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 +43 -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 +9 -0
- package/es/table-component/components/command/Command.js +28 -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 +24 -0
- package/es/table-component/footer/TableFooterRow.d.ts +14 -0
- package/es/table-component/footer/TableFooterRow.js +71 -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 +324 -0
- package/es/table-component/header/TableHeadRow.d.ts +16 -0
- package/es/table-component/header/TableHeadRow.js +86 -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 +11 -0
- package/es/table-component/hook/useColumns.js +209 -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 +121 -0
- package/es/table-component/hook/utils.js +1727 -0
- package/es/table-component/index.d.ts +5 -0
- package/es/table-component/index.js +2 -0
- package/es/table-component/style.scss +1083 -0
- package/es/table-component/table/Grid.d.ts +23 -0
- package/es/table-component/table/Grid.js +310 -0
- package/es/table-component/table/GridEdit.d.ts +23 -0
- package/es/table-component/table/GridEdit.js +282 -0
- package/es/table-component/type.d.ts +482 -0
- package/es/table-component/type.js +1 -0
- package/es/table-component/useContext.d.ts +119 -0
- package/es/table-component/useContext.js +61 -0
- package/lib/grid-component/GridStyle.js +1 -1
- package/lib/grid-component/InternalTable.js +5 -1
- package/lib/grid-component/TableGrid.js +2 -2
- package/lib/index.d.ts +1 -0
- package/lib/index.js +8 -1
- package/lib/table-component/ColumnsChoose.d.ts +10 -0
- package/lib/table-component/ColumnsChoose.js +568 -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 +299 -0
- package/lib/table-component/TableContainer.d.ts +22 -0
- package/lib/table-component/TableContainer.js +137 -0
- package/lib/table-component/TableContainerEdit.d.ts +28 -0
- package/lib/table-component/TableContainerEdit.js +1220 -0
- package/lib/table-component/body/EditableCell.d.ts +16 -0
- package/lib/table-component/body/EditableCell.js +1038 -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 +10 -0
- package/lib/table-component/body/TableBodyCell.js +148 -0
- package/lib/table-component/body/TableBodyCellEdit.d.ts +15 -0
- package/lib/table-component/body/TableBodyCellEdit.js +821 -0
- package/lib/table-component/body/TableBodyRow.d.ts +21 -0
- package/lib/table-component/body/TableBodyRow.js +153 -0
- package/lib/table-component/components/ControlCheckbox.d.ts +13 -0
- package/lib/table-component/components/ControlCheckbox.js +95 -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 +51 -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 +9 -0
- package/lib/table-component/components/command/Command.js +37 -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 +32 -0
- package/lib/table-component/footer/TableFooterRow.d.ts +14 -0
- package/lib/table-component/footer/TableFooterRow.js +79 -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 +333 -0
- package/lib/table-component/header/TableHeadRow.d.ts +16 -0
- package/lib/table-component/header/TableHeadRow.js +94 -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 +11 -0
- package/lib/table-component/hook/useColumns.js +220 -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 +121 -0
- package/lib/table-component/hook/utils.js +1817 -0
- package/lib/table-component/index.d.ts +5 -0
- package/lib/table-component/index.js +9 -0
- package/lib/table-component/style.scss +1083 -0
- package/lib/table-component/table/Grid.d.ts +23 -0
- package/lib/table-component/table/Grid.js +313 -0
- package/lib/table-component/table/GridEdit.d.ts +23 -0
- package/lib/table-component/table/GridEdit.js +284 -0
- package/lib/table-component/type.d.ts +482 -0
- package/lib/table-component/type.js +5 -0
- package/lib/table-component/useContext.d.ts +119 -0
- package/lib/table-component/useContext.js +67 -0
- package/package.json +3 -1
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import type { ColumnDef, ColumnPinningState, ExpandedState, VisibilityState } from '@tanstack/react-table';
|
|
2
|
+
import type { ColumnsTable, Sorter, TableProps } from '../type';
|
|
3
|
+
import type { Dispatch, SetStateAction } from 'react';
|
|
4
|
+
import React from 'react';
|
|
5
|
+
type Props<T> = Omit<TableProps<T>, 'columns'> & {
|
|
6
|
+
id: string;
|
|
7
|
+
rowKey: string;
|
|
8
|
+
prefix: string;
|
|
9
|
+
columns: ColumnDef<T>[];
|
|
10
|
+
propsColumns: ColumnsTable;
|
|
11
|
+
columnVisibility: VisibilityState;
|
|
12
|
+
expanded: ExpandedState;
|
|
13
|
+
columnPinning: ColumnPinningState;
|
|
14
|
+
originData: T[];
|
|
15
|
+
mergedFilterKeys: any;
|
|
16
|
+
setMergedFilterKeys: any;
|
|
17
|
+
isFullScreen: boolean;
|
|
18
|
+
triggerFilter: Dispatch<SetStateAction<any>>;
|
|
19
|
+
triggerSorter: Dispatch<SetStateAction<Sorter[]>>;
|
|
20
|
+
onContextMenu?: (data: T) => (event: any) => void;
|
|
21
|
+
};
|
|
22
|
+
declare const Grid: <RecordType extends object>(props: Props<RecordType>) => React.JSX.Element;
|
|
23
|
+
export default Grid;
|
|
@@ -0,0 +1,313 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
4
|
+
Object.defineProperty(exports, "__esModule", {
|
|
5
|
+
value: true
|
|
6
|
+
});
|
|
7
|
+
exports.default = void 0;
|
|
8
|
+
var _extends2 = _interopRequireDefault(require("@babel/runtime/helpers/extends"));
|
|
9
|
+
var _reactTable = require("@tanstack/react-table");
|
|
10
|
+
var _core = require("@dnd-kit/core");
|
|
11
|
+
var _modifiers = require("@dnd-kit/modifiers");
|
|
12
|
+
var _sortable = require("@dnd-kit/sortable");
|
|
13
|
+
var _pagination = _interopRequireDefault(require("rc-master-ui/es/pagination"));
|
|
14
|
+
var _becoxyIcons = require("becoxy-icons");
|
|
15
|
+
var _classnames = _interopRequireDefault(require("classnames"));
|
|
16
|
+
var _rcMasterUi = require("rc-master-ui");
|
|
17
|
+
var _react = _interopRequireDefault(require("react"));
|
|
18
|
+
var _ColumnsChoose = require("../ColumnsChoose");
|
|
19
|
+
var _TableContainer = _interopRequireDefault(require("../TableContainer"));
|
|
20
|
+
var _operator = require("../features/operator");
|
|
21
|
+
var _utils = require("../hook/utils");
|
|
22
|
+
// import { makeData } from "../default/makeData";
|
|
23
|
+
|
|
24
|
+
// import { flattenArray, getFixedFields, getInvisibleColumns, unFlattenData, updateOrInsert } from './hook/utils'
|
|
25
|
+
|
|
26
|
+
// import { faker } from '@faker-js/faker'
|
|
27
|
+
|
|
28
|
+
const Grid = props => {
|
|
29
|
+
const {
|
|
30
|
+
t,
|
|
31
|
+
id,
|
|
32
|
+
prefix,
|
|
33
|
+
dataSource,
|
|
34
|
+
originData,
|
|
35
|
+
columns,
|
|
36
|
+
propsColumns,
|
|
37
|
+
pagination,
|
|
38
|
+
expanded,
|
|
39
|
+
columnVisibility,
|
|
40
|
+
columnPinning,
|
|
41
|
+
selectionSettings,
|
|
42
|
+
rowSelected,
|
|
43
|
+
sortMultiple,
|
|
44
|
+
triggerSorter,
|
|
45
|
+
triggerFilter,
|
|
46
|
+
setMergedFilterKeys,
|
|
47
|
+
onSorter,
|
|
48
|
+
onFilter,
|
|
49
|
+
showToolbar,
|
|
50
|
+
isFullScreen,
|
|
51
|
+
fullScreen,
|
|
52
|
+
toolbarItems,
|
|
53
|
+
actionTemplate,
|
|
54
|
+
showColumnChoose,
|
|
55
|
+
groupColumns,
|
|
56
|
+
height,
|
|
57
|
+
...rest
|
|
58
|
+
} = props;
|
|
59
|
+
const bottomToolbarRef = _react.default.useRef(null);
|
|
60
|
+
const topToolbarRef = _react.default.useRef(null);
|
|
61
|
+
const [tableHeight, settableHeight] = _react.default.useState(0);
|
|
62
|
+
const [columnResizeMode] = _react.default.useState('onChange');
|
|
63
|
+
const [columnResizeDirection] = _react.default.useState('ltr');
|
|
64
|
+
const [paginationState, setPagination] = _react.default.useState({
|
|
65
|
+
pageIndex: pagination && pagination.currentPage ? pagination.currentPage - 1 : 0,
|
|
66
|
+
pageSize: pagination && pagination.pageSize ? pagination.pageSize : 20
|
|
67
|
+
});
|
|
68
|
+
const [rowSelection, setRowSelection] = _react.default.useState({});
|
|
69
|
+
const [grouping, setGrouping] = _react.default.useState([]);
|
|
70
|
+
const [columnSizing, setColumnSizing] = _react.default.useState({});
|
|
71
|
+
const [columnFilters, setColumnFilters] = _react.default.useState([]);
|
|
72
|
+
const [operator, setOperator] = _react.default.useState([]);
|
|
73
|
+
const [sorting, setSorting] = _react.default.useState([]);
|
|
74
|
+
const [columnOrder, setColumnOrder] = _react.default.useState(() => columns.map(c => c.id));
|
|
75
|
+
const [isSelectionChange, setIsSelectionChange] = _react.default.useState({
|
|
76
|
+
isChange: false,
|
|
77
|
+
type: '',
|
|
78
|
+
rowData: {}
|
|
79
|
+
});
|
|
80
|
+
const [sorterChange, setSorterChange] = _react.default.useState(false);
|
|
81
|
+
const [filterChange, setFilterChange] = _react.default.useState(false);
|
|
82
|
+
const table = (0, _reactTable.useReactTable)({
|
|
83
|
+
_features: [_operator.OperatorFeature],
|
|
84
|
+
data: dataSource,
|
|
85
|
+
columns: columns,
|
|
86
|
+
state: {
|
|
87
|
+
rowSelection,
|
|
88
|
+
expanded,
|
|
89
|
+
columnPinning,
|
|
90
|
+
columnVisibility,
|
|
91
|
+
pagination: pagination ? paginationState : undefined,
|
|
92
|
+
grouping,
|
|
93
|
+
columnSizing,
|
|
94
|
+
columnOrder,
|
|
95
|
+
columnFilters,
|
|
96
|
+
operator,
|
|
97
|
+
sorting
|
|
98
|
+
},
|
|
99
|
+
getCoreRowModel: (0, _reactTable.getCoreRowModel)(),
|
|
100
|
+
getRowId(originalRow) {
|
|
101
|
+
return originalRow.rowId;
|
|
102
|
+
},
|
|
103
|
+
getSubRows: row => row.children,
|
|
104
|
+
// RowSelection
|
|
105
|
+
enableSubRowSelection: selectionSettings && selectionSettings.mode === 'checkbox' && selectionSettings.type !== 'single',
|
|
106
|
+
enableMultiRowSelection: selectionSettings && selectionSettings.mode === 'checkbox' && selectionSettings.type !== 'single',
|
|
107
|
+
enableRowSelection: true,
|
|
108
|
+
onRowSelectionChange: setRowSelection,
|
|
109
|
+
// RowSelection
|
|
110
|
+
|
|
111
|
+
// ColumnSizing
|
|
112
|
+
columnResizeMode,
|
|
113
|
+
columnResizeDirection,
|
|
114
|
+
onColumnSizingChange: setColumnSizing,
|
|
115
|
+
// ColumnSizing
|
|
116
|
+
|
|
117
|
+
// ColumnSorting
|
|
118
|
+
// getSortedRowModel: getSortedRowModel(),
|
|
119
|
+
onSortingChange: setSorting,
|
|
120
|
+
enableMultiSort: sortMultiple,
|
|
121
|
+
isMultiSortEvent: () => sortMultiple ? true : false,
|
|
122
|
+
// ColumnSorting
|
|
123
|
+
|
|
124
|
+
onColumnFiltersChange: setColumnFilters,
|
|
125
|
+
onColumnOperatorChange: setOperator,
|
|
126
|
+
// getFilteredRowModel: getFilteredRowModel(),
|
|
127
|
+
|
|
128
|
+
onColumnOrderChange: setColumnOrder,
|
|
129
|
+
onGroupingChange: setGrouping,
|
|
130
|
+
getGroupedRowModel: (0, _reactTable.getGroupedRowModel)(),
|
|
131
|
+
// onExpandedChange: setExpanded,
|
|
132
|
+
getExpandedRowModel: (0, _reactTable.getExpandedRowModel)(),
|
|
133
|
+
getPaginationRowModel: pagination ? (0, _reactTable.getPaginationRowModel)() : undefined,
|
|
134
|
+
onPaginationChange: setPagination,
|
|
135
|
+
// onColumnVisibilityChange: setColumnVisibility,
|
|
136
|
+
// onColumnPinningChange,
|
|
137
|
+
|
|
138
|
+
debugTable: true
|
|
139
|
+
});
|
|
140
|
+
_react.default.useEffect(() => {
|
|
141
|
+
if (isSelectionChange.isChange) {
|
|
142
|
+
const aa = table.getState().rowSelection;
|
|
143
|
+
const dataTable = table.getRowModel().flatRows;
|
|
144
|
+
const ids = Object.keys(aa);
|
|
145
|
+
const ssss = dataTable.filter(it => ids.includes(it.id));
|
|
146
|
+
const rs = ssss.map(it => it.original);
|
|
147
|
+
rowSelected?.({
|
|
148
|
+
type: isSelectionChange.type,
|
|
149
|
+
rowData: isSelectionChange.rowData,
|
|
150
|
+
selected: rs
|
|
151
|
+
});
|
|
152
|
+
}
|
|
153
|
+
}, [isSelectionChange, rowSelected, rowSelection, table]);
|
|
154
|
+
_react.default.useEffect(() => {
|
|
155
|
+
if (sorterChange) {
|
|
156
|
+
const aa = table.getState().sorting;
|
|
157
|
+
const rs = aa.map(it => {
|
|
158
|
+
return {
|
|
159
|
+
columnKey: it.id,
|
|
160
|
+
field: it.id,
|
|
161
|
+
order: it.desc ? 'descend' : 'ascend'
|
|
162
|
+
};
|
|
163
|
+
});
|
|
164
|
+
if (onSorter) {
|
|
165
|
+
onSorter?.(rs);
|
|
166
|
+
} else {
|
|
167
|
+
triggerSorter(rs);
|
|
168
|
+
}
|
|
169
|
+
}
|
|
170
|
+
}, [onSorter, sorterChange, sorting, table, triggerSorter]);
|
|
171
|
+
_react.default.useEffect(() => {
|
|
172
|
+
if (filterChange) {
|
|
173
|
+
// const filterState = table.getState().columnFilters
|
|
174
|
+
const operatorState = table.getState().operator;
|
|
175
|
+
const merged = columnFilters.map(filter => {
|
|
176
|
+
const match = operatorState.find(op => op.id === filter.id);
|
|
177
|
+
const col = table.getVisibleFlatColumns().find(it => it.id === filter.id)?.columnDef.meta;
|
|
178
|
+
return {
|
|
179
|
+
field: filter.id,
|
|
180
|
+
key: filter.id,
|
|
181
|
+
column: col,
|
|
182
|
+
filteredKeys: filter.value,
|
|
183
|
+
operator: match ? match.operator : undefined
|
|
184
|
+
// ...(match && { operator: match.operator })
|
|
185
|
+
};
|
|
186
|
+
});
|
|
187
|
+
if (onFilter) {
|
|
188
|
+
onFilter?.((0, _utils.convertFilters)(merged));
|
|
189
|
+
} else {
|
|
190
|
+
triggerFilter((0, _utils.convertFilters)(merged));
|
|
191
|
+
const b = (0, _utils.filterDataByColumns)(originData, (0, _utils.convertFilters)(merged), [], []);
|
|
192
|
+
setMergedFilterKeys((0, _utils.getAllRowKey)(b));
|
|
193
|
+
}
|
|
194
|
+
}
|
|
195
|
+
}, [filterChange, onFilter, originData, setMergedFilterKeys, table, triggerFilter, columnFilters]);
|
|
196
|
+
_react.default.useEffect(() => {
|
|
197
|
+
const totalHeight = height;
|
|
198
|
+
if (totalHeight && topToolbarRef.current && bottomToolbarRef.current) {
|
|
199
|
+
settableHeight(totalHeight - topToolbarRef.current.offsetHeight - bottomToolbarRef.current.offsetHeight);
|
|
200
|
+
}
|
|
201
|
+
}, [id, columns, height]);
|
|
202
|
+
|
|
203
|
+
// reorder columns after drag & drop
|
|
204
|
+
function handleDragEnd(event) {
|
|
205
|
+
const {
|
|
206
|
+
active,
|
|
207
|
+
over
|
|
208
|
+
} = event;
|
|
209
|
+
if (active && over && active.id !== over.id) {
|
|
210
|
+
setColumnOrder(cols => {
|
|
211
|
+
const oldIndex = cols.indexOf(active.id);
|
|
212
|
+
const newIndex = cols.indexOf(over.id);
|
|
213
|
+
return (0, _sortable.arrayMove)(cols, oldIndex, newIndex); //this is just a splice util
|
|
214
|
+
});
|
|
215
|
+
}
|
|
216
|
+
}
|
|
217
|
+
const sensors = (0, _core.useSensors)((0, _core.useSensor)(_core.MouseSensor, {}), (0, _core.useSensor)(_core.TouchSensor, {}), (0, _core.useSensor)(_core.KeyboardSensor, {}));
|
|
218
|
+
return /*#__PURE__*/_react.default.createElement("div", {
|
|
219
|
+
className: `${prefix}-grid`,
|
|
220
|
+
style: {
|
|
221
|
+
height: height ?? undefined
|
|
222
|
+
}
|
|
223
|
+
}, (showToolbar !== false || fullScreen !== false) && /*#__PURE__*/_react.default.createElement("div", {
|
|
224
|
+
ref: topToolbarRef,
|
|
225
|
+
className: (0, _classnames.default)(`${prefix}-grid-top-toolbar`, {})
|
|
226
|
+
}, /*#__PURE__*/_react.default.createElement("div", {
|
|
227
|
+
style: {
|
|
228
|
+
display: 'flex',
|
|
229
|
+
justifyContent: 'space-between',
|
|
230
|
+
alignItems: 'center',
|
|
231
|
+
gap: '.75rem'
|
|
232
|
+
}
|
|
233
|
+
}, toolbarItems && toolbarItems?.length > 0 && /*#__PURE__*/_react.default.createElement("div", {
|
|
234
|
+
style: {
|
|
235
|
+
flex: 1,
|
|
236
|
+
overflow: 'hidden'
|
|
237
|
+
}
|
|
238
|
+
}, /*#__PURE__*/_react.default.createElement(_rcMasterUi.Toolbar, {
|
|
239
|
+
items: (toolbarItems ?? []).filter(it => it.position !== 'Bottom'),
|
|
240
|
+
mode: 'scroll'
|
|
241
|
+
})), fullScreen !== false && (isFullScreen ? /*#__PURE__*/_react.default.createElement(_becoxyIcons.Minimize, {
|
|
242
|
+
fontSize: 16
|
|
243
|
+
// onClick={() => handleFullScreen?.()}
|
|
244
|
+
,
|
|
245
|
+
"data-tooltip-id": "tooltip-icon",
|
|
246
|
+
"data-tooltip-content": t ? t('Minimized') : 'Minimized'
|
|
247
|
+
}) : /*#__PURE__*/_react.default.createElement(_becoxyIcons.Maximize, {
|
|
248
|
+
fontSize: 16
|
|
249
|
+
// onClick={() => handleFullScreen?.()}
|
|
250
|
+
,
|
|
251
|
+
"data-tooltip-id": "tooltip-icon",
|
|
252
|
+
"data-tooltip-content": t ? t('Full screen') : 'Full screen'
|
|
253
|
+
})), /*#__PURE__*/_react.default.createElement("div", {
|
|
254
|
+
style: {
|
|
255
|
+
display: 'flex',
|
|
256
|
+
justifyContent: 'space-between',
|
|
257
|
+
alignItems: 'center',
|
|
258
|
+
gap: '.75rem'
|
|
259
|
+
}
|
|
260
|
+
}, pagination && pagination.onChange && pagination?.position && pagination?.position[0] === 'topRight' && /*#__PURE__*/_react.default.createElement(_pagination.default, (0, _extends2.default)({
|
|
261
|
+
showSizeChanger: true,
|
|
262
|
+
responsive: true,
|
|
263
|
+
size: 'small',
|
|
264
|
+
rootClassName: 'top-pagination',
|
|
265
|
+
showTotal: (total, range) =>
|
|
266
|
+
// @ts-ignore
|
|
267
|
+
`${range[0]}-${range[1]} / ${total} ${t ? t(pagination?.locale?.items ?? 'items') : 'items'}`
|
|
268
|
+
}, pagination)), typeof actionTemplate === 'function' ? actionTemplate() : actionTemplate, showColumnChoose && /*#__PURE__*/_react.default.createElement(_ColumnsChoose.ColumnsChoose, {
|
|
269
|
+
columns: propsColumns,
|
|
270
|
+
t: t,
|
|
271
|
+
columnsGroup: groupColumns
|
|
272
|
+
// triggerChangeColumns={triggerChangeColumns}
|
|
273
|
+
})))), /*#__PURE__*/_react.default.createElement(_core.DndContext, {
|
|
274
|
+
collisionDetection: _core.closestCenter,
|
|
275
|
+
modifiers: [_modifiers.restrictToHorizontalAxis],
|
|
276
|
+
onDragEnd: handleDragEnd,
|
|
277
|
+
sensors: sensors
|
|
278
|
+
}, /*#__PURE__*/_react.default.createElement(_TableContainer.default, (0, _extends2.default)({}, rest, {
|
|
279
|
+
id: id,
|
|
280
|
+
table: table,
|
|
281
|
+
editAble: false,
|
|
282
|
+
dataSource: dataSource,
|
|
283
|
+
originData: originData,
|
|
284
|
+
prefix: prefix,
|
|
285
|
+
selectionSettings: selectionSettings,
|
|
286
|
+
setIsSelectionChange: setIsSelectionChange,
|
|
287
|
+
setSorterChange: setSorterChange,
|
|
288
|
+
setFilterChange: setFilterChange,
|
|
289
|
+
tableHeight: tableHeight
|
|
290
|
+
// setMergedFilterKeys={setMergedFilterKeys}
|
|
291
|
+
}))), /*#__PURE__*/_react.default.createElement("div", {
|
|
292
|
+
ref: bottomToolbarRef
|
|
293
|
+
}, pagination && /*#__PURE__*/_react.default.createElement(_pagination.default
|
|
294
|
+
// style={{padding: '0.75rem 1rem'}}
|
|
295
|
+
, {
|
|
296
|
+
rootClassName: 'pagination-template',
|
|
297
|
+
showSizeChanger: true,
|
|
298
|
+
responsive: true,
|
|
299
|
+
size: 'small',
|
|
300
|
+
total: pagination.total,
|
|
301
|
+
pageSize: paginationState.pageSize,
|
|
302
|
+
pageSizeOptions: [20, 50, 100, 1000, 10000],
|
|
303
|
+
onChange: (page, pageSize) => {
|
|
304
|
+
if (pagination.onChange) {
|
|
305
|
+
pagination.onChange(page, pageSize);
|
|
306
|
+
} else {
|
|
307
|
+
table.setPageIndex(page - 1);
|
|
308
|
+
table.setPageSize(pageSize);
|
|
309
|
+
}
|
|
310
|
+
}
|
|
311
|
+
})));
|
|
312
|
+
};
|
|
313
|
+
var _default = exports.default = Grid;
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import type { ColumnDef, ColumnPinningState, ExpandedState, VisibilityState } from '@tanstack/react-table';
|
|
2
|
+
import type { ColumnsTable, Sorter, TableProps } from '../type';
|
|
3
|
+
import type { Dispatch, SetStateAction } from 'react';
|
|
4
|
+
import React from 'react';
|
|
5
|
+
type Props<T> = Omit<TableProps<T>, 'columns'> & {
|
|
6
|
+
id: string;
|
|
7
|
+
rowKey: string;
|
|
8
|
+
prefix: string;
|
|
9
|
+
columns: ColumnDef<T>[];
|
|
10
|
+
propsColumns: ColumnsTable;
|
|
11
|
+
columnVisibility: VisibilityState;
|
|
12
|
+
expanded: ExpandedState;
|
|
13
|
+
columnPinning: ColumnPinningState;
|
|
14
|
+
originData: T[];
|
|
15
|
+
mergedFilterKeys: any;
|
|
16
|
+
setMergedFilterKeys: any;
|
|
17
|
+
isFullScreen: boolean;
|
|
18
|
+
triggerFilter: Dispatch<SetStateAction<any>>;
|
|
19
|
+
triggerSorter: Dispatch<SetStateAction<Sorter[]>>;
|
|
20
|
+
onContextMenu?: (data: T) => (event: any) => void;
|
|
21
|
+
};
|
|
22
|
+
declare const GridEdit: <RecordType extends object>(props: Props<RecordType>) => React.JSX.Element;
|
|
23
|
+
export default GridEdit;
|
|
@@ -0,0 +1,284 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
4
|
+
Object.defineProperty(exports, "__esModule", {
|
|
5
|
+
value: true
|
|
6
|
+
});
|
|
7
|
+
exports.default = void 0;
|
|
8
|
+
var _extends2 = _interopRequireDefault(require("@babel/runtime/helpers/extends"));
|
|
9
|
+
var _reactTable = require("@tanstack/react-table");
|
|
10
|
+
var _core = require("@dnd-kit/core");
|
|
11
|
+
var _modifiers = require("@dnd-kit/modifiers");
|
|
12
|
+
var _sortable = require("@dnd-kit/sortable");
|
|
13
|
+
var _react = _interopRequireDefault(require("react"));
|
|
14
|
+
var _operator = require("../features/operator");
|
|
15
|
+
var _utils = require("../hook/utils");
|
|
16
|
+
var _TableContainerEdit = _interopRequireDefault(require("../TableContainerEdit"));
|
|
17
|
+
// import { makeData } from "../default/makeData";
|
|
18
|
+
|
|
19
|
+
// import { flattenArray, getFixedFields, getInvisibleColumns, unFlattenData, updateOrInsert } from './hook/utils'
|
|
20
|
+
|
|
21
|
+
// import { faker } from '@faker-js/faker'
|
|
22
|
+
|
|
23
|
+
const GridEdit = props => {
|
|
24
|
+
const {
|
|
25
|
+
t,
|
|
26
|
+
id,
|
|
27
|
+
prefix,
|
|
28
|
+
dataSource,
|
|
29
|
+
originData,
|
|
30
|
+
columns,
|
|
31
|
+
propsColumns,
|
|
32
|
+
pagination,
|
|
33
|
+
expanded,
|
|
34
|
+
columnVisibility,
|
|
35
|
+
columnPinning,
|
|
36
|
+
selectionSettings,
|
|
37
|
+
rowSelected,
|
|
38
|
+
sortMultiple,
|
|
39
|
+
triggerSorter,
|
|
40
|
+
triggerFilter,
|
|
41
|
+
setMergedFilterKeys,
|
|
42
|
+
onSorter,
|
|
43
|
+
onFilter,
|
|
44
|
+
// showToolbar,
|
|
45
|
+
// isFullScreen,
|
|
46
|
+
// fullScreen,
|
|
47
|
+
// toolbarItems,
|
|
48
|
+
actionTemplate,
|
|
49
|
+
// showColumnChoose,
|
|
50
|
+
groupColumns,
|
|
51
|
+
height,
|
|
52
|
+
onDataChange,
|
|
53
|
+
onCellPaste,
|
|
54
|
+
...rest
|
|
55
|
+
} = props;
|
|
56
|
+
const ref = _react.default.useRef(null);
|
|
57
|
+
|
|
58
|
+
// const bottomToolbarRef = React.useRef<HTMLDivElement>(null)
|
|
59
|
+
// const topToolbarRef: any = React.useRef<HTMLDivElement>(null)
|
|
60
|
+
|
|
61
|
+
const [columnResizeMode] = _react.default.useState('onChange');
|
|
62
|
+
const [columnResizeDirection] = _react.default.useState('ltr');
|
|
63
|
+
const [paginationState, setPagination] = _react.default.useState({
|
|
64
|
+
pageIndex: pagination && pagination.currentPage ? pagination.currentPage - 1 : 0,
|
|
65
|
+
pageSize: pagination && pagination.pageSize ? pagination.pageSize : 20
|
|
66
|
+
});
|
|
67
|
+
const [rowSelection, setRowSelection] = _react.default.useState({});
|
|
68
|
+
const [grouping, setGrouping] = _react.default.useState([]);
|
|
69
|
+
const [columnSizing, setColumnSizing] = _react.default.useState({});
|
|
70
|
+
const [columnFilters, setColumnFilters] = _react.default.useState([]);
|
|
71
|
+
const [operator, setOperator] = _react.default.useState([]);
|
|
72
|
+
const [sorting, setSorting] = _react.default.useState([]);
|
|
73
|
+
const [columnOrder, setColumnOrder] = _react.default.useState(() => columns.map(c => c.id));
|
|
74
|
+
const [isSelectionChange, setIsSelectionChange] = _react.default.useState({
|
|
75
|
+
isChange: false,
|
|
76
|
+
type: '',
|
|
77
|
+
rowData: {}
|
|
78
|
+
});
|
|
79
|
+
const [sorterChange, setSorterChange] = _react.default.useState(false);
|
|
80
|
+
const [filterChange, setFilterChange] = _react.default.useState(false);
|
|
81
|
+
const table = (0, _reactTable.useReactTable)({
|
|
82
|
+
_features: [_operator.OperatorFeature],
|
|
83
|
+
data: dataSource,
|
|
84
|
+
columns: columns,
|
|
85
|
+
state: {
|
|
86
|
+
rowSelection,
|
|
87
|
+
expanded,
|
|
88
|
+
columnPinning,
|
|
89
|
+
columnVisibility,
|
|
90
|
+
pagination: pagination ? paginationState : undefined,
|
|
91
|
+
grouping,
|
|
92
|
+
columnSizing,
|
|
93
|
+
columnOrder,
|
|
94
|
+
columnFilters,
|
|
95
|
+
operator,
|
|
96
|
+
sorting
|
|
97
|
+
},
|
|
98
|
+
getCoreRowModel: (0, _reactTable.getCoreRowModel)(),
|
|
99
|
+
getRowId(originalRow) {
|
|
100
|
+
return originalRow.rowId;
|
|
101
|
+
},
|
|
102
|
+
getSubRows: row => row.children,
|
|
103
|
+
// RowSelection
|
|
104
|
+
enableSubRowSelection: selectionSettings && selectionSettings.mode === 'checkbox' && selectionSettings.type !== 'single',
|
|
105
|
+
enableMultiRowSelection: selectionSettings && selectionSettings.mode === 'checkbox' && selectionSettings.type !== 'single',
|
|
106
|
+
enableRowSelection: true,
|
|
107
|
+
onRowSelectionChange: setRowSelection,
|
|
108
|
+
// RowSelection
|
|
109
|
+
|
|
110
|
+
// ColumnSizing
|
|
111
|
+
columnResizeMode,
|
|
112
|
+
columnResizeDirection,
|
|
113
|
+
onColumnSizingChange: setColumnSizing,
|
|
114
|
+
// ColumnSizing
|
|
115
|
+
|
|
116
|
+
// ColumnSorting
|
|
117
|
+
// getSortedRowModel: getSortedRowModel(),
|
|
118
|
+
onSortingChange: setSorting,
|
|
119
|
+
enableMultiSort: sortMultiple,
|
|
120
|
+
isMultiSortEvent: () => sortMultiple ? true : false,
|
|
121
|
+
// ColumnSorting
|
|
122
|
+
|
|
123
|
+
onColumnFiltersChange: setColumnFilters,
|
|
124
|
+
onColumnOperatorChange: setOperator,
|
|
125
|
+
// getFilteredRowModel: getFilteredRowModel(),
|
|
126
|
+
|
|
127
|
+
onColumnOrderChange: setColumnOrder,
|
|
128
|
+
onGroupingChange: setGrouping,
|
|
129
|
+
getGroupedRowModel: (0, _reactTable.getGroupedRowModel)(),
|
|
130
|
+
// onExpandedChange: setExpanded,
|
|
131
|
+
getExpandedRowModel: (0, _reactTable.getExpandedRowModel)(),
|
|
132
|
+
getPaginationRowModel: pagination ? (0, _reactTable.getPaginationRowModel)() : undefined,
|
|
133
|
+
onPaginationChange: setPagination,
|
|
134
|
+
// onColumnVisibilityChange: setColumnVisibility,
|
|
135
|
+
// onColumnPinningChange,
|
|
136
|
+
|
|
137
|
+
debugTable: true
|
|
138
|
+
});
|
|
139
|
+
_react.default.useEffect(() => {
|
|
140
|
+
if (isSelectionChange.isChange) {
|
|
141
|
+
const aa = table.getState().rowSelection;
|
|
142
|
+
const dataTable = table.getRowModel().flatRows;
|
|
143
|
+
const ids = Object.keys(aa);
|
|
144
|
+
const ssss = dataTable.filter(it => ids.includes(it.id));
|
|
145
|
+
const rs = ssss.map(it => it.original);
|
|
146
|
+
rowSelected?.({
|
|
147
|
+
type: isSelectionChange.type,
|
|
148
|
+
rowData: isSelectionChange.rowData,
|
|
149
|
+
selected: rs
|
|
150
|
+
});
|
|
151
|
+
}
|
|
152
|
+
}, [isSelectionChange, rowSelected, rowSelection, table]);
|
|
153
|
+
_react.default.useEffect(() => {
|
|
154
|
+
if (sorterChange) {
|
|
155
|
+
const aa = table.getState().sorting;
|
|
156
|
+
const rs = aa.map(it => {
|
|
157
|
+
return {
|
|
158
|
+
columnKey: it.id,
|
|
159
|
+
field: it.id,
|
|
160
|
+
order: it.desc ? 'descend' : 'ascend'
|
|
161
|
+
};
|
|
162
|
+
});
|
|
163
|
+
if (onSorter) {
|
|
164
|
+
onSorter?.(rs);
|
|
165
|
+
} else {
|
|
166
|
+
triggerSorter(rs);
|
|
167
|
+
}
|
|
168
|
+
}
|
|
169
|
+
}, [onSorter, sorterChange, sorting, table, triggerSorter]);
|
|
170
|
+
_react.default.useEffect(() => {
|
|
171
|
+
if (filterChange) {
|
|
172
|
+
// const filterState = table.getState().columnFilters
|
|
173
|
+
const operatorState = table.getState().operator;
|
|
174
|
+
const merged = columnFilters.map(filter => {
|
|
175
|
+
const match = operatorState.find(op => op.id === filter.id);
|
|
176
|
+
const col = table.getVisibleFlatColumns().find(it => it.id === filter.id)?.columnDef.meta;
|
|
177
|
+
return {
|
|
178
|
+
field: filter.id,
|
|
179
|
+
key: filter.id,
|
|
180
|
+
column: col,
|
|
181
|
+
filteredKeys: filter.value,
|
|
182
|
+
operator: match ? match.operator : undefined
|
|
183
|
+
// ...(match && { operator: match.operator })
|
|
184
|
+
};
|
|
185
|
+
});
|
|
186
|
+
if (onFilter) {
|
|
187
|
+
onFilter?.((0, _utils.convertFilters)(merged));
|
|
188
|
+
} else {
|
|
189
|
+
triggerFilter((0, _utils.convertFilters)(merged));
|
|
190
|
+
const b = (0, _utils.filterDataByColumns)(originData, (0, _utils.convertFilters)(merged), [], []);
|
|
191
|
+
setMergedFilterKeys((0, _utils.getAllRowKey)(b));
|
|
192
|
+
}
|
|
193
|
+
}
|
|
194
|
+
}, [filterChange, onFilter, originData, setMergedFilterKeys, table, triggerFilter, columnFilters]);
|
|
195
|
+
|
|
196
|
+
// React.useEffect(() => {
|
|
197
|
+
// const totalHeight = height
|
|
198
|
+
|
|
199
|
+
// if (totalHeight && topToolbarRef.current && bottomToolbarRef.current) {
|
|
200
|
+
// settableHeight(totalHeight - topToolbarRef.current.offsetHeight - bottomToolbarRef.current.offsetHeight)
|
|
201
|
+
// }
|
|
202
|
+
// }, [id, columns, height])
|
|
203
|
+
|
|
204
|
+
// reorder columns after drag & drop
|
|
205
|
+
function handleDragEnd(event) {
|
|
206
|
+
const {
|
|
207
|
+
active,
|
|
208
|
+
over
|
|
209
|
+
} = event;
|
|
210
|
+
if (active && over && active.id !== over.id) {
|
|
211
|
+
setColumnOrder(cols => {
|
|
212
|
+
const oldIndex = cols.indexOf(active.id);
|
|
213
|
+
const newIndex = cols.indexOf(over.id);
|
|
214
|
+
return (0, _sortable.arrayMove)(cols, oldIndex, newIndex); //this is just a splice util
|
|
215
|
+
});
|
|
216
|
+
}
|
|
217
|
+
}
|
|
218
|
+
const sensors = (0, _core.useSensors)((0, _core.useSensor)(_core.MouseSensor, {}), (0, _core.useSensor)(_core.TouchSensor, {}), (0, _core.useSensor)(_core.KeyboardSensor, {}));
|
|
219
|
+
const triggerChangeData = newData => {
|
|
220
|
+
onDataChange?.(newData);
|
|
221
|
+
};
|
|
222
|
+
const triggerPaste = (pastedRows, pastedColumnsArray, newData, copyRows) => {
|
|
223
|
+
const handlePasteCallback = callbackData => {
|
|
224
|
+
const rsFilterData = (0, _utils.updateOrInsert)((0, _utils.flattenArray)([...dataSource]), callbackData);
|
|
225
|
+
const rs = (0, _utils.unFlattenData)(rsFilterData);
|
|
226
|
+
triggerChangeData(rs);
|
|
227
|
+
};
|
|
228
|
+
if (onCellPaste && onCellPaste.onPasted) {
|
|
229
|
+
if (onCellPaste.onPasted.length > 1) {
|
|
230
|
+
// có callback
|
|
231
|
+
onCellPaste.onPasted({
|
|
232
|
+
pasteData: pastedRows,
|
|
233
|
+
copyRows,
|
|
234
|
+
type: 'onPaste',
|
|
235
|
+
data: dataSource,
|
|
236
|
+
pastedColumns: pastedColumnsArray
|
|
237
|
+
}, handlePasteCallback);
|
|
238
|
+
} else {
|
|
239
|
+
// không có callback
|
|
240
|
+
onCellPaste.onPasted({
|
|
241
|
+
pasteData: pastedRows,
|
|
242
|
+
type: 'onPaste',
|
|
243
|
+
copyRows,
|
|
244
|
+
data: dataSource,
|
|
245
|
+
pastedColumns: pastedColumnsArray
|
|
246
|
+
}, handlePasteCallback);
|
|
247
|
+
triggerChangeData(newData);
|
|
248
|
+
}
|
|
249
|
+
} else {
|
|
250
|
+
triggerChangeData(newData);
|
|
251
|
+
}
|
|
252
|
+
};
|
|
253
|
+
return /*#__PURE__*/_react.default.createElement("div", {
|
|
254
|
+
className: `${prefix}-grid`,
|
|
255
|
+
style: {
|
|
256
|
+
height: height ?? undefined
|
|
257
|
+
},
|
|
258
|
+
ref: ref
|
|
259
|
+
}, /*#__PURE__*/_react.default.createElement(_core.DndContext, {
|
|
260
|
+
collisionDetection: _core.closestCenter,
|
|
261
|
+
modifiers: [_modifiers.restrictToHorizontalAxis],
|
|
262
|
+
onDragEnd: handleDragEnd,
|
|
263
|
+
sensors: sensors
|
|
264
|
+
}, /*#__PURE__*/_react.default.createElement(_TableContainerEdit.default, (0, _extends2.default)({}, rest, {
|
|
265
|
+
id: id,
|
|
266
|
+
table: table,
|
|
267
|
+
editAble: true,
|
|
268
|
+
dataSource: dataSource,
|
|
269
|
+
originData: originData,
|
|
270
|
+
prefix: prefix,
|
|
271
|
+
selectionSettings: selectionSettings,
|
|
272
|
+
setIsSelectionChange: setIsSelectionChange,
|
|
273
|
+
setSorterChange: setSorterChange,
|
|
274
|
+
setFilterChange: setFilterChange,
|
|
275
|
+
height: height,
|
|
276
|
+
expanded: expanded,
|
|
277
|
+
pagination: pagination,
|
|
278
|
+
setExpanded: () => {},
|
|
279
|
+
setMergedFilterKeys: setMergedFilterKeys,
|
|
280
|
+
triggerChangeData: triggerChangeData,
|
|
281
|
+
triggerPaste: triggerPaste
|
|
282
|
+
}))));
|
|
283
|
+
};
|
|
284
|
+
var _default = exports.default = GridEdit;
|