es-grid-template 1.2.0 → 1.2.1

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 (67) hide show
  1. package/assets/index.css +679 -0
  2. package/assets/index.scss +1006 -0
  3. package/es/grid-component/ColumnsChoose.d.ts +1 -0
  4. package/es/grid-component/ColumnsChoose.js +63 -28
  5. package/es/grid-component/ColumnsGroup/ColumnsGroup.d.ts +12 -0
  6. package/es/grid-component/ColumnsGroup/ColumnsGroup.js +223 -0
  7. package/es/grid-component/ColumnsGroup/index.d.ts +1 -0
  8. package/es/grid-component/ColumnsGroup/index.js +1 -0
  9. package/es/grid-component/ConvertColumnTable.d.ts +7 -0
  10. package/es/grid-component/ConvertColumnTable.js +143 -0
  11. package/es/grid-component/EditableCell.js +1 -1
  12. package/es/grid-component/GridStyle.js +1 -1
  13. package/es/grid-component/InternalTable.js +148 -248
  14. package/es/grid-component/TableGrid.d.ts +4 -1
  15. package/es/grid-component/TableGrid.js +29 -58
  16. package/es/grid-component/hooks/{useColumns → columns}/index.d.ts +2 -2
  17. package/es/grid-component/hooks/{useColumns → columns}/index.js +20 -16
  18. package/es/grid-component/hooks/content/HeaderContent.d.ts +11 -0
  19. package/es/grid-component/hooks/content/HeaderContent.js +80 -0
  20. package/es/grid-component/hooks/content/TooltipContent.d.ts +13 -0
  21. package/es/grid-component/hooks/content/TooltipContent.js +74 -0
  22. package/es/grid-component/hooks/useColumns.d.ts +16 -0
  23. package/es/grid-component/hooks/useColumns.js +272 -0
  24. package/es/grid-component/hooks/utils.d.ts +46 -1
  25. package/es/grid-component/hooks/utils.js +740 -2
  26. package/es/grid-component/index.js +3 -1
  27. package/es/grid-component/styles.scss +304 -64
  28. package/es/grid-component/table/Grid.d.ts +2 -0
  29. package/es/grid-component/table/Grid.js +1 -5
  30. package/es/grid-component/table/GridEdit.d.ts +4 -1
  31. package/es/grid-component/table/GridEdit.js +690 -281
  32. package/es/grid-component/table/Group.d.ts +13 -0
  33. package/es/grid-component/table/Group.js +154 -0
  34. package/es/grid-component/type.d.ts +38 -1
  35. package/lib/grid-component/ColumnsChoose.d.ts +1 -0
  36. package/lib/grid-component/ColumnsChoose.js +62 -27
  37. package/lib/grid-component/ColumnsGroup/ColumnsGroup.d.ts +12 -0
  38. package/lib/grid-component/ColumnsGroup/ColumnsGroup.js +234 -0
  39. package/lib/grid-component/ColumnsGroup/index.d.ts +1 -0
  40. package/lib/grid-component/ColumnsGroup/index.js +16 -0
  41. package/lib/grid-component/ConvertColumnTable.d.ts +7 -0
  42. package/lib/grid-component/ConvertColumnTable.js +152 -0
  43. package/lib/grid-component/EditableCell.js +1 -1
  44. package/lib/grid-component/GridStyle.js +1 -1
  45. package/lib/grid-component/InternalTable.js +142 -248
  46. package/lib/grid-component/TableGrid.d.ts +4 -1
  47. package/lib/grid-component/TableGrid.js +23 -56
  48. package/lib/grid-component/hooks/{useColumns → columns}/index.d.ts +2 -2
  49. package/lib/grid-component/hooks/{useColumns → columns}/index.js +20 -16
  50. package/lib/grid-component/hooks/content/HeaderContent.d.ts +11 -0
  51. package/lib/grid-component/hooks/content/HeaderContent.js +87 -0
  52. package/lib/grid-component/hooks/content/TooltipContent.d.ts +13 -0
  53. package/lib/grid-component/hooks/content/TooltipContent.js +81 -0
  54. package/lib/grid-component/hooks/useColumns.d.ts +16 -0
  55. package/lib/grid-component/hooks/useColumns.js +283 -0
  56. package/lib/grid-component/hooks/utils.d.ts +46 -1
  57. package/lib/grid-component/hooks/utils.js +763 -5
  58. package/lib/grid-component/index.js +2 -1
  59. package/lib/grid-component/styles.scss +304 -64
  60. package/lib/grid-component/table/Grid.d.ts +2 -0
  61. package/lib/grid-component/table/Grid.js +1 -5
  62. package/lib/grid-component/table/GridEdit.d.ts +4 -1
  63. package/lib/grid-component/table/GridEdit.js +689 -280
  64. package/lib/grid-component/table/Group.d.ts +13 -0
  65. package/lib/grid-component/table/Group.js +163 -0
  66. package/lib/grid-component/type.d.ts +38 -1
  67. package/package.json +106 -105
@@ -4,15 +4,27 @@ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefau
4
4
  Object.defineProperty(exports, "__esModule", {
5
5
  value: true
6
6
  });
