@mui/x-tree-view 8.0.0-alpha.2 → 8.0.0-alpha.4
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 +376 -0
- package/README.md +1 -1
- package/hooks/useTreeItemUtils/useTreeItemUtils.d.ts +4 -4
- package/index.js +1 -1
- package/internals/plugins/useTreeViewExpansion/useTreeViewExpansion.selectors.d.ts +30 -10
- package/internals/plugins/useTreeViewItems/useTreeViewItems.selectors.d.ts +252 -84
- package/internals/plugins/useTreeViewItems/useTreeViewItems.types.d.ts +26 -8
- package/internals/plugins/useTreeViewSelection/useTreeViewSelection.itemPlugin.js +13 -16
- package/modern/index.js +1 -1
- package/modern/internals/plugins/useTreeViewSelection/useTreeViewSelection.itemPlugin.js +13 -16
- package/node/index.js +1 -1
- package/node/internals/plugins/useTreeViewSelection/useTreeViewSelection.itemPlugin.js +13 -16
- package/package.json +2 -2
|
@@ -102,12 +102,36 @@ interface UseTreeViewItemsEventLookup {
|
|
|
102
102
|
}
|
|
103
103
|
export interface UseTreeViewItemsState<R extends {}> {
|
|
104
104
|
items: {
|
|
105
|
+
/**
|
|
106
|
+
* If `true`, will allow focus on disabled items.
|
|
107
|
+
* Always equal to `props.disabledItemsFocusable` (or `false` if not provided).
|
|
108
|
+
*/
|
|
105
109
|
disabledItemsFocusable: boolean;
|
|
106
|
-
|
|
107
|
-
|
|
110
|
+
/**
|
|
111
|
+
* Model of each item as provided by `props.items` or by imperative items updates.
|
|
112
|
+
* It is not updated when properties derived from the model are updated:
|
|
113
|
+
* - when the label of an item is updated, `itemMetaLookup` is updated, not `itemModelLookup`.
|
|
114
|
+
* - when the children of an item are updated, `itemOrderedChildrenIdsLookup` and `itemChildrenIndexesLookup` are updated, not `itemModelLookup`.
|
|
115
|
+
* This means that the `children`, `label` or `id` properties of an item model should never be used directly, always use the structured sub-states instead.
|
|
116
|
+
*/
|
|
117
|
+
itemModelLookup: {
|
|
118
|
+
[itemId: string]: TreeViewBaseItem<R>;
|
|
119
|
+
};
|
|
120
|
+
/**
|
|
121
|
+
* Meta data of each item.
|
|
122
|
+
*/
|
|
123
|
+
itemMetaLookup: {
|
|
124
|
+
[itemId: string]: TreeViewItemMeta;
|
|
125
|
+
};
|
|
126
|
+
/**
|
|
127
|
+
* Ordered children ids of each item.
|
|
128
|
+
*/
|
|
108
129
|
itemOrderedChildrenIdsLookup: {
|
|
109
130
|
[parentItemId: string]: string[];
|
|
110
131
|
};
|
|
132
|
+
/**
|
|
133
|
+
* Index of each child in the ordered children ids of its parent.
|
|
134
|
+
*/
|
|
111
135
|
itemChildrenIndexesLookup: {
|
|
112
136
|
[parentItemId: string]: {
|
|
113
137
|
[itemId: string]: number;
|
|
@@ -129,10 +153,4 @@ export type UseTreeViewItemsSignature = TreeViewPluginSignature<{
|
|
|
129
153
|
state: UseTreeViewItemsState<TreeViewDefaultItemModelProperties>;
|
|
130
154
|
contextValue: UseTreeViewItemsContextValue;
|
|
131
155
|
}>;
|
|
132
|
-
export type TreeViewItemMetaLookup = {
|
|
133
|
-
[itemId: string]: TreeViewItemMeta;
|
|
134
|
-
};
|
|
135
|
-
export type TreeViewItemModelLookup<R extends {}> = {
|
|
136
|
-
[itemId: string]: TreeViewBaseItem<R>;
|
|
137
|
-
};
|
|
138
156
|
export {};
|
|
@@ -2,19 +2,18 @@ import _extends from "@babel/runtime/helpers/esm/extends";
|
|
|
2
2
|
import { useTreeViewContext } from "../../TreeViewProvider/index.js";
|
|
3
3
|
import { selectorItemOrderedChildrenIds } from "../useTreeViewItems/useTreeViewItems.selectors.js";
|
|
4
4
|
import { selectorIsItemSelected } from "./useTreeViewSelection.selectors.js";
|
|
5
|
-
|
|
5
|
+
import { useSelector } from "../../hooks/useSelector.js";
|
|
6
|
+
function selectorItemCheckboxStatus(state, {
|
|
6
7
|
itemId,
|
|
7
|
-
|
|
8
|
-
selectionPropagation,
|
|
9
|
-
selected
|
|
8
|
+
selectionPropagation
|
|
10
9
|
}) {
|
|
11
|
-
if (
|
|
10
|
+
if (selectorIsItemSelected(state, itemId)) {
|
|
12
11
|
return {
|
|
13
12
|
indeterminate: false,
|
|
14
13
|
checked: true
|
|
15
14
|
};
|
|
16
15
|
}
|
|
17
|
-
const children = selectorItemOrderedChildrenIds(
|
|
16
|
+
const children = selectorItemOrderedChildrenIds(state, itemId);
|
|
18
17
|
if (children.length === 0) {
|
|
19
18
|
return {
|
|
20
19
|
indeterminate: false,
|
|
@@ -25,18 +24,18 @@ function getCheckboxStatus({
|
|
|
25
24
|
let hasUnSelectedDescendant = false;
|
|
26
25
|
const traverseDescendants = itemToTraverseId => {
|
|
27
26
|
if (itemToTraverseId !== itemId) {
|
|
28
|
-
if (selectorIsItemSelected(
|
|
27
|
+
if (selectorIsItemSelected(state, itemToTraverseId)) {
|
|
29
28
|
hasSelectedDescendant = true;
|
|
30
29
|
} else {
|
|
31
30
|
hasUnSelectedDescendant = true;
|
|
32
31
|
}
|
|
33
32
|
}
|
|
34
|
-
selectorItemOrderedChildrenIds(
|
|
33
|
+
selectorItemOrderedChildrenIds(state, itemToTraverseId).forEach(traverseDescendants);
|
|
35
34
|
};
|
|
36
35
|
traverseDescendants(itemId);
|
|
37
36
|
return {
|
|
38
|
-
indeterminate: hasSelectedDescendant && hasUnSelectedDescendant || !hasUnSelectedDescendant
|
|
39
|
-
checked: selectionPropagation.parents ? hasSelectedDescendant :
|
|
37
|
+
indeterminate: hasSelectedDescendant && hasUnSelectedDescendant || !hasUnSelectedDescendant,
|
|
38
|
+
checked: selectionPropagation.parents ? hasSelectedDescendant : false
|
|
40
39
|
};
|
|
41
40
|
}
|
|
42
41
|
export const useTreeViewSelectionItemPlugin = ({
|
|
@@ -53,6 +52,10 @@ export const useTreeViewSelectionItemPlugin = ({
|
|
|
53
52
|
selectionPropagation
|
|
54
53
|
}
|
|
55
54
|
} = useTreeViewContext();
|
|
55
|
+
const checkboxStatus = useSelector(store, selectorItemCheckboxStatus, {
|
|
56
|
+
itemId,
|
|
57
|
+
selectionPropagation
|
|
58
|
+
}, (a, b) => a.checked === b.checked && a.indeterminate === b.indeterminate);
|
|
56
59
|
return {
|
|
57
60
|
propsEnhancers: {
|
|
58
61
|
checkbox: ({
|
|
@@ -70,12 +73,6 @@ export const useTreeViewSelectionItemPlugin = ({
|
|
|
70
73
|
}
|
|
71
74
|
interactions.handleCheckboxSelection(event);
|
|
72
75
|
};
|
|
73
|
-
const checkboxStatus = getCheckboxStatus({
|
|
74
|
-
store,
|
|
75
|
-
itemId,
|
|
76
|
-
selectionPropagation,
|
|
77
|
-
selected: status.selected
|
|
78
|
-
});
|
|
79
76
|
return _extends({
|
|
80
77
|
visible: checkboxSelection,
|
|
81
78
|
disabled: disableSelection || status.disabled,
|
package/modern/index.js
CHANGED
|
@@ -2,19 +2,18 @@ import _extends from "@babel/runtime/helpers/esm/extends";
|
|
|
2
2
|
import { useTreeViewContext } from "../../TreeViewProvider/index.js";
|
|
3
3
|
import { selectorItemOrderedChildrenIds } from "../useTreeViewItems/useTreeViewItems.selectors.js";
|
|
4
4
|
import { selectorIsItemSelected } from "./useTreeViewSelection.selectors.js";
|
|
5
|
-
|
|
5
|
+
import { useSelector } from "../../hooks/useSelector.js";
|
|
6
|
+
function selectorItemCheckboxStatus(state, {
|
|
6
7
|
itemId,
|
|
7
|
-
|
|
8
|
-
selectionPropagation,
|
|
9
|
-
selected
|
|
8
|
+
selectionPropagation
|
|
10
9
|
}) {
|
|
11
|
-
if (
|
|
10
|
+
if (selectorIsItemSelected(state, itemId)) {
|
|
12
11
|
return {
|
|
13
12
|
indeterminate: false,
|
|
14
13
|
checked: true
|
|
15
14
|
};
|
|
16
15
|
}
|
|
17
|
-
const children = selectorItemOrderedChildrenIds(
|
|
16
|
+
const children = selectorItemOrderedChildrenIds(state, itemId);
|
|
18
17
|
if (children.length === 0) {
|
|
19
18
|
return {
|
|
20
19
|
indeterminate: false,
|
|
@@ -25,18 +24,18 @@ function getCheckboxStatus({
|
|
|
25
24
|
let hasUnSelectedDescendant = false;
|
|
26
25
|
const traverseDescendants = itemToTraverseId => {
|
|
27
26
|
if (itemToTraverseId !== itemId) {
|
|
28
|
-
if (selectorIsItemSelected(
|
|
27
|
+
if (selectorIsItemSelected(state, itemToTraverseId)) {
|
|
29
28
|
hasSelectedDescendant = true;
|
|
30
29
|
} else {
|
|
31
30
|
hasUnSelectedDescendant = true;
|
|
32
31
|
}
|
|
33
32
|
}
|
|
34
|
-
selectorItemOrderedChildrenIds(
|
|
33
|
+
selectorItemOrderedChildrenIds(state, itemToTraverseId).forEach(traverseDescendants);
|
|
35
34
|
};
|
|
36
35
|
traverseDescendants(itemId);
|
|
37
36
|
return {
|
|
38
|
-
indeterminate: hasSelectedDescendant && hasUnSelectedDescendant || !hasUnSelectedDescendant
|
|
39
|
-
checked: selectionPropagation.parents ? hasSelectedDescendant :
|
|
37
|
+
indeterminate: hasSelectedDescendant && hasUnSelectedDescendant || !hasUnSelectedDescendant,
|
|
38
|
+
checked: selectionPropagation.parents ? hasSelectedDescendant : false
|
|
40
39
|
};
|
|
41
40
|
}
|
|
42
41
|
export const useTreeViewSelectionItemPlugin = ({
|
|
@@ -53,6 +52,10 @@ export const useTreeViewSelectionItemPlugin = ({
|
|
|
53
52
|
selectionPropagation
|
|
54
53
|
}
|
|
55
54
|
} = useTreeViewContext();
|
|
55
|
+
const checkboxStatus = useSelector(store, selectorItemCheckboxStatus, {
|
|
56
|
+
itemId,
|
|
57
|
+
selectionPropagation
|
|
58
|
+
}, (a, b) => a.checked === b.checked && a.indeterminate === b.indeterminate);
|
|
56
59
|
return {
|
|
57
60
|
propsEnhancers: {
|
|
58
61
|
checkbox: ({
|
|
@@ -70,12 +73,6 @@ export const useTreeViewSelectionItemPlugin = ({
|
|
|
70
73
|
}
|
|
71
74
|
interactions.handleCheckboxSelection(event);
|
|
72
75
|
};
|
|
73
|
-
const checkboxStatus = getCheckboxStatus({
|
|
74
|
-
store,
|
|
75
|
-
itemId,
|
|
76
|
-
selectionPropagation,
|
|
77
|
-
selected: status.selected
|
|
78
|
-
});
|
|
79
76
|
return _extends({
|
|
80
77
|
visible: checkboxSelection,
|
|
81
78
|
disabled: disableSelection || status.disabled,
|
package/node/index.js
CHANGED
|
@@ -9,19 +9,18 @@ var _extends2 = _interopRequireDefault(require("@babel/runtime/helpers/extends")
|
|
|
9
9
|
var _TreeViewProvider = require("../../TreeViewProvider");
|
|
10
10
|
var _useTreeViewItems = require("../useTreeViewItems/useTreeViewItems.selectors");
|
|
11
11
|
var _useTreeViewSelection = require("./useTreeViewSelection.selectors");
|
|
12
|
-
|
|
12
|
+
var _useSelector = require("../../hooks/useSelector");
|
|
13
|
+
function selectorItemCheckboxStatus(state, {
|
|
13
14
|
itemId,
|
|
14
|
-
|
|
15
|
-
selectionPropagation,
|
|
16
|
-
selected
|
|
15
|
+
selectionPropagation
|
|
17
16
|
}) {
|
|
18
|
-
if (
|
|
17
|
+
if ((0, _useTreeViewSelection.selectorIsItemSelected)(state, itemId)) {
|
|
19
18
|
return {
|
|
20
19
|
indeterminate: false,
|
|
21
20
|
checked: true
|
|
22
21
|
};
|
|
23
22
|
}
|
|
24
|
-
const children = (0, _useTreeViewItems.selectorItemOrderedChildrenIds)(
|
|
23
|
+
const children = (0, _useTreeViewItems.selectorItemOrderedChildrenIds)(state, itemId);
|
|
25
24
|
if (children.length === 0) {
|
|
26
25
|
return {
|
|
27
26
|
indeterminate: false,
|
|
@@ -32,18 +31,18 @@ function getCheckboxStatus({
|
|
|
32
31
|
let hasUnSelectedDescendant = false;
|
|
33
32
|
const traverseDescendants = itemToTraverseId => {
|
|
34
33
|
if (itemToTraverseId !== itemId) {
|
|
35
|
-
if ((0, _useTreeViewSelection.selectorIsItemSelected)(
|
|
34
|
+
if ((0, _useTreeViewSelection.selectorIsItemSelected)(state, itemToTraverseId)) {
|
|
36
35
|
hasSelectedDescendant = true;
|
|
37
36
|
} else {
|
|
38
37
|
hasUnSelectedDescendant = true;
|
|
39
38
|
}
|
|
40
39
|
}
|
|
41
|
-
(0, _useTreeViewItems.selectorItemOrderedChildrenIds)(
|
|
40
|
+
(0, _useTreeViewItems.selectorItemOrderedChildrenIds)(state, itemToTraverseId).forEach(traverseDescendants);
|
|
42
41
|
};
|
|
43
42
|
traverseDescendants(itemId);
|
|
44
43
|
return {
|
|
45
|
-
indeterminate: hasSelectedDescendant && hasUnSelectedDescendant || !hasUnSelectedDescendant
|
|
46
|
-
checked: selectionPropagation.parents ? hasSelectedDescendant :
|
|
44
|
+
indeterminate: hasSelectedDescendant && hasUnSelectedDescendant || !hasUnSelectedDescendant,
|
|
45
|
+
checked: selectionPropagation.parents ? hasSelectedDescendant : false
|
|
47
46
|
};
|
|
48
47
|
}
|
|
49
48
|
const useTreeViewSelectionItemPlugin = ({
|
|
@@ -60,6 +59,10 @@ const useTreeViewSelectionItemPlugin = ({
|
|
|
60
59
|
selectionPropagation
|
|
61
60
|
}
|
|
62
61
|
} = (0, _TreeViewProvider.useTreeViewContext)();
|
|
62
|
+
const checkboxStatus = (0, _useSelector.useSelector)(store, selectorItemCheckboxStatus, {
|
|
63
|
+
itemId,
|
|
64
|
+
selectionPropagation
|
|
65
|
+
}, (a, b) => a.checked === b.checked && a.indeterminate === b.indeterminate);
|
|
63
66
|
return {
|
|
64
67
|
propsEnhancers: {
|
|
65
68
|
checkbox: ({
|
|
@@ -77,12 +80,6 @@ const useTreeViewSelectionItemPlugin = ({
|
|
|
77
80
|
}
|
|
78
81
|
interactions.handleCheckboxSelection(event);
|
|
79
82
|
};
|
|
80
|
-
const checkboxStatus = getCheckboxStatus({
|
|
81
|
-
store,
|
|
82
|
-
itemId,
|
|
83
|
-
selectionPropagation,
|
|
84
|
-
selected: status.selected
|
|
85
|
-
});
|
|
86
83
|
return (0, _extends2.default)({
|
|
87
84
|
visible: checkboxSelection,
|
|
88
85
|
disabled: disableSelection || status.disabled,
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@mui/x-tree-view",
|
|
3
|
-
"version": "8.0.0-alpha.
|
|
3
|
+
"version": "8.0.0-alpha.4",
|
|
4
4
|
"description": "The community edition of the Tree View components (MUI X).",
|
|
5
5
|
"author": "MUI Team",
|
|
6
6
|
"main": "./node/index.js",
|
|
@@ -40,7 +40,7 @@
|
|
|
40
40
|
"prop-types": "^15.8.1",
|
|
41
41
|
"react-transition-group": "^4.4.5",
|
|
42
42
|
"reselect": "^5.1.1",
|
|
43
|
-
"use-sync-external-store": "^1.
|
|
43
|
+
"use-sync-external-store": "^1.4.0",
|
|
44
44
|
"@mui/x-internals": "8.0.0-alpha.2"
|
|
45
45
|
},
|
|
46
46
|
"peerDependencies": {
|