Fix:修复在移动端激活节点、展开收起时等操作时会拉起输入法的问题
This commit is contained in:
parent
5a32c1d99d
commit
69e192ea9d
@ -1,4 +1,4 @@
|
|||||||
import { getStrWithBrFromHtml, checkNodeOuter } from '../../utils'
|
import { getStrWithBrFromHtml, checkNodeOuter, isMobile } from '../../utils'
|
||||||
|
|
||||||
// 节点文字编辑类
|
// 节点文字编辑类
|
||||||
export default class TextEdit {
|
export default class TextEdit {
|
||||||
@ -67,7 +67,7 @@ export default class TextEdit {
|
|||||||
|
|
||||||
// 创建一个隐藏的文本输入框
|
// 创建一个隐藏的文本输入框
|
||||||
createHiddenInput() {
|
createHiddenInput() {
|
||||||
if (this.hiddenInputEl) return
|
if (this.hiddenInputEl || isMobile()) return
|
||||||
this.hiddenInputEl = document.createElement('input')
|
this.hiddenInputEl = document.createElement('input')
|
||||||
this.hiddenInputEl.type = 'text'
|
this.hiddenInputEl.type = 'text'
|
||||||
this.hiddenInputEl.style.cssText = `
|
this.hiddenInputEl.style.cssText = `
|
||||||
|
|||||||
@ -7,7 +7,6 @@ class TouchEvent {
|
|||||||
this.singleTouchstartEvent = null
|
this.singleTouchstartEvent = null
|
||||||
this.clickNum = 0
|
this.clickNum = 0
|
||||||
this.doubleTouchmoveDistance = 0
|
this.doubleTouchmoveDistance = 0
|
||||||
this.mindMap.renderer.textEdit.stopFocusOnNodeActive()
|
|
||||||
this.bindEvent()
|
this.bindEvent()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -455,25 +455,25 @@ export const loadImage = imgFile => {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// 移除字符串中的html实体
|
// 移除字符串中的html实体
|
||||||
export const removeHTMLEntities = (str) => {
|
export const removeHTMLEntities = str => {
|
||||||
[[' ', ' ']].forEach((item) => {
|
;[[' ', ' ']].forEach(item => {
|
||||||
str = str.replaceAll(item[0], item[1])
|
str = str.replaceAll(item[0], item[1])
|
||||||
})
|
})
|
||||||
return str
|
return str
|
||||||
}
|
}
|
||||||
|
|
||||||
// 获取一个数据的类型
|
// 获取一个数据的类型
|
||||||
export const getType = (data) => {
|
export const getType = data => {
|
||||||
return Object.prototype.toString.call(data).slice(7, -1)
|
return Object.prototype.toString.call(data).slice(7, -1)
|
||||||
}
|
}
|
||||||
|
|
||||||
// 判断一个数据是否是null和undefined和空字符串
|
// 判断一个数据是否是null和undefined和空字符串
|
||||||
export const isUndef = (data) => {
|
export const isUndef = data => {
|
||||||
return data === null || data === undefined || data === ''
|
return data === null || data === undefined || data === ''
|
||||||
}
|
}
|
||||||
|
|
||||||
// 移除html字符串中节点的内联样式
|
// 移除html字符串中节点的内联样式
|
||||||
export const removeHtmlStyle = (html) => {
|
export const removeHtmlStyle = html => {
|
||||||
return html.replaceAll(/(<[^\s]+)\s+style=["'][^'"]+["']\s*(>)/g, '$1$2')
|
return html.replaceAll(/(<[^\s]+)\s+style=["'][^'"]+["']\s*(>)/g, '$1$2')
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -485,12 +485,12 @@ export const addHtmlStyle = (html, tag, style) => {
|
|||||||
|
|
||||||
// 检查一个字符串是否是富文本字符
|
// 检查一个字符串是否是富文本字符
|
||||||
let checkIsRichTextEl = null
|
let checkIsRichTextEl = null
|
||||||
export const checkIsRichText = (str) => {
|
export const checkIsRichText = str => {
|
||||||
if (!checkIsRichTextEl) {
|
if (!checkIsRichTextEl) {
|
||||||
checkIsRichTextEl = document.createElement('div')
|
checkIsRichTextEl = document.createElement('div')
|
||||||
}
|
}
|
||||||
checkIsRichTextEl.innerHTML = str
|
checkIsRichTextEl.innerHTML = str
|
||||||
for (let c = checkIsRichTextEl.childNodes, i = c.length; i--;) {
|
for (let c = checkIsRichTextEl.childNodes, i = c.length; i--; ) {
|
||||||
if (c[i].nodeType == 1) return true
|
if (c[i].nodeType == 1) return true
|
||||||
}
|
}
|
||||||
return false
|
return false
|
||||||
@ -503,13 +503,20 @@ export const replaceHtmlText = (html, searchText, replaceText) => {
|
|||||||
replaceHtmlTextEl = document.createElement('div')
|
replaceHtmlTextEl = document.createElement('div')
|
||||||
}
|
}
|
||||||
replaceHtmlTextEl.innerHTML = html
|
replaceHtmlTextEl.innerHTML = html
|
||||||
let walk = (root) => {
|
let walk = root => {
|
||||||
let childNodes = root.childNodes
|
let childNodes = root.childNodes
|
||||||
childNodes.forEach((node) => {
|
childNodes.forEach(node => {
|
||||||
if (node.nodeType === 1) {// 元素节点
|
if (node.nodeType === 1) {
|
||||||
|
// 元素节点
|
||||||
walk(node)
|
walk(node)
|
||||||
} else if (node.nodeType === 3) {// 文本节点
|
} else if (node.nodeType === 3) {
|
||||||
root.replaceChild(document.createTextNode(node.nodeValue.replaceAll(searchText, replaceText)), node)
|
// 文本节点
|
||||||
|
root.replaceChild(
|
||||||
|
document.createTextNode(
|
||||||
|
node.nodeValue.replaceAll(searchText, replaceText)
|
||||||
|
),
|
||||||
|
node
|
||||||
|
)
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
@ -518,22 +525,39 @@ export const replaceHtmlText = (html, searchText, replaceText) => {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// 判断一个颜色是否是白色
|
// 判断一个颜色是否是白色
|
||||||
export const isWhite = (color) => {
|
export const isWhite = color => {
|
||||||
color = String(color).replaceAll(/\s+/g, '')
|
color = String(color).replaceAll(/\s+/g, '')
|
||||||
return ['#fff', '#ffffff', '#FFF', '#FFFFFF', 'rgb(255,255,255)'].includes(color) || /rgba\(255,255,255,[^)]+\)/.test(color)
|
return (
|
||||||
|
['#fff', '#ffffff', '#FFF', '#FFFFFF', 'rgb(255,255,255)'].includes(
|
||||||
|
color
|
||||||
|
) || /rgba\(255,255,255,[^)]+\)/.test(color)
|
||||||
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
// 判断一个颜色是否是透明
|
// 判断一个颜色是否是透明
|
||||||
export const isTransparent = (color) => {
|
export const isTransparent = color => {
|
||||||
color = String(color).replaceAll(/\s+/g, '')
|
color = String(color).replaceAll(/\s+/g, '')
|
||||||
return ['', 'transparent'].includes(color) || /rgba\(\d+,\d+,\d+,0\)/.test(color)
|
return (
|
||||||
|
['', 'transparent'].includes(color) || /rgba\(\d+,\d+,\d+,0\)/.test(color)
|
||||||
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
// 从当前主题里获取一个非透明非白色的颜色
|
// 从当前主题里获取一个非透明非白色的颜色
|
||||||
export const getVisibleColorFromTheme = (themeConfig) => {
|
export const getVisibleColorFromTheme = themeConfig => {
|
||||||
let { lineColor, root, second, node } = themeConfig
|
let { lineColor, root, second, node } = themeConfig
|
||||||
let list = [lineColor, root.fillColor, root.color, second.fillColor, second.color, node.fillColor, node.color, root.borderColor, second.borderColor, node.borderColor]
|
let list = [
|
||||||
for(let i = 0; i < list.length; i++) {
|
lineColor,
|
||||||
|
root.fillColor,
|
||||||
|
root.color,
|
||||||
|
second.fillColor,
|
||||||
|
second.color,
|
||||||
|
node.fillColor,
|
||||||
|
node.color,
|
||||||
|
root.borderColor,
|
||||||
|
second.borderColor,
|
||||||
|
node.borderColor
|
||||||
|
]
|
||||||
|
for (let i = 0; i < list.length; i++) {
|
||||||
let color = list[i]
|
let color = list[i]
|
||||||
if (!isTransparent(color) && !isWhite(color)) {
|
if (!isTransparent(color) && !isWhite(color)) {
|
||||||
return color
|
return color
|
||||||
@ -543,22 +567,24 @@ export const getVisibleColorFromTheme = (themeConfig) => {
|
|||||||
|
|
||||||
// 将<p><span></span><p>形式的节点富文本内容转换成\n换行的文本
|
// 将<p><span></span><p>形式的节点富文本内容转换成\n换行的文本
|
||||||
let nodeRichTextToTextWithWrapEl = null
|
let nodeRichTextToTextWithWrapEl = null
|
||||||
export const nodeRichTextToTextWithWrap = (html) => {
|
export const nodeRichTextToTextWithWrap = html => {
|
||||||
if (!nodeRichTextToTextWithWrapEl) {
|
if (!nodeRichTextToTextWithWrapEl) {
|
||||||
nodeRichTextToTextWithWrapEl = document.createElement('div')
|
nodeRichTextToTextWithWrapEl = document.createElement('div')
|
||||||
}
|
}
|
||||||
nodeRichTextToTextWithWrapEl.innerHTML = html
|
nodeRichTextToTextWithWrapEl.innerHTML = html
|
||||||
const childNodes = nodeRichTextToTextWithWrapEl.childNodes
|
const childNodes = nodeRichTextToTextWithWrapEl.childNodes
|
||||||
let res = ''
|
let res = ''
|
||||||
for(let i = 0; i < childNodes.length; i++) {
|
for (let i = 0; i < childNodes.length; i++) {
|
||||||
const node = childNodes[i]
|
const node = childNodes[i]
|
||||||
if (node.nodeType === 1) {// 元素节点
|
if (node.nodeType === 1) {
|
||||||
|
// 元素节点
|
||||||
if (node.tagName.toLowerCase() === 'p') {
|
if (node.tagName.toLowerCase() === 'p') {
|
||||||
res += node.textContent + '\n'
|
res += node.textContent + '\n'
|
||||||
} else {
|
} else {
|
||||||
res += node.textContent
|
res += node.textContent
|
||||||
}
|
}
|
||||||
} else if (node.nodeType === 3) {// 文本节点
|
} else if (node.nodeType === 3) {
|
||||||
|
// 文本节点
|
||||||
res += node.nodeValue
|
res += node.nodeValue
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -567,7 +593,7 @@ export const nodeRichTextToTextWithWrap = (html) => {
|
|||||||
|
|
||||||
// 将<br>换行的文本转换成<p><span></span><p>形式的节点富文本内容
|
// 将<br>换行的文本转换成<p><span></span><p>形式的节点富文本内容
|
||||||
let textToNodeRichTextWithWrapEl = null
|
let textToNodeRichTextWithWrapEl = null
|
||||||
export const textToNodeRichTextWithWrap = (html) => {
|
export const textToNodeRichTextWithWrap = html => {
|
||||||
if (!textToNodeRichTextWithWrapEl) {
|
if (!textToNodeRichTextWithWrapEl) {
|
||||||
textToNodeRichTextWithWrapEl = document.createElement('div')
|
textToNodeRichTextWithWrapEl = document.createElement('div')
|
||||||
}
|
}
|
||||||
@ -575,23 +601,34 @@ export const textToNodeRichTextWithWrap = (html) => {
|
|||||||
const childNodes = textToNodeRichTextWithWrapEl.childNodes
|
const childNodes = textToNodeRichTextWithWrapEl.childNodes
|
||||||
let list = []
|
let list = []
|
||||||
let str = ''
|
let str = ''
|
||||||
for(let i = 0; i < childNodes.length; i++) {
|
for (let i = 0; i < childNodes.length; i++) {
|
||||||
const node = childNodes[i]
|
const node = childNodes[i]
|
||||||
if (node.nodeType === 1) {// 元素节点
|
if (node.nodeType === 1) {
|
||||||
|
// 元素节点
|
||||||
if (node.tagName.toLowerCase() === 'br') {
|
if (node.tagName.toLowerCase() === 'br') {
|
||||||
list.push(str)
|
list.push(str)
|
||||||
str = ''
|
str = ''
|
||||||
} else {
|
} else {
|
||||||
str += node.textContent
|
str += node.textContent
|
||||||
}
|
}
|
||||||
} else if (node.nodeType === 3) {// 文本节点
|
} else if (node.nodeType === 3) {
|
||||||
|
// 文本节点
|
||||||
str += node.nodeValue
|
str += node.nodeValue
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (str) {
|
if (str) {
|
||||||
list.push(str)
|
list.push(str)
|
||||||
}
|
}
|
||||||
return list.map((item) => {
|
return list
|
||||||
return `<p><span>${item}</span></p>`
|
.map(item => {
|
||||||
}).join('')
|
return `<p><span>${item}</span></p>`
|
||||||
}
|
})
|
||||||
|
.join('')
|
||||||
|
}
|
||||||
|
|
||||||
|
// 判断是否是移动端环境
|
||||||
|
export const isMobile = () => {
|
||||||
|
return /Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i.test(
|
||||||
|
navigator.userAgent
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user