From 333e5cc878369bd827428836f5601c2b311a5b11 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=A1=97=E8=A7=92=E5=B0=8F=E6=9E=97?= <1013335014@qq.com> Date: Fri, 3 Jan 2025 15:36:44 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BB=A3=E7=A0=81=E4=BC=98=E5=8C=96=EF=BC=9A?= =?UTF-8?q?=E5=B0=86=E6=89=80=E6=9C=89replaceAll=E6=96=B9=E6=B3=95?= =?UTF-8?q?=E6=94=B9=E4=B8=BAreplace=E6=96=B9=E6=B3=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- simple-mind-map/src/plugins/RichText.js | 2 +- simple-mind-map/src/plugins/Search.js | 2 +- simple-mind-map/src/utils/index.js | 14 ++-- web/scripts/createNodeImageList.js | 68 ++++++++++--------- web/src/pages/Edit/components/Outline.vue | 2 +- web/src/pages/Edit/components/OutlineEdit.vue | 2 +- 6 files changed, 47 insertions(+), 43 deletions(-) diff --git a/simple-mind-map/src/plugins/RichText.js b/simple-mind-map/src/plugins/RichText.js index a01116a6..c91425d4 100644 --- a/simple-mind-map/src/plugins/RichText.js +++ b/simple-mind-map/src/plugins/RichText.js @@ -338,7 +338,7 @@ class RichText { // 获取当前正在编辑的内容 getEditText() { // https://github.com/slab/quill/issues/4509 - return this.quill.container.firstChild.innerHTML.replaceAll(/ +/g, match => + return this.quill.container.firstChild.innerHTML.replace(/ +/g, match => ' '.repeat(match.length) ) // 去除ql-cursor节点 diff --git a/simple-mind-map/src/plugins/Search.js b/simple-mind-map/src/plugins/Search.js index 47de8e98..bbe7f77b 100644 --- a/simple-mind-map/src/plugins/Search.js +++ b/simple-mind-map/src/plugins/Search.js @@ -293,7 +293,7 @@ class Search { if (richText) { return replaceHtmlText(text, searchText, replaceText) } else { - return text.replaceAll(searchText, replaceText) + return text.replace(new RegExp(searchText, 'g'), replaceText) } } diff --git a/simple-mind-map/src/utils/index.js b/simple-mind-map/src/utils/index.js index 0ed836c0..ea759932 100644 --- a/simple-mind-map/src/utils/index.js +++ b/simple-mind-map/src/utils/index.js @@ -511,7 +511,7 @@ export const loadImage = imgFile => { // 移除字符串中的html实体 export const removeHTMLEntities = str => { [[' ', ' ']].forEach(item => { - str = str.replaceAll(item[0], item[1]) + str = str.replace(new RegExp(item[0], 'g'), item[1]) }) return str } @@ -528,7 +528,7 @@ export const isUndef = data => { // 移除html字符串中节点的内联样式 export const removeHtmlStyle = html => { - return html.replaceAll(/(<[^\s]+)\s+style=["'][^'"]+["']\s*(>)/g, '$1$2') + return html.replace(/(<[^\s]+)\s+style=["'][^'"]+["']\s*(>)/g, '$1$2') } // 给html标签中指定的标签添加内联样式 @@ -586,7 +586,7 @@ export const replaceHtmlText = (html, searchText, replaceText) => { // 文本节点 root.replaceChild( document.createTextNode( - node.nodeValue.replaceAll(searchText, replaceText) + node.nodeValue.replace(new RegExp(searchText, 'g'), replaceText) ), node ) @@ -613,7 +613,7 @@ export const removeHtmlNodeByClass = (html, selector) => { // 判断一个颜色是否是白色 export const isWhite = color => { - color = String(color).replaceAll(/\s+/g, '') + color = String(color).replace(/\s+/g, '') return ( ['#fff', '#ffffff', '#FFF', '#FFFFFF', 'rgb(255,255,255)'].includes( color @@ -623,7 +623,7 @@ export const isWhite = color => { // 判断一个颜色是否是透明 export const isTransparent = color => { - color = String(color).replaceAll(/\s+/g, '') + color = String(color).replace(/\s+/g, '') return ( ['', 'transparent'].includes(color) || /rgba\(\d+,\d+,\d+,0\)/.test(color) ) @@ -1166,7 +1166,7 @@ export const removeFromParentNodeData = node => { // 给html自闭合标签添加闭合状态 export const handleSelfCloseTags = str => { selfCloseTagList.forEach(tagName => { - str = str.replaceAll( + str = str.replace( new RegExp(`<${tagName}([^>]*)>`, 'g'), `<${tagName} $1 />` ) @@ -1241,7 +1241,7 @@ export const handleInputPasteText = (e, text) => { // 去除格式 text = getTextFromHtml(text) // 去除换行 - // text = text.replaceAll(/\n/g, '') + // text = text.replace(/\n/g, '') const textArr = text.split(/\n/g) const fragment = document.createDocumentFragment() textArr.forEach((item, index) => { diff --git a/web/scripts/createNodeImageList.js b/web/scripts/createNodeImageList.js index f8b74c92..f760977b 100644 --- a/web/scripts/createNodeImageList.js +++ b/web/scripts/createNodeImageList.js @@ -4,47 +4,51 @@ const fs = require('fs') const fileDest = path.join(__dirname, '../src/assets/svg') const targetDest = path.join(__dirname, '../src/config/image.js') -const run = (dir) => { - let dirs = fs.readdirSync(dir) - dirs.forEach(item => { - let cur = path.join(dir, item) - if (fs.statSync(cur).isDirectory()) { - walkDir(cur, item) - } - }) +const run = dir => { + let dirs = fs.readdirSync(dir) + dirs.forEach(item => { + let cur = path.join(dir, item) + if (fs.statSync(cur).isDirectory()) { + walkDir(cur, item) + } + }) } const list = [] const importList = [] const walkDir = (dir, item) => { - let files = fs.readdirSync(dir) - let name = files.find((file) => { - return !/\./.test(file) + let files = fs.readdirSync(dir) + let name = files.find(file => { + return !/\./.test(file) + }) + let fileList = files.filter(file => { + return /\.svg$/.test(file) + }) + let itemList = [] + fileList.forEach(file => { + let fileName = + item + '_' + file.replace(/\.svg$/, '').replace(new RegExp('-', 'g'), '') + importList.push(`import ${fileName} from '../assets/svg/${item}/${file}'`) + itemList.push({ + url: fileName, + width: 100, + height: 100 }) - let fileList = files.filter((file) => { - return /\.svg$/.test(file) - }) - let itemList = [] - fileList.forEach((file) => { - let fileName = item + '_' + file.replace(/\.svg$/, '').replaceAll('-', '') - importList.push(`import ${fileName} from '../assets/svg/${item}/${file}'`) - itemList.push({ - url: fileName, - width: 100, - height: 100 - }) - }) - list.push({ - name, - list: itemList - }) - const content = ` + }) + list.push({ + name, + list: itemList + }) + const content = ` // 该文件请运行npm run createNodeImageList命令自动生成 ${importList.join('\n')} -export default ${JSON.stringify(list, null, 2).replace(/(url":\s*)"([^"]+)"(,)/g, '$1$2$3')} +export default ${JSON.stringify(list, null, 2).replace( + /(url":\s*)"([^"]+)"(,)/g, + '$1$2$3' + )} ` - fs.writeFileSync(targetDest, content) + fs.writeFileSync(targetDest, content) } run(fileDest) -console.log('运行成功') \ No newline at end of file +console.log('运行成功') diff --git a/web/src/pages/Edit/components/Outline.vue b/web/src/pages/Edit/components/Outline.vue index 533ae7d4..b8168d54 100644 --- a/web/src/pages/Edit/components/Outline.vue +++ b/web/src/pages/Edit/components/Outline.vue @@ -142,7 +142,7 @@ export default { ? nodeRichTextToTextWithWrap(root.data.text) : root.data.text text = htmlEscape(text) - text = text.replaceAll(/\n/g, '
') + text = text.replace(/\n/g, '
') root.textCache = text // 保存一份修改前的数据,用于对比是否修改了 root.label = text root.uid = root.data.uid diff --git a/web/src/pages/Edit/components/OutlineEdit.vue b/web/src/pages/Edit/components/OutlineEdit.vue index fc1c0d96..1df83d07 100644 --- a/web/src/pages/Edit/components/OutlineEdit.vue +++ b/web/src/pages/Edit/components/OutlineEdit.vue @@ -111,7 +111,7 @@ export default { ? nodeRichTextToTextWithWrap(root.data.text) : root.data.text text = htmlEscape(text) - text = text.replaceAll(/\n/g, '
') + text = text.replace(/\n/g, '
') root.textCache = text // 保存一份修改前的数据,用于对比是否修改了 root.label = text root.uid = root.data.uid