es-grid-template 1.2.0 → 1.2.2

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 (69) hide show
  1. package/assets/index.css +695 -0
  2. package/assets/index.scss +1063 -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.d.ts +1 -0
  14. package/es/grid-component/InternalTable.js +150 -249
  15. package/es/grid-component/TableGrid.d.ts +4 -1
  16. package/es/grid-component/TableGrid.js +31 -70
  17. package/es/grid-component/hooks/{useColumns → columns}/index.d.ts +2 -2
  18. package/es/grid-component/hooks/{useColumns → columns}/index.js +20 -16
  19. package/es/grid-component/hooks/content/HeaderContent.d.ts +11 -0
  20. package/es/grid-component/hooks/content/HeaderContent.js +79 -0
  21. package/es/grid-component/hooks/content/TooltipContent.d.ts +13 -0
  22. package/es/grid-component/hooks/content/TooltipContent.js +74 -0
  23. package/es/grid-component/hooks/useColumns.d.ts +16 -0
  24. package/es/grid-component/hooks/useColumns.js +280 -0
  25. package/es/grid-component/hooks/utils.d.ts +26 -1
  26. package/es/grid-component/hooks/utils.js +331 -1
  27. package/es/grid-component/index.js +3 -1
  28. package/es/grid-component/styles.scss +365 -68
  29. package/es/grid-component/table/Grid.d.ts +2 -0
  30. package/es/grid-component/table/Grid.js +18 -6
  31. package/es/grid-component/table/GridEdit.d.ts +4 -1
  32. package/es/grid-component/table/GridEdit.js +941 -307
  33. package/es/grid-component/table/Group.d.ts +13 -0
  34. package/es/grid-component/table/Group.js +154 -0
  35. package/es/grid-component/type.d.ts +39 -2
  36. package/lib/grid-component/ColumnsChoose.d.ts +1 -0
  37. package/lib/grid-component/ColumnsChoose.js +62 -27
  38. package/lib/grid-component/ColumnsGroup/ColumnsGroup.d.ts +12 -0
  39. package/lib/grid-component/ColumnsGroup/ColumnsGroup.js +234 -0
  40. package/lib/grid-component/ColumnsGroup/index.d.ts +1 -0
  41. package/lib/grid-component/ColumnsGroup/index.js +16 -0
  42. package/lib/grid-component/ConvertColumnTable.d.ts +7 -0
  43. package/lib/grid-component/ConvertColumnTable.js +152 -0
  44. package/lib/grid-component/EditableCell.js +1 -1
  45. package/lib/grid-component/GridStyle.js +1 -1
  46. package/lib/grid-component/InternalTable.d.ts +1 -0
  47. package/lib/grid-component/InternalTable.js +144 -249
  48. package/lib/grid-component/TableGrid.d.ts +4 -1
  49. package/lib/grid-component/TableGrid.js +26 -68
  50. package/lib/grid-component/hooks/{useColumns → columns}/index.d.ts +2 -2
  51. package/lib/grid-component/hooks/{useColumns → columns}/index.js +20 -16
  52. package/lib/grid-component/hooks/content/HeaderContent.d.ts +11 -0
  53. package/lib/grid-component/hooks/content/HeaderContent.js +86 -0
  54. package/lib/grid-component/hooks/content/TooltipContent.d.ts +13 -0
  55. package/lib/grid-component/hooks/content/TooltipContent.js +81 -0
  56. package/lib/grid-component/hooks/useColumns.d.ts +16 -0
  57. package/lib/grid-component/hooks/useColumns.js +291 -0
  58. package/lib/grid-component/hooks/utils.d.ts +26 -1
  59. package/lib/grid-component/hooks/utils.js +347 -5
  60. package/lib/grid-component/index.js +2 -1
  61. package/lib/grid-component/styles.scss +365 -68
  62. package/lib/grid-component/table/Grid.d.ts +2 -0
  63. package/lib/grid-component/table/Grid.js +18 -6
  64. package/lib/grid-component/table/GridEdit.d.ts +4 -1
  65. package/lib/grid-component/table/GridEdit.js +939 -305
  66. package/lib/grid-component/table/Group.d.ts +13 -0
  67. package/lib/grid-component/table/Group.js +163 -0
  68. package/lib/grid-component/type.d.ts +39 -2
  69. package/package.json +106 -105
@@ -4,15 +4,19 @@ 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.addRows8 = addRows8;
9
+ exports.customWeekStartEndFormat = exports.countItemsBeforeIndex = exports.convertLabelToTitle = exports.convertFlatColumn = exports.convertDayjsToDate = exports.convertDateToDayjs = exports.convertArrayWithIndent = exports.checkThousandSeparator = exports.checkFieldKey = exports.checkDecimalSeparator = void 0;
8
10
  exports.findAllChildrenKeys = findAllChildrenKeys;
9
- exports.getEditType = exports.getDatepickerFormat = exports.getDateString = exports.getColumnsVisible = exports.getAllVisibleKeys = exports.genPresets = exports.flattenData = exports.flattenArray = void 0;
11
+ 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
12
  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;
13
+ exports.updateData = exports.updateColumnsByGroup = exports.updateColumns = exports.updateArrayByKey = exports.transformColumns1 = exports.transformColumns = exports.totalFixedWidth = exports.sumDataByField = exports.removeColumns = exports.parseBooleanToValue = exports.newGuid = 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
14
  var _dayjs = _interopRequireDefault(require("dayjs"));
13
15
  var _moment = _interopRequireDefault(require("moment/moment"));
14
16
  var _uuid = require("uuid");
15
17
  var _colors = require("@ant-design/colors");
18
+ var _rcMasterUi = require("rc-master-ui");
19
+ var _columns = require("./columns");
16
20
  const newGuid = () => {
17
21
  for (let i = 0; i < 20; i++) {
18
22
  // @ts-ignore
@@ -167,6 +171,27 @@ const updateColumns = (columns, includes) => {
167
171
  });
168
172
  };
169
173
  exports.updateColumns = updateColumns;
