obsidian-dev-utils
Version:
This is the collection of useful functions that you can use for your Obsidian plugin development
190 lines (189 loc) • 7.57 kB
text/typescript
/**
* @packageDocumentation
*
* Base classes for abstract file commands.
*/
import type { Plugin, TAbstractFile, WorkspaceLeaf } from 'obsidian';
import { CommandInvocationBase } from './CommandBase.cjs';
import { NonEditorCommandBase } from './NonEditorCommandBase.cjs';
/**
* Base class for abstract file commands.
*
* @typeParam TPlugin - The type of the plugin that the command belongs to.
*/
export declare abstract class AbstractFileCommandBase<TPlugin extends Plugin = Plugin> extends NonEditorCommandBase<TPlugin> {
/**
* The item name to use in the file menu.
*/
protected readonly fileMenuItemName?: string;
/**
* The section to use in the file menu.
*/
protected readonly fileMenuSection?: string;
/**
* The item name to use in the files menu.
*/
protected readonly filesMenuItemName?: string;
/**
* The section to use in the files menu.
*/
protected readonly filesMenuSection?: 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.
* @returns Whether the command can execute.
*/
checkCallback(checking: boolean): boolean;
/**
* Registers the command.
*/
register(): void;
/**
* Creates a new file command invocation.
*
* @param abstractFile - The abstract file to create the command invocation for.
* @returns The command invocation.
*/
protected createCommandInvocation(abstractFile?: TAbstractFile): AbstractFileCommandInvocationBase<TPlugin>;
/**
* Creates a new command invocation for an abstract file.
*
* @param abstractFile - The abstract file to create the command invocation for.
* @returns The command invocation.
*/
protected abstract createCommandInvocationForAbstractFile(abstractFile: null | TAbstractFile): AbstractFileCommandInvocationBase<TPlugin>;
/**
* Creates a new command invocation for abstract files.
*
* @param abstractFiles - The abstract files to create the command invocation for.
* @returns The command invocation.
*/
protected createCommandInvocationForAbstractFiles(abstractFiles: TAbstractFile[]): AbstractFilesCommandInvocationBase<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 command palette.
*
* @returns Whether the command should be added to the command palette.
*/
protected shouldAddToCommandPalette(): boolean;
private handleAbstractFileMenu;
private handleAbstractFilesMenu;
}
/**
* Base class for abstract file command invocations.
*
* @typeParam TPlugin - The type of the plugin that the command belongs to.
*/
export declare abstract class AbstractFileCommandInvocationBase<TPlugin extends Plugin> extends CommandInvocationBase<TPlugin> {
/** */
protected readonly _abstractFile: null | TAbstractFile;
/**
* The abstract file to invoke the command for.
*
* @returns The abstract file to invoke the command for.
* @throws If the abstract file is not set.
*/
protected get abstractFile(): TAbstractFile;
/**
* Creates a new abstract file command invocation.
*
* @param plugin - The plugin that the command belongs to.
* @param abstractFile - The abstract file to invoke the command for.
*/
constructor(plugin: TPlugin, abstractFile: null | TAbstractFile);
/**
* Checks if the command can execute.
*
* @returns Whether the command can execute.
*/
protected canExecute(): boolean;
}
/**
* Base class for abstract files command invocations.
*
* @typeParam TPlugin - The type of the plugin that the command belongs to.
*/
export declare abstract class AbstractFilesCommandInvocationBase<TPlugin extends Plugin> extends CommandInvocationBase<TPlugin> {
readonly abstractFiles: TAbstractFile[];
/**
* Creates a new abstract files command invocation.
*
* @param plugin - The plugin that the command belongs to.
* @param abstractFiles - The abstract files to invoke the command for.
*/
constructor(plugin: TPlugin, abstractFiles: TAbstractFile[]);
}
/**
* Base class for array-delegating abstract file command invocations.
*
* @typeParam TPlugin - The type of the plugin that the command belongs to.
*/
export declare class ArrayDelegatingAbstractFileCommandInvocation<TPlugin extends Plugin> extends AbstractFileCommandInvocationBase<TPlugin> {
private readonly createCommandInvocationForFiles;
/**
* Creates a new array-delegating abstract file command invocation.
*
* @param plugin - The plugin that the command invocation belongs to.
* @param abstractFile - The abstract file to invoke the command for.
* @param createCommandInvocationForFiles - The function to create a command invocation for files.
*/
constructor(plugin: TPlugin, abstractFile: null | TAbstractFile, createCommandInvocationForFiles: (abstractFiles: TAbstractFile[]) => AbstractFilesCommandInvocationBase<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 sequential abstract files command invocations.
*
* @typeParam TPlugin - The type of the plugin that the command belongs to.
*/
export declare class SequentialAbstractFilesCommandInvocationBase<TPlugin extends Plugin> extends AbstractFilesCommandInvocationBase<TPlugin> {
private readonly createCommandInvocationForFile;
/**
* Creates a new sequential files command invocation.
*
* @param plugin - The plugin that the command invocation belongs to.
* @param abstractFiles - The files to invoke the command for.
* @param createCommandInvocationForFile - The function to create a command invocation for a file.
*/
constructor(plugin: TPlugin, abstractFiles: TAbstractFile[], createCommandInvocationForFile: (abstractFile: TAbstractFile) => AbstractFileCommandInvocationBase<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>;
}