A privacy-first, self-hosted, fully open source personal knowledge management software, written in typescript and golang. (PERSONAL FORK)
1import {isInEmbedBlock} from "../util/hasClosest";
2import {Constants} from "../../constants";
3
4export const genIconHTML = (element?: false | HTMLElement, actions = ["edit", "more"]) => {
5 let enable = true;
6 if (element) {
7 const readonly = element.getAttribute("data-readonly");
8 if (typeof readonly === "string") {
9 enable = readonly === "false";
10 } else {
11 return '<div class="protyle-icons"></div>';
12 }
13 }
14 if (actions.length === 3) {
15 return `<div class="protyle-icons">
16 <span aria-label="${window.siyuan.languages.refresh}" class="b3-tooltips__nw b3-tooltips protyle-icon protyle-icon--first protyle-action__reload"><svg><use xlink:href="#iconRefresh"></use></svg></span>
17 <span aria-label="${window.siyuan.languages.edit}" class="b3-tooltips__nw b3-tooltips protyle-icon protyle-action__edit${enable ? "" : " fn__none"}"><svg><use xlink:href="#iconEdit"></use></svg></span>
18 <span aria-label="${window.siyuan.languages.more}" class="b3-tooltips__nw b3-tooltips protyle-icon protyle-action__menu protyle-icon--last"><svg><use xlink:href="#iconMore"></use></svg></span>
19</div>`;
20 } else {
21 return `<div class="protyle-icons">
22 <span aria-label="${window.siyuan.languages.edit}" class="b3-tooltips__nw b3-tooltips protyle-icon protyle-icon--first protyle-action__edit${enable ? "" : " fn__none"}"><svg><use xlink:href="#iconEdit"></use></svg></span>
23 <span aria-label="${window.siyuan.languages.more}" class="b3-tooltips__nw b3-tooltips protyle-icon protyle-action__menu protyle-icon--last${enable ? "" : " protyle-icon--first"}"><svg><use xlink:href="#iconMore"></use></svg></span>
24</div>`;
25 }
26};
27
28export const genRenderFrame = (renderElement: Element) => {
29 if (renderElement.querySelector(".protyle-cursor")) {
30 return;
31 }
32 const type = renderElement.getAttribute("data-type");
33 if (type === "NodeBlockQueryEmbed") {
34 renderElement.insertAdjacentHTML("afterbegin", `<div class="protyle-icons${isInEmbedBlock(renderElement) ? " fn__none" : ""}">
35 <span aria-label="${window.siyuan.languages.refresh}" class="b3-tooltips__nw b3-tooltips protyle-icon protyle-action__reload protyle-icon--first"><svg class="fn__rotate"><use xlink:href="#iconRefresh"></use></svg></span>
36 <span aria-label="${window.siyuan.languages.update} SQL" class="b3-tooltips__nw b3-tooltips protyle-icon protyle-action__edit"><svg><use xlink:href="#iconEdit"></use></svg></span>
37 <span aria-label="${window.siyuan.languages.more}" class="b3-tooltips__nw b3-tooltips protyle-icon protyle-action__menu protyle-icon--last"><svg><use xlink:href="#iconMore"></use></svg></span>
38</div><div class="protyle-cursor">${Constants.ZWSP}</div>`);
39 } else if (type === "NodeMathBlock" || renderElement.getAttribute("data-subtype") === "math") {
40 renderElement.firstElementChild.innerHTML = `<span></span><span class="protyle-cursor">${Constants.ZWSP}</span>`;
41 }
42};
43
44export const processClonePHElement = (item: Element) => {
45 item.querySelectorAll("protyle-html").forEach((phElement) => {
46 phElement.setAttribute("data-content", Lute.UnEscapeHTMLStr(phElement.getAttribute("data-content")));
47 });
48 return item;
49};