import { type PropertyValues } from '@a11d/lit'; import { LocalStorage } from '@a11d/local-storage'; import { HookSet, RoutableComponent, NavigationStrategy } from '../index.js'; import { type Dialog, DialogActionKey } from './index.js'; /** The parameters of a dialog, passed to its constructor and mapped to its URL if it has a route. */ export type DialogParameters = void | Record; /** The outcome of a dialog action: the result resolving the confirmation, or an `Error` rejecting it. */ export type DialogResult = TResult | Error; /** What a dialog action returns: a `DialogResult`, or a promise of one. */ export type DialogAction = DialogResult | PromiseLike>; /** Where a dialog opens: in place, or popped out into a new tab or window. */ export declare enum DialogConfirmationStrategy { Dialog = 0, Tab = 1, Window = 2 } /** The confirmation strategies that pop a dialog out into a new tab or window. */ export type PopupConfirmationStrategy = Exclude; /** * The base class of a handler for the errors thrown by dialog actions, registered with `DialogComponent.errorHandler()`. * * Declare its key in the global `DialogComponentErrorHandlers` interface for dialog elements to refer to it by `errorHandler`. */ export declare abstract class DialogComponentErrorHandler { protected readonly dialogComponent: DialogComponent; constructor(dialogComponent: DialogComponent); abstract handle(error: Error): void | Promise; } /** * The base class of a dialog, opened by `confirm`, which resolves with the dialog's result once it closes. * * Its template renders a dialog element, such as `lit-dialog`, whose heading defaults to the component's `label` metadata. * An action resolves `confirm` with the value it returns or rejects it with the `Error` it returns, and cancelling rejects it * with a `DialogCancelledError`. An error thrown by an action keeps the dialog open and goes to the dialog element's `errorHandler`. * A dialog with a `@route` can also pop out into a tab or window. */ export declare abstract class DialogComponent extends RoutableComponent { /** Hooks awaited with each dialog before it connects. */ static readonly connectingHooks: HookSet>; private static readonly errorHandlers; private static defaultErrorHandler; /** Marks the decorated element class as a dialog element, which `dialogElement` finds in a dialog component's render root. */ static dialogElement(): (constructor: Constructor) => void; /** Registers the decorated class as the error handler of the key, and as the default one if `isDefault` is set. */ static errorHandler(key: string, isDefault?: boolean): (ErrorHandlerConstructor: Constructor) => void; /** The strategy poppable dialogs open with unless `confirm` is given one, persisted in local storage. */ static readonly poppableConfirmationStrategy: LocalStorage; /** Resolves the element dialogs are appended to, the application's top layer by default. */ static getHost(): Promise; /** The dialog element in the render root; accessing it throws when there is none. */ readonly dialogElement: Dialog & HTMLElement; get primaryActionElement(): HTMLElement | undefined; get secondaryActionElement(): HTMLElement | undefined; get cancellationActionElement(): HTMLElement | undefined; /** The window that opened the window the dialog popped out into, or the current window otherwise. */ get opener(): Window & typeof globalThis; protected handleBeforeUnload(): Promise; protected handleKeyDown(e: KeyboardEvent): Promise; connectedCallback(): Promise; /** Opens the dialog like `confirm`, taking the navigation strategy as the confirmation strategy. */ navigate(strategy?: NavigationStrategy, force?: boolean): Promise; /** Opens the dialog and resolves with its result once it closes; poppable dialogs open with `poppableConfirmationStrategy` by default. */ confirm(strategy?: DialogConfirmationStrategy): Promise; private _confirmationPromiseExecutor?; private confirmAsDialog; private confirmAsPopup; /** Copies the reactive properties of this dialog to its counterpart in the window it pops out into; override it to copy more. */ protected cloned(other: DialogComponent): void; /** Closes the dialog and reopens it in a new tab or window, whose result then settles the original confirmation. */ protected pop(strategy?: Exclude): Promise; /** Closes the dialog, resolving its confirmation with the result, or rejecting it if the result is an `Error`. */ protected close(result: TResult | Error): void; private get open(); private set open(value); /** Whether the dialog can pop out into a tab or window, which requires a route that the current URL does not match. */ get poppable(): boolean; protected firstUpdated(props: PropertyValues): void; /** Returns the result to close the dialog with when its primary action is invoked; throws unless overridden. */ protected primaryAction(): DialogAction; /** Returns the result to close the dialog with when its secondary action is invoked; cancels the dialog by default. */ protected secondaryAction(): DialogAction; /** Returns the result to close the dialog with when it is cancelled, a `DialogCancelledError` by default. */ protected cancellationAction(): DialogAction; /** Runs the action of the key and closes the dialog with its result, unless `manualClose` keeps it open. */ protected readonly handleAction: (actionKey: DialogActionKey) => Promise; /** Passes an error thrown by an action to the dialog element's `errorHandler`, or to the default error handler without one. */ protected handleError(error: Error): void | Promise; } //# sourceMappingURL=DialogComponent.d.ts.map