@mui/x-tree-view 8.11.0 → 8.11.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.
Files changed (150) hide show
  1. package/CHANGELOG.md +74 -0
  2. package/RichTreeView/RichTreeView.js +16 -15
  3. package/RichTreeView/RichTreeView.types.d.ts +3 -2
  4. package/SimpleTreeView/SimpleTreeView.js +10 -9
  5. package/SimpleTreeView/SimpleTreeView.types.d.ts +3 -2
  6. package/TreeItem/TreeItem.d.ts +1 -1
  7. package/TreeItemProvider/TreeItemProvider.js +3 -3
  8. package/esm/RichTreeView/RichTreeView.js +16 -15
  9. package/esm/RichTreeView/RichTreeView.types.d.ts +3 -2
  10. package/esm/SimpleTreeView/SimpleTreeView.js +10 -9
  11. package/esm/SimpleTreeView/SimpleTreeView.types.d.ts +3 -2
  12. package/esm/TreeItem/TreeItem.d.ts +1 -1
  13. package/esm/TreeItemProvider/TreeItemProvider.js +3 -3
  14. package/esm/hooks/useTreeItemModel.js +3 -3
  15. package/esm/hooks/useTreeItemUtils/useTreeItemUtils.js +24 -25
  16. package/esm/index.js +1 -1
  17. package/esm/internals/TreeViewProvider/TreeViewChildrenItemProvider.js +2 -2
  18. package/esm/internals/TreeViewProvider/TreeViewProvider.types.d.ts +3 -3
  19. package/esm/internals/components/RichTreeViewItems.js +5 -5
  20. package/esm/internals/corePlugins/useTreeViewId/index.d.ts +2 -1
  21. package/esm/internals/corePlugins/useTreeViewId/index.js +2 -1
  22. package/esm/internals/corePlugins/useTreeViewId/useTreeViewId.js +10 -13
  23. package/esm/internals/corePlugins/useTreeViewId/useTreeViewId.selectors.d.ts +8 -34
  24. package/esm/internals/corePlugins/useTreeViewId/useTreeViewId.selectors.js +9 -9
  25. package/esm/internals/index.d.ts +6 -14
  26. package/esm/internals/index.js +6 -13
  27. package/esm/internals/models/plugin.d.ts +2 -3
  28. package/esm/internals/models/treeView.d.ts +4 -6
  29. package/esm/internals/plugins/useTreeViewExpansion/index.d.ts +2 -1
  30. package/esm/internals/plugins/useTreeViewExpansion/index.js +2 -1
  31. package/esm/internals/plugins/useTreeViewExpansion/useTreeViewExpansion.js +26 -30
  32. package/esm/internals/plugins/useTreeViewExpansion/useTreeViewExpansion.selectors.d.ts +24 -316
  33. package/esm/internals/plugins/useTreeViewExpansion/useTreeViewExpansion.selectors.js +27 -38
  34. package/esm/internals/plugins/useTreeViewExpansion/useTreeViewExpansion.types.d.ts +7 -1
  35. package/esm/internals/plugins/useTreeViewFocus/index.d.ts +2 -1
  36. package/esm/internals/plugins/useTreeViewFocus/index.js +2 -1
  37. package/esm/internals/plugins/useTreeViewFocus/useTreeViewFocus.js +17 -21
  38. package/esm/internals/plugins/useTreeViewFocus/useTreeViewFocus.selectors.d.ts +20 -628
  39. package/esm/internals/plugins/useTreeViewFocus/useTreeViewFocus.selectors.js +25 -37
  40. package/esm/internals/plugins/useTreeViewItems/index.d.ts +2 -1
  41. package/esm/internals/plugins/useTreeViewItems/index.js +2 -1
  42. package/esm/internals/plugins/useTreeViewItems/useTreeViewItems.js +78 -99
  43. package/esm/internals/plugins/useTreeViewItems/useTreeViewItems.selectors.d.ts +52 -1142
  44. package/esm/internals/plugins/useTreeViewItems/useTreeViewItems.selectors.js +58 -98
  45. package/esm/internals/plugins/useTreeViewItems/useTreeViewItems.utils.d.ts +1 -1
  46. package/esm/internals/plugins/useTreeViewItems/useTreeViewItems.utils.js +1 -1
  47. package/esm/internals/plugins/useTreeViewJSXItems/useTreeViewJSXItems.js +32 -42
  48. package/esm/internals/plugins/useTreeViewKeyboardNavigation/useTreeViewKeyboardNavigation.js +22 -22
  49. package/esm/internals/plugins/useTreeViewKeyboardNavigation/useTreeViewKeyboardNavigation.types.d.ts +2 -0
  50. package/esm/internals/plugins/useTreeViewLabel/index.d.ts +2 -1
  51. package/esm/internals/plugins/useTreeViewLabel/index.js +2 -1
  52. package/esm/internals/plugins/useTreeViewLabel/useTreeViewLabel.itemPlugin.js +4 -4
  53. package/esm/internals/plugins/useTreeViewLabel/useTreeViewLabel.js +17 -25
  54. package/esm/internals/plugins/useTreeViewLabel/useTreeViewLabel.selectors.d.ts +14 -100
  55. package/esm/internals/plugins/useTreeViewLabel/useTreeViewLabel.selectors.js +24 -34
  56. package/esm/internals/plugins/useTreeViewLazyLoading/index.d.ts +2 -1
  57. package/esm/internals/plugins/useTreeViewLazyLoading/index.js +1 -1
  58. package/esm/internals/plugins/useTreeViewLazyLoading/useTreeViewLazyLoading.selectors.d.ts +18 -245
  59. package/esm/internals/plugins/useTreeViewLazyLoading/useTreeViewLazyLoading.selectors.js +15 -27
  60. package/esm/internals/plugins/useTreeViewLazyLoading/useTreeViewLazyLoading.types.d.ts +20 -6
  61. package/esm/internals/plugins/useTreeViewSelection/index.d.ts +2 -1
  62. package/esm/internals/plugins/useTreeViewSelection/index.js +2 -1
  63. package/esm/internals/plugins/useTreeViewSelection/useTreeViewSelection.itemPlugin.js +25 -38
  64. package/esm/internals/plugins/useTreeViewSelection/useTreeViewSelection.js +30 -34
  65. package/esm/internals/plugins/useTreeViewSelection/useTreeViewSelection.selectors.d.ts +38 -517
  66. package/esm/internals/plugins/useTreeViewSelection/useTreeViewSelection.selectors.js +46 -71
  67. package/esm/internals/plugins/useTreeViewSelection/useTreeViewSelection.types.d.ts +1 -0
  68. package/esm/internals/plugins/useTreeViewSelection/useTreeViewSelection.utils.js +10 -10
  69. package/esm/internals/useTreeView/useTreeView.d.ts +1 -1
  70. package/esm/internals/useTreeView/useTreeView.js +11 -18
  71. package/esm/internals/useTreeView/useTreeView.types.d.ts +1 -1
  72. package/esm/internals/useTreeView/useTreeViewBuildContext.d.ts +2 -3
  73. package/esm/internals/utils/tree.js +33 -33
  74. package/esm/useTreeItem/useTreeItem.js +14 -14
  75. package/esm/useTreeItem/useTreeItem.types.d.ts +2 -1
  76. package/hooks/useTreeItemModel.js +3 -3
  77. package/hooks/useTreeItemUtils/useTreeItemUtils.js +18 -19
  78. package/index.js +1 -1
  79. package/internals/TreeViewProvider/TreeViewChildrenItemProvider.js +1 -1
  80. package/internals/TreeViewProvider/TreeViewProvider.types.d.ts +3 -3
  81. package/internals/components/RichTreeViewItems.js +5 -5
  82. package/internals/corePlugins/useTreeViewId/index.d.ts +2 -1
  83. package/internals/corePlugins/useTreeViewId/index.js +8 -1
  84. package/internals/corePlugins/useTreeViewId/useTreeViewId.js +9 -12
  85. package/internals/corePlugins/useTreeViewId/useTreeViewId.selectors.d.ts +8 -34
  86. package/internals/corePlugins/useTreeViewId/useTreeViewId.selectors.js +10 -10
  87. package/internals/index.d.ts +6 -14
  88. package/internals/index.js +12 -73
  89. package/internals/models/plugin.d.ts +2 -3
  90. package/internals/models/treeView.d.ts +4 -6
  91. package/internals/plugins/useTreeViewExpansion/index.d.ts +2 -1
  92. package/internals/plugins/useTreeViewExpansion/index.js +8 -1
  93. package/internals/plugins/useTreeViewExpansion/useTreeViewExpansion.js +24 -28
  94. package/internals/plugins/useTreeViewExpansion/useTreeViewExpansion.selectors.d.ts +24 -316
  95. package/internals/plugins/useTreeViewExpansion/useTreeViewExpansion.selectors.js +27 -38
  96. package/internals/plugins/useTreeViewExpansion/useTreeViewExpansion.types.d.ts +7 -1
  97. package/internals/plugins/useTreeViewFocus/index.d.ts +2 -1
  98. package/internals/plugins/useTreeViewFocus/index.js +8 -1
  99. package/internals/plugins/useTreeViewFocus/useTreeViewFocus.js +14 -18
  100. package/internals/plugins/useTreeViewFocus/useTreeViewFocus.selectors.d.ts +20 -628
  101. package/internals/plugins/useTreeViewFocus/useTreeViewFocus.selectors.js +23 -35
  102. package/internals/plugins/useTreeViewItems/index.d.ts +2 -1
  103. package/internals/plugins/useTreeViewItems/index.js +8 -1
  104. package/internals/plugins/useTreeViewItems/useTreeViewItems.js +77 -98
  105. package/internals/plugins/useTreeViewItems/useTreeViewItems.selectors.d.ts +52 -1142
  106. package/internals/plugins/useTreeViewItems/useTreeViewItems.selectors.js +59 -99
  107. package/internals/plugins/useTreeViewItems/useTreeViewItems.utils.d.ts +1 -1
  108. package/internals/plugins/useTreeViewItems/useTreeViewItems.utils.js +1 -1
  109. package/internals/plugins/useTreeViewJSXItems/useTreeViewJSXItems.js +32 -42
  110. package/internals/plugins/useTreeViewKeyboardNavigation/useTreeViewKeyboardNavigation.js +18 -18
  111. package/internals/plugins/useTreeViewKeyboardNavigation/useTreeViewKeyboardNavigation.types.d.ts +2 -0
  112. package/internals/plugins/useTreeViewLabel/index.d.ts +2 -1
  113. package/internals/plugins/useTreeViewLabel/index.js +8 -1
  114. package/internals/plugins/useTreeViewLabel/useTreeViewLabel.itemPlugin.js +3 -3
  115. package/internals/plugins/useTreeViewLabel/useTreeViewLabel.js +16 -24
  116. package/internals/plugins/useTreeViewLabel/useTreeViewLabel.selectors.d.ts +14 -100
  117. package/internals/plugins/useTreeViewLabel/useTreeViewLabel.selectors.js +24 -34
  118. package/internals/plugins/useTreeViewLazyLoading/index.d.ts +2 -1
  119. package/internals/plugins/useTreeViewLazyLoading/index.js +8 -1
  120. package/internals/plugins/useTreeViewLazyLoading/useTreeViewLazyLoading.selectors.d.ts +18 -245
  121. package/internals/plugins/useTreeViewLazyLoading/useTreeViewLazyLoading.selectors.js +16 -28
  122. package/internals/plugins/useTreeViewLazyLoading/useTreeViewLazyLoading.types.d.ts +20 -6
  123. package/internals/plugins/useTreeViewSelection/index.d.ts +2 -1
  124. package/internals/plugins/useTreeViewSelection/index.js +8 -1
  125. package/internals/plugins/useTreeViewSelection/useTreeViewSelection.itemPlugin.js +23 -37
  126. package/internals/plugins/useTreeViewSelection/useTreeViewSelection.js +29 -33
  127. package/internals/plugins/useTreeViewSelection/useTreeViewSelection.selectors.d.ts +38 -517
  128. package/internals/plugins/useTreeViewSelection/useTreeViewSelection.selectors.js +46 -71
  129. package/internals/plugins/useTreeViewSelection/useTreeViewSelection.types.d.ts +1 -0
  130. package/internals/plugins/useTreeViewSelection/useTreeViewSelection.utils.js +8 -8
  131. package/internals/useTreeView/useTreeView.d.ts +1 -1
  132. package/internals/useTreeView/useTreeView.js +11 -18
  133. package/internals/useTreeView/useTreeView.types.d.ts +1 -1
  134. package/internals/useTreeView/useTreeViewBuildContext.d.ts +2 -3
  135. package/internals/utils/tree.js +31 -31
  136. package/package.json +12 -13
  137. package/useTreeItem/useTreeItem.js +14 -14
  138. package/useTreeItem/useTreeItem.types.d.ts +2 -1
  139. package/esm/internals/hooks/useSelector.d.ts +0 -4
  140. package/esm/internals/hooks/useSelector.js +0 -8
  141. package/esm/internals/utils/TreeViewStore.d.ts +0 -12
  142. package/esm/internals/utils/TreeViewStore.js +0 -22
  143. package/esm/internals/utils/selectors.d.ts +0 -21
  144. package/esm/internals/utils/selectors.js +0 -51
  145. package/internals/hooks/useSelector.d.ts +0 -4
  146. package/internals/hooks/useSelector.js +0 -16
  147. package/internals/utils/TreeViewStore.d.ts +0 -12
  148. package/internals/utils/TreeViewStore.js +0 -29
  149. package/internals/utils/selectors.d.ts +0 -21
  150. package/internals/utils/selectors.js +0 -58
