/** * Event binding helpers for components. * * Provides a safe, sanitizer-friendly way to wire event handlers from * `render()` output without using inline `on*` attributes or `eval`. * * Handlers are stored in a Map keyed by a generated ID. The `on()` / * `onClick()` / etc. helpers return an attribute string of the form * `data-bq-on-click=""`. A single delegated listener per event type per * component host dispatches events to the registered handler. * * Sanitizer-safe because the actual handler functions are *not* stored as * attribute values, only opaque IDs. * * @module bquery/component */ import type { ComponentScope } from './scope'; type EventHandler = (event: Event) => void; /** * Bind a function to an event. Returns a string of the form * `data-bq-on-=""` suitable for embedding into a template via * the `${...}` interpolation slot. * * Must be called while a component scope is active (typically from `render()`). * The handler is automatically removed when the owning component scope * disconnects, so handlers do not leak across re-renders for the same component. * * @example * ```ts * render({ state }) { * return html` * * `; * } * ``` */ export declare const on: (event: string, handler: EventHandler) => string; /** * @internal */ export declare const cleanupDelegatedHandlers: (root: ParentNode, scope?: ComponentScope) => void; export declare const onClick: (handler: EventHandler) => string; export declare const onInput: (handler: EventHandler) => string; export declare const onChange: (handler: EventHandler) => string; export declare const onSubmit: (handler: EventHandler) => string; /** * Install the delegated event listener machinery on a host element. * * Typically called from `connected()`: * * ```ts * connected() { * bindDelegatedEvents(this); * } * ``` * * Returns a cleanup function which is also registered with the active * component scope (if any) so it runs automatically on disconnect. * * Delegation walks the event path looking for `data-bq-on-=""` * attributes and invokes the matching handler from the internal store. */ export declare const bindDelegatedEvents: (host: HTMLElement) => (() => void); export {}; //# sourceMappingURL=events.d.ts.map