import type { ComponentConstructor, ComponentInstance } from "./Component.js"; /** * Async event interface. */ export type AsyncEvent = Event & { respondWith(callback: () => Promise): void; }; /** * Describe the signature of a delegated event callback. * @param event The original DOM event. * @param target The matched delegated element. */ export type DelegatedEventCallback = (event: Event, target?: Node) => unknown; /** * A descriptor for an event delegation. */ export type DelegatedEventDescriptor = AddEventListenerOptions & { callback: DelegatedEventCallback; }; /** * Property configuration for properties accessor. */ export type ListenerConfig = DelegatedEventCallback | DelegatedEventDescriptor; /** * The listener interface. */ type Listener = [string, string | null, DelegatedEventCallback, AddEventListenerOptions?]; /** * Delegate an Event listener. * * @param element The root element for the delegation * @param eventName The event name to listen * @param selector The selector to delegate * @param callback The callback to trigger when an Event matches the delegation * @param options An options object that specifies characteristics about the event listener. @see [MDN]{@link https://developer.mozilla.org/en-US/docs/Web/API/EventTarget/addEventListener} */ export declare const delegateEventListener: (element: Element, eventName: string, selector: string | null, callback: DelegatedEventCallback, options?: AddEventListenerOptions) => void; /** * Remove an Event delegation. * * @param element The root element of the delegation * @param eventName The Event name to undelegate * @param selector The selector to undelegate * @param callback The callback to remove */ export declare const undelegateEventListener: (element: Element, eventName: string, selector: string | null, callback: DelegatedEventCallback) => void; /** * Dispatch a custom Event. * @param element The dispatcher node. * @param event The event to dispatch or the name of the synthetic event to create. * @param detail Detail object of the event. * @param bubbles Should the event bubble. * @param cancelable Should the event be cancelable. * @param composed Is the event composed. * @returns True if either event's cancelable attribute value is false or its preventDefault() method was not invoked, and false otherwise. */ export declare const dispatchEvent: (element: Element, event: Event | string, detail?: CustomEventInit["detail"], bubbles?: boolean, cancelable?: boolean, composed?: boolean) => boolean; /** * Dispatch an async custom Event. * * @param element The dispatcher node. * @param event The event to dispatch or the name of the synthetic event to create. * @param detail Detail object of the event. * @param bubbles Should the event bubble. * @param cancelable Should the event be cancelable. * @param composed Is the event composed. * @returns A promise that resolves when all the async event's promises are resolved. */ export declare const dispatchAsyncEvent: (element: Element, event: Event | string, detail?: CustomEventInit["detail"], bubbles?: boolean, cancelable?: boolean, composed?: boolean) => Promise; /** * Retrieve all listeners descriptors. * @param prototype The component prototype. * @returns A list of listeners. * @throws If the component has not been finalized. */ export declare const getListeners: (prototype: T) => Listener[]; /** * Add an event listener to the prototype. * @param prototype The component prototype. * @param eventName The name of the event to listen. * @param selector The selector event target of the listener. * @param callback The event callback. * @param options The event listener options. */ export declare const defineListener: (prototype: T, eventName: string, selector: string | null, callback: DelegatedEventCallback, options?: AddEventListenerOptions) => void; /** * Retrieve all static listeners from a component constructor. * @param ctr The component constructor. * @yields A tuple containing event name, selector, callback and options. */ export declare function staticListeners< T extends ComponentInstance, C extends ComponentConstructor >(ctr: C): Iterable<[string, string | null, DelegatedEventCallback, AddEventListenerOptions?]>; /** * Retrieve all decorated listeners from a component constructor. * @param ctr The component constructor. * @yields A tuple containing event name, selector, callback and options. */ export declare function decoratedListeners< T extends ComponentInstance, C extends ComponentConstructor >(ctr: C): Iterable<[string, string | null, DelegatedEventCallback, AddEventListenerOptions]>; /** * Retrieve all decorated events from a component constructor. * @param ctr The component constructor. * @yields A tuple containing property key and event name. */ export declare function decoratedEvents< T extends ComponentInstance, C extends ComponentConstructor >(ctr: C): Iterable<[keyof T, string]>; declare function listen(eventName: string, options?: AddEventListenerOptions): any; declare function listen(eventName: string, selector: string, options?: AddEventListenerOptions): any; export { listen }; /** * A type for custom event properties. */ export type EventHandler< T extends Event = Event, OverrideNative extends boolean = false, OverrideOnError extends boolean = false > = ((event: T | (OverrideNative extends true ? Event : never) | (OverrideOnError extends true ? string : never)) => any) | null; /** * Extract event type from handler property. */ export type EventType< T extends ComponentInstance, P extends keyof T, Strict extends boolean = false > = Exclude extends EventHandler ? E | (Strict extends false ? (OverrideNative extends true ? Event : never) | (OverrideOnError extends true ? string : never) : never) : never; /** * Create `on{event}` properties. * @param eventName The name of the event to create a property for. * @returns A decorator for creating event properties. */ export declare function fires(eventName?: string): any;