UNPKG

obsidian-dev-utils

Version:

This is the collection of useful functions that you can use for your Obsidian plugin development

126 lines (125 loc) 3.32 kB
/** * @packageDocumentation * * Base classes for commands. */ import type { App, Command, IconName, Plugin } from 'obsidian'; /** * Options for creating a command. * * @typeParam TPlugin - The type of the plugin that the command belongs to. */ export interface CommandBaseOptions<TPlugin extends Plugin> { /** * The icon to use for the command. */ icon: IconName; /** * The ID of the command. */ id: string; /** * The name of the command. */ name: string; /** * The plugin that the command belongs to. */ plugin: TPlugin; } /** * Base class for commands. * * @typeParam TPlugin - The type of the plugin that the command belongs to. */ export declare abstract class CommandBase<TPlugin extends Plugin> implements Command { /** * The icon of the command. */ icon: IconName; /** * The ID of the command. * * Obsidian changes the passed ID by prepending the plugin's ID to it. * * @see {@link originalId}. */ id: string; /** * The name of the command. * * Obsidian changes the passed name by prepending the plugin's name to it. * * @see {@link originalName}. */ name: string; /** * The app that the command belongs to. */ protected readonly app: App; /** * The original ID of the command. */ protected readonly originalId: string; /** * The original name of the command. */ protected readonly originalName: string; /** * The plugin that the command belongs to. */ protected readonly plugin: TPlugin; /** * Creates a new command. * * @param options - The options for the command. */ constructor(options: CommandBaseOptions<TPlugin>); /** * Registers the command. */ register(): void; } /** * Base class for command invocations. * * @typeParam TPlugin - The type of the plugin that the command belongs to. */ export declare abstract class CommandInvocationBase<TPlugin extends Plugin = Plugin> { protected readonly plugin: TPlugin; /** * The app that the command invocation belongs to. */ protected readonly app: App; private lastCanExecuteResult?; /** * Creates a new command invocation. * * @param plugin - The plugin that the command invocation belongs to. */ constructor(plugin: TPlugin); /** * Invokes the command. * * @param checking - Is checking mode only. If `true`, only the check if the command can execute is performed. If `false`, the command is executed. * @returns Whether the command was executed. */ invoke(checking: boolean): boolean; /** * Invokes the command asynchronously. * * @param checking - Is checking mode only. If `true`, only the check if the command can execute is performed. If `false`, the command is executed. * @returns A promise that resolves when the command has been executed. */ invokeAsync(checking: boolean): Promise<void>; /** * Checks if the command can execute. * * @returns Whether the command can execute. */ protected canExecute(): boolean; /** * Executes the command. */ protected execute(): Promise<void>; }