@mui/x-data-grid-premium 5.11.0

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 (199) hide show
  1. package/CHANGELOG.md +4052 -0
  2. package/DataGridPremium/DataGridPremium.d.ts +9 -0
  3. package/DataGridPremium/DataGridPremium.js +986 -0
  4. package/DataGridPremium/index.d.ts +2 -0
  5. package/DataGridPremium/index.js +2 -0
  6. package/DataGridPremium/package.json +6 -0
  7. package/DataGridPremium/useDataGridPremiumComponent.d.ts +4 -0
  8. package/DataGridPremium/useDataGridPremiumComponent.js +78 -0
  9. package/DataGridPremium/useDataGridPremiumProps.d.ts +6 -0
  10. package/DataGridPremium/useDataGridPremiumProps.js +37 -0
  11. package/LICENSE +12 -0
  12. package/README.md +31 -0
  13. package/components/GridExcelExportMenuItem.d.ts +9 -0
  14. package/components/GridExcelExportMenuItem.js +32 -0
  15. package/components/GridGroupingColumnLeafCell.d.ts +4 -0
  16. package/components/GridGroupingColumnLeafCell.js +22 -0
  17. package/components/GridGroupingCriteriaCell.d.ts +7 -0
  18. package/components/GridGroupingCriteriaCell.js +78 -0
  19. package/components/GridRowGroupableColumnMenuItems.d.ts +11 -0
  20. package/components/GridRowGroupableColumnMenuItems.js +63 -0
  21. package/components/GridRowGroupingColumnMenuItems.d.ts +11 -0
  22. package/components/GridRowGroupingColumnMenuItems.js +58 -0
  23. package/components/index.d.ts +1 -0
  24. package/components/index.js +1 -0
  25. package/components/package.json +6 -0
  26. package/hooks/features/export/gridExcelExportInterface.d.ts +58 -0
  27. package/hooks/features/export/gridExcelExportInterface.js +1 -0
  28. package/hooks/features/export/index.d.ts +1 -0
  29. package/hooks/features/export/index.js +1 -0
  30. package/hooks/features/export/serializer/excelSerializer.d.ts +14 -0
  31. package/hooks/features/export/serializer/excelSerializer.js +218 -0
  32. package/hooks/features/export/useGridExcelExport.d.ts +10 -0
  33. package/hooks/features/export/useGridExcelExport.js +77 -0
  34. package/hooks/features/index.d.ts +2 -0
  35. package/hooks/features/index.js +3 -0
  36. package/hooks/features/rowGrouping/createGroupingColDef.d.ts +42 -0
  37. package/hooks/features/rowGrouping/createGroupingColDef.js +318 -0
  38. package/hooks/features/rowGrouping/gridRowGroupingInterfaces.d.ts +37 -0
  39. package/hooks/features/rowGrouping/gridRowGroupingInterfaces.js +1 -0
  40. package/hooks/features/rowGrouping/gridRowGroupingSelector.d.ts +4 -0
  41. package/hooks/features/rowGrouping/gridRowGroupingSelector.js +5 -0
  42. package/hooks/features/rowGrouping/gridRowGroupingUtils.d.ts +27 -0
  43. package/hooks/features/rowGrouping/gridRowGroupingUtils.js +139 -0
  44. package/hooks/features/rowGrouping/index.d.ts +3 -0
  45. package/hooks/features/rowGrouping/index.js +3 -0
  46. package/hooks/features/rowGrouping/useGridRowGrouping.d.ts +11 -0
  47. package/hooks/features/rowGrouping/useGridRowGrouping.js +200 -0
  48. package/hooks/features/rowGrouping/useGridRowGroupingPreProcessors.d.ts +4 -0
  49. package/hooks/features/rowGrouping/useGridRowGroupingPreProcessors.js +201 -0
  50. package/hooks/index.d.ts +2 -0
  51. package/hooks/index.js +3 -0
  52. package/hooks/package.json +6 -0
  53. package/hooks/utils/index.d.ts +1 -0
  54. package/hooks/utils/index.js +1 -0
  55. package/hooks/utils/useGridApiContext.d.ts +4 -0
  56. package/hooks/utils/useGridApiContext.js +2 -0
  57. package/hooks/utils/useGridApiRef.d.ts +4 -0
  58. package/hooks/utils/useGridApiRef.js +2 -0
  59. package/hooks/utils/useGridRootProps.d.ts +2 -0
  60. package/hooks/utils/useGridRootProps.js +2 -0
  61. package/hooks/utils/useKeepGroupedColumnsHidden.d.ts +12 -0
  62. package/hooks/utils/useKeepGroupedColumnsHidden.js +50 -0
  63. package/index.d.ts +22 -0
  64. package/index.js +25 -0
  65. package/legacy/DataGridPremium/DataGridPremium.js +986 -0
  66. package/legacy/DataGridPremium/index.js +2 -0
  67. package/legacy/DataGridPremium/useDataGridPremiumComponent.js +78 -0
  68. package/legacy/DataGridPremium/useDataGridPremiumProps.js +46 -0
  69. package/legacy/components/GridExcelExportMenuItem.js +30 -0
  70. package/legacy/components/GridGroupingColumnLeafCell.js +20 -0
  71. package/legacy/components/GridGroupingCriteriaCell.js +74 -0
  72. package/legacy/components/GridRowGroupableColumnMenuItems.js +61 -0
  73. package/legacy/components/GridRowGroupingColumnMenuItems.js +56 -0
  74. package/legacy/components/index.js +1 -0
  75. package/legacy/hooks/features/export/gridExcelExportInterface.js +1 -0
  76. package/legacy/hooks/features/export/index.js +1 -0
  77. package/legacy/hooks/features/export/serializer/excelSerializer.js +260 -0
  78. package/legacy/hooks/features/export/useGridExcelExport.js +111 -0
  79. package/legacy/hooks/features/index.js +3 -0
  80. package/legacy/hooks/features/rowGrouping/createGroupingColDef.js +319 -0
  81. package/legacy/hooks/features/rowGrouping/gridRowGroupingInterfaces.js +1 -0
  82. package/legacy/hooks/features/rowGrouping/gridRowGroupingSelector.js +13 -0
  83. package/legacy/hooks/features/rowGrouping/gridRowGroupingUtils.js +147 -0
  84. package/legacy/hooks/features/rowGrouping/index.js +3 -0
  85. package/legacy/hooks/features/rowGrouping/useGridRowGrouping.js +206 -0
  86. package/legacy/hooks/features/rowGrouping/useGridRowGroupingPreProcessors.js +215 -0
  87. package/legacy/hooks/index.js +3 -0
  88. package/legacy/hooks/utils/index.js +1 -0
  89. package/legacy/hooks/utils/useGridApiContext.js +2 -0
  90. package/legacy/hooks/utils/useGridApiRef.js +2 -0
  91. package/legacy/hooks/utils/useGridRootProps.js +2 -0
  92. package/legacy/hooks/utils/useKeepGroupedColumnsHidden.js +50 -0
  93. package/legacy/index.js +25 -0
  94. package/legacy/models/dataGridPremiumProps.js +1 -0
  95. package/legacy/models/gridApiPremium.js +1 -0
  96. package/legacy/models/gridGroupingValueGetterParams.js +1 -0
  97. package/legacy/models/gridStatePremium.js +1 -0
  98. package/legacy/models/index.js +1 -0
  99. package/legacy/typeOverloads/index.js +1 -0
  100. package/legacy/typeOverloads/modules.js +33 -0
  101. package/legacy/typeOverloads/reexports.js +6 -0
  102. package/legacy/utils/releaseInfo.js +15 -0
  103. package/models/dataGridPremiumProps.d.ts +64 -0
  104. package/models/dataGridPremiumProps.js +1 -0
  105. package/models/gridApiPremium.d.ts +13 -0
  106. package/models/gridApiPremium.js +1 -0
  107. package/models/gridGroupingValueGetterParams.d.ts +31 -0
  108. package/models/gridGroupingValueGetterParams.js +1 -0
  109. package/models/gridStatePremium.d.ts +14 -0
  110. package/models/gridStatePremium.js +1 -0
  111. package/models/index.d.ts +1 -0
  112. package/models/index.js +1 -0
  113. package/models/package.json +6 -0
  114. package/modern/DataGridPremium/DataGridPremium.js +986 -0
  115. package/modern/DataGridPremium/index.js +2 -0
  116. package/modern/DataGridPremium/useDataGridPremiumComponent.js +76 -0
  117. package/modern/DataGridPremium/useDataGridPremiumProps.js +37 -0
  118. package/modern/components/GridExcelExportMenuItem.js +32 -0
  119. package/modern/components/GridGroupingColumnLeafCell.js +20 -0
  120. package/modern/components/GridGroupingCriteriaCell.js +76 -0
  121. package/modern/components/GridRowGroupableColumnMenuItems.js +61 -0
  122. package/modern/components/GridRowGroupingColumnMenuItems.js +56 -0
  123. package/modern/components/index.js +1 -0
  124. package/modern/hooks/features/export/gridExcelExportInterface.js +1 -0
  125. package/modern/hooks/features/export/index.js +1 -0
  126. package/modern/hooks/features/export/serializer/excelSerializer.js +216 -0
  127. package/modern/hooks/features/export/useGridExcelExport.js +73 -0
  128. package/modern/hooks/features/index.js +3 -0
  129. package/modern/hooks/features/rowGrouping/createGroupingColDef.js +302 -0
  130. package/modern/hooks/features/rowGrouping/gridRowGroupingInterfaces.js +1 -0
  131. package/modern/hooks/features/rowGrouping/gridRowGroupingSelector.js +5 -0
  132. package/modern/hooks/features/rowGrouping/gridRowGroupingUtils.js +137 -0
  133. package/modern/hooks/features/rowGrouping/index.js +3 -0
  134. package/modern/hooks/features/rowGrouping/useGridRowGrouping.js +192 -0
  135. package/modern/hooks/features/rowGrouping/useGridRowGroupingPreProcessors.js +201 -0
  136. package/modern/hooks/index.js +3 -0
  137. package/modern/hooks/utils/index.js +1 -0
  138. package/modern/hooks/utils/useGridApiContext.js +2 -0
  139. package/modern/hooks/utils/useGridApiRef.js +2 -0
  140. package/modern/hooks/utils/useGridRootProps.js +2 -0
  141. package/modern/hooks/utils/useKeepGroupedColumnsHidden.js +46 -0
  142. package/modern/index.js +25 -0
  143. package/modern/models/dataGridPremiumProps.js +1 -0
  144. package/modern/models/gridApiPremium.js +1 -0
  145. package/modern/models/gridGroupingValueGetterParams.js +1 -0
  146. package/modern/models/gridStatePremium.js +1 -0
  147. package/modern/models/index.js +1 -0
  148. package/modern/typeOverloads/index.js +1 -0
  149. package/modern/typeOverloads/modules.js +33 -0
  150. package/modern/typeOverloads/reexports.js +6 -0
  151. package/modern/utils/releaseInfo.js +15 -0
  152. package/node/DataGridPremium/DataGridPremium.js +1009 -0
  153. package/node/DataGridPremium/index.js +30 -0
  154. package/node/DataGridPremium/useDataGridPremiumComponent.js +91 -0
  155. package/node/DataGridPremium/useDataGridPremiumProps.js +57 -0
  156. package/node/components/GridExcelExportMenuItem.js +49 -0
  157. package/node/components/GridGroupingColumnLeafCell.js +38 -0
  158. package/node/components/GridGroupingCriteriaCell.js +99 -0
  159. package/node/components/GridRowGroupableColumnMenuItems.js +82 -0
  160. package/node/components/GridRowGroupingColumnMenuItems.js +78 -0
  161. package/node/components/index.js +18 -0
  162. package/node/hooks/features/export/gridExcelExportInterface.js +5 -0
  163. package/node/hooks/features/export/index.js +18 -0
  164. package/node/hooks/features/export/serializer/excelSerializer.js +233 -0
  165. package/node/hooks/features/export/useGridExcelExport.js +95 -0
  166. package/node/hooks/features/index.js +31 -0
  167. package/node/hooks/features/rowGrouping/createGroupingColDef.js +341 -0
  168. package/node/hooks/features/rowGrouping/gridRowGroupingInterfaces.js +5 -0
  169. package/node/hooks/features/rowGrouping/gridRowGroupingSelector.js +18 -0
  170. package/node/hooks/features/rowGrouping/gridRowGroupingUtils.js +172 -0
  171. package/node/hooks/features/rowGrouping/index.js +51 -0
  172. package/node/hooks/features/rowGrouping/useGridRowGrouping.js +228 -0
  173. package/node/hooks/features/rowGrouping/useGridRowGroupingPreProcessors.js +223 -0
  174. package/node/hooks/index.js +31 -0
  175. package/node/hooks/utils/index.js +18 -0
  176. package/node/hooks/utils/useGridApiContext.js +11 -0
  177. package/node/hooks/utils/useGridApiRef.js +11 -0
  178. package/node/hooks/utils/useGridRootProps.js +11 -0
  179. package/node/hooks/utils/useKeepGroupedColumnsHidden.js +66 -0
  180. package/node/index.js +272 -0
  181. package/node/models/dataGridPremiumProps.js +5 -0
  182. package/node/models/gridApiPremium.js +5 -0
  183. package/node/models/gridGroupingValueGetterParams.js +5 -0
  184. package/node/models/gridStatePremium.js +5 -0
  185. package/node/models/index.js +18 -0
  186. package/node/typeOverloads/index.js +3 -0
  187. package/node/typeOverloads/modules.js +34 -0
  188. package/node/typeOverloads/reexports.js +29 -0
  189. package/node/utils/releaseInfo.js +25 -0
  190. package/package.json +63 -0
  191. package/typeOverloads/index.d.ts +1 -0
  192. package/typeOverloads/index.js +1 -0
  193. package/typeOverloads/modules.d.ts +0 -0
  194. package/typeOverloads/modules.js +33 -0
  195. package/typeOverloads/package.json +6 -0
  196. package/typeOverloads/reexports.d.ts +22 -0
  197. package/typeOverloads/reexports.js +6 -0
  198. package/utils/releaseInfo.d.ts +1 -0
  199. package/utils/releaseInfo.js +15 -0
