Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[TreeView] Move useTreeViewId to the core plugins #13566

Merged
merged 1 commit into from
Jun 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
import {
useTreeViewId,
UseTreeViewIdParameters,
useTreeViewItems,
UseTreeViewItemsParameters,
useTreeViewExpansion,
Expand All @@ -14,10 +12,10 @@ import {
UseTreeViewIconsParameters,
ConvertPluginsIntoSignatures,
MergeSignaturesProperty,
TreeViewCorePluginParameters,
} from '@mui/x-tree-view/internals';

export const RICH_TREE_VIEW_PRO_PLUGINS = [
useTreeViewId,
useTreeViewItems,
useTreeViewExpansion,
useTreeViewSelection,
Expand All @@ -42,7 +40,7 @@ export type RichTreeViewProPluginSlotProps = MergeSignaturesProperty<

// We can't infer this type from the plugin, otherwise we would lose the generics.
export interface RichTreeViewProPluginParameters<R extends {}, Multiple extends boolean | undefined>
extends UseTreeViewIdParameters,
extends TreeViewCorePluginParameters,
UseTreeViewItemsParameters<R>,
UseTreeViewExpansionParameters,
UseTreeViewFocusParameters,
Expand Down
5 changes: 2 additions & 3 deletions packages/x-tree-view/src/RichTreeView/RichTreeView.plugins.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { useTreeViewId, UseTreeViewIdParameters } from '../internals/plugins/useTreeViewId';
import { TreeViewCorePluginParameters } from '../internals/corePlugins';
import {
useTreeViewItems,
UseTreeViewItemsParameters,
Expand All @@ -23,7 +23,6 @@ import {
import { ConvertPluginsIntoSignatures, MergeSignaturesProperty } from '../internals/models';

export const RICH_TREE_VIEW_PLUGINS = [
useTreeViewId,
useTreeViewItems,
useTreeViewExpansion,
useTreeViewSelection,
Expand All @@ -48,7 +47,7 @@ export type RichTreeViewPluginSlotProps = MergeSignaturesProperty<

// We can't infer this type from the plugin, otherwise we would lose the generics.
export interface RichTreeViewPluginParameters<R extends {}, Multiple extends boolean | undefined>
extends UseTreeViewIdParameters,
extends TreeViewCorePluginParameters,
UseTreeViewItemsParameters<R>,
UseTreeViewExpansionParameters,
UseTreeViewFocusParameters,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { useTreeViewId, UseTreeViewIdParameters } from '../internals/plugins/useTreeViewId';
import { TreeViewCorePluginParameters } from '../internals/corePlugins';
import {
useTreeViewItems,
UseTreeViewItemsParameters,
Expand All @@ -24,7 +24,6 @@ import { useTreeViewJSXItems } from '../internals/plugins/useTreeViewJSXItems';
import { ConvertPluginsIntoSignatures, MergeSignaturesProperty } from '../internals/models';

export const SIMPLE_TREE_VIEW_PLUGINS = [
useTreeViewId,
useTreeViewItems,
useTreeViewExpansion,
useTreeViewSelection,
Expand All @@ -50,7 +49,7 @@ export type SimpleTreeViewPluginSlotProps = MergeSignaturesProperty<

// We can't infer this type from the plugin, otherwise we would lose the generics.
export interface SimpleTreeViewPluginParameters<Multiple extends boolean | undefined>
extends UseTreeViewIdParameters,
extends TreeViewCorePluginParameters,
Omit<
UseTreeViewItemsParameters<any>,
'items' | 'isItemDisabled' | 'getItemLabel' | 'getItemId'
Expand Down
2 changes: 0 additions & 2 deletions packages/x-tree-view/src/TreeItem/TreeItem.types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ import { UseTreeViewItemsSignature } from '../internals/plugins/useTreeViewItems
import { UseTreeViewFocusSignature } from '../internals/plugins/useTreeViewFocus';
import { UseTreeViewExpansionSignature } from '../internals/plugins/useTreeViewExpansion';
import { UseTreeViewKeyboardNavigationSignature } from '../internals/plugins/useTreeViewKeyboardNavigation';
import { UseTreeViewIdSignature } from '../internals/plugins/useTreeViewId';

export interface TreeItemSlots {
/**
Expand Down Expand Up @@ -123,7 +122,6 @@ export type TreeItemMinimalPlugins = readonly [
UseTreeViewFocusSignature,
UseTreeViewExpansionSignature,
UseTreeViewKeyboardNavigationSignature,
UseTreeViewIdSignature,
];

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import { useTreeViewContext } from './useTreeViewContext';
import { escapeOperandAttributeSelector } from '../utils/utils';
import type { UseTreeViewJSXItemsSignature } from '../plugins/useTreeViewJSXItems';
import type { UseTreeViewItemsSignature } from '../plugins/useTreeViewItems';
import type { UseTreeViewIdSignature } from '../plugins/useTreeViewId';

export const TreeViewChildrenItemContext =
React.createContext<TreeViewChildrenItemContextValue | null>(null);
Expand All @@ -22,9 +21,7 @@ export function TreeViewChildrenItemProvider(props: TreeViewChildrenItemProvider
const { children, itemId = null } = props;

const { instance, rootRef } =
useTreeViewContext<
[UseTreeViewJSXItemsSignature, UseTreeViewItemsSignature, UseTreeViewIdSignature]
>();
useTreeViewContext<[UseTreeViewJSXItemsSignature, UseTreeViewItemsSignature]>();
const childrenIdAttrToIdRef = React.useRef<Map<string, string>>(new Map());

React.useEffect(() => {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,15 @@
import { useTreeViewInstanceEvents } from './useTreeViewInstanceEvents';
import { useTreeViewId, UseTreeViewIdParameters } from './useTreeViewId';
import { ConvertPluginsIntoSignatures } from '../models';

/**
* Internal plugins that create the tools used by the other plugins.
* These plugins are used by the tree view components.
*/
export const TREE_VIEW_CORE_PLUGINS = [useTreeViewInstanceEvents] as const;
export const TREE_VIEW_CORE_PLUGINS = [useTreeViewInstanceEvents, useTreeViewId] as const;

export type TreeViewCorePluginSignatures = ConvertPluginsIntoSignatures<
typeof TREE_VIEW_CORE_PLUGINS
>;

export interface TreeViewCorePluginParameters extends UseTreeViewIdParameters {}
2 changes: 1 addition & 1 deletion packages/x-tree-view/src/internals/corePlugins/index.ts
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
export { TREE_VIEW_CORE_PLUGINS } from './corePlugins';
export type { TreeViewCorePluginSignatures } from './corePlugins';
export type { TreeViewCorePluginSignatures, TreeViewCorePluginParameters } from './corePlugins';
5 changes: 3 additions & 2 deletions packages/x-tree-view/src/internals/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@ export type {
TreeViewExperimentalFeatures,
} from './models';

// Core plugins
export type { TreeViewCorePluginParameters } from './corePlugins';

// Plugins
export { useTreeViewExpansion } from './plugins/useTreeViewExpansion';
export type {
Expand All @@ -30,8 +33,6 @@ export type {
} from './plugins/useTreeViewFocus';
export { useTreeViewKeyboardNavigation } from './plugins/useTreeViewKeyboardNavigation';
export type { UseTreeViewKeyboardNavigationSignature } from './plugins/useTreeViewKeyboardNavigation';
export { useTreeViewId } from './plugins/useTreeViewId';
export type { UseTreeViewIdSignature, UseTreeViewIdParameters } from './plugins/useTreeViewId';
export { useTreeViewIcons } from './plugins/useTreeViewIcons';
export type {
UseTreeViewIconsSignature,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import * as React from 'react';
import { TreeViewPluginSignature } from '../../models';
import { UseTreeViewIdSignature } from '../useTreeViewId/useTreeViewId.types';
import type { UseTreeViewItemsSignature } from '../useTreeViewItems';
import type { UseTreeViewSelectionSignature } from '../useTreeViewSelection';
import { UseTreeViewExpansionSignature } from '../useTreeViewExpansion';
Expand Down Expand Up @@ -62,7 +61,6 @@ export type UseTreeViewFocusSignature = TreeViewPluginSignature<{
publicAPI: UseTreeViewFocusPublicAPI;
state: UseTreeViewFocusState;
dependencies: [
UseTreeViewIdSignature,
UseTreeViewItemsSignature,
UseTreeViewSelectionSignature,
UseTreeViewExpansionSignature,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ import {
} from '../useTreeViewItems/useTreeViewItems.utils';
import type { TreeItemProps } from '../../../TreeItem';
import type { TreeItem2Props } from '../../../TreeItem2';
import { UseTreeViewIdSignature } from '../useTreeViewId';
import { TreeViewItemDepthContext } from '../../TreeViewItemDepthContext';

export const useTreeViewJSXItems: TreeViewPlugin<UseTreeViewJSXItemsSignature> = ({
Expand Down Expand Up @@ -122,7 +121,7 @@ const useTreeViewJSXItemsItemPlugin: TreeViewItemPlugin<TreeItemProps | TreeItem
rootRef,
contentRef,
}) => {
const { instance } = useTreeViewContext<[UseTreeViewIdSignature, UseTreeViewJSXItemsSignature]>();
const { instance } = useTreeViewContext<[UseTreeViewJSXItemsSignature]>();
const { children, disabled = false, label, itemId, id } = props;

const parentContext = React.useContext(TreeViewChildrenItemContext);
Expand Down
2 changes: 0 additions & 2 deletions packages/x-tree-view/src/useTreeItem2/useTreeItem2.types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import { MuiCancellableEventHandler } from '../internals/models/MuiCancellableEv
import { TreeViewPublicAPI } from '../internals/models';
import { UseTreeViewSelectionSignature } from '../internals/plugins/useTreeViewSelection';
import { UseTreeViewItemsSignature } from '../internals/plugins/useTreeViewItems';
import { UseTreeViewIdSignature } from '../internals/plugins/useTreeViewId';
import { UseTreeViewFocusSignature } from '../internals/plugins/useTreeViewFocus';
import { UseTreeViewKeyboardNavigationSignature } from '../internals/plugins/useTreeViewKeyboardNavigation';

Expand Down Expand Up @@ -187,7 +186,6 @@ export interface UseTreeItem2ReturnValue<
export type UseTreeItem2MinimalPlugins = readonly [
UseTreeViewSelectionSignature,
UseTreeViewItemsSignature,
UseTreeViewIdSignature,
UseTreeViewFocusSignature,
UseTreeViewKeyboardNavigationSignature,
];
Expand Down
Loading