-
Notifications
You must be signed in to change notification settings - Fork 60
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit ed37707
Showing
8 changed files
with
1,627 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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` | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
})); | ||
|
||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" | ||
} |
Oops, something went wrong.