@mui/x-data-grid 7.12.1 → 7.14.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 (157) hide show
  1. package/CHANGELOG.md +162 -1
  2. package/DataGrid/DataGrid.js +10 -1
  3. package/components/GridColumnHeaders.js +1 -1
  4. package/components/GridConfigurationContext.d.ts +2 -0
  5. package/components/GridConfigurationContext.js +5 -0
  6. package/components/GridHeaders.js +1 -1
  7. package/components/GridRow.js +6 -8
  8. package/components/GridScrollArea.js +1 -1
  9. package/components/GridSkeletonLoadingOverlay.js +1 -1
  10. package/components/cell/GridCell.js +12 -13
  11. package/components/cell/GridEditSingleSelectCell.js +2 -3
  12. package/components/cell/GridSkeletonCell.js +2 -2
  13. package/components/columnHeaders/GridColumnHeaderItem.js +1 -1
  14. package/components/containers/GridRootStyles.js +9 -2
  15. package/components/menu/columnMenu/GridColumnMenuContainer.js +2 -2
  16. package/components/panel/GridPanel.js +1 -2
  17. package/components/panel/filterPanel/GridFilterForm.js +9 -4
  18. package/components/toolbar/GridToolbarDensitySelector.js +2 -2
  19. package/components/toolbar/GridToolbarExportContainer.js +2 -2
  20. package/components/toolbar/GridToolbarQuickFilter.js +5 -3
  21. package/components/virtualization/GridMainContainer.js +3 -2
  22. package/components/virtualization/GridVirtualScrollerFiller.js +1 -1
  23. package/context/GridContextProvider.d.ts +3 -1
  24. package/context/GridContextProvider.js +12 -7
  25. package/hooks/core/useGridStateInitialization.js +1 -3
  26. package/hooks/features/dimensions/useGridDimensions.js +1 -1
  27. package/hooks/features/export/serializers/csvSerializer.js +4 -3
  28. package/hooks/features/filter/gridFilterSelector.d.ts +20 -7
  29. package/hooks/features/filter/gridFilterSelector.js +34 -0
  30. package/hooks/features/filter/gridFilterState.d.ts +6 -0
  31. package/hooks/features/filter/index.d.ts +2 -1
  32. package/hooks/features/filter/index.js +1 -1
  33. package/hooks/features/filter/useGridFilter.js +3 -0
  34. package/hooks/features/rowSelection/useGridRowSelection.js +4 -1
  35. package/hooks/features/rows/useGridParamsApi.js +2 -1
  36. package/hooks/features/rows/useGridRowAriaAttributes.d.ts +2 -0
  37. package/hooks/features/rows/useGridRowAriaAttributes.js +19 -0
  38. package/hooks/utils/useGridAriaAttributes.d.ts +2 -6
  39. package/hooks/utils/useGridAriaAttributes.js +5 -8
  40. package/hooks/utils/useGridConfiguration.d.ts +2 -0
  41. package/hooks/utils/useGridConfiguration.js +9 -0
  42. package/hooks/utils/useGridSelector.d.ts +5 -2
  43. package/hooks/utils/useGridSelector.js +39 -1
  44. package/index.js +1 -1
  45. package/internals/index.d.ts +5 -2
  46. package/internals/index.js +5 -2
  47. package/locales/csCZ.js +4 -5
  48. package/locales/heIL.js +4 -5
  49. package/locales/viVN.js +4 -5
  50. package/models/configuration/gridConfiguration.d.ts +10 -0
  51. package/models/configuration/gridConfiguration.js +1 -0
  52. package/models/configuration/gridRowConfiguration.d.ts +12 -0
  53. package/models/configuration/gridRowConfiguration.js +1 -0
  54. package/models/gridDataSource.d.ts +8 -7
  55. package/models/gridRows.d.ts +2 -2
  56. package/models/params/gridCellParams.d.ts +4 -0
  57. package/models/props/DataGridProps.d.ts +1 -1
  58. package/modern/DataGrid/DataGrid.js +10 -1
  59. package/modern/components/GridColumnHeaders.js +1 -1
  60. package/modern/components/GridConfigurationContext.js +5 -0
  61. package/modern/components/GridHeaders.js +1 -1
  62. package/modern/components/GridRow.js +6 -8
  63. package/modern/components/GridScrollArea.js +1 -1
  64. package/modern/components/GridSkeletonLoadingOverlay.js +1 -1
  65. package/modern/components/cell/GridCell.js +12 -13
  66. package/modern/components/cell/GridEditSingleSelectCell.js +2 -3
  67. package/modern/components/cell/GridSkeletonCell.js +2 -2
  68. package/modern/components/columnHeaders/GridColumnHeaderItem.js +1 -1
  69. package/modern/components/containers/GridRootStyles.js +9 -2
  70. package/modern/components/menu/columnMenu/GridColumnMenuContainer.js +2 -2
  71. package/modern/components/panel/GridPanel.js +1 -2
  72. package/modern/components/panel/filterPanel/GridFilterForm.js +9 -4
  73. package/modern/components/toolbar/GridToolbarDensitySelector.js +2 -2
  74. package/modern/components/toolbar/GridToolbarExportContainer.js +2 -2
  75. package/modern/components/toolbar/GridToolbarQuickFilter.js +5 -3
  76. package/modern/components/virtualization/GridMainContainer.js +3 -2
  77. package/modern/components/virtualization/GridVirtualScrollerFiller.js +1 -1
  78. package/modern/context/GridContextProvider.js +12 -7
  79. package/modern/hooks/core/useGridStateInitialization.js +1 -3
  80. package/modern/hooks/features/dimensions/useGridDimensions.js +1 -1
  81. package/modern/hooks/features/export/serializers/csvSerializer.js +4 -3
  82. package/modern/hooks/features/filter/gridFilterSelector.js +34 -0
  83. package/modern/hooks/features/filter/index.js +1 -1
  84. package/modern/hooks/features/filter/useGridFilter.js +3 -0
  85. package/modern/hooks/features/rowSelection/useGridRowSelection.js +4 -1
  86. package/modern/hooks/features/rows/useGridParamsApi.js +2 -1
  87. package/modern/hooks/features/rows/useGridRowAriaAttributes.js +19 -0
  88. package/modern/hooks/utils/useGridAriaAttributes.js +5 -8
  89. package/modern/hooks/utils/useGridConfiguration.js +9 -0
  90. package/modern/hooks/utils/useGridSelector.js +39 -1
  91. package/modern/index.js +1 -1
  92. package/modern/internals/index.js +5 -2
  93. package/modern/locales/csCZ.js +4 -5
  94. package/modern/locales/heIL.js +4 -5
  95. package/modern/locales/viVN.js +4 -5
  96. package/modern/models/configuration/gridConfiguration.js +1 -0
  97. package/modern/models/configuration/gridRowConfiguration.js +1 -0
  98. package/modern/utils/createSelector.js +116 -0
  99. package/modern/utils/keyboardUtils.js +1 -11
  100. package/node/DataGrid/DataGrid.js +10 -1
  101. package/node/components/GridColumnHeaders.js +1 -1
  102. package/node/{utils/fastMemo.js → components/GridConfigurationContext.js} +4 -4
  103. package/node/components/GridHeaders.js +1 -1
  104. package/node/components/GridRow.js +6 -8
  105. package/node/components/GridScrollArea.js +1 -1
  106. package/node/components/GridSkeletonLoadingOverlay.js +1 -1
  107. package/node/components/cell/GridCell.js +12 -13
  108. package/node/components/cell/GridEditSingleSelectCell.js +2 -3
  109. package/node/components/cell/GridSkeletonCell.js +2 -2
  110. package/node/components/columnHeaders/GridColumnHeaderItem.js +1 -1
  111. package/node/components/containers/GridRootStyles.js +9 -2
  112. package/node/components/menu/columnMenu/GridColumnMenuContainer.js +1 -1
  113. package/node/components/panel/GridPanel.js +1 -2
  114. package/node/components/panel/filterPanel/GridFilterForm.js +9 -4
  115. package/node/components/toolbar/GridToolbarDensitySelector.js +1 -1
  116. package/node/components/toolbar/GridToolbarExportContainer.js +1 -1
  117. package/node/components/toolbar/GridToolbarQuickFilter.js +5 -3
  118. package/node/components/virtualization/GridMainContainer.js +3 -2
  119. package/node/components/virtualization/GridVirtualScrollerFiller.js +1 -1
  120. package/node/context/GridContextProvider.js +12 -7
  121. package/node/hooks/core/useGridStateInitialization.js +1 -3
  122. package/node/hooks/features/dimensions/useGridDimensions.js +1 -1
  123. package/node/hooks/features/export/serializers/csvSerializer.js +4 -3
  124. package/node/hooks/features/filter/gridFilterSelector.js +35 -1
  125. package/node/hooks/features/filter/index.js +97 -15
  126. package/node/hooks/features/filter/useGridFilter.js +3 -0
  127. package/node/hooks/features/rowSelection/useGridRowSelection.js +4 -1
  128. package/node/hooks/features/rows/useGridParamsApi.js +2 -1
  129. package/node/hooks/features/rows/useGridRowAriaAttributes.js +28 -0
  130. package/node/hooks/utils/useGridAriaAttributes.js +4 -7
  131. package/node/hooks/utils/useGridConfiguration.js +18 -0
  132. package/node/hooks/utils/useGridSelector.js +42 -3
  133. package/node/index.js +1 -1
  134. package/node/internals/index.js +53 -12
  135. package/node/locales/csCZ.js +4 -5
  136. package/node/locales/heIL.js +4 -5
  137. package/node/locales/viVN.js +4 -5
  138. package/node/models/configuration/gridConfiguration.js +5 -0
  139. package/node/models/configuration/gridRowConfiguration.js +5 -0
  140. package/node/utils/createSelector.js +119 -2
  141. package/node/utils/keyboardUtils.js +2 -15
  142. package/package.json +4 -4
  143. package/utils/createSelector.d.ts +19 -0
  144. package/utils/createSelector.js +116 -0
  145. package/utils/keyboardUtils.d.ts +1 -9
  146. package/utils/keyboardUtils.js +1 -11
  147. package/modern/utils/fastMemo.js +0 -5
  148. package/modern/utils/fastObjectShallowCompare.js +0 -28
  149. package/modern/utils/throttle.js +0 -19
  150. package/node/utils/fastObjectShallowCompare.js +0 -34
  151. package/node/utils/throttle.js +0 -25
  152. package/utils/fastMemo.d.ts +0 -1
  153. package/utils/fastMemo.js +0 -5
  154. package/utils/fastObjectShallowCompare.d.ts +0 -1
  155. package/utils/fastObjectShallowCompare.js +0 -28
  156. package/utils/throttle.d.ts +0 -4
  157. package/utils/throttle.js +0 -19
