@mui/x-tree-view 9.10.0 → 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 +224 -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 +2 -1
  14. package/internals/MinimalTreeViewStore/MinimalTreeViewStore.d.ts +2 -1
  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 +66 -17
  30. package/internals/plugins/selection/TreeViewSelectionPlugin.mjs +66 -17
  31. package/internals/plugins/selection/itemPlugin.js +13 -36
  32. package/internals/plugins/selection/itemPlugin.mjs +14 -37
  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
@@ -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,
@@ -1,7 +1,8 @@
1
+ import _formatErrorMessage from "@mui/x-internals/formatErrorMessage";
1
2
  import _extends from "@babel/runtime/helpers/esm/extends";
2
3
  import { idSelectors } from "../id/index.mjs";
3
4
  import { itemsSelectors } from "./selectors.mjs";
4
- import { buildItemsLookups, TREE_VIEW_ROOT_PARENT_ID } from "./utils.mjs";
5
+ import { buildItemsLookups, buildItemsLookupsRecursively, buildSiblingIndexes, TREE_VIEW_ROOT_PARENT_ID } from "./utils.mjs";
5
6
  export class TreeViewItemsPlugin {
6
7
  // We can't type `store`, otherwise we get the following TS error:
7
8
  // 'items' implicitly has type 'any' because it does not have a type annotation and is referenced directly or indirectly in its own initializer.
@@ -23,41 +24,13 @@ export class TreeViewItemsPlugin {
23
24
  * Builds the state properties derived from the `items` prop.
24
25
  */
25
26
  static buildItemsStateIfNeeded = parameters => {
26
- const itemMetaLookup = {};
27
- const itemModelLookup = {};
28
- const itemOrderedChildrenIdsLookup = {};
29
- const itemChildrenIndexesLookup = {};
30
- function processSiblings(items, parentId, depth) {
31
- const parentIdWithDefault = parentId ?? TREE_VIEW_ROOT_PARENT_ID;
32
- const {
33
- metaLookup,
34
- modelLookup,
35
- orderedChildrenIds,
36
- childrenIndexes,
37
- itemsChildren
38
- } = buildItemsLookups({
39
- storeParameters: parameters,
40
- items,
41
- parentId,
42
- depth,
43
- isItemExpandable: (item, children) => !!children && children.length > 0,
44
- otherItemsMetaLookup: itemMetaLookup
45
- });
46
- Object.assign(itemMetaLookup, metaLookup);
47
- Object.assign(itemModelLookup, modelLookup);
48
- itemOrderedChildrenIdsLookup[parentIdWithDefault] = orderedChildrenIds;
49
- itemChildrenIndexesLookup[parentIdWithDefault] = childrenIndexes;
50
- for (const item of itemsChildren) {
51
- processSiblings(item.children || [], item.id, depth + 1);
52
- }
53
- }
54
- processSiblings(parameters.items, null, 0);
55
- return {
56
- itemMetaLookup,
57
- itemModelLookup,
58
- itemOrderedChildrenIdsLookup,
59
- itemChildrenIndexesLookup
60
- };
27
+ return buildItemsLookupsRecursively({
28
+ storeParameters: parameters,
29
+ items: parameters.items,
30
+ parentId: null,
31
+ depth: 0,
32
+ isItemExpandable: (item, children) => !!children && children.length > 0
33
+ });
61
34
  };
62
35
 
63
36
  /**
@@ -124,6 +97,79 @@ export class TreeViewItemsPlugin {
124
97
  });
125
98
  this.store.set('itemMetaLookup', itemMetaLookup);
126
99
  };
100
+
101
+ /**
102
+ * Add items to the tree.
103
+ * 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.
104
+ * @param {AddItemsParameters<R>} parameters The items to add and their position in the tree.
105
+ */
106
+ addItems = ({
107
+ items,
108
+ parentId = null,
109
+ index
110
+ }) => {
111
+ if (items.length === 0) {
112
+ return;
113
+ }
114
+ if (parentId != null && itemsSelectors.itemMeta(this.store.state, parentId) == null) {
115
+ 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.' : _formatErrorMessage(295, parentId));
116
+ }
117
+ const parentDepth = parentId == null ? -1 : itemsSelectors.itemDepth(this.store.state, parentId);
118
+
119
+ // When the items are lazy loaded, an item can be expandable even if its children are not loaded yet.
120
+ const dataSource = this.store.parameters.dataSource;
121
+ const isItemExpandable = (item, children) => {
122
+ if (children != null && children.length > 0) {
123
+ return true;
124
+ }
125
+ return dataSource == null ? false : dataSource.getChildrenCount(item) !== 0;
126
+ };
127
+ const {
128
+ itemMetaLookup: metaLookup,
129
+ itemModelLookup: modelLookup,
130
+ itemOrderedChildrenIdsLookup: orderedChildrenIdsLookup,
131
+ itemChildrenIndexesLookup: childrenIndexesLookup
132
+ } = buildItemsLookupsRecursively({
133
+ storeParameters: this.store.parameters,
134
+ items,
135
+ parentId,
136
+ depth: parentDepth + 1,
137
+ isItemExpandable,
138
+ existingItemMetaLookup: this.store.state.itemMetaLookup
139
+ });
140
+
141
+ // `buildItemsLookups` allows an id to be re-used by an item with the same parent,
142
+ // which is only valid when rebuilding the state from the `items` prop.
143
+ for (const id of Object.keys(metaLookup)) {
144
+ if (this.store.state.itemMetaLookup[id] != null) {
145
+ 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.' : _formatErrorMessage(194, id));
146
+ }
147
+ }
148
+ const parentIdWithDefault = parentId ?? TREE_VIEW_ROOT_PARENT_ID;
149
+ const existingChildrenIds = itemsSelectors.itemOrderedChildrenIds(this.store.state, parentId);
150
+ const insertionIndex = index ?? existingChildrenIds.length;
151
+ if (insertionIndex < 0 || insertionIndex > existingChildrenIds.length) {
152
+ 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}).` : _formatErrorMessage(296, insertionIndex, existingChildrenIds.length));
153
+ }
154
+ const newChildrenIds = orderedChildrenIdsLookup[parentIdWithDefault];
155
+ const mergedChildrenIds = [...existingChildrenIds];
156
+ mergedChildrenIds.splice(insertionIndex, 0, ...newChildrenIds);
157
+ orderedChildrenIdsLookup[parentIdWithDefault] = mergedChildrenIds;
158
+ childrenIndexesLookup[parentIdWithDefault] = buildSiblingIndexes(mergedChildrenIds);
159
+ const newMetaLookup = _extends({}, this.store.state.itemMetaLookup, metaLookup);
160
+ if (parentId != null && !newMetaLookup[parentId].expandable) {
161
+ newMetaLookup[parentId] = _extends({}, newMetaLookup[parentId], {
162
+ expandable: true
163
+ });
164
+ }
165
+ this.store.update({
166
+ itemMetaLookup: newMetaLookup,
167
+ itemModelLookup: _extends({}, this.store.state.itemModelLookup, modelLookup),
168
+ itemOrderedChildrenIdsLookup: _extends({}, this.store.state.itemOrderedChildrenIdsLookup, orderedChildrenIdsLookup),
169
+ itemChildrenIndexesLookup: _extends({}, this.store.state.itemChildrenIndexesLookup, childrenIndexesLookup)
170
+ });
171
+ this.store.selection.propagateSelectionToNewItems(parentId, newChildrenIds);
172
+ };
127
173
  buildPublicAPI = () => {
128
174
  return {
129
175
  getItem: this.getItem,
@@ -30,6 +30,34 @@ export declare function buildItemsLookups<R extends TreeViewValidItem<R>>(parame
30
30
  children: R[];
31
31
  }[];
32
32
  };
33
+ /**
34
+ * Builds the items lookups for a tree of items, recursing into the children of each item.
35
+ * The returned lookups only contain the items passed to this method.
36
+ */
37
+ export declare function buildItemsLookupsRecursively<R extends TreeViewValidItem<R>>(parameters: BuildItemsLookupsRecursivelyParameters<R>): {
38
+ itemMetaLookup: {
39
+ [itemId: string]: TreeViewItemMeta;
40
+ };
41
+ itemModelLookup: {
42
+ [itemId: string]: R;
43
+ };
44
+ itemOrderedChildrenIdsLookup: {
45
+ [parentItemId: string]: string[];
46
+ };
47
+ itemChildrenIndexesLookup: {
48
+ [parentItemId: string]: {
49
+ [itemId: string]: number;
50
+ };
51
+ };
52
+ };
53
+ interface BuildItemsLookupsRecursivelyParameters<R extends TreeViewValidItem<R>> extends Omit<BuildItemsLookupsParameters<R>, 'otherItemsMetaLookup'> {
54
+ /**
55
+ * The meta of the items already present in the tree, used to detect duplicated ids.
56
+ */
57
+ existingItemMetaLookup?: {
58
+ [itemId: string]: TreeViewItemMeta;
59
+ };
60
+ }
33
61
  interface BuildItemsLookupsParameters<R extends TreeViewValidItem<R>> {
34
62
  items: readonly R[];
35
63
  storeParameters: Pick<MinimalTreeViewParameters<R, any>, 'getItemId' | 'getItemLabel' | 'getItemChildren' | 'isItemDisabled' | 'isItemSelectionDisabled'>;
@@ -30,6 +30,34 @@ export declare function buildItemsLookups<R extends TreeViewValidItem<R>>(parame
30
30
  children: R[];
31
31
  }[];
32
32
  };
33
+ /**
34
+ * Builds the items lookups for a tree of items, recursing into the children of each item.
35
+ * The returned lookups only contain the items passed to this method.
36
+ */
37
+ export declare function buildItemsLookupsRecursively<R extends TreeViewValidItem<R>>(parameters: BuildItemsLookupsRecursivelyParameters<R>): {
38
+ itemMetaLookup: {
39
+ [itemId: string]: TreeViewItemMeta;
40
+ };
41
+ itemModelLookup: {
42
+ [itemId: string]: R;
43
+ };
44
+ itemOrderedChildrenIdsLookup: {
45
+ [parentItemId: string]: string[];
46
+ };
47
+ itemChildrenIndexesLookup: {
48
+ [parentItemId: string]: {
49
+ [itemId: string]: number;
50
+ };
51
+ };
52
+ };
53
+ interface BuildItemsLookupsRecursivelyParameters<R extends TreeViewValidItem<R>> extends Omit<BuildItemsLookupsParameters<R>, 'otherItemsMetaLookup'> {
54
+ /**
55
+ * The meta of the items already present in the tree, used to detect duplicated ids.
56
+ */
57
+ existingItemMetaLookup?: {
58
+ [itemId: string]: TreeViewItemMeta;
59
+ };
60
+ }
33
61
  interface BuildItemsLookupsParameters<R extends TreeViewValidItem<R>> {
34
62
  items: readonly R[];
35
63
  storeParameters: Pick<MinimalTreeViewParameters<R, any>, 'getItemId' | 'getItemLabel' | 'getItemChildren' | 'isItemDisabled' | 'isItemSelectionDisabled'>;
@@ -6,7 +6,9 @@ Object.defineProperty(exports, "__esModule", {
6
6
  });
7
7
  exports.TREE_VIEW_ROOT_PARENT_ID = void 0;
8
8
  exports.buildItemsLookups = buildItemsLookups;
9
+ exports.buildItemsLookupsRecursively = buildItemsLookupsRecursively;
9
10
  exports.isItemDisabled = exports.buildSiblingIndexes = void 0;
11
+ var _extends2 = _interopRequireDefault(require("@babel/runtime/helpers/extends"));
10
12
  var _formatErrorMessage2 = _interopRequireDefault(require("@mui/x-internals/formatErrorMessage"));
11
13
  const TREE_VIEW_ROOT_PARENT_ID = exports.TREE_VIEW_ROOT_PARENT_ID = '__TREE_VIEW_ROOT_PARENT_ID__';
12
14
  const buildSiblingIndexes = siblings => {
@@ -104,6 +106,53 @@ function buildItemsLookups(parameters) {
104
106
  itemsChildren
105
107
  };
106
108
  }
109
+
110
+ /**
111
+ * Builds the items lookups for a tree of items, recursing into the children of each item.
112
+ * The returned lookups only contain the items passed to this method.
113
+ */
114
+ function buildItemsLookupsRecursively(parameters) {
115
+ const {
116
+ storeParameters,
117
+ items,
118
+ parentId,
119
+ depth,
120
+ isItemExpandable,
121
+ existingItemMetaLookup
122
+ } = parameters;
123
+ const itemMetaLookup = {};
124
+ const itemModelLookup = {};
125
+ const itemOrderedChildrenIdsLookup = {};
126
+ const itemChildrenIndexesLookup = {};
127
+
128
+ // Both the existing items and the ones processed here, to detect duplicated ids.
129
+ const otherItemsMetaLookup = (0, _extends2.default)({}, existingItemMetaLookup);
130
+ const processSiblings = (siblings, siblingsParentId, siblingsDepth) => {
131
+ const lookups = buildItemsLookups({
132
+ storeParameters,
133
+ items: siblings,
134
+ parentId: siblingsParentId,
135
+ depth: siblingsDepth,
136
+ isItemExpandable,
137
+ otherItemsMetaLookup
138
+ });
139
+ Object.assign(itemMetaLookup, lookups.metaLookup);
140
+ Object.assign(otherItemsMetaLookup, lookups.metaLookup);
141
+ Object.assign(itemModelLookup, lookups.modelLookup);
142
+ itemOrderedChildrenIdsLookup[siblingsParentId ?? TREE_VIEW_ROOT_PARENT_ID] = lookups.orderedChildrenIds;
143
+ itemChildrenIndexesLookup[siblingsParentId ?? TREE_VIEW_ROOT_PARENT_ID] = lookups.childrenIndexes;
144
+ for (const item of lookups.itemsChildren) {
145
+ processSiblings(item.children, item.id, siblingsDepth + 1);
146
+ }
147
+ };
148
+ processSiblings(items, parentId, depth);
149
+ return {
150
+ itemMetaLookup,
151
+ itemModelLookup,
152
+ itemOrderedChildrenIdsLookup,
153
+ itemChildrenIndexesLookup
154
+ };
155
+ }
107
156
  function checkId({
108
157
  id,
109
158
  parentId,
@@ -1,3 +1,4 @@
1
+ import _extends from "@babel/runtime/helpers/esm/extends";
1
2
  import _formatErrorMessage from "@mui/x-internals/formatErrorMessage";
2
3
  export const TREE_VIEW_ROOT_PARENT_ID = '__TREE_VIEW_ROOT_PARENT_ID__';
3
4
  export const buildSiblingIndexes = siblings => {
@@ -93,6 +94,53 @@ export function buildItemsLookups(parameters) {
93
94
  itemsChildren
94
95
  };
95
96
  }
97
+
98
+ /**
99
+ * Builds the items lookups for a tree of items, recursing into the children of each item.
100
+ * The returned lookups only contain the items passed to this method.
101
+ */
102
+ export function buildItemsLookupsRecursively(parameters) {
103
+ const {
104
+ storeParameters,
105
+ items,
106
+ parentId,
107
+ depth,
108
+ isItemExpandable,
109
+ existingItemMetaLookup
110
+ } = parameters;
111
+ const itemMetaLookup = {};
112
+ const itemModelLookup = {};
113
+ const itemOrderedChildrenIdsLookup = {};
114
+ const itemChildrenIndexesLookup = {};
115
+
116
+ // Both the existing items and the ones processed here, to detect duplicated ids.
117
+ const otherItemsMetaLookup = _extends({}, existingItemMetaLookup);
118
+ const processSiblings = (siblings, siblingsParentId, siblingsDepth) => {
119
+ const lookups = buildItemsLookups({
120
+ storeParameters,
121
+ items: siblings,
122
+ parentId: siblingsParentId,
123
+ depth: siblingsDepth,
124
+ isItemExpandable,
125
+ otherItemsMetaLookup
126
+ });
127
+ Object.assign(itemMetaLookup, lookups.metaLookup);
128
+ Object.assign(otherItemsMetaLookup, lookups.metaLookup);
129
+ Object.assign(itemModelLookup, lookups.modelLookup);
130
+ itemOrderedChildrenIdsLookup[siblingsParentId ?? TREE_VIEW_ROOT_PARENT_ID] = lookups.orderedChildrenIds;
131
+ itemChildrenIndexesLookup[siblingsParentId ?? TREE_VIEW_ROOT_PARENT_ID] = lookups.childrenIndexes;
132
+ for (const item of lookups.itemsChildren) {
133
+ processSiblings(item.children, item.id, siblingsDepth + 1);
134
+ }
135
+ };
136
+ processSiblings(items, parentId, depth);
137
+ return {
138
+ itemMetaLookup,
139
+ itemModelLookup,
140
+ itemOrderedChildrenIdsLookup,
141
+ itemChildrenIndexesLookup
142
+ };
143
+ }
96
144
  function checkId({
97
145
  id,
98
146
  parentId,
@@ -1,3 +1,4 @@
1
+ import type { TreeViewItemId, TreeViewItemSelectionStatus } from "../../../models/index.mjs";
1
2
  export declare class TreeViewSelectionPlugin<Multiple extends boolean | undefined> {
2
3
  private store;
3
4
  private lastSelectedItem;
@@ -5,7 +6,15 @@ export declare class TreeViewSelectionPlugin<Multiple extends boolean | undefine
5
6
  constructor(store: any);
6
7
  private setSelectedItems;
7
8
  private selectRange;
9
+ /**
10
+ * Get the selection status of an item.
11
+ * An item that is not selected is `indeterminate` when some of its selectable descendants are selected.
12
+ * @param {TreeViewItemId} itemId The id of the item to get the selection status of.
13
+ * @returns {TreeViewItemSelectionStatus} The selection status of the item.
14
+ */
15
+ private getItemSelection;
8
16
  buildPublicAPI: () => {
17
+ getItemSelection: (itemId: TreeViewItemId) => TreeViewItemSelectionStatus;
9
18
  setItemSelection: ({
10
19
  itemId,
11
20
  event,
@@ -18,6 +27,12 @@ export declare class TreeViewSelectionPlugin<Multiple extends boolean | undefine
18
27
  keepExistingSelection?: boolean;
19
28
  }) => void;
20
29
  };
30
+ /**
31
+ * Select the items added below a selected parent when the selection propagates to the descendants.
32
+ * @param {TreeViewItemId | null} parentId The id of the item the new items were added to.
33
+ * @param {TreeViewItemId[]} newItemIds The ids of the items that were just added.
34
+ */
35
+ propagateSelectionToNewItems: (parentId: TreeViewItemId | null, newItemIds: TreeViewItemId[]) => void;
21
36
  /**
22
37
  * Select or deselect an item.
23
38
  * @param {object} parameters The parameters of the method.
@@ -1,3 +1,4 @@
1
+ import type { TreeViewItemId, TreeViewItemSelectionStatus } from "../../../models/index.js";
1
2
  export declare class TreeViewSelectionPlugin<Multiple extends boolean | undefined> {
2
3
  private store;
3
4
  private lastSelectedItem;
@@ -5,7 +6,15 @@ export declare class TreeViewSelectionPlugin<Multiple extends boolean | undefine
5
6
  constructor(store: any);
6
7
  private setSelectedItems;
7
8
  private selectRange;
9
+ /**
10
+ * Get the selection status of an item.
11
+ * An item that is not selected is `indeterminate` when some of its selectable descendants are selected.
12
+ * @param {TreeViewItemId} itemId The id of the item to get the selection status of.
13
+ * @returns {TreeViewItemSelectionStatus} The selection status of the item.
14
+ */
15
+ private getItemSelection;
8
16
  buildPublicAPI: () => {
17
+ getItemSelection: (itemId: TreeViewItemId) => TreeViewItemSelectionStatus;
9
18
  setItemSelection: ({
10
19
  itemId,
11
20
  event,
@@ -18,6 +27,12 @@ export declare class TreeViewSelectionPlugin<Multiple extends boolean | undefine
18
27
  keepExistingSelection?: boolean;
19
28
  }) => void;
20
29
  };
30
+ /**
31
+ * Select the items added below a selected parent when the selection propagates to the descendants.
32
+ * @param {TreeViewItemId | null} parentId The id of the item the new items were added to.
33
+ * @param {TreeViewItemId[]} newItemIds The ids of the items that were just added.
34
+ */
35
+ propagateSelectionToNewItems: (parentId: TreeViewItemId | null, newItemIds: TreeViewItemId[]) => void;
21
36
  /**
22
37
  * Select or deselect an item.
23
38
  * @param {object} parameters The parameters of the method.