UNPKG

docusaurus-openai-search

Version:

AI-powered search plugin for Docusaurus - extends Algolia search with intelligent keyword generation and RAG-based answers

142 lines (141 loc) 3.69 kB
/** * Cleanup Manager Utility for Docusaurus AI Search * Provides centralized cleanup mechanisms for DOM elements, refs, and resources */ import React from 'react'; export interface CleanupTask { id: string; cleanup: () => void; priority?: number; } export declare class CleanupManager { private static instance; private tasks; private isDestroyed; private constructor(); static getInstance(): CleanupManager; /** * Reset the singleton instance (for testing/cleanup) */ static reset(): void; /** * Register a cleanup task */ register(task: CleanupTask): void; /** * Unregister a cleanup task */ unregister(taskId: string): void; /** * Execute cleanup for a specific task */ cleanupTask(taskId: string): void; /** * Execute all cleanup tasks */ cleanup(): void; /** * Get number of registered tasks */ getTaskCount(): number; /** * Check if cleanup manager is destroyed */ isDestroyed_(): boolean; } /** * DOM Element Cleanup Utilities */ export declare class DOMCleanupUtils { /** * Clear all child nodes from an element */ static clearElement(element: Element | null): void; /** * Remove element from DOM if it exists */ static removeElement(element: Element | null): void; /** * Clear element attributes */ static clearAttributes(element: Element | null, preserveAttributes?: string[]): void; /** * Reset element to initial state */ static resetElement(element: Element | null, preserveAttributes?: string[]): void; } /** * Ref Cleanup Utilities */ export declare class RefCleanupUtils { /** * Clear React ref */ static clearRef<T>(ref: React.RefObject<T>): void; /** * Clear multiple refs of any type */ static clearRefs(...refs: React.RefObject<any>[]): void; /** * Reset ref to initial value */ static resetRef<T>(ref: React.RefObject<T>, initialValue: T): void; } /** * Timer Cleanup Utilities */ export declare class TimerCleanupUtils { private static timers; /** * Register a timer for cleanup */ static registerTimer(timer: NodeJS.Timeout): NodeJS.Timeout; /** * Clear a specific timer */ static clearTimer(timer: NodeJS.Timeout): void; /** * Clear all registered timers */ static clearAllTimers(): void; /** * Create a timeout that auto-registers for cleanup */ static setTimeout(callback: () => void, delay: number): NodeJS.Timeout; /** * Create an interval that auto-registers for cleanup */ static setInterval(callback: () => void, delay: number): NodeJS.Timeout; } /** * Modal-specific cleanup utilities */ export declare class ModalCleanupUtils { /** * Reset modal state */ static resetModalState(setState: React.Dispatch<React.SetStateAction<any>>, initialState: any): void; /** * Clear modal refs and DOM elements */ static clearModalRefs(...refs: React.RefObject<any>[]): void; /** * Complete modal cleanup */ static cleanupModal(options: { refs?: React.RefObject<any>[]; states?: Array<{ setter: React.Dispatch<React.SetStateAction<any>>; initialValue: any; }>; cleanupTasks?: string[]; }): void; } /** * Hook for component cleanup */ export declare function useCleanup(componentId: string): { registerCleanup: (taskId: string, cleanup: () => void, priority?: number) => void; unregisterCleanup: (taskId: string) => void; cleanupComponent: () => void; };