2021-03-08 20:19:05 +08:00
|
|
|
import React, { useState, useRef, useEffect } from 'react'
|
|
|
|
import ReactDOM from 'react-dom'
|
|
|
|
import { Editor } from './Editor'
|
|
|
|
|
|
|
|
// export const EditorContent = ({ editor }) => {
|
|
|
|
// const editorContentRef = useRef(null)
|
|
|
|
|
|
|
|
// useEffect(() => {
|
|
|
|
// if (editor && editor.options.element) {
|
|
|
|
// console.log('set editorContent element')
|
|
|
|
|
|
|
|
// const element = editorContentRef.current
|
|
|
|
|
|
|
|
// element.appendChild(editor.options.element.firstChild)
|
|
|
|
|
|
|
|
// editor.setOptions({
|
|
|
|
// element,
|
|
|
|
// })
|
|
|
|
|
|
|
|
// console.log({instance: this})
|
|
|
|
|
|
|
|
// // TODO: why setTimeout?
|
|
|
|
// setTimeout(() => {
|
|
|
|
// editor.createNodeViews()
|
|
|
|
// }, 0)
|
|
|
|
// }
|
|
|
|
// })
|
|
|
|
|
|
|
|
// return (
|
|
|
|
// <div ref={editorContentRef} />
|
|
|
|
// )
|
|
|
|
// }
|
|
|
|
|
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);
|