@angular/core 18.1.0 → 18.1.2

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.
Files changed (43) hide show
  1. package/esm2022/primitives/event-dispatch/contract_binary.mjs +3 -3
  2. package/esm2022/primitives/event-dispatch/index.mjs +7 -7
  3. package/esm2022/primitives/event-dispatch/src/a11y_click.mjs +1 -1
  4. package/esm2022/primitives/event-dispatch/src/action_resolver.mjs +1 -1
  5. package/esm2022/primitives/event-dispatch/src/bootstrap_app_scoped.mjs +44 -0
  6. package/esm2022/primitives/event-dispatch/src/bootstrap_global.mjs +32 -0
  7. package/esm2022/primitives/event-dispatch/src/cache.mjs +10 -21
  8. package/esm2022/primitives/event-dispatch/src/earlyeventcontract.mjs +56 -21
  9. package/esm2022/primitives/event-dispatch/src/event.mjs +3 -3
  10. package/esm2022/primitives/event-dispatch/src/event_contract_defines.mjs +1 -6
  11. package/esm2022/primitives/event-dispatch/src/event_type.mjs +19 -21
  12. package/esm2022/primitives/event-dispatch/src/eventcontract.mjs +44 -41
  13. package/esm2022/primitives/event-dispatch/src/property.mjs +1 -1
  14. package/esm2022/rxjs-interop/src/to_signal.mjs +6 -5
  15. package/esm2022/src/event_delegation_utils.mjs +9 -9
  16. package/esm2022/src/event_dispatch/event_delegation.mjs +2 -4
  17. package/esm2022/src/hydration/event_replay.mjs +19 -24
  18. package/esm2022/src/render3/after_render_hooks.mjs +8 -3
  19. package/esm2022/src/render3/component_ref.mjs +1 -1
  20. package/esm2022/src/version.mjs +1 -1
  21. package/esm2022/testing/src/logger.mjs +3 -3
  22. package/event-dispatch-contract.min.js +1 -1
  23. package/fesm2022/core.mjs +35 -36
  24. package/fesm2022/core.mjs.map +1 -1
  25. package/fesm2022/primitives/event-dispatch.mjs +558 -526
  26. package/fesm2022/primitives/event-dispatch.mjs.map +1 -1
  27. package/fesm2022/primitives/signals.mjs +1 -1
  28. package/fesm2022/rxjs-interop.mjs +6 -5
  29. package/fesm2022/rxjs-interop.mjs.map +1 -1
  30. package/fesm2022/testing.mjs +1 -1
  31. package/index.d.ts +3 -3
  32. package/package.json +1 -1
  33. package/primitives/event-dispatch/index.d.ts +46 -45
  34. package/primitives/signals/index.d.ts +1 -1
  35. package/rxjs-interop/index.d.ts +1 -1
  36. package/schematics/migrations/invalid-two-way-bindings/bundle.js +45 -33
  37. package/schematics/migrations/invalid-two-way-bindings/bundle.js.map +2 -2
  38. package/schematics/ng-generate/control-flow-migration/bundle.js +52 -33
  39. package/schematics/ng-generate/control-flow-migration/bundle.js.map +2 -2
  40. package/schematics/ng-generate/standalone-migration/bundle.js +64 -45
  41. package/schematics/ng-generate/standalone-migration/bundle.js.map +2 -2
  42. package/testing/index.d.ts +1 -1
  43. package/esm2022/primitives/event-dispatch/src/register_events.mjs +0 -31
@@ -1,5 +1,5 @@
1
1
  /**
2
- * @license Angular v18.1.0
2
+ * @license Angular v18.1.2
3
3
  * (c) 2010-2024 Google LLC. https://angular.io/
4
4
  * License: MIT
5
5
  */
@@ -20,19 +20,80 @@ const Attribute = {
20
20
  JSACTION: 'jsaction',
21
21
  };
22
22
 
23
- const Char = {
23
+ /** All properties that are used by jsaction. */
24
+ const Property = {
24
25
  /**
25
- * The separator between the namespace and the action name in the
26
- * jsaction attribute value.
26
+ * The parsed value of the jsaction attribute is stored in this
27
+ * property on the DOM node. The parsed value is an Object. The
28
+ * property names of the object are the events; the values are the
29
+ * names of the actions. This property is attached even on nodes
30
+ * that don't have a jsaction attribute as an optimization, because
31
+ * property lookup is faster than attribute access.
27
32
  */
28
- NAMESPACE_ACTION_SEPARATOR: '.',
33
+ JSACTION: '__jsaction',
29
34
  /**
30
- * The separator between the event name and action in the jsaction
31
- * attribute value.
35
+ * The owner property references an a logical owner for a DOM node. JSAction
36
+ * will follow this reference instead of parentNode when traversing the DOM
37
+ * to find jsaction attributes. This allows overlaying a logical structure
38
+ * over a document where the DOM structure can't reflect that structure.
32
39
  */
33
- EVENT_ACTION_SEPARATOR: ':',
40
+ OWNER: '__owner',
34
41
  };
35
42
 
43
+ /**
44
+ * Map from jsaction annotation to a parsed map from event name to action name.
45
+ */
46
+ const parseCache = {};
47
+ /**
48
+ * Reads the jsaction parser cache from the given DOM Element.
49
+ */
50
+ function get(element) {
51
+ return element[Property.JSACTION];
52
+ }
53
+ /**
54
+ * Reads the jsaction parser cache for the given DOM element. If no cache is yet present,
55
+ * creates an empty one.
56
+ */
57
+ function getDefaulted(element) {
58
+ const cache = get(element) ?? {};
59
+ set(element, cache);
60
+ return cache;
61
+ }
62
+ /**
63
+ * Writes the jsaction parser cache to the given DOM Element.
64
+ */
65
+ function set(element, actionMap) {
66
+ element[Property.JSACTION] = actionMap;
67
+ }
68
+ /**
69
+ * Looks up the parsed action map from the source jsaction attribute value.
70
+ *
71
+ * @param text Unparsed jsaction attribute value.
72
+ * @return Parsed jsaction attribute value, if already present in the cache.
73
+ */
74
+ function getParsed(text) {
75
+ return parseCache[text];
76
+ }
77
+ /**
78
+ * Inserts the parse result for the given source jsaction value into the cache.
79
+ *
80
+ * @param text Unparsed jsaction attribute value.
81
+ * @param parsed Attribute value parsed into the action map.
82
+ */
83
+ function setParsed(text, parsed) {
84
+ parseCache[text] = parsed;
85
+ }
86
+ /**
87
+ * Clears the jsaction parser cache from the given DOM Element.
88
+ *
89
+ * @param element .
90
+ */
91
+ function clear(element) {
92
+ if (Property.JSACTION in element) {
93
+ delete element[Property.JSACTION];
94
+ }
95
+ }
96
+
36
97
  /*
37
98
  * Names of events that are special to jsaction. These are not all
38
99
  * event types that are legal to use in either HTML or the addEvent()
@@ -269,32 +330,25 @@ const EventType = {
269
330
  */
270
331
  CUSTOM: '_custom',
271
332
  };
