import { default as EventEmitter } from './EventEmitter'; import { ModalWindow, ModalWindowAny } from './ModalWindow'; import { ExternalStore, ModalComponent, ModalComponentProps, ModalNamedComponents, ModalParams, ModalSnapshot, ModalWindowParams } from './types'; interface ModalControllerEvents { add(modalWindow: ModalWindowAny): void; remove(modalWindow: ModalWindowAny): void; update(): void; } interface ModalControllerConfig { components: Components; defaultParams: Partial; } declare class ModalController = ModalControllerConfig> implements ExternalStore { #private; private config?; protected windows: Set; protected events: EventEmitter; constructor(config?: Config | undefined); protected set active(value: boolean); get active(): boolean; /** * Hides modal without touching any modals. */ hide(): void; /** * Shows modal without touching any modals. */ show(): void; /** * Opens a modal window. Infers props from the component. * * - If the same modal window is already in the queue, it will be ignored. * - If the modal window is weak, it will be unmounted after closing. * - If the modal window is forked, it will be opened over all other modals. * - If the modal window is closable (be default `true`), it will be closed by clicking on the overlay. * - If the modal window is not closable, it will be closed only by calling internal `close` method. * * @param component Modal component. * @param params Modal params. * @returns Modal window and `PromiseLike`. * * @example * await Modal.open(MyModal, { id: 1 }) * console.log("Modal was closed") * * @example * const modal = Modal.open(MyModal, { id: 1 }) * modal.then(() => console.log("Modal was closed")) * * @example * const modal = Modal.open(MyModal, { id: 1 }) * modal.on("close", () => console.log("Modal was closed")) */ open

(component: ModalComponent

, ...[modalParams]: ModalWindowParams

): ModalWindow

; openNamed[Name]>>(componentName: Name, ...[modalParams]: ModalWindowParams

): ModalWindow

; /** * Replaces the last modal window in the queue with a new one. * * If the queue is empty, it will work the same as `open` method. */ replace

(component: ModalComponent

, ...[modalParams]: ModalWindowParams

): ModalWindow

; replaceNamed[Name]>>(componentName: Name, ...[modalParams]: ModalWindowParams

): ModalWindow

; /** * Closes modal by its instance. */ close(modalWindow: ModalWindowAny): void; private remove; /** * Closes all modals, which have this `id`. */ closeById(id: ModalParams["id"]): void; /** * Closes all modals, which have this `component`. Additionally it will seek for `params` if given (compares by `===`). */ closeByComponent

(component: ModalComponent

, params?: P): void; closeByName(componentName: keyof Config["components"]): void; /** * Closes all modals. */ closeAll(): void; private getNamedComponent; /** * Subscribes to `event` with `listener`. * * @example * Modal.on("close", () => { }) * * @returns `unsubscribe` method */ on(event: T, listener: ModalControllerEvents[T]): () => void; /** * Used for container component to get the current state. * * Observes the state and calls the callback on any changes. * * @returns `unsubscribe` method to stop observing. */ subscribe(callback: () => void): () => void; getSnapshot(): ModalSnapshot; private refreshSnapshot; } export { ModalController };