event_dispatcher.d-pVP0-wST.d.ts 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345
  1. /**
  2. * @license Angular v19.2.4
  3. * (c) 2010-2025 Google LLC. https://angular.io/
  4. * License: MIT
  5. */
  6. /**
  7. * Records information about the action that should handle a given `Event`.
  8. */
  9. interface ActionInfo {
  10. name: string;
  11. element: Element;
  12. }
  13. type ActionInfoInternal = [name: string, element: Element];
  14. /**
  15. * Records information for later handling of events. This type is
  16. * shared, and instances of it are passed, between the eventcontract
  17. * and the dispatcher jsbinary. Therefore, the fields of this type are
  18. * referenced by string literals rather than property literals
  19. * throughout the code.
  20. *
  21. * 'targetElement' is the element the action occurred on, 'actionElement'
  22. * is the element that has the jsaction handler.
  23. *
  24. * A null 'actionElement' identifies an EventInfo instance that didn't match a
  25. * jsaction attribute. This allows us to execute global event handlers with the
  26. * appropriate event type (including a11y clicks and custom events).
  27. * The declare portion of this interface creates a set of externs that make sure
  28. * renaming doesn't happen for EventInfo. This is important since EventInfo
  29. * is shared across multiple binaries.
  30. */
  31. declare interface EventInfo {
  32. eventType: string;
  33. event: Event;
  34. targetElement: Element;
  35. /** The element that is the container for this Event. */
  36. eic: Element;
  37. timeStamp: number;
  38. /**
  39. * The action parsed from the JSAction element.
  40. */
  41. eia?: ActionInfoInternal;
  42. /**
  43. * Whether this `Event` is a replay event, meaning no dispatcher was
  44. * installed when this `Event` was originally dispatched.
  45. */
  46. eirp?: boolean;
  47. /**
  48. * Whether this `Event` represents a `keydown` event that should be processed
  49. * as a `click`. Only used when a11y click events is on.
  50. */
  51. eiack?: boolean;
  52. /** Whether action resolution has already run on this `EventInfo`. */
  53. eir?: boolean;
  54. }
  55. /**
  56. * Utility class around an `EventInfo`.
  57. *
  58. * This should be used in compilation units that are less sensitive to code
  59. * size.
  60. */
  61. declare class EventInfoWrapper {
  62. readonly eventInfo: EventInfo;
  63. constructor(eventInfo: EventInfo);
  64. getEventType(): string;
  65. setEventType(eventType: string): void;
  66. getEvent(): Event;
  67. setEvent(event: Event): void;
  68. getTargetElement(): Element;
  69. setTargetElement(targetElement: Element): void;
  70. getContainer(): Element;
  71. setContainer(container: Element): void;
  72. getTimestamp(): number;
  73. setTimestamp(timestamp: number): void;
  74. getAction(): {
  75. name: string;
  76. element: Element;
  77. } | undefined;
  78. setAction(action: ActionInfo | undefined): void;
  79. getIsReplay(): boolean | undefined;
  80. setIsReplay(replay: boolean): void;
  81. getResolved(): boolean | undefined;
  82. setResolved(resolved: boolean): void;
  83. clone(): EventInfoWrapper;
  84. }
  85. declare interface EarlyJsactionDataContainer {
  86. _ejsa?: EarlyJsactionData;
  87. _ejsas?: {
  88. [appId: string]: EarlyJsactionData | undefined;
  89. };
  90. }
  91. declare global {
  92. interface Window {
  93. _ejsa?: EarlyJsactionData;
  94. _ejsas?: {
  95. [appId: string]: EarlyJsactionData | undefined;
  96. };
  97. }
  98. }
  99. /**
  100. * Defines the early jsaction data types.
  101. */
  102. declare interface EarlyJsactionData {
  103. /** List used to keep track of the early JSAction event types. */
  104. et: string[];
  105. /** List used to keep track of the early JSAction capture event types. */
  106. etc: string[];
  107. /** Early JSAction handler for all events. */
  108. h: (event: Event) => void;
  109. /** Dispatcher handler. Initializes to populating `q`. */
  110. d: (eventInfo: EventInfo) => void;
  111. /** List used to push `EventInfo` objects if the dispatcher is not registered. */
  112. q: EventInfo[];
  113. /** Container for listening to events. */
  114. c: HTMLElement;
  115. }
  116. /**
  117. * An `EventContractContainerManager` provides the common interface for managing
  118. * containers.
  119. */
  120. interface EventContractContainerManager {
  121. addEventListener(eventType: string, getHandler: (element: Element) => (event: Event) => void, passive?: boolean): void;
  122. cleanUp(): void;
  123. }
  124. /**
  125. * A class representing a container node and all the event handlers
  126. * installed on it. Used so that handlers can be cleaned up if the
  127. * container is removed from the contract.
  128. */
  129. declare class EventContractContainer implements EventContractContainerManager {
  130. readonly element: Element;
  131. /**
  132. * Array of event handlers and their corresponding event types that are
  133. * installed on this container.
  134. *
  135. */
  136. private handlerInfos;
  137. /**
  138. * @param element The container Element.
  139. */
  140. constructor(element: Element);
  141. /**
  142. * Installs the provided installer on the element owned by this container,
  143. * and maintains a reference to resulting handler in order to remove it
  144. * later if desired.
  145. */
  146. addEventListener(eventType: string, getHandler: (element: Element) => (event: Event) => void, passive?: boolean): void;
  147. /**
  148. * Removes all the handlers installed on this container.
  149. */
  150. cleanUp(): void;
  151. }
  152. /**
  153. * @fileoverview An enum to control who can call certain jsaction APIs.
  154. */
  155. declare enum Restriction {
  156. I_AM_THE_JSACTION_FRAMEWORK = 0
  157. }
  158. /**
  159. * @fileoverview Implements the local event handling contract. This
  160. * allows DOM objects in a container that enters into this contract to
  161. * define event handlers which are executed in a local context.
  162. *
  163. * One EventContract instance can manage the contract for multiple
  164. * containers, which are added using the addContainer() method.
  165. *
  166. * Events can be registered using the addEvent() method.
  167. *
  168. * A Dispatcher is added using the registerDispatcher() method. Until there is
  169. * a dispatcher, events are queued. The idea is that the EventContract
  170. * class is inlined in the HTML of the top level page and instantiated
  171. * right after the start of <body>. The Dispatcher class is contained
  172. * in the external deferred js, and instantiated and registered with
  173. * EventContract when the external javascript in the page loads. The
  174. * external javascript will also register the jsaction handlers, which
  175. * then pick up the queued events at the time of registration.
  176. *
  177. * Since this class is meant to be inlined in the main page HTML, the
  178. * size of the binary compiled from this file MUST be kept as small as
  179. * possible and thus its dependencies to a minimum.
  180. */
  181. /**
  182. * The API of an EventContract that is safe to call from any compilation unit.
  183. */
  184. declare interface UnrenamedEventContract {
  185. ecrd(dispatcher: Dispatcher, restriction: Restriction): void;
  186. }
  187. /** A function that is called to handle events captured by the EventContract. */
  188. type Dispatcher = (eventInfo: EventInfo, globalDispatch?: boolean) => void;
  189. /**
  190. * A function that handles an event dispatched from the browser.
  191. *
  192. * eventType: May differ from `event.type` if JSAction uses a
  193. * short-hand name or is patching over an non-bubbling event with a bubbling
  194. * variant.
  195. * event: The native browser event.
  196. * container: The container for this dispatch.
  197. */
  198. type EventHandler = (eventType: string, event: Event, container: Element) => void;
  199. /**
  200. * EventContract intercepts events in the bubbling phase at the
  201. * boundary of a container element, and maps them to generic actions
  202. * which are specified using the custom jsaction attribute in
  203. * HTML. Behavior of the application is then specified in terms of
  204. * handler for such actions, cf. jsaction.Dispatcher in dispatcher.js.
  205. *
  206. * This has several benefits: (1) No DOM event handlers need to be
  207. * registered on the specific elements in the UI. (2) The set of
  208. * events that the application has to handle can be specified in terms
  209. * of the semantics of the application, rather than in terms of DOM
  210. * events. (3) Invocation of handlers can be delayed and handlers can
  211. * be delay loaded in a generic way.
  212. */
  213. declare class EventContract implements UnrenamedEventContract {
  214. static MOUSE_SPECIAL_SUPPORT: boolean;
  215. private containerManager;
  216. /**
  217. * The DOM events which this contract covers. Used to prevent double
  218. * registration of event types. The value of the map is the
  219. * internally created DOM event handler function that handles the
  220. * DOM events. See addEvent().
  221. *
  222. */
  223. private eventHandlers;
  224. private browserEventTypeToExtraEventTypes;
  225. /**
  226. * The dispatcher function. Events are passed to this function for
  227. * handling once it was set using the registerDispatcher() method. This is
  228. * done because the function is passed from another jsbinary, so passing the
  229. * instance and invoking the method here would require to leave the method
  230. * unobfuscated.
  231. */
  232. private dispatcher;
  233. /**
  234. * The list of suspended `EventInfo` that will be dispatched
  235. * as soon as the `Dispatcher` is registered.
  236. */
  237. private queuedEventInfos;
  238. constructor(containerManager: EventContractContainerManager);
  239. private handleEvent;
  240. /**
  241. * Handle an `EventInfo`.
  242. */
  243. private handleEventInfo;
  244. /**
  245. * Enables jsaction handlers to be called for the event type given by
  246. * name.
  247. *
  248. * If the event is already registered, this does nothing.
  249. *
  250. * @param prefixedEventType If supplied, this event is used in
  251. * the actual browser event registration instead of the name that is
  252. * exposed to jsaction. Use this if you e.g. want users to be able
  253. * to subscribe to jsaction="transitionEnd:foo" while the underlying
  254. * event is webkitTransitionEnd in one browser and mozTransitionEnd
  255. * in another.
  256. *
  257. * @param passive A boolean value that, if `true`, indicates that the event
  258. * handler will never call `preventDefault()`.
  259. */
  260. addEvent(eventType: string, prefixedEventType?: string, passive?: boolean): void;
  261. /**
  262. * Gets the queued early events and replay them using the appropriate handler
  263. * in the provided event contract. Once all the events are replayed, it cleans
  264. * up the early contract.
  265. */
  266. replayEarlyEvents(earlyJsactionData?: EarlyJsactionData | undefined): void;
  267. /**
  268. * Replays all the early `EventInfo` objects, dispatching them through the normal
  269. * `EventContract` flow.
  270. */
  271. replayEarlyEventInfos(earlyEventInfos: EventInfo[]): void;
  272. /**
  273. * Returns all JSAction event types that have been registered for a given
  274. * browser event type.
  275. */
  276. private getEventTypesForBrowserEventType;
  277. /**
  278. * Returns the event handler function for a given event type.
  279. */
  280. handler(eventType: string): EventHandler | undefined;
  281. /**
  282. * Cleans up the event contract. This resets all of the `EventContract`'s
  283. * internal state. Users are responsible for not using this `EventContract`
  284. * after it has been cleaned up.
  285. */
  286. cleanUp(): void;
  287. /**
  288. * Register a dispatcher function. Event info of each event mapped to
  289. * a jsaction is passed for handling to this callback. The queued
  290. * events are passed as well to the dispatcher for later replaying
  291. * once the dispatcher is registered. Clears the event queue to null.
  292. *
  293. * @param dispatcher The dispatcher function.
  294. * @param restriction
  295. */
  296. registerDispatcher(dispatcher: Dispatcher, restriction: Restriction): void;
  297. /**
  298. * Unrenamed alias for registerDispatcher. Necessary for any codebases that
  299. * split the `EventContract` and `Dispatcher` code into different compilation
  300. * units.
  301. */
  302. ecrd(dispatcher: Dispatcher, restriction: Restriction): void;
  303. }
  304. /** An internal symbol used to indicate whether propagation should be stopped or not. */
  305. declare const PROPAGATION_STOPPED_SYMBOL: unique symbol;
  306. /** Extra event phases beyond what the browser provides. */
  307. declare const EventPhase: {
  308. REPLAY: number;
  309. };
  310. declare global {
  311. interface Event {
  312. [PROPAGATION_STOPPED_SYMBOL]?: boolean;
  313. }
  314. }
  315. /**
  316. * A dispatcher that uses browser-based `Event` semantics, for example bubbling, `stopPropagation`,
  317. * `currentTarget`, etc.
  318. */
  319. declare class EventDispatcher {
  320. private readonly dispatchDelegate;
  321. private readonly clickModSupport;
  322. private readonly actionResolver;
  323. private readonly dispatcher;
  324. constructor(dispatchDelegate: (event: Event, actionName: string) => void, clickModSupport?: boolean);
  325. /**
  326. * The entrypoint for the `EventContract` dispatch.
  327. */
  328. dispatch(eventInfo: EventInfo): void;
  329. /** Internal method that does basic disaptching. */
  330. private dispatchToDelegate;
  331. }
  332. /**
  333. * Registers deferred functionality for an EventContract and a Jsaction
  334. * Dispatcher.
  335. */
  336. declare function registerDispatcher(eventContract: UnrenamedEventContract, dispatcher: EventDispatcher): void;
  337. export { type EarlyJsactionDataContainer as E, Restriction as R, type EventInfo as a, EventContractContainer as b, EventDispatcher as c, EventPhase as d, EventInfoWrapper as e, EventContract as f, registerDispatcher as r };