From bbe2dc18865a4c580c40990e8c53169efda044cc Mon Sep 17 00:00:00 2001 From: jinzcdev Date: Sat, 10 May 2025 21:58:57 +0800 Subject: [PATCH 1/3] fix: correct `undefined` in summary subtopics with boundaries - add unit tests for summary subtopics with boundaries --- src/parser/mindmap.ts | 4 ++++ src/parser/mindmark.ts | 4 ++-- src/parser/summary.spec.ts | 22 ++++++++++++++++++++++ 3 files changed, 28 insertions(+), 2 deletions(-) diff --git a/src/parser/mindmap.ts b/src/parser/mindmap.ts index 57153bd..c5477a5 100644 --- a/src/parser/mindmap.ts +++ b/src/parser/mindmap.ts @@ -240,6 +240,8 @@ export const addTopic = (parentObject, mainTopic = "Main Topic", options = {}) = id: UUID(), title: mainTopic, titleUnedited: true, + boundaries: [], + summaries: [], ...options } parentObject.children.attached.push(topicObject) @@ -331,6 +333,8 @@ export const addSingleSummary = (parentObject, topicObject, options = {}) => { id: UUID(), title: "Summary", titleUnedited: true, + boundaries: [], + summaries: [], ...options } parentObject.children.summary = parentObject.children.summary || [] diff --git a/src/parser/mindmark.ts b/src/parser/mindmark.ts index 83990a6..71cc660 100644 --- a/src/parser/mindmark.ts +++ b/src/parser/mindmark.ts @@ -106,7 +106,7 @@ function addLine(line: string, status: any) { topicObject.title = line parentObject.boundaries - .filter(b => b.name == name) + ?.filter(b => b.name == name) .some(b => { let index = parentObject.children.attached.indexOf(topicObject) @@ -133,7 +133,7 @@ function addLine(line: string, status: any) { topicObject.title = line parentObject.summaries - .filter(b => b.name == name) + ?.filter(b => b.name == name) .some(b => { let index = parentObject.children.attached.indexOf(topicObject) diff --git a/src/parser/summary.spec.ts b/src/parser/summary.spec.ts index b49a88f..a1c921e 100644 --- a/src/parser/summary.spec.ts +++ b/src/parser/summary.spec.ts @@ -98,4 +98,26 @@ central topic }) + + it('Subtopics with boundaries', () => { + let map = createMapByXMindMark(` +central topic +* topic 1 [S] +* topic 2 [S] +[S] summary topic + - subtopic 1 [B] + - subtopic 2 [B] + [B] boundary topic + `) + let summaryTopic = map.rootTopic.children.summary[0] + strictEqual('summary topic', summaryTopic.title) + strictEqual('subtopic 1 ', summaryTopic.children.attached[0].title) + strictEqual('subtopic 2 ', summaryTopic.children.attached[1].title) + let summary = map.rootTopic.summaries[0] + strictEqual('(0,1)', summary.range) + strictEqual(summaryTopic.id, summary.topicId) + let boundary = summaryTopic.boundaries[0] + strictEqual('(0,1)', boundary.range) + strictEqual('boundary topic', boundary.title) + }) }) From 8dba0cd0cdf3655c4775b988213f5a1c74c8df03 Mon Sep 17 00:00:00 2001 From: jinzcdev Date: Sun, 11 May 2025 14:47:27 +0800 Subject: [PATCH 2/3] fix: fix summary handling with nested subtopics --- src/parser/mindmark.ts | 17 +++++++++++++++++ src/parser/summary.spec.ts | 30 ++++++++++++++++++++++++++++++ 2 files changed, 47 insertions(+) diff --git a/src/parser/mindmark.ts b/src/parser/mindmark.ts index 71cc660..4c310e5 100644 --- a/src/parser/mindmark.ts +++ b/src/parser/mindmark.ts @@ -43,6 +43,23 @@ function addLine(line: string, status: any) { status.lastTopic = topicObject + // Update levels array, setting summary topic as new parent topic level + // Use appropriate indentation level to ensure subsequent subtopics can correctly identify their parent + let summaryLevel = { + parent: topicObject, + indent: indent + 4, // Reserve indentation level for subtopics + boundaries: [], + summaries: [] + } + + // Add new level or replace existing level with same indentation + const existingLevelIndex = status.levels.findIndex(l => l.indent === indent + 4) + if (existingLevelIndex >= 0) { + status.levels[existingLevelIndex] = summaryLevel + } else { + status.levels.push(summaryLevel) + } + return } diff --git a/src/parser/summary.spec.ts b/src/parser/summary.spec.ts index a1c921e..d2ab12e 100644 --- a/src/parser/summary.spec.ts +++ b/src/parser/summary.spec.ts @@ -99,6 +99,36 @@ central topic }) + it('SubSubtopics', () => { + let map = createMapByXMindMark(` +central topic +- subtopic 1[S] + - subsubtopic 1 +[S] summary topic + - summarySubtopic 1 + - summarySubtopic 2 + `) + + let subtopic1 = map.rootTopic.children.attached[0]; + strictEqual('subtopic 1', subtopic1.title); + + // Verify subtopic 1's child topic, now there's only one child + strictEqual('subsubtopic 1', subtopic1.children.attached[0].title); + + // Verify summary topic + let summaryTopic = map.rootTopic.children.summary[0]; + strictEqual('summary topic', summaryTopic.title); + + // Verify child topics under summary topic + strictEqual('summarySubtopic 1', summaryTopic.children.attached[0].title); + strictEqual('summarySubtopic 2', summaryTopic.children.attached[1].title); + + // Verify summary relationship + let summary = map.rootTopic.summaries[0]; + strictEqual('(0,0)', summary.range); + strictEqual(summaryTopic.id, summary.topicId); + }) + it('Subtopics with boundaries', () => { let map = createMapByXMindMark(` central topic From 1e2e8ceea55edc7f3b722b58ee0b1a79e17a8a37 Mon Sep 17 00:00:00 2001 From: jinzcdev Date: Sun, 11 May 2025 15:13:34 +0800 Subject: [PATCH 3/3] fix: rename `relstionship.spec.ts` to `relationship.spec.ts` --- src/parser/{relstionship.spec.ts => relationship.spec.ts} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename src/parser/{relstionship.spec.ts => relationship.spec.ts} (100%) diff --git a/src/parser/relstionship.spec.ts b/src/parser/relationship.spec.ts similarity index 100% rename from src/parser/relstionship.spec.ts rename to src/parser/relationship.spec.ts