mirror of
https://github.com/vrtmrz/obsidian-livesync.git
synced 2026-04-05 16:45:20 +00:00
29 lines
901 B
TypeScript
29 lines
901 B
TypeScript
import { ItemView } from "@/deps.ts";
|
|
import { type mount, unmount } from "svelte";
|
|
|
|
export abstract class SvelteItemView extends ItemView {
|
|
abstract instantiateComponent(target: HTMLElement): ReturnType<typeof mount> | Promise<ReturnType<typeof mount>>;
|
|
component?: ReturnType<typeof mount>;
|
|
override async onOpen() {
|
|
await super.onOpen();
|
|
this.contentEl.empty();
|
|
await this._dismountComponent();
|
|
this.component = await this.instantiateComponent(this.contentEl);
|
|
return;
|
|
}
|
|
async _dismountComponent() {
|
|
if (this.component) {
|
|
await unmount(this.component);
|
|
this.component = undefined;
|
|
}
|
|
}
|
|
override async onClose() {
|
|
await super.onClose();
|
|
if (this.component) {
|
|
await unmount(this.component);
|
|
this.component = undefined;
|
|
}
|
|
return;
|
|
}
|
|
}
|