mirror of
https://github.com/zsviczian/obsidian-excalidraw-plugin.git
synced 2025-08-06 05:46:28 +00:00
inner content
This commit is contained in:
@@ -1,9 +1,9 @@
|
||||
import typescript from '@rollup/plugin-typescript';
|
||||
import {nodeResolve} from '@rollup/plugin-node-resolve';
|
||||
import { nodeResolve } from '@rollup/plugin-node-resolve';
|
||||
import commonjs from '@rollup/plugin-commonjs';
|
||||
|
||||
export default {
|
||||
input: 'main.ts',
|
||||
input: 'src/main.ts',
|
||||
output: {
|
||||
dir: '.',
|
||||
sourcemap: 'inline',
|
||||
@@ -13,7 +13,7 @@ export default {
|
||||
external: ['obsidian'],
|
||||
plugins: [
|
||||
typescript(),
|
||||
nodeResolve({browser: true}),
|
||||
nodeResolve({ browser: true }),
|
||||
commonjs(),
|
||||
]
|
||||
};
|
||||
1
src/constants.ts
Normal file
1
src/constants.ts
Normal file
@@ -0,0 +1 @@
|
||||
export const VIEW_TYPE_STATS_TRACKER = "stats-tracker";
|
||||
@@ -1,4 +1,6 @@
|
||||
import { TFile, Plugin, MarkdownView, debounce, Debouncer } from 'obsidian';
|
||||
import { TFile, Plugin, MarkdownView, debounce, Debouncer, WorkspaceLeaf } from 'obsidian';
|
||||
import { VIEW_TYPE_STATS_TRACKER } from './constants';
|
||||
import StatsTrackerView from './view';
|
||||
|
||||
interface WordCount {
|
||||
initial: number;
|
||||
@@ -22,6 +24,8 @@ export default class DailyStats extends Plugin {
|
||||
today: string;
|
||||
debouncedUpdate: Debouncer<[contents: string, filepath: string]>;
|
||||
|
||||
private view: StatsTrackerView;
|
||||
|
||||
async onload() {
|
||||
await this.loadSettings();
|
||||
|
||||
@@ -37,6 +41,24 @@ export default class DailyStats extends Plugin {
|
||||
this.updateWordCount(contents, filepath);
|
||||
}, 400, false);
|
||||
|
||||
this.registerView(
|
||||
VIEW_TYPE_STATS_TRACKER,
|
||||
(leaf: WorkspaceLeaf) => (this.view = new StatsTrackerView(leaf))
|
||||
);
|
||||
|
||||
this.addCommand({
|
||||
id: "show-daily-stats-tracker-view",
|
||||
name: "Open tracker view",
|
||||
checkCallback: (checking: boolean) => {
|
||||
if (checking) {
|
||||
return (
|
||||
this.app.workspace.getLeavesOfType(VIEW_TYPE_STATS_TRACKER).length === 0
|
||||
);
|
||||
}
|
||||
this.initLeaf();
|
||||
},
|
||||
});
|
||||
|
||||
this.registerEvent(
|
||||
this.app.workspace.on("quit", this.onunload.bind(this))
|
||||
);
|
||||
@@ -55,6 +77,23 @@ export default class DailyStats extends Plugin {
|
||||
this.updateDate();
|
||||
this.saveSettings();
|
||||
}, 1000));
|
||||
|
||||
if (this.app.workspace.layoutReady) {
|
||||
this.initLeaf();
|
||||
} else {
|
||||
this.registerEvent(
|
||||
this.app.workspace.on("layout-ready", this.initLeaf.bind(this))
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
initLeaf(): void {
|
||||
if (this.app.workspace.getLeavesOfType(VIEW_TYPE_STATS_TRACKER).length) {
|
||||
return;
|
||||
}
|
||||
this.app.workspace.getRightLeaf(false).setViewState({
|
||||
type: VIEW_TYPE_STATS_TRACKER,
|
||||
});
|
||||
}
|
||||
|
||||
async onunload() {
|
||||
26
src/view.ts
Normal file
26
src/view.ts
Normal file
@@ -0,0 +1,26 @@
|
||||
import { ItemView, WorkspaceLeaf } from "obsidian";
|
||||
import { VIEW_TYPE_STATS_TRACKER } from "./constants";
|
||||
|
||||
export default class StatsTrackerView extends ItemView {
|
||||
|
||||
constructor(leaf: WorkspaceLeaf) {
|
||||
super(leaf);
|
||||
}
|
||||
|
||||
getDisplayText() {
|
||||
return "Daily Stats";
|
||||
}
|
||||
|
||||
getIcon() {
|
||||
return "calendar-with-checkmark";
|
||||
}
|
||||
|
||||
getViewType() {
|
||||
return VIEW_TYPE_STATS_TRACKER;
|
||||
}
|
||||
|
||||
async onOpen() {
|
||||
var modal_content = '<div id="first">Inner content</div>';
|
||||
(this as any).contentEl.innerHTML = modal_content;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user