@mui/x-tree-view-pro 8.0.0-alpha.0 → 8.0.0-alpha.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 +429 -5
- package/README.md +2 -2
- package/RichTreeViewPro/RichTreeViewPro.js +2 -4
- package/RichTreeViewPro/RichTreeViewPro.types.d.ts +3 -16
- package/index.js +1 -1
- package/internals/plugins/useTreeViewItemsReordering/useTreeViewItemsReordering.itemPlugin.js +12 -14
- package/internals/plugins/useTreeViewItemsReordering/useTreeViewItemsReordering.js +32 -30
- package/internals/plugins/useTreeViewItemsReordering/useTreeViewItemsReordering.selectors.d.ts +159 -0
- package/internals/plugins/useTreeViewItemsReordering/useTreeViewItemsReordering.selectors.js +35 -0
- package/internals/plugins/useTreeViewItemsReordering/useTreeViewItemsReordering.types.d.ts +1 -1
- package/internals/plugins/useTreeViewItemsReordering/useTreeViewItemsReordering.utils.d.ts +4 -6
- package/internals/plugins/useTreeViewItemsReordering/useTreeViewItemsReordering.utils.js +25 -17
- package/internals/utils/releaseInfo.js +1 -1
- package/modern/RichTreeViewPro/RichTreeViewPro.js +2 -4
- package/modern/index.js +1 -1
- package/modern/internals/plugins/useTreeViewItemsReordering/useTreeViewItemsReordering.itemPlugin.js +12 -14
- package/modern/internals/plugins/useTreeViewItemsReordering/useTreeViewItemsReordering.js +32 -30
- package/modern/internals/plugins/useTreeViewItemsReordering/useTreeViewItemsReordering.selectors.js +35 -0
- package/modern/internals/plugins/useTreeViewItemsReordering/useTreeViewItemsReordering.utils.js +25 -17
- package/modern/internals/utils/releaseInfo.js +1 -1
- package/node/RichTreeViewPro/RichTreeViewPro.js +2 -4
- package/node/index.js +1 -1
- package/node/internals/plugins/useTreeViewItemsReordering/useTreeViewItemsReordering.itemPlugin.js +11 -13
- package/node/internals/plugins/useTreeViewItemsReordering/useTreeViewItemsReordering.js +32 -30
- package/node/internals/plugins/useTreeViewItemsReordering/useTreeViewItemsReordering.selectors.js +42 -0
- package/node/internals/plugins/useTreeViewItemsReordering/useTreeViewItemsReordering.utils.js +24 -16
- package/node/internals/utils/releaseInfo.js +1 -1
- package/package.json +8 -6
package/node/internals/plugins/useTreeViewItemsReordering/useTreeViewItemsReordering.utils.js
CHANGED
|
@@ -10,15 +10,15 @@ var _internals = require("@mui/x-tree-view/internals");
|
|
|
10
10
|
/**
|
|
11
11
|
* Checks if the item with the id itemIdB is an ancestor of the item with the id itemIdA.
|
|
12
12
|
*/
|
|
13
|
-
const isAncestor = (
|
|
14
|
-
const itemMetaA =
|
|
13
|
+
const isAncestor = (store, itemIdA, itemIdB) => {
|
|
14
|
+
const itemMetaA = (0, _internals.selectorItemMeta)(store.value, itemIdA);
|
|
15
15
|
if (itemMetaA.parentId === itemIdB) {
|
|
16
16
|
return true;
|
|
17
17
|
}
|
|
18
18
|
if (itemMetaA.parentId == null) {
|
|
19
19
|
return false;
|
|
20
20
|
}
|
|
21
|
-
return isAncestor(
|
|
21
|
+
return isAncestor(store, itemMetaA.parentId, itemIdB);
|
|
22
22
|
};
|
|
23
23
|
|
|
24
24
|
/**
|
|
@@ -97,12 +97,12 @@ const moveItemInTree = ({
|
|
|
97
97
|
newPosition,
|
|
98
98
|
prevState
|
|
99
99
|
}) => {
|
|
100
|
-
const itemToMoveMeta = prevState.
|
|
100
|
+
const itemToMoveMeta = prevState.itemMetaLookup[itemToMoveId];
|
|
101
101
|
const oldParentId = oldPosition.parentId ?? _internals.TREE_VIEW_ROOT_PARENT_ID;
|
|
102
102
|
const newParentId = newPosition.parentId ?? _internals.TREE_VIEW_ROOT_PARENT_ID;
|
|
103
103
|
|
|
104
104
|
// 1. Update the `itemOrderedChildrenIds`.
|
|
105
|
-
const itemOrderedChildrenIds = (0, _extends2.default)({}, prevState.
|
|
105
|
+
const itemOrderedChildrenIds = (0, _extends2.default)({}, prevState.itemOrderedChildrenIdsLookup);
|
|
106
106
|
if (oldParentId === newParentId) {
|
|
107
107
|
const updatedChildren = [...itemOrderedChildrenIds[oldParentId]];
|
|
108
108
|
updatedChildren.splice(oldPosition.index, 1);
|
|
@@ -118,43 +118,51 @@ const moveItemInTree = ({
|
|
|
118
118
|
}
|
|
119
119
|
|
|
120
120
|
// 2. Update the `itemChildrenIndexes`
|
|
121
|
-
const itemChildrenIndexes = (0, _extends2.default)({}, prevState.
|
|
121
|
+
const itemChildrenIndexes = (0, _extends2.default)({}, prevState.itemChildrenIndexesLookup);
|
|
122
122
|
itemChildrenIndexes[oldParentId] = (0, _internals.buildSiblingIndexes)(itemOrderedChildrenIds[oldParentId]);
|
|
123
123
|
if (newParentId !== oldParentId) {
|
|
124
124
|
itemChildrenIndexes[newParentId] = (0, _internals.buildSiblingIndexes)(itemOrderedChildrenIds[newParentId]);
|
|
125
125
|
}
|
|
126
126
|
|
|
127
|
-
// 3. Update the `
|
|
128
|
-
const
|
|
127
|
+
// 3. Update the `itemMetaLookup`
|
|
128
|
+
const itemMetaLookup = (0, _extends2.default)({}, prevState.itemMetaLookup);
|
|
129
129
|
|
|
130
130
|
// 3.1 Update the `expandable` property of the old and the new parent
|
|
131
|
+
function updateExpandable(itemId) {
|
|
132
|
+
const isExpandable = itemOrderedChildrenIds[itemId].length > 0;
|
|
133
|
+
if (itemMetaLookup[itemId].expandable !== isExpandable) {
|
|
134
|
+
itemMetaLookup[itemId] = (0, _extends2.default)({}, itemMetaLookup[itemId], {
|
|
135
|
+
expandable: isExpandable
|
|
136
|
+
});
|
|
137
|
+
}
|
|
138
|
+
}
|
|
131
139
|
if (oldParentId !== _internals.TREE_VIEW_ROOT_PARENT_ID && oldParentId !== newParentId) {
|
|
132
|
-
|
|
140
|
+
updateExpandable(oldParentId);
|
|
133
141
|
}
|
|
134
142
|
if (newParentId !== _internals.TREE_VIEW_ROOT_PARENT_ID && newParentId !== oldParentId) {
|
|
135
|
-
|
|
143
|
+
updateExpandable(newParentId);
|
|
136
144
|
}
|
|
137
145
|
|
|
138
146
|
// 3.2 Update the `parentId` and `depth` properties of the item to move
|
|
139
147
|
// The depth is always defined because drag&drop is only usable with Rich Tree View components.
|
|
140
|
-
const itemToMoveDepth = newPosition.parentId == null ? 0 :
|
|
141
|
-
|
|
148
|
+
const itemToMoveDepth = newPosition.parentId == null ? 0 : itemMetaLookup[newParentId].depth + 1;
|
|
149
|
+
itemMetaLookup[itemToMoveId] = (0, _extends2.default)({}, itemToMoveMeta, {
|
|
142
150
|
parentId: newPosition.parentId,
|
|
143
151
|
depth: itemToMoveDepth
|
|
144
152
|
});
|
|
145
153
|
|
|
146
154
|
// 3.3 Update the depth of all the children of the item to move
|
|
147
155
|
const updateItemDepth = (itemId, depth) => {
|
|
148
|
-
|
|
156
|
+
itemMetaLookup[itemId] = (0, _extends2.default)({}, itemMetaLookup[itemId], {
|
|
149
157
|
depth
|
|
150
158
|
});
|
|
151
159
|
itemOrderedChildrenIds[itemId]?.forEach(childId => updateItemDepth(childId, depth + 1));
|
|
152
160
|
};
|
|
153
161
|
itemOrderedChildrenIds[itemToMoveId]?.forEach(childId => updateItemDepth(childId, itemToMoveDepth + 1));
|
|
154
162
|
return (0, _extends2.default)({}, prevState, {
|
|
155
|
-
itemOrderedChildrenIds,
|
|
156
|
-
itemChildrenIndexes,
|
|
157
|
-
|
|
163
|
+
itemOrderedChildrenIdsLookup: itemOrderedChildrenIds,
|
|
164
|
+
itemChildrenIndexesLookup: itemChildrenIndexes,
|
|
165
|
+
itemMetaLookup
|
|
158
166
|
});
|
|
159
167
|
};
|
|
160
168
|
exports.moveItemInTree = moveItemInTree;
|
|
@@ -6,7 +6,7 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
6
6
|
exports.getReleaseInfo = void 0;
|
|
7
7
|
var _utils = require("@mui/utils");
|
|
8
8
|
const getReleaseInfo = () => {
|
|
9
|
-
const releaseInfo = "
|
|
9
|
+
const releaseInfo = "MTczMjIzMDAwMDAwMA==";
|
|
10
10
|
if (process.env.NODE_ENV !== 'production') {
|
|
11
11
|
// A simple hack to set the value in the test environment (has no build step).
|
|
12
12
|
// eslint-disable-next-line no-useless-concat
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@mui/x-tree-view-pro",
|
|
3
|
-
"version": "8.0.0-alpha.
|
|
3
|
+
"version": "8.0.0-alpha.1",
|
|
4
4
|
"description": "The Pro plan edition of the Tree View components (MUI X).",
|
|
5
5
|
"author": "MUI Team",
|
|
6
6
|
"main": "./node/index.js",
|
|
@@ -39,17 +39,19 @@
|
|
|
39
39
|
"clsx": "^2.1.1",
|
|
40
40
|
"prop-types": "^15.8.1",
|
|
41
41
|
"react-transition-group": "^4.4.5",
|
|
42
|
-
"
|
|
43
|
-
"
|
|
44
|
-
"@mui/x-
|
|
42
|
+
"reselect": "^5.1.1",
|
|
43
|
+
"use-sync-external-store": "^1.2.2",
|
|
44
|
+
"@mui/x-internals": "8.0.0-alpha.1",
|
|
45
|
+
"@mui/x-license": "8.0.0-alpha.1",
|
|
46
|
+
"@mui/x-tree-view": "8.0.0-alpha.1"
|
|
45
47
|
},
|
|
46
48
|
"peerDependencies": {
|
|
47
49
|
"@emotion/react": "^11.9.0",
|
|
48
50
|
"@emotion/styled": "^11.8.1",
|
|
49
51
|
"@mui/material": "^5.15.14 || ^6.0.0",
|
|
50
52
|
"@mui/system": "^5.15.14 || ^6.0.0",
|
|
51
|
-
"react": "^17.0.0 || ^18.0.0",
|
|
52
|
-
"react-dom": "^17.0.0 || ^18.0.0"
|
|
53
|
+
"react": "^17.0.0 || ^18.0.0 || ^19.0.0",
|
|
54
|
+
"react-dom": "^17.0.0 || ^18.0.0 || ^19.0.0"
|
|
53
55
|
},
|
|
54
56
|
"peerDependenciesMeta": {
|
|
55
57
|
"@emotion/react": {
|