import React, { useState, useRef, useEffect } from 'react'; import { Layout, Typography, Spin, Empty, Button, Card, Tooltip, message, Modal } from 'antd'; import { LoadingOutlined, WarningOutlined, SaveOutlined, EditOutlined, CheckOutlined } from '@ant-design/icons'; const { Content } = Layout; const { Title, Text } = Typography; interface SmartCanvasProps { content: string; streaming: boolean; annotations?: any[]; onStartGenerate?: () => void; onContentChange?: (content: string) => void; onContentSave?: (content: string) => void; episodeTitle?: string; episodeNumber?: number; } export const SmartCanvas: React.FC = ({ content, streaming, annotations = [], onStartGenerate, onContentChange, onContentSave, episodeTitle = '未命名草稿', episodeNumber = 5 }) => { const [isEditing, setIsEditing] = useState(false); const [editContent, setEditContent] = useState(content); const [showSaveModal, setShowSaveModal] = useState(false); const [selectedText, setSelectedText] = useState(''); const textareaRef = useRef(null); // Update editContent when content changes (e.g., from agent streaming) useEffect(() => { if (!isEditing) { setEditContent(content); } }, [content, isEditing]); const handleEditToggle = () => { if (isEditing) { // Save and exit edit mode setIsEditing(false); if (onContentChange) { onContentChange(editContent); } message.success('内容已更新'); } else { // Enter edit mode setIsEditing(true); setEditContent(content); } }; const handleSave = () => { if (onContentSave) { onContentSave(editContent); message.success('内容已保存'); } setIsEditing(false); }; const handleTextSelection = () => { const selection = window.getSelection(); const text = selection?.toString() || ''; setSelectedText(text); if (text.length > 0) { setShowSaveModal(true); } }; const handleInsertReference = () => { // This will be handled by parent component through callback setShowSaveModal(false); // Notify parent to insert reference into chat if (onContentChange) { onContentChange(`【引用】: ${selectedText}`); } message.info('已复制到剪贴板,可以在对话框中粘贴引用'); navigator.clipboard.writeText(selectedText); }; return (
第 {episodeNumber} 集:{episodeTitle} {/* 操作按钮 */} {!streaming && content && (
)} {content ? ( isEditing ? ( // 编辑模式