@mui/x-tree-view 9.10.1 → 9.11.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (41) hide show
  1. package/CHANGELOG.md +118 -0
  2. package/README.md +1 -11
  3. package/RichTreeView/RichTreeView.js +2 -0
  4. package/RichTreeView/RichTreeView.mjs +2 -0
  5. package/SimpleTreeView/SimpleTreeView.js +1 -0
  6. package/SimpleTreeView/SimpleTreeView.mjs +1 -0
  7. package/TreeItemIcon/TreeItemIcon.js +1 -0
  8. package/TreeItemIcon/TreeItemIcon.mjs +1 -0
  9. package/hooks/useTreeItemUtils/useTreeItemUtils.js +2 -0
  10. package/hooks/useTreeItemUtils/useTreeItemUtils.mjs +2 -0
  11. package/index.js +1 -1
  12. package/index.mjs +1 -1
  13. package/internals/MinimalTreeViewStore/MinimalTreeViewStore.d.mts +1 -0
  14. package/internals/MinimalTreeViewStore/MinimalTreeViewStore.d.ts +1 -0
  15. package/internals/RichTreeViewStore/RichTreeViewStore.d.mts +8 -2
  16. package/internals/RichTreeViewStore/RichTreeViewStore.d.ts +8 -2
  17. package/internals/RichTreeViewStore/RichTreeViewStore.js +5 -2
  18. package/internals/RichTreeViewStore/RichTreeViewStore.mjs +5 -2
  19. package/internals/plugins/items/TreeViewItemsPlugin.d.mts +27 -0
  20. package/internals/plugins/items/TreeViewItemsPlugin.d.ts +27 -0
  21. package/internals/plugins/items/TreeViewItemsPlugin.js +81 -35
  22. package/internals/plugins/items/TreeViewItemsPlugin.mjs +82 -36
  23. package/internals/plugins/items/utils.d.mts +28 -0
  24. package/internals/plugins/items/utils.d.ts +28 -0
  25. package/internals/plugins/items/utils.js +49 -0
  26. package/internals/plugins/items/utils.mjs +48 -0
  27. package/internals/plugins/selection/TreeViewSelectionPlugin.d.mts +15 -0
  28. package/internals/plugins/selection/TreeViewSelectionPlugin.d.ts +15 -0
  29. package/internals/plugins/selection/TreeViewSelectionPlugin.js +50 -10
  30. package/internals/plugins/selection/TreeViewSelectionPlugin.mjs +50 -10
  31. package/internals/plugins/selection/itemPlugin.js +3 -37
  32. package/internals/plugins/selection/itemPlugin.mjs +4 -38
  33. package/internals/plugins/selection/selectors.d.mts +11 -0
  34. package/internals/plugins/selection/selectors.d.ts +11 -0
  35. package/internals/plugins/selection/selectors.js +56 -3
  36. package/internals/plugins/selection/selectors.mjs +56 -3
  37. package/models/items.d.mts +2 -1
  38. package/models/items.d.ts +2 -1
  39. package/package.json +3 -3
  40. package/useTreeItem/useTreeItem.types.d.mts +4 -0
  41. package/useTreeItem/useTreeItem.types.d.ts +4 -0
package/CHANGELOG.md CHANGED
@@ -1,5 +1,123 @@
1
1
  # Changelog
2
2
 
