mirror of
https://github.com/runofthemillgeek/swarnam-obsidian.git
synced 2024-11-16 07:20:16 +00:00
Initial commit!
This commit is contained in:
commit
ed3770792a
11
.gitignore
vendored
Normal file
11
.gitignore
vendored
Normal file
@ -0,0 +1,11 @@
|
|||||||
|
# Intellij
|
||||||
|
*.iml
|
||||||
|
.idea
|
||||||
|
|
||||||
|
# npm
|
||||||
|
node_modules
|
||||||
|
package-lock.json
|
||||||
|
|
||||||
|
# build
|
||||||
|
main.js
|
||||||
|
*.js.map
|
35
README.md
Normal file
35
README.md
Normal file
@ -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
main.ts
Normal file
77
main.ts
Normal file
@ -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
manifest.json
Normal file
8
manifest.json
Normal file
@ -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"
|
||||||
|
}
|
1453
obsidian.d.ts
vendored
Normal file
1453
obsidian.d.ts
vendored
Normal file
File diff suppressed because it is too large
Load Diff
18
package.json
Normal file
18
package.json
Normal file
@ -0,0 +1,18 @@
|
|||||||
|
{
|
||||||
|
"name": "obsidian-sample-plugin",
|
||||||
|
"version": "0.9.7",
|
||||||
|
"description": "This is a sample plugin for Obsidian (https://obsidian.md)",
|
||||||
|
"main": "main.js",
|
||||||
|
"scripts": {
|
||||||
|
"dev": "tsc --project tsconfig.json -w",
|
||||||
|
"build": "tsc --project tsconfig.json"
|
||||||
|
},
|
||||||
|
"keywords": [],
|
||||||
|
"author": "",
|
||||||
|
"license": "MIT",
|
||||||
|
"devDependencies": {
|
||||||
|
"@types/codemirror": "0.0.98",
|
||||||
|
"@types/node": "^14.14.2",
|
||||||
|
"typescript": "^4.0.3"
|
||||||
|
}
|
||||||
|
}
|
4
styles.css
Normal file
4
styles.css
Normal file
@ -0,0 +1,4 @@
|
|||||||
|
/* Sets all the text color to red! */
|
||||||
|
body {
|
||||||
|
color: red;
|
||||||
|
}
|
21
tsconfig.json
Normal file
21
tsconfig.json
Normal file
@ -0,0 +1,21 @@
|
|||||||
|
{
|
||||||
|
"compilerOptions": {
|
||||||
|
"baseUrl": ".",
|
||||||
|
"inlineSourceMap": true,
|
||||||
|
"inlineSources": true,
|
||||||
|
"module": "CommonJS",
|
||||||
|
"target": "es5",
|
||||||
|
"allowJs": true,
|
||||||
|
"noImplicitAny": true,
|
||||||
|
"moduleResolution": "node",
|
||||||
|
"lib": [
|
||||||
|
"dom",
|
||||||
|
"es5",
|
||||||
|
"scripthost",
|
||||||
|
"es2015"
|
||||||
|
]
|
||||||
|
},
|
||||||
|
"include": [
|
||||||
|
"**/*.ts"
|
||||||
|
]
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user