UNPKG

obsidian-dev-utils

Version:

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

54 lines (53 loc) 1.51 kB
/** * @packageDocumentation * * Utility for displaying a prompt modal in Obsidian. * * This module exports a function to display a modal that prompts the user for input. The modal includes "OK" and "Cancel" buttons. */ import type { App } from 'obsidian'; import type { Promisable } from 'type-fest'; import type { MaybeReturn } from '../../Type.cjs'; /** * Options for {@link prompt}. */ export interface PromptOptions { /** * An Obsidian app instance. */ app: App; /** * A text for the "Cancel" button. */ cancelButtonText?: string; /** * A default value to pre-fill the input field. */ defaultValue?: string; /** * A text for the "OK" button. */ okButtonText?: string; /** * A placeholder text for the input field. */ placeholder?: string; /** * A title of the modal. */ title?: DocumentFragment | string; /** * A function to validate the input value. * * @param value - The input value to validate. * @returns an error message if the value is invalid, or null if the value is valid. */ valueValidator?(value: string): Promisable<MaybeReturn<string>>; } /** * Displays a prompt modal in Obsidian to get user input. * * @param options - The options for the prompt modal. * @returns A {@link Promise} that resolves with the user input or null if the prompt was cancelled. */ export declare function prompt(options: PromptOptions): Promise<null | string>;