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/issues/11637
Vanessa80ebf8586c2a
diff --git a/app/src/search/spread.ts b/app/src/search/spread.tsindex 3b4a266426..43481fd8c1 100644--- a/app/src/search/spread.ts+++ b/app/src/search/spread.ts@@ -1,9 +1,9 @@import {getNotebookName, pathPosix} from "../util/pathName";import {Constants} from "../constants";import {Dialog} from "../dialog";-import {fetchSyncPost} from "../util/fetch";+import {fetchPost, fetchSyncPost} from "../util/fetch";import {focusByRange} from "../protyle/util/selection";-import {genSearch} from "./util";+import {genSearch, updateConfig} from "./util";import {App} from "../index";export const openSearch = async (options: {@@ -13,49 +13,6 @@ export const openSearch = async (options: {notebookId?: string,searchPath?: string}) => {- // 全局搜索中使用 ctrl+F 需继续执行 https://ld246.com/article/1716632837934- let globalToPath = false;- const exitDialog = window.siyuan.dialogs.find((item) => {- if (item.element.querySelector("#searchList")) {- const lastKey = item.element.getAttribute("data-key");- if (lastKey === Constants.DIALOG_GLOBALSEARCH && options.hotkey === Constants.DIALOG_SEARCH) {- globalToPath = true;- }- const replaceHeaderElement = item.element.querySelectorAll(".search__header")[1];- if (lastKey !== options.hotkey && options.hotkey === Constants.DIALOG_REPLACE && replaceHeaderElement.classList.contains("fn__none")) {- replaceHeaderElement.classList.remove("fn__none");- item.element.setAttribute("data-key", options.hotkey);- return true;- }- const searchPathElement = item.element.querySelector("#searchPathInput");- if (lastKey !== options.hotkey && options.hotkey === Constants.DIALOG_GLOBALSEARCH) {- if (searchPathElement.textContent !== "") {- item.destroy();- return false;- } else if (!replaceHeaderElement.classList.contains("fn__none")) {- replaceHeaderElement.classList.add("fn__none");- item.element.setAttribute("data-key", options.hotkey);- return true;- }- }- if (lastKey !== options.hotkey && options.hotkey === Constants.DIALOG_SEARCH) {- if (searchPathElement.textContent === "") {- item.destroy();- return false;- } else if (!replaceHeaderElement.classList.contains("fn__none")) {- replaceHeaderElement.classList.add("fn__none");- item.element.setAttribute("data-key", options.hotkey);- return true;- }- }- // 切换关闭- item.destroy();- return true;- }- });- if (exitDialog && !globalToPath) {- return;- }const localData = window.siyuan.storage[Constants.LOCAL_SEARCHDATA];let hPath = "";let idPath: string[] = [];@@ -79,7 +36,56 @@ export const openSearch = async (options: {idPath = localData.idPath;}}-+ const config = {+ removed: localData.removed,+ k: options.key || localData.k,+ r: localData.r,+ hasReplace: options.hotkey === Constants.DIALOG_REPLACE,+ method: localData.method,+ hPath,+ idPath,+ group: localData.group,+ sort: localData.sort,+ types: Object.assign({}, localData.types),+ replaceTypes: Object.assign({}, localData.replaceTypes),+ page: options.key ? 1 : localData.page+ };+ // 搜索中继续执行 ctrl+F/P 不退出 https://github.com/siyuan-note/siyuan/issues/11637+ const exitDialog = window.siyuan.dialogs.find((item) => {+ // 再次打开+ if (item.element.querySelector("#searchList")) {+ const searchElement = item.element.querySelector(".b3-dialog__body")+ const cloneData = JSON.parse(JSON.stringify(item.data)) as Config.IUILayoutTabSearchConfig;+ const selectText = getSelection().rangeCount > 0 ? getSelection().getRangeAt(0).toString() : undefined;+ if (selectText) {+ cloneData.k = selectText;+ }+ item.element.setAttribute("data-key", options.hotkey);+ if (options.hotkey === Constants.DIALOG_REPLACE) {+ cloneData.hasReplace = true;+ updateConfig(searchElement, cloneData, item.data, item.editors.edit);+ } else if (options.hotkey === Constants.DIALOG_GLOBALSEARCH) {+ cloneData.hasReplace = false;+ cloneData.hPath = "";+ cloneData.idPath = [];+ updateConfig(searchElement, cloneData, item.data, item.editors.edit);+ } else if (options.hotkey === Constants.DIALOG_SEARCH) {+ cloneData.hasReplace = false;+ const toPath = item.editors.edit.protyle.path+ fetchPost("/api/filetree/getHPathsByPaths", {paths: [toPath]}, (response) => {+ cloneData.idPath = [pathPosix().join(item.editors.edit.protyle.notebookId, toPath)];+ cloneData.hPath = response.data[0];+ item.data.idPath = cloneData.idPath+ item.data.hPath = cloneData.hPath+ updateConfig(searchElement, cloneData, item.data, item.editors.edit);+ });+ }+ return true;+ }+ });+ if (exitDialog) {+ return;+ }let range: Range;if (getSelection().rangeCount > 0) {range = getSelection().getRangeAt(0);@@ -107,20 +113,6 @@ export const openSearch = async (options: {}});dialog.element.setAttribute("data-key", options.hotkey);- const config = {- removed: localData.removed,- k: options.key || localData.k,- r: localData.r,- hasReplace: options.hotkey === Constants.DIALOG_REPLACE,- method: localData.method,- hPath,- idPath,- group: localData.group,- sort: localData.sort,- types: Object.assign({}, localData.types),- replaceTypes: Object.assign({}, localData.replaceTypes),- page: options.key ? 1 : localData.page- };dialog.editors = genSearch(options.app, config, dialog.element.querySelector(".b3-dialog__body"), () => {dialog.destroy({focus: "false"});});diff --git a/app/src/search/util.ts b/app/src/search/util.tsindex 92f8c9b3aa..afc98e16b5 100644--- a/app/src/search/util.ts+++ b/app/src/search/util.ts@@ -1072,7 +1072,7 @@ export const getQueryTip = (method: number) => {return methodTip;};-const updateConfig = (element: Element, item: Config.IUILayoutTabSearchConfig, config: Config.IUILayoutTabSearchConfig,+export const updateConfig = (element: Element, item: Config.IUILayoutTabSearchConfig, config: Config.IUILayoutTabSearchConfig,edit: Protyle, clear = false) => {const dialogElement = hasClosestByClassName(element, "b3-dialog--open");if (dialogElement && dialogElement.getAttribute("data-key") === Constants.DIALOG_SEARCH) {diff --git a/app/src/types/config.d.ts b/app/src/types/config.d.tsindex de739d7669..5d985ea860 100644--- a/app/src/types/config.d.ts+++ b/app/src/types/config.d.ts@@ -1925,7 +1925,7 @@ declare namespace Config {* - `1`: Group by document*/group: number;- hasReplace: any;+ hasReplace: boolean;/*** Readable path list*/@@ -1961,6 +1961,7 @@ declare namespace Config {r: string;/*** Whether to clear the search box after removing the currently used query condition group+ * 移除后需记录搜索内容 https://github.com/siyuan-note/siyuan/issues/7745*/removed?: boolean;replaceTypes: IUILayoutTabSearchConfigReplaceTypes;diff --git a/app/src/types/index.d.ts b/app/src/types/index.d.tsindex 92d21ef83b..48fffda606 100644--- a/app/src/types/index.d.ts+++ b/app/src/types/index.d.ts@@ -259,44 +259,6 @@ interface ISearchAssetOption {k: string,}-interface ISearchOption {- page: number- removed?: boolean // 移除后需记录搜索内容 https://github.com/siyuan-note/siyuan/issues/7745- name?: string- sort: number, // 0:按块类型(默认),1:按创建时间升序,2:按创建时间降序,3:按更新时间升序,4:按更新时间降序,5:按内容顺序(仅在按文档分组时),6:按相关度升序,7:按相关度降序- group: number, // 0:不分组,1:按文档分组- hasReplace: boolean,- method: number // 0:文本,1:查询语法,2:SQL,3:正则表达式- hPath: string- idPath: string[]- k: string- r: string- types: ISearchType,- replaceTypes: {- [key: string]: boolean;- },-}--interface ISearchType {- audioBlock: boolean- videoBlock: boolean- iframeBlock: boolean- widgetBlock: boolean- mathBlock: boolean- table: boolean- blockquote: boolean- superBlock: boolean- paragraph: boolean- document: boolean- heading: boolean- list: boolean- listItem: boolean- codeBlock: boolean- htmlBlock: boolean- embedBlock: boolean- databaseBlock: boolean-}-interface ITextOption {color?: string,type: string