Skip to content

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

:bug: Restore mind map to list conversion control https://github.com/siyuan-note/siyuan/issues/19818

Vanessac3fa982ff678
diff --git a/app/src/protyle/render/listMindmap/model.test.ts b/app/src/protyle/render/listMindmap/model.test.ts
index af147a098a..dc9c544799 100644
--- a/app/src/protyle/render/listMindmap/model.test.ts
+++ b/app/src/protyle/render/listMindmap/model.test.ts
@@ -730,6 +730,7 @@ const browserCases = async (sourceCode: string, css: string, taskSource: string,
let interactions = 0;
let undo = 0;
let redo = 0;
+ let exits = 0;
let finishAllowed: boolean | Promise<boolean> = true;
const options = {
host, model,
@@ -754,12 +755,21 @@ const browserCases = async (sourceCode: string, css: string, taskSource: string,
onRelationAdd: (...args: unknown[]) => relationAdditions.push(args),
onRelationChange: (...args: unknown[]) => relationChanges.push(args),
onRelationDelete: (id: string) => relationDeletions.push(id),
- onExit: (): void => undefined,
+ onExit: () => exits++,
};
const frame = () => new Promise<void>(resolve => requestAnimationFrame(() => resolve()));
const settle = async () => { await frame(); await frame(); };
const view = new api.ListMindmapView(options);
await settle();
+ const listButton = host.querySelector<HTMLButtonElement>('.mindmap-view__toolbar button[aria-label="listBlock"]');
+ check.ok(listButton);
+ check.equal(listButton.querySelector("use").getAttribute("xlink:href"), "#iconList");
+ finishAllowed = false;
+ listButton.click();
+ check.equal(exits, 0, "conversion waits for pending node edits");
+ finishAllowed = true;
+ listButton.click();
+ check.equal(exits, 1, "the toolbar restores the list conversion action");
const viewport = host.querySelector<HTMLElement>(".mindmap-view__viewport");
check.equal(viewport.getAttribute("data-prevent-swipe"), "true");
const originalCapture = HTMLElement.prototype.setPointerCapture;
@@ -1816,6 +1826,7 @@ const browserCases = async (sourceCode: string, css: string, taskSource: string,
const readonly = new api.ListMindmapView({...options, readOnly: true});
await settle();
+ check.equal(host.querySelector('.mindmap-view__toolbar [aria-label="listBlock"]'), null);
check.equal(host.querySelector('.mindmap-view__toolbar [aria-label="listMindmapChild"]'), null);
check.equal(host.querySelector('[aria-label="undo"]'), null);
nodeElement(beta).dispatchEvent(new MouseEvent("dblclick", {bubbles: true}));
diff --git a/app/src/protyle/render/listMindmap/toggle.test.ts b/app/src/protyle/render/listMindmap/toggle.test.ts
index 5c596111b2..014c3e1376 100644
--- a/app/src/protyle/render/listMindmap/toggle.test.ts
+++ b/app/src/protyle/render/listMindmap/toggle.test.ts
@@ -24,6 +24,7 @@ const setup = () => {
closest: (selector: string) => selector === ".protyle-wysiwyg" ? root : embed,
getAttribute: (name: string) => attrs.get(name),
setAttribute: (name: string, value: string) => attrs.set(name, value),
+ removeAttribute: (name: string) => attrs.delete(name),
};
const operations: {doOperations: any[], undoOperations: any[]}[] = [];
const updates: string[] = [];
@@ -53,6 +54,17 @@ test("a regular list becomes a dedicated mind map block", () => {
assert.equal(operations.length, 0);
});
+test("a dedicated mind map becomes a list block", () => {
+ const {owner, list, attrs, attribute, operations, updates, api} = setup();
+ attrs.delete(attribute);
+ list.dataset.type = "NodeMindmap";
+ list.outerHTML = '<div data-type="NodeMindmap"></div>';
+ api.toggleListMindmap(owner, list);
+ assert.equal(list.dataset.type, "NodeList");
+ assert.deepEqual(updates, ['<div data-type="NodeMindmap"></div>']);
+ assert.equal(operations.length, 0);
+});
+
test("embedded mind maps persist view changes against the source list with undo", () => {
const {owner, list, attrs, attribute, operations, api} = setup();
assert.equal(api.canEdit(owner, list), false, "embedded node content remains read-only");
diff --git a/app/src/protyle/render/listMindmap/view.ts b/app/src/protyle/render/listMindmap/view.ts
index 9283a76d0a..1dcc19e17e 100644
--- a/app/src/protyle/render/listMindmap/view.ts
+++ b/app/src/protyle/render/listMindmap/view.ts
@@ -373,6 +373,9 @@ export class ListMindmapView {
this.buttons.set(id, button);
this.toolbar.append(button);
};
+ if (!this.options.readOnly) {
+ add("list", "listBlock", "iconList", () => this.options.onExit());
+ }
this.toolbar.append(createElement("span", "mindmap-view__spacer fn__flex-1"));
if (!this.options.readOnly) {
add("relation", "connect", "iconRoute", () => {