@mui/x-tree-view 8.11.1 → 8.11.2
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.
- package/CHANGELOG.md +95 -0
- package/esm/hooks/index.d.ts +2 -1
- package/esm/hooks/index.js +2 -1
- package/esm/hooks/useApplyPropagationToSelectedItemsOnMount.d.ts +53 -0
- package/esm/hooks/useApplyPropagationToSelectedItemsOnMount.js +80 -0
- package/esm/index.js +1 -1
- package/esm/internals/plugins/useTreeViewItems/useTreeViewItems.js +4 -3
- package/hooks/index.d.ts +2 -1
- package/hooks/index.js +8 -1
- package/hooks/useApplyPropagationToSelectedItemsOnMount.d.ts +53 -0
- package/hooks/useApplyPropagationToSelectedItemsOnMount.js +87 -0
- package/index.js +1 -1
- package/internals/plugins/useTreeViewItems/useTreeViewItems.js +4 -3
- package/package.json +4 -4
package/CHANGELOG.md
CHANGED
|
@@ -5,6 +5,101 @@
|
|
|
5
5
|
All notable changes to this project will be documented in this file.
|
|
6
6
|
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
|
|
7
7
|
|
|
8
|
+
## 8.11.2
|
|
9
|
+
|
|
10
|
+
_Sep 10, 2025_
|
|
11
|
+
|
|
12
|
+
We'd like to extend a big thank you to the 13 contributors who made this release possible. Here are some highlights ✨:
|
|
13
|
+
|
|
14
|
+
- 🐞 Bugfixes
|
|
15
|
+
- 📚 Documentation improvements
|
|
16
|
+
|
|
17
|
+
Special thanks go out to the community members for their valuable contributions:
|
|
18
|
+
@ludvigeriksson, @sai6855
|
|
19
|
+
|
|
20
|
+
The following are all team members who have contributed to this release:
|
|
21
|
+
@alexfauquette, @bernardobelchior, @brijeshb42, @flaviendelangle, @Janpot, @LukasTy, @MBilalShafi, @noraleonte, @rita-codes, @romgrk, @siriwatknp
|
|
22
|
+
|
|
23
|
+
### Data Grid
|
|
24
|
+
|
|
25
|
+
#### `@mui/x-data-grid@8.11.2`
|
|
26
|
+
|
|
27
|
+
- [DataGrid] Allow opting out of the exclude row selection model (#19423) @MBilalShafi
|
|
28
|
+
- [DataGrid] Fix column dropdown menu text alignment for the "Unpin" menu item (#19462) @MBilalShafi
|
|
29
|
+
- [DataGrid] Fix indeterminate state for "Select all" checkbox with exclude model (#19466) @MBilalShafi
|
|
30
|
+
- [DataGrid] Fix styled API arguments error (#19460) @MBilalShafi
|
|
31
|
+
- [DataGrid] Fix `stringify()` for theme objects (#19427) @romgrk
|
|
32
|
+
|
|
33
|
+
#### `@mui/x-data-grid-pro@8.11.2` [](https://mui.com/r/x-pro-svg-link 'Pro plan')
|
|
34
|
+
|
|
35
|
+
Same changes as in `@mui/x-data-grid@8.11.2`.
|
|
36
|
+
|
|
37
|
+
#### `@mui/x-data-grid-premium@8.11.2` [](https://mui.com/r/x-premium-svg-link 'Premium plan')
|
|
38
|
+
|
|
39
|
+
Same changes as in `@mui/x-data-grid-pro@8.11.2`, plus:
|
|
40
|
+
|
|
41
|
+
- [DataGridPremium] Fallback to the regular reorder method for plain data (#19467) @MBilalShafi
|
|
42
|
+
- [DataGridPremium] Fix showing `0` as total aggregation value when aggregation position is set to `null` for row groups (#19515) @cherniavskii
|
|
43
|
+
|
|
44
|
+
### Date and Time Pickers
|
|
45
|
+
|
|
46
|
+
#### `@mui/x-date-pickers@8.11.2`
|
|
47
|
+
|
|
48
|
+
- [pickers] Gracefully handle `textField.slotProps` (#18980) @LukasTy
|
|
49
|
+
- [pickers] Improve hour and minute placement in Date Time Picker (#19227) @MBilalShafi
|
|
50
|
+
- [pickers] Use `calendarState.currentMonth` in Month Calendar when available (#19073) @LukasTy
|
|
51
|
+
- [pickers] Improve invalid value pasting into a section (#19357) @sai6855
|
|
52
|
+
- [fields] Remove redundant `id` and `aria-labelledby` attributes from spinbuttons (#19523) @LukasTy
|
|
53
|
+
|
|
54
|
+
#### `@mui/x-date-pickers-pro@8.11.2` [](https://mui.com/r/x-pro-svg-link 'Pro plan')
|
|
55
|
+
|
|
56
|
+
Same changes as in `@mui/x-date-pickers@8.11.2`.
|
|
57
|
+
|
|
58
|
+
### Charts
|
|
59
|
+
|
|
60
|
+
#### `@mui/x-charts@8.11.2`
|
|
61
|
+
|
|
62
|
+
- [charts] Fix highlight regression (#19486) @alexfauquette
|
|
63
|
+
- [charts] Improve code reuse in `ChartsXAxis` and `ChartsYAxis` (#19198) @bernardobelchior
|
|
64
|
+
- [charts] Simplify params in `getRange` and `createDateFormatter` (#19517) @bernardobelchior
|
|
65
|
+
- [charts] Handle domain edge cases with `filterMode: 'discard'` (#19199) @bernardobelchior
|
|
66
|
+
- [l10n] Add Swedish (sv-SE) locale (#19489) @ludvigeriksson
|
|
67
|
+
|
|
68
|
+
#### `@mui/x-charts-pro@8.11.2` [](https://mui.com/r/x-pro-svg-link 'Pro plan')
|
|
69
|
+
|
|
70
|
+
Same changes as in `@mui/x-charts@8.11.2`.
|
|
71
|
+
|
|
72
|
+
### Tree View
|
|
73
|
+
|
|
74
|
+
#### `@mui/x-tree-view@8.11.2`
|
|
75
|
+
|
|
76
|
+
- [TreeView] Do not mutate `props.items` in the `getItemTree()` method (#19483) @flaviendelangle
|
|
77
|
+
- [TreeView] Expose a new hook to apply selection propagation on the selected items (#19402) @flaviendelangle
|
|
78
|
+
|
|
79
|
+
#### `@mui/x-tree-view-pro@8.11.2` [](https://mui.com/r/x-pro-svg-link 'Pro plan')
|
|
80
|
+
|
|
81
|
+
Same changes as in `@mui/x-tree-view@8.11.2`.
|
|
82
|
+
|
|
83
|
+
### Codemod
|
|
84
|
+
|
|
85
|
+
#### `@mui/x-codemod@8.11.2`
|
|
86
|
+
|
|
87
|
+
Internal changes.
|
|
88
|
+
|
|
89
|
+
### Docs
|
|
90
|
+
|
|
91
|
+
- [docs] Add recipe for save and manage filters from the panel (#19361) @siriwatknp
|
|
92
|
+
|
|
93
|
+
### Core
|
|
94
|
+
|
|
95
|
+
- [code-infra] Remove log when restarting dev server (#19490) @bernardobelchior
|
|
96
|
+
- [code-infra] Store test results in CI (#19507) @Janpot
|
|
97
|
+
|
|
98
|
+
### Miscellaneous
|
|
99
|
+
|
|
100
|
+
- [infra] Set nodejs versions of various CIs to 22.18 (#19503) @brijeshb42
|
|
101
|
+
- [test] Split infinitive @romgrk
|
|
102
|
+
|
|
8
103
|
## 8.11.1
|
|
9
104
|
|
|
10
105
|
_Sep 4, 2025_
|
package/esm/hooks/index.d.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
1
|
export { useTreeViewApiRef } from "./useTreeViewApiRef.js";
|
|
2
2
|
export { useTreeItemUtils } from "./useTreeItemUtils/index.js";
|
|
3
|
-
export { useTreeItemModel } from "./useTreeItemModel.js";
|
|
3
|
+
export { useTreeItemModel } from "./useTreeItemModel.js";
|
|
4
|
+
export { useApplyPropagationToSelectedItemsOnMount } from "./useApplyPropagationToSelectedItemsOnMount.js";
|
package/esm/hooks/index.js
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
1
|
export { useTreeViewApiRef } from "./useTreeViewApiRef.js";
|
|
2
2
|
export { useTreeItemUtils } from "./useTreeItemUtils/index.js";
|
|
3
|
-
export { useTreeItemModel } from "./useTreeItemModel.js";
|
|
3
|
+
export { useTreeItemModel } from "./useTreeItemModel.js";
|
|
4
|
+
export { useApplyPropagationToSelectedItemsOnMount } from "./useApplyPropagationToSelectedItemsOnMount.js";
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
import { TreeViewItemId, TreeViewSelectionPropagation } from "../models/index.js";
|
|
2
|
+
/**
|
|
3
|
+
* Applies the selection propagation rules to the selected items.
|
|
4
|
+
* The value is only computed during the first render, any update of the parameters will be ignored.
|
|
5
|
+
*
|
|
6
|
+
* Uncontrolled example:
|
|
7
|
+
* ```tsx
|
|
8
|
+
* const defaultSelectedItems = useApplyPropagationToSelectedItemsOnMount({
|
|
9
|
+
* items: props.items,
|
|
10
|
+
* selectionPropagation: props.selectionPropagation,
|
|
11
|
+
* selectedItems: ['10', '11', '13', '14'],
|
|
12
|
+
* });
|
|
13
|
+
*
|
|
14
|
+
* return (
|
|
15
|
+
* <RichTreeView
|
|
16
|
+
* items={props.items}
|
|
17
|
+
* selectionPropagation={props.selectionPropagation}
|
|
18
|
+
* defaultSelectedItems={defaultSelectedItems}
|
|
19
|
+
* />
|
|
20
|
+
* );
|
|
21
|
+
* ```
|
|
22
|
+
*
|
|
23
|
+
* Controlled example:
|
|
24
|
+
* ```tsx
|
|
25
|
+
* const initialSelectedItems = useApplyPropagationToSelectedItemsOnMount({
|
|
26
|
+
* items: props.items,
|
|
27
|
+
* selectionPropagation: props.selectionPropagation,
|
|
28
|
+
* selectedItems: ['10', '11', '13', '14'],
|
|
29
|
+
* });
|
|
30
|
+
*
|
|
31
|
+
* const [selectedItems, setSelectedItems] = React.useState(initialSelectedItems);
|
|
32
|
+
*
|
|
33
|
+
* return (
|
|
34
|
+
* <RichTreeView
|
|
35
|
+
* items={props.items}
|
|
36
|
+
* selectionPropagation={props.selectionPropagation}
|
|
37
|
+
* selectedItems={selectedItems}
|
|
38
|
+
* onSelectedItemsChange={setSelectedItems}
|
|
39
|
+
* />
|
|
40
|
+
* );
|
|
41
|
+
* ```
|
|
42
|
+
*/
|
|
43
|
+
export declare function useApplyPropagationToSelectedItemsOnMount(parameters: UseApplyPropagationToDefaultSelectedItemsParameters<any>): string[];
|
|
44
|
+
interface UseApplyPropagationToDefaultSelectedItemsParameters<R extends {
|
|
45
|
+
children?: R[];
|
|
46
|
+
}> {
|
|
47
|
+
items: R[];
|
|
48
|
+
getItemId?: (item: R) => TreeViewItemId;
|
|
49
|
+
getItemChildren?: (item: R) => R[] | undefined;
|
|
50
|
+
selectedItems: string[];
|
|
51
|
+
selectionPropagation: TreeViewSelectionPropagation;
|
|
52
|
+
}
|
|
53
|
+
export {};
|
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
import useLazyRef from '@mui/utils/useLazyRef';
|
|
2
|
+
import { getLookupFromArray } from "../internals/plugins/useTreeViewSelection/useTreeViewSelection.utils.js";
|
|
3
|
+
const defaultGetItemId = item => item.id;
|
|
4
|
+
const defaultGetItemChildren = item => item.children;
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* Applies the selection propagation rules to the selected items.
|
|
8
|
+
* The value is only computed during the first render, any update of the parameters will be ignored.
|
|
9
|
+
*
|
|
10
|
+
* Uncontrolled example:
|
|
11
|
+
* ```tsx
|
|
12
|
+
* const defaultSelectedItems = useApplyPropagationToSelectedItemsOnMount({
|
|
13
|
+
* items: props.items,
|
|
14
|
+
* selectionPropagation: props.selectionPropagation,
|
|
15
|
+
* selectedItems: ['10', '11', '13', '14'],
|
|
16
|
+
* });
|
|
17
|
+
*
|
|
18
|
+
* return (
|
|
19
|
+
* <RichTreeView
|
|
20
|
+
* items={props.items}
|
|
21
|
+
* selectionPropagation={props.selectionPropagation}
|
|
22
|
+
* defaultSelectedItems={defaultSelectedItems}
|
|
23
|
+
* />
|
|
24
|
+
* );
|
|
25
|
+
* ```
|
|
26
|
+
*
|
|
27
|
+
* Controlled example:
|
|
28
|
+
* ```tsx
|
|
29
|
+
* const initialSelectedItems = useApplyPropagationToSelectedItemsOnMount({
|
|
30
|
+
* items: props.items,
|
|
31
|
+
* selectionPropagation: props.selectionPropagation,
|
|
32
|
+
* selectedItems: ['10', '11', '13', '14'],
|
|
33
|
+
* });
|
|
34
|
+
*
|
|
35
|
+
* const [selectedItems, setSelectedItems] = React.useState(initialSelectedItems);
|
|
36
|
+
*
|
|
37
|
+
* return (
|
|
38
|
+
* <RichTreeView
|
|
39
|
+
* items={props.items}
|
|
40
|
+
* selectionPropagation={props.selectionPropagation}
|
|
41
|
+
* selectedItems={selectedItems}
|
|
42
|
+
* onSelectedItemsChange={setSelectedItems}
|
|
43
|
+
* />
|
|
44
|
+
* );
|
|
45
|
+
* ```
|
|
46
|
+
*/
|
|
47
|
+
export function useApplyPropagationToSelectedItemsOnMount(parameters) {
|
|
48
|
+
const {
|
|
49
|
+
items: itemsParam,
|
|
50
|
+
getItemId = defaultGetItemId,
|
|
51
|
+
getItemChildren = defaultGetItemChildren,
|
|
52
|
+
selectedItems,
|
|
53
|
+
selectionPropagation
|
|
54
|
+
} = parameters;
|
|
55
|
+
return useLazyRef(() => {
|
|
56
|
+
const lookup = getLookupFromArray(selectedItems);
|
|
57
|
+
function walk(items, isParentSelected) {
|
|
58
|
+
for (const item of items) {
|
|
59
|
+
const itemId = getItemId(item);
|
|
60
|
+
let isSelected = lookup[itemId];
|
|
61
|
+
if (!isSelected && selectionPropagation.descendants && isParentSelected) {
|
|
62
|
+
lookup[itemId] = true;
|
|
63
|
+
isSelected = true;
|
|
64
|
+
}
|
|
65
|
+
const children = getItemChildren(item) ?? [];
|
|
66
|
+
if (children.length > 0) {
|
|
67
|
+
walk(children, isSelected);
|
|
68
|
+
if (!isSelected && selectionPropagation.parents) {
|
|
69
|
+
const areAllChildrenSelected = children.every(childId => lookup[getItemId(childId)]);
|
|
70
|
+
if (areAllChildrenSelected) {
|
|
71
|
+
lookup[itemId] = true;
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
walk(itemsParam, false);
|
|
78
|
+
return Object.keys(lookup);
|
|
79
|
+
}).current;
|
|
80
|
+
}
|
package/esm/index.js
CHANGED
|
@@ -115,13 +115,14 @@ export const useTreeViewItems = ({
|
|
|
115
115
|
const getItemTree = React.useCallback(() => {
|
|
116
116
|
const getItemFromItemId = itemId => {
|
|
117
117
|
const item = itemsSelectors.itemModel(store.state, itemId);
|
|
118
|
+
const itemToMutate = _extends({}, item);
|
|
118
119
|
const newChildren = itemsSelectors.itemOrderedChildrenIds(store.state, itemId);
|
|
119
120
|
if (newChildren.length > 0) {
|
|
120
|
-
|
|
121
|
+
itemToMutate.children = newChildren.map(getItemFromItemId);
|
|
121
122
|
} else {
|
|
122
|
-
delete
|
|
123
|
+
delete itemToMutate.children;
|
|
123
124
|
}
|
|
124
|
-
return
|
|
125
|
+
return itemToMutate;
|
|
125
126
|
};
|
|
126
127
|
return itemsSelectors.itemOrderedChildrenIds(store.state, null).map(getItemFromItemId);
|
|
127
128
|
}, [store]);
|
package/hooks/index.d.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
1
|
export { useTreeViewApiRef } from "./useTreeViewApiRef.js";
|
|
2
2
|
export { useTreeItemUtils } from "./useTreeItemUtils/index.js";
|
|
3
|
-
export { useTreeItemModel } from "./useTreeItemModel.js";
|
|
3
|
+
export { useTreeItemModel } from "./useTreeItemModel.js";
|
|
4
|
+
export { useApplyPropagationToSelectedItemsOnMount } from "./useApplyPropagationToSelectedItemsOnMount.js";
|
package/hooks/index.js
CHANGED
|
@@ -3,6 +3,12 @@
|
|
|
3
3
|
Object.defineProperty(exports, "__esModule", {
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
|
+
Object.defineProperty(exports, "useApplyPropagationToSelectedItemsOnMount", {
|
|
7
|
+
enumerable: true,
|
|
8
|
+
get: function () {
|
|
9
|
+
return _useApplyPropagationToSelectedItemsOnMount.useApplyPropagationToSelectedItemsOnMount;
|
|
10
|
+
}
|
|
11
|
+
});
|
|
6
12
|
Object.defineProperty(exports, "useTreeItemModel", {
|
|
7
13
|
enumerable: true,
|
|
8
14
|
get: function () {
|
|
@@ -23,4 +29,5 @@ Object.defineProperty(exports, "useTreeViewApiRef", {
|
|
|
23
29
|
});
|
|
24
30
|
var _useTreeViewApiRef = require("./useTreeViewApiRef");
|
|
25
31
|
var _useTreeItemUtils = require("./useTreeItemUtils");
|
|
26
|
-
var _useTreeItemModel = require("./useTreeItemModel");
|
|
32
|
+
var _useTreeItemModel = require("./useTreeItemModel");
|
|
33
|
+
var _useApplyPropagationToSelectedItemsOnMount = require("./useApplyPropagationToSelectedItemsOnMount");
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
import { TreeViewItemId, TreeViewSelectionPropagation } from "../models/index.js";
|
|
2
|
+
/**
|
|
3
|
+
* Applies the selection propagation rules to the selected items.
|
|
4
|
+
* The value is only computed during the first render, any update of the parameters will be ignored.
|
|
5
|
+
*
|
|
6
|
+
* Uncontrolled example:
|
|
7
|
+
* ```tsx
|
|
8
|
+
* const defaultSelectedItems = useApplyPropagationToSelectedItemsOnMount({
|
|
9
|
+
* items: props.items,
|
|
10
|
+
* selectionPropagation: props.selectionPropagation,
|
|
11
|
+
* selectedItems: ['10', '11', '13', '14'],
|
|
12
|
+
* });
|
|
13
|
+
*
|
|
14
|
+
* return (
|
|
15
|
+
* <RichTreeView
|
|
16
|
+
* items={props.items}
|
|
17
|
+
* selectionPropagation={props.selectionPropagation}
|
|
18
|
+
* defaultSelectedItems={defaultSelectedItems}
|
|
19
|
+
* />
|
|
20
|
+
* );
|
|
21
|
+
* ```
|
|
22
|
+
*
|
|
23
|
+
* Controlled example:
|
|
24
|
+
* ```tsx
|
|
25
|
+
* const initialSelectedItems = useApplyPropagationToSelectedItemsOnMount({
|
|
26
|
+
* items: props.items,
|
|
27
|
+
* selectionPropagation: props.selectionPropagation,
|
|
28
|
+
* selectedItems: ['10', '11', '13', '14'],
|
|
29
|
+
* });
|
|
30
|
+
*
|
|
31
|
+
* const [selectedItems, setSelectedItems] = React.useState(initialSelectedItems);
|
|
32
|
+
*
|
|
33
|
+
* return (
|
|
34
|
+
* <RichTreeView
|
|
35
|
+
* items={props.items}
|
|
36
|
+
* selectionPropagation={props.selectionPropagation}
|
|
37
|
+
* selectedItems={selectedItems}
|
|
38
|
+
* onSelectedItemsChange={setSelectedItems}
|
|
39
|
+
* />
|
|
40
|
+
* );
|
|
41
|
+
* ```
|
|
42
|
+
*/
|
|
43
|
+
export declare function useApplyPropagationToSelectedItemsOnMount(parameters: UseApplyPropagationToDefaultSelectedItemsParameters<any>): string[];
|
|
44
|
+
interface UseApplyPropagationToDefaultSelectedItemsParameters<R extends {
|
|
45
|
+
children?: R[];
|
|
46
|
+
}> {
|
|
47
|
+
items: R[];
|
|
48
|
+
getItemId?: (item: R) => TreeViewItemId;
|
|
49
|
+
getItemChildren?: (item: R) => R[] | undefined;
|
|
50
|
+
selectedItems: string[];
|
|
51
|
+
selectionPropagation: TreeViewSelectionPropagation;
|
|
52
|
+
}
|
|
53
|
+
export {};
|
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
|
|
4
|
+
Object.defineProperty(exports, "__esModule", {
|
|
5
|
+
value: true
|
|
6
|
+
});
|
|
7
|
+
exports.useApplyPropagationToSelectedItemsOnMount = useApplyPropagationToSelectedItemsOnMount;
|
|
8
|
+
var _useLazyRef = _interopRequireDefault(require("@mui/utils/useLazyRef"));
|
|
9
|
+
var _useTreeViewSelection = require("../internals/plugins/useTreeViewSelection/useTreeViewSelection.utils");
|
|
10
|
+
const defaultGetItemId = item => item.id;
|
|
11
|
+
const defaultGetItemChildren = item => item.children;
|
|
12
|
+
|
|
13
|
+
/**
|
|
14
|
+
* Applies the selection propagation rules to the selected items.
|
|
15
|
+
* The value is only computed during the first render, any update of the parameters will be ignored.
|
|
16
|
+
*
|
|
17
|
+
* Uncontrolled example:
|
|
18
|
+
* ```tsx
|
|
19
|
+
* const defaultSelectedItems = useApplyPropagationToSelectedItemsOnMount({
|
|
20
|
+
* items: props.items,
|
|
21
|
+
* selectionPropagation: props.selectionPropagation,
|
|
22
|
+
* selectedItems: ['10', '11', '13', '14'],
|
|
23
|
+
* });
|
|
24
|
+
*
|
|
25
|
+
* return (
|
|
26
|
+
* <RichTreeView
|
|
27
|
+
* items={props.items}
|
|
28
|
+
* selectionPropagation={props.selectionPropagation}
|
|
29
|
+
* defaultSelectedItems={defaultSelectedItems}
|
|
30
|
+
* />
|
|
31
|
+
* );
|
|
32
|
+
* ```
|
|
33
|
+
*
|
|
34
|
+
* Controlled example:
|
|
35
|
+
* ```tsx
|
|
36
|
+
* const initialSelectedItems = useApplyPropagationToSelectedItemsOnMount({
|
|
37
|
+
* items: props.items,
|
|
38
|
+
* selectionPropagation: props.selectionPropagation,
|
|
39
|
+
* selectedItems: ['10', '11', '13', '14'],
|
|
40
|
+
* });
|
|
41
|
+
*
|
|
42
|
+
* const [selectedItems, setSelectedItems] = React.useState(initialSelectedItems);
|
|
43
|
+
*
|
|
44
|
+
* return (
|
|
45
|
+
* <RichTreeView
|
|
46
|
+
* items={props.items}
|
|
47
|
+
* selectionPropagation={props.selectionPropagation}
|
|
48
|
+
* selectedItems={selectedItems}
|
|
49
|
+
* onSelectedItemsChange={setSelectedItems}
|
|
50
|
+
* />
|
|
51
|
+
* );
|
|
52
|
+
* ```
|
|
53
|
+
*/
|
|
54
|
+
function useApplyPropagationToSelectedItemsOnMount(parameters) {
|
|
55
|
+
const {
|
|
56
|
+
items: itemsParam,
|
|
57
|
+
getItemId = defaultGetItemId,
|
|
58
|
+
getItemChildren = defaultGetItemChildren,
|
|
59
|
+
selectedItems,
|
|
60
|
+
selectionPropagation
|
|
61
|
+
} = parameters;
|
|
62
|
+
return (0, _useLazyRef.default)(() => {
|
|
63
|
+
const lookup = (0, _useTreeViewSelection.getLookupFromArray)(selectedItems);
|
|
64
|
+
function walk(items, isParentSelected) {
|
|
65
|
+
for (const item of items) {
|
|
66
|
+
const itemId = getItemId(item);
|
|
67
|
+
let isSelected = lookup[itemId];
|
|
68
|
+
if (!isSelected && selectionPropagation.descendants && isParentSelected) {
|
|
69
|
+
lookup[itemId] = true;
|
|
70
|
+
isSelected = true;
|
|
71
|
+
}
|
|
72
|
+
const children = getItemChildren(item) ?? [];
|
|
73
|
+
if (children.length > 0) {
|
|
74
|
+
walk(children, isSelected);
|
|
75
|
+
if (!isSelected && selectionPropagation.parents) {
|
|
76
|
+
const areAllChildrenSelected = children.every(childId => lookup[getItemId(childId)]);
|
|
77
|
+
if (areAllChildrenSelected) {
|
|
78
|
+
lookup[itemId] = true;
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
walk(itemsParam, false);
|
|
85
|
+
return Object.keys(lookup);
|
|
86
|
+
}).current;
|
|
87
|
+
}
|
package/index.js
CHANGED
|
@@ -122,13 +122,14 @@ const useTreeViewItems = ({
|
|
|
122
122
|
const getItemTree = React.useCallback(() => {
|
|
123
123
|
const getItemFromItemId = itemId => {
|
|
124
124
|
const item = _useTreeViewItems2.itemsSelectors.itemModel(store.state, itemId);
|
|
125
|
+
const itemToMutate = (0, _extends2.default)({}, item);
|
|
125
126
|
const newChildren = _useTreeViewItems2.itemsSelectors.itemOrderedChildrenIds(store.state, itemId);
|
|
126
127
|
if (newChildren.length > 0) {
|
|
127
|
-
|
|
128
|
+
itemToMutate.children = newChildren.map(getItemFromItemId);
|
|
128
129
|
} else {
|
|
129
|
-
delete
|
|
130
|
+
delete itemToMutate.children;
|
|
130
131
|
}
|
|
131
|
-
return
|
|
132
|
+
return itemToMutate;
|
|
132
133
|
};
|
|
133
134
|
return _useTreeViewItems2.itemsSelectors.itemOrderedChildrenIds(store.state, null).map(getItemFromItemId);
|
|
134
135
|
}, [store]);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@mui/x-tree-view",
|
|
3
|
-
"version": "8.11.
|
|
3
|
+
"version": "8.11.2",
|
|
4
4
|
"author": "MUI Team",
|
|
5
5
|
"description": "The community edition of the MUI X Tree View components.",
|
|
6
6
|
"license": "MIT",
|
|
@@ -32,13 +32,13 @@
|
|
|
32
32
|
},
|
|
33
33
|
"dependencies": {
|
|
34
34
|
"@babel/runtime": "^7.28.2",
|
|
35
|
-
"@base-ui-components/utils": "0.1.
|
|
36
|
-
"@mui/utils": "^7.3.
|
|
35
|
+
"@base-ui-components/utils": "0.1.1",
|
|
36
|
+
"@mui/utils": "^7.3.2",
|
|
37
37
|
"@types/react-transition-group": "^4.4.12",
|
|
38
38
|
"clsx": "^2.1.1",
|
|
39
39
|
"prop-types": "^15.8.1",
|
|
40
40
|
"react-transition-group": "^4.4.5",
|
|
41
|
-
"@mui/x-internals": "8.11.
|
|
41
|
+
"@mui/x-internals": "8.11.2"
|
|
42
42
|
},
|
|
43
43
|
"peerDependencies": {
|
|
44
44
|
"@emotion/react": "^11.9.0",
|