Skip to content

An open-source, privacy-first, self-hosted knowledge workspace where humans and AI agents work together 开源、隐私优先、自托管的知识工作空间,让人与智能体在此协作

:art: https://github.com/siyuan-note/siyuan/issues/10749

Vanessa05b425dd82e5
diff --git a/app/src/boot/onGetConfig.ts b/app/src/boot/onGetConfig.ts
index 7b6d7863bd..771a8b9886 100644
--- a/app/src/boot/onGetConfig.ts
+++ b/app/src/boot/onGetConfig.ts
@@ -1,5 +1,5 @@
import {adjustLayout, exportLayout, JSONToLayout, resetLayout, resizeTopBar} from "../layout/util";
-import {resizeTabs} from "../layout/tabUtil";
+import {resizeTabs, setTabPosition} from "../layout/tabUtil";
import {setStorageVal} from "../protyle/util/compatibility";
/// #if !BROWSER
import {ipcRenderer, webFrame} from "electron";
@@ -20,7 +20,6 @@ import {isWindow} from "../util/functions";
import {initStatus} from "../layout/status";
import {showMessage} from "../dialog/message";
import {replaceLocalPath} from "../editor/rename";
-import {setTabPosition} from "../window/setHeader";
import {initBar} from "../layout/topBar";
import {openChangelog} from "./openChangelog";
import {App} from "../index";
diff --git a/app/src/layout/Wnd.ts b/app/src/layout/Wnd.ts
index efbf49f281..53ae19942a 100644
--- a/app/src/layout/Wnd.ts
+++ b/app/src/layout/Wnd.ts
@@ -23,7 +23,7 @@ import {
import {Constants} from "../constants";
/// #if !BROWSER
import {ipcRenderer, webFrame} from "electron";
-import {setModelsHash, setTabPosition} from "../window/setHeader";
+import {setModelsHash} from "../window/setHeader";
/// #endif
import {Search} from "../search";
import {showMessage} from "../dialog/message";
@@ -45,7 +45,7 @@ import {App} from "../index";
import {unicode2Emoji} from "../emoji";
import {closeWindow} from "../window/closeWin";
import {setTitle} from "../dialog/processSystem";
-import {newCenterEmptyTab, resizeTabs} from "./tabUtil";
+import {newCenterEmptyTab, resizeTabs, setTabPosition} from "./tabUtil";
import {fullscreen} from "../protyle/breadcrumb/action";
import {setPadding} from "../protyle/ui/initUI";
import {setPosition} from "../util/setPosition";
diff --git a/app/src/layout/dock/index.ts b/app/src/layout/dock/index.ts
index 192b2132a2..94f2c4db72 100644
--- a/app/src/layout/dock/index.ts
+++ b/app/src/layout/dock/index.ts
@@ -10,7 +10,7 @@ import {Tag} from "./Tag";
import {Graph} from "./Graph";
import {Model} from "../Model";
import {adjustLayout, saveLayout, setPanelFocus} from "../util";
-import {getDockByType, resizeTabs} from "../tabUtil";
+import {getDockByType, resizeTabs, setTabPosition} from "../tabUtil";
import {Inbox} from "./Inbox";
import {Protyle} from "../../protyle";
import {Backlink} from "./Backlink";
@@ -21,7 +21,6 @@ import {Plugin} from "../../plugin";
import {Custom} from "./Custom";
import {clearBeforeResizeTop, recordBeforeResizeTop} from "../../protyle/util/resize";
import {Constants} from "../../constants";
-import {setTabPosition} from "../../window/setHeader";
const TYPES = ["file", "outline", "inbox", "bookmark", "tag", "graph", "globalGraph", "backlink"];
diff --git a/app/src/layout/dock/util.ts b/app/src/layout/dock/util.ts
index 88c6f31ed9..78b2a59e00 100644
--- a/app/src/layout/dock/util.ts
+++ b/app/src/layout/dock/util.ts
@@ -3,14 +3,13 @@ import {Tab} from "../Tab";
import {Graph} from "./Graph";
import {Outline} from "./Outline";
import {fixWndFlex1, getInstanceById, getWndByLayout} from "../util";
-import {getDockByType, resizeTabs} from "../tabUtil";
+import {getDockByType, resizeTabs, setTabPosition} from "../tabUtil";
import {Backlink} from "./Backlink";
import {App} from "../../index";
import {Wnd} from "../Wnd";
import {fetchSyncPost} from "../../util/fetch";
import {Files} from "./Files";
import {Editor} from "../../editor";
-import {setTabPosition} from "../../window/setHeader";
export const openBacklink = async (options: {
app: App,
diff --git a/app/src/layout/tabUtil.ts b/app/src/layout/tabUtil.ts
index 812d73e771..af72c7f7a0 100644
--- a/app/src/layout/tabUtil.ts
+++ b/app/src/layout/tabUtil.ts
@@ -1,6 +1,6 @@
import {Tab} from "./Tab";
import {getInstanceById, newModelByInitData, saveLayout} from "./util";
-import {getAllModels, getAllTabs} from "./getAll";
+import {getAllModels, getAllTabs, getAllWnds} from "./getAll";
import {hideAllElements, hideElements} from "../protyle/ui/hideElements";
import {pdfResize} from "../asset/renderAssets";
import {App} from "../index";
@@ -24,6 +24,103 @@ import {newFile} from "../util/newFile";
import {mountHelp, newNotebook} from "../util/mount";
import {Constants} from "../constants";
import {fetchPost} from "../util/fetch";
+import {isWindow} from "../util/functions";
+import {Wnd} from "./Wnd";
+
+export const setTabPosition = (onlyPadding = false) => {
+ const isWindowMode = isWindow();
+ const wndsTemp: Wnd[] = [];
+ if (isWindowMode) {
+ getAllWnds(window.siyuan.layout.layout, wndsTemp);
+ } else if (window.siyuan.config.appearance.hideToolbar) {
+ if (!window.siyuan.layout.centerLayout) {
+ return;
+ }
+ getAllWnds(window.siyuan.layout.centerLayout, wndsTemp);
+ }
+
+ if (wndsTemp.length === 0) {
+ return;
+ }
+
+ const centerRect = (isWindowMode ? window.siyuan.layout.layout : window.siyuan.layout.centerLayout).element.getBoundingClientRect();
+ const toolbarDragElement = document.getElementById("drag");
+ const toolbarDragRect = toolbarDragElement?.getBoundingClientRect() || {left: 0, right: 0};
+ if (toolbarDragElement) {
+ toolbarDragElement.style.removeProperty("--b3-toolbar-drag-left");
+ toolbarDragElement.style.removeProperty("--b3-toolbar-drag-right");
+ }
+ wndsTemp.forEach(item => {
+ const headerElement = item.headersElement.parentElement;
+ const headerRect = headerElement.getBoundingClientRect();
+ headerElement.style.paddingLeft = "";
+ (headerElement.lastElementChild as HTMLElement).style.marginRight = "";
+ headerElement.style.visibility = "";
+ if (headerRect.top <= 0) {
+ // header padding
+ if (isWindowMode) {
+ if (headerRect.left === 0) {
+ headerElement.style.paddingLeft = getComputedStyle(document.body).getPropertyValue("--b3-toolbar-left-mac");
+ }
+ } else {
+ if (headerRect.left > toolbarDragRect.left && headerRect.left === centerRect.left) {
+ toolbarDragElement.style.setProperty("--b3-toolbar-drag-left", headerRect.left - toolbarDragRect.left + "px");
+ } else if (headerRect.left < toolbarDragRect.left) {
+ headerElement.style.paddingLeft = (toolbarDragRect.left - headerRect.left) + "px";
+ }
+ }
+
+ if (isWindowMode) {
+ if (headerRect.right === centerRect.right) {
+ (headerElement.lastElementChild as HTMLElement).style.marginRight = document.querySelector(".toolbar__window").clientWidth + "px";
+ }
+ } else {
+ if (headerRect.right < toolbarDragRect.right && headerRect.right === centerRect.right) {
+ toolbarDragElement.style.setProperty("--b3-toolbar-drag-right", toolbarDragRect.right - headerRect.right + "px");
+ } else if (headerRect.right > toolbarDragRect.right) {
+ // 不能取 clientWidth,因为设置了 min-width(64) 导致 clientWidth 大于实际宽度
+ if (headerRect.right - toolbarDragRect.right + 64 > headerRect.width) {
+ headerElement.style.visibility = "hidden";
+ } else {
+ (headerElement.lastElementChild as HTMLElement).style.marginRight = (headerRect.right - toolbarDragRect.right) + "px";
+ }
+ }
+ }
+ }
+
+ if (onlyPadding) {
+ return;
+ }
+
+ item.element.classList.remove("layout__wnd--right", "layout__wnd--left", "layout__wnd--center");
+ (item.element.querySelector(".layout-tab-container") as HTMLElement).style.backgroundColor = "";
+ const dragElement = headerElement.querySelector(".item--readonly .fn__flex-1") as HTMLElement;
+ if (headerRect.top <= 0) {
+ // empty
+ if (headerElement.classList.contains("fn__none")) {
+ (item.element.querySelector(".layout-tab-container") as HTMLElement).style.backgroundColor = "transparent";
+ return;
+ }
+ // header transparent
+ item.element.classList.add("layout__wnd--center");
+ if (!isWindowMode) {
+ if (headerRect.left - 1 <= centerRect.left) {
+ item.element.classList.add("layout__wnd--left");
+ }
+ if (headerRect.right + 1 >= centerRect.right) {
+ item.element.classList.add("layout__wnd--right");
+ }
+ }
+ dragElement.parentElement.parentElement.style.minWidth = "56px";
+ dragElement.style.height = dragElement.parentElement.clientHeight + "px";
+ (dragElement.style as CSSStyleDeclarationElectron).WebkitAppRegion = "drag";
+ } else {
+ dragElement.parentElement.parentElement.style.minWidth = "";
+ dragElement.style.height = "";
+ (dragElement.style as CSSStyleDeclarationElectron).WebkitAppRegion = "";
+ }
+ });
+};
export const getActiveTab = (wndActive = true) => {
const activeTabElement = document.querySelector(".layout__wnd--active .item--focus");
diff --git a/app/src/layout/util.ts b/app/src/layout/util.ts
index 3d5584056c..71e26e7599 100644
--- a/app/src/layout/util.ts
+++ b/app/src/layout/util.ts
@@ -28,10 +28,9 @@ import {newCardModel} from "../card/newCardTab";
import {App} from "../index";
import {afterLoadPlugin} from "../plugin/loader";
import {setTitle} from "../dialog/processSystem";
-import {newCenterEmptyTab, resizeTabs} from "./tabUtil";
+import {newCenterEmptyTab, resizeTabs, setTabPosition} from "./tabUtil";
import {setStorageVal} from "../protyle/util/compatibility";
import {adjustDockPadding} from "./dock/util";
-import {setTabPosition} from "../window/setHeader";
export const setPanelFocus = (element: Element, isSaveLayout = true) => {
if (element.getAttribute("data-type") === "wnd") {
diff --git a/app/src/plugin/index.ts b/app/src/plugin/index.ts
index 87ee6f1593..62838297ad 100644
--- a/app/src/plugin/index.ts
+++ b/app/src/plugin/index.ts
@@ -7,8 +7,7 @@ import {Custom} from "../layout/dock/Custom";
import {getAllEditor, getAllModels} from "../layout/getAll";
import {Tab} from "../layout/Tab";
import {resizeTopBar, setPanelFocus} from "../layout/util";
-import {getDockByType} from "../layout/tabUtil";
-import {setTabPosition} from "../window/setHeader";
+import {getDockByType, setTabPosition} from "../layout/tabUtil";
///#else
import {MobileCustom} from "../mobile/dock/MobileCustom";
/// #endif
diff --git a/app/src/plugin/uninstall.ts b/app/src/plugin/uninstall.ts
index 337e82712d..36aa75e0a1 100644
--- a/app/src/plugin/uninstall.ts
+++ b/app/src/plugin/uninstall.ts
@@ -3,11 +3,11 @@ import {Plugin} from "./index";
/// #if !MOBILE
import {getAllModels} from "../layout/getAll";
import {resizeTopBar} from "../layout/util";
+import {setTabPosition} from "../layout/tabUtil";
/// #endif
import {Constants} from "../constants";
import {setStorageVal} from "../protyle/util/compatibility";
import {getAllEditor} from "../layout/getAll";
-import {setTabPosition} from "../window/setHeader";
export const uninstall = (app: App, name: string, isReload: boolean) => {
app.plugins.find((plugin: Plugin, index) => {
diff --git a/app/src/window/init.ts b/app/src/window/init.ts
index fce5c15fb7..aa33481035 100644
--- a/app/src/window/init.ts
+++ b/app/src/window/init.ts
@@ -2,7 +2,7 @@ import {Constants} from "../constants";
import {ipcRenderer, webFrame} from "electron";
import {fetchPost} from "../util/fetch";
import {adjustLayout, getInstanceById, JSONToCenter} from "../layout/util";
-import {resizeTabs} from "../layout/tabUtil";
+import {resizeTabs, setTabPosition} from "../layout/tabUtil";
import {initStatus} from "../layout/status";
import {appearance} from "../config/appearance";
import {initAssets, setInlineStyle} from "../util/assets";
@@ -12,12 +12,12 @@ import {initWindow} from "../boot/onGetConfig";
import {App} from "../index";
import {afterLoadPlugin} from "../plugin/loader";
import {Tab} from "../layout/Tab";
-import {initWindowEvent} from "../boot/globalEvent/event";
-import {getAllEditor} from "../layout/getAll";
/// #if !BROWSER
import {initNativeDialogOverride} from "../protyle/util/compatibility";
-import {setTabPosition} from "./setHeader";
/// #endif
+import {initWindowEvent} from "../boot/globalEvent/event";
+import {getAllEditor} from "../layout/getAll";
+
export const init = (app: App) => {
webFrame.setZoomFactor(window.siyuan.storage[Constants.LOCAL_ZOOM]);
diff --git a/app/src/window/setHeader.ts b/app/src/window/setHeader.ts
index 59e6a1e51e..1efe766030 100644
--- a/app/src/window/setHeader.ts
+++ b/app/src/window/setHeader.ts
@@ -1,106 +1,9 @@
import {isWindow} from "../util/functions";
-import {Wnd} from "../layout/Wnd";
-import {getAllTabs, getAllWnds} from "../layout/getAll";
+import {getAllTabs} from "../layout/getAll";
import {Editor} from "../editor";
import {Asset} from "../asset";
import {Constants} from "../constants";
-export const setTabPosition = (onlyPadding = false) => {
- const isWindowMode = isWindow();
- const wndsTemp: Wnd[] = [];
- if (isWindowMode) {
- getAllWnds(window.siyuan.layout.layout, wndsTemp);
- } else if (window.siyuan.config.appearance.hideToolbar) {
- if (!window.siyuan.layout.centerLayout) {
- return;
- }
- getAllWnds(window.siyuan.layout.centerLayout, wndsTemp);
- }
-
- if (wndsTemp.length === 0) {
- return;
- }
-
- const centerRect = (isWindowMode ? window.siyuan.layout.layout : window.siyuan.layout.centerLayout).element.getBoundingClientRect();
- const toolbarDragElement = document.getElementById("drag");
- const toolbarDragRect = toolbarDragElement?.getBoundingClientRect() || {left: 0, right: 0};
- if (toolbarDragElement) {
- toolbarDragElement.style.removeProperty("--b3-toolbar-drag-left");
- toolbarDragElement.style.removeProperty("--b3-toolbar-drag-right");
- }
- wndsTemp.forEach(item => {
- const headerElement = item.headersElement.parentElement;
- const headerRect = headerElement.getBoundingClientRect();
- headerElement.style.paddingLeft = "";
- (headerElement.lastElementChild as HTMLElement).style.marginRight = "";
- headerElement.style.visibility = "";
- if (headerRect.top <= 0) {
- // header padding
- if (isWindowMode) {
- if (headerRect.left === 0) {
- headerElement.style.paddingLeft = getComputedStyle(document.body).getPropertyValue("--b3-toolbar-left-mac");
- }
- } else {
- if (headerRect.left > toolbarDragRect.left && headerRect.left === centerRect.left) {
- toolbarDragElement.style.setProperty("--b3-toolbar-drag-left", headerRect.left - toolbarDragRect.left + "px");
- } else if (headerRect.left < toolbarDragRect.left) {
- headerElement.style.paddingLeft = (toolbarDragRect.left - headerRect.left) + "px";
- }
- }
-
- if (isWindowMode) {
- if (headerRect.right === centerRect.right) {
- (headerElement.lastElementChild as HTMLElement).style.marginRight = document.querySelector(".toolbar__window").clientWidth + "px";
- }
- } else {
- if (headerRect.right < toolbarDragRect.right && headerRect.right === centerRect.right) {
- toolbarDragElement.style.setProperty("--b3-toolbar-drag-right", toolbarDragRect.right - headerRect.right + "px");
- } else if (headerRect.right > toolbarDragRect.right) {
- // 不能取 clientWidth,因为设置了 min-width(64) 导致 clientWidth 大于实际宽度
- if (headerRect.right - toolbarDragRect.right + 64 > headerRect.width) {
- headerElement.style.visibility = "hidden";
- } else {
- (headerElement.lastElementChild as HTMLElement).style.marginRight = (headerRect.right - toolbarDragRect.right) + "px";
- }
- }
- }
- }
-
- if (onlyPadding) {
- return;
- }
-
- item.element.classList.remove("layout__wnd--right", "layout__wnd--left", "layout__wnd--center");
- (item.element.querySelector(".layout-tab-container") as HTMLElement).style.backgroundColor = "";
- const dragElement = headerElement.querySelector(".item--readonly .fn__flex-1") as HTMLElement;
- if (headerRect.top <= 0) {
- // empty
- if (headerElement.classList.contains("fn__none")) {
- (item.element.querySelector(".layout-tab-container") as HTMLElement).style.backgroundColor = "transparent";
- return;
- }
- // header transparent
- item.element.classList.add("layout__wnd--center");
- if (!isWindowMode) {
- if (headerRect.left - 1 <= centerRect.left) {
- item.element.classList.add("layout__wnd--left");
- }
- if (headerRect.right + 1 >= centerRect.right) {
- item.element.classList.add("layout__wnd--right");
- }
- }
- dragElement.parentElement.parentElement.style.minWidth = "56px";
- dragElement.style.height = dragElement.parentElement.clientHeight + "px";
- (dragElement.style as CSSStyleDeclarationElectron).WebkitAppRegion = "drag";
- } else {
- dragElement.parentElement.parentElement.style.minWidth = "";
- dragElement.style.height = "";
- (dragElement.style as CSSStyleDeclarationElectron).WebkitAppRegion = "";
- }
- });
-};
-
-
export const setModelsHash = () => {
if (!isWindow()) {
return;