@@ -1,102 +1,16 @@
1
1
  import { UseTreeViewLabelSignature } from "./useTreeViewLabel.types.js";
2
- import { TreeViewRootSelector } from "../../utils/selectors.js";
3
- /**
4
- * Check if an item is editable.
5
- * @param {TreeViewState<[UseTreeViewItemsSignature]>} state The state of the tree view.
6
- * @param {TreeViewItemId} itemId The id of the item to check.
7
- * @returns {boolean} `true` if the item is editable, `false` otherwise.
8
- */
9
- export declare const selectorIsItemEditable: ((state: any, itemId: string) => boolean) & {
10
- clearCache: () => void;
11
- resultsCount: () => number;
12
- resetResultsCount: () => void;
13
- } & {
14
- resultFunc: (resultFuncArgs_0: {
15
- isItemEditable: ((item: any) => boolean) | boolean;
16
- editedItemId: string | null;
17
- } | undefined, resultFuncArgs_1: import("../../../index.js").TreeViewBaseItem<import("../../../index.js").TreeViewDefaultItemModelProperties>) => boolean;
18
- memoizedResultFunc: ((resultFuncArgs_0: {
19
- isItemEditable: ((item: any) => boolean) | boolean;
20
- editedItemId: string | null;
21
- } | undefined, resultFuncArgs_1: import("../../../index.js").TreeViewBaseItem<import("../../../index.js").TreeViewDefaultItemModelProperties>) => boolean) & {
22
- clearCache: () => void;
23
- resultsCount: () => number;
24
- resetResultsCount: () => void;
25
- };
26
- lastResult: () => boolean;
27
- dependencies: [TreeViewRootSelector<UseTreeViewLabelSignature, true>, (state: any, itemId: string) => import("../../../index.js").TreeViewBaseItem<import("../../../index.js").TreeViewDefaultItemModelProperties>];
28
- recomputations: () => number;
29
- resetRecomputations: () => void;
30
- dependencyRecomputations: () => number;
31
- resetDependencyRecomputations: () => void;
32
- } & {
33
- memoize: typeof import("reselect").weakMapMemoize;
34
- argsMemoize: typeof import("reselect").weakMapMemoize;
35
- };
36
- /**
37
- * Check if the given item is being edited.
38
- * @param {TreeViewState<[UseTreeViewLabelSignature]>} state The state of the tree view.
39
- * @param {TreeViewItemId} itemId The id of the item to check.
40
- * @returns {boolean} `true` if the item is being edited, `false` otherwise.
41
- */
42
- export declare const selectorIsItemBeingEdited: ((state: any, itemId: string | null) => boolean) & {
43
- clearCache: () => void;
44
- resultsCount: () => number;
45
- resetResultsCount: () => void;
46
- } & {
47
- resultFunc: (resultFuncArgs_0: {
48
- isItemEditable: ((item: any) => boolean) | boolean;
49
- editedItemId: string | null;
50
- } | undefined, resultFuncArgs_1: string | null) => boolean;
51
- memoizedResultFunc: ((resultFuncArgs_0: {
52
- isItemEditable: ((item: any) => boolean) | boolean;
53
- editedItemId: string | null;
54
- } | undefined, resultFuncArgs_1: string | null) => boolean) & {
55
- clearCache: () => void;
56
- resultsCount: () => number;
57
- resetResultsCount: () => void;
58
- };
59
- lastResult: () => boolean;
60
- dependencies: [TreeViewRootSelector<UseTreeViewLabelSignature, true>, (_: any, itemId: string | null) => string | null];
61
- recomputations: () => number;
62
- resetRecomputations: () => void;
63
- dependencyRecomputations: () => number;
64
- resetDependencyRecomputations: () => void;
65
- } & {
66
- memoize: typeof import("reselect").weakMapMemoize;
67
- argsMemoize: typeof import("reselect").weakMapMemoize;
68
- };
69
- /**
70
- * Check if an item is being edited.
71
- * @param {TreeViewState<[UseTreeViewLabelSignature]>} state The state of the tree view.
72
- * @returns {boolean} `true` if an item is being edited, `false` otherwise.
73
- */
74
- export declare const selectorIsAnyItemBeingEdited: ((state: import("../../corePlugins/useTreeViewId/useTreeViewId.types.js").UseTreeViewIdState & Partial<import("./useTreeViewLabel.types.js").UseTreeViewLabelState> & {
75
- cacheKey: import("../../models/index.js").TreeViewStateCacheKey;
76
- }) => boolean) & {
77
- clearCache: () => void;
78
- resultsCount: () => number;
79
- resetResultsCount: () => void;
80
- } & {
81
- resultFunc: (resultFuncArgs_0: {
82
- isItemEditable: ((item: any) => boolean) | boolean;
83
- editedItemId: string | null;
84
- } | undefined) => boolean;
85
- memoizedResultFunc: ((resultFuncArgs_0: {
86
- isItemEditable: ((item: any) => boolean) | boolean;
87
- editedItemId: string | null;
88
- } | undefined) => boolean) & {
89
- clearCache: () => void;
90
- resultsCount: () => number;
91
- resetResultsCount: () => void;
92
- };
93
- lastResult: () => boolean;
94
- dependencies: [TreeViewRootSelector<UseTreeViewLabelSignature, true>];
95
- recomputations: () => number;
96
- resetRecomputations: () => void;
97
- dependencyRecomputations: () => number;
98
- resetDependencyRecomputations: () => void;
99
- } & {
100
- memoize: typeof import("reselect").weakMapMemoize;
101
- argsMemoize: typeof import("reselect").weakMapMemoize;
2
+ import { TreeViewState } from "../../models/index.js";
3
+ export declare const labelSelectors: {
4
+ /**
5
+ * Checks whether an item is editable.
6
+ */
7
+ isItemEditable: (args_0: import("../../corePlugins/useTreeViewId/useTreeViewId.types.js").UseTreeViewIdState & import("../useTreeViewItems/index.js").UseTreeViewItemsState<import("../../../index.js").TreeViewDefaultItemModelProperties> & Partial<{}>, _itemId: string) => boolean;
8
+ /**
9
+ * Checks whether an item is being edited.
10
+ */
11
+ isItemBeingEdited: (state: TreeViewState<[], [UseTreeViewLabelSignature]>, itemId: string | null) => boolean;
12
+ /**
13
+ * Checks whether any item is being edited.
14
+ */
15
+ isAnyItemBeingEdited: (state: TreeViewState<[], [UseTreeViewLabelSignature]>) => boolean;
102
16
  };
@@ -1,34 +1,24 @@
1
- import { createSelector } from "../../utils/selectors.js";
2
- import { selectorItemModel } from "../useTreeViewItems/useTreeViewItems.selectors.js";
3
- const selectorTreeViewLabelState = state => state.label;
4
-
5
- /**
6
- * Check if an item is editable.
7
- * @param {TreeViewState<[UseTreeViewItemsSignature]>} state The state of the tree view.
8
- * @param {TreeViewItemId} itemId The id of the item to check.
9
- * @returns {boolean} `true` if the item is editable, `false` otherwise.
10
- */
11
- export const selectorIsItemEditable = createSelector([selectorTreeViewLabelState, (state, itemId) => selectorItemModel(state, itemId)], (labelState, itemModel) => {
12
- if (!itemModel || !labelState) {
13
- return false;
14
- }
15
- if (typeof labelState.isItemEditable === 'boolean') {
16
- return labelState.isItemEditable;
17
- }
18
- return labelState.isItemEditable(itemModel);
19
- });
20
-
21
- /**
22
- * Check if the given item is being edited.
23
- * @param {TreeViewState<[UseTreeViewLabelSignature]>} state The state of the tree view.
24
- * @param {TreeViewItemId} itemId The id of the item to check.
25
- * @returns {boolean} `true` if the item is being edited, `false` otherwise.
26
- */
27
- export const selectorIsItemBeingEdited = createSelector([selectorTreeViewLabelState, (_, itemId) => itemId], (labelState, itemId) => itemId ? labelState?.editedItemId === itemId : false);
28
-
29
- /**
30
- * Check if an item is being edited.
31
- * @param {TreeViewState<[UseTreeViewLabelSignature]>} state The state of the tree view.
32
- * @returns {boolean} `true` if an item is being edited, `false` otherwise.
33
- */
34
- export const selectorIsAnyItemBeingEdited = createSelector(selectorTreeViewLabelState, labelState => !!labelState?.editedItemId);
1
+ import { createSelector } from '@mui/x-internals/store';
2
+ import { itemsSelectors } from "../useTreeViewItems/useTreeViewItems.selectors.js";
3
+ export const labelSelectors = {
4
+ /**
5
+ * Checks whether an item is editable.
6
+ */
7
+ isItemEditable: createSelector(state => state.label?.isItemEditable, itemsSelectors.itemModel, (isItemEditable, itemModel, _itemId) => {
8
+ if (!itemModel || isItemEditable == null) {
9
+ return false;
10
+ }
11
+ if (typeof isItemEditable === 'boolean') {
12
+ return isItemEditable;
13
+ }
14
+ return isItemEditable(itemModel);
15
+ }),
16
+ /**
17
+ * Checks whether an item is being edited.
18
+ */
19
+ isItemBeingEdited: createSelector((state, itemId) => itemId == null ? false : state.label?.editedItemId === itemId),
20
+ /**
21
+ * Checks whether any item is being edited.
22
+ */
23
+ isAnyItemBeingEdited: createSelector(state => !!state.label?.editedItemId)
24
+ };
@@ -1 +1,2 @@
1
- export type { UseTreeViewLazyLoadingSignature, UseTreeViewLazyLoadingParameters } from "./useTreeViewLazyLoading.types.js";
1
+ export type { UseTreeViewLazyLoadingSignature, UseTreeViewLazyLoadingParameters, UseTreeViewLazyLoadingInstance } from "./useTreeViewLazyLoading.types.js";
2
+ export { lazyLoadingSelectors } from "./useTreeViewLazyLoading.selectors.js";
@@ -1 +1 @@
1
- export {};
1
+ export { lazyLoadingSelectors } from "./useTreeViewLazyLoading.selectors.js";
@@ -1,247 +1,20 @@
1
- import { TreeViewRootSelector, TreeViewRootSelectorForOptionalPlugin } from "../../utils/selectors.js";
1
+ import { TreeViewItemId } from "../../../models/index.js";
2
2
  import { UseTreeViewLazyLoadingSignature } from "./useTreeViewLazyLoading.types.js";
3
- export declare const selectorDataSourceState: ((state: import("../../corePlugins/useTreeViewId/useTreeViewId.types.js").UseTreeViewIdState & import("./useTreeViewLazyLoading.types.js").UseTreeViewLazyLoadingState & Partial<{}> & {
4
- cacheKey: import("../../models/index.js").TreeViewStateCacheKey;
5
- }) => {
6
- loading: Record<import("../../../index.js").TreeViewItemId, boolean>;
7
- errors: Record<import("../../../index.js").TreeViewItemId, Error | null>;
8
- }) & {
9
- clearCache: () => void;
10
- resultsCount: () => number;
11
- resetResultsCount: () => void;
12
- } & {
13
- resultFunc: (resultFuncArgs_0: {
14
- enabled: boolean;
15
- dataSource: {
16
- loading: Record<import("../../../index.js").TreeViewItemId, boolean>;
17
- errors: Record<import("../../../index.js").TreeViewItemId, Error | null>;
18
- };
19
- }) => {
20
- loading: Record<import("../../../index.js").TreeViewItemId, boolean>;
21
- errors: Record<import("../../../index.js").TreeViewItemId, Error | null>;
22
- };
23
- memoizedResultFunc: ((resultFuncArgs_0: {
24
- enabled: boolean;
25
- dataSource: {
26
- loading: Record<import("../../../index.js").TreeViewItemId, boolean>;
27
- errors: Record<import("../../../index.js").TreeViewItemId, Error | null>;
28
- };
29
- }) => {
30
- loading: Record<import("../../../index.js").TreeViewItemId, boolean>;
31
- errors: Record<import("../../../index.js").TreeViewItemId, Error | null>;
32
- }) & {
33
- clearCache: () => void;
34
- resultsCount: () => number;
35
- resetResultsCount: () => void;
36
- };
37
- lastResult: () => {
38
- loading: Record<import("../../../index.js").TreeViewItemId, boolean>;
39
- errors: Record<import("../../../index.js").TreeViewItemId, Error | null>;
40
- };
41
- dependencies: [TreeViewRootSelector<UseTreeViewLazyLoadingSignature>];
42
- recomputations: () => number;
43
- resetRecomputations: () => void;
44
- dependencyRecomputations: () => number;
45
- resetDependencyRecomputations: () => void;
46
- } & {
47
- memoize: typeof import("reselect").weakMapMemoize;
48
- argsMemoize: typeof import("reselect").weakMapMemoize;
49
- };
50
- /**
51
- * Check if lazy loading is enabled.
52
- * @param {TreeViewState<[UseTreeViewLazyLoadingSignature]>} state The state of the tree view.
53
- * @returns {boolean} True if lazy loading is enabled, false if it isn't.
54
- */
55
- export declare const selectorIsLazyLoadingEnabled: ((state: import("../../corePlugins/useTreeViewId/useTreeViewId.types.js").UseTreeViewIdState & Partial<import("./useTreeViewLazyLoading.types.js").UseTreeViewLazyLoadingState> & {
56
- cacheKey: import("../../models/index.js").TreeViewStateCacheKey;
57
- }) => boolean) & {
58
- clearCache: () => void;
59
- resultsCount: () => number;
60
- resetResultsCount: () => void;
61
- } & {
62
- resultFunc: (resultFuncArgs_0: {
63
- enabled: boolean;
64
- dataSource: {
65
- loading: Record<import("../../../index.js").TreeViewItemId, boolean>;
66
- errors: Record<import("../../../index.js").TreeViewItemId, Error | null>;
67
- };
68
- } | undefined) => boolean;
69
- memoizedResultFunc: ((resultFuncArgs_0: {
70
- enabled: boolean;
71
- dataSource: {
72
- loading: Record<import("../../../index.js").TreeViewItemId, boolean>;
73
- errors: Record<import("../../../index.js").TreeViewItemId, Error | null>;
74
- };
75
- } | undefined) => boolean) & {
76
- clearCache: () => void;
77
- resultsCount: () => number;
78
- resetResultsCount: () => void;
79
- };
80
- lastResult: () => boolean;
81
- dependencies: [TreeViewRootSelectorForOptionalPlugin<UseTreeViewLazyLoadingSignature>];
82
- recomputations: () => number;
83
- resetRecomputations: () => void;
84
- dependencyRecomputations: () => number;
85
- resetDependencyRecomputations: () => void;
86
- } & {
87
- memoize: typeof import("reselect").weakMapMemoize;
88
- argsMemoize: typeof import("reselect").weakMapMemoize;
89
- };
90
- /**
91
- * Get the loading state for a tree item.
92
- * @param {TreeViewState<[UseTreeViewLazyLoadingSignature]>} state The state of the tree view.
93
- * @param {TreeViewItemId} itemId The id of the item to get the loading state of.
94
- * @returns {boolean} The loading state for the Tree Item.
95
- */
96
- export declare const selectorIsItemLoading: ((state: any, itemId: string) => boolean) & {
97
- clearCache: () => void;
98
- resultsCount: () => number;
99
- resetResultsCount: () => void;
100
- } & {
101
- resultFunc: (resultFuncArgs_0: {
102
- loading: Record<import("../../../index.js").TreeViewItemId, boolean>;
103
- errors: Record<import("../../../index.js").TreeViewItemId, Error | null>;
104
- }, resultFuncArgs_1: string) => boolean;
105
- memoizedResultFunc: ((resultFuncArgs_0: {
106
- loading: Record<import("../../../index.js").TreeViewItemId, boolean>;
107
- errors: Record<import("../../../index.js").TreeViewItemId, Error | null>;
108
- }, resultFuncArgs_1: string) => boolean) & {
109
- clearCache: () => void;
110
- resultsCount: () => number;
111
- resetResultsCount: () => void;
112
- };
113
- lastResult: () => boolean;
114
- dependencies: [((state: import("../../corePlugins/useTreeViewId/useTreeViewId.types.js").UseTreeViewIdState & import("./useTreeViewLazyLoading.types.js").UseTreeViewLazyLoadingState & Partial<{}> & {
115
- cacheKey: import("../../models/index.js").TreeViewStateCacheKey;
116
- }) => {
117
- loading: Record<import("../../../index.js").TreeViewItemId, boolean>;
118
- errors: Record<import("../../../index.js").TreeViewItemId, Error | null>;
119
- }) & {
120
- clearCache: () => void;
121
- resultsCount: () => number;
122
- resetResultsCount: () => void;
123
- } & {
124
- resultFunc: (resultFuncArgs_0: {
125
- enabled: boolean;
126
- dataSource: {
127
- loading: Record<import("../../../index.js").TreeViewItemId, boolean>;
128
- errors: Record<import("../../../index.js").TreeViewItemId, Error | null>;
129
- };
130
- }) => {
131
- loading: Record<import("../../../index.js").TreeViewItemId, boolean>;
132
- errors: Record<import("../../../index.js").TreeViewItemId, Error | null>;
133
- };
134
- memoizedResultFunc: ((resultFuncArgs_0: {
135
- enabled: boolean;
136
- dataSource: {
137
- loading: Record<import("../../../index.js").TreeViewItemId, boolean>;
138
- errors: Record<import("../../../index.js").TreeViewItemId, Error | null>;
139
- };
140
- }) => {
141
- loading: Record<import("../../../index.js").TreeViewItemId, boolean>;
142
- errors: Record<import("../../../index.js").TreeViewItemId, Error | null>;
143
- }) & {
144
- clearCache: () => void;
145
- resultsCount: () => number;
146
- resetResultsCount: () => void;
147
- };
148
- lastResult: () => {
149
- loading: Record<import("../../../index.js").TreeViewItemId, boolean>;
150
- errors: Record<import("../../../index.js").TreeViewItemId, Error | null>;
151
- };
152
- dependencies: [TreeViewRootSelector<UseTreeViewLazyLoadingSignature>];
153
- recomputations: () => number;
154
- resetRecomputations: () => void;
155
- dependencyRecomputations: () => number;
156
- resetDependencyRecomputations: () => void;
157
- } & {
158
- memoize: typeof import("reselect").weakMapMemoize;
159
- argsMemoize: typeof import("reselect").weakMapMemoize;
160
- }, (_: any, itemId: string) => string];
161
- recomputations: () => number;
162
- resetRecomputations: () => void;
163
- dependencyRecomputations: () => number;
164
- resetDependencyRecomputations: () => void;
165
- } & {
166
- memoize: typeof import("reselect").weakMapMemoize;
167
- argsMemoize: typeof import("reselect").weakMapMemoize;
168
- };
169
- /**
170
- * Get the error for a tree item.
171
- * @param {TreeViewState<[UseTreeViewLazyLoadingSignature]>} state The state of the tree view.
172
- * @param {TreeViewItemId} itemId The id of the item to get the error for.
173
- * @returns {boolean} The error for the Tree Item.
174
- */
175
- export declare const selectorGetTreeItemError: ((state: any, itemId: string) => Error | null) & {
176
- clearCache: () => void;
177
- resultsCount: () => number;
178
- resetResultsCount: () => void;
179
- } & {
180
- resultFunc: (resultFuncArgs_0: {
181
- loading: Record<import("../../../index.js").TreeViewItemId, boolean>;
182
- errors: Record<import("../../../index.js").TreeViewItemId, Error | null>;
183
- }, resultFuncArgs_1: string) => Error | null;
184
- memoizedResultFunc: ((resultFuncArgs_0: {
185
- loading: Record<import("../../../index.js").TreeViewItemId, boolean>;
186
- errors: Record<import("../../../index.js").TreeViewItemId, Error | null>;
187
- }, resultFuncArgs_1: string) => Error | null) & {
188
- clearCache: () => void;
189
- resultsCount: () => number;
190
- resetResultsCount: () => void;
191
- };
192
- lastResult: () => Error | null;
193
- dependencies: [((state: import("../../corePlugins/useTreeViewId/useTreeViewId.types.js").UseTreeViewIdState & import("./useTreeViewLazyLoading.types.js").UseTreeViewLazyLoadingState & Partial<{}> & {
194
- cacheKey: import("../../models/index.js").TreeViewStateCacheKey;
195
- }) => {
196
- loading: Record<import("../../../index.js").TreeViewItemId, boolean>;
197
- errors: Record<import("../../../index.js").TreeViewItemId, Error | null>;
198
- }) & {
199
- clearCache: () => void;
200
- resultsCount: () => number;
201
- resetResultsCount: () => void;
202
- } & {
203
- resultFunc: (resultFuncArgs_0: {
204
- enabled: boolean;
205
- dataSource: {
206
- loading: Record<import("../../../index.js").TreeViewItemId, boolean>;
207
- errors: Record<import("../../../index.js").TreeViewItemId, Error | null>;
208
- };
209
- }) => {
210
- loading: Record<import("../../../index.js").TreeViewItemId, boolean>;
211
- errors: Record<import("../../../index.js").TreeViewItemId, Error | null>;
212
- };
213
- memoizedResultFunc: ((resultFuncArgs_0: {
214
- enabled: boolean;
215
- dataSource: {
216
- loading: Record<import("../../../index.js").TreeViewItemId, boolean>;
217
- errors: Record<import("../../../index.js").TreeViewItemId, Error | null>;
218
- };
219
- }) => {
220
- loading: Record<import("../../../index.js").TreeViewItemId, boolean>;
221
- errors: Record<import("../../../index.js").TreeViewItemId, Error | null>;
222
- }) & {
223
- clearCache: () => void;
224
- resultsCount: () => number;
225
- resetResultsCount: () => void;
226
- };
227
- lastResult: () => {
228
- loading: Record<import("../../../index.js").TreeViewItemId, boolean>;
229
- errors: Record<import("../../../index.js").TreeViewItemId, Error | null>;
230
- };
231
- dependencies: [TreeViewRootSelector<UseTreeViewLazyLoadingSignature>];
232
- recomputations: () => number;
233
- resetRecomputations: () => void;
234
- dependencyRecomputations: () => number;
235
- resetDependencyRecomputations: () => void;
236
- } & {
237
- memoize: typeof import("reselect").weakMapMemoize;
238
- argsMemoize: typeof import("reselect").weakMapMemoize;
239
- }, (_: any, itemId: string) => string];
240
- recomputations: () => number;
241
- resetRecomputations: () => void;
242
- dependencyRecomputations: () => number;
243
- resetDependencyRecomputations: () => void;
244
- } & {
245
- memoize: typeof import("reselect").weakMapMemoize;
246
- argsMemoize: typeof import("reselect").weakMapMemoize;
3
+ import { TreeViewState } from "../../models/index.js";
4
+ export declare const lazyLoadingSelectors: {
5
+ /**
6
+ * Gets the data source used to lazy load items.
7
+ */
8
+ dataSource: (state: TreeViewState<[], [UseTreeViewLazyLoadingSignature]>) => {
9
+ loading: Record<TreeViewItemId, boolean>;
10
+ errors: Record<TreeViewItemId, Error | null>;
11
+ } | undefined;
12
+ /**
13
+ * Checks whether an item is loading.
14
+ */
15
+ isItemLoading: (state: TreeViewState<[], [UseTreeViewLazyLoadingSignature]>, itemId: string) => boolean;
16
+ /**
17
+ * Checks whether an item has errors.
18
+ */
19
+ itemHasError: (state: TreeViewState<[], [UseTreeViewLazyLoadingSignature]>, itemId: string) => boolean;
247
20
  };
@@ -1,27 +1,15 @@
1
- import { createSelector } from "../../utils/selectors.js";
2
- const selectorLazyLoading = state => state.lazyLoading;
3
- const selectorLazyLoadingOptional = state => state.lazyLoading;
4
- export const selectorDataSourceState = createSelector([selectorLazyLoading], lazyLoading => lazyLoading.dataSource);
5
-
6
- /**
7
- * Check if lazy loading is enabled.
8
- * @param {TreeViewState<[UseTreeViewLazyLoadingSignature]>} state The state of the tree view.
9
- * @returns {boolean} True if lazy loading is enabled, false if it isn't.
10
- */
11
- export const selectorIsLazyLoadingEnabled = createSelector([selectorLazyLoadingOptional], lazyLoading => !!lazyLoading?.enabled);
12
-
13
- /**
14
- * Get the loading state for a tree item.
15
- * @param {TreeViewState<[UseTreeViewLazyLoadingSignature]>} state The state of the tree view.
16
- * @param {TreeViewItemId} itemId The id of the item to get the loading state of.
17
- * @returns {boolean} The loading state for the Tree Item.
18
- */
19
- export const selectorIsItemLoading = createSelector([selectorDataSourceState, (_, itemId) => itemId], (dataSourceState, itemId) => dataSourceState.loading[itemId] || false);
20
-
21
- /**
22
- * Get the error for a tree item.
23
- * @param {TreeViewState<[UseTreeViewLazyLoadingSignature]>} state The state of the tree view.
24
- * @param {TreeViewItemId} itemId The id of the item to get the error for.
25
- * @returns {boolean} The error for the Tree Item.
26
- */
27
- export const selectorGetTreeItemError = createSelector([selectorDataSourceState, (_, itemId) => itemId], (dataSourceState, itemId) => dataSourceState.errors[itemId] || null);
1
+ import { createSelector } from '@mui/x-internals/store';
2
+ export const lazyLoadingSelectors = {
3
+ /**
4
+ * Gets the data source used to lazy load items.
5
+ */
6
+ dataSource: createSelector(state => state.lazyLoading?.dataSource),
7
+ /**
8
+ * Checks whether an item is loading.
9
+ */
10
+ isItemLoading: createSelector((state, itemId) => state.lazyLoading?.dataSource.loading[itemId] ?? false),
11
+ /**
12
+ * Checks whether an item has errors.
13
+ */
14
+ itemHasError: createSelector((state, itemId) => !!state.lazyLoading?.dataSource.errors[itemId])
15
+ };
@@ -25,24 +25,38 @@ type DataSource<R extends {}> = {
25
25
  */
26
26
  getTreeItems: (parentId?: TreeViewItemId) => Promise<R[]>;
27
27
  };
28
- export interface UseTreeViewLazyLoadingPublicAPI {}
28
+ export interface UseTreeViewLazyLoadingPublicAPI {
29
+ /**
30
+ * Method used for updating an item's children.
31
+ * Only relevant for lazy-loaded tree views.
32
+ *
33
+ * @param {TreeViewItemId} itemId The The id of the item to update the children of.
34
+ * @returns {Promise<void>} The promise resolved when the items are fetched.
35
+ */
36
+ updateItemChildren: (itemId: TreeViewItemId) => Promise<void>;
37
+ }
29
38
  export interface UseTreeViewLazyLoadingInstance extends UseTreeViewLazyLoadingPublicAPI {
30
39
  /**
31
40
  * Method used for fetching multiple items concurrently.
32
41
  * Only relevant for lazy-loaded tree views.
33
42
  *
34
43
  * @param {TreeViewItemId[]} parentIds The ids of the items to fetch the children of.
35
- * @returns { Promise<void>} The children of the items.
44
+ * @returns {Promise<void>} The promise resolved when the items are fetched.
36
45
  */
37
46
  fetchItems: (parentIds?: TreeViewItemId[]) => Promise<void>;
38
47
  /**
39
- * Method used for fetching and item's children.
48
+ * Method used for fetching an item's children.
40
49
  * Only relevant for lazy-loaded tree views.
41
50
  *
42
- * @param {TreeViewItemId} itemId The The id of the item to fetch the children of.
43
- * @returns { Promise<void>} The children of the item.
51
+ * @param {object} parameters The parameters of the method.
52
+ * @param {TreeViewItemId} parameters.itemId The The id of the item to fetch the children of.
53
+ * @param {boolean} [parameters.forceRefresh] Whether to force a refresh of the children when the cache already contains some data.
54
+ * @returns {Promise<void>} The promise resolved when the items are fetched.
44
55
  */
45
- fetchItemChildren: (itemId: TreeViewItemId) => Promise<void>;
56
+ fetchItemChildren: (parameters: {
57
+ itemId: TreeViewItemId;
58
+ forceRefresh?: boolean;
59
+ }) => Promise<void>;
46
60
  /**
47
61
  * Set the loading state of an item.
48
62
  * @param {TreeViewItemId} itemId The id of the item to set the loading state of.
@@ -1,2 +1,3 @@
1
1
  export { useTreeViewSelection } from "./useTreeViewSelection.js";
2
- export type { UseTreeViewSelectionSignature, UseTreeViewSelectionParameters, UseTreeViewSelectionParametersWithDefaults } from "./useTreeViewSelection.types.js";
2
+ export type { UseTreeViewSelectionSignature, UseTreeViewSelectionParameters, UseTreeViewSelectionParametersWithDefaults } from "./useTreeViewSelection.types.js";
3
+ export { selectionSelectors } from "./useTreeViewSelection.selectors.js";
@@ -1 +1,2 @@
1
- export { useTreeViewSelection } from "./useTreeViewSelection.js";
1
+ export { useTreeViewSelection } from "./useTreeViewSelection.js";
2
+ export { selectionSelectors } from "./useTreeViewSelection.selectors.js";
@@ -1,49 +1,30 @@
1
- import _extends from "@babel/runtime/helpers/esm/extends";
2
- import { fastObjectShallowCompare } from '@mui/x-internals/fastObjectShallowCompare';
1
+ import { createSelector, useStore } from '@mui/x-internals/store';
3
2
  import { useTreeViewContext } from "../../TreeViewProvider/index.js";
4
- import { selectorItemOrderedChildrenIds } from "../useTreeViewItems/useTreeViewItems.selectors.js";
5
- import { selectorIsCheckboxSelectionEnabled, selectorIsItemSelected, selectorIsItemSelectionEnabled, selectorSelectionPropagationRules } from "./useTreeViewSelection.selectors.js";
6
- import { useSelector } from "../../hooks/useSelector.js";
7
- function selectorItemCheckboxStatus(state, itemId) {
8
- const isCheckboxSelectionEnabled = selectorIsCheckboxSelectionEnabled(state);
9
- const isSelectionEnabledForItem = selectorIsItemSelectionEnabled(state, itemId);
10
- if (selectorIsItemSelected(state, itemId)) {
11
- return {
12
- disabled: !isSelectionEnabledForItem,
13
- visible: isCheckboxSelectionEnabled,
14
- indeterminate: false,
15
- checked: true
16
- };
17
- }
18
- const children = selectorItemOrderedChildrenIds(state, itemId);
19
- if (children.length === 0) {
20
- return {
21
- disabled: !isSelectionEnabledForItem,
22
- visible: isCheckboxSelectionEnabled,
23
- indeterminate: false,
24
- checked: false
25
- };
3
+ import { itemsSelectors } from "../useTreeViewItems/useTreeViewItems.selectors.js";
4
+ import { selectionSelectors } from "./useTreeViewSelection.selectors.js";
5
+ const selectorCheckboxSelectionStatus = createSelector((state, itemId) => {
6
+ if (selectionSelectors.isItemSelected(state, itemId)) {
7
+ return 'checked';
26
8
  }
27
9
  let hasSelectedDescendant = false;
28
10
  let hasUnSelectedDescendant = false;
29
11
  const traverseDescendants = itemToTraverseId => {
30
12
  if (itemToTraverseId !== itemId) {
31
- if (selectorIsItemSelected(state, itemToTraverseId)) {
13
+ if (selectionSelectors.isItemSelected(state, itemToTraverseId)) {
32
14
  hasSelectedDescendant = true;
33
15
  } else {
34
16
  hasUnSelectedDescendant = true;
35
17
  }
36
18
  }
37
- selectorItemOrderedChildrenIds(state, itemToTraverseId).forEach(traverseDescendants);
19
+ itemsSelectors.itemOrderedChildrenIds(state, itemToTraverseId).forEach(traverseDescendants);
38
20
  };
39
21
  traverseDescendants(itemId);
40
- return {
41
- disabled: !isSelectionEnabledForItem,
42
- visible: isCheckboxSelectionEnabled,
43
- indeterminate: hasSelectedDescendant && hasUnSelectedDescendant,
44
- checked: selectorSelectionPropagationRules(state).parents ? hasSelectedDescendant && !hasUnSelectedDescendant : false
45
- };
46
- }
22
+ if (hasSelectedDescendant && hasUnSelectedDescendant) {
23
+ return 'indeterminate';
24
+ }
25
+ const shouldSelectBasedOnDescendants = selectionSelectors.propagationRules(state).parents;
26
+ return shouldSelectBasedOnDescendants && hasSelectedDescendant && !hasUnSelectedDescendant ? 'checked' : 'empty';
27
+ });
47
28
  export const useTreeViewSelectionItemPlugin = ({
48
29
  props
49
30
  }) => {
@@ -53,7 +34,9 @@ export const useTreeViewSelectionItemPlugin = ({
53
34
  const {
54
35
  store
55
36
  } = useTreeViewContext();
56
- const checkboxStatus = useSelector(store, selectorItemCheckboxStatus, itemId, fastObjectShallowCompare);
37
+ const isCheckboxSelectionEnabled = useStore(store, selectionSelectors.isCheckboxSelectionEnabled);
38
+ const isItemSelectionEnabled = useStore(store, selectionSelectors.canItemBeSelected, itemId);
39
+ const checkboxSelectionStatus = useStore(store, selectorCheckboxSelectionStatus, itemId);
57
40
  return {
58
41
  propsEnhancers: {
59
42
  checkbox: ({
@@ -65,15 +48,19 @@ export const useTreeViewSelectionItemPlugin = ({
65
48
  if (event.defaultMuiPrevented) {
66
49
  return;
67
50
  }
68
- if (!selectorIsItemSelectionEnabled(store.value, itemId)) {
51
+ if (!selectionSelectors.canItemBeSelected(store.state, itemId)) {
69
52
  return;
70
53
  }
71
54
  interactions.handleCheckboxSelection(event);
72
55
  };
73
- return _extends({
56
+ return {
74
57
  tabIndex: -1,
75
- onChange: handleChange
76
- }, checkboxStatus);
58
+ onChange: handleChange,
59
+ visible: isCheckboxSelectionEnabled,
60
+ disabled: !isItemSelectionEnabled,
61
+ checked: checkboxSelectionStatus === 'checked',
62
+ indeterminate: checkboxSelectionStatus === 'indeterminate'
63
+ };
77
64
  }
78
65
  }
79
66
  };