Permalink
Cannot retrieve contributors at this time
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
39 lines (30 sloc)
994 Bytes
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
| import "obsidian"; | |
| import { Plugin } from "obsidian"; | |
| import FolderNoteAPI, { FNCEvents, NoteLoc } from "./typings/api"; | |
| export type { FNCEvents, FolderNoteAPI, NoteLoc }; | |
| // EVENTS | |
| type OnArgs<T> = T extends [infer A, ...infer B] | |
| ? A extends string | |
| ? [name: A, callback: (...args: B) => any] | |
| : never | |
| : never; | |
| type EventsOnArgs = OnArgs<FNCEvents>; | |
| declare module "obsidian" { | |
| interface Vault { | |
| on(...args: EventsOnArgs): EventRef; | |
| } | |
| } | |
| // UTIL FUNCTIONS | |
| export const getApi = (plugin?: Plugin): FolderNoteAPI | undefined => { | |
| if (plugin) return plugin.app.plugins.plugins["folder-note-core"]?.api; | |
| else return window["FolderNoteAPIv0"]; | |
| }; | |
| export const isPluginEnabled = (plugin: Plugin) => | |
| plugin.app.plugins.enabledPlugins.has("folder-note-core"); | |
| export const registerApi = ( | |
| plugin: Plugin, | |
| callback: (api: FolderNoteAPI) => void, | |
| ): FolderNoteAPI | undefined => { | |
| plugin.app.vault.on("folder-note:api-ready", callback); | |
| return getApi(plugin); | |
| }; |