From 79755e80b917d42eaf3ac6f3e86fd57486534e59 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, 4 Jun 2024 16:30:23 +0800 Subject: [PATCH] =?UTF-8?q?Fix=EF=BC=9A=E4=BF=AE=E5=A4=8D=E8=8A=82?= =?UTF-8?q?=E7=82=B9=E5=89=8D=E5=90=8E=E8=87=AA=E5=AE=9A=E4=B9=89=E5=86=85?= =?UTF-8?q?=E5=AE=B9=E5=AF=BC=E5=87=BA=E5=9B=BE=E7=89=87=E6=97=B6=E6=98=BE?= =?UTF-8?q?=E7=A4=BA=E7=A9=BA=E7=99=BD=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/core/render/node/Node.js | 14 +++++++++----- .../src/core/render/node/nodeCreateContents.js | 5 +++-- simple-mind-map/src/utils/index.js | 7 ++++++- 3 files changed, 18 insertions(+), 8 deletions(-) diff --git a/simple-mind-map/src/core/render/node/Node.js b/simple-mind-map/src/core/render/node/Node.js index 4468e714..8c17fdea 100644 --- a/simple-mind-map/src/core/render/node/Node.js +++ b/simple-mind-map/src/core/render/node/Node.js @@ -11,7 +11,8 @@ import { CONSTANTS } from '../../../constants/constant' import { copyNodeTree, createForeignObjectNode, - createUid + createUid, + addXmlns } from '../../../utils/index' // 节点类 @@ -204,10 +205,7 @@ class Node { } // 如果没有返回内容,那么还是使用内置的节点内容 if (this._customNodeContent) { - this._customNodeContent.setAttribute( - 'xmlns', - 'http://www.w3.org/1999/xhtml' - ) + addXmlns(this._customNodeContent) return } this._imgData = this.createImgNode() @@ -220,9 +218,15 @@ class Node { this._prefixData = createNodePrefixContent ? createNodePrefixContent(this) : null + if (this._prefixData && this._prefixData.el) { + addXmlns(this._prefixData.el) + } this._postfixData = createNodePostfixContent ? createNodePostfixContent(this) : null + if (this._postfixData && this._postfixData.el) { + addXmlns(this._postfixData.el) + } } // 计算节点的宽高 diff --git a/simple-mind-map/src/core/render/node/nodeCreateContents.js b/simple-mind-map/src/core/render/node/nodeCreateContents.js index dbc1876a..ae6138e0 100644 --- a/simple-mind-map/src/core/render/node/nodeCreateContents.js +++ b/simple-mind-map/src/core/render/node/nodeCreateContents.js @@ -5,7 +5,8 @@ import { addHtmlStyle, checkIsRichText, isUndef, - createForeignObjectNode + createForeignObjectNode, + addXmlns } from '../../../utils' import { Image as SVGImage, SVG, A, G, Rect, Text } from '@svgdotjs/svg.js' import iconsSvg from '../../../svg/icons' @@ -157,7 +158,7 @@ function createRichTextNode() { div.innerHTML = html let el = div.children[0] el.classList.add('smm-richtext-node-wrap') - el.setAttribute('xmlns', 'http://www.w3.org/1999/xhtml') + addXmlns(el) el.style.maxWidth = textAutoWrapWidth + 'px' let { width, height } = el.getBoundingClientRect() // 如果文本为空,那么需要计算一个默认高度 diff --git a/simple-mind-map/src/utils/index.js b/simple-mind-map/src/utils/index.js index 842e3cea..78e7266d 100644 --- a/simple-mind-map/src/utils/index.js +++ b/simple-mind-map/src/utils/index.js @@ -1335,7 +1335,7 @@ export const handleGetSvgDataExtraContent = ({ if (!res) return const { el, cssText, height } = res if (el instanceof HTMLElement) { - el.setAttribute('xmlns', 'http://www.w3.org/1999/xhtml') + addXmlns(el) const foreignObject = createForeignObjectNode({ el, height }) callback(foreignObject, height) } @@ -1525,3 +1525,8 @@ export const defenseXSS = text => { // 返回最终结果 return result } + +// 给节点添加命名空间 +export const addXmlns = el => { + el.setAttribute('xmlns', 'http://www.w3.org/1999/xhtml') +}