import { useStore } from '@nanostores/react'; import { AnimatePresence, motion, type Variants } from 'framer-motion'; import { memo, useCallback, useEffect } from 'react'; import { Panel, PanelGroup, PanelResizeHandle } from 'react-resizable-panels'; import { workbenchStore } from '../../lib/stores/workbench'; import { cubicEasingFn } from '../../utils/easings'; import { renderLogger } from '../../utils/logger'; import type { OnChangeCallback as OnEditorChange, OnScrollCallback as OnEditorScroll, } from '../editor/codemirror/CodeMirrorEditor'; import { IconButton } from '../ui/IconButton'; import { EditorPanel } from './EditorPanel'; import { Preview } from './Preview'; interface WorkspaceProps { chatStarted?: boolean; isStreaming?: boolean; } const workbenchVariants = { closed: { width: 0, transition: { duration: 0.2, ease: cubicEasingFn, }, }, open: { width: '100%', transition: { duration: 0.2, ease: cubicEasingFn, }, }, } satisfies Variants; export const Workbench = memo(({ chatStarted, isStreaming }: WorkspaceProps) => { renderLogger.trace('Workbench'); const showWorkbench = useStore(workbenchStore.showWorkbench); const selectedFile = useStore(workbenchStore.selectedFile); const currentDocument = useStore(workbenchStore.currentDocument); const files = useStore(workbenchStore.files); useEffect(() => { workbenchStore.setDocuments(files); }, [files]); const onEditorChange = useCallback((update) => { workbenchStore.setCurrentDocumentContent(update.content); }, []); const onEditorScroll = useCallback((position) => { workbenchStore.setCurrentDocumentScrollPosition(position); }, []); const onFileSelect = useCallback((filePath: string | undefined) => { workbenchStore.setSelectedFile(filePath); }, []); return ( chatStarted && ( {showWorkbench && (
{ workbenchStore.showWorkbench.set(false); }} />
)}
) ); });