adiguno_hello-nemesis/CustomView.ts

60 lines
1.5 KiB
TypeScript
Raw Normal View History

import { ItemView, WorkspaceLeaf } from "obsidian";
// Each view is uniquely identified by a text string
// and several operations require that you specify the view you'd like to use.
// Extracting it to a constant, VIEW_TYPE_EXAMPLE, is a good idea—as you will see later in this guide.
2025-01-31 13:56:48 +00:00
import { Root, createRoot } from "react-dom/client";
import * as React from "react";
2025-02-01 08:57:33 +00:00
import { NemesisRightReactView } from "./NemesisRightReactView";
export const VIEW_TYPE_EXAMPLE = "example-view";
export class ExampleView extends ItemView {
2025-01-31 13:56:48 +00:00
root: Root | null = null;
2025-02-20 11:21:07 +00:00
content: string = "";
2025-01-31 15:03:54 +00:00
contents: string[] = [];
2025-01-31 13:56:48 +00:00
constructor(leaf: WorkspaceLeaf) {
super(leaf);
}
getViewType() {
return VIEW_TYPE_EXAMPLE;
}
getDisplayText() {
2025-02-20 11:21:07 +00:00
return "Nemesis Panel";
}
async onOpen() {
2025-01-31 13:56:48 +00:00
// const container = this.containerEl.children[1];
// container.empty();
// container.createEl("h4", { text: "Example view" });
this.root = createRoot(this.containerEl.children[1]);
// this.root.render(<div>asdf</div>);
// this.root.render(<ExampleReactView />);
2025-01-31 15:03:54 +00:00
this.root.render(
2025-02-20 11:21:07 +00:00
React.createElement(NemesisRightReactView, {
contents: this.contents,
})
);
}
async onClose() {
// Nothing to clean up.
2025-01-31 13:56:48 +00:00
this.root?.unmount();
}
2025-01-31 15:03:54 +00:00
updateContent(content: string) {
this.content = content;
2025-02-20 11:21:07 +00:00
this.contents = this.content.split("<section-done>");
2025-01-31 15:03:54 +00:00
// console.log(this.content)
// console.log(this.contents)
if (!this.root) return null;
this.root.render(
2025-02-01 08:57:33 +00:00
React.createElement(NemesisRightReactView, {
2025-02-20 11:21:07 +00:00
contents: this.contents,
2025-01-31 15:03:54 +00:00
})
);
2025-02-20 11:21:07 +00:00
}
}