import React from 'react' import ReactDOM from 'react-dom' import { Editor } from './Editor' type EditorContentProps = { editor: Editor | null } const Portals = ({ renderers }: { renderers: Map }) => { return (
{Array.from(renderers).map(([key, renderer]) => { return ReactDOM.createPortal( renderer.comp, renderer.teleportElement, renderer.id, ) })}
) } // const Content = React.memo(({ reference }: { reference: React.RefObject }) => { // return ( //
// ) // }) export class PureEditorContent extends React.Component { editorContentRef: React.RefObject constructor(props: EditorContentProps) { super(props) this.editorContentRef = React.createRef() this.state = { editor: this.props.editor, renderers: new Map(), } } componentDidUpdate() { const { editor } = this.props if (editor && editor.options.element) { if (editor.contentComponent) { return } // this.setState({ // editor, // }) const element = this.editorContentRef.current element.appendChild(editor.options.element.firstChild) editor.setOptions({ element, }) editor.contentComponent = this // TODO: why setTimeout? setTimeout(() => { editor.createNodeViews() }, 0) } } render() { // console.log('render', this.state) // console.log('render', this.props.editor, this.state.editor) return ( <>
) } } export const EditorContent = React.memo(PureEditorContent)