diff --git a/simple-mind-map/index.js b/simple-mind-map/index.js index 23db2ceb..b1a75161 100644 --- a/simple-mind-map/index.js +++ b/simple-mind-map/index.js @@ -10,7 +10,6 @@ import BatchExecution from './src/utils/BatchExecution' import { layoutValueList, CONSTANTS, - commonCaches, ERROR_TYPES, cssContent } from './src/constants/constant' @@ -228,19 +227,10 @@ class MindMap { // 初始化缓存数据 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 - }) + this.commonCaches = { + measureCustomNodeContentSizeEl: null, + measureRichtextNodeTextSizeEl: null + } } // 设置主题 diff --git a/simple-mind-map/src/constants/constant.js b/simple-mind-map/src/constants/constant.js index 6778376e..b4b227d3 100644 --- a/simple-mind-map/src/constants/constant.js +++ b/simple-mind-map/src/constants/constant.js @@ -317,12 +317,6 @@ export const nodeDataNoStylePropList = [ 'attachmentName' ] -// 数据缓存 -export const commonCaches = { - measureCustomNodeContentSizeEl: null, - measureRichtextNodeTextSizeEl: null -} - // 错误类型 export const ERROR_TYPES = { READ_CLIPBOARD_ERROR: 'read_clipboard_error', diff --git a/simple-mind-map/src/core/render/node/nodeCreateContents.js b/simple-mind-map/src/core/render/node/nodeCreateContents.js index 20fda808..cd2dd183 100644 --- a/simple-mind-map/src/core/render/node/nodeCreateContents.js +++ b/simple-mind-map/src/core/render/node/nodeCreateContents.js @@ -16,7 +16,7 @@ import { ForeignObject } from '@svgdotjs/svg.js' import iconsSvg from '../../../svg/icons' -import { CONSTANTS, commonCaches } from '../../../constants/constant' +import { CONSTANTS } from '../../../constants/constant' // 创建图片节点 function createImgNode() { @@ -149,13 +149,13 @@ function createRichTextNode() { }) } let html = `
${this.getData('text')}
` - if (!commonCaches.measureRichtextNodeTextSizeEl) { - commonCaches.measureRichtextNodeTextSizeEl = document.createElement('div') - commonCaches.measureRichtextNodeTextSizeEl.style.position = 'fixed' - commonCaches.measureRichtextNodeTextSizeEl.style.left = '-999999px' - this.mindMap.el.appendChild(commonCaches.measureRichtextNodeTextSizeEl) + if (!this.mindMap.commonCaches.measureRichtextNodeTextSizeEl) { + this.mindMap.commonCaches.measureRichtextNodeTextSizeEl = document.createElement('div') + this.mindMap.commonCaches.measureRichtextNodeTextSizeEl.style.position = 'fixed' + this.mindMap.commonCaches.measureRichtextNodeTextSizeEl.style.left = '-999999px' + this.mindMap.el.appendChild(this.mindMap.commonCaches.measureRichtextNodeTextSizeEl) } - let div = commonCaches.measureRichtextNodeTextSizeEl + let div = this.mindMap.commonCaches.measureRichtextNodeTextSizeEl div.innerHTML = html let el = div.children[0] el.classList.add('smm-richtext-node-wrap') @@ -413,18 +413,18 @@ function getNoteContentPosition() { // 测量自定义节点内容元素的宽高 function measureCustomNodeContentSize(content) { - if (!commonCaches.measureCustomNodeContentSizeEl) { - commonCaches.measureCustomNodeContentSizeEl = document.createElement('div') - commonCaches.measureCustomNodeContentSizeEl.style.cssText = ` + if (!this.mindMap.commonCaches.measureCustomNodeContentSizeEl) { + this.mindMap.commonCaches.measureCustomNodeContentSizeEl = document.createElement('div') + this.mindMap.commonCaches.measureCustomNodeContentSizeEl.style.cssText = ` position: fixed; left: -99999px; top: -99999px; ` - this.mindMap.el.appendChild(commonCaches.measureCustomNodeContentSizeEl) + this.mindMap.el.appendChild(this.mindMap.commonCaches.measureCustomNodeContentSizeEl) } - commonCaches.measureCustomNodeContentSizeEl.innerHTML = '' - commonCaches.measureCustomNodeContentSizeEl.appendChild(content) - let rect = commonCaches.measureCustomNodeContentSizeEl.getBoundingClientRect() + this.mindMap.commonCaches.measureCustomNodeContentSizeEl.innerHTML = '' + this.mindMap.commonCaches.measureCustomNodeContentSizeEl.appendChild(content) + let rect = this.mindMap.commonCaches.measureCustomNodeContentSizeEl.getBoundingClientRect() return { width: rect.width, height: rect.height