@mui/x-tree-view-pro 7.12.0 → 7.13.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.
Files changed (96) hide show
  1. package/{build/CHANGELOG.md → CHANGELOG.md} +151 -2
  2. package/{build/RichTreeViewPro → RichTreeViewPro}/RichTreeViewPro.js +21 -3
  3. package/{build/RichTreeViewPro → RichTreeViewPro}/RichTreeViewPro.plugins.d.ts +3 -3
  4. package/{build/RichTreeViewPro → RichTreeViewPro}/RichTreeViewPro.plugins.js +2 -2
  5. package/{build/index.js → index.js} +1 -1
  6. package/{build/modern/internals → internals}/plugins/useTreeViewItemsReordering/useTreeViewItemsReordering.js +5 -4
  7. package/{build/internals → internals}/plugins/useTreeViewItemsReordering/useTreeViewItemsReordering.types.d.ts +1 -1
  8. package/{build/internals → internals}/utils/releaseInfo.js +1 -1
  9. package/{build/modern → modern}/RichTreeViewPro/RichTreeViewPro.js +21 -3
  10. package/{build/modern → modern}/RichTreeViewPro/RichTreeViewPro.plugins.js +2 -2
  11. package/{build/modern → modern}/index.js +1 -1
  12. package/{build → modern}/internals/plugins/useTreeViewItemsReordering/useTreeViewItemsReordering.js +5 -4
  13. package/{build/modern → modern}/internals/utils/releaseInfo.js +1 -1
  14. package/{build/node → node}/RichTreeViewPro/RichTreeViewPro.js +21 -3
  15. package/{build/node → node}/RichTreeViewPro/RichTreeViewPro.plugins.js +1 -1
  16. package/{build/node → node}/index.js +1 -1
  17. package/{build/node → node}/internals/plugins/useTreeViewItemsReordering/useTreeViewItemsReordering.js +5 -4
  18. package/{build/node → node}/internals/utils/releaseInfo.js +1 -1
  19. package/package.json +17 -20
  20. package/build/LICENSE +0 -11
  21. package/build/README.md +0 -26
  22. package/build/package.json +0 -59
  23. package/src/RichTreeViewPro/RichTreeViewPro.plugins.ts +0 -54
  24. package/src/RichTreeViewPro/RichTreeViewPro.test.tsx +0 -20
  25. package/src/RichTreeViewPro/RichTreeViewPro.tsx +0 -383
  26. package/src/RichTreeViewPro/RichTreeViewPro.types.ts +0 -80
  27. package/src/RichTreeViewPro/index.ts +0 -8
  28. package/src/RichTreeViewPro/richTreeViewProClasses.ts +0 -18
  29. package/src/index.ts +0 -17
  30. package/src/internals/index.ts +0 -1
  31. package/src/internals/plugins/useTreeViewItemsReordering/index.ts +0 -7
  32. package/src/internals/plugins/useTreeViewItemsReordering/useTreeViewItemsReordering.itemPlugin.ts +0 -155
  33. package/src/internals/plugins/useTreeViewItemsReordering/useTreeViewItemsReordering.test.tsx +0 -370
  34. package/src/internals/plugins/useTreeViewItemsReordering/useTreeViewItemsReordering.ts +0 -278
  35. package/src/internals/plugins/useTreeViewItemsReordering/useTreeViewItemsReordering.types.ts +0 -160
  36. package/src/internals/plugins/useTreeViewItemsReordering/useTreeViewItemsReordering.utils.ts +0 -199
  37. package/src/internals/utils/releaseInfo.ts +0 -15
  38. package/src/internals/zero-styled/index.ts +0 -8
  39. package/src/themeAugmentation/components.d.ts +0 -13
  40. package/src/themeAugmentation/index.js +0 -1
  41. package/src/themeAugmentation/index.ts +0 -3
  42. package/src/themeAugmentation/overrides.d.ts +0 -13
  43. package/src/themeAugmentation/props.d.ts +0 -12
  44. package/src/themeAugmentation/themeAugmentation.spec.ts +0 -26
  45. package/tsconfig.build.json +0 -21
  46. package/tsconfig.build.tsbuildinfo +0 -1
  47. package/tsconfig.json +0 -14
  48. /package/{build/RichTreeViewPro → RichTreeViewPro}/RichTreeViewPro.d.ts +0 -0
  49. /package/{build/RichTreeViewPro → RichTreeViewPro}/RichTreeViewPro.types.d.ts +0 -0
  50. /package/{build/RichTreeViewPro → RichTreeViewPro}/RichTreeViewPro.types.js +0 -0
  51. /package/{build/RichTreeViewPro → RichTreeViewPro}/index.d.ts +0 -0
  52. /package/{build/RichTreeViewPro → RichTreeViewPro}/index.js +0 -0
  53. /package/{build/RichTreeViewPro → RichTreeViewPro}/package.json +0 -0
  54. /package/{build/RichTreeViewPro → RichTreeViewPro}/richTreeViewProClasses.d.ts +0 -0
  55. /package/{build/RichTreeViewPro → RichTreeViewPro}/richTreeViewProClasses.js +0 -0
  56. /package/{build/index.d.ts → index.d.ts} +0 -0
  57. /package/{build/internals → internals}/index.d.ts +0 -0
  58. /package/{build/internals → internals}/index.js +0 -0
  59. /package/{build/internals → internals}/package.json +0 -0
  60. /package/{build/internals → internals}/plugins/useTreeViewItemsReordering/index.d.ts +0 -0
  61. /package/{build/internals → internals}/plugins/useTreeViewItemsReordering/index.js +0 -0
  62. /package/{build/internals → internals}/plugins/useTreeViewItemsReordering/useTreeViewItemsReordering.d.ts +0 -0
  63. /package/{build/internals → internals}/plugins/useTreeViewItemsReordering/useTreeViewItemsReordering.itemPlugin.d.ts +0 -0
  64. /package/{build/internals → internals}/plugins/useTreeViewItemsReordering/useTreeViewItemsReordering.itemPlugin.js +0 -0
  65. /package/{build/internals → internals}/plugins/useTreeViewItemsReordering/useTreeViewItemsReordering.types.js +0 -0
  66. /package/{build/internals → internals}/plugins/useTreeViewItemsReordering/useTreeViewItemsReordering.utils.d.ts +0 -0
  67. /package/{build/internals → internals}/plugins/useTreeViewItemsReordering/useTreeViewItemsReordering.utils.js +0 -0
  68. /package/{build/internals → internals}/utils/releaseInfo.d.ts +0 -0
  69. /package/{build/internals → internals}/zero-styled/index.d.ts +0 -0
  70. /package/{build/internals → internals}/zero-styled/index.js +0 -0
  71. /package/{build/modern → modern}/RichTreeViewPro/RichTreeViewPro.types.js +0 -0
  72. /package/{build/modern → modern}/RichTreeViewPro/index.js +0 -0
  73. /package/{build/modern → modern}/RichTreeViewPro/richTreeViewProClasses.js +0 -0
  74. /package/{build/modern → modern}/internals/index.js +0 -0
  75. /package/{build/modern → modern}/internals/plugins/useTreeViewItemsReordering/index.js +0 -0
  76. /package/{build/modern → modern}/internals/plugins/useTreeViewItemsReordering/useTreeViewItemsReordering.itemPlugin.js +0 -0
  77. /package/{build/modern → modern}/internals/plugins/useTreeViewItemsReordering/useTreeViewItemsReordering.types.js +0 -0
  78. /package/{build/modern → modern}/internals/plugins/useTreeViewItemsReordering/useTreeViewItemsReordering.utils.js +0 -0
  79. /package/{build/modern → modern}/internals/zero-styled/index.js +0 -0
  80. /package/{build/modern → modern}/themeAugmentation/index.js +0 -0
  81. /package/{build/node → node}/RichTreeViewPro/RichTreeViewPro.types.js +0 -0
  82. /package/{build/node → node}/RichTreeViewPro/index.js +0 -0
  83. /package/{build/node → node}/RichTreeViewPro/richTreeViewProClasses.js +0 -0
  84. /package/{build/node → node}/internals/index.js +0 -0
  85. /package/{build/node → node}/internals/plugins/useTreeViewItemsReordering/index.js +0 -0
  86. /package/{build/node → node}/internals/plugins/useTreeViewItemsReordering/useTreeViewItemsReordering.itemPlugin.js +0 -0
  87. /package/{build/node → node}/internals/plugins/useTreeViewItemsReordering/useTreeViewItemsReordering.types.js +0 -0
  88. /package/{build/node → node}/internals/plugins/useTreeViewItemsReordering/useTreeViewItemsReordering.utils.js +0 -0
  89. /package/{build/node → node}/internals/zero-styled/index.js +0 -0
  90. /package/{build/node → node}/themeAugmentation/index.js +0 -0
  91. /package/{build/themeAugmentation → themeAugmentation}/components.d.ts +0 -0
  92. /package/{build/themeAugmentation → themeAugmentation}/index.d.ts +0 -0
  93. /package/{build/themeAugmentation → themeAugmentation}/index.js +0 -0
  94. /package/{build/themeAugmentation → themeAugmentation}/overrides.d.ts +0 -0
  95. /package/{build/themeAugmentation → themeAugmentation}/package.json +0 -0
  96. /package/{build/themeAugmentation → themeAugmentation}/props.d.ts +0 -0
