@angular/core 21.0.0-next.0 → 21.0.0-next.10
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/fesm2022/_attribute-chunk.mjs +12 -0
- package/fesm2022/_attribute-chunk.mjs.map +1 -0
- package/fesm2022/_debug_node-chunk.mjs +18469 -0
- package/fesm2022/_debug_node-chunk.mjs.map +1 -0
- package/fesm2022/_effect-chunk.mjs +423 -0
- package/fesm2022/_effect-chunk.mjs.map +1 -0
- package/fesm2022/_effect-chunk2.mjs +2951 -0
- package/fesm2022/_effect-chunk2.mjs.map +1 -0
- package/fesm2022/_not_found-chunk.mjs +39 -0
- package/fesm2022/_not_found-chunk.mjs.map +1 -0
- package/fesm2022/_resource-chunk.mjs +378 -0
- package/fesm2022/_resource-chunk.mjs.map +1 -0
- package/fesm2022/_untracked-chunk.mjs +96 -0
- package/fesm2022/_untracked-chunk.mjs.map +1 -0
- package/fesm2022/_weak_ref-chunk.mjs +10 -0
- package/fesm2022/_weak_ref-chunk.mjs.map +1 -0
- package/fesm2022/core.mjs +2499 -4185
- package/fesm2022/core.mjs.map +1 -1
- package/fesm2022/primitives-di.mjs +23 -0
- package/fesm2022/primitives-di.mjs.map +1 -0
- package/fesm2022/primitives-event-dispatch.mjs +788 -0
- package/fesm2022/primitives-event-dispatch.mjs.map +1 -0
- package/fesm2022/primitives-signals.mjs +187 -0
- package/fesm2022/primitives-signals.mjs.map +1 -0
- package/fesm2022/rxjs-interop.mjs +210 -308
- package/fesm2022/rxjs-interop.mjs.map +1 -1
- package/fesm2022/testing.mjs +2309 -3170
- package/fesm2022/testing.mjs.map +1 -1
- package/package.json +18 -12
- package/resources/best-practices.md +56 -0
- package/schematics/bundles/add-bootstrap-context-to-server-main.cjs +117 -0
- package/schematics/bundles/application-config-core.cjs +84 -0
- package/schematics/bundles/{apply_import_manager-DR9xXCle.cjs → apply_import_manager-1Zs_gpB6.cjs} +4 -5
- package/schematics/bundles/bootstrap-options-migration.cjs +598 -0
- package/schematics/bundles/cleanup-unused-imports.cjs +9 -13
- package/schematics/bundles/common-to-standalone-migration.cjs +381 -0
- package/schematics/bundles/{compiler_host-BXBP7CE2.cjs → compiler_host-DBwYMlTo.cjs} +10 -11
- package/schematics/bundles/control-flow-migration.cjs +122 -119
- package/schematics/bundles/{imports-CIX-JgAN.cjs → imports-DP72APSx.cjs} +6 -1
- package/schematics/bundles/{index-CfTQUOiz.cjs → index-B7I9sIUx.cjs} +36 -39
- package/schematics/bundles/inject-migration.cjs +148 -70
- package/schematics/bundles/leading_space-D9nQ8UQC.cjs +1 -1
- package/schematics/bundles/{migrate_ts_type_references-6NtAj-Wk.cjs → migrate_ts_type_references-UGIUl7En.cjs} +500 -24
- package/schematics/bundles/ng_component_template-Dsuq1Lw7.cjs +185 -0
- package/schematics/bundles/{ng_decorators-B5HCqr20.cjs → ng_decorators-DSFlWYQY.cjs} +2 -2
- package/schematics/bundles/ngclass-to-class-migration.cjs +542 -0
- package/schematics/bundles/ngstyle-to-style-migration.cjs +487 -0
- package/schematics/bundles/nodes-B16H9JUd.cjs +1 -1
- package/schematics/bundles/output-migration.cjs +16 -19
- package/schematics/bundles/parse_html-8VLCL37B.cjs +132 -0
- package/schematics/bundles/{project_paths-DcaODbky.cjs → project_paths-DvD50ouC.cjs} +14 -247
- package/schematics/bundles/project_tsconfig_paths-CDVxT6Ov.cjs +90 -0
- package/schematics/bundles/property_name-BBwFuqMe.cjs +1 -1
- package/schematics/bundles/route-lazy-loading.cjs +54 -26
- package/schematics/bundles/router-current-navigation.cjs +7 -18
- package/schematics/bundles/router-last-successful-navigation.cjs +7 -18
- package/schematics/bundles/router-testing-module-migration.cjs +502 -0
- package/schematics/bundles/self-closing-tags-migration.cjs +17 -216
- package/schematics/bundles/signal-input-migration.cjs +93 -29
- package/schematics/bundles/signal-queries-migration.cjs +22 -25
- package/schematics/bundles/signals.cjs +10 -13
- package/schematics/bundles/standalone-migration.cjs +135 -102
- package/schematics/bundles/{symbol-VPWguRxr.cjs → symbol-BObKoqes.cjs} +3 -2
- package/schematics/collection.json +23 -0
- package/schematics/migrations/common-to-standalone-migration/schema.json +14 -0
- package/schematics/migrations/ngclass-to-class-migration/schema.json +20 -0
- package/schematics/migrations/ngstyle-to-style-migration/schema.json +20 -0
- package/schematics/migrations/router-testing-module-migration/schema.json +14 -0
- package/schematics/migrations.json +16 -2
- package/{api.d.d.ts → types/_api-chunk.d.ts} +9 -6
- package/{chrome_dev_tools_performance.d.d.ts → types/_chrome_dev_tools_performance-chunk.d.ts} +26 -31
- package/{discovery.d.d.ts → types/_discovery-chunk.d.ts} +135 -98
- package/{signal.d.d.ts → types/_effect-chunk.d.ts} +14 -5
- package/{event_dispatcher.d.d.ts → types/_event_dispatcher-chunk.d.ts} +2 -2
- package/{graph.d.d.ts → types/_formatter-chunk.d.ts} +40 -7
- package/{weak_ref.d.d.ts → types/_weak_ref-chunk.d.ts} +2 -2
- package/{index.d.ts → types/core.d.ts} +233 -305
- package/{primitives/di/index.d.ts → types/primitives-di.d.ts} +2 -2
- package/{primitives/event-dispatch/index.d.ts → types/primitives-event-dispatch.d.ts} +4 -4
- package/{primitives/signals/index.d.ts → types/primitives-signals.d.ts} +7 -8
- package/{rxjs-interop/index.d.ts → types/rxjs-interop.d.ts} +8 -6
- package/{testing/index.d.ts → types/testing.d.ts} +7 -7
- package/fesm2022/attribute.mjs +0 -24
- package/fesm2022/attribute.mjs.map +0 -1
- package/fesm2022/debug_node.mjs +0 -31833
- package/fesm2022/debug_node.mjs.map +0 -1
- package/fesm2022/not_found.mjs +0 -56
- package/fesm2022/not_found.mjs.map +0 -1
- package/fesm2022/primitives/di.mjs +0 -23
- package/fesm2022/primitives/di.mjs.map +0 -1
- package/fesm2022/primitives/event-dispatch.mjs +0 -1622
- package/fesm2022/primitives/event-dispatch.mjs.map +0 -1
- package/fesm2022/primitives/signals.mjs +0 -89
- package/fesm2022/primitives/signals.mjs.map +0 -1
- package/fesm2022/resource.mjs +0 -633
- package/fesm2022/resource.mjs.map +0 -1
- package/fesm2022/root_effect_scheduler.mjs +0 -4007
- package/fesm2022/root_effect_scheduler.mjs.map +0 -1
- package/fesm2022/signal.mjs +0 -560
- package/fesm2022/signal.mjs.map +0 -1
- package/fesm2022/untracked.mjs +0 -117
- package/fesm2022/untracked.mjs.map +0 -1
- package/fesm2022/weak_ref.mjs +0 -12
- package/fesm2022/weak_ref.mjs.map +0 -1
- package/schematics/bundles/index-esqfDjNB.cjs +0 -22074
- package/schematics/bundles/project_tsconfig_paths-CS-eSeHC.cjs +0 -51062
|
@@ -1,1622 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* @license Angular v21.0.0-next.0
|
|
3
|
-
* (c) 2010-2025 Google LLC. https://angular.io/
|
|
4
|
-
* License: MIT
|
|
5
|
-
*/
|
|
6
|
-
|
|
7
|
-
import { Attribute } from '../attribute.mjs';
|
|
8
|
-
|
|
9
|
-
/** All properties that are used by jsaction. */
|
|
10
|
-
const Property = {
|
|
11
|
-
/**
|
|
12
|
-
* The parsed value of the jsaction attribute is stored in this
|
|
13
|
-
* property on the DOM node. The parsed value is an Object. The
|
|
14
|
-
* property names of the object are the events; the values are the
|
|
15
|
-
* names of the actions. This property is attached even on nodes
|
|
16
|
-
* that don't have a jsaction attribute as an optimization, because
|
|
17
|
-
* property lookup is faster than attribute access.
|
|
18
|
-
*/
|
|
19
|
-
JSACTION: '__jsaction',
|
|
20
|
-
/**
|
|
21
|
-
* The owner property references an a logical owner for a DOM node. JSAction
|
|
22
|
-
* will follow this reference instead of parentNode when traversing the DOM
|
|
23
|
-
* to find jsaction attributes. This allows overlaying a logical structure
|
|
24
|
-
* over a document where the DOM structure can't reflect that structure.
|
|
25
|
-
*/
|
|
26
|
-
OWNER: '__owner',
|
|
27
|
-
};
|
|
28
|
-
|
|
29
|
-
/**
|
|
30
|
-
* Map from jsaction annotation to a parsed map from event name to action name.
|
|
31
|
-
*/
|
|
32
|
-
const parseCache = {};
|
|
33
|
-
/**
|
|
34
|
-
* Reads the jsaction parser cache from the given DOM Element.
|
|
35
|
-
*/
|
|
36
|
-
function get(element) {
|
|
37
|
-
return element[Property.JSACTION];
|
|
38
|
-
}
|
|
39
|
-
/**
|
|
40
|
-
* Reads the jsaction parser cache for the given DOM element. If no cache is yet present,
|
|
41
|
-
* creates an empty one.
|
|
42
|
-
*/
|
|
43
|
-
function getDefaulted(element) {
|
|
44
|
-
const cache = get(element) ?? {};
|
|
45
|
-
set(element, cache);
|
|
46
|
-
return cache;
|
|
47
|
-
}
|
|
48
|
-
/**
|
|
49
|
-
* Writes the jsaction parser cache to the given DOM Element.
|
|
50
|
-
*/
|
|
51
|
-
function set(element, actionMap) {
|
|
52
|
-
element[Property.JSACTION] = actionMap;
|
|
53
|
-
}
|
|
54
|
-
/**
|
|
55
|
-
* Looks up the parsed action map from the source jsaction attribute value.
|
|
56
|
-
*
|
|
57
|
-
* @param text Unparsed jsaction attribute value.
|
|
58
|
-
* @return Parsed jsaction attribute value, if already present in the cache.
|
|
59
|
-
*/
|
|
60
|
-
function getParsed(text) {
|
|
61
|
-
return parseCache[text];
|
|
62
|
-
}
|
|
63
|
-
/**
|
|
64
|
-
* Inserts the parse result for the given source jsaction value into the cache.
|
|
65
|
-
*
|
|
66
|
-
* @param text Unparsed jsaction attribute value.
|
|
67
|
-
* @param parsed Attribute value parsed into the action map.
|
|
68
|
-
*/
|
|
69
|
-
function setParsed(text, parsed) {
|
|
70
|
-
parseCache[text] = parsed;
|
|
71
|
-
}
|
|
72
|
-
|
|
73
|
-
/*
|
|
74
|
-
* Names of events that are special to jsaction. These are not all
|
|
75
|
-
* event types that are legal to use in either HTML or the addEvent()
|
|
76
|
-
* API, but these are the ones that are treated specially. All other
|
|
77
|
-
* DOM events can be used in either addEvent() or in the value of the
|
|
78
|
-
* jsaction attribute. Beware of browser specific events or events
|
|
79
|
-
* that don't bubble though: If they are not mentioned here, then
|
|
80
|
-
* event contract doesn't work around their peculiarities.
|
|
81
|
-
*/
|
|
82
|
-
const EventType = {
|
|
83
|
-
/**
|
|
84
|
-
* Mouse middle click, introduced in Chrome 55 and not yet supported on
|
|
85
|
-
* other browsers.
|
|
86
|
-
*/
|
|
87
|
-
AUXCLICK: 'auxclick',
|
|
88
|
-
/**
|
|
89
|
-
* The change event fired by browsers when the `value` attribute of input,
|
|
90
|
-
* select, and textarea elements are changed.
|
|
91
|
-
*/
|
|
92
|
-
CHANGE: 'change',
|
|
93
|
-
/**
|
|
94
|
-
* The click event. In addEvent() refers to all click events, in the
|
|
95
|
-
* jsaction attribute it refers to the unmodified click and Enter/Space
|
|
96
|
-
* keypress events. In the latter case, a jsaction click will be triggered,
|
|
97
|
-
* for accessibility reasons. See clickmod and clickonly, below.
|
|
98
|
-
*/
|
|
99
|
-
CLICK: 'click',
|
|
100
|
-
/**
|
|
101
|
-
* Specifies the jsaction for a modified click event (i.e. a mouse
|
|
102
|
-
* click with the modifier key Cmd/Ctrl pressed). This event isn't
|
|
103
|
-
* separately enabled in addEvent(), because in the DOM, it's just a
|
|
104
|
-
* click event.
|
|
105
|
-
*/
|
|
106
|
-
CLICKMOD: 'clickmod',
|
|
107
|
-
/**
|
|
108
|
-
* Specifies the jsaction for a click-only event. Click-only doesn't take
|
|
109
|
-
* into account the case where an element with focus receives an Enter/Space
|
|
110
|
-
* keypress. This event isn't separately enabled in addEvent().
|
|
111
|
-
*/
|
|
112
|
-
CLICKONLY: 'clickonly',
|
|
113
|
-
/**
|
|
114
|
-
* The dblclick event.
|
|
115
|
-
*/
|
|
116
|
-
DBLCLICK: 'dblclick',
|
|
117
|
-
/**
|
|
118
|
-
* Focus doesn't bubble, but you can use it in addEvent() and
|
|
119
|
-
* jsaction anyway. EventContract does the right thing under the
|
|
120
|
-
* hood.
|
|
121
|
-
*/
|
|
122
|
-
FOCUS: 'focus',
|
|
123
|
-
/**
|
|
124
|
-
* This event only exists in IE. For addEvent() and jsaction, use
|
|
125
|
-
* focus instead; EventContract does the right thing even though
|
|
126
|
-
* focus doesn't bubble.
|
|
127
|
-
*/
|
|
128
|
-
FOCUSIN: 'focusin',
|
|
129
|
-
/**
|
|
130
|
-
* Analog to focus.
|
|
131
|
-
*/
|
|
132
|
-
BLUR: 'blur',
|
|
133
|
-
/**
|
|
134
|
-
* Analog to focusin.
|
|
135
|
-
*/
|
|
136
|
-
FOCUSOUT: 'focusout',
|
|
137
|
-
/**
|
|
138
|
-
* Submit doesn't bubble, so it cannot be used with event
|
|
139
|
-
* contract. However, the browser helpfully fires a click event on
|
|
140
|
-
* the submit button of a form (even if the form is not submitted by
|
|
141
|
-
* a click on the submit button). So you should handle click on the
|
|
142
|
-
* submit button instead.
|
|
143
|
-
*/
|
|
144
|
-
SUBMIT: 'submit',
|
|
145
|
-
/**
|
|
146
|
-
* The keydown event. In addEvent() and non-click jsaction it represents the
|
|
147
|
-
* regular DOM keydown event. It represents click actions in non-Gecko
|
|
148
|
-
* browsers.
|
|
149
|
-
*/
|
|
150
|
-
KEYDOWN: 'keydown',
|
|
151
|
-
/**
|
|
152
|
-
* The keypress event. In addEvent() and non-click jsaction it represents the
|
|
153
|
-
* regular DOM keypress event. It represents click actions in Gecko browsers.
|
|
154
|
-
*/
|
|
155
|
-
KEYPRESS: 'keypress',
|
|
156
|
-
/**
|
|
157
|
-
* The keyup event. In addEvent() and non-click jsaction it represents the
|
|
158
|
-
* regular DOM keyup event. It represents click actions in non-Gecko
|
|
159
|
-
* browsers.
|
|
160
|
-
*/
|
|
161
|
-
KEYUP: 'keyup',
|
|
162
|
-
/**
|
|
163
|
-
* The mouseup event. Can either be used directly or used implicitly to
|
|
164
|
-
* capture mouseup events. In addEvent(), it represents a regular DOM
|
|
165
|
-
* mouseup event.
|
|
166
|
-
*/
|
|
167
|
-
MOUSEUP: 'mouseup',
|
|
168
|
-
/**
|
|
169
|
-
* The mousedown event. Can either be used directly or used implicitly to
|
|
170
|
-
* capture mouseenter events. In addEvent(), it represents a regular DOM
|
|
171
|
-
* mouseover event.
|
|
172
|
-
*/
|
|
173
|
-
MOUSEDOWN: 'mousedown',
|
|
174
|
-
/**
|
|
175
|
-
* The mouseover event. Can either be used directly or used implicitly to
|
|
176
|
-
* capture mouseenter events. In addEvent(), it represents a regular DOM
|
|
177
|
-
* mouseover event.
|
|
178
|
-
*/
|
|
179
|
-
MOUSEOVER: 'mouseover',
|
|
180
|
-
/**
|
|
181
|
-
* The mouseout event. Can either be used directly or used implicitly to
|
|
182
|
-
* capture mouseover events. In addEvent(), it represents a regular DOM
|
|
183
|
-
* mouseout event.
|
|
184
|
-
*/
|
|
185
|
-
MOUSEOUT: 'mouseout',
|
|
186
|
-
/**
|
|
187
|
-
* The mouseenter event. Does not bubble and fires individually on each
|
|
188
|
-
* element being entered within a DOM tree.
|
|
189
|
-
*/
|
|
190
|
-
MOUSEENTER: 'mouseenter',
|
|
191
|
-
/**
|
|
192
|
-
* The mouseleave event. Does not bubble and fires individually on each
|
|
193
|
-
* element being entered within a DOM tree.
|
|
194
|
-
*/
|
|
195
|
-
MOUSELEAVE: 'mouseleave',
|
|
196
|
-
/**
|
|
197
|
-
* The mousemove event.
|
|
198
|
-
*/
|
|
199
|
-
MOUSEMOVE: 'mousemove',
|
|
200
|
-
/**
|
|
201
|
-
* The pointerup event. Can either be used directly or used implicitly to
|
|
202
|
-
* capture pointerup events. In addEvent(), it represents a regular DOM
|
|
203
|
-
* pointerup event.
|
|
204
|
-
*/
|
|
205
|
-
POINTERUP: 'pointerup',
|
|
206
|
-
/**
|
|
207
|
-
* The pointerdown event. Can either be used directly or used implicitly to
|
|
208
|
-
* capture pointerenter events. In addEvent(), it represents a regular DOM
|
|
209
|
-
* mouseover event.
|
|
210
|
-
*/
|
|
211
|
-
POINTERDOWN: 'pointerdown',
|
|
212
|
-
/**
|
|
213
|
-
* The pointerover event. Can either be used directly or used implicitly to
|
|
214
|
-
* capture pointerenter events. In addEvent(), it represents a regular DOM
|
|
215
|
-
* pointerover event.
|
|
216
|
-
*/
|
|
217
|
-
POINTEROVER: 'pointerover',
|
|
218
|
-
/**
|
|
219
|
-
* The pointerout event. Can either be used directly or used implicitly to
|
|
220
|
-
* capture pointerover events. In addEvent(), it represents a regular DOM
|
|
221
|
-
* pointerout event.
|
|
222
|
-
*/
|
|
223
|
-
POINTEROUT: 'pointerout',
|
|
224
|
-
/**
|
|
225
|
-
* The pointerenter event. Does not bubble and fires individually on each
|
|
226
|
-
* element being entered within a DOM tree.
|
|
227
|
-
*/
|
|
228
|
-
POINTERENTER: 'pointerenter',
|
|
229
|
-
/**
|
|
230
|
-
* The pointerleave event. Does not bubble and fires individually on each
|
|
231
|
-
* element being entered within a DOM tree.
|
|
232
|
-
*/
|
|
233
|
-
POINTERLEAVE: 'pointerleave',
|
|
234
|
-
/**
|
|
235
|
-
* The pointermove event.
|
|
236
|
-
*/
|
|
237
|
-
POINTERMOVE: 'pointermove',
|
|
238
|
-
/**
|
|
239
|
-
* The pointercancel event.
|
|
240
|
-
*/
|
|
241
|
-
POINTERCANCEL: 'pointercancel',
|
|
242
|
-
/**
|
|
243
|
-
* The gotpointercapture event is fired when
|
|
244
|
-
* Element.setPointerCapture(pointerId) is called on a mouse input, or
|
|
245
|
-
* implicitly when a touch input begins.
|
|
246
|
-
*/
|
|
247
|
-
GOTPOINTERCAPTURE: 'gotpointercapture',
|
|
248
|
-
/**
|
|
249
|
-
* The lostpointercapture event is fired when
|
|
250
|
-
* Element.releasePointerCapture(pointerId) is called, or implicitly after a
|
|
251
|
-
* touch input ends.
|
|
252
|
-
*/
|
|
253
|
-
LOSTPOINTERCAPTURE: 'lostpointercapture',
|
|
254
|
-
/**
|
|
255
|
-
* The error event. The error event doesn't bubble, but you can use it in
|
|
256
|
-
* addEvent() and jsaction anyway. EventContract does the right thing under
|
|
257
|
-
* the hood (except in IE8 which does not use error events).
|
|
258
|
-
*/
|
|
259
|
-
ERROR: 'error',
|
|
260
|
-
/**
|
|
261
|
-
* The load event. The load event doesn't bubble, but you can use it in
|
|
262
|
-
* addEvent() and jsaction anyway. EventContract does the right thing
|
|
263
|
-
* under the hood.
|
|
264
|
-
*/
|
|
265
|
-
LOAD: 'load',
|
|
266
|
-
/**
|
|
267
|
-
* The unload event.
|
|
268
|
-
*/
|
|
269
|
-
UNLOAD: 'unload',
|
|
270
|
-
/**
|
|
271
|
-
* The touchstart event. Bubbles, will only ever fire in browsers with
|
|
272
|
-
* touch support.
|
|
273
|
-
*/
|
|
274
|
-
TOUCHSTART: 'touchstart',
|
|
275
|
-
/**
|
|
276
|
-
* The touchend event. Bubbles, will only ever fire in browsers with
|
|
277
|
-
* touch support.
|
|
278
|
-
*/
|
|
279
|
-
TOUCHEND: 'touchend',
|
|
280
|
-
/**
|
|
281
|
-
* The touchmove event. Bubbles, will only ever fire in browsers with
|
|
282
|
-
* touch support.
|
|
283
|
-
*/
|
|
284
|
-
TOUCHMOVE: 'touchmove',
|
|
285
|
-
/**
|
|
286
|
-
* The input event.
|
|
287
|
-
*/
|
|
288
|
-
INPUT: 'input',
|
|
289
|
-
/**
|
|
290
|
-
* The scroll event.
|
|
291
|
-
*/
|
|
292
|
-
SCROLL: 'scroll',
|
|
293
|
-
/**
|
|
294
|
-
* The toggle event. The toggle event doesn't bubble, but you can use it in
|
|
295
|
-
* addEvent() and jsaction anyway. EventContract does the right thing
|
|
296
|
-
* under the hood.
|
|
297
|
-
*/
|
|
298
|
-
TOGGLE: 'toggle',
|
|
299
|
-
/**
|
|
300
|
-
* A custom event. The actual custom event type is declared as the 'type'
|
|
301
|
-
* field in the event details. Supported in Firefox 6+, IE 9+, and all Chrome
|
|
302
|
-
* versions.
|
|
303
|
-
*
|
|
304
|
-
* This is an internal name. Users should use jsaction's fireCustomEvent to
|
|
305
|
-
* fire custom events instead of relying on this type to create them.
|
|
306
|
-
*/
|
|
307
|
-
CUSTOM: '_custom',
|
|
308
|
-
};
|
|
309
|
-
/** All event types that do not bubble or capture and need a polyfill. */
|
|
310
|
-
const MOUSE_SPECIAL_EVENT_TYPES = [
|
|
311
|
-
EventType.MOUSEENTER,
|
|
312
|
-
EventType.MOUSELEAVE,
|
|
313
|
-
'pointerenter',
|
|
314
|
-
'pointerleave',
|
|
315
|
-
];
|
|
316
|
-
/** All event types that are registered in the bubble phase. */
|
|
317
|
-
const BUBBLE_EVENT_TYPES = [
|
|
318
|
-
EventType.CLICK,
|
|
319
|
-
EventType.DBLCLICK,
|
|
320
|
-
EventType.FOCUSIN,
|
|
321
|
-
EventType.FOCUSOUT,
|
|
322
|
-
EventType.KEYDOWN,
|
|
323
|
-
EventType.KEYUP,
|
|
324
|
-
EventType.KEYPRESS,
|
|
325
|
-
EventType.MOUSEOVER,
|
|
326
|
-
EventType.MOUSEOUT,
|
|
327
|
-
EventType.SUBMIT,
|
|
328
|
-
EventType.TOUCHSTART,
|
|
329
|
-
EventType.TOUCHEND,
|
|
330
|
-
EventType.TOUCHMOVE,
|
|
331
|
-
'touchcancel',
|
|
332
|
-
'auxclick',
|
|
333
|
-
'change',
|
|
334
|
-
'compositionstart',
|
|
335
|
-
'compositionupdate',
|
|
336
|
-
'compositionend',
|
|
337
|
-
'beforeinput',
|
|
338
|
-
'input',
|
|
339
|
-
'select',
|
|
340
|
-
'copy',
|
|
341
|
-
'cut',
|
|
342
|
-
'paste',
|
|
343
|
-
'mousedown',
|
|
344
|
-
'mouseup',
|
|
345
|
-
'wheel',
|
|
346
|
-
'contextmenu',
|
|
347
|
-
'dragover',
|
|
348
|
-
'dragenter',
|
|
349
|
-
'dragleave',
|
|
350
|
-
'drop',
|
|
351
|
-
'dragstart',
|
|
352
|
-
'dragend',
|
|
353
|
-
'pointerdown',
|
|
354
|
-
'pointermove',
|
|
355
|
-
'pointerup',
|
|
356
|
-
'pointercancel',
|
|
357
|
-
'pointerover',
|
|
358
|
-
'pointerout',
|
|
359
|
-
'gotpointercapture',
|
|
360
|
-
'lostpointercapture',
|
|
361
|
-
// Video events.
|
|
362
|
-
'ended',
|
|
363
|
-
'loadedmetadata',
|
|
364
|
-
// Page visibility events.
|
|
365
|
-
'pagehide',
|
|
366
|
-
'pageshow',
|
|
367
|
-
'visibilitychange',
|
|
368
|
-
// Content visibility events.
|
|
369
|
-
'beforematch',
|
|
370
|
-
];
|
|
371
|
-
/** All event types that are registered in the capture phase. */
|
|
372
|
-
const CAPTURE_EVENT_TYPES = [
|
|
373
|
-
EventType.FOCUS,
|
|
374
|
-
EventType.BLUR,
|
|
375
|
-
EventType.ERROR,
|
|
376
|
-
EventType.LOAD,
|
|
377
|
-
EventType.TOGGLE,
|
|
378
|
-
];
|
|
379
|
-
/**
|
|
380
|
-
* Whether or not an event type should be registered in the capture phase.
|
|
381
|
-
* @param eventType
|
|
382
|
-
* @returns bool
|
|
383
|
-
*/
|
|
384
|
-
const isCaptureEventType = (eventType) => CAPTURE_EVENT_TYPES.indexOf(eventType) >= 0;
|
|
385
|
-
/** All event types that are registered early. */
|
|
386
|
-
const EARLY_EVENT_TYPES = BUBBLE_EVENT_TYPES.concat(CAPTURE_EVENT_TYPES);
|
|
387
|
-
/**
|
|
388
|
-
* Whether or not an event type is registered in the early contract.
|
|
389
|
-
*/
|
|
390
|
-
const isEarlyEventType = (eventType) => EARLY_EVENT_TYPES.indexOf(eventType) >= 0;
|
|
391
|
-
|
|
392
|
-
/**
|
|
393
|
-
* Gets a browser event type, if it would differ from the JSAction event type.
|
|
394
|
-
*/
|
|
395
|
-
function getBrowserEventType(eventType) {
|
|
396
|
-
// Mouseenter and mouseleave events are not handled directly because they
|
|
397
|
-
// are not available everywhere. In browsers where they are available, they
|
|
398
|
-
// don't bubble and aren't visible at the container boundary. Instead, we
|
|
399
|
-
// synthesize the mouseenter and mouseleave events from mouseover and
|
|
400
|
-
// mouseout events, respectively. Cf. eventcontract.js.
|
|
401
|
-
if (eventType === EventType.MOUSEENTER) {
|
|
402
|
-
return EventType.MOUSEOVER;
|
|
403
|
-
}
|
|
404
|
-
else if (eventType === EventType.MOUSELEAVE) {
|
|
405
|
-
return EventType.MOUSEOUT;
|
|
406
|
-
}
|
|
407
|
-
else if (eventType === EventType.POINTERENTER) {
|
|
408
|
-
return EventType.POINTEROVER;
|
|
409
|
-
}
|
|
410
|
-
else if (eventType === EventType.POINTERLEAVE) {
|
|
411
|
-
return EventType.POINTEROUT;
|
|
412
|
-
}
|
|
413
|
-
return eventType;
|
|
414
|
-
}
|
|
415
|
-
/**
|
|
416
|
-
* Registers the event handler function with the given DOM element for
|
|
417
|
-
* the given event type.
|
|
418
|
-
*
|
|
419
|
-
* @param element The element.
|
|
420
|
-
* @param eventType The event type.
|
|
421
|
-
* @param handler The handler function to install.
|
|
422
|
-
* @param passive A boolean value that, if `true`, indicates that the function
|
|
423
|
-
* specified by `handler` will never call `preventDefault()`.
|
|
424
|
-
* @return Information needed to uninstall the event handler eventually.
|
|
425
|
-
*/
|
|
426
|
-
function addEventListener(element, eventType, handler, passive) {
|
|
427
|
-
// All event handlers are registered in the bubbling
|
|
428
|
-
// phase.
|
|
429
|
-
//
|
|
430
|
-
// All browsers support focus and blur, but these events only are propagated
|
|
431
|
-
// in the capture phase. Very legacy browsers do not support focusin or
|
|
432
|
-
// focusout.
|
|
433
|
-
//
|
|
434
|
-
// It would be a bad idea to register all event handlers in the
|
|
435
|
-
// capture phase because then regular onclick handlers would not be
|
|
436
|
-
// executed at all on events that trigger a jsaction. That's not
|
|
437
|
-
// entirely what we want, at least for now.
|
|
438
|
-
//
|
|
439
|
-
// Error and load events (i.e. on images) do not bubble so they are also
|
|
440
|
-
// handled in the capture phase.
|
|
441
|
-
let capture = false;
|
|
442
|
-
if (isCaptureEventType(eventType)) {
|
|
443
|
-
capture = true;
|
|
444
|
-
}
|
|
445
|
-
const options = typeof passive === 'boolean' ? { capture, passive } : capture;
|
|
446
|
-
element.addEventListener(eventType, handler, options);
|
|
447
|
-
return { eventType, handler, capture, passive };
|
|
448
|
-
}
|
|
449
|
-
/**
|
|
450
|
-
* Removes the event handler for the given event from the element.
|
|
451
|
-
* the given event type.
|
|
452
|
-
*
|
|
453
|
-
* @param element The element.
|
|
454
|
-
* @param info The information needed to deregister the handler, as returned by
|
|
455
|
-
* addEventListener(), above.
|
|
456
|
-
*/
|
|
457
|
-
function removeEventListener(element, info) {
|
|
458
|
-
if (element.removeEventListener) {
|
|
459
|
-
// It's worth noting that some browser releases have been inconsistent on this, and unless
|
|
460
|
-
// you have specific reasons otherwise, it's probably wise to use the same values used for
|
|
461
|
-
// the call to addEventListener() when calling removeEventListener().
|
|
462
|
-
const options = typeof info.passive === 'boolean' ? { capture: info.capture } : info.capture;
|
|
463
|
-
element.removeEventListener(info.eventType, info.handler, options);
|
|
464
|
-
// `detachEvent` is an old DOM API.
|
|
465
|
-
}
|
|
466
|
-
else if (element.detachEvent) {
|
|
467
|
-
// `detachEvent` is an old DOM API.
|
|
468
|
-
element.detachEvent(`on${info.eventType}`, info.handler);
|
|
469
|
-
}
|
|
470
|
-
}
|
|
471
|
-
/**
|
|
472
|
-
* Prevents the default action of an event.
|
|
473
|
-
* @param e The event to prevent the default action for.
|
|
474
|
-
*/
|
|
475
|
-
function preventDefault(e) {
|
|
476
|
-
e.preventDefault ? e.preventDefault() : (e.returnValue = false);
|
|
477
|
-
}
|
|
478
|
-
/**
|
|
479
|
-
* Whether we are on a Mac. Not pulling in useragent just for this.
|
|
480
|
-
*/
|
|
481
|
-
let isMac = typeof navigator !== 'undefined' && /Macintosh/.test(navigator.userAgent);
|
|
482
|
-
/**
|
|
483
|
-
* Determines and returns whether the given event (which is assumed to be a
|
|
484
|
-
* click event) is a middle click.
|
|
485
|
-
* NOTE: There is not a consistent way to identify middle click
|
|
486
|
-
* http://www.unixpapa.com/js/mouse.html
|
|
487
|
-
*/
|
|
488
|
-
function isMiddleClick(e) {
|
|
489
|
-
return (
|
|
490
|
-
// `which` is an old DOM API.
|
|
491
|
-
e.which === 2 ||
|
|
492
|
-
// `which` is an old DOM API.
|
|
493
|
-
(e.which == null &&
|
|
494
|
-
// `button` is an old DOM API.
|
|
495
|
-
e.button === 4) // middle click for IE
|
|
496
|
-
);
|
|
497
|
-
}
|
|
498
|
-
/**
|
|
499
|
-
* Determines and returns whether the given event (which is assumed
|
|
500
|
-
* to be a click event) is modified. A middle click is considered a modified
|
|
501
|
-
* click to retain the default browser action, which opens a link in a new tab.
|
|
502
|
-
* @param e The event.
|
|
503
|
-
* @return Whether the given event is modified.
|
|
504
|
-
*/
|
|
505
|
-
function isModifiedClickEvent(e) {
|
|
506
|
-
return (
|
|
507
|
-
// `metaKey` is an old DOM API.
|
|
508
|
-
(isMac && e.metaKey) ||
|
|
509
|
-
// `ctrlKey` is an old DOM API.
|
|
510
|
-
(!isMac && e.ctrlKey) ||
|
|
511
|
-
isMiddleClick(e) ||
|
|
512
|
-
// `shiftKey` is an old DOM API.
|
|
513
|
-
e.shiftKey);
|
|
514
|
-
}
|
|
515
|
-
/**
|
|
516
|
-
* Determines whether the event corresponds to a non-bubbling mouse
|
|
517
|
-
* event type (mouseenter, mouseleave, pointerenter, and pointerleave).
|
|
518
|
-
*
|
|
519
|
-
* During mouseover (mouseenter) and pointerover (pointerenter), the
|
|
520
|
-
* relatedTarget is the element being entered from. During mouseout (mouseleave)
|
|
521
|
-
* and pointerout (pointerleave), the relatedTarget is the element being exited
|
|
522
|
-
* to.
|
|
523
|
-
*
|
|
524
|
-
* In both cases, if relatedTarget is outside target, then the corresponding
|
|
525
|
-
* special event has occurred, otherwise it hasn't.
|
|
526
|
-
*
|
|
527
|
-
* @param e The mouseover/mouseout event.
|
|
528
|
-
* @param type The type of the mouse special event.
|
|
529
|
-
* @param element The element on which the jsaction for the
|
|
530
|
-
* mouseenter/mouseleave event is defined.
|
|
531
|
-
* @return True if the event is a mouseenter/mouseleave event.
|
|
532
|
-
*/
|
|
533
|
-
function isMouseSpecialEvent(e, type, element) {
|
|
534
|
-
// `relatedTarget` is an old DOM API.
|
|
535
|
-
const related = e.relatedTarget;
|
|
536
|
-
return (((e.type === EventType.MOUSEOVER && type === EventType.MOUSEENTER) ||
|
|
537
|
-
(e.type === EventType.MOUSEOUT && type === EventType.MOUSELEAVE) ||
|
|
538
|
-
(e.type === EventType.POINTEROVER && type === EventType.POINTERENTER) ||
|
|
539
|
-
(e.type === EventType.POINTEROUT && type === EventType.POINTERLEAVE)) &&
|
|
540
|
-
(!related || (related !== element && !element.contains(related))));
|
|
541
|
-
}
|
|
542
|
-
/**
|
|
543
|
-
* Creates a new EventLike object for a mouseenter/mouseleave event that's
|
|
544
|
-
* derived from the original corresponding mouseover/mouseout event.
|
|
545
|
-
* @param e The event.
|
|
546
|
-
* @param target The element on which the jsaction for the mouseenter/mouseleave
|
|
547
|
-
* event is defined.
|
|
548
|
-
* @return A modified event-like object copied from the event object passed into
|
|
549
|
-
* this function.
|
|
550
|
-
*/
|
|
551
|
-
function createMouseSpecialEvent(e, target) {
|
|
552
|
-
// We have to create a copy of the event object because we need to mutate
|
|
553
|
-
// its fields. We do this for the special mouse events because the event
|
|
554
|
-
// target needs to be retargeted to the action element rather than the real
|
|
555
|
-
// element (since we are simulating the special mouse events with mouseover/
|
|
556
|
-
// mouseout).
|
|
557
|
-
//
|
|
558
|
-
// Since we're making a copy anyways, we might as well attempt to convert
|
|
559
|
-
// this event into a pseudo-real mouseenter/mouseleave event by adjusting
|
|
560
|
-
// its type.
|
|
561
|
-
//
|
|
562
|
-
const copy = {};
|
|
563
|
-
for (const property in e) {
|
|
564
|
-
if (property === 'srcElement' || property === 'target') {
|
|
565
|
-
continue;
|
|
566
|
-
}
|
|
567
|
-
const key = property;
|
|
568
|
-
// Making a copy requires iterating through all properties of `Event`.
|
|
569
|
-
const value = e[key];
|
|
570
|
-
if (typeof value === 'function') {
|
|
571
|
-
continue;
|
|
572
|
-
}
|
|
573
|
-
// Value should be the expected type, but the value of `key` is not known
|
|
574
|
-
// statically.
|
|
575
|
-
copy[key] = value;
|
|
576
|
-
}
|
|
577
|
-
if (e.type === EventType.MOUSEOVER) {
|
|
578
|
-
copy['type'] = EventType.MOUSEENTER;
|
|
579
|
-
}
|
|
580
|
-
else if (e.type === EventType.MOUSEOUT) {
|
|
581
|
-
copy['type'] = EventType.MOUSELEAVE;
|
|
582
|
-
}
|
|
583
|
-
else if (e.type === EventType.POINTEROVER) {
|
|
584
|
-
copy['type'] = EventType.POINTERENTER;
|
|
585
|
-
}
|
|
586
|
-
else {
|
|
587
|
-
copy['type'] = EventType.POINTERLEAVE;
|
|
588
|
-
}
|
|
589
|
-
copy['target'] = copy['srcElement'] = target;
|
|
590
|
-
copy['bubbles'] = false;
|
|
591
|
-
copy['_originalEvent'] = e;
|
|
592
|
-
return copy;
|
|
593
|
-
}
|
|
594
|
-
|
|
595
|
-
/**
|
|
596
|
-
* Whether the user agent is running on iOS.
|
|
597
|
-
*/
|
|
598
|
-
const isIos = typeof navigator !== 'undefined' && /iPhone|iPad|iPod/.test(navigator.userAgent);
|
|
599
|
-
/**
|
|
600
|
-
* A class representing a container node and all the event handlers
|
|
601
|
-
* installed on it. Used so that handlers can be cleaned up if the
|
|
602
|
-
* container is removed from the contract.
|
|
603
|
-
*/
|
|
604
|
-
class EventContractContainer {
|
|
605
|
-
element;
|
|
606
|
-
/**
|
|
607
|
-
* Array of event handlers and their corresponding event types that are
|
|
608
|
-
* installed on this container.
|
|
609
|
-
*
|
|
610
|
-
*/
|
|
611
|
-
handlerInfos = [];
|
|
612
|
-
/**
|
|
613
|
-
* @param element The container Element.
|
|
614
|
-
*/
|
|
615
|
-
constructor(element) {
|
|
616
|
-
this.element = element;
|
|
617
|
-
}
|
|
618
|
-
/**
|
|
619
|
-
* Installs the provided installer on the element owned by this container,
|
|
620
|
-
* and maintains a reference to resulting handler in order to remove it
|
|
621
|
-
* later if desired.
|
|
622
|
-
*/
|
|
623
|
-
addEventListener(eventType, getHandler, passive) {
|
|
624
|
-
// In iOS, event bubbling doesn't happen automatically in any DOM element,
|
|
625
|
-
// unless it has an onclick attribute or DOM event handler attached to it.
|
|
626
|
-
// This breaks JsAction in some cases. See "Making Elements Clickable"
|
|
627
|
-
// section at http://goo.gl/2VoGnB.
|
|
628
|
-
//
|
|
629
|
-
// A workaround for this issue is to change the CSS cursor style to 'pointer'
|
|
630
|
-
// for the container element, which magically turns on event bubbling. This
|
|
631
|
-
// solution is described in the comments section at http://goo.gl/6pEO1z.
|
|
632
|
-
//
|
|
633
|
-
// We use a navigator.userAgent check here as this problem is present both
|
|
634
|
-
// on Mobile Safari and thin WebKit wrappers, such as Chrome for iOS.
|
|
635
|
-
if (isIos) {
|
|
636
|
-
this.element.style.cursor = 'pointer';
|
|
637
|
-
}
|
|
638
|
-
this.handlerInfos.push(addEventListener(this.element, eventType, getHandler(this.element), passive));
|
|
639
|
-
}
|
|
640
|
-
/**
|
|
641
|
-
* Removes all the handlers installed on this container.
|
|
642
|
-
*/
|
|
643
|
-
cleanUp() {
|
|
644
|
-
for (let i = 0; i < this.handlerInfos.length; i++) {
|
|
645
|
-
removeEventListener(this.element, this.handlerInfos[i]);
|
|
646
|
-
}
|
|
647
|
-
this.handlerInfos = [];
|
|
648
|
-
}
|
|
649
|
-
}
|
|
650
|
-
|
|
651
|
-
const Char = {
|
|
652
|
-
/**
|
|
653
|
-
* The separator between the namespace and the action name in the
|
|
654
|
-
* jsaction attribute value.
|
|
655
|
-
*/
|
|
656
|
-
NAMESPACE_ACTION_SEPARATOR: '.',
|
|
657
|
-
/**
|
|
658
|
-
* The separator between the event name and action in the jsaction
|
|
659
|
-
* attribute value.
|
|
660
|
-
*/
|
|
661
|
-
EVENT_ACTION_SEPARATOR: ':',
|
|
662
|
-
};
|
|
663
|
-
|
|
664
|
-
/** Added for readability when accessing stable property names. */
|
|
665
|
-
function getEventType(eventInfo) {
|
|
666
|
-
return eventInfo.eventType;
|
|
667
|
-
}
|
|
668
|
-
/** Added for readability when accessing stable property names. */
|
|
669
|
-
function setEventType(eventInfo, eventType) {
|
|
670
|
-
eventInfo.eventType = eventType;
|
|
671
|
-
}
|
|
672
|
-
/** Added for readability when accessing stable property names. */
|
|
673
|
-
function getEvent(eventInfo) {
|
|
674
|
-
return eventInfo.event;
|
|
675
|
-
}
|
|
676
|
-
/** Added for readability when accessing stable property names. */
|
|
677
|
-
function setEvent(eventInfo, event) {
|
|
678
|
-
eventInfo.event = event;
|
|
679
|
-
}
|
|
680
|
-
/** Added for readability when accessing stable property names. */
|
|
681
|
-
function getTargetElement(eventInfo) {
|
|
682
|
-
return eventInfo.targetElement;
|
|
683
|
-
}
|
|
684
|
-
/** Added for readability when accessing stable property names. */
|
|
685
|
-
function setTargetElement(eventInfo, targetElement) {
|
|
686
|
-
eventInfo.targetElement = targetElement;
|
|
687
|
-
}
|
|
688
|
-
/** Added for readability when accessing stable property names. */
|
|
689
|
-
function getContainer(eventInfo) {
|
|
690
|
-
return eventInfo.eic;
|
|
691
|
-
}
|
|
692
|
-
/** Added for readability when accessing stable property names. */
|
|
693
|
-
function setContainer(eventInfo, container) {
|
|
694
|
-
eventInfo.eic = container;
|
|
695
|
-
}
|
|
696
|
-
/** Added for readability when accessing stable property names. */
|
|
697
|
-
function getTimestamp(eventInfo) {
|
|
698
|
-
return eventInfo.timeStamp;
|
|
699
|
-
}
|
|
700
|
-
/** Added for readability when accessing stable property names. */
|
|
701
|
-
function setTimestamp(eventInfo, timestamp) {
|
|
702
|
-
eventInfo.timeStamp = timestamp;
|
|
703
|
-
}
|
|
704
|
-
/** Added for readability when accessing stable property names. */
|
|
705
|
-
function getAction(eventInfo) {
|
|
706
|
-
return eventInfo.eia;
|
|
707
|
-
}
|
|
708
|
-
/** Added for readability when accessing stable property names. */
|
|
709
|
-
function setAction(eventInfo, actionName, actionElement) {
|
|
710
|
-
eventInfo.eia = [actionName, actionElement];
|
|
711
|
-
}
|
|
712
|
-
/** Added for readability when accessing stable property names. */
|
|
713
|
-
function unsetAction(eventInfo) {
|
|
714
|
-
eventInfo.eia = undefined;
|
|
715
|
-
}
|
|
716
|
-
/** Added for readability when accessing stable property names. */
|
|
717
|
-
function getActionElement(actionInfo) {
|
|
718
|
-
return actionInfo[1];
|
|
719
|
-
}
|
|
720
|
-
/** Added for readability when accessing stable property names. */
|
|
721
|
-
function getIsReplay(eventInfo) {
|
|
722
|
-
return eventInfo.eirp;
|
|
723
|
-
}
|
|
724
|
-
/** Added for readability when accessing stable property names. */
|
|
725
|
-
function setIsReplay(eventInfo, replay) {
|
|
726
|
-
eventInfo.eirp = replay;
|
|
727
|
-
}
|
|
728
|
-
/** Added for readability when accessing stable property names. */
|
|
729
|
-
function getResolved(eventInfo) {
|
|
730
|
-
return eventInfo.eir;
|
|
731
|
-
}
|
|
732
|
-
/** Added for readability when accessing stable property names. */
|
|
733
|
-
function setResolved(eventInfo, resolved) {
|
|
734
|
-
eventInfo.eir = resolved;
|
|
735
|
-
}
|
|
736
|
-
/** Clones an `EventInfo` */
|
|
737
|
-
function cloneEventInfo(eventInfo) {
|
|
738
|
-
return {
|
|
739
|
-
eventType: eventInfo.eventType,
|
|
740
|
-
event: eventInfo.event,
|
|
741
|
-
targetElement: eventInfo.targetElement,
|
|
742
|
-
eic: eventInfo.eic,
|
|
743
|
-
eia: eventInfo.eia,
|
|
744
|
-
timeStamp: eventInfo.timeStamp,
|
|
745
|
-
eirp: eventInfo.eirp,
|
|
746
|
-
eiack: eventInfo.eiack,
|
|
747
|
-
eir: eventInfo.eir,
|
|
748
|
-
};
|
|
749
|
-
}
|
|
750
|
-
/**
|
|
751
|
-
* Utility function for creating an `EventInfo`.
|
|
752
|
-
*
|
|
753
|
-
* This can be used from code-size sensitive compilation units, as taking
|
|
754
|
-
* parameters vs. an `Object` literal reduces code size.
|
|
755
|
-
*/
|
|
756
|
-
function createEventInfoFromParameters(eventType, event, targetElement, container, timestamp, action, isReplay, a11yClickKey) {
|
|
757
|
-
return {
|
|
758
|
-
eventType,
|
|
759
|
-
event,
|
|
760
|
-
targetElement,
|
|
761
|
-
eic: container,
|
|
762
|
-
timeStamp: timestamp,
|
|
763
|
-
eia: action,
|
|
764
|
-
eirp: isReplay,
|
|
765
|
-
eiack: a11yClickKey,
|
|
766
|
-
};
|
|
767
|
-
}
|
|
768
|
-
/**
|
|
769
|
-
* Utility class around an `EventInfo`.
|
|
770
|
-
*
|
|
771
|
-
* This should be used in compilation units that are less sensitive to code
|
|
772
|
-
* size.
|
|
773
|
-
*/
|
|
774
|
-
class EventInfoWrapper {
|
|
775
|
-
eventInfo;
|
|
776
|
-
constructor(eventInfo) {
|
|
777
|
-
this.eventInfo = eventInfo;
|
|
778
|
-
}
|
|
779
|
-
getEventType() {
|
|
780
|
-
return getEventType(this.eventInfo);
|
|
781
|
-
}
|
|
782
|
-
setEventType(eventType) {
|
|
783
|
-
setEventType(this.eventInfo, eventType);
|
|
784
|
-
}
|
|
785
|
-
getEvent() {
|
|
786
|
-
return getEvent(this.eventInfo);
|
|
787
|
-
}
|
|
788
|
-
setEvent(event) {
|
|
789
|
-
setEvent(this.eventInfo, event);
|
|
790
|
-
}
|
|
791
|
-
getTargetElement() {
|
|
792
|
-
return getTargetElement(this.eventInfo);
|
|
793
|
-
}
|
|
794
|
-
setTargetElement(targetElement) {
|
|
795
|
-
setTargetElement(this.eventInfo, targetElement);
|
|
796
|
-
}
|
|
797
|
-
getContainer() {
|
|
798
|
-
return getContainer(this.eventInfo);
|
|
799
|
-
}
|
|
800
|
-
setContainer(container) {
|
|
801
|
-
setContainer(this.eventInfo, container);
|
|
802
|
-
}
|
|
803
|
-
getTimestamp() {
|
|
804
|
-
return getTimestamp(this.eventInfo);
|
|
805
|
-
}
|
|
806
|
-
setTimestamp(timestamp) {
|
|
807
|
-
setTimestamp(this.eventInfo, timestamp);
|
|
808
|
-
}
|
|
809
|
-
getAction() {
|
|
810
|
-
const action = getAction(this.eventInfo);
|
|
811
|
-
if (!action)
|
|
812
|
-
return undefined;
|
|
813
|
-
return {
|
|
814
|
-
name: action[0],
|
|
815
|
-
element: action[1],
|
|
816
|
-
};
|
|
817
|
-
}
|
|
818
|
-
setAction(action) {
|
|
819
|
-
if (!action) {
|
|
820
|
-
unsetAction(this.eventInfo);
|
|
821
|
-
return;
|
|
822
|
-
}
|
|
823
|
-
setAction(this.eventInfo, action.name, action.element);
|
|
824
|
-
}
|
|
825
|
-
getIsReplay() {
|
|
826
|
-
return getIsReplay(this.eventInfo);
|
|
827
|
-
}
|
|
828
|
-
setIsReplay(replay) {
|
|
829
|
-
setIsReplay(this.eventInfo, replay);
|
|
830
|
-
}
|
|
831
|
-
getResolved() {
|
|
832
|
-
return getResolved(this.eventInfo);
|
|
833
|
-
}
|
|
834
|
-
setResolved(resolved) {
|
|
835
|
-
setResolved(this.eventInfo, resolved);
|
|
836
|
-
}
|
|
837
|
-
clone() {
|
|
838
|
-
return new EventInfoWrapper(cloneEventInfo(this.eventInfo));
|
|
839
|
-
}
|
|
840
|
-
}
|
|
841
|
-
|
|
842
|
-
/**
|
|
843
|
-
* Since maps from event to action are immutable we can use a single map
|
|
844
|
-
* to represent the empty map.
|
|
845
|
-
*/
|
|
846
|
-
const EMPTY_ACTION_MAP = {};
|
|
847
|
-
/**
|
|
848
|
-
* This regular expression matches a semicolon.
|
|
849
|
-
*/
|
|
850
|
-
const REGEXP_SEMICOLON = /\s*;\s*/;
|
|
851
|
-
/** If no event type is defined, defaults to `click`. */
|
|
852
|
-
const DEFAULT_EVENT_TYPE = EventType.CLICK;
|
|
853
|
-
/** Resolves actions for Events. */
|
|
854
|
-
class ActionResolver {
|
|
855
|
-
a11yClickSupport = false;
|
|
856
|
-
clickModSupport = true;
|
|
857
|
-
syntheticMouseEventSupport;
|
|
858
|
-
updateEventInfoForA11yClick = undefined;
|
|
859
|
-
preventDefaultForA11yClick = undefined;
|
|
860
|
-
populateClickOnlyAction = undefined;
|
|
861
|
-
constructor({ syntheticMouseEventSupport = false, clickModSupport = true, } = {}) {
|
|
862
|
-
this.syntheticMouseEventSupport = syntheticMouseEventSupport;
|
|
863
|
-
this.clickModSupport = clickModSupport;
|
|
864
|
-
}
|
|
865
|
-
resolveEventType(eventInfo) {
|
|
866
|
-
// We distinguish modified and plain clicks in order to support the
|
|
867
|
-
// default browser behavior of modified clicks on links; usually to
|
|
868
|
-
// open the URL of the link in new tab or new window on ctrl/cmd
|
|
869
|
-
// click. A DOM 'click' event is mapped to the jsaction 'click'
|
|
870
|
-
// event iff there is no modifier present on the event. If there is
|
|
871
|
-
// a modifier, it's mapped to 'clickmod' instead.
|
|
872
|
-
//
|
|
873
|
-
// It's allowed to omit the event in the jsaction attribute. In that
|
|
874
|
-
// case, 'click' is assumed. Thus the following two are equivalent:
|
|
875
|
-
//
|
|
876
|
-
// <a href="someurl" jsaction="gna.fu">
|
|
877
|
-
// <a href="someurl" jsaction="click:gna.fu">
|
|
878
|
-
//
|
|
879
|
-
// For unmodified clicks, EventContract invokes the jsaction
|
|
880
|
-
// 'gna.fu'. For modified clicks, EventContract won't find a
|
|
881
|
-
// suitable action and leave the event to be handled by the
|
|
882
|
-
// browser.
|
|
883
|
-
//
|
|
884
|
-
// In order to also invoke a jsaction handler for a modifier click,
|
|
885
|
-
// 'clickmod' needs to be used:
|
|
886
|
-
//
|
|
887
|
-
// <a href="someurl" jsaction="clickmod:gna.fu">
|
|
888
|
-
//
|
|
889
|
-
// EventContract invokes the jsaction 'gna.fu' for modified
|
|
890
|
-
// clicks. Unmodified clicks are left to the browser.
|
|
891
|
-
//
|
|
892
|
-
// In order to set up the event contract to handle both clickonly and
|
|
893
|
-
// clickmod, only addEvent(EventType.CLICK) is necessary.
|
|
894
|
-
//
|
|
895
|
-
// In order to set up the event contract to handle click,
|
|
896
|
-
// addEvent() is necessary for CLICK, KEYDOWN, and KEYPRESS event types. If
|
|
897
|
-
// a11y click support is enabled, addEvent() will set up the appropriate key
|
|
898
|
-
// event handler automatically.
|
|
899
|
-
if (this.clickModSupport &&
|
|
900
|
-
getEventType(eventInfo) === EventType.CLICK &&
|
|
901
|
-
isModifiedClickEvent(getEvent(eventInfo))) {
|
|
902
|
-
setEventType(eventInfo, EventType.CLICKMOD);
|
|
903
|
-
}
|
|
904
|
-
else if (this.a11yClickSupport) {
|
|
905
|
-
this.updateEventInfoForA11yClick(eventInfo);
|
|
906
|
-
}
|
|
907
|
-
}
|
|
908
|
-
resolveAction(eventInfo) {
|
|
909
|
-
if (getResolved(eventInfo)) {
|
|
910
|
-
return;
|
|
911
|
-
}
|
|
912
|
-
this.populateAction(eventInfo, getTargetElement(eventInfo));
|
|
913
|
-
setResolved(eventInfo, true);
|
|
914
|
-
}
|
|
915
|
-
resolveParentAction(eventInfo) {
|
|
916
|
-
const action = getAction(eventInfo);
|
|
917
|
-
const actionElement = action && getActionElement(action);
|
|
918
|
-
unsetAction(eventInfo);
|
|
919
|
-
const parentNode = actionElement && this.getParentNode(actionElement);
|
|
920
|
-
if (!parentNode) {
|
|
921
|
-
return;
|
|
922
|
-
}
|
|
923
|
-
this.populateAction(eventInfo, parentNode);
|
|
924
|
-
}
|
|
925
|
-
/**
|
|
926
|
-
* Searches for a jsaction that the DOM event maps to and creates an
|
|
927
|
-
* object containing event information used for dispatching by
|
|
928
|
-
* jsaction.Dispatcher. This method populates the `action` and `actionElement`
|
|
929
|
-
* fields of the EventInfo object passed in by finding the first
|
|
930
|
-
* jsaction attribute above the target Node of the event, and below
|
|
931
|
-
* the container Node, that specifies a jsaction for the event
|
|
932
|
-
* type. If no such jsaction is found, then action is undefined.
|
|
933
|
-
*
|
|
934
|
-
* @param eventInfo `EventInfo` to set `action` and `actionElement` if an
|
|
935
|
-
* action is found on any `Element` in the path of the `Event`.
|
|
936
|
-
*/
|
|
937
|
-
populateAction(eventInfo, currentTarget) {
|
|
938
|
-
let actionElement = currentTarget;
|
|
939
|
-
while (actionElement && actionElement !== getContainer(eventInfo)) {
|
|
940
|
-
if (actionElement.nodeType === Node.ELEMENT_NODE) {
|
|
941
|
-
this.populateActionOnElement(actionElement, eventInfo);
|
|
942
|
-
}
|
|
943
|
-
if (getAction(eventInfo)) {
|
|
944
|
-
// An event is handled by at most one jsaction. Thus we stop at the
|
|
945
|
-
// first matching jsaction specified in a jsaction attribute up the
|
|
946
|
-
// ancestor chain of the event target node.
|
|
947
|
-
break;
|
|
948
|
-
}
|
|
949
|
-
actionElement = this.getParentNode(actionElement);
|
|
950
|
-
}
|
|
951
|
-
const action = getAction(eventInfo);
|
|
952
|
-
if (!action) {
|
|
953
|
-
// No action found.
|
|
954
|
-
return;
|
|
955
|
-
}
|
|
956
|
-
if (this.a11yClickSupport) {
|
|
957
|
-
this.preventDefaultForA11yClick(eventInfo);
|
|
958
|
-
}
|
|
959
|
-
// We attempt to handle the mouseenter/mouseleave events here by
|
|
960
|
-
// detecting whether the mouseover/mouseout events correspond to
|
|
961
|
-
// entering/leaving an element.
|
|
962
|
-
if (this.syntheticMouseEventSupport) {
|
|
963
|
-
if (getEventType(eventInfo) === EventType.MOUSEENTER ||
|
|
964
|
-
getEventType(eventInfo) === EventType.MOUSELEAVE ||
|
|
965
|
-
getEventType(eventInfo) === EventType.POINTERENTER ||
|
|
966
|
-
getEventType(eventInfo) === EventType.POINTERLEAVE) {
|
|
967
|
-
// We attempt to handle the mouseenter/mouseleave events here by
|
|
968
|
-
// detecting whether the mouseover/mouseout events correspond to
|
|
969
|
-
// entering/leaving an element.
|
|
970
|
-
if (isMouseSpecialEvent(getEvent(eventInfo), getEventType(eventInfo), getActionElement(action))) {
|
|
971
|
-
// If both mouseover/mouseout and mouseenter/mouseleave events are
|
|
972
|
-
// enabled, two separate handlers for mouseover/mouseout are
|
|
973
|
-
// registered. Both handlers will see the same event instance
|
|
974
|
-
// so we create a copy to avoid interfering with the dispatching of
|
|
975
|
-
// the mouseover/mouseout event.
|
|
976
|
-
const copiedEvent = createMouseSpecialEvent(getEvent(eventInfo), getActionElement(action));
|
|
977
|
-
setEvent(eventInfo, copiedEvent);
|
|
978
|
-
// Since the mouseenter/mouseleave events do not bubble, the target
|
|
979
|
-
// of the event is technically the `actionElement` (the node with the
|
|
980
|
-
// `jsaction` attribute)
|
|
981
|
-
setTargetElement(eventInfo, getActionElement(action));
|
|
982
|
-
}
|
|
983
|
-
else {
|
|
984
|
-
unsetAction(eventInfo);
|
|
985
|
-
}
|
|
986
|
-
}
|
|
987
|
-
}
|
|
988
|
-
}
|
|
989
|
-
/**
|
|
990
|
-
* Walk to the parent node, unless the node has a different owner in
|
|
991
|
-
* which case we walk to the owner. Attempt to walk to host of a
|
|
992
|
-
* shadow root if needed.
|
|
993
|
-
*/
|
|
994
|
-
getParentNode(element) {
|
|
995
|
-
const owner = element[Property.OWNER];
|
|
996
|
-
if (owner) {
|
|
997
|
-
return owner;
|
|
998
|
-
}
|
|
999
|
-
const parentNode = element.parentNode;
|
|
1000
|
-
if (parentNode?.nodeName === '#document-fragment') {
|
|
1001
|
-
return parentNode?.host ?? null;
|
|
1002
|
-
}
|
|
1003
|
-
return parentNode;
|
|
1004
|
-
}
|
|
1005
|
-
/**
|
|
1006
|
-
* Accesses the jsaction map on a node and retrieves the name of the
|
|
1007
|
-
* action the given event is mapped to, if any. It parses the
|
|
1008
|
-
* attribute value and stores it in a property on the node for
|
|
1009
|
-
* subsequent retrieval without re-parsing and re-accessing the
|
|
1010
|
-
* attribute.
|
|
1011
|
-
*
|
|
1012
|
-
* @param actionElement The DOM node to retrieve the jsaction map from.
|
|
1013
|
-
* @param eventInfo `EventInfo` to set `action` and `actionElement` if an
|
|
1014
|
-
* action is found on the `actionElement`.
|
|
1015
|
-
*/
|
|
1016
|
-
populateActionOnElement(actionElement, eventInfo) {
|
|
1017
|
-
const actionMap = this.parseActions(actionElement);
|
|
1018
|
-
const actionName = actionMap[getEventType(eventInfo)];
|
|
1019
|
-
if (actionName !== undefined) {
|
|
1020
|
-
setAction(eventInfo, actionName, actionElement);
|
|
1021
|
-
}
|
|
1022
|
-
if (this.a11yClickSupport) {
|
|
1023
|
-
this.populateClickOnlyAction(actionElement, eventInfo, actionMap);
|
|
1024
|
-
}
|
|
1025
|
-
}
|
|
1026
|
-
/**
|
|
1027
|
-
* Parses and caches an element's jsaction element into a map.
|
|
1028
|
-
*
|
|
1029
|
-
* This is primarily for internal use.
|
|
1030
|
-
*
|
|
1031
|
-
* @param actionElement The DOM node to retrieve the jsaction map from.
|
|
1032
|
-
* @return Map from event to qualified name of the jsaction bound to it.
|
|
1033
|
-
*/
|
|
1034
|
-
parseActions(actionElement) {
|
|
1035
|
-
let actionMap = get(actionElement);
|
|
1036
|
-
if (!actionMap) {
|
|
1037
|
-
const jsactionAttribute = actionElement.getAttribute(Attribute.JSACTION);
|
|
1038
|
-
if (!jsactionAttribute) {
|
|
1039
|
-
actionMap = EMPTY_ACTION_MAP;
|
|
1040
|
-
set(actionElement, actionMap);
|
|
1041
|
-
}
|
|
1042
|
-
else {
|
|
1043
|
-
actionMap = getParsed(jsactionAttribute);
|
|
1044
|
-
if (!actionMap) {
|
|
1045
|
-
actionMap = {};
|
|
1046
|
-
const values = jsactionAttribute.split(REGEXP_SEMICOLON);
|
|
1047
|
-
for (let idx = 0; idx < values.length; idx++) {
|
|
1048
|
-
const value = values[idx];
|
|
1049
|
-
if (!value) {
|
|
1050
|
-
continue;
|
|
1051
|
-
}
|
|
1052
|
-
const colon = value.indexOf(Char.EVENT_ACTION_SEPARATOR);
|
|
1053
|
-
const hasColon = colon !== -1;
|
|
1054
|
-
const type = hasColon ? value.substr(0, colon).trim() : DEFAULT_EVENT_TYPE;
|
|
1055
|
-
const action = hasColon ? value.substr(colon + 1).trim() : value;
|
|
1056
|
-
actionMap[type] = action;
|
|
1057
|
-
}
|
|
1058
|
-
setParsed(jsactionAttribute, actionMap);
|
|
1059
|
-
}
|
|
1060
|
-
set(actionElement, actionMap);
|
|
1061
|
-
}
|
|
1062
|
-
}
|
|
1063
|
-
return actionMap;
|
|
1064
|
-
}
|
|
1065
|
-
addA11yClickSupport(updateEventInfoForA11yClick, preventDefaultForA11yClick, populateClickOnlyAction) {
|
|
1066
|
-
this.a11yClickSupport = true;
|
|
1067
|
-
this.updateEventInfoForA11yClick = updateEventInfoForA11yClick;
|
|
1068
|
-
this.preventDefaultForA11yClick = preventDefaultForA11yClick;
|
|
1069
|
-
this.populateClickOnlyAction = populateClickOnlyAction;
|
|
1070
|
-
}
|
|
1071
|
-
}
|
|
1072
|
-
|
|
1073
|
-
/**
|
|
1074
|
-
* @fileoverview An enum to control who can call certain jsaction APIs.
|
|
1075
|
-
*/
|
|
1076
|
-
var Restriction;
|
|
1077
|
-
(function (Restriction) {
|
|
1078
|
-
Restriction[Restriction["I_AM_THE_JSACTION_FRAMEWORK"] = 0] = "I_AM_THE_JSACTION_FRAMEWORK";
|
|
1079
|
-
})(Restriction || (Restriction = {}));
|
|
1080
|
-
|
|
1081
|
-
/**
|
|
1082
|
-
* Receives a DOM event, determines the jsaction associated with the source
|
|
1083
|
-
* element of the DOM event, and invokes the handler associated with the
|
|
1084
|
-
* jsaction.
|
|
1085
|
-
*/
|
|
1086
|
-
class Dispatcher {
|
|
1087
|
-
dispatchDelegate;
|
|
1088
|
-
// The ActionResolver to use to resolve actions.
|
|
1089
|
-
actionResolver;
|
|
1090
|
-
/** The replayer function to be called when there are queued events. */
|
|
1091
|
-
eventReplayer;
|
|
1092
|
-
/** Whether the event replay is scheduled. */
|
|
1093
|
-
eventReplayScheduled = false;
|
|
1094
|
-
/** The queue of events. */
|
|
1095
|
-
replayEventInfoWrappers = [];
|
|
1096
|
-
/**
|
|
1097
|
-
* Options are:
|
|
1098
|
-
* - `eventReplayer`: When the event contract dispatches replay events
|
|
1099
|
-
* to the Dispatcher, the Dispatcher collects them and in the next tick
|
|
1100
|
-
* dispatches them to the `eventReplayer`. Defaults to dispatching to `dispatchDelegate`.
|
|
1101
|
-
* @param dispatchDelegate A function that should handle dispatching an `EventInfoWrapper` to handlers.
|
|
1102
|
-
*/
|
|
1103
|
-
constructor(dispatchDelegate, { actionResolver, eventReplayer, } = {}) {
|
|
1104
|
-
this.dispatchDelegate = dispatchDelegate;
|
|
1105
|
-
this.actionResolver = actionResolver;
|
|
1106
|
-
this.eventReplayer = eventReplayer;
|
|
1107
|
-
}
|
|
1108
|
-
/**
|
|
1109
|
-
* Receives an event or the event queue from the EventContract. The event
|
|
1110
|
-
* queue is copied and it attempts to replay.
|
|
1111
|
-
* If event info is passed in it looks for an action handler that can handle
|
|
1112
|
-
* the given event. If there is no handler registered queues the event and
|
|
1113
|
-
* checks if a loader is registered for the given namespace. If so, calls it.
|
|
1114
|
-
*
|
|
1115
|
-
* Alternatively, if in global dispatch mode, calls all registered global
|
|
1116
|
-
* handlers for the appropriate event type.
|
|
1117
|
-
*
|
|
1118
|
-
* The three functionalities of this call are deliberately not split into
|
|
1119
|
-
* three methods (and then declared as an abstract interface), because the
|
|
1120
|
-
* interface is used by EventContract, which lives in a different jsbinary.
|
|
1121
|
-
* Therefore the interface between the three is defined entirely in terms that
|
|
1122
|
-
* are invariant under jscompiler processing (Function and Array, as opposed
|
|
1123
|
-
* to a custom type with method names).
|
|
1124
|
-
*
|
|
1125
|
-
* @param eventInfo The info for the event that triggered this call or the
|
|
1126
|
-
* queue of events from EventContract.
|
|
1127
|
-
*/
|
|
1128
|
-
dispatch(eventInfo) {
|
|
1129
|
-
const eventInfoWrapper = new EventInfoWrapper(eventInfo);
|
|
1130
|
-
this.actionResolver?.resolveEventType(eventInfo);
|
|
1131
|
-
this.actionResolver?.resolveAction(eventInfo);
|
|
1132
|
-
const action = eventInfoWrapper.getAction();
|
|
1133
|
-
if (action && shouldPreventDefaultBeforeDispatching(action.element, eventInfoWrapper)) {
|
|
1134
|
-
preventDefault(eventInfoWrapper.getEvent());
|
|
1135
|
-
}
|
|
1136
|
-
if (this.eventReplayer && eventInfoWrapper.getIsReplay()) {
|
|
1137
|
-
this.scheduleEventInfoWrapperReplay(eventInfoWrapper);
|
|
1138
|
-
return;
|
|
1139
|
-
}
|
|
1140
|
-
this.dispatchDelegate(eventInfoWrapper);
|
|
1141
|
-
}
|
|
1142
|
-
/**
|
|
1143
|
-
* Schedules an `EventInfoWrapper` for replay. The replaying will happen in its own
|
|
1144
|
-
* stack once the current flow cedes control. This is done to mimic
|
|
1145
|
-
* browser event handling.
|
|
1146
|
-
*/
|
|
1147
|
-
scheduleEventInfoWrapperReplay(eventInfoWrapper) {
|
|
1148
|
-
this.replayEventInfoWrappers.push(eventInfoWrapper);
|
|
1149
|
-
if (this.eventReplayScheduled) {
|
|
1150
|
-
return;
|
|
1151
|
-
}
|
|
1152
|
-
this.eventReplayScheduled = true;
|
|
1153
|
-
Promise.resolve().then(() => {
|
|
1154
|
-
this.eventReplayScheduled = false;
|
|
1155
|
-
this.eventReplayer(this.replayEventInfoWrappers);
|
|
1156
|
-
});
|
|
1157
|
-
}
|
|
1158
|
-
}
|
|
1159
|
-
/**
|
|
1160
|
-
* Returns true if the default action of this event should be prevented before
|
|
1161
|
-
* this event is dispatched.
|
|
1162
|
-
*/
|
|
1163
|
-
function shouldPreventDefaultBeforeDispatching(actionElement, eventInfoWrapper) {
|
|
1164
|
-
// Prevent browser from following <a> node links if a jsaction is present
|
|
1165
|
-
// and we are dispatching the action now. Note that the targetElement may be
|
|
1166
|
-
// a child of an anchor that has a jsaction attached. For that reason, we
|
|
1167
|
-
// need to check the actionElement rather than the targetElement.
|
|
1168
|
-
return (actionElement.tagName === 'A' &&
|
|
1169
|
-
(eventInfoWrapper.getEventType() === EventType.CLICK ||
|
|
1170
|
-
eventInfoWrapper.getEventType() === EventType.CLICKMOD));
|
|
1171
|
-
}
|
|
1172
|
-
|
|
1173
|
-
/** An internal symbol used to indicate whether propagation should be stopped or not. */
|
|
1174
|
-
const PROPAGATION_STOPPED_SYMBOL =
|
|
1175
|
-
/* @__PURE__ */ Symbol.for('propagationStopped');
|
|
1176
|
-
/** Extra event phases beyond what the browser provides. */
|
|
1177
|
-
const EventPhase = {
|
|
1178
|
-
REPLAY: 101,
|
|
1179
|
-
};
|
|
1180
|
-
const PREVENT_DEFAULT_ERROR_MESSAGE_DETAILS = ' Because event replay occurs after browser dispatch, `preventDefault` would have no ' +
|
|
1181
|
-
'effect. You can check whether an event is being replayed by accessing the event phase: ' +
|
|
1182
|
-
'`event.eventPhase === EventPhase.REPLAY`.';
|
|
1183
|
-
const PREVENT_DEFAULT_ERROR_MESSAGE = `\`preventDefault\` called during event replay.`;
|
|
1184
|
-
const COMPOSED_PATH_ERROR_MESSAGE_DETAILS = ' Because event replay occurs after browser ' +
|
|
1185
|
-
'dispatch, `composedPath()` will be empty. Iterate parent nodes from `event.target` or ' +
|
|
1186
|
-
'`event.currentTarget` if you need to check elements in the event path.';
|
|
1187
|
-
const COMPOSED_PATH_ERROR_MESSAGE = `\`composedPath\` called during event replay.`;
|
|
1188
|
-
/**
|
|
1189
|
-
* A dispatcher that uses browser-based `Event` semantics, for example bubbling, `stopPropagation`,
|
|
1190
|
-
* `currentTarget`, etc.
|
|
1191
|
-
*/
|
|
1192
|
-
class EventDispatcher {
|
|
1193
|
-
dispatchDelegate;
|
|
1194
|
-
clickModSupport;
|
|
1195
|
-
actionResolver;
|
|
1196
|
-
dispatcher;
|
|
1197
|
-
constructor(dispatchDelegate, clickModSupport = true) {
|
|
1198
|
-
this.dispatchDelegate = dispatchDelegate;
|
|
1199
|
-
this.clickModSupport = clickModSupport;
|
|
1200
|
-
this.actionResolver = new ActionResolver({ clickModSupport });
|
|
1201
|
-
this.dispatcher = new Dispatcher((eventInfoWrapper) => {
|
|
1202
|
-
this.dispatchToDelegate(eventInfoWrapper);
|
|
1203
|
-
}, {
|
|
1204
|
-
actionResolver: this.actionResolver,
|
|
1205
|
-
});
|
|
1206
|
-
}
|
|
1207
|
-
/**
|
|
1208
|
-
* The entrypoint for the `EventContract` dispatch.
|
|
1209
|
-
*/
|
|
1210
|
-
dispatch(eventInfo) {
|
|
1211
|
-
this.dispatcher.dispatch(eventInfo);
|
|
1212
|
-
}
|
|
1213
|
-
/** Internal method that does basic disaptching. */
|
|
1214
|
-
dispatchToDelegate(eventInfoWrapper) {
|
|
1215
|
-
if (eventInfoWrapper.getIsReplay()) {
|
|
1216
|
-
prepareEventForReplay(eventInfoWrapper);
|
|
1217
|
-
}
|
|
1218
|
-
prepareEventForBubbling(eventInfoWrapper);
|
|
1219
|
-
while (eventInfoWrapper.getAction()) {
|
|
1220
|
-
prepareEventForDispatch(eventInfoWrapper);
|
|
1221
|
-
// If this is a capture event, ONLY dispatch if the action element is the target.
|
|
1222
|
-
if (isCaptureEventType(eventInfoWrapper.getEventType()) &&
|
|
1223
|
-
eventInfoWrapper.getAction().element !== eventInfoWrapper.getTargetElement()) {
|
|
1224
|
-
return;
|
|
1225
|
-
}
|
|
1226
|
-
this.dispatchDelegate(eventInfoWrapper.getEvent(), eventInfoWrapper.getAction().name);
|
|
1227
|
-
if (propagationStopped(eventInfoWrapper)) {
|
|
1228
|
-
return;
|
|
1229
|
-
}
|
|
1230
|
-
this.actionResolver.resolveParentAction(eventInfoWrapper.eventInfo);
|
|
1231
|
-
}
|
|
1232
|
-
}
|
|
1233
|
-
}
|
|
1234
|
-
function prepareEventForBubbling(eventInfoWrapper) {
|
|
1235
|
-
const event = eventInfoWrapper.getEvent();
|
|
1236
|
-
const originalStopPropagation = eventInfoWrapper.getEvent().stopPropagation.bind(event);
|
|
1237
|
-
const stopPropagation = () => {
|
|
1238
|
-
event[PROPAGATION_STOPPED_SYMBOL] = true;
|
|
1239
|
-
originalStopPropagation();
|
|
1240
|
-
};
|
|
1241
|
-
patchEventInstance(event, 'stopPropagation', stopPropagation);
|
|
1242
|
-
patchEventInstance(event, 'stopImmediatePropagation', stopPropagation);
|
|
1243
|
-
}
|
|
1244
|
-
function propagationStopped(eventInfoWrapper) {
|
|
1245
|
-
const event = eventInfoWrapper.getEvent();
|
|
1246
|
-
return !!event[PROPAGATION_STOPPED_SYMBOL];
|
|
1247
|
-
}
|
|
1248
|
-
function prepareEventForReplay(eventInfoWrapper) {
|
|
1249
|
-
const event = eventInfoWrapper.getEvent();
|
|
1250
|
-
const target = eventInfoWrapper.getTargetElement();
|
|
1251
|
-
const originalPreventDefault = event.preventDefault.bind(event);
|
|
1252
|
-
patchEventInstance(event, 'target', target);
|
|
1253
|
-
patchEventInstance(event, 'eventPhase', EventPhase.REPLAY);
|
|
1254
|
-
patchEventInstance(event, 'preventDefault', () => {
|
|
1255
|
-
originalPreventDefault();
|
|
1256
|
-
throw new Error(PREVENT_DEFAULT_ERROR_MESSAGE + (ngDevMode ? PREVENT_DEFAULT_ERROR_MESSAGE_DETAILS : ''));
|
|
1257
|
-
});
|
|
1258
|
-
patchEventInstance(event, 'composedPath', () => {
|
|
1259
|
-
throw new Error(COMPOSED_PATH_ERROR_MESSAGE + (ngDevMode ? COMPOSED_PATH_ERROR_MESSAGE_DETAILS : ''));
|
|
1260
|
-
});
|
|
1261
|
-
}
|
|
1262
|
-
function prepareEventForDispatch(eventInfoWrapper) {
|
|
1263
|
-
const event = eventInfoWrapper.getEvent();
|
|
1264
|
-
const currentTarget = eventInfoWrapper.getAction()?.element;
|
|
1265
|
-
if (currentTarget) {
|
|
1266
|
-
patchEventInstance(event, 'currentTarget', currentTarget, {
|
|
1267
|
-
// `currentTarget` is going to get reassigned every dispatch.
|
|
1268
|
-
configurable: true,
|
|
1269
|
-
});
|
|
1270
|
-
}
|
|
1271
|
-
}
|
|
1272
|
-
/**
|
|
1273
|
-
* Patch `Event` instance during non-standard `Event` dispatch. This patches just the `Event`
|
|
1274
|
-
* instance that the browser created, it does not patch global properties or methods.
|
|
1275
|
-
*
|
|
1276
|
-
* This is necessary because dispatching an `Event` outside of browser dispatch results in
|
|
1277
|
-
* incorrect properties and methods that need to be polyfilled or do not work.
|
|
1278
|
-
*
|
|
1279
|
-
* JSAction dispatch adds two extra "phases" to event dispatch:
|
|
1280
|
-
* 1. Event delegation - the event is being dispatched by a delegating event handler on a container
|
|
1281
|
-
* (typically `window.document.documentElement`), to a delegated event handler on some child
|
|
1282
|
-
* element. Certain `Event` properties will be unintuitive, such as `currentTarget`, which would
|
|
1283
|
-
* be the container rather than the child element. Bubbling would also not work. In order to
|
|
1284
|
-
* emulate the browser, these properties and methods on the `Event` are patched.
|
|
1285
|
-
* 2. Event replay - the event is being dispatched by the framework once the handlers have been
|
|
1286
|
-
* loaded (during hydration, or late-loaded). Certain `Event` properties can be unset by the
|
|
1287
|
-
* browser because the `Event` is no longer actively being dispatched, such as `target`. Other
|
|
1288
|
-
* methods have no effect because the `Event` has already been dispatched, such as
|
|
1289
|
-
* `preventDefault`. Bubbling would also not work. These properties and methods are patched,
|
|
1290
|
-
* either to fill in information that the browser may have removed, or to throw errors in methods
|
|
1291
|
-
* that no longer behave as expected.
|
|
1292
|
-
*/
|
|
1293
|
-
function patchEventInstance(event, property, value, { configurable = false } = {}) {
|
|
1294
|
-
Object.defineProperty(event, property, { value, configurable });
|
|
1295
|
-
}
|
|
1296
|
-
/**
|
|
1297
|
-
* Registers deferred functionality for an EventContract and a Jsaction
|
|
1298
|
-
* Dispatcher.
|
|
1299
|
-
*/
|
|
1300
|
-
function registerDispatcher$1(eventContract, dispatcher) {
|
|
1301
|
-
eventContract.ecrd((eventInfo) => {
|
|
1302
|
-
dispatcher.dispatch(eventInfo);
|
|
1303
|
-
}, Restriction.I_AM_THE_JSACTION_FRAMEWORK);
|
|
1304
|
-
}
|
|
1305
|
-
|
|
1306
|
-
/** Creates an `EarlyJsactionData` object. */
|
|
1307
|
-
function createEarlyJsactionData(container) {
|
|
1308
|
-
const q = [];
|
|
1309
|
-
const d = (eventInfo) => {
|
|
1310
|
-
q.push(eventInfo);
|
|
1311
|
-
};
|
|
1312
|
-
const h = (event) => {
|
|
1313
|
-
d(createEventInfoFromParameters(event.type, event, event.target, container, Date.now()));
|
|
1314
|
-
};
|
|
1315
|
-
return {
|
|
1316
|
-
c: container,
|
|
1317
|
-
q,
|
|
1318
|
-
et: [],
|
|
1319
|
-
etc: [],
|
|
1320
|
-
d,
|
|
1321
|
-
h,
|
|
1322
|
-
};
|
|
1323
|
-
}
|
|
1324
|
-
/** Add all the events to the container stored in the `EarlyJsactionData`. */
|
|
1325
|
-
function addEvents(earlyJsactionData, types, capture) {
|
|
1326
|
-
for (let i = 0; i < types.length; i++) {
|
|
1327
|
-
const eventType = types[i];
|
|
1328
|
-
const eventTypes = capture ? earlyJsactionData.etc : earlyJsactionData.et;
|
|
1329
|
-
eventTypes.push(eventType);
|
|
1330
|
-
earlyJsactionData.c.addEventListener(eventType, earlyJsactionData.h, capture);
|
|
1331
|
-
}
|
|
1332
|
-
}
|
|
1333
|
-
/** Get the queued `EventInfo` objects that were dispatched before a dispatcher was registered. */
|
|
1334
|
-
function getQueuedEventInfos(earlyJsactionData) {
|
|
1335
|
-
return earlyJsactionData?.q ?? [];
|
|
1336
|
-
}
|
|
1337
|
-
/** Register a different dispatcher function on the `EarlyJsactionData`. */
|
|
1338
|
-
function registerDispatcher(earlyJsactionData, dispatcher) {
|
|
1339
|
-
if (!earlyJsactionData) {
|
|
1340
|
-
return;
|
|
1341
|
-
}
|
|
1342
|
-
earlyJsactionData.d = dispatcher;
|
|
1343
|
-
}
|
|
1344
|
-
/** Removes all event listener handlers. */
|
|
1345
|
-
function removeAllEventListeners(earlyJsactionData) {
|
|
1346
|
-
if (!earlyJsactionData) {
|
|
1347
|
-
return;
|
|
1348
|
-
}
|
|
1349
|
-
removeEventListeners(earlyJsactionData.c, earlyJsactionData.et, earlyJsactionData.h);
|
|
1350
|
-
removeEventListeners(earlyJsactionData.c, earlyJsactionData.etc, earlyJsactionData.h, true);
|
|
1351
|
-
}
|
|
1352
|
-
function removeEventListeners(container, eventTypes, earlyEventHandler, capture) {
|
|
1353
|
-
for (let i = 0; i < eventTypes.length; i++) {
|
|
1354
|
-
container.removeEventListener(eventTypes[i], earlyEventHandler, /* useCapture */ capture);
|
|
1355
|
-
}
|
|
1356
|
-
}
|
|
1357
|
-
|
|
1358
|
-
/**
|
|
1359
|
-
* @define Support for the non-bubbling mouseenter and mouseleave events. This
|
|
1360
|
-
* flag can be overridden in a build rule.
|
|
1361
|
-
*/
|
|
1362
|
-
const MOUSE_SPECIAL_SUPPORT = false;
|
|
1363
|
-
|
|
1364
|
-
/**
|
|
1365
|
-
* @fileoverview Implements the local event handling contract. This
|
|
1366
|
-
* allows DOM objects in a container that enters into this contract to
|
|
1367
|
-
* define event handlers which are executed in a local context.
|
|
1368
|
-
*
|
|
1369
|
-
* One EventContract instance can manage the contract for multiple
|
|
1370
|
-
* containers, which are added using the addContainer() method.
|
|
1371
|
-
*
|
|
1372
|
-
* Events can be registered using the addEvent() method.
|
|
1373
|
-
*
|
|
1374
|
-
* A Dispatcher is added using the registerDispatcher() method. Until there is
|
|
1375
|
-
* a dispatcher, events are queued. The idea is that the EventContract
|
|
1376
|
-
* class is inlined in the HTML of the top level page and instantiated
|
|
1377
|
-
* right after the start of <body>. The Dispatcher class is contained
|
|
1378
|
-
* in the external deferred js, and instantiated and registered with
|
|
1379
|
-
* EventContract when the external javascript in the page loads. The
|
|
1380
|
-
* external javascript will also register the jsaction handlers, which
|
|
1381
|
-
* then pick up the queued events at the time of registration.
|
|
1382
|
-
*
|
|
1383
|
-
* Since this class is meant to be inlined in the main page HTML, the
|
|
1384
|
-
* size of the binary compiled from this file MUST be kept as small as
|
|
1385
|
-
* possible and thus its dependencies to a minimum.
|
|
1386
|
-
*/
|
|
1387
|
-
/**
|
|
1388
|
-
* EventContract intercepts events in the bubbling phase at the
|
|
1389
|
-
* boundary of a container element, and maps them to generic actions
|
|
1390
|
-
* which are specified using the custom jsaction attribute in
|
|
1391
|
-
* HTML. Behavior of the application is then specified in terms of
|
|
1392
|
-
* handler for such actions, cf. jsaction.Dispatcher in dispatcher.js.
|
|
1393
|
-
*
|
|
1394
|
-
* This has several benefits: (1) No DOM event handlers need to be
|
|
1395
|
-
* registered on the specific elements in the UI. (2) The set of
|
|
1396
|
-
* events that the application has to handle can be specified in terms
|
|
1397
|
-
* of the semantics of the application, rather than in terms of DOM
|
|
1398
|
-
* events. (3) Invocation of handlers can be delayed and handlers can
|
|
1399
|
-
* be delay loaded in a generic way.
|
|
1400
|
-
*/
|
|
1401
|
-
class EventContract {
|
|
1402
|
-
static MOUSE_SPECIAL_SUPPORT = MOUSE_SPECIAL_SUPPORT;
|
|
1403
|
-
containerManager;
|
|
1404
|
-
/**
|
|
1405
|
-
* The DOM events which this contract covers. Used to prevent double
|
|
1406
|
-
* registration of event types. The value of the map is the
|
|
1407
|
-
* internally created DOM event handler function that handles the
|
|
1408
|
-
* DOM events. See addEvent().
|
|
1409
|
-
*
|
|
1410
|
-
*/
|
|
1411
|
-
eventHandlers = {};
|
|
1412
|
-
browserEventTypeToExtraEventTypes = {};
|
|
1413
|
-
/**
|
|
1414
|
-
* The dispatcher function. Events are passed to this function for
|
|
1415
|
-
* handling once it was set using the registerDispatcher() method. This is
|
|
1416
|
-
* done because the function is passed from another jsbinary, so passing the
|
|
1417
|
-
* instance and invoking the method here would require to leave the method
|
|
1418
|
-
* unobfuscated.
|
|
1419
|
-
*/
|
|
1420
|
-
dispatcher = null;
|
|
1421
|
-
/**
|
|
1422
|
-
* The list of suspended `EventInfo` that will be dispatched
|
|
1423
|
-
* as soon as the `Dispatcher` is registered.
|
|
1424
|
-
*/
|
|
1425
|
-
queuedEventInfos = [];
|
|
1426
|
-
constructor(containerManager) {
|
|
1427
|
-
this.containerManager = containerManager;
|
|
1428
|
-
}
|
|
1429
|
-
handleEvent(eventType, event, container) {
|
|
1430
|
-
const eventInfo = createEventInfoFromParameters(
|
|
1431
|
-
/* eventType= */ eventType,
|
|
1432
|
-
/* event= */ event,
|
|
1433
|
-
/* targetElement= */ event.target,
|
|
1434
|
-
/* container= */ container,
|
|
1435
|
-
/* timestamp= */ Date.now());
|
|
1436
|
-
this.handleEventInfo(eventInfo);
|
|
1437
|
-
}
|
|
1438
|
-
/**
|
|
1439
|
-
* Handle an `EventInfo`.
|
|
1440
|
-
*/
|
|
1441
|
-
handleEventInfo(eventInfo) {
|
|
1442
|
-
if (!this.dispatcher) {
|
|
1443
|
-
// All events are queued when the dispatcher isn't yet loaded.
|
|
1444
|
-
setIsReplay(eventInfo, true);
|
|
1445
|
-
this.queuedEventInfos?.push(eventInfo);
|
|
1446
|
-
return;
|
|
1447
|
-
}
|
|
1448
|
-
this.dispatcher(eventInfo);
|
|
1449
|
-
}
|
|
1450
|
-
/**
|
|
1451
|
-
* Enables jsaction handlers to be called for the event type given by
|
|
1452
|
-
* name.
|
|
1453
|
-
*
|
|
1454
|
-
* If the event is already registered, this does nothing.
|
|
1455
|
-
*
|
|
1456
|
-
* @param prefixedEventType If supplied, this event is used in
|
|
1457
|
-
* the actual browser event registration instead of the name that is
|
|
1458
|
-
* exposed to jsaction. Use this if you e.g. want users to be able
|
|
1459
|
-
* to subscribe to jsaction="transitionEnd:foo" while the underlying
|
|
1460
|
-
* event is webkitTransitionEnd in one browser and mozTransitionEnd
|
|
1461
|
-
* in another.
|
|
1462
|
-
*
|
|
1463
|
-
* @param passive A boolean value that, if `true`, indicates that the event
|
|
1464
|
-
* handler will never call `preventDefault()`.
|
|
1465
|
-
*/
|
|
1466
|
-
addEvent(eventType, prefixedEventType, passive) {
|
|
1467
|
-
if (eventType in this.eventHandlers || !this.containerManager) {
|
|
1468
|
-
return;
|
|
1469
|
-
}
|
|
1470
|
-
if (!EventContract.MOUSE_SPECIAL_SUPPORT && MOUSE_SPECIAL_EVENT_TYPES.indexOf(eventType) >= 0) {
|
|
1471
|
-
return;
|
|
1472
|
-
}
|
|
1473
|
-
const eventHandler = (eventType, event, container) => {
|
|
1474
|
-
this.handleEvent(eventType, event, container);
|
|
1475
|
-
};
|
|
1476
|
-
// Store the callback to allow us to replay events.
|
|
1477
|
-
this.eventHandlers[eventType] = eventHandler;
|
|
1478
|
-
const browserEventType = getBrowserEventType(prefixedEventType || eventType);
|
|
1479
|
-
if (browserEventType !== eventType) {
|
|
1480
|
-
const eventTypes = this.browserEventTypeToExtraEventTypes[browserEventType] || [];
|
|
1481
|
-
eventTypes.push(eventType);
|
|
1482
|
-
this.browserEventTypeToExtraEventTypes[browserEventType] = eventTypes;
|
|
1483
|
-
}
|
|
1484
|
-
this.containerManager.addEventListener(browserEventType, (element) => {
|
|
1485
|
-
return (event) => {
|
|
1486
|
-
eventHandler(eventType, event, element);
|
|
1487
|
-
};
|
|
1488
|
-
}, passive);
|
|
1489
|
-
}
|
|
1490
|
-
/**
|
|
1491
|
-
* Gets the queued early events and replay them using the appropriate handler
|
|
1492
|
-
* in the provided event contract. Once all the events are replayed, it cleans
|
|
1493
|
-
* up the early contract.
|
|
1494
|
-
*/
|
|
1495
|
-
replayEarlyEvents(earlyJsactionData = window._ejsa) {
|
|
1496
|
-
// Check if the early contract is present and prevent calling this function
|
|
1497
|
-
// more than once.
|
|
1498
|
-
if (!earlyJsactionData) {
|
|
1499
|
-
return;
|
|
1500
|
-
}
|
|
1501
|
-
// Replay the early contract events.
|
|
1502
|
-
this.replayEarlyEventInfos(earlyJsactionData.q);
|
|
1503
|
-
// Clean up the early contract.
|
|
1504
|
-
removeAllEventListeners(earlyJsactionData);
|
|
1505
|
-
delete window._ejsa;
|
|
1506
|
-
}
|
|
1507
|
-
/**
|
|
1508
|
-
* Replays all the early `EventInfo` objects, dispatching them through the normal
|
|
1509
|
-
* `EventContract` flow.
|
|
1510
|
-
*/
|
|
1511
|
-
replayEarlyEventInfos(earlyEventInfos) {
|
|
1512
|
-
for (let i = 0; i < earlyEventInfos.length; i++) {
|
|
1513
|
-
const earlyEventInfo = earlyEventInfos[i];
|
|
1514
|
-
const eventTypes = this.getEventTypesForBrowserEventType(earlyEventInfo.eventType);
|
|
1515
|
-
for (let j = 0; j < eventTypes.length; j++) {
|
|
1516
|
-
const eventInfo = cloneEventInfo(earlyEventInfo);
|
|
1517
|
-
// EventInfo eventType maps to JSAction's internal event type,
|
|
1518
|
-
// rather than the browser event type.
|
|
1519
|
-
setEventType(eventInfo, eventTypes[j]);
|
|
1520
|
-
this.handleEventInfo(eventInfo);
|
|
1521
|
-
}
|
|
1522
|
-
}
|
|
1523
|
-
}
|
|
1524
|
-
/**
|
|
1525
|
-
* Returns all JSAction event types that have been registered for a given
|
|
1526
|
-
* browser event type.
|
|
1527
|
-
*/
|
|
1528
|
-
getEventTypesForBrowserEventType(browserEventType) {
|
|
1529
|
-
const eventTypes = [];
|
|
1530
|
-
if (this.eventHandlers[browserEventType]) {
|
|
1531
|
-
eventTypes.push(browserEventType);
|
|
1532
|
-
}
|
|
1533
|
-
if (this.browserEventTypeToExtraEventTypes[browserEventType]) {
|
|
1534
|
-
eventTypes.push(...this.browserEventTypeToExtraEventTypes[browserEventType]);
|
|
1535
|
-
}
|
|
1536
|
-
return eventTypes;
|
|
1537
|
-
}
|
|
1538
|
-
/**
|
|
1539
|
-
* Returns the event handler function for a given event type.
|
|
1540
|
-
*/
|
|
1541
|
-
handler(eventType) {
|
|
1542
|
-
return this.eventHandlers[eventType];
|
|
1543
|
-
}
|
|
1544
|
-
/**
|
|
1545
|
-
* Cleans up the event contract. This resets all of the `EventContract`'s
|
|
1546
|
-
* internal state. Users are responsible for not using this `EventContract`
|
|
1547
|
-
* after it has been cleaned up.
|
|
1548
|
-
*/
|
|
1549
|
-
cleanUp() {
|
|
1550
|
-
this.containerManager?.cleanUp();
|
|
1551
|
-
this.containerManager = null;
|
|
1552
|
-
this.eventHandlers = {};
|
|
1553
|
-
this.browserEventTypeToExtraEventTypes = {};
|
|
1554
|
-
this.dispatcher = null;
|
|
1555
|
-
this.queuedEventInfos = [];
|
|
1556
|
-
}
|
|
1557
|
-
/**
|
|
1558
|
-
* Register a dispatcher function. Event info of each event mapped to
|
|
1559
|
-
* a jsaction is passed for handling to this callback. The queued
|
|
1560
|
-
* events are passed as well to the dispatcher for later replaying
|
|
1561
|
-
* once the dispatcher is registered. Clears the event queue to null.
|
|
1562
|
-
*
|
|
1563
|
-
* @param dispatcher The dispatcher function.
|
|
1564
|
-
* @param restriction
|
|
1565
|
-
*/
|
|
1566
|
-
registerDispatcher(dispatcher, restriction) {
|
|
1567
|
-
this.ecrd(dispatcher, restriction);
|
|
1568
|
-
}
|
|
1569
|
-
/**
|
|
1570
|
-
* Unrenamed alias for registerDispatcher. Necessary for any codebases that
|
|
1571
|
-
* split the `EventContract` and `Dispatcher` code into different compilation
|
|
1572
|
-
* units.
|
|
1573
|
-
*/
|
|
1574
|
-
ecrd(dispatcher, restriction) {
|
|
1575
|
-
this.dispatcher = dispatcher;
|
|
1576
|
-
if (this.queuedEventInfos?.length) {
|
|
1577
|
-
for (let i = 0; i < this.queuedEventInfos.length; i++) {
|
|
1578
|
-
this.handleEventInfo(this.queuedEventInfos[i]);
|
|
1579
|
-
}
|
|
1580
|
-
this.queuedEventInfos = null;
|
|
1581
|
-
}
|
|
1582
|
-
}
|
|
1583
|
-
}
|
|
1584
|
-
|
|
1585
|
-
/**
|
|
1586
|
-
* Creates an `EarlyJsactionData`, adds events to it, and populates it on a nested object on
|
|
1587
|
-
* the window.
|
|
1588
|
-
*/
|
|
1589
|
-
function bootstrapAppScopedEarlyEventContract(container, appId, bubbleEventTypes, captureEventTypes, dataContainer = window) {
|
|
1590
|
-
const earlyJsactionData = createEarlyJsactionData(container);
|
|
1591
|
-
if (!dataContainer._ejsas) {
|
|
1592
|
-
dataContainer._ejsas = {};
|
|
1593
|
-
}
|
|
1594
|
-
dataContainer._ejsas[appId] = earlyJsactionData;
|
|
1595
|
-
addEvents(earlyJsactionData, bubbleEventTypes);
|
|
1596
|
-
addEvents(earlyJsactionData, captureEventTypes, /* capture= */ true);
|
|
1597
|
-
}
|
|
1598
|
-
/** Get the queued `EventInfo` objects that were dispatched before a dispatcher was registered. */
|
|
1599
|
-
function getAppScopedQueuedEventInfos(appId, dataContainer = window) {
|
|
1600
|
-
return getQueuedEventInfos(dataContainer._ejsas?.[appId]);
|
|
1601
|
-
}
|
|
1602
|
-
/**
|
|
1603
|
-
* Registers a dispatcher function on the `EarlyJsactionData` present on the nested object on the
|
|
1604
|
-
* window.
|
|
1605
|
-
*/
|
|
1606
|
-
function registerAppScopedDispatcher(restriction, appId, dispatcher, dataContainer = window) {
|
|
1607
|
-
registerDispatcher(dataContainer._ejsas?.[appId], dispatcher);
|
|
1608
|
-
}
|
|
1609
|
-
/** Removes all event listener handlers. */
|
|
1610
|
-
function removeAllAppScopedEventListeners(appId, dataContainer = window) {
|
|
1611
|
-
removeAllEventListeners(dataContainer._ejsas?.[appId]);
|
|
1612
|
-
}
|
|
1613
|
-
/** Clear the early event contract. */
|
|
1614
|
-
function clearAppScopedEarlyEventContract(appId, dataContainer = window) {
|
|
1615
|
-
if (!dataContainer._ejsas) {
|
|
1616
|
-
return;
|
|
1617
|
-
}
|
|
1618
|
-
dataContainer._ejsas[appId] = undefined;
|
|
1619
|
-
}
|
|
1620
|
-
|
|
1621
|
-
export { Attribute, EventContract, EventContractContainer, EventDispatcher, EventInfoWrapper, EventPhase, bootstrapAppScopedEarlyEventContract, clearAppScopedEarlyEventContract, getDefaulted as getActionCache, getAppScopedQueuedEventInfos, isCaptureEventType, isEarlyEventType, registerAppScopedDispatcher, registerDispatcher$1 as registerDispatcher, removeAllAppScopedEventListeners };
|
|
1622
|
-
//# sourceMappingURL=event-dispatch.mjs.map
|