Fix:修复自定义节点内容时,二次创建根实例时节点内容不渲染的问题
This commit is contained in:
parent
4b2ebb2e1c
commit
8e30d4a94f
@ -7,9 +7,9 @@ import Style from './src/core/render/node/Style'
|
|||||||
import KeyCommand from './src/core/command/KeyCommand'
|
import KeyCommand from './src/core/command/KeyCommand'
|
||||||
import Command from './src/core/command/Command'
|
import Command from './src/core/command/Command'
|
||||||
import BatchExecution from './src/utils/BatchExecution'
|
import BatchExecution from './src/utils/BatchExecution'
|
||||||
import { layoutValueList, CONSTANTS } from './src/constants/constant'
|
import { layoutValueList, CONSTANTS, commonCaches } from './src/constants/constant'
|
||||||
import { SVG } from '@svgdotjs/svg.js'
|
import { SVG } from '@svgdotjs/svg.js'
|
||||||
import { simpleDeepClone } from './src/utils'
|
import { simpleDeepClone, getType } from './src/utils'
|
||||||
import defaultTheme, { checkIsNodeSizeIndependenceConfig } from './src/themes/default'
|
import defaultTheme, { checkIsNodeSizeIndependenceConfig } from './src/themes/default'
|
||||||
import { defaultOpt } from './src/constants/defaultOptions'
|
import { defaultOpt } from './src/constants/defaultOptions'
|
||||||
|
|
||||||
@ -35,6 +35,9 @@ class MindMap {
|
|||||||
// 初始化主题
|
// 初始化主题
|
||||||
this.initTheme()
|
this.initTheme()
|
||||||
|
|
||||||
|
// 初始化缓存数据
|
||||||
|
this.initCache()
|
||||||
|
|
||||||
// 事件类
|
// 事件类
|
||||||
this.event = new Event({
|
this.event = new Event({
|
||||||
mindMap: this
|
mindMap: this
|
||||||
@ -129,6 +132,23 @@ class MindMap {
|
|||||||
this.event.off(event, fn)
|
this.event.off(event, fn)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 初始化缓存数据
|
||||||
|
initCache() {
|
||||||
|
Object.keys(commonCaches).forEach((key) => {
|
||||||
|
let type = getType(commonCaches[key])
|
||||||
|
let value = ''
|
||||||
|
switch(type) {
|
||||||
|
case 'Boolean':
|
||||||
|
value = false
|
||||||
|
break
|
||||||
|
default:
|
||||||
|
value = null
|
||||||
|
break
|
||||||
|
}
|
||||||
|
commonCaches[key] = value
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
// 设置主题
|
// 设置主题
|
||||||
initTheme() {
|
initTheme() {
|
||||||
// 合并主题配置
|
// 合并主题配置
|
||||||
|
|||||||
@ -325,3 +325,8 @@ export const nodeDataNoStylePropList = [
|
|||||||
'uid',
|
'uid',
|
||||||
'activeStyle'
|
'activeStyle'
|
||||||
]
|
]
|
||||||
|
|
||||||
|
// 数据缓存
|
||||||
|
export const commonCaches = {
|
||||||
|
measureCustomNodeContentSizeEl: null
|
||||||
|
}
|
||||||
@ -1,7 +1,7 @@
|
|||||||
import { measureText, resizeImgSize, getTextFromHtml } from '../../../utils'
|
import { measureText, resizeImgSize, getTextFromHtml } from '../../../utils'
|
||||||
import { Image, SVG, A, G, Rect, Text, ForeignObject } from '@svgdotjs/svg.js'
|
import { Image, SVG, A, G, Rect, Text, ForeignObject } from '@svgdotjs/svg.js'
|
||||||
import iconsSvg from '../../../svg/icons'
|
import iconsSvg from '../../../svg/icons'
|
||||||
import { CONSTANTS } from '../../../constants/constant'
|
import { CONSTANTS, commonCaches } from '../../../constants/constant'
|
||||||
|
|
||||||
// 创建图片节点
|
// 创建图片节点
|
||||||
function createImgNode() {
|
function createImgNode() {
|
||||||
@ -293,20 +293,19 @@ function createNoteNode() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// 测量自定义节点内容元素的宽高
|
// 测量自定义节点内容元素的宽高
|
||||||
let warpEl = null
|
|
||||||
function measureCustomNodeContentSize (content) {
|
function measureCustomNodeContentSize (content) {
|
||||||
if (!warpEl) {
|
if (!commonCaches.measureCustomNodeContentSizeEl) {
|
||||||
warpEl = document.createElement('div')
|
commonCaches.measureCustomNodeContentSizeEl = document.createElement('div')
|
||||||
warpEl.style.cssText = `
|
commonCaches.measureCustomNodeContentSizeEl.style.cssText = `
|
||||||
position: fixed;
|
position: fixed;
|
||||||
left: -99999px;
|
left: -99999px;
|
||||||
top: -99999px;
|
top: -99999px;
|
||||||
`
|
`
|
||||||
this.mindMap.el.appendChild(warpEl)
|
this.mindMap.el.appendChild(commonCaches.measureCustomNodeContentSizeEl)
|
||||||
}
|
}
|
||||||
warpEl.innerHTML = ''
|
commonCaches.measureCustomNodeContentSizeEl.innerHTML = ''
|
||||||
warpEl.appendChild(content)
|
commonCaches.measureCustomNodeContentSizeEl.appendChild(content)
|
||||||
let rect = warpEl.getBoundingClientRect()
|
let rect = commonCaches.measureCustomNodeContentSizeEl.getBoundingClientRect()
|
||||||
return {
|
return {
|
||||||
width: rect.width,
|
width: rect.width,
|
||||||
height: rect.height
|
height: rect.height
|
||||||
|
|||||||
@ -461,3 +461,8 @@ export const removeHTMLEntities = (str) => {
|
|||||||
})
|
})
|
||||||
return str
|
return str
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 获取一个数据的类型
|
||||||
|
export const getType = (data) => {
|
||||||
|
return Object.prototype.toString.call(data).slice(7, -1)
|
||||||
|
}
|
||||||
Loading…
x
Reference in New Issue
Block a user