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: https://github.com/siyuan-note/siyuan/issues/9846
Vanessa5fac682e6f9c
diff --git a/app/src/boot/globalEvent/searchKeydown.ts b/app/src/boot/globalEvent/searchKeydown.tsindex 3995433b61..072e36223c 100644--- a/app/src/boot/globalEvent/searchKeydown.ts+++ b/app/src/boot/globalEvent/searchKeydown.ts@@ -3,7 +3,7 @@ import * as path from "path";/// #endifimport {matchHotKey} from "../../protyle/util/hotKey";import {fetchPost} from "../../util/fetch";-import {openFileById} from "../../editor/util";+import {checkFold, openFileById} from "../../editor/util";import {Constants} from "../../constants";import {newFileByName} from "../../util/newFile";import {App} from "../../index";@@ -90,19 +90,18 @@ export const searchKeydown = (app: App, event: KeyboardEvent) => {if (!isAsset) {if (matchHotKey(window.siyuan.config.keymap.editor.general.insertRight.custom, event)) {const id = currentList.getAttribute("data-node-id");- fetchPost("/api/block/checkBlockFold", {id}, (foldResponse) => {+ checkFold(id, (zoomIn, action) => {openFileById({app,id,position: "right",- action: foldResponse.data ? [Constants.CB_GET_FOCUS, Constants.CB_GET_ALL] :- (id === currentList.getAttribute("data-root-id") ? [Constants.CB_GET_FOCUS, Constants.CB_GET_ROOTSCROLL] : [Constants.CB_GET_FOCUS, Constants.CB_GET_CONTEXT]),- zoomIn: foldResponse.data+ action,+ zoomIn});if (dialog) {dialog.destroy({focus: "false"});}- });+ })return true;}const id = currentList.getAttribute("data-node-id");@@ -197,18 +196,17 @@ export const searchKeydown = (app: App, event: KeyboardEvent) => {replace(element, config, edit, false);} else {const id = currentList.getAttribute("data-node-id");- fetchPost("/api/block/checkBlockFold", {id}, (foldResponse) => {+ checkFold(id, (zoomIn, action) => {openFileById({app,id,- action: foldResponse.data ? [Constants.CB_GET_FOCUS, Constants.CB_GET_ALL] :- (id === currentList.getAttribute("data-root-id") ? [Constants.CB_GET_FOCUS, Constants.CB_GET_ROOTSCROLL] : [Constants.CB_GET_FOCUS, Constants.CB_GET_CONTEXT]),- zoomIn: foldResponse.data+ action,+ zoomIn});if (dialog) {dialog.destroy({focus: "false"});}- });+ })}} else {/// #if !BROWSERdiff --git a/app/src/constants.ts b/app/src/constants.tsindex 97b01d7102..917304a18a 100644--- a/app/src/constants.ts+++ b/app/src/constants.ts@@ -75,9 +75,9 @@ export abstract class Constants {public static readonly CB_GET_ALL = "cb-get-all"; // 获取所有块public static readonly CB_GET_BACKLINK = "cb-get-backlink"; // 悬浮窗为传递型需展示上下文public static readonly CB_GET_UNUNDO = "cb-get-unundo"; // 不需要记录历史- public static readonly CB_GET_SCROLL = "cb-get-scroll"; // 滚动到指定位置+ public static readonly CB_GET_SCROLL = "cb-get-scroll"; // 滚动到指定位置,用于直接打开文档,必有 rootIDpublic static readonly CB_GET_CONTEXT = "cb-get-context"; // 包含上下文- public static readonly CB_GET_ROOTSCROLL = "cb-get-rootscroll"; // 如果为 rootID 就滚动到指定位置+ public static readonly CB_GET_ROOTSCROLL = "cb-get-rootscroll"; // 如果为 rootID 就滚动到指定位置,必有 rootIDpublic static readonly CB_GET_HTML = "cb-get-html"; // 直接渲染,不需要再 /api/block/getDocInfo,否则搜索表格无法定位public static readonly CB_GET_HISTORY = "cb-get-history"; // 历史渲染diff --git a/app/src/editor/index.ts b/app/src/editor/index.tsindex fa5e5a1664..f2ee93a016 100644--- a/app/src/editor/index.ts+++ b/app/src/editor/index.ts@@ -19,7 +19,7 @@ export class Editor extends Model {app: App,tab: Tab,blockId: string,- rootId?: string, // 使用 rootId 会优先使用本地 filepositon 定位+ rootId: string,mode?: TEditorMode,action?: string[],}) {@@ -38,7 +38,7 @@ export class Editor extends Model {private initProtyle(options: {blockId: string,action?: string[]- rootId?: string,+ rootId: string,mode?: TEditorMode,}) {this.editor = new Protyle(this.app, this.element, {diff --git a/app/src/editor/util.ts b/app/src/editor/util.tsindex 039577e95d..c5f8bc3a6e 100644--- a/app/src/editor/util.ts+++ b/app/src/editor/util.ts@@ -28,6 +28,15 @@ import {Search} from "../search";import {App} from "../index";import {newCardModel} from "../card/newCardTab";+export const checkFold = (id: string, cb: (zoomIn: boolean, action: string[]) => void) => {+ if (!id) {+ return;+ }+ fetchPost("/api/block/checkBlockFold", {id}, (foldResponse) => {+ cb(foldResponse.data, foldResponse.data ? [Constants.CB_GET_FOCUS, Constants.CB_GET_ALL] : [Constants.CB_GET_FOCUS, Constants.CB_GET_CONTEXT, Constants.CB_GET_ROOTSCROLL])+ });+}+export const openFileById = async (options: {app: App,id: string,@@ -472,6 +481,7 @@ const newTab = (options: IOpenFileOptions) => {app: options.app,tab,blockId: options.id,+ rootId: options.rootID,action: [Constants.CB_GET_ALL, Constants.CB_GET_FOCUS],});} else {@@ -479,6 +489,7 @@ const newTab = (options: IOpenFileOptions) => {app: options.app,tab,blockId: options.id,+ rootId: options.rootID,mode: options.mode,action: options.action,});@@ -538,7 +549,7 @@ export const updatePanelByEditor = (options: {updateOutline(models, options.protyle, options.reload);updateBacklinkGraph(models, options.protyle);options.protyle.app.plugins.forEach(item => {- item.eventBus.emit("switch-protyle", {protyle:options.protyle});+ item.eventBus.emit("switch-protyle", {protyle: options.protyle});});}};diff --git a/app/src/layout/Wnd.ts b/app/src/layout/Wnd.tsindex 511d212fd2..a3cb753ab5 100644--- a/app/src/layout/Wnd.ts+++ b/app/src/layout/Wnd.ts@@ -466,7 +466,7 @@ export class Wnd {openFileById({app: this.app,id: keepCursorId,- action: [Constants.CB_GET_FOCUS, Constants.CB_GET_CONTEXT, Constants.CB_GET_ROOTSCROLL]+ action: [Constants.CB_GET_FOCUS, Constants.CB_GET_SCROLL]});}currentTab.headElement.removeAttribute("keep-cursor");diff --git a/app/src/layout/dock/Bookmark.ts b/app/src/layout/dock/Bookmark.tsindex df7e2d48f7..964289baab 100644--- a/app/src/layout/dock/Bookmark.ts+++ b/app/src/layout/dock/Bookmark.ts@@ -5,8 +5,7 @@ import {setPanelFocus} from "../util";import {getDockByType} from "../tabUtil";import {fetchPost} from "../../util/fetch";import {updateHotkeyTip} from "../../protyle/util/compatibility";-import {openFileById} from "../../editor/util";-import {Constants} from "../../constants";+import {checkFold, openFileById} from "../../editor/util";import {hasClosestByClassName} from "../../protyle/util/hasClosest";import {openBookmarkMenu} from "../../menus/bookmark";import {App} from "../../index";@@ -84,44 +83,54 @@ export class Bookmark extends Model {return;}}- const id = element.getAttribute("data-node-id");- if (id) {- fetchPost("/api/block/checkBlockFold", {id}, (foldResponse) => {- openFileById({- app,- id,- action: foldResponse.data ? [Constants.CB_GET_FOCUS, Constants.CB_GET_ALL] : [Constants.CB_GET_FOCUS, Constants.CB_GET_CONTEXT, Constants.CB_GET_ROOTSCROLL],- zoomIn: foldResponse.data- });+ const id = element.getAttribute("data-node-id")+ checkFold(id, (zoomIn, action: string[]) => {+ openFileById({+ app,+ id,+ action,+ zoomIn});- }+ });},rightClick: (element: HTMLElement, event: MouseEvent) => {openBookmarkMenu(element, event, this);},- ctrlClick(element: HTMLElement) {- openFileById({- app,- id: element.getAttribute("data-node-id"),- keepCursor: true,- action: [Constants.CB_GET_CONTEXT, Constants.CB_GET_ROOTSCROLL]- });+ ctrlClick: (element: HTMLElement) => {+ const id = element.getAttribute("data-node-id")+ checkFold(id, (zoomIn, action: string[]) => {+ openFileById({+ app,+ id,+ keepCursor: true,+ action,+ zoomIn+ });+ })},- altClick(element: HTMLElement) {- openFileById({- app,- id: element.getAttribute("data-node-id"),- position: "right",- action: [Constants.CB_GET_FOCUS, Constants.CB_GET_CONTEXT, Constants.CB_GET_ROOTSCROLL]- });+ altClick: (element: HTMLElement,) => {+ const id = element.getAttribute("data-node-id")+ checkFold(id, (zoomIn, action: string[]) => {+ openFileById({+ app,+ id,+ position: "bottom",+ action,+ zoomIn+ });+ })},- shiftClick(element: HTMLElement) {- openFileById({- app,- id: element.getAttribute("data-node-id"),- position: "bottom",- action: [Constants.CB_GET_FOCUS, Constants.CB_GET_CONTEXT, Constants.CB_GET_ROOTSCROLL]- });+ shiftClick: (element: HTMLElement) => {+ const id = element.getAttribute("data-node-id")+ checkFold(id, (zoomIn, action: string[]) => {+ openFileById({+ app,+ id,+ position: "bottom",+ action,+ zoomIn+ });+ })},blockExtHTML: '<span class="b3-list-item__action"><svg><use xlink:href="#iconMore"></use></svg></span>',topExtHTML: '<span class="b3-list-item__action"><svg><use xlink:href="#iconMore"></use></svg></span>',diff --git a/app/src/layout/dock/Graph.ts b/app/src/layout/dock/Graph.tsindex 9d483e328a..3342a9bf09 100644--- a/app/src/layout/dock/Graph.ts+++ b/app/src/layout/dock/Graph.ts@@ -7,7 +7,7 @@ import {addScript} from "../../protyle/util/addScript";import {BlockPanel} from "../../block/Panel";import {fullscreen} from "../../protyle/breadcrumb/action";import {fetchPost} from "../../util/fetch";-import {isCurrentEditor, openFileById} from "../../editor/util";+import {checkFold, isCurrentEditor, openFileById} from "../../editor/util";import {updateHotkeyTip} from "../../protyle/util/compatibility";import {openGlobalSearch} from "../../search/util";import {App} from "../../index";@@ -652,19 +652,25 @@ export class Graph extends Model {return;}if (window.siyuan.shiftIsPressed) {- openFileById({- app: this.app,- id: node.id,- position: "bottom",- action: [Constants.CB_GET_FOCUS, Constants.CB_GET_CONTEXT, Constants.CB_GET_ROOTSCROLL]- });+ checkFold(node.id, (zoomIn, action: string[]) => {+ openFileById({+ app: this.app,+ id: node.id,+ position: "bottom",+ action,+ zoomIn+ });+ })} else if (window.siyuan.altIsPressed) {- openFileById({- app: this.app,- id: node.id,- position: "right",- action: [Constants.CB_GET_FOCUS, Constants.CB_GET_CONTEXT, Constants.CB_GET_ROOTSCROLL]- });+ checkFold(node.id, (zoomIn, action: string[]) => {+ openFileById({+ app: this.app,+ id: node.id,+ position: "right",+ action,+ zoomIn+ });+ })} else if (window.siyuan.ctrlIsPressed) {window.siyuan.blockPanels.push(new BlockPanel({app: this.app,@@ -674,11 +680,14 @@ export class Graph extends Model {nodeIds: [node.id],}));} else {- openFileById({- app: this.app,- id: node.id,- action: [Constants.CB_GET_FOCUS, Constants.CB_GET_CONTEXT, Constants.CB_GET_ROOTSCROLL]- });+ checkFold(node.id, (zoomIn, action: string[]) => {+ openFileById({+ app: this.app,+ id: node.id,+ action,+ zoomIn+ });+ })}});}, 1000);diff --git a/app/src/layout/tabUtil.ts b/app/src/layout/tabUtil.tsindex 3d1beb44de..05d14de5c7 100644--- a/app/src/layout/tabUtil.ts+++ b/app/src/layout/tabUtil.ts@@ -235,7 +235,8 @@ export const copyTab = (app: App, tab: Tab) => {model = new Editor({app,tab: newTab,- blockId: tab.model.editor.protyle.block.id+ blockId: tab.model.editor.protyle.block.id,+ rootId: tab.model.editor.protyle.block.rootID});} else if (tab.model instanceof Asset) {model = new Asset({diff --git a/app/src/mobile/editor.ts b/app/src/mobile/editor.tsindex b408431dde..a7394d5446 100644--- a/app/src/mobile/editor.ts+++ b/app/src/mobile/editor.ts@@ -60,6 +60,7 @@ export const openMobileFileById = (app: App, id: string, action = [Constants.CB_} else {window.siyuan.mobile.editor = new Protyle(app, document.getElementById("editor"), {blockId: id,+ rootId: data.data.rootID,action,render: {scroll: true,diff --git a/app/src/mobile/util/initFramework.ts b/app/src/mobile/util/initFramework.tsindex 0abd376deb..1e48b10629 100644--- a/app/src/mobile/util/initFramework.ts+++ b/app/src/mobile/util/initFramework.ts@@ -20,6 +20,7 @@ import {syncGuide} from "../../sync/syncGuide";import {Inbox} from "../../layout/dock/Inbox";import {App} from "../../index";import {setTitle} from "../../dialog/processSystem";+import {checkFold} from "../../editor/util";export const initFramework = (app: App, isStart: boolean) => {setInlineStyle();@@ -134,7 +135,9 @@ export const initFramework = (app: App, isStart: boolean) => {} else {fetchPost("/api/block/getRecentUpdatedBlocks", {}, (response) => {if (response.data.length !== 0) {- openMobileFileById(app, response.data[0].id, [Constants.CB_GET_HL, Constants.CB_GET_CONTEXT, Constants.CB_GET_ROOTSCROLL]);+ checkFold(response.data[0].id, (zoomIn) => {+ openMobileFileById(app, response.data[0].id, zoomIn ? [Constants.CB_GET_ALL, Constants.CB_GET_HL] : [Constants.CB_GET_HL, Constants.CB_GET_CONTEXT, Constants.CB_GET_ROOTSCROLL]);+ });} else {setEmpty(app);}diff --git a/app/src/protyle/index.ts b/app/src/protyle/index.tsindex 5524908110..5195f48bc2 100644--- a/app/src/protyle/index.ts+++ b/app/src/protyle/index.ts@@ -228,44 +228,22 @@ export class Protyle {removeLoading(this.protyle);return;}- const filePosition = window.siyuan.storage[Constants.LOCAL_FILEPOSITION][options.blockId] ||- window.siyuan.storage[Constants.LOCAL_FILEPOSITION][options.rootId];+if (this.protyle.options.mode !== "preview" &&- !mergedOptions.action.includes(Constants.CB_GET_ALL) &&- (mergedOptions.action.includes(Constants.CB_GET_SCROLL) || mergedOptions.action.includes(Constants.CB_GET_ROOTSCROLL)) &&- filePosition) {+ options.rootId && window.siyuan.storage[Constants.LOCAL_FILEPOSITION][options.rootId] &&+ (+ mergedOptions.action.includes(Constants.CB_GET_SCROLL) ||+ (mergedOptions.action.includes(Constants.CB_GET_ROOTSCROLL) && options.rootId === options.blockId)+ )+ ) {getDocByScroll({protyle: this.protyle,- scrollAttr: filePosition,+ scrollAttr: window.siyuan.storage[Constants.LOCAL_FILEPOSITION][options.rootId],mergedOptions,cb: () => {this.afterOnGet(mergedOptions);}});- } else if (this.protyle.options.mode !== "preview" &&- (mergedOptions.action.includes(Constants.CB_GET_SCROLL) || mergedOptions.action.includes(Constants.CB_GET_ROOTSCROLL))) {- fetchPost("/api/block/getDocInfo", {- id: options.blockId- }, (response) => {- if (!mergedOptions.action.includes(Constants.CB_GET_SCROLL) &&- response.data.rootID !== options.blockId && mergedOptions.action.includes(Constants.CB_GET_ROOTSCROLL)) {- // 打开根文档保持上一次历史,否则按照原有 action 执行 https://github.com/siyuan-note/siyuan/issues/9082- this.getDoc(mergedOptions);- return;- }- if (window.siyuan.storage[Constants.LOCAL_FILEPOSITION][response.data.rootID]) {- getDocByScroll({- protyle: this.protyle,- scrollAttr: window.siyuan.storage[Constants.LOCAL_FILEPOSITION][response.data.rootID],- mergedOptions,- cb: () => {- this.afterOnGet(mergedOptions);- }- });- } else {- this.getDoc(mergedOptions);- }- });} else {this.getDoc(mergedOptions);}diff --git a/app/src/search/util.ts b/app/src/search/util.tsindex 90ebc75d96..ce7a39118d 100644--- a/app/src/search/util.ts+++ b/app/src/search/util.ts@@ -5,7 +5,7 @@ import * as path from "path";import {Constants} from "../constants";import {escapeAriaLabel, escapeGreat, escapeHtml} from "../util/escape";import {fetchPost} from "../util/fetch";-import {openFile, openFileById} from "../editor/util";+import {checkFold, openFile, openFileById} from "../editor/util";import {showMessage} from "../dialog/message";import {reloadProtyle} from "../protyle/util/reload";import {MenuItem} from "../menus/Menu";@@ -865,19 +865,18 @@ export const genSearch = (app: App, config: ISearchOption, element: Element, clo} else {if (event.altKey) {const id = target.getAttribute("data-node-id");- fetchPost("/api/block/checkBlockFold", {id}, (foldResponse) => {+ checkFold(id, (zoomIn, action) => {openFileById({app,id,- action: foldResponse.data ? [Constants.CB_GET_FOCUS, Constants.CB_GET_ALL] :- (id === target.getAttribute("data-root-id") ? [Constants.CB_GET_FOCUS, Constants.CB_GET_ROOTSCROLL] : [Constants.CB_GET_FOCUS, Constants.CB_GET_CONTEXT]),- zoomIn: foldResponse.data,+ action,+ zoomIn,position: "right"});if (closeCB) {closeCB();}- });+ })} else if (!target.classList.contains("b3-list-item--focus")) {searchPanelElement.querySelector(".b3-list-item--focus").classList.remove("b3-list-item--focus");target.classList.add("b3-list-item--focus");@@ -906,18 +905,17 @@ export const genSearch = (app: App, config: ISearchOption, element: Element, clo/// #endif} else {const id = target.getAttribute("data-node-id");- fetchPost("/api/block/checkBlockFold", {id}, (foldResponse) => {+ checkFold(id, (zoomIn, action) => {openFileById({app,id,- action: foldResponse.data ? [Constants.CB_GET_FOCUS, Constants.CB_GET_ALL] :- (id === target.getAttribute("data-root-id") ? [Constants.CB_GET_FOCUS, Constants.CB_GET_ROOTSCROLL] : [Constants.CB_GET_FOCUS, Constants.CB_GET_CONTEXT]),- zoomIn: foldResponse.data+ action,+ zoomIn});if (closeCB) {closeCB();}- });+ })}}window.siyuan.menus.menu.remove();diff --git a/app/src/util/backForward.ts b/app/src/util/backForward.tsindex 2e183f2f21..a69c433fc6 100644--- a/app/src/util/backForward.ts+++ b/app/src/util/backForward.ts@@ -57,6 +57,7 @@ const focusStack = async (app: App, stack: IBackStack) => {app: app,tab,blockId: stack.zoomId || stack.protyle.block.rootID,+ rootId: stack.protyle.block.rootID,action: stack.zoomId ? [Constants.CB_GET_FOCUS, Constants.CB_GET_ALL] : [Constants.CB_GET_FOCUS]});tab.addModel(editor);