es-grid-template 1.2.2 → 1.2.4

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/assets/index.css +0 -17
  2. package/assets/index.scss +1082 -1063
  3. package/es/grid-component/ColumnsChoose.d.ts +1 -0
  4. package/es/grid-component/ColumnsChoose.js +351 -61
  5. package/es/grid-component/GridStyle.js +1 -1
  6. package/es/grid-component/InternalTable.js +7 -0
  7. package/es/grid-component/TableGrid.js +3 -2
  8. package/es/grid-component/hooks/useColumns.js +3 -3
  9. package/es/grid-component/hooks/useForceUpdate.d.ts +2 -0
  10. package/es/grid-component/hooks/useForceUpdate.js +5 -0
  11. package/es/grid-component/hooks/utils.d.ts +2 -0
  12. package/es/grid-component/hooks/utils.js +77 -16
  13. package/es/grid-component/styles.scss +22 -3
  14. package/es/grid-component/table/Grid.js +2 -1
  15. package/es/grid-component/table/GridEdit.js +72 -9
  16. package/es/grid-component/type.d.ts +1 -0
  17. package/lib/grid-component/ColumnsChoose.d.ts +1 -0
  18. package/lib/grid-component/ColumnsChoose.js +350 -60
  19. package/lib/grid-component/GridStyle.js +1 -1
  20. package/lib/grid-component/InternalTable.js +7 -0
  21. package/lib/grid-component/TableGrid.js +3 -2
  22. package/lib/grid-component/hooks/useColumns.js +3 -3
  23. package/lib/grid-component/hooks/useForceUpdate.d.ts +2 -0
  24. package/lib/grid-component/hooks/useForceUpdate.js +13 -0
  25. package/lib/grid-component/hooks/utils.d.ts +2 -0
  26. package/lib/grid-component/hooks/utils.js +81 -17
  27. package/lib/grid-component/styles.scss +22 -3
  28. package/lib/grid-component/table/Grid.js +2 -1
  29. package/lib/grid-component/table/GridEdit.js +71 -8
  30. package/lib/grid-component/type.d.ts +1 -0
  31. package/package.json +106 -106
@@ -4,6 +4,7 @@ import { v4 as uuidv4 } from 'uuid';
4
4
  import { presetPalettes } from "@ant-design/colors";
5
5
  import { Table } from "rc-master-ui";
6
6
  import { flatColumns2 } from "./columns";
7
+ import { SELECTION_COLUMN } from "./useColumns";
7
8
  export const newGuid = () => {
8
9
  for (let i = 0; i < 20; i++) {
9
10
  // @ts-ignore
@@ -138,9 +139,14 @@ export const updateColumns = (columns, includes) => {
138
139
  newColumn.children = updateColumns(newColumn.children, includes);
139
140
  hasVisibleChild = newColumn.children.some(child => !child.hidden);
140
141
  }
141
- newColumn.hidden = newColumn.key && !includes.includes(newColumn.key);
142
+
143
+ // newColumn.hidden = newColumn.key && !includes.includes(newColumn.key)
144
+ newColumn.hidden = newColumn.field && !includes.includes(newColumn.field);
145
+ // newColumn.fixed = newColumn.field && !includes.includes(newColumn.field) ? undefined : newColumn.fixed
146
+
142
147
  if (newColumn.children && newColumn.children.length > 0) {
143
148
  newColumn.hidden = !hasVisibleChild;
149
+ // newColumn.fixed = !hasVisibleChild ? undefined : newColumn.fixed
144
150
  }
145
151
  return newColumn;
146
152
  });
@@ -474,19 +480,6 @@ export const getFirstSelectCell = selectCells => {
474
480
  col
475
481
  };
476
482
  };
