import { Box, Button, ModalBody, ModalFooter, useDisclosure } from '@chakra-ui/react'; import React, { useMemo, useCallback } from 'react'; import { editorStateToText } from './utils'; import type { EditorProps } from './Editor'; import Editor from './Editor'; import MyModal from '../../MyModal'; import { useTranslation } from 'next-i18next'; import type { EditorState, LexicalEditor } from 'lexical'; import type { FormPropsType } from './type'; const PromptEditor = ({ showOpenModal = true, value, onChange, onBlur, onKeyDown, title, isDisabled, ...props }: FormPropsType & EditorProps & { title?: string; isDisabled?: boolean; onChange?: (text: string) => void; onBlur?: (text: string) => void; }) => { const { isOpen, onOpen, onClose } = useDisclosure(); const { t } = useTranslation(); const onChangeInput = useCallback( (editorState: EditorState, editor: LexicalEditor) => { const text = editorStateToText(editor); onChange?.(text); }, [onChange] ); const onBlurInput = useCallback( (editor: LexicalEditor) => { if (onBlur) { const text = editorStateToText(editor); onBlur(text); } }, [onBlur] ); const formattedValue = useMemo(() => { if (typeof value === 'object') { return JSON.stringify(value); } if (value === undefined || value === null) { return ''; } return String(value || ''); }, [value]); return ( <> {isDisabled && ( )} ); }; export default React.memo(PromptEditor);