@angular/core 21.0.0-next.8 → 21.0.0-rc.0
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 +2 -14
- package/fesm2022/_attribute-chunk.mjs.map +1 -1
- package/fesm2022/_debug_node-chunk.mjs +15214 -28375
- package/fesm2022/_debug_node-chunk.mjs.map +1 -1
- package/fesm2022/_effect-chunk.mjs +402 -120
- package/fesm2022/_effect-chunk.mjs.map +1 -1
- package/fesm2022/_effect-chunk2.mjs +2951 -0
- package/fesm2022/_effect-chunk2.mjs.map +1 -0
- package/fesm2022/_not_found-chunk.mjs +18 -35
- package/fesm2022/_not_found-chunk.mjs.map +1 -1
- package/fesm2022/_resource-chunk.mjs +316 -563
- package/fesm2022/_resource-chunk.mjs.map +1 -1
- package/fesm2022/_untracked-chunk.mjs +96 -0
- package/fesm2022/_untracked-chunk.mjs.map +1 -0
- package/fesm2022/_weak_ref-chunk.mjs +2 -4
- package/fesm2022/_weak_ref-chunk.mjs.map +1 -1
- package/fesm2022/core.mjs +2466 -4309
- package/fesm2022/core.mjs.map +1 -1
- package/fesm2022/primitives-di.mjs +9 -9
- package/fesm2022/primitives-di.mjs.map +1 -1
- package/fesm2022/primitives-event-dispatch.mjs +626 -1460
- package/fesm2022/primitives-event-dispatch.mjs.map +1 -1
- package/fesm2022/primitives-signals.mjs +157 -191
- package/fesm2022/primitives-signals.mjs.map +1 -1
- package/fesm2022/rxjs-interop.mjs +208 -308
- package/fesm2022/rxjs-interop.mjs.map +1 -1
- package/fesm2022/testing.mjs +2305 -3164
- package/fesm2022/testing.mjs.map +1 -1
- package/package.json +8 -2
- package/resources/best-practices.md +56 -0
- package/schematics/bundles/add-bootstrap-context-to-server-main.cjs +7 -25
- package/schematics/bundles/application-config-core.cjs +8 -19
- package/schematics/bundles/{apply_import_manager-CBLmogDD.cjs → apply_import_manager-1Zs_gpB6.cjs} +4 -5
- package/schematics/bundles/bootstrap-options-migration.cjs +93 -132
- package/schematics/bundles/cleanup-unused-imports.cjs +9 -13
- package/schematics/bundles/common-to-standalone-migration.cjs +381 -0
- package/schematics/bundles/{compiler_host-T6xncpiw.cjs → compiler_host-DBwYMlTo.cjs} +10 -11
- package/schematics/bundles/control-flow-migration.cjs +29 -31
- package/schematics/bundles/{imports-DwPXlGFl.cjs → imports-DP72APSx.cjs} +1 -23
- package/schematics/bundles/{index-DWSaRJdz.cjs → index-B7I9sIUx.cjs} +36 -37
- package/schematics/bundles/inject-migration.cjs +9 -26
- package/schematics/bundles/leading_space-D9nQ8UQC.cjs +1 -1
- package/schematics/bundles/{migrate_ts_type_references-Cu-FR4L5.cjs → migrate_ts_type_references-UGIUl7En.cjs} +458 -24
- package/schematics/bundles/{ng_component_template-BkWiUuGG.cjs → ng_component_template-Dsuq1Lw7.cjs} +4 -5
- package/schematics/bundles/{ng_decorators-BI0uV7KI.cjs → ng_decorators-DSFlWYQY.cjs} +2 -2
- package/schematics/bundles/ngclass-to-class-migration.cjs +16 -19
- package/schematics/bundles/ngstyle-to-style-migration.cjs +15 -18
- package/schematics/bundles/nodes-B16H9JUd.cjs +1 -1
- package/schematics/bundles/output-migration.cjs +16 -19
- package/schematics/bundles/{parse_html-C97tKKp3.cjs → parse_html-8VLCL37B.cjs} +5 -5
- package/schematics/bundles/{project_paths-C6g3lqjX.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 +9 -25
- package/schematics/bundles/router-current-navigation.cjs +6 -17
- package/schematics/bundles/router-last-successful-navigation.cjs +6 -17
- package/schematics/bundles/router-testing-module-migration.cjs +7 -18
- package/schematics/bundles/self-closing-tags-migration.cjs +14 -17
- package/schematics/bundles/signal-input-migration.cjs +23 -26
- package/schematics/bundles/signal-queries-migration.cjs +22 -25
- package/schematics/bundles/signals.cjs +10 -13
- package/schematics/bundles/standalone-migration.cjs +22 -56
- package/schematics/bundles/symbol-BObKoqes.cjs +1 -1
- package/schematics/collection.json +6 -0
- package/schematics/migrations/common-to-standalone-migration/schema.json +14 -0
- package/types/_api-chunk.d.ts +1 -1
- package/types/_chrome_dev_tools_performance-chunk.d.ts +20 -12
- package/types/_discovery-chunk.d.ts +18 -14
- package/types/_effect-chunk.d.ts +1 -1
- package/types/_event_dispatcher-chunk.d.ts +1 -1
- package/types/_formatter-chunk.d.ts +4 -3
- package/types/_weak_ref-chunk.d.ts +1 -1
- package/types/core.d.ts +49 -100
- package/types/primitives-di.d.ts +1 -1
- package/types/primitives-event-dispatch.d.ts +1 -1
- package/types/primitives-signals.d.ts +2 -2
- package/types/rxjs-interop.d.ts +1 -1
- package/types/testing.d.ts +1 -1
- package/fesm2022/_root_effect_scheduler-chunk.mjs +0 -4630
- package/fesm2022/_root_effect_scheduler-chunk.mjs.map +0 -1
- package/fesm2022/_signal-chunk.mjs +0 -581
- package/fesm2022/_signal-chunk.mjs.map +0 -1
- package/schematics/bundles/index-BnmACOsq.cjs +0 -22319
- package/schematics/bundles/project_tsconfig_paths-CdhVNYMk.cjs +0 -51583
|
@@ -1,1621 +1,787 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* @license Angular v21.0.0-
|
|
2
|
+
* @license Angular v21.0.0-rc.0
|
|
3
3
|
* (c) 2010-2025 Google LLC. https://angular.dev/
|
|
4
4
|
* License: MIT
|
|
5
5
|
*/
|
|
6
6
|
|
|
7
7
|
import { Attribute } from './_attribute-chunk.mjs';
|
|
8
8
|
|
|
9
|
-
/** All properties that are used by jsaction. */
|
|
10
9
|
const Property = {
|
|
11
|
-
|
|
12
|
-
|
|
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',
|
|
10
|
+
JSACTION: '__jsaction',
|
|
11
|
+
OWNER: '__owner'
|
|
27
12
|
};
|
|
28
13
|
|
|
29
|
-
/**
|
|
30
|
-
* Map from jsaction annotation to a parsed map from event name to action name.
|
|
31
|
-
*/
|
|
32
14
|
const parseCache = {};
|
|
33
|
-
/**
|
|
34
|
-
* Reads the jsaction parser cache from the given DOM Element.
|
|
35
|
-
*/
|
|
36
15
|
function get(element) {
|
|
37
|
-
|
|
16
|
+
return element[Property.JSACTION];
|
|
38
17
|
}
|
|
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
18
|
function getDefaulted(element) {
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
19
|
+
const cache = get(element) ?? {};
|
|
20
|
+
set(element, cache);
|
|
21
|
+
return cache;
|
|
47
22
|
}
|
|
48
|
-
/**
|
|
49
|
-
* Writes the jsaction parser cache to the given DOM Element.
|
|
50
|
-
*/
|
|
51
23
|
function set(element, actionMap) {
|
|
52
|
-
|
|
24
|
+
element[Property.JSACTION] = actionMap;
|
|
53
25
|
}
|
|
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
26
|
function getParsed(text) {
|
|
61
|
-
|
|
27
|
+
return parseCache[text];
|
|
62
28
|
}
|
|
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
29
|
function setParsed(text, parsed) {
|
|
70
|
-
|
|
30
|
+
parseCache[text] = parsed;
|
|
71
31
|
}
|
|
72
32
|
|
|
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
33
|
const EventType = {
|
|
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
|
-
* 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',
|
|
34
|
+
AUXCLICK: 'auxclick',
|
|
35
|
+
CHANGE: 'change',
|
|
36
|
+
CLICK: 'click',
|
|
37
|
+
CLICKMOD: 'clickmod',
|
|
38
|
+
CLICKONLY: 'clickonly',
|
|
39
|
+
DBLCLICK: 'dblclick',
|
|
40
|
+
FOCUS: 'focus',
|
|
41
|
+
FOCUSIN: 'focusin',
|
|
42
|
+
BLUR: 'blur',
|
|
43
|
+
FOCUSOUT: 'focusout',
|
|
44
|
+
SUBMIT: 'submit',
|
|
45
|
+
KEYDOWN: 'keydown',
|
|
46
|
+
KEYPRESS: 'keypress',
|
|
47
|
+
KEYUP: 'keyup',
|
|
48
|
+
MOUSEUP: 'mouseup',
|
|
49
|
+
MOUSEDOWN: 'mousedown',
|
|
50
|
+
MOUSEOVER: 'mouseover',
|
|
51
|
+
MOUSEOUT: 'mouseout',
|
|
52
|
+
MOUSEENTER: 'mouseenter',
|
|
53
|
+
MOUSELEAVE: 'mouseleave',
|
|
54
|
+
MOUSEMOVE: 'mousemove',
|
|
55
|
+
POINTERUP: 'pointerup',
|
|
56
|
+
POINTERDOWN: 'pointerdown',
|
|
57
|
+
POINTEROVER: 'pointerover',
|
|
58
|
+
POINTEROUT: 'pointerout',
|
|
59
|
+
POINTERENTER: 'pointerenter',
|
|
60
|
+
POINTERLEAVE: 'pointerleave',
|
|
61
|
+
POINTERMOVE: 'pointermove',
|
|
62
|
+
POINTERCANCEL: 'pointercancel',
|
|
63
|
+
GOTPOINTERCAPTURE: 'gotpointercapture',
|
|
64
|
+
LOSTPOINTERCAPTURE: 'lostpointercapture',
|
|
65
|
+
ERROR: 'error',
|
|
66
|
+
LOAD: 'load',
|
|
67
|
+
UNLOAD: 'unload',
|
|
68
|
+
TOUCHSTART: 'touchstart',
|
|
69
|
+
TOUCHEND: 'touchend',
|
|
70
|
+
TOUCHMOVE: 'touchmove',
|
|
71
|
+
INPUT: 'input',
|
|
72
|
+
SCROLL: 'scroll',
|
|
73
|
+
TOGGLE: 'toggle',
|
|
74
|
+
CUSTOM: '_custom'
|
|
308
75
|
};
|
|
309
|
-
|
|
310
|
-
const
|
|
311
|
-
|
|
312
|
-
|
|
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. */
|
|
76
|
+
const MOUSE_SPECIAL_EVENT_TYPES = [EventType.MOUSEENTER, EventType.MOUSELEAVE, 'pointerenter', 'pointerleave'];
|
|
77
|
+
const BUBBLE_EVENT_TYPES = [EventType.CLICK, EventType.DBLCLICK, EventType.FOCUSIN, EventType.FOCUSOUT, EventType.KEYDOWN, EventType.KEYUP, EventType.KEYPRESS, EventType.MOUSEOVER, EventType.MOUSEOUT, EventType.SUBMIT, EventType.TOUCHSTART, EventType.TOUCHEND, EventType.TOUCHMOVE, 'touchcancel', 'auxclick', 'change', 'compositionstart', 'compositionupdate', 'compositionend', 'beforeinput', 'input', 'select', 'copy', 'cut', 'paste', 'mousedown', 'mouseup', 'wheel', 'contextmenu', 'dragover', 'dragenter', 'dragleave', 'drop', 'dragstart', 'dragend', 'pointerdown', 'pointermove', 'pointerup', 'pointercancel', 'pointerover', 'pointerout', 'gotpointercapture', 'lostpointercapture', 'ended', 'loadedmetadata', 'pagehide', 'pageshow', 'visibilitychange', 'beforematch'];
|
|
78
|
+
const CAPTURE_EVENT_TYPES = [EventType.FOCUS, EventType.BLUR, EventType.ERROR, EventType.LOAD, EventType.TOGGLE];
|
|
79
|
+
const isCaptureEventType = eventType => CAPTURE_EVENT_TYPES.indexOf(eventType) >= 0;
|
|
386
80
|
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;
|
|
81
|
+
const isEarlyEventType = eventType => EARLY_EVENT_TYPES.indexOf(eventType) >= 0;
|
|
391
82
|
|
|
392
|
-
/**
|
|
393
|
-
* Gets a browser event type, if it would differ from the JSAction event type.
|
|
394
|
-
*/
|
|
395
83
|
function getBrowserEventType(eventType) {
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
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;
|
|
84
|
+
if (eventType === EventType.MOUSEENTER) {
|
|
85
|
+
return EventType.MOUSEOVER;
|
|
86
|
+
} else if (eventType === EventType.MOUSELEAVE) {
|
|
87
|
+
return EventType.MOUSEOUT;
|
|
88
|
+
} else if (eventType === EventType.POINTERENTER) {
|
|
89
|
+
return EventType.POINTEROVER;
|
|
90
|
+
} else if (eventType === EventType.POINTERLEAVE) {
|
|
91
|
+
return EventType.POINTEROUT;
|
|
92
|
+
}
|
|
93
|
+
return eventType;
|
|
414
94
|
}
|
|
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
95
|
function addEventListener(element, eventType, handler, passive) {
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
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 };
|
|
96
|
+
let capture = false;
|
|
97
|
+
if (isCaptureEventType(eventType)) {
|
|
98
|
+
capture = true;
|
|
99
|
+
}
|
|
100
|
+
const options = typeof passive === 'boolean' ? {
|
|
101
|
+
capture,
|
|
102
|
+
passive
|
|
103
|
+
} : capture;
|
|
104
|
+
element.addEventListener(eventType, handler, options);
|
|
105
|
+
return {
|
|
106
|
+
eventType,
|
|
107
|
+
handler,
|
|
108
|
+
capture,
|
|
109
|
+
passive
|
|
110
|
+
};
|
|
448
111
|
}
|
|
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
112
|
function removeEventListener(element, info) {
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
else if (element.detachEvent) {
|
|
467
|
-
// `detachEvent` is an old DOM API.
|
|
468
|
-
element.detachEvent(`on${info.eventType}`, info.handler);
|
|
469
|
-
}
|
|
113
|
+
if (element.removeEventListener) {
|
|
114
|
+
const options = typeof info.passive === 'boolean' ? {
|
|
115
|
+
capture: info.capture
|
|
116
|
+
} : info.capture;
|
|
117
|
+
element.removeEventListener(info.eventType, info.handler, options);
|
|
118
|
+
} else if (element.detachEvent) {
|
|
119
|
+
element.detachEvent(`on${info.eventType}`, info.handler);
|
|
120
|
+
}
|
|
470
121
|
}
|
|
471
|
-
/**
|
|
472
|
-
* Prevents the default action of an event.
|
|
473
|
-
* @param e The event to prevent the default action for.
|
|
474
|
-
*/
|
|
475
122
|
function preventDefault(e) {
|
|
476
|
-
|
|
123
|
+
e.preventDefault ? e.preventDefault() : e.returnValue = false;
|
|
477
124
|
}
|
|
478
|
-
/**
|
|
479
|
-
* Whether we are on a Mac. Not pulling in useragent just for this.
|
|
480
|
-
*/
|
|
481
125
|
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
126
|
function isMiddleClick(e) {
|
|
489
|
-
|
|
490
|
-
|
|
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
|
-
);
|
|
127
|
+
return (e.which === 2 || e.which == null && e.button === 4
|
|
128
|
+
);
|
|
497
129
|
}
|
|
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
130
|
function isModifiedClickEvent(e) {
|
|
506
|
-
|
|
507
|
-
|
|
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);
|
|
131
|
+
return (isMac && e.metaKey || !isMac && e.ctrlKey || isMiddleClick(e) || e.shiftKey
|
|
132
|
+
);
|
|
514
133
|
}
|
|
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
134
|
function isMouseSpecialEvent(e, type, element) {
|
|
534
|
-
|
|
535
|
-
|
|
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))));
|
|
135
|
+
const related = e.relatedTarget;
|
|
136
|
+
return (e.type === EventType.MOUSEOVER && type === EventType.MOUSEENTER || e.type === EventType.MOUSEOUT && type === EventType.MOUSELEAVE || e.type === EventType.POINTEROVER && type === EventType.POINTERENTER || e.type === EventType.POINTEROUT && type === EventType.POINTERLEAVE) && (!related || related !== element && !element.contains(related));
|
|
541
137
|
}
|
|
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
138
|
function createMouseSpecialEvent(e, target) {
|
|
552
|
-
|
|
553
|
-
|
|
554
|
-
|
|
555
|
-
|
|
556
|
-
|
|
557
|
-
|
|
558
|
-
|
|
559
|
-
|
|
560
|
-
|
|
561
|
-
|
|
562
|
-
|
|
563
|
-
|
|
564
|
-
|
|
565
|
-
|
|
566
|
-
|
|
567
|
-
|
|
568
|
-
|
|
569
|
-
|
|
570
|
-
|
|
571
|
-
|
|
572
|
-
|
|
573
|
-
|
|
574
|
-
|
|
575
|
-
|
|
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;
|
|
139
|
+
const copy = {};
|
|
140
|
+
for (const property in e) {
|
|
141
|
+
if (property === 'srcElement' || property === 'target') {
|
|
142
|
+
continue;
|
|
143
|
+
}
|
|
144
|
+
const key = property;
|
|
145
|
+
const value = e[key];
|
|
146
|
+
if (typeof value === 'function') {
|
|
147
|
+
continue;
|
|
148
|
+
}
|
|
149
|
+
copy[key] = value;
|
|
150
|
+
}
|
|
151
|
+
if (e.type === EventType.MOUSEOVER) {
|
|
152
|
+
copy['type'] = EventType.MOUSEENTER;
|
|
153
|
+
} else if (e.type === EventType.MOUSEOUT) {
|
|
154
|
+
copy['type'] = EventType.MOUSELEAVE;
|
|
155
|
+
} else if (e.type === EventType.POINTEROVER) {
|
|
156
|
+
copy['type'] = EventType.POINTERENTER;
|
|
157
|
+
} else {
|
|
158
|
+
copy['type'] = EventType.POINTERLEAVE;
|
|
159
|
+
}
|
|
160
|
+
copy['target'] = copy['srcElement'] = target;
|
|
161
|
+
copy['bubbles'] = false;
|
|
162
|
+
copy['_originalEvent'] = e;
|
|
163
|
+
return copy;
|
|
593
164
|
}
|
|
594
165
|
|
|
595
|
-
/**
|
|
596
|
-
* Whether the user agent is running on iOS.
|
|
597
|
-
*/
|
|
598
166
|
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
167
|
class EventContractContainer {
|
|
605
|
-
|
|
606
|
-
|
|
607
|
-
|
|
608
|
-
|
|
609
|
-
|
|
610
|
-
|
|
611
|
-
|
|
612
|
-
|
|
613
|
-
|
|
614
|
-
|
|
615
|
-
|
|
616
|
-
|
|
617
|
-
|
|
618
|
-
|
|
619
|
-
|
|
620
|
-
|
|
621
|
-
|
|
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
|
-
}
|
|
168
|
+
element;
|
|
169
|
+
handlerInfos = [];
|
|
170
|
+
constructor(element) {
|
|
171
|
+
this.element = element;
|
|
172
|
+
}
|
|
173
|
+
addEventListener(eventType, getHandler, passive) {
|
|
174
|
+
if (isIos) {
|
|
175
|
+
this.element.style.cursor = 'pointer';
|
|
176
|
+
}
|
|
177
|
+
this.handlerInfos.push(addEventListener(this.element, eventType, getHandler(this.element), passive));
|
|
178
|
+
}
|
|
179
|
+
cleanUp() {
|
|
180
|
+
for (let i = 0; i < this.handlerInfos.length; i++) {
|
|
181
|
+
removeEventListener(this.element, this.handlerInfos[i]);
|
|
182
|
+
}
|
|
183
|
+
this.handlerInfos = [];
|
|
184
|
+
}
|
|
649
185
|
}
|
|
650
186
|
|
|
651
187
|
const Char = {
|
|
652
|
-
|
|
653
|
-
|
|
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: ':',
|
|
188
|
+
NAMESPACE_ACTION_SEPARATOR: '.',
|
|
189
|
+
EVENT_ACTION_SEPARATOR: ':'
|
|
662
190
|
};
|
|
663
191
|
|
|
664
|
-
/** Added for readability when accessing stable property names. */
|
|
665
192
|
function getEventType(eventInfo) {
|
|
666
|
-
|
|
193
|
+
return eventInfo.eventType;
|
|
667
194
|
}
|
|
668
|
-
/** Added for readability when accessing stable property names. */
|
|
669
195
|
function setEventType(eventInfo, eventType) {
|
|
670
|
-
|
|
196
|
+
eventInfo.eventType = eventType;
|
|
671
197
|
}
|
|
672
|
-
/** Added for readability when accessing stable property names. */
|
|
673
198
|
function getEvent(eventInfo) {
|
|
674
|
-
|
|
199
|
+
return eventInfo.event;
|
|
675
200
|
}
|
|
676
|
-
/** Added for readability when accessing stable property names. */
|
|
677
201
|
function setEvent(eventInfo, event) {
|
|
678
|
-
|
|
202
|
+
eventInfo.event = event;
|
|
679
203
|
}
|
|
680
|
-
/** Added for readability when accessing stable property names. */
|
|
681
204
|
function getTargetElement(eventInfo) {
|
|
682
|
-
|
|
205
|
+
return eventInfo.targetElement;
|
|
683
206
|
}
|
|
684
|
-
/** Added for readability when accessing stable property names. */
|
|
685
207
|
function setTargetElement(eventInfo, targetElement) {
|
|
686
|
-
|
|
208
|
+
eventInfo.targetElement = targetElement;
|
|
687
209
|
}
|
|
688
|
-
/** Added for readability when accessing stable property names. */
|
|
689
210
|
function getContainer(eventInfo) {
|
|
690
|
-
|
|
211
|
+
return eventInfo.eic;
|
|
691
212
|
}
|
|
692
|
-
/** Added for readability when accessing stable property names. */
|
|
693
213
|
function setContainer(eventInfo, container) {
|
|
694
|
-
|
|
214
|
+
eventInfo.eic = container;
|
|
695
215
|
}
|
|
696
|
-
/** Added for readability when accessing stable property names. */
|
|
697
216
|
function getTimestamp(eventInfo) {
|
|
698
|
-
|
|
217
|
+
return eventInfo.timeStamp;
|
|
699
218
|
}
|
|
700
|
-
/** Added for readability when accessing stable property names. */
|
|
701
219
|
function setTimestamp(eventInfo, timestamp) {
|
|
702
|
-
|
|
220
|
+
eventInfo.timeStamp = timestamp;
|
|
703
221
|
}
|
|
704
|
-
/** Added for readability when accessing stable property names. */
|
|
705
222
|
function getAction(eventInfo) {
|
|
706
|
-
|
|
223
|
+
return eventInfo.eia;
|
|
707
224
|
}
|
|
708
|
-
/** Added for readability when accessing stable property names. */
|
|
709
225
|
function setAction(eventInfo, actionName, actionElement) {
|
|
710
|
-
|
|
226
|
+
eventInfo.eia = [actionName, actionElement];
|
|
711
227
|
}
|
|
712
|
-
/** Added for readability when accessing stable property names. */
|
|
713
228
|
function unsetAction(eventInfo) {
|
|
714
|
-
|
|
229
|
+
eventInfo.eia = undefined;
|
|
715
230
|
}
|
|
716
|
-
/** Added for readability when accessing stable property names. */
|
|
717
231
|
function getActionElement(actionInfo) {
|
|
718
|
-
|
|
232
|
+
return actionInfo[1];
|
|
719
233
|
}
|
|
720
|
-
/** Added for readability when accessing stable property names. */
|
|
721
234
|
function getIsReplay(eventInfo) {
|
|
722
|
-
|
|
235
|
+
return eventInfo.eirp;
|
|
723
236
|
}
|
|
724
|
-
/** Added for readability when accessing stable property names. */
|
|
725
237
|
function setIsReplay(eventInfo, replay) {
|
|
726
|
-
|
|
238
|
+
eventInfo.eirp = replay;
|
|
727
239
|
}
|
|
728
|
-
/** Added for readability when accessing stable property names. */
|
|
729
240
|
function getResolved(eventInfo) {
|
|
730
|
-
|
|
241
|
+
return eventInfo.eir;
|
|
731
242
|
}
|
|
732
|
-
/** Added for readability when accessing stable property names. */
|
|
733
243
|
function setResolved(eventInfo, resolved) {
|
|
734
|
-
|
|
244
|
+
eventInfo.eir = resolved;
|
|
735
245
|
}
|
|
736
|
-
/** Clones an `EventInfo` */
|
|
737
246
|
function cloneEventInfo(eventInfo) {
|
|
738
|
-
|
|
739
|
-
|
|
740
|
-
|
|
741
|
-
|
|
742
|
-
|
|
743
|
-
|
|
744
|
-
|
|
745
|
-
|
|
746
|
-
|
|
747
|
-
|
|
748
|
-
|
|
247
|
+
return {
|
|
248
|
+
eventType: eventInfo.eventType,
|
|
249
|
+
event: eventInfo.event,
|
|
250
|
+
targetElement: eventInfo.targetElement,
|
|
251
|
+
eic: eventInfo.eic,
|
|
252
|
+
eia: eventInfo.eia,
|
|
253
|
+
timeStamp: eventInfo.timeStamp,
|
|
254
|
+
eirp: eventInfo.eirp,
|
|
255
|
+
eiack: eventInfo.eiack,
|
|
256
|
+
eir: eventInfo.eir
|
|
257
|
+
};
|
|
749
258
|
}
|
|
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
259
|
function createEventInfoFromParameters(eventType, event, targetElement, container, timestamp, action, isReplay, a11yClickKey) {
|
|
757
|
-
|
|
758
|
-
|
|
759
|
-
|
|
760
|
-
|
|
761
|
-
|
|
762
|
-
|
|
763
|
-
|
|
764
|
-
|
|
765
|
-
|
|
766
|
-
|
|
260
|
+
return {
|
|
261
|
+
eventType,
|
|
262
|
+
event,
|
|
263
|
+
targetElement,
|
|
264
|
+
eic: container,
|
|
265
|
+
timeStamp: timestamp,
|
|
266
|
+
eia: action,
|
|
267
|
+
eirp: isReplay,
|
|
268
|
+
eiack: a11yClickKey
|
|
269
|
+
};
|
|
767
270
|
}
|
|
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
271
|
class EventInfoWrapper {
|
|
775
|
-
|
|
776
|
-
|
|
777
|
-
|
|
778
|
-
|
|
779
|
-
|
|
780
|
-
|
|
781
|
-
|
|
782
|
-
|
|
783
|
-
|
|
784
|
-
|
|
785
|
-
|
|
786
|
-
|
|
787
|
-
|
|
788
|
-
|
|
789
|
-
|
|
790
|
-
|
|
791
|
-
|
|
792
|
-
|
|
793
|
-
|
|
794
|
-
|
|
795
|
-
|
|
796
|
-
|
|
797
|
-
|
|
798
|
-
|
|
799
|
-
|
|
800
|
-
|
|
801
|
-
|
|
802
|
-
|
|
803
|
-
|
|
804
|
-
|
|
805
|
-
|
|
806
|
-
|
|
807
|
-
|
|
808
|
-
|
|
809
|
-
|
|
810
|
-
|
|
811
|
-
|
|
812
|
-
|
|
813
|
-
|
|
814
|
-
|
|
815
|
-
|
|
816
|
-
|
|
817
|
-
|
|
818
|
-
|
|
819
|
-
|
|
820
|
-
|
|
821
|
-
|
|
822
|
-
|
|
823
|
-
|
|
824
|
-
|
|
825
|
-
getIsReplay()
|
|
826
|
-
|
|
827
|
-
|
|
828
|
-
setIsReplay(replay)
|
|
829
|
-
|
|
830
|
-
|
|
831
|
-
getResolved()
|
|
832
|
-
|
|
833
|
-
|
|
834
|
-
setResolved(resolved)
|
|
835
|
-
|
|
836
|
-
|
|
837
|
-
|
|
838
|
-
|
|
839
|
-
}
|
|
272
|
+
eventInfo;
|
|
273
|
+
constructor(eventInfo) {
|
|
274
|
+
this.eventInfo = eventInfo;
|
|
275
|
+
}
|
|
276
|
+
getEventType() {
|
|
277
|
+
return getEventType(this.eventInfo);
|
|
278
|
+
}
|
|
279
|
+
setEventType(eventType) {
|
|
280
|
+
setEventType(this.eventInfo, eventType);
|
|
281
|
+
}
|
|
282
|
+
getEvent() {
|
|
283
|
+
return getEvent(this.eventInfo);
|
|
284
|
+
}
|
|
285
|
+
setEvent(event) {
|
|
286
|
+
setEvent(this.eventInfo, event);
|
|
287
|
+
}
|
|
288
|
+
getTargetElement() {
|
|
289
|
+
return getTargetElement(this.eventInfo);
|
|
290
|
+
}
|
|
291
|
+
setTargetElement(targetElement) {
|
|
292
|
+
setTargetElement(this.eventInfo, targetElement);
|
|
293
|
+
}
|
|
294
|
+
getContainer() {
|
|
295
|
+
return getContainer(this.eventInfo);
|
|
296
|
+
}
|
|
297
|
+
setContainer(container) {
|
|
298
|
+
setContainer(this.eventInfo, container);
|
|
299
|
+
}
|
|
300
|
+
getTimestamp() {
|
|
301
|
+
return getTimestamp(this.eventInfo);
|
|
302
|
+
}
|
|
303
|
+
setTimestamp(timestamp) {
|
|
304
|
+
setTimestamp(this.eventInfo, timestamp);
|
|
305
|
+
}
|
|
306
|
+
getAction() {
|
|
307
|
+
const action = getAction(this.eventInfo);
|
|
308
|
+
if (!action) return undefined;
|
|
309
|
+
return {
|
|
310
|
+
name: action[0],
|
|
311
|
+
element: action[1]
|
|
312
|
+
};
|
|
313
|
+
}
|
|
314
|
+
setAction(action) {
|
|
315
|
+
if (!action) {
|
|
316
|
+
unsetAction(this.eventInfo);
|
|
317
|
+
return;
|
|
318
|
+
}
|
|
319
|
+
setAction(this.eventInfo, action.name, action.element);
|
|
320
|
+
}
|
|
321
|
+
getIsReplay() {
|
|
322
|
+
return getIsReplay(this.eventInfo);
|
|
323
|
+
}
|
|
324
|
+
setIsReplay(replay) {
|
|
325
|
+
setIsReplay(this.eventInfo, replay);
|
|
326
|
+
}
|
|
327
|
+
getResolved() {
|
|
328
|
+
return getResolved(this.eventInfo);
|
|
329
|
+
}
|
|
330
|
+
setResolved(resolved) {
|
|
331
|
+
setResolved(this.eventInfo, resolved);
|
|
332
|
+
}
|
|
333
|
+
clone() {
|
|
334
|
+
return new EventInfoWrapper(cloneEventInfo(this.eventInfo));
|
|
335
|
+
}
|
|
840
336
|
}
|
|
841
337
|
|
|
842
|
-
/**
|
|
843
|
-
* Since maps from event to action are immutable we can use a single map
|
|
844
|
-
* to represent the empty map.
|
|
845
|
-
*/
|
|
846
338
|
const EMPTY_ACTION_MAP = {};
|
|
847
|
-
/**
|
|
848
|
-
* This regular expression matches a semicolon.
|
|
849
|
-
*/
|
|
850
339
|
const REGEXP_SEMICOLON = /\s*;\s*/;
|
|
851
|
-
/** If no event type is defined, defaults to `click`. */
|
|
852
340
|
const DEFAULT_EVENT_TYPE = EventType.CLICK;
|
|
853
|
-
/** Resolves actions for Events. */
|
|
854
341
|
class ActionResolver {
|
|
855
|
-
|
|
856
|
-
|
|
857
|
-
|
|
858
|
-
|
|
859
|
-
|
|
860
|
-
|
|
861
|
-
|
|
862
|
-
|
|
863
|
-
|
|
864
|
-
|
|
865
|
-
|
|
866
|
-
|
|
867
|
-
|
|
868
|
-
|
|
869
|
-
|
|
870
|
-
|
|
871
|
-
|
|
872
|
-
|
|
873
|
-
|
|
874
|
-
|
|
875
|
-
|
|
876
|
-
|
|
877
|
-
|
|
878
|
-
|
|
879
|
-
|
|
880
|
-
|
|
881
|
-
|
|
882
|
-
|
|
883
|
-
|
|
884
|
-
|
|
885
|
-
|
|
886
|
-
|
|
887
|
-
|
|
888
|
-
|
|
889
|
-
|
|
890
|
-
|
|
891
|
-
|
|
892
|
-
|
|
893
|
-
|
|
894
|
-
|
|
895
|
-
|
|
896
|
-
|
|
897
|
-
|
|
898
|
-
|
|
899
|
-
|
|
900
|
-
|
|
901
|
-
|
|
902
|
-
|
|
903
|
-
|
|
904
|
-
|
|
905
|
-
|
|
906
|
-
|
|
907
|
-
|
|
908
|
-
|
|
909
|
-
|
|
910
|
-
|
|
911
|
-
|
|
912
|
-
|
|
913
|
-
|
|
914
|
-
|
|
915
|
-
|
|
916
|
-
|
|
917
|
-
|
|
918
|
-
|
|
919
|
-
|
|
920
|
-
|
|
921
|
-
|
|
922
|
-
|
|
923
|
-
|
|
924
|
-
|
|
925
|
-
|
|
926
|
-
|
|
927
|
-
|
|
928
|
-
|
|
929
|
-
|
|
930
|
-
|
|
931
|
-
|
|
932
|
-
|
|
933
|
-
|
|
934
|
-
|
|
935
|
-
|
|
936
|
-
|
|
937
|
-
|
|
938
|
-
|
|
939
|
-
|
|
940
|
-
|
|
941
|
-
|
|
942
|
-
|
|
943
|
-
|
|
944
|
-
|
|
945
|
-
|
|
946
|
-
|
|
947
|
-
|
|
948
|
-
|
|
949
|
-
|
|
950
|
-
|
|
951
|
-
|
|
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);
|
|
342
|
+
a11yClickSupport = false;
|
|
343
|
+
clickModSupport = true;
|
|
344
|
+
syntheticMouseEventSupport;
|
|
345
|
+
updateEventInfoForA11yClick = undefined;
|
|
346
|
+
preventDefaultForA11yClick = undefined;
|
|
347
|
+
populateClickOnlyAction = undefined;
|
|
348
|
+
constructor({
|
|
349
|
+
syntheticMouseEventSupport = false,
|
|
350
|
+
clickModSupport = true
|
|
351
|
+
} = {}) {
|
|
352
|
+
this.syntheticMouseEventSupport = syntheticMouseEventSupport;
|
|
353
|
+
this.clickModSupport = clickModSupport;
|
|
354
|
+
}
|
|
355
|
+
resolveEventType(eventInfo) {
|
|
356
|
+
if (this.clickModSupport && getEventType(eventInfo) === EventType.CLICK && isModifiedClickEvent(getEvent(eventInfo))) {
|
|
357
|
+
setEventType(eventInfo, EventType.CLICKMOD);
|
|
358
|
+
} else if (this.a11yClickSupport) {
|
|
359
|
+
this.updateEventInfoForA11yClick(eventInfo);
|
|
360
|
+
}
|
|
361
|
+
}
|
|
362
|
+
resolveAction(eventInfo) {
|
|
363
|
+
if (getResolved(eventInfo)) {
|
|
364
|
+
return;
|
|
365
|
+
}
|
|
366
|
+
this.populateAction(eventInfo, getTargetElement(eventInfo));
|
|
367
|
+
setResolved(eventInfo, true);
|
|
368
|
+
}
|
|
369
|
+
resolveParentAction(eventInfo) {
|
|
370
|
+
const action = getAction(eventInfo);
|
|
371
|
+
const actionElement = action && getActionElement(action);
|
|
372
|
+
unsetAction(eventInfo);
|
|
373
|
+
const parentNode = actionElement && this.getParentNode(actionElement);
|
|
374
|
+
if (!parentNode) {
|
|
375
|
+
return;
|
|
376
|
+
}
|
|
377
|
+
this.populateAction(eventInfo, parentNode);
|
|
378
|
+
}
|
|
379
|
+
populateAction(eventInfo, currentTarget) {
|
|
380
|
+
let actionElement = currentTarget;
|
|
381
|
+
while (actionElement && actionElement !== getContainer(eventInfo)) {
|
|
382
|
+
if (actionElement.nodeType === Node.ELEMENT_NODE) {
|
|
383
|
+
this.populateActionOnElement(actionElement, eventInfo);
|
|
384
|
+
}
|
|
385
|
+
if (getAction(eventInfo)) {
|
|
386
|
+
break;
|
|
387
|
+
}
|
|
388
|
+
actionElement = this.getParentNode(actionElement);
|
|
389
|
+
}
|
|
390
|
+
const action = getAction(eventInfo);
|
|
391
|
+
if (!action) {
|
|
392
|
+
return;
|
|
393
|
+
}
|
|
394
|
+
if (this.a11yClickSupport) {
|
|
395
|
+
this.preventDefaultForA11yClick(eventInfo);
|
|
396
|
+
}
|
|
397
|
+
if (this.syntheticMouseEventSupport) {
|
|
398
|
+
if (getEventType(eventInfo) === EventType.MOUSEENTER || getEventType(eventInfo) === EventType.MOUSELEAVE || getEventType(eventInfo) === EventType.POINTERENTER || getEventType(eventInfo) === EventType.POINTERLEAVE) {
|
|
399
|
+
if (isMouseSpecialEvent(getEvent(eventInfo), getEventType(eventInfo), getActionElement(action))) {
|
|
400
|
+
const copiedEvent = createMouseSpecialEvent(getEvent(eventInfo), getActionElement(action));
|
|
401
|
+
setEvent(eventInfo, copiedEvent);
|
|
402
|
+
setTargetElement(eventInfo, getActionElement(action));
|
|
403
|
+
} else {
|
|
404
|
+
unsetAction(eventInfo);
|
|
405
|
+
}
|
|
406
|
+
}
|
|
407
|
+
}
|
|
408
|
+
}
|
|
409
|
+
getParentNode(element) {
|
|
410
|
+
const owner = element[Property.OWNER];
|
|
411
|
+
if (owner) {
|
|
412
|
+
return owner;
|
|
413
|
+
}
|
|
414
|
+
const parentNode = element.parentNode;
|
|
415
|
+
if (parentNode?.nodeName === '#document-fragment') {
|
|
416
|
+
return parentNode?.host ?? null;
|
|
417
|
+
}
|
|
418
|
+
return parentNode;
|
|
419
|
+
}
|
|
420
|
+
populateActionOnElement(actionElement, eventInfo) {
|
|
421
|
+
const actionMap = this.parseActions(actionElement);
|
|
422
|
+
const actionName = actionMap[getEventType(eventInfo)];
|
|
423
|
+
if (actionName !== undefined) {
|
|
424
|
+
setAction(eventInfo, actionName, actionElement);
|
|
425
|
+
}
|
|
426
|
+
if (this.a11yClickSupport) {
|
|
427
|
+
this.populateClickOnlyAction(actionElement, eventInfo, actionMap);
|
|
428
|
+
}
|
|
429
|
+
}
|
|
430
|
+
parseActions(actionElement) {
|
|
431
|
+
let actionMap = get(actionElement);
|
|
432
|
+
if (!actionMap) {
|
|
433
|
+
const jsactionAttribute = actionElement.getAttribute(Attribute.JSACTION);
|
|
434
|
+
if (!jsactionAttribute) {
|
|
435
|
+
actionMap = EMPTY_ACTION_MAP;
|
|
436
|
+
set(actionElement, actionMap);
|
|
437
|
+
} else {
|
|
438
|
+
actionMap = getParsed(jsactionAttribute);
|
|
1036
439
|
if (!actionMap) {
|
|
1037
|
-
|
|
1038
|
-
|
|
1039
|
-
|
|
1040
|
-
|
|
440
|
+
actionMap = {};
|
|
441
|
+
const values = jsactionAttribute.split(REGEXP_SEMICOLON);
|
|
442
|
+
for (let idx = 0; idx < values.length; idx++) {
|
|
443
|
+
const value = values[idx];
|
|
444
|
+
if (!value) {
|
|
445
|
+
continue;
|
|
1041
446
|
}
|
|
1042
|
-
|
|
1043
|
-
|
|
1044
|
-
|
|
1045
|
-
|
|
1046
|
-
|
|
1047
|
-
|
|
1048
|
-
|
|
1049
|
-
|
|
1050
|
-
|
|
1051
|
-
|
|
1052
|
-
|
|
1053
|
-
|
|
1054
|
-
|
|
1055
|
-
|
|
1056
|
-
|
|
1057
|
-
|
|
1058
|
-
|
|
1059
|
-
|
|
1060
|
-
|
|
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
|
-
}
|
|
447
|
+
const colon = value.indexOf(Char.EVENT_ACTION_SEPARATOR);
|
|
448
|
+
const hasColon = colon !== -1;
|
|
449
|
+
const type = hasColon ? value.substr(0, colon).trim() : DEFAULT_EVENT_TYPE;
|
|
450
|
+
const action = hasColon ? value.substr(colon + 1).trim() : value;
|
|
451
|
+
actionMap[type] = action;
|
|
452
|
+
}
|
|
453
|
+
setParsed(jsactionAttribute, actionMap);
|
|
454
|
+
}
|
|
455
|
+
set(actionElement, actionMap);
|
|
456
|
+
}
|
|
457
|
+
}
|
|
458
|
+
return actionMap;
|
|
459
|
+
}
|
|
460
|
+
addA11yClickSupport(updateEventInfoForA11yClick, preventDefaultForA11yClick, populateClickOnlyAction) {
|
|
461
|
+
this.a11yClickSupport = true;
|
|
462
|
+
this.updateEventInfoForA11yClick = updateEventInfoForA11yClick;
|
|
463
|
+
this.preventDefaultForA11yClick = preventDefaultForA11yClick;
|
|
464
|
+
this.populateClickOnlyAction = populateClickOnlyAction;
|
|
465
|
+
}
|
|
1071
466
|
}
|
|
1072
467
|
|
|
1073
|
-
/**
|
|
1074
|
-
* @fileoverview An enum to control who can call certain jsaction APIs.
|
|
1075
|
-
*/
|
|
1076
468
|
var Restriction;
|
|
1077
469
|
(function (Restriction) {
|
|
1078
|
-
|
|
470
|
+
Restriction[Restriction["I_AM_THE_JSACTION_FRAMEWORK"] = 0] = "I_AM_THE_JSACTION_FRAMEWORK";
|
|
1079
471
|
})(Restriction || (Restriction = {}));
|
|
1080
472
|
|
|
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
473
|
class Dispatcher {
|
|
1087
|
-
|
|
1088
|
-
|
|
1089
|
-
|
|
1090
|
-
|
|
1091
|
-
|
|
1092
|
-
|
|
1093
|
-
|
|
1094
|
-
|
|
1095
|
-
|
|
1096
|
-
|
|
1097
|
-
|
|
1098
|
-
|
|
1099
|
-
|
|
1100
|
-
|
|
1101
|
-
|
|
1102
|
-
|
|
1103
|
-
|
|
1104
|
-
|
|
1105
|
-
|
|
1106
|
-
|
|
1107
|
-
}
|
|
1108
|
-
|
|
1109
|
-
|
|
1110
|
-
|
|
1111
|
-
|
|
1112
|
-
|
|
1113
|
-
|
|
1114
|
-
|
|
1115
|
-
|
|
1116
|
-
|
|
1117
|
-
|
|
1118
|
-
|
|
1119
|
-
|
|
1120
|
-
|
|
1121
|
-
|
|
1122
|
-
|
|
1123
|
-
|
|
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
|
-
}
|
|
474
|
+
dispatchDelegate;
|
|
475
|
+
actionResolver;
|
|
476
|
+
eventReplayer;
|
|
477
|
+
eventReplayScheduled = false;
|
|
478
|
+
replayEventInfoWrappers = [];
|
|
479
|
+
constructor(dispatchDelegate, {
|
|
480
|
+
actionResolver,
|
|
481
|
+
eventReplayer
|
|
482
|
+
} = {}) {
|
|
483
|
+
this.dispatchDelegate = dispatchDelegate;
|
|
484
|
+
this.actionResolver = actionResolver;
|
|
485
|
+
this.eventReplayer = eventReplayer;
|
|
486
|
+
}
|
|
487
|
+
dispatch(eventInfo) {
|
|
488
|
+
const eventInfoWrapper = new EventInfoWrapper(eventInfo);
|
|
489
|
+
this.actionResolver?.resolveEventType(eventInfo);
|
|
490
|
+
this.actionResolver?.resolveAction(eventInfo);
|
|
491
|
+
const action = eventInfoWrapper.getAction();
|
|
492
|
+
if (action && shouldPreventDefaultBeforeDispatching(action.element, eventInfoWrapper)) {
|
|
493
|
+
preventDefault(eventInfoWrapper.getEvent());
|
|
494
|
+
}
|
|
495
|
+
if (this.eventReplayer && eventInfoWrapper.getIsReplay()) {
|
|
496
|
+
this.scheduleEventInfoWrapperReplay(eventInfoWrapper);
|
|
497
|
+
return;
|
|
498
|
+
}
|
|
499
|
+
this.dispatchDelegate(eventInfoWrapper);
|
|
500
|
+
}
|
|
501
|
+
scheduleEventInfoWrapperReplay(eventInfoWrapper) {
|
|
502
|
+
this.replayEventInfoWrappers.push(eventInfoWrapper);
|
|
503
|
+
if (this.eventReplayScheduled) {
|
|
504
|
+
return;
|
|
505
|
+
}
|
|
506
|
+
this.eventReplayScheduled = true;
|
|
507
|
+
Promise.resolve().then(() => {
|
|
508
|
+
this.eventReplayScheduled = false;
|
|
509
|
+
this.eventReplayer(this.replayEventInfoWrappers);
|
|
510
|
+
});
|
|
511
|
+
}
|
|
1158
512
|
}
|
|
1159
|
-
/**
|
|
1160
|
-
* Returns true if the default action of this event should be prevented before
|
|
1161
|
-
* this event is dispatched.
|
|
1162
|
-
*/
|
|
1163
513
|
function shouldPreventDefaultBeforeDispatching(actionElement, eventInfoWrapper) {
|
|
1164
|
-
|
|
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));
|
|
514
|
+
return actionElement.tagName === 'A' && (eventInfoWrapper.getEventType() === EventType.CLICK || eventInfoWrapper.getEventType() === EventType.CLICKMOD);
|
|
1171
515
|
}
|
|
1172
516
|
|
|
1173
|
-
|
|
1174
|
-
const PROPAGATION_STOPPED_SYMBOL =
|
|
1175
|
-
/* @__PURE__ */ Symbol.for('propagationStopped');
|
|
1176
|
-
/** Extra event phases beyond what the browser provides. */
|
|
517
|
+
const PROPAGATION_STOPPED_SYMBOL = /* @__PURE__ */Symbol.for('propagationStopped');
|
|
1177
518
|
const EventPhase = {
|
|
1178
|
-
|
|
519
|
+
REPLAY: 101
|
|
1179
520
|
};
|
|
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`.';
|
|
521
|
+
const PREVENT_DEFAULT_ERROR_MESSAGE_DETAILS = ' Because event replay occurs after browser dispatch, `preventDefault` would have no ' + 'effect. You can check whether an event is being replayed by accessing the event phase: ' + '`event.eventPhase === EventPhase.REPLAY`.';
|
|
1183
522
|
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.';
|
|
523
|
+
const COMPOSED_PATH_ERROR_MESSAGE_DETAILS = ' Because event replay occurs after browser ' + 'dispatch, `composedPath()` will be empty. Iterate parent nodes from `event.target` or ' + '`event.currentTarget` if you need to check elements in the event path.';
|
|
1187
524
|
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
525
|
class EventDispatcher {
|
|
1193
|
-
|
|
1194
|
-
|
|
1195
|
-
|
|
1196
|
-
|
|
1197
|
-
|
|
1198
|
-
|
|
1199
|
-
|
|
1200
|
-
|
|
1201
|
-
|
|
1202
|
-
|
|
1203
|
-
|
|
1204
|
-
|
|
1205
|
-
|
|
1206
|
-
|
|
1207
|
-
|
|
1208
|
-
|
|
1209
|
-
|
|
1210
|
-
dispatch(eventInfo)
|
|
1211
|
-
|
|
1212
|
-
|
|
1213
|
-
|
|
1214
|
-
|
|
1215
|
-
|
|
1216
|
-
|
|
1217
|
-
|
|
1218
|
-
|
|
1219
|
-
|
|
1220
|
-
|
|
1221
|
-
|
|
1222
|
-
|
|
1223
|
-
|
|
1224
|
-
|
|
1225
|
-
|
|
1226
|
-
|
|
1227
|
-
if (propagationStopped(eventInfoWrapper)) {
|
|
1228
|
-
return;
|
|
1229
|
-
}
|
|
1230
|
-
this.actionResolver.resolveParentAction(eventInfoWrapper.eventInfo);
|
|
1231
|
-
}
|
|
526
|
+
dispatchDelegate;
|
|
527
|
+
clickModSupport;
|
|
528
|
+
actionResolver;
|
|
529
|
+
dispatcher;
|
|
530
|
+
constructor(dispatchDelegate, clickModSupport = true) {
|
|
531
|
+
this.dispatchDelegate = dispatchDelegate;
|
|
532
|
+
this.clickModSupport = clickModSupport;
|
|
533
|
+
this.actionResolver = new ActionResolver({
|
|
534
|
+
clickModSupport
|
|
535
|
+
});
|
|
536
|
+
this.dispatcher = new Dispatcher(eventInfoWrapper => {
|
|
537
|
+
this.dispatchToDelegate(eventInfoWrapper);
|
|
538
|
+
}, {
|
|
539
|
+
actionResolver: this.actionResolver
|
|
540
|
+
});
|
|
541
|
+
}
|
|
542
|
+
dispatch(eventInfo) {
|
|
543
|
+
this.dispatcher.dispatch(eventInfo);
|
|
544
|
+
}
|
|
545
|
+
dispatchToDelegate(eventInfoWrapper) {
|
|
546
|
+
if (eventInfoWrapper.getIsReplay()) {
|
|
547
|
+
prepareEventForReplay(eventInfoWrapper);
|
|
548
|
+
}
|
|
549
|
+
prepareEventForBubbling(eventInfoWrapper);
|
|
550
|
+
while (eventInfoWrapper.getAction()) {
|
|
551
|
+
prepareEventForDispatch(eventInfoWrapper);
|
|
552
|
+
if (isCaptureEventType(eventInfoWrapper.getEventType()) && eventInfoWrapper.getAction().element !== eventInfoWrapper.getTargetElement()) {
|
|
553
|
+
return;
|
|
554
|
+
}
|
|
555
|
+
this.dispatchDelegate(eventInfoWrapper.getEvent(), eventInfoWrapper.getAction().name);
|
|
556
|
+
if (propagationStopped(eventInfoWrapper)) {
|
|
557
|
+
return;
|
|
558
|
+
}
|
|
559
|
+
this.actionResolver.resolveParentAction(eventInfoWrapper.eventInfo);
|
|
1232
560
|
}
|
|
561
|
+
}
|
|
1233
562
|
}
|
|
1234
563
|
function prepareEventForBubbling(eventInfoWrapper) {
|
|
1235
|
-
|
|
1236
|
-
|
|
1237
|
-
|
|
1238
|
-
|
|
1239
|
-
|
|
1240
|
-
|
|
1241
|
-
|
|
1242
|
-
|
|
564
|
+
const event = eventInfoWrapper.getEvent();
|
|
565
|
+
const originalStopPropagation = eventInfoWrapper.getEvent().stopPropagation.bind(event);
|
|
566
|
+
const stopPropagation = () => {
|
|
567
|
+
event[PROPAGATION_STOPPED_SYMBOL] = true;
|
|
568
|
+
originalStopPropagation();
|
|
569
|
+
};
|
|
570
|
+
patchEventInstance(event, 'stopPropagation', stopPropagation);
|
|
571
|
+
patchEventInstance(event, 'stopImmediatePropagation', stopPropagation);
|
|
1243
572
|
}
|
|
1244
573
|
function propagationStopped(eventInfoWrapper) {
|
|
1245
|
-
|
|
1246
|
-
|
|
574
|
+
const event = eventInfoWrapper.getEvent();
|
|
575
|
+
return !!event[PROPAGATION_STOPPED_SYMBOL];
|
|
1247
576
|
}
|
|
1248
577
|
function prepareEventForReplay(eventInfoWrapper) {
|
|
1249
|
-
|
|
1250
|
-
|
|
1251
|
-
|
|
1252
|
-
|
|
1253
|
-
|
|
1254
|
-
|
|
1255
|
-
|
|
1256
|
-
|
|
1257
|
-
|
|
1258
|
-
|
|
1259
|
-
|
|
1260
|
-
|
|
578
|
+
const event = eventInfoWrapper.getEvent();
|
|
579
|
+
const target = eventInfoWrapper.getTargetElement();
|
|
580
|
+
const originalPreventDefault = event.preventDefault.bind(event);
|
|
581
|
+
patchEventInstance(event, 'target', target);
|
|
582
|
+
patchEventInstance(event, 'eventPhase', EventPhase.REPLAY);
|
|
583
|
+
patchEventInstance(event, 'preventDefault', () => {
|
|
584
|
+
originalPreventDefault();
|
|
585
|
+
throw new Error(PREVENT_DEFAULT_ERROR_MESSAGE + (ngDevMode ? PREVENT_DEFAULT_ERROR_MESSAGE_DETAILS : ''));
|
|
586
|
+
});
|
|
587
|
+
patchEventInstance(event, 'composedPath', () => {
|
|
588
|
+
throw new Error(COMPOSED_PATH_ERROR_MESSAGE + (ngDevMode ? COMPOSED_PATH_ERROR_MESSAGE_DETAILS : ''));
|
|
589
|
+
});
|
|
1261
590
|
}
|
|
1262
591
|
function prepareEventForDispatch(eventInfoWrapper) {
|
|
1263
|
-
|
|
1264
|
-
|
|
1265
|
-
|
|
1266
|
-
|
|
1267
|
-
|
|
1268
|
-
|
|
1269
|
-
|
|
1270
|
-
}
|
|
592
|
+
const event = eventInfoWrapper.getEvent();
|
|
593
|
+
const currentTarget = eventInfoWrapper.getAction()?.element;
|
|
594
|
+
if (currentTarget) {
|
|
595
|
+
patchEventInstance(event, 'currentTarget', currentTarget, {
|
|
596
|
+
configurable: true
|
|
597
|
+
});
|
|
598
|
+
}
|
|
1271
599
|
}
|
|
1272
|
-
|
|
1273
|
-
|
|
1274
|
-
|
|
1275
|
-
|
|
1276
|
-
|
|
1277
|
-
|
|
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 });
|
|
600
|
+
function patchEventInstance(event, property, value, {
|
|
601
|
+
configurable = false
|
|
602
|
+
} = {}) {
|
|
603
|
+
Object.defineProperty(event, property, {
|
|
604
|
+
value,
|
|
605
|
+
configurable
|
|
606
|
+
});
|
|
1295
607
|
}
|
|
1296
|
-
/**
|
|
1297
|
-
* Registers deferred functionality for an EventContract and a Jsaction
|
|
1298
|
-
* Dispatcher.
|
|
1299
|
-
*/
|
|
1300
608
|
function registerDispatcher$1(eventContract, dispatcher) {
|
|
1301
|
-
|
|
1302
|
-
|
|
1303
|
-
|
|
609
|
+
eventContract.ecrd(eventInfo => {
|
|
610
|
+
dispatcher.dispatch(eventInfo);
|
|
611
|
+
}, Restriction.I_AM_THE_JSACTION_FRAMEWORK);
|
|
1304
612
|
}
|
|
1305
613
|
|
|
1306
|
-
/** Creates an `EarlyJsactionData` object. */
|
|
1307
614
|
function createEarlyJsactionData(container) {
|
|
1308
|
-
|
|
1309
|
-
|
|
1310
|
-
|
|
1311
|
-
|
|
1312
|
-
|
|
1313
|
-
|
|
1314
|
-
|
|
1315
|
-
|
|
1316
|
-
|
|
1317
|
-
|
|
1318
|
-
|
|
1319
|
-
|
|
1320
|
-
|
|
1321
|
-
|
|
1322
|
-
|
|
615
|
+
const q = [];
|
|
616
|
+
const d = eventInfo => {
|
|
617
|
+
q.push(eventInfo);
|
|
618
|
+
};
|
|
619
|
+
const h = event => {
|
|
620
|
+
d(createEventInfoFromParameters(event.type, event, event.target, container, Date.now()));
|
|
621
|
+
};
|
|
622
|
+
return {
|
|
623
|
+
c: container,
|
|
624
|
+
q,
|
|
625
|
+
et: [],
|
|
626
|
+
etc: [],
|
|
627
|
+
d,
|
|
628
|
+
h
|
|
629
|
+
};
|
|
1323
630
|
}
|
|
1324
|
-
/** Add all the events to the container stored in the `EarlyJsactionData`. */
|
|
1325
631
|
function addEvents(earlyJsactionData, types, capture) {
|
|
1326
|
-
|
|
1327
|
-
|
|
1328
|
-
|
|
1329
|
-
|
|
1330
|
-
|
|
1331
|
-
|
|
632
|
+
for (let i = 0; i < types.length; i++) {
|
|
633
|
+
const eventType = types[i];
|
|
634
|
+
const eventTypes = capture ? earlyJsactionData.etc : earlyJsactionData.et;
|
|
635
|
+
eventTypes.push(eventType);
|
|
636
|
+
earlyJsactionData.c.addEventListener(eventType, earlyJsactionData.h, capture);
|
|
637
|
+
}
|
|
1332
638
|
}
|
|
1333
|
-
/** Get the queued `EventInfo` objects that were dispatched before a dispatcher was registered. */
|
|
1334
639
|
function getQueuedEventInfos(earlyJsactionData) {
|
|
1335
|
-
|
|
640
|
+
return earlyJsactionData?.q ?? [];
|
|
1336
641
|
}
|
|
1337
|
-
/** Register a different dispatcher function on the `EarlyJsactionData`. */
|
|
1338
642
|
function registerDispatcher(earlyJsactionData, dispatcher) {
|
|
1339
|
-
|
|
1340
|
-
|
|
1341
|
-
|
|
1342
|
-
|
|
643
|
+
if (!earlyJsactionData) {
|
|
644
|
+
return;
|
|
645
|
+
}
|
|
646
|
+
earlyJsactionData.d = dispatcher;
|
|
1343
647
|
}
|
|
1344
|
-
/** Removes all event listener handlers. */
|
|
1345
648
|
function removeAllEventListeners(earlyJsactionData) {
|
|
1346
|
-
|
|
1347
|
-
|
|
1348
|
-
|
|
1349
|
-
|
|
1350
|
-
|
|
649
|
+
if (!earlyJsactionData) {
|
|
650
|
+
return;
|
|
651
|
+
}
|
|
652
|
+
removeEventListeners(earlyJsactionData.c, earlyJsactionData.et, earlyJsactionData.h);
|
|
653
|
+
removeEventListeners(earlyJsactionData.c, earlyJsactionData.etc, earlyJsactionData.h, true);
|
|
1351
654
|
}
|
|
1352
655
|
function removeEventListeners(container, eventTypes, earlyEventHandler, capture) {
|
|
1353
|
-
|
|
1354
|
-
|
|
1355
|
-
|
|
656
|
+
for (let i = 0; i < eventTypes.length; i++) {
|
|
657
|
+
container.removeEventListener(eventTypes[i], earlyEventHandler, capture);
|
|
658
|
+
}
|
|
1356
659
|
}
|
|
1357
660
|
|
|
1358
|
-
/**
|
|
1359
|
-
* @define Support for the non-bubbling mouseenter and mouseleave events. This
|
|
1360
|
-
* flag can be overridden in a build rule.
|
|
1361
|
-
*/
|
|
1362
661
|
const MOUSE_SPECIAL_SUPPORT = false;
|
|
1363
662
|
|
|
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
663
|
class EventContract {
|
|
1402
|
-
|
|
1403
|
-
|
|
1404
|
-
|
|
1405
|
-
|
|
1406
|
-
|
|
1407
|
-
|
|
1408
|
-
|
|
1409
|
-
|
|
1410
|
-
|
|
1411
|
-
|
|
1412
|
-
|
|
1413
|
-
|
|
1414
|
-
|
|
1415
|
-
|
|
1416
|
-
|
|
1417
|
-
|
|
1418
|
-
|
|
1419
|
-
|
|
1420
|
-
|
|
1421
|
-
|
|
1422
|
-
|
|
1423
|
-
|
|
1424
|
-
|
|
1425
|
-
|
|
1426
|
-
|
|
1427
|
-
|
|
1428
|
-
|
|
1429
|
-
|
|
1430
|
-
|
|
1431
|
-
|
|
1432
|
-
|
|
1433
|
-
|
|
1434
|
-
|
|
1435
|
-
|
|
664
|
+
static MOUSE_SPECIAL_SUPPORT = MOUSE_SPECIAL_SUPPORT;
|
|
665
|
+
containerManager;
|
|
666
|
+
eventHandlers = {};
|
|
667
|
+
browserEventTypeToExtraEventTypes = {};
|
|
668
|
+
dispatcher = null;
|
|
669
|
+
queuedEventInfos = [];
|
|
670
|
+
constructor(containerManager) {
|
|
671
|
+
this.containerManager = containerManager;
|
|
672
|
+
}
|
|
673
|
+
handleEvent(eventType, event, container) {
|
|
674
|
+
const eventInfo = createEventInfoFromParameters(eventType, event, event.target, container, Date.now());
|
|
675
|
+
this.handleEventInfo(eventInfo);
|
|
676
|
+
}
|
|
677
|
+
handleEventInfo(eventInfo) {
|
|
678
|
+
if (!this.dispatcher) {
|
|
679
|
+
setIsReplay(eventInfo, true);
|
|
680
|
+
this.queuedEventInfos?.push(eventInfo);
|
|
681
|
+
return;
|
|
682
|
+
}
|
|
683
|
+
this.dispatcher(eventInfo);
|
|
684
|
+
}
|
|
685
|
+
addEvent(eventType, prefixedEventType, passive) {
|
|
686
|
+
if (eventType in this.eventHandlers || !this.containerManager) {
|
|
687
|
+
return;
|
|
688
|
+
}
|
|
689
|
+
if (!EventContract.MOUSE_SPECIAL_SUPPORT && MOUSE_SPECIAL_EVENT_TYPES.indexOf(eventType) >= 0) {
|
|
690
|
+
return;
|
|
691
|
+
}
|
|
692
|
+
const eventHandler = (eventType, event, container) => {
|
|
693
|
+
this.handleEvent(eventType, event, container);
|
|
694
|
+
};
|
|
695
|
+
this.eventHandlers[eventType] = eventHandler;
|
|
696
|
+
const browserEventType = getBrowserEventType(prefixedEventType || eventType);
|
|
697
|
+
if (browserEventType !== eventType) {
|
|
698
|
+
const eventTypes = this.browserEventTypeToExtraEventTypes[browserEventType] || [];
|
|
699
|
+
eventTypes.push(eventType);
|
|
700
|
+
this.browserEventTypeToExtraEventTypes[browserEventType] = eventTypes;
|
|
701
|
+
}
|
|
702
|
+
this.containerManager.addEventListener(browserEventType, element => {
|
|
703
|
+
return event => {
|
|
704
|
+
eventHandler(eventType, event, element);
|
|
705
|
+
};
|
|
706
|
+
}, passive);
|
|
707
|
+
}
|
|
708
|
+
replayEarlyEvents(earlyJsactionData = window._ejsa) {
|
|
709
|
+
if (!earlyJsactionData) {
|
|
710
|
+
return;
|
|
711
|
+
}
|
|
712
|
+
this.replayEarlyEventInfos(earlyJsactionData.q);
|
|
713
|
+
removeAllEventListeners(earlyJsactionData);
|
|
714
|
+
delete window._ejsa;
|
|
715
|
+
}
|
|
716
|
+
replayEarlyEventInfos(earlyEventInfos) {
|
|
717
|
+
for (let i = 0; i < earlyEventInfos.length; i++) {
|
|
718
|
+
const earlyEventInfo = earlyEventInfos[i];
|
|
719
|
+
const eventTypes = this.getEventTypesForBrowserEventType(earlyEventInfo.eventType);
|
|
720
|
+
for (let j = 0; j < eventTypes.length; j++) {
|
|
721
|
+
const eventInfo = cloneEventInfo(earlyEventInfo);
|
|
722
|
+
setEventType(eventInfo, eventTypes[j]);
|
|
1436
723
|
this.handleEventInfo(eventInfo);
|
|
1437
|
-
|
|
1438
|
-
|
|
1439
|
-
|
|
1440
|
-
|
|
1441
|
-
|
|
1442
|
-
|
|
1443
|
-
|
|
1444
|
-
|
|
1445
|
-
|
|
1446
|
-
|
|
1447
|
-
|
|
1448
|
-
|
|
1449
|
-
|
|
1450
|
-
|
|
1451
|
-
|
|
1452
|
-
|
|
1453
|
-
|
|
1454
|
-
|
|
1455
|
-
|
|
1456
|
-
|
|
1457
|
-
|
|
1458
|
-
|
|
1459
|
-
|
|
1460
|
-
|
|
1461
|
-
|
|
1462
|
-
|
|
1463
|
-
|
|
1464
|
-
|
|
1465
|
-
|
|
1466
|
-
|
|
1467
|
-
|
|
1468
|
-
|
|
1469
|
-
|
|
1470
|
-
|
|
1471
|
-
|
|
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
|
-
}
|
|
724
|
+
}
|
|
725
|
+
}
|
|
726
|
+
}
|
|
727
|
+
getEventTypesForBrowserEventType(browserEventType) {
|
|
728
|
+
const eventTypes = [];
|
|
729
|
+
if (this.eventHandlers[browserEventType]) {
|
|
730
|
+
eventTypes.push(browserEventType);
|
|
731
|
+
}
|
|
732
|
+
if (this.browserEventTypeToExtraEventTypes[browserEventType]) {
|
|
733
|
+
eventTypes.push(...this.browserEventTypeToExtraEventTypes[browserEventType]);
|
|
734
|
+
}
|
|
735
|
+
return eventTypes;
|
|
736
|
+
}
|
|
737
|
+
handler(eventType) {
|
|
738
|
+
return this.eventHandlers[eventType];
|
|
739
|
+
}
|
|
740
|
+
cleanUp() {
|
|
741
|
+
this.containerManager?.cleanUp();
|
|
742
|
+
this.containerManager = null;
|
|
743
|
+
this.eventHandlers = {};
|
|
744
|
+
this.browserEventTypeToExtraEventTypes = {};
|
|
745
|
+
this.dispatcher = null;
|
|
746
|
+
this.queuedEventInfos = [];
|
|
747
|
+
}
|
|
748
|
+
registerDispatcher(dispatcher, restriction) {
|
|
749
|
+
this.ecrd(dispatcher, restriction);
|
|
750
|
+
}
|
|
751
|
+
ecrd(dispatcher, restriction) {
|
|
752
|
+
this.dispatcher = dispatcher;
|
|
753
|
+
if (this.queuedEventInfos?.length) {
|
|
754
|
+
for (let i = 0; i < this.queuedEventInfos.length; i++) {
|
|
755
|
+
this.handleEventInfo(this.queuedEventInfos[i]);
|
|
756
|
+
}
|
|
757
|
+
this.queuedEventInfos = null;
|
|
758
|
+
}
|
|
759
|
+
}
|
|
1583
760
|
}
|
|
1584
761
|
|
|
1585
|
-
/**
|
|
1586
|
-
* Creates an `EarlyJsactionData`, adds events to it, and populates it on a nested object on
|
|
1587
|
-
* the window.
|
|
1588
|
-
*/
|
|
1589
762
|
function bootstrapAppScopedEarlyEventContract(container, appId, bubbleEventTypes, captureEventTypes, dataContainer = window) {
|
|
1590
|
-
|
|
1591
|
-
|
|
1592
|
-
|
|
1593
|
-
|
|
1594
|
-
|
|
1595
|
-
|
|
1596
|
-
|
|
763
|
+
const earlyJsactionData = createEarlyJsactionData(container);
|
|
764
|
+
if (!dataContainer._ejsas) {
|
|
765
|
+
dataContainer._ejsas = {};
|
|
766
|
+
}
|
|
767
|
+
dataContainer._ejsas[appId] = earlyJsactionData;
|
|
768
|
+
addEvents(earlyJsactionData, bubbleEventTypes);
|
|
769
|
+
addEvents(earlyJsactionData, captureEventTypes, true);
|
|
1597
770
|
}
|
|
1598
|
-
/** Get the queued `EventInfo` objects that were dispatched before a dispatcher was registered. */
|
|
1599
771
|
function getAppScopedQueuedEventInfos(appId, dataContainer = window) {
|
|
1600
|
-
|
|
772
|
+
return getQueuedEventInfos(dataContainer._ejsas?.[appId]);
|
|
1601
773
|
}
|
|
1602
|
-
/**
|
|
1603
|
-
* Registers a dispatcher function on the `EarlyJsactionData` present on the nested object on the
|
|
1604
|
-
* window.
|
|
1605
|
-
*/
|
|
1606
774
|
function registerAppScopedDispatcher(restriction, appId, dispatcher, dataContainer = window) {
|
|
1607
|
-
|
|
775
|
+
registerDispatcher(dataContainer._ejsas?.[appId], dispatcher);
|
|
1608
776
|
}
|
|
1609
|
-
/** Removes all event listener handlers. */
|
|
1610
777
|
function removeAllAppScopedEventListeners(appId, dataContainer = window) {
|
|
1611
|
-
|
|
778
|
+
removeAllEventListeners(dataContainer._ejsas?.[appId]);
|
|
1612
779
|
}
|
|
1613
|
-
/** Clear the early event contract. */
|
|
1614
780
|
function clearAppScopedEarlyEventContract(appId, dataContainer = window) {
|
|
1615
|
-
|
|
1616
|
-
|
|
1617
|
-
|
|
1618
|
-
|
|
781
|
+
if (!dataContainer._ejsas) {
|
|
782
|
+
return;
|
|
783
|
+
}
|
|
784
|
+
dataContainer._ejsas[appId] = undefined;
|
|
1619
785
|
}
|
|
1620
786
|
|
|
1621
787
|
export { Attribute, EventContract, EventContractContainer, EventDispatcher, EventInfoWrapper, EventPhase, bootstrapAppScopedEarlyEventContract, clearAppScopedEarlyEventContract, getDefaulted as getActionCache, getAppScopedQueuedEventInfos, isCaptureEventType, isEarlyEventType, registerAppScopedDispatcher, registerDispatcher$1 as registerDispatcher, removeAllAppScopedEventListeners };
|