import { InteractionMode , InteractionManager , TreeEnvironmentContextProps , TreeItem , TreeItemActions , TreeItemRenderFlags , } from '../types' ; import { HTMLProps } from 'react' ; export class ClickItemToExpandInteractionManager implements InteractionManager { public readonly mode = InteractionMode . ClickItemToExpand ; private environment : TreeEnvironmentContextProps ; constructor ( environment ) { this . environment = environment ; } createInteractiveElementProps ( item , treeId , actions , renderFlags ) { return { onClick : e => { actions . focusItem ( ) ; if ( e . shiftKey ) { actions . selectUpTo ( ) ; } else if ( e . ctrlKey ) { if ( renderFlags . isSelected ) { actions . unselectItem ( ) ; } else { actions . addToSelectedItems ( ) ; } } else { if ( item . hasChildren ) { actions . toggleExpandedState ( ) ; } actions . selectItem ( ) ; if ( ! item . hasChildren || this . environment . canInvokePrimaryActionOnItemContainer ) { actions . primaryAction ( ) ; } } } , onFocus : ( ) => { actions . focusItem ( ) ; } , onDragStart : e => { e . dataTransfer . dropEffect = 'move' ; actions . startDragging ( ) ; } , onDragOver : e => { e . preventDefault ( ) ; } , draggable : renderFlags . canDrag && ! renderFlags . isRenaming , tabIndex : ! renderFlags . isRenaming ? ( renderFlags . isFocused ? 0 : - 1 ) : undefined } ; } }