@mui/x-tree-view 7.6.1 → 7.7.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 +147 -0
- package/RichTreeView/RichTreeView.d.ts +1 -3
- package/RichTreeView/RichTreeView.js +12 -15
- package/RichTreeView/RichTreeView.plugins.d.ts +13 -0
- package/RichTreeView/RichTreeView.plugins.js +10 -0
- package/RichTreeView/RichTreeView.types.d.ts +6 -6
- package/RichTreeView/index.d.ts +2 -0
- package/RichTreeView/index.js +1 -1
- package/SimpleTreeView/SimpleTreeView.d.ts +1 -1
- package/SimpleTreeView/SimpleTreeView.js +11 -14
- package/SimpleTreeView/SimpleTreeView.plugins.d.ts +12 -7
- package/SimpleTreeView/SimpleTreeView.plugins.js +8 -2
- package/SimpleTreeView/SimpleTreeView.types.d.ts +3 -3
- package/TreeItem/TreeItem.js +7 -1
- package/TreeItem/TreeItem.types.d.ts +22 -1
- package/TreeItem2/TreeItem2.js +12 -2
- package/TreeItem2/TreeItem2.types.d.ts +10 -1
- package/TreeView/TreeView.js +2 -1
- package/hooks/useTreeViewApiRef.d.ts +1 -1
- package/index.js +1 -1
- package/internals/TreeViewProvider/TreeViewContext.d.ts +2 -2
- package/internals/TreeViewProvider/TreeViewProvider.d.ts +1 -1
- package/internals/TreeViewProvider/TreeViewProvider.types.d.ts +10 -9
- package/internals/TreeViewProvider/index.d.ts +1 -1
- package/internals/TreeViewProvider/useTreeViewContext.d.ts +1 -1
- package/internals/corePlugins/corePlugins.d.ts +2 -2
- package/internals/corePlugins/index.d.ts +1 -1
- package/internals/hooks/useInstanceEventHandler.d.ts +2 -2
- package/internals/index.d.ts +1 -5
- package/internals/index.js +1 -3
- package/internals/models/helpers.d.ts +3 -16
- package/internals/models/plugin.d.ts +9 -9
- package/internals/models/treeView.d.ts +5 -4
- package/internals/plugins/useTreeViewKeyboardNavigation/useTreeViewKeyboardNavigation.js +4 -5
- package/internals/useTreeView/extractPluginParamsFromProps.d.ts +13 -0
- package/internals/{utils → useTreeView}/extractPluginParamsFromProps.js +16 -16
- package/internals/useTreeView/index.d.ts +0 -1
- package/internals/useTreeView/useTreeView.d.ts +4 -4
- package/internals/useTreeView/useTreeView.js +85 -72
- package/internals/useTreeView/useTreeView.types.d.ts +13 -12
- package/internals/useTreeView/useTreeViewModels.d.ts +3 -2
- package/internals/utils/publishTreeViewEvent.d.ts +1 -1
- package/internals/zero-styled/index.d.ts +3 -0
- package/internals/zero-styled/index.js +7 -0
- package/modern/RichTreeView/RichTreeView.js +12 -15
- package/modern/RichTreeView/RichTreeView.plugins.js +10 -0
- package/modern/RichTreeView/index.js +1 -1
- package/modern/SimpleTreeView/SimpleTreeView.js +11 -14
- package/modern/SimpleTreeView/SimpleTreeView.plugins.js +8 -2
- package/modern/TreeItem/TreeItem.js +7 -1
- package/modern/TreeItem2/TreeItem2.js +12 -2
- package/modern/TreeView/TreeView.js +2 -1
- package/modern/index.js +1 -1
- package/modern/internals/index.js +1 -3
- package/modern/internals/plugins/useTreeViewKeyboardNavigation/useTreeViewKeyboardNavigation.js +4 -5
- package/modern/internals/{utils → useTreeView}/extractPluginParamsFromProps.js +16 -16
- package/modern/internals/useTreeView/useTreeView.js +85 -72
- package/modern/internals/zero-styled/index.js +7 -0
- package/node/RichTreeView/RichTreeView.js +14 -17
- package/node/RichTreeView/RichTreeView.plugins.js +16 -0
- package/node/RichTreeView/index.js +13 -1
- package/node/SimpleTreeView/SimpleTreeView.js +13 -16
- package/node/SimpleTreeView/SimpleTreeView.plugins.js +8 -2
- package/node/TreeItem/TreeItem.js +10 -4
- package/node/TreeItem2/TreeItem2.js +18 -8
- package/node/TreeView/TreeView.js +4 -3
- package/node/index.js +1 -1
- package/node/internals/index.js +1 -15
- package/node/internals/plugins/useTreeViewKeyboardNavigation/useTreeViewKeyboardNavigation.js +4 -5
- package/node/internals/{utils → useTreeView}/extractPluginParamsFromProps.js +16 -16
- package/node/internals/useTreeView/useTreeView.js +85 -72
- package/node/internals/zero-styled/index.js +17 -0
- package/package.json +2 -2
- package/useTreeItem2/useTreeItem2.d.ts +2 -2
- package/useTreeItem2/useTreeItem2.types.d.ts +14 -2
- package/internals/plugins/defaultPlugins.d.ts +0 -13
- package/internals/plugins/defaultPlugins.js +0 -10
- package/internals/plugins/index.d.ts +0 -2
- package/internals/plugins/index.js +0 -1
- package/internals/utils/extractPluginParamsFromProps.d.ts +0 -18
- package/modern/internals/plugins/defaultPlugins.js +0 -10
- package/modern/internals/plugins/index.js +0 -1
- package/node/internals/plugins/defaultPlugins.js +0 -16
- package/node/internals/plugins/index.js +0 -12
|
@@ -1,17 +1,17 @@
|
|
|
1
1
|
import _extends from "@babel/runtime/helpers/esm/extends";
|
|
2
2
|
import * as React from 'react';
|
|
3
3
|
import PropTypes from 'prop-types';
|
|
4
|
-
import { styled, useThemeProps } from '@mui/material/styles';
|
|
5
4
|
import composeClasses from '@mui/utils/composeClasses';
|
|
6
5
|
import { useSlotProps } from '@mui/base/utils';
|
|
7
6
|
import { getRichTreeViewUtilityClass } from './richTreeViewClasses';
|
|
7
|
+
import { styled, createUseThemeProps } from '../internals/zero-styled';
|
|
8
8
|
import { useTreeView } from '../internals/useTreeView';
|
|
9
9
|
import { TreeViewProvider } from '../internals/TreeViewProvider';
|
|
10
|
-
import {
|
|
10
|
+
import { RICH_TREE_VIEW_PLUGINS } from './RichTreeView.plugins';
|
|
11
11
|
import { TreeItem } from '../TreeItem';
|
|
12
12
|
import { buildWarning } from '../internals/utils/warning';
|
|
13
|
-
import { extractPluginParamsFromProps } from '../internals/utils/extractPluginParamsFromProps';
|
|
14
13
|
import { jsx as _jsx } from "react/jsx-runtime";
|
|
14
|
+
const useThemeProps = createUseThemeProps('MuiRichTreeView');
|
|
15
15
|
const useUtilityClasses = ownerState => {
|
|
16
16
|
const {
|
|
17
17
|
classes
|
|
@@ -80,27 +80,24 @@ const RichTreeView = /*#__PURE__*/React.forwardRef(function RichTreeView(inProps
|
|
|
80
80
|
childrenWarning();
|
|
81
81
|
}
|
|
82
82
|
}
|
|
83
|
-
const {
|
|
84
|
-
pluginParams,
|
|
85
|
-
slots,
|
|
86
|
-
slotProps,
|
|
87
|
-
otherProps
|
|
88
|
-
} = extractPluginParamsFromProps({
|
|
89
|
-
props,
|
|
90
|
-
plugins: DEFAULT_TREE_VIEW_PLUGINS,
|
|
91
|
-
rootRef: ref
|
|
92
|
-
});
|
|
93
83
|
const {
|
|
94
84
|
getRootProps,
|
|
95
85
|
contextValue,
|
|
96
86
|
instance
|
|
97
|
-
} = useTreeView(
|
|
87
|
+
} = useTreeView({
|
|
88
|
+
plugins: RICH_TREE_VIEW_PLUGINS,
|
|
89
|
+
rootRef: ref,
|
|
90
|
+
props
|
|
91
|
+
});
|
|
92
|
+
const {
|
|
93
|
+
slots,
|
|
94
|
+
slotProps
|
|
95
|
+
} = props;
|
|
98
96
|
const classes = useUtilityClasses(props);
|
|
99
97
|
const Root = slots?.root ?? RichTreeViewRoot;
|
|
100
98
|
const rootProps = useSlotProps({
|
|
101
99
|
elementType: Root,
|
|
102
100
|
externalSlotProps: slotProps?.root,
|
|
103
|
-
externalForwardedProps: otherProps,
|
|
104
101
|
className: classes.root,
|
|
105
102
|
getSlotProps: getRootProps,
|
|
106
103
|
ownerState: props
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { useTreeViewId } from '../internals/plugins/useTreeViewId';
|
|
2
|
+
import { useTreeViewItems } from '../internals/plugins/useTreeViewItems';
|
|
3
|
+
import { useTreeViewExpansion } from '../internals/plugins/useTreeViewExpansion';
|
|
4
|
+
import { useTreeViewSelection } from '../internals/plugins/useTreeViewSelection';
|
|
5
|
+
import { useTreeViewFocus } from '../internals/plugins/useTreeViewFocus';
|
|
6
|
+
import { useTreeViewKeyboardNavigation } from '../internals/plugins/useTreeViewKeyboardNavigation';
|
|
7
|
+
import { useTreeViewIcons } from '../internals/plugins/useTreeViewIcons';
|
|
8
|
+
export const RICH_TREE_VIEW_PLUGINS = [useTreeViewId, useTreeViewItems, useTreeViewExpansion, useTreeViewSelection, useTreeViewFocus, useTreeViewKeyboardNavigation, useTreeViewIcons];
|
|
9
|
+
|
|
10
|
+
// We can't infer this type from the plugin, otherwise we would lose the generics.
|
|
@@ -1,16 +1,16 @@
|
|
|
1
1
|
import _extends from "@babel/runtime/helpers/esm/extends";
|
|
2
2
|
import * as React from 'react';
|
|
3
3
|
import PropTypes from 'prop-types';
|
|
4
|
-
import { styled, useThemeProps } from '@mui/material/styles';
|
|
5
4
|
import composeClasses from '@mui/utils/composeClasses';
|
|
6
5
|
import { useSlotProps } from '@mui/base/utils';
|
|
6
|
+
import { styled, createUseThemeProps } from '../internals/zero-styled';
|
|
7
7
|
import { getSimpleTreeViewUtilityClass } from './simpleTreeViewClasses';
|
|
8
8
|
import { useTreeView } from '../internals/useTreeView';
|
|
9
9
|
import { TreeViewProvider } from '../internals/TreeViewProvider';
|
|
10
10
|
import { SIMPLE_TREE_VIEW_PLUGINS } from './SimpleTreeView.plugins';
|
|
11
11
|
import { buildWarning } from '../internals/utils/warning';
|
|
12
|
-
import { extractPluginParamsFromProps } from '../internals/utils/extractPluginParamsFromProps';
|
|
13
12
|
import { jsx as _jsx } from "react/jsx-runtime";
|
|
13
|
+
const useThemeProps = createUseThemeProps('MuiSimpleTreeView');
|
|
14
14
|
const useUtilityClasses = ownerState => {
|
|
15
15
|
const {
|
|
16
16
|
classes
|
|
@@ -56,27 +56,24 @@ const SimpleTreeView = /*#__PURE__*/React.forwardRef(function SimpleTreeView(inP
|
|
|
56
56
|
}
|
|
57
57
|
}
|
|
58
58
|
const {
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
59
|
+
getRootProps,
|
|
60
|
+
contextValue
|
|
61
|
+
} = useTreeView({
|
|
62
|
+
plugins: SIMPLE_TREE_VIEW_PLUGINS,
|
|
63
|
+
rootRef: ref,
|
|
64
64
|
props: _extends({}, props, {
|
|
65
65
|
items: EMPTY_ITEMS
|
|
66
|
-
})
|
|
67
|
-
plugins: SIMPLE_TREE_VIEW_PLUGINS,
|
|
68
|
-
rootRef: ref
|
|
66
|
+
})
|
|
69
67
|
});
|
|
70
68
|
const {
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
} =
|
|
69
|
+
slots,
|
|
70
|
+
slotProps
|
|
71
|
+
} = props;
|
|
74
72
|
const classes = useUtilityClasses(props);
|
|
75
73
|
const Root = slots?.root ?? SimpleTreeViewRoot;
|
|
76
74
|
const rootProps = useSlotProps({
|
|
77
75
|
elementType: Root,
|
|
78
76
|
externalSlotProps: slotProps?.root,
|
|
79
|
-
externalForwardedProps: otherProps,
|
|
80
77
|
className: classes.root,
|
|
81
78
|
getSlotProps: getRootProps,
|
|
82
79
|
ownerState
|
|
@@ -1,5 +1,11 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { useTreeViewId } from '../internals/plugins/useTreeViewId';
|
|
2
|
+
import { useTreeViewItems } from '../internals/plugins/useTreeViewItems';
|
|
3
|
+
import { useTreeViewExpansion } from '../internals/plugins/useTreeViewExpansion';
|
|
4
|
+
import { useTreeViewSelection } from '../internals/plugins/useTreeViewSelection';
|
|
5
|
+
import { useTreeViewFocus } from '../internals/plugins/useTreeViewFocus';
|
|
6
|
+
import { useTreeViewKeyboardNavigation } from '../internals/plugins/useTreeViewKeyboardNavigation';
|
|
7
|
+
import { useTreeViewIcons } from '../internals/plugins/useTreeViewIcons';
|
|
2
8
|
import { useTreeViewJSXItems } from '../internals/plugins/useTreeViewJSXItems';
|
|
3
|
-
export const SIMPLE_TREE_VIEW_PLUGINS = [
|
|
9
|
+
export const SIMPLE_TREE_VIEW_PLUGINS = [useTreeViewId, useTreeViewItems, useTreeViewExpansion, useTreeViewSelection, useTreeViewFocus, useTreeViewKeyboardNavigation, useTreeViewIcons, useTreeViewJSXItems];
|
|
4
10
|
|
|
5
11
|
// We can't infer this type from the plugin, otherwise we would lose the generics.
|
|
@@ -11,10 +11,11 @@ import Collapse from '@mui/material/Collapse';
|
|
|
11
11
|
import { resolveComponentProps, useSlotProps } from '@mui/base/utils';
|
|
12
12
|
import useForkRef from '@mui/utils/useForkRef';
|
|
13
13
|
import { shouldForwardProp } from '@mui/system/createStyled';
|
|
14
|
-
import { alpha
|
|
14
|
+
import { alpha } from '@mui/material/styles';
|
|
15
15
|
import unsupportedProp from '@mui/utils/unsupportedProp';
|
|
16
16
|
import elementTypeAcceptingRef from '@mui/utils/elementTypeAcceptingRef';
|
|
17
17
|
import { unstable_composeClasses as composeClasses } from '@mui/base';
|
|
18
|
+
import { styled, createUseThemeProps } from '../internals/zero-styled';
|
|
18
19
|
import { TreeItemContent } from './TreeItemContent';
|
|
19
20
|
import { treeItemClasses, getTreeItemUtilityClass } from './treeItemClasses';
|
|
20
21
|
import { useTreeViewContext } from '../internals/TreeViewProvider/useTreeViewContext';
|
|
@@ -22,6 +23,7 @@ import { TreeViewCollapseIcon, TreeViewExpandIcon } from '../icons';
|
|
|
22
23
|
import { TreeItem2Provider } from '../TreeItem2Provider';
|
|
23
24
|
import { TreeViewItemDepthContext } from '../internals/TreeViewItemDepthContext';
|
|
24
25
|
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
26
|
+
const useThemeProps = createUseThemeProps('MuiTreeItem');
|
|
25
27
|
const useUtilityClasses = ownerState => {
|
|
26
28
|
const {
|
|
27
29
|
classes
|
|
@@ -390,6 +392,10 @@ process.env.NODE_ENV !== "production" ? TreeItem.propTypes = {
|
|
|
390
392
|
* Use the `onItemFocus` callback on the tree if you need to monitor a item's focus.
|
|
391
393
|
*/
|
|
392
394
|
onFocus: unsupportedProp,
|
|
395
|
+
/**
|
|
396
|
+
* Callback fired when a key of the keyboard is pressed on the item.
|
|
397
|
+
*/
|
|
398
|
+
onKeyDown: PropTypes.func,
|
|
393
399
|
/**
|
|
394
400
|
* The props used for each component slot.
|
|
395
401
|
* @default {}
|
|
@@ -6,17 +6,19 @@ import * as React from 'react';
|
|
|
6
6
|
import PropTypes from 'prop-types';
|
|
7
7
|
import clsx from 'clsx';
|
|
8
8
|
import unsupportedProp from '@mui/utils/unsupportedProp';
|
|
9
|
-
import { alpha
|
|
9
|
+
import { alpha } from '@mui/material/styles';
|
|
10
10
|
import Collapse from '@mui/material/Collapse';
|
|
11
11
|
import MuiCheckbox from '@mui/material/Checkbox';
|
|
12
12
|
import { useSlotProps } from '@mui/base/utils';
|
|
13
13
|
import { shouldForwardProp } from '@mui/system/createStyled';
|
|
14
14
|
import composeClasses from '@mui/utils/composeClasses';
|
|
15
|
+
import { styled, createUseThemeProps } from '../internals/zero-styled';
|
|
15
16
|
import { unstable_useTreeItem2 as useTreeItem2 } from '../useTreeItem2';
|
|
16
17
|
import { getTreeItemUtilityClass } from '../TreeItem';
|
|
17
18
|
import { TreeItem2Icon } from '../TreeItem2Icon';
|
|
18
19
|
import { TreeItem2Provider } from '../TreeItem2Provider';
|
|
19
20
|
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
21
|
+
const useThemeProps = createUseThemeProps('MuiTreeItem2');
|
|
20
22
|
export const TreeItem2Root = styled('li', {
|
|
21
23
|
name: 'MuiTreeItem2',
|
|
22
24
|
slot: 'Root',
|
|
@@ -321,11 +323,19 @@ process.env.NODE_ENV !== "production" ? TreeItem2.propTypes = {
|
|
|
321
323
|
* The label of the item.
|
|
322
324
|
*/
|
|
323
325
|
label: PropTypes.node,
|
|
326
|
+
/**
|
|
327
|
+
* Callback fired when the item root is blurred.
|
|
328
|
+
*/
|
|
329
|
+
onBlur: PropTypes.func,
|
|
324
330
|
/**
|
|
325
331
|
* This prop isn't supported.
|
|
326
|
-
* Use the `onItemFocus` callback on the tree if you need to monitor
|
|
332
|
+
* Use the `onItemFocus` callback on the tree if you need to monitor an item's focus.
|
|
327
333
|
*/
|
|
328
334
|
onFocus: unsupportedProp,
|
|
335
|
+
/**
|
|
336
|
+
* Callback fired when a key is pressed on the keyboard and the tree is in focus.
|
|
337
|
+
*/
|
|
338
|
+
onKeyDown: PropTypes.func,
|
|
329
339
|
/**
|
|
330
340
|
* The props used for each component slot.
|
|
331
341
|
* @default {}
|
|
@@ -1,11 +1,12 @@
|
|
|
1
1
|
import _extends from "@babel/runtime/helpers/esm/extends";
|
|
2
2
|
import * as React from 'react';
|
|
3
3
|
import PropTypes from 'prop-types';
|
|
4
|
-
import { styled, useThemeProps } from '@mui/material/styles';
|
|
5
4
|
import composeClasses from '@mui/utils/composeClasses';
|
|
5
|
+
import { styled, createUseThemeProps } from '../internals/zero-styled';
|
|
6
6
|
import { getTreeViewUtilityClass } from './treeViewClasses';
|
|
7
7
|
import { SimpleTreeView, SimpleTreeViewRoot } from '../SimpleTreeView';
|
|
8
8
|
import { jsx as _jsx } from "react/jsx-runtime";
|
|
9
|
+
const useThemeProps = createUseThemeProps('MuiTreeView');
|
|
9
10
|
const useUtilityClasses = ownerState => {
|
|
10
11
|
const {
|
|
11
12
|
classes
|
package/modern/index.js
CHANGED
|
@@ -2,7 +2,6 @@ export { useTreeView } from './useTreeView';
|
|
|
2
2
|
export { TreeViewProvider } from './TreeViewProvider';
|
|
3
3
|
export { unstable_resetCleanupTracking } from './hooks/useInstanceEventHandler';
|
|
4
4
|
// Plugins
|
|
5
|
-
export { DEFAULT_TREE_VIEW_PLUGINS } from './plugins/defaultPlugins';
|
|
6
5
|
export { useTreeViewExpansion } from './plugins/useTreeViewExpansion';
|
|
7
6
|
export { useTreeViewSelection } from './plugins/useTreeViewSelection';
|
|
8
7
|
export { useTreeViewFocus } from './plugins/useTreeViewFocus';
|
|
@@ -11,5 +10,4 @@ export { useTreeViewId } from './plugins/useTreeViewId';
|
|
|
11
10
|
export { useTreeViewIcons } from './plugins/useTreeViewIcons';
|
|
12
11
|
export { useTreeViewItems } from './plugins/useTreeViewItems';
|
|
13
12
|
export { useTreeViewJSXItems } from './plugins/useTreeViewJSXItems';
|
|
14
|
-
export { buildWarning } from './utils/warning';
|
|
15
|
-
export { extractPluginParamsFromProps } from './utils/extractPluginParamsFromProps';
|
|
13
|
+
export { buildWarning } from './utils/warning';
|
package/modern/internals/plugins/useTreeViewKeyboardNavigation/useTreeViewKeyboardNavigation.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import * as React from 'react';
|
|
2
|
-
import {
|
|
2
|
+
import { useRtl } from '@mui/system/RtlProvider';
|
|
3
3
|
import useEventCallback from '@mui/utils/useEventCallback';
|
|
4
4
|
import { getFirstNavigableItem, getLastNavigableItem, getNextNavigableItem, getPreviousNavigableItem } from '../../utils/tree';
|
|
5
5
|
function isPrintableCharacter(string) {
|
|
@@ -10,8 +10,7 @@ export const useTreeViewKeyboardNavigation = ({
|
|
|
10
10
|
params,
|
|
11
11
|
state
|
|
12
12
|
}) => {
|
|
13
|
-
const
|
|
14
|
-
const isRTL = theme.direction === 'rtl';
|
|
13
|
+
const isRtl = useRtl();
|
|
15
14
|
const firstCharMap = React.useRef({});
|
|
16
15
|
const updateFirstCharMap = useEventCallback(callback => {
|
|
17
16
|
firstCharMap.current = callback(firstCharMap.current);
|
|
@@ -138,7 +137,7 @@ export const useTreeViewKeyboardNavigation = ({
|
|
|
138
137
|
|
|
139
138
|
// If the focused item is expanded, we move the focus to its first child
|
|
140
139
|
// If the focused item is collapsed and has children, we expand it
|
|
141
|
-
case key === 'ArrowRight' && !
|
|
140
|
+
case key === 'ArrowRight' && !isRtl || key === 'ArrowLeft' && isRtl:
|
|
142
141
|
{
|
|
143
142
|
if (instance.isItemExpanded(itemId)) {
|
|
144
143
|
const nextItemId = getNextNavigableItem(instance, itemId);
|
|
@@ -155,7 +154,7 @@ export const useTreeViewKeyboardNavigation = ({
|
|
|
155
154
|
|
|
156
155
|
// If the focused item is expanded, we collapse it
|
|
157
156
|
// If the focused item is collapsed and has a parent, we move the focus to this parent
|
|
158
|
-
case key === 'ArrowLeft' && !
|
|
157
|
+
case key === 'ArrowLeft' && !isRtl || key === 'ArrowRight' && isRtl:
|
|
159
158
|
{
|
|
160
159
|
if (canToggleItemExpansion(itemId) && instance.isItemExpanded(itemId)) {
|
|
161
160
|
instance.toggleItemExpansion(event, itemId);
|
|
@@ -8,35 +8,35 @@ export const extractPluginParamsFromProps = _ref => {
|
|
|
8
8
|
apiRef,
|
|
9
9
|
experimentalFeatures
|
|
10
10
|
},
|
|
11
|
-
plugins
|
|
12
|
-
rootRef
|
|
11
|
+
plugins
|
|
13
12
|
} = _ref,
|
|
14
13
|
props = _objectWithoutPropertiesLoose(_ref.props, _excluded);
|
|
15
14
|
const paramsLookup = {};
|
|
16
15
|
plugins.forEach(plugin => {
|
|
17
16
|
Object.assign(paramsLookup, plugin.params);
|
|
18
17
|
});
|
|
19
|
-
const pluginParams = {
|
|
20
|
-
|
|
21
|
-
rootRef,
|
|
22
|
-
slots: slots ?? {},
|
|
23
|
-
slotProps: slotProps ?? {},
|
|
24
|
-
experimentalFeatures: experimentalFeatures ?? {},
|
|
25
|
-
apiRef
|
|
26
|
-
};
|
|
27
|
-
const otherProps = {};
|
|
18
|
+
const pluginParams = {};
|
|
19
|
+
const forwardedProps = {};
|
|
28
20
|
Object.keys(props).forEach(propName => {
|
|
29
21
|
const prop = props[propName];
|
|
30
22
|
if (paramsLookup[propName]) {
|
|
31
23
|
pluginParams[propName] = prop;
|
|
32
24
|
} else {
|
|
33
|
-
|
|
25
|
+
forwardedProps[propName] = prop;
|
|
34
26
|
}
|
|
35
27
|
});
|
|
28
|
+
const defaultizedPluginParams = plugins.reduce((acc, plugin) => {
|
|
29
|
+
if (plugin.getDefaultizedParams) {
|
|
30
|
+
return plugin.getDefaultizedParams(acc);
|
|
31
|
+
}
|
|
32
|
+
return acc;
|
|
33
|
+
}, pluginParams);
|
|
36
34
|
return {
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
35
|
+
apiRef,
|
|
36
|
+
forwardedProps,
|
|
37
|
+
pluginParams: defaultizedPluginParams,
|
|
38
|
+
slots: slots ?? {},
|
|
39
|
+
slotProps: slotProps ?? {},
|
|
40
|
+
experimentalFeatures: experimentalFeatures ?? {}
|
|
41
41
|
};
|
|
42
42
|
};
|
|
@@ -3,6 +3,7 @@ import * as React from 'react';
|
|
|
3
3
|
import useForkRef from '@mui/utils/useForkRef';
|
|
4
4
|
import { useTreeViewModels } from './useTreeViewModels';
|
|
5
5
|
import { TREE_VIEW_CORE_PLUGINS } from '../corePlugins';
|
|
6
|
+
import { extractPluginParamsFromProps } from './extractPluginParamsFromProps';
|
|
6
7
|
export function useTreeViewApiInitialization(inputApiRef) {
|
|
7
8
|
const fallbackPublicApiRef = React.useRef({});
|
|
8
9
|
if (inputApiRef) {
|
|
@@ -13,62 +14,69 @@ export function useTreeViewApiInitialization(inputApiRef) {
|
|
|
13
14
|
}
|
|
14
15
|
return fallbackPublicApiRef.current;
|
|
15
16
|
}
|
|
16
|
-
export const useTreeView =
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
17
|
+
export const useTreeView = ({
|
|
18
|
+
plugins: inPlugins,
|
|
19
|
+
rootRef,
|
|
20
|
+
props
|
|
21
|
+
}) => {
|
|
22
|
+
const plugins = [...TREE_VIEW_CORE_PLUGINS, ...inPlugins];
|
|
23
|
+
const {
|
|
24
|
+
pluginParams,
|
|
25
|
+
forwardedProps,
|
|
26
|
+
apiRef,
|
|
27
|
+
experimentalFeatures,
|
|
28
|
+
slots,
|
|
29
|
+
slotProps
|
|
30
|
+
} = extractPluginParamsFromProps({
|
|
31
|
+
plugins,
|
|
32
|
+
props
|
|
33
|
+
});
|
|
34
|
+
const models = useTreeViewModels(plugins, pluginParams);
|
|
25
35
|
const instanceRef = React.useRef({});
|
|
26
36
|
const instance = instanceRef.current;
|
|
27
|
-
const publicAPI = useTreeViewApiInitialization(
|
|
37
|
+
const publicAPI = useTreeViewApiInitialization(apiRef);
|
|
28
38
|
const innerRootRef = React.useRef(null);
|
|
29
|
-
const handleRootRef = useForkRef(innerRootRef,
|
|
39
|
+
const handleRootRef = useForkRef(innerRootRef, rootRef);
|
|
30
40
|
const [state, setState] = React.useState(() => {
|
|
31
41
|
const temp = {};
|
|
32
42
|
plugins.forEach(plugin => {
|
|
33
43
|
if (plugin.getInitialState) {
|
|
34
|
-
Object.assign(temp, plugin.getInitialState(
|
|
44
|
+
Object.assign(temp, plugin.getInitialState(pluginParams));
|
|
35
45
|
}
|
|
36
46
|
});
|
|
37
47
|
return temp;
|
|
38
48
|
});
|
|
39
|
-
const
|
|
40
|
-
const
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
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;
|
|
44
63
|
};
|
|
45
|
-
const
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
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
|
+
});
|
|
56
76
|
});
|
|
57
|
-
|
|
58
|
-
rootPropsGetters.push(pluginResponse.getRootProps);
|
|
59
|
-
}
|
|
60
|
-
if (pluginResponse.publicAPI) {
|
|
61
|
-
Object.assign(publicAPI, pluginResponse.publicAPI);
|
|
62
|
-
}
|
|
63
|
-
if (pluginResponse.instance) {
|
|
64
|
-
Object.assign(instance, pluginResponse.instance);
|
|
65
|
-
}
|
|
66
|
-
if (pluginResponse.contextValue) {
|
|
67
|
-
Object.assign(contextValue, pluginResponse.contextValue);
|
|
68
|
-
}
|
|
77
|
+
return finalChildren;
|
|
69
78
|
};
|
|
70
|
-
|
|
71
|
-
contextValue.runItemPlugins = itemPluginProps => {
|
|
79
|
+
const runItemPlugins = itemPluginProps => {
|
|
72
80
|
let finalRootRef = null;
|
|
73
81
|
let finalContentRef = null;
|
|
74
82
|
plugins.forEach(plugin => {
|
|
@@ -92,40 +100,45 @@ export const useTreeView = inParams => {
|
|
|
92
100
|
rootRef: finalRootRef
|
|
93
101
|
};
|
|
94
102
|
};
|
|
95
|
-
const
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
finalChildren = itemWrapper({
|
|
103
|
-
itemId,
|
|
104
|
-
children: finalChildren,
|
|
105
|
-
instance
|
|
106
|
-
});
|
|
107
|
-
});
|
|
108
|
-
return finalChildren;
|
|
103
|
+
const contextValue = {
|
|
104
|
+
publicAPI,
|
|
105
|
+
wrapItem,
|
|
106
|
+
wrapRoot,
|
|
107
|
+
runItemPlugins,
|
|
108
|
+
instance: instance,
|
|
109
|
+
rootRef: innerRootRef
|
|
109
110
|
};
|
|
110
|
-
const
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
111
|
+
const rootPropsGetters = [];
|
|
112
|
+
const runPlugin = plugin => {
|
|
113
|
+
const pluginResponse = plugin({
|
|
114
|
+
instance,
|
|
115
|
+
params: pluginParams,
|
|
116
|
+
slots,
|
|
117
|
+
slotProps,
|
|
118
|
+
experimentalFeatures,
|
|
119
|
+
state,
|
|
120
|
+
setState,
|
|
121
|
+
rootRef: innerRootRef,
|
|
122
|
+
models
|
|
122
123
|
});
|
|
123
|
-
|
|
124
|
+
if (pluginResponse.getRootProps) {
|
|
125
|
+
rootPropsGetters.push(pluginResponse.getRootProps);
|
|
126
|
+
}
|
|
127
|
+
if (pluginResponse.publicAPI) {
|
|
128
|
+
Object.assign(publicAPI, pluginResponse.publicAPI);
|
|
129
|
+
}
|
|
130
|
+
if (pluginResponse.instance) {
|
|
131
|
+
Object.assign(instance, pluginResponse.instance);
|
|
132
|
+
}
|
|
133
|
+
if (pluginResponse.contextValue) {
|
|
134
|
+
Object.assign(contextValue, pluginResponse.contextValue);
|
|
135
|
+
}
|
|
124
136
|
};
|
|
137
|
+
plugins.forEach(runPlugin);
|
|
125
138
|
const getRootProps = (otherHandlers = {}) => {
|
|
126
139
|
const rootProps = _extends({
|
|
127
140
|
role: 'tree'
|
|
128
|
-
}, otherHandlers, {
|
|
141
|
+
}, forwardedProps, otherHandlers, {
|
|
129
142
|
ref: handleRootRef
|
|
130
143
|
});
|
|
131
144
|
rootPropsGetters.forEach(rootPropsGetter => {
|
|
@@ -136,7 +149,7 @@ export const useTreeView = inParams => {
|
|
|
136
149
|
return {
|
|
137
150
|
getRootProps,
|
|
138
151
|
rootRef: handleRootRef,
|
|
139
|
-
contextValue
|
|
140
|
-
instance
|
|
152
|
+
contextValue,
|
|
153
|
+
instance
|
|
141
154
|
};
|
|
142
155
|
};
|
|
@@ -8,19 +8,19 @@ exports.RichTreeViewRoot = exports.RichTreeView = void 0;
|
|
|
8
8
|
var _extends2 = _interopRequireDefault(require("@babel/runtime/helpers/extends"));
|
|
9
9
|
var React = _interopRequireWildcard(require("react"));
|
|
10
10
|
var _propTypes = _interopRequireDefault(require("prop-types"));
|
|
11
|
-
var _styles = require("@mui/material/styles");
|
|
12
11
|
var _composeClasses = _interopRequireDefault(require("@mui/utils/composeClasses"));
|
|
13
12
|
var _utils = require("@mui/base/utils");
|
|
14
13
|
var _richTreeViewClasses = require("./richTreeViewClasses");
|
|
14
|
+
var _zeroStyled = require("../internals/zero-styled");
|
|
15
15
|
var _useTreeView = require("../internals/useTreeView");
|
|
16
16
|
var _TreeViewProvider = require("../internals/TreeViewProvider");
|
|
17
|
-
var
|
|
17
|
+
var _RichTreeView = require("./RichTreeView.plugins");
|
|
18
18
|
var _TreeItem = require("../TreeItem");
|
|
19
19
|
var _warning = require("../internals/utils/warning");
|
|
20
|
-
var _extractPluginParamsFromProps = require("../internals/utils/extractPluginParamsFromProps");
|
|
21
20
|
var _jsxRuntime = require("react/jsx-runtime");
|
|
22
21
|
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); }
|
|
23
22
|
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; }
|
|
23
|
+
const useThemeProps = (0, _zeroStyled.createUseThemeProps)('MuiRichTreeView');
|
|
24
24
|
const useUtilityClasses = ownerState => {
|
|
25
25
|
const {
|
|
26
26
|
classes
|
|
@@ -30,7 +30,7 @@ const useUtilityClasses = ownerState => {
|
|
|
30
30
|
};
|
|
31
31
|
return (0, _composeClasses.default)(slots, _richTreeViewClasses.getRichTreeViewUtilityClass, classes);
|
|
32
32
|
};
|
|
33
|
-
const RichTreeViewRoot = exports.RichTreeViewRoot = (0,
|
|
33
|
+
const RichTreeViewRoot = exports.RichTreeViewRoot = (0, _zeroStyled.styled)('ul', {
|
|
34
34
|
name: 'MuiRichTreeView',
|
|
35
35
|
slot: 'Root',
|
|
36
36
|
overridesResolver: (props, styles) => styles.root
|
|
@@ -80,7 +80,7 @@ const childrenWarning = (0, _warning.buildWarning)(['MUI X: The `RichTreeView` c
|
|
|
80
80
|
* - [RichTreeView API](https://mui.com/x/api/tree-view/rich-tree-view/)
|
|
81
81
|
*/
|
|
82
82
|
const RichTreeView = exports.RichTreeView = /*#__PURE__*/React.forwardRef(function RichTreeView(inProps, ref) {
|
|
83
|
-
const props =
|
|
83
|
+
const props = useThemeProps({
|
|
84
84
|
props: inProps,
|
|
85
85
|
name: 'MuiRichTreeView'
|
|
86
86
|
});
|
|
@@ -89,27 +89,24 @@ const RichTreeView = exports.RichTreeView = /*#__PURE__*/React.forwardRef(functi
|
|
|
89
89
|
childrenWarning();
|
|
90
90
|
}
|
|
91
91
|
}
|
|
92
|
-
const {
|
|
93
|
-
pluginParams,
|
|
94
|
-
slots,
|
|
95
|
-
slotProps,
|
|
96
|
-
otherProps
|
|
97
|
-
} = (0, _extractPluginParamsFromProps.extractPluginParamsFromProps)({
|
|
98
|
-
props,
|
|
99
|
-
plugins: _plugins.DEFAULT_TREE_VIEW_PLUGINS,
|
|
100
|
-
rootRef: ref
|
|
101
|
-
});
|
|
102
92
|
const {
|
|
103
93
|
getRootProps,
|
|
104
94
|
contextValue,
|
|
105
95
|
instance
|
|
106
|
-
} = (0, _useTreeView.useTreeView)(
|
|
96
|
+
} = (0, _useTreeView.useTreeView)({
|
|
97
|
+
plugins: _RichTreeView.RICH_TREE_VIEW_PLUGINS,
|
|
98
|
+
rootRef: ref,
|
|
99
|
+
props
|
|
100
|
+
});
|
|
101
|
+
const {
|
|
102
|
+
slots,
|
|
103
|
+
slotProps
|
|
104
|
+
} = props;
|
|
107
105
|
const classes = useUtilityClasses(props);
|
|
108
106
|
const Root = slots?.root ?? RichTreeViewRoot;
|
|
109
107
|
const rootProps = (0, _utils.useSlotProps)({
|
|
110
108
|
elementType: Root,
|
|
111
109
|
externalSlotProps: slotProps?.root,
|
|
112
|
-
externalForwardedProps: otherProps,
|
|
113
110
|
className: classes.root,
|
|
114
111
|
getSlotProps: getRootProps,
|
|
115
112
|
ownerState: props
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.RICH_TREE_VIEW_PLUGINS = void 0;
|
|
7
|
+
var _useTreeViewId = require("../internals/plugins/useTreeViewId");
|
|
8
|
+
var _useTreeViewItems = require("../internals/plugins/useTreeViewItems");
|
|
9
|
+
var _useTreeViewExpansion = require("../internals/plugins/useTreeViewExpansion");
|
|
10
|
+
var _useTreeViewSelection = require("../internals/plugins/useTreeViewSelection");
|
|
11
|
+
var _useTreeViewFocus = require("../internals/plugins/useTreeViewFocus");
|
|
12
|
+
var _useTreeViewKeyboardNavigation = require("../internals/plugins/useTreeViewKeyboardNavigation");
|
|
13
|
+
var _useTreeViewIcons = require("../internals/plugins/useTreeViewIcons");
|
|
14
|
+
const RICH_TREE_VIEW_PLUGINS = exports.RICH_TREE_VIEW_PLUGINS = [_useTreeViewId.useTreeViewId, _useTreeViewItems.useTreeViewItems, _useTreeViewExpansion.useTreeViewExpansion, _useTreeViewSelection.useTreeViewSelection, _useTreeViewFocus.useTreeViewFocus, _useTreeViewKeyboardNavigation.useTreeViewKeyboardNavigation, _useTreeViewIcons.useTreeViewIcons];
|
|
15
|
+
|
|
16
|
+
// We can't infer this type from the plugin, otherwise we would lose the generics.
|