@mui/x-tree-view-pro 8.0.0-alpha.8 → 8.0.0-beta.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 (132) hide show
  1. package/CHANGELOG.md +2566 -687
  2. package/README.md +1 -1
  3. package/RichTreeViewPro/RichTreeViewPro.d.ts +5 -5
  4. package/RichTreeViewPro/RichTreeViewPro.js +101 -89
  5. package/RichTreeViewPro/RichTreeViewPro.plugins.d.ts +4 -5
  6. package/RichTreeViewPro/RichTreeViewPro.plugins.js +10 -3
  7. package/RichTreeViewPro/RichTreeViewPro.types.d.ts +38 -38
  8. package/RichTreeViewPro/RichTreeViewPro.types.js +5 -1
  9. package/RichTreeViewPro/index.d.ts +3 -3
  10. package/RichTreeViewPro/index.js +27 -3
  11. package/RichTreeViewPro/richTreeViewProClasses.d.ts +3 -3
  12. package/RichTreeViewPro/richTreeViewProClasses.js +13 -5
  13. package/esm/RichTreeViewPro/RichTreeViewPro.d.ts +20 -0
  14. package/{node → esm}/RichTreeViewPro/RichTreeViewPro.js +95 -95
  15. package/esm/RichTreeViewPro/RichTreeViewPro.plugins.d.ts +7 -0
  16. package/esm/RichTreeViewPro/RichTreeViewPro.plugins.js +6 -0
  17. package/esm/RichTreeViewPro/RichTreeViewPro.types.d.ts +51 -0
  18. package/esm/RichTreeViewPro/RichTreeViewPro.types.js +1 -0
  19. package/esm/RichTreeViewPro/index.d.ts +3 -0
  20. package/esm/RichTreeViewPro/index.js +3 -0
  21. package/esm/RichTreeViewPro/richTreeViewProClasses.d.ts +7 -0
  22. package/esm/RichTreeViewPro/richTreeViewProClasses.js +6 -0
  23. package/esm/index.d.ts +12 -0
  24. package/esm/index.js +22 -0
  25. package/esm/internals/index.d.ts +1 -0
  26. package/esm/internals/index.js +1 -0
  27. package/esm/internals/plugins/useTreeViewItemsReordering/index.d.ts +2 -0
  28. package/esm/internals/plugins/useTreeViewItemsReordering/index.js +1 -0
  29. package/esm/internals/plugins/useTreeViewItemsReordering/useTreeViewItemsReordering.d.ts +3 -0
  30. package/esm/internals/plugins/useTreeViewItemsReordering/useTreeViewItemsReordering.itemPlugin.d.ts +3 -0
  31. package/{node → esm}/internals/plugins/useTreeViewItemsReordering/useTreeViewItemsReordering.itemPlugin.js +10 -19
  32. package/{node → esm}/internals/plugins/useTreeViewItemsReordering/useTreeViewItemsReordering.js +29 -48
  33. package/esm/internals/plugins/useTreeViewItemsReordering/useTreeViewItemsReordering.selectors.d.ts +183 -0
  34. package/{node → esm}/internals/plugins/useTreeViewItemsReordering/useTreeViewItemsReordering.selectors.js +4 -11
  35. package/esm/internals/plugins/useTreeViewItemsReordering/useTreeViewItemsReordering.types.d.ts +132 -0
  36. package/esm/internals/plugins/useTreeViewItemsReordering/useTreeViewItemsReordering.types.js +1 -0
  37. package/esm/internals/plugins/useTreeViewItemsReordering/useTreeViewItemsReordering.utils.d.ts +37 -0
  38. package/{node → esm}/internals/plugins/useTreeViewItemsReordering/useTreeViewItemsReordering.utils.js +21 -31
  39. package/esm/internals/plugins/useTreeViewLazyLoading/index.d.ts +1 -0
  40. package/esm/internals/plugins/useTreeViewLazyLoading/index.js +1 -0
  41. package/esm/internals/plugins/useTreeViewLazyLoading/useTreeViewLazyLoading.d.ts +3 -0
  42. package/esm/internals/plugins/useTreeViewLazyLoading/useTreeViewLazyLoading.js +288 -0
  43. package/esm/internals/plugins/useTreeViewLazyLoading/utils.d.ts +32 -0
  44. package/esm/internals/plugins/useTreeViewLazyLoading/utils.js +85 -0
  45. package/esm/internals/utils/releaseInfo.d.ts +1 -0
  46. package/esm/internals/utils/releaseInfo.js +13 -0
  47. package/esm/internals/zero-styled/index.d.ts +3 -0
  48. package/esm/internals/zero-styled/index.js +7 -0
  49. package/esm/package.json +1 -0
  50. package/esm/themeAugmentation/components.d.ts +11 -0
  51. package/esm/themeAugmentation/index.d.ts +3 -0
  52. package/esm/themeAugmentation/index.js +0 -0
  53. package/esm/themeAugmentation/overrides.d.ts +12 -0
  54. package/esm/themeAugmentation/props.d.ts +10 -0
  55. package/index.d.ts +2 -2
  56. package/index.js +147 -15
  57. package/internals/index.d.ts +1 -1
  58. package/internals/index.js +12 -1
  59. package/internals/plugins/useTreeViewItemsReordering/index.d.ts +2 -2
  60. package/internals/plugins/useTreeViewItemsReordering/index.js +12 -1
  61. package/internals/plugins/useTreeViewItemsReordering/useTreeViewItemsReordering.d.ts +2 -2
  62. package/internals/plugins/useTreeViewItemsReordering/useTreeViewItemsReordering.itemPlugin.d.ts +1 -1
  63. package/internals/plugins/useTreeViewItemsReordering/useTreeViewItemsReordering.itemPlugin.js +19 -10
  64. package/internals/plugins/useTreeViewItemsReordering/useTreeViewItemsReordering.js +38 -39
  65. package/internals/plugins/useTreeViewItemsReordering/useTreeViewItemsReordering.selectors.d.ts +138 -134
  66. package/internals/plugins/useTreeViewItemsReordering/useTreeViewItemsReordering.selectors.js +11 -4
  67. package/internals/plugins/useTreeViewItemsReordering/useTreeViewItemsReordering.types.d.ts +108 -117
  68. package/internals/plugins/useTreeViewItemsReordering/useTreeViewItemsReordering.types.js +5 -1
  69. package/internals/plugins/useTreeViewItemsReordering/useTreeViewItemsReordering.utils.d.ts +28 -15
  70. package/internals/plugins/useTreeViewItemsReordering/useTreeViewItemsReordering.utils.js +31 -21
  71. package/internals/plugins/useTreeViewLazyLoading/index.d.ts +1 -0
  72. package/internals/plugins/useTreeViewLazyLoading/index.js +12 -0
  73. package/internals/plugins/useTreeViewLazyLoading/useTreeViewLazyLoading.d.ts +3 -0
  74. package/internals/plugins/useTreeViewLazyLoading/useTreeViewLazyLoading.js +297 -0
  75. package/internals/plugins/useTreeViewLazyLoading/utils.d.ts +32 -0
  76. package/internals/plugins/useTreeViewLazyLoading/utils.js +89 -0
  77. package/internals/utils/releaseInfo.d.ts +1 -1
  78. package/internals/utils/releaseInfo.js +13 -5
  79. package/internals/zero-styled/index.d.ts +1 -1
  80. package/internals/zero-styled/index.js +14 -4
  81. package/modern/RichTreeViewPro/RichTreeViewPro.d.ts +20 -0
  82. package/modern/RichTreeViewPro/RichTreeViewPro.js +21 -15
  83. package/modern/RichTreeViewPro/RichTreeViewPro.plugins.d.ts +7 -0
  84. package/modern/RichTreeViewPro/RichTreeViewPro.plugins.js +2 -1
  85. package/modern/RichTreeViewPro/RichTreeViewPro.types.d.ts +51 -0
  86. package/modern/RichTreeViewPro/index.d.ts +3 -0
  87. package/modern/RichTreeViewPro/richTreeViewProClasses.d.ts +7 -0
  88. package/modern/index.d.ts +12 -0
  89. package/modern/index.js +1 -1
  90. package/modern/internals/index.d.ts +1 -0
  91. package/modern/internals/plugins/useTreeViewItemsReordering/index.d.ts +2 -0
  92. package/modern/internals/plugins/useTreeViewItemsReordering/useTreeViewItemsReordering.d.ts +3 -0
  93. package/modern/internals/plugins/useTreeViewItemsReordering/useTreeViewItemsReordering.itemPlugin.d.ts +3 -0
  94. package/modern/internals/plugins/useTreeViewItemsReordering/useTreeViewItemsReordering.js +4 -14
  95. package/modern/internals/plugins/useTreeViewItemsReordering/useTreeViewItemsReordering.selectors.d.ts +183 -0
  96. package/modern/internals/plugins/useTreeViewItemsReordering/useTreeViewItemsReordering.types.d.ts +132 -0
  97. package/modern/internals/plugins/useTreeViewItemsReordering/useTreeViewItemsReordering.utils.d.ts +37 -0
  98. package/modern/internals/plugins/useTreeViewLazyLoading/index.d.ts +1 -0
  99. package/modern/internals/plugins/useTreeViewLazyLoading/index.js +1 -0
  100. package/modern/internals/plugins/useTreeViewLazyLoading/useTreeViewLazyLoading.d.ts +3 -0
  101. package/modern/internals/plugins/useTreeViewLazyLoading/useTreeViewLazyLoading.js +288 -0
  102. package/modern/internals/plugins/useTreeViewLazyLoading/utils.d.ts +32 -0
  103. package/modern/internals/plugins/useTreeViewLazyLoading/utils.js +85 -0
  104. package/modern/internals/utils/releaseInfo.d.ts +1 -0
  105. package/modern/internals/utils/releaseInfo.js +1 -1
  106. package/modern/internals/zero-styled/index.d.ts +3 -0
  107. package/modern/package.json +1 -0
  108. package/modern/themeAugmentation/components.d.ts +11 -0
  109. package/modern/themeAugmentation/index.d.ts +3 -0
  110. package/modern/themeAugmentation/overrides.d.ts +12 -0
  111. package/modern/themeAugmentation/props.d.ts +10 -0
  112. package/package.json +43 -10
  113. package/themeAugmentation/components.d.ts +1 -3
  114. package/themeAugmentation/index.d.ts +1 -1
  115. package/themeAugmentation/index.js +1 -0
  116. package/themeAugmentation/overrides.d.ts +2 -3
  117. package/themeAugmentation/props.d.ts +2 -4
  118. package/tsconfig.build.tsbuildinfo +1 -0
  119. package/RichTreeViewPro/package.json +0 -6
  120. package/internals/package.json +0 -6
  121. package/node/RichTreeViewPro/RichTreeViewPro.plugins.js +0 -11
  122. package/node/RichTreeViewPro/RichTreeViewPro.types.js +0 -5
  123. package/node/RichTreeViewPro/index.js +0 -27
  124. package/node/RichTreeViewPro/richTreeViewProClasses.js +0 -14
  125. package/node/index.js +0 -154
  126. package/node/internals/index.js +0 -12
  127. package/node/internals/plugins/useTreeViewItemsReordering/index.js +0 -12
  128. package/node/internals/plugins/useTreeViewItemsReordering/useTreeViewItemsReordering.types.js +0 -5
  129. package/node/internals/utils/releaseInfo.js +0 -21
  130. package/node/internals/zero-styled/index.js +0 -17
  131. package/node/themeAugmentation/index.js +0 -1
  132. package/themeAugmentation/package.json +0 -6
