main
js 75 lines 2.02 KB
Raw
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 {enableCreateEventHandleAPI} from 'shared/ReactFeatureFlags';
13
14 export const allNativeEvents: Set<DOMEventName> = new Set();
15
16 if (enableCreateEventHandleAPI) {
17 allNativeEvents.add('beforeblur');
18 allNativeEvents.add('afterblur');
19 }
20
21 /**
22 * Mapping from registration name to event name
23 */
24 export const registrationNameDependencies: {
25 [registrationName: string]: Array<DOMEventName>,
26 } = {};
27
28 /**
29 * Mapping from lowercase registration names to the properly cased version,
30 * used to warn in the case of missing event handlers. Available
31 * only in __DEV__.
32 * @type {Object}
33 */
34 export const possibleRegistrationNames: {
35 [lowerCasedName: string]: string,
36 } = __DEV__ ? {} : (null as any);
37 // Trust the developer to only use possibleRegistrationNames in __DEV__
38
39 export function registerTwoPhaseEvent(
40 registrationName: string,
41 dependencies: Array<DOMEventName>,
42 ): void {
43 registerDirectEvent(registrationName, dependencies);
44 registerDirectEvent(registrationName + 'Capture', dependencies);
45 }
46
47 export function registerDirectEvent(
48 registrationName: string,
49 dependencies: Array<DOMEventName>,
50 ) {
51 if (__DEV__) {
52 if (registrationNameDependencies[registrationName]) {
53 console.error(
54 'EventRegistry: More than one plugin attempted to publish the same ' +
55 'registration name, `%s`.',
56 registrationName,
57 );
58 }
59 }
60
61 registrationNameDependencies[registrationName] = dependencies;
62
63 if (__DEV__) {
64 const lowerCasedName = registrationName.toLowerCase();
65 possibleRegistrationNames[lowerCasedName] = registrationName;
66
67 if (registrationName === 'onDoubleClick') {
68 possibleRegistrationNames.ondblclick = registrationName;
69 }
70 }
71
72 for (let i = 0; i < dependencies.length; i++) {
73 allNativeEvents.add(dependencies[i]);
74 }
75 }