From 80727b759d15efaa515cc033467f6fe779c76659 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, 29 Mar 2024 18:02:02 +0800 Subject: [PATCH 1/4] =?UTF-8?q?Fix=EF=BC=9A=E4=BF=AE=E5=A4=8D=E6=90=9C?= =?UTF-8?q?=E7=B4=A2=E6=97=B6=E5=85=A8=E9=83=A8=E6=9B=BF=E6=8D=A2=E6=93=8D?= =?UTF-8?q?=E4=BD=9C=E6=8A=A5=E9=94=99=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/Search.js | 42 +++++++++++++++++---------- 1 file changed, 27 insertions(+), 15 deletions(-) diff --git a/simple-mind-map/src/plugins/Search.js b/simple-mind-map/src/plugins/Search.js index 7b5d69a4..8e7727ac 100644 --- a/simple-mind-map/src/plugins/Search.js +++ b/simple-mind-map/src/plugins/Search.js @@ -86,6 +86,7 @@ class Search { this.matchNodeList = [] this.currentIndex = -1 const { isOnlySearchCurrentRenderNodes } = this.mindMap.opt + // 如果要搜索收起来的节点,那么要遍历渲染树而不是节点树 const tree = isOnlySearchCurrentRenderNodes ? this.mindMap.renderer.root : this.mindMap.renderer.renderTree @@ -103,6 +104,11 @@ class Search { }) } + // 判断对象是否是节点实例 + isNodeInstance(node) { + return node instanceof Node + } + // 搜索下一个,定位到下一个匹配节点 searchNext(callback) { if (!this.isSearching || this.matchNodeList.length <= 0) return @@ -113,13 +119,12 @@ class Search { } const currentNode = this.matchNodeList[this.currentIndex] this.notResetSearchText = true - const uid = - currentNode instanceof Node - ? currentNode.getData('uid') - : currentNode.data.uid + const uid = this.isNodeInstance(currentNode) + ? currentNode.getData('uid') + : currentNode.data.uid const targetNode = this.mindMap.renderer.findNodeByUid(uid) this.mindMap.execCommand('GO_TARGET_NODE', uid, node => { - if (!(currentNode instanceof Node)) { + if (!this.isNodeInstance(currentNode)) { this.matchNodeList[this.currentIndex] = node } callback() @@ -173,15 +178,20 @@ class Search { return replaceText = String(replaceText) this.matchNodeList.forEach(node => { - let text = this.getReplacedText(node, this.searchText, replaceText) - this.mindMap.renderer.setNodeDataRender( - node, - { - text, - resetRichText: !!node.getData('richText') - }, - true - ) + const text = this.getReplacedText(node, this.searchText, replaceText) + if (this.isNodeInstance(node)) { + this.mindMap.renderer.setNodeDataRender( + node, + { + text, + resetRichText: !!node.getData('richText') + }, + true + ) + } else { + node.data.text = text + node.data.resetRichText = !!node.data.richText + } }) this.mindMap.render() this.mindMap.command.addHistory() @@ -190,7 +200,9 @@ class Search { // 获取某个节点替换后的文本 getReplacedText(node, searchText, replaceText) { - let { richText, text } = node.getData() + let { richText, text } = this.isNodeInstance(node) + ? node.getData() + : node.data if (richText) { return replaceHtmlText(text, searchText, replaceText) } else { From c0f69e038af037a59c97f3fd64e7e809d0bc522a 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: Mon, 1 Apr 2024 13:50:20 +0800 Subject: [PATCH 2/4] =?UTF-8?q?Feat=EF=BC=9A=E8=8A=82=E7=82=B9=E5=86=85?= =?UTF-8?q?=E5=AE=B9=E6=94=AF=E6=8C=81=E8=AE=BE=E7=BD=AE=E9=99=84=E4=BB=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- simple-mind-map/src/core/render/Render.js | 15 ++++++++- simple-mind-map/src/core/render/node/Node.js | 15 +++++++++ .../src/core/render/node/nodeCommandWraps.js | 6 ++++ .../core/render/node/nodeCreateContents.js | 33 ++++++++++++++++++- simple-mind-map/src/svg/icons.js | 5 +++ 5 files changed, 72 insertions(+), 2 deletions(-) diff --git a/simple-mind-map/src/core/render/Render.js b/simple-mind-map/src/core/render/Render.js index 4bfa6c31..c6be1777 100644 --- a/simple-mind-map/src/core/render/Render.js +++ b/simple-mind-map/src/core/render/Render.js @@ -65,7 +65,9 @@ class Render { this.mindMap = opt.mindMap this.themeConfig = this.mindMap.themeConfig // 渲染树,操作过程中修改的都是这里的数据 - this.renderTree = this.mindMap.opt.data ? merge({}, this.mindMap.opt.data) : null + this.renderTree = this.mindMap.opt.data + ? merge({}, this.mindMap.opt.data) + : null // 是否重新渲染 this.reRender = false // 是否正在渲染中 @@ -246,6 +248,9 @@ class Render { // 设置节点备注 this.setNodeNote = this.setNodeNote.bind(this) this.mindMap.command.add('SET_NODE_NOTE', this.setNodeNote) + // 设置节点附件 + this.setNodeAttachment = this.setNodeAttachment.bind(this) + this.mindMap.command.add('SET_NODE_ATTACHMENT', this.setNodeAttachment) // 设置节点标签 this.setNodeTag = this.setNodeTag.bind(this) this.mindMap.command.add('SET_NODE_TAG', this.setNodeTag) @@ -1600,6 +1605,14 @@ class Render { }) } + // 设置节点附件 + setNodeAttachment(node, url, name = '') { + this.setNodeDataRender(node, { + attachmentUrl: url, + attachmentName: name + }) + } + // 设置节点标签 setNodeTag(node, tag) { this.setNodeDataRender(node, { diff --git a/simple-mind-map/src/core/render/node/Node.js b/simple-mind-map/src/core/render/node/Node.js index 80863b74..8a1cad17 100644 --- a/simple-mind-map/src/core/render/node/Node.js +++ b/simple-mind-map/src/core/render/node/Node.js @@ -75,6 +75,7 @@ class Node { this._noteData = null this.noteEl = null this.noteContentIsShow = false + this._attachmentData = null this._expandBtn = null this._lastExpandBtnType = null this._showExpandBtn = false @@ -199,6 +200,7 @@ class Node { this._hyperlinkData = this.createHyperlinkNode() this._tagData = this.createTagNode() this._noteData = this.createNoteNode() + this._attachmentData = this.createAttachmentNode() } // 计算节点的宽高 @@ -267,6 +269,11 @@ class Node { textContentWidth += this._noteData.width textContentHeight = Math.max(textContentHeight, this._noteData.height) } + // 附件 + if (this._attachmentData) { + textContentWidth += this._attachmentData.width + textContentHeight = Math.max(textContentHeight, this._attachmentData.height) + } // 文字内容部分的尺寸 this._rectInfo.textContentWidth = textContentWidth this._rectInfo.textContentHeight = textContentHeight @@ -399,6 +406,14 @@ class Node { textContentNested.add(this._noteData.node) textContentOffsetX += this._noteData.width } + // 附件 + if (this._attachmentData) { + this._attachmentData.node + .x(textContentOffsetX) + .y((this._rectInfo.textContentHeight - this._attachmentData.height) / 2) + textContentNested.add(this._attachmentData.node) + textContentOffsetX += this._attachmentData.width + } // 文字内容整体 textContentNested.translate( width / 2 - textContentNested.bbox().width / 2, diff --git a/simple-mind-map/src/core/render/node/nodeCommandWraps.js b/simple-mind-map/src/core/render/node/nodeCommandWraps.js index 1a51130e..3f961cfa 100644 --- a/simple-mind-map/src/core/render/node/nodeCommandWraps.js +++ b/simple-mind-map/src/core/render/node/nodeCommandWraps.js @@ -28,6 +28,11 @@ function setNote(note) { this.mindMap.execCommand('SET_NODE_NOTE', this, note) } +// 设置附件 +function setAttachment(url, name) { + this.mindMap.execCommand('SET_NODE_ATTACHMENT', this, url, name) +} + // 设置标签 function setTag(tag) { this.mindMap.execCommand('SET_NODE_TAG', this, tag) @@ -55,6 +60,7 @@ export default { setIcon, setHyperlink, setNote, + setAttachment, setTag, setShape, setStyle, diff --git a/simple-mind-map/src/core/render/node/nodeCreateContents.js b/simple-mind-map/src/core/render/node/nodeCreateContents.js index 8fe5f3c7..20fda808 100644 --- a/simple-mind-map/src/core/render/node/nodeCreateContents.js +++ b/simple-mind-map/src/core/render/node/nodeCreateContents.js @@ -262,7 +262,7 @@ function createHyperlinkNode() { e.stopPropagation() }) if (hyperlinkTitle) { - a.attr('title', hyperlinkTitle) + node.add(SVG(`
%
ze^lu{{=^bL^NWsOE5~pA&L7<5FYd6mdHlV3{KLObb==ol6WXz}e8wnm^A;^Ma)btU
zXjf}F&K$E$@jgv_&Nja01h3N0cbsA`U$KkV`G(!hFwFpm*~dXTd5#6nFvN#+bAUJa
zl<)b3K_%r2dN|Fbl5~z2=wc`HY~dI$e=){5FY^(7)bS;~Y~@>8spl1{`IzS!;RB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