react 15.3.1-rc.2 → 15.4.0-rc.1

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 (190) hide show
  1. package/dist/react-with-addons.js +3961 -21387
  2. package/dist/react-with-addons.min.js +3 -6
  3. package/dist/react.js +2701 -19464
  4. package/dist/react.min.js +2 -6
  5. package/lib/LinkedStateMixin.js +1 -2
  6. package/lib/PooledClass.js +3 -0
  7. package/lib/ReactAddonsDOMDependencies.js +36 -0
  8. package/lib/ReactAddonsDOMDependenciesUMDShim.js +32 -0
  9. package/lib/ReactCSSTransitionGroup.js +60 -42
  10. package/lib/ReactCSSTransitionGroupChild.js +2 -2
  11. package/lib/ReactClass.js +38 -53
  12. package/lib/ReactComponentTreeHook.js +84 -100
  13. package/lib/{DOMNamespaces.js → ReactComponentTreeHookUMDShim.js} +5 -7
  14. package/lib/ReactCurrentOwner.js +1 -1
  15. package/lib/{renderSubtreeIntoContainer.js → ReactCurrentOwnerUMDShim.js} +6 -4
  16. package/lib/ReactElement.js +6 -29
  17. package/lib/ReactElementSymbol.js +20 -0
  18. package/lib/{ReactDOMComponentFlags.js → ReactElementType.js} +4 -9
  19. package/lib/ReactElementValidator.js +1 -2
  20. package/lib/ReactPropTypeLocationNames.js +1 -0
  21. package/lib/ReactPropTypeLocations.js +2 -11
  22. package/lib/ReactPropTypes.js +30 -13
  23. package/lib/ReactPropTypesSecret.js +1 -0
  24. package/lib/ReactTransitionEvents.js +1 -1
  25. package/lib/ReactTransitionGroup.js +145 -141
  26. package/lib/ReactUMDEntry.js +11 -5
  27. package/lib/{ReactDOMFeatureFlags.js → ReactUMDShim.js} +4 -6
  28. package/lib/ReactVersion.js +1 -1
  29. package/lib/ReactWithAddons.js +15 -2
  30. package/lib/ReactWithAddonsUMDEntry.js +11 -5
  31. package/lib/canDefineProperty.js +2 -0
  32. package/lib/onlyChild.js +1 -1
  33. package/lib/traverseAllChildren.js +11 -2
  34. package/lib/update.js +6 -7
  35. package/package.json +2 -2
  36. package/lib/AutoFocusUtils.js +0 -24
  37. package/lib/BeforeInputEventPlugin.js +0 -388
  38. package/lib/CSSProperty.js +0 -148
  39. package/lib/CSSPropertyOperations.js +0 -205
  40. package/lib/CallbackQueue.js +0 -106
  41. package/lib/ChangeEventPlugin.js +0 -325
  42. package/lib/DOMChildrenOperations.js +0 -194
  43. package/lib/DOMLazyTree.js +0 -118
  44. package/lib/DOMProperty.js +0 -206
  45. package/lib/DOMPropertyOperations.js +0 -221
  46. package/lib/Danger.js +0 -48
  47. package/lib/DefaultEventPluginOrder.js +0 -27
  48. package/lib/DisabledInputUtils.js +0 -50
  49. package/lib/EnterLeaveEventPlugin.js +0 -105
  50. package/lib/EventConstants.js +0 -97
  51. package/lib/EventPluginHub.js +0 -251
  52. package/lib/EventPluginRegistry.js +0 -247
  53. package/lib/EventPluginUtils.js +0 -229
  54. package/lib/EventPropagators.js +0 -137
  55. package/lib/FallbackCompositionState.js +0 -95
  56. package/lib/HTMLDOMPropertyConfig.js +0 -209
  57. package/lib/LinkedValueUtils.js +0 -136
  58. package/lib/NativeMethodsMixin.js +0 -167
  59. package/lib/ReactBrowserEventEmitter.js +0 -317
  60. package/lib/ReactChildReconciler.js +0 -154
  61. package/lib/ReactChildrenMutationWarningHook.js +0 -54
  62. package/lib/ReactComponentBrowserEnvironment.js +0 -30
  63. package/lib/ReactComponentEnvironment.js +0 -45
  64. package/lib/ReactComponentTreeTestUtils.js +0 -87
  65. package/lib/ReactCompositeComponent.js +0 -920
  66. package/lib/ReactDOM.js +0 -110
  67. package/lib/ReactDOMButton.js +0 -24
  68. package/lib/ReactDOMComponent.js +0 -1005
  69. package/lib/ReactDOMComponentTree.js +0 -188
  70. package/lib/ReactDOMContainerInfo.js +0 -33
  71. package/lib/ReactDOMEmptyComponent.js +0 -60
  72. package/lib/ReactDOMFiber.js +0 -78
  73. package/lib/ReactDOMIDOperations.js +0 -34
  74. package/lib/ReactDOMInput.js +0 -269
  75. package/lib/ReactDOMNullInputValuePropHook.js +0 -43
  76. package/lib/ReactDOMOption.js +0 -123
  77. package/lib/ReactDOMSelect.js +0 -201
  78. package/lib/ReactDOMSelection.js +0 -212
  79. package/lib/ReactDOMServer.js +0 -26
  80. package/lib/ReactDOMTextComponent.js +0 -164
  81. package/lib/ReactDOMTextarea.js +0 -155
  82. package/lib/ReactDOMTreeTraversal.js +0 -136
  83. package/lib/ReactDOMUnknownPropertyHook.js +0 -112
  84. package/lib/ReactDebugTool.js +0 -307
  85. package/lib/ReactDefaultBatchingStrategy.js +0 -68
  86. package/lib/ReactDefaultInjection.js +0 -84
  87. package/lib/ReactEmptyComponent.js +0 -30
  88. package/lib/ReactErrorUtils.js +0 -76
  89. package/lib/ReactEventEmitterMixin.js +0 -33
  90. package/lib/ReactEventListener.js +0 -157
  91. package/lib/ReactFeatureFlags.js +0 -22
  92. package/lib/ReactHostComponent.js +0 -76
  93. package/lib/ReactHostOperationHistoryHook.js +0 -37
  94. package/lib/ReactInjection.js +0 -36
  95. package/lib/ReactInputSelection.js +0 -124
  96. package/lib/ReactInstanceHandles.js +0 -302
  97. package/lib/ReactInstanceMap.js +0 -48
  98. package/lib/ReactInstrumentation.js +0 -21
  99. package/lib/ReactInvalidSetStateWarningHook.js +0 -36
  100. package/lib/ReactMarkupChecksum.js +0 -50
  101. package/lib/ReactMount.js +0 -495
  102. package/lib/ReactMultiChild.js +0 -451
  103. package/lib/ReactMultiChildUpdateTypes.js +0 -32
  104. package/lib/ReactNative.js +0 -71
  105. package/lib/ReactNativeAttributePayload.js +0 -371
  106. package/lib/ReactNativeBaseComponent.js +0 -198
  107. package/lib/ReactNativeBridgeEventPlugin.js +0 -60
  108. package/lib/ReactNativeComponentEnvironment.js +0 -31
  109. package/lib/ReactNativeComponentTree.js +0 -68
  110. package/lib/ReactNativeContainerInfo.js +0 -21
  111. package/lib/ReactNativeDOMIDOperations.js +0 -79
  112. package/lib/ReactNativeDefaultInjection.js +0 -101
  113. package/lib/ReactNativeEventEmitter.js +0 -191
  114. package/lib/ReactNativeEventPluginOrder.js +0 -16
  115. package/lib/ReactNativeGlobalResponderHandler.js +0 -25
  116. package/lib/ReactNativeMount.js +0 -193
  117. package/lib/ReactNativePropRegistry.js +0 -52
  118. package/lib/ReactNativeReconcileTransaction.js +0 -116
  119. package/lib/ReactNativeTagHandles.js +0 -56
  120. package/lib/ReactNativeTextComponent.js +0 -71
  121. package/lib/ReactNativeTreeTraversal.js +0 -127
  122. package/lib/ReactNodeTypes.js +0 -40
  123. package/lib/ReactNoop.js +0 -173
  124. package/lib/ReactOwner.js +0 -94
  125. package/lib/ReactPerf.js +0 -494
  126. package/lib/ReactReconcileTransaction.js +0 -178
  127. package/lib/ReactReconciler.js +0 -168
  128. package/lib/ReactRef.js +0 -80
  129. package/lib/ReactServerBatchingStrategy.js +0 -22
  130. package/lib/ReactServerRendering.js +0 -90
  131. package/lib/ReactServerRenderingTransaction.js +0 -90
  132. package/lib/ReactServerUpdateQueue.js +0 -141
  133. package/lib/ReactSimpleEmptyComponent.js +0 -37
  134. package/lib/ReactTestMount.js +0 -123
  135. package/lib/ReactTestReconcileTransaction.js +0 -108
  136. package/lib/ReactTestRenderer.js +0 -144
  137. package/lib/ReactTestUtils.js +0 -518
  138. package/lib/ReactUpdateQueue.js +0 -226
  139. package/lib/ReactUpdates.js +0 -251
  140. package/lib/ResponderEventPlugin.js +0 -510
  141. package/lib/ResponderSyntheticEvent.js +0 -39
  142. package/lib/ResponderTouchHistoryStore.js +0 -184
  143. package/lib/SVGDOMPropertyConfig.js +0 -302
  144. package/lib/SelectEventPlugin.js +0 -196
  145. package/lib/SimpleEventPlugin.js +0 -635
  146. package/lib/SyntheticAnimationEvent.js +0 -39
  147. package/lib/SyntheticClipboardEvent.js +0 -38
  148. package/lib/SyntheticCompositionEvent.js +0 -36
  149. package/lib/SyntheticDragEvent.js +0 -36
  150. package/lib/SyntheticEvent.js +0 -267
  151. package/lib/SyntheticFocusEvent.js +0 -36
  152. package/lib/SyntheticInputEvent.js +0 -37
  153. package/lib/SyntheticKeyboardEvent.js +0 -84
  154. package/lib/SyntheticMouseEvent.js +0 -72
  155. package/lib/SyntheticTouchEvent.js +0 -45
  156. package/lib/SyntheticTransitionEvent.js +0 -39
  157. package/lib/SyntheticUIEvent.js +0 -59
  158. package/lib/SyntheticWheelEvent.js +0 -54
  159. package/lib/TapEventPlugin.js +0 -110
  160. package/lib/TouchHistoryMath.js +0 -99
  161. package/lib/Transaction.js +0 -233
  162. package/lib/ViewportMetrics.js +0 -27
  163. package/lib/accumulate.js +0 -46
  164. package/lib/accumulateInto.js +0 -58
  165. package/lib/adler32.js +0 -44
  166. package/lib/createMicrosoftUnsafeLocalFunction.js +0 -32
  167. package/lib/createReactNativeComponentClass.js +0 -42
  168. package/lib/dangerousStyleValue.js +0 -79
  169. package/lib/escapeTextContentForBrowser.js +0 -122
  170. package/lib/findDOMNode.js +0 -60
  171. package/lib/findNodeHandle.js +0 -91
  172. package/lib/forEachAccumulated.js +0 -31
  173. package/lib/getEventCharCode.js +0 -50
  174. package/lib/getEventKey.js +0 -102
  175. package/lib/getEventModifierState.js +0 -43
  176. package/lib/getEventTarget.js +0 -35
  177. package/lib/getHostComponentFromComposite.js +0 -30
  178. package/lib/getNodeForCharacterOffset.js +0 -74
  179. package/lib/getTestDocument.js +0 -21
  180. package/lib/getTextContentAccessor.js +0 -33
  181. package/lib/getVendorPrefixedEventName.js +0 -101
  182. package/lib/instantiateReactComponent.js +0 -119
  183. package/lib/isEventSupported.js +0 -60
  184. package/lib/isTextInputElement.js +0 -51
  185. package/lib/quoteAttributeValueForBrowser.js +0 -26
  186. package/lib/reactComponentExpect.js +0 -217
  187. package/lib/setInnerHTML.js +0 -98
  188. package/lib/setTextContent.js +0 -48
  189. package/lib/shouldUpdateReactComponent.js +0 -42
  190. package/lib/validateDOMNesting.js +0 -369
@@ -13,14 +13,20 @@
13
13
 
14
14
  var _assign = require('object-assign');
15
15
 
16
- var ReactDOM = require('./ReactDOM');
17
- var ReactDOMServer = require('./ReactDOMServer');
18
16
  var React = require('./React');
19
17
 
20
- // `version` will be added here by ReactIsomorphic.
18
+ // `version` will be added here by the React module.
21
19
  var ReactUMDEntry = _assign({
22
- __SECRET_DOM_DO_NOT_USE_OR_YOU_WILL_BE_FIRED: ReactDOM,
23
- __SECRET_DOM_SERVER_DO_NOT_USE_OR_YOU_WILL_BE_FIRED: ReactDOMServer
20
+ __SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED: {
21
+ ReactCurrentOwner: require('./ReactCurrentOwner')
22
+ }
24
23
  }, React);
25
24
 
25
+ if (process.env.NODE_ENV !== 'production') {
26
+ _assign(ReactUMDEntry.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED, {
27
+ // ReactComponentTreeHook should not be included in production.
28
+ ReactComponentTreeHook: require('./ReactComponentTreeHook')
29
+ });
30
+ }
31
+
26
32
  module.exports = ReactUMDEntry;
@@ -6,13 +6,11 @@
6
6
  * LICENSE file in the root directory of this source tree. An additional grant
7
7
  * of patent rights can be found in the PATENTS file in the same directory.
8
8
  *
9
- * @providesModule ReactDOMFeatureFlags
9
+ * @providesModule ReactUMDShim
10
10
  */
11
11
 
12
- 'use strict';
12
+ /* globals React */
13
13
 
14
- var ReactDOMFeatureFlags = {
15
- useCreateElement: true
16
- };
14
+ 'use strict';
17
15
 
18
- module.exports = ReactDOMFeatureFlags;
16
+ module.exports = React;
@@ -11,4 +11,4 @@
11
11
 
12
12
  'use strict';
13
13
 
14
- module.exports = '15.3.1-rc.2';
14
+ module.exports = '15.4.0-rc.1';
@@ -13,6 +13,7 @@
13
13
 
14
14
  var LinkedStateMixin = require('./LinkedStateMixin');
15
15
  var React = require('./React');
16
+ var ReactAddonsDOMDependencies = require('./ReactAddonsDOMDependencies');
16
17
  var ReactComponentWithPureRenderMixin = require('./ReactComponentWithPureRenderMixin');
17
18
  var ReactCSSTransitionGroup = require('./ReactCSSTransitionGroup');
18
19
  var ReactFragment = require('./ReactFragment');
@@ -33,8 +34,20 @@ React.addons = {
33
34
  };
