UNPKG

obsidian-dev-utils

Version:

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

185 lines (184 loc) 7.54 kB
/** * @packageDocumentation * * Base classes for file commands. */ import type { Plugin, TAbstractFile, WorkspaceLeaf } from 'obsidian'; import { TFile } from 'obsidian'; import { AbstractFileCommandBase, AbstractFileCommandInvocationBase, AbstractFilesCommandInvocationBase } from './AbstractFileCommandBase.cjs'; /** * Base class for file command invocations. * * @typeParam TPlugin - The type of the plugin that the command belongs to. */ export declare abstract class FileCommandInvocationBase<TPlugin extends Plugin> extends AbstractFileCommandInvocationBase<TPlugin> { /** * Gets the file that the command invocation belongs to. * * @returns The file that the command invocation belongs to. * @throws If the abstract file is not a file. */ protected get file(): TFile; /** * Creates a new file command invocation. * * @param plugin - The plugin that the command invocation belongs to. * @param file - The file to invoke the command for. */ constructor(plugin: TPlugin, file: null | TFile); /** * Checks if the command can execute. * * @returns Whether the command can execute. */ protected canExecute(): boolean; } /** * Base class for array-delegating file command invocations. * * @typeParam TPlugin - The type of the plugin that the command belongs to. */ export declare class ArrayDelegatingFileCommandInvocation<TPlugin extends Plugin> extends FileCommandInvocationBase<TPlugin> { private readonly createCommandInvocationForFiles; /** * Creates a new array-delegating file command invocation. * * @param plugin - The plugin that the command invocation belongs to. * @param file - The file to invoke the command for. * @param createCommandInvocationForFiles - The function to create a command invocation for files. */ constructor(plugin: TPlugin, file: null | TFile, createCommandInvocationForFiles: (files: TFile[]) => FilesCommandInvocationBase<TPlugin>); /** * Checks if the command can execute. * * @returns Whether the command can execute. */ protected canExecute(): boolean; /** * Executes the command. * * @returns A promise that resolves when the command has been executed. */ protected execute(): Promise<void>; } /** * Base class for file commands. * * @typeParam TPlugin - The type of the plugin that the command belongs to. */ export declare abstract class FileCommandBase<TPlugin extends Plugin = Plugin> extends AbstractFileCommandBase<TPlugin> { /** * Creates a new abstract file command invocation. * * @param abstractFile - The abstract file to invoke the command for. * @returns The command invocation. */ protected createCommandInvocation(abstractFile?: TAbstractFile): AbstractFileCommandInvocationBase<TPlugin>; /** * Creates a new abstract file command invocation for an abstract file. * * @param abstractFile - The abstract file to invoke the command for. If `null`, the active file is used. * @returns The command invocation. */ protected createCommandInvocationForAbstractFile(abstractFile: null | TAbstractFile): AbstractFileCommandInvocationBase<TPlugin>; /** * Creates a new abstract files command invocation for abstract files. * * @param abstractFiles - The abstract files to invoke the command for. * @returns A new abstract files command invocation. */ protected createCommandInvocationForAbstractFiles(abstractFiles: TAbstractFile[]): AbstractFilesCommandInvocationBase<TPlugin>; /** * Creates a new file command invocation for a file. * * @param file - The file to invoke the command for. * @returns A new file command invocation. */ protected abstract createCommandInvocationForFile(file: null | TFile): FileCommandInvocationBase<TPlugin>; /** * Creates a new files command invocation for files. * * @param files - The files to invoke the command for. * @returns A new files command invocation. */ protected createCommandInvocationForFiles(files: TFile[]): FilesCommandInvocationBase<TPlugin>; /** * Checks if the command should be added to the abstract file menu. * * @param abstractFile - The abstract file to check. * @param source - The source of the abstract file. * @param leaf - The leaf to check. * @returns Whether the command should be added to the abstract file menu. */ protected shouldAddToAbstractFileMenu(abstractFile: TAbstractFile, source: string, leaf?: WorkspaceLeaf): boolean; /** * Checks if the command should be added to the abstract files menu. * * @param abstractFiles - The abstract files to check. * @param source - The source of the abstract files. * @param leaf - The leaf to check. * @returns Whether the command should be added to the abstract files menu. */ protected shouldAddToAbstractFilesMenu(abstractFiles: TAbstractFile[], source: string, leaf?: WorkspaceLeaf): boolean; /** * Checks if the command should be added to the file menu. * * @param _file - The file to check. * @param _source - The source of the file. * @param _leaf - The leaf to check. * @returns Whether the command should be added to the file menu. */ protected shouldAddToFileMenu(_file: TFile, _source: string, _leaf?: WorkspaceLeaf): boolean; /** * Checks if the command should be added to the files menu. * * @param _files - The files to check. * @param _source - The source of the files. * @param _leaf - The leaf to check. * @returns Whether the command should be added to the files menu. */ protected shouldAddToFilesMenu(_files: TFile[], _source: string, _leaf?: WorkspaceLeaf): boolean; } /** * Base class for files command invocations. * * @typeParam TPlugin - The type of the plugin that the command belongs to. */ export declare abstract class FilesCommandInvocationBase<TPlugin extends Plugin> extends AbstractFilesCommandInvocationBase<TPlugin> { readonly files: TFile[]; /** * Creates a new files command invocation. * * @param plugin - The plugin that the command invocation belongs to. * @param files - The files to invoke the command for. */ constructor(plugin: TPlugin, files: TFile[]); } /** * Base class for sequential files command invocations. * * @typeParam TPlugin - The type of the plugin that the command belongs to. */ export declare class SequentialFilesCommandInvocationBase<TPlugin extends Plugin> extends FilesCommandInvocationBase<TPlugin> { private readonly createCommandInvocationForFile; /** * Creates a new sequential files command invocation. * * @param plugin - The plugin that the command invocation belongs to. * @param files - The files to invoke the command for. * @param createCommandInvocationForFile - The function to create a command invocation for a file. */ constructor(plugin: TPlugin, files: TFile[], createCommandInvocationForFile: (file: TFile) => FileCommandInvocationBase<TPlugin>); /** * Checks if the command can execute. * * @returns Whether the command can execute. */ protected canExecute(): boolean; /** * Executes the command. * * @returns A promise that resolves when the command has been executed. */ protected execute(): Promise<void>; }