2021-03-09 05:16:32 +08:00
|
|
|
import React from 'react'
|
2021-03-09 06:10:10 +08:00
|
|
|
import { Editor } from './Editor'
|
2021-03-09 05:00:07 +08:00
|
|
|
|
2021-03-09 06:10:10 +08:00
|
|
|
type EditorContentProps = {
|
|
|
|
editor: Editor | null
|
|
|
|
}
|
|
|
|
|
|
|
|
export class PureEditorContent extends React.Component<EditorContentProps, EditorContentProps> {
|
|
|
|
editorContentRef: React.RefObject<any>
|
|
|
|
|
|
|
|
constructor(props: EditorContentProps) {
|
2021-03-08 20:19:05 +08:00
|
|
|
super(props)
|
|
|
|
this.editorContentRef = 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);
|