2022-09-28 23:53:04 +08:00
|
|
|
|
import {Tab} from "../Tab";
|
|
|
|
|
|
import {Model} from "../Model";
|
|
|
|
|
|
import {getDisplayName} from "../../util/pathName";
|
|
|
|
|
|
import {Tree} from "../../util/Tree";
|
|
|
|
|
|
import {getDockByType, setPanelFocus} from "../util";
|
|
|
|
|
|
import {fetchPost} from "../../util/fetch";
|
|
|
|
|
|
import {Constants} from "../../constants";
|
|
|
|
|
|
import {updateHotkeyTip} from "../../protyle/util/compatibility";
|
|
|
|
|
|
import {openFileById} from "../../editor/util";
|
2022-10-02 20:56:48 +08:00
|
|
|
|
import {Protyle} from "../../protyle";
|
2022-09-28 23:53:04 +08:00
|
|
|
|
|
|
|
|
|
|
export class Backlink extends Model {
|
|
|
|
|
|
public element: HTMLElement;
|
|
|
|
|
|
public inputsElement: NodeListOf<HTMLInputElement>;
|
|
|
|
|
|
public type: "pin" | "local";
|
|
|
|
|
|
public blockId: string;
|
|
|
|
|
|
public rootId: string; // "local" 必传
|
|
|
|
|
|
private tree: Tree;
|
|
|
|
|
|
private notebookId: string;
|
|
|
|
|
|
private mTree: Tree;
|
2022-09-30 00:12:35 +08:00
|
|
|
|
private editors: Protyle[] = [];
|
2022-10-04 18:16:44 +08:00
|
|
|
|
private status: {
|
|
|
|
|
|
[key: string]: {
|
|
|
|
|
|
scrollTop: number,
|
|
|
|
|
|
mScrollTop: number,
|
|
|
|
|
|
backlinkOpenIds: string[],
|
|
|
|
|
|
backlinkMOpenIds: string[],
|
|
|
|
|
|
backlinkMStatus: number // 0 全展开,1 展开一半箭头向下,2 展开一半箭头向上,3 全收起
|
|
|
|
|
|
}
|
|
|
|
|
|
} = {};
|
2022-09-28 23:53:04 +08:00
|
|
|
|
|
|
|
|
|
|
constructor(options: {
|
|
|
|
|
|
tab: Tab,
|
|
|
|
|
|
blockId: string,
|
|
|
|
|
|
rootId?: string,
|
|
|
|
|
|
type: "pin" | "local"
|
|
|
|
|
|
}) {
|
|
|
|
|
|
super({
|
|
|
|
|
|
id: options.tab.id,
|
|
|
|
|
|
callback() {
|
|
|
|
|
|
if (this.type === "local") {
|
|
|
|
|
|
fetchPost("/api/block/checkBlockExist", {id: this.blockId}, existResponse => {
|
|
|
|
|
|
if (!existResponse.data) {
|
|
|
|
|
|
this.parent.parent.removeTab(this.parent.id);
|
|
|
|
|
|
}
|
|
|
|
|
|
});
|
|
|
|
|
|
}
|
|
|
|
|
|
},
|
|
|
|
|
|
msgCallback(data) {
|
|
|
|
|
|
if (data && this.type === "local") {
|
|
|
|
|
|
switch (data.cmd) {
|
|
|
|
|
|
case "rename":
|
|
|
|
|
|
if (this.blockId === data.data.id) {
|
|
|
|
|
|
this.parent.updateTitle(data.data.title);
|
|
|
|
|
|
}
|
|
|
|
|
|
break;
|
|
|
|
|
|
case "unmount":
|
|
|
|
|
|
if (this.notebookId === data.data.box) {
|
|
|
|
|
|
this.parent.parent.removeTab(this.parent.id);
|
|
|
|
|
|
}
|
|
|
|
|
|
break;
|
|
|
|
|
|
case "remove":
|
|
|
|
|
|
if (this.path?.indexOf(getDisplayName(data.data.path, false, true)) === 0) {
|
|
|
|
|
|
this.parent.parent.removeTab(this.parent.id);
|
|
|
|
|
|
}
|
|
|
|
|
|
break;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
});
|
|
|
|
|
|
this.blockId = options.blockId;
|
|
|
|
|
|
this.rootId = options.rootId;
|
|
|
|
|
|
this.type = options.type;
|
|
|
|
|
|
this.element = options.tab.panelElement;
|
|
|
|
|
|
this.element.classList.add("fn__flex-column", "file-tree", "sy__backlink");
|
|
|
|
|
|
this.element.innerHTML = `<div class="block__icons">
|
|
|
|
|
|
<div class="block__logo">
|
|
|
|
|
|
<svg><use xlink:href="#iconLink"></use></svg>
|
|
|
|
|
|
${window.siyuan.languages.backlinks}
|
|
|
|
|
|
</div>
|
|
|
|
|
|
<span class="counter listCount"></span>
|
|
|
|
|
|
<span class="fn__space"></span>
|
|
|
|
|
|
<label class="b3-form__icon b3-form__icon--small search__label">
|
2022-10-02 12:24:48 +08:00
|
|
|
|
<svg class="b3-form__icon-icon"><use xlink:href="#iconFilter"></use></svg>
|
2022-10-05 10:05:42 +08:00
|
|
|
|
<input class="b3-text-field b3-text-field--small b3-form__icon-input" placeholder="${window.siyuan.languages.filterDocNameEnter}" />
|
2022-09-28 23:53:04 +08:00
|
|
|
|
</label>
|
|
|
|
|
|
<span class="fn__space"></span>
|
|
|
|
|
|
<span data-type="refresh" class="block__icon b3-tooltips b3-tooltips__sw" aria-label="${window.siyuan.languages.refresh}"><svg><use xlink:href='#iconRefresh'></use></svg></span>
|
|
|
|
|
|
<span class="fn__space"></span>
|
|
|
|
|
|
<span data-type="collapse" class="block__icon b3-tooltips b3-tooltips__sw" aria-label="${window.siyuan.languages.collapse} ${updateHotkeyTip(window.siyuan.config.keymap.editor.general.collapse.custom)}">
|
|
|
|
|
|
<svg><use xlink:href="#iconContract"></use></svg>
|
|
|
|
|
|
</span>
|
|
|
|
|
|
<span class="${this.type === "local" ? "fn__none " : ""}fn__space"></span>
|
|
|
|
|
|
<span data-type="min" class="${this.type === "local" ? "fn__none " : ""}block__icon b3-tooltips b3-tooltips__sw" aria-label="${window.siyuan.languages.min} ${updateHotkeyTip(window.siyuan.config.keymap.general.closeTab.custom)}"><svg><use xlink:href='#iconMin'></use></svg></span>
|
|
|
|
|
|
</div>
|
|
|
|
|
|
<div class="backlinkList fn__flex-1"></div>
|
|
|
|
|
|
<div class="block__icons">
|
|
|
|
|
|
<div class="block__logo">
|
|
|
|
|
|
<svg><use xlink:href="#iconLink"></use></svg>
|
|
|
|
|
|
${window.siyuan.languages.mentions}
|
|
|
|
|
|
</div>
|
|
|
|
|
|
<span class="counter listMCount"></span>
|
|
|
|
|
|
<span class="fn__space"></span>
|
|
|
|
|
|
<label class="b3-form__icon b3-form__icon--small search__label">
|
2022-10-02 12:24:48 +08:00
|
|
|
|
<svg class="b3-form__icon-icon"><use xlink:href="#iconFilter"></use></svg>
|
2022-10-05 10:05:42 +08:00
|
|
|
|
<input class="b3-text-field b3-text-field--small b3-form__icon-input" placeholder="${window.siyuan.languages.filterDocNameEnter}" />
|
2022-09-28 23:53:04 +08:00
|
|
|
|
</label>
|
|
|
|
|
|
<span class="fn__space"></span>
|
|
|
|
|
|
<span data-type="mCollapse" class="block__icon b3-tooltips b3-tooltips__nw" aria-label="${window.siyuan.languages.collapse}">
|
|
|
|
|
|
<svg><use xlink:href="#iconContract"></use></svg>
|
|
|
|
|
|
</span>
|
|
|
|
|
|
<span class="fn__space"></span>
|
|
|
|
|
|
<span data-type="layout" class="block__icon b3-tooltips b3-tooltips__nw" aria-label="${window.siyuan.languages.down}">
|
|
|
|
|
|
<svg><use xlink:href="#iconDown"></use></svg>
|
|
|
|
|
|
</span>
|
|
|
|
|
|
</div>
|
|
|
|
|
|
<div class="backlinkMList fn__flex-1"></div>`;
|
|
|
|
|
|
|
|
|
|
|
|
this.inputsElement = this.element.querySelectorAll("input");
|
|
|
|
|
|
this.inputsElement.forEach((item) => {
|
|
|
|
|
|
item.addEventListener("keydown", (event: KeyboardEvent) => {
|
|
|
|
|
|
if (!event.isComposing && event.key === "Enter") {
|
|
|
|
|
|
this.searchBacklinks();
|
|
|
|
|
|
}
|
|
|
|
|
|
});
|
|
|
|
|
|
item.addEventListener("input", (event: KeyboardEvent) => {
|
|
|
|
|
|
const inputElement = event.target as HTMLInputElement;
|
|
|
|
|
|
if (inputElement.value === "") {
|
|
|
|
|
|
inputElement.classList.remove("search__input--block");
|
|
|
|
|
|
} else {
|
|
|
|
|
|
inputElement.classList.add("search__input--block");
|
|
|
|
|
|
}
|
|
|
|
|
|
});
|
|
|
|
|
|
});
|
|
|
|
|
|
this.tree = new Tree({
|
|
|
|
|
|
element: this.element.querySelector(".backlinkList") as HTMLElement,
|
|
|
|
|
|
data: null,
|
2022-10-02 11:37:56 +08:00
|
|
|
|
click: (element) => {
|
|
|
|
|
|
this.toggleItem(element, false);
|
2022-09-28 23:53:04 +08:00
|
|
|
|
},
|
2022-09-30 10:39:35 +08:00
|
|
|
|
ctrlClick(element) {
|
2022-09-28 23:53:04 +08:00
|
|
|
|
openFileById({
|
|
|
|
|
|
id: element.getAttribute("data-node-id"),
|
|
|
|
|
|
keepCursor: true,
|
|
|
|
|
|
action: [Constants.CB_GET_CONTEXT]
|
|
|
|
|
|
});
|
|
|
|
|
|
},
|
2022-09-30 10:39:35 +08:00
|
|
|
|
altClick(element) {
|
2022-09-28 23:53:04 +08:00
|
|
|
|
openFileById({
|
|
|
|
|
|
id: element.getAttribute("data-node-id"),
|
|
|
|
|
|
position: "right",
|
|
|
|
|
|
action: [Constants.CB_GET_FOCUS, Constants.CB_GET_CONTEXT]
|
|
|
|
|
|
});
|
|
|
|
|
|
},
|
2022-09-30 10:39:35 +08:00
|
|
|
|
shiftClick(element) {
|
2022-09-28 23:53:04 +08:00
|
|
|
|
openFileById({
|
|
|
|
|
|
id: element.getAttribute("data-node-id"),
|
|
|
|
|
|
position: "bottom",
|
|
|
|
|
|
action: [Constants.CB_GET_FOCUS, Constants.CB_GET_CONTEXT]
|
|
|
|
|
|
});
|
2022-09-29 12:48:25 +08:00
|
|
|
|
},
|
2022-09-30 10:39:35 +08:00
|
|
|
|
toggleClick: (liElement) => {
|
2022-10-02 00:00:44 +08:00
|
|
|
|
this.toggleItem(liElement, false);
|
2022-09-28 23:53:04 +08:00
|
|
|
|
}
|
|
|
|
|
|
});
|
|
|
|
|
|
this.mTree = new Tree({
|
|
|
|
|
|
element: this.element.querySelector(".backlinkMList") as HTMLElement,
|
|
|
|
|
|
data: null,
|
2022-10-03 16:22:18 +08:00
|
|
|
|
click: (element) => {
|
2022-10-02 11:37:56 +08:00
|
|
|
|
this.toggleItem(element, true);
|
2022-09-28 23:53:04 +08:00
|
|
|
|
},
|
2022-09-30 10:39:35 +08:00
|
|
|
|
ctrlClick(element) {
|
2022-09-28 23:53:04 +08:00
|
|
|
|
openFileById({
|
|
|
|
|
|
id: element.getAttribute("data-node-id"),
|
|
|
|
|
|
keepCursor: true,
|
|
|
|
|
|
action: [Constants.CB_GET_CONTEXT]
|
|
|
|
|
|
});
|
|
|
|
|
|
},
|
2022-09-30 10:39:35 +08:00
|
|
|
|
altClick(element) {
|
2022-09-28 23:53:04 +08:00
|
|
|
|
openFileById({
|
|
|
|
|
|
id: element.getAttribute("data-node-id"),
|
|
|
|
|
|
position: "right",
|
|
|
|
|
|
action: [Constants.CB_GET_FOCUS, Constants.CB_GET_CONTEXT]
|
|
|
|
|
|
});
|
|
|
|
|
|
},
|
2022-09-30 10:39:35 +08:00
|
|
|
|
shiftClick(element) {
|
2022-09-28 23:53:04 +08:00
|
|
|
|
openFileById({
|
|
|
|
|
|
id: element.getAttribute("data-node-id"),
|
|
|
|
|
|
position: "bottom",
|
|
|
|
|
|
action: [Constants.CB_GET_FOCUS, Constants.CB_GET_CONTEXT]
|
|
|
|
|
|
});
|
|
|
|
|
|
},
|
2022-10-02 00:00:44 +08:00
|
|
|
|
toggleClick: (liElement) => {
|
|
|
|
|
|
this.toggleItem(liElement, true);
|
|
|
|
|
|
},
|
2022-09-28 23:53:04 +08:00
|
|
|
|
blockExtHTML: `<span class="b3-list-item__action b3-tooltips b3-tooltips__nw" aria-label="${window.siyuan.languages.more}"><svg><use xlink:href="#iconMore"></use></svg></span>`
|
|
|
|
|
|
});
|
2022-09-30 00:12:35 +08:00
|
|
|
|
this.tree.element.addEventListener("scroll", () => {
|
|
|
|
|
|
this.tree.element.querySelectorAll(".protyle-gutters").forEach(item => {
|
|
|
|
|
|
item.classList.add("fn__none");
|
|
|
|
|
|
item.innerHTML = "";
|
2022-10-04 18:16:44 +08:00
|
|
|
|
});
|
|
|
|
|
|
this.tree.element.querySelectorAll(".protyle-wysiwyg--hl").forEach((hlItem) => {
|
|
|
|
|
|
hlItem.classList.remove("protyle-wysiwyg--hl");
|
2022-09-30 00:13:07 +08:00
|
|
|
|
});
|
|
|
|
|
|
});
|
2022-09-30 00:12:35 +08:00
|
|
|
|
this.mTree.element.addEventListener("scroll", () => {
|
|
|
|
|
|
this.mTree.element.querySelectorAll(".protyle-gutters").forEach(item => {
|
|
|
|
|
|
item.classList.add("fn__none");
|
|
|
|
|
|
item.innerHTML = "";
|
2022-10-04 18:16:44 +08:00
|
|
|
|
});
|
|
|
|
|
|
this.mTree.element.querySelectorAll(".protyle-wysiwyg--hl").forEach((hlItem) => {
|
|
|
|
|
|
hlItem.classList.remove("protyle-wysiwyg--hl");
|
2022-09-30 00:13:07 +08:00
|
|
|
|
});
|
|
|
|
|
|
});
|
2022-09-28 23:53:04 +08:00
|
|
|
|
// 为了快捷键的 dispatch
|
|
|
|
|
|
this.element.querySelector('[data-type="collapse"]').addEventListener("click", () => {
|
2022-09-30 10:39:35 +08:00
|
|
|
|
this.tree.element.querySelectorAll(".protyle").forEach(item => {
|
|
|
|
|
|
item.classList.add("fn__none");
|
|
|
|
|
|
});
|
|
|
|
|
|
this.tree.element.querySelectorAll(".b3-list-item__arrow").forEach(item => {
|
|
|
|
|
|
item.classList.remove("b3-list-item__arrow--open");
|
|
|
|
|
|
});
|
2022-09-28 23:53:04 +08:00
|
|
|
|
});
|
|
|
|
|
|
this.element.addEventListener("click", (event) => {
|
|
|
|
|
|
if (this.type === "local") {
|
|
|
|
|
|
setPanelFocus(this.element.parentElement.parentElement);
|
|
|
|
|
|
} else {
|
|
|
|
|
|
setPanelFocus(this.element.firstElementChild);
|
|
|
|
|
|
}
|
|
|
|
|
|
let target = event.target as HTMLElement;
|
|
|
|
|
|
while (target && !target.isEqualNode(this.element)) {
|
|
|
|
|
|
if (target.classList.contains("block__icon")) {
|
|
|
|
|
|
const type = target.getAttribute("data-type");
|
|
|
|
|
|
switch (type) {
|
|
|
|
|
|
case "refresh":
|
|
|
|
|
|
this.refresh();
|
|
|
|
|
|
break;
|
|
|
|
|
|
case "mCollapse":
|
2022-09-30 10:39:35 +08:00
|
|
|
|
this.mTree.element.querySelectorAll(".protyle").forEach(item => {
|
|
|
|
|
|
item.classList.add("fn__none");
|
|
|
|
|
|
});
|
|
|
|
|
|
this.mTree.element.querySelectorAll(".b3-list-item__arrow").forEach(item => {
|
|
|
|
|
|
item.classList.remove("b3-list-item__arrow--open");
|
|
|
|
|
|
});
|
2022-09-28 23:53:04 +08:00
|
|
|
|
break;
|
|
|
|
|
|
case "min":
|
|
|
|
|
|
getDockByType("backlink").toggleModel("backlink");
|
|
|
|
|
|
break;
|
|
|
|
|
|
case "layout":
|
|
|
|
|
|
if (this.mTree.element.style.flex) {
|
|
|
|
|
|
if (this.mTree.element.style.height === "0px") {
|
|
|
|
|
|
this.tree.element.classList.remove("fn__none");
|
|
|
|
|
|
this.mTree.element.removeAttribute("style");
|
|
|
|
|
|
target.setAttribute("aria-label", window.siyuan.languages.up);
|
|
|
|
|
|
target.querySelector("use").setAttribute("xlink:href", "#iconUp");
|
|
|
|
|
|
} else {
|
|
|
|
|
|
this.tree.element.classList.remove("fn__none");
|
|
|
|
|
|
this.mTree.element.removeAttribute("style");
|
|
|
|
|
|
target.setAttribute("aria-label", window.siyuan.languages.down);
|
|
|
|
|
|
target.querySelector("use").setAttribute("xlink:href", "#iconDown");
|
|
|
|
|
|
}
|
|
|
|
|
|
} else {
|
|
|
|
|
|
if (target.getAttribute("aria-label") === window.siyuan.languages.down) {
|
|
|
|
|
|
this.tree.element.classList.remove("fn__none");
|
|
|
|
|
|
this.mTree.element.setAttribute("style", "flex:none;height:0px");
|
|
|
|
|
|
target.setAttribute("aria-label", window.siyuan.languages.up);
|
|
|
|
|
|
target.querySelector("use").setAttribute("xlink:href", "#iconUp");
|
|
|
|
|
|
} else {
|
|
|
|
|
|
this.tree.element.classList.add("fn__none");
|
|
|
|
|
|
this.mTree.element.setAttribute("style", `flex:none;height:${this.element.clientHeight - this.tree.element.previousElementSibling.clientHeight * 2}px`);
|
|
|
|
|
|
target.setAttribute("aria-label", window.siyuan.languages.down);
|
|
|
|
|
|
target.querySelector("use").setAttribute("xlink:href", "#iconDown");
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
2022-10-04 18:16:44 +08:00
|
|
|
|
this.tree.element.dispatchEvent(new CustomEvent("scroll"));
|
|
|
|
|
|
this.mTree.element.dispatchEvent(new CustomEvent("scroll"));
|
2022-09-28 23:53:04 +08:00
|
|
|
|
break;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
target = target.parentElement;
|
|
|
|
|
|
}
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
this.searchBacklinks();
|
|
|
|
|
|
|
|
|
|
|
|
if (this.type === "pin") {
|
|
|
|
|
|
setPanelFocus(this.element.firstElementChild);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2022-10-02 10:14:54 +08:00
|
|
|
|
private toggleItem(liElement: HTMLElement, isMention: boolean) {
|
2022-09-30 10:39:35 +08:00
|
|
|
|
const svgElement = liElement.firstElementChild.firstElementChild;
|
2022-10-03 16:22:18 +08:00
|
|
|
|
const docId = liElement.getAttribute("data-node-id");
|
2022-09-30 10:39:35 +08:00
|
|
|
|
if (svgElement.classList.contains("b3-list-item__arrow--open")) {
|
|
|
|
|
|
svgElement.classList.remove("b3-list-item__arrow--open");
|
2022-10-02 20:15:08 +08:00
|
|
|
|
this.editors.find((item, index) => {
|
|
|
|
|
|
if (item.protyle.block.rootID === docId) {
|
|
|
|
|
|
item.destroy();
|
|
|
|
|
|
this.editors.splice(index, 1);
|
|
|
|
|
|
return true;
|
|
|
|
|
|
}
|
|
|
|
|
|
});
|
|
|
|
|
|
liElement.nextElementSibling?.remove();
|
2022-09-30 10:39:35 +08:00
|
|
|
|
} else {
|
|
|
|
|
|
svgElement.classList.add("b3-list-item__arrow--open");
|
2022-10-02 20:15:08 +08:00
|
|
|
|
fetchPost(isMention ? "/api/ref/getBackmentionDoc" : "/api/ref/getBacklinkDoc", {
|
|
|
|
|
|
defID: this.blockId,
|
|
|
|
|
|
refTreeID: docId
|
|
|
|
|
|
}, (response) => {
|
|
|
|
|
|
const editorElement = document.createElement("div");
|
|
|
|
|
|
editorElement.style.minHeight = "auto";
|
2022-10-03 16:22:18 +08:00
|
|
|
|
editorElement.setAttribute("data-defid", this.blockId);
|
2022-10-04 18:16:44 +08:00
|
|
|
|
editorElement.setAttribute("data-ismention", isMention ? "true" : "false");
|
2022-10-02 20:15:08 +08:00
|
|
|
|
liElement.after(editorElement);
|
|
|
|
|
|
const editor = new Protyle(editorElement, {
|
|
|
|
|
|
blockId: "",
|
|
|
|
|
|
backlinkData: isMention ? response.data.backmentions : response.data.backlinks,
|
|
|
|
|
|
render: {
|
|
|
|
|
|
background: false,
|
|
|
|
|
|
title: false,
|
|
|
|
|
|
gutter: true,
|
|
|
|
|
|
scroll: false,
|
|
|
|
|
|
breadcrumb: false,
|
|
|
|
|
|
}
|
2022-09-30 10:39:35 +08:00
|
|
|
|
});
|
2022-10-03 16:22:18 +08:00
|
|
|
|
editor.protyle.block.rootID = docId;
|
2022-10-02 20:15:08 +08:00
|
|
|
|
this.editors.push(editor);
|
|
|
|
|
|
});
|
2022-09-30 10:39:35 +08:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2022-10-04 18:16:44 +08:00
|
|
|
|
private refresh() {
|
2022-09-28 23:53:04 +08:00
|
|
|
|
fetchPost("/api/ref/refreshBacklink", {
|
|
|
|
|
|
id: this.blockId,
|
|
|
|
|
|
}, () => {
|
|
|
|
|
|
this.searchBacklinks();
|
|
|
|
|
|
});
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private searchBacklinks(reload = false) {
|
|
|
|
|
|
const element = this.element.querySelector('.block__icon[data-type="refresh"] svg');
|
|
|
|
|
|
if (element.classList.contains("fn__rotate") && !reload) {
|
|
|
|
|
|
return;
|
|
|
|
|
|
}
|
|
|
|
|
|
element.classList.add("fn__rotate");
|
2022-10-02 12:08:13 +08:00
|
|
|
|
fetchPost("/api/ref/getBacklink2", {
|
2022-09-28 23:53:04 +08:00
|
|
|
|
k: this.inputsElement[0].value,
|
|
|
|
|
|
mk: this.inputsElement[1].value,
|
|
|
|
|
|
id: this.blockId,
|
|
|
|
|
|
}, response => {
|
2022-10-04 18:16:44 +08:00
|
|
|
|
this.saveStatus();
|
2022-09-28 23:53:04 +08:00
|
|
|
|
this.render(response.data);
|
|
|
|
|
|
});
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2022-10-04 18:16:44 +08:00
|
|
|
|
public saveStatus() {
|
|
|
|
|
|
this.status[this.blockId] = {
|
|
|
|
|
|
scrollTop: this.tree.element.scrollTop,
|
|
|
|
|
|
mScrollTop: this.mTree.element.scrollTop,
|
|
|
|
|
|
backlinkOpenIds: [],
|
|
|
|
|
|
backlinkMOpenIds: [],
|
|
|
|
|
|
backlinkMStatus: 3 // 0 全展开,1 展开一半箭头向下,2 展开一半箭头向上,3 全收起
|
|
|
|
|
|
}
|
|
|
|
|
|
this.tree.element.querySelectorAll(".b3-list-item__arrow--open").forEach(item => {
|
|
|
|
|
|
this.status[this.blockId].backlinkOpenIds.push(item.parentElement.parentElement.getAttribute("data-node-id"))
|
|
|
|
|
|
})
|
|
|
|
|
|
this.mTree.element.querySelectorAll(".b3-list-item__arrow--open").forEach(item => {
|
|
|
|
|
|
this.status[this.blockId].backlinkMOpenIds.push(item.parentElement.parentElement.getAttribute("data-node-id"))
|
|
|
|
|
|
})
|
|
|
|
|
|
if (this.mTree.element.style.flex) {
|
|
|
|
|
|
if (this.mTree.element.style.height === "0px") {
|
|
|
|
|
|
this.status[this.blockId].backlinkMStatus = 3;
|
|
|
|
|
|
} else {
|
|
|
|
|
|
this.status[this.blockId].backlinkMStatus = 0;
|
|
|
|
|
|
}
|
|
|
|
|
|
} else {
|
|
|
|
|
|
if (this.mTree.element.previousElementSibling.querySelector('[data-type="layout"]').getAttribute("aria-label") === window.siyuan.languages.down) {
|
|
|
|
|
|
this.status[this.blockId].backlinkMStatus = 1;
|
|
|
|
|
|
} else {
|
|
|
|
|
|
this.status[this.blockId].backlinkMStatus = 2;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2022-09-28 23:53:04 +08:00
|
|
|
|
public render(data: { box: string, backlinks: IBlockTree[], backmentions: IBlockTree[], linkRefsCount: number, mentionsCount: number, k: string, mk: string }) {
|
|
|
|
|
|
if (!data) {
|
|
|
|
|
|
data = {
|
|
|
|
|
|
box: "",
|
|
|
|
|
|
backlinks: [],
|
|
|
|
|
|
backmentions: [],
|
|
|
|
|
|
linkRefsCount: 0,
|
|
|
|
|
|
mentionsCount: 0,
|
|
|
|
|
|
k: "",
|
|
|
|
|
|
mk: ""
|
|
|
|
|
|
};
|
|
|
|
|
|
}
|
2022-09-29 22:26:55 +08:00
|
|
|
|
|
|
|
|
|
|
this.editors.forEach(item => {
|
2022-09-30 00:13:07 +08:00
|
|
|
|
item.destroy();
|
|
|
|
|
|
});
|
2022-09-29 22:26:55 +08:00
|
|
|
|
this.editors = [];
|
2022-09-28 23:53:04 +08:00
|
|
|
|
this.element.querySelector('.block__icon[data-type="refresh"] svg').classList.remove("fn__rotate");
|
|
|
|
|
|
this.notebookId = data.box;
|
|
|
|
|
|
this.inputsElement[0].value = data.k;
|
|
|
|
|
|
this.inputsElement[1].value = data.mk;
|
|
|
|
|
|
this.tree.updateData(data.backlinks);
|
|
|
|
|
|
this.mTree.updateData(data.backmentions);
|
|
|
|
|
|
|
|
|
|
|
|
const countElement = this.element.querySelector(".listCount");
|
|
|
|
|
|
if (data.linkRefsCount === 0) {
|
|
|
|
|
|
countElement.classList.add("fn__none");
|
|
|
|
|
|
} else {
|
|
|
|
|
|
countElement.classList.remove("fn__none");
|
|
|
|
|
|
countElement.textContent = data.linkRefsCount.toString();
|
|
|
|
|
|
}
|
|
|
|
|
|
const mCountElement = this.element.querySelector(".listMCount");
|
|
|
|
|
|
if (data.mentionsCount === 0) {
|
|
|
|
|
|
mCountElement.classList.add("fn__none");
|
|
|
|
|
|
} else {
|
|
|
|
|
|
mCountElement.classList.remove("fn__none");
|
|
|
|
|
|
mCountElement.textContent = data.mentionsCount.toString();
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2022-10-04 18:16:44 +08:00
|
|
|
|
if (!this.status[this.blockId]) {
|
|
|
|
|
|
this.status[this.blockId] = {
|
|
|
|
|
|
scrollTop: 0,
|
|
|
|
|
|
mScrollTop: 0,
|
|
|
|
|
|
backlinkOpenIds: [],
|
|
|
|
|
|
backlinkMOpenIds: [],
|
|
|
|
|
|
backlinkMStatus: 3
|
|
|
|
|
|
}
|
|
|
|
|
|
if (data.mentionsCount === 0) {
|
|
|
|
|
|
this.status[this.blockId].backlinkMStatus = 3;
|
|
|
|
|
|
} else {
|
|
|
|
|
|
this.status[this.blockId].backlinkMOpenIds = [data.backmentions[0].id]
|
|
|
|
|
|
if (data.linkRefsCount === 0) {
|
|
|
|
|
|
this.status[this.blockId].backlinkMStatus = 0;
|
|
|
|
|
|
} else {
|
|
|
|
|
|
this.status[this.blockId].backlinkOpenIds = [data.backlinks[0].id]
|
|
|
|
|
|
this.status[this.blockId].backlinkMStatus = 1;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
2022-09-28 23:53:04 +08:00
|
|
|
|
}
|
2022-10-04 18:16:44 +08:00
|
|
|
|
|
|
|
|
|
|
// restore status
|
|
|
|
|
|
this.status[this.blockId].backlinkOpenIds.forEach(item => {
|
|
|
|
|
|
const liElement = this.tree.element.querySelector(`.b3-list-item[data-node-id="${item}"]`) as HTMLElement
|
|
|
|
|
|
if (liElement) {
|
|
|
|
|
|
this.toggleItem(liElement, false);
|
|
|
|
|
|
}
|
|
|
|
|
|
})
|
|
|
|
|
|
this.status[this.blockId].backlinkMOpenIds.forEach(item => {
|
|
|
|
|
|
const liElement = this.mTree.element.querySelector(`.b3-list-item[data-node-id="${item}"]`) as HTMLElement
|
|
|
|
|
|
if (liElement) {
|
|
|
|
|
|
this.toggleItem(liElement, true);
|
|
|
|
|
|
}
|
|
|
|
|
|
})
|
|
|
|
|
|
// 0 全展开,1 展开一半箭头向下,2 展开一半箭头向上,3 全收起
|
|
|
|
|
|
const layoutElement = this.mTree.element.previousElementSibling.querySelector('[data-type="layout"]');
|
|
|
|
|
|
if (this.status[this.blockId].backlinkMStatus === 2 || this.status[this.blockId].backlinkMStatus === 1) {
|
|
|
|
|
|
this.tree.element.classList.remove("fn__none");
|
|
|
|
|
|
this.mTree.element.removeAttribute("style");
|
|
|
|
|
|
if (this.status[this.blockId].backlinkMStatus === 1) {
|
|
|
|
|
|
layoutElement.setAttribute("aria-label", window.siyuan.languages.down);
|
|
|
|
|
|
layoutElement.querySelector("use").setAttribute("xlink:href", "#iconDown");
|
|
|
|
|
|
} else {
|
|
|
|
|
|
layoutElement.setAttribute("aria-label", window.siyuan.languages.up);
|
|
|
|
|
|
layoutElement.querySelector("use").setAttribute("xlink:href", "#iconUp");
|
|
|
|
|
|
}
|
|
|
|
|
|
}else if (this.status[this.blockId].backlinkMStatus === 3) {
|
2022-09-28 23:53:04 +08:00
|
|
|
|
this.tree.element.classList.remove("fn__none");
|
|
|
|
|
|
this.mTree.element.setAttribute("style", "flex:none;height:0px");
|
|
|
|
|
|
layoutElement.setAttribute("aria-label", window.siyuan.languages.up);
|
|
|
|
|
|
layoutElement.querySelector("use").setAttribute("xlink:href", "#iconUp");
|
2022-10-04 18:16:44 +08:00
|
|
|
|
} else {
|
2022-09-28 23:53:04 +08:00
|
|
|
|
this.tree.element.classList.add("fn__none");
|
|
|
|
|
|
this.mTree.element.setAttribute("style", `flex:none;height:${this.element.clientHeight - this.tree.element.previousElementSibling.clientHeight * 2}px`);
|
|
|
|
|
|
layoutElement.setAttribute("aria-label", window.siyuan.languages.down);
|
|
|
|
|
|
layoutElement.querySelector("use").setAttribute("xlink:href", "#iconDown");
|
|
|
|
|
|
}
|
2022-10-04 18:16:44 +08:00
|
|
|
|
setTimeout(() => {
|
|
|
|
|
|
this.tree.element.scrollTop = this.status[this.blockId].scrollTop;
|
|
|
|
|
|
this.mTree.element.scrollTop = this.status[this.blockId].mScrollTop;
|
|
|
|
|
|
}, Constants.TIMEOUT_BLOCKLOAD);
|
2022-09-28 23:53:04 +08:00
|
|
|
|
}
|
|
|
|
|
|
}
|