import { BrowserEventDispatcher } from '@wlindabla/event_dispatcher/browser'; import { DomSwapManagerInterface, SwapStrategyInterface } from './contracts.cjs'; import { SwapContext } from './types.cjs'; /** * @wlindabla/sonata_spa — DomSwapManager * Selects and executes the appropriate SwapStrategy based on the RouteMatch. * Dispatches spa:swap:before (stoppable) and spa:swap:after events. * @author AGBOKOUDJO Franck */ /** * Orchestrates the DOM swap process using the Strategy Pattern. * * On each navigation, DomSwapManager: * 1. Dispatches SpaSwapEvent (spa:swap:before) — STOPPABLE * → Developer can cancel the swap and perform a custom one * 2. Selects the appropriate SwapStrategy based on routeMatch.pageType * → Custom strategies are checked first (registered via addStrategy()) * → Built-in strategies: List, Show/Dashboard, Form, Generic (fallback) * 3. Executes strategy.swap(context) * 4. Dispatches SpaSwapAfterEvent (spa:swap:after) * * Strategy selection order: * 1. Custom strategies (registered by developer) * 2. ListSwapStrategy → 'list' * 3. ShowSwapStrategy → 'show' | 'dashboard' * 4. FormSwapStrategy → 'create' | 'edit' * 5. GenericSwapStrategy → everything else (fallback) * * @example * ```typescript * // Register a custom strategy before boot() * spa.getDomSwapManager().addStrategy(new MyCustomStrategy()); * ``` * @author AGBOKOUDJO Franck */ declare class DomSwapManager implements DomSwapManagerInterface { private readonly dispatcher; /** Custom strategies registered by the developer — checked first */ private readonly customStrategies; /** Built-in strategies — checked after custom ones */ private readonly builtInStrategies; constructor(dispatcher: BrowserEventDispatcher, genericSelectors?: string[]); /** * Select the appropriate strategy and perform the DOM swap. * * @param context - The full swap context with virtualDoc and DOM references */ swap(context: SwapContext): void; /** * Register a custom swap strategy. * Custom strategies are checked before built-in strategies. * Useful for pages with a unique layout outside standard Sonata CRUD. * * @param strategy - The strategy to register * @returns this — for method chaining * * @example * ```typescript * swapManager.addStrategy(new MyDashboardStrategy()); * ``` */ addStrategy(strategy: SwapStrategyInterface): this; /** * Select the first strategy that supports the current page type. * Custom strategies are checked before built-in ones. * GenericSwapStrategy is always the final fallback. * * @param context - The swap context * @returns The matching SwapStrategy */ private selectStrategy; /** * Get all registered strategies (custom + built-in). * Useful for debugging. */ getStrategies(): SwapStrategyInterface[]; } export { DomSwapManager as D };