An open-source, privacy-first, self-hosted knowledge workspace where humans and AI agents work together 开源、隐私优先、自托管的知识工作空间,让人与智能体在此协作
TypeScript agentic-aiai-agentknowledge-baselocal-firstmarkdownmcpmindmapnote-takingself-hostedsiyuanworkspace
:sparkles: Show mobile backlinks in a bottom sheet https://github.com/siyuan-note/siyuan/issues/19250
Daniel821ef4f6ac2d
diff --git a/app/src/assets/scss/protyle/_protyle.scss b/app/src/assets/scss/protyle/_protyle.scssindex 4c7feb3916..c4683205e4 100644--- a/app/src/assets/scss/protyle/_protyle.scss+++ b/app/src/assets/scss/protyle/_protyle.scss@@ -14,6 +14,14 @@top: 30px;width: 16px;bottom: 9px; // 下图标 hover 时,需要留出一定的空间+ // 空白区域透传点击,避免遮挡编辑器右侧的反链计数。+ pointer-events: none;++ &__down,+ &__up,+ &__bar {+ pointer-events: auto;+ }svg {height: 16px;diff --git a/app/src/mobile/util/openBacklinks.ts b/app/src/mobile/util/openBacklinks.tsnew file mode 100644index 0000000000..dd895b218e--- /dev/null+++ b/app/src/mobile/util/openBacklinks.ts@@ -0,0 +1,39 @@+import {Constants} from "../../constants";+import {fetchPost} from "../../util/fetch";+import {isEncryptedBox} from "../../util/pathName";+import {Tree} from "../../util/Tree";+import {openMobileFileById} from "../editor";+import {activeBlur} from "./keyboardToolbar";++export const openMobileBacklinks = (protyle: IProtyle, blockId: string) => {+ activeBlur();+ const menu = window.siyuan.menus.menu;+ menu.remove();+ const element = document.createElement("div");+ const titleElement = document.createElement("div");+ titleElement.className = "b3-menu__item b3-menu__item--readonly";+ titleElement.textContent = window.siyuan.languages.backlinks;+ const listElement = document.createElement("div");+ element.append(titleElement, listElement);+ menu.append(element);+ menu.fullscreen("bottom");+ const param: IObject = {id: blockId, beforeLen: 10, k: "", mk: "", includeMentions: false};+ if (isEncryptedBox(protyle.notebookId)) {+ param.notebook = protyle.notebookId;+ }+ fetchPost("/api/ref/getBacklink", param, response => {+ if (!element.isConnected || menu.element.classList.contains("fn__none")) {+ return;+ }+ const tree = new Tree({+ element: listElement,+ data: response.data.backlinks,+ click(target) {+ menu.remove();+ openMobileFileById(protyle.app, target.getAttribute("data-node-id"),+ [Constants.CB_GET_HL, Constants.CB_GET_CONTEXT, Constants.CB_GET_ROOTSCROLL]);+ }+ });+ tree.expandAll();+ });+};diff --git a/app/src/protyle/header/Title.ts b/app/src/protyle/header/Title.tsindex 3c922f7eca..0f6ff9da36 100644--- a/app/src/protyle/header/Title.ts+++ b/app/src/protyle/header/Title.ts@@ -313,6 +313,11 @@ export class Title {this.element.querySelector(".protyle-attr").addEventListener("click", (event: MouseEvent & {target: HTMLElement}) => {+ /// #if MOBILE+ if (event.target.closest(".protyle-attr--refcount") && commonClick(event, protyle)) {+ return;+ }+ /// #endifconst docInfoParam: IObject = {id: protyle.block.rootID};diff --git a/app/src/protyle/wysiwyg/commonClick.ts b/app/src/protyle/wysiwyg/commonClick.tsindex f2d3cbbbd5..be0f579b2f 100644--- a/app/src/protyle/wysiwyg/commonClick.ts+++ b/app/src/protyle/wysiwyg/commonClick.ts@@ -7,11 +7,26 @@ import {isMobile} from "../../util/functions";import {isOnlyMeta} from "../util/compatibility";import {hasClosestBlock} from "../util/hasClosest";import {zoomOut} from "../../menus/protyle";+/// #if MOBILE+import {openMobileBacklinks} from "../../mobile/util/openBacklinks";+/// #endifexport const commonClick = (event: MouseEvent & {target: HTMLElement}, protyle: IProtyle, data?: Record<string, string>) => {const isM = isMobile();+ /// #if MOBILE+ const attrRefCountElement = hasClosestByClassName(event.target, "protyle-attr--refcount");+ if (isM && attrRefCountElement) {+ const blockId = attrRefCountElement.parentElement.parentElement.getAttribute("data-node-id");+ if (blockId) {+ openMobileBacklinks(protyle, blockId);+ }+ event.preventDefault();+ event.stopPropagation();+ return true;+ }+ /// #endifconst attrBookmarkElement = hasClosestByClassName(event.target, "protyle-attr--bookmark");if (attrBookmarkElement) {if (!isM && isOnlyMeta(event)) {diff --git a/app/src/protyle/wysiwyg/index.ts b/app/src/protyle/wysiwyg/index.tsindex a184adae54..ec1b0b3019 100644--- a/app/src/protyle/wysiwyg/index.ts+++ b/app/src/protyle/wysiwyg/index.ts@@ -4458,6 +4458,12 @@ export class WYSIWYG {event.stopPropagation();return;}+ /// #if MOBILE+ if (hasClosestByClassName(event.target, "protyle-attr--refcount") && commonClick(event, protyle)) {+ mobileBlur = true;+ return;+ }+ /// #endifconst openListItemAttrByShift = shouldOpenListItemAttr(event.shiftKey, protyle.disabled,hasClosestByClassName(event.target, "protyle-action"));const shiftAssetElement = hasClosestByAttribute(event.target, "data-type", "file-annotation-ref") ||diff --git a/kernel/api/ref.go b/kernel/api/ref.goindex 158e2acdf1..0b0a406af9 100644--- a/kernel/api/ref.go+++ b/kernel/api/ref.go@@ -319,6 +319,10 @@ func getBacklink(c *gin.Context) {id := arg["id"].(string)keyword := arg["k"].(string)mentionKeyword := arg["mk"].(string)+ includeMentions := true+ if val, ok := arg["includeMentions"].(bool); ok {+ includeMentions = val+ }beforeLen := 12if nil != arg["beforeLen"] {beforeLen = int(arg["beforeLen"].(float64))@@ -339,9 +343,9 @@ func getBacklink(c *gin.Context) {return}if notebook != "" && model.IsEncryptedBox(notebook) {- boxID, backlinks, backmentions, linkRefsCount, mentionsCount = model.GetBacklinkInBox(id, keyword, mentionKeyword, beforeLen, containChildren, notebook)+ boxID, backlinks, backmentions, linkRefsCount, mentionsCount = model.GetBacklinkInBoxWithOptions(id, keyword, mentionKeyword, beforeLen, containChildren, notebook, includeMentions)} else {- boxID, backlinks, backmentions, linkRefsCount, mentionsCount = model.GetBacklink(id, keyword, mentionKeyword, beforeLen, containChildren)+ boxID, backlinks, backmentions, linkRefsCount, mentionsCount = model.GetBacklinkInBoxWithOptions(id, keyword, mentionKeyword, beforeLen, containChildren, "", includeMentions)}}if model.IsReadOnlyRoleContext(c) {@@ -360,5 +364,7 @@ func getBacklink(c *gin.Context) {"mk": mentionKeyword,"box": boxID,}- util.RandomSleep(200, 500)+ if includeMentions {+ util.RandomSleep(200, 500)+ }}diff --git a/kernel/model/backlink.go b/kernel/model/backlink.goindex 6966149d7a..3375870a57 100644--- a/kernel/model/backlink.go+++ b/kernel/model/backlink.go@@ -686,6 +686,11 @@ func GetBacklink(id, keyword, mentionKeyword string, beforeLen int, containChild// GetBacklinkInBox 与 GetBacklink 一致,但按 boxID 路由到加密 db 或全局 db。func GetBacklinkInBox(id, keyword, mentionKeyword string, beforeLen int, containChildren bool, boxID string) (boxIDOut string, linkPaths, mentionPaths []*Path, linkRefsCount, mentionsCount int) {+ return GetBacklinkInBoxWithOptions(id, keyword, mentionKeyword, beforeLen, containChildren, boxID, true)+}++// GetBacklinkInBoxWithOptions 按笔记本查询反链,并按需搜索提及。+func GetBacklinkInBoxWithOptions(id, keyword, mentionKeyword string, beforeLen int, containChildren bool, boxID string, includeMentions bool) (boxIDOut string, linkPaths, mentionPaths []*Path, linkRefsCount, mentionsCount int) {linkPaths = []*Path{}mentionPaths = []*Path{}@@ -794,6 +799,9 @@ func GetBacklinkInBox(id, keyword, mentionKeyword string, beforeLen int, contain}linkPaths = toSubTreeInBox(linkRefs, keyword, boxID, originalRefBlockIDs)+ if !includeMentions {+ return+ }mentions, _ := buildTreeBackmentionInBox(sqlBlock, linkRefs, mentionKeyword, excludeBacklinkIDs, beforeLen, boxID)mentionsCount = len(mentions)mentionPaths = toFlatTree(mentions, 0, "backlink", nil)