Skip to content

Commit

Permalink
test commit
Browse files Browse the repository at this point in the history
  • Loading branch information
Hananoshika Yomaru committed Oct 11, 2023
1 parent 11a9937 commit 71d695d
Show file tree
Hide file tree
Showing 8 changed files with 3,751 additions and 70 deletions.
4 changes: 4 additions & 0 deletions .husky/pre-push
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#!/usr/bin/env sh
. "$(dirname -- "$0")/_/husky.sh"

bun tsc -noEmit -skipLibCheck
2 changes: 2 additions & 0 deletions bun-fix.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
/// <reference lib="dom" />
/// <reference lib="dom.iterable" />
Binary file added bun.lockb
Binary file not shown.
12 changes: 6 additions & 6 deletions esbuild.config.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,19 @@ import esbuild from "esbuild";
import process from "process";
import builtins from "builtin-modules";

const banner =
`/*
const banner = `/*
THIS IS A GENERATED/BUNDLED FILE BY ESBUILD
if you want to view the source, please visit the github repository of this plugin
*/
`;

const prod = (process.argv[2] === "production");
const prod = process.argv[2] === "production";

const context = await esbuild.context({
banner: {
js: banner,
},
entryPoints: ["main.ts"],
entryPoints: ["src/main.ts"],
bundle: true,
external: [
"obsidian",
Expand All @@ -31,7 +30,8 @@ const context = await esbuild.context({
"@lezer/common",
"@lezer/highlight",
"@lezer/lr",
...builtins],
...builtins,
],
format: "cjs",
target: "es2018",
logLevel: "info",
Expand All @@ -45,4 +45,4 @@ if (prod) {
process.exit(0);
} else {
await context.watch();
}
}
7 changes: 5 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,9 @@
"main": "main.js",
"scripts": {
"dev": "node esbuild.config.mjs",
"build": "tsc -noEmit -skipLibCheck && node esbuild.config.mjs production",
"version": "node version-bump.mjs && git add manifest.json versions.json"
"build": "node esbuild.config.mjs production",
"version": "node version-bump.mjs && git add manifest.json versions.json",
"prepare": "husky install"
},
"keywords": [],
"author": "",
Expand All @@ -16,7 +17,9 @@
"@typescript-eslint/eslint-plugin": "5.29.0",
"@typescript-eslint/parser": "5.29.0",
"builtin-modules": "3.3.0",
"bun-types": "^1.0.5-canary.20231009T140142",
"esbuild": "0.17.3",
"husky": "^8.0.3",
"obsidian": "latest",
"tslib": "2.4.0",
"typescript": "4.7.4"
Expand Down
100 changes: 60 additions & 40 deletions main.ts → src/main.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,13 @@
import { App, Editor, MarkdownView, Modal, Notice, Plugin, PluginSettingTab, Setting } from 'obsidian';
import {
App,
Editor,
MarkdownView,
Modal,
Notice,
Plugin,
PluginSettingTab,
Setting,
} from "obsidian";

// Remember to rename these classes and interfaces!

Expand All @@ -7,8 +16,8 @@ interface MyPluginSettings {
}

const DEFAULT_SETTINGS: MyPluginSettings = {
mySetting: 'default'
}
mySetting: "default",
};

export default class MyPlugin extends Plugin {
settings: MyPluginSettings;
Expand All @@ -17,41 +26,46 @@ export default class MyPlugin extends Plugin {
await this.loadSettings();

// This creates an icon in the left ribbon.
const ribbonIconEl = this.addRibbonIcon('dice', 'Sample Plugin', (evt: MouseEvent) => {
// Called when the user clicks the icon.
new Notice('This is a notice!');
});
const ribbonIconEl = this.addRibbonIcon(
"dice",
"Sample Plugin",
(evt: MouseEvent) => {
// Called when the user clicks the icon.
new Notice("This is a notice!");
}
);
// Perform additional things with the ribbon
ribbonIconEl.addClass('my-plugin-ribbon-class');
ribbonIconEl.addClass("my-plugin-ribbon-class");

// This adds a status bar item to the bottom of the app. Does not work on mobile apps.
const statusBarItemEl = this.addStatusBarItem();
statusBarItemEl.setText('Status Bar Text');
statusBarItemEl.setText("Status Bar Text");

// This adds a simple command that can be triggered anywhere
this.addCommand({
id: 'open-sample-modal-simple',
name: 'Open sample modal (simple)',
id: "open-sample-modal-simple",
name: "Open sample modal (simple)",
callback: () => {
new SampleModal(this.app).open();
}
},
});
// This adds an editor command that can perform some operation on the current editor instance
this.addCommand({
id: 'sample-editor-command',
name: 'Sample editor command',
id: "sample-editor-command",
name: "Sample editor command",
editorCallback: (editor: Editor, view: MarkdownView) => {
console.log(editor.getSelection());
editor.replaceSelection('Sample Editor Command');
}
editor.replaceSelection("Sample Editor Command");
},
});
// This adds a complex command that can check whether the current state of the app allows execution of the command
this.addCommand({
id: 'open-sample-modal-complex',
name: 'Open sample modal (complex)',
id: "open-sample-modal-complex",
name: "Open sample modal (complex)",
checkCallback: (checking: boolean) => {
// Conditions to check
const markdownView = this.app.workspace.getActiveViewOfType(MarkdownView);
const markdownView =
this.app.workspace.getActiveViewOfType(MarkdownView);
if (markdownView) {
// If checking is true, we're simply "checking" if the command can be run.
// If checking is false, then we want to actually perform the operation.
Expand All @@ -62,28 +76,32 @@ export default class MyPlugin extends Plugin {
// This command will only show up in Command Palette when the check function returns true
return true;
}
}
},
});

// This adds a settings tab so the user can configure various aspects of the plugin
this.addSettingTab(new SampleSettingTab(this.app, this));

// If the plugin hooks up any global DOM events (on parts of the app that doesn't belong to this plugin)
// Using this function will automatically remove the event listener when this plugin is disabled.
this.registerDomEvent(document, 'click', (evt: MouseEvent) => {
console.log('click', evt);
this.registerDomEvent(document, "click", (evt: MouseEvent) => {
console.log("click", evt);
});

// When registering intervals, this function will automatically clear the interval when the plugin is disabled.
this.registerInterval(window.setInterval(() => console.log('setInterval'), 5 * 60 * 1000));
this.registerInterval(
window.setInterval(() => console.log("setInterval"), 5 * 60 * 1000)
);
}

onunload() {

}
onunload() {}

async loadSettings() {
this.settings = Object.assign({}, DEFAULT_SETTINGS, await this.loadData());
this.settings = Object.assign(
{},
DEFAULT_SETTINGS,
await this.loadData()
);
}

async saveSettings() {
Expand All @@ -97,12 +115,12 @@ class SampleModal extends Modal {
}

onOpen() {
const {contentEl} = this;
contentEl.setText('Woah!');
const { contentEl } = this;
contentEl.setText("Woah!");
}

onClose() {
const {contentEl} = this;
const { contentEl } = this;
contentEl.empty();
}
}
Expand All @@ -116,19 +134,21 @@ class SampleSettingTab extends PluginSettingTab {
}

display(): void {
const {containerEl} = this;
const { containerEl } = this;

containerEl.empty();

new Setting(containerEl)
.setName('Setting #1')
.setDesc('It\'s a secret')
.addText(text => text
.setPlaceholder('Enter your secret')
.setValue(this.plugin.settings.mySetting)
.onChange(async (value) => {
this.plugin.settings.mySetting = value;
await this.plugin.saveSettings();
}));
.setName("Setting #1")
.setDesc("It's a secret")
.addText((text) =>
text
.setPlaceholder("Enter your secret")
.setValue(this.plugin.settings.mySetting)
.onChange(async (value) => {
this.plugin.settings.mySetting = value;
await this.plugin.saveSettings();
})
);
}
}
Loading

0 comments on commit 71d695d

Please sign in to comment.