es-grid-template 1.8.70 → 1.8.72

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 (239) hide show
  1. package/es/grid-component/TempTable.js +2 -1
  2. package/es/group-component/ColumnsChoose.d.ts +13 -0
  3. package/es/group-component/ColumnsChoose.js +211 -0
  4. package/es/group-component/ColumnsGroup/ColumnsGroup.d.ts +12 -0
  5. package/es/group-component/ColumnsGroup/ColumnsGroup.js +230 -0
  6. package/es/group-component/ColumnsGroup/index.d.ts +1 -0
  7. package/es/group-component/ColumnsGroup/index.js +1 -0
  8. package/es/group-component/ContextMenu.d.ts +19 -0
  9. package/es/group-component/ContextMenu.js +74 -0
  10. package/es/group-component/InternalTable.d.ts +8 -0
  11. package/es/group-component/InternalTable.js +224 -0
  12. package/es/group-component/TableContainer.d.ts +49 -0
  13. package/es/group-component/TableContainer.js +375 -0
  14. package/es/group-component/TableContainerEdit.d.ts +48 -0
  15. package/es/group-component/TableContainerEdit.js +2068 -0
  16. package/es/group-component/body/EditableCell.d.ts +16 -0
  17. package/es/group-component/body/EditableCell.js +1066 -0
  18. package/es/group-component/body/TableBody.d.ts +14 -0
  19. package/es/group-component/body/TableBody.js +82 -0
  20. package/es/group-component/body/TableBodyCell.d.ts +12 -0
  21. package/es/group-component/body/TableBodyCell.js +587 -0
  22. package/es/group-component/body/TableBodyCellEdit.d.ts +17 -0
  23. package/es/group-component/body/TableBodyCellEdit.js +1398 -0
  24. package/es/group-component/body/TableBodyCellEmpty.d.ts +12 -0
  25. package/es/group-component/body/TableBodyCellEmpty.js +149 -0
  26. package/es/group-component/body/TableBodyRow.d.ts +21 -0
  27. package/es/group-component/body/TableBodyRow.js +199 -0
  28. package/es/group-component/body/TableBodyRowGroupCell.d.ts +12 -0
  29. package/es/group-component/body/TableBodyRowGroupCell.js +567 -0
  30. package/es/group-component/components/ControlCheckbox.d.ts +13 -0
  31. package/es/group-component/components/ControlCheckbox.js +84 -0
  32. package/es/group-component/components/EditForm/EditForm.d.ts +27 -0
  33. package/es/group-component/components/EditForm/EditForm.js +394 -0
  34. package/es/group-component/components/EditForm/index.d.ts +1 -0
  35. package/es/group-component/components/EditForm/index.js +1 -0
  36. package/es/group-component/components/InputControl/InputControl.d.ts +27 -0
  37. package/es/group-component/components/InputControl/InputControl.js +118 -0
  38. package/es/group-component/components/InputControl/index.d.ts +1 -0
  39. package/es/group-component/components/InputControl/index.js +1 -0
  40. package/es/group-component/components/async-select/index.d.ts +11 -0
  41. package/es/group-component/components/async-select/index.js +38 -0
  42. package/es/group-component/components/async-table-select/index.d.ts +11 -0
  43. package/es/group-component/components/async-table-select/index.js +40 -0
  44. package/es/group-component/components/checkbox-control/index.d.ts +13 -0
  45. package/es/group-component/components/checkbox-control/index.js +40 -0
  46. package/es/group-component/components/checkbox-filter/CheckboxFilter.d.ts +18 -0
  47. package/es/group-component/components/checkbox-filter/CheckboxFilter.js +258 -0
  48. package/es/group-component/components/checkbox-filter/FilterSearch.d.ts +12 -0
  49. package/es/group-component/components/checkbox-filter/FilterSearch.js +36 -0
  50. package/es/group-component/components/command/Command.d.ts +10 -0
  51. package/es/group-component/components/command/Command.js +35 -0
  52. package/es/group-component/components/number/index.d.ts +12 -0
  53. package/es/group-component/components/number/index.js +42 -0
  54. package/es/group-component/components/number-range/index.d.ts +13 -0
  55. package/es/group-component/components/number-range/index.js +79 -0
  56. package/es/group-component/features/operator.d.ts +24 -0
  57. package/es/group-component/features/operator.js +62 -0
  58. package/es/group-component/footer/TableFooter.d.ts +7 -0
  59. package/es/group-component/footer/TableFooter.js +34 -0
  60. package/es/group-component/footer/TableFooterCell.d.ts +7 -0
  61. package/es/group-component/footer/TableFooterCell.js +66 -0
  62. package/es/group-component/footer/TableFooterRow.d.ts +8 -0
  63. package/es/group-component/footer/TableFooterRow.js +30 -0
  64. package/es/group-component/header/TableHead.d.ts +15 -0
  65. package/es/group-component/header/TableHead.js +98 -0
  66. package/es/group-component/header/TableHeadCell.d.ts +15 -0
  67. package/es/group-component/header/TableHeadCell.js +310 -0
  68. package/es/group-component/header/TableHeadCell2.d.ts +17 -0
  69. package/es/group-component/header/TableHeadCell2.js +321 -0
  70. package/es/group-component/header/TableHeadGroupCell.d.ts +17 -0
  71. package/es/group-component/header/TableHeadGroupCell.js +94 -0
  72. package/es/group-component/header/TableHeadRow.d.ts +15 -0
  73. package/es/group-component/header/TableHeadRow.js +52 -0
  74. package/es/group-component/header/renderFilter.d.ts +20 -0
  75. package/es/group-component/header/renderFilter.js +291 -0
  76. package/es/group-component/hook/convert.d.ts +1 -0
  77. package/es/group-component/hook/convert.js +28 -0
  78. package/es/group-component/hook/useColumns.d.ts +28 -0
  79. package/es/group-component/hook/useColumns.js +306 -0
  80. package/es/group-component/hook/useFilterOperator.d.ts +7 -0
  81. package/es/group-component/hook/useFilterOperator.js +33 -0
  82. package/es/group-component/hook/utils.d.ts +220 -0
  83. package/es/group-component/hook/utils.js +2340 -0
  84. package/es/group-component/index.d.ts +2 -0
  85. package/es/group-component/index.js +2 -0
  86. package/es/group-component/style.d.ts +22 -0
  87. package/es/group-component/style.js +48 -0
  88. package/es/group-component/style.scss +1438 -0
  89. package/es/group-component/table/Grid.d.ts +33 -0
  90. package/es/group-component/table/Grid.js +438 -0
  91. package/es/group-component/table/TableWrapper.d.ts +33 -0
  92. package/es/group-component/table/TableWrapper.js +250 -0
  93. package/es/group-component/useContext.d.ts +100 -0
  94. package/es/group-component/useContext.js +21 -0
  95. package/es/table-component/InternalTable.js +6 -1
  96. package/es/table-component/TableContainer.js +4 -2
  97. package/es/table-component/TableContainerEdit.js +2 -2
  98. package/es/table-component/body/TableBodyCell.js +49 -40
  99. package/es/table-component/body/TableBodyCellEdit.js +9 -3
  100. package/es/table-component/body/TableBodyRow.js +4 -1
  101. package/es/table-component/hook/utils.d.ts +1 -0
  102. package/es/table-component/hook/utils.js +15 -7
  103. package/es/table-component/style.js +1 -1
  104. package/es/table-component/table/Grid.js +3 -0
  105. package/es/table-component/useContext.d.ts +5 -0
  106. package/es/table-virtuoso/InternalTable.js +2 -2
  107. package/es/table-virtuoso/body/TableBodyCell.js +2 -7
  108. package/es/table-virtuoso/body/TableBodyCellRowGroup.d.ts +14 -0
  109. package/es/table-virtuoso/body/TableBodyCellRowGroup.js +196 -0
  110. package/es/table-virtuoso/body/TableBodyRow.d.ts +1 -1
  111. package/es/table-virtuoso/body/TableBodyRow.js +43 -1
  112. package/es/table-virtuoso/hook/utils.d.ts +1 -0
  113. package/es/table-virtuoso/hook/utils.js +29 -0
  114. package/es/table-virtuoso/style.js +3 -1
  115. package/es/table-virtuoso/table/Grid.js +2 -2
  116. package/es/table-virtuoso/table/TableWrapper.d.ts +7 -1
  117. package/es/table-virtuoso/table/TableWrapper.js +24 -5
  118. package/es/table-virtuoso/useContext.d.ts +6 -3
  119. package/es/table-virtuoso/useContext.js +18 -0
  120. package/lib/grid-component/TempTable.js +2 -1
  121. package/lib/group-component/ColumnsChoose.d.ts +13 -0
  122. package/lib/group-component/ColumnsChoose.js +221 -0
  123. package/lib/group-component/ColumnsGroup/ColumnsGroup.d.ts +12 -0
  124. package/lib/group-component/ColumnsGroup/ColumnsGroup.js +241 -0
  125. package/lib/group-component/ColumnsGroup/index.d.ts +1 -0
  126. package/lib/group-component/ColumnsGroup/index.js +16 -0
  127. package/lib/group-component/ContextMenu.d.ts +19 -0
  128. package/lib/group-component/ContextMenu.js +83 -0
  129. package/lib/group-component/InternalTable.d.ts +8 -0
  130. package/lib/group-component/InternalTable.js +233 -0
  131. package/lib/group-component/TableContainer.d.ts +49 -0
  132. package/lib/group-component/TableContainer.js +382 -0
  133. package/lib/group-component/TableContainerEdit.d.ts +48 -0
  134. package/lib/group-component/TableContainerEdit.js +2075 -0
  135. package/lib/group-component/body/EditableCell.d.ts +16 -0
  136. package/lib/group-component/body/EditableCell.js +1075 -0
  137. package/lib/group-component/body/TableBody.d.ts +14 -0
  138. package/lib/group-component/body/TableBody.js +91 -0
  139. package/lib/group-component/body/TableBodyCell.d.ts +12 -0
  140. package/lib/group-component/body/TableBodyCell.js +595 -0
  141. package/lib/group-component/body/TableBodyCellEdit.d.ts +17 -0
  142. package/lib/group-component/body/TableBodyCellEdit.js +1405 -0
  143. package/lib/group-component/body/TableBodyCellEmpty.d.ts +12 -0
  144. package/lib/group-component/body/TableBodyCellEmpty.js +156 -0
  145. package/lib/group-component/body/TableBodyRow.d.ts +21 -0
  146. package/lib/group-component/body/TableBodyRow.js +206 -0
  147. package/lib/group-component/body/TableBodyRowGroupCell.d.ts +12 -0
  148. package/lib/group-component/body/TableBodyRowGroupCell.js +575 -0
  149. package/lib/group-component/components/ControlCheckbox.d.ts +13 -0
  150. package/lib/group-component/components/ControlCheckbox.js +92 -0
  151. package/lib/group-component/components/EditForm/EditForm.d.ts +27 -0
  152. package/lib/group-component/components/EditForm/EditForm.js +404 -0
  153. package/lib/group-component/components/EditForm/index.d.ts +1 -0
  154. package/lib/group-component/components/EditForm/index.js +16 -0
  155. package/lib/group-component/components/InputControl/InputControl.d.ts +27 -0
  156. package/lib/group-component/components/InputControl/InputControl.js +127 -0
  157. package/lib/group-component/components/InputControl/index.d.ts +1 -0
  158. package/lib/group-component/components/InputControl/index.js +16 -0
  159. package/lib/group-component/components/async-select/index.d.ts +11 -0
  160. package/lib/group-component/components/async-select/index.js +47 -0
  161. package/lib/group-component/components/async-table-select/index.d.ts +11 -0
  162. package/lib/group-component/components/async-table-select/index.js +49 -0
  163. package/lib/group-component/components/checkbox-control/index.d.ts +13 -0
  164. package/lib/group-component/components/checkbox-control/index.js +48 -0
  165. package/lib/group-component/components/checkbox-filter/CheckboxFilter.d.ts +18 -0
  166. package/lib/group-component/components/checkbox-filter/CheckboxFilter.js +267 -0
  167. package/lib/group-component/components/checkbox-filter/FilterSearch.d.ts +12 -0
  168. package/lib/group-component/components/checkbox-filter/FilterSearch.js +44 -0
  169. package/lib/group-component/components/command/Command.d.ts +10 -0
  170. package/lib/group-component/components/command/Command.js +44 -0
  171. package/lib/group-component/components/number/index.d.ts +12 -0
  172. package/lib/group-component/components/number/index.js +50 -0
  173. package/lib/group-component/components/number-range/index.d.ts +13 -0
  174. package/lib/group-component/components/number-range/index.js +87 -0
  175. package/lib/group-component/features/operator.d.ts +24 -0
  176. package/lib/group-component/features/operator.js +67 -0
  177. package/lib/group-component/footer/TableFooter.d.ts +7 -0
  178. package/lib/group-component/footer/TableFooter.js +44 -0
  179. package/lib/group-component/footer/TableFooterCell.d.ts +7 -0
  180. package/lib/group-component/footer/TableFooterCell.js +75 -0
  181. package/lib/group-component/footer/TableFooterRow.d.ts +8 -0
  182. package/lib/group-component/footer/TableFooterRow.js +37 -0
  183. package/lib/group-component/header/TableHead.d.ts +15 -0
  184. package/lib/group-component/header/TableHead.js +107 -0
  185. package/lib/group-component/header/TableHeadCell.d.ts +15 -0
  186. package/lib/group-component/header/TableHeadCell.js +319 -0
  187. package/lib/group-component/header/TableHeadCell2.d.ts +17 -0
  188. package/lib/group-component/header/TableHeadCell2.js +330 -0
  189. package/lib/group-component/header/TableHeadGroupCell.d.ts +17 -0
  190. package/lib/group-component/header/TableHeadGroupCell.js +103 -0
  191. package/lib/group-component/header/TableHeadRow.d.ts +15 -0
  192. package/lib/group-component/header/TableHeadRow.js +59 -0
  193. package/lib/group-component/header/renderFilter.d.ts +20 -0
  194. package/lib/group-component/header/renderFilter.js +301 -0
  195. package/lib/group-component/hook/convert.d.ts +1 -0
  196. package/lib/group-component/hook/convert.js +34 -0
  197. package/lib/group-component/hook/useColumns.d.ts +28 -0
  198. package/lib/group-component/hook/useColumns.js +318 -0
  199. package/lib/group-component/hook/useFilterOperator.d.ts +7 -0
  200. package/lib/group-component/hook/useFilterOperator.js +40 -0
  201. package/lib/group-component/hook/utils.d.ts +220 -0
  202. package/lib/group-component/hook/utils.js +2468 -0
  203. package/lib/group-component/index.d.ts +2 -0
  204. package/lib/group-component/index.js +9 -0
  205. package/lib/group-component/style.d.ts +22 -0
  206. package/lib/group-component/style.js +55 -0
  207. package/lib/group-component/style.scss +1438 -0
  208. package/lib/group-component/table/Grid.d.ts +33 -0
  209. package/lib/group-component/table/Grid.js +443 -0
  210. package/lib/group-component/table/TableWrapper.d.ts +33 -0
  211. package/lib/group-component/table/TableWrapper.js +259 -0
  212. package/lib/group-component/useContext.d.ts +100 -0
  213. package/lib/group-component/useContext.js +27 -0
  214. package/lib/table-component/InternalTable.js +6 -1
  215. package/lib/table-component/TableContainer.js +4 -2
  216. package/lib/table-component/TableContainerEdit.js +2 -2
  217. package/lib/table-component/body/TableBodyCell.js +49 -40
  218. package/lib/table-component/body/TableBodyCellEdit.js +9 -3
  219. package/lib/table-component/body/TableBodyRow.js +4 -1
  220. package/lib/table-component/hook/utils.d.ts +1 -0
  221. package/lib/table-component/hook/utils.js +16 -7
  222. package/lib/table-component/style.js +1 -1
  223. package/lib/table-component/table/Grid.js +3 -0
  224. package/lib/table-component/useContext.d.ts +5 -0
  225. package/lib/table-virtuoso/InternalTable.js +2 -2
  226. package/lib/table-virtuoso/body/TableBodyCell.js +2 -7
  227. package/lib/table-virtuoso/body/TableBodyCellRowGroup.d.ts +14 -0
  228. package/lib/table-virtuoso/body/TableBodyCellRowGroup.js +203 -0
  229. package/lib/table-virtuoso/body/TableBodyRow.d.ts +1 -1
  230. package/lib/table-virtuoso/body/TableBodyRow.js +43 -1
  231. package/lib/table-virtuoso/hook/utils.d.ts +1 -0
  232. package/lib/table-virtuoso/hook/utils.js +32 -1
  233. package/lib/table-virtuoso/style.js +3 -1
  234. package/lib/table-virtuoso/table/Grid.js +2 -2
  235. package/lib/table-virtuoso/table/TableWrapper.d.ts +7 -1
  236. package/lib/table-virtuoso/table/TableWrapper.js +24 -5
  237. package/lib/table-virtuoso/useContext.d.ts +6 -3
  238. package/lib/table-virtuoso/useContext.js +18 -0
  239. package/package.json +1 -1
