@mui/x-tree-view 7.0.0-beta.4 → 7.0.0-beta.5
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 +138 -14
- package/RichTreeView/RichTreeView.js +8 -0
- package/RichTreeView/RichTreeView.types.d.ts +7 -1
- package/SimpleTreeView/SimpleTreeView.js +8 -0
- package/SimpleTreeView/SimpleTreeView.types.d.ts +7 -1
- package/TreeView/TreeView.js +8 -0
- package/hooks/index.d.ts +1 -0
- package/hooks/index.js +1 -0
- package/hooks/package.json +6 -0
- package/hooks/useTreeViewApiRef.d.ts +6 -0
- package/hooks/useTreeViewApiRef.js +5 -0
- package/index.d.ts +1 -0
- package/index.js +3 -2
- package/internals/hooks/useTimeout.d.ts +5 -3
- package/internals/hooks/useTimeout.js +13 -5
- package/internals/models/helpers.d.ts +1 -0
- package/internals/models/plugin.d.ts +12 -0
- package/internals/models/treeView.d.ts +1 -0
- package/internals/plugins/useTreeViewFocus/useTreeViewFocus.js +40 -22
- package/internals/plugins/useTreeViewFocus/useTreeViewFocus.types.d.ts +5 -0
- package/internals/useTreeView/useTreeView.d.ts +2 -0
- package/internals/useTreeView/useTreeView.js +12 -0
- package/internals/useTreeView/useTreeView.types.d.ts +2 -1
- package/internals/useTreeView/useTreeView.utils.d.ts +2 -1
- package/internals/useTreeView/useTreeView.utils.js +3 -0
- package/internals/utils/extractPluginParamsFromProps.d.ts +3 -2
- package/internals/utils/extractPluginParamsFromProps.js +5 -3
- package/internals/utils/utils.d.ts +1 -0
- package/internals/utils/utils.js +10 -0
- package/modern/RichTreeView/RichTreeView.js +8 -0
- package/modern/SimpleTreeView/SimpleTreeView.js +8 -0
- package/modern/TreeView/TreeView.js +8 -0
- package/modern/hooks/index.js +1 -0
- package/modern/hooks/useTreeViewApiRef.js +5 -0
- package/modern/index.js +3 -2
- package/modern/internals/hooks/useTimeout.js +13 -5
- package/modern/internals/plugins/useTreeViewFocus/useTreeViewFocus.js +40 -22
- package/modern/internals/useTreeView/useTreeView.js +12 -0
- package/modern/internals/useTreeView/useTreeView.utils.js +3 -0
- package/modern/internals/utils/extractPluginParamsFromProps.js +5 -3
- package/modern/internals/utils/utils.js +10 -0
- package/node/RichTreeView/RichTreeView.js +8 -0
- package/node/SimpleTreeView/SimpleTreeView.js +8 -0
- package/node/TreeView/TreeView.js +8 -0
- package/node/hooks/index.js +12 -0
- package/node/hooks/useTreeViewApiRef.js +14 -0
- package/node/index.js +13 -1
- package/node/internals/hooks/useTimeout.js +13 -4
- package/node/internals/plugins/useTreeViewFocus/useTreeViewFocus.js +39 -21
- package/node/internals/useTreeView/useTreeView.js +13 -0
- package/node/internals/useTreeView/useTreeView.utils.js +6 -2
- package/node/internals/utils/extractPluginParamsFromProps.js +5 -3
- package/node/internals/utils/utils.js +17 -0
- package/package.json +1 -1
|
@@ -3,6 +3,16 @@ import * as React from 'react';
|
|
|
3
3
|
import useForkRef from '@mui/utils/useForkRef';
|
|
4
4
|
import { useTreeViewModels } from './useTreeViewModels';
|
|
5
5
|
import { TREE_VIEW_CORE_PLUGINS } from '../corePlugins';
|
|
6
|
+
export function useTreeViewApiInitialization(inputApiRef) {
|
|
7
|
+
const fallbackPublicApiRef = React.useRef({});
|
|
8
|
+
if (inputApiRef) {
|
|
9
|
+
if (inputApiRef.current == null) {
|
|
10
|
+
inputApiRef.current = {};
|
|
11
|
+
}
|
|
12
|
+
return inputApiRef.current;
|
|
13
|
+
}
|
|
14
|
+
return fallbackPublicApiRef.current;
|
|
15
|
+
}
|
|
6
16
|
export const useTreeView = inParams => {
|
|
7
17
|
const plugins = [...TREE_VIEW_CORE_PLUGINS, ...inParams.plugins];
|
|
8
18
|
const params = plugins.reduce((acc, plugin) => {
|
|
@@ -14,6 +24,7 @@ export const useTreeView = inParams => {
|
|
|
14
24
|
const models = useTreeViewModels(plugins, params);
|
|
15
25
|
const instanceRef = React.useRef({});
|
|
16
26
|
const instance = instanceRef.current;
|
|
27
|
+
const publicAPI = useTreeViewApiInitialization(inParams.apiRef);
|
|
17
28
|
const innerRootRef = React.useRef(null);
|
|
18
29
|
const handleRootRef = useForkRef(innerRootRef, inParams.rootRef);
|
|
19
30
|
const [state, setState] = React.useState(() => {
|
|
@@ -32,6 +43,7 @@ export const useTreeView = inParams => {
|
|
|
32
43
|
const runPlugin = plugin => {
|
|
33
44
|
const pluginResponse = plugin({
|
|
34
45
|
instance,
|
|
46
|
+
publicAPI,
|
|
35
47
|
params,
|
|
36
48
|
slots: params.slots,
|
|
37
49
|
slotProps: params.slotProps,
|
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
import * as React from 'react';
|
|
2
2
|
import { EventHandlers } from '@mui/base/utils';
|
|
3
3
|
import type { TreeViewContextValue } from '../TreeViewProvider';
|
|
4
|
-
import { TreeViewAnyPluginSignature, TreeViewPlugin, ConvertPluginsIntoSignatures, MergePluginsProperty, TreeViewInstance } from '../models';
|
|
4
|
+
import { TreeViewAnyPluginSignature, TreeViewPlugin, ConvertPluginsIntoSignatures, MergePluginsProperty, TreeViewInstance, TreeViewPublicAPI } from '../models';
|
|
5
5
|
export type UseTreeViewParameters<TPlugins extends readonly TreeViewPlugin<TreeViewAnyPluginSignature>[]> = UseTreeViewBaseParameters<TPlugins> & MergePluginsProperty<ConvertPluginsIntoSignatures<TPlugins>, 'params'>;
|
|
6
6
|
export interface UseTreeViewBaseParameters<TPlugins extends readonly TreeViewPlugin<TreeViewAnyPluginSignature>[]> {
|
|
7
|
+
apiRef: React.MutableRefObject<TreeViewPublicAPI<ConvertPluginsIntoSignatures<TPlugins>>> | undefined;
|
|
7
8
|
rootRef?: React.Ref<HTMLUListElement> | undefined;
|
|
8
9
|
plugins: TPlugins;
|
|
9
10
|
slots: MergePluginsProperty<ConvertPluginsIntoSignatures<TPlugins>, 'slots'>;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { TreeViewAnyPluginSignature, TreeViewInstance, TreeViewUsedInstance } from '../models';
|
|
1
|
+
import { TreeViewAnyPluginSignature, TreeViewInstance, TreeViewUsedInstance, TreeViewUsedPublicAPI } from '../models';
|
|
2
2
|
import type { UseTreeViewExpansionSignature } from '../plugins/useTreeViewExpansion';
|
|
3
3
|
import type { UseTreeViewNodesSignature } from '../plugins/useTreeViewNodes';
|
|
4
4
|
export declare const getPreviousNode: (instance: TreeViewInstance<[UseTreeViewNodesSignature, UseTreeViewExpansionSignature]>, nodeId: string) => string | null;
|
|
@@ -6,3 +6,4 @@ export declare const getNextNode: (instance: TreeViewInstance<[UseTreeViewExpans
|
|
|
6
6
|
export declare const getLastNode: (instance: TreeViewInstance<[UseTreeViewExpansionSignature, UseTreeViewNodesSignature]>) => string;
|
|
7
7
|
export declare const getFirstNode: (instance: TreeViewInstance<[UseTreeViewNodesSignature]>) => string;
|
|
8
8
|
export declare const populateInstance: <T extends TreeViewAnyPluginSignature>(instance: TreeViewUsedInstance<T>, methods: T["instance"]) => void;
|
|
9
|
+
export declare const populatePublicAPI: <T extends TreeViewAnyPluginSignature>(publicAPI: TreeViewUsedPublicAPI<T>, methods: T["publicAPI"]) => void;
|
|
@@ -40,4 +40,7 @@ export const getLastNode = instance => {
|
|
|
40
40
|
export const getFirstNode = instance => instance.getNavigableChildrenIds(null)[0];
|
|
41
41
|
export const populateInstance = (instance, methods) => {
|
|
42
42
|
Object.assign(instance, methods);
|
|
43
|
+
};
|
|
44
|
+
export const populatePublicAPI = (publicAPI, methods) => {
|
|
45
|
+
Object.assign(publicAPI, methods);
|
|
43
46
|
};
|
|
@@ -1,10 +1,11 @@
|
|
|
1
1
|
import * as React from 'react';
|
|
2
|
-
import { ConvertPluginsIntoSignatures, MergePluginsProperty, TreeViewPlugin } from '../models';
|
|
2
|
+
import { ConvertPluginsIntoSignatures, MergePluginsProperty, TreeViewPlugin, TreeViewPublicAPI } from '../models';
|
|
3
3
|
import { UseTreeViewBaseParameters } from '../useTreeView/useTreeView.types';
|
|
4
4
|
export declare const extractPluginParamsFromProps: <TPlugins extends readonly TreeViewPlugin<any>[], TSlots extends MergePluginsProperty<TPlugins, "slots">, TSlotProps extends MergePluginsProperty<TPlugins, "slotProps">, TProps extends {
|
|
5
5
|
slots?: TSlots | undefined;
|
|
6
6
|
slotProps?: TSlotProps | undefined;
|
|
7
|
-
|
|
7
|
+
apiRef?: React.MutableRefObject<TreeViewPublicAPI<ConvertPluginsIntoSignatures<TPlugins>> | undefined> | undefined;
|
|
8
|
+
}>({ props: { slots, slotProps, apiRef, ...props }, plugins, rootRef, }: {
|
|
8
9
|
props: TProps;
|
|
9
10
|
plugins: TPlugins;
|
|
10
11
|
rootRef?: React.Ref<HTMLUListElement> | undefined;
|
|
@@ -1,10 +1,11 @@
|
|
|
1
1
|
import _objectWithoutPropertiesLoose from "@babel/runtime/helpers/esm/objectWithoutPropertiesLoose";
|
|
2
|
-
const _excluded = ["slots", "slotProps"];
|
|
2
|
+
const _excluded = ["slots", "slotProps", "apiRef"];
|
|
3
3
|
export const extractPluginParamsFromProps = _ref => {
|
|
4
4
|
let {
|
|
5
5
|
props: {
|
|
6
6
|
slots,
|
|
7
|
-
slotProps
|
|
7
|
+
slotProps,
|
|
8
|
+
apiRef
|
|
8
9
|
},
|
|
9
10
|
plugins,
|
|
10
11
|
rootRef
|
|
@@ -18,7 +19,8 @@ export const extractPluginParamsFromProps = _ref => {
|
|
|
18
19
|
plugins,
|
|
19
20
|
rootRef,
|
|
20
21
|
slots: slots != null ? slots : {},
|
|
21
|
-
slotProps: slotProps != null ? slotProps : {}
|
|
22
|
+
slotProps: slotProps != null ? slotProps : {},
|
|
23
|
+
apiRef
|
|
22
24
|
};
|
|
23
25
|
const otherProps = {};
|
|
24
26
|
Object.keys(props).forEach(propName => {
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const getActiveElement: (root?: Document | ShadowRoot) => Element | null;
|
|
@@ -132,6 +132,14 @@ process.env.NODE_ENV !== "production" ? RichTreeView.propTypes = {
|
|
|
132
132
|
// | These PropTypes are generated from the TypeScript type definitions |
|
|
133
133
|
// | To update them edit the TypeScript types and run "yarn proptypes" |
|
|
134
134
|
// ----------------------------------------------------------------------
|
|
135
|
+
/**
|
|
136
|
+
* The ref object that allows Tree View manipulation. Can be instantiated with `useTreeViewApiRef()`.
|
|
137
|
+
*/
|
|
138
|
+
apiRef: PropTypes.shape({
|
|
139
|
+
current: PropTypes.shape({
|
|
140
|
+
focusNode: PropTypes.func.isRequired
|
|
141
|
+
})
|
|
142
|
+
}),
|
|
135
143
|
/**
|
|
136
144
|
* Override or extend the styles applied to the component.
|
|
137
145
|
*/
|
|
@@ -90,6 +90,14 @@ process.env.NODE_ENV !== "production" ? SimpleTreeView.propTypes = {
|
|
|
90
90
|
// | These PropTypes are generated from the TypeScript type definitions |
|
|
91
91
|
// | To update them edit the TypeScript types and run "yarn proptypes" |
|
|
92
92
|
// ----------------------------------------------------------------------
|
|
93
|
+
/**
|
|
94
|
+
* The ref object that allows Tree View manipulation. Can be instantiated with `useTreeViewApiRef()`.
|
|
95
|
+
*/
|
|
96
|
+
apiRef: PropTypes.shape({
|
|
97
|
+
current: PropTypes.shape({
|
|
98
|
+
focusNode: PropTypes.func.isRequired
|
|
99
|
+
})
|
|
100
|
+
}),
|
|
93
101
|
/**
|
|
94
102
|
* The content of the component.
|
|
95
103
|
*/
|
|
@@ -64,6 +64,14 @@ process.env.NODE_ENV !== "production" ? TreeView.propTypes = {
|
|
|
64
64
|
// | These PropTypes are generated from the TypeScript type definitions |
|
|
65
65
|
// | To update them edit the TypeScript types and run "yarn proptypes" |
|
|
66
66
|
// ----------------------------------------------------------------------
|
|
67
|
+
/**
|
|
68
|
+
* The ref object that allows Tree View manipulation. Can be instantiated with `useTreeViewApiRef()`.
|
|
69
|
+
*/
|
|
70
|
+
apiRef: PropTypes.shape({
|
|
71
|
+
current: PropTypes.shape({
|
|
72
|
+
focusNode: PropTypes.func.isRequired
|
|
73
|
+
})
|
|
74
|
+
}),
|
|
67
75
|
/**
|
|
68
76
|
* The content of the component.
|
|
69
77
|
*/
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { useTreeViewApiRef } from './useTreeViewApiRef';
|
package/modern/index.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* @mui/x-tree-view v7.0.0-beta.
|
|
2
|
+
* @mui/x-tree-view v7.0.0-beta.5
|
|
3
3
|
*
|
|
4
4
|
* @license MIT
|
|
5
5
|
* This source code is licensed under the MIT license found in the
|
|
@@ -11,4 +11,5 @@ export * from './SimpleTreeView';
|
|
|
11
11
|
export * from './RichTreeView';
|
|
12
12
|
export { unstable_resetCleanupTracking } from './internals/hooks/useInstanceEventHandler';
|
|
13
13
|
export * from './models';
|
|
14
|
-
export * from './icons';
|
|
14
|
+
export * from './icons';
|
|
15
|
+
export * from './hooks';
|
|
@@ -1,12 +1,14 @@
|
|
|
1
|
+
'use client';
|
|
2
|
+
|
|
1
3
|
import { useLazyRef } from './useLazyRef';
|
|
2
4
|
import { useOnMount } from './useOnMount';
|
|
3
|
-
class Timeout {
|
|
5
|
+
export class Timeout {
|
|
4
6
|
constructor() {
|
|
5
|
-
this.currentId =
|
|
7
|
+
this.currentId = null;
|
|
6
8
|
this.clear = () => {
|
|
7
|
-
if (this.currentId !==
|
|
9
|
+
if (this.currentId !== null) {
|
|
8
10
|
clearTimeout(this.currentId);
|
|
9
|
-
this.currentId =
|
|
11
|
+
this.currentId = null;
|
|
10
12
|
}
|
|
11
13
|
};
|
|
12
14
|
this.disposeEffect = () => {
|
|
@@ -16,9 +18,15 @@ class Timeout {
|
|
|
16
18
|
static create() {
|
|
17
19
|
return new Timeout();
|
|
18
20
|
}
|
|
21
|
+
/**
|
|
22
|
+
* Executes `fn` after `delay`, clearing any previously scheduled call.
|
|
23
|
+
*/
|
|
19
24
|
start(delay, fn) {
|
|
20
25
|
this.clear();
|
|
21
|
-
this.currentId = setTimeout(
|
|
26
|
+
this.currentId = setTimeout(() => {
|
|
27
|
+
this.currentId = null;
|
|
28
|
+
fn();
|
|
29
|
+
}, delay);
|
|
22
30
|
}
|
|
23
31
|
}
|
|
24
32
|
export function useTimeout() {
|
|
@@ -2,10 +2,12 @@ import _extends from "@babel/runtime/helpers/esm/extends";
|
|
|
2
2
|
import * as React from 'react';
|
|
3
3
|
import useEventCallback from '@mui/utils/useEventCallback';
|
|
4
4
|
import ownerDocument from '@mui/utils/ownerDocument';
|
|
5
|
-
import { populateInstance } from '../../useTreeView/useTreeView.utils';
|
|
5
|
+
import { populateInstance, populatePublicAPI } from '../../useTreeView/useTreeView.utils';
|
|
6
6
|
import { useInstanceEventHandler } from '../../hooks/useInstanceEventHandler';
|
|
7
|
+
import { getActiveElement } from '../../utils/utils';
|
|
7
8
|
export const useTreeViewFocus = ({
|
|
8
9
|
instance,
|
|
10
|
+
publicAPI,
|
|
9
11
|
params,
|
|
10
12
|
state,
|
|
11
13
|
setState,
|
|
@@ -14,19 +16,45 @@ export const useTreeViewFocus = ({
|
|
|
14
16
|
}) => {
|
|
15
17
|
const setFocusedNodeId = useEventCallback(nodeId => {
|
|
16
18
|
const cleanNodeId = typeof nodeId === 'function' ? nodeId(state.focusedNodeId) : nodeId;
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
19
|
+
if (state.focusedNodeId !== cleanNodeId) {
|
|
20
|
+
setState(prevState => _extends({}, prevState, {
|
|
21
|
+
focusedNodeId: cleanNodeId
|
|
22
|
+
}));
|
|
23
|
+
}
|
|
20
24
|
});
|
|
21
|
-
const
|
|
25
|
+
const isTreeViewFocused = React.useCallback(() => !!rootRef.current && rootRef.current === getActiveElement(ownerDocument(rootRef.current)), [rootRef]);
|
|
26
|
+
const isNodeFocused = React.useCallback(nodeId => state.focusedNodeId === nodeId && isTreeViewFocused(), [state.focusedNodeId, isTreeViewFocused]);
|
|
27
|
+
const isNodeVisible = nodeId => {
|
|
28
|
+
const node = instance.getNode(nodeId);
|
|
29
|
+
return node && (node.parentId == null || instance.isNodeExpanded(node.parentId));
|
|
30
|
+
};
|
|
22
31
|
const focusNode = useEventCallback((event, nodeId) => {
|
|
23
|
-
if
|
|
32
|
+
// if we receive a nodeId, and it is visible, the focus will be set to it
|
|
33
|
+
if (nodeId && isNodeVisible(nodeId)) {
|
|
34
|
+
if (!isTreeViewFocused()) {
|
|
35
|
+
instance.focusRoot();
|
|
36
|
+
}
|
|
24
37
|
setFocusedNodeId(nodeId);
|
|
25
38
|
if (params.onNodeFocus) {
|
|
26
39
|
params.onNodeFocus(event, nodeId);
|
|
27
40
|
}
|
|
28
41
|
}
|
|
29
42
|
});
|
|
43
|
+
const focusDefaultNode = useEventCallback(event => {
|
|
44
|
+
let nodeToFocusId;
|
|
45
|
+
if (Array.isArray(models.selectedNodes.value)) {
|
|
46
|
+
nodeToFocusId = models.selectedNodes.value.find(isNodeVisible);
|
|
47
|
+
} else if (models.selectedNodes.value != null && isNodeVisible(models.selectedNodes.value)) {
|
|
48
|
+
nodeToFocusId = models.selectedNodes.value;
|
|
49
|
+
}
|
|
50
|
+
if (nodeToFocusId == null) {
|
|
51
|
+
nodeToFocusId = instance.getNavigableChildrenIds(null)[0];
|
|
52
|
+
}
|
|
53
|
+
setFocusedNodeId(nodeToFocusId);
|
|
54
|
+
if (params.onNodeFocus) {
|
|
55
|
+
params.onNodeFocus(event, nodeToFocusId);
|
|
56
|
+
}
|
|
57
|
+
});
|
|
30
58
|
const focusRoot = useEventCallback(() => {
|
|
31
59
|
rootRef.current?.focus({
|
|
32
60
|
preventScroll: true
|
|
@@ -35,7 +63,11 @@ export const useTreeViewFocus = ({
|
|
|
35
63
|
populateInstance(instance, {
|
|
36
64
|
isNodeFocused,
|
|
37
65
|
focusNode,
|
|
38
|
-
focusRoot
|
|
66
|
+
focusRoot,
|
|
67
|
+
focusDefaultNode
|
|
68
|
+
});
|
|
69
|
+
populatePublicAPI(publicAPI, {
|
|
70
|
+
focusNode
|
|
39
71
|
});
|
|
40
72
|
useInstanceEventHandler(instance, 'removeNode', ({
|
|
41
73
|
id
|
|
@@ -49,23 +81,9 @@ export const useTreeViewFocus = ({
|
|
|
49
81
|
});
|
|
50
82
|
const createHandleFocus = otherHandlers => event => {
|
|
51
83
|
otherHandlers.onFocus?.(event);
|
|
52
|
-
|
|
53
84
|
// if the event bubbled (which is React specific) we don't want to steal focus
|
|
54
85
|
if (event.target === event.currentTarget) {
|
|
55
|
-
|
|
56
|
-
const node = instance.getNode(nodeId);
|
|
57
|
-
return node && (node.parentId == null || instance.isNodeExpanded(node.parentId));
|
|
58
|
-
};
|
|
59
|
-
let nodeToFocusId;
|
|
60
|
-
if (Array.isArray(models.selectedNodes.value)) {
|
|
61
|
-
nodeToFocusId = models.selectedNodes.value.find(isNodeVisible);
|
|
62
|
-
} else if (models.selectedNodes.value != null && isNodeVisible(models.selectedNodes.value)) {
|
|
63
|
-
nodeToFocusId = models.selectedNodes.value;
|
|
64
|
-
}
|
|
65
|
-
if (nodeToFocusId == null) {
|
|
66
|
-
nodeToFocusId = instance.getNavigableChildrenIds(null)[0];
|
|
67
|
-
}
|
|
68
|
-
instance.focusNode(event, nodeToFocusId);
|
|
86
|
+
instance.focusDefaultNode(event);
|
|
69
87
|
}
|
|
70
88
|
};
|
|
71
89
|
const createHandleBlur = otherHandlers => event => {
|
|
@@ -3,6 +3,16 @@ import * as React from 'react';
|
|
|
3
3
|
import useForkRef from '@mui/utils/useForkRef';
|
|
4
4
|
import { useTreeViewModels } from './useTreeViewModels';
|
|
5
5
|
import { TREE_VIEW_CORE_PLUGINS } from '../corePlugins';
|
|
6
|
+
export function useTreeViewApiInitialization(inputApiRef) {
|
|
7
|
+
const fallbackPublicApiRef = React.useRef({});
|
|
8
|
+
if (inputApiRef) {
|
|
9
|
+
if (inputApiRef.current == null) {
|
|
10
|
+
inputApiRef.current = {};
|
|
11
|
+
}
|
|
12
|
+
return inputApiRef.current;
|
|
13
|
+
}
|
|
14
|
+
return fallbackPublicApiRef.current;
|
|
15
|
+
}
|
|
6
16
|
export const useTreeView = inParams => {
|
|
7
17
|
const plugins = [...TREE_VIEW_CORE_PLUGINS, ...inParams.plugins];
|
|
8
18
|
const params = plugins.reduce((acc, plugin) => {
|
|
@@ -14,6 +24,7 @@ export const useTreeView = inParams => {
|
|
|
14
24
|
const models = useTreeViewModels(plugins, params);
|
|
15
25
|
const instanceRef = React.useRef({});
|
|
16
26
|
const instance = instanceRef.current;
|
|
27
|
+
const publicAPI = useTreeViewApiInitialization(inParams.apiRef);
|
|
17
28
|
const innerRootRef = React.useRef(null);
|
|
18
29
|
const handleRootRef = useForkRef(innerRootRef, inParams.rootRef);
|
|
19
30
|
const [state, setState] = React.useState(() => {
|
|
@@ -32,6 +43,7 @@ export const useTreeView = inParams => {
|
|
|
32
43
|
const runPlugin = plugin => {
|
|
33
44
|
const pluginResponse = plugin({
|
|
34
45
|
instance,
|
|
46
|
+
publicAPI,
|
|
35
47
|
params,
|
|
36
48
|
slots: params.slots,
|
|
37
49
|
slotProps: params.slotProps,
|
|
@@ -40,4 +40,7 @@ export const getLastNode = instance => {
|
|
|
40
40
|
export const getFirstNode = instance => instance.getNavigableChildrenIds(null)[0];
|
|
41
41
|
export const populateInstance = (instance, methods) => {
|
|
42
42
|
Object.assign(instance, methods);
|
|
43
|
+
};
|
|
44
|
+
export const populatePublicAPI = (publicAPI, methods) => {
|
|
45
|
+
Object.assign(publicAPI, methods);
|
|
43
46
|
};
|
|
@@ -1,10 +1,11 @@
|
|
|
1
1
|
import _objectWithoutPropertiesLoose from "@babel/runtime/helpers/esm/objectWithoutPropertiesLoose";
|
|
2
|
-
const _excluded = ["slots", "slotProps"];
|
|
2
|
+
const _excluded = ["slots", "slotProps", "apiRef"];
|
|
3
3
|
export const extractPluginParamsFromProps = _ref => {
|
|
4
4
|
let {
|
|
5
5
|
props: {
|
|
6
6
|
slots,
|
|
7
|
-
slotProps
|
|
7
|
+
slotProps,
|
|
8
|
+
apiRef
|
|
8
9
|
},
|
|
9
10
|
plugins,
|
|
10
11
|
rootRef
|
|
@@ -18,7 +19,8 @@ export const extractPluginParamsFromProps = _ref => {
|
|
|
18
19
|
plugins,
|
|
19
20
|
rootRef,
|
|
20
21
|
slots: slots ?? {},
|
|
21
|
-
slotProps: slotProps ?? {}
|
|
22
|
+
slotProps: slotProps ?? {},
|
|
23
|
+
apiRef
|
|
22
24
|
};
|
|
23
25
|
const otherProps = {};
|
|
24
26
|
Object.keys(props).forEach(propName => {
|
|
@@ -141,6 +141,14 @@ process.env.NODE_ENV !== "production" ? RichTreeView.propTypes = {
|
|
|
141
141
|
// | These PropTypes are generated from the TypeScript type definitions |
|
|
142
142
|
// | To update them edit the TypeScript types and run "yarn proptypes" |
|
|
143
143
|
// ----------------------------------------------------------------------
|
|
144
|
+
/**
|
|
145
|
+
* The ref object that allows Tree View manipulation. Can be instantiated with `useTreeViewApiRef()`.
|
|
146
|
+
*/
|
|
147
|
+
apiRef: _propTypes.default.shape({
|
|
148
|
+
current: _propTypes.default.shape({
|
|
149
|
+
focusNode: _propTypes.default.func.isRequired
|
|
150
|
+
})
|
|
151
|
+
}),
|
|
144
152
|
/**
|
|
145
153
|
* Override or extend the styles applied to the component.
|
|
146
154
|
*/
|
|
@@ -99,6 +99,14 @@ process.env.NODE_ENV !== "production" ? SimpleTreeView.propTypes = {
|
|
|
99
99
|
// | These PropTypes are generated from the TypeScript type definitions |
|
|
100
100
|
// | To update them edit the TypeScript types and run "yarn proptypes" |
|
|
101
101
|
// ----------------------------------------------------------------------
|
|
102
|
+
/**
|
|
103
|
+
* The ref object that allows Tree View manipulation. Can be instantiated with `useTreeViewApiRef()`.
|
|
104
|
+
*/
|
|
105
|
+
apiRef: _propTypes.default.shape({
|
|
106
|
+
current: _propTypes.default.shape({
|
|
107
|
+
focusNode: _propTypes.default.func.isRequired
|
|
108
|
+
})
|
|
109
|
+
}),
|
|
102
110
|
/**
|
|
103
111
|
* The content of the component.
|
|
104
112
|
*/
|
|
@@ -73,6 +73,14 @@ process.env.NODE_ENV !== "production" ? TreeView.propTypes = {
|
|
|
73
73
|
// | These PropTypes are generated from the TypeScript type definitions |
|
|
74
74
|
// | To update them edit the TypeScript types and run "yarn proptypes" |
|
|
75
75
|
// ----------------------------------------------------------------------
|
|
76
|
+
/**
|
|
77
|
+
* The ref object that allows Tree View manipulation. Can be instantiated with `useTreeViewApiRef()`.
|
|
78
|
+
*/
|
|
79
|
+
apiRef: _propTypes.default.shape({
|
|
80
|
+
current: _propTypes.default.shape({
|
|
81
|
+
focusNode: _propTypes.default.func.isRequired
|
|
82
|
+
})
|
|
83
|
+
}),
|
|
76
84
|
/**
|
|
77
85
|
* The content of the component.
|
|
78
86
|
*/
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
Object.defineProperty(exports, "useTreeViewApiRef", {
|
|
7
|
+
enumerable: true,
|
|
8
|
+
get: function () {
|
|
9
|
+
return _useTreeViewApiRef.useTreeViewApiRef;
|
|
10
|
+
}
|
|
11
|
+
});
|
|
12
|
+
var _useTreeViewApiRef = require("./useTreeViewApiRef");
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.useTreeViewApiRef = void 0;
|
|
7
|
+
var React = _interopRequireWildcard(require("react"));
|
|
8
|
+
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); }
|
|
9
|
+
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 && Object.prototype.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; }
|
|
10
|
+
/**
|
|
11
|
+
* Hook that instantiates a [[TreeViewApiRef]].
|
|
12
|
+
*/
|
|
13
|
+
const useTreeViewApiRef = () => React.useRef(undefined);
|
|
14
|
+
exports.useTreeViewApiRef = useTreeViewApiRef;
|
package/node/index.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* @mui/x-tree-view v7.0.0-beta.
|
|
2
|
+
* @mui/x-tree-view v7.0.0-beta.5
|
|
3
3
|
*
|
|
4
4
|
* @license MIT
|
|
5
5
|
* This source code is licensed under the MIT license found in the
|
|
@@ -91,4 +91,16 @@ Object.keys(_icons).forEach(function (key) {
|
|
|
91
91
|
return _icons[key];
|
|
92
92
|
}
|
|
93
93
|
});
|
|
94
|
+
});
|
|
95
|
+
var _hooks = require("./hooks");
|
|
96
|
+
Object.keys(_hooks).forEach(function (key) {
|
|
97
|
+
if (key === "default" || key === "__esModule") return;
|
|
98
|
+
if (Object.prototype.hasOwnProperty.call(_exportNames, key)) return;
|
|
99
|
+
if (key in exports && exports[key] === _hooks[key]) return;
|
|
100
|
+
Object.defineProperty(exports, key, {
|
|
101
|
+
enumerable: true,
|
|
102
|
+
get: function () {
|
|
103
|
+
return _hooks[key];
|
|
104
|
+
}
|
|
105
|
+
});
|
|
94
106
|
});
|
|
@@ -1,18 +1,20 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
'use client';
|
|
2
3
|
|
|
3
4
|
Object.defineProperty(exports, "__esModule", {
|
|
4
5
|
value: true
|
|
5
6
|
});
|
|
7
|
+
exports.Timeout = void 0;
|
|
6
8
|
exports.useTimeout = useTimeout;
|
|
7
9
|
var _useLazyRef = require("./useLazyRef");
|
|
8
10
|
var _useOnMount = require("./useOnMount");
|
|
9
11
|
class Timeout {
|
|
10
12
|
constructor() {
|
|
11
|
-
this.currentId =
|
|
13
|
+
this.currentId = null;
|
|
12
14
|
this.clear = () => {
|
|
13
|
-
if (this.currentId !==
|
|
15
|
+
if (this.currentId !== null) {
|
|
14
16
|
clearTimeout(this.currentId);
|
|
15
|
-
this.currentId =
|
|
17
|
+
this.currentId = null;
|
|
16
18
|
}
|
|
17
19
|
};
|
|
18
20
|
this.disposeEffect = () => {
|
|
@@ -22,11 +24,18 @@ class Timeout {
|
|
|
22
24
|
static create() {
|
|
23
25
|
return new Timeout();
|
|
24
26
|
}
|
|
27
|
+
/**
|
|
28
|
+
* Executes `fn` after `delay`, clearing any previously scheduled call.
|
|
29
|
+
*/
|
|
25
30
|
start(delay, fn) {
|
|
26
31
|
this.clear();
|
|
27
|
-
this.currentId = setTimeout(
|
|
32
|
+
this.currentId = setTimeout(() => {
|
|
33
|
+
this.currentId = null;
|
|
34
|
+
fn();
|
|
35
|
+
}, delay);
|
|
28
36
|
}
|
|
29
37
|
}
|
|
38
|
+
exports.Timeout = Timeout;
|
|
30
39
|
function useTimeout() {
|
|
31
40
|
const timeout = (0, _useLazyRef.useLazyRef)(Timeout.create).current;
|
|
32
41
|
(0, _useOnMount.useOnMount)(timeout.disposeEffect);
|