mirror of
https://github.com/ueberdosis/tiptap.git
synced 2024-12-14 18:49:02 +08:00
unregister plugins correctly, fix #188
This commit is contained in:
parent
c0713b64af
commit
0742ca8abe
@ -52,4 +52,8 @@ export default {
|
||||
})
|
||||
},
|
||||
|
||||
beforeDestroy() {
|
||||
this.editor.unregisterPlugin('floating_menu')
|
||||
},
|
||||
|
||||
}
|
||||
|
@ -63,4 +63,8 @@ export default {
|
||||
})
|
||||
},
|
||||
|
||||
beforeDestroy() {
|
||||
this.editor.unregisterPlugin('menu_bubble')
|
||||
},
|
||||
|
||||
}
|
||||
|
@ -439,6 +439,17 @@ export default class Editor extends Emitter {
|
||||
this.view.updateState(newState)
|
||||
}
|
||||
|
||||
unregisterPlugin(name = null) {
|
||||
if (!name || !this.view.docView) {
|
||||
return
|
||||
}
|
||||
|
||||
const newState = this.state.reconfigure({
|
||||
plugins: this.state.plugins.filter(plugin => !plugin.key.startsWith(`${name}$`)),
|
||||
})
|
||||
this.view.updateState(newState)
|
||||
}
|
||||
|
||||
destroy() {
|
||||
if (!this.view) {
|
||||
return
|
||||
|
@ -1,4 +1,4 @@
|
||||
import { Plugin } from 'prosemirror-state'
|
||||
import { Plugin, PluginKey } from 'prosemirror-state'
|
||||
|
||||
class Menu {
|
||||
|
||||
@ -75,6 +75,7 @@ class Menu {
|
||||
|
||||
export default function (options) {
|
||||
return new Plugin({
|
||||
key: new PluginKey('floating_menu'),
|
||||
view(editorView) {
|
||||
return new Menu({ editorView, options })
|
||||
},
|
||||
|
@ -1,4 +1,4 @@
|
||||
import { Plugin } from 'prosemirror-state'
|
||||
import { Plugin, PluginKey } from 'prosemirror-state'
|
||||
|
||||
function textRange(node, from, to) {
|
||||
const range = document.createRange()
|
||||
@ -135,6 +135,7 @@ class Menu {
|
||||
|
||||
export default function (options) {
|
||||
return new Plugin({
|
||||
key: new PluginKey('menu_bubble'),
|
||||
view(editorView) {
|
||||
return new Menu({ editorView, options })
|
||||
},
|
||||
|
Loading…
Reference in New Issue
Block a user