fix toggle editor

This commit is contained in:
Philipp Kühn
2021-03-15 14:53:23 +01:00
parent ee5283e13e
commit 57915d8638
2 changed files with 44 additions and 4 deletions

View File

@@ -22,7 +22,6 @@ export interface EditorContentProps {
}
export interface EditorContentState {
editor: Editor | null,
renderers: Map<string, ReactRenderer>
}
@@ -34,12 +33,19 @@ export class PureEditorContent extends React.Component<EditorContentProps, Edito
this.editorContentRef = React.createRef()
this.state = {
editor: this.props.editor,
renderers: new Map(),
}
}
componentDidMount() {
this.init()
}
componentDidUpdate() {
this.init()
}
init() {
const { editor } = this.props
if (editor && editor.options.element) {
@@ -68,6 +74,34 @@ export class PureEditorContent extends React.Component<EditorContentProps, Edito
}
}
componentWillUnmount() {
const { editor } = this.props
if (!editor) {
return
}
if (!editor.isDestroyed) {
editor.view.setProps({
nodeViews: {},
})
}
editor.contentComponent = null
if (!editor.options.element.firstChild) {
return
}
const newElement = document.createElement('div')
newElement.appendChild(editor.options.element.firstChild)
editor.setOptions({
element: newElement,
})
}
render() {
return (
<>