477
-
478
- // export const getLastSelectCell = (selectCells: any): {row: number, col: number} => {
479
- //
480
- // if (selectCells.size === 0) {
481
- // return {row: 0, col: 0}
482
- // }
483
- // const lastValue = [...selectCells].pop();
484
- //
485
- // const [row, col] = lastValue.split("-").map(Number);
486
- // return {row, col};
487
- //
488
- // }
489
-
490
483
  export const getRowsPasteIndex = pasteRows => {
491
484
  if (!pasteRows) {
492
485
  return [];
@@ -504,8 +497,25 @@ export function addRows8(arr, n) {
504
497
  const addedRows = [];
505
498
 
506
499
  // Hàm kiểm tra kiểu date hợp lệ
507
- const isValidDate = d => {
508
- return !isNaN(Date.parse(d));
500
+ const isValidDate = item => {
501
+ // console.log('!isNaN(Date.parse(d))', !isNaN(Date.parse(d)))
502
+ // return !isNaN(Date.parse(d))
503
+
504
+ if (typeof item === 'number') {
505
+ // return 'number'
506
+ return false;
507
+ }
508
+ if (typeof item === 'string') {
509
+ // Kiểm tra nếu là chuỗi ISO date hợp lệ
510
+ const date = new Date(item);
511
+ if (!isNaN(date.getTime()) && item.includes('T')) {
512
+ // return 'date'
513
+ return true;
514
+ }
515
+ // return 'string'
516
+ return false;
517
+ }
518
+ return !isNaN(Date.parse(item));
509
519
  };
510
520
 
511
521
  // Lấy giá trị mẫu của cột j từ hàng đầu tiên
@@ -711,4 +721,55 @@ export const convertFlatColumn = array => {
711
721
  }
712
722
  });
713
723
  return result;
724
+ };
725
+ export const convertColumns = cols => {
726
+ return cols.map(col => {
727
+ if (col === SELECTION_COLUMN) {
728
+ return SELECTION_COLUMN;
729
+ }
730
+ const transformedColumn = {
731
+ ...col,
732
+ dataIndex: col.field ?? col.dataIndex,
733
+ key: col.field ?? col.dataIndex ?? col.key,
734
+ // title: t ? t(col.columnGroupText ?? col.headerText ?? col.title) : col.columnGroupText ?? col.headerText ?? col.title,
735
+ // title: () => (<span>aaa</span>),
736
+ // title: () => (<HeaderContent column={{...col} as any} t={t}/>),
737
+ // title: () => (<span>{t ? t(col.columnGroupText ?? col.headerText ?? col.title) : col.columnGroupText ?? col.headerText ?? col.title}</span>),
738
+ ellipsis: col.ellipsis !== false,
739
+ align: col.textAlign ?? col.align,
740
+ fixed: col.frozen ? col.frozen.toLowerCase() : col.fixed
741
+ };
742
+ if (transformedColumn.children && transformedColumn.children?.length) {
743
+ return {
744
+ ...transformedColumn,
745
+ children: convertColumns(transformedColumn.children)
746
+ };
747
+ }
748
+ if (["index", "#"].includes(col.field)) {
749
+ return {
750
+ ...transformedColumn,
751
+ onCell: () => ({
752
+ className: 'cell-number'
753
+ }),
754
+ render: (_, __, rowIndex) => rowIndex + 1
755
+ };
756
+ }
757
+ if (col.key === 'command') {
758
+ return {
759
+ ...transformedColumn,
760
+ onCell: () => ({
761
+ className: 'cell-number',
762
+ style: {
763
+ padding: '2px 8px'
764
+ }
765
+ })
766
+ };
767
+ }
768
+ return {
769
+ ...transformedColumn
770
+ };
771
+ });
772
+ };
773
+ export const checkChild = inputArray => {
774
+ return inputArray.some(item => item.children && item.children.length > 0);
714
775
  };
@@ -42,6 +42,14 @@ $fontFamily: "Montserrat",Helvetica,Arial,serif !default;
42
42
  //font-weight: 500;
43
43
  }
44
44
 
45
+ .ui-rc-table {
46
+ .#{$prefix}-table-cell {
47
+ &.#{$prefix}-table-selection-column {
48
+ //padding: 6px 8px !important;
49
+ //padding: 6px 8px !important;
50
+ }
51
+ }
52
+ }
45
53
 
