From 03445994119a8e0ecda934f9fc5a87b905907b90 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=A1=97=E8=A7=92=E5=B0=8F=E6=9E=97?= <1013335014@qq.com> Date: Tue, 24 Sep 2024 18:21:48 +0800 Subject: [PATCH] =?UTF-8?q?Fix=EF=BC=9A=E4=BC=98=E5=8C=96=E5=85=AC?= =?UTF-8?q?=E5=BC=8F=E6=8F=92=E4=BB=B6=EF=BC=8C=E9=80=82=E9=85=8D=E5=88=9B?= =?UTF-8?q?=E5=BB=BA=E5=A4=9A=E4=B8=AA=E5=AE=9E=E4=BE=8B=E7=9A=84=E6=83=85?= =?UTF-8?q?=E5=86=B5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- simple-mind-map/index.js | 3 +++ simple-mind-map/src/plugins/Formula.js | 16 +++++++++++++++- 2 files changed, 18 insertions(+), 1 deletion(-) diff --git a/simple-mind-map/index.js b/simple-mind-map/index.js index 3260844d..657e87fe 100644 --- a/simple-mind-map/index.js +++ b/simple-mind-map/index.js @@ -35,6 +35,7 @@ class MindMap { * @param {defaultOpt} opt */ constructor(opt = {}) { + MindMap.instanceCount++ // 合并选项 this.opt = this.handleOpt(merge(defaultOpt, opt)) // 预处理节点数据 @@ -618,6 +619,7 @@ class MindMap { this.el.innerHTML = '' this.el = null this.removeCss() + MindMap.instanceCount-- } } @@ -634,6 +636,7 @@ MindMap.hasPlugin = plugin => { return item === plugin }) } +MindMap.instanceCount = 0 // 定义新主题 MindMap.defineTheme = (name, config = {}) => { diff --git a/simple-mind-map/src/plugins/Formula.js b/simple-mind-map/src/plugins/Formula.js index e6b9db1c..3827566f 100644 --- a/simple-mind-map/src/plugins/Formula.js +++ b/simple-mind-map/src/plugins/Formula.js @@ -4,6 +4,7 @@ import { getChromeVersion, htmlEscape } from '../utils/index' import { getBaseStyleText, getFontStyleText } from './FormulaStyle' let extended = false +const QuillFormula = Quill.import('formats/formula') // 数学公式支持插件 // 该插件在富文本模式下可用 @@ -18,6 +19,18 @@ class Formula { this.cssEl = null this.addStyle() this.extendQuill() + this.onDestroy = this.onDestroy.bind(this) + this.mindMap.on('beforeDestroy', this.onDestroy) + } + + onDestroy() { + const instanceCount = Object.getPrototypeOf(this.mindMap).constructor + .instanceCount + // 如果思维导图实例数量变成0了,那么就恢复成默认的 + if (instanceCount <= 1) { + extended = false + Quill.register('formats/formula', QuillFormula, true) + } } init() { @@ -55,7 +68,6 @@ class Formula { if (extended) return extended = true - const QuillFormula = Quill.import('formats/formula') const self = this class CustomFormulaBlot extends QuillFormula { @@ -173,11 +185,13 @@ class Formula { // 插件被移除前做的事情 beforePluginRemove() { this.removeStyle() + this.mindMap.off('beforeDestroy', this.onDestroy) } // 插件被卸载前做的事情 beforePluginDestroy() { this.removeStyle() + this.mindMap.off('beforeDestroy', this.onDestroy) } }