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; public pdfObject: any;
constructor(options: { tab: Tab, path: string, page?: number | string }) { constructor(options: { tab: Tab, path: string, page?: number | string }) {
super({ super({id: options.tab.id});
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;
}
}
}
});
if (window.siyuan.config.fileTree.openFilesUseCurrentTab) { if (window.siyuan.config.fileTree.openFilesUseCurrentTab) {
options.tab.headElement.classList.add("item--unupdate"); options.tab.headElement.classList.add("item--unupdate");
} }

View file

@ -50,7 +50,7 @@ export const deleteFiles = (liElements: Element[]) => {
const paths: string[] = [] const paths: string[] = []
liElements.forEach(item => { liElements.forEach(item => {
const dataPath = item.getAttribute("data-path") const dataPath = item.getAttribute("data-path")
if(dataPath !== "/") { if (dataPath !== "/") {
paths.push(item.getAttribute("data-path")); paths.push(item.getAttribute("data-path"));
} }
}) })

View file

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

View file

@ -38,7 +38,7 @@ export class Bookmark extends Model {
}); });
break; break;
case "unmount": case "unmount":
case "remove": case "removeDoc":
case "mount": case "mount":
if (data.cmd !== "mount" || data.code !== 1) { if (data.cmd !== "mount" || data.code !== 1) {
fetchPost("/api/bookmark/getBookmark", {}, response => { 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)); this.element.insertAdjacentHTML("beforeend", this.genNotebook(data.data.box));
break; break;
case "unmount": case "unmount":
case "remove": case "removeDoc":
this.onRemove(data); this.onRemove(data);
break; break;
case "createdailynote": case "createdailynote":
@ -579,9 +579,9 @@ export class Files extends Model {
private onRemove(data: IWebSocketData) { private onRemove(data: IWebSocketData) {
// "doc2heading" 后删除文件或挂载帮助文档前的 unmount // "doc2heading" 后删除文件或挂载帮助文档前的 unmount
const targetElement = this.element.querySelector(`ul[data-url="${data.data.box}"] li[data-path="${data.data.path || "/"}"]`);
if (data.cmd === "unmount") { if (data.cmd === "unmount") {
setNoteBook((notebooks) => { setNoteBook((notebooks) => {
const targetElement = this.element.querySelector(`ul[data-url="${data.data.box}"] li[data-path="${"/"}"]`);
if (targetElement) { if (targetElement) {
targetElement.parentElement.remove(); targetElement.parentElement.remove();
if (Constants.CB_MOUNT_REMOVE !== data.callback) { if (Constants.CB_MOUNT_REMOVE !== data.callback) {
@ -601,28 +601,33 @@ export class Files extends Model {
removeElement.remove(); removeElement.remove();
} }
} }
} else if (targetElement) { return;
// 子节点展开则删除
if (targetElement.nextElementSibling?.tagName === "UL") {
targetElement.nextElementSibling.remove();
}
// 移除当前节点
const parentElement = targetElement.parentElement.previousElementSibling as HTMLElement;
if (targetElement.parentElement.childElementCount === 1) {
if (parentElement) {
const iconElement = parentElement.querySelector("svg");
iconElement.classList.remove("b3-list-item__arrow--open");
iconElement.parentElement.classList.add("fn__hidden");
const emojiElement = iconElement.parentElement.nextElementSibling;
if (emojiElement.innerHTML === unicode2Emoji(Constants.SIYUAN_IMAGE_FOLDER)) {
emojiElement.innerHTML = unicode2Emoji(Constants.SIYUAN_IMAGE_FILE);
}
}
targetElement.parentElement.remove();
} else {
targetElement.remove();
}
} }
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();
}
// 移除当前节点
const parentElement = targetElement.parentElement.previousElementSibling as HTMLElement;
if (targetElement.parentElement.childElementCount === 1) {
if (parentElement) {
const iconElement = parentElement.querySelector("svg");
iconElement.classList.remove("b3-list-item__arrow--open");
iconElement.parentElement.classList.add("fn__hidden");
const emojiElement = iconElement.parentElement.nextElementSibling;
if (emojiElement.innerHTML === unicode2Emoji(Constants.SIYUAN_IMAGE_FOLDER)) {
emojiElement.innerHTML = unicode2Emoji(Constants.SIYUAN_IMAGE_FILE);
}
}
targetElement.parentElement.remove();
} else {
targetElement.remove();
}
}
})
} }
private onMount(data: { data: { box: INotebook, existed?: boolean }, callback?: string }) { 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 {getDockByType, setPanelFocus} from "../util";
import {Model} from "../Model"; import {Model} from "../Model";
import {Constants} from "../../constants"; import {Constants} from "../../constants";
import {getDisplayName} from "../../util/pathName";
import {addScript} from "../../protyle/util/addScript"; import {addScript} from "../../protyle/util/addScript";
import {BlockPanel} from "../../block/Panel"; import {BlockPanel} from "../../block/Panel";
import {fullscreen} from "../../protyle/breadcrumb/action"; import {fullscreen} from "../../protyle/breadcrumb/action";
@ -54,7 +53,7 @@ export class Graph extends Model {
} }
break; break;
case "rename": 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); this.searchGraph(false);
if (this.type === "local") { if (this.type === "local") {
this.parent.updateTitle(data.data.title); this.parent.updateTitle(data.data.title);
@ -64,22 +63,13 @@ export class Graph extends Model {
this.searchGraph(false); this.searchGraph(false);
} }
break; break;
case "moveDoc": case "unmount":
if (this.type === "global") { if (this.type === "local" && this.graphData && this.graphData.box === data.data.box) {
this.searchGraph(false); this.parent.parent.removeTab(this.parent.id);
} 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);
} }
break; break;
case "unmount": case "removeDoc":
case "remove": if (this.type === "local" && data.data.ids.includes(this.rootId)) {
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)) {
this.parent.parent.removeTab(this.parent.id); this.parent.parent.removeTab(this.parent.id);
} }
break; break;
@ -453,6 +443,7 @@ export class Graph extends Model {
}); });
} else { } else {
fetchPost("/api/graph/getLocalGraph", { fetchPost("/api/graph/getLocalGraph", {
type: this.type, // 用于如下场景当打开文档A的关系图、关系图、文档A后刷新由于防止请求重复处理文档A关系图无法渲染。
k: this.inputElement.value, k: this.inputElement.value,
id: id || this.blockId, id: id || this.blockId,
conf: { conf: {

View file

@ -61,6 +61,11 @@ export class Outline extends Model {
}); });
} }
break; 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; break;
case "unmount": case "unmount":
case "remove": case "removeDoc":
case "mount": case "mount":
if (data.cmd !== "mount" || data.code !== 1) { if (data.cmd !== "mount" || data.code !== 1) {
this.update(); this.update();

View file

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

View file

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

View file

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