Skip to content

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

:recycle:

Vanessaca38d4f715fa
diff --git a/app/src/block/Panel.ts b/app/src/block/Panel.ts
index 86d6435dcb..83e84aa68e 100644
--- a/app/src/block/Panel.ts
+++ b/app/src/block/Panel.ts
@@ -17,7 +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";
+import {getTopBarHeight} from "../layout/getTopBarHeight";
export class BlockPanel {
public element: HTMLElement;
diff --git a/app/src/dialog/moveResize.ts b/app/src/dialog/moveResize.ts
index 52416e423c..33211231d9 100644
--- a/app/src/dialog/moveResize.ts
+++ b/app/src/dialog/moveResize.ts
@@ -2,7 +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";
+import {getTopBarHeight} from "../layout/getTopBarHeight";
export const moveResize = (element: HTMLElement, afterCB?: (type: string) => void) => {
element.addEventListener("mousedown", (event: MouseEvent & { target: HTMLElement }) => {
diff --git a/app/src/layout/getTopBarHeight.ts b/app/src/layout/getTopBarHeight.ts
new file mode 100644
index 0000000000..c449490041
--- /dev/null
+++ b/app/src/layout/getTopBarHeight.ts
@@ -0,0 +1,3 @@
+export const getTopBarHeight = () => {
+ return document.getElementById("sidebar") ? 0 : (document.getElementById("toolbar").clientHeight || document.querySelector(".layout-tab-bar").clientHeight);
+};
diff --git a/app/src/layout/topBar.ts b/app/src/layout/topBar.ts
index 0b76ff0b09..f38f7121a6 100644
--- a/app/src/layout/topBar.ts
+++ b/app/src/layout/topBar.ts
@@ -25,10 +25,6 @@ import {commandPanel} from "../boot/globalEvent/command/panel";
import {openTopBarMenu} from "../plugin/openTopBarMenu";
import {getWorkspaceName} from "../util/processTitle";
-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.ts
index 6af675e77b..38ebd1f8bc 100644
--- a/app/src/menus/Menu.ts
+++ b/app/src/menus/Menu.ts
@@ -3,7 +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";
+import {getTopBarHeight} from "../layout/getTopBarHeight";
export class Menu {
public element: HTMLElement;
diff --git a/app/src/plugin/API.ts b/app/src/plugin/API.ts
index b288b87567..fe7593c797 100644
--- a/app/src/plugin/API.ts
+++ b/app/src/plugin/API.ts
@@ -34,7 +34,17 @@ import {Files} from "../layout/dock/Files";
import {ProtyleMethod} from "./ProtyleMethod";
import {openEmojiPanel} from "../emoji";
-interface IOpenWindowOptions {
+let openTab;
+let openWindow;
+/// #if MOBILE
+openTab = () => {
+ // TODO: Mobile
+};
+openWindow = () => {
+ // TODO: Mobile
+};
+/// #else
+openWindow = (options: {
position?: IPosition,
height?: number,
width?: number,
@@ -43,9 +53,28 @@ interface IOpenWindowOptions {
doc?: {
id: string, // 块 id
},
-}
+}) => {
+ if (options.doc && options.doc.id) {
+ openNewWindowById(options.doc.id, {
+ alwaysOnTop: options.alwaysOnTop,
+ position: options.position,
+ width: options.width,
+ height: options.height
+ });
+ return;
+ }
+ if (options.tab) {
+ openNewWindow(options.tab, {
+ alwaysOnTop: options.alwaysOnTop,
+ position: options.position,
+ width: options.width,
+ height: options.height
+ });
+ return;
+ }
+};
-interface IOpenTabOptions {
+openTab = (options: {
app: App,
doc?: {
id: string, // 块 id
@@ -77,40 +106,7 @@ interface IOpenTabOptions {
keepCursor?: boolean // 是否跳转到新 tab 上
removeCurrentTab?: boolean // 在当前页签打开时需移除原有页签
afterOpen?: (model?: Model) => void // 打开后回调
-}
-
-let openTab: (options: IOpenTabOptions) => void;
-let openWindow: (options: IOpenWindowOptions) => void;
-/// #if MOBILE
-openTab = () => {
- // TODO: Mobile
-};
-openWindow = () => {
- // TODO: Mobile
-};
-/// #else
-openWindow = (options: IOpenWindowOptions) => {
- if (options.doc && options.doc.id) {
- openNewWindowById(options.doc.id, {
- alwaysOnTop: options.alwaysOnTop,
- position: options.position,
- width: options.width,
- height: options.height
- });
- return;
- }
- if (options.tab) {
- openNewWindow(options.tab, {
- alwaysOnTop: options.alwaysOnTop,
- position: options.position,
- width: options.width,
- height: options.height
- });
- return;
- }
-};
-
-openTab = (options: IOpenTabOptions) => {
+}) => {
if (options.doc) {
if (options.doc.zoomIn) {
if (options.doc.action && !options.doc.action.includes(Constants.CB_GET_ALL)) {
@@ -341,44 +337,41 @@ const openEmoji = (options: {
});
};
-export const API: Record<string, unknown> = {};
-const def = <T>(key: string, get: () => T) => {
- Object.defineProperty(API, key, {get, enumerable: true, configurable: true});
+export const API = {
+ adaptHotkey: updateHotkeyTip,
+ confirm: confirmDialog,
+ Constants,
+ showMessage,
+ hideMessage,
+ fetchPost,
+ fetchSyncPost,
+ fetchGet,
+ getFrontend,
+ getBackend,
+ getModelByDockType,
+ openTab,
+ openWindow,
+ openMobileFileById,
+ lockScreen,
+ exitSiYuan,
+ Protyle,
+ ProtyleMethod,
+ Plugin,
+ Dialog,
+ Menu,
+ Setting,
+ getAllEditor,
+ /// #if !MOBILE
+ getActiveTab,
+ getAllModels,
+ getAllTabs,
+ /// #endif
+ getActiveEditor,
+ platformUtils,
+ openSetting,
+ openAttributePanel,
+ saveLayout,
+ globalCommand,
+ expandDocTree,
+ openEmoji
};
-
-def("adaptHotkey", () => updateHotkeyTip);
-def("confirm", () => confirmDialog);
-def("Constants", () => Constants);
-def("showMessage", () => showMessage);
-def("hideMessage", () => hideMessage);
-def("fetchPost", () => fetchPost);
-def("fetchSyncPost", () => fetchSyncPost);
-def("fetchGet", () => fetchGet);
-def("getFrontend", () => getFrontend);
-def("getBackend", () => getBackend);
-def("getModelByDockType", () => getModelByDockType);
-def("openTab", () => openTab);
-def("openWindow", () => openWindow);
-def("openMobileFileById", () => openMobileFileById);
-def("lockScreen", () => lockScreen);
-def("exitSiYuan", () => exitSiYuan);
-def("Protyle", () => Protyle);
-def("ProtyleMethod", () => ProtyleMethod);
-def("Plugin", () => Plugin);
-def("Dialog", () => Dialog);
-def("Menu", () => Menu);
-def("Setting", () => Setting);
-def("getAllEditor", () => getAllEditor);
-/// #if !MOBILE
-def("getActiveTab", () => getActiveTab);
-def("getAllModels", () => getAllModels);
-def("getAllTabs", () => getAllTabs);
-/// #endif
-def("getActiveEditor", () => getActiveEditor);
-def("platformUtils", () => platformUtils);
-def("openSetting", () => openSetting);
-def("openAttributePanel", () => openAttributePanel);
-def("saveLayout", () => saveLayout);
-def("globalCommand", () => globalCommand);
-def("expandDocTree", () => expandDocTree);
-def("openEmoji", () => openEmoji);
diff --git a/app/src/protyle/index.ts b/app/src/protyle/index.ts
index 41a222d7ce..8d1e65d596 100644
--- a/app/src/protyle/index.ts
+++ b/app/src/protyle/index.ts
@@ -465,8 +465,8 @@ export class Protyle {
resize(this.protyle);
}
- public reload(focus: boolean) {
- reloadProtyle(this.protyle, focus);
+ public reload(focus: boolean, updateReadonly?: boolean) {
+ reloadProtyle(this.protyle, focus, updateReadonly);
}
public insert(html: string, isBlock = false, useProtyleRange = false) {
diff --git a/app/src/protyle/wysiwyg/keydown.ts b/app/src/protyle/wysiwyg/keydown.ts
index 19fbbd9a5d..6be774af19 100644
--- a/app/src/protyle/wysiwyg/keydown.ts
+++ b/app/src/protyle/wysiwyg/keydown.ts
@@ -77,7 +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";
+import {getTopBarHeight} from "../../layout/getTopBarHeight";
export const getContentByInlineHTML = (range: Range, cb: (content: string) => void) => {
let html = "";
diff --git a/app/src/util/reloadSync.ts b/app/src/util/reloadSync.ts
index 05d933bc67..8d829baed5 100644
--- a/app/src/util/reloadSync.ts
+++ b/app/src/util/reloadSync.ts
@@ -11,18 +11,6 @@ import {setStorageVal} from "../protyle/util/compatibility";
import type {Tab} from "../layout/Tab";
import {setTitle} from "./processTitle";
-const updateTitle = (rootID: string, tab: Tab, protyle?: IProtyle) => {
- fetchPost("/api/block/getDocInfo", {
- id: rootID
- }, (response) => {
- const titleEmpty = response.data.ial[Constants.CUSTOM_SY_TITLE_EMPTY] === "true";
- tab.updateTitle(getDocDisplayName(response.data.name, titleEmpty));
- if (protyle && protyle.title) {
- protyle.title.setTitle(response.data.name, titleEmpty);
- }
- });
-};
-
export const reloadSync = (
app: App,
data: { upsertRootIDs: string[], removeRootIDs: string[] },
@@ -40,7 +28,7 @@ export const reloadSync = (
if (data.removeRootIDs.includes(window.siyuan.mobile.popEditor.protyle.block.rootID)) {
hideElements(["dialog"]);
} else {
- reloadProtyle(window.siyuan.mobile.popEditor.protyle, false, updateReadonly);
+ window.siyuan.mobile.popEditor.reload(false, updateReadonly);
}
}
if (document.getElementById("empty").classList.contains("fn__none") &&
@@ -48,7 +36,7 @@ export const reloadSync = (
if (data.removeRootIDs.includes(window.siyuan.mobile.editor.protyle.block.rootID)) {
setEmpty(app);
} else {
- reloadProtyle(window.siyuan.mobile.editor.protyle, false, updateReadonly);
+ window.siyuan.mobile.editor.reload(false, updateReadonly);
fetchPost("/api/block/getDocInfo", {
id: window.siyuan.mobile.editor.protyle.block.rootID
}, (response) => {
@@ -62,13 +50,24 @@ export const reloadSync = (
});
/// #else
const allModels = getAllModels();
+ const updateTitle = (rootID: string, tab: Tab, protyle?: IProtyle) => {
+ fetchPost("/api/block/getDocInfo", {
+ id: rootID
+ }, (response) => {
+ const titleEmpty = response.data.ial[Constants.CUSTOM_SY_TITLE_EMPTY] === "true";
+ tab.updateTitle(getDocDisplayName(response.data.name, titleEmpty));
+ if (protyle && protyle.title) {
+ protyle.title.setTitle(response.data.name, titleEmpty);
+ }
+ });
+ };
allModels.editor.forEach(item => {
if (data.upsertRootIDs.includes(item.editor.protyle.block.rootID)) {
fetchPost("/api/block/getDocInfo", {
id: item.editor.protyle.block.rootID,
}, (response) => {
item.editor.protyle.wysiwyg.renderCustom(response.data.ial);
- reloadProtyle(item.editor.protyle, false, updateReadonly);
+ item.editor.reload(false, updateReadonly);
updateTitle(item.editor.protyle.block.rootID, item.parent, item.editor.protyle);
});
} else if (data.removeRootIDs.includes(item.editor.protyle.block.rootID)) {
diff --git a/app/src/util/setPosition.ts b/app/src/util/setPosition.ts
index 2f18eb93cc..dd11d8b476 100644
--- a/app/src/util/setPosition.ts
+++ b/app/src/util/setPosition.ts
@@ -1,4 +1,4 @@
-import {getTopBarHeight} from "../layout/topBar";
+import {getTopBarHeight} from "../layout/getTopBarHeight";
export const setPosition = (element: HTMLElement, left: number, top: number, targetHeight = 0, targetLeft = 0) => {
element.style.top = top + "px";