@mui/x-tree-view 7.10.0 → 7.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 (48) hide show
  1. package/CHANGELOG.md +169 -0
  2. package/RichTreeView/RichTreeView.js +2 -3
  3. package/SimpleTreeView/SimpleTreeView.js +2 -3
  4. package/TreeItem2/TreeItem2.d.ts +1 -1
  5. package/index.js +1 -1
  6. package/internals/corePlugins/useTreeViewInstanceEvents/useTreeViewInstanceEvents.js +1 -1
  7. package/internals/index.d.ts +1 -1
  8. package/internals/index.js +1 -1
  9. package/internals/models/index.d.ts +1 -0
  10. package/internals/models/index.js +1 -0
  11. package/internals/models/itemPlugin.d.ts +36 -0
  12. package/internals/models/itemPlugin.js +1 -0
  13. package/internals/models/plugin.d.ts +1 -14
  14. package/internals/useTreeView/useTreeView.js +7 -62
  15. package/internals/useTreeView/useTreeViewBuildContext.d.ts +10 -0
  16. package/internals/useTreeView/useTreeViewBuildContext.js +95 -0
  17. package/internals/useTreeView/useTreeViewPlugins.d.ts +0 -0
  18. package/internals/useTreeView/useTreeViewPlugins.js +0 -0
  19. package/internals/utils/warning.d.ts +2 -1
  20. package/internals/utils/warning.js +19 -12
  21. package/modern/RichTreeView/RichTreeView.js +2 -3
  22. package/modern/SimpleTreeView/SimpleTreeView.js +2 -3
  23. package/modern/index.js +1 -1
  24. package/modern/internals/corePlugins/useTreeViewInstanceEvents/useTreeViewInstanceEvents.js +1 -1
  25. package/modern/internals/index.js +1 -1
  26. package/modern/internals/models/index.js +1 -0
  27. package/modern/internals/models/itemPlugin.js +1 -0
  28. package/modern/internals/useTreeView/useTreeView.js +7 -62
  29. package/modern/internals/useTreeView/useTreeViewBuildContext.js +95 -0
  30. package/modern/internals/useTreeView/useTreeViewPlugins.js +0 -0
  31. package/modern/internals/utils/warning.js +19 -12
  32. package/node/RichTreeView/RichTreeView.js +1 -2
  33. package/node/SimpleTreeView/SimpleTreeView.js +1 -2
  34. package/node/index.js +1 -1
  35. package/node/internals/corePlugins/useTreeViewInstanceEvents/useTreeViewInstanceEvents.js +1 -1
  36. package/node/internals/index.js +6 -6
  37. package/node/internals/models/index.js +11 -0
  38. package/node/internals/models/itemPlugin.js +5 -0
  39. package/node/internals/useTreeView/useTreeView.js +7 -62
  40. package/node/internals/useTreeView/useTreeViewBuildContext.js +102 -0
  41. package/node/internals/useTreeView/useTreeViewPlugins.js +1 -0
  42. package/node/internals/utils/warning.js +21 -14
  43. package/package.json +6 -5
  44. package/useTreeItem2/index.d.ts +1 -1
  45. package/internals/utils/EventManager.d.ts +0 -29
  46. package/internals/utils/EventManager.js +0 -69
  47. package/modern/internals/utils/EventManager.js +0 -69
  48. package/node/internals/utils/EventManager.js +0 -76
@@ -8,7 +8,7 @@ import { getSimpleTreeViewUtilityClass } from './simpleTreeViewClasses';
8
8
  import { useTreeView } from '../internals/useTreeView';
9
9
  import { TreeViewProvider } from '../internals/TreeViewProvider';
10
10
  import { SIMPLE_TREE_VIEW_PLUGINS } from './SimpleTreeView.plugins';
11
- import { buildWarning } from '../internals/utils/warning';
11
+ import { warnOnce } from '../internals/utils/warning';
12
12
  import { jsx as _jsx } from "react/jsx-runtime";
13
13
  const useThemeProps = createUseThemeProps('MuiSimpleTreeView');
