@mui/x-tree-view 7.1.0 → 7.1.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 +175 -4
- package/README.md +1 -1
- package/RichTreeView/RichTreeView.d.ts +2 -2
- package/RichTreeView/RichTreeView.js +7 -5
- package/SimpleTreeView/SimpleTreeView.js +4 -2
- package/TreeView/TreeView.js +2 -1
- package/index.js +1 -1
- package/internals/index.d.ts +18 -8
- package/internals/index.js +11 -0
- package/internals/models/plugin.d.ts +1 -1
- package/internals/plugins/useTreeViewExpansion/useTreeViewExpansion.js +24 -10
- package/internals/plugins/useTreeViewExpansion/useTreeViewExpansion.types.d.ts +12 -2
- package/internals/plugins/useTreeViewFocus/useTreeViewFocus.types.d.ts +12 -4
- package/internals/plugins/useTreeViewItems/useTreeViewItems.js +1 -1
- package/internals/plugins/useTreeViewItems/useTreeViewItems.types.d.ts +12 -7
- package/internals/plugins/useTreeViewJSXItems/index.d.ts +1 -1
- package/internals/plugins/useTreeViewJSXItems/useTreeViewJSXItems.js +1 -1
- package/internals/plugins/useTreeViewJSXItems/useTreeViewJSXItems.types.d.ts +2 -2
- package/internals/useTreeView/useTreeViewModels.js +2 -2
- package/modern/RichTreeView/RichTreeView.js +7 -5
- package/modern/SimpleTreeView/SimpleTreeView.js +4 -2
- package/modern/TreeView/TreeView.js +2 -1
- package/modern/index.js +1 -1
- package/modern/internals/index.js +11 -0
- package/modern/internals/plugins/useTreeViewExpansion/useTreeViewExpansion.js +24 -10
- package/modern/internals/plugins/useTreeViewItems/useTreeViewItems.js +1 -1
- package/modern/internals/plugins/useTreeViewJSXItems/useTreeViewJSXItems.js +1 -1
- package/modern/internals/useTreeView/useTreeViewModels.js +2 -2
- package/node/RichTreeView/RichTreeView.js +7 -5
- package/node/SimpleTreeView/SimpleTreeView.js +4 -2
- package/node/TreeView/TreeView.js +2 -1
- package/node/index.js +1 -1
- package/node/internals/index.js +70 -0
- package/node/internals/plugins/useTreeViewExpansion/useTreeViewExpansion.js +23 -9
- package/node/internals/plugins/useTreeViewItems/useTreeViewItems.js +1 -1
- package/node/internals/plugins/useTreeViewJSXItems/useTreeViewJSXItems.js +1 -1
- package/node/internals/useTreeView/useTreeViewModels.js +2 -2
- package/package.json +2 -2
package/CHANGELOG.md
CHANGED
|
@@ -3,6 +3,107 @@
|
|
|
3
3
|
All notable changes to this project will be documented in this file.
|
|
4
4
|
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
|
|
5
5
|
|
|
6
|
+
## 7.1.1
|
|
7
|
+
|
|
8
|
+
_Apr 5, 2024_
|
|
9
|
+
|
|
10
|
+
We'd like to offer a big thanks to the 19 contributors who made this release possible. Here are some highlights ✨:
|
|
11
|
+
|
|
12
|
+
- 🚀 Add `setItemExpansion` Tree View API method (#12595) @flaviendelangle
|
|
13
|
+
- 🌍 Improve Persian (fa-IR), Portuguese (pt-BR), and Spanish (es-ES) locale on the Data Grid
|
|
14
|
+
- 🌍 Improve Persian (fa-IR), Portuguese (pt-BR), and Ukrainian (uk-UA) locale on the Pickers
|
|
15
|
+
- 🐞 Bugfixes
|
|
16
|
+
- 📚 Documentation improvements
|
|
17
|
+
|
|
18
|
+
### Data Grid
|
|
19
|
+
|
|
20
|
+
#### `@mui/x-data-grid@7.1.1`
|
|
21
|
+
|
|
22
|
+
- [DataGrid] Allow higher packages' props to be used in MIT (#12365) @MBilalShafi
|
|
23
|
+
- [DataGrid] Fix RTL mode (#12583) @romgrk
|
|
24
|
+
- [DataGrid] Fix `ColDefChangesGridNoSnap` demo crash (#12663) @MBilalShafi
|
|
25
|
+
- [DataGrid] Fix server-side filter demo not working (#12662) @MBilalShafi
|
|
26
|
+
- [DataGrid] Log error if `rowCount` is used with client-side pagination (#12448) @michelengelen
|
|
27
|
+
- [DataGrid] Remove `GridFormatterParams` completely (#12660) @romgrk
|
|
28
|
+
- [DataGrid] Restore main slot (#12657) @romgrk
|
|
29
|
+
- [l10n] Improve Persian (fa-IR) locale (#12630) @amirhosseinzf
|
|
30
|
+
- [l10n] Improve Portuguese (pt-BR) locale (#12618) @hugoalkimim
|
|
31
|
+
- [l10n] Improve Spanish (es-ES) locale (#12606) @aitor40
|
|
32
|
+
|
|
33
|
+
#### `@mui/x-data-grid-pro@7.1.1` [](https://mui.com/r/x-pro-svg-link 'Pro plan')
|
|
34
|
+
|
|
35
|
+
Same changes as in `@mui/x-data-grid@7.1.1`.
|
|
36
|
+
|
|
37
|
+
#### `@mui/x-data-grid-premium@7.1.1` [](https://mui.com/r/x-premium-svg-link 'Premium plan')
|
|
38
|
+
|
|
39
|
+
Same changes as in `@mui/x-data-grid-pro@7.1.1`.
|
|
40
|
+
|
|
41
|
+
### Date and Time Pickers
|
|
42
|
+
|
|
43
|
+
#### `@mui/x-date-pickers@7.1.1`
|
|
44
|
+
|
|
45
|
+
- [fields] Fix `readOnly` behavior (#12609) @LukasTy
|
|
46
|
+
- [l10n] Improve Persian (fa-IR) locale (#12632) @misafari
|
|
47
|
+
- [l10n] Improve Portuguese (pt-BR) locale (#12613) @cnHealth
|
|
48
|
+
- [l10n] Improve Ukrainian (uk-UA) locale (#12627) @alexkobylansky
|
|
49
|
+
|
|
50
|
+
#### `@mui/x-date-pickers-pro@7.1.1` [](https://mui.com/r/x-pro-svg-link 'Pro plan')
|
|
51
|
+
|
|
52
|
+
Same changes as in `@mui/x-date-pickers@7.1.1`, plus:
|
|
53
|
+
|
|
54
|
+
- [DateTimeRangePicker] Fix selection on same day (#12604) @LukasTy
|
|
55
|
+
|
|
56
|
+
### Charts
|
|
57
|
+
|
|
58
|
+
#### `@mui/x-charts@7.1.1`
|
|
59
|
+
|
|
60
|
+
- [charts] Fix `tickInterval` usage for y-axis (#12592) @alexfauquette
|
|
61
|
+
- [charts] Fix Scatter series highlight when `id` is a `number` (#12677) @JCQuintas
|
|
62
|
+
- [charts] Fix TS error when using `sx` property on `ChartsTooltip` (#12659) @JCQuintas
|
|
63
|
+
|
|
64
|
+
### Tree View
|
|
65
|
+
|
|
66
|
+
#### `@mui/x-tree-view@7.1.1`
|
|
67
|
+
|
|
68
|
+
- [TreeView] Add JSDoc to all `publicAPI` methods (#12649) @flaviendelangle
|
|
69
|
+
- [TreeView] Create `RichTreeViewPro` component (not released yet) (#12610) @flaviendelangle
|
|
70
|
+
- [TreeView] Create pro package (not released yet) (#12240) @flaviendelangle
|
|
71
|
+
- [TreeView] Fix typo in errors (#12623) @alissa-tung
|
|
72
|
+
- [TreeView] New API method: `setItemExpansion` (#12595) @flaviendelangle
|
|
73
|
+
|
|
74
|
+
### Docs
|
|
75
|
+
|
|
76
|
+
- [docs] Add a recipe for the `checkboxSelectionVisibleOnly` prop (#12646) @michelengelen
|
|
77
|
+
- [docs] Explain the use of `_action: 'delete'` in `processRowUpdate` (#12670) @michelengelen
|
|
78
|
+
- [docs] Fix formatting and typo on migration guide @oliviertassinari
|
|
79
|
+
- [docs] Fix formatting in changelog @oliviertassinari
|
|
80
|
+
- [docs] Fix grammar in TreeView migration doc (#12615) @joshkel
|
|
81
|
+
- [docs] Fix missing closing props in `PieShapeNoSnap` demo (#12636) @alp-ex
|
|
82
|
+
- [docs] Fix type arguments in Custom Field page (#12619) @Juneezee
|
|
83
|
+
- [docs] Fix typo in `getItemId` prop description (#12637) @flaviendelangle
|
|
84
|
+
- [docs] Make the Charts `margin` usage more visible (#12591) @alexfauquette
|
|
85
|
+
- [docs] Match IE 11 spacing with Material UI @oliviertassinari
|
|
86
|
+
- [docs] Move data grid interfaces to standard API page layout (#12016) @alexfauquette
|
|
87
|
+
- [docs] Remove ` around @default values (#12158) @alexfauquette
|
|
88
|
+
- [docs] Remove `day` from the default `dayOfWeekFormatter` function params (#12644) @LukasTy
|
|
89
|
+
- [docs] Use `TreeItem2` for icon expansion example on `RichTreeView` (#12563) @flaviendelangle
|
|
90
|
+
|
|
91
|
+
### Core
|
|
92
|
+
|
|
93
|
+
- [core] Add cherry-pick `master` to `v6` action (#12648) @LukasTy
|
|
94
|
+
- [core] Fix typo in `@mui/x-tree-view-pro/themeAugmentation` (#12674) @flaviendelangle
|
|
95
|
+
- [core] Introduce `describeTreeView` to run test on `SimpleTreeView` and `RichTreeView`, using `TreeItem` and `TreeItem2` + migrate expansion tests (#12428) @flaviendelangle
|
|
96
|
+
- [core] Limit `test-types` CI step allowed memory (#12651) @LukasTy
|
|
97
|
+
- [core] Remove explicit `express` package (#12602) @LukasTy
|
|
98
|
+
- [core] Update to new embedded translations in the docs package (#12232) @Janpot
|
|
99
|
+
- [core] Use PR labels to identify the package a `l10n` PR belongs to (#12639) @LukasTy
|
|
100
|
+
- [core] Use `describeTreeView` for selection tests (#12647) @flaviendelangle
|
|
101
|
+
- [docs-infra] Adjust the links to search for issues (#11995) @michelengelen
|
|
102
|
+
- [infra] Polish support survey experience (#12624) @oliviertassinari
|
|
103
|
+
- [support-infra] Replace author association with a permission check in survey action (#12068) @michelengelen
|
|
104
|
+
- [support-infra] Fix user permission check (#12669) @michelengelen
|
|
105
|
+
- [test] Fix Tree View test import (#12668) @LukasTy
|
|
106
|
+
|
|
6
107
|
## 7.1.0
|
|
7
108
|
|
|
8
109
|
_Mar 28, 2024_
|
|
@@ -74,7 +175,7 @@ Same changes as in `@mui/x-date-pickers@7.1.0`, plus:
|
|
|
74
175
|
- [core] Include `DateTimeRangePicker` tag in `releaseChangelog` (#12526) @LukasTy
|
|
75
176
|
- [core] Upgrade monorepo (#12536) @cherniavskii
|
|
76
177
|
|
|
77
|
-
##
|
|
178
|
+
## 7.0.0
|
|
78
179
|
|
|
79
180
|
_Mar 22, 2024_
|
|
80
181
|
|
|
@@ -530,13 +631,13 @@ We'd like to offer a big thanks to the 10 contributors who made this release pos
|
|
|
530
631
|
|
|
531
632
|
- 🎁 Introduce a new DOM structure for the field components that provides a better accessibility
|
|
532
633
|
- 🚀 Simplify Data Grid DOM structure for improved performance (#12013) @romgrk
|
|
533
|
-
- 🕥 The support for
|
|
634
|
+
- 🕥 The support for IE 11 has been removed (#12151) @flaviendelangle
|
|
534
635
|
- 🐞 Bugfixes
|
|
535
636
|
- 📚 Documentation improvements
|
|
536
637
|
|
|
537
638
|
### Breaking changes
|
|
538
639
|
|
|
539
|
-
- The support for
|
|
640
|
+
- The support for IE 11 has been removed from all MUI X packages. The `legacy` bundle that used to support old browsers like IE 11 is no longer included.
|
|
540
641
|
|
|
541
642
|
### Data Grid
|
|
542
643
|
|
|
@@ -641,7 +742,7 @@ These components are no longer exported from `@mui/x-charts`:
|
|
|
641
742
|
|
|
642
743
|
### Tree View / `@mui/x-tree-view@7.0.0-beta.4`
|
|
643
744
|
|
|
644
|
-
- [TreeView] Stop using custom `findIndex` to support
|
|
745
|
+
- [TreeView] Stop using custom `findIndex` to support IE 11 (#12129) @flaviendelangle
|
|
645
746
|
|
|
646
747
|
### Docs
|
|
647
748
|
|
|
@@ -2871,6 +2972,76 @@ Here is an example of the renaming for the `<ChartsTooltip />` component.
|
|
|
2871
2972
|
- [core] Update release instructions as per v7 configuration (#10962) @MBilalShafi
|
|
2872
2973
|
- [license] Correctly throw errors (#10924) @oliviertassinari
|
|
2873
2974
|
|
|
2975
|
+
## 6.19.9
|
|
2976
|
+
|
|
2977
|
+
_Apr 5, 2024_
|
|
2978
|
+
|
|
2979
|
+
We'd like to offer a big thanks to the 3 contributors who made this release possible. Here are some highlights ✨:
|
|
2980
|
+
|
|
2981
|
+
- 🐞 Bugfixes
|
|
2982
|
+
- 📚 Documentation improvements
|
|
2983
|
+
|
|
2984
|
+
### Data Grid
|
|
2985
|
+
|
|
2986
|
+
#### `@mui/x-data-grid@6.19.9`
|
|
2987
|
+
|
|
2988
|
+
- [DataGrid] Remove legacy editing API event: `rowEditCommit` (#12087) @MBilalShafi
|
|
2989
|
+
|
|
2990
|
+
#### `@mui/x-data-grid-pro@6.19.9` [](https://mui.com/r/x-pro-svg-link 'Pro plan')
|
|
2991
|
+
|
|
2992
|
+
Same changes as in `@mui/x-data-grid@6.19.9`.
|
|
2993
|
+
|
|
2994
|
+
#### `@mui/x-data-grid-premium@6.19.9` [](https://mui.com/r/x-premium-svg-link 'Premium plan')
|
|
2995
|
+
|
|
2996
|
+
Same changes as in `@mui/x-data-grid-pro@6.19.9`.
|
|
2997
|
+
|
|
2998
|
+
### Date Pickers
|
|
2999
|
+
|
|
3000
|
+
#### `@mui/x-date-pickers@6.19.9`
|
|
3001
|
+
|
|
3002
|
+
No changes.
|
|
3003
|
+
|
|
3004
|
+
#### `@mui/x-date-pickers-pro@6.19.9` [](https://mui.com/r/x-pro-svg-link 'Pro plan')
|
|
3005
|
+
|
|
3006
|
+
- [DateRangePicker] Fix selection behavior with single input field when `readOnly` (#12605) @LukasTy
|
|
3007
|
+
|
|
3008
|
+
### Docs
|
|
3009
|
+
|
|
3010
|
+
- [docs] Add a recipe for the `checkboxSelectionVisibleOnly` prop (#12667) @michelengelen
|
|
3011
|
+
- [docs] Explain the use of `_action: 'delete'` in `processRowUpdate` (#12673) @michelengelen
|
|
3012
|
+
|
|
3013
|
+
### Core
|
|
3014
|
+
|
|
3015
|
+
- [core] Use Circle CI context (#12607) @cherniavskii
|
|
3016
|
+
|
|
3017
|
+
## 6.19.8
|
|
3018
|
+
|
|
3019
|
+
_Mar 20, 2024_
|
|
3020
|
+
|
|
3021
|
+
We'd like to offer a big thanks to the 3 contributors who made this release possible.
|
|
3022
|
+
|
|
3023
|
+
### Data Grid
|
|
3024
|
+
|
|
3025
|
+
#### `@mui/x-data-grid@6.19.8`
|
|
3026
|
+
|
|
3027
|
+
- [DataGrid] Fix `ElementType` usage (#12505) @cherniavskii
|
|
3028
|
+
- [DataGrid] Fix cell value formatting on copy (#12483) @sai6855
|
|
3029
|
+
- [DataGrid] Fix checkbox selection when filtering (#12485) @g1mishra
|
|
3030
|
+
|
|
3031
|
+
#### `@mui/x-data-grid-pro@6.19.8` [](https://mui.com/r/x-pro-svg-link 'Pro plan')
|
|
3032
|
+
|
|
3033
|
+
Same changes as in `@mui/x-data-grid@6.19.8`.
|
|
3034
|
+
|
|
3035
|
+
#### `@mui/x-data-grid-premium@6.19.8` [](https://mui.com/r/x-premium-svg-link 'Premium plan')
|
|
3036
|
+
|
|
3037
|
+
Same changes as in `@mui/x-data-grid-pro@6.19.8`, plus:
|
|
3038
|
+
|
|
3039
|
+
- [DataGridPremium] Add support for confirmation before clipboard paste (#12466) @cherniavskii
|
|
3040
|
+
|
|
3041
|
+
### Docs
|
|
3042
|
+
|
|
3043
|
+
- [docs] Update links to v7 (#12495) @cherniavskii
|
|
3044
|
+
|
|
2874
3045
|
## 6.19.7
|
|
2875
3046
|
|
|
2876
3047
|
_Mar 14, 2024_
|
package/README.md
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# MUI X Tree View
|
|
2
2
|
|
|
3
|
-
This package is the
|
|
3
|
+
This package is the Community plan edition of the Tree View components.
|
|
4
4
|
It's part of [MUI X](https://mui.com/x/), an open-core extension of MUI Core, with advanced components.
|
|
5
5
|
|
|
6
6
|
## Installation
|
|
@@ -3,7 +3,7 @@ import { RichTreeViewProps } from './RichTreeView.types';
|
|
|
3
3
|
export declare const RichTreeViewRoot: import("@emotion/styled").StyledComponent<import("@mui/system").MUIStyledCommonProps<import("@mui/material/styles").Theme> & {
|
|
4
4
|
ownerState: RichTreeViewProps<any, any>;
|
|
5
5
|
}, Pick<React.DetailedHTMLProps<React.HTMLAttributes<HTMLUListElement>, HTMLUListElement>, keyof React.ClassAttributes<HTMLUListElement> | keyof React.HTMLAttributes<HTMLUListElement>>, {}>;
|
|
6
|
-
type
|
|
6
|
+
type RichTreeViewComponent = (<R extends {}, Multiple extends boolean | undefined = undefined>(props: RichTreeViewProps<R, Multiple> & React.RefAttributes<HTMLUListElement>) => React.JSX.Element) & {
|
|
7
7
|
propTypes?: any;
|
|
8
8
|
};
|
|
9
9
|
/**
|
|
@@ -16,5 +16,5 @@ type TreeViewComponent = (<R extends {}, Multiple extends boolean | undefined =
|
|
|
16
16
|
*
|
|
17
17
|
* - [RichTreeView API](https://mui.com/x/api/tree-view/rich-tree-view/)
|
|
18
18
|
*/
|
|
19
|
-
declare const RichTreeView:
|
|
19
|
+
declare const RichTreeView: RichTreeViewComponent;
|
|
20
20
|
export { RichTreeView };
|
|
@@ -29,7 +29,8 @@ export const RichTreeViewRoot = styled('ul', {
|
|
|
29
29
|
padding: 0,
|
|
30
30
|
margin: 0,
|
|
31
31
|
listStyle: 'none',
|
|
32
|
-
outline: 0
|
|
32
|
+
outline: 0,
|
|
33
|
+
position: 'relative'
|
|
33
34
|
});
|
|
34
35
|
function WrappedTreeItem({
|
|
35
36
|
slots,
|
|
@@ -138,7 +139,8 @@ process.env.NODE_ENV !== "production" ? RichTreeView.propTypes = {
|
|
|
138
139
|
apiRef: PropTypes.shape({
|
|
139
140
|
current: PropTypes.shape({
|
|
140
141
|
focusItem: PropTypes.func.isRequired,
|
|
141
|
-
getItem: PropTypes.func.isRequired
|
|
142
|
+
getItem: PropTypes.func.isRequired,
|
|
143
|
+
setItemExpansion: PropTypes.func.isRequired
|
|
142
144
|
})
|
|
143
145
|
}),
|
|
144
146
|
/**
|
|
@@ -174,12 +176,12 @@ process.env.NODE_ENV !== "production" ? RichTreeView.propTypes = {
|
|
|
174
176
|
*/
|
|
175
177
|
expandedItems: PropTypes.arrayOf(PropTypes.string),
|
|
176
178
|
/**
|
|
177
|
-
* Used to determine the
|
|
179
|
+
* Used to determine the id of a given item.
|
|
178
180
|
*
|
|
179
181
|
* @template R
|
|
180
182
|
* @param {R} item The item to check.
|
|
181
183
|
* @returns {string} The id of the item.
|
|
182
|
-
* @default
|
|
184
|
+
* @default (item) => item.id
|
|
183
185
|
*/
|
|
184
186
|
getItemId: PropTypes.func,
|
|
185
187
|
/**
|
|
@@ -188,7 +190,7 @@ process.env.NODE_ENV !== "production" ? RichTreeView.propTypes = {
|
|
|
188
190
|
* @template R
|
|
189
191
|
* @param {R} item The item to check.
|
|
190
192
|
* @returns {string} The label of the item.
|
|
191
|
-
* @default
|
|
193
|
+
* @default (item) => item.label
|
|
192
194
|
*/
|
|
193
195
|
getItemLabel: PropTypes.func,
|
|
194
196
|
/**
|
|
@@ -28,7 +28,8 @@ export const SimpleTreeViewRoot = styled('ul', {
|
|
|
28
28
|
padding: 0,
|
|
29
29
|
margin: 0,
|
|
30
30
|
listStyle: 'none',
|
|
31
|
-
outline: 0
|
|
31
|
+
outline: 0,
|
|
32
|
+
position: 'relative'
|
|
32
33
|
});
|
|
33
34
|
const EMPTY_ITEMS = [];
|
|
34
35
|
const itemsPropWarning = buildWarning(['MUI X: The `SimpleTreeView` component does not support the `items` prop.', 'If you want to add items, you need to pass them as JSX children.', 'Check the documentation for more details: https://mui.com/x/react-tree-view/simple-tree-view/items/']);
|
|
@@ -96,7 +97,8 @@ process.env.NODE_ENV !== "production" ? SimpleTreeView.propTypes = {
|
|
|
96
97
|
apiRef: PropTypes.shape({
|
|
97
98
|
current: PropTypes.shape({
|
|
98
99
|
focusItem: PropTypes.func.isRequired,
|
|
99
|
-
getItem: PropTypes.func.isRequired
|
|
100
|
+
getItem: PropTypes.func.isRequired,
|
|
101
|
+
setItemExpansion: PropTypes.func.isRequired
|
|
100
102
|
})
|
|
101
103
|
}),
|
|
102
104
|
/**
|
package/TreeView/TreeView.js
CHANGED
|
@@ -70,7 +70,8 @@ process.env.NODE_ENV !== "production" ? TreeView.propTypes = {
|
|
|
70
70
|
apiRef: PropTypes.shape({
|
|
71
71
|
current: PropTypes.shape({
|
|
72
72
|
focusItem: PropTypes.func.isRequired,
|
|
73
|
-
getItem: PropTypes.func.isRequired
|
|
73
|
+
getItem: PropTypes.func.isRequired,
|
|
74
|
+
setItemExpansion: PropTypes.func.isRequired
|
|
74
75
|
})
|
|
75
76
|
}),
|
|
76
77
|
/**
|
package/index.js
CHANGED
package/internals/index.d.ts
CHANGED
|
@@ -1,15 +1,25 @@
|
|
|
1
1
|
export { useTreeView } from './useTreeView';
|
|
2
2
|
export { TreeViewProvider } from './TreeViewProvider';
|
|
3
|
-
export
|
|
3
|
+
export { unstable_resetCleanupTracking } from './hooks/useInstanceEventHandler';
|
|
4
|
+
export type { TreeViewPlugin, TreeViewPluginSignature, ConvertPluginsIntoSignatures, MergePluginsProperty, TreeViewPublicAPI, } from './models';
|
|
4
5
|
export { DEFAULT_TREE_VIEW_PLUGINS } from './plugins/defaultPlugins';
|
|
5
6
|
export type { DefaultTreeViewPlugins, DefaultTreeViewPluginSlots, DefaultTreeViewPluginSlotProps, } from './plugins/defaultPlugins';
|
|
6
7
|
export type { DefaultTreeViewPluginParameters } from './plugins/defaultPlugins';
|
|
7
|
-
export
|
|
8
|
-
export type {
|
|
9
|
-
export
|
|
8
|
+
export { useTreeViewExpansion } from './plugins/useTreeViewExpansion';
|
|
9
|
+
export type { UseTreeViewExpansionSignature, UseTreeViewExpansionParameters, } from './plugins/useTreeViewExpansion';
|
|
10
|
+
export { useTreeViewSelection } from './plugins/useTreeViewSelection';
|
|
11
|
+
export type { UseTreeViewSelectionSignature, UseTreeViewSelectionParameters, } from './plugins/useTreeViewSelection';
|
|
12
|
+
export { useTreeViewFocus } from './plugins/useTreeViewFocus';
|
|
13
|
+
export type { UseTreeViewFocusSignature, UseTreeViewFocusParameters, } from './plugins/useTreeViewFocus';
|
|
14
|
+
export { useTreeViewKeyboardNavigation } from './plugins/useTreeViewKeyboardNavigation';
|
|
10
15
|
export type { UseTreeViewKeyboardNavigationSignature } from './plugins/useTreeViewKeyboardNavigation';
|
|
11
|
-
export
|
|
12
|
-
export type {
|
|
13
|
-
export
|
|
14
|
-
export type {
|
|
16
|
+
export { useTreeViewId } from './plugins/useTreeViewId';
|
|
17
|
+
export type { UseTreeViewIdSignature, UseTreeViewIdParameters } from './plugins/useTreeViewId';
|
|
18
|
+
export { useTreeViewIcons } from './plugins/useTreeViewIcons';
|
|
19
|
+
export type { UseTreeViewIconsSignature, UseTreeViewIconsParameters, } from './plugins/useTreeViewIcons';
|
|
20
|
+
export { useTreeViewItems } from './plugins/useTreeViewItems';
|
|
21
|
+
export type { UseTreeViewItemsSignature, UseTreeViewItemsParameters, } from './plugins/useTreeViewItems';
|
|
22
|
+
export { useTreeViewJSXItems } from './plugins/useTreeViewJSXItems';
|
|
23
|
+
export type { UseTreeViewJSXItemsSignature, UseTreeViewJSXItemsParameters, } from './plugins/useTreeViewJSXItems';
|
|
24
|
+
export { buildWarning } from './utils/warning';
|
|
15
25
|
export { extractPluginParamsFromProps } from './utils/extractPluginParamsFromProps';
|
package/internals/index.js
CHANGED
|
@@ -1,4 +1,15 @@
|
|
|
1
1
|
export { useTreeView } from './useTreeView';
|
|
2
2
|
export { TreeViewProvider } from './TreeViewProvider';
|
|
3
|
+
export { unstable_resetCleanupTracking } from './hooks/useInstanceEventHandler';
|
|
4
|
+
// Plugins
|
|
3
5
|
export { DEFAULT_TREE_VIEW_PLUGINS } from './plugins/defaultPlugins';
|
|
6
|
+
export { useTreeViewExpansion } from './plugins/useTreeViewExpansion';
|
|
7
|
+
export { useTreeViewSelection } from './plugins/useTreeViewSelection';
|
|
8
|
+
export { useTreeViewFocus } from './plugins/useTreeViewFocus';
|
|
9
|
+
export { useTreeViewKeyboardNavigation } from './plugins/useTreeViewKeyboardNavigation';
|
|
10
|
+
export { useTreeViewId } from './plugins/useTreeViewId';
|
|
11
|
+
export { useTreeViewIcons } from './plugins/useTreeViewIcons';
|
|
12
|
+
export { useTreeViewItems } from './plugins/useTreeViewItems';
|
|
13
|
+
export { useTreeViewJSXItems } from './plugins/useTreeViewJSXItems';
|
|
14
|
+
export { buildWarning } from './utils/warning';
|
|
4
15
|
export { extractPluginParamsFromProps } from './utils/extractPluginParamsFromProps';
|
|
@@ -97,7 +97,7 @@ type TreeViewUsedPlugins<TSignature extends TreeViewAnyPluginSignature> = [
|
|
|
97
97
|
TreeViewCorePluginsSignature,
|
|
98
98
|
...TSignature['dependantPlugins']
|
|
99
99
|
];
|
|
100
|
-
type TreeViewUsedParams<TSignature extends TreeViewAnyPluginSignature> = TSignature['params'] & MergePluginsProperty<TreeViewUsedPlugins<TSignature>, 'params'>;
|
|
100
|
+
export type TreeViewUsedParams<TSignature extends TreeViewAnyPluginSignature> = TSignature['params'] & MergePluginsProperty<TreeViewUsedPlugins<TSignature>, 'params'>;
|
|
101
101
|
type TreeViewUsedDefaultizedParams<TSignature extends TreeViewAnyPluginSignature> = TSignature['defaultizedParams'] & MergePluginsProperty<TreeViewUsedPlugins<TSignature>, 'defaultizedParams'>;
|
|
102
102
|
export type TreeViewUsedInstance<TSignature extends TreeViewAnyPluginSignature> = TSignature['instance'] & MergePluginsProperty<TreeViewUsedPlugins<TSignature>, 'instance'> & {
|
|
103
103
|
/**
|
|
@@ -1,33 +1,43 @@
|
|
|
1
1
|
import _extends from "@babel/runtime/helpers/esm/extends";
|
|
2
2
|
import * as React from 'react';
|
|
3
3
|
import useEventCallback from '@mui/utils/useEventCallback';
|
|
4
|
-
import { populateInstance } from '../../useTreeView/useTreeView.utils';
|
|
4
|
+
import { populateInstance, populatePublicAPI } from '../../useTreeView/useTreeView.utils';
|
|
5
5
|
export const useTreeViewExpansion = ({
|
|
6
6
|
instance,
|
|
7
|
+
publicAPI,
|
|
7
8
|
params,
|
|
8
9
|
models
|
|
9
10
|
}) => {
|
|
11
|
+
const expandedItemsMap = React.useMemo(() => {
|
|
12
|
+
const temp = new Map();
|
|
13
|
+
models.expandedItems.value.forEach(id => {
|
|
14
|
+
temp.set(id, true);
|
|
15
|
+
});
|
|
16
|
+
return temp;
|
|
17
|
+
}, [models.expandedItems.value]);
|
|
10
18
|
const setExpandedItems = (event, value) => {
|
|
11
19
|
params.onExpandedItemsChange?.(event, value);
|
|
12
20
|
models.expandedItems.setControlledValue(value);
|
|
13
21
|
};
|
|
14
|
-
const isItemExpanded = React.useCallback(itemId =>
|
|
15
|
-
return Array.isArray(models.expandedItems.value) ? models.expandedItems.value.indexOf(itemId) !== -1 : false;
|
|
16
|
-
}, [models.expandedItems.value]);
|
|
22
|
+
const isItemExpanded = React.useCallback(itemId => expandedItemsMap.has(itemId), [expandedItemsMap]);
|
|
17
23
|
const isItemExpandable = React.useCallback(itemId => !!instance.getNode(itemId)?.expandable, [instance]);
|
|
18
24
|
const toggleItemExpansion = useEventCallback((event, itemId) => {
|
|
19
|
-
|
|
25
|
+
const isExpandedBefore = instance.isItemExpanded(itemId);
|
|
26
|
+
instance.setItemExpansion(event, itemId, !isExpandedBefore);
|
|
27
|
+
});
|
|
28
|
+
const setItemExpansion = useEventCallback((event, itemId, isExpanded) => {
|
|
29
|
+
const isExpandedBefore = instance.isItemExpanded(itemId);
|
|
30
|
+
if (isExpandedBefore === isExpanded) {
|
|
20
31
|
return;
|
|
21
32
|
}
|
|
22
|
-
const isExpandedBefore = models.expandedItems.value.indexOf(itemId) !== -1;
|
|
23
33
|
let newExpanded;
|
|
24
|
-
if (
|
|
25
|
-
newExpanded = models.expandedItems.value.filter(id => id !== itemId);
|
|
26
|
-
} else {
|
|
34
|
+
if (isExpanded) {
|
|
27
35
|
newExpanded = [itemId].concat(models.expandedItems.value);
|
|
36
|
+
} else {
|
|
37
|
+
newExpanded = models.expandedItems.value.filter(id => id !== itemId);
|
|
28
38
|
}
|
|
29
39
|
if (params.onItemExpansionToggle) {
|
|
30
|
-
params.onItemExpansionToggle(event, itemId,
|
|
40
|
+
params.onItemExpansionToggle(event, itemId, isExpanded);
|
|
31
41
|
}
|
|
32
42
|
setExpandedItems(event, newExpanded);
|
|
33
43
|
});
|
|
@@ -48,9 +58,13 @@ export const useTreeViewExpansion = ({
|
|
|
48
58
|
populateInstance(instance, {
|
|
49
59
|
isItemExpanded,
|
|
50
60
|
isItemExpandable,
|
|
61
|
+
setItemExpansion,
|
|
51
62
|
toggleItemExpansion,
|
|
52
63
|
expandAllSiblings
|
|
53
64
|
});
|
|
65
|
+
populatePublicAPI(publicAPI, {
|
|
66
|
+
setItemExpansion
|
|
67
|
+
});
|
|
54
68
|
};
|
|
55
69
|
useTreeViewExpansion.models = {
|
|
56
70
|
expandedItems: {
|
|
@@ -1,10 +1,19 @@
|
|
|
1
1
|
import * as React from 'react';
|
|
2
2
|
import { DefaultizedProps, TreeViewPluginSignature } from '../../models';
|
|
3
3
|
import { UseTreeViewItemsSignature } from '../useTreeViewItems';
|
|
4
|
-
export interface
|
|
4
|
+
export interface UseTreeViewExpansionPublicAPI {
|
|
5
|
+
/**
|
|
6
|
+
* Change the expansion status of a given item.
|
|
7
|
+
* @param {React.SyntheticEvent} event The UI event that triggered the change.
|
|
8
|
+
* @param {string} itemId The id of the item to modify.
|
|
9
|
+
* @param {boolean} isExpanded The new expansion status of the given item.
|
|
10
|
+
*/
|
|
11
|
+
setItemExpansion: (event: React.SyntheticEvent, itemId: string, isExpanded: boolean) => void;
|
|
12
|
+
}
|
|
13
|
+
export interface UseTreeViewExpansionInstance extends UseTreeViewExpansionPublicAPI {
|
|
5
14
|
isItemExpanded: (itemId: string) => boolean;
|
|
6
15
|
isItemExpandable: (itemId: string) => boolean;
|
|
7
|
-
toggleItemExpansion: (event: React.SyntheticEvent,
|
|
16
|
+
toggleItemExpansion: (event: React.SyntheticEvent, itemId: string) => void;
|
|
8
17
|
expandAllSiblings: (event: React.KeyboardEvent, itemId: string) => void;
|
|
9
18
|
}
|
|
10
19
|
export interface UseTreeViewExpansionParameters {
|
|
@@ -38,6 +47,7 @@ export type UseTreeViewExpansionSignature = TreeViewPluginSignature<{
|
|
|
38
47
|
params: UseTreeViewExpansionParameters;
|
|
39
48
|
defaultizedParams: UseTreeViewExpansionDefaultizedParameters;
|
|
40
49
|
instance: UseTreeViewExpansionInstance;
|
|
50
|
+
publicAPI: UseTreeViewExpansionPublicAPI;
|
|
41
51
|
modelNames: 'expandedItems';
|
|
42
52
|
dependantPlugins: [UseTreeViewItemsSignature];
|
|
43
53
|
}>;
|
|
@@ -4,15 +4,23 @@ import { UseTreeViewIdSignature } from '../useTreeViewId/useTreeViewId.types';
|
|
|
4
4
|
import type { UseTreeViewItemsSignature } from '../useTreeViewItems';
|
|
5
5
|
import type { UseTreeViewSelectionSignature } from '../useTreeViewSelection';
|
|
6
6
|
import { UseTreeViewExpansionSignature } from '../useTreeViewExpansion';
|
|
7
|
-
export interface
|
|
7
|
+
export interface UseTreeViewFocusPublicAPI {
|
|
8
|
+
/**
|
|
9
|
+
* Focuses the item with the given id.
|
|
10
|
+
*
|
|
11
|
+
* If the item is the child of a collapsed item, then this method will do nothing.
|
|
12
|
+
* Make sure to expand the ancestors of the item before calling this method if needed.
|
|
13
|
+
* @param {React.SyntheticEvent} event The event source of the action.
|
|
14
|
+
* @param {string} itemId The id of the item to focus.
|
|
15
|
+
*/
|
|
16
|
+
focusItem: (event: React.SyntheticEvent, itemId: string) => void;
|
|
17
|
+
}
|
|
18
|
+
export interface UseTreeViewFocusInstance extends UseTreeViewFocusPublicAPI {
|
|
8
19
|
isItemFocused: (itemId: string) => boolean;
|
|
9
20
|
canItemBeTabbed: (itemId: string) => boolean;
|
|
10
|
-
focusItem: (event: React.SyntheticEvent, itemId: string) => void;
|
|
11
21
|
focusDefaultItem: (event: React.SyntheticEvent | null) => void;
|
|
12
22
|
removeFocusedItem: () => void;
|
|
13
23
|
}
|
|
14
|
-
export interface UseTreeViewFocusPublicAPI extends Pick<UseTreeViewFocusInstance, 'focusItem'> {
|
|
15
|
-
}
|
|
16
24
|
export interface UseTreeViewFocusParameters {
|
|
17
25
|
/**
|
|
18
26
|
* Callback fired when tree items are focused.
|
|
@@ -16,7 +16,7 @@ const updateItemsState = ({
|
|
|
16
16
|
throw new Error(['MUI X: The Tree View component requires all items to have a unique `id` property.', 'Alternatively, you can use the `getItemId` prop to specify a custom id for each item.', 'An item was provided without id in the `items` prop:', JSON.stringify(item)].join('\n'));
|
|
17
17
|
}
|
|
18
18
|
if (nodeMap[id] != null) {
|
|
19
|
-
throw new Error(['MUI X: The Tree View component requires all items to have a unique `id` property.', 'Alternatively, you can use the `getItemId` prop to specify a custom id for each item.', `
|
|
19
|
+
throw new Error(['MUI X: The Tree View component requires all items to have a unique `id` property.', 'Alternatively, you can use the `getItemId` prop to specify a custom id for each item.', `Two items were provided with the same id in the \`items\` prop: "${id}"`].join('\n'));
|
|
20
20
|
}
|
|
21
21
|
const label = getItemLabel ? getItemLabel(item) : item.label;
|
|
22
22
|
if (label == null) {
|
|
@@ -6,9 +6,16 @@ interface TreeViewItemProps {
|
|
|
6
6
|
id: string | undefined;
|
|
7
7
|
children?: TreeViewItemProps[];
|
|
8
8
|
}
|
|
9
|
-
export interface
|
|
10
|
-
|
|
9
|
+
export interface UseTreeViewItemsPublicAPI<R extends {}> {
|
|
10
|
+
/**
|
|
11
|
+
* Get the item with the given id.
|
|
12
|
+
* @param {string} itemId The id of the item to return.
|
|
13
|
+
* @returns {R} The item with the given id.
|
|
14
|
+
*/
|
|
11
15
|
getItem: (itemId: string) => R;
|
|
16
|
+
}
|
|
17
|
+
export interface UseTreeViewItemsInstance<R extends {}> extends UseTreeViewItemsPublicAPI<R> {
|
|
18
|
+
getNode: (itemId: string) => TreeViewNode;
|
|
12
19
|
getItemsToRender: () => TreeViewItemProps[];
|
|
13
20
|
getChildrenIds: (itemId: string | null) => string[];
|
|
14
21
|
getNavigableChildrenIds: (itemId: string | null) => string[];
|
|
@@ -25,8 +32,6 @@ export interface UseTreeViewItemsInstance<R extends {}> {
|
|
|
25
32
|
*/
|
|
26
33
|
areItemUpdatesPrevented: () => boolean;
|
|
27
34
|
}
|
|
28
|
-
export interface UseTreeViewItemsPublicAPI<R extends {}> extends Pick<UseTreeViewItemsInstance<R>, 'getItem'> {
|
|
29
|
-
}
|
|
30
35
|
export interface UseTreeViewItemsParameters<R extends {}> {
|
|
31
36
|
/**
|
|
32
37
|
* If `true`, will allow focus on disabled items.
|
|
@@ -47,16 +52,16 @@ export interface UseTreeViewItemsParameters<R extends {}> {
|
|
|
47
52
|
* @template R
|
|
48
53
|
* @param {R} item The item to check.
|
|
49
54
|
* @returns {string} The label of the item.
|
|
50
|
-
* @default
|
|
55
|
+
* @default (item) => item.label
|
|
51
56
|
*/
|
|
52
57
|
getItemLabel?: (item: R) => string;
|
|
53
58
|
/**
|
|
54
|
-
* Used to determine the
|
|
59
|
+
* Used to determine the id of a given item.
|
|
55
60
|
*
|
|
56
61
|
* @template R
|
|
57
62
|
* @param {R} item The item to check.
|
|
58
63
|
* @returns {string} The id of the item.
|
|
59
|
-
* @default
|
|
64
|
+
* @default (item) => item.id
|
|
60
65
|
*/
|
|
61
66
|
getItemId?: (item: R) => TreeViewItemId;
|
|
62
67
|
}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
export { useTreeViewJSXItems } from './useTreeViewJSXItems';
|
|
2
|
-
export type { UseTreeViewJSXItemsSignature,
|
|
2
|
+
export type { UseTreeViewJSXItemsSignature, UseTreeViewJSXItemsParameters, UseTreeViewItemsDefaultizedParameters, } from './useTreeViewJSXItems.types';
|
|
@@ -15,7 +15,7 @@ export const useTreeViewJSXItems = ({
|
|
|
15
15
|
const insertJSXItem = useEventCallback(item => {
|
|
16
16
|
setState(prevState => {
|
|
17
17
|
if (prevState.items.nodeMap[item.id] != null) {
|
|
18
|
-
throw new Error(['MUI X: The Tree View component requires all items to have a unique `id` property.', 'Alternatively, you can use the `getItemId` prop to specify a custom id for each item.', `
|
|
18
|
+
throw new Error(['MUI X: The Tree View component requires all items to have a unique `id` property.', 'Alternatively, you can use the `getItemId` prop to specify a custom id for each item.', `Two items were provided with the same id in the \`items\` prop: "${item.id}"`].join('\n'));
|
|
19
19
|
}
|
|
20
20
|
return _extends({}, prevState, {
|
|
21
21
|
items: _extends({}, prevState.items, {
|
|
@@ -6,12 +6,12 @@ export interface UseTreeViewItemsInstance {
|
|
|
6
6
|
removeJSXItem: (itemId: string) => void;
|
|
7
7
|
mapFirstCharFromJSX: (itemId: string, firstChar: string) => () => void;
|
|
8
8
|
}
|
|
9
|
-
export interface
|
|
9
|
+
export interface UseTreeViewJSXItemsParameters {
|
|
10
10
|
}
|
|
11
11
|
export interface UseTreeViewItemsDefaultizedParameters {
|
|
12
12
|
}
|
|
13
13
|
export type UseTreeViewJSXItemsSignature = TreeViewPluginSignature<{
|
|
14
|
-
params:
|
|
14
|
+
params: UseTreeViewJSXItemsParameters;
|
|
15
15
|
defaultizedParams: UseTreeViewItemsDefaultizedParameters;
|
|
16
16
|
instance: UseTreeViewItemsInstance;
|
|
17
17
|
dependantPlugins: [UseTreeViewItemsSignature, UseTreeViewKeyboardNavigationSignature];
|
|
@@ -22,7 +22,7 @@ export const useTreeViewModels = (plugins, props) => {
|
|
|
22
22
|
return initialState;
|
|
23
23
|
});
|
|
24
24
|
const models = Object.fromEntries(Object.entries(modelsRef.current).map(([modelName, model]) => {
|
|
25
|
-
const value =
|
|
25
|
+
const value = props[modelName] ?? modelsState[modelName];
|
|
26
26
|
return [modelName, {
|
|
27
27
|
value,
|
|
28
28
|
setControlledValue: newValue => {
|
|
@@ -53,7 +53,7 @@ export const useTreeViewModels = (plugins, props) => {
|
|
|
53
53
|
if (!model.isControlled && defaultValue !== newDefaultValue) {
|
|
54
54
|
console.error([`MUI X: A component is changing the default ${modelName} state of an uncontrolled TreeView after being initialized. ` + `To suppress this warning opt to use a controlled TreeView.`].join('\n'));
|
|
55
55
|
}
|
|
56
|
-
}, [JSON.stringify(
|
|
56
|
+
}, [JSON.stringify(newDefaultValue)]);
|
|
57
57
|
});
|
|
58
58
|
}
|
|
59
59
|
/* eslint-enable react-hooks/rules-of-hooks, react-hooks/exhaustive-deps */
|
|
@@ -29,7 +29,8 @@ export const RichTreeViewRoot = styled('ul', {
|
|
|
29
29
|
padding: 0,
|
|
30
30
|
margin: 0,
|
|
31
31
|
listStyle: 'none',
|
|
32
|
-
outline: 0
|
|
32
|
+
outline: 0,
|
|
33
|
+
position: 'relative'
|
|
33
34
|
});
|
|
34
35
|
function WrappedTreeItem({
|
|
35
36
|
slots,
|
|
@@ -138,7 +139,8 @@ process.env.NODE_ENV !== "production" ? RichTreeView.propTypes = {
|
|
|
138
139
|
apiRef: PropTypes.shape({
|
|
139
140
|
current: PropTypes.shape({
|
|
140
141
|
focusItem: PropTypes.func.isRequired,
|
|
141
|
-
getItem: PropTypes.func.isRequired
|
|
142
|
+
getItem: PropTypes.func.isRequired,
|
|
143
|
+
setItemExpansion: PropTypes.func.isRequired
|
|
142
144
|
})
|
|
143
145
|
}),
|
|
144
146
|
/**
|
|
@@ -174,12 +176,12 @@ process.env.NODE_ENV !== "production" ? RichTreeView.propTypes = {
|
|
|
174
176
|
*/
|
|
175
177
|
expandedItems: PropTypes.arrayOf(PropTypes.string),
|
|
176
178
|
/**
|
|
177
|
-
* Used to determine the
|
|
179
|
+
* Used to determine the id of a given item.
|
|
178
180
|
*
|
|
179
181
|
* @template R
|
|
180
182
|
* @param {R} item The item to check.
|
|
181
183
|
* @returns {string} The id of the item.
|
|
182
|
-
* @default
|
|
184
|
+
* @default (item) => item.id
|
|
183
185
|
*/
|
|
184
186
|
getItemId: PropTypes.func,
|
|
185
187
|
/**
|
|
@@ -188,7 +190,7 @@ process.env.NODE_ENV !== "production" ? RichTreeView.propTypes = {
|
|
|
188
190
|
* @template R
|
|
189
191
|
* @param {R} item The item to check.
|
|
190
192
|
* @returns {string} The label of the item.
|
|
191
|
-
* @default
|
|
193
|
+
* @default (item) => item.label
|
|
192
194
|
*/
|
|
193
195
|
getItemLabel: PropTypes.func,
|
|
194
196
|
/**
|
|
@@ -28,7 +28,8 @@ export const SimpleTreeViewRoot = styled('ul', {
|
|
|
28
28
|
padding: 0,
|
|
29
29
|
margin: 0,
|
|
30
30
|
listStyle: 'none',
|
|
31
|
-
outline: 0
|
|
31
|
+
outline: 0,
|
|
32
|
+
position: 'relative'
|
|
32
33
|
});
|
|
33
34
|
const EMPTY_ITEMS = [];
|
|
34
35
|
const itemsPropWarning = buildWarning(['MUI X: The `SimpleTreeView` component does not support the `items` prop.', 'If you want to add items, you need to pass them as JSX children.', 'Check the documentation for more details: https://mui.com/x/react-tree-view/simple-tree-view/items/']);
|
|
@@ -96,7 +97,8 @@ process.env.NODE_ENV !== "production" ? SimpleTreeView.propTypes = {
|
|
|
96
97
|
apiRef: PropTypes.shape({
|
|
97
98
|
current: PropTypes.shape({
|
|
98
99
|
focusItem: PropTypes.func.isRequired,
|
|
99
|
-
getItem: PropTypes.func.isRequired
|
|
100
|
+
getItem: PropTypes.func.isRequired,
|
|
101
|
+
setItemExpansion: PropTypes.func.isRequired
|
|
100
102
|
})
|
|
101
103
|
}),
|
|
102
104
|
/**
|
|
@@ -70,7 +70,8 @@ process.env.NODE_ENV !== "production" ? TreeView.propTypes = {
|
|
|
70
70
|
apiRef: PropTypes.shape({
|
|
71
71
|
current: PropTypes.shape({
|
|
72
72
|
focusItem: PropTypes.func.isRequired,
|
|
73
|
-
getItem: PropTypes.func.isRequired
|
|
73
|
+
getItem: PropTypes.func.isRequired,
|
|
74
|
+
setItemExpansion: PropTypes.func.isRequired
|
|
74
75
|
})
|
|
75
76
|
}),
|
|
76
77
|
/**
|
package/modern/index.js
CHANGED
|
@@ -1,4 +1,15 @@
|
|
|
1
1
|
export { useTreeView } from './useTreeView';
|
|
2
2
|
export { TreeViewProvider } from './TreeViewProvider';
|
|
3
|
+
export { unstable_resetCleanupTracking } from './hooks/useInstanceEventHandler';
|
|
4
|
+
// Plugins
|
|
3
5
|
export { DEFAULT_TREE_VIEW_PLUGINS } from './plugins/defaultPlugins';
|
|
6
|
+
export { useTreeViewExpansion } from './plugins/useTreeViewExpansion';
|
|
7
|
+
export { useTreeViewSelection } from './plugins/useTreeViewSelection';
|
|
8
|
+
export { useTreeViewFocus } from './plugins/useTreeViewFocus';
|
|
9
|
+
export { useTreeViewKeyboardNavigation } from './plugins/useTreeViewKeyboardNavigation';
|
|
10
|
+
export { useTreeViewId } from './plugins/useTreeViewId';
|
|
11
|
+
export { useTreeViewIcons } from './plugins/useTreeViewIcons';
|
|
12
|
+
export { useTreeViewItems } from './plugins/useTreeViewItems';
|
|
13
|
+
export { useTreeViewJSXItems } from './plugins/useTreeViewJSXItems';
|
|
14
|
+
export { buildWarning } from './utils/warning';
|
|
4
15
|
export { extractPluginParamsFromProps } from './utils/extractPluginParamsFromProps';
|
|
@@ -1,33 +1,43 @@
|
|
|
1
1
|
import _extends from "@babel/runtime/helpers/esm/extends";
|
|
2
2
|
import * as React from 'react';
|
|
3
3
|
import useEventCallback from '@mui/utils/useEventCallback';
|
|
4
|
-
import { populateInstance } from '../../useTreeView/useTreeView.utils';
|
|
4
|
+
import { populateInstance, populatePublicAPI } from '../../useTreeView/useTreeView.utils';
|
|
5
5
|
export const useTreeViewExpansion = ({
|
|
6
6
|
instance,
|
|
7
|
+
publicAPI,
|
|
7
8
|
params,
|
|
8
9
|
models
|
|
9
10
|
}) => {
|
|
11
|
+
const expandedItemsMap = React.useMemo(() => {
|
|
12
|
+
const temp = new Map();
|
|
13
|
+
models.expandedItems.value.forEach(id => {
|
|
14
|
+
temp.set(id, true);
|
|
15
|
+
});
|
|
16
|
+
return temp;
|
|
17
|
+
}, [models.expandedItems.value]);
|
|
10
18
|
const setExpandedItems = (event, value) => {
|
|
11
19
|
params.onExpandedItemsChange?.(event, value);
|
|
12
20
|
models.expandedItems.setControlledValue(value);
|
|
13
21
|
};
|
|
14
|
-
const isItemExpanded = React.useCallback(itemId =>
|
|
15
|
-
return Array.isArray(models.expandedItems.value) ? models.expandedItems.value.indexOf(itemId) !== -1 : false;
|
|
16
|
-
}, [models.expandedItems.value]);
|
|
22
|
+
const isItemExpanded = React.useCallback(itemId => expandedItemsMap.has(itemId), [expandedItemsMap]);
|
|
17
23
|
const isItemExpandable = React.useCallback(itemId => !!instance.getNode(itemId)?.expandable, [instance]);
|
|
18
24
|
const toggleItemExpansion = useEventCallback((event, itemId) => {
|
|
19
|
-
|
|
25
|
+
const isExpandedBefore = instance.isItemExpanded(itemId);
|
|
26
|
+
instance.setItemExpansion(event, itemId, !isExpandedBefore);
|
|
27
|
+
});
|
|
28
|
+
const setItemExpansion = useEventCallback((event, itemId, isExpanded) => {
|
|
29
|
+
const isExpandedBefore = instance.isItemExpanded(itemId);
|
|
30
|
+
if (isExpandedBefore === isExpanded) {
|
|
20
31
|
return;
|
|
21
32
|
}
|
|
22
|
-
const isExpandedBefore = models.expandedItems.value.indexOf(itemId) !== -1;
|
|
23
33
|
let newExpanded;
|
|
24
|
-
if (
|
|
25
|
-
newExpanded = models.expandedItems.value.filter(id => id !== itemId);
|
|
26
|
-
} else {
|
|
34
|
+
if (isExpanded) {
|
|
27
35
|
newExpanded = [itemId].concat(models.expandedItems.value);
|
|
36
|
+
} else {
|
|
37
|
+
newExpanded = models.expandedItems.value.filter(id => id !== itemId);
|
|
28
38
|
}
|
|
29
39
|
if (params.onItemExpansionToggle) {
|
|
30
|
-
params.onItemExpansionToggle(event, itemId,
|
|
40
|
+
params.onItemExpansionToggle(event, itemId, isExpanded);
|
|
31
41
|
}
|
|
32
42
|
setExpandedItems(event, newExpanded);
|
|
33
43
|
});
|
|
@@ -48,9 +58,13 @@ export const useTreeViewExpansion = ({
|
|
|
48
58
|
populateInstance(instance, {
|
|
49
59
|
isItemExpanded,
|
|
50
60
|
isItemExpandable,
|
|
61
|
+
setItemExpansion,
|
|
51
62
|
toggleItemExpansion,
|
|
52
63
|
expandAllSiblings
|
|
53
64
|
});
|
|
65
|
+
populatePublicAPI(publicAPI, {
|
|
66
|
+
setItemExpansion
|
|
67
|
+
});
|
|
54
68
|
};
|
|
55
69
|
useTreeViewExpansion.models = {
|
|
56
70
|
expandedItems: {
|
|
@@ -16,7 +16,7 @@ const updateItemsState = ({
|
|
|
16
16
|
throw new Error(['MUI X: The Tree View component requires all items to have a unique `id` property.', 'Alternatively, you can use the `getItemId` prop to specify a custom id for each item.', 'An item was provided without id in the `items` prop:', JSON.stringify(item)].join('\n'));
|
|
17
17
|
}
|
|
18
18
|
if (nodeMap[id] != null) {
|
|
19
|
-
throw new Error(['MUI X: The Tree View component requires all items to have a unique `id` property.', 'Alternatively, you can use the `getItemId` prop to specify a custom id for each item.', `
|
|
19
|
+
throw new Error(['MUI X: The Tree View component requires all items to have a unique `id` property.', 'Alternatively, you can use the `getItemId` prop to specify a custom id for each item.', `Two items were provided with the same id in the \`items\` prop: "${id}"`].join('\n'));
|
|
20
20
|
}
|
|
21
21
|
const label = getItemLabel ? getItemLabel(item) : item.label;
|
|
22
22
|
if (label == null) {
|
|
@@ -15,7 +15,7 @@ export const useTreeViewJSXItems = ({
|
|
|
15
15
|
const insertJSXItem = useEventCallback(item => {
|
|
16
16
|
setState(prevState => {
|
|
17
17
|
if (prevState.items.nodeMap[item.id] != null) {
|
|
18
|
-
throw new Error(['MUI X: The Tree View component requires all items to have a unique `id` property.', 'Alternatively, you can use the `getItemId` prop to specify a custom id for each item.', `
|
|
18
|
+
throw new Error(['MUI X: The Tree View component requires all items to have a unique `id` property.', 'Alternatively, you can use the `getItemId` prop to specify a custom id for each item.', `Two items were provided with the same id in the \`items\` prop: "${item.id}"`].join('\n'));
|
|
19
19
|
}
|
|
20
20
|
return _extends({}, prevState, {
|
|
21
21
|
items: _extends({}, prevState.items, {
|
|
@@ -22,7 +22,7 @@ export const useTreeViewModels = (plugins, props) => {
|
|
|
22
22
|
return initialState;
|
|
23
23
|
});
|
|
24
24
|
const models = Object.fromEntries(Object.entries(modelsRef.current).map(([modelName, model]) => {
|
|
25
|
-
const value =
|
|
25
|
+
const value = props[modelName] ?? modelsState[modelName];
|
|
26
26
|
return [modelName, {
|
|
27
27
|
value,
|
|
28
28
|
setControlledValue: newValue => {
|
|
@@ -53,7 +53,7 @@ export const useTreeViewModels = (plugins, props) => {
|
|
|
53
53
|
if (!model.isControlled && defaultValue !== newDefaultValue) {
|
|
54
54
|
console.error([`MUI X: A component is changing the default ${modelName} state of an uncontrolled TreeView after being initialized. ` + `To suppress this warning opt to use a controlled TreeView.`].join('\n'));
|
|
55
55
|
}
|
|
56
|
-
}, [JSON.stringify(
|
|
56
|
+
}, [JSON.stringify(newDefaultValue)]);
|
|
57
57
|
});
|
|
58
58
|
}
|
|
59
59
|
/* eslint-enable react-hooks/rules-of-hooks, react-hooks/exhaustive-deps */
|
|
@@ -38,7 +38,8 @@ const RichTreeViewRoot = exports.RichTreeViewRoot = (0, _styles.styled)('ul', {
|
|
|
38
38
|
padding: 0,
|
|
39
39
|
margin: 0,
|
|
40
40
|
listStyle: 'none',
|
|
41
|
-
outline: 0
|
|
41
|
+
outline: 0,
|
|
42
|
+
position: 'relative'
|
|
42
43
|
});
|
|
43
44
|
function WrappedTreeItem({
|
|
44
45
|
slots,
|
|
@@ -147,7 +148,8 @@ process.env.NODE_ENV !== "production" ? RichTreeView.propTypes = {
|
|
|
147
148
|
apiRef: _propTypes.default.shape({
|
|
148
149
|
current: _propTypes.default.shape({
|
|
149
150
|
focusItem: _propTypes.default.func.isRequired,
|
|
150
|
-
getItem: _propTypes.default.func.isRequired
|
|
151
|
+
getItem: _propTypes.default.func.isRequired,
|
|
152
|
+
setItemExpansion: _propTypes.default.func.isRequired
|
|
151
153
|
})
|
|
152
154
|
}),
|
|
153
155
|
/**
|
|
@@ -183,12 +185,12 @@ process.env.NODE_ENV !== "production" ? RichTreeView.propTypes = {
|
|
|
183
185
|
*/
|
|
184
186
|
expandedItems: _propTypes.default.arrayOf(_propTypes.default.string),
|
|
185
187
|
/**
|
|
186
|
-
* Used to determine the
|
|
188
|
+
* Used to determine the id of a given item.
|
|
187
189
|
*
|
|
188
190
|
* @template R
|
|
189
191
|
* @param {R} item The item to check.
|
|
190
192
|
* @returns {string} The id of the item.
|
|
191
|
-
* @default
|
|
193
|
+
* @default (item) => item.id
|
|
192
194
|
*/
|
|
193
195
|
getItemId: _propTypes.default.func,
|
|
194
196
|
/**
|
|
@@ -197,7 +199,7 @@ process.env.NODE_ENV !== "production" ? RichTreeView.propTypes = {
|
|
|
197
199
|
* @template R
|
|
198
200
|
* @param {R} item The item to check.
|
|
199
201
|
* @returns {string} The label of the item.
|
|
200
|
-
* @default
|
|
202
|
+
* @default (item) => item.label
|
|
201
203
|
*/
|
|
202
204
|
getItemLabel: _propTypes.default.func,
|
|
203
205
|
/**
|
|
@@ -37,7 +37,8 @@ const SimpleTreeViewRoot = exports.SimpleTreeViewRoot = (0, _styles.styled)('ul'
|
|
|
37
37
|
padding: 0,
|
|
38
38
|
margin: 0,
|
|
39
39
|
listStyle: 'none',
|
|
40
|
-
outline: 0
|
|
40
|
+
outline: 0,
|
|
41
|
+
position: 'relative'
|
|
41
42
|
});
|
|
42
43
|
const EMPTY_ITEMS = [];
|
|
43
44
|
const itemsPropWarning = (0, _warning.buildWarning)(['MUI X: The `SimpleTreeView` component does not support the `items` prop.', 'If you want to add items, you need to pass them as JSX children.', 'Check the documentation for more details: https://mui.com/x/react-tree-view/simple-tree-view/items/']);
|
|
@@ -105,7 +106,8 @@ process.env.NODE_ENV !== "production" ? SimpleTreeView.propTypes = {
|
|
|
105
106
|
apiRef: _propTypes.default.shape({
|
|
106
107
|
current: _propTypes.default.shape({
|
|
107
108
|
focusItem: _propTypes.default.func.isRequired,
|
|
108
|
-
getItem: _propTypes.default.func.isRequired
|
|
109
|
+
getItem: _propTypes.default.func.isRequired,
|
|
110
|
+
setItemExpansion: _propTypes.default.func.isRequired
|
|
109
111
|
})
|
|
110
112
|
}),
|
|
111
113
|
/**
|
|
@@ -79,7 +79,8 @@ process.env.NODE_ENV !== "production" ? TreeView.propTypes = {
|
|
|
79
79
|
apiRef: _propTypes.default.shape({
|
|
80
80
|
current: _propTypes.default.shape({
|
|
81
81
|
focusItem: _propTypes.default.func.isRequired,
|
|
82
|
-
getItem: _propTypes.default.func.isRequired
|
|
82
|
+
getItem: _propTypes.default.func.isRequired,
|
|
83
|
+
setItemExpansion: _propTypes.default.func.isRequired
|
|
83
84
|
})
|
|
84
85
|
}),
|
|
85
86
|
/**
|
package/node/index.js
CHANGED
package/node/internals/index.js
CHANGED
|
@@ -15,19 +15,89 @@ Object.defineProperty(exports, "TreeViewProvider", {
|
|
|
15
15
|
return _TreeViewProvider.TreeViewProvider;
|
|
16
16
|
}
|
|
17
17
|
});
|
|
18
|
+
Object.defineProperty(exports, "buildWarning", {
|
|
19
|
+
enumerable: true,
|
|
20
|
+
get: function () {
|
|
21
|
+
return _warning.buildWarning;
|
|
22
|
+
}
|
|
23
|
+
});
|
|
18
24
|
Object.defineProperty(exports, "extractPluginParamsFromProps", {
|
|
19
25
|
enumerable: true,
|
|
20
26
|
get: function () {
|
|
21
27
|
return _extractPluginParamsFromProps.extractPluginParamsFromProps;
|
|
22
28
|
}
|
|
23
29
|
});
|
|
30
|
+
Object.defineProperty(exports, "unstable_resetCleanupTracking", {
|
|
31
|
+
enumerable: true,
|
|
32
|
+
get: function () {
|
|
33
|
+
return _useInstanceEventHandler.unstable_resetCleanupTracking;
|
|
34
|
+
}
|
|
35
|
+
});
|
|
24
36
|
Object.defineProperty(exports, "useTreeView", {
|
|
25
37
|
enumerable: true,
|
|
26
38
|
get: function () {
|
|
27
39
|
return _useTreeView.useTreeView;
|
|
28
40
|
}
|
|
29
41
|
});
|
|
42
|
+
Object.defineProperty(exports, "useTreeViewExpansion", {
|
|
43
|
+
enumerable: true,
|
|
44
|
+
get: function () {
|
|
45
|
+
return _useTreeViewExpansion.useTreeViewExpansion;
|
|
46
|
+
}
|
|
47
|
+
});
|
|
48
|
+
Object.defineProperty(exports, "useTreeViewFocus", {
|
|
49
|
+
enumerable: true,
|
|
50
|
+
get: function () {
|
|
51
|
+
return _useTreeViewFocus.useTreeViewFocus;
|
|
52
|
+
}
|
|
53
|
+
});
|
|
54
|
+
Object.defineProperty(exports, "useTreeViewIcons", {
|
|
55
|
+
enumerable: true,
|
|
56
|
+
get: function () {
|
|
57
|
+
return _useTreeViewIcons.useTreeViewIcons;
|
|
58
|
+
}
|
|
59
|
+
});
|
|
60
|
+
Object.defineProperty(exports, "useTreeViewId", {
|
|
61
|
+
enumerable: true,
|
|
62
|
+
get: function () {
|
|
63
|
+
return _useTreeViewId.useTreeViewId;
|
|
64
|
+
}
|
|
65
|
+
});
|
|
66
|
+
Object.defineProperty(exports, "useTreeViewItems", {
|
|
67
|
+
enumerable: true,
|
|
68
|
+
get: function () {
|
|
69
|
+
return _useTreeViewItems.useTreeViewItems;
|
|
70
|
+
}
|
|
71
|
+
});
|
|
72
|
+
Object.defineProperty(exports, "useTreeViewJSXItems", {
|
|
73
|
+
enumerable: true,
|
|
74
|
+
get: function () {
|
|
75
|
+
return _useTreeViewJSXItems.useTreeViewJSXItems;
|
|
76
|
+
}
|
|
77
|
+
});
|
|
78
|
+
Object.defineProperty(exports, "useTreeViewKeyboardNavigation", {
|
|
79
|
+
enumerable: true,
|
|
80
|
+
get: function () {
|
|
81
|
+
return _useTreeViewKeyboardNavigation.useTreeViewKeyboardNavigation;
|
|
82
|
+
}
|
|
83
|
+
});
|
|
84
|
+
Object.defineProperty(exports, "useTreeViewSelection", {
|
|
85
|
+
enumerable: true,
|
|
86
|
+
get: function () {
|
|
87
|
+
return _useTreeViewSelection.useTreeViewSelection;
|
|
88
|
+
}
|
|
89
|
+
});
|
|
30
90
|
var _useTreeView = require("./useTreeView");
|
|
31
91
|
var _TreeViewProvider = require("./TreeViewProvider");
|
|
92
|
+
var _useInstanceEventHandler = require("./hooks/useInstanceEventHandler");
|
|
32
93
|
var _defaultPlugins = require("./plugins/defaultPlugins");
|
|
94
|
+
var _useTreeViewExpansion = require("./plugins/useTreeViewExpansion");
|
|
95
|
+
var _useTreeViewSelection = require("./plugins/useTreeViewSelection");
|
|
96
|
+
var _useTreeViewFocus = require("./plugins/useTreeViewFocus");
|
|
97
|
+
var _useTreeViewKeyboardNavigation = require("./plugins/useTreeViewKeyboardNavigation");
|
|
98
|
+
var _useTreeViewId = require("./plugins/useTreeViewId");
|
|
99
|
+
var _useTreeViewIcons = require("./plugins/useTreeViewIcons");
|
|
100
|
+
var _useTreeViewItems = require("./plugins/useTreeViewItems");
|
|
101
|
+
var _useTreeViewJSXItems = require("./plugins/useTreeViewJSXItems");
|
|
102
|
+
var _warning = require("./utils/warning");
|
|
33
103
|
var _extractPluginParamsFromProps = require("./utils/extractPluginParamsFromProps");
|
|
@@ -13,30 +13,40 @@ function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return
|
|
|
13
13
|
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 && Object.prototype.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; }
|
|
14
14
|
const useTreeViewExpansion = ({
|
|
15
15
|
instance,
|
|
16
|
+
publicAPI,
|
|
16
17
|
params,
|
|
17
18
|
models
|
|
18
19
|
}) => {
|
|
20
|
+
const expandedItemsMap = React.useMemo(() => {
|
|
21
|
+
const temp = new Map();
|
|
22
|
+
models.expandedItems.value.forEach(id => {
|
|
23
|
+
temp.set(id, true);
|
|
24
|
+
});
|
|
25
|
+
return temp;
|
|
26
|
+
}, [models.expandedItems.value]);
|
|
19
27
|
const setExpandedItems = (event, value) => {
|
|
20
28
|
params.onExpandedItemsChange?.(event, value);
|
|
21
29
|
models.expandedItems.setControlledValue(value);
|
|
22
30
|
};
|
|
23
|
-
const isItemExpanded = React.useCallback(itemId =>
|
|
24
|
-
return Array.isArray(models.expandedItems.value) ? models.expandedItems.value.indexOf(itemId) !== -1 : false;
|
|
25
|
-
}, [models.expandedItems.value]);
|
|
31
|
+
const isItemExpanded = React.useCallback(itemId => expandedItemsMap.has(itemId), [expandedItemsMap]);
|
|
26
32
|
const isItemExpandable = React.useCallback(itemId => !!instance.getNode(itemId)?.expandable, [instance]);
|
|
27
33
|
const toggleItemExpansion = (0, _useEventCallback.default)((event, itemId) => {
|
|
28
|
-
|
|
34
|
+
const isExpandedBefore = instance.isItemExpanded(itemId);
|
|
35
|
+
instance.setItemExpansion(event, itemId, !isExpandedBefore);
|
|
36
|
+
});
|
|
37
|
+
const setItemExpansion = (0, _useEventCallback.default)((event, itemId, isExpanded) => {
|
|
38
|
+
const isExpandedBefore = instance.isItemExpanded(itemId);
|
|
39
|
+
if (isExpandedBefore === isExpanded) {
|
|
29
40
|
return;
|
|
30
41
|
}
|
|
31
|
-
const isExpandedBefore = models.expandedItems.value.indexOf(itemId) !== -1;
|
|
32
42
|
let newExpanded;
|
|
33
|
-
if (
|
|
34
|
-
newExpanded = models.expandedItems.value.filter(id => id !== itemId);
|
|
35
|
-
} else {
|
|
43
|
+
if (isExpanded) {
|
|
36
44
|
newExpanded = [itemId].concat(models.expandedItems.value);
|
|
45
|
+
} else {
|
|
46
|
+
newExpanded = models.expandedItems.value.filter(id => id !== itemId);
|
|
37
47
|
}
|
|
38
48
|
if (params.onItemExpansionToggle) {
|
|
39
|
-
params.onItemExpansionToggle(event, itemId,
|
|
49
|
+
params.onItemExpansionToggle(event, itemId, isExpanded);
|
|
40
50
|
}
|
|
41
51
|
setExpandedItems(event, newExpanded);
|
|
42
52
|
});
|
|
@@ -57,9 +67,13 @@ const useTreeViewExpansion = ({
|
|
|
57
67
|
(0, _useTreeView.populateInstance)(instance, {
|
|
58
68
|
isItemExpanded,
|
|
59
69
|
isItemExpandable,
|
|
70
|
+
setItemExpansion,
|
|
60
71
|
toggleItemExpansion,
|
|
61
72
|
expandAllSiblings
|
|
62
73
|
});
|
|
74
|
+
(0, _useTreeView.populatePublicAPI)(publicAPI, {
|
|
75
|
+
setItemExpansion
|
|
76
|
+
});
|
|
63
77
|
};
|
|
64
78
|
exports.useTreeViewExpansion = useTreeViewExpansion;
|
|
65
79
|
useTreeViewExpansion.models = {
|
|
@@ -25,7 +25,7 @@ const updateItemsState = ({
|
|
|
25
25
|
throw new Error(['MUI X: The Tree View component requires all items to have a unique `id` property.', 'Alternatively, you can use the `getItemId` prop to specify a custom id for each item.', 'An item was provided without id in the `items` prop:', JSON.stringify(item)].join('\n'));
|
|
26
26
|
}
|
|
27
27
|
if (nodeMap[id] != null) {
|
|
28
|
-
throw new Error(['MUI X: The Tree View component requires all items to have a unique `id` property.', 'Alternatively, you can use the `getItemId` prop to specify a custom id for each item.', `
|
|
28
|
+
throw new Error(['MUI X: The Tree View component requires all items to have a unique `id` property.', 'Alternatively, you can use the `getItemId` prop to specify a custom id for each item.', `Two items were provided with the same id in the \`items\` prop: "${id}"`].join('\n'));
|
|
29
29
|
}
|
|
30
30
|
const label = getItemLabel ? getItemLabel(item) : item.label;
|
|
31
31
|
if (label == null) {
|
|
@@ -24,7 +24,7 @@ const useTreeViewJSXItems = ({
|
|
|
24
24
|
const insertJSXItem = (0, _useEventCallback.default)(item => {
|
|
25
25
|
setState(prevState => {
|
|
26
26
|
if (prevState.items.nodeMap[item.id] != null) {
|
|
27
|
-
throw new Error(['MUI X: The Tree View component requires all items to have a unique `id` property.', 'Alternatively, you can use the `getItemId` prop to specify a custom id for each item.', `
|
|
27
|
+
throw new Error(['MUI X: The Tree View component requires all items to have a unique `id` property.', 'Alternatively, you can use the `getItemId` prop to specify a custom id for each item.', `Two items were provided with the same id in the \`items\` prop: "${item.id}"`].join('\n'));
|
|
28
28
|
}
|
|
29
29
|
return (0, _extends2.default)({}, prevState, {
|
|
30
30
|
items: (0, _extends2.default)({}, prevState.items, {
|
|
@@ -31,7 +31,7 @@ const useTreeViewModels = (plugins, props) => {
|
|
|
31
31
|
return initialState;
|
|
32
32
|
});
|
|
33
33
|
const models = Object.fromEntries(Object.entries(modelsRef.current).map(([modelName, model]) => {
|
|
34
|
-
const value =
|
|
34
|
+
const value = props[modelName] ?? modelsState[modelName];
|
|
35
35
|
return [modelName, {
|
|
36
36
|
value,
|
|
37
37
|
setControlledValue: newValue => {
|
|
@@ -62,7 +62,7 @@ const useTreeViewModels = (plugins, props) => {
|
|
|
62
62
|
if (!model.isControlled && defaultValue !== newDefaultValue) {
|
|
63
63
|
console.error([`MUI X: A component is changing the default ${modelName} state of an uncontrolled TreeView after being initialized. ` + `To suppress this warning opt to use a controlled TreeView.`].join('\n'));
|
|
64
64
|
}
|
|
65
|
-
}, [JSON.stringify(
|
|
65
|
+
}, [JSON.stringify(newDefaultValue)]);
|
|
66
66
|
});
|
|
67
67
|
}
|
|
68
68
|
/* eslint-enable react-hooks/rules-of-hooks, react-hooks/exhaustive-deps */
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@mui/x-tree-view",
|
|
3
|
-
"version": "7.1.
|
|
4
|
-
"description": "The community edition of the
|
|
3
|
+
"version": "7.1.1",
|
|
4
|
+
"description": "The community edition of the Tree View components (MUI X).",
|
|
5
5
|
"author": "MUI Team",
|
|
6
6
|
"main": "./node/index.js",
|
|
7
7
|
"license": "MIT",
|