import { ErrorInfo, ReactNode } from 'react'; import { ModuleId, VirtualModule, VirtualNode, ModuleBoundaryConfig, ModuleBoundaryState, ModulePerformanceMetrics, ModuleLifecycleState, ModuleLifecycleEvent, HydrationState } from './types'; /** * Manager class for virtual module lifecycle and state. * Implements the Module Boundary pattern with full lifecycle management. */ export declare class VirtualModuleManager { /** Module configuration */ private readonly config; /** Current module state */ private state; /** Lifecycle hooks */ private readonly hooks; /** Event listeners for lifecycle events */ private readonly listeners; /** Child modules */ private readonly children; /** Parent module reference */ private parent; /** Virtual DOM nodes */ private vdom; /** Container element */ private container; /** Portal roots */ private readonly portals; /** Performance measurement marks */ private readonly perfMarks; /** Dependency resolution cache */ private resolvedDependencies; /** * Creates a new VirtualModuleManager. * @param config - Module boundary configuration */ constructor(config: ModuleBoundaryConfig); /** * Gets the module ID. */ get id(): ModuleId; /** * Gets the module name. */ get name(): string; /** * Gets the current lifecycle state. */ get lifecycleState(): ModuleLifecycleState; /** * Gets the current hydration state. */ get hydrationState(): HydrationState; /** * Gets whether the module is mounted. */ get isMounted(): boolean; /** * Gets whether the module is visible. */ get isVisible(): boolean; /** * Gets whether the module has an error. */ get hasError(): boolean; /** * Gets the current error. */ get error(): Error | null; /** * Gets the performance metrics. */ get metrics(): ModulePerformanceMetrics; /** * Gets the module configuration. */ getConfig(): ModuleBoundaryConfig; /** * Gets the current state (immutable snapshot). */ getState(): Readonly; /** * Gets the virtual DOM nodes. */ getVDOM(): ReadonlyArray; /** * Gets child modules. */ getChildren(): ReadonlyMap; /** * Gets the parent module. */ getParent(): VirtualModuleManager | null; /** * Initializes the module. * @throws Error if initialization fails */ initialize(): Promise; /** * Mounts the module to a container element. * @param container - DOM container element */ mount(container: Element): Promise; /** * Unmounts the module. */ unmount(): Promise; /** * Suspends the module (lazy state). */ suspend(): Promise; /** * Disposes the module and releases resources. */ dispose(): Promise; /** * Handles an error in the module. * @param error - The error that occurred * @param errorInfo - React error info (optional) */ handleError(error: Error, errorInfo?: ErrorInfo): void; /** * Clears the error state and allows recovery. */ clearError(): void; /** * Attempts to recover from error state. */ recover(): Promise; /** * Gets resolved dependencies. */ getDependencies(): ReadonlyMap; /** * Registers a child module. * @param child - Child module manager */ registerChild(child: VirtualModuleManager): void; /** * Unregisters a child module. * @param moduleId - ID of child module */ unregisterChild(moduleId: ModuleId): Promise; /** * Gets a child module by ID. * @param moduleId - Child module ID */ getChild(moduleId: ModuleId): VirtualModuleManager | null; /** * Sets content for a named slot. * @param name - Slot name * @param content - React content */ setSlot(name: string, content: ReactNode): void; /** * Gets content from a named slot. * @param name - Slot name */ getSlot(name: string): ReactNode | null; /** * Clears a named slot. * @param name - Slot name */ clearSlot(name: string): void; /** * Sets a module-scoped state value. * @param key - State key * @param value - State value */ setModuleState(key: string, value: T): void; /** * Gets a module-scoped state value. * @param key - State key */ getModuleState(key: string): T | undefined; /** * Clears all module-scoped state. */ clearModuleState(): void; /** * Updates visibility state. * @param isVisible - Whether module is visible */ setVisibility(isVisible: boolean): void; /** * Sets the virtual DOM nodes. * @param nodes - Virtual DOM nodes */ setVDOM(nodes: VirtualNode[]): void; /** * Registers a portal root. * @param name - Portal name * @param element - Portal container element */ registerPortal(name: string, element: Element): void; /** * Gets a portal root. * @param name - Portal name */ getPortal(name: string): Element | null; /** * Unregisters a portal. * @param name - Portal name */ unregisterPortal(name: string): void; /** * Subscribes to a lifecycle event. * @param event - Lifecycle event type * @param handler - Event handler * @returns Unsubscribe function */ subscribe(event: ModuleLifecycleEvent, handler: () => void): () => void; /** * Records a render. * @param renderTime - Time taken to render (ms) */ recordRender(renderTime: number): void; /** * Exports the module to a VirtualModule interface. */ toVirtualModule(): VirtualModule; /** * Validates if a state transition is allowed. * @param from - Current state * @param to - Target state * @returns Whether the transition is valid */ private isValidTransition; /** * Transitions to a new lifecycle state. * @param to - Target state * @throws Error if transition is invalid */ private transitionTo; /** * Resolves module dependencies using topological sort. */ private resolveDependencies; /** * Finds a dependency module. * @param moduleId - ID of the dependency * @returns Module manager or null */ private findDependency; /** * Finds container element for a child module. * @param moduleId - Child module ID */ private findChildContainer; /** * Counts total virtual nodes recursively. */ private countVNodes; /** * Emits a lifecycle event. * @param event - Lifecycle event type */ private emitLifecycleEvent; /** * Marks a performance timestamp. * @param name - Mark name */ private markPerf; /** * Measures time between two marks. * @param startMark - Start mark name * @param endMark - End mark name */ private measurePerf; /** * Updates a performance metric. * @param metric - Metric name * @param value - Metric value */ private updateMetric; } /** * Creates a new virtual module manager. * @param config - Module configuration * @returns New VirtualModuleManager instance * * @example * ```typescript * const module = createVirtualModule({ * id: createModuleId('my-module'), * name: 'My Module', * version: '1.0.0', * lifecycle: { * onAfterMount: () => console.log('Module mounted'), * }, * }); * ``` */ export declare function createVirtualModule(config: ModuleBoundaryConfig): VirtualModuleManager; /** * Creates a module ID with validation. * @param id - Raw ID string * @returns Branded ModuleId * * @example * ```typescript * const moduleId = createValidatedModuleId('feature-dashboard'); * ``` */ export declare function createValidatedModuleId(id: string): ModuleId; /** * Creates a minimal module configuration. * @param id - Module ID * @param name - Module name * @returns Minimal module configuration */ export declare function createMinimalConfig(id: string, name: string): ModuleBoundaryConfig;