es-grid-template 1.8.64 → 1.8.66

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 (222) hide show
  1. package/es/grid-component/TempTable.d.ts +2 -2
  2. package/es/grid-component/TempTable.js +5 -5
  3. package/es/grid-component/hooks/index.js +0 -1
  4. package/es/grid-component/hooks/useLazyKVMap.d.ts +1 -1
  5. package/es/grid-component/hooks/useLazyKVMap.js +0 -4
  6. package/es/grid-component/hooks/utils.d.ts +1 -8
  7. package/es/grid-component/hooks/utils.js +176 -144
  8. package/es/grid-component/index.d.ts +1 -1
  9. package/es/grid-component/index.js +0 -4
  10. package/es/grid-component/styles.scss +1394 -1394
  11. package/es/grid-component/type.d.ts +0 -407
  12. package/es/grid-component/type.js +490 -1
  13. package/es/table-component/type.d.ts +10 -0
  14. package/es/{grid-component → table-virtuoso}/ColumnsGroup/ColumnsGroup.js +4 -3
  15. package/es/{grid-component → table-virtuoso}/InternalTable.d.ts +2 -3
  16. package/es/table-virtuoso/InternalTable.js +391 -0
  17. package/es/table-virtuoso/body/TableBodyCell.d.ts +14 -0
  18. package/es/table-virtuoso/body/TableBodyCell.js +457 -0
  19. package/es/table-virtuoso/body/TableBodyRow.d.ts +13 -0
  20. package/es/table-virtuoso/body/TableBodyRow.js +112 -0
  21. package/es/table-virtuoso/footer/TableFooterCell.d.ts +7 -0
  22. package/es/table-virtuoso/footer/TableFooterCell.js +54 -0
  23. package/es/table-virtuoso/header/TableHeadCell.d.ts +14 -0
  24. package/es/table-virtuoso/header/TableHeadCell.js +265 -0
  25. package/es/table-virtuoso/header/renderFilter.d.ts +20 -0
  26. package/es/table-virtuoso/header/renderFilter.js +289 -0
  27. package/es/table-virtuoso/hook/constant.d.ts +73 -0
  28. package/es/table-virtuoso/hook/constant.js +240 -0
  29. package/es/table-virtuoso/hook/convert.d.ts +1 -0
  30. package/es/table-virtuoso/hook/convert.js +28 -0
  31. package/es/table-virtuoso/hook/useColumns.d.ts +28 -0
  32. package/es/table-virtuoso/hook/useColumns.js +302 -0
  33. package/es/table-virtuoso/hook/useFilterOperator.d.ts +7 -0
  34. package/es/table-virtuoso/hook/useFilterOperator.js +33 -0
  35. package/es/table-virtuoso/hook/utils.d.ts +159 -0
  36. package/es/table-virtuoso/hook/utils.js +2263 -0
  37. package/es/table-virtuoso/index.d.ts +2 -0
  38. package/es/table-virtuoso/index.js +2 -0
  39. package/es/table-virtuoso/style.d.ts +22 -0
  40. package/es/table-virtuoso/style.js +12 -0
  41. package/es/table-virtuoso/style.scss +1441 -0
  42. package/es/table-virtuoso/table/Grid.d.ts +37 -0
  43. package/es/table-virtuoso/table/Grid.js +298 -0
  44. package/es/table-virtuoso/table/TableContainer.d.ts +49 -0
  45. package/es/table-virtuoso/table/TableContainer.js +292 -0
  46. package/es/table-virtuoso/table/TableWrapper.d.ts +22 -0
  47. package/es/table-virtuoso/table/TableWrapper.js +161 -0
  48. package/es/table-virtuoso/type.d.ts +0 -0
  49. package/es/table-virtuoso/type.js +785 -0
  50. package/es/table-virtuoso/useContext.d.ts +97 -0
  51. package/es/table-virtuoso/useContext.js +21 -0
  52. package/lib/grid-component/TempTable.d.ts +2 -2
  53. package/lib/grid-component/TempTable.js +5 -7
  54. package/lib/grid-component/hooks/useLazyKVMap.d.ts +1 -1
  55. package/lib/grid-component/hooks/useLazyKVMap.js +0 -3
  56. package/lib/grid-component/hooks/utils.d.ts +1 -8
  57. package/lib/grid-component/hooks/utils.js +179 -152
  58. package/lib/grid-component/index.d.ts +1 -1
  59. package/lib/grid-component/index.js +0 -3
  60. package/lib/grid-component/styles.scss +1394 -1394
  61. package/lib/grid-component/type.d.ts +0 -407
  62. package/lib/grid-component/type.js +490 -4
  63. package/lib/table-component/type.d.ts +10 -0
  64. package/lib/{grid-component → table-virtuoso}/ColumnsGroup/ColumnsGroup.js +4 -3
  65. package/lib/{grid-component → table-virtuoso}/InternalTable.d.ts +2 -3
  66. package/lib/table-virtuoso/InternalTable.js +400 -0
  67. package/lib/table-virtuoso/body/TableBodyCell.d.ts +14 -0
  68. package/lib/table-virtuoso/body/TableBodyCell.js +464 -0
  69. package/lib/table-virtuoso/body/TableBodyRow.d.ts +13 -0
  70. package/lib/table-virtuoso/body/TableBodyRow.js +119 -0
  71. package/lib/table-virtuoso/footer/TableFooterCell.d.ts +7 -0
  72. package/lib/table-virtuoso/footer/TableFooterCell.js +63 -0
  73. package/lib/table-virtuoso/header/TableHeadCell.d.ts +14 -0
  74. package/lib/table-virtuoso/header/TableHeadCell.js +274 -0
  75. package/lib/table-virtuoso/header/renderFilter.d.ts +20 -0
  76. package/lib/table-virtuoso/header/renderFilter.js +299 -0
  77. package/lib/table-virtuoso/hook/constant.d.ts +73 -0
  78. package/lib/table-virtuoso/hook/constant.js +247 -0
  79. package/lib/table-virtuoso/hook/convert.d.ts +1 -0
  80. package/lib/table-virtuoso/hook/convert.js +34 -0
  81. package/lib/table-virtuoso/hook/useColumns.d.ts +28 -0
  82. package/lib/table-virtuoso/hook/useColumns.js +315 -0
  83. package/lib/table-virtuoso/hook/useFilterOperator.d.ts +7 -0
  84. package/lib/table-virtuoso/hook/useFilterOperator.js +40 -0
  85. package/lib/table-virtuoso/hook/utils.d.ts +159 -0
  86. package/lib/table-virtuoso/hook/utils.js +2389 -0
  87. package/lib/table-virtuoso/index.d.ts +2 -0
  88. package/lib/table-virtuoso/index.js +9 -0
  89. package/lib/table-virtuoso/style.d.ts +22 -0
  90. package/lib/table-virtuoso/style.js +19 -0
  91. package/lib/table-virtuoso/style.scss +1441 -0
  92. package/lib/table-virtuoso/table/Grid.d.ts +37 -0
  93. package/lib/table-virtuoso/table/Grid.js +307 -0
  94. package/lib/table-virtuoso/table/TableContainer.d.ts +49 -0
  95. package/lib/table-virtuoso/table/TableContainer.js +300 -0
  96. package/lib/table-virtuoso/table/TableWrapper.d.ts +22 -0
  97. package/lib/table-virtuoso/table/TableWrapper.js +166 -0
  98. package/lib/table-virtuoso/type.d.ts +0 -0
  99. package/lib/table-virtuoso/type.js +786 -0
  100. package/lib/table-virtuoso/useContext.d.ts +97 -0
  101. package/lib/table-virtuoso/useContext.js +27 -0
  102. package/package.json +2 -1
  103. package/es/grid-component/AdvanceFilter.d.ts +0 -14
  104. package/es/grid-component/AdvanceFilter.js +0 -454
  105. package/es/grid-component/CheckboxFilter.d.ts +0 -20
  106. package/es/grid-component/CheckboxFilter.js +0 -244
  107. package/es/grid-component/CheckboxFilter2.d.ts +0 -20
  108. package/es/grid-component/CheckboxFilter2.js +0 -244
  109. package/es/grid-component/ColumnsChoose.d.ts +0 -10
  110. package/es/grid-component/ColumnsChoose.js +0 -230
  111. package/es/grid-component/Command.d.ts +0 -8
  112. package/es/grid-component/Command.js +0 -80
  113. package/es/grid-component/ContextMenu.d.ts +0 -20
  114. package/es/grid-component/ContextMenu.js +0 -130
  115. package/es/grid-component/ConvertColumnTable.d.ts +0 -7
  116. package/es/grid-component/ConvertColumnTable.js +0 -144
  117. package/es/grid-component/EditForm/EditForm.d.ts +0 -27
  118. package/es/grid-component/EditForm/EditForm.js +0 -394
  119. package/es/grid-component/EditForm/index.d.ts +0 -1
  120. package/es/grid-component/EditForm/index.js +0 -1
  121. package/es/grid-component/EditableCell.d.ts +0 -20
  122. package/es/grid-component/EditableCell.js +0 -1030
  123. package/es/grid-component/FilterSearch.d.ts +0 -12
  124. package/es/grid-component/FilterSearch.js +0 -33
  125. package/es/grid-component/GridStyle.d.ts +0 -8
  126. package/es/grid-component/GridStyle.js +0 -5
  127. package/es/grid-component/InternalTable.js +0 -1170
  128. package/es/grid-component/TableGrid.d.ts +0 -21
  129. package/es/grid-component/TableGrid.js +0 -493
  130. package/es/grid-component/async-select/index.d.ts +0 -11
  131. package/es/grid-component/async-select/index.js +0 -38
  132. package/es/grid-component/async-table-select/index.d.ts +0 -11
  133. package/es/grid-component/async-table-select/index.js +0 -40
  134. package/es/grid-component/checkbox-control/index.d.ts +0 -13
  135. package/es/grid-component/checkbox-control/index.js +0 -40
  136. package/es/grid-component/hooks/columns/index.d.ts +0 -10
  137. package/es/grid-component/hooks/columns/index.js +0 -503
  138. package/es/grid-component/hooks/content/ControlCheckbox.d.ts +0 -13
  139. package/es/grid-component/hooks/content/ControlCheckbox.js +0 -87
  140. package/es/grid-component/hooks/content/HeaderContent.d.ts +0 -14
  141. package/es/grid-component/hooks/content/HeaderContent.js +0 -44
  142. package/es/grid-component/hooks/content/TooltipContent.d.ts +0 -13
  143. package/es/grid-component/hooks/content/TooltipContent.js +0 -74
  144. package/es/grid-component/hooks/useColumns.d.ts +0 -19
  145. package/es/grid-component/hooks/useColumns.js +0 -317
  146. package/es/grid-component/number/index.d.ts +0 -10
  147. package/es/grid-component/number/index.js +0 -39
  148. package/es/grid-component/number-range/index.d.ts +0 -11
  149. package/es/grid-component/number-range/index.js +0 -63
  150. package/es/grid-component/table/Grid.d.ts +0 -23
  151. package/es/grid-component/table/Grid.js +0 -49
  152. package/es/grid-component/table/GridEdit.d.ts +0 -23
  153. package/es/grid-component/table/GridEdit.js +0 -2726
  154. package/es/grid-component/table/Group.d.ts +0 -21
  155. package/es/grid-component/table/Group.js +0 -195
  156. package/es/grid-component/table/InfiniteTable.d.ts +0 -23
  157. package/es/grid-component/table/InfiniteTable.js +0 -101
  158. package/es/grid-component/useContext.d.ts +0 -34
  159. package/es/grid-component/useContext.js +0 -8
  160. package/lib/grid-component/AdvanceFilter.d.ts +0 -14
  161. package/lib/grid-component/AdvanceFilter.js +0 -463
  162. package/lib/grid-component/CheckboxFilter.d.ts +0 -20
  163. package/lib/grid-component/CheckboxFilter.js +0 -253
  164. package/lib/grid-component/CheckboxFilter2.d.ts +0 -20
  165. package/lib/grid-component/CheckboxFilter2.js +0 -253
  166. package/lib/grid-component/ColumnsChoose.d.ts +0 -10
  167. package/lib/grid-component/ColumnsChoose.js +0 -240
  168. package/lib/grid-component/Command.d.ts +0 -8
  169. package/lib/grid-component/Command.js +0 -88
  170. package/lib/grid-component/ContextMenu.d.ts +0 -20
  171. package/lib/grid-component/ContextMenu.js +0 -140
  172. package/lib/grid-component/ConvertColumnTable.d.ts +0 -7
  173. package/lib/grid-component/ConvertColumnTable.js +0 -153
  174. package/lib/grid-component/EditForm/EditForm.d.ts +0 -27
  175. package/lib/grid-component/EditForm/EditForm.js +0 -404
  176. package/lib/grid-component/EditForm/index.d.ts +0 -1
  177. package/lib/grid-component/EditForm/index.js +0 -16
  178. package/lib/grid-component/EditableCell.d.ts +0 -20
  179. package/lib/grid-component/EditableCell.js +0 -1032
  180. package/lib/grid-component/FilterSearch.d.ts +0 -12
  181. package/lib/grid-component/FilterSearch.js +0 -42
  182. package/lib/grid-component/GridStyle.d.ts +0 -8
  183. package/lib/grid-component/GridStyle.js +0 -12
  184. package/lib/grid-component/InternalTable.js +0 -1178
  185. package/lib/grid-component/TableGrid.d.ts +0 -21
  186. package/lib/grid-component/TableGrid.js +0 -493
  187. package/lib/grid-component/async-select/index.d.ts +0 -11
  188. package/lib/grid-component/async-select/index.js +0 -47
  189. package/lib/grid-component/async-table-select/index.d.ts +0 -11
  190. package/lib/grid-component/async-table-select/index.js +0 -49
  191. package/lib/grid-component/checkbox-control/index.d.ts +0 -13
  192. package/lib/grid-component/checkbox-control/index.js +0 -48
  193. package/lib/grid-component/hooks/columns/index.d.ts +0 -10
  194. package/lib/grid-component/hooks/columns/index.js +0 -518
  195. package/lib/grid-component/hooks/content/ControlCheckbox.d.ts +0 -13
  196. package/lib/grid-component/hooks/content/ControlCheckbox.js +0 -95
  197. package/lib/grid-component/hooks/content/HeaderContent.d.ts +0 -14
  198. package/lib/grid-component/hooks/content/HeaderContent.js +0 -53
  199. package/lib/grid-component/hooks/content/TooltipContent.d.ts +0 -13
  200. package/lib/grid-component/hooks/content/TooltipContent.js +0 -81
  201. package/lib/grid-component/hooks/useColumns.d.ts +0 -19
  202. package/lib/grid-component/hooks/useColumns.js +0 -328
  203. package/lib/grid-component/number/index.d.ts +0 -10
  204. package/lib/grid-component/number/index.js +0 -47
  205. package/lib/grid-component/number-range/index.d.ts +0 -11
  206. package/lib/grid-component/number-range/index.js +0 -71
  207. package/lib/grid-component/table/Grid.d.ts +0 -23
  208. package/lib/grid-component/table/Grid.js +0 -58
  209. package/lib/grid-component/table/GridEdit.d.ts +0 -23
  210. package/lib/grid-component/table/GridEdit.js +0 -2723
  211. package/lib/grid-component/table/Group.d.ts +0 -21
  212. package/lib/grid-component/table/Group.js +0 -204
  213. package/lib/grid-component/table/InfiniteTable.d.ts +0 -23
  214. package/lib/grid-component/table/InfiniteTable.js +0 -109
  215. package/lib/grid-component/useContext.d.ts +0 -34
  216. package/lib/grid-component/useContext.js +0 -13
  217. /package/es/{grid-component → table-virtuoso}/ColumnsGroup/ColumnsGroup.d.ts +0 -0
  218. /package/es/{grid-component → table-virtuoso}/ColumnsGroup/index.d.ts +0 -0
  219. /package/es/{grid-component → table-virtuoso}/ColumnsGroup/index.js +0 -0
  220. /package/lib/{grid-component → table-virtuoso}/ColumnsGroup/ColumnsGroup.d.ts +0 -0
  221. /package/lib/{grid-component → table-virtuoso}/ColumnsGroup/index.d.ts +0 -0
  222. /package/lib/{grid-component → table-virtuoso}/ColumnsGroup/index.js +0 -0
@@ -0,0 +1,2389 @@
1
+ "use strict";
2
+
3
+ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
4
+ Object.defineProperty(exports, "__esModule", {
5
+ value: true
6
+ });
7
+ exports.addRowIdArray = void 0;
8
+ exports.addRowsDown = addRowsDown;
9
+ exports.addRowsDownWithCtrl = addRowsDownWithCtrl;
10
+ exports.addRowsUp = addRowsUp;
11
+ exports.addRowsUpWithCtrl = addRowsUpWithCtrl;
12
+ exports.appendIfNotExists = void 0;
13
+ exports.areStringArraysEqual = areStringArraysEqual;
14
+ exports.arraysEqualIgnoreOrderFast = arraysEqualIgnoreOrderFast;
15
+ exports.checkThousandSeparator = exports.checkFieldKey = exports.checkDecimalSeparator = void 0;
16
+ exports.compareDate = compareDate;
17
+ exports.compareDates = compareDates;
18
+ exports.convertArrayWithIndent = void 0;
19
+ exports.convertColumnsToTreeData = convertColumnsToTreeData;
20
+ exports.convertFlatColumn1 = exports.convertFilters = exports.convertDayjsToDate = exports.convertDateToDayjs = void 0;
21
+ exports.convertFormat = convertFormat;
22
+ exports.convertToObjTrue = exports.convertToObj = exports.convertLabelToTitle = void 0;
23
+ exports.countUnselectedChildren = countUnselectedChildren;
24
+ exports.detectSeparators = exports.customWeekStartEndFormat = void 0;
25
+ exports.excludeItems = excludeItems;
26
+ exports.extendsObject = void 0;
27
+ exports.filterByIds = filterByIds;
28
+ exports.filterDataByColumns = filterDataByColumns;
29
+ exports.findAllChildrenKeys2 = findAllChildrenKeys2;
30
+ exports.findFirst = findFirst;
31
+ exports.genPresets = exports.flattenData = exports.flattenArray = exports.flatColumns2 = exports.findItemByKey = void 0;
32
+ exports.getAllChildren = getAllChildren;
33
+ exports.getAllVisibleKeys1 = exports.getAllVisibleKeys = exports.getAllRowKey = void 0;
34
+ exports.getCellsByPosition = getCellsByPosition;
35
+ exports.getColIdsBetween = getColIdsBetween;
36
+ exports.getFormat = exports.getFixedFields = exports.getEditType = exports.getDiffent2Array = exports.getDefaultValue = exports.getDefaultOperator = exports.getDatepickerFormat = exports.getDateRangeFormat = exports.getCommonPinningStyles2 = exports.getCommonPinningStyles = exports.getCommonPinningHeaderStyles = void 0;
37
+ exports.getHiddenParentKeys = getHiddenParentKeys;
38
+ exports.getHiddenParentKeys1 = getHiddenParentKeys1;
39
+ exports.getInvisibleColumns = getInvisibleColumns;
40
+ exports.getNewItemsOnly = exports.getLastSelectCell = void 0;
41
+ exports.getRowIdsBetween = getRowIdsBetween;
42
+ exports.getVisibleColumnKeys1 = exports.getVisibleColumnKeys = exports.getTypeFilter = exports.getTableHeight = exports.getSelectedCellMatrix = void 0;
43
+ exports.groupArrayByColumns = groupArrayByColumns;
44
+ exports.isColor = void 0;
45
+ exports.isDateString = isDateString;
46
+ exports.isEmpty = exports.isEditable = exports.isDisable = void 0;
47
+ exports.isEqualSet = isEqualSet;
48
+ exports.isObjEmpty = exports.isNullOrUndefined = exports.isNameColor = exports.isFormattedNumber = void 0;
49
+ exports.isObjEqual = isObjEqual;
50
+ exports.isTreeArray = isTreeArray;
51
+ exports.parseBooleanToValue = exports.onRemoveBgSelectedCell = exports.onAddBgSelectedCell = exports.newGuid = void 0;
52
+ exports.parseClipboardEvent = parseClipboardEvent;
53
+ exports.parseExcelClipboard = parseExcelClipboard;
54
+ exports.parseExcelClipboardText = parseExcelClipboardText;
55
+ exports.parseExcelText = parseExcelText;
56
+ exports.removeDuplicatesByKey = removeDuplicatesByKey;
57
+ exports.removeKeys = removeKeys;
58
+ exports.sortByType = exports.shouldInclude = exports.removeVietnameseTones = void 0;
59
+ exports.sortData = sortData;
60
+ exports.sumSize = void 0;
61
+ exports.toggleRowAndChildren = toggleRowAndChildren;
62
+ exports.updateArrayByKey = exports.unFlattenData = void 0;
63
+ exports.updateColumnWidthsRecursive = updateColumnWidthsRecursive;
64
+ exports.updateColumnsByGroup = exports.updateColumns1 = void 0;
65
+ exports.updateOrInsert = updateOrInsert;
66
+ exports.updateWidthsByOther = updateWidthsByOther;
67
+ var _useSelection = require("rc-master-ui/es/table/hooks/useSelection");
68
+ var _uuid = require("uuid");
69
+ var _colors = require("@ant-design/colors");
70
+ var _dayjs = _interopRequireDefault(require("dayjs"));
71
+ var _moment = _interopRequireDefault(require("moment"));
72
+ const newGuid = () => {
73
+ for (let i = 0; i < 20; i++) {
74
+ return (0, _uuid.v4)();
75
+ }
76
+ };
77
+ exports.newGuid = newGuid;
78
+ const convertDayjsToDate = (dateString, format) => {
79
+ const dayjsDate = (0, _dayjs.default)(dateString, format); // Parse using the provided format
80
+ if (!dayjsDate.isValid()) {
81
+ throw new Error('Invalid date or format');
82
+ }
83
+ // return moment(dayjsDate.toDate()).format() // Convert to JavaScript Date
84
+ return dayjsDate.toDate(); // Convert to JavaScript Date
85
+ };
86
+ exports.convertDayjsToDate = convertDayjsToDate;
87
+ const convertDateToDayjs = (date, format) => {
88
+ const dateValue = date ? (0, _dayjs.default)(date).format(format) : null;
89
+ return dateValue ? (0, _dayjs.default)(dateValue, format) : null;
90
+ };
91
+ exports.convertDateToDayjs = convertDateToDayjs;
92
+ const getCommonPinningHeaderStyles = column => {
93
+ const isPinned = column.getIsPinned();
94
+ return {
95
+ left: isPinned === "left" ? `${column.getStart("left")}px` : undefined,
96
+ right: isPinned === "right" ? `${column.getAfter("right")}px` : undefined,
97
+ opacity: 1,
98
+ position: isPinned ? "sticky" : "relative",
99
+ // width: 'auto',
100
+ zIndex: isPinned ? 4 : 3
101
+ };
102
+ };
103
+ exports.getCommonPinningHeaderStyles = getCommonPinningHeaderStyles;
104
+ const getCommonPinningStyles = column => {
105
+ const isPinned = column.getIsPinned();
106
+ return {
107
+ left: isPinned === "left" ? `${column.getStart("left")}px` : undefined,
108
+ right: isPinned === "right" ? `${column.getAfter("right")}px` : undefined,
109
+ opacity: 1,
110
+ position: isPinned ? "sticky" : "relative",
111
+ // width: 'auto',
112
+ zIndex: isPinned ? 2 : 0
113
+ };
114
+ };
115
+ exports.getCommonPinningStyles = getCommonPinningStyles;
116
+ const getCommonPinningStyles2 = header => {
117
+ const isPinned = header.column.getIsPinned();
118
+ // const isLastLeftPinnedColumn = isPinned === "left" && column.getIsLastColumn("left");
119
+ // const isFirstRightPinnedColumn =isPinned === "right" && column.getIsFirstColumn("right");
120
+
121
+ return {
122
+ // boxShadow: isFirstRightPinnedColumn
123
+ // ? "#e0e0e0 2px 0px 1px -1px inset"
124
+ // : undefined,
125
+
126
+ left: isPinned === "left" ? `${header.getStart("left")}px` : undefined,
127
+ right: isPinned === "right" ? `${header.getAfter("right")}px` : undefined,
128
+ opacity: 1,
129
+ position: isPinned ? "sticky" : "relative",
130
+ width: 'auto',
131
+ zIndex: isPinned ? 2 : 0
132
+ };
133
+ };
134
+ exports.getCommonPinningStyles2 = getCommonPinningStyles2;
135
+ const sumSize = items => {
136
+ return items.reduce((total, item) => total + item.size, 0);
137
+ };
138
+ exports.sumSize = sumSize;
139
+ const appendIfNotExists = (a, b) => {
140
+ const existingKeys = new Set(a.map(item => item.index));
141
+ b.forEach(item => {
142
+ if (!existingKeys.has(item.index)) {
143
+ a.push(item);
144
+ }
145
+ });
146
+ return a;
147
+ };
148
+ exports.appendIfNotExists = appendIfNotExists;
149
+ const getNewItemsOnly = (a, b) => {
150
+ const existingKeys = new Set(a.map(item => item.key));
151
+ return b.filter(item => !existingKeys.has(item.key));
152
+ };
153
+ exports.getNewItemsOnly = getNewItemsOnly;
154
+ const extendsObject = (...list) => {
155
+ const result = {
156
+ ...list[0]
157
+ };
158
+ for (let i = 1; i < list.length; i++) {
159
+ const obj = list[i];
160
+ if (obj) {
161
+ Object.keys(obj).forEach(key => {
162
+ const val = obj[key];
163
+ if (val !== undefined) {
164
+ result[key] = val;
165
+ }
166
+ });
167
+ }
168
+ }
169
+ return result;
170
+ };
171
+ exports.extendsObject = extendsObject;
172
+ const isEmpty = d => {
173
+ return d === null || d === undefined || d === '';
174
+ };
175
+ exports.isEmpty = isEmpty;
176
+ const getFormat = (colFormat, format) => {
177
+ return {
178
+ thousandSeparator: colFormat?.thousandSeparator ?? format?.thousandSeparator,
179
+ decimalSeparator: colFormat?.decimalSeparator ?? format?.decimalSeparator,
180
+ decimalScale: colFormat?.decimalScale ?? format?.decimalScale ? Number(colFormat?.decimalScale ?? format?.decimalScale) : colFormat?.decimalScale ?? format?.decimalScale,
181
+ allowNegative: colFormat?.allowNegative ?? format?.allowNegative,
182
+ // check nhập số âm
183
+ prefix: colFormat?.prefix ?? format?.prefix,
184
+ suffix: colFormat?.suffix ?? format?.suffix,
185
+ fixedDecimalScale: colFormat?.fixedDecimalScale ?? format?.fixedDecimalScale,
186
+ // mặc định thêm số 0 sau số thập phân
187
+ dateFormat: colFormat?.dateFormat ?? format?.dateFormat,
188
+ datetimeFormat: colFormat?.datetimeFormat ?? format?.datetimeFormat,
189
+ timeFormat: colFormat?.timeFormat ?? format?.timeFormat,
190
+ weekFormat: colFormat?.weekFormat ?? format?.weekFormat,
191
+ monthFormat: colFormat?.monthFormat ?? format?.monthFormat,
192
+ yearFormat: colFormat?.yearFormat ?? format?.yearFormat
193
+ };
194
+ };
195
+ exports.getFormat = getFormat;
196
+ function convertFormat(formatStr) {
197
+ // return formatStr.split('').map((char, i) => {
198
+ // if (char === 'D' || char === 'd') {
199
+ // return 'd'; // ngày: lowercase
200
+ // }
201
+ // if (char === 'Y' || char === 'y') {
202
+ // return 'y'; // năm: lowercase
203
+ // }
204
+ // if (char === 'M' || char === 'm') {
205
+ // return char; // tháng: giữ nguyên
206
+ // }
207
+ // return char; // separator
208
+ // }).join('');
209
+
210
+ return formatStr.split('').map(char => {
211
+ if (char === 'D' || char === 'd') return 'd';
212
+ if (char === 'Y' || char === 'y') return 'y';
213
+ if ('Hhmsa'.includes(char)) return char; // giờ, phút, giây, am/pm
214
+ if (char === 'M' || char === 'm') return char; // tháng: giữ nguyên
215
+ return char; // dấu phân cách
216
+ }).join('');
217
+ }
218
+ const getDatepickerFormat = (type, format) => {
219
+ const typeFormat = type ? type.toLowerCase() : '';
220
+ switch (typeFormat) {
221
+ case "date":
222
+ case "daterange":
223
+ return format?.dateFormat ?? 'DD/MM/YYYY';
224
+ case "datetime":
225
+ return format?.datetimeFormat ?? 'DD/MM/YYYY HH:mm';
226
+ case "week":
227
+ return format?.weekFormat ?? 'DD/MM';
228
+ case "month":
229
+ return format?.monthFormat ?? 'MM/YYYY';
230
+ case "quarter":
231
+ return format?.dateFormat ?? 'DD/MM/YYYY';
232
+ case "year":
233
+ return format?.yearFormat ?? 'YYYY';
234
+ case "time":
235
+ return format?.timeFormat ?? 'HH:mm';
236
+ default:
237
+ return 'DD/MM/YYYY';
238
+ }
239
+ };
240
+ exports.getDatepickerFormat = getDatepickerFormat;
241
+ const getDateRangeFormat = (type, format) => {
242
+ const typeFormat = type ? type.toLowerCase() : '';
243
+ switch (typeFormat) {
244
+ case "date":
245
+ case "daterange":
246
+ return convertFormat(format?.dateFormat ?? 'dd/MM/yyyy');
247
+ case "datetime":
248
+ return format?.datetimeFormat ?? 'dd/MM/yyyy HH:mm';
249
+ case "week":
250
+ return format?.weekFormat ?? 'dd/MM';
251
+ case "month":
252
+ return format?.monthFormat ?? 'MM/yyyy';
253
+ case "quarter":
254
+ return format?.dateFormat ?? 'dd/MM/yyyy';
255
+ case "year":
256
+ return format?.yearFormat ?? 'yyyy';
257
+ case "time":
258
+ return format?.timeFormat ?? 'HH:mm';
259
+ default:
260
+ return 'dd/MM/yyyy';
261
+ }
262
+ };
263
+ exports.getDateRangeFormat = getDateRangeFormat;
264
+ const getTypeFilter = col => {
265
+ if (col?.typeFilter) {
266
+ return col.typeFilter;
267
+ }
268
+ const type = col?.type ?? 'Text';
269
+ switch (type) {
270
+ case "number":
271
+ return 'Number';
272
+ case "date":
273
+ return 'Date';
274
+ case "datetime":
275
+ return 'Datetime';
276
+ case "boolean":
277
+ return 'Checkbox';
278
+ case "checkbox":
279
+ return 'Checkbox';
280
+
281
+ // case "week": return ''
282
+ // case "month": return 'Month'
283
+ // case "quarter": return col.format?.dateFormat ? col.format?.dateFormat : 'DD/MM/YYYY'
284
+ // case "year": return col.format?.yearFormat ? col.format?.yearFormat : 'YYYY'
285
+ // case "time": return col.format?.timeFormat ? col.format?.timeFormat : 'HH:mm'
286
+ case "string":
287
+ default:
288
+ return 'Text';
289
+ }
290
+ };
291
+ exports.getTypeFilter = getTypeFilter;
292
+ const addRowIdArray = inputArray => {
293
+ if (inputArray) {
294
+ return inputArray.map(item => {
295
+ if (typeof item.children !== "string" && item.children && item.children.length > 0) {
296
+ item.children = addRowIdArray(item.children);
297
+ }
298
+
299
+ // return { ...item, rowId: item.rowId ?? item.id ?? newGuid() }
300
+ return {
301
+ ...item,
302
+ rowId: item.id ?? item.rowId ?? newGuid()
303
+ };
304
+ });
305
+ } else {
306
+ return [];
307
+ }
308
+ };
309
+ exports.addRowIdArray = addRowIdArray;
310
+ function groupArrayByColumns(arr, columns) {
311
+ const result = [];
312
+ if (columns && columns.length > 0) {
313
+ arr.forEach(item => {
314
+ let currentLevel = result;
315
+ const parentChain = []; // Lưu rowId của mỗi level để biết parent
316
+
317
+ columns.forEach((column, index) => {
318
+ const value = item[column];
319
+
320
+ // Tạo key unique cho group dựa trên value của cột
321
+ // Tìm existing item ở level hiện tại
322
+ const existingItem = currentLevel.find(i => i[column] === value);
323
+ if (existingItem) {
324
+ // Item đã tồn tại, chỉ update parentChain
325
+ parentChain[index] = existingItem.rowId;
326
+ currentLevel = existingItem.children;
327
+ } else {
328
+ // Tạo item mới
329
+ const groupRowId = String(value);
330
+ const newItem = {
331
+ [column]: value,
332
+ field: column,
333
+ rowId: groupRowId,
334
+ id: groupRowId,
335
+ parentId: parentChain[index - 1] ?? null,
336
+ // Parent là rowId của level trước
337
+ children: []
338
+ };
339
+ currentLevel.push(newItem);
340
+ parentChain[index] = groupRowId;
341
+ currentLevel = newItem.children;
342
+ }
343
+ });
344
+
345
+ // Data item cuối cùng: parentId là rowId của group parent gần nhất (level cuối cùng)
346
+ currentLevel.push({
347
+ ...item,
348
+ rowId: item.id ?? item.rowId,
349
+ parentId: parentChain[columns.length - 1] ?? null
350
+ });
351
+ });
352
+ return result;
353
+ } else {
354
+ return arr;
355
+ }
356
+ }
357
+ const flatColumns2 = columns => {
358
+ return columns.reduce((list, column) => {
359
+ const subColumns = column.children;
360
+ if (column === _useSelection.SELECTION_COLUMN) {
361
+ return [...list, {
362
+ ...column
363
+ }];
364
+ }
365
+ if (subColumns && subColumns.length > 0) {
366
+ return [...list, ...flatColumns2(subColumns).map(subColum => ({
367
+ ...subColum
368
+ }))];
369
+ }
370
+ return [...list, {
371
+ ...column
372
+ }];
373
+ }, []);
374
+ };
375
+ exports.flatColumns2 = flatColumns2;
376
+ const checkThousandSeparator = (thousandSeparator, decimalSeparator) => {
377
+ if (thousandSeparator) {
378
+ if (decimalSeparator) {
379
+ if (thousandSeparator === decimalSeparator) {
380
+ return ',';
381
+ } else {
382
+ return thousandSeparator;
383
+ }
384
+ } else {
385
+ return thousandSeparator;
386
+ }
387
+ } else {
388
+ return undefined;
389
+ }
390
+ };
391
+ exports.checkThousandSeparator = checkThousandSeparator;
392
+ const checkDecimalSeparator = (thousandSeparator, decimalSeparator) => {
393
+ if (decimalSeparator) {
394
+ if (thousandSeparator) {
395
+ if (thousandSeparator === decimalSeparator) {
396
+ return '.';
397
+ } else {
398
+ return decimalSeparator;
399
+ }
400
+ } else {
401
+ return decimalSeparator;
402
+ }
403
+ } else {
404
+ if (thousandSeparator && thousandSeparator === '.') {
405
+ return ',';
406
+ }
407
+ return '.';
408
+ }
409
+ };
410
+ exports.checkDecimalSeparator = checkDecimalSeparator;
411
+ const getFixedFields = (columns, type) => {
412
+ const result = [];
413
+ function traverse(cols) {
414
+ for (const col of cols) {
415
+ if ((col.fixed ?? col.fixedType) === type && col.field && (col.visible !== false || col.hidden)) {
416
+ result.push(col.field);
417
+ }
418
+ if (col.children && col.children.length > 0) {
419
+ traverse(col.children);
420
+ }
421
+ }
422
+ }
423
+ traverse(columns);
424
+ return result;
425
+ };
426
+ exports.getFixedFields = getFixedFields;
427
+ function areStringArraysEqual(a, b) {
428
+ if (a.length !== b.length) return false;
429
+ const sortedA = [...a].sort();
430
+ const sortedB = [...b].sort();
431
+ return sortedA.every((val, index) => val === sortedB[index]);
432
+ }
433
+ const getDefaultOperator = col => {
434
+ if (col.operator) {
435
+ return col.operator;
436
+ }
437
+ if (col.typeFilter) {
438
+ switch (col.typeFilter) {
439
+ case 'Number':
440
+ case 'Date':
441
+ case 'Datetime':
442
+ case 'Time':
443
+ case 'Month':
444
+ case 'Quarter':
445
+ case 'Year':
446
+ case 'Week':
447
+ case 'Dropdown':
448
+ case 'Checkbox':
449
+ case 'CheckboxDropdown':
450
+ case 'CheckboxTree':
451
+ case 'DropTree':
452
+ return 'equal';
453
+ case 'Text':
454
+ default:
455
+ return 'contains';
456
+ }
457
+ }
458
+ switch (col.type) {
459
+ case 'number':
460
+ case 'date':
461
+ case 'datetime':
462
+ case 'week':
463
+ case 'year':
464
+ case 'quarter':
465
+ return 'equal';
466
+ case 'string':
467
+ default:
468
+ return 'contains';
469
+ }
470
+ };
471
+ exports.getDefaultOperator = getDefaultOperator;
472
+ function isEqualSet(setA, setB) {
473
+ if (setA.size !== setB.size) {
474
+ return false;
475
+ }
476
+ for (const item of setA) {
477
+ if (!setB.has(item)) {
478
+ return false;
479
+ }
480
+ }
481
+ return true;
482
+ }
483
+ const getLastSelectCell = selectCells => {
484
+ if (selectCells.size === 0) {
485
+ return {
486
+ row: 0,
487
+ col: 0
488
+ };
489
+ }
490
+ const lastValue = [...selectCells].at(-1);
491
+ const [row, col] = lastValue.split("-").map(Number);
492
+ return {
493
+ row,
494
+ col
495
+ };
496
+ };
497
+ exports.getLastSelectCell = getLastSelectCell;
498
+ function getCellsByPosition(cellSet, position = "bottom") {
499
+ const cells = Array.from(cellSet).map(key => {
500
+ const [row, col] = key.split("-").map(Number);
501
+ return {
502
+ row,
503
+ col,
504
+ key
505
+ };
506
+ });
507
+ switch (position) {
508
+ case "top":
509
+ {
510
+ // const minRow = Math.min(...cells.map(c => c.row));
511
+ // return cells.filter(c => c.row === minRow).map(c => c.key);
512
+
513
+ // const rows = cells.map(c => c.row).filter(r => r > 0);
514
+ // if (rows.length === 0) return [];
515
+ // const minRow = Math.min(...rows);
516
+ // return cells.filter(c => c.row === minRow).map(c => c.key);
517
+
518
+ const minRow = Math.min(...cells.map(c => c.row));
519
+ if (minRow === 0) {
520
+ return [];
521
+ } // Bỏ qua nếu rowIndex = 0
522
+
523
+ return cells.filter(c => c.row === minRow).map(c => `${c.row}-${c.col}`);
524
+ }
525
+ case "bottom":
526
+ {
527
+ const maxRow = Math.max(...cells.map(c => c.row));
528
+ return cells.filter(c => c.row === maxRow).map(c => c.key);
529
+ }
530
+ case "left":
531
+ {
532
+ // const minCol = Math.min(...cells.map(c => c.col));
533
+ // return cells.filter(c => c.col === minCol).map(c => c.key);
534
+
535
+ // const cols = cells.map(c => c.col).filter(c => c > 0);
536
+ // if (cols.length === 0) return [];
537
+ // const minCol = Math.min(...cols);
538
+ // return cells.filter(c => c.col === minCol).map(c => c.key);
539
+
540
+ const minCol = Math.min(...cells.map(c => c.col));
541
+ if (minCol === 0) {
542
+ return [];
543
+ } // Bỏ qua nếu colIndex = 0
544
+
545
+ // Trả về các ô cùng row, nhưng ở cột bên trái
546
+ return cells.filter(c => c.col === minCol).map(c => `${c.row}-${c.col}`);
547
+ }
548
+ case "right":
549
+ {
550
+ const maxCol = Math.max(...cells.map(c => c.col));
551
+ return cells.filter(c => c.col === maxCol).map(c => c.key);
552
+ }
553
+ default:
554
+ return [];
555
+ }
556
+ }
557
+ const onAddBgSelectedCell = (selectedCells, id, isFocusCellIndex) => {
558
+ const selectors = Array.from(selectedCells).map(pos => {
559
+ const [row1, col1] = pos.split('-');
560
+ return `[data-row-index="${row1}"][data-col-index="${col1}"]`;
561
+ });
562
+ const table = document.querySelector(`#${id}`);
563
+
564
+ //// xóa class các ô đã chọn trước đó
565
+ const cellsSelected = table ? table?.querySelectorAll('.ui-rc-table-cell.selected-bg') : null;
566
+ if (cellsSelected) {
567
+ cellsSelected.forEach(cell => {
568
+ cell.classList.remove('selected-bg');
569
+ });
570
+ }
571
+
572
+ /// thêm class
573
+ const cells = table && selectors.length > 0 ? table?.querySelectorAll(selectors.join(',')) : null;
574
+ if (cells) {
575
+ cells.forEach(cell => {
576
+ cell.classList.add('selected-bg');
577
+ });
578
+ }
579
+ const rowsArray = [...new Set([...selectedCells].map(item => item.split("-")[0]))];
580
+ const rowsSelectors = rowsArray.map(r => `.rc-ui-cell-index[data-row-index="${r}"]`).join(", ");
581
+ const cellsIndex = table && rowsSelectors.length > 0 ? table?.querySelectorAll(rowsSelectors) : null;
582
+ if (cellsIndex && isFocusCellIndex !== false) {
583
+ cellsIndex.forEach(cell => {
584
+ cell.classList.add('focus');
585
+ });
586
+ }
587
+
588
+ // // tăng z-index để hiển thị round point paste
589
+ // const row = getLastSelectCell(selectedCells).row
590
+ // const col = getLastSelectCell(selectedCells).col
591
+ // const cell: any = table?.querySelector(`.ui-rc-table-cell[data-row-index="${row}"][data-col-index="${col}"]`)
592
+ //
593
+ // if (cell) {
594
+ // cell.style.zIndex = 1
595
+ // }
596
+ //
597
+ // if (cell && cell.classList.contains('ui-rc-table-cell-fix-left')) {
598
+ // cell.style.zIndex = 3;
599
+ // }
600
+
601
+ // thêm class border selected
602
+
603
+ // addBorderClass(selectedCells, 'bottom', 'cell-border-bottom', id)
604
+ // addBorderClass(selectedCells, 'right', 'cell-border-right', id)
605
+ // addBorderClass(selectedCells, 'top', 'cell-border-top', id)
606
+ // addBorderClass(selectedCells, 'left', 'cell-border-left', id)
607
+ };
608
+ exports.onAddBgSelectedCell = onAddBgSelectedCell;
609
+ const onRemoveBgSelectedCell = (selectedCells, id, rowsSelected) => {
610
+ const table = document.querySelector(`#${id}`);
611
+ const cells = table ? table?.querySelectorAll('.ui-rc-table-cell.selected-bg') : null;
612
+ if (cells) {
613
+ cells.forEach(cell => {
614
+ cell.classList.remove('selected-bg');
615
+ });
616
+ }
617
+ const cellsIndex = table ? table?.querySelectorAll('.ui-rc-table-cell.focus') : null;
618
+ if (cellsIndex) {
619
+ cellsIndex.forEach(cell => {
620
+ cell.classList.remove('focus');
621
+ });
622
+ }
623
+
624
+ // xóa class selected ô STT
625
+
626
+ if (rowsSelected && rowsSelected.size > 0) {
627
+ const rowsSelectedArray = [...new Set([...rowsSelected].map(item => item.split("-")[0]))];
628
+ const rowsSelectedSelectors = rowsSelectedArray.map(r => `.rc-ui-cell-index[data-row-index="${r}"]`).join(", ");
629
+ const cellsSelectedIndex = table && rowsSelectedSelectors.length > 0 ? table?.querySelectorAll(rowsSelectedSelectors) : null;
630
+ if (cellsSelectedIndex) {
631
+ cellsSelectedIndex.forEach(cell => {
632
+ cell.classList.remove('selected');
633
+ });
634
+ }
635
+ }
636
+ };
637
+ exports.onRemoveBgSelectedCell = onRemoveBgSelectedCell;
638
+ function getColIdsBetween(table, a, b) {
639
+ const ids = table.getVisibleLeafColumns().map(c => c.id);
640
+ const [start, end] = [ids.indexOf(a), ids.indexOf(b)].sort((x, y) => x - y);
641
+ return ids.slice(start, end + 1);
642
+ }
643
+ function getRowIdsBetween(table, a, b) {
644
+ // const ids = table.getRowModel().rows.map(r => r.id);
645
+ const ids = table.getRowModel().flatRows.map(r => r.id);
646
+ const [start, end] = [ids.indexOf(a), ids.indexOf(b)].sort((x, y) => x - y);
647
+ return ids.slice(start, end + 1);
648
+ }
649
+ const updateArrayByKey = (arr, element, key) => {
650
+ if (arr) {
651
+ return arr.map(it => {
652
+ const item = {
653
+ ...it
654
+ };
655
+ if (item[key] === element[key]) {
656
+ return {
657
+ ...item,
658
+ ...element
659
+ };
660
+ } else if (item.children && item.children.length > 0) {
661
+ item.children = updateArrayByKey(item.children, element, key);
662
+ }
663
+ return item;
664
+ });
665
+ } else {
666
+ return [];
667
+ }
668
+ };
669
+ exports.updateArrayByKey = updateArrayByKey;
670
+ const unFlattenData = data => {
671
+ const idToNodeMap = {};
672
+ const tree = [];
673
+
674
+ // Bước 1: Tạo map id -> node
675
+ data.forEach(item => {
676
+ // idToNodeMap[item.rowId] = { ...item, children: [] }
677
+ idToNodeMap[item.rowId] = {
678
+ ...item
679
+ };
680
+ });
681
+
682
+ // Bước 2: Gắn vào parent hoặc đẩy lên root nếu không có parent
683
+ data.forEach(item => {
684
+ const currentNode = idToNodeMap[item.rowId];
685
+ if (!item.parentId) {
686
+ tree.push(currentNode);
687
+ } else {
688
+ const parentNode = idToNodeMap[item.parentId];
689
+ if (parentNode) {
690
+ parentNode.children = parentNode.children ?? [];
691
+ parentNode.children.push(currentNode);
692
+ } else {
693
+ // Nếu parentId không tồn tại thì xem như root
694
+ tree.push(currentNode);
695
+ }
696
+ }
697
+ });
698
+ return tree;
699
+ };
700
+ exports.unFlattenData = unFlattenData;
701
+ const flattenArray = arr => {
702
+ if (!arr) {
703
+ return [];
704
+ }
705
+ return arr.reduce((r, {
706
+ children,
707
+ ...rest
708
+ }) => {
709
+ r.push(rest);
710
+ if (children) {
711
+ r.push(...flattenArray(children));
712
+ }
713
+ return r;
714
+ }, []);
715
+ };
716
+ exports.flattenArray = flattenArray;
717
+ function updateOrInsert(dataArray, dataFilter) {
718
+ const updatedArray = [...dataArray];
719
+ dataFilter.forEach(filterItem => {
720
+ const existingIndex = updatedArray.findIndex(item => item.rowId === filterItem.rowId);
721
+ if (existingIndex !== -1) {
722
+ // Cập nhật item đã tồn tại
723
+ updatedArray[existingIndex] = {
724
+ ...updatedArray[existingIndex],
725
+ ...filterItem
726
+ };
727
+ } else {
728
+ // Tìm vị trí cuối cùng của item trước đó trong dataFilter
729
+ const prevIndexInFilter = dataFilter.findIndex(f => f.rowId === filterItem.rowId) - 1;
730
+ if (prevIndexInFilter >= 0) {
731
+ const prevId = dataFilter[prevIndexInFilter].rowId;
732
+ const prevIndexInArray = updatedArray.findIndex(item => item.rowId === prevId);
733
+ if (prevIndexInArray !== -1) {
734
+ // Thêm ngay sau phần tử trước đó
735
+ updatedArray.splice(prevIndexInArray + 1, 0, filterItem);
736
+ return;
737
+ }
738
+ }
739
+
740
+ // Nếu không tìm thấy phần tử trước đó, hoặc là phần đầu tiên, thì push vào cuối
741
+ updatedArray.push(filterItem);
742
+ }
743
+ });
744
+ return updatedArray;
745
+ }
746
+ const findItemByKey = (array, key, value) => {
747
+ for (let i = 0; i < array.length; i++) {
748
+ const item = array[i];
749
+ if (item[key] === value) {
750
+ return item;
751
+ }
752
+ if (item.children && item.children.length > 0) {
753
+ const foundInChildren = findItemByKey(item.children, key, value);
754
+ if (foundInChildren) {
755
+ return foundInChildren;
756
+ }
757
+ }
758
+ }
759
+ return null;
760
+ };
761
+ exports.findItemByKey = findItemByKey;
762
+ const isFormattedNumber = str => {
763
+ if (!str) return false;
764
+ if (typeof str !== 'string') return false;
765
+ const regexUS = /^\d{1,3}(,\d{3})*(\.\d+)?$/; // 100,000.111
766
+ const regexEU = /^\d{1,3}(\.\d{3})*(,\d+)?$/; // 100.000,111
767
+
768
+ // Không có dấu hàng nghìn, chỉ dấu thập phân: 100000.1 hoặc 100000,01
769
+ const regexDecimalOnly = /^-?\d+([.,]\d{1,})$/;
770
+ return regexUS.test(str) || regexEU.test(str) || regexDecimalOnly.test(str);
771
+ };
772
+ exports.isFormattedNumber = isFormattedNumber;
773
+ const detectSeparators = str => {
774
+ if (typeof str !== 'string') return null;
775
+ const hasComma = str.includes(',');
776
+ const hasDot = str.includes('.');
777
+
778
+ // Trường hợp có cả dấu , và .
779
+ if (hasComma && hasDot) {
780
+ const lastComma = str.lastIndexOf(',');
781
+ const lastDot = str.lastIndexOf('.');
782
+ return lastComma > lastDot ? {
783
+ thousandSeparator: '.',
784
+ decimalSeparator: ','
785
+ } : {
786
+ thousandSeparator: ',',
787
+ decimalSeparator: '.'
788
+ };
789
+ }
790
+
791
+ // Trường hợp chỉ có dấu phẩy
792
+ if (hasComma && !hasDot) {
793
+ const parts = str.split(',');
794
+ if (parts.length === 2) {
795
+ return parts[1].length === 3 ? {
796
+ thousandSeparator: ',',
797
+ decimalSeparator: undefined
798
+ } : {
799
+ thousandSeparator: undefined,
800
+ decimalSeparator: ','
801
+ };
802
+ }
803
+ }
804
+
805
+ // Trường hợp chỉ có dấu chấm
806
+ if (hasDot && !hasComma) {
807
+ const parts = str.split('.');
808
+ if (parts.length === 2) {
809
+ return parts[1].length === 3 ? {
810
+ thousandSeparator: '.',
811
+ decimalSeparator: undefined
812
+ } : {
813
+ thousandSeparator: undefined,
814
+ decimalSeparator: '.'
815
+ };
816
+ }
817
+ }
818
+
819
+ // Không có dấu hoặc không hợp lệ
820
+ return null;
821
+ };
822
+ exports.detectSeparators = detectSeparators;
823
+ function isDate(value) {
824
+ if (value instanceof Date) {
825
+ return !isNaN(value.getTime());
826
+ }
827
+ if (typeof value === "string") {
828
+ // Chỉ chấp nhận định dạng yyyy-mm-dd hoặc mm/yyyy
829
+ return /^\d{4}-\d{2}-\d{2}$/.test(value) || /^\d{2}\/\d{4}$/.test(value);
830
+ }
831
+ return false;
832
+ }
833
+
834
+ // Chuỗi MM/YYYY → Date
835
+ function isDateString(str) {
836
+ return typeof str === "string" && (/^\d{2}\/\d{4}$/.test(str) || /^\d{4}-\d{2}-\d{2}$/.test(str));
837
+ }
838
+ function parseToDate(str) {
839
+ if (/^\d{2}\/\d{4}$/.test(str)) {
840
+ const [month, year] = str.split('/');
841
+ return new Date(parseInt(year), parseInt(month) - 1, 1);
842
+ }
843
+ return new Date(str);
844
+ }
845
+
846
+ // So sánh ngày (cùng ngày/tháng/năm)
847
+ function compareDates(date1, date2) {
848
+ return date1.getDate() === date2.getDate() && date1.getMonth() === date2.getMonth() && date1.getFullYear() === date2.getFullYear();
849
+ }
850
+
851
+ // Helper: compare MM/YYYY date string with itemValue
852
+ function compareDate(itemValue, value) {
853
+ const [month, year] = value.split('/').map(Number);
854
+ const date = new Date(itemValue);
855
+ return date.getMonth() + 1 === month && date.getFullYear() === year;
856
+ }
857
+ const removeVietnameseTones = str => {
858
+ if (!str) {
859
+ return '';
860
+ }
861
+ return str.normalize('NFD') // Tách các ký tự có dấu thành ký tự cơ bản + dấu
862
+ .replace(/[\u0300-\u036f]/g, '') // Xóa dấu
863
+ .replace(/đ/g, 'd') // Thay thế đ
864
+ .replace(/Đ/g, 'D').replace(/[^a-zA-Z0-9\s]/g, '') // Loại bỏ ký tự đặc biệt
865
+ .replace(/\s+/g, ' ') // Thay nhiều khoảng trắng thành 1 khoảng trắng
866
+ .trim();
867
+ };
868
+ exports.removeVietnameseTones = removeVietnameseTones;
869
+ const shouldInclude = (item, queries) => {
870
+ if (item.isFilterState === true) {
871
+ return true;
872
+ }
873
+ let result = null;
874
+ for (const query of queries) {
875
+ const {
876
+ field,
877
+ value,
878
+ operator,
879
+ predicate
880
+ } = query;
881
+ const itemValue = item[field];
882
+ let condition = false;
883
+ const isDateComparison = isDate(itemValue) || isDateString(value);
884
+ const itemDate = isDateComparison ? new Date(itemValue) : null;
885
+ const queryDate = isDateComparison ? parseToDate(value) : null;
886
+ const itemStr = removeVietnameseTones(itemValue?.toString().toLowerCase?.() ?? '');
887
+ const queryStr = removeVietnameseTones(value?.toString().toLowerCase?.() ?? '');
888
+ switch (operator.toLowerCase()) {
889
+ case "equal":
890
+ condition = isDateComparison ? compareDates(itemDate, queryDate) : itemValue === value;
891
+ break;
892
+ case "notequal":
893
+ condition = isDateComparison ? !compareDates(itemDate, queryDate) : itemValue !== value;
894
+ break;
895
+ case "greaterthan":
896
+ // @ts-ignore
897
+ condition = isDateComparison ? itemDate > queryDate : itemValue > value;
898
+
899
+ // condition = isDateComparison ? invalidDate(itemDate) && invalidDate(queryDate) && itemDate > queryDate : itemValue > value;
900
+ break;
901
+ case "greaterthanorequal":
902
+ // @ts-ignore
903
+ condition = isDateComparison ? itemDate >= queryDate : itemValue >= value;
904
+ break;
905
+ case "lessthan":
906
+ // @ts-ignore
907
+ condition = isDateComparison ? itemDate < queryDate : itemValue < value;
908
+ break;
909
+ case "lessthanorequal":
910
+ // @ts-ignore
911
+ condition = isDateComparison ? itemDate <= queryDate : itemValue <= value;
912
+ break;
913
+ case "contains":
914
+ condition = itemStr?.includes(queryStr);
915
+ break;
916
+ case "startswith":
917
+ condition = itemStr?.startsWith(queryStr);
918
+ break;
919
+ case "endswith":
920
+ condition = itemStr?.endsWith(queryStr);
921
+ break;
922
+ default:
923
+ console.warn(`Unknown operator: ${operator}`);
924
+ break;
925
+ }
926
+ if (predicate === "and") {
927
+ result = result === null ? condition : result && condition;
928
+ } else if (predicate === "or") {
929
+ result = result === null ? condition : result || condition;
930
+ }
931
+ }
932
+ return result;
933
+ };
934
+ exports.shouldInclude = shouldInclude;
935
+ function getSortValue(item, field) {
936
+ if (item[field] !== undefined) return item[field];
937
+ if (item.children && item.children.length > 0) {
938
+ return getSortValue(item.children[0], field);
939
+ }
940
+ return undefined;
941
+ }
942
+ function compareValues(a, b, order) {
943
+ const desc = order === "descend";
944
+ if (a == null && b == null) return 0;
945
+ if (a == null) return desc ? 1 : -1;
946
+ if (b == null) return desc ? -1 : 1;
947
+
948
+ // Nếu là số
949
+ if (typeof a === "number" && typeof b === "number") {
950
+ return desc ? b - a : a - b;
951
+ }
952
+
953
+ // Nếu là ngày hợp lệ
954
+ const dateA = new Date(a);
955
+ const dateB = new Date(b);
956
+ if (!isNaN(dateA.getTime()) && !isNaN(dateB.getTime())) {
957
+ return desc ? dateB.getTime() - dateA.getTime() : dateA.getTime() - dateB.getTime();
958
+ }
959
+
960
+ // Mặc định coi như string
961
+ return desc ? String(b).localeCompare(String(a)) : String(a).localeCompare(String(b));
962
+ }
963
+ function sortData(data, sorter) {
964
+ const sorted = [...data].sort((a, b) => {
965
+ for (const {
966
+ field,
967
+ order
968
+ } of sorter) {
969
+ const result = compareValues(getSortValue(a, field), getSortValue(b, field), order);
970
+ if (result !== 0) return result;
971
+ }
972
+ return 0;
973
+ });
974
+ return sorted.map(item => ({
975
+ ...item,
976
+ children: item.children ? sortData(item.children, sorter) : undefined
977
+ }));
978
+ }
979
+ function filterDataByColumns(data, queries, sorter, keysFilter) {
980
+ if (!queries || queries.length === 0) {
981
+ return sorter ? sortData(data, sorter) : data;
982
+ }
983
+ let filtered = data.map(item => {
984
+ const newItem = {
985
+ ...item
986
+ };
987
+ if (Array.isArray(item.children)) {
988
+ newItem.children = filterDataByColumns(item.children, queries, sorter, keysFilter);
989
+ }
990
+ const isSelfMatched = shouldInclude(item, queries) || keysFilter?.includes(newItem?.rowId);
991
+
992
+ // Nếu chính item thỏa hoặc có con thỏa → giữ lại
993
+ if (isSelfMatched || newItem.children && newItem.children.length > 0) {
994
+ return newItem;
995
+ }
996
+ return null; // loại bỏ node không phù hợp
997
+ }).filter(Boolean); // xóa các null
998
+
999
+ if (sorter && sorter.length > 0) {
1000
+ filtered = sortData(filtered, sorter);
1001
+ }
1002
+ return filtered;
1003
+ }
1004
+ const getAllRowKey = data => {
1005
+ const a = flattenArray(data);
1006
+ return a.length ? a.map(it => it.rowId) : undefined;
1007
+ };
1008
+ exports.getAllRowKey = getAllRowKey;
1009
+ const isEditable = (column, rowData) => {
1010
+ if (column && typeof column.editEnable === 'function') {
1011
+ return column.editEnable(rowData);
1012
+ }
1013
+ return column?.editEnable;
1014
+ };
1015
+ exports.isEditable = isEditable;
1016
+ const checkFieldKey = key => {
1017
+ if (key) {
1018
+ return key;
1019
+ } else {
1020
+ return 'value';
1021
+ }
1022
+ };
1023
+ exports.checkFieldKey = checkFieldKey;
1024
+ const convertArrayWithIndent = (inputArray, parentIndent = 0) => {
1025
+ if (inputArray) {
1026
+ return inputArray.map(item => {
1027
+ const indent = parentIndent;
1028
+ if (item.children && item.children.length > 0) {
1029
+ item.children = convertArrayWithIndent(item.children, indent + 1);
1030
+ }
1031
+ return {
1032
+ ...item,
1033
+ indent,
1034
+ rowId: item.rowId ? item.rowId : item.id ? item.id : newGuid()
1035
+ };
1036
+ });
1037
+ } else {
1038
+ return [];
1039
+ }
1040
+ };
1041
+ exports.convertArrayWithIndent = convertArrayWithIndent;
1042
+ const convertLabelToTitle = data => {
1043
+ return data.map(item => {
1044
+ const {
1045
+ label,
1046
+ title,
1047
+ value,
1048
+ key,
1049
+ ...rest
1050
+ } = item;
1051
+ const newItem = {
1052
+ ...rest,
1053
+ value,
1054
+ label,
1055
+ key: key ?? value,
1056
+ title: title ?? label
1057
+ };
1058
+ if (item.children) {
1059
+ newItem.children = convertLabelToTitle(item.children);
1060
+ }
1061
+ return newItem;
1062
+ });
1063
+ };
1064
+ exports.convertLabelToTitle = convertLabelToTitle;
1065
+ const isNullOrUndefined = d => {
1066
+ return d === null || d === undefined;
1067
+ };
1068
+ exports.isNullOrUndefined = isNullOrUndefined;
1069
+ const isObjEmpty = obj => {
1070
+ if (isNullOrUndefined(obj)) {
1071
+ return true;
1072
+ } else {
1073
+ return Object.keys(obj).length === 0;
1074
+ }
1075
+ };
1076
+ exports.isObjEmpty = isObjEmpty;
1077
+ const isDisable = (column, rowData) => {
1078
+ if (column && typeof column?.disable === 'function') {
1079
+ return column.disable(rowData);
1080
+ }
1081
+ return !!column?.disable;
1082
+ };
1083
+ exports.isDisable = isDisable;
1084
+ const customWeekStartEndFormat = (value, weekFormat) => {
1085
+ return `${(0, _dayjs.default)(value).startOf('week').format(weekFormat)} ~ ${(0, _dayjs.default)(value).endOf('week').format(weekFormat)}`;
1086
+ };
1087
+ exports.customWeekStartEndFormat = customWeekStartEndFormat;
1088
+ const parseBooleanToValue = (value, type) => {
1089
+ return type === 'boolean' ? value : Number(value);
1090
+ };
1091
+ exports.parseBooleanToValue = parseBooleanToValue;
1092
+ const isNameColor = strColor => {
1093
+ const s = new Option().style;
1094
+ s.color = strColor;
1095
+ return s.color === strColor;
1096
+ };
1097
+ exports.isNameColor = isNameColor;
1098
+ const isColor = value => {
1099
+ const hexRegex = /^#([0-9A-F]{3}){1,2}$/i;
1100
+ const rgbRegex = /^rgb\((\d{1,3}), (\d{1,3}), (\d{1,3})\)$/;
1101
+ const rgbaRegex = /^rgba\((\d{1,3}), (\d{1,3}), (\d{1,3}), (0|1|0?\.\d+)\)$/;
1102
+ const hslRegex = /^hsl\(\d{1,3}, \d{1,3}%, \d{1,3}%\)$/;
1103
+ const hslaRegex = /^hsla\(\d{1,3}, \d{1,3}%, \d{1,3}%, (0|1|0?\.\d+)\)$/;
1104
+ const namedColors = /^(?:aqua|black|blue|fuchsia|gray|green|lime|maroon|navy|olive|purple|red|silver|teal|white|yellow)$/i;
1105
+ return hexRegex.test(value) || rgbRegex.test(value) || rgbaRegex.test(value) || hslRegex.test(value) || hslaRegex.test(value) || namedColors.test(value) || isNameColor(value);
1106
+ };
1107
+ exports.isColor = isColor;
1108
+ const genPresets = (presets = _colors.presetPalettes) => {
1109
+ return Object.entries(presets).map(([label, colors]) => ({
1110
+ label,
1111
+ colors,
1112
+ key: label
1113
+ }));
1114
+ };
1115
+ exports.genPresets = genPresets;
1116
+ const getEditType = (column, rowData) => {
1117
+ if (column && typeof column.editType === 'function') {
1118
+ return column.editType(rowData);
1119
+ }
1120
+ return column?.editType ?? 'text';
1121
+ };
1122
+ exports.getEditType = getEditType;
1123
+ const getDefaultValue = defaultValue => {
1124
+ if (defaultValue && typeof defaultValue === 'function') {
1125
+ return defaultValue();
1126
+ }
1127
+ return defaultValue;
1128
+ };
1129
+ exports.getDefaultValue = getDefaultValue;
1130
+ const flattenData = (childrenColumnName, data) => {
1131
+ let list = [];
1132
+ (data || []).forEach(record => {
1133
+ list.push(record);
1134
+ if (record && typeof record === 'object' && childrenColumnName in record) {
1135
+ list = [...list, ...flattenData(childrenColumnName, record[childrenColumnName])];
1136
+ }
1137
+ });
1138
+ return list;
1139
+ };
1140
+ exports.flattenData = flattenData;
1141
+ const getSelectedCellMatrix = (table, startCell, endCell) => {
1142
+ if (!startCell || !endCell) return {
1143
+ rowIds: [],
1144
+ colIds: [],
1145
+ startRowIndex: undefined,
1146
+ endRowIndex: undefined,
1147
+ startColIndex: undefined,
1148
+ endColIndex: undefined,
1149
+ colRange: [],
1150
+ rowRange: []
1151
+ };
1152
+
1153
+ // const rowIds = table.getRowModel().rows.map(r => r.id);
1154
+ const rowIds = table.getRowModel().flatRows.map(r => r.id);
1155
+ const colIds = table.getVisibleLeafColumns().map(c => c.id);
1156
+
1157
+ // const colIds = table.getAllLeafColumns().map(c => c.id);
1158
+
1159
+ const [startRowIndex, endRowIndex] = [rowIds.indexOf(startCell.rowId), rowIds.indexOf(endCell.rowId)].sort((a, b) => a - b);
1160
+ const [startColIndex, endColIndex] = [colIds.indexOf(startCell.colId), colIds.indexOf(endCell.colId)].sort((a, b) => a - b);
1161
+ return {
1162
+ rowRange: rowIds.slice(startRowIndex, endRowIndex + 1),
1163
+ colRange: colIds.slice(startColIndex, endColIndex + 1),
1164
+ startRowIndex,
1165
+ endRowIndex,
1166
+ startColIndex,
1167
+ endColIndex,
1168
+ rowIds,
1169
+ colIds
1170
+ };
1171
+ };
1172
+ exports.getSelectedCellMatrix = getSelectedCellMatrix;
1173
+ function addRowsDownWithCtrl(arr, n) {
1174
+ if (!Array.isArray(arr) || arr.length === 0) {
1175
+ return {
1176
+ combined: arr,
1177
+ addedRows: []
1178
+ };
1179
+ }
1180
+ const m = arr.length;
1181
+ const numCols = arr[0].length;
1182
+ const addedRows = [];
1183
+
1184
+ // Hàm kiểm tra kiểu date hợp lệ
1185
+ const isValidDate = item => {
1186
+ // return !isNaN(Date.parse(d))
1187
+
1188
+ if (typeof item === 'number') {
1189
+ // return 'number'
1190
+ return false;
1191
+ }
1192
+ if (typeof item === 'string') {
1193
+ // Kiểm tra nếu là chuỗi ISO date hợp lệ
1194
+ const date = new Date(item);
1195
+ if (!isNaN(date.getTime()) && item.includes('T')) {
1196
+ // return 'date'
1197
+ return true;
1198
+ }
1199
+ // return 'string'
1200
+ return false;
1201
+ }
1202
+ return !isNaN(Date.parse(item));
1203
+ };
1204
+
1205
+ // Lấy giá trị mẫu của cột j từ hàng đầu tiên
1206
+ const getSample = j => arr[0][j];
1207
+
1208
+ // Xác định chế độ xử lý cho mỗi cột:
1209
+ // mode = 'number-stepping' | 'date-stepping' | 'number-constant' | 'cycle'
1210
+ const modes = [];
1211
+ const steps = []; // bước tăng, nếu có (cho number hoặc date)
1212
+
1213
+ for (let j = 0; j < numCols; j++) {
1214
+ const sample = getSample(j);
1215
+ if (m === 1) {
1216
+ // 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.
1217
+ if (typeof sample === "number") {
1218
+ modes[j] = "number-constant";
1219
+ } else if (isValidDate(sample)) {
1220
+ modes[j] = "date-stepping";
1221
+ steps[j] = 24 * 3600 * 1000; // 1 ngày = 86400000 ms
1222
+ } else {
1223
+ modes[j] = "cycle";
1224
+ }
1225
+ } else if (m === 2) {
1226
+ // 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
1227
+ const first = arr[0][j],
1228
+ second = arr[1][j];
1229
+ if (typeof first === "number" && typeof second === "number") {
1230
+ modes[j] = "number-stepping";
1231
+ steps[j] = second - first;
1232
+ } else if (isValidDate(first) && isValidDate(second)) {
1233
+ modes[j] = "date-stepping";
1234
+ steps[j] = Date.parse(second) - Date.parse(first);
1235
+ } else {
1236
+ modes[j] = "cycle";
1237
+ }
1238
+ } else {
1239
+ // Nếu mảng có >2 hàng
1240
+ const first = arr[0][j],
1241
+ second = arr[1][j],
1242
+ third = arr[2][j];
1243
+ if (typeof first === "number" && typeof second === "number" && typeof third === "number") {
1244
+ const step1 = second - first;
1245
+ const step2 = third - second;
1246
+ if (step1 === step2) {
1247
+ modes[j] = "number-stepping";
1248
+ steps[j] = step1;
1249
+ } else {
1250
+ modes[j] = "cycle";
1251
+ }
1252
+ } else if (isValidDate(first) && isValidDate(second) && isValidDate(third)) {
1253
+ const step1 = Date.parse(second) - Date.parse(first);
1254
+ const step2 = Date.parse(third) - Date.parse(second);
1255
+ if (step1 === step2) {
1256
+ modes[j] = "date-stepping";
1257
+ steps[j] = step1;
1258
+ } else {
1259
+ modes[j] = "cycle";
1260
+ }
1261
+ } else {
1262
+ modes[j] = "cycle";
1263
+ }
1264
+ }
1265
+ }
1266
+
1267
+ // Tạo các dòng mới (thêm n dòng)
1268
+ // 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
1269
+ // Nếu chế độ là cycle thì dùng arr[i mod m][j]
1270
+ for (let i = 0; i < n; i++) {
1271
+ const newRow = [];
1272
+ for (let j = 0; j < numCols; j++) {
1273
+ let newValue;
1274
+ switch (modes[j]) {
1275
+ case "number-constant":
1276
+ // Mảng có 1 hàng, số giữ nguyên
1277
+ newValue = arr[0][j];
1278
+ break;
1279
+ case "number-stepping":
1280
+ {
1281
+ // Lấy giá trị cuối của cột j trong mảng ban đầu
1282
+ const lastValue = arr[m - 1][j];
1283
+ newValue = lastValue + (i + 1) * steps[j];
1284
+ }
1285
+ break;
1286
+ case "date-stepping":
1287
+ {
1288
+ // 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
1289
+ const lastDate = new Date(arr[m - 1][j]);
1290
+ const newTime = lastDate.getTime() + (i + 1) * steps[j];
1291
+ newValue = (0, _moment.default)(new Date(newTime)).format();
1292
+ }
1293
+ break;
1294
+ case "cycle":
1295
+ default:
1296
+ // Lặp lại nội dung theo vòng tròn: dùng hàng thứ (i mod m)
1297
+ newValue = arr[i % m][j];
1298
+ break;
1299
+ }
1300
+ newRow.push(newValue);
1301
+ }
1302
+ addedRows.push(newRow);
1303
+ }
1304
+ const combined = arr.concat(addedRows);
1305
+ return {
1306
+ combined,
1307
+ addedRows
1308
+ };
1309
+ }
1310
+ function addRowsDown(arr, n) {
1311
+ if (!Array.isArray(arr) || arr.length === 0) {
1312
+ return {
1313
+ combined: arr,
1314
+ addedRows: []
1315
+ };
1316
+ }
1317
+ const m = arr.length;
1318
+ const numCols = arr[0].length;
1319
+ const addedRows = [];
1320
+
1321
+ // // Hàm kiểm tra kiểu date hợp lệ
1322
+ // const isValidDate = (item: any) => {
1323
+ //
1324
+ //
1325
+ // // return !isNaN(Date.parse(d))
1326
+ //
1327
+ // if (typeof item === 'number') {
1328
+ // // return 'number'
1329
+ // return false
1330
+ // }
1331
+ // if (typeof item === 'string') {
1332
+ // // Kiểm tra nếu là chuỗi ISO date hợp lệ
1333
+ // const date = new Date(item)
1334
+ // if (!isNaN(date.getTime()) && item.includes('T')) {
1335
+ // // return 'date'
1336
+ // return true
1337
+ // }
1338
+ // // return 'string'
1339
+ // return false
1340
+ // }
1341
+ //
1342
+ // return !isNaN(Date.parse(item))
1343
+ //
1344
+ // }
1345
+
1346
+ // Lấy giá trị mẫu của cột j từ hàng đầu tiên
1347
+ const getSample = j => arr[0][j];
1348
+
1349
+ // Xác định chế độ xử lý cho mỗi cột:
1350
+ // mode = 'number-stepping' | 'date-stepping' | 'number-constant' | 'cycle'
1351
+ const modes = [];
1352
+ const steps = []; // bước tăng, nếu có (cho number hoặc date)
1353
+
1354
+ for (let j = 0; j < numCols; j++) {
1355
+ const sample = getSample(j);
1356
+ if (m === 1) {
1357
+ // 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.
1358
+ if (typeof sample === "number") {
1359
+ modes[j] = "number-constant";
1360
+ }
1361
+ // else if (isValidDate(sample)) {
1362
+ // modes[j] = "date-stepping"
1363
+ // steps[j] = 24 * 3600 * 1000 // 1 ngày = 86400000 ms
1364
+ // }
1365
+ else {
1366
+ modes[j] = "cycle";
1367
+ }
1368
+ } else if (m === 2) {
1369
+ // 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
1370
+ const first = arr[0][j],
1371
+ second = arr[1][j];
1372
+ if (typeof first === "number" && typeof second === "number") {
1373
+ modes[j] = "number-stepping";
1374
+ steps[j] = second - first;
1375
+ }
1376
+ // else if (isValidDate(first) && isValidDate(second)) {
1377
+ // modes[j] = "date-stepping"
1378
+ // steps[j] = Date.parse(second) - Date.parse(first)
1379
+ // }
1380
+ else {
1381
+ modes[j] = "cycle";
1382
+ }
1383
+ } else {
1384
+ // Nếu mảng có >2 hàng
1385
+ const first = arr[0][j],
1386
+ second = arr[1][j],
1387
+ third = arr[2][j];
1388
+ if (typeof first === "number" && typeof second === "number" && typeof third === "number") {
1389
+ const step1 = second - first;
1390
+ const step2 = third - second;
1391
+ if (step1 === step2) {
1392
+ modes[j] = "number-stepping";
1393
+ steps[j] = step1;
1394
+ } else {
1395
+ modes[j] = "cycle";
1396
+ }
1397
+ }
1398
+ // else if (isValidDate(first) && isValidDate(second) && isValidDate(third)) {
1399
+ // const step1 = Date.parse(second) - Date.parse(first)
1400
+ // const step2 = Date.parse(third) - Date.parse(second)
1401
+ // if (step1 === step2) {
1402
+ // modes[j] = "date-stepping"
1403
+ // steps[j] = step1
1404
+ // } else {
1405
+ // modes[j] = "cycle"
1406
+ // }
1407
+ // }
1408
+ else {
1409
+ modes[j] = "cycle";
1410
+ }
1411
+ }
1412
+ }
1413
+
1414
+ // Tạo các dòng mới (thêm n dòng)
1415
+ // 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
1416
+ // Nếu chế độ là cycle thì dùng arr[i mod m][j]
1417
+ for (let i = 0; i < n; i++) {
1418
+ const newRow = [];
1419
+ for (let j = 0; j < numCols; j++) {
1420
+ let newValue;
1421
+ switch (modes[j]) {
1422
+ case "number-constant":
1423
+ // Mảng có 1 hàng, số giữ nguyên
1424
+ newValue = arr[0][j];
1425
+ break;
1426
+ case "number-stepping":
1427
+ {
1428
+ // Lấy giá trị cuối của cột j trong mảng ban đầu
1429
+ const lastValue = arr[m - 1][j];
1430
+ newValue = lastValue + (i + 1) * steps[j];
1431
+ }
1432
+ break;
1433
+ // case "date-stepping":
1434
+ // {
1435
+ // // 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
1436
+ // const lastDate = new Date(arr[m - 1][j])
1437
+ // const newTime = lastDate.getTime() + (i + 1) * steps[j]
1438
+ // newValue = moment(new Date(newTime)).format()
1439
+ // }
1440
+ // break
1441
+ case "cycle":
1442
+ default:
1443
+ // Lặp lại nội dung theo vòng tròn: dùng hàng thứ (i mod m)
1444
+ newValue = arr[i % m][j];
1445
+ break;
1446
+ }
1447
+ newRow.push(newValue);
1448
+ }
1449
+ addedRows.push(newRow);
1450
+ }
1451
+ const combined = arr.concat(addedRows);
1452
+ return {
1453
+ combined,
1454
+ addedRows
1455
+ };
1456
+ }
1457
+ function addRowsUpWithCtrl(array, n) {
1458
+ const arr = array.reverse();
1459
+ if (!Array.isArray(arr) || arr.length === 0) {
1460
+ return {
1461
+ combined: arr,
1462
+ addedRows: []
1463
+ };
1464
+ }
1465
+ const m = arr.length;
1466
+ const numCols = arr[0].length;
1467
+ const addedRows = [];
1468
+
1469
+ // Hàm kiểm tra kiểu date hợp lệ
1470
+ const isValidDate = item => {
1471
+ // return !isNaN(Date.parse(d))
1472
+
1473
+ if (typeof item === 'number') {
1474
+ // return 'number'
1475
+ return false;
1476
+ }
1477
+ if (typeof item === 'string') {
1478
+ // Kiểm tra nếu là chuỗi ISO date hợp lệ
1479
+ const date = new Date(item);
1480
+ if (!isNaN(date.getTime()) && item.includes('T')) {
1481
+ // return 'date'
1482
+ return true;
1483
+ }
1484
+ // return 'string'
1485
+ return false;
1486
+ }
1487
+ return !isNaN(Date.parse(item));
1488
+ };
1489
+
1490
+ // Lấy giá trị mẫu của cột j từ hàng đầu tiên
1491
+ const getSample = j => arr[0][j];
1492
+
1493
+ // Xác định chế độ xử lý cho mỗi cột:
1494
+ // mode = 'number-stepping' | 'date-stepping' | 'number-constant' | 'cycle'
1495
+ const modes = [];
1496
+ const steps = []; // bước tăng, nếu có (cho number hoặc date)
1497
+
1498
+ for (let j = 0; j < numCols; j++) {
1499
+ const sample = getSample(j);
1500
+ if (m === 1) {
1501
+ // 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.
1502
+ if (typeof sample === "number") {
1503
+ modes[j] = "number-constant";
1504
+ } else if (isValidDate(sample)) {
1505
+ modes[j] = "date-stepping";
1506
+ steps[j] = 24 * 3600 * 1000; // 1 ngày = 86400000 ms
1507
+ } else {
1508
+ modes[j] = "cycle";
1509
+ }
1510
+ } else if (m === 2) {
1511
+ // 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
1512
+ const first = arr[0][j],
1513
+ second = arr[1][j];
1514
+ if (typeof first === "number" && typeof second === "number") {
1515
+ modes[j] = "number-stepping";
1516
+ steps[j] = second - first;
1517
+ } else if (isValidDate(first) && isValidDate(second)) {
1518
+ modes[j] = "date-stepping";
1519
+ steps[j] = Date.parse(second) - Date.parse(first);
1520
+ } else {
1521
+ modes[j] = "cycle";
1522
+ }
1523
+ } else {
1524
+ // Nếu mảng có >2 hàng
1525
+ const first = arr[0][j],
1526
+ second = arr[1][j],
1527
+ third = arr[2][j];
1528
+ if (typeof first === "number" && typeof second === "number" && typeof third === "number") {
1529
+ const step1 = second - first;
1530
+ const step2 = third - second;
1531
+ if (step1 === step2) {
1532
+ modes[j] = "number-stepping";
1533
+ steps[j] = step1;
1534
+ } else {
1535
+ modes[j] = "cycle";
1536
+ }
1537
+ } else if (isValidDate(first) && isValidDate(second) && isValidDate(third)) {
1538
+ const step1 = Date.parse(second) - Date.parse(first);
1539
+ const step2 = Date.parse(third) - Date.parse(second);
1540
+ if (step1 === step2) {
1541
+ modes[j] = "date-stepping";
1542
+ steps[j] = step1;
1543
+ } else {
1544
+ modes[j] = "cycle";
1545
+ }
1546
+ } else {
1547
+ modes[j] = "cycle";
1548
+ }
1549
+ }
1550
+ }
1551
+
1552
+ // Tạo các dòng mới (thêm n dòng)
1553
+ // 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
1554
+ // Nếu chế độ là cycle thì dùng arr[i mod m][j]
1555
+ for (let i = n - 1; i >= 0; i--) {
1556
+ const newRow = [];
1557
+ for (let j = 0; j < numCols; j++) {
1558
+ let newValue;
1559
+ switch (modes[j]) {
1560
+ case "number-constant":
1561
+ // Mảng có 1 hàng, số giữ nguyên
1562
+ newValue = arr[0][j];
1563
+ break;
1564
+ case "number-stepping":
1565
+ {
1566
+ // Lấy giá trị cuối của cột j trong mảng ban đầu
1567
+
1568
+ const lastValue = arr[m - 1][j];
1569
+ newValue = lastValue - (i + 1) * steps[j] * -1;
1570
+ }
1571
+ break;
1572
+ case "date-stepping":
1573
+ {
1574
+ // 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
1575
+
1576
+ const lastDate = new Date(arr[m - 1][j]);
1577
+ const newTime = m === 1 ? lastDate.getTime() - (i + 1) * steps[j] : lastDate.getTime() - (i + 1) * steps[j] * -1;
1578
+ newValue = (0, _moment.default)(new Date(newTime)).format();
1579
+ }
1580
+ break;
1581
+ case "cycle":
1582
+ default:
1583
+ // Lặp lại nội dung theo vòng tròn: dùng hàng thứ (i mod m)
1584
+
1585
+ newValue = arr[i % m][j];
1586
+ break;
1587
+ }
1588
+ newRow.push(newValue);
1589
+ }
1590
+ addedRows.push(newRow);
1591
+ }
1592
+ const combined = arr.concat(addedRows);
1593
+ return {
1594
+ combined,
1595
+ addedRows
1596
+ };
1597
+ }
1598
+ function addRowsUp(array, n) {
1599
+ const arr = array.reverse();
1600
+ if (!Array.isArray(arr) || arr.length === 0) {
1601
+ return {
1602
+ combined: arr,
1603
+ addedRows: []
1604
+ };
1605
+ }
1606
+ const m = arr.length;
1607
+ const numCols = arr[0].length;
1608
+ const addedRows = [];
1609
+
1610
+ // Hàm kiểm tra kiểu date hợp lệ
1611
+ // const isValidDate = (item: any) => {
1612
+ //
1613
+ //
1614
+ // // return !isNaN(Date.parse(d))
1615
+ //
1616
+ // if (typeof item === 'number') {
1617
+ // // return 'number'
1618
+ // return false
1619
+ // }
1620
+ // if (typeof item === 'string') {
1621
+ // // Kiểm tra nếu là chuỗi ISO date hợp lệ
1622
+ // const date = new Date(item)
1623
+ // if (!isNaN(date.getTime()) && item.includes('T')) {
1624
+ // // return 'date'
1625
+ // return true
1626
+ // }
1627
+ // // return 'string'
1628
+ // return false
1629
+ // }
1630
+ //
1631
+ // return !isNaN(Date.parse(item))
1632
+ //
1633
+ // }
1634
+
1635
+ // Lấy giá trị mẫu của cột j từ hàng đầu tiên
1636
+ const getSample = j => arr[0][j];
1637
+
1638
+ // Xác định chế độ xử lý cho mỗi cột:
1639
+ // mode = 'number-stepping' | 'date-stepping' | 'number-constant' | 'cycle'
1640
+ const modes = [];
1641
+ const steps = []; // bước tăng, nếu có (cho number hoặc date)
1642
+
1643
+ for (let j = 0; j < numCols; j++) {
1644
+ const sample = getSample(j);
1645
+ if (m === 1) {
1646
+ // 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.
1647
+ if (typeof sample === "number") {
1648
+ modes[j] = "number-constant";
1649
+ } else {
1650
+ modes[j] = "cycle";
1651
+ }
1652
+ } else if (m === 2) {
1653
+ // 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
1654
+ const first = arr[0][j],
1655
+ second = arr[1][j];
1656
+ if (typeof first === "number" && typeof second === "number") {
1657
+ modes[j] = "number-stepping";
1658
+ steps[j] = second - first;
1659
+ } else {
1660
+ modes[j] = "cycle";
1661
+ }
1662
+ } else {
1663
+ // Nếu mảng có >2 hàng
1664
+ const first = arr[0][j],
1665
+ second = arr[1][j],
1666
+ third = arr[2][j];
1667
+ if (typeof first === "number" && typeof second === "number" && typeof third === "number") {
1668
+ const step1 = second - first;
1669
+ const step2 = third - second;
1670
+ if (step1 === step2) {
1671
+ modes[j] = "number-stepping";
1672
+ steps[j] = step1;
1673
+ } else {
1674
+ modes[j] = "cycle";
1675
+ }
1676
+ } else {
1677
+ modes[j] = "cycle";
1678
+ }
1679
+ }
1680
+ }
1681
+
1682
+ // Tạo các dòng mới (thêm n dòng)
1683
+ // 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
1684
+ // Nếu chế độ là cycle thì dùng arr[i mod m][j]
1685
+ for (let i = n - 1; i >= 0; i--) {
1686
+ const newRow = [];
1687
+ for (let j = 0; j < numCols; j++) {
1688
+ let newValue;
1689
+ switch (modes[j]) {
1690
+ case "number-constant":
1691
+ // Mảng có 1 hàng, số giữ nguyên
1692
+ newValue = arr[0][j];
1693
+ break;
1694
+ case "number-stepping":
1695
+ {
1696
+ // Lấy giá trị cuối của cột j trong mảng ban đầu
1697
+
1698
+ const lastValue = arr[m - 1][j];
1699
+ newValue = lastValue - (i + 1) * steps[j] * -1;
1700
+ }
1701
+ break;
1702
+ case "cycle":
1703
+ default:
1704
+ // Lặp lại nội dung theo vòng tròn: dùng hàng thứ (i mod m)
1705
+
1706
+ newValue = arr[i % m][j];
1707
+ break;
1708
+ }
1709
+ newRow.push(newValue);
1710
+ }
1711
+ addedRows.push(newRow);
1712
+ }
1713
+ const combined = arr.concat(addedRows);
1714
+ return {
1715
+ combined,
1716
+ addedRows
1717
+ };
1718
+ }
1719
+ const convertFilters = filters => {
1720
+ const result = [];
1721
+ filters.forEach(({
1722
+ key,
1723
+ column,
1724
+ filteredKeys,
1725
+ operator
1726
+ }) => {
1727
+ if (!filteredKeys || filteredKeys.length === 0) {
1728
+ return;
1729
+ }
1730
+ if (column?.typeFilter === "DateRange" && filteredKeys.length === 2) {
1731
+ result.push({
1732
+ key,
1733
+ field: column?.field,
1734
+ value: filteredKeys[0],
1735
+ predicate: "and",
1736
+ operator: "greaterthanorequal"
1737
+ }, {
1738
+ key,
1739
+ field: column?.field,
1740
+ value: filteredKeys[1],
1741
+ predicate: "and",
1742
+ operator: "lessthanorequal"
1743
+ });
1744
+ } else if (column?.typeFilter === "NumberRange") {
1745
+ if ((filteredKeys[0] || filteredKeys[0] === 0) && !filteredKeys[1]) {
1746
+ result.push({
1747
+ key,
1748
+ field: column?.field,
1749
+ value: filteredKeys[0],
1750
+ predicate: "and",
1751
+ operator: "greaterthanorequal"
1752
+ });
1753
+ }
1754
+ if ((filteredKeys[1] || filteredKeys[1] === 0) && !filteredKeys[0]) {
1755
+ result.push({
1756
+ key,
1757
+ field: column?.field,
1758
+ value: filteredKeys[1],
1759
+ predicate: "and",
1760
+ operator: "lessthanorequal"
1761
+ });
1762
+ }
1763
+ if ((filteredKeys[0] || filteredKeys[0] === 0) && (filteredKeys[1] || filteredKeys[1] === 0)) {
1764
+ result.push({
1765
+ key,
1766
+ field: column?.field,
1767
+ value: filteredKeys[0],
1768
+ predicate: "and",
1769
+ operator: "greaterthanorequal"
1770
+ }, {
1771
+ key,
1772
+ field: column?.field,
1773
+ value: filteredKeys[1],
1774
+ predicate: "and",
1775
+ operator: "lessthanorequal"
1776
+ });
1777
+ }
1778
+ } else if (column?.typeFilter === 'Checkbox') {
1779
+ filteredKeys.forEach(value => {
1780
+ result.push({
1781
+ key,
1782
+ field: column?.field,
1783
+ value,
1784
+ predicate: "or",
1785
+ operator
1786
+ });
1787
+ });
1788
+ } else {
1789
+ result.push({
1790
+ key,
1791
+ field: column?.field,
1792
+ value: filteredKeys[0],
1793
+ predicate: 'and',
1794
+ operator
1795
+ });
1796
+ }
1797
+ });
1798
+ return result;
1799
+ };
1800
+
1801
+ // export function getInvisibleColumns(columns: ColumnTable[]): Record<string, boolean> {
1802
+ // const result: Record<string, boolean> = {};
1803
+ // for (const col of columns) {
1804
+ // if (col.visible === false || col.hidden) {
1805
+ // result[col.field ?? ''] = false;
1806
+ // }
1807
+ // }
1808
+ // return result;
1809
+ // }
1810
+ exports.convertFilters = convertFilters;
1811
+ function getInvisibleColumns(columns) {
1812
+ const result = {};
1813
+ function traverse(cols) {
1814
+ for (const col of cols) {
1815
+ if (col.visible === false) {
1816
+ result[col.field ?? ''] = false;
1817
+ }
1818
+ if (col.children && col.children.length > 0) {
1819
+ traverse(col.children);
1820
+ }
1821
+ }
1822
+ }
1823
+ traverse(columns);
1824
+ return result;
1825
+ }
1826
+ const getAllVisibleKeys = columns => {
1827
+ const keys = [];
1828
+ const traverse = (cols, parentHidden = false) => {
1829
+ for (const col of cols) {
1830
+ if (col.hidden || parentHidden) {
1831
+ continue;
1832
+ }
1833
+ if (col.key) {
1834
+ keys.push(col.key);
1835
+ }
1836
+ if (col.children) {
1837
+ traverse(col.children, col.hidden);
1838
+ }
1839
+ }
1840
+ };
1841
+ traverse(columns);
1842
+ return keys;
1843
+ };
1844
+ exports.getAllVisibleKeys = getAllVisibleKeys;
1845
+ const getAllVisibleKeys1 = columns => {
1846
+ const keys = [];
1847
+ const traverse = (cols, parentHidden = false) => {
1848
+ for (const col of cols) {
1849
+ if (col.visible === false || col.hidden || parentHidden) {
1850
+ continue;
1851
+ }
1852
+ if (col.field) {
1853
+ keys.push(col.field);
1854
+ }
1855
+ if (col.children) {
1856
+ traverse(col.children, col.visible);
1857
+ }
1858
+ }
1859
+ };
1860
+ traverse(columns);
1861
+ return keys;
1862
+ };
1863
+ exports.getAllVisibleKeys1 = getAllVisibleKeys1;
1864
+ function getHiddenParentKeys(columns, parentKeys = []) {
1865
+ const hiddenParents = new Set();
1866
+ for (const column of columns) {
1867
+ if (column.children) {
1868
+ const currentPath = column.key ? [...parentKeys, column.key] : [...parentKeys];
1869
+ const childHiddenParents = getHiddenParentKeys(column.children, currentPath);
1870
+ if (childHiddenParents.length > 0) {
1871
+ childHiddenParents.forEach(key => hiddenParents.add(key));
1872
+ currentPath.forEach(key => hiddenParents.add(key));
1873
+ }
1874
+ } else if (column.hidden) {
1875
+ parentKeys.forEach(key => hiddenParents.add(key));
1876
+ }
1877
+ }
1878
+ return Array.from(hiddenParents);
1879
+ }
1880
+ function getHiddenParentKeys1(columns, parentKeys = []) {
1881
+ const hiddenParents = new Set();
1882
+ for (const column of columns) {
1883
+ if (column.children) {
1884
+ const currentPath = column.field ? [...parentKeys, column.field] : [...parentKeys];
1885
+ const childHiddenParents = getHiddenParentKeys1(column.children, currentPath);
1886
+ if (childHiddenParents.length > 0) {
1887
+ childHiddenParents.forEach(key => hiddenParents.add(key));
1888
+ currentPath.forEach(key => hiddenParents.add(key));
1889
+ }
1890
+ } else if (column.visible !== false && column.hidden !== true) {
1891
+ parentKeys.forEach(key => hiddenParents.add(key));
1892
+ }
1893
+ }
1894
+ return Array.from(hiddenParents);
1895
+ }
1896
+ const getVisibleColumnKeys = columns => {
1897
+ const allKeys = getAllVisibleKeys(columns);
1898
+ const allParentKeys = getHiddenParentKeys(columns);
1899
+ return allKeys.filter(item => !allParentKeys.includes(item));
1900
+ };
1901
+ exports.getVisibleColumnKeys = getVisibleColumnKeys;
1902
+ const getVisibleColumnKeys1 = columns => {
1903
+ const allKeys = getAllVisibleKeys1(columns);
1904
+ const allParentKeys = getHiddenParentKeys1(columns);
1905
+ return allKeys.filter(item => !allParentKeys.includes(item));
1906
+ };
1907
+ exports.getVisibleColumnKeys1 = getVisibleColumnKeys1;
1908
+ function isObjEqual(obj1, obj2) {
1909
+ // Trường hợp tham chiếu bằng nhau
1910
+ if (obj1 === obj2) return true;
1911
+
1912
+ // Nếu 1 trong 2 không phải object hoặc null thì so sánh trực tiếp
1913
+ if (typeof obj1 !== 'object' || obj1 === null || typeof obj2 !== 'object' || obj2 === null) {
1914
+ return obj1 === obj2;
1915
+ }
1916
+
1917
+ // Lấy danh sách key
1918
+ const keys1 = Object.keys(obj1);
1919
+ const keys2 = Object.keys(obj2);
1920
+
1921
+ // Nếu số key khác nhau thì khác nhau
1922
+ if (keys1.length !== keys2.length) return false;
1923
+
1924
+ // Duyệt và so sánh từng key
1925
+ for (const key of keys1) {
1926
+ if (!keys2.includes(key)) return false;
1927
+ if (!isObjEqual(obj1[key], obj2[key])) return false;
1928
+ }
1929
+ return true;
1930
+ }
1931
+
1932
+ // Sorting function
1933
+ const sortByType = arr => {
1934
+ if (arr) {
1935
+ return arr.sort((a, b) => {
1936
+ if ((a.fixed ?? a.fixedType) === 'left' && (b.fixed ?? b.fixedType) !== 'left') {
1937
+ return -1;
1938
+ } else if ((a.fixed ?? a.fixedType) !== 'left' && (b.fixed ?? b.fixedType) === 'left') {
1939
+ return 1;
1940
+ } else if ((a.fixed ?? a.fixedType) === 'right' && (b.fixed ?? b.fixedType) !== 'right') {
1941
+ return 1;
1942
+ } else if ((a.fixed ?? a.fixedType) !== 'right' && (b.fixed ?? b.fixedType) === 'right') {
1943
+ return -1;
1944
+ }
1945
+ return 0;
1946
+ });
1947
+ } else {
1948
+ return [];
1949
+ }
1950
+ };
1951
+ exports.sortByType = sortByType;
1952
+ function convertColumnsToTreeData(columns, groupColumns) {
1953
+ // return columns.map((col) => {
1954
+ // const node: TreeDataNode = {
1955
+ // key: String(col.id ?? col.id ?? col.header), // key duy nhất
1956
+ // title: String(col.header ?? col.id ?? ''), // tiêu đề
1957
+ // }
1958
+
1959
+ // // Nếu có children (nested columns)
1960
+ // if ('columns' in col && Array.isArray((col as any).columns)) {
1961
+ // node.children = convertColumnsToTreeData(
1962
+ // (col as any).columns as ColumnDef<T, any>[]
1963
+ // )
1964
+ // }
1965
+
1966
+ // return node
1967
+ // })
1968
+
1969
+ return columns.filter(col => {
1970
+ const meta = col.meta ?? {};
1971
+ const inGroup = groupColumns ? groupColumns.includes(String(col.id ?? col.id)) : false;
1972
+
1973
+ // Điều kiện filter:
1974
+ // - Nếu meta.showInColumnChoose = false => loại bỏ
1975
+ // - Nếu không nằm trong groupColumns và không phải column group => loại bỏ
1976
+ if (meta.showInColumnChoose === false) return false;
1977
+ if (inGroup && !('columns' in col && Array.isArray(col.columns))) {
1978
+ return false;
1979
+ }
1980
+ return true;
1981
+ }).map(col => {
1982
+ const node = {
1983
+ key: String(col.id ?? col.id ?? col.header),
1984
+ // title: () => col.header as any
1985
+ title: col.header
1986
+
1987
+ // title: String(col.header ?? col.id ?? ''),
1988
+ };
1989
+ if ('columns' in col && Array.isArray(col.columns)) {
1990
+ const children = convertColumnsToTreeData(col.columns, groupColumns);
1991
+ if (children.length > 0) {
1992
+ node.children = children;
1993
+ }
1994
+ }
1995
+ return node;
1996
+ });
1997
+ }
1998
+ const updateColumns1 = (columns, includes) => {
1999
+ return columns.map(column => {
2000
+ const newColumn = {
2001
+ ...column
2002
+ };
2003
+ let hasVisibleChild = false;
2004
+ if (!column.field) {
2005
+ return column;
2006
+ }
2007
+ if (newColumn.children) {
2008
+ newColumn.children = updateColumns1(newColumn.children, includes);
2009
+ hasVisibleChild = newColumn.children.some(child => !child.hidden);
2010
+ }
2011
+ newColumn.visible = !!(newColumn.field && includes.includes(newColumn.field));
2012
+ if (newColumn.children && newColumn.children.length > 0) {
2013
+ newColumn.visible = !hasVisibleChild;
2014
+ }
2015
+ return newColumn;
2016
+ });
2017
+ };
2018
+ exports.updateColumns1 = updateColumns1;
2019
+ const convertToObj = arr => {
2020
+ // const result = Object.keys(obj).reduce((acc: any, key) => {
2021
+ // acc[key] = false;
2022
+ // return acc;
2023
+ // }, {});
2024
+
2025
+ // return result
2026
+
2027
+ return Object.fromEntries(arr.map(key => [key, false]));
2028
+ };
2029
+ exports.convertToObj = convertToObj;
2030
+ const convertToObjTrue = arr => {
2031
+ // const result = Object.keys(obj).reduce((acc: any, key) => {
2032
+ // acc[key] = false;
2033
+ // return acc;
2034
+ // }, {});
2035
+
2036
+ // return result
2037
+
2038
+ return Object.fromEntries(arr.map(key => [key, true]));
2039
+ };
2040
+ exports.convertToObjTrue = convertToObjTrue;
2041
+ const getDiffent2Array = (a, b) => {
2042
+ return [...a.filter(x => !b.includes(x)), ...b.filter(x => !a.includes(x))];
2043
+ };
2044
+ exports.getDiffent2Array = getDiffent2Array;
2045
+ function findFirst(items) {
2046
+ const leftItem = items.find(item => item.getIsPinned() === 'left');
2047
+ if (leftItem) return leftItem;
2048
+ return null;
2049
+ }
2050
+ function isTreeArray(arr) {
2051
+ if (!Array.isArray(arr) || arr.length === 0) {
2052
+ return false;
2053
+ }
2054
+ for (const item of arr) {
2055
+ if (!item) {
2056
+ return false;
2057
+ }
2058
+ if (item.children?.length > 0) {
2059
+ return true;
2060
+ }
2061
+ }
2062
+ return false;
2063
+ }
2064
+ function updateColumnWidthsRecursive(columns, sizing) {
2065
+ return columns.map(col => {
2066
+ const updated = {
2067
+ ...col
2068
+ };
2069
+
2070
+ // cập nhật width nếu có trong sizing
2071
+ if (sizing[col.field] !== undefined) {
2072
+ updated.width = sizing[col.field];
2073
+ }
2074
+
2075
+ // nếu có children thì gọi đệ quy
2076
+ if (col.children && col.children.length > 0) {
2077
+ updated.children = updateColumnWidthsRecursive(col.children, sizing);
2078
+ }
2079
+ return updated;
2080
+ });
2081
+ }
2082
+ function updateWidthsByOther(source, target) {
2083
+ const targetMap = new Map();
2084
+
2085
+ // tạo map {field -> width} từ target
2086
+ const buildMap = cols => {
2087
+ cols.forEach(col => {
2088
+ if (col.width !== undefined) {
2089
+ targetMap.set(col.field, col.width);
2090
+ }
2091
+ if (col.children) {
2092
+ buildMap(col.children);
2093
+ }
2094
+ });
2095
+ };
2096
+ buildMap(target);
2097
+
2098
+ // cập nhật width từ map
2099
+ const update = cols => cols.map(col => {
2100
+ const updated = {
2101
+ ...col
2102
+ };
2103
+ if (targetMap.has(col.field)) {
2104
+ updated.width = targetMap.get(col.field);
2105
+ }
2106
+ if (col.children) {
2107
+ updated.children = update(col.children);
2108
+ }
2109
+ return updated;
2110
+ });
2111
+ return update(source);
2112
+ }
2113
+ function findAllChildrenKeys2(data, rowKey, childrenColumnName) {
2114
+ const keys = [];
2115
+ function dig(list) {
2116
+ (list || []).forEach(item => {
2117
+ keys.push(item[rowKey]);
2118
+ dig(item[childrenColumnName]);
2119
+ });
2120
+ }
2121
+ dig(data);
2122
+ return keys;
2123
+ }
2124
+ function parseExcelText(text) {
2125
+ // const text = e.clipboardData?.getData('text/plain') ?? '';
2126
+ if (!text) return [];
2127
+
2128
+ // Excel thường dùng \r\n giữa dòng, \t giữa cột
2129
+ const rows = text.split(/\r?\n/) // tách theo dòng
2130
+ .filter(r => r.trim() !== '') // bỏ dòng trống
2131
+ .map(row => row.split('\t') // tách theo cột
2132
+ .map(cell => cell.replace(/\r/g, '').replace(/\n/g, '\n')) // giữ xuống dòng trong ô
2133
+ );
2134
+ return rows;
2135
+ }
2136
+ function parseExcelClipboard(e) {
2137
+ const text = e.clipboardData?.getData('text/plain') ?? '';
2138
+ if (!text) return [];
2139
+
2140
+ // Excel thường dùng \r\n giữa dòng, \t giữa cột
2141
+ const rows = text.split(/\r?\n/) // tách theo dòng
2142
+ .filter(r => r.trim() !== '') // bỏ dòng trống
2143
+ .map(row => row.split('\t') // tách theo cột
2144
+ .map(cell => cell.replace(/\r/g, '').replace(/\n/g, '\n')) // giữ xuống dòng trong ô
2145
+ );
2146
+ return rows;
2147
+ }
2148
+ function parseExcelClipboardText(text) {
2149
+ const rows = [];
2150
+ let curRow = [];
2151
+ let curCell = '';
2152
+ let inQuotes = false;
2153
+ for (let i = 0; i < text.length; i++) {
2154
+ const ch = text[i];
2155
+ if (ch === '"') {
2156
+ // "" -> an escaped quote inside quoted field
2157
+ if (inQuotes && text[i + 1] === '"') {
2158
+ curCell += '"';
2159
+ i++; // skip next
2160
+ } else {
2161
+ inQuotes = !inQuotes; // open/close quote
2162
+ }
2163
+ continue;
2164
+ }
2165
+
2166
+ // tab as column separator (only if not inside quotes)
2167
+ if (ch === '\t' && !inQuotes) {
2168
+ curRow.push(curCell);
2169
+ curCell = '';
2170
+ continue;
2171
+ }
2172
+
2173
+ // newline as row separator (handle \r\n and lone \r or \n), only outside quotes
2174
+ if ((ch === '\r' || ch === '\n') && !inQuotes) {
2175
+ // handle CRLF
2176
+ if (ch === '\r' && text[i + 1] === '\n') i++;
2177
+ curRow.push(curCell);
2178
+ curCell = '';
2179
+ rows.push(curRow);
2180
+ curRow = [];
2181
+ continue;
2182
+ }
2183
+
2184
+ // normal character
2185
+ curCell += ch;
2186
+ }
2187
+
2188
+ // push last cell/row (if any)
2189
+ // avoid adding one spurious empty row when text ends with newline (we already pushed that row)
2190
+ if (curCell !== '' || curRow.length > 0) {
2191
+ curRow.push(curCell);
2192
+ rows.push(curRow);
2193
+ }
2194
+
2195
+ // if the whole input was empty, return []
2196
+ if (rows.length === 1 && rows[0].length === 1 && rows[0][0] === '' && text.trim() === '') {
2197
+ return [];
2198
+ }
2199
+ return rows;
2200
+ }
2201
+ function parseClipboardEvent(e) {
2202
+ const dataTransfer = e.clipboardData ?? e.nativeEvent?.clipboardData;
2203
+ if (!dataTransfer) return [];
2204
+
2205
+ // 1) try HTML (better fidelity for Excel)
2206
+ const html = dataTransfer.getData?.('text/html');
2207
+ if (html) {
2208
+ try {
2209
+ const doc = new DOMParser().parseFromString(html, 'text/html');
2210
+ const table = doc.querySelector('table');
2211
+ if (table) {
2212
+ const result = [];
2213
+ for (const tr of Array.from(table.rows)) {
2214
+ const row = [];
2215
+ for (const cell of Array.from(tr.cells)) {
2216
+ // innerText preserves newlines from <br>
2217
+ row.push(cell.innerText ?? '');
2218
+ }
2219
+ result.push(row);
2220
+ }
2221
+ if (result.length) return result;
2222
+ }
2223
+ } catch {
2224
+ // fallback to text parsing
2225
+ }
2226
+ }
2227
+
2228
+ // 2) fallback: parse plain text (TSV with quoted fields)
2229
+ const text = dataTransfer.getData?.('text/plain') ?? '';
2230
+ return parseExcelClipboardText(text);
2231
+ }
2232
+ function arraysEqualIgnoreOrderFast(a, b) {
2233
+ if (a.length !== b.length) return false;
2234
+ const count = Object.create(null);
2235
+ for (let i = 0; i < a.length; i++) {
2236
+ const key = a[i];
2237
+ count[key] = (count[key] || 0) + 1;
2238
+ }
2239
+ for (let i = 0; i < b.length; i++) {
2240
+ const key = b[i];
2241
+ if (!count[key]) return false;
2242
+ count[key]--;
2243
+ if (count[key] === 0) delete count[key];
2244
+ }
2245
+ return Object.keys(count).length === 0;
2246
+ }
2247
+ function filterByIds(a, b) {
2248
+ const idSet = new Set(a);
2249
+ return b.filter(item => idSet.has(item.id));
2250
+ }
2251
+ function excludeItems(arrayA, arrayB) {
2252
+ const idsInB = new Set(arrayB.map(item => item.id));
2253
+
2254
+ // Lọc A, chỉ giữ lại phần tử không có trong B
2255
+ return arrayA.filter(item => !idsInB.has(item.id));
2256
+ }
2257
+ function getAllChildren(row) {
2258
+ const children = row.subRows ?? [];
2259
+ return children.reduce((acc, child) => {
2260
+ return acc.concat(child, getAllChildren(child));
2261
+ }, []);
2262
+ }
2263
+
2264
+ // export function toggleSelectAllChildren(row: any) {
2265
+ // const children = row.subRows ?? [];
2266
+
2267
+ // return children.reduce((acc: any, child: any) => {
2268
+ // return acc.concat(child, getAllChildren(child));
2269
+ // }, []);
2270
+ // }
2271
+
2272
+ function toggleRowAndChildren(row, isSelected) {
2273
+ // Toggle chính row hiện tại
2274
+ row.toggleSelected(isSelected);
2275
+
2276
+ // Nếu có subRows thì gọi đệ quy
2277
+ if (row.subRows && row.subRows.length > 0) {
2278
+ row.subRows.forEach(subRow => toggleRowAndChildren(subRow, isSelected));
2279
+ }
2280
+ }
2281
+ function countUnselectedChildren(row) {
2282
+ const parent = row.getParentRow();
2283
+ if (!parent) return 0; // Không có cha thì return 0
2284
+
2285
+ const unselectedCount = parent.subRows.filter(child => !child.getIsSelected()).length;
2286
+ return unselectedCount;
2287
+ }
2288
+ function removeDuplicatesByKey(arr, key = 'id') {
2289
+ const map = new Map();
2290
+ for (const item of arr) {
2291
+ if (!map.has(item[key])) {
2292
+ map.set(item[key], item);
2293
+ }
2294
+ }
2295
+ return Array.from(map.values());
2296
+ }
2297
+ const getTableHeight = (height, minHeight) => {
2298
+ if (height && !minHeight) {
2299
+ return height;
2300
+ }
2301
+ if (minHeight && !height) {
2302
+ return minHeight;
2303
+ }
2304
+ if (minHeight && height) {
2305
+ return Math.max(minHeight, height);
2306
+ // if (height > minHeight) {
2307
+ // return height
2308
+ // }
2309
+
2310
+ // if (minHeight > height) {
2311
+ // return minHeight
2312
+ // }
2313
+ }
2314
+ };
2315
+ exports.getTableHeight = getTableHeight;
2316
+ const convertFlatColumn1 = array => {
2317
+ const tmp = [...array];
2318
+ let result = [];
2319
+ tmp.forEach(item => {
2320
+ if (item.children) {
2321
+ result = result.concat(convertFlatColumn1(item.children));
2322
+ } else {
2323
+ result.push(item);
2324
+ }
2325
+ });
2326
+ return result;
2327
+ };
2328
+
2329
+ // export const updateColumnsByGroup = (columns: ColumnsTable, columnsGroup: string[]) => {
2330
+ // return columns.map(column => {
2331
+ // const newColumn = { ...column }
2332
+ // let hasVisibleChild = false
2333
+ // if (column.field) {
2334
+ // return column
2335
+ // }
2336
+
2337
+ // if (newColumn.children) {
2338
+ // newColumn.children = updateColumnsByGroup(newColumn.children, columnsGroup)
2339
+
2340
+ // hasVisibleChild = newColumn.children.some((child: any) => !!child.visible)
2341
+ // }
2342
+
2343
+ // newColumn.visible = !(newColumn.field && columnsGroup.includes(newColumn.field))
2344
+
2345
+ // if (newColumn.children && newColumn.children.length > 0) {
2346
+ // newColumn.visible = !!hasVisibleChild
2347
+ // }
2348
+
2349
+ // return newColumn
2350
+ // })
2351
+ // }
2352
+ exports.convertFlatColumn1 = convertFlatColumn1;
2353
+ const updateColumnsByGroup = (columns, columnsGroup) => {
2354
+ return columns.map(column => {
2355
+ const newColumn = {
2356
+ ...column
2357
+ };
2358
+ let hasVisibleChild = false;
2359
+ if (!column.field) {
2360
+ return column;
2361
+ }
2362
+ if (newColumn.children) {
2363
+ newColumn.children = updateColumnsByGroup(newColumn.children, columnsGroup);
2364
+ hasVisibleChild = newColumn.children.some(child => child.visible !== false);
2365
+ }
2366
+
2367
+ // Map previous behaviour (hidden = true when field in columnsGroup)
2368
+ // to the new `visible` property: visible = !hidden
2369
+ if (newColumn.field && columnsGroup.includes(newColumn.field)) {
2370
+ newColumn.visible = !(newColumn.field && columnsGroup.includes(newColumn.field));
2371
+ }
2372
+
2373
+ // For parent columns, visibility depends on whether any child is visible
2374
+ if (newColumn.children && newColumn.children.length > 0) {
2375
+ newColumn.visible = !!hasVisibleChild;
2376
+ }
2377
+ return newColumn;
2378
+ });
2379
+ };
2380
+ exports.updateColumnsByGroup = updateColumnsByGroup;
2381
+ function removeKeys(obj, keys) {
2382
+ const newObj = {
2383
+ ...obj
2384
+ };
2385
+ keys.forEach(key => {
2386
+ delete newObj[key];
2387
+ });
2388
+ return newObj;
2389
+ }