mirror of
https://github.com/siyuan-note/siyuan.git
synced 2025-12-17 07:00:12 +01:00
This commit is contained in:
parent
ba69c44f08
commit
a5f23edee2
1 changed files with 40 additions and 19 deletions
|
|
@ -199,16 +199,38 @@ export class Outline extends Model {
|
||||||
},
|
},
|
||||||
rightClick: (element: HTMLElement, event: MouseEvent) => {
|
rightClick: (element: HTMLElement, event: MouseEvent) => {
|
||||||
this.showContextMenu(element, event);
|
this.showContextMenu(element, event);
|
||||||
|
},
|
||||||
|
toggleClick:(liElement) => {
|
||||||
|
if (!liElement.nextElementSibling) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
const svgElement = liElement.firstElementChild.firstElementChild;
|
||||||
|
if (svgElement.classList.contains("b3-list-item__arrow--open")) {
|
||||||
|
svgElement.classList.remove("b3-list-item__arrow--open");
|
||||||
|
liElement.nextElementSibling.classList.add("fn__none");
|
||||||
|
if (liElement.nextElementSibling.nextElementSibling && liElement.nextElementSibling.nextElementSibling.tagName === "UL") {
|
||||||
|
liElement.nextElementSibling.nextElementSibling.classList.add("fn__none");
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
svgElement.classList.add("b3-list-item__arrow--open");
|
||||||
|
liElement.nextElementSibling.classList.remove("fn__none");
|
||||||
|
if (liElement.nextElementSibling.nextElementSibling && liElement.nextElementSibling.nextElementSibling.tagName === "UL") {
|
||||||
|
liElement.nextElementSibling.nextElementSibling.classList.remove("fn__none");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
this.saveExpendIds();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
// 为了快捷键的 dispatch
|
// 为了快捷键的 dispatch
|
||||||
options.tab.panelElement.querySelector('[data-type="collapse"]').addEventListener("click", () => {
|
options.tab.panelElement.querySelector('[data-type="collapse"]').addEventListener("click", () => {
|
||||||
this.tree.collapseAll();
|
this.tree.collapseAll();
|
||||||
|
this.saveExpendIds();
|
||||||
});
|
});
|
||||||
|
|
||||||
// 普通的全部展开按钮
|
// 普通的全部展开按钮
|
||||||
options.tab.panelElement.querySelector('[data-type="expand"]').addEventListener("click", () => {
|
options.tab.panelElement.querySelector('[data-type="expand"]').addEventListener("click", () => {
|
||||||
this.tree.expandAll();
|
this.tree.expandAll();
|
||||||
|
this.saveExpendIds();
|
||||||
});
|
});
|
||||||
|
|
||||||
// 保持当前标题展开功能
|
// 保持当前标题展开功能
|
||||||
|
|
@ -591,6 +613,7 @@ export class Outline extends Model {
|
||||||
ulElement.previousElementSibling.querySelector(".b3-list-item__arrow").classList.add("b3-list-item__arrow--open");
|
ulElement.previousElementSibling.querySelector(".b3-list-item__arrow").classList.add("b3-list-item__arrow--open");
|
||||||
ulElement = ulElement.parentElement;
|
ulElement = ulElement.parentElement;
|
||||||
}
|
}
|
||||||
|
this.saveExpendIds();
|
||||||
} else {
|
} else {
|
||||||
while (currentElement && currentElement.clientHeight === 0) {
|
while (currentElement && currentElement.clientHeight === 0) {
|
||||||
currentElement = currentElement.parentElement.previousElementSibling as HTMLElement;
|
currentElement = currentElement.parentElement.previousElementSibling as HTMLElement;
|
||||||
|
|
@ -609,25 +632,22 @@ export class Outline extends Model {
|
||||||
if (currentElement) {
|
if (currentElement) {
|
||||||
currentId = currentElement.getAttribute("data-node-id");
|
currentId = currentElement.getAttribute("data-node-id");
|
||||||
}
|
}
|
||||||
|
const scrollTop = this.element.scrollTop;
|
||||||
|
|
||||||
// 保存当前文档的折叠状态到新的持久化存储
|
// 保存当前文档的折叠状态到新的持久化存储
|
||||||
if (!this.isPreview) {
|
this.saveExpendIds();
|
||||||
const currentExpandIds = this.tree.getExpandIds();
|
|
||||||
fetchPost("/api/storage/setOutlineStorage", {
|
|
||||||
docID: this.blockId,
|
|
||||||
val: {
|
|
||||||
expandIds: currentExpandIds
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
if (typeof callbackId !== "undefined") {
|
if (typeof callbackId !== "undefined") {
|
||||||
this.blockId = callbackId;
|
this.blockId = callbackId;
|
||||||
}
|
}
|
||||||
this.tree.updateData(data.data);
|
this.tree.updateData(data.data);
|
||||||
|
|
||||||
// 从新的持久化存储恢复折叠状态
|
if (this.isPreview) {
|
||||||
if (!this.isPreview) {
|
this.tree.element.querySelectorAll(".popover__block").forEach(item => {
|
||||||
|
item.classList.remove("popover__block");
|
||||||
|
});
|
||||||
|
this.element.scrollTop = scrollTop;
|
||||||
|
} else {
|
||||||
fetchPost("/api/storage/getOutlineStorage", {
|
fetchPost("/api/storage/getOutlineStorage", {
|
||||||
docID: this.blockId
|
docID: this.blockId
|
||||||
}, storageResponse => {
|
}, storageResponse => {
|
||||||
|
|
@ -640,15 +660,9 @@ export class Outline extends Model {
|
||||||
if ((this.headerElement.querySelector("input.b3-text-field.search__label") as HTMLInputElement).value) {
|
if ((this.headerElement.querySelector("input.b3-text-field.search__label") as HTMLInputElement).value) {
|
||||||
this.setFilter();
|
this.setFilter();
|
||||||
}
|
}
|
||||||
|
this.element.scrollTop = scrollTop;
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
if (this.isPreview) {
|
|
||||||
this.tree.element.querySelectorAll(".popover__block").forEach(item => {
|
|
||||||
item.classList.remove("popover__block");
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
if (currentId) {
|
if (currentId) {
|
||||||
currentElement = this.element.querySelector(`[data-node-id="${currentId}"]`);
|
currentElement = this.element.querySelector(`[data-node-id="${currentId}"]`);
|
||||||
if (currentElement) {
|
if (currentElement) {
|
||||||
|
|
@ -782,6 +796,7 @@ export class Outline extends Model {
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
this.saveExpendIds();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -833,6 +848,7 @@ export class Outline extends Model {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
this.saveExpendIds();
|
||||||
}
|
}
|
||||||
|
|
||||||
private collapseChildren(element: HTMLElement, expand?: boolean) {
|
private collapseChildren(element: HTMLElement, expand?: boolean) {
|
||||||
|
|
@ -855,6 +871,7 @@ export class Outline extends Model {
|
||||||
arrowElement.classList.remove("b3-list-item__arrow--open");
|
arrowElement.classList.remove("b3-list-item__arrow--open");
|
||||||
nextElement.classList.add("fn__none");
|
nextElement.classList.add("fn__none");
|
||||||
}
|
}
|
||||||
|
this.saveExpendIds();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -1152,6 +1169,7 @@ export class Outline extends Model {
|
||||||
label: window.siyuan.languages.expandAll,
|
label: window.siyuan.languages.expandAll,
|
||||||
click: () => {
|
click: () => {
|
||||||
this.tree.expandAll();
|
this.tree.expandAll();
|
||||||
|
this.saveExpendIds();
|
||||||
}
|
}
|
||||||
}).element);
|
}).element);
|
||||||
|
|
||||||
|
|
@ -1159,7 +1177,10 @@ export class Outline extends Model {
|
||||||
window.siyuan.menus.menu.append(new MenuItem({
|
window.siyuan.menus.menu.append(new MenuItem({
|
||||||
icon: "iconContract",
|
icon: "iconContract",
|
||||||
label: window.siyuan.languages.foldAll,
|
label: window.siyuan.languages.foldAll,
|
||||||
click: () => this.tree.collapseAll()
|
click: () => {
|
||||||
|
this.tree.collapseAll();
|
||||||
|
this.saveExpendIds();
|
||||||
|
}
|
||||||
}).element);
|
}).element);
|
||||||
|
|
||||||
window.siyuan.menus.menu.popup({
|
window.siyuan.menus.menu.popup({
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue