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: Show backlinks at the bottom of documents https://github.com/siyuan-note/siyuan/issues/18319
Daniel484e3782963c
diff --git a/app/appearance/langs/ar.json b/app/appearance/langs/ar.jsonindex 6756697f41..335528b3cc 100644--- a/app/appearance/langs/ar.json+++ b/app/appearance/langs/ar.json@@ -1,4 +1,5 @@{+ "backlinkShowBottom": "إظهار الروابط المرجعية في أسفل المستند","databaseAttrHideEmpty": "إخفاء السمات الفارغة لقاعدة البيانات","databaseAttrUseTabs": "استخدام علامات تبويب لسمات قاعدة البيانات","rebuildHistoryIndex": "إعادة بناء فهرس السجل",diff --git a/app/appearance/langs/de.json b/app/appearance/langs/de.jsonindex 827349b8ff..cee3a40fc5 100644--- a/app/appearance/langs/de.json+++ b/app/appearance/langs/de.json@@ -1,4 +1,5 @@{+ "backlinkShowBottom": "Backlinks am Dokumentende anzeigen","databaseAttrHideEmpty": "Leere Datenbankattribute ausblenden","databaseAttrUseTabs": "Registerkarten für Datenbankattribute verwenden","rebuildHistoryIndex": "Verlaufsindex neu aufbauen",diff --git a/app/appearance/langs/en.json b/app/appearance/langs/en.jsonindex 09c13ea528..17750953bb 100644--- a/app/appearance/langs/en.json+++ b/app/appearance/langs/en.json@@ -1,4 +1,5 @@{+ "backlinkShowBottom": "Show backlinks at the bottom of the document","databaseAttrHideEmpty": "Hide empty database attributes","databaseAttrUseTabs": "Use tabs for database attributes","rebuildHistoryIndex": "Rebuild history index",diff --git a/app/appearance/langs/es.json b/app/appearance/langs/es.jsonindex 4fd0d26cc0..c59347fcc2 100644--- a/app/appearance/langs/es.json+++ b/app/appearance/langs/es.json@@ -1,4 +1,5 @@{+ "backlinkShowBottom": "Mostrar enlaces entrantes al final del documento","databaseAttrHideEmpty": "Ocultar atributos vacíos de la base de datos","databaseAttrUseTabs": "Usar pestañas para los atributos de la base de datos","rebuildHistoryIndex": "Reconstruir índice del historial",diff --git a/app/appearance/langs/fr.json b/app/appearance/langs/fr.jsonindex 59f66c5ce3..5fbfff8db1 100644--- a/app/appearance/langs/fr.json+++ b/app/appearance/langs/fr.json@@ -1,4 +1,5 @@{+ "backlinkShowBottom": "Afficher les backlinks au bas du document","databaseAttrHideEmpty": "Masquer les attributs de base de données vides","databaseAttrUseTabs": "Utiliser des onglets pour les attributs de base de données","rebuildHistoryIndex": "Reconstruire l'index de l'historique",diff --git a/app/appearance/langs/he.json b/app/appearance/langs/he.jsonindex db29702707..f996ac4dc6 100644--- a/app/appearance/langs/he.json+++ b/app/appearance/langs/he.json@@ -1,4 +1,5 @@{+ "backlinkShowBottom": "הצגת קישורים אחוריים בתחתית המסמך","databaseAttrHideEmpty": "הסתרת מאפייני מסד נתונים ריקים","databaseAttrUseTabs": "שימוש בכרטיסיות עבור מאפייני מסד נתונים","rebuildHistoryIndex": "בנה מחדש את אינדקס ההיסטוריה",diff --git a/app/appearance/langs/hi.json b/app/appearance/langs/hi.jsonindex 29efdde5ac..b29b2033a2 100644--- a/app/appearance/langs/hi.json+++ b/app/appearance/langs/hi.json@@ -1,4 +1,5 @@{+ "backlinkShowBottom": "दस्तावेज़ के नीचे बैकलिंक्स दिखाएँ","databaseAttrHideEmpty": "खाली डेटाबेस विशेषताएँ छिपाएँ","databaseAttrUseTabs": "डेटाबेस विशेषताओं के लिए टैब का उपयोग करें","rebuildHistoryIndex": "इतिहास इंडेक्स पुनर्निर्माण करें",diff --git a/app/appearance/langs/id.json b/app/appearance/langs/id.jsonindex a5de653855..cebcf09677 100644--- a/app/appearance/langs/id.json+++ b/app/appearance/langs/id.json@@ -1,4 +1,5 @@{+ "backlinkShowBottom": "Tampilkan pranala balik di bagian bawah dokumen","databaseAttrHideEmpty": "Sembunyikan atribut basis data yang kosong","databaseAttrUseTabs": "Gunakan tab untuk atribut basis data","rebuildHistoryIndex": "Bangun ulang indeks riwayat",diff --git a/app/appearance/langs/it.json b/app/appearance/langs/it.jsonindex 98356d6cf9..bade81680a 100644--- a/app/appearance/langs/it.json+++ b/app/appearance/langs/it.json@@ -1,4 +1,5 @@{+ "backlinkShowBottom": "Mostra i backlink in fondo al documento","databaseAttrHideEmpty": "Nascondi gli attributi vuoti del database","databaseAttrUseTabs": "Usa schede per gli attributi del database","rebuildHistoryIndex": "Ricostruisci indice cronologia",diff --git a/app/appearance/langs/ja.json b/app/appearance/langs/ja.jsonindex 7c854cc8b7..4db2d00261 100644--- a/app/appearance/langs/ja.json+++ b/app/appearance/langs/ja.json@@ -1,4 +1,5 @@{+ "backlinkShowBottom": "文書の下部にバックリンクを表示","databaseAttrHideEmpty": "空のデータベース属性を非表示","databaseAttrUseTabs": "データベース属性にタブを使用","rebuildHistoryIndex": "履歴インデックスを再構築",diff --git a/app/appearance/langs/ko.json b/app/appearance/langs/ko.jsonindex 8e7ca1fb05..b88518bffe 100644--- a/app/appearance/langs/ko.json+++ b/app/appearance/langs/ko.json@@ -1,4 +1,5 @@{+ "backlinkShowBottom": "문서 하단에 백링크 표시","databaseAttrHideEmpty": "빈 데이터베이스 속성 숨기기","databaseAttrUseTabs": "데이터베이스 속성에 탭 사용","rebuildHistoryIndex": "기록 인덱스 재구축",diff --git a/app/appearance/langs/nl.json b/app/appearance/langs/nl.jsonindex a8294864c8..75a4849c61 100644--- a/app/appearance/langs/nl.json+++ b/app/appearance/langs/nl.json@@ -1,4 +1,5 @@{+ "backlinkShowBottom": "Terugverwijzingen onderaan het document weergeven","databaseAttrHideEmpty": "Lege databasekenmerken verbergen","databaseAttrUseTabs": "Tabbladen gebruiken voor databasekenmerken","rebuildHistoryIndex": "Geschiedenisindex herbouwen",diff --git a/app/appearance/langs/pl.json b/app/appearance/langs/pl.jsonindex bc58b05a1e..62b5e342e6 100644--- a/app/appearance/langs/pl.json+++ b/app/appearance/langs/pl.json@@ -1,4 +1,5 @@{+ "backlinkShowBottom": "Pokaż odniesienia zwrotne na dole dokumentu","databaseAttrHideEmpty": "Ukryj puste atrybuty bazy danych","databaseAttrUseTabs": "Używaj kart dla atrybutów bazy danych","rebuildHistoryIndex": "Odbuduj indeks historii",diff --git a/app/appearance/langs/pt-BR.json b/app/appearance/langs/pt-BR.jsonindex 6a85e0ea5b..e46aa1e774 100644--- a/app/appearance/langs/pt-BR.json+++ b/app/appearance/langs/pt-BR.json@@ -1,4 +1,5 @@{+ "backlinkShowBottom": "Mostrar backlinks na parte inferior do documento","databaseAttrHideEmpty": "Ocultar atributos vazios do banco de dados","databaseAttrUseTabs": "Usar abas para atributos do banco de dados","rebuildHistoryIndex": "Reconstruir índice do histórico",diff --git a/app/appearance/langs/ru.json b/app/appearance/langs/ru.jsonindex b1c2a30d3d..2289cbbd98 100644--- a/app/appearance/langs/ru.json+++ b/app/appearance/langs/ru.json@@ -1,4 +1,5 @@{+ "backlinkShowBottom": "Показывать обратные ссылки внизу документа","databaseAttrHideEmpty": "Скрывать пустые атрибуты базы данных","databaseAttrUseTabs": "Использовать вкладки для атрибутов базы данных","rebuildHistoryIndex": "Перестроить индекс истории",diff --git a/app/appearance/langs/sk.json b/app/appearance/langs/sk.jsonindex b445f8a4d5..cf775fcfeb 100644--- a/app/appearance/langs/sk.json+++ b/app/appearance/langs/sk.json@@ -1,4 +1,5 @@{+ "backlinkShowBottom": "Zobraziť spätné odkazy v spodnej časti dokumentu","databaseAttrHideEmpty": "Skryť prázdne atribúty databázy","databaseAttrUseTabs": "Používať karty pre atribúty databázy","rebuildHistoryIndex": "Znovu vytvoriť index histórie",diff --git a/app/appearance/langs/th.json b/app/appearance/langs/th.jsonindex 0292316d0d..5344633250 100644--- a/app/appearance/langs/th.json+++ b/app/appearance/langs/th.json@@ -1,4 +1,5 @@{+ "backlinkShowBottom": "แสดงลิงก์ย้อนกลับที่ด้านล่างของเอกสาร","databaseAttrHideEmpty": "ซ่อนแอตทริบิวต์ฐานข้อมูลที่ว่างเปล่า","databaseAttrUseTabs": "ใช้แท็บสำหรับแอตทริบิวต์ฐานข้อมูล","rebuildHistoryIndex": "สร้างดัชนีประวัติใหม่",diff --git a/app/appearance/langs/tr.json b/app/appearance/langs/tr.jsonindex 8e6ff2ad0d..42e3c7d910 100644--- a/app/appearance/langs/tr.json+++ b/app/appearance/langs/tr.json@@ -1,4 +1,5 @@{+ "backlinkShowBottom": "Belgenin altında geri bağlantıları göster","databaseAttrHideEmpty": "Boş veritabanı özniteliklerini gizle","databaseAttrUseTabs": "Veritabanı öznitelikleri için sekmeleri kullan","rebuildHistoryIndex": "Geçmiş indeksini yeniden oluştur",diff --git a/app/appearance/langs/uk.json b/app/appearance/langs/uk.jsonindex 5b2c0fa93a..de5d729286 100644--- a/app/appearance/langs/uk.json+++ b/app/appearance/langs/uk.json@@ -1,4 +1,5 @@{+ "backlinkShowBottom": "Показувати зворотні посилання внизу документа","databaseAttrHideEmpty": "Приховувати порожні атрибути бази даних","databaseAttrUseTabs": "Використовувати вкладки для атрибутів бази даних","rebuildHistoryIndex": "Перебудувати індекс історії",diff --git a/app/appearance/langs/zh-CN.json b/app/appearance/langs/zh-CN.jsonindex db818176c5..54b6e76623 100644--- a/app/appearance/langs/zh-CN.json+++ b/app/appearance/langs/zh-CN.json@@ -1,4 +1,5 @@{+ "backlinkShowBottom": "在文档底部显示反链","databaseAttrHideEmpty": "数据库属性隐藏空字段","databaseAttrUseTabs": "数据库属性使用页签","rebuildHistoryIndex": "重建历史索引",diff --git a/app/appearance/langs/zh-TW.json b/app/appearance/langs/zh-TW.jsonindex 340285c96e..9860666c91 100644--- a/app/appearance/langs/zh-TW.json+++ b/app/appearance/langs/zh-TW.json@@ -1,4 +1,5 @@{+ "backlinkShowBottom": "在文件底部顯示反向連結","databaseAttrHideEmpty": "資料庫屬性隱藏空欄位","databaseAttrUseTabs": "資料庫屬性使用頁籤","rebuildHistoryIndex": "重建歷史索引",diff --git a/app/src/assets/scss/protyle/_protyle.scss b/app/src/assets/scss/protyle/_protyle.scssindex e4531e4290..adc734f81c 100644--- a/app/src/assets/scss/protyle/_protyle.scss+++ b/app/src/assets/scss/protyle/_protyle.scss@@ -358,6 +358,24 @@}}+.sy__backlink--bottom {+ box-sizing: border-box;+ min-height: 32px;+ outline: none;++ > .block__icons {+ border-top: 1px solid var(--b3-border-color);+ flex-shrink: 0;+ }++ > .backlinkList,+ > .backlinkMList {+ flex: none;+ min-height: auto;+ overflow: visible;+ }+}+.protyle-top:hover .protyle-background--enable {.protyle-background__action,.protyle-background__img .protyle-icons {diff --git a/app/src/boot/globalEvent/command/panel.ts b/app/src/boot/globalEvent/command/panel.tsindex 57fbbc40d0..802914a520 100644--- a/app/src/boot/globalEvent/command/panel.ts+++ b/app/src/boot/globalEvent/command/panel.ts@@ -216,7 +216,7 @@ export const execByCommand = async (options: {const activeTab = getActiveTab();if (!protyle && activeTab) {if (activeTab.model instanceof Editor) {- protyle = activeTab.model.editor.protyle;+ protyle = activeTab.model.getCurrentProtyle(range);} else if (activeTab.model instanceof Search) {if (activeTab.model.element.querySelector("#searchUnRefPanel").classList.contains("fn__none")) {protyle = activeTab.model.editors.edit.protyle;diff --git a/app/src/boot/globalEvent/keydown.ts b/app/src/boot/globalEvent/keydown.tsindex 536b2d5446..35eedfd173 100644--- a/app/src/boot/globalEvent/keydown.ts+++ b/app/src/boot/globalEvent/keydown.ts@@ -175,6 +175,11 @@ const dialogArrow = (app: App, element: HTMLElement, event: KeyboardEvent) => {};const editKeydown = (app: App, event: KeyboardEvent) => {+ const eventTarget = event.target as HTMLElement;+ if (hasClosestByClassName(eventTarget, "sy__backlink--bottom", true) &&+ !hasClosestByClassName(eventTarget, "protyle", true)) {+ return false;+ }let protyle: IProtyle;let range: Range;if (getSelection().rangeCount > 0) {@@ -205,7 +210,7 @@ const editKeydown = (app: App, event: KeyboardEvent) => {const activeTab = getActiveTab();if (!protyle && activeTab) {if (activeTab.model instanceof Editor) {- protyle = activeTab.model.editor.protyle;+ protyle = activeTab.model.getCurrentProtyle(range);} else if (activeTab.model instanceof Search) {if (activeTab.model.element.querySelector("#searchUnRefPanel").classList.contains("fn__none")) {protyle = activeTab.model.editors.edit.protyle;@@ -980,7 +985,10 @@ const panelTreeKeydown = (app: App, event: KeyboardEvent) => {return false;}- let activePanelElement = document.querySelector(".layout__tab--active");+ const bottomBacklinkElement = hasClosestByClassName(target, "sy__backlink--bottom", true);+ const bottomBacklink = bottomBacklinkElement ? getAllModels().backlink.find(item =>+ item.type === "bottom" && item.element === bottomBacklinkElement) : undefined;+ let activePanelElement = bottomBacklinkElement || document.querySelector(".layout__tab--active");if (!activePanelElement) {Array.from(document.querySelectorAll(".layout__wnd--active .layout-tab-container > div")).find(item => {if (!item.classList.contains("fn__none") && item.className.indexOf("sy__") > -1) {@@ -997,18 +1005,20 @@ const panelTreeKeydown = (app: App, event: KeyboardEvent) => {}let matchCommand = false;- app.plugins.find(item => {- item.commands.find(command => {- if (command.dockCallback && matchHotKey(command.customHotkey, event)) {- matchCommand = true;- command.dockCallback(activePanelElement as HTMLElement);+ if (!bottomBacklink) {+ app.plugins.find(item => {+ item.commands.find(command => {+ if (command.dockCallback && matchHotKey(command.customHotkey, event)) {+ matchCommand = true;+ command.dockCallback(activePanelElement as HTMLElement);+ return true;+ }+ });+ if (matchCommand) {return true;}});- if (matchCommand) {- return true;- }- });+ }if (matchCommand) {return true;}@@ -1038,22 +1048,41 @@ const panelTreeKeydown = (app: App, event: KeyboardEvent) => {activePanelElement.classList.contains("sy__graph")) {return false;}- const model = (getInstanceById(activePanelElement.getAttribute("data-id"), window.siyuan.layout.layout) as Tab)?.model;+ const model = bottomBacklink ||+ (getInstanceById(activePanelElement.getAttribute("data-id"), window.siyuan.layout.layout) as Tab)?.model;if (!model) {return false;}- let activeItemElement = activePanelElement.querySelector(".b3-list-item--focus");+ const visibleTreeElements = bottomBacklink ? [bottomBacklink.tree.element, bottomBacklink.mTree.element].filter(item =>+ !item.classList.contains("fn__none")) : [];+ let activeItemElement: Element;+ if (bottomBacklink) {+ visibleTreeElements.find(item => {+ activeItemElement = item.querySelector(".b3-list-item--focus");+ return !!activeItemElement;+ });+ } else {+ activeItemElement = activePanelElement.querySelector(".b3-list-item--focus");+ }if (!activeItemElement) {- activeItemElement = activePanelElement.querySelector(".b3-list .b3-list-item");+ if (bottomBacklink) {+ visibleTreeElements.find(item => {+ activeItemElement = item.querySelector(".b3-list-item");+ return !!activeItemElement;+ });+ } else {+ activeItemElement = activePanelElement.querySelector(".b3-list .b3-list-item");+ }if (activeItemElement) {activeItemElement.classList.add("b3-list-item--focus");}return false;}- let tree = (model as Backlink).tree;- if (activeItemElement.parentElement.parentElement.classList.contains("backlinkMList")) {- tree = (model as Backlink).mTree;+ const backlinkModel = model as Backlink;+ let tree = backlinkModel.tree;+ if (backlinkModel.mTree?.element.contains(activeItemElement)) {+ tree = backlinkModel.mTree;}if (!tree) {return false;@@ -1699,7 +1728,7 @@ export const windowKeyDown = (app: App, event: KeyboardEvent) => {}// 面板的操作- if (!isTabWindow && panelTreeKeydown(app, event)) {+ if ((!isTabWindow || hasClosestByClassName(target, "sy__backlink--bottom", true)) && panelTreeKeydown(app, event)) {return;}diff --git a/app/src/config/tabs/editorRuntime.ts b/app/src/config/tabs/editorRuntime.tsindex 1a3ab6eed4..e11de621e2 100644--- a/app/src/config/tabs/editorRuntime.ts+++ b/app/src/config/tabs/editorRuntime.ts@@ -1,5 +1,5 @@import {Constants} from "../../constants";-import {getAllEditor} from "../../layout/getAll";+import {getAllEditor, getAllModels} from "../../layout/getAll";import {setInlineStyle} from "../../util/assets";import {reloadProtyle} from "../../protyle/util/reload";import {resize} from "../../protyle/util/resize";@@ -7,6 +7,7 @@ import {createConfigNamespaceApi} from "../util/namespaceApi";const applyEditorConfig = (data: Config.IEditor) => {window.siyuan.config.editor = data;+ getAllModels().editor.forEach(item => item.updateBacklinkPanel());getAllEditor().forEach((editorItem) => {const protyle = editorItem.protyle;protyle.databaseAttributePanel?.updateDisplayConfig();diff --git a/app/src/config/tabs/editorTab.ts b/app/src/config/tabs/editorTab.tsindex 691940aea2..e41c58b7b3 100644--- a/app/src/config/tabs/editorTab.ts+++ b/app/src/config/tabs/editorTab.ts@@ -181,6 +181,11 @@ const registerEditorBidirectionalGroup = (tab: SettingTabBuilder) => {title: window.siyuan.languages.backlinkContainChildren,desc: window.siyuan.languages.backlinkContainChildrenTip,});+ if (!isMobile()) {+ group.switch("editor.backlinkShowBottom", {+ title: window.siyuan.languages.backlinkShowBottom,+ });+ }group.number("editor.backlinkExpandCount", {title: window.siyuan.languages.backlinkExpand,desc: window.siyuan.languages.backlinkExpandTip,diff --git a/app/src/dialog/processSystem.ts b/app/src/dialog/processSystem.tsindex b50a94f234..7ad194e1a3 100644--- a/app/src/dialog/processSystem.ts+++ b/app/src/dialog/processSystem.ts@@ -5,7 +5,7 @@ import {exportLayout} from "../layout/util";import {getDockByType} from "../layout/tabUtil";import {Files} from "../layout/dock/Files";/// #endif-import {getAllEditor} from "../layout/getAll";+import {getAllEditor, getAllModels} from "../layout/getAll";/// #if !BROWSERimport {ipcRenderer} from "electron";/// #endif@@ -21,6 +21,22 @@ import {saveScroll} from "../protyle/scroll/saveScroll";import {isInAndroid, isInHarmony, isInIOS, setStorageVal} from "../protyle/util/compatibility";import {Plugin} from "../plugin";+const BACKLINK_REFRESH_DELAY = 3600;+let backlinkRefreshTimeout: number;++export const scheduleBacklinkRefresh = () => {+ window.clearTimeout(backlinkRefreshTimeout);+ // 等待索引队列写入后再查询提及,并合并连续事务触发的刷新。+ backlinkRefreshTimeout = window.setTimeout(() => {+ getAllModels().backlink.forEach(item => {+ if (item.type === "bottom") {+ item.markDirty();+ item.refreshIfVisible();+ }+ });+ }, BACKLINK_REFRESH_DELAY);+};+export const setRefDynamicText = (data: {"blockID": string,"defBlockID": string,@@ -33,14 +49,27 @@ export const setRefDynamicText = (data: {item.innerHTML = data.refText;});});+ scheduleBacklinkRefresh();};export const setDefRefCount = (data: {"blockID": string,+ "defIDs"?: string[],"refCount": number,"rootRefCount": number,"rootID": string}) => {+ /// #if !MOBILE+ getAllModels().backlink.forEach(item => {+ const containsChangedBlock = window.siyuan.config.editor.backlinkContainChildren && item.rootId === data.rootID;+ if (item.type !== "bottom" || (!containsChangedBlock &&+ item.blockId !== data.rootID && item.blockId !== data.blockID && !data.defIDs?.includes(item.blockId))) {+ return;+ }+ item.markDirty();+ item.refreshIfVisible();+ });+ /// #endifgetAllEditor().forEach(editor => {if (editor.protyle.block.rootID === data.rootID && editor.protyle.title) {const attrElement = editor.protyle.title.element.querySelector(".protyle-attr");diff --git a/app/src/editor/index.ts b/app/src/editor/index.tsindex 1322b465f2..5b75683e2e 100644--- a/app/src/editor/index.ts+++ b/app/src/editor/index.ts@@ -9,11 +9,16 @@ import {countBlockWord} from "../layout/status";import {App} from "../index";import {fullscreen} from "../protyle/breadcrumb/action";import {fetchPost} from "../util/fetch";+import {Backlink} from "../layout/dock/Backlink";export class Editor extends Model {public element: HTMLElement;public editor: Protyle;public headElement: HTMLElement;+ public backlink?: Backlink;+ private backlinkElement?: HTMLElement;+ private backlinkIntersectionObserver?: IntersectionObserver;+ private backlinkMutationObserver?: MutationObserver;constructor(options: {app: App,@@ -74,9 +79,108 @@ export class Editor extends Model {if (options.afterInitProtyle) {options.afterInitProtyle(editor);}+ this.updateBacklinkPanel();},});// 需在 after 回调之前,否则不会聚焦 https://github.com/siyuan-note/siyuan/issues/5303this.editor.protyle.model = this;}++ public updateBacklinkPanel() {+ if (!window.siyuan.config.editor.backlinkShowBottom) {+ this.destroyBacklinkPanel();+ return;+ }+ if (this.backlinkElement) {+ this.updateBacklinkVisibility();+ return;+ }++ const backlinkElement = document.createElement("div");+ backlinkElement.className = "fn__none sy__backlink--bottom";+ this.backlinkElement = backlinkElement;+ this.editor.protyle.wysiwyg.element.after(backlinkElement);+ setPadding(this.editor.protyle);++ this.backlinkIntersectionObserver = new IntersectionObserver((entries) => {+ if (this.backlinkElement !== backlinkElement || !entries[0].isIntersecting ||+ backlinkElement.classList.contains("fn__none")) {+ return;+ }+ if (!this.backlink) {+ this.backlink = new Backlink({+ app: this.app,+ blockId: this.getBacklinkBlockId(),+ rootId: this.editor.protyle.block.rootID,+ type: "bottom",+ element: backlinkElement,+ ownerProtyle: this.editor.protyle,+ });+ } else {+ this.backlink.refreshDirty();+ }+ }, {+ root: this.editor.protyle.contentElement,+ rootMargin: "640px 0px",+ });+ this.backlinkIntersectionObserver.observe(backlinkElement);++ this.backlinkMutationObserver = new MutationObserver(() => {+ this.updateBacklinkVisibility();+ });+ this.backlinkMutationObserver.observe(this.editor.protyle.wysiwyg.element, {+ attributes: true,+ attributeFilter: ["data-eof"],+ childList: true,+ subtree: true,+ });+ this.updateBacklinkVisibility();+ }++ public destroy() {+ this.destroyBacklinkPanel();+ this.editor.destroy();+ }++ public getCurrentProtyle(range?: Range) {+ if (range) {+ const backlinkEditor = this.backlink?.editors.find(item => item.protyle.element.contains(range.startContainer));+ if (backlinkEditor) {+ return backlinkEditor.protyle;+ }+ }+ return this.editor.protyle;+ }++ private getBacklinkBlockId() {+ const protyle = this.editor.protyle;+ return protyle.block.showAll ? protyle.block.id : (protyle.block.parentID || protyle.block.rootID);+ }++ private updateBacklinkVisibility() {+ if (!this.backlinkElement) {+ return;+ }+ const lastElement = this.editor.protyle.wysiwyg.element.lastElementChild;+ const hidden = lastElement?.getAttribute("data-eof") !== "2";+ if (this.backlinkElement.classList.contains("fn__none") !== hidden) {+ this.backlinkElement.classList.toggle("fn__none", hidden);+ setPadding(this.editor.protyle);+ }+ }++ private destroyBacklinkPanel() {+ const hasBacklinkElement = !!this.backlinkElement;+ this.backlinkIntersectionObserver?.disconnect();+ this.backlinkMutationObserver?.disconnect();+ this.backlink?.destroy();+ this.backlinkElement?.remove();+ this.backlinkIntersectionObserver = undefined;+ this.backlinkMutationObserver = undefined;+ this.backlink = undefined;+ this.backlinkElement = undefined;+ if (hasBacklinkElement) {+ setPadding(this.editor.protyle);+ }+ }}diff --git a/app/src/editor/util.ts b/app/src/editor/util.tsindex 918f5b8537..3dd678175f 100644--- a/app/src/editor/util.ts+++ b/app/src/editor/util.ts@@ -699,6 +699,26 @@ export const updateBacklinkGraph = (models: IModels, protyle: IProtyle) => {}});models.backlink.forEach(item => {+ if (item.type === "bottom") {+ if (!protyle || item.ownerProtyle !== protyle) {+ return;+ }+ const blockId = protyle.block.showAll ? protyle.block.id : (protyle.block.parentID || protyle.block.rootID);+ if (blockId === item.blockId) {+ return;+ }+ const backlinkKeyword = item.inputsElement[0].value;+ const backmentionKeyword = item.inputsElement[1].value;+ item.saveStatus();+ item.blockId = blockId;+ item.rootId = protyle.block.rootID;+ item.render(undefined);+ item.inputsElement[0].value = backlinkKeyword;+ item.inputsElement[1].value = backmentionKeyword;+ item.markDirty();+ item.refreshIfVisible();+ return;+ }if (item.type === "local" && item.rootId !== protyle?.block?.rootID) {return;}diff --git a/app/src/index.ts b/app/src/index.tsindex 148920e1d1..027b7be6b1 100644--- a/app/src/index.ts+++ b/app/src/index.ts@@ -25,6 +25,7 @@ import {progressBackgroundTask,progressLoading,progressStatus,+ scheduleBacklinkRefresh,setDefRefCount,setRefDynamicText,transactionError@@ -87,6 +88,9 @@ export class App {case "setDefRefCount":setDefRefCount(data.data);break;+ case "transactions":+ scheduleBacklinkRefresh();+ break;case "reloadTag":if (getDockByType("tag")?.data.tag instanceof Tag) {(getDockByType("tag").data.tag as Tag).update();@@ -148,6 +152,7 @@ export class App {});break;case "rename":+ scheduleBacklinkRefresh();getAllTabs().forEach((tab) => {if (tab.headElement) {const initTab = tab.headElement.getAttribute("data-initdata");diff --git a/app/src/layout/Wnd.ts b/app/src/layout/Wnd.tsindex 33a8baa5e3..69a64c9188 100644--- a/app/src/layout/Wnd.ts+++ b/app/src/layout/Wnd.ts@@ -746,7 +746,7 @@ export class Wnd {item.destroy();}});- model.editor.destroy();+ model.destroy();return;}if (model instanceof Search) {diff --git a/app/src/layout/dock/Backlink.ts b/app/src/layout/dock/Backlink.tsindex 4a0dc3d68c..bf644fe8e5 100644--- a/app/src/layout/dock/Backlink.ts+++ b/app/src/layout/dock/Backlink.ts@@ -17,9 +17,10 @@ import {getAllModels} from "../getAll";export class Backlink extends Model {public element: HTMLElement;public inputsElement: NodeListOf<HTMLInputElement>;- public type: "pin" | "local";+ public type: "pin" | "local" | "bottom";public blockId: string;- public rootId: string; // "local" 必传+ public rootId: string; // "local" 和 "bottom" 必传+ public ownerProtyle?: IProtyle;public tree: Tree;private notebookId: string;public mTree: Tree;@@ -32,35 +33,51 @@ export class Backlink extends Model {mScrollTop: number,backlinkOpenIds: string[],backlinkMOpenIds: string[],- backlinkMStatus: number // 0 全展开,1 展开一半箭头向下,2 展开一半箭头向上,3 全收起+ backlinkMStatus: number, // 0 全展开,1 展开一半箭头向下,2 展开一半箭头向上,3 全收起+ backlinkFolded?: boolean,+ backmentionFolded?: boolean}} = {};+ private dirty = false;+ private destroyed = false;constructor(options: {app: App,- tab: Tab,+ tab?: Tab,+ element?: HTMLElement,blockId: string,rootId?: string,- type: "pin" | "local"+ type: "pin" | "local" | "bottom",+ ownerProtyle?: IProtyle}) {super({app: options.app});- this.connect({- id: options.tab.id,- type: "backlink",- callback: this.handelCallback.bind(this),- msgCallback: this.handleMsgCallback.bind(this),- });+ if (options.type !== "bottom") {+ this.connect({+ id: options.tab.id,+ type: "backlink",+ callback: this.handelCallback.bind(this),+ msgCallback: this.handleMsgCallback.bind(this),+ });+ }this.blockId = options.blockId;this.rootId = options.rootId;this.type = options.type;- this.element = options.tab.panelElement;+ this.ownerProtyle = options.ownerProtyle;+ this.element = options.element || options.tab.panelElement;this.element.classList.add("fn__flex-column", "file-tree", "sy__backlink", "dockPanel");+ if (this.type === "bottom") {+ this.element.classList.add("sy__backlink--bottom");+ this.element.tabIndex = -1;+ this.element.addEventListener("focusout", () => {+ window.setTimeout(() => this.refreshIfVisible());+ });+ }const backlinkSort = window.siyuan.config.editor.backlinkSort;const backmentionSort = window.siyuan.config.editor.backmentionSort;this.element.innerHTML = `<div class="block__icons">- <div class="block__logo fn__flex-1">${window.siyuan.languages.backlinks}</div>+ <div class="block__logo fn__flex-1${this.type === "bottom" ? " fn__pointer" : ""}"${this.type === "bottom" ? ' data-type="backlink"' : ""}>${window.siyuan.languages.backlinks}</div><span class="counter listCount" style="margin-left: 0"></span><span class="fn__space"></span><input class="b3-text-field search__label fn__none fn__size200" placeholder="${window.siyuan.languages.filterKeywordEnter}" />@@ -77,8 +94,10 @@ export class Backlink extends Model {<span data-type="collapse" class="block__icon ariaLabel" data-position="north" aria-label="${window.siyuan.languages.collapse}${updateHotkeyAfterTip(window.siyuan.config.keymap.editor.general.collapse.custom)}"><svg><use xlink:href="#iconContract"></use></svg></span>- <span class="${this.type === "local" ? "fn__none " : ""}fn__space"></span>- <span data-type="min" class="${this.type === "local" ? "fn__none " : ""}block__icon ariaLabel" data-position="north" aria-label="${window.siyuan.languages.min}${updateHotkeyAfterTip(window.siyuan.config.keymap.general.closeTab.custom)}"><svg><use xlink:href='#iconMin'></use></svg></span>+ <span class="${this.type === "bottom" ? "" : "fn__none "}fn__space"></span>+ <span data-type="bLayout" class="${this.type === "bottom" ? "" : "fn__none "}block__icon ariaLabel" data-position="north" aria-label="${window.siyuan.languages.collapse}"><svg><use xlink:href='#iconDown'></use></svg></span>+ <span class="${this.type !== "pin" ? "fn__none " : ""}fn__space"></span>+ <span data-type="min" class="${this.type !== "pin" ? "fn__none " : ""}block__icon ariaLabel" data-position="north" aria-label="${window.siyuan.languages.min}${updateHotkeyAfterTip(window.siyuan.config.keymap.general.closeTab.custom)}"><svg><use xlink:href='#iconMin'></use></svg></span></div><div class="backlinkList fn__flex-1"></div><div class="block__icons">@@ -240,8 +259,11 @@ export class Backlink extends Model {});});this.element.addEventListener("click", (event) => {- this.setFocus();let target = event.target as HTMLElement;+ const eventProtyleElement = target.closest(".protyle");+ if (this.type !== "bottom" || !eventProtyleElement || !this.element.contains(eventProtyleElement)) {+ this.setFocus();+ }while (target && !target.isEqualNode(this.element)) {if ((target.classList.contains("block__icon") || target.classList.contains("block__logo")) &&target.parentElement.parentElement === this.element) {@@ -284,11 +306,29 @@ export class Backlink extends Model {event.stopPropagation();break;case "layout":- this.setLayout(target);+ if (this.type === "bottom") {+ this.setBottomLayout(target, this.mTree.element);+ } else {+ this.setLayout(target);+ }event.stopPropagation();break;+ case "bLayout":+ this.setBottomLayout(target, this.tree.element);+ event.stopPropagation();+ break;+ case "backlink":+ if (this.type === "bottom") {+ this.setBottomLayout(target.parentElement.querySelector('[data-type="bLayout"]'), this.tree.element);+ event.stopPropagation();+ }+ break;case "mention":- this.setLayout(target.parentElement.querySelector('[data-type="layout"]'));+ if (this.type === "bottom") {+ this.setBottomLayout(target.parentElement.querySelector('[data-type="layout"]'), this.mTree.element);+ } else {+ this.setLayout(target.parentElement.querySelector('[data-type="layout"]'));+ }event.stopPropagation();break;}@@ -363,7 +403,23 @@ export class Backlink extends Model {this.mTree.element.dispatchEvent(new CustomEvent("scroll"));}+ private setBottomLayout(element: HTMLElement, listElement: HTMLElement) {+ const folded = !listElement.classList.contains("fn__none");+ listElement.classList.toggle("fn__none", folded);+ if (folded) {+ listElement.querySelector(".b3-list-item--focus")?.classList.remove("b3-list-item--focus");+ }+ element.setAttribute("aria-label", folded ? window.siyuan.languages.expand : window.siyuan.languages.collapse);+ element.querySelector("use").setAttribute("xlink:href", folded ? "#iconRight" : "#iconDown");+ this.saveStatus();+ }+private setFocus() {+ if (this.type === "bottom") {+ this.setOwnerFocus();+ this.element.focus({preventScroll: true});+ return;+ }if (this.type === "local") {setPanelFocus(this.element.parentElement.parentElement);} else {@@ -371,6 +427,13 @@ export class Backlink extends Model {}}+ private setOwnerFocus() {+ const wndElement = this.ownerProtyle.element.closest('[data-type="wnd"]');+ if (wndElement) {+ setPanelFocus(wndElement);+ }+ }+private showSortMenu(type: string, sort: string) {const clickEvent = (currentSort: string) => {(type === "sort" ? this.tree : this.mTree).element.previousElementSibling.querySelector(`[data-type="${type}"]`).setAttribute("data-sort", currentSort);@@ -466,17 +529,21 @@ export class Backlink extends Model {svgElement.removeAttribute("disabled");} else {const keyword = isMention ? this.inputsElement[1].value : this.inputsElement[0].value;+ const blockId = this.blockId;fetchPost(isMention ? "/api/ref/getBackmentionDoc" : "/api/ref/getBacklinkDoc", {- defID: this.blockId,+ defID: blockId,refTreeID: docId,highlight: !isSupportCSSHL(),keyword,}, (response) => {+ if (this.destroyed || blockId !== this.blockId || !liElement.isConnected) {+ return;+ }svgElement.removeAttribute("disabled");svgElement.classList.add("b3-list-item__arrow--open");const editorElement = document.createElement("div");editorElement.style.minHeight = "auto";- editorElement.setAttribute("data-defid", this.blockId);+ editorElement.setAttribute("data-defid", blockId);editorElement.setAttribute("data-ismention", isMention ? "true" : "false");liElement.after(editorElement);const editor = new Protyle(this.app, editorElement, {@@ -492,6 +559,9 @@ export class Backlink extends Model {breadcrumb: false,}});+ if (this.type === "bottom") {+ editor.protyle.wysiwyg.element.addEventListener("focusin", () => this.setOwnerFocus());+ }editor.protyle.notebookId = liElement.getAttribute("data-notebook-id");searchMarkRender(editor.protyle, response.data.keywords);this.editors.push(editor);@@ -505,9 +575,13 @@ export class Backlink extends Model {return;}element.classList.add("fn__rotate");+ this.dirty = false;fetchPost("/api/ref/refreshBacklink", {id: this.blockId,}, () => {+ if (this.destroyed) {+ return;+ }element.classList.remove("fn__rotate");this.searchBacklinks();});@@ -519,6 +593,7 @@ export class Backlink extends Model {return;}element.classList.add("fn__rotate");+ this.dirty = false;// 解析当前反链面板所属 box:优先用已记录的 notebookId,首次为空时按 rootId 在已打开的编辑器里查找let notebookId = this.notebookId;if (!notebookId && this.rootId) {@@ -536,14 +611,21 @@ export class Backlink extends Model {mk: this.inputsElement[1].value,id: this.blockId,};+ const blockId = this.blockId;if (isEncryptedBox(notebookId)) {param.notebook = notebookId;}fetchPost("/api/ref/getBacklink2", param, response => {+ if (this.destroyed || blockId !== this.blockId) {+ return;+ }if (!init) {this.saveStatus();}this.render(response.data);+ if (this.type === "bottom" && this.dirty) {+ this.refreshIfVisible();+ }});}@@ -555,7 +637,9 @@ export class Backlink extends Model {mScrollTop: this.mTree.element.scrollTop,backlinkOpenIds: [],backlinkMOpenIds: [],- backlinkMStatus: 3 // 0 全展开,1 展开一半箭头向下,2 展开一半箭头向上,3 全收起+ backlinkMStatus: 3, // 0 全展开,1 展开一半箭头向下,2 展开一半箭头向上,3 全收起+ backlinkFolded: this.tree.element.classList.contains("fn__none"),+ backmentionFolded: this.mTree.element.classList.contains("fn__none")};this.tree.element.querySelectorAll(".b3-list-item__arrow--open").forEach(item => {this.status[this.blockId].backlinkOpenIds.push(item.parentElement.parentElement.getAttribute("data-node-id"));@@ -611,14 +695,14 @@ export class Backlink extends Model {this.mTree.updateData(data.backmentions);const countElement = this.element.querySelector(".listCount");- if (data.linkRefsCount === 0) {+ if (data.linkRefsCount === 0 && this.type !== "bottom") {countElement.classList.add("fn__none");} else {countElement.classList.remove("fn__none");countElement.textContent = data.linkRefsCount.toString();}const mCountElement = this.element.querySelector(".listMCount");- if (data.mentionsCount === 0) {+ if (data.mentionsCount === 0 && this.type !== "bottom") {mCountElement.classList.add("fn__none");} else {mCountElement.classList.remove("fn__none");@@ -633,7 +717,9 @@ export class Backlink extends Model {mScrollTop: 0,backlinkOpenIds: [],backlinkMOpenIds: [],- backlinkMStatus: 3+ backlinkMStatus: 3,+ backlinkFolded: false,+ backmentionFolded: false};if (data.mentionsCount === 0 || window.siyuan.config.editor.backmentionExpandCount === -1) {this.status[this.blockId].backlinkMStatus = 3;@@ -675,28 +761,35 @@ export class Backlink extends Model {this.toggleItem(liElement, true);}});- // 0 全展开,1 展开一半箭头向下,2 展开一半箭头向上,3 全收起- const layoutElement = this.mTree.element.previousElementSibling.querySelector('[data-type="layout"]');- if (this.status[this.blockId].backlinkMStatus === 2 || this.status[this.blockId].backlinkMStatus === 1) {- this.tree.element.classList.remove("fn__none");- this.mTree.element.removeAttribute("style");- if (this.status[this.blockId].backlinkMStatus === 1) {- layoutElement.setAttribute("aria-label", window.siyuan.languages.down);- layoutElement.querySelector("use").setAttribute("xlink:href", "#iconDown");- } else {+ if (this.type === "bottom") {+ this.restoreBottomLayout(this.tree.element.previousElementSibling.querySelector('[data-type="bLayout"]'), this.tree.element,+ this.status[this.blockId].backlinkFolded);+ this.restoreBottomLayout(this.mTree.element.previousElementSibling.querySelector('[data-type="layout"]'), this.mTree.element,+ this.status[this.blockId].backmentionFolded);+ } else {+ // 0 全展开,1 展开一半箭头向下,2 展开一半箭头向上,3 全收起+ const layoutElement = this.mTree.element.previousElementSibling.querySelector('[data-type="layout"]');+ if (this.status[this.blockId].backlinkMStatus === 2 || this.status[this.blockId].backlinkMStatus === 1) {+ this.tree.element.classList.remove("fn__none");+ this.mTree.element.removeAttribute("style");+ if (this.status[this.blockId].backlinkMStatus === 1) {+ layoutElement.setAttribute("aria-label", window.siyuan.languages.down);+ layoutElement.querySelector("use").setAttribute("xlink:href", "#iconDown");+ } else {+ layoutElement.setAttribute("aria-label", window.siyuan.languages.up);+ layoutElement.querySelector("use").setAttribute("xlink:href", "#iconUp");+ }+ } else if (this.status[this.blockId].backlinkMStatus === 3) {+ this.tree.element.classList.remove("fn__none");+ this.mTree.element.setAttribute("style", "flex:none;height:0px");layoutElement.setAttribute("aria-label", window.siyuan.languages.up);layoutElement.querySelector("use").setAttribute("xlink:href", "#iconUp");+ } else {+ this.tree.element.classList.add("fn__none");+ this.mTree.element.setAttribute("style", `flex:none;height:${this.element.clientHeight - this.tree.element.previousElementSibling.clientHeight * 2}px`);+ layoutElement.setAttribute("aria-label", window.siyuan.languages.down);+ layoutElement.querySelector("use").setAttribute("xlink:href", "#iconDown");}- } else if (this.status[this.blockId].backlinkMStatus === 3) {- this.tree.element.classList.remove("fn__none");- this.mTree.element.setAttribute("style", "flex:none;height:0px");- layoutElement.setAttribute("aria-label", window.siyuan.languages.up);- layoutElement.querySelector("use").setAttribute("xlink:href", "#iconUp");- } else {- this.tree.element.classList.add("fn__none");- this.mTree.element.setAttribute("style", `flex:none;height:${this.element.clientHeight - this.tree.element.previousElementSibling.clientHeight * 2}px`);- layoutElement.setAttribute("aria-label", window.siyuan.languages.down);- layoutElement.querySelector("use").setAttribute("xlink:href", "#iconDown");}this.tree.element.previousElementSibling.querySelector('[data-type="sort"]').setAttribute("data-sort", this.status[this.blockId].sort.toString());this.mTree.element.previousElementSibling.querySelector('[data-type="mSort"]').setAttribute("data-sort", this.status[this.blockId].mSort.toString());@@ -706,4 +799,51 @@ export class Backlink extends Model {this.mTree.element.scrollTop = this.status[this.blockId].mScrollTop;}, Constants.TIMEOUT_LOAD);}++ private restoreBottomLayout(element: HTMLElement, listElement: HTMLElement, folded: boolean) {+ listElement.classList.toggle("fn__none", folded);+ element.setAttribute("aria-label", folded ? window.siyuan.languages.expand : window.siyuan.languages.collapse);+ element.querySelector("use").setAttribute("xlink:href", folded ? "#iconRight" : "#iconDown");+ }++ public markDirty() {+ this.dirty = true;+ }++ public refreshIfVisible() {+ if (this.type !== "bottom" || !this.dirty) {+ return;+ }+ const activeProtyleElement = document.activeElement?.closest(".protyle");+ if (activeProtyleElement && this.element.contains(activeProtyleElement)) {+ return;+ }+ if (this.element.classList.contains("fn__none") ||+ !this.element.isConnected || this.element.getClientRects().length === 0 ||+ this.ownerProtyle.element.getClientRects().length === 0) {+ return;+ }+ const rect = this.element.getBoundingClientRect();+ const ownerRect = this.ownerProtyle.contentElement.getBoundingClientRect();+ if (rect.top > ownerRect.bottom + 640 || rect.bottom < ownerRect.top - 640) {+ return;+ }+ this.searchBacklinks();+ }++ public refreshDirty() {+ if (this.dirty) {+ this.refreshIfVisible();+ }+ }++ public destroy() {+ this.destroyed = true;+ this.editors.forEach(item => item.destroy());+ this.editors = [];+ if (this.ws) {+ this.ws.onclose = null;+ this.ws.close();+ }+ }}diff --git a/app/src/layout/dock/util.ts b/app/src/layout/dock/util.tsindex c95ed9499c..fe9aeac50c 100644--- a/app/src/layout/dock/util.ts+++ b/app/src/layout/dock/util.ts@@ -230,7 +230,7 @@ export const clearOBG = () => {}});models.backlink.forEach(item => {- if (item.type === "local") {+ if (item.type !== "pin") {return;}if ("" === item.blockId) {diff --git a/app/src/layout/getAll.ts b/app/src/layout/getAll.tsindex df80ef3492..9013ac011a 100644--- a/app/src/layout/getAll.ts+++ b/app/src/layout/getAll.ts@@ -81,6 +81,9 @@ export const getAllModels = () => {const model = item.model;if (model instanceof Editor) {models.editor.push(model);+ if (model.backlink) {+ models.backlink.push(model.backlink);+ }} else if (model instanceof Graph) {models.graph.push(model);} else if (model instanceof Outline) {diff --git a/app/src/protyle/ui/initUI.ts b/app/src/protyle/ui/initUI.tsindex 28a03aa3ea..bff92c66ea 100644--- a/app/src/protyle/ui/initUI.ts+++ b/app/src/protyle/ui/initUI.ts@@ -145,6 +145,10 @@ export const initUI = (protyle: IProtyle) => {}, Constants.TIMEOUT_LOAD);}, {passive: true});protyle.contentElement.addEventListener("click", (event: MouseEvent & { target: HTMLElement }) => {+ const eventProtyleElement = hasClosestByClassName(event.target, "protyle", true);+ if (eventProtyleElement && eventProtyleElement !== protyle.element) {+ return;+ }hideElements(["hint", "util"], protyle);// wysiwyg 元素下方点击无效果 https://github.com/siyuan-note/siyuan/issues/12009if (protyle.disabled ||@@ -210,6 +214,10 @@ export const initUI = (protyle: IProtyle) => {protyle.element.addEventListener(isMobile() ? "pointerover" : "mouseover", (event: PointerEvent & {target: HTMLElement}) => {+ const eventProtyleElement = hasClosestByClassName(event.target, "protyle", true);+ if (eventProtyleElement && eventProtyleElement !== protyle.element) {+ return;+ }if (isMobile() && event.pointerType !== "mouse") {return;}@@ -327,11 +335,14 @@ export const setPadding = (protyle: IProtyle) => {const padding = getPadding(protyle);const paddingLeft = padding.left;const paddingRight = padding.right;+ const backlinkBottomElement = protyle.contentElement.querySelector(".sy__backlink--bottom") as HTMLElement;+ const backlinkBottomVisible = backlinkBottomElement && !backlinkBottomElement.classList.contains("fn__none");if (protyle.options.backlinkData) {protyle.wysiwyg.element.style.padding = `4px ${paddingRight}px 4px ${paddingLeft}px`;} else {- protyle.wysiwyg.element.style.padding = `${padding.top}px ${paddingRight}px ${padding.bottom}px ${paddingLeft}px`;+ const paddingBottom = backlinkBottomVisible && protyle.options.typewriterMode ? 16 : padding.bottom;+ protyle.wysiwyg.element.style.padding = `${padding.top}px ${paddingRight}px ${paddingBottom}px ${paddingLeft}px`;}if (protyle.options.render.background) {protyle.background.element.querySelector(".protyle-background__ia").setAttribute("style", `margin-left:${paddingLeft}px;margin-right:${paddingRight}px`);@@ -343,6 +354,11 @@ export const setPadding = (protyle: IProtyle) => {if (protyle.databaseAttributePanel) {protyle.databaseAttributePanel.element.style.margin = `8px ${paddingRight}px 8px ${paddingLeft}px`;}+ if (backlinkBottomElement) {+ backlinkBottomElement.style.padding = `0 ${paddingRight}px 16px ${paddingLeft}px`;+ backlinkBottomElement.style.marginBottom = backlinkBottomVisible && protyle.options.typewriterMode ?+ `${Math.max(padding.bottom - 16, 0)}px` : "";+ }// https://github.com/siyuan-note/siyuan/issues/15021protyle.element.style.setProperty("--b3-width-protyle", protyle.element.clientWidth + "px");diff --git a/app/src/protyle/undo/globalUndo.ts b/app/src/protyle/undo/globalUndo.tsindex d5f1424633..740019d5cf 100644--- a/app/src/protyle/undo/globalUndo.ts+++ b/app/src/protyle/undo/globalUndo.ts@@ -86,6 +86,10 @@ export const getActiveProtyle = (): IProtyle => {/// #elseconst activeTab = getActiveTab();const model = activeTab?.model;+ if (model && (model as any).getCurrentProtyle) {+ const range = getSelection().rangeCount > 0 ? getSelection().getRangeAt(0) : undefined;+ return (model as any).getCurrentProtyle(range);+ }if (model && (model as any).editor?.protyle) {return (model as any).editor.protyle;}diff --git a/app/src/protyle/util/editorCommonEvent.ts b/app/src/protyle/util/editorCommonEvent.tsindex 5ada01c061..4c0ad0da7f 100644--- a/app/src/protyle/util/editorCommonEvent.ts+++ b/app/src/protyle/util/editorCommonEvent.ts@@ -290,8 +290,9 @@ const moveTo = async (protyle: IProtyle, sourceElements: Element[], targetElemen} else {/// #if !MOBILEconst allEditor = getAllEditor();+ const sourceProtyleElement = hasClosestByClassName(topSourceParentElement, "protyle", true);for (let i = 0; i < allEditor.length; i++) {- if (allEditor[i].protyle.element.contains(topSourceParentElement)) {+ if (allEditor[i].protyle.element === sourceProtyleElement) {const otherSbData = await cancelSB(allEditor[i].protyle, topSourceParentElement);doOperations.push(otherSbData.doOperations[0], otherSbData.doOperations[1]);undoOperations.push(otherSbData.undoOperations[1], otherSbData.undoOperations[0]);@@ -311,8 +312,9 @@ const moveTo = async (protyle: IProtyle, sourceElements: Element[], targetElemen} else {/// #if !MOBILEconst allEditor = getAllEditor();+ const sourceProtyleElement = hasClosestByClassName(oldSourceParentElement, "protyle", true);for (let i = 0; i < allEditor.length; i++) {- if (allEditor[i].protyle.element.contains(oldSourceParentElement)) {+ if (allEditor[i].protyle.element === sourceProtyleElement) {const otherSbData = await cancelSB(allEditor[i].protyle, oldSourceParentElement);doOperations.push(otherSbData.doOperations[0], otherSbData.doOperations[1]);undoOperations.push(otherSbData.undoOperations[1], otherSbData.undoOperations[0]);@@ -326,7 +328,7 @@ const moveTo = async (protyle: IProtyle, sourceElements: Element[], targetElemen/// #if !MOBILE// 拖拽后,根文档原内容为空getAllEditor().find(item => {- if (item.protyle.element.contains(oldSourceParentElement)) {+ if (item.protyle.wysiwyg.element === oldSourceParentElement) {if (!item.protyle.block.showAll) {const newId = Lute.NewNodeID();doOperations.splice(0, 0, {diff --git a/app/src/protyle/util/onGet.ts b/app/src/protyle/util/onGet.tsindex 50fac8299f..75142f4d7a 100644--- a/app/src/protyle/util/onGet.ts+++ b/app/src/protyle/util/onGet.ts@@ -92,6 +92,7 @@ export const onGet = (options: {// 防止动态加载加载过多的内容setHTML({content: options.data.data.content,+ eof: options.data.data.eof,expand: options.data.data.isBacklinkExpand,action: options.action,scrollAttr: options.scrollAttr,@@ -123,6 +124,7 @@ export const onGet = (options: {setHTML({content: options.data.data.content,+ eof: options.data.data.eof,expand: options.data.data.isBacklinkExpand,action: options.action,scrollAttr: options.scrollAttr,@@ -137,6 +139,7 @@ export const onGet = (options: {const setHTML = (options: {content: string,+ eof: boolean,action?: string[],isSyncing: boolean,expand: boolean,@@ -217,6 +220,12 @@ const setHTML = (options: {}}+ if (options.eof) {+ const eofElement = options.action.includes(Constants.CB_GET_BEFORE) ?+ protyle.wysiwyg.element.firstElementChild : protyle.wysiwyg.element.lastElementChild;+ eofElement?.setAttribute("data-eof", options.action.includes(Constants.CB_GET_BEFORE) ? "1" : "2");+ }+/// #if MOBILEprotyle.wysiwyg.element.querySelectorAll("video, audio").forEach(item => {item.addEventListener("playing", () => {diff --git a/app/src/protyle/wysiwyg/remove.ts b/app/src/protyle/wysiwyg/remove.tsindex ee77e50290..601ce739f1 100644--- a/app/src/protyle/wysiwyg/remove.ts+++ b/app/src/protyle/wysiwyg/remove.ts@@ -27,9 +27,7 @@ import {isMobile} from "../../util/functions";import {mathRender} from "../render/mathRender";import {hasClosestBlock, hasClosestByClassName, isInEmbedBlock} from "../util/hasClosest";/// #if !MOBILE-import {getInstanceById} from "../../layout/util";-import {Tab} from "../../layout/Tab";-import {Backlink} from "../../layout/dock/Backlink";+import {getAllModels} from "../../layout/getAll";/// #endifimport {fetchPost, fetchSyncPost} from "../../util/fetch";import {onGet} from "../util/onGet";@@ -289,9 +287,11 @@ export const removeBlock = async (protyle: IProtyle, blockElement: Element, rangif (!sideElement) {const backlinkElement = hasClosestByClassName(protyle.element, "sy__backlink", true);if (backlinkElement) {- const backLinkTab = getInstanceById(backlinkElement.getAttribute("data-id"), window.siyuan.layout.layout);- if (backLinkTab instanceof Tab && backLinkTab.model instanceof Backlink) {- const editors = backLinkTab.model.editors;+ getAllModels().backlink.find(item => {+ if (!item.element.contains(protyle.element)) {+ return false;+ }+ const editors = item.editors;editors.find((item, index) => {if (item.protyle.element === protyle.element) {item.destroy();@@ -301,7 +301,8 @@ export const removeBlock = async (protyle: IProtyle, blockElement: Element, rangreturn true;}});- }+ return true;+ });}}/// #endifdiff --git a/app/src/types/config.d.ts b/app/src/types/config.d.tsindex 8e572e9d03..1f35d63e3e 100644--- a/app/src/types/config.d.ts+++ b/app/src/types/config.d.ts@@ -473,6 +473,10 @@ declare namespace Config {* Whether the backlink contains children*/backlinkContainChildren: boolean;+ /**+ * Whether to show backlinks at the bottom of the document+ */+ backlinkShowBottom: boolean;/*** Backlink sort mode*/diff --git a/app/src/util/reloadSync.ts b/app/src/util/reloadSync.tsindex 7cd56d6321..1d24a234ca 100644--- a/app/src/util/reloadSync.ts+++ b/app/src/util/reloadSync.ts@@ -130,6 +130,11 @@ export const reloadSync = (}});allModels.backlink.forEach(item => {+ if (item.type === "bottom") {+ item.markDirty();+ item.refreshIfVisible();+ return;+ }if (item.type === "local" && data.removeRootIDs.includes(item.rootId)) {item.parent.parent.removeTab(item.parent.id, false, false);} else {diff --git a/app/src/window/index.ts b/app/src/window/index.tsindex 2df8dfd7ba..359bf256a5 100644--- a/app/src/window/index.ts+++ b/app/src/window/index.ts@@ -13,6 +13,7 @@ import {progressBackgroundTask,progressLoading,progressStatus,+ scheduleBacklinkRefresh,setDefRefCount,setRefDynamicText,transactionError@@ -61,6 +62,9 @@ class App {case "setDefRefCount":setDefRefCount(data.data);break;+ case "transactions":+ scheduleBacklinkRefresh();+ break;case "setRefDynamicText":setRefDynamicText(data.data);break;@@ -105,6 +109,7 @@ class App {});break;case "rename":+ scheduleBacklinkRefresh();getAllTabs().forEach((tab) => {if (tab.headElement) {const initTab = tab.headElement.getAttribute("data-initdata");diff --git a/kernel/conf/editor.go b/kernel/conf/editor.goindex fde7836a0c..e13ba1b5b3 100644--- a/kernel/conf/editor.go+++ b/kernel/conf/editor.go@@ -60,6 +60,7 @@ type Editor struct {BacklinkExpandCount int `json:"backlinkExpandCount"` // 反向链接默认展开数量BackmentionExpandCount int `json:"backmentionExpandCount"` // 反链提及默认展开数量BacklinkContainChildren bool `json:"backlinkContainChildren"` // 反向链接是否包含子块进行计算+ BacklinkShowBottom bool `json:"backlinkShowBottom"` // 是否在文档底部显示反向链接BacklinkSort *int `json:"backlinkSort"` // 反向链接排序方式BackmentionSort *int `json:"backmentionSort"` // 反链提及排序方式HeadingEmbedMode int `json:"headingEmbedMode"` // 标题嵌入块模式,0:显示标题与下方的块,1:仅显示标题,2:仅显示标题下方的块@@ -106,6 +107,7 @@ func NewEditor() *Editor {BacklinkExpandCount: 8,BackmentionExpandCount: -1,BacklinkContainChildren: true,+ BacklinkShowBottom: false,BacklinkSort: func() *int { v := util.SortModeUpdatedDESC; return &v }(),BackmentionSort: func() *int { v := util.SortModeUpdatedDESC; return &v }(),HeadingEmbedMode: 0,