mirror of
https://github.com/siyuan-note/siyuan.git
synced 2026-01-22 00:06:09 +01:00
This commit is contained in:
parent
5a9bb84641
commit
a635bcbafd
15 changed files with 63 additions and 64 deletions
|
|
@ -19,8 +19,7 @@ import {resize} from "../protyle/util/resize";
|
|||
export class BlockPanel {
|
||||
public element: HTMLElement;
|
||||
public targetElement: HTMLElement;
|
||||
public nodeIds: string[];
|
||||
public defIds: string[] = [];
|
||||
public refDefs: IRefDefs[];
|
||||
public id: string;
|
||||
private app: App;
|
||||
public x: number;
|
||||
|
|
@ -35,17 +34,15 @@ export class BlockPanel {
|
|||
constructor(options: {
|
||||
app: App,
|
||||
targetElement?: HTMLElement,
|
||||
nodeIds?: string[],
|
||||
defIds?: string[],
|
||||
refDefs: IRefDefs[]
|
||||
isBacklink: boolean,
|
||||
originalRefBlockIDs?: IObject, // isBacklink 为 true 时有效
|
||||
x?: number,
|
||||
y?: number,
|
||||
originalRefBlockIDs?: IObject, // isBacklink 为 true 时有效
|
||||
}) {
|
||||
this.id = genUUID();
|
||||
this.targetElement = options.targetElement;
|
||||
this.nodeIds = options.nodeIds;
|
||||
this.defIds = options.defIds || [];
|
||||
this.refDefs = options.refDefs;
|
||||
this.app = options.app;
|
||||
this.x = options.x;
|
||||
this.y = options.y;
|
||||
|
|
@ -61,7 +58,7 @@ export class BlockPanel {
|
|||
this.element.setAttribute("data-oid", parentElement.getAttribute("data-oid"));
|
||||
level = parseInt(parentElement.getAttribute("data-level")) + 1;
|
||||
} else {
|
||||
this.element.setAttribute("data-oid", this.nodeIds[0]);
|
||||
this.element.setAttribute("data-oid", this.refDefs[0].refID);
|
||||
}
|
||||
// 移除同层级其他更高级的 block popover
|
||||
this.element.setAttribute("data-level", level.toString());
|
||||
|
|
@ -121,13 +118,13 @@ export class BlockPanel {
|
|||
}
|
||||
} else if (type === "open") {
|
||||
/// #if !BROWSER
|
||||
openNewWindowById(this.nodeIds[0]);
|
||||
openNewWindowById(this.refDefs[0].refID);
|
||||
/// #endif
|
||||
} else if (type === "stickTab") {
|
||||
openFileById({
|
||||
app: options.app,
|
||||
id: this.nodeIds[0],
|
||||
action: this.editors[0].protyle.block.rootID !== this.nodeIds[0] ? [Constants.CB_GET_ALL, Constants.CB_GET_FOCUS] : [Constants.CB_GET_CONTEXT],
|
||||
id: this.refDefs[0].refID,
|
||||
action: this.editors[0].protyle.block.rootID !== this.refDefs[0].refID ? [Constants.CB_GET_ALL, Constants.CB_GET_FOCUS] : [Constants.CB_GET_CONTEXT],
|
||||
});
|
||||
}
|
||||
event.preventDefault();
|
||||
|
|
@ -150,7 +147,7 @@ export class BlockPanel {
|
|||
|
||||
private initProtyle(editorElement: HTMLElement, afterCB?: () => void) {
|
||||
const index = parseInt(editorElement.getAttribute("data-index"));
|
||||
fetchPost("/api/block/getBlockInfo", {id: this.nodeIds[index]}, (response) => {
|
||||
fetchPost("/api/block/getBlockInfo", {id: this.refDefs[index].refID}, (response) => {
|
||||
if (response.code === 3) {
|
||||
showMessage(response.msg);
|
||||
return;
|
||||
|
|
@ -159,7 +156,7 @@ export class BlockPanel {
|
|||
return;
|
||||
}
|
||||
const action: TProtyleAction[] = [];
|
||||
if (response.data.rootID !== this.nodeIds[index]) {
|
||||
if (response.data.rootID !== this.refDefs[index].refID) {
|
||||
action.push(Constants.CB_GET_ALL);
|
||||
} else {
|
||||
action.push(Constants.CB_GET_CONTEXT);
|
||||
|
|
@ -170,8 +167,8 @@ export class BlockPanel {
|
|||
action.push(Constants.CB_GET_BACKLINK);
|
||||
}
|
||||
const editor = new Protyle(this.app, editorElement, {
|
||||
blockId: this.nodeIds[index],
|
||||
defId: this.defIds[index] || this.defIds[0] || "",
|
||||
blockId: this.refDefs[index].refID,
|
||||
defIds: this.refDefs[index].defIDs || [],
|
||||
originalRefBlockIDs: this.isBacklink ? this.originalRefBlockIDs : undefined,
|
||||
action,
|
||||
render: {
|
||||
|
|
@ -181,7 +178,7 @@ export class BlockPanel {
|
|||
},
|
||||
typewriterMode: false,
|
||||
after: (editor) => {
|
||||
if (response.data.rootID !== this.nodeIds[index]) {
|
||||
if (response.data.rootID !== this.refDefs[index].refID) {
|
||||
editor.protyle.breadcrumb.element.parentElement.lastElementChild.classList.remove("fn__none");
|
||||
}
|
||||
if (afterCB) {
|
||||
|
|
@ -235,7 +232,7 @@ export class BlockPanel {
|
|||
return;
|
||||
}
|
||||
let openHTML = "";
|
||||
if (this.nodeIds.length === 1) {
|
||||
if (this.refDefs.length === 1) {
|
||||
openHTML = `<span data-type="stickTab" class="block__icon block__icon--show b3-tooltips b3-tooltips__sw" aria-label="${window.siyuan.languages.openBy}"><svg><use xlink:href="#iconOpen"></use></svg></span>
|
||||
<span class="fn__space"></span>`;
|
||||
/// #if !BROWSER
|
||||
|
|
@ -250,10 +247,10 @@ export class BlockPanel {
|
|||
<span data-type="close" class="block__icon block__icon--show b3-tooltips b3-tooltips__sw" aria-label="${window.siyuan.languages.close}"><svg style="width: 12px;margin: 0 1px;"><use xlink:href="#iconClose"></use></svg></span>
|
||||
</div>
|
||||
<div class="block__content">`;
|
||||
if (this.nodeIds.length === 0) {
|
||||
if (this.refDefs.length === 0) {
|
||||
html += `<div class="ft__smaller ft__smaller ft__secondary b3-form__space--small" contenteditable="false">${window.siyuan.languages.refExpired}</div>`;
|
||||
} else {
|
||||
this.nodeIds.forEach((item, index) => {
|
||||
this.refDefs.forEach((item, index) => {
|
||||
html += `<div class="block__edit fn__flex-1 protyle" data-index="${index}"></div>`;
|
||||
});
|
||||
}
|
||||
|
|
|
|||
|
|
@ -334,24 +334,23 @@ export const showPopover = async (app: App, showRef = false) => {
|
|||
if (!popoverTargetElement || window.siyuan.menus.menu.data?.isSameNode(popoverTargetElement)) {
|
||||
return;
|
||||
}
|
||||
let ids: string[];
|
||||
let defIds: string[];
|
||||
let refDefs: IRefDefs[];
|
||||
let originalRefBlockIDs: IObject
|
||||
const dataId = popoverTargetElement.getAttribute("data-id");
|
||||
if (dataId) {
|
||||
// backlink/util/hint/正文标题 上的弹层
|
||||
if (showRef) {
|
||||
const postResponse = await fetchSyncPost("/api/block/getRefIDs", {id: dataId});
|
||||
ids = postResponse.data.refIDs;
|
||||
defIds = postResponse.data.defIDs;
|
||||
refDefs = postResponse.data.refIDs;
|
||||
originalRefBlockIDs = postResponse.data.originalRefBlockIDs;
|
||||
} else {
|
||||
if (dataId.startsWith("[")) {
|
||||
ids = JSON.parse(dataId);
|
||||
JSON.parse(dataId).forEach((item: string) => {
|
||||
refDefs.push({refID: item});
|
||||
});
|
||||
} else {
|
||||
ids = [dataId];
|
||||
refDefs = [{refID: dataId}];
|
||||
}
|
||||
defIds = JSON.parse(popoverTargetElement.getAttribute("data-defids") || "[]");
|
||||
}
|
||||
} else if (popoverTargetElement.getAttribute("data-type")?.indexOf("virtual-block-ref") > -1) {
|
||||
const nodeElement = hasClosestBlock(popoverTargetElement);
|
||||
|
|
@ -360,18 +359,18 @@ export const showPopover = async (app: App, showRef = false) => {
|
|||
anchor: popoverTargetElement.textContent,
|
||||
excludeIDs: [nodeElement.getAttribute("data-node-id")]
|
||||
});
|
||||
ids = postResponse.data;
|
||||
refDefs = postResponse.data.refDefs;
|
||||
}
|
||||
} else if (popoverTargetElement.getAttribute("data-type")?.split(" ").includes("a")) {
|
||||
// 以思源协议开头的链接
|
||||
ids = [getIdFromSYProtocol(popoverTargetElement.getAttribute("data-href"))];
|
||||
refDefs = [{refID: getIdFromSYProtocol(popoverTargetElement.getAttribute("data-href"))}];
|
||||
} else if (popoverTargetElement.dataset.type === "url") {
|
||||
// 在 database 的 url 列中以思源协议开头的链接
|
||||
ids = [getIdFromSYProtocol(popoverTargetElement.textContent.trim())];
|
||||
refDefs = [{refID: getIdFromSYProtocol(popoverTargetElement.textContent.trim())}];
|
||||
} else if (popoverTargetElement.dataset.popoverUrl) {
|
||||
// 镜像数据库
|
||||
const postResponse = await fetchSyncPost(popoverTargetElement.dataset.popoverUrl, {avID: popoverTargetElement.dataset.avId});
|
||||
ids = postResponse.data;
|
||||
refDefs = postResponse.data.refDefs;
|
||||
} else {
|
||||
// pdf
|
||||
let targetId;
|
||||
|
|
@ -382,7 +381,9 @@ export const showPopover = async (app: App, showRef = false) => {
|
|||
} else if (popoverTargetElement.classList.contains("pdf__rect")) {
|
||||
const relationIds = popoverTargetElement.getAttribute("data-relations");
|
||||
if (relationIds) {
|
||||
ids = relationIds.split(",");
|
||||
relationIds.split(",").forEach((item: string) => {
|
||||
refDefs.push({refID: item});
|
||||
});
|
||||
url = "";
|
||||
} else {
|
||||
targetId = popoverTargetElement.getAttribute("data-node-id");
|
||||
|
|
@ -394,8 +395,7 @@ export const showPopover = async (app: App, showRef = false) => {
|
|||
}
|
||||
if (url) {
|
||||
const postResponse = await fetchSyncPost(url, {id: targetId});
|
||||
ids = postResponse.data.refIDs;
|
||||
defIds = postResponse.data.defIDs;
|
||||
refDefs = postResponse.data.refIDs;
|
||||
originalRefBlockIDs = postResponse.data.originalRefBlockIDs;
|
||||
}
|
||||
}
|
||||
|
|
@ -403,7 +403,7 @@ export const showPopover = async (app: App, showRef = false) => {
|
|||
let hasPin = false;
|
||||
window.siyuan.blockPanels.find((item) => {
|
||||
if ((item.targetElement || typeof item.x === "number") && item.element.getAttribute("data-pin") === "true"
|
||||
&& JSON.stringify(ids) === JSON.stringify(item.nodeIds)) {
|
||||
&& JSON.stringify(refDefs) === JSON.stringify(item.refDefs)) {
|
||||
hasPin = true;
|
||||
return true;
|
||||
}
|
||||
|
|
@ -415,8 +415,7 @@ export const showPopover = async (app: App, showRef = false) => {
|
|||
app,
|
||||
targetElement: popoverTargetElement,
|
||||
isBacklink: showRef || popoverTargetElement.classList.contains("protyle-attr--refcount") || popoverTargetElement.classList.contains("counter"),
|
||||
nodeIds: ids,
|
||||
defIds,
|
||||
refDefs,
|
||||
originalRefBlockIDs,
|
||||
}));
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue