base commit

This commit is contained in:
@kirill.komarov
2026-05-03 20:30:21 +05:00
parent fe10f25b8c
commit 6885e39017
13 changed files with 253 additions and 72 deletions
+10 -4
View File
@@ -22,14 +22,19 @@ export function RichTextMessageEditor({
placeholder = 'Введите сообщение',
disabled = false,
}: RichTextMessageEditorProps) {
const initialContent = value.trim() ? value : '<p></p>'
const editor = useEditor({
extensions: [
TiptapStarterKit.configure({ heading: false, codeBlock: false, blockquote: false, horizontalRule: false }),
Placeholder.configure({ placeholder }),
],
content: value,
content: initialContent,
editable: !disabled,
onUpdate: ({ editor: tiptap }) => onChange(tiptap.getText()),
onUpdate: ({ editor: tiptap }) => {
const plainText = tiptap.getText().trim()
onChange(plainText ? tiptap.getHTML() : '')
},
})
useEffect(() => {
@@ -39,8 +44,9 @@ export function RichTextMessageEditor({
useEffect(() => {
if (!editor) return
if (editor.getText() === value) return
editor.commands.setContent(value, false)
const normalizedValue = value.trim() ? value : '<p></p>'
if (editor.getHTML() === normalizedValue) return
editor.commands.setContent(normalizedValue, false)
}, [editor, value])
return (