Fix:修复节点前后自定义内容导出图片时显示空白的问题

This commit is contained in:
街角小林 2024-06-04 16:30:23 +08:00
parent b8a23beba4
commit 79755e80b9
3 changed files with 18 additions and 8 deletions

View File

@ -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)
}
}
// 计算节点的宽高

View File

@ -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()
// 如果文本为空,那么需要计算一个默认高度

View File

@ -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')
}