Feat:富文本插件增加对老版本数据的处理

This commit is contained in:
街角小林
2024-12-25 18:28:00 +08:00
parent 3642763301
commit 628a6b72a2
2 changed files with 36 additions and 6 deletions

View File

@@ -9,7 +9,8 @@ import {
formatGetNodeGeneralization,
nodeRichTextToTextWithWrap,
getNodeRichTextStyles,
htmlEscape
htmlEscape,
compareVersion
} from '../utils'
import { CONSTANTS, richTextSupportStyleList } from '../constants/constant'
import MindMapNode from '../core/render/node/MindMapNode'
@@ -762,22 +763,29 @@ class RichText {
}
handleDataToRichText(data) {
const oldIsRichText = data.richText
data.richText = true
data.resetRichText = true
data.text = htmlEscape(data.text)
// 如果原本就是富文本,那么不能转换
if (!oldIsRichText) {
data.text = htmlEscape(data.text)
}
}
// 处理导入数据
handleSetData(data) {
// 短期处理,为了兼容老数据,长期会去除
const isOldRichTextVersion =
!data.smmVersion || compareVersion(data.smmVersion, '0.13.0') === '<'
const walk = root => {
if (root.data && !root.data.richText) {
if (root.data && (!root.data.richText || isOldRichTextVersion)) {
this.handleDataToRichText(root.data)
}
// 概要
if (root.data) {
const generalizationList = formatGetNodeGeneralization(root.data)
generalizationList.forEach(item => {
if (!item.richText) {
if (!item.richText || isOldRichTextVersion) {
this.handleDataToRichText(item)
}
})

View File

@@ -175,7 +175,7 @@ export const copyRenderTree = (tree, root, removeActiveState = false) => {
})
}
// data、children外的其他字段
Object.keys(root).forEach((key) => {
Object.keys(root).forEach(key => {
if (!['data', 'children'].includes(key) && !/^_/.test(key)) {
tree[key] = root[key]
}
@@ -216,7 +216,7 @@ export const copyNodeTree = (
})
}
// data、children外的其他字段
Object.keys(root).forEach((key) => {
Object.keys(root).forEach(key => {
if (!['data', 'children'].includes(key) && !/^_/.test(key)) {
tree[key] = root[key]
}
@@ -1673,3 +1673,25 @@ export const getNodeRichTextStyles = node => {
})
return res
}
// 判断两个版本号的关系
/*
a > b 返回 >
a < b 返回 <
a = b 返回 =
*/
export const compareVersion = (a, b) => {
const aArr = String(a).split('.')
const bArr = String(b).split('.')
const max = Math.max(aArr.length, bArr.length)
for (let i = 0; i < max; i++) {
const ai = aArr[i] || 0
const bi = bArr[i] || 0
if (ai > bi) {
return '>'
} else if (ai < bi) {
return '<'
}
}
return '='
}