Skip to content

Commit 948a412

Browse files
committed
Add initial version of the plugin API helper
1 parent a308c8b commit 948a412

File tree

6 files changed

+2711
-0
lines changed

6 files changed

+2711
-0
lines changed

.eslintrc

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
{
2+
"root": true,
3+
"parser": "@typescript-eslint/parser",
4+
"env": { "node": true },
5+
"plugins": [
6+
"@typescript-eslint"
7+
],
8+
"extends": [
9+
"eslint:recommended",
10+
"plugin:@typescript-eslint/eslint-recommended",
11+
"plugin:@typescript-eslint/recommended"
12+
],
13+
"parserOptions": {
14+
"sourceType": "module"
15+
},
16+
"rules": {
17+
"no-unused-vars": "off",
18+
"@typescript-eslint/no-unused-vars": ["error", { "args": "none" }],
19+
"@typescript-eslint/ban-ts-comment": "off",
20+
"no-prototype-builtins": "off",
21+
"@typescript-eslint/no-empty-function": "off"
22+
}
23+
}

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
node_modules

index.ts

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
import {Plugin} from 'obsidian';
2+
3+
declare global {
4+
interface Window {
5+
['PluginApi']?: any
6+
}
7+
}
8+
9+
export function registerAPI(name: string, api: any, plugin: Plugin) {
10+
window['PluginApi'] = window['PluginApi'] || {};
11+
12+
window['PluginApi'][name] = api;
13+
14+
plugin.register(() => {
15+
delete window['PluginApi'][name];
16+
});
17+
}

0 commit comments

Comments
 (0)