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: Unify height menus and support custom mind map height https://github.com/siyuan-note/siyuan/issues/19813
Vanessab4392dd032ef
diff --git a/app/src/assets/scss/protyle/_mindmap-view.scss b/app/src/assets/scss/protyle/_mindmap-view.scssindex f1a4367456..8c7f9e2a4e 100644--- a/app/src/assets/scss/protyle/_mindmap-view.scss+++ b/app/src/assets/scss/protyle/_mindmap-view.scss@@ -27,8 +27,8 @@display: flex;flex-direction: column;width: 100%;- height: 460px;- min-height: 260px;+ height: var(--mindmap-view-height, 460px);+ min-height: min(260px, var(--mindmap-view-height, 260px));box-sizing: border-box;overflow: hidden;border: 1px solid var(--b3-border-color);diff --git a/app/src/config/entryVisibility/catalog.test.ts b/app/src/config/entryVisibility/catalog.test.tsindex 7d51343608..6694c8659f 100644--- a/app/src/config/entryVisibility/catalog.test.ts+++ b/app/src/config/entryVisibility/catalog.test.ts@@ -822,6 +822,8 @@ test("super block actions and vertical alignment use their respective menu group});test("gutter height menus follow width and stay aligned across selection scopes", () => {+ assert.deepEqual(getEntryCatalogNode("gutter.single.chart")?.children?.map(item => item.key), ["update"]);+ assert.equal(getEntryCatalogNode("gutter.single.chart.height"), undefined);const expectedHeightOrder = ["heightInput","height_25%",diff --git a/app/src/config/entryVisibility/catalog.ts b/app/src/config/entryVisibility/catalog.tsindex df9378f405..d9871834c2 100644--- a/app/src/config/entryVisibility/catalog.ts+++ b/app/src/config/entryVisibility/catalog.ts@@ -406,7 +406,7 @@ const gutterSingle = () => [node("saveCodeBlockAsFile", lang("saveCodeBlockAsFile")),]),separator("separator_chart"),- node("chart", lang("chart"), true, [node("height", lang("height")), node("update", lang("update"))]),+ node("chart", lang("chart"), true, [node("update", lang("update"))]),separator("separator_table"),gutterTable(),separator("separator_exportCSV"),diff --git a/app/src/config/entryVisibility/profile.test.ts b/app/src/config/entryVisibility/profile.test.tsindex 3f913d3b98..7b76337567 100644--- a/app/src/config/entryVisibility/profile.test.ts+++ b/app/src/config/entryVisibility/profile.test.ts@@ -11,6 +11,25 @@ import {normalizeEntryVisibilityImportProfile,} from "./profile";+test("chart height migration retains shared visibility and plugin order", () => {+ for (const existing of [undefined, true, false]) {+ const entries: Record<string, boolean> = {"gutter.single.chart.height": false};+ if (existing !== undefined) {+ entries["gutter.single.height"] = existing;+ }+ const profile = normalizeEntryVisibilityImportProfile({name: "Custom", entries, orders: {+ "gutter.single": ["pluginBefore", "width", "height", "pluginAfter"],+ "gutter.single.chart": ["pluginBefore", "height", "update", "pluginAfter"],+ }}, 6, {});+ assert.deepEqual(profile.entries, {"gutter.single.height": existing ?? false});+ assert.deepEqual(profile.orders, {+ "gutter.single": ["pluginBefore", "width", "height", "pluginAfter"],+ "gutter.single.chart": ["pluginBefore", "update", "pluginAfter"],+ });+ assert.deepEqual(normalizeEntryVisibilityImportProfile(profile, 6, {}), profile);+ }+});+test("task state imports match kernel migrations and remain stable on reimport", () => {const fixtures = JSON.parse(readFileSync(resolve(process.cwd(), "../kernel/conf/testdata/task_status_menu.json"), "utf8"));for (const fixture of fixtures) {diff --git a/app/src/config/entryVisibility/profile.ts b/app/src/config/entryVisibility/profile.tsindex eb8c7178e8..65ba9e0b59 100644--- a/app/src/config/entryVisibility/profile.ts+++ b/app/src/config/entryVisibility/profile.ts@@ -21,6 +21,22 @@ export type TEntryVisibilityImportProfile = {export const isEntryVisibilityImportVersionSupported = (version: number, currentVersion: number) =>Number.isInteger(version) && version >= 1 && version <= currentVersion;+// 将图表高度配置合并到公共高度入口,保留已有公共配置及插件顺序。+export const migrateChartHeightMenu = (profile: Pick<Config.IEntryVisibilityProfile, "entries" | "orders">) => {+ const legacy = "gutter.single.chart.height";+ const target = "gutter.single.height";+ if (legacy in profile.entries) {+ if (!(target in profile.entries)) {+ profile.entries[target] = profile.entries[legacy] && profile.entries["gutter.single.chart"] !== false;+ }+ delete profile.entries[legacy];+ }+ const order = profile.orders["gutter.single.chart"];+ if (order?.includes("height")) {+ profile.orders["gutter.single.chart"] = order.filter(key => key !== "height");+ }+};+// 展开任务状态子菜单,合并重复入口的可见性,并在原菜单位置保留子项顺序及插件位置。export const migrateTaskStatusMenu = (profile: Pick<Config.IEntryVisibilityProfile, "entries" | "orders">) => {const parent = "gutter.single.listBlock";@@ -128,5 +144,6 @@ export const normalizeEntryVisibilityImportProfile = (if (version < 6) {migrateTaskStatusMenu({entries, orders});}+ migrateChartHeightMenu({entries, orders});return {name: profile.name, entries, orders};};diff --git a/app/src/menus/protyle.ts b/app/src/menus/protyle.tsindex ed26008be9..a99a321967 100644--- a/app/src/menus/protyle.ts+++ b/app/src/menus/protyle.ts@@ -1478,6 +1478,7 @@ export const imgMenu = (protyle: IProtyle, range: Range, assetElement: HTMLElemelet rangeHeightElement: HTMLInputElement;window.siyuan.menus.menu.append(new MenuItem({id: "height",+ icon: "iconHeight",label: window.siyuan.languages.height,submenu: [{id: "heightInput",@@ -1495,9 +1496,6 @@ export const imgMenu = (protyle: IProtyle, range: Range, assetElement: HTMLElemeimgElement.parentElement.style.width = "";});inputElement.addEventListener("blur", () => {- if (inputElement.value === imgElement.style.height.replace("px", "")) {- return;- }nodeElement.setAttribute("updated", dayjs().format("YYYYMMDDHHmmss"));updateTransaction(protyle, nodeElement, html);window.siyuan.menus.menu.remove();diff --git a/app/src/protyle/gutter/height.test.ts b/app/src/protyle/gutter/height.test.tsnew file mode 100644index 0000000000..a3b58e74f1--- /dev/null+++ b/app/src/protyle/gutter/height.test.ts@@ -0,0 +1,40 @@+import * as assert from "node:assert/strict";+import test from "node:test";++test("height controls preserve each block's storage target and clear legacy iframe height", async () => {+ const globals = ["SIYUAN_VERSION", "NODE_ENV"].map(name => ({name,+ descriptor: Object.getOwnPropertyDescriptor(globalThis, name)}));+ globals.forEach(({name}) => Object.defineProperty(globalThis, name, {configurable: true, value: "test"}));+ try {+ const {getBlockHeightTarget, setBlockHeight} = await import("./height");+ for (const type of ["NodeCodeBlock", "NodeMindmap", "NodeIFrame", "NodeWidget", "NodeVideo"]) {+ const media = {style: {height: "320px", width: "640px"}, removeAttribute: (): void => undefined};+ const block = {dataset: {type}, style: {height: "", maxHeight: ""},+ querySelector: (selector: string) => ["iframe", "video"].includes(selector) ? media : null} as unknown as HTMLElement;+ setBlockHeight(block, "50vh");+ const target = getBlockHeightTarget(block);+ assert.equal(target.element.style[target.property], "50vh", type);+ assert.equal(target.element, type === "NodeVideo" ? media : block);+ assert.equal(target.property, type === "NodeCodeBlock" ? "maxHeight" : "height");+ assert.equal(media.style.width, "640px");+ if (["NodeIFrame", "NodeWidget"].includes(type)) {+ assert.equal(media.style.height, "");+ }+ setBlockHeight(block, "");+ assert.equal(target.element.style[target.property], "");+ }+ for (const type of ["NodeParagraph", "NodeAudio", "NodeTable"]) {+ assert.equal(getBlockHeightTarget({dataset: {type}} as unknown as HTMLElement), undefined);+ }+ assert.equal(getBlockHeightTarget({dataset: {type: "NodeCodeBlock", subtype: "mermaid"}} as unknown as HTMLElement), undefined);+ assert.equal(getBlockHeightTarget({dataset: {type: "NodeCodeBlock", subtype: "echarts"}} as unknown as HTMLElement).property, "height");+ } finally {+ globals.forEach(({name, descriptor}) => {+ if (descriptor) {+ Object.defineProperty(globalThis, name, descriptor);+ } else {+ Reflect.deleteProperty(globalThis, name);+ }+ });+ }+});diff --git a/app/src/protyle/gutter/height.ts b/app/src/protyle/gutter/height.tsnew file mode 100644index 0000000000..1d08432377--- /dev/null+++ b/app/src/protyle/gutter/height.ts@@ -0,0 +1,47 @@+import {Constants} from "../../constants";+import {syncListMindmapHeight} from "../render/listMindmap/height";++export const getBlockHeightTarget = (block: HTMLElement): {element: HTMLElement, property: "height" | "maxHeight"} | undefined => {+ const type = block.dataset.type;+ if (type === "NodeCodeBlock") {+ if (!block.dataset.subtype) {+ return {element: block, property: "maxHeight"};+ }+ return block.dataset.subtype === "echarts" ? {element: block, property: "height"} : undefined;+ }+ if (type === "NodeVideo") {+ const video = block.querySelector("video");+ return video ? {element: video, property: "height"} : undefined;+ }+ if (["NodeMindmap", "NodeIFrame", "NodeWidget"].includes(type) ||+ type === "NodeList" && block.getAttribute(Constants.CUSTOM_SY_LIST_MINDMAP) === "1") {+ return {element: block, property: "height"};+ }+};++export const setBlockHeight = (block: HTMLElement, height: string) => {+ const target = getBlockHeightTarget(block);+ if (!target) {+ return;+ }+ target.element.style[target.property] = height;+ const host = block.querySelector<HTMLElement>(":scope > .mindmap-view");+ if (host) {+ syncListMindmapHeight(block, host);+ }+ if (["NodeIFrame", "NodeWidget"].includes(block.dataset.type)) {+ // 高度统一保存在块上,清除历史数据中 iframe 自身的高度。+ const iframe = block.querySelector("iframe");+ if (iframe) {+ iframe.style.height = "";+ iframe.removeAttribute("height");+ }+ }+ if (block.dataset.subtype === "echarts") {+ const chart = block.querySelector<HTMLElement>("[_echarts_instance_]");+ if (chart) {+ chart.style.height = height || "420px";+ window.echarts?.getInstanceById(chart.getAttribute("_echarts_instance_"))?.resize();+ }+ }+};diff --git a/app/src/protyle/gutter/index.ts b/app/src/protyle/gutter/index.tsindex 95a8d52573..856f8fb6cd 100644--- a/app/src/protyle/gutter/index.ts+++ b/app/src/protyle/gutter/index.ts@@ -44,6 +44,7 @@ import {markGutterForFoldRestore} from "../ui/gutterVisibility";import {highlightRender} from "../render/highlightRender";import {blockRender} from "../render/blockRender";import {toggleListMindmap} from "../render/listMindmap";+import {getBlockHeightTarget, setBlockHeight} from "./height";import {getContenteditableElement,getEmbedGutterOperationContext,@@ -2317,35 +2318,11 @@ export class Gutter {}).element);} else if (type === "NodeCodeBlock" && !protyle.disabled && nodeElement.getAttribute("data-subtype") === "echarts") {window.siyuan.menus.menu.append(new MenuItem({id: "separator_chart", type: "separator"}).element);- const height = (nodeElement as HTMLElement).style.height;- let html = nodeElement.outerHTML;window.siyuan.menus.menu.append(new MenuItem({id: "chart",label: window.siyuan.languages.chart,icon: "iconCode",submenu: [{- id: "height",- iconHTML: "",- type: "readonly",- label: `<div class="fn__flex"><input class="b3-text-field fn__flex-1" value="${height ? parseInt(height) : "420"}" step="1" min="148" style="margin: 4px 8px 4px 0" placeholder="${window.siyuan.languages.height}"><span class="fn__flex-center">px</span></div>`,- bind: (element) => {- element.querySelector("input").addEventListener("change", (event) => {- const newHeight = ((event.target as HTMLInputElement).value || "420") + "px";- (nodeElement as HTMLElement).style.height = newHeight;- updateTransaction(protyle, nodeElement, html);- html = nodeElement.outerHTML;- event.stopPropagation();- const renderElement = nodeElement.querySelector('[contenteditable="false"]') as HTMLElement;- if (renderElement) {- renderElement.style.height = newHeight;- const chartInstance = window.echarts.getInstanceById(renderElement.getAttribute("_echarts_instance_"));- if (chartInstance) {- chartInstance.resize();- }- }- });- }- }, {id: "update",label: window.siyuan.languages.update,icon: "iconEdit",@@ -3324,26 +3301,32 @@ export class Gutter {}private genHeights(nodeElements: Element[], protyle: IProtyle) {- if (nodeElements.length === 0 ||- nodeElements.some(item => item.getAttribute("data-type") !== "NodeCodeBlock" || item.getAttribute("data-subtype"))) {+ if (nodeElements.length === 0 || nodeElements.some(item => !getBlockHeightTarget(item as HTMLElement))) {return;}+ const getHeight = (item: HTMLElement) => {+ const target = getBlockHeightTarget(item);+ return target.element.style[target.property] ||+ (["NodeIFrame", "NodeWidget"].includes(item.dataset.type) ? item.querySelector("iframe")?.style.height || "" : "");+ };+ const setHeight = setBlockHeight;let rangeElement: HTMLInputElement;const firstElement = nodeElements[0] as HTMLElement;+ const firstHeight = getHeight(firstElement);const styles: IMenu[] = [{id: "heightInput",iconHTML: "",type: "readonly",- label: `<div class="fn__flex"><input class="b3-text-field fn__flex-1" value="${firstElement.style.maxHeight.endsWith("px") ? parseInt(firstElement.style.maxHeight) : ""}" type="number" min="1" style="margin: 4px 8px 4px 0" placeholder="${window.siyuan.languages.height}"><span class="fn__flex-center">px</span></div>`,+ label: `<div class="fn__flex"><input class="b3-text-field fn__flex-1" value="${firstHeight.endsWith("px") ? parseInt(firstHeight) : ""}" type="number" min="1" style="margin: 4px 8px 4px 0" placeholder="${window.siyuan.languages.height}"><span class="fn__flex-center">px</span></div>`,bind: (element) => {const inputElement = element.querySelector("input");inputElement.addEventListener("input", () => {- const maxHeight = inputElement.value ? inputElement.value + "px" : "";+ const heightValue = inputElement.value ? inputElement.value + "px" : "";nodeElements.forEach((item: HTMLElement) => {- item.style.maxHeight = maxHeight;+ setHeight(item, heightValue);});rangeElement.value = "0";- rangeElement.parentElement.setAttribute("aria-label", maxHeight || window.siyuan.languages.default);+ rangeElement.parentElement.setAttribute("aria-label", heightValue || window.siyuan.languages.default);});this.updateNodeElements(nodeElements, protyle, inputElement);}@@ -3355,7 +3338,7 @@ export class Gutter {label: item,click: () => {this.genClick(nodeElements, protyle, (e: HTMLElement) => {- e.style.maxHeight = parseInt(item) + "vh";+ setHeight(e, parseInt(item) + "vh");});}});@@ -3364,7 +3347,7 @@ export class Gutter {id: "separator_1",type: "separator"});- const height = firstElement.style.maxHeight.endsWith("vh") ? parseInt(firstElement.style.maxHeight) : 0;+ const height = firstHeight.endsWith("vh") ? parseInt(firstHeight) : 0;window.siyuan.menus.menu.append(new MenuItem({id: "height",icon: "iconHeight",@@ -3373,12 +3356,12 @@ export class Gutter {id: "heightDrag",iconHTML: "",type: "readonly",- label: `<div style="margin: 4px 0;" aria-label="${firstElement.style.maxHeight ? firstElement.style.maxHeight.replace("vh", "%") : window.siyuan.languages.default}" class="b3-tooltips b3-tooltips__n"><input style="box-sizing: border-box" value="${height}" class="b3-slider fn__block" max="100" min="1" step="1" type="range"></div>`,+ label: `<div style="margin: 4px 0;" aria-label="${firstHeight ? firstHeight.replace("vh", "%") : window.siyuan.languages.default}" class="b3-tooltips b3-tooltips__n"><input style="box-sizing: border-box" value="${height}" class="b3-slider fn__block" max="100" min="1" step="1" type="range"></div>`,bind: (element) => {rangeElement = element.querySelector("input");rangeElement.addEventListener("input", () => {nodeElements.forEach((e: HTMLElement) => {- e.style.maxHeight = rangeElement.value + "vh";+ setHeight(e, rangeElement.value + "vh");});rangeElement.parentElement.setAttribute("aria-label", `${rangeElement.value}%`);});@@ -3393,9 +3376,7 @@ export class Gutter {label: window.siyuan.languages.default,click: () => {this.genClick(nodeElements, protyle, (e: HTMLElement) => {- if (e.style.maxHeight) {- e.style.maxHeight = "";- }+ setHeight(e, "");});}}]),diff --git a/app/src/protyle/render/listMindmap/height.ts b/app/src/protyle/render/listMindmap/height.tsnew file mode 100644index 0000000000..478b3eab9e--- /dev/null+++ b/app/src/protyle/render/listMindmap/height.ts@@ -0,0 +1,8 @@+export const syncListMindmapHeight = (list: HTMLElement, host: HTMLElement) => {+ const height = list.style.height;+ if (height) {+ host.style.setProperty("--mindmap-view-height", height);+ } else {+ host.style.removeProperty("--mindmap-view-height");+ }+};diff --git a/app/src/protyle/render/listMindmap/index.ts b/app/src/protyle/render/listMindmap/index.tsindex bc1315383e..4eb867eab6 100644--- a/app/src/protyle/render/listMindmap/index.ts+++ b/app/src/protyle/render/listMindmap/index.ts@@ -32,6 +32,7 @@ import {} from "./model";import type {ListMindmapMetadata, ListMindmapModel} from "./model";import {getListMindmapElements, registerListMindmapRoot, registerListMindmapView} from "./render";+import {syncListMindmapHeight} from "./height";import {ListMindmapView} from "./view";import {openListMindmapEditor} from "./editor";import {focusListMindmap} from "./create";@@ -106,6 +107,7 @@ class ListMindmapController {list.querySelector(":scope > .mindmap-view")?.remove();this.host = document.createElement("div");this.host.className = "mindmap-view";+ syncListMindmapHeight(list, this.host);this.host.contentEditable = "false";this.host.addEventListener("pointermove", event => {if (event.pointerType !== "mouse" || event.buttons || !owner.options.render.gutter ||@@ -509,6 +511,7 @@ class ListMindmapController {public refresh() {this.view.setReadOnly(!canEdit(this.owner, this.list));+ syncListMindmapHeight(this.list, this.host);const snapshot = cleanListMindmapHTML(this.list.outerHTML);if (snapshot === this.snapshot) {return;diff --git a/app/src/protyle/render/listMindmap/render.ts b/app/src/protyle/render/listMindmap/render.tsindex 5258ec76c5..6034174a18 100644--- a/app/src/protyle/render/listMindmap/render.ts+++ b/app/src/protyle/render/listMindmap/render.ts@@ -1,4 +1,5 @@import {Constants} from "../../../constants";+import {syncListMindmapHeight} from "./height";import {readListMindmap} from "./model";import {ListMindmapView} from "./view";import {revealTabsForTarget} from "../tabsRender";@@ -91,6 +92,10 @@ export const listMindmapRender = (root: Element, cdn?: string) => {getListMindmapElements(root).forEach(list => {const previous = previews.get(list);if (previous) {+ const host = list.querySelector<HTMLElement>(":scope > .mindmap-view");+ if (host) {+ syncListMindmapHeight(list, host);+ }previous.refreshLayout();return;}@@ -99,6 +104,7 @@ export const listMindmapRender = (root: Element, cdn?: string) => {list.querySelector(":scope > .mindmap-view")?.remove();const host = document.createElement("div");host.className = "mindmap-view";+ syncListMindmapHeight(list, host);host.contentEditable = "false";list.appendChild(host);const view = new ListMindmapView({diff --git a/kernel/conf/appearance.go b/kernel/conf/appearance.goindex 6c79d4d127..29011ec0e9 100644--- a/kernel/conf/appearance.go+++ b/kernel/conf/appearance.go@@ -168,6 +168,7 @@ func NormalizeEntryVisibility(entryVisibility *EntryVisibility, fallback string)if version < 6 {migrateTaskStatusMenu(profile)}+ migrateChartHeightMenu(profile)profileIDs[profile.ID] = trueprofiles = append(profiles, profile)}diff --git a/kernel/conf/chart_height_menu.go b/kernel/conf/chart_height_menu.gonew file mode 100644index 0000000000..81a99d7c77--- /dev/null+++ b/kernel/conf/chart_height_menu.go@@ -0,0 +1,23 @@+package conf++// 将图表高度配置合并到公共高度入口,保留已有公共配置及插件顺序。+func migrateChartHeightMenu(profile *EntryVisibilityProfile) {+ const legacy = "gutter.single.chart.height"+ const target = "gutter.single.height"+ if visible, ok := profile.Entries[legacy]; ok {+ if _, exists := profile.Entries[target]; !exists {+ parent, configured := profile.Entries["gutter.single.chart"]+ profile.Entries[target] = visible && (!configured || parent)+ }+ delete(profile.Entries, legacy)+ }+ if order, ok := profile.Orders["gutter.single.chart"]; ok {+ filtered := make([]string, 0, len(order))+ for _, key := range order {+ if key != "height" {+ filtered = append(filtered, key)+ }+ }+ profile.Orders["gutter.single.chart"] = filtered+ }+}diff --git a/kernel/conf/chart_height_menu_test.go b/kernel/conf/chart_height_menu_test.gonew file mode 100644index 0000000000..81ed8d9043--- /dev/null+++ b/kernel/conf/chart_height_menu_test.go@@ -0,0 +1,29 @@+package conf++import (+ "reflect"+ "testing"+)++func TestMigrateChartHeightMenu(t *testing.T) {+ for _, existing := range []string{"unset", "visible", "hidden"} {+ profile := &EntryVisibilityProfile{+ Entries: map[string]bool{"gutter.single.chart.height": false},+ Orders: map[string][]string{+ "gutter.single": {"pluginBefore", "width", "height", "pluginAfter"},+ "gutter.single.chart": {"pluginBefore", "height", "update", "pluginAfter"},+ },+ }+ if existing != "unset" {+ profile.Entries["gutter.single.height"] = existing == "visible"+ }+ for i := 0; i < 2; i++ {+ migrateChartHeightMenu(profile)+ if !reflect.DeepEqual(profile.Entries, map[string]bool{"gutter.single.height": existing == "visible"}) ||+ !reflect.DeepEqual(profile.Orders["gutter.single.chart"], []string{"pluginBefore", "update", "pluginAfter"}) ||+ !reflect.DeepEqual(profile.Orders["gutter.single"], []string{"pluginBefore", "width", "height", "pluginAfter"}) {+ t.Fatalf("unexpected migration for %s: %+v", existing, profile)+ }+ }+ }+}