34
35
 
35
36
  if (process.env.NODE_ENV !== 'production') {
36
- React.addons.Perf = require('./ReactPerf');
37
- React.addons.TestUtils = require('./ReactTestUtils');
37
+ // For the UMD build we get these lazily from the global since they're tied
38
+ // to the DOM renderer and it hasn't loaded yet.
39
+ Object.defineProperty(React.addons, 'Perf', {
40
+ enumerable: true,
41
+ get: function () {
42
+ return ReactAddonsDOMDependencies.getReactPerf();
43
+ }
44
+ });
45
+ Object.defineProperty(React.addons, 'TestUtils', {
46
+ enumerable: true,
47
+ get: function () {
48
+ return ReactAddonsDOMDependencies.getReactTestUtils();
49
+ }
50
+ });
38
51
  }
39
52
 
40
53
  module.exports = React;
@@ -13,14 +13,20 @@
13
13
 
14
14
  var _assign = require('object-assign');
15
15
 
16
- var ReactDOM = require('./ReactDOM');
17
- var ReactDOMServer = require('./ReactDOMServer');
18
16
  var ReactWithAddons = require('./ReactWithAddons');
19
17
 
20
- // `version` will be added here by ReactIsomorphic.
18
+ // `version` will be added here by the React module.
21
19
  var ReactWithAddonsUMDEntry = _assign({
22
- __SECRET_DOM_DO_NOT_USE_OR_YOU_WILL_BE_FIRED: ReactDOM,
23
- __SECRET_DOM_SERVER_DO_NOT_USE_OR_YOU_WILL_BE_FIRED: ReactDOMServer
20
+ __SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED: {
21
+ ReactCurrentOwner: require('./ReactCurrentOwner')
22
+ }
24
23
  }, ReactWithAddons);
25
24
 
25
+ if (process.env.NODE_ENV !== 'production') {
26
+ _assign(ReactWithAddonsUMDEntry.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED, {
27
+ // ReactComponentTreeHook should not be included in production.
28
+ ReactComponentTreeHook: require('./ReactComponentTreeHook')
29
+ });
30
+ }
31
+
26
32
  module.exports = ReactWithAddonsUMDEntry;
@@ -6,6 +6,7 @@
6
6
  * LICENSE file in the root directory of this source tree. An additional grant
7
7
  * of patent rights can be found in the PATENTS file in the same directory.
8
8
  *
9
+ *
9
10
  * @providesModule canDefineProperty
10
11
  */
11
12
 
@@ -14,6 +15,7 @@
14
15
  var canDefineProperty = false;
