Skip to content

An open-source, privacy-first, self-hosted knowledge workspace where humans and AI agents work together 开源、隐私优先、自托管的知识工作空间,让人与智能体在此协作

:sparkles: Convert tabs directly to mind maps https://github.com/siyuan-note/siyuan/issues/20579

Daniel521b6c211f37
diff --git a/app/src/protyle/gutter/index.ts b/app/src/protyle/gutter/index.ts
index d45e62b602..6181309bc4 100644
--- a/app/src/protyle/gutter/index.ts
+++ b/app/src/protyle/gutter/index.ts
@@ -1967,6 +1967,7 @@ export class Gutter {
{menuId: "list", icon: "iconList", label: "list", type: "Tabs2UL"},
{menuId: "orderedList", icon: "iconOrderedList", label: "ordered-list", type: "Tabs2OL"},
{menuId: "check", icon: "iconCheck", label: "check", type: "Tabs2TL"},
+ {menuId: "listMindmap", icon: "iconMindmap", label: "mindmap", type: "Tabs2Mindmap"},
].forEach(target => turnIntoSubmenu.push(this.turnsOneInto({
...target,
id,
diff --git a/app/src/protyle/gutter/turnIntoMenu.test.ts b/app/src/protyle/gutter/turnIntoMenu.test.ts
index 3f7f8f4712..f39bc74265 100644
--- a/app/src/protyle/gutter/turnIntoMenu.test.ts
+++ b/app/src/protyle/gutter/turnIntoMenu.test.ts
@@ -47,6 +47,18 @@ test("partial paragraph and heading menus keep their candidates and callbacks",
}
});
+test("tabs expose direct mind map conversion through the existing configurable entry", () => {
+ const source = readFileSync(resolve(process.cwd(), "src/protyle/gutter/index.ts"), "utf8");
+ const tabsMenu = source.slice(source.indexOf('} else if (type === "NodeTabs" && allowStructuralMutation)'),
+ source.indexOf('} else if (type === "NodeBlockquote" && allowStructuralMutation)'));
+ assert.match(tabsMenu, /menuId: "listMindmap", icon: "iconMindmap", label: "mindmap", type: "Tabs2Mindmap"/);
+ const catalog = getEntryCatalogChildren("gutter.single.turnInto");
+ assert.equal(catalog.filter(item => item.key === "listMindmap").length, 1);
+ assert.equal(catalog.find(item => item.key === "listMindmap").simple, true);
+ assert.deepEqual(orderGutterTurnIntoItems(["superBlock", "listMindmap", "check", "list", "orderedList"], key => key),
+ ["list", "orderedList", "check", "listMindmap", "superBlock"]);
+});
+
test("blockquote callout types retain existing catalog identities and saved orders", () => {
const path = "gutter.single.turnInto";
const types = [...CALLOUT_PRESETS.map(item => item.id), "calloutCustom"];
diff --git a/app/src/protyle/render/listMindmap/model.test.ts b/app/src/protyle/render/listMindmap/model.test.ts
index df4a4e5ff5..c7fda15c88 100644
--- a/app/src/protyle/render/listMindmap/model.test.ts
+++ b/app/src/protyle/render/listMindmap/model.test.ts
@@ -801,6 +801,21 @@ const browserCases = async (sourceCode: string, css: string, taskSource: string,
check.equal(convertedTabs.getAttribute("data-type"), "NodeTabs");
check.equal(convertedTabs.querySelectorAll(':scope > [data-type="NodeTabItem"]').length, 2);
check.ok(convertedTabs.textContent.includes("Nested"));
+ const tabsBefore = convertedTabs.outerHTML;
+ const tabsIDs = ids(convertedTabs).filter(id =>
+ convertedTabs.querySelector(`[data-node-id="${id}"]`).getAttribute("tabs-placeholder") !== "true");
+ const directMindmap = api.convertTabsList(convertedTabs, "Tabs2Mindmap", lute);
+ check.equal(directMindmap.getAttribute("data-type"), "NodeMindmap");
+ check.equal(directMindmap.getAttribute("data-node-id"), convertedTabs.getAttribute("data-node-id"));
+ check.equal(directMindmap.querySelectorAll(':scope > [data-type="NodeMindmapItem"]').length, 2);
+ check.ok(directMindmap.querySelector('[data-type="NodeMindmapItem"] [data-type="NodeMindmap"]'));
+ check.deepEqual(ids(directMindmap), tabsIDs);
+ check.equal(directMindmap.querySelector('[data-type="NodeTabs"], [data-type="NodeTabItem"]'), null);
+ check.equal(directMindmap.getAttribute("tabs-active-id"), null);
+ check.ok(directMindmap.textContent.includes("Alpha") && directMindmap.textContent.includes("Nested") &&
+ directMindmap.textContent.includes("Beta"));
+ check.equal(lute.BlockDOM2Md(directMindmap.outerHTML).includes("Nested"), true);
+ check.equal(convertedTabs.outerHTML, tabsBefore, "direct conversion preserves the undo source");
check.equal(typedList.outerHTML, typedBefore);
check.equal(cleaned.includes("Derived editor"), false);
check.equal(cleaned.includes("data-mindmap-view-rendered"), false);
@@ -3736,10 +3751,10 @@ test("list mindmap mutations preserve block data in the real DOM and Lute", {
${shortcutStatements.map(item => item.getText(keydownSource)).join("\n")}
};
class ListHint {${fill.getText(hintSource)}}`, {compilerOptions: {target: typescript.ScriptTarget.ES2021}}).outputText;
- const tabsSource = "const {tabsRender, destroyTabsRender, getTabTask, revealTabsForTarget} = (() => {" +
+ const tabsSource = "const {tabsRender, destroyTabsRender, getTabTask, getTabTitle, getTabTitleBlock, revealTabsForTarget} = (() => {" +
["../../../util/escape.ts", "../tabsState.ts", "../tabsDrag.ts", "../tabsAttributes.ts", "../tabsVisibility.ts", "../tabsRender.ts"]
.map(file => compile(path.join(__dirname, file))).join("\n") +
- "return {tabsRender, destroyTabsRender, getTabTask, revealTabsForTarget};})();\n";
+ "return {tabsRender, destroyTabsRender, getTabTask, getTabTitle, getTabTitleBlock, revealTabsForTarget};})();\n";
const source = tabsSource + compile(path.join(__dirname, "../../wysiwyg/tabsList.ts")) +
compile(path.join(__dirname, "../av/richTextValue.ts")) + compile(path.join(__dirname, "../../wysiwyg/listContext.ts")) +
compile(path.join(__dirname, "summary.ts")) + compile(path.join(__dirname, "model.ts")) + compile(path.join(__dirname, "fold.ts")) +
diff --git a/app/src/protyle/wysiwyg/tabsList.test.ts b/app/src/protyle/wysiwyg/tabsList.test.ts
index 962d74357e..974777fd12 100644
--- a/app/src/protyle/wysiwyg/tabsList.test.ts
+++ b/app/src/protyle/wysiwyg/tabsList.test.ts
@@ -1,6 +1,18 @@
import * as assert from "node:assert/strict";
import {test} from "node:test";
-import {isEmptyTabPlaceholder} from "./tabsList";
+
+const buildGlobals = ["SIYUAN_VERSION", "NODE_ENV"].map(name => ({
+ name, descriptor: Object.getOwnPropertyDescriptor(globalThis, name),
+}));
+buildGlobals.forEach(({name}) => Object.defineProperty(globalThis, name, {configurable: true, value: "test"}));
+const {isEmptyTabPlaceholder}: typeof import("./tabsList") = require("./tabsList");
+buildGlobals.forEach(({name, descriptor}) => {
+ if (descriptor) {
+ Object.defineProperty(globalThis, name, descriptor);
+ } else {
+ Reflect.deleteProperty(globalThis, name);
+ }
+});
const paragraph = (attrs: Record<string, string>, text = "", rich = false) => ({
attributes: Object.entries(attrs).map(([name, value]) => ({name, value})),
diff --git a/app/src/protyle/wysiwyg/tabsList.ts b/app/src/protyle/wysiwyg/tabsList.ts
index 5f5851750f..c6b915c3ff 100644
--- a/app/src/protyle/wysiwyg/tabsList.ts
+++ b/app/src/protyle/wysiwyg/tabsList.ts
@@ -1,9 +1,10 @@
import {getTabTitle, getTabTitleBlock} from "../render/tabsRender";
+import {retagMindmapBranch} from "../render/listMindmap/model";
-export type TTabsListConversion = "List2Tabs" | "Tabs2UL" | "Tabs2OL" | "Tabs2TL";
+export type TTabsListConversion = "List2Tabs" | "Tabs2UL" | "Tabs2OL" | "Tabs2TL" | "Tabs2Mindmap";
export const isTabsListConversion = (type: string): type is TTabsListConversion =>
- ["List2Tabs", "Tabs2UL", "Tabs2OL", "Tabs2TL"].includes(type);
+ ["List2Tabs", "Tabs2UL", "Tabs2OL", "Tabs2TL", "Tabs2Mindmap"].includes(type);
const blockChildren = (element: Element): Element[] => Array.from(
(element.getAttribute("data-type") === "NodeTabItem" ?
@@ -170,5 +171,8 @@ export const convertTabsList = (source: Element, type: TTabsListConversion, lute
?.insertAdjacentHTML("afterbegin", "<wbr>");
}
}
+ if (type === "Tabs2Mindmap") {
+ retagMindmapBranch(result, true);
+ }
return result;
};