2022-03-29 13:18:25 +02:00
|
|
|
import { ItemView, WorkspaceLeaf, Platform, Menu } from "obsidian";
|
2022-04-13 21:21:48 +02:00
|
|
|
import { CustomFrame } from "./frame";
|
|
|
|
import { CustomFrameSettings, CustomFramesSettings } from "./settings";
|
2022-03-29 13:18:25 +02:00
|
|
|
|
|
|
|
export class CustomFrameView extends ItemView {
|
|
|
|
|
2022-03-29 15:15:34 +02:00
|
|
|
private static readonly actions: Action[] = [
|
|
|
|
{
|
|
|
|
name: "Return to original page",
|
|
|
|
icon: "home",
|
2022-04-13 21:21:48 +02:00
|
|
|
action: v => v.frame.return()
|
2022-03-29 16:04:55 +02:00
|
|
|
}, {
|
2022-03-29 15:53:18 +02:00
|
|
|
name: "Open dev tools",
|
|
|
|
icon: "binary",
|
2022-04-13 21:21:48 +02:00
|
|
|
action: v => v.frame.toggleDevTools()
|
2022-03-29 16:04:55 +02:00
|
|
|
}, {
|
2022-03-29 15:53:18 +02:00
|
|
|
name: "Copy link",
|
|
|
|
icon: "link",
|
2022-04-13 21:21:48 +02:00
|
|
|
action: v => v.frame.copyLink()
|
2022-03-29 15:15:34 +02:00
|
|
|
}, {
|
|
|
|
name: "Refresh",
|
|
|
|
icon: "refresh-cw",
|
2022-04-13 21:21:48 +02:00
|
|
|
action: v => v.frame.refresh()
|
2022-03-29 15:15:34 +02:00
|
|
|
}, {
|
|
|
|
name: "Go back",
|
|
|
|
icon: "arrow-left",
|
2022-04-13 21:21:48 +02:00
|
|
|
action: v => v.frame.goBack()
|
2022-03-29 15:15:34 +02:00
|
|
|
}, {
|
|
|
|
name: "Go forward",
|
|
|
|
icon: "arrow-right",
|
2022-04-13 21:21:48 +02:00
|
|
|
action: v => v.frame.goForward()
|
2022-03-29 15:15:34 +02:00
|
|
|
}
|
|
|
|
];
|
|
|
|
|
2022-04-13 21:21:48 +02:00
|
|
|
private readonly data: CustomFrameSettings;
|
2022-03-29 13:18:25 +02:00
|
|
|
private readonly name: string;
|
2022-04-13 21:21:48 +02:00
|
|
|
private frame: CustomFrame;
|
2022-03-29 13:18:25 +02:00
|
|
|
|
2022-04-13 21:21:48 +02:00
|
|
|
constructor(leaf: WorkspaceLeaf, settings: CustomFramesSettings, data: CustomFrameSettings, name: string) {
|
2022-03-29 13:18:25 +02:00
|
|
|
super(leaf);
|
|
|
|
this.data = data;
|
|
|
|
this.name = name;
|
2022-04-13 21:59:39 +02:00
|
|
|
this.frame = new CustomFrame(settings, data);
|
2022-03-29 13:18:25 +02:00
|
|
|
|
2022-03-29 15:15:34 +02:00
|
|
|
for (let action of CustomFrameView.actions)
|
|
|
|
this.addAction(action.icon, action.name, () => action.action(this));
|
2022-03-29 13:18:25 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
onload(): void {
|
|
|
|
this.contentEl.empty();
|
|
|
|
this.contentEl.addClass("custom-frames-view");
|
2022-04-13 21:21:48 +02:00
|
|
|
this.contentEl.appendChild(this.frame.create());
|
2022-03-29 13:18:25 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
onHeaderMenu(menu: Menu): void {
|
|
|
|
super.onHeaderMenu(menu);
|
2022-03-29 15:15:34 +02:00
|
|
|
for (let action of CustomFrameView.actions) {
|
|
|
|
menu.addItem(i => {
|
|
|
|
i.setTitle(action.name);
|
|
|
|
i.setIcon(action.icon);
|
|
|
|
i.onClick(() => action.action(this));
|
|
|
|
});
|
|
|
|
}
|
2022-03-29 13:18:25 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
getViewType(): string {
|
|
|
|
return this.name;
|
|
|
|
}
|
|
|
|
|
|
|
|
getDisplayText(): string {
|
|
|
|
return this.data.displayName;
|
|
|
|
}
|
|
|
|
|
|
|
|
getIcon(): string {
|
|
|
|
return this.data.icon ? `lucide-${this.data.icon}` : "documents";
|
|
|
|
}
|
2022-03-29 15:15:34 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
interface Action {
|
|
|
|
name: string;
|
|
|
|
icon: string;
|
|
|
|
action: (view: CustomFrameView) => any;
|
2022-03-29 13:18:25 +02:00
|
|
|
}
|