es-grid-template 1.9.48 → 1.9.49

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.
@@ -9,7 +9,7 @@ import "./style.scss";
9
9
  import { faker } from '@faker-js/faker';
10
10
  import useMergedState from "rc-util/es/hooks/useMergedState";
11
11
  import Grid from "./table/Grid";
12
- import { addRowIdArray, convertFlatColumn1, convertToObj, convertToObjTrue, filterDataByColumns, findAllChildrenKeys2, flatColumns2, getAllRowKey, getDiffent2Array, getFixedFields, getInvisibleColumns, groupArrayByColumns, isTreeArray, updateWidthsByOther } from "./hook/utils";
12
+ import { addRowIdArray, convertFlatColumn1, convertToObj, convertToObjTrue, filterDataByColumns, findAllChildrenKeys2, flatColumns2, getAllRowKey, getDiffent2Array, getFixedFields, getInvisibleColumns, getTreeDepth, groupArrayByColumns, isTreeArray, updateWidthsByOther } from "./hook/utils";
13
13
  import { convertToTanStackColumns } from "./hook/useColumns";
14
14
  import { convertColumns } from "./hook/convert";
15
15
  import { removeInvisibleColumns } from "../grid-component/hooks";
@@ -95,16 +95,32 @@ const InternalTable = props => {
95
95
  }
96
96
  return addRowIdArray(dataSource);
97
97
  }, [dataSource, groupAble, groupColumns, groupSetting]);
98
+ const depthData = React.useMemo(() => {
99
+ return getTreeDepth(convertData);
100
+ }, [convertData]);
101
+ const expandIconColumnIndex = expandable?.expandIconColumnIndex ?? 0;
102
+ const flatColumns = React.useMemo(() => {
103
+ return flatColumns2(propsColumns);
104
+ }, [propsColumns]);
105
+ const visibleColumns = React.useMemo(() => {
106
+ return flatColumns.filter(it => it.visible !== false);
107
+ }, [flatColumns]);
108
+ const expandColumn = React.useMemo(() => {
109
+ return visibleColumns[expandIconColumnIndex];
110
+ }, [expandIconColumnIndex, visibleColumns]);
98
111
  const mergedColumns = React.useMemo(() => {
99
112
  return convertToTanStackColumns({
100
113
  t,
101
114
  columns,
102
115
  format,
103
- editAble
116
+ editAble,
117
+ depthData,
118
+ expandable,
119
+ expandColumn
104
120
  });
105
121
 
106
122
  // return convertToTanStackColumns<RecordType>(columns)
107
- }, [t, columns, format, editAble]);
123
+ }, [t, columns, format, editAble, expandable, depthData, expandColumn]);
108
124
  const isDataTree = React.useMemo(() => {
109
125
  return isTreeArray(dataSource);
110
126
  }, [dataSource]);
@@ -43,6 +43,7 @@ type TableContainerProps<T> = Omit<TableProps<T>, 'columns'> & {
43
43
  setIsExpandClick: Dispatch<SetStateAction<boolean>>;
44
44
  columnSizingInfo: ColumnSizingInfoState;
45
45
  columnSizing: ColumnSizingState;
46
+ maxDepth?: number;
46
47
  };
47
48
  declare const TableContainer: <RecordType extends object>(props: TableContainerProps<RecordType>) => JSX.Element;
48
49
  export default TableContainer;
@@ -78,6 +78,7 @@ const TableContainer = props => {
78
78
  setIsExpandClick,
79
79
  recordClick,
80
80
  striped = true,
81
+ maxDepth,
81
82
  ...rest
82
83
  } = props;
83
84
  const [paginationLocal] = useLocale('Pagination');
@@ -339,7 +340,8 @@ const TableContainer = props => {
339
340
  pagination,
340
341
  dataSourceFilter,
341
342
  onExpandClick,
342
- setIsExpandClick
343
+ setIsExpandClick,
344
+ maxDepth
343
345
  }
