An open-source, privacy-first, self-hosted knowledge workspace where humans and AI agents work together 开源、隐私优先、自托管的知识工作空间,让人与智能体在此协作
TypeScript agentic-aiai-agentknowledge-baselocal-firstmarkdownmcpmindmapnote-takingself-hostedsiyuanworkspace
:sparkles: Improve list mind map connection previews and zoom controls https://github.com/siyuan-note/siyuan/issues/18831
Vanessad63998260fc5
diff --git a/app/src/assets/scss/protyle/_list-mindmap.scss b/app/src/assets/scss/protyle/_list-mindmap.scssindex 28d46abfa1..43e8becbe5 100644--- a/app/src/assets/scss/protyle/_list-mindmap.scss+++ b/app/src/assets/scss/protyle/_list-mindmap.scss@@ -50,12 +50,7 @@opacity: 0;pointer-events: none;gap: 4px;- overflow-x: auto;- scrollbar-width: none;-- &::-webkit-scrollbar {- display: none;- }+ overflow: visible;}&:hover &__toolbar,@@ -82,6 +77,40 @@user-select: none;}+ &__zoom-control {+ position: relative;+ display: flex;+ align-items: center;+ flex-shrink: 0;+ pointer-events: auto;++ &:hover .list-mindmap__zoom-actions,+ &:focus-within .list-mindmap__zoom-actions {+ display: flex;+ }+ }++ &__zoom-actions {+ @include protyle-toolbar-surface;+ position: absolute;+ top: 100%;+ right: 0;+ display: none;+ align-items: center;+ gap: 8px;+ padding: 8px;+ width: max-content;++ .block__icon {+ gap: 4px;+ white-space: nowrap;+ }++ .b3-slider {+ width: 100px;+ }+ }+&__viewport {position: relative;flex: 1;@@ -434,7 +463,7 @@&__inspector--line {align-items: center;flex-wrap: nowrap;- gap: 8px 16px;+ gap: 0;.list-mindmap__palette {margin: 0;@@ -474,16 +503,6 @@flex-wrap: nowrap;}- &__color {- svg {- visibility: hidden;- }-- &[aria-pressed="true"] svg {- visibility: visible;- }- }-}@media print {diff --git a/app/src/layout/topBar.ts b/app/src/layout/topBar.tsindex 5cfe820c47..67368ae29a 100644--- a/app/src/layout/topBar.ts+++ b/app/src/layout/topBar.ts@@ -303,6 +303,7 @@ ${isInMobileApp() ? `<div id="barExit" data-topbar-entry="barExit" class="ft__er}).element);window.siyuan.menus.menu.append(new MenuItem({label: window.siyuan.languages.reset,+ icon: "iconRefresh",accelerator: "⌘0",click: () => {setZoom("restore");diff --git a/app/src/protyle/render/listMindmap/index.ts b/app/src/protyle/render/listMindmap/index.tsindex b44212d799..ce2e9e4ba7 100644--- a/app/src/protyle/render/listMindmap/index.ts+++ b/app/src/protyle/render/listMindmap/index.ts@@ -155,6 +155,7 @@ class ListMindmapController {});},onManageNodeColors: () => openInlineStyleDialog("style1"),+ onManageLineColors: () => openInlineStyleDialog("backgroundColor"),finishEdit: () => this.activeEditor?.finish(),onExit: async () => {if (this.activeEditor && !await this.activeEditor.finish()) {diff --git a/app/src/protyle/render/listMindmap/routing.test.ts b/app/src/protyle/render/listMindmap/routing.test.tsindex 32be1fa764..445569740a 100644--- a/app/src/protyle/render/listMindmap/routing.test.ts+++ b/app/src/protyle/render/listMindmap/routing.test.ts@@ -19,6 +19,15 @@ const validate = (route: MindmapRoutePoint[], nodes: MindmapRouteBox[]) => {}};+test("connection preview routes to the exact pointer position around obstacles", () => {+ const from = {x: 0, y: 0, width: 100, height: 40};+ const obstacle = {x: 160, y: 0, width: 100, height: 80};+ const pointer = {x: 340, y: 30, width: 0, height: 0};+ const route = routeMindmapRelation(from, pointer, [from, obstacle]);+ validate(route, [from, obstacle]);+ assert.deepEqual(route[route.length - 1], {x: pointer.x, y: pointer.y});+});+test("relations route around intervening nodes in both directions", () => {const nodes = [{x: 300, y: 100, width: 165, height: 76},diff --git a/app/src/protyle/render/listMindmap/routing.ts b/app/src/protyle/render/listMindmap/routing.tsindex f7d48916d0..afe050f60d 100644--- a/app/src/protyle/render/listMindmap/routing.ts+++ b/app/src/protyle/render/listMindmap/routing.ts@@ -17,7 +17,8 @@ export const routeMindmapRelation = (from: MindmapRouteBox, to: MindmapRouteBox,{x: node.x + node.width + clearance, y: node.y + Math.max(0, Math.min(node.height / 2, node.height - 22)), direction: 0},];const starts = ports(from);- const goals = ports(to);+ const goals = to.width === 0 && to.height === 0 ?+ [{x: to.x, y: to.y, direction: 0}, {x: to.x, y: to.y, direction: 1}] : ports(to);const xs = [...new Set([...boxes.flatMap(box => [box.left, box.right]), ...starts.map(p => p.x), ...goals.map(p => p.x)])].sort((a, b) => a - b);const ys = [...new Set([...boxes.flatMap(box => [box.top, box.bottom]), ...starts.map(p => p.y), ...goals.map(p => p.y)])].sort((a, b) => a - b);const point = (index: number) => ({x: xs[index % xs.length], y: ys[Math.floor(index / xs.length)]});diff --git a/app/src/protyle/render/listMindmap/view.ts b/app/src/protyle/render/listMindmap/view.tsindex 75516d99a4..570947573e 100644--- a/app/src/protyle/render/listMindmap/view.ts+++ b/app/src/protyle/render/listMindmap/view.ts@@ -22,6 +22,7 @@ export interface ListMindmapViewOptions {colors?: () => {label: string, value: string}[];nodeColors?: () => {label: string, color: string, backgroundColor: string}[];onManageNodeColors?: () => void;+ onManageLineColors?: () => void;onFullscreen?: (enter: boolean, button: HTMLButtonElement) => void;onEdit?: (id: string, contentHost: HTMLElement) => void;finishEdit?: () => boolean | void | Promise<boolean | void>;@@ -65,6 +66,7 @@ export class ListMindmapView {private readonly toolbar: HTMLDivElement;private readonly inspector: HTMLDivElement;private readonly zoomLabel: HTMLSpanElement;+ private readonly zoomSlider = createElement("input", "b3-slider");private readonly nodeElements = new Map<string, HTMLDivElement>();private readonly relationElements = new Map<string, HTMLButtonElement>();private readonly buttons = new Map<string, HTMLButtonElement>();@@ -83,6 +85,7 @@ export class ListMindmapView {private linePaths: {id: string, relation: boolean, path: Path2D}[] = [];private relationRoutes = new Map<string, MindmapRoutePoint[]>();private relationFrom?: string;+ private relationPreview?: {x: number, y: number, targetId?: string};private editingId?: string;private pointer?: PointerState;private pointerCapture?: HTMLElement;@@ -197,7 +200,9 @@ export class ListMindmapView {button.type = "button";button.setAttribute("aria-label", this.label(key));// 图标引用现有图标集,避免复制或生成路径数据。- button.innerHTML = `<svg aria-hidden="true"><use xlink:href="#${icon}"></use></svg>`;+ if (icon) {+ button.innerHTML = `<svg aria-hidden="true"><use xlink:href="#${icon}"></use></svg>`;+ }button.addEventListener("click", (event) => {event.stopPropagation();this.finishThen(action);@@ -311,13 +316,25 @@ export class ListMindmapView {add("relation", "connect", "iconRoute", () => {this.inspector.hidden = true;this.relationFrom = this.relationFrom ? undefined : this.selectedId;+ this.relationPreview = undefined;this.updateSelection();});}- add("zoomOut", "zoomOut", "iconZoomOut", () => this.zoomAt(this.scale / 1.2));- this.toolbar.append(this.zoomLabel);- add("zoomIn", "zoomIn", "iconZoomIn", () => this.zoomAt(this.scale * 1.2));- add("fit", "listMindmapFit", "iconRefresh", () => this.fit());+ const zoomControl = createElement("div", "list-mindmap__zoom-control");+ const zoomActions = createElement("div", "list-mindmap__zoom-actions");+ this.zoomLabel.tabIndex = 0;+ this.zoomLabel.setAttribute("aria-label", this.label("zoom"));+ this.zoomSlider.type = "range";+ this.zoomSlider.min = "15";+ this.zoomSlider.max = "250";+ this.zoomSlider.step = "1";+ this.zoomSlider.setAttribute("aria-label", this.label("zoom"));+ this.zoomSlider.oninput = () => this.zoomAt(Number(this.zoomSlider.value) / 100);+ const reset = this.makeButton("reset", "iconRefresh", () => this.zoomAt(1));+ zoomActions.append(this.zoomSlider, reset);+ zoomControl.append(this.zoomLabel, zoomActions);+ this.toolbar.append(zoomControl);+ add("fit", "listMindmapFit", "iconFocus", () => this.fit());add("fullscreen", "fullscreen", "iconFullscreen", () => this.toggleFullscreen());}@@ -561,11 +578,13 @@ export class ListMindmapView {}));}- private relationPath(id: string, from: ListMindmapPosition, to: ListMindmapPosition, label: HTMLElement) {- let points = this.relationRoutes.get(id);+ private relationPath(id: string | undefined, from: ListMindmapPosition, to: ListMindmapPosition, label?: HTMLElement) {+ let points = id ? this.relationRoutes.get(id) : undefined;if (!points) {points = routeMindmapRelation(from, to, this.routingObstacles());- this.relationRoutes.set(id, points);+ if (id) {+ this.relationRoutes.set(id, points);+ }}if (points.length < 2) {return;@@ -585,6 +604,9 @@ export class ListMindmapView {const end = points[points.length - 1];const previous = points[points.length - 2];path.lineTo(end.x, end.y);+ if (!label) {+ return {path, end, previous, labelPoint: undefined as MindmapRoutePoint | undefined};+ }const width = label.offsetWidth;const height = label.offsetHeight;const segments = points.slice(1).map((p, i) => ({a: points[i], b: p,@@ -612,6 +634,7 @@ export class ListMindmapView {}this.world.style.transform = `translate(${this.offsetX}px, ${this.offsetY}px) scale(${this.scale})`;this.zoomLabel.textContent = `${Math.round(this.scale * 100)}%`;+ this.zoomSlider.value = String(Math.round(this.scale * 100));const width = this.viewport.clientWidth;const height = this.viewport.clientHeight;const ratio = window.devicePixelRatio || 1;@@ -705,6 +728,37 @@ export class ListMindmapView {element.style.top = `${labelPoint.y}px`;}});+ this.drawRelationPreview(context, primary);+ }++ private drawRelationPreview(context: CanvasRenderingContext2D, color: string) {+ const from = this.positions.get(this.relationFrom);+ if (!from || !this.relationPreview) {+ return;+ }+ const target = this.positions.get(this.relationPreview.targetId);+ const route = this.relationPath(undefined, from, target || {+ id: "", x: this.relationPreview.x, y: this.relationPreview.y, width: 0, height: 0,+ });+ if (!route) {+ return;+ }+ const {path, end, previous} = route;+ context.beginPath();+ context.strokeStyle = color;+ context.lineWidth = 1.5;+ context.setLineDash([5, 4]);+ context.stroke(path);+ context.setLineDash([]);+ context.beginPath();+ const size = Math.max(10 / this.scale, 4.5);+ const direction = Math.atan2(end.y - previous.y, end.x - previous.x);+ context.fillStyle = color;+ context.moveTo(end.x - size * Math.cos(direction - Math.PI / 6), end.y - size * Math.sin(direction - Math.PI / 6));+ context.lineTo(end.x, end.y);+ context.lineTo(end.x - size * Math.cos(direction + Math.PI / 6), end.y - size * Math.sin(direction + Math.PI / 6));+ context.closePath();+ context.fill();}private selectNode(id: string) {@@ -722,9 +776,13 @@ export class ListMindmapView {}private updateSelection() {+ if (!this.relationFrom) {+ this.relationPreview = undefined;+ }this.nodeElements.forEach((element, id) => {element.classList.toggle("list-mindmap__node--selected", this.selectedId === id);- element.classList.toggle("list-mindmap__node--relation", this.relationFrom === id);+ element.classList.toggle("list-mindmap__node--relation", this.relationFrom === id ||+ this.relationPreview?.targetId === id);element.setAttribute("aria-selected", String(this.selectedId === id));});this.relationElements.forEach((element, id) => element.classList.toggle("list-mindmap__relation--selected", this.selectedRelation === id));@@ -821,6 +879,17 @@ export class ListMindmapView {}private pointerMove = (event: PointerEvent) => {+ if (this.relationFrom) {+ const bounds = this.viewport.getBoundingClientRect();+ const id = (event.target as Element).closest<HTMLElement>(".list-mindmap__node")?.dataset.mindmapId;+ this.relationPreview = {+ x: (event.clientX - bounds.left - this.offsetX) / this.scale,+ y: (event.clientY - bounds.top - this.offsetY) / this.scale,+ targetId: id && id !== this.relationFrom && !this.model.nodes.get(id)?.virtual ? id : undefined,+ };+ this.updateSelection();+ return;+ }const pointer = this.pointer;if (!pointer) {const target = event.target as Element;@@ -1112,6 +1181,14 @@ export class ListMindmapView {mode === WheelEvent.DOM_DELTA_PAGE ? this.viewport.clientWidth : 1;const unitY = mode === WheelEvent.DOM_DELTA_LINE ? 16 :mode === WheelEvent.DOM_DELTA_PAGE ? this.viewport.clientHeight : 1;+ // 浏览器将触控板捏合转换为带 Ctrl 的滚轮事件,和鼠标组合滚轮共用光标锚点缩放。+ if (event.ctrlKey) {+ const bounds = this.viewport.getBoundingClientRect();+ const delta = Math.max(-24, Math.min(24, event.deltaY * unitY));+ this.zoomAt(this.scale * Math.exp(-delta * .01),+ event.clientX - bounds.left, event.clientY - bounds.top);+ return;+ }this.offsetX -= event.deltaX * unitX;this.offsetY -= event.deltaY * unitY;this.draw();@@ -1173,21 +1250,29 @@ export class ListMindmapView {this.inspector.classList.toggle("list-mindmap__inspector--line", lineSelected);this.inspector.style.left = "";this.inspector.style.top = "";+ const squareButton = (key: string, icon: string, action: () => void) => {+ const button = this.makeButton(key, icon, action);+ button.className = "color__square";+ button.querySelector("svg").classList.add("svg--mid");+ return button;+ };const color = (value: string, action: (value: string) => void, key = "color") => {const palette = createElement("div", "list-mindmap__palette");palette.setAttribute("role", "group");palette.setAttribute("aria-label", this.label(key));const colors = [{label: this.label("default"), value: ""}, ...(this.options.colors?.() || [])];colors.forEach(item => {- const button = this.makeButton("color", "iconCheck", () => action(item.value));+ const button = this.makeButton("color", "", () => action(item.value));const selected = (value || "") === item.value;- button.className = "color__square list-mindmap__color" + (selected ? " color__square--current" : "");- button.querySelector("svg").classList.add("svg--mid");+ button.className = "color__square" + (selected ? " color__square--current" : "");button.setAttribute("aria-label", item.label);button.setAttribute("aria-pressed", String(selected));button.style.backgroundColor = item.value || "var(--b3-theme-background)";palette.append(button);});+ if (this.options.onManageLineColors) {+ palette.append(squareButton("manageColors", "iconSettings", this.options.onManageLineColors));+ }this.inspector.append(palette);};if (this.selectedRelation) {@@ -1197,7 +1282,7 @@ export class ListMindmapView {}const change = (patch: Partial<ListMindmapRelation>) => this.options.onRelationChange?.(relation.id, patch);color(relation.color, value => change({color: value}));- const remove = this.makeButton("delete", "iconTrashcan", () => this.options.onRelationDelete?.(relation.id));+ const remove = squareButton("delete", "iconTrashcan", () => this.options.onRelationDelete?.(relation.id));this.inspector.append(remove);return;}@@ -1231,15 +1316,13 @@ export class ListMindmapView {nodePalette.append(button);});if (this.options.onManageNodeColors) {- const manage = this.makeButton("manageColors", "iconSettings", this.options.onManageNodeColors);- manage.className = "color__square";- manage.querySelector("svg").classList.add("svg--mid");+ const manage = squareButton("manageColors", "iconSettings", this.options.onManageNodeColors);nodePalette.append(manage);}this.inspector.append(nodePalette);const node = this.model.nodes.get(id);if (node && !node.virtual && node !== this.model.root) {- this.inspector.append(this.makeButton("delete", "iconTrashcan", () => this.deleteSelection()));+ nodePalette.append(squareButton("delete", "iconTrashcan", () => this.deleteSelection()));}}diff --git a/docs/LIST-MINDMAP.md b/docs/LIST-MINDMAP.mdindex ac5489bdce..7e3a24d8b8 100644--- a/docs/LIST-MINDMAP.md+++ b/docs/LIST-MINDMAP.md@@ -14,7 +14,7 @@- 点击画布空白处或脑图外部取消选中,收起节点样式及关系线设置;点击节点继续选择关系线终点,点击其他区域取消连线- 连接按钮使用带箭头的弯曲连线图标,位于缩小按钮前;先选择起点,再选择终点,可编辑文字、颜色或删除关系线;路径通过正交可视网格上的 A* 搜索避开节点和折叠、添加按钮区域,减少转弯并绘制圆角,布局变化时重新计算,平移和缩放时复用路径- 节点默认无背景、不显示边框,正文格式通过节点内的 Protyle 编辑;选中节点后,脑图面板底部显示单排配色工具栏,仅展示节点配色及颜色管理入口,复用外观面板中的文字色与背景色组合,包含内置及自定义颜色并遵循其顺序和可见性,可恢复默认色;点击树连线或关系线,在脑图面板底部显示对应的设置菜单,线条颜色复用外观背景色,菜单不显示标题栏、虚线及宽度控件;双击关系线文字,在原位置显示输入框进行编辑-- 滚轮或触控板滚动用于移动画布,工具栏提供缩放、适应画布和全屏;全屏沿用编辑器的窗口内全屏及窗口控件避让,点击全屏按钮或按 Esc 退出并回到原列表位置+- 滚轮或触控板滚动用于移动画布,Ctrl + 滚轮或触控板双指捏合以鼠标位置为中心缩放;工具栏提供缩放、适应画布和全屏;全屏沿用编辑器的窗口内全屏及窗口控件避让,点击全屏按钮或按 Esc 退出并回到原列表位置- 本次不包含概要和自由摆放节点## 数据与兼容性