import { Component } from 'vue'; import { ModalController } from './state'; import { Constructor, IsAny, IsPlainObject, Pretty } from './utils'; /** * Button configuration for dialog OK/Cancel buttons. * Can be a simple string (label), boolean (show/hide), or full configuration object. */ export interface DialogButtonConfig { /** Button label text */ label?: string; /** Button variant style */ variant?: "hero" | "primary" | "secondary-outline" | "secondary-text"; /** Whether the button is disabled */ disabled?: boolean; /** CSS class(es) for the button */ class?: string | string[] | Record; } /** * Configuration for prompt input in dialogs. */ export interface DialogPromptConfig { /** Initial value for the input */ model?: string; /** Input type (text, password, email, etc.) */ type?: "text" | "password" | "email" | "number" | "tel" | "url"; /** Placeholder text */ placeholder?: string; /** Label for the input */ label?: string; /** Whether the input is required */ required?: boolean; } /** * Configuration for options selection in dialogs. */ export interface DialogOptionsConfig { /** Initial selected value(s) */ model?: string | string[]; /** Type of selection - radio for single, checkbox for multiple */ type?: "radio" | "checkbox"; /** Array of options - can be strings or objects with label/value */ items: (string | { label: string; value: string; })[]; } /** * Progress indicator configuration. */ export interface DialogProgressConfig { /** Message to display with the spinner */ message?: string; } /** * Options for creating a dialog using showModal.create(). * * @example * ```typescript * showModal.create({ * title: "Confirm Delete", * message: "Are you sure you want to delete this item?", * ok: "Delete", * cancel: "Cancel" * }).onOk(() => { * deleteItem(); * }); * ``` */ export interface DialogOptions { /** CSS class(es) to apply to the dialog card */ class?: string | string[] | Record; /** CSS style to apply to the dialog card */ style?: string | Record; /** Title text for the dialog header */ title?: string; /** Message content for the dialog body */ message?: string; /** * Render title and message as HTML. * WARNING: This can lead to XSS attacks - sanitize content first! */ html?: boolean; /** Position of the dialog on screen */ position?: "standard" | "top" | "right" | "bottom" | "left"; /** Configuration for a text input prompt */ prompt?: DialogPromptConfig; /** Configuration for radio/checkbox options selection */ options?: DialogOptionsConfig; /** * Display a loading spinner. * Can be true for default spinner or an object with message. */ progress?: boolean | DialogProgressConfig; /** * OK button configuration. * - `true`: Show default "OK" button * - `false`: Hide OK button * - `string`: Use as button label * - `object`: Full button configuration */ ok?: string | boolean | DialogButtonConfig; /** * Cancel button configuration. * - `true`: Show default "Cancel" button * - `false`: Hide Cancel button * - `string`: Use as button label * - `object`: Full button configuration */ cancel?: string | boolean | DialogButtonConfig; /** Which button to focus by default ("ok" | "cancel" | "none") */ focus?: "ok" | "cancel" | "none"; /** Stack buttons vertically instead of horizontally */ stackButtons?: boolean; /** Color theme for the dialog */ color?: string; /** Apply dark mode styling */ dark?: boolean | null; /** * User cannot dismiss dialog by clicking outside or pressing ESC. * Also prevents route changes from dismissing it. */ persistent?: boolean; /** User cannot dismiss dialog by pressing ESC key */ noEscDismiss?: boolean; /** User cannot dismiss dialog by clicking outside of it */ noBackdropDismiss?: boolean; /** Route changes won't dismiss the dialog */ noRouteDismiss?: boolean; /** Seamless mode - no backdrop, user can interact with page */ seamless?: boolean; /** Maximize the dialog to fill the screen */ maximized?: boolean; /** Dialog will try to render with same width as the window */ fullWidth?: boolean; /** Dialog will try to render with same height as the window */ fullHeight?: boolean; /** Transition animation when showing the dialog */ transitionShow?: string; /** Transition animation when hiding the dialog */ transitionHide?: string; } /** * Result returned when a dialog closes. */ export interface DialogResult { /** Whether the OK button was clicked */ ok: boolean; /** Whether the dialog was cancelled */ cancelled: boolean; /** Value from prompt input (if prompt was configured) */ promptValue?: string; /** Selected option value(s) (if options were configured) */ optionValue?: string | string[]; } /** * Chainable dialog instance returned by showModal.create(). * Provides .onOk(), .onCancel(), and other callbacks. */ export interface DialogChainObject { /** * Register a callback for when the OK button is clicked. * @param callback - Function called with the dialog result * @returns The dialog chain for method chaining */ onOk(callback: (result: DialogResult) => void): DialogChainObject; /** * Register a callback for when the Cancel button is clicked or dialog is dismissed. * @param callback - Function called when cancelled * @returns The dialog chain for method chaining */ onCancel(callback: () => void): DialogChainObject; /** * Register a callback for when the dialog is dismissed (backdrop click, ESC key). * @param callback - Function called when dismissed * @returns The dialog chain for method chaining */ onDismiss(callback: () => void): DialogChainObject; /** * Hide the dialog programmatically. */ hide(): void; /** * Update dialog options while it's open. * Useful for updating progress messages. * @param options - Partial options to update */ update(options: Partial): void; } /** * Extracts the props type from a Vue component. * @template T - The Vue component type * @typedef {T extends Constructor<{ $props: infer TProps }> ? TProps : object} GetModalProps */ export type GetModalProps = T extends Constructor<{ $props: infer TProps; }> ? TProps : object; /** * Extracts the response type from a Vue component's close event. * Handles various response patterns including dismissed state and response data. * @template T - The Vue component type * @typedef {Object} GetModalResponse * @property {boolean} dismissed - Whether the modal was dismissed without a response * @property {*} [response] - The response data from the modal (if not dismissed) */ export type GetModalResponse = T extends Constructor<{ $emit?: (event: "close", args: infer TResponse) => void; }> ? IsAny extends true ? { dismissed: boolean; } : IsPlainObject extends true ? Pretty<{ dismissed: false; } & TResponse> | Pretty<{ dismissed: true; } & { [k in keyof TResponse]?: undefined; }> : { dismissed: false; response: TResponse; } | { dismissed: true; } : { dismissed: boolean; }; /** * Creates a modal controller for a component that doesn't require props. * @template T - The Vue component type * @param {T} component - The Vue component to display in the modal * @param {GetModalProps} [props] - Optional props to pass to the component * @returns {ModalController>} A modal controller instance */ export declare function createModal(component: T & object extends GetModalProps ? T : never, props?: GetModalProps): ModalController>; /** * Creates a modal controller for a component that requires props. * @template T - The Vue component type * @param {T} component - The Vue component to display in the modal * @param {GetModalProps} props - Required props to pass to the component * @returns {ModalController>} A modal controller instance */ export declare function createModal(component: T & object extends GetModalProps ? never : T, props: GetModalProps): ModalController>; /** * Creates a modal controller with generic component and props. * @param {Component} component - The Vue component to display in the modal * @param {Record} [props] - Optional props to pass to the component * @returns {ModalController} A modal controller instance */ export declare function createModal(component: Component, props?: Record): ModalController; /** * Creates a simple dialog without a custom component. * * @param {DialogOptions} options - Configuration for the dialog * @returns {DialogChainObject} A chainable object with onOk, onCancel, onDismiss callbacks * * @example * ```typescript * // Simple confirmation dialog * showModal.create({ * title: "Delete Item", * message: "Are you sure you want to delete this item?", * ok: "Delete", * cancel: "Cancel" * }).onOk(() => { * deleteItem(); * }).onCancel(() => { * console.log('Cancelled'); * }); * * // Prompt dialog * showModal.create({ * title: "Rename", * message: "Enter a new name:", * prompt: { model: "", placeholder: "New name" }, * ok: "Rename", * cancel: true * }).onOk((result) => { * console.log('New name:', result.promptValue); * }); * * // Options selection dialog * showModal.create({ * title: "Select Option", * options: { * type: "radio", * items: ["Option A", "Option B", "Option C"] * }, * ok: "Select", * cancel: true * }).onOk((result) => { * console.log('Selected:', result.optionValue); * }); * * // HTML content (be careful with XSS!) * showModal.create({ * title: "Warning", * message: "Important: This action cannot be undone.", * html: true, * ok: true, * cancel: "Go Back" * }); * ``` */ declare function createDialog(options: DialogOptions): DialogChainObject; interface ShowModalFunction { (component: T & object extends GetModalProps ? T : never, props?: GetModalProps): Promise>; (component: T & object extends GetModalProps ? never : T, props: GetModalProps): Promise>; (component: Component, props?: Record): Promise; (component: ModalController): Promise; /** * Creates and shows a simple dialog without needing a custom component. */ create: typeof createDialog; } export declare const showModal: ShowModalFunction; /** * Closes a modal by its ID with optional removal settings. * * @param {string} id - The unique identifier of the modal to close * @param {Object} [options={}] - Configuration options for closing * @param {boolean} [options.remove=false] - Whether to immediately remove the modal from the stack * @param {number} [options.removeAfter] - Remove the modal after this many milliseconds * @returns {Promise} A promise that resolves when the modal is closed and optionally removed * * @example * ```typescript * // Close a modal immediately * await closeModal('modal-id'); * * // Close and remove immediately * await closeModal('modal-id', { remove: true }); * * // Close and remove after 300ms (for animation) * await closeModal('modal-id', { removeAfter: 300 }); * ``` */ export declare function closeModal(id: string, options?: { remove?: boolean; removeAfter?: number; }): Promise; export {};