344
346
  }, /*#__PURE__*/React.createElement(TableWrapper, _extends({}, rest, {
345
347
  contextMenuItems: contextMenuItems,
@@ -356,13 +356,13 @@ const EditableCell = props => {
356
356
  // const newVal = datetime.isValid() ? moment(datetime.toDate()).format() : ''
357
357
  onChange(newVal);
358
358
  }
359
- onChange(dateString);
360
359
  setTimeout(() => {
361
360
  // @ts-ignore
362
361
  dateTimePickerRef.current?.focus();
363
362
  }, 0);
364
363
  },
365
364
  onBlur: () => {
365
+ console.log('22222222222');
366
366
  const formState = getValues();
367
367
  const itemState = getValues(dataIndex);
368
368
  // @ts-ignore
@@ -377,6 +377,7 @@ const EditableCell = props => {
377
377
  onChange(newVal);
378
378
  newValue = newVal;
379
379
  }
380
+ console.log('newValue', newValue);
380
381
  if (prevState !== newState) {
381
382
  handleCellChange?.({
382
383
  key: key,
@@ -232,7 +232,7 @@ const TableBodyCell = props => {
232
232
  [`${prefix}-grid-cell-ellipsis`]: true,
233
233
  [`${prefix}-grid-cell-fix-left-last`]: isLastLeftPinnedColumn,
234
234
  [`${prefix}-grid-cell-fix-right-first`]: isFirstRightPinnedColumn,
235
- [`${prefix}-grid-cell-text-center`]: columnMeta?.textAlign === 'center',
235
+ [`${prefix}-grid-cell-text-center`]: columnMeta?.textAlign === 'center' && cell.column.getIndex() !== expandIconColumnIndex,
236
236
  [`${prefix}-grid-cell-text-right`]: columnMeta?.textAlign === 'right'
237
237
  }),
238
238
  style: {
@@ -1,13 +1,16 @@
1
1
  import type { Dispatch, SetStateAction } from "react";
2
- import type { ColumnsTable, ColumnTable, IFormat, SelectionSettings } from '../../grid-component/type';
2
+ import type { ColumnsTable, ColumnTable, ExpandableConfig, IFormat, SelectionSettings } from '../../grid-component/type';
3
3
  import type { Cell, ColumnDef } from '@tanstack/react-table';
4
4
  export declare const renderValueCell: <T>(column: ColumnTable<T>, value: any, record: T, rowIndex: number, colIndex: number, format?: IFormat, editAble?: boolean) => any;
5
5
  export declare const getValueCellString: <T>(column: ColumnTable<T>, value: any, record: T, rowIndex: number, colIndex: number, format?: IFormat) => any;
6
- export declare function convertToTanStackColumns<T>({ t, columns, format, editAble }: {
6
+ export declare function convertToTanStackColumns<T>({ t, columns, format, editAble, depthData, expandColumn }: {
7
7
  t?: any;
8
8
  columns: ColumnsTable<T>;
9
+ expandable?: ExpandableConfig<T>;
9
10
  format?: IFormat;
10
11
  editAble?: boolean;
12
+ depthData?: number;
13
+ expandColumn?: ColumnTable;
11
14
  }): ColumnDef<T, any>[];
12
15
  export type ToggleRow<T> = {
13
16
  e: any;
@@ -141,10 +141,11 @@ export function convertToTanStackColumns({
141
141
  // setExpanded,
142
142
  // expandable,
143
143
  format,
144
- editAble
144
+ editAble,
145
+ depthData,
146
+ // expandable,
147
+ expandColumn
145
148
  }) {
146
- // const expandIconColumnIndex = expandable?.expandIconColumnIndex ?? 0
147
-
148
149
  return sortByType(columns).map(col => {
149
150
  const {
150
151
  headerText,
@@ -202,7 +203,7 @@ export function convertToTanStackColumns({
202
203
  // enableHiding: false,
203
204
  // enableResizing: true,
204
205
  id: field,
205
- size: width,
206
+ size: expandColumn?.field === col.field ? (width ?? 0) + (depthData ?? 0) * 25 : width,
206
207
  accessorKey: field,
207
208
  sortDescFirst: false,
208
209
  minSize: minWidth,
@@ -219,7 +220,9 @@ export function convertToTanStackColumns({
219
220
  columns: children,
220
221
  editAble,
221
222
  format,
222
- t
223
+ t,
224
+ depthData,
225
+ expandColumn
223
226
  });
224
227
  }
225
228
  const meta = {
@@ -166,3 +166,4 @@ export declare const updateColumnsByGroup: (columns: any[], columnsGroup: string
166
166
  export declare const removeColumns: <RecordType>(columns: ColumnTable<RecordType>[], groupColumns: string[]) => ColumnsTable<RecordType>;
167
167
  export declare function sumFields(columns: ColumnTable[], data: any[], childrenKey?: string): any;
168
168
  export declare function sumNumberFields(columns: ColumnTable[], data: any[], childrenKey?: string): any;
169
+ export declare const getTreeDepth: (rows: any[]) => number;
@@ -2714,4 +2714,8 @@ export function sumNumberFields(columns, data, childrenKey = 'children') {
2714
2714
  }
2715
2715
  }
2716
2716
  return result;
2717
- }
2717
+ }
2718
+ export const getTreeDepth = rows => {
2719
+ if (!rows?.length) return 0;
2720
+ return 1 + Math.max(0, ...rows.map(r => getTreeDepth(r.children)));
2721
+ };
@@ -93,6 +93,7 @@ export interface IContext<T> {
93
93
  rowData: any;
94
94
  }) => void;
95
95
  setIsExpandClick: Dispatch<SetStateAction<boolean>>;
96
+ maxDepth?: number;
96
97
  }
97
98
  export declare const TableContext: import("react").Context<IContext<any>>;
98
99
  export type ContextCellChange = {
@@ -104,16 +104,32 @@ const InternalTable = props => {
104
104
  }
105
105
  return (0, _utils.addRowIdArray)(dataSource);
106
106
  }, [dataSource, groupAble, groupColumns, groupSetting]);
107
+ const depthData = _react.default.useMemo(() => {
108
+ return (0, _utils.getTreeDepth)(convertData);
109
+ }, [convertData]);
110
+ const expandIconColumnIndex = expandable?.expandIconColumnIndex ?? 0;
111
+ const flatColumns = _react.default.useMemo(() => {
112
+ return (0, _utils.flatColumns2)(propsColumns);
113
+ }, [propsColumns]);
114
+ const visibleColumns = _react.default.useMemo(() => {
115
+ return flatColumns.filter(it => it.visible !== false);
116
+ }, [flatColumns]);
117
+ const expandColumn = _react.default.useMemo(() => {
118
+ return visibleColumns[expandIconColumnIndex];
119
+ }, [expandIconColumnIndex, visibleColumns]);
107
120
  const mergedColumns = _react.default.useMemo(() => {
108
121
  return (0, _useColumns.convertToTanStackColumns)({
109
122
  t,
110
123
  columns,
111
124
  format,
112
- editAble
125
+ editAble,
126
+ depthData,
127
+ expandable,
128
+ expandColumn
113
129
  });
114
130
 
115
131
  // return convertToTanStackColumns<RecordType>(columns)
116
- }, [t, columns, format, editAble]);
132
+ }, [t, columns, format, editAble, expandable, depthData, expandColumn]);
117
133
  const isDataTree = _react.default.useMemo(() => {
118
134
  return (0, _utils.isTreeArray)(dataSource);
119
135
  }, [dataSource]);
@@ -43,6 +43,7 @@ type TableContainerProps<T> = Omit<TableProps<T>, 'columns'> & {
43
43
  setIsExpandClick: Dispatch<SetStateAction<boolean>>;
44
44
  columnSizingInfo: ColumnSizingInfoState;
45
45
  columnSizing: ColumnSizingState;
46
+ maxDepth?: number;
46
47
  };
47
48
  declare const TableContainer: <RecordType extends object>(props: TableContainerProps<RecordType>) => JSX.Element;
48
49
  export default TableContainer;
@@ -85,6 +85,7 @@ const TableContainer = props => {
85
85
  setIsExpandClick,
86
86
  recordClick,
87
87
  striped = true,
88
+ maxDepth,
88
89
  ...rest
89
90
  } = props;
90
91
  const [paginationLocal] = (0, _locale.useLocale)('Pagination');
@@ -346,7 +347,8 @@ const TableContainer = props => {
346
347
  pagination,
347
348
  dataSourceFilter,
348
349
  onExpandClick,
349
- setIsExpandClick
350
+ setIsExpandClick,
351
+ maxDepth
350
352
  }
351
353
  }, /*#__PURE__*/_react.default.createElement(_TableWrapper.default, (0, _extends2.default)({}, rest, {
352
354
  contextMenuItems: contextMenuItems,
@@ -364,13 +364,13 @@ const EditableCell = props => {
364
364
  // const newVal = datetime.isValid() ? moment(datetime.toDate()).format() : ''
365
365
  onChange(newVal);
366
366
  }
367
- onChange(dateString);
368
367
  setTimeout(() => {
369
368
  // @ts-ignore
370
369
  dateTimePickerRef.current?.focus();
371
370
  }, 0);
372
371
  },
373
372
  onBlur: () => {
373
+ console.log('22222222222');
374
374
  const formState = getValues();
375
375
  const itemState = getValues(dataIndex);
376
376
  // @ts-ignore
@@ -385,6 +385,7 @@ const EditableCell = props => {
385
385
  onChange(newVal);
386
386
  newValue = newVal;
387
387
  }
388
+ console.log('newValue', newValue);
388
389
  if (prevState !== newState) {
389
390
  handleCellChange?.({
390
391
  key: key,
@@ -239,7 +239,7 @@ const TableBodyCell = props => {
239
239
  [`${prefix}-grid-cell-ellipsis`]: true,
240
240
  [`${prefix}-grid-cell-fix-left-last`]: isLastLeftPinnedColumn,
241
241
  [`${prefix}-grid-cell-fix-right-first`]: isFirstRightPinnedColumn,
242
- [`${prefix}-grid-cell-text-center`]: columnMeta?.textAlign === 'center',
242
+ [`${prefix}-grid-cell-text-center`]: columnMeta?.textAlign === 'center' && cell.column.getIndex() !== expandIconColumnIndex,
243
243
  [`${prefix}-grid-cell-text-right`]: columnMeta?.textAlign === 'right'
244
244
  }),
245
245
  style: {
@@ -1,13 +1,16 @@
1
1
  import type { Dispatch, SetStateAction } from "react";
2
- import type { ColumnsTable, ColumnTable, IFormat, SelectionSettings } from '../../grid-component/type';
2
+ import type { ColumnsTable, ColumnTable, ExpandableConfig, IFormat, SelectionSettings } from '../../grid-component/type';
3
3
  import type { Cell, ColumnDef } from '@tanstack/react-table';
4
4
  export declare const renderValueCell: <T>(column: ColumnTable<T>, value: any, record: T, rowIndex: number, colIndex: number, format?: IFormat, editAble?: boolean) => any;
5
5
  export declare const getValueCellString: <T>(column: ColumnTable<T>, value: any, record: T, rowIndex: number, colIndex: number, format?: IFormat) => any;
6
- export declare function convertToTanStackColumns<T>({ t, columns, format, editAble }: {
6
+ export declare function convertToTanStackColumns<T>({ t, columns, format, editAble, depthData, expandColumn }: {
7
7
  t?: any;
8
8
  columns: ColumnsTable<T>;
9
+ expandable?: ExpandableConfig<T>;
9
10
  format?: IFormat;
10
11
  editAble?: boolean;
12
+ depthData?: number;
13
+ expandColumn?: ColumnTable;
11
14
  }): ColumnDef<T, any>[];
12
15
  export type ToggleRow<T> = {
13
16
  e: any;
@@ -153,10 +153,11 @@ function convertToTanStackColumns({
153
153
  // setExpanded,
154
154
  // expandable,
155
155
  format,
156
- editAble
156
+ editAble,
157
+ depthData,
158
+ // expandable,
159
+ expandColumn
157
160
  }) {
158
- // const expandIconColumnIndex = expandable?.expandIconColumnIndex ?? 0
159
-
160
161
  return (0, _utils.sortByType)(columns).map(col => {
161
162
  const {
162
163
  headerText,
@@ -214,7 +215,7 @@ function convertToTanStackColumns({
214
215
  // enableHiding: false,
215
216
  // enableResizing: true,
216
217
  id: field,
217
- size: width,
218
+ size: expandColumn?.field === col.field ? (width ?? 0) + (depthData ?? 0) * 25 : width,
218
219
  accessorKey: field,
219
220
  sortDescFirst: false,
220
221
  minSize: minWidth,
@@ -231,7 +232,9 @@ function convertToTanStackColumns({
231
232
  columns: children,
232
233
  editAble,
233
234
  format,
234
- t
235
+ t,
236
+ depthData,
237
+ expandColumn
235
238
  });
236
239
  }
237
240
  const meta = {
@@ -166,3 +166,4 @@ export declare const updateColumnsByGroup: (columns: any[], columnsGroup: string
166
166
  export declare const removeColumns: <RecordType>(columns: ColumnTable<RecordType>[], groupColumns: string[]) => ColumnsTable<RecordType>;
167
167
  export declare function sumFields(columns: ColumnTable[], data: any[], childrenKey?: string): any;
168
168
  export declare function sumNumberFields(columns: ColumnTable[], data: any[], childrenKey?: string): any;
169
+ export declare const getTreeDepth: (rows: any[]) => number;
@@ -41,7 +41,7 @@ exports.getHiddenParentKeys1 = getHiddenParentKeys1;
41
41
  exports.getInvisibleColumns = getInvisibleColumns;
42
42
  exports.getNewItemsOnly = exports.getLastSelectCell = void 0;
43
43
  exports.getRowIdsBetween = getRowIdsBetween;
44
- exports.getVisibleColumnKeys1 = exports.getVisibleColumnKeys = exports.getTypeFilter = exports.getTableHeight = exports.getSelectedCellMatrix = void 0;
44
+ exports.getVisibleColumnKeys1 = exports.getVisibleColumnKeys = exports.getTypeFilter = exports.getTreeDepth = exports.getTableHeight = exports.getSelectedCellMatrix = void 0;
45
45
  exports.getVisibleFields = getVisibleFields;
46
46
  exports.groupArrayByColumns = groupArrayByColumns;
47
47
  exports.isColor = void 0;
@@ -2848,4 +2848,9 @@ function sumNumberFields(columns, data, childrenKey = 'children') {
2848
2848
  }
2849
2849
  }
2850
2850
  return result;
2851
- }
2851
+ }
2852
+ const getTreeDepth = rows => {
2853
+ if (!rows?.length) return 0;
2854
+ return 1 + Math.max(0, ...rows.map(r => getTreeDepth(r.children)));
2855
+ };
2856
+ exports.getTreeDepth = getTreeDepth;
@@ -93,6 +93,7 @@ export interface IContext<T> {
93
93
  rowData: any;
94
94
  }) => void;
95
95
  setIsExpandClick: Dispatch<SetStateAction<boolean>>;
96
+ maxDepth?: number;
96
97
  }
97
98
  export declare const TableContext: import("react").Context<IContext<any>>;
98
99
  export type ContextCellChange = {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "es-grid-template",
3
- "version": "1.9.48",
3
+ "version": "1.9.49",
4
4
  "description": "es-grid-template",
5
5
  "keywords": [
6
6
  "react",
@@ -57,7 +57,7 @@
57
57
  "@vitest/coverage-v8": "2.0.5",
58
58
  "antd": "5.24.1",
59
59
  "antd-style": "3.7.1",
60
- "becoxy-icons": "2.0.1",
60
+ "becoxy-icons": "^2.1.1",
61
61
  "classnames": "2.3.1",
62
62
  "dayjs": "^1.11.13",
63
63
  "lodash": "4.17.21",