@@ -1,17 +1,10 @@
1
- "use strict";
2
-
3
- var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
4
- Object.defineProperty(exports, "__esModule", {
5
- value: true
6
- });
7
- exports.moveItemInTree = exports.isAncestor = exports.chooseActionToApply = void 0;
8
- var _extends2 = _interopRequireDefault(require("@babel/runtime/helpers/extends"));
9
- var _internals = require("@mui/x-tree-view/internals");
1
+ import _extends from "@babel/runtime/helpers/esm/extends";
2
+ import { buildSiblingIndexes, TREE_VIEW_ROOT_PARENT_ID, selectorItemMeta } from '@mui/x-tree-view/internals';
10
3
  /**
11
4
  * Checks if the item with the id itemIdB is an ancestor of the item with the id itemIdA.
12
5
  */
13
- const isAncestor = (store, itemIdA, itemIdB) => {
14
- const itemMetaA = (0, _internals.selectorItemMeta)(store.value, itemIdA);
6
+ export const isAncestor = (store, itemIdA, itemIdB) => {
7
+ const itemMetaA = selectorItemMeta(store.value, itemIdA);
15
8
  if (itemMetaA.parentId === itemIdB) {
16
9
  return true;
17
10
  }
@@ -26,7 +19,6 @@ const isAncestor = (store, itemIdA, itemIdB) => {
26
19
  * @param {string | null} itemChildrenIndentation The indentation as passed to the `itemChildrenIndentation` prop.
27
20
  * @param {HTMLElement} contentElement The DOM element to which the indentation will be applied.
28
21
  */
29
- exports.isAncestor = isAncestor;
30
22
  const parseItemChildrenIndentation = (itemChildrenIndentation, contentElement) => {
31
23
  if (typeof itemChildrenIndentation === 'number') {
32
24
  return itemChildrenIndentation;
@@ -45,7 +37,7 @@ const parseItemChildrenIndentation = (itemChildrenIndentation, contentElement) =
45
37
  contentElement.removeChild(tempElement);
46
38
  return value;
47
39
  };
48
- const chooseActionToApply = ({
40
+ export const chooseActionToApply = ({
49
41
  itemChildrenIndentation,
50
42
  validActions,
51
43
  targetHeight,
@@ -90,24 +82,23 @@ const chooseActionToApply = ({
90
82
  }
91
83
  return action;
92
84
  };
93
- exports.chooseActionToApply = chooseActionToApply;
94
- const moveItemInTree = ({
85
+ export const moveItemInTree = ({
95
86
  itemToMoveId,
96
87
  oldPosition,
97
88
  newPosition,
98
89
  prevState
99
90
  }) => {
100
91
  const itemToMoveMeta = prevState.itemMetaLookup[itemToMoveId];
101
- const oldParentId = oldPosition.parentId ?? _internals.TREE_VIEW_ROOT_PARENT_ID;
102
- const newParentId = newPosition.parentId ?? _internals.TREE_VIEW_ROOT_PARENT_ID;
92
+ const oldParentId = oldPosition.parentId ?? TREE_VIEW_ROOT_PARENT_ID;
93
+ const newParentId = newPosition.parentId ?? TREE_VIEW_ROOT_PARENT_ID;
103
94
 
104
95
  // 1. Update the `itemOrderedChildrenIds`.
105
- const itemOrderedChildrenIds = (0, _extends2.default)({}, prevState.itemOrderedChildrenIdsLookup);
96
+ const itemOrderedChildrenIds = _extends({}, prevState.itemOrderedChildrenIdsLookup);
106
97
  if (oldParentId === newParentId) {
107
98
  const updatedChildren = [...itemOrderedChildrenIds[oldParentId]];
108
99
  updatedChildren.splice(oldPosition.index, 1);
109
100
  updatedChildren.splice(newPosition.index, 0, itemToMoveId);
110
- itemOrderedChildrenIds[itemToMoveMeta.parentId ?? _internals.TREE_VIEW_ROOT_PARENT_ID] = updatedChildren;
101
+ itemOrderedChildrenIds[itemToMoveMeta.parentId ?? TREE_VIEW_ROOT_PARENT_ID] = updatedChildren;
111
102
  } else {
112
103
  const updatedOldParentChildren = [...itemOrderedChildrenIds[oldParentId]];
113
104
  updatedOldParentChildren.splice(oldPosition.index, 1);
@@ -118,51 +109,50 @@ const moveItemInTree = ({
118
109
  }
119
110
 
120
111
  // 2. Update the `itemChildrenIndexes`
121
- const itemChildrenIndexes = (0, _extends2.default)({}, prevState.itemChildrenIndexesLookup);
122
- itemChildrenIndexes[oldParentId] = (0, _internals.buildSiblingIndexes)(itemOrderedChildrenIds[oldParentId]);
112
+ const itemChildrenIndexes = _extends({}, prevState.itemChildrenIndexesLookup);
113
+ itemChildrenIndexes[oldParentId] = buildSiblingIndexes(itemOrderedChildrenIds[oldParentId]);
123
114
  if (newParentId !== oldParentId) {
124
- itemChildrenIndexes[newParentId] = (0, _internals.buildSiblingIndexes)(itemOrderedChildrenIds[newParentId]);
115
+ itemChildrenIndexes[newParentId] = buildSiblingIndexes(itemOrderedChildrenIds[newParentId]);
125
116
  }
126
117
 
127
118
  // 3. Update the `itemMetaLookup`
128
- const itemMetaLookup = (0, _extends2.default)({}, prevState.itemMetaLookup);
119
+ const itemMetaLookup = _extends({}, prevState.itemMetaLookup);
129
120
 
130
121
  // 3.1 Update the `expandable` property of the old and the new parent
131
122
  function updateExpandable(itemId) {
132
123
  const isExpandable = itemOrderedChildrenIds[itemId].length > 0;
133
124
  if (itemMetaLookup[itemId].expandable !== isExpandable) {
134
- itemMetaLookup[itemId] = (0, _extends2.default)({}, itemMetaLookup[itemId], {
125
+ itemMetaLookup[itemId] = _extends({}, itemMetaLookup[itemId], {
135
126
  expandable: isExpandable
136
127
  });
137
128
  }
138
129
  }
139
- if (oldParentId !== _internals.TREE_VIEW_ROOT_PARENT_ID && oldParentId !== newParentId) {
130
+ if (oldParentId !== TREE_VIEW_ROOT_PARENT_ID && oldParentId !== newParentId) {
140
131
  updateExpandable(oldParentId);
141
132
  }
142
- if (newParentId !== _internals.TREE_VIEW_ROOT_PARENT_ID && newParentId !== oldParentId) {
133
+ if (newParentId !== TREE_VIEW_ROOT_PARENT_ID && newParentId !== oldParentId) {
143
134
  updateExpandable(newParentId);
144
135
  }
145
136
 
146
137
  // 3.2 Update the `parentId` and `depth` properties of the item to move
147
138
  // The depth is always defined because drag&drop is only usable with Rich Tree View components.
148
139
  const itemToMoveDepth = newPosition.parentId == null ? 0 : itemMetaLookup[newParentId].depth + 1;
149
- itemMetaLookup[itemToMoveId] = (0, _extends2.default)({}, itemToMoveMeta, {
140
+ itemMetaLookup[itemToMoveId] = _extends({}, itemToMoveMeta, {
150
141
  parentId: newPosition.parentId,
151
142
  depth: itemToMoveDepth
152
143
  });
153
144
 
154
145
  // 3.3 Update the depth of all the children of the item to move
155
146
  const updateItemDepth = (itemId, depth) => {
156
- itemMetaLookup[itemId] = (0, _extends2.default)({}, itemMetaLookup[itemId], {
147
+ itemMetaLookup[itemId] = _extends({}, itemMetaLookup[itemId], {
157
148
  depth
158
149
  });
159
150
  itemOrderedChildrenIds[itemId]?.forEach(childId => updateItemDepth(childId, depth + 1));
160
151
  };
161
152
  itemOrderedChildrenIds[itemToMoveId]?.forEach(childId => updateItemDepth(childId, itemToMoveDepth + 1));
162
- return (0, _extends2.default)({}, prevState, {
153
+ return _extends({}, prevState, {
163
154
  itemOrderedChildrenIdsLookup: itemOrderedChildrenIds,
164
155
  itemChildrenIndexesLookup: itemChildrenIndexes,
165
156
  itemMetaLookup
166
157
  });
167
- };
168
- exports.moveItemInTree = moveItemInTree;
158
+ };
@@ -0,0 +1 @@
1
+ export { useTreeViewLazyLoading } from "./useTreeViewLazyLoading.js";
@@ -0,0 +1 @@
1
+ export { useTreeViewLazyLoading } from "./useTreeViewLazyLoading.js";
@@ -0,0 +1,3 @@
1
+ import { TreeViewPlugin } from '@mui/x-tree-view/internals';
2
+ import type { UseTreeViewLazyLoadingSignature } from '@mui/x-tree-view/internals';
3
+ export declare const useTreeViewLazyLoading: TreeViewPlugin<UseTreeViewLazyLoadingSignature>;
@@ -0,0 +1,288 @@
1
+ import _extends from "@babel/runtime/helpers/esm/extends";
2
+ import * as React from 'react';
3
+ import useLazyRef from '@mui/utils/useLazyRef';
4
+ import { warnOnce } from '@mui/x-internals/warning';
5
+ import useEventCallback from '@mui/utils/useEventCallback';
6
+ import { selectorItemMeta, selectorIsItemSelected, useInstanceEventHandler, selectorDataSourceState, selectorGetTreeItemError } from '@mui/x-tree-view/internals';
7
+ import { DataSourceCacheDefault } from '@mui/x-tree-view/utils';
8
+ import { NestedDataManager } from "./utils.js";
9
+ const INITIAL_STATE = {
10
+ loading: {},
11
+ errors: {}
12
+ };
13
+ const noopCache = {
14
+ clear: () => {},
15
+ get: () => undefined,
16
+ set: () => {}
17
+ };
18
+ function getCache(cacheProp) {
19
+ if (cacheProp === null) {
20
+ return noopCache;
21
+ }
22
+ return cacheProp ?? new DataSourceCacheDefault({});
23
+ }
24
+ export const useTreeViewLazyLoading = ({
25
+ instance,
26
+ params,
27
+ store
28
+ }) => {
29
+ const isLazyLoadingEnabled = params.dataSource?.getChildrenCount !== undefined;
30
+ const firstRenderRef = React.useRef(true);
31
+ const nestedDataManager = useLazyRef(() => new NestedDataManager(instance)).current;
32
+ const cacheRef = useLazyRef(() => getCache(params.dataSourceCache));
33
+ const setDataSourceLoading = useEventCallback((itemId, isLoading) => {
34
+ if (!isLazyLoadingEnabled) {
35
+ return;
36
+ }
37
+ store.update(prevState => {
38
+ if (!prevState.lazyLoading.dataSource.loading[itemId] && !isLoading) {
39
+ return prevState;
40
+ }
41
+ const loading = _extends({}, prevState.lazyLoading.dataSource.loading);
42
+ if (isLoading === false) {
43
+ delete loading[itemId];
44
+ } else {
45
+ loading[itemId] = isLoading;
46
+ }
47
+ return _extends({}, prevState, {
48
+ lazyLoading: _extends({}, prevState.lazyLoading, {
49
+ dataSource: _extends({}, prevState.lazyLoading.dataSource, {
50
+ loading
51
+ })
52
+ })
53
+ });
54
+ });
55
+ });
56
+ const setDataSourceError = (itemId, error) => {
57
+ if (!isLazyLoadingEnabled) {
58
+ return;
59
+ }
60
+ store.update(prevState => {
61
+ const errors = _extends({}, prevState.lazyLoading.dataSource.errors);
62
+ if (error === null && errors[itemId] !== undefined) {
63
+ delete errors[itemId];
64
+ } else {
65
+ errors[itemId] = error;
66
+ }
67
+ errors[itemId] = error;
68
+ return _extends({}, prevState, {
69
+ lazyLoading: _extends({}, prevState.lazyLoading, {
70
+ dataSource: _extends({}, prevState.lazyLoading.dataSource, {
71
+ errors
72
+ })
73
+ })
74
+ });
75
+ });
76
+ };
77
+ const resetDataSourceState = useEventCallback(() => {
78
+ if (!isLazyLoadingEnabled) {
79
+ return;
80
+ }
81
+ store.update(prevState => _extends({}, prevState, {
82
+ lazyLoading: _extends({}, prevState.lazyLoading, {
83
+ dataSource: INITIAL_STATE
84
+ })
85
+ }));
86
+ });
87
+ const fetchItems = useEventCallback(async parentIds => {
88
+ if (!isLazyLoadingEnabled) {
89
+ return;
90
+ }
91
+ const getChildrenCount = params.dataSource?.getChildrenCount || (() => 0);
92
+ const getTreeItems = params.dataSource?.getTreeItems;
93
+ if (!getTreeItems) {
94
+ return;
95
+ }
96
+ if (parentIds) {
97
+ await nestedDataManager.queue(parentIds);
98
+ return;
99
+ }
100
+ nestedDataManager.clear();
101
+
102
+ // reset the state if we are refetching the first visible items
103
+ if (selectorDataSourceState(store.value) !== INITIAL_STATE) {
104
+ resetDataSourceState();
105
+ }
106
+ // handle caching here
107
+ const cachedData = cacheRef.current.get('root');
108
+ if (cachedData !== undefined) {
109
+ return;
110
+ }
111
+
112
+ // handle loading here
113
+ instance.setTreeViewLoading(true);
114
+ try {
115
+ const getTreeItemsResponse = await getTreeItems();
116
+
117
+ // set caching
118
+ cacheRef.current.set('root', getTreeItemsResponse);
119
+
120
+ // update the items in the state
121
+ instance.addItems({
122
+ items: getTreeItemsResponse,
123
+ depth: 0,
124
+ getChildrenCount
125
+ });
126
+ } catch (error) {
127
+ // set the items to empty
128
+ instance.addItems({
129
+ items: [],
130
+ depth: 0,
131
+ getChildrenCount
132
+ });
133
+ // set error state
134
+ instance.setTreeViewError(error);
135
+ } finally {
136
+ // set loading state
137
+ instance.setTreeViewLoading(false);
138
+ }
139
+ });
140
+ const fetchItemChildren = useEventCallback(async id => {
141
+ if (!isLazyLoadingEnabled) {
142
+ return;
143
+ }
144
+ const getChildrenCount = params.dataSource?.getChildrenCount || (() => 0);
145
+ const getTreeItems = params.dataSource?.getTreeItems;
146
+ if (!getTreeItems) {
147
+ nestedDataManager.clearPendingRequest(id);
148
+ return;
149
+ }
150
+ const parent = selectorItemMeta(store.value, id);
151
+ if (!parent) {
152
+ nestedDataManager.clearPendingRequest(id);
153
+ return;
154
+ }
155
+ const depth = parent.depth ? parent.depth + 1 : 1;
156
+
157
+ // handle loading here
158
+ instance.setDataSourceLoading(id, true);
159
+
160
+ // handle caching here
161
+ const cachedData = cacheRef.current.get(id);
162
+ if (cachedData !== undefined && cachedData !== -1) {
163
+ nestedDataManager.setRequestSettled(id);
164
+ instance.addItems({
165
+ items: cachedData,
166
+ depth,
167
+ parentId: id,
168
+ getChildrenCount
169
+ });
170
+ instance.setDataSourceLoading(id, false);
171
+ return;
172
+ }
173
+ if (cachedData === -1) {
174
+ instance.removeChildren(id);
175
+ }
176
+ const existingError = selectorGetTreeItemError(store.value, id) ?? null;
177
+ if (existingError) {
178
+ instance.setDataSourceError(id, null);
179
+ }
180
+ try {
181
+ const getTreeItemsResponse = await getTreeItems(id);
182
+ nestedDataManager.setRequestSettled(id);
183
+
184
+ // set caching
185
+ cacheRef.current.set(id, getTreeItemsResponse);
186
+ // update the items in the state
187
+ instance.addItems({
188
+ items: getTreeItemsResponse,
189
+ depth,
190
+ parentId: id,
191
+ getChildrenCount
192
+ });
193
+ } catch (error) {
194
+ const childrenFetchError = error;
195
+ // handle errors here
196
+ instance.setDataSourceError(id, childrenFetchError);
197
+ instance.removeChildren(id);
198
+ } finally {
199
+ // unset loading
200
+ instance.setDataSourceLoading(id, false);
201
+ nestedDataManager.setRequestSettled(id);
202
+ }
203
+ });
204
+ useInstanceEventHandler(instance, 'beforeItemToggleExpansion', async eventParameters => {
205
+ if (!isLazyLoadingEnabled || !eventParameters.shouldBeExpanded) {
206
+ return;
207
+ }
208
+ eventParameters.isExpansionPrevented = true;
209
+ await instance.fetchItems([eventParameters.itemId]);
210
+ const fetchErrors = Boolean(selectorGetTreeItemError(store.value, eventParameters.itemId));
211
+ if (!fetchErrors) {
212
+ instance.applyItemExpansion({
213
+ itemId: eventParameters.itemId,
214
+ shouldBeExpanded: true,
215
+ event: eventParameters.event
216
+ });
217
+ if (selectorIsItemSelected(store.value, eventParameters.itemId)) {
218
+ // make sure selection propagation works correctly
219
+ instance.setItemSelection({
220
+ event: eventParameters.event,
221
+ itemId: eventParameters.itemId,
222
+ keepExistingSelection: true,
223
+ shouldBeSelected: true
224
+ });
225
+ }
226
+ }
227
+ });
228
+ React.useEffect(() => {
229
+ if (isLazyLoadingEnabled && firstRenderRef.current) {
230
+ store.update(prevState => _extends({}, prevState, {
231
+ lazyLoading: _extends({}, prevState.lazyLoading, {
232
+ enabled: true
233
+ })
234
+ }));
235
+ if (params.items.length) {
236
+ const getChildrenCount = params.dataSource?.getChildrenCount || (() => 0);
237
+ instance.addItems({
238
+ items: params.items,
239
+ depth: 0,
240
+ getChildrenCount
241
+ });
242
+ } else {
243
+ instance.fetchItems();
244
+ }
245
+ firstRenderRef.current = false;
246
+ }
247
+ }, [instance, params.items, params.dataSource, isLazyLoadingEnabled, store]);
248
+ if (isLazyLoadingEnabled) {
249
+ instance.preventItemUpdates();
250
+ }
251
+ return {
252
+ instance: {
253
+ fetchItemChildren,
254
+ fetchItems,
255
+ setDataSourceLoading,
256
+ setDataSourceError
257
+ },
258
+ publicAPI: {}
259
+ };
260
+ };
261
+ useTreeViewLazyLoading.getDefaultizedParams = ({
262
+ params,
263
+ experimentalFeatures
264
+ }) => {
265
+ const canUseFeature = experimentalFeatures?.lazyLoading;
266
+ if (process.env.NODE_ENV !== 'production') {
267
+ if (params.dataSource && !canUseFeature) {
268
+ warnOnce(['MUI X: The label editing feature requires the `lazyLoading` experimental feature to be enabled.', 'You can do it by passing `experimentalFeatures={{ lazyLoading: true}}` to the Rich Tree View Pro component.', 'Check the documentation for more details: https://mui.com/x/react-tree-view/rich-tree-view/lazy-loading/']);
269
+ }
270
+ }
271
+ const defaultDataSource = params?.dataSource ?? {
272
+ getChildrenCount: () => 0,
273
+ getTreeItems: () => Promise.resolve([])
274
+ };
275
+ return _extends({}, params, {
276
+ dataSource: canUseFeature ? defaultDataSource : {}
277
+ });
278
+ };
279
+ useTreeViewLazyLoading.getInitialState = () => ({
280
+ lazyLoading: {
281
+ enabled: false,
282
+ dataSource: INITIAL_STATE
283
+ }
284
+ });
285
+ useTreeViewLazyLoading.params = {
286
+ dataSource: true,
287
+ dataSourceCache: true
288
+ };
@@ -0,0 +1,32 @@
1
+ import { TreeViewInstance, UseTreeViewLazyLoadingSignature } from '@mui/x-tree-view/internals';
2
+ import { TreeViewItemId } from '@mui/x-tree-view/models';
3
+ export declare enum RequestStatus {
4
+ QUEUED = 0,
5
+ PENDING = 1,
6
+ SETTLED = 2,
7
+ UNKNOWN = 3,
8
+ }
9
+ /**
10
+ * Plugins that the `NestedDataManager` class can use if they are present, but are not required.
11
+ */
12
+ export type NestedDataManagerOptionalPlugins = readonly [];
13
+ /**
14
+ * Fetches row children from the server with option to limit the number of concurrent requests
15
+ * Determines the status of a request based on the enum `RequestStatus`
16
+ * Uses `ParentId` to uniquely identify a request
17
+ */
18
+ export declare class NestedDataManager {
19
+ private pendingRequests;
20
+ private queuedRequests;
21
+ private settledRequests;
22
+ private instance;
23
+ private maxConcurrentRequests;
24
+ constructor(instance: TreeViewInstance<[UseTreeViewLazyLoadingSignature]>, maxConcurrentRequests?: number);
25
+ private processQueue;
26
+ queue: (ids: TreeViewItemId[]) => Promise<void>;
27
+ setRequestSettled: (id: TreeViewItemId) => Promise<void>;
28
+ clear: () => void;
29
+ clearPendingRequest: (id: TreeViewItemId) => Promise<void>;
30
+ getRequestStatus: (id: TreeViewItemId) => RequestStatus;
31
+ getActiveRequestsCount: () => number;
32
+ }
@@ -0,0 +1,85 @@
1
+ const MAX_CONCURRENT_REQUESTS = Infinity;
2
+ export let RequestStatus = /*#__PURE__*/function (RequestStatus) {
3
+ RequestStatus[RequestStatus["QUEUED"] = 0] = "QUEUED";
4
+ RequestStatus[RequestStatus["PENDING"] = 1] = "PENDING";
5
+ RequestStatus[RequestStatus["SETTLED"] = 2] = "SETTLED";
6
+ RequestStatus[RequestStatus["UNKNOWN"] = 3] = "UNKNOWN";
7
+ return RequestStatus;
8
+ }({});
9
+
10
+ /**
11
+ * Plugins that need to be present in the Tree View in order for the `NestedDataManager` class to work correctly.
12
+ */
13
+
14
+ /**
15
+ * Plugins that the `NestedDataManager` class can use if they are present, but are not required.
16
+ */
17
+
18
+ /**
19
+ * Fetches row children from the server with option to limit the number of concurrent requests
20
+ * Determines the status of a request based on the enum `RequestStatus`
21
+ * Uses `ParentId` to uniquely identify a request
22
+ */
23
+ export class NestedDataManager {
24
+ constructor(instance, maxConcurrentRequests = MAX_CONCURRENT_REQUESTS) {
25
+ this.pendingRequests = new Set();
26
+ this.queuedRequests = new Set();
27
+ this.settledRequests = new Set();
28
+ this.instance = void 0;
29
+ this.maxConcurrentRequests = void 0;
30
+ this.processQueue = async () => {
31
+ if (this.queuedRequests.size === 0 || this.pendingRequests.size >= this.maxConcurrentRequests) {
32
+ return;
33
+ }
34
+ const loopLength = Math.min(this.maxConcurrentRequests - this.pendingRequests.size, this.queuedRequests.size);
35
+ if (loopLength === 0) {
36
+ return;
37
+ }
38
+ const fetchQueue = Array.from(this.queuedRequests);
39
+ const fetchPromises = [];
40
+ for (let i = 0; i < loopLength; i += 1) {
41
+ const id = fetchQueue[i];
42
+ this.queuedRequests.delete(id);
43
+ this.pendingRequests.add(id);
44
+ fetchPromises.push(this.instance.fetchItemChildren(id));
45
+ }
46
+ await Promise.all(fetchPromises);
47
+ };
48
+ this.queue = async ids => {
49
+ const loadingIds = {};
50
+ ids.forEach(id => {
51
+ this.queuedRequests.add(id);
52
+ loadingIds[id] = true;
53
+ });
54
+ await this.processQueue();
55
+ };
56
+ this.setRequestSettled = async id => {
57
+ this.pendingRequests.delete(id);
58
+ this.settledRequests.add(id);
59
+ await this.processQueue();
60
+ };
61
+ this.clear = () => {
62
+ this.queuedRequests.clear();
63
+ Array.from(this.pendingRequests).forEach(id => this.clearPendingRequest(id));
64
+ };
65
+ this.clearPendingRequest = async id => {
66
+ this.pendingRequests.delete(id);
67
+ await this.processQueue();
68
+ };
69
+ this.getRequestStatus = id => {
70
+ if (this.pendingRequests.has(id)) {
71
+ return RequestStatus.PENDING;
72
+ }
73
+ if (this.queuedRequests.has(id)) {
74
+ return RequestStatus.QUEUED;
75
+ }
76
+ if (this.settledRequests.has(id)) {
77
+ return RequestStatus.SETTLED;
78
+ }
79
+ return RequestStatus.UNKNOWN;
80
+ };
81
+ this.getActiveRequestsCount = () => this.pendingRequests.size + this.queuedRequests.size;
82
+ this.instance = instance;
83
+ this.maxConcurrentRequests = maxConcurrentRequests;
84
+ }
85
+ }
@@ -0,0 +1 @@
1
+ export declare const getReleaseInfo: () => any;
@@ -0,0 +1,13 @@
1
+ import ponyfillGlobal from '@mui/utils/ponyfillGlobal';
2
+ export const getReleaseInfo = () => {
3
+ const releaseInfo = "MTc0MjI0ODgwMDAwMA==";
4
+ if (process.env.NODE_ENV !== 'production') {
5
+ // A simple hack to set the value in the test environment (has no build step).
6
+ // eslint-disable-next-line no-useless-concat
7
+ if (releaseInfo === '__RELEASE' + '_INFO__') {
8
+ // eslint-disable-next-line no-underscore-dangle
9
+ return ponyfillGlobal.__MUI_RELEASE_INFO__;
10
+ }
11
+ }
12
+ return releaseInfo;
13
+ };
@@ -0,0 +1,3 @@
1
+ import { useThemeProps } from '@mui/material/styles';
2
+ export { styled } from '@mui/material/styles';
3
+ export declare function createUseThemeProps(name: string): typeof useThemeProps;
@@ -0,0 +1,7 @@
1
+ import { useThemeProps } from '@mui/material/styles';
2
+ export { styled } from '@mui/material/styles';
3
+
4
+ // eslint-disable-next-line @typescript-eslint/no-unused-vars
5
+ export function createUseThemeProps(name) {
6
+ return useThemeProps;
7
+ }
@@ -0,0 +1 @@
1
+ {"type":"module","sideEffects":false}
@@ -0,0 +1,11 @@
1
+ import { ComponentsProps, ComponentsOverrides, ComponentsVariants } from '@mui/material/styles';
2
+ export interface TreeViewComponents<Theme = unknown> {
3
+ MuiRichTreeViewPro?: {
4
+ defaultProps?: ComponentsProps['MuiRichTreeViewPro'];
5
+ styleOverrides?: ComponentsOverrides<Theme>['MuiRichTreeViewPro'];
6
+ variants?: ComponentsVariants<Theme>['MuiRichTreeViewPro'];
7
+ };
8
+ }
9
+ declare module '@mui/material/styles' {
10
+ interface Components<Theme = unknown> extends TreeViewComponents<Theme> {}
11
+ }
@@ -0,0 +1,3 @@
1
+ export type * from './overrides';
2
+ export type * from './props';
3
+ export type * from './components';
File without changes
@@ -0,0 +1,12 @@
1
+ import { RichTreeViewProClassKey } from "../RichTreeViewPro/index.js";
2
+
3
+ // prettier-ignore
4
+ export interface TreeViewComponentNameToClassKey {
5
+ MuiRichTreeViewPro: RichTreeViewProClassKey;
6
+ }
7
+ declare module '@mui/material/styles' {
8
+ interface ComponentNameToClassKey extends TreeViewComponentNameToClassKey {}
9
+ }
10
+
11
+ // disable automatic export
12
+ export {};
@@ -0,0 +1,10 @@
1
+ import { RichTreeViewProProps } from "../RichTreeViewPro/index.js";
2
+ export interface TreeViewComponentsPropsList {
3
+ MuiRichTreeViewPro: RichTreeViewProProps<any, any>;
4
+ }
5
+ declare module '@mui/material/styles' {
6
+ interface ComponentsPropsList extends TreeViewComponentsPropsList {}
7
+ }
8
+
9
+ // disable automatic export
10
+ export {};
package/index.d.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  export * from '@mui/x-tree-view/SimpleTreeView';
2
- export * from './RichTreeViewPro';
2
+ export * from "./RichTreeViewPro/index.js";
3
3
  export * from '@mui/x-tree-view/TreeItem';
4
4
  export * from '@mui/x-tree-view/useTreeItem';
5
5
  export * from '@mui/x-tree-view/TreeItemIcon';
@@ -9,4 +9,4 @@ export * from '@mui/x-tree-view/TreeItemLabelInput';
9
9
  export { unstable_resetCleanupTracking } from '@mui/x-tree-view/internals';
10
10
  export * from '@mui/x-tree-view/models';
11
11
  export * from '@mui/x-tree-view/icons';
12
- export * from '@mui/x-tree-view/hooks';
12
+ export * from '@mui/x-tree-view/hooks';