base commit
This commit is contained in:
@@ -0,0 +1,46 @@
|
||||
import { useEffect } from 'react'
|
||||
import Box from '@mui/material/Box'
|
||||
import { EditorContent, useEditor } from '@tiptap/react'
|
||||
import TiptapStarterKit from '@tiptap/starter-kit'
|
||||
|
||||
type RichTextMessageContentProps = {
|
||||
value: string
|
||||
}
|
||||
|
||||
export function RichTextMessageContent({ value }: RichTextMessageContentProps) {
|
||||
const editor = useEditor({
|
||||
extensions: [
|
||||
TiptapStarterKit.configure({ heading: false, codeBlock: false, blockquote: false, horizontalRule: false }),
|
||||
],
|
||||
content: value.trim() ? value : '<p></p>',
|
||||
editable: false,
|
||||
})
|
||||
|
||||
useEffect(() => {
|
||||
if (!editor) return
|
||||
const normalizedValue = value.trim() ? value : '<p></p>'
|
||||
if (editor.getHTML() === normalizedValue) return
|
||||
editor.commands.setContent(normalizedValue, false)
|
||||
}, [editor, value])
|
||||
|
||||
return (
|
||||
<Box
|
||||
sx={{
|
||||
'& .ProseMirror': {
|
||||
outline: 'none',
|
||||
whiteSpace: 'pre-wrap',
|
||||
wordBreak: 'break-word',
|
||||
},
|
||||
'& .ProseMirror p': {
|
||||
m: 0,
|
||||
},
|
||||
'& .ProseMirror ul, & .ProseMirror ol': {
|
||||
m: 0,
|
||||
pl: 3,
|
||||
},
|
||||
}}
|
||||
>
|
||||
<EditorContent editor={editor} />
|
||||
</Box>
|
||||
)
|
||||
}
|
||||
Reference in New Issue
Block a user