@mui/x-tree-view 7.10.0 → 7.11.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md CHANGED
@@ -3,6 +3,91 @@
3
3
  All notable changes to this project will be documented in this file.
4
4
  See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
5
5
 
6
+ ## 7.11.0
7
+
8
+ _Jul 18, 2024_
9
+
10
+ We'd like to offer a big thanks to the 13 contributors who made this release possible. Here are some highlights ✨:
11
+
12
+ - 🎨 Add [color legend](https://mui.com/x/react-charts/legend/#color-legend) for charts (#13700) @alexfauquette
13
+ - 🌍 Improve Korean (ko-KR) locale on the Date and Time Pickers
14
+ - 🌍 Improve Russian (ru-RU) locale on the Date and Time Pickers and Data Grid
15
+ - 🐞 Bugfixes
16
+ - 📚 Documentation improvements
17
+
18
+ <!--/ HIGHLIGHT_ABOVE_SEPARATOR /-->
19
+
20
+ ### Data Grid
21
+
22
+ #### `@mui/x-data-grid@7.11.0`
23
+
24
+ - [DataGrid] Expose `gridEditRowsStateSelector` (#13877) @romgrk
25
+ - [DataGrid] Fix `columnResizeStop` event not emitted when column is not resized (#13307) @mateuseap
26
+ - [DataGrid] Fix delete filter inconsistent behavior (#13353) @oukunan
27
+ - [DataGrid] Enable flip on preferences panel (#13803) @romgrk
28
+ - [DataGrid] Support `date` and `datetime-local` input types in `GridFilterInputMultipleValue` type (#13411) @karudedios
29
+ - [l10n] Improve Russian (ru-RU) locale (#13735) @diro-atk
30
+
31
+ #### `@mui/x-data-grid-pro@7.11.0` [![pro](https://mui.com/r/x-pro-svg)](https://mui.com/r/x-pro-svg-link 'Pro plan')
32
+
33
+ Same changes as in `@mui/x-data-grid@7.11.0`.
34
+
35
+ #### `@mui/x-data-grid-premium@7.11.0` [![premium](https://mui.com/r/x-premium-svg)](https://mui.com/r/x-premium-svg-link 'Premium plan')
36
+
37
+ Same changes as in `@mui/x-data-grid-pro@7.11.0`.
38
+
39
+ ### Date and Time Pickers
40
+
41
+ #### `@mui/x-date-pickers@7.11.0`
42
+
43
+ - [l10n] Improve Korean (ko-KR) locale (#13651) @100pearlcent
44
+ - [l10n] Improve Russian (ru-RU) locale (#13871) @Inv1x
45
+ - [pickers] Add more conformance tests improving API docs precision (#13800) @LukasTy
46
+ - [TimePicker] Add `Mui-selected` class to `TimeClock` meridiem buttons (#13848) @LukasTy
47
+
48
+ #### `@mui/x-date-pickers-pro@7.11.0` [![pro](https://mui.com/r/x-pro-svg)](https://mui.com/r/x-pro-svg-link 'Pro plan')
49
+
50
+ Same changes as in `@mui/x-date-pickers@7.11.0`, plus:
51
+
52
+ - [DateRangePicker] Fix `name` prop propagation regression (#13821) @LukasTy
53
+
54
+ ### Charts
55
+
56
+ #### `@mui/x-charts@7.11.0`
57
+
58
+ - [charts] Create color legend (#13700) @alexfauquette
59
+ - [charts] Defaultize axis on top level `useChartContainerProps` (#13817) @JCQuintas
60
+ - [charts] Fix charts not passing `className` to root element (#13647) @JCQuintas
61
+ - [charts] Generate API documentation for pro components (#13822) @alexfauquette
62
+ - [charts] Improve zoomed highlight behaviour (unreleased) (#13868) @JCQuintas
63
+ - [charts] Allow zoom on Y axis and add zoom options to configure zooming behaviour (unreleased) (#13726) @JCQuintas
64
+ - [charts] Disable animations while zooming (unreleased) (#13807) @JCQuintas
65
+
66
+ ### Tree View
67
+
68
+ #### `@mui/x-tree-view@7.11.0`
69
+
70
+ - [TreeView] Extract some logic outside of the `useTreeView` hook (#13845) @flaviendelangle
71
+
72
+ ### Docs
73
+
74
+ - [docs] Add warning about `process.env.NODE_ENV` in production (#13869) @cherniavskii
75
+ - [docs] Allow controlling the demo form from the example (#13796) @JCQuintas
76
+ - [docs] Clarify Pickers clearable behavior not working on mobile (#13786) @lnhrdt
77
+ - [docs] Improve the documentation of the picker's `onChange` and `onAccept` props (#13543) @flaviendelangle
78
+ - [docs] Replace company name with project name @oliviertassinari
79
+ - [docs] Sort Pickers & Charts API slots alphabetically (#13843) @LukasTy
80
+
81
+ ### Core
82
+
83
+ - [core] Add MUI Internal `renovate` group (#13846) @LukasTy
84
+ - [core] Link GitHub issue for `import/prefer-default-export` rule @oliviertassinari
85
+ - [core] Normalize `...other` and test imports in charts (#13844) @JCQuintas
86
+ - [core] Normalize rest / other to match the most common used @oliviertassinari
87
+ - [code-infra] Follow `next` tag for `@mui/docs` package bumps (#13813) @LukasTy
88
+ - [code-infra] Use specific version for `@mui/docs` dependency (#13760) @LukasTy
89
+ - [internals] Move `EventManager` to `@mui/x-internals` package (#13815) @flaviendelangle
90
+
6
91
  ## 7.10.0
7
92
 
8
93
  _Jul 11, 2024_
@@ -14,7 +14,7 @@ export declare const TreeItem2GroupTransition: import("@emotion/styled").StyledC
14
14
  }, {}, {}>;
15
15
  export declare const TreeItem2Checkbox: import("@emotion/styled").StyledComponent<Pick<Omit<CheckboxProps & {
16
16
  visible: boolean;
17
- }, "ref"> & React.RefAttributes<HTMLButtonElement>, "hidden" | "visible" | "color" | "content" | "size" | "style" | "icon" | "translate" | "disabled" | "form" | "slot" | "title" | "suppressHydrationWarning" | "className" | "id" | "lang" | "name" | "role" | "tabIndex" | "aria-activedescendant" | "aria-atomic" | "aria-autocomplete" | "aria-braillelabel" | "aria-brailleroledescription" | "aria-busy" | "aria-checked" | "aria-colcount" | "aria-colindex" | "aria-colindextext" | "aria-colspan" | "aria-controls" | "aria-current" | "aria-describedby" | "aria-description" | "aria-details" | "aria-disabled" | "aria-dropeffect" | "aria-errormessage" | "aria-expanded" | "aria-flowto" | "aria-grabbed" | "aria-haspopup" | "aria-hidden" | "aria-invalid" | "aria-keyshortcuts" | "aria-label" | "aria-labelledby" | "aria-level" | "aria-live" | "aria-modal" | "aria-multiline" | "aria-multiselectable" | "aria-orientation" | "aria-owns" | "aria-placeholder" | "aria-posinset" | "aria-pressed" | "aria-readonly" | "aria-relevant" | "aria-required" | "aria-roledescription" | "aria-rowcount" | "aria-rowindex" | "aria-rowindextext" | "aria-rowspan" | "aria-selected" | "aria-setsize" | "aria-sort" | "aria-valuemax" | "aria-valuemin" | "aria-valuenow" | "aria-valuetext" | "dangerouslySetInnerHTML" | "onCopy" | "onCopyCapture" | "onCut" | "onCutCapture" | "onPaste" | "onPasteCapture" | "onCompositionEnd" | "onCompositionEndCapture" | "onCompositionStart" | "onCompositionStartCapture" | "onCompositionUpdate" | "onCompositionUpdateCapture" | "onFocus" | "onFocusCapture" | "onBlur" | "onBlurCapture" | "onChange" | "onChangeCapture" | "onBeforeInput" | "onBeforeInputCapture" | "onInput" | "onInputCapture" | "onReset" | "onResetCapture" | "onSubmit" | "onSubmitCapture" | "onInvalid" | "onInvalidCapture" | "onLoad" | "onLoadCapture" | "onError" | "onErrorCapture" | "onKeyDown" | "onKeyDownCapture" | "onKeyPress" | "onKeyPressCapture" | "onKeyUp" | "onKeyUpCapture" | "onAbort" | "onAbortCapture" | "onCanPlay" | "onCanPlayCapture" | "onCanPlayThrough" | "onCanPlayThroughCapture" | "onDurationChange" | "onDurationChangeCapture" | "onEmptied" | "onEmptiedCapture" | "onEncrypted" | "onEncryptedCapture" | "onEnded" | "onEndedCapture" | "onLoadedData" | "onLoadedDataCapture" | "onLoadedMetadata" | "onLoadedMetadataCapture" | "onLoadStart" | "onLoadStartCapture" | "onPause" | "onPauseCapture" | "onPlay" | "onPlayCapture" | "onPlaying" | "onPlayingCapture" | "onProgress" | "onProgressCapture" | "onRateChange" | "onRateChangeCapture" | "onResize" | "onResizeCapture" | "onSeeked" | "onSeekedCapture" | "onSeeking" | "onSeekingCapture" | "onStalled" | "onStalledCapture" | "onSuspend" | "onSuspendCapture" | "onTimeUpdate" | "onTimeUpdateCapture" | "onVolumeChange" | "onVolumeChangeCapture" | "onWaiting" | "onWaitingCapture" | "onAuxClick" | "onAuxClickCapture" | "onClick" | "onClickCapture" | "onContextMenu" | "onContextMenuCapture" | "onDoubleClick" | "onDoubleClickCapture" | "onDrag" | "onDragCapture" | "onDragEnd" | "onDragEndCapture" | "onDragEnter" | "onDragEnterCapture" | "onDragExit" | "onDragExitCapture" | "onDragLeave" | "onDragLeaveCapture" | "onDragOver" | "onDragOverCapture" | "onDragStart" | "onDragStartCapture" | "onDrop" | "onDropCapture" | "onMouseDown" | "onMouseDownCapture" | "onMouseEnter" | "onMouseLeave" | "onMouseMove" | "onMouseMoveCapture" | "onMouseOut" | "onMouseOutCapture" | "onMouseOver" | "onMouseOverCapture" | "onMouseUp" | "onMouseUpCapture" | "onSelect" | "onSelectCapture" | "onTouchCancel" | "onTouchCancelCapture" | "onTouchEnd" | "onTouchEndCapture" | "onTouchMove" | "onTouchMoveCapture" | "onTouchStart" | "onTouchStartCapture" | "onPointerDown" | "onPointerDownCapture" | "onPointerMove" | "onPointerMoveCapture" | "onPointerUp" | "onPointerUpCapture" | "onPointerCancel" | "onPointerCancelCapture" | "onPointerEnter" | "onPointerLeave" | "onPointerOver" | "onPointerOverCapture" | "onPointerOut" | "onPointerOutCapture" | "onGotPointerCapture" | "onGotPointerCaptureCapture" | "onLostPointerCapture" | "onLostPointerCaptureCapture" | "onScroll" | "onScrollCapture" | "onWheel" | "onWheelCapture" | "onAnimationStart" | "onAnimationStartCapture" | "onAnimationEnd" | "onAnimationEndCapture" | "onAnimationIteration" | "onAnimationIterationCapture" | "onTransitionEnd" | "onTransitionEndCapture" | "defaultChecked" | "defaultValue" | "suppressContentEditableWarning" | "accessKey" | "autoFocus" | "contentEditable" | "contextMenu" | "dir" | "draggable" | "nonce" | "spellCheck" | "radioGroup" | "about" | "datatype" | "inlist" | "prefix" | "property" | "rel" | "resource" | "rev" | "typeof" | "vocab" | "autoCapitalize" | "autoCorrect" | "autoSave" | "itemProp" | "itemScope" | "itemType" | "itemID" | "itemRef" | "results" | "security" | "unselectable" | "inputMode" | "is" | "formAction" | "formEncType" | "formMethod" | "formNoValidate" | "formTarget" | "value" | "readOnly" | "required" | "action" | "checked" | "component" | "sx" | "classes" | "onFocusVisible" | "inputRef" | "centerRipple" | "disableRipple" | "disableTouchRipple" | "focusRipple" | "focusVisibleClassName" | "LinkComponent" | "TouchRippleProps" | "touchRippleRef" | "disableFocusRipple" | "edge" | "checkedIcon" | "inputProps" | "indeterminate" | "indeterminateIcon" | keyof React.RefAttributes<HTMLButtonElement>> & import("@mui/system/createStyled").MUIStyledCommonProps<import("@mui/material/styles").Theme>, {}, {}>;
17
+ }, "ref"> & React.RefAttributes<HTMLButtonElement>, "hidden" | "visible" | "color" | "content" | "size" | "style" | "icon" | "translate" | "disabled" | "form" | "slot" | "title" | "suppressHydrationWarning" | "className" | "id" | "lang" | "name" | "role" | "tabIndex" | "aria-activedescendant" | "aria-atomic" | "aria-autocomplete" | "aria-braillelabel" | "aria-brailleroledescription" | "aria-busy" | "aria-checked" | "aria-colcount" | "aria-colindex" | "aria-colindextext" | "aria-colspan" | "aria-controls" | "aria-current" | "aria-describedby" | "aria-description" | "aria-details" | "aria-disabled" | "aria-dropeffect" | "aria-errormessage" | "aria-expanded" | "aria-flowto" | "aria-grabbed" | "aria-haspopup" | "aria-hidden" | "aria-invalid" | "aria-keyshortcuts" | "aria-label" | "aria-labelledby" | "aria-level" | "aria-live" | "aria-modal" | "aria-multiline" | "aria-multiselectable" | "aria-orientation" | "aria-owns" | "aria-placeholder" | "aria-posinset" | "aria-pressed" | "aria-readonly" | "aria-relevant" | "aria-required" | "aria-roledescription" | "aria-rowcount" | "aria-rowindex" | "aria-rowindextext" | "aria-rowspan" | "aria-selected" | "aria-setsize" | "aria-sort" | "aria-valuemax" | "aria-valuemin" | "aria-valuenow" | "aria-valuetext" | "dangerouslySetInnerHTML" | "onCopy" | "onCopyCapture" | "onCut" | "onCutCapture" | "onPaste" | "onPasteCapture" | "onCompositionEnd" | "onCompositionEndCapture" | "onCompositionStart" | "onCompositionStartCapture" | "onCompositionUpdate" | "onCompositionUpdateCapture" | "onFocus" | "onFocusCapture" | "onBlur" | "onBlurCapture" | "onChange" | "onChangeCapture" | "onBeforeInput" | "onBeforeInputCapture" | "onInput" | "onInputCapture" | "onReset" | "onResetCapture" | "onSubmit" | "onSubmitCapture" | "onInvalid" | "onInvalidCapture" | "onLoad" | "onLoadCapture" | "onError" | "onErrorCapture" | "onKeyDown" | "onKeyDownCapture" | "onKeyPress" | "onKeyPressCapture" | "onKeyUp" | "onKeyUpCapture" | "onAbort" | "onAbortCapture" | "onCanPlay" | "onCanPlayCapture" | "onCanPlayThrough" | "onCanPlayThroughCapture" | "onDurationChange" | "onDurationChangeCapture" | "onEmptied" | "onEmptiedCapture" | "onEncrypted" | "onEncryptedCapture" | "onEnded" | "onEndedCapture" | "onLoadedData" | "onLoadedDataCapture" | "onLoadedMetadata" | "onLoadedMetadataCapture" | "onLoadStart" | "onLoadStartCapture" | "onPause" | "onPauseCapture" | "onPlay" | "onPlayCapture" | "onPlaying" | "onPlayingCapture" | "onProgress" | "onProgressCapture" | "onRateChange" | "onRateChangeCapture" | "onResize" | "onResizeCapture" | "onSeeked" | "onSeekedCapture" | "onSeeking" | "onSeekingCapture" | "onStalled" | "onStalledCapture" | "onSuspend" | "onSuspendCapture" | "onTimeUpdate" | "onTimeUpdateCapture" | "onVolumeChange" | "onVolumeChangeCapture" | "onWaiting" | "onWaitingCapture" | "onAuxClick" | "onAuxClickCapture" | "onClick" | "onClickCapture" | "onContextMenu" | "onContextMenuCapture" | "onDoubleClick" | "onDoubleClickCapture" | "onDrag" | "onDragCapture" | "onDragEnd" | "onDragEndCapture" | "onDragEnter" | "onDragEnterCapture" | "onDragExit" | "onDragExitCapture" | "onDragLeave" | "onDragLeaveCapture" | "onDragOver" | "onDragOverCapture" | "onDragStart" | "onDragStartCapture" | "onDrop" | "onDropCapture" | "onMouseDown" | "onMouseDownCapture" | "onMouseEnter" | "onMouseLeave" | "onMouseMove" | "onMouseMoveCapture" | "onMouseOut" | "onMouseOutCapture" | "onMouseOver" | "onMouseOverCapture" | "onMouseUp" | "onMouseUpCapture" | "onSelect" | "onSelectCapture" | "onTouchCancel" | "onTouchCancelCapture" | "onTouchEnd" | "onTouchEndCapture" | "onTouchMove" | "onTouchMoveCapture" | "onTouchStart" | "onTouchStartCapture" | "onPointerDown" | "onPointerDownCapture" | "onPointerMove" | "onPointerMoveCapture" | "onPointerUp" | "onPointerUpCapture" | "onPointerCancel" | "onPointerCancelCapture" | "onPointerEnter" | "onPointerLeave" | "onPointerOver" | "onPointerOverCapture" | "onPointerOut" | "onPointerOutCapture" | "onGotPointerCapture" | "onGotPointerCaptureCapture" | "onLostPointerCapture" | "onLostPointerCaptureCapture" | "onScroll" | "onScrollCapture" | "onWheel" | "onWheelCapture" | "onAnimationStart" | "onAnimationStartCapture" | "onAnimationEnd" | "onAnimationEndCapture" | "onAnimationIteration" | "onAnimationIterationCapture" | "onTransitionEnd" | "onTransitionEndCapture" | "defaultChecked" | "defaultValue" | "suppressContentEditableWarning" | "accessKey" | "autoFocus" | "contentEditable" | "contextMenu" | "dir" | "draggable" | "nonce" | "spellCheck" | "radioGroup" | "about" | "datatype" | "inlist" | "prefix" | "property" | "rel" | "resource" | "rev" | "typeof" | "vocab" | "autoCapitalize" | "autoCorrect" | "autoSave" | "itemProp" | "itemScope" | "itemType" | "itemID" | "itemRef" | "results" | "security" | "unselectable" | "inputMode" | "is" | "formAction" | "formEncType" | "formMethod" | "formNoValidate" | "formTarget" | "value" | "readOnly" | "required" | "action" | "checked" | "component" | "sx" | "classes" | "centerRipple" | "disableRipple" | "disableTouchRipple" | "focusRipple" | "focusVisibleClassName" | "LinkComponent" | "onFocusVisible" | "TouchRippleProps" | "touchRippleRef" | "disableFocusRipple" | "edge" | "checkedIcon" | "inputProps" | "inputRef" | "indeterminate" | "indeterminateIcon" | keyof React.RefAttributes<HTMLButtonElement>> & import("@mui/system/createStyled").MUIStyledCommonProps<import("@mui/material/styles").Theme>, {}, {}>;
18
18
  type TreeItem2Component = ((props: TreeItem2Props & React.RefAttributes<HTMLLIElement>) => React.JSX.Element) & {
19
19
  propTypes?: any;
20
20
  };
package/index.js CHANGED
@@ -1,5 +1,5 @@
1
1
  /**
2
- * @mui/x-tree-view v7.10.0
2
+ * @mui/x-tree-view v7.11.0
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
  };
@@ -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,10 @@
1
+ import * as React from 'react';
2
+ import { TreeViewContextValue } from '../TreeViewProvider';
3
+ import { ConvertSignaturesIntoPlugins, TreeViewAnyPluginSignature, TreeViewInstance, TreeViewPublicAPI } from '../models';
4
+ import { TreeViewCorePluginSignatures } from '../corePlugins';
5
+ export declare const useTreeViewBuildContext: <TSignatures extends readonly TreeViewAnyPluginSignature[]>({ plugins, instance, publicAPI, rootRef, }: {
6
+ plugins: ConvertSignaturesIntoPlugins<readonly [...TreeViewCorePluginSignatures, ...TSignatures]>;
7
+ instance: TreeViewInstance<TSignatures>;
8
+ publicAPI: TreeViewPublicAPI<TSignatures>;
9
+ rootRef: React.RefObject<HTMLUListElement>;
10
+ }) => TreeViewContextValue<TSignatures>;
@@ -0,0 +1,73 @@
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
+ plugins.forEach(plugin => {
11
+ if (!plugin.itemPlugin) {
12
+ return;
13
+ }
14
+ const itemPluginResponse = plugin.itemPlugin({
15
+ props: itemPluginProps,
16
+ rootRef: finalRootRef,
17
+ contentRef: finalContentRef
18
+ });
19
+ if (itemPluginResponse?.rootRef) {
20
+ finalRootRef = itemPluginResponse.rootRef;
21
+ }
22
+ if (itemPluginResponse?.contentRef) {
23
+ finalContentRef = itemPluginResponse.contentRef;
24
+ }
25
+ });
26
+ return {
27
+ contentRef: finalContentRef,
28
+ rootRef: finalRootRef
29
+ };
30
+ };
31
+ const wrapItem = ({
32
+ itemId,
33
+ children
34
+ }) => {
35
+ let finalChildren = children;
36
+ // The wrappers are reversed to ensure that the first wrapper is the outermost one.
37
+ for (let i = plugins.length - 1; i >= 0; i -= 1) {
38
+ const plugin = plugins[i];
39
+ if (plugin.wrapItem) {
40
+ finalChildren = plugin.wrapItem({
41
+ itemId,
42
+ children: finalChildren,
43
+ instance
44
+ });
45
+ }
46
+ }
47
+ return finalChildren;
48
+ };
49
+ const wrapRoot = ({
50
+ children
51
+ }) => {
52
+ let finalChildren = children;
53
+ // The wrappers are reversed to ensure that the first wrapper is the outermost one.
54
+ for (let i = plugins.length - 1; i >= 0; i -= 1) {
55
+ const plugin = plugins[i];
56
+ if (plugin.wrapRoot) {
57
+ finalChildren = plugin.wrapRoot({
58
+ children: finalChildren,
59
+ instance
60
+ });
61
+ }
62
+ }
63
+ return finalChildren;
64
+ };
65
+ return {
66
+ runItemPlugins,
67
+ wrapItem,
68
+ wrapRoot,
69
+ instance,
70
+ rootRef,
71
+ publicAPI
72
+ };
73
+ };
File without changes
File without changes
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.0
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
  };
@@ -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,73 @@
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
+ plugins.forEach(plugin => {
11
+ if (!plugin.itemPlugin) {
12
+ return;
13
+ }
14
+ const itemPluginResponse = plugin.itemPlugin({
15
+ props: itemPluginProps,
16
+ rootRef: finalRootRef,
17
+ contentRef: finalContentRef
18
+ });
19
+ if (itemPluginResponse?.rootRef) {
20
+ finalRootRef = itemPluginResponse.rootRef;
21
+ }
22
+ if (itemPluginResponse?.contentRef) {
23
+ finalContentRef = itemPluginResponse.contentRef;
24
+ }
25
+ });
26
+ return {
27
+ contentRef: finalContentRef,
28
+ rootRef: finalRootRef
29
+ };
30
+ };
31
+ const wrapItem = ({
32
+ itemId,
33
+ children
34
+ }) => {
35
+ let finalChildren = children;
36
+ // The wrappers are reversed to ensure that the first wrapper is the outermost one.
37
+ for (let i = plugins.length - 1; i >= 0; i -= 1) {
38
+ const plugin = plugins[i];
39
+ if (plugin.wrapItem) {
40
+ finalChildren = plugin.wrapItem({
41
+ itemId,
42
+ children: finalChildren,
43
+ instance
44
+ });
45
+ }
46
+ }
47
+ return finalChildren;
48
+ };
49
+ const wrapRoot = ({
50
+ children
51
+ }) => {
52
+ let finalChildren = children;
53
+ // The wrappers are reversed to ensure that the first wrapper is the outermost one.
54
+ for (let i = plugins.length - 1; i >= 0; i -= 1) {
55
+ const plugin = plugins[i];
56
+ if (plugin.wrapRoot) {
57
+ finalChildren = plugin.wrapRoot({
58
+ children: finalChildren,
59
+ instance
60
+ });
61
+ }
62
+ }
63
+ return finalChildren;
64
+ };
65
+ return {
66
+ runItemPlugins,
67
+ wrapItem,
68
+ wrapRoot,
69
+ instance,
70
+ rootRef,
71
+ publicAPI
72
+ };
73
+ };
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.0
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 => {
@@ -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,80 @@
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
+ plugins.forEach(plugin => {
17
+ if (!plugin.itemPlugin) {
18
+ return;
19
+ }
20
+ const itemPluginResponse = plugin.itemPlugin({
21
+ props: itemPluginProps,
22
+ rootRef: finalRootRef,
23
+ contentRef: finalContentRef
24
+ });
25
+ if (itemPluginResponse?.rootRef) {
26
+ finalRootRef = itemPluginResponse.rootRef;
27
+ }
28
+ if (itemPluginResponse?.contentRef) {
29
+ finalContentRef = itemPluginResponse.contentRef;
30
+ }
31
+ });
32
+ return {
33
+ contentRef: finalContentRef,
34
+ rootRef: finalRootRef
35
+ };
36
+ };
37
+ const wrapItem = ({
38
+ itemId,
39
+ children
40
+ }) => {
41
+ let finalChildren = children;
42
+ // The wrappers are reversed to ensure that the first wrapper is the outermost one.
43
+ for (let i = plugins.length - 1; i >= 0; i -= 1) {
44
+ const plugin = plugins[i];
45
+ if (plugin.wrapItem) {
46
+ finalChildren = plugin.wrapItem({
47
+ itemId,
48
+ children: finalChildren,
49
+ instance
50
+ });
51
+ }
52
+ }
53
+ return finalChildren;
54
+ };
55
+ const wrapRoot = ({
56
+ children
57
+ }) => {
58
+ let finalChildren = children;
59
+ // The wrappers are reversed to ensure that the first wrapper is the outermost one.
60
+ for (let i = plugins.length - 1; i >= 0; i -= 1) {
61
+ const plugin = plugins[i];
62
+ if (plugin.wrapRoot) {
63
+ finalChildren = plugin.wrapRoot({
64
+ children: finalChildren,
65
+ instance
66
+ });
67
+ }
68
+ }
69
+ return finalChildren;
70
+ };
71
+ return {
72
+ runItemPlugins,
73
+ wrapItem,
74
+ wrapRoot,
75
+ instance,
76
+ rootRef,
77
+ publicAPI
78
+ };
79
+ };
80
+ exports.useTreeViewBuildContext = useTreeViewBuildContext;
@@ -0,0 +1 @@
1
+ "use strict";
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.0",
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.2",
39
+ "@mui/utils": "^5.16.2",
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.0"
44
45
  },
45
46
  "peerDependencies": {
46
47
  "@emotion/react": "^11.9.0",
@@ -1,29 +0,0 @@
1
- export type EventListener = (...args: any[]) => void;
2
- export interface EventListenerOptions {
3
- isFirst?: boolean;
4
- }
5
- interface EventListenerCollection {
6
- /**
7
- * List of listeners to run before the others
8
- * They are run in the opposite order of the registration order
9
- */
10
- highPriority: Map<EventListener, true>;
11
- /**
12
- * List of events to run after the high priority listeners
13
- * They are run in the registration order
14
- */
15
- regular: Map<EventListener, true>;
16
- }
17
- export declare class EventManager {
18
- maxListeners: number;
19
- warnOnce: boolean;
20
- events: {
21
- [eventName: string]: EventListenerCollection;
22
- };
23
- on(eventName: string, listener: EventListener, options?: EventListenerOptions): void;
24
- removeListener(eventName: string, listener: EventListener): void;
25
- removeAllListeners(): void;
26
- emit(eventName: string, ...args: any[]): void;
27
- once(eventName: string, listener: EventListener): void;
28
- }
29
- export {};
@@ -1,69 +0,0 @@
1
- // Used https://gist.github.com/mudge/5830382 as a starting point.
2
- // See https://github.com/browserify/events/blob/master/events.js for
3
- // the Node.js (https://nodejs.org/api/events.html) polyfill used by webpack.
4
- export class EventManager {
5
- constructor() {
6
- this.maxListeners = 20;
7
- this.warnOnce = false;
8
- this.events = {};
9
- }
10
- on(eventName, listener, options = {}) {
11
- let collection = this.events[eventName];
12
- if (!collection) {
13
- collection = {
14
- highPriority: new Map(),
15
- regular: new Map()
16
- };
17
- this.events[eventName] = collection;
18
- }
19
- if (options.isFirst) {
20
- collection.highPriority.set(listener, true);
21
- } else {
22
- collection.regular.set(listener, true);
23
- }
24
- if (process.env.NODE_ENV !== 'production') {
25
- const collectionSize = collection.highPriority.size + collection.regular.size;
26
- if (collectionSize > this.maxListeners && !this.warnOnce) {
27
- this.warnOnce = true;
28
- console.warn([`Possible EventEmitter memory leak detected. ${collectionSize} ${eventName} listeners added.`].join('\n'));
29
- }
30
- }
31
- }
32
- removeListener(eventName, listener) {
33
- if (this.events[eventName]) {
34
- this.events[eventName].regular.delete(listener);
35
- this.events[eventName].highPriority.delete(listener);
36
- }
37
- }
38
- removeAllListeners() {
39
- this.events = {};
40
- }
41
- emit(eventName, ...args) {
42
- const collection = this.events[eventName];
43
- if (!collection) {
44
- return;
45
- }
46
- const highPriorityListeners = Array.from(collection.highPriority.keys());
47
- const regularListeners = Array.from(collection.regular.keys());
48
- for (let i = highPriorityListeners.length - 1; i >= 0; i -= 1) {
49
- const listener = highPriorityListeners[i];
50
- if (collection.highPriority.has(listener)) {
51
- listener.apply(this, args);
52
- }
53
- }
54
- for (let i = 0; i < regularListeners.length; i += 1) {
55
- const listener = regularListeners[i];
56
- if (collection.regular.has(listener)) {
57
- listener.apply(this, args);
58
- }
59
- }
60
- }
61
- once(eventName, listener) {
62
- // eslint-disable-next-line consistent-this
63
- const that = this;
64
- this.on(eventName, function oneTimeListener(...args) {
65
- that.removeListener(eventName, oneTimeListener);
66
- listener.apply(that, args);
67
- });
68
- }
69
- }
@@ -1,69 +0,0 @@
1
- // Used https://gist.github.com/mudge/5830382 as a starting point.
2
- // See https://github.com/browserify/events/blob/master/events.js for
3
- // the Node.js (https://nodejs.org/api/events.html) polyfill used by webpack.
4
- export class EventManager {
5
- constructor() {
6
- this.maxListeners = 20;
7
- this.warnOnce = false;
8
- this.events = {};
9
- }
10
- on(eventName, listener, options = {}) {
11
- let collection = this.events[eventName];
12
- if (!collection) {
13
- collection = {
14
- highPriority: new Map(),
15
- regular: new Map()
16
- };
17
- this.events[eventName] = collection;
18
- }
19
- if (options.isFirst) {
20
- collection.highPriority.set(listener, true);
21
- } else {
22
- collection.regular.set(listener, true);
23
- }
24
- if (process.env.NODE_ENV !== 'production') {
25
- const collectionSize = collection.highPriority.size + collection.regular.size;
26
- if (collectionSize > this.maxListeners && !this.warnOnce) {
27
- this.warnOnce = true;
28
- console.warn([`Possible EventEmitter memory leak detected. ${collectionSize} ${eventName} listeners added.`].join('\n'));
29
- }
30
- }
31
- }
32
- removeListener(eventName, listener) {
33
- if (this.events[eventName]) {
34
- this.events[eventName].regular.delete(listener);
35
- this.events[eventName].highPriority.delete(listener);
36
- }
37
- }
38
- removeAllListeners() {
39
- this.events = {};
40
- }
41
- emit(eventName, ...args) {
42
- const collection = this.events[eventName];
43
- if (!collection) {
44
- return;
45
- }
46
- const highPriorityListeners = Array.from(collection.highPriority.keys());
47
- const regularListeners = Array.from(collection.regular.keys());
48
- for (let i = highPriorityListeners.length - 1; i >= 0; i -= 1) {
49
- const listener = highPriorityListeners[i];
50
- if (collection.highPriority.has(listener)) {
51
- listener.apply(this, args);
52
- }
53
- }
54
- for (let i = 0; i < regularListeners.length; i += 1) {
55
- const listener = regularListeners[i];
56
- if (collection.regular.has(listener)) {
57
- listener.apply(this, args);
58
- }
59
- }
60
- }
61
- once(eventName, listener) {
62
- // eslint-disable-next-line consistent-this
63
- const that = this;
64
- this.on(eventName, function oneTimeListener(...args) {
65
- that.removeListener(eventName, oneTimeListener);
66
- listener.apply(that, args);
67
- });
68
- }
69
- }
@@ -1,76 +0,0 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.EventManager = void 0;
7
- // Used https://gist.github.com/mudge/5830382 as a starting point.
8
- // See https://github.com/browserify/events/blob/master/events.js for
9
- // the Node.js (https://nodejs.org/api/events.html) polyfill used by webpack.
10
- class EventManager {
11
- constructor() {
12
- this.maxListeners = 20;
13
- this.warnOnce = false;
14
- this.events = {};
15
- }
16
- on(eventName, listener, options = {}) {
17
- let collection = this.events[eventName];
18
- if (!collection) {
19
- collection = {
20
- highPriority: new Map(),
21
- regular: new Map()
22
- };
23
- this.events[eventName] = collection;
24
- }
25
- if (options.isFirst) {
26
- collection.highPriority.set(listener, true);
27
- } else {
28
- collection.regular.set(listener, true);
29
- }
30
- if (process.env.NODE_ENV !== 'production') {
31
- const collectionSize = collection.highPriority.size + collection.regular.size;
32
- if (collectionSize > this.maxListeners && !this.warnOnce) {
33
- this.warnOnce = true;
34
- console.warn([`Possible EventEmitter memory leak detected. ${collectionSize} ${eventName} listeners added.`].join('\n'));
35
- }
36
- }
37
- }
38
- removeListener(eventName, listener) {
39
- if (this.events[eventName]) {
40
- this.events[eventName].regular.delete(listener);
41
- this.events[eventName].highPriority.delete(listener);
42
- }
43
- }
44
- removeAllListeners() {
45
- this.events = {};
46
- }
47
- emit(eventName, ...args) {
48
- const collection = this.events[eventName];
49
- if (!collection) {
50
- return;
51
- }
52
- const highPriorityListeners = Array.from(collection.highPriority.keys());
53
- const regularListeners = Array.from(collection.regular.keys());
54
- for (let i = highPriorityListeners.length - 1; i >= 0; i -= 1) {
55
- const listener = highPriorityListeners[i];
56
- if (collection.highPriority.has(listener)) {
57
- listener.apply(this, args);
58
- }
59
- }
60
- for (let i = 0; i < regularListeners.length; i += 1) {
61
- const listener = regularListeners[i];
62
- if (collection.regular.has(listener)) {
63
- listener.apply(this, args);
64
- }
65
- }
66
- }
67
- once(eventName, listener) {
68
- // eslint-disable-next-line consistent-this
69
- const that = this;
70
- this.on(eventName, function oneTimeListener(...args) {
71
- that.removeListener(eventName, oneTimeListener);
72
- listener.apply(that, args);
73
- });
74
- }
75
- }
76
- exports.EventManager = EventManager;