-
-
Notifications
You must be signed in to change notification settings - Fork 17
/
TagFolderView.ts
73 lines (64 loc) · 2.16 KB
/
TagFolderView.ts
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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
import { WorkspaceLeaf, type ViewState } from "obsidian";
import TagFolderViewComponent from "./TagFolderViewComponent.svelte";
import { VIEW_TYPE_TAGFOLDER, type TREE_TYPE, VIEW_TYPE_TAGFOLDER_LINK } from "./types";
import TagFolderPlugin from "./main";
import { TagFolderViewBase } from "./TagFolderViewBase";
import { mount, unmount } from 'svelte'
export interface TagFolderViewState extends ViewState {
treeViewType: TREE_TYPE
}
export class TagFolderView extends TagFolderViewBase {
icon = "stacked-levels";
treeViewType?: TREE_TYPE;
getIcon(): string {
return "stacked-levels";
}
constructor(leaf: WorkspaceLeaf, plugin: TagFolderPlugin, viewType: TREE_TYPE) {
super(leaf);
this.plugin = plugin;
this.showMenu = this.showMenu.bind(this);
this.showOrder = this.showOrder.bind(this);
this.newNote = this.newNote.bind(this);
this.showLevelSelect = this.showLevelSelect.bind(this);
this.switchView = this.switchView.bind(this);
this.treeViewType = viewType;
// this.setState({ viewType: this.viewType, type: this.getViewType() }, {});
}
newNote(evt: MouseEvent) {
//@ts-ignore
this.app.commands.executeCommandById("file-explorer:new-file");
}
getViewType() {
return this.treeViewType == "tags" ? VIEW_TYPE_TAGFOLDER : VIEW_TYPE_TAGFOLDER_LINK;
}
getDisplayText() {
return this.treeViewType == "tags" ? "Tag Folder" : "Link Folder";
}
async onOpen() {
this.containerEl.empty();
const app = mount(TagFolderViewComponent,
{
target: this.containerEl,
props: {
openFile: this.plugin.focusFile,
hoverPreview: (a: MouseEvent, b: string) => this.plugin.hoverPreview(a, b),
vaultName: this.app.vault.getName(),
showMenu: this.showMenu,
showLevelSelect: this.showLevelSelect,
showOrder: this.showOrder,
newNote: this.newNote,
openScrollView: this.plugin.openScrollView,
isViewSwitchable: this.plugin.settings.useMultiPaneList,
switchView: this.switchView,
viewType: this.treeViewType,
saveSettings: this.saveSettings.bind(this),
},
});
this.component = app
return await Promise.resolve();
}
async onClose() {
unmount(this.component);
return await Promise.resolve();
}
}