7
- exports.customWeekStartEndFormat = exports.countItemsBeforeIndex = exports.convertLabelToTitle = exports.convertDayjsToDate = exports.convertDateToDayjs = exports.convertArrayWithIndent = exports.checkThousandSeparator = exports.checkFieldKey = exports.checkDecimalSeparator = void 0;
7
+ exports.addRowIdArray = void 0;
8
+ exports.addRows = addRows;
9
+ exports.addRows1 = addRows1;
10
+ exports.addRows2 = addRows2;
11
+ exports.addRows4 = addRows4;
12
+ exports.addRows6 = addRows6;
13
+ exports.addRows7 = addRows7;
14
+ exports.addRows8 = addRows8;
15
+ exports.checkThousandSeparator = exports.checkFieldKey = exports.checkDecimalSeparator = void 0;
16
+ exports.cloneRows = cloneRows;
17
+ exports.customWeekStartEndFormat = exports.countItemsBeforeIndex = exports.convertLabelToTitle = exports.convertFlatColumn = exports.convertDayjsToDate = exports.convertDateToDayjs = exports.convertArrayWithIndent = void 0;
8
18
  exports.findAllChildrenKeys = findAllChildrenKeys;
9
- exports.getEditType = exports.getDatepickerFormat = exports.getDateString = exports.getColumnsVisible = exports.getAllVisibleKeys = exports.genPresets = exports.flattenData = exports.flattenArray = void 0;
19
+ exports.getFirstSelectCell = exports.getEditType = exports.getDefaultValue = exports.getDatepickerFormat = exports.getDateString = exports.getColumnsVisible = exports.getAllVisibleKeys = exports.genPresets = exports.flattenData = exports.flattenArray = exports.findItemByKey = void 0;
10
20
  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 = exports.getRowNumber = void 0;
21
+ exports.updateData = exports.updateColumnsByGroup = exports.updateColumns = exports.updateArrayByKey = exports.transformColumns1 = exports.transformColumns = exports.totalFixedWidth = exports.sumDataByField = exports.removeColumns = exports.parseBooleanToValue = exports.newGuid = exports.mmm = exports.isObjEmpty = exports.isNullOrUndefined = exports.isNameColor = exports.isEmpty = exports.isDisable = exports.isColor = exports.getVisibleColumnKeys = exports.getTypeFilter = exports.getTemplate = exports.getRowsPasteIndex = exports.getRowNumber = exports.getLastSelectCell = void 0;
12
22
  var _dayjs = _interopRequireDefault(require("dayjs"));
13
23
  var _moment = _interopRequireDefault(require("moment/moment"));
14
24
  var _uuid = require("uuid");
15
25
  var _colors = require("@ant-design/colors");
26
+ var _rcMasterUi = require("rc-master-ui");
27
+ var _columns = require("./columns");
16
28
  const newGuid = () => {
17
29
  for (let i = 0; i < 20; i++) {
18
30
  // @ts-ignore
@@ -167,6 +179,27 @@ const updateColumns = (columns, includes) => {
167
179
  });
168
180
  };
169
181
  exports.updateColumns = updateColumns;
