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/5315
Vanessadab5377a4b1c
diff --git a/app/src/dialog/processSystem.ts b/app/src/dialog/processSystem.tsindex 38f991691b..d1f0c967f3 100644--- a/app/src/dialog/processSystem.ts+++ b/app/src/dialog/processSystem.ts@@ -3,11 +3,11 @@ import {fetchPost} from "../util/fetch";/// #if !MOBILEimport {getAllModels} from "../layout/getAll";import {ipcRenderer} from "electron";+import {exportLayout} from "../layout/util";/// #endifimport {showMessage} from "./message";import {Dialog} from "./index";import {isMobile} from "../util/functions";-import {exportLayout} from "../layout/util";export const lockFile = (id: string) => {const html = `<div class="b3-dialog__scrim"></div>@@ -134,9 +134,13 @@ export const transactionError = (data: { code: number, data: string }) => {});const btnsElement = dialog.element.querySelectorAll(".b3-button");btnsElement[0].addEventListener("click", () => {+ /// #if MOBILE+ exitSiYuan();+ /// #elseexportLayout(false, () => {exitSiYuan();});+ /// #endif});btnsElement[1].addEventListener("click", () => {fetchPost("/api/filetree/refreshFiletree", {});diff --git a/app/src/protyle/hint/index.ts b/app/src/protyle/hint/index.tsindex b4710ea9aa..fe16ec0640 100644--- a/app/src/protyle/hint/index.ts+++ b/app/src/protyle/hint/index.ts@@ -25,8 +25,9 @@ import {addEmoji, filterEmoji, lazyLoadEmoji, unicode2Emoji} from "../../emoji";import {escapeHtml} from "../../util/escape";import {blockRender} from "../markdown/blockRender";import {uploadFiles} from "../upload";+/// #if !MOBILEimport {openFileById} from "../../editor/util";-import {isMobile} from "../../util/functions";+/// #endifimport {openMobileFileById} from "../../mobile/editor";import {getIconByType} from "../../editor/getIcon";@@ -497,15 +498,15 @@ ${unicode2Emoji(emoji.unicode, true)}</button>`;md: ""}, () => {insertHTML(genEmptyBlock(false, false, `<span data-type="block-ref" data-id="${newSubDocId}" data-subtype="d">Untitled</span>`), protyle);- if (isMobile()) {- openMobileFileById(newSubDocId, true);- } else {- openFileById({- id: newSubDocId,- hasContext: true,- action: [Constants.CB_GET_HL]- });- }+ /// #if MOBILE+ openMobileFileById(newSubDocId, true);+ /// #else+ openFileById({+ id: newSubDocId,+ hasContext: true,+ action: [Constants.CB_GET_HL]+ });+ /// #endif});return;} else if (Constants.INLINE_TYPE.includes(value)) {diff --git a/app/src/protyle/preview/index.ts b/app/src/protyle/preview/index.tsindex f0f1d2e9c6..1f507cb88f 100644--- a/app/src/protyle/preview/index.ts+++ b/app/src/protyle/preview/index.ts@@ -10,12 +10,14 @@ import {getSearch, isMobile} from "../../util/functions";/// #if !BROWSERimport {shell} from "electron";/// #endif+/// #if !MOBILE+import {openAsset, openBy} from "../../editor/util";+/// #endifimport {fetchPost} from "../../util/fetch";import {processRender} from "../util/processCode";import {highlightRender} from "../markdown/highlightRender";import {speechRender} from "../markdown/speechRender";import {mediaRender} from "../markdown/mediaRender";-import {openAsset, openBy} from "../../editor/util";export class Preview {public element: HTMLElement;@@ -46,6 +48,7 @@ export class Preview {event.stopPropagation();event.preventDefault();if (isLocalPath(linkAddress)) {+ /// #if !MOBILEif (Constants.SIYUAN_ASSETS_EXTS.includes(pathPosix().extname((linkAddress.split("?page")[0])))) {openAsset(linkAddress.split("?page")[0], parseInt(getSearch("page", linkAddress)));} else {@@ -53,6 +56,7 @@ export class Preview {openBy(linkAddress, "folder");/// #endif}+ /// #endif} else {/// #if !BROWSERshell.openExternal(linkAddress).catch((e) => {diff --git a/app/src/protyle/util/onGet.ts b/app/src/protyle/util/onGet.tsindex f9e1cd2569..2aa885c86a 100644--- a/app/src/protyle/util/onGet.ts+++ b/app/src/protyle/util/onGet.ts@@ -8,7 +8,9 @@ import {processRender} from "./processCode";import {highlightRender} from "../markdown/highlightRender";import {blockRender} from "../markdown/blockRender";import {highlightById} from "../../util/highlightById";+/// #if !MOBILEimport {pushBack} from "../../util/backForward";+/// #endifimport {focusBlock} from "./selection";import {hasClosestByAttribute, hasClosestByClassName} from "./hasClosest";import {preventScroll} from "../scroll/preventScroll";@@ -144,9 +146,11 @@ const setHTML = (options: { content: string, action?: string[] }, protyle: IProtif (options.action.includes(Constants.CB_GET_HL)) {preventScroll(protyle); // 搜索页签滚动会导致再次请求const hlElement = highlightById(protyle, protyle.block.id, true);+ /// #if !MOBILEif (hlElement && !options.action.includes(Constants.CB_GET_UNUNDO)) {pushBack(protyle, undefined, hlElement);}+ /// #endif} else if (options.action.includes(Constants.CB_GET_FOCUS)) {let focusElement: Element;Array.from(protyle.wysiwyg.element.querySelectorAll(`[data-node-id="${protyle.block.id}"]`)).find((item: HTMLElement) => {@@ -161,9 +165,11 @@ const setHTML = (options: { content: string, action?: string[] }, protyle: IProt}if (focusElement && !protyle.wysiwyg.element.firstElementChild.isSameNode(focusElement)) {focusBlock(focusElement);+ /// #if !MOBILEif (!options.action.includes(Constants.CB_GET_UNUNDO)) {pushBack(protyle, undefined, focusElement);}+ /// #endiffocusElement.scrollIntoView();// 减少抖动 https://ld246.com/article/1654263598088setTimeout(() => {@@ -171,16 +177,20 @@ const setHTML = (options: { content: string, action?: string[] }, protyle: IProt}, Constants.TIMEOUT_BLOCKLOAD);} else {focusBlock(protyle.wysiwyg.element.firstElementChild);+ /// #if !MOBILEif (!options.action.includes(Constants.CB_GET_UNUNDO)) {pushBack(protyle, undefined, protyle.wysiwyg.element.firstElementChild);}+ /// #endif}} else if (options.action.includes(Constants.CB_GET_FOCUSFIRST)) {// settimeout 时间需短一点,否则定位后快速滚动无效preventScroll(protyle, 8, 256);protyle.contentElement.scrollTop = 8;focusBlock(protyle.wysiwyg.element.firstElementChild);+ /// #if !MOBILEpushBack(protyle, undefined, protyle.wysiwyg.element.firstElementChild);+ /// #endif}if (protyle.disabled) {disabledProtyle(protyle);diff --git a/app/src/protyle/wysiwyg/index.ts b/app/src/protyle/wysiwyg/index.tsindex d787e84316..b4b6d186cf 100644--- a/app/src/protyle/wysiwyg/index.ts+++ b/app/src/protyle/wysiwyg/index.ts@@ -42,12 +42,12 @@ import {keydown} from "./keydown";import {openMobileFileById} from "../../mobile/editor";import {removeBlock} from "./remove";import {highlightRender} from "../markdown/highlightRender";-import {getAllModels} from "../../layout/getAll";import {setPosition} from "../../util/setPosition";import {openAttr} from "../../menus/commonMenuItem";import {blockRender} from "../markdown/blockRender";-import {pushBack} from "../../util/backForward";/// #if !MOBILE+import {getAllModels} from "../../layout/getAll";+import {pushBack} from "../../util/backForward";import {openAsset, openBy, openFileById} from "../../editor/util";/// #endifimport {BlockPanel} from "../../block/Panel";@@ -157,6 +157,7 @@ export class WYSIWYG {}nodeElement = tempElement;}+ /// #if !MOBILEif (protyle.model) {getAllModels().outline.forEach(item => {if (item.blockId === protyle.block.rootID) {@@ -173,6 +174,7 @@ export class WYSIWYG {}});}+ /// #endif}private bindEvent(protyle: IProtyle) {@@ -1381,6 +1383,7 @@ export class WYSIWYG {}/// #endif});+ /// #if !MOBILEif (protyle.model) {// 打开双链需记录到后退中 https://github.com/siyuan-note/insider/issues/801let blockElement: HTMLElement | false;@@ -1393,6 +1396,7 @@ export class WYSIWYG {pushBack(protyle, getEditorRange(this.element), blockElement);}}+ /// #endifreturn;}@@ -1726,7 +1730,9 @@ export class WYSIWYG {if (!protyle.wysiwyg.element.querySelector(".protyle-wysiwyg--select")) {countSelectWord(newRange);}+ /// #if !MOBILEpushBack(protyle, newRange);+ /// #endif}, isMobile() ? 520 : 0); // Android 双击慢了出不来protyle.toolbar.isNewEmptyInline = false;diff --git a/app/src/protyle/wysiwyg/transaction.ts b/app/src/protyle/wysiwyg/transaction.tsindex 97a047e145..fe432864f7 100644--- a/app/src/protyle/wysiwyg/transaction.ts+++ b/app/src/protyle/wysiwyg/transaction.ts@@ -10,7 +10,9 @@ import {lockFile} from "../../dialog/processSystem";import {setFold} from "../../menus/protyle";import {addLoading} from "../ui/initUI";import {onGet} from "../util/onGet";+/// #if !MOBILEimport {getAllModels} from "../../layout/getAll";+/// #endifimport {removeFoldHeading} from "../util/heading";import {genEmptyElement, genSBElement} from "../../block/util";import {hideElements} from "../ui/hideElements";@@ -311,6 +313,7 @@ export const onTransaction = (protyle: IProtyle, operation: IOperation, focus: bendOffset: range.endOffset,};}+ /// #if !MOBILEif (!updateElement) {// 打开两个相同的文档 A、A1,从 A 拖拽块 B 到 A1,在后续 ws 处理中,无法获取到拖拽出去的 BgetAllModels().editor.forEach(editor => {@@ -320,6 +323,7 @@ export const onTransaction = (protyle: IProtyle, operation: IOperation, focus: b}});}+ /// #endifif (operation.previousID) {let beforeElement: Element;Array.from(protyle.wysiwyg.element.querySelectorAll(`[data-node-id="${operation.previousID}"]`)).find(item => {diff --git a/app/src/util/processMessage.ts b/app/src/util/processMessage.tsindex 279ad2c6df..3f985ac42b 100644--- a/app/src/util/processMessage.ts+++ b/app/src/util/processMessage.ts@@ -1,6 +1,7 @@import {hideMessage, showMessage} from "../dialog/message";+/// #if !MOBILEimport {exportLayout} from "../layout/util";-import {isMobile} from "./functions";+/// #endifexport const processMessage = (response: IWebSocketData) => {if ("msg" === response.cmd) {@@ -19,11 +20,11 @@ export const processMessage = (response: IWebSocketData) => {return false;}if ("reloadui" === response.cmd) {- if (isMobile()) {- window.location.reload();- } else {- exportLayout(true);- }+ /// #if MOBILE+ window.location.reload();+ /// #else+ exportLayout(true);+ /// #endifreturn false;}