@@ -1,9 +1,11 @@
1
1
  import * as React from 'react';
2
2
  import { GridPrivateApiCommunity } from '../models/api/gridApiCommunity';
3
+ import { GridConfiguration } from '../models/configuration/gridConfiguration';
3
4
  type GridContextProviderProps = {
4
5
  privateApiRef: React.MutableRefObject<GridPrivateApiCommunity>;
6
+ configuration: GridConfiguration;
5
7
  props: {};
6
8
  children: React.ReactNode;
7
9
  };
8
- export declare function GridContextProvider({ privateApiRef, props, children }: GridContextProviderProps): React.JSX.Element;
10
+ export declare function GridContextProvider({ privateApiRef, configuration, props, children, }: GridContextProviderProps): React.JSX.Element;
9
11
  export {};
@@ -2,20 +2,25 @@ import * as React from 'react';
2
2
  import { GridApiContext } from '../components/GridApiContext';
3
3
  import { GridPrivateApiContext } from '../hooks/utils/useGridPrivateApiContext';
4
4
  import { GridRootPropsContext } from './GridRootPropsContext';
5
+ import { GridConfigurationContext } from '../components/GridConfigurationContext';
5
6
  import { jsx as _jsx } from "react/jsx-runtime";
6
7
  export function GridContextProvider({
7
8
  privateApiRef,
9
+ configuration,
8
10
  props,
9
11
  children
10
12
  }) {
11
13
  const apiRef = React.useRef(privateApiRef.current.getPublicApi());
12
- return /*#__PURE__*/_jsx(GridRootPropsContext.Provider, {
13
- value: props,
14
- children: /*#__PURE__*/_jsx(GridPrivateApiContext.Provider, {
15
- value: privateApiRef,
16
- children: /*#__PURE__*/_jsx(GridApiContext.Provider, {
17
- value: apiRef,
18
- children: children
14
+ return /*#__PURE__*/_jsx(GridConfigurationContext.Provider, {
15
+ value: configuration,
16
+ children: /*#__PURE__*/_jsx(GridRootPropsContext.Provider, {
17
+ value: props,
18
+ children: /*#__PURE__*/_jsx(GridPrivateApiContext.Provider, {
19
+ value: privateApiRef,
20
+ children: /*#__PURE__*/_jsx(GridApiContext.Provider, {
21
+ value: apiRef,
22
+ children: children
23
+ })
19
24
  })
20
25
  })
21
26
  });
@@ -48,9 +48,7 @@ export const useGridStateInitialization = apiRef => {
48
48
  if (!ignoreSetState) {
49
49
  // We always assign it as we mutate rows for perf reason.
50
50
  apiRef.current.state = newState;
51
- if (apiRef.current.publishEvent) {
52
- apiRef.current.publishEvent('stateChange', newState);
53
- }
51
+ apiRef.current.publishEvent('stateChange', newState);
54
52
  apiRef.current.store.update(newState);
55
53
  }
56
54
  if (updatedControlStateIds.length === 1) {
@@ -1,9 +1,9 @@
1
1
  import _extends from "@babel/runtime/helpers/esm/extends";
2
2
  import * as React from 'react';
3
3
  import { unstable_ownerDocument as ownerDocument, unstable_useEnhancedEffect as useEnhancedEffect, unstable_useEventCallback as useEventCallback, unstable_ownerWindow as ownerWindow } from '@mui/utils';
4
+ import { throttle } from '@mui/x-internals/throttle';
4
5
  import { useGridApiEventHandler, useGridApiOptionHandler } from '../../utils/useGridApiEventHandler';
5
6
  import { useGridApiMethod } from '../../utils/useGridApiMethod';
6
- import { throttle } from '../../../utils/throttle';
7
7
  import { useGridLogger } from '../../utils/useGridLogger';
8
8
  import { gridColumnsTotalWidthSelector, gridVisiblePinnedColumnDefinitionsSelector } from '../columns';
9
9
  import { gridDimensionsSelector } from './gridDimensionsSelectors';
@@ -1,6 +1,9 @@
1
1
  import { GRID_CHECKBOX_SELECTION_COL_DEF } from '../../../../colDef';
2
2
  import { warnOnce } from '../../../../internals/utils/warning';
3
3
  function sanitizeCellValue(value, csvOptions) {
4
+ if (value === null || value === undefined) {
5
+ return '';
6
+ }
4
7
  const valueStr = typeof value === 'string' ? value : `${value}`;
5
8
  if (csvOptions.shouldAppendQuotes || csvOptions.escapeFormulas) {
6
9
  const escapedValue = valueStr.replace(/"/g, '""');
@@ -51,9 +54,7 @@ class CSVRow {
51
54
  if (!this.isEmpty) {
52
55
  this.rowString += this.options.csvOptions.delimiter;
53
56
  }
54
- if (value === null || value === undefined) {
55
- this.rowString += '';
56
- } else if (typeof this.options.sanitizeCellValue === 'function') {
57
+ if (typeof this.options.sanitizeCellValue === 'function') {
57
58
  this.rowString += this.options.sanitizeCellValue(value, this.options.csvOptions);
58
59
  } else {
59
60
  this.rowString += value;
@@ -1,3 +1,4 @@
1
+ import { GridRowId } from '../../../models/gridRows';
1
2
  import { GridFilterItem } from '../../../models/gridFilterItem';
2
3
  import { GridStateCommunity } from '../../../models/gridStateCommunity';
3
4
  /**
@@ -19,41 +20,53 @@ export declare const gridVisibleRowsLookupSelector: (state: GridStateCommunity)
19
20
  * @category Filtering
20
21
  * @ignore - do not document.
21
22
  */
22
- export declare const gridFilteredRowsLookupSelector: import("../../../utils/createSelector").OutputSelector<GridStateCommunity, Record<import("../../..").GridRowId, boolean>>;
23
+ export declare const gridFilteredRowsLookupSelector: import("../../../utils/createSelector").OutputSelector<GridStateCommunity, Record<GridRowId, boolean>>;
23
24
  /**
24
25
  * @category Filtering
25
26
  * @ignore - do not document.
26
27
  */
27
- export declare const gridFilteredDescendantCountLookupSelector: import("../../../utils/createSelector").OutputSelector<GridStateCommunity, Record<import("../../..").GridRowId, number>>;
28
+ export declare const gridFilteredChildrenCountLookupSelector: import("../../../utils/createSelector").OutputSelector<GridStateCommunity, Record<GridRowId, number>>;
29
+ /**
30
+ * @category Filtering
31
+ * @ignore - do not document.
32
+ */
33
+ export declare const gridFilteredDescendantCountLookupSelector: import("../../../utils/createSelector").OutputSelector<GridStateCommunity, Record<GridRowId, number>>;
28
34
  /**
29
35
  * Get the id and the model of the rows accessible after the filtering process.
30
36
  * Does not contain the collapsed children.
31
37
  * @category Filtering
32
38
  */
33
- export declare const gridExpandedSortedRowEntriesSelector: import("../../../utils/createSelector").OutputSelector<GridStateCommunity, import("../../..").GridRowEntry<import("../../..").GridValidRowModel>[]>;
39
+ export declare const gridExpandedSortedRowEntriesSelector: import("../../../utils/createSelector").OutputSelector<GridStateCommunity, import("../../../models/gridRows").GridRowEntry<import("../../../models/gridRows").GridValidRowModel>[]>;
34
40
  /**
35
41
  * Get the id of the rows accessible after the filtering process.
36
42
  * Does not contain the collapsed children.
37
43
  * @category Filtering
38
44
  */
39
- export declare const gridExpandedSortedRowIdsSelector: import("../../../utils/createSelector").OutputSelector<GridStateCommunity, import("../../..").GridRowId[]>;
45
+ export declare const gridExpandedSortedRowIdsSelector: import("../../../utils/createSelector").OutputSelector<GridStateCommunity, GridRowId[]>;
40
46
  /**
41
47
  * Get the id and the model of the rows accessible after the filtering process.
42
48
  * Contains the collapsed children.
43
49
  * @category Filtering
44
50
  */
45
- export declare const gridFilteredSortedRowEntriesSelector: import("../../../utils/createSelector").OutputSelector<GridStateCommunity, import("../../..").GridRowEntry<import("../../..").GridValidRowModel>[]>;
51
+ export declare const gridFilteredSortedRowEntriesSelector: import("../../../utils/createSelector").OutputSelector<GridStateCommunity, import("../../../models/gridRows").GridRowEntry<import("../../../models/gridRows").GridValidRowModel>[]>;
46
52
  /**
47
53
  * Get the id of the rows accessible after the filtering process.
48
54
  * Contains the collapsed children.
49
55
  * @category Filtering
50
56
  */
51
- export declare const gridFilteredSortedRowIdsSelector: import("../../../utils/createSelector").OutputSelector<GridStateCommunity, import("../../..").GridRowId[]>;
57
+ export declare const gridFilteredSortedRowIdsSelector: import("../../../utils/createSelector").OutputSelector<GridStateCommunity, GridRowId[]>;
58
+ /**
59
+ * Get the ids to position in the current tree level lookup of the rows accessible after the filtering process.
60
+ * Does not contain the collapsed children.
61
+ * @category Filtering
62
+ * @ignore - do not document.
63
+ */
64
+ export declare const gridExpandedSortedRowTreeLevelPositionLookupSelector: import("../../../utils/createSelector").OutputSelector<GridStateCommunity, Record<GridRowId, number>>;
52
65
  /**
53
66
  * Get the id and the model of the top level rows accessible after the filtering process.
54
67
  * @category Filtering
55
68
  */
56
- export declare const gridFilteredSortedTopLevelRowEntriesSelector: import("../../../utils/createSelector").OutputSelector<GridStateCommunity, import("../../..").GridRowEntry<import("../../..").GridValidRowModel>[]>;
69
+ export declare const gridFilteredSortedTopLevelRowEntriesSelector: import("../../../utils/createSelector").OutputSelector<GridStateCommunity, import("../../../models/gridRows").GridRowEntry<import("../../../models/gridRows").GridValidRowModel>[]>;
57
70
  /**
58
71
  * Get the amount of rows accessible after the filtering process.
59
72
  * @category Filtering
@@ -32,6 +32,12 @@ export const gridVisibleRowsLookupSelector = state => state.visibleRowsLookup;
32
32
  */
33
33
  export const gridFilteredRowsLookupSelector = createSelector(gridFilterStateSelector, filterState => filterState.filteredRowsLookup);
34
34
 
35
+ /**
36
+ * @category Filtering
37
+ * @ignore - do not document.
38
+ */
39
+ export const gridFilteredChildrenCountLookupSelector = createSelector(gridFilterStateSelector, filterState => filterState.filteredChildrenCountLookup);
40
+
35
41
  /**
36
42
  * @category Filtering
37
43
  * @ignore - do not document.
@@ -66,6 +72,34 @@ export const gridFilteredSortedRowEntriesSelector = createSelectorMemoized(gridF
66
72
  */
67
73
  export const gridFilteredSortedRowIdsSelector = createSelectorMemoized(gridFilteredSortedRowEntriesSelector, filteredSortedRowEntries => filteredSortedRowEntries.map(row => row.id));
68
74
 
75
+ /**
76
+ * Get the ids to position in the current tree level lookup of the rows accessible after the filtering process.
77
+ * Does not contain the collapsed children.
78
+ * @category Filtering
79
+ * @ignore - do not document.
80
+ */
81
+ export const gridExpandedSortedRowTreeLevelPositionLookupSelector = createSelectorMemoized(gridExpandedSortedRowIdsSelector, gridRowTreeSelector, (visibleSortedRowIds, rowTree) => {
82
+ const depthPositionCounter = {};
83
+ let lastDepth = 0;
84
+ return visibleSortedRowIds.reduce((acc, rowId) => {
85
+ const rowNode = rowTree[rowId];
86
+ if (!depthPositionCounter[rowNode.depth]) {
87
+ depthPositionCounter[rowNode.depth] = 0;
88
+ }
89
+
90
+ // going deeper in the tree should reset the counter
91
+ // since it might have been used in some other branch at the same level, up in the tree
92
+ // going back up should keep the counter and continue where it left off
93
+ if (rowNode.depth > lastDepth) {
94
+ depthPositionCounter[rowNode.depth] = 0;
95
+ }
96
+ lastDepth = rowNode.depth;
97
+ depthPositionCounter[rowNode.depth] += 1;
98
+ acc[rowId] = depthPositionCounter[rowNode.depth];
99
+ return acc;
100
+ }, {});
101
+ });
102
+
69
103
  /**
70
104
  * Get the id and the model of the top level rows accessible after the filtering process.
71
105
  * @category Filtering
@@ -17,6 +17,12 @@ export interface GridFilterState {
17
17
  * This is the equivalent of the `visibleRowsLookup` if all the groups were expanded.
18
18
  */
19
19
  filteredRowsLookup: Record<GridRowId, boolean>;
20
+ /**
21
+ * Amount of children that are passing the filters or have children that are passing the filter (does not count grand children).
22
+ * If a row is not registered in this lookup, it is supposed to have no descendant passing the filters.
23
+ * If `GridDataSource` is being used to load the data, the value is `-1` if there are some children but the count is unknown.
24
+ */
25
+ filteredChildrenCountLookup: Record<GridRowId, number>;
20
26
  /**
21
27
  * Amount of descendants that are passing the filters.
22
28
  * For the Tree Data, it includes all the intermediate depth levels (= amount of children + amount of grand children + ...).
@@ -1,3 +1,4 @@
1
1
  export type { GridFilterState, GridFilterInitialState } from './gridFilterState';
2
2
  export { getDefaultGridFilterModel } from './gridFilterState';
3
- export * from './gridFilterSelector';
3
+ export { gridFilterModelSelector, gridQuickFilterValuesSelector, gridVisibleRowsLookupSelector, gridFilteredRowsLookupSelector, gridFilteredDescendantCountLookupSelector, gridExpandedSortedRowEntriesSelector, gridExpandedSortedRowIdsSelector, gridFilteredSortedRowEntriesSelector, gridFilteredSortedRowIdsSelector, gridFilteredSortedTopLevelRowEntriesSelector, gridExpandedRowCountSelector, gridFilteredTopLevelRowCountSelector, gridFilteredRowCountSelector, gridFilteredDescendantRowCountSelector, gridFilterActiveItemsSelector, gridFilterActiveItemsLookupSelector, } from './gridFilterSelector';
4
+ export type { GridFilterActiveItemsLookup } from './gridFilterSelector';
@@ -1,2 +1,2 @@
1
1
  export { getDefaultGridFilterModel } from './gridFilterState';
2
- export * from './gridFilterSelector';
2
+ export { gridFilterModelSelector, gridQuickFilterValuesSelector, gridVisibleRowsLookupSelector, gridFilteredRowsLookupSelector, gridFilteredDescendantCountLookupSelector, gridExpandedSortedRowEntriesSelector, gridExpandedSortedRowIdsSelector, gridFilteredSortedRowEntriesSelector, gridFilteredSortedRowIdsSelector, gridFilteredSortedTopLevelRowEntriesSelector, gridExpandedRowCountSelector, gridFilteredTopLevelRowCountSelector, gridFilteredRowCountSelector, gridFilteredDescendantRowCountSelector, gridFilterActiveItemsSelector, gridFilterActiveItemsLookupSelector } from './gridFilterSelector';
@@ -23,6 +23,7 @@ export const filterStateInitializer = (state, props, apiRef) => {
23
23
  filter: {
24
24
  filterModel: sanitizeFilterModel(filterModel, props.disableMultipleColumnsFiltering, apiRef),
25
25
  filteredRowsLookup: {},
26
+ filteredChildrenCountLookup: {},
26
27
  filteredDescendantCountLookup: {}
27
28
  },
28
29
  visibleRowsLookup: {}
@@ -273,6 +274,7 @@ export const useGridFilter = (apiRef, props) => {
273
274
  if (props.filterMode !== 'client' || !params.isRowMatchingFilters) {
274
275
  return {
275
276
  filteredRowsLookup: {},
277
+ filteredChildrenCountLookup: {},
276
278
  filteredDescendantCountLookup: {}
277
279
  };
278
280
  }
@@ -301,6 +303,7 @@ export const useGridFilter = (apiRef, props) => {
301
303
  }
302
304
  return {
303
305
  filteredRowsLookup,
306
+ filteredChildrenCountLookup: {},
304
307
  filteredDescendantCountLookup: {}
305
308
  };
306
309
  }, [apiRef, props.filterMode, getRowId, getRowsRef]);
@@ -105,6 +105,9 @@ export const useGridRowSelection = (apiRef, props) => {
105
105
  }, [apiRef, logger, props.rowSelection, props.signature, canHaveMultipleSelection]);
106
106
  const isRowSelected = React.useCallback(id => gridRowSelectionStateSelector(apiRef.current.state).includes(id), [apiRef]);
107
107
  const isRowSelectable = React.useCallback(id => {
108
+ if (props.rowSelection === false) {
109
+ return false;
110
+ }
108
111
  if (propIsRowSelectable && !propIsRowSelectable(apiRef.current.getRowParams(id))) {
109
112
  return false;
110
113
  }
@@ -113,7 +116,7 @@ export const useGridRowSelection = (apiRef, props) => {
113
116
  return false;
114
117
  }
115
118
  return true;
116
- }, [apiRef, propIsRowSelectable]);
119
+ }, [apiRef, props.rowSelection, propIsRowSelectable]);
117
120
  const getSelectedRows = React.useCallback(() => selectedGridRowsSelector(apiRef), [apiRef]);
118
121
  const selectRow = React.useCallback((id, isSelected = true, resetSelection = false) => {
119
122
  if (!apiRef.current.isRowSelectable(id)) {
@@ -51,7 +51,8 @@ export function useGridParamsApi(apiRef) {
51
51
  tabIndex: cellTabIndex && cellTabIndex.field === field && cellTabIndex.id === id ? 0 : -1,
52
52
  value,
53
53
  formattedValue: value,
54
- isEditable: false
54
+ isEditable: false,
55
+ api: {}
55
56
  };
56
57
  if (colDef && colDef.valueFormatter) {
57
58
  params.formattedValue = colDef.valueFormatter(value, row, colDef, apiRef);
@@ -0,0 +1,2 @@
1
+ import { GetRowAriaAttributesFn } from '../../../models/configuration/gridRowConfiguration';
2
+ export declare const useGridRowAriaAttributes: () => GetRowAriaAttributesFn;
@@ -0,0 +1,19 @@
1
+ import * as React from 'react';
2
+ import { selectedIdsLookupSelector } from '../rowSelection';
3
+ import { useGridSelector } from '../../utils/useGridSelector';
4
+ import { gridColumnGroupsHeaderMaxDepthSelector } from '../columnGrouping/gridColumnGroupsSelector';
5
+ import { useGridPrivateApiContext } from '../../utils/useGridPrivateApiContext';
6
+ export const useGridRowAriaAttributes = () => {
7
+ const apiRef = useGridPrivateApiContext();
8
+ const selectedIdsLookup = useGridSelector(apiRef, selectedIdsLookupSelector);
9
+ const headerGroupingMaxDepth = useGridSelector(apiRef, gridColumnGroupsHeaderMaxDepthSelector);
10
+ return React.useCallback((rowNode, index) => {
11
+ const ariaAttributes = {};
12
+ const ariaRowIndex = index + headerGroupingMaxDepth + 2; // 1 for the header row and 1 as it's 1-based
13
+ ariaAttributes['aria-rowindex'] = ariaRowIndex;
14
+ if (apiRef.current.isRowSelectable(rowNode.id)) {
15
+ ariaAttributes['aria-selected'] = selectedIdsLookup[rowNode.id] !== undefined;
16
+ }
17
+ return ariaAttributes;
18
+ }, [apiRef, selectedIdsLookup, headerGroupingMaxDepth]);
19
+ };
@@ -1,6 +1,2 @@
1
- export declare const useGridAriaAttributes: () => {
2
- role: string;
3
- 'aria-colcount': number;
4
- 'aria-rowcount': number;
5
- 'aria-multiselectable': boolean;
6
- };
1
+ import * as React from 'react';
2
+ export declare const useGridAriaAttributes: () => React.HTMLAttributes<HTMLElement>;
@@ -2,24 +2,21 @@ import { gridVisibleColumnDefinitionsSelector } from '../features/columns/gridCo
2
2
  import { useGridSelector } from './useGridSelector';
3
3
  import { useGridRootProps } from './useGridRootProps';
4
4
  import { gridColumnGroupsHeaderMaxDepthSelector } from '../features/columnGrouping/gridColumnGroupsSelector';
5
- import { gridPinnedRowsCountSelector, gridRowCountSelector } from '../features/rows/gridRowsSelector';
5
+ import { gridPinnedRowsCountSelector } from '../features/rows/gridRowsSelector';
6
6
  import { useGridPrivateApiContext } from './useGridPrivateApiContext';
7
7
  import { isMultipleRowSelectionEnabled } from '../features/rowSelection/utils';
8
+ import { gridExpandedRowCountSelector } from '../features/filter/gridFilterSelector';
8
9
  export const useGridAriaAttributes = () => {
9
10
  const apiRef = useGridPrivateApiContext();
10
11
  const rootProps = useGridRootProps();
11
12
  const visibleColumns = useGridSelector(apiRef, gridVisibleColumnDefinitionsSelector);
12
- const totalRowCount = useGridSelector(apiRef, gridRowCountSelector);
13
+ const accessibleRowCount = useGridSelector(apiRef, gridExpandedRowCountSelector);
13
14
  const headerGroupingMaxDepth = useGridSelector(apiRef, gridColumnGroupsHeaderMaxDepthSelector);
14
15
  const pinnedRowsCount = useGridSelector(apiRef, gridPinnedRowsCountSelector);
15
- let role = 'grid';
16
- if (rootProps.treeData) {
17
- role = 'treegrid';
18
- }
19
16
  return {
20
- role,
17
+ role: 'grid',
21
18
  'aria-colcount': visibleColumns.length,
22
- 'aria-rowcount': headerGroupingMaxDepth + 1 + pinnedRowsCount + totalRowCount,
19
+ 'aria-rowcount': headerGroupingMaxDepth + 1 + pinnedRowsCount + accessibleRowCount,
23
20
  'aria-multiselectable': isMultipleRowSelectionEnabled(rootProps)
24
21
  };
25
22
  };
@@ -0,0 +1,2 @@
1
+ import { GridConfiguration } from '../../models/configuration/gridConfiguration';
2
+ export declare const useGridConfiguration: () => GridConfiguration;
@@ -0,0 +1,9 @@
1
+ import * as React from 'react';
2
+ import { GridConfigurationContext } from '../../components/GridConfigurationContext';
3
+ export const useGridConfiguration = () => {
4
+ const configuration = React.useContext(GridConfigurationContext);
5
+ if (configuration === undefined) {
6
+ throw new Error(['MUI X: Could not find the data grid configuration context.', 'It looks like you rendered your component outside of a DataGrid, DataGridPro or DataGridPremium parent component.', 'This can also happen if you are bundling multiple versions of the data grid.'].join('\n'));
7
+ }
8
+ return configuration;
9
+ };
@@ -1,6 +1,9 @@
1
1
  import * as React from 'react';
2
+ import { fastObjectShallowCompare } from '@mui/x-internals/fastObjectShallowCompare';
2
3
  import type { GridApiCommon } from '../../models/api/gridApiCommon';
3
- import { OutputSelector } from '../../utils/createSelector';
4
- import { fastObjectShallowCompare } from '../../utils/fastObjectShallowCompare';
4
+ import { OutputSelector, OutputSelectorV8 } from '../../utils/createSelector';
5
+ type Selector<Api extends GridApiCommon, Args, T> = ((state: Api['state']) => T) | OutputSelectorV8<Api['state'], Args, T>;
5
6
  export declare const objectShallowCompare: typeof fastObjectShallowCompare;
6
7
  export declare const useGridSelector: <Api extends GridApiCommon, T>(apiRef: React.MutableRefObject<Api>, selector: ((state: Api["state"]) => T) | OutputSelector<Api["state"], T>, equals?: (a: T, b: T) => boolean) => T;
8
+ export declare const useGridSelectorV8: <Api extends GridApiCommon, Args, T>(apiRef: React.MutableRefObject<Api>, selector: Selector<Api, Args, T>, args?: Args, equals?: (a: T, b: T) => boolean) => T;
9
+ export {};
@@ -1,17 +1,26 @@
1
1
  import * as React from 'react';
2
+ import { fastObjectShallowCompare } from '@mui/x-internals/fastObjectShallowCompare';
2
3
  import { useLazyRef } from './useLazyRef';
3
4
  import { useOnMount } from './useOnMount';
4
5
  import { warnOnce } from '../../internals/utils/warning';
5
- import { fastObjectShallowCompare } from '../../utils/fastObjectShallowCompare';
6
6
  function isOutputSelector(selector) {
7
7
  return selector.acceptsApiRef;
8
8
  }
9
+ // TODO v8: Remove this function
9
10
  function applySelector(apiRef, selector) {
10
11
  if (isOutputSelector(selector)) {
11
12
  return selector(apiRef);
12
13
  }
13
14
  return selector(apiRef.current.state);
14
15
  }
16
+
17
+ // TODO v8: Rename this function to `applySelector`
18
+ function applySelectorV8(apiRef, selector, args, instanceId) {
19
+ if (isOutputSelector(selector)) {
20
+ return selector(apiRef, args);
21
+ }
22
+ return selector(apiRef.current.state, instanceId);
23
+ }
15
24
  const defaultCompare = Object.is;
16
25
  export const objectShallowCompare = fastObjectShallowCompare;
17
26
  const createRefs = () => ({
@@ -19,6 +28,8 @@ const createRefs = () => ({
19
28
  equals: null,
20
29
  selector: null
21
30
  });
31
+
32
+ // TODO v8: Remove this function
22
33
  export const useGridSelector = (apiRef, selector, equals = defaultCompare) => {
23
34
  if (process.env.NODE_ENV !== 'production') {
24
35
  if (!apiRef.current.state) {
@@ -43,4 +54,31 @@ export const useGridSelector = (apiRef, selector, equals = defaultCompare) => {
43
54
  });
44
55
  });
45
56
  return state;
57
+ };
58
+
59
+ // TODO v8: Rename this function to `useGridSelector`
60
+ export const useGridSelectorV8 = (apiRef, selector, args = undefined, equals = defaultCompare) => {
61
+ if (process.env.NODE_ENV !== 'production') {
62
+ if (!apiRef.current.state) {
63
+ warnOnce(['MUI X: `useGridSelector` has been called before the initialization of the state.', 'This hook can only be used inside the context of the grid.']);
64
+ }
65
+ }
66
+ const refs = useLazyRef(createRefs);
67
+ const didInit = refs.current.selector !== null;
68
+ const [state, setState] = React.useState(
69
+ // We don't use an initialization function to avoid allocations
70
+ didInit ? null : applySelectorV8(apiRef, selector, args, apiRef.current.instanceId));
71
+ refs.current.state = state;
72
+ refs.current.equals = equals;
73
+ refs.current.selector = selector;
74
+ useOnMount(() => {
75
+ return apiRef.current.store.subscribe(() => {
76
+ const newState = applySelectorV8(apiRef, refs.current.selector, args, apiRef.current.instanceId);
77
+ if (!refs.current.equals(refs.current.state, newState)) {
78
+ refs.current.state = newState;
79
+ setState(newState);
80
+ }
81
+ });
82
+ });
83
+ return state;
46
84
  };
package/index.js CHANGED
@@ -1,5 +1,5 @@
1
1
  /**
2
- * @mui/x-data-grid v7.12.1
2
+ * @mui/x-data-grid v7.14.0
3
3
  *
4
4
  * @license MIT
5
5
  * This source code is licensed under the MIT license found in the
@@ -31,6 +31,7 @@ export { useGridCsvExport } from '../hooks/features/export/useGridCsvExport';
31
31
  export { useGridPrintExport } from '../hooks/features/export/useGridPrintExport';
32
32
  export { useGridFilter, filterStateInitializer } from '../hooks/features/filter/useGridFilter';
33
33
  export { passFilterLogic } from '../hooks/features/filter/gridFilterUtils';
34
+ export { gridFilteredChildrenCountLookupSelector, gridExpandedSortedRowTreeLevelPositionLookupSelector, } from '../hooks/features/filter/gridFilterSelector';
34
35
  export { isSingleSelectColDef } from '../components/panel/filterPanel/filterPanelUtils';
35
36
  export type { GridAggregatedFilterItemApplier, GridAggregatedFilterItemApplierResult, } from '../hooks/features/filter/gridFilterState';
36
37
  export { useGridFocus, focusStateInitializer } from '../hooks/features/focus/useGridFocus';
@@ -40,6 +41,8 @@ export { useGridPreferencesPanel, preferencePanelStateInitializer, } from '../ho
40
41
  export { useGridEditing, editingStateInitializer } from '../hooks/features/editing/useGridEditing';
41
42
  export { gridEditRowsStateSelector } from '../hooks/features/editing/gridEditingSelectors';
42
43
  export { useGridRows, rowsStateInitializer } from '../hooks/features/rows/useGridRows';
44
+ export { useGridAriaAttributes } from '../hooks/utils/useGridAriaAttributes';
45
+ export { useGridRowAriaAttributes } from '../hooks/features/rows/useGridRowAriaAttributes';
43
46
  export { useGridRowsPreProcessors } from '../hooks/features/rows/useGridRowsPreProcessors';
44
47
  export type { GridRowTreeCreationParams, GridRowTreeCreationValue, GridHydrateRowsValue, GridRowsPartialUpdates, GridRowsPartialUpdateAction, GridTreeDepths, GridRowTreeUpdatedGroupsManager, GridRowTreeUpdateGroupAction, GridPinnedRowsState, } from '../hooks/features/rows/gridRowsInterfaces';
45
48
  export { getTreeNodeDescendants, buildRootGroup } from '../hooks/features/rows/gridRowsUtils';
@@ -69,12 +72,12 @@ export type * from '../models/props/DataGridProps';
69
72
  export type * from '../models/gridDataSource';
70
73
  export { getColumnsToExport, defaultGetRowsToExport } from '../hooks/features/export/utils';
71
74
  export * from '../utils/createControllablePromise';
72
- export { createSelector, createSelectorMemoized } from '../utils/createSelector';
75
+ export { createSelector, createSelectorV8, createSelectorMemoized, createSelectorMemoizedV8, } from '../utils/createSelector';
76
+ export { useGridSelectorV8 } from '../hooks/utils/useGridSelector';
73
77
  export { gridRowGroupsToFetchSelector } from '../hooks/features/rows/gridRowsSelector';
74
78
  export { findParentElementFromClassName, getActiveElement, isEventTargetInPortal, } from '../utils/domUtils';
75
79
  export { isNavigationKey, isPasteShortcut } from '../utils/keyboardUtils';
76
80
  export * from '../utils/utils';
77
- export * from '../utils/fastMemo';
78
81
  export { exportAs } from '../utils/exportAs';
79
82
  export * from '../utils/getPublicApiRef';
80
83
  export * from '../utils/cellBorderUtils';
@@ -23,6 +23,7 @@ export { useGridCsvExport } from '../hooks/features/export/useGridCsvExport';
23
23
  export { useGridPrintExport } from '../hooks/features/export/useGridPrintExport';
24
24
  export { useGridFilter, filterStateInitializer } from '../hooks/features/filter/useGridFilter';
25
25
  export { passFilterLogic } from '../hooks/features/filter/gridFilterUtils';
26
+ export { gridFilteredChildrenCountLookupSelector, gridExpandedSortedRowTreeLevelPositionLookupSelector } from '../hooks/features/filter/gridFilterSelector';
26
27
  export { isSingleSelectColDef } from '../components/panel/filterPanel/filterPanelUtils';
27
28
  export { useGridFocus, focusStateInitializer } from '../hooks/features/focus/useGridFocus';
28
29
  export { useGridKeyboardNavigation } from '../hooks/features/keyboardNavigation/useGridKeyboardNavigation';
@@ -31,6 +32,8 @@ export { useGridPreferencesPanel, preferencePanelStateInitializer } from '../hoo
31
32
  export { useGridEditing, editingStateInitializer } from '../hooks/features/editing/useGridEditing';
32
33
  export { gridEditRowsStateSelector } from '../hooks/features/editing/gridEditingSelectors';
33
34
  export { useGridRows, rowsStateInitializer } from '../hooks/features/rows/useGridRows';
35
+ export { useGridAriaAttributes } from '../hooks/utils/useGridAriaAttributes';
36
+ export { useGridRowAriaAttributes } from '../hooks/features/rows/useGridRowAriaAttributes';
34
37
  export { useGridRowsPreProcessors } from '../hooks/features/rows/useGridRowsPreProcessors';
35
38
  export { getTreeNodeDescendants, buildRootGroup } from '../hooks/features/rows/gridRowsUtils';
36
39
  export { useGridRowsMeta, rowsMetaStateInitializer } from '../hooks/features/rows/useGridRowsMeta';
@@ -54,12 +57,12 @@ export { useGridVisibleRows, getVisibleRows } from '../hooks/utils/useGridVisibl
54
57
  export { useGridInitializeState } from '../hooks/utils/useGridInitializeState';
55
58
  export { getColumnsToExport, defaultGetRowsToExport } from '../hooks/features/export/utils';
56
59
  export * from '../utils/createControllablePromise';
57
- export { createSelector, createSelectorMemoized } from '../utils/createSelector';
60
+ export { createSelector, createSelectorV8, createSelectorMemoized, createSelectorMemoizedV8 } from '../utils/createSelector';
61
+ export { useGridSelectorV8 } from '../hooks/utils/useGridSelector';
58
62
  export { gridRowGroupsToFetchSelector } from '../hooks/features/rows/gridRowsSelector';
59
63
  export { findParentElementFromClassName, getActiveElement, isEventTargetInPortal } from '../utils/domUtils';
60
64
  export { isNavigationKey, isPasteShortcut } from '../utils/keyboardUtils';
61
65
  export * from '../utils/utils';
62
- export * from '../utils/fastMemo';
63
66
  export { exportAs } from '../utils/exportAs';
64
67
  export * from '../utils/getPublicApiRef';
65
68
  export * from '../utils/cellBorderUtils';
package/locales/csCZ.js CHANGED
@@ -38,11 +38,10 @@ const csCZGrid = {
38
38
  toolbarExportPrint: 'Vytisknout',
39
39
  toolbarExportExcel: 'Stáhnout jako Excel',
40
40
  // Columns management text
41
- // columnsManagementSearchTitle: 'Search',
42
- // columnsManagementNoColumns: 'No columns',
43
- // columnsManagementShowHideAllText: 'Show/Hide All',
44
- // columnsManagementReset: 'Reset',
45
-
41
+ columnsManagementSearchTitle: 'Hledat sloupce',
42
+ columnsManagementNoColumns: 'Žádné sloupce',
43
+ columnsManagementShowHideAllText: 'Zobrazit/skrýt vše',
44
+ columnsManagementReset: 'Resetovat',
46
45
  // Filter panel text
47
46
  filterPanelAddFilter: 'Přidat filtr',
48
47
  filterPanelRemoveAll: 'Odstranit vše',
package/locales/heIL.js CHANGED
@@ -30,11 +30,10 @@ const heILGrid = {
30
30
  toolbarExportPrint: 'הדפסה',
31
31
  toolbarExportExcel: 'ייצוא ל- Excel',
32
32
  // Columns management text
33
- // columnsManagementSearchTitle: 'Search',
34
- // columnsManagementNoColumns: 'No columns',
35
- // columnsManagementShowHideAllText: 'Show/Hide All',
36
- // columnsManagementReset: 'Reset',
37
-
33
+ columnsManagementSearchTitle: 'חיפוש',
34
+ columnsManagementNoColumns: 'אין עמודות',
35
+ columnsManagementShowHideAllText: 'הצג/הסתר הכל',
36
+ columnsManagementReset: 'אתחול',
38
37
  // Filter panel text
39
38
  filterPanelAddFilter: 'הוסף מסנן',
40
39
  filterPanelRemoveAll: 'מחק הכל',
package/locales/viVN.js CHANGED
@@ -30,11 +30,10 @@ const viVNGrid = {
30
30
  toolbarExportPrint: 'In',
31
31
  toolbarExportExcel: 'Xuất Excel',
32
32
  // Columns management text
33
- // columnsManagementSearchTitle: 'Search',
34
- // columnsManagementNoColumns: 'No columns',
35
- // columnsManagementShowHideAllText: 'Show/Hide All',
36
- // columnsManagementReset: 'Reset',
37
-
33
+ columnsManagementSearchTitle: 'Tìm kiếm',
34
+ columnsManagementNoColumns: 'Không có cột',
35
+ columnsManagementShowHideAllText: 'Hiện/Ẩn Tất cả',
36
+ columnsManagementReset: 'Đặt lại',
38
37
  // Filter panel text
39
38
  filterPanelAddFilter: 'Thêm bộ lọc',
40
39
  filterPanelRemoveAll: 'Xóa tất cả',
@@ -0,0 +1,10 @@
1
+ import * as React from 'react';
2
+ import { GridRowAriaAttributesInternalHook } from './gridRowConfiguration';
3
+ export interface GridAriaAttributesInternalHook {
4
+ useGridAriaAttributes: () => React.HTMLAttributes<HTMLElement>;
5
+ }
6
+ export interface GridInternalHook extends GridAriaAttributesInternalHook, GridRowAriaAttributesInternalHook {
7
+ }
8
+ export interface GridConfiguration {
9
+ hooks: GridInternalHook;
10
+ }
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,12 @@
1
+ import * as React from 'react';
2
+ import { GridTreeNode } from '../gridRows';
3
+ /**
4
+ * Get the ARIA attributes for a row
5
+ * @param {GridTreeNode} rowNode The row node
6
+ * @param {number} index The position index of the row
7
+ * @returns {React.HTMLAttributes<HTMLElement>} The ARIA attributes
8
+ */
9
+ export type GetRowAriaAttributesFn = (rowNode: GridTreeNode, index: number) => React.HTMLAttributes<HTMLElement>;
10
+ export interface GridRowAriaAttributesInternalHook {
11
+ useGridRowAriaAttributes: () => GetRowAriaAttributesFn;
12
+ }
@@ -0,0 +1 @@
1
+ export {};