This commit is contained in:
Vanessa 2022-11-03 22:47:19 +08:00
parent ab24754196
commit 115767a0f4
11 changed files with 56 additions and 65 deletions

View file

@ -18,20 +18,7 @@ export class Asset extends Model {
public pdfObject: any;
constructor(options: { tab: Tab, path: string, page?: number | string }) {
super({
id: options.tab.id,
msgCallback(data) {
if (data) {
switch (data.cmd) {
case "remove":
if (data.data.path === this.path) {
this.parent.parent.removeTab(this.parent.id);
}
break;
}
}
}
});
super({id: options.tab.id});
if (window.siyuan.config.fileTree.openFilesUseCurrentTab) {
options.tab.headElement.classList.add("item--unupdate");
}

View file

@ -53,17 +53,17 @@ export class Backlink extends Model {
if (data && this.type === "local") {
switch (data.cmd) {
case "rename":
if (this.blockId === data.data.id) {
if (this.rootId === data.data.id) {
this.parent.updateTitle(data.data.title);
}
break;
case "unmount":
if (this.notebookId === data.data.box) {
if (this.notebookId === data.data.box && this.type === "local") {
this.parent.parent.removeTab(this.parent.id);
}
break;
case "remove":
if (this.path?.indexOf(getDisplayName(data.data.path, false, true)) === 0) {
case "removeDoc":
if (data.data.ids.includes(this.rootId) && this.type === "local") {
this.parent.parent.removeTab(this.parent.id);
}
break;

View file

@ -38,7 +38,7 @@ export class Bookmark extends Model {
});
break;
case "unmount":
case "remove":
case "removeDoc":
case "mount":
if (data.cmd !== "mount" || data.code !== 1) {
fetchPost("/api/bookmark/getBookmark", {}, response => {

View file

@ -42,7 +42,7 @@ export class Files extends Model {
this.element.insertAdjacentHTML("beforeend", this.genNotebook(data.data.box));
break;
case "unmount":
case "remove":
case "removeDoc":
this.onRemove(data);
break;
case "createdailynote":
@ -579,9 +579,9 @@ export class Files extends Model {
private onRemove(data: IWebSocketData) {
// "doc2heading" 后删除文件或挂载帮助文档前的 unmount
const targetElement = this.element.querySelector(`ul[data-url="${data.data.box}"] li[data-path="${data.data.path || "/"}"]`);
if (data.cmd === "unmount") {
setNoteBook((notebooks) => {
const targetElement = this.element.querySelector(`ul[data-url="${data.data.box}"] li[data-path="${"/"}"]`);
if (targetElement) {
targetElement.parentElement.remove();
if (Constants.CB_MOUNT_REMOVE !== data.callback) {
@ -601,7 +601,11 @@ export class Files extends Model {
removeElement.remove();
}
}
} else if (targetElement) {
return;
}
data.data.ids.forEach((item: string) => {
const targetElement = this.element.querySelector(`li.b3-list-item[data-node-id="${item}"]`);
if (targetElement) {
// 子节点展开则删除
if (targetElement.nextElementSibling?.tagName === "UL") {
targetElement.nextElementSibling.remove();
@ -623,6 +627,7 @@ export class Files extends Model {
targetElement.remove();
}
}
})
}
private onMount(data: { data: { box: INotebook, existed?: boolean }, callback?: string }) {

View file

@ -2,7 +2,6 @@ import {Tab} from "../Tab";
import {getDockByType, setPanelFocus} from "../util";
import {Model} from "../Model";
import {Constants} from "../../constants";
import {getDisplayName} from "../../util/pathName";
import {addScript} from "../../protyle/util/addScript";
import {BlockPanel} from "../../block/Panel";
import {fullscreen} from "../../protyle/breadcrumb/action";
@ -54,7 +53,7 @@ export class Graph extends Model {
}
break;
case "rename":
if (this.graphData && data.data.box === this.graphData.box && this.path === data.data.path) {
if (this.graphData && data.data.box === this.graphData.box && this.rootId === data.data.id) {
this.searchGraph(false);
if (this.type === "local") {
this.parent.updateTitle(data.data.title);
@ -64,22 +63,13 @@ export class Graph extends Model {
this.searchGraph(false);
}
break;
case "moveDoc":
if (this.type === "global") {
this.searchGraph(false);
} else if (this.graphData && (data.data.fromNotebook === this.graphData.box || data.data.toNotebook === this.graphData.box) &&
this.path === data.data.fromPath) {
this.path = data.data.newPath;
this.graphData.box = data.data.toNotebook;
this.searchGraph(false);
case "unmount":
if (this.type === "local" && this.graphData && this.graphData.box === data.data.box) {
this.parent.parent.removeTab(this.parent.id);
}
break;
case "unmount":
case "remove":
if (this.type === "global") {
this.searchGraph(false);
} else if (this.graphData && this.graphData.box === data.data.box &&
(!data.data.path || this.path.indexOf(getDisplayName(data.data.path, false, true)) === 0)) {
case "removeDoc":
if (this.type === "local" && data.data.ids.includes(this.rootId)) {
this.parent.parent.removeTab(this.parent.id);
}
break;
@ -453,6 +443,7 @@ export class Graph extends Model {
});
} else {
fetchPost("/api/graph/getLocalGraph", {
type: this.type, // 用于如下场景当打开文档A的关系图、关系图、文档A后刷新由于防止请求重复处理文档A关系图无法渲染。
k: this.inputElement.value,
id: id || this.blockId,
conf: {

View file

@ -61,6 +61,11 @@ export class Outline extends Model {
});
}
break;
case "removeDoc":
if (data.data.ids.includes(this.blockId) && this.type === "local") {
this.parent.parent.removeTab(this.parent.id);
}
break;
}
}
}

View file

@ -35,7 +35,7 @@ export class Tag extends Model {
});
break;
case "unmount":
case "remove":
case "removeDoc":
case "mount":
if (data.cmd !== "mount" || data.code !== 1) {
this.update();

View file

@ -38,7 +38,7 @@ export class MobileFiles extends Model {
this.element.insertAdjacentHTML("beforeend", this.genNotebook(data.data.box));
break;
case "unmount":
case "remove":
case "removeDoc":
this.onRemove(data);
break;
case "createdailynote":

View file

@ -148,9 +148,8 @@ export class Protyle {
this.protyle.model.parent.parent.removeTab(this.protyle.model.parent.id, false, false);
}
break;
case "remove":
if (this.protyle.model && (this.protyle.notebookId === data.data.box &&
(!data.data.path || this.protyle.path.indexOf(getDisplayName(data.data.path, false, true)) === 0))) {
case "removeDoc":
if (this.protyle.model && data.data.ids.includes(this.protyle.block.rootID)) {
this.protyle.model.parent.parent.removeTab(this.protyle.model.parent.id, false, false);
}
break;

View file

@ -12,8 +12,12 @@ export const fetchPost = (url: string, data?: any, cb?: (response: IWebSocketDat
if (data) {
if (["/api/search/searchRefBlock", "/api/graph/getGraph", "/api/graph/getLocalGraph"].includes(url)) {
window.siyuan.reqIds[url] = new Date().getTime();
if (data.type === "local" && url === "/api/graph/getLocalGraph") {
// 当打开文档A的关系图、关系图、文档A后刷新由于防止请求重复处理文档A关系图无法渲染。
} else {
data.reqId = window.siyuan.reqIds[url];
}
}
if (data instanceof FormData) {
init.body = data;
} else {