es-grid-template 1.4.0 → 1.4.2
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/EditableCell.js +46 -15
- package/es/grid-component/InternalTable.d.ts +1 -0
- package/es/grid-component/InternalTable.js +469 -113
- package/es/grid-component/TableGrid.js +46 -48
- package/es/grid-component/hooks/columns/index.d.ts +1 -1
- package/es/grid-component/hooks/columns/index.js +3 -13
- package/es/grid-component/hooks/useColumns.js +5 -2
- package/es/grid-component/hooks/utils.d.ts +17 -2
- package/es/grid-component/hooks/utils.js +24 -5
- package/es/grid-component/styles.scss +1186 -1170
- package/es/grid-component/table/Grid.d.ts +1 -0
- package/es/grid-component/table/GridEdit.d.ts +1 -0
- package/es/grid-component/table/GridEdit.js +190 -140
- package/es/grid-component/table/Group.d.ts +1 -0
- package/es/grid-component/type.d.ts +7 -2
- package/es/grid-component/useContext.d.ts +1 -0
- package/lib/grid-component/EditableCell.js +46 -15
- package/lib/grid-component/InternalTable.d.ts +1 -0
- package/lib/grid-component/InternalTable.js +469 -102
- package/lib/grid-component/TableGrid.js +45 -47
- package/lib/grid-component/hooks/columns/index.d.ts +1 -1
- package/lib/grid-component/hooks/columns/index.js +5 -15
- package/lib/grid-component/hooks/useColumns.js +4 -1
- package/lib/grid-component/hooks/utils.d.ts +17 -2
- package/lib/grid-component/hooks/utils.js +26 -6
- package/lib/grid-component/styles.scss +1186 -1170
- package/lib/grid-component/table/Grid.d.ts +1 -0
- package/lib/grid-component/table/GridEdit.d.ts +1 -0
- package/lib/grid-component/table/GridEdit.js +189 -139
- package/lib/grid-component/table/Group.d.ts +1 -0
- package/lib/grid-component/type.d.ts +7 -2
- package/lib/grid-component/useContext.d.ts +1 -0
- package/package.json +5 -5
|
@@ -4,10 +4,9 @@ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefau
|
|
|
4
4
|
Object.defineProperty(exports, "__esModule", {
|
|
5
5
|
value: true
|
|
6
6
|
});
|
|
7
|
-
exports.default = void 0;
|
|
7
|
+
exports.default = exports.SELECTION_COLUMN = void 0;
|
|
8
8
|
var _extends2 = _interopRequireDefault(require("@babel/runtime/helpers/extends"));
|
|
9
9
|
var _react = _interopRequireWildcard(require("react"));
|
|
10
|
-
var _reactResizable = require("react-resizable");
|
|
11
10
|
require("react-resizable/css/styles.css");
|
|
12
11
|
var _customParseFormat = _interopRequireDefault(require("dayjs/plugin/customParseFormat"));
|
|
13
12
|
var _hooks = require("./hooks");
|
|
@@ -18,27 +17,79 @@ var _GridEdit = _interopRequireDefault(require("./table/GridEdit"));
|
|
|
18
17
|
var _Grid = _interopRequireDefault(require("./table/Grid"));
|
|
19
18
|
var _en_US = _interopRequireDefault(require("rc-master-ui/es/date-picker/locale/en_US"));
|
|
20
19
|
var _vi_VN = _interopRequireDefault(require("rc-master-ui/es/date-picker/locale/vi_VN"));
|
|
21
|
-
var _useColumns = _interopRequireDefault(require("./hooks/useColumns"));
|
|
22
20
|
require("./styles.scss");
|
|
23
21
|
var _columns = require("./hooks/columns");
|
|
24
22
|
var _Group = _interopRequireDefault(require("./table/Group"));
|
|
25
23
|
var _sweetalert = _interopRequireDefault(require("sweetalert2"));
|
|
26
24
|
var _sweetalert2ReactContent = _interopRequireDefault(require("sweetalert2-react-content"));
|
|
27
25
|
var _reactTooltip = require("react-tooltip");
|
|
26
|
+
var _classnames = _interopRequireDefault(require("classnames"));
|
|
27
|
+
var _HeaderContent = _interopRequireDefault(require("./hooks/content/HeaderContent"));
|
|
28
|
+
var _becoxyIcons = require("becoxy-icons");
|
|
29
|
+
var _rcMasterUi = require("rc-master-ui");
|
|
30
|
+
var _antd = require("antd");
|
|
31
|
+
var _icons = require("@ant-design/icons");
|
|
32
|
+
var _modifiers = require("@dnd-kit/modifiers");
|
|
33
|
+
var _core = require("@dnd-kit/core");
|
|
34
|
+
var _sortable = require("@dnd-kit/sortable");
|
|
35
|
+
var _reactResizable = require("react-resizable");
|
|
28
36
|
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); }
|
|
29
37
|
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; }
|
|
30
|
-
|
|
31
|
-
const MySwal = (0, _sweetalert2ReactContent.default)(_sweetalert.default);
|
|
38
|
+
// import {Resizable} from "react-resizable";
|
|
32
39
|
|
|
33
|
-
//
|
|
34
|
-
// const DESCEND = 'descend';
|
|
40
|
+
// import useColumns from "./hooks/useColumns";
|
|
35
41
|
|
|
42
|
+
// import {CSS} from "@dnd-kit/utilities";
|
|
43
|
+
|
|
44
|
+
_dayjs.default.extend(_customParseFormat.default);
|
|
45
|
+
const MySwal = (0, _sweetalert2ReactContent.default)(_sweetalert.default);
|
|
46
|
+
const ASCEND = 'ascend';
|
|
47
|
+
const DESCEND = 'descend';
|
|
48
|
+
const SELECTION_COLUMN = exports.SELECTION_COLUMN = {};
|
|
49
|
+
const dragActiveStyle = (dragState, id) => {
|
|
50
|
+
const {
|
|
51
|
+
active,
|
|
52
|
+
over,
|
|
53
|
+
direction
|
|
54
|
+
} = dragState;
|
|
55
|
+
// drag active style
|
|
56
|
+
let style = {};
|
|
57
|
+
if (active && active === id) {
|
|
58
|
+
style = {
|
|
59
|
+
backgroundColor: '#c0c0c0',
|
|
60
|
+
opacity: 0.3
|
|
61
|
+
};
|
|
62
|
+
}
|
|
63
|
+
// dragover dashed style
|
|
64
|
+
else if (over && id === over && active !== over) {
|
|
65
|
+
style = direction === 'right' ? {
|
|
66
|
+
borderRight: '1px dashed gray'
|
|
67
|
+
} : {
|
|
68
|
+
borderLeft: '1px dashed gray'
|
|
69
|
+
};
|
|
70
|
+
}
|
|
71
|
+
return style;
|
|
72
|
+
};
|
|
73
|
+
const DragIndexContext = /*#__PURE__*/(0, _react.createContext)({
|
|
74
|
+
active: -1,
|
|
75
|
+
over: -1
|
|
76
|
+
});
|
|
36
77
|
const ResizableTitle = props => {
|
|
37
78
|
const {
|
|
38
79
|
onResize,
|
|
39
80
|
width,
|
|
40
81
|
...restProps
|
|
41
82
|
} = props;
|
|
83
|
+
const dragState = (0, _react.useContext)(DragIndexContext);
|
|
84
|
+
|
|
85
|
+
// const { attributes, listeners, setNodeRef, isDragging } = useSortable({ id: props.id });
|
|
86
|
+
|
|
87
|
+
const style = {
|
|
88
|
+
...props.style,
|
|
89
|
+
// cursor: 'move',
|
|
90
|
+
// ...(isDragging ? { position: 'relative', zIndex: 9999, userSelect: 'none' } : {}),
|
|
91
|
+
...dragActiveStyle(dragState, props.id)
|
|
92
|
+
};
|
|
42
93
|
if (!width) {
|
|
43
94
|
return /*#__PURE__*/_react.default.createElement("th", restProps);
|
|
44
95
|
}
|
|
@@ -58,9 +109,47 @@ const ResizableTitle = props => {
|
|
|
58
109
|
draggableOpts: {
|
|
59
110
|
enableUserSelectHack: false
|
|
60
111
|
}
|
|
61
|
-
}, /*#__PURE__*/_react.default.createElement("th", restProps
|
|
112
|
+
}, /*#__PURE__*/_react.default.createElement("th", (0, _extends2.default)({}, restProps, {
|
|
113
|
+
style: style
|
|
114
|
+
})))
|
|
62
115
|
);
|
|
63
116
|
};
|
|
117
|
+
const TableBodyCell = props => {
|
|
118
|
+
const dragState = (0, _react.useContext)(DragIndexContext);
|
|
119
|
+
return /*#__PURE__*/_react.default.createElement("div", (0, _extends2.default)({}, props, {
|
|
120
|
+
style: {
|
|
121
|
+
...props.style,
|
|
122
|
+
...dragActiveStyle(dragState, props.id)
|
|
123
|
+
}
|
|
124
|
+
}));
|
|
125
|
+
};
|
|
126
|
+
const SortableHeaderCell = ({
|
|
127
|
+
children,
|
|
128
|
+
columnKey
|
|
129
|
+
}) => {
|
|
130
|
+
const {
|
|
131
|
+
attributes,
|
|
132
|
+
listeners,
|
|
133
|
+
setNodeRef,
|
|
134
|
+
isDragging
|
|
135
|
+
} = (0, _sortable.useSortable)({
|
|
136
|
+
id: columnKey
|
|
137
|
+
});
|
|
138
|
+
const style = {
|
|
139
|
+
// ...props.style,
|
|
140
|
+
cursor: 'move',
|
|
141
|
+
...(isDragging ? {
|
|
142
|
+
position: 'relative',
|
|
143
|
+
zIndex: 9999,
|
|
144
|
+
userSelect: 'none'
|
|
145
|
+
} : {})
|
|
146
|
+
// ...dragActiveStyle(dragState, props.id),
|
|
147
|
+
};
|
|
148
|
+
return /*#__PURE__*/_react.default.createElement("div", (0, _extends2.default)({
|
|
149
|
+
ref: setNodeRef,
|
|
150
|
+
style: style
|
|
151
|
+
}, attributes, listeners), children);
|
|
152
|
+
};
|
|
64
153
|
const InternalTable = props => {
|
|
65
154
|
const {
|
|
66
155
|
t,
|
|
@@ -89,11 +178,12 @@ const InternalTable = props => {
|
|
|
89
178
|
groupColumns,
|
|
90
179
|
commandClick,
|
|
91
180
|
commandSettings,
|
|
181
|
+
pagination,
|
|
92
182
|
...rest
|
|
93
183
|
} = props;
|
|
94
184
|
const rowKey = _react.default.useMemo(() => {
|
|
95
|
-
return
|
|
96
|
-
}, [
|
|
185
|
+
return propRowKey ?? 'rowId';
|
|
186
|
+
}, [propRowKey]);
|
|
97
187
|
const local = lang && lang === 'en' ? _en_US.default : _vi_VN.default;
|
|
98
188
|
const buddhistLocale = {
|
|
99
189
|
...local,
|
|
@@ -106,32 +196,19 @@ const InternalTable = props => {
|
|
|
106
196
|
// const [isFilter, setIsFilter] = React.useState<boolean>(false);
|
|
107
197
|
// const [cellTooltip, seCellTooltip] = React.useState<any>(undefined);
|
|
108
198
|
|
|
109
|
-
const
|
|
110
|
-
|
|
111
|
-
|
|
199
|
+
const [dragIndex, setDragIndex] = (0, _react.useState)({
|
|
200
|
+
active: -1,
|
|
201
|
+
over: -1
|
|
202
|
+
});
|
|
203
|
+
const [tooltipContent, setTooltipContent] = (0, _react.useState)('');
|
|
204
|
+
const mergedData = _react.default.useMemo(() => {
|
|
112
205
|
return (0, _hooks.addRowIdArray)(dataSource);
|
|
113
|
-
// return dataSource
|
|
114
206
|
}, [dataSource]);
|
|
115
207
|
const [columns, setColumns] = _react.default.useState([]);
|
|
116
208
|
const tableRef = _react.default.useRef(null);
|
|
117
209
|
_react.default.useEffect(() => {
|
|
118
210
|
setColumns(propsColumns);
|
|
119
211
|
}, [propsColumns]);
|
|
120
|
-
// }, [!!propsColumns.length && !!propsColumns])
|
|
121
|
-
|
|
122
|
-
// const [data, setData] = useState<RecordType[]>([]);
|
|
123
|
-
|
|
124
|
-
// const [isManualUpdate, setIsManualUpdate] = useState(false);
|
|
125
|
-
|
|
126
|
-
// useEffect(() => {
|
|
127
|
-
// if (!isManualUpdate) {
|
|
128
|
-
// const mergedData = addRowIdArray(dataSource)
|
|
129
|
-
//
|
|
130
|
-
// setData(mergedData || []);
|
|
131
|
-
// }
|
|
132
|
-
// setIsManualUpdate(false);
|
|
133
|
-
// }, [dataSource, isManualUpdate])
|
|
134
|
-
|
|
135
212
|
const handleResize = column => (e, {
|
|
136
213
|
size
|
|
137
214
|
}) => {
|
|
@@ -152,31 +229,287 @@ const InternalTable = props => {
|
|
|
152
229
|
return record => record?.[rowKey];
|
|
153
230
|
}, [rowKey]);
|
|
154
231
|
|
|
155
|
-
// const
|
|
156
|
-
//
|
|
157
|
-
//
|
|
232
|
+
// const [transformSelectionColumns] = useColumns<RecordType>(
|
|
233
|
+
// {
|
|
234
|
+
// locale,
|
|
235
|
+
// t,
|
|
236
|
+
// rowKey,
|
|
237
|
+
// // dataSource: mergerdData,
|
|
238
|
+
// dataSource,
|
|
239
|
+
// buddhistLocale,
|
|
240
|
+
// dataSourceFilter: propDataSourceFilter,
|
|
241
|
+
// format,
|
|
242
|
+
// sortMultiple,
|
|
243
|
+
// groupAble,
|
|
244
|
+
// groupSetting,
|
|
245
|
+
// groupColumns,
|
|
246
|
+
// handleResize,
|
|
247
|
+
// // onMouseHover
|
|
248
|
+
// },
|
|
249
|
+
// );
|
|
158
250
|
|
|
159
|
-
const
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
rowKey,
|
|
163
|
-
// dataSource: mergerdData,
|
|
164
|
-
dataSource,
|
|
165
|
-
buddhistLocale,
|
|
166
|
-
dataSourceFilter: propDataSourceFilter,
|
|
167
|
-
format,
|
|
168
|
-
sortMultiple,
|
|
169
|
-
groupAble,
|
|
170
|
-
groupSetting,
|
|
171
|
-
groupColumns,
|
|
172
|
-
handleResize
|
|
173
|
-
// onMouseHover
|
|
174
|
-
});
|
|
175
|
-
const mergedColumns = _react.default.useMemo(() => {
|
|
176
|
-
return transformSelectionColumns(columns);
|
|
177
|
-
}, [columns, transformSelectionColumns]);
|
|
251
|
+
// const mergedColumns: any = React.useMemo(() => {
|
|
252
|
+
// return transformSelectionColumns(columns)
|
|
253
|
+
// }, [columns, transformSelectionColumns])
|
|
178
254
|
|
|
179
|
-
|
|
255
|
+
const firstNonGroupColumn = (0, _columns.flatColumns2)(columns).find(col => col.field && col.field !== '#' && !groupColumns?.includes(col.field) && col.hidden !== true);
|
|
256
|
+
const nonGroupColumns = (0, _columns.flatColumns2)(columns).filter(col => col.field && col.field !== '#' && !groupColumns?.includes(col.field) && col.hidden !== true);
|
|
257
|
+
const getColumnSearchProps = (0, _react.useCallback)(column => ({
|
|
258
|
+
filterDropdown: ({
|
|
259
|
+
setSelectedKeys,
|
|
260
|
+
selectedKeys,
|
|
261
|
+
confirm,
|
|
262
|
+
setOperatorKey,
|
|
263
|
+
operatorKey,
|
|
264
|
+
visible,
|
|
265
|
+
searchValue,
|
|
266
|
+
setSearchValue
|
|
267
|
+
}) => {
|
|
268
|
+
const type = (0, _hooks.getTypeFilter)(column);
|
|
269
|
+
const operatorOptions = type === ('Checkbox' || 'Dropdown' || 'DropTree' || 'CheckboxDropdown') ? _hooks.booleanOperator : !type || type === 'Text' ? _hooks.stringOperator : _hooks.numberOperator;
|
|
270
|
+
return /*#__PURE__*/_react.default.createElement("div", {
|
|
271
|
+
style: {
|
|
272
|
+
padding: 8,
|
|
273
|
+
minWidth: 275
|
|
274
|
+
},
|
|
275
|
+
onKeyDown: e => e.stopPropagation()
|
|
276
|
+
}, column?.showOperator !== false && column?.typeFilter !== 'DateRange' && column?.typeFilter !== 'NumberRange' && /*#__PURE__*/_react.default.createElement("div", {
|
|
277
|
+
className: 'mb-1'
|
|
278
|
+
}, /*#__PURE__*/_react.default.createElement(_rcMasterUi.Select, {
|
|
279
|
+
options: (0, _hooks.translateOption)(operatorOptions, t),
|
|
280
|
+
style: {
|
|
281
|
+
width: '100%',
|
|
282
|
+
marginBottom: 8
|
|
283
|
+
},
|
|
284
|
+
value: operatorKey,
|
|
285
|
+
onChange: val => {
|
|
286
|
+
setOperatorKey(val);
|
|
287
|
+
}
|
|
288
|
+
})), /*#__PURE__*/_react.default.createElement("div", {
|
|
289
|
+
style: {
|
|
290
|
+
marginBottom: 8
|
|
291
|
+
}
|
|
292
|
+
}, (0, _columns.renderFilter)(column, selectedKeys, setSelectedKeys, confirm, visible, searchValue, setSearchValue, propDataSourceFilter ?? [], buddhistLocale, locale, t)), /*#__PURE__*/_react.default.createElement(_antd.Space, {
|
|
293
|
+
style: {
|
|
294
|
+
justifyContent: 'end',
|
|
295
|
+
width: '100%'
|
|
296
|
+
}
|
|
297
|
+
}, /*#__PURE__*/_react.default.createElement(_antd.Button, {
|
|
298
|
+
type: "primary",
|
|
299
|
+
onClick: () => {
|
|
300
|
+
// confirm({closeDropdown: false})
|
|
301
|
+
confirm();
|
|
302
|
+
// handleSearch(selectedKeys as string[], confirm)
|
|
303
|
+
},
|
|
304
|
+
icon: /*#__PURE__*/_react.default.createElement(_icons.SearchOutlined, null),
|
|
305
|
+
size: "small",
|
|
306
|
+
style: {
|
|
307
|
+
width: 90
|
|
308
|
+
}
|
|
309
|
+
}, t ? t('Filter') : 'Filter'), /*#__PURE__*/_react.default.createElement(_antd.Button, {
|
|
310
|
+
type: "link",
|
|
311
|
+
size: "small",
|
|
312
|
+
onClick: () => {
|
|
313
|
+
// setSearchValue('')
|
|
314
|
+
setSelectedKeys([]);
|
|
315
|
+
confirm();
|
|
316
|
+
// handleSearch()
|
|
317
|
+
// close()
|
|
318
|
+
}
|
|
319
|
+
}, t ? t("Clear") : 'Clear')));
|
|
320
|
+
},
|
|
321
|
+
filterIcon: filtered => /*#__PURE__*/_react.default.createElement(_becoxyIcons.FilterFill, {
|
|
322
|
+
fontSize: 12
|
|
323
|
+
// onClick={() => {
|
|
324
|
+
// onFilterClick?.(column, onFilterCallback)
|
|
325
|
+
// }}
|
|
326
|
+
,
|
|
327
|
+
style: {
|
|
328
|
+
color: filtered ? '#E3165B' : '#283046'
|
|
329
|
+
}
|
|
330
|
+
}),
|
|
331
|
+
filterDropdownProps: {
|
|
332
|
+
onOpenChange(open) {
|
|
333
|
+
if (open) {
|
|
334
|
+
// setTimeout(() => searchInput.current?.select(), 100)
|
|
335
|
+
}
|
|
336
|
+
}
|
|
337
|
+
}
|
|
338
|
+
}), [buddhistLocale, propDataSourceFilter, locale, t]);
|
|
339
|
+
const convertColumns = _react.default.useMemo(() => {
|
|
340
|
+
return (0, _columns.flatColumns2)(columns).map((column, colIndex) => {
|
|
341
|
+
if (column === SELECTION_COLUMN) {
|
|
342
|
+
return SELECTION_COLUMN;
|
|
343
|
+
}
|
|
344
|
+
const transformedColumn = {
|
|
345
|
+
...column,
|
|
346
|
+
dataIndex: column.field ?? column.dataIndex,
|
|
347
|
+
// key: column.field ?? column.dataIndex ?? column.key,
|
|
348
|
+
// title: () => (<HeaderContent column={{...column} as any} t={t}/>),
|
|
349
|
+
title: /*#__PURE__*/_react.default.createElement(SortableHeaderCell, {
|
|
350
|
+
columnKey: column.field
|
|
351
|
+
}, /*#__PURE__*/_react.default.createElement(_HeaderContent.default, {
|
|
352
|
+
column: {
|
|
353
|
+
...column
|
|
354
|
+
},
|
|
355
|
+
t: t
|
|
356
|
+
})),
|
|
357
|
+
ellipsis: column.ellipsis !== false,
|
|
358
|
+
align: column.textAlign ?? column.align,
|
|
359
|
+
fixed: column.fixedType ?? column.fixed,
|
|
360
|
+
isSummary: column.isSummary ?? column.haveSum,
|
|
361
|
+
hidden: column.hidden ?? column.visible === false
|
|
362
|
+
};
|
|
363
|
+
if (transformedColumn.field === '#') {
|
|
364
|
+
return {
|
|
365
|
+
...transformedColumn,
|
|
366
|
+
onCell: () => ({
|
|
367
|
+
className: 'cell-number'
|
|
368
|
+
}),
|
|
369
|
+
render: (val, record) => {
|
|
370
|
+
if (pagination && pagination.onChange && pagination.currentPage && pagination.pageSize) {
|
|
371
|
+
return (0, _hooks.findItemPath)(mergedData, record, rowKey, pagination.currentPage, pagination.pageSize);
|
|
372
|
+
}
|
|
373
|
+
return (0, _hooks.findItemPath)(mergedData, record, rowKey);
|
|
374
|
+
}
|
|
375
|
+
};
|
|
376
|
+
}
|
|
377
|
+
if (transformedColumn.field === 'command') {
|
|
378
|
+
return {
|
|
379
|
+
...transformedColumn,
|
|
380
|
+
onCell: () => ({
|
|
381
|
+
className: 'cell-number',
|
|
382
|
+
style: {
|
|
383
|
+
padding: '2px 8px'
|
|
384
|
+
}
|
|
385
|
+
})
|
|
386
|
+
};
|
|
387
|
+
}
|
|
388
|
+
return {
|
|
389
|
+
...transformedColumn,
|
|
390
|
+
...(transformedColumn.allowFiltering === false ? {} : {
|
|
391
|
+
...getColumnSearchProps(column)
|
|
392
|
+
}),
|
|
393
|
+
sorter: column.sorter === false ? undefined : {
|
|
394
|
+
compare: a => a,
|
|
395
|
+
multiple: sortMultiple ? colIndex : undefined
|
|
396
|
+
},
|
|
397
|
+
sortIcon: args => {
|
|
398
|
+
const {
|
|
399
|
+
sortOrder
|
|
400
|
+
} = args;
|
|
401
|
+
return /*#__PURE__*/_react.default.createElement(_react.Fragment, null, !sortOrder && /*#__PURE__*/_react.default.createElement(_becoxyIcons.ArrowUp, {
|
|
402
|
+
fontSize: 15,
|
|
403
|
+
style: {
|
|
404
|
+
display: 'flex',
|
|
405
|
+
opacity: 0,
|
|
406
|
+
marginLeft: 4
|
|
407
|
+
},
|
|
408
|
+
className: (0, _classnames.default)(`ui-rc-table-column-sorter-up`, {
|
|
409
|
+
active: true
|
|
410
|
+
})
|
|
411
|
+
}), sortOrder === ASCEND && /*#__PURE__*/_react.default.createElement("span", {
|
|
412
|
+
className: (0, _classnames.default)(`ui-rc-table-column-sorter-up`, {
|
|
413
|
+
active: sortOrder === ASCEND
|
|
414
|
+
}),
|
|
415
|
+
style: {
|
|
416
|
+
display: 'flex',
|
|
417
|
+
marginLeft: 4
|
|
418
|
+
}
|
|
419
|
+
}, /*#__PURE__*/_react.default.createElement(_becoxyIcons.ArrowUp, {
|
|
420
|
+
fontSize: 15,
|
|
421
|
+
color: '#000'
|
|
422
|
+
})), sortOrder === DESCEND && /*#__PURE__*/_react.default.createElement("span", {
|
|
423
|
+
className: (0, _classnames.default)(`ui-rc-table-column-sorter-up`, {
|
|
424
|
+
active: sortOrder === DESCEND
|
|
425
|
+
}),
|
|
426
|
+
style: {
|
|
427
|
+
display: 'flex',
|
|
428
|
+
marginLeft: 4
|
|
429
|
+
}
|
|
430
|
+
}, /*#__PURE__*/_react.default.createElement(_becoxyIcons.ArrowDown, {
|
|
431
|
+
fontSize: 15,
|
|
432
|
+
color: '#000'
|
|
433
|
+
})));
|
|
434
|
+
},
|
|
435
|
+
onHeaderCell: () => ({
|
|
436
|
+
id: `${column.field}`,
|
|
437
|
+
width: column.width,
|
|
438
|
+
onResize: handleResize?.(column),
|
|
439
|
+
className: column.headerTextAlign === 'center' ? 'head-align-center' : column.headerTextAlign === 'right' ? 'head-align-right' : ''
|
|
440
|
+
}),
|
|
441
|
+
onCell: (data, index) => {
|
|
442
|
+
return {
|
|
443
|
+
id: `${column.field}`,
|
|
444
|
+
colSpan: groupColumns && data.children && column.field === firstNonGroupColumn?.field ? 2 : groupColumns && data.children && nonGroupColumns[1].field === column.field ? 0 : 1,
|
|
445
|
+
// 'z-index': data?.children && column.field === firstNonGroupColumn?.field ? 11 : undefined,
|
|
446
|
+
...transformedColumn?.onCell?.(data, index),
|
|
447
|
+
className: (0, _classnames.default)(transformedColumn?.onCell?.(data, index).className ?? '', {
|
|
448
|
+
'cell-group': groupColumns && data.children,
|
|
449
|
+
'cell-group-fixed': groupColumns && data.children && column.field === firstNonGroupColumn?.field
|
|
450
|
+
}),
|
|
451
|
+
'data-tooltip-id': "tooltip-cell-content"
|
|
452
|
+
};
|
|
453
|
+
},
|
|
454
|
+
render: (value, record, rowIndex) => {
|
|
455
|
+
const colFormat = typeof column.format === 'function' ? column.format(record) : column.format;
|
|
456
|
+
const cellFormat = (0, _hooks.getFormat)(colFormat, format);
|
|
457
|
+
if (groupSetting && groupSetting.hiddenColumnGroup === false) {
|
|
458
|
+
if (record.children) {
|
|
459
|
+
return (0, _columns.renderContent)(column, value, record, rowIndex, cellFormat);
|
|
460
|
+
}
|
|
461
|
+
if (groupColumns?.includes(column.field)) {
|
|
462
|
+
return '';
|
|
463
|
+
}
|
|
464
|
+
return (0, _columns.renderContent)(column, value, record, rowIndex, cellFormat);
|
|
465
|
+
}
|
|
466
|
+
if (column.field === firstNonGroupColumn?.field && record.children) {
|
|
467
|
+
const currentGroupColumn = (0, _columns.flatColumns2)(columns).find(it => it.field === record.field);
|
|
468
|
+
if (currentGroupColumn?.template) {
|
|
469
|
+
return (0, _columns.renderContent)(currentGroupColumn, record[record.field], record, rowIndex, cellFormat);
|
|
470
|
+
}
|
|
471
|
+
return /*#__PURE__*/_react.default.createElement("span", null, currentGroupColumn?.headerText, ": ", (0, _columns.renderContent)(currentGroupColumn, record[record.field], record, rowIndex, cellFormat));
|
|
472
|
+
}
|
|
473
|
+
return (0, _columns.renderContent)(column, value, record, rowIndex, cellFormat);
|
|
474
|
+
},
|
|
475
|
+
hidden: groupSetting && groupSetting.hiddenColumnGroup === false ? transformedColumn.hidden : groupAble && groupColumns && groupColumns.includes(column.field) ? true : transformedColumn.hidden
|
|
476
|
+
};
|
|
477
|
+
});
|
|
478
|
+
}, [columns, t, getColumnSearchProps, sortMultiple, groupSetting, groupAble, groupColumns, pagination, mergedData, rowKey, handleResize, firstNonGroupColumn?.field, nonGroupColumns, format]);
|
|
479
|
+
const transformColumns = _react.default.useCallback(cols => {
|
|
480
|
+
return cols.map(column => {
|
|
481
|
+
const find = convertColumns.find(it => it.field === column.field);
|
|
482
|
+
if (column === SELECTION_COLUMN) {
|
|
483
|
+
return SELECTION_COLUMN;
|
|
484
|
+
}
|
|
485
|
+
if (find) {
|
|
486
|
+
return {
|
|
487
|
+
...find
|
|
488
|
+
};
|
|
489
|
+
}
|
|
490
|
+
if (!find) {
|
|
491
|
+
return {
|
|
492
|
+
...column
|
|
493
|
+
};
|
|
494
|
+
}
|
|
495
|
+
|
|
496
|
+
// Xử lý đệ quy cho children
|
|
497
|
+
if (column.children?.length) {
|
|
498
|
+
return {
|
|
499
|
+
...column,
|
|
500
|
+
children: transformColumns(column.children)
|
|
501
|
+
};
|
|
502
|
+
}
|
|
503
|
+
});
|
|
504
|
+
}, [convertColumns]);
|
|
505
|
+
const mergedColumns = _react.default.useMemo(() => {
|
|
506
|
+
return transformColumns(columns);
|
|
507
|
+
}, [columns, transformColumns]);
|
|
508
|
+
const sensors = (0, _core.useSensors)((0, _core.useSensor)(_core.PointerSensor, {
|
|
509
|
+
activationConstraint: {
|
|
510
|
+
distance: 1
|
|
511
|
+
}
|
|
512
|
+
}));
|
|
180
513
|
const triggerChangeColumns = (newColumns, type) => {
|
|
181
514
|
setColumns(newColumns);
|
|
182
515
|
if (tableRef.current && type === 'columnChoose') {
|
|
@@ -191,6 +524,34 @@ const InternalTable = props => {
|
|
|
191
524
|
flattenColumns: []
|
|
192
525
|
});
|
|
193
526
|
};
|
|
527
|
+
const onDragEnd = ({
|
|
528
|
+
active,
|
|
529
|
+
over
|
|
530
|
+
}) => {
|
|
531
|
+
if (active.id !== over?.id) {
|
|
532
|
+
const targetColumn = (0, _columns.flatColumns2)(columns).find(it => it.field === over?.id);
|
|
533
|
+
const activeIndex = (0, _columns.flatColumns2)(columns).findIndex(i => i.field === active?.id);
|
|
534
|
+
const overIndex = (0, _columns.flatColumns2)(columns).findIndex(i => i.field === over?.id);
|
|
535
|
+
const rs = (0, _sortable.arrayMove)(columns, activeIndex, overIndex);
|
|
536
|
+
triggerChangeColumns(rs, targetColumn && targetColumn.fixed === 'left' ? 'columnChoose' : '');
|
|
537
|
+
}
|
|
538
|
+
setDragIndex({
|
|
539
|
+
active: -1,
|
|
540
|
+
over: -1
|
|
541
|
+
});
|
|
542
|
+
};
|
|
543
|
+
const onDragOver = ({
|
|
544
|
+
active,
|
|
545
|
+
over
|
|
546
|
+
}) => {
|
|
547
|
+
const activeIndex = columns.findIndex(i => i.field === active.id);
|
|
548
|
+
const overIndex = columns.findIndex(i => i.field === over?.id);
|
|
549
|
+
setDragIndex({
|
|
550
|
+
active: active.id,
|
|
551
|
+
over: over?.id,
|
|
552
|
+
direction: overIndex > activeIndex ? 'right' : 'left'
|
|
553
|
+
});
|
|
554
|
+
};
|
|
194
555
|
const triggerGroupColumns = groupedColumns => {
|
|
195
556
|
setColumns((0, _hooks.updateColumnsByGroup)(mergedColumns, groupedColumns));
|
|
196
557
|
if (groupSetting) {
|
|
@@ -232,20 +593,6 @@ const InternalTable = props => {
|
|
|
232
593
|
onDataChange?.(newData);
|
|
233
594
|
// onDataChange?.(removeFieldRecursive(newData, 'isFilterState'))
|
|
234
595
|
};
|
|
235
|
-
|
|
236
|
-
// const triggerFilter = (queries: any) => {
|
|
237
|
-
// console.log('queries', queries)
|
|
238
|
-
// // console.log('data', dataSource)
|
|
239
|
-
// setFilterState(queries)
|
|
240
|
-
//
|
|
241
|
-
// if (queries && queries.length > 0) {
|
|
242
|
-
// setIsFilter(true)
|
|
243
|
-
// } else {
|
|
244
|
-
// setIsFilter(false)
|
|
245
|
-
// }
|
|
246
|
-
//
|
|
247
|
-
// }
|
|
248
|
-
|
|
249
596
|
const triggerCommandClick = args => {
|
|
250
597
|
const {
|
|
251
598
|
id,
|
|
@@ -253,7 +600,7 @@ const InternalTable = props => {
|
|
|
253
600
|
rowData,
|
|
254
601
|
index
|
|
255
602
|
} = args;
|
|
256
|
-
const tmpData = [...
|
|
603
|
+
const tmpData = [...mergedData];
|
|
257
604
|
if (id === 'DELETE') {
|
|
258
605
|
// bật modal confirm
|
|
259
606
|
if (commandSettings && commandSettings.confirmDialog) {
|
|
@@ -279,7 +626,7 @@ const InternalTable = props => {
|
|
|
279
626
|
|
|
280
627
|
let newData = [];
|
|
281
628
|
if (rowData?.parentId) {
|
|
282
|
-
const parent = (0, _hooks.findItemByKey)(
|
|
629
|
+
const parent = (0, _hooks.findItemByKey)(mergedData, rowKey, rowData.parentId);
|
|
283
630
|
const childData = parent?.children ? [...parent.children] : [];
|
|
284
631
|
const findIndex = childData.findIndex(obj => obj[rowKey] === rowData[rowKey]);
|
|
285
632
|
childData.splice(Number(findIndex), 1);
|
|
@@ -311,7 +658,7 @@ const InternalTable = props => {
|
|
|
311
658
|
rowId: rowData.rowId,
|
|
312
659
|
rowData,
|
|
313
660
|
index,
|
|
314
|
-
rows: [...
|
|
661
|
+
rows: [...mergedData]
|
|
315
662
|
});
|
|
316
663
|
}
|
|
317
664
|
}
|
|
@@ -325,7 +672,7 @@ const InternalTable = props => {
|
|
|
325
672
|
|
|
326
673
|
let newData2 = [];
|
|
327
674
|
if (rowData?.parentId) {
|
|
328
|
-
const parent = (0, _hooks.findItemByKey)(
|
|
675
|
+
const parent = (0, _hooks.findItemByKey)(mergedData, rowKey, rowData.parentId);
|
|
329
676
|
const childData = parent?.children ? [...parent.children] : [];
|
|
330
677
|
const findIndex = childData.findIndex(obj => obj[rowKey] === rowData[rowKey]);
|
|
331
678
|
childData.splice(Number(findIndex), 1);
|
|
@@ -355,7 +702,7 @@ const InternalTable = props => {
|
|
|
355
702
|
rowId,
|
|
356
703
|
rowData,
|
|
357
704
|
index,
|
|
358
|
-
rows: [...
|
|
705
|
+
rows: [...mergedData]
|
|
359
706
|
});
|
|
360
707
|
}
|
|
361
708
|
}
|
|
@@ -368,7 +715,7 @@ const InternalTable = props => {
|
|
|
368
715
|
};
|
|
369
716
|
const triggerPaste = (pastedRows, pastedColumnsArray, newData) => {
|
|
370
717
|
const handlePasteCallback = callbackData => {
|
|
371
|
-
const newDataUpdate = (0, _hooks.updateData)(
|
|
718
|
+
const newDataUpdate = (0, _hooks.updateData)(mergedData, callbackData, rowKey);
|
|
372
719
|
triggerChangeData(newDataUpdate);
|
|
373
720
|
|
|
374
721
|
// onCellPaste?.dataChange?.(newDataUpdate)
|
|
@@ -379,7 +726,7 @@ const InternalTable = props => {
|
|
|
379
726
|
onCellPaste.onPasted({
|
|
380
727
|
pasteData: pastedRows,
|
|
381
728
|
type: 'onPaste',
|
|
382
|
-
data:
|
|
729
|
+
data: mergedData,
|
|
383
730
|
pastedColumns: pastedColumnsArray
|
|
384
731
|
}, handlePasteCallback);
|
|
385
732
|
} else {
|
|
@@ -387,7 +734,7 @@ const InternalTable = props => {
|
|
|
387
734
|
onCellPaste.onPasted({
|
|
388
735
|
pasteData: pastedRows,
|
|
389
736
|
type: 'onPaste',
|
|
390
|
-
data:
|
|
737
|
+
data: mergedData,
|
|
391
738
|
pastedColumns: pastedColumnsArray
|
|
392
739
|
}, handlePasteCallback);
|
|
393
740
|
triggerChangeData(newData);
|
|
@@ -399,22 +746,23 @@ const InternalTable = props => {
|
|
|
399
746
|
}
|
|
400
747
|
};
|
|
401
748
|
const TableComponent = groupAble ? _Group.default : editAble ? _GridEdit.default : _Grid.default;
|
|
402
|
-
return /*#__PURE__*/_react.default.createElement(_react.Fragment, null, /*#__PURE__*/_react.default.createElement(
|
|
749
|
+
return /*#__PURE__*/_react.default.createElement(_react.Fragment, null, /*#__PURE__*/_react.default.createElement(_core.DndContext, {
|
|
750
|
+
sensors: sensors,
|
|
751
|
+
modifiers: [_modifiers.restrictToHorizontalAxis],
|
|
752
|
+
onDragEnd: onDragEnd,
|
|
753
|
+
onDragOver: onDragOver,
|
|
754
|
+
collisionDetection: _core.closestCenter
|
|
755
|
+
}, /*#__PURE__*/_react.default.createElement(_sortable.SortableContext, {
|
|
756
|
+
items: columns.map(i => i.field),
|
|
757
|
+
strategy: _sortable.horizontalListSortingStrategy
|
|
758
|
+
}, /*#__PURE__*/_react.default.createElement(DragIndexContext.Provider, {
|
|
759
|
+
value: dragIndex
|
|
760
|
+
}, /*#__PURE__*/_react.default.createElement(TableComponent, (0, _extends2.default)({}, rest, {
|
|
403
761
|
t: t,
|
|
404
762
|
locale: locale,
|
|
405
763
|
tableRef: tableRef,
|
|
406
|
-
dataSource:
|
|
407
|
-
|
|
408
|
-
// components={components}
|
|
409
|
-
,
|
|
410
|
-
components: {
|
|
411
|
-
header: {
|
|
412
|
-
cell: allowResizing ? ResizableTitle : undefined
|
|
413
|
-
}
|
|
414
|
-
},
|
|
415
|
-
format: format
|
|
416
|
-
// columns={columns}
|
|
417
|
-
,
|
|
764
|
+
dataSource: mergedData,
|
|
765
|
+
format: format,
|
|
418
766
|
columns: mergedColumns,
|
|
419
767
|
showSorterTooltip: {
|
|
420
768
|
target: 'sorter-icon'
|
|
@@ -429,25 +777,44 @@ const InternalTable = props => {
|
|
|
429
777
|
groupSetting: groupSetting,
|
|
430
778
|
groupAble: groupAble,
|
|
431
779
|
groupColumns: groupColumns,
|
|
432
|
-
commandClick: triggerCommandClick
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
780
|
+
commandClick: triggerCommandClick,
|
|
781
|
+
pagination: pagination,
|
|
782
|
+
components: {
|
|
783
|
+
header: {
|
|
784
|
+
cell: ResizableTitle
|
|
785
|
+
},
|
|
786
|
+
body: {
|
|
787
|
+
cell: TableBodyCell
|
|
788
|
+
}
|
|
789
|
+
},
|
|
790
|
+
setTooltipContent: setTooltipContent
|
|
791
|
+
})))), /*#__PURE__*/_react.default.createElement(_core.DragOverlay, {
|
|
792
|
+
style: {
|
|
793
|
+
width: 100
|
|
794
|
+
}
|
|
795
|
+
}, /*#__PURE__*/_react.default.createElement("th", {
|
|
796
|
+
style: {
|
|
797
|
+
backgroundColor: '#c4c4c4',
|
|
798
|
+
padding: 6,
|
|
799
|
+
borderRadius: 6,
|
|
800
|
+
fontWeight: 500
|
|
801
|
+
}
|
|
802
|
+
}, columns[columns.findIndex(i => i.field === dragIndex.active)]?.headerText))), /*#__PURE__*/_react.default.createElement(_reactTooltip.Tooltip, {
|
|
803
|
+
id: "tooltip-form-error",
|
|
804
|
+
style: {
|
|
805
|
+
zIndex: 1999
|
|
806
|
+
}
|
|
807
|
+
}), /*#__PURE__*/_react.default.createElement(_reactTooltip.Tooltip, {
|
|
438
808
|
id: "tooltip-cell-content",
|
|
439
809
|
style: {
|
|
440
810
|
zIndex: 1999
|
|
811
|
+
},
|
|
812
|
+
render: () => {
|
|
813
|
+
if (tooltipContent) {
|
|
814
|
+
return /*#__PURE__*/_react.default.createElement("span", null, typeof tooltipContent === 'function' ? tooltipContent() : tooltipContent);
|
|
815
|
+
}
|
|
816
|
+
return undefined;
|
|
441
817
|
}
|
|
442
|
-
// content={'sssss'}
|
|
443
|
-
// content={cellTooltip}
|
|
444
|
-
// render={() => {
|
|
445
|
-
// return (
|
|
446
|
-
// <span>
|
|
447
|
-
// aaaa
|
|
448
|
-
// </span>
|
|
449
|
-
// )
|
|
450
|
-
// }}
|
|
451
818
|
}));
|
|
452
819
|
};
|
|
453
820
|
var _default = exports.default = InternalTable;
|