From f1355c9d2a4b7b0eaf4ee7f1ea440063f972b930 Mon Sep 17 00:00:00 2001 From: wanglin2 <1013335014@qq.com> Date: Tue, 20 Jun 2023 16:29:54 +0800 Subject: [PATCH] =?UTF-8?q?Fix=EF=BC=9A=E4=BF=AE=E5=A4=8D=E5=88=87?= =?UTF-8?q?=E6=8D=A2=E4=B8=BB=E9=A2=98=E6=97=B6=E8=8A=82=E7=82=B9=E6=A0=B7?= =?UTF-8?q?=E5=BC=8F=E6=B2=A1=E6=9C=89=E9=9A=8F=E4=B9=8B=E5=88=87=E6=8D=A2?= =?UTF-8?q?=E7=9A=84=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- simple-mind-map/src/constants/constant.js | 20 +++++++++++++++++++ simple-mind-map/src/core/render/node/Node.js | 5 +++++ simple-mind-map/src/core/render/node/Style.js | 13 +++++++++++- .../core/render/node/nodeCreateContents.js | 12 ++++++++++- simple-mind-map/src/plugins/RichText.js | 9 +++++++-- 5 files changed, 55 insertions(+), 4 deletions(-) diff --git a/simple-mind-map/src/constants/constant.js b/simple-mind-map/src/constants/constant.js index 6505b71d..a441e99d 100644 --- a/simple-mind-map/src/constants/constant.js +++ b/simple-mind-map/src/constants/constant.js @@ -259,4 +259,24 @@ export const layoutValueList = [ CONSTANTS.LAYOUT.TIMELINE, CONSTANTS.LAYOUT.TIMELINE2, CONSTANTS.LAYOUT.FISHBONE +] + +// 节点数据中非样式的字段 +export const nodeDataNoStylePropList = [ + 'text', + 'image', + 'imageTitle', + 'imageSize', + 'icon', + 'tag', + 'hyperlink', + 'hyperlinkTitle', + 'note', + 'expand', + 'isActive', + 'generalization', + 'richText', + 'resetRichText', + 'uid', + 'activeStyle' ] \ No newline at end of file diff --git a/simple-mind-map/src/core/render/node/Node.js b/simple-mind-map/src/core/render/node/Node.js index d92c9f72..3d2bab6f 100644 --- a/simple-mind-map/src/core/render/node/Node.js +++ b/simple-mind-map/src/core/render/node/Node.js @@ -798,6 +798,11 @@ class Node { getData(key) { return key ? this.nodeData.data[key] || '' : this.nodeData.data } + + // 是否存在自定义样式 + hasCustomStyle() { + return this.style.hasCustomStyle() + } } export default Node diff --git a/simple-mind-map/src/core/render/node/Style.js b/simple-mind-map/src/core/render/node/Style.js index f6816580..99e7def9 100644 --- a/simple-mind-map/src/core/render/node/Style.js +++ b/simple-mind-map/src/core/render/node/Style.js @@ -1,4 +1,4 @@ -import { tagColorList } from '../../../constants/constant' +import { tagColorList, nodeDataNoStylePropList } from '../../../constants/constant' const rootProp = ['paddingX', 'paddingY'] const backgroundStyleProps = ['backgroundColor', 'backgroundImage', 'backgroundRepeat', 'backgroundPosition', 'backgroundSize'] @@ -209,6 +209,17 @@ class Style { node2.fill({ color: color }) fillNode.fill({ color: fill }) } + + // 是否设置了自定义的样式 + hasCustomStyle() { + let res = false + Object.keys(this.ctx.nodeData.data).forEach((item) => { + if (!nodeDataNoStylePropList.includes(item)) { + res = true + } + }) + return res + } } Style.cacheStyle = null diff --git a/simple-mind-map/src/core/render/node/nodeCreateContents.js b/simple-mind-map/src/core/render/node/nodeCreateContents.js index c5231e71..e175455f 100644 --- a/simple-mind-map/src/core/render/node/nodeCreateContents.js +++ b/simple-mind-map/src/core/render/node/nodeCreateContents.js @@ -64,8 +64,18 @@ function createIconNode() { function createRichTextNode() { let g = new G() // 重新设置富文本节点内容 - if (this.nodeData.data.resetRichText || [CONSTANTS.CHANGE_THEME].includes(this.mindMap.renderer.renderSource)) { + let recoverText = false + if (this.nodeData.data.resetRichText) { delete this.nodeData.data.resetRichText + recoverText = true + } + if ([CONSTANTS.CHANGE_THEME].includes(this.mindMap.renderer.renderSource)) { + // 如果自定义过样式则不允许覆盖 + if (!this.hasCustomStyle()) { + recoverText = true + } + } + if (recoverText) { let text = getTextFromHtml(this.nodeData.data.text) this.nodeData.data.text = `
${text}
` } diff --git a/simple-mind-map/src/plugins/RichText.js b/simple-mind-map/src/plugins/RichText.js index ab5eca67..47cc9ecd 100644 --- a/simple-mind-map/src/plugins/RichText.js +++ b/simple-mind-map/src/plugins/RichText.js @@ -219,7 +219,7 @@ class RichText { underline: node.style.merge('textDecoration') === 'underline', strike: node.style.merge('textDecoration') === 'line-through' } - this.formatAllText(style) + this.pureFormatAllText(style) } // 获取当前正在编辑的内容 @@ -325,7 +325,7 @@ class RichText { // 中文输入结束 onCompositionEnd() { - if (!this.showTextEdit) { + if (!this.showTextEdit || !this.lostStyle) { return } this.isCompositing = false @@ -372,6 +372,11 @@ class RichText { // 格式化所有文本 formatAllText(config = {}) { this.syncFormatToNodeConfig(config) + this.pureFormatAllText(config) + } + + // 纯粹的格式化所有文本 + pureFormatAllText(config = {}) { this.quill.formatText(0, this.quill.getLength(), config) }