UNPKG

obsidian-dev-utils

Version:

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

178 lines (177 loc) 7.45 kB
/** * @packageDocumentation * * Base classes for folder commands. */ import type { Plugin, TAbstractFile, WorkspaceLeaf } from 'obsidian'; import { TFolder } from 'obsidian'; import { AbstractFileCommandBase, AbstractFileCommandInvocationBase, AbstractFilesCommandInvocationBase } from './AbstractFileCommandBase.cjs'; /** * Base class for folder command invocations. * * @typeParam TPlugin - The type of the plugin that the command belongs to. */ export declare abstract class FolderCommandInvocationBase<TPlugin extends Plugin> extends AbstractFileCommandInvocationBase<TPlugin> { /** * Gets the folder that the command invocation belongs to. * * @returns The folder that the command invocation belongs to. * @throws If the abstract file is not a folder. */ protected get folder(): TFolder; /** * 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 ArrayDelegatingFolderCommandInvocation<TPlugin extends Plugin> extends FolderCommandInvocationBase<TPlugin> { private readonly createCommandInvocationForFiles; /** * Creates a new array-delegating folder command invocation. * * @param plugin - The plugin that the command invocation belongs to. * @param folder - The file to invoke the command for. * @param createCommandInvocationForFiles - The function to create a command invocation for files. */ constructor(plugin: TPlugin, folder: null | TFolder, createCommandInvocationForFiles: (folders: TFolder[]) => FoldersCommandInvocationBase<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 folder commands. * * @typeParam TPlugin - The type of the plugin that the command belongs to. */ export declare abstract class FolderCommandBase<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 A new abstract file 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. * @returns A new abstract file 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 abstract file command invocation for a folder. * * @param folder - The folder to invoke the command for. * @returns A new folder command invocation. */ protected abstract createCommandInvocationForFolder(folder: null | TFolder): FolderCommandInvocationBase<TPlugin>; /** * Creates a new folders command invocation for folders. * * @param folders - The folders to invoke the command for. * @returns A new folders command invocation. */ protected createCommandInvocationForFolders(folders: TFolder[]): FoldersCommandInvocationBase<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 folder menu. * * @param _folder - The folder to check. * @param _source - The source of the folder. * @param _leaf - The leaf to check. * @returns Whether the command should be added to the folder menu. */ protected shouldAddToFolderMenu(_folder: TFolder, _source: string, _leaf?: WorkspaceLeaf): boolean; /** * Checks if the command should be added to the folders menu. * * @param _folders - The folders to check. * @param _source - The source of the folders. * @param _leaf - The leaf to check. * @returns Whether the command should be added to the folders menu. */ protected shouldAddToFoldersMenu(_folders: TFolder[], _source: string, _leaf?: WorkspaceLeaf): boolean; } /** * Base class for folders command invocations. * * @typeParam TPlugin - The type of the plugin that the command belongs to. */ export declare abstract class FoldersCommandInvocationBase<TPlugin extends Plugin> extends AbstractFilesCommandInvocationBase<TPlugin> { readonly folders: TFolder[]; /** * Creates a new folders command invocation. * * @param plugin - The plugin that the command invocation belongs to. * @param folders - The folders to invoke the command for. */ constructor(plugin: TPlugin, folders: TFolder[]); } /** * Base class for sequential folders command invocations. * * @typeParam TPlugin - The type of the plugin that the command belongs to. */ export declare class SequentialFoldersCommandInvocationBase<TPlugin extends Plugin> extends FoldersCommandInvocationBase<TPlugin> { private readonly createCommandInvocationForFolder; /** * Creates a new sequential folders command invocation. * * @param plugin - The plugin that the command invocation belongs to. * @param folders - The folders to invoke the command for. * @param createCommandInvocationForFolder - The function to create a command invocation for a folder. */ constructor(plugin: TPlugin, folders: TFolder[], createCommandInvocationForFolder: (folder: TFolder) => FolderCommandInvocationBase<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>; }