Merge branch 'feature' into tag_color

This commit is contained in:
街角小林 2023-09-23 10:34:38 +08:00 committed by GitHub
commit 2a816f62fa
3 changed files with 28 additions and 6 deletions

View File

@ -2,7 +2,8 @@
"name": "simple-mind-map",
"version": "0.7.1-fix.2",
"description": "一个简单的web在线思维导图",
"authors": [{
"authors": [
{
"name": "街角小林",
"email": "1013335014@qq.com"
},
@ -49,4 +50,4 @@
"eslint": "^8.25.0",
"prettier": "^2.7.1"
}
}
}

View File

@ -1,4 +1,10 @@
import { getStrWithBrFromHtml, checkNodeOuter, focusInput, selectAllInput } from '../../utils'
import {
getStrWithBrFromHtml,
checkNodeOuter,
focusInput,
selectAllInput,
htmlEscape
} from '../../utils'
import { ERROR_TYPES } from '../../constants/constant'
// 节点文字编辑类
@ -167,9 +173,11 @@ export default class TextEdit {
let scale = this.mindMap.view.scale
let lineHeight = node.style.merge('lineHeight')
let fontSize = node.style.merge('fontSize')
let textLines = (this.cacheEditingText || node.nodeData.data.text).split(
/\n/gim
)
let textLines = (this.cacheEditingText || node.nodeData.data.text)
.split(/\n/gim)
.map(item => {
return htmlEscape(item)
})
let isMultiLine = node._textData.node.attr('data-ismultiLine') === 'true'
node.style.domText(this.textEditNode, scale, isMultiLine)
this.textEditNode.style.zIndex = nodeTextEditZIndex

View File

@ -798,6 +798,7 @@ export const getNodeIndex = node => {
: 0
}
// 根据内容生成颜色
export const generateColorByContent = str => {
let hash = 0
@ -811,3 +812,15 @@ export const generateColorByContent = str => {
const h = rng.genrand_int32() % 360
return 'hsla(' + h + ', 50%, 50%, 1)'
}
// html转义
export const htmlEscape = str => {
;[
['&', '&'],
['<', '&lt;'],
['>', '&gt;']
].forEach(item => {
str = str.replace(new RegExp(item[0], 'g'), item[1])
})
return str
}