/** * Copyright (c) Meta Platforms, Inc. and affiliates. * * This source code is licensed under the MIT license found in the * LICENSE file in the root directory of this source tree. * */ import {AutoFocusPlugin} from '@lexical/react/LexicalAutoFocusPlugin'; import {LexicalComposer} from '@lexical/react/LexicalComposer'; import {useLexicalComposerContext} from '@lexical/react/LexicalComposerContext'; import {ContentEditable} from '@lexical/react/LexicalContentEditable'; import {LexicalErrorBoundary} from '@lexical/react/LexicalErrorBoundary'; import {HistoryPlugin} from '@lexical/react/LexicalHistoryPlugin'; import {RichTextPlugin} from '@lexical/react/LexicalRichTextPlugin'; import {TablePlugin} from '@lexical/react/LexicalTablePlugin'; import { INSERT_TABLE_COMMAND, TableCellNode, TableNode, TableRowNode, } from '@lexical/table'; import {LexicalEditor} from 'lexical'; import {useEffect, useState} from 'react'; import ExampleTheme from './ExampleTheme'; import ToolbarPlugin from './plugins/ToolbarPlugin'; import TreeViewPlugin from './plugins/TreeViewPlugin'; const editorConfig = { namespace: 'React.js Demo', nodes: [TableNode, TableCellNode, TableRowNode], // Handling of errors during update onError(error: Error) { throw error; }, // The editor theme theme: ExampleTheme, }; const $updateEditorState = (editor: LexicalEditor) => { editor.dispatchCommand(INSERT_TABLE_COMMAND, { columns: String(3), includeHeaders: true, rows: String(3), }); }; function InsertTable({ showTable, setShowTable, }: { showTable: boolean; setShowTable: React.Dispatch>; }) { const [editor] = useLexicalComposerContext(); useEffect(() => { if (!showTable) { setShowTable(true); } }, [showTable, setShowTable]); useEffect(() => { if (showTable) { $updateEditorState(editor); } }, [editor, showTable]); return <>; } function Placeholder() { return
Enter some rich text...
; } export default function App() { const [showTable, setShowTable] = useState(false); return (
} placeholder={} ErrorBoundary={LexicalErrorBoundary} />
); }