174
+ const updateColumnsByGroup = (columns, columnsGroup) => {
175
+ return columns.map(column => {
176
+ const newColumn = {
177
+ ...column
178
+ };
179
+ let hasVisibleChild = false;
180
+ if (!column.key && !column.dataIndex) {
181
+ return column;
182
+ }
183
+ if (newColumn.children) {
184
+ newColumn.children = updateColumnsByGroup(newColumn.children, columnsGroup);
185
+ hasVisibleChild = newColumn.children.some(child => !child.hidden);
186
+ }
187
+ newColumn.hidden = newColumn.key && columnsGroup.includes(newColumn.key);
188
+ if (newColumn.children && newColumn.children.length > 0) {
189
+ newColumn.hidden = !hasVisibleChild;
190
+ }
191
+ return newColumn;
192
+ });
193
+ };
194
+ exports.updateColumnsByGroup = updateColumnsByGroup;
170
195
  const getDatepickerFormat = (type, col) => {
171
196
  const typeFormat = type ? type.toLowerCase() : '';
172
197
  switch (typeFormat) {
@@ -224,7 +249,10 @@ const getTypeFilter = col => {
224
249
  exports.getTypeFilter = getTypeFilter;
225
250
  const updateArrayByKey = (arr, element, key) => {
226
251
  if (arr) {
227
- return arr.map(item => {
252
+ return arr.map(it => {
253
+ const item = {
254
+ ...it
255
+ };
228
256
  if (item[key] === element[key]) {
229
257
  return {
230
258
  ...item,
@@ -426,4 +454,318 @@ const getRowNumber = (array, rowKey, key) => {
426
454
  const flattArray = flattenData('children', array);
427
455
  return flattArray.findIndex(it => it[key] === rowKey);
428
456
  };
429
- exports.getRowNumber = getRowNumber;
457
+ exports.getRowNumber = getRowNumber;
458
+ const getDefaultValue = defaultValue => {
459
+ if (defaultValue && typeof defaultValue === 'function') {
460
+ return defaultValue();
461
+ }
462
+ return defaultValue;
463
+ };
464
+ exports.getDefaultValue = getDefaultValue;
465
+ const addRowIdArray = inputArray => {
466
+ if (inputArray) {
467
+ return inputArray.map(item => {
468
+ if (item.children && item.children.length > 0) {
469
+ // item.children = convertArrayWithIndent(item.children)
470
+ item.children = addRowIdArray(item.children);
471
+ }
472
+
473
+ // return { ...item, rowId: item.rowId ? item.rowId : (item.id ? item.id : newGuid())}
474
+ return {
475
+ ...item,
476
+ rowId: item.rowId ?? item.id ?? newGuid()
477
+ };
478
+ });
479
+ } else {
480
+ return [];
481
+ }
482
+ };
483
+ exports.addRowIdArray = addRowIdArray;
484
+ const findItemByKey = (array, key, value) => {
485
+ for (let i = 0; i < array.length; i++) {
486
+ const item = array[i];
487
+ if (item[key] === value) {
488
+ return item;
489
+ }
490
+ if (item.children && item.children.length > 0) {
491
+ const foundInChildren = findItemByKey(item.children, key, value);
492
+ if (foundInChildren) {
493
+ return foundInChildren;
494
+ }
495
+ }
496
+ }
497
+ return null;
498
+ };
499
+ exports.findItemByKey = findItemByKey;
500
+ const getLastSelectCell = selectCells => {
501
+ if (selectCells.size === 0) {
502
+ return {
503
+ row: 0,
504
+ col: 0
505
+ };
506
+ }
507
+ const lastValue = [...selectCells].at(-1);
508
+ const [row, col] = lastValue.split("-").map(Number);
509
+ return {
510
+ row,
511
+ col
512
+ };
513
+ };
514
+ exports.getLastSelectCell = getLastSelectCell;
515
+ const getFirstSelectCell = selectCells => {
516
+ if (selectCells.size === 0) {
517
+ return {
518
+ row: 0,
519
+ col: 0
520
+ };
521
+ }
522
+ const firstValue = selectCells.values().next().value;
523
+ const [row, col] = firstValue.split("-").map(Number);
524
+ return {
525
+ row,
526
+ col
527
+ };
528
+ };
529
+
530
+ // export const getLastSelectCell = (selectCells: any): {row: number, col: number} => {
531
+ //
532
+ // if (selectCells.size === 0) {
533
+ // return {row: 0, col: 0}
534
+ // }
535
+ // const lastValue = [...selectCells].pop();
536
+ //
537
+ // const [row, col] = lastValue.split("-").map(Number);
538
+ // return {row, col};
539
+ //
540
+ // }
541
+ exports.getFirstSelectCell = getFirstSelectCell;
542
+ const getRowsPasteIndex = pasteRows => {
543
+ if (!pasteRows) {
544
+ return [];
545
+ }
546
+ const result = Array.from(pasteRows).map(item => parseInt(item.split("-")[0]));
547
+ return [...new Set(result)];
548
+ };
549
+ exports.getRowsPasteIndex = getRowsPasteIndex;
550
+ function addRows8(arr, n) {
551
+ if (!Array.isArray(arr) || arr.length === 0) return {
552
+ combined: arr,
553
+ addedRows: []
554
+ };
555
+ const m = arr.length;
556
+ const numCols = arr[0].length;
557
+ const addedRows = [];
558
+
559
+ // Hàm kiểm tra kiểu date hợp lệ
560
+ const isValidDate = d => {
561
+ return !isNaN(Date.parse(d));
562
+ };
563
+
564
+ // Lấy giá trị mẫu của cột j từ hàng đầu tiên
565
+ const getSample = j => arr[0][j];
566
+
567
+ // Xác định chế độ xử lý cho mỗi cột:
568
+ // mode = 'number-stepping' | 'date-stepping' | 'number-constant' | 'cycle'
569
+ const modes = [];
570
+ const steps = []; // bước tăng, nếu có (cho number hoặc date)
571
+
572
+ for (let j = 0; j < numCols; j++) {
573
+ const sample = getSample(j);
574
+ if (m === 1) {
575
+ // 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.
576
+ if (typeof sample === "number") {
577
+ modes[j] = "number-constant";
578
+ } else if (isValidDate(sample)) {
579
+ modes[j] = "date-stepping";
580
+ steps[j] = 24 * 3600 * 1000; // 1 ngày = 86400000 ms
581
+ } else {
582
+ modes[j] = "cycle";
583
+ }
584
+ } else if (m === 2) {
585
+ // 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
586
+ const first = arr[0][j],
587
+ second = arr[1][j];
588
+ if (typeof first === "number" && typeof second === "number") {
589
+ modes[j] = "number-stepping";
590
+ steps[j] = second - first;
591
+ } else if (isValidDate(first) && isValidDate(second)) {
592
+ modes[j] = "date-stepping";
593
+ steps[j] = Date.parse(second) - Date.parse(first);
594
+ } else {
595
+ modes[j] = "cycle";
596
+ }
597
+ } else {
598
+ // Nếu mảng có >2 hàng
599
+ const first = arr[0][j],
600
+ second = arr[1][j],
601
+ third = arr[2][j];
602
+ if (typeof first === "number" && typeof second === "number" && typeof third === "number") {
603
+ const step1 = second - first;
604
+ const step2 = third - second;
605
+ if (step1 === step2) {
606
+ modes[j] = "number-stepping";
607
+ steps[j] = step1;
608
+ } else {
609
+ modes[j] = "cycle";
610
+ }
611
+ } else if (isValidDate(first) && isValidDate(second) && isValidDate(third)) {
612
+ const step1 = Date.parse(second) - Date.parse(first);
613
+ const step2 = Date.parse(third) - Date.parse(second);
614
+ if (step1 === step2) {
615
+ modes[j] = "date-stepping";
616
+ steps[j] = step1;
617
+ } else {
618
+ modes[j] = "cycle";
619
+ }
620
+ } else {
621
+ modes[j] = "cycle";
622
+ }
623
+ }
624
+ }
625
+
626
+ // Tạo các dòng mới (thêm n dòng)
627
+ // 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
628
+ // Nếu chế độ là cycle thì dùng arr[i mod m][j]
629
+ for (let i = 0; i < n; i++) {
630
+ const newRow = [];
631
+ for (let j = 0; j < numCols; j++) {
632
+ let newValue;
633
+ switch (modes[j]) {
634
+ case "number-constant":
635
+ // Mảng có 1 hàng, số giữ nguyên
636
+ newValue = arr[0][j];
637
+ break;
638
+ case "number-stepping":
639
+ {
640
+ // Lấy giá trị cuối của cột j trong mảng ban đầu
641
+ const lastValue = arr[m - 1][j];
642
+ newValue = lastValue + (i + 1) * steps[j];
643
+ }
644
+ break;
645
+ case "date-stepping":
646
+ {
647
+ // 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
648
+ const lastDate = new Date(arr[m - 1][j]);
649
+ const newTime = lastDate.getTime() + (i + 1) * steps[j];
650
+ newValue = (0, _moment.default)(new Date(newTime)).format();
651
+ }
652
+ break;
653
+ case "cycle":
654
+ default:
655
+ // Lặp lại nội dung theo vòng tròn: dùng hàng thứ (i mod m)
656
+ newValue = arr[i % m][j];
657
+ break;
658
+ }
659
+ newRow.push(newValue);
660
+ }
661
+ addedRows.push(newRow);
662
+ }
663
+ const combined = arr.concat(addedRows);
664
+ return {
665
+ combined,
666
+ addedRows
667
+ };
668
+ }
669
+ const transformColumns = (cols, convertColumns, t) => {
670
+ // @ts-ignore
671
+ return cols.map(column => {
672
+ const find = convertColumns.find(it => it.key === column.field);
673
+ if (!column?.field && !column?.key) {
674
+ return _rcMasterUi.Table.SELECTION_COLUMN;
675
+ }
676
+ if (find) {
677
+ return {
678
+ ...find
679
+ };
680
+ }
681
+
682
+ // Xử lý đệ quy cho children
683
+ if (column.children?.length) {
684
+ return {
685
+ ...column,
686
+ key: column.field ?? column.dataIndex ?? column.key,
687
+ title: t ? t(column.headerText) : column.headerText,
688
+ ellipsis: column.ellipsis !== false,
689
+ align: column.textAlign ?? column.align,
690
+ children: transformColumns(column.children, convertColumns)
691
+ };
692
+ }
693
+ });
694
+ };
695
+ exports.transformColumns = transformColumns;
696
+ const transformColumns1 = (cols, sortMultiple) => {
697
+ const convertColumns = (0, _columns.flatColumns2)(cols).map((column, colIndex) => {
698
+ if (!column?.field && !column?.key) {
699
+ return _rcMasterUi.Table.SELECTION_COLUMN;
700
+ }
701
+ if (column.dataIndex === 'index' || column.field === 'index' || column.dataIndex === '#' || column.dataIndex === '#') {
702
+ return {
703
+ ...column
704
+ };
705
+ }
706
+ if ((column.key || column.field) === 'command') {
707
+ return {
708
+ ...column
709
+ };
710
+ }
711
+ return {
712
+ ...column,
713
+ key: column.field ?? column.dataIndex ?? column.key,
714
+ sorter: column.sorter === false ? undefined : {
715
+ compare: a => a,
716
+ multiple: sortMultiple ? colIndex : undefined
717
+ }
718
+ };
719
+ });
720
+
721
+ // @ts-ignore
722
+ return cols.map(column => {
723
+ const find = convertColumns.find(it => it.key === column.field);
724
+ if (!column?.field && !column?.key) {
725
+ return _rcMasterUi.Table.SELECTION_COLUMN;
726
+ }
727
+ if (find) {
728
+ return {
729
+ ...find
730
+ };
731
+ }
732
+
733
+ // Xử lý đệ quy cho children
734
+ if (column.children?.length) {
735
+ return {
736
+ ...column,
737
+ key: column.field ?? column.dataIndex ?? column.key,
738
+ ellipsis: column.ellipsis !== false,
739
+ align: column.textAlign ?? column.align,
740
+ children: transformColumns(column.children, convertColumns)
741
+ };
742
+ }
743
+ });
744
+ };
745
+ exports.transformColumns1 = transformColumns1;
746
+ const removeColumns = (columns, groupColumns) => {
747
+ const ttt = [...columns];
748
+ return ttt.filter(column => !groupColumns.includes(column.field)).map(column => {
749
+ const newCol = {
750
+ ...column
751
+ };
752
+ if (newCol.children) {
753
+ newCol.children = removeColumns(newCol.children, groupColumns);
754
+ }
755
+ return newCol;
756
+ });
757
+ };
758
+ exports.removeColumns = removeColumns;
759
+ const convertFlatColumn = array => {
760
+ const tmp = [...array];
761
+ let result = [];
762
+ tmp.forEach(item => {
763
+ if (item.children) {
764
+ result = result.concat(convertFlatColumn(item.children));
765
+ } else {
766
+ result.push(item);
767
+ }
768
+ });
769
+ return result;
770
+ };
771
+ exports.convertFlatColumn = convertFlatColumn;
@@ -6,4 +6,5 @@ Object.defineProperty(exports, "__esModule", {
6
6
  });
7
7
  exports.default = void 0;
8
8
  var _InternalTable = _interopRequireDefault(require("./InternalTable"));
9
- var _default = exports.default = _InternalTable.default;
9
+ // import ConvertColumnTable from './ConvertColumnTable'
10
+ var _default = exports.default = _InternalTable.default; // export default ConvertColumnTable