@@ -1,278 +0,0 @@
1
- import * as React from 'react';
2
- import { warnOnce, TreeViewPlugin } from '@mui/x-tree-view/internals';
3
- import { TreeViewItemsReorderingAction } from '@mui/x-tree-view/models';
4
- import {
5
- TreeViewItemItemReorderingValidActions,
6
- TreeViewItemReorderPosition,
7
- UseTreeViewItemsReorderingInstance,
8
- UseTreeViewItemsReorderingSignature,
9
- } from './useTreeViewItemsReordering.types';
10
- import {
11
- chooseActionToApply,
12
- isAncestor,
13
- moveItemInTree,
14
- } from './useTreeViewItemsReordering.utils';
15
- import { useTreeViewItemsReorderingItemPlugin } from './useTreeViewItemsReordering.itemPlugin';
16
-
17
- export const useTreeViewItemsReordering: TreeViewPlugin<UseTreeViewItemsReorderingSignature> = ({
18
- params,
19
- instance,
20
- state,
21
- setState,
22
- experimentalFeatures,
23
- }) => {
24
- const isItemsReorderingEnabled =
25
- params.itemsReordering && !!experimentalFeatures?.itemsReordering;
26
-
27
- if (process.env.NODE_ENV !== 'production') {
28
- if (
29
- params.itemsReordering &&
30
- (!experimentalFeatures?.indentationAtItemLevel || !experimentalFeatures?.itemsReordering)
31
- ) {
32
- warnOnce([
33
- 'MUI X: The items reordering feature requires the `indentationAtItemLevel` and `itemsReordering` experimental features to be enabled.',
34
- 'You can do it by passing `experimentalFeatures={{ indentationAtItemLevel: true, itemsReordering: true }}` to the `RichTreeViewPro` component.',
35
- 'Check the documentation for more details: https://mui.com/x/react-tree-view/rich-tree-view/items/',
36
- ]);
37
- }
38
- }
39
-
40
- const canItemBeDragged = React.useCallback(
41
- (itemId: string) => {
42
- if (!isItemsReorderingEnabled) {
43
- return false;
44
- }
45
-
46
- const isItemReorderable = params.isItemReorderable;
47
- if (isItemReorderable) {
48
- return isItemReorderable(itemId);
49
- }
50
-
51
- return true;
52
- },
53
- [isItemsReorderingEnabled, params.isItemReorderable],
54
- );
55
-
56
- const getDroppingTargetValidActions = React.useCallback(
57
- (itemId: string) => {
58
- if (!state.itemsReordering) {
59
- throw new Error('There is no ongoing reordering.');
60
- }
61
-
62
- if (itemId === state.itemsReordering.draggedItemId) {
63
- return {};
64
- }
65
-
66
- const canMoveItemToNewPosition = params.canMoveItemToNewPosition;
67
- const targetItemMeta = instance.getItemMeta(itemId);
68
- const targetItemIndex = instance.getItemIndex(targetItemMeta.id);
69
- const draggedItemMeta = instance.getItemMeta(state.itemsReordering.draggedItemId);
70
- const draggedItemIndex = instance.getItemIndex(draggedItemMeta.id);
71
-
72
- const oldPosition: TreeViewItemReorderPosition = {
73
- parentId: draggedItemMeta.parentId,
74
- index: draggedItemIndex,
75
- };
76
-
77
- const checkIfPositionIsValid = (positionAfterAction: TreeViewItemReorderPosition) => {
78
- let isValid: boolean;
79
- // If the new position is equal to the old one, we don't want to show any dropping UI.
80
- if (
81
- positionAfterAction.parentId === oldPosition.parentId &&
82
- positionAfterAction.index === oldPosition.index
83
- ) {
84
- isValid = false;
85
- } else if (canMoveItemToNewPosition) {
86
- isValid = canMoveItemToNewPosition({
87
- itemId,
88
- oldPosition,
89
- newPosition: positionAfterAction,
90
- });
91
- } else {
92
- isValid = true;
93
- }
94
-
95
- return isValid;
96
- };
97
-
98
- const positionsAfterAction: Record<
99
- TreeViewItemsReorderingAction,
100
- TreeViewItemReorderPosition | null
101
- > = {
102
- 'make-child': { parentId: targetItemMeta.id, index: 0 },
103
- 'reorder-above': {
104
- parentId: targetItemMeta.parentId,
105
- index:
106
- targetItemMeta.parentId === draggedItemMeta.parentId &&
107
- targetItemIndex > draggedItemIndex
108
- ? targetItemIndex - 1
109
- : targetItemIndex,
110
- },
111
- 'reorder-below': targetItemMeta.expandable
112
- ? null
113
- : {
114
- parentId: targetItemMeta.parentId,
115
- index:
116
- targetItemMeta.parentId === draggedItemMeta.parentId &&
117
- targetItemIndex > draggedItemIndex
118
- ? targetItemIndex
119
- : targetItemIndex + 1,
120
- },
121
- 'move-to-parent':
122
- targetItemMeta.parentId == null
123
- ? null
124
- : {
125
- parentId: targetItemMeta.parentId,
126
- index: instance.getItemOrderedChildrenIds(targetItemMeta.parentId).length,
127
- },
128
- };
129
-
130
- const validActions: TreeViewItemItemReorderingValidActions = {};
131
- Object.keys(positionsAfterAction).forEach((action) => {
132
- const positionAfterAction = positionsAfterAction[action as TreeViewItemsReorderingAction];
133
- if (positionAfterAction != null && checkIfPositionIsValid(positionAfterAction)) {
134
- validActions[action as TreeViewItemsReorderingAction] = positionAfterAction;
135
- }
136
- });
137
-
138
- return validActions;
139
- },
140
- [instance, state.itemsReordering, params.canMoveItemToNewPosition],
141
- );
142
-
143
- const startDraggingItem = React.useCallback(
144
- (itemId: string) => {
145
- setState((prevState) => ({
146
- ...prevState,
147
- itemsReordering: {
148
- targetItemId: itemId,
149
- draggedItemId: itemId,
150
- action: null,
151
- newPosition: null,
152
- },
153
- }));
154
- },
155
- [setState],
156
- );
157
-
158
- const stopDraggingItem = React.useCallback(
159
- (itemId: string) => {
160
- if (state.itemsReordering == null || state.itemsReordering.draggedItemId !== itemId) {
161
- return;
162
- }
163
-
164
- if (
165
- state.itemsReordering.draggedItemId === state.itemsReordering.targetItemId ||
166
- state.itemsReordering.action == null ||
167
- state.itemsReordering.newPosition == null
168
- ) {
169
- setState((prevState) => ({ ...prevState, itemsReordering: null }));
170
- return;
171
- }
172
-
173
- const draggedItemMeta = instance.getItemMeta(state.itemsReordering.draggedItemId);
174
-
175
- const oldPosition: TreeViewItemReorderPosition = {
176
- parentId: draggedItemMeta.parentId,
177
- index: instance.getItemIndex(draggedItemMeta.id),
178
- };
179
-
180
- const newPosition = state.itemsReordering.newPosition;
181
-
182
- setState((prevState) => ({
183
- ...prevState,
184
- itemsReordering: null,
185
- items: moveItemInTree({
186
- itemToMoveId: itemId,
187
- newPosition,
188
- oldPosition,
189
- prevState: prevState.items,
190
- }),
191
- }));
192
-
193
- const onItemPositionChange = params.onItemPositionChange;
194
- onItemPositionChange?.({
195
- itemId,
196
- newPosition,
197
- oldPosition,
198
- });
199
- },
200
- [setState, state.itemsReordering, instance, params.onItemPositionChange],
201
- );
202
-
203
- const setDragTargetItem = React.useCallback<
204
- UseTreeViewItemsReorderingInstance['setDragTargetItem']
205
- >(
206
- ({ itemId, validActions, targetHeight, cursorY, cursorX, contentElement }) => {
207
- setState((prevState) => {
208
- const prevSubState = prevState.itemsReordering;
209
- if (prevSubState == null || isAncestor(instance, itemId, prevSubState.draggedItemId)) {
210
- return prevState;
211
- }
212
- const action = chooseActionToApply({
213
- itemChildrenIndentation: params.itemChildrenIndentation,
214
- validActions,
215
- targetHeight,
216
- targetDepth: prevState.items.itemMetaMap[itemId].depth!,
217
- cursorY,
218
- cursorX,
219
- contentElement,
220
- });
221
-
222
- const newPosition = action == null ? null : validActions[action]!;
223
-
224
- if (
225
- prevSubState.targetItemId === itemId &&
226
- prevSubState.action === action &&
227
- prevSubState.newPosition?.parentId === newPosition?.parentId &&
228
- prevSubState.newPosition?.index === newPosition?.index
229
- ) {
230
- return prevState;
231
- }
232
-
233
- return {
234
- ...prevState,
235
- itemsReordering: {
236
- ...prevSubState,
237
- targetItemId: itemId,
238
- newPosition,
239
- action,
240
- },
241
- };
242
- });
243
- },
244
- [instance, setState, params.itemChildrenIndentation],
245
- );
246
-
247
- return {
248
- instance: {
249
- canItemBeDragged,
250
- getDroppingTargetValidActions,
251
- startDraggingItem,
252
- stopDraggingItem,
253
- setDragTargetItem,
254
- },
255
- contextValue: {
256
- itemsReordering: {
257
- enabled: isItemsReorderingEnabled,
258
- currentDrag: state.itemsReordering,
259
- },
260
- },
261
- };
262
- };
263
-
264
- useTreeViewItemsReordering.itemPlugin = useTreeViewItemsReorderingItemPlugin;
265
-
266
- useTreeViewItemsReordering.getDefaultizedParams = (params) => ({
267
- ...params,
268
- itemsReordering: params.itemsReordering ?? false,
269
- });
270
-
271
- useTreeViewItemsReordering.getInitialState = () => ({ itemsReordering: null });
272
-
273
- useTreeViewItemsReordering.params = {
274
- itemsReordering: true,
275
- isItemReorderable: true,
276
- canMoveItemToNewPosition: true,
277
- onItemPositionChange: true,
278
- };
@@ -1,160 +0,0 @@
1
- import * as React from 'react';
2
- import {
3
- DefaultizedProps,
4
- TreeViewPluginSignature,
5
- UseTreeViewItemsSignature,
6
- MuiCancellableEventHandler,
7
- } from '@mui/x-tree-view/internals';
8
- import { TreeViewItemId, TreeViewItemsReorderingAction } from '@mui/x-tree-view/models';
9
- import { TreeItem2DragAndDropOverlayProps } from '@mui/x-tree-view/TreeItem2DragAndDropOverlay';
10
-
11
- export interface UseTreeViewItemsReorderingInstance {
12
- /**
13
- * Check if a given item can be dragged.
14
- * @param {TreeViewItemId} itemId The id of the item to check.
15
- * @returns {boolean} `true` if the item can be dragged, `false` otherwise.
16
- */
17
- canItemBeDragged: (itemId: TreeViewItemId) => boolean;
18
- /**
19
- * Get the valid reordering action if a given item is the target of the ongoing reordering.
20
- * @param {TreeViewItemId} itemId The id of the item to get the action of.
21
- * @returns {TreeViewItemItemReorderingValidActions} The valid actions for the item.
22
- */
23
- getDroppingTargetValidActions: (itemId: TreeViewItemId) => TreeViewItemItemReorderingValidActions;
24
- /**
25
- * Start a reordering for the given item.
26
- * @param {TreeViewItemId} itemId The id of the item to start the reordering for.
27
- */
28
- startDraggingItem: (itemId: TreeViewItemId) => void;
29
- /**
30
- * Stop the reordering of a given item.
31
- * @param {TreeViewItemId} itemId The id of the item to stop the reordering for.
32
- */
33
- stopDraggingItem: (itemId: TreeViewItemId) => void;
34
- /**
35
- * Set the new target item for the ongoing reordering.
36
- * The action will be determined based on the position of the cursor inside the target and the valid actions for this target.
37
- * @param {object} params The params describing the new target item.
38
- * @param {TreeViewItemId} params.itemId The id of the new target item.
39
- * @param {TreeViewItemItemReorderingValidActions} params.validActions The valid actions for the new target item.
40
- * @param {number} params.targetHeight The height of the target item.
41
- * @param {number} params.cursorY The Y coordinate of the mouse cursor.
42
- * @param {number} params.cursorX The X coordinate of the mouse cursor.
43
- * @param {HTMLDivElement} params.contentElement The DOM element rendered for the content slot.
44
- */
45
- setDragTargetItem: (params: {
46
- itemId: TreeViewItemId;
47
- validActions: TreeViewItemItemReorderingValidActions;
48
- targetHeight: number;
49
- cursorY: number;
50
- cursorX: number;
51
- contentElement: HTMLDivElement;
52
- }) => void;
53
- }
54
-
55
- export interface TreeViewItemReorderPosition {
56
- parentId: string | null;
57
- index: number;
58
- }
59
-
60
- export type TreeViewItemItemReorderingValidActions = {
61
- [key in TreeViewItemsReorderingAction]?: TreeViewItemReorderPosition;
62
- };
63
-
64
- export interface UseTreeViewItemsReorderingParameters {
65
- /**
66
- * If `true`, the reordering of items is enabled.
67
- * Make sure to also enable the `itemsReordering` experimental feature:
68
- * `<RichTreeViewPro experimentalFeatures={{ itemsReordering: true }} itemsReordering />`.
69
- * @default false
70
- */
71
- itemsReordering?: boolean;
72
- /**
73
- * Used to determine if a given item can be reordered.
74
- * @param {string} itemId The id of the item to check.
75
- * @returns {boolean} `true` if the item can be reordered.
76
- * @default () => true
77
- */
78
- isItemReorderable?: (itemId: string) => boolean;
79
- /**
80
- * Used to determine if a given item can move to some new position.
81
- * @param {object} params The params describing the item re-ordering.
82
- * @param {string} params.itemId The id of the item to check.
83
- * @param {TreeViewItemReorderPosition} params.oldPosition The old position of the item.
84
- * @param {TreeViewItemReorderPosition} params.newPosition The new position of the item.
85
- * @returns {boolean} `true` if the item can move to the new position.
86
- */
87
- canMoveItemToNewPosition?: (params: {
88
- itemId: string;
89
- oldPosition: TreeViewItemReorderPosition;
90
- newPosition: TreeViewItemReorderPosition;
91
- }) => boolean;
92
- /**
93
- * Callback fired when a tree item is moved in the tree.
94
- * @param {object} params The params describing the item re-ordering.
95
- * @param {string} params.itemId The id of the item moved.
96
- * @param {TreeViewItemReorderPosition} params.oldPosition The old position of the item.
97
- * @param {TreeViewItemReorderPosition} params.newPosition The new position of the item.
98
- */
99
- onItemPositionChange?: (params: {
100
- itemId: string;
101
- oldPosition: TreeViewItemReorderPosition;
102
- newPosition: TreeViewItemReorderPosition;
103
- }) => void;
104
- }
105
-
106
- export type UseTreeViewItemsReorderingDefaultizedParameters = DefaultizedProps<
107
- UseTreeViewItemsReorderingParameters,
108
- 'itemsReordering'
109
- >;
110
-
111
- export interface UseTreeViewItemsReorderingState {
112
- itemsReordering: {
113
- draggedItemId: string;
114
- targetItemId: string;
115
- newPosition: TreeViewItemReorderPosition | null;
116
- action: TreeViewItemsReorderingAction | null;
117
- } | null;
118
- }
119
-
120
- interface UseTreeViewItemsReorderingContextValue {
121
- itemsReordering: {
122
- enabled: boolean;
123
- currentDrag: UseTreeViewItemsReorderingState['itemsReordering'];
124
- };
125
- }
126
-
127
- export type UseTreeViewItemsReorderingSignature = TreeViewPluginSignature<{
128
- params: UseTreeViewItemsReorderingParameters;
129
- defaultizedParams: UseTreeViewItemsReorderingDefaultizedParameters;
130
- instance: UseTreeViewItemsReorderingInstance;
131
- state: UseTreeViewItemsReorderingState;
132
- contextValue: UseTreeViewItemsReorderingContextValue;
133
- experimentalFeatures: 'itemsReordering';
134
- dependencies: [UseTreeViewItemsSignature];
135
- }>;
136
-
137
- export interface UseTreeItem2RootSlotPropsFromItemsReordering {
138
- draggable?: true;
139
- onDragStart?: MuiCancellableEventHandler<React.DragEvent>;
140
- onDragOver?: MuiCancellableEventHandler<React.DragEvent>;
141
- onDragEnd?: MuiCancellableEventHandler<React.DragEvent>;
142
- }
143
-
144
- export interface UseTreeItem2ContentSlotPropsFromItemsReordering {
145
- onDragEnter?: MuiCancellableEventHandler<React.DragEvent>;
146
- onDragOver?: MuiCancellableEventHandler<React.DragEvent>;
147
- }
148
-
149
- export interface UseTreeItem2DragAndDropOverlaySlotPropsFromItemsReordering
150
- extends TreeItem2DragAndDropOverlayProps {}
151
-
152
- declare module '@mui/x-tree-view/useTreeItem2' {
153
- interface UseTreeItem2RootSlotOwnProps extends UseTreeItem2RootSlotPropsFromItemsReordering {}
154
-
155
- interface UseTreeItem2ContentSlotOwnProps
156
- extends UseTreeItem2ContentSlotPropsFromItemsReordering {}
157
-
158
- interface UseTreeItem2DragAndDropOverlaySlotOwnProps
159
- extends UseTreeItem2DragAndDropOverlaySlotPropsFromItemsReordering {}
160
- }
@@ -1,199 +0,0 @@
1
- import {
2
- TreeViewInstance,
3
- UseTreeViewItemsSignature,
4
- UseTreeViewItemsState,
5
- buildSiblingIndexes,
6
- TREE_VIEW_ROOT_PARENT_ID,
7
- } from '@mui/x-tree-view/internals';
8
- import { TreeViewItemId, TreeViewItemsReorderingAction } from '@mui/x-tree-view/models';
9
- import {
10
- TreeViewItemItemReorderingValidActions,
11
- TreeViewItemReorderPosition,
12
- } from './useTreeViewItemsReordering.types';
13
-
14
- /**
15
- * Checks if the item with the id itemIdB is an ancestor of the item with the id itemIdA.
16
- */
17
- export const isAncestor = (
18
- instance: TreeViewInstance<[UseTreeViewItemsSignature]>,
19
- itemIdA: string,
20
- itemIdB: string,
21
- ): boolean => {
22
- const itemMetaA = instance.getItemMeta(itemIdA);
23
- if (itemMetaA.parentId === itemIdB) {
24
- return true;
25
- }
26
-
27
- if (itemMetaA.parentId == null) {
28
- return false;
29
- }
30
-
31
- return isAncestor(instance, itemMetaA.parentId, itemIdB);
32
- };
33
-
34
- /**
35
- * Transforms a CSS string `itemChildrenIndentation` into a number representing the indentation in number.
36
- * @param {string | null} itemChildrenIndentation The indentation as passed to the `itemChildrenIndentation` prop.
37
- * @param {HTMLElement} contentElement The DOM element to which the indentation will be applied.
38
- */
39
- const parseItemChildrenIndentation = (
40
- itemChildrenIndentation: string | number,
41
- contentElement: HTMLElement,
42
- ) => {
43
- if (typeof itemChildrenIndentation === 'number') {
44
- return itemChildrenIndentation;
45
- }
46
-
47
- const pixelExec = /^(\d.+)(px)$/.exec(itemChildrenIndentation);
48
- if (pixelExec) {
49
- return parseFloat(pixelExec[1]);
50
- }
51
-
52
- // If the format is neither `px` nor a number, we need to measure the indentation using an actual DOM element.
53
- const tempElement = document.createElement('div');
54
- tempElement.style.width = itemChildrenIndentation;
55
- tempElement.style.position = 'absolute';
56
- contentElement.appendChild(tempElement);
57
- const value = tempElement.offsetWidth;
58
- contentElement.removeChild(tempElement);
59
-
60
- return value;
61
- };
62
-
63
- interface GetNewPositionParams {
64
- itemChildrenIndentation: string | number;
65
- validActions: TreeViewItemItemReorderingValidActions;
66
- targetHeight: number;
67
- targetDepth: number;
68
- cursorY: number;
69
- cursorX: number;
70
- contentElement: HTMLDivElement;
71
- }
72
-
73
- export const chooseActionToApply = ({
74
- itemChildrenIndentation,
75
- validActions,
76
- targetHeight,
77
- targetDepth,
78
- cursorX,
79
- cursorY,
80
- contentElement,
81
- }: GetNewPositionParams) => {
82
- let action: TreeViewItemsReorderingAction | null;
83
-
84
- const itemChildrenIndentationPx = parseItemChildrenIndentation(
85
- itemChildrenIndentation,
86
- contentElement,
87
- );
88
- // If we can move the item to the parent of the target, then we allocate the left offset to this action
89
- // Support moving to other ancestors
90
- if (validActions['move-to-parent'] && cursorX < itemChildrenIndentationPx * targetDepth) {
91
- action = 'move-to-parent';
92
- }
93
-
94
- // If we can move the item inside the target, then we have the following split:
95
- // - the upper quarter of the target moves it above
96
- // - the lower quarter of the target moves it below
97
- // - the inner half makes it a child
98
- else if (validActions['make-child']) {
99
- if (validActions['reorder-above'] && cursorY < (1 / 4) * targetHeight) {
100
- action = 'reorder-above';
101
- } else if (validActions['reorder-below'] && cursorY > (3 / 4) * targetHeight) {
102
- action = 'reorder-below';
103
- } else {
104
- action = 'make-child';
105
- }
106
- }
107
- // If we can't move the item inside the target, then we have the following split:
108
- // - the upper half of the target moves it above
109
- // - the lower half of the target moves it below
110
- else {
111
- // eslint-disable-next-line no-lonely-if
112
- if (validActions['reorder-above'] && cursorY < (1 / 2) * targetHeight) {
113
- action = 'reorder-above';
114
- } else if (validActions['reorder-below'] && cursorY >= (1 / 2) * targetHeight) {
115
- action = 'reorder-below';
116
- } else {
117
- action = null;
118
- }
119
- }
120
-
121
- return action;
122
- };
123
-
124
- export const moveItemInTree = <R extends { children?: R[] }>({
125
- itemToMoveId,
126
- oldPosition,
127
- newPosition,
128
- prevState,
129
- }: {
130
- itemToMoveId: TreeViewItemId;
131
- oldPosition: TreeViewItemReorderPosition;
132
- newPosition: TreeViewItemReorderPosition;
133
- prevState: UseTreeViewItemsState<R>['items'];
134
- }): UseTreeViewItemsState<R>['items'] => {
135
- const itemToMoveMeta = prevState.itemMetaMap[itemToMoveId];
136
-
137
- const oldParentId = oldPosition.parentId ?? TREE_VIEW_ROOT_PARENT_ID;
138
- const newParentId = newPosition.parentId ?? TREE_VIEW_ROOT_PARENT_ID;
139
-
140
- // 1. Update the `itemOrderedChildrenIds`.
141
- const itemOrderedChildrenIds = { ...prevState.itemOrderedChildrenIds };
142
- if (oldParentId === newParentId) {
143
- const updatedChildren = [...itemOrderedChildrenIds[oldParentId]];
144
- updatedChildren.splice(oldPosition.index, 1);
145
- updatedChildren.splice(newPosition.index, 0, itemToMoveId);
146
- itemOrderedChildrenIds[itemToMoveMeta.parentId ?? TREE_VIEW_ROOT_PARENT_ID] = updatedChildren;
147
- } else {
148
- const updatedOldParentChildren = [...itemOrderedChildrenIds[oldParentId]];
149
- updatedOldParentChildren.splice(oldPosition.index, 1);
150
- itemOrderedChildrenIds[oldParentId] = updatedOldParentChildren;
151
-
152
- const updatedNewParentChildren = [...(itemOrderedChildrenIds[newParentId] ?? [])];
153
- updatedNewParentChildren.splice(newPosition.index, 0, itemToMoveId);
154
- itemOrderedChildrenIds[newParentId] = updatedNewParentChildren;
155
- }
156
-
157
- // 2. Update the `itemChildrenIndexes`
158
- const itemChildrenIndexes = { ...prevState.itemChildrenIndexes };
159
- itemChildrenIndexes[oldParentId] = buildSiblingIndexes(itemOrderedChildrenIds[oldParentId]);
160
- if (newParentId !== oldParentId) {
161
- itemChildrenIndexes[newParentId] = buildSiblingIndexes(itemOrderedChildrenIds[newParentId]);
162
- }
163
-
164
- // 3. Update the `itemMetaMap`
165
- const itemMetaMap = { ...prevState.itemMetaMap };
166
-
167
- // 3.1 Update the `expandable` property of the old and the new parent
168
- if (oldParentId !== TREE_VIEW_ROOT_PARENT_ID && oldParentId !== newParentId) {
169
- itemMetaMap[oldParentId].expandable = itemOrderedChildrenIds[oldParentId].length > 0;
170
- }
171
- if (newParentId !== TREE_VIEW_ROOT_PARENT_ID && newParentId !== oldParentId) {
172
- itemMetaMap[newParentId].expandable = itemOrderedChildrenIds[newParentId].length > 0;
173
- }
174
-
175
- // 3.2 Update the `parentId` and `depth` properties of the item to move
176
- // The depth is always defined because drag&drop is only usable with Rich Tree View components.
177
- const itemToMoveDepth = newPosition.parentId == null ? 0 : itemMetaMap[newParentId].depth! + 1;
178
- itemMetaMap[itemToMoveId] = {
179
- ...itemToMoveMeta,
180
- parentId: newPosition.parentId,
181
- depth: itemToMoveDepth,
182
- };
183
-
184
- // 3.3 Update the depth of all the children of the item to move
185
- const updateItemDepth = (itemId: string, depth: number) => {
186
- itemMetaMap[itemId] = { ...itemMetaMap[itemId], depth };
187
- itemOrderedChildrenIds[itemId]?.forEach((childId) => updateItemDepth(childId, depth + 1));
188
- };
189
- itemOrderedChildrenIds[itemToMoveId]?.forEach((childId) =>
190
- updateItemDepth(childId, itemToMoveDepth + 1),
191
- );
192
-
193
- return {
194
- ...prevState,
195
- itemOrderedChildrenIds,
196
- itemChildrenIndexes,
197
- itemMetaMap,
198
- };
199
- };
@@ -1,15 +0,0 @@
1
- import { ponyfillGlobal } from '@mui/utils';
2
-
3
- export const getReleaseInfo = () => {
4
- const releaseInfo = '__RELEASE_INFO__';
5
- if (process.env.NODE_ENV !== 'production') {
6
- // A simple hack to set the value in the test environment (has no build step).
7
- // eslint-disable-next-line no-useless-concat
8
- if (releaseInfo === '__RELEASE' + '_INFO__') {
9
- // eslint-disable-next-line no-underscore-dangle
10
- return ponyfillGlobal.__MUI_RELEASE_INFO__;
11
- }
12
- }
13
-
14
- return releaseInfo;
15
- };
@@ -1,8 +0,0 @@
1
- import { useThemeProps } from '@mui/material/styles';
2
-
3
- export { styled } from '@mui/material/styles';
4
-
5
- // eslint-disable-next-line @typescript-eslint/no-unused-vars
6
- export function createUseThemeProps(name: string) {
7
- return useThemeProps;
8
- }
@@ -1,13 +0,0 @@
1
- import { ComponentsProps, ComponentsOverrides, ComponentsVariants } from '@mui/material/styles';
2
-
3
- export interface TreeViewComponents<Theme = unknown> {
4
- MuiRichTreeViewPro?: {
5
- defaultProps?: ComponentsProps['MuiRichTreeViewPro'];
6
- styleOverrides?: ComponentsOverrides<Theme>['MuiRichTreeViewPro'];
7
- variants?: ComponentsVariants<Theme>['MuiRichTreeViewPro'];
8
- };
9
- }
10
-
11
- declare module '@mui/material/styles' {
12
- interface Components<Theme = unknown> extends TreeViewComponents<Theme> {}
13
- }
@@ -1 +0,0 @@
1
- // Prefer to use `import type {} from '@mui/x-tree-view-pro/themeAugmentation';` instead to avoid importing an empty file.
@@ -1,3 +0,0 @@
1
- export * from './overrides';
2
- export * from './props';
3
- export * from './components';
@@ -1,13 +0,0 @@
1
- import { RichTreeViewProClassKey } from '../RichTreeViewPro';
2
-
3
- // prettier-ignore
4
- export interface TreeViewComponentNameToClassKey {
5
- MuiRichTreeViewPro: RichTreeViewProClassKey;
6
- }
7
-
8
- declare module '@mui/material/styles' {
9
- interface ComponentNameToClassKey extends TreeViewComponentNameToClassKey {}
10
- }
11
-
12
- // disable automatic export
13
- export {};