This commit is contained in:
Vanessa 2023-02-07 12:40:45 +08:00
parent 42065d6daa
commit b43f5112bb
2 changed files with 15 additions and 27 deletions

View File

@ -17,6 +17,7 @@ import {preventScroll} from "../scroll/preventScroll";
import {restoreScroll} from "../scroll/saveScroll"; import {restoreScroll} from "../scroll/saveScroll";
import {removeLoading} from "../ui/initUI"; import {removeLoading} from "../ui/initUI";
import {isMobile} from "../../util/functions"; import {isMobile} from "../../util/functions";
import {foldPassiveType} from "../wysiwyg/renderBacklink";
export const onGet = (data: IWebSocketData, protyle: IProtyle, action: string[] = [], scrollAttr?: IScrollAttr, renderTitle = false) => { export const onGet = (data: IWebSocketData, protyle: IProtyle, action: string[] = [], scrollAttr?: IScrollAttr, renderTitle = false) => {
protyle.wysiwyg.element.removeAttribute("data-top"); protyle.wysiwyg.element.removeAttribute("data-top");
@ -182,25 +183,7 @@ const setHTML = (options: {
protyle.wysiwyg.element.innerHTML = options.content; protyle.wysiwyg.element.innerHTML = options.content;
} }
if (options.action.includes(Constants.CB_GET_BACKLINK)) { if (options.action.includes(Constants.CB_GET_BACKLINK)) {
if (protyle.wysiwyg.element.firstElementChild.classList.contains("li")) { foldPassiveType(options.expand, protyle.wysiwyg.element);
if (options.expand) {
const thirdLiElement = protyle.wysiwyg.element.querySelector(".li .li .li");
if (thirdLiElement) {
thirdLiElement.setAttribute("fold", "1");
}
} else {
protyle.wysiwyg.element.firstElementChild.setAttribute("fold", "1");
}
} else if (protyle.wysiwyg.element.firstElementChild.getAttribute("data-type") === "NodeHeading") {
Array.from(protyle.wysiwyg.element.children).forEach((item, index) => {
if ((options.expand && index > 2) || (!options.expand && index > 1)) {
if ((options.expand && index === 3) || (!options.expand && index === 2)) {
item.insertAdjacentHTML("beforebegin", '<div style="max-width: 100%;justify-content: center;" contenteditable="false" class="protyle-breadcrumb__item"><svg><use xlink:href="#iconMore"></use></svg></div>');
}
item.classList.add("fn__none");
}
});
}
} }
processRender(protyle.wysiwyg.element); processRender(protyle.wysiwyg.element);
highlightRender(protyle.wysiwyg.element); highlightRender(protyle.wysiwyg.element);

View File

@ -27,21 +27,20 @@ export const renderBacklink = (protyle: IProtyle, backlinkData: {
} }
}; };
const setBacklinkFold = (html: string, expand: boolean) => { // 传递型折叠处理
const tempDom = document.createElement("template"); export const foldPassiveType = (expand: boolean, element: HTMLElement | DocumentFragment) => {
tempDom.innerHTML = html; if (element.firstElementChild.classList.contains("li")) {
if (tempDom.content.firstElementChild.classList.contains("li")) {
if (expand) { if (expand) {
tempDom.content.querySelectorAll(".li .li .li").forEach(item => { element.querySelectorAll(".li .li .li").forEach(item => {
if (item.childElementCount > 3) { if (item.childElementCount > 3) {
item.setAttribute("fold", "1"); item.setAttribute("fold", "1");
} }
}); });
} else { } else {
tempDom.content.firstElementChild.setAttribute("fold", "1"); element.firstElementChild.setAttribute("fold", "1");
} }
} else if (tempDom.content.firstElementChild.getAttribute("data-type") === "NodeHeading") { } else if (element.firstElementChild.getAttribute("data-type") === "NodeHeading") {
Array.from(tempDom.content.children).forEach((item, index) => { Array.from(element.children).forEach((item, index) => {
if ((expand && index > 2) || (!expand && index > 1)) { if ((expand && index > 2) || (!expand && index > 1)) {
if ((expand && index === 3) || (!expand && index === 2)) { if ((expand && index === 3) || (!expand && index === 2)) {
item.insertAdjacentHTML("beforebegin", '<div style="max-width: 100%;justify-content: center;" contenteditable="false" class="protyle-breadcrumb__item"><svg><use xlink:href="#iconMore"></use></svg></div>'); item.insertAdjacentHTML("beforebegin", '<div style="max-width: 100%;justify-content: center;" contenteditable="false" class="protyle-breadcrumb__item"><svg><use xlink:href="#iconMore"></use></svg></div>');
@ -50,6 +49,12 @@ const setBacklinkFold = (html: string, expand: boolean) => {
} }
}); });
} }
}
const setBacklinkFold = (html: string, expand: boolean) => {
const tempDom = document.createElement("template");
tempDom.innerHTML = html;
foldPassiveType(expand, tempDom.content);
return tempDom.innerHTML; return tempDom.innerHTML;
}; };