From b3705712f2f4e0da50552d70428eb1c05eadc1a2 Mon Sep 17 00:00:00 2001 From: wanglin2 <1013335014@qq.com> Date: Thu, 30 Jan 2025 21:39:04 +0800 Subject: [PATCH 1/6] =?UTF-8?q?Fix:=E4=BF=AE=E5=A4=8D=E6=A6=82=E8=A6=81?= =?UTF-8?q?=E8=8A=82=E7=82=B9=E4=BC=9A=E6=98=BE=E7=A4=BA=E5=BF=AB=E9=80=9F?= =?UTF-8?q?=E5=88=9B=E5=BB=BA=E5=AD=90=E8=8A=82=E7=82=B9=E6=8C=89=E9=92=AE?= =?UTF-8?q?=E7=9A=84=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .gitignore | 3 ++- simple-mind-map/src/core/render/node/quickCreateChildBtn.js | 5 ++++- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/.gitignore b/.gitignore index f18f78ea..ce3d8a8f 100644 --- a/.gitignore +++ b/.gitignore @@ -2,4 +2,5 @@ node_modules .DS_Store dist_electron simple-mind-map/dist -simple-mind-map/types \ No newline at end of file +simple-mind-map/types +utools/dist \ No newline at end of file diff --git a/simple-mind-map/src/core/render/node/quickCreateChildBtn.js b/simple-mind-map/src/core/render/node/quickCreateChildBtn.js index 257cb883..bf19a3a8 100644 --- a/simple-mind-map/src/core/render/node/quickCreateChildBtn.js +++ b/simple-mind-map/src/core/render/node/quickCreateChildBtn.js @@ -2,13 +2,14 @@ import btnsSvg from '../../../svg/btns' import { SVG, Circle, G } from '@svgdotjs/svg.js' function initQuickCreateChildBtn() { + if (this.isGeneralization) return this._quickCreateChildBtn = null this._showQuickCreateChildBtn = false } // 显示按钮 function showQuickCreateChildBtn() { - if (this.getChildrenLength() > 0) return + if (this.isGeneralization || this.getChildrenLength() > 0) return // 创建按钮 if (this._quickCreateChildBtn) { this.group.add(this._quickCreateChildBtn) @@ -63,6 +64,7 @@ function showQuickCreateChildBtn() { // 移除按钮 function removeQuickCreateChildBtn() { + if (this.isGeneralization) return if (this._quickCreateChildBtn && this._showQuickCreateChildBtn) { this._quickCreateChildBtn.remove() this._showQuickCreateChildBtn = false @@ -71,6 +73,7 @@ function removeQuickCreateChildBtn() { // 隐藏按钮 function hideQuickCreateChildBtn() { + if (this.isGeneralization) return const { isActive } = this.getData() if (!isActive) { this.removeQuickCreateChildBtn() From 1770cb98aae8772118f79538ba430a25eff2cfc3 Mon Sep 17 00:00:00 2001 From: wanglin2 <1013335014@qq.com> Date: Sat, 1 Feb 2025 11:28:25 +0800 Subject: [PATCH 2/6] =?UTF-8?q?Feat:=E8=87=AA=E5=8A=A8=E7=BB=99=E6=B2=A1?= =?UTF-8?q?=E6=9C=89uid=E7=9A=84=E8=8A=82=E7=82=B9=E6=95=B0=E6=8D=AE?= =?UTF-8?q?=E6=B7=BB=E5=8A=A0uid?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- simple-mind-map/index.js | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/simple-mind-map/index.js b/simple-mind-map/index.js index 7976dcc5..072f293d 100644 --- a/simple-mind-map/index.js +++ b/simple-mind-map/index.js @@ -20,7 +20,8 @@ import { isUndef, handleGetSvgDataExtraContent, getNodeTreeBoundingRect, - mergeTheme + mergeTheme, + createUidForAppointNodes } from './src/utils' import defaultTheme, { checkIsNodeSizeIndependenceConfig @@ -149,6 +150,8 @@ class MindMap { if (data.data && !data.data.expand) { data.data.expand = true } + // 给没有uid的节点添加uid + createUidForAppointNodes([data], false, null, true) return data } @@ -395,6 +398,7 @@ class MindMap { // 更新画布数据,如果新的数据是在当前画布节点数据基础上增删改查后形成的,那么可以使用该方法来更新画布数据 updateData(data) { + data = this.handleData(data) this.emit('before_update_data', data) this.renderer.setData(data) this.render() @@ -583,7 +587,7 @@ class MindMap { this.watermark.isInExport = false } // 添加必要的样式 - [this.joinCss(), ...cssTextList].forEach(s => { + ;[this.joinCss(), ...cssTextList].forEach(s => { clone.add(SVG(``)) }) // 附加内容 From b0a5c8c12a0edf7a869c0c75b24ce902800b1155 Mon Sep 17 00:00:00 2001 From: wanglin2 <1013335014@qq.com> Date: Sat, 1 Feb 2025 11:29:00 +0800 Subject: [PATCH 3/6] =?UTF-8?q?Feat:createUidForAppointNodes=E5=B7=A5?= =?UTF-8?q?=E5=85=B7=E6=96=B9=E6=B3=95=E6=94=AF=E6=8C=81=E5=A4=84=E7=90=86?= =?UTF-8?q?=E6=A6=82=E8=A6=81=E6=95=B0=E6=8D=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- simple-mind-map/src/utils/index.js | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/simple-mind-map/src/utils/index.js b/simple-mind-map/src/utils/index.js index 59af46da..94d42aab 100644 --- a/simple-mind-map/src/utils/index.js +++ b/simple-mind-map/src/utils/index.js @@ -508,7 +508,7 @@ export const loadImage = imgFile => { // 移除字符串中的html实体 export const removeHTMLEntities = str => { - [[' ', ' ']].forEach(item => { + ;[[' ', ' ']].forEach(item => { str = str.replace(new RegExp(item[0], 'g'), item[1]) }) return str @@ -1002,7 +1002,8 @@ export const addDataToAppointNodes = (appointNodes, data = {}) => { export const createUidForAppointNodes = ( appointNodes, createNewId = false, - handle = null + handle = null, + handleGeneralization = false ) => { const walk = list => { list.forEach(node => { @@ -1012,6 +1013,14 @@ export const createUidForAppointNodes = ( if (createNewId || isUndef(node.data.uid)) { node.data.uid = createUid() } + if (handleGeneralization) { + const generalizationList = formatGetNodeGeneralization(node.data) + generalizationList.forEach(gNode => { + if (createNewId || isUndef(gNode.uid)) { + gNode.uid = createUid() + } + }) + } handle && handle(node) if (node.children && node.children.length > 0) { walk(node.children) @@ -1060,7 +1069,7 @@ export const generateColorByContent = str => { // html转义 export const htmlEscape = str => { - [ + ;[ ['&', '&'], ['<', '<'], ['>', '>'] From c95919a1a06787cf616c25cd002612bdd1fa2d2c Mon Sep 17 00:00:00 2001 From: wanglin2 <1013335014@qq.com> Date: Sat, 1 Feb 2025 11:32:07 +0800 Subject: [PATCH 4/6] update --- simple-mind-map/src/plugins/Search.js | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/simple-mind-map/src/plugins/Search.js b/simple-mind-map/src/plugins/Search.js index bbe7f77b..91b53c86 100644 --- a/simple-mind-map/src/plugins/Search.js +++ b/simple-mind-map/src/plugins/Search.js @@ -182,6 +182,10 @@ class Search { const uid = this.isNodeInstance(currentNode) ? currentNode.getData('uid') : currentNode.data.uid + if (!uid) { + callback() + return + } const targetNode = this.mindMap.renderer.findNodeByUid(uid) this.mindMap.execCommand('GO_TARGET_NODE', uid, node => { if (!this.isNodeInstance(currentNode)) { From 24365a22c34b66c8aba357501da602ffc4379962 Mon Sep 17 00:00:00 2001 From: wanglin2 <1013335014@qq.com> Date: Sat, 1 Feb 2025 11:34:17 +0800 Subject: [PATCH 5/6] =?UTF-8?q?Demo:=E5=AF=BC=E5=85=A5=E6=95=B0=E6=8D=AE?= =?UTF-8?q?=E6=97=B6=E9=9A=90=E8=97=8F=E6=90=9C=E7=B4=A2=E6=A1=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- web/src/pages/Edit/components/Search.vue | 2 ++ 1 file changed, 2 insertions(+) diff --git a/web/src/pages/Edit/components/Search.vue b/web/src/pages/Edit/components/Search.vue index b03e9bf2..852a27fd 100644 --- a/web/src/pages/Edit/components/Search.vue +++ b/web/src/pages/Edit/components/Search.vue @@ -125,6 +125,7 @@ export default { ) this.mindMap.keyCommand.addShortcut('Control+f', this.showSearch) window.addEventListener('resize', this.setSearchResultListHeight) + this.$bus.$on('setData', this.close) }, mounted() { this.setSearchResultListHeight() @@ -141,6 +142,7 @@ export default { ) this.mindMap.keyCommand.removeShortcut('Control+f', this.showSearch) window.removeEventListener('resize', this.setSearchResultListHeight) + this.$bus.$off('setData', this.close) }, methods: { isUndef, From 68f99d52368530fcec09c59c7a93612c7afded17 Mon Sep 17 00:00:00 2001 From: wanglin2 <1013335014@qq.com> Date: Mon, 10 Feb 2025 20:52:11 +0800 Subject: [PATCH 6/6] =?UTF-8?q?Feat:=E6=96=B0=E5=A2=9E=E6=B7=BB=E5=8A=A0?= =?UTF-8?q?=E8=8A=82=E7=82=B9=E8=87=AA=E5=AE=9A=E4=B9=89=E5=86=85=E5=AE=B9?= =?UTF-8?q?=E7=9A=84=E5=AE=9E=E4=BE=8B=E5=8C=96=E9=80=89=E9=A1=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../src/constants/defaultOptions.js | 19 +++++++++++++++++++ .../src/core/render/node/MindMapNode.js | 13 ++++++++++++- .../src/core/render/node/nodeLayout.js | 19 ++++++++++++++++++- 3 files changed, 49 insertions(+), 2 deletions(-) diff --git a/simple-mind-map/src/constants/defaultOptions.js b/simple-mind-map/src/constants/defaultOptions.js index c655211e..25e39f28 100644 --- a/simple-mind-map/src/constants/defaultOptions.js +++ b/simple-mind-map/src/constants/defaultOptions.js @@ -302,6 +302,25 @@ export const defaultOpt = { }, // 自定义快捷创建子节点按钮的点击操作, customQuickCreateChildBtnClick: null, + // 添加自定义的节点内容 + // 可传递一个对象,格式如下: + /* + { + // 返回要添加的DOM元素详细 + create: (node) => { + return { + el, // DOM节点 + width: 20, // 宽高 + height: 20 + } + }, + // 处理生成的@svgdotjs/svg.js库的ForeignObject节点实例,可以设置其在节点内的位置 + handle: ({ content, element, node }) => { + + } + } + */ + addCustomContentToNode: null, // 【Select插件】 // 多选节点时鼠标移动到边缘时的画布移动偏移量 diff --git a/simple-mind-map/src/core/render/node/MindMapNode.js b/simple-mind-map/src/core/render/node/MindMapNode.js index aa1812fa..86dd9e5b 100644 --- a/simple-mind-map/src/core/render/node/MindMapNode.js +++ b/simple-mind-map/src/core/render/node/MindMapNode.js @@ -99,6 +99,7 @@ class MindMapNode { this._generalizationList = [] this._unVisibleRectRegionNode = null this._isMouseenter = false + this._customContentAddToNodeAdd = null // 尺寸信息 this._rectInfo = { textContentWidth: 0, @@ -216,7 +217,8 @@ class MindMapNode { isUseCustomNodeContent, customCreateNodeContent, createNodePrefixContent, - createNodePostfixContent + createNodePostfixContent, + addCustomContentToNode } = this.mindMap.opt // 需要创建的内容类型 const typeList = [ @@ -289,6 +291,15 @@ class MindMapNode { addXmlns(this._postfixData.el) } } + if ( + addCustomContentToNode && + typeof addCustomContentToNode.create === 'function' + ) { + this._customContentAddToNodeAdd = addCustomContentToNode.create(this) + if (this._customContentAddToNodeAdd && this._customContentAddToNodeAdd.el) { + addXmlns(this._customContentAddToNodeAdd.el) + } + } } // 计算节点的宽高 diff --git a/simple-mind-map/src/core/render/node/nodeLayout.js b/simple-mind-map/src/core/render/node/nodeLayout.js index b6004b05..7844c0e3 100644 --- a/simple-mind-map/src/core/render/node/nodeLayout.js +++ b/simple-mind-map/src/core/render/node/nodeLayout.js @@ -177,7 +177,8 @@ function layout() { const { hoverRectPadding, openRealtimeRenderOnNodeTextEdit, - textContentMargin + textContentMargin, + addCustomContentToNode } = this.mindMap.opt // 避免编辑过程中展开收起按钮闪烁的问题 if (openRealtimeRenderOnNodeTextEdit && this._expandBtn) { @@ -428,6 +429,22 @@ function layout() { } textContentNested.translate(translateX, translateY) addHoverNode() + if (this._customContentAddToNodeAdd && this._customContentAddToNodeAdd.el) { + const foreignObject = createForeignObjectNode( + this._customContentAddToNodeAdd + ) + this.group.add(foreignObject) + if ( + addCustomContentToNode && + typeof addCustomContentToNode.handle === 'function' + ) { + addCustomContentToNode.handle({ + content: this._customContentAddToNodeAdd, + element: foreignObject, + node: this + }) + } + } this.mindMap.emit('node_layout_end', this) }