react 15.3.2-rc.1 → 15.4.0-rc.3

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 (209) hide show
  1. package/dist/react-with-addons.js +3863 -21388
  2. package/dist/react-with-addons.min.js +3 -6
  3. package/dist/react.js +2639 -19486
  4. package/dist/react.min.js +2 -6
  5. package/lib/KeyEscapeUtils.js +0 -1
  6. package/lib/LinkedStateMixin.js +1 -3
  7. package/lib/PooledClass.js +3 -1
  8. package/lib/React.js +0 -1
  9. package/lib/ReactAddonsDOMDependencies.js +35 -0
  10. package/lib/ReactAddonsDOMDependenciesUMDShim.js +31 -0
  11. package/lib/ReactCSSTransitionGroup.js +60 -43
  12. package/lib/ReactCSSTransitionGroupChild.js +2 -3
  13. package/lib/ReactChildren.js +0 -1
  14. package/lib/ReactClass.js +38 -54
  15. package/lib/ReactComponent.js +0 -1
  16. package/lib/ReactComponentTreeDevtool.js +0 -1
  17. package/lib/ReactComponentTreeHook.js +84 -101
  18. package/lib/{DOMNamespaces.js → ReactComponentTreeHookUMDShim.js} +4 -7
  19. package/lib/ReactComponentWithPureRenderMixin.js +0 -1
  20. package/lib/ReactCurrentOwner.js +1 -2
  21. package/lib/{renderSubtreeIntoContainer.js → ReactCurrentOwnerUMDShim.js} +5 -4
  22. package/lib/ReactDOMFactories.js +0 -1
  23. package/lib/ReactElement.js +6 -14
  24. package/lib/ReactElementSymbol.js +19 -0
  25. package/lib/{ReactDOMComponentFlags.js → ReactElementType.js} +3 -9
  26. package/lib/ReactElementValidator.js +1 -3
  27. package/lib/ReactFragment.js +0 -1
  28. package/lib/ReactLink.js +0 -1
  29. package/lib/ReactNoopUpdateQueue.js +0 -1
  30. package/lib/ReactPropTypeLocationNames.js +1 -1
  31. package/lib/ReactPropTypeLocations.js +2 -12
  32. package/lib/ReactPropTypes.js +5 -3
  33. package/lib/ReactPropTypesSecret.js +1 -1
  34. package/lib/ReactPureComponent.js +0 -1
  35. package/lib/ReactStateSetters.js +0 -1
  36. package/lib/ReactTransitionChildMapping.js +0 -1
  37. package/lib/ReactTransitionEvents.js +1 -2
  38. package/lib/ReactTransitionGroup.js +145 -142
  39. package/lib/ReactUMDEntry.js +11 -6
  40. package/lib/{ReactDOMFeatureFlags.js → ReactUMDShim.js} +3 -6
  41. package/lib/ReactVersion.js +1 -2
  42. package/lib/ReactWithAddons.js +15 -3
  43. package/lib/ReactWithAddonsUMDEntry.js +11 -6
  44. package/lib/canDefineProperty.js +2 -1
  45. package/lib/checkReactTypeSpec.js +0 -1
  46. package/lib/deprecated.js +0 -1
  47. package/lib/flattenChildren.js +0 -1
  48. package/lib/getIteratorFn.js +0 -1
  49. package/lib/onlyChild.js +0 -1
  50. package/lib/reactProdInvariant.js +0 -1
  51. package/lib/sliceChildren.js +0 -1
  52. package/lib/traverseAllChildren.js +11 -3
  53. package/lib/update.js +6 -8
  54. package/package.json +1 -1
  55. package/lib/AutoFocusUtils.js +0 -24
  56. package/lib/BeforeInputEventPlugin.js +0 -390
  57. package/lib/CSSProperty.js +0 -148
  58. package/lib/CSSPropertyOperations.js +0 -205
  59. package/lib/CallbackQueue.js +0 -106
  60. package/lib/ChangeEventPlugin.js +0 -325
  61. package/lib/DOMChildrenOperations.js +0 -194
  62. package/lib/DOMLazyTree.js +0 -118
  63. package/lib/DOMProperty.js +0 -206
  64. package/lib/DOMPropertyOperations.js +0 -221
  65. package/lib/Danger.js +0 -48
  66. package/lib/DefaultEventPluginOrder.js +0 -27
  67. package/lib/DisabledInputUtils.js +0 -50
  68. package/lib/EnterLeaveEventPlugin.js +0 -105
  69. package/lib/EventConstants.js +0 -97
  70. package/lib/EventPluginHub.js +0 -251
  71. package/lib/EventPluginRegistry.js +0 -247
  72. package/lib/EventPluginUtils.js +0 -229
  73. package/lib/EventPropagators.js +0 -137
  74. package/lib/FallbackCompositionState.js +0 -95
  75. package/lib/HTMLDOMPropertyConfig.js +0 -212
  76. package/lib/LinkedValueUtils.js +0 -136
  77. package/lib/NativeMethodsMixin.js +0 -167
  78. package/lib/ReactBrowserEventEmitter.js +0 -330
  79. package/lib/ReactChildReconciler.js +0 -154
  80. package/lib/ReactChildrenMutationWarningHook.js +0 -54
  81. package/lib/ReactComponentBrowserEnvironment.js +0 -30
  82. package/lib/ReactComponentEnvironment.js +0 -45
  83. package/lib/ReactComponentTreeTestUtils.js +0 -87
  84. package/lib/ReactCompositeComponent.js +0 -904
  85. package/lib/ReactDOM.js +0 -110
  86. package/lib/ReactDOMButton.js +0 -24
  87. package/lib/ReactDOMComponent.js +0 -1006
  88. package/lib/ReactDOMComponentTree.js +0 -188
  89. package/lib/ReactDOMContainerInfo.js +0 -33
  90. package/lib/ReactDOMEmptyComponent.js +0 -60
  91. package/lib/ReactDOMFiber.js +0 -76
  92. package/lib/ReactDOMIDOperations.js +0 -34
  93. package/lib/ReactDOMInput.js +0 -269
  94. package/lib/ReactDOMNullInputValuePropHook.js +0 -43
  95. package/lib/ReactDOMOption.js +0 -123
  96. package/lib/ReactDOMSelect.js +0 -201
  97. package/lib/ReactDOMSelection.js +0 -212
  98. package/lib/ReactDOMServer.js +0 -26
  99. package/lib/ReactDOMTextComponent.js +0 -164
  100. package/lib/ReactDOMTextarea.js +0 -155
  101. package/lib/ReactDOMTreeTraversal.js +0 -136
  102. package/lib/ReactDOMUnknownPropertyHook.js +0 -112
  103. package/lib/ReactDebugTool.js +0 -301
  104. package/lib/ReactDefaultBatchingStrategy.js +0 -68
  105. package/lib/ReactDefaultInjection.js +0 -84
  106. package/lib/ReactEmptyComponent.js +0 -30
  107. package/lib/ReactErrorUtils.js +0 -76
  108. package/lib/ReactEventEmitterMixin.js +0 -33
  109. package/lib/ReactEventListener.js +0 -157
  110. package/lib/ReactFeatureFlags.js +0 -22
  111. package/lib/ReactHostComponent.js +0 -76
  112. package/lib/ReactHostOperationHistoryHook.js +0 -37
  113. package/lib/ReactInjection.js +0 -36
  114. package/lib/ReactInputSelection.js +0 -124
  115. package/lib/ReactInstanceHandles.js +0 -302
  116. package/lib/ReactInstanceMap.js +0 -48
  117. package/lib/ReactInstrumentation.js +0 -21
  118. package/lib/ReactInvalidSetStateWarningHook.js +0 -36
  119. package/lib/ReactMarkupChecksum.js +0 -50
  120. package/lib/ReactMount.js +0 -534
  121. package/lib/ReactMultiChild.js +0 -451
  122. package/lib/ReactMultiChildUpdateTypes.js +0 -32
  123. package/lib/ReactNative.js +0 -71
  124. package/lib/ReactNativeAttributePayload.js +0 -371
  125. package/lib/ReactNativeBaseComponent.js +0 -198
  126. package/lib/ReactNativeBridgeEventPlugin.js +0 -60
  127. package/lib/ReactNativeComponentEnvironment.js +0 -31
  128. package/lib/ReactNativeComponentTree.js +0 -68
  129. package/lib/ReactNativeContainerInfo.js +0 -21
  130. package/lib/ReactNativeDOMIDOperations.js +0 -79
  131. package/lib/ReactNativeDefaultInjection.js +0 -101
  132. package/lib/ReactNativeEventEmitter.js +0 -191
  133. package/lib/ReactNativeEventPluginOrder.js +0 -16
  134. package/lib/ReactNativeGlobalResponderHandler.js +0 -25
  135. package/lib/ReactNativeMount.js +0 -193
  136. package/lib/ReactNativePropRegistry.js +0 -52
  137. package/lib/ReactNativeReconcileTransaction.js +0 -129
  138. package/lib/ReactNativeTagHandles.js +0 -56
  139. package/lib/ReactNativeTextComponent.js +0 -71
  140. package/lib/ReactNativeTreeTraversal.js +0 -127
  141. package/lib/ReactNodeTypes.js +0 -40
  142. package/lib/ReactNoop.js +0 -173
  143. package/lib/ReactOwner.js +0 -94
  144. package/lib/ReactPerf.js +0 -494
  145. package/lib/ReactReconcileTransaction.js +0 -178
  146. package/lib/ReactReconciler.js +0 -168
  147. package/lib/ReactRef.js +0 -80
  148. package/lib/ReactServerBatchingStrategy.js +0 -22
  149. package/lib/ReactServerRendering.js +0 -90
  150. package/lib/ReactServerRenderingTransaction.js +0 -90
  151. package/lib/ReactServerUpdateQueue.js +0 -141
  152. package/lib/ReactSimpleEmptyComponent.js +0 -37
  153. package/lib/ReactTestMount.js +0 -126
  154. package/lib/ReactTestReconcileTransaction.js +0 -121
  155. package/lib/ReactTestRenderer.js +0 -144
  156. package/lib/ReactTestUtils.js +0 -518
  157. package/lib/ReactUpdateQueue.js +0 -226
  158. package/lib/ReactUpdates.js +0 -251
  159. package/lib/ResponderEventPlugin.js +0 -510
  160. package/lib/ResponderSyntheticEvent.js +0 -39
  161. package/lib/ResponderTouchHistoryStore.js +0 -184
  162. package/lib/SVGDOMPropertyConfig.js +0 -302
  163. package/lib/SelectEventPlugin.js +0 -196
  164. package/lib/SimpleEventPlugin.js +0 -635
  165. package/lib/SyntheticAnimationEvent.js +0 -39
  166. package/lib/SyntheticClipboardEvent.js +0 -38
  167. package/lib/SyntheticCompositionEvent.js +0 -36
  168. package/lib/SyntheticDragEvent.js +0 -36
  169. package/lib/SyntheticEvent.js +0 -268
  170. package/lib/SyntheticFocusEvent.js +0 -36
  171. package/lib/SyntheticInputEvent.js +0 -37
  172. package/lib/SyntheticKeyboardEvent.js +0 -84
  173. package/lib/SyntheticMouseEvent.js +0 -72
  174. package/lib/SyntheticTouchEvent.js +0 -45
  175. package/lib/SyntheticTransitionEvent.js +0 -39
  176. package/lib/SyntheticUIEvent.js +0 -59
  177. package/lib/SyntheticWheelEvent.js +0 -54
  178. package/lib/TapEventPlugin.js +0 -110
  179. package/lib/TouchHistoryMath.js +0 -99
  180. package/lib/Transaction.js +0 -233
  181. package/lib/ViewportMetrics.js +0 -27
  182. package/lib/accumulate.js +0 -46
  183. package/lib/accumulateInto.js +0 -58
  184. package/lib/adler32.js +0 -44
  185. package/lib/createMicrosoftUnsafeLocalFunction.js +0 -32
  186. package/lib/createReactNativeComponentClass.js +0 -42
  187. package/lib/dangerousStyleValue.js +0 -79
  188. package/lib/escapeTextContentForBrowser.js +0 -123
  189. package/lib/findDOMNode.js +0 -60
  190. package/lib/findNodeHandle.js +0 -91
  191. package/lib/forEachAccumulated.js +0 -31
  192. package/lib/getEventCharCode.js +0 -50
  193. package/lib/getEventKey.js +0 -102
  194. package/lib/getEventModifierState.js +0 -43
  195. package/lib/getEventTarget.js +0 -35
  196. package/lib/getHostComponentFromComposite.js +0 -30
  197. package/lib/getNodeForCharacterOffset.js +0 -74
  198. package/lib/getTestDocument.js +0 -21
  199. package/lib/getTextContentAccessor.js +0 -33
  200. package/lib/getVendorPrefixedEventName.js +0 -101
  201. package/lib/instantiateReactComponent.js +0 -119
  202. package/lib/isEventSupported.js +0 -60
  203. package/lib/isTextInputElement.js +0 -51
  204. package/lib/quoteAttributeValueForBrowser.js +0 -26
  205. package/lib/reactComponentExpect.js +0 -217
  206. package/lib/setInnerHTML.js +0 -98
  207. package/lib/setTextContent.js +0 -48
  208. package/lib/shouldUpdateReactComponent.js +0 -42
  209. package/lib/validateDOMNesting.js +0 -382
