@mui/x-tree-view 6.0.0-alpha.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.
Files changed (76) hide show
  1. package/CHANGELOG.md +3682 -0
  2. package/LICENSE +21 -0
  3. package/README.md +34 -0
  4. package/TreeItem/TreeItem.d.ts +13 -0
  5. package/TreeItem/TreeItem.js +392 -0
  6. package/TreeItem/TreeItem.types.d.ts +84 -0
  7. package/TreeItem/TreeItem.types.js +1 -0
  8. package/TreeItem/TreeItemContent.d.ts +52 -0
  9. package/TreeItem/TreeItemContent.js +101 -0
  10. package/TreeItem/index.d.ts +5 -0
  11. package/TreeItem/index.js +4 -0
  12. package/TreeItem/package.json +6 -0
  13. package/TreeItem/treeItemClasses.d.ts +23 -0
  14. package/TreeItem/treeItemClasses.js +6 -0
  15. package/TreeItem/useTreeItem.d.ts +10 -0
  16. package/TreeItem/useTreeItem.js +68 -0
  17. package/TreeView/TreeView.d.ts +14 -0
  18. package/TreeView/TreeView.js +854 -0
  19. package/TreeView/TreeView.types.d.ts +170 -0
  20. package/TreeView/TreeView.types.js +1 -0
  21. package/TreeView/TreeViewContext.d.ts +6 -0
  22. package/TreeView/TreeViewContext.js +31 -0
  23. package/TreeView/descendants.d.ts +42 -0
  24. package/TreeView/descendants.js +186 -0
  25. package/TreeView/index.d.ts +3 -0
  26. package/TreeView/index.js +3 -0
  27. package/TreeView/package.json +6 -0
  28. package/TreeView/treeViewClasses.d.ts +7 -0
  29. package/TreeView/treeViewClasses.js +6 -0
  30. package/index.d.ts +2 -0
  31. package/index.js +9 -0
  32. package/internals/models.d.ts +1 -0
  33. package/internals/models.js +1 -0
  34. package/legacy/TreeItem/TreeItem.js +391 -0
  35. package/legacy/TreeItem/TreeItem.types.js +1 -0
  36. package/legacy/TreeItem/TreeItemContent.js +98 -0
  37. package/legacy/TreeItem/index.js +4 -0
  38. package/legacy/TreeItem/treeItemClasses.js +6 -0
  39. package/legacy/TreeItem/useTreeItem.js +67 -0
  40. package/legacy/TreeView/TreeView.js +907 -0
  41. package/legacy/TreeView/TreeView.types.js +1 -0
  42. package/legacy/TreeView/TreeViewContext.js +41 -0
  43. package/legacy/TreeView/descendants.js +199 -0
  44. package/legacy/TreeView/index.js +3 -0
  45. package/legacy/TreeView/treeViewClasses.js +6 -0
  46. package/legacy/index.js +9 -0
  47. package/legacy/internals/models.js +1 -0
  48. package/modern/TreeItem/TreeItem.js +391 -0
  49. package/modern/TreeItem/TreeItem.types.js +1 -0
  50. package/modern/TreeItem/TreeItemContent.js +101 -0
  51. package/modern/TreeItem/index.js +4 -0
  52. package/modern/TreeItem/treeItemClasses.js +6 -0
  53. package/modern/TreeItem/useTreeItem.js +68 -0
  54. package/modern/TreeView/TreeView.js +853 -0
  55. package/modern/TreeView/TreeView.types.js +1 -0
  56. package/modern/TreeView/TreeViewContext.js +31 -0
  57. package/modern/TreeView/descendants.js +186 -0
  58. package/modern/TreeView/index.js +3 -0
  59. package/modern/TreeView/treeViewClasses.js +6 -0
  60. package/modern/index.js +9 -0
  61. package/modern/internals/models.js +1 -0
  62. package/node/TreeItem/TreeItem.js +400 -0
  63. package/node/TreeItem/TreeItem.types.js +5 -0
  64. package/node/TreeItem/TreeItemContent.js +109 -0
  65. package/node/TreeItem/index.js +38 -0
  66. package/node/TreeItem/treeItemClasses.js +15 -0
  67. package/node/TreeItem/useTreeItem.js +76 -0
  68. package/node/TreeView/TreeView.js +862 -0
  69. package/node/TreeView/TreeView.types.js +5 -0
  70. package/node/TreeView/TreeViewContext.js +40 -0
  71. package/node/TreeView/descendants.js +194 -0
  72. package/node/TreeView/index.js +27 -0
  73. package/node/TreeView/treeViewClasses.js +15 -0
  74. package/node/index.js +34 -0
  75. package/node/internals/models.js +5 -0
  76. package/package.json +59 -0
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,41 @@
1
+ import * as React from 'react';
2
+ /**
3
+ * @ignore - internal component.
4
+ */
5
+ export var TreeViewContext = /*#__PURE__*/React.createContext({
6
+ registerNode: function registerNode() {},
7
+ unregisterNode: function unregisterNode() {},
8
+ isFocused: function isFocused() {
9
+ return false;
10
+ },
11
+ isSelected: function isSelected() {
12
+ return false;
13
+ },
14
+ isExpanded: function isExpanded() {
15
+ return false;
16
+ },
17
+ isExpandable: function isExpandable() {
18
+ return false;
19
+ },
20
+ isDisabled: function isDisabled() {
21
+ return false;
22
+ },
23
+ mapFirstChar: function mapFirstChar() {},
24
+ unMapFirstChar: function unMapFirstChar() {},
25
+ focus: function focus() {},
26
+ toggleExpansion: function toggleExpansion() {},
27
+ selectNode: function selectNode() {},
28
+ selectRange: function selectRange() {},
29
+ multiSelect: false,
30
+ disabledItemsFocusable: false,
31
+ treeId: undefined,
32
+ icons: {
33
+ defaultCollapseIcon: null,
34
+ defaultExpandIcon: null,
35
+ defaultParentIcon: null,
36
+ defaultEndIcon: null
37
+ }
38
+ });
39
+ if (process.env.NODE_ENV !== 'production') {
40
+ TreeViewContext.displayName = 'TreeViewContext';
41
+ }
@@ -0,0 +1,199 @@
1
+ import _objectWithoutProperties from "@babel/runtime/helpers/esm/objectWithoutProperties";
2
+ import _extends from "@babel/runtime/helpers/esm/extends";
3
+ import _slicedToArray from "@babel/runtime/helpers/esm/slicedToArray";
4
+ var _excluded = ["element"];
5
+ import * as React from 'react';
6
+ import PropTypes from 'prop-types';
7
+ import useEnhancedEffect from '@mui/utils/useEnhancedEffect';
8
+
9
+ /** Credit: https://github.com/reach/reach-ui/blob/86a046f54d53b6420e392b3fa56dd991d9d4e458/packages/descendants/README.md
10
+ * Modified slightly to suit our purposes.
11
+ */
12
+
13
+ // To replace with .findIndex() once we stop IE11 support.
14
+ import { jsx as _jsx } from "react/jsx-runtime";
15
+ function findIndex(array, comp) {
16
+ for (var i = 0; i < array.length; i += 1) {
17
+ if (comp(array[i])) {
18
+ return i;
19
+ }
20
+ }
21
+ return -1;
22
+ }
23
+ function binaryFindElement(array, element) {
24
+ var start = 0;
25
+ var end = array.length - 1;
26
+ while (start <= end) {
27
+ var middle = Math.floor((start + end) / 2);
28
+ if (array[middle].element === element) {
29
+ return middle;
30
+ }
31
+
32
+ // eslint-disable-next-line no-bitwise
33
+ if (array[middle].element.compareDocumentPosition(element) & Node.DOCUMENT_POSITION_PRECEDING) {
34
+ end = middle - 1;
35
+ } else {
36
+ start = middle + 1;
37
+ }
38
+ }
39
+ return start;
40
+ }
41
+ var DescendantContext = /*#__PURE__*/React.createContext({});
42
+ if (process.env.NODE_ENV !== 'production') {
43
+ DescendantContext.displayName = 'DescendantContext';
44
+ }
45
+ function usePrevious(value) {
46
+ var ref = React.useRef(null);
47
+ React.useEffect(function () {
48
+ ref.current = value;
49
+ }, [value]);
50
+ return ref.current;
51
+ }
52
+ var noop = function noop() {};
53
+
54
+ /**
55
+ * This hook registers our descendant by passing it into an array. We can then
56
+ * search that array by to find its index when registering it in the component.
57
+ * We use this for focus management, keyboard navigation, and typeahead
58
+ * functionality for some components.
59
+ *
60
+ * The hook accepts the element node
61
+ *
62
+ * Our main goals with this are:
63
+ * 1) maximum composability,
64
+ * 2) minimal API friction
65
+ * 3) SSR compatibility*
66
+ * 4) concurrent safe
67
+ * 5) index always up-to-date with the tree despite changes
68
+ * 6) works with memoization of any component in the tree (hopefully)
69
+ *
70
+ * * As for SSR, the good news is that we don't actually need the index on the
71
+ * server for most use-cases, as we are only using it to determine the order of
72
+ * composed descendants for keyboard navigation.
73
+ */
74
+ export function useDescendant(descendant) {
75
+ var _React$useState = React.useState(),
76
+ _React$useState2 = _slicedToArray(_React$useState, 2),
77
+ forceUpdate = _React$useState2[1];
78
+ var _React$useContext = React.useContext(DescendantContext),
79
+ _React$useContext$reg = _React$useContext.registerDescendant,
80
+ registerDescendant = _React$useContext$reg === void 0 ? noop : _React$useContext$reg,
81
+ _React$useContext$unr = _React$useContext.unregisterDescendant,
82
+ unregisterDescendant = _React$useContext$unr === void 0 ? noop : _React$useContext$unr,
83
+ _React$useContext$des = _React$useContext.descendants,
84
+ descendants = _React$useContext$des === void 0 ? [] : _React$useContext$des,
85
+ _React$useContext$par = _React$useContext.parentId,
86
+ parentId = _React$useContext$par === void 0 ? null : _React$useContext$par;
87
+
88
+ // This will initially return -1 because we haven't registered the descendant
89
+ // on the first render. After we register, this will then return the correct
90
+ // index on the following render, and we will re-register descendants
91
+ // so that everything is up-to-date before the user interacts with a
92
+ // collection.
93
+ var index = findIndex(descendants, function (item) {
94
+ return item.element === descendant.element;
95
+ });
96
+ var previousDescendants = usePrevious(descendants);
97
+
98
+ // We also need to re-register descendants any time ANY of the other
99
+ // descendants have changed. My brain was melting when I wrote this and it
100
+ // feels a little off, but checking in render and using the result in the
101
+ // effect's dependency array works well enough.
102
+ var someDescendantsHaveChanged = descendants.some(function (newDescendant, position) {
103
+ return previousDescendants && previousDescendants[position] && previousDescendants[position].element !== newDescendant.element;
104
+ });
105
+
106
+ // Prevent any flashing
107
+ useEnhancedEffect(function () {
108
+ if (descendant.element) {
109
+ registerDescendant(_extends({}, descendant, {
110
+ index: index
111
+ }));
112
+ return function () {
113
+ unregisterDescendant(descendant.element);
114
+ };
115
+ }
116
+ forceUpdate({});
117
+ return undefined;
118
+ }, [registerDescendant, unregisterDescendant, index, someDescendantsHaveChanged, descendant]);
119
+ return {
120
+ parentId: parentId,
121
+ index: index
122
+ };
123
+ }
124
+ export function DescendantProvider(props) {
125
+ var children = props.children,
126
+ id = props.id;
127
+ var _React$useState3 = React.useState([]),
128
+ _React$useState4 = _slicedToArray(_React$useState3, 2),
129
+ items = _React$useState4[0],
130
+ set = _React$useState4[1];
131
+ var registerDescendant = React.useCallback(function (_ref) {
132
+ var element = _ref.element,
133
+ other = _objectWithoutProperties(_ref, _excluded);
134
+ set(function (oldItems) {
135
+ if (oldItems.length === 0) {
136
+ // If there are no items, register at index 0 and bail.
137
+ return [_extends({}, other, {
138
+ element: element,
139
+ index: 0
140
+ })];
141
+ }
142
+ var index = binaryFindElement(oldItems, element);
143
+ var newItems;
144
+ if (oldItems[index] && oldItems[index].element === element) {
145
+ // If the element is already registered, just use the same array
146
+ newItems = oldItems;
147
+ } else {
148
+ // When registering a descendant, we need to make sure we insert in
149
+ // into the array in the same order that it appears in the DOM. So as
150
+ // new descendants are added or maybe some are removed, we always know
151
+ // that the array is up-to-date and correct.
152
+ //
153
+ // So here we look at our registered descendants and see if the new
154
+ // element we are adding appears earlier than an existing descendant's
155
+ // DOM node via `node.compareDocumentPosition`. If it does, we insert
156
+ // the new element at this index. Because `registerDescendant` will be
157
+ // called in an effect every time the descendants state value changes,
158
+ // we should be sure that this index is accurate when descendent
159
+ // elements come or go from our component.
160
+
161
+ var newItem = _extends({}, other, {
162
+ element: element,
163
+ index: index
164
+ });
165
+
166
+ // If an index is not found we will push the element to the end.
167
+ newItems = oldItems.slice();
168
+ newItems.splice(index, 0, newItem);
169
+ }
170
+ newItems.forEach(function (item, position) {
171
+ item.index = position;
172
+ });
173
+ return newItems;
174
+ });
175
+ }, []);
176
+ var unregisterDescendant = React.useCallback(function (element) {
177
+ set(function (oldItems) {
178
+ return oldItems.filter(function (item) {
179
+ return element !== item.element;
180
+ });
181
+ });
182
+ }, []);
183
+ var value = React.useMemo(function () {
184
+ return {
185
+ descendants: items,
186
+ registerDescendant: registerDescendant,
187
+ unregisterDescendant: unregisterDescendant,
188
+ parentId: id
189
+ };
190
+ }, [items, registerDescendant, unregisterDescendant, id]);
191
+ return /*#__PURE__*/_jsx(DescendantContext.Provider, {
192
+ value: value,
193
+ children: children
194
+ });
195
+ }
196
+ process.env.NODE_ENV !== "production" ? DescendantProvider.propTypes = {
197
+ children: PropTypes.node,
198
+ id: PropTypes.string
199
+ } : void 0;
@@ -0,0 +1,3 @@
1
+ export * from './TreeView';
2
+ export * from './treeViewClasses';
3
+ export {};
@@ -0,0 +1,6 @@
1
+ import generateUtilityClass from '@mui/utils/generateUtilityClass';
2
+ import generateUtilityClasses from '@mui/utils/generateUtilityClasses';
3
+ export function getTreeViewUtilityClass(slot) {
4
+ return generateUtilityClass('MuiTreeView', slot);
5
+ }
6
+ export var treeViewClasses = generateUtilityClasses('MuiTreeView', ['root']);
@@ -0,0 +1,9 @@
1
+ /**
2
+ * @mui/x-tree-view v6.0.0-alpha.0
3
+ *
4
+ * @license MIT
5
+ * This source code is licensed under the MIT license found in the
6
+ * LICENSE file in the root directory of this source tree.
7
+ */
8
+ export * from './TreeItem';
9
+ export * from './TreeView';
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,391 @@
1
+ import _objectWithoutPropertiesLoose from "@babel/runtime/helpers/esm/objectWithoutPropertiesLoose";
2
+ import _extends from "@babel/runtime/helpers/esm/extends";
3
+ const _excluded = ["children", "className", "collapseIcon", "ContentComponent", "ContentProps", "endIcon", "expandIcon", "disabled", "icon", "id", "label", "nodeId", "onClick", "onMouseDown", "TransitionComponent", "TransitionProps"];
4
+ import * as React from 'react';
5
+ import PropTypes from 'prop-types';
6
+ import clsx from 'clsx';
7
+ import Collapse from '@mui/material/Collapse';
8
+ import { alpha, styled, useThemeProps } from '@mui/material/styles';
9
+ import ownerDocument from '@mui/utils/ownerDocument';
10
+ import useForkRef from '@mui/utils/useForkRef';
11
+ import unsupportedProp from '@mui/utils/unsupportedProp';
12
+ import elementTypeAcceptingRef from '@mui/utils/elementTypeAcceptingRef';
13
+ import { unstable_composeClasses as composeClasses } from '@mui/base';
14
+ import { TreeViewContext } from '../TreeView/TreeViewContext';
15
+ import { DescendantProvider, useDescendant } from '../TreeView/descendants';
16
+ import { TreeItemContent } from './TreeItemContent';
17
+ import { treeItemClasses, getTreeItemUtilityClass } from './treeItemClasses';
18
+ import { jsx as _jsx } from "react/jsx-runtime";
19
+ import { jsxs as _jsxs } from "react/jsx-runtime";
20
+ const useUtilityClasses = ownerState => {
21
+ const {
22
+ classes
23
+ } = ownerState;
24
+ const slots = {
25
+ root: ['root'],
26
+ content: ['content'],
27
+ expanded: ['expanded'],
28
+ selected: ['selected'],
29
+ focused: ['focused'],
30
+ disabled: ['disabled'],
31
+ iconContainer: ['iconContainer'],
32
+ label: ['label'],
33
+ group: ['group']
34
+ };
35
+ return composeClasses(slots, getTreeItemUtilityClass, classes);
36
+ };
37
+ const TreeItemRoot = styled('li', {
38
+ name: 'MuiTreeItem',
39
+ slot: 'Root',
40
+ overridesResolver: (props, styles) => styles.root
41
+ })({
42
+ listStyle: 'none',
43
+ margin: 0,
44
+ padding: 0,
45
+ outline: 0
46
+ });
47
+ const StyledTreeItemContent = styled(TreeItemContent, {
48
+ name: 'MuiTreeItem',
49
+ slot: 'Content',
50
+ overridesResolver: (props, styles) => {
51
+ return [styles.content, styles.iconContainer && {
52
+ [`& .${treeItemClasses.iconContainer}`]: styles.iconContainer
53
+ }, styles.label && {
54
+ [`& .${treeItemClasses.label}`]: styles.label
55
+ }];
56
+ }
57
+ })(({
58
+ theme
59
+ }) => ({
60
+ padding: '0 8px',
61
+ width: '100%',
62
+ display: 'flex',
63
+ alignItems: 'center',
64
+ cursor: 'pointer',
65
+ WebkitTapHighlightColor: 'transparent',
66
+ '&:hover': {
67
+ backgroundColor: (theme.vars || theme).palette.action.hover,
68
+ // Reset on touch devices, it doesn't add specificity
69
+ '@media (hover: none)': {
70
+ backgroundColor: 'transparent'
71
+ }
72
+ },
73
+ [`&.${treeItemClasses.disabled}`]: {
74
+ opacity: (theme.vars || theme).palette.action.disabledOpacity,
75
+ backgroundColor: 'transparent'
76
+ },
77
+ [`&.${treeItemClasses.focused}`]: {
78
+ backgroundColor: (theme.vars || theme).palette.action.focus
79
+ },
80
+ [`&.${treeItemClasses.selected}`]: {
81
+ backgroundColor: theme.vars ? `rgba(${theme.vars.palette.primary.mainChannel} / ${theme.vars.palette.action.selectedOpacity})` : alpha(theme.palette.primary.main, theme.palette.action.selectedOpacity),
82
+ '&:hover': {
83
+ backgroundColor: theme.vars ? `rgba(${theme.vars.palette.primary.mainChannel} / calc(${theme.vars.palette.action.selectedOpacity} + ${theme.vars.palette.action.hoverOpacity}))` : alpha(theme.palette.primary.main, theme.palette.action.selectedOpacity + theme.palette.action.hoverOpacity),
84
+ // Reset on touch devices, it doesn't add specificity
85
+ '@media (hover: none)': {
86
+ backgroundColor: theme.vars ? `rgba(${theme.vars.palette.primary.mainChannel} / ${theme.vars.palette.action.selectedOpacity})` : alpha(theme.palette.primary.main, theme.palette.action.selectedOpacity)
87
+ }
88
+ },
89
+ [`&.${treeItemClasses.focused}`]: {
90
+ backgroundColor: theme.vars ? `rgba(${theme.vars.palette.primary.mainChannel} / calc(${theme.vars.palette.action.selectedOpacity} + ${theme.vars.palette.action.focusOpacity}))` : alpha(theme.palette.primary.main, theme.palette.action.selectedOpacity + theme.palette.action.focusOpacity)
91
+ }
92
+ },
93
+ [`& .${treeItemClasses.iconContainer}`]: {
94
+ marginRight: 4,
95
+ width: 15,
96
+ display: 'flex',
97
+ flexShrink: 0,
98
+ justifyContent: 'center',
99
+ '& svg': {
100
+ fontSize: 18
101
+ }
102
+ },
103
+ [`& .${treeItemClasses.label}`]: _extends({
104
+ width: '100%',
105
+ // fixes overflow - see https://github.com/mui/material-ui/issues/27372
106
+ minWidth: 0,
107
+ paddingLeft: 4,
108
+ position: 'relative'
109
+ }, theme.typography.body1)
110
+ }));
111
+ const TreeItemGroup = styled(Collapse, {
112
+ name: 'MuiTreeItem',
113
+ slot: 'Group',
114
+ overridesResolver: (props, styles) => styles.group
115
+ })({
116
+ margin: 0,
117
+ padding: 0,
118
+ marginLeft: 17
119
+ });
120
+
121
+ /**
122
+ *
123
+ * Demos:
124
+ *
125
+ * - [Tree View](https://mui.com/material-ui/react-tree-view/)
126
+ *
127
+ * API:
128
+ *
129
+ * - [TreeItem API](https://mui.com/material-ui/api/tree-item/)
130
+ */
131
+ export const TreeItem = /*#__PURE__*/React.forwardRef(function TreeItem(inProps, ref) {
132
+ const props = useThemeProps({
133
+ props: inProps,
134
+ name: 'MuiTreeItem'
135
+ });
136
+ const {
137
+ children,
138
+ className,
139
+ collapseIcon,
140
+ ContentComponent = TreeItemContent,
141
+ ContentProps,
142
+ endIcon,
143
+ expandIcon,
144
+ disabled: disabledProp,
145
+ icon,
146
+ id: idProp,
147
+ label,
148
+ nodeId,
149
+ onClick,
150
+ onMouseDown,
151
+ TransitionComponent = Collapse,
152
+ TransitionProps
153
+ } = props,
154
+ other = _objectWithoutPropertiesLoose(props, _excluded);
155
+ const {
156
+ icons: contextIcons,
157
+ focus,
158
+ isExpanded,
159
+ isFocused,
160
+ isSelected,
161
+ isDisabled,
162
+ multiSelect,
163
+ disabledItemsFocusable,
164
+ mapFirstChar,
165
+ unMapFirstChar,
166
+ registerNode,
167
+ unregisterNode,
168
+ treeId
169
+ } = React.useContext(TreeViewContext);
170
+ let id;
171
+ if (idProp != null) {
172
+ id = idProp;
173
+ } else if (treeId && nodeId) {
174
+ id = `${treeId}-${nodeId}`;
175
+ }
176
+ const [treeItemElement, setTreeItemElement] = React.useState(null);
177
+ const contentRef = React.useRef(null);
178
+ const handleRef = useForkRef(setTreeItemElement, ref);
179
+ const descendant = React.useMemo(() => ({
180
+ element: treeItemElement,
181
+ id: nodeId
182
+ }), [nodeId, treeItemElement]);
183
+ const {
184
+ index,
185
+ parentId
186
+ } = useDescendant(descendant);
187
+ const expandable = Boolean(Array.isArray(children) ? children.length : children);
188
+ const expanded = isExpanded ? isExpanded(nodeId) : false;
189
+ const focused = isFocused ? isFocused(nodeId) : false;
190
+ const selected = isSelected ? isSelected(nodeId) : false;
191
+ const disabled = isDisabled ? isDisabled(nodeId) : false;
192
+ const ownerState = _extends({}, props, {
193
+ expanded,
194
+ focused,
195
+ selected,
196
+ disabled
197
+ });
198
+ const classes = useUtilityClasses(ownerState);
199
+ let displayIcon;
200
+ let expansionIcon;
201
+ if (expandable) {
202
+ if (!expanded) {
203
+ expansionIcon = expandIcon || contextIcons.defaultExpandIcon;
204
+ } else {
205
+ expansionIcon = collapseIcon || contextIcons.defaultCollapseIcon;
206
+ }
207
+ }
208
+ if (expandable) {
209
+ displayIcon = contextIcons.defaultParentIcon;
210
+ } else {
211
+ displayIcon = endIcon || contextIcons.defaultEndIcon;
212
+ }
213
+ React.useEffect(() => {
214
+ // On the first render a node's index will be -1. We want to wait for the real index.
215
+ if (registerNode && unregisterNode && index !== -1) {
216
+ registerNode({
217
+ id: nodeId,
218
+ idAttribute: id,
219
+ index,
220
+ parentId,
221
+ expandable,
222
+ disabled: disabledProp
223
+ });
224
+ return () => {
225
+ unregisterNode(nodeId);
226
+ };
227
+ }
228
+ return undefined;
229
+ }, [registerNode, unregisterNode, parentId, index, nodeId, expandable, disabledProp, id]);
230
+ React.useEffect(() => {
231
+ if (mapFirstChar && unMapFirstChar && label) {
232
+ mapFirstChar(nodeId, (contentRef.current?.textContent ?? '').substring(0, 1).toLowerCase());
233
+ return () => {
234
+ unMapFirstChar(nodeId);
235
+ };
236
+ }
237
+ return undefined;
238
+ }, [mapFirstChar, unMapFirstChar, nodeId, label]);
239
+ let ariaSelected;
240
+ if (multiSelect) {
241
+ ariaSelected = selected;
242
+ } else if (selected) {
243
+ /* single-selection trees unset aria-selected on un-selected items.
244
+ *
245
+ * If the tree does not support multiple selection, aria-selected
246
+ * is set to true for the selected node and it is not present on any other node in the tree.
247
+ * Source: https://www.w3.org/WAI/ARIA/apg/patterns/treeview/
248
+ */
249
+ ariaSelected = true;
250
+ }
251
+ function handleFocus(event) {
252
+ // DOM focus stays on the tree which manages focus with aria-activedescendant
253
+ if (event.target === event.currentTarget) {
254
+ let rootElement;
255
+ if (typeof event.target.getRootNode === 'function') {
256
+ rootElement = event.target.getRootNode();
257
+ } else {
258
+ rootElement = ownerDocument(event.target);
259
+ }
260
+ rootElement.getElementById(treeId).focus({
261
+ preventScroll: true
262
+ });
263
+ }
264
+ const unfocusable = !disabledItemsFocusable && disabled;
265
+ if (!focused && event.currentTarget === event.target && !unfocusable) {
266
+ focus(event, nodeId);
267
+ }
268
+ }
269
+ return /*#__PURE__*/_jsxs(TreeItemRoot, _extends({
270
+ className: clsx(classes.root, className),
271
+ role: "treeitem",
272
+ "aria-expanded": expandable ? expanded : undefined,
273
+ "aria-selected": ariaSelected,
274
+ "aria-disabled": disabled || undefined,
275
+ id: id,
276
+ tabIndex: -1
277
+ }, other, {
278
+ ownerState: ownerState,
279
+ onFocus: handleFocus,
280
+ ref: handleRef,
281
+ children: [/*#__PURE__*/_jsx(StyledTreeItemContent, _extends({
282
+ as: ContentComponent,
283
+ ref: contentRef,
284
+ classes: {
285
+ root: classes.content,
286
+ expanded: classes.expanded,
287
+ selected: classes.selected,
288
+ focused: classes.focused,
289
+ disabled: classes.disabled,
290
+ iconContainer: classes.iconContainer,
291
+ label: classes.label
292
+ },
293
+ label: label,
294
+ nodeId: nodeId,
295
+ onClick: onClick,
296
+ onMouseDown: onMouseDown,
297
+ icon: icon,
298
+ expansionIcon: expansionIcon,
299
+ displayIcon: displayIcon,
300
+ ownerState: ownerState
301
+ }, ContentProps)), children && /*#__PURE__*/_jsx(DescendantProvider, {
302
+ id: nodeId,
303
+ children: /*#__PURE__*/_jsx(TreeItemGroup, _extends({
304
+ as: TransitionComponent,
305
+ unmountOnExit: true,
306
+ className: classes.group,
307
+ in: expanded,
308
+ component: "ul",
309
+ role: "group"
310
+ }, TransitionProps, {
311
+ children: children
312
+ }))
313
+ })]
314
+ }));
315
+ });
316
+ process.env.NODE_ENV !== "production" ? TreeItem.propTypes = {
317
+ // ----------------------------- Warning --------------------------------
318
+ // | These PropTypes are generated from the TypeScript type definitions |
319
+ // | To update them edit the TypeScript types and run "yarn proptypes" |
320
+ // ----------------------------------------------------------------------
321
+ /**
322
+ * The content of the component.
323
+ */
324
+ children: PropTypes.node,
325
+ /**
326
+ * Override or extend the styles applied to the component.
327
+ */
328
+ classes: PropTypes.object,
329
+ /**
330
+ * className applied to the root element.
331
+ */
332
+ className: PropTypes.string,
333
+ /**
334
+ * The icon used to collapse the node.
335
+ */
336
+ collapseIcon: PropTypes.node,
337
+ /**
338
+ * The component used for the content node.
339
+ * @default TreeItemContent
340
+ */
341
+ ContentComponent: elementTypeAcceptingRef,
342
+ /**
343
+ * Props applied to ContentComponent.
344
+ */
345
+ ContentProps: PropTypes.object,
346
+ /**
347
+ * If `true`, the node is disabled.
348
+ * @default false
349
+ */
350
+ disabled: PropTypes.bool,
351
+ /**
352
+ * The icon displayed next to an end node.
353
+ */
354
+ endIcon: PropTypes.node,
355
+ /**
356
+ * The icon used to expand the node.
357
+ */
358
+ expandIcon: PropTypes.node,
359
+ /**
360
+ * The icon to display next to the tree node's label.
361
+ */
362
+ icon: PropTypes.node,
363
+ /**
364
+ * The tree node label.
365
+ */
366
+ label: PropTypes.node,
367
+ /**
368
+ * The id of the node.
369
+ */
370
+ nodeId: PropTypes.string.isRequired,
371
+ /**
372
+ * This prop isn't supported.
373
+ * Use the `onNodeFocus` callback on the tree if you need to monitor a node's focus.
374
+ */
375
+ onFocus: unsupportedProp,
376
+ /**
377
+ * The system prop that allows defining system overrides as well as additional CSS styles.
378
+ */
379
+ sx: PropTypes.oneOfType([PropTypes.arrayOf(PropTypes.oneOfType([PropTypes.func, PropTypes.object, PropTypes.bool])), PropTypes.func, PropTypes.object]),
380
+ /**
381
+ * The component used for the transition.
382
+ * [Follow this guide](/material-ui/transitions/#transitioncomponent-prop) to learn more about the requirements for this component.
383
+ * @default Collapse
384
+ */
385
+ TransitionComponent: PropTypes.elementType,
386
+ /**
387
+ * Props applied to the transition element.
388
+ * By default, the element is based on this [`Transition`](http://reactcommunity.org/react-transition-group/transition/) component.
389
+ */
390
+ TransitionProps: PropTypes.object
391
+ } : void 0;
@@ -0,0 +1 @@
1
+ export {};