This commit is contained in:
Vanessa 2023-10-11 11:24:29 +08:00
parent 37f950ba4f
commit 23c3f9f154
6 changed files with 214 additions and 81 deletions

View File

@ -464,7 +464,9 @@ export class Graph extends Model {
if (id) { if (id) {
this.blockId = id; this.blockId = id;
} }
if (!isCurrentEditor(this.blockId)) { if (!isCurrentEditor(this.blockId) &&
this.graphElement.firstElementChild.classList.contains("fn__none") // 引用右键打开关系图
) {
return; return;
} }
this.graphData = response.data; this.graphData = response.data;

View File

@ -2,12 +2,21 @@ import {getAllModels} from "../getAll";
import {Tab} from "../Tab"; import {Tab} from "../Tab";
import {Graph} from "./Graph"; import {Graph} from "./Graph";
import {Outline} from "./Outline"; import {Outline} from "./Outline";
import {resizeTabs, switchWnd} from "../util"; import {getInstanceById, getWndByLayout, resizeTabs, switchWnd} from "../util";
import {Backlink} from "./Backlink"; import {Backlink} from "./Backlink";
import {App} from "../../index";
import {Wnd} from "../Wnd";
import {fetchSyncPost} from "../../util/fetch";
export const openBacklink = (protyle: IProtyle) => { export const openBacklink = async (options: {
app: App,
blockId: string,
rootId?: string,
title?: string,
useBlockId?: boolean,
}) => {
const backlink = getAllModels().backlink.find(item => { const backlink = getAllModels().backlink.find(item => {
if (item.blockId === protyle.block.id && item.type === "local") { if (item.blockId === options.blockId && item.type === "local") {
item.parent.parent.removeTab(item.parent.id); item.parent.parent.removeTab(item.parent.id);
return true; return true;
} }
@ -15,27 +24,49 @@ export const openBacklink = (protyle: IProtyle) => {
if (backlink) { if (backlink) {
return; return;
} }
const newWnd = protyle.model.parent.parent.split("lr"); let wnd: Wnd = undefined;
const tab = new Tab({ const element = document.querySelector(".layout__wnd--active");
if (element) {
wnd = getInstanceById(element.getAttribute("data-id")) as Wnd;
}
if (!wnd) {
wnd = getWndByLayout(window.siyuan.layout.centerLayout);
}
const newWnd = wnd.split("lr");
if (!options.rootId) {
const response = await fetchSyncPost("api/block/getDocInfo", {id: options.blockId});
options.rootId = response.data.rootID
options.useBlockId = response.data.rootID !== response.data.id
options.title = response.data.name || "Untitled"
} else if (!options.title) {
const response = await fetchSyncPost("api/block/getDocInfo", {id: options.blockId});
options.title = response.data.name || "Untitled"
}
newWnd.addTab(new Tab({
icon: "iconLink", icon: "iconLink",
title: protyle.title.editElement.textContent || "Untitled", title: options.title,
callback(tab: Tab) { callback(tab: Tab) {
tab.addModel(new Backlink({ tab.addModel(new Backlink({
app: protyle.app, app: options.app,
type: "local", type: "local",
tab, tab,
// 通过搜索打开的包含上下文,但不是缩放,因此需要传 rootID https://ld246.com/article/1666786639708 // 通过搜索打开的包含上下文,但不是缩放,因此需要传 rootID https://ld246.com/article/1666786639708
blockId: protyle.block.showAll ? protyle.block.id : protyle.block.rootID, blockId: options.useBlockId ? options.blockId : options.rootId,
rootId: protyle.block.rootID, rootId: options.rootId,
})); }));
} }
}); }));
newWnd.addTab(tab);
}; };
export const openGraph = (protyle: IProtyle) => { export const openGraph = async (options: {
app: App,
blockId: string,
rootId?: string,
title?: string,
useBlockId?: boolean,
}) => {
const graph = getAllModels().graph.find(item => { const graph = getAllModels().graph.find(item => {
if (item.blockId === protyle.block.id && item.type === "local") { if (item.blockId === options.blockId && item.type === "local") {
item.parent.parent.removeTab(item.parent.id); item.parent.parent.removeTab(item.parent.id);
return true; return true;
} }
@ -43,24 +74,40 @@ export const openGraph = (protyle: IProtyle) => {
if (graph) { if (graph) {
return; return;
} }
const wnd = protyle.model.parent.parent.split("lr"); let wnd: Wnd = undefined;
const tab = new Tab({ const element = document.querySelector(".layout__wnd--active");
if (element) {
wnd = getInstanceById(element.getAttribute("data-id")) as Wnd;
}
if (!wnd) {
wnd = getWndByLayout(window.siyuan.layout.centerLayout);
}
const newWnd = wnd.split("lr");
if (!options.rootId) {
const response = await fetchSyncPost("api/block/getDocInfo", {id: options.blockId});
options.rootId = response.data.rootID
options.useBlockId = response.data.rootID !== response.data.id
options.title = response.data.name || "Untitled"
} else if (!options.title) {
const response = await fetchSyncPost("api/block/getDocInfo", {id: options.blockId});
options.title = response.data.name || "Untitled"
}
newWnd.addTab(new Tab({
icon: "iconGraph", icon: "iconGraph",
title: protyle.title.editElement.textContent || "Untitled", title: options.title,
callback(tab: Tab) { callback(tab: Tab) {
tab.addModel(new Graph({ tab.addModel(new Graph({
app: protyle.app, app: options.app,
type: "local", type: "local",
tab, tab,
blockId: protyle.block.id, blockId: options.blockId,
rootId: protyle.block.rootID, rootId: options.rootId,
})); }));
} }
}); }));
wnd.addTab(tab);
}; };
export const openOutline = (protyle: IProtyle) => { export const openOutline = async (protyle: IProtyle) => {
const outlinePanel = getAllModels().outline.find(item => { const outlinePanel = getAllModels().outline.find(item => {
if (item.blockId === protyle.block.rootID && item.type === "local") { if (item.blockId === protyle.block.rootID && item.type === "local") {
item.parent.parent.removeTab(item.parent.id); item.parent.parent.removeTab(item.parent.id);
@ -70,10 +117,25 @@ export const openOutline = (protyle: IProtyle) => {
if (outlinePanel) { if (outlinePanel) {
return; return;
} }
const newWnd = protyle.model.parent.parent.split("lr"); let wnd: Wnd = undefined;
const tab = new Tab({ const element = document.querySelector(".layout__wnd--active");
if (element) {
wnd = getInstanceById(element.getAttribute("data-id")) as Wnd;
}
if (!wnd) {
wnd = getWndByLayout(window.siyuan.layout.centerLayout);
}
const newWnd = wnd.split("lr");
let title = ""
if (!protyle.title) {
const response = await fetchSyncPost("api/block/getDocInfo", {id: protyle.block.rootID});
title = response.data.name || "Untitled"
} else {
title = protyle.title.editElement.textContent || "Untitled"
}
newWnd.addTab(new Tab({
icon: "iconAlignCenter", icon: "iconAlignCenter",
title: protyle.title.editElement.textContent || "Untitled", title,
callback(tab: Tab) { callback(tab: Tab) {
tab.addModel(new Outline({ tab.addModel(new Outline({
app: protyle.app, app: protyle.app,
@ -83,11 +145,10 @@ export const openOutline = (protyle: IProtyle) => {
isPreview: !protyle.preview.element.classList.contains("fn__none") isPreview: !protyle.preview.element.classList.contains("fn__none")
})); }));
} }
}); }));
newWnd.addTab(tab);
newWnd.element.classList.remove("fn__flex-1"); newWnd.element.classList.remove("fn__flex-1");
newWnd.element.style.width = "200px"; newWnd.element.style.width = "200px";
switchWnd(newWnd, protyle.model.parent.parent); switchWnd(newWnd, wnd);
}; };
export const resetFloatDockSize = () => { export const resetFloatDockSize = () => {

View File

@ -44,6 +44,7 @@ import {renameTag} from "../util/noRelyPCFunction";
import {hideElements} from "../protyle/ui/hideElements"; import {hideElements} from "../protyle/ui/hideElements";
import {emitOpenMenu} from "../plugin/EventBus"; import {emitOpenMenu} from "../plugin/EventBus";
import {openMobileFileById} from "../mobile/editor"; import {openMobileFileById} from "../mobile/editor";
import {openBacklink, openGraph} from "../layout/dock/util";
export const fileAnnotationRefMenu = (protyle: IProtyle, refElement: HTMLElement) => { export const fileAnnotationRefMenu = (protyle: IProtyle, refElement: HTMLElement) => {
const nodeElement = hasClosestBlock(refElement); const nodeElement = hasClosestBlock(refElement);
@ -255,6 +256,30 @@ export const refMenu = (protyle: IProtyle, element: HTMLElement) => {
} }
}).element); }).element);
/// #endif /// #endif
window.siyuan.menus.menu.append(new MenuItem({type: "separator"}).element);
window.siyuan.menus.menu.append(new MenuItem({
icon: "iconLink",
label: window.siyuan.languages.backlinks,
accelerator: window.siyuan.config.keymap.editor.general.backlinks.custom,
click: () => {
openBacklink({
app: protyle.app,
blockId: refBlockId,
});
}
}).element);
window.siyuan.menus.menu.append(new MenuItem({
icon: "iconGraph",
label: window.siyuan.languages.graphView,
accelerator: window.siyuan.config.keymap.editor.general.graphView.custom,
click: () => {
openGraph({
app: protyle.app,
blockId: refBlockId,
});
}
}).element);
window.siyuan.menus.menu.append(new MenuItem({type: "separator"}).element);
/// #endif /// #endif
let submenu: IMenu[] = []; let submenu: IMenu[] = [];
if (element.getAttribute("data-subtype") === "s") { if (element.getAttribute("data-subtype") === "s") {

View File

@ -57,7 +57,6 @@ export const openTitleMenu = (protyle: IProtyle, position: IPosition) => {
}).element); }).element);
} }
/// #if !MOBILE /// #if !MOBILE
if (protyle.model) {
window.siyuan.menus.menu.append(new MenuItem({type: "separator"}).element); window.siyuan.menus.menu.append(new MenuItem({type: "separator"}).element);
window.siyuan.menus.menu.append(new MenuItem({ window.siyuan.menus.menu.append(new MenuItem({
icon: "iconAlignCenter", icon: "iconAlignCenter",
@ -72,7 +71,13 @@ export const openTitleMenu = (protyle: IProtyle, position: IPosition) => {
label: window.siyuan.languages.backlinks, label: window.siyuan.languages.backlinks,
accelerator: window.siyuan.config.keymap.editor.general.backlinks.custom, accelerator: window.siyuan.config.keymap.editor.general.backlinks.custom,
click: () => { click: () => {
openBacklink(protyle); openBacklink({
app: protyle.app,
blockId: protyle.block.id,
rootId: protyle.block.rootID,
useBlockId: protyle.block.showAll,
title: protyle.title ? (protyle.title.editElement.textContent || "Untitled") : null
});
} }
}).element); }).element);
window.siyuan.menus.menu.append(new MenuItem({ window.siyuan.menus.menu.append(new MenuItem({
@ -80,10 +85,15 @@ export const openTitleMenu = (protyle: IProtyle, position: IPosition) => {
label: window.siyuan.languages.graphView, label: window.siyuan.languages.graphView,
accelerator: window.siyuan.config.keymap.editor.general.graphView.custom, accelerator: window.siyuan.config.keymap.editor.general.graphView.custom,
click: () => { click: () => {
openGraph(protyle); openGraph({
app: protyle.app,
blockId: protyle.block.id,
rootId: protyle.block.rootID,
useBlockId: protyle.block.showAll,
title: protyle.title ? (protyle.title.editElement.textContent || "Untitled") : null
});
} }
}).element); }).element);
}
/// #endif /// #endif
window.siyuan.menus.menu.append(new MenuItem({type: "separator"}).element); window.siyuan.menus.menu.append(new MenuItem({type: "separator"}).element);
window.siyuan.menus.menu.append(new MenuItem({ window.siyuan.menus.menu.append(new MenuItem({
@ -209,7 +219,12 @@ export const openTitleMenu = (protyle: IProtyle, position: IPosition) => {
label: window.siyuan.languages.fileHistory, label: window.siyuan.languages.fileHistory,
icon: "iconHistory", icon: "iconHistory",
click() { click() {
openDocHistory({app: protyle.app, id: protyle.block.rootID, notebookId: protyle.notebookId, pathString: response.data.name}); openDocHistory({
app: protyle.app,
id: protyle.block.rootID,
notebookId: protyle.notebookId,
pathString: response.data.name
});
} }
}).element); }).element);
} }

View File

@ -12,7 +12,7 @@ import {netImg2LocalAssets} from "../breadcrumb/action";
import {openBacklink, openGraph, openOutline} from "../../layout/dock/util"; import {openBacklink, openGraph, openOutline} from "../../layout/dock/util";
/// #endif /// #endif
import {getContenteditableElement, hasNextSibling, hasPreviousSibling} from "./getBlock"; import {getContenteditableElement, hasNextSibling, hasPreviousSibling} from "./getBlock";
import {hasClosestByMatchTag} from "../util/hasClosest"; import {hasClosestByAttribute, hasClosestByMatchTag} from "../util/hasClosest";
import {hideElements} from "../ui/hideElements"; import {hideElements} from "../ui/hideElements";
import {countBlockWord} from "../../layout/status"; import {countBlockWord} from "../../layout/status";
import {scrollCenter} from "../../util/highlightById"; import {scrollCenter} from "../../util/highlightById";
@ -21,7 +21,7 @@ import {onGet} from "../util/onGet";
import {Constants} from "../../constants"; import {Constants} from "../../constants";
import * as dayjs from "dayjs"; import * as dayjs from "dayjs";
export const commonHotkey = (protyle: IProtyle, event: KeyboardEvent, nodeElement?: HTMLElement) => { export const commonHotkey = (protyle: IProtyle, event: KeyboardEvent, nodeElement?: HTMLElement, range?: Range) => {
const target = event.target as HTMLElement; const target = event.target as HTMLElement;
if (matchHotKey(window.siyuan.config.keymap.editor.general.copyHPath.custom, event)) { if (matchHotKey(window.siyuan.config.keymap.editor.general.copyHPath.custom, event)) {
fetchPost("/api/filetree/getHPathByID", { fetchPost("/api/filetree/getHPathByID", {
@ -66,17 +66,48 @@ export const commonHotkey = (protyle: IProtyle, event: KeyboardEvent, nodeElemen
return true; return true;
} }
/// #if !MOBILE /// #if !MOBILE
if (protyle.model) {
if (matchHotKey(window.siyuan.config.keymap.editor.general.backlinks.custom, event)) { if (matchHotKey(window.siyuan.config.keymap.editor.general.backlinks.custom, event)) {
event.preventDefault(); event.preventDefault();
event.stopPropagation(); event.stopPropagation();
openBacklink(protyle); if (range) {
const refElement = hasClosestByAttribute(range.startContainer, "data-type", "block-ref");
if (refElement) {
openBacklink({
app: protyle.app,
blockId: refElement.dataset.id,
});
return true;
}
}
openBacklink({
app: protyle.app,
blockId: protyle.block.id,
rootId: protyle.block.rootID,
useBlockId: protyle.block.showAll,
title: protyle.title ? (protyle.title.editElement.textContent || "Untitled") : null,
});
return true; return true;
} }
if (matchHotKey(window.siyuan.config.keymap.editor.general.graphView.custom, event)) { if (matchHotKey(window.siyuan.config.keymap.editor.general.graphView.custom, event)) {
event.preventDefault(); event.preventDefault();
event.stopPropagation(); event.stopPropagation();
openGraph(protyle); if (range) {
const refElement = hasClosestByAttribute(range.startContainer, "data-type", "block-ref");
if (refElement) {
openGraph({
app: protyle.app,
blockId: refElement.dataset.id,
});
return true;
}
}
openGraph({
app: protyle.app,
blockId: protyle.block.id,
rootId: protyle.block.rootID,
useBlockId: protyle.block.showAll,
title: protyle.title ? (protyle.title.editElement.textContent || "Untitled") : null,
});
return true; return true;
} }
if (matchHotKey(window.siyuan.config.keymap.editor.general.outline.custom, event)) { if (matchHotKey(window.siyuan.config.keymap.editor.general.outline.custom, event)) {
@ -88,7 +119,6 @@ export const commonHotkey = (protyle: IProtyle, event: KeyboardEvent, nodeElemen
focusByOffset(target, offset.start, offset.end); focusByOffset(target, offset.start, offset.end);
return true; return true;
} }
}
let matchCommand = false; let matchCommand = false;
protyle.app.plugins.find(item => { protyle.app.plugins.find(item => {

View File

@ -983,7 +983,7 @@ export const keydown = (protyle: IProtyle, editorElement: HTMLElement) => {
return true; return true;
} }
/// #if !MOBILE /// #if !MOBILE
if (commonHotkey(protyle, event, nodeElement)) { if (commonHotkey(protyle, event, nodeElement, range)) {
return true; return true;
} }
/// #endif /// #endif