@mui/x-tree-view-pro 7.22.1 → 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 +486 -11
- package/README.md +4 -4
- package/RichTreeViewPro/RichTreeViewPro.js +22 -5
- package/RichTreeViewPro/RichTreeViewPro.types.d.ts +3 -17
- package/index.d.ts +5 -7
- package/index.js +6 -8
- package/internals/plugins/useTreeViewItemsReordering/useTreeViewItemsReordering.itemPlugin.d.ts +1 -2
- package/internals/plugins/useTreeViewItemsReordering/useTreeViewItemsReordering.itemPlugin.js +12 -14
- package/internals/plugins/useTreeViewItemsReordering/useTreeViewItemsReordering.js +34 -32
- 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 +11 -10
- 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 +22 -5
- package/modern/index.js +6 -8
- package/modern/internals/plugins/useTreeViewItemsReordering/useTreeViewItemsReordering.itemPlugin.js +12 -14
- package/modern/internals/plugins/useTreeViewItemsReordering/useTreeViewItemsReordering.js +34 -32
- 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 +22 -5
- package/node/index.js +18 -42
- package/node/internals/plugins/useTreeViewItemsReordering/useTreeViewItemsReordering.itemPlugin.js +11 -13
- package/node/internals/plugins/useTreeViewItemsReordering/useTreeViewItemsReordering.js +34 -32
- 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 +9 -7
|
@@ -2,31 +2,18 @@ import * as React from 'react';
|
|
|
2
2
|
import { Theme } from '@mui/material/styles';
|
|
3
3
|
import { SxProps } from '@mui/system';
|
|
4
4
|
import { SlotComponentProps } from '@mui/utils';
|
|
5
|
-
import {
|
|
6
|
-
import { TreeItem2Props } from '@mui/x-tree-view/TreeItem2';
|
|
7
|
-
import { TreeViewItemId } from '@mui/x-tree-view/models';
|
|
8
|
-
import { TreeViewPublicAPI, TreeViewExperimentalFeatures } from '@mui/x-tree-view/internals';
|
|
5
|
+
import { TreeViewPublicAPI, TreeViewExperimentalFeatures, RichTreeViewItemsSlots, RichTreeViewItemsSlotProps } from '@mui/x-tree-view/internals';
|
|
9
6
|
import { RichTreeViewProClasses } from './richTreeViewProClasses';
|
|
10
7
|
import { RichTreeViewProPluginParameters, RichTreeViewProPluginSlotProps, RichTreeViewProPluginSlots, RichTreeViewProPluginSignatures } from './RichTreeViewPro.plugins';
|
|
11
|
-
interface
|
|
12
|
-
itemId: TreeViewItemId;
|
|
13
|
-
label: string;
|
|
14
|
-
}
|
|
15
|
-
export interface RichTreeViewProSlots extends RichTreeViewProPluginSlots {
|
|
8
|
+
export interface RichTreeViewProSlots extends RichTreeViewProPluginSlots, RichTreeViewItemsSlots {
|
|
16
9
|
/**
|
|
17
10
|
* Element rendered at the root.
|
|
18
11
|
* @default RichTreeViewProRoot
|
|
19
12
|
*/
|
|
20
13
|
root?: React.ElementType;
|
|
21
|
-
/**
|
|
22
|
-
* Custom component for the item.
|
|
23
|
-
* @default TreeItem.
|
|
24
|
-
*/
|
|
25
|
-
item?: React.JSXElementConstructor<TreeItemProps> | React.JSXElementConstructor<TreeItem2Props>;
|
|
26
14
|
}
|
|
27
|
-
export interface RichTreeViewProSlotProps<R extends {}, Multiple extends boolean | undefined> extends RichTreeViewProPluginSlotProps {
|
|
15
|
+
export interface RichTreeViewProSlotProps<R extends {}, Multiple extends boolean | undefined> extends RichTreeViewProPluginSlotProps, RichTreeViewItemsSlotProps {
|
|
28
16
|
root?: SlotComponentProps<'ul', {}, RichTreeViewProProps<R, Multiple>>;
|
|
29
|
-
item?: SlotComponentProps<typeof TreeItem, {}, RichTreeViewItemProSlotOwnerState>;
|
|
30
17
|
}
|
|
31
18
|
export type RichTreeViewProApiRef = React.MutableRefObject<TreeViewPublicAPI<RichTreeViewProPluginSignatures> | undefined>;
|
|
32
19
|
export interface RichTreeViewProPropsBase extends React.HTMLAttributes<HTMLUListElement> {
|
|
@@ -62,4 +49,3 @@ export interface RichTreeViewProProps<R extends {}, Multiple extends boolean | u
|
|
|
62
49
|
*/
|
|
63
50
|
experimentalFeatures?: TreeViewExperimentalFeatures<RichTreeViewProPluginSignatures>;
|
|
64
51
|
}
|
|
65
|
-
export {};
|
package/index.d.ts
CHANGED
|
@@ -1,13 +1,11 @@
|
|
|
1
|
-
export * from '@mui/x-tree-view/TreeView';
|
|
2
1
|
export * from '@mui/x-tree-view/SimpleTreeView';
|
|
3
2
|
export * from './RichTreeViewPro';
|
|
4
3
|
export * from '@mui/x-tree-view/TreeItem';
|
|
5
|
-
export * from '@mui/x-tree-view/
|
|
6
|
-
export * from '@mui/x-tree-view/
|
|
7
|
-
export * from '@mui/x-tree-view/
|
|
8
|
-
export * from '@mui/x-tree-view/
|
|
9
|
-
export * from '@mui/x-tree-view/
|
|
10
|
-
export * from '@mui/x-tree-view/TreeItem2LabelInput';
|
|
4
|
+
export * from '@mui/x-tree-view/useTreeItem';
|
|
5
|
+
export * from '@mui/x-tree-view/TreeItemIcon';
|
|
6
|
+
export * from '@mui/x-tree-view/TreeItemProvider';
|
|
7
|
+
export * from '@mui/x-tree-view/TreeItemDragAndDropOverlay';
|
|
8
|
+
export * from '@mui/x-tree-view/TreeItemLabelInput';
|
|
11
9
|
export { unstable_resetCleanupTracking } from '@mui/x-tree-view/internals';
|
|
12
10
|
export * from '@mui/x-tree-view/models';
|
|
13
11
|
export * from '@mui/x-tree-view/icons';
|
package/index.js
CHANGED
|
@@ -1,23 +1,21 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* @mui/x-tree-view-pro
|
|
2
|
+
* @mui/x-tree-view-pro v8.0.0-alpha.1
|
|
3
3
|
*
|
|
4
4
|
* @license MUI X Commercial
|
|
5
5
|
* This source code is licensed under the commercial license found in the
|
|
6
6
|
* LICENSE file in the root directory of this source tree.
|
|
7
7
|
*/
|
|
8
8
|
// Tree View
|
|
9
|
-
export * from '@mui/x-tree-view/TreeView';
|
|
10
9
|
export * from '@mui/x-tree-view/SimpleTreeView';
|
|
11
10
|
export * from "./RichTreeViewPro/index.js";
|
|
12
11
|
|
|
13
12
|
// Tree Item
|
|
14
13
|
export * from '@mui/x-tree-view/TreeItem';
|
|
15
|
-
export * from '@mui/x-tree-view/
|
|
16
|
-
export * from '@mui/x-tree-view/
|
|
17
|
-
export * from '@mui/x-tree-view/
|
|
18
|
-
export * from '@mui/x-tree-view/
|
|
19
|
-
export * from '@mui/x-tree-view/
|
|
20
|
-
export * from '@mui/x-tree-view/TreeItem2LabelInput';
|
|
14
|
+
export * from '@mui/x-tree-view/useTreeItem';
|
|
15
|
+
export * from '@mui/x-tree-view/TreeItemIcon';
|
|
16
|
+
export * from '@mui/x-tree-view/TreeItemProvider';
|
|
17
|
+
export * from '@mui/x-tree-view/TreeItemDragAndDropOverlay';
|
|
18
|
+
export * from '@mui/x-tree-view/TreeItemLabelInput';
|
|
21
19
|
export { unstable_resetCleanupTracking } from '@mui/x-tree-view/internals';
|
|
22
20
|
export * from '@mui/x-tree-view/models';
|
|
23
21
|
export * from '@mui/x-tree-view/icons';
|
package/internals/plugins/useTreeViewItemsReordering/useTreeViewItemsReordering.itemPlugin.d.ts
CHANGED
|
@@ -1,4 +1,3 @@
|
|
|
1
1
|
import { TreeViewItemPlugin } from '@mui/x-tree-view/internals';
|
|
2
|
-
import { TreeItem2Props } from '@mui/x-tree-view/TreeItem2';
|
|
3
2
|
export declare const isAndroid: () => boolean;
|
|
4
|
-
export declare const useTreeViewItemsReorderingItemPlugin: TreeViewItemPlugin
|
|
3
|
+
export declare const useTreeViewItemsReorderingItemPlugin: TreeViewItemPlugin;
|
package/internals/plugins/useTreeViewItemsReordering/useTreeViewItemsReordering.itemPlugin.js
CHANGED
|
@@ -1,17 +1,21 @@
|
|
|
1
1
|
import * as React from 'react';
|
|
2
|
-
import { useTreeViewContext, isTargetInDescendants } from '@mui/x-tree-view/internals';
|
|
2
|
+
import { useTreeViewContext, isTargetInDescendants, useSelector } from '@mui/x-tree-view/internals';
|
|
3
|
+
import { selectorItemsReorderingDraggedItemProperties, selectorItemsReorderingIsValidTarget } from "./useTreeViewItemsReordering.selectors.js";
|
|
3
4
|
export const isAndroid = () => navigator.userAgent.toLowerCase().includes('android');
|
|
4
5
|
export const useTreeViewItemsReorderingItemPlugin = ({
|
|
5
6
|
props
|
|
6
7
|
}) => {
|
|
7
8
|
const {
|
|
8
|
-
|
|
9
|
-
|
|
9
|
+
instance,
|
|
10
|
+
store,
|
|
11
|
+
itemsReordering
|
|
10
12
|
} = useTreeViewContext();
|
|
11
13
|
const {
|
|
12
14
|
itemId
|
|
13
15
|
} = props;
|
|
14
16
|
const validActionsRef = React.useRef(null);
|
|
17
|
+
const draggedItemProperties = useSelector(store, selectorItemsReorderingDraggedItemProperties, itemId);
|
|
18
|
+
const isValidTarget = useSelector(store, selectorItemsReorderingIsValidTarget, itemId);
|
|
15
19
|
return {
|
|
16
20
|
propsEnhancers: {
|
|
17
21
|
root: ({
|
|
@@ -19,8 +23,7 @@ export const useTreeViewItemsReorderingItemPlugin = ({
|
|
|
19
23
|
contentRefObject,
|
|
20
24
|
externalEventHandlers
|
|
21
25
|
}) => {
|
|
22
|
-
|
|
23
|
-
if (!draggable) {
|
|
26
|
+
if (!itemsReordering.enabled || itemsReordering.isItemReorderable && !itemsReordering.isItemReorderable(itemId)) {
|
|
24
27
|
return {};
|
|
25
28
|
}
|
|
26
29
|
const handleDragStart = event => {
|
|
@@ -75,8 +78,7 @@ export const useTreeViewItemsReorderingItemPlugin = ({
|
|
|
75
78
|
externalEventHandlers,
|
|
76
79
|
contentRefObject
|
|
77
80
|
}) => {
|
|
78
|
-
|
|
79
|
-
if (!currentDrag || currentDrag.draggedItemId === itemId) {
|
|
81
|
+
if (!isValidTarget) {
|
|
80
82
|
return {};
|
|
81
83
|
}
|
|
82
84
|
const handleDragOver = event => {
|
|
@@ -109,17 +111,13 @@ export const useTreeViewItemsReorderingItemPlugin = ({
|
|
|
109
111
|
};
|
|
110
112
|
},
|
|
111
113
|
dragAndDropOverlay: () => {
|
|
112
|
-
|
|
113
|
-
if (!currentDrag || currentDrag.targetItemId !== itemId || currentDrag.action == null) {
|
|
114
|
+
if (!draggedItemProperties) {
|
|
114
115
|
return {};
|
|
115
116
|
}
|
|
116
|
-
const targetDepth = currentDrag.newPosition?.parentId == null ? 0 :
|
|
117
|
-
// The depth is always defined because drag&drop is only usable with Rich Tree View components.
|
|
118
|
-
instance.getItemMeta(currentDrag.newPosition.parentId).depth + 1;
|
|
119
117
|
return {
|
|
120
|
-
action:
|
|
118
|
+
action: draggedItemProperties.action,
|
|
121
119
|
style: {
|
|
122
|
-
'--TreeView-targetDepth': targetDepth
|
|
120
|
+
'--TreeView-targetDepth': draggedItemProperties.targetDepth
|
|
123
121
|
}
|
|
124
122
|
};
|
|
125
123
|
}
|
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
import _extends from "@babel/runtime/helpers/esm/extends";
|
|
2
2
|
import * as React from 'react';
|
|
3
|
+
import { selectorItemIndex, selectorItemMeta, selectorItemOrderedChildrenIds } from '@mui/x-tree-view/internals';
|
|
3
4
|
import { warnOnce } from '@mui/x-internals/warning';
|
|
4
5
|
import { chooseActionToApply, isAncestor, moveItemInTree } from "./useTreeViewItemsReordering.utils.js";
|
|
5
6
|
import { useTreeViewItemsReorderingItemPlugin } from "./useTreeViewItemsReordering.itemPlugin.js";
|
|
7
|
+
import { selectorItemsReordering } from "./useTreeViewItemsReordering.selectors.js";
|
|
6
8
|
export const useTreeViewItemsReordering = ({
|
|
7
9
|
params,
|
|
8
|
-
|
|
9
|
-
state,
|
|
10
|
-
setState
|
|
10
|
+
store
|
|
11
11
|
}) => {
|
|
12
12
|
const canItemBeDragged = React.useCallback(itemId => {
|
|
13
13
|
if (!params.itemsReordering) {
|
|
@@ -20,7 +20,7 @@ export const useTreeViewItemsReordering = ({
|
|
|
20
20
|
return true;
|
|
21
21
|
}, [params.itemsReordering, params.isItemReorderable]);
|
|
22
22
|
const getDroppingTargetValidActions = React.useCallback(itemId => {
|
|
23
|
-
const itemsReordering =
|
|
23
|
+
const itemsReordering = selectorItemsReordering(store.value);
|
|
24
24
|
if (!itemsReordering) {
|
|
25
25
|
throw new Error('There is no ongoing reordering.');
|
|
26
26
|
}
|
|
@@ -28,10 +28,10 @@ export const useTreeViewItemsReordering = ({
|
|
|
28
28
|
return {};
|
|
29
29
|
}
|
|
30
30
|
const canMoveItemToNewPosition = params.canMoveItemToNewPosition;
|
|
31
|
-
const targetItemMeta =
|
|
32
|
-
const targetItemIndex =
|
|
33
|
-
const draggedItemMeta =
|
|
34
|
-
const draggedItemIndex =
|
|
31
|
+
const targetItemMeta = selectorItemMeta(store.value, itemId);
|
|
32
|
+
const targetItemIndex = selectorItemIndex(store.value, targetItemMeta.id);
|
|
33
|
+
const draggedItemMeta = selectorItemMeta(store.value, itemsReordering.draggedItemId);
|
|
34
|
+
const draggedItemIndex = selectorItemIndex(store.value, draggedItemMeta.id);
|
|
35
35
|
const oldPosition = {
|
|
36
36
|
parentId: draggedItemMeta.parentId,
|
|
37
37
|
index: draggedItemIndex
|
|
@@ -67,7 +67,7 @@ export const useTreeViewItemsReordering = ({
|
|
|
67
67
|
},
|
|
68
68
|
'move-to-parent': targetItemMeta.parentId == null ? null : {
|
|
69
69
|
parentId: targetItemMeta.parentId,
|
|
70
|
-
index:
|
|
70
|
+
index: selectorItemOrderedChildrenIds(store.value, targetItemMeta.parentId).length
|
|
71
71
|
}
|
|
72
72
|
};
|
|
73
73
|
const validActions = {};
|
|
@@ -78,9 +78,9 @@ export const useTreeViewItemsReordering = ({
|
|
|
78
78
|
}
|
|
79
79
|
});
|
|
80
80
|
return validActions;
|
|
81
|
-
}, [
|
|
81
|
+
}, [store, params.canMoveItemToNewPosition]);
|
|
82
82
|
const startDraggingItem = React.useCallback(itemId => {
|
|
83
|
-
|
|
83
|
+
store.update(prevState => _extends({}, prevState, {
|
|
84
84
|
itemsReordering: {
|
|
85
85
|
targetItemId: itemId,
|
|
86
86
|
draggedItemId: itemId,
|
|
@@ -88,24 +88,25 @@ export const useTreeViewItemsReordering = ({
|
|
|
88
88
|
newPosition: null
|
|
89
89
|
}
|
|
90
90
|
}));
|
|
91
|
-
}, [
|
|
91
|
+
}, [store]);
|
|
92
92
|
const stopDraggingItem = React.useCallback(itemId => {
|
|
93
|
-
|
|
93
|
+
const itemsReordering = selectorItemsReordering(store.value);
|
|
94
|
+
if (itemsReordering == null || itemsReordering.draggedItemId !== itemId) {
|
|
94
95
|
return;
|
|
95
96
|
}
|
|
96
|
-
if (
|
|
97
|
-
|
|
97
|
+
if (itemsReordering.draggedItemId === itemsReordering.targetItemId || itemsReordering.action == null || itemsReordering.newPosition == null) {
|
|
98
|
+
store.update(prevState => _extends({}, prevState, {
|
|
98
99
|
itemsReordering: null
|
|
99
100
|
}));
|
|
100
101
|
return;
|
|
101
102
|
}
|
|
102
|
-
const draggedItemMeta =
|
|
103
|
+
const draggedItemMeta = selectorItemMeta(store.value, itemsReordering.draggedItemId);
|
|
103
104
|
const oldPosition = {
|
|
104
105
|
parentId: draggedItemMeta.parentId,
|
|
105
|
-
index:
|
|
106
|
+
index: selectorItemIndex(store.value, draggedItemMeta.id)
|
|
106
107
|
};
|
|
107
|
-
const newPosition =
|
|
108
|
-
|
|
108
|
+
const newPosition = itemsReordering.newPosition;
|
|
109
|
+
store.update(prevState => _extends({}, prevState, {
|
|
109
110
|
itemsReordering: null,
|
|
110
111
|
items: moveItemInTree({
|
|
111
112
|
itemToMoveId: itemId,
|
|
@@ -120,7 +121,7 @@ export const useTreeViewItemsReordering = ({
|
|
|
120
121
|
newPosition,
|
|
121
122
|
oldPosition
|
|
122
123
|
});
|
|
123
|
-
}, [
|
|
124
|
+
}, [store, params.onItemPositionChange]);
|
|
124
125
|
const setDragTargetItem = React.useCallback(({
|
|
125
126
|
itemId,
|
|
126
127
|
validActions,
|
|
@@ -129,16 +130,16 @@ export const useTreeViewItemsReordering = ({
|
|
|
129
130
|
cursorX,
|
|
130
131
|
contentElement
|
|
131
132
|
}) => {
|
|
132
|
-
|
|
133
|
+
store.update(prevState => {
|
|
133
134
|
const prevSubState = prevState.itemsReordering;
|
|
134
|
-
if (prevSubState == null || isAncestor(
|
|
135
|
+
if (prevSubState == null || isAncestor(store, itemId, prevSubState.draggedItemId)) {
|
|
135
136
|
return prevState;
|
|
136
137
|
}
|
|
137
138
|
const action = chooseActionToApply({
|
|
138
139
|
itemChildrenIndentation: params.itemChildrenIndentation,
|
|
139
140
|
validActions,
|
|
140
141
|
targetHeight,
|
|
141
|
-
targetDepth: prevState.items.
|
|
142
|
+
targetDepth: prevState.items.itemMetaLookup[itemId].depth,
|
|
142
143
|
cursorY,
|
|
143
144
|
cursorX,
|
|
144
145
|
contentElement
|
|
@@ -155,7 +156,13 @@ export const useTreeViewItemsReordering = ({
|
|
|
155
156
|
})
|
|
156
157
|
});
|
|
157
158
|
});
|
|
158
|
-
}, [
|
|
159
|
+
}, [store, params.itemChildrenIndentation]);
|
|
160
|
+
const pluginContextValue = React.useMemo(() => ({
|
|
161
|
+
itemsReordering: {
|
|
162
|
+
enabled: params.itemsReordering,
|
|
163
|
+
isItemReorderable: params.isItemReorderable
|
|
164
|
+
}
|
|
165
|
+
}), [params.itemsReordering, params.isItemReorderable]);
|
|
159
166
|
return {
|
|
160
167
|
instance: {
|
|
161
168
|
canItemBeDragged,
|
|
@@ -164,12 +171,7 @@ export const useTreeViewItemsReordering = ({
|
|
|
164
171
|
stopDraggingItem,
|
|
165
172
|
setDragTargetItem
|
|
166
173
|
},
|
|
167
|
-
contextValue:
|
|
168
|
-
itemsReordering: {
|
|
169
|
-
enabled: params.itemsReordering,
|
|
170
|
-
currentDrag: state.itemsReordering
|
|
171
|
-
}
|
|
172
|
-
}
|
|
174
|
+
contextValue: pluginContextValue
|
|
173
175
|
};
|
|
174
176
|
};
|
|
175
177
|
useTreeViewItemsReordering.itemPlugin = useTreeViewItemsReorderingItemPlugin;
|
|
@@ -177,10 +179,10 @@ useTreeViewItemsReordering.getDefaultizedParams = ({
|
|
|
177
179
|
params,
|
|
178
180
|
experimentalFeatures
|
|
179
181
|
}) => {
|
|
180
|
-
const canUseFeature = experimentalFeatures?.
|
|
182
|
+
const canUseFeature = experimentalFeatures?.itemsReordering;
|
|
181
183
|
if (process.env.NODE_ENV !== 'production') {
|
|
182
184
|
if (params.itemsReordering && !canUseFeature) {
|
|
183
|
-
warnOnce(['MUI X: The items reordering feature requires the `
|
|
185
|
+
warnOnce(['MUI X: The items reordering feature requires the `itemsReordering` experimental feature to be enabled.', 'You can do it by passing `experimentalFeatures={{ itemsReordering: true }}` to the `<RichTreeViewPro />`component.', 'Check the documentation for more details: https://mui.com/x/react-tree-view/rich-tree-view/items/']);
|
|
184
186
|
}
|
|
185
187
|
}
|
|
186
188
|
return _extends({}, params, {
|
package/internals/plugins/useTreeViewItemsReordering/useTreeViewItemsReordering.selectors.d.ts
ADDED
|
@@ -0,0 +1,159 @@
|
|
|
1
|
+
import { TreeViewState } from '@mui/x-tree-view/internals';
|
|
2
|
+
import { UseTreeViewItemsReorderingSignature } from './useTreeViewItemsReordering.types';
|
|
3
|
+
/**
|
|
4
|
+
* Get the items reordering state.
|
|
5
|
+
* @param {TreeViewState<[UseTreeViewItemsReorderingSignature]>} state The state of the tree view.
|
|
6
|
+
* @returns {TreeViewItemsReorderingState | null} The items reordering state.
|
|
7
|
+
*/
|
|
8
|
+
export declare const selectorItemsReordering: (state: TreeViewState<[UseTreeViewItemsReorderingSignature]>) => {
|
|
9
|
+
draggedItemId: string;
|
|
10
|
+
targetItemId: string;
|
|
11
|
+
newPosition: import("./useTreeViewItemsReordering.types").TreeViewItemReorderPosition | null;
|
|
12
|
+
action: import("@mui/x-tree-view").TreeViewItemsReorderingAction | null;
|
|
13
|
+
} | null;
|
|
14
|
+
/**
|
|
15
|
+
* Get the properties of the dragged item.
|
|
16
|
+
* @param {TreeViewState<[UseTreeViewItemsSignature, UseTreeViewItemsReorderingSignature]>} state The state of the tree view.
|
|
17
|
+
* @param {string} itemId The id of the item.
|
|
18
|
+
* @returns {TreeViewItemDraggedItemProperties | null} The properties of the dragged item if the current item is being dragged, `null` otherwise.
|
|
19
|
+
*/
|
|
20
|
+
export declare const selectorItemsReorderingDraggedItemProperties: ((state: any, itemId: string) => {
|
|
21
|
+
newPosition: import("./useTreeViewItemsReordering.types").TreeViewItemReorderPosition | null;
|
|
22
|
+
action: import("@mui/x-tree-view").TreeViewItemsReorderingAction;
|
|
23
|
+
targetDepth: number;
|
|
24
|
+
} | null) & {
|
|
25
|
+
clearCache: () => void;
|
|
26
|
+
resultsCount: () => number;
|
|
27
|
+
resetResultsCount: () => void;
|
|
28
|
+
} & {
|
|
29
|
+
resultFunc: (resultFuncArgs_0: {
|
|
30
|
+
draggedItemId: string;
|
|
31
|
+
targetItemId: string;
|
|
32
|
+
newPosition: import("./useTreeViewItemsReordering.types").TreeViewItemReorderPosition | null;
|
|
33
|
+
action: import("@mui/x-tree-view").TreeViewItemsReorderingAction | null;
|
|
34
|
+
} | null, resultFuncArgs_1: import("@mui/x-tree-view/internals/plugins/useTreeViewItems/useTreeViewItems.types").TreeViewItemMetaLookup, resultFuncArgs_2: string) => {
|
|
35
|
+
newPosition: import("./useTreeViewItemsReordering.types").TreeViewItemReorderPosition | null;
|
|
36
|
+
action: import("@mui/x-tree-view").TreeViewItemsReorderingAction;
|
|
37
|
+
targetDepth: number;
|
|
38
|
+
} | null;
|
|
39
|
+
memoizedResultFunc: ((resultFuncArgs_0: {
|
|
40
|
+
draggedItemId: string;
|
|
41
|
+
targetItemId: string;
|
|
42
|
+
newPosition: import("./useTreeViewItemsReordering.types").TreeViewItemReorderPosition | null;
|
|
43
|
+
action: import("@mui/x-tree-view").TreeViewItemsReorderingAction | null;
|
|
44
|
+
} | null, resultFuncArgs_1: import("@mui/x-tree-view/internals/plugins/useTreeViewItems/useTreeViewItems.types").TreeViewItemMetaLookup, resultFuncArgs_2: string) => {
|
|
45
|
+
newPosition: import("./useTreeViewItemsReordering.types").TreeViewItemReorderPosition | null;
|
|
46
|
+
action: import("@mui/x-tree-view").TreeViewItemsReorderingAction;
|
|
47
|
+
targetDepth: number;
|
|
48
|
+
} | null) & {
|
|
49
|
+
clearCache: () => void;
|
|
50
|
+
resultsCount: () => number;
|
|
51
|
+
resetResultsCount: () => void;
|
|
52
|
+
};
|
|
53
|
+
lastResult: () => {
|
|
54
|
+
newPosition: import("./useTreeViewItemsReordering.types").TreeViewItemReorderPosition | null;
|
|
55
|
+
action: import("@mui/x-tree-view").TreeViewItemsReorderingAction;
|
|
56
|
+
targetDepth: number;
|
|
57
|
+
} | null;
|
|
58
|
+
dependencies: [(state: TreeViewState<[UseTreeViewItemsReorderingSignature]>) => {
|
|
59
|
+
draggedItemId: string;
|
|
60
|
+
targetItemId: string;
|
|
61
|
+
newPosition: import("./useTreeViewItemsReordering.types").TreeViewItemReorderPosition | null;
|
|
62
|
+
action: import("@mui/x-tree-view").TreeViewItemsReorderingAction | null;
|
|
63
|
+
} | null, ((state: import("@mui/x-tree-view/internals/corePlugins/useTreeViewId/useTreeViewId.types").UseTreeViewIdState & import("@mui/x-tree-view/internals").UseTreeViewItemsState<import("@mui/x-tree-view").TreeViewDefaultItemModelProperties> & Partial<{}> & {
|
|
64
|
+
cacheKey: import("@mui/x-tree-view/internals/models").TreeViewStateCacheKey;
|
|
65
|
+
}) => import("@mui/x-tree-view/internals/plugins/useTreeViewItems/useTreeViewItems.types").TreeViewItemMetaLookup) & {
|
|
66
|
+
clearCache: () => void;
|
|
67
|
+
resultsCount: () => number;
|
|
68
|
+
resetResultsCount: () => void;
|
|
69
|
+
} & {
|
|
70
|
+
resultFunc: (resultFuncArgs_0: {
|
|
71
|
+
disabledItemsFocusable: boolean;
|
|
72
|
+
itemModelLookup: import("@mui/x-tree-view/internals/plugins/useTreeViewItems/useTreeViewItems.types").TreeViewItemModelLookup<import("@mui/x-tree-view").TreeViewDefaultItemModelProperties>;
|
|
73
|
+
itemMetaLookup: import("@mui/x-tree-view/internals/plugins/useTreeViewItems/useTreeViewItems.types").TreeViewItemMetaLookup;
|
|
74
|
+
itemOrderedChildrenIdsLookup: {
|
|
75
|
+
[parentItemId: string]: string[];
|
|
76
|
+
};
|
|
77
|
+
itemChildrenIndexesLookup: {
|
|
78
|
+
[parentItemId: string]: {
|
|
79
|
+
[itemId: string]: number;
|
|
80
|
+
};
|
|
81
|
+
};
|
|
82
|
+
}) => import("@mui/x-tree-view/internals/plugins/useTreeViewItems/useTreeViewItems.types").TreeViewItemMetaLookup;
|
|
83
|
+
memoizedResultFunc: ((resultFuncArgs_0: {
|
|
84
|
+
disabledItemsFocusable: boolean;
|
|
85
|
+
itemModelLookup: import("@mui/x-tree-view/internals/plugins/useTreeViewItems/useTreeViewItems.types").TreeViewItemModelLookup<import("@mui/x-tree-view").TreeViewDefaultItemModelProperties>;
|
|
86
|
+
itemMetaLookup: import("@mui/x-tree-view/internals/plugins/useTreeViewItems/useTreeViewItems.types").TreeViewItemMetaLookup;
|
|
87
|
+
itemOrderedChildrenIdsLookup: {
|
|
88
|
+
[parentItemId: string]: string[];
|
|
89
|
+
};
|
|
90
|
+
itemChildrenIndexesLookup: {
|
|
91
|
+
[parentItemId: string]: {
|
|
92
|
+
[itemId: string]: number;
|
|
93
|
+
};
|
|
94
|
+
};
|
|
95
|
+
}) => import("@mui/x-tree-view/internals/plugins/useTreeViewItems/useTreeViewItems.types").TreeViewItemMetaLookup) & {
|
|
96
|
+
clearCache: () => void;
|
|
97
|
+
resultsCount: () => number;
|
|
98
|
+
resetResultsCount: () => void;
|
|
99
|
+
};
|
|
100
|
+
lastResult: () => import("@mui/x-tree-view/internals/plugins/useTreeViewItems/useTreeViewItems.types").TreeViewItemMetaLookup;
|
|
101
|
+
dependencies: [import("@mui/x-tree-view/internals/utils/selectors").TreeViewRootSelector<import("@mui/x-tree-view/internals").UseTreeViewItemsSignature>];
|
|
102
|
+
recomputations: () => number;
|
|
103
|
+
resetRecomputations: () => void;
|
|
104
|
+
dependencyRecomputations: () => number;
|
|
105
|
+
resetDependencyRecomputations: () => void;
|
|
106
|
+
} & {
|
|
107
|
+
argsMemoize: typeof import("reselect").weakMapMemoize;
|
|
108
|
+
memoize: typeof import("reselect").weakMapMemoize;
|
|
109
|
+
}, (_: any, itemId: string) => string];
|
|
110
|
+
recomputations: () => number;
|
|
111
|
+
resetRecomputations: () => void;
|
|
112
|
+
dependencyRecomputations: () => number;
|
|
113
|
+
resetDependencyRecomputations: () => void;
|
|
114
|
+
} & {
|
|
115
|
+
argsMemoize: typeof import("reselect").weakMapMemoize;
|
|
116
|
+
memoize: typeof import("reselect").weakMapMemoize;
|
|
117
|
+
};
|
|
118
|
+
/**
|
|
119
|
+
* Check if the current item is a valid target for the dragged item.
|
|
120
|
+
* @param {TreeViewState<[UseTreeViewItemsReorderingSignature]>} state The state of the tree view.
|
|
121
|
+
* @param {string} itemId The id of the item.
|
|
122
|
+
* @returns {boolean} `true` if the current item is a valid target for the dragged item, `false` otherwise.
|
|
123
|
+
*/
|
|
124
|
+
export declare const selectorItemsReorderingIsValidTarget: ((state: any, itemId: string) => boolean | null) & {
|
|
125
|
+
clearCache: () => void;
|
|
126
|
+
resultsCount: () => number;
|
|
127
|
+
resetResultsCount: () => void;
|
|
128
|
+
} & {
|
|
129
|
+
resultFunc: (resultFuncArgs_0: {
|
|
130
|
+
draggedItemId: string;
|
|
131
|
+
targetItemId: string;
|
|
132
|
+
newPosition: import("./useTreeViewItemsReordering.types").TreeViewItemReorderPosition | null;
|
|
133
|
+
action: import("@mui/x-tree-view").TreeViewItemsReorderingAction | null;
|
|
134
|
+
} | null, resultFuncArgs_1: string) => boolean | null;
|
|
135
|
+
memoizedResultFunc: ((resultFuncArgs_0: {
|
|
136
|
+
draggedItemId: string;
|
|
137
|
+
targetItemId: string;
|
|
138
|
+
newPosition: import("./useTreeViewItemsReordering.types").TreeViewItemReorderPosition | null;
|
|
139
|
+
action: import("@mui/x-tree-view").TreeViewItemsReorderingAction | null;
|
|
140
|
+
} | null, resultFuncArgs_1: string) => boolean | null) & {
|
|
141
|
+
clearCache: () => void;
|
|
142
|
+
resultsCount: () => number;
|
|
143
|
+
resetResultsCount: () => void;
|
|
144
|
+
};
|
|
145
|
+
lastResult: () => boolean | null;
|
|
146
|
+
dependencies: [(state: TreeViewState<[UseTreeViewItemsReorderingSignature]>) => {
|
|
147
|
+
draggedItemId: string;
|
|
148
|
+
targetItemId: string;
|
|
149
|
+
newPosition: import("./useTreeViewItemsReordering.types").TreeViewItemReorderPosition | null;
|
|
150
|
+
action: import("@mui/x-tree-view").TreeViewItemsReorderingAction | null;
|
|
151
|
+
} | null, (_: any, itemId: string) => string];
|
|
152
|
+
recomputations: () => number;
|
|
153
|
+
resetRecomputations: () => void;
|
|
154
|
+
dependencyRecomputations: () => number;
|
|
155
|
+
resetDependencyRecomputations: () => void;
|
|
156
|
+
} & {
|
|
157
|
+
argsMemoize: typeof import("reselect").weakMapMemoize;
|
|
158
|
+
memoize: typeof import("reselect").weakMapMemoize;
|
|
159
|
+
};
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import { createSelector, selectorItemMetaLookup } from '@mui/x-tree-view/internals';
|
|
2
|
+
/**
|
|
3
|
+
* Get the items reordering state.
|
|
4
|
+
* @param {TreeViewState<[UseTreeViewItemsReorderingSignature]>} state The state of the tree view.
|
|
5
|
+
* @returns {TreeViewItemsReorderingState | null} The items reordering state.
|
|
6
|
+
*/
|
|
7
|
+
export const selectorItemsReordering = state => state.itemsReordering;
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* Get the properties of the dragged item.
|
|
11
|
+
* @param {TreeViewState<[UseTreeViewItemsSignature, UseTreeViewItemsReorderingSignature]>} state The state of the tree view.
|
|
12
|
+
* @param {string} itemId The id of the item.
|
|
13
|
+
* @returns {TreeViewItemDraggedItemProperties | null} The properties of the dragged item if the current item is being dragged, `null` otherwise.
|
|
14
|
+
*/
|
|
15
|
+
export const selectorItemsReorderingDraggedItemProperties = createSelector([selectorItemsReordering, selectorItemMetaLookup, (_, itemId) => itemId], (itemsReordering, itemMetaLookup, itemId) => {
|
|
16
|
+
if (!itemsReordering || itemsReordering.targetItemId !== itemId || itemsReordering.action == null) {
|
|
17
|
+
return null;
|
|
18
|
+
}
|
|
19
|
+
const targetDepth = itemsReordering.newPosition?.parentId == null ? 0 :
|
|
20
|
+
// The depth is always defined because drag&drop is only usable with Rich Tree View components.
|
|
21
|
+
itemMetaLookup[itemId].depth + 1;
|
|
22
|
+
return {
|
|
23
|
+
newPosition: itemsReordering.newPosition,
|
|
24
|
+
action: itemsReordering.action,
|
|
25
|
+
targetDepth
|
|
26
|
+
};
|
|
27
|
+
});
|
|
28
|
+
|
|
29
|
+
/**
|
|
30
|
+
* Check if the current item is a valid target for the dragged item.
|
|
31
|
+
* @param {TreeViewState<[UseTreeViewItemsReorderingSignature]>} state The state of the tree view.
|
|
32
|
+
* @param {string} itemId The id of the item.
|
|
33
|
+
* @returns {boolean} `true` if the current item is a valid target for the dragged item, `false` otherwise.
|
|
34
|
+
*/
|
|
35
|
+
export const selectorItemsReorderingIsValidTarget = createSelector([selectorItemsReordering, (_, itemId) => itemId], (itemsReordering, itemId) => itemsReordering && itemsReordering.draggedItemId !== itemId);
|
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
import * as React from 'react';
|
|
2
|
-
import { DefaultizedProps
|
|
2
|
+
import { DefaultizedProps } from '@mui/x-internals/types';
|
|
3
|
+
import { TreeViewPluginSignature, UseTreeViewItemsSignature } from '@mui/x-tree-view/internals';
|
|
3
4
|
import { TreeViewItemId, TreeViewItemsReorderingAction, TreeViewCancellableEventHandler } from '@mui/x-tree-view/models';
|
|
4
|
-
import {
|
|
5
|
+
import { TreeItemDragAndDropOverlayProps } from '@mui/x-tree-view/TreeItemDragAndDropOverlay';
|
|
5
6
|
export interface UseTreeViewItemsReorderingInstance {
|
|
6
7
|
/**
|
|
7
8
|
* Check if a given item can be dragged.
|
|
@@ -105,7 +106,7 @@ export interface UseTreeViewItemsReorderingState {
|
|
|
105
106
|
interface UseTreeViewItemsReorderingContextValue {
|
|
106
107
|
itemsReordering: {
|
|
107
108
|
enabled: boolean;
|
|
108
|
-
|
|
109
|
+
isItemReorderable: ((itemId: string) => boolean) | undefined;
|
|
109
110
|
};
|
|
110
111
|
}
|
|
111
112
|
export type UseTreeViewItemsReorderingSignature = TreeViewPluginSignature<{
|
|
@@ -117,24 +118,24 @@ export type UseTreeViewItemsReorderingSignature = TreeViewPluginSignature<{
|
|
|
117
118
|
experimentalFeatures: 'itemsReordering';
|
|
118
119
|
dependencies: [UseTreeViewItemsSignature];
|
|
119
120
|
}>;
|
|
120
|
-
export interface
|
|
121
|
+
export interface UseTreeItemRootSlotPropsFromItemsReordering {
|
|
121
122
|
draggable?: true;
|
|
122
123
|
onDragStart?: TreeViewCancellableEventHandler<React.DragEvent>;
|
|
123
124
|
onDragOver?: TreeViewCancellableEventHandler<React.DragEvent>;
|
|
124
125
|
onDragEnd?: TreeViewCancellableEventHandler<React.DragEvent>;
|
|
125
126
|
}
|
|
126
|
-
export interface
|
|
127
|
+
export interface UseTreeItemContentSlotPropsFromItemsReordering {
|
|
127
128
|
onDragEnter?: TreeViewCancellableEventHandler<React.DragEvent>;
|
|
128
129
|
onDragOver?: TreeViewCancellableEventHandler<React.DragEvent>;
|
|
129
130
|
}
|
|
130
|
-
export interface
|
|
131
|
+
export interface UseTreeItemDragAndDropOverlaySlotPropsFromItemsReordering extends TreeItemDragAndDropOverlayProps {
|
|
131
132
|
}
|
|
132
|
-
declare module '@mui/x-tree-view/
|
|
133
|
-
interface
|
|
133
|
+
declare module '@mui/x-tree-view/useTreeItem' {
|
|
134
|
+
interface UseTreeItemRootSlotOwnProps extends UseTreeItemRootSlotPropsFromItemsReordering {
|
|
134
135
|
}
|
|
135
|
-
interface
|
|
136
|
+
interface UseTreeItemContentSlotOwnProps extends UseTreeItemContentSlotPropsFromItemsReordering {
|
|
136
137
|
}
|
|
137
|
-
interface
|
|
138
|
+
interface UseTreeItemDragAndDropOverlaySlotOwnProps extends UseTreeItemDragAndDropOverlaySlotPropsFromItemsReordering {
|
|
138
139
|
}
|
|
139
140
|
}
|
|
140
141
|
export {};
|
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { TreeViewUsedStore, UseTreeViewItemsState } from '@mui/x-tree-view/internals';
|
|
2
2
|
import { TreeViewItemId, TreeViewItemsReorderingAction } from '@mui/x-tree-view/models';
|
|
3
|
-
import { TreeViewItemItemReorderingValidActions, TreeViewItemReorderPosition } from './useTreeViewItemsReordering.types';
|
|
3
|
+
import { TreeViewItemItemReorderingValidActions, TreeViewItemReorderPosition, UseTreeViewItemsReorderingSignature } from './useTreeViewItemsReordering.types';
|
|
4
4
|
/**
|
|
5
5
|
* Checks if the item with the id itemIdB is an ancestor of the item with the id itemIdA.
|
|
6
6
|
*/
|
|
7
|
-
export declare const isAncestor: (
|
|
7
|
+
export declare const isAncestor: (store: TreeViewUsedStore<UseTreeViewItemsReorderingSignature>, itemIdA: string, itemIdB: string) => boolean;
|
|
8
8
|
interface GetNewPositionParams {
|
|
9
9
|
itemChildrenIndentation: string | number;
|
|
10
10
|
validActions: TreeViewItemItemReorderingValidActions;
|
|
@@ -15,9 +15,7 @@ interface GetNewPositionParams {
|
|
|
15
15
|
contentElement: HTMLDivElement;
|
|
16
16
|
}
|
|
17
17
|
export declare const chooseActionToApply: ({ itemChildrenIndentation, validActions, targetHeight, targetDepth, cursorX, cursorY, contentElement, }: GetNewPositionParams) => TreeViewItemsReorderingAction | null;
|
|
18
|
-
export declare const moveItemInTree: <R extends {
|
|
19
|
-
children?: R[];
|
|
20
|
-
}>({ itemToMoveId, oldPosition, newPosition, prevState, }: {
|
|
18
|
+
export declare const moveItemInTree: <R extends {}>({ itemToMoveId, oldPosition, newPosition, prevState, }: {
|
|
21
19
|
itemToMoveId: TreeViewItemId;
|
|
22
20
|
oldPosition: TreeViewItemReorderPosition;
|
|
23
21
|
newPosition: TreeViewItemReorderPosition;
|