182
+ const updateColumnsByGroup = (columns, columnsGroup) => {
183
+ return columns.map(column => {
184
+ const newColumn = {
185
+ ...column
186
+ };
187
+ let hasVisibleChild = false;
188
+ if (!column.key && !column.dataIndex) {
189
+ return column;
190
+ }
191
+ if (newColumn.children) {
192
+ newColumn.children = updateColumnsByGroup(newColumn.children, columnsGroup);
193
+ hasVisibleChild = newColumn.children.some(child => !child.hidden);
194
+ }
195
+ newColumn.hidden = newColumn.key && columnsGroup.includes(newColumn.key);
196
+ if (newColumn.children && newColumn.children.length > 0) {
197
+ newColumn.hidden = !hasVisibleChild;
198
+ }
199
+ return newColumn;
200
+ });
201
+ };
202
+ exports.updateColumnsByGroup = updateColumnsByGroup;
170
203
  const getDatepickerFormat = (type, col) => {
171
204
  const typeFormat = type ? type.toLowerCase() : '';
172
205
  switch (typeFormat) {
@@ -224,7 +257,10 @@ const getTypeFilter = col => {
224
257
  exports.getTypeFilter = getTypeFilter;
225
258
  const updateArrayByKey = (arr, element, key) => {
226
259
  if (arr) {
227
- return arr.map(item => {
260
+ return arr.map(it => {
261
+ const item = {
262
+ ...it
263
+ };
228
264
  if (item[key] === element[key]) {
229
265
  return {
230
266
  ...item,
@@ -426,4 +462,726 @@ const getRowNumber = (array, rowKey, key) => {
426
462
  const flattArray = flattenData('children', array);
427
463
  return flattArray.findIndex(it => it[key] === rowKey);
428
464
  };
429
- exports.getRowNumber = getRowNumber;
465
+ exports.getRowNumber = getRowNumber;
466
+ const getDefaultValue = defaultValue => {
467
+ if (defaultValue && typeof defaultValue === 'function') {
468
+ return defaultValue();
469
+ }
470
+ return defaultValue;
471
+ };
472
+ exports.getDefaultValue = getDefaultValue;
473
+ const addRowIdArray = inputArray => {
474
+ if (inputArray) {
475
+ return inputArray.map(item => {
476
+ if (item.children && item.children.length > 0) {
477
+ // item.children = convertArrayWithIndent(item.children)
478
+ item.children = addRowIdArray(item.children);
479
+ }
480
+
481
+ // return { ...item, rowId: item.rowId ? item.rowId : (item.id ? item.id : newGuid())}
482
+ return {
483
+ ...item,
484
+ rowId: item.rowId ?? item.id ?? newGuid()
485
+ };
486
+ });
487
+ } else {
488
+ return [];
489
+ }
490
+ };
491
+ exports.addRowIdArray = addRowIdArray;
492
+ const findItemByKey = (array, key, value) => {
493
+ for (let i = 0; i < array.length; i++) {
494
+ const item = array[i];
495
+ if (item[key] === value) {
496
+ return item;
497
+ }
498
+ if (item.children && item.children.length > 0) {
499
+ const foundInChildren = findItemByKey(item.children, key, value);
500
+ if (foundInChildren) {
501
+ return foundInChildren;
502
+ }
503
+ }
504
+ }
505
+ return null;
506
+ };
507
+ exports.findItemByKey = findItemByKey;
508
+ const getLastSelectCell = selectCells => {
509
+ if (selectCells.size === 0) {
510
+ return {
511
+ row: 0,
512
+ col: 0
513
+ };
514
+ }
515
+ const lastValue = [...selectCells].at(-1);
516
+ const [row, col] = lastValue.split("-").map(Number);
517
+ return {
518
+ row,
519
+ col
520
+ };
521
+ };
522
+ exports.getLastSelectCell = getLastSelectCell;
523
+ const getFirstSelectCell = selectCells => {
524
+ if (selectCells.size === 0) {
525
+ return {
526
+ row: 0,
527
+ col: 0
528
+ };
529
+ }
530
+ const firstValue = selectCells.values().next().value;
531
+ const [row, col] = firstValue.split("-").map(Number);
532
+ return {
533
+ row,
534
+ col
535
+ };
536
+ };
537
+
538
+ // export const getLastSelectCell = (selectCells: any): {row: number, col: number} => {
539
+ //
540
+ // if (selectCells.size === 0) {
541
+ // return {row: 0, col: 0}
542
+ // }
543
+ // const lastValue = [...selectCells].pop();
544
+ //
545
+ // const [row, col] = lastValue.split("-").map(Number);
546
+ // return {row, col};
547
+ //
548
+ // }
549
+ exports.getFirstSelectCell = getFirstSelectCell;
550
+ const getRowsPasteIndex = pasteRows => {
551
+ if (!pasteRows) {
552
+ return [];
553
+ }
554
+ const result = Array.from(pasteRows).map(item => parseInt(item.split("-")[0]));
555
+ return [...new Set(result)];
556
+ };
557
+
558
+ // export const fff = [
559
+ // [1,'1998-11-03T18:20:45+07:00', "Fadel Groves", "C", true],
560
+ // ]
561
+ //
562
+ // export const oooo = [
563
+ // [1,'1998-11-03T18:20:45+07:00', "Fadel Groves", "C", true],
564
+ // [1,'1998-11-04T18:20:45+07:00', "Fadel Groves", "C", true],
565
+ // [1,'1998-11-05T18:20:45+07:00', "Fadel Groves", "C", true],
566
+ // [1,'1998-11-06T18:20:45+07:00', "Fadel Groves", "C", true],
567
+ // ]
568
+ //
569
+ // export const iii = [
570
+ // [1,'1998-11-03T18:20:45+07:00', "Fadel Groves", "C", true],
571
+ // [2,'1998-11-07T18:20:45+07:00', "Fahey Roads", "C", true],
572
+ // [3,'1998-11-19T18:20:45+07:00', "tess", "C", true],
573
+ // ]
574
+ //
575
+ // export const jjj = [
576
+ // [1,'1998-11-03T18:20:45+07:00', "Fadel Groves", "C", true],
577
+ // [2,'1998-11-07T18:20:45+07:00', "Fahey Roads", "C", true],
578
+ // [3,'1998-11-19T18:20:45+07:00', "tess", "C", true],
579
+ //
580
+ // [4,'1998-11-03T18:20:45+07:00', "Fadel Groves", "C", true],
581
+ // [5,'1998-11-07T18:20:45+07:00', "Fahey Roads", "C", true],
582
+ // [6,'1998-11-19T18:20:45+07:00', "tess", "C", true],
583
+ // ]
584
+ //
585
+ //
586
+ exports.getRowsPasteIndex = getRowsPasteIndex;
587
+ const mmm = exports.mmm = [[1, '1998-11-03T18:20:45+07:00', "Fadel Groves", "C", true], [3, '1998-11-04T18:20:45+07:00', "Fahey Roads", "C", true], [5, '1998-11-05T18:20:45+07:00', "tess", "C", true]];
588
+ //
589
+ // export const nnn = [
590
+ // [1,'1998-11-03T18:20:45+07:00', "Fadel Groves", "C", true],
591
+ // [2,'1998-11-04T18:20:45+07:00', "Fahey Roads", "C", true],
592
+ // [3,'1998-11-05T18:20:45+07:00', "tess", "C", true],
593
+ //
594
+ // [4,'1998-11-06T18:20:45+07:00', "Fadel Groves", "C", true],
595
+ // [5,'1998-11-07T18:20:45+07:00', "Fahey Roads", "C", true],
596
+ // [6,'1998-11-08T18:20:45+07:00', "tess", "C", true],
597
+ // ]
598
+
599
+ function cloneRows(array, numRows) {
600
+ const result = [...array]; // Sao chép mảng ban đầu
601
+
602
+ for (let i = 0; i < numRows; i++) {
603
+ const lastId = result[result.length - 1][0]; // Lấy ID cuối cùng hiện có
604
+
605
+ for (let j = 0; j < array.length - 1; j++) {
606
+ // Nhân bản trừ dòng cuối
607
+ const newRow = [lastId + j + 1, array[j][1]]; // Tăng ID và giữ nguyên giá trị cột 2
608
+ result.push(newRow);
609
+ }
610
+ }
611
+ return result;
612
+ }
613
+ function addRows1(arr, n) {
614
+ // const newArr = [...arr]; // Sao chép mảng gốc để không sửa đổi trực tiếp
615
+ // const baseIndex = arr[arr.length - 1][0]; // Lấy chỉ mục cuối cùng
616
+ //
617
+ // for (let i = 0; i < n; i++) {
618
+ // const newIndex = baseIndex + 1 + i;
619
+ // const newRow = [newIndex, ...arr[i % arr.length].slice(1)]; // Lặp lại các phần tử còn lại theo vòng tròn
620
+ // newArr.push(newRow);
621
+ // }
622
+ //
623
+ // return newArr;
624
+
625
+ const newArr = [...arr]; // Sao chép mảng gốc để không sửa đổi trực tiếp
626
+
627
+ if (arr.length === 1) {
628
+ // Nếu chỉ có một phần tử, lặp lại phần tử đó n lần
629
+ for (let i = 0; i < n; i++) {
630
+ newArr.push([...arr[0]]);
631
+ }
632
+ } else {
633
+ const baseIndex = arr[arr.length - 1][0]; // Lấy chỉ mục cuối cùng
634
+
635
+ for (let i = 0; i < n; i++) {
636
+ const newIndex = baseIndex + 1 + i;
637
+ const newRow = [newIndex, ...arr[i % arr.length].slice(1)]; // Lặp lại các phần tử còn lại theo vòng tròn
638
+ newArr.push(newRow);
639
+ }
640
+ }
641
+ return newArr;
642
+ }
643
+ function addRows2(arr, n) {
644
+ const newArr = [...arr]; // Sao chép mảng gốc để không sửa đổi trực tiếp
645
+ const addedRows = [];
646
+ if (arr.length === 1) {
647
+ // Nếu chỉ có một phần tử, lặp lại phần tử đó n lần
648
+ for (let i = 0; i < n; i++) {
649
+ newArr.push([...arr[0]]);
650
+ addedRows.push([...arr[0]]);
651
+ }
652
+ } else {
653
+ const differences = [];
654
+ for (let i = 1; i < arr.length; i++) {
655
+ differences.push(arr[i][0] - arr[i - 1][0]);
656
+ }
657
+ const step = differences.reduce((a, b) => a + b, 0) / differences.length; // Tính khoảng cách trung bình
658
+
659
+ for (let i = 0; i < n; i++) {
660
+ const newIndex = newArr[newArr.length - 1][0] + step;
661
+ const newRow = [newIndex, ...arr[i % arr.length].slice(1)]; // Lặp lại nội dung theo vòng tròn
662
+ newArr.push(newRow);
663
+ addedRows.push(newRow);
664
+ }
665
+ }
666
+ return {
667
+ newArr,
668
+ addedRows
669
+ };
670
+ }
671
+ function addRows(arr, n) {
672
+ const newArr = [...arr]; // Sao chép mảng gốc để không sửa đổi trực tiếp
673
+ const addedRows = [];
674
+ if (arr.length === 1) {
675
+ for (let i = 0; i < n; i++) {
676
+ newArr.push([...arr[0]]);
677
+ addedRows.push([...arr[0]]);
678
+ }
679
+ } else {
680
+ const diffs = arr[0].map((_, colIndex) => {
681
+ if (typeof arr[0][colIndex] === 'number') {
682
+ return arr[1][colIndex] - arr[0][colIndex];
683
+ } else if (!isNaN(Date.parse(arr[0][colIndex]))) {
684
+ console.log('Date.parse(arr[0][colIndex])', Date.parse(arr[0][colIndex]));
685
+ console.log('arr[0][colIndex]', arr[0][colIndex]);
686
+ // @ts-ignore
687
+ return new Date(arr[1][colIndex]) - new Date(arr[0][colIndex]);
688
+ }
689
+ return null;
690
+ });
691
+ console.log('diffs', diffs);
692
+ for (let i = 0; i < n; i++) {
693
+ const lastRow = [...newArr[newArr.length - 1]];
694
+ const newRow = lastRow.map((value, colIndex) => {
695
+ if (typeof value === 'number' && diffs[colIndex] !== null) {
696
+ return value + diffs[colIndex];
697
+ } else if (!isNaN(Date.parse(value)) && diffs[colIndex] !== null) {
698
+ const lastDate = new Date(value);
699
+ return (0, _moment.default)(new Date(lastDate.getTime() + diffs[colIndex])).format();
700
+ } else return arr[i % arr.length][colIndex]; // Lặp lại nội dung theo vòng tròn
701
+ // arr[i % arr.length].slice(1)
702
+ // return value;
703
+ });
704
+ newArr.push(newRow);
705
+ addedRows.push(newRow);
706
+ }
707
+ }
708
+ return {
709
+ newArr,
710
+ addedRows
711
+ };
712
+ }
713
+ function addRows4(arr, n) {
714
+ const newArr = [...arr]; // Sao chép mảng gốc để không sửa đổi trực tiếp
715
+ const addedRows = [];
716
+ if (arr.length === 1) {
717
+ for (let i = 0; i < n; i++) {
718
+ newArr.push([...arr[0]]);
719
+ addedRows.push([...arr[0]]);
720
+ }
721
+ } else {
722
+ const diffs = arr[0].map((_, colIndex) => {
723
+ if (typeof arr[0][colIndex] === 'number') {
724
+ return arr[1][colIndex] - arr[0][colIndex];
725
+ } else if (!isNaN(Date.parse(arr[0][colIndex]))) {
726
+ // @ts-ignore
727
+ return new Date(arr[1][colIndex]) - new Date(arr[0][colIndex]);
728
+ }
729
+ return null;
730
+ });
731
+ for (let i = 0; i < n; i++) {
732
+ const lastRow = [...newArr[newArr.length - 1]];
733
+ const newRow = lastRow.map((value, colIndex) => {
734
+ if (typeof value === 'number' && diffs[colIndex] !== null) {
735
+ return value + diffs[colIndex];
736
+ } else if (!isNaN(Date.parse(value)) && diffs[colIndex] !== null) {
737
+ const lastDate = new Date(value);
738
+ return new Date(lastDate.getTime() + diffs[colIndex]).toISOString();
739
+ } else if (typeof value === 'string') {
740
+ return arr[(i + 1) % arr.length][colIndex]; // Lặp lại nội dung theo vòng tròn
741
+ }
742
+ return value;
743
+ });
744
+ newArr.push(newRow);
745
+ addedRows.push(newRow);
746
+ }
747
+ }
748
+ return {
749
+ newArr,
750
+ addedRows
751
+ };
752
+ }
753
+ function addRows6(arr, n) {
754
+ // const newArr = [...arr]; // Sao chép mảng gốc để không sửa đổi trực tiếp
755
+ // const addedRows = [];
756
+ //
757
+ // if (arr.length === 1) {
758
+ // for (let i = 0; i < n; i++) {
759
+ // newArr.push([...arr[0]]);
760
+ // addedRows.push([...arr[0]]);
761
+ // }
762
+ // } else {
763
+ // const diffs = arr[0].map((_: any, colIndex: number) => {
764
+ // if (typeof arr[0][colIndex] === 'number') {
765
+ // return arr[1][colIndex] - arr[0][colIndex];
766
+ // } else if (!isNaN(Date.parse(arr[0][colIndex])) && arr.length === 2) {
767
+ // // @ts-ignore
768
+ // return new Date(arr[1][colIndex]) - new Date(arr[0][colIndex]);
769
+ // }
770
+ // return null;
771
+ // });
772
+ //
773
+ // for (let i = 0; i < n; i++) {
774
+ // const lastRow = [...newArr[newArr.length - 1]];
775
+ //
776
+ // const newRow = lastRow.map((value, colIndex) => {
777
+ // if (typeof value === 'number' && diffs[colIndex] !== null) {
778
+ // return value + diffs[colIndex];
779
+ // } else if (!isNaN(Date.parse(value))) {
780
+ // if (arr.length > 2) {
781
+ // return arr[(i) % arr.length][colIndex]; // Lặp lại nội dung theo vòng tròn
782
+ // } else if (diffs[colIndex] !== null) {
783
+ // const lastDate = new Date(value);
784
+ // return new Date(lastDate.getTime() + diffs[colIndex]).toISOString();
785
+ // }
786
+ // } else if (typeof value === 'string') {
787
+ // return arr[(i) % arr.length][colIndex]; // Lặp lại nội dung theo vòng tròn
788
+ // }
789
+ // return value;
790
+ // });
791
+ //
792
+ // newArr.push(newRow);
793
+ // addedRows.push(newRow);
794
+ // }
795
+ // }
796
+ //
797
+ // return { newArr, addedRows };
798
+
799
+ const newArr = [...arr]; // Sao chép mảng gốc để không sửa đổi trực tiếp
800
+ const addedRows = [];
801
+ if (arr.length === 1) {
802
+ for (let i = 0; i < n; i++) {
803
+ newArr.push([...arr[0]]);
804
+ addedRows.push([...arr[0]]);
805
+ }
806
+ } else {
807
+ const diffs = arr[0].map((_, colIndex) => {
808
+ if (typeof arr[0][colIndex] === 'number') {
809
+ return arr[1][colIndex] - arr[0][colIndex];
810
+ } else if (!isNaN(Date.parse(arr[0][colIndex]))) {
811
+ // @ts-ignore
812
+ const dateDiffs = arr.slice(1).map((row, i) => new Date(row[colIndex]) - new Date(arr[i][colIndex]));
813
+ const avgDiff = dateDiffs.reduce((a, b) => a + b, 0) / dateDiffs.length;
814
+ return avgDiff || null;
815
+ }
816
+ return null;
817
+ });
818
+ for (let i = 0; i < n; i++) {
819
+ const lastRow = [...newArr[newArr.length - 1]];
820
+ const newRow = lastRow.map((value, colIndex) => {
821
+ if (typeof value === 'number' && diffs[colIndex] !== null) {
822
+ return value + diffs[colIndex];
823
+ } else if (!isNaN(Date.parse(value)) && diffs[colIndex] !== null) {
824
+ const lastDate = new Date(value);
825
+ return new Date(lastDate.getTime() + diffs[colIndex]).toISOString();
826
+ } else {
827
+ return arr[i % arr.length][colIndex]; // Lặp lại nội dung theo vòng tròn
828
+ }
829
+ });
830
+ newArr.push(newRow);
831
+ addedRows.push(newRow);
832
+ }
833
+ }
834
+ return {
835
+ newArr,
836
+ addedRows
837
+ };
838
+ }
839
+ function addRows7(arr, n) {
840
+ if (!Array.isArray(arr) || arr.length === 0) return arr;
841
+ const m = arr.length;
842
+ const numCols = arr[0].length;
843
+ const newRows = [];
844
+
845
+ // Hàm kiểm tra kiểu date hợp lệ
846
+ const isValidDate = d => {
847
+ return !isNaN(Date.parse(d));
848
+ };
849
+
850
+ // Lấy giá trị mẫu của cột j từ hàng i (i thuộc [0, m-1])
851
+ const getSample = j => arr[0][j];
852
+
853
+ // Xác định cho mỗi cột chế độ xử lý:
854
+ // mode = 'number-stepping' | 'date-stepping' | 'cycle'
855
+ const modes = [];
856
+ const steps = []; // bước tăng, nếu có (cho number hoặc date)
857
+
858
+ for (let j = 0; j < numCols; j++) {
859
+ const sample = getSample(j);
860
+ if (m === 1) {
861
+ // Nếu mảng chỉ có 1 hàng: nếu là số thì giữ nguyên; nếu là date thì tăng 1 ngày; còn lại giữ nguyên.
862
+ if (typeof sample === "number") {
863
+ modes[j] = "number-constant";
864
+ } else if (isValidDate(sample)) {
865
+ modes[j] = "date-stepping";
866
+ steps[j] = 24 * 3600 * 1000; // 1 ngày = 86400000 ms
867
+ } else {
868
+ modes[j] = "cycle";
869
+ }
870
+ } else if (m === 2) {
871
+ // Nếu mảng có 2 hàng: nếu là số thì tính bước = row2 - row1, tương tự với date
872
+ const first = arr[0][j],
873
+ second = arr[1][j];
874
+ if (typeof first === "number" && typeof second === "number") {
875
+ modes[j] = "number-stepping";
876
+ steps[j] = second - first;
877
+ } else if (isValidDate(first) && isValidDate(second)) {
878
+ modes[j] = "date-stepping";
879
+ steps[j] = Date.parse(second) - Date.parse(first);
880
+ } else {
881
+ modes[j] = "cycle";
882
+ }
883
+ } else {
884
+ // mảng có >2 hàng
885
+ const first = arr[0][j],
886
+ second = arr[1][j],
887
+ third = arr[2][j];
888
+ if (typeof first === "number" && typeof second === "number" && typeof third === "number") {
889
+ const step1 = second - first;
890
+ const step2 = third - second;
891
+ if (step1 === step2) {
892
+ modes[j] = "number-stepping";
893
+ steps[j] = step1;
894
+ } else {
895
+ modes[j] = "cycle";
896
+ }
897
+ } else if (isValidDate(first) && isValidDate(second) && isValidDate(third)) {
898
+ const step1 = Date.parse(second) - Date.parse(first);
899
+ const step2 = Date.parse(third) - Date.parse(second);
900
+ if (step1 === step2) {
901
+ modes[j] = "date-stepping";
902
+ steps[j] = step1;
903
+ } else {
904
+ modes[j] = "cycle";
905
+ }
906
+ } else {
907
+ modes[j] = "cycle";
908
+ }
909
+ }
910
+ }
911
+
912
+ // Tạo các dòng mới (thêm n dòng)
913
+ // Với mỗi cột, nếu chế độ là stepping thì lấy giá trị cuối của mảng ban đầu, cộng thêm (i+1)*step
914
+ // Nếu chế độ là cycle thì dùng arr[i mod m][j]
915
+ for (let i = 0; i < n; i++) {
916
+ const newRow = [];
917
+ for (let j = 0; j < numCols; j++) {
918
+ let newValue;
919
+ switch (modes[j]) {
920
+ case "number-constant":
921
+ // mảng có 1 hàng, số giữ nguyên
922
+ newValue = arr[0][j];
923
+ break;
924
+ case "number-stepping":
925
+ {
926
+ // lấy giá trị cuối của cột j trong mảng ban đầu
927
+ const lastValue = arr[m - 1][j];
928
+ newValue = lastValue + (i + 1) * steps[j];
929
+ }
930
+ break;
931
+ case "date-stepping":
932
+ {
933
+ // lấy giá trị cuối, chuyển về date, cộng thêm (i+1)*step, convert về ISO string giữ định dạng ban đầu (nếu cần giữ định dạng như cũ)
934
+ const lastDate = new Date(arr[m - 1][j]);
935
+ const newTime = lastDate.getTime() + (i + 1) * steps[j];
936
+ // Giữ định dạng ISO với timezone tương tự nếu cần.
937
+ newValue = new Date(newTime).toISOString();
938
+ }
939
+ break;
940
+ case "cycle":
941
+ default:
942
+ // Lặp lại nội dung theo vòng tròn: dùng hàng thứ (i mod m)
943
+ newValue = arr[i % m][j];
944
+ break;
945
+ }
946
+ newRow.push(newValue);
947
+ }
948
+ newRows.push(newRow);
949
+ }
950
+ return arr.concat(newRows);
951
+ }
952
+ function addRows8(arr, n) {
953
+ if (!Array.isArray(arr) || arr.length === 0) return {
954
+ combined: arr,
955
+ addedRows: []
956
+ };
957
+ const m = arr.length;
958
+ const numCols = arr[0].length;
959
+ const addedRows = [];
960
+
961
+ // Hàm kiểm tra kiểu date hợp lệ
962
+ const isValidDate = d => {
963
+ return !isNaN(Date.parse(d));
964
+ };
965
+
966
+ // Lấy giá trị mẫu của cột j từ hàng đầu tiên
967
+ const getSample = j => arr[0][j];
968
+
969
+ // Xác định chế độ xử lý cho mỗi cột:
970
+ // mode = 'number-stepping' | 'date-stepping' | 'number-constant' | 'cycle'
971
+ const modes = [];
972
+ const steps = []; // bước tăng, nếu có (cho number hoặc date)
973
+
974
+ for (let j = 0; j < numCols; j++) {
975
+ const sample = getSample(j);
976
+ if (m === 1) {
977
+ // Nếu mảng chỉ có 1 hàng: nếu là số thì giữ nguyên; nếu là date thì tăng 1 ngày; còn lại giữ nguyên.
978
+ if (typeof sample === "number") {
979
+ modes[j] = "number-constant";
980
+ } else if (isValidDate(sample)) {
981
+ modes[j] = "date-stepping";
982
+ steps[j] = 24 * 3600 * 1000; // 1 ngày = 86400000 ms
983
+ } else {
984
+ modes[j] = "cycle";
985
+ }
986
+ } else if (m === 2) {
987
+ // Nếu mảng có 2 hàng: nếu là số thì tính bước = row2 - row1, tương tự với date
988
+ const first = arr[0][j],
989
+ second = arr[1][j];
990
+ if (typeof first === "number" && typeof second === "number") {
991
+ modes[j] = "number-stepping";
992
+ steps[j] = second - first;
993
+ } else if (isValidDate(first) && isValidDate(second)) {
994
+ modes[j] = "date-stepping";
995
+ steps[j] = Date.parse(second) - Date.parse(first);
996
+ } else {
997
+ modes[j] = "cycle";
998
+ }
999
+ } else {
1000
+ // Nếu mảng có >2 hàng
1001
+ const first = arr[0][j],
1002
+ second = arr[1][j],
1003
+ third = arr[2][j];
1004
+ if (typeof first === "number" && typeof second === "number" && typeof third === "number") {
1005
+ const step1 = second - first;
1006
+ const step2 = third - second;
1007
+ if (step1 === step2) {
1008
+ modes[j] = "number-stepping";
1009
+ steps[j] = step1;
1010
+ } else {
1011
+ modes[j] = "cycle";
1012
+ }
1013
+ } else if (isValidDate(first) && isValidDate(second) && isValidDate(third)) {
1014
+ const step1 = Date.parse(second) - Date.parse(first);
1015
+ const step2 = Date.parse(third) - Date.parse(second);
1016
+ if (step1 === step2) {
1017
+ modes[j] = "date-stepping";
1018
+ steps[j] = step1;
1019
+ } else {
1020
+ modes[j] = "cycle";
1021
+ }
1022
+ } else {
1023
+ modes[j] = "cycle";
1024
+ }
1025
+ }
1026
+ }
1027
+
1028
+ // Tạo các dòng mới (thêm n dòng)
1029
+ // Với mỗi cột, nếu chế độ là stepping thì lấy giá trị cuối của mảng ban đầu và cộng thêm (i+1)*step
1030
+ // Nếu chế độ là cycle thì dùng arr[i mod m][j]
1031
+ for (let i = 0; i < n; i++) {
1032
+ const newRow = [];
1033
+ for (let j = 0; j < numCols; j++) {
1034
+ let newValue;
1035
+ switch (modes[j]) {
1036
+ case "number-constant":
1037
+ // Mảng có 1 hàng, số giữ nguyên
1038
+ newValue = arr[0][j];
1039
+ break;
1040
+ case "number-stepping":
1041
+ {
1042
+ // Lấy giá trị cuối của cột j trong mảng ban đầu
1043
+ const lastValue = arr[m - 1][j];
1044
+ newValue = lastValue + (i + 1) * steps[j];
1045
+ }
1046
+ break;
1047
+ case "date-stepping":
1048
+ {
1049
+ // Lấy giá trị cuối, chuyển về date, cộng thêm (i+1)*step, chuyển lại về định dạng ISO
1050
+ const lastDate = new Date(arr[m - 1][j]);
1051
+ const newTime = lastDate.getTime() + (i + 1) * steps[j];
1052
+ newValue = (0, _moment.default)(new Date(newTime)).format();
1053
+ }
1054
+ break;
1055
+ case "cycle":
1056
+ default:
1057
+ // Lặp lại nội dung theo vòng tròn: dùng hàng thứ (i mod m)
1058
+ newValue = arr[i % m][j];
1059
+ break;
1060
+ }
1061
+ newRow.push(newValue);
1062
+ }
1063
+ addedRows.push(newRow);
1064
+ }
1065
+ const combined = arr.concat(addedRows);
1066
+ return {
1067
+ combined,
1068
+ addedRows
1069
+ };
1070
+ }
1071
+ const transformColumns = (cols, convertColumns, t) => {
1072
+ // @ts-ignore
1073
+ return cols.map(column => {
1074
+ const find = convertColumns.find(it => it.key === column.field);
1075
+ if (!column?.field && !column?.key) {
1076
+ return _rcMasterUi.Table.SELECTION_COLUMN;
1077
+ }
1078
+ if (find) {
1079
+ return {
1080
+ ...find
1081
+ };
1082
+ }
1083
+
1084
+ // Xử lý đệ quy cho children
1085
+ if (column.children?.length) {
1086
+ return {
1087
+ ...column,
1088
+ key: column.field ?? column.dataIndex ?? column.key,
1089
+ title: t ? t(column.headerText ?? column.title) : column.headerText ?? column.title,
1090
+ ellipsis: column.ellipsis !== false,
1091
+ align: column.textAlign ?? column.align,
1092
+ children: transformColumns(column.children, convertColumns)
1093
+ };
1094
+ }
1095
+ });
1096
+ };
1097
+ exports.transformColumns = transformColumns;
1098
+ const transformColumns1 = (cols, sortMultiple) => {
1099
+ const convertColumns = (0, _columns.flatColumns2)(cols).map((column, colIndex) => {
1100
+ if (!column?.field && !column?.key) {
1101
+ return _rcMasterUi.Table.SELECTION_COLUMN;
1102
+ }
1103
+ if (column.dataIndex === 'index' || column.field === 'index' || column.dataIndex === '#' || column.dataIndex === '#') {
1104
+ return {
1105
+ ...column
1106
+ };
1107
+ }
1108
+ if ((column.key || column.field) === 'command') {
1109
+ return {
1110
+ ...column
1111
+ };
1112
+ }
1113
+ return {
1114
+ ...column,
1115
+ key: column.field ?? column.dataIndex ?? column.key,
1116
+ sorter: column.sorter === false ? undefined : {
1117
+ compare: a => a,
1118
+ multiple: sortMultiple ? colIndex : undefined
1119
+ }
1120
+ };
1121
+ });
1122
+
1123
+ // @ts-ignore
1124
+ return cols.map(column => {
1125
+ const find = convertColumns.find(it => it.key === column.field);
1126
+ if (!column?.field && !column?.key) {
1127
+ return _rcMasterUi.Table.SELECTION_COLUMN;
1128
+ }
1129
+ if (find) {
1130
+ return {
1131
+ ...find
1132
+ };
1133
+ }
1134
+
1135
+ // Xử lý đệ quy cho children
1136
+ if (column.children?.length) {
1137
+ return {
1138
+ ...column,
1139
+ key: column.field ?? column.dataIndex ?? column.key,
1140
+ ellipsis: column.ellipsis !== false,
1141
+ align: column.textAlign ?? column.align,
1142
+ children: transformColumns(column.children, convertColumns)
1143
+ };
1144
+ }
1145
+ });
1146
+ };
1147
+ exports.transformColumns1 = transformColumns1;
1148
+ const removeColumns = (columns, groupColumns) => {
1149
+ const ttt = [...columns];
1150
+
1151
+ // @ts-ignore
1152
+ return ttt.filter(column => !groupColumns.includes(column.field)).map(column => {
1153
+ const newCol = {
1154
+ ...column
1155
+ };
1156
+ if (newCol.children) {
1157
+ newCol.children = removeColumns(newCol.children, groupColumns);
1158
+ }
1159
+ return newCol;
1160
+ });
1161
+ };
1162
+ exports.removeColumns = removeColumns;
1163
+ const convertFlatColumn = array => {
1164
+ const tmp = [...array];
1165
+ let result = [];
1166
+ tmp.forEach(item => {
1167
+ if (item.children) {
1168
+ result = result.concat(convertFlatColumn(item.children));
1169
+ } else {
1170
+ result.push(item);
1171
+ }
1172
+ });
1173
+ return result;
1174
+ };
1175
+
1176
+ // export const getColumnsByKeys = (columns: ColumnsTable, keys: string[]) => {
1177
+ // if (!columns || !keys) {
1178
+ // return[]
1179
+ // }
1180
+ //
1181
+ // return flatColumns2(columns).filter((column) => keys.includes(column.field as string)).map((it) => {
1182
+ // return {...it, value: it.field, label: it.headerText}
1183
+ // })
1184
+ //
1185
+ //
1186
+ // }
1187
+ exports.convertFlatColumn = convertFlatColumn;