mirror of
https://github.com/siyuan-note/siyuan.git
synced 2025-12-21 17:10:12 +01:00
This commit is contained in:
parent
ab24754196
commit
115767a0f4
11 changed files with 56 additions and 65 deletions
|
|
@ -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");
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -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;
|
||||||
|
|
|
||||||
|
|
@ -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 => {
|
||||||
|
|
|
||||||
|
|
@ -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,7 +601,11 @@ export class Files extends Model {
|
||||||
removeElement.remove();
|
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") {
|
if (targetElement.nextElementSibling?.tagName === "UL") {
|
||||||
targetElement.nextElementSibling.remove();
|
targetElement.nextElementSibling.remove();
|
||||||
|
|
@ -623,6 +627,7 @@ export class Files extends Model {
|
||||||
targetElement.remove();
|
targetElement.remove();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
private onMount(data: { data: { box: INotebook, existed?: boolean }, callback?: string }) {
|
private onMount(data: { data: { box: INotebook, existed?: boolean }, callback?: string }) {
|
||||||
|
|
|
||||||
|
|
@ -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: {
|
||||||
|
|
|
||||||
|
|
@ -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;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -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();
|
||||||
|
|
|
||||||
|
|
@ -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":
|
||||||
|
|
|
||||||
|
|
@ -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;
|
||||||
|
|
|
||||||
|
|
@ -12,8 +12,12 @@ 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();
|
||||||
|
if (data.type === "local" && url === "/api/graph/getLocalGraph") {
|
||||||
|
// 当打开文档A的关系图、关系图、文档A后刷新,由于防止请求重复处理,文档A关系图无法渲染。
|
||||||
|
} else {
|
||||||
data.reqId = window.siyuan.reqIds[url];
|
data.reqId = window.siyuan.reqIds[url];
|
||||||
}
|
}
|
||||||
|
}
|
||||||
if (data instanceof FormData) {
|
if (data instanceof FormData) {
|
||||||
init.body = data;
|
init.body = data;
|
||||||
} else {
|
} else {
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue