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
Vanessa73505073e60d
diff --git a/app/src/dialog/processSystem.ts b/app/src/dialog/processSystem.tsindex 86a6919066..4f44f8ba4d 100644--- a/app/src/dialog/processSystem.ts+++ b/app/src/dialog/processSystem.ts@@ -21,7 +21,7 @@ import {setEmpty} from "../mobile/util/setEmpty";import {hideAllElements, hideElements} from "../protyle/ui/hideElements";import {App} from "../index";import {saveScroll} from "../protyle/scroll/saveScroll";-import {isInAndroid, isInIOS} from "../protyle/util/compatibility";+import {isInAndroid, isInIOS, setStorageVal} from "../protyle/util/compatibility";import {Plugin} from "../plugin";const updateTitle = (rootID: string, tab: Tab) => {@@ -65,12 +65,14 @@ export const reloadSync = (app: App, data: { upsertRootIDs: string[], removeRootreloadProtyle(item.editor.protyle, false);updateTitle(item.editor.protyle.block.rootID, item.parent);} else if (data.removeRootIDs.includes(item.editor.protyle.block.rootID)) {- item.parent.parent.removeTab(item.parent.id, false, false, false);+ item.parent.parent.removeTab(item.parent.id, false, false);+ delete window.siyuan.storage[Constants.LOCAL_FILEPOSITION][item.editor.protyle.block.rootID];+ setStorageVal(Constants.LOCAL_FILEPOSITION, window.siyuan.storage[Constants.LOCAL_FILEPOSITION]);}});allModels.graph.forEach(item => {if (item.type === "local" && data.removeRootIDs.includes(item.rootId)) {- item.parent.parent.removeTab(item.parent.id, false, false, false);+ item.parent.parent.removeTab(item.parent.id, false, false);} else if (item.type !== "local" || data.upsertRootIDs.includes(item.rootId)) {item.searchGraph(false);if (item.type === "local") {@@ -80,7 +82,7 @@ export const reloadSync = (app: App, data: { upsertRootIDs: string[], removeRoot});allModels.outline.forEach(item => {if (item.type === "local" && data.removeRootIDs.includes(item.blockId)) {- item.parent.parent.removeTab(item.parent.id, false, false, false);+ item.parent.parent.removeTab(item.parent.id, false, false);} else if (item.type !== "local" || data.upsertRootIDs.includes(item.blockId)) {fetchPost("/api/outline/getDocOutline", {id: item.blockId,@@ -94,7 +96,7 @@ export const reloadSync = (app: App, data: { upsertRootIDs: string[], removeRoot});allModels.backlink.forEach(item => {if (item.type === "local" && data.removeRootIDs.includes(item.rootId)) {- item.parent.parent.removeTab(item.parent.id, false, false, false);+ item.parent.parent.removeTab(item.parent.id, false, false);} else {item.refresh();if (item.type === "local") {diff --git a/app/src/editor/index.ts b/app/src/editor/index.tsindex 43fc75699e..fa5e5a1664 100644--- a/app/src/editor/index.ts+++ b/app/src/editor/index.ts@@ -19,9 +19,9 @@ export class Editor extends Model {app: App,tab: Tab,blockId: string,+ rootId?: string, // 使用 rootId 会优先使用本地 filepositon 定位mode?: TEditorMode,action?: string[],- scrollAttr?: IScrollAttr}) {super({app: options.app,@@ -38,19 +38,19 @@ export class Editor extends Model {private initProtyle(options: {blockId: string,action?: string[]+ rootId?: string,mode?: TEditorMode,- scrollAttr?: IScrollAttr}) {this.editor = new Protyle(this.app, this.element, {action: options.action || [],blockId: options.blockId,+ rootId: options.rootId,mode: options.mode,render: {title: true,background: true,scroll: true,},- scrollAttr: options.scrollAttr,typewriterMode: true,after: (editor) => {if (window.siyuan.editorIsFullscreen) {diff --git a/app/src/editor/util.ts b/app/src/editor/util.tsindex fe6e8e3c86..039577e95d 100644--- a/app/src/editor/util.ts+++ b/app/src/editor/util.ts@@ -277,7 +277,7 @@ export const openFile = async (options: IOpenFileOptions) => {createdTab = newTab(options);wnd.addTab(createdTab);if (unUpdateTab && options.removeCurrentTab) {- wnd.removeTab(unUpdateTab.id, false, true, false);+ wnd.removeTab(unUpdateTab.id, false, false);}} else {createdTab = newTab(options);@@ -306,7 +306,6 @@ const getUnInitTab = (options: IOpenFileOptions) => {} else {initObj.action = options.action;}- delete initObj.scrollAttr;item.headElement.setAttribute("data-initdata", JSON.stringify(initObj));item.parent.switchTab(item.headElement);return true;diff --git a/app/src/layout/Wnd.ts b/app/src/layout/Wnd.tsindex 30eeeb3499..511d212fd2 100644--- a/app/src/layout/Wnd.ts+++ b/app/src/layout/Wnd.ts@@ -682,7 +682,7 @@ export class Wnd {model.send("closews", {});}- private removeTabAction = (id: string, closeAll = false, hasSaveScroll = true, animate = true) => {+ private removeTabAction = (id: string, closeAll = false, animate = true) => {clearCounter();this.children.find((item, index) => {if (item.id === id) {@@ -691,7 +691,7 @@ export class Wnd {item.model.beforeDestroy();}}- if (item.model instanceof Editor && hasSaveScroll) {+ if (item.model instanceof Editor) {saveScroll(item.model.editor.protyle);}if (this.children.length === 1) {@@ -787,7 +787,7 @@ export class Wnd {/// #endif};- public removeTab(id: string, closeAll = false, needSaveScroll = true, animate = true) {+ public removeTab(id: string, closeAll = false, animate = true) {for (let index = 0; index < this.children.length; index++) {const item = this.children[index];if (item.id === id) {@@ -796,9 +796,9 @@ export class Wnd {showMessage(window.siyuan.languages.uploading);return;}- this.removeTabAction(id, closeAll, needSaveScroll, animate);+ this.removeTabAction(id, closeAll, animate);} else {- this.removeTabAction(id, closeAll, needSaveScroll, animate);+ this.removeTabAction(id, closeAll, animate);}return;}diff --git a/app/src/layout/tabUtil.ts b/app/src/layout/tabUtil.tsindex f02dffd746..3d1beb44de 100644--- a/app/src/layout/tabUtil.ts+++ b/app/src/layout/tabUtil.ts@@ -304,10 +304,6 @@ export const copyTab = (app: App, tab: Tab) => {} else if (!tab.model && tab.headElement) {const initData = JSON.parse(tab.headElement.getAttribute("data-initdata") || "{}");if (initData) {- // 历史数据兼容 2023-05-24- if (initData.scrollAttr) {- initData.scrollAttr.rootId = initData.rootId;- }model = newModelByInitData(app, newTab, initData);}}@@ -320,7 +316,7 @@ export const closeTabByType = async (tab: Tab, type: "closeOthers" | "closeAll"if (type === "closeOthers") {for (let index = 0; index < tab.parent.children.length; index++) {if (tab.parent.children[index].id !== tab.id && !tab.parent.children[index].headElement.classList.contains("item--pin")) {- await tab.parent.children[index].parent.removeTab(tab.parent.children[index].id, true, true, false);+ await tab.parent.children[index].parent.removeTab(tab.parent.children[index].id, true, false);index--;}}diff --git a/app/src/layout/util.ts b/app/src/layout/util.tsindex f5149838d5..7a9a3e13b5 100644--- a/app/src/layout/util.ts+++ b/app/src/layout/util.ts@@ -378,7 +378,7 @@ export const JSONToLayout = (app: App, isStart: boolean) => {if (window.siyuan.config.fileTree.closeTabsOnStart && isStart) {getAllTabs().forEach(item => {if (item.headElement && !item.headElement.classList.contains("item--pin")) {- item.parent.removeTab(item.id, false, false, false);+ item.parent.removeTab(item.id, false, false);}});}@@ -402,7 +402,7 @@ export const JSONToLayout = (app: App, isStart: boolean) => {const tabId = item.getAttribute("data-id");const tab = getInstanceById(tabId) as Tab;if (tab) {- tab.parent.removeTab(tabId, false, false, false);+ tab.parent.removeTab(tabId, false, false);}}}@@ -643,10 +643,10 @@ export const newModelByInitData = (app: App, tab: Tab, json: any) => {model = new Editor({app,tab,+ rootId: json.rootId,blockId: json.blockId,mode: json.mode,action: typeof json.action === "string" ? [json.action] : json.action,- scrollAttr: json.scrollAttr,});}return model;diff --git a/app/src/protyle/header/openTitleMenu.ts b/app/src/protyle/header/openTitleMenu.tsindex c4a4fcb464..a544fdd384 100644--- a/app/src/protyle/header/openTitleMenu.ts+++ b/app/src/protyle/header/openTitleMenu.ts@@ -27,6 +27,7 @@ import {openDocHistory} from "../../history/doc";import {openNewWindowById} from "../../window/openNewWindow";import {genImportMenu} from "../../menus/navigation";import {transferBlockRef} from "../../menus/block";+import {saveScroll} from "../scroll/saveScroll";export const openTitleMenu = (protyle: IProtyle, position: IPosition) => {hideTooltip();@@ -204,6 +205,7 @@ export const openTitleMenu = (protyle: IProtyle, position: IPosition) => {label: window.siyuan.languages.openByNewWindow,icon: "iconOpenWindow",click() {+ saveScroll(protyle);openNewWindowById(protyle.block.rootID);}}).element);diff --git a/app/src/protyle/index.ts b/app/src/protyle/index.tsindex df4d271a31..fe2c4f7cb0 100644--- a/app/src/protyle/index.ts+++ b/app/src/protyle/index.ts@@ -39,6 +39,7 @@ import {insertHTML} from "./util/insertHTML";import {avRender} from "./render/av/render";import {focusBlock, getEditorRange} from "./util/selection";import {hasClosestBlock} from "./util/hasClosest";+import {setStorageVal} from "./util/compatibility";export class Protyle {@@ -196,7 +197,7 @@ export class Protyle {setEmpty(app);/// #elseif (this.protyle.model) {- this.protyle.model.parent.parent.removeTab(this.protyle.model.parent.id, false, false);+ this.protyle.model.parent.parent.removeTab(this.protyle.model.parent.id, false);}/// #endif}@@ -207,9 +208,11 @@ export class Protyle {setEmpty(app);/// #elseif (this.protyle.model) {- this.protyle.model.parent.parent.removeTab(this.protyle.model.parent.id, false, false);+ this.protyle.model.parent.parent.removeTab(this.protyle.model.parent.id, false);}/// #endif+ delete window.siyuan.storage[Constants.LOCAL_FILEPOSITION][this.protyle.block.rootID];+ setStorageVal(Constants.LOCAL_FILEPOSITION, window.siyuan.storage[Constants.LOCAL_FILEPOSITION]);}break;}@@ -225,10 +228,10 @@ export class Protyle {removeLoading(this.protyle);return;}- if (options.scrollAttr) {+ if (options.rootId) {getDocByScroll({protyle: this.protyle,- scrollAttr: options.scrollAttr,+ scrollAttr: window.siyuan.storage[Constants.LOCAL_FILEPOSITION][options.rootId],mergedOptions,cb: () => {this.afterOnGet(mergedOptions);@@ -245,19 +248,10 @@ export class Protyle {this.getDoc(mergedOptions);return;}- let scrollObj;- if (response.data.ial.scroll) {- try {- scrollObj = JSON.parse(response.data.ial.scroll.replace(/"/g, '"'));- } catch (e) {- scrollObj = undefined;- }- }- if (scrollObj) {- scrollObj.rootId = response.data.rootID;+ if (window.siyuan.storage[Constants.LOCAL_FILEPOSITION][response.data.rootID]) {getDocByScroll({protyle: this.protyle,- scrollAttr: scrollObj,+ scrollAttr: window.siyuan.storage[Constants.LOCAL_FILEPOSITION][response.data.rootID],mergedOptions,cb: () => {this.afterOnGet(mergedOptions);diff --git a/app/src/protyle/scroll/saveScroll.ts b/app/src/protyle/scroll/saveScroll.tsindex 87149b468d..8aa5a87381 100644--- a/app/src/protyle/scroll/saveScroll.ts+++ b/app/src/protyle/scroll/saveScroll.ts@@ -39,8 +39,8 @@ export const saveScroll = (protyle: IProtyle, getObject = false) => {if (getObject) {return attr;}- window.siyuan.storage[Constants.LOCAL_FILEPOSITION][protyle.block.rootID] = JSON.stringify(attr);- setStorageVal(Constants.LOCAL_FILEPOSITION, window.siyuan.storage[Constants.LOCAL_FILEPOSITION][protyle.block.rootID]);+ window.siyuan.storage[Constants.LOCAL_FILEPOSITION][protyle.block.rootID] = attr;+ setStorageVal(Constants.LOCAL_FILEPOSITION, window.siyuan.storage[Constants.LOCAL_FILEPOSITION]);};export const getDocByScroll = (options: {diff --git a/app/src/protyle/util/onGet.ts b/app/src/protyle/util/onGet.tsindex 7ed24f98a7..937dbfcf4b 100644--- a/app/src/protyle/util/onGet.ts+++ b/app/src/protyle/util/onGet.ts@@ -33,7 +33,7 @@ export const onGet = (options: {if (options.data.code === 1) {// 其他报错if (options.protyle.model) {- options.protyle.model.parent.parent.removeTab(options.protyle.model.parent.id, false, false);+ options.protyle.model.parent.parent.removeTab(options.protyle.model.parent.id, false);} else {options.protyle.element.innerHTML = `<div class="ft__smaller ft__secondary b3-form__space--small" contenteditable="false">${window.siyuan.languages.refExpired}</div>`;}diff --git a/app/src/types/protyle.d.ts b/app/src/types/protyle.d.tsindex 062be23463..4ce2fd7fc9 100644--- a/app/src/types/protyle.d.ts+++ b/app/src/types/protyle.d.ts@@ -393,8 +393,8 @@ interface IOptions {action?: string[],mode?: TEditorMode,blockId: string+ rootId?: stringkey?: string- scrollAttr?: IScrollAttrdefId?: stringrender?: {background?: booleandiff --git a/app/src/window/openNewWindow.ts b/app/src/window/openNewWindow.tsindex d82324bba8..98bb7df19a 100644--- a/app/src/window/openNewWindow.ts+++ b/app/src/window/openNewWindow.ts@@ -53,26 +53,16 @@ export const openNewWindowById = (id: string, options: windowOptions = {}) => {}};if (response.data.rootID === id) {- fetchPost("/api/attr/getBlockAttrs", {id}, (attrResponse) => {- if (attrResponse.data.scroll) {- json.children.scrollAttr = JSON.parse(attrResponse.data.scroll);- // 历史数据兼容- json.children.scrollAttr.rootId = response.data.rootID;- }- /// #if !BROWSER- ipcRenderer.send(Constants.SIYUAN_OPEN_WINDOW, {- position: options.position,- width: options.width,- height: options.height,- url: `${window.location.protocol}//${window.location.host}/stage/build/app/window.html?v=${Constants.SIYUAN_VERSION}&json=${encodeURIComponent(JSON.stringify(json))}`- });- /// #endif+ /// #if !BROWSER+ ipcRenderer.send(Constants.SIYUAN_OPEN_WINDOW, {+ position: options.position,+ width: options.width,+ height: options.height,+ url: `${window.location.protocol}//${window.location.host}/stage/build/app/window.html?v=${Constants.SIYUAN_VERSION}&json=${encodeURIComponent(JSON.stringify(json))}`});+ /// #endif} else {json.children.action = Constants.CB_GET_ALL;- json.children.scrollAttr = {- zoomInId: id,- };/// #if !BROWSERipcRenderer.send(Constants.SIYUAN_OPEN_WINDOW, {position: options.position,