import * as i0 from '@angular/core';
import { Provider, EnvironmentProviders, NgZone } from '@angular/core';
import { EventManager } from '@angular/platform-browser';
declare const EVENT_PLUGINS: Provider[];
/**
* Provides a set of custom event plugins to Angular's event handling system. This function
* registers custom event plugins like `DebounceEventPlugin` and `DeferEventPlugin`, enhancing
* the capabilities of Angular's native event management. By using `EVENT_MANAGER_PLUGINS`, these
* plugins are integrated into Angular's event system and can be utilized in templates and components
* to handle events with custom behaviors such as debouncing or deferring event execution.
*
* @example
* Registering the event plugins in an Angular module:
* ```ts
* @NgModule({
* imports: [
* BrowserModule,
* BrowserAnimationsModule,
* // other imports...
* ],
* declarations: [AppComponent],
* providers: [
* provideEventPlugins(),
* ],
* bootstrap: [AppComponent],
* })
* export class AppModule {}
* ```
* Assuming `DebounceEventPlugin` modifies event names with a `.debounce` modifier:
* ```html
*
* ```
* Assuming `DeferEventPlugin` modifies event names with a `.defer` modifier:
* ```html
*
* ```
*
* @returns {EnvironmentProviders} - A configuration object for Angular's DI system, to be used with `makeEnvironmentProviders`.
*/
declare function provideEventPlugins(): EnvironmentProviders;
type EventManagerArg = ConstructorParameters[0][0];
type EventManagerPlugin = {
[K in keyof EventManagerArg]: EventManagerArg[K];
};
/**
* An abstract class for implementing custom event plugins in Angular. This class provides
* the core functionality required to create a custom event listener with specific behavior,
* allowing developers to extend Angular's native event handling capabilities.
*
* @example
* Extending EventPlugin to create a custom event plugin:
* ```ts
* @Injectable()
* class CustomEventPlugin extends EventPlugin {
* public readonly modifier = /custom/;
*
* public addEventListener(element: HTMLElement, eventName: string, handler: EventListener): Function {
* // Custom logic for adding an event listener
* }
* }
* ```
*
* ```html
*
* ```
*/
declare abstract class EventPlugin implements EventManagerPlugin {
protected abstract readonly modifier: RegExp;
/**
* The event manager for handling events.
*
* @type {EventManager}
*/
manager: EventManager;
/**
* Adds an event listener to the given element.
*
* @param {HTMLElement} element - The element to attach the event listener to.
* @param {string} eventName - The name of the event.
* @param {EventListener} handler - The event listener function.
* @returns {Function} - A function that can be called to remove the event listener.
*/
abstract addEventListener(element: HTMLElement, eventName: string, handler: EventListener): Function;
/**
* Adds a global event listener.
*
* @returns {Function} - A function that does nothing.
*/
addGlobalEventListener(): Function;
/**
* Checks if the event plugin supports the given event name.
*
* @param {string} eventName - The name of the event.
* @returns {boolean} - `true` if the event plugin supports the event, `false` otherwise.
*/
supports(eventName: string): boolean;
/**
* Gets the NgZone instance from the event manager.
*
* @returns {NgZone} - The NgZone instance.
*/
protected getZone(): NgZone;
/**
* Tears down the event listener.
*
* @param {Function | null} listener - The event listener function.
* @returns {Function} - A function that can be called to clean up the listener.
*/
protected teardown(listener: Function | null): () => void;
}
/**
* A service that extends `EventPlugin` for debouncing events. This service wraps event listeners
* and ensures that they are triggered no more than once per specified delay period. It is
* particularly useful for handling events that fire frequently, such as mouse movements
* or keystrokes, in a performant manner.
*
* The delay period can be specified directly in the event name using the syntax
* `(eventName.debounce.delay)`, where `delay` is the debounce duration in milliseconds.
* If no delay is specified, a default delay of 250 milliseconds is used.
*
* @example
* Provide the `DebounceEventPlugin` in an Angular module:
* ```ts
* @NgModule({
* providers: [
* ...
* provideEventPlugins(),
* ...
* ],
* })
* export class AppModule {}
* ```
*
* In a component template, apply the debounce modifier to an event, specifying a custom delay:
* ```html
*
* ```
* In a component template, apply the debounce modifier with the default delay:
* ```html
*
* ```
*/
declare class DebounceEventPlugin extends EventPlugin {
readonly modifier: RegExp;
addEventListener(element: HTMLElement, eventName: string, originalHandler: EventListener): Function;
private createHandler;
private runOutsideAngular;
static ɵfac: i0.ɵɵFactoryDeclaration;
static ɵprov: i0.ɵɵInjectableDeclaration;
}
/**
* A service that extends `EventPlugin` to allow event handlers to be deferred until the end of the current call stack.
* This can improve performance by avoiding triggering Angular's change detection unnecessarily.
*
* @example
* Provide the `DeferEventPlugin` in an Angular module:
* ```ts
* @NgModule({
* providers: [
* ...
* provideEventPlugins(),
* ...
* ],
* })
* export class AppModule {}
* ```
*
* In your Angular component:
* ```html
*
* ```
*
* The `.defer` modifier in the event name `click.defer` indicates that the event handler should be deferred.
*/
declare class DeferEventPlugin extends EventPlugin {
readonly modifier: RegExp;
addEventListener(element: HTMLElement, eventName: string, originalHandler: EventListener): Function;
private createHandler;
static ɵfac: i0.ɵɵFactoryDeclaration;
static ɵprov: i0.ɵɵInjectableDeclaration;
}
export { DebounceEventPlugin, DeferEventPlugin, EVENT_PLUGINS, EventPlugin, provideEventPlugins };