/// #if !MOBILE import {getAllDocks} from "./getAll"; import {updateHotkeyTip} from "../protyle/util/compatibility"; import {exportLayout, getDockByType, resizeTabs} from "./util"; import {hasClosestByClassName} from "../protyle/util/hasClosest"; import {fetchPost} from "../util/fetch"; import {mountHelp} from "../util/mount"; /// #if !BROWSER import {getCurrentWindow} from "@electron/remote"; /// #endif /// #endif export const initStatus = () => { /// #if !MOBILE const allDocks = getAllDocks(); let menuHTML = ""; allDocks.forEach(item => { menuHTML += ``; }); document.getElementById("status").innerHTML = `
${menuHTML}
`; const dockElement = document.getElementById("barDock"); dockElement.addEventListener("mousemove", () => { dockElement.querySelector(".b3-menu").classList.remove("fn__none"); }); dockElement.addEventListener("mouseleave", () => { dockElement.querySelector(".b3-menu").classList.add("fn__none"); }); /// #if !BROWSER document.querySelector("#barDebug").classList.remove("fn__none"); /// #endif document.querySelector("#status").addEventListener("click", (event) => { let target = event.target as HTMLElement; while (target.id !== "status") { if (target.id === "barDock") { const useElement = target.firstElementChild.firstElementChild; const dockIsShow = useElement.getAttribute("xlink:href") === "#iconHideDock"; if (dockIsShow) { useElement.setAttribute("xlink:href", "#iconDock"); target.setAttribute("aria-label", window.siyuan.languages.showDock); } else { useElement.setAttribute("xlink:href", "#iconHideDock"); target.setAttribute("aria-label", window.siyuan.languages.hideDock); } document.querySelectorAll(".dock").forEach(item => { if (dockIsShow) { if (item.querySelector(".dock__item")) { item.classList.add("fn__none"); } } else { if (item.querySelector(".dock__item")) { item.classList.remove("fn__none"); } } }); resizeTabs(); target.querySelector(".b3-menu").classList.add("fn__none"); event.stopPropagation(); break; } else if (target.classList.contains("b3-menu__item")) { const type = target.getAttribute("data-type") as TDockType; getDockByType(type).toggleModel(type); if (type === "file" && getSelection().rangeCount > 0) { const range = getSelection().getRangeAt(0); const wysiwygElement = hasClosestByClassName(range.startContainer, "protyle-wysiwyg", true); if (wysiwygElement) { wysiwygElement.blur(); } } target.parentElement.classList.add("fn__none"); event.stopPropagation(); break; } else if (target.id === "barLock") { exportLayout(false, () => { fetchPost("/api/system/logoutAuth", {}, () => { window.location.href = "/"; }); }); event.stopPropagation(); break; } else if (target.id === "barHelp") { mountHelp(); event.stopPropagation(); break; } else if (target.id === "barDebug") { /// #if !BROWSER getCurrentWindow().webContents.openDevTools({mode: "bottom"}); /// #endif event.stopPropagation(); break; } else if (target.id === "barFeedback") { if ("zh_CN" === window.siyuan.config.lang) { window.open("https://ld246.com/article/1649901726096"); } else { window.open("https://github.com/siyuan-note/siyuan/issues"); } event.stopPropagation(); break; } target = target.parentElement; } }); if (window.siyuan.config.appearance.hideStatusBar) { document.getElementById("status").classList.add("fn__none"); } /// #endif }; export const countSelectWord = (range: Range) => { /// #if !MOBILE if (document.getElementById("status").classList.contains("fn__none")) { return; } const selectText = range.toString(); if (selectText) { fetchPost("/api/block/getContentWordCount", {"content": range.toString()}, (response) => { renderStatusbarCounter(response.data); }); } else { document.querySelector("#status .status__counter").innerHTML = ""; } /// #endif }; export const countBlockWord = (ids: string[]) => { /// #if !MOBILE if (document.getElementById("status").classList.contains("fn__none")) { return; } if (ids.length > 0) { fetchPost("/api/block/getBlocksWordCount", {ids}, (response) => { renderStatusbarCounter(response.data); }); } else { document.querySelector("#status .status__counter").innerHTML = ""; } /// #endif }; export const renderStatusbarCounter = (stat: { runeCount: number, wordCount: number, linkCount: number, imageCount: number, refCount: number }) => { let html = `${window.siyuan.languages.runeCount} ${stat.runeCount} ${window.siyuan.languages.wordCount} ${stat.wordCount}`; if (0 < stat.linkCount) { html += `${window.siyuan.languages.link} ${stat.linkCount}`; } if (0 < stat.imageCount) { html += `${window.siyuan.languages.image} ${stat.imageCount}`; } if (0 < stat.refCount) { html += `${window.siyuan.languages.ref} ${stat.refCount}`; } document.querySelector("#status .status__counter").innerHTML = html; };