Feat:非富文本模式文本编辑框的样式同步节点样式
This commit is contained in:
parent
eb342bf69b
commit
c2125b07ca
@ -6,7 +6,9 @@ import {
|
|||||||
htmlEscape,
|
htmlEscape,
|
||||||
handleInputPasteText,
|
handleInputPasteText,
|
||||||
checkSmmFormatData,
|
checkSmmFormatData,
|
||||||
getTextFromHtml
|
getTextFromHtml,
|
||||||
|
isWhite,
|
||||||
|
getVisibleColorFromTheme
|
||||||
} from '../../utils'
|
} from '../../utils'
|
||||||
import {
|
import {
|
||||||
ERROR_TYPES,
|
ERROR_TYPES,
|
||||||
@ -218,9 +220,11 @@ export default class TextEdit {
|
|||||||
openRealtimeRenderOnNodeTextEdit
|
openRealtimeRenderOnNodeTextEdit
|
||||||
) {
|
) {
|
||||||
if (!this.textEditNode) return
|
if (!this.textEditNode) return
|
||||||
this.textEditNode.style.backgroundColor = openRealtimeRenderOnNodeTextEdit
|
this.textEditNode.style.background = openRealtimeRenderOnNodeTextEdit
|
||||||
? 'transparent'
|
? 'transparent'
|
||||||
: '#fff'
|
: this.currentNode
|
||||||
|
? this.getBackground(this.currentNode)
|
||||||
|
: ''
|
||||||
this.textEditNode.style.boxShadow = openRealtimeRenderOnNodeTextEdit
|
this.textEditNode.style.boxShadow = openRealtimeRenderOnNodeTextEdit
|
||||||
? 'none'
|
? 'none'
|
||||||
: '0 0 20px rgba(0,0,0,.5)'
|
: '0 0 20px rgba(0,0,0,.5)'
|
||||||
@ -266,14 +270,14 @@ export default class TextEdit {
|
|||||||
${
|
${
|
||||||
openRealtimeRenderOnNodeTextEdit
|
openRealtimeRenderOnNodeTextEdit
|
||||||
? ''
|
? ''
|
||||||
: `background-color:#fff;
|
: `box-shadow: 0 0 20px rgba(0,0,0,.5);`
|
||||||
box-shadow: 0 0 20px rgba(0,0,0,.5);`
|
|
||||||
}
|
}
|
||||||
padding: ${this.textNodePaddingY}px ${this.textNodePaddingX}px;
|
padding: ${this.textNodePaddingY}px ${this.textNodePaddingX}px;
|
||||||
margin-left: -${this.textNodePaddingX}px;
|
margin-left: -${this.textNodePaddingX}px;
|
||||||
margin-top: -${this.textNodePaddingY}px;
|
margin-top: -${this.textNodePaddingY}px;
|
||||||
outline: none;
|
outline: none;
|
||||||
word-break: break-all;
|
word-break: break-all;
|
||||||
|
line-break: anywhere;
|
||||||
`
|
`
|
||||||
this.textEditNode.setAttribute('contenteditable', true)
|
this.textEditNode.setAttribute('contenteditable', true)
|
||||||
this.textEditNode.addEventListener('keyup', e => {
|
this.textEditNode.addEventListener('keyup', e => {
|
||||||
@ -320,6 +324,9 @@ export default class TextEdit {
|
|||||||
})
|
})
|
||||||
const isMultiLine = node._textData.node.attr('data-ismultiLine') === 'true'
|
const isMultiLine = node._textData.node.attr('data-ismultiLine') === 'true'
|
||||||
node.style.domText(this.textEditNode, scale)
|
node.style.domText(this.textEditNode, scale)
|
||||||
|
if (!openRealtimeRenderOnNodeTextEdit) {
|
||||||
|
this.textEditNode.style.background = this.getBackground(node)
|
||||||
|
}
|
||||||
this.textEditNode.style.zIndex = nodeTextEditZIndex
|
this.textEditNode.style.zIndex = nodeTextEditZIndex
|
||||||
this.textEditNode.innerHTML = textLines.join('<br>')
|
this.textEditNode.innerHTML = textLines.join('<br>')
|
||||||
this.textEditNode.style.minWidth =
|
this.textEditNode.style.minWidth =
|
||||||
@ -370,6 +377,27 @@ export default class TextEdit {
|
|||||||
this.textEditNode.style.top = rect.top + 'px'
|
this.textEditNode.style.top = rect.top + 'px'
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 获取编辑区域的背景填充
|
||||||
|
getBackground(node) {
|
||||||
|
const gradientStyle = node.style.merge('gradientStyle')
|
||||||
|
// 当前使用的是渐变色背景
|
||||||
|
if (gradientStyle) {
|
||||||
|
const startColor = node.style.merge('startColor')
|
||||||
|
const endColor = node.style.merge('endColor')
|
||||||
|
return `linear-gradient(to right, ${startColor}, ${endColor})`
|
||||||
|
} else {
|
||||||
|
// 单色背景
|
||||||
|
const bgColor = node.style.merge('fillColor')
|
||||||
|
const color = node.style.merge('color')
|
||||||
|
// 默认使用节点的填充色,否则如果节点颜色是白色的话编辑时看不见
|
||||||
|
return bgColor === 'transparent'
|
||||||
|
? isWhite(color)
|
||||||
|
? getVisibleColorFromTheme(this.mindMap.themeConfig)
|
||||||
|
: '#fff'
|
||||||
|
: bgColor
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// 删除文本编辑元素
|
// 删除文本编辑元素
|
||||||
removeTextEditEl() {
|
removeTextEditEl() {
|
||||||
if (this.mindMap.richText) {
|
if (this.mindMap.richText) {
|
||||||
|
|||||||
@ -238,6 +238,8 @@ class Style {
|
|||||||
fontStyle: this.merge('fontStyle'),
|
fontStyle: this.merge('fontStyle'),
|
||||||
textDecoration: this.merge('textDecoration')
|
textDecoration: this.merge('textDecoration')
|
||||||
}
|
}
|
||||||
|
node.style.color = styles.color
|
||||||
|
node.style.textDecoration = styles.textDecoration
|
||||||
node.style.fontFamily = styles.fontFamily
|
node.style.fontFamily = styles.fontFamily
|
||||||
node.style.fontSize = styles.fontSize * fontSizeScale + 'px'
|
node.style.fontSize = styles.fontSize * fontSizeScale + 'px'
|
||||||
node.style.fontWeight = styles.fontWeight || 'normal'
|
node.style.fontWeight = styles.fontWeight || 'normal'
|
||||||
|
|||||||
@ -4,8 +4,6 @@ import 'quill/dist/quill.snow.css'
|
|||||||
import {
|
import {
|
||||||
walk,
|
walk,
|
||||||
getTextFromHtml,
|
getTextFromHtml,
|
||||||
isWhite,
|
|
||||||
getVisibleColorFromTheme,
|
|
||||||
isUndef,
|
isUndef,
|
||||||
checkSmmFormatData,
|
checkSmmFormatData,
|
||||||
removeHtmlNodeByClass,
|
removeHtmlNodeByClass,
|
||||||
@ -250,7 +248,8 @@ class RichText {
|
|||||||
this.textEditNode.style.marginTop = `-${paddingY * scaleY}px`
|
this.textEditNode.style.marginTop = `-${paddingY * scaleY}px`
|
||||||
this.textEditNode.style.zIndex = nodeTextEditZIndex
|
this.textEditNode.style.zIndex = nodeTextEditZIndex
|
||||||
if (!openRealtimeRenderOnNodeTextEdit) {
|
if (!openRealtimeRenderOnNodeTextEdit) {
|
||||||
this.textEditNode.style.background = this.getBackground(node)
|
this.textEditNode.style.background =
|
||||||
|
this.mindMap.renderer.textEdit.getBackground(node)
|
||||||
}
|
}
|
||||||
this.textEditNode.style.minWidth = originWidth + paddingX * 2 + 'px'
|
this.textEditNode.style.minWidth = originWidth + paddingX * 2 + 'px'
|
||||||
this.textEditNode.style.minHeight = originHeight + 'px'
|
this.textEditNode.style.minHeight = originHeight + 'px'
|
||||||
@ -312,7 +311,7 @@ class RichText {
|
|||||||
this.textEditNode.style.background = openRealtimeRenderOnNodeTextEdit
|
this.textEditNode.style.background = openRealtimeRenderOnNodeTextEdit
|
||||||
? 'transparent'
|
? 'transparent'
|
||||||
: this.node
|
: this.node
|
||||||
? this.getBackground(node)
|
? this.mindMap.renderer.textEdit.getBackground(this.node)
|
||||||
: ''
|
: ''
|
||||||
this.textEditNode.style.boxShadow = openRealtimeRenderOnNodeTextEdit
|
this.textEditNode.style.boxShadow = openRealtimeRenderOnNodeTextEdit
|
||||||
? 'none'
|
? 'none'
|
||||||
@ -340,27 +339,6 @@ class RichText {
|
|||||||
targetNode.removeChild(this.textEditNode)
|
targetNode.removeChild(this.textEditNode)
|
||||||
}
|
}
|
||||||
|
|
||||||
// 获取编辑区域的背景填充
|
|
||||||
getBackground(node) {
|
|
||||||
const gradientStyle = node.style.merge('gradientStyle')
|
|
||||||
// 当前使用的是渐变色背景
|
|
||||||
if (gradientStyle) {
|
|
||||||
const startColor = node.style.merge('startColor')
|
|
||||||
const endColor = node.style.merge('endColor')
|
|
||||||
return `linear-gradient(to right, ${startColor}, ${endColor})`
|
|
||||||
} else {
|
|
||||||
// 单色背景
|
|
||||||
const bgColor = node.style.merge('fillColor')
|
|
||||||
const color = node.style.merge('color')
|
|
||||||
// 默认使用节点的填充色,否则如果节点颜色是白色的话编辑时看不见
|
|
||||||
return bgColor === 'transparent'
|
|
||||||
? isWhite(color)
|
|
||||||
? getVisibleColorFromTheme(this.mindMap.themeConfig)
|
|
||||||
: '#fff'
|
|
||||||
: bgColor
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// 如果是非富文本的情况,需要手动应用文本样式
|
// 如果是非富文本的情况,需要手动应用文本样式
|
||||||
setTextStyleIfNotRichText(node) {
|
setTextStyleIfNotRichText(node) {
|
||||||
let style = {
|
let style = {
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user