An open-source, privacy-first, self-hosted knowledge workspace where humans and AI agents work together 开源、隐私优先、自托管的知识工作空间,让人与智能体在此协作
TypeScript agentic-aiai-agentknowledge-baselocal-firstmarkdownmcpmindmapnote-takingself-hostedsiyuanworkspace
feat(doctree): Add collapse animation to document tree. (#18288)
Aoidayo60e9582fe918
diff --git a/app/src/assets/scss/main/_main.scss b/app/src/assets/scss/main/_main.scssindex 93bba332dc..b149e6cb1b 100644--- a/app/src/assets/scss/main/_main.scss+++ b/app/src/assets/scss/main/_main.scss@@ -282,7 +282,8 @@ html[data-frontend="browser-desktop"] {transition: var(--b3-transition);}- &__sliderDown {+ &__sliderDown,+ &__sliderUp {height: 0;overflow: hidden;transition: var(--b3-transition);diff --git a/app/src/assets/scss/main/_mobile.scss b/app/src/assets/scss/main/_mobile.scssindex a60a742655..baf4f54699 100644--- a/app/src/assets/scss/main/_mobile.scss+++ b/app/src/assets/scss/main/_mobile.scss@@ -73,7 +73,8 @@}}-.file-tree__sliderDown {+.file-tree__sliderDown,+.file-tree__sliderUp {height: 0;overflow: hidden;transition: var(--b3-transition);diff --git a/app/src/layout/dock/Files.ts b/app/src/layout/dock/Files.tsindex 6601efa8e2..0ab57829e4 100644--- a/app/src/layout/dock/Files.ts+++ b/app/src/layout/dock/Files.ts@@ -246,7 +246,12 @@ export class Files extends Model {}break;} else if (isNotCtrl(event) && target.classList.contains("b3-list-item__toggle")) {- this.getLeaf(target.parentElement, notebookId);+ const liElement = target.parentElement;+ if (liElement.querySelector(".b3-list-item__arrow--open")) {+ this.collapseLeaf(liElement);+ } else if ((liElement.nextElementSibling as HTMLElement)?.dataset.collapsing !== "true") {+ this.getLeaf(liElement, notebookId);+ }event.preventDefault();event.stopPropagation();window.siyuan.menus.menu.remove();@@ -1338,14 +1343,12 @@ data-type="navigation-root" data-path="/" data-count="${item.subFileCount || 0}"setTimeout(() => {nextElement.setAttribute("style", `top: -1px;position: relative;height:${nextElement.childElementCount * (liElement.clientHeight + 1) - 1}px;`);setTimeout(() => {- this.element.querySelectorAll(".file-tree__sliderDown").forEach(item => {- item.classList.remove("file-tree__sliderDown");- item.removeAttribute("style");- });+ nextElement.classList.remove("file-tree__sliderDown");+ nextElement.removeAttribute("style");if (typeof scrollTop === "number") {this.element.scroll({top: scrollTop, behavior: "smooth"});}- }, 120);+ }, 200);}, 2);this.refreshPublishAccessSwitch();}@@ -1413,12 +1416,49 @@ data-type="navigation-root" data-path="/" data-count="${item.subFileCount || 0}"}}+ private collapseLeaf(liElement: Element) {+ const toggleElement = liElement.querySelector(".b3-list-item__arrow");+ const leafElement = liElement.nextElementSibling as HTMLElement;+ toggleElement.classList.remove("b3-list-item__arrow--open");+ if (leafElement?.tagName !== "UL") {+ this.getOpenPaths();+ return;+ }++ // 仅当手动点击折叠按钮时才需要动画,其他情况下默认直接移除列表容器。+ leafElement.dataset.collapsing = "true";+ leafElement.style.height = `${leafElement.scrollHeight}px`;+ leafElement.style.overflow = "hidden";+ leafElement.classList.add("file-tree__sliderUp");+ window.setTimeout(() => {+ leafElement.style.height = "0";+ window.setTimeout(() => {+ if (!leafElement.isConnected) {+ return;+ }+ leafElement.remove();+ this.getOpenPaths();+ }, 200);+ }, 2);+ }+public getLeaf(liElement: Element, notebookId: string, focusUpdate = false) {const toggleElement = liElement.querySelector(".b3-list-item__arrow");+ const leafElement = liElement.nextElementSibling as HTMLElement;+ if (leafElement?.dataset.collapsing === "true") {+ leafElement.remove();+ this.getOpenPaths();+ return;+ }if (toggleElement.classList.contains("b3-list-item__arrow--open") && !focusUpdate) {toggleElement.classList.remove("b3-list-item__arrow--open");- liElement.nextElementSibling?.remove();- this.getOpenPaths();+ if (leafElement?.tagName === "UL") {+ leafElement.remove();+ this.getOpenPaths();+ } else {+ // 没有UL,直接更新路径+ this.getOpenPaths();+ }return;}fetchPost("/api/filetree/listDocsByPath", {diff --git a/app/src/mobile/dock/MobileFiles.ts b/app/src/mobile/dock/MobileFiles.tsindex a2a692af74..f9e723d77e 100644--- a/app/src/mobile/dock/MobileFiles.ts+++ b/app/src/mobile/dock/MobileFiles.ts@@ -150,7 +150,12 @@ export class MobileFiles extends Model {const ulElement = hasTopClosestByTag(target, "UL");if (ulElement) {const notebookId = ulElement.getAttribute("data-url");- this.getLeaf(target.parentElement, notebookId);+ const liElement = target.parentElement;+ if (liElement.querySelector(".b3-list-item__arrow--open")) {+ this.collapseLeaf(liElement);+ } else if ((liElement.nextElementSibling as HTMLElement)?.dataset.collapsing !== "true") {+ this.getLeaf(liElement, notebookId);+ }this.setCurrent(target.parentElement);window.siyuan.menus.menu.remove();}@@ -965,14 +970,12 @@ export class MobileFiles extends Model {setTimeout(() => {nextElement.setAttribute("style", `height:${nextElement.childElementCount * liElement.clientHeight}px;`);setTimeout(() => {- this.element.querySelectorAll(".file-tree__sliderDown").forEach(item => {- item.classList.remove("file-tree__sliderDown");- item.removeAttribute("style");- });+ nextElement.classList.remove("file-tree__sliderDown");+ nextElement.removeAttribute("style");if (typeof scrollTop === "number") {this.element.scroll({top: scrollTop, behavior: "smooth"});}- }, 120);+ }, 200);}, 2);this.refreshPublishAccessSwitch();}@@ -1037,11 +1040,43 @@ export class MobileFiles extends Model {}}+ private collapseLeaf(liElement: Element) {+ const toggleElement = liElement.querySelector(".b3-list-item__arrow");+ const leafElement = liElement.nextElementSibling as HTMLElement;+ toggleElement.classList.remove("b3-list-item__arrow--open");+ if (leafElement?.tagName !== "UL") {+ this.getOpenPaths();+ return;+ }++ // 仅当手动点击折叠按钮时才需要动画,其他情况下默认直接移除列表容器。+ leafElement.dataset.collapsing = "true";+ leafElement.style.height = `${leafElement.scrollHeight}px`;+ leafElement.style.overflow = "hidden";+ leafElement.classList.add("file-tree__sliderUp");+ window.setTimeout(() => {+ leafElement.style.height = "0";+ window.setTimeout(() => {+ if (!leafElement.isConnected) {+ return;+ }+ leafElement.remove();+ this.getOpenPaths();+ }, 200);+ }, 2);+ }+public getLeaf(liElement: Element, notebookId: string, focusUpdate = false) {const toggleElement = liElement.querySelector(".b3-list-item__arrow");+ const leafElement = liElement.nextElementSibling as HTMLElement;+ if (leafElement?.dataset.collapsing === "true") {+ leafElement.remove();+ this.getOpenPaths();+ return;+ }if (toggleElement.classList.contains("b3-list-item__arrow--open") && !focusUpdate) {toggleElement.classList.remove("b3-list-item__arrow--open");- liElement.nextElementSibling?.remove();+ leafElement?.remove();this.getOpenPaths();return;}