import React from 'react'; import { observer } from 'mobx-react-lite'; import { SxProps } from '@mui/material'; import Box from '@mui/material/Box'; import EditIcon from '@mui/icons-material/Edit'; import TextField from '@mui/material/TextField'; import CheckIcon from '@mui/icons-material/Check'; import CloseIcon from '@mui/icons-material/Close'; import MoreHorizIcon from '@mui/icons-material/MoreHoriz'; import UnfoldLessIcon from '@mui/icons-material/UnfoldLess'; import MarkdownBlock from '@/components/MarkdownBlock'; import { globalStorage } from '@/storage'; export interface IObjectNodeProps { name: string; content: string; _ref?: React.RefObject; style?: SxProps; editObjectName?: string; stepId: string; handleExpand?: () => void; } export default observer( ({ style = {}, name, content, _ref, editObjectName, stepId, handleExpand, }: IObjectNodeProps) => { const inputStringRef = React.useRef(''); const [edit, setEdit] = React.useState(false); const [expand, setExpand] = React.useState(false); const refDetail = React.useRef(null); // 使用useEffect来更新detail容器的高度 React.useEffect(() => { if (refDetail.current) { refDetail.current.style.height = expand ? `${refDetail.current.scrollHeight}px` : '0px'; } if (handleExpand) { let count = 0; const intervalId = setInterval(() => { handleExpand(); count++; if (count >= 20) { clearInterval(intervalId); } }, 10); } }, [expand]); return ( { if (stepId) { globalStorage.setFocusingStepTaskId(stepId); } }} > {name} {content && !editObjectName ? ( {expand ? ( ) : ( <> )} { setExpand(v => !v); e.stopPropagation(); }} sx={{ position: 'absolute', right: '18px', bottom: '14px', cursor: 'pointer', userSelect: 'none', height: '14px', display: 'flex', alignItems: 'center', justifyContent: 'center', background: '#0002', borderRadius: '8px', marginLeft: '4px', padding: '0 4px', '&:hover': { background: '#0003', }, }} > {expand ? ( ) : ( )} ) : ( <> )} {editObjectName ? ( {edit ? ( <> { if (ele) { ele.value = inputStringRef.current; } }} onChange={event => (inputStringRef.current = event.target.value) } size="small" sx={{ fontSize: '12px', paddingTop: '10px', paddingBottom: '10px', borderRadius: '10px', border: 'none !important', borderBottom: 'none !important', '&::before': { borderBottom: 'none !important', border: 'none !important', }, '& > .MuiInputBase-root': { border: 'none', background: '#0001', '& > .MuiOutlinedInput-notchedOutline': { border: 'none !important', }, }, }} /> { setEdit(false); globalStorage.form.inputs[editObjectName] = inputStringRef.current; }} sx={{ position: 'absolute', right: '8px', bottom: '2px', cursor: 'pointer', userSelect: 'none', height: '18px', display: 'flex', alignItems: 'center', justifyContent: 'center', backdropFilter: 'contrast(0.6)', borderRadius: '3px', marginLeft: '4px', }} > setEdit(false)} sx={{ position: 'absolute', right: '34px', bottom: '2px', cursor: 'pointer', userSelect: 'none', height: '18px', display: 'flex', alignItems: 'center', justifyContent: 'center', backdropFilter: 'contrast(0.6)', borderRadius: '3px', marginLeft: '4px', }} > ) : ( <> { inputStringRef.current = globalStorage.form.inputs[editObjectName]; setEdit(true); }} sx={{ position: 'absolute', right: '6px', bottom: '8px', cursor: 'pointer', userSelect: 'none', height: '14px', display: 'flex', alignItems: 'center', justifyContent: 'center', borderRadius: '3px', marginLeft: '4px', opacity: 0.5, transition: 'opacity 200ms ease-out', '&:hover': { opacity: 1, }, }} > )} ) : ( <> )} ); }, );