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