Fix:修复同时创建多个实例时,文本编辑后节点宽高丢失的问题
This commit is contained in:
parent
487aa38216
commit
088fd398a9
@ -10,7 +10,6 @@ import BatchExecution from './src/utils/BatchExecution'
|
|||||||
import {
|
import {
|
||||||
layoutValueList,
|
layoutValueList,
|
||||||
CONSTANTS,
|
CONSTANTS,
|
||||||
commonCaches,
|
|
||||||
ERROR_TYPES,
|
ERROR_TYPES,
|
||||||
cssContent
|
cssContent
|
||||||
} from './src/constants/constant'
|
} from './src/constants/constant'
|
||||||
@ -228,19 +227,10 @@ class MindMap {
|
|||||||
|
|
||||||
// 初始化缓存数据
|
// 初始化缓存数据
|
||||||
initCache() {
|
initCache() {
|
||||||
Object.keys(commonCaches).forEach(key => {
|
this.commonCaches = {
|
||||||
let type = getType(commonCaches[key])
|
measureCustomNodeContentSizeEl: null,
|
||||||
let value = ''
|
measureRichtextNodeTextSizeEl: null
|
||||||
switch (type) {
|
}
|
||||||
case 'Boolean':
|
|
||||||
value = false
|
|
||||||
break
|
|
||||||
default:
|
|
||||||
value = null
|
|
||||||
break
|
|
||||||
}
|
|
||||||
commonCaches[key] = value
|
|
||||||
})
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// 设置主题
|
// 设置主题
|
||||||
|
|||||||
@ -317,12 +317,6 @@ export const nodeDataNoStylePropList = [
|
|||||||
'attachmentName'
|
'attachmentName'
|
||||||
]
|
]
|
||||||
|
|
||||||
// 数据缓存
|
|
||||||
export const commonCaches = {
|
|
||||||
measureCustomNodeContentSizeEl: null,
|
|
||||||
measureRichtextNodeTextSizeEl: null
|
|
||||||
}
|
|
||||||
|
|
||||||
// 错误类型
|
// 错误类型
|
||||||
export const ERROR_TYPES = {
|
export const ERROR_TYPES = {
|
||||||
READ_CLIPBOARD_ERROR: 'read_clipboard_error',
|
READ_CLIPBOARD_ERROR: 'read_clipboard_error',
|
||||||
|
|||||||
@ -16,7 +16,7 @@ import {
|
|||||||
ForeignObject
|
ForeignObject
|
||||||
} from '@svgdotjs/svg.js'
|
} from '@svgdotjs/svg.js'
|
||||||
import iconsSvg from '../../../svg/icons'
|
import iconsSvg from '../../../svg/icons'
|
||||||
import { CONSTANTS, commonCaches } from '../../../constants/constant'
|
import { CONSTANTS } from '../../../constants/constant'
|
||||||
|
|
||||||
// 创建图片节点
|
// 创建图片节点
|
||||||
function createImgNode() {
|
function createImgNode() {
|
||||||
@ -149,13 +149,13 @@ function createRichTextNode() {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
let html = `<div>${this.getData('text')}</div>`
|
let html = `<div>${this.getData('text')}</div>`
|
||||||
if (!commonCaches.measureRichtextNodeTextSizeEl) {
|
if (!this.mindMap.commonCaches.measureRichtextNodeTextSizeEl) {
|
||||||
commonCaches.measureRichtextNodeTextSizeEl = document.createElement('div')
|
this.mindMap.commonCaches.measureRichtextNodeTextSizeEl = document.createElement('div')
|
||||||
commonCaches.measureRichtextNodeTextSizeEl.style.position = 'fixed'
|
this.mindMap.commonCaches.measureRichtextNodeTextSizeEl.style.position = 'fixed'
|
||||||
commonCaches.measureRichtextNodeTextSizeEl.style.left = '-999999px'
|
this.mindMap.commonCaches.measureRichtextNodeTextSizeEl.style.left = '-999999px'
|
||||||
this.mindMap.el.appendChild(commonCaches.measureRichtextNodeTextSizeEl)
|
this.mindMap.el.appendChild(this.mindMap.commonCaches.measureRichtextNodeTextSizeEl)
|
||||||
}
|
}
|
||||||
let div = commonCaches.measureRichtextNodeTextSizeEl
|
let div = this.mindMap.commonCaches.measureRichtextNodeTextSizeEl
|
||||||
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')
|
||||||
@ -413,18 +413,18 @@ function getNoteContentPosition() {
|
|||||||
|
|
||||||
// 测量自定义节点内容元素的宽高
|
// 测量自定义节点内容元素的宽高
|
||||||
function measureCustomNodeContentSize(content) {
|
function measureCustomNodeContentSize(content) {
|
||||||
if (!commonCaches.measureCustomNodeContentSizeEl) {
|
if (!this.mindMap.commonCaches.measureCustomNodeContentSizeEl) {
|
||||||
commonCaches.measureCustomNodeContentSizeEl = document.createElement('div')
|
this.mindMap.commonCaches.measureCustomNodeContentSizeEl = document.createElement('div')
|
||||||
commonCaches.measureCustomNodeContentSizeEl.style.cssText = `
|
this.mindMap.commonCaches.measureCustomNodeContentSizeEl.style.cssText = `
|
||||||
position: fixed;
|
position: fixed;
|
||||||
left: -99999px;
|
left: -99999px;
|
||||||
top: -99999px;
|
top: -99999px;
|
||||||
`
|
`
|
||||||
this.mindMap.el.appendChild(commonCaches.measureCustomNodeContentSizeEl)
|
this.mindMap.el.appendChild(this.mindMap.commonCaches.measureCustomNodeContentSizeEl)
|
||||||
}
|
}
|
||||||
commonCaches.measureCustomNodeContentSizeEl.innerHTML = ''
|
this.mindMap.commonCaches.measureCustomNodeContentSizeEl.innerHTML = ''
|
||||||
commonCaches.measureCustomNodeContentSizeEl.appendChild(content)
|
this.mindMap.commonCaches.measureCustomNodeContentSizeEl.appendChild(content)
|
||||||
let rect = commonCaches.measureCustomNodeContentSizeEl.getBoundingClientRect()
|
let rect = this.mindMap.commonCaches.measureCustomNodeContentSizeEl.getBoundingClientRect()
|
||||||
return {
|
return {
|
||||||
width: rect.width,
|
width: rect.width,
|
||||||
height: rect.height
|
height: rect.height
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user