From 21823e11d861a7b5f67a24bcf5ac45a1be06b916 Mon Sep 17 00:00:00 2001 From: Daniel <845765@qq.com> Date: Tue, 30 Apr 2024 08:58:20 +0800 Subject: [PATCH] :art: Clean code --- app/electron/main.js | 4 ++-- app/src/boot/globalEvent/commandPanel.ts | 6 ++--- app/src/boot/onGetConfig.ts | 4 ++-- app/src/config/about.ts | 2 +- app/src/config/editor.ts | 2 +- app/src/editor/util.ts | 2 +- app/src/history/history.ts | 28 ++++++++++++------------ app/src/menus/onGetnotebookconf.ts | 2 +- app/src/protyle/header/Background.ts | 20 ++++++++--------- app/src/protyle/ui/initUI.ts | 2 +- app/src/protyle/util/hotKey.ts | 4 ++-- app/src/protyle/wysiwyg/input.ts | 2 +- 12 files changed, 39 insertions(+), 39 deletions(-) diff --git a/app/electron/main.js b/app/electron/main.js index 203b864b2..66a1c1863 100644 --- a/app/electron/main.js +++ b/app/electron/main.js @@ -231,9 +231,9 @@ const writeLog = (out) => { }; let openAsHidden = false; -isOpenAsHidden = function () { +const isOpenAsHidden = function () { return 1 === workspaces.length && openAsHidden; -} +}; const initMainWindow = () => { let windowStateInitialized = true; diff --git a/app/src/boot/globalEvent/commandPanel.ts b/app/src/boot/globalEvent/commandPanel.ts index 387340eb9..db1084870 100644 --- a/app/src/boot/globalEvent/commandPanel.ts +++ b/app/src/boot/globalEvent/commandPanel.ts @@ -19,7 +19,7 @@ import {Files} from "../../layout/dock/Files"; /// #endif export const commandPanel = (app: App) => { - const range = getSelection().getRangeAt(0) + const range = getSelection().getRangeAt(0); const dialog = new Dialog({ width: isMobile() ? "92vw" : "80vw", height: isMobile() ? "80vh" : "70vh", @@ -83,7 +83,7 @@ export const commandPanel = (app: App) => { inputElement.focus(); /// #if !MOBILE listElement.addEventListener("click", (event: KeyboardEvent) => { - const liElement = hasClosestByClassName(event.target as HTMLElement, "b3-list-item") + const liElement = hasClosestByClassName(event.target as HTMLElement, "b3-list-item"); if (liElement) { const command = liElement.getAttribute("data-command"); if (command) { @@ -93,7 +93,7 @@ export const commandPanel = (app: App) => { event.stopPropagation(); } } - }) + }); /// #endif inputElement.addEventListener("keydown", (event: KeyboardEvent) => { event.stopPropagation(); diff --git a/app/src/boot/onGetConfig.ts b/app/src/boot/onGetConfig.ts index 57e0cbad4..fbb3a1f82 100644 --- a/app/src/boot/onGetConfig.ts +++ b/app/src/boot/onGetConfig.ts @@ -34,7 +34,7 @@ const matchKeymap = (keymap: Config.IKeys, key1: "general" | "editor", key2?: "g if (!window.siyuan.config.keymap[key1]) { ipcRenderer.send(Constants.SIYUAN_CMD, { cmd: "writeLog", - msg: 'window.siyuan.config.keymap.general is not found' + msg: "window.siyuan.config.keymap.general is not found" }); window.siyuan.config.keymap[key1] = keymap as Config.IKeymapGeneral; return false; @@ -43,7 +43,7 @@ const matchKeymap = (keymap: Config.IKeys, key1: "general" | "editor", key2?: "g if (!window.siyuan.config.keymap[key1]) { ipcRenderer.send(Constants.SIYUAN_CMD, { cmd: "writeLog", - msg: 'window.siyuan.config.keymap.editor is not found' + msg: "window.siyuan.config.keymap.editor is not found" }); window.siyuan.config.keymap[key1] = JSON.parse(JSON.stringify(Constants.SIYUAN_KEYMAP.editor)); return false; diff --git a/app/src/config/about.ts b/app/src/config/about.ts index cfe0444f0..67ed8a807 100644 --- a/app/src/config/about.ts +++ b/app/src/config/about.ts @@ -352,7 +352,7 @@ export const about = { /// #if !BROWSER const autoLaunchElement = about.element.querySelector("#autoLaunch") as HTMLInputElement; autoLaunchElement.addEventListener("change", () => { - const autoLaunchMode = parseInt(autoLaunchElement.value) + const autoLaunchMode = parseInt(autoLaunchElement.value); fetchPost("/api/system/setAutoLaunch", {autoLaunch: autoLaunchMode}, () => { window.siyuan.config.system.autoLaunch2 = autoLaunchMode; ipcRenderer.send(Constants.SIYUAN_AUTO_LAUNCH, { diff --git a/app/src/config/editor.ts b/app/src/config/editor.ts index 88e774ded..2b0a9d29b 100644 --- a/app/src/config/editor.ts +++ b/app/src/config/editor.ts @@ -336,7 +336,7 @@ export const editor = { (editor.element.querySelector("#dynamicLoadBlocks") as HTMLInputElement).value = "1024"; } - let markdown = { + const markdown = { inlineSup: (editor.element.querySelector("#editorMarkdownInlineSup") as HTMLInputElement).checked, inlineSub: (editor.element.querySelector("#editorMarkdownInlineSub") as HTMLInputElement).checked, inlineTag: (editor.element.querySelector("#editorMarkdownInlineTag") as HTMLInputElement).checked, diff --git a/app/src/editor/util.ts b/app/src/editor/util.ts index e4ab2f499..4a1366371 100644 --- a/app/src/editor/util.ts +++ b/app/src/editor/util.ts @@ -750,4 +750,4 @@ export const openLink = (protyle: IProtyle, aLink: string, event?: MouseEvent, c /// #endif } /// #endif -} +}; diff --git a/app/src/history/history.ts b/app/src/history/history.ts index f239b39ae..0dff8cd62 100644 --- a/app/src/history/history.ts +++ b/app/src/history/history.ts @@ -42,25 +42,25 @@ const renderDoc = (element: HTMLElement, currentPage: number) => { if (window.siyuan.storage[Constants.LOCAL_HISTORY].type !== 2) { opElement.value = "all"; } - opElement.querySelector('option[value="clean"]').classList.remove("fn__none") - opElement.querySelector('option[value="update"]').classList.remove("fn__none") - opElement.querySelector('option[value="delete"]').classList.add("fn__none") - opElement.querySelector('option[value="format"]').classList.add("fn__none") - opElement.querySelector('option[value="sync"]').classList.remove("fn__none") - opElement.querySelector('option[value="replace"]').classList.add("fn__none") - opElement.querySelector('option[value="outline"]').classList.add("fn__none") + opElement.querySelector('option[value="clean"]').classList.remove("fn__none"); + opElement.querySelector('option[value="update"]').classList.remove("fn__none"); + opElement.querySelector('option[value="delete"]').classList.add("fn__none"); + opElement.querySelector('option[value="format"]').classList.add("fn__none"); + opElement.querySelector('option[value="sync"]').classList.remove("fn__none"); + opElement.querySelector('option[value="replace"]').classList.add("fn__none"); + opElement.querySelector('option[value="outline"]').classList.add("fn__none"); } else { notebookElement.removeAttribute("disabled"); if (window.siyuan.storage[Constants.LOCAL_HISTORY].type === 2) { opElement.value = "all"; } - opElement.querySelector('option[value="clean"]').classList.add("fn__none") - opElement.querySelector('option[value="update"]').classList.remove("fn__none") - opElement.querySelector('option[value="delete"]').classList.remove("fn__none") - opElement.querySelector('option[value="format"]').classList.remove("fn__none") - opElement.querySelector('option[value="sync"]').classList.remove("fn__none") - opElement.querySelector('option[value="replace"]').classList.remove("fn__none") - opElement.querySelector('option[value="outline"]').classList.remove("fn__none") + opElement.querySelector('option[value="clean"]').classList.add("fn__none"); + opElement.querySelector('option[value="update"]').classList.remove("fn__none"); + opElement.querySelector('option[value="delete"]').classList.remove("fn__none"); + opElement.querySelector('option[value="format"]').classList.remove("fn__none"); + opElement.querySelector('option[value="sync"]').classList.remove("fn__none"); + opElement.querySelector('option[value="replace"]').classList.remove("fn__none"); + opElement.querySelector('option[value="outline"]').classList.remove("fn__none"); } window.siyuan.storage[Constants.LOCAL_HISTORY] = { notebookId: notebookElement.value, diff --git a/app/src/menus/onGetnotebookconf.ts b/app/src/menus/onGetnotebookconf.ts index a7de89d44..85d255f02 100644 --- a/app/src/menus/onGetnotebookconf.ts +++ b/app/src/menus/onGetnotebookconf.ts @@ -33,7 +33,7 @@ export const genNotebookOption = (id: string, notebookId?: string) => { html += ``; }); return html; -} +}; export const onGetnotebookconf = (data: INotebookConf) => { const titleHTML = `
${escapeHtml(data.name)} diff --git a/app/src/protyle/header/Background.ts b/app/src/protyle/header/Background.ts index 34078c13f..6ec8267d4 100644 --- a/app/src/protyle/header/Background.ts +++ b/app/src/protyle/header/Background.ts @@ -452,20 +452,20 @@ export class Background { html += `
${item}
`; }); this.tagsElement.innerHTML = `${html} -` - this.tagsElement.classList.remove("fn__none") - this.actionElements[0].classList.add("fn__none") +`; + this.tagsElement.classList.remove("fn__none"); + this.actionElements[0].classList.add("fn__none"); } else { - this.tagsElement.classList.add("fn__none") - this.actionElements[0].classList.remove("fn__none") + this.tagsElement.classList.add("fn__none"); + this.actionElements[0].classList.remove("fn__none"); } if (icon) { this.iconElement.classList.remove("fn__none"); this.iconElement.innerHTML = unicode2Emoji(icon); - this.actionElements[1].classList.add("fn__none") + this.actionElements[1].classList.add("fn__none"); } else { - this.actionElements[1].classList.remove("fn__none") + this.actionElements[1].classList.remove("fn__none"); this.iconElement.classList.add("fn__none"); } @@ -483,16 +483,16 @@ export class Background { this.imgElement.setAttribute("src", this.transparentData); this.element.querySelector('[data-type="position"]').classList.add("fn__none"); } - this.actionElements[2].classList.add("fn__none") + this.actionElements[2].classList.add("fn__none"); this.imgElement.parentElement.classList.remove("fn__none"); this.iconElement.style.marginTop = ""; /// #if MOBILE // 移动端键盘弹起和点击加号需保持滚动高度一致 - this.imgElement.style.height = "200px" + this.imgElement.style.height = "200px"; /// #endif } else { this.imgElement.parentElement.classList.add("fn__none"); - this.actionElements[2].classList.remove("fn__none") + this.actionElements[2].classList.remove("fn__none"); this.iconElement.style.marginTop = "8px"; } } diff --git a/app/src/protyle/ui/initUI.ts b/app/src/protyle/ui/initUI.ts index 91dfc907a..ce3ad7a75 100644 --- a/app/src/protyle/ui/initUI.ts +++ b/app/src/protyle/ui/initUI.ts @@ -10,7 +10,7 @@ import {lineNumberRender} from "../render/highlightRender"; export const initUI = (protyle: IProtyle) => { protyle.contentElement = document.createElement("div"); protyle.contentElement.className = "protyle-content"; - protyle.contentElement.innerHTML = `
` + protyle.contentElement.innerHTML = "
"; if (protyle.options.render.background) { protyle.contentElement.firstElementChild.appendChild(protyle.background.element); } diff --git a/app/src/protyle/util/hotKey.ts b/app/src/protyle/util/hotKey.ts index 8e020ee67..c4c38d24a 100644 --- a/app/src/protyle/util/hotKey.ts +++ b/app/src/protyle/util/hotKey.ts @@ -48,9 +48,9 @@ const replaceDirect = (hotKey: string, keyCode: string) => { if (item === Constants.ZWSP) { hotKeys[index] = keyCode; } - }) + }); return hotKeys; -} +}; export const matchHotKey = (hotKey: string, event: KeyboardEvent) => { if (!hotKey) { diff --git a/app/src/protyle/wysiwyg/input.ts b/app/src/protyle/wysiwyg/input.ts index 95927c6d7..919a708f2 100644 --- a/app/src/protyle/wysiwyg/input.ts +++ b/app/src/protyle/wysiwyg/input.ts @@ -224,7 +224,7 @@ export const input = async (protyle: IProtyle, blockElement: HTMLElement, range: mathRender(realElement); if (index === tempElement.content.childElementCount - 1) { // https://github.com/siyuan-note/siyuan/issues/11156 - const currentWbrElement = blockElement.querySelector("wbr") + const currentWbrElement = blockElement.querySelector("wbr"); if (currentWbrElement && currentWbrElement.parentElement.tagName === "SPAN" && currentWbrElement.parentElement.innerHTML === "") { const types = currentWbrElement.parentElement.getAttribute("data-type") || ""; if (types.includes("sup") || types.includes("u") || types.includes("sub")) {