Skip to content

Commit

Permalink
Initial commit!
Browse files Browse the repository at this point in the history
  • Loading branch information
lishid committed Oct 25, 2020
0 parents commit ed37707
Show file tree
Hide file tree
Showing 8 changed files with 1,627 additions and 0 deletions.
11 changes: 11 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# Intellij
*.iml
.idea

# npm
node_modules
package-lock.json

# build
main.js
*.js.map
35 changes: 35 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
### Obsidian Sample Plugin

This is a sample plugin for Obsidian (https://obsidian.md).

This project uses Typescript to provide type checking and documentation.
The repo contains the latest plugin API (obsidian.d.ts) in Typescript Definition format, which contains JSDoc comments describing what it does.

#### How to use

- Clone this repo.
- `npm i` or `yarn` to install dependencies
- `npm run dev` to start compilation in watch mode.

#### How to install the plugin

- Copy over `main.js`, `styles.css`, `manifest.json` to your vault `vault/.obsidian/plugins/plugin-id/`.

#### Plugin structure

`manifest.json`

- `id` the ID of your plugin.
- `name` the display name of your plugin.
- `description` the long description of your plugin.
- `isDesktopOnly` whether your plugin uses NodeJS or Electron APIs.
- `js` (optional) an alternative js entry point. Defaults to `main.js`
- `css` (optional) a css file that should be injected. Defaults to `styles.css`

`main.js`

- This is the main entry point of your plugin.
- Import any Obsidian API using `require('obsidian')`
- Import NodeJS or Electron API using `require('fs')` or `require('electron')`
- Must export a default class which extends `CustomPlugin`

77 changes: 77 additions & 0 deletions main.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
import { App, CustomPlugin, Modal, Notice, PluginSettingTab, Setting } from 'obsidian';

export default class MyPlugin extends CustomPlugin {
onInit() {

}

onload() {
console.log('loading plugin');

this.addRibbonIcon('dice', 'Sample Plugin', () => {
new Notice('This is a notice!');
});

this.addStatusBarItem().setText('Status Bar Text');

this.addCommand({
id: 'open-sample-modal',
name: 'Open Sample Modal',
// callback: () => {
// console.log('Simple Callback');
// },
checkCallback: (checking: boolean) => {
let leaf = this.app.workspace.activeLeaf;
if (leaf) {
if (!checking) {
new SampleModal(this.app).open();
}
return true;
}
return false;
}
});

this.addSettingTab(new SampleSettingTab(this.app, this));
}

onunload() {
console.log('unloading plugin');
}
}

class SampleModal extends Modal {
constructor(app: App) {
super(app);
}

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

onClose() {
let {contentEl} = this;
contentEl.empty();
}
}

class SampleSettingTab extends PluginSettingTab {
display(): void {
let {containerEl} = this;

containerEl.empty();

containerEl.createEl('h2', {text: 'Settings for my awesome plugin.'});

new Setting(containerEl)
.setName('Setting #1')
.setDesc('It\'s a secret')
.addText(text => text.setPlaceholder('Enter your secret')
.setValue('')
.onChange((value) => {
console.log('Secret: ' + value);
}));

}
}
8 changes: 8 additions & 0 deletions manifest.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"id": "obsidian-sample-plugin",
"name": "Sample Plugin",
"description": "This is a sample plugin for Obsidian (https://obsidian.md)",
"isDesktopOnly": false,
"js": "main.js",
"css": "styles.css"
}
Loading

0 comments on commit ed37707

Please sign in to comment.