import { DrawerPosition } from '../../../Types/DrawerPosition'; import type { IPortalElementProps } from '../../Primitives/Portal/IPortalElementProps'; import type { PortalProjectionElement } from '../../Primitives/Portal/PortalProjectionElement'; import type { IOverlayElement } from '../Abstracts/OverlayElement'; import { DrawerElement } from './DrawerElement'; import type { IDrawerElementProps } from './IDrawerElementProps'; import { type IDrawerBehavior, type IDrawerServiceConfig } from './IDrawerServiceConfig'; /** * Function type for resolving drawer results. * * @public */ export type DrawerResolveFunction = (result: unknown) => void; /** * Represents the `IDrawerRef` interface. * * @public */ export interface IDrawerRef { readonly drawerId: string; readonly drawerElement: DrawerElement; readonly portalProjectionElement: PortalProjectionElement; readonly wrapperElement: HTMLElement; readonly stackLevel: number; readonly computedWidth: string; readonly options?: IDrawerOptions; resolve?: DrawerResolveFunction; } /** * Interface for Drawer options. * * @public */ export interface IDrawerOptions extends Omit, 'position'>, Partial { /** * The position of the drawer. * Supports 'auto' to automatically use the same position as the last opened drawer. * Falls back to default position if no drawer is currently open. */ position?: DrawerPosition | 'auto'; /** * Whether to close the drawer when navigating away. */ navigateToClose?: boolean; } /** * Service for managing the display and behavior of drawer elements. * Provides methods to open and close drawer elements within a portal structure. * Supports extensible behavior pattern for customizing drawer interactions. * * @example * ```typescript * // Configure service globally before use * DrawerService.configure({ * behaviors: [withDrawerStackBehavior({ baseWidth: '80%' })], * closeOnNavigation: true * }); * * // Use the singleton instance * const result = await DrawerService.instance.open('myDrawer', MyDrawerWrapper, options); * ``` * * @public */ export declare class DrawerService { private static _instance; private static _config; private readonly _drawerRefMap; private readonly _drawerStack; private readonly _behaviors; private _portalElement?; /** * Constructs a new instance of the `DrawerService` class. * Use `DrawerService.instance` to access the singleton instance. * * @private */ private constructor(); /** * Returns the singleton instance of the DrawerService. * Creates the instance on first access using the current configuration. * * @public * @readonly */ static get instance(): DrawerService; /** * Returns the current number of open drawers in the stack. * * @public * @readonly */ get stackSize(): number; /** * Returns an array of all drawer references in stack order (oldest first). * * @public * @readonly */ get stack(): ReadonlyArray; /** * Returns the registered behaviors for this service instance. * * @public * @readonly */ get behaviors(): ReadonlyArray; /** * Configures the drawer service globally. * Must be called before accessing the singleton instance. * * @public * @static * @param config - Configuration options for the drawer service. * @returns The DrawerService class for chaining. * @throws Error if called after the instance has already been created. * * @example * ```typescript * DrawerService.configure({ * behaviors: [withDrawerStackBehavior({ baseWidth: '80%' })], * closeOnNavigation: true * }); * ``` */ static configure(config: Partial): typeof DrawerService; /** * Opens a custom wrapper component containing a drawer within a portal. * * @public * @template T - Type of the wrapper component extending HTMLElement. * @template TData - Type of data provided to the wrapper component. * @template TResult - Expected return type of the resolved drawer result. * @param drawerId - Unique identifier for the drawer instance. * @param wrapperClass - Class of the wrapper component containing the drawer. * @param options - Properties for portal and drawer. * @param data - Optional data passed to the wrapper component. * @returns A promise resolving with the drawer result. */ open(drawerId: string, wrapperClass: new (args?: TData) => T, options?: IDrawerOptions, data?: TData): Promise; /** * Closes the drawer in the wrapper component and optionally removes the wrapper from the DOM. * * @public * @template TResult - Type of result returned when the drawer is closed. * @param {string} drawerId - Unique identifier for the drawer instance. * @param {TResult} [result] - Optional result returned when closing the drawer. * @returns {Promise} A promise resolving once the drawer is fully closed. */ close(drawerId: string, result?: TResult): Promise; /** * Closes the topmost drawer in the stack. * * @public * @template TResult - Type of result returned when the drawer is closed. * @param {TResult} [result] - Optional result returned when closing the drawer. * @returns {Promise} A promise resolving once the drawer is fully closed. */ closeTop(result?: TResult): Promise; /** * Closes all open drawers in the stack, from top to bottom. * * @public * @returns {Promise} A promise resolving once all drawers are closed. */ closeAll(): Promise; /** * Returns the drawer element with the specified ID if it exists. * For example, all drawer elements will be automatically registered (by id) when its available in the DOM. * With this method, you can get the drawer element by its ID and call its methods directly. * * @public */ tryGet(drawerId: string): IOverlayElement | undefined; /** * Creates a new drawer reference. * * @private */ private createDrawerRef; /** * Handles cleanup when a drawer is closed (either directly or via DrawerService.close()). * This ensures behaviors are properly detached and state is cleaned up. * * @private * @param drawerId - The ID of the drawer that was closed. */ private handleDrawerClosed; /** * Extends the drawer component by placing it within a portal structure. * * @private * @param portalProps - Properties to set on the portal. * @param element - The element to place within the portal. * @returns The created PortalElement containing the drawer. */ private extendToPortal; /** * Resolves the drawer position, handling 'auto' by returning the last drawer's position. * * @private * @param requestedPosition - The requested position, which may be 'auto'. * @returns The resolved position ('left', 'right', 'top', or 'bottom'). */ private resolvePosition; } //# sourceMappingURL=DrawerService.d.ts.map