From 0742ca8abe913b1648a50da072075e424fe9b5d4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Philipp=20Ku=CC=88hn?= Date: Sat, 18 May 2019 00:22:05 +0200 Subject: [PATCH] unregister plugins correctly, fix #188 --- packages/tiptap/src/Components/EditorFloatingMenu.js | 4 ++++ packages/tiptap/src/Components/EditorMenuBubble.js | 4 ++++ packages/tiptap/src/Editor.js | 11 +++++++++++ packages/tiptap/src/Plugins/FloatingMenu.js | 3 ++- packages/tiptap/src/Plugins/MenuBubble.js | 3 ++- 5 files changed, 23 insertions(+), 2 deletions(-) diff --git a/packages/tiptap/src/Components/EditorFloatingMenu.js b/packages/tiptap/src/Components/EditorFloatingMenu.js index 45823a976..c281c89ca 100644 --- a/packages/tiptap/src/Components/EditorFloatingMenu.js +++ b/packages/tiptap/src/Components/EditorFloatingMenu.js @@ -52,4 +52,8 @@ export default { }) }, + beforeDestroy() { + this.editor.unregisterPlugin('floating_menu') + }, + } diff --git a/packages/tiptap/src/Components/EditorMenuBubble.js b/packages/tiptap/src/Components/EditorMenuBubble.js index 299283755..3d5e67f49 100644 --- a/packages/tiptap/src/Components/EditorMenuBubble.js +++ b/packages/tiptap/src/Components/EditorMenuBubble.js @@ -63,4 +63,8 @@ export default { }) }, + beforeDestroy() { + this.editor.unregisterPlugin('menu_bubble') + }, + } diff --git a/packages/tiptap/src/Editor.js b/packages/tiptap/src/Editor.js index f3d0e93a0..2f8a1aa8d 100644 --- a/packages/tiptap/src/Editor.js +++ b/packages/tiptap/src/Editor.js @@ -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 diff --git a/packages/tiptap/src/Plugins/FloatingMenu.js b/packages/tiptap/src/Plugins/FloatingMenu.js index d071cbacf..c2c59c063 100644 --- a/packages/tiptap/src/Plugins/FloatingMenu.js +++ b/packages/tiptap/src/Plugins/FloatingMenu.js @@ -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 }) }, diff --git a/packages/tiptap/src/Plugins/MenuBubble.js b/packages/tiptap/src/Plugins/MenuBubble.js index 77c726502..3873d9ccf 100644 --- a/packages/tiptap/src/Plugins/MenuBubble.js +++ b/packages/tiptap/src/Plugins/MenuBubble.js @@ -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 }) },