@mui/x-tree-view-pro 8.11.0 → 8.11.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +169 -0
- package/RichTreeViewPro/RichTreeViewPro.js +14 -12
- package/RichTreeViewPro/RichTreeViewPro.types.d.ts +3 -2
- package/RichTreeViewPro/index.d.ts +2 -1
- package/esm/RichTreeViewPro/RichTreeViewPro.js +14 -12
- package/esm/RichTreeViewPro/RichTreeViewPro.types.d.ts +3 -2
- package/esm/RichTreeViewPro/index.d.ts +2 -1
- package/esm/index.js +1 -1
- package/esm/internals/plugins/useTreeViewItemsReordering/index.d.ts +2 -1
- package/esm/internals/plugins/useTreeViewItemsReordering/index.js +2 -1
- package/esm/internals/plugins/useTreeViewItemsReordering/useTreeViewItemsReordering.itemPlugin.js +6 -5
- package/esm/internals/plugins/useTreeViewItemsReordering/useTreeViewItemsReordering.js +57 -71
- package/esm/internals/plugins/useTreeViewItemsReordering/useTreeViewItemsReordering.selectors.d.ts +17 -433
- package/esm/internals/plugins/useTreeViewItemsReordering/useTreeViewItemsReordering.selectors.js +35 -50
- package/esm/internals/plugins/useTreeViewItemsReordering/useTreeViewItemsReordering.utils.js +2 -2
- package/esm/internals/plugins/useTreeViewLazyLoading/useTreeViewLazyLoading.js +82 -78
- package/esm/internals/plugins/useTreeViewLazyLoading/utils.js +3 -1
- package/index.js +1 -1
- package/internals/plugins/useTreeViewItemsReordering/index.d.ts +2 -1
- package/internals/plugins/useTreeViewItemsReordering/index.js +8 -1
- package/internals/plugins/useTreeViewItemsReordering/useTreeViewItemsReordering.itemPlugin.js +4 -3
- package/internals/plugins/useTreeViewItemsReordering/useTreeViewItemsReordering.js +55 -69
- package/internals/plugins/useTreeViewItemsReordering/useTreeViewItemsReordering.selectors.d.ts +17 -433
- package/internals/plugins/useTreeViewItemsReordering/useTreeViewItemsReordering.selectors.js +35 -50
- package/internals/plugins/useTreeViewItemsReordering/useTreeViewItemsReordering.utils.js +1 -1
- package/internals/plugins/useTreeViewLazyLoading/useTreeViewLazyLoading.js +81 -77
- package/internals/plugins/useTreeViewLazyLoading/utils.js +3 -1
- package/package.json +15 -14
|
@@ -42,54 +42,44 @@ const useTreeViewLazyLoading = ({
|
|
|
42
42
|
if (!isLazyLoadingEnabled) {
|
|
43
43
|
return;
|
|
44
44
|
}
|
|
45
|
-
store.
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
})
|
|
60
|
-
})
|
|
61
|
-
});
|
|
62
|
-
});
|
|
45
|
+
if (_internals.lazyLoadingSelectors.isItemLoading(store.state, itemId) === isLoading) {
|
|
46
|
+
return;
|
|
47
|
+
}
|
|
48
|
+
const loadingState = (0, _extends2.default)({}, store.state.lazyLoading.dataSource.loading);
|
|
49
|
+
if (isLoading === false) {
|
|
50
|
+
delete loadingState[itemId];
|
|
51
|
+
} else {
|
|
52
|
+
loadingState[itemId] = isLoading;
|
|
53
|
+
}
|
|
54
|
+
store.set('lazyLoading', (0, _extends2.default)({}, store.state.lazyLoading, {
|
|
55
|
+
dataSource: (0, _extends2.default)({}, store.state.lazyLoading.dataSource, {
|
|
56
|
+
loading: loadingState
|
|
57
|
+
})
|
|
58
|
+
}));
|
|
63
59
|
});
|
|
64
60
|
const setDataSourceError = (itemId, error) => {
|
|
65
61
|
if (!isLazyLoadingEnabled) {
|
|
66
62
|
return;
|
|
67
63
|
}
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
} else {
|
|
73
|
-
errors[itemId] = error;
|
|
74
|
-
}
|
|
64
|
+
const errors = (0, _extends2.default)({}, store.state.lazyLoading.dataSource.errors);
|
|
65
|
+
if (error === null && errors[itemId] !== undefined) {
|
|
66
|
+
delete errors[itemId];
|
|
67
|
+
} else {
|
|
75
68
|
errors[itemId] = error;
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
});
|
|
69
|
+
}
|
|
70
|
+
errors[itemId] = error;
|
|
71
|
+
store.set('lazyLoading', (0, _extends2.default)({}, store.state.lazyLoading, {
|
|
72
|
+
dataSource: (0, _extends2.default)({}, store.state.lazyLoading.dataSource, {
|
|
73
|
+
errors
|
|
74
|
+
})
|
|
75
|
+
}));
|
|
84
76
|
};
|
|
85
77
|
const resetDataSourceState = (0, _useEventCallback.default)(() => {
|
|
86
78
|
if (!isLazyLoadingEnabled) {
|
|
87
79
|
return;
|
|
88
80
|
}
|
|
89
|
-
store.
|
|
90
|
-
|
|
91
|
-
dataSource: INITIAL_STATE
|
|
92
|
-
})
|
|
81
|
+
store.set('lazyLoading', (0, _extends2.default)({}, store.state.lazyLoading, {
|
|
82
|
+
dataSource: INITIAL_STATE
|
|
93
83
|
}));
|
|
94
84
|
});
|
|
95
85
|
const fetchItems = (0, _useEventCallback.default)(async parentIds => {
|
|
@@ -109,7 +99,7 @@ const useTreeViewLazyLoading = ({
|
|
|
109
99
|
// handle loading here
|
|
110
100
|
instance.setTreeViewLoading(true);
|
|
111
101
|
// reset the state if we are refetching the first visible items
|
|
112
|
-
if (
|
|
102
|
+
if (_internals.lazyLoadingSelectors.dataSource(store.state) !== INITIAL_STATE) {
|
|
113
103
|
resetDataSourceState();
|
|
114
104
|
}
|
|
115
105
|
// handle caching here
|
|
@@ -149,70 +139,83 @@ const useTreeViewLazyLoading = ({
|
|
|
149
139
|
instance.setTreeViewLoading(false);
|
|
150
140
|
}
|
|
151
141
|
});
|
|
152
|
-
const fetchItemChildren = (0, _useEventCallback.default)(async
|
|
142
|
+
const fetchItemChildren = (0, _useEventCallback.default)(async ({
|
|
143
|
+
itemId,
|
|
144
|
+
forceRefresh
|
|
145
|
+
}) => {
|
|
153
146
|
if (!isLazyLoadingEnabled) {
|
|
154
147
|
return;
|
|
155
148
|
}
|
|
156
149
|
const getChildrenCount = params.dataSource?.getChildrenCount || (() => 0);
|
|
157
150
|
const getTreeItems = params.dataSource?.getTreeItems;
|
|
158
151
|
if (!getTreeItems) {
|
|
159
|
-
nestedDataManager.clearPendingRequest(
|
|
152
|
+
nestedDataManager.clearPendingRequest(itemId);
|
|
160
153
|
return;
|
|
161
154
|
}
|
|
162
|
-
const parent =
|
|
155
|
+
const parent = _internals.itemsSelectors.itemMeta(store.state, itemId);
|
|
163
156
|
if (!parent) {
|
|
164
|
-
nestedDataManager.clearPendingRequest(
|
|
157
|
+
nestedDataManager.clearPendingRequest(itemId);
|
|
165
158
|
return;
|
|
166
159
|
}
|
|
167
160
|
const depth = parent.depth ? parent.depth + 1 : 1;
|
|
168
161
|
|
|
169
162
|
// handle loading here
|
|
170
|
-
instance.setDataSourceLoading(
|
|
163
|
+
instance.setDataSourceLoading(itemId, true);
|
|
171
164
|
|
|
172
165
|
// handle caching here
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
166
|
+
if (!forceRefresh) {
|
|
167
|
+
const cachedData = cacheRef.current.get(itemId);
|
|
168
|
+
if (cachedData !== undefined && cachedData !== -1) {
|
|
169
|
+
nestedDataManager.setRequestSettled(itemId);
|
|
170
|
+
instance.addItems({
|
|
171
|
+
items: cachedData,
|
|
172
|
+
depth,
|
|
173
|
+
parentId: itemId,
|
|
174
|
+
getChildrenCount
|
|
175
|
+
});
|
|
176
|
+
instance.setDataSourceLoading(itemId, false);
|
|
177
|
+
return;
|
|
178
|
+
}
|
|
179
|
+
if (cachedData === -1) {
|
|
180
|
+
instance.removeChildren(itemId);
|
|
181
|
+
}
|
|
187
182
|
}
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
instance.setDataSourceError(id, null);
|
|
183
|
+
if (_internals.lazyLoadingSelectors.itemHasError(store.state, itemId)) {
|
|
184
|
+
instance.setDataSourceError(itemId, null);
|
|
191
185
|
}
|
|
192
186
|
try {
|
|
193
|
-
const getTreeItemsResponse = await getTreeItems(
|
|
194
|
-
nestedDataManager.setRequestSettled(
|
|
187
|
+
const getTreeItemsResponse = await getTreeItems(itemId);
|
|
188
|
+
nestedDataManager.setRequestSettled(itemId);
|
|
195
189
|
|
|
196
190
|
// set caching
|
|
197
|
-
cacheRef.current.set(
|
|
191
|
+
cacheRef.current.set(itemId, getTreeItemsResponse);
|
|
198
192
|
// update the items in the state
|
|
193
|
+
if (forceRefresh) {
|
|
194
|
+
instance.removeChildren(itemId);
|
|
195
|
+
}
|
|
199
196
|
instance.addItems({
|
|
200
197
|
items: getTreeItemsResponse,
|
|
201
198
|
depth,
|
|
202
|
-
parentId:
|
|
199
|
+
parentId: itemId,
|
|
203
200
|
getChildrenCount
|
|
204
201
|
});
|
|
205
202
|
} catch (error) {
|
|
206
203
|
const childrenFetchError = error;
|
|
207
204
|
// handle errors here
|
|
208
|
-
instance.setDataSourceError(
|
|
209
|
-
instance.removeChildren(
|
|
205
|
+
instance.setDataSourceError(itemId, childrenFetchError);
|
|
206
|
+
instance.removeChildren(itemId);
|
|
210
207
|
} finally {
|
|
211
208
|
// unset loading
|
|
212
|
-
instance.setDataSourceLoading(
|
|
213
|
-
nestedDataManager.setRequestSettled(
|
|
209
|
+
instance.setDataSourceLoading(itemId, false);
|
|
210
|
+
nestedDataManager.setRequestSettled(itemId);
|
|
214
211
|
}
|
|
215
212
|
});
|
|
213
|
+
const updateItemChildren = (0, _useEventCallback.default)(itemId => {
|
|
214
|
+
return instance.fetchItemChildren({
|
|
215
|
+
itemId,
|
|
216
|
+
forceRefresh: true
|
|
217
|
+
});
|
|
218
|
+
});
|
|
216
219
|
(0, _internals.useInstanceEventHandler)(instance, 'beforeItemToggleExpansion', async eventParameters => {
|
|
217
220
|
if (!isLazyLoadingEnabled || !eventParameters.shouldBeExpanded) {
|
|
218
221
|
return;
|
|
@@ -221,14 +224,14 @@ const useTreeViewLazyLoading = ({
|
|
|
221
224
|
|
|
222
225
|
eventParameters.isExpansionPrevented = true;
|
|
223
226
|
await instance.fetchItems([eventParameters.itemId]);
|
|
224
|
-
const
|
|
225
|
-
if (!
|
|
227
|
+
const itemHasError = _internals.lazyLoadingSelectors.itemHasError(store.state, eventParameters.itemId);
|
|
228
|
+
if (!itemHasError) {
|
|
226
229
|
instance.applyItemExpansion({
|
|
227
230
|
itemId: eventParameters.itemId,
|
|
228
231
|
shouldBeExpanded: true,
|
|
229
232
|
event: eventParameters.event
|
|
230
233
|
});
|
|
231
|
-
if (
|
|
234
|
+
if (_internals.selectionSelectors.isItemSelected(store.state, eventParameters.itemId)) {
|
|
232
235
|
// make sure selection propagation works correctly
|
|
233
236
|
instance.setItemSelection({
|
|
234
237
|
event: eventParameters.event,
|
|
@@ -241,10 +244,8 @@ const useTreeViewLazyLoading = ({
|
|
|
241
244
|
});
|
|
242
245
|
React.useEffect(() => {
|
|
243
246
|
if (isLazyLoadingEnabled && firstRenderRef.current) {
|
|
244
|
-
store.
|
|
245
|
-
|
|
246
|
-
enabled: true
|
|
247
|
-
})
|
|
247
|
+
store.set('lazyLoading', (0, _extends2.default)({}, store.state.lazyLoading, {
|
|
248
|
+
enabled: true
|
|
248
249
|
}));
|
|
249
250
|
if (params.items.length) {
|
|
250
251
|
const getChildrenCount = params.dataSource?.getChildrenCount || (() => 0);
|
|
@@ -254,7 +255,7 @@ const useTreeViewLazyLoading = ({
|
|
|
254
255
|
getChildrenCount
|
|
255
256
|
});
|
|
256
257
|
} else {
|
|
257
|
-
const expandedItems =
|
|
258
|
+
const expandedItems = _internals.expansionSelectors.expandedItemsRaw(store.state);
|
|
258
259
|
if (expandedItems.length > 0) {
|
|
259
260
|
instance.resetItemExpansion();
|
|
260
261
|
}
|
|
@@ -270,10 +271,13 @@ const useTreeViewLazyLoading = ({
|
|
|
270
271
|
instance: {
|
|
271
272
|
fetchItemChildren,
|
|
272
273
|
fetchItems,
|
|
274
|
+
updateItemChildren,
|
|
273
275
|
setDataSourceLoading,
|
|
274
276
|
setDataSourceError
|
|
275
277
|
},
|
|
276
|
-
publicAPI: {
|
|
278
|
+
publicAPI: {
|
|
279
|
+
updateItemChildren
|
|
280
|
+
}
|
|
277
281
|
};
|
|
278
282
|
};
|
|
279
283
|
exports.useTreeViewLazyLoading = useTreeViewLazyLoading;
|
|
@@ -45,7 +45,9 @@ class NestedDataManager {
|
|
|
45
45
|
const id = fetchQueue[i];
|
|
46
46
|
this.queuedRequests.delete(id);
|
|
47
47
|
this.pendingRequests.add(id);
|
|
48
|
-
fetchPromises.push(this.instance.fetchItemChildren(
|
|
48
|
+
fetchPromises.push(this.instance.fetchItemChildren({
|
|
49
|
+
itemId: id
|
|
50
|
+
}));
|
|
49
51
|
}
|
|
50
52
|
await Promise.all(fetchPromises);
|
|
51
53
|
};
|
package/package.json
CHANGED
|
@@ -1,9 +1,8 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@mui/x-tree-view-pro",
|
|
3
|
-
"version": "8.11.
|
|
3
|
+
"version": "8.11.2",
|
|
4
4
|
"author": "MUI Team",
|
|
5
5
|
"description": "The Pro plan edition of the MUI X Tree View components.",
|
|
6
|
-
"main": "./index.js",
|
|
7
6
|
"license": "SEE LICENSE IN LICENSE",
|
|
8
7
|
"bugs": {
|
|
9
8
|
"url": "https://github.com/mui/mui-x/issues"
|
|
@@ -33,16 +32,17 @@
|
|
|
33
32
|
},
|
|
34
33
|
"dependencies": {
|
|
35
34
|
"@babel/runtime": "^7.28.2",
|
|
36
|
-
"@
|
|
35
|
+
"@base-ui-components/utils": "0.1.1",
|
|
36
|
+
"@mui/utils": "^7.3.2",
|
|
37
37
|
"@types/react-transition-group": "^4.4.12",
|
|
38
38
|
"clsx": "^2.1.1",
|
|
39
39
|
"prop-types": "^15.8.1",
|
|
40
40
|
"react-transition-group": "^4.4.5",
|
|
41
41
|
"reselect": "^5.1.1",
|
|
42
42
|
"use-sync-external-store": "^1.5.0",
|
|
43
|
-
"@mui/x-
|
|
44
|
-
"@mui/x-
|
|
45
|
-
"@mui/x-
|
|
43
|
+
"@mui/x-license": "8.11.2",
|
|
44
|
+
"@mui/x-tree-view": "8.11.2",
|
|
45
|
+
"@mui/x-internals": "8.11.2"
|
|
46
46
|
},
|
|
47
47
|
"peerDependencies": {
|
|
48
48
|
"@emotion/react": "^11.9.0",
|
|
@@ -64,27 +64,28 @@
|
|
|
64
64
|
"node": ">=14.0.0"
|
|
65
65
|
},
|
|
66
66
|
"type": "commonjs",
|
|
67
|
+
"main": "./index.js",
|
|
67
68
|
"types": "./index.d.ts",
|
|
68
69
|
"exports": {
|
|
69
70
|
"./package.json": "./package.json",
|
|
70
71
|
".": {
|
|
71
|
-
"import": {
|
|
72
|
-
"types": "./esm/index.d.ts",
|
|
73
|
-
"default": "./esm/index.js"
|
|
74
|
-
},
|
|
75
72
|
"require": {
|
|
76
73
|
"types": "./index.d.ts",
|
|
77
74
|
"default": "./index.js"
|
|
75
|
+
},
|
|
76
|
+
"default": {
|
|
77
|
+
"types": "./esm/index.d.ts",
|
|
78
|
+
"default": "./esm/index.js"
|
|
78
79
|
}
|
|
79
80
|
},
|
|
80
81
|
"./*": {
|
|
81
|
-
"import": {
|
|
82
|
-
"types": "./esm/*/index.d.ts",
|
|
83
|
-
"default": "./esm/*/index.js"
|
|
84
|
-
},
|
|
85
82
|
"require": {
|
|
86
83
|
"types": "./*/index.d.ts",
|
|
87
84
|
"default": "./*/index.js"
|
|
85
|
+
},
|
|
86
|
+
"default": {
|
|
87
|
+
"types": "./esm/*/index.d.ts",
|
|
88
|
+
"default": "./esm/*/index.js"
|
|
88
89
|
}
|
|
89
90
|
},
|
|
90
91
|
"./esm": null
|