import { $convertToMarkdownString, TRANSFORMERS, } from '@lexical/markdown'; import { LexicalComposer, InitialConfigType } 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 classNames from 'clsx'; import React, { useState } from 'react'; import { FormattedMessage } from 'react-intl'; import { useFeatures } from 'soapbox/hooks'; 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: InitialConfigType = { namespace: 'ComposeForm', onError: console.error, nodes, theme: { text: { bold: 'font-bold', code: 'font-mono', italic: 'italic', strikethrough: 'line-through', underline: 'underline', underlineStrikethrough: 'underline-line-through', }, }, }; const ComposeEditor = React.forwardRef(({ condensed, onFocus }, editorStateRef) => { const features = useFeatures(); 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); }); }} /> {features.richText && } {features.richText && floatingAnchorElem && ( <> )}
); }); export default ComposeEditor;