46
54
 
47
55
  &.table-none-column-select {
@@ -57,8 +65,12 @@ $fontFamily: "Montserrat",Helvetica,Arial,serif !default;
57
65
  }
58
66
 
59
67
  .#{$prefix}-table {
60
- line-height: 20px;
68
+
69
+ //line-height: 20px;
70
+
61
71
  .#{$prefix}-table-cell {
72
+ //min-height: 35px;
73
+ //height: 35px;
62
74
 
63
75
  .#{$prefix}-table-filter-column {
64
76
  .#{$prefix}-dropdown-trigger.#{$prefix}-table-filter-trigger {
@@ -323,6 +335,13 @@ $fontFamily: "Montserrat",Helvetica,Arial,serif !default;
323
335
 
324
336
  .#{$prefix}-table-wrapper {
325
337
 
338
+ .#{$prefix}-table.#{$prefix}-table-small {
339
+ .#{$prefix}-table-selection-column{
340
+ //padding: 8px 8px;
341
+ //padding: 6px 8px;
342
+ }
343
+ }
344
+
326
345
  &.grid-editable {
327
346
 
328
347
  .#{$prefix}-table-row {
@@ -527,7 +546,7 @@ $fontFamily: "Montserrat",Helvetica,Arial,serif !default;
527
546
  .#{$prefix}-table.#{$prefix}-table-small {
528
547
  .#{$prefix}-table-selection-column{
529
548
  //padding: 8px 8px;
530
- padding: 6px 8px;
549
+ //padding: 6px 8px;
531
550
  }
532
551
  }
533
552
 
@@ -619,7 +638,7 @@ $fontFamily: "Montserrat",Helvetica,Arial,serif !default;
619
638
  .#{$prefix}-table-row-expand-icon {
620
639
  position: absolute;
621
640
  //.ui-rc_content {
622
- padding-left: $i * 10px;
641
+ //padding-left: $i * 10px;
623
642
  //}
624
643
  }
625
644
 
@@ -27,7 +27,8 @@ const Grid = props => {
27
27
  rowSelectedHoverBg: '#eb4619',
28
28
  cellFontSize: 12,
29
29
  cellFontSizeSM: 13,
30
- headerBg: '#ffffff'
30
+ headerBg: '#ffffff',
31
+ cellPaddingBlockSM: 7
31
32
  }
32
33
  }
33
34
  }
@@ -13,7 +13,7 @@ import dayjs from "dayjs";
13
13
  import 'dayjs/locale/es';
14
14
  import 'dayjs/locale/vi';
15
15
  import TableGrid from "../TableGrid";
16
- import { addRows8, findAllChildrenKeys, findItemByKey, flattenArray, flattenData, getDefaultValue, getEditType, getFirstSelectCell, getLastSelectCell, getRowNumber, getRowsPasteIndex, isObjEmpty, newGuid, totalFixedWidth, updateArrayByKey } from "../hooks";
16
+ import { addRows8, checkChild, findAllChildrenKeys, findItemByKey, flattenArray, flattenData, getDefaultValue, getEditType, getFirstSelectCell, getLastSelectCell, getRowNumber, getRowsPasteIndex, isObjEmpty, newGuid, totalFixedWidth, updateArrayByKey } from "../hooks";
17
17
  import Message from "../../Message/Message";
18
18
 
19
19
  // import Command from "../Command";
