import React, { useRef, useEffect, useState, useCallback } from 'react' function exec(cmd, value = null) { try { document.execCommand(cmd, false, value) } catch (_) { /* ignore */ } } /** * Leichter WYSIWYG-Editor (contenteditable) — ohne zusätzliche npm-Pakete. * Speichert HTML; Anzeige über sanitizeTrainerHtml + dangerouslySetInnerHTML. */ export default function RichTextEditor({ value, onChange, placeholder, minHeight = '140px' }) { const ref = useRef(null) const [focused, setFocused] = useState(false) const lastExternal = useRef(value) useEffect(() => { if (!ref.current) return if (focused) return if (value !== lastExternal.current) { lastExternal.current = value if (ref.current.innerHTML !== (value || '')) { ref.current.innerHTML = value || '' } } }, [value, focused]) const sync = useCallback(() => { if (!ref.current) return const html = ref.current.innerHTML lastExternal.current = html onChange(html) }, [onChange]) const onLink = () => { const url = window.prompt('Link-URL (https://…)') if (url) exec('createLink', url) sync() } return (