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: Improve mind map palette scrolling and control alignment https://github.com/siyuan-note/siyuan/issues/20856
Daniel7c3416a9206b
diff --git a/app/src/assets/scss/business/_color.scss b/app/src/assets/scss/business/_color.scssindex 222bba7059..37f432a79e 100644--- a/app/src/assets/scss/business/_color.scss+++ b/app/src/assets/scss/business/_color.scss@@ -22,10 +22,6 @@margin: 0 8px 0 0;}- &--compact {- margin: 0;- }-&:hover:not(.color__square--list):not(.color__square--current) {box-shadow: 0 0 0 1px var(--b3-border-color) inset, 0 0 0 3px var(--b3-list-hover);}@@ -33,4 +29,17 @@&--current {box-shadow: 0 0 0 2px var(--b3-menu-background) inset, 0 0 0 3px var(--b3-list-hover);}++ &--compact {+ margin: 0;++ // 紧凑排列时将反馈限制在按钮内部,避免被滚动边界或相邻色卡遮挡。+ &:hover:not(.color__square--list):not(.color__square--current) {+ box-shadow: 0 0 0 1px var(--b3-border-color) inset, 0 0 0 3px var(--b3-list-hover) inset;+ }++ &.color__square--current {+ box-shadow: 0 0 0 1px var(--b3-menu-background) inset, 0 0 0 3px var(--b3-list-hover) inset;+ }+ }}diff --git a/app/src/assets/scss/protyle/_mindmap-view.scss b/app/src/assets/scss/protyle/_mindmap-view.scssindex 7f8acd7ff2..98041cc62e 100644--- a/app/src/assets/scss/protyle/_mindmap-view.scss+++ b/app/src/assets/scss/protyle/_mindmap-view.scss@@ -1052,7 +1052,9 @@.b3-text-field {grid-column: span 2;- width: 100%;+ // 两侧控件按相同外边界排列,滑块左右留白随列宽保持一致。+ width: calc(50% + 26px);+ max-width: 100%;min-width: 0;}@@ -1060,6 +1062,8 @@grid-column: span 4;width: 100%;min-width: 0;+ margin: 0;+ box-sizing: border-box;}.color__square {diff --git a/app/src/protyle/render/listMindmap/inspector.test.ts b/app/src/protyle/render/listMindmap/inspector.test.tsindex 76d14544b6..319cbc2c50 100644--- a/app/src/protyle/render/listMindmap/inspector.test.ts+++ b/app/src/protyle/render/listMindmap/inspector.test.ts@@ -136,7 +136,7 @@ const browserCases = async (source: string, css: string) => {visible(inspector);view.selectedEdge = undefined;view.model.metadata.summaries = [{id: "summary", label: "Summary", parentId: model.root.id,- fromId: model.root.children[0].id, toId: model.root.children[1].id}];+ nodeIds: model.root.children.map((node: {id: string}) => node.id)}];view.selectSummary("summary");stage = "summary";await settle();diff --git a/app/src/protyle/render/listMindmap/model.test.ts b/app/src/protyle/render/listMindmap/model.test.tsindex 5981d6bfa0..ffe7df21c4 100644--- a/app/src/protyle/render/listMindmap/model.test.ts+++ b/app/src/protyle/render/listMindmap/model.test.ts@@ -2230,6 +2230,9 @@ const browserCases = async (sourceCode: string, css: string, taskSource: string,}const originalLineColors = options.colors;options.colors = () => Array.from({length: 15}, (_, i) => ({label: `Line ${i}`, value: `rgb(${i}, 0, 0)`}));+ host.style.setProperty("--b3-list-hover", "rgba(100, 100, 100, .4)");+ host.style.setProperty("--b3-menu-background", "#fff");+ host.style.setProperty("--b3-border-color", "#888");view.selectNode(alpha, true);for (const width of [240, 320, 760]) {host.style.width = `${width}px`;@@ -2266,6 +2269,15 @@ const browserCases = async (sourceCode: string, css: string, taskSource: string,check.ok(buttons[7].getBoundingClientRect().left >= palette.getBoundingClientRect().right - 1,"the next color stays outside the first page");}+ const selectedColor = palettes[0].querySelector<HTMLElement>(".color__square--current");+ check.equal(getComputedStyle(selectedColor).boxShadow.match(/inset/g)?.length, 2,+ "selected colors keep both feedback rings inside the clipped palette");+ await moveMouse();+ await moveMouse(palettes[0].children[6]);+ check.equal(getComputedStyle(palettes[0].children[6]).boxShadow.match(/inset/g)?.length, 2,+ "hover feedback also stays inside the last visible color: " + JSON.stringify({width,+ hover: palettes[0].children[6].matches(":hover"), bounds: palettes[0].children[6].getBoundingClientRect().toJSON(),+ shadow: getComputedStyle(palettes[0].children[6]).boxShadow}));const beforeSettings = nodeStyles.length;managers[0].focus();check.equal(host.querySelector('[role="tooltip"]').textContent, "listMindmapManageNodeColors");@@ -2322,6 +2334,44 @@ const browserCases = async (sourceCode: string, css: string, taskSource: string,check.ok(touchPalette.scrollLeft > 0, "a native horizontal swipe reaches colors beyond the first six groups");check.equal(touchManager.getBoundingClientRect().left, managerPosition, "swiping the palette keeps color settings fixed");check.equal(nodeStyles.length, beforeColorSwipe, "swiping colors does not apply a color or alter document styles");+ for (const scale of [1, .75]) {+ host.style.transformOrigin = "top left";+ host.style.transform = `scale(${scale})`;+ await settle();+ touchPalette.scrollLeft = 0;+ const bounds = touchPalette.getBoundingClientRect();+ const start = {x: Math.round(bounds.right - 12), y: Math.round(bounds.top + bounds.height / 2)};+ const canvasPosition = {x: view.offsetX, y: view.offsetY, scale: view.scale};+ const settingsPosition = touchManager.getBoundingClientRect().left;+ await nativeInput([+ {type: "mouseMove", ...start},+ {type: "mouseWheel", ...start, deltaX: 0, deltaY: -60},+ ]);+ await settle();+ check.ok(touchPalette.scrollLeft > 0, "a native vertical mouse wheel browses the horizontal palette");+ touchPalette.scrollLeft = 0;+ await nativeInput([+ {type: "mouseMove", ...start},+ {type: "mouseDown", ...start, button: "left", clickCount: 1},+ ...[20, 40, 60, 80].map(delta => ({type: "mouseMove", x: start.x - delta, y: start.y, button: "left"})),+ {type: "mouseUp", x: start.x - 80, y: start.y, button: "left", clickCount: 1},+ ]);+ await settle();+ check.ok(Math.abs(touchPalette.scrollLeft - 80 / scale) < 2, "mouse dragging accounts for an outer editor scale");+ check.equal(nodeStyles.length, beforeColorSwipe, "drag release never applies the color underneath the pointer");+ check.deepEqual(view.getSelectedIds(), paletteSelection);+ check.deepEqual({x: view.offsetX, y: view.offsetY, scale: view.scale}, canvasPosition);+ check.equal(touchManager.getBoundingClientRect().left, settingsPosition);+ }+ const visibleColor = touchPalette.children[Math.ceil(touchPalette.scrollLeft /+ (touchPalette.scrollWidth / touchPalette.children.length)) + 1] as HTMLButtonElement;+ await clickMouse(visibleColor);+ check.equal(nodeStyles.length, beforeColorSwipe + 1, "a regular click after dragging still applies a color");+ visibleColor.focus({preventScroll: true});+ await nativeInput([{type: "keyDown", keyCode: "Return"}, {type: "char", keyCode: "\r"},+ {type: "keyUp", keyCode: "Return"}]);+ await settle();+ check.equal(nodeStyles.length, beforeColorSwipe + 2, "keyboard activation remains available after palette dragging");options.colors = originalLineColors;view.focusNode(beta);host.style.cssText = originalHostStyle;@@ -2342,12 +2392,37 @@ const browserCases = async (sourceCode: string, css: string, taskSource: string,check.deepEqual(Array.from(widthControls.children).map(control => control.tagName === "INPUT" ?control.getAttribute("type") : control.getAttribute("aria-label")),["number", "range", "listMindmapRestoreWidth", "default"], "the width input precedes the centered slider and reset controls");- check.ok(Math.abs(widthInput().getBoundingClientRect().width - inspector.getBoundingClientRect().width / 4 + 2) < 2,- "the numeric input occupies two of the eight columns");+ for (const canvasWidth of [240, 320, 760]) {+ host.style.width = `${canvasWidth}px`;+ await settle();+ const row = widthControls.getBoundingClientRect();+ const numeric = widthInput().getBoundingClientRect();+ const range = widthControls.querySelector(".b3-slider").getBoundingClientRect();+ const restore = widthControls.querySelector('[aria-label="listMindmapRestoreWidth"]').getBoundingClientRect();+ const automatic = widthControls.querySelector('[aria-label="default"]').getBoundingClientRect();+ check.ok(Math.abs((range.left + range.right) / 2 - (row.left + row.right) / 2) < 1,+ "the width slider stays centered within the panel");+ check.ok(Math.abs(range.left - numeric.right - (restore.left - range.right)) < 1,+ "the slider has equal space beside the number field and reset controls");+ check.ok(Math.abs(numeric.width - (automatic.right - restore.left)) < 1,+ "the numeric field matches the combined width of the two right-hand controls");+ check.equal(getComputedStyle(widthInput()).paddingRight, "4px", "the compact number field retains a reachable native stepper");+ }+ host.style.cssText = originalHostStyle;widthInput().value = "640";widthInput().dispatchEvent(new Event("change", {bubbles: true}));await settle();check.deepEqual(nodeStyles.at(-1), [beta, {width: 640}]);+ const stepper = widthInput().getBoundingClientRect();+ const stepperPoint = {x: Math.round(stepper.right - 8), y: Math.round(stepper.top + 5)};+ await nativeInput([+ {type: "mouseMove", ...stepperPoint},+ {type: "mouseDown", ...stepperPoint, button: "left", clickCount: 1},+ {type: "mouseUp", ...stepperPoint, button: "left", clickCount: 1},+ ]);+ host.focus();+ await settle();+ check.deepEqual(nodeStyles.at(-1), [beta, {width: 641}], "the native number stepper stays reachable at the field's right edge");const styleCount = nodeStyles.length;widthInput().value = "12";widthInput().dispatchEvent(new Event("change", {bubbles: true}));diff --git a/app/src/protyle/render/listMindmap/view.ts b/app/src/protyle/render/listMindmap/view.tsindex fb2339bc20..cdff244f29 100644--- a/app/src/protyle/render/listMindmap/view.ts+++ b/app/src/protyle/render/listMindmap/view.ts@@ -3879,6 +3879,66 @@ export class ListMindmapView {}private makePaletteRow(palette: HTMLElement, controls: HTMLElement[], columns = 8) {+ // 触屏沿用原生横向滚动,鼠标支持拖动和滚轮浏览;拖动完成后不触发色卡点击。+ let drag: {id: number, x: number, scroll: number, scale: number};+ let moved = false;+ palette.addEventListener("pointerdown", (event: PointerEvent) => {+ moved = false;+ if (event.pointerType !== "mouse" || event.button !== 0 ||+ palette.scrollWidth <= palette.clientWidth) {+ return;+ }+ drag = {id: event.pointerId, x: event.clientX, scroll: palette.scrollLeft,+ scale: palette.getBoundingClientRect().width / palette.offsetWidth || 1};+ });+ palette.addEventListener("pointermove", (event: PointerEvent) => {+ if (!drag || event.pointerId !== drag.id) {+ return;+ }+ const delta = (event.clientX - drag.x) / drag.scale;+ if (!moved && Math.abs(delta) < 4) {+ return;+ }+ if (!moved) {+ moved = true;+ palette.setPointerCapture(event.pointerId);+ this.tooltip.hidden = true;+ }+ palette.scrollLeft = drag.scroll - delta;+ event.preventDefault();+ });+ const end = (event: PointerEvent) => {+ if (drag?.id === event.pointerId) {+ drag = undefined;+ }+ };+ palette.addEventListener("pointerup", end);+ palette.addEventListener("pointercancel", end);+ palette.addEventListener("lostpointercapture", end);+ palette.addEventListener("pointerleave", () => {+ if (!moved) {+ drag = undefined;+ }+ });+ palette.addEventListener("click", event => {+ if (moved && event.detail !== 0) {+ event.preventDefault();+ event.stopImmediatePropagation();+ }+ moved = false;+ }, {capture: true});+ palette.addEventListener("wheel", (event: WheelEvent) => {+ if (event.ctrlKey || event.metaKey || palette.scrollWidth <= palette.clientWidth) {+ return;+ }+ const delta = Math.abs(event.deltaX) > Math.abs(event.deltaY) ? event.deltaX : event.deltaY;+ if (delta) {+ const unit = event.deltaMode === WheelEvent.DOM_DELTA_LINE ? 16 :+ event.deltaMode === WheelEvent.DOM_DELTA_PAGE ? palette.clientWidth : 1;+ palette.scrollLeft += delta * unit;+ event.preventDefault();+ }+ }, {passive: false});const row = createElement("div", "mindmap-view__palette-row");row.style.setProperty("--mindmap-palette-columns", String(columns - controls.length));row.style.setProperty("--mindmap-toolbar-columns", String(columns));@@ -3965,7 +4025,7 @@ export class ListMindmapView {slider.value = String(panel.slider);slider.setAttribute("aria-label", this.label("width"));slider.dataset.widthControl = "slider";- const width = createElement("input", "b3-text-field b3-text-field--size");+ const width = createElement("input", "b3-text-field b3-text-field--small");width.type = "number";width.min = "32";width.step = "1";