/** * @typedef {import('bootstrap').Modal} Modal */ export type Modal = import('bootstrap').Modal; export type ModalClass = typeof import('bootstrap').Modal; export type CustomElementConfig = { /** * - CSS classes to be added to the element (as a string or an array of strings). */ className?: string | string[]; /** * - CSS properties and values (e.g., { 'background-color': '#000' }). */ styles?: Record; }; export type ModalOptions = { /** * - The text to be displayed in the modal header. */ title?: string; /** * - The text to be displayed on the primary confirmation button. */ confirmText?: string; /** * - The text to be displayed on the secondary cancel button. */ cancelText?: string; /** * - The initial value for the input field (used in prompts). */ defaultValue?: string; /** * - Customization for the main modal container. */ modalConfig?: CustomElementConfig; /** * - Customization for the modal header. */ headerConfig?: CustomElementConfig; /** * - Customization for the modal title. */ titleConfig?: CustomElementConfig; /** * - Customization for the close button. */ closeBtnConfig?: CustomElementConfig; /** * - Customization for the modal body. */ bodyConfig?: CustomElementConfig; /** * - Customization for the modal footer. */ footerConfig?: CustomElementConfig; /** * - Customization for the confirm button. */ confirmBtnConfig?: CustomElementConfig; /** * - Customization for the cancel button. */ cancelBtnConfig?: CustomElementConfig; /** * - Customization for the modal content container. */ contentConfig?: CustomElementConfig; /** * - Customization for the modal dialog wrapper. */ dialogConfig?: CustomElementConfig; }; /** * @typedef {typeof import('bootstrap').Modal} ModalClass */ /** * @typedef {Object} CustomElementConfig * @property {string | string[]} [className] - CSS classes to be added to the element (as a string or an array of strings). * @property {Object} [styles] - CSS properties and values (e.g., { 'background-color': '#000' }). */ /** * @typedef {Object} ModalOptions - Configuration options for the dialog content and buttons. * @property {string} [title] - The text to be displayed in the modal header. * @property {string} [confirmText] - The text to be displayed on the primary confirmation button. * @property {string} [cancelText] - The text to be displayed on the secondary cancel button. * @property {string} [defaultValue] - The initial value for the input field (used in prompts). * @property {CustomElementConfig} [modalConfig] - Customization for the main modal container. * @property {CustomElementConfig} [headerConfig] - Customization for the modal header. * @property {CustomElementConfig} [titleConfig] - Customization for the modal title. * @property {CustomElementConfig} [closeBtnConfig] - Customization for the close button. * @property {CustomElementConfig} [bodyConfig] - Customization for the modal body. * @property {CustomElementConfig} [footerConfig] - Customization for the modal footer. * @property {CustomElementConfig} [confirmBtnConfig] - Customization for the confirm button. * @property {CustomElementConfig} [cancelBtnConfig] - Customization for the cancel button. * @property {CustomElementConfig} [contentConfig] - Customization for the modal content container. * @property {CustomElementConfig} [dialogConfig] - Customization for the modal dialog wrapper. */ /** * Utility to replace native alert/confirm/prompt with Bootstrap 5 modals. * Built with strict DOM manipulation to prevent XSS. */ declare class BootstrapDialogs { #private; /** @type {Modal|null} */ static _activeInstance: Modal | null; /** @type {Modal|null} */ static _loadingInstance: Modal | null; /** @type {HTMLElement|null} */ static _modalElement: HTMLElement | null; /** @type {HTMLElement|null} */ static _loadingElement: HTMLElement | null; /** @type {Function|null} */ static _activeResolve: Function | null; /** @type {'alert'|'confirm'|'prompt'|null} */ static _activeType: 'alert' | 'confirm' | 'prompt' | null; /** * Gets a deep copy of the default configuration. * @returns {Object} */ static get defaultConfig(): Record; /** * Sets the entire default configuration. * @param {Object} config - The new default configuration. * @throws {TypeError} If the configuration is invalid. */ static set defaultConfig(config: Record); /** * Sets the Modal class constructor (e.g., Bootstrap's Modal). * @param {ModalClass} Modal - The Bootstrap Modal class constructor. * @throws {Error} If a Modal class has already been set. */ static set Modal(Modal: ModalClass); /** * Gets the currently set Modal class constructor. * @returns {ModalClass} The currently configured Modal class. * @throws {Error} If no Modal class has been set. */ static get Modal(): ModalClass; /** * Updates a specific configuration key by merging it with existing defaults. * @param {string} key - The key within #defaultConfig to update. * @param {CustomElementConfig} config - The partial or full configuration to merge. * @private */ private static _updateConfigKey; /** @param {CustomElementConfig} cfg */ static set modalConfig(cfg: CustomElementConfig); static get modalConfig(): CustomElementConfig; /** @param {CustomElementConfig} cfg */ static set headerConfig(cfg: CustomElementConfig); static get headerConfig(): CustomElementConfig; /** @param {CustomElementConfig} cfg */ static set titleConfig(cfg: CustomElementConfig); static get titleConfig(): CustomElementConfig; /** @param {CustomElementConfig} cfg */ static set closeBtnConfig(cfg: CustomElementConfig); static get closeBtnConfig(): CustomElementConfig; /** @param {CustomElementConfig} cfg */ static set bodyConfig(cfg: CustomElementConfig); static get bodyConfig(): CustomElementConfig; /** @param {CustomElementConfig} cfg */ static set footerConfig(cfg: CustomElementConfig); static get footerConfig(): CustomElementConfig; /** @param {CustomElementConfig} cfg */ static set confirmBtnConfig(cfg: CustomElementConfig); static get confirmBtnConfig(): CustomElementConfig; /** @param {CustomElementConfig} cfg */ static set cancelBtnConfig(cfg: CustomElementConfig); static get cancelBtnConfig(): CustomElementConfig; /** @param {CustomElementConfig} cfg */ static set contentConfig(cfg: CustomElementConfig); static get contentConfig(): CustomElementConfig; /** @param {CustomElementConfig} cfg */ static set dialogConfig(cfg: CustomElementConfig); static get dialogConfig(): CustomElementConfig; /** * Helper to forcefully clean up body styles injected by Bootstrap JS. * @returns {void} */ static _restoreBody(): void; /** * Applies custom classes and styles to a given element. * Combines default configurations with user-provided overrides. * @param {HTMLElement} element - The target element. * @param {CustomElementConfig} [defaultConfig] - The default configuration. * @param {CustomElementConfig} [userConfig] - The user customization. * @private */ private static _applyCustomizations; /** * Validates the ModalOptions object deeply. * @param {ModalOptions} options - The options to validate. * @throws {TypeError} If validation fails. * @private */ private static _validateOptions; /** * Displays a simple alert modal. * @param {string} message - The text message to be displayed to the user. * @param {ModalOptions} [options={}] - Configuration options for the alert modal. * @returns {Promise} A promise that resolves when the alert is closed. */ static alert(message: string, options?: ModalOptions): Promise; /** * Displays a confirmation modal. * @param {string} message - The question or message to be displayed to the user. * @param {ModalOptions} [options={}] - Configuration options for the confirmation modal. * @returns {Promise} A promise that resolves with true if confirmed, or false if cancelled. */ static confirm(message: string, options?: ModalOptions): Promise; /** * Displays a prompt modal with an input field. * @param {string} message - The instruction or question for the user. * @param {string} [defaultValue=''] - The initial value for the input field. * @param {ModalOptions} [options={}] - Configuration options for the prompt modal. * @returns {Promise} A promise that resolves with the input value, or null if cancelled. */ static prompt(message: string, defaultValue?: string, options?: ModalOptions): Promise; /** * Displays a global, non-dismissible loading overlay for background/DB tasks. * If a loading overlay is already active, it updates the existing message and styles. * @param {string} [message='Processing...'] - The text to display while the loading state is active. * @param {CustomElementConfig} [config] - Customization for the loading message element. * @returns {void} */ static showLoading(message?: string, config?: CustomElementConfig): void; /** * Hides and destroys the active loading overlay. * @returns {void} */ static hideLoading(): void; /** * Core method to build the modal DOM structure safely. * @param {string} titleText - The text to be placed in the modal header. * @param {HTMLElement|string} bodyContent - The content to be placed in the modal body. * @param {boolean} showCancel - Whether to display the cancel button. * @param {string} confirmText - The text for the confirmation button. * @param {string|null} [cancelText='Cancel'] - The text for the cancel button. * @param {ModalOptions} [options={}] - Configuration options for customization. * @returns {HTMLElement} The constructed modal element. */ static _buildModalElement(titleText: string, bodyContent: HTMLElement | string, showCancel: boolean, confirmText: string, cancelText?: string | null, options?: ModalOptions): HTMLElement; /** * Clean up any existing modal and resolve its promise. * @returns {void} */ static _cleanup(): void; /** * Internal method to initialize the modal instance and handle lifecycle. * @param {string} title - The title text for the modal. * @param {HTMLElement|string} bodyContent - The content to be placed in the modal body. * @param {boolean} showCancel - Whether to include a cancel button. * @param {string} confirmText - The text for the confirmation button. * @param {string|null} [cancelText='Cancel'] - The text for the cancel button. * @param {'alert'|'confirm'|'prompt'} [type='alert'] - The type of dialog being shown. * @param {ModalOptions} [options={}] - Configuration options for customization. * @returns {Promise} A promise that resolves with the user's action. */ static _show(title: string, bodyContent: HTMLElement | string, showCancel: boolean, confirmText: string, cancelText?: string | null, type?: 'alert' | 'confirm' | 'prompt', options?: ModalOptions): Promise; } export { BootstrapDialogs }; /** * @param {string} msg - The message to display. * @param {ModalOptions} [options] - Configuration options for the alert. * @returns {Promise} */ export declare const alert: (msg: string, options?: ModalOptions) => Promise; /** * @param {string} msg - The message to display. * @param {string} [def] - The default value for the input field. * @param {ModalOptions} [options] - Configuration options for the prompt. * @returns {Promise} */ export declare const prompt: (msg: string, def?: string, options?: ModalOptions) => Promise; /** * @param {string} msg - The message to display. * @param {ModalOptions} [options] - Configuration options for the confirmation. * @returns {Promise} */ export declare const confirm: (msg: string, options?: ModalOptions) => Promise; /** * @param {string} msg - The message to display. * @param {CustomElementConfig} [config] - Customization for the loading message. * @returns {void} */ export declare const showLoading: (msg: string, config?: CustomElementConfig) => void; /** * Hides and destroys the active loading overlay. * @returns {void} */ export declare const hideLoading: () => void; //# sourceMappingURL=BootstrapDialogs.d.mts.map