import { $convertToMarkdownString, TRANSFORMERS, } from '@lexical/markdown'; import { LexicalComposer } from '@lexical/react/LexicalComposer'; import { ContentEditable } from '@lexical/react/LexicalContentEditable'; import LexicalErrorBoundary from '@lexical/react/LexicalErrorBoundary'; import { HistoryPlugin } from '@lexical/react/LexicalHistoryPlugin'; import { LinkPlugin } from '@lexical/react/LexicalLinkPlugin'; import { OnChangePlugin } from '@lexical/react/LexicalOnChangePlugin'; import { RichTextPlugin } from '@lexical/react/LexicalRichTextPlugin'; import React, { useState } from 'react'; import { FormattedMessage } from 'react-intl'; import nodes from './nodes'; import FloatingLinkEditorPlugin from './plugins/floating-link-editor-plugin'; import FloatingTextFormatToolbarPlugin from './plugins/floating-text-format-toolbar-plugin'; // import type { EditorState } from 'lexical'; const initialConfig = { namespace: 'ComposeForm', onError: console.error, nodes, }; const ComposeEditor = React.forwardRef((_, editorStateRef) => { const [floatingAnchorElem, setFloatingAnchorElem] = useState(null); const onRef = (_floatingAnchorElem: HTMLDivElement) => { if (_floatingAnchorElem !== null) { setFloatingAnchorElem(_floatingAnchorElem); } }; return (
} placeholder={(
)} ErrorBoundary={LexicalErrorBoundary} /> { editor.update(() => { if (editorStateRef) (editorStateRef as any).current = $convertToMarkdownString(TRANSFORMERS); }); }} /> {floatingAnchorElem ? ( <> ) : ''}
); }); export default ComposeEditor;