/** * @module lib/Dialog * This module contains the Dialog class, which allows you to quickly and easily create modal dialogs - [see the documentation for more info](https://github.com/Sv443-Network/UserUtils/blob/main/docs.md#dialog) */ import { NanoEmitter } from "@sv443-network/coreutils"; export declare const defaultDialogCss: string; /** ID of the last opened (top-most) dialog */ export declare let currentDialogId: string | null; /** IDs of all currently open dialogs, top-most first */ export declare const openDialogs: string[]; /** Default English strings used in the Dialog */ export declare const defaultStrings: { closeDialogTooltip: string; }; /** Options passed to the Dialog constructor */ export interface DialogOptions { /** ID that gets added to child element IDs - has to be unique and conform to HTML ID naming rules! */ id: string; /** Target and max width of the dialog in pixels */ width: number; /** Target and max height of the dialog in pixels */ height: number; /** Whether the dialog should close when the background is clicked - defaults to true */ closeOnBgClick?: boolean; /** Whether the dialog should close when the escape key is pressed - defaults to true */ closeOnEscPress?: boolean; /** Whether the dialog should be destroyed when it's closed - defaults to false */ destroyOnClose?: boolean; /** Whether the dialog should be unmounted when it's closed - defaults to true - superseded by destroyOnClose */ unmountOnClose?: boolean; /** Whether all listeners should be removed when the dialog is destroyed - defaults to true */ removeListenersOnDestroy?: boolean; /** Whether the dialog should have a smaller overall appearance - defaults to false */ small?: boolean; /** Where to align or anchor the dialog vertically - defaults to "center" */ verticalAlign?: "top" | "center" | "bottom"; /** Strings used in the dialog (used for translations) - defaults to the default English strings */ strings?: Partial; /** CSS to apply to the dialog - defaults to the {@linkcode defaultDialogCss} */ dialogCss?: string; /** Called to render the body of the dialog */ renderBody: () => HTMLElement | Promise; /** Called to render the header of the dialog - leave undefined for a blank header */ renderHeader?: () => HTMLElement | Promise; /** Called to render the footer of the dialog - leave undefined for no footer */ renderFooter?: () => HTMLElement | Promise; /** Called to render the close button of the dialog - leave undefined for no close button */ renderCloseBtn?: () => HTMLElement | Promise; } /** Creates and manages a modal dialog element */ export declare class Dialog extends NanoEmitter<{ /** Emitted just **after** the dialog is closed */ close: () => void; /** Emitted just **after** the dialog is opened */ open: () => void; /** Emitted just **after** the dialog contents are rendered */ render: () => void; /** Emitted just **after** the dialog contents are cleared */ clear: () => void; /** Emitted just **after** the dialog is destroyed and **before** all listeners are removed */ destroy: () => void; }> { /** Options passed to the dialog in the constructor */ readonly options: DialogOptions; /** ID that gets added to child element IDs - has to be unique and conform to HTML ID naming rules! */ readonly id: string; /** Strings used in the dialog (used for translations) */ strings: typeof defaultStrings; protected dialogOpen: boolean; protected dialogMounted: boolean; constructor(options: DialogOptions); /** Call after DOMContentLoaded to pre-render the dialog and invisibly mount it in the DOM */ mount(): Promise; /** Closes the dialog and clears all its contents (unmounts elements from the DOM) in preparation for a new rendering call */ unmount(): void; /** Clears the DOM of the dialog and then renders it again */ remount(): Promise; /** * Opens the dialog - also mounts it if it hasn't been mounted yet * Prevents default action and immediate propagation of the passed event */ open(e?: MouseEvent | KeyboardEvent): Promise; /** Closes the dialog - prevents default action and immediate propagation of the passed event */ close(e?: MouseEvent | KeyboardEvent): void; /** Returns true if the dialog is currently open */ isOpen(): boolean; /** Returns true if the dialog is currently mounted */ isMounted(): boolean; /** Clears the DOM of the dialog and removes all event listeners */ destroy(): void; /** Returns the ID of the top-most dialog (the dialog that has been opened last) */ static getCurrentDialogId(): string | null; /** Returns the IDs of all currently open dialogs, top-most first */ static getOpenDialogs(): string[]; protected getString(key: keyof typeof defaultStrings): string; /** Called once to attach all generic event listeners */ protected attachListeners(bgElem: HTMLElement): void; /** * Adds generic, accessible interaction listeners to the passed element. * All listeners have the default behavior prevented and stop propagation (for keyboard events only as long as the captured key is valid). * @param listenerOptions Provide a {@linkcode listenerOptions} object to configure the listeners */ protected onInteraction(elem: TElem, listener: (evt: MouseEvent | KeyboardEvent) => void, listenerOptions?: AddEventListenerOptions & { preventDefault?: boolean; stopPropagation?: boolean; }): void; /** Returns the dialog content element and all its children */ protected getDialogContent(): Promise; }