import LayoutCenter from '../components/layout-center' import styles from '../lexical/styles.module.css' import Theme from '../lexical/theme' import ListMaxIndentLevelPlugin from '../lexical/plugins/list-max-indent' import AutoLinkPlugin from '../lexical/plugins/autolink' import ToolbarPlugin from '../lexical/plugins/toolbar' import LinkTooltipPlugin from '../lexical/plugins/link-tooltip' import { LexicalComposer } from '@lexical/react/LexicalComposer' import { RichTextPlugin } from '@lexical/react/LexicalRichTextPlugin' import { ContentEditable } from '@lexical/react/LexicalContentEditable' import { AutoFocusPlugin } from '@lexical/react/LexicalAutoFocusPlugin' import { HistoryPlugin } from '@lexical/react/LexicalHistoryPlugin' import LexicalErrorBoundary from '@lexical/react/LexicalErrorBoundary' import { HorizontalRuleNode } from '@lexical/react/LexicalHorizontalRuleNode' import { OnChangePlugin } from '@lexical/react/LexicalOnChangePlugin' import { HeadingNode, QuoteNode } from '@lexical/rich-text' import { TableCellNode, TableNode, TableRowNode } from '@lexical/table' import { ListItemNode, ListNode } from '@lexical/list' import { CodeHighlightNode, CodeNode } from '@lexical/code' import { AutoLinkNode, LinkNode } from '@lexical/link' import { LinkPlugin } from '@lexical/react/LexicalLinkPlugin' import { ListPlugin } from '@lexical/react/LexicalListPlugin' import { MarkdownShortcutPlugin } from '@lexical/react/LexicalMarkdownShortcutPlugin' import { useState } from 'react' import LinkInsertPlugin, { LinkInsertProvider } from '../lexical/plugins/link-insert' import { ImageNode } from '../lexical/nodes/image' import ImageInsertPlugin from '../lexical/plugins/image-insert' import { SN_TRANSFORMERS } from '../lexical/utils/image-markdown-transformer' import { $convertToMarkdownString, $convertFromMarkdownString } from '@lexical/markdown' import { useLexicalComposerContext } from '@lexical/react/LexicalComposerContext' import Text from '../components/text' import { Button } from 'react-bootstrap' const editorConfig = { // The editor theme theme: Theme, // Handling of errors during update onError (error) { throw error }, // Any custom nodes go here nodes: [ HeadingNode, ListNode, ListItemNode, QuoteNode, CodeNode, CodeHighlightNode, TableNode, TableCellNode, TableRowNode, AutoLinkNode, LinkNode, HorizontalRuleNode, ImageNode ] } function Editor ({ markdown }) { const [floatingAnchorElem, setFloatingAnchorElem] = useState(null) const onRef = (_floatingAnchorElem) => { if (_floatingAnchorElem !== null) { setFloatingAnchorElem(_floatingAnchorElem) } } let initialConfig = editorConfig if (markdown) { initialConfig = { ...initialConfig, editorState: () => $convertFromMarkdownString(markdown, SN_TRANSFORMERS) } } return (
} placeholder={null} ErrorBoundary={LexicalErrorBoundary} />
{!markdown && }
) } function Markdown () { const [editor] = useLexicalComposerContext() const [markdown, setMarkdown] = useState(null) const [preview, togglePreview] = useState(true) return ( <>
editor.update(() => { setMarkdown($convertToMarkdownString(SN_TRANSFORMERS)) })} />
{preview ? ( {markdown} ) : (
                {markdown}
              
)}
) } export default function Lexical () { return ( ) }