mirror of
https://github.com/siyuan-note/siyuan.git
synced 2025-12-17 23:20:13 +01:00
🎨 add isPreview
This commit is contained in:
parent
9b6fe676ab
commit
1a7110de1a
5 changed files with 40 additions and 9 deletions
|
|
@ -1,7 +1,7 @@
|
||||||
import {Tab} from "../Tab";
|
import {Tab} from "../Tab";
|
||||||
import {Model} from "../Model";
|
import {Model} from "../Model";
|
||||||
import {Tree} from "../../util/Tree";
|
import {Tree} from "../../util/Tree";
|
||||||
import {getDockByType, setPanelFocus} from "../util";
|
import {getDockByType, getInstanceById, setPanelFocus} from "../util";
|
||||||
import {fetchPost} from "../../util/fetch";
|
import {fetchPost} from "../../util/fetch";
|
||||||
import {getAllModels} from "../getAll";
|
import {getAllModels} from "../getAll";
|
||||||
import {hasClosestBlock, hasClosestByClassName, hasTopClosestByClassName} from "../../protyle/util/hasClosest";
|
import {hasClosestBlock, hasClosestByClassName, hasTopClosestByClassName} from "../../protyle/util/hasClosest";
|
||||||
|
|
@ -27,7 +27,8 @@ export class Outline extends Model {
|
||||||
app: App,
|
app: App,
|
||||||
tab: Tab,
|
tab: Tab,
|
||||||
blockId: string,
|
blockId: string,
|
||||||
type: "pin" | "local"
|
type: "pin" | "local",
|
||||||
|
isPreview: boolean
|
||||||
}) {
|
}) {
|
||||||
super({
|
super({
|
||||||
app: options.app,
|
app: options.app,
|
||||||
|
|
@ -75,6 +76,7 @@ export class Outline extends Model {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
this.isPreview = options.isPreview;
|
||||||
this.blockId = options.blockId;
|
this.blockId = options.blockId;
|
||||||
this.type = options.type;
|
this.type = options.type;
|
||||||
options.tab.panelElement.classList.add("fn__flex-column", "file-tree", "sy__outline");
|
options.tab.panelElement.classList.add("fn__flex-column", "file-tree", "sy__outline");
|
||||||
|
|
@ -104,7 +106,21 @@ export class Outline extends Model {
|
||||||
click: (element: HTMLElement) => {
|
click: (element: HTMLElement) => {
|
||||||
const id = element.getAttribute("data-node-id");
|
const id = element.getAttribute("data-node-id");
|
||||||
if (this.isPreview) {
|
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 {
|
} else {
|
||||||
fetchPost("/api/attr/getBlockAttrs", {id}, (attrResponse) => {
|
fetchPost("/api/attr/getBlockAttrs", {id}, (attrResponse) => {
|
||||||
openFileById({
|
openFileById({
|
||||||
|
|
@ -177,11 +193,20 @@ export class Outline extends Model {
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
fetchPost("/api/outline/getDocOutline", {
|
if (this.isPreview) {
|
||||||
id: this.blockId,
|
fetchPost("/api/export/preview", {
|
||||||
}, response => {
|
id: this.blockId,
|
||||||
this.update(response);
|
}, 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) {
|
public updateDocTitle(ial?: IObject) {
|
||||||
|
|
|
||||||
|
|
@ -376,6 +376,7 @@ export class Dock {
|
||||||
type: "pin",
|
type: "pin",
|
||||||
tab,
|
tab,
|
||||||
blockId: editor?.protyle?.block?.rootID,
|
blockId: editor?.protyle?.block?.rootID,
|
||||||
|
isPreview: !editor?.protyle?.preview?.element.classList.contains("fn__none")
|
||||||
});
|
});
|
||||||
if (editor?.protyle?.title?.editElement) {
|
if (editor?.protyle?.title?.editElement) {
|
||||||
outline.updateDocTitle(editor.protyle?.background?.ial);
|
outline.updateDocTitle(editor.protyle?.background?.ial);
|
||||||
|
|
|
||||||
|
|
@ -80,6 +80,7 @@ export const openOutline = (protyle: IProtyle) => {
|
||||||
type: "local",
|
type: "local",
|
||||||
tab,
|
tab,
|
||||||
blockId: protyle.block.rootID,
|
blockId: protyle.block.rootID,
|
||||||
|
isPreview: !protyle.preview.element.classList.contains("fn__none")
|
||||||
}));
|
}));
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
|
||||||
|
|
@ -366,6 +366,7 @@ export const JSONToCenter = (app: App, json: ILayoutJSON, layout?: Layout | Wnd
|
||||||
tab: (layout as Tab),
|
tab: (layout as Tab),
|
||||||
blockId: json.blockId,
|
blockId: json.blockId,
|
||||||
type: json.type as "pin" | "local",
|
type: json.type as "pin" | "local",
|
||||||
|
isPreview: json.isPreview,
|
||||||
}));
|
}));
|
||||||
} else if (json.instance === "Tag") {
|
} else if (json.instance === "Tag") {
|
||||||
(layout as Tab).addModel(new Tag(app, (layout as Tab)));
|
(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) {
|
} else if (layout instanceof Outline) {
|
||||||
json.blockId = layout.blockId;
|
json.blockId = layout.blockId;
|
||||||
json.type = layout.type;
|
json.type = layout.type;
|
||||||
|
json.isPreview = layout.isPreview;
|
||||||
json.instance = "Outline";
|
json.instance = "Outline";
|
||||||
} else if (layout instanceof Tag) {
|
} else if (layout instanceof Tag) {
|
||||||
json.instance = "Tag";
|
json.instance = "Tag";
|
||||||
|
|
@ -710,7 +712,8 @@ export const copyTab = (app: App, tab: Tab) => {
|
||||||
app,
|
app,
|
||||||
tab: newTab,
|
tab: newTab,
|
||||||
blockId: tab.model.blockId,
|
blockId: tab.model.blockId,
|
||||||
type: tab.model.type
|
type: tab.model.type,
|
||||||
|
isPreview: tab.model.isPreview
|
||||||
});
|
});
|
||||||
} else if (tab.model instanceof Backlink) {
|
} else if (tab.model instanceof Backlink) {
|
||||||
model = new Backlink({
|
model = new Backlink({
|
||||||
|
|
|
||||||
1
app/src/types/index.d.ts
vendored
1
app/src/types/index.d.ts
vendored
|
|
@ -308,6 +308,7 @@ interface ILayoutJSON extends ILayoutOptions {
|
||||||
rootId?: string
|
rootId?: string
|
||||||
active?: boolean
|
active?: boolean
|
||||||
pin?: boolean
|
pin?: boolean
|
||||||
|
isPreview?: boolean
|
||||||
customModelData?: any
|
customModelData?: any
|
||||||
customModelType?: string
|
customModelType?: string
|
||||||
config?: ISearchOption
|
config?: ISearchOption
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue