@mui/x-tree-view 7.19.0 → 7.21.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 +224 -43
- package/RichTreeView/RichTreeView.js +14 -53
- package/SimpleTreeView/SimpleTreeView.js +8 -8
- package/TreeItem/TreeItem.js +25 -12
- package/TreeItem/TreeItem.types.d.ts +6 -4
- package/TreeItem/TreeItemContent.d.ts +5 -5
- package/TreeItem/TreeItemContent.js +29 -33
- package/TreeItem/treeItemClasses.d.ts +1 -1
- package/TreeItem2/TreeItem2.types.d.ts +1 -1
- package/TreeItem2DragAndDropOverlay/TreeItem2DragAndDropOverlay.js +7 -7
- package/TreeItem2Icon/TreeItem2Icon.types.d.ts +1 -1
- package/TreeView/TreeView.d.ts +1 -1
- package/TreeView/TreeView.js +8 -8
- package/index.js +1 -1
- package/internals/components/RichTreeViewItems.d.ts +35 -0
- package/internals/components/RichTreeViewItems.js +56 -0
- package/internals/corePlugins/corePlugins.d.ts +1 -1
- package/internals/corePlugins/corePlugins.js +1 -1
- package/internals/corePlugins/useTreeViewId/useTreeViewId.js +3 -3
- package/internals/corePlugins/useTreeViewId/useTreeViewId.types.d.ts +1 -1
- package/internals/corePlugins/useTreeViewId/useTreeViewId.utils.d.ts +1 -1
- package/internals/corePlugins/useTreeViewId/useTreeViewId.utils.js +1 -1
- package/internals/index.d.ts +1 -0
- package/internals/index.js +1 -0
- package/internals/models/treeView.d.ts +2 -2
- package/internals/plugins/useTreeViewExpansion/useTreeViewExpansion.types.d.ts +2 -2
- package/internals/plugins/useTreeViewFocus/useTreeViewFocus.types.d.ts +1 -1
- package/internals/plugins/useTreeViewIcons/useTreeViewIcons.types.d.ts +1 -1
- package/internals/plugins/useTreeViewItems/index.d.ts +1 -1
- package/internals/plugins/useTreeViewItems/useTreeViewItems.types.d.ts +8 -8
- package/internals/plugins/useTreeViewJSXItems/useTreeViewJSXItems.js +1 -1
- package/internals/plugins/useTreeViewKeyboardNavigation/useTreeViewKeyboardNavigation.js +3 -3
- package/internals/plugins/useTreeViewLabel/useTreeViewLabel.js +1 -1
- package/internals/plugins/useTreeViewLabel/useTreeViewLabel.types.d.ts +1 -1
- package/internals/plugins/useTreeViewSelection/useTreeViewSelection.types.d.ts +3 -3
- package/modern/RichTreeView/RichTreeView.js +14 -53
- package/modern/SimpleTreeView/SimpleTreeView.js +8 -8
- package/modern/TreeItem/TreeItem.js +25 -12
- package/modern/TreeItem/TreeItemContent.js +29 -33
- package/modern/TreeItem2DragAndDropOverlay/TreeItem2DragAndDropOverlay.js +7 -7
- package/modern/TreeView/TreeView.js +8 -8
- package/modern/index.js +1 -1
- package/modern/internals/components/RichTreeViewItems.js +56 -0
- package/modern/internals/corePlugins/corePlugins.js +1 -1
- package/modern/internals/corePlugins/useTreeViewId/useTreeViewId.js +3 -3
- package/modern/internals/corePlugins/useTreeViewId/useTreeViewId.utils.js +1 -1
- package/modern/internals/index.js +1 -0
- package/modern/internals/plugins/useTreeViewJSXItems/useTreeViewJSXItems.js +1 -1
- package/modern/internals/plugins/useTreeViewKeyboardNavigation/useTreeViewKeyboardNavigation.js +3 -3
- package/modern/internals/plugins/useTreeViewLabel/useTreeViewLabel.js +1 -1
- package/modern/useTreeItem2/useTreeItem2.js +11 -11
- package/node/RichTreeView/RichTreeView.js +14 -53
- package/node/SimpleTreeView/SimpleTreeView.js +8 -8
- package/node/TreeItem/TreeItem.js +25 -12
- package/node/TreeItem/TreeItemContent.js +29 -33
- package/node/TreeItem2DragAndDropOverlay/TreeItem2DragAndDropOverlay.js +7 -7
- package/node/TreeView/TreeView.js +8 -8
- package/node/index.js +1 -1
- package/node/internals/components/RichTreeViewItems.js +64 -0
- package/node/internals/corePlugins/corePlugins.js +1 -1
- package/node/internals/corePlugins/useTreeViewId/useTreeViewId.js +3 -3
- package/node/internals/corePlugins/useTreeViewId/useTreeViewId.utils.js +1 -1
- package/node/internals/index.js +7 -0
- package/node/internals/plugins/useTreeViewJSXItems/useTreeViewJSXItems.js +1 -1
- package/node/internals/plugins/useTreeViewKeyboardNavigation/useTreeViewKeyboardNavigation.js +3 -3
- package/node/internals/plugins/useTreeViewLabel/useTreeViewLabel.js +1 -1
- package/node/useTreeItem2/useTreeItem2.js +11 -11
- package/package.json +4 -4
- package/useTreeItem2/index.d.ts +1 -1
- package/useTreeItem2/useTreeItem2.js +11 -11
- package/useTreeItem2/useTreeItem2.types.d.ts +2 -2
|
@@ -26,7 +26,7 @@ const TreeItem2DragAndDropOverlayRoot = styled('div', {
|
|
|
26
26
|
style: {
|
|
27
27
|
marginLeft: 'calc(var(--TreeView-indentMultiplier) * var(--TreeView-itemDepth))',
|
|
28
28
|
borderRadius: theme.shape.borderRadius,
|
|
29
|
-
backgroundColor:
|
|
29
|
+
backgroundColor: theme.vars ? `rgba(${theme.vars.palette.primary.dark} / ${0.15})` : alpha(theme.palette.primary.dark, 0.15)
|
|
30
30
|
}
|
|
31
31
|
}, {
|
|
32
32
|
props: {
|
|
@@ -34,9 +34,9 @@ const TreeItem2DragAndDropOverlayRoot = styled('div', {
|
|
|
34
34
|
},
|
|
35
35
|
style: _extends({
|
|
36
36
|
marginLeft: 'calc(var(--TreeView-indentMultiplier) * var(--TreeView-itemDepth))',
|
|
37
|
-
borderTop: `1px solid ${
|
|
37
|
+
borderTop: theme.vars ? `1px solid rgba(${theme.vars.palette.grey[900]} / ${0.6})` : `1px solid ${alpha(theme.palette.grey[900], 0.6)}`
|
|
38
38
|
}, theme.applyStyles('dark', {
|
|
39
|
-
borderTopColor:
|
|
39
|
+
borderTopColor: theme.vars ? `rgba(${theme.vars.palette.grey[100]} / ${0.6})` : alpha(theme.palette.grey[100], 0.6)
|
|
40
40
|
}))
|
|
41
41
|
}, {
|
|
42
42
|
props: {
|
|
@@ -44,9 +44,9 @@ const TreeItem2DragAndDropOverlayRoot = styled('div', {
|
|
|
44
44
|
},
|
|
45
45
|
style: _extends({
|
|
46
46
|
marginLeft: 'calc(var(--TreeView-indentMultiplier) * var(--TreeView-itemDepth))',
|
|
47
|
-
borderBottom: `1px solid ${
|
|
47
|
+
borderBottom: theme.vars ? `1px solid rgba(${theme.vars.palette.grey[900]} / ${0.6})` : `1px solid ${alpha(theme.palette.grey[900], 0.6)}`
|
|
48
48
|
}, theme.applyStyles('dark', {
|
|
49
|
-
borderBottomColor:
|
|
49
|
+
borderBottomColor: theme.vars ? `rgba(${theme.vars.palette.grey[100]} / ${0.6})` : alpha(theme.palette.grey[100], 0.6)
|
|
50
50
|
}))
|
|
51
51
|
}, {
|
|
52
52
|
props: {
|
|
@@ -54,9 +54,9 @@ const TreeItem2DragAndDropOverlayRoot = styled('div', {
|
|
|
54
54
|
},
|
|
55
55
|
style: _extends({
|
|
56
56
|
marginLeft: 'calc(var(--TreeView-indentMultiplier) * calc(var(--TreeView-itemDepth) - 1))',
|
|
57
|
-
borderBottom: `1px solid ${
|
|
57
|
+
borderBottom: theme.vars ? `1px solid rgba(${theme.vars.palette.grey[900]} / ${0.6})` : `1px solid ${alpha(theme.palette.grey[900], 0.6)}`
|
|
58
58
|
}, theme.applyStyles('dark', {
|
|
59
|
-
borderBottomColor:
|
|
59
|
+
borderBottomColor: theme.vars ? `rgba(${theme.vars.palette.grey[100]} / ${0.6})` : alpha(theme.palette.grey[100], 0.6)
|
|
60
60
|
}))
|
|
61
61
|
}]
|
|
62
62
|
}));
|
|
@@ -32,7 +32,7 @@ const warn = () => {
|
|
|
32
32
|
};
|
|
33
33
|
|
|
34
34
|
/**
|
|
35
|
-
* This component has been deprecated in favor of the new
|
|
35
|
+
* This component has been deprecated in favor of the new Simple Tree View component.
|
|
36
36
|
* You can have a look at how to migrate to the new component in the v7 [migration guide](https://mui.com/x/migration/migration-tree-view-v6/#use-simpletreeview-instead-of-treeview)
|
|
37
37
|
*
|
|
38
38
|
* Demos:
|
|
@@ -82,7 +82,7 @@ process.env.NODE_ENV !== "production" ? TreeView.propTypes = {
|
|
|
82
82
|
})
|
|
83
83
|
}),
|
|
84
84
|
/**
|
|
85
|
-
* If `true`, the
|
|
85
|
+
* If `true`, the Tree View renders a checkbox at the left of its label that allows selecting it.
|
|
86
86
|
* @default false
|
|
87
87
|
*/
|
|
88
88
|
checkboxSelection: PropTypes.bool,
|
|
@@ -152,39 +152,39 @@ process.env.NODE_ENV !== "production" ? TreeView.propTypes = {
|
|
|
152
152
|
*/
|
|
153
153
|
multiSelect: PropTypes.bool,
|
|
154
154
|
/**
|
|
155
|
-
* Callback fired when
|
|
155
|
+
* Callback fired when Tree Items are expanded/collapsed.
|
|
156
156
|
* @param {React.SyntheticEvent} event The DOM event that triggered the change.
|
|
157
157
|
* @param {array} itemIds The ids of the expanded items.
|
|
158
158
|
*/
|
|
159
159
|
onExpandedItemsChange: PropTypes.func,
|
|
160
160
|
/**
|
|
161
|
-
* Callback fired when the `content` slot of a given
|
|
161
|
+
* Callback fired when the `content` slot of a given Tree Item is clicked.
|
|
162
162
|
* @param {React.MouseEvent} event The DOM event that triggered the change.
|
|
163
163
|
* @param {string} itemId The id of the focused item.
|
|
164
164
|
*/
|
|
165
165
|
onItemClick: PropTypes.func,
|
|
166
166
|
/**
|
|
167
|
-
* Callback fired when a
|
|
167
|
+
* Callback fired when a Tree Item is expanded or collapsed.
|
|
168
168
|
* @param {React.SyntheticEvent} event The DOM event that triggered the change.
|
|
169
169
|
* @param {array} itemId The itemId of the modified item.
|
|
170
170
|
* @param {array} isExpanded `true` if the item has just been expanded, `false` if it has just been collapsed.
|
|
171
171
|
*/
|
|
172
172
|
onItemExpansionToggle: PropTypes.func,
|
|
173
173
|
/**
|
|
174
|
-
* Callback fired when a given
|
|
174
|
+
* Callback fired when a given Tree Item is focused.
|
|
175
175
|
* @param {React.SyntheticEvent | null} event The DOM event that triggered the change. **Warning**: This is a generic event not a focus event.
|
|
176
176
|
* @param {string} itemId The id of the focused item.
|
|
177
177
|
*/
|
|
178
178
|
onItemFocus: PropTypes.func,
|
|
179
179
|
/**
|
|
180
|
-
* Callback fired when a
|
|
180
|
+
* Callback fired when a Tree Item is selected or deselected.
|
|
181
181
|
* @param {React.SyntheticEvent} event The DOM event that triggered the change.
|
|
182
182
|
* @param {array} itemId The itemId of the modified item.
|
|
183
183
|
* @param {array} isSelected `true` if the item has just been selected, `false` if it has just been deselected.
|
|
184
184
|
*/
|
|
185
185
|
onItemSelectionToggle: PropTypes.func,
|
|
186
186
|
/**
|
|
187
|
-
* Callback fired when
|
|
187
|
+
* Callback fired when Tree Items are selected/deselected.
|
|
188
188
|
* @param {React.SyntheticEvent} event The DOM event that triggered the change.
|
|
189
189
|
* @param {string[] | string} itemIds The ids of the selected items.
|
|
190
190
|
* When `multiSelect` is `true`, this is an array of strings; when false (default) a string.
|
package/modern/index.js
CHANGED
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
import _extends from "@babel/runtime/helpers/esm/extends";
|
|
2
|
+
import _objectWithoutPropertiesLoose from "@babel/runtime/helpers/esm/objectWithoutPropertiesLoose";
|
|
3
|
+
const _excluded = ["ownerState"];
|
|
4
|
+
import * as React from 'react';
|
|
5
|
+
import useSlotProps from '@mui/utils/useSlotProps';
|
|
6
|
+
import { TreeItem } from "../../TreeItem/index.js";
|
|
7
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
8
|
+
function WrappedTreeItem({
|
|
9
|
+
slots,
|
|
10
|
+
slotProps,
|
|
11
|
+
label,
|
|
12
|
+
id,
|
|
13
|
+
itemId,
|
|
14
|
+
itemsToRender
|
|
15
|
+
}) {
|
|
16
|
+
const Item = slots?.item ?? TreeItem;
|
|
17
|
+
const _useSlotProps = useSlotProps({
|
|
18
|
+
elementType: Item,
|
|
19
|
+
externalSlotProps: slotProps?.item,
|
|
20
|
+
additionalProps: {
|
|
21
|
+
itemId,
|
|
22
|
+
id,
|
|
23
|
+
label
|
|
24
|
+
},
|
|
25
|
+
ownerState: {
|
|
26
|
+
itemId,
|
|
27
|
+
label
|
|
28
|
+
}
|
|
29
|
+
}),
|
|
30
|
+
itemProps = _objectWithoutPropertiesLoose(_useSlotProps, _excluded);
|
|
31
|
+
const children = React.useMemo(() => itemsToRender ? /*#__PURE__*/_jsx(RichTreeViewItems, {
|
|
32
|
+
itemsToRender: itemsToRender,
|
|
33
|
+
slots: slots,
|
|
34
|
+
slotProps: slotProps
|
|
35
|
+
}) : null, [itemsToRender, slots, slotProps]);
|
|
36
|
+
return /*#__PURE__*/_jsx(Item, _extends({}, itemProps, {
|
|
37
|
+
children: children
|
|
38
|
+
}));
|
|
39
|
+
}
|
|
40
|
+
export function RichTreeViewItems(props) {
|
|
41
|
+
const {
|
|
42
|
+
itemsToRender,
|
|
43
|
+
slots,
|
|
44
|
+
slotProps
|
|
45
|
+
} = props;
|
|
46
|
+
return /*#__PURE__*/_jsx(React.Fragment, {
|
|
47
|
+
children: itemsToRender.map(item => /*#__PURE__*/_jsx(WrappedTreeItem, {
|
|
48
|
+
slots: slots,
|
|
49
|
+
slotProps: slotProps,
|
|
50
|
+
label: item.label,
|
|
51
|
+
id: item.id,
|
|
52
|
+
itemId: item.itemId,
|
|
53
|
+
itemsToRender: item.children
|
|
54
|
+
}, item.itemId))
|
|
55
|
+
});
|
|
56
|
+
}
|
|
@@ -3,6 +3,6 @@ import { useTreeViewOptionalPlugins } from "./useTreeViewOptionalPlugins/index.j
|
|
|
3
3
|
import { useTreeViewId } from "./useTreeViewId/index.js";
|
|
4
4
|
/**
|
|
5
5
|
* Internal plugins that create the tools used by the other plugins.
|
|
6
|
-
* These plugins are used by the
|
|
6
|
+
* These plugins are used by the Tree View components.
|
|
7
7
|
*/
|
|
8
8
|
export const TREE_VIEW_CORE_PLUGINS = [useTreeViewInstanceEvents, useTreeViewOptionalPlugins, useTreeViewId];
|
|
@@ -6,10 +6,9 @@ export const useTreeViewId = ({
|
|
|
6
6
|
state,
|
|
7
7
|
setState
|
|
8
8
|
}) => {
|
|
9
|
-
const treeId = state.id.treeId;
|
|
10
9
|
React.useEffect(() => {
|
|
11
10
|
setState(prevState => {
|
|
12
|
-
if (prevState.id.treeId === params.id) {
|
|
11
|
+
if (prevState.id.treeId === params.id && prevState.id.treeId !== undefined) {
|
|
13
12
|
return prevState;
|
|
14
13
|
}
|
|
15
14
|
return _extends({}, prevState, {
|
|
@@ -19,6 +18,7 @@ export const useTreeViewId = ({
|
|
|
19
18
|
});
|
|
20
19
|
});
|
|
21
20
|
}, [setState, params.id]);
|
|
21
|
+
const treeId = params.id ?? state.id.treeId;
|
|
22
22
|
return {
|
|
23
23
|
getRootProps: () => ({
|
|
24
24
|
id: treeId
|
|
@@ -35,6 +35,6 @@ useTreeViewId.getInitialState = ({
|
|
|
35
35
|
id
|
|
36
36
|
}) => ({
|
|
37
37
|
id: {
|
|
38
|
-
treeId: id ??
|
|
38
|
+
treeId: id ?? undefined
|
|
39
39
|
}
|
|
40
40
|
});
|
|
@@ -5,7 +5,7 @@ export const createTreeViewDefaultId = () => {
|
|
|
5
5
|
};
|
|
6
6
|
|
|
7
7
|
/**
|
|
8
|
-
* Generate the id attribute (i.e.: the `id` attribute passed to the DOM element) of a
|
|
8
|
+
* Generate the id attribute (i.e.: the `id` attribute passed to the DOM element) of a Tree Item.
|
|
9
9
|
* If the user explicitly defined an id attribute, it will be returned.
|
|
10
10
|
* Otherwise, the method creates a unique id for the item based on the Tree View id attribute and the item `itemId`
|
|
11
11
|
* @param {object} params The parameters to determine the id attribute of the item.
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
export { useTreeView } from "./useTreeView/index.js";
|
|
2
2
|
export { TreeViewProvider, useTreeViewContext } from "./TreeViewProvider/index.js";
|
|
3
|
+
export { RichTreeViewItems } from "./components/RichTreeViewItems.js";
|
|
3
4
|
export { unstable_resetCleanupTracking } from "./hooks/useInstanceEventHandler.js";
|
|
4
5
|
|
|
5
6
|
// Core plugins
|
|
@@ -25,7 +25,7 @@ export const useTreeViewJSXItems = ({
|
|
|
25
25
|
itemMetaMap: _extends({}, prevState.items.itemMetaMap, {
|
|
26
26
|
[item.id]: item
|
|
27
27
|
}),
|
|
28
|
-
// For
|
|
28
|
+
// For Simple Tree View, we don't have a proper `item` object, so we create a very basic one.
|
|
29
29
|
itemMap: _extends({}, prevState.items.itemMap, {
|
|
30
30
|
[item.id]: {
|
|
31
31
|
id: item.id,
|
package/modern/internals/plugins/useTreeViewKeyboardNavigation/useTreeViewKeyboardNavigation.js
CHANGED
|
@@ -4,7 +4,7 @@ import useEventCallback from '@mui/utils/useEventCallback';
|
|
|
4
4
|
import { getFirstNavigableItem, getLastNavigableItem, getNextNavigableItem, getPreviousNavigableItem, isTargetInDescendants } from "../../utils/tree.js";
|
|
5
5
|
import { hasPlugin } from "../../utils/plugins.js";
|
|
6
6
|
import { useTreeViewLabel } from "../useTreeViewLabel/index.js";
|
|
7
|
-
function
|
|
7
|
+
function isPrintableKey(string) {
|
|
8
8
|
return !!string && string.length === 1 && !!string.match(/\S/);
|
|
9
9
|
}
|
|
10
10
|
export const useTreeViewKeyboardNavigation = ({
|
|
@@ -227,7 +227,7 @@ export const useTreeViewKeyboardNavigation = ({
|
|
|
227
227
|
|
|
228
228
|
// Multi select behavior when pressing Ctrl + a
|
|
229
229
|
// Selects all the items
|
|
230
|
-
case
|
|
230
|
+
case String.fromCharCode(event.keyCode) === 'A' && ctrlPressed && params.multiSelect && !params.disableSelection:
|
|
231
231
|
{
|
|
232
232
|
instance.selectAllNavigableItems(event);
|
|
233
233
|
event.preventDefault();
|
|
@@ -236,7 +236,7 @@ export const useTreeViewKeyboardNavigation = ({
|
|
|
236
236
|
|
|
237
237
|
// Type-ahead
|
|
238
238
|
// TODO: Support typing multiple characters
|
|
239
|
-
case !ctrlPressed && !event.shiftKey &&
|
|
239
|
+
case !ctrlPressed && !event.shiftKey && isPrintableKey(key):
|
|
240
240
|
{
|
|
241
241
|
const matchingItem = getFirstMatchingItem(itemId, key);
|
|
242
242
|
if (matchingItem != null) {
|
|
@@ -73,7 +73,7 @@ useTreeViewLabel.getDefaultizedParams = ({
|
|
|
73
73
|
const canUseFeature = experimentalFeatures?.labelEditing;
|
|
74
74
|
if (process.env.NODE_ENV !== 'production') {
|
|
75
75
|
if (params.isItemEditable && !canUseFeature) {
|
|
76
|
-
warnOnce(['MUI X: The label editing feature requires the `labelEditing` experimental feature to be enabled.', 'You can do it by passing `experimentalFeatures={{ labelEditing: true}}` to the
|
|
76
|
+
warnOnce(['MUI X: The label editing feature requires the `labelEditing` experimental feature to be enabled.', 'You can do it by passing `experimentalFeatures={{ labelEditing: true}}` to the Rich Tree View Pro component.', 'Check the documentation for more details: https://mui.com/x/react-tree-view/rich-tree-view/editing/']);
|
|
77
77
|
}
|
|
78
78
|
}
|
|
79
79
|
return _extends({}, params, {
|
|
@@ -16,7 +16,6 @@ export const useTreeItem2 = parameters => {
|
|
|
16
16
|
indentationAtItemLevel
|
|
17
17
|
},
|
|
18
18
|
selection: {
|
|
19
|
-
multiSelect,
|
|
20
19
|
disableSelection,
|
|
21
20
|
checkboxSelection
|
|
22
21
|
},
|
|
@@ -84,7 +83,7 @@ export const useTreeItem2 = parameters => {
|
|
|
84
83
|
// the input that triggers the root blur can be either the relatedTarget (when entering editing state) or the target (when exiting editing state)
|
|
85
84
|
// when we enter the editing state, we focus the input -> we don't want to remove the focused item from the state
|
|
86
85
|
if (status.editing ||
|
|
87
|
-
// we can exit the editing state by clicking outside the input (within the
|
|
86
|
+
// we can exit the editing state by clicking outside the input (within the Tree Item) or by pressing Enter or Escape -> we don't want to remove the focused item from the state in these cases
|
|
88
87
|
// we can also exit the editing state by clicking on the root itself -> want to remove the focused item from the state in this case
|
|
89
88
|
event.relatedTarget && isTargetInDescendants(event.relatedTarget, rootElement) && (event.target && event.target?.dataset?.element === 'labelInput' && isTargetInDescendants(event.target, rootElement) || event.relatedTarget?.dataset?.element === 'labelInput')) {
|
|
90
89
|
return;
|
|
@@ -150,17 +149,18 @@ export const useTreeItem2 = parameters => {
|
|
|
150
149
|
};
|
|
151
150
|
const getRootProps = (externalProps = {}) => {
|
|
152
151
|
const externalEventHandlers = _extends({}, extractEventHandlers(parameters), extractEventHandlers(externalProps));
|
|
152
|
+
|
|
153
|
+
// https://www.w3.org/WAI/ARIA/apg/patterns/treeview/
|
|
153
154
|
let ariaSelected;
|
|
154
|
-
if (
|
|
155
|
-
|
|
156
|
-
} else if (status.selected) {
|
|
157
|
-
/* single-selection trees unset aria-selected on un-selected items.
|
|
158
|
-
*
|
|
159
|
-
* If the tree does not support multiple selection, aria-selected
|
|
160
|
-
* is set to true for the selected item and it is not present on any other item in the tree.
|
|
161
|
-
* Source: https://www.w3.org/WAI/ARIA/apg/patterns/treeview/
|
|
162
|
-
*/
|
|
155
|
+
if (status.selected) {
|
|
156
|
+
// - each selected node has aria-selected set to true.
|
|
163
157
|
ariaSelected = true;
|
|
158
|
+
} else if (disableSelection || status.disabled) {
|
|
159
|
+
// - if the tree contains nodes that are not selectable, aria-selected is not present on those nodes.
|
|
160
|
+
ariaSelected = undefined;
|
|
161
|
+
} else {
|
|
162
|
+
// - all nodes that are selectable but not selected have aria-selected set to false.
|
|
163
|
+
ariaSelected = false;
|
|
164
164
|
}
|
|
165
165
|
const props = _extends({}, externalEventHandlers, {
|
|
166
166
|
ref: handleRootRef,
|
|
@@ -18,7 +18,7 @@ var _zeroStyled = require("../internals/zero-styled");
|
|
|
18
18
|
var _useTreeView = require("../internals/useTreeView");
|
|
19
19
|
var _TreeViewProvider = require("../internals/TreeViewProvider");
|
|
20
20
|
var _RichTreeView = require("./RichTreeView.plugins");
|
|
21
|
-
var
|
|
21
|
+
var _RichTreeViewItems = require("../internals/components/RichTreeViewItems");
|
|
22
22
|
var _jsxRuntime = require("react/jsx-runtime");
|
|
23
23
|
const useThemeProps = (0, _zeroStyled.createUseThemeProps)('MuiRichTreeView');
|
|
24
24
|
const useUtilityClasses = ownerState => {
|
|
@@ -41,33 +41,6 @@ const RichTreeViewRoot = exports.RichTreeViewRoot = (0, _zeroStyled.styled)('ul'
|
|
|
41
41
|
outline: 0,
|
|
42
42
|
position: 'relative'
|
|
43
43
|
});
|
|
44
|
-
function WrappedTreeItem({
|
|
45
|
-
slots,
|
|
46
|
-
slotProps,
|
|
47
|
-
label,
|
|
48
|
-
id,
|
|
49
|
-
itemId,
|
|
50
|
-
children
|
|
51
|
-
}) {
|
|
52
|
-
const Item = slots?.item ?? _TreeItem.TreeItem;
|
|
53
|
-
const itemProps = (0, _useSlotProps.default)({
|
|
54
|
-
elementType: Item,
|
|
55
|
-
externalSlotProps: slotProps?.item,
|
|
56
|
-
additionalProps: {
|
|
57
|
-
itemId,
|
|
58
|
-
id,
|
|
59
|
-
label
|
|
60
|
-
},
|
|
61
|
-
ownerState: {
|
|
62
|
-
itemId,
|
|
63
|
-
label
|
|
64
|
-
}
|
|
65
|
-
});
|
|
66
|
-
return /*#__PURE__*/(0, _jsxRuntime.jsx)(Item, (0, _extends2.default)({}, itemProps, {
|
|
67
|
-
children: children
|
|
68
|
-
}));
|
|
69
|
-
}
|
|
70
|
-
|
|
71
44
|
/**
|
|
72
45
|
*
|
|
73
46
|
* Demos:
|
|
@@ -85,7 +58,7 @@ const RichTreeView = exports.RichTreeView = /*#__PURE__*/React.forwardRef(functi
|
|
|
85
58
|
});
|
|
86
59
|
if (process.env.NODE_ENV !== 'production') {
|
|
87
60
|
if (props.children != null) {
|
|
88
|
-
(0, _warning.warnOnce)(['MUI X: The
|
|
61
|
+
(0, _warning.warnOnce)(['MUI X: The Rich Tree View component does not support JSX children.', 'If you want to add items, you need to use the `items` prop.', 'Check the documentation for more details: https://mui.com/x/react-tree-view/rich-tree-view/items/.']);
|
|
89
62
|
}
|
|
90
63
|
}
|
|
91
64
|
const {
|
|
@@ -110,26 +83,14 @@ const RichTreeView = exports.RichTreeView = /*#__PURE__*/React.forwardRef(functi
|
|
|
110
83
|
getSlotProps: getRootProps,
|
|
111
84
|
ownerState: props
|
|
112
85
|
});
|
|
113
|
-
const itemsToRender = instance.getItemsToRender();
|
|
114
|
-
const renderItem = ({
|
|
115
|
-
label,
|
|
116
|
-
itemId,
|
|
117
|
-
id,
|
|
118
|
-
children
|
|
119
|
-
}) => {
|
|
120
|
-
return /*#__PURE__*/(0, _jsxRuntime.jsx)(WrappedTreeItem, {
|
|
121
|
-
slots: slots,
|
|
122
|
-
slotProps: slotProps,
|
|
123
|
-
label: label,
|
|
124
|
-
id: id,
|
|
125
|
-
itemId: itemId,
|
|
126
|
-
children: children?.map(renderItem)
|
|
127
|
-
}, itemId);
|
|
128
|
-
};
|
|
129
86
|
return /*#__PURE__*/(0, _jsxRuntime.jsx)(_TreeViewProvider.TreeViewProvider, {
|
|
130
87
|
value: contextValue,
|
|
131
88
|
children: /*#__PURE__*/(0, _jsxRuntime.jsx)(Root, (0, _extends2.default)({}, rootProps, {
|
|
132
|
-
children:
|
|
89
|
+
children: /*#__PURE__*/(0, _jsxRuntime.jsx)(_RichTreeViewItems.RichTreeViewItems, {
|
|
90
|
+
slots: slots,
|
|
91
|
+
slotProps: slotProps,
|
|
92
|
+
itemsToRender: instance.getItemsToRender()
|
|
93
|
+
})
|
|
133
94
|
}))
|
|
134
95
|
});
|
|
135
96
|
});
|
|
@@ -154,7 +115,7 @@ process.env.NODE_ENV !== "production" ? RichTreeView.propTypes = {
|
|
|
154
115
|
})
|
|
155
116
|
}),
|
|
156
117
|
/**
|
|
157
|
-
* If `true`, the
|
|
118
|
+
* If `true`, the Tree View renders a checkbox at the left of its label that allows selecting it.
|
|
158
119
|
* @default false
|
|
159
120
|
*/
|
|
160
121
|
checkboxSelection: _propTypes.default.bool,
|
|
@@ -257,26 +218,26 @@ process.env.NODE_ENV !== "production" ? RichTreeView.propTypes = {
|
|
|
257
218
|
*/
|
|
258
219
|
multiSelect: _propTypes.default.bool,
|
|
259
220
|
/**
|
|
260
|
-
* Callback fired when
|
|
221
|
+
* Callback fired when Tree Items are expanded/collapsed.
|
|
261
222
|
* @param {React.SyntheticEvent} event The DOM event that triggered the change.
|
|
262
223
|
* @param {array} itemIds The ids of the expanded items.
|
|
263
224
|
*/
|
|
264
225
|
onExpandedItemsChange: _propTypes.default.func,
|
|
265
226
|
/**
|
|
266
|
-
* Callback fired when the `content` slot of a given
|
|
227
|
+
* Callback fired when the `content` slot of a given Tree Item is clicked.
|
|
267
228
|
* @param {React.MouseEvent} event The DOM event that triggered the change.
|
|
268
229
|
* @param {string} itemId The id of the focused item.
|
|
269
230
|
*/
|
|
270
231
|
onItemClick: _propTypes.default.func,
|
|
271
232
|
/**
|
|
272
|
-
* Callback fired when a
|
|
233
|
+
* Callback fired when a Tree Item is expanded or collapsed.
|
|
273
234
|
* @param {React.SyntheticEvent} event The DOM event that triggered the change.
|
|
274
235
|
* @param {array} itemId The itemId of the modified item.
|
|
275
236
|
* @param {array} isExpanded `true` if the item has just been expanded, `false` if it has just been collapsed.
|
|
276
237
|
*/
|
|
277
238
|
onItemExpansionToggle: _propTypes.default.func,
|
|
278
239
|
/**
|
|
279
|
-
* Callback fired when a given
|
|
240
|
+
* Callback fired when a given Tree Item is focused.
|
|
280
241
|
* @param {React.SyntheticEvent | null} event The DOM event that triggered the change. **Warning**: This is a generic event not a focus event.
|
|
281
242
|
* @param {string} itemId The id of the focused item.
|
|
282
243
|
*/
|
|
@@ -288,14 +249,14 @@ process.env.NODE_ENV !== "production" ? RichTreeView.propTypes = {
|
|
|
288
249
|
*/
|
|
289
250
|
onItemLabelChange: _propTypes.default.func,
|
|
290
251
|
/**
|
|
291
|
-
* Callback fired when a
|
|
252
|
+
* Callback fired when a Tree Item is selected or deselected.
|
|
292
253
|
* @param {React.SyntheticEvent} event The DOM event that triggered the change.
|
|
293
254
|
* @param {array} itemId The itemId of the modified item.
|
|
294
255
|
* @param {array} isSelected `true` if the item has just been selected, `false` if it has just been deselected.
|
|
295
256
|
*/
|
|
296
257
|
onItemSelectionToggle: _propTypes.default.func,
|
|
297
258
|
/**
|
|
298
|
-
* Callback fired when
|
|
259
|
+
* Callback fired when Tree Items are selected/deselected.
|
|
299
260
|
* @param {React.SyntheticEvent} event The DOM event that triggered the change.
|
|
300
261
|
* @param {string[] | string} itemIds The ids of the selected items.
|
|
301
262
|
* When `multiSelect` is `true`, this is an array of strings; when false (default) a string.
|
|
@@ -60,7 +60,7 @@ const SimpleTreeView = exports.SimpleTreeView = /*#__PURE__*/React.forwardRef(fu
|
|
|
60
60
|
const ownerState = props;
|
|
61
61
|
if (process.env.NODE_ENV !== 'production') {
|
|
62
62
|
if (props.items != null) {
|
|
63
|
-
(0, _warning.warnOnce)(['MUI X: The
|
|
63
|
+
(0, _warning.warnOnce)(['MUI X: The Simple Tree View component does not support the `items` prop.', 'If you want to add items, you need to pass them as JSX children.', 'Check the documentation for more details: https://mui.com/x/react-tree-view/simple-tree-view/items/.']);
|
|
64
64
|
}
|
|
65
65
|
}
|
|
66
66
|
const {
|
|
@@ -111,7 +111,7 @@ process.env.NODE_ENV !== "production" ? SimpleTreeView.propTypes = {
|
|
|
111
111
|
})
|
|
112
112
|
}),
|
|
113
113
|
/**
|
|
114
|
-
* If `true`, the
|
|
114
|
+
* If `true`, the Tree View renders a checkbox at the left of its label that allows selecting it.
|
|
115
115
|
* @default false
|
|
116
116
|
*/
|
|
117
117
|
checkboxSelection: _propTypes.default.bool,
|
|
@@ -181,39 +181,39 @@ process.env.NODE_ENV !== "production" ? SimpleTreeView.propTypes = {
|
|
|
181
181
|
*/
|
|
182
182
|
multiSelect: _propTypes.default.bool,
|
|
183
183
|
/**
|
|
184
|
-
* Callback fired when
|
|
184
|
+
* Callback fired when Tree Items are expanded/collapsed.
|
|
185
185
|
* @param {React.SyntheticEvent} event The DOM event that triggered the change.
|
|
186
186
|
* @param {array} itemIds The ids of the expanded items.
|
|
187
187
|
*/
|
|
188
188
|
onExpandedItemsChange: _propTypes.default.func,
|
|
189
189
|
/**
|
|
190
|
-
* Callback fired when the `content` slot of a given
|
|
190
|
+
* Callback fired when the `content` slot of a given Tree Item is clicked.
|
|
191
191
|
* @param {React.MouseEvent} event The DOM event that triggered the change.
|
|
192
192
|
* @param {string} itemId The id of the focused item.
|
|
193
193
|
*/
|
|
194
194
|
onItemClick: _propTypes.default.func,
|
|
195
195
|
/**
|
|
196
|
-
* Callback fired when a
|
|
196
|
+
* Callback fired when a Tree Item is expanded or collapsed.
|
|
197
197
|
* @param {React.SyntheticEvent} event The DOM event that triggered the change.
|
|
198
198
|
* @param {array} itemId The itemId of the modified item.
|
|
199
199
|
* @param {array} isExpanded `true` if the item has just been expanded, `false` if it has just been collapsed.
|
|
200
200
|
*/
|
|
201
201
|
onItemExpansionToggle: _propTypes.default.func,
|
|
202
202
|
/**
|
|
203
|
-
* Callback fired when a given
|
|
203
|
+
* Callback fired when a given Tree Item is focused.
|
|
204
204
|
* @param {React.SyntheticEvent | null} event The DOM event that triggered the change. **Warning**: This is a generic event not a focus event.
|
|
205
205
|
* @param {string} itemId The id of the focused item.
|
|
206
206
|
*/
|
|
207
207
|
onItemFocus: _propTypes.default.func,
|
|
208
208
|
/**
|
|
209
|
-
* Callback fired when a
|
|
209
|
+
* Callback fired when a Tree Item is selected or deselected.
|
|
210
210
|
* @param {React.SyntheticEvent} event The DOM event that triggered the change.
|
|
211
211
|
* @param {array} itemId The itemId of the modified item.
|
|
212
212
|
* @param {array} isSelected `true` if the item has just been selected, `false` if it has just been deselected.
|
|
213
213
|
*/
|
|
214
214
|
onItemSelectionToggle: _propTypes.default.func,
|
|
215
215
|
/**
|
|
216
|
-
* Callback fired when
|
|
216
|
+
* Callback fired when Tree Items are selected/deselected.
|
|
217
217
|
* @param {React.SyntheticEvent} event The DOM event that triggered the change.
|
|
218
218
|
* @param {string[] | string} itemIds The ids of the selected items.
|
|
219
219
|
* When `multiSelect` is `true`, this is an array of strings; when false (default) a string.
|
|
@@ -22,6 +22,7 @@ var _resolveComponentProps = _interopRequireDefault(require("@mui/utils/resolveC
|
|
|
22
22
|
var _useSlotProps4 = _interopRequireDefault(require("@mui/utils/useSlotProps"));
|
|
23
23
|
var _unsupportedProp = _interopRequireDefault(require("@mui/utils/unsupportedProp"));
|
|
24
24
|
var _elementTypeAcceptingRef = _interopRequireDefault(require("@mui/utils/elementTypeAcceptingRef"));
|
|
25
|
+
var _warning = require("@mui/x-internals/warning");
|
|
25
26
|
var _zeroStyled = require("../internals/zero-styled");
|
|
26
27
|
var _TreeItemContent = require("./TreeItemContent");
|
|
27
28
|
var _treeItemClasses = require("./treeItemClasses");
|
|
@@ -188,7 +189,7 @@ const TreeItem = exports.TreeItem = /*#__PURE__*/React.forwardRef(function TreeI
|
|
|
188
189
|
indentationAtItemLevel
|
|
189
190
|
},
|
|
190
191
|
selection: {
|
|
191
|
-
|
|
192
|
+
disableSelection
|
|
192
193
|
},
|
|
193
194
|
expansion: {
|
|
194
195
|
expansionTrigger
|
|
@@ -227,6 +228,15 @@ const TreeItem = exports.TreeItem = /*#__PURE__*/React.forwardRef(function TreeI
|
|
|
227
228
|
handleCancelItemLabelEditing,
|
|
228
229
|
handleSaveItemLabel
|
|
229
230
|
} = (0, _useTreeItemState.useTreeItemState)(itemId);
|
|
231
|
+
if (process.env.NODE_ENV !== 'production') {
|
|
232
|
+
// Checking directly the `props` to avoid having the default value applied
|
|
233
|
+
if (props.ContentComponent) {
|
|
234
|
+
(0, _warning.warnOnce)(['MUI X: The ContentComponent prop of the TreeItem component is deprecated and will be removed in the next major release.', 'You can use the new TreeItem2 component or the new useTreeItem2 hook to customize the rendering of the content.', 'For more detail, see https://mui.com/x/react-tree-view/tree-item-customization/.']);
|
|
235
|
+
}
|
|
236
|
+
if (props.ContentProps) {
|
|
237
|
+
(0, _warning.warnOnce)(['MUI X: The ContentProps prop of the TreeItem component is deprecated and will be removed in the next major release.', 'You can use the new TreeItem2 component or the new useTreeItem2 hook to customize the rendering of the content.', 'For more detail, see https://mui.com/x/react-tree-view/tree-item-customization/.']);
|
|
238
|
+
}
|
|
239
|
+
}
|
|
230
240
|
const {
|
|
231
241
|
contentRef,
|
|
232
242
|
rootRef,
|
|
@@ -315,17 +325,18 @@ const TreeItem = exports.TreeItem = /*#__PURE__*/React.forwardRef(function TreeI
|
|
|
315
325
|
}),
|
|
316
326
|
iconProps = (0, _objectWithoutPropertiesLoose2.default)(_useSlotProps3, _excluded4);
|
|
317
327
|
const icon = Icon ? /*#__PURE__*/(0, _jsxRuntime.jsx)(Icon, (0, _extends2.default)({}, iconProps)) : null;
|
|
328
|
+
|
|
329
|
+
// https://www.w3.org/WAI/ARIA/apg/patterns/treeview/
|
|
318
330
|
let ariaSelected;
|
|
319
|
-
if (
|
|
320
|
-
|
|
321
|
-
} else if (selected) {
|
|
322
|
-
/* single-selection trees unset aria-selected on un-selected items.
|
|
323
|
-
*
|
|
324
|
-
* If the tree does not support multiple selection, aria-selected
|
|
325
|
-
* is set to true for the selected item and it is not present on any other item in the tree.
|
|
326
|
-
* Source: https://www.w3.org/WAI/ARIA/apg/patterns/treeview/
|
|
327
|
-
*/
|
|
331
|
+
if (selected) {
|
|
332
|
+
// - each selected node has aria-selected set to true.
|
|
328
333
|
ariaSelected = true;
|
|
334
|
+
} else if (disableSelection || disabled) {
|
|
335
|
+
// - if the tree contains nodes that are not selectable, aria-selected is not present on those nodes.
|
|
336
|
+
ariaSelected = undefined;
|
|
337
|
+
} else {
|
|
338
|
+
// - all nodes that are selectable but not selected have aria-selected set to false.
|
|
339
|
+
ariaSelected = false;
|
|
329
340
|
}
|
|
330
341
|
function handleFocus(event) {
|
|
331
342
|
const canBeFocused = !disabled || disabledItemsFocusable;
|
|
@@ -336,7 +347,7 @@ const TreeItem = exports.TreeItem = /*#__PURE__*/React.forwardRef(function TreeI
|
|
|
336
347
|
function handleBlur(event) {
|
|
337
348
|
onBlur?.(event);
|
|
338
349
|
if (editing ||
|
|
339
|
-
// we can exit the editing state by clicking outside the input (within the
|
|
350
|
+
// we can exit the editing state by clicking outside the input (within the Tree Item) or by pressing Enter or Escape -> we don't want to remove the focused item from the state in these cases
|
|
340
351
|
// we can also exit the editing state by clicking on the root itself -> want to remove the focused item from the state in this case
|
|
341
352
|
event.relatedTarget && (0, _tree.isTargetInDescendants)(event.relatedTarget, rootRefObject.current) && (event.target && event.target?.dataset?.element === 'labelInput' && (0, _tree.isTargetInDescendants)(event.target, rootRefObject.current) || event.relatedTarget?.dataset?.element === 'labelInput')) {
|
|
342
353
|
return;
|
|
@@ -449,11 +460,13 @@ process.env.NODE_ENV !== "production" ? TreeItem.propTypes = {
|
|
|
449
460
|
className: _propTypes.default.string,
|
|
450
461
|
/**
|
|
451
462
|
* The component used to render the content of the item.
|
|
463
|
+
* @deprecated Consider using the `<TreeItem2 />` component or the `useTreeItem2` hook instead. For more details, see https://mui.com/x/react-tree-view/tree-item-customization/.
|
|
452
464
|
* @default TreeItemContent
|
|
453
465
|
*/
|
|
454
466
|
ContentComponent: _elementTypeAcceptingRef.default,
|
|
455
467
|
/**
|
|
456
468
|
* Props applied to ContentComponent.
|
|
469
|
+
* @deprecated Consider using the `<TreeItem2 />` component or the `useTreeItem2` hook instead. For more details, see https://mui.com/x/react-tree-view/tree-item-customization/.
|
|
457
470
|
*/
|
|
458
471
|
ContentProps: _propTypes.default.object,
|
|
459
472
|
/**
|
|
@@ -466,7 +479,7 @@ process.env.NODE_ENV !== "production" ? TreeItem.propTypes = {
|
|
|
466
479
|
*/
|
|
467
480
|
itemId: _propTypes.default.string.isRequired,
|
|
468
481
|
/**
|
|
469
|
-
* The
|
|
482
|
+
* The Tree Item label.
|
|
470
483
|
*/
|
|
471
484
|
label: _propTypes.default.node,
|
|
472
485
|
/**
|