272
- const NON_BUBBLING_MOUSE_EVENTS = [
333
+ /** All event types that do not bubble or capture and need a polyfill. */
334
+ const MOUSE_SPECIAL_EVENT_TYPES = [
273
335
  EventType.MOUSEENTER,
274
336
  EventType.MOUSELEAVE,
275
337
  'pointerenter',
276
338
  'pointerleave',
277
339
  ];
278
- /**
279
- * Detects whether a given event type is supported by JSAction.
280
- */
281
- const isSupportedEvent = (eventType) => SUPPORTED_EVENTS.indexOf(eventType) >= 0;
282
- const SUPPORTED_EVENTS = [
340
+ /** All event types that are registered in the bubble phase. */
341
+ const BUBBLE_EVENT_TYPES = [
283
342
  EventType.CLICK,
284
343
  EventType.DBLCLICK,
285
- EventType.FOCUS,
286
344
  EventType.FOCUSIN,
287
- EventType.BLUR,
288
- EventType.ERROR,
289
345
  EventType.FOCUSOUT,
290
346
  EventType.KEYDOWN,
291
347
  EventType.KEYUP,
292
348
  EventType.KEYPRESS,
293
- EventType.LOAD,
294
349
  EventType.MOUSEOVER,
295
350
  EventType.MOUSEOUT,
296
351
  EventType.SUBMIT,
297
- EventType.TOGGLE,
298
352
  EventType.TOUCHSTART,
299
353
  EventType.TOUCHEND,
300
354
  EventType.TOUCHMOVE,
@@ -338,313 +392,26 @@ const SUPPORTED_EVENTS = [
338
392
  // Content visibility events.
339
393
  'beforematch',
340
394
  ];
341
- /**
342
- *
343
- * Decides whether or not an event type is an event that only has a capture phase.
344
- *
345
- * @param eventType
346
- * @returns bool
347
- */
348
- const isCaptureEvent = (eventType) => CAPTURE_EVENTS.indexOf(eventType) >= 0;
349
- const CAPTURE_EVENTS = [
395
+ /** All event types that are registered in the capture phase. */
396
+ const CAPTURE_EVENT_TYPES = [
350
397
  EventType.FOCUS,
351
- EventType.BLUR,
352
- EventType.ERROR,
353
- EventType.LOAD,
354
- EventType.TOGGLE,
355
- ];
356
-
357
- /** All properties that are used by jsaction. */
358
- const Property = {
359
- /**
360
- * The parsed value of the jsaction attribute is stored in this
361
- * property on the DOM node. The parsed value is an Object. The
362
- * property names of the object are the events; the values are the
363
- * names of the actions. This property is attached even on nodes
364
- * that don't have a jsaction attribute as an optimization, because
365
- * property lookup is faster than attribute access.
366
- */
367
- JSACTION: '__jsaction',
368
- /**
369
- * The owner property references an a logical owner for a DOM node. JSAction
370
- * will follow this reference instead of parentNode when traversing the DOM
371
- * to find jsaction attributes. This allows overlaying a logical structure
372
- * over a document where the DOM structure can't reflect that structure.
373
- */
374
- OWNER: '__owner',
375
- };
376
-
377
- /**
378
- * Map from jsaction annotation to a parsed map from event name to action name.
379
- */
380
- const parseCache = {};
381
- function registerEventType(element, eventType, action) {
382
- const cache = get(element) || {};
383
- cache[eventType] = action;
384
- set(element, cache);
385
- }
386
- function unregisterEventType(element, eventType) {
387
- const cache = get(element);
388
- if (cache) {
389
- cache[eventType] = undefined;
390
- }
391
- }
392
- /**
393
- * Reads the jsaction parser cache from the given DOM Element.
394
- *
395
- * @param element .
396
- * @return Map from event to qualified name of the jsaction bound to it.
397
- */
398
- function get(element) {
399
- // @ts-ignore
400
- return element[Property.JSACTION];
401
- }
402
- /**
403
- * Writes the jsaction parser cache to the given DOM Element.
404
- *
405
- * @param element .
406
- * @param actionMap Map from event to qualified name of the jsaction bound to
407
- * it.
408
- */
409
- function set(element, actionMap) {
410
- // @ts-ignore
411
- element[Property.JSACTION] = actionMap;
412
- }
413
- /**
414
- * Looks up the parsed action map from the source jsaction attribute value.
415
- *
416
- * @param text Unparsed jsaction attribute value.
417
- * @return Parsed jsaction attribute value, if already present in the cache.
418
- */
419
- function getParsed(text) {
420
- return parseCache[text];
421
- }
422
- /**
423
- * Inserts the parse result for the given source jsaction value into the cache.
424
- *
425
- * @param text Unparsed jsaction attribute value.
426
- * @param parsed Attribute value parsed into the action map.
427
- */
428
- function setParsed(text, parsed) {
429
- parseCache[text] = parsed;
430
- }
431
- /**
432
- * Clears the jsaction parser cache from the given DOM Element.
433
- *
434
- * @param element .
435
- */
436
- function clear(element) {
437
- if (Property.JSACTION in element) {
438
- delete element[Property.JSACTION];
439
- }
440
- }
441
-
442
- /** Added for readability when accessing stable property names. */
443
- function getEventType(eventInfo) {
444
- return eventInfo.eventType;
445
- }
446
- /** Added for readability when accessing stable property names. */
447
- function setEventType(eventInfo, eventType) {
448
- eventInfo.eventType = eventType;
449
- }
450
- /** Added for readability when accessing stable property names. */
451
- function getEvent(eventInfo) {
452
- return eventInfo.event;
453
- }
454
- /** Added for readability when accessing stable property names. */
455
- function setEvent(eventInfo, event) {
456
- eventInfo.event = event;
457
- }
458
- /** Added for readability when accessing stable property names. */
459
- function getTargetElement(eventInfo) {
460
- return eventInfo.targetElement;
461
- }
462
- /** Added for readability when accessing stable property names. */
463
- function setTargetElement(eventInfo, targetElement) {
464
- eventInfo.targetElement = targetElement;
465
- }
466
- /** Added for readability when accessing stable property names. */
467
- function getContainer(eventInfo) {
468
- return eventInfo.eic;
469
- }
470
- /** Added for readability when accessing stable property names. */
471
- function setContainer(eventInfo, container) {
472
- eventInfo.eic = container;
473
- }
474
- /** Added for readability when accessing stable property names. */
475
- function getTimestamp(eventInfo) {
476
- return eventInfo.timeStamp;
477
- }
478
- /** Added for readability when accessing stable property names. */
479
- function setTimestamp(eventInfo, timestamp) {
480
- eventInfo.timeStamp = timestamp;
481
- }
482
- /** Added for readability when accessing stable property names. */
483
- function getAction(eventInfo) {
484
- return eventInfo.eia;
485
- }
486
- /** Added for readability when accessing stable property names. */
487
- function setAction(eventInfo, actionName, actionElement) {
488
- eventInfo.eia = [actionName, actionElement];
489
- }
490
- /** Added for readability when accessing stable property names. */
491
- function unsetAction(eventInfo) {
492
- eventInfo.eia = undefined;
493
- }
494
- /** Added for readability when accessing stable property names. */
495
- function getActionName(actionInfo) {
496
- return actionInfo[0];
497
- }
498
- /** Added for readability when accessing stable property names. */
499
- function getActionElement(actionInfo) {
500
- return actionInfo[1];
501
- }
502
- /** Added for readability when accessing stable property names. */
503
- function getIsReplay(eventInfo) {
504
- return eventInfo.eirp;
505
- }
506
- /** Added for readability when accessing stable property names. */
507
- function setIsReplay(eventInfo, replay) {
508
- eventInfo.eirp = replay;
509
- }
510
- /** Added for readability when accessing stable property names. */
511
- function getA11yClickKey(eventInfo) {
512
- return eventInfo.eiack;
513
- }
514
- /** Added for readability when accessing stable property names. */
515
- function setA11yClickKey(eventInfo, a11yClickKey) {
516
- eventInfo.eiack = a11yClickKey;
517
- }
518
- /** Added for readability when accessing stable property names. */
519
- function getResolved(eventInfo) {
520
- return eventInfo.eir;
521
- }
522
- /** Added for readability when accessing stable property names. */
523
- function setResolved(eventInfo, resolved) {
524
- eventInfo.eir = resolved;
525
- }
526
- /** Clones an `EventInfo` */
527
- function cloneEventInfo(eventInfo) {
528
- return {
529
- eventType: eventInfo.eventType,
530
- event: eventInfo.event,
531
- targetElement: eventInfo.targetElement,
532
- eic: eventInfo.eic,
533
- eia: eventInfo.eia,
534
- timeStamp: eventInfo.timeStamp,
535
- eirp: eventInfo.eirp,
536
- eiack: eventInfo.eiack,
537
- eir: eventInfo.eir,
538
- };
539
- }
540
- /**
541
- * Utility function for creating an `EventInfo`.
542
- *
543
- * This can be used from code-size sensitive compilation units, as taking
544
- * parameters vs. an `Object` literal reduces code size.
545
- */
546
- function createEventInfoFromParameters(eventType, event, targetElement, container, timestamp, action, isReplay, a11yClickKey) {
547
- return {
548
- eventType,
549
- event,
550
- targetElement,
551
- eic: container,
552
- timeStamp: timestamp,
553
- eia: action,
554
- eirp: isReplay,
555
- eiack: a11yClickKey,
556
- };
557
- }
558
- /**
559
- * Utility function for creating an `EventInfo`.
560
- *
561
- * This should be used in compilation units that are less sensitive to code
562
- * size.
563
- */
564
- function createEventInfo({ eventType, event, targetElement, container, timestamp, action, isReplay, a11yClickKey, }) {
565
- return {
566
- eventType,
567
- event,
568
- targetElement,
569
- eic: container,
570
- timeStamp: timestamp,
571
- eia: action ? [action.name, action.element] : undefined,
572
- eirp: isReplay,
573
- eiack: a11yClickKey,
574
- };
575
- }
576
- /**
577
- * Utility class around an `EventInfo`.
578
- *
579
- * This should be used in compilation units that are less sensitive to code
580
- * size.
581
- */
582
- class EventInfoWrapper {
583
- constructor(eventInfo) {
584
- this.eventInfo = eventInfo;
585
- }
586
- getEventType() {
587
- return getEventType(this.eventInfo);
588
- }
589
- setEventType(eventType) {
590
- setEventType(this.eventInfo, eventType);
591
- }
592
- getEvent() {
593
- return getEvent(this.eventInfo);
594
- }
595
- setEvent(event) {
596
- setEvent(this.eventInfo, event);
597
- }
598
- getTargetElement() {
599
- return getTargetElement(this.eventInfo);
600
- }
601
- setTargetElement(targetElement) {
602
- setTargetElement(this.eventInfo, targetElement);
603
- }
604
- getContainer() {
605
- return getContainer(this.eventInfo);
606
- }
607
- setContainer(container) {
608
- setContainer(this.eventInfo, container);
609
- }
610
- getTimestamp() {
611
- return getTimestamp(this.eventInfo);
612
- }
613
- setTimestamp(timestamp) {
614
- setTimestamp(this.eventInfo, timestamp);
615
- }
616
- getAction() {
617
- const action = getAction(this.eventInfo);
618
- if (!action)
619
- return undefined;
620
- return {
621
- name: action[0],
622
- element: action[1],
623
- };
624
- }
625
- setAction(action) {
626
- if (!action) {
627
- unsetAction(this.eventInfo);
628
- return;
629
- }
630
- setAction(this.eventInfo, action.name, action.element);
631
- }
632
- getIsReplay() {
633
- return getIsReplay(this.eventInfo);
634
- }
635
- setIsReplay(replay) {
636
- setIsReplay(this.eventInfo, replay);
637
- }
638
- getResolved() {
639
- return getResolved(this.eventInfo);
640
- }
641
- setResolved(resolved) {
642
- setResolved(this.eventInfo, resolved);
643
- }
644
- clone() {
645
- return new EventInfoWrapper(cloneEventInfo(this.eventInfo));
646
- }
647
- }
398
+ EventType.BLUR,
399
+ EventType.ERROR,
400
+ EventType.LOAD,
401
+ EventType.TOGGLE,
402
+ ];
403
+ /**
404
+ * Whether or not an event type should be registered in the capture phase.
405
+ * @param eventType
406
+ * @returns bool
407
+ */
408
+ const isCaptureEventType = (eventType) => CAPTURE_EVENT_TYPES.indexOf(eventType) >= 0;
409
+ /** All event types that are registered early. */
410
+ const EARLY_EVENT_TYPES = BUBBLE_EVENT_TYPES.concat(CAPTURE_EVENT_TYPES);
411
+ /**
412
+ * Whether or not an event type is registered in the early contract.
413
+ */
414
+ const isEarlyEventType = (eventType) => EARLY_EVENT_TYPES.indexOf(eventType) >= 0;
648
415
 
649
416
  /**
650
417
  * If on a Macintosh with an extended keyboard, the Enter key located in the
@@ -706,7 +473,7 @@ function addEventListener(element, eventType, handler) {
706
473
  // Error and load events (i.e. on images) do not bubble so they are also
707
474
  // handled in the capture phase.
708
475
  let capture = false;
709
- if (isCaptureEvent(eventType)) {
476
+ if (isCaptureEventType(eventType)) {
710
477
  capture = true;
711
478
  }
712
479
  element.addEventListener(eventType, handler, capture);
@@ -1217,70 +984,345 @@ function isNativeHTMLControl(el) {
1217
984
  return el.tagName.toUpperCase() in NATIVE_HTML_CONTROLS;
1218
985
  }
1219
986
  /**
1220
- * Returns if the given element is natively activatable. Browsers emit click
1221
- * events for natively activatable elements, even when activated via keyboard.
1222
- * For these elements, we don't need to raise a11y click events.
1223
- * @param el The element.
1224
- * @return If the given element is a native HTML control.
987
+ * Returns if the given element is natively activatable. Browsers emit click
988
+ * events for natively activatable elements, even when activated via keyboard.
989
+ * For these elements, we don't need to raise a11y click events.
990
+ * @param el The element.
991
+ * @return If the given element is a native HTML control.
992
+ */
993
+ function isNativelyActivatable(el) {
994
+ return (el.tagName.toUpperCase() === 'BUTTON' ||
995
+ (!!el.type && el.type.toUpperCase() === 'FILE'));
996
+ }
997
+ /**
998
+ * HTML <input> types (not ARIA roles) which will auto-trigger a click event for
999
+ * the Space key, with side-effects. We will not call preventDefault if space is
1000
+ * pressed, nor will we raise a11y click events. For all other elements, we can
1001
+ * suppress the default event (which has no desired side-effects) and handle the
1002
+ * keydown ourselves.
1003
+ */
1004
+ const PROCESS_SPACE = {
1005
+ 'CHECKBOX': true,
1006
+ 'FILE': true,
1007
+ 'OPTION': true,
1008
+ 'RADIO': true,
1009
+ };
1010
+ /** TagNames and Input types for which to not process enter/space as click. */
1011
+ const TEXT_CONTROLS = {
1012
+ 'COLOR': true,
1013
+ 'DATE': true,
1014
+ 'DATETIME': true,
1015
+ 'DATETIME-LOCAL': true,
1016
+ 'EMAIL': true,
1017
+ 'MONTH': true,
1018
+ 'NUMBER': true,
1019
+ 'PASSWORD': true,
1020
+ 'RANGE': true,
1021
+ 'SEARCH': true,
1022
+ 'TEL': true,
1023
+ 'TEXT': true,
1024
+ 'TEXTAREA': true,
1025
+ 'TIME': true,
1026
+ 'URL': true,
1027
+ 'WEEK': true,
1028
+ };
1029
+ /** TagNames that are native HTML controls. */
1030
+ const NATIVE_HTML_CONTROLS = {
1031
+ 'A': true,
1032
+ 'AREA': true,
1033
+ 'BUTTON': true,
1034
+ 'DIALOG': true,
1035
+ 'IMG': true,
1036
+ 'INPUT': true,
1037
+ 'LINK': true,
1038
+ 'MENU': true,
1039
+ 'OPTGROUP': true,
1040
+ 'OPTION': true,
1041
+ 'PROGRESS': true,
1042
+ 'SELECT': true,
1043
+ 'TEXTAREA': true,
1044
+ };
1045
+ /** Exported for testing. */
1046
+ const testing = {
1047
+ setIsMac(value) {
1048
+ isMac = value;
1049
+ },
1050
+ };
1051
+
1052
+ /**
1053
+ * Whether the user agent is running on iOS.
1054
+ */
1055
+ const isIos = typeof navigator !== 'undefined' && /iPhone|iPad|iPod/.test(navigator.userAgent);
1056
+ /**
1057
+ * A class representing a container node and all the event handlers
1058
+ * installed on it. Used so that handlers can be cleaned up if the
1059
+ * container is removed from the contract.
1060
+ */
1061
+ class EventContractContainer {
1062
+ /**
1063
+ * @param element The container Element.
1064
+ */
1065
+ constructor(element) {
1066
+ this.element = element;
1067
+ /**
1068
+ * Array of event handlers and their corresponding event types that are
1069
+ * installed on this container.
1070
+ *
1071
+ */
1072
+ this.handlerInfos = [];
1073
+ }
1074
+ /**
1075
+ * Installs the provided installer on the element owned by this container,
1076
+ * and maintains a reference to resulting handler in order to remove it
1077
+ * later if desired.
1078
+ */
1079
+ addEventListener(eventType, getHandler) {
1080
+ // In iOS, event bubbling doesn't happen automatically in any DOM element,
1081
+ // unless it has an onclick attribute or DOM event handler attached to it.
1082
+ // This breaks JsAction in some cases. See "Making Elements Clickable"
1083
+ // section at http://goo.gl/2VoGnB.
1084
+ //
1085
+ // A workaround for this issue is to change the CSS cursor style to 'pointer'
1086
+ // for the container element, which magically turns on event bubbling. This
1087
+ // solution is described in the comments section at http://goo.gl/6pEO1z.
1088
+ //
1089
+ // We use a navigator.userAgent check here as this problem is present both
1090
+ // on Mobile Safari and thin WebKit wrappers, such as Chrome for iOS.
1091
+ if (isIos) {
1092
+ this.element.style.cursor = 'pointer';
1093
+ }
1094
+ this.handlerInfos.push(addEventListener(this.element, eventType, getHandler(this.element)));
1095
+ }
1096
+ /**
1097
+ * Removes all the handlers installed on this container.
1098
+ */
1099
+ cleanUp() {
1100
+ for (let i = 0; i < this.handlerInfos.length; i++) {
1101
+ removeEventListener(this.element, this.handlerInfos[i]);
1102
+ }
1103
+ this.handlerInfos = [];
1104
+ }
1105
+ }
1106
+
1107
+ const Char = {
1108
+ /**
1109
+ * The separator between the namespace and the action name in the
1110
+ * jsaction attribute value.
1111
+ */
1112
+ NAMESPACE_ACTION_SEPARATOR: '.',
1113
+ /**
1114
+ * The separator between the event name and action in the jsaction
1115
+ * attribute value.
1116
+ */
1117
+ EVENT_ACTION_SEPARATOR: ':',
1118
+ };
1119
+
1120
+ /** Added for readability when accessing stable property names. */
1121
+ function getEventType(eventInfo) {
1122
+ return eventInfo.eventType;
1123
+ }
1124
+ /** Added for readability when accessing stable property names. */
1125
+ function setEventType(eventInfo, eventType) {
1126
+ eventInfo.eventType = eventType;
1127
+ }
1128
+ /** Added for readability when accessing stable property names. */
1129
+ function getEvent(eventInfo) {
1130
+ return eventInfo.event;
1131
+ }
1132
+ /** Added for readability when accessing stable property names. */
1133
+ function setEvent(eventInfo, event) {
1134
+ eventInfo.event = event;
1135
+ }
1136
+ /** Added for readability when accessing stable property names. */
1137
+ function getTargetElement(eventInfo) {
1138
+ return eventInfo.targetElement;
1139
+ }
1140
+ /** Added for readability when accessing stable property names. */
1141
+ function setTargetElement(eventInfo, targetElement) {
1142
+ eventInfo.targetElement = targetElement;
1143
+ }
1144
+ /** Added for readability when accessing stable property names. */
1145
+ function getContainer(eventInfo) {
1146
+ return eventInfo.eic;
1147
+ }
1148
+ /** Added for readability when accessing stable property names. */
1149
+ function setContainer(eventInfo, container) {
1150
+ eventInfo.eic = container;
1151
+ }
1152
+ /** Added for readability when accessing stable property names. */
1153
+ function getTimestamp(eventInfo) {
1154
+ return eventInfo.timeStamp;
1155
+ }
1156
+ /** Added for readability when accessing stable property names. */
1157
+ function setTimestamp(eventInfo, timestamp) {
1158
+ eventInfo.timeStamp = timestamp;
1159
+ }
1160
+ /** Added for readability when accessing stable property names. */
1161
+ function getAction(eventInfo) {
1162
+ return eventInfo.eia;
1163
+ }
1164
+ /** Added for readability when accessing stable property names. */
1165
+ function setAction(eventInfo, actionName, actionElement) {
1166
+ eventInfo.eia = [actionName, actionElement];
1167
+ }
1168
+ /** Added for readability when accessing stable property names. */
1169
+ function unsetAction(eventInfo) {
1170
+ eventInfo.eia = undefined;
1171
+ }
1172
+ /** Added for readability when accessing stable property names. */
1173
+ function getActionName(actionInfo) {
1174
+ return actionInfo[0];
1175
+ }
1176
+ /** Added for readability when accessing stable property names. */
1177
+ function getActionElement(actionInfo) {
1178
+ return actionInfo[1];
1179
+ }
1180
+ /** Added for readability when accessing stable property names. */
1181
+ function getIsReplay(eventInfo) {
1182
+ return eventInfo.eirp;
1183
+ }
1184
+ /** Added for readability when accessing stable property names. */
1185
+ function setIsReplay(eventInfo, replay) {
1186
+ eventInfo.eirp = replay;
1187
+ }
1188
+ /** Added for readability when accessing stable property names. */
1189
+ function getA11yClickKey(eventInfo) {
1190
+ return eventInfo.eiack;
1191
+ }
1192
+ /** Added for readability when accessing stable property names. */
1193
+ function setA11yClickKey(eventInfo, a11yClickKey) {
1194
+ eventInfo.eiack = a11yClickKey;
1195
+ }
1196
+ /** Added for readability when accessing stable property names. */
1197
+ function getResolved(eventInfo) {
1198
+ return eventInfo.eir;
1199
+ }
1200
+ /** Added for readability when accessing stable property names. */
1201
+ function setResolved(eventInfo, resolved) {
1202
+ eventInfo.eir = resolved;
1203
+ }
1204
+ /** Clones an `EventInfo` */
1205
+ function cloneEventInfo(eventInfo) {
1206
+ return {
1207
+ eventType: eventInfo.eventType,
1208
+ event: eventInfo.event,
1209
+ targetElement: eventInfo.targetElement,
1210
+ eic: eventInfo.eic,
1211
+ eia: eventInfo.eia,
1212
+ timeStamp: eventInfo.timeStamp,
1213
+ eirp: eventInfo.eirp,
1214
+ eiack: eventInfo.eiack,
1215
+ eir: eventInfo.eir,
1216
+ };
1217
+ }
1218
+ /**
1219
+ * Utility function for creating an `EventInfo`.
1220
+ *
1221
+ * This can be used from code-size sensitive compilation units, as taking
1222
+ * parameters vs. an `Object` literal reduces code size.
1223
+ */
1224
+ function createEventInfoFromParameters(eventType, event, targetElement, container, timestamp, action, isReplay, a11yClickKey) {
1225
+ return {
1226
+ eventType,
1227
+ event,
1228
+ targetElement,
1229
+ eic: container,
1230
+ timeStamp: timestamp,
1231
+ eia: action,
1232
+ eirp: isReplay,
1233
+ eiack: a11yClickKey,
1234
+ };
1235
+ }
1236
+ /**
1237
+ * Utility function for creating an `EventInfo`.
1238
+ *
1239
+ * This should be used in compilation units that are less sensitive to code
1240
+ * size.
1225
1241
  */
1226
- function isNativelyActivatable(el) {
1227
- return (el.tagName.toUpperCase() === 'BUTTON' ||
1228
- (!!el.type && el.type.toUpperCase() === 'FILE'));
1242
+ function createEventInfo({ eventType, event, targetElement, container, timestamp, action, isReplay, a11yClickKey, }) {
1243
+ return {
1244
+ eventType,
1245
+ event,
1246
+ targetElement,
1247
+ eic: container,
1248
+ timeStamp: timestamp,
1249
+ eia: action ? [action.name, action.element] : undefined,
1250
+ eirp: isReplay,
1251
+ eiack: a11yClickKey,
1252
+ };
1229
1253
  }
1230
1254
  /**
1231
- * HTML <input> types (not ARIA roles) which will auto-trigger a click event for
1232
- * the Space key, with side-effects. We will not call preventDefault if space is
1233
- * pressed, nor will we raise a11y click events. For all other elements, we can
1234
- * suppress the default event (which has no desired side-effects) and handle the
1235
- * keydown ourselves.
1255
+ * Utility class around an `EventInfo`.
1256
+ *
1257
+ * This should be used in compilation units that are less sensitive to code
1258
+ * size.
1236
1259
  */
1237
- const PROCESS_SPACE = {
1238
- 'CHECKBOX': true,
1239
- 'FILE': true,
1240
- 'OPTION': true,
1241
- 'RADIO': true,
1242
- };
1243
- /** TagNames and Input types for which to not process enter/space as click. */
1244
- const TEXT_CONTROLS = {
1245
- 'COLOR': true,
1246
- 'DATE': true,
1247
- 'DATETIME': true,
1248
- 'DATETIME-LOCAL': true,
1249
- 'EMAIL': true,
1250
- 'MONTH': true,
1251
- 'NUMBER': true,
1252
- 'PASSWORD': true,
1253
- 'RANGE': true,
1254
- 'SEARCH': true,
1255
- 'TEL': true,
1256
- 'TEXT': true,
1257
- 'TEXTAREA': true,
1258
- 'TIME': true,
1259
- 'URL': true,
1260
- 'WEEK': true,
1261
- };
1262
- /** TagNames that are native HTML controls. */
1263
- const NATIVE_HTML_CONTROLS = {
1264
- 'A': true,
1265
- 'AREA': true,
1266
- 'BUTTON': true,
1267
- 'DIALOG': true,
1268
- 'IMG': true,
1269
- 'INPUT': true,
1270
- 'LINK': true,
1271
- 'MENU': true,
1272
- 'OPTGROUP': true,
1273
- 'OPTION': true,
1274
- 'PROGRESS': true,
1275
- 'SELECT': true,
1276
- 'TEXTAREA': true,
1277
- };
1278
- /** Exported for testing. */
1279
- const testing = {
1280
- setIsMac(value) {
1281
- isMac = value;
1282
- },
1283
- };
1260
+ class EventInfoWrapper {
1261
+ constructor(eventInfo) {
1262
+ this.eventInfo = eventInfo;
1263
+ }
1264
+ getEventType() {
1265
+ return getEventType(this.eventInfo);
1266
+ }
1267
+ setEventType(eventType) {
1268
+ setEventType(this.eventInfo, eventType);
1269
+ }
1270
+ getEvent() {
1271
+ return getEvent(this.eventInfo);
1272
+ }
1273
+ setEvent(event) {
1274
+ setEvent(this.eventInfo, event);
1275
+ }
1276
+ getTargetElement() {
1277
+ return getTargetElement(this.eventInfo);
1278
+ }
1279
+ setTargetElement(targetElement) {
1280
+ setTargetElement(this.eventInfo, targetElement);
1281
+ }
1282
+ getContainer() {
1283
+ return getContainer(this.eventInfo);
1284
+ }
1285
+ setContainer(container) {
1286
+ setContainer(this.eventInfo, container);
1287
+ }
1288
+ getTimestamp() {
1289
+ return getTimestamp(this.eventInfo);
1290
+ }
1291
+ setTimestamp(timestamp) {
1292
+ setTimestamp(this.eventInfo, timestamp);
1293
+ }
1294
+ getAction() {
1295
+ const action = getAction(this.eventInfo);
1296
+ if (!action)
1297
+ return undefined;
1298
+ return {
1299
+ name: action[0],
1300
+ element: action[1],
1301
+ };
1302
+ }
1303
+ setAction(action) {
1304
+ if (!action) {
1305
+ unsetAction(this.eventInfo);
1306
+ return;
1307
+ }
1308
+ setAction(this.eventInfo, action.name, action.element);
1309
+ }
1310
+ getIsReplay() {
1311
+ return getIsReplay(this.eventInfo);
1312
+ }
1313
+ setIsReplay(replay) {
1314
+ setIsReplay(this.eventInfo, replay);
1315
+ }
1316
+ getResolved() {
1317
+ return getResolved(this.eventInfo);
1318
+ }
1319
+ setResolved(resolved) {
1320
+ setResolved(this.eventInfo, resolved);
1321
+ }
1322
+ clone() {
1323
+ return new EventInfoWrapper(cloneEventInfo(this.eventInfo));
1324
+ }
1325
+ }
1284
1326
 
1285
1327
  /**
1286
1328
  * Since maps from event to action are immutable we can use a single map
@@ -1618,7 +1660,7 @@ function shouldPreventDefaultBeforeDispatching(actionElement, eventInfoWrapper)
1618
1660
  * Registers deferred functionality for an EventContract and a Jsaction
1619
1661
  * Dispatcher.
1620
1662
  */
1621
- function registerDispatcher$1(eventContract, dispatcher) {
1663
+ function registerDispatcher$2(eventContract, dispatcher) {
1622
1664
  eventContract.ecrd((eventInfo) => {
1623
1665
  dispatcher.dispatch(eventInfo);
1624
1666
  }, Restriction.I_AM_THE_JSACTION_FRAMEWORK);
@@ -1736,78 +1778,110 @@ function patchEventInstance(event, property, value, { configurable = false } = {
1736
1778
  * Registers deferred functionality for an EventContract and a Jsaction
1737
1779
  * Dispatcher.
1738
1780
  */
1739
- function registerDispatcher(eventContract, dispatcher) {
1781
+ function registerDispatcher$1(eventContract, dispatcher) {
1740
1782
  eventContract.ecrd((eventInfo) => {
1741
1783
  dispatcher.dispatch(eventInfo);
1742
1784
  }, Restriction.I_AM_THE_JSACTION_FRAMEWORK);
1743
1785
  }
1744
1786
 
1745
1787
  /**
1746
- * Whether the user agent is running on iOS.
1747
- */
1748
- const isIos = typeof navigator !== 'undefined' && /iPhone|iPad|iPod/.test(navigator.userAgent);
1749
- /**
1750
- * A class representing a container node and all the event handlers
1751
- * installed on it. Used so that handlers can be cleaned up if the
1752
- * container is removed from the contract.
1788
+ * EarlyEventContract intercepts events in the bubbling phase at the
1789
+ * boundary of the document body. This mapping will be passed to the
1790
+ * late-loaded EventContract.
1753
1791
  */
1754
- class EventContractContainer {
1755
- /**
1756
- * @param element The container Element.
1757
- */
1758
- constructor(element) {
1759
- this.element = element;
1760
- /**
1761
- * Array of event handlers and their corresponding event types that are
1762
- * installed on this container.
1763
- *
1764
- */
1765
- this.handlerInfos = [];
1792
+ class EarlyEventContract {
1793
+ constructor(dataContainer = window, container = window.document.documentElement) {
1794
+ this.dataContainer = dataContainer;
1795
+ dataContainer._ejsa = createEarlyJsactionData(container);
1766
1796
  }
1767
1797
  /**
1768
- * Installs the provided installer on the element owned by this container,
1769
- * and maintains a reference to resulting handler in order to remove it
1770
- * later if desired.
1798
+ * Installs a list of event types for container .
1771
1799
  */
1772
- addEventListener(eventType, getHandler) {
1773
- // In iOS, event bubbling doesn't happen automatically in any DOM element,
1774
- // unless it has an onclick attribute or DOM event handler attached to it.
1775
- // This breaks JsAction in some cases. See "Making Elements Clickable"
1776
- // section at http://goo.gl/2VoGnB.
1777
- //
1778
- // A workaround for this issue is to change the CSS cursor style to 'pointer'
1779
- // for the container element, which magically turns on event bubbling. This
1780
- // solution is described in the comments section at http://goo.gl/6pEO1z.
1781
- //
1782
- // We use a navigator.userAgent check here as this problem is present both
1783
- // on Mobile Safari and thin WebKit wrappers, such as Chrome for iOS.
1784
- if (isIos) {
1785
- this.element.style.cursor = 'pointer';
1786
- }
1787
- this.handlerInfos.push(addEventListener(this.element, eventType, getHandler(this.element)));
1800
+ addEvents(types, capture) {
1801
+ addEvents(this.dataContainer._ejsa, types, capture);
1788
1802
  }
1789
- /**
1790
- * Removes all the handlers installed on this container.
1791
- */
1792
- cleanUp() {
1793
- for (let i = 0; i < this.handlerInfos.length; i++) {
1794
- removeEventListener(this.element, this.handlerInfos[i]);
1795
- }
1796
- this.handlerInfos = [];
1803
+ }
1804
+ /** Creates an `EarlyJsactionData` object. */
1805
+ function createEarlyJsactionData(container) {
1806
+ const q = [];
1807
+ const d = (eventInfo) => {
1808
+ q.push(eventInfo);
1809
+ };
1810
+ const h = (event) => {
1811
+ d(createEventInfoFromParameters(event.type, event, event.target, container, Date.now()));
1812
+ };
1813
+ return {
1814
+ c: container,
1815
+ q,
1816
+ et: [],
1817
+ etc: [],
1818
+ d,
1819
+ h,
1820
+ };
1821
+ }
1822
+ /** Add all the events to the container stored in the `EarlyJsactionData`. */
1823
+ function addEvents(earlyJsactionData, types, capture) {
1824
+ for (let i = 0; i < types.length; i++) {
1825
+ const eventType = types[i];
1826
+ const eventTypes = capture ? earlyJsactionData.etc : earlyJsactionData.et;
1827
+ eventTypes.push(eventType);
1828
+ earlyJsactionData.c.addEventListener(eventType, earlyJsactionData.h, capture);
1829
+ }
1830
+ }
1831
+ /** Get the queued `EventInfo` objects that were dispatched before a dispatcher was registered. */
1832
+ function getQueuedEventInfos(earlyJsactionData) {
1833
+ return earlyJsactionData?.q ?? [];
1834
+ }
1835
+ /** Register a different dispatcher function on the `EarlyJsactionData`. */
1836
+ function registerDispatcher(earlyJsactionData, dispatcher) {
1837
+ if (!earlyJsactionData) {
1838
+ return;
1839
+ }
1840
+ earlyJsactionData.d = dispatcher;
1841
+ }
1842
+ /** Removes all event listener handlers. */
1843
+ function removeAllEventListeners(earlyJsactionData) {
1844
+ if (!earlyJsactionData) {
1845
+ return;
1846
+ }
1847
+ removeEventListeners(earlyJsactionData.c, earlyJsactionData.et, earlyJsactionData.h);
1848
+ removeEventListeners(earlyJsactionData.c, earlyJsactionData.etc, earlyJsactionData.h, true);
1849
+ }
1850
+ function removeEventListeners(container, eventTypes, earlyEventHandler, capture) {
1851
+ for (let i = 0; i < eventTypes.length; i++) {
1852
+ container.removeEventListener(eventTypes[i], earlyEventHandler, /* useCapture */ capture);
1797
1853
  }
1798
1854
  }
1799
1855
 
1800
- /**
1801
- * @define Support for accessible click actions. This flag can be overridden in
1802
- * a build rule.
1803
- */
1804
- const A11Y_CLICK_SUPPORT = false;
1805
1856
  /**
1806
1857
  * @define Support for the non-bubbling mouseenter and mouseleave events. This
1807
1858
  * flag can be overridden in a build rule.
1808
1859
  */
1809
1860
  const MOUSE_SPECIAL_SUPPORT = false;
1810
1861
 
1862
+ /**
1863
+ * @fileoverview Implements the local event handling contract. This
1864
+ * allows DOM objects in a container that enters into this contract to
1865
+ * define event handlers which are executed in a local context.
1866
+ *
1867
+ * One EventContract instance can manage the contract for multiple
1868
+ * containers, which are added using the addContainer() method.
1869
+ *
1870
+ * Events can be registered using the addEvent() method.
1871
+ *
1872
+ * A Dispatcher is added using the registerDispatcher() method. Until there is
1873
+ * a dispatcher, events are queued. The idea is that the EventContract
1874
+ * class is inlined in the HTML of the top level page and instantiated
1875
+ * right after the start of <body>. The Dispatcher class is contained
1876
+ * in the external deferred js, and instantiated and registered with
1877
+ * EventContract when the external javascript in the page loads. The
1878
+ * external javascript will also register the jsaction handlers, which
1879
+ * then pick up the queued events at the time of registration.
1880
+ *
1881
+ * Since this class is meant to be inlined in the main page HTML, the
1882
+ * size of the binary compiled from this file MUST be kept as small as
1883
+ * possible and thus its dependencies to a minimum.
1884
+ */
1811
1885
  /**
1812
1886
  * EventContract intercepts events in the bubbling phase at the
1813
1887
  * boundary of a container element, and maps them to generic actions
@@ -1823,10 +1897,8 @@ const MOUSE_SPECIAL_SUPPORT = false;
1823
1897
  * be delay loaded in a generic way.
1824
1898
  */
1825
1899
  class EventContract {
1826
- static { this.A11Y_CLICK_SUPPORT = A11Y_CLICK_SUPPORT; }
1827
1900
  static { this.MOUSE_SPECIAL_SUPPORT = MOUSE_SPECIAL_SUPPORT; }
1828
- constructor(containerManager, useActionResolver) {
1829
- this.useActionResolver = useActionResolver;
1901
+ constructor(containerManager) {
1830
1902
  /**
1831
1903
  * The DOM events which this contract covers. Used to prevent double
1832
1904
  * registration of event types. The value of the map is the
@@ -1889,7 +1961,7 @@ class EventContract {
1889
1961
  if (eventType in this.eventHandlers || !this.containerManager) {
1890
1962
  return;
1891
1963
  }
1892
- if (!EventContract.MOUSE_SPECIAL_SUPPORT && NON_BUBBLING_MOUSE_EVENTS.indexOf(eventType) >= 0) {
1964
+ if (!EventContract.MOUSE_SPECIAL_SUPPORT && MOUSE_SPECIAL_EVENT_TYPES.indexOf(eventType) >= 0) {
1893
1965
  return;
1894
1966
  }
1895
1967
  const eventHandler = (eventType, event, container) => {
@@ -1914,31 +1986,34 @@ class EventContract {
1914
1986
  * in the provided event contract. Once all the events are replayed, it cleans
1915
1987
  * up the early contract.
1916
1988
  */
1917
- replayEarlyEvents(earlyJsactionContainer = window) {
1989
+ replayEarlyEvents(earlyJsactionData = window._ejsa) {
1918
1990
  // Check if the early contract is present and prevent calling this function
1919
1991
  // more than once.
1920
- const earlyJsactionData = earlyJsactionContainer._ejsa;
1921
1992
  if (!earlyJsactionData) {
1922
1993
  return;
1923
1994
  }
1924
1995
  // Replay the early contract events.
1925
- const earlyEventInfos = earlyJsactionData.q;
1926
- for (let idx = 0; idx < earlyEventInfos.length; idx++) {
1927
- const earlyEventInfo = earlyEventInfos[idx];
1996
+ this.replayEarlyEventInfos(earlyJsactionData.q);
1997
+ // Clean up the early contract.
1998
+ removeAllEventListeners(earlyJsactionData);
1999
+ delete window._ejsa;
2000
+ }
2001
+ /**
2002
+ * Replays all the early `EventInfo` objects, dispatching them through the normal
2003
+ * `EventContract` flow.
2004
+ */
2005
+ replayEarlyEventInfos(earlyEventInfos) {
2006
+ for (let i = 0; i < earlyEventInfos.length; i++) {
2007
+ const earlyEventInfo = earlyEventInfos[i];
1928
2008
  const eventTypes = this.getEventTypesForBrowserEventType(earlyEventInfo.eventType);
1929
- for (let i = 0; i < eventTypes.length; i++) {
2009
+ for (let j = 0; j < eventTypes.length; j++) {
1930
2010
  const eventInfo = cloneEventInfo(earlyEventInfo);
1931
2011
  // EventInfo eventType maps to JSAction's internal event type,
1932
2012
  // rather than the browser event type.
1933
- setEventType(eventInfo, eventTypes[i]);
2013
+ setEventType(eventInfo, eventTypes[j]);
1934
2014
  this.handleEventInfo(eventInfo);
1935
2015
  }
1936
2016
  }
1937
- // Clean up the early contract.
1938
- const earlyEventHandler = earlyJsactionData.h;
1939
- removeEventListeners(earlyJsactionData.c, earlyJsactionData.et, earlyEventHandler);
1940
- removeEventListeners(earlyJsactionData.c, earlyJsactionData.etc, earlyEventHandler, true);
1941
- delete earlyJsactionContainer._ejsa;
1942
2017
  }
1943
2018
  /**
1944
2019
  * Returns all JSAction event types that have been registered for a given
@@ -1999,86 +2074,43 @@ class EventContract {
1999
2074
  this.queuedEventInfos = null;
2000
2075
  }
2001
2076
  }
2002
- /**
2003
- * Adds a11y click support to the given `EventContract`. Meant to be called in
2004
- * the same compilation unit as the `EventContract`.
2005
- */
2006
- addA11yClickSupport() { }
2007
- /**
2008
- * Enables a11y click support to be deferred. Meant to be called in the same
2009
- * compilation unit as the `EventContract`.
2010
- */
2011
- exportAddA11yClickSupport() { }
2012
- }
2013
- function removeEventListeners(container, eventTypes, earlyEventHandler, capture) {
2014
- for (let idx = 0; idx < eventTypes.length; idx++) {
2015
- container.removeEventListener(eventTypes[idx], earlyEventHandler, /* useCapture */ capture);
2016
- }
2017
2077
  }
2018
- /**
2019
- * Adds a11y click support to the given `EventContract`. Meant to be called
2020
- * in a different compilation unit from the `EventContract`. The `EventContract`
2021
- * must have called `exportAddA11yClickSupport` in its compilation unit for this
2022
- * to have any effect.
2023
- */
2024
- function addDeferredA11yClickSupport(eventContract) { }
2025
2078
 
2026
2079
  /**
2027
- * EarlyEventContract intercepts events in the bubbling phase at the
2028
- * boundary of the document body. This mapping will be passed to the
2029
- * late-loaded EventContract.
2080
+ * Creates an `EarlyJsactionData`, adds events to it, and populates it on a nested object on
2081
+ * the window.
2030
2082
  */
2031
- class EarlyEventContract {
2032
- constructor(replaySink = window, container = window.document.documentElement) {
2033
- this.replaySink = replaySink;
2034
- this.container = container;
2035
- replaySink._ejsa = {
2036
- c: container,
2037
- q: [],
2038
- et: [],
2039
- etc: [],
2040
- h: (event) => {
2041
- const eventInfo = createEventInfoFromParameters(event.type, event, event.target, container, Date.now());
2042
- replaySink._ejsa.q.push(eventInfo);
2043
- },
2044
- };
2045
- }
2046
- /**
2047
- * Installs a list of event types for container .
2048
- */
2049
- addEvents(types, capture) {
2050
- const replaySink = this.replaySink._ejsa;
2051
- for (let idx = 0; idx < types.length; idx++) {
2052
- const eventType = types[idx];
2053
- const eventTypes = capture ? replaySink.etc : replaySink.et;
2054
- eventTypes.push(eventType);
2055
- this.container.addEventListener(eventType, replaySink.h, capture);
2056
- }
2083
+ function bootstrapAppScopedEarlyEventContract(container, appId, bubbleEventTypes, captureEventTypes, dataContainer = window) {
2084
+ const earlyJsactionData = createEarlyJsactionData(container);
2085
+ if (!dataContainer._ejsas) {
2086
+ dataContainer._ejsas = {};
2057
2087
  }
2088
+ dataContainer._ejsas[appId] = earlyJsactionData;
2089
+ addEvents(earlyJsactionData, bubbleEventTypes);
2090
+ addEvents(earlyJsactionData, captureEventTypes, /* capture= */ true);
2091
+ }
2092
+ /** Get the queued `EventInfo` objects that were dispatched before a dispatcher was registered. */
2093
+ function getAppScopedQueuedEventInfos(appId, dataContainer = window) {
2094
+ return getQueuedEventInfos(dataContainer._ejsas?.[appId]);
2058
2095
  }
2059
-
2060
2096
  /**
2061
- * Provides a factory function for bootstrapping an event contract on a
2062
- * specified object (by default, exposed on the `window`).
2063
- * @param field The property on the object that the event contract will be placed on.
2064
- * @param container The container that listens to events
2065
- * @param appId A given identifier for an application. If there are multiple apps on the page
2066
- * then this is how contracts can be initialized for each one.
2067
- * @param eventTypes An array of event names that should be listened to.
2068
- * @param captureEventTypes An array of event names that should be listened to with capture.
2069
- * @param earlyJsactionTracker The object that should receive the event contract.
2097
+ * Registers a dispatcher function on the `EarlyJsactionData` present on the nested object on the
2098
+ * window.
2070
2099
  */
2071
- function bootstrapEarlyEventContract(field, container, appId, eventTypes, captureEventTypes, earlyJsactionTracker = window) {
2072
- if (!earlyJsactionTracker[field]) {
2073
- earlyJsactionTracker[field] = {};
2100
+ function registerAppScopedDispatcher(restriction, appId, dispatcher, dataContainer = window) {
2101
+ registerDispatcher(dataContainer._ejsas?.[appId], dispatcher);
2102
+ }
2103
+ /** Removes all event listener handlers. */
2104
+ function removeAllAppScopedEventListeners(appId, dataContainer = window) {
2105
+ removeAllEventListeners(dataContainer._ejsas?.[appId]);
2106
+ }
2107
+ /** Clear the early event contract. */
2108
+ function clearAppScopedEarlyEventContract(appId, dataContainer = window) {
2109
+ if (!dataContainer._ejsas) {
2110
+ return;
2074
2111
  }
2075
- earlyJsactionTracker[field][appId] = {};
2076
- const eventContract = new EarlyEventContract(earlyJsactionTracker[field][appId], container);
2077
- if (eventTypes)
2078
- eventContract.addEvents(eventTypes);
2079
- if (captureEventTypes)
2080
- eventContract.addEvents(captureEventTypes, true);
2112
+ dataContainer._ejsas[appId] = undefined;
2081
2113
  }
2082
2114
 
2083
- export { Attribute, EventContract, EventContractContainer, EventDispatcher, EventInfoWrapper, EventPhase, bootstrapEarlyEventContract, isCaptureEvent, isSupportedEvent, registerDispatcher, registerEventType, unregisterEventType };
2115
+ export { Attribute, EventContract, EventContractContainer, EventDispatcher, EventInfoWrapper, EventPhase, bootstrapAppScopedEarlyEventContract, clearAppScopedEarlyEventContract, getDefaulted as getActionCache, getAppScopedQueuedEventInfos, isCaptureEventType, isEarlyEventType, registerAppScopedDispatcher, registerDispatcher$1 as registerDispatcher, removeAllAppScopedEventListeners };
2084
2116
  //# sourceMappingURL=event-dispatch.mjs.map