A privacy-first, self-hosted, fully open source personal knowledge management software, written in typescript and golang. (PERSONAL FORK)
at lambda-fork/main 87 lines 3.7 kB view raw
1import {getAllEditor} from "../../layout/getAll"; 2 3// "gutter", "toolbar", "select", "hint", "util", "dialog", "gutterOnly" 4export const hideElements = (panels: string[], protyle?: IProtyle, focusHide = false) => { 5 if (!protyle) { 6 if (panels.includes("dialog")) { 7 const dialogLength = window.siyuan.dialogs.length; 8 for (let i = 0; i < dialogLength; i++) { 9 window.siyuan.dialogs[i].destroy(); 10 } 11 } 12 return; 13 } 14 if (panels.includes("hint")) { 15 clearTimeout(protyle.hint.timeId); 16 protyle.hint.element.classList.add("fn__none"); 17 } 18 if (protyle.gutter && panels.includes("gutter")) { 19 protyle.gutter.element.classList.add("fn__none"); 20 protyle.gutter.element.innerHTML = ""; 21 // https://ld246.com/article/1651935412480 22 protyle.wysiwyg.element.querySelectorAll(".protyle-wysiwyg--hl").forEach((item) => { 23 item.classList.remove("protyle-wysiwyg--hl"); 24 }); 25 } 26 // 不能 remove("protyle-wysiwyg--hl") 否则打开页签的时候 "cb-get-hl" 高亮会被移除 27 if (protyle.gutter && panels.includes("gutterOnly")) { 28 protyle.gutter.element.classList.add("fn__none"); 29 protyle.gutter.element.innerHTML = ""; 30 } 31 if (protyle.toolbar && panels.includes("toolbar")) { 32 protyle.toolbar.element.classList.add("fn__none"); 33 protyle.toolbar.element.style.display = ""; 34 } 35 if (protyle.toolbar && panels.includes("util")) { 36 const pinElement = protyle.toolbar.subElement.querySelector('[data-type="pin"]'); 37 if (focusHide || !pinElement || (pinElement && pinElement.getAttribute("aria-label") === window.siyuan.languages.pin)) { 38 protyle.toolbar.subElement.classList.add("fn__none"); 39 if (protyle.toolbar.subElementCloseCB) { 40 protyle.toolbar.subElementCloseCB(); 41 protyle.toolbar.subElementCloseCB = undefined; 42 } 43 } 44 } 45 if (panels.includes("select")) { 46 protyle.wysiwyg.element.querySelectorAll(".protyle-wysiwyg--select").forEach(item => { 47 item.classList.remove("protyle-wysiwyg--select"); 48 item.removeAttribute("select-start"); 49 item.removeAttribute("select-end"); 50 }); 51 } 52}; 53 54// "toolbar", "pdfutil", "gutter", "util" 55export const hideAllElements = (types: string[]) => { 56 if (types.includes("toolbar")) { 57 document.querySelectorAll(".protyle-toolbar").forEach((item: HTMLElement) => { 58 item.classList.add("fn__none"); 59 item.style.display = ""; 60 }); 61 } 62 if (types.includes("util")) { 63 getAllEditor().forEach(item => { 64 if (item.protyle.toolbar) { 65 const pinElement = item.protyle.toolbar.subElement.querySelector('[data-type="pin"]'); 66 if (!pinElement || (pinElement && pinElement.getAttribute("aria-label") === window.siyuan.languages.pin)) { 67 item.protyle.toolbar.subElement.classList.add("fn__none"); 68 if (item.protyle.toolbar.subElementCloseCB) { 69 item.protyle.toolbar.subElementCloseCB(); 70 item.protyle.toolbar.subElementCloseCB = undefined; 71 } 72 } 73 } 74 }); 75 } 76 if (types.includes("pdfutil")) { 77 document.querySelectorAll(".pdf__util").forEach(item => { 78 item.classList.add("fn__none"); 79 }); 80 } 81 if (types.includes("gutter")) { 82 document.querySelectorAll(".protyle-gutters").forEach(item => { 83 item.classList.add("fn__none"); 84 item.innerHTML = ""; 85 }); 86 } 87};