@@ -0,0 +1,2075 @@
1
+ "use strict";
2
+
3
+ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
4
+ Object.defineProperty(exports, "__esModule", {
5
+ value: true
6
+ });
7
+ exports.default = void 0;
8
+ var _extends2 = _interopRequireDefault(require("@babel/runtime/helpers/extends"));
9
+ var _react = _interopRequireWildcard(require("react"));
10
+ var _usehooksTs = require("usehooks-ts");
11
+ var _utils = require("./hook/utils");
12
+ var _reactVirtual = require("@tanstack/react-virtual");
13
+ var _reactHookForm = require("react-hook-form");
14
+ var _antd = require("antd");
15
+ var _pagination = _interopRequireDefault(require("rc-master-ui/es/pagination"));
16
+ var _reactNumericComponent = require("react-numeric-component");
17
+ var _useContext = require("./useContext");
18
+ var _yup = require("@hookform/resolvers/yup");
19
+ var _rcMasterUi = require("rc-master-ui");
20
+ var _classnames = _interopRequireDefault(require("classnames"));
21
+ var _becoxyIcons = require("becoxy-icons");
22
+ var _ColumnsChoose = require("./ColumnsChoose");
23
+ var _TableWrapper = _interopRequireDefault(require("./table/TableWrapper"));
24
+ var _sweetalert2ReactContent = _interopRequireDefault(require("sweetalert2-react-content"));
25
+ var _sweetalert = _interopRequireDefault(require("sweetalert2"));
26
+ var _utils2 = require("../table-component/hook/utils");
27
+ var _ColumnsGroup = require("./ColumnsGroup");
28
+ var _utils3 = require("../table-virtuoso/hook/utils");
29
+ function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return null; var r = new WeakMap(), t = new WeakMap(); return (_getRequireWildcardCache = function (e) { return e ? t : r; })(e); }
30
+ function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" != typeof e && "function" != typeof e) return { default: e }; var t = _getRequireWildcardCache(r); if (t && t.has(e)) return t.get(e); var n = { __proto__: null }, a = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var u in e) if ("default" !== u && Object.prototype.hasOwnProperty.call(e, u)) { var i = a ? Object.getOwnPropertyDescriptor(e, u) : null; i && (i.get || i.set) ? Object.defineProperty(n, u, i) : n[u] = e[u]; } return n.default = e, t && t.set(e, n), n; }
31
+ const MySwal = (0, _sweetalert2ReactContent.default)(_sweetalert.default);
32
+ const {
33
+ Paragraph,
34
+ Title
35
+ } = _antd.Typography;
36
+ const validateData = async (data, formSchema) => {
37
+ if (!formSchema) {
38
+ return [];
39
+ } else {
40
+ const errors = [];
41
+ for (let i = 0; i < data.length; i++) {
42
+ try {
43
+ await formSchema.validate(data[i], {
44
+ abortEarly: false
45
+ });
46
+ } catch (error) {
47
+ errors.push(error.inner.reduce((acc, err) => {
48
+ acc[err.path] = {
49
+ field: err.path,
50
+ index: i,
51
+ message: err.message,
52
+ type: err.type,
53
+ ref: {
54
+ name: err.path
55
+ }
56
+ };
57
+ return {
58
+ ...acc,
59
+ index: i,
60
+ id: data[i].rowId
61
+ };
62
+ }, {}));
63
+ }
64
+ }
65
+ return errors;
66
+ }
67
+ };
68
+ const TableContainerEdit = props => {
69
+ const {
70
+ t,
71
+ table,
72
+ title,
73
+ id,
74
+ prefix,
75
+ commandClick,
76
+ editAble,
77
+ rowEditable,
78
+ rowKey,
79
+ format,
80
+ dataSource,
81
+ originData,
82
+ expandable,
83
+ wrapSettings,
84
+ recordDoubleClick,
85
+ // triggerFilter,
86
+ selectionSettings,
87
+ isSelectionChange,
88
+ setIsSelectionChange,
89
+ // onContextMenu,
90
+ contextMenuItems,
91
+ setSorterChange,
92
+ setFilterChange,
93
+ onCellPaste,
94
+ // triggerPaste,
95
+ validate,
96
+ // triggerChangeData,
97
+ onCellChange,
98
+ onDataChange,
99
+ defaultValue,
100
+ toolbarItems,
101
+ mergedFilterKeys,
102
+ setMergedFilterKeys,
103
+ expanded,
104
+ setExpanded,
105
+ onBlur,
106
+ fullScreen,
107
+ pagination,
108
+ showToolbar,
109
+ actionTemplate,
110
+ showColumnChoose,
111
+ height,
112
+ minHeight,
113
+ summary,
114
+ locale,
115
+ groupColumns,
116
+ groupSetting,
117
+ columns,
118
+ propsColumns,
119
+ triggerChangeColumns,
120
+ columnHidden,
121
+ showEmptyText,
122
+ isFullScreen,
123
+ setIsFullScreen,
124
+ infiniteScroll,
125
+ windowSize,
126
+ next,
127
+ loading,
128
+ contextMenuOpen,
129
+ contextMenuClick,
130
+ contextMenuHidden,
131
+ commandSettings,
132
+ isDataTree,
133
+ onCellClick,
134
+ // setColumnSizing,
135
+ setColumns,
136
+ columnSizing,
137
+ columnSizingInfo,
138
+ rowClassName,
139
+ onRowStyles,
140
+ dataSourceFilter,
141
+ triggerGroupColumns
142
+ } = props;
143
+ const containerRef = _react.default.useRef(null);
144
+ const bottomToolbarRef = _react.default.useRef(null);
145
+ const topToolbarRef = _react.default.useRef(null);
146
+ const childrenColumnName = 'children';
147
+
148
+ // const visibleColumns = table.getVisibleLeafColumns()
149
+
150
+ // //The virtualizers need to know the scrollable container element
151
+ const tableContainerRef = _react.default.useRef(null);
152
+ const [, copy] = (0, _usehooksTs.useCopyToClipboard)();
153
+
154
+ // const columnSizingState = table.getState().columnSizing;
155
+
156
+ const itemsAdd = _react.default.useMemo(() => {
157
+ return [{
158
+ key: '10',
159
+ label: `10 ${t ? t('rows') : 'rows'}`
160
+ }, {
161
+ key: '50',
162
+ label: `50 ${t ? t('rows') : 'rows'}`
163
+ }, {
164
+ key: '100',
165
+ label: `100 ${t ? t('rows') : 'rows'}`
166
+ }];
167
+ }, [t]);
168
+ const [dataErrors, setDataErrors] = _react.default.useState([]);
169
+ _react.default.useEffect(() => {
170
+ if (validate && dataSource && dataSource.length) {
171
+ validateData(dataSource, validate).then(error => {
172
+ setDataErrors([...error]);
173
+ // if (getErrors) {
174
+ // getErrors([...error])
175
+ // }
176
+ });
177
+ }
178
+ }, [validate, dataSource]);
179
+ const visibleColumns = table.getVisibleLeafColumns();
180
+ // const visibleColumns = table.getVisibleFlatColumns();
181
+
182
+ const fixedLeftColumns = table.getState().columnPinning.left ? visibleColumns.filter(vc => table.getState().columnPinning.left?.includes(vc.id)) : [];
183
+ const fixedRightColumns = table.getState().columnPinning.right ? visibleColumns.filter(vc => table.getState().columnPinning.right?.includes(vc.id)) : [];
184
+
185
+ //we are using a slightly different virtualization strategy for columns (compared to virtual rows) in order to support dynamic row heights
186
+ const columnVirtualizer = (0, _reactVirtual.useVirtualizer)({
187
+ count: visibleColumns.length,
188
+ estimateSize: index => visibleColumns[index].getSize(),
189
+ //estimate width of each column for accurate scrollbar dragging
190
+ getScrollElement: () => tableContainerRef.current,
191
+ horizontal: true,
192
+ // measureElement(element) {
193
+
194
+ // return element?.getBoundingClientRect().width;
195
+ // },
196
+
197
+ measureElement: typeof window !== 'undefined' && navigator.userAgent.indexOf('Firefox') === -1 ? element => element?.getBoundingClientRect().height : undefined,
198
+ overscan: 0 //how many columns to render on each side off screen each way (adjust this for performance)
199
+ });
200
+ const virtualColumns = columnVirtualizer.getVirtualItems();
201
+ const cacheColumns = columnVirtualizer.measurementsCache;
202
+ const rightCols = table.getState().columnPinning.right?.length ? [...cacheColumns].slice(-(table.getState().columnPinning.right?.length ?? 0)) : [];
203
+ const leftCols = [...cacheColumns].slice(0, table.getState().columnPinning.left?.length ?? 0);
204
+ const rightWidth = (0, _utils.sumSize)(rightCols);
205
+ const leftWidth = (0, _utils.sumSize)(leftCols);
206
+
207
+ //different virtualization strategy for columns - instead of absolute and translateY, we add empty columns to the left and right
208
+ let virtualPaddingLeft;
209
+ let virtualPaddingRight;
210
+ const pdRight = columnVirtualizer.getTotalSize() - (virtualColumns[virtualColumns.length - 1]?.end ?? 0);
211
+ if (columnVirtualizer && virtualColumns?.length) {
212
+ virtualPaddingLeft = fixedLeftColumns && fixedLeftColumns.length > 0 ? (virtualColumns[0]?.start ?? 0) - leftWidth > 0 ? (virtualColumns[0]?.start ?? 0) - leftWidth : 0 : virtualColumns[0]?.start ?? 0;
213
+
214
+ // virtualPaddingLeft = leftCols.length === rss.length ? (virtualColumns[0]?.start ?? 0) : 0;
215
+ // columnVirtualizer.getTotalSize() - (virtualColumns[virtualColumns.length - 1]?.end ?? 0) - rightWidth > 0 ? columnVirtualizer.getTotalSize() - (virtualColumns[virtualColumns.length - 1]?.end ?? 0) - rightWidth : 0;
216
+ virtualPaddingRight = fixedRightColumns && fixedRightColumns.length > 0 ? pdRight - rightWidth > 0 ? pdRight - rightWidth : 0 : pdRight;
217
+ // virtualPaddingRight = columnVirtualizer.getTotalSize() - (virtualColumns[virtualColumns.length - 1]?.end ?? 0)
218
+ }
219
+ const [editingKey, setEditingKey] = _react.default.useState('');
220
+ const [rangeState, setRangeState] = _react.default.useState({
221
+ startRowIndex: undefined,
222
+ endRowIndex: undefined,
223
+ startColIndex: undefined,
224
+ endColIndex: undefined,
225
+ rowIds: [],
226
+ colIds: [],
227
+ colRange: [],
228
+ rowRange: []
229
+ });
230
+ const [rangePasteState, setRangePasteState] = _react.default.useState({
231
+ startRowIndex: undefined,
232
+ endRowIndex: undefined,
233
+ startColIndex: undefined,
234
+ endColIndex: undefined,
235
+ rowIds: [],
236
+ colIds: [],
237
+ colRange: [],
238
+ rowRange: []
239
+ });
240
+ const [focusedCell, setFocusedCell] = _react.default.useState(undefined);
241
+ const [startCell, setStartCell] = _react.default.useState(undefined);
242
+ const [endCell, setEndCell] = _react.default.useState(undefined);
243
+ const [startPasteCell, setStartPasteCell] = _react.default.useState(undefined);
244
+ const [endPasteCell, setEndPasteCell] = _react.default.useState(undefined);
245
+ const [isSelecting, setIsSelecting] = _react.default.useState(false);
246
+ const [isPasting, setIsPasting] = _react.default.useState(false);
247
+ // const [isFullScreen] = React.useState(false);
248
+ const [tableHeight, settableHeight] = _react.default.useState(0);
249
+
250
+ // const [isAddNewRow, setIsAddNewRow] = React.useState(false)
251
+
252
+ const rowsFocus = _react.default.useMemo(() => {
253
+ return startCell && endCell ? (0, _utils.getRowIdsBetween)(table, startCell.rowId, endCell.rowId) : [];
254
+ }, [endCell, startCell, table]);
255
+ const copySelectionToClipboard = _react.default.useCallback(() => {
256
+ if (!startCell || !endCell) {
257
+ return;
258
+ }
259
+
260
+ // const allRows = table.getRowModel().rows;
261
+ const allRows = table.getRowModel().flatRows;
262
+ // const allColumns = table.getAllLeafColumns();
263
+
264
+ const rowIds = (0, _utils.getRowIdsBetween)(table, startCell.rowId, endCell.rowId);
265
+ const colIds = (0, _utils.getColIdsBetween)(table, startCell.colId, endCell.colId);
266
+ const dataToCopy = [];
267
+ rowIds.forEach(rowId => {
268
+ const row = allRows.find(r => r.id === rowId);
269
+ if (!row) return;
270
+ const rowData = [];
271
+ colIds.forEach(colId => {
272
+ const cellll = row.getVisibleCells().find(c => c.column.id === colId);
273
+ const value = cellll?.getValue();
274
+ rowData.push(value !== undefined ? String(value) : '');
275
+ });
276
+ dataToCopy.push(rowData);
277
+ });
278
+
279
+ // Convert to TSV string
280
+ const tsv = dataToCopy.map(row => row.join('\t')).join('\n');
281
+
282
+ // Copy to clipboard
283
+ // navigator.clipboard.writeText(tsv).then(() => {
284
+ // });
285
+
286
+ copy(tsv).then(() => {}).catch(() => {});
287
+ }, [startCell, endCell, table]);
288
+ const triggerChangeData = _react.default.useCallback(newData => {
289
+ onDataChange?.(newData);
290
+ }, [onDataChange, dataSource]);
291
+ const triggerPaste = _react.default.useCallback((pastedRows, pastedColumnsArray, newData, copyRows) => {
292
+ const handlePasteCallback = callbackData => {
293
+ const rsFilterData = (0, _utils.updateOrInsert)((0, _utils.flattenArray)([...originData]), (0, _utils.flattenArray)([...callbackData]));
294
+ const rs = (0, _utils.unFlattenData)(rsFilterData);
295
+ triggerChangeData(rs);
296
+ };
297
+ if (onCellPaste && onCellPaste.onPasted) {
298
+ if (onCellPaste.onPasted.length > 1) {
299
+ // có callback
300
+ onCellPaste.onPasted({
301
+ pasteData: pastedRows,
302
+ copyRows,
303
+ type: 'onPaste',
304
+ data: originData,
305
+ pastedColumns: pastedColumnsArray
306
+ }, handlePasteCallback);
307
+ } else {
308
+ // không có callback
309
+ onCellPaste.onPasted({
310
+ pasteData: pastedRows,
311
+ type: 'onPaste',
312
+ copyRows,
313
+ data: originData,
314
+ pastedColumns: pastedColumnsArray
315
+ }, handlePasteCallback);
316
+ triggerChangeData(newData);
317
+ }
318
+ } else {
319
+ triggerChangeData(newData);
320
+ }
321
+ }, [onCellPaste, originData, triggerChangeData]);
322
+ const handlePasted = _react.default.useCallback(pasteData => {
323
+ if (!startCell) {
324
+ return;
325
+ }
326
+ const rows = pasteData.slice(0, onCellPaste?.maxRowsPaste ?? 200);
327
+
328
+ // const allRows = table.getRowModel().rows;
329
+ const allRows = table.getRowModel().flatRows;
330
+ const allCols = table.getVisibleLeafColumns();
331
+ const startRowIdx = allRows.findIndex(r => r.id === startCell.rowId);
332
+ const startColIdx = allCols.findIndex(c => c.id === startCell.colId);
333
+
334
+ // const record: any = allRows[startRowIdx].original
335
+
336
+ const record = table.getRow(startCell.rowId).original;
337
+ const row = table.getRow(startCell.rowId);
338
+ if (!row.parentId) {
339
+ // Cập nhật data mới
340
+ const newData = (0, _utils.flattenArray)([...dataSource]);
341
+
342
+ // Lấy vị trí bắt đầu
343
+
344
+ // const startRow = newData.findIndex((it) => it[rowKey as any] === record[rowKey])
345
+ const startRow = startRowIdx;
346
+ const startCol = startColIdx;
347
+ const pastedRows = [];
348
+ const pastedColumns = new Set();
349
+ rows.forEach((rowValues, rowIndex) => {
350
+ const targetRow = startRow + rowIndex;
351
+
352
+ // Nếu vượt quá số dòng hiện có, thêm dòng mới
353
+ if (targetRow >= newData.length) {
354
+ newData.push({
355
+ id: undefined,
356
+ rowId: (0, _utils.newGuid)()
357
+ });
358
+ }
359
+ rowValues.forEach((cellValue, colIndex) => {
360
+ const targetCol = startCol + colIndex;
361
+ if (targetCol >= allCols.length) {
362
+ // Không vượt quá số cột
363
+ return;
364
+ }
365
+ const columnTarget = allCols[targetCol];
366
+ const columnOri = columnTarget.columnDef.meta ?? {};
367
+ const isEdit = typeof columnOri?.editEnable === 'function' ? columnOri.editEnable(newData[targetRow]) : columnOri.editEnable;
368
+ if (isEdit) {
369
+ const columnKey = allCols[targetCol].id;
370
+
371
+ // if (columnOri.type === 'number' && isFormattedNumber(cellValue.trim())) {
372
+ if (columnOri.type === 'number') {
373
+ if (cellValue.trim() === '') {
374
+ newData[targetRow] = {
375
+ ...newData[targetRow],
376
+ [columnKey]: null
377
+ };
378
+ }
379
+ if ((0, _utils.isFormattedNumber)(cellValue.trim()) || !isNaN(Number(cellValue.trim()))) {
380
+ const colFormat = typeof columnOri.format === 'function' ? columnOri.format(record) : columnOri.format;
381
+ const valuePasteFormat = (0, _utils.detectSeparators)(cellValue.trim());
382
+ const cellFormat = (0, _utils.getFormat)(colFormat, format);
383
+ const thousandSeparator = valuePasteFormat?.thousandSeparator;
384
+ const decimalSeparator = valuePasteFormat?.decimalSeparator;
385
+ const dec = cellFormat?.decimalScale;
386
+ const numericFormatProps = {
387
+ thousandSeparator: (0, _utils.checkThousandSeparator)(thousandSeparator, decimalSeparator),
388
+ decimalSeparator: (0, _utils.checkDecimalSeparator)(thousandSeparator, decimalSeparator),
389
+ allowNegative: cellFormat?.allowNegative ?? true,
390
+ prefix: cellFormat?.prefix,
391
+ suffix: cellFormat?.suffix,
392
+ decimalScale: dec,
393
+ fixedDecimalScale: cellFormat?.fixedDecimalScale ?? false
394
+ };
395
+ const val = (0, _reactNumericComponent.removeNumericFormat)(cellValue.trim(), undefined, numericFormatProps);
396
+ newData[targetRow] = {
397
+ ...newData[targetRow],
398
+ [columnKey]: Number(val)
399
+ };
400
+ }
401
+ } else {
402
+ newData[targetRow] = {
403
+ ...newData[targetRow],
404
+ [columnKey]: cellValue.trim()
405
+ };
406
+ }
407
+ pastedColumns.add(columnKey);
408
+ }
409
+ });
410
+
411
+ // Lưu dòng được paste
412
+ pastedRows.push(newData[targetRow]);
413
+ });
414
+ const pastedColumnsArray = Array.from(pastedColumns) ?? [];
415
+ const rsFilterData = (0, _utils.updateOrInsert)((0, _utils.flattenArray)([...originData]), newData);
416
+ const rs = (0, _utils.unFlattenData)(rsFilterData);
417
+ triggerPaste?.(pastedRows, pastedColumnsArray, rs, []);
418
+ } else {
419
+ // const parent = findItemByKey(dataSource, rowKey as any, record.parentId)
420
+ const parent = row.getParentRow()?.original;
421
+
422
+ // Cập nhật childData mới
423
+ const childData = parent?.children ? [...parent.children] : [];
424
+
425
+ // Lấy vị trí bắt đầu
426
+ // const { row: startRow, col: startCol } = selectedCell;
427
+ const startRow = childData.findIndex(it => it[rowKey] === record[rowKey]);
428
+ const startCol = startColIdx;
429
+ const pastedRows = [];
430
+ const pastedColumns = new Set();
431
+ rows.forEach((rowValues, rowIndex) => {
432
+ const targetRow = startRow + rowIndex;
433
+
434
+ // Nếu vượt quá số dòng hiện có, thêm dòng mới
435
+ if (targetRow >= childData.length) {
436
+ childData.push({
437
+ id: undefined,
438
+ rowId: (0, _utils.newGuid)(),
439
+ parentId: parent[rowKey ?? 'id']
440
+ });
441
+ }
442
+ rowValues.forEach((cellValue, colIndex) => {
443
+ const targetCol = startCol + colIndex;
444
+ if (targetCol >= allCols.length) {
445
+ // Không vượt quá số cột
446
+ return;
447
+ }
448
+ const columnTarget = allCols[targetCol];
449
+
450
+ // const isEdit = typeof columnTarget.editEnable === 'function' ? columnTarget.editEnable(childData[targetRow]) : columnTarget.editEnable
451
+
452
+ const columnOri = columnTarget.columnDef.meta ?? {};
453
+ const isEdit = typeof columnOri?.editEnable === 'function' ? columnOri.editEnable(childData[targetRow]) : columnOri.editEnable;
454
+
455
+ // if (isEdit) {
456
+
457
+ // const columnKey = allCols[targetCol].id
458
+
459
+ // childData[targetRow] = { ...childData[targetRow], [columnKey]: cellValue.trim() }
460
+
461
+ // pastedColumns.add(columnKey)
462
+ // }
463
+
464
+ if (isEdit) {
465
+ const columnKey = allCols[targetCol].id;
466
+
467
+ // if (columnOri.type === 'number' && isFormattedNumber(cellValue.trim())) {
468
+ if (columnOri.type === 'number') {
469
+ if (cellValue.trim() === '') {
470
+ childData[targetRow] = {
471
+ ...childData[targetRow],
472
+ [columnKey]: null
473
+ };
474
+ }
475
+ if ((0, _utils.isFormattedNumber)(cellValue.trim()) || !isNaN(Number(cellValue.trim()))) {
476
+ const colFormat = typeof columnOri.format === 'function' ? columnOri.format(record) : columnOri.format;
477
+ const valuePasteFormat = (0, _utils.detectSeparators)(cellValue.trim());
478
+ const cellFormat = (0, _utils.getFormat)(colFormat, format);
479
+ const thousandSeparator = valuePasteFormat?.thousandSeparator;
480
+ const decimalSeparator = valuePasteFormat?.decimalSeparator;
481
+ const dec = cellFormat?.decimalScale;
482
+ const numericFormatProps = {
483
+ thousandSeparator: (0, _utils.checkThousandSeparator)(thousandSeparator, decimalSeparator),
484
+ decimalSeparator: (0, _utils.checkDecimalSeparator)(thousandSeparator, decimalSeparator),
485
+ allowNegative: cellFormat?.allowNegative ?? true,
486
+ prefix: cellFormat?.prefix,
487
+ suffix: cellFormat?.suffix,
488
+ decimalScale: dec,
489
+ fixedDecimalScale: cellFormat?.fixedDecimalScale ?? false
490
+ };
491
+ const val = (0, _reactNumericComponent.removeNumericFormat)(cellValue.trim(), undefined, numericFormatProps);
492
+ childData[targetRow] = {
493
+ ...childData[targetRow],
494
+ [columnKey]: Number(val)
495
+ };
496
+ }
497
+ } else {
498
+ childData[targetRow] = {
499
+ ...childData[targetRow],
500
+ [columnKey]: cellValue.trim()
501
+ };
502
+ }
503
+ pastedColumns.add(columnKey);
504
+ }
505
+ });
506
+
507
+ // Lưu dòng được paste
508
+ pastedRows.push(childData[targetRow]);
509
+ });
510
+ const pastedColumnsArray = Array.from(pastedColumns) ?? [];
511
+ const newRowData = {
512
+ ...parent,
513
+ children: childData
514
+ }; // item đã được filter
515
+
516
+ const newDataSource = (0, _utils.updateArrayByKey)(originData, newRowData, rowKey);
517
+ triggerPaste?.(pastedRows, pastedColumnsArray, newDataSource, []);
518
+ }
519
+ }, [dataSource, format, onCellPaste?.maxRowsPaste, originData, rowKey, startCell, table, triggerPaste]);
520
+ const handlePastedGroup = _react.default.useCallback(pasteData => {
521
+ if (!startCell) {
522
+ return;
523
+ }
524
+ const rows = pasteData.slice(0, onCellPaste?.maxRowsPaste ?? 200);
525
+
526
+ // const allRows = table.getRowModel().flatRows;
527
+ const allCols = table.getVisibleLeafColumns();
528
+
529
+ // const startRowIdx = allRows.findIndex(r => r.id === startCell.rowId);
530
+ const startColIdx = allCols.findIndex(c => c.id === startCell.colId);
531
+
532
+ // const record: any = allRows[startRowIdx].original
533
+
534
+ const record = table.getRow(startCell.rowId).original;
535
+ const row = table.getRow(startCell.rowId);
536
+ if (!row.parentId) {
537
+
538
+ // // Cập nhật data mới
539
+ // const newData = flattenArray([...dataSource])
540
+
541
+ // // Lấy vị trí bắt đầu
542
+
543
+ // // const startRow = newData.findIndex((it) => it[rowKey as any] === record[rowKey])
544
+ // const startRow = startRowIdx
545
+
546
+ // const startCol = startColIdx
547
+
548
+ // const pastedRows: RecordType[] = []
549
+ // const pastedColumns = new Set()
550
+
551
+ // rows.forEach((rowValues: any, rowIndex: any) => {
552
+ // const targetRow = startRow + rowIndex
553
+
554
+ // // Nếu vượt quá số dòng hiện có, thêm dòng mới
555
+ // if (targetRow >= newData.length) {
556
+
557
+ // newData.push({ id: undefined, rowId: newGuid() })
558
+ // }
559
+
560
+ // rowValues.forEach((cellValue: any, colIndex: any) => {
561
+
562
+ // const targetCol = startCol + colIndex
563
+
564
+ // if (targetCol >= allCols.length) { // Không vượt quá số cột
565
+ // return
566
+ // }
567
+
568
+ // const columnTarget = allCols[targetCol]
569
+
570
+ // const columnOri: any = columnTarget.columnDef.meta ?? {}
571
+
572
+ // const isEdit = typeof columnOri?.editEnable === 'function' ? columnOri.editEnable(newData[targetRow]) : columnOri.editEnable
573
+
574
+ // if (isEdit) {
575
+
576
+ // const columnKey = allCols[targetCol].id
577
+
578
+ // // if (columnOri.type === 'number' && isFormattedNumber(cellValue.trim())) {
579
+ // if (columnOri.type === 'number') {
580
+ // if (cellValue.trim() === '') {
581
+ // newData[targetRow] = { ...newData[targetRow], [columnKey]: null }
582
+ // }
583
+
584
+ // if (isFormattedNumber(cellValue.trim()) || !isNaN(Number(cellValue.trim()))) {
585
+
586
+ // const colFormat = typeof columnOri.format === 'function' ? columnOri.format(record) : columnOri.format
587
+
588
+ // const valuePasteFormat = detectSeparators(cellValue.trim())
589
+
590
+ // const cellFormat = getFormat(colFormat, format)
591
+ // const thousandSeparator = valuePasteFormat?.thousandSeparator
592
+ // const decimalSeparator = valuePasteFormat?.decimalSeparator
593
+ // const dec = cellFormat?.decimalScale
594
+
595
+ // const numericFormatProps = {
596
+ // thousandSeparator: checkThousandSeparator(thousandSeparator, decimalSeparator),
597
+ // decimalSeparator: checkDecimalSeparator(thousandSeparator, decimalSeparator),
598
+ // allowNegative: (cellFormat?.allowNegative) ?? true,
599
+ // prefix: cellFormat?.prefix,
600
+ // suffix: cellFormat?.suffix,
601
+ // decimalScale: dec,
602
+ // fixedDecimalScale: (cellFormat?.fixedDecimalScale) ?? false
603
+ // }
604
+
605
+ // const val = removeNumericFormat(cellValue.trim(), undefined, numericFormatProps)
606
+
607
+ // newData[targetRow] = { ...newData[targetRow], [columnKey]: Number(val) }
608
+
609
+ // }
610
+
611
+ // } else {
612
+
613
+ // newData[targetRow] = { ...newData[targetRow], [columnKey]: cellValue.trim() }
614
+
615
+ // }
616
+
617
+ // pastedColumns.add(columnKey)
618
+
619
+ // }
620
+
621
+ // }
622
+ // )
623
+
624
+ // // Lưu dòng được paste
625
+ // pastedRows.push(newData[targetRow])
626
+
627
+ // })
628
+
629
+ // const pastedColumnsArray = Array.from(pastedColumns) ?? []
630
+
631
+ // const rsFilterData = updateOrInsert(flattenArray([...originData]), newData)
632
+ // const rsFilterData1 = updateOrInsert(flattenArray([...dataSource]), newData)
633
+
634
+ // const rs = unFlattenData(rsFilterData)
635
+
636
+ // const dta = unGroupData(rs, originData)
637
+
638
+ // triggerPaste?.(pastedRows, pastedColumnsArray as string[], rs, [])
639
+ } else {
640
+ // const parent = findItemByKey(dataSource, rowKey as any, record.parentId)
641
+ const parent = row.getParentRow()?.original;
642
+
643
+ // Cập nhật childData mới
644
+ const childData = parent?.children ? [...parent.children] : [];
645
+
646
+ // Lấy vị trí bắt đầu
647
+ // const { row: startRow, col: startCol } = selectedCell;
648
+ const startRow = childData.findIndex(it => it[rowKey] === record[rowKey]);
649
+ const startCol = startColIdx;
650
+ const pastedRows = [];
651
+ const pastedColumns = new Set();
652
+ rows.forEach((rowValues, rowIndex) => {
653
+ const targetRow = startRow + rowIndex;
654
+
655
+ // Nếu vượt quá số dòng hiện có, thêm dòng mới
656
+ if (targetRow >= childData.length) {
657
+ childData.push({
658
+ id: undefined,
659
+ rowId: (0, _utils.newGuid)(),
660
+ parentId: parent[rowKey ?? 'id']
661
+ });
662
+ }
663
+ rowValues.forEach((cellValue, colIndex) => {
664
+ const targetCol = startCol + colIndex;
665
+ if (targetCol >= allCols.length) {
666
+ // Không vượt quá số cột
667
+ return;
668
+ }
669
+ const columnTarget = allCols[targetCol];
670
+
671
+ // const isEdit = typeof columnTarget.editEnable === 'function' ? columnTarget.editEnable(childData[targetRow]) : columnTarget.editEnable
672
+
673
+ const columnOri = columnTarget.columnDef.meta ?? {};
674
+ const isEdit = typeof columnOri?.editEnable === 'function' ? columnOri.editEnable(childData[targetRow]) : columnOri.editEnable;
675
+
676
+ // if (isEdit) {
677
+
678
+ // const columnKey = allCols[targetCol].id
679
+
680
+ // childData[targetRow] = { ...childData[targetRow], [columnKey]: cellValue.trim() }
681
+
682
+ // pastedColumns.add(columnKey)
683
+ // }
684
+
685
+ if (isEdit) {
686
+ const columnKey = allCols[targetCol].id;
687
+
688
+ // if (columnOri.type === 'number' && isFormattedNumber(cellValue.trim())) {
689
+ if (columnOri.type === 'number') {
690
+ if (cellValue.trim() === '') {
691
+ childData[targetRow] = {
692
+ ...childData[targetRow],
693
+ [columnKey]: null
694
+ };
695
+ }
696
+ if ((0, _utils.isFormattedNumber)(cellValue.trim()) || !isNaN(Number(cellValue.trim()))) {
697
+ const colFormat = typeof columnOri.format === 'function' ? columnOri.format(record) : columnOri.format;
698
+ const valuePasteFormat = (0, _utils.detectSeparators)(cellValue.trim());
699
+ const cellFormat = (0, _utils.getFormat)(colFormat, format);
700
+ const thousandSeparator = valuePasteFormat?.thousandSeparator;
701
+ const decimalSeparator = valuePasteFormat?.decimalSeparator;
702
+ const dec = cellFormat?.decimalScale;
703
+ const numericFormatProps = {
704
+ thousandSeparator: (0, _utils.checkThousandSeparator)(thousandSeparator, decimalSeparator),
705
+ decimalSeparator: (0, _utils.checkDecimalSeparator)(thousandSeparator, decimalSeparator),
706
+ allowNegative: cellFormat?.allowNegative ?? true,
707
+ prefix: cellFormat?.prefix,
708
+ suffix: cellFormat?.suffix,
709
+ decimalScale: dec,
710
+ fixedDecimalScale: cellFormat?.fixedDecimalScale ?? false
711
+ };
712
+ const val = (0, _reactNumericComponent.removeNumericFormat)(cellValue.trim(), undefined, numericFormatProps);
713
+ childData[targetRow] = {
714
+ ...childData[targetRow],
715
+ [columnKey]: Number(val)
716
+ };
717
+ }
718
+ } else {
719
+ childData[targetRow] = {
720
+ ...childData[targetRow],
721
+ [columnKey]: cellValue.trim()
722
+ };
723
+ }
724
+ pastedColumns.add(columnKey);
725
+ }
726
+ });
727
+
728
+ // Lưu dòng được paste
729
+ pastedRows.push(childData[targetRow]);
730
+ });
731
+ const pastedColumnsArray = Array.from(pastedColumns) ?? [];
732
+ const newRowData = {
733
+ ...parent,
734
+ children: childData
735
+ }; // item đã được filter
736
+
737
+ // const newDataSource = updateArrayByKey(originData, newRowData, rowKey as string)
738
+ const newDataSource = (0, _utils.updateArrayByKey)(dataSource, newRowData, rowKey);
739
+ const dta = (0, _utils3.unGroupData)(newDataSource, originData);
740
+ triggerPaste?.(pastedRows, pastedColumnsArray, dta, []);
741
+ }
742
+ }, [dataSource, format, onCellPaste?.maxRowsPaste, originData, rowKey, startCell, table, triggerPaste]);
743
+ const handlePasteToTable = _react.default.useCallback(pasteData => {
744
+ if (!startCell) return;
745
+
746
+ // const pastedRows = pasted.trim().split('\n').map(row => row.split('\t'));
747
+
748
+ // const clipboardText = e.clipboardData?.getData('text/plain') ?? '';
749
+
750
+ // Chuyển đổi dữ liệu từ clipboard thành mảng
751
+ // const rowsPasted = pasteData.split("\n").filter((row: any) => row !== '').map((row: any) =>
752
+ // row.replace(/\r/g, "").split("\t")
753
+
754
+ // )
755
+
756
+ // const rowsPasted = parseExcelText(pasteData)
757
+ const rowsPasted = (0, _utils.parseExcelClipboardText)(pasteData);
758
+ if (rowsPasted.length > (onCellPaste?.maxRowsPaste ?? 200)) {
759
+ // bật popup thông báo
760
+
761
+ _antd.Modal.confirm({
762
+ content: /*#__PURE__*/_react.default.createElement("div", null, /*#__PURE__*/_react.default.createElement(Paragraph, {
763
+ style: {
764
+ marginBottom: '.25rem',
765
+ fontSize: 14
766
+ }
767
+ }, "D\u1EEF li\u1EC7u sao ch\xE9p v\u01B0\u1EE3t qu\xE1 s\u1ED1 d\xF2ng cho ph\xE9p (", onCellPaste?.maxRowsPaste ?? 200, " d\xF2ng).Ph\u1EA7n m\u1EC1n s\u1EBD ch\u1EC9 l\u1EA5y (", onCellPaste?.maxRowsPaste ?? 200, " d\xF2ng \u0111\u1EA7u ti\xEAn."), /*#__PURE__*/_react.default.createElement(Title, {
768
+ level: 5,
769
+ style: {
770
+ marginTop: '.75rem'
771
+ }
772
+ }, "B\u1EA1n c\xF3 mu\u1ED1n ti\u1EBFp t\u1EE5c sao ch\xE9p kh\xF4ng?")),
773
+ centered: true,
774
+ className: 'be-popup-container',
775
+ onOk: () => {
776
+ if (groupColumns && groupColumns.length > 0) {
777
+ handlePastedGroup(rowsPasted);
778
+ } else {
779
+ handlePasted(rowsPasted);
780
+ }
781
+ }
782
+ // footer: (_, { OkBtn, CancelBtn }) => (
783
+ // <>
784
+ // <OkBtn />
785
+ // <CancelBtn />
786
+ // </>
787
+ // ),
788
+ });
789
+ } else {
790
+ if (groupColumns && groupColumns.length > 0) {
791
+ handlePastedGroup(rowsPasted);
792
+ } else {
793
+ handlePasted(rowsPasted);
794
+ }
795
+ }
796
+ }, [handlePasted, onCellPaste?.maxRowsPaste, startCell, handlePastedGroup, groupColumns]);
797
+ _react.default.useEffect(() => {
798
+ const handleKeyDown = e => {
799
+ if (e.ctrlKey && e.key === 'c' && startCell && endCell && !editingKey) {
800
+ e.preventDefault();
801
+ copySelectionToClipboard();
802
+ }
803
+ };
804
+ window.addEventListener('keydown', handleKeyDown);
805
+ return () => window.removeEventListener('keydown', handleKeyDown);
806
+ }, [startCell, endCell, table, copySelectionToClipboard, editingKey]);
807
+ _react.default.useEffect(() => {
808
+ const handlePaste = e => {
809
+ if (startCell && !editingKey) {
810
+ e.preventDefault(); // Chặn hành vi mặc định
811
+ const clipboardText = e.clipboardData?.getData('text/plain') ?? '';
812
+ handlePasteToTable(clipboardText);
813
+ }
814
+ };
815
+ window.addEventListener('paste', handlePaste);
816
+ return () => window.removeEventListener('paste', handlePaste);
817
+ }, [startCell, endCell, table, handlePasteToTable, editingKey]);
818
+ _react.default.useEffect(() => {
819
+ const handleClickOutside = event => {
820
+ const element = event.target;
821
+ const container = document.querySelector(".be-popup-container");
822
+ const containerContextMenu = document.querySelector(".popup-context-menu");
823
+ const tableBody = document.querySelector(`#${id} .ui-rc-grid-tbody`);
824
+ const itemContainer = document.querySelector(`#${id} .ui-rc-toolbar-selection-overflow-item`);
825
+ const itemHeader = document.querySelector(`#${id} .ui-rc-table-thead`);
826
+ const isInsideContainer = element.closest(".be-popup-container") && container;
827
+ const isInsideContainerContext = containerContextMenu && element.closest(".popup-context-menu");
828
+ const isInsideToolbar = element.closest(`.ui-rc-toolbar-selection-overflow-item`) && itemContainer;
829
+ const isInsideHeader = itemHeader && itemHeader.contains(event.target);
830
+ if (isInsideContainer || isInsideToolbar || isInsideHeader || isInsideContainerContext || element.id === id) {
831
+ return;
832
+ }
833
+ if (containerRef.current && tableBody && !tableBody.contains(event.target)) {
834
+ if (editingKey) {
835
+ onBlur?.(dataSource);
836
+ }
837
+ setTimeout(() => {
838
+ setEditingKey('');
839
+ // editingKey.current = ''
840
+ });
841
+ setEndCell(undefined);
842
+ setStartCell(undefined);
843
+ setRangeState(undefined);
844
+ setFocusedCell(undefined);
845
+ }
846
+ };
847
+
848
+ // document.addEventListener('click', handleClickOutside)
849
+ document.addEventListener('mousedown', handleClickOutside);
850
+ // document.addEventListener('touchstart', handleClickOutside)
851
+
852
+ return () => {
853
+ // document.removeEventListener('click', handleClickOutside)
854
+ document.removeEventListener('mousedown', handleClickOutside);
855
+ // document.removeEventListener('touchstart', handleClickOutside)
856
+ };
857
+ }, [dataSource, editingKey, id, onBlur]);
858
+ const columnSizingState = table.getState().columnSizing;
859
+ _react.default.useEffect(() => {
860
+ requestAnimationFrame(() => {
861
+ columnVirtualizer.measure();
862
+ });
863
+ }, [columnSizingState, columnVirtualizer]);
864
+ _react.default.useEffect(() => {
865
+ if (!tableContainerRef.current) {
866
+ return;
867
+ }
868
+ if (columnSizingInfo.isResizingColumn === false) {
869
+ const aa = (0, _utils.updateColumnWidthsRecursive)(propsColumns, columnSizing);
870
+ setColumns(aa);
871
+ }
872
+ }, [columnSizingInfo]);
873
+ _react.default.useEffect(() => {
874
+ // const totalHeight = minHeight ?? height
875
+ const totalHeight = (0, _utils.getTableHeight)(height, minHeight);
876
+ if (totalHeight) {
877
+ const topHeight = topToolbarRef.current ? topToolbarRef.current.offsetHeight : 0;
878
+ const bottomHeight = bottomToolbarRef.current ? bottomToolbarRef.current.offsetHeight : 0;
879
+ settableHeight(totalHeight - topHeight - bottomHeight);
880
+ }
881
+ }, [id, height, editAble, minHeight, toolbarItems]);
882
+ const {
883
+ control,
884
+ handleSubmit,
885
+ setValue,
886
+ // trigger,
887
+ getValues,
888
+ reset,
889
+ formState: {
890
+ errors
891
+ }
892
+ } = (0, _reactHookForm.useForm)({
893
+ mode: 'onChange',
894
+ resolver: validate ? (0, _yup.yupResolver)(validate) : undefined
895
+ });
896
+ const handleAddMulti = _react.default.useCallback((item, n, newId) => {
897
+ if (item.onClick) {
898
+ item.onClick({
899
+ toolbar: item
900
+ });
901
+ } else {
902
+ const defaultRowValue = (0, _utils.getDefaultValue)(defaultValue);
903
+ const newRows = Array.from({
904
+ length: n
905
+ }).map(() => defaultRowValue ? {
906
+ ...defaultRowValue,
907
+ id: undefined,
908
+ rowId: n === 1 && newId ? newId : (0, _utils.newGuid)()
909
+ } : {
910
+ id: undefined,
911
+ rowId: n === 1 && newId ? newId : (0, _utils.newGuid)()
912
+ });
913
+ const kkk = (0, _utils.getAllRowKey)(newRows) ?? [];
914
+ const rs = mergedFilterKeys ? [...mergedFilterKeys, ...kkk] : [...kkk];
915
+ setMergedFilterKeys?.(rs);
916
+ const newData = dataSource.concat(newRows);
917
+ triggerChangeData?.(newData);
918
+ }
919
+ }, [dataSource, defaultValue, mergedFilterKeys, setMergedFilterKeys, triggerChangeData]);
920
+ const onSubmit = formData => {
921
+ try {
922
+ // const record = (await form.validateFields()) as RecordType;
923
+ const row = {
924
+ ...formData
925
+ };
926
+
927
+ // const newData = [...dataSource]
928
+ const newData = [...originData];
929
+
930
+ // @ts-ignore
931
+ const index = (0, _utils.flattenData)(childrenColumnName, newData).findIndex(item => formData[rowKey] === item[rowKey]);
932
+ const rs = (0, _utils.updateArrayByKey)(newData, row, rowKey);
933
+ if (index > -1) {
934
+ triggerChangeData?.(rs);
935
+ }
936
+ } catch (errInfo) {
937
+ console.log('Validate Failed:', errInfo);
938
+ }
939
+ };
940
+ const onSubmit2 = (formData, newOriginData) => {
941
+ try {
942
+ // const record = (await form.validateFields()) as RecordType;
943
+ const row = {
944
+ ...formData
945
+ };
946
+
947
+ // const newData = [...dataSource]
948
+ const newData = [...newOriginData];
949
+
950
+ // @ts-ignore
951
+ const index = (0, _utils.flattenData)(childrenColumnName, newData).findIndex(item => formData[rowKey] === item[rowKey]);
952
+ const rs = (0, _utils.updateArrayByKey)(newData, row, rowKey);
953
+ if (index > -1) {
954
+ triggerChangeData?.(rs);
955
+ }
956
+ } catch (errInfo) {
957
+ console.log('Validate Failed:', errInfo);
958
+ }
959
+ };
960
+ const handleCellChange = args => {
961
+ const {
962
+ record,
963
+ type: changeType,
964
+ newState,
965
+ prevState,
966
+ option,
967
+ field,
968
+ indexCol,
969
+ indexRow,
970
+ key
971
+ } = args;
972
+ if (changeType === 'blur') {
973
+ const handleChangeCallback = callbackData => {
974
+ const callbackRecord = callbackData;
975
+ Object.entries(callbackRecord).forEach(([name, value]) => {
976
+ setValue(name, value);
977
+ });
978
+ onSubmit(callbackRecord);
979
+ };
980
+ if (onCellChange) {
981
+ if (onCellChange.length > 1) {
982
+ onCellChange({
983
+ field,
984
+ indexCol,
985
+ type: 'onChange',
986
+ value: newState,
987
+ option,
988
+ indexRow,
989
+ rowData: record,
990
+ rowId: key,
991
+ // rowsData: [...dataSource],
992
+ rowsData: [...originData],
993
+ sumValue: []
994
+ }, handleChangeCallback);
995
+ } else {
996
+ onCellChange({
997
+ field,
998
+ indexCol,
999
+ type: 'onChange',
1000
+ option,
1001
+ value: newState,
1002
+ indexRow,
1003
+ rowData: record,
1004
+ rowId: key,
1005
+ // rowsData: [...dataSource],
1006
+ rowsData: [...originData],
1007
+ sumValue: []
1008
+ }, handleChangeCallback);
1009
+ onSubmit(record);
1010
+ }
1011
+ }
1012
+ }
1013
+ if (prevState && newState && prevState !== newState && changeType === 'enter') {
1014
+ onSubmit(record);
1015
+ }
1016
+ };
1017
+ const handleCellChangeAndAddRow = args => {
1018
+ const {
1019
+ record,
1020
+ type: changeType,
1021
+ newState,
1022
+ option,
1023
+ field,
1024
+ indexCol,
1025
+ indexRow,
1026
+ key
1027
+ } = args;
1028
+
1029
+ // add new row
1030
+
1031
+ const defaultRowValue = (0, _utils.getDefaultValue)(defaultValue);
1032
+ const newRowId = (0, _utils.newGuid)();
1033
+ const newRows = Array.from({
1034
+ length: 1
1035
+ }).map(() => defaultRowValue ? {
1036
+ ...defaultRowValue,
1037
+ id: undefined,
1038
+ rowId: newRowId
1039
+ } : {
1040
+ id: undefined,
1041
+ rowId: newRowId
1042
+ });
1043
+ const kkk = (0, _utils.getAllRowKey)(newRows) ?? [];
1044
+ const rs = mergedFilterKeys ? [...mergedFilterKeys, ...kkk] : [...kkk];
1045
+ setMergedFilterKeys?.(rs);
1046
+ const newData = originData.concat(newRows);
1047
+ setFocusedCell?.({
1048
+ rowId: newRowId,
1049
+ colId: field
1050
+ });
1051
+ setStartCell?.({
1052
+ rowId: newRowId,
1053
+ colId: field
1054
+ });
1055
+ setEndCell?.({
1056
+ rowId: newRowId,
1057
+ colId: field
1058
+ });
1059
+ setTimeout(() => {
1060
+ setRangeState?.((0, _utils.getSelectedCellMatrix)(table, {
1061
+ rowId: newRowId,
1062
+ colId: field
1063
+ }, {
1064
+ rowId: newRowId,
1065
+ colId: field
1066
+ }));
1067
+ });
1068
+ setTimeout(() => {
1069
+ const row = document.querySelector(`.ui-rc-grid-row[data-row-key="${newRowId}"]`);
1070
+ const cellFocus = row?.querySelector('.ui-rc-grid-cell:not(.ui-rc-grid-cell-selection)');
1071
+ if (cellFocus) {
1072
+ cellFocus.scrollIntoView({
1073
+ behavior: "smooth",
1074
+ block: "start"
1075
+ });
1076
+ cellFocus.focus();
1077
+ }
1078
+ }, 100);
1079
+ if (changeType === 'blur') {
1080
+ const handleChangeCallback = callbackData => {
1081
+ const callbackRecord = callbackData;
1082
+ onSubmit2(callbackRecord, [...newData]);
1083
+ };
1084
+ if (onCellChange) {
1085
+ if (onCellChange.length > 1) {
1086
+ onCellChange({
1087
+ field,
1088
+ indexCol,
1089
+ type: 'onChange',
1090
+ value: newState,
1091
+ option,
1092
+ indexRow,
1093
+ rowData: record,
1094
+ rowId: key,
1095
+ rowsData: [...newData],
1096
+ sumValue: []
1097
+ }, handleChangeCallback);
1098
+ } else {
1099
+ onCellChange({
1100
+ field,
1101
+ indexCol,
1102
+ type: 'onChange',
1103
+ option,
1104
+ value: newState,
1105
+ indexRow,
1106
+ rowData: record,
1107
+ rowId: key,
1108
+ rowsData: [...newData],
1109
+ sumValue: []
1110
+ }, handleChangeCallback);
1111
+ onSubmit2(record, [...newData]);
1112
+ }
1113
+ }
1114
+ }
1115
+
1116
+ // if (prevState && newState && prevState !== newState && changeType === 'enter') {
1117
+
1118
+ // onSubmit(record)
1119
+
1120
+ // }
1121
+ };
1122
+ const handleDuplicate = _react.default.useCallback(() => {
1123
+ // không tính tree
1124
+
1125
+ // Cập nhật data mới
1126
+ const newData = (0, _utils.flattenArray)([...dataSource]);
1127
+
1128
+ // const duplicatedItems = rowsFocus.map(index => ({ ...newData[index], rowId: newGuid(), id: undefined, isDuplicate: true }))
1129
+
1130
+ const duplicatedItem = table.getRowModel().flatRows.find(it => it.id === focusedCell?.rowId);
1131
+
1132
+ // setStartCell(focusedCell)
1133
+ // setEndCell(focusedCell)
1134
+
1135
+ // setRangeState(getSelectedCellMatrix(table, focusedCell, focusedCell))
1136
+
1137
+ const duplicatedItems = [{
1138
+ ...duplicatedItem?.original,
1139
+ rowId: (0, _utils.newGuid)(),
1140
+ id: undefined,
1141
+ isDuplicate: true
1142
+ }];
1143
+
1144
+ // Vị trí chèn là ngay sau phần tử lớn nhất trong rowsFocus
1145
+
1146
+ // const insertAfter = Math.max(...rowsFocus)
1147
+ const insertAfter = newData.findIndex(it => it[rowKey] === focusedCell?.rowId);
1148
+ const rsFilter = [...newData.slice(0, insertAfter + 1), ...duplicatedItems, ...newData.slice(insertAfter + 1)];
1149
+
1150
+ // const rs = updateOrInsertInOrder(originData, rsFilter)
1151
+ const rs = (0, _utils.updateOrInsert)(originData, rsFilter);
1152
+ // const rs2 = mergeWithFilter(originData, rsFilter)
1153
+
1154
+ triggerChangeData?.(rs);
1155
+ }, [dataSource, focusedCell, originData, rowKey, table, triggerChangeData]);
1156
+
1157
+ // thêm n dòng bên trên
1158
+ const handleInsertBefore = _react.default.useCallback((item, n) => {
1159
+ const defaultRowValue = (0, _utils.getDefaultValue)(defaultValue);
1160
+ setStartCell(focusedCell);
1161
+ setEndCell(focusedCell);
1162
+ setRangeState((0, _utils.getSelectedCellMatrix)(table, focusedCell, focusedCell));
1163
+
1164
+ // const record: any = table.getRowModel().rows.find((it) => it.id === rowsFocus[rowsFocus.length - 1])?.original
1165
+ const record = table.getRowModel().flatRows.find(it => it.id === rowsFocus[rowsFocus.length - 1])?.original;
1166
+ if (item.onClick) {
1167
+ item.onClick({
1168
+ toolbar: item
1169
+ });
1170
+ } else {
1171
+ if (!record?.parentId) {
1172
+ // Cập nhật data mới
1173
+
1174
+ const newData = [...originData];
1175
+ const newRows = Array.from({
1176
+ length: n
1177
+ }).map(() => defaultRowValue ? {
1178
+ ...defaultRowValue,
1179
+ id: undefined,
1180
+ rowId: (0, _utils.newGuid)()
1181
+ } : {
1182
+ id: undefined,
1183
+ rowId: (0, _utils.newGuid)()
1184
+ });
1185
+ const kkk = (0, _utils.getAllRowKey)(newRows) ?? [];
1186
+ const rs = mergedFilterKeys ? [...mergedFilterKeys, ...kkk] : [...kkk];
1187
+ setMergedFilterKeys?.(rs);
1188
+ const index = newData.findIndex(obj => obj[rowKey] === record[rowKey]);
1189
+ newData.splice(index, 0, ...newRows);
1190
+ triggerChangeData?.(newData);
1191
+ } else {
1192
+ const newData = [...originData];
1193
+ const parent = (0, _utils.findItemByKey)(newData, rowKey, record.parentId);
1194
+ const newRows = Array.from({
1195
+ length: n
1196
+ }).map(() => defaultRowValue ? {
1197
+ ...defaultRowValue,
1198
+ id: undefined,
1199
+ rowId: (0, _utils.newGuid)(),
1200
+ parentId: parent.rowId
1201
+ } : {
1202
+ id: undefined,
1203
+ rowId: (0, _utils.newGuid)(),
1204
+ parentId: parent.rowId
1205
+ });
1206
+
1207
+ // Cập nhật childData mới
1208
+ const childData = parent?.children ? [...parent.children] : [];
1209
+ const index = childData.findIndex(obj => obj[rowKey] === record[rowKey]);
1210
+ childData.splice(index, 0, ...newRows);
1211
+ const newRowData = {
1212
+ ...parent,
1213
+ children: childData
1214
+ };
1215
+ const newDataSource = (0, _utils.updateArrayByKey)(newData, newRowData, rowKey);
1216
+ triggerChangeData?.(newDataSource);
1217
+ }
1218
+ }
1219
+ }, [defaultValue, focusedCell, mergedFilterKeys, originData, rowKey, rowsFocus, setMergedFilterKeys, table, triggerChangeData]);
1220
+
1221
+ //thêm 1 dòng bên dưới
1222
+ const handleInsertAfter = _react.default.useCallback((item, n) => {
1223
+ const defaultRowValue = (0, _utils.getDefaultValue)(defaultValue);
1224
+
1225
+ // const insertAfter = Math.max(...rowsFocus)
1226
+
1227
+ // const record: RecordType = flattenData(childrenColumnName, dataSource)[insertAfter]
1228
+
1229
+ // const record: any = table.getRowModel().rows.find((it) => it.id === focusedCell?.rowId)?.original
1230
+ const record = table.getRowModel().flatRows.find(it => it.id === focusedCell?.rowId)?.original;
1231
+ if (item.onClick) {
1232
+ item.onClick({
1233
+ toolbar: item
1234
+ });
1235
+ } else {
1236
+ if (!record?.parentId) {
1237
+ // Cập nhật data mới
1238
+ const newData = [...originData];
1239
+ const newRows = Array.from({
1240
+ length: n
1241
+ }).map(() => defaultRowValue ? {
1242
+ ...defaultRowValue,
1243
+ id: undefined,
1244
+ rowId: (0, _utils.newGuid)()
1245
+ } : {
1246
+ id: undefined,
1247
+ rowId: (0, _utils.newGuid)()
1248
+ });
1249
+ const kkk = (0, _utils.getAllRowKey)(newRows) ?? [];
1250
+ const rs = mergedFilterKeys ? [...mergedFilterKeys, ...kkk] : [...kkk];
1251
+ setMergedFilterKeys?.(rs);
1252
+ const index = newData.findIndex(obj => obj[rowKey] === record[rowKey]);
1253
+ newData.splice(index + 1, 0, ...newRows);
1254
+ triggerChangeData?.(newData);
1255
+ } else {
1256
+ const newData = [...originData];
1257
+ const parent = (0, _utils.findItemByKey)(newData, rowKey, record.parentId);
1258
+ const newRows = Array.from({
1259
+ length: n
1260
+ }).map(() => defaultRowValue ? {
1261
+ ...defaultRowValue,
1262
+ id: undefined,
1263
+ rowId: (0, _utils.newGuid)(),
1264
+ parentId: parent.rowId
1265
+ } : {
1266
+ id: undefined,
1267
+ rowId: (0, _utils.newGuid)(),
1268
+ parentId: parent.rowId
1269
+ });
1270
+ const kkk = (0, _utils.getAllRowKey)(newRows) ?? [];
1271
+ const rs = mergedFilterKeys ? [...mergedFilterKeys, ...kkk] : [...kkk];
1272
+ setMergedFilterKeys?.(rs);
1273
+
1274
+ // Cập nhật childData mới
1275
+ const childData = parent?.children ? [...parent.children] : [];
1276
+ const index = childData.findIndex(obj => obj[rowKey] === record[rowKey]);
1277
+ childData.splice(index + 1, 0, ...newRows);
1278
+ const newRowData = {
1279
+ ...parent,
1280
+ children: childData
1281
+ };
1282
+ const newDataSource = (0, _utils.updateArrayByKey)(newData, newRowData, rowKey);
1283
+ triggerChangeData?.(newDataSource);
1284
+ }
1285
+ }
1286
+ }, [defaultValue, table, focusedCell?.rowId, originData, mergedFilterKeys, setMergedFilterKeys, triggerChangeData, rowKey]);
1287
+ const handleInsertChild = _react.default.useCallback(item => {
1288
+ const defaultRowValue = (0, _utils.getDefaultValue)(defaultValue);
1289
+ const rowId = (0, _utils.newGuid)();
1290
+ const record = table.getRowModel().rows.find(it => it.id === focusedCell?.rowId)?.original;
1291
+ if (item.onClick) {
1292
+ item.onClick({
1293
+ toolbar: item
1294
+ });
1295
+ } else {
1296
+ // const newData = [...dataSource]
1297
+ const newData = [...originData];
1298
+ let newElement;
1299
+ if (!record?.children || record?.children && record.children.length === 0) {
1300
+ newElement = {
1301
+ ...record,
1302
+ children: [{
1303
+ ...defaultRowValue,
1304
+ parentId: record?.rowId,
1305
+ rowId
1306
+ }]
1307
+ };
1308
+ } else {
1309
+ newElement = {
1310
+ ...record,
1311
+ children: [...record.children, {
1312
+ ...defaultRowValue,
1313
+ parentId: record.rowId,
1314
+ rowId
1315
+ }]
1316
+ };
1317
+ }
1318
+ const rs = mergedFilterKeys ? [...mergedFilterKeys, rowId] : [rowId];
1319
+ setMergedFilterKeys?.(rs);
1320
+ const newDataSource = (0, _utils.updateArrayByKey)(newData, newElement, rowKey);
1321
+ triggerChangeData?.(newDataSource);
1322
+ }
1323
+ setTimeout(() => {
1324
+ const row = table.getRowModel().rows.find(it => it.id === focusedCell?.rowId);
1325
+ if (row) {
1326
+ setExpanded(old => ({
1327
+ ...old,
1328
+ [row.id]: true
1329
+ }));
1330
+ }
1331
+ }, 10);
1332
+
1333
+ // const hasKey = mergedExpandedKeys.has(key)
1334
+ // if (!hasKey) {
1335
+ // const newExpandedKeys = [...mergedExpandedKeys, key]
1336
+ // setInnerExpandedKeys(newExpandedKeys)
1337
+ // }
1338
+ }, [defaultValue, focusedCell?.rowId, mergedFilterKeys, originData, rowKey, setExpanded, setMergedFilterKeys, table, triggerChangeData]);
1339
+ const handleDeleteRows = _react.default.useCallback(item => {
1340
+ if (item.onClick) {
1341
+ item.onClick({
1342
+ toolbar: item
1343
+ });
1344
+ } else {
1345
+ const filterData = (0, _utils.flattenArray)([...originData]);
1346
+ const rs = filterData.filter(it => !rowsFocus.includes(it[rowKey]));
1347
+ const newDaa = (0, _utils.unFlattenData)(rs);
1348
+ if (commandSettings && commandSettings.confirmDialog) {
1349
+ MySwal.fire({
1350
+ title: t ? t('Confirm') : 'Confirm',
1351
+ text: t ? t('Do you want to delete item?') : 'Do you want to delete item?',
1352
+ // icon: 'warning',
1353
+ allowOutsideClick: false,
1354
+ showCancelButton: true,
1355
+ confirmButtonText: t ? t('Delete') : 'Delete',
1356
+ cancelButtonText: t ? t('Cancel') : 'Cancel',
1357
+ customClass: {
1358
+ confirmButton: 'be-button btn-primary',
1359
+ cancelButton: 'be-button btn-danger ms-1'
1360
+ },
1361
+ buttonsStyling: false
1362
+ }).then(async result => {
1363
+ if (result.value) {
1364
+ triggerChangeData?.([...newDaa]);
1365
+ } else if (result.dismiss === MySwal.DismissReason.cancel) {}
1366
+ });
1367
+ } else {
1368
+ // không hiện dialog
1369
+ triggerChangeData?.([...newDaa]);
1370
+ }
1371
+ }
1372
+ }, [commandSettings, originData, rowKey, rowsFocus, t, triggerChangeData]);
1373
+ const handleDeleteAll = _react.default.useCallback(item => {
1374
+ if (item.onClick) {
1375
+ item.onClick({
1376
+ toolbar: item
1377
+ });
1378
+ } else {
1379
+ if (commandSettings && commandSettings.confirmDialog) {
1380
+ MySwal.fire({
1381
+ title: t ? t('Confirm') : 'Confirm',
1382
+ text: t ? t('Do you want to delete item?') : 'Do you want to delete item?',
1383
+ // icon: 'warning',
1384
+ allowOutsideClick: false,
1385
+ showCancelButton: true,
1386
+ confirmButtonText: t ? t('Delete') : 'Delete',
1387
+ cancelButtonText: t ? t('Cancel') : 'Cancel',
1388
+ customClass: {
1389
+ confirmButton: 'be-button btn-primary',
1390
+ cancelButton: 'be-button btn-danger ms-1'
1391
+ },
1392
+ buttonsStyling: false
1393
+ }).then(async result => {
1394
+ if (result.value) {
1395
+ triggerChangeData?.([]);
1396
+ } else if (result.dismiss === MySwal.DismissReason.cancel) {}
1397
+ });
1398
+ } else {
1399
+ triggerChangeData?.([]);
1400
+ }
1401
+ }
1402
+ }, [commandSettings, t, triggerChangeData]);
1403
+ const handleDeleteContent = () => {
1404
+ if (startCell && endCell) {
1405
+ const tmpData = (0, _utils.flattenArray)([...dataSource]);
1406
+ const rs = tmpData.map((row, index) => {
1407
+ if (!rangeState?.rowRange.includes(row.rowId)) {
1408
+ return row;
1409
+ }
1410
+ const updatedRow = {
1411
+ ...row
1412
+ };
1413
+ for (const colId of rangeState.colRange) {
1414
+ const column = table.getVisibleFlatColumns().find(it => it.id === colId)?.columnDef.meta;
1415
+ const columnIndex = table.getVisibleFlatColumns().findIndex(it => it.id === colId);
1416
+ if ((0, _utils.isEditable)(column, row)) {
1417
+ updatedRow[colId] = '';
1418
+ handleCellChange({
1419
+ key: row[rowKey],
1420
+ field: column.field ?? column.dataIndex,
1421
+ record: updatedRow,
1422
+ prevState: row[column.field],
1423
+ newState: '',
1424
+ option: '',
1425
+ indexCol: columnIndex,
1426
+ indexRow: index,
1427
+ type: 'blur'
1428
+ });
1429
+ }
1430
+ }
1431
+ return updatedRow;
1432
+ });
1433
+ const newData = (0, _utils.unFlattenData)(rs);
1434
+ triggerChangeData?.([...newData]);
1435
+ }
1436
+ };
1437
+ const toolbarItemsBottom = _react.default.useMemo(() => {
1438
+ if (!rowsFocus || rowsFocus.length === 0) {
1439
+ return toolbarItems?.filter(it => it.position === 'Bottom' && it.visible !== false && it.key !== 'DUPLICATE' && it.key !== 'INSERT_BEFORE' && it.key !== 'INSERT_AFTER' && it.key !== 'DELETE_ROWS' && it.key !== 'INSERT_CHILDREN').map(item => {
1440
+ if (item.key === 'ADD') {
1441
+ return {
1442
+ ...item,
1443
+ template: () => {
1444
+ return /*#__PURE__*/_react.default.createElement(_react.Fragment, null, item.key === 'ADD' && /*#__PURE__*/_react.default.createElement("div", {
1445
+ className: (0, _classnames.default)(`be-toolbar-item`, item?.className)
1446
+ }, /*#__PURE__*/_react.default.createElement(_antd.Dropdown.Button, {
1447
+ overlayClassName: 'be-popup-container',
1448
+ trigger: ['click'],
1449
+ style: {
1450
+ color: '#28c76f',
1451
+ borderColor: '#28c76f'
1452
+ },
1453
+ className: 'toolbar-button toolbar-dropdown-button',
1454
+ menu: {
1455
+ items: itemsAdd,
1456
+ onClick: e => handleAddMulti(item, Number(e.key))
1457
+ }
1458
+ }, /*#__PURE__*/_react.default.createElement("span", {
1459
+ style: {
1460
+ color: '#28c76f'
1461
+ },
1462
+ onClick: () => handleAddMulti(item, 1)
1463
+ }, item.label ? t ? t(item.label) : item.label : t ? t('Add item') : 'Add item'))));
1464
+ }
1465
+ };
1466
+ }
1467
+ if (item.key === 'DELETE') {
1468
+ return {
1469
+ ...item,
1470
+ template: () => {
1471
+ return /*#__PURE__*/_react.default.createElement("div", {
1472
+ className: (0, _classnames.default)(`be-toolbar-item`, item?.className)
1473
+ }, /*#__PURE__*/_react.default.createElement(_antd.Button, {
1474
+ style: {
1475
+ color: '#eb4619',
1476
+ borderColor: '#eb4619'
1477
+ },
1478
+ variant: 'outlined',
1479
+ onClick: () => handleDeleteAll(item),
1480
+ className: "d-flex toolbar-button"
1481
+ }, item.label ? t ? t(item.label) : item.label : t ? t('Delete all item') : 'Delete all item'));
1482
+ }
1483
+ };
1484
+ }
1485
+ return {
1486
+ ...item
1487
+ };
1488
+ });
1489
+ }
1490
+ return toolbarItems?.filter(it => it.position === 'Bottom' && it.visible !== false).map(item => {
1491
+ if (item.key === 'ADD') {
1492
+ return {
1493
+ ...item,
1494
+ template: () => {
1495
+ return /*#__PURE__*/_react.default.createElement(_react.Fragment, null, item.key === 'ADD' && /*#__PURE__*/_react.default.createElement("div", {
1496
+ className: (0, _classnames.default)(`be-toolbar-item`, item?.className)
1497
+ }, /*#__PURE__*/_react.default.createElement(_antd.Dropdown.Button, {
1498
+ overlayClassName: 'be-popup-container',
1499
+ style: {
1500
+ color: '#28c76f',
1501
+ borderColor: '#28c76f'
1502
+ },
1503
+ className: 'toolbar-button toolbar-dropdown-button',
1504
+ menu: {
1505
+ items: itemsAdd,
1506
+ onClick: e => handleAddMulti(item, Number(e.key))
1507
+ }
1508
+ }, /*#__PURE__*/_react.default.createElement("span", {
1509
+ style: {
1510
+ color: '#28c76f'
1511
+ },
1512
+ onClick: () => handleAddMulti(item, 1)
1513
+ }, item.label ? t ? t(item.label) : item.label : t ? t('Add item') : 'Add item'))));
1514
+ }
1515
+ };
1516
+ }
1517
+ if (item.key === 'DUPLICATE') {
1518
+ return {
1519
+ ...item,
1520
+ template: () => {
1521
+ return /*#__PURE__*/_react.default.createElement(_react.Fragment, null, item.key === 'DUPLICATE' && item.visible !== false && rowsFocus.length > 0 && /*#__PURE__*/_react.default.createElement("div", {
1522
+ className: (0, _classnames.default)(`be-toolbar-item`, item?.className)
1523
+ }, /*#__PURE__*/_react.default.createElement(_antd.Button, {
1524
+ style: {
1525
+ color: '#28c76f',
1526
+ borderColor: '#28c76f'
1527
+ },
1528
+ variant: 'outlined',
1529
+ onClick: handleDuplicate,
1530
+ className: "d-flex toolbar-button"
1531
+ }, item.label ? t ? t(item.label) : item.label : t ? t('Duplicate') : 'Duplicate')));
1532
+ }
1533
+ };
1534
+ }
1535
+ if (item.key === 'INSERT_BEFORE') {
1536
+ return {
1537
+ ...item,
1538
+ template: () => {
1539
+ return /*#__PURE__*/_react.default.createElement(_react.Fragment, null, /*#__PURE__*/_react.default.createElement("div", {
1540
+ className: (0, _classnames.default)(`be-toolbar-item`, item?.className)
1541
+ }, /*#__PURE__*/_react.default.createElement(_antd.Dropdown.Button, {
1542
+ overlayClassName: 'be-popup-container',
1543
+ style: {
1544
+ color: '#28c76f',
1545
+ borderColor: '#28c76f'
1546
+ },
1547
+ className: 'toolbar-button toolbar-dropdown-button',
1548
+ menu: {
1549
+ items: itemsAdd,
1550
+ onClick: e => handleInsertBefore(item, Number(e.key))
1551
+ }
1552
+ }, /*#__PURE__*/_react.default.createElement("span", {
1553
+ style: {
1554
+ color: '#28c76f'
1555
+ },
1556
+ onClick: () => handleInsertBefore(item, 1)
1557
+ }, item.label ? t ? t(item.label) : item.label : t ? t('Insert item before') : 'Insert item before'))));
1558
+ }
1559
+ };
1560
+ }
1561
+ if (item.key === 'INSERT_AFTER') {
1562
+ return {
1563
+ ...item,
1564
+ template: () => {
1565
+ return /*#__PURE__*/_react.default.createElement(_react.Fragment, null, /*#__PURE__*/_react.default.createElement("div", {
1566
+ className: (0, _classnames.default)(`be-toolbar-item`, item?.className)
1567
+ }, /*#__PURE__*/_react.default.createElement(_antd.Dropdown.Button, {
1568
+ overlayClassName: 'be-popup-container',
1569
+ style: {
1570
+ color: '#28c76f',
1571
+ borderColor: '#28c76f'
1572
+ },
1573
+ className: 'toolbar-button toolbar-dropdown-button',
1574
+ menu: {
1575
+ items: itemsAdd,
1576
+ onClick: e => handleInsertAfter(item, Number(e.key))
1577
+ }
1578
+ }, /*#__PURE__*/_react.default.createElement("span", {
1579
+ style: {
1580
+ color: '#28c76f'
1581
+ },
1582
+ onClick: () => handleInsertAfter(item, 1)
1583
+ }, item.label ? t ? t(item.label) : item.label : t ? t('Insert item after') : 'Insert item after'))));
1584
+ }
1585
+ };
1586
+ }
1587
+ if (item.key === 'INSERT_CHILDREN') {
1588
+ return {
1589
+ ...item,
1590
+ template: () => {
1591
+ return /*#__PURE__*/_react.default.createElement(_react.Fragment, null, /*#__PURE__*/_react.default.createElement("div", {
1592
+ className: (0, _classnames.default)(`be-toolbar-item`, item?.className)
1593
+ }, /*#__PURE__*/_react.default.createElement(_antd.Button, {
1594
+ style: {
1595
+ color: '#28c76f',
1596
+ borderColor: '#28c76f'
1597
+ },
1598
+ variant: 'outlined',
1599
+ onClick: () => handleInsertChild(item),
1600
+ className: "d-flex toolbar-button"
1601
+ }, item.label ? t ? t(item.label) : item.label : t ? t('Insert item children') : 'Insert item children')));
1602
+ }
1603
+ };
1604
+ }
1605
+ if (item.key === 'DELETE') {
1606
+ return {
1607
+ ...item,
1608
+ template: () => {
1609
+ return /*#__PURE__*/_react.default.createElement("div", {
1610
+ className: (0, _classnames.default)(`be-toolbar-item`, item?.className)
1611
+ }, /*#__PURE__*/_react.default.createElement(_antd.Button, {
1612
+ style: {
1613
+ color: '#eb4619',
1614
+ borderColor: '#eb4619'
1615
+ },
1616
+ variant: 'outlined',
1617
+ onClick: handleDeleteAll,
1618
+ className: "d-flex toolbar-button"
1619
+ }, item.label ? t ? t(item.label) : item.label : t ? t('Delete all item') : 'Delete all item'));
1620
+ }
1621
+ };
1622
+ }
1623
+ if (item.key === 'DELETE_ROWS') {
1624
+ return {
1625
+ ...item,
1626
+ template: () => {
1627
+ return /*#__PURE__*/_react.default.createElement("div", {
1628
+ className: (0, _classnames.default)(`be-toolbar-item`, item?.className)
1629
+ }, /*#__PURE__*/_react.default.createElement(_antd.Button, {
1630
+ style: {
1631
+ color: '#eb4619',
1632
+ borderColor: '#eb4619'
1633
+ },
1634
+ variant: 'outlined',
1635
+ onClick: () => handleDeleteRows(item),
1636
+ className: "d-flex toolbar-button"
1637
+ }, t ? `${t('Delete')} ${rowsFocus.length} ${t('row')}` : `Delete ${rowsFocus.length} item`));
1638
+ }
1639
+ };
1640
+ }
1641
+ return {
1642
+ ...item
1643
+ };
1644
+ });
1645
+ }, [handleAddMulti, handleDeleteAll, handleDeleteRows, handleDuplicate, handleInsertAfter, handleInsertBefore, handleInsertChild, itemsAdd, rowsFocus, t, toolbarItems]);
1646
+ const triggerCommandClick = args => {
1647
+ const {
1648
+ id: idCommand,
1649
+ rowId,
1650
+ rowData,
1651
+ index
1652
+ } = args;
1653
+ const tmpData = [...dataSource];
1654
+ if (idCommand === 'DELETE') {
1655
+ // bật modal confirm
1656
+ if (commandSettings && commandSettings.confirmDialog) {
1657
+ MySwal.fire({
1658
+ title: t ? t('Confirm') : 'Confirm',
1659
+ text: t ? t('Do you want to delete item?') : 'Do you want to delete item?',
1660
+ // icon: 'warning',
1661
+ allowOutsideClick: false,
1662
+ showCancelButton: true,
1663
+ confirmButtonText: t ? t('Delete') : 'Delete',
1664
+ cancelButtonText: t ? t('Cancel') : 'Cancel',
1665
+ customClass: {
1666
+ confirmButton: 'be-button btn-primary',
1667
+ cancelButton: 'be-button btn-danger ms-1'
1668
+ },
1669
+ buttonsStyling: false
1670
+ }).then(async result => {
1671
+ if (result.value) {
1672
+ if (!commandSettings || commandSettings && commandSettings.client !== false) {
1673
+ // client
1674
+
1675
+ // kiểm tra dòng hiện tại có parent
1676
+
1677
+ let newData = [];
1678
+ if (rowData?.parentId) {
1679
+ const parent = (0, _utils.findItemByKey)(tmpData, rowKey, rowData.parentId);
1680
+ const childData = parent?.children ? [...parent.children] : [];
1681
+ const findIndex = childData.findIndex(obj => obj[rowKey] === rowData[rowKey]);
1682
+ childData.splice(Number(findIndex), 1);
1683
+ const newRowData = {
1684
+ ...parent,
1685
+ children: childData
1686
+ };
1687
+ // const newDataSource = updateArrayByKey(tmpData, newRowData, rowKey as string)
1688
+ newData = (0, _utils.updateArrayByKey)(tmpData, newRowData, rowKey);
1689
+ } else {
1690
+ tmpData.splice(Number(index), 1);
1691
+ newData = [...tmpData];
1692
+ }
1693
+ if (commandClick) {
1694
+ commandClick({
1695
+ id: idCommand,
1696
+ rowId: rowData.rowId,
1697
+ rowData,
1698
+ index,
1699
+ rows: [...newData]
1700
+ });
1701
+ }
1702
+ } else {
1703
+ // server ~~ không làm gì
1704
+ if (commandClick) {
1705
+ commandClick({
1706
+ id: idCommand,
1707
+ rowId: rowData.rowId,
1708
+ rowData,
1709
+ index,
1710
+ rows: [...originData]
1711
+ });
1712
+ }
1713
+ }
1714
+ } else if (result.dismiss === MySwal.DismissReason.cancel) {}
1715
+ });
1716
+ } else {
1717
+ // -------------------
1718
+
1719
+ if (!commandSettings || commandSettings && commandSettings.client !== false) {
1720
+ // client
1721
+
1722
+ let newData2 = [];
1723
+ if (rowData?.parentId) {
1724
+ const parent = (0, _utils.findItemByKey)(originData, rowKey, rowData.parentId);
1725
+ const childData = parent?.children ? [...parent.children] : [];
1726
+ const findIndex = childData.findIndex(obj => obj[rowKey] === rowData[rowKey]);
1727
+ childData.splice(Number(findIndex), 1);
1728
+ const newRowData = {
1729
+ ...parent,
1730
+ children: childData
1731
+ };
1732
+ newData2 = (0, _utils.updateArrayByKey)(tmpData, newRowData, rowKey);
1733
+ } else {
1734
+ tmpData.splice(Number(index), 1);
1735
+ newData2 = [...tmpData];
1736
+ }
1737
+ if (commandClick) {
1738
+ commandClick({
1739
+ id: idCommand,
1740
+ rowId,
1741
+ rowData,
1742
+ index,
1743
+ rows: [...newData2]
1744
+ });
1745
+ }
1746
+ } else {
1747
+ // server
1748
+ if (commandClick) {
1749
+ commandClick({
1750
+ id: idCommand,
1751
+ rowId,
1752
+ rowData,
1753
+ index,
1754
+ rows: [...originData]
1755
+ });
1756
+ }
1757
+ }
1758
+ }
1759
+ } else {
1760
+ if (commandClick) {
1761
+ commandClick({
1762
+ ...args,
1763
+ rows: originData
1764
+ });
1765
+ }
1766
+ }
1767
+ };
1768
+ const triggerContextMenuClick = args => {
1769
+ if (args.item?.parentKey && args.item.parentKey === 'INSERT_BEFORE') {
1770
+ if (args.item.key === 'INSERT_BEFORE_ADV') {
1771
+ // mở Modal
1772
+
1773
+ // setOpenModalAddRow((prev) => (
1774
+ // {
1775
+ // ...prev,
1776
+ // open: true,
1777
+ // type: 'INSERT_BEFORE'
1778
+ // }
1779
+ // ))
1780
+ } else {
1781
+ handleInsertBefore(args.item, args.item.row);
1782
+ }
1783
+ return;
1784
+ }
1785
+ if (args.item?.parentKey && args.item.parentKey === 'INSERT_AFTER') {
1786
+ if (args.item.key === 'INSERT_AFTER_ADV') {
1787
+
1788
+ // setOpenModalAddRow((prev) => (
1789
+ // {
1790
+ // ...prev,
1791
+ // open: true,
1792
+ // type: 'INSERT_AFTER'
1793
+ // }
1794
+ // ))
1795
+ } else {
1796
+ handleInsertAfter(args.item, args.item.row);
1797
+ }
1798
+ return;
1799
+ }
1800
+ if (args.item.key === 'INSERT_CHILDREN') {
1801
+ handleInsertChild(args.item);
1802
+ return;
1803
+ }
1804
+ if (args.item.key === 'DELETE_ROWS') {
1805
+ handleDeleteRows(args.item);
1806
+ return;
1807
+ }
1808
+ if (args.item.key === 'DELETE_CONTENT') {
1809
+ handleDeleteContent();
1810
+ return;
1811
+ }
1812
+ contextMenuClick?.(args);
1813
+ };
1814
+ const handleCellClick = (rowNumber, record, column, rowId, cellValue) => {
1815
+ const cellClickCallback = newOptions => {
1816
+ if (newOptions) {
1817
+ const newElem = {
1818
+ ...column,
1819
+ editSelectSettings: {
1820
+ ...(column?.editSelectSettings ? {
1821
+ ...column?.editSelectSettings
1822
+ } : {}),
1823
+ options: newOptions
1824
+ }
1825
+ };
1826
+ const rrr = (0, _utils.updateArrayByKey)([...propsColumns], newElem, 'field');
1827
+ triggerChangeColumns?.(rrr, [], "cellClick");
1828
+ }
1829
+ };
1830
+ if (onCellClick) {
1831
+ onCellClick({
1832
+ index: rowNumber,
1833
+ rowId,
1834
+ cellValue,
1835
+ type: "Editing",
1836
+ field: column.field,
1837
+ rowData: record
1838
+ }, cellClickCallback);
1839
+ }
1840
+ };
1841
+ const handleOnGroup = value => {
1842
+ triggerGroupColumns?.(value);
1843
+ };
1844
+ const handleCollapseAllGroup = () => {
1845
+ setExpanded({});
1846
+ };
1847
+ const handleExpandAllGroup = () => {
1848
+ const allKeys = (0, _utils2.findAllChildrenKeys2)(dataSource, rowKey, 'children');
1849
+ setExpanded((0, _utils2.convertToObjTrue)(allKeys));
1850
+ };
1851
+ const groupToolbar = () => {
1852
+ return /*#__PURE__*/_react.default.createElement("div", {
1853
+ style: {
1854
+ display: 'flex',
1855
+ gap: '10px',
1856
+ marginRight: 10
1857
+ }
1858
+ }, groupSetting?.showGroupIcon !== false && /*#__PURE__*/_react.default.createElement(_ColumnsGroup.ColumnsGroup, {
1859
+ t: t
1860
+ // defaultGroupColumns={['name']}
1861
+ ,
1862
+ unClearableLevel: groupSetting?.unClearableLevel
1863
+ // unClearableLevel={2}
1864
+ ,
1865
+ columns: propsColumns ? (0, _utils2.flatColumns2)(propsColumns) : [],
1866
+ columnsGrouped: groupColumns,
1867
+ onSubmit: handleOnGroup
1868
+ }), /*#__PURE__*/_react.default.createElement(_react.default.Fragment, null, !(0, _utils2.isObjEmpty)(expanded) ? /*#__PURE__*/_react.default.createElement(_becoxyIcons.Collapse2, {
1869
+ fontSize: 16,
1870
+ color: '#555555',
1871
+ onClick: handleCollapseAllGroup
1872
+ }) : /*#__PURE__*/_react.default.createElement(_becoxyIcons.Expand2, {
1873
+ fontSize: 16,
1874
+ color: '#555555',
1875
+ onClick: handleExpandAllGroup
1876
+ })));
1877
+ };
1878
+ return /*#__PURE__*/_react.default.createElement("div", {
1879
+ ref: containerRef,
1880
+ id: id
1881
+ }, (showToolbar !== false || fullScreen !== false || showColumnChoose || title) && /*#__PURE__*/_react.default.createElement("div", {
1882
+ ref: topToolbarRef,
1883
+ className: (0, _classnames.default)(`${prefix}-grid-top-toolbar`, {})
1884
+ }, /*#__PURE__*/_react.default.createElement("div", {
1885
+ style: {
1886
+ textAlign: 'center'
1887
+ }
1888
+ }, typeof title === 'function' ? title?.(originData) : title), /*#__PURE__*/_react.default.createElement("div", {
1889
+ style: {
1890
+ display: 'flex',
1891
+ justifyContent: 'space-between',
1892
+ alignItems: 'center',
1893
+ gap: '.75rem'
1894
+ }
1895
+ }, groupToolbar(), /*#__PURE__*/_react.default.createElement("div", {
1896
+ style: {
1897
+ flex: 1,
1898
+ overflow: 'hidden'
1899
+ }
1900
+ }, /*#__PURE__*/_react.default.createElement(_rcMasterUi.Toolbar, {
1901
+ items: (toolbarItems ?? []).filter(it => it.position !== 'Bottom'),
1902
+ mode: 'scroll'
1903
+ })), /*#__PURE__*/_react.default.createElement("div", {
1904
+ style: {
1905
+ display: 'flex',
1906
+ justifyContent: 'space-between',
1907
+ alignItems: 'center',
1908
+ gap: '.75rem'
1909
+ }
1910
+ }, pagination && pagination.onChange && pagination?.position && pagination?.position[0] === 'topRight' && /*#__PURE__*/_react.default.createElement(_pagination.default, (0, _extends2.default)({
1911
+ showSizeChanger: true,
1912
+ responsive: true,
1913
+ size: 'small',
1914
+ rootClassName: 'top-pagination',
1915
+ showTotal: (total, range) =>
1916
+ // @ts-ignore
1917
+ `${range[0]}-${range[1]} / ${total} ${t ? t(pagination?.locale?.items ?? 'items') : 'items'}`
1918
+ }, pagination)), typeof actionTemplate === 'function' ? actionTemplate() : actionTemplate, fullScreen !== false && (isFullScreen ? /*#__PURE__*/_react.default.createElement(_becoxyIcons.Minimize, {
1919
+ fontSize: 16,
1920
+ onClick: () => {
1921
+ setIsFullScreen(!isFullScreen);
1922
+ },
1923
+ "data-tooltip-id": `${id}-tooltip-content`,
1924
+ "data-tooltip-content": t ? t('Minimized') : 'Minimized'
1925
+ }) : /*#__PURE__*/_react.default.createElement(_becoxyIcons.Maximize, {
1926
+ fontSize: 16,
1927
+ onClick: () => {
1928
+ setIsFullScreen(!isFullScreen);
1929
+ },
1930
+ "data-tooltip-id": `${id}-tooltip-content`,
1931
+ "data-tooltip-content": t ? t('Full screen') : 'Full screen'
1932
+ })), showColumnChoose && /*#__PURE__*/_react.default.createElement(_ColumnsChoose.ColumnsChoose, {
1933
+ columns: columns,
1934
+ originColumns: propsColumns,
1935
+ t: t,
1936
+ columnsGroup: groupColumns,
1937
+ triggerChangeColumns: triggerChangeColumns,
1938
+ columnHidden: columnHidden
1939
+ })))), /*#__PURE__*/_react.default.createElement("form", {
1940
+ onSubmit: handleSubmit(onSubmit)
1941
+ }, /*#__PURE__*/_react.default.createElement(_useContext.TableContext.Provider, {
1942
+ value: {
1943
+ t,
1944
+ isDataTree,
1945
+ locale,
1946
+ prefix,
1947
+ id,
1948
+ rowKey,
1949
+ format,
1950
+ expandable,
1951
+ expanded,
1952
+ setExpanded,
1953
+ dataSource,
1954
+ originData,
1955
+ wrapSettings,
1956
+ recordDoubleClick,
1957
+ selectionSettings,
1958
+ isSelectionChange,
1959
+ setIsSelectionChange,
1960
+ // onContextMenu,
1961
+ setSorterChange,
1962
+ setFilterChange,
1963
+ rangeState,
1964
+ setRangeState,
1965
+ rangePasteState,
1966
+ setRangePasteState,
1967
+ focusedCell,
1968
+ setFocusedCell,
1969
+ startCell,
1970
+ editingKey,
1971
+ endCell,
1972
+ isSelecting,
1973
+ isPasting,
1974
+ startPasteCell,
1975
+ endPasteCell,
1976
+ setEditingKey,
1977
+ setEndCell,
1978
+ setIsSelecting,
1979
+ setStartCell,
1980
+ setIsPasting,
1981
+ setEndPasteCell,
1982
+ setStartPasteCell,
1983
+ //
1984
+ control,
1985
+ // trigger,
1986
+ errors,
1987
+ getValues,
1988
+ setValue,
1989
+ reset,
1990
+ handleCellChange,
1991
+ handleCellChangeAndAddRow,
1992
+ triggerPaste,
1993
+ handleDeleteContent,
1994
+ handleAddMulti,
1995
+ dataErrors,
1996
+ windowSize,
1997
+ handleCellClick,
1998
+ pagination,
1999
+ rowClassName,
2000
+ rowEditable,
2001
+ onRowStyles,
2002
+ dataSourceFilter,
2003
+ groupColumns
2004
+ }
2005
+ }, /*#__PURE__*/_react.default.createElement(_TableWrapper.default, {
2006
+ contextMenuItems: contextMenuItems,
2007
+ height: tableHeight,
2008
+ minHeight: minHeight,
2009
+ id: id,
2010
+ prefix: prefix,
2011
+ table: table,
2012
+ tableContainerRef: tableContainerRef,
2013
+ commandClick: triggerCommandClick,
2014
+ contextMenuClick: triggerContextMenuClick,
2015
+ contextMenuHidden: contextMenuHidden,
2016
+ contextMenuOpen: contextMenuOpen,
2017
+ editAble: editAble,
2018
+ showEmptyText: showEmptyText,
2019
+ summary: summary,
2020
+ dataSource: dataSource,
2021
+ infiniteScroll: infiniteScroll,
2022
+ next: next,
2023
+ loading: loading,
2024
+ columnVirtualizer: columnVirtualizer,
2025
+ virtualPaddingLeft: virtualPaddingLeft,
2026
+ virtualPaddingRight: virtualPaddingRight,
2027
+ fixedLeftColumns: fixedLeftColumns,
2028
+ fixedRightColumns: fixedRightColumns
2029
+ }))), /*#__PURE__*/_react.default.createElement("div", {
2030
+ ref: bottomToolbarRef
2031
+ }, toolbarItemsBottom && toolbarItemsBottom.length > 0 && /*#__PURE__*/_react.default.createElement("div", {
2032
+ className: (0, _classnames.default)('ui-rc-toolbar-bottom', {
2033
+ 'ui-rc-toolbar-bottom_border-bottom': !pagination || infiniteScroll
2034
+ })
2035
+ // style={{ border: '0 1px 1px 1px solid #e0e0e0' }}
2036
+ // style={{
2037
+ // borderBottom: '1px solid #e0e0e0',
2038
+ // borderRight: '1px solid #e0e0e0',
2039
+ // borderLeft: '1px solid #e0e0e0'
2040
+ // }}
2041
+ }, /*#__PURE__*/_react.default.createElement(_rcMasterUi.Toolbar, {
2042
+ style: {
2043
+ width: '100%'
2044
+ },
2045
+ items: toolbarItemsBottom ?? [],
2046
+ mode: 'scroll',
2047
+ onClick: ({}) => {
2048
+ setEditingKey('');
2049
+ }
2050
+ })), pagination && !infiniteScroll && /*#__PURE__*/_react.default.createElement(_pagination.default, (0, _extends2.default)({}, pagination, {
2051
+ rootClassName: 'pagination-template',
2052
+ showSizeChanger: true,
2053
+ responsive: true,
2054
+ size: 'small',
2055
+ total: pagination.total,
2056
+ pageSize: pagination.onChange ? pagination?.pageSize : table.getState().pagination.pageSize,
2057
+ pageSizeOptions: [20, 50, 100, 1000, 10000],
2058
+ onChange: (page, pageSize) => {
2059
+ if (pagination.onChange) {
2060
+ pagination.onChange(page, pageSize);
2061
+ } else {
2062
+ table.setPageIndex(page - 1);
2063
+ table.setPageSize(pageSize);
2064
+ }
2065
+ },
2066
+ showTotal: (total, range) => `${(0, _reactNumericComponent.numericFormatter)((range[0] ?? 0).toString(), {
2067
+ thousandSeparator: '.'
2068
+ })}-${(0, _reactNumericComponent.numericFormatter)((range[1] ?? 0).toString(), {
2069
+ thousandSeparator: '.'
2070
+ })} / ${(0, _reactNumericComponent.numericFormatter)((total ?? 0).toString(), {
2071
+ thousandSeparator: '.'
2072
+ })} items`
2073
+ }))));
2074
+ };
2075
+ var _default = exports.default = TableContainerEdit;