@@ -0,0 +1,341 @@
1
+ "use strict";
2
+
3
+ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
4
+
5
+ Object.defineProperty(exports, "__esModule", {
6
+ value: true
7
+ });
8
+ exports.createGroupingColDefForOneGroupingCriteria = exports.createGroupingColDefForAllGroupingCriteria = void 0;
9
+
10
+ var _objectWithoutPropertiesLoose2 = _interopRequireDefault(require("@babel/runtime/helpers/objectWithoutPropertiesLoose"));
11
+
12
+ var _extends2 = _interopRequireDefault(require("@babel/runtime/helpers/extends"));
13
+
14
+ var React = _interopRequireWildcard(require("react"));
15
+
16
+ var _xDataGridPro = require("@mui/x-data-grid-pro");
17
+
18
+ var _GridGroupingCriteriaCell = require("../../../components/GridGroupingCriteriaCell");
19
+
20
+ var _GridGroupingColumnLeafCell = require("../../../components/GridGroupingColumnLeafCell");
21
+
22
+ var _gridRowGroupingUtils = require("./gridRowGroupingUtils");
23
+
24
+ var _gridRowGroupingSelector = require("./gridRowGroupingSelector");
25
+
26
+ var _jsxRuntime = require("react/jsx-runtime");
27
+
28
+ const _excluded = ["leafField", "mainGroupingCriteria", "hideDescendantCount"],
29
+ _excluded2 = ["leafField", "mainGroupingCriteria", "hideDescendantCount"];
30
+
31
+ function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function (nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
32
+
33
+ function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
34
+
35
+ const GROUPING_COL_DEF_DEFAULT_PROPERTIES = (0, _extends2.default)({}, _xDataGridPro.GRID_STRING_COL_DEF, {
36
+ disableReorder: true
37
+ });
38
+ const GROUPING_COL_DEF_FORCED_PROPERTIES = {
39
+ type: 'rowGroupByColumnsGroup',
40
+ editable: false,
41
+ groupable: false
42
+ };
43
+ /**
44
+ * When sorting two cells with different grouping criteria, we consider that the cell with the grouping criteria coming first in the model should be displayed below.
45
+ * This can occur when some rows don't have all the fields. In which case we want the rows with the missing field to be displayed above.
46
+ * TODO: Make this index comparator depth invariant, the logic should not be inverted when sorting in the "desc" direction (but the current return format of `sortComparator` does not support this behavior).
47
+ */
48
+
49
+ const groupingFieldIndexComparator = (v1, v2, cellParams1, cellParams2) => {
50
+ const model = (0, _gridRowGroupingSelector.gridRowGroupingSanitizedModelSelector)(cellParams1.api.state, cellParams1.api.instanceId);
51
+ const groupingField1 = cellParams1.rowNode.groupingField;
52
+ const groupingField2 = cellParams2.rowNode.groupingField;
53
+
54
+ if (groupingField1 === groupingField2) {
55
+ return 0;
56
+ }
57
+
58
+ if (groupingField1 == null) {
59
+ return -1;
60
+ }
61
+
62
+ if (groupingField2 == null) {
63
+ return 1;
64
+ }
65
+
66
+ if (model.indexOf(groupingField1) < model.indexOf(groupingField2)) {
67
+ return -1;
68
+ }
69
+
70
+ return 1;
71
+ };
72
+
73
+ const getLeafProperties = leafColDef => {
74
+ var _leafColDef$headerNam, _leafColDef$filterOpe;
75
+
76
+ return {
77
+ headerName: (_leafColDef$headerNam = leafColDef.headerName) != null ? _leafColDef$headerNam : leafColDef.field,
78
+ sortable: leafColDef.sortable,
79
+ filterable: leafColDef.filterable,
80
+ filterOperators: (_leafColDef$filterOpe = leafColDef.filterOperators) == null ? void 0 : _leafColDef$filterOpe.map(operator => (0, _extends2.default)({}, operator, {
81
+ getApplyFilterFn: (filterItem, column) => {
82
+ const originalFn = operator.getApplyFilterFn(filterItem, column);
83
+
84
+ if (!originalFn) {
85
+ return null;
86
+ }
87
+
88
+ return params => {
89
+ // We only want to filter leaves
90
+ if (params.rowNode.groupingField != null) {
91
+ return true;
92
+ }
93
+
94
+ return originalFn(params);
95
+ };
96
+ }
97
+ })),
98
+ sortComparator: (v1, v2, cellParams1, cellParams2) => {
99
+ // We only want to sort the leaves
100
+ if (cellParams1.rowNode.groupingField === null && cellParams2.rowNode.groupingField === null) {
101
+ return leafColDef.sortComparator(v1, v2, cellParams1, cellParams2);
102
+ }
103
+
104
+ return groupingFieldIndexComparator(v1, v2, cellParams1, cellParams2);
105
+ }
106
+ };
107
+ };
108
+
109
+ const getGroupingCriteriaProperties = (groupedByColDef, applyHeaderName) => {
110
+ var _groupedByColDef$filt;
111
+
112
+ const properties = {
113
+ sortable: groupedByColDef.sortable,
114
+ filterable: groupedByColDef.filterable,
115
+ sortComparator: (v1, v2, cellParams1, cellParams2) => {
116
+ // We only want to sort the groups of the current grouping criteria
117
+ if (cellParams1.rowNode.groupingField === groupedByColDef.field && cellParams2.rowNode.groupingField === groupedByColDef.field) {
118
+ return groupedByColDef.sortComparator(v1, v2, cellParams1, cellParams2);
119
+ }
120
+
121
+ return groupingFieldIndexComparator(v1, v2, cellParams1, cellParams2);
122
+ },
123
+ filterOperators: (_groupedByColDef$filt = groupedByColDef.filterOperators) == null ? void 0 : _groupedByColDef$filt.map(operator => (0, _extends2.default)({}, operator, {
124
+ getApplyFilterFn: (filterItem, column) => {
125
+ const originalFn = operator.getApplyFilterFn(filterItem, column);
126
+
127
+ if (!originalFn) {
128
+ return null;
129
+ }
130
+
131
+ return params => {
132
+ // We only want to filter the groups of the current grouping criteria
133
+ if (params.rowNode.groupingField !== groupedByColDef.field) {
134
+ return true;
135
+ }
136
+
137
+ return originalFn(params);
138
+ };
139
+ }
140
+ }))
141
+ };
142
+
143
+ if (applyHeaderName) {
144
+ var _groupedByColDef$head;
145
+
146
+ properties.headerName = (_groupedByColDef$head = groupedByColDef.headerName) != null ? _groupedByColDef$head : groupedByColDef.field;
147
+ }
148
+
149
+ return properties;
150
+ };
151
+
152
+ /**
153
+ * Creates the `GridColDef` for a grouping column that only takes care of a single grouping criteria
154
+ */
155
+ const createGroupingColDefForOneGroupingCriteria = ({
156
+ columnsLookup,
157
+ groupedByColDef,
158
+ groupingCriteria,
159
+ colDefOverride
160
+ }) => {
161
+ var _groupedByColDef$widt, _leafColDef$width;
162
+
163
+ const _ref = colDefOverride != null ? colDefOverride : {},
164
+ {
165
+ leafField,
166
+ mainGroupingCriteria,
167
+ hideDescendantCount
168
+ } = _ref,
169
+ colDefOverrideProperties = (0, _objectWithoutPropertiesLoose2.default)(_ref, _excluded);
170
+
171
+ const leafColDef = leafField ? columnsLookup[leafField] : null; // The properties that do not depend on the presence of a `leafColDef` and that can be overridden by `colDefOverride`
172
+
173
+ const commonProperties = {
174
+ width: Math.max(((_groupedByColDef$widt = groupedByColDef.width) != null ? _groupedByColDef$widt : _xDataGridPro.GRID_STRING_COL_DEF.width) + 40, (_leafColDef$width = leafColDef == null ? void 0 : leafColDef.width) != null ? _leafColDef$width : 0),
175
+ renderCell: params => {
176
+ // Render leaves
177
+ if (params.rowNode.groupingField == null) {
178
+ if (leafColDef) {
179
+ const leafParams = (0, _extends2.default)({}, params.api.getCellParams(params.id, leafField), {
180
+ api: params.api
181
+ });
182
+
183
+ if (leafColDef.renderCell) {
184
+ return leafColDef.renderCell(leafParams);
185
+ }
186
+
187
+ return /*#__PURE__*/(0, _jsxRuntime.jsx)(_GridGroupingColumnLeafCell.GridGroupingColumnLeafCell, (0, _extends2.default)({}, leafParams));
188
+ }
189
+
190
+ return '';
191
+ } // Render current grouping criteria groups
192
+
193
+
194
+ if (params.rowNode.groupingField === groupingCriteria) {
195
+ return /*#__PURE__*/(0, _jsxRuntime.jsx)(_GridGroupingCriteriaCell.GridGroupingCriteriaCell, (0, _extends2.default)({}, params, {
196
+ hideDescendantCount: hideDescendantCount
197
+ }));
198
+ }
199
+
200
+ return '';
201
+ },
202
+ valueGetter: params => {
203
+ if (!params.rowNode) {
204
+ return undefined;
205
+ }
206
+
207
+ if (params.rowNode.groupingField == null) {
208
+ if (leafColDef) {
209
+ return params.api.getCellValue(params.id, leafField);
210
+ }
211
+
212
+ return undefined;
213
+ }
214
+
215
+ if (params.rowNode.groupingField === groupingCriteria) {
216
+ return params.rowNode.groupingKey;
217
+ }
218
+
219
+ return undefined;
220
+ }
221
+ }; // If we have a `mainGroupingCriteria` defined and matching the `groupingCriteria`
222
+ // Then we apply the sorting / filtering on the groups of this column's grouping criteria based on the properties of `groupedByColDef`.
223
+ // It can be useful to define a `leafField` for leaves rendering but still use the grouping criteria for the sorting / filtering
224
+ //
225
+ // If we have a `leafField` defined and matching an existing column
226
+ // Then we apply the sorting / filtering on the leaves based on the properties of `leavesColDef`
227
+ //
228
+ // By default, we apply the sorting / filtering on the groups of this column's grouping criteria based on the properties of `groupedColDef`.
229
+
230
+ let sourceProperties;
231
+
232
+ if (mainGroupingCriteria && mainGroupingCriteria === groupingCriteria) {
233
+ sourceProperties = getGroupingCriteriaProperties(groupedByColDef, true);
234
+ } else if (leafColDef) {
235
+ sourceProperties = getLeafProperties(leafColDef);
236
+ } else {
237
+ sourceProperties = getGroupingCriteriaProperties(groupedByColDef, true);
238
+ } // The properties that can't be overridden with `colDefOverride`
239
+
240
+
241
+ const forcedProperties = (0, _extends2.default)({
242
+ field: (0, _gridRowGroupingUtils.getRowGroupingFieldFromGroupingCriteria)(groupingCriteria)
243
+ }, GROUPING_COL_DEF_FORCED_PROPERTIES);
244
+ return (0, _extends2.default)({}, GROUPING_COL_DEF_DEFAULT_PROPERTIES, commonProperties, sourceProperties, colDefOverrideProperties, forcedProperties);
245
+ };
246
+
247
+ exports.createGroupingColDefForOneGroupingCriteria = createGroupingColDefForOneGroupingCriteria;
248
+
249
+ /**
250
+ * Creates the `GridColDef` for a grouping column that takes care of all the grouping criteria
251
+ */
252
+ const createGroupingColDefForAllGroupingCriteria = ({
253
+ apiRef,
254
+ columnsLookup,
255
+ rowGroupingModel,
256
+ colDefOverride
257
+ }) => {
258
+ var _leafColDef$width2;
259
+
260
+ const _ref2 = colDefOverride != null ? colDefOverride : {},
261
+ {
262
+ leafField,
263
+ mainGroupingCriteria,
264
+ hideDescendantCount
265
+ } = _ref2,
266
+ colDefOverrideProperties = (0, _objectWithoutPropertiesLoose2.default)(_ref2, _excluded2);
267
+
268
+ const leafColDef = leafField ? columnsLookup[leafField] : null; // The properties that do not depend on the presence of a `leafColDef` and that can be overridden by `colDefOverride`
269
+
270
+ const commonProperties = {
271
+ headerName: apiRef.current.getLocaleText('groupingColumnHeaderName'),
272
+ width: Math.max(...rowGroupingModel.map(field => {
273
+ var _columnsLookup$field$;
274
+
275
+ return ((_columnsLookup$field$ = columnsLookup[field].width) != null ? _columnsLookup$field$ : _xDataGridPro.GRID_STRING_COL_DEF.width) + 40;
276
+ }), (_leafColDef$width2 = leafColDef == null ? void 0 : leafColDef.width) != null ? _leafColDef$width2 : 0),
277
+ renderCell: params => {
278
+ // Render the leaves
279
+ if (params.rowNode.groupingField == null) {
280
+ if (leafColDef) {
281
+ const leafParams = (0, _extends2.default)({}, params.api.getCellParams(params.id, leafField), {
282
+ api: params.api
283
+ });
284
+
285
+ if (leafColDef.renderCell) {
286
+ return leafColDef.renderCell(leafParams);
287
+ }
288
+
289
+ return /*#__PURE__*/(0, _jsxRuntime.jsx)(_GridGroupingColumnLeafCell.GridGroupingColumnLeafCell, (0, _extends2.default)({}, leafParams));
290
+ }
291
+
292
+ return '';
293
+ } // Render the groups
294
+
295
+
296
+ return /*#__PURE__*/(0, _jsxRuntime.jsx)(_GridGroupingCriteriaCell.GridGroupingCriteriaCell, (0, _extends2.default)({}, params, {
297
+ hideDescendantCount: hideDescendantCount
298
+ }));
299
+ },
300
+ valueGetter: params => {
301
+ if (!params.rowNode) {
302
+ return undefined;
303
+ }
304
+
305
+ if (params.rowNode.groupingField == null) {
306
+ if (leafColDef) {
307
+ return params.api.getCellValue(params.id, leafField);
308
+ }
309
+
310
+ return undefined;
311
+ }
312
+
313
+ return params.rowNode.groupingKey;
314
+ }
315
+ }; // If we have a `mainGroupingCriteria` defined and matching one of the `orderedGroupedByFields`
316
+ // Then we apply the sorting / filtering on the groups of this column's grouping criteria based on the properties of `columnsLookup[mainGroupingCriteria]`.
317
+ // It can be useful to use another grouping criteria than the top level one for the sorting / filtering
318
+ //
319
+ // If we have a `leafField` defined and matching an existing column
320
+ // Then we apply the sorting / filtering on the leaves based on the properties of `leavesColDef`
321
+ //
322
+ // By default, we apply the sorting / filtering on the groups of the top level grouping criteria based on the properties of `columnsLookup[orderedGroupedByFields[0]]`.
323
+
324
+ let sourceProperties;
325
+
326
+ if (mainGroupingCriteria && rowGroupingModel.includes(mainGroupingCriteria)) {
327
+ sourceProperties = getGroupingCriteriaProperties(columnsLookup[mainGroupingCriteria], true);
328
+ } else if (leafColDef) {
329
+ sourceProperties = getLeafProperties(leafColDef);
330
+ } else {
331
+ sourceProperties = getGroupingCriteriaProperties(columnsLookup[rowGroupingModel[0]], rowGroupingModel.length === 1);
332
+ } // The properties that can't be overridden with `colDefOverride`
333
+
334
+
335
+ const forcedProperties = (0, _extends2.default)({
336
+ field: _gridRowGroupingUtils.GRID_ROW_GROUPING_SINGLE_GROUPING_FIELD
337
+ }, GROUPING_COL_DEF_FORCED_PROPERTIES);
338
+ return (0, _extends2.default)({}, GROUPING_COL_DEF_DEFAULT_PROPERTIES, commonProperties, sourceProperties, colDefOverrideProperties, forcedProperties);
339
+ };
340
+
341
+ exports.createGroupingColDefForAllGroupingCriteria = createGroupingColDefForAllGroupingCriteria;
@@ -0,0 +1,5 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
@@ -0,0 +1,18 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.gridRowGroupingStateSelector = exports.gridRowGroupingSanitizedModelSelector = exports.gridRowGroupingModelSelector = void 0;
7
+
8
+ var _xDataGridPro = require("@mui/x-data-grid-pro");
9
+
10
+ var _internals = require("@mui/x-data-grid-pro/internals");
11
+
12
+ const gridRowGroupingStateSelector = state => state.rowGrouping;
13
+
14
+ exports.gridRowGroupingStateSelector = gridRowGroupingStateSelector;
15
+ const gridRowGroupingModelSelector = (0, _internals.createSelector)(gridRowGroupingStateSelector, rowGrouping => rowGrouping.model);
16
+ exports.gridRowGroupingModelSelector = gridRowGroupingModelSelector;
17
+ const gridRowGroupingSanitizedModelSelector = (0, _internals.createSelector)(gridRowGroupingModelSelector, _xDataGridPro.gridColumnLookupSelector, (model, columnsLookup) => model.filter(field => !!columnsLookup[field] && columnsLookup[field].groupable));
18
+ exports.gridRowGroupingSanitizedModelSelector = gridRowGroupingSanitizedModelSelector;
@@ -0,0 +1,172 @@
1
+ "use strict";
2
+
3
+ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
4
+
5
+ Object.defineProperty(exports, "__esModule", {
6
+ value: true
7
+ });
8
+ exports.setStrategyAvailability = exports.mergeStateWithRowGroupingModel = exports.isGroupingColumn = exports.getRowGroupingFieldFromGroupingCriteria = exports.getRowGroupingCriteriaFromGroupingField = exports.getColDefOverrides = exports.filterRowTreeFromGroupingColumns = exports.ROW_GROUPING_STRATEGY = exports.GRID_ROW_GROUPING_SINGLE_GROUPING_FIELD = void 0;
9
+
10
+ var _extends2 = _interopRequireDefault(require("@babel/runtime/helpers/extends"));
11
+
12
+ var _gridRowGroupingSelector = require("./gridRowGroupingSelector");
13
+
14
+ const GRID_ROW_GROUPING_SINGLE_GROUPING_FIELD = '__row_group_by_columns_group__';
15
+ exports.GRID_ROW_GROUPING_SINGLE_GROUPING_FIELD = GRID_ROW_GROUPING_SINGLE_GROUPING_FIELD;
16
+ const ROW_GROUPING_STRATEGY = 'grouping-columns';
17
+ exports.ROW_GROUPING_STRATEGY = ROW_GROUPING_STRATEGY;
18
+
19
+ const getRowGroupingFieldFromGroupingCriteria = groupingCriteria => {
20
+ if (groupingCriteria === null) {
21
+ return GRID_ROW_GROUPING_SINGLE_GROUPING_FIELD;
22
+ }
23
+
24
+ return `__row_group_by_columns_group_${groupingCriteria}__`;
25
+ };
26
+
27
+ exports.getRowGroupingFieldFromGroupingCriteria = getRowGroupingFieldFromGroupingCriteria;
28
+
29
+ const getRowGroupingCriteriaFromGroupingField = groupingColDefField => {
30
+ const match = groupingColDefField.match(/^__row_group_by_columns_group_(.*)__$/);
31
+
32
+ if (!match) {
33
+ return null;
34
+ }
35
+
36
+ return match[1];
37
+ };
38
+
39
+ exports.getRowGroupingCriteriaFromGroupingField = getRowGroupingCriteriaFromGroupingField;
40
+
41
+ const isGroupingColumn = field => field === GRID_ROW_GROUPING_SINGLE_GROUPING_FIELD || getRowGroupingCriteriaFromGroupingField(field) !== null;
42
+
43
+ exports.isGroupingColumn = isGroupingColumn;
44
+
45
+ /**
46
+ * When filtering a group, we only want to filter according to the items related to this grouping column.
47
+ */
48
+ const shouldApplyFilterItemOnGroup = (columnField, node) => {
49
+ if (columnField === GRID_ROW_GROUPING_SINGLE_GROUPING_FIELD) {
50
+ return true;
51
+ }
52
+
53
+ const groupingCriteriaField = getRowGroupingCriteriaFromGroupingField(columnField);
54
+ return groupingCriteriaField === node.groupingField;
55
+ };
56
+ /**
57
+ * A leaf is visible if it passed the filter
58
+ * A group is visible if all the following criteria are met:
59
+ * - One of its children is passing the filter
60
+ * - It is passing the filter
61
+ */
62
+
63
+
64
+ const filterRowTreeFromGroupingColumns = params => {
65
+ const {
66
+ rowTree,
67
+ isRowMatchingFilters
68
+ } = params;
69
+ const visibleRowsLookup = {};
70
+ const filteredRowsLookup = {};
71
+ const filteredDescendantCountLookup = {};
72
+
73
+ const filterTreeNode = (node, areAncestorsPassingChildren, areAncestorsExpanded) => {
74
+ var _node$children, _node$children2;
75
+
76
+ let isMatchingFilters;
77
+
78
+ if (!isRowMatchingFilters) {
79
+ isMatchingFilters = true;
80
+ } else {
81
+ const shouldApplyItem = node.isAutoGenerated ? columnField => shouldApplyFilterItemOnGroup(columnField, node) : undefined;
82
+ isMatchingFilters = isRowMatchingFilters(node.id, shouldApplyItem);
83
+ }
84
+
85
+ let filteredDescendantCount = 0;
86
+ (_node$children = node.children) == null ? void 0 : _node$children.forEach(childId => {
87
+ const childNode = rowTree[childId];
88
+ const childSubTreeSize = filterTreeNode(childNode, areAncestorsPassingChildren && isMatchingFilters, areAncestorsExpanded && !!node.childrenExpanded);
89
+ filteredDescendantCount += childSubTreeSize;
90
+ });
91
+ let shouldPassFilters;
92
+
93
+ if (!areAncestorsPassingChildren) {
94
+ shouldPassFilters = false;
95
+ } else if ((_node$children2 = node.children) != null && _node$children2.length) {
96
+ shouldPassFilters = isMatchingFilters && filteredDescendantCount > 0;
97
+ } else {
98
+ shouldPassFilters = isMatchingFilters;
99
+ }
100
+
101
+ visibleRowsLookup[node.id] = shouldPassFilters && areAncestorsExpanded;
102
+ filteredRowsLookup[node.id] = shouldPassFilters;
103
+
104
+ if (!shouldPassFilters) {
105
+ return 0;
106
+ }
107
+
108
+ filteredDescendantCountLookup[node.id] = filteredDescendantCount;
109
+
110
+ if (!node.children) {
111
+ return filteredDescendantCount + 1;
112
+ }
113
+
114
+ return filteredDescendantCount;
115
+ };
116
+
117
+ const nodes = Object.values(rowTree);
118
+
119
+ for (let i = 0; i < nodes.length; i += 1) {
120
+ const node = nodes[i];
121
+
122
+ if (node.depth === 0) {
123
+ filterTreeNode(node, true, true);
124
+ }
125
+ }
126
+
127
+ return {
128
+ visibleRowsLookup,
129
+ filteredRowsLookup,
130
+ filteredDescendantCountLookup
131
+ };
132
+ };
133
+
134
+ exports.filterRowTreeFromGroupingColumns = filterRowTreeFromGroupingColumns;
135
+
136
+ const getColDefOverrides = (groupingColDefProp, fields) => {
137
+ if (typeof groupingColDefProp === 'function') {
138
+ return groupingColDefProp({
139
+ groupingName: ROW_GROUPING_STRATEGY,
140
+ fields
141
+ });
142
+ }
143
+
144
+ return groupingColDefProp;
145
+ };
146
+
147
+ exports.getColDefOverrides = getColDefOverrides;
148
+
149
+ const mergeStateWithRowGroupingModel = rowGroupingModel => state => (0, _extends2.default)({}, state, {
150
+ rowGrouping: (0, _extends2.default)({}, state.rowGrouping, {
151
+ model: rowGroupingModel
152
+ })
153
+ });
154
+
155
+ exports.mergeStateWithRowGroupingModel = mergeStateWithRowGroupingModel;
156
+
157
+ const setStrategyAvailability = (apiRef, disableRowGrouping) => {
158
+ let isAvailable;
159
+
160
+ if (disableRowGrouping) {
161
+ isAvailable = () => false;
162
+ } else {
163
+ isAvailable = () => {
164
+ const rowGroupingSanitizedModel = (0, _gridRowGroupingSelector.gridRowGroupingSanitizedModelSelector)(apiRef);
165
+ return rowGroupingSanitizedModel.length > 0;
166
+ };
167
+ }
168
+
169
+ apiRef.current.unstable_setStrategyAvailability('rowTree', ROW_GROUPING_STRATEGY, isAvailable);
170
+ };
171
+
172
+ exports.setStrategyAvailability = setStrategyAvailability;
@@ -0,0 +1,51 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ var _exportNames = {
7
+ GRID_ROW_GROUPING_SINGLE_GROUPING_FIELD: true,
8
+ getRowGroupingFieldFromGroupingCriteria: true
9
+ };
10
+ Object.defineProperty(exports, "GRID_ROW_GROUPING_SINGLE_GROUPING_FIELD", {
11
+ enumerable: true,
12
+ get: function () {
13
+ return _gridRowGroupingUtils.GRID_ROW_GROUPING_SINGLE_GROUPING_FIELD;
14
+ }
15
+ });
16
+ Object.defineProperty(exports, "getRowGroupingFieldFromGroupingCriteria", {
17
+ enumerable: true,
18
+ get: function () {
19
+ return _gridRowGroupingUtils.getRowGroupingFieldFromGroupingCriteria;
20
+ }
21
+ });
22
+
23
+ var _gridRowGroupingSelector = require("./gridRowGroupingSelector");
24
+
25
+ Object.keys(_gridRowGroupingSelector).forEach(function (key) {
26
+ if (key === "default" || key === "__esModule") return;
27
+ if (Object.prototype.hasOwnProperty.call(_exportNames, key)) return;
28
+ if (key in exports && exports[key] === _gridRowGroupingSelector[key]) return;
29
+ Object.defineProperty(exports, key, {
30
+ enumerable: true,
31
+ get: function () {
32
+ return _gridRowGroupingSelector[key];
33
+ }
34
+ });
35
+ });
36
+
37
+ var _gridRowGroupingInterfaces = require("./gridRowGroupingInterfaces");
38
+
39
+ Object.keys(_gridRowGroupingInterfaces).forEach(function (key) {
40
+ if (key === "default" || key === "__esModule") return;
41
+ if (Object.prototype.hasOwnProperty.call(_exportNames, key)) return;
42
+ if (key in exports && exports[key] === _gridRowGroupingInterfaces[key]) return;
43
+ Object.defineProperty(exports, key, {
44
+ enumerable: true,
45
+ get: function () {
46
+ return _gridRowGroupingInterfaces[key];
47
+ }
48
+ });
49
+ });
50
+
51
+ var _gridRowGroupingUtils = require("./gridRowGroupingUtils");