15
16
  if (process.env.NODE_ENV !== 'production') {
16
17
  try {
18
+ // $FlowFixMe https://github.com/facebook/flow/issues/285
17
19
  Object.defineProperty({}, 'x', { get: function () {} });
18
20
  canDefineProperty = true;
19
21
  } catch (x) {
package/lib/onlyChild.js CHANGED
@@ -31,7 +31,7 @@ var invariant = require('fbjs/lib/invariant');
31
31
  * structure.
32
32
  */
33
33
  function onlyChild(children) {
34
- !ReactElement.isValidElement(children) ? process.env.NODE_ENV !== 'production' ? invariant(false, 'onlyChild must be passed a children with exactly one child.') : _prodInvariant('23') : void 0;
34
+ !ReactElement.isValidElement(children) ? process.env.NODE_ENV !== 'production' ? invariant(false, 'React.Children.only expected to receive a single React element child.') : _prodInvariant('143') : void 0;
35
35
  return children;
36
36
  }
37
37
 
@@ -14,7 +14,7 @@
14
14
  var _prodInvariant = require('./reactProdInvariant');
15
15
 
16
16
  var ReactCurrentOwner = require('./ReactCurrentOwner');
17
- var ReactElement = require('./ReactElement');
17
+ var REACT_ELEMENT_TYPE = require('./ReactElementSymbol');
18
18
 
19
19
  var getIteratorFn = require('./getIteratorFn');
20
20
  var invariant = require('fbjs/lib/invariant');
@@ -24,6 +24,12 @@ var warning = require('fbjs/lib/warning');
24
24
  var SEPARATOR = '.';
25
25
  var SUBSEPARATOR = ':';
26
26
 
27
+ /**
28
+ * This is inlined from ReactElement since this file is shared between
29
+ * isomorphic and renderers. We could extract this to a
30
+ *
31
+ */
32
+
27
33
  /**
28
34
  * TODO: Test that a single child and an array with one item have the same key
29
35
  * pattern.
@@ -65,7 +71,10 @@ function traverseAllChildrenImpl(children, nameSoFar, callback, traverseContext)
65
71
  children = null;
66
72
  }
67
73
 
68
- if (children === null || type === 'string' || type === 'number' || ReactElement.isValidElement(children)) {
74
+ if (children === null || type === 'string' || type === 'number' ||
75
+ // The following is inlined from ReactElement. This means we can optimize
76
+ // some checks. React Fiber also inlines this logic for similar purposes.
77
+ type === 'object' && children.$$typeof === REACT_ELEMENT_TYPE) {
69
78
  callback(traverseContext, children,
70
79
  // If it's the only child, treat the name as if it was wrapped in an array
71
80
  // so that it's consistent if the number of children grows.
package/lib/update.js CHANGED
@@ -16,7 +16,6 @@
16
16
  var _prodInvariant = require('./reactProdInvariant'),
17
17
  _assign = require('object-assign');
18
18
 
19
- var keyOf = require('fbjs/lib/keyOf');
20
19
  var invariant = require('fbjs/lib/invariant');
21
20
  var hasOwnProperty = {}.hasOwnProperty;
22
21
 
@@ -30,12 +29,12 @@ function shallowCopy(x) {
30
29
  }
31
30
  }
32
31
 
33
- var COMMAND_PUSH = keyOf({ $push: null });
34
- var COMMAND_UNSHIFT = keyOf({ $unshift: null });
35
- var COMMAND_SPLICE = keyOf({ $splice: null });
36
- var COMMAND_SET = keyOf({ $set: null });
37
- var COMMAND_MERGE = keyOf({ $merge: null });
38
- var COMMAND_APPLY = keyOf({ $apply: null });
32
+ var COMMAND_PUSH = '$push';
33
+ var COMMAND_UNSHIFT = '$unshift';
34
+ var COMMAND_SPLICE = '$splice';
35
+ var COMMAND_SET = '$set';
36
+ var COMMAND_MERGE = '$merge';
37
+ var COMMAND_APPLY = '$apply';
39
38
 
40
39
  var ALL_COMMANDS_LIST = [COMMAND_PUSH, COMMAND_UNSHIFT, COMMAND_SPLICE, COMMAND_SET, COMMAND_MERGE, COMMAND_APPLY];
41
40
 
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "react",
3
3
  "description": "React is a JavaScript library for building user interfaces.",
4
- "version": "15.3.1-rc.2",
4
+ "version": "15.4.0-rc.1",
5
5
  "keywords": [
6
6
  "react"
7
7
  ],
@@ -23,7 +23,7 @@
23
23
  "node": ">=0.10.0"
24
24
  },
25
25
  "dependencies": {
26
- "fbjs": "^0.8.1",
26
+ "fbjs": "^0.8.4",
27
27
  "loose-envify": "^1.1.0",
28
28
  "object-assign": "^4.1.0"
29
29
  },
@@ -1,24 +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 AutoFocusUtils
10
- */
11
-
12
- 'use strict';
13
-
14
- var ReactDOMComponentTree = require('./ReactDOMComponentTree');
15
-
16
- var focusNode = require('fbjs/lib/focusNode');
17
-
18
- var AutoFocusUtils = {
19
- focusDOMComponent: function () {
20
- focusNode(ReactDOMComponentTree.getNodeFromInstance(this));
21
- }
22
- };
23
-
24
- module.exports = AutoFocusUtils;
@@ -1,388 +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 BeforeInputEventPlugin
10
- */
11
-
12
- 'use strict';
13
-
14
- var EventConstants = require('./EventConstants');
15
- var EventPropagators = require('./EventPropagators');
16
- var ExecutionEnvironment = require('fbjs/lib/ExecutionEnvironment');
17
- var FallbackCompositionState = require('./FallbackCompositionState');
18
- var SyntheticCompositionEvent = require('./SyntheticCompositionEvent');
19
- var SyntheticInputEvent = require('./SyntheticInputEvent');
20
-
21
- var keyOf = require('fbjs/lib/keyOf');
22
-
23
- var END_KEYCODES = [9, 13, 27, 32]; // Tab, Return, Esc, Space
24
- var START_KEYCODE = 229;
25
-
26
- var canUseCompositionEvent = ExecutionEnvironment.canUseDOM && 'CompositionEvent' in window;
27
-
28
- var documentMode = null;
29
- if (ExecutionEnvironment.canUseDOM && 'documentMode' in document) {
30
- documentMode = document.documentMode;
31
- }
32
-
33
- // Webkit offers a very useful `textInput` event that can be used to
34
- // directly represent `beforeInput`. The IE `textinput` event is not as
35
- // useful, so we don't use it.
36
- var canUseTextInputEvent = ExecutionEnvironment.canUseDOM && 'TextEvent' in window && !documentMode && !isPresto();
37
-
38
- // In IE9+, we have access to composition events, but the data supplied
39
- // by the native compositionend event may be incorrect. Japanese ideographic
40
- // spaces, for instance (\u3000) are not recorded correctly.
41
- var useFallbackCompositionData = ExecutionEnvironment.canUseDOM && (!canUseCompositionEvent || documentMode && documentMode > 8 && documentMode <= 11);
42
-
43
- /**
44
- * Opera <= 12 includes TextEvent in window, but does not fire
45
- * text input events. Rely on keypress instead.
46
- */
47
- function isPresto() {
48
- var opera = window.opera;
49
- return typeof opera === 'object' && typeof opera.version === 'function' && parseInt(opera.version(), 10) <= 12;
50
- }
51
-
52
- var SPACEBAR_CODE = 32;
53
- var SPACEBAR_CHAR = String.fromCharCode(SPACEBAR_CODE);
54
-
55
- var topLevelTypes = EventConstants.topLevelTypes;
56
-
57
- // Events and their corresponding property names.
58
- var eventTypes = {
59
- beforeInput: {
60
- phasedRegistrationNames: {
61
- bubbled: keyOf({ onBeforeInput: null }),
62
- captured: keyOf({ onBeforeInputCapture: null })
63
- },
64
- dependencies: [topLevelTypes.topCompositionEnd, topLevelTypes.topKeyPress, topLevelTypes.topTextInput, topLevelTypes.topPaste]
65
- },
66
- compositionEnd: {
67
- phasedRegistrationNames: {
68
- bubbled: keyOf({ onCompositionEnd: null }),
69
- captured: keyOf({ onCompositionEndCapture: null })
70
- },
71
- dependencies: [topLevelTypes.topBlur, topLevelTypes.topCompositionEnd, topLevelTypes.topKeyDown, topLevelTypes.topKeyPress, topLevelTypes.topKeyUp, topLevelTypes.topMouseDown]
72
- },
73
- compositionStart: {
74
- phasedRegistrationNames: {
75
- bubbled: keyOf({ onCompositionStart: null }),
76
- captured: keyOf({ onCompositionStartCapture: null })
77
- },
78
- dependencies: [topLevelTypes.topBlur, topLevelTypes.topCompositionStart, topLevelTypes.topKeyDown, topLevelTypes.topKeyPress, topLevelTypes.topKeyUp, topLevelTypes.topMouseDown]
79
- },
80
- compositionUpdate: {
81
- phasedRegistrationNames: {
82
- bubbled: keyOf({ onCompositionUpdate: null }),
83
- captured: keyOf({ onCompositionUpdateCapture: null })
84
- },
85
- dependencies: [topLevelTypes.topBlur, topLevelTypes.topCompositionUpdate, topLevelTypes.topKeyDown, topLevelTypes.topKeyPress, topLevelTypes.topKeyUp, topLevelTypes.topMouseDown]
86
- }
87
- };
88
-
89
- // Track whether we've ever handled a keypress on the space key.
90
- var hasSpaceKeypress = false;
91
-
92
- /**
93
- * Return whether a native keypress event is assumed to be a command.
94
- * This is required because Firefox fires `keypress` events for key commands
95
- * (cut, copy, select-all, etc.) even though no character is inserted.
96
- */
97
- function isKeypressCommand(nativeEvent) {
98
- return (nativeEvent.ctrlKey || nativeEvent.altKey || nativeEvent.metaKey) &&
99
- // ctrlKey && altKey is equivalent to AltGr, and is not a command.
100
- !(nativeEvent.ctrlKey && nativeEvent.altKey);
101
- }
102
-
103
- /**
104
- * Translate native top level events into event types.
105
- *
106
- * @param {string} topLevelType
107
- * @return {object}
108
- */
109
- function getCompositionEventType(topLevelType) {
110
- switch (topLevelType) {
111
- case topLevelTypes.topCompositionStart:
112
- return eventTypes.compositionStart;
113
- case topLevelTypes.topCompositionEnd:
114
- return eventTypes.compositionEnd;
115
- case topLevelTypes.topCompositionUpdate:
116
- return eventTypes.compositionUpdate;
117
- }
118
- }
119
-
120
- /**
121
- * Does our fallback best-guess model think this event signifies that
122
- * composition has begun?
123
- *
124
- * @param {string} topLevelType
125
- * @param {object} nativeEvent
126
- * @return {boolean}
127
- */
128
- function isFallbackCompositionStart(topLevelType, nativeEvent) {
129
- return topLevelType === topLevelTypes.topKeyDown && nativeEvent.keyCode === START_KEYCODE;
130
- }
131
-
132
- /**
133
- * Does our fallback mode think that this event is the end of composition?
134
- *
135
- * @param {string} topLevelType
136
- * @param {object} nativeEvent
137
- * @return {boolean}
138
- */
139
- function isFallbackCompositionEnd(topLevelType, nativeEvent) {
140
- switch (topLevelType) {
141
- case topLevelTypes.topKeyUp:
142
- // Command keys insert or clear IME input.
143
- return END_KEYCODES.indexOf(nativeEvent.keyCode) !== -1;
144
- case topLevelTypes.topKeyDown:
145
- // Expect IME keyCode on each keydown. If we get any other
146
- // code we must have exited earlier.
147
- return nativeEvent.keyCode !== START_KEYCODE;
148
- case topLevelTypes.topKeyPress:
149
- case topLevelTypes.topMouseDown:
150
- case topLevelTypes.topBlur:
151
- // Events are not possible without cancelling IME.
152
- return true;
153
- default:
154
- return false;
155
- }
156
- }
157
-
158
- /**
159
- * Google Input Tools provides composition data via a CustomEvent,
160
- * with the `data` property populated in the `detail` object. If this
161
- * is available on the event object, use it. If not, this is a plain
162
- * composition event and we have nothing special to extract.
163
- *
164
- * @param {object} nativeEvent
165
- * @return {?string}
166
- */
167
- function getDataFromCustomEvent(nativeEvent) {
168
- var detail = nativeEvent.detail;
169
- if (typeof detail === 'object' && 'data' in detail) {
170
- return detail.data;
171
- }
172
- return null;
173
- }
174
-
175
- // Track the current IME composition fallback object, if any.
176
- var currentComposition = null;
177
-
178
- /**
179
- * @return {?object} A SyntheticCompositionEvent.
180
- */
181
- function extractCompositionEvent(topLevelType, targetInst, nativeEvent, nativeEventTarget) {
182
- var eventType;
183
- var fallbackData;
184
-
185
- if (canUseCompositionEvent) {
186
- eventType = getCompositionEventType(topLevelType);
187
- } else if (!currentComposition) {
188
- if (isFallbackCompositionStart(topLevelType, nativeEvent)) {
189
- eventType = eventTypes.compositionStart;
190
- }
191
- } else if (isFallbackCompositionEnd(topLevelType, nativeEvent)) {
192
- eventType = eventTypes.compositionEnd;
193
- }
194
-
195
- if (!eventType) {
196
- return null;
197
- }
198
-
199
- if (useFallbackCompositionData) {
200
- // The current composition is stored statically and must not be
201
- // overwritten while composition continues.
202
- if (!currentComposition && eventType === eventTypes.compositionStart) {
203
- currentComposition = FallbackCompositionState.getPooled(nativeEventTarget);
204
- } else if (eventType === eventTypes.compositionEnd) {
205
- if (currentComposition) {
206
- fallbackData = currentComposition.getData();
207
- }
208
- }
209
- }
210
-
211
- var event = SyntheticCompositionEvent.getPooled(eventType, targetInst, nativeEvent, nativeEventTarget);
212
-
213
- if (fallbackData) {
214
- // Inject data generated from fallback path into the synthetic event.
215
- // This matches the property of native CompositionEventInterface.
216
- event.data = fallbackData;
217
- } else {
218
- var customData = getDataFromCustomEvent(nativeEvent);
219
- if (customData !== null) {
220
- event.data = customData;
221
- }
222
- }
223
-
224
- EventPropagators.accumulateTwoPhaseDispatches(event);
225
- return event;
226
- }
227
-
228
- /**
229
- * @param {string} topLevelType Record from `EventConstants`.
230
- * @param {object} nativeEvent Native browser event.
231
- * @return {?string} The string corresponding to this `beforeInput` event.
232
- */
233
- function getNativeBeforeInputChars(topLevelType, nativeEvent) {
234
- switch (topLevelType) {
235
- case topLevelTypes.topCompositionEnd:
236
- return getDataFromCustomEvent(nativeEvent);
237
- case topLevelTypes.topKeyPress:
238
- /**
239
- * If native `textInput` events are available, our goal is to make
240
- * use of them. However, there is a special case: the spacebar key.
241
- * In Webkit, preventing default on a spacebar `textInput` event
242
- * cancels character insertion, but it *also* causes the browser
243
- * to fall back to its default spacebar behavior of scrolling the
244
- * page.
245
- *
246
- * Tracking at:
247
- * https://code.google.com/p/chromium/issues/detail?id=355103
248
- *
249
- * To avoid this issue, use the keypress event as if no `textInput`
250
- * event is available.
251
- */
252
- var which = nativeEvent.which;
253
- if (which !== SPACEBAR_CODE) {
254
- return null;
255
- }
256
-
257
- hasSpaceKeypress = true;
258
- return SPACEBAR_CHAR;
259
-
260
- case topLevelTypes.topTextInput:
261
- // Record the characters to be added to the DOM.
262
- var chars = nativeEvent.data;
263
-
264
- // If it's a spacebar character, assume that we have already handled
265
- // it at the keypress level and bail immediately. Android Chrome
266
- // doesn't give us keycodes, so we need to blacklist it.
267
- if (chars === SPACEBAR_CHAR && hasSpaceKeypress) {
268
- return null;
269
- }
270
-
271
- return chars;
272
-
273
- default:
274
- // For other native event types, do nothing.
275
- return null;
276
- }
277
- }
278
-
279
- /**
280
- * For browsers that do not provide the `textInput` event, extract the
281
- * appropriate string to use for SyntheticInputEvent.
282
- *
283
- * @param {string} topLevelType Record from `EventConstants`.
284
- * @param {object} nativeEvent Native browser event.
285
- * @return {?string} The fallback string for this `beforeInput` event.
286
- */
287
- function getFallbackBeforeInputChars(topLevelType, nativeEvent) {
288
- // If we are currently composing (IME) and using a fallback to do so,
289
- // try to extract the composed characters from the fallback object.
290
- if (currentComposition) {
291
- if (topLevelType === topLevelTypes.topCompositionEnd || isFallbackCompositionEnd(topLevelType, nativeEvent)) {
292
- var chars = currentComposition.getData();
293
- FallbackCompositionState.release(currentComposition);
294
- currentComposition = null;
295
- return chars;
296
- }
297
- return null;
298
- }
299
-
300
- switch (topLevelType) {
301
- case topLevelTypes.topPaste:
302
- // If a paste event occurs after a keypress, throw out the input
303
- // chars. Paste events should not lead to BeforeInput events.
304
- return null;
305
- case topLevelTypes.topKeyPress:
306
- /**
307
- * As of v27, Firefox may fire keypress events even when no character
308
- * will be inserted. A few possibilities:
309
- *
310
- * - `which` is `0`. Arrow keys, Esc key, etc.
311
- *
312
- * - `which` is the pressed key code, but no char is available.
313
- * Ex: 'AltGr + d` in Polish. There is no modified character for
314
- * this key combination and no character is inserted into the
315
- * document, but FF fires the keypress for char code `100` anyway.
316
- * No `input` event will occur.
317
- *
318
- * - `which` is the pressed key code, but a command combination is
319
- * being used. Ex: `Cmd+C`. No character is inserted, and no
320
- * `input` event will occur.
321
- */
322
- if (nativeEvent.which && !isKeypressCommand(nativeEvent)) {
323
- return String.fromCharCode(nativeEvent.which);
324
- }
325
- return null;
326
- case topLevelTypes.topCompositionEnd:
327
- return useFallbackCompositionData ? null : nativeEvent.data;
328
- default:
329
- return null;
330
- }
331
- }
332
-
333
- /**
334
- * Extract a SyntheticInputEvent for `beforeInput`, based on either native
335
- * `textInput` or fallback behavior.
336
- *
337
- * @return {?object} A SyntheticInputEvent.
338
- */
339
- function extractBeforeInputEvent(topLevelType, targetInst, nativeEvent, nativeEventTarget) {
340
- var chars;
341
-
342
- if (canUseTextInputEvent) {
343
- chars = getNativeBeforeInputChars(topLevelType, nativeEvent);
344
- } else {
345
- chars = getFallbackBeforeInputChars(topLevelType, nativeEvent);
346
- }
347
-
348
- // If no characters are being inserted, no BeforeInput event should
349
- // be fired.
350
- if (!chars) {
351
- return null;
352
- }
353
-
354
- var event = SyntheticInputEvent.getPooled(eventTypes.beforeInput, targetInst, nativeEvent, nativeEventTarget);
355
-
356
- event.data = chars;
357
- EventPropagators.accumulateTwoPhaseDispatches(event);
358
- return event;
359
- }
360
-
361
- /**
362
- * Create an `onBeforeInput` event to match
363
- * http://www.w3.org/TR/2013/WD-DOM-Level-3-Events-20131105/#events-inputevents.
364
- *
365
- * This event plugin is based on the native `textInput` event
366
- * available in Chrome, Safari, Opera, and IE. This event fires after
367
- * `onKeyPress` and `onCompositionEnd`, but before `onInput`.
368
- *
369
- * `beforeInput` is spec'd but not implemented in any browsers, and
370
- * the `input` event does not provide any useful information about what has
371
- * actually been added, contrary to the spec. Thus, `textInput` is the best
372
- * available event to identify the characters that have actually been inserted
373
- * into the target node.
374
- *
375
- * This plugin is also responsible for emitting `composition` events, thus
376
- * allowing us to share composition fallback code for both `beforeInput` and
377
- * `composition` event types.
378
- */
379
- var BeforeInputEventPlugin = {
380
-
381
- eventTypes: eventTypes,
382
-
383
- extractEvents: function (topLevelType, targetInst, nativeEvent, nativeEventTarget) {
384
- return [extractCompositionEvent(topLevelType, targetInst, nativeEvent, nativeEventTarget), extractBeforeInputEvent(topLevelType, targetInst, nativeEvent, nativeEventTarget)];
385
- }
386
- };
387
-
388
- module.exports = BeforeInputEventPlugin;