14
14
  const useUtilityClasses = ownerState => {
@@ -32,7 +32,6 @@ export const SimpleTreeViewRoot = styled('ul', {
32
32
  position: 'relative'
33
33
  });
34
34
  const EMPTY_ITEMS = [];
35
- const itemsPropWarning = buildWarning(['MUI X: The `SimpleTreeView` component does not support the `items` prop.', 'If you want to add items, you need to pass them as JSX children.', 'Check the documentation for more details: https://mui.com/x/react-tree-view/simple-tree-view/items/']);
36
35
 
37
36
  /**
38
37
  *
@@ -52,7 +51,7 @@ const SimpleTreeView = /*#__PURE__*/React.forwardRef(function SimpleTreeView(inP
52
51
  const ownerState = props;
53
52
  if (process.env.NODE_ENV !== 'production') {
54
53
  if (props.items != null) {
55
- itemsPropWarning();
54
+ warnOnce(['MUI X: The `SimpleTreeView` component does not support the `items` prop.', 'If you want to add items, you need to pass them as JSX children.', 'Check the documentation for more details: https://mui.com/x/react-tree-view/simple-tree-view/items/.']);
56
55
  }
57
56
  }
58
57
  const {
package/modern/index.js CHANGED
@@ -1,5 +1,5 @@
1
1
  /**
2
- * @mui/x-tree-view v7.10.0
2
+ * @mui/x-tree-view v7.11.1
3
3
  *
4
4
  * @license MIT
5
5
  * This source code is licensed under the MIT license found in the
@@ -1,5 +1,5 @@
1
1
  import * as React from 'react';
2
- import { EventManager } from '../../utils/EventManager';
2
+ import { EventManager } from '@mui/x-internals/EventManager';
3
3
  const isSyntheticEvent = event => {
4
4
  return event.isPropagationStopped !== undefined;
5
5
  };
@@ -12,4 +12,4 @@ export { useTreeViewKeyboardNavigation } from './plugins/useTreeViewKeyboardNavi
12
12
  export { useTreeViewIcons } from './plugins/useTreeViewIcons';
13
13
  export { useTreeViewItems } from './plugins/useTreeViewItems';
14
14
  export { useTreeViewJSXItems } from './plugins/useTreeViewJSXItems';
15
- export { buildWarning } from './utils/warning';
15
+ export { warnOnce } from './utils/warning';
@@ -1,3 +1,4 @@
1
1
  export * from './helpers';
2
2
  export * from './plugin';
3
+ export * from './itemPlugin';
3
4
  export * from './treeView';
@@ -0,0 +1 @@
1
+ export {};
@@ -4,6 +4,7 @@ import useForkRef from '@mui/utils/useForkRef';
4
4
  import { useTreeViewModels } from './useTreeViewModels';
5
5
  import { TREE_VIEW_CORE_PLUGINS } from '../corePlugins';
6
6
  import { extractPluginParamsFromProps } from './extractPluginParamsFromProps';
7
+ import { useTreeViewBuildContext } from './useTreeViewBuildContext';
7
8
  export function useTreeViewApiInitialization(inputApiRef) {
8
9
  const fallbackPublicApiRef = React.useRef({});
9
10
  if (inputApiRef) {
@@ -37,6 +38,12 @@ export const useTreeView = ({
37
38
  const publicAPI = useTreeViewApiInitialization(apiRef);
38
39
  const innerRootRef = React.useRef(null);
39
40
  const handleRootRef = useForkRef(innerRootRef, rootRef);
41
+ const contextValue = useTreeViewBuildContext({
42
+ plugins,
43
+ instance,
44
+ publicAPI,
45
+ rootRef: innerRootRef
46
+ });
40
47
  const [state, setState] = React.useState(() => {
41
48
  const temp = {};
42
49
  plugins.forEach(plugin => {
@@ -46,68 +53,6 @@ export const useTreeView = ({
46
53
  });
47
54
  return temp;
48
55
  });
49
- const itemWrappers = plugins.map(plugin => plugin.wrapItem).filter(wrapItem => !!wrapItem);
50
- const wrapItem = ({
51
- itemId,
52
- children
53
- }) => {
54
- let finalChildren = children;
55
- itemWrappers.forEach(itemWrapper => {
56
- finalChildren = itemWrapper({
57
- itemId,
58
- children: finalChildren,
59
- instance
60
- });
61
- });
62
- return finalChildren;
63
- };
64
- const rootWrappers = plugins.map(plugin => plugin.wrapRoot).filter(wrapRoot => !!wrapRoot)
65
- // The wrappers are reversed to ensure that the first wrapper is the outermost one.
66
- .reverse();
67
- const wrapRoot = ({
68
- children
69
- }) => {
70
- let finalChildren = children;
71
- rootWrappers.forEach(rootWrapper => {
72
- finalChildren = rootWrapper({
73
- children: finalChildren,
74
- instance
75
- });
76
- });
77
- return finalChildren;
78
- };
79
- const runItemPlugins = itemPluginProps => {
80
- let finalRootRef = null;
81
- let finalContentRef = null;
82
- plugins.forEach(plugin => {
83
- if (!plugin.itemPlugin) {
84
- return;
85
- }
86
- const itemPluginResponse = plugin.itemPlugin({
87
- props: itemPluginProps,
88
- rootRef: finalRootRef,
89
- contentRef: finalContentRef
90
- });
91
- if (itemPluginResponse?.rootRef) {
92
- finalRootRef = itemPluginResponse.rootRef;
93
- }
94
- if (itemPluginResponse?.contentRef) {
95
- finalContentRef = itemPluginResponse.contentRef;
96
- }
97
- });
98
- return {
99
- contentRef: finalContentRef,
100
- rootRef: finalRootRef
101
- };
102
- };
103
- const contextValue = {
104
- publicAPI,
105
- wrapItem,
106
- wrapRoot,
107
- runItemPlugins,
108
- instance: instance,
109
- rootRef: innerRootRef
110
- };
111
56
  const rootPropsGetters = [];
112
57
  const runPlugin = plugin => {
113
58
  const pluginResponse = plugin({
@@ -0,0 +1,95 @@
1
+ export const useTreeViewBuildContext = ({
2
+ plugins,
3
+ instance,
4
+ publicAPI,
5
+ rootRef
6
+ }) => {
7
+ const runItemPlugins = itemPluginProps => {
8
+ let finalRootRef = null;
9
+ let finalContentRef = null;
10
+ const pluginPropEnhancers = [];
11
+ const pluginPropEnhancersNames = {};
12
+ plugins.forEach(plugin => {
13
+ if (!plugin.itemPlugin) {
14
+ return;
15
+ }
16
+ const itemPluginResponse = plugin.itemPlugin({
17
+ props: itemPluginProps,
18
+ rootRef: finalRootRef,
19
+ contentRef: finalContentRef
20
+ });
21
+ if (itemPluginResponse?.rootRef) {
22
+ finalRootRef = itemPluginResponse.rootRef;
23
+ }
24
+ if (itemPluginResponse?.contentRef) {
25
+ finalContentRef = itemPluginResponse.contentRef;
26
+ }
27
+ if (itemPluginResponse?.propsEnhancers) {
28
+ pluginPropEnhancers.push(itemPluginResponse.propsEnhancers);
29
+
30
+ // Prepare a list of all the slots which are enhanced by at least one plugin
31
+ Object.keys(itemPluginResponse.propsEnhancers).forEach(propsEnhancerName => {
32
+ pluginPropEnhancersNames[propsEnhancerName] = true;
33
+ });
34
+ }
35
+ });
36
+ const resolvePropsEnhancer = currentSlotName => currentSlotParams => {
37
+ const enhancedProps = {};
38
+ pluginPropEnhancers.forEach(propsEnhancersForCurrentPlugin => {
39
+ const propsEnhancerForCurrentPluginAndSlot = propsEnhancersForCurrentPlugin[currentSlotName];
40
+ if (propsEnhancerForCurrentPluginAndSlot != null) {
41
+ Object.assign(enhancedProps, propsEnhancerForCurrentPluginAndSlot(currentSlotParams));
42
+ }
43
+ });
44
+ return enhancedProps;
45
+ };
46
+ const propsEnhancers = Object.fromEntries(Object.keys(pluginPropEnhancersNames).map(propEnhancerName => [propEnhancerName, resolvePropsEnhancer(propEnhancerName)]));
47
+ return {
48
+ contentRef: finalContentRef,
49
+ rootRef: finalRootRef,
50
+ propsEnhancers
51
+ };
52
+ };
53
+ const wrapItem = ({
54
+ itemId,
55
+ children
56
+ }) => {
57
+ let finalChildren = children;
58
+ // The wrappers are reversed to ensure that the first wrapper is the outermost one.
59
+ for (let i = plugins.length - 1; i >= 0; i -= 1) {
60
+ const plugin = plugins[i];
61
+ if (plugin.wrapItem) {
62
+ finalChildren = plugin.wrapItem({
63
+ itemId,
64
+ children: finalChildren,
65
+ instance
66
+ });
67
+ }
68
+ }
69
+ return finalChildren;
70
+ };
71
+ const wrapRoot = ({
72
+ children
73
+ }) => {
74
+ let finalChildren = children;
75
+ // The wrappers are reversed to ensure that the first wrapper is the outermost one.
76
+ for (let i = plugins.length - 1; i >= 0; i -= 1) {
77
+ const plugin = plugins[i];
78
+ if (plugin.wrapRoot) {
79
+ finalChildren = plugin.wrapRoot({
80
+ children: finalChildren,
81
+ instance
82
+ });
83
+ }
84
+ }
85
+ return finalChildren;
86
+ };
87
+ return {
88
+ runItemPlugins,
89
+ wrapItem,
90
+ wrapRoot,
91
+ instance,
92
+ rootRef,
93
+ publicAPI
94
+ };
95
+ };
@@ -1,14 +1,21 @@
1
- export const buildWarning = (message, gravity = 'warning') => {
2
- let alreadyWarned = false;
1
+ const warnedOnceCache = new Set();
2
+
3
+ // TODO move to @mui/x-internals
4
+ // TODO eventually move to @base_ui/internals. Base UI, etc. too need this helper.
5
+ export function warnOnce(message, gravity = 'warning') {
6
+ if (process.env.NODE_ENV === 'production') {
7
+ return;
8
+ }
3
9
  const cleanMessage = Array.isArray(message) ? message.join('\n') : message;
4
- return () => {
5
- if (!alreadyWarned) {
6
- alreadyWarned = true;
7
- if (gravity === 'error') {
8
- console.error(cleanMessage);
9
- } else {
10
- console.warn(cleanMessage);
11
- }
10
+ if (!warnedOnceCache.has(cleanMessage)) {
11
+ warnedOnceCache.add(cleanMessage);
12
+ if (gravity === 'error') {
13
+ console.error(cleanMessage);
14
+ } else {
15
+ console.warn(cleanMessage);
12
16
  }
13
- };
14
- };
17
+ }
18
+ }
19
+ export function clearWarningsCache() {
20
+ warnedOnceCache.clear();
21
+ }
@@ -67,7 +67,6 @@ function WrappedTreeItem({
67
67
  children: children
68
68
  }));
69
69
  }
70
- const childrenWarning = (0, _warning.buildWarning)(['MUI X: The `RichTreeView` component does not support JSX children.', 'If you want to add items, you need to use the `items` prop', 'Check the documentation for more details: https://mui.com/x/react-tree-view/rich-tree-view/items/']);
71
70
 
72
71
  /**
73
72
  *
@@ -86,7 +85,7 @@ const RichTreeView = exports.RichTreeView = /*#__PURE__*/React.forwardRef(functi
86
85
  });
87
86
  if (process.env.NODE_ENV !== 'production') {
88
87
  if (props.children != null) {
89
- childrenWarning();
88
+ (0, _warning.warnOnce)(['MUI X: The `RichTreeView` component does not support JSX children.', 'If you want to add items, you need to use the `items` prop.', 'Check the documentation for more details: https://mui.com/x/react-tree-view/rich-tree-view/items/.']);
90
89
  }
91
90
  }
92
91
  const {
@@ -41,7 +41,6 @@ const SimpleTreeViewRoot = exports.SimpleTreeViewRoot = (0, _zeroStyled.styled)(
41
41
  position: 'relative'
42
42
  });
43
43
  const EMPTY_ITEMS = [];
44
- const itemsPropWarning = (0, _warning.buildWarning)(['MUI X: The `SimpleTreeView` component does not support the `items` prop.', 'If you want to add items, you need to pass them as JSX children.', 'Check the documentation for more details: https://mui.com/x/react-tree-view/simple-tree-view/items/']);
45
44
 
46
45
  /**
47
46
  *
@@ -61,7 +60,7 @@ const SimpleTreeView = exports.SimpleTreeView = /*#__PURE__*/React.forwardRef(fu
61
60
  const ownerState = props;
62
61
  if (process.env.NODE_ENV !== 'production') {
63
62
  if (props.items != null) {
64
- itemsPropWarning();
63
+ (0, _warning.warnOnce)(['MUI X: The `SimpleTreeView` component does not support the `items` prop.', 'If you want to add items, you need to pass them as JSX children.', 'Check the documentation for more details: https://mui.com/x/react-tree-view/simple-tree-view/items/.']);
65
64
  }
66
65
  }
67
66
  const {
package/node/index.js CHANGED
@@ -1,5 +1,5 @@
1
1
  /**
2
- * @mui/x-tree-view v7.10.0
2
+ * @mui/x-tree-view v7.11.1
3
3
  *
4
4
  * @license MIT
5
5
  * This source code is licensed under the MIT license found in the
@@ -5,7 +5,7 @@ Object.defineProperty(exports, "__esModule", {
5
5
  });
6
6
  exports.useTreeViewInstanceEvents = void 0;
7
7
  var React = _interopRequireWildcard(require("react"));
8
- var _EventManager = require("../../utils/EventManager");
8
+ var _EventManager = require("@mui/x-internals/EventManager");
9
9
  function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return null; var r = new WeakMap(), t = new WeakMap(); return (_getRequireWildcardCache = function (e) { return e ? t : r; })(e); }
10
10
  function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" != typeof e && "function" != typeof e) return { default: e }; var t = _getRequireWildcardCache(r); if (t && t.has(e)) return t.get(e); var n = { __proto__: null }, a = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var u in e) if ("default" !== u && {}.hasOwnProperty.call(e, u)) { var i = a ? Object.getOwnPropertyDescriptor(e, u) : null; i && (i.get || i.set) ? Object.defineProperty(n, u, i) : n[u] = e[u]; } return n.default = e, t && t.set(e, n), n; }
11
11
  const isSyntheticEvent = event => {
@@ -9,12 +9,6 @@ Object.defineProperty(exports, "TreeViewProvider", {
9
9
  return _TreeViewProvider.TreeViewProvider;
10
10
  }
11
11
  });
12
- Object.defineProperty(exports, "buildWarning", {
13
- enumerable: true,
14
- get: function () {
15
- return _warning.buildWarning;
16
- }
17
- });
18
12
  Object.defineProperty(exports, "unstable_resetCleanupTracking", {
19
13
  enumerable: true,
20
14
  get: function () {
@@ -69,6 +63,12 @@ Object.defineProperty(exports, "useTreeViewSelection", {
69
63
  return _useTreeViewSelection.useTreeViewSelection;
70
64
  }
71
65
  });
66
+ Object.defineProperty(exports, "warnOnce", {
67
+ enumerable: true,
68
+ get: function () {
69
+ return _warning.warnOnce;
70
+ }
71
+ });
72
72
  var _useTreeView = require("./useTreeView");
73
73
  var _TreeViewProvider = require("./TreeViewProvider");
74
74
  var _useInstanceEventHandler = require("./hooks/useInstanceEventHandler");
@@ -25,6 +25,17 @@ Object.keys(_plugin).forEach(function (key) {
25
25
  }
26
26
  });
27
27
  });
28
+ var _itemPlugin = require("./itemPlugin");
29
+ Object.keys(_itemPlugin).forEach(function (key) {
30
+ if (key === "default" || key === "__esModule") return;
31
+ if (key in exports && exports[key] === _itemPlugin[key]) return;
32
+ Object.defineProperty(exports, key, {
33
+ enumerable: true,
34
+ get: function () {
35
+ return _itemPlugin[key];
36
+ }
37
+ });
38
+ });
28
39
  var _treeView = require("./treeView");
29
40
  Object.keys(_treeView).forEach(function (key) {
30
41
  if (key === "default" || key === "__esModule") return;
@@ -0,0 +1,5 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
@@ -12,6 +12,7 @@ var _useForkRef = _interopRequireDefault(require("@mui/utils/useForkRef"));
12
12
  var _useTreeViewModels = require("./useTreeViewModels");
13
13
  var _corePlugins = require("../corePlugins");
14
14
  var _extractPluginParamsFromProps = require("./extractPluginParamsFromProps");
15
+ var _useTreeViewBuildContext = require("./useTreeViewBuildContext");
15
16
  function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return null; var r = new WeakMap(), t = new WeakMap(); return (_getRequireWildcardCache = function (e) { return e ? t : r; })(e); }
16
17
  function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" != typeof e && "function" != typeof e) return { default: e }; var t = _getRequireWildcardCache(r); if (t && t.has(e)) return t.get(e); var n = { __proto__: null }, a = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var u in e) if ("default" !== u && {}.hasOwnProperty.call(e, u)) { var i = a ? Object.getOwnPropertyDescriptor(e, u) : null; i && (i.get || i.set) ? Object.defineProperty(n, u, i) : n[u] = e[u]; } return n.default = e, t && t.set(e, n), n; }
17
18
  function useTreeViewApiInitialization(inputApiRef) {
@@ -47,6 +48,12 @@ const useTreeView = ({
47
48
  const publicAPI = useTreeViewApiInitialization(apiRef);
48
49
  const innerRootRef = React.useRef(null);
49
50
  const handleRootRef = (0, _useForkRef.default)(innerRootRef, rootRef);
51
+ const contextValue = (0, _useTreeViewBuildContext.useTreeViewBuildContext)({
52
+ plugins,
53
+ instance,
54
+ publicAPI,
55
+ rootRef: innerRootRef
56
+ });
50
57
  const [state, setState] = React.useState(() => {
51
58
  const temp = {};
52
59
  plugins.forEach(plugin => {
@@ -56,68 +63,6 @@ const useTreeView = ({
56
63
  });
57
64
  return temp;
58
65
  });
59
- const itemWrappers = plugins.map(plugin => plugin.wrapItem).filter(wrapItem => !!wrapItem);
60
- const wrapItem = ({
61
- itemId,
62
- children
63
- }) => {
64
- let finalChildren = children;
65
- itemWrappers.forEach(itemWrapper => {
66
- finalChildren = itemWrapper({
67
- itemId,
68
- children: finalChildren,
69
- instance
70
- });
71
- });
72
- return finalChildren;
73
- };
74
- const rootWrappers = plugins.map(plugin => plugin.wrapRoot).filter(wrapRoot => !!wrapRoot)
75
- // The wrappers are reversed to ensure that the first wrapper is the outermost one.
76
- .reverse();
77
- const wrapRoot = ({
78
- children
79
- }) => {
80
- let finalChildren = children;
81
- rootWrappers.forEach(rootWrapper => {
82
- finalChildren = rootWrapper({
83
- children: finalChildren,
84
- instance
85
- });
86
- });
87
- return finalChildren;
88
- };
89
- const runItemPlugins = itemPluginProps => {
90
- let finalRootRef = null;
91
- let finalContentRef = null;
92
- plugins.forEach(plugin => {
93
- if (!plugin.itemPlugin) {
94
- return;
95
- }
96
- const itemPluginResponse = plugin.itemPlugin({
97
- props: itemPluginProps,
98
- rootRef: finalRootRef,
99
- contentRef: finalContentRef
100
- });
101
- if (itemPluginResponse?.rootRef) {
102
- finalRootRef = itemPluginResponse.rootRef;
103
- }
104
- if (itemPluginResponse?.contentRef) {
105
- finalContentRef = itemPluginResponse.contentRef;
106
- }
107
- });
108
- return {
109
- contentRef: finalContentRef,
110
- rootRef: finalRootRef
111
- };
112
- };
113
- const contextValue = {
114
- publicAPI,
115
- wrapItem,
116
- wrapRoot,
117
- runItemPlugins,
118
- instance: instance,
119
- rootRef: innerRootRef
120
- };
121
66
  const rootPropsGetters = [];
122
67
  const runPlugin = plugin => {
123
68
  const pluginResponse = plugin({
@@ -0,0 +1,102 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.useTreeViewBuildContext = void 0;
7
+ const useTreeViewBuildContext = ({
8
+ plugins,
9
+ instance,
10
+ publicAPI,
11
+ rootRef
12
+ }) => {
13
+ const runItemPlugins = itemPluginProps => {
14
+ let finalRootRef = null;
15
+ let finalContentRef = null;
16
+ const pluginPropEnhancers = [];
17
+ const pluginPropEnhancersNames = {};
18
+ plugins.forEach(plugin => {
19
+ if (!plugin.itemPlugin) {
20
+ return;
21
+ }
22
+ const itemPluginResponse = plugin.itemPlugin({
23
+ props: itemPluginProps,
24
+ rootRef: finalRootRef,
25
+ contentRef: finalContentRef
26
+ });
27
+ if (itemPluginResponse?.rootRef) {
28
+ finalRootRef = itemPluginResponse.rootRef;
29
+ }
30
+ if (itemPluginResponse?.contentRef) {
31
+ finalContentRef = itemPluginResponse.contentRef;
32
+ }
33
+ if (itemPluginResponse?.propsEnhancers) {
34
+ pluginPropEnhancers.push(itemPluginResponse.propsEnhancers);
35
+
36
+ // Prepare a list of all the slots which are enhanced by at least one plugin
37
+ Object.keys(itemPluginResponse.propsEnhancers).forEach(propsEnhancerName => {
38
+ pluginPropEnhancersNames[propsEnhancerName] = true;
39
+ });
40
+ }
41
+ });
42
+ const resolvePropsEnhancer = currentSlotName => currentSlotParams => {
43
+ const enhancedProps = {};
44
+ pluginPropEnhancers.forEach(propsEnhancersForCurrentPlugin => {
45
+ const propsEnhancerForCurrentPluginAndSlot = propsEnhancersForCurrentPlugin[currentSlotName];
46
+ if (propsEnhancerForCurrentPluginAndSlot != null) {
47
+ Object.assign(enhancedProps, propsEnhancerForCurrentPluginAndSlot(currentSlotParams));
48
+ }
49
+ });
50
+ return enhancedProps;
51
+ };
52
+ const propsEnhancers = Object.fromEntries(Object.keys(pluginPropEnhancersNames).map(propEnhancerName => [propEnhancerName, resolvePropsEnhancer(propEnhancerName)]));
53
+ return {
54
+ contentRef: finalContentRef,
55
+ rootRef: finalRootRef,
56
+ propsEnhancers
57
+ };
58
+ };
59
+ const wrapItem = ({
60
+ itemId,
61
+ children
62
+ }) => {
63
+ let finalChildren = children;
64
+ // The wrappers are reversed to ensure that the first wrapper is the outermost one.
65
+ for (let i = plugins.length - 1; i >= 0; i -= 1) {
66
+ const plugin = plugins[i];
67
+ if (plugin.wrapItem) {
68
+ finalChildren = plugin.wrapItem({
69
+ itemId,
70
+ children: finalChildren,
71
+ instance
72
+ });
73
+ }
74
+ }
75
+ return finalChildren;
76
+ };
77
+ const wrapRoot = ({
78
+ children
79
+ }) => {
80
+ let finalChildren = children;
81
+ // The wrappers are reversed to ensure that the first wrapper is the outermost one.
82
+ for (let i = plugins.length - 1; i >= 0; i -= 1) {
83
+ const plugin = plugins[i];
84
+ if (plugin.wrapRoot) {
85
+ finalChildren = plugin.wrapRoot({
86
+ children: finalChildren,
87
+ instance
88
+ });
89
+ }
90
+ }
91
+ return finalChildren;
92
+ };
93
+ return {
94
+ runItemPlugins,
95
+ wrapItem,
96
+ wrapRoot,
97
+ instance,
98
+ rootRef,
99
+ publicAPI
100
+ };
101
+ };
102
+ exports.useTreeViewBuildContext = useTreeViewBuildContext;
@@ -0,0 +1 @@
1
+ "use strict";
@@ -3,19 +3,26 @@
3
3
  Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
- exports.buildWarning = void 0;
7
- const buildWarning = (message, gravity = 'warning') => {
8
- let alreadyWarned = false;
6
+ exports.clearWarningsCache = clearWarningsCache;
7
+ exports.warnOnce = warnOnce;
8
+ const warnedOnceCache = new Set();
9
+
10
+ // TODO move to @mui/x-internals
11
+ // TODO eventually move to @base_ui/internals. Base UI, etc. too need this helper.
12
+ function warnOnce(message, gravity = 'warning') {
13
+ if (process.env.NODE_ENV === 'production') {
14
+ return;
15
+ }
9
16
  const cleanMessage = Array.isArray(message) ? message.join('\n') : message;
10
- return () => {
11
- if (!alreadyWarned) {
12
- alreadyWarned = true;
13
- if (gravity === 'error') {
14
- console.error(cleanMessage);
15
- } else {
16
- console.warn(cleanMessage);
17
- }
17
+ if (!warnedOnceCache.has(cleanMessage)) {
18
+ warnedOnceCache.add(cleanMessage);
19
+ if (gravity === 'error') {
20
+ console.error(cleanMessage);
21
+ } else {
22
+ console.warn(cleanMessage);
18
23
  }
19
- };
20
- };
21
- exports.buildWarning = buildWarning;
24
+ }
25
+ }
26
+ function clearWarningsCache() {
27
+ warnedOnceCache.clear();
28
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mui/x-tree-view",
3
- "version": "7.10.0",
3
+ "version": "7.11.1",
4
4
  "description": "The community edition of the Tree View components (MUI X).",
5
5
  "author": "MUI Team",
6
6
  "main": "./node/index.js",
@@ -33,14 +33,15 @@
33
33
  "directory": "packages/x-tree-view"
34
34
  },
35
35
  "dependencies": {
36
- "@babel/runtime": "^7.24.7",
36
+ "@babel/runtime": "^7.24.8",
37
37
  "@mui/base": "^5.0.0-beta.40",
38
- "@mui/system": "^5.16.0",
39
- "@mui/utils": "^5.16.0",
38
+ "@mui/system": "^5.16.5",
39
+ "@mui/utils": "^5.16.5",
40
40
  "@types/react-transition-group": "^4.4.10",
41
41
  "clsx": "^2.1.1",
42
42
  "prop-types": "^15.8.1",
43
- "react-transition-group": "^4.4.5"
43
+ "react-transition-group": "^4.4.5",
44
+ "@mui/x-internals": "7.11.1"
44
45
  },
45
46
  "peerDependencies": {
46
47
  "@emotion/react": "^11.9.0",
@@ -1,2 +1,2 @@
1
1
  export { useTreeItem2 as unstable_useTreeItem2 } from './useTreeItem2';
2
- export type { UseTreeItem2Parameters, UseTreeItem2ReturnValue, UseTreeItem2Status, UseTreeItem2ContentSlotOwnProps, } from './useTreeItem2.types';
2
+ export type { UseTreeItem2Parameters, UseTreeItem2ReturnValue, UseTreeItem2Status, UseTreeItem2RootSlotOwnProps, UseTreeItem2ContentSlotOwnProps, UseTreeItem2LabelSlotOwnProps, UseTreeItem2IconContainerSlotOwnProps, UseTreeItem2GroupTransitionSlotOwnProps, } from './useTreeItem2.types';