From 13dc61a5857391c19946204af77cc59955fb25b1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=B0=8F=E7=89=9B=E4=BB=94?= <635750556@qq.com> Date: Fri, 17 Nov 2023 16:20:02 +0800 Subject: [PATCH] =?UTF-8?q?=E6=97=A7=E7=89=88=E6=9C=ACxmind8=E6=94=AF?= =?UTF-8?q?=E6=8C=81=E5=AF=BC=E5=85=A5=E6=A6=82=E8=A6=81=EF=BC=8C=E8=80=81?= =?UTF-8?q?=E7=9A=84=E6=B3=A8=E8=A7=A3=E8=A2=AB=E6=90=9E=E6=88=90=E4=BA=86?= =?UTF-8?q?=E4=B8=80=E4=B8=AA=E4=B8=BB=E9=A2=98=E4=BA=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- simple-mind-map/src/parse/xmind.js | 79 +++++++++++++++++++++++++++--- 1 file changed, 73 insertions(+), 6 deletions(-) diff --git a/simple-mind-map/src/parse/xmind.js b/simple-mind-map/src/parse/xmind.js index 2615fd85..ec630657 100644 --- a/simple-mind-map/src/parse/xmind.js +++ b/simple-mind-map/src/parse/xmind.js @@ -122,7 +122,7 @@ const transformXmind = async (content, files) => { let summariesPosition = {} if (node.summaries && node.summaries.length > 0) { node.summaries.forEach(item => { - // 使用正则表达式提取第二个数字,例如 (2,3) + // 使用正则表达式提取位置数字,例如 (2,3) const match = item.range.match(/\((\d+),(\d+)\)/) const firstNumber = match ? parseInt(match[1], 10) : null const secondNumber = match ? parseInt(match[2], 10) : null @@ -227,20 +227,87 @@ const transformOldXmind = content => { } catch (error) { console.log(error) } + + // 概要 + if (node.currentSummary) { + let summaryText = '' + if (node.currentSummary + && node.currentSummary.elements + && node.currentSummary.elements[0] + && node.currentSummary.elements[0].elements + && node.currentSummary.elements[0].elements[0]) { + summaryText = node.currentSummary.elements[0].elements[0].text + } + newNode.data.generalization = { + text: summaryText, + expand: true, + isActive: false, + } + } + // 子节点 newNode.children = [] + let _children = getItemByName(nodeElements, 'children') if (_children && _children.elements && _children.elements.length > 0) { + let summaryNode = null + let summariesNode = getItemByName(nodeElements, 'summaries') _children.elements.forEach(item => { + if (item.name === 'topics' && item.attributes.type === 'summary') { + summaryNode = item + return + } + }) + + // 分析概要位置 + // xmind 支持合并概要,现在的组件不支持合并概要,分别拆分开来 + let summariesPosition = {} + if (summariesNode !== null && summariesNode.elements && summariesNode.elements.length > 0) { + summariesNode.elements.forEach(item => { + // 使用正则表达式提取位置数字,例如 (2,3) + const match = item.attributes.range.match(/\((\d+),(\d+)\)/) + const firstNumber = match ? parseInt(match[1], 10) : null + const secondNumber = match ? parseInt(match[2], 10) : null + summariesPosition[item.attributes['topic-id']] = [] + for (let i = firstNumber; i <= secondNumber; i++) { + summariesPosition[item.attributes['topic-id']].push(i) + } + }) + } + + let summariesPositionData = {} + if (summaryNode !== null && summaryNode.elements && summaryNode.elements.length > 0) { + summaryNode.elements.forEach(summary => { + if (Object.prototype.hasOwnProperty.call(summariesPosition, summary.attributes.id)) { + summariesPosition[summary.attributes.id].forEach (index => { + summariesPositionData[index] = summary + }) + } + }) + } + + _children.elements.forEach((item, index) => { if (item.name === 'topics') { - ;(item.elements || []).forEach(item2 => { - let newChild = {} - newNode.children.push(newChild) - walk(item2, newChild) - }) + if (item.attributes.type !== 'summary') { + (item.elements || []).forEach((item2, index2) => { + let newChild = {} + let currentSummary = null + if (Object.prototype.hasOwnProperty.call(summariesPositionData, index2)) { + currentSummary = summariesPositionData[index2] + } + newNode.children.push(newChild) + item2.currentSummary = currentSummary + walk(item2, newChild) + }) + } } else { let newChild = {} + let currentSummary = null + if (Object.prototype.hasOwnProperty.call(summariesPositionData, index)) { + currentSummary = summariesPositionData[index] + } newNode.children.push(newChild) + item.currentSummary = currentSummary walk(item, newChild) } })