@mui/x-data-grid-pro 5.17.5 → 6.0.0-alpha.1

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 (129) hide show
  1. package/CHANGELOG.md +297 -19
  2. package/DataGridPro/DataGridPro.js +4 -14
  3. package/DataGridPro/useDataGridProProps.js +2 -2
  4. package/components/DataGridProVirtualScroller.js +2 -2
  5. package/components/GridDetailPanelToggleCell.js +1 -1
  6. package/components/GridRowReorderCell.js +4 -6
  7. package/components/GridTreeDataGroupingCell.d.ts +2 -2
  8. package/components/GridTreeDataGroupingCell.js +1 -1
  9. package/hooks/features/detailPanel/useGridDetailPanel.js +2 -2
  10. package/hooks/features/detailPanel/useGridDetailPanelCache.js +2 -2
  11. package/hooks/features/infiniteLoader/useGridInfiniteLoader.js +2 -2
  12. package/hooks/features/lazyLoader/useGridLazyLoader.js +20 -9
  13. package/hooks/features/lazyLoader/useGridLazyLoaderPreProcessors.d.ts +1 -1
  14. package/hooks/features/lazyLoader/useGridLazyLoaderPreProcessors.js +20 -6
  15. package/hooks/features/rowPinning/gridRowPinningInterface.d.ts +2 -2
  16. package/hooks/features/rowPinning/useGridRowPinningPreProcessors.d.ts +16 -16
  17. package/hooks/features/rowPinning/useGridRowPinningPreProcessors.js +62 -25
  18. package/hooks/features/rowReorder/useGridRowReorder.js +5 -5
  19. package/hooks/features/treeData/gridTreeDataGroupColDef.js +1 -1
  20. package/hooks/features/treeData/gridTreeDataUtils.js +14 -12
  21. package/hooks/features/treeData/useGridTreeData.js +2 -6
  22. package/hooks/features/treeData/useGridTreeDataPreProcessors.js +35 -18
  23. package/index.js +1 -1
  24. package/internals/index.d.ts +4 -2
  25. package/internals/index.js +4 -2
  26. package/legacy/DataGridPro/DataGridPro.js +4 -14
  27. package/legacy/DataGridPro/useDataGridProProps.js +2 -2
  28. package/legacy/components/DataGridProVirtualScroller.js +2 -2
  29. package/legacy/components/GridDetailPanelToggleCell.js +1 -1
  30. package/legacy/components/GridRowReorderCell.js +4 -6
  31. package/legacy/components/GridTreeDataGroupingCell.js +1 -1
  32. package/legacy/hooks/features/detailPanel/useGridDetailPanel.js +2 -2
  33. package/legacy/hooks/features/detailPanel/useGridDetailPanelCache.js +2 -2
  34. package/legacy/hooks/features/infiniteLoader/useGridInfiniteLoader.js +2 -2
  35. package/legacy/hooks/features/lazyLoader/useGridLazyLoader.js +25 -15
  36. package/legacy/hooks/features/lazyLoader/useGridLazyLoaderPreProcessors.js +21 -7
  37. package/legacy/hooks/features/rowPinning/useGridRowPinningPreProcessors.js +62 -25
  38. package/legacy/hooks/features/rowReorder/useGridRowReorder.js +5 -5
  39. package/legacy/hooks/features/treeData/gridTreeDataGroupColDef.js +1 -1
  40. package/legacy/hooks/features/treeData/gridTreeDataUtils.js +14 -12
  41. package/legacy/hooks/features/treeData/useGridTreeData.js +2 -6
  42. package/legacy/hooks/features/treeData/useGridTreeDataPreProcessors.js +37 -22
  43. package/legacy/index.js +1 -1
  44. package/legacy/internals/index.js +4 -2
  45. package/legacy/utils/tree/createRowTree.js +36 -0
  46. package/legacy/utils/tree/index.js +1 -1
  47. package/legacy/utils/tree/insertDataRowInTree.js +127 -0
  48. package/legacy/utils/tree/models.js +1 -0
  49. package/legacy/utils/tree/removeDataRowFromTree.js +97 -0
  50. package/legacy/utils/tree/sortRowTree.js +49 -43
  51. package/legacy/utils/tree/updateRowTree.js +81 -0
  52. package/legacy/utils/tree/utils.js +184 -0
  53. package/models/dataGridProProps.d.ts +3 -3
  54. package/modern/DataGridPro/DataGridPro.js +4 -14
  55. package/modern/DataGridPro/useDataGridProProps.js +2 -2
  56. package/modern/components/DataGridProVirtualScroller.js +2 -2
  57. package/modern/components/GridDetailPanelToggleCell.js +1 -1
  58. package/modern/components/GridRowReorderCell.js +4 -4
  59. package/modern/components/GridTreeDataGroupingCell.js +1 -1
  60. package/modern/hooks/features/detailPanel/useGridDetailPanel.js +2 -2
  61. package/modern/hooks/features/detailPanel/useGridDetailPanelCache.js +2 -2
  62. package/modern/hooks/features/infiniteLoader/useGridInfiniteLoader.js +2 -2
  63. package/modern/hooks/features/lazyLoader/useGridLazyLoader.js +20 -9
  64. package/modern/hooks/features/lazyLoader/useGridLazyLoaderPreProcessors.js +20 -6
  65. package/modern/hooks/features/rowPinning/useGridRowPinningPreProcessors.js +60 -23
  66. package/modern/hooks/features/rowReorder/useGridRowReorder.js +5 -3
  67. package/modern/hooks/features/treeData/gridTreeDataGroupColDef.js +1 -1
  68. package/modern/hooks/features/treeData/gridTreeDataUtils.js +13 -9
  69. package/modern/hooks/features/treeData/useGridTreeData.js +2 -4
  70. package/modern/hooks/features/treeData/useGridTreeDataPreProcessors.js +35 -18
  71. package/modern/index.js +1 -1
  72. package/modern/internals/index.js +4 -2
  73. package/modern/utils/tree/createRowTree.js +35 -0
  74. package/modern/utils/tree/index.js +1 -1
  75. package/modern/utils/tree/insertDataRowInTree.js +127 -0
  76. package/modern/utils/tree/models.js +1 -0
  77. package/modern/utils/tree/removeDataRowFromTree.js +100 -0
  78. package/modern/utils/tree/sortRowTree.js +46 -40
  79. package/modern/utils/tree/updateRowTree.js +83 -0
  80. package/modern/utils/tree/utils.js +180 -0
  81. package/node/DataGridPro/DataGridPro.js +4 -14
  82. package/node/DataGridPro/useDataGridProProps.js +1 -1
  83. package/node/components/DataGridProVirtualScroller.js +1 -1
  84. package/node/components/GridDetailPanelToggleCell.js +1 -1
  85. package/node/components/GridRowReorderCell.js +3 -5
  86. package/node/components/GridTreeDataGroupingCell.js +1 -1
  87. package/node/hooks/features/detailPanel/useGridDetailPanel.js +1 -1
  88. package/node/hooks/features/detailPanel/useGridDetailPanelCache.js +1 -1
  89. package/node/hooks/features/infiniteLoader/useGridInfiniteLoader.js +1 -1
  90. package/node/hooks/features/lazyLoader/useGridLazyLoader.js +19 -8
  91. package/node/hooks/features/lazyLoader/useGridLazyLoaderPreProcessors.js +18 -5
  92. package/node/hooks/features/rowPinning/useGridRowPinningPreProcessors.js +63 -26
  93. package/node/hooks/features/rowReorder/useGridRowReorder.js +4 -4
  94. package/node/hooks/features/treeData/gridTreeDataGroupColDef.js +1 -1
  95. package/node/hooks/features/treeData/gridTreeDataUtils.js +14 -12
  96. package/node/hooks/features/treeData/useGridTreeData.js +1 -5
  97. package/node/hooks/features/treeData/useGridTreeDataPreProcessors.js +35 -17
  98. package/node/index.js +1 -1
  99. package/node/internals/index.js +35 -10
  100. package/node/utils/tree/createRowTree.js +46 -0
  101. package/node/utils/tree/index.js +2 -2
  102. package/node/utils/tree/insertDataRowInTree.js +139 -0
  103. package/node/utils/tree/models.js +5 -0
  104. package/node/utils/tree/removeDataRowFromTree.js +110 -0
  105. package/node/utils/tree/sortRowTree.js +50 -43
  106. package/node/utils/tree/updateRowTree.js +98 -0
  107. package/node/utils/tree/utils.js +217 -0
  108. package/package.json +5 -5
  109. package/utils/tree/createRowTree.d.ts +15 -0
  110. package/utils/tree/createRowTree.js +35 -0
  111. package/utils/tree/index.d.ts +1 -1
  112. package/utils/tree/index.js +1 -1
  113. package/utils/tree/insertDataRowInTree.d.ts +51 -0
  114. package/utils/tree/insertDataRowInTree.js +129 -0
  115. package/utils/tree/models.d.ts +13 -0
  116. package/utils/tree/models.js +1 -0
  117. package/utils/tree/removeDataRowFromTree.d.ts +40 -0
  118. package/utils/tree/removeDataRowFromTree.js +100 -0
  119. package/utils/tree/sortRowTree.d.ts +6 -1
  120. package/utils/tree/sortRowTree.js +46 -40
  121. package/utils/tree/updateRowTree.d.ts +19 -0
  122. package/utils/tree/updateRowTree.js +83 -0
  123. package/utils/tree/utils.d.ts +66 -0
  124. package/utils/tree/utils.js +186 -0
  125. package/legacy/utils/tree/buildRowTree.js +0 -195
  126. package/modern/utils/tree/buildRowTree.js +0 -174
  127. package/node/utils/tree/buildRowTree.js +0 -195
  128. package/utils/tree/buildRowTree.d.ts +0 -48
  129. package/utils/tree/buildRowTree.js +0 -186
