From a2acf810cb61e36b64c5ff36b1bb081c5991c902 Mon Sep 17 00:00:00 2001
From: wanglin2 <1013335014@qq.com>
Date: Fri, 28 Jul 2023 17:05:44 +0800
Subject: [PATCH 01/10] =?UTF-8?q?Fix=EF=BC=9A=E4=BF=AE=E5=A4=8D=E6=90=9C?=
=?UTF-8?q?=E7=B4=A2=E5=AE=9A=E4=BD=8D=E5=88=B0=E6=9F=90=E4=B8=AA=E8=8A=82?=
=?UTF-8?q?=E7=82=B9=E5=90=8E=E5=88=A0=E9=99=A4=E8=AF=A5=E8=8A=82=E7=82=B9?=
=?UTF-8?q?=EF=BC=8C=E5=86=8D=E6=AC=A1=E6=90=9C=E7=B4=A2=E6=90=9C=E7=B4=A2?=
=?UTF-8?q?=E7=BB=93=E6=9E=9C=E6=9C=AA=E6=9B=B4=E6=96=B0=E7=9A=84=E9=97=AE?=
=?UTF-8?q?=E9=A2=98?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
simple-mind-map/src/plugins/Search.js | 1 +
1 file changed, 1 insertion(+)
diff --git a/simple-mind-map/src/plugins/Search.js b/simple-mind-map/src/plugins/Search.js
index 7202ef5c..58c2a29e 100644
--- a/simple-mind-map/src/plugins/Search.js
+++ b/simple-mind-map/src/plugins/Search.js
@@ -82,6 +82,7 @@ class Search {
let currentNode = this.matchNodeList[this.currentIndex]
this.notResetSearchText = true
this.mindMap.execCommand('GO_TARGET_NODE', currentNode, () => {
+ this.notResetSearchText = false
callback()
})
}
From cd4f1b1bd8470423f5607ede7cb717c878bcb1f6 Mon Sep 17 00:00:00 2001
From: wanglin2 <1013335014@qq.com>
Date: Fri, 28 Jul 2023 17:34:55 +0800
Subject: [PATCH 02/10] =?UTF-8?q?Feat=EF=BC=9A=E6=90=9C=E7=B4=A2=E6=94=AF?=
=?UTF-8?q?=E6=8C=81=E6=90=9C=E7=B4=A2=E7=A9=BA=E7=99=BD=E5=AD=97=E7=AC=A6?=
=?UTF-8?q?=E5=92=8C=E6=9B=BF=E6=8D=A2=E4=B8=BA=E7=A9=BA=E7=99=BD=E5=AD=97?=
=?UTF-8?q?=E7=AC=A6?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
simple-mind-map/src/plugins/Search.js | 22 +++++++++++++++-------
simple-mind-map/src/utils/index.js | 5 +++++
web/src/pages/Edit/components/Search.vue | 7 +++++--
3 files changed, 25 insertions(+), 9 deletions(-)
diff --git a/simple-mind-map/src/plugins/Search.js b/simple-mind-map/src/plugins/Search.js
index 58c2a29e..b83f7272 100644
--- a/simple-mind-map/src/plugins/Search.js
+++ b/simple-mind-map/src/plugins/Search.js
@@ -1,4 +1,4 @@
-import { bfsWalk, getTextFromHtml } from '../utils/index'
+import { bfsWalk, getTextFromHtml, isUndef } from '../utils/index'
// 搜索插件
class Search {
@@ -30,8 +30,8 @@ class Search {
// 搜索
search(text, callback) {
- text = String(text).trim()
- if (!text) return this.endSearch()
+ if (isUndef(text)) return this.endSearch()
+ text = String(text)
this.isSearching = true
if (this.searchText === text) {
// 和上一次搜索文本一样,那么搜索下一个
@@ -89,9 +89,13 @@ class Search {
// 替换当前节点
replace(replaceText) {
- replaceText = String(replaceText).trim()
- if (!replaceText || !this.isSearching || this.matchNodeList.length <= 0)
+ if (
+ isUndef(replaceText) ||
+ !this.isSearching ||
+ this.matchNodeList.length <= 0
+ )
return
+ replaceText = String(replaceText)
let currentNode = this.matchNodeList[this.currentIndex]
if (!currentNode) return
let text = this.getReplacedText(currentNode, this.searchText, replaceText)
@@ -110,9 +114,13 @@ class Search {
// 替换所有
replaceAll(replaceText) {
- replaceText = String(replaceText).trim()
- if (!replaceText || !this.isSearching || this.matchNodeList.length <= 0)
+ if (
+ isUndef(replaceText) ||
+ !this.isSearching ||
+ this.matchNodeList.length <= 0
+ )
return
+ replaceText = String(replaceText)
this.matchNodeList.forEach(node => {
let text = this.getReplacedText(node, this.searchText, replaceText)
this.mindMap.renderer.setNodeDataRender(
diff --git a/simple-mind-map/src/utils/index.js b/simple-mind-map/src/utils/index.js
index 886e5385..453f2259 100644
--- a/simple-mind-map/src/utils/index.js
+++ b/simple-mind-map/src/utils/index.js
@@ -465,4 +465,9 @@ export const removeHTMLEntities = (str) => {
// 获取一个数据的类型
export const getType = (data) => {
return Object.prototype.toString.call(data).slice(7, -1)
+}
+
+// 判断一个数据是否是null和undefined和空字符串
+export const isUndef = (data) => {
+ return data === null || data === undefined || data === ''
}
\ No newline at end of file
diff --git a/web/src/pages/Edit/components/Search.vue b/web/src/pages/Edit/components/Search.vue
index 396ac1fe..70f8870a 100644
--- a/web/src/pages/Edit/components/Search.vue
+++ b/web/src/pages/Edit/components/Search.vue
@@ -15,7 +15,7 @@
{{ $t('search.replace') }}
@@ -49,6 +49,7 @@
+
+
+
\ No newline at end of file
diff --git a/web/src/pages/Edit/components/Toolbar.vue b/web/src/pages/Edit/components/Toolbar.vue
index 6adeefb3..ffe88569 100644
--- a/web/src/pages/Edit/components/Toolbar.vue
+++ b/web/src/pages/Edit/components/Toolbar.vue
@@ -68,7 +68,7 @@
:class="{
disabled: activeNodes.length <= 0
}"
- @click="$bus.$emit('showNodeIcon')"
+ @click="showNodeIcon"
>
{{ $t('toolbar.icon') }}
@@ -166,7 +166,7 @@ import NodeNote from './NodeNote'
import NodeTag from './NodeTag'
import Export from './Export'
import Import from './Import'
-import { mapState } from 'vuex'
+import { mapState, mapMutations } from 'vuex'
import { Notification } from 'element-ui'
import exampleData from 'simple-mind-map/example/exampleData'
import { getData } from '../../../api'
@@ -235,6 +235,13 @@ export default {
this.$bus.$off('write_local_file', this.onWriteLocalFile)
},
methods: {
+ ...mapMutations(['setActiveSidebar']),
+
+ showNodeIcon() {
+ // this.$bus.$emit('showNodeIcon')
+ this.setActiveSidebar('nodeIconSidebar')
+ },
+
/**
* @Author: 王林25
* @Date: 2022-11-14 19:17:40
From 55da8eac8385d4561a83e1cc1fdea92cb2e4e3eb Mon Sep 17 00:00:00 2001
From: wanglin2 <1013335014@qq.com>
Date: Sat, 29 Jul 2023 10:45:25 +0800
Subject: [PATCH 06/10] =?UTF-8?q?Fix:=E4=BF=AE=E5=A4=8D=E8=B0=83=E6=95=B4?=
=?UTF-8?q?=E5=9B=BE=E7=89=87=E5=A4=A7=E5=B0=8F=E7=9A=84=E6=8C=89=E9=92=AE?=
=?UTF-8?q?=E5=9C=A8=E8=8A=82=E7=82=B9=E6=93=8D=E4=BD=9C=E5=90=8E=E6=B2=A1?=
=?UTF-8?q?=E6=9C=89=E6=9B=B4=E6=96=B0=E7=9A=84=E9=97=AE=E9=A2=98?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
simple-mind-map/src/plugins/NodeImgAdjust.js | 5 ++++-
1 file changed, 4 insertions(+), 1 deletion(-)
diff --git a/simple-mind-map/src/plugins/NodeImgAdjust.js b/simple-mind-map/src/plugins/NodeImgAdjust.js
index a9b9d947..37fce4b7 100644
--- a/simple-mind-map/src/plugins/NodeImgAdjust.js
+++ b/simple-mind-map/src/plugins/NodeImgAdjust.js
@@ -208,7 +208,10 @@ class NodeImgAdjust {
// 渲染完成事件
onRenderEnd() {
- if (!this.isAdjusted) return
+ if (!this.isAdjusted) {
+ this.hideHandleEl()
+ return
+ }
this.isAdjusted = false
}
From 4c9698a147ffcd2c318c4de93c103d5fce2c4187 Mon Sep 17 00:00:00 2001
From: wanglin2 <1013335014@qq.com>
Date: Sat, 29 Jul 2023 14:23:57 +0800
Subject: [PATCH 07/10] =?UTF-8?q?Fix:1.=E4=BF=AE=E5=A4=8D=E5=86=85?=
=?UTF-8?q?=E9=83=A8=E6=95=B0=E6=8D=AE=E6=B7=B1=E6=8B=B7=E8=B4=9D=E4=BD=8D?=
=?UTF-8?q?=E7=BD=AE=E4=B8=8D=E6=AD=A3=E7=A1=AE=E7=9A=84=E9=97=AE=E9=A2=98?=
=?UTF-8?q?;2.=E4=BF=AE=E5=A4=8D=E5=AF=8C=E6=96=87=E6=9C=AC=E8=8A=82?=
=?UTF-8?q?=E7=82=B9=E6=8D=A2=E8=A1=8C=E4=B8=8D=E7=94=9F=E6=95=88=E7=9A=84?=
=?UTF-8?q?=E9=97=AE=E9=A2=98;3.=E4=BF=AE=E5=A4=8D=E5=88=87=E6=8D=A2?=
=?UTF-8?q?=E4=B8=BB=E9=A2=98=E7=AD=89=E5=9C=BA=E6=99=AF=E6=97=B6=E8=8A=82?=
=?UTF-8?q?=E7=82=B9=E6=8D=A2=E8=A1=8C=E4=BC=9A=E4=B8=A2=E5=A4=B1=E7=9A=84?=
=?UTF-8?q?=E9=97=AE=E9=A2=98;?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
simple-mind-map/index.js | 2 ++
simple-mind-map/src/core/render/Render.js | 6 ++---
.../src/core/render/node/nodeCommandWraps.js | 4 ++--
.../core/render/node/nodeCreateContents.js | 22 ++++++++++++++---
simple-mind-map/src/plugins/Search.js | 2 +-
simple-mind-map/src/utils/index.js | 24 +++++++++++++++++++
6 files changed, 51 insertions(+), 9 deletions(-)
diff --git a/simple-mind-map/index.js b/simple-mind-map/index.js
index babb799c..9f373ebe 100644
--- a/simple-mind-map/index.js
+++ b/simple-mind-map/index.js
@@ -81,6 +81,8 @@ class MindMap {
// 配置参数处理
handleOpt(opt) {
+ // 深拷贝一份节点数据
+ opt.data = simpleDeepClone(opt.data || {})
// 检查布局配置
if (!layoutValueList.includes(opt.layout)) {
opt.layout = CONSTANTS.LAYOUT.LOGICAL_STRUCTURE
diff --git a/simple-mind-map/src/core/render/Render.js b/simple-mind-map/src/core/render/Render.js
index 0ae17ed6..bc2c4439 100644
--- a/simple-mind-map/src/core/render/Render.js
+++ b/simple-mind-map/src/core/render/Render.js
@@ -48,7 +48,7 @@ class Render {
this.themeConfig = this.mindMap.themeConfig
this.draw = this.mindMap.draw
// 渲染树,操作过程中修改的都是这里的数据
- this.renderTree = merge({}, simpleDeepClone(this.mindMap.opt.data) || {})
+ this.renderTree = merge({},this.mindMap.opt.data || {})
// 是否重新渲染
this.reRender = false
// 是否正在渲染中
@@ -972,11 +972,11 @@ class Render {
}
// 设置节点文本
- setNodeText(node, text, richText) {
+ setNodeText(node, text, richText, resetRichText) {
this.setNodeDataRender(node, {
text,
richText,
- resetRichText: richText
+ resetRichText
})
}
diff --git a/simple-mind-map/src/core/render/node/nodeCommandWraps.js b/simple-mind-map/src/core/render/node/nodeCommandWraps.js
index ceb66ad2..3ef043e9 100644
--- a/simple-mind-map/src/core/render/node/nodeCommandWraps.js
+++ b/simple-mind-map/src/core/render/node/nodeCommandWraps.js
@@ -4,8 +4,8 @@ function setData(data = {}) {
}
// 设置文本
-function setText(text, richText) {
- this.mindMap.execCommand('SET_NODE_TEXT', this, text, richText)
+function setText(text, richText, resetRichText) {
+ this.mindMap.execCommand('SET_NODE_TEXT', this, text, richText, resetRichText)
}
// 设置图片
diff --git a/simple-mind-map/src/core/render/node/nodeCreateContents.js b/simple-mind-map/src/core/render/node/nodeCreateContents.js
index c521d2d4..c870d953 100644
--- a/simple-mind-map/src/core/render/node/nodeCreateContents.js
+++ b/simple-mind-map/src/core/render/node/nodeCreateContents.js
@@ -1,4 +1,4 @@
-import { measureText, resizeImgSize, getTextFromHtml } from '../../../utils'
+import { measureText, resizeImgSize, removeHtmlStyle, addHtmlStyle, checkIsRichText } from '../../../utils'
import { Image, SVG, A, G, Rect, Text, ForeignObject } from '@svgdotjs/svg.js'
import iconsSvg from '../../../svg/icons'
import { CONSTANTS, commonCaches } from '../../../constants/constant'
@@ -64,6 +64,9 @@ function createIconNode() {
node = new Image().load(src)
}
node.size(iconSize, iconSize)
+ node.on('click', e => {
+ this.mindMap.emit('node_icon_click', this, e)
+ })
return {
node,
width: iconSize,
@@ -88,8 +91,21 @@ function createRichTextNode() {
}
}
if (recoverText) {
- let text = getTextFromHtml(this.nodeData.data.text)
- this.nodeData.data.text = `
${text}
`
+ let text = this.nodeData.data.text
+ // 判断节点内容是否是富文本
+ let isRichText = checkIsRichText(text)
+ // 样式字符串
+ let style = this.style.createStyleText()
+ if (isRichText) {
+ // 如果是富文本那么线移除内联样式
+ text = removeHtmlStyle(text)
+ // 再添加新的内联样式
+ text = addHtmlStyle(text, 'span', style)
+ } else {
+ // 非富文本
+ text = `${text}
`
+ }
+ this.nodeData.data.text = text
}
let html = `${this.nodeData.data.text}
`
let div = document.createElement('div')
diff --git a/simple-mind-map/src/plugins/Search.js b/simple-mind-map/src/plugins/Search.js
index b83f7272..5844ff00 100644
--- a/simple-mind-map/src/plugins/Search.js
+++ b/simple-mind-map/src/plugins/Search.js
@@ -100,7 +100,7 @@ class Search {
if (!currentNode) return
let text = this.getReplacedText(currentNode, this.searchText, replaceText)
this.notResetSearchText = true
- currentNode.setText(text, currentNode.nodeData.data.richText)
+ currentNode.setText(text, currentNode.nodeData.data.richText, true)
this.matchNodeList = this.matchNodeList.filter(node => {
return currentNode !== node
})
diff --git a/simple-mind-map/src/utils/index.js b/simple-mind-map/src/utils/index.js
index 453f2259..b6befddd 100644
--- a/simple-mind-map/src/utils/index.js
+++ b/simple-mind-map/src/utils/index.js
@@ -470,4 +470,28 @@ export const getType = (data) => {
// 判断一个数据是否是null和undefined和空字符串
export const isUndef = (data) => {
return data === null || data === undefined || data === ''
+}
+
+// 移除html字符串中节点的内联样式
+export const removeHtmlStyle = (html) => {
+ return html.replaceAll(/(<[^\s]+)\s+style=["'][^'"]+["']\s*(>)/g, '$1$2')
+}
+
+// 给html标签中指定的标签添加内联样式
+export const addHtmlStyle = (html, tag, style) => {
+ const reg = new RegExp(`(<${tag}[^>]*)(>[^<>]*${tag}>)`, 'g')
+ return html.replaceAll(reg, `$1 style="${style}"$2`)
+}
+
+// 检查一个字符串是否是富文本字符
+let checkIsRichTextEl = null
+export const checkIsRichText = (str) => {
+ if (!checkIsRichTextEl) {
+ checkIsRichTextEl = document.createElement('div')
+ }
+ checkIsRichTextEl.innerHTML = str
+ for (let c = checkIsRichTextEl.childNodes, i = c.length; i--;) {
+ if (c[i].nodeType == 1) return true
+ }
+ return false
}
\ No newline at end of file
From 20eba7b29bc070b682ac98786453cc48786b0d76 Mon Sep 17 00:00:00 2001
From: wanglin2 <1013335014@qq.com>
Date: Sat, 29 Jul 2023 14:24:50 +0800
Subject: [PATCH 08/10] =?UTF-8?q?Demo:=E4=BF=AE=E5=A4=8D=E5=9C=A8=E6=90=9C?=
=?UTF-8?q?=E7=B4=A2=E6=A1=86=E5=9B=9E=E8=BD=A6=E5=90=8E=E8=BE=93=E5=85=A5?=
=?UTF-8?q?=E6=A1=86=E7=84=A6=E7=82=B9=E4=B8=A2=E5=A4=B1=E7=9A=84=E9=97=AE?=
=?UTF-8?q?=E9=A2=98?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
web/src/pages/Edit/components/Search.vue | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/web/src/pages/Edit/components/Search.vue b/web/src/pages/Edit/components/Search.vue
index 1b5ada1d..58c7afeb 100644
--- a/web/src/pages/Edit/components/Search.vue
+++ b/web/src/pages/Edit/components/Search.vue
@@ -102,7 +102,7 @@ export default {
showSearch() {
this.$bus.$emit('closeSideBar')
this.show = true
- // this.$refs.input.focus()
+ // this.$refs.searchInputRef.focus()
},
hideReplaceInput() {
@@ -112,7 +112,7 @@ export default {
onSearchNext() {
this.mindMap.search.search(this.searchText, () => {
- this.$refs.input.focus()
+ this.$refs.searchInputRef.focus()
})
},
From 78f5d4ec88924dd1a5f355764141fca526ccdad6 Mon Sep 17 00:00:00 2001
From: wanglin2 <1013335014@qq.com>
Date: Sat, 29 Jul 2023 16:08:12 +0800
Subject: [PATCH 09/10] =?UTF-8?q?Demo:=E6=94=AF=E6=8C=81=E7=82=B9=E5=87=BB?=
=?UTF-8?q?=E8=8A=82=E7=82=B9=E5=86=85=E7=9A=84=E5=9B=BE=E6=A0=87=E6=98=BE?=
=?UTF-8?q?=E7=A4=BA=E4=B8=80=E4=B8=AA=E5=9B=BE=E6=A0=87=E5=BF=AB=E6=8D=B7?=
=?UTF-8?q?=E6=9B=BF=E6=8D=A2=E5=92=8C=E5=88=A0=E9=99=A4=E6=82=AC=E6=B5=AE?=
=?UTF-8?q?=E9=9D=A2=E6=9D=BF?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
.../core/render/node/nodeCreateContents.js | 2 +-
web/src/pages/Edit/components/Edit.vue | 7 +-
.../pages/Edit/components/NodeIconSidebar.vue | 3 +-
.../pages/Edit/components/NodeIconToolbar.vue | 212 ++++++++++++++++++
web/src/pages/Edit/components/Toolbar.vue | 1 +
5 files changed, 220 insertions(+), 5 deletions(-)
create mode 100644 web/src/pages/Edit/components/NodeIconToolbar.vue
diff --git a/simple-mind-map/src/core/render/node/nodeCreateContents.js b/simple-mind-map/src/core/render/node/nodeCreateContents.js
index c870d953..505bab59 100644
--- a/simple-mind-map/src/core/render/node/nodeCreateContents.js
+++ b/simple-mind-map/src/core/render/node/nodeCreateContents.js
@@ -65,7 +65,7 @@ function createIconNode() {
}
node.size(iconSize, iconSize)
node.on('click', e => {
- this.mindMap.emit('node_icon_click', this, e)
+ this.mindMap.emit('node_icon_click', this, item, e)
})
return {
node,
diff --git a/web/src/pages/Edit/components/Edit.vue b/web/src/pages/Edit/components/Edit.vue
index 026d3d37..d45b3bc1 100644
--- a/web/src/pages/Edit/components/Edit.vue
+++ b/web/src/pages/Edit/components/Edit.vue
@@ -19,7 +19,8 @@
-
+
+
@@ -64,6 +65,7 @@ import store from '../../../store'
import i18n from '../../../i18n'
import Search from './Search.vue'
import NodeIconSidebar from './NodeIconSidebar.vue'
+import NodeIconToolbar from './NodeIconToolbar.vue'
// 注册插件
MindMap
@@ -108,7 +110,8 @@ export default {
NodeImgPreview,
SidebarTrigger,
Search,
- NodeIconSidebar
+ NodeIconSidebar,
+ NodeIconToolbar
},
data() {
return {
diff --git a/web/src/pages/Edit/components/NodeIconSidebar.vue b/web/src/pages/Edit/components/NodeIconSidebar.vue
index a1868690..5293e7f7 100644
--- a/web/src/pages/Edit/components/NodeIconSidebar.vue
+++ b/web/src/pages/Edit/components/NodeIconSidebar.vue
@@ -37,14 +37,13 @@
+
+
+
\ No newline at end of file
diff --git a/web/src/pages/Edit/components/Toolbar.vue b/web/src/pages/Edit/components/Toolbar.vue
index ffe88569..9519002c 100644
--- a/web/src/pages/Edit/components/Toolbar.vue
+++ b/web/src/pages/Edit/components/Toolbar.vue
@@ -239,6 +239,7 @@ export default {
showNodeIcon() {
// this.$bus.$emit('showNodeIcon')
+ this.$bus.$emit('close_node_icon_toolbar')
this.setActiveSidebar('nodeIconSidebar')
},
From e11b6647b87c957079f8623c2b1a6a9d38b96099 Mon Sep 17 00:00:00 2001
From: wanglin2 <1013335014@qq.com>
Date: Sat, 29 Jul 2023 19:22:40 +0800
Subject: [PATCH 10/10] =?UTF-8?q?=E6=89=93=E5=8C=850.6.10?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
index.html | 2 +-
simple-mind-map/package.json | 2 +-
simple-mind-map/src/utils/index.js | 21 +++++++++++++++++++++
web/package.json | 2 +-
4 files changed, 24 insertions(+), 3 deletions(-)
diff --git a/index.html b/index.html
index a8ed770a..00cadcbc 100644
--- a/index.html
+++ b/index.html
@@ -1 +1 @@
-思绪思维导图
\ No newline at end of file
+思绪思维导图
\ No newline at end of file
diff --git a/simple-mind-map/package.json b/simple-mind-map/package.json
index bb56420b..f42f03e4 100644
--- a/simple-mind-map/package.json
+++ b/simple-mind-map/package.json
@@ -1,6 +1,6 @@
{
"name": "simple-mind-map",
- "version": "0.6.9-fix.1",
+ "version": "0.6.10",
"description": "一个简单的web在线思维导图",
"authors": [
{
diff --git a/simple-mind-map/src/utils/index.js b/simple-mind-map/src/utils/index.js
index b6befddd..5488e394 100644
--- a/simple-mind-map/src/utils/index.js
+++ b/simple-mind-map/src/utils/index.js
@@ -494,4 +494,25 @@ export const checkIsRichText = (str) => {
if (c[i].nodeType == 1) return true
}
return false
+}
+
+// 搜索和替换html字符串中指定的文本
+let replaceHtmlTextEl = null
+export const replaceHtmlText = (html, searchText, replaceText) => {
+ if (!replaceHtmlTextEl) {
+ replaceHtmlTextEl = document.createElement('div')
+ }
+ replaceHtmlTextEl.innerHTML = html
+ let walk = (root) => {
+ let childNodes = root.childNodes
+ childNodes.forEach((node) => {
+ if (node.nodeType === 1) {// 元素节点
+ walk(node)
+ } else if (node.nodeType === 3) {// 文本节点
+ root.replaceChild(document.createTextNode(node.nodeValue.replaceAll(searchText, replaceText)), node)
+ }
+ })
+ }
+ walk(replaceHtmlTextEl)
+ return replaceHtmlTextEl.innerHTML
}
\ No newline at end of file
diff --git a/web/package.json b/web/package.json
index 0f4be4ba..8dacffda 100644
--- a/web/package.json
+++ b/web/package.json
@@ -6,7 +6,7 @@
"serve": "vue-cli-service serve",
"build": "vue-cli-service build && node ../copy.js",
"lint": "vue-cli-service lint",
- "buildLibrary": "vue-cli-service build --target lib --name simpleMindMap ../simple-mind-map/full.js --dest ../simple-mind-map/dist && esbuild ../simple-mind-map/full.js --bundle --external:buffer --format=esm --outfile=../simple-mind-map/dist/simpleMindMap.esm.js",
+ "buildLibrary": "vue-cli-service build --target lib --name simpleMindMap ../simple-mind-map/full.js --dest ../simple-mind-map/dist && esbuild ../simple-mind-map/full.js --bundle --external:buffer --format=esm --outfile=../simple-mind-map/dist/simpleMindMap.esm.js && esbuild ../simple-mind-map/full.js --bundle --minify --external:buffer --format=esm --outfile=../simple-mind-map/dist/simpleMindMap.esm.min.js",
"format": "prettier --write src/* src/*/* src/*/*/* src/*/*/*/*",
"buildDoc": "node ./scripts/buildDoc.js",
"autoBuildDoc": "node ./scripts/autoBuildDoc.js",