import React, { useState, useCallback, useEffect, SetStateAction, forwardRef } from 'react'; import { motion, AnimatePresence } from 'framer-motion'; import { FileText, Undo2, X, TriangleAlert } from 'lucide-react'; import { ScriptRenderer } from '@/components/script-renderer/ScriptRenderer'; import { useEditData } from '@/components/pages/work-flow/use-edit-data'; import FloatingGlassPanel from './FloatingGlassPanel'; interface ScriptTabContentProps { setIsPauseWorkFlow: (isPauseWorkFlow: boolean) => void; isPauseWorkFlow: boolean; originalText?: string; onApply: () => void; setActiveTab: (tabId: string) => void; onClose: () => void; } export const ScriptTabContent = forwardRef< { switchBefore: (tabId: string) => boolean, saveOrCloseBefore: () => void }, ScriptTabContentProps >((props, ref) => { const { setIsPauseWorkFlow, isPauseWorkFlow, originalText, onApply, setActiveTab, onClose } = props; const { loading, scriptData, setAnyAttribute, applyScript } = useEditData('script', originalText); const [isUpdate, setIsUpdate] = useState(false); const [isRemindApplyUpdate, setIsRemindApplyUpdate] = useState(false); const [nextToTabId, setNextToTabId] = useState(''); useEffect(() => { console.log('contentEditableRef---scriptTabContentIsChange', isUpdate); }, [isUpdate]); // 暴露方法给父组件 React.useImperativeHandle(ref, () => ({ switchBefore: (tabId: string) => { setNextToTabId(tabId); console.log('switchBefore', isUpdate); if (isUpdate) { setIsRemindApplyUpdate(true); } return isUpdate; }, saveOrCloseBefore: () => { console.log('saveOrCloseBefore'); if (isUpdate) { onApply(); } else { onClose(); } } })); const handleApply = () => { onApply(); } const handleCancel = () => { setIsRemindApplyUpdate(false); setActiveTab(nextToTabId); } // 如果loading 显示loading状态 if (loading) { return (

Loading...

); } // 如果没有数据,显示空状态 if (!scriptData || scriptData.length === 0) { return (

No script data

); } return (

The script content has been modified. Do I need to apply it?

); });