import { useState, useEffect } from 'react'; import { useRefresh } from '@flowgram.ai/free-layout-editor'; import { useClientContext } from '@flowgram.ai/free-layout-editor'; import { Tooltip, IconButton, Divider } from '@douyinfe/semi-ui'; import { IconUndo, IconRedo } from '@douyinfe/semi-icons'; import { AddNode } from '../add-node'; import { ZoomSelect } from './zoom-select'; import { SwitchLine } from './switch-line'; import { ToolContainer, ToolSection } from './styles'; import { Save } from './save'; import { Run } from './run'; import { Readonly } from './readonly'; import { MinimapSwitch } from './minimap-switch'; import { Minimap } from './minimap'; import { Interactive } from './interactive'; import { FitView } from './fit-view'; import { Comment } from './comment'; import { AutoLayout } from './auto-layout'; export const DemoTools = () => { const { history, playground } = useClientContext(); const [canUndo, setCanUndo] = useState(false); const [canRedo, setCanRedo] = useState(false); const [minimapVisible, setMinimapVisible] = useState(true); useEffect(() => { const disposable = history.undoRedoService.onChange(() => { setCanUndo(history.canUndo()); setCanRedo(history.canRedo()); }); return () => disposable.dispose(); }, [history]); const refresh = useRefresh(); useEffect(() => { const disposable = playground.config.onReadonlyOrDisabledChange(() => refresh()); return () => disposable.dispose(); }, [playground]); return ( } disabled={!canUndo || playground.config.readonly} onClick={() => history.undo()} /> } disabled={!canRedo || playground.config.readonly} onClick={() => history.redo()} /> ); };