event_dispatcher.d.d.ts 14 KB

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