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
@@ -2,6 +2,8 @@ import dayjs from "dayjs";
2
2
  import moment from "moment/moment";
3
3
  import { v4 as uuidv4 } from 'uuid';
4
4
  import { presetPalettes } from "@ant-design/colors";
5
+ import { Table } from "rc-master-ui";
6
+ import { flatColumns2 } from "./columns";
5
7
  export const newGuid = () => {
6
8
  for (let i = 0; i < 20; i++) {
7
9
  // @ts-ignore
@@ -143,6 +145,26 @@ export const updateColumns = (columns, includes) => {
143
145
  return newColumn;
144
146
  });
145
147
  };
148
+ export const updateColumnsByGroup = (columns, columnsGroup) => {
149
+ return columns.map(column => {
150
+ const newColumn = {
151
+ ...column
152
+ };
153
+ let hasVisibleChild = false;
154
+ if (!column.key && !column.dataIndex) {
155
+ return column;
156
+ }
157
+ if (newColumn.children) {
158
+ newColumn.children = updateColumnsByGroup(newColumn.children, columnsGroup);
159
+ hasVisibleChild = newColumn.children.some(child => !child.hidden);
160
+ }
161
+ newColumn.hidden = newColumn.key && columnsGroup.includes(newColumn.key);
162
+ if (newColumn.children && newColumn.children.length > 0) {
163
+ newColumn.hidden = !hasVisibleChild;
164
+ }
165
+ return newColumn;
166
+ });
167
+ };
146
168
  export const getDatepickerFormat = (type, col) => {
147
169
  const typeFormat = type ? type.toLowerCase() : '';
148
170
  switch (typeFormat) {
@@ -197,7 +219,10 @@ export const getTypeFilter = col => {
197
219
  };
198
220
  export const updateArrayByKey = (arr, element, key) => {
199
221
  if (arr) {
200
- return arr.map(item => {
222
+ return arr.map(it => {
223
+ const item = {
224
+ ...it
225
+ };
201
226
  if (item[key] === element[key]) {
202
227
  return {
203
228
  ...item,
@@ -381,4 +406,717 @@ export const getRowNumber = (array, rowKey, key) => {
381
406
  // const flattArray = flattenArray(array)
382
407
  const flattArray = flattenData('children', array);
383
408
  return flattArray.findIndex(it => it[key] === rowKey);
384
- };
409
+ };
410
+ export const getDefaultValue = defaultValue => {
411
+ if (defaultValue && typeof defaultValue === 'function') {
412
+ return defaultValue();
413
+ }
414
+ return defaultValue;
415
+ };
416
+ export const addRowIdArray = inputArray => {
417
+ if (inputArray) {
418
+ return inputArray.map(item => {
419
+ if (item.children && item.children.length > 0) {
420
+ // item.children = convertArrayWithIndent(item.children)
421
+ item.children = addRowIdArray(item.children);
422
+ }
423
+
424
+ // return { ...item, rowId: item.rowId ? item.rowId : (item.id ? item.id : newGuid())}
425
+ return {
426
+ ...item,
427
+ rowId: item.rowId ?? item.id ?? newGuid()
428
+ };
429
+ });
430
+ } else {
431
+ return [];
432
+ }
433
+ };
434
+ export const findItemByKey = (array, key, value) => {
435
+ for (let i = 0; i < array.length; i++) {
436
+ const item = array[i];
437
+ if (item[key] === value) {
438
+ return item;
439
+ }
440
+ if (item.children && item.children.length > 0) {
441
+ const foundInChildren = findItemByKey(item.children, key, value);
442
+ if (foundInChildren) {
443
+ return foundInChildren;
444
+ }
445
+ }
446
+ }
447
+ return null;
448
+ };
449
+ export const getLastSelectCell = selectCells => {
450
+ if (selectCells.size === 0) {
451
+ return {
452
+ row: 0,
453
+ col: 0
454
+ };
455
+ }
456
+ const lastValue = [...selectCells].at(-1);
457
+ const [row, col] = lastValue.split("-").map(Number);
458
+ return {
459
+ row,
460
+ col
461
+ };
462
+ };
463
+ export const getFirstSelectCell = selectCells => {
464
+ if (selectCells.size === 0) {
465
+ return {
466
+ row: 0,
467
+ col: 0
468
+ };
469
+ }
470
+ const firstValue = selectCells.values().next().value;
471
+ const [row, col] = firstValue.split("-").map(Number);
472
+ return {
473
+ row,
474
+ col
475
+ };
476
+ };
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
+ export const getRowsPasteIndex = pasteRows => {
491
+ if (!pasteRows) {
492
+ return [];
493
+ }
494
+ const result = Array.from(pasteRows).map(item => parseInt(item.split("-")[0]));
495
+ return [...new Set(result)];
496
+ };
497
+
498
+ // export const fff = [
499
+ // [1,'1998-11-03T18:20:45+07:00', "Fadel Groves", "C", true],
500
+ // ]
501
+ //
502
+ // export const oooo = [
503
+ // [1,'1998-11-03T18:20:45+07:00', "Fadel Groves", "C", true],
504
+ // [1,'1998-11-04T18:20:45+07:00', "Fadel Groves", "C", true],
505
+ // [1,'1998-11-05T18:20:45+07:00', "Fadel Groves", "C", true],
506
+ // [1,'1998-11-06T18:20:45+07:00', "Fadel Groves", "C", true],
507
+ // ]
508
+ //
509
+ // export const iii = [
510
+ // [1,'1998-11-03T18:20:45+07:00', "Fadel Groves", "C", true],
511
+ // [2,'1998-11-07T18:20:45+07:00', "Fahey Roads", "C", true],
512
+ // [3,'1998-11-19T18:20:45+07:00', "tess", "C", true],
513
+ // ]
514
+ //
515
+ // export const jjj = [
516
+ // [1,'1998-11-03T18:20:45+07:00', "Fadel Groves", "C", true],
517
+ // [2,'1998-11-07T18:20:45+07:00', "Fahey Roads", "C", true],
518
+ // [3,'1998-11-19T18:20:45+07:00', "tess", "C", true],
519
+ //
520
+ // [4,'1998-11-03T18:20:45+07:00', "Fadel Groves", "C", true],
521
+ // [5,'1998-11-07T18:20:45+07:00', "Fahey Roads", "C", true],
522
+ // [6,'1998-11-19T18:20:45+07:00', "tess", "C", true],
523
+ // ]
524
+ //
525
+ //
526
+ export const 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]];
527
+ //
528
+ // export const nnn = [
529
+ // [1,'1998-11-03T18:20:45+07:00', "Fadel Groves", "C", true],
530
+ // [2,'1998-11-04T18:20:45+07:00', "Fahey Roads", "C", true],
531
+ // [3,'1998-11-05T18:20:45+07:00', "tess", "C", true],
532
+ //
533
+ // [4,'1998-11-06T18:20:45+07:00', "Fadel Groves", "C", true],
534
+ // [5,'1998-11-07T18:20:45+07:00', "Fahey Roads", "C", true],
535
+ // [6,'1998-11-08T18:20:45+07:00', "tess", "C", true],
536
+ // ]
537
+
538
+ export function cloneRows(array, numRows) {
539
+ const result = [...array]; // Sao chép mảng ban đầu
540
+
541
+ for (let i = 0; i < numRows; i++) {
542
+ const lastId = result[result.length - 1][0]; // Lấy ID cuối cùng hiện có
543
+
544
+ for (let j = 0; j < array.length - 1; j++) {
545
+ // Nhân bản trừ dòng cuối
546
+ const newRow = [lastId + j + 1, array[j][1]]; // Tăng ID và giữ nguyên giá trị cột 2
547
+ result.push(newRow);
548
+ }
549
+ }
550
+ return result;
551
+ }
552
+ export function addRows1(arr, n) {
553
+ // const newArr = [...arr]; // Sao chép mảng gốc để không sửa đổi trực tiếp
554
+ // const baseIndex = arr[arr.length - 1][0]; // Lấy chỉ mục cuối cùng
555
+ //
556
+ // for (let i = 0; i < n; i++) {
557
+ // const newIndex = baseIndex + 1 + i;
558
+ // 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
559
+ // newArr.push(newRow);
560
+ // }
561
+ //
562
+ // return newArr;
563
+
564
+ const newArr = [...arr]; // Sao chép mảng gốc để không sửa đổi trực tiếp
565
+
566
+ if (arr.length === 1) {
567
+ // Nếu chỉ có một phần tử, lặp lại phần tử đó n lần
568
+ for (let i = 0; i < n; i++) {
569
+ newArr.push([...arr[0]]);
570
+ }
571
+ } else {
572
+ const baseIndex = arr[arr.length - 1][0]; // Lấy chỉ mục cuối cùng
573
+
574
+ for (let i = 0; i < n; i++) {
575
+ const newIndex = baseIndex + 1 + i;
576
+ 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
577
+ newArr.push(newRow);
578
+ }
579
+ }
580
+ return newArr;
581
+ }
582
+ export function addRows2(arr, n) {
583
+ const newArr = [...arr]; // Sao chép mảng gốc để không sửa đổi trực tiếp
584
+ const addedRows = [];
585
+ if (arr.length === 1) {
586
+ // Nếu chỉ có một phần tử, lặp lại phần tử đó n lần
587
+ for (let i = 0; i < n; i++) {
588
+ newArr.push([...arr[0]]);
589
+ addedRows.push([...arr[0]]);
590
+ }
591
+ } else {
592
+ const differences = [];
593
+ for (let i = 1; i < arr.length; i++) {
594
+ differences.push(arr[i][0] - arr[i - 1][0]);
595
+ }
596
+ const step = differences.reduce((a, b) => a + b, 0) / differences.length; // Tính khoảng cách trung bình
597
+
598
+ for (let i = 0; i < n; i++) {
599
+ const newIndex = newArr[newArr.length - 1][0] + step;
600
+ const newRow = [newIndex, ...arr[i % arr.length].slice(1)]; // Lặp lại nội dung theo vòng tròn
601
+ newArr.push(newRow);
602
+ addedRows.push(newRow);
603
+ }
604
+ }
605
+ return {
606
+ newArr,
607
+ addedRows
608
+ };
609
+ }
610
+ export function addRows(arr, n) {
611
+ const newArr = [...arr]; // Sao chép mảng gốc để không sửa đổi trực tiếp
612
+ const addedRows = [];
613
+ if (arr.length === 1) {
614
+ for (let i = 0; i < n; i++) {
615
+ newArr.push([...arr[0]]);
616
+ addedRows.push([...arr[0]]);
617
+ }
618
+ } else {
619
+ const diffs = arr[0].map((_, colIndex) => {
620
+ if (typeof arr[0][colIndex] === 'number') {
621
+ return arr[1][colIndex] - arr[0][colIndex];
622
+ } else if (!isNaN(Date.parse(arr[0][colIndex]))) {
623
+ console.log('Date.parse(arr[0][colIndex])', Date.parse(arr[0][colIndex]));
624
+ console.log('arr[0][colIndex]', arr[0][colIndex]);
625
+ // @ts-ignore
626
+ return new Date(arr[1][colIndex]) - new Date(arr[0][colIndex]);
627
+ }
628
+ return null;
629
+ });
630
+ console.log('diffs', diffs);
631
+ for (let i = 0; i < n; i++) {
632
+ const lastRow = [...newArr[newArr.length - 1]];
633
+ const newRow = lastRow.map((value, colIndex) => {
634
+ if (typeof value === 'number' && diffs[colIndex] !== null) {
635
+ return value + diffs[colIndex];
636
+ } else if (!isNaN(Date.parse(value)) && diffs[colIndex] !== null) {
637
+ const lastDate = new Date(value);
638
+ return moment(new Date(lastDate.getTime() + diffs[colIndex])).format();
639
+ } else return arr[i % arr.length][colIndex]; // Lặp lại nội dung theo vòng tròn
640
+ // arr[i % arr.length].slice(1)
641
+ // return value;
642
+ });
643
+ newArr.push(newRow);
644
+ addedRows.push(newRow);
645
+ }
646
+ }
647
+ return {
648
+ newArr,
649
+ addedRows
650
+ };
651
+ }
652
+ export function addRows4(arr, n) {
653
+ const newArr = [...arr]; // Sao chép mảng gốc để không sửa đổi trực tiếp
654
+ const addedRows = [];
655
+ if (arr.length === 1) {
656
+ for (let i = 0; i < n; i++) {
657
+ newArr.push([...arr[0]]);
658
+ addedRows.push([...arr[0]]);
659
+ }
660
+ } else {
661
+ const diffs = arr[0].map((_, colIndex) => {
662
+ if (typeof arr[0][colIndex] === 'number') {
663
+ return arr[1][colIndex] - arr[0][colIndex];
664
+ } else if (!isNaN(Date.parse(arr[0][colIndex]))) {
665
+ // @ts-ignore
666
+ return new Date(arr[1][colIndex]) - new Date(arr[0][colIndex]);
667
+ }
668
+ return null;
669
+ });
670
+ for (let i = 0; i < n; i++) {
671
+ const lastRow = [...newArr[newArr.length - 1]];
672
+ const newRow = lastRow.map((value, colIndex) => {
673
+ if (typeof value === 'number' && diffs[colIndex] !== null) {
674
+ return value + diffs[colIndex];
675
+ } else if (!isNaN(Date.parse(value)) && diffs[colIndex] !== null) {
676
+ const lastDate = new Date(value);
677
+ return new Date(lastDate.getTime() + diffs[colIndex]).toISOString();
678
+ } else if (typeof value === 'string') {
679
+ return arr[(i + 1) % arr.length][colIndex]; // Lặp lại nội dung theo vòng tròn
680
+ }
681
+ return value;
682
+ });
683
+ newArr.push(newRow);
684
+ addedRows.push(newRow);
685
+ }
686
+ }
687
+ return {
688
+ newArr,
689
+ addedRows
690
+ };
691
+ }
692
+ export function addRows6(arr, n) {
693
+ // const newArr = [...arr]; // Sao chép mảng gốc để không sửa đổi trực tiếp
694
+ // const addedRows = [];
695
+ //
696
+ // if (arr.length === 1) {
697
+ // for (let i = 0; i < n; i++) {
698
+ // newArr.push([...arr[0]]);
699
+ // addedRows.push([...arr[0]]);
700
+ // }
701
+ // } else {
702
+ // const diffs = arr[0].map((_: any, colIndex: number) => {
703
+ // if (typeof arr[0][colIndex] === 'number') {
704
+ // return arr[1][colIndex] - arr[0][colIndex];
705
+ // } else if (!isNaN(Date.parse(arr[0][colIndex])) && arr.length === 2) {
706
+ // // @ts-ignore
707
+ // return new Date(arr[1][colIndex]) - new Date(arr[0][colIndex]);
708
+ // }
709
+ // return null;
710
+ // });
711
+ //
712
+ // for (let i = 0; i < n; i++) {
713
+ // const lastRow = [...newArr[newArr.length - 1]];
714
+ //
715
+ // const newRow = lastRow.map((value, colIndex) => {
716
+ // if (typeof value === 'number' && diffs[colIndex] !== null) {
717
+ // return value + diffs[colIndex];
718
+ // } else if (!isNaN(Date.parse(value))) {
719
+ // if (arr.length > 2) {
720
+ // return arr[(i) % arr.length][colIndex]; // Lặp lại nội dung theo vòng tròn
721
+ // } else if (diffs[colIndex] !== null) {
722
+ // const lastDate = new Date(value);
723
+ // return new Date(lastDate.getTime() + diffs[colIndex]).toISOString();
724
+ // }
725
+ // } else if (typeof value === 'string') {
726
+ // return arr[(i) % arr.length][colIndex]; // Lặp lại nội dung theo vòng tròn
727
+ // }
728
+ // return value;
729
+ // });
730
+ //
731
+ // newArr.push(newRow);
732
+ // addedRows.push(newRow);
733
+ // }
734
+ // }
735
+ //
736
+ // return { newArr, addedRows };
737
+
738
+ const newArr = [...arr]; // Sao chép mảng gốc để không sửa đổi trực tiếp
739
+ const addedRows = [];
740
+ if (arr.length === 1) {
741
+ for (let i = 0; i < n; i++) {
742
+ newArr.push([...arr[0]]);
743
+ addedRows.push([...arr[0]]);
744
+ }
745
+ } else {
746
+ const diffs = arr[0].map((_, colIndex) => {
747
+ if (typeof arr[0][colIndex] === 'number') {
748
+ return arr[1][colIndex] - arr[0][colIndex];
749
+ } else if (!isNaN(Date.parse(arr[0][colIndex]))) {
750
+ // @ts-ignore
751
+ const dateDiffs = arr.slice(1).map((row, i) => new Date(row[colIndex]) - new Date(arr[i][colIndex]));
752
+ const avgDiff = dateDiffs.reduce((a, b) => a + b, 0) / dateDiffs.length;
753
+ return avgDiff || null;
754
+ }
755
+ return null;
756
+ });
757
+ for (let i = 0; i < n; i++) {
758
+ const lastRow = [...newArr[newArr.length - 1]];
759
+ const newRow = lastRow.map((value, colIndex) => {
760
+ if (typeof value === 'number' && diffs[colIndex] !== null) {
761
+ return value + diffs[colIndex];
762
+ } else if (!isNaN(Date.parse(value)) && diffs[colIndex] !== null) {
763
+ const lastDate = new Date(value);
764
+ return new Date(lastDate.getTime() + diffs[colIndex]).toISOString();
765
+ } else {
766
+ return arr[i % arr.length][colIndex]; // Lặp lại nội dung theo vòng tròn
767
+ }
768
+ });
769
+ newArr.push(newRow);
770
+ addedRows.push(newRow);
771
+ }
772
+ }
773
+ return {
774
+ newArr,
775
+ addedRows
776
+ };
777
+ }
778
+ export function addRows7(arr, n) {
779
+ if (!Array.isArray(arr) || arr.length === 0) return arr;
780
+ const m = arr.length;
781
+ const numCols = arr[0].length;
782
+ const newRows = [];
783
+
784
+ // Hàm kiểm tra kiểu date hợp lệ
785
+ const isValidDate = d => {
786
+ return !isNaN(Date.parse(d));
787
+ };
788
+
789
+ // Lấy giá trị mẫu của cột j từ hàng i (i thuộc [0, m-1])
790
+ const getSample = j => arr[0][j];
791
+
792
+ // Xác định cho mỗi cột chế độ xử lý:
793
+ // mode = 'number-stepping' | 'date-stepping' | 'cycle'
794
+ const modes = [];
795
+ const steps = []; // bước tăng, nếu có (cho number hoặc date)
796
+
797
+ for (let j = 0; j < numCols; j++) {
798
+ const sample = getSample(j);
799
+ if (m === 1) {
800
+ // 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.
801
+ if (typeof sample === "number") {
802
+ modes[j] = "number-constant";
803
+ } else if (isValidDate(sample)) {
804
+ modes[j] = "date-stepping";
805
+ steps[j] = 24 * 3600 * 1000; // 1 ngày = 86400000 ms
806
+ } else {
807
+ modes[j] = "cycle";
808
+ }
809
+ } else if (m === 2) {
810
+ // 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
811
+ const first = arr[0][j],
812
+ second = arr[1][j];
813
+ if (typeof first === "number" && typeof second === "number") {
814
+ modes[j] = "number-stepping";
815
+ steps[j] = second - first;
816
+ } else if (isValidDate(first) && isValidDate(second)) {
817
+ modes[j] = "date-stepping";
818
+ steps[j] = Date.parse(second) - Date.parse(first);
819
+ } else {
820
+ modes[j] = "cycle";
821
+ }
822
+ } else {
823
+ // mảng có >2 hàng
824
+ const first = arr[0][j],
825
+ second = arr[1][j],
826
+ third = arr[2][j];
827
+ if (typeof first === "number" && typeof second === "number" && typeof third === "number") {
828
+ const step1 = second - first;
829
+ const step2 = third - second;
830
+ if (step1 === step2) {
831
+ modes[j] = "number-stepping";
832
+ steps[j] = step1;
833
+ } else {
834
+ modes[j] = "cycle";
835
+ }
836
+ } else if (isValidDate(first) && isValidDate(second) && isValidDate(third)) {
837
+ const step1 = Date.parse(second) - Date.parse(first);
838
+ const step2 = Date.parse(third) - Date.parse(second);
839
+ if (step1 === step2) {
840
+ modes[j] = "date-stepping";
841
+ steps[j] = step1;
842
+ } else {
843
+ modes[j] = "cycle";
844
+ }
845
+ } else {
846
+ modes[j] = "cycle";
847
+ }
848
+ }
849
+ }
850
+
851
+ // Tạo các dòng mới (thêm n dòng)
852
+ // 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
853
+ // Nếu chế độ là cycle thì dùng arr[i mod m][j]
854
+ for (let i = 0; i < n; i++) {
855
+ const newRow = [];
856
+ for (let j = 0; j < numCols; j++) {
857
+ let newValue;
858
+ switch (modes[j]) {
859
+ case "number-constant":
860
+ // mảng có 1 hàng, số giữ nguyên
861
+ newValue = arr[0][j];
862
+ break;
863
+ case "number-stepping":
864
+ {
865
+ // lấy giá trị cuối của cột j trong mảng ban đầu
866
+ const lastValue = arr[m - 1][j];
867
+ newValue = lastValue + (i + 1) * steps[j];
868
+ }
869
+ break;
870
+ case "date-stepping":
871
+ {
872
+ // 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ũ)
873
+ const lastDate = new Date(arr[m - 1][j]);
874
+ const newTime = lastDate.getTime() + (i + 1) * steps[j];
875
+ // Giữ định dạng ISO với timezone tương tự nếu cần.
876
+ newValue = new Date(newTime).toISOString();
877
+ }
878
+ break;
879
+ case "cycle":
880
+ default:
881
+ // Lặp lại nội dung theo vòng tròn: dùng hàng thứ (i mod m)
882
+ newValue = arr[i % m][j];
883
+ break;
884
+ }
885
+ newRow.push(newValue);
886
+ }
887
+ newRows.push(newRow);
888
+ }
889
+ return arr.concat(newRows);
890
+ }
891
+ export function addRows8(arr, n) {
892
+ if (!Array.isArray(arr) || arr.length === 0) return {
893
+ combined: arr,
894
+ addedRows: []
895
+ };
896
+ const m = arr.length;
897
+ const numCols = arr[0].length;
898
+ const addedRows = [];
899
+
900
+ // Hàm kiểm tra kiểu date hợp lệ
901
+ const isValidDate = d => {
902
+ return !isNaN(Date.parse(d));
903
+ };
904
+
905
+ // Lấy giá trị mẫu của cột j từ hàng đầu tiên
906
+ const getSample = j => arr[0][j];
907
+
908
+ // Xác định chế độ xử lý cho mỗi cột:
909
+ // mode = 'number-stepping' | 'date-stepping' | 'number-constant' | 'cycle'
910
+ const modes = [];
911
+ const steps = []; // bước tăng, nếu có (cho number hoặc date)
912
+
913
+ for (let j = 0; j < numCols; j++) {
914
+ const sample = getSample(j);
915
+ if (m === 1) {
916
+ // 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.
917
+ if (typeof sample === "number") {
918
+ modes[j] = "number-constant";
919
+ } else if (isValidDate(sample)) {
920
+ modes[j] = "date-stepping";
921
+ steps[j] = 24 * 3600 * 1000; // 1 ngày = 86400000 ms
922
+ } else {
923
+ modes[j] = "cycle";
924
+ }
925
+ } else if (m === 2) {
926
+ // 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
927
+ const first = arr[0][j],
928
+ second = arr[1][j];
929
+ if (typeof first === "number" && typeof second === "number") {
930
+ modes[j] = "number-stepping";
931
+ steps[j] = second - first;
932
+ } else if (isValidDate(first) && isValidDate(second)) {
933
+ modes[j] = "date-stepping";
934
+ steps[j] = Date.parse(second) - Date.parse(first);
935
+ } else {
936
+ modes[j] = "cycle";
937
+ }
938
+ } else {
939
+ // Nếu mảng có >2 hàng
940
+ const first = arr[0][j],
941
+ second = arr[1][j],
942
+ third = arr[2][j];
943
+ if (typeof first === "number" && typeof second === "number" && typeof third === "number") {
944
+ const step1 = second - first;
945
+ const step2 = third - second;
946
+ if (step1 === step2) {
947
+ modes[j] = "number-stepping";
948
+ steps[j] = step1;
949
+ } else {
950
+ modes[j] = "cycle";
951
+ }
952
+ } else if (isValidDate(first) && isValidDate(second) && isValidDate(third)) {
953
+ const step1 = Date.parse(second) - Date.parse(first);
954
+ const step2 = Date.parse(third) - Date.parse(second);
955
+ if (step1 === step2) {
956
+ modes[j] = "date-stepping";
957
+ steps[j] = step1;
958
+ } else {
959
+ modes[j] = "cycle";
960
+ }
961
+ } else {
962
+ modes[j] = "cycle";
963
+ }
964
+ }
965
+ }
966
+
967
+ // Tạo các dòng mới (thêm n dòng)
968
+ // 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
969
+ // Nếu chế độ là cycle thì dùng arr[i mod m][j]
970
+ for (let i = 0; i < n; i++) {
971
+ const newRow = [];
972
+ for (let j = 0; j < numCols; j++) {
973
+ let newValue;
974
+ switch (modes[j]) {
975
+ case "number-constant":
976
+ // Mảng có 1 hàng, số giữ nguyên
977
+ newValue = arr[0][j];
978
+ break;
979
+ case "number-stepping":
980
+ {
981
+ // Lấy giá trị cuối của cột j trong mảng ban đầu
982
+ const lastValue = arr[m - 1][j];
983
+ newValue = lastValue + (i + 1) * steps[j];
984
+ }
985
+ break;
986
+ case "date-stepping":
987
+ {
988
+ // 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
989
+ const lastDate = new Date(arr[m - 1][j]);
990
+ const newTime = lastDate.getTime() + (i + 1) * steps[j];
991
+ newValue = moment(new Date(newTime)).format();
992
+ }
993
+ break;
994
+ case "cycle":
995
+ default:
996
+ // Lặp lại nội dung theo vòng tròn: dùng hàng thứ (i mod m)
997
+ newValue = arr[i % m][j];
998
+ break;
999
+ }
1000
+ newRow.push(newValue);
1001
+ }
1002
+ addedRows.push(newRow);
1003
+ }
1004
+ const combined = arr.concat(addedRows);
1005
+ return {
1006
+ combined,
1007
+ addedRows
1008
+ };
1009
+ }
1010
+ export const transformColumns = (cols, convertColumns, t) => {
1011
+ // @ts-ignore
1012
+ return cols.map(column => {
1013
+ const find = convertColumns.find(it => it.key === column.field);
1014
+ if (!column?.field && !column?.key) {
1015
+ return Table.SELECTION_COLUMN;
1016
+ }
1017
+ if (find) {
1018
+ return {
1019
+ ...find
1020
+ };
1021
+ }
1022
+
1023
+ // Xử lý đệ quy cho children
1024
+ if (column.children?.length) {
1025
+ return {
1026
+ ...column,
1027
+ key: column.field ?? column.dataIndex ?? column.key,
1028
+ title: t ? t(column.headerText ?? column.title) : column.headerText ?? column.title,
1029
+ ellipsis: column.ellipsis !== false,
1030
+ align: column.textAlign ?? column.align,
1031
+ children: transformColumns(column.children, convertColumns)
1032
+ };
1033
+ }
1034
+ });
1035
+ };
1036
+ export const transformColumns1 = (cols, sortMultiple) => {
1037
+ const convertColumns = flatColumns2(cols).map((column, colIndex) => {
1038
+ if (!column?.field && !column?.key) {
1039
+ return Table.SELECTION_COLUMN;
1040
+ }
1041
+ if (column.dataIndex === 'index' || column.field === 'index' || column.dataIndex === '#' || column.dataIndex === '#') {
1042
+ return {
1043
+ ...column
1044
+ };
1045
+ }
1046
+ if ((column.key || column.field) === 'command') {
1047
+ return {
1048
+ ...column
1049
+ };
1050
+ }
1051
+ return {
1052
+ ...column,
1053
+ key: column.field ?? column.dataIndex ?? column.key,
1054
+ sorter: column.sorter === false ? undefined : {
1055
+ compare: a => a,
1056
+ multiple: sortMultiple ? colIndex : undefined
1057
+ }
1058
+ };
1059
+ });
1060
+
1061
+ // @ts-ignore
1062
+ return cols.map(column => {
1063
+ const find = convertColumns.find(it => it.key === column.field);
1064
+ if (!column?.field && !column?.key) {
1065
+ return Table.SELECTION_COLUMN;
1066
+ }
1067
+ if (find) {
1068
+ return {
1069
+ ...find
1070
+ };
1071
+ }
1072
+
1073
+ // Xử lý đệ quy cho children
1074
+ if (column.children?.length) {
1075
+ return {
1076
+ ...column,
1077
+ key: column.field ?? column.dataIndex ?? column.key,
1078
+ ellipsis: column.ellipsis !== false,
1079
+ align: column.textAlign ?? column.align,
1080
+ children: transformColumns(column.children, convertColumns)
1081
+ };
1082
+ }
1083
+ });
1084
+ };
1085
+ export const removeColumns = (columns, groupColumns) => {
1086
+ const ttt = [...columns];
1087
+
1088
+ // @ts-ignore
1089
+ return ttt.filter(column => !groupColumns.includes(column.field)).map(column => {
1090
+ const newCol = {
1091
+ ...column
1092
+ };
1093
+ if (newCol.children) {
1094
+ newCol.children = removeColumns(newCol.children, groupColumns);
1095
+ }
1096
+ return newCol;
1097
+ });
1098
+ };
1099
+ export const convertFlatColumn = array => {
1100
+ const tmp = [...array];
1101
+ let result = [];
1102
+ tmp.forEach(item => {
1103
+ if (item.children) {
1104
+ result = result.concat(convertFlatColumn(item.children));
1105
+ } else {
1106
+ result.push(item);
1107
+ }
1108
+ });
1109
+ return result;
1110
+ };
1111
+
1112
+ // export const getColumnsByKeys = (columns: ColumnsTable, keys: string[]) => {
1113
+ // if (!columns || !keys) {
1114
+ // return[]
1115
+ // }
1116
+ //
1117
+ // return flatColumns2(columns).filter((column) => keys.includes(column.field as string)).map((it) => {
1118
+ // return {...it, value: it.field, label: it.headerText}
1119
+ // })
1120
+ //
1121
+ //
1122
+ // }