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.
Files changed (31) hide show
  1. package/es/grid-component/ColumnsChoose.js +1 -1
  2. package/es/grid-component/GridStyle.js +1 -1
  3. package/es/grid-component/InternalTable.js +94 -107
  4. package/es/grid-component/TableGrid.d.ts +4 -2
  5. package/es/grid-component/TableGrid.js +17 -7
  6. package/es/grid-component/hooks/constant.js +14 -14
  7. package/es/grid-component/hooks/useColumns/index.d.ts +5 -3
  8. package/es/grid-component/hooks/useColumns/index.js +29 -1
  9. package/es/grid-component/hooks/utils.d.ts +6 -2
  10. package/es/grid-component/hooks/utils.js +44 -2
  11. package/es/grid-component/styles.scss +766 -701
  12. package/es/grid-component/table/Grid.d.ts +3 -0
  13. package/es/grid-component/table/Grid.js +3 -3
  14. package/es/grid-component/table/GridEdit.js +234 -168
  15. package/es/grid-component/type.d.ts +6 -2
  16. package/lib/grid-component/ColumnsChoose.js +1 -1
  17. package/lib/grid-component/GridStyle.js +1 -1
  18. package/lib/grid-component/InternalTable.js +92 -103
  19. package/lib/grid-component/TableGrid.d.ts +4 -2
  20. package/lib/grid-component/TableGrid.js +17 -7
  21. package/lib/grid-component/hooks/constant.js +14 -14
  22. package/lib/grid-component/hooks/useColumns/index.d.ts +5 -3
  23. package/lib/grid-component/hooks/useColumns/index.js +30 -1
  24. package/lib/grid-component/hooks/utils.d.ts +6 -2
  25. package/lib/grid-component/hooks/utils.js +51 -5
  26. package/lib/grid-component/styles.scss +766 -701
  27. package/lib/grid-component/table/Grid.d.ts +3 -0
  28. package/lib/grid-component/table/Grid.js +3 -3
  29. package/lib/grid-component/table/GridEdit.js +228 -164
  30. package/lib/grid-component/type.d.ts +6 -2
  31. package/package.json +105 -105
@@ -89,8 +89,6 @@ const InternalTable = props => {
89
89
  // },
90
90
  // );
91
91
 
92
- // console.log('mergedColumns', mergedColumns)
93
-
94
92
  const tableRef = (0, _react.useRef)(null);
95
93
  const [data, setData] = (0, _react.useState)([]);
96
94
  const [columns, setColumns] = (0, _react.useState)([]);
@@ -98,7 +96,7 @@ const InternalTable = props => {
98
96
  // const [expandKeys, setExpandKeys] = useState<string[]>([]);
99
97
  const [dataSourceFilter, setDataSourceFilter] = (0, _react.useState)(propDataSourceFilter ?? []);
100
98
  (0, _react.useEffect)(() => {
101
- const rs = propsColumns ? [_rcMasterUi.Table.SELECTION_COLUMN, ...propsColumns] : [];
99
+ const rs = propsColumns && propsColumns.length > 0 ? [_rcMasterUi.Table.SELECTION_COLUMN, ...propsColumns] : [];
102
100
  // const rs = propsColumns ? [...propsColumns] : []
103
101
  setColumns(rs);
104
102
  }, [propsColumns]);
@@ -154,13 +152,17 @@ const InternalTable = props => {
154
152
  setSelectedKeys,
155
153
  selectedKeys,
156
154
  confirm,
157
- close,
155
+ // close,
158
156
  setOperatorKey,
159
157
  operatorKey,
160
158
  visible,
161
159
  searchValue,
162
160
  setSearchValue
163
161
  }) => {
162
+ const type = (0, _hooks.getTypeFilter)(column);
163
+ // const operatorOptions = !type || type === 'Text' ? stringOperator : numberOperator
164
+ // const operatorOptions = type === 'Checkbox' || type === 'Dropdown' || type === 'DropTree' || ty
165
+ const operatorOptions = type === ('Checkbox' || 'Dropdown' || 'DropTree' || 'CheckboxDropdown') ? _hooks.booleanOperator : !type || type === 'Text' ? _hooks.stringOperator : _hooks.numberOperator;
164
166
  return /*#__PURE__*/_react.default.createElement("div", {
165
167
  style: {
166
168
  padding: 8,
@@ -170,7 +172,7 @@ const InternalTable = props => {
170
172
  }, column?.showOperator !== false && column?.typeFilter !== 'DateRange' && column?.typeFilter !== 'NumberRange' && /*#__PURE__*/_react.default.createElement("div", {
171
173
  className: 'mb-1'
172
174
  }, /*#__PURE__*/_react.default.createElement(_rcMasterUi.Select, {
173
- options: (0, _hooks.translateOption)(_hooks.numberOperator, t),
175
+ options: (0, _hooks.translateOption)(operatorOptions, t),
174
176
  style: {
175
177
  width: '100%',
176
178
  marginBottom: 8
@@ -201,13 +203,17 @@ const InternalTable = props => {
201
203
  style: {
202
204
  width: 90
203
205
  }
204
- }, "Filter"), /*#__PURE__*/_react.default.createElement(_antd.Button, {
206
+ }, t ? t('Filter') : 'Filter'), /*#__PURE__*/_react.default.createElement(_antd.Button, {
205
207
  type: "link",
206
208
  size: "small",
207
209
  onClick: () => {
208
- close();
210
+ // setSearchValue('')
211
+ setSelectedKeys([]);
212
+ confirm();
213
+ // handleSearch()
214
+ // close()
209
215
  }
210
- }, "close")));
216
+ }, t ? t("Clear") : 'Clear')));
211
217
  },
212
218
  filterIcon: filtered => /*#__PURE__*/_react.default.createElement(_becoxyIcons.FilterFill, {
213
219
  fontSize: 12,
@@ -226,117 +232,100 @@ const InternalTable = props => {
226
232
  }
227
233
  }
228
234
  }), [buddhistLocale, dataSourceFilter, onFilterCallback, onFilterClick, t]);
