diff --git a/app/src/block/Panel.ts b/app/src/block/Panel.ts index 643b55a54..8721a801b 100644 --- a/app/src/block/Panel.ts +++ b/app/src/block/Panel.ts @@ -1,5 +1,5 @@ import {hasClosestByClassName} from "../protyle/util/hasClosest"; -import Protyle from "../protyle"; +import {Protyle} from "../protyle"; import {genUUID} from "../util/genID"; import {setPadding} from "../protyle/ui/initUI"; import {setPosition} from "../util/setPosition"; diff --git a/app/src/editor/index.ts b/app/src/editor/index.ts index 3f1518e27..f6fc3d17d 100644 --- a/app/src/editor/index.ts +++ b/app/src/editor/index.ts @@ -1,5 +1,5 @@ import {Tab} from "../layout/Tab"; -import Protyle from "../protyle"; +import {Protyle} from "../protyle"; import {Model} from "../layout/Model"; import {disabledProtyle} from "../protyle/util/onGet"; import {setPadding} from "../protyle/ui/initUI"; diff --git a/app/src/layout/dock/Backlink.ts b/app/src/layout/dock/Backlink.ts index 3d62be607..b7490bacc 100644 --- a/app/src/layout/dock/Backlink.ts +++ b/app/src/layout/dock/Backlink.ts @@ -2,16 +2,12 @@ import {Tab} from "../Tab"; import {Model} from "../Model"; import {getDisplayName} from "../../util/pathName"; import {Tree} from "../../util/Tree"; -import {hasClosestByClassName} from "../../protyle/util/hasClosest"; import {getDockByType, setPanelFocus} from "../util"; import {fetchPost} from "../../util/fetch"; import {Constants} from "../../constants"; -import {getAllModels} from "../getAll"; -import {onGet} from "../../protyle/util/onGet"; import {updateHotkeyTip} from "../../protyle/util/compatibility"; import {openFileById} from "../../editor/util"; -import {MenuItem} from "../../menus/Menu"; -import Protyle from "../../protyle"; +import {Protyle} from "../../protyle"; export class Backlink extends Model { public element: HTMLElement; @@ -306,6 +302,8 @@ export class Backlink extends Model { }, (response) => { const editorElement = document.createElement("div"); editorElement.style.minHeight = "auto"; + editorElement.setAttribute("data-defid", this.blockId) + editorElement.setAttribute("data-ismention", isMention? "true" : "false") liElement.after(editorElement); const editor = new Protyle(editorElement, { blockId: "", diff --git a/app/src/layout/dock/index.ts b/app/src/layout/dock/index.ts index 11a554ba6..f0288a881 100644 --- a/app/src/layout/dock/index.ts +++ b/app/src/layout/dock/index.ts @@ -11,7 +11,7 @@ import {Graph} from "./Graph"; import {Model} from "../Model"; import {getDockByType, resizeTabs, setPanelFocus} from "../util"; import {Inbox} from "./Inbox"; -import Protyle from "../../protyle"; +import {Protyle} from "../../protyle"; import {Backlink} from "./Backlink"; export class Dock { diff --git a/app/src/menus/protyle.ts b/app/src/menus/protyle.ts index 99df66078..672cbbc5b 100644 --- a/app/src/menus/protyle.ts +++ b/app/src/menus/protyle.ts @@ -383,6 +383,9 @@ export const contentMenu = (protyle: IProtyle, nodeElement: Element) => { }; export const zoomOut = (protyle: IProtyle, id: string, focusId?: string, isPushBack = true, callback?: () => void) => { + if (protyle.options.backlinkData) { + return; + } const breadcrumbHLElement = protyle.breadcrumb?.element.querySelector(".protyle-breadcrumb__item--active"); if (breadcrumbHLElement && breadcrumbHLElement.getAttribute("data-node-id") === id) { if (id === protyle.block.rootID) { diff --git a/app/src/mobile/editor.ts b/app/src/mobile/editor.ts index a8e9352e2..eee385851 100644 --- a/app/src/mobile/editor.ts +++ b/app/src/mobile/editor.ts @@ -1,4 +1,4 @@ -import Protyle from "../protyle"; +import {Protyle} from "../protyle"; import {setEditor} from "./util/setEmpty"; import {closePanel} from "./util/closePanel"; import {Constants} from "../constants"; @@ -21,7 +21,7 @@ export const openMobileFileById = (id: string, action = [Constants.CB_GET_HL]) = setEditMode(window.siyuan.mobileEditor.protyle, "wysiwyg"); } let blockElement; - Array.from(window.siyuan.mobileEditor.protyle.wysiwyg.element.querySelectorAll(`[data-node-id="${id}"]`)).find(item => { + Array.from(window.siyuan.mobileEditor.protyle.wysiwyg.element.querySelectorAll(`[data-node-id="${id}"]`)).find((item: HTMLElement) => { if (!hasClosestByAttribute(item.parentElement, "data-type", "NodeBlockQueryEmbed")) { blockElement = item; return true; diff --git a/app/src/protyle/index.ts b/app/src/protyle/index.ts index c5ff89e44..1d903d3fe 100644 --- a/app/src/protyle/index.ts +++ b/app/src/protyle/index.ts @@ -27,7 +27,7 @@ import {onGet} from "./util/onGet"; import {reloadProtyle} from "./util/reload"; import {renderBacklink} from "./wysiwyg/renderBacklink"; -class Protyle { +export class Protyle { public readonly version: string; public protyle: IProtyle; @@ -95,7 +95,7 @@ class Protyle { case "heading2doc": case "li2doc": if (this.protyle.block.rootID === data.data.srcRootBlockID) { - if (this.protyle.block.showAll && data.cmd === "heading2doc") { + if (this.protyle.block.showAll && data.cmd === "heading2doc" && !this.protyle.options.backlinkData) { fetchPost("/api/filetree/getDoc", { id: this.protyle.block.rootID, size: Constants.SIZE_GET, @@ -245,5 +245,3 @@ class Protyle { destroy(this.protyle); } } - -export default Protyle; diff --git a/app/src/protyle/util/editorCommonEvent.ts b/app/src/protyle/util/editorCommonEvent.ts index 76ab100fb..3a70030fc 100644 --- a/app/src/protyle/util/editorCommonEvent.ts +++ b/app/src/protyle/util/editorCommonEvent.ts @@ -654,7 +654,8 @@ export const dropEvent = (protyle: IProtyle, editorElement: HTMLElement) => { } } } - } else if (window.siyuan.dragElement && window.siyuan.dragElement.getAttribute("data-type") === "navigation-file" && targetElement) { + } else if (window.siyuan.dragElement && window.siyuan.dragElement.getAttribute("data-type") === "navigation-file" + && targetElement && !protyle.options.backlinkData) { // 文件树拖拽 fetchPost("/api/filetree/doc2Heading", { srcID: window.siyuan.dragElement.getAttribute("data-node-id"), diff --git a/app/src/protyle/util/reload.ts b/app/src/protyle/util/reload.ts index 93e96a38a..c3471d5c3 100644 --- a/app/src/protyle/util/reload.ts +++ b/app/src/protyle/util/reload.ts @@ -3,11 +3,9 @@ import {fetchPost} from "../../util/fetch"; import {Constants} from "../../constants"; import {onGet} from "./onGet"; import {saveScroll} from "../scroll/saveScroll"; +import {renderBacklink} from "../wysiwyg/renderBacklink"; export const reloadProtyle = (protyle:IProtyle) => { - if (protyle.options.backlinkData) { - return; - } if (window.siyuan.config.editor.displayBookmarkIcon) { protyle.wysiwyg.element.classList.add("protyle-wysiwyg--attr"); } else { @@ -15,11 +13,22 @@ export const reloadProtyle = (protyle:IProtyle) => { } protyle.lute.SetProtyleMarkNetImg(window.siyuan.config.editor.displayNetImgMark); addLoading(protyle); - fetchPost("/api/filetree/getDoc", { - id: protyle.block.showAll ? protyle.block.id : protyle.block.rootID, - mode: 0, - size: protyle.block.showAll ? Constants.SIZE_GET_MAX : Constants.SIZE_GET, - }, getResponse => { - onGet(getResponse, protyle, protyle.block.showAll ? [Constants.CB_GET_ALL, Constants.CB_GET_FOCUS] : [Constants.CB_GET_FOCUS], saveScroll(protyle, true), true); - }); + if (protyle.options.backlinkData) { + const isMention = protyle.element.getAttribute("data-ismention") === "true"; + fetchPost(isMention ? "/api/ref/getBackmentionDoc" : "/api/ref/getBacklinkDoc", { + defID: protyle.element.getAttribute("data-defid"), + refTreeID: protyle.block.rootID + }, response => { + protyle.options.backlinkData = isMention ? response.data.backmentions : response.data.backlinks, + renderBacklink(protyle, protyle.options.backlinkData); + }); + } else { + fetchPost("/api/filetree/getDoc", { + id: protyle.block.showAll ? protyle.block.id : protyle.block.rootID, + mode: 0, + size: protyle.block.showAll ? Constants.SIZE_GET_MAX : Constants.SIZE_GET, + }, getResponse => { + onGet(getResponse, protyle, protyle.block.showAll ? [Constants.CB_GET_ALL, Constants.CB_GET_FOCUS] : [Constants.CB_GET_FOCUS], saveScroll(protyle, true), true); + }); + } }; diff --git a/app/src/protyle/wysiwyg/keydown.ts b/app/src/protyle/wysiwyg/keydown.ts index 2c7d97b7e..fb45f6116 100644 --- a/app/src/protyle/wysiwyg/keydown.ts +++ b/app/src/protyle/wysiwyg/keydown.ts @@ -446,7 +446,8 @@ export const keydown = (protyle: IProtyle, editorElement: HTMLElement) => { // ctrl+home 光标移动到顶 if (!event.altKey && !event.shiftKey && isCtrl(event) && event.key === "Home") { if (protyle.wysiwyg.element.firstElementChild.getAttribute("data-node-index") === "0" || - protyle.wysiwyg.element.firstElementChild.getAttribute("data-eof") === "true") { + protyle.wysiwyg.element.firstElementChild.getAttribute("data-eof") === "true" || + protyle.options.backlinkData) { focusBlock(protyle.wysiwyg.element.firstElementChild); protyle.contentElement.scrollTop = 0; protyle.scroll.lastScrollTop = 1; diff --git a/app/src/search/index.ts b/app/src/search/index.ts index 2a7b6ab04..cfe3e1abb 100644 --- a/app/src/search/index.ts +++ b/app/src/search/index.ts @@ -1,6 +1,6 @@ import {Model} from "../layout/Model"; import {Tab} from "../layout/Tab"; -import Protyle from "../protyle"; +import {Protyle} from "../protyle"; import {Constants} from "../constants"; import {getIconByType} from "../editor/getIcon"; import {getDisplayName, getNotebookName} from "../util/pathName"; diff --git a/app/src/search/spread.ts b/app/src/search/spread.ts index 85b480d90..d14682bf9 100644 --- a/app/src/search/spread.ts +++ b/app/src/search/spread.ts @@ -2,7 +2,7 @@ import {escapeHtml} from "../util/escape"; import {getIconByType} from "../editor/getIcon"; import {getDisplayName, getNotebookName, pathPosix} from "../util/pathName"; import {Constants} from "../constants"; -import Protyle from "../protyle"; +import {Protyle} from "../protyle"; import {Dialog} from "../dialog"; import {fetchPost, fetchSyncPost} from "../util/fetch"; import {onGet} from "../protyle/util/onGet"; diff --git a/app/src/types/protyle.d.ts b/app/src/types/protyle.d.ts index 1c04ac1f2..f5db501b4 100644 --- a/app/src/types/protyle.d.ts +++ b/app/src/types/protyle.d.ts @@ -401,7 +401,7 @@ interface IOptions { }; /** 编辑器异步渲染完成后的回调方法 */ - after?(protyle: import("../protyle/index").default): void; + after?(protyle: import("../protyle").Protyle): void; } interface IProtyle { diff --git a/app/src/util/globalShortcut.ts b/app/src/util/globalShortcut.ts index 999c3094c..6fcb14c03 100644 --- a/app/src/util/globalShortcut.ts +++ b/app/src/util/globalShortcut.ts @@ -771,7 +771,7 @@ const editKeydown = (event: KeyboardEvent) => { event.stopPropagation(); return true; } - if (matchHotKey(window.siyuan.config.keymap.editor.general.wysiwyg.custom, event)) { + if (matchHotKey(window.siyuan.config.keymap.editor.general.wysiwyg.custom, event) && !protyle.options.backlinkData) { setEditMode(protyle, "wysiwyg"); protyle.scroll.lastScrollTop = 0; fetchPost("/api/filetree/getDoc", { diff --git a/app/src/util/history.ts b/app/src/util/history.ts index ca460ee84..00bf39cf6 100644 --- a/app/src/util/history.ts +++ b/app/src/util/history.ts @@ -6,7 +6,7 @@ import {escapeHtml} from "./escape"; import {isMobile} from "./functions"; import {hasClosestByClassName} from "../protyle/util/hasClosest"; import {renderAssetsPreview} from "../asset/renderAssets"; -import Protyle from "../protyle"; +import {Protyle} from "../protyle"; import {onGet} from "../protyle/util/onGet"; let historyEditor: Protyle;