Skip to content

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

:recycle: Align the pinned section DOM with document lists https://github.com/siyuan-note/siyuan/issues/19401

Daniel93d4457e67ad
diff --git a/app/src/assets/scss/component/_list.scss b/app/src/assets/scss/component/_list.scss
index 7451fac9f9..3d8f260c1f 100644
--- a/app/src/assets/scss/component/_list.scss
+++ b/app/src/assets/scss/component/_list.scss
@@ -5,16 +5,30 @@
--file-toggle-width: 0px;
padding-bottom: 2px;
margin-bottom: 6px;
+ flex-shrink: 0;
+ max-height: 40%;
+ min-height: 30px;
+ overflow: hidden;
+ border-bottom: 1px solid var(--b3-border-color);
+
+ > .b3-list {
+ min-height: 0;
+ }
+
+ &-list {
+ overflow: auto;
+ min-height: 0;
+ }
[data-pin-heading] > .b3-list-item__icon:hover {
background-color: transparent;
}
- &.b3-list--background .b3-list-item.dragover__top::after {
+ .b3-list--background .b3-list-item.dragover__top::after {
top: 0;
}
- &.b3-list--background .b3-list-item.dragover__bottom::after {
+ .b3-list--background .b3-list-item.dragover__bottom::after {
bottom: 0;
}
}
diff --git a/app/src/editor/deleteFile.ts b/app/src/editor/deleteFile.ts
index df1ca90c88..c11818d086 100644
--- a/app/src/editor/deleteFile.ts
+++ b/app/src/editor/deleteFile.ts
@@ -81,7 +81,7 @@ export const deleteFiles = async (liElements: Element[]) => {
if (liElements.length === 1) {
const itemTopULElement = hasTopClosestByTag(liElements[0], "UL");
if (itemTopULElement) {
- const itemNotebookId = itemTopULElement.getAttribute("data-url");
+ const itemNotebookId = liElements[0].getAttribute("data-notebook") || itemTopULElement.getAttribute("data-url");
if (liElements[0].getAttribute("data-type") === "navigation-file") {
deleteFile(itemNotebookId, liElements[0].getAttribute("data-path"));
} else {
diff --git a/app/src/layout/dock/PinnedDocs.test.ts b/app/src/layout/dock/PinnedDocs.test.ts
index b8c81ef258..0c1fff4934 100644
--- a/app/src/layout/dock/PinnedDocs.test.ts
+++ b/app/src/layout/dock/PinnedDocs.test.ts
@@ -7,6 +7,7 @@ import * as ts from "typescript";
interface IPanelHarness {
element: unknown;
+ heading: unknown;
refresh(): Promise<void>;
collapse(): void;
expanded: Set<string>;
@@ -44,12 +45,16 @@ const loadPanel = (fetchCode = 0) => {
runInNewContext(source, {
exports,
localStorage: {setItem: (key: string, value: string) => storage.set(key, value)},
- window: {siyuan: {config, notebooks: []}},
- document: {activeElement: null, createElement: () => ({
+ window: {siyuan: {config, notebooks: [], languages: {}}},
+ document: {activeElement: null, createElement: (tagName: string) => ({
+ tagName, style: {setProperty: () => {}},
+ setAttribute: () => {}, addEventListener: () => {},
dataset: {}, children: [] as unknown[],
append(child: unknown) { this.children.push(child); },
})},
require: (name: string) => {
+ if (name.endsWith("/fileTreeIcon")) { return {getFileTreeIconHTML: () => ""}; }
+ if (name.endsWith("/escape")) { return {escapeHtml: (value: string) => value}; }
if (name.endsWith("/emoji")) { return {openEmojiPanel: record("icon")}; }
if (name.endsWith("/navigation")) {
return {initFileMenu: (...args: unknown[]) => {
@@ -80,10 +85,9 @@ test("collapse clears descendant expansion and persists the closed section", asy
hasAttribute: () => true,
setAttribute: (name: string, value: string) => states.push([name, value]),
};
- panel.list = {querySelectorAll: () => [row]};
- panel.element = {
- lastElementChild: {classList: {toggle: (name: string, value: boolean) => states.push([name, value])}},
- firstElementChild: {setAttribute: (name: string, value: string) => states.push([name, value])},
+ panel.list = {querySelectorAll: () => [row], classList: {toggle: (name: string, value: boolean) => states.push([name, value])}};
+ panel.heading = {
+ setAttribute: (name: string, value: string) => states.push([name, value]),
querySelector: () => ({classList: {toggle: () => {}}}),
};
panel.collapse();
@@ -113,6 +117,21 @@ test("pinned document more actions open the source document menu", () => {
assert.equal(calls[3].kind, "fullscreen");
});
+test("pinned roots share one list and retain each document notebook without wrapper lists", async () => {
+ const {panel} = loadPanel();
+ panel.expanded = new Set();
+ const children: {tagName: string, dataset: Record<string, string>}[] = [];
+ const parent = {append: (child: typeof children[number]) => children.push(child)};
+ for (const notebook of ["first", "second"]) {
+ await panel.appendDoc(parent, {id: notebook + "-doc", notebook, name: "Document", path: "/doc.sy", subFileCount: 0}, notebook, 0, 0);
+ }
+ assert.deepEqual(children.map(child => child.tagName), ["li", "ul", "li", "ul"]);
+ assert.equal(children[0].dataset.notebook, "first");
+ assert.equal(children[2].dataset.notebook, "second");
+ assert.equal(children[1].dataset.url, "first");
+ assert.equal(children[3].dataset.url, "second");
+});
+
test("pinned icons respect editing, expansion and readonly settings", () => {
const {panel, calls, config} = loadPanel();
const row = {dataset: {nodeId: "document", notebook: "notebook", count: "1"}};
@@ -192,7 +211,7 @@ test("pinned area follows list contents on initial load, pin, unpin and sync", a
panel.generation = 0;
panel.names = new Map();
panel.appendDoc = async () => {};
- panel.list = {parentElement: {scrollTop: 0}, contains: () => false,
+ panel.list = {scrollTop: 0, contains: () => false,
querySelectorAll: (): unknown[] => [], replaceChildren: () => {}};
panel.element = {classList: {toggle: (name: string, hidden: boolean) => {
assert.equal(name, "fn__none");
diff --git a/app/src/layout/dock/PinnedDocs.ts b/app/src/layout/dock/PinnedDocs.ts
index 2d21d7247e..c933f04571 100644
--- a/app/src/layout/dock/PinnedDocs.ts
+++ b/app/src/layout/dock/PinnedDocs.ts
@@ -29,6 +29,7 @@ interface IPinnedDoc {
export class PinnedDocs {
public element: HTMLElement;
private list: HTMLElement;
+ private heading: HTMLElement;
private expanded = new Set<string>();
private generation = 0;
private refreshTimer: number;
@@ -43,10 +44,17 @@ export class PinnedDocs {
constructor(private app: App, private sourceTree: HTMLElement, private open: (id: string, notebook: string) => void,
private mobile = false) {
this.element = document.createElement("div");
- this.element.className = "file-tree__pins b3-list--background fn__flex-column fn__none";
- this.element.style.cssText = "flex-shrink:0;max-height:40%;min-height:30px;overflow:hidden;border-bottom:1px solid var(--b3-border-color)";
- this.element.innerHTML = `<button class="b3-list-item" type="button" data-pin-heading="true"><span class="b3-list-item__toggle"><svg class="b3-list-item__arrow"><use xlink:href="#iconRight"></use></svg></span><span class="b3-list-item__icon"><svg><use xlink:href="#iconPin"></use></svg></span><span class="b3-list-item__text">${window.siyuan.languages.pinnedDocs}</span></button><div class="fn__flex-1" style="overflow:auto;min-height:0"><ul class="b3-list"></ul></div>`;
- this.list = this.element.lastElementChild.firstElementChild as HTMLElement;
+ this.element.className = "file-tree__pins fn__flex-column fn__none";
+ this.element.innerHTML = `<ul class="b3-list b3-list--background fn__flex-column"><li class="b3-list-item" tabindex="0" role="button" data-pin-heading="true"><span class="b3-list-item__toggle"><svg class="b3-list-item__arrow"><use xlink:href="#iconRight"></use></svg></span><span class="b3-list-item__icon"><svg><use xlink:href="#iconPin"></use></svg></span><span class="b3-list-item__text">${window.siyuan.languages.pinnedDocs}</span></li><ul class="file-tree__pins-list fn__flex-1"></ul></ul>`;
+ this.heading = this.element.firstElementChild.firstElementChild as HTMLElement;
+ this.list = this.heading.nextElementSibling as HTMLElement;
+ this.heading.addEventListener("keydown", event => {
+ if (event.key === "Enter" || event.key === " ") {
+ event.preventDefault();
+ event.stopPropagation();
+ this.heading.click();
+ }
+ });
sourceTree.before(this.element);
try {
this.expanded = new Set(JSON.parse(localStorage.getItem("siyuan-pinned-docs-expanded") || "[]"));
@@ -156,9 +164,9 @@ export class PinnedDocs {
}
private setCollapsed(collapsed: boolean) {
- this.element.lastElementChild.classList.toggle("fn__none", collapsed);
- this.element.firstElementChild.setAttribute("aria-expanded", String(!collapsed));
- this.element.querySelector("svg").classList.toggle("b3-list-item__arrow--open", !collapsed);
+ this.list.classList.toggle("fn__none", collapsed);
+ this.heading.setAttribute("aria-expanded", String(!collapsed));
+ this.heading.querySelector("svg").classList.toggle("b3-list-item__arrow--open", !collapsed);
}
public async refresh() {
@@ -170,7 +178,7 @@ export class PinnedDocs {
if (response.code !== 0 || generation !== this.generation || this.disposed) {
return;
}
- const scroll = this.list.parentElement.scrollTop;
+ const scroll = this.list.scrollTop;
const focused = this.list.contains(document.activeElement) ? (document.activeElement as HTMLElement).dataset.pinRow : undefined;
const selected = new Set(Array.from(this.list.querySelectorAll<HTMLElement>(".b3-list-item--focus"), row => row.dataset.pinRow));
pinnedDocIDs.clear();
@@ -182,11 +190,7 @@ export class PinnedDocs {
} else {
this.names.set(doc.id, doc.name);
}
- const wrapper = document.createElement("ul");
- wrapper.dataset.url = doc.notebook;
- wrapper.dataset.sortmode = String(window.siyuan.notebooks.find(notebook => notebook.id === doc.notebook)?.sortMode ?? 15);
- list.append(wrapper);
- await this.appendDoc(wrapper, doc, doc.id, 0, generation);
+ await this.appendDoc(list, doc, doc.id, 0, generation);
}
if (generation === this.generation && !this.disposed) {
this.list.replaceChildren(...Array.from(list.children));
@@ -195,7 +199,7 @@ export class PinnedDocs {
row.classList.toggle("b3-list-item--focus", selected.has(row.dataset.pinRow));
if (row.dataset.pinRow === focused) { row.focus({preventScroll: true}); }
});
- this.list.parentElement.scrollTop = scroll;
+ this.list.scrollTop = scroll;
}
}
@@ -206,6 +210,7 @@ export class PinnedDocs {
row.dataset.pinRoot = String(depth === 0);
row.dataset.nodeId = doc.id;
row.dataset.notebook = doc.notebook;
+ row.dataset.sortmode = String(window.siyuan.notebooks.find(notebook => notebook.id === doc.notebook)?.sortMode ?? 15);
row.dataset.path = doc.path;
row.dataset.name = doc.name;
row.dataset.count = String(doc.subFileCount);
@@ -245,6 +250,8 @@ export class PinnedDocs {
parent.append(row);
const children = document.createElement("ul");
children.className = "fn__none";
+ children.dataset.url = doc.notebook;
+ children.dataset.sortmode = String(window.siyuan.notebooks.find(notebook => notebook.id === doc.notebook)?.sortMode ?? 15);
parent.append(children);
if (this.expanded.has(key) && doc.subFileCount && !doc.unavailable) {
await this.loadChildren(row, children, generation);
@@ -292,7 +299,7 @@ export class PinnedDocs {
if (this.suppressClick) { event.preventDefault(); return; }
const target = event.target as Element;
if (target.closest("[data-pin-heading]")) {
- const collapsed = this.element.firstElementChild.getAttribute("aria-expanded") === "true";
+ const collapsed = this.heading.getAttribute("aria-expanded") === "true";
this.setCollapsed(collapsed);
localStorage.setItem("siyuan-pinned-docs-collapsed", String(collapsed));
return;
@@ -356,7 +363,7 @@ export class PinnedDocs {
if (source && (!row || row.closest("[data-encrypted=true]"))) { return false; }
if (!row) {
this.dropTarget = {id: "", position: "pin-before"};
- this.element.firstElementChild.classList.add("dragover__bottom");
+ this.heading.classList.add("dragover__bottom");
} else {
if (row.dataset.unavailable === "true") { return false; }
const rect = row.getBoundingClientRect();
@@ -365,7 +372,7 @@ export class PinnedDocs {
this.dropTarget = {id: row.dataset.nodeId || row.dataset.url, position};
row.classList.add(position === "inside" ? "dragover" : position.endsWith("before") ? "dragover__top" : "dragover__bottom");
}
- const scrollElement = source ? this.sourceTree : this.list.parentElement;
+ const scrollElement = source ? this.sourceTree : this.list;
dragOverScroll({clientY: y} as MouseEvent, scrollElement.getBoundingClientRect(), scrollElement);
return true;
}
diff --git a/app/src/menus/navigation.ts b/app/src/menus/navigation.ts
index 4d3f19a303..aa5ed36dfb 100644
--- a/app/src/menus/navigation.ts
+++ b/app/src/menus/navigation.ts
@@ -241,7 +241,7 @@ const initMultiMenu = (selectItemElements: NodeListOf<HTMLElement>, app: App) =>
window.siyuan.menus.menu.element.setAttribute("data-from", Constants.MENU_FROM_DOC_TREE_MORE_DOCS);
const fileItemElement = fileItemElements[0];
const blockIDs: string[] = [];
- const notebookId = fileItemElement.parentElement?.getAttribute("data-url") || "";
+ const notebookId = fileItemElement.getAttribute("data-notebook") || fileItemElement.closest("ul[data-url]")?.getAttribute("data-url") || "";
selectItemElements.forEach(item => {
const id = item.getAttribute("data-node-id");
if (id) {
@@ -272,7 +272,7 @@ const initMultiMenu = (selectItemElements: NodeListOf<HTMLElement>, app: App) =>
}
window.siyuan.menus.menu.append(movePathToMenu(getTopPaths(selectedItems), selectedItems.map((item) =>
- item.closest("ul[data-url]")?.getAttribute("data-url") || "")));
+ item.getAttribute("data-notebook") || item.closest("ul[data-url]")?.getAttribute("data-url") || "")));
if (blockIDs.length > 0) {
window.siyuan.menus.menu.append(new MenuItem({
@@ -719,7 +719,7 @@ export const initFileMenu = (app: App, notebookId: string, pathString: string, l
}
/// #endif
if (!window.siyuan.config.readonly) {
- if (isCustomFileTreeList(liElement.parentElement)) {
+ if (isCustomFileTreeList(liElement.getAttribute("data-pin-root") === "true" ? liElement : liElement.parentElement)) {
window.siyuan.menus.menu.append(new MenuItem({
id: "newDocAbove",
icon: "iconBefore",
@@ -772,7 +772,7 @@ export const initFileMenu = (app: App, notebookId: string, pathString: string, l
}).element);
const selectedItems = Array.from(fileElement.querySelectorAll(".b3-list-item--focus"));
window.siyuan.menus.menu.append(movePathToMenu(getTopPaths(selectedItems), selectedItems.map((item) =>
- item.closest("ul[data-url]")?.getAttribute("data-url") || "")));
+ item.getAttribute("data-notebook") || item.closest("ul[data-url]")?.getAttribute("data-url") || "")));
window.siyuan.menus.menu.append(new MenuItem({
id: "addToDatabase",
label: window.siyuan.languages.addToDatabase,
diff --git a/app/src/util/fileTreeSort.ts b/app/src/util/fileTreeSort.ts
index 68791cc3c5..6dd77f362c 100644
--- a/app/src/util/fileTreeSort.ts
+++ b/app/src/util/fileTreeSort.ts
@@ -34,7 +34,7 @@ export const getFileTreeListSortMode = (element: Element) => {
return effectiveSortMode;
}
- const notebookElement = element?.closest("ul[data-url][data-sortmode]");
+ const notebookElement = element?.closest("[data-sortmode]");
const notebookSortMode = parseSortMode(notebookElement?.getAttribute("data-sortmode"));
return notebookSortMode === 15 || typeof notebookSortMode !== "number" ?
window.siyuan.config.fileTree.sort : notebookSortMode;