@mui/x-tree-view-pro 7.12.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.
- package/LICENSE +11 -0
- package/README.md +26 -0
- package/build/CHANGELOG.md +4336 -0
- package/build/LICENSE +11 -0
- package/build/README.md +26 -0
- package/build/RichTreeViewPro/RichTreeViewPro.d.ts +20 -0
- package/build/RichTreeViewPro/RichTreeViewPro.js +359 -0
- package/build/RichTreeViewPro/RichTreeViewPro.plugins.d.ts +8 -0
- package/build/RichTreeViewPro/RichTreeViewPro.plugins.js +5 -0
- package/build/RichTreeViewPro/RichTreeViewPro.types.d.ts +65 -0
- package/build/RichTreeViewPro/RichTreeViewPro.types.js +1 -0
- package/build/RichTreeViewPro/index.d.ts +3 -0
- package/build/RichTreeViewPro/index.js +3 -0
- package/build/RichTreeViewPro/package.json +6 -0
- package/build/RichTreeViewPro/richTreeViewProClasses.d.ts +7 -0
- package/build/RichTreeViewPro/richTreeViewProClasses.js +6 -0
- package/build/index.d.ts +12 -0
- package/build/index.js +22 -0
- package/build/internals/index.d.ts +1 -0
- package/build/internals/index.js +1 -0
- package/build/internals/package.json +6 -0
- package/build/internals/plugins/useTreeViewItemsReordering/index.d.ts +2 -0
- package/build/internals/plugins/useTreeViewItemsReordering/index.js +1 -0
- package/build/internals/plugins/useTreeViewItemsReordering/useTreeViewItemsReordering.d.ts +3 -0
- package/build/internals/plugins/useTreeViewItemsReordering/useTreeViewItemsReordering.itemPlugin.d.ts +4 -0
- package/build/internals/plugins/useTreeViewItemsReordering/useTreeViewItemsReordering.itemPlugin.js +128 -0
- package/build/internals/plugins/useTreeViewItemsReordering/useTreeViewItemsReordering.js +193 -0
- package/build/internals/plugins/useTreeViewItemsReordering/useTreeViewItemsReordering.types.d.ts +140 -0
- package/build/internals/plugins/useTreeViewItemsReordering/useTreeViewItemsReordering.types.js +1 -0
- package/build/internals/plugins/useTreeViewItemsReordering/useTreeViewItemsReordering.utils.d.ts +26 -0
- package/build/internals/plugins/useTreeViewItemsReordering/useTreeViewItemsReordering.utils.js +150 -0
- package/build/internals/utils/releaseInfo.d.ts +1 -0
- package/build/internals/utils/releaseInfo.js +13 -0
- package/build/internals/zero-styled/index.d.ts +3 -0
- package/build/internals/zero-styled/index.js +7 -0
- package/build/modern/RichTreeViewPro/RichTreeViewPro.js +359 -0
- package/build/modern/RichTreeViewPro/RichTreeViewPro.plugins.js +5 -0
- package/build/modern/RichTreeViewPro/RichTreeViewPro.types.js +1 -0
- package/build/modern/RichTreeViewPro/index.js +3 -0
- package/build/modern/RichTreeViewPro/richTreeViewProClasses.js +6 -0
- package/build/modern/index.js +22 -0
- package/build/modern/internals/index.js +1 -0
- package/build/modern/internals/plugins/useTreeViewItemsReordering/index.js +1 -0
- package/build/modern/internals/plugins/useTreeViewItemsReordering/useTreeViewItemsReordering.itemPlugin.js +128 -0
- package/build/modern/internals/plugins/useTreeViewItemsReordering/useTreeViewItemsReordering.js +193 -0
- package/build/modern/internals/plugins/useTreeViewItemsReordering/useTreeViewItemsReordering.types.js +1 -0
- package/build/modern/internals/plugins/useTreeViewItemsReordering/useTreeViewItemsReordering.utils.js +150 -0
- package/build/modern/internals/utils/releaseInfo.js +13 -0
- package/build/modern/internals/zero-styled/index.js +7 -0
- package/build/modern/themeAugmentation/index.js +3 -0
- package/build/node/RichTreeViewPro/RichTreeViewPro.js +367 -0
- package/build/node/RichTreeViewPro/RichTreeViewPro.plugins.js +11 -0
- package/build/node/RichTreeViewPro/RichTreeViewPro.types.js +5 -0
- package/build/node/RichTreeViewPro/index.js +27 -0
- package/build/node/RichTreeViewPro/richTreeViewProClasses.js +14 -0
- package/build/node/index.js +154 -0
- package/build/node/internals/index.js +12 -0
- package/build/node/internals/plugins/useTreeViewItemsReordering/index.js +12 -0
- package/build/node/internals/plugins/useTreeViewItemsReordering/useTreeViewItemsReordering.itemPlugin.js +138 -0
- package/build/node/internals/plugins/useTreeViewItemsReordering/useTreeViewItemsReordering.js +203 -0
- package/build/node/internals/plugins/useTreeViewItemsReordering/useTreeViewItemsReordering.types.js +5 -0
- package/build/node/internals/plugins/useTreeViewItemsReordering/useTreeViewItemsReordering.utils.js +160 -0
- package/build/node/internals/utils/releaseInfo.js +20 -0
- package/build/node/internals/zero-styled/index.js +17 -0
- package/build/node/themeAugmentation/index.js +38 -0
- package/build/package.json +59 -0
- package/build/themeAugmentation/components.d.ts +13 -0
- package/build/themeAugmentation/index.d.ts +3 -0
- package/build/themeAugmentation/index.js +3 -0
- package/build/themeAugmentation/overrides.d.ts +13 -0
- package/build/themeAugmentation/package.json +6 -0
- package/build/themeAugmentation/props.d.ts +12 -0
- package/package.json +71 -0
- package/src/RichTreeViewPro/RichTreeViewPro.plugins.ts +54 -0
- package/src/RichTreeViewPro/RichTreeViewPro.test.tsx +20 -0
- package/src/RichTreeViewPro/RichTreeViewPro.tsx +383 -0
- package/src/RichTreeViewPro/RichTreeViewPro.types.ts +80 -0
- package/src/RichTreeViewPro/index.ts +8 -0
- package/src/RichTreeViewPro/richTreeViewProClasses.ts +18 -0
- package/src/index.ts +17 -0
- package/src/internals/index.ts +1 -0
- package/src/internals/plugins/useTreeViewItemsReordering/index.ts +7 -0
- package/src/internals/plugins/useTreeViewItemsReordering/useTreeViewItemsReordering.itemPlugin.ts +155 -0
- package/src/internals/plugins/useTreeViewItemsReordering/useTreeViewItemsReordering.test.tsx +370 -0
- package/src/internals/plugins/useTreeViewItemsReordering/useTreeViewItemsReordering.ts +278 -0
- package/src/internals/plugins/useTreeViewItemsReordering/useTreeViewItemsReordering.types.ts +160 -0
- package/src/internals/plugins/useTreeViewItemsReordering/useTreeViewItemsReordering.utils.ts +199 -0
- package/src/internals/utils/releaseInfo.ts +15 -0
- package/src/internals/zero-styled/index.ts +8 -0
- package/src/themeAugmentation/components.d.ts +13 -0
- package/src/themeAugmentation/index.js +1 -0
- package/src/themeAugmentation/index.ts +3 -0
- package/src/themeAugmentation/overrides.d.ts +13 -0
- package/src/themeAugmentation/props.d.ts +12 -0
- package/src/themeAugmentation/themeAugmentation.spec.ts +26 -0
- package/tsconfig.build.json +21 -0
- package/tsconfig.build.tsbuildinfo +1 -0
- package/tsconfig.json +14 -0
package/build/modern/internals/plugins/useTreeViewItemsReordering/useTreeViewItemsReordering.js
ADDED
|
@@ -0,0 +1,193 @@
|
|
|
1
|
+
import _extends from "@babel/runtime/helpers/esm/extends";
|
|
2
|
+
import * as React from 'react';
|
|
3
|
+
import { warnOnce } from '@mui/x-tree-view/internals';
|
|
4
|
+
import { chooseActionToApply, isAncestor, moveItemInTree } from './useTreeViewItemsReordering.utils';
|
|
5
|
+
import { useTreeViewItemsReorderingItemPlugin } from './useTreeViewItemsReordering.itemPlugin';
|
|
6
|
+
export const useTreeViewItemsReordering = ({
|
|
7
|
+
params,
|
|
8
|
+
instance,
|
|
9
|
+
state,
|
|
10
|
+
setState,
|
|
11
|
+
experimentalFeatures
|
|
12
|
+
}) => {
|
|
13
|
+
const isItemsReorderingEnabled = params.itemsReordering && !!experimentalFeatures?.itemsReordering;
|
|
14
|
+
if (process.env.NODE_ENV !== 'production') {
|
|
15
|
+
if (params.itemsReordering && (!experimentalFeatures?.indentationAtItemLevel || !experimentalFeatures?.itemsReordering)) {
|
|
16
|
+
warnOnce(['MUI X: The items reordering feature requires the `indentationAtItemLevel` and `itemsReordering` experimental features to be enabled.', 'You can do it by passing `experimentalFeatures={{ indentationAtItemLevel: true, itemsReordering: true }}` to the `RichTreeViewPro` component.', 'Check the documentation for more details: https://mui.com/x/react-tree-view/rich-tree-view/items/']);
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
const canItemBeDragged = React.useCallback(itemId => {
|
|
20
|
+
if (!isItemsReorderingEnabled) {
|
|
21
|
+
return false;
|
|
22
|
+
}
|
|
23
|
+
const isItemReorderable = params.isItemReorderable;
|
|
24
|
+
if (isItemReorderable) {
|
|
25
|
+
return isItemReorderable(itemId);
|
|
26
|
+
}
|
|
27
|
+
return true;
|
|
28
|
+
}, [isItemsReorderingEnabled, params.isItemReorderable]);
|
|
29
|
+
const getDroppingTargetValidActions = React.useCallback(itemId => {
|
|
30
|
+
if (!state.itemsReordering) {
|
|
31
|
+
throw new Error('There is no ongoing reordering.');
|
|
32
|
+
}
|
|
33
|
+
if (itemId === state.itemsReordering.draggedItemId) {
|
|
34
|
+
return {};
|
|
35
|
+
}
|
|
36
|
+
const canMoveItemToNewPosition = params.canMoveItemToNewPosition;
|
|
37
|
+
const targetItemMeta = instance.getItemMeta(itemId);
|
|
38
|
+
const targetItemIndex = instance.getItemIndex(targetItemMeta.id);
|
|
39
|
+
const draggedItemMeta = instance.getItemMeta(state.itemsReordering.draggedItemId);
|
|
40
|
+
const draggedItemIndex = instance.getItemIndex(draggedItemMeta.id);
|
|
41
|
+
const oldPosition = {
|
|
42
|
+
parentId: draggedItemMeta.parentId,
|
|
43
|
+
index: draggedItemIndex
|
|
44
|
+
};
|
|
45
|
+
const checkIfPositionIsValid = positionAfterAction => {
|
|
46
|
+
let isValid;
|
|
47
|
+
// If the new position is equal to the old one, we don't want to show any dropping UI.
|
|
48
|
+
if (positionAfterAction.parentId === oldPosition.parentId && positionAfterAction.index === oldPosition.index) {
|
|
49
|
+
isValid = false;
|
|
50
|
+
} else if (canMoveItemToNewPosition) {
|
|
51
|
+
isValid = canMoveItemToNewPosition({
|
|
52
|
+
itemId,
|
|
53
|
+
oldPosition,
|
|
54
|
+
newPosition: positionAfterAction
|
|
55
|
+
});
|
|
56
|
+
} else {
|
|
57
|
+
isValid = true;
|
|
58
|
+
}
|
|
59
|
+
return isValid;
|
|
60
|
+
};
|
|
61
|
+
const positionsAfterAction = {
|
|
62
|
+
'make-child': {
|
|
63
|
+
parentId: targetItemMeta.id,
|
|
64
|
+
index: 0
|
|
65
|
+
},
|
|
66
|
+
'reorder-above': {
|
|
67
|
+
parentId: targetItemMeta.parentId,
|
|
68
|
+
index: targetItemMeta.parentId === draggedItemMeta.parentId && targetItemIndex > draggedItemIndex ? targetItemIndex - 1 : targetItemIndex
|
|
69
|
+
},
|
|
70
|
+
'reorder-below': targetItemMeta.expandable ? null : {
|
|
71
|
+
parentId: targetItemMeta.parentId,
|
|
72
|
+
index: targetItemMeta.parentId === draggedItemMeta.parentId && targetItemIndex > draggedItemIndex ? targetItemIndex : targetItemIndex + 1
|
|
73
|
+
},
|
|
74
|
+
'move-to-parent': targetItemMeta.parentId == null ? null : {
|
|
75
|
+
parentId: targetItemMeta.parentId,
|
|
76
|
+
index: instance.getItemOrderedChildrenIds(targetItemMeta.parentId).length
|
|
77
|
+
}
|
|
78
|
+
};
|
|
79
|
+
const validActions = {};
|
|
80
|
+
Object.keys(positionsAfterAction).forEach(action => {
|
|
81
|
+
const positionAfterAction = positionsAfterAction[action];
|
|
82
|
+
if (positionAfterAction != null && checkIfPositionIsValid(positionAfterAction)) {
|
|
83
|
+
validActions[action] = positionAfterAction;
|
|
84
|
+
}
|
|
85
|
+
});
|
|
86
|
+
return validActions;
|
|
87
|
+
}, [instance, state.itemsReordering, params.canMoveItemToNewPosition]);
|
|
88
|
+
const startDraggingItem = React.useCallback(itemId => {
|
|
89
|
+
setState(prevState => _extends({}, prevState, {
|
|
90
|
+
itemsReordering: {
|
|
91
|
+
targetItemId: itemId,
|
|
92
|
+
draggedItemId: itemId,
|
|
93
|
+
action: null,
|
|
94
|
+
newPosition: null
|
|
95
|
+
}
|
|
96
|
+
}));
|
|
97
|
+
}, [setState]);
|
|
98
|
+
const stopDraggingItem = React.useCallback(itemId => {
|
|
99
|
+
if (state.itemsReordering == null || state.itemsReordering.draggedItemId !== itemId) {
|
|
100
|
+
return;
|
|
101
|
+
}
|
|
102
|
+
if (state.itemsReordering.draggedItemId === state.itemsReordering.targetItemId || state.itemsReordering.action == null || state.itemsReordering.newPosition == null) {
|
|
103
|
+
setState(prevState => _extends({}, prevState, {
|
|
104
|
+
itemsReordering: null
|
|
105
|
+
}));
|
|
106
|
+
return;
|
|
107
|
+
}
|
|
108
|
+
const draggedItemMeta = instance.getItemMeta(state.itemsReordering.draggedItemId);
|
|
109
|
+
const oldPosition = {
|
|
110
|
+
parentId: draggedItemMeta.parentId,
|
|
111
|
+
index: instance.getItemIndex(draggedItemMeta.id)
|
|
112
|
+
};
|
|
113
|
+
const newPosition = state.itemsReordering.newPosition;
|
|
114
|
+
setState(prevState => _extends({}, prevState, {
|
|
115
|
+
itemsReordering: null,
|
|
116
|
+
items: moveItemInTree({
|
|
117
|
+
itemToMoveId: itemId,
|
|
118
|
+
newPosition,
|
|
119
|
+
oldPosition,
|
|
120
|
+
prevState: prevState.items
|
|
121
|
+
})
|
|
122
|
+
}));
|
|
123
|
+
const onItemPositionChange = params.onItemPositionChange;
|
|
124
|
+
onItemPositionChange?.({
|
|
125
|
+
itemId,
|
|
126
|
+
newPosition,
|
|
127
|
+
oldPosition
|
|
128
|
+
});
|
|
129
|
+
}, [setState, state.itemsReordering, instance, params.onItemPositionChange]);
|
|
130
|
+
const setDragTargetItem = React.useCallback(({
|
|
131
|
+
itemId,
|
|
132
|
+
validActions,
|
|
133
|
+
targetHeight,
|
|
134
|
+
cursorY,
|
|
135
|
+
cursorX,
|
|
136
|
+
contentElement
|
|
137
|
+
}) => {
|
|
138
|
+
setState(prevState => {
|
|
139
|
+
const prevSubState = prevState.itemsReordering;
|
|
140
|
+
if (prevSubState == null || isAncestor(instance, itemId, prevSubState.draggedItemId)) {
|
|
141
|
+
return prevState;
|
|
142
|
+
}
|
|
143
|
+
const action = chooseActionToApply({
|
|
144
|
+
itemChildrenIndentation: params.itemChildrenIndentation,
|
|
145
|
+
validActions,
|
|
146
|
+
targetHeight,
|
|
147
|
+
targetDepth: prevState.items.itemMetaMap[itemId].depth,
|
|
148
|
+
cursorY,
|
|
149
|
+
cursorX,
|
|
150
|
+
contentElement
|
|
151
|
+
});
|
|
152
|
+
const newPosition = action == null ? null : validActions[action];
|
|
153
|
+
if (prevSubState.targetItemId === itemId && prevSubState.action === action && prevSubState.newPosition?.parentId === newPosition?.parentId && prevSubState.newPosition?.index === newPosition?.index) {
|
|
154
|
+
return prevState;
|
|
155
|
+
}
|
|
156
|
+
return _extends({}, prevState, {
|
|
157
|
+
itemsReordering: _extends({}, prevSubState, {
|
|
158
|
+
targetItemId: itemId,
|
|
159
|
+
newPosition,
|
|
160
|
+
action
|
|
161
|
+
})
|
|
162
|
+
});
|
|
163
|
+
});
|
|
164
|
+
}, [instance, setState, params.itemChildrenIndentation]);
|
|
165
|
+
return {
|
|
166
|
+
instance: {
|
|
167
|
+
canItemBeDragged,
|
|
168
|
+
getDroppingTargetValidActions,
|
|
169
|
+
startDraggingItem,
|
|
170
|
+
stopDraggingItem,
|
|
171
|
+
setDragTargetItem
|
|
172
|
+
},
|
|
173
|
+
contextValue: {
|
|
174
|
+
itemsReordering: {
|
|
175
|
+
enabled: isItemsReorderingEnabled,
|
|
176
|
+
currentDrag: state.itemsReordering
|
|
177
|
+
}
|
|
178
|
+
}
|
|
179
|
+
};
|
|
180
|
+
};
|
|
181
|
+
useTreeViewItemsReordering.itemPlugin = useTreeViewItemsReorderingItemPlugin;
|
|
182
|
+
useTreeViewItemsReordering.getDefaultizedParams = params => _extends({}, params, {
|
|
183
|
+
itemsReordering: params.itemsReordering ?? false
|
|
184
|
+
});
|
|
185
|
+
useTreeViewItemsReordering.getInitialState = () => ({
|
|
186
|
+
itemsReordering: null
|
|
187
|
+
});
|
|
188
|
+
useTreeViewItemsReordering.params = {
|
|
189
|
+
itemsReordering: true,
|
|
190
|
+
isItemReorderable: true,
|
|
191
|
+
canMoveItemToNewPosition: true,
|
|
192
|
+
onItemPositionChange: true
|
|
193
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,150 @@
|
|
|
1
|
+
import _extends from "@babel/runtime/helpers/esm/extends";
|
|
2
|
+
import { buildSiblingIndexes, TREE_VIEW_ROOT_PARENT_ID } from '@mui/x-tree-view/internals';
|
|
3
|
+
/**
|
|
4
|
+
* Checks if the item with the id itemIdB is an ancestor of the item with the id itemIdA.
|
|
5
|
+
*/
|
|
6
|
+
export const isAncestor = (instance, itemIdA, itemIdB) => {
|
|
7
|
+
const itemMetaA = instance.getItemMeta(itemIdA);
|
|
8
|
+
if (itemMetaA.parentId === itemIdB) {
|
|
9
|
+
return true;
|
|
10
|
+
}
|
|
11
|
+
if (itemMetaA.parentId == null) {
|
|
12
|
+
return false;
|
|
13
|
+
}
|
|
14
|
+
return isAncestor(instance, itemMetaA.parentId, itemIdB);
|
|
15
|
+
};
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
* Transforms a CSS string `itemChildrenIndentation` into a number representing the indentation in number.
|
|
19
|
+
* @param {string | null} itemChildrenIndentation The indentation as passed to the `itemChildrenIndentation` prop.
|
|
20
|
+
* @param {HTMLElement} contentElement The DOM element to which the indentation will be applied.
|
|
21
|
+
*/
|
|
22
|
+
const parseItemChildrenIndentation = (itemChildrenIndentation, contentElement) => {
|
|
23
|
+
if (typeof itemChildrenIndentation === 'number') {
|
|
24
|
+
return itemChildrenIndentation;
|
|
25
|
+
}
|
|
26
|
+
const pixelExec = /^(\d.+)(px)$/.exec(itemChildrenIndentation);
|
|
27
|
+
if (pixelExec) {
|
|
28
|
+
return parseFloat(pixelExec[1]);
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
// If the format is neither `px` nor a number, we need to measure the indentation using an actual DOM element.
|
|
32
|
+
const tempElement = document.createElement('div');
|
|
33
|
+
tempElement.style.width = itemChildrenIndentation;
|
|
34
|
+
tempElement.style.position = 'absolute';
|
|
35
|
+
contentElement.appendChild(tempElement);
|
|
36
|
+
const value = tempElement.offsetWidth;
|
|
37
|
+
contentElement.removeChild(tempElement);
|
|
38
|
+
return value;
|
|
39
|
+
};
|
|
40
|
+
export const chooseActionToApply = ({
|
|
41
|
+
itemChildrenIndentation,
|
|
42
|
+
validActions,
|
|
43
|
+
targetHeight,
|
|
44
|
+
targetDepth,
|
|
45
|
+
cursorX,
|
|
46
|
+
cursorY,
|
|
47
|
+
contentElement
|
|
48
|
+
}) => {
|
|
49
|
+
let action;
|
|
50
|
+
const itemChildrenIndentationPx = parseItemChildrenIndentation(itemChildrenIndentation, contentElement);
|
|
51
|
+
// If we can move the item to the parent of the target, then we allocate the left offset to this action
|
|
52
|
+
// Support moving to other ancestors
|
|
53
|
+
if (validActions['move-to-parent'] && cursorX < itemChildrenIndentationPx * targetDepth) {
|
|
54
|
+
action = 'move-to-parent';
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
// If we can move the item inside the target, then we have the following split:
|
|
58
|
+
// - the upper quarter of the target moves it above
|
|
59
|
+
// - the lower quarter of the target moves it below
|
|
60
|
+
// - the inner half makes it a child
|
|
61
|
+
else if (validActions['make-child']) {
|
|
62
|
+
if (validActions['reorder-above'] && cursorY < 1 / 4 * targetHeight) {
|
|
63
|
+
action = 'reorder-above';
|
|
64
|
+
} else if (validActions['reorder-below'] && cursorY > 3 / 4 * targetHeight) {
|
|
65
|
+
action = 'reorder-below';
|
|
66
|
+
} else {
|
|
67
|
+
action = 'make-child';
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
// If we can't move the item inside the target, then we have the following split:
|
|
71
|
+
// - the upper half of the target moves it above
|
|
72
|
+
// - the lower half of the target moves it below
|
|
73
|
+
else {
|
|
74
|
+
// eslint-disable-next-line no-lonely-if
|
|
75
|
+
if (validActions['reorder-above'] && cursorY < 1 / 2 * targetHeight) {
|
|
76
|
+
action = 'reorder-above';
|
|
77
|
+
} else if (validActions['reorder-below'] && cursorY >= 1 / 2 * targetHeight) {
|
|
78
|
+
action = 'reorder-below';
|
|
79
|
+
} else {
|
|
80
|
+
action = null;
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
return action;
|
|
84
|
+
};
|
|
85
|
+
export const moveItemInTree = ({
|
|
86
|
+
itemToMoveId,
|
|
87
|
+
oldPosition,
|
|
88
|
+
newPosition,
|
|
89
|
+
prevState
|
|
90
|
+
}) => {
|
|
91
|
+
const itemToMoveMeta = prevState.itemMetaMap[itemToMoveId];
|
|
92
|
+
const oldParentId = oldPosition.parentId ?? TREE_VIEW_ROOT_PARENT_ID;
|
|
93
|
+
const newParentId = newPosition.parentId ?? TREE_VIEW_ROOT_PARENT_ID;
|
|
94
|
+
|
|
95
|
+
// 1. Update the `itemOrderedChildrenIds`.
|
|
96
|
+
const itemOrderedChildrenIds = _extends({}, prevState.itemOrderedChildrenIds);
|
|
97
|
+
if (oldParentId === newParentId) {
|
|
98
|
+
const updatedChildren = [...itemOrderedChildrenIds[oldParentId]];
|
|
99
|
+
updatedChildren.splice(oldPosition.index, 1);
|
|
100
|
+
updatedChildren.splice(newPosition.index, 0, itemToMoveId);
|
|
101
|
+
itemOrderedChildrenIds[itemToMoveMeta.parentId ?? TREE_VIEW_ROOT_PARENT_ID] = updatedChildren;
|
|
102
|
+
} else {
|
|
103
|
+
const updatedOldParentChildren = [...itemOrderedChildrenIds[oldParentId]];
|
|
104
|
+
updatedOldParentChildren.splice(oldPosition.index, 1);
|
|
105
|
+
itemOrderedChildrenIds[oldParentId] = updatedOldParentChildren;
|
|
106
|
+
const updatedNewParentChildren = [...(itemOrderedChildrenIds[newParentId] ?? [])];
|
|
107
|
+
updatedNewParentChildren.splice(newPosition.index, 0, itemToMoveId);
|
|
108
|
+
itemOrderedChildrenIds[newParentId] = updatedNewParentChildren;
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
// 2. Update the `itemChildrenIndexes`
|
|
112
|
+
const itemChildrenIndexes = _extends({}, prevState.itemChildrenIndexes);
|
|
113
|
+
itemChildrenIndexes[oldParentId] = buildSiblingIndexes(itemOrderedChildrenIds[oldParentId]);
|
|
114
|
+
if (newParentId !== oldParentId) {
|
|
115
|
+
itemChildrenIndexes[newParentId] = buildSiblingIndexes(itemOrderedChildrenIds[newParentId]);
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
// 3. Update the `itemMetaMap`
|
|
119
|
+
const itemMetaMap = _extends({}, prevState.itemMetaMap);
|
|
120
|
+
|
|
121
|
+
// 3.1 Update the `expandable` property of the old and the new parent
|
|
122
|
+
if (oldParentId !== TREE_VIEW_ROOT_PARENT_ID && oldParentId !== newParentId) {
|
|
123
|
+
itemMetaMap[oldParentId].expandable = itemOrderedChildrenIds[oldParentId].length > 0;
|
|
124
|
+
}
|
|
125
|
+
if (newParentId !== TREE_VIEW_ROOT_PARENT_ID && newParentId !== oldParentId) {
|
|
126
|
+
itemMetaMap[newParentId].expandable = itemOrderedChildrenIds[newParentId].length > 0;
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
// 3.2 Update the `parentId` and `depth` properties of the item to move
|
|
130
|
+
// The depth is always defined because drag&drop is only usable with Rich Tree View components.
|
|
131
|
+
const itemToMoveDepth = newPosition.parentId == null ? 0 : itemMetaMap[newParentId].depth + 1;
|
|
132
|
+
itemMetaMap[itemToMoveId] = _extends({}, itemToMoveMeta, {
|
|
133
|
+
parentId: newPosition.parentId,
|
|
134
|
+
depth: itemToMoveDepth
|
|
135
|
+
});
|
|
136
|
+
|
|
137
|
+
// 3.3 Update the depth of all the children of the item to move
|
|
138
|
+
const updateItemDepth = (itemId, depth) => {
|
|
139
|
+
itemMetaMap[itemId] = _extends({}, itemMetaMap[itemId], {
|
|
140
|
+
depth
|
|
141
|
+
});
|
|
142
|
+
itemOrderedChildrenIds[itemId]?.forEach(childId => updateItemDepth(childId, depth + 1));
|
|
143
|
+
};
|
|
144
|
+
itemOrderedChildrenIds[itemToMoveId]?.forEach(childId => updateItemDepth(childId, itemToMoveDepth + 1));
|
|
145
|
+
return _extends({}, prevState, {
|
|
146
|
+
itemOrderedChildrenIds,
|
|
147
|
+
itemChildrenIndexes,
|
|
148
|
+
itemMetaMap
|
|
149
|
+
});
|
|
150
|
+
};
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { ponyfillGlobal } from '@mui/utils';
|
|
2
|
+
export const getReleaseInfo = () => {
|
|
3
|
+
const releaseInfo = "MTcyMjQ2MzIwMDAwMA==";
|
|
4
|
+
if (process.env.NODE_ENV !== 'production') {
|
|
5
|
+
// A simple hack to set the value in the test environment (has no build step).
|
|
6
|
+
// eslint-disable-next-line no-useless-concat
|
|
7
|
+
if (releaseInfo === '__RELEASE' + '_INFO__') {
|
|
8
|
+
// eslint-disable-next-line no-underscore-dangle
|
|
9
|
+
return ponyfillGlobal.__MUI_RELEASE_INFO__;
|
|
10
|
+
}
|
|
11
|
+
}
|
|
12
|
+
return releaseInfo;
|
|
13
|
+
};
|