This commit is contained in:
Vanessa 2022-10-02 20:56:48 +08:00
parent 8b8859bc54
commit 1bb123b74a
15 changed files with 41 additions and 31 deletions

View file

@ -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";

View file

@ -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";

View file

@ -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: "",

View file

@ -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 {

View file

@ -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) {

View file

@ -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;

View file

@ -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;

View file

@ -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"),

View file

@ -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);
});
}
};

View file

@ -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;

View file

@ -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";

View file

@ -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";

View file

@ -401,7 +401,7 @@ interface IOptions {
};
/** 编辑器异步渲染完成后的回调方法 */
after?(protyle: import("../protyle/index").default): void;
after?(protyle: import("../protyle").Protyle): void;
}
interface IProtyle {

View file

@ -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", {

View file

@ -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;