An open-source, privacy-first, self-hosted knowledge workspace where humans and AI agents work together 开源、隐私优先、自托管的知识工作空间,让人与智能体在此协作
TypeScript agentic-aiai-agentknowledge-baselocal-firstmarkdownmcpmindmapnote-takingself-hostedsiyuanworkspace
:recycle: constants.ts
Vanessa1cdbb0982363
diff --git a/app/src/block/Panel.ts b/app/src/block/Panel.tsindex 1f260c0498..86d6435dcb 100644--- a/app/src/block/Panel.ts+++ b/app/src/block/Panel.ts@@ -17,6 +17,7 @@ import {App} from "../index";import {resize} from "../protyle/util/resize";import {checkFold} from "../util/noRelyPCFunction";import {updateHotkeyAfterTip} from "../protyle/util/compatibility";+import {getTopBarHeight} from "../layout/topBar";export class BlockPanel {public element: HTMLElement;@@ -286,6 +287,7 @@ export class BlockPanel {}, {threshold: 0,});+ const topBarHeight = getTopBarHeight();this.element.querySelectorAll(".block__edit").forEach((item: HTMLElement, index) => {if (index < 5) {this.initProtyle(item, index === 0 ? () => {@@ -306,8 +308,8 @@ export class BlockPanel {}// 单击嵌入块悬浮窗的位置最好是覆盖嵌入块// 防止图片撑高后悬浮窗显示不下,只能设置高度- this.element.style.height = Math.min(window.innerHeight - Constants.SIZE_TOOLBAR_HEIGHT, targetRect.height + 42) + "px";- setPosition(this.element, targetRect.left, Math.max(top - 42, Constants.SIZE_TOOLBAR_HEIGHT), -42, 0);+ this.element.style.height = Math.min(window.innerHeight - topBarHeight, targetRect.height + 42) + "px";+ setPosition(this.element, targetRect.left, Math.max(top - 42, topBarHeight), -42, 0);} else if (this.targetElement) {if (this.targetElement.classList.contains("pdf__rect")) {targetRect = this.targetElement.firstElementChild.getBoundingClientRect();@@ -322,7 +324,7 @@ export class BlockPanel {setPosition(this.element, targetRect.left, targetRect.bottom + 4, targetRect.height + 12, 8);} else if (typeof this.x === "number" && typeof this.y === "number") {setPosition(this.element, this.x, this.y);- this.element.style.maxHeight = Math.floor(window.innerHeight - Math.max(this.y, Constants.SIZE_TOOLBAR_HEIGHT) - 12) + "px";+ this.element.style.maxHeight = Math.floor(window.innerHeight - Math.max(this.y, topBarHeight) - 12) + "px";}const elementRect = this.element.getBoundingClientRect();if (this.targetElement && !this.targetElement.classList.contains("protyle-wysiwyg__embed")) {diff --git a/app/src/constants.ts b/app/src/constants.tsindex 775c1836dd..000bb0b72b 100644--- a/app/src/constants.ts+++ b/app/src/constants.ts@@ -77,7 +77,6 @@ export abstract class Constants {public static readonly SIZE_SCROLL_TB: number = 24;public static readonly SIZE_SCROLL_STEP: number = 256;public static readonly SIZE_LINK_TEXT_MAX: number = 64;- public static readonly SIZE_TOOLBAR_HEIGHT: number = isMobile() ? 0 : 32;public static readonly SIZE_GET_MAX = 102400;public static readonly SIZE_UNDO = 64;public static readonly SIZE_TITLE = 512;@@ -858,38 +857,4 @@ export abstract class Constants {public static readonly SIYUAN_RENDER_CODE_LANGUAGES: string[] = ["abc", "plantuml", "mermaid", "flowchart", "echarts", "mindmap", "graphviz", "math"];- public static readonly PROTYLE_TOOLBAR: string[] = isMobile() ? [- "block-ref",- "a",- "|",- "text",- "strong",- "em",- "u",- "clear",- "|",- "code",- "tag",- "inline-math",- "inline-memo",- ] : [- "block-ref",- "a",- "|",- "text",- "strong",- "em",- "u",- "s",- "mark",- "sup",- "sub",- "clear",- "|",- "code",- "kbd",- "tag",- "inline-math",- "inline-memo",- ];}diff --git a/app/src/dialog/moveResize.ts b/app/src/dialog/moveResize.tsindex f89956bb63..52416e423c 100644--- a/app/src/dialog/moveResize.ts+++ b/app/src/dialog/moveResize.ts@@ -2,6 +2,7 @@ import {hasClosestByClassName} from "../protyle/util/hasClosest";import {Constants} from "../constants";import {hideAllElements} from "../protyle/ui/hideElements";import {setStorageVal} from "../protyle/util/compatibility";+import {getTopBarHeight} from "../layout/topBar";export const moveResize = (element: HTMLElement, afterCB?: (type: string) => void) => {element.addEventListener("mousedown", (event: MouseEvent & { target: HTMLElement }) => {@@ -47,6 +48,7 @@ export const moveResize = (element: HTMLElement, afterCB?: (type: string) => voidocumentSelf.ondragstart = () => false;let hasMove = false;+ const topBarHeight = getTopBarHeight();documentSelf.onmousemove = (moveEvent: MouseEvent) => {hasMove = true;if (!element) {@@ -62,18 +64,18 @@ export const moveResize = (element: HTMLElement, afterCB?: (type: string) => voipositionY = window.innerHeight - height;}element.style.left = Math.max(positionX, 0) + "px";- element.style.top = Math.max(positionY, Constants.SIZE_TOOLBAR_HEIGHT) + "px";+ element.style.top = Math.max(positionY, topBarHeight) + "px";} else {if (type === "r" &&moveEvent.clientX - x + width > 200 && moveEvent.clientX - x + width < window.innerWidth) {element.style.width = moveEvent.clientX - x + width + "px";element.style.maxWidth = "none";} else if (type === "d" &&- moveEvent.clientY - y + height > 160 && moveEvent.clientY - y + height < window.innerHeight - Constants.SIZE_TOOLBAR_HEIGHT) {+ moveEvent.clientY - y + height > 160 && moveEvent.clientY - y + height < window.innerHeight - topBarHeight) {element.style.height = moveEvent.clientY - y + height + "px";element.style.maxHeight = "";} else if (type === "t" &&- moveEvent.clientY > Constants.SIZE_TOOLBAR_HEIGHT && y - moveEvent.clientY + height > 160) {+ moveEvent.clientY > topBarHeight && y - moveEvent.clientY + height > 160) {element.style.top = moveEvent.clientY + "px";element.style.maxHeight = "";element.style.height = (y - moveEvent.clientY + height) + "px";@@ -84,14 +86,14 @@ export const moveResize = (element: HTMLElement, afterCB?: (type: string) => voielement.style.maxWidth = "none";} else if (type === "rd" &&moveEvent.clientX - x + width > 200 && moveEvent.clientX - x + width < window.innerWidth &&- moveEvent.clientY - y + height > 160 && moveEvent.clientY - y + height < window.innerHeight - Constants.SIZE_TOOLBAR_HEIGHT) {+ moveEvent.clientY - y + height > 160 && moveEvent.clientY - y + height < window.innerHeight - topBarHeight) {element.style.height = moveEvent.clientY - y + height + "px";element.style.maxHeight = "";element.style.maxWidth = "none";element.style.width = moveEvent.clientX - x + width + "px";} else if (type === "rt" &&moveEvent.clientX - x + width > 200 && moveEvent.clientX - x + width < window.innerWidth &&- moveEvent.clientY > Constants.SIZE_TOOLBAR_HEIGHT && y - moveEvent.clientY + height > 160) {+ moveEvent.clientY > topBarHeight && y - moveEvent.clientY + height > 160) {element.style.width = moveEvent.clientX - x + width + "px";element.style.top = moveEvent.clientY + "px";element.style.maxHeight = "";@@ -99,7 +101,7 @@ export const moveResize = (element: HTMLElement, afterCB?: (type: string) => voielement.style.height = (y - moveEvent.clientY + height) + "px";} else if (type === "lt" &&moveEvent.clientX > 0 && x - moveEvent.clientX + width > 200 &&- moveEvent.clientY > Constants.SIZE_TOOLBAR_HEIGHT && y - moveEvent.clientY + height > 160) {+ moveEvent.clientY > topBarHeight && y - moveEvent.clientY + height > 160) {element.style.left = moveEvent.clientX + "px";element.style.width = (x - moveEvent.clientX + width) + "px";element.style.top = moveEvent.clientY + "px";@@ -108,7 +110,7 @@ export const moveResize = (element: HTMLElement, afterCB?: (type: string) => voielement.style.height = (y - moveEvent.clientY + height) + "px";} else if (type === "ld" &&moveEvent.clientX > 0 && x - moveEvent.clientX + width > 200 &&- moveEvent.clientY - y + height > 160 && moveEvent.clientY - y + height < window.innerHeight - Constants.SIZE_TOOLBAR_HEIGHT) {+ moveEvent.clientY - y + height > 160 && moveEvent.clientY - y + height < window.innerHeight - topBarHeight) {element.style.left = moveEvent.clientX + "px";element.style.width = (x - moveEvent.clientX + width) + "px";element.style.height = moveEvent.clientY - y + height + "px";diff --git a/app/src/index.ts b/app/src/index.tsindex e409989263..4e0b328d9f 100644--- a/app/src/index.ts+++ b/app/src/index.ts@@ -7,7 +7,14 @@ import {account} from "./config/account";import {addScript, addScriptSync} from "./protyle/util/addScript";import {genUUID} from "./util/genID";import {fetchGet, fetchPost} from "./util/fetch";-import {addBaseURL, getDocDisplayName, getIdFromSYProtocol, isSYProtocol, redirectToCheckAuth, setNoteBook} from "./util/pathName";+import {+ addBaseURL,+ getDocDisplayName,+ getIdFromSYProtocol,+ isSYProtocol,+ redirectToCheckAuth,+ setNoteBook+} from "./util/pathName";import {registerServiceWorker} from "./util/serviceWorker";import {openFileById} from "./editor/util";import {@@ -209,7 +216,7 @@ export class App {}break;case "updateKernelPluginState": {- const {name, state} = data.data as {name: string, state: TKernelPluginState};+ const {name, state} = data.data as { name: string, state: TKernelPluginState };const plugin = this.plugins.find(p => p.name === name);if (plugin) {plugin.kernel.state.code = state;diff --git a/app/src/layout/topBar.ts b/app/src/layout/topBar.tsindex aa3c48df8b..c2bd42a605 100644--- a/app/src/layout/topBar.ts+++ b/app/src/layout/topBar.ts@@ -25,6 +25,10 @@ import {exportLayout} from "./util";import {commandPanel} from "../boot/globalEvent/command/panel";import {openTopBarMenu} from "../plugin/openTopBarMenu";+export const getTopBarHeight = () => {+ return document.getElementById("sidebar") ? 0 : (document.getElementById("toolbar").clientHeight || document.querySelector(".layout-tab-bar").clientHeight);+};+export const initBar = (app: App) => {const toolbarElement = document.getElementById("toolbar");toolbarElement.innerHTML = `diff --git a/app/src/menus/Menu.ts b/app/src/menus/Menu.tsindex fae6584985..6af675e77b 100644--- a/app/src/menus/Menu.ts+++ b/app/src/menus/Menu.ts@@ -3,6 +3,7 @@ import {setPosition} from "../util/setPosition";import {hasClosestByClassName} from "../protyle/util/hasClosest";import {isMobile} from "../util/functions";import {Constants} from "../constants";+import {getTopBarHeight} from "../layout/topBar";export class Menu {public element: HTMLElement;@@ -74,7 +75,7 @@ export class Menu {// 垂直方向位置调整// 减 9px 是为了尽量对齐菜单选项(b3-menu__submenu 的默认 padding-top 加上子菜单首个 b3-menu__item 的默认 margin-top)// 减 1px 是为了避免在特定情况下渲染出不应存在的滚动条而做的兼容处理- subMenuElement.style.top = Math.max(Constants.SIZE_TOOLBAR_HEIGHT,+ subMenuElement.style.top = Math.max(getTopBarHeight(),Math.min(itemRect.top - 9, window.innerHeight - subMenuRect.height - 1)) + "px";// 水平方向位置调整diff --git a/app/src/protyle/toolbar/index.ts b/app/src/protyle/toolbar/index.tsindex ef1aa5d4e4..9db65ddc5d 100644--- a/app/src/protyle/toolbar/index.ts+++ b/app/src/protyle/toolbar/index.ts@@ -54,6 +54,7 @@ export class Toolbar {public subElementCloseCB: () => void;public range: Range;public toolbarHeight: number;+ private readonly LINE_HEIGHT = 32;constructor(protyle: IProtyle) {const options = protyle.options;@@ -90,7 +91,41 @@ export class Toolbar {public update(protyle: IProtyle) {this.element.innerHTML = "";- protyle.options.toolbar = toolbarKeyToMenu(Constants.PROTYLE_TOOLBAR);+ debugger+ protyle.options.toolbar = toolbarKeyToMenu(isMobile() ? [+ "block-ref",+ "a",+ "|",+ "text",+ "strong",+ "em",+ "u",+ "clear",+ "|",+ "code",+ "tag",+ "inline-math",+ "inline-memo",+ ] : [+ "block-ref",+ "a",+ "|",+ "text",+ "strong",+ "em",+ "u",+ "s",+ "mark",+ "sup",+ "sub",+ "clear",+ "|",+ "code",+ "kbd",+ "tag",+ "inline-math",+ "inline-memo",+ ]);protyle.app.plugins.forEach(item => {const pluginToolbar = item.updateProtyleToolbar(protyle.options.toolbar);pluginToolbar.forEach(toolbarItem => {@@ -1526,7 +1561,7 @@ export class Toolbar {previewPath = response.data.templates[0]?.path;/// #if !MOBILEconst rangePosition = getSelectionPosition(nodeElement, range);- setPosition(this.subElement, rangePosition.left, rangePosition.top + 18, Constants.SIZE_TOOLBAR_HEIGHT);+ setPosition(this.subElement, rangePosition.left, rangePosition.top + 18, this.LINE_HEIGHT);(this.subElement.firstElementChild as HTMLElement).style.maxHeight = Math.min(window.innerHeight * 0.8, window.innerHeight - this.subElement.getBoundingClientRect().top) - 16 + "px";/// #elsesetPosition(this.subElement, 0, 0);@@ -1661,7 +1696,7 @@ export class Toolbar {if (init) {/// #if !MOBILEconst rangePosition = getSelectionPosition(nodeElement, range);- setPosition(this.subElement, rangePosition.left, rangePosition.top + 18, Constants.SIZE_TOOLBAR_HEIGHT);+ setPosition(this.subElement, rangePosition.left, rangePosition.top + 18, this.LINE_HEIGHT);/// #elsesetPosition(this.subElement, 0, 0);/// #endif@@ -1778,7 +1813,7 @@ export class Toolbar {<button class="keyboard__action${protyle.disabled ? " fn__none" : ""}" data-action="pasteEscaped"><span>${window.siyuan.languages.pasteEscaped}</span></button><div class="keyboard__split${protyle.disabled ? " fn__none" : ""}"></div><button class="keyboard__action" data-action="back"><svg><use xlink:href="#iconBack"></use></svg></button>`;- setPosition(this.subElement, rangePosition.left, rangePosition.top + 28, Constants.SIZE_TOOLBAR_HEIGHT);+ setPosition(this.subElement, rangePosition.left, rangePosition.top + 28, this.LINE_HEIGHT);}});this.subElement.style.zIndex = (++window.siyuan.zIndex).toString();@@ -1786,7 +1821,7 @@ export class Toolbar {this.subElementCloseCB = undefined;this.element.classList.add("fn__none");const rangePosition = getSelectionPosition(nodeElement, range);- setPosition(this.subElement, rangePosition.left, rangePosition.top - 48, Constants.SIZE_TOOLBAR_HEIGHT);+ setPosition(this.subElement, rangePosition.left, rangePosition.top - 48, this.LINE_HEIGHT);}private genItem(protyle: IProtyle, menuItem: IMenuItem) {diff --git a/app/src/protyle/util/Options.ts b/app/src/protyle/util/Options.tsindex 8d89a70c0e..795f884727 100644--- a/app/src/protyle/util/Options.ts+++ b/app/src/protyle/util/Options.ts@@ -2,6 +2,7 @@ import {Constants} from "../../constants";import {merge} from "./merge";import {hintEmbed, hintRef, hintSlash, hintTag} from "../hint/extend";import {toolbarKeyToMenu} from "../toolbar/util";+import {isMobile} from "../../util/functions";export class Options {public options: IProtyleOptions;@@ -89,7 +90,40 @@ export class Options {},mode: "both",},- toolbar: Constants.PROTYLE_TOOLBAR,+ toolbar: isMobile() ? [+ "block-ref",+ "a",+ "|",+ "text",+ "strong",+ "em",+ "u",+ "clear",+ "|",+ "code",+ "tag",+ "inline-math",+ "inline-memo",+ ] : [+ "block-ref",+ "a",+ "|",+ "text",+ "strong",+ "em",+ "u",+ "s",+ "mark",+ "sup",+ "sub",+ "clear",+ "|",+ "code",+ "kbd",+ "tag",+ "inline-math",+ "inline-memo",+ ],typewriterMode: false,upload: {max: 1024 * 1024 * 1024 * 16,diff --git a/app/src/protyle/wysiwyg/keydown.ts b/app/src/protyle/wysiwyg/keydown.tsindex dc57e1c281..19fbbd9a5d 100644--- a/app/src/protyle/wysiwyg/keydown.ts+++ b/app/src/protyle/wysiwyg/keydown.ts@@ -77,6 +77,7 @@ import {onlyProtyleCommand} from "../../boot/globalEvent/command/protyle";import {AIChat} from "../../ai/chat";import {updateCalloutType} from "./callout";import {tabCodeBlock} from "./codeBlock";+import {getTopBarHeight} from "../../layout/topBar";export const getContentByInlineHTML = (range: Range, cb: (content: string) => void) => {let html = "";@@ -539,7 +540,7 @@ export const keydown = (protyle: IProtyle, editorElement: HTMLElement) => {const contentRect = protyle.contentElement.getBoundingClientRect();let centerElement = document.elementFromPoint(contentRect.x + contentRect.width / 2, contentRect.y + contentRect.height / 2);if (centerElement.classList.contains("protyle-wysiwyg")) {- centerElement = document.elementFromPoint(contentRect.x + contentRect.width / 2, contentRect.y + contentRect.height / 2 + Constants.SIZE_TOOLBAR_HEIGHT);+ centerElement = document.elementFromPoint(contentRect.x + contentRect.width / 2, contentRect.y + contentRect.height / 2 + getTopBarHeight());}const centerBlockElement = hasClosestBlock(centerElement);if (centerBlockElement && centerBlockElement !== nodeElement) {diff --git a/app/src/util/fetch.ts b/app/src/util/fetch.tsindex 29a4a44ec9..e294e63a9a 100644--- a/app/src/util/fetch.ts+++ b/app/src/util/fetch.ts@@ -5,13 +5,13 @@ import {ipcRenderer} from "electron";import {processMessage} from "./processMessage";import {kernelError} from "../dialog/processSystem";-export const fetchPost = (+export function fetchPost(url: string,data?: any,cb?: (response: IWebSocketData) => void,headers?: IObject,failCallback?: (response: IWebSocketData) => void,- signal?: AbortSignal) => {+ signal?: AbortSignal) {const init: RequestInit = {method: "POST",};@@ -123,7 +123,7 @@ export const fetchPost = (});};-export const fetchSyncPost = async (url: string, data?: any) => {+export async function fetchSyncPost(url: string, data?: any) {const init: RequestInit = {method: "POST",};@@ -140,7 +140,7 @@ export const fetchSyncPost = async (url: string, data?: any) => {return res2;};-export const fetchGet = (url: string, cb: (response: IWebSocketData | IObject | string) => void) => {+export function fetchGet(url: string, cb: (response: IWebSocketData | IObject | string) => void) {fetch(url).then((response) => {if (response.headers.get("content-type")?.indexOf("application/json") > -1) {return response.json();diff --git a/app/src/util/setPosition.ts b/app/src/util/setPosition.tsindex d535a6a7e1..2f18eb93cc 100644--- a/app/src/util/setPosition.ts+++ b/app/src/util/setPosition.ts@@ -1,20 +1,21 @@-import {Constants} from "../constants";+import {getTopBarHeight} from "../layout/topBar";export const setPosition = (element: HTMLElement, left: number, top: number, targetHeight = 0, targetLeft = 0) => {element.style.top = top + "px";element.style.left = left + "px";const rect = element.getBoundingClientRect();- if (rect.top < Constants.SIZE_TOOLBAR_HEIGHT) {+ const topBarHeight = getTopBarHeight();+ if (rect.top < topBarHeight) {// 如果元素接触顶栏,向下移- element.style.top = Constants.SIZE_TOOLBAR_HEIGHT + "px";+ element.style.top = topBarHeight + "px";} else if (rect.bottom > window.innerHeight) {const y = top - rect.height - targetHeight;- if (y > Constants.SIZE_TOOLBAR_HEIGHT && (y + rect.height) < window.innerHeight) {+ if (y > topBarHeight && (y + rect.height) < window.innerHeight) {// 如果元素底部超出窗口(下方空间不够),向上移element.style.top = y + "px";} else {// 如果上下空间都不够,向上移,但尽量靠底部- element.style.top = Math.max(Constants.SIZE_TOOLBAR_HEIGHT, window.innerHeight - rect.height) + "px";+ element.style.top = Math.max(topBarHeight, window.innerHeight - rect.height) + "px";}}if (rect.right > window.innerWidth) {