🎨 add isPreview

This commit is contained in:
Vanessa 2023-06-18 22:40:44 +08:00
parent 9b6fe676ab
commit 1a7110de1a
5 changed files with 40 additions and 9 deletions

View file

@ -1,7 +1,7 @@
import {Tab} from "../Tab";
import {Model} from "../Model";
import {Tree} from "../../util/Tree";
import {getDockByType, setPanelFocus} from "../util";
import {getDockByType, getInstanceById, setPanelFocus} from "../util";
import {fetchPost} from "../../util/fetch";
import {getAllModels} from "../getAll";
import {hasClosestBlock, hasClosestByClassName, hasTopClosestByClassName} from "../../protyle/util/hasClosest";
@ -27,7 +27,8 @@ export class Outline extends Model {
app: App,
tab: Tab,
blockId: string,
type: "pin" | "local"
type: "pin" | "local",
isPreview: boolean
}) {
super({
app: options.app,
@ -75,6 +76,7 @@ export class Outline extends Model {
}
}
});
this.isPreview = options.isPreview;
this.blockId = options.blockId;
this.type = options.type;
options.tab.panelElement.classList.add("fn__flex-column", "file-tree", "sy__outline");
@ -104,7 +106,21 @@ export class Outline extends Model {
click: (element: HTMLElement) => {
const id = element.getAttribute("data-node-id");
if (this.isPreview) {
document.getElementById(id)?.scrollIntoView()
const headElement = document.getElementById(id)
if (headElement) {
const tabElement = hasTopClosestByClassName(headElement, "protyle")
if (tabElement) {
const tab = getInstanceById(tabElement.getAttribute("data-id")) as Tab
tab.parent.switchTab(tab.headElement)
}
headElement.scrollIntoView();
} else {
openFileById({
app: options.app,
id: this.blockId,
mode: "preview",
});
}
} else {
fetchPost("/api/attr/getBlockAttrs", {id}, (attrResponse) => {
openFileById({
@ -177,11 +193,20 @@ export class Outline extends Model {
}
});
fetchPost("/api/outline/getDocOutline", {
id: this.blockId,
}, response => {
this.update(response);
});
if (this.isPreview) {
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);
});
}
}
public updateDocTitle(ial?: IObject) {

View file

@ -376,6 +376,7 @@ export class Dock {
type: "pin",
tab,
blockId: editor?.protyle?.block?.rootID,
isPreview: !editor?.protyle?.preview?.element.classList.contains("fn__none")
});
if (editor?.protyle?.title?.editElement) {
outline.updateDocTitle(editor.protyle?.background?.ial);

View file

@ -80,6 +80,7 @@ export const openOutline = (protyle: IProtyle) => {
type: "local",
tab,
blockId: protyle.block.rootID,
isPreview: !protyle.preview.element.classList.contains("fn__none")
}));
}
});

View file

@ -366,6 +366,7 @@ export const JSONToCenter = (app: App, json: ILayoutJSON, layout?: Layout | Wnd
tab: (layout as Tab),
blockId: json.blockId,
type: json.type as "pin" | "local",
isPreview: json.isPreview,
}));
} else if (json.instance === "Tag") {
(layout as Tab).addModel(new Tag(app, (layout as Tab)));
@ -522,6 +523,7 @@ export const layoutToJSON = (layout: Layout | Wnd | Tab | Model, json: any, drop
} else if (layout instanceof Outline) {
json.blockId = layout.blockId;
json.type = layout.type;
json.isPreview = layout.isPreview;
json.instance = "Outline";
} else if (layout instanceof Tag) {
json.instance = "Tag";
@ -710,7 +712,8 @@ export const copyTab = (app: App, tab: Tab) => {
app,
tab: newTab,
blockId: tab.model.blockId,
type: tab.model.type
type: tab.model.type,
isPreview: tab.model.isPreview
});
} else if (tab.model instanceof Backlink) {
model = new Backlink({

View file

@ -308,6 +308,7 @@ interface ILayoutJSON extends ILayoutOptions {
rootId?: string
active?: boolean
pin?: boolean
isPreview?: boolean
customModelData?: any
customModelType?: string
config?: ISearchOption