From 5003a9fd787c9581c39cfce75429485bd9659d90 Mon Sep 17 00:00:00 2001 From: Tron Date: Tue, 25 Nov 2025 09:37:14 +0800 Subject: [PATCH] =?UTF-8?q?=F0=9F=8E=A8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/src/protyle/render/util.ts | 4 +- app/src/protyle/toolbar/index.ts | 98 ++++++++++----------- app/src/protyle/wysiwyg/index.ts | 142 +++++++++++++++---------------- 3 files changed, 122 insertions(+), 122 deletions(-) diff --git a/app/src/protyle/render/util.ts b/app/src/protyle/render/util.ts index 51f91702e..a2ac71f86 100644 --- a/app/src/protyle/render/util.ts +++ b/app/src/protyle/render/util.ts @@ -1,5 +1,5 @@ -import {isInEmbedBlock} from "../util/hasClosest"; -import {Constants} from "../../constants"; +import { isInEmbedBlock } from "../util/hasClosest"; +import { Constants } from "../../constants"; export const genIconHTML = (element?: false | HTMLElement, actions = ["edit", "more"]) => { let enable = true; diff --git a/app/src/protyle/toolbar/index.ts b/app/src/protyle/toolbar/index.ts index 284c98ce8..e5760216d 100644 --- a/app/src/protyle/toolbar/index.ts +++ b/app/src/protyle/toolbar/index.ts @@ -1,6 +1,6 @@ -import {Divider} from "./Divider"; -import {Font, hasSameTextStyle, setFontStyle} from "./Font"; -import {ToolbarItem} from "./ToolbarItem"; +import { Divider } from "./Divider"; +import { Font, hasSameTextStyle, setFontStyle } from "./Font"; +import { ToolbarItem } from "./ToolbarItem"; import { fixTableRange, focusBlock, @@ -12,40 +12,40 @@ import { setFirstNodeRange, setLastNodeRange } from "../util/selection"; -import {hasClosestBlock, hasClosestByAttribute, hasClosestByClassName} from "../util/hasClosest"; -import {Link} from "./Link"; -import {setPosition} from "../../util/setPosition"; -import {transaction, updateTransaction} from "../wysiwyg/transaction"; -import {Constants} from "../../constants"; -import {copyPlainText, openByMobile, readClipboard, setStorageVal} from "../util/compatibility"; -import {upDownHint} from "../../util/upDownHint"; -import {highlightRender} from "../render/highlightRender"; -import {getContenteditableElement, hasNextSibling, hasPreviousSibling} from "../wysiwyg/getBlock"; -import {processRender} from "../util/processCode"; -import {BlockRef} from "./BlockRef"; -import {hintRenderTemplate, hintRenderWidget} from "../hint/extend"; -import {blockRender} from "../render/blockRender"; +import { hasClosestBlock, hasClosestByAttribute, hasClosestByClassName } from "../util/hasClosest"; +import { Link } from "./Link"; +import { setPosition } from "../../util/setPosition"; +import { transaction, updateTransaction } from "../wysiwyg/transaction"; +import { Constants } from "../../constants"; +import { copyPlainText, openByMobile, readClipboard, setStorageVal } from "../util/compatibility"; +import { upDownHint } from "../../util/upDownHint"; +import { highlightRender } from "../render/highlightRender"; +import { getContenteditableElement, hasNextSibling, hasPreviousSibling } from "../wysiwyg/getBlock"; +import { processRender } from "../util/processCode"; +import { BlockRef } from "./BlockRef"; +import { hintRenderTemplate, hintRenderWidget } from "../hint/extend"; +import { blockRender } from "../render/blockRender"; /// #if !BROWSER -import {openBy} from "../../editor/util"; +import { openBy } from "../../editor/util"; /// #endif -import {fetchPost} from "../../util/fetch"; -import {isArrayEqual, isMobile} from "../../util/functions"; +import { fetchPost } from "../../util/fetch"; +import { isArrayEqual, isMobile } from "../../util/functions"; import * as dayjs from "dayjs"; -import {insertEmptyBlock} from "../../block/util"; -import {matchHotKey} from "../util/hotKey"; -import {hideElements} from "../ui/hideElements"; -import {electronUndo} from "../undo"; -import {previewTemplate, toolbarKeyToMenu} from "./util"; -import {hideMessage, showMessage} from "../../dialog/message"; -import {InlineMath} from "./InlineMath"; -import {InlineMemo} from "./InlineMemo"; -import {mathRender} from "../render/mathRender"; -import {linkMenu} from "../../menus/protyle"; -import {addScript} from "../util/addScript"; -import {confirmDialog} from "../../dialog/confirmDialog"; -import {paste, pasteAsPlainText, pasteEscaped} from "../util/paste"; -import {escapeHtml} from "../../util/escape"; -import {resizeSide} from "../../history/resizeSide"; +import { insertEmptyBlock } from "../../block/util"; +import { matchHotKey } from "../util/hotKey"; +import { hideElements } from "../ui/hideElements"; +import { electronUndo } from "../undo"; +import { previewTemplate, toolbarKeyToMenu } from "./util"; +import { hideMessage, showMessage } from "../../dialog/message"; +import { InlineMath } from "./InlineMath"; +import { InlineMemo } from "./InlineMemo"; +import { mathRender } from "../render/mathRender"; +import { linkMenu } from "../../menus/protyle"; +import { addScript } from "../util/addScript"; +import { confirmDialog } from "../../dialog/confirmDialog"; +import { paste, pasteAsPlainText, pasteEscaped } from "../util/paste"; +import { escapeHtml } from "../../util/escape"; +import { resizeSide } from "../../history/resizeSide"; export class Toolbar { public element: HTMLElement; @@ -309,12 +309,12 @@ export class Toolbar { const startPreviousSibling = hasPreviousSibling(this.range.startContainer); const endNextSibling = hasNextSibling(this.range.endContainer); if (( - this.range.startOffset !== 0 || - // https://github.com/siyuan-note/siyuan/issues/14869 - (this.range.startOffset === 0 && startPreviousSibling && - (startPreviousSibling.nodeType === 3 || (startPreviousSibling as HTMLElement).tagName === "BR") && - this.range.startContainer.previousSibling.parentElement === this.range.startContainer.parentElement) - ) && ( + this.range.startOffset !== 0 || + // https://github.com/siyuan-note/siyuan/issues/14869 + (this.range.startOffset === 0 && startPreviousSibling && + (startPreviousSibling.nodeType === 3 || (startPreviousSibling as HTMLElement).tagName === "BR") && + this.range.startContainer.previousSibling.parentElement === this.range.startContainer.parentElement) + ) && ( this.range.endOffset !== this.range.endContainer.textContent.length || // https://github.com/siyuan-note/siyuan/issues/14869#issuecomment-2911553387 ( @@ -1038,9 +1038,9 @@ export class Toolbar { } const clonedSvg = svgElement.cloneNode(true) as SVGSVGElement; const bbox = svgElement.getBBox(); - clonedSvg.setAttribute("viewBox", `${bbox.x-20} ${bbox.y-20} ${bbox.width+40} ${bbox.height+40}`); - clonedSvg.setAttribute("width", String(bbox.width+40)); - clonedSvg.setAttribute("height", String(bbox.height+40)); + clonedSvg.setAttribute("viewBox", `${bbox.x - 20} ${bbox.y - 20} ${bbox.width + 40} ${bbox.height + 40}`); + clonedSvg.setAttribute("width", String(bbox.width + 40)); + clonedSvg.setAttribute("height", String(bbox.height + 40)); clonedSvg.setAttribute("xmlns", "http://www.w3.org/2000/svg"); clonedSvg.setAttribute("xmlns:xlink", "http://www.w3.org/1999/xlink"); @@ -1348,7 +1348,7 @@ export class Toolbar { let html = `
${window.siyuan.languages.clear}
`; let hljsLanguages = Constants.ALIAS_CODE_LANGUAGES.concat(window.hljs?.listLanguages() ?? []).sort(); - const eventDetail = {languages: hljsLanguages, type: "init", listElement}; + const eventDetail = { languages: hljsLanguages, type: "init", listElement }; if (protyle.app && protyle.app.plugins) { protyle.app.plugins.forEach((plugin: any) => { plugin.eventBus.emit("code-language-update", eventDetail); @@ -1422,7 +1422,7 @@ export class Toolbar { } } - const eventDetail = {languages: value ? matchLanguages : hljsLanguages, type: "match", value, listElement}; + const eventDetail = { languages: value ? matchLanguages : hljsLanguages, type: "match", value, listElement }; if (protyle.app && protyle.app.plugins) { protyle.app.plugins.forEach((plugin: any) => { plugin.eventBus.emit("code-language-update", eventDetail); @@ -1589,7 +1589,7 @@ export class Toolbar { /// #endif if (iconElement && iconElement.getAttribute("data-type") === "remove") { confirmDialog(window.siyuan.languages.remove, window.siyuan.languages.confirmDelete + "?", () => { - fetchPost("/api/search/removeTemplate", {path: iconElement.parentElement.getAttribute("data-value")}, () => { + fetchPost("/api/search/removeTemplate", { path: iconElement.parentElement.getAttribute("data-value") }, () => { if (iconElement.parentElement.parentElement.childElementCount === 1) { iconElement.parentElement.parentElement.innerHTML = `
  • ${window.siyuan.languages.emptyContent}
  • `; previewTemplate("", previewElement, protyle.block.parentID); @@ -1613,13 +1613,13 @@ export class Toolbar { } const previousElement = hasClosestByAttribute(target, "data-type", "previous"); if (previousElement) { - inputElement.dispatchEvent(new KeyboardEvent("keydown", {key: "ArrowUp"})); + inputElement.dispatchEvent(new KeyboardEvent("keydown", { key: "ArrowUp" })); event.stopPropagation(); return; } const nextElement = hasClosestByAttribute(target, "data-type", "next"); if (nextElement) { - inputElement.dispatchEvent(new KeyboardEvent("keydown", {key: "ArrowDown"})); + inputElement.dispatchEvent(new KeyboardEvent("keydown", { key: "ArrowDown" })); event.stopPropagation(); return; } @@ -1791,7 +1791,7 @@ ${item.name} } else { try { const text = await readClipboard(); - paste(protyle, Object.assign(text, {target: nodeElement as HTMLElement})); + paste(protyle, Object.assign(text, { target: nodeElement as HTMLElement })); } catch (e) { console.log(e); } diff --git a/app/src/protyle/wysiwyg/index.ts b/app/src/protyle/wysiwyg/index.ts index e31ba33b7..b6232537a 100644 --- a/app/src/protyle/wysiwyg/index.ts +++ b/app/src/protyle/wysiwyg/index.ts @@ -1,4 +1,4 @@ -import {enableLuteMarkdownSyntax, getTextStar, paste, restoreLuteMarkdownSyntax} from "../util/paste"; +import { enableLuteMarkdownSyntax, getTextStar, paste, restoreLuteMarkdownSyntax } from "../util/paste"; import { hasClosestBlock, hasClosestByAttribute, @@ -18,9 +18,9 @@ import { setInsertWbrHTML, setLastNodeRange, } from "../util/selection"; -import {Constants} from "../../constants"; -import {isMobile} from "../../util/functions"; -import {previewDocImage} from "../preview/image"; +import { Constants } from "../../constants"; +import { isMobile } from "../../util/functions"; +import { previewDocImage } from "../preview/image"; import { contentMenu, enterBack, @@ -34,8 +34,8 @@ import { zoomOut } from "../../menus/protyle"; import * as dayjs from "dayjs"; -import {dropEvent} from "../util/editorCommonEvent"; -import {input} from "./input"; +import { dropEvent } from "../util/editorCommonEvent"; +import { input } from "./input"; import { getContenteditableElement, getNextBlock, @@ -45,43 +45,43 @@ import { isEndOfBlock, isNotEditBlock } from "./getBlock"; -import {transaction, updateTransaction} from "./transaction"; -import {hideElements} from "../ui/hideElements"; +import { transaction, updateTransaction } from "./transaction"; +import { hideElements } from "../ui/hideElements"; /// #if !BROWSER -import {ipcRenderer} from "electron"; +import { ipcRenderer } from "electron"; /// #endif -import {getEnableHTML, removeEmbed} from "./removeEmbed"; -import {keydown} from "./keydown"; -import {openMobileFileById} from "../../mobile/editor"; -import {removeBlock} from "./remove"; -import {highlightRender} from "../render/highlightRender"; -import {openAttr} from "../../menus/commonMenuItem"; -import {blockRender} from "../render/blockRender"; +import { getEnableHTML, removeEmbed } from "./removeEmbed"; +import { keydown } from "./keydown"; +import { openMobileFileById } from "../../mobile/editor"; +import { removeBlock } from "./remove"; +import { highlightRender } from "../render/highlightRender"; +import { openAttr } from "../../menus/commonMenuItem"; +import { blockRender } from "../render/blockRender"; /// #if !MOBILE -import {getAllModels} from "../../layout/getAll"; -import {pushBack} from "../../util/backForward"; -import {openFileById} from "../../editor/util"; -import {openGlobalSearch} from "../../search/util"; +import { getAllModels } from "../../layout/getAll"; +import { pushBack } from "../../util/backForward"; +import { openFileById } from "../../editor/util"; +import { openGlobalSearch } from "../../search/util"; /// #else -import {popSearch} from "../../mobile/menu/search"; +import { popSearch } from "../../mobile/menu/search"; /// #endif -import {BlockPanel} from "../../block/Panel"; -import {copyPlainText, isInIOS, isMac, isOnlyMeta, readClipboard, encodeBase64} from "../util/compatibility"; -import {MenuItem} from "../../menus/Menu"; -import {fetchPost, fetchSyncPost} from "../../util/fetch"; -import {onGet} from "../util/onGet"; -import {clearTableCell, isIncludeCell, setTableAlign} from "../util/table"; -import {countBlockWord, countSelectWord} from "../../layout/status"; -import {showMessage} from "../../dialog/message"; -import {getBacklinkHeadingMore, loadBreadcrumb} from "./renderBacklink"; -import {removeSearchMark} from "../toolbar/util"; -import {activeBlur} from "../../mobile/util/keyboardToolbar"; -import {commonClick} from "./commonClick"; -import {avClick, avContextmenu, updateAVName} from "../render/av/action"; -import {selectRow, stickyRow} from "../render/av/row"; -import {showColMenu} from "../render/av/col"; -import {openViewMenu} from "../render/av/view"; -import {checkFold} from "../../util/noRelyPCFunction"; +import { BlockPanel } from "../../block/Panel"; +import { copyPlainText, isInIOS, isMac, isOnlyMeta, readClipboard, encodeBase64 } from "../util/compatibility"; +import { MenuItem } from "../../menus/Menu"; +import { fetchPost, fetchSyncPost } from "../../util/fetch"; +import { onGet } from "../util/onGet"; +import { clearTableCell, isIncludeCell, setTableAlign } from "../util/table"; +import { countBlockWord, countSelectWord } from "../../layout/status"; +import { showMessage } from "../../dialog/message"; +import { getBacklinkHeadingMore, loadBreadcrumb } from "./renderBacklink"; +import { removeSearchMark } from "../toolbar/util"; +import { activeBlur } from "../../mobile/util/keyboardToolbar"; +import { commonClick } from "./commonClick"; +import { avClick, avContextmenu, updateAVName } from "../render/av/action"; +import { selectRow, stickyRow } from "../render/av/row"; +import { showColMenu } from "../render/av/col"; +import { openViewMenu } from "../render/av/view"; +import { checkFold } from "../../util/noRelyPCFunction"; import { addDragFill, dragFillCellsValue, @@ -91,16 +91,16 @@ import { getTypeByCellElement, updateCellsValue } from "../render/av/cell"; -import {openEmojiPanel, unicode2Emoji} from "../../emoji"; -import {openLink} from "../../editor/openLink"; -import {mathRender} from "../render/mathRender"; -import {editAssetItem} from "../render/av/asset"; -import {img3115} from "../../boot/compatibleVersion"; -import {globalClickHideMenu} from "../../boot/globalEvent/click"; -import {hideTooltip} from "../../dialog/tooltip"; -import {openGalleryItemMenu} from "../render/av/gallery/util"; -import {clearSelect} from "../util/clearSelect"; -import {chartRender} from "../render/chartRender"; +import { openEmojiPanel, unicode2Emoji } from "../../emoji"; +import { openLink } from "../../editor/openLink"; +import { mathRender } from "../render/mathRender"; +import { editAssetItem } from "../render/av/asset"; +import { img3115 } from "../../boot/compatibleVersion"; +import { globalClickHideMenu } from "../../boot/globalEvent/click"; +import { hideTooltip } from "../../dialog/tooltip"; +import { openGalleryItemMenu } from "../render/av/gallery/util"; +import { clearSelect } from "../util/clearSelect"; +import { chartRender } from "../render/chartRender"; export class WYSIWYG { public lastHTMLs: { [key: string]: string } = {}; @@ -1523,11 +1523,11 @@ export class WYSIWYG { const scrollTop = tableBlockElement.querySelector("table").scrollTop; tableBlockElement.querySelectorAll("th, td").forEach((item: HTMLTableCellElement) => { if (!item.classList.contains("fn__none") && isIncludeCell({ - tableSelectElement, - scrollLeft, - scrollTop, - item, - }) && + tableSelectElement, + scrollLeft, + scrollTop, + item, + }) && (selectCellElements.length === 0 || (selectCellElements.length > 0 && item.offsetTop === selectCellElements[0].offsetTop))) { selectCellElements.push(item); } @@ -1573,11 +1573,11 @@ export class WYSIWYG { const scrollTop = tableBlockElement.querySelector("table").scrollTop; tableBlockElement.querySelectorAll("th, td").forEach((item: HTMLTableCellElement) => { if (!item.classList.contains("fn__none") && isIncludeCell({ - tableSelectElement, - scrollLeft, - scrollTop, - item, - }) && + tableSelectElement, + scrollLeft, + scrollTop, + item, + }) && (selectCellElements.length === 0 || (selectCellElements.length > 0 && item.offsetTop === selectCellElements[0].offsetTop))) { selectCellElements.push(item); } @@ -1669,7 +1669,7 @@ export class WYSIWYG { } else if (tableBlockElement) { try { const text = await readClipboard(); - paste(protyle, Object.assign(text, {target: tableBlockElement as HTMLElement})); + paste(protyle, Object.assign(text, { target: tableBlockElement as HTMLElement })); } catch (e) { console.log(e); } @@ -1677,7 +1677,7 @@ export class WYSIWYG { } }).element); } - window.siyuan.menus.menu.popup({x: mouseUpEvent.clientX - 8, y: mouseUpEvent.clientY - 16}); + window.siyuan.menus.menu.popup({ x: mouseUpEvent.clientX - 8, y: mouseUpEvent.clientY - 16 }); } } @@ -2073,7 +2073,7 @@ export class WYSIWYG { // 多选块 hideElements(["util"], protyle); protyle.gutter.renderMenu(protyle, selectElements[0]); - window.siyuan.menus.menu.popup({x, y}); + window.siyuan.menus.menu.popup({ x, y }); return; } const target = event.detail.target || event.target as HTMLElement; @@ -2086,7 +2086,7 @@ export class WYSIWYG { /// #if MOBILE window.siyuan.menus.menu.fullscreen(); /// #else - window.siyuan.menus.menu.popup({x, y}); + window.siyuan.menus.menu.popup({ x, y }); /// #endif return false; } @@ -2160,7 +2160,7 @@ export class WYSIWYG { const avTabHeaderElement = hasClosestByClassName(target, "item"); if (nodeElement.classList.contains("av") && avTabHeaderElement) { if (avTabHeaderElement.classList.contains("item--focus")) { - openViewMenu({protyle, blockElement: nodeElement, element: avTabHeaderElement}); + openViewMenu({ protyle, blockElement: nodeElement, element: avTabHeaderElement }); } else { transaction(protyle, [{ action: "setAttrViewBlockView", @@ -2244,7 +2244,7 @@ export class WYSIWYG { ) { if ((!isMobile() || protyle.toolbar?.element.classList.contains("fn__none")) && !nodeElement.classList.contains("av")) { contentMenu(protyle, nodeElement); - window.siyuan.menus.menu.popup({x, y: y + 13, h: 26}); + window.siyuan.menus.menu.popup({ x, y: y + 13, h: 26 }); protyle.toolbar?.element.classList.add("fn__none"); if (nodeElement.classList.contains("table")) { nodeElement.querySelector(".table__select").removeAttribute("style"); @@ -2258,7 +2258,7 @@ export class WYSIWYG { /// #if MOBILE window.siyuan.menus.menu.fullscreen(); /// #else - window.siyuan.menus.menu.popup({x, y}); + window.siyuan.menus.menu.popup({ x, y }); /// #endif protyle.toolbar?.element.classList.add("fn__none"); } @@ -2329,7 +2329,7 @@ export class WYSIWYG { window.siyuan.menus.menu.remove(); } } - }, {passive: true}); + }, { passive: true }); this.element.addEventListener("paste", (event: ClipboardEvent & { target: HTMLElement }) => { // https://github.com/siyuan-note/siyuan/issues/11241 @@ -2658,7 +2658,7 @@ export class WYSIWYG { action, zoomIn }); - window.dispatchEvent(new KeyboardEvent("keydown", {key: "Escape"})); + window.dispatchEvent(new KeyboardEvent("keydown", { key: "Escape" })); } else if (event.altKey) { openFileById({ app: protyle.app, @@ -2768,7 +2768,7 @@ export class WYSIWYG { const tagElement = hasClosestByAttribute(event.target, "data-type", "tag"); if (tagElement && !event.altKey && !event.shiftKey && range.toString() === "") { /// #if !MOBILE - openGlobalSearch(protyle.app, `#${tagElement.textContent}#`, !ctrlIsPressed, {method: 0}); + openGlobalSearch(protyle.app, `#${tagElement.textContent}#`, !ctrlIsPressed, { method: 0 }); hideElements(["dialog"]); /// #else popSearch(protyle.app, { @@ -2822,7 +2822,7 @@ export class WYSIWYG { app: protyle.app, targetElement: embedItemElement, isBacklink: false, - refDefs: [{refID: embedId}] + refDefs: [{ refID: embedId }] })); } /// #endif @@ -2963,7 +2963,7 @@ export class WYSIWYG { } else if (event.shiftKey && !protyle.disabled) { openAttr(actionElement.parentElement, "bookmark", protyle); } else if (ctrlIsPressed) { - zoomOut({protyle, id: actionId}); + zoomOut({ protyle, id: actionId }); } else { if (actionElement.classList.contains("protyle-action--task")) { if (!protyle.disabled) { @@ -2982,7 +2982,7 @@ export class WYSIWYG { if (protyle.block.showAll && protyle.block.id === actionId) { enterBack(protyle, actionId); } else { - zoomOut({protyle, id: actionId}); + zoomOut({ protyle, id: actionId }); } } }