remove styling on destroy
This commit is contained in:
@@ -16,6 +16,7 @@ import getAllMethodNames from './utils/getAllMethodNames'
|
|||||||
import nodeIsActive from './utils/nodeIsActive'
|
import nodeIsActive from './utils/nodeIsActive'
|
||||||
import markIsActive from './utils/markIsActive'
|
import markIsActive from './utils/markIsActive'
|
||||||
import getMarkAttrs from './utils/getMarkAttrs'
|
import getMarkAttrs from './utils/getMarkAttrs'
|
||||||
|
import removeElement from './utils/removeElement'
|
||||||
import getSchemaTypeByName from './utils/getSchemaTypeByName'
|
import getSchemaTypeByName from './utils/getSchemaTypeByName'
|
||||||
import ExtensionManager from './ExtensionManager'
|
import ExtensionManager from './ExtensionManager'
|
||||||
import Extension from './Extension'
|
import Extension from './Extension'
|
||||||
@@ -44,6 +45,7 @@ export class Editor extends EventEmitter {
|
|||||||
extensions: [],
|
extensions: [],
|
||||||
}
|
}
|
||||||
commands: { [key: string]: any } = {}
|
commands: { [key: string]: any } = {}
|
||||||
|
css!: HTMLStyleElement
|
||||||
|
|
||||||
private lastCommand = Promise.resolve()
|
private lastCommand = Promise.resolve()
|
||||||
|
|
||||||
@@ -62,7 +64,7 @@ export class Editor extends EventEmitter {
|
|||||||
this.registerCommand('clearContent', require('./commands/clearContent').default)
|
this.registerCommand('clearContent', require('./commands/clearContent').default)
|
||||||
|
|
||||||
if (this.options.injectCSS) {
|
if (this.options.injectCSS) {
|
||||||
injectCSS(require('./style.css'))
|
this.css = injectCSS(require('./style.css'))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -232,6 +234,7 @@ export class Editor extends EventEmitter {
|
|||||||
|
|
||||||
this.view.destroy()
|
this.view.destroy()
|
||||||
this.removeAllListeners()
|
this.removeAllListeners()
|
||||||
|
removeElement(this.css)
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,15 +1,13 @@
|
|||||||
export default function injectCSS(css: string) {
|
export default function injectCSS(css: string) {
|
||||||
if (process.env.NODE_ENV !== 'test') {
|
const style = document.createElement('style')
|
||||||
const style = document.createElement('style')
|
style.type = 'text/css'
|
||||||
style.type = 'text/css'
|
style.textContent = css
|
||||||
style.textContent = css
|
const { head } = document
|
||||||
const { head } = document
|
const { firstChild } = head
|
||||||
const { firstChild } = head
|
|
||||||
|
|
||||||
if (firstChild) {
|
if (firstChild) {
|
||||||
head.insertBefore(style, firstChild)
|
return head.insertBefore(style, firstChild)
|
||||||
} else {
|
} else {
|
||||||
head.appendChild(style)
|
return head.appendChild(style)
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
5
packages/core/src/utils/removeElement.ts
Normal file
5
packages/core/src/utils/removeElement.ts
Normal file
@@ -0,0 +1,5 @@
|
|||||||
|
export default function removeElement(element: HTMLElement) {
|
||||||
|
if (element && element.parentNode) {
|
||||||
|
element.parentNode.removeChild(element)
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user