@@ -85,8 +85,6 @@ const GridEdit = props => {
85
85
  const [isSelectDragging, setSelectIsDragging] = useState(false);
86
86
  const [isPasteDragging, setIsPasteDragging] = useState(false); // isPasteDragging == tiếp tục hiển thị con trỏ crosshair
87
87
 
88
- // const [showDraggingPoint, setShowDraggingPoint] = useState(false);
89
-
90
88
  const [rowsSelected, setRowsSelected] = useState(new Set());
91
89
  const [startSelectedCells, setStartSelectedCell] = useState(null);
92
90
  const [innerExpandedKeys, setInnerExpandedKeys] = React.useState(() => {
@@ -259,10 +257,54 @@ const GridEdit = props => {
259
257
  }
260
258
  }
261
259
  };
262
- const handleDeleteAll = () => {};
260
+ const handleInsertChild = item => {
261
+ const defaultRowValue = getDefaultValue(defaultValue);
262
+ const rowId = defaultRowValue && defaultRowValue.id ? defaultRowValue.id : newGuid();
263
+ const record = flattenData(childrenColumnName, dataSource)[rowsFocus[rowsFocus.length - 1]];
264
+ if (item.onClick) {
265
+ item.onClick({
266
+ toolbar: item
267
+ });
268
+ } else {
269
+ const newData = [...dataSource];
270
+ let newElement = {};
271
+ if (!record.children || record.children.length === 0) {
272
+ newElement = {
273
+ ...record,
274
+ children: [{
275
+ ...defaultRowValue,
276
+ parentId: record.rowId,
277
+ rowId
278
+ }]
279
+ };
280
+ } else {
281
+ newElement = {
282
+ ...record,
283
+ children: [...record.children, {
284
+ ...defaultRowValue,
285
+ parentId: record.rowId,
286
+ rowId
287
+ }]
288
+ };
289
+ }
290
+ const newDataSource = updateArrayByKey(newData, newElement, rowKey);
291
+ triggerChangeData?.(newDataSource, 'INSERT_CHILDREN');
292
+ }
293
+ const key = getRowKey(record, dataSource.indexOf(record));
294
+
295
+ // let newExpandedKeys: Key[];
296
+ const hasKey = mergedExpandedKeys.has(key);
297
+ if (!hasKey) {
298
+ const newExpandedKeys = [...mergedExpandedKeys, key];
299
+ setInnerExpandedKeys(newExpandedKeys);
300
+ }
301
+ };
302
+ const handleDeleteAll = () => {
303
+ triggerChangeData?.([], 'INSERT_BEFORE');
304
+ };
263
305
  const toolbarItemsBottom = useMemo(() => {
264
306
  if (!rowsFocus || rowsFocus.length === 0) {
265
- return toolbarItems?.filter(it => it.position === 'Bottom' && it.visible !== false && it.key !== 'DUPLICATE' && it.key !== 'INSERT_BEFORE' && it.key !== 'INSERT_AFTER').map(item => {
307
+ return toolbarItems?.filter(it => it.position === 'Bottom' && it.visible !== false && it.key !== 'DUPLICATE' && it.key !== 'INSERT_BEFORE' && it.key !== 'INSERT_AFTER' && it.key !== 'INSERT_CHILDREN').map(item => {
266
308
  if (item.key === 'ADD') {
267
309
  return {
268
310
  ...item,
@@ -391,6 +433,24 @@ const GridEdit = props => {
391
433
  }
392
434
  };
393
435
  }
436
+ if (item.key === 'INSERT_CHILDREN') {
437
+ return {
438
+ ...item,
439
+ template: () => {
440
+ return /*#__PURE__*/React.createElement(Fragment, null, /*#__PURE__*/React.createElement("div", {
441
+ className: classnames(`be-toolbar-item`, item?.className)
442
+ }, /*#__PURE__*/React.createElement(Button, {
443
+ style: {
444
+ color: '#28c76f',
445
+ borderColor: '#28c76f'
446
+ },
447
+ variant: 'outlined',
448
+ onClick: () => handleInsertChild(item),
449
+ className: "d-flex toolbar-button"
450
+ }, item.title ? t ? t(item.title) : item.title : t ? t('Insert item after') : 'Insert item after')));
451
+ }
452
+ };
453
+ }
394
454
  if (item.key === 'DELETE') {
395
455
  return {
396
456
  ...item,
@@ -951,8 +1011,8 @@ const GridEdit = props => {
951
1011
  const newData = [...dataSource];
952
1012
 
953
1013
  // @ts-ignore
954
- const index = newData.findIndex(item => formData[rowKey] === item[rowKey]);
955
- const rs = updateArrayByKey(dataSource, row, rowKey);
1014
+ const index = flattenData(childrenColumnName, newData).findIndex(item => formData[rowKey] === item[rowKey]);
1015
+ const rs = updateArrayByKey(newData, row, rowKey);
956
1016
  if (index > -1) {
957
1017
  triggerChangeData?.(rs, 'onChange');
958
1018
  }
@@ -1324,7 +1384,7 @@ const GridEdit = props => {
1324
1384
  onMouseUp: handleMouseUp
1325
1385
  }, /*#__PURE__*/React.createElement("div", {
1326
1386
  className: 'ui-rc_content'
1327
- }, renderContent(column, value, record, rowIndex, format)), getLastSelectCell(selectedCells).row === rowNumber && getLastSelectCell(selectedCells).col === colIndex && !isSelectDragging &&
1387
+ }, renderContent(column, value, record, rowIndex, format)), selectedCells && selectedCells.size > 0 && getLastSelectCell(selectedCells).row === rowNumber && getLastSelectCell(selectedCells).col === colIndex && !isSelectDragging &&
1328
1388
  /*#__PURE__*/
1329
1389
  // showDraggingPoint &&
1330
1390
  React.createElement("div", {
@@ -1413,7 +1473,8 @@ const GridEdit = props => {
1413
1473
  rowSelectedHoverBg: '#eb4619',
1414
1474
  cellFontSize: 12,
1415
1475
  cellFontSizeSM: 13,
1416
- headerBg: '#ffffff'
1476
+ headerBg: '#ffffff',
1477
+ cellPaddingBlockSM: 7
1417
1478
  // cellPaddingBlock: 0,
1418
1479
  // cellPaddingBlockSM: 0,
1419
1480
  // cellPaddingInlineSM: 0,
@@ -1447,6 +1508,7 @@ const GridEdit = props => {
1447
1508
  rowHoverable: false,
1448
1509
  bottomToolbar: bottomToolbar,
1449
1510
  expandable: {
1511
+ expandIconColumnIndex: checkChild(dataSource) ? 3 : undefined,
1450
1512
  ...expandable,
1451
1513
  expandedRowKeys: innerExpandedKeys,
1452
1514
  expandIcon: args => {
@@ -1481,6 +1543,7 @@ const GridEdit = props => {
1481
1543
  }
1482
1544
  }
1483
1545
  },
1546
+ triggerChangeColumns: triggerChangeColumns,
1484
1547
  rowSelection: columns && columns.length === 0 ? undefined : {
1485
1548
  type: mode === 'checkbox' || type === 'multiple' ? 'checkbox' : "radio",
1486
1549
  columnWidth: !mode ? 0.0000001 : columnWidth ?? 50,
@@ -178,6 +178,7 @@ export interface TableProps<RecordType> extends Omit<RcTableProps<RecordType>, '
178
178
  onDataChange?: (data: RecordType[]) => void;
179
179
  defaultValue?: AnyObject | (() => AnyObject);
180
180
  summary?: boolean | ((data: readonly RecordType[]) => React.ReactNode);
181
+ showEmptyText?: boolean;
181
182
  }
182
183
  export interface TableEditProps<RecordType = AnyObject> extends Omit<TableProps<RecordType>, 'columns'> {
183
184
  columns: ColumnsTable<RecordType>;
@@ -5,5 +5,6 @@ export type IColumnsChoose<RecordType> = {
5
5
  columnsGroup?: string[];
6
6
  triggerChangeColumns?: (columns: ColumnsTable<RecordType>, type: string) => void;
7
7
  t?: any;
8
+ triggerChangeKeys?: any;
8
9
  };
9
10
  export declare const ColumnsChoose: <RecordType extends object>(props: IColumnsChoose<RecordType>) => React.JSX.Element;