-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathmain.tsx
More file actions
59 lines (48 loc) · 1.13 KB
/
Copy pathmain.tsx
File metadata and controls
59 lines (48 loc) · 1.13 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
import { StrictMode } from 'react';
import { Root, createRoot } from 'react-dom/client';
import { PeriodicTable } from 'src/PeriodicTable';
import {Plugin, ItemView, WorkspaceLeaf} from 'obsidian';
export const PERIODIC_VIEW = "periodic-view";
export default class MyPlugin extends Plugin{
onload(){
const infoView = this.app.workspace.getLeavesOfType(PERIODIC_VIEW)[0];
if(!infoView){
this.registerView(
PERIODIC_VIEW,
(leaf) => new PeriodicView(leaf)
);
}
this.activateView();
}
onunload(){
}
async activateView(){
await this.app.workspace.getRightLeaf(false).setViewState({
type: PERIODIC_VIEW,
active: false
});
}
}
export class PeriodicView extends ItemView{
root: Root | null = null;
constructor(leaf: WorkspaceLeaf) {
super(leaf);
}
getViewType() {
return PERIODIC_VIEW;
}
getDisplayText() {
return "Periodic table";
}
async onOpen() {
this.root = createRoot(this.containerEl.children[1]);
this.root.render(
<StrictMode>
<PeriodicTable />
</StrictMode>
);
}
async onClose() {
this.root?.unmount();
}
}