An open-source, privacy-first, self-hosted knowledge workspace where humans and AI agents work together 开源、隐私优先、自托管的知识工作空间,让人与智能体在此协作
TypeScript agentic-aiai-agentknowledge-baselocal-firstmarkdownmcpmindmapnote-takingself-hostedsiyuanworkspace
:art: Improve mindmap summary appearance and pan feedback https://github.com/siyuan-note/siyuan/issues/19747
Danielbd3911b342c1
diff --git a/app/appearance/icons/index.html b/app/appearance/icons/index.htmlindex c4f9aa7109..647982466e 100644--- a/app/appearance/icons/index.html+++ b/app/appearance/icons/index.html@@ -856,6 +856,12 @@</svg>iconHand</div>+ <div>+ <svg>+ <use xlink:href="#iconPan"></use>+ </svg>+ iconPan+ </div><div><svg><use xlink:href="#iconShieldCheck"></use>diff --git a/app/appearance/icons/litheness/icon.js b/app/appearance/icons/litheness/icon.jsindex 70d520ef87..27f5cae365 100644--- a/app/appearance/icons/litheness/icon.js+++ b/app/appearance/icons/litheness/icon.js@@ -430,6 +430,9 @@ document.body.insertAdjacentHTML('afterbegin', `<svg id="iconsLitheness" style="<symbol id="iconHand" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.7" stroke-linecap="round" stroke-linejoin="round"><path d="M22 14a8 8 0 0 1-8 8"/><path d="M18 11v-1a2 2 0 0 0-2-2a2 2 0 0 0-2 2"/><path d="M14 10V9a2 2 0 0 0-2-2a2 2 0 0 0-2 2v1"/><path d="M10 9.5V4a2 2 0 0 0-2-2a2 2 0 0 0-2 2v10"/><path d="M18 11a2 2 0 1 1 4 0v3a8 8 0 0 1-8 8h-2c-2.8 0-4.5-.86-5.99-2.34l-3.6-3.6a2 2 0 0 1 2.83-2.82L7 15"/></symbol>+ <symbol id="iconPan" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.7" stroke-linecap="round" stroke-linejoin="round">+ <path d="M18 11V6a2 2 0 0 0-2-2a2 2 0 0 0-2 2"/><path d="M14 10V4a2 2 0 0 0-2-2a2 2 0 0 0-2 2v2"/><path d="M10 10.5V6a2 2 0 0 0-2-2a2 2 0 0 0-2 2v8"/><path d="M18 8a2 2 0 1 1 4 0v6a8 8 0 0 1-8 8h-2c-2.8 0-4.5-.86-5.99-2.34l-3.6-3.6a2 2 0 0 1 2.83-2.82L7 15"/>+ </symbol><symbol id="iconShieldCheck" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.7" stroke-linecap="round" stroke-linejoin="round"><path d="M20 13c0 5-3.5 7.5-7.66 8.95a1 1 0 0 1-.67-.01C7.5 20.5 4 18 4 13V6a1 1 0 0 1 1-1c2 0 4.5-1.2 6.24-2.72a1.17 1.17 0 0 1 1.52 0C14.51 3.81 17 5 19 5a1 1 0 0 1 1 1z"/><path d="m9 12 2 2 4-4"/></symbol>diff --git a/app/src/assets/scss/protyle/_mindmap-view.scss b/app/src/assets/scss/protyle/_mindmap-view.scssindex 8e51a13b15..90b69047ac 100644--- a/app/src/assets/scss/protyle/_mindmap-view.scss+++ b/app/src/assets/scss/protyle/_mindmap-view.scss@@ -157,7 +157,7 @@flex: 1;min-height: 0;overflow: hidden;- cursor: grab;+ cursor: default;touch-action: none;user-select: none;@@ -213,7 +213,12 @@color: var(--b3-theme-on-background);font-size: 16px;line-height: 1.5;- cursor: grab;+ cursor: default;++ &:focus-visible {+ outline: 1px solid var(--b3-theme-primary);+ outline-offset: 2px;+ }&:hover:not(.mindmap-view__node--dragging):not(.mindmap-view__node--editing):not(.mindmap-view__node--selected) {box-shadow: inset 0 0 0 2px var(--b3-list-hover);@@ -618,6 +623,10 @@opacity: 0;}+ &__viewport--dragging &__node {+ cursor: grabbing;+ }+&__ghost {z-index: 5;opacity: .5;@@ -649,17 +658,10 @@}}- &__summary {- position: absolute;- width: max-content;+ &__node--summary {max-width: 240px;white-space: normal;overflow-wrap: anywhere;-- &--selected {- outline: 2px solid var(--b3-theme-primary);- outline-offset: 2px;- }}&__summary-editor {diff --git a/app/src/protyle/render/listMindmap/model.test.ts b/app/src/protyle/render/listMindmap/model.test.tsindex 04ffcc2865..ec2e61c333 100644--- a/app/src/protyle/render/listMindmap/model.test.ts+++ b/app/src/protyle/render/listMindmap/model.test.ts@@ -2110,19 +2110,27 @@ const browserCases = async (sourceCode: string, css: string, taskSource: string,await settle();check.equal(single.scale, 1, "initial layout keeps a single node at its normal size");const panButton = host.querySelector<HTMLButtonElement>('[aria-label="cursorHand"]');+ const panViewport = host.querySelector<HTMLElement>(".mindmap-view__viewport");+ check.equal(getComputedStyle(panViewport).cursor, "default");+ check.equal(getComputedStyle(host.querySelector(".mindmap-view__node")).cursor, "default");+ check.equal(panButton.querySelector("use").getAttribute("xlink:href"), "#iconPan");panButton.click();check.equal(panButton.getAttribute("aria-pressed"), "true");+ check.equal(getComputedStyle(panViewport).cursor, "grab");const panNode = host.querySelector<HTMLElement>(".mindmap-view__node");check.equal(getComputedStyle(panNode).pointerEvents, "none");const panBefore = {x: single.offsetX, y: single.offsetY};panNode.dispatchEvent(new PointerEvent("pointerdown", {bubbles: true, pointerId: 81, clientX: 100, clientY: 100}));panNode.dispatchEvent(new PointerEvent("pointermove", {bubbles: true, pointerId: 81, clientX: 140, clientY: 125}));+ check.equal(getComputedStyle(panViewport).cursor, "grabbing");panNode.dispatchEvent(new PointerEvent("pointerup", {bubbles: true, pointerId: 81, clientX: 140, clientY: 125}));+ check.equal(getComputedStyle(panViewport).cursor, "grab");check.equal(single.offsetX, panBefore.x + 40, "hand tool pans from a node instead of moving it");check.equal(single.offsetY, panBefore.y + 25);check.equal(host.querySelector(".mindmap-view__ghost"), null);panButton.click();check.equal(panButton.getAttribute("aria-pressed"), "false");+ check.equal(getComputedStyle(panViewport).cursor, "default");check.ok(getComputedStyle(panNode).pointerEvents !== "none");single.fit();check.ok(single.scale > 1 && single.scale <= 2.5, "fit enlarges small maps within the zoom limit");@@ -2929,6 +2937,47 @@ const browserCases = async (sourceCode: string, css: string, taskSource: string,const summaryLabel = summaryHost.querySelector<HTMLElement>(".mindmap-view__summary");check.ok(summaryLabel.textContent.startsWith("<script>"));check.equal(summaryLabel.querySelector("script"), null);+ check.equal(summaryLabel.tagName, "DIV");+ check.ok(summaryLabel.classList.contains("mindmap-view__node--summary"));+ check.ok(summaryLabel.classList.contains("mindmap-view__node--selected"));+ check.equal(summaryLabel.classList.contains("b3-button"), false);+ const ordinaryNode = summaryHost.querySelector<HTMLElement>(".mindmap-view__node[data-mindmap-id]");+ for (const property of ["padding", "border-radius", "font-size", "line-height"]) {+ check.equal(getComputedStyle(summaryLabel).getPropertyValue(property), getComputedStyle(ordinaryNode).getPropertyValue(property));+ }+ const summaryViewport = summaryHost.querySelector<HTMLElement>(".mindmap-view__viewport");+ const summaryPosition = summaryView.summaryPositions.get("summary");+ const summaryBounds = summaryLabel.getBoundingClientRect();+ const bracketCenter = summaryViewport.getBoundingClientRect().top + summaryView.offsetY ++ (summaryPosition.top + summaryPosition.bottom) / 2 * summaryView.scale;+ check.ok(Math.abs((summaryBounds.top + summaryBounds.bottom) / 2 - bracketCenter) < 1);+ const visibleBounds = Array.from(summaryHost.querySelectorAll<HTMLElement>("[data-mindmap-id]"))+ .filter(element => element.dataset.mindmapId !== summaryView.model.root.id).map(element => element.getBoundingClientRect());+ check.ok(Math.abs((Math.min(...visibleBounds.map(rect => rect.top)) + Math.max(...visibleBounds.map(rect => rect.bottom))) / 2 -+ bracketCenter) < 1, "summary brackets center on the displayed member nodes");+ summaryView.clearSelection();+ summaryLabel.focus();+ check.equal(document.activeElement, summaryLabel);+ // 离屏窗口未获得系统焦点时,显式派发聚焦事件以覆盖节点选择行为。+ summaryLabel.dispatchEvent(new FocusEvent("focus"));+ check.equal(summaryView.selectedSummary, "summary", "focusing the summary selects it");+ for (const key of [" ", "Enter"]) {+ summaryView.clearSelection();+ const event = new KeyboardEvent("keydown", {key, bubbles: true, cancelable: true});+ summaryLabel.dispatchEvent(event);+ check.equal(event.defaultPrevented, true);+ check.equal(summaryView.selectedSummary, "summary", `keyboard activation with ${key}`);+ }+ summaryView.clearSelection();+ summaryLabel.dispatchEvent(new PointerEvent("pointerdown", {bubbles: true, pointerType: "touch", pointerId: 91,+ isPrimary: true, button: 0}));+ check.equal(summaryView.pointer, undefined, "selecting a summary does not start canvas or node dragging");+ summaryLabel.click();+ check.equal(summaryView.selectedSummary, "summary", "touching the summary selects it");+ summaryLabel.dispatchEvent(new MouseEvent("dblclick", {bubbles: true}));+ const reopenedSummary = summaryHost.querySelector<HTMLInputElement>(".mindmap-view__summary-editor");+ check.ok(reopenedSummary);+ reopenedSummary.dispatchEvent(new KeyboardEvent("keydown", {key: "Escape", bubbles: true}));const savedSummary = api.readListMindmap(summaryList).metadata.summaries[0];const summaryContext = summaryHost.querySelector("canvas").getContext("2d");const setSummaryTheme = (property: string, value: string) =>diff --git a/app/src/protyle/render/listMindmap/summary.test.ts b/app/src/protyle/render/listMindmap/summary.test.tsindex 70763be9c6..7b289e5244 100644--- a/app/src/protyle/render/listMindmap/summary.test.ts+++ b/app/src/protyle/render/listMindmap/summary.test.ts@@ -57,8 +57,9 @@ test("summary brackets cover visible descendants and disappear with their memberconst sizes = new Map([["s", {width: 150, height: 60}]]);const expanded = layoutListMindmapSummaries(model, positions, sizes).get("s");assert.equal(expanded.x, 476);- assert.equal(expanded.top, 12);- assert.equal(expanded.bottom, 218);+ assert.equal(expanded.top, 9);+ assert.equal(expanded.bottom, 215);+ assert.equal(expanded.labelY + expanded.height / 2, (expanded.top + expanded.bottom) / 2);positions.delete("nested");assert.equal(layoutListMindmapSummaries(model, positions, sizes).get("s").x, 256);positions.delete("a");diff --git a/app/src/protyle/render/listMindmap/summary.ts b/app/src/protyle/render/listMindmap/summary.tsindex 23a6276283..25254e800c 100644--- a/app/src/protyle/render/listMindmap/summary.ts+++ b/app/src/protyle/render/listMindmap/summary.ts@@ -115,8 +115,10 @@ export const layoutListMindmapSummaries = (model: ListMindmapModel, positions: Mcontinue;}right = Math.max(right, position.x + position.width);- top = Math.min(top, position.y);- bottom = Math.max(bottom, position.y + position.height);+ // 节点向上避让下划线,括号和标签按实际显示边界居中。+ const nodeTop = position.y - (id === model.root.id ? 1 : 3);+ top = Math.min(top, nodeTop);+ bottom = Math.max(bottom, nodeTop + position.height);pending.push(...(model.nodes.get(id)?.children.map(node => node.id) || []));}const center = (top + bottom) / 2;diff --git a/app/src/protyle/render/listMindmap/view.ts b/app/src/protyle/render/listMindmap/view.tsindex 335e942de3..8bd60c6b1c 100644--- a/app/src/protyle/render/listMindmap/view.ts+++ b/app/src/protyle/render/listMindmap/view.ts@@ -110,7 +110,7 @@ export class ListMindmapView {private readonly nodeElements = new Map<string, HTMLDivElement>();private readonly previewID = `mindmap-view-${Lute.NewNodeID()}-`;private readonly relationElements = new Map<string, HTMLButtonElement>();- private readonly summaryElements = new Map<string, HTMLButtonElement>();+ private readonly summaryElements = new Map<string, HTMLDivElement>();private summaryPositions = new Map<string, ListMindmapSummaryPosition>();private readonly summaryStatus = createElement("div", "mindmap-view__route-status");private selectedSummary?: string;@@ -454,7 +454,7 @@ export class ListMindmapView {button.before(control);control.append(button, this.levelSelect);}- add("pan", "cursorHand", "iconHand", () => {+ add("pan", "cursorHand", "iconPan", () => {this.finishThen(() => {this.finishRelationEdit?.(true);this.cancelPointer();@@ -922,12 +922,26 @@ export class ListMindmapView {(this.model.metadata.summaries || []).forEach(summary => {let element = this.summaryElements.get(summary.id);if (!element) {- element = createElement("button", "b3-button b3-button--outline mindmap-view__summary");- element.type = "button";+ element = createElement("div", "mindmap-view__node mindmap-view__node--summary mindmap-view__summary");+ element.setAttribute("role", "button");+ element.tabIndex = 0;element.dataset.summaryId = summary.id;element.addEventListener("click", event => {event.stopPropagation();- this.finishThen(() => this.selectSummary(summary.id));+ if (!this.panning && !this.suppressLinkClick) {+ this.finishThen(() => this.selectSummary(summary.id));+ }+ });+ element.addEventListener("focus", () => this.finishThen(() => this.selectSummary(summary.id)));+ element.addEventListener("keydown", event => {+ if (!event.isComposing && !event.ctrlKey && !event.metaKey && !event.altKey && !event.shiftKey &&+ (event.key === "Enter" || event.key === " ")) {+ event.preventDefault();+ event.stopPropagation();+ if (!event.repeat) {+ this.finishThen(() => this.selectSummary(summary.id));+ }+ }});this.summaryElements.set(summary.id, element);this.world.append(element);@@ -1030,10 +1044,13 @@ export class ListMindmapView {return;}const {x, top, bottom, labelX, labelY} = position;+ const radius = Math.min(6, (bottom - top) / 2);const path = new Path2D();path.moveTo(x - 10, top);- path.lineTo(x, top);- path.lineTo(x, bottom);+ path.lineTo(x - radius, top);+ path.quadraticCurveTo(x, top, x, top + radius);+ path.lineTo(x, bottom - radius);+ path.quadraticCurveTo(x, bottom, x - radius, bottom);path.lineTo(x - 10, bottom);path.moveTo(x, (top + bottom) / 2);path.lineTo(labelX - 6, (top + bottom) / 2);@@ -1048,6 +1065,7 @@ export class ListMindmapView {element.style.top = `${labelY}px`;element.style.visibility = this.editingSummary === summary.id ? "hidden" : "";element.classList.toggle("mindmap-view__summary--selected", selected);+ element.classList.toggle("mindmap-view__node--selected", selected);element.setAttribute("aria-pressed", String(selected));});}@@ -1736,6 +1754,9 @@ export class ListMindmapView {if (![0, 2].includes(event.button) || target.closest("button, input, select, textarea, audio, video, iframe, .mindmap-view__node--editing")) {return;}+ if (event.button === 0 && !this.panning && target.closest(".mindmap-view__summary")) {+ return;+ }this.suppressPanContextMenu = event.button === 2;const element = target.closest<HTMLElement>(".mindmap-view__node");const id = element?.dataset.mindmapId;