Skip to content

An open-source, privacy-first, self-hosted knowledge workspace where humans and AI agents work together 开源、隐私优先、自托管的知识工作空间,让人与智能体在此协作

:bug: Preserve folded summaries and custom mind map heights https://github.com/siyuan-note/siyuan/issues/19975

Danielaf0baad6877a
diff --git a/app/src/assets/scss/protyle/_wysiwyg.scss b/app/src/assets/scss/protyle/_wysiwyg.scss
index 92df5779ef..aff725ba69 100644
--- a/app/src/assets/scss/protyle/_wysiwyg.scss
+++ b/app/src/assets/scss/protyle/_wysiwyg.scss
@@ -915,6 +915,7 @@
&[data-type="NodeMindmap"],
&[data-type="NodeList"][custom-sy-list-mindmap="1"] {
height: calc(1.625em + 12px);
+ max-height: calc(1.625em + 12px);
> .mindmap-view {
display: none;
diff --git a/app/src/protyle/render/foldedContent.test.ts b/app/src/protyle/render/foldedContent.test.ts
index c79f07dc8f..af5ee9813f 100644
--- a/app/src/protyle/render/foldedContent.test.ts
+++ b/app/src/protyle/render/foldedContent.test.ts
@@ -42,6 +42,29 @@ const browserCases = async (sources: Record<string, string>, css: string) => {
};
const mathRender = new Function(...Object.keys(dependencies), sources.math + "\nreturn mathRender;")(
...Object.values(dependencies));
+ const summaries = document.createElement("div");
+ summaries.innerHTML = '<div class="li" data-node-id="item" data-type="NodeListItem" fold="1">' +
+ '<div class="protyle-action"></div><div class="p" data-node-id="summary" data-type="NodeParagraph">' +
+ '<div contenteditable="true"><span data-subtype="math" data-content="x"></span></div></div>' +
+ '<div class="p" data-node-id="hidden" data-type="NodeParagraph">' +
+ '<div contenteditable="true"><span data-subtype="math" data-content="y"></span></div></div></div>';
+ root.appendChild(summaries);
+ const summary = summaries.querySelector<HTMLElement>('[data-node-id="summary"]');
+ const hidden = summaries.querySelector<HTMLElement>('[data-node-id="hidden"]');
+ check.notEqual(getComputedStyle(summary).display, "none");
+ check.equal(getComputedStyle(hidden).display, "none");
+ check.equal(api.isFoldedRenderContent(summary.firstElementChild.firstElementChild), false);
+ check.equal(api.isFoldedRenderContent(hidden.firstElementChild.firstElementChild), true);
+ mathRender(summaries);
+ check.equal(requests.length, 1, "visible folded summaries still initialize KaTeX");
+ outer.querySelector(".callout-title").appendChild(summaries);
+ check.equal(api.isFoldedRenderContent(summary.firstElementChild.firstElementChild), false,
+ "folded callout titles remain renderable");
+ outer.querySelector(".callout-content").appendChild(summaries);
+ check.equal(api.isFoldedRenderContent(summary.firstElementChild.firstElementChild), true,
+ "an outer hidden region still defers the inner visible summary");
+ summaries.remove();
+ requests.length = 0;
mathRender(root);
check.equal(requests.length, 0, "folded math must not initialize KaTeX");
for (const language of ["abc", "echarts", "graphviz", "flowchart", "plantuml", "mermaid"]) {
@@ -128,6 +151,7 @@ const browserCases = async (sources: Record<string, string>, css: string) => {
mindmap.dataset.type = "NodeMindmap";
mindmap.dataset.nodeId = "map";
mindmap.dataset.mindmapViewRendered = "true";
+ mindmap.style.height = "500px";
mindmap.innerHTML = '<div class="mindmap-item" data-node-id="item" data-type="NodeMindmapItem">Root title</div>' +
'<div class="mindmap-view" style="--mindmap-view-height:500px"></div>';
root.appendChild(mindmap);
@@ -137,6 +161,7 @@ const browserCases = async (sources: Record<string, string>, css: string) => {
check.equal(getComputedStyle(mindmap.querySelector(".mindmap-view")).display, "none");
check.equal(getComputedStyle(mindmap.firstElementChild).display, "block");
mindmap.removeAttribute("fold");
+ check.equal(mindmap.style.height, "500px", "folding preserves the configured height");
check.equal(mindmap.getBoundingClientRect().height, expanded);
mindmap.remove();
}
diff --git a/app/src/protyle/render/foldedContent.ts b/app/src/protyle/render/foldedContent.ts
index ce31bb57a8..3e9db72da2 100644
--- a/app/src/protyle/render/foldedContent.ts
+++ b/app/src/protyle/render/foldedContent.ts
@@ -10,12 +10,28 @@ export const isFoldedRenderContent = (element: Element, includeSelf = false) =>
if (!root || !foldedRenderRoots.has(root)) {
return false;
}
+ let child = element;
let parent = includeSelf ? element : element.parentElement;
while (parent && parent !== root) {
if (parent.getAttribute("fold") === "1" && parent.hasAttribute("data-node-id") &&
parent.getAttribute("data-type") !== "NodeHeading") {
- return true;
+ if (parent === element) {
+ return true;
+ }
+ const type = parent.getAttribute("data-type");
+ if (type === "NodeCallout" && child.classList.contains("callout-content") ||
+ type === "NodeTabs" && child.classList.contains("tab-item")) {
+ return true;
+ }
+ // 列表项和引述等容器保留首个子块作为摘要,摘要中的公式仍需渲染。
+ if (["NodeListItem", "NodeMindmapItem", "NodeBlockquote", "NodeList", "NodeMindmap"].includes(type)) {
+ const firstBlock = Array.from(parent.children).find(node => node.hasAttribute("data-node-id"));
+ if (child !== firstBlock && (child.hasAttribute("data-node-id") || child.classList.contains("mindmap-view"))) {
+ return true;
+ }
+ }
}
+ child = parent;
parent = parent.parentElement;
}
return false;