@mui/x-tree-view 7.9.0 → 7.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.
- package/CHANGELOG.md +159 -0
- package/RichTreeView/RichTreeView.js +2 -0
- package/SimpleTreeView/SimpleTreeView.js +2 -0
- package/TreeItem2/TreeItem2.d.ts +1 -1
- package/TreeView/TreeView.js +2 -0
- package/index.js +1 -1
- package/internals/corePlugins/corePlugins.d.ts +1 -1
- package/internals/corePlugins/corePlugins.js +2 -1
- package/internals/corePlugins/useTreeViewInstanceEvents/useTreeViewInstanceEvents.js +1 -1
- package/internals/corePlugins/useTreeViewOptionalPlugins/index.d.ts +2 -0
- package/internals/corePlugins/useTreeViewOptionalPlugins/index.js +1 -0
- package/internals/corePlugins/useTreeViewOptionalPlugins/useTreeViewOptionalPlugins.d.ts +3 -0
- package/internals/corePlugins/useTreeViewOptionalPlugins/useTreeViewOptionalPlugins.js +12 -0
- package/internals/corePlugins/useTreeViewOptionalPlugins/useTreeViewOptionalPlugins.types.d.ts +8 -0
- package/internals/corePlugins/useTreeViewOptionalPlugins/useTreeViewOptionalPlugins.types.js +1 -0
- package/internals/models/plugin.d.ts +1 -0
- package/internals/plugins/useTreeViewItems/useTreeViewItems.js +19 -3
- package/internals/plugins/useTreeViewItems/useTreeViewItems.types.d.ts +13 -8
- package/internals/useTreeView/useTreeView.js +9 -63
- package/internals/useTreeView/useTreeViewBuildContext.d.ts +10 -0
- package/internals/useTreeView/useTreeViewBuildContext.js +73 -0
- package/internals/useTreeView/useTreeViewPlugins.d.ts +0 -0
- package/internals/useTreeView/useTreeViewPlugins.js +0 -0
- package/internals/utils/plugins.d.ts +2 -0
- package/internals/utils/plugins.js +4 -0
- package/modern/RichTreeView/RichTreeView.js +2 -0
- package/modern/SimpleTreeView/SimpleTreeView.js +2 -0
- package/modern/TreeView/TreeView.js +2 -0
- package/modern/index.js +1 -1
- package/modern/internals/corePlugins/corePlugins.js +2 -1
- package/modern/internals/corePlugins/useTreeViewInstanceEvents/useTreeViewInstanceEvents.js +1 -1
- package/modern/internals/corePlugins/useTreeViewOptionalPlugins/index.js +1 -0
- package/modern/internals/corePlugins/useTreeViewOptionalPlugins/useTreeViewOptionalPlugins.js +12 -0
- package/modern/internals/corePlugins/useTreeViewOptionalPlugins/useTreeViewOptionalPlugins.types.js +1 -0
- package/modern/internals/plugins/useTreeViewItems/useTreeViewItems.js +19 -3
- package/modern/internals/useTreeView/useTreeView.js +9 -63
- package/modern/internals/useTreeView/useTreeViewBuildContext.js +73 -0
- package/modern/internals/useTreeView/useTreeViewPlugins.js +0 -0
- package/modern/internals/utils/plugins.js +4 -0
- package/node/RichTreeView/RichTreeView.js +2 -0
- package/node/SimpleTreeView/SimpleTreeView.js +2 -0
- package/node/TreeView/TreeView.js +2 -0
- package/node/index.js +1 -1
- package/node/internals/corePlugins/corePlugins.js +2 -1
- package/node/internals/corePlugins/useTreeViewInstanceEvents/useTreeViewInstanceEvents.js +1 -1
- package/node/internals/corePlugins/useTreeViewOptionalPlugins/index.js +12 -0
- package/node/internals/corePlugins/useTreeViewOptionalPlugins/useTreeViewOptionalPlugins.js +19 -0
- package/node/internals/corePlugins/useTreeViewOptionalPlugins/useTreeViewOptionalPlugins.types.js +5 -0
- package/node/internals/plugins/useTreeViewItems/useTreeViewItems.js +19 -3
- package/node/internals/useTreeView/useTreeView.js +9 -63
- package/node/internals/useTreeView/useTreeViewBuildContext.js +80 -0
- package/node/internals/useTreeView/useTreeViewPlugins.js +1 -0
- package/node/internals/utils/plugins.js +11 -0
- package/package.json +6 -5
- package/internals/utils/EventManager.d.ts +0 -29
- package/internals/utils/EventManager.js +0 -69
- package/modern/internals/utils/EventManager.js +0 -69
- package/node/internals/utils/EventManager.js +0 -76
package/modern/index.js
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
import { useTreeViewInstanceEvents } from './useTreeViewInstanceEvents';
|
|
2
|
+
import { useTreeViewOptionalPlugins } from './useTreeViewOptionalPlugins';
|
|
2
3
|
import { useTreeViewId } from './useTreeViewId';
|
|
3
4
|
/**
|
|
4
5
|
* Internal plugins that create the tools used by the other plugins.
|
|
5
6
|
* These plugins are used by the tree view components.
|
|
6
7
|
*/
|
|
7
|
-
export const TREE_VIEW_CORE_PLUGINS = [useTreeViewInstanceEvents, useTreeViewId];
|
|
8
|
+
export const TREE_VIEW_CORE_PLUGINS = [useTreeViewInstanceEvents, useTreeViewOptionalPlugins, useTreeViewId];
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { useTreeViewOptionalPlugins } from './useTreeViewOptionalPlugins';
|
package/modern/internals/corePlugins/useTreeViewOptionalPlugins/useTreeViewOptionalPlugins.types.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -1,4 +1,6 @@
|
|
|
1
1
|
import _extends from "@babel/runtime/helpers/esm/extends";
|
|
2
|
+
import _objectWithoutPropertiesLoose from "@babel/runtime/helpers/esm/objectWithoutPropertiesLoose";
|
|
3
|
+
const _excluded = ["children"];
|
|
2
4
|
import * as React from 'react';
|
|
3
5
|
import { publishTreeViewEvent } from '../../utils/publishTreeViewEvent';
|
|
4
6
|
import { buildSiblingIndexes, TREE_VIEW_ROOT_PARENT_ID } from './useTreeViewItems.utils';
|
|
@@ -37,7 +39,6 @@ const updateItemsState = ({
|
|
|
37
39
|
depth
|
|
38
40
|
};
|
|
39
41
|
itemMap[id] = item;
|
|
40
|
-
itemOrderedChildrenIds[id] = [];
|
|
41
42
|
const parentIdWithDefault = parentId ?? TREE_VIEW_ROOT_PARENT_ID;
|
|
42
43
|
if (!itemOrderedChildrenIds[parentIdWithDefault]) {
|
|
43
44
|
itemOrderedChildrenIds[parentIdWithDefault] = [];
|
|
@@ -66,6 +67,18 @@ export const useTreeViewItems = ({
|
|
|
66
67
|
}) => {
|
|
67
68
|
const getItemMeta = React.useCallback(itemId => state.items.itemMetaMap[itemId], [state.items.itemMetaMap]);
|
|
68
69
|
const getItem = React.useCallback(itemId => state.items.itemMap[itemId], [state.items.itemMap]);
|
|
70
|
+
const getItemTree = React.useCallback(() => {
|
|
71
|
+
const getItemFromItemId = id => {
|
|
72
|
+
const _state$items$itemMap$ = state.items.itemMap[id],
|
|
73
|
+
item = _objectWithoutPropertiesLoose(_state$items$itemMap$, _excluded);
|
|
74
|
+
const newChildren = state.items.itemOrderedChildrenIds[id];
|
|
75
|
+
if (newChildren) {
|
|
76
|
+
item.children = newChildren.map(getItemFromItemId);
|
|
77
|
+
}
|
|
78
|
+
return item;
|
|
79
|
+
};
|
|
80
|
+
return state.items.itemOrderedChildrenIds[TREE_VIEW_ROOT_PARENT_ID].map(getItemFromItemId);
|
|
81
|
+
}, [state.items.itemMap, state.items.itemOrderedChildrenIds]);
|
|
69
82
|
const isItemDisabled = React.useCallback(itemId => {
|
|
70
83
|
if (itemId == null) {
|
|
71
84
|
return false;
|
|
@@ -140,7 +153,7 @@ export const useTreeViewItems = ({
|
|
|
140
153
|
label: item.label,
|
|
141
154
|
itemId: item.id,
|
|
142
155
|
id: item.idAttribute,
|
|
143
|
-
children: state.items.itemOrderedChildrenIds[id]
|
|
156
|
+
children: state.items.itemOrderedChildrenIds[id]?.map(getPropsFromItemId)
|
|
144
157
|
};
|
|
145
158
|
};
|
|
146
159
|
return state.items.itemOrderedChildrenIds[TREE_VIEW_ROOT_PARENT_ID].map(getPropsFromItemId);
|
|
@@ -153,11 +166,14 @@ export const useTreeViewItems = ({
|
|
|
153
166
|
}),
|
|
154
167
|
publicAPI: {
|
|
155
168
|
getItem,
|
|
156
|
-
getItemDOMElement
|
|
169
|
+
getItemDOMElement,
|
|
170
|
+
getItemTree,
|
|
171
|
+
getItemOrderedChildrenIds
|
|
157
172
|
},
|
|
158
173
|
instance: {
|
|
159
174
|
getItemMeta,
|
|
160
175
|
getItem,
|
|
176
|
+
getItemTree,
|
|
161
177
|
getItemsToRender,
|
|
162
178
|
getItemIndex,
|
|
163
179
|
getItemDOMElement,
|
|
@@ -4,6 +4,7 @@ import useForkRef from '@mui/utils/useForkRef';
|
|
|
4
4
|
import { useTreeViewModels } from './useTreeViewModels';
|
|
5
5
|
import { TREE_VIEW_CORE_PLUGINS } from '../corePlugins';
|
|
6
6
|
import { extractPluginParamsFromProps } from './extractPluginParamsFromProps';
|
|
7
|
+
import { useTreeViewBuildContext } from './useTreeViewBuildContext';
|
|
7
8
|
export function useTreeViewApiInitialization(inputApiRef) {
|
|
8
9
|
const fallbackPublicApiRef = React.useRef({});
|
|
9
10
|
if (inputApiRef) {
|
|
@@ -37,6 +38,12 @@ export const useTreeView = ({
|
|
|
37
38
|
const publicAPI = useTreeViewApiInitialization(apiRef);
|
|
38
39
|
const innerRootRef = React.useRef(null);
|
|
39
40
|
const handleRootRef = useForkRef(innerRootRef, rootRef);
|
|
41
|
+
const contextValue = useTreeViewBuildContext({
|
|
42
|
+
plugins,
|
|
43
|
+
instance,
|
|
44
|
+
publicAPI,
|
|
45
|
+
rootRef: innerRootRef
|
|
46
|
+
});
|
|
40
47
|
const [state, setState] = React.useState(() => {
|
|
41
48
|
const temp = {};
|
|
42
49
|
plugins.forEach(plugin => {
|
|
@@ -46,68 +53,6 @@ export const useTreeView = ({
|
|
|
46
53
|
});
|
|
47
54
|
return temp;
|
|
48
55
|
});
|
|
49
|
-
const itemWrappers = plugins.map(plugin => plugin.wrapItem).filter(wrapItem => !!wrapItem);
|
|
50
|
-
const wrapItem = ({
|
|
51
|
-
itemId,
|
|
52
|
-
children
|
|
53
|
-
}) => {
|
|
54
|
-
let finalChildren = children;
|
|
55
|
-
itemWrappers.forEach(itemWrapper => {
|
|
56
|
-
finalChildren = itemWrapper({
|
|
57
|
-
itemId,
|
|
58
|
-
children: finalChildren,
|
|
59
|
-
instance
|
|
60
|
-
});
|
|
61
|
-
});
|
|
62
|
-
return finalChildren;
|
|
63
|
-
};
|
|
64
|
-
const rootWrappers = plugins.map(plugin => plugin.wrapRoot).filter(wrapRoot => !!wrapRoot)
|
|
65
|
-
// The wrappers are reversed to ensure that the first wrapper is the outermost one.
|
|
66
|
-
.reverse();
|
|
67
|
-
const wrapRoot = ({
|
|
68
|
-
children
|
|
69
|
-
}) => {
|
|
70
|
-
let finalChildren = children;
|
|
71
|
-
rootWrappers.forEach(rootWrapper => {
|
|
72
|
-
finalChildren = rootWrapper({
|
|
73
|
-
children: finalChildren,
|
|
74
|
-
instance
|
|
75
|
-
});
|
|
76
|
-
});
|
|
77
|
-
return finalChildren;
|
|
78
|
-
};
|
|
79
|
-
const runItemPlugins = itemPluginProps => {
|
|
80
|
-
let finalRootRef = null;
|
|
81
|
-
let finalContentRef = null;
|
|
82
|
-
plugins.forEach(plugin => {
|
|
83
|
-
if (!plugin.itemPlugin) {
|
|
84
|
-
return;
|
|
85
|
-
}
|
|
86
|
-
const itemPluginResponse = plugin.itemPlugin({
|
|
87
|
-
props: itemPluginProps,
|
|
88
|
-
rootRef: finalRootRef,
|
|
89
|
-
contentRef: finalContentRef
|
|
90
|
-
});
|
|
91
|
-
if (itemPluginResponse?.rootRef) {
|
|
92
|
-
finalRootRef = itemPluginResponse.rootRef;
|
|
93
|
-
}
|
|
94
|
-
if (itemPluginResponse?.contentRef) {
|
|
95
|
-
finalContentRef = itemPluginResponse.contentRef;
|
|
96
|
-
}
|
|
97
|
-
});
|
|
98
|
-
return {
|
|
99
|
-
contentRef: finalContentRef,
|
|
100
|
-
rootRef: finalRootRef
|
|
101
|
-
};
|
|
102
|
-
};
|
|
103
|
-
const contextValue = {
|
|
104
|
-
publicAPI,
|
|
105
|
-
wrapItem,
|
|
106
|
-
wrapRoot,
|
|
107
|
-
runItemPlugins,
|
|
108
|
-
instance: instance,
|
|
109
|
-
rootRef: innerRootRef
|
|
110
|
-
};
|
|
111
56
|
const rootPropsGetters = [];
|
|
112
57
|
const runPlugin = plugin => {
|
|
113
58
|
const pluginResponse = plugin({
|
|
@@ -119,7 +64,8 @@ export const useTreeView = ({
|
|
|
119
64
|
state,
|
|
120
65
|
setState,
|
|
121
66
|
rootRef: innerRootRef,
|
|
122
|
-
models
|
|
67
|
+
models,
|
|
68
|
+
plugins
|
|
123
69
|
});
|
|
124
70
|
if (pluginResponse.getRootProps) {
|
|
125
71
|
rootPropsGetters.push(pluginResponse.getRootProps);
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
export const useTreeViewBuildContext = ({
|
|
2
|
+
plugins,
|
|
3
|
+
instance,
|
|
4
|
+
publicAPI,
|
|
5
|
+
rootRef
|
|
6
|
+
}) => {
|
|
7
|
+
const runItemPlugins = itemPluginProps => {
|
|
8
|
+
let finalRootRef = null;
|
|
9
|
+
let finalContentRef = null;
|
|
10
|
+
plugins.forEach(plugin => {
|
|
11
|
+
if (!plugin.itemPlugin) {
|
|
12
|
+
return;
|
|
13
|
+
}
|
|
14
|
+
const itemPluginResponse = plugin.itemPlugin({
|
|
15
|
+
props: itemPluginProps,
|
|
16
|
+
rootRef: finalRootRef,
|
|
17
|
+
contentRef: finalContentRef
|
|
18
|
+
});
|
|
19
|
+
if (itemPluginResponse?.rootRef) {
|
|
20
|
+
finalRootRef = itemPluginResponse.rootRef;
|
|
21
|
+
}
|
|
22
|
+
if (itemPluginResponse?.contentRef) {
|
|
23
|
+
finalContentRef = itemPluginResponse.contentRef;
|
|
24
|
+
}
|
|
25
|
+
});
|
|
26
|
+
return {
|
|
27
|
+
contentRef: finalContentRef,
|
|
28
|
+
rootRef: finalRootRef
|
|
29
|
+
};
|
|
30
|
+
};
|
|
31
|
+
const wrapItem = ({
|
|
32
|
+
itemId,
|
|
33
|
+
children
|
|
34
|
+
}) => {
|
|
35
|
+
let finalChildren = children;
|
|
36
|
+
// The wrappers are reversed to ensure that the first wrapper is the outermost one.
|
|
37
|
+
for (let i = plugins.length - 1; i >= 0; i -= 1) {
|
|
38
|
+
const plugin = plugins[i];
|
|
39
|
+
if (plugin.wrapItem) {
|
|
40
|
+
finalChildren = plugin.wrapItem({
|
|
41
|
+
itemId,
|
|
42
|
+
children: finalChildren,
|
|
43
|
+
instance
|
|
44
|
+
});
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
return finalChildren;
|
|
48
|
+
};
|
|
49
|
+
const wrapRoot = ({
|
|
50
|
+
children
|
|
51
|
+
}) => {
|
|
52
|
+
let finalChildren = children;
|
|
53
|
+
// The wrappers are reversed to ensure that the first wrapper is the outermost one.
|
|
54
|
+
for (let i = plugins.length - 1; i >= 0; i -= 1) {
|
|
55
|
+
const plugin = plugins[i];
|
|
56
|
+
if (plugin.wrapRoot) {
|
|
57
|
+
finalChildren = plugin.wrapRoot({
|
|
58
|
+
children: finalChildren,
|
|
59
|
+
instance
|
|
60
|
+
});
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
return finalChildren;
|
|
64
|
+
};
|
|
65
|
+
return {
|
|
66
|
+
runItemPlugins,
|
|
67
|
+
wrapItem,
|
|
68
|
+
wrapRoot,
|
|
69
|
+
instance,
|
|
70
|
+
rootRef,
|
|
71
|
+
publicAPI
|
|
72
|
+
};
|
|
73
|
+
};
|
|
File without changes
|
|
@@ -147,6 +147,8 @@ process.env.NODE_ENV !== "production" ? RichTreeView.propTypes = {
|
|
|
147
147
|
focusItem: _propTypes.default.func.isRequired,
|
|
148
148
|
getItem: _propTypes.default.func.isRequired,
|
|
149
149
|
getItemDOMElement: _propTypes.default.func.isRequired,
|
|
150
|
+
getItemOrderedChildrenIds: _propTypes.default.func.isRequired,
|
|
151
|
+
getItemTree: _propTypes.default.func.isRequired,
|
|
150
152
|
selectItem: _propTypes.default.func.isRequired,
|
|
151
153
|
setItemExpansion: _propTypes.default.func.isRequired
|
|
152
154
|
})
|
|
@@ -105,6 +105,8 @@ process.env.NODE_ENV !== "production" ? SimpleTreeView.propTypes = {
|
|
|
105
105
|
focusItem: _propTypes.default.func.isRequired,
|
|
106
106
|
getItem: _propTypes.default.func.isRequired,
|
|
107
107
|
getItemDOMElement: _propTypes.default.func.isRequired,
|
|
108
|
+
getItemOrderedChildrenIds: _propTypes.default.func.isRequired,
|
|
109
|
+
getItemTree: _propTypes.default.func.isRequired,
|
|
108
110
|
selectItem: _propTypes.default.func.isRequired,
|
|
109
111
|
setItemExpansion: _propTypes.default.func.isRequired
|
|
110
112
|
})
|
|
@@ -82,6 +82,8 @@ process.env.NODE_ENV !== "production" ? TreeView.propTypes = {
|
|
|
82
82
|
focusItem: _propTypes.default.func.isRequired,
|
|
83
83
|
getItem: _propTypes.default.func.isRequired,
|
|
84
84
|
getItemDOMElement: _propTypes.default.func.isRequired,
|
|
85
|
+
getItemOrderedChildrenIds: _propTypes.default.func.isRequired,
|
|
86
|
+
getItemTree: _propTypes.default.func.isRequired,
|
|
85
87
|
selectItem: _propTypes.default.func.isRequired,
|
|
86
88
|
setItemExpansion: _propTypes.default.func.isRequired
|
|
87
89
|
})
|
package/node/index.js
CHANGED
|
@@ -5,9 +5,10 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
5
5
|
});
|
|
6
6
|
exports.TREE_VIEW_CORE_PLUGINS = void 0;
|
|
7
7
|
var _useTreeViewInstanceEvents = require("./useTreeViewInstanceEvents");
|
|
8
|
+
var _useTreeViewOptionalPlugins = require("./useTreeViewOptionalPlugins");
|
|
8
9
|
var _useTreeViewId = require("./useTreeViewId");
|
|
9
10
|
/**
|
|
10
11
|
* Internal plugins that create the tools used by the other plugins.
|
|
11
12
|
* These plugins are used by the tree view components.
|
|
12
13
|
*/
|
|
13
|
-
const TREE_VIEW_CORE_PLUGINS = exports.TREE_VIEW_CORE_PLUGINS = [_useTreeViewInstanceEvents.useTreeViewInstanceEvents, _useTreeViewId.useTreeViewId];
|
|
14
|
+
const TREE_VIEW_CORE_PLUGINS = exports.TREE_VIEW_CORE_PLUGINS = [_useTreeViewInstanceEvents.useTreeViewInstanceEvents, _useTreeViewOptionalPlugins.useTreeViewOptionalPlugins, _useTreeViewId.useTreeViewId];
|
|
@@ -5,7 +5,7 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
5
5
|
});
|
|
6
6
|
exports.useTreeViewInstanceEvents = void 0;
|
|
7
7
|
var React = _interopRequireWildcard(require("react"));
|
|
8
|
-
var _EventManager = require("
|
|
8
|
+
var _EventManager = require("@mui/x-internals/EventManager");
|
|
9
9
|
function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return null; var r = new WeakMap(), t = new WeakMap(); return (_getRequireWildcardCache = function (e) { return e ? t : r; })(e); }
|
|
10
10
|
function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" != typeof e && "function" != typeof e) return { default: e }; var t = _getRequireWildcardCache(r); if (t && t.has(e)) return t.get(e); var n = { __proto__: null }, a = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var u in e) if ("default" !== u && {}.hasOwnProperty.call(e, u)) { var i = a ? Object.getOwnPropertyDescriptor(e, u) : null; i && (i.get || i.set) ? Object.defineProperty(n, u, i) : n[u] = e[u]; } return n.default = e, t && t.set(e, n), n; }
|
|
11
11
|
const isSyntheticEvent = event => {
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
Object.defineProperty(exports, "useTreeViewOptionalPlugins", {
|
|
7
|
+
enumerable: true,
|
|
8
|
+
get: function () {
|
|
9
|
+
return _useTreeViewOptionalPlugins.useTreeViewOptionalPlugins;
|
|
10
|
+
}
|
|
11
|
+
});
|
|
12
|
+
var _useTreeViewOptionalPlugins = require("./useTreeViewOptionalPlugins");
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.useTreeViewOptionalPlugins = void 0;
|
|
7
|
+
const useTreeViewOptionalPlugins = ({
|
|
8
|
+
plugins
|
|
9
|
+
}) => {
|
|
10
|
+
const pluginSet = new Set(plugins);
|
|
11
|
+
const getAvailablePlugins = () => pluginSet;
|
|
12
|
+
return {
|
|
13
|
+
instance: {
|
|
14
|
+
getAvailablePlugins
|
|
15
|
+
}
|
|
16
|
+
};
|
|
17
|
+
};
|
|
18
|
+
exports.useTreeViewOptionalPlugins = useTreeViewOptionalPlugins;
|
|
19
|
+
useTreeViewOptionalPlugins.params = {};
|
|
@@ -6,11 +6,13 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
6
6
|
});
|
|
7
7
|
exports.useTreeViewItems = void 0;
|
|
8
8
|
var _extends2 = _interopRequireDefault(require("@babel/runtime/helpers/extends"));
|
|
9
|
+
var _objectWithoutPropertiesLoose2 = _interopRequireDefault(require("@babel/runtime/helpers/objectWithoutPropertiesLoose"));
|
|
9
10
|
var React = _interopRequireWildcard(require("react"));
|
|
10
11
|
var _publishTreeViewEvent = require("../../utils/publishTreeViewEvent");
|
|
11
12
|
var _useTreeViewItems = require("./useTreeViewItems.utils");
|
|
12
13
|
var _TreeViewItemDepthContext = require("../../TreeViewItemDepthContext");
|
|
13
14
|
var _jsxRuntime = require("react/jsx-runtime");
|
|
15
|
+
const _excluded = ["children"];
|
|
14
16
|
function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return null; var r = new WeakMap(), t = new WeakMap(); return (_getRequireWildcardCache = function (e) { return e ? t : r; })(e); }
|
|
15
17
|
function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" != typeof e && "function" != typeof e) return { default: e }; var t = _getRequireWildcardCache(r); if (t && t.has(e)) return t.get(e); var n = { __proto__: null }, a = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var u in e) if ("default" !== u && {}.hasOwnProperty.call(e, u)) { var i = a ? Object.getOwnPropertyDescriptor(e, u) : null; i && (i.get || i.set) ? Object.defineProperty(n, u, i) : n[u] = e[u]; } return n.default = e, t && t.set(e, n), n; }
|
|
16
18
|
const updateItemsState = ({
|
|
@@ -46,7 +48,6 @@ const updateItemsState = ({
|
|
|
46
48
|
depth
|
|
47
49
|
};
|
|
48
50
|
itemMap[id] = item;
|
|
49
|
-
itemOrderedChildrenIds[id] = [];
|
|
50
51
|
const parentIdWithDefault = parentId ?? _useTreeViewItems.TREE_VIEW_ROOT_PARENT_ID;
|
|
51
52
|
if (!itemOrderedChildrenIds[parentIdWithDefault]) {
|
|
52
53
|
itemOrderedChildrenIds[parentIdWithDefault] = [];
|
|
@@ -75,6 +76,18 @@ const useTreeViewItems = ({
|
|
|
75
76
|
}) => {
|
|
76
77
|
const getItemMeta = React.useCallback(itemId => state.items.itemMetaMap[itemId], [state.items.itemMetaMap]);
|
|
77
78
|
const getItem = React.useCallback(itemId => state.items.itemMap[itemId], [state.items.itemMap]);
|
|
79
|
+
const getItemTree = React.useCallback(() => {
|
|
80
|
+
const getItemFromItemId = id => {
|
|
81
|
+
const _state$items$itemMap$ = state.items.itemMap[id],
|
|
82
|
+
item = (0, _objectWithoutPropertiesLoose2.default)(_state$items$itemMap$, _excluded);
|
|
83
|
+
const newChildren = state.items.itemOrderedChildrenIds[id];
|
|
84
|
+
if (newChildren) {
|
|
85
|
+
item.children = newChildren.map(getItemFromItemId);
|
|
86
|
+
}
|
|
87
|
+
return item;
|
|
88
|
+
};
|
|
89
|
+
return state.items.itemOrderedChildrenIds[_useTreeViewItems.TREE_VIEW_ROOT_PARENT_ID].map(getItemFromItemId);
|
|
90
|
+
}, [state.items.itemMap, state.items.itemOrderedChildrenIds]);
|
|
78
91
|
const isItemDisabled = React.useCallback(itemId => {
|
|
79
92
|
if (itemId == null) {
|
|
80
93
|
return false;
|
|
@@ -149,7 +162,7 @@ const useTreeViewItems = ({
|
|
|
149
162
|
label: item.label,
|
|
150
163
|
itemId: item.id,
|
|
151
164
|
id: item.idAttribute,
|
|
152
|
-
children: state.items.itemOrderedChildrenIds[id]
|
|
165
|
+
children: state.items.itemOrderedChildrenIds[id]?.map(getPropsFromItemId)
|
|
153
166
|
};
|
|
154
167
|
};
|
|
155
168
|
return state.items.itemOrderedChildrenIds[_useTreeViewItems.TREE_VIEW_ROOT_PARENT_ID].map(getPropsFromItemId);
|
|
@@ -162,11 +175,14 @@ const useTreeViewItems = ({
|
|
|
162
175
|
}),
|
|
163
176
|
publicAPI: {
|
|
164
177
|
getItem,
|
|
165
|
-
getItemDOMElement
|
|
178
|
+
getItemDOMElement,
|
|
179
|
+
getItemTree,
|
|
180
|
+
getItemOrderedChildrenIds
|
|
166
181
|
},
|
|
167
182
|
instance: {
|
|
168
183
|
getItemMeta,
|
|
169
184
|
getItem,
|
|
185
|
+
getItemTree,
|
|
170
186
|
getItemsToRender,
|
|
171
187
|
getItemIndex,
|
|
172
188
|
getItemDOMElement,
|
|
@@ -12,6 +12,7 @@ var _useForkRef = _interopRequireDefault(require("@mui/utils/useForkRef"));
|
|
|
12
12
|
var _useTreeViewModels = require("./useTreeViewModels");
|
|
13
13
|
var _corePlugins = require("../corePlugins");
|
|
14
14
|
var _extractPluginParamsFromProps = require("./extractPluginParamsFromProps");
|
|
15
|
+
var _useTreeViewBuildContext = require("./useTreeViewBuildContext");
|
|
15
16
|
function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return null; var r = new WeakMap(), t = new WeakMap(); return (_getRequireWildcardCache = function (e) { return e ? t : r; })(e); }
|
|
16
17
|
function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" != typeof e && "function" != typeof e) return { default: e }; var t = _getRequireWildcardCache(r); if (t && t.has(e)) return t.get(e); var n = { __proto__: null }, a = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var u in e) if ("default" !== u && {}.hasOwnProperty.call(e, u)) { var i = a ? Object.getOwnPropertyDescriptor(e, u) : null; i && (i.get || i.set) ? Object.defineProperty(n, u, i) : n[u] = e[u]; } return n.default = e, t && t.set(e, n), n; }
|
|
17
18
|
function useTreeViewApiInitialization(inputApiRef) {
|
|
@@ -47,6 +48,12 @@ const useTreeView = ({
|
|
|
47
48
|
const publicAPI = useTreeViewApiInitialization(apiRef);
|
|
48
49
|
const innerRootRef = React.useRef(null);
|
|
49
50
|
const handleRootRef = (0, _useForkRef.default)(innerRootRef, rootRef);
|
|
51
|
+
const contextValue = (0, _useTreeViewBuildContext.useTreeViewBuildContext)({
|
|
52
|
+
plugins,
|
|
53
|
+
instance,
|
|
54
|
+
publicAPI,
|
|
55
|
+
rootRef: innerRootRef
|
|
56
|
+
});
|
|
50
57
|
const [state, setState] = React.useState(() => {
|
|
51
58
|
const temp = {};
|
|
52
59
|
plugins.forEach(plugin => {
|
|
@@ -56,68 +63,6 @@ const useTreeView = ({
|
|
|
56
63
|
});
|
|
57
64
|
return temp;
|
|
58
65
|
});
|
|
59
|
-
const itemWrappers = plugins.map(plugin => plugin.wrapItem).filter(wrapItem => !!wrapItem);
|
|
60
|
-
const wrapItem = ({
|
|
61
|
-
itemId,
|
|
62
|
-
children
|
|
63
|
-
}) => {
|
|
64
|
-
let finalChildren = children;
|
|
65
|
-
itemWrappers.forEach(itemWrapper => {
|
|
66
|
-
finalChildren = itemWrapper({
|
|
67
|
-
itemId,
|
|
68
|
-
children: finalChildren,
|
|
69
|
-
instance
|
|
70
|
-
});
|
|
71
|
-
});
|
|
72
|
-
return finalChildren;
|
|
73
|
-
};
|
|
74
|
-
const rootWrappers = plugins.map(plugin => plugin.wrapRoot).filter(wrapRoot => !!wrapRoot)
|
|
75
|
-
// The wrappers are reversed to ensure that the first wrapper is the outermost one.
|
|
76
|
-
.reverse();
|
|
77
|
-
const wrapRoot = ({
|
|
78
|
-
children
|
|
79
|
-
}) => {
|
|
80
|
-
let finalChildren = children;
|
|
81
|
-
rootWrappers.forEach(rootWrapper => {
|
|
82
|
-
finalChildren = rootWrapper({
|
|
83
|
-
children: finalChildren,
|
|
84
|
-
instance
|
|
85
|
-
});
|
|
86
|
-
});
|
|
87
|
-
return finalChildren;
|
|
88
|
-
};
|
|
89
|
-
const runItemPlugins = itemPluginProps => {
|
|
90
|
-
let finalRootRef = null;
|
|
91
|
-
let finalContentRef = null;
|
|
92
|
-
plugins.forEach(plugin => {
|
|
93
|
-
if (!plugin.itemPlugin) {
|
|
94
|
-
return;
|
|
95
|
-
}
|
|
96
|
-
const itemPluginResponse = plugin.itemPlugin({
|
|
97
|
-
props: itemPluginProps,
|
|
98
|
-
rootRef: finalRootRef,
|
|
99
|
-
contentRef: finalContentRef
|
|
100
|
-
});
|
|
101
|
-
if (itemPluginResponse?.rootRef) {
|
|
102
|
-
finalRootRef = itemPluginResponse.rootRef;
|
|
103
|
-
}
|
|
104
|
-
if (itemPluginResponse?.contentRef) {
|
|
105
|
-
finalContentRef = itemPluginResponse.contentRef;
|
|
106
|
-
}
|
|
107
|
-
});
|
|
108
|
-
return {
|
|
109
|
-
contentRef: finalContentRef,
|
|
110
|
-
rootRef: finalRootRef
|
|
111
|
-
};
|
|
112
|
-
};
|
|
113
|
-
const contextValue = {
|
|
114
|
-
publicAPI,
|
|
115
|
-
wrapItem,
|
|
116
|
-
wrapRoot,
|
|
117
|
-
runItemPlugins,
|
|
118
|
-
instance: instance,
|
|
119
|
-
rootRef: innerRootRef
|
|
120
|
-
};
|
|
121
66
|
const rootPropsGetters = [];
|
|
122
67
|
const runPlugin = plugin => {
|
|
123
68
|
const pluginResponse = plugin({
|
|
@@ -129,7 +74,8 @@ const useTreeView = ({
|
|
|
129
74
|
state,
|
|
130
75
|
setState,
|
|
131
76
|
rootRef: innerRootRef,
|
|
132
|
-
models
|
|
77
|
+
models,
|
|
78
|
+
plugins
|
|
133
79
|
});
|
|
134
80
|
if (pluginResponse.getRootProps) {
|
|
135
81
|
rootPropsGetters.push(pluginResponse.getRootProps);
|
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.useTreeViewBuildContext = void 0;
|
|
7
|
+
const useTreeViewBuildContext = ({
|
|
8
|
+
plugins,
|
|
9
|
+
instance,
|
|
10
|
+
publicAPI,
|
|
11
|
+
rootRef
|
|
12
|
+
}) => {
|
|
13
|
+
const runItemPlugins = itemPluginProps => {
|
|
14
|
+
let finalRootRef = null;
|
|
15
|
+
let finalContentRef = null;
|
|
16
|
+
plugins.forEach(plugin => {
|
|
17
|
+
if (!plugin.itemPlugin) {
|
|
18
|
+
return;
|
|
19
|
+
}
|
|
20
|
+
const itemPluginResponse = plugin.itemPlugin({
|
|
21
|
+
props: itemPluginProps,
|
|
22
|
+
rootRef: finalRootRef,
|
|
23
|
+
contentRef: finalContentRef
|
|
24
|
+
});
|
|
25
|
+
if (itemPluginResponse?.rootRef) {
|
|
26
|
+
finalRootRef = itemPluginResponse.rootRef;
|
|
27
|
+
}
|
|
28
|
+
if (itemPluginResponse?.contentRef) {
|
|
29
|
+
finalContentRef = itemPluginResponse.contentRef;
|
|
30
|
+
}
|
|
31
|
+
});
|
|
32
|
+
return {
|
|
33
|
+
contentRef: finalContentRef,
|
|
34
|
+
rootRef: finalRootRef
|
|
35
|
+
};
|
|
36
|
+
};
|
|
37
|
+
const wrapItem = ({
|
|
38
|
+
itemId,
|
|
39
|
+
children
|
|
40
|
+
}) => {
|
|
41
|
+
let finalChildren = children;
|
|
42
|
+
// The wrappers are reversed to ensure that the first wrapper is the outermost one.
|
|
43
|
+
for (let i = plugins.length - 1; i >= 0; i -= 1) {
|
|
44
|
+
const plugin = plugins[i];
|
|
45
|
+
if (plugin.wrapItem) {
|
|
46
|
+
finalChildren = plugin.wrapItem({
|
|
47
|
+
itemId,
|
|
48
|
+
children: finalChildren,
|
|
49
|
+
instance
|
|
50
|
+
});
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
return finalChildren;
|
|
54
|
+
};
|
|
55
|
+
const wrapRoot = ({
|
|
56
|
+
children
|
|
57
|
+
}) => {
|
|
58
|
+
let finalChildren = children;
|
|
59
|
+
// The wrappers are reversed to ensure that the first wrapper is the outermost one.
|
|
60
|
+
for (let i = plugins.length - 1; i >= 0; i -= 1) {
|
|
61
|
+
const plugin = plugins[i];
|
|
62
|
+
if (plugin.wrapRoot) {
|
|
63
|
+
finalChildren = plugin.wrapRoot({
|
|
64
|
+
children: finalChildren,
|
|
65
|
+
instance
|
|
66
|
+
});
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
return finalChildren;
|
|
70
|
+
};
|
|
71
|
+
return {
|
|
72
|
+
runItemPlugins,
|
|
73
|
+
wrapItem,
|
|
74
|
+
wrapRoot,
|
|
75
|
+
instance,
|
|
76
|
+
rootRef,
|
|
77
|
+
publicAPI
|
|
78
|
+
};
|
|
79
|
+
};
|
|
80
|
+
exports.useTreeViewBuildContext = useTreeViewBuildContext;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.hasPlugin = void 0;
|
|
7
|
+
const hasPlugin = (instance, plugin) => {
|
|
8
|
+
const plugins = instance.getAvailablePlugins();
|
|
9
|
+
return plugins.has(plugin);
|
|
10
|
+
};
|
|
11
|
+
exports.hasPlugin = hasPlugin;
|