3
+ ## 9.11.0
4
+
5
+ _Aug 6, 2026_
6
+
7
+ We'd like to extend a big thank you to the 14 contributors who made this release possible. Here are some highlights ✨:
8
+
9
+ - ✨ Add `addItems()` and `getItemSelection()` API methods to Tree View
10
+
11
+ Special thanks go out to these community members for their valuable contributions:
12
+ @12joan, @Anexus5919, @kevincorizi-sbt, @mixelburg, @mustafajw07, @strazto
13
+
14
+ The following team members contributed to this release:
15
+ @flaviendelangle, @hasdfa, @JCQuintas, @LukasTy, @MBilalShafi, @michelengelen, @noraleonte, @rita-codes
16
+
17
+ ### Data Grid
18
+
19
+ #### `@mui/x-data-grid@9.11.0`
20
+
21
+ - [DataGrid] Fix `updateRows` stripping class prototypes from rows in datasource mode (#22288) @mixelburg
22
+ - [DataGrid] Do not re-fetch data when an `Activity` becomes visible (#22603) @12joan
23
+ - [DataGrid] Fix toolbar button stealing focus when a sibling's disabled state changes (#23204) @MBilalShafi
24
+
25
+ #### `@mui/x-data-grid-pro@9.11.0` [![pro](https://mui.com/r/x-pro-svg)](https://mui.com/r/x-pro-svg-link 'Pro plan')
26
+
27
+ Same changes as in `@mui/x-data-grid@9.11.0`.
28
+
29
+ #### `@mui/x-data-grid-premium@9.11.0` [![premium](https://mui.com/r/x-premium-svg)](https://mui.com/r/x-premium-svg-link 'Premium plan')
30
+
31
+ Same changes as in `@mui/x-data-grid-pro@9.11.0`.
32
+
33
+ ### Date and Time Pickers
34
+
35
+ #### `@mui/x-date-pickers@9.11.0`
36
+
37
+ - [pickers] Fix day shift when editing dates predating timezone standardization (#23296) @JCQuintas
38
+
39
+ #### `@mui/x-date-pickers-pro@9.11.0` [![pro](https://mui.com/r/x-pro-svg)](https://mui.com/r/x-pro-svg-link 'Pro plan')
40
+
41
+ Same changes as in `@mui/x-date-pickers@9.11.0`, plus:
42
+
43
+ - [DateRangePicker] Fix disabled filler cells showing the range highlight (#23293) @JCQuintas
44
+
45
+ ### Charts
46
+
47
+ #### `@mui/x-charts@9.11.0`
48
+
49
+ - [charts] Activate the focused item with `Enter`/`Space` (#23218) @JCQuintas
50
+ - [charts] Extract the axis click payload builders (#23215) @JCQuintas
51
+ - [charts] Fix `GestureManager` event listener leak on chart unmount (#23283) @kevincorizi-sbt
52
+ - [charts] Fix `slotProps.legend.position` and `direction` in `RadarChart` (#23254) @JCQuintas
53
+ - [charts] Fix axis clicks being discarded on slight pointer movement (#23244) @noraleonte
54
+ - [charts] Fix image export of charts sized by their parent element (#23255) @JCQuintas
55
+ - [charts] Forward `experimentalFeatures` on `RadarChart` and `Heatmap` (#23216) @JCQuintas
56
+ - [charts] Hide focus indicator when the chart loses focus (#23213) @JCQuintas
57
+
58
+ #### `@mui/x-charts-pro@9.11.0` [![pro](https://mui.com/r/x-pro-svg)](https://mui.com/r/x-pro-svg-link 'Pro plan')
59
+
60
+ Same changes as in `@mui/x-charts@9.11.0`.
61
+
62
+ #### `@mui/x-charts-premium@9.11.0` [![premium](https://mui.com/r/x-premium-svg)](https://mui.com/r/x-premium-svg-link 'Premium plan')
63
+
64
+ Same changes as in `@mui/x-charts-pro@9.11.0`, plus:
65
+
66
+ - [charts-premium] Fix `RangeBar` type override (#23217) @JCQuintas
67
+
68
+ ### Tree View
69
+
70
+ #### `@mui/x-tree-view@9.11.0`
71
+
72
+ - [tree view] Add `addItems()` API method (#23159) @JCQuintas
73
+ - [tree view] Add `getItemSelection` API method (#23257) @noraleonte
74
+ - [tree view] Ignore `keepExistingSelection` when `multiSelect` is `false` (#23242) @JCQuintas
75
+ - [tree view] Prevent duplicate ids in multi-select arrow navigation (#23006) @Anexus5919
76
+
77
+ #### `@mui/x-tree-view-pro@9.11.0` [![pro](https://mui.com/r/x-pro-svg)](https://mui.com/r/x-pro-svg-link 'Pro plan')
78
+
79
+ Same changes as in `@mui/x-tree-view@9.11.0`, plus:
80
+
81
+ - [tree view] Discard superseded lazy-loading responses (#23005) @Anexus5919
82
+
83
+ ### Scheduler
84
+
85
+ #### `@mui/x-scheduler@9.0.0-beta.8`
86
+
87
+ - [scheduler] Add `localeText` prop to standalone views (#23210) @rita-codes
88
+ - [scheduler] Finetune touch experience for time grid events and introduce editing drawer (#22624) @noraleonte
89
+ - [scheduler] Introduce the edit dialog form context & lifecycle contract (#23284) @rita-codes
90
+ - [scheduler] Refactor edit dialog General tab into section components (#23206) @rita-codes
91
+ - [scheduler] Replace copied Base UI internals with `@base-ui/react/internals` imports (#21972) @flaviendelangle
92
+ - [scheduler] Hide resource picker when no resources are provided (#23290) @mustafajw07
93
+ - [scheduler] Support multi-resource occurrences in `EventTimeline` (#23240) @mustafajw07
94
+
95
+ #### `@mui/x-scheduler-premium@9.0.0-beta.8` [![premium](https://mui.com/r/x-premium-svg)](https://mui.com/r/x-premium-svg-link 'Premium plan')
96
+
97
+ Same changes as in `@mui/x-scheduler@9.0.0-beta.8`.
98
+
99
+ ### Codemod
100
+
101
+ #### `@mui/x-codemod@9.11.0`
102
+
103
+ - [codemod] Remove unused `@babel/core` and `@babel/traverse` dependencies (#23245) @LukasTy
104
+
105
+ ### Docs
106
+
107
+ - [docs] Add recipe for adding new rows from clipboard copy (#22913) @michelengelen
108
+ - [docs] Clarify the package versions in v8 upgrade guides (#22376) @strazto
109
+ - [docs] Replace README peer dependency lists with an npm install command (#23256) @LukasTy
110
+
111
+ ### Core
112
+
113
+ - [code-infra] Align action pin version comments (#23238) @LukasTy
114
+
115
+ ### Miscellaneous
116
+
117
+ - [chat] Drop the undeclared `@mui/icons-material` dependency (#23252) @LukasTy
118
+ - [chat] Sanitize image part URLs and share the URL allow-list with markdown (#23058) @hasdfa
119
+ - [test] Type the `PickersTextField` test stub instead of `as any` (#23194) @LukasTy
120
+
3
121
  ## 9.10.1
4
122
 
5
123
  _Jul 23, 2026_
package/README.md CHANGED
@@ -8,17 +8,7 @@ It's part of [MUI X](https://mui.com/x/), an open-core extension of our Core li
8
8
  Install the package in your project directory with:
9
9
 
10
10
  ```bash
11
- npm install @mui/x-tree-view
12
- ```
13
-
14
- This component has the following peer dependencies that you need to install as well.
15
-
16
- ```json
17
- "peerDependencies": {
18
- "@mui/material": "^5.15.14 || ^6.0.0 || ^7.0.0",
19
- "react": "^17.0.0 || ^18.0.0 || ^19.0.0",
20
- "react-dom": "^17.0.0 || ^18.0.0 || ^19.0.0"
21
- },
11
+ npm install @mui/x-tree-view @mui/material @emotion/react @emotion/styled
22
12
  ```
23
13
 
24
14
  ## Documentation
@@ -143,10 +143,12 @@ process.env.NODE_ENV !== "production" ? RichTreeView.propTypes /* remove-proptyp
143
143
  */
144
144
  apiRef: _propTypes.default.shape({
145
145
  current: _propTypes.default.shape({
146
+ addItems: _propTypes.default.func,
146
147
  focusItem: _propTypes.default.func,
147
148
  getItem: _propTypes.default.func,
148
149
  getItemDOMElement: _propTypes.default.func,
149
150
  getItemOrderedChildrenIds: _propTypes.default.func,
151
+ getItemSelection: _propTypes.default.func,
150
152
  getItemTree: _propTypes.default.func,
151
153
  getParentId: _propTypes.default.func,
152
154
  isItemExpanded: _propTypes.default.func,
@@ -136,10 +136,12 @@ process.env.NODE_ENV !== "production" ? RichTreeView.propTypes /* remove-proptyp
136
136
  */
137
137
  apiRef: PropTypes.shape({
138
138
  current: PropTypes.shape({
139
+ addItems: PropTypes.func,
139
140
  focusItem: PropTypes.func,
140
141
  getItem: PropTypes.func,
141
142
  getItemDOMElement: PropTypes.func,
142
143
  getItemOrderedChildrenIds: PropTypes.func,
144
+ getItemSelection: PropTypes.func,
143
145
  getItemTree: PropTypes.func,
144
146
  getParentId: PropTypes.func,
145
147
  isItemExpanded: PropTypes.func,
@@ -127,6 +127,7 @@ process.env.NODE_ENV !== "production" ? SimpleTreeView.propTypes /* remove-propt
127
127
  getItem: _propTypes.default.func,
128
128
  getItemDOMElement: _propTypes.default.func,
129
129
  getItemOrderedChildrenIds: _propTypes.default.func,
130
+ getItemSelection: _propTypes.default.func,
130
131
  getItemTree: _propTypes.default.func,
131
132
  getParentId: _propTypes.default.func,
132
133
  isItemExpanded: _propTypes.default.func,
@@ -120,6 +120,7 @@ process.env.NODE_ENV !== "production" ? SimpleTreeView.propTypes /* remove-propt
120
120
  getItem: PropTypes.func,
121
121
  getItemDOMElement: PropTypes.func,
122
122
  getItemOrderedChildrenIds: PropTypes.func,
123
+ getItemSelection: PropTypes.func,
123
124
  getItemTree: PropTypes.func,
124
125
  getParentId: PropTypes.func,
125
126
  isItemExpanded: PropTypes.func,
@@ -90,6 +90,7 @@ process.env.NODE_ENV !== "production" ? TreeItemIcon.propTypes /* remove-proptyp
90
90
  expandable: _propTypes.default.bool.isRequired,
91
91
  expanded: _propTypes.default.bool.isRequired,
92
92
  focused: _propTypes.default.bool.isRequired,
93
+ indeterminate: _propTypes.default.bool,
93
94
  loading: _propTypes.default.bool.isRequired,
94
95
  selected: _propTypes.default.bool.isRequired
95
96
  }).isRequired
@@ -83,6 +83,7 @@ process.env.NODE_ENV !== "production" ? TreeItemIcon.propTypes /* remove-proptyp
83
83
  expandable: PropTypes.bool.isRequired,
84
84
  expanded: PropTypes.bool.isRequired,
85
85
  focused: PropTypes.bool.isRequired,
86
+ indeterminate: PropTypes.bool,
86
87
  loading: PropTypes.bool.isRequired,
87
88
  selected: PropTypes.bool.isRequired
88
89
  }).isRequired
@@ -35,6 +35,7 @@ const useTreeItemUtils = ({
35
35
  const isExpanded = (0, _store.useStore)(store, _selectors.expansionSelectors.isItemExpanded, itemId);
36
36
  const isFocused = (0, _store.useStore)(store, _selectors2.focusSelectors.isItemFocused, itemId);
37
37
  const isSelected = (0, _store.useStore)(store, _selectors4.selectionSelectors.isItemSelected, itemId);
38
+ const isIndeterminate = (0, _store.useStore)(store, _selectors4.selectionSelectors.isItemIndeterminate, itemId);
38
39
  const isDisabled = (0, _store.useStore)(store, _selectors3.itemsSelectors.isItemDisabled, itemId);
39
40
  const isEditing = (0, _store.useStore)(store, _selectors6.labelSelectors.isItemBeingEdited, itemId);
40
41
  const isEditable = (0, _store.useStore)(store, _selectors6.labelSelectors.isItemEditable, itemId);
@@ -43,6 +44,7 @@ const useTreeItemUtils = ({
43
44
  expanded: isExpanded,
44
45
  focused: isFocused,
45
46
  selected: isSelected,
47
+ indeterminate: isIndeterminate,
46
48
  disabled: isDisabled,
47
49
  editing: isEditing,
48
50
  editable: isEditable,
@@ -29,6 +29,7 @@ export const useTreeItemUtils = ({
29
29
  const isExpanded = useStore(store, expansionSelectors.isItemExpanded, itemId);
30
30
  const isFocused = useStore(store, focusSelectors.isItemFocused, itemId);
31
31
  const isSelected = useStore(store, selectionSelectors.isItemSelected, itemId);
32
+ const isIndeterminate = useStore(store, selectionSelectors.isItemIndeterminate, itemId);
32
33
  const isDisabled = useStore(store, itemsSelectors.isItemDisabled, itemId);
33
34
  const isEditing = useStore(store, labelSelectors.isItemBeingEdited, itemId);
34
35
  const isEditable = useStore(store, labelSelectors.isItemEditable, itemId);
@@ -37,6 +38,7 @@ export const useTreeItemUtils = ({
37
38
  expanded: isExpanded,
38
39
  focused: isFocused,
39
40
  selected: isSelected,
41
+ indeterminate: isIndeterminate,
40
42
  disabled: isDisabled,
41
43
  editing: isEditing,
42
44
  editable: isEditable,
package/index.js CHANGED
@@ -1,5 +1,5 @@
1
1
  /**
2
- * @mui/x-tree-view v9.10.1
2
+ * @mui/x-tree-view v9.11.0
3
3
  *
4
4
  * @license MIT
5
5
  * This source code is licensed under the MIT license found in the
package/index.mjs CHANGED
@@ -1,5 +1,5 @@
1
1
  /**
2
- * @mui/x-tree-view v9.10.1
2
+ * @mui/x-tree-view v9.11.0
3
3
  *
4
4
  * @license MIT
5
5
  * This source code is licensed under the MIT license found in the
@@ -52,6 +52,7 @@ export declare class MinimalTreeViewStore<R extends TreeViewValidItem<R>, Multip
52
52
  shouldBeExpanded?: boolean;
53
53
  }) => void;
54
54
  focusItem: (event: React.SyntheticEvent | null, itemId: import("../../index.mjs").TreeViewItemId) => void;
55
+ getItemSelection: (itemId: import("../../index.mjs").TreeViewItemId) => import("../../index.mjs").TreeViewItemSelectionStatus;
55
56
  setItemSelection: ({
56
57
  itemId,
57
58
  event,
@@ -52,6 +52,7 @@ export declare class MinimalTreeViewStore<R extends TreeViewValidItem<R>, Multip
52
52
  shouldBeExpanded?: boolean;
53
53
  }) => void;
54
54
  focusItem: (event: React.SyntheticEvent | null, itemId: import("../../index.js").TreeViewItemId) => void;
55
+ getItemSelection: (itemId: import("../../index.js").TreeViewItemId) => import("../../index.js").TreeViewItemSelectionStatus;
55
56
  setItemSelection: ({
56
57
  itemId,
57
58
  event,
@@ -1,7 +1,7 @@
1
1
  import type { TreeViewValidItem } from "../../models/index.mjs";
2
- import { TreeViewLabelEditingPlugin } from "../plugins/labelEditing/index.mjs";
3
2
  import { MinimalTreeViewStore } from "../MinimalTreeViewStore/index.mjs";
4
- import type { RichTreeViewStoreParameters, RichTreeViewState } from "./RichTreeViewStore.types.mjs";
3
+ import { TreeViewLabelEditingPlugin } from "../plugins/labelEditing/index.mjs";
4
+ import type { RichTreeViewState, RichTreeViewStoreParameters } from "./RichTreeViewStore.types.mjs";
5
5
  export declare class ExtendableRichTreeViewStore<R extends TreeViewValidItem<R>, Multiple extends boolean | undefined, State extends RichTreeViewState<R, Multiple> = RichTreeViewState<R, Multiple>, Parameters extends RichTreeViewStoreParameters<R, Multiple> = RichTreeViewStoreParameters<R, Multiple>> extends MinimalTreeViewStore<R, Multiple, State, Parameters> {
6
6
  labelEditing: TreeViewLabelEditingPlugin;
7
7
  /**
@@ -24,6 +24,11 @@ export declare class ExtendableRichTreeViewStore<R extends TreeViewValidItem<R>,
24
24
  itemId: import("../../index.mjs").TreeViewItemId;
25
25
  shouldBeDisabled?: boolean;
26
26
  }) => void;
27
+ addItems: ({
28
+ items,
29
+ parentId,
30
+ index
31
+ }: import("../plugins/items/index.mjs").AddItemsParameters<R>) => void;
27
32
  isItemExpanded: (itemId: import("../../index.mjs").TreeViewItemId) => boolean;
28
33
  setItemExpansion: ({
29
34
  itemId,
@@ -35,6 +40,7 @@ export declare class ExtendableRichTreeViewStore<R extends TreeViewValidItem<R>,
35
40
  shouldBeExpanded?: boolean;
36
41
  }) => void;
37
42
  focusItem: (event: React.SyntheticEvent | null, itemId: import("../../index.mjs").TreeViewItemId) => void;
43
+ getItemSelection: (itemId: import("../../index.mjs").TreeViewItemId) => import("../../index.mjs").TreeViewItemSelectionStatus;
38
44
  setItemSelection: ({
39
45
  itemId,
40
46
  event,
@@ -1,7 +1,7 @@
1
1
  import type { TreeViewValidItem } from "../../models/index.js";
2
- import { TreeViewLabelEditingPlugin } from "../plugins/labelEditing/index.js";
3
2
  import { MinimalTreeViewStore } from "../MinimalTreeViewStore/index.js";
4
- import type { RichTreeViewStoreParameters, RichTreeViewState } from "./RichTreeViewStore.types.js";
3
+ import { TreeViewLabelEditingPlugin } from "../plugins/labelEditing/index.js";
4
+ import type { RichTreeViewState, RichTreeViewStoreParameters } from "./RichTreeViewStore.types.js";
5
5
  export declare class ExtendableRichTreeViewStore<R extends TreeViewValidItem<R>, Multiple extends boolean | undefined, State extends RichTreeViewState<R, Multiple> = RichTreeViewState<R, Multiple>, Parameters extends RichTreeViewStoreParameters<R, Multiple> = RichTreeViewStoreParameters<R, Multiple>> extends MinimalTreeViewStore<R, Multiple, State, Parameters> {
6
6
  labelEditing: TreeViewLabelEditingPlugin;
7
7
  /**
@@ -24,6 +24,11 @@ export declare class ExtendableRichTreeViewStore<R extends TreeViewValidItem<R>,
24
24
  itemId: import("../../index.js").TreeViewItemId;
25
25
  shouldBeDisabled?: boolean;
26
26
  }) => void;
27
+ addItems: ({
28
+ items,
29
+ parentId,
30
+ index
31
+ }: import("../plugins/items/index.js").AddItemsParameters<R>) => void;
27
32
  isItemExpanded: (itemId: import("../../index.js").TreeViewItemId) => boolean;
28
33
  setItemExpansion: ({
29
34
  itemId,
@@ -35,6 +40,7 @@ export declare class ExtendableRichTreeViewStore<R extends TreeViewValidItem<R>,
35
40
  shouldBeExpanded?: boolean;
36
41
  }) => void;
37
42
  focusItem: (event: React.SyntheticEvent | null, itemId: import("../../index.js").TreeViewItemId) => void;
43
+ getItemSelection: (itemId: import("../../index.js").TreeViewItemId) => import("../../index.js").TreeViewItemSelectionStatus;
38
44
  setItemSelection: ({
39
45
  itemId,
40
46
  event,
@@ -6,8 +6,8 @@ Object.defineProperty(exports, "__esModule", {
6
6
  });
7
7
  exports.RichTreeViewStore = exports.ExtendableRichTreeViewStore = void 0;
8
8
  var _extends2 = _interopRequireDefault(require("@babel/runtime/helpers/extends"));
9
- var _labelEditing = require("../plugins/labelEditing");
10
9
  var _MinimalTreeViewStore = require("../MinimalTreeViewStore");
10
+ var _labelEditing = require("../plugins/labelEditing");
11
11
  var _RichTreeViewStore = require("./RichTreeViewStore.utils");
12
12
  class ExtendableRichTreeViewStore extends _MinimalTreeViewStore.MinimalTreeViewStore {
13
13
  labelEditing = new _labelEditing.TreeViewLabelEditingPlugin(this);
@@ -18,7 +18,10 @@ class ExtendableRichTreeViewStore extends _MinimalTreeViewStore.MinimalTreeViewS
18
18
  */
19
19
  static rawMapper = _RichTreeViewStore.parametersToStateMapper;
20
20
  buildPublicAPI() {
21
- return (0, _extends2.default)({}, super.buildPublicAPI(), this.labelEditing.buildPublicAPI());
21
+ return (0, _extends2.default)({}, super.buildPublicAPI(), this.labelEditing.buildPublicAPI(), {
22
+ // `addItems` is not exposed on the Simple Tree View, where the items are defined with JSX.
23
+ addItems: this.items.addItems
24
+ });
22
25
  }
23
26
  }
24
27
  exports.ExtendableRichTreeViewStore = ExtendableRichTreeViewStore;
@@ -1,6 +1,6 @@
1
1
  import _extends from "@babel/runtime/helpers/esm/extends";
2
- import { TreeViewLabelEditingPlugin } from "../plugins/labelEditing/index.mjs";
3
2
  import { MinimalTreeViewStore } from "../MinimalTreeViewStore/index.mjs";
3
+ import { TreeViewLabelEditingPlugin } from "../plugins/labelEditing/index.mjs";
4
4
  import { parametersToStateMapper } from "./RichTreeViewStore.utils.mjs";
5
5
  export class ExtendableRichTreeViewStore extends MinimalTreeViewStore {
6
6
  labelEditing = new TreeViewLabelEditingPlugin(this);
@@ -11,7 +11,10 @@ export class ExtendableRichTreeViewStore extends MinimalTreeViewStore {
11
11
  */
12
12
  static rawMapper = parametersToStateMapper;
13
13
  buildPublicAPI() {
14
- return _extends({}, super.buildPublicAPI(), this.labelEditing.buildPublicAPI());
14
+ return _extends({}, super.buildPublicAPI(), this.labelEditing.buildPublicAPI(), {
15
+ // `addItems` is not exposed on the Simple Tree View, where the items are defined with JSX.
16
+ addItems: this.items.addItems
17
+ });
15
18
  }
16
19
  }
17
20
  export class RichTreeViewStore extends ExtendableRichTreeViewStore {
@@ -58,6 +58,16 @@ export declare class TreeViewItemsPlugin<R extends TreeViewValidItem<R>> {
58
58
  * @param {boolean } parameters.shouldBeDisabled true if the item should be disabled.
59
59
  */
60
60
  private setIsItemDisabled;
61
+ /**
62
+ * Add items to the tree.
63
+ * The items are added as children of the item with the given `parentId`, or at the root level if `parentId` is `null` or not defined.
64
+ * @param {AddItemsParameters<R>} parameters The items to add and their position in the tree.
65
+ */
66
+ addItems: ({
67
+ items,
68
+ parentId,
69
+ index
70
+ }: AddItemsParameters<R>) => void;
61
71
  buildPublicAPI: () => {
62
72
  getItem: (itemId: TreeViewItemId) => R;
63
73
  getItemDOMElement: (itemId: TreeViewItemId) => HTMLElement | null;
@@ -102,4 +112,21 @@ export declare class TreeViewItemsPlugin<R extends TreeViewValidItem<R>> {
102
112
  * @param {TreeViewItemId} itemId The id of the item being clicked.
103
113
  */
104
114
  handleItemClick: (event: React.MouseEvent, itemId: TreeViewItemId) => void;
115
+ }
116
+ export interface AddItemsParameters<R extends TreeViewValidItem<R>> {
117
+ /**
118
+ * The items to add to the tree.
119
+ */
120
+ items: readonly R[];
121
+ /**
122
+ * The id of the item to add the items to.
123
+ * If `null` or not defined, the items are added at the root level.
124
+ * @default null
125
+ */
126
+ parentId?: TreeViewItemId | null;
127
+ /**
128
+ * The position in the parent's children at which the items are inserted.
129
+ * If not defined, the items are appended after the existing children.
130
+ */
131
+ index?: number;
105
132
  }
@@ -58,6 +58,16 @@ export declare class TreeViewItemsPlugin<R extends TreeViewValidItem<R>> {
58
58
  * @param {boolean } parameters.shouldBeDisabled true if the item should be disabled.
59
59
  */
60
60
  private setIsItemDisabled;
61
+ /**
62
+ * Add items to the tree.
63
+ * The items are added as children of the item with the given `parentId`, or at the root level if `parentId` is `null` or not defined.
64
+ * @param {AddItemsParameters<R>} parameters The items to add and their position in the tree.
65
+ */
66
+ addItems: ({
67
+ items,
68
+ parentId,
69
+ index
70
+ }: AddItemsParameters<R>) => void;
61
71
  buildPublicAPI: () => {
62
72
  getItem: (itemId: TreeViewItemId) => R;
63
73
  getItemDOMElement: (itemId: TreeViewItemId) => HTMLElement | null;
@@ -102,4 +112,21 @@ export declare class TreeViewItemsPlugin<R extends TreeViewValidItem<R>> {
102
112
  * @param {TreeViewItemId} itemId The id of the item being clicked.
103
113
  */
104
114
  handleItemClick: (event: React.MouseEvent, itemId: TreeViewItemId) => void;
115
+ }
116
+ export interface AddItemsParameters<R extends TreeViewValidItem<R>> {
117
+ /**
118
+ * The items to add to the tree.
119
+ */
120
+ items: readonly R[];
121
+ /**
122
+ * The id of the item to add the items to.
123
+ * If `null` or not defined, the items are added at the root level.
124
+ * @default null
125
+ */
126
+ parentId?: TreeViewItemId | null;
127
+ /**
128
+ * The position in the parent's children at which the items are inserted.
129
+ * If not defined, the items are appended after the existing children.
130
+ */
131
+ index?: number;
105
132
  }
@@ -5,6 +5,7 @@ Object.defineProperty(exports, "__esModule", {
5
5
  value: true
6
6
  });
7
7
  exports.TreeViewItemsPlugin = void 0;
8
+ var _formatErrorMessage2 = _interopRequireDefault(require("@mui/x-internals/formatErrorMessage"));
8
9
  var _extends2 = _interopRequireDefault(require("@babel/runtime/helpers/extends"));
9
10
  var _id = require("../id");
10
11
  var _selectors = require("./selectors");
@@ -30,41 +31,13 @@ class TreeViewItemsPlugin {
30
31
  * Builds the state properties derived from the `items` prop.
31
32
  */
32
33
  static buildItemsStateIfNeeded = parameters => {
33
- const itemMetaLookup = {};
34
- const itemModelLookup = {};
35
- const itemOrderedChildrenIdsLookup = {};
36
- const itemChildrenIndexesLookup = {};
37
- function processSiblings(items, parentId, depth) {
38
- const parentIdWithDefault = parentId ?? _utils.TREE_VIEW_ROOT_PARENT_ID;
39
- const {
40
- metaLookup,
41
- modelLookup,
42
- orderedChildrenIds,
43
- childrenIndexes,
44
- itemsChildren
45
- } = (0, _utils.buildItemsLookups)({
46
- storeParameters: parameters,
47
- items,
48
- parentId,
49
- depth,
50
- isItemExpandable: (item, children) => !!children && children.length > 0,
51
- otherItemsMetaLookup: itemMetaLookup
52
- });
53
- Object.assign(itemMetaLookup, metaLookup);
54
- Object.assign(itemModelLookup, modelLookup);
55
- itemOrderedChildrenIdsLookup[parentIdWithDefault] = orderedChildrenIds;
56
- itemChildrenIndexesLookup[parentIdWithDefault] = childrenIndexes;
57
- for (const item of itemsChildren) {
58
- processSiblings(item.children || [], item.id, depth + 1);
59
- }
60
- }
61
- processSiblings(parameters.items, null, 0);
62
- return {
63
- itemMetaLookup,
64
- itemModelLookup,
65
- itemOrderedChildrenIdsLookup,
66
- itemChildrenIndexesLookup
67
- };
34
+ return (0, _utils.buildItemsLookupsRecursively)({
35
+ storeParameters: parameters,
36
+ items: parameters.items,
37
+ parentId: null,
38
+ depth: 0,
39
+ isItemExpandable: (item, children) => !!children && children.length > 0
40
+ });
68
41
  };
69
42
 
70
43
  /**
@@ -131,6 +104,79 @@ class TreeViewItemsPlugin {
131
104
  });
132
105
  this.store.set('itemMetaLookup', itemMetaLookup);
133
106
  };
107
+
108
+ /**
109
+ * Add items to the tree.
110
+ * The items are added as children of the item with the given `parentId`, or at the root level if `parentId` is `null` or not defined.
111
+ * @param {AddItemsParameters<R>} parameters The items to add and their position in the tree.
112
+ */
113
+ addItems = ({
114
+ items,
115
+ parentId = null,
116
+ index
117
+ }) => {
118
+ if (items.length === 0) {
119
+ return;
120
+ }
121
+ if (parentId != null && _selectors.itemsSelectors.itemMeta(this.store.state, parentId) == null) {
122
+ throw new Error(process.env.NODE_ENV !== "production" ? `MUI X Tree View: Unable to add items to the parent with id "${parentId}" because it is not present in the tree. ` + 'Pass the id of an existing item, or `null` to add the items at the root level.' : (0, _formatErrorMessage2.default)(295, parentId));
123
+ }
124
+ const parentDepth = parentId == null ? -1 : _selectors.itemsSelectors.itemDepth(this.store.state, parentId);
125
+
126
+ // When the items are lazy loaded, an item can be expandable even if its children are not loaded yet.
127
+ const dataSource = this.store.parameters.dataSource;
128
+ const isItemExpandable = (item, children) => {
129
+ if (children != null && children.length > 0) {
130
+ return true;
131
+ }
132
+ return dataSource == null ? false : dataSource.getChildrenCount(item) !== 0;
133
+ };
134
+ const {
135
+ itemMetaLookup: metaLookup,
136
+ itemModelLookup: modelLookup,
137
+ itemOrderedChildrenIdsLookup: orderedChildrenIdsLookup,
138
+ itemChildrenIndexesLookup: childrenIndexesLookup
139
+ } = (0, _utils.buildItemsLookupsRecursively)({
140
+ storeParameters: this.store.parameters,
141
+ items,
142
+ parentId,
143
+ depth: parentDepth + 1,
144
+ isItemExpandable,
145
+ existingItemMetaLookup: this.store.state.itemMetaLookup
146
+ });
147
+
148
+ // `buildItemsLookups` allows an id to be re-used by an item with the same parent,
149
+ // which is only valid when rebuilding the state from the `items` prop.
150
+ for (const id of Object.keys(metaLookup)) {
151
+ if (this.store.state.itemMetaLookup[id] != null) {
152
+ throw new Error(process.env.NODE_ENV !== "production" ? `MUI X Tree View: All items must have a unique \`id\` property. ` + `The id "${id}" is used by multiple items. ` + 'Use the `getItemId` prop to specify a custom id for each item if needed.' : (0, _formatErrorMessage2.default)(194, id));
153
+ }
154
+ }
155
+ const parentIdWithDefault = parentId ?? _utils.TREE_VIEW_ROOT_PARENT_ID;
156
+ const existingChildrenIds = _selectors.itemsSelectors.itemOrderedChildrenIds(this.store.state, parentId);
157
+ const insertionIndex = index ?? existingChildrenIds.length;
158
+ if (insertionIndex < 0 || insertionIndex > existingChildrenIds.length) {
159
+ throw new Error(process.env.NODE_ENV !== "production" ? `MUI X Tree View: Unable to add items at index "${insertionIndex}" because it is out of range. ` + `The index must be between 0 and the amount of children of the parent item (${existingChildrenIds.length}).` : (0, _formatErrorMessage2.default)(296, insertionIndex, existingChildrenIds.length));
160
+ }
161
+ const newChildrenIds = orderedChildrenIdsLookup[parentIdWithDefault];
162
+ const mergedChildrenIds = [...existingChildrenIds];
163
+ mergedChildrenIds.splice(insertionIndex, 0, ...newChildrenIds);
164
+ orderedChildrenIdsLookup[parentIdWithDefault] = mergedChildrenIds;
165
+ childrenIndexesLookup[parentIdWithDefault] = (0, _utils.buildSiblingIndexes)(mergedChildrenIds);
166
+ const newMetaLookup = (0, _extends2.default)({}, this.store.state.itemMetaLookup, metaLookup);
167
+ if (parentId != null && !newMetaLookup[parentId].expandable) {
168
+ newMetaLookup[parentId] = (0, _extends2.default)({}, newMetaLookup[parentId], {
169
+ expandable: true
170
+ });
171
+ }
172
+ this.store.update({
173
+ itemMetaLookup: newMetaLookup,
174
+ itemModelLookup: (0, _extends2.default)({}, this.store.state.itemModelLookup, modelLookup),
175
+ itemOrderedChildrenIdsLookup: (0, _extends2.default)({}, this.store.state.itemOrderedChildrenIdsLookup, orderedChildrenIdsLookup),
176
+ itemChildrenIndexesLookup: (0, _extends2.default)({}, this.store.state.itemChildrenIndexesLookup, childrenIndexesLookup)
177
+ });
178
+ this.store.selection.propagateSelectionToNewItems(parentId, newChildrenIds);
179
+ };
134
180
  buildPublicAPI = () => {
135
181
  return {
136
182
  getItem: this.getItem,