@mui/x-data-grid 7.0.0-beta.5 → 7.0.0-beta.7

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 (210) hide show
  1. package/CHANGELOG.md +252 -50
  2. package/DataGrid/DataGrid.js +44 -0
  3. package/DataGrid/useDataGridComponent.js +3 -0
  4. package/DataGrid/useDataGridProps.js +3 -2
  5. package/components/GridColumnHeaders.d.ts +1 -2
  6. package/components/GridColumnHeaders.js +6 -17
  7. package/components/GridHeaders.js +1 -4
  8. package/components/GridPagination.js +2 -7
  9. package/components/GridPinnedRows.d.ts +1 -2
  10. package/components/GridRow.d.ts +1 -1
  11. package/components/GridRow.js +9 -26
  12. package/components/GridScrollArea.d.ts +10 -0
  13. package/components/GridScrollArea.js +150 -0
  14. package/components/cell/GridCell.d.ts +7 -2
  15. package/components/cell/GridCell.js +14 -10
  16. package/components/columnHeaders/GridBaseColumnHeaders.js +1 -0
  17. package/components/columnHeaders/GridColumnGroupHeader.d.ts +5 -0
  18. package/components/columnHeaders/GridColumnGroupHeader.js +18 -8
  19. package/components/columnHeaders/GridColumnHeaderItem.d.ts +5 -0
  20. package/components/columnHeaders/GridColumnHeaderItem.js +21 -6
  21. package/components/columnHeaders/GridGenericColumnHeaderItem.d.ts +1 -0
  22. package/components/columnHeaders/GridGenericColumnHeaderItem.js +6 -5
  23. package/components/containers/GridRootStyles.js +12 -22
  24. package/components/virtualization/GridVirtualScrollbar.js +4 -0
  25. package/components/virtualization/GridVirtualScroller.js +11 -4
  26. package/components/virtualization/GridVirtualScrollerFiller.js +2 -1
  27. package/constants/gridClasses.d.ts +6 -32
  28. package/constants/gridClasses.js +1 -1
  29. package/hooks/core/pipeProcessing/gridPipeProcessingApi.d.ts +5 -1
  30. package/hooks/core/pipeProcessing/useGridPipeProcessing.js +22 -20
  31. package/hooks/features/columnHeaders/useGridColumnHeaders.d.ts +23 -7
  32. package/hooks/features/columnHeaders/useGridColumnHeaders.js +186 -99
  33. package/hooks/features/columnResize/columnResizeSelector.d.ts +3 -0
  34. package/hooks/features/columnResize/columnResizeSelector.js +3 -0
  35. package/hooks/features/columnResize/columnResizeState.d.ts +3 -0
  36. package/hooks/features/columnResize/columnResizeState.js +1 -0
  37. package/hooks/features/columnResize/gridColumnResizeApi.d.ts +44 -0
  38. package/hooks/features/columnResize/gridColumnResizeApi.js +10 -0
  39. package/hooks/features/columnResize/index.d.ts +3 -0
  40. package/hooks/features/columnResize/index.js +3 -0
  41. package/hooks/features/columnResize/useGridColumnResize.d.ts +10 -0
  42. package/hooks/features/columnResize/useGridColumnResize.js +563 -0
  43. package/hooks/features/columns/gridColumnsUtils.js +4 -1
  44. package/hooks/features/dimensions/useGridDimensions.js +5 -5
  45. package/hooks/features/editing/useGridCellEditing.js +21 -2
  46. package/hooks/features/export/useGridPrintExport.js +8 -7
  47. package/hooks/features/headerFiltering/gridHeaderFilteringSelectors.d.ts +1 -0
  48. package/hooks/features/headerFiltering/gridHeaderFilteringSelectors.js +6 -0
  49. package/hooks/features/headerFiltering/useGridHeaderFiltering.js +30 -7
  50. package/hooks/features/index.d.ts +1 -0
  51. package/hooks/features/index.js +1 -0
  52. package/hooks/features/pagination/gridPaginationInterfaces.d.ts +19 -2
  53. package/hooks/features/pagination/gridPaginationSelector.d.ts +5 -0
  54. package/hooks/features/pagination/gridPaginationSelector.js +8 -2
  55. package/hooks/features/pagination/useGridPagination.d.ts +1 -6
  56. package/hooks/features/pagination/useGridPagination.js +9 -157
  57. package/hooks/features/pagination/useGridPaginationModel.d.ts +11 -0
  58. package/hooks/features/pagination/useGridPaginationModel.js +170 -0
  59. package/hooks/features/pagination/useGridRowCount.d.ts +8 -0
  60. package/hooks/features/pagination/useGridRowCount.js +97 -0
  61. package/hooks/features/rows/useGridParamsApi.js +6 -10
  62. package/hooks/features/scroll/useGridScroll.js +1 -1
  63. package/hooks/features/sorting/useGridSorting.js +2 -2
  64. package/hooks/features/virtualization/gridVirtualizationSelectors.d.ts +4 -4
  65. package/hooks/features/virtualization/gridVirtualizationSelectors.js +0 -2
  66. package/hooks/features/virtualization/useGridVirtualScroller.d.ts +2 -2
  67. package/hooks/features/virtualization/useGridVirtualScroller.js +6 -0
  68. package/hooks/utils/useLazyRef.d.ts +1 -2
  69. package/hooks/utils/useLazyRef.js +1 -11
  70. package/hooks/utils/useOnMount.d.ts +1 -2
  71. package/hooks/utils/useOnMount.js +1 -7
  72. package/hooks/utils/useTimeout.d.ts +1 -11
  73. package/hooks/utils/useTimeout.js +1 -36
  74. package/index.js +1 -1
  75. package/internals/index.d.ts +2 -2
  76. package/internals/index.js +2 -2
  77. package/internals/utils/getPinnedCellOffset.d.ts +3 -0
  78. package/internals/utils/getPinnedCellOffset.js +17 -0
  79. package/joy/joySlots.js +13 -52
  80. package/locales/jaJP.js +3 -4
  81. package/material/index.js +0 -2
  82. package/models/api/gridApiCommon.d.ts +2 -1
  83. package/models/api/gridCoreApi.d.ts +1 -5
  84. package/models/api/gridInfiniteLoaderApi.d.ts +6 -0
  85. package/models/api/gridInfiniteLoaderApi.js +1 -0
  86. package/models/events/gridEventLookup.d.ts +6 -0
  87. package/models/gridHeaderFilteringModel.d.ts +1 -0
  88. package/models/gridSlotsComponent.d.ts +0 -5
  89. package/models/gridStateCommunity.d.ts +2 -0
  90. package/models/params/gridScrollParams.d.ts +5 -3
  91. package/models/props/DataGridProps.d.ts +35 -1
  92. package/modern/DataGrid/DataGrid.js +44 -0
  93. package/modern/DataGrid/useDataGridComponent.js +3 -0
  94. package/modern/DataGrid/useDataGridProps.js +3 -2
  95. package/modern/components/GridColumnHeaders.js +6 -17
  96. package/modern/components/GridHeaders.js +1 -4
  97. package/modern/components/GridPagination.js +2 -4
  98. package/modern/components/GridRow.js +9 -26
  99. package/modern/components/GridScrollArea.js +150 -0
  100. package/modern/components/cell/GridCell.js +14 -10
  101. package/modern/components/columnHeaders/GridBaseColumnHeaders.js +1 -0
  102. package/modern/components/columnHeaders/GridColumnGroupHeader.js +18 -8
  103. package/modern/components/columnHeaders/GridColumnHeaderItem.js +21 -6
  104. package/modern/components/columnHeaders/GridGenericColumnHeaderItem.js +6 -5
  105. package/modern/components/containers/GridRootStyles.js +12 -22
  106. package/modern/components/virtualization/GridVirtualScrollbar.js +4 -0
  107. package/modern/components/virtualization/GridVirtualScroller.js +11 -4
  108. package/modern/components/virtualization/GridVirtualScrollerFiller.js +2 -1
  109. package/modern/constants/gridClasses.js +1 -1
  110. package/modern/hooks/core/pipeProcessing/useGridPipeProcessing.js +22 -20
  111. package/modern/hooks/features/columnHeaders/useGridColumnHeaders.js +184 -97
  112. package/modern/hooks/features/columnResize/columnResizeSelector.js +3 -0
  113. package/modern/hooks/features/columnResize/columnResizeState.js +1 -0
  114. package/modern/hooks/features/columnResize/gridColumnResizeApi.js +10 -0
  115. package/modern/hooks/features/columnResize/index.js +3 -0
  116. package/modern/hooks/features/columnResize/useGridColumnResize.js +553 -0
  117. package/modern/hooks/features/columns/gridColumnsUtils.js +4 -1
  118. package/modern/hooks/features/dimensions/useGridDimensions.js +5 -5
  119. package/modern/hooks/features/editing/useGridCellEditing.js +21 -2
  120. package/modern/hooks/features/export/useGridPrintExport.js +8 -7
  121. package/modern/hooks/features/headerFiltering/gridHeaderFilteringSelectors.js +3 -0
  122. package/modern/hooks/features/headerFiltering/useGridHeaderFiltering.js +21 -2
  123. package/modern/hooks/features/index.js +1 -0
  124. package/modern/hooks/features/pagination/gridPaginationSelector.js +8 -2
  125. package/modern/hooks/features/pagination/useGridPagination.js +8 -149
  126. package/modern/hooks/features/pagination/useGridPaginationModel.js +165 -0
  127. package/modern/hooks/features/pagination/useGridRowCount.js +94 -0
  128. package/modern/hooks/features/rows/useGridParamsApi.js +6 -10
  129. package/modern/hooks/features/scroll/useGridScroll.js +1 -1
  130. package/modern/hooks/features/sorting/useGridSorting.js +2 -2
  131. package/modern/hooks/features/virtualization/gridVirtualizationSelectors.js +0 -2
  132. package/modern/hooks/features/virtualization/useGridVirtualScroller.js +5 -0
  133. package/modern/hooks/utils/useLazyRef.js +1 -11
  134. package/modern/hooks/utils/useOnMount.js +1 -7
  135. package/modern/hooks/utils/useTimeout.js +1 -36
  136. package/modern/index.js +1 -1
  137. package/modern/internals/index.js +2 -2
  138. package/modern/internals/utils/getPinnedCellOffset.js +17 -0
  139. package/modern/joy/joySlots.js +11 -50
  140. package/modern/locales/jaJP.js +3 -4
  141. package/modern/material/index.js +0 -2
  142. package/modern/models/api/gridInfiniteLoaderApi.js +1 -0
  143. package/modern/utils/cellBorderUtils.js +8 -0
  144. package/modern/utils/createSelector.js +12 -20
  145. package/modern/utils/domUtils.js +144 -0
  146. package/node/DataGrid/DataGrid.js +44 -0
  147. package/node/DataGrid/useDataGridComponent.js +3 -0
  148. package/node/DataGrid/useDataGridProps.js +3 -2
  149. package/node/components/GridColumnHeaders.js +6 -16
  150. package/node/components/GridHeaders.js +1 -4
  151. package/node/components/GridPagination.js +1 -3
  152. package/node/components/GridRow.js +8 -25
  153. package/node/components/GridScrollArea.js +158 -0
  154. package/node/components/cell/GridCell.js +15 -11
  155. package/node/components/columnHeaders/GridBaseColumnHeaders.js +1 -0
  156. package/node/components/columnHeaders/GridColumnGroupHeader.js +18 -8
  157. package/node/components/columnHeaders/GridColumnHeaderItem.js +21 -6
  158. package/node/components/columnHeaders/GridGenericColumnHeaderItem.js +6 -5
  159. package/node/components/containers/GridRootStyles.js +12 -22
  160. package/node/components/virtualization/GridVirtualScrollbar.js +4 -0
  161. package/node/components/virtualization/GridVirtualScroller.js +11 -4
  162. package/node/components/virtualization/GridVirtualScrollerFiller.js +2 -1
  163. package/node/constants/gridClasses.js +1 -1
  164. package/node/hooks/core/pipeProcessing/useGridPipeProcessing.js +22 -20
  165. package/node/hooks/features/columnHeaders/useGridColumnHeaders.js +190 -103
  166. package/node/hooks/features/columnResize/columnResizeSelector.js +10 -0
  167. package/node/hooks/features/columnResize/columnResizeState.js +5 -0
  168. package/node/hooks/features/columnResize/gridColumnResizeApi.js +16 -0
  169. package/node/hooks/features/columnResize/index.js +38 -0
  170. package/node/hooks/features/columnResize/useGridColumnResize.js +564 -0
  171. package/node/hooks/features/columns/gridColumnsUtils.js +4 -1
  172. package/node/hooks/features/dimensions/useGridDimensions.js +5 -5
  173. package/node/hooks/features/editing/useGridCellEditing.js +21 -2
  174. package/node/hooks/features/export/useGridPrintExport.js +8 -7
  175. package/node/hooks/features/headerFiltering/gridHeaderFilteringSelectors.js +4 -1
  176. package/node/hooks/features/headerFiltering/useGridHeaderFiltering.js +21 -2
  177. package/node/hooks/features/index.js +11 -0
  178. package/node/hooks/features/pagination/gridPaginationSelector.js +8 -2
  179. package/node/hooks/features/pagination/useGridPagination.js +9 -153
  180. package/node/hooks/features/pagination/useGridPaginationModel.js +176 -0
  181. package/node/hooks/features/pagination/useGridRowCount.js +103 -0
  182. package/node/hooks/features/rows/useGridParamsApi.js +6 -10
  183. package/node/hooks/features/scroll/useGridScroll.js +1 -1
  184. package/node/hooks/features/sorting/useGridSorting.js +2 -2
  185. package/node/hooks/features/virtualization/gridVirtualizationSelectors.js +0 -2
  186. package/node/hooks/features/virtualization/useGridVirtualScroller.js +5 -0
  187. package/node/hooks/utils/useLazyRef.js +7 -13
  188. package/node/hooks/utils/useOnMount.js +8 -10
  189. package/node/hooks/utils/useTimeout.js +7 -37
  190. package/node/index.js +1 -1
  191. package/node/internals/index.js +15 -15
  192. package/node/internals/utils/getPinnedCellOffset.js +24 -0
  193. package/node/joy/joySlots.js +11 -50
  194. package/node/locales/jaJP.js +3 -4
  195. package/node/material/index.js +0 -2
  196. package/node/models/api/gridInfiniteLoaderApi.js +5 -0
  197. package/node/utils/cellBorderUtils.js +16 -0
  198. package/node/utils/createSelector.js +14 -23
  199. package/node/utils/domUtils.js +155 -0
  200. package/package.json +2 -2
  201. package/utils/cellBorderUtils.d.ts +3 -0
  202. package/utils/cellBorderUtils.js +8 -0
  203. package/utils/createSelector.d.ts +0 -1
  204. package/utils/createSelector.js +12 -22
  205. package/utils/domUtils.d.ts +14 -1
  206. package/utils/domUtils.js +147 -0
  207. package/components/columnHeaders/GridColumnHeadersInner.d.ts +0 -8
  208. package/components/columnHeaders/GridColumnHeadersInner.js +0 -58
  209. package/modern/components/columnHeaders/GridColumnHeadersInner.js +0 -58
  210. package/node/components/columnHeaders/GridColumnHeadersInner.js +0 -67
