From 6f68422160d85f83df96e6c4fd9be55a858faea6 Mon Sep 17 00:00:00 2001 From: Flavien DELANGLE Date: Wed, 19 Jun 2024 08:36:28 +0200 Subject: [PATCH] [TreeView] Improve typing to support optional dependencies in plugins and in the item (#13523) --- .../headless/LogExpandedItems.tsx | 2 +- .../rich-tree-view/headless/headless.md | 4 +- .../x-tree-view/src/TreeItem/TreeItem.tsx | 9 +++- .../src/TreeItem/TreeItem.types.ts | 8 +++ .../src/TreeItem/useTreeItemState.ts | 4 +- .../useTreeItem2Utils/useTreeItem2Utils.tsx | 10 +++- .../TreeViewProvider.types.ts | 11 ++-- .../TreeViewProvider/useTreeViewContext.ts | 10 +++- .../src/internals/models/plugin.ts | 54 +++++++++++-------- .../src/internals/models/treeView.ts | 14 +++-- .../useTreeViewExpansion.types.ts | 2 +- .../useTreeViewFocus.types.ts | 2 +- .../useTreeViewIcons.types.ts | 2 +- .../useTreeViewJSXItems.types.ts | 2 +- .../useTreeViewKeyboardNavigation.types.ts | 2 +- .../useTreeViewSelection.types.ts | 2 +- .../src/useTreeItem2/useTreeItem2.ts | 6 ++- .../src/useTreeItem2/useTreeItem2.types.ts | 15 ++++-- 18 files changed, 109 insertions(+), 50 deletions(-) diff --git a/docs/data/tree-view/rich-tree-view/headless/LogExpandedItems.tsx b/docs/data/tree-view/rich-tree-view/headless/LogExpandedItems.tsx index 7a45a2b3e0cd..70285558cbb9 100644 --- a/docs/data/tree-view/rich-tree-view/headless/LogExpandedItems.tsx +++ b/docs/data/tree-view/rich-tree-view/headless/LogExpandedItems.tsx @@ -37,7 +37,7 @@ type TreeViewLogExpandedSignature = TreeViewPluginSignature<{ // The parameters of this plugin as they are passed to the plugin after calling `plugin.getDefaultizedParams` defaultizedParams: TreeViewLogExpandedDefaultizedParameters; // Dependencies of this plugin (we need the expansion plugin to access its model) - dependantPlugins: [UseTreeViewExpansionSignature]; + dependencies: [UseTreeViewExpansionSignature]; }>; const useTreeViewLogExpanded: TreeViewPlugin = ({ diff --git a/docs/data/tree-view/rich-tree-view/headless/headless.md b/docs/data/tree-view/rich-tree-view/headless/headless.md index 86ca7bfccbc5..6afb2d8403a0 100644 --- a/docs/data/tree-view/rich-tree-view/headless/headless.md +++ b/docs/data/tree-view/rich-tree-view/headless/headless.md @@ -283,7 +283,7 @@ type UseCustomPluginSignature = TreeViewPluginSignature<{ // The name of the models defined by your plugin modelNames: UseCustomPluginModelNames; // The plugins this plugin needs to work correctly - dependantPlugins: UseCustomPluginDependantPlugins; + dependencies: UseCustomPluginDependantPlugins; }>; ``` @@ -317,7 +317,7 @@ type UseCustomPluginSignature = TreeViewPluginSignature<{ contextValue: { customPlugin: { enabled: boolean } }; modelNames: 'customModel'; // We want to have access to the expansion models and methods of the expansion plugin. - dependantPlugins: [UseTreeViewExpansionSignature]; + dependencies: [UseTreeViewExpansionSignature]; }>; ``` diff --git a/packages/x-tree-view/src/TreeItem/TreeItem.tsx b/packages/x-tree-view/src/TreeItem/TreeItem.tsx index f4224825ec58..2f35d8974905 100644 --- a/packages/x-tree-view/src/TreeItem/TreeItem.tsx +++ b/packages/x-tree-view/src/TreeItem/TreeItem.tsx @@ -13,7 +13,12 @@ import { unstable_composeClasses as composeClasses } from '@mui/base'; import { styled, createUseThemeProps } from '../internals/zero-styled'; import { TreeItemContent } from './TreeItemContent'; import { treeItemClasses, getTreeItemUtilityClass } from './treeItemClasses'; -import { TreeItemMinimalPlugins, TreeItemOwnerState, TreeItemProps } from './TreeItem.types'; +import { + TreeItemMinimalPlugins, + TreeItemOptionalPlugins, + TreeItemOwnerState, + TreeItemProps, +} from './TreeItem.types'; import { useTreeViewContext } from '../internals/TreeViewProvider/useTreeViewContext'; import { TreeViewCollapseIcon, TreeViewExpandIcon } from '../icons'; import { TreeItem2Provider } from '../TreeItem2Provider'; @@ -185,7 +190,7 @@ export const TreeItem = React.forwardRef(function TreeItem( disabledItemsFocusable, indentationAtItemLevel, instance, - } = useTreeViewContext(); + } = useTreeViewContext(); const depthContext = React.useContext(TreeViewItemDepthContext); const props = useThemeProps({ props: inProps, name: 'MuiTreeItem' }); diff --git a/packages/x-tree-view/src/TreeItem/TreeItem.types.ts b/packages/x-tree-view/src/TreeItem/TreeItem.types.ts index 54df7cbef8da..c0554c4e4c80 100644 --- a/packages/x-tree-view/src/TreeItem/TreeItem.types.ts +++ b/packages/x-tree-view/src/TreeItem/TreeItem.types.ts @@ -113,6 +113,9 @@ export interface TreeItemOwnerState extends TreeItemProps { indentationAtItemLevel: boolean; } +/** + * Plugins that need to be present in the Tree View in order for `TreeItem` to work correctly. + */ export type TreeItemMinimalPlugins = readonly [ UseTreeViewIconsSignature, UseTreeViewSelectionSignature, @@ -122,3 +125,8 @@ export type TreeItemMinimalPlugins = readonly [ UseTreeViewKeyboardNavigationSignature, UseTreeViewIdSignature, ]; + +/** + * Plugins that `TreeItem` can use if they are present, but are not required. + */ +export type TreeItemOptionalPlugins = readonly []; diff --git a/packages/x-tree-view/src/TreeItem/useTreeItemState.ts b/packages/x-tree-view/src/TreeItem/useTreeItemState.ts index fea40a777a0f..09f9ce6f88c2 100644 --- a/packages/x-tree-view/src/TreeItem/useTreeItemState.ts +++ b/packages/x-tree-view/src/TreeItem/useTreeItemState.ts @@ -12,11 +12,13 @@ type UseTreeItemStateMinimalPlugins = readonly [ UseTreeViewItemsSignature, ]; +type UseTreeItemStateOptionalPlugins = readonly []; + export function useTreeItemState(itemId: string) { const { instance, selection: { multiSelect, checkboxSelection, disableSelection }, - } = useTreeViewContext(); + } = useTreeViewContext(); const expandable = instance.isItemExpandable(itemId); const expanded = instance.isItemExpanded(itemId); diff --git a/packages/x-tree-view/src/hooks/useTreeItem2Utils/useTreeItem2Utils.tsx b/packages/x-tree-view/src/hooks/useTreeItem2Utils/useTreeItem2Utils.tsx index 09e188c73e75..81e0f169559c 100644 --- a/packages/x-tree-view/src/hooks/useTreeItem2Utils/useTreeItem2Utils.tsx +++ b/packages/x-tree-view/src/hooks/useTreeItem2Utils/useTreeItem2Utils.tsx @@ -24,6 +24,9 @@ const isItemExpandable = (reactChildren: React.ReactNode) => { return Boolean(reactChildren); }; +/** + * Plugins that need to be present in the Tree View in order for `useTreeItem2Utils` to work correctly. + */ type UseTreeItem2UtilsMinimalPlugins = readonly [ UseTreeViewSelectionSignature, UseTreeViewExpansionSignature, @@ -31,6 +34,11 @@ type UseTreeItem2UtilsMinimalPlugins = readonly [ UseTreeViewFocusSignature, ]; +/** + * Plugins that `useTreeItem2Utils` can use if they are present, but are not required. + */ +export type UseTreeItem2UtilsOptionalPlugins = readonly []; + export const useTreeItem2Utils = ({ itemId, children, @@ -41,7 +49,7 @@ export const useTreeItem2Utils = ({ const { instance, selection: { multiSelect }, - } = useTreeViewContext(); + } = useTreeViewContext(); const status: UseTreeItem2Status = { expandable: isItemExpandable(children), diff --git a/packages/x-tree-view/src/internals/TreeViewProvider/TreeViewProvider.types.ts b/packages/x-tree-view/src/internals/TreeViewProvider/TreeViewProvider.types.ts index f0af466f0f21..b60339cc5913 100644 --- a/packages/x-tree-view/src/internals/TreeViewProvider/TreeViewProvider.types.ts +++ b/packages/x-tree-view/src/internals/TreeViewProvider/TreeViewProvider.types.ts @@ -13,10 +13,13 @@ export type TreeViewItemPluginsRunner = ( props: TProps, ) => Required; -export type TreeViewContextValue = - MergeSignaturesProperty & { - instance: TreeViewInstance; - publicAPI: TreeViewPublicAPI; +export type TreeViewContextValue< + TSignatures extends readonly TreeViewAnyPluginSignature[], + TOptionalSignatures extends readonly TreeViewAnyPluginSignature[] = [], +> = MergeSignaturesProperty & + Partial> & { + instance: TreeViewInstance; + publicAPI: TreeViewPublicAPI; rootRef: React.RefObject; wrapItem: TreeItemWrapper; wrapRoot: TreeRootWrapper; diff --git a/packages/x-tree-view/src/internals/TreeViewProvider/useTreeViewContext.ts b/packages/x-tree-view/src/internals/TreeViewProvider/useTreeViewContext.ts index 62fbce3ad739..ee7c8e7ff9ff 100644 --- a/packages/x-tree-view/src/internals/TreeViewProvider/useTreeViewContext.ts +++ b/packages/x-tree-view/src/internals/TreeViewProvider/useTreeViewContext.ts @@ -3,8 +3,14 @@ import { TreeViewAnyPluginSignature } from '../models'; import { TreeViewContext } from './TreeViewContext'; import { TreeViewContextValue } from './TreeViewProvider.types'; -export const useTreeViewContext = () => { - const context = React.useContext(TreeViewContext) as TreeViewContextValue; +export const useTreeViewContext = < + TSignatures extends readonly TreeViewAnyPluginSignature[], + TOptionalSignatures extends readonly TreeViewAnyPluginSignature[] = [], +>() => { + const context = React.useContext(TreeViewContext) as TreeViewContextValue< + TSignatures, + TOptionalSignatures + >; if (context == null) { throw new Error( [ diff --git a/packages/x-tree-view/src/internals/models/plugin.ts b/packages/x-tree-view/src/internals/models/plugin.ts index fd26dd4c42d7..b9459acecf93 100644 --- a/packages/x-tree-view/src/internals/models/plugin.ts +++ b/packages/x-tree-view/src/internals/models/plugin.ts @@ -47,7 +47,8 @@ export type TreeViewPluginSignature< slotProps?: { [key in keyof T['slotProps']]: {} | (() => {}) }; modelNames?: keyof T['defaultizedParams']; experimentalFeatures?: string; - dependantPlugins?: readonly TreeViewAnyPluginSignature[]; + dependencies?: readonly TreeViewAnyPluginSignature[]; + optionalDependencies?: readonly TreeViewAnyPluginSignature[]; }, > = { params: T extends { params: {} } ? T['params'] : {}; @@ -67,7 +68,10 @@ export type TreeViewPluginSignature< } : {}; experimentalFeatures: T['experimentalFeatures']; - dependantPlugins: T extends { dependantPlugins: Array } ? T['dependantPlugins'] : []; + dependencies: T extends { dependencies: Array } ? T['dependencies'] : []; + optionalDependencies: T extends { optionalDependencies: Array } + ? T['optionalDependencies'] + : []; }; export type TreeViewAnyPluginSignature = { @@ -75,7 +79,8 @@ export type TreeViewAnyPluginSignature = { instance: any; params: any; defaultizedParams: any; - dependantPlugins: any; + dependencies: any; + optionalDependencies: any; events: any; contextValue: any; slots: any; @@ -85,32 +90,37 @@ export type TreeViewAnyPluginSignature = { publicAPI: any; }; -type TreeViewUsedPlugins = [ +type TreeViewRequiredPlugins = [ ...TreeViewCorePluginSignatures, - ...TSignature['dependantPlugins'], + ...TSignature['dependencies'], ]; +type PluginPropertyWithDependencies< + TSignature extends TreeViewAnyPluginSignature, + TProperty extends keyof TreeViewAnyPluginSignature, +> = TSignature[TProperty] & + MergeSignaturesProperty, TProperty> & + Partial>; + export type TreeViewUsedParams = - TSignature['params'] & MergeSignaturesProperty, 'params'>; + PluginPropertyWithDependencies; type TreeViewUsedDefaultizedParams = - TSignature['defaultizedParams'] & - MergeSignaturesProperty, 'defaultizedParams'>; + PluginPropertyWithDependencies; export type TreeViewUsedInstance = - TSignature['instance'] & - MergeSignaturesProperty, 'instance'> & { - /** - * Private property only defined in TypeScript to be able to access the plugin signature from the instance object. - */ - $$signature: TSignature; - }; + PluginPropertyWithDependencies & { + /** + * Private property only defined in TypeScript to be able to access the plugin signature from the instance object. + */ + $$signature: TSignature; + }; -type TreeViewUsedState = TSignature['state'] & - MergeSignaturesProperty, 'state'>; +type TreeViewUsedState = + PluginPropertyWithDependencies; type TreeViewUsedExperimentalFeatures = - TreeViewExperimentalFeatures<[TSignature, ...TSignature['dependantPlugins']]>; + TreeViewExperimentalFeatures<[TSignature, ...TSignature['dependencies']]>; type RemoveSetValue>> = { [K in keyof Models]: Omit; @@ -118,10 +128,10 @@ type RemoveSetValue>> = { export type TreeViewUsedModels = TSignature['models'] & - RemoveSetValue, 'models'>>; + RemoveSetValue, 'models'>>; export type TreeViewUsedEvents = - TSignature['events'] & MergeSignaturesProperty, 'events'>; + TSignature['events'] & MergeSignaturesProperty, 'events'>; export interface TreeViewItemPluginOptions extends TreeViewItemPluginResponse { props: TProps; @@ -167,11 +177,11 @@ export type TreeViewPlugin = { * @param {{ nodeId: TreeViewItemId; children: React.ReactNode; }} params The params of the item. * @returns {React.ReactNode} The wrapped item. */ - wrapItem?: TreeItemWrapper<[TSignature, ...TSignature['dependantPlugins']]>; + wrapItem?: TreeItemWrapper<[TSignature, ...TSignature['dependencies']]>; /** * Render function used to add React wrappers around the TreeView. * @param {{ children: React.ReactNode; }} params The params of the root. * @returns {React.ReactNode} The wrapped root. */ - wrapRoot?: TreeRootWrapper<[TSignature, ...TSignature['dependantPlugins']]>; + wrapRoot?: TreeRootWrapper<[TSignature, ...TSignature['dependencies']]>; }; diff --git a/packages/x-tree-view/src/internals/models/treeView.ts b/packages/x-tree-view/src/internals/models/treeView.ts index e513e0f8bff5..a9b5e2452203 100644 --- a/packages/x-tree-view/src/internals/models/treeView.ts +++ b/packages/x-tree-view/src/internals/models/treeView.ts @@ -24,11 +24,17 @@ export interface TreeViewModel { setControlledValue: (value: TValue | ((prevValue: TValue) => TValue)) => void; } -export type TreeViewInstance = - MergeSignaturesProperty<[...TreeViewCorePluginSignatures, ...TSignatures], 'instance'>; +export type TreeViewInstance< + TSignatures extends readonly TreeViewAnyPluginSignature[], + TOptionalSignatures extends readonly TreeViewAnyPluginSignature[] = [], +> = MergeSignaturesProperty<[...TreeViewCorePluginSignatures, ...TSignatures], 'instance'> & + Partial>; -export type TreeViewPublicAPI = - MergeSignaturesProperty<[...TreeViewCorePluginSignatures, ...TSignatures], 'publicAPI'>; +export type TreeViewPublicAPI< + TSignatures extends readonly TreeViewAnyPluginSignature[], + TOptionalSignatures extends readonly TreeViewAnyPluginSignature[] = [], +> = MergeSignaturesProperty<[...TreeViewCorePluginSignatures, ...TSignatures], 'publicAPI'> & + Partial>; export type TreeViewExperimentalFeatures< TSignatures extends readonly TreeViewAnyPluginSignature[], diff --git a/packages/x-tree-view/src/internals/plugins/useTreeViewExpansion/useTreeViewExpansion.types.ts b/packages/x-tree-view/src/internals/plugins/useTreeViewExpansion/useTreeViewExpansion.types.ts index 1eabf3ce9daf..f3e93a059afd 100644 --- a/packages/x-tree-view/src/internals/plugins/useTreeViewExpansion/useTreeViewExpansion.types.ts +++ b/packages/x-tree-view/src/internals/plugins/useTreeViewExpansion/useTreeViewExpansion.types.ts @@ -85,5 +85,5 @@ export type UseTreeViewExpansionSignature = TreeViewPluginSignature<{ instance: UseTreeViewExpansionInstance; publicAPI: UseTreeViewExpansionPublicAPI; modelNames: 'expandedItems'; - dependantPlugins: [UseTreeViewItemsSignature]; + dependencies: [UseTreeViewItemsSignature]; }>; diff --git a/packages/x-tree-view/src/internals/plugins/useTreeViewFocus/useTreeViewFocus.types.ts b/packages/x-tree-view/src/internals/plugins/useTreeViewFocus/useTreeViewFocus.types.ts index 993487fcf86d..50c265aa5866 100644 --- a/packages/x-tree-view/src/internals/plugins/useTreeViewFocus/useTreeViewFocus.types.ts +++ b/packages/x-tree-view/src/internals/plugins/useTreeViewFocus/useTreeViewFocus.types.ts @@ -61,7 +61,7 @@ export type UseTreeViewFocusSignature = TreeViewPluginSignature<{ instance: UseTreeViewFocusInstance; publicAPI: UseTreeViewFocusPublicAPI; state: UseTreeViewFocusState; - dependantPlugins: [ + dependencies: [ UseTreeViewIdSignature, UseTreeViewItemsSignature, UseTreeViewSelectionSignature, diff --git a/packages/x-tree-view/src/internals/plugins/useTreeViewIcons/useTreeViewIcons.types.ts b/packages/x-tree-view/src/internals/plugins/useTreeViewIcons/useTreeViewIcons.types.ts index 0ceb50b8fe3e..5705fbbddaa0 100644 --- a/packages/x-tree-view/src/internals/plugins/useTreeViewIcons/useTreeViewIcons.types.ts +++ b/packages/x-tree-view/src/internals/plugins/useTreeViewIcons/useTreeViewIcons.types.ts @@ -43,5 +43,5 @@ export type UseTreeViewIconsSignature = TreeViewPluginSignature<{ contextValue: UseTreeViewIconsContextValue; slots: UseTreeViewIconsSlots; slotProps: UseTreeViewIconsSlotProps; - dependantPlugins: [UseTreeViewItemsSignature, UseTreeViewSelectionSignature]; + dependencies: [UseTreeViewItemsSignature, UseTreeViewSelectionSignature]; }>; diff --git a/packages/x-tree-view/src/internals/plugins/useTreeViewJSXItems/useTreeViewJSXItems.types.ts b/packages/x-tree-view/src/internals/plugins/useTreeViewJSXItems/useTreeViewJSXItems.types.ts index 3f613428603e..45cddbf7350a 100644 --- a/packages/x-tree-view/src/internals/plugins/useTreeViewJSXItems/useTreeViewJSXItems.types.ts +++ b/packages/x-tree-view/src/internals/plugins/useTreeViewJSXItems/useTreeViewJSXItems.types.ts @@ -38,5 +38,5 @@ export type UseTreeViewJSXItemsSignature = TreeViewPluginSignature<{ params: UseTreeViewJSXItemsParameters; defaultizedParams: UseTreeViewItemsDefaultizedParameters; instance: UseTreeViewItemsInstance; - dependantPlugins: [UseTreeViewItemsSignature, UseTreeViewKeyboardNavigationSignature]; + dependencies: [UseTreeViewItemsSignature, UseTreeViewKeyboardNavigationSignature]; }>; diff --git a/packages/x-tree-view/src/internals/plugins/useTreeViewKeyboardNavigation/useTreeViewKeyboardNavigation.types.ts b/packages/x-tree-view/src/internals/plugins/useTreeViewKeyboardNavigation/useTreeViewKeyboardNavigation.types.ts index 9aceca62b73f..8572a6e75fc2 100644 --- a/packages/x-tree-view/src/internals/plugins/useTreeViewKeyboardNavigation/useTreeViewKeyboardNavigation.types.ts +++ b/packages/x-tree-view/src/internals/plugins/useTreeViewKeyboardNavigation/useTreeViewKeyboardNavigation.types.ts @@ -29,7 +29,7 @@ export interface UseTreeViewKeyboardNavigationInstance { export type UseTreeViewKeyboardNavigationSignature = TreeViewPluginSignature<{ instance: UseTreeViewKeyboardNavigationInstance; - dependantPlugins: [ + dependencies: [ UseTreeViewItemsSignature, UseTreeViewSelectionSignature, UseTreeViewFocusSignature, diff --git a/packages/x-tree-view/src/internals/plugins/useTreeViewSelection/useTreeViewSelection.types.ts b/packages/x-tree-view/src/internals/plugins/useTreeViewSelection/useTreeViewSelection.types.ts index 56474f46a0ba..c6fc7cedf450 100644 --- a/packages/x-tree-view/src/internals/plugins/useTreeViewSelection/useTreeViewSelection.types.ts +++ b/packages/x-tree-view/src/internals/plugins/useTreeViewSelection/useTreeViewSelection.types.ts @@ -131,7 +131,7 @@ export type UseTreeViewSelectionSignature = TreeViewPluginSignature<{ instance: UseTreeViewSelectionInstance; contextValue: UseTreeViewSelectionContextValue; modelNames: 'selectedItems'; - dependantPlugins: [ + dependencies: [ UseTreeViewItemsSignature, UseTreeViewExpansionSignature, UseTreeViewItemsSignature, diff --git a/packages/x-tree-view/src/useTreeItem2/useTreeItem2.ts b/packages/x-tree-view/src/useTreeItem2/useTreeItem2.ts index 72fd74f6d23c..54c6e3dc7435 100644 --- a/packages/x-tree-view/src/useTreeItem2/useTreeItem2.ts +++ b/packages/x-tree-view/src/useTreeItem2/useTreeItem2.ts @@ -11,6 +11,7 @@ import { UseTreeItemIconContainerSlotProps, UseTreeItem2CheckboxSlotProps, UseTreeItem2MinimalPlugins, + UseTreeItem2OptionalPlugins, } from './useTreeItem2.types'; import { useTreeViewContext } from '../internals/TreeViewProvider/useTreeViewContext'; import { MuiCancellableEvent } from '../internals/models/MuiCancellableEvent'; @@ -19,9 +20,10 @@ import { TreeViewItemDepthContext } from '../internals/TreeViewItemDepthContext' export const useTreeItem2 = < TSignatures extends UseTreeItem2MinimalPlugins = UseTreeItem2MinimalPlugins, + TOptionalSignatures extends UseTreeItem2OptionalPlugins = UseTreeItem2OptionalPlugins, >( parameters: UseTreeItem2Parameters, -): UseTreeItem2ReturnValue => { +): UseTreeItem2ReturnValue => { const { runItemPlugins, selection: { multiSelect, disableSelection, checkboxSelection }, @@ -29,7 +31,7 @@ export const useTreeItem2 = < indentationAtItemLevel, instance, publicAPI, - } = useTreeViewContext(); + } = useTreeViewContext(); const depthContext = React.useContext(TreeViewItemDepthContext); const { id, itemId, label, children, rootRef } = parameters; diff --git a/packages/x-tree-view/src/useTreeItem2/useTreeItem2.types.ts b/packages/x-tree-view/src/useTreeItem2/useTreeItem2.types.ts index 08651b015ad3..321b9d5a1408 100644 --- a/packages/x-tree-view/src/useTreeItem2/useTreeItem2.types.ts +++ b/packages/x-tree-view/src/useTreeItem2/useTreeItem2.types.ts @@ -1,7 +1,7 @@ import * as React from 'react'; import { TreeViewItemId } from '../models'; import { MuiCancellableEventHandler } from '../internals/models/MuiCancellableEvent'; -import { TreeViewAnyPluginSignature, TreeViewPublicAPI } from '../internals/models'; +import { TreeViewPublicAPI } from '../internals/models'; import { UseTreeViewSelectionSignature } from '../internals/plugins/useTreeViewSelection'; import { UseTreeViewItemsSignature } from '../internals/plugins/useTreeViewItems'; import { UseTreeViewIdSignature } from '../internals/plugins/useTreeViewId'; @@ -116,7 +116,8 @@ export interface UseTreeItem2Status { } export interface UseTreeItem2ReturnValue< - TSignatures extends readonly TreeViewAnyPluginSignature[], + TSignatures extends UseTreeItem2MinimalPlugins, + TOptionalSignatures extends UseTreeItem2OptionalPlugins, > { /** * Resolver for the root slot's props. @@ -177,9 +178,12 @@ export interface UseTreeItem2ReturnValue< /** * The object the allows Tree View manipulation. */ - publicAPI: TreeViewPublicAPI; + publicAPI: TreeViewPublicAPI; } +/** + * Plugins that need to be present in the Tree View in order for `useTreeItem2` to work correctly. + */ export type UseTreeItem2MinimalPlugins = readonly [ UseTreeViewSelectionSignature, UseTreeViewItemsSignature, @@ -187,3 +191,8 @@ export type UseTreeItem2MinimalPlugins = readonly [ UseTreeViewFocusSignature, UseTreeViewKeyboardNavigationSignature, ]; + +/** + * Plugins that `useTreeItem2` can use if they are present, but are not required. + */ +export type UseTreeItem2OptionalPlugins = readonly [];