An open-source, privacy-first, self-hosted knowledge workspace where humans and AI agents work together 开源、隐私优先、自托管的知识工作空间,让人与智能体在此协作
TypeScript agentic-aiai-agentknowledge-baselocal-firstmarkdownmcpmindmapnote-takingself-hostedsiyuanworkspace
:bug: Correct mind map summary previews on selection and blur https://github.com/siyuan-note/siyuan/issues/20812
Daniel582182f3cc1b
diff --git a/app/src/protyle/render/listMindmap/model.test.ts b/app/src/protyle/render/listMindmap/model.test.tsindex 8f38ee8f17..a20f696c61 100644--- a/app/src/protyle/render/listMindmap/model.test.ts+++ b/app/src/protyle/render/listMindmap/model.test.ts@@ -4682,12 +4682,42 @@ const browserCases = async (sourceCode: string, css: string, taskSource: string,await settle();summaryView.focusNode(summaryIds[0]);const summaryButton = summaryHost.querySelector<HTMLButtonElement>(".mindmap-view__summary-action");- check.equal(summaryButton.disabled, false);+ for (const id of [summaryModel.root.id, summaryIds[0]]) {+ summaryView.focusNode(id);+ check.equal(summaryButton.hidden, true, "a single selected node has no summary action");+ check.equal(summaryButton.disabled, true, "a single selected node cannot create a summary");+ summaryButton.click();+ check.equal(api.readListMindmap(summaryList).metadata.summaries?.length || 0, 0);+ }for (const id of summaryIds.slice(1)) {summaryView.selectNode(id, true);}await settle();check.equal(summaryButton.hidden, false);+ check.equal(summaryButton.disabled, false);+ const summaryCanvas = summaryHost.querySelector<HTMLCanvasElement>("canvas");+ const outsideSummary = document.createElement("button");+ document.body.append(outsideSummary);+ for (const leave of [+ () => window.dispatchEvent(new Event("blur")),+ () => summaryHost.dispatchEvent(new FocusEvent("focusout", {relatedTarget: outsideSummary})),+ ]) {+ const preview = summaryCanvas.toDataURL();+ const selected = summaryView.getSelectedIds();+ leave();+ check.equal(summaryButton.hidden, true, "leaving the mindmap hides the summary action");+ check.deepEqual(summaryView.getSelectedIds(), selected, "focus changes preserve the node selection");+ const inactive = summaryCanvas.toDataURL();+ check.ok(inactive !== preview, "leaving the mindmap immediately clears the dashed summary preview");+ summaryView.draw();+ check.equal(summaryCanvas.toDataURL(), inactive, "no stale preview remains until a later redraw");+ summaryView.focusNode(summaryIds[0]);+ for (const id of summaryIds.slice(1)) {+ summaryView.selectNode(id, true);+ }+ check.equal(summaryButton.hidden, false, "multi-selection restores the summary action");+ }+ outsideSummary.remove();check.equal(summaryHost.querySelector('.mindmap-view__inspector [aria-label="listMindmapSummary"]'), null);const summaryActionBounds = summaryButton.getBoundingClientRect();check.equal(document.elementFromPoint(summaryActionBounds.left + summaryActionBounds.width / 2,diff --git a/app/src/protyle/render/listMindmap/summaryView.test.ts b/app/src/protyle/render/listMindmap/summaryView.test.tsindex 1d7e5c9093..6e787044b3 100644--- a/app/src/protyle/render/listMindmap/summaryView.test.ts+++ b/app/src/protyle/render/listMindmap/summaryView.test.ts@@ -30,13 +30,16 @@ test("summary previews and committed paths match across styles, zoom levels andconst sandbox: any = {Path2D: PathFixture, buildListMindmapSummaryConnector, layoutListMindmapSummaries, getListMindmapSummarySelection};runInNewContext(compiled, sandbox);const view = new sandbox.View();- const child: ListMindmapNode = {id: "a", parentId: "root", children: [], contentBlocks: [], virtual: false, collapsed: false};- const root: ListMindmapNode = {id: "root", children: [child], contentBlocks: [], virtual: true, collapsed: false};- const range = {parentId: "root", nodeIds: ["a"]};- const model: ListMindmapModel = {list: undefined, root, nodes: new Map([["root", root], ["a", child]]),+ const children = ["a", "b"].map((id): ListMindmapNode =>+ ({id, parentId: "root", children: [], contentBlocks: [], virtual: false, collapsed: false}));+ const root: ListMindmapNode = {id: "root", children, contentBlocks: [], virtual: true, collapsed: false};+ const range = {parentId: "root", nodeIds: ["a", "b"]};+ const model: ListMindmapModel = {list: undefined, root, nodes: new Map([root, ...children].map(node => [node.id, node])),metadata: {version: 1, nodes: {}, relations: [], connectorStyle}};- const positions = new Map([["a", {id: "a", x: 100, y: 40, width: 120, height: 50}]]);- Object.assign(view, {model, positions, summaryPositions: new Map(), getSelectedIds: () => ["a"],+ const positions = new Map(children.map((node, index) =>+ [node.id, {id: node.id, x: 100, y: 40 + index * 80, width: 120, height: 50}]));+ let selected = ["a"];+ Object.assign(view, {model, positions, summaryPositions: new Map(), getSelectedIds: () => selected,inspector: {hidden: false, getBoundingClientRect: () => ({left: 0, right: 0, top: 0, bottom: 0})},summaryAction: {offsetWidth: 80, offsetHeight: 32, style: {}, setAttribute: () => {}},label: (key: string) => key, offsetX: 0, offsetY: 0, getToolbarBounds: (): DOMRect[] => [],@@ -46,6 +49,10 @@ test("summary previews and committed paths match across styles, zoom levels andconst context = {save: () => {}, restore: () => {}, setLineDash: () => {},stroke: (path: PathFixture) => strokes.push(path)};view.drawSummaryPreview(context, "blue");+ assert.equal(strokes.length, 0, "single selection does not draw a summary preview");+ assert.equal(view.summaryAction.hidden, true);+ selected = ["a", "b"];+ view.drawSummaryPreview(context, "blue");assert.equal(strokes.length, 1);assert.equal(view.summaryAction.hidden, false);const preview = strokes.pop();@@ -141,9 +148,10 @@ test("summary creation consumes the current selection once and retains the snapsassert.equal(calls.length, 1, "identical ranges do not submit again");});-test("invalid, crossing, duplicate and read-only summary selections never submit", async () => {- for (const mode of ["empty", "virtual", "crossing", "duplicate", "readonly", "locked", "export"]) {+test("single, invalid, crossing, duplicate and read-only summary selections never submit", async () => {+ for (const mode of ["single", "empty", "virtual", "crossing", "duplicate", "readonly", "locked", "export"]) {const {view, model, calls, select} = create();+ if (mode === "single") { select(["a"]); }if (mode === "empty") { select([]); }if (mode === "virtual") { select(["root"]); }if (mode === "crossing" || mode === "duplicate") {diff --git a/app/src/protyle/render/listMindmap/view.ts b/app/src/protyle/render/listMindmap/view.tsindex 8709749653..9e24381e97 100644--- a/app/src/protyle/render/listMindmap/view.ts+++ b/app/src/protyle/render/listMindmap/view.ts@@ -490,6 +490,7 @@ export class ListMindmapView {this.summaryStatus.hidden = true;this.summaryAction.hidden = true;const selecting = !!this.relationFrom || this.multiSelect;+ const inspectorVisible = !this.inspector.hidden;this.multiSelect = false;this.pinching = false;this.pinch = undefined;@@ -500,6 +501,8 @@ export class ListMindmapView {this.inspector.hidden = true;if (selecting) {this.updateSelection();+ } else if (inspectorVisible) {+ this.draw();}}}@@ -1324,6 +1327,9 @@ export class ListMindmapView {return;}const selected = this.getSelectedIds();+ if (selected.length < 2) {+ return;+ }const {ranges, conflict} = getListMindmapSummarySelection(this.model, new Set(selected));if (conflict || !ranges.length) {return;@@ -1432,7 +1438,8 @@ export class ListMindmapView {}private drawSummaryPreview(context: CanvasRenderingContext2D, color: string) {- if (this.readOnly || this.inspector.hidden || this.printTransform || this.options.printLayout) {+ if (this.readOnly || this.inspector.hidden || this.getSelectedIds().length < 2 ||+ this.printTransform || this.options.printLayout) {this.summaryAction.hidden = true;return;}@@ -2148,7 +2155,8 @@ export class ListMindmapView {const {ranges, conflict} = getListMindmapSummarySelection(this.model, new Set(this.getSelectedIds()));const disabled: Record<string, boolean> = {relation: !node || node.virtual || this.getSelectedIds().length > 1,- summary: this.readOnly || this.summaryPending || conflict || !ranges.length || !this.options.onSummaryBatchAdd,+ summary: this.readOnly || this.summaryPending || this.getSelectedIds().length < 2 ||+ conflict || !ranges.length || !this.options.onSummaryBatchAdd,style: !node && !this.selectedRelation && !this.selectedEdge,};Object.keys(disabled).forEach((key) => {