229
- const handleResize = indexPath => (e, {
235
+ const handleResize = column => (e, {
230
236
  size
231
237
  }) => {
232
- const updateColumns = (cols, path) => {
233
- const [currentIndex, ...restPath] = path;
234
- return cols.map((col, idx) => {
235
- if (idx === currentIndex) {
236
- if (restPath.length === 0) {
237
- // Cập nhật width của cột cuối cùng trong path
238
- // return { ...col, width: size.width }
239
-
240
- // Kiểm tra minWidth trước khi cập nhật width
241
- if (col.minWidth && size.width < col.minWidth) {
242
- e.preventDefault();
243
- return col; // Không cập nhật nếu nhỏ hơn minWidth
244
- }
245
-
246
- // Kiểm tra minWidth trước khi cập nhật width
247
- if (col.maxWidth && size.width > col.maxWidth) {
248
- e.preventDefault();
249
- return col; // Không cập nhật nếu nhỏ hơn minWidth
250
- }
251
- return {
252
- ...col,
253
- width: size.width
254
- };
255
- } else if (col.children) {
256
- // Tiếp tục cập nhật các cấp con
257
- return {
258
- ...col,
259
- children: updateColumns(col.children, restPath)
260
- };
261
- }
262
- }
263
- // e.preventDefault()
264
- return col;
265
- });
238
+ const newColumn = {
239
+ ...column,
240
+ width: size.width
266
241
  };
267
- setColumns(prevColumns => updateColumns(prevColumns, indexPath));
242
+ const newColumns = (0, _hooks.updateArrayByKey)(columns, newColumn, 'field');
243
+ setColumns(newColumns);
268
244
  };
269
- const transformColumns = _react.default.useCallback((cols, parentPath = []) => {
270
- return cols.map((col, index) => {
271
- const currentPath = [...parentPath, index];
272
- // @ts-ignore
273
- if (!col?.dataIndex && !col.key && !col.field) {
274
- return col;
275
- }
276
- const transformedColumn = {
277
- ...col,
278
- dataIndex: col.field ?? col.dataIndex,
279
- key: col.field ?? col.dataIndex ?? col.key,
280
- title: t ? t(col.headerText ?? col.title) : col.headerText ?? col.title,
281
- ellipsis: col.ellipsis !== false,
282
- align: col.textAlign ?? col.align,
283
- fixed: col.frozen ? col.frozen.toLowerCase() : col.fixed
245
+ const convertColumns = (0, _useColumns.flatColumns2)(columns).map((column, colIndex) => {
246
+ if (!column?.dataIndex && !column.key && !column.field) {
247
+ return column;
248
+ }
249
+ const transformedColumn = {
250
+ ...column,
251
+ dataIndex: column.field ?? column.dataIndex,
252
+ key: column.field ?? column.dataIndex ?? column.key,
253
+ title: t ? t(column.headerText ?? column.title) : column.headerText ?? column.title,
254
+ ellipsis: column.ellipsis !== false,
255
+ align: column.textAlign ?? column.align,
256
+ fixed: column.frozen ? column.frozen.toLowerCase() : column.fixed
257
+ };
258
+
259
+ // @ts-ignore
260
+ if (["index", "#"].includes(transformedColumn.dataIndex)) {
261
+ return {
262
+ ...transformedColumn,
263
+ onCell: () => ({
264
+ className: 'cell-number'
265
+ }),
266
+ render: (_, __, rowIndex) => rowIndex + 1
284
267
  };
285
- if (col.children) {
286
- return {
287
- ...transformedColumn,
288
- children: transformColumns(col.children, currentPath)
289
- };
268
+ }
269
+ if (column.field === 'command') {
270
+ return {
271
+ ...transformedColumn,
272
+ onCell: () => ({
273
+ className: column.field === 'command' ? "ui-rc-cell-command" : ''
274
+ }),
275
+ onHeaderCell: () => ({
276
+ width: column.width,
277
+ onResize: handleResize(column)
278
+ })
279
+ };
280
+ }
281
+ return {
282
+ ...(column.allowFiltering === false ? {} : {
283
+ ...getColumnSearchProps(column)
284
+ }),
285
+ ...transformedColumn,
286
+ onFilter: value => {
287
+ return value;
288
+ },
289
+ sorter: column.sorter === false ? undefined : {
290
+ compare: a => a,
291
+ multiple: sortMultiple ? colIndex : undefined
292
+ },
293
+ onHeaderCell: () => ({
294
+ width: column.width,
295
+ onResize: handleResize(column)
296
+ }),
297
+ render: (value, record, rowIndex) => (0, _useColumns.renderContent)(column, value, record, rowIndex, format)
298
+ };
299
+ });
300
+ const transformColumns = _react.default.useCallback(cols => {
301
+ // @ts-ignore
302
+ return cols.map(column => {
303
+ const find = convertColumns.find(it => it.key === column.field);
304
+ if (!column?.field && !column?.key) {
305
+ return column;
290
306
  }
291
-
292
- // @ts-ignore
293
- if (["index", "#"].includes(transformedColumn.dataIndex)) {
307
+ if (find) {
294
308
  return {
295
- ...transformedColumn,
296
- onCell: () => ({
297
- className: 'cell-number'
298
- }),
299
- render: (_, __, rowIndex) => rowIndex + 1
309
+ ...find
300
310
  };
301
311
  }
302
- if (col.field === 'command') {
312
+
313
+ // Xử lý đệ quy cho children
314
+ if (column.children?.length) {
303
315
  return {
304
- ...transformedColumn,
305
- onCell: () => ({
306
- className: col.field === 'command' ? "ui-rc-cell-command" : ''
307
- }),
308
- onHeaderCell: () => ({
309
- width: col.width,
310
- onResize: handleResize(currentPath)
311
- })
316
+ ...column,
317
+ key: column.field ?? column.dataIndex ?? column.key,
318
+ title: t ? t(column.headerText ?? column.title) : column.headerText ?? column.title,
319
+ ellipsis: column.ellipsis !== false,
320
+ align: column.textAlign ?? column.align,
321
+ children: transformColumns(column.children)
312
322
  };
313
323
  }
314
- return {
315
- ...(col.allowFiltering === false ? {} : {
316
- ...getColumnSearchProps(col)
317
- }),
318
- ...transformedColumn,
319
- onFilter: value => {
320
- return value;
321
- },
322
- sorter: col.sorter === false ? undefined : {
323
- compare: a => a,
324
- multiple: sortMultiple ? index : undefined
325
- },
326
- onHeaderCell: () => ({
327
- width: col.width,
328
- onResize: handleResize(currentPath)
329
- }),
330
- render: (value, record, rowIndex) => (0, _useColumns.renderContent)(col, value, record, rowIndex, format)
331
- };
332
324
  });
333
- }, [getColumnSearchProps]);
325
+ }, [convertColumns]);
334
326
  const mergedColumns = _react.default.useMemo(() => {
335
327
  return transformColumns(columns);
336
328
  }, [transformColumns, columns]);
337
-
338
- // console.log('mergedColumns', mergedColumns)
339
-
340
329
  const triggerChangeColumns = newColumns => {
341
330
  setColumns(newColumns);
342
331
  };
@@ -1,11 +1,13 @@
1
1
  import React from 'react';
2
2
  import 'dayjs/locale/es';
3
3
  import 'dayjs/locale/vi';
4
- import type { ColumnsTable, GridTableProps } from "./type";
4
+ import type { ColumnsTable, GetRowKey, GridTableProps } from "./type";
5
5
  type GridProps<T> = GridTableProps<T> & {
6
6
  triggerChangeColumns?: (columns: ColumnsTable<T>, type: string) => void;
7
- triggerChangeData?: () => void;
7
+ triggerChangeData?: (newData: T[], type: string) => void;
8
8
  tableRef: any;
9
+ bottomToolbar?: () => React.ReactElement;
10
+ getRowKey?: GetRowKey<T>;
9
11
  };
10
12
  declare const TableGrid: <RecordType extends object>(props: GridProps<RecordType>) => React.JSX.Element;
11
13
  export default TableGrid;
@@ -97,6 +97,7 @@ const TableGrid = props => {
97
97
  dataSource,
98
98
  locale,
99
99
  expandable,
100
+ rowHoverable,
100
101
  // mergedData,
101
102
  title,
102
103
  format,
@@ -125,6 +126,7 @@ const TableGrid = props => {
125
126
  summary,
126
127
  showToolbar,
127
128
  onSorter,
129
+ bottomToolbar,
128
130
  ...rest
129
131
  } = props;
130
132
  const {
@@ -323,6 +325,7 @@ const TableGrid = props => {
323
325
  },
324
326
  loading: {
325
327
  spinning: columns && columns.length === 0 || loading === true,
328
+ // spinning: loading === true,
326
329
  indicator: /*#__PURE__*/_react.default.createElement(_LoadingSpinner.default, null)
327
330
  },
328
331
  dataSource: dataSource
@@ -335,7 +338,7 @@ const TableGrid = props => {
335
338
  virtual: virtual,
336
339
  columns: columns,
337
340
  rowKey: rowKey,
338
- rowHoverable: true,
341
+ rowHoverable: rowHoverable,
339
342
  size: "small",
340
343
  scroll: scroll ? scroll : {
341
344
  y: 500
@@ -348,7 +351,7 @@ const TableGrid = props => {
348
351
  onContextMenu: onContextMenu(data)
349
352
  };
350
353
  },
351
- rowSelection: {
354
+ rowSelection: columns && columns.length === 0 ? undefined : {
352
355
  ...selectionSettings,
353
356
  type: selectionSettings?.mode === 'checkbox' || type === 'multiple' ? 'checkbox' : "radio",
354
357
  columnWidth: !mode ? 0.0000001 : columnWidth ?? 50,
@@ -357,7 +360,9 @@ const TableGrid = props => {
357
360
  selectedRowKeys: mergedSelectedKeys,
358
361
  defaultSelectedRowKeys: selectionSettings?.defaultSelectedRowKeys,
359
362
  preserveSelectedRowKeys: true,
360
- ...rowSelection,
363
+ // ...rowSelection,
364
+ // checkStrictly: false,
365
+
361
366
  hideSelectAll: !type || type === 'single' || selectionSettings?.mode === 'radio' ? true : hideSelectAll ?? type !== 'multiple'
362
367
  },
363
368
  onScroll: () => {
@@ -415,9 +420,9 @@ const TableGrid = props => {
415
420
  // @ts-ignore
416
421
  , {
417
422
  style: {
418
- width: `calc(100% - 650px`
423
+ width: pagination && pagination.onChange && pagination?.position && pagination?.position[0] === 'topRight' ? `calc(100% - 650px` : `calc(100% - 25px`
419
424
  },
420
- items: toolbarItems ?? [],
425
+ items: (toolbarItems ?? []).filter(it => it.position !== 'Bottom'),
421
426
  mode: 'scroll'
422
427
  }), /*#__PURE__*/_react.default.createElement("div", {
423
428
  style: {
@@ -452,7 +457,7 @@ const TableGrid = props => {
452
457
  } = args;
453
458
 
454
459
  // @ts-ignore
455
- if (record?.children && record?.children?.length > 0 || record?.isChildren) {
460
+ if (record?.children?.length > 0 || record?.isChildren) {
456
461
  return expanded ? /*#__PURE__*/_react.default.createElement("button", {
457
462
  onClick: e => {
458
463
  e.preventDefault();
@@ -468,12 +473,17 @@ const TableGrid = props => {
468
473
  },
469
474
  className: 'ui-rc-table-row-expand-icon ui-rc-table-row-expand-icon-collapsed'
470
475
  });
476
+ } else {
477
+ return /*#__PURE__*/_react.default.createElement("button", {
478
+ className: 'ui-rc-table-row-expand-icon ui-rc-table-row-expand-icon-spaced'
479
+ });
471
480
  }
472
481
  }
473
482
  }
474
- })), pagination && pagination.onChange && !pagination.position && /*#__PURE__*/_react.default.createElement(_pagination.default
483
+ })), bottomToolbar?.(), pagination && pagination.onChange && !pagination.position && /*#__PURE__*/_react.default.createElement(_pagination.default
475
484
  // style={{padding: '0.75rem 1rem'}}
476
485
  , (0, _extends2.default)({
486
+ rootClassName: 'pagination-template',
477
487
  showSizeChanger: true,
478
488
  responsive: true,
479
489
  size: 'small',
@@ -16,29 +16,29 @@ const numberOperator = exports.numberOperator = [{
16
16
  key: '>'
17
17
  }, {
18
18
  value: 'greaterthanorequal',
19
- label: 'Greater Than or Equal',
19
+ label: 'Greater than or equal',
20
20
  key: '>='
21
21
  }, {
22
22
  value: 'lessthan',
23
- label: 'Less Than',
23
+ label: 'Less than',
24
24
  key: '<'
25
25
  }, {
26
26
  value: 'lessthanorequal',
27
- label: 'Less Than Or Equal',
27
+ label: 'Less than or equal',
28
28
  key: '<='
29
29
  }, {
30
30
  value: 'notequal',
31
- label: 'Not Equal',
31
+ label: 'Not equal',
32
32
  key: '!='
33
33
  }];
34
34
  const stringOperator = exports.stringOperator = [{
35
35
  value: 'startswith',
36
36
  key: '_=',
37
- label: 'Starts With'
37
+ label: 'Starts with'
38
38
  }, {
39
39
  value: 'endswith',
40
40
  key: '|=',
41
- label: 'Ends With'
41
+ label: 'Ends with'
42
42
  }, {
43
43
  value: 'contains',
44
44
  key: '~=',
@@ -50,7 +50,7 @@ const stringOperator = exports.stringOperator = [{
50
50
  }, {
51
51
  value: 'notequal',
52
52
  key: '!=',
53
- label: 'Not Equal'
53
+ label: 'Not equal'
54
54
  }];
55
55
  const dateOperator = exports.dateOperator = [{
56
56
  value: 'equal',
@@ -59,15 +59,15 @@ const dateOperator = exports.dateOperator = [{
59
59
  }, {
60
60
  value: 'notequal',
61
61
  key: '!=',
62
- label: 'Not Equal'
62
+ label: 'Not equal'
63
63
  }, {
64
64
  value: 'greaterthan',
65
65
  key: '>',
66
- label: 'Greater Than'
66
+ label: 'Greater than'
67
67
  }, {
68
68
  value: 'lessthan',
69
69
  key: '<',
70
- label: 'Less Than'
70
+ label: 'Less than'
71
71
  }];
72
72
  const dateTimeOperator = exports.dateTimeOperator = [{
73
73
  value: 'equal',
@@ -76,15 +76,15 @@ const dateTimeOperator = exports.dateTimeOperator = [{
76
76
  }, {
77
77
  value: 'notequal',
78
78
  key: '!=',
79
- label: 'Not Equal'
79
+ label: 'Not equal'
80
80
  }, {
81
81
  value: 'greaterthan',
82
82
  key: '>',
83
- label: 'Greater Than'
83
+ label: 'Greater than'
84
84
  }, {
85
85
  value: 'lessthan',
86
86
  key: '<',
87
- label: 'Less Than'
87
+ label: 'Less than'
88
88
  }];
89
89
  const booleanOperator = exports.booleanOperator = [{
90
90
  value: 'equal',
@@ -93,7 +93,7 @@ const booleanOperator = exports.booleanOperator = [{
93
93
  }, {
94
94
  value: 'notequal',
95
95
  key: '!=',
96
- label: 'Not Equal'
96
+ label: 'Not equal'
97
97
  }];
98
98
  const translateOption = (options, t) => {
99
99
  if (!t) {
@@ -1,7 +1,9 @@
1
- import type { ColumnsType, ColumnType, IFormat } from "../../type";
1
+ import type { ColumnType, IFormat } from "../../type";
2
2
  import React from "react";
3
- import { TableLocale } from "rc-master-ui/lib/table/interface";
4
- export declare function flatColumns<RecordType>(columns: ColumnsType<RecordType>, parentKey?: string): ColumnType<RecordType>[];
3
+ import type { TableLocale } from "rc-master-ui/lib/table/interface";
4
+ import type { ColumnsTable } from "../../type";
5
+ export declare function flatColumns<RecordType>(columns: ColumnsTable<RecordType>, parentKey?: string): ColumnsTable<RecordType>;
6
+ export declare function flatColumns2<RecordType>(columns: ColumnsTable<RecordType>, parentKey?: string): ColumnsTable<RecordType>;
5
7
  export declare const getValueCell: <T>(column: ColumnType<T>, value: any, format?: IFormat) => any;
6
8
  export declare const renderContent: <RecordType>(column: ColumnType<RecordType>, value: any, record: RecordType, index: number, format?: IFormat) => React.JSX.Element;
7
9
  export declare const renderFilter: <RecordType>(column: ColumnType<RecordType>, selectedKeys: string[], setSelectedKeys: any, confirm: any, visible: boolean, searchValue: string, setSearchValue: any, dataSourceFilter: any[], buddhistLocale: any, locale?: TableLocale, t?: any) => React.JSX.Element;
@@ -5,6 +5,7 @@ Object.defineProperty(exports, "__esModule", {
5
5
  value: true
6
6
  });
7
7
  exports.flatColumns = flatColumns;
8
+ exports.flatColumns2 = flatColumns2;
8
9
  exports.renderFilter = exports.renderContent = exports.getValueCell = void 0;
9
10
  var _utils = require("../utils");
10
11
  var _reactNumericComponent = require("react-numeric-component");
@@ -13,11 +14,11 @@ var _moment = _interopRequireDefault(require("moment/moment"));
13
14
  var _react = _interopRequireWildcard(require("react"));
14
15
  var _rcMasterUi = require("rc-master-ui");
15
16
  var _CheckboxFilter = _interopRequireDefault(require("../../CheckboxFilter"));
17
+ var _useSelection = require("rc-master-ui/es/table/hooks/useSelection");
16
18
  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); }
17
19
  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; }
18
20
  // import * as React from 'react'
19
21
 
20
- // import {ColorPicker} from "antd";
21
22
  const {
22
23
  RangePicker
23
24
  } = _rcMasterUi.DatePicker;
@@ -44,6 +45,34 @@ function flatColumns(columns, parentKey = 'key') {
44
45
  }];
45
46
  }, []);
46
47
  }
48
+ function flatColumns2(columns, parentKey = 'key') {
49
+ // @ts-ignore
50
+ return columns.reduce((list, column, index) => {
51
+ const {
52
+ fixed
53
+ } = column;
54
+ // Convert `fixed='true'` to `fixed='left'` instead
55
+ const parsedFixed = fixed === true ? 'left' : fixed;
56
+ const mergedKey = `${parentKey}-${index}`;
57
+ const subColumns = column.children;
58
+ if (column === _useSelection.SELECTION_COLUMN) {
59
+ return [...list, {
60
+ ...column
61
+ }];
62
+ }
63
+ if (subColumns && subColumns.length > 0) {
64
+ return [...list, ...flatColumns(subColumns, mergedKey).map(subColum => ({
65
+ fixed: parsedFixed,
66
+ ...subColum
67
+ }))];
68
+ }
69
+ return [...list, {
70
+ key: mergedKey,
71
+ ...column,
72
+ fixed: parsedFixed
73
+ }];
74
+ }, []);
75
+ }
47
76
  const getValueCell = (column, value, format) => {
48
77
  switch (column?.type) {
49
78
  case 'number':
@@ -4,7 +4,7 @@ import type { EditType, IColumnType, TypeFilter } from "rc-master-ui";
4
4
  import type { ColumnEditType, ColumnsType, ColumnTable, GetRowKey } from "../type";
5
5
  import type { SelectionSettings } from "../type";
6
6
  import type { AnyObject } from "../type";
7
- import { Key } from "react";
7
+ import type { Key } from "react";
8
8
  export declare const newGuid: () => any;
9
9
  export declare const sumDataByField: (data: any[], field: string) => any;
10
10
  export declare const checkThousandSeparator: (thousandSeparator: string | undefined, decimalSeparator: string | undefined) => string;
@@ -24,7 +24,7 @@ export declare const customWeekStartEndFormat: (value: any, weekFormat: string)
24
24
  export declare const getTypeFilter: (col: ColumnTable<any>) => TypeFilter;
25
25
  export declare const updateArrayByKey: (arr: any[], element: any, key: string) => any[];
26
26
  export declare const getDateString: <T>(column: ColumnTable<T>, value: any) => string;
27
- export declare const getEditType: <T>(column: ColumnEditType<T>, rowData?: any) => EditType | ((rowData?: any) => EditType);
27
+ export declare const getEditType: <T>(column: ColumnEditType<T>, rowData?: any) => EditType;
28
28
  export declare const isDisable: <T>(column: ColumnEditType<T>, rowData?: any) => boolean;
29
29
  export declare const checkFieldKey: (key: string | undefined) => string;
30
30
  export declare const convertLabelToTitle: (data: any[]) => any[];
@@ -37,3 +37,7 @@ export declare const updateData: <Record_1 = AnyObject>(initData: Record_1[], ro
37
37
  export declare const parseBooleanToValue: (value: boolean, type: 'boolean' | 'number') => number | boolean;
38
38
  export declare const genPresets: (presets?: import("@ant-design/colors").PalettesProps) => import("antd/es/color-picker/interface").PresetsItem[];
39
39
  export declare function findAllChildrenKeys<RecordType>(data: readonly RecordType[], getRowKey: GetRowKey<RecordType>, childrenColumnName: string): Key[];
40
+ export declare const flattenArray: <RecordType extends AnyObject = AnyObject>(arr: any[]) => RecordType[];
41
+ export declare const flattenData: <RecordType extends AnyObject = AnyObject>(childrenColumnName: keyof RecordType, data?: RecordType[]) => RecordType[];
42
+ export declare const countItemsBeforeIndex: (array: any[], index: number) => number;
43
+ export declare const getRowNumber: (array: any[], rowKey: any, key: any) => number;
@@ -4,11 +4,11 @@ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefau
4
4
  Object.defineProperty(exports, "__esModule", {
5
5
  value: true
6
6
  });
7
- exports.customWeekStartEndFormat = exports.convertLabelToTitle = exports.convertDayjsToDate = exports.convertDateToDayjs = exports.convertArrayWithIndent = exports.checkThousandSeparator = exports.checkFieldKey = exports.checkDecimalSeparator = void 0;
7
+ exports.customWeekStartEndFormat = exports.countItemsBeforeIndex = exports.convertLabelToTitle = exports.convertDayjsToDate = exports.convertDateToDayjs = exports.convertArrayWithIndent = exports.checkThousandSeparator = exports.checkFieldKey = exports.checkDecimalSeparator = void 0;
8
8
  exports.findAllChildrenKeys = findAllChildrenKeys;
9
- exports.getEditType = exports.getDatepickerFormat = exports.getDateString = exports.getColumnsVisible = exports.getAllVisibleKeys = exports.genPresets = void 0;
9
+ exports.getEditType = exports.getDatepickerFormat = exports.getDateString = exports.getColumnsVisible = exports.getAllVisibleKeys = exports.genPresets = exports.flattenData = exports.flattenArray = void 0;
10
10
  exports.getHiddenParentKeys = getHiddenParentKeys;
11
- exports.updateData = exports.updateColumns = exports.updateArrayByKey = exports.totalFixedWidth = exports.sumDataByField = exports.parseBooleanToValue = exports.newGuid = exports.isObjEmpty = exports.isNullOrUndefined = exports.isNameColor = exports.isEmpty = exports.isDisable = exports.isColor = exports.getVisibleColumnKeys = exports.getTypeFilter = exports.getTemplate = void 0;
11
+ exports.updateData = exports.updateColumns = exports.updateArrayByKey = exports.totalFixedWidth = exports.sumDataByField = exports.parseBooleanToValue = exports.newGuid = exports.isObjEmpty = exports.isNullOrUndefined = exports.isNameColor = exports.isEmpty = exports.isDisable = exports.isColor = exports.getVisibleColumnKeys = exports.getTypeFilter = exports.getTemplate = exports.getRowNumber = void 0;
12
12
  var _dayjs = _interopRequireDefault(require("dayjs"));
13
13
  var _moment = _interopRequireDefault(require("moment/moment"));
14
14
  var _uuid = require("uuid");
@@ -251,7 +251,7 @@ const getEditType = (column, rowData) => {
251
251
  if (column && typeof column.editType === 'function') {
252
252
  return column.editType(rowData);
253
253
  }
254
- return column.editType;
254
+ return column.editType ?? 'text';
255
255
  };
256
256
  exports.getEditType = getEditType;
257
257
  const isDisable = (column, rowData) => {
@@ -380,4 +380,50 @@ function findAllChildrenKeys(data, getRowKey, childrenColumnName) {
380
380
  }
381
381
  dig(data);
382
382
  return keys;
383
- }
383
+ }
384
+ const flattenArray = arr => {
385
+ if (!arr) {
386
+ return [];
387
+ }
388
+ return arr.reduce((r, {
389
+ children,
390
+ ...rest
391
+ }) => {
392
+ r.push(rest);
393
+ if (children) {
394
+ r.push(...flattenArray(children));
395
+ }
396
+ return r;
397
+ }, []);
398
+ };
399
+ exports.flattenArray = flattenArray;
400
+ const flattenData = (childrenColumnName, data) => {
401
+ let list = [];
402
+ (data || []).forEach(record => {
403
+ list.push(record);
404
+ if (record && typeof record === 'object' && childrenColumnName in record) {
405
+ list = [...list, ...flattenData(childrenColumnName, record[childrenColumnName])];
406
+ }
407
+ });
408
+ return list;
409
+ };
410
+ exports.flattenData = flattenData;
411
+ const countItemsBeforeIndex = (array, index) => {
412
+ let count = 0;
413
+ for (let i = 0; i < index; i++) {
414
+ if (array[i].children && array[i].children.length > 0) {
415
+ const rs = flattenData('children', [array[i]]);
416
+ count += rs.length;
417
+ } else {
418
+ count++;
419
+ }
420
+ }
421
+ return count;
422
+ };
423
+ exports.countItemsBeforeIndex = countItemsBeforeIndex;
424
+ const getRowNumber = (array, rowKey, key) => {
425
+ // const flattArray = flattenArray(array)
426
+ const flattArray = flattenData('children', array);
427
+ return flattArray.findIndex(it => it[key] === rowKey);
428
+ };
429
+ exports.getRowNumber = getRowNumber;