一些检查失败了
automerge / automerge (push) Has been cancelled
react-native-android-build-apk / AssembleRelease (push) Has been cancelled
Build macOS M1 / Main (push) Has been cancelled
Joplin Continuous Integration / Main (macos-15-intel) (push) Has been cancelled
Joplin Continuous Integration / Main (ubuntu-22.04) (push) Has been cancelled
Joplin Continuous Integration / Main (ubuntu-22.04-arm) (push) Has been cancelled
Joplin Continuous Integration / Main (windows-11-vs2026-arm) (push) Has been cancelled
Joplin Continuous Integration / Main (windows-2025) (push) Has been cancelled
Joplin Continuous Integration / ServerDockerImage (ubuntu-22.04) (push) Has been cancelled
Joplin Continuous Integration / ServerDockerImage (ubuntu-22.04-arm) (push) Has been cancelled
Joplin UI tests / Main (ubuntu-22.04) (push) Has been cancelled
Joplin UI tests / Main (windows-2025) (push) Has been cancelled
Joplin UI tests / Mobile (push) Has been cancelled
Close stale issues / ProcessStaleIssues (push) Has been cancelled
76 行
2.1 KiB
TypeScript
76 行
2.1 KiB
TypeScript
import * as React from 'react';
|
|
import { useCallback } from 'react';
|
|
import { StyledHeader, StyledHeaderIcon, StyledHeaderLabel } from '../styles';
|
|
import { HeaderId, HeaderListItem } from '../types';
|
|
import bridge from '../../../services/bridge';
|
|
import MenuUtils from '@joplin/lib/services/commands/MenuUtils';
|
|
import CommandService from '@joplin/lib/services/CommandService';
|
|
import ListItemWrapper, { ItemSelectionState, ListItemRef } from './ListItemWrapper';
|
|
import ExpandIcon from './ExpandIcon';
|
|
|
|
const Menu = bridge().Menu;
|
|
const MenuItem = bridge().MenuItem;
|
|
const menuUtils = new MenuUtils(CommandService.instance());
|
|
|
|
|
|
interface Props {
|
|
anchorRef: ListItemRef;
|
|
item: HeaderListItem;
|
|
selectionState: ItemSelectionState;
|
|
onDrop: React.DragEventHandler|null;
|
|
index: number;
|
|
itemCount: number;
|
|
}
|
|
|
|
const HeaderItem: React.FC<Props> = props => {
|
|
const item = props.item;
|
|
const onItemClick = item.onClick;
|
|
const itemId = item.id;
|
|
|
|
const onClick: React.MouseEventHandler<HTMLElement> = useCallback(event => {
|
|
if (onItemClick) {
|
|
onItemClick(itemId, event);
|
|
}
|
|
}, [onItemClick, itemId]);
|
|
|
|
const onContextMenu = useCallback(async () => {
|
|
if (itemId === HeaderId.FolderHeader) {
|
|
const menu = new Menu();
|
|
|
|
menu.append(
|
|
new MenuItem(menuUtils.commandToStatefulMenuItem('newFolder')),
|
|
);
|
|
|
|
menu.popup({ window: bridge().activeWindow() });
|
|
}
|
|
}, [itemId]);
|
|
|
|
return (
|
|
<ListItemWrapper
|
|
containerRef={props.anchorRef}
|
|
selectionState={props.selectionState}
|
|
itemIndex={props.index}
|
|
itemCount={props.itemCount}
|
|
expanded={props.item.expanded}
|
|
onContextMenu={onContextMenu}
|
|
depth={item.depth}
|
|
highlightOnHover={false}
|
|
className='sidebar-header-container'
|
|
{...item.extraProps}
|
|
onDrop={props.onDrop}
|
|
>
|
|
<StyledHeader
|
|
onClick={onClick}
|
|
>
|
|
<span className='sidebar-expand-link' aria-hidden='true'>
|
|
<ExpandIcon isVisible={true} isExpanded={props.item.expanded}/>
|
|
</span>
|
|
<StyledHeaderIcon aria-hidden='true' role='img' className={item.iconName}/>
|
|
<StyledHeaderLabel>{item.label}</StyledHeaderLabel>
|
|
</StyledHeader>
|
|
</ListItemWrapper>
|
|
);
|
|
};
|
|
|
|
export default HeaderItem;
|