@@ -36,12 +36,10 @@ const useUtilityClasses = ownerState => {
36
36
  };
37
37
 
38
38
  const GridRowReorderCell = params => {
39
- var _params$rowNode$posit;
40
-
41
39
  const apiRef = (0, _xDataGrid.useGridApiContext)();
42
40
  const rootProps = (0, _useGridRootProps.useGridRootProps)();
43
41
  const sortModel = (0, _xDataGrid.useGridSelector)(apiRef, _xDataGrid.gridSortModelSelector);
44
- const treeDepth = (0, _xDataGrid.useGridSelector)(apiRef, _xDataGrid.gridRowTreeDepthSelector);
42
+ const treeDepth = (0, _xDataGrid.useGridSelector)(apiRef, _xDataGrid.gridRowMaximumTreeDepthSelector);
45
43
  const editRowsState = (0, _xDataGrid.useGridSelector)(apiRef, _xDataGrid.gridEditRowsStateSelector); // eslint-disable-next-line no-underscore-dangle
46
44
 
47
45
  const cellValue = params.row.__reorder__ || params.id; // TODO: remove sortModel and treeDepth checks once row reorder is compatible
@@ -77,7 +75,7 @@ const GridRowReorderCell = params => {
77
75
  onDragEnd: publish('rowDragEnd')
78
76
  } : null;
79
77
 
80
- if (((_params$rowNode$posit = params.rowNode.position) != null ? _params$rowNode$posit : 'body') !== 'body') {
78
+ if (params.rowNode.type === 'footer') {
81
79
  return null;
82
80
  }
83
81
 
@@ -95,7 +93,7 @@ const GridRowReorderCell = params => {
95
93
  exports.GridRowReorderCell = GridRowReorderCell;
96
94
 
97
95
  const renderRowReorderCell = params => {
98
- if (params.rowNode.isPinned) {
96
+ if (params.rowNode.type === 'footer' || params.rowNode.type === 'pinnedRow') {
99
97
  return null;
100
98
  }
101
99
 
@@ -173,7 +173,7 @@ process.env.NODE_ENV !== "production" ? GridTreeDataGroupingCell.propTypes = {
173
173
  /**
174
174
  * The row model of the row that the current cell belongs to.
175
175
  */
176
- row: _propTypes.default.object.isRequired,
176
+ row: _propTypes.default.any.isRequired,
177
177
 
178
178
  /**
179
179
  * The node of the row that the current cell belongs to.
@@ -43,7 +43,7 @@ function cacheContentAndHeight(apiRef, getDetailPanelContent, getDetailPanelHeig
43
43
  // only call getDetailPanelContent when asked for an id
44
44
 
45
45
 
46
- const rowIds = (0, _xDataGrid.gridRowIdsSelector)(apiRef);
46
+ const rowIds = (0, _xDataGrid.gridDataRowIdsSelector)(apiRef);
47
47
  const contentCache = rowIds.reduce((acc, id) => {
48
48
  const params = apiRef.current.getRowParams(id);
49
49
  acc[id] = getDetailPanelContent(params);
@@ -24,7 +24,7 @@ function cacheContentAndHeight(apiRef, getDetailPanelContent, getDetailPanelHeig
24
24
  // only call getDetailPanelContent when asked for an id
25
25
 
26
26
 
27
- const rowIds = (0, _xDataGrid.gridRowIdsSelector)(apiRef);
27
+ const rowIds = (0, _xDataGrid.gridDataRowIdsSelector)(apiRef);
28
28
  const contentCache = rowIds.reduce((acc, id) => {
29
29
  const params = apiRef.current.getRowParams(id);
30
30
  acc[id] = getDetailPanelContent(params);
@@ -29,7 +29,7 @@ const useGridInfiniteLoader = (apiRef, props) => {
29
29
  const handleRowsScrollEnd = React.useCallback(scrollPosition => {
30
30
  const dimensions = apiRef.current.getRootDimensions(); // Prevent the infite loading working in combination with lazy loading
31
31
 
32
- if (!dimensions || props.rowsLoadingMode !== _xDataGrid.GridFeatureModeConstant.client) {
32
+ if (!dimensions || props.rowsLoadingMode !== 'client') {
33
33
  return;
34
34
  }
35
35
 
@@ -15,7 +15,11 @@ function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "functio
15
15
 
16
16
  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; }
17
17
 
18
- function findSkeletonRowsSection(visibleRows, range) {
18
+ function findSkeletonRowsSection({
19
+ apiRef,
20
+ visibleRows,
21
+ range
22
+ }) {
19
23
  let {
20
24
  firstRowIndex,
21
25
  lastRowIndex
@@ -26,16 +30,19 @@ function findSkeletonRowsSection(visibleRows, range) {
26
30
  let isSkeletonSectionFound = false;
27
31
 
28
32
  while (!isSkeletonSectionFound && firstRowIndex < lastRowIndex) {
29
- if (!visibleRowsSection[startIndex].model && !visibleRowsSection[endIndex].model) {
33
+ const isStartingWithASkeletonRow = apiRef.current.getRowNode(visibleRowsSection[startIndex].id).type === 'skeletonRow';
34
+ const isEndingWithASkeletonRow = apiRef.current.getRowNode(visibleRowsSection[endIndex].id).type === 'skeletonRow';
35
+
36
+ if (isStartingWithASkeletonRow && isEndingWithASkeletonRow) {
30
37
  isSkeletonSectionFound = true;
31
38
  }
32
39
 
33
- if (visibleRowsSection[startIndex].model) {
40
+ if (!isStartingWithASkeletonRow) {
34
41
  startIndex += 1;
35
42
  firstRowIndex += 1;
36
43
  }
37
44
 
38
- if (visibleRowsSection[endIndex].model) {
45
+ if (!isEndingWithASkeletonRow) {
39
46
  endIndex -= 1;
40
47
  lastRowIndex -= 1;
41
48
  }
@@ -56,7 +63,7 @@ function isLazyLoadingDisabled({
56
63
  return true;
57
64
  }
58
65
 
59
- if (rowsLoadingMode !== _xDataGrid.GridFeatureModeConstant.server) {
66
+ if (rowsLoadingMode !== 'server') {
60
67
  return true;
61
68
  }
62
69
 
@@ -120,9 +127,13 @@ const useGridLazyLoader = (apiRef, props) => {
120
127
  }
121
128
 
122
129
  if (sortModel.length === 0 && filterModel.items.length === 0) {
123
- const skeletonRowsSection = findSkeletonRowsSection(visibleRows.rows, {
124
- firstRowIndex: params.firstRowToRender,
125
- lastRowIndex: params.lastRowToRender
130
+ const skeletonRowsSection = findSkeletonRowsSection({
131
+ apiRef,
132
+ visibleRows: visibleRows.rows,
133
+ range: {
134
+ firstRowIndex: params.firstRowToRender,
135
+ lastRowIndex: params.lastRowToRender
136
+ }
126
137
  });
127
138
 
128
139
  if (!skeletonRowsSection) {
@@ -31,19 +31,32 @@ const useGridLazyLoaderPreProcessors = (apiRef, props) => {
31
31
  lazyLoading
32
32
  } = (_props$experimentalFe = props.experimentalFeatures) != null ? _props$experimentalFe : {};
33
33
  const addSkeletonRows = React.useCallback(groupingParams => {
34
- if (!lazyLoading || props.rowsLoadingMode !== _xDataGrid.GridFeatureModeConstant.server || !props.rowCount || groupingParams.ids.length >= props.rowCount) {
34
+ const tree = (0, _extends2.default)({}, groupingParams.tree);
35
+ const rootGroup = tree[_xDataGrid.GRID_ROOT_GROUP_ID];
36
+
37
+ if (!lazyLoading || props.rowsLoadingMode !== 'server' || !props.rowCount || rootGroup.children.length >= props.rowCount) {
35
38
  return groupingParams;
36
39
  }
37
40
 
38
- const newRowsIds = [...groupingParams.ids];
41
+ const rootGroupChildren = [...rootGroup.children];
39
42
 
40
- for (let i = 0; i < props.rowCount - groupingParams.ids.length; i += 1) {
43
+ for (let i = 0; i < props.rowCount - rootGroup.children.length; i += 1) {
41
44
  const skeletonId = getSkeletonRowId(i);
42
- newRowsIds.push(skeletonId);
45
+ rootGroupChildren.push(skeletonId);
46
+ const skeletonRowNode = {
47
+ type: 'skeletonRow',
48
+ id: skeletonId,
49
+ parent: _xDataGrid.GRID_ROOT_GROUP_ID,
50
+ depth: 0
51
+ };
52
+ tree[skeletonId] = skeletonRowNode;
43
53
  }
44
54
 
55
+ tree[_xDataGrid.GRID_ROOT_GROUP_ID] = (0, _extends2.default)({}, rootGroup, {
56
+ children: rootGroupChildren
57
+ });
45
58
  return (0, _extends2.default)({}, groupingParams, {
46
- ids: newRowsIds
59
+ tree
47
60
  });
48
61
  }, [props.rowCount, props.rowsLoadingMode, lazyLoading]);
49
62
  (0, _internals.useGridRegisterPipeProcessor)(apiRef, 'hydrateRows', addSkeletonRows);
@@ -14,6 +14,10 @@ var React = _interopRequireWildcard(require("react"));
14
14
 
15
15
  var _internals = require("@mui/x-data-grid/internals");
16
16
 
17
+ var _xDataGrid = require("@mui/x-data-grid");
18
+
19
+ var _utils = require("../../../utils/tree/utils");
20
+
17
21
  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); }
18
22
 
19
23
  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; }
@@ -23,35 +27,57 @@ function addPinnedRow({
23
27
  rowModel,
24
28
  rowId,
25
29
  position,
26
- apiRef
30
+ apiRef,
31
+ isAutoGenerated
27
32
  }) {
28
- var _groupingParams$addit;
33
+ var _groupingParams$addit, _groupingParams$addit2, _groupingParams$addit3, _groupingParams$addit4;
29
34
 
30
- const idRowsLookup = (0, _extends2.default)({}, groupingParams.idRowsLookup);
31
- const tree = (0, _extends2.default)({}, groupingParams.tree); // TODO: warn if id is already present in `props.rows`
35
+ const dataRowIdToModelLookup = (0, _extends2.default)({}, groupingParams.dataRowIdToModelLookup);
36
+ const dataRowIdToIdLookup = (0, _extends2.default)({}, groupingParams.dataRowIdToIdLookup);
37
+ const tree = (0, _extends2.default)({}, groupingParams.tree);
38
+ const treeDepths = (0, _extends2.default)({}, groupingParams.treeDepths); // TODO: warn if id is already present in `props.rows`
32
39
 
33
- idRowsLookup[rowId] = rowModel; // Do not push it to ids list so that pagination is not affected by pinned rows
34
- // ids.push(rowId);
35
-
36
- tree[rowId] = {
40
+ const node = {
41
+ type: 'pinnedRow',
37
42
  id: rowId,
38
- isAutoGenerated: false,
39
- parent: null,
40
43
  depth: 0,
41
- groupingKey: null,
42
- groupingField: null,
43
- isPinned: true
44
+ parent: _xDataGrid.GRID_ROOT_GROUP_ID,
45
+ isAutoGenerated
44
46
  };
45
- apiRef.current.unstable_caches.rows.idRowsLookup[rowId] = (0, _extends2.default)({}, rowModel);
46
- apiRef.current.unstable_caches.rows.idToIdLookup[rowId] = rowId;
47
+ (0, _utils.insertNodeInTree)({
48
+ node,
49
+ tree,
50
+ treeDepths
51
+ });
52
+
53
+ if (!isAutoGenerated) {
54
+ dataRowIdToModelLookup[rowId] = rowModel;
55
+ dataRowIdToIdLookup[rowId] = rowId;
56
+ } // Do not push it to ids list so that pagination is not affected by pinned rows
57
+
58
+
59
+ apiRef.current.unstable_caches.rows.dataRowIdToModelLookup[rowId] = (0, _extends2.default)({}, rowModel);
60
+ apiRef.current.unstable_caches.rows.dataRowIdToIdLookup[rowId] = rowId;
47
61
  const previousPinnedRows = ((_groupingParams$addit = groupingParams.additionalRowGroups) == null ? void 0 : _groupingParams$addit.pinnedRows) || {};
48
62
  const newPinnedRow = {
49
63
  id: rowId,
50
64
  model: rowModel
51
65
  };
66
+
67
+ if ((_groupingParams$addit2 = groupingParams.additionalRowGroups) != null && (_groupingParams$addit3 = _groupingParams$addit2.pinnedRows) != null && (_groupingParams$addit4 = _groupingParams$addit3[position]) != null && _groupingParams$addit4.includes(newPinnedRow)) {
68
+ return (0, _extends2.default)({}, groupingParams, {
69
+ dataRowIdToModelLookup,
70
+ dataRowIdToIdLookup,
71
+ tree,
72
+ treeDepths
73
+ });
74
+ }
75
+
52
76
  return (0, _extends2.default)({}, groupingParams, {
53
- idRowsLookup,
77
+ dataRowIdToModelLookup,
78
+ dataRowIdToIdLookup,
54
79
  tree,
80
+ treeDepths,
55
81
  additionalRowGroups: (0, _extends2.default)({}, groupingParams.additionalRowGroups, {
56
82
  pinnedRows: (0, _extends2.default)({}, previousPinnedRows, {
57
83
  [position]: [...(previousPinnedRows[position] || []), newPinnedRow]
@@ -62,7 +88,7 @@ function addPinnedRow({
62
88
 
63
89
  const useGridRowPinningPreProcessors = apiRef => {
64
90
  const addPinnedRows = React.useCallback(groupingParams => {
65
- var _pinnedRowsCache$topI, _pinnedRowsCache$bott;
91
+ var _pinnedRowsCache$topI, _pinnedRowsCache$bott, _pinnedRowsCache$bott2, _pinnedRowsCache$topI2;
66
92
 
67
93
  const pinnedRowsCache = apiRef.current.unstable_caches.pinnedRows || {};
68
94
  let newGroupingParams = (0, _extends2.default)({}, groupingParams, {
@@ -77,7 +103,8 @@ const useGridRowPinningPreProcessors = apiRef => {
77
103
  rowModel: pinnedRowsCache.idLookup[rowId],
78
104
  rowId,
79
105
  position: 'top',
80
- apiRef
106
+ apiRef,
107
+ isAutoGenerated: false
81
108
  });
82
109
  });
83
110
  (_pinnedRowsCache$bott = pinnedRowsCache.bottomIds) == null ? void 0 : _pinnedRowsCache$bott.forEach(rowId => {
@@ -86,17 +113,27 @@ const useGridRowPinningPreProcessors = apiRef => {
86
113
  rowModel: pinnedRowsCache.idLookup[rowId],
87
114
  rowId,
88
115
  position: 'bottom',
89
- apiRef
116
+ apiRef,
117
+ isAutoGenerated: false
90
118
  });
91
- }); // If row with the same `id` is present both in `rows` and `pinnedRows` - remove it from `ids`
119
+ }); // If row with the same `id` is present both in `rows` and `pinnedRows` - remove it from the root group children
92
120
 
93
- newGroupingParams.ids = newGroupingParams.ids.filter(rowId => {
94
- if (newGroupingParams.tree[rowId] && newGroupingParams.tree[rowId].isPinned) {
95
- return false;
96
- }
121
+ if ((_pinnedRowsCache$bott2 = pinnedRowsCache.bottomIds) != null && _pinnedRowsCache$bott2.length || (_pinnedRowsCache$topI2 = pinnedRowsCache.topIds) != null && _pinnedRowsCache$topI2.length) {
122
+ const shouldKeepRow = rowId => {
123
+ if (newGroupingParams.tree[rowId] && newGroupingParams.tree[rowId].type === 'pinnedRow') {
124
+ return false;
125
+ }
126
+
127
+ return true;
128
+ };
129
+
130
+ const rootGroupNode = newGroupingParams.tree[_xDataGrid.GRID_ROOT_GROUP_ID];
131
+ newGroupingParams.tree[_xDataGrid.GRID_ROOT_GROUP_ID] = (0, _extends2.default)({}, rootGroupNode, {
132
+ children: rootGroupNode.children.filter(shouldKeepRow)
133
+ });
134
+ newGroupingParams.dataRowIds = newGroupingParams.dataRowIds.filter(shouldKeepRow);
135
+ }
97
136
 
98
- return true;
99
- });
100
137
  return newGroupingParams;
101
138
  }, [apiRef]);
102
139
  (0, _internals.useGridRegisterPipeProcessor)(apiRef, 'hydrateRows', addPinnedRows);
@@ -33,7 +33,7 @@ const useUtilityClasses = ownerState => {
33
33
  const useGridRowReorder = (apiRef, props) => {
34
34
  const logger = (0, _xDataGrid.useGridLogger)(apiRef, 'useGridRowReorder');
35
35
  const sortModel = (0, _xDataGrid.useGridSelector)(apiRef, _xDataGrid.gridSortModelSelector);
36
- const treeDepth = (0, _xDataGrid.useGridSelector)(apiRef, _xDataGrid.gridRowTreeDepthSelector);
36
+ const treeDepth = (0, _xDataGrid.useGridSelector)(apiRef, _xDataGrid.gridRowMaximumTreeDepthSelector);
37
37
  const dragRowNode = React.useRef(null);
38
38
  const originRowIndex = React.useRef(null);
39
39
  const removeDnDStylesTimeout = React.useRef();
@@ -73,13 +73,13 @@ const useGridRowReorder = (apiRef, props) => {
73
73
  originRowIndex.current = apiRef.current.getRowIndex(params.id);
74
74
  }, [isRowReorderDisabled, classes.rowDragging, logger, apiRef]);
75
75
  const handleDragOver = React.useCallback((params, event) => {
76
- var _apiRef$current$getRo;
77
-
78
76
  if (dragRowId === '') {
79
77
  return;
80
78
  }
81
79
 
82
- if ((_apiRef$current$getRo = apiRef.current.getRowNode(params.id)) != null && _apiRef$current$getRo.isPinned) {
80
+ const rowNode = apiRef.current.getRowNode(params.id);
81
+
82
+ if (!rowNode || rowNode.type === 'footer' || rowNode.type === 'pinnedRow') {
83
83
  return;
84
84
  }
85
85
 
@@ -22,7 +22,7 @@ const GRID_TREE_DATA_GROUPING_COL_DEF = (0, _extends2.default)({}, _xDataGrid.GR
22
22
  disableReorder: true,
23
23
  align: 'left',
24
24
  width: 200,
25
- valueGetter: params => params.rowNode.groupingKey
25
+ valueGetter: params => params.rowNode.type === 'group' ? params.rowNode.groupingKey : undefined
26
26
  });
27
27
  exports.GRID_TREE_DATA_GROUPING_COL_DEF = GRID_TREE_DATA_GROUPING_COL_DEF;
28
28
  const GRID_TREE_DATA_GROUPING_FIELD = '__tree_data_group__';
@@ -27,14 +27,12 @@ const filterRowTreeFromTreeData = params => {
27
27
  const filteredDescendantCountLookup = {};
28
28
 
29
29
  const filterTreeNode = (node, isParentMatchingFilters, areAncestorsExpanded) => {
30
- var _node$children;
31
-
32
30
  const shouldSkipFilters = disableChildrenFiltering && node.depth > 0;
33
31
  let isMatchingFilters;
34
32
 
35
33
  if (shouldSkipFilters) {
36
34
  isMatchingFilters = null;
37
- } else if (!isRowMatchingFilters || node.position === 'footer') {
35
+ } else if (!isRowMatchingFilters || node.type === 'footer') {
38
36
  isMatchingFilters = true;
39
37
  } else {
40
38
  const {
@@ -45,13 +43,17 @@ const filterRowTreeFromTreeData = params => {
45
43
  }
46
44
 
47
45
  let filteredDescendantCount = 0;
48
- (_node$children = node.children) == null ? void 0 : _node$children.forEach(childId => {
49
- var _isMatchingFilters;
50
46
 
51
- const childNode = rowTree[childId];
52
- const childSubTreeSize = filterTreeNode(childNode, (_isMatchingFilters = isMatchingFilters) != null ? _isMatchingFilters : isParentMatchingFilters, areAncestorsExpanded && !!node.childrenExpanded);
53
- filteredDescendantCount += childSubTreeSize;
54
- });
47
+ if (node.type === 'group') {
48
+ node.children.forEach(childId => {
49
+ var _isMatchingFilters;
50
+
51
+ const childNode = rowTree[childId];
52
+ const childSubTreeSize = filterTreeNode(childNode, (_isMatchingFilters = isMatchingFilters) != null ? _isMatchingFilters : isParentMatchingFilters, areAncestorsExpanded && !!node.childrenExpanded);
53
+ filteredDescendantCount += childSubTreeSize;
54
+ });
55
+ }
56
+
55
57
  let shouldPassFilters;
56
58
 
57
59
  switch (isMatchingFilters) {
@@ -75,9 +77,9 @@ const filterRowTreeFromTreeData = params => {
75
77
  }
76
78
 
77
79
  visibleRowsLookup[node.id] = shouldPassFilters && areAncestorsExpanded;
78
- filteredRowsLookup[node.id] = shouldPassFilters;
80
+ filteredRowsLookup[node.id] = shouldPassFilters; // TODO: Should we keep storing the visibility status of footer independently or rely on the group visibility in the selector ?
79
81
 
80
- if (node.footerId != null) {
82
+ if (node.type === 'group' && node.footerId != null) {
81
83
  visibleRowsLookup[node.footerId] = shouldPassFilters && areAncestorsExpanded && !!node.childrenExpanded;
82
84
  }
83
85
 
@@ -87,7 +89,7 @@ const filterRowTreeFromTreeData = params => {
87
89
 
88
90
  filteredDescendantCountLookup[node.id] = filteredDescendantCount;
89
91
 
90
- if (node.position === 'footer') {
92
+ if (node.type === 'footer') {
91
93
  return filteredDescendantCount;
92
94
  }
93
95
 
@@ -21,11 +21,7 @@ const useGridTreeData = apiRef => {
21
21
  const cellParams = apiRef.current.getCellParams(params.id, params.field);
22
22
 
23
23
  if (cellParams.colDef.type === 'treeDataGroup' && event.key === ' ' && !event.shiftKey) {
24
- var _gridFilteredDescenda;
25
-
26
- const filteredDescendantCount = (_gridFilteredDescenda = (0, _xDataGrid.gridFilteredDescendantCountLookupSelector)(apiRef)[params.id]) != null ? _gridFilteredDescenda : 0;
27
-
28
- if (filteredDescendantCount === 0) {
24
+ if (params.rowNode.type !== 'group') {
29
25
  return;
30
26
  }
31
27
 
@@ -23,10 +23,12 @@ var _gridTreeDataUtils = require("./gridTreeDataUtils");
23
23
 
24
24
  var _components = require("../../../components");
25
25
 
26
- var _buildRowTree = require("../../../utils/tree/buildRowTree");
26
+ var _createRowTree = require("../../../utils/tree/createRowTree");
27
27
 
28
28
  var _sortRowTree = require("../../../utils/tree/sortRowTree");
29
29
 
30
+ var _updateRowTree = require("../../../utils/tree/updateRowTree");
31
+
30
32
  var _jsxRuntime = require("react/jsx-runtime");
31
33
 
32
34
  const _excluded = ["hideDescendantCount"];
@@ -95,28 +97,45 @@ const useGridTreeDataPreProcessors = (apiRef, props) => {
95
97
 
96
98
  return columnsState;
97
99
  }, [props.treeData, getGroupingColDef]);
98
- const createRowTree = React.useCallback(params => {
100
+ const createRowTreeForTreeData = React.useCallback(params => {
99
101
  if (!props.getTreeDataPath) {
100
102
  throw new Error('MUI: No getTreeDataPath given.');
101
103
  }
102
104
 
103
- const rows = params.ids.map(rowId => ({
105
+ const getRowTreeBuilderNode = rowId => ({
104
106
  id: rowId,
105
- path: props.getTreeDataPath(params.idRowsLookup[rowId]).map(key => ({
107
+ path: props.getTreeDataPath(params.dataRowIdToModelLookup[rowId]).map(key => ({
106
108
  key,
107
109
  field: null
108
110
  }))
109
- })).sort((a, b) => a.path.length - b.path.length);
110
- return (0, _buildRowTree.buildRowTree)((0, _extends2.default)({
111
- rows
112
- }, params, {
111
+ });
112
+
113
+ const onDuplicatePath = (firstId, secondId, path) => {
114
+ throw new Error(['MUI: The path returned by `getTreeDataPath` should be unique.', `The rows with id #${firstId} and #${secondId} have the same.`, `Path: ${JSON.stringify(path.map(step => step.key))}.`].join('\n'));
115
+ };
116
+
117
+ if (params.updates.type === 'full') {
118
+ return (0, _createRowTree.createRowTree)({
119
+ nodes: params.updates.rows.map(getRowTreeBuilderNode),
120
+ defaultGroupingExpansionDepth: props.defaultGroupingExpansionDepth,
121
+ isGroupExpandedByDefault: props.isGroupExpandedByDefault,
122
+ groupingName: _gridTreeDataUtils.TREE_DATA_STRATEGY,
123
+ onDuplicatePath
124
+ });
125
+ }
126
+
127
+ return (0, _updateRowTree.updateRowTree)({
128
+ nodes: {
129
+ inserted: params.updates.actions.insert.map(getRowTreeBuilderNode),
130
+ modified: params.updates.actions.modify.map(getRowTreeBuilderNode),
131
+ removed: params.updates.actions.remove
132
+ },
133
+ previousTree: params.previousTree,
134
+ previousTreeDepth: params.previousTreeDepths,
113
135
  defaultGroupingExpansionDepth: props.defaultGroupingExpansionDepth,
114
136
  isGroupExpandedByDefault: props.isGroupExpandedByDefault,
115
- groupingName: _gridTreeDataUtils.TREE_DATA_STRATEGY,
116
- onDuplicatePath: (firstId, secondId, path) => {
117
- throw new Error(['MUI: The path returned by `getTreeDataPath` should be unique.', `The rows with id #${firstId} and #${secondId} have the same.`, `Path: ${JSON.stringify(path.map(step => step.key))}.`].join('\n'));
118
- }
119
- }));
137
+ groupingName: _gridTreeDataUtils.TREE_DATA_STRATEGY
138
+ });
120
139
  }, [props.getTreeDataPath, props.defaultGroupingExpansionDepth, props.isGroupExpandedByDefault]);
121
140
  const filterRows = React.useCallback(params => {
122
141
  const rowTree = (0, _xDataGrid.gridRowTreeSelector)(apiRef);
@@ -130,16 +149,15 @@ const useGridTreeDataPreProcessors = (apiRef, props) => {
130
149
  }, [apiRef, props.disableChildrenFiltering]);
131
150
  const sortRows = React.useCallback(params => {
132
151
  const rowTree = (0, _xDataGrid.gridRowTreeSelector)(apiRef);
133
- const rowIds = (0, _xDataGrid.gridRowIdsSelector)(apiRef);
134
152
  return (0, _sortRowTree.sortRowTree)({
135
153
  rowTree,
136
- rowIds,
137
154
  sortRowList: params.sortRowList,
138
- disableChildrenSorting: props.disableChildrenSorting
155
+ disableChildrenSorting: props.disableChildrenSorting,
156
+ shouldRenderGroupBelowLeaves: false
139
157
  });
140
158
  }, [apiRef, props.disableChildrenSorting]);
141
159
  (0, _internals.useGridRegisterPipeProcessor)(apiRef, 'hydrateColumns', updateGroupingColumn);
142
- (0, _internals.useGridRegisterStrategyProcessor)(apiRef, _gridTreeDataUtils.TREE_DATA_STRATEGY, 'rowTreeCreation', createRowTree);
160
+ (0, _internals.useGridRegisterStrategyProcessor)(apiRef, _gridTreeDataUtils.TREE_DATA_STRATEGY, 'rowTreeCreation', createRowTreeForTreeData);
143
161
  (0, _internals.useGridRegisterStrategyProcessor)(apiRef, _gridTreeDataUtils.TREE_DATA_STRATEGY, 'filtering', filterRows);
144
162
  (0, _internals.useGridRegisterStrategyProcessor)(apiRef, _gridTreeDataUtils.TREE_DATA_STRATEGY, 'sorting', sortRows);
145
163
  /**
package/node/index.js CHANGED
@@ -1,4 +1,4 @@
1
- /** @license MUI v5.17.5
1
+ /** @license MUI v6.0.0-alpha.1
2
2
  *
3
3
  * This source code is licensed under the MIT license found in the
4
4
  * LICENSE file in the root directory of this source tree.
@@ -26,8 +26,11 @@ var _exportNames = {
26
26
  rowPinningStateInitializer: true,
27
27
  useGridRowPinningPreProcessors: true,
28
28
  addPinnedRow: true,
29
- buildRowTree: true,
30
- sortRowTree: true
29
+ createRowTree: true,
30
+ updateRowTree: true,
31
+ sortRowTree: true,
32
+ insertNodeInTree: true,
33
+ removeNodeFromTree: true
31
34
  };
32
35
  Object.defineProperty(exports, "DataGridProColumnHeaders", {
33
36
  enumerable: true,
@@ -53,12 +56,6 @@ Object.defineProperty(exports, "addPinnedRow", {
53
56
  return _useGridRowPinningPreProcessors.addPinnedRow;
54
57
  }
55
58
  });
56
- Object.defineProperty(exports, "buildRowTree", {
57
- enumerable: true,
58
- get: function () {
59
- return _buildRowTree.buildRowTree;
60
- }
61
- });
62
59
  Object.defineProperty(exports, "columnPinningStateInitializer", {
63
60
  enumerable: true,
64
61
  get: function () {
@@ -77,12 +74,30 @@ Object.defineProperty(exports, "columnResizeStateInitializer", {
77
74
  return _useGridColumnResize.columnResizeStateInitializer;
78
75
  }
79
76
  });
77
+ Object.defineProperty(exports, "createRowTree", {
78
+ enumerable: true,
79
+ get: function () {
80
+ return _createRowTree.createRowTree;
81
+ }
82
+ });
80
83
  Object.defineProperty(exports, "detailPanelStateInitializer", {
81
84
  enumerable: true,
82
85
  get: function () {
83
86
  return _useGridDetailPanel.detailPanelStateInitializer;
84
87
  }
85
88
  });
89
+ Object.defineProperty(exports, "insertNodeInTree", {
90
+ enumerable: true,
91
+ get: function () {
92
+ return _utils.insertNodeInTree;
93
+ }
94
+ });
95
+ Object.defineProperty(exports, "removeNodeFromTree", {
96
+ enumerable: true,
97
+ get: function () {
98
+ return _utils.removeNodeFromTree;
99
+ }
100
+ });
86
101
  Object.defineProperty(exports, "rowPinningStateInitializer", {
87
102
  enumerable: true,
88
103
  get: function () {
@@ -95,6 +110,12 @@ Object.defineProperty(exports, "sortRowTree", {
95
110
  return _sortRowTree.sortRowTree;
96
111
  }
97
112
  });
113
+ Object.defineProperty(exports, "updateRowTree", {
114
+ enumerable: true,
115
+ get: function () {
116
+ return _updateRowTree.updateRowTree;
117
+ }
118
+ });
98
119
  Object.defineProperty(exports, "useGridColumnPinning", {
99
120
  enumerable: true,
100
121
  get: function () {
@@ -220,6 +241,10 @@ var _useGridRowPinning = require("../hooks/features/rowPinning/useGridRowPinning
220
241
 
221
242
  var _useGridRowPinningPreProcessors = require("../hooks/features/rowPinning/useGridRowPinningPreProcessors");
222
243
 
223
- var _buildRowTree = require("../utils/tree/buildRowTree");
244
+ var _createRowTree = require("../utils/tree/createRowTree");
245
+
246
+ var _updateRowTree = require("../utils/tree/updateRowTree");
247
+
248
+ var _sortRowTree = require("../utils/tree/sortRowTree");
224
249
 
225
- var _sortRowTree = require("../utils/tree/sortRowTree");
250
+ var _utils = require("../utils/tree/utils");
@@ -0,0 +1,46 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.createRowTree = void 0;
7
+
8
+ var _xDataGrid = require("@mui/x-data-grid");
9
+
10
+ var _internals = require("@mui/x-data-grid/internals");
11
+
12
+ var _insertDataRowInTree = require("./insertDataRowInTree");
13
+
14
+ /**
15
+ * Transform a list of rows into a tree structure where each row references its parent and children.
16
+ */
17
+ const createRowTree = params => {
18
+ const dataRowIds = [];
19
+ const tree = {
20
+ [_xDataGrid.GRID_ROOT_GROUP_ID]: (0, _internals.buildRootGroup)()
21
+ };
22
+ const treeDepths = {};
23
+
24
+ for (let i = 0; i < params.nodes.length; i += 1) {
25
+ const node = params.nodes[i];
26
+ dataRowIds.push(node.id);
27
+ (0, _insertDataRowInTree.insertDataRowInTree)({
28
+ tree,
29
+ id: node.id,
30
+ path: node.path,
31
+ onDuplicatePath: params.onDuplicatePath,
32
+ treeDepths,
33
+ isGroupExpandedByDefault: params.isGroupExpandedByDefault,
34
+ defaultGroupingExpansionDepth: params.defaultGroupingExpansionDepth
35
+ });
36
+ }
37
+
38
+ return {
39
+ tree,
40
+ treeDepths,
41
+ groupingName: params.groupingName,
42
+ dataRowIds
43
+ };
44
+ };
45
+
46
+ exports.createRowTree = createRowTree;