2025-09-08 14:50:06 +00:00
|
|
|
import { ItemView, WorkspaceLeaf } from 'obsidian';
|
|
|
|
|
import { mount, unmount } from 'svelte';
|
2025-09-16 16:14:37 +00:00
|
|
|
import ChatWindow from 'Components/ChatWindow.svelte';
|
2025-10-02 08:34:54 +00:00
|
|
|
import TopBar from 'Components/TopBar.svelte';
|
2025-10-17 23:44:15 +00:00
|
|
|
import type { StatusBarService } from 'Services/StatusBarService';
|
|
|
|
|
import { Resolve } from 'Services/DependencyService';
|
|
|
|
|
import { Services } from 'Services/Services';
|
2025-09-08 14:50:06 +00:00
|
|
|
|
|
|
|
|
export const VIEW_TYPE_MAIN = 'main-view';
|
|
|
|
|
|
|
|
|
|
export class MainView extends ItemView {
|
2025-10-17 23:44:15 +00:00
|
|
|
|
|
|
|
|
private statusBarService: StatusBarService = Resolve<StatusBarService>(Services.StatusBarService);
|
|
|
|
|
|
2025-09-08 14:50:06 +00:00
|
|
|
constructor(leaf: WorkspaceLeaf) {
|
|
|
|
|
super(leaf);
|
|
|
|
|
}
|
|
|
|
|
|
2025-10-02 08:34:54 +00:00
|
|
|
topBar: ReturnType<typeof TopBar> | undefined;
|
2025-09-16 16:14:37 +00:00
|
|
|
input: ReturnType<typeof ChatWindow> | undefined;
|
2025-09-08 14:50:06 +00:00
|
|
|
|
|
|
|
|
getViewType() {
|
|
|
|
|
return VIEW_TYPE_MAIN;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
getDisplayText() {
|
2025-10-17 22:51:23 +00:00
|
|
|
return "AI Agent";
|
2025-09-08 14:50:06 +00:00
|
|
|
}
|
|
|
|
|
|
2025-10-17 23:44:15 +00:00
|
|
|
getIcon(): string {
|
|
|
|
|
return 'sparkles';
|
|
|
|
|
}
|
|
|
|
|
|
2025-09-08 14:50:06 +00:00
|
|
|
async onOpen() {
|
|
|
|
|
const container = this.contentEl;
|
|
|
|
|
container.empty();
|
2025-10-02 08:34:54 +00:00
|
|
|
|
2025-10-09 20:34:40 +00:00
|
|
|
// Mount TopBar with reference to ChatWindow's focus function
|
2025-10-02 08:34:54 +00:00
|
|
|
this.topBar = mount(TopBar, {
|
|
|
|
|
target: container,
|
2025-10-02 21:56:22 +00:00
|
|
|
props: {
|
2025-10-09 20:34:40 +00:00
|
|
|
leaf: this.leaf,
|
2025-10-24 16:25:19 +00:00
|
|
|
onNewConversation: () => {
|
|
|
|
|
this.input?.resetChatArea();
|
|
|
|
|
this.input?.focusInput();
|
|
|
|
|
}
|
2025-10-02 21:56:22 +00:00
|
|
|
}
|
2025-10-02 08:34:54 +00:00
|
|
|
});
|
|
|
|
|
|
2025-10-09 20:34:40 +00:00
|
|
|
// Mount ChatWindow first
|
2025-09-16 16:14:37 +00:00
|
|
|
this.input = mount(ChatWindow, {
|
2025-09-08 14:50:06 +00:00
|
|
|
target: container,
|
2025-09-16 16:14:37 +00:00
|
|
|
props: {}
|
2025-09-08 14:50:06 +00:00
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
async onClose() {
|
2025-10-02 08:34:54 +00:00
|
|
|
if (this.topBar) {
|
|
|
|
|
unmount(this.topBar);
|
|
|
|
|
}
|
2025-09-08 14:50:06 +00:00
|
|
|
if (this.input) {
|
|
|
|
|
unmount(this.input);
|
|
|
|
|
}
|
2025-10-17 23:44:15 +00:00
|
|
|
this.statusBarService.removeStatusBarMessage();
|
2025-09-08 14:50:06 +00:00
|
|
|
}
|
|
|
|
|
}
|