mirror of
https://github.com/siyuan-note/siyuan.git
synced 2025-12-29 21:08:49 +01:00
This commit is contained in:
parent
05cd94bc12
commit
9eaf181379
4 changed files with 48 additions and 13 deletions
|
|
@ -547,12 +547,17 @@ export const updateOutline = (models: IModels, protyle: IProtyle, reload = false
|
|||
if (blockId === item.blockId && !reload) {
|
||||
return;
|
||||
}
|
||||
if (protyle && !protyle.preview.element.classList.contains("fn__none")) {
|
||||
protyle.preview.render(protyle);
|
||||
return;
|
||||
}
|
||||
fetchPost("/api/outline/getDocOutline", {
|
||||
id: blockId,
|
||||
}, response => {
|
||||
if (!isCurrentEditor(blockId) || item.blockId === blockId) {
|
||||
if (!reload && (!isCurrentEditor(blockId) || item.blockId === blockId)) {
|
||||
return;
|
||||
}
|
||||
item.isPreview = false;
|
||||
item.update(response, blockId);
|
||||
if (protyle) {
|
||||
item.updateDocTitle(protyle.background.ial);
|
||||
|
|
@ -569,7 +574,6 @@ export const updateOutline = (models: IModels, protyle: IProtyle, reload = false
|
|||
item.updateDocTitle();
|
||||
}
|
||||
});
|
||||
return;
|
||||
}
|
||||
});
|
||||
};
|
||||
|
|
|
|||
|
|
@ -20,6 +20,7 @@ export class Outline extends Model {
|
|||
public headerElement: HTMLElement;
|
||||
public type: "pin" | "local";
|
||||
public blockId: string;
|
||||
public isPreview: boolean;
|
||||
private openNodes: { [key: string]: string[] } = {};
|
||||
|
||||
constructor(options: {
|
||||
|
|
@ -102,6 +103,9 @@ export class Outline extends Model {
|
|||
data: null,
|
||||
click: (element: HTMLElement) => {
|
||||
const id = element.getAttribute("data-node-id");
|
||||
if (this.isPreview) {
|
||||
document.getElementById(id)?.scrollIntoView()
|
||||
} else {
|
||||
fetchPost("/api/attr/getBlockAttrs", {id}, (attrResponse) => {
|
||||
openFileById({
|
||||
app: options.app,
|
||||
|
|
@ -110,6 +114,7 @@ export class Outline extends Model {
|
|||
});
|
||||
});
|
||||
}
|
||||
}
|
||||
});
|
||||
// 为了快捷键的 dispatch
|
||||
options.tab.panelElement.querySelector('[data-type="collapse"]').addEventListener("click", () => {
|
||||
|
|
@ -200,6 +205,9 @@ export class Outline extends Model {
|
|||
}
|
||||
|
||||
private onTransaction(data: IWebSocketData) {
|
||||
if (this.isPreview) {
|
||||
return;
|
||||
}
|
||||
let needReload = false;
|
||||
data.data[0].doOperations.forEach((item: IOperation) => {
|
||||
if ((item.action === "update" || item.action === "insert") &&
|
||||
|
|
@ -286,19 +294,26 @@ export class Outline extends Model {
|
|||
currentId = currentElement.getAttribute("data-node-id");
|
||||
}
|
||||
|
||||
if (this.openNodes[this.blockId]) {
|
||||
if (!this.isPreview && this.openNodes[this.blockId]) {
|
||||
this.openNodes[this.blockId] = this.tree.getExpandIds();
|
||||
}
|
||||
if (typeof callbackId !== "undefined") {
|
||||
this.blockId = callbackId;
|
||||
}
|
||||
this.tree.updateData(data.data);
|
||||
if (this.openNodes[this.blockId] && !this.headerElement.querySelector('[data-type="expand"]').classList.contains("block__icon--active")) {
|
||||
if (!this.isPreview && this.openNodes[this.blockId] && !this.headerElement.querySelector('[data-type="expand"]').classList.contains("block__icon--active")) {
|
||||
this.tree.setExpandIds(this.openNodes[this.blockId]);
|
||||
} else {
|
||||
this.tree.expandAll();
|
||||
if (!this.isPreview) {
|
||||
this.openNodes[this.blockId] = this.tree.getExpandIds();
|
||||
}
|
||||
}
|
||||
if (this.isPreview) {
|
||||
this.tree.element.querySelectorAll(".popover__block").forEach(item => {
|
||||
item.classList.remove("popover__block");
|
||||
})
|
||||
}
|
||||
|
||||
if (currentId) {
|
||||
currentElement = this.element.querySelector(`[data-node-id="${currentId}"]`);
|
||||
|
|
|
|||
|
|
@ -1,5 +1,4 @@
|
|||
import {getEventName, openByMobile, writeText} from "../util/compatibility";
|
||||
import {hasClosestByTag} from "../util/hasClosest";
|
||||
import {openByMobile, writeText} from "../util/compatibility";
|
||||
import {focusByRange} from "../util/selection";
|
||||
import {showMessage} from "../../dialog/message";
|
||||
import {isLocalPath, pathPosix} from "../../util/pathName";
|
||||
|
|
@ -19,6 +18,7 @@ import {highlightRender} from "../render/highlightRender";
|
|||
import {speechRender} from "../render/speechRender";
|
||||
import {avRender} from "../render/av/render";
|
||||
import {setPanelFocus} from "../../layout/util";
|
||||
import {getAllModels} from "../../layout/getAll";
|
||||
|
||||
export class Preview {
|
||||
public element: HTMLElement;
|
||||
|
|
@ -159,11 +159,24 @@ export class Preview {
|
|||
fetchPost("/api/export/preview", {
|
||||
id: protyle.block.parentID || protyle.options.blockId,
|
||||
}, response => {
|
||||
const oldScrollTop = protyle.preview.previewElement.scrollTop;
|
||||
protyle.preview.previewElement.innerHTML = response.data.html;
|
||||
processRender(protyle.preview.previewElement);
|
||||
highlightRender(protyle.preview.previewElement);
|
||||
avRender(protyle.preview.previewElement);
|
||||
speechRender(protyle.preview.previewElement, protyle.options.lang);
|
||||
protyle.preview.previewElement.scrollTop = oldScrollTop;
|
||||
getAllModels().outline.find(item => {
|
||||
if (item.type === "pin" || (item.type === "local" && item.blockId === protyle.block.rootID)) {
|
||||
response.data = response.data.outline;
|
||||
item.isPreview = true;
|
||||
item.update(response, protyle.block.rootID);
|
||||
if (item.type === "pin") {
|
||||
item.updateDocTitle(protyle.background.ial);
|
||||
}
|
||||
return;
|
||||
}
|
||||
});
|
||||
});
|
||||
}, protyle.options.preview.delay);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,5 +1,7 @@
|
|||
import {setPadding} from "../ui/initUI";
|
||||
import {hideElements} from "../ui/hideElements";
|
||||
import {getAllModels} from "../../layout/getAll";
|
||||
import {updateOutline} from "../../editor/util";
|
||||
|
||||
export const setEditMode = (protyle: IProtyle, type: TEditorMode) => {
|
||||
if (type === "preview") {
|
||||
|
|
@ -29,6 +31,7 @@ export const setEditMode = (protyle: IProtyle, type: TEditorMode) => {
|
|||
protyle.breadcrumb?.element.classList.remove("fn__none");
|
||||
protyle.breadcrumb.toggleExit(!protyle.block.showAll);
|
||||
}
|
||||
updateOutline(getAllModels(), protyle, true);
|
||||
}
|
||||
hideElements(["gutter", "toolbar", "select", "hint", "util"], protyle);
|
||||
};
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue