Vanessa 2024-09-18 11:34:41 +08:00
parent 4f31068205
commit 141889f058
5 changed files with 28 additions and 41 deletions

View file

@ -105,6 +105,7 @@ export const reloadSync = (
} else if (item.type !== "local" || data.upsertRootIDs.includes(item.blockId)) {
fetchPost("/api/outline/getDocOutline", {
id: item.blockId,
preview: item.isPreview
}, response => {
item.update(response);
});

View file

@ -578,23 +578,29 @@ export const isCurrentEditor = (blockId: string) => {
export const updateOutline = (models: IModels, protyle: IProtyle, reload = false) => {
models.outline.find(item => {
if (protyle && item.blockId === protyle.block.rootID && item.type === "pin") {
item.isPreview = !protyle.preview.element.classList.contains("fn__none");
}
if (reload || (item.type === "pin" && (!protyle || item.blockId !== protyle.block?.rootID))) {
if (reload ||
(item.type === "pin" &&
(!protyle || item.blockId !== protyle.block?.rootID ||
item.isPreview === protyle.preview.element.classList.contains("fn__none"))
)
) {
let blockId = "";
if (protyle && protyle.block) {
blockId = protyle.block.rootID;
}
if (blockId === item.blockId && !reload) {
if (blockId === item.blockId && !reload && item.isPreview !== protyle.preview.element.classList.contains("fn__none")) {
return;
}
fetchPost("/api/outline/getDocOutline", {
id: blockId,
preview: !protyle.preview.element.classList.contains("fn__none")
}, response => {
if (!reload && (!isCurrentEditor(blockId) || item.blockId === blockId)) {
if (!reload && (!isCurrentEditor(blockId) || item.blockId === blockId) &&
item.isPreview !== protyle.preview.element.classList.contains("fn__none")) {
return;
}
item.isPreview = !protyle.preview.element.classList.contains("fn__none");
item.update(response, blockId);
if (protyle) {
item.updateDocTitle(protyle.background.ial);

View file

@ -182,7 +182,7 @@ export class Outline extends Model {
openFileById({
app: options.app,
id: this.blockId,
afterOpen: (model: Editor) =>{
afterOpen: (model: Editor) => {
if (model) {
if (this.isPreview) {
model.editor.protyle.preview.element.querySelector(".b3-typography").scrollTop = 0;
@ -206,22 +206,13 @@ export class Outline extends Model {
}
});
this.bindSort();
if (this.isPreview) {
if (this.blockId) {
fetchPost("/api/export/preview", {
id: this.blockId,
}, response => {
response.data = response.data.outline;
this.update(response);
});
}
} else {
fetchPost("/api/outline/getDocOutline", {
id: this.blockId,
}, response => {
this.update(response);
});
}
fetchPost("/api/outline/getDocOutline", {
id: this.blockId,
preview: this.isPreview
}, response => {
this.update(response);
});
}
private bindSort() {
@ -368,7 +359,7 @@ export class Outline extends Model {
}
private onTransaction(data: IWebSocketData) {
if (this.isPreview || data.data.rootID !== this.blockId) {
if (data.data.rootID !== this.blockId) {
return;
}
let needReload = false;
@ -397,6 +388,7 @@ export class Outline extends Model {
if (needReload) {
fetchPost("/api/outline/getDocOutline", {
id: this.blockId,
preview: this.isPreview
}, response => {
this.update(response);
// https://github.com/siyuan-note/siyuan/issues/8372

View file

@ -71,6 +71,7 @@ export class MobileOutline {
}
fetchPost("/api/outline/getDocOutline", {
id: window.siyuan.mobile.editor.protyle.block.rootID,
preview: !window.siyuan.mobile.editor.protyle.preview.element.classList.contains("fn__none")
}, response => {
let currentId;
let currentElement = this.element.querySelector(".b3-list-item--focus");

View file

@ -10,7 +10,7 @@ import {getSearch, isMobile} from "../../util/functions";
import {shell} from "electron";
/// #endif
/// #if !MOBILE
import {openAsset, openBy} from "../../editor/util";
import {openAsset, openBy, updateOutline} from "../../editor/util";
import {getAllModels} from "../../layout/getAll";
/// #endif
import {fetchPost} from "../../util/fetch";
@ -164,7 +164,7 @@ export class Preview {
this.previewElement = previewElement;
}
public render(protyle: IProtyle, cb?: (outlineData: IBlockTree[]) => void) {
public render(protyle: IProtyle) {
if (this.element.style.display === "none") {
return;
}
@ -191,21 +191,8 @@ export class Preview {
avRender(protyle.preview.previewElement, protyle);
speechRender(protyle.preview.previewElement, protyle.options.lang);
protyle.preview.previewElement.scrollTop = oldScrollTop;
/// #if MOBILE
if (cb) {
cb(response.data.outline);
}
/// #else
response.data = response.data.outline;
getAllModels().outline.forEach(item => {
if (item.type === "pin" || (item.type === "local" && item.blockId === protyle.block.rootID)) {
item.isPreview = true;
item.update(response, protyle.block.rootID);
if (item.type === "pin") {
item.updateDocTitle(protyle.background.ial);
}
}
});
/// #if !MOBILE
updateOutline(getAllModels(), protyle);
/// #endif
loadingElement.remove();
});