import * as React from 'react' ; import { useMemo } from 'react' ; import { InteractionManager , InteractionMode } from '../types' ; import { useTreeEnvironment } from './ControlledTreeEnvironment' ; import { mergeInteractionManagers } from './mergeInteractionManagers' ; import { buildInteractionMode } from './buildInteractionMode' ; const InteractionManagerContext = React . createContext < InteractionManager > ( null as any ) ; export const useInteractionManager = ( ) => React . useContext ( InteractionManagerContext ) ; export const InteractionManagerProvider = props => { const environment = useTreeEnvironment ( ) ; const { defaultInteractionMode } = environment ; const interactionManager = useMemo ( ( ) => { if ( defaultInteractionMode && typeof defaultInteractionMode !== 'string' ) { if ( defaultInteractionMode . extends ) { return mergeInteractionManagers ( defaultInteractionMode , buildInteractionMode ( defaultInteractionMode . extends , environment ) ) ; } else { return defaultInteractionMode ; } } return buildInteractionMode ( ( defaultInteractionMode as InteractionMode ) ?? InteractionMode . ClickItemToExpand , environment ) ; } , [ ] ) ; return ( < InteractionManagerContext . Provider value = { interactionManager } > { props . children } < /InteractionManagerContext.Provider>); } ;