@mui/x-tree-view-pro 8.0.0-alpha.13 → 8.0.0-alpha.14
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 +131 -0
- package/RichTreeViewPro/RichTreeViewPro.js +19 -6
- package/RichTreeViewPro/RichTreeViewPro.plugins.d.ts +3 -3
- package/RichTreeViewPro/RichTreeViewPro.plugins.js +2 -1
- package/esm/RichTreeViewPro/RichTreeViewPro.js +19 -6
- package/esm/RichTreeViewPro/RichTreeViewPro.plugins.d.ts +3 -3
- package/esm/RichTreeViewPro/RichTreeViewPro.plugins.js +2 -1
- package/esm/index.js +1 -1
- package/esm/internals/plugins/useTreeViewItemsReordering/useTreeViewItemsReordering.selectors.d.ts +4 -0
- package/esm/internals/plugins/useTreeViewLazyLoading/index.d.ts +1 -0
- package/esm/internals/plugins/useTreeViewLazyLoading/index.js +1 -0
- package/esm/internals/plugins/useTreeViewLazyLoading/useTreeViewLazyLoading.d.ts +3 -0
- package/esm/internals/plugins/useTreeViewLazyLoading/useTreeViewLazyLoading.js +288 -0
- package/esm/internals/plugins/useTreeViewLazyLoading/utils.d.ts +32 -0
- package/esm/internals/plugins/useTreeViewLazyLoading/utils.js +85 -0
- package/esm/internals/utils/releaseInfo.js +1 -1
- package/index.js +1 -1
- package/internals/plugins/useTreeViewItemsReordering/useTreeViewItemsReordering.selectors.d.ts +4 -0
- package/internals/plugins/useTreeViewLazyLoading/index.d.ts +1 -0
- package/internals/plugins/useTreeViewLazyLoading/index.js +12 -0
- package/internals/plugins/useTreeViewLazyLoading/useTreeViewLazyLoading.d.ts +3 -0
- package/internals/plugins/useTreeViewLazyLoading/useTreeViewLazyLoading.js +297 -0
- package/internals/plugins/useTreeViewLazyLoading/utils.d.ts +32 -0
- package/internals/plugins/useTreeViewLazyLoading/utils.js +89 -0
- package/internals/utils/releaseInfo.js +1 -1
- package/modern/RichTreeViewPro/RichTreeViewPro.js +19 -6
- package/modern/RichTreeViewPro/RichTreeViewPro.plugins.d.ts +3 -3
- package/modern/RichTreeViewPro/RichTreeViewPro.plugins.js +2 -1
- package/modern/index.js +1 -1
- package/modern/internals/plugins/useTreeViewItemsReordering/useTreeViewItemsReordering.selectors.d.ts +4 -0
- package/modern/internals/plugins/useTreeViewLazyLoading/index.d.ts +1 -0
- package/modern/internals/plugins/useTreeViewLazyLoading/index.js +1 -0
- package/modern/internals/plugins/useTreeViewLazyLoading/useTreeViewLazyLoading.d.ts +3 -0
- package/modern/internals/plugins/useTreeViewLazyLoading/useTreeViewLazyLoading.js +288 -0
- package/modern/internals/plugins/useTreeViewLazyLoading/utils.d.ts +32 -0
- package/modern/internals/plugins/useTreeViewLazyLoading/utils.js +85 -0
- package/modern/internals/utils/releaseInfo.js +1 -1
- package/package.json +3 -3
- package/tsconfig.build.tsbuildinfo +1 -1
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import { UseTreeViewItemsParameters, UseTreeViewExpansionParameters, UseTreeViewSelectionParameters, UseTreeViewFocusParameters, UseTreeViewIconsParameters, ConvertPluginsIntoSignatures, MergeSignaturesProperty, TreeViewCorePluginParameters, UseTreeViewLabelParameters } from '@mui/x-tree-view/internals';
|
|
1
|
+
import { UseTreeViewItemsParameters, UseTreeViewExpansionParameters, UseTreeViewSelectionParameters, UseTreeViewFocusParameters, UseTreeViewIconsParameters, ConvertPluginsIntoSignatures, MergeSignaturesProperty, TreeViewCorePluginParameters, UseTreeViewLabelParameters, UseTreeViewLazyLoadingParameters } from '@mui/x-tree-view/internals';
|
|
2
2
|
import { UseTreeViewItemsReorderingParameters } from "../internals/plugins/useTreeViewItemsReordering/index.js";
|
|
3
|
-
export declare const RICH_TREE_VIEW_PRO_PLUGINS: readonly [import("@mui/x-tree-view/internals").TreeViewPlugin<import("@mui/x-tree-view/internals").UseTreeViewItemsSignature>, import("@mui/x-tree-view/internals").TreeViewPlugin<import("@mui/x-tree-view/internals").UseTreeViewExpansionSignature>, import("@mui/x-tree-view/internals").TreeViewPlugin<import("@mui/x-tree-view/internals").UseTreeViewSelectionSignature>, import("@mui/x-tree-view/internals").TreeViewPlugin<import("@mui/x-tree-view/internals").UseTreeViewFocusSignature>, import("@mui/x-tree-view/internals").TreeViewPlugin<import("@mui/x-tree-view/internals").UseTreeViewKeyboardNavigationSignature>, import("@mui/x-tree-view/internals").TreeViewPlugin<import("@mui/x-tree-view/internals").UseTreeViewIconsSignature>, import("@mui/x-tree-view/internals").TreeViewPlugin<import("@mui/x-tree-view/internals").UseTreeViewLabelSignature>, import("@mui/x-tree-view/internals").TreeViewPlugin<import("../internals").UseTreeViewItemsReorderingSignature>];
|
|
3
|
+
export declare const RICH_TREE_VIEW_PRO_PLUGINS: readonly [import("@mui/x-tree-view/internals").TreeViewPlugin<import("@mui/x-tree-view/internals").UseTreeViewItemsSignature>, import("@mui/x-tree-view/internals").TreeViewPlugin<import("@mui/x-tree-view/internals").UseTreeViewExpansionSignature>, import("@mui/x-tree-view/internals").TreeViewPlugin<import("@mui/x-tree-view/internals").UseTreeViewSelectionSignature>, import("@mui/x-tree-view/internals").TreeViewPlugin<import("@mui/x-tree-view/internals").UseTreeViewFocusSignature>, import("@mui/x-tree-view/internals").TreeViewPlugin<import("@mui/x-tree-view/internals").UseTreeViewKeyboardNavigationSignature>, import("@mui/x-tree-view/internals").TreeViewPlugin<import("@mui/x-tree-view/internals").UseTreeViewIconsSignature>, import("@mui/x-tree-view/internals").TreeViewPlugin<import("@mui/x-tree-view/internals").UseTreeViewLabelSignature>, import("@mui/x-tree-view/internals").TreeViewPlugin<import("@mui/x-tree-view/internals").UseTreeViewLazyLoadingSignature>, import("@mui/x-tree-view/internals").TreeViewPlugin<import("../internals").UseTreeViewItemsReorderingSignature>];
|
|
4
4
|
export type RichTreeViewProPluginSignatures = ConvertPluginsIntoSignatures<typeof RICH_TREE_VIEW_PRO_PLUGINS>;
|
|
5
5
|
export type RichTreeViewProPluginSlots = MergeSignaturesProperty<RichTreeViewProPluginSignatures, 'slots'>;
|
|
6
6
|
export type RichTreeViewProPluginSlotProps = MergeSignaturesProperty<RichTreeViewProPluginSignatures, 'slotProps'>;
|
|
7
|
-
export interface RichTreeViewProPluginParameters<R extends {}, Multiple extends boolean | undefined> extends TreeViewCorePluginParameters, UseTreeViewItemsParameters<R>, UseTreeViewExpansionParameters, UseTreeViewFocusParameters, UseTreeViewSelectionParameters<Multiple>, UseTreeViewIconsParameters, UseTreeViewLabelParameters<R>, UseTreeViewItemsReorderingParameters {}
|
|
7
|
+
export interface RichTreeViewProPluginParameters<R extends {}, Multiple extends boolean | undefined> extends TreeViewCorePluginParameters, UseTreeViewItemsParameters<R>, UseTreeViewExpansionParameters, UseTreeViewFocusParameters, UseTreeViewSelectionParameters<Multiple>, UseTreeViewIconsParameters, UseTreeViewLabelParameters<R>, UseTreeViewLazyLoadingParameters<R>, UseTreeViewItemsReorderingParameters {}
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { useTreeViewItems, useTreeViewExpansion, useTreeViewSelection, useTreeViewFocus, useTreeViewKeyboardNavigation, useTreeViewIcons, useTreeViewLabel } from '@mui/x-tree-view/internals';
|
|
2
2
|
import { useTreeViewItemsReordering } from "../internals/plugins/useTreeViewItemsReordering/index.js";
|
|
3
|
-
|
|
3
|
+
import { useTreeViewLazyLoading } from "../internals/plugins/useTreeViewLazyLoading/index.js";
|
|
4
|
+
export const RICH_TREE_VIEW_PRO_PLUGINS = [useTreeViewItems, useTreeViewExpansion, useTreeViewSelection, useTreeViewFocus, useTreeViewKeyboardNavigation, useTreeViewIcons, useTreeViewLabel, useTreeViewLazyLoading, useTreeViewItemsReordering];
|
|
4
5
|
|
|
5
6
|
// We can't infer this type from the plugin, otherwise we would lose the generics.
|
package/modern/index.js
CHANGED
|
@@ -89,6 +89,8 @@ export declare const selectorItemsReorderingDraggedItemProperties: ((state: any,
|
|
|
89
89
|
[itemId: string]: number;
|
|
90
90
|
};
|
|
91
91
|
};
|
|
92
|
+
loading: boolean;
|
|
93
|
+
error: Error | null;
|
|
92
94
|
}) => {
|
|
93
95
|
[itemId: string]: import("@mui/x-tree-view/internals").TreeViewItemMeta;
|
|
94
96
|
};
|
|
@@ -108,6 +110,8 @@ export declare const selectorItemsReorderingDraggedItemProperties: ((state: any,
|
|
|
108
110
|
[itemId: string]: number;
|
|
109
111
|
};
|
|
110
112
|
};
|
|
113
|
+
loading: boolean;
|
|
114
|
+
error: Error | null;
|
|
111
115
|
}) => {
|
|
112
116
|
[itemId: string]: import("@mui/x-tree-view/internals").TreeViewItemMeta;
|
|
113
117
|
}) & {
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { useTreeViewLazyLoading } from "./useTreeViewLazyLoading.js";
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { useTreeViewLazyLoading } from "./useTreeViewLazyLoading.js";
|
|
@@ -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
|
+
}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import ponyfillGlobal from '@mui/utils/ponyfillGlobal';
|
|
2
2
|
export const getReleaseInfo = () => {
|
|
3
|
-
const releaseInfo = "
|
|
3
|
+
const releaseInfo = "MTc0MTMwMjAwMDAwMA==";
|
|
4
4
|
if (process.env.NODE_ENV !== 'production') {
|
|
5
5
|
// A simple hack to set the value in the test environment (has no build step).
|
|
6
6
|
// eslint-disable-next-line no-useless-concat
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@mui/x-tree-view-pro",
|
|
3
|
-
"version": "8.0.0-alpha.
|
|
3
|
+
"version": "8.0.0-alpha.14",
|
|
4
4
|
"description": "The Pro plan edition of the Tree View components (MUI X).",
|
|
5
5
|
"author": "MUI Team",
|
|
6
6
|
"main": "./index.js",
|
|
@@ -42,8 +42,8 @@
|
|
|
42
42
|
"reselect": "^5.1.1",
|
|
43
43
|
"use-sync-external-store": "^1.4.0",
|
|
44
44
|
"@mui/x-internals": "8.0.0-alpha.13",
|
|
45
|
-
"@mui/x-
|
|
46
|
-
"@mui/x-
|
|
45
|
+
"@mui/x-license": "8.0.0-alpha.14",
|
|
46
|
+
"@mui/x-tree-view": "8.0.0-alpha.14"
|
|
47
47
|
},
|
|
48
48
|
"peerDependencies": {
|
|
49
49
|
"@emotion/react": "^11.9.0",
|