1. /**
    
  2.  * Copyright (c) Meta Platforms, Inc. and affiliates.
    
  3.  *
    
  4.  * This source code is licensed under the MIT license found in the
    
  5.  * LICENSE file in the root directory of this source tree.
    
  6.  *
    
  7.  * @flow
    
  8.  */
    
  9. 
    
  10. import type {DOMEventName} from './DOMEventNames';
    
  11. 
    
  12. import {registerTwoPhaseEvent} from './EventRegistry';
    
  13. import {
    
  14.   ANIMATION_END,
    
  15.   ANIMATION_ITERATION,
    
  16.   ANIMATION_START,
    
  17.   TRANSITION_END,
    
  18. } from './DOMEventNames';
    
  19. 
    
  20. import {enableCreateEventHandleAPI} from 'shared/ReactFeatureFlags';
    
  21. 
    
  22. export const topLevelEventsToReactNames: Map<DOMEventName, string | null> =
    
  23.   new Map();
    
  24. 
    
  25. // NOTE: Capitalization is important in this list!
    
  26. //
    
  27. // E.g. it needs "pointerDown", not "pointerdown".
    
  28. // This is because we derive both React name ("onPointerDown")
    
  29. // and DOM name ("pointerdown") from the same list.
    
  30. //
    
  31. // Exceptions that don't match this convention are listed separately.
    
  32. //
    
  33. // prettier-ignore
    
  34. const simpleEventPluginEvents = [
    
  35.   'abort',
    
  36.   'auxClick',
    
  37.   'cancel',
    
  38.   'canPlay',
    
  39.   'canPlayThrough',
    
  40.   'click',
    
  41.   'close',
    
  42.   'contextMenu',
    
  43.   'copy',
    
  44.   'cut',
    
  45.   'drag',
    
  46.   'dragEnd',
    
  47.   'dragEnter',
    
  48.   'dragExit',
    
  49.   'dragLeave',
    
  50.   'dragOver',
    
  51.   'dragStart',
    
  52.   'drop',
    
  53.   'durationChange',
    
  54.   'emptied',
    
  55.   'encrypted',
    
  56.   'ended',
    
  57.   'error',
    
  58.   'gotPointerCapture',
    
  59.   'input',
    
  60.   'invalid',
    
  61.   'keyDown',
    
  62.   'keyPress',
    
  63.   'keyUp',
    
  64.   'load',
    
  65.   'loadedData',
    
  66.   'loadedMetadata',
    
  67.   'loadStart',
    
  68.   'lostPointerCapture',
    
  69.   'mouseDown',
    
  70.   'mouseMove',
    
  71.   'mouseOut',
    
  72.   'mouseOver',
    
  73.   'mouseUp',
    
  74.   'paste',
    
  75.   'pause',
    
  76.   'play',
    
  77.   'playing',
    
  78.   'pointerCancel',
    
  79.   'pointerDown',
    
  80.   'pointerMove',
    
  81.   'pointerOut',
    
  82.   'pointerOver',
    
  83.   'pointerUp',
    
  84.   'progress',
    
  85.   'rateChange',
    
  86.   'reset',
    
  87.   'resize',
    
  88.   'seeked',
    
  89.   'seeking',
    
  90.   'stalled',
    
  91.   'submit',
    
  92.   'suspend',
    
  93.   'timeUpdate',
    
  94.   'touchCancel',
    
  95.   'touchEnd',
    
  96.   'touchStart',
    
  97.   'volumeChange',
    
  98.   'scroll',
    
  99.   'scrollEnd',
    
  100.   'toggle',
    
  101.   'touchMove',
    
  102.   'waiting',
    
  103.   'wheel',
    
  104. ];
    
  105. 
    
  106. if (enableCreateEventHandleAPI) {
    
  107.   // Special case: these two events don't have on* React handler
    
  108.   // and are only accessible via the createEventHandle API.
    
  109.   topLevelEventsToReactNames.set('beforeblur', null);
    
  110.   topLevelEventsToReactNames.set('afterblur', null);
    
  111. }
    
  112. 
    
  113. function registerSimpleEvent(domEventName: DOMEventName, reactName: string) {
    
  114.   topLevelEventsToReactNames.set(domEventName, reactName);
    
  115.   registerTwoPhaseEvent(reactName, [domEventName]);
    
  116. }
    
  117. 
    
  118. export function registerSimpleEvents() {
    
  119.   for (let i = 0; i < simpleEventPluginEvents.length; i++) {
    
  120.     const eventName = ((simpleEventPluginEvents[i]: any): string);
    
  121.     const domEventName = ((eventName.toLowerCase(): any): DOMEventName);
    
  122.     const capitalizedEvent = eventName[0].toUpperCase() + eventName.slice(1);
    
  123.     registerSimpleEvent(domEventName, 'on' + capitalizedEvent);
    
  124.   }
    
  125.   // Special cases where event names don't match.
    
  126.   registerSimpleEvent(ANIMATION_END, 'onAnimationEnd');
    
  127.   registerSimpleEvent(ANIMATION_ITERATION, 'onAnimationIteration');
    
  128.   registerSimpleEvent(ANIMATION_START, 'onAnimationStart');
    
  129.   registerSimpleEvent('dblclick', 'onDoubleClick');
    
  130.   registerSimpleEvent('focusin', 'onFocus');
    
  131.   registerSimpleEvent('focusout', 'onBlur');
    
  132.   registerSimpleEvent(TRANSITION_END, 'onTransitionEnd');
    
  133. }