import { useState, useEffect } from 'react'; import { StyledEdgelessToolbar, StyledToolbarWrapper, StyledToolbarItem, } from './style'; import { SelectIcon, TextIcon, ShapeIcon, PenIcon, StickerIcon, ConnectorIcon, UndoIcon, RedoIcon, } from './Icons'; import { MuiSlide } from '@/ui/mui'; import { Tooltip } from '@/ui/tooltip'; import useCurrentPageMeta from '@/hooks/use-current-page-meta'; import { useAppState } from '@/providers/app-state-provider'; import useHistoryUpdated from '@/hooks/use-history-update'; import { useTranslation } from '@affine/i18n'; const useToolbarList1 = () => { const { t } = useTranslation(); return [ { flavor: 'select', icon: , toolTip: t('Select'), disable: false, callback: () => { window.dispatchEvent( new CustomEvent('affine.switch-mouse-mode', { detail: { type: 'default', }, }) ); }, }, { flavor: 'text', icon: , toolTip: t('Text'), disable: true, }, { flavor: 'shape', icon: , toolTip: t('Shape'), disable: false, callback: () => { window.dispatchEvent( new CustomEvent('affine.switch-mouse-mode', { detail: { type: 'shape', color: 'black', shape: 'rectangle', }, }) ); }, }, { flavor: 'sticky', icon: , toolTip: t('Sticky'), disable: true, }, { flavor: 'pen', icon: , toolTip: t('Pen'), disable: true, }, { flavor: 'connector', icon: , toolTip: t('Connector'), disable: true, }, ]; }; const UndoRedo = () => { const [canUndo, setCanUndo] = useState(false); const [canRedo, setCanRedo] = useState(false); const { currentPage } = useAppState(); const onHistoryUpdated = useHistoryUpdated(); const { t } = useTranslation(); useEffect(() => { onHistoryUpdated(page => { setCanUndo(page.canUndo); setCanRedo(page.canRedo); }); }, [onHistoryUpdated]); return ( { currentPage?.undo(); }} > { currentPage?.redo(); }} > ); }; export const EdgelessToolbar = () => { const { mode } = useCurrentPageMeta() || {}; return ( {useToolbarList1().map( ({ icon, toolTip, flavor, disable, callback }, index) => { return ( { console.log('click toolbar button:', flavor); callback?.(); }} > {icon} ); } )} ); }; export default EdgelessToolbar;