2021-03-09 05:16:32 +08:00
|
|
|
import React from 'react'
|
2021-03-09 05:00:07 +08:00
|
|
|
|
|
|
|
export class PureEditorContent extends React.Component {
|
2021-03-08 20:19:05 +08:00
|
|
|
constructor(props) {
|
|
|
|
super(props)
|
|
|
|
this.editorContentRef = React.createRef()
|
|
|
|
this.editorPortalRef = React.createRef()
|
|
|
|
|
|
|
|
this.state = {
|
|
|
|
editor: this.props.editor
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
componentDidUpdate() {
|
|
|
|
const { editor } = this.props
|
|
|
|
|
|
|
|
if (editor && editor.options.element) {
|
|
|
|
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() {
|
|
|
|
return (
|
|
|
|
<div ref={this.editorContentRef} />
|
|
|
|
)
|
|
|
|
}
|
|
|
|
}
|
2021-03-09 05:00:07 +08:00
|
|
|
|
|
|
|
export const EditorContent = React.memo(PureEditorContent);
|