An open-source, privacy-first, self-hosted knowledge workspace where humans and AI agents work together 开源、隐私优先、自托管的知识工作空间,让人与智能体在此协作
TypeScript agentic-aiai-agentknowledge-baselocal-firstmarkdownmcpmindmapnote-takingself-hostedsiyuanworkspace
:art: https://github.com/siyuan-note/siyuan/pull/17651
Vanessafe1c5a01d390
diff --git a/app/src/boot/globalEvent/keydown.ts b/app/src/boot/globalEvent/keydown.tsindex 13f3319dd8..c026c3a3f9 100644--- a/app/src/boot/globalEvent/keydown.ts+++ b/app/src/boot/globalEvent/keydown.ts@@ -38,9 +38,8 @@ import {unicode2Emoji} from "../../emoji";import {deleteFiles} from "../../editor/deleteFile";import {escapeHtml} from "../../util/escape";import {syncGuide} from "../../sync/syncGuide";-import {duplicateBlock, foldRecursiveHotkey, getStartEndElement, goEnd, goHome} from "../../protyle/wysiwyg/commonHotkey";-import {getNextFileLi, getPreviousFileLi, getTopAloneElement} from "../../protyle/wysiwyg/getBlock";-import {foldBlocksRecursively} from "../../protyle/util/blockFold";+import {duplicateBlock, getStartEndElement, goEnd, goHome} from "../../protyle/wysiwyg/commonHotkey";+import {getNextFileLi, getPreviousFileLi} from "../../protyle/wysiwyg/getBlock";import {Backlink} from "../../layout/dock/Backlink";/// #if !BROWSERimport {setZoom} from "../../layout/topBar";@@ -353,10 +352,6 @@ const editKeydown = (app: App, event: KeyboardEvent) => {return true;}- if (!isFileFocus && !event.repeat && !protyle.disabled && foldRecursiveHotkey(protyle, event, hasClosestBlock(range.startContainer))) {- return true;- }-const target = event.target as HTMLElement;if (target.tagName !== "TABLE" && ["INPUT", "TEXTAREA"].includes(target.tagName)) {return false;diff --git a/app/src/menus/protyle.ts b/app/src/menus/protyle.tsindex befcb81c09..f2ec93811d 100644--- a/app/src/menus/protyle.ts+++ b/app/src/menus/protyle.ts@@ -28,7 +28,6 @@ import {openMenu} from "./commonMenuItem";import {fetchPost, fetchSyncPost} from "../util/fetch";import {Constants} from "../constants";import {copyPlainText, readClipboard, setStorageVal, updateHotkeyTip, writeText} from "../protyle/util/compatibility";-import {preventScroll} from "../protyle/scroll/preventScroll";import {onGet} from "../protyle/util/onGet";import {getAllModels} from "../layout/getAll";import {paste, pasteAsPlainText, pasteEscaped} from "../protyle/util/paste";@@ -38,8 +37,6 @@ import {openGlobalSearch} from "../search/util";import {openNewWindowById} from "../window/openNewWindow";/// #endifimport {getSearch, isMobile} from "../util/functions";-import {removeFoldHeading} from "../protyle/util/heading";-import {lineNumberRender} from "../protyle/render/highlightRender";import * as dayjs from "dayjs";import {blockRender} from "../protyle/render/blockRender";import {renameAsset} from "../editor/rename";@@ -62,10 +59,10 @@ import {popSearch} from "../mobile/menu/search";import {showMessage} from "../dialog/message";import {img3115} from "../boot/compatibleVersion";import {hideTooltip} from "../dialog/tooltip";-import {clearSelect} from "../protyle/util/clear";import {scrollCenter} from "../util/highlightById";import {base64ToURL} from "../util/image";import {setPosition} from "../util/setPosition";+import {setFold} from "../protyle/util/blockFold";const renderAssetList = (element: Element, k: string, position: IPosition, exts: string[] = []) => {fetchPost("/api/search/searchAsset", {@@ -2566,5 +2563,3 @@ export const setFoldById = (data: {}});};--export {foldBlocksRecursively, setFold} from "../protyle/util/blockFold";diff --git a/app/src/protyle/gutter/index.ts b/app/src/protyle/gutter/index.tsindex 54e6f61af9..7c516f0ccf 100644--- a/app/src/protyle/gutter/index.ts+++ b/app/src/protyle/gutter/index.ts@@ -2058,18 +2058,16 @@ export class Gutter {focusBlock(nodeElement);}}).element);- if (type === "NodeHeading" || ((type === "NodeListItem" || type === "NodeBlockquote" || type === "NodeSuperBlock") && nodeElement.childElementCount > 3)) {- window.siyuan.menus.menu.append(new MenuItem({- id: "foldRecursive",- icon: "iconFoldUnFold",- label: window.siyuan.languages.foldRecursive || "Fold/Expand recursively",- accelerator: window.siyuan.config.keymap.editor.general.foldRecursive?.custom,- click() {- foldBlocksRecursively(protyle, [nodeElement]);- focusBlock(nodeElement);- }- }).element);- }+ window.siyuan.menus.menu.append(new MenuItem({+ id: "foldRecursive",+ icon: "iconFoldUnFold",+ label: window.siyuan.languages.foldRecursive || "Fold/Expand recursively",+ accelerator: window.siyuan.config.keymap.editor.general.foldRecursive?.custom,+ click() {+ foldBlocksRecursively(protyle, [nodeElement]);+ focusBlock(nodeElement);+ }+ }).element);if (!protyle.disabled) {window.siyuan.menus.menu.append(new MenuItem({id: "attr",diff --git a/app/src/protyle/hint/index.ts b/app/src/protyle/hint/index.tsindex efc83556f0..7b4112f146 100644--- a/app/src/protyle/hint/index.ts+++ b/app/src/protyle/hint/index.ts@@ -16,7 +16,7 @@ import {getContenteditableElement, hasNextSibling, hasPreviousSibling} from "../import {transaction, updateTransaction} from "../wysiwyg/transaction";import {insertHTML} from "../util/insertHTML";import {highlightRender} from "../render/highlightRender";-import {assetMenu, imgMenu, setFold} from "../../menus/protyle";+import {assetMenu, imgMenu} from "../../menus/protyle";import {hideElements} from "../ui/hideElements";import {fetchPost} from "../../util/fetch";import {getDisplayName, pathPosix} from "../../util/pathName";@@ -42,6 +42,7 @@ import {isNotCtrl, isOnlyMeta} from "../util/compatibility";import {avRender} from "../render/av/render";import {genIconHTML} from "../render/util";import {updateAttrViewCellAnimation} from "../render/av/action";+import {setFold} from "../util/blockFold";export class Hint {public timeId: number;diff --git a/app/src/protyle/util/blockFold.ts b/app/src/protyle/util/blockFold.tsindex cc0ce4e050..acba47991e 100644--- a/app/src/protyle/util/blockFold.ts+++ b/app/src/protyle/util/blockFold.ts@@ -6,6 +6,7 @@ import {focusBlock} from "./selection";import {scrollCenter} from "../../util/highlightById";import {clearSelect} from "./clear";import {removeFoldHeading} from "./heading";+import {getTopAloneElement} from "../wysiwyg/getBlock";export const setFold = (protyle: IProtyle, nodeElement: Element, isOpen?: boolean,isRemove?: boolean, addLoading = true, getOperations = false) => {@@ -24,37 +25,33 @@ export const setFold = (protyle: IProtyle, nodeElement: Element, isOpen?: booleareturn {fold: -1};}nodeElement.removeAttribute("fold");- if (!getOperations) {- // https://github.com/siyuan-note/siyuan/issues/4411- nodeElement.querySelectorAll(".protyle-linenumber__rows").forEach((item: HTMLElement) => {- lineNumberRender(item.parentElement);- });- }+ // https://github.com/siyuan-note/siyuan/issues/4411+ nodeElement.querySelectorAll(".protyle-linenumber__rows").forEach((item: HTMLElement) => {+ lineNumberRender(item.parentElement);+ });} else {if (typeof isOpen === "boolean" && isOpen) {return {fold: -1};}nodeElement.setAttribute("fold", "1");- if (!getOperations) {- // 光标在子列表中,再次 focus 段尾的时候不会变 https://ld246.com/article/1647099132461- if (getSelection().rangeCount > 0) {- const range = getSelection().getRangeAt(0);- const blockElement = hasClosestBlock(range.startContainer);- if (blockElement && blockElement.getBoundingClientRect().width === 0) {- // https://github.com/siyuan-note/siyuan/issues/5833- focusBlock(nodeElement, undefined, false);- }+ // 光标在子列表中,再次 focus 段尾的时候不会变 https://ld246.com/article/1647099132461+ if (getSelection().rangeCount > 0) {+ const range = getSelection().getRangeAt(0);+ const blockElement = hasClosestBlock(range.startContainer);+ if (blockElement && blockElement.getBoundingClientRect().width === 0) {+ // https://github.com/siyuan-note/siyuan/issues/5833+ focusBlock(nodeElement, undefined, false);}- clearSelect(["img", "av"], nodeElement);- scrollCenter(protyle, nodeElement);}+ clearSelect(["img", "av"], nodeElement);+ scrollCenter(protyle, nodeElement);}const id = nodeElement.getAttribute("data-node-id");const doOperations: IOperation[] = [];const undoOperations: IOperation[] = [];if (nodeElement.getAttribute("data-type") === "NodeHeading") {if (hasFold) {- if (addLoading && !getOperations) {+ if (addLoading) {nodeElement.insertAdjacentHTML("beforeend", '<div spin="1" style="text-align: center"><img width="24px" height="24px" src="/stage/loading-pure.svg"></div>');}doOperations.push({@@ -190,3 +187,24 @@ export const foldBlocksRecursively = (protyle: IProtyle, nodeElements: Element[]scrollCenter(protyle, elementsToFold[0]);}};++export const foldRecursiveHotkey = (protyle: IProtyle, nodeElement: HTMLElement) => {+ const selectElements = Array.from(protyle.wysiwyg.element.querySelectorAll(".protyle-wysiwyg--select"));+ if (selectElements.length > 0) {+ foldBlocksRecursively(protyle, selectElements);+ } else if (nodeElement) {+ const nodeType = nodeElement.getAttribute("data-type");+ if (nodeElement.parentElement.getAttribute("data-type") === "NodeListItem") {+ if (nodeElement.parentElement.childElementCount > 3) {+ foldBlocksRecursively(protyle, [nodeElement.parentElement]);+ } else {+ foldBlocksRecursively(protyle, [nodeElement]);+ }+ } else if (nodeType === "NodeHeading") {+ foldBlocksRecursively(protyle, [nodeElement]);+ } else {+ foldBlocksRecursively(protyle, [getTopAloneElement(nodeElement)]);+ }+ }+ return true;+};diff --git a/app/src/protyle/util/editorCommonEvent.ts b/app/src/protyle/util/editorCommonEvent.tsindex a8cc1a8f58..61b0603ffb 100644--- a/app/src/protyle/util/editorCommonEvent.ts+++ b/app/src/protyle/util/editorCommonEvent.ts@@ -26,7 +26,7 @@ import {isBrowser} from "../../util/functions";import {hideElements} from "../ui/hideElements";import {insertAttrViewBlockAnimation} from "../render/av/row";import * as dayjs from "dayjs";-import {setFold, zoomOut} from "../../menus/protyle";+import {zoomOut} from "../../menus/protyle";/// #if !BROWSERimport {webUtils} from "electron";import {dragUpload} from "../render/av/asset";@@ -38,6 +38,7 @@ import {processClonePHElement} from "../render/util";import {insertGalleryItemAnimation} from "../render/av/gallery/item";import {clearSelect} from "./clear";import {dragoverTab} from "../render/av/view";+import {setFold} from "./blockFold";// position: afterbegin 为拖拽成超级块; "afterend", "beforebegin" 一般拖拽const moveTo = async (protyle: IProtyle, sourceElements: Element[], targetElement: Element,diff --git a/app/src/protyle/util/insertHTML.ts b/app/src/protyle/util/insertHTML.tsindex a4580db97b..8d612a5cf3 100644--- a/app/src/protyle/util/insertHTML.ts+++ b/app/src/protyle/util/insertHTML.ts@@ -21,7 +21,7 @@ import {fetchPost} from "../../util/fetch";import {isIncludeCell} from "./table";import {getFieldIdByCellElement} from "../render/av/row";import {processClonePHElement} from "../render/util";-import {setFold} from "../../menus/protyle";+import {setFold} from "./blockFold";const processAV = (range: Range, html: string, protyle: IProtyle, blockElement: HTMLElement) => {const tempElement = document.createElement("template");diff --git a/app/src/protyle/wysiwyg/commonHotkey.ts b/app/src/protyle/wysiwyg/commonHotkey.tsindex d2a92c1627..549317b80b 100644--- a/app/src/protyle/wysiwyg/commonHotkey.ts+++ b/app/src/protyle/wysiwyg/commonHotkey.ts@@ -15,8 +15,7 @@ import {processClonePHElement} from "../render/util";import {copyTextByType} from "../toolbar/util";import {hasClosestByTag, hasTopClosestByClassName} from "../util/hasClosest";import {removeEmbed} from "./removeEmbed";-import {clearBlockElement, clearSelect} from "../util/clear";-import {foldBlocksRecursively} from "../util/blockFold";+import {clearBlockElement} from "../util/clear";export const commonHotkey = (protyle: IProtyle, event: KeyboardEvent, nodeElement?: HTMLElement) => {if (matchHotKey(window.siyuan.config.keymap.editor.general.netImg2LocalAsset.custom, event)) {@@ -96,10 +95,6 @@ export const commonHotkey = (protyle: IProtyle, event: KeyboardEvent, nodeElemenreturn true;}- if (foldRecursiveHotkey(protyle, event, nodeElement)) {- return true;- }-if (matchHotKey(window.siyuan.config.keymap.editor.general.copyBlockEmbed.custom, event)) {if (nodeElement) {const selectElements = Array.from(protyle.wysiwyg.element.querySelectorAll(".protyle-wysiwyg--select"));@@ -466,30 +461,3 @@ export const alignImgLeft = (protyle: IProtyle, nodeElement: Element, assetEleme});updateTransaction(protyle, id, nodeElement.outerHTML, html);};--export const foldRecursiveHotkey = (protyle: IProtyle, event: KeyboardEvent, nodeElement: HTMLElement) => {- if (window.siyuan.config.keymap.editor.general.foldRecursive && matchHotKey(window.siyuan.config.keymap.editor.general.foldRecursive.custom, event) && !event.repeat) {- const selectElements = Array.from(protyle.wysiwyg.element.querySelectorAll(".protyle-wysiwyg--select"));- if (selectElements.length > 0) {- foldBlocksRecursively(protyle, selectElements);- } else if (nodeElement) {- const nodeType = nodeElement.getAttribute("data-type");- if (nodeElement.parentElement.getAttribute("data-type") === "NodeListItem") {- if (nodeElement.parentElement.childElementCount > 3) {- foldBlocksRecursively(protyle, [nodeElement.parentElement]);- } else {- foldBlocksRecursively(protyle, [nodeElement]);- }- } else if (nodeType === "NodeHeading") {- foldBlocksRecursively(protyle, [nodeElement]);- } else {- foldBlocksRecursively(protyle, [getTopAloneElement(nodeElement)]);- }- }- event.stopPropagation();- event.preventDefault();- return true;- }- return false;-};-diff --git a/app/src/protyle/wysiwyg/index.ts b/app/src/protyle/wysiwyg/index.tsindex cba84e6ef3..75e6fbff6b 100644--- a/app/src/protyle/wysiwyg/index.ts+++ b/app/src/protyle/wysiwyg/index.ts@@ -29,7 +29,6 @@ import {inlineMathMenu,linkMenu,refMenu,- setFold,tagMenu,zoomOut} from "../../menus/protyle";@@ -104,6 +103,7 @@ import {chartRender} from "../render/chartRender";import {reloadProtyle} from "../util/reload";import {updateCalloutType} from "./callout";import {nbsp2space, removeZWJ} from "../util/normalizeText";+import {setFold} from "../util/blockFold";export class WYSIWYG {public lastHTMLs: { [key: string]: string } = {};diff --git a/app/src/protyle/wysiwyg/input.ts b/app/src/protyle/wysiwyg/input.tsindex 44a2496309..036aedbd13 100644--- a/app/src/protyle/wysiwyg/input.ts+++ b/app/src/protyle/wysiwyg/input.ts@@ -12,7 +12,7 @@ import {hasClosestByAttribute, hasClosestByClassName, isInEmbedBlock} from "../uimport {fetchPost, fetchSyncPost} from "../../util/fetch";import {headingTurnIntoList, turnIntoTaskList} from "./turnIntoList";import {updateAVName} from "../render/av/action";-import {setFold} from "../../menus/protyle";+import {setFold} from "../util/blockFold";export const input = async (protyle: IProtyle, blockElement: HTMLElement, range: Range, needRender = true, event?: InputEvent) => {if (!blockElement.parentElement) {diff --git a/app/src/protyle/wysiwyg/keydown.ts b/app/src/protyle/wysiwyg/keydown.tsindex 07872a9d7a..07c78c727a 100644--- a/app/src/protyle/wysiwyg/keydown.ts+++ b/app/src/protyle/wysiwyg/keydown.ts@@ -53,9 +53,9 @@ import {isLocalPath} from "../../util/pathName";/// #if !MOBILEimport {openBy, openFileById} from "../../editor/util";/// #endif-import {alignImgCenter, alignImgLeft, commonHotkey, downSelect, foldRecursiveHotkey, getStartEndElement, upSelect} from "./commonHotkey";+import {alignImgCenter, alignImgLeft, commonHotkey, downSelect, getStartEndElement, upSelect} from "./commonHotkey";import {fileAnnotationRefMenu, inlineMathMenu, linkMenu, refMenu, tagMenu} from "../../menus/protyle";-import {foldBlocksRecursively, setFold} from "../util/blockFold";+import {foldRecursiveHotkey, setFold} from "../util/blockFold";import {openAttr} from "../../menus/commonMenuItem";import {Constants} from "../../constants";import {fetchPost} from "../../util/fetch";@@ -331,8 +331,11 @@ export const keydown = (protyle: IProtyle, editorElement: HTMLElement) => {return false;}- if (foldRecursiveHotkey(protyle, event, nodeElement)) {- return true;+ if (matchHotKey(window.siyuan.config.keymap.editor.general.foldRecursive.custom, event) && !event.repeat) {+ foldRecursiveHotkey(protyle, nodeElement);+ event.stopPropagation();+ event.preventDefault();+ return;}if (matchHotKey(window.siyuan.config.keymap.editor.general.expand.custom, event) && !event.repeat) {diff --git a/app/src/protyle/wysiwyg/list.ts b/app/src/protyle/wysiwyg/list.tsindex da16e938a3..657f5ce4d7 100644--- a/app/src/protyle/wysiwyg/list.ts+++ b/app/src/protyle/wysiwyg/list.ts@@ -5,8 +5,8 @@ import * as dayjs from "dayjs";import {Constants} from "../../constants";import {moveToPrevious, removeBlock} from "./remove";import {hasClosestByClassName} from "../util/hasClosest";-import {setFold} from "../../menus/protyle";import {getParentBlock} from "./getBlock";+import {setFold} from "../util/blockFold";export const updateListOrder = (listElement: Element, sIndex?: number) => {if (listElement.getAttribute("data-subtype") !== "o") {diff --git a/app/src/protyle/wysiwyg/remove.ts b/app/src/protyle/wysiwyg/remove.tsindex c598a522df..7b1b1324bc 100644--- a/app/src/protyle/wysiwyg/remove.ts+++ b/app/src/protyle/wysiwyg/remove.ts@@ -18,7 +18,7 @@ import {import {transaction, turnsIntoOneTransaction, turnsIntoTransaction, updateTransaction} from "./transaction";import {cancelSB, genEmptyElement} from "../../block/util";import {listOutdent, updateListOrder} from "./list";-import {setFold, zoomOut} from "../../menus/protyle";+import {zoomOut} from "../../menus/protyle";import {preventScroll} from "../scroll/preventScroll";import {hideElements} from "../ui/hideElements";import {Constants} from "../../constants";@@ -31,6 +31,7 @@ import {Tab} from "../../layout/Tab";import {Backlink} from "../../layout/dock/Backlink";import {fetchPost, fetchSyncPost} from "../../util/fetch";import {onGet} from "../util/onGet";+import {setFold} from "../util/blockFold";export const removeBlock = async (protyle: IProtyle, blockElement: Element, range: Range, type: "Delete" | "Backspace" | "remove") => {protyle.observerLoad?.disconnect();diff --git a/app/src/protyle/wysiwyg/transaction.ts b/app/src/protyle/wysiwyg/transaction.tsindex 69b6b348f7..5147fef458 100644--- a/app/src/protyle/wysiwyg/transaction.ts+++ b/app/src/protyle/wysiwyg/transaction.ts@@ -6,7 +6,7 @@ import {blockRender} from "../render/blockRender";import {processRender} from "../util/processCode";import {highlightRender} from "../render/highlightRender";import {hasClosestBlock, hasClosestByAttribute, hasTopClosestByAttribute, isInEmbedBlock} from "../util/hasClosest";-import {setFold, zoomOut} from "../../menus/protyle";+import {zoomOut} from "../../menus/protyle";import {disabledProtyle, enableProtyle, onGet} from "../util/onGet";/// #if !MOBILEimport {getAllModels} from "../../layout/getAll";@@ -21,6 +21,7 @@ import {isPaidUser, needSubscribe} from "../../util/needSubscribe";import {resize} from "../util/resize";import {processClonePHElement} from "../render/util";import {scrollCenter} from "../../util/highlightById";+import {setFold} from "../util/blockFold";const removeTopElement = (updateElement: Element, protyle: IProtyle) => {// 移动到其他文档中,该块需移除