Fix:修复节点前后自定义内容导出图片时显示空白的问题
This commit is contained in:
parent
b8a23beba4
commit
79755e80b9
@ -11,7 +11,8 @@ import { CONSTANTS } from '../../../constants/constant'
|
|||||||
import {
|
import {
|
||||||
copyNodeTree,
|
copyNodeTree,
|
||||||
createForeignObjectNode,
|
createForeignObjectNode,
|
||||||
createUid
|
createUid,
|
||||||
|
addXmlns
|
||||||
} from '../../../utils/index'
|
} from '../../../utils/index'
|
||||||
|
|
||||||
// 节点类
|
// 节点类
|
||||||
@ -204,10 +205,7 @@ class Node {
|
|||||||
}
|
}
|
||||||
// 如果没有返回内容,那么还是使用内置的节点内容
|
// 如果没有返回内容,那么还是使用内置的节点内容
|
||||||
if (this._customNodeContent) {
|
if (this._customNodeContent) {
|
||||||
this._customNodeContent.setAttribute(
|
addXmlns(this._customNodeContent)
|
||||||
'xmlns',
|
|
||||||
'http://www.w3.org/1999/xhtml'
|
|
||||||
)
|
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
this._imgData = this.createImgNode()
|
this._imgData = this.createImgNode()
|
||||||
@ -220,9 +218,15 @@ class Node {
|
|||||||
this._prefixData = createNodePrefixContent
|
this._prefixData = createNodePrefixContent
|
||||||
? createNodePrefixContent(this)
|
? createNodePrefixContent(this)
|
||||||
: null
|
: null
|
||||||
|
if (this._prefixData && this._prefixData.el) {
|
||||||
|
addXmlns(this._prefixData.el)
|
||||||
|
}
|
||||||
this._postfixData = createNodePostfixContent
|
this._postfixData = createNodePostfixContent
|
||||||
? createNodePostfixContent(this)
|
? createNodePostfixContent(this)
|
||||||
: null
|
: null
|
||||||
|
if (this._postfixData && this._postfixData.el) {
|
||||||
|
addXmlns(this._postfixData.el)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// 计算节点的宽高
|
// 计算节点的宽高
|
||||||
|
|||||||
@ -5,7 +5,8 @@ import {
|
|||||||
addHtmlStyle,
|
addHtmlStyle,
|
||||||
checkIsRichText,
|
checkIsRichText,
|
||||||
isUndef,
|
isUndef,
|
||||||
createForeignObjectNode
|
createForeignObjectNode,
|
||||||
|
addXmlns
|
||||||
} from '../../../utils'
|
} from '../../../utils'
|
||||||
import { Image as SVGImage, SVG, A, G, Rect, Text } from '@svgdotjs/svg.js'
|
import { Image as SVGImage, SVG, A, G, Rect, Text } from '@svgdotjs/svg.js'
|
||||||
import iconsSvg from '../../../svg/icons'
|
import iconsSvg from '../../../svg/icons'
|
||||||
@ -157,7 +158,7 @@ function createRichTextNode() {
|
|||||||
div.innerHTML = html
|
div.innerHTML = html
|
||||||
let el = div.children[0]
|
let el = div.children[0]
|
||||||
el.classList.add('smm-richtext-node-wrap')
|
el.classList.add('smm-richtext-node-wrap')
|
||||||
el.setAttribute('xmlns', 'http://www.w3.org/1999/xhtml')
|
addXmlns(el)
|
||||||
el.style.maxWidth = textAutoWrapWidth + 'px'
|
el.style.maxWidth = textAutoWrapWidth + 'px'
|
||||||
let { width, height } = el.getBoundingClientRect()
|
let { width, height } = el.getBoundingClientRect()
|
||||||
// 如果文本为空,那么需要计算一个默认高度
|
// 如果文本为空,那么需要计算一个默认高度
|
||||||
|
|||||||
@ -1335,7 +1335,7 @@ export const handleGetSvgDataExtraContent = ({
|
|||||||
if (!res) return
|
if (!res) return
|
||||||
const { el, cssText, height } = res
|
const { el, cssText, height } = res
|
||||||
if (el instanceof HTMLElement) {
|
if (el instanceof HTMLElement) {
|
||||||
el.setAttribute('xmlns', 'http://www.w3.org/1999/xhtml')
|
addXmlns(el)
|
||||||
const foreignObject = createForeignObjectNode({ el, height })
|
const foreignObject = createForeignObjectNode({ el, height })
|
||||||
callback(foreignObject, height)
|
callback(foreignObject, height)
|
||||||
}
|
}
|
||||||
@ -1525,3 +1525,8 @@ export const defenseXSS = text => {
|
|||||||
// 返回最终结果
|
// 返回最终结果
|
||||||
return result
|
return result
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 给节点添加命名空间
|
||||||
|
export const addXmlns = el => {
|
||||||
|
el.setAttribute('xmlns', 'http://www.w3.org/1999/xhtml')
|
||||||
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user