@@ -1,247 +0,0 @@
1
- /**
2
- * Copyright 2013-present, Facebook, Inc.
3
- * All rights reserved.
4
- *
5
- * This source code is licensed under the BSD-style license found in the
6
- * LICENSE file in the root directory of this source tree. An additional grant
7
- * of patent rights can be found in the PATENTS file in the same directory.
8
- *
9
- * @providesModule EventPluginRegistry
10
- */
11
-
12
- 'use strict';
13
-
14
- var _prodInvariant = require('./reactProdInvariant');
15
-
16
- var invariant = require('fbjs/lib/invariant');
17
-
18
- /**
19
- * Injectable ordering of event plugins.
20
- */
21
- var EventPluginOrder = null;
22
-
23
- /**
24
- * Injectable mapping from names to event plugin modules.
25
- */
26
- var namesToPlugins = {};
27
-
28
- /**
29
- * Recomputes the plugin list using the injected plugins and plugin ordering.
30
- *
31
- * @private
32
- */
33
- function recomputePluginOrdering() {
34
- if (!EventPluginOrder) {
35
- // Wait until an `EventPluginOrder` is injected.
36
- return;
37
- }
38
- for (var pluginName in namesToPlugins) {
39
- var PluginModule = namesToPlugins[pluginName];
40
- var pluginIndex = EventPluginOrder.indexOf(pluginName);
41
- !(pluginIndex > -1) ? process.env.NODE_ENV !== 'production' ? invariant(false, 'EventPluginRegistry: Cannot inject event plugins that do not exist in the plugin ordering, `%s`.', pluginName) : _prodInvariant('96', pluginName) : void 0;
42
- if (EventPluginRegistry.plugins[pluginIndex]) {
43
- continue;
44
- }
45
- !PluginModule.extractEvents ? process.env.NODE_ENV !== 'production' ? invariant(false, 'EventPluginRegistry: Event plugins must implement an `extractEvents` method, but `%s` does not.', pluginName) : _prodInvariant('97', pluginName) : void 0;
46
- EventPluginRegistry.plugins[pluginIndex] = PluginModule;
47
- var publishedEvents = PluginModule.eventTypes;
48
- for (var eventName in publishedEvents) {
49
- !publishEventForPlugin(publishedEvents[eventName], PluginModule, eventName) ? process.env.NODE_ENV !== 'production' ? invariant(false, 'EventPluginRegistry: Failed to publish event `%s` for plugin `%s`.', eventName, pluginName) : _prodInvariant('98', eventName, pluginName) : void 0;
50
- }
51
- }
52
- }
53
-
54
- /**
55
- * Publishes an event so that it can be dispatched by the supplied plugin.
56
- *
57
- * @param {object} dispatchConfig Dispatch configuration for the event.
58
- * @param {object} PluginModule Plugin publishing the event.
59
- * @return {boolean} True if the event was successfully published.
60
- * @private
61
- */
62
- function publishEventForPlugin(dispatchConfig, PluginModule, eventName) {
63
- !!EventPluginRegistry.eventNameDispatchConfigs.hasOwnProperty(eventName) ? process.env.NODE_ENV !== 'production' ? invariant(false, 'EventPluginHub: More than one plugin attempted to publish the same event name, `%s`.', eventName) : _prodInvariant('99', eventName) : void 0;
64
- EventPluginRegistry.eventNameDispatchConfigs[eventName] = dispatchConfig;
65
-
66
- var phasedRegistrationNames = dispatchConfig.phasedRegistrationNames;
67
- if (phasedRegistrationNames) {
68
- for (var phaseName in phasedRegistrationNames) {
69
- if (phasedRegistrationNames.hasOwnProperty(phaseName)) {
70
- var phasedRegistrationName = phasedRegistrationNames[phaseName];
71
- publishRegistrationName(phasedRegistrationName, PluginModule, eventName);
72
- }
73
- }
74
- return true;
75
- } else if (dispatchConfig.registrationName) {
76
- publishRegistrationName(dispatchConfig.registrationName, PluginModule, eventName);
77
- return true;
78
- }
79
- return false;
80
- }
81
-
82
- /**
83
- * Publishes a registration name that is used to identify dispatched events and
84
- * can be used with `EventPluginHub.putListener` to register listeners.
85
- *
86
- * @param {string} registrationName Registration name to add.
87
- * @param {object} PluginModule Plugin publishing the event.
88
- * @private
89
- */
90
- function publishRegistrationName(registrationName, PluginModule, eventName) {
91
- !!EventPluginRegistry.registrationNameModules[registrationName] ? process.env.NODE_ENV !== 'production' ? invariant(false, 'EventPluginHub: More than one plugin attempted to publish the same registration name, `%s`.', registrationName) : _prodInvariant('100', registrationName) : void 0;
92
- EventPluginRegistry.registrationNameModules[registrationName] = PluginModule;
93
- EventPluginRegistry.registrationNameDependencies[registrationName] = PluginModule.eventTypes[eventName].dependencies;
94
-
95
- if (process.env.NODE_ENV !== 'production') {
96
- var lowerCasedName = registrationName.toLowerCase();
97
- EventPluginRegistry.possibleRegistrationNames[lowerCasedName] = registrationName;
98
-
99
- if (registrationName === 'onDoubleClick') {
100
- EventPluginRegistry.possibleRegistrationNames.ondblclick = registrationName;
101
- }
102
- }
103
- }
104
-
105
- /**
106
- * Registers plugins so that they can extract and dispatch events.
107
- *
108
- * @see {EventPluginHub}
109
- */
110
- var EventPluginRegistry = {
111
-
112
- /**
113
- * Ordered list of injected plugins.
114
- */
115
- plugins: [],
116
-
117
- /**
118
- * Mapping from event name to dispatch config
119
- */
120
- eventNameDispatchConfigs: {},
121
-
122
- /**
123
- * Mapping from registration name to plugin module
124
- */
125
- registrationNameModules: {},
126
-
127
- /**
128
- * Mapping from registration name to event name
129
- */
130
- registrationNameDependencies: {},
131
-
132
- /**
133
- * Mapping from lowercase registration names to the properly cased version,
134
- * used to warn in the case of missing event handlers. Available
135
- * only in __DEV__.
136
- * @type {Object}
137
- */
138
- possibleRegistrationNames: process.env.NODE_ENV !== 'production' ? {} : null,
139
-
140
- /**
141
- * Injects an ordering of plugins (by plugin name). This allows the ordering
142
- * to be decoupled from injection of the actual plugins so that ordering is
143
- * always deterministic regardless of packaging, on-the-fly injection, etc.
144
- *
145
- * @param {array} InjectedEventPluginOrder
146
- * @internal
147
- * @see {EventPluginHub.injection.injectEventPluginOrder}
148
- */
149
- injectEventPluginOrder: function (InjectedEventPluginOrder) {
150
- !!EventPluginOrder ? process.env.NODE_ENV !== 'production' ? invariant(false, 'EventPluginRegistry: Cannot inject event plugin ordering more than once. You are likely trying to load more than one copy of React.') : _prodInvariant('101') : void 0;
151
- // Clone the ordering so it cannot be dynamically mutated.
152
- EventPluginOrder = Array.prototype.slice.call(InjectedEventPluginOrder);
153
- recomputePluginOrdering();
154
- },
155
-
156
- /**
157
- * Injects plugins to be used by `EventPluginHub`. The plugin names must be
158
- * in the ordering injected by `injectEventPluginOrder`.
159
- *
160
- * Plugins can be injected as part of page initialization or on-the-fly.
161
- *
162
- * @param {object} injectedNamesToPlugins Map from names to plugin modules.
163
- * @internal
164
- * @see {EventPluginHub.injection.injectEventPluginsByName}
165
- */
166
- injectEventPluginsByName: function (injectedNamesToPlugins) {
167
- var isOrderingDirty = false;
168
- for (var pluginName in injectedNamesToPlugins) {
169
- if (!injectedNamesToPlugins.hasOwnProperty(pluginName)) {
170
- continue;
171
- }
172
- var PluginModule = injectedNamesToPlugins[pluginName];
173
- if (!namesToPlugins.hasOwnProperty(pluginName) || namesToPlugins[pluginName] !== PluginModule) {
174
- !!namesToPlugins[pluginName] ? process.env.NODE_ENV !== 'production' ? invariant(false, 'EventPluginRegistry: Cannot inject two different event plugins using the same name, `%s`.', pluginName) : _prodInvariant('102', pluginName) : void 0;
175
- namesToPlugins[pluginName] = PluginModule;
176
- isOrderingDirty = true;
177
- }
178
- }
179
- if (isOrderingDirty) {
180
- recomputePluginOrdering();
181
- }
182
- },
183
-
184
- /**
185
- * Looks up the plugin for the supplied event.
186
- *
187
- * @param {object} event A synthetic event.
188
- * @return {?object} The plugin that created the supplied event.
189
- * @internal
190
- */
191
- getPluginModuleForEvent: function (event) {
192
- var dispatchConfig = event.dispatchConfig;
193
- if (dispatchConfig.registrationName) {
194
- return EventPluginRegistry.registrationNameModules[dispatchConfig.registrationName] || null;
195
- }
196
- for (var phase in dispatchConfig.phasedRegistrationNames) {
197
- if (!dispatchConfig.phasedRegistrationNames.hasOwnProperty(phase)) {
198
- continue;
199
- }
200
- var PluginModule = EventPluginRegistry.registrationNameModules[dispatchConfig.phasedRegistrationNames[phase]];
201
- if (PluginModule) {
202
- return PluginModule;
203
- }
204
- }
205
- return null;
206
- },
207
-
208
- /**
209
- * Exposed for unit testing.
210
- * @private
211
- */
212
- _resetEventPlugins: function () {
213
- EventPluginOrder = null;
214
- for (var pluginName in namesToPlugins) {
215
- if (namesToPlugins.hasOwnProperty(pluginName)) {
216
- delete namesToPlugins[pluginName];
217
- }
218
- }
219
- EventPluginRegistry.plugins.length = 0;
220
-
221
- var eventNameDispatchConfigs = EventPluginRegistry.eventNameDispatchConfigs;
222
- for (var eventName in eventNameDispatchConfigs) {
223
- if (eventNameDispatchConfigs.hasOwnProperty(eventName)) {
224
- delete eventNameDispatchConfigs[eventName];
225
- }
226
- }
227
-
228
- var registrationNameModules = EventPluginRegistry.registrationNameModules;
229
- for (var registrationName in registrationNameModules) {
230
- if (registrationNameModules.hasOwnProperty(registrationName)) {
231
- delete registrationNameModules[registrationName];
232
- }
233
- }
234
-
235
- if (process.env.NODE_ENV !== 'production') {
236
- var possibleRegistrationNames = EventPluginRegistry.possibleRegistrationNames;
237
- for (var lowerCasedName in possibleRegistrationNames) {
238
- if (possibleRegistrationNames.hasOwnProperty(lowerCasedName)) {
239
- delete possibleRegistrationNames[lowerCasedName];
240
- }
241
- }
242
- }
243
- }
244
-
245
- };
246
-
247
- module.exports = EventPluginRegistry;
@@ -1,229 +0,0 @@
1
- /**
2
- * Copyright 2013-present, Facebook, Inc.
3
- * All rights reserved.
4
- *
5
- * This source code is licensed under the BSD-style license found in the
6
- * LICENSE file in the root directory of this source tree. An additional grant
7
- * of patent rights can be found in the PATENTS file in the same directory.
8
- *
9
- * @providesModule EventPluginUtils
10
- */
11
-
12
- 'use strict';
13
-
14
- var _prodInvariant = require('./reactProdInvariant');
15
-
16
- var EventConstants = require('./EventConstants');
17
- var ReactErrorUtils = require('./ReactErrorUtils');
18
-
19
- var invariant = require('fbjs/lib/invariant');
20
- var warning = require('fbjs/lib/warning');
21
-
22
- /**
23
- * Injected dependencies:
24
- */
25
-
26
- /**
27
- * - `ComponentTree`: [required] Module that can convert between React instances
28
- * and actual node references.
29
- */
30
- var ComponentTree;
31
- var TreeTraversal;
32
- var injection = {
33
- injectComponentTree: function (Injected) {
34
- ComponentTree = Injected;
35
- if (process.env.NODE_ENV !== 'production') {
36
- process.env.NODE_ENV !== 'production' ? warning(Injected && Injected.getNodeFromInstance && Injected.getInstanceFromNode, 'EventPluginUtils.injection.injectComponentTree(...): Injected ' + 'module is missing getNodeFromInstance or getInstanceFromNode.') : void 0;
37
- }
38
- },
39
- injectTreeTraversal: function (Injected) {
40
- TreeTraversal = Injected;
41
- if (process.env.NODE_ENV !== 'production') {
42
- process.env.NODE_ENV !== 'production' ? warning(Injected && Injected.isAncestor && Injected.getLowestCommonAncestor, 'EventPluginUtils.injection.injectTreeTraversal(...): Injected ' + 'module is missing isAncestor or getLowestCommonAncestor.') : void 0;
43
- }
44
- }
45
- };
46
-
47
- var topLevelTypes = EventConstants.topLevelTypes;
48
-
49
- function isEndish(topLevelType) {
50
- return topLevelType === topLevelTypes.topMouseUp || topLevelType === topLevelTypes.topTouchEnd || topLevelType === topLevelTypes.topTouchCancel;
51
- }
52
-
53
- function isMoveish(topLevelType) {
54
- return topLevelType === topLevelTypes.topMouseMove || topLevelType === topLevelTypes.topTouchMove;
55
- }
56
- function isStartish(topLevelType) {
57
- return topLevelType === topLevelTypes.topMouseDown || topLevelType === topLevelTypes.topTouchStart;
58
- }
59
-
60
- var validateEventDispatches;
61
- if (process.env.NODE_ENV !== 'production') {
62
- validateEventDispatches = function (event) {
63
- var dispatchListeners = event._dispatchListeners;
64
- var dispatchInstances = event._dispatchInstances;
65
-
66
- var listenersIsArr = Array.isArray(dispatchListeners);
67
- var listenersLen = listenersIsArr ? dispatchListeners.length : dispatchListeners ? 1 : 0;
68
-
69
- var instancesIsArr = Array.isArray(dispatchInstances);
70
- var instancesLen = instancesIsArr ? dispatchInstances.length : dispatchInstances ? 1 : 0;
71
-
72
- process.env.NODE_ENV !== 'production' ? warning(instancesIsArr === listenersIsArr && instancesLen === listenersLen, 'EventPluginUtils: Invalid `event`.') : void 0;
73
- };
74
- }
75
-
76
- /**
77
- * Dispatch the event to the listener.
78
- * @param {SyntheticEvent} event SyntheticEvent to handle
79
- * @param {boolean} simulated If the event is simulated (changes exn behavior)
80
- * @param {function} listener Application-level callback
81
- * @param {*} inst Internal component instance
82
- */
83
- function executeDispatch(event, simulated, listener, inst) {
84
- var type = event.type || 'unknown-event';
85
- event.currentTarget = EventPluginUtils.getNodeFromInstance(inst);
86
- if (simulated) {
87
- ReactErrorUtils.invokeGuardedCallbackWithCatch(type, listener, event);
88
- } else {
89
- ReactErrorUtils.invokeGuardedCallback(type, listener, event);
90
- }
91
- event.currentTarget = null;
92
- }
93
-
94
- /**
95
- * Standard/simple iteration through an event's collected dispatches.
96
- */
97
- function executeDispatchesInOrder(event, simulated) {
98
- var dispatchListeners = event._dispatchListeners;
99
- var dispatchInstances = event._dispatchInstances;
100
- if (process.env.NODE_ENV !== 'production') {
101
- validateEventDispatches(event);
102
- }
103
- if (Array.isArray(dispatchListeners)) {
104
- for (var i = 0; i < dispatchListeners.length; i++) {
105
- if (event.isPropagationStopped()) {
106
- break;
107
- }
108
- // Listeners and Instances are two parallel arrays that are always in sync.
109
- executeDispatch(event, simulated, dispatchListeners[i], dispatchInstances[i]);
110
- }
111
- } else if (dispatchListeners) {
112
- executeDispatch(event, simulated, dispatchListeners, dispatchInstances);
113
- }
114
- event._dispatchListeners = null;
115
- event._dispatchInstances = null;
116
- }
117
-
118
- /**
119
- * Standard/simple iteration through an event's collected dispatches, but stops
120
- * at the first dispatch execution returning true, and returns that id.
121
- *
122
- * @return {?string} id of the first dispatch execution who's listener returns
123
- * true, or null if no listener returned true.
124
- */
125
- function executeDispatchesInOrderStopAtTrueImpl(event) {
126
- var dispatchListeners = event._dispatchListeners;
127
- var dispatchInstances = event._dispatchInstances;
128
- if (process.env.NODE_ENV !== 'production') {
129
- validateEventDispatches(event);
130
- }
131
- if (Array.isArray(dispatchListeners)) {
132
- for (var i = 0; i < dispatchListeners.length; i++) {
133
- if (event.isPropagationStopped()) {
134
- break;
135
- }
136
- // Listeners and Instances are two parallel arrays that are always in sync.
137
- if (dispatchListeners[i](event, dispatchInstances[i])) {
138
- return dispatchInstances[i];
139
- }
140
- }
141
- } else if (dispatchListeners) {
142
- if (dispatchListeners(event, dispatchInstances)) {
143
- return dispatchInstances;
144
- }
145
- }
146
- return null;
147
- }
148
-
149
- /**
150
- * @see executeDispatchesInOrderStopAtTrueImpl
151
- */
152
- function executeDispatchesInOrderStopAtTrue(event) {
153
- var ret = executeDispatchesInOrderStopAtTrueImpl(event);
154
- event._dispatchInstances = null;
155
- event._dispatchListeners = null;
156
- return ret;
157
- }
158
-
159
- /**
160
- * Execution of a "direct" dispatch - there must be at most one dispatch
161
- * accumulated on the event or it is considered an error. It doesn't really make
162
- * sense for an event with multiple dispatches (bubbled) to keep track of the
163
- * return values at each dispatch execution, but it does tend to make sense when
164
- * dealing with "direct" dispatches.
165
- *
166
- * @return {*} The return value of executing the single dispatch.
167
- */
168
- function executeDirectDispatch(event) {
169
- if (process.env.NODE_ENV !== 'production') {
170
- validateEventDispatches(event);
171
- }
172
- var dispatchListener = event._dispatchListeners;
173
- var dispatchInstance = event._dispatchInstances;
174
- !!Array.isArray(dispatchListener) ? process.env.NODE_ENV !== 'production' ? invariant(false, 'executeDirectDispatch(...): Invalid `event`.') : _prodInvariant('103') : void 0;
175
- event.currentTarget = dispatchListener ? EventPluginUtils.getNodeFromInstance(dispatchInstance) : null;
176
- var res = dispatchListener ? dispatchListener(event) : null;
177
- event.currentTarget = null;
178
- event._dispatchListeners = null;
179
- event._dispatchInstances = null;
180
- return res;
181
- }
182
-
183
- /**
184
- * @param {SyntheticEvent} event
185
- * @return {boolean} True iff number of dispatches accumulated is greater than 0.
186
- */
187
- function hasDispatches(event) {
188
- return !!event._dispatchListeners;
189
- }
190
-
191
- /**
192
- * General utilities that are useful in creating custom Event Plugins.
193
- */
194
- var EventPluginUtils = {
195
- isEndish: isEndish,
196
- isMoveish: isMoveish,
197
- isStartish: isStartish,
198
-
199
- executeDirectDispatch: executeDirectDispatch,
200
- executeDispatchesInOrder: executeDispatchesInOrder,
201
- executeDispatchesInOrderStopAtTrue: executeDispatchesInOrderStopAtTrue,
202
- hasDispatches: hasDispatches,
203
-
204
- getInstanceFromNode: function (node) {
205
- return ComponentTree.getInstanceFromNode(node);
206
- },
207
- getNodeFromInstance: function (node) {
208
- return ComponentTree.getNodeFromInstance(node);
209
- },
210
- isAncestor: function (a, b) {
211
- return TreeTraversal.isAncestor(a, b);
212
- },
213
- getLowestCommonAncestor: function (a, b) {
214
- return TreeTraversal.getLowestCommonAncestor(a, b);
215
- },
216
- getParentInstance: function (inst) {
217
- return TreeTraversal.getParentInstance(inst);
218
- },
219
- traverseTwoPhase: function (target, fn, arg) {
220
- return TreeTraversal.traverseTwoPhase(target, fn, arg);
221
- },
222
- traverseEnterLeave: function (from, to, fn, argFrom, argTo) {
223
- return TreeTraversal.traverseEnterLeave(from, to, fn, argFrom, argTo);
224
- },
225
-
226
- injection: injection
227
- };
228
-
229
- module.exports = EventPluginUtils;