UNPKG

obsidian-dev-utils

Version:

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

90 lines (89 loc) 3.18 kB
/** * @packageDocumentation * * Base classes for editor commands. */ import type { Editor, MarkdownFileInfo, Plugin, TFile } from 'obsidian'; import { CommandBase, CommandInvocationBase } from './CommandBase.cjs'; /** * Base class for editor commands. * * @typeParam TPlugin - The type of the plugin that the command belongs to. */ export declare abstract class EditorCommandBase<TPlugin extends Plugin> extends CommandBase<TPlugin> { /** * The item name to use in the editor menu. */ protected readonly editorMenuItemName?: string; /** * The section to use in the editor menu. */ protected readonly editorMenuSection?: string; /** * Checks if the command can execute or executes it. * * @param checking - Is checking mode only. If `true`, only the check if the command can execute is performed. If `false`, the command is executed. * @param editor - The editor to check. * @param ctx - The context of the command. * @returns Whether the command can execute. */ editorCheckCallback(checking: boolean, editor: Editor, ctx: MarkdownFileInfo): boolean; /** * Registers the command. */ register(): void; /** * Creates a new editor command invocation. * * @param editor - The editor to create the command invocation for. * @param ctx - The context of the command. * @returns The command invocation. */ protected abstract createEditorCommandInvocation(editor: Editor, ctx: MarkdownFileInfo): CommandInvocationBase; /** * Checks if the command should be added to the command palette. * * @returns Whether the command should be added to the command palette. */ protected shouldAddToCommandPalette(): boolean; /** * Checks if the command should be added to the editor menu. * * @param _editor - The editor to check. * @param _ctx - The context of the command. * @returns Whether the command should be added to the editor menu. */ protected shouldAddToEditorMenu(_editor: Editor, _ctx: MarkdownFileInfo): boolean; private handleEditorMenu; } /** * Base class for editor command invocations. * * @typeParam TPlugin - The type of the plugin that the command belongs to. */ export declare class EditorCommandInvocationBase<TPlugin extends Plugin> extends CommandInvocationBase<TPlugin> { protected readonly editor: Editor; protected readonly ctx: MarkdownFileInfo; /** * The file to invoke the command for. * * @returns The file to invoke the command for. * @throws If the file is not set. */ protected get file(): TFile; private readonly _file; /** * Creates a new editor command invocation. * * @param plugin - The plugin that the command invocation belongs to. * @param editor - The editor to create the command invocation for. * @param ctx - The context of the command. */ constructor(plugin: TPlugin, editor: Editor, ctx: MarkdownFileInfo); /** * Checks if the command can execute. * * @returns Whether the command can execute. */ canExecute(): boolean; }