import { type FC, useEffect } from 'react' import { GeneratorType } from '@/app/components/app/configuration/config/automatic/types' import { useLexicalComposerContext } from '@lexical/react/LexicalComposerContext' import { useSelectOrDelete } from '../../hooks' import { CurrentBlockNode, DELETE_CURRENT_BLOCK_COMMAND } from '.' import cn from '@/utils/classnames' import { CodeAssistant, MagicEdit } from '../../../icons/src/vender/line/general' type CurrentBlockComponentProps = { nodeKey: string generatorType: GeneratorType } const CurrentBlockComponent: FC = ({ nodeKey, generatorType, }) => { const [editor] = useLexicalComposerContext() const [ref, isSelected] = useSelectOrDelete(nodeKey, DELETE_CURRENT_BLOCK_COMMAND) const Icon = generatorType === GeneratorType.prompt ? MagicEdit : CodeAssistant useEffect(() => { if (!editor.hasNodes([CurrentBlockNode])) throw new Error('WorkflowVariableBlockPlugin: WorkflowVariableBlock not registered on editor') }, [editor]) return (
{ e.stopPropagation() }} ref={ref} >
{generatorType === GeneratorType.prompt ? 'current_prompt' : 'current_code'}
) } export default CurrentBlockComponent