-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathwebapi.event.d.ts
150 lines (144 loc) · 7.6 KB
/
webapi.event.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
//@ts-ignore
declare module globalThis {
/** Evaluation phase of the event flow */
enum Phase {
/** No event is being processed at this time. */
NONE = 0,
/** The event is being propagated through the target's ancestor objects. */
CAPTURING_PHASE = 1,
/** The event has arrived at the event's target. Event listeners registered for this phase are called at this time. If Event.bubbles is false, processing the event is finished after this phase is complete. */
AT_TARGET = 2,
/** The event is propagating back up through the target's ancestors in reverse order, starting with the parent, and eventually reaching the containing Window. This is known as bubbling, and occurs only if Event.bubbles is true. Event listeners registered for this phase are triggered during this process. */
BUBBLING_PHASE = 3
}
interface EventInit {
bubbles?: boolean;
cancelable?: boolean;
composed?: boolean;
}
/**
* The Event interface represents an event which takes place in the DOM.
*
* An event can be triggered by the user action e.g. clicking the mouse button or tapping keyboard, or generated by APIs to represent the progress of an asynchronous task. It can also be triggered programmatically, such as by calling the HTMLElement.click() method of an element, or by defining the event, then sending it to a specified target using EventTarget.dispatchEvent().
*
* There are many types of events, some of which use other interfaces based on the main Event interface. Event itself contains the properties and methods which are common to all events.
*
* Many DOM elements can be set up to accept (or "listen" for) these events, and execute code in response to process (or "handle") them. Event-handlers are usually connected (or "attached") to various HTML elements (such as <button>, <div>, <span>, etc.) using EventTarget.addEventListener(), and this generally replaces using the old HTML event handler attributes. Further, when properly added, such handlers can also be disconnected if needed using removeEventListener().
*/
class Event {
constructor(type: string, eventInitDict?: EventInit);
/**
* Returns true or false depending on how event was initialized. True if event goes through its target's ancestors in reverse tree order, and false otherwise.
*/
get bubbles(): boolean;
cancelBubble: boolean;
/**
* Returns true or false depending on how event was initialized. Its return value does not always carry meaning, but true can indicate that part of the operation during which event was dispatched, can be canceled by invoking the preventDefault() method.
*/
get cancelable(): boolean;
/**
* Returns true or false depending on how event was initialized. True if event invokes listeners past a ShadowRoot node that is the root of its target, and false otherwise.
*/
get composed(): boolean;
/**
* Returns the object whose event listener's callback is currently being invoked.
*/
get currentTarget(): EventTarget;
/**
* Returns true if preventDefault() was invoked successfully to indicate cancelation, and false otherwise.
*/
get defaultPrevented(): boolean;
/**
* Returns the event's phase, which is one of NONE, CAPTURING_PHASE, AT_TARGET, and BUBBLING_PHASE.
*/
get eventPhase(): Phase;
/**
* Returns true if event was dispatched by the user agent, and false otherwise.
*/
get isTrusted(): boolean;
returnValue: boolean;
/**
* Returns the object to which event is dispatched (its target).
*/
get target(): EventTarget;
/**
* Returns the event's timestamp as the number of milliseconds measured relative to the time origin.
*/
get timeStamp(): number;
/**
* Returns the type of event, e.g. "click", "hashchange", or "submit".
*/
get type(): string;
/**
* Returns the invocation target objects of event's path (objects on which listeners will be invoked), except for any nodes in shadow trees of which the shadow root's mode is "closed" that are not reachable from event's currentTarget.
*/
composedPath(): EventTarget[];
initEvent(type: string, bubbles?: boolean, cancelable?: boolean): void;
/**
* If invoked when the cancelable attribute value is true, and while executing a listener for the event with passive set to false, signals to the operation that caused event to be dispatched that it needs to be canceled.
*/
preventDefault(): void;
/**
* Invoking this method prevents event from reaching any registered event listeners after the current one finishes running and, when dispatched in a tree, also prevents event from reaching any other objects.
*/
stopImmediatePropagation(): void;
/**
* When dispatched in a tree, invoking this method prevents event from reaching any objects other than the current object.
*/
stopPropagation(): void;
}
interface ProgressEventInit extends EventInit {
lengthComputable ?: boolean;
loaded ?: number;
total ?: number;
}
/** Events measuring progress of an underlying process, like an HTTP request (for an XMLHttpRequest, or the loading of the underlying resource of an <img>, <audio>, <video>, <style> or <link>). */
class ProgressEvent < T extends EventTarget = EventTarget > extends Event {
get lengthComputable(): boolean;
get loaded(): number;
get target(): T;
get total(): number;
constructor(type: string, eventInitDict?: ProgressEventInit);
}
interface EventListener {
(evt: Event): void;
}
interface EventListenerObject {
handleEvent(evt: Event): void;
}
interface EventListenerOptions {
capture?: boolean;
}
interface AddEventListenerOptions extends EventListenerOptions {
once?: boolean;
passive?: boolean;
}
type EventListenerOrEventListenerObject = EventListener | EventListenerObject;
interface EventListenerRecord extends AddEventListenerOptions {
listener: EventListenerOrEventListenerObject;
}
class EventTarget {
/**
* Appends an event listener for events whose type attribute value is type. The callback argument sets the callback that will be invoked when the event is dispatched.
*
* The options argument sets listener-specific options. For compatibility this can be a boolean, in which case the method behaves exactly as if the value was specified as options's capture.
*
* When set to true, options's capture prevents callback from being invoked when the event's eventPhase attribute value is BUBBLING_PHASE. When false (or not present), callback will not be invoked when event's eventPhase attribute value is CAPTURING_PHASE. Either way, callback will be invoked if event's eventPhase attribute value is AT_TARGET.
*
* When set to true, options's passive indicates that the callback will not cancel the event by invoking preventDefault(). This is used to enable performance optimizations described in § 2.8 Observing event listeners.
*
* When set to true, options's once indicates that the callback will only be invoked once after which the event listener will be removed.
*
* The event listener is appended to target's event listener list and is not appended if it has the same type, callback, and capture.
*/
addEventListener(type: string, listener: EventListenerOrEventListenerObject, options?: boolean | AddEventListenerOptions): void;
/**
* Dispatches a synthetic event event to target and returns true if either event's cancelable attribute value is false or its preventDefault() method was not invoked, and false otherwise.
*/
dispatchEvent(event: Event): boolean;
/**
* Removes the event listener in target's event listener list with the same type, callback, and options.
*/
removeEventListener(type: string, listener: EventListenerOrEventListenerObject, options?: EventListenerOptions | boolean): void;
}
}