@@ -3,8 +3,19 @@
3
3
  Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
+ exports.findGridCellElementsFromCol = findGridCellElementsFromCol;
7
+ exports.findGridCells = findGridCells;
8
+ exports.findGridElement = findGridElement;
9
+ exports.findGridHeader = findGridHeader;
10
+ exports.findGroupHeaderElementsFromField = findGroupHeaderElementsFromField;
11
+ exports.findHeaderElementFromField = findHeaderElementFromField;
12
+ exports.findLeftPinnedCellsAfterCol = findLeftPinnedCellsAfterCol;
13
+ exports.findLeftPinnedHeadersAfterCol = findLeftPinnedHeadersAfterCol;
6
14
  exports.findParentElementFromClassName = findParentElementFromClassName;
15
+ exports.findRightPinnedCellsBeforeCol = findRightPinnedCellsBeforeCol;
16
+ exports.findRightPinnedHeadersBeforeCol = findRightPinnedHeadersBeforeCol;
7
17
  exports.getActiveElement = void 0;
18
+ exports.getFieldFromHeaderElem = getFieldFromHeaderElem;
8
19
  exports.getGridCellElement = getGridCellElement;
9
20
  exports.getGridColumnHeaderElement = getGridColumnHeaderElement;
10
21
  exports.getGridRowElement = getGridRowElement;
@@ -59,4 +70,148 @@ function isEventTargetInPortal(event) {
59
70
  return true;
60
71
  }
61
72
  return false;
73
+ }
74
+ function getFieldFromHeaderElem(colCellEl) {
75
+ return colCellEl.getAttribute('data-field');
76
+ }
77
+ function findHeaderElementFromField(elem, field) {
78
+ return elem.querySelector(`[data-field="${field}"]`);
79
+ }
80
+ function findGroupHeaderElementsFromField(elem, field) {
81
+ return Array.from(elem.querySelectorAll(`[data-fields*="|-${field}-|"]`) ?? []);
82
+ }
83
+ function findGridCellElementsFromCol(col, api) {
84
+ const root = findParentElementFromClassName(col, _gridClasses.gridClasses.root);
85
+ if (!root) {
86
+ throw new Error('MUI X: The root element is not found.');
87
+ }
88
+ const ariaColIndex = col.getAttribute('aria-colindex');
89
+ if (!ariaColIndex) {
90
+ return [];
91
+ }
92
+ const colIndex = Number(ariaColIndex) - 1;
93
+ const cells = [];
94
+ if (!api.virtualScrollerRef?.current) {
95
+ return [];
96
+ }
97
+ queryRows(api).forEach(rowElement => {
98
+ const rowId = rowElement.getAttribute('data-id');
99
+ if (!rowId) {
100
+ return;
101
+ }
102
+ let columnIndex = colIndex;
103
+ const cellColSpanInfo = api.unstable_getCellColSpanInfo(rowId, colIndex);
104
+ if (cellColSpanInfo && cellColSpanInfo.spannedByColSpan) {
105
+ columnIndex = cellColSpanInfo.leftVisibleCellIndex;
106
+ }
107
+ const cell = rowElement.querySelector(`[data-colindex="${columnIndex}"]`);
108
+ if (cell) {
109
+ cells.push(cell);
110
+ }
111
+ });
112
+ return cells;
113
+ }
114
+ function findGridElement(api, klass) {
115
+ return api.rootElementRef.current.querySelector(`.${_gridClasses.gridClasses[klass]}`);
116
+ }
117
+ const findPinnedCells = ({
118
+ api,
119
+ colIndex,
120
+ position,
121
+ filterFn
122
+ }) => {
123
+ if (colIndex === null) {
124
+ return [];
125
+ }
126
+ const cells = [];
127
+ queryRows(api).forEach(rowElement => {
128
+ const rowId = rowElement.getAttribute('data-id');
129
+ if (!rowId) {
130
+ return;
131
+ }
132
+ rowElement.querySelectorAll(`.${_gridClasses.gridClasses[position === 'left' ? 'cell--pinnedLeft' : 'cell--pinnedRight']}`).forEach(cell => {
133
+ const currentColIndex = parseCellColIndex(cell);
134
+ if (currentColIndex !== null && filterFn(currentColIndex)) {
135
+ cells.push(cell);
136
+ }
137
+ });
138
+ });
139
+ return cells;
140
+ };
141
+ function findLeftPinnedCellsAfterCol(api, col) {
142
+ const colIndex = parseCellColIndex(col);
143
+ return findPinnedCells({
144
+ api,
145
+ colIndex,
146
+ position: 'left',
147
+ filterFn: index => index > colIndex
148
+ });
149
+ }
150
+ function findRightPinnedCellsBeforeCol(api, col) {
151
+ const colIndex = parseCellColIndex(col);
152
+ return findPinnedCells({
153
+ api,
154
+ colIndex,
155
+ position: 'right',
156
+ filterFn: index => index < colIndex
157
+ });
158
+ }
159
+ const findPinnedHeaders = ({
160
+ api,
161
+ colIndex,
162
+ position,
163
+ filterFn
164
+ }) => {
165
+ if (!api.columnHeadersContainerRef?.current) {
166
+ return [];
167
+ }
168
+ if (colIndex === null) {
169
+ return [];
170
+ }
171
+ const elements = [];
172
+ api.columnHeadersContainerRef.current.querySelectorAll(`.${_gridClasses.gridClasses[position === 'left' ? 'columnHeader--pinnedLeft' : 'columnHeader--pinnedRight']}`).forEach(element => {
173
+ const currentColIndex = parseCellColIndex(element);
174
+ if (currentColIndex !== null && filterFn(currentColIndex)) {
175
+ elements.push(element);
176
+ }
177
+ });
178
+ return elements;
179
+ };
180
+ function findLeftPinnedHeadersAfterCol(api, col) {
181
+ const colIndex = parseCellColIndex(col);
182
+ return findPinnedHeaders({
183
+ api,
184
+ position: 'left',
185
+ colIndex,
186
+ filterFn: index => index > colIndex
187
+ });
188
+ }
189
+ function findRightPinnedHeadersBeforeCol(api, col) {
190
+ const colIndex = parseCellColIndex(col);
191
+ return findPinnedHeaders({
192
+ api,
193
+ position: 'right',
194
+ colIndex,
195
+ filterFn: index => index < colIndex
196
+ });
197
+ }
198
+ function findGridHeader(api, field) {
199
+ const headers = api.columnHeadersContainerRef.current;
200
+ return headers.querySelector(`:scope > div > [data-field="${field}"][role="columnheader"]`);
201
+ }
202
+ function findGridCells(api, field) {
203
+ const container = api.virtualScrollerRef.current;
204
+ return Array.from(container.querySelectorAll(`:scope > div > div > div > [data-field="${field}"][role="gridcell"]`));
205
+ }
206
+ function queryRows(api) {
207
+ return api.virtualScrollerRef.current.querySelectorAll(
208
+ // Use > to ignore rows from nested data grids (e.g. in detail panel)
209
+ `:scope > div > div > .${_gridClasses.gridClasses.row}`);
210
+ }
211
+ function parseCellColIndex(col) {
212
+ const ariaColIndex = col.getAttribute('aria-colindex');
213
+ if (!ariaColIndex) {
214
+ return null;
215
+ }
216
+ return Number(ariaColIndex) - 1;
62
217
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mui/x-data-grid",
3
- "version": "7.0.0-beta.5",
3
+ "version": "7.0.0-beta.7",
4
4
  "description": "The community edition of the data grid component (MUI X).",
5
5
  "author": "MUI Team",
6
6
  "main": "./node/index.js",
@@ -36,7 +36,7 @@
36
36
  "directory": "packages/x-data-grid"
37
37
  },
38
38
  "dependencies": {
39
- "@babel/runtime": "^7.23.9",
39
+ "@babel/runtime": "^7.24.0",
40
40
  "@mui/system": "^5.15.9",
41
41
  "@mui/utils": "^5.15.9",
42
42
  "clsx": "^2.1.0",
@@ -0,0 +1,3 @@
1
+ import { GridPinnedColumnPosition } from '../hooks/features/columns/gridColumnsInterfaces';
2
+ export declare const shouldCellShowRightBorder: (pinnedPosition: GridPinnedColumnPosition | undefined, indexInSection: number, sectionLength: number, showCellVerticalBorderRootProp: boolean) => boolean;
3
+ export declare const shouldCellShowLeftBorder: (pinnedPosition: GridPinnedColumnPosition | undefined, indexInSection: number) => boolean;
@@ -0,0 +1,8 @@
1
+ import { GridPinnedColumnPosition } from '../hooks/features/columns/gridColumnsInterfaces';
2
+ export const shouldCellShowRightBorder = (pinnedPosition, indexInSection, sectionLength, showCellVerticalBorderRootProp) => {
3
+ const isSectionLastCell = indexInSection === sectionLength - 1;
4
+ return showCellVerticalBorderRootProp && (pinnedPosition !== GridPinnedColumnPosition.LEFT ? !isSectionLastCell : true) || pinnedPosition === GridPinnedColumnPosition.LEFT && isSectionLastCell;
5
+ };
6
+ export const shouldCellShowLeftBorder = (pinnedPosition, indexInSection) => {
7
+ return pinnedPosition === GridPinnedColumnPosition.RIGHT && indexInSection === 0;
8
+ };
@@ -20,5 +20,4 @@ type SelectorArgs<Selectors extends ReadonlyArray<Selector<any>>, Result> = [sel
20
20
  type CreateSelectorFunction = <Selectors extends ReadonlyArray<Selector<any>>, Result>(...items: SelectorArgs<Selectors, Result>) => OutputSelector<StateFromSelectorList<Selectors>, Result>;
21
21
  export declare const createSelector: CreateSelectorFunction;
22
22
  export declare const createSelectorMemoized: CreateSelectorFunction;
23
- export declare const unstable_resetCreateSelectorCache: () => void;
24
23
  export {};
@@ -1,8 +1,6 @@
1
1
  import { createSelector as reselectCreateSelector } from 'reselect';
2
2
  import { buildWarning } from './warning';
3
- const cacheContainer = {
4
- cache: new WeakMap()
5
- };
3
+ const cache = new WeakMap();
6
4
  const missingInstanceIdWarning = buildWarning(['MUI X: A selector was called without passing the instance ID, which may impact the performance of the grid.', 'To fix, call it with `apiRef`, e.g. `mySelector(apiRef)`, or pass the instance ID explicitly, e.g. `mySelector(state, apiRef.current.instanceId)`.']);
7
5
  function checkIsAPIRef(value) {
8
6
  return 'current' in value && 'instanceId' in value.current;
@@ -75,9 +73,7 @@ export const createSelector = (a, b, c, d, e, f, ...rest) => {
75
73
  return selector;
76
74
  };
77
75
  export const createSelectorMemoized = (...args) => {
78
- const selector = (...selectorArgs) => {
79
- var _cache$get, _cache$get3;
80
- const [stateOrApiRef, instanceId] = selectorArgs;
76
+ const selector = (stateOrApiRef, instanceId) => {
81
77
  const isAPIRef = checkIsAPIRef(stateOrApiRef);
82
78
  const cacheKey = isAPIRef ? stateOrApiRef.current.instanceId : instanceId != null ? instanceId : DEFAULT_INSTANCE_ID;
83
79
  const state = isAPIRef ? stateOrApiRef.current.state : stateOrApiRef;
@@ -86,30 +82,24 @@ export const createSelectorMemoized = (...args) => {
86
82
  missingInstanceIdWarning();
87
83
  }
88
84
  }
89
- const {
90
- cache
91
- } = cacheContainer;
92
- if (cache.get(cacheKey) && (_cache$get = cache.get(cacheKey)) != null && _cache$get.get(args)) {
93
- var _cache$get2;
85
+ const cacheArgsInit = cache.get(cacheKey);
86
+ const cacheArgs = cacheArgsInit != null ? cacheArgsInit : new Map();
87
+ const cacheFn = cacheArgs == null ? void 0 : cacheArgs.get(args);
88
+ if (cacheArgs && cacheFn) {
94
89
  // We pass the cache key because the called selector might have as
95
90
  // dependency another selector created with this `createSelector`.
96
- return (_cache$get2 = cache.get(cacheKey)) == null ? void 0 : _cache$get2.get(args)(state, cacheKey);
91
+ return cacheFn(state, cacheKey);
97
92
  }
98
- const newSelector = reselectCreateSelector(...args);
99
- if (!cache.get(cacheKey)) {
100
- cache.set(cacheKey, new Map());
93
+ const fn = reselectCreateSelector(...args);
94
+ if (!cacheArgsInit) {
95
+ cache.set(cacheKey, cacheArgs);
101
96
  }
102
- (_cache$get3 = cache.get(cacheKey)) == null || _cache$get3.set(args, newSelector);
103
- return newSelector(state, cacheKey);
97
+ cacheArgs.set(args, fn);
98
+ return fn(state, cacheKey);
104
99
  };
105
100
 
106
101
  // We use this property to detect if the selector was created with createSelector
107
102
  // or it's only a simple function the receives the state and returns part of it.
108
103
  selector.acceptsApiRef = true;
109
104
  return selector;
110
- };
111
-
112
- // eslint-disable-next-line @typescript-eslint/naming-convention
113
- export const unstable_resetCreateSelectorCache = () => {
114
- cacheContainer.cache = new WeakMap();
115
105
  };
@@ -1,5 +1,7 @@
1
1
  /// <reference types="react" />
2
- import { GridRowId } from '../models/gridRows';
2
+ import { gridClasses } from '../constants/gridClasses';
3
+ import type { GridPrivateApiCommunity } from '../models/api/gridApiCommunity';
4
+ import type { GridRowId } from '../models/gridRows';
3
5
  export declare function isOverflown(element: Element): boolean;
4
6
  export declare function findParentElementFromClassName(elem: Element, className: string): Element | null;
5
7
  export declare function getGridColumnHeaderElement(root: Element, field: string): HTMLDivElement | null;
@@ -10,3 +12,14 @@ export declare function getGridCellElement(root: Element, { id, field }: {
10
12
  }): HTMLDivElement | null;
11
13
  export declare const getActiveElement: (root?: Document | ShadowRoot) => Element | null;
12
14
  export declare function isEventTargetInPortal(event: React.SyntheticEvent): boolean;
15
+ export declare function getFieldFromHeaderElem(colCellEl: Element): string;
16
+ export declare function findHeaderElementFromField(elem: Element, field: string): HTMLDivElement;
17
+ export declare function findGroupHeaderElementsFromField(elem: Element, field: string): Element[];
18
+ export declare function findGridCellElementsFromCol(col: HTMLElement, api: GridPrivateApiCommunity): Element[];
19
+ export declare function findGridElement(api: GridPrivateApiCommunity, klass: keyof typeof gridClasses): HTMLElement;
20
+ export declare function findLeftPinnedCellsAfterCol(api: GridPrivateApiCommunity, col: HTMLElement): HTMLElement[];
21
+ export declare function findRightPinnedCellsBeforeCol(api: GridPrivateApiCommunity, col: HTMLElement): HTMLElement[];
22
+ export declare function findLeftPinnedHeadersAfterCol(api: GridPrivateApiCommunity, col: HTMLElement): HTMLElement[];
23
+ export declare function findRightPinnedHeadersBeforeCol(api: GridPrivateApiCommunity, col: HTMLElement): HTMLElement[];
24
+ export declare function findGridHeader(api: GridPrivateApiCommunity, field: string): Element | null;
25
+ export declare function findGridCells(api: GridPrivateApiCommunity, field: string): Element[];
package/utils/domUtils.js CHANGED
@@ -46,4 +46,151 @@ export function isEventTargetInPortal(event) {
46
46
  return true;
47
47
  }
48
48
  return false;
49
+ }
50
+ export function getFieldFromHeaderElem(colCellEl) {
51
+ return colCellEl.getAttribute('data-field');
52
+ }
53
+ export function findHeaderElementFromField(elem, field) {
54
+ return elem.querySelector(`[data-field="${field}"]`);
55
+ }
56
+ export function findGroupHeaderElementsFromField(elem, field) {
57
+ var _elem$querySelectorAl;
58
+ return Array.from((_elem$querySelectorAl = elem.querySelectorAll(`[data-fields*="|-${field}-|"]`)) != null ? _elem$querySelectorAl : []);
59
+ }
60
+ export function findGridCellElementsFromCol(col, api) {
61
+ var _api$virtualScrollerR;
62
+ const root = findParentElementFromClassName(col, gridClasses.root);
63
+ if (!root) {
64
+ throw new Error('MUI X: The root element is not found.');
65
+ }
66
+ const ariaColIndex = col.getAttribute('aria-colindex');
67
+ if (!ariaColIndex) {
68
+ return [];
69
+ }
70
+ const colIndex = Number(ariaColIndex) - 1;
71
+ const cells = [];
72
+ if (!((_api$virtualScrollerR = api.virtualScrollerRef) != null && _api$virtualScrollerR.current)) {
73
+ return [];
74
+ }
75
+ queryRows(api).forEach(rowElement => {
76
+ const rowId = rowElement.getAttribute('data-id');
77
+ if (!rowId) {
78
+ return;
79
+ }
80
+ let columnIndex = colIndex;
81
+ const cellColSpanInfo = api.unstable_getCellColSpanInfo(rowId, colIndex);
82
+ if (cellColSpanInfo && cellColSpanInfo.spannedByColSpan) {
83
+ columnIndex = cellColSpanInfo.leftVisibleCellIndex;
84
+ }
85
+ const cell = rowElement.querySelector(`[data-colindex="${columnIndex}"]`);
86
+ if (cell) {
87
+ cells.push(cell);
88
+ }
89
+ });
90
+ return cells;
91
+ }
92
+ export function findGridElement(api, klass) {
93
+ return api.rootElementRef.current.querySelector(`.${gridClasses[klass]}`);
94
+ }
95
+ const findPinnedCells = ({
96
+ api,
97
+ colIndex,
98
+ position,
99
+ filterFn
100
+ }) => {
101
+ if (colIndex === null) {
102
+ return [];
103
+ }
104
+ const cells = [];
105
+ queryRows(api).forEach(rowElement => {
106
+ const rowId = rowElement.getAttribute('data-id');
107
+ if (!rowId) {
108
+ return;
109
+ }
110
+ rowElement.querySelectorAll(`.${gridClasses[position === 'left' ? 'cell--pinnedLeft' : 'cell--pinnedRight']}`).forEach(cell => {
111
+ const currentColIndex = parseCellColIndex(cell);
112
+ if (currentColIndex !== null && filterFn(currentColIndex)) {
113
+ cells.push(cell);
114
+ }
115
+ });
116
+ });
117
+ return cells;
118
+ };
119
+ export function findLeftPinnedCellsAfterCol(api, col) {
120
+ const colIndex = parseCellColIndex(col);
121
+ return findPinnedCells({
122
+ api,
123
+ colIndex,
124
+ position: 'left',
125
+ filterFn: index => index > colIndex
126
+ });
127
+ }
128
+ export function findRightPinnedCellsBeforeCol(api, col) {
129
+ const colIndex = parseCellColIndex(col);
130
+ return findPinnedCells({
131
+ api,
132
+ colIndex,
133
+ position: 'right',
134
+ filterFn: index => index < colIndex
135
+ });
136
+ }
137
+ const findPinnedHeaders = ({
138
+ api,
139
+ colIndex,
140
+ position,
141
+ filterFn
142
+ }) => {
143
+ var _api$columnHeadersCon;
144
+ if (!((_api$columnHeadersCon = api.columnHeadersContainerRef) != null && _api$columnHeadersCon.current)) {
145
+ return [];
146
+ }
147
+ if (colIndex === null) {
148
+ return [];
149
+ }
150
+ const elements = [];
151
+ api.columnHeadersContainerRef.current.querySelectorAll(`.${gridClasses[position === 'left' ? 'columnHeader--pinnedLeft' : 'columnHeader--pinnedRight']}`).forEach(element => {
152
+ const currentColIndex = parseCellColIndex(element);
153
+ if (currentColIndex !== null && filterFn(currentColIndex)) {
154
+ elements.push(element);
155
+ }
156
+ });
157
+ return elements;
158
+ };
159
+ export function findLeftPinnedHeadersAfterCol(api, col) {
160
+ const colIndex = parseCellColIndex(col);
161
+ return findPinnedHeaders({
162
+ api,
163
+ position: 'left',
164
+ colIndex,
165
+ filterFn: index => index > colIndex
166
+ });
167
+ }
168
+ export function findRightPinnedHeadersBeforeCol(api, col) {
169
+ const colIndex = parseCellColIndex(col);
170
+ return findPinnedHeaders({
171
+ api,
172
+ position: 'right',
173
+ colIndex,
174
+ filterFn: index => index < colIndex
175
+ });
176
+ }
177
+ export function findGridHeader(api, field) {
178
+ const headers = api.columnHeadersContainerRef.current;
179
+ return headers.querySelector(`:scope > div > [data-field="${field}"][role="columnheader"]`);
180
+ }
181
+ export function findGridCells(api, field) {
182
+ const container = api.virtualScrollerRef.current;
183
+ return Array.from(container.querySelectorAll(`:scope > div > div > div > [data-field="${field}"][role="gridcell"]`));
184
+ }
185
+ function queryRows(api) {
186
+ return api.virtualScrollerRef.current.querySelectorAll(
187
+ // Use > to ignore rows from nested data grids (e.g. in detail panel)
188
+ `:scope > div > div > .${gridClasses.row}`);
189
+ }
190
+ function parseCellColIndex(col) {
191
+ const ariaColIndex = col.getAttribute('aria-colindex');
192
+ if (!ariaColIndex) {
193
+ return null;
194
+ }
195
+ return Number(ariaColIndex) - 1;
49
196
  }
@@ -1,8 +0,0 @@
1
- import * as React from 'react';
2
- import { SxProps, Theme } from '@mui/system';
3
- interface GridColumnHeadersInnerProps extends React.HTMLAttributes<HTMLDivElement> {
4
- isDragging: boolean;
5
- sx?: SxProps<Theme>;
6
- }
7
- export declare const GridColumnHeadersInner: React.ForwardRefExoticComponent<GridColumnHeadersInnerProps & React.RefAttributes<HTMLDivElement>>;
8
- export {};
@@ -1,58 +0,0 @@
1
- import _extends from "@babel/runtime/helpers/esm/extends";
2
- import _objectWithoutPropertiesLoose from "@babel/runtime/helpers/esm/objectWithoutPropertiesLoose";
3
- const _excluded = ["isDragging", "className"];
4
- import * as React from 'react';
5
- import clsx from 'clsx';
6
- import { unstable_composeClasses as composeClasses } from '@mui/utils';
7
- import { styled } from '@mui/system';
8
- import { gridClasses, getDataGridUtilityClass } from '../../constants/gridClasses';
9
- import { useGridRootProps } from '../../hooks/utils/useGridRootProps';
10
- import { useGridApiContext } from '../../hooks/utils/useGridApiContext';
11
- import { jsx as _jsx } from "react/jsx-runtime";
12
- const useUtilityClasses = ownerState => {
13
- const {
14
- isDragging,
15
- hasScrollX,
16
- classes
17
- } = ownerState;
18
- const slots = {
19
- root: ['columnHeadersInner', isDragging && 'columnHeaderDropZone', hasScrollX && 'columnHeadersInner--scrollable']
20
- };
21
- return composeClasses(slots, getDataGridUtilityClass, classes);
22
- };
23
- const GridColumnHeadersInnerRoot = styled('div', {
24
- name: 'MuiDataGrid',
25
- slot: 'columnHeadersInner',
26
- overridesResolver: (props, styles) => [{
27
- [`&.${gridClasses.columnHeaderDropZone}`]: styles.columnHeaderDropZone
28
- }, styles.columnHeadersInner]
29
- })(() => ({
30
- display: 'flex',
31
- alignItems: 'flex-start',
32
- flexDirection: 'column',
33
- [`&.${gridClasses.columnHeaderDropZone} .${gridClasses.columnHeaderDraggableContainer}`]: {
34
- cursor: 'move'
35
- },
36
- [`&.${gridClasses['columnHeadersInner--scrollable']} .${gridClasses.columnHeader}:last-child`]: {
37
- borderRight: 'none'
38
- }
39
- }));
40
- export const GridColumnHeadersInner = /*#__PURE__*/React.forwardRef(function GridColumnHeadersInner(props, ref) {
41
- const {
42
- isDragging,
43
- className
44
- } = props,
45
- other = _objectWithoutPropertiesLoose(props, _excluded);
46
- const apiRef = useGridApiContext();
47
- const rootProps = useGridRootProps();
48
- const ownerState = _extends({}, rootProps, {
49
- isDragging,
50
- hasScrollX: apiRef.current.getRootDimensions().hasScrollX
51
- });
52
- const classes = useUtilityClasses(ownerState);
53
- return /*#__PURE__*/_jsx(GridColumnHeadersInnerRoot, _extends({
54
- ref: ref,
55
- className: clsx(className, classes.root),
56
- ownerState: ownerState
57
- }, other));
58
- });
@@ -1,58 +0,0 @@
1
- import _extends from "@babel/runtime/helpers/esm/extends";
2
- import _objectWithoutPropertiesLoose from "@babel/runtime/helpers/esm/objectWithoutPropertiesLoose";
3
- const _excluded = ["isDragging", "className"];
4
- import * as React from 'react';
5
- import clsx from 'clsx';
6
- import { unstable_composeClasses as composeClasses } from '@mui/utils';
7
- import { styled } from '@mui/system';
8
- import { gridClasses, getDataGridUtilityClass } from '../../constants/gridClasses';
9
- import { useGridRootProps } from '../../hooks/utils/useGridRootProps';
10
- import { useGridApiContext } from '../../hooks/utils/useGridApiContext';
11
- import { jsx as _jsx } from "react/jsx-runtime";
12
- const useUtilityClasses = ownerState => {
13
- const {
14
- isDragging,
15
- hasScrollX,
16
- classes
17
- } = ownerState;
18
- const slots = {
19
- root: ['columnHeadersInner', isDragging && 'columnHeaderDropZone', hasScrollX && 'columnHeadersInner--scrollable']
20
- };
21
- return composeClasses(slots, getDataGridUtilityClass, classes);
22
- };
23
- const GridColumnHeadersInnerRoot = styled('div', {
24
- name: 'MuiDataGrid',
25
- slot: 'columnHeadersInner',
26
- overridesResolver: (props, styles) => [{
27
- [`&.${gridClasses.columnHeaderDropZone}`]: styles.columnHeaderDropZone
28
- }, styles.columnHeadersInner]
29
- })(() => ({
30
- display: 'flex',
31
- alignItems: 'flex-start',
32
- flexDirection: 'column',
33
- [`&.${gridClasses.columnHeaderDropZone} .${gridClasses.columnHeaderDraggableContainer}`]: {
34
- cursor: 'move'
35
- },
36
- [`&.${gridClasses['columnHeadersInner--scrollable']} .${gridClasses.columnHeader}:last-child`]: {
37
- borderRight: 'none'
38
- }
39
- }));
40
- export const GridColumnHeadersInner = /*#__PURE__*/React.forwardRef(function GridColumnHeadersInner(props, ref) {
41
- const {
42
- isDragging,
43
- className
44
- } = props,
45
- other = _objectWithoutPropertiesLoose(props, _excluded);
46
- const apiRef = useGridApiContext();
47
- const rootProps = useGridRootProps();
48
- const ownerState = _extends({}, rootProps, {
49
- isDragging,
50
- hasScrollX: apiRef.current.getRootDimensions().hasScrollX
51
- });
52
- const classes = useUtilityClasses(ownerState);
53
- return /*#__PURE__*/_jsx(GridColumnHeadersInnerRoot, _extends({
54
- ref: ref,
55
- className: clsx(className, classes.root),
56
- ownerState: ownerState
57
- }, other));
58
- });
@@ -1,67 +0,0 @@
1
- "use strict";
2
-
3
- var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
4
- Object.defineProperty(exports, "__esModule", {
5
- value: true
6
- });
7
- exports.GridColumnHeadersInner = void 0;
8
- var _extends2 = _interopRequireDefault(require("@babel/runtime/helpers/extends"));
9
- var _objectWithoutPropertiesLoose2 = _interopRequireDefault(require("@babel/runtime/helpers/objectWithoutPropertiesLoose"));
10
- var React = _interopRequireWildcard(require("react"));
11
- var _clsx = _interopRequireDefault(require("clsx"));
12
- var _utils = require("@mui/utils");
13
- var _system = require("@mui/system");
14
- var _gridClasses = require("../../constants/gridClasses");
15
- var _useGridRootProps = require("../../hooks/utils/useGridRootProps");
16
- var _useGridApiContext = require("../../hooks/utils/useGridApiContext");
17
- var _jsxRuntime = require("react/jsx-runtime");
18
- const _excluded = ["isDragging", "className"];
19
- 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); }
20
- 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; }
21
- const useUtilityClasses = ownerState => {
22
- const {
23
- isDragging,
24
- hasScrollX,
25
- classes
26
- } = ownerState;
27
- const slots = {
28
- root: ['columnHeadersInner', isDragging && 'columnHeaderDropZone', hasScrollX && 'columnHeadersInner--scrollable']
29
- };
30
- return (0, _utils.unstable_composeClasses)(slots, _gridClasses.getDataGridUtilityClass, classes);
31
- };
32
- const GridColumnHeadersInnerRoot = (0, _system.styled)('div', {
33
- name: 'MuiDataGrid',
34
- slot: 'columnHeadersInner',
35
- overridesResolver: (props, styles) => [{
36
- [`&.${_gridClasses.gridClasses.columnHeaderDropZone}`]: styles.columnHeaderDropZone
37
- }, styles.columnHeadersInner]
38
- })(() => ({
39
- display: 'flex',
40
- alignItems: 'flex-start',
41
- flexDirection: 'column',
42
- [`&.${_gridClasses.gridClasses.columnHeaderDropZone} .${_gridClasses.gridClasses.columnHeaderDraggableContainer}`]: {
43
- cursor: 'move'
44
- },
45
- [`&.${_gridClasses.gridClasses['columnHeadersInner--scrollable']} .${_gridClasses.gridClasses.columnHeader}:last-child`]: {
46
- borderRight: 'none'
47
- }
48
- }));
49
- const GridColumnHeadersInner = exports.GridColumnHeadersInner = /*#__PURE__*/React.forwardRef(function GridColumnHeadersInner(props, ref) {
50
- const {
51
- isDragging,
52
- className
53
- } = props,
54
- other = (0, _objectWithoutPropertiesLoose2.default)(props, _excluded);
55
- const apiRef = (0, _useGridApiContext.useGridApiContext)();
56
- const rootProps = (0, _useGridRootProps.useGridRootProps)();
57
- const ownerState = (0, _extends2.default)({}, rootProps, {
58
- isDragging,
59
- hasScrollX: apiRef.current.getRootDimensions().hasScrollX
60
- });
61
- const classes = useUtilityClasses(ownerState);
62
- return /*#__PURE__*/(0, _jsxRuntime.jsx)(GridColumnHeadersInnerRoot, (0, _extends2.default)({
63
- ref: ref,
64
- className: (0, _clsx.default)(className, classes.root),
65
- ownerState: ownerState
66
- }, other));
67
- });