@mui/x-tree-view 7.6.2 → 7.7.1
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 +163 -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 +9 -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 +7 -2
- package/SimpleTreeView/SimpleTreeView.types.d.ts +3 -3
- package/TreeItem/TreeItem.js +7 -1
- package/TreeItem/TreeItem.types.d.ts +27 -1
- package/TreeItem2/TreeItem2.js +12 -2
- package/TreeItem2/TreeItem2.types.d.ts +10 -1
- package/TreeView/TreeView.js +2 -1
- package/hooks/useTreeItem2Utils/useTreeItem2Utils.d.ts +4 -0
- package/hooks/useTreeItem2Utils/useTreeItem2Utils.js +9 -0
- package/hooks/useTreeViewApiRef.d.ts +1 -1
- package/index.js +1 -1
- package/internals/TreeViewProvider/TreeViewChildrenItemProvider.js +3 -1
- package/internals/TreeViewProvider/TreeViewContext.d.ts +2 -8
- 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 +6 -3
- package/internals/corePlugins/corePlugins.js +2 -1
- package/internals/corePlugins/index.d.ts +1 -1
- package/internals/{plugins → corePlugins}/useTreeViewId/useTreeViewId.types.d.ts +0 -4
- package/internals/hooks/useInstanceEventHandler.d.ts +2 -2
- package/internals/index.d.ts +2 -7
- package/internals/index.js +4 -4
- package/internals/models/helpers.d.ts +3 -16
- package/internals/models/plugin.d.ts +25 -19
- package/internals/models/treeView.d.ts +5 -4
- package/internals/plugins/useTreeViewExpansion/useTreeViewExpansion.types.d.ts +1 -1
- package/internals/plugins/useTreeViewFocus/useTreeViewFocus.types.d.ts +1 -3
- package/internals/plugins/useTreeViewIcons/useTreeViewIcons.types.d.ts +1 -1
- package/internals/plugins/useTreeViewJSXItems/useTreeViewJSXItems.types.d.ts +1 -1
- package/internals/plugins/useTreeViewKeyboardNavigation/useTreeViewKeyboardNavigation.js +4 -5
- package/internals/plugins/useTreeViewKeyboardNavigation/useTreeViewKeyboardNavigation.types.d.ts +1 -1
- package/internals/plugins/useTreeViewSelection/useTreeViewSelection.types.d.ts +1 -1
- 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/utils/utils.d.ts +1 -0
- package/internals/utils/utils.js +7 -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 +9 -0
- package/modern/RichTreeView/index.js +1 -1
- package/modern/SimpleTreeView/SimpleTreeView.js +11 -14
- package/modern/SimpleTreeView/SimpleTreeView.plugins.js +7 -2
- package/modern/TreeItem/TreeItem.js +7 -1
- package/modern/TreeItem2/TreeItem2.js +12 -2
- package/modern/TreeView/TreeView.js +2 -1
- package/modern/hooks/useTreeItem2Utils/useTreeItem2Utils.js +9 -0
- package/modern/index.js +1 -1
- package/modern/internals/TreeViewProvider/TreeViewChildrenItemProvider.js +3 -1
- package/modern/internals/corePlugins/corePlugins.js +2 -1
- package/modern/internals/index.js +4 -4
- 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/utils/utils.js +7 -1
- package/modern/internals/zero-styled/index.js +7 -0
- package/node/RichTreeView/RichTreeView.js +14 -17
- package/node/RichTreeView/RichTreeView.plugins.js +15 -0
- package/node/RichTreeView/index.js +13 -1
- package/node/SimpleTreeView/SimpleTreeView.js +13 -16
- package/node/SimpleTreeView/SimpleTreeView.plugins.js +7 -2
- package/node/TreeItem/TreeItem.js +10 -4
- package/node/TreeItem2/TreeItem2.js +18 -8
- package/node/TreeView/TreeView.js +4 -3
- package/node/hooks/useTreeItem2Utils/useTreeItem2Utils.js +9 -0
- package/node/index.js +1 -1
- package/node/internals/TreeViewProvider/TreeViewChildrenItemProvider.js +3 -1
- package/node/internals/corePlugins/corePlugins.js +2 -1
- package/node/internals/index.js +1 -22
- 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/utils/utils.js +8 -1
- package/node/internals/zero-styled/index.js +17 -0
- package/package.json +4 -4
- package/useTreeItem2/useTreeItem2.d.ts +2 -2
- package/useTreeItem2/useTreeItem2.types.d.ts +20 -3
- 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
- /package/internals/{plugins → corePlugins}/useTreeViewId/index.d.ts +0 -0
- /package/internals/{plugins → corePlugins}/useTreeViewId/index.js +0 -0
- /package/internals/{plugins → corePlugins}/useTreeViewId/useTreeViewId.d.ts +0 -0
- /package/internals/{plugins → corePlugins}/useTreeViewId/useTreeViewId.js +0 -0
- /package/internals/{plugins → corePlugins}/useTreeViewId/useTreeViewId.types.js +0 -0
- /package/modern/internals/{plugins → corePlugins}/useTreeViewId/index.js +0 -0
- /package/modern/internals/{plugins → corePlugins}/useTreeViewId/useTreeViewId.js +0 -0
- /package/modern/internals/{plugins → corePlugins}/useTreeViewId/useTreeViewId.types.js +0 -0
- /package/node/internals/{plugins → corePlugins}/useTreeViewId/index.js +0 -0
- /package/node/internals/{plugins → corePlugins}/useTreeViewId/useTreeViewId.js +0 -0
- /package/node/internals/{plugins → corePlugins}/useTreeViewId/useTreeViewId.types.js +0 -0
|
@@ -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
|
};
|
|
@@ -1,23 +1,24 @@
|
|
|
1
1
|
import * as React from 'react';
|
|
2
2
|
import { EventHandlers } from '@mui/base/utils';
|
|
3
3
|
import type { TreeViewContextValue } from '../TreeViewProvider';
|
|
4
|
-
import { TreeViewAnyPluginSignature,
|
|
5
|
-
export
|
|
6
|
-
|
|
7
|
-
apiRef: React.MutableRefObject<TreeViewPublicAPI<ConvertPluginsIntoSignatures<TPlugins>>> | undefined;
|
|
4
|
+
import { TreeViewAnyPluginSignature, ConvertSignaturesIntoPlugins, MergeSignaturesProperty, TreeViewInstance, TreeViewPublicAPI, TreeViewExperimentalFeatures } from '../models';
|
|
5
|
+
export interface UseTreeViewParameters<TSignatures extends readonly TreeViewAnyPluginSignature[], TProps extends Partial<UseTreeViewBaseProps<TSignatures>>> {
|
|
6
|
+
plugins: ConvertSignaturesIntoPlugins<TSignatures>;
|
|
8
7
|
rootRef?: React.Ref<HTMLUListElement> | undefined;
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
8
|
+
props: TProps;
|
|
9
|
+
}
|
|
10
|
+
export interface UseTreeViewBaseProps<TSignatures extends readonly TreeViewAnyPluginSignature[]> {
|
|
11
|
+
apiRef: React.MutableRefObject<TreeViewPublicAPI<TSignatures> | undefined> | undefined;
|
|
12
|
+
slots: MergeSignaturesProperty<TSignatures, 'slots'>;
|
|
13
|
+
slotProps: MergeSignaturesProperty<TSignatures, 'slotProps'>;
|
|
14
|
+
experimentalFeatures: TreeViewExperimentalFeatures<TSignatures>;
|
|
13
15
|
}
|
|
14
|
-
export type UseTreeViewDefaultizedParameters<TPlugins extends readonly TreeViewPlugin<TreeViewAnyPluginSignature>[]> = UseTreeViewBaseParameters<TPlugins> & MergePluginsProperty<ConvertPluginsIntoSignatures<TPlugins>, 'defaultizedParams'>;
|
|
15
16
|
export interface UseTreeViewRootSlotProps extends Pick<React.HTMLAttributes<HTMLUListElement>, 'onFocus' | 'onBlur' | 'onKeyDown' | 'id' | 'aria-multiselectable' | 'role' | 'tabIndex'> {
|
|
16
17
|
ref: React.Ref<HTMLUListElement>;
|
|
17
18
|
}
|
|
18
|
-
export interface UseTreeViewReturnValue<
|
|
19
|
+
export interface UseTreeViewReturnValue<TSignatures extends readonly TreeViewAnyPluginSignature[]> {
|
|
19
20
|
getRootProps: <TOther extends EventHandlers = {}>(otherHandlers?: TOther) => UseTreeViewRootSlotProps;
|
|
20
21
|
rootRef: React.RefCallback<HTMLUListElement> | null;
|
|
21
|
-
contextValue: TreeViewContextValue<
|
|
22
|
-
instance: TreeViewInstance<
|
|
22
|
+
contextValue: TreeViewContextValue<TSignatures>;
|
|
23
|
+
instance: TreeViewInstance<TSignatures>;
|
|
23
24
|
}
|
|
@@ -1,6 +1,7 @@
|
|
|
1
|
-
import { TreeViewAnyPluginSignature,
|
|
1
|
+
import { TreeViewAnyPluginSignature, ConvertSignaturesIntoPlugins, MergeSignaturesProperty } from '../models';
|
|
2
|
+
import { TreeViewCorePluginSignatures } from '../corePlugins';
|
|
2
3
|
/**
|
|
3
4
|
* Implements the same behavior as `useControlled` but for several models.
|
|
4
5
|
* The controlled models are never stored in the state, and the state is only updated if the model is not controlled.
|
|
5
6
|
*/
|
|
6
|
-
export declare const useTreeViewModels: <
|
|
7
|
+
export declare const useTreeViewModels: <TSignatures extends readonly TreeViewAnyPluginSignature[]>(plugins: ConvertSignaturesIntoPlugins<readonly [...TreeViewCorePluginSignatures, ...TSignatures]>, props: MergeSignaturesProperty<TSignatures, 'defaultizedParams'>) => MergeSignaturesProperty<TSignatures, "models">;
|
|
@@ -2,4 +2,4 @@ import { UseTreeViewInstanceEventsInstance } from '../corePlugins/useTreeViewIns
|
|
|
2
2
|
import { TreeViewAnyPluginSignature, TreeViewUsedEvents } from '../models';
|
|
3
3
|
export declare const publishTreeViewEvent: <Instance extends UseTreeViewInstanceEventsInstance & {
|
|
4
4
|
$$signature: TreeViewAnyPluginSignature;
|
|
5
|
-
}, E extends keyof Instance["$$signature"]["events"] | keyof import("../models").
|
|
5
|
+
}, E extends keyof Instance["$$signature"]["events"] | keyof import("../models").MergeSignaturesProperty<[import("../corePlugins/useTreeViewInstanceEvents/useTreeViewInstanceEvents.types").UseTreeViewInstanceEventsSignature, import("../corePlugins/useTreeViewId").UseTreeViewIdSignature, ...Instance["$$signature"]["dependencies"]], "events">>(instance: Instance, eventName: E, params: TreeViewUsedEvents<Instance['$$signature']>[E]['params']) => void;
|
package/internals/utils/utils.js
CHANGED
|
@@ -8,4 +8,10 @@ export const getActiveElement = (root = document) => {
|
|
|
8
8
|
return getActiveElement(activeEl.shadowRoot);
|
|
9
9
|
}
|
|
10
10
|
return activeEl;
|
|
11
|
-
};
|
|
11
|
+
};
|
|
12
|
+
|
|
13
|
+
// TODO, eventually replaces this function with CSS.escape, once available in jsdom, either added manually or built in
|
|
14
|
+
// https://github.com/jsdom/jsdom/issues/1550#issuecomment-236734471
|
|
15
|
+
export function escapeOperandAttributeSelector(operand) {
|
|
16
|
+
return operand.replace(/["\\]/g, '\\$&');
|
|
17
|
+
}
|
|
@@ -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,9 @@
|
|
|
1
|
+
import { useTreeViewItems } from '../internals/plugins/useTreeViewItems';
|
|
2
|
+
import { useTreeViewExpansion } from '../internals/plugins/useTreeViewExpansion';
|
|
3
|
+
import { useTreeViewSelection } from '../internals/plugins/useTreeViewSelection';
|
|
4
|
+
import { useTreeViewFocus } from '../internals/plugins/useTreeViewFocus';
|
|
5
|
+
import { useTreeViewKeyboardNavigation } from '../internals/plugins/useTreeViewKeyboardNavigation';
|
|
6
|
+
import { useTreeViewIcons } from '../internals/plugins/useTreeViewIcons';
|
|
7
|
+
export const RICH_TREE_VIEW_PLUGINS = [useTreeViewItems, useTreeViewExpansion, useTreeViewSelection, useTreeViewFocus, useTreeViewKeyboardNavigation, useTreeViewIcons];
|
|
8
|
+
|
|
9
|
+
// 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,10 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { useTreeViewItems } from '../internals/plugins/useTreeViewItems';
|
|
2
|
+
import { useTreeViewExpansion } from '../internals/plugins/useTreeViewExpansion';
|
|
3
|
+
import { useTreeViewSelection } from '../internals/plugins/useTreeViewSelection';
|
|
4
|
+
import { useTreeViewFocus } from '../internals/plugins/useTreeViewFocus';
|
|
5
|
+
import { useTreeViewKeyboardNavigation } from '../internals/plugins/useTreeViewKeyboardNavigation';
|
|
6
|
+
import { useTreeViewIcons } from '../internals/plugins/useTreeViewIcons';
|
|
2
7
|
import { useTreeViewJSXItems } from '../internals/plugins/useTreeViewJSXItems';
|
|
3
|
-
export const SIMPLE_TREE_VIEW_PLUGINS = [
|
|
8
|
+
export const SIMPLE_TREE_VIEW_PLUGINS = [useTreeViewItems, useTreeViewExpansion, useTreeViewSelection, useTreeViewFocus, useTreeViewKeyboardNavigation, useTreeViewIcons, useTreeViewJSXItems];
|
|
4
9
|
|
|
5
10
|
// 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
|
|
@@ -5,6 +5,15 @@ const isItemExpandable = reactChildren => {
|
|
|
5
5
|
}
|
|
6
6
|
return Boolean(reactChildren);
|
|
7
7
|
};
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* Plugins that need to be present in the Tree View in order for `useTreeItem2Utils` to work correctly.
|
|
11
|
+
*/
|
|
12
|
+
|
|
13
|
+
/**
|
|
14
|
+
* Plugins that `useTreeItem2Utils` can use if they are present, but are not required.
|
|
15
|
+
*/
|
|
16
|
+
|
|
8
17
|
export const useTreeItem2Utils = ({
|
|
9
18
|
itemId,
|
|
10
19
|
children
|
package/modern/index.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import * as React from 'react';
|
|
2
2
|
import PropTypes from 'prop-types';
|
|
3
3
|
import { useTreeViewContext } from './useTreeViewContext';
|
|
4
|
+
import { escapeOperandAttributeSelector } from '../utils/utils';
|
|
4
5
|
import { jsx as _jsx } from "react/jsx-runtime";
|
|
5
6
|
export const TreeViewChildrenItemContext = /*#__PURE__*/React.createContext(null);
|
|
6
7
|
if (process.env.NODE_ENV !== 'production') {
|
|
@@ -34,7 +35,8 @@ export function TreeViewChildrenItemProvider(props) {
|
|
|
34
35
|
return;
|
|
35
36
|
}
|
|
36
37
|
const previousChildrenIds = instance.getItemOrderedChildrenIds(itemId ?? null) ?? [];
|
|
37
|
-
const
|
|
38
|
+
const escapedIdAttr = escapeOperandAttributeSelector(idAttr);
|
|
39
|
+
const childrenElements = rootRef.current.querySelectorAll(`${itemId == null ? '' : `*[id="${escapedIdAttr}"] `}[role="treeitem"]:not(*[id="${escapedIdAttr}"] [role="treeitem"] [role="treeitem"])`);
|
|
38
40
|
const childrenIds = Array.from(childrenElements).map(child => childrenIdAttrToIdRef.current.get(child.id));
|
|
39
41
|
const hasChanged = childrenIds.length !== previousChildrenIds.length || childrenIds.some((childId, index) => childId !== previousChildrenIds[index]);
|
|
40
42
|
if (hasChanged) {
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { useTreeViewInstanceEvents } from './useTreeViewInstanceEvents';
|
|
2
|
+
import { useTreeViewId } from './useTreeViewId';
|
|
2
3
|
/**
|
|
3
4
|
* Internal plugins that create the tools used by the other plugins.
|
|
4
5
|
* These plugins are used by the tree view components.
|
|
5
6
|
*/
|
|
6
|
-
export const TREE_VIEW_CORE_PLUGINS = [useTreeViewInstanceEvents];
|
|
7
|
+
export const TREE_VIEW_CORE_PLUGINS = [useTreeViewInstanceEvents, useTreeViewId];
|
|
@@ -1,15 +1,15 @@
|
|
|
1
1
|
export { useTreeView } from './useTreeView';
|
|
2
2
|
export { TreeViewProvider } from './TreeViewProvider';
|
|
3
3
|
export { unstable_resetCleanupTracking } from './hooks/useInstanceEventHandler';
|
|
4
|
+
|
|
5
|
+
// Core plugins
|
|
6
|
+
|
|
4
7
|
// Plugins
|
|
5
|
-
export { DEFAULT_TREE_VIEW_PLUGINS } from './plugins/defaultPlugins';
|
|
6
8
|
export { useTreeViewExpansion } from './plugins/useTreeViewExpansion';
|
|
7
9
|
export { useTreeViewSelection } from './plugins/useTreeViewSelection';
|
|
8
10
|
export { useTreeViewFocus } from './plugins/useTreeViewFocus';
|
|
9
11
|
export { useTreeViewKeyboardNavigation } from './plugins/useTreeViewKeyboardNavigation';
|
|
10
|
-
export { useTreeViewId } from './plugins/useTreeViewId';
|
|
11
12
|
export { useTreeViewIcons } from './plugins/useTreeViewIcons';
|
|
12
13
|
export { useTreeViewItems } from './plugins/useTreeViewItems';
|
|
13
14
|
export { useTreeViewJSXItems } from './plugins/useTreeViewJSXItems';
|
|
14
|
-
export { buildWarning } from './utils/warning';
|
|
15
|
-
export { extractPluginParamsFromProps } from './utils/extractPluginParamsFromProps';
|
|
15
|
+
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);
|