import React, { PropsWithChildren, useState } from 'react'; import { StyledHeader, StyledHeaderRightSide, StyledHeaderContainer, StyledBrowserWarning, StyledCloseButton, } from './styles'; import { ExportIcon, EdgelessIcon, PaperIcon, ExportToHtmlIcon, ExportToMarkdownIcon, MoreVerticalIcon, FavouritesIcon, FavouritedIcon, TrashIcon, } from '@blocksuite/icons'; import { useEditor } from '@/providers/editor-provider'; import ThemeModeSwitch from '@/components/theme-mode-switch'; import { IconButton, Button } from '@/ui/button'; import CloseIcon from '@mui/icons-material/Close'; import { getWarningMessage, shouldShowWarning } from './utils'; import { Menu, MenuItem } from '@/ui/menu'; import { useRouter } from 'next/router'; import { useConfirm } from '@/providers/confirm-provider'; import { SyncIcon } from './sync-icon'; import { toast } from '@/components/toast'; const PopoverContent = () => { const { editor, mode, setMode, getPageMeta, page, toggleFavoritePage, toggleDeletePage, } = useEditor(); const { confirm } = useConfirm(); const { id, favorite, title } = getPageMeta(page?.id) ?? { id: '', favorite: false, title: '', }; return ( <> { toggleFavoritePage(id); }} icon={favorite ? : } > {favorite ? 'Remove' : 'Add'} to favourites : } onClick={() => { setMode(mode === 'page' ? 'edgeless' : 'page'); }} > Convert to {mode === 'page' ? 'Edgeless' : 'Page'} { editor && editor.contentParser.onExportHtml(); }} icon={} > Export to HTML { editor && editor.contentParser.onExportMarkdown(); }} icon={} > Export to Markdown } > } isDir={true}> Export { confirm({ title: 'Delete page?', content: `${title || 'Untitled'} will be moved to Trash`, confirmText: 'Delete', confirmType: 'danger', }).then(confirm => { confirm && toggleDeletePage(id); toast('Moved to Trash'); }); }} icon={} > Delete ); }; const BrowserWarning = ({ show, onClose, }: { show: boolean; onClose: () => void; }) => { return ( {getWarningMessage()} ); }; const HeaderRight = () => { const { pageList, toggleDeletePage, permanentlyDeletePage } = useEditor(); const { confirm } = useConfirm(); const router = useRouter(); const currentPageMeta = pageList.find(p => p.id === router.query.pageId); const isTrash = !!currentPageMeta?.trash; if (isTrash) { const { id } = currentPageMeta; return ( <> ); } return ( <> } placement="bottom-end"> ); }; export const Header = ({ children }: PropsWithChildren<{}>) => { const [showWarning, setShowWarning] = useState(shouldShowWarning()); return ( { setShowWarning(false); }} /> {children} ); }; export default Header;