react 0.9.0-rc1 → 0.11.0-rc1

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 (168) hide show
  1. package/README.md +3 -0
  2. package/dist/JSXTransformer.js +13445 -0
  3. package/dist/react-with-addons.js +20226 -0
  4. package/dist/react-with-addons.min.js +22 -0
  5. package/dist/react.js +18434 -0
  6. package/dist/react.min.js +21 -0
  7. package/lib/AutoFocusMixin.js +4 -2
  8. package/lib/BeforeInputEventPlugin.js +222 -0
  9. package/lib/CSSCore.js +1 -1
  10. package/lib/CSSProperty.js +1 -1
  11. package/lib/CSSPropertyOperations.js +4 -4
  12. package/lib/{ReactMountReady.js → CallbackQueue.js} +33 -25
  13. package/lib/ChangeEventPlugin.js +2 -2
  14. package/lib/ClientReactRootIndex.js +1 -1
  15. package/lib/CompositionEventPlugin.js +6 -2
  16. package/lib/DOMChildrenOperations.js +34 -21
  17. package/lib/DOMProperty.js +52 -22
  18. package/lib/DOMPropertyOperations.js +29 -17
  19. package/lib/Danger.js +1 -1
  20. package/lib/DefaultEventPluginOrder.js +2 -1
  21. package/lib/EnterLeaveEventPlugin.js +1 -1
  22. package/lib/EventConstants.js +2 -1
  23. package/lib/EventListener.js +5 -2
  24. package/lib/EventPluginHub.js +5 -6
  25. package/lib/EventPluginRegistry.js +27 -4
  26. package/lib/EventPluginUtils.js +12 -2
  27. package/lib/EventPropagators.js +1 -1
  28. package/lib/ExecutionEnvironment.js +9 -3
  29. package/lib/{DefaultDOMPropertyConfig.js → HTMLDOMPropertyConfig.js} +47 -58
  30. package/lib/LinkedStateMixin.js +1 -1
  31. package/lib/LinkedValueUtils.js +27 -29
  32. package/lib/LocalEventTrapMixin.js +52 -0
  33. package/lib/MobileSafariClickEventPlugin.js +1 -1
  34. package/lib/PooledClass.js +1 -1
  35. package/lib/React.js +39 -4
  36. package/lib/ReactBrowserComponentMixin.js +46 -0
  37. package/lib/{ReactEventEmitter.js → ReactBrowserEventEmitter.js} +118 -95
  38. package/lib/ReactCSSTransitionGroup.js +13 -11
  39. package/lib/ReactCSSTransitionGroupChild.js +3 -6
  40. package/lib/ReactChildren.js +35 -14
  41. package/lib/ReactComponent.js +120 -224
  42. package/lib/ReactComponentBrowserEnvironment.js +4 -37
  43. package/lib/ReactComponentWithPureRenderMixin.js +54 -0
  44. package/lib/ReactCompositeComponent.js +250 -288
  45. package/lib/ReactContext.js +1 -1
  46. package/lib/ReactCurrentOwner.js +1 -1
  47. package/lib/ReactDOM.js +26 -24
  48. package/lib/ReactDOMButton.js +3 -2
  49. package/lib/ReactDOMComponent.js +43 -24
  50. package/lib/ReactDOMForm.js +8 -13
  51. package/lib/ReactDOMIDOperations.js +3 -32
  52. package/lib/ReactDOMImg.js +8 -14
  53. package/lib/ReactDOMInput.js +3 -2
  54. package/lib/ReactDOMOption.js +12 -8
  55. package/lib/ReactDOMSelect.js +19 -17
  56. package/lib/ReactDOMSelection.js +36 -11
  57. package/lib/ReactDOMTextarea.js +10 -8
  58. package/lib/ReactDefaultBatchingStrategy.js +4 -4
  59. package/lib/ReactDefaultInjection.js +28 -15
  60. package/lib/ReactDefaultPerf.js +29 -12
  61. package/lib/ReactDefaultPerfAnalysis.js +5 -1
  62. package/lib/ReactDescriptor.js +243 -0
  63. package/lib/ReactDescriptorValidator.js +283 -0
  64. package/lib/ReactEmptyComponent.js +78 -0
  65. package/lib/ReactErrorUtils.js +1 -1
  66. package/lib/ReactEventEmitterMixin.js +2 -4
  67. package/lib/ReactEventListener.js +189 -0
  68. package/lib/ReactInjection.js +9 -3
  69. package/lib/ReactInputSelection.js +3 -2
  70. package/lib/ReactInstanceHandles.js +1 -1
  71. package/lib/ReactLink.js +25 -1
  72. package/lib/ReactMarkupChecksum.js +1 -1
  73. package/lib/ReactMount.js +62 -22
  74. package/lib/ReactMultiChild.js +19 -14
  75. package/lib/ReactMultiChildUpdateTypes.js +1 -1
  76. package/lib/ReactOwner.js +7 -2
  77. package/lib/ReactPerf.js +1 -1
  78. package/lib/ReactPropTransferer.js +45 -30
  79. package/lib/ReactPropTypeLocationNames.js +1 -1
  80. package/lib/ReactPropTypeLocations.js +1 -1
  81. package/lib/ReactPropTypes.js +222 -238
  82. package/lib/ReactPutListenerQueue.js +3 -3
  83. package/lib/ReactReconcileTransaction.js +22 -21
  84. package/lib/ReactRootIndex.js +1 -1
  85. package/lib/ReactServerRendering.js +42 -12
  86. package/lib/ReactServerRenderingTransaction.js +115 -0
  87. package/lib/ReactStateSetters.js +1 -1
  88. package/lib/ReactTestUtils.js +412 -0
  89. package/lib/ReactTextComponent.js +22 -14
  90. package/lib/ReactTransitionChildMapping.js +3 -3
  91. package/lib/ReactTransitionEvents.js +20 -1
  92. package/lib/ReactTransitionGroup.js +10 -7
  93. package/lib/ReactUpdates.js +140 -23
  94. package/lib/ReactWithAddons.js +13 -3
  95. package/lib/SVGDOMPropertyConfig.js +97 -0
  96. package/lib/SelectEventPlugin.js +1 -1
  97. package/lib/ServerReactRootIndex.js +1 -1
  98. package/lib/SimpleEventPlugin.js +8 -2
  99. package/lib/SyntheticClipboardEvent.js +1 -1
  100. package/lib/SyntheticCompositionEvent.js +1 -1
  101. package/lib/SyntheticDragEvent.js +1 -1
  102. package/lib/SyntheticEvent.js +1 -1
  103. package/lib/SyntheticFocusEvent.js +1 -1
  104. package/lib/SyntheticInputEvent.js +52 -0
  105. package/lib/SyntheticKeyboardEvent.js +34 -5
  106. package/lib/SyntheticMouseEvent.js +4 -1
  107. package/lib/SyntheticTouchEvent.js +5 -2
  108. package/lib/SyntheticUIEvent.js +25 -3
  109. package/lib/SyntheticWheelEvent.js +1 -1
  110. package/lib/Transaction.js +1 -33
  111. package/lib/ViewportMetrics.js +1 -1
  112. package/lib/accumulate.js +1 -1
  113. package/lib/adler32.js +1 -1
  114. package/lib/cloneWithProps.js +11 -9
  115. package/lib/containsNode.js +1 -1
  116. package/lib/copyProperties.js +1 -1
  117. package/lib/createArrayFrom.js +1 -1
  118. package/lib/createFullPageComponent.js +2 -2
  119. package/lib/createNodesFromMarkup.js +1 -1
  120. package/lib/cx.js +1 -1
  121. package/lib/dangerousStyleValue.js +12 -6
  122. package/lib/emptyFunction.js +1 -1
  123. package/lib/{ReactComponentEnvironment.js → emptyObject.js} +7 -6
  124. package/lib/escapeTextForBrowser.js +3 -4
  125. package/lib/flattenChildren.js +10 -8
  126. package/lib/focusNode.js +33 -0
  127. package/lib/forEachAccumulated.js +1 -1
  128. package/lib/getActiveElement.js +1 -1
  129. package/lib/getEventKey.js +36 -6
  130. package/lib/getEventModifierState.js +52 -0
  131. package/lib/getEventTarget.js +1 -1
  132. package/lib/getMarkupWrap.js +3 -1
  133. package/lib/getNodeForCharacterOffset.js +1 -1
  134. package/lib/getReactRootElementInContainer.js +1 -1
  135. package/lib/getTextContentAccessor.js +2 -2
  136. package/lib/getUnboundedScrollPosition.js +1 -1
  137. package/lib/hyphenate.js +4 -1
  138. package/lib/hyphenateStyleName.js +46 -0
  139. package/lib/instantiateReactComponent.js +62 -0
  140. package/lib/invariant.js +21 -23
  141. package/lib/isEventSupported.js +1 -1
  142. package/lib/isNode.js +2 -2
  143. package/lib/isTextInputElement.js +1 -1
  144. package/lib/isTextNode.js +1 -1
  145. package/lib/joinClasses.js +1 -1
  146. package/lib/keyMirror.js +1 -1
  147. package/lib/keyOf.js +1 -1
  148. package/lib/{objMap.js → mapObject.js} +9 -4
  149. package/lib/memoizeStringOnly.js +1 -1
  150. package/lib/merge.js +1 -1
  151. package/lib/mergeHelpers.js +12 -1
  152. package/lib/mergeInto.js +4 -3
  153. package/lib/mixInto.js +1 -1
  154. package/lib/monitorCodeUse.js +37 -0
  155. package/lib/onlyChild.js +4 -4
  156. package/lib/performance.js +33 -0
  157. package/lib/performanceNow.js +6 -15
  158. package/lib/setInnerHTML.js +77 -0
  159. package/lib/shallowEqual.js +1 -1
  160. package/lib/shouldUpdateReactComponent.js +15 -29
  161. package/lib/toArray.js +1 -1
  162. package/lib/traverseAllChildren.js +10 -6
  163. package/lib/update.js +171 -0
  164. package/lib/warning.js +19 -11
  165. package/package.json +5 -3
  166. package/lib/ReactEventTopLevelCallback.js +0 -109
  167. package/lib/createObjectFrom.js +0 -61
  168. package/lib/objMapKeyVal.js +0 -47
@@ -1,5 +1,5 @@
1
1
  /**
2
- * Copyright 2013 Facebook, Inc.
2
+ * Copyright 2013-2014 Facebook, Inc.
3
3
  *
4
4
  * Licensed under the Apache License, Version 2.0 (the "License");
5
5
  * you may not use this file except in compliance with the License.
package/lib/accumulate.js CHANGED
@@ -1,5 +1,5 @@
1
1
  /**
2
- * Copyright 2013 Facebook, Inc.
2
+ * Copyright 2013-2014 Facebook, Inc.
3
3
  *
4
4
  * Licensed under the Apache License, Version 2.0 (the "License");
5
5
  * you may not use this file except in compliance with the License.
package/lib/adler32.js CHANGED
@@ -1,5 +1,5 @@
1
1
  /**
2
- * Copyright 2013 Facebook, Inc.
2
+ * Copyright 2013-2014 Facebook, Inc.
3
3
  *
4
4
  * Licensed under the Apache License, Version 2.0 (the "License");
5
5
  * you may not use this file except in compliance with the License.
@@ -1,5 +1,5 @@
1
1
  /**
2
- * Copyright 2013 Facebook, Inc.
2
+ * Copyright 2013-2014 Facebook, Inc.
3
3
  *
4
4
  * Licensed under the Apache License, Version 2.0 (the "License");
5
5
  * you may not use this file except in compliance with the License.
@@ -22,6 +22,7 @@
22
22
  var ReactPropTransferer = require("./ReactPropTransferer");
23
23
 
24
24
  var keyOf = require("./keyOf");
25
+ var warning = require("./warning");
25
26
 
26
27
  var CHILDREN_PROP = keyOf({children: null});
27
28
 
@@ -36,13 +37,12 @@ var CHILDREN_PROP = keyOf({children: null});
36
37
  */
37
38
  function cloneWithProps(child, props) {
38
39
  if ("production" !== process.env.NODE_ENV) {
39
- if (child.props.ref) {
40
- console.warn(
41
- 'You are calling cloneWithProps() on a child with a ref. This is ' +
42
- 'dangerous because you\'re creating a new child which will not be ' +
43
- 'added as a ref to its parent.'
44
- );
45
- }
40
+ ("production" !== process.env.NODE_ENV ? warning(
41
+ !child.props.ref,
42
+ 'You are calling cloneWithProps() on a child with a ref. This is ' +
43
+ 'dangerous because you\'re creating a new child which will not be ' +
44
+ 'added as a ref to its parent.'
45
+ ) : null);
46
46
  }
47
47
 
48
48
  var newProps = ReactPropTransferer.mergeProps(props, child.props);
@@ -53,7 +53,9 @@ function cloneWithProps(child, props) {
53
53
  newProps.children = child.props.children;
54
54
  }
55
55
 
56
- return child.constructor.ConvenienceConstructor(newProps);
56
+ // The current API doesn't retain _owner and _context, which is why this
57
+ // doesn't use ReactDescriptor.cloneAndReplaceProps.
58
+ return child.constructor(newProps);
57
59
  }
58
60
 
59
61
  module.exports = cloneWithProps;
@@ -1,5 +1,5 @@
1
1
  /**
2
- * Copyright 2013 Facebook, Inc.
2
+ * Copyright 2013-2014 Facebook, Inc.
3
3
  *
4
4
  * Licensed under the Apache License, Version 2.0 (the "License");
5
5
  * you may not use this file except in compliance with the License.
@@ -1,5 +1,5 @@
1
1
  /**
2
- * Copyright 2013 Facebook, Inc.
2
+ * Copyright 2013-2014 Facebook, Inc.
3
3
  *
4
4
  * Licensed under the Apache License, Version 2.0 (the "License");
5
5
  * you may not use this file except in compliance with the License.
@@ -1,5 +1,5 @@
1
1
  /**
2
- * Copyright 2013 Facebook, Inc.
2
+ * Copyright 2013-2014 Facebook, Inc.
3
3
  *
4
4
  * Licensed under the Apache License, Version 2.0 (the "License");
5
5
  * you may not use this file except in compliance with the License.
@@ -1,5 +1,5 @@
1
1
  /**
2
- * Copyright 2013 Facebook, Inc.
2
+ * Copyright 2013-2014 Facebook, Inc.
3
3
  *
4
4
  * Licensed under the Apache License, Version 2.0 (the "License");
5
5
  * you may not use this file except in compliance with the License.
@@ -38,7 +38,7 @@ var invariant = require("./invariant");
38
38
  function createFullPageComponent(componentClass) {
39
39
  var FullPageComponent = ReactCompositeComponent.createClass({
40
40
  displayName: 'ReactFullPageComponent' + (
41
- componentClass.componentConstructor.displayName || ''
41
+ componentClass.type.displayName || ''
42
42
  ),
43
43
 
44
44
  componentWillUnmount: function() {
@@ -1,5 +1,5 @@
1
1
  /**
2
- * Copyright 2013 Facebook, Inc.
2
+ * Copyright 2013-2014 Facebook, Inc.
3
3
  *
4
4
  * Licensed under the Apache License, Version 2.0 (the "License");
5
5
  * you may not use this file except in compliance with the License.
package/lib/cx.js CHANGED
@@ -1,5 +1,5 @@
1
1
  /**
2
- * Copyright 2013 Facebook, Inc.
2
+ * Copyright 2013-2014 Facebook, Inc.
3
3
  *
4
4
  * Licensed under the Apache License, Version 2.0 (the "License");
5
5
  * you may not use this file except in compliance with the License.
@@ -1,5 +1,5 @@
1
1
  /**
2
- * Copyright 2013 Facebook, Inc.
2
+ * Copyright 2013-2014 Facebook, Inc.
3
3
  *
4
4
  * Licensed under the Apache License, Version 2.0 (the "License");
5
5
  * you may not use this file except in compliance with the License.
@@ -21,16 +21,18 @@
21
21
 
22
22
  var CSSProperty = require("./CSSProperty");
23
23
 
24
+ var isUnitlessNumber = CSSProperty.isUnitlessNumber;
25
+
24
26
  /**
25
- * Convert a value into the proper css writable value. The `styleName` name
26
- * name should be logical (no hyphens), as specified
27
+ * Convert a value into the proper css writable value. The style name `name`
28
+ * should be logical (no hyphens), as specified
27
29
  * in `CSSProperty.isUnitlessNumber`.
28
30
  *
29
- * @param {string} styleName CSS property name such as `topMargin`.
31
+ * @param {string} name CSS property name such as `topMargin`.
30
32
  * @param {*} value CSS property value such as `10px`.
31
33
  * @return {string} Normalized style value with dimensions applied.
32
34
  */
33
- function dangerousStyleValue(styleName, value) {
35
+ function dangerousStyleValue(name, value) {
34
36
  // Note that we've removed escapeTextForBrowser() calls here since the
35
37
  // whole string will be escaped when the attribute is injected into
36
38
  // the markup. If you provide unsafe user data here they can inject
@@ -47,10 +49,14 @@ function dangerousStyleValue(styleName, value) {
47
49
  }
48
50
 
49
51
  var isNonNumeric = isNaN(value);
50
- if (isNonNumeric || value === 0 || CSSProperty.isUnitlessNumber[styleName]) {
52
+ if (isNonNumeric || value === 0 ||
53
+ isUnitlessNumber.hasOwnProperty(name) && isUnitlessNumber[name]) {
51
54
  return '' + value; // cast to string
52
55
  }
53
56
 
57
+ if (typeof value === 'string') {
58
+ value = value.trim();
59
+ }
54
60
  return value + 'px';
55
61
  }
56
62
 
@@ -1,5 +1,5 @@
1
1
  /**
2
- * Copyright 2013 Facebook, Inc.
2
+ * Copyright 2013-2014 Facebook, Inc.
3
3
  *
4
4
  * Licensed under the Apache License, Version 2.0 (the "License");
5
5
  * you may not use this file except in compliance with the License.
@@ -1,5 +1,5 @@
1
1
  /**
2
- * Copyright 2013 Facebook, Inc.
2
+ * Copyright 2013-2014 Facebook, Inc.
3
3
  *
4
4
  * Licensed under the Apache License, Version 2.0 (the "License");
5
5
  * you may not use this file except in compliance with the License.
@@ -13,14 +13,15 @@
13
13
  * See the License for the specific language governing permissions and
14
14
  * limitations under the License.
15
15
  *
16
- * @providesModule ReactComponentEnvironment
16
+ * @providesModule emptyObject
17
17
  */
18
18
 
19
19
  "use strict";
20
20
 
21
- var ReactComponentBrowserEnvironment =
22
- require("./ReactComponentBrowserEnvironment");
21
+ var emptyObject = {};
23
22
 
24
- var ReactComponentEnvironment = ReactComponentBrowserEnvironment;
23
+ if ("production" !== process.env.NODE_ENV) {
24
+ Object.freeze(emptyObject);
25
+ }
25
26
 
26
- module.exports = ReactComponentEnvironment;
27
+ module.exports = emptyObject;
@@ -1,5 +1,5 @@
1
1
  /**
2
- * Copyright 2013 Facebook, Inc.
2
+ * Copyright 2013-2014 Facebook, Inc.
3
3
  *
4
4
  * Licensed under the Apache License, Version 2.0 (the "License");
5
5
  * you may not use this file except in compliance with the License.
@@ -24,11 +24,10 @@ var ESCAPE_LOOKUP = {
24
24
  ">": ">",
25
25
  "<": "&lt;",
26
26
  "\"": "&quot;",
27
- "'": "&#x27;",
28
- "/": "&#x2f;"
27
+ "'": "&#x27;"
29
28
  };
30
29
 
31
- var ESCAPE_REGEX = /[&><"'\/]/g;
30
+ var ESCAPE_REGEX = /[&><"']/g;
32
31
 
33
32
  function escaper(match) {
34
33
  return ESCAPE_LOOKUP[match];
@@ -1,5 +1,5 @@
1
1
  /**
2
- * Copyright 2013 Facebook, Inc.
2
+ * Copyright 2013-2014 Facebook, Inc.
3
3
  *
4
4
  * Licensed under the Apache License, Version 2.0 (the "License");
5
5
  * you may not use this file except in compliance with the License.
@@ -18,8 +18,8 @@
18
18
 
19
19
  "use strict";
20
20
 
21
- var invariant = require("./invariant");
22
21
  var traverseAllChildren = require("./traverseAllChildren");
22
+ var warning = require("./warning");
23
23
 
24
24
  /**
25
25
  * @param {function} traverseContext Context passed through traversal.
@@ -29,13 +29,15 @@ var traverseAllChildren = require("./traverseAllChildren");
29
29
  function flattenSingleChildIntoContext(traverseContext, child, name) {
30
30
  // We found a component instance.
31
31
  var result = traverseContext;
32
- ("production" !== process.env.NODE_ENV ? invariant(
33
- !result.hasOwnProperty(name),
34
- 'flattenChildren(...): Encountered two children with the same key, `%s`. ' +
35
- 'Children keys must be unique.',
32
+ var keyUnique = !result.hasOwnProperty(name);
33
+ ("production" !== process.env.NODE_ENV ? warning(
34
+ keyUnique,
35
+ 'flattenChildren(...): Encountered two children with the same key, ' +
36
+ '`%s`. Child keys must be unique; when two children share a key, only ' +
37
+ 'the first child will be used.',
36
38
  name
37
- ) : invariant(!result.hasOwnProperty(name)));
38
- if (child != null) {
39
+ ) : null);
40
+ if (keyUnique && child != null) {
39
41
  result[name] = child;
40
42
  }
41
43
  }
@@ -0,0 +1,33 @@
1
+ /**
2
+ * Copyright 2014 Facebook, Inc.
3
+ *
4
+ * Licensed under the Apache License, Version 2.0 (the "License");
5
+ * you may not use this file except in compliance with the License.
6
+ * You may obtain a copy of the License at
7
+ *
8
+ * http://www.apache.org/licenses/LICENSE-2.0
9
+ *
10
+ * Unless required by applicable law or agreed to in writing, software
11
+ * distributed under the License is distributed on an "AS IS" BASIS,
12
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ * See the License for the specific language governing permissions and
14
+ * limitations under the License.
15
+ *
16
+ * @providesModule focusNode
17
+ */
18
+
19
+ "use strict";
20
+
21
+ /**
22
+ * IE8 throws if an input/textarea is disabled and we try to focus it.
23
+ * Focus only when necessary.
24
+ *
25
+ * @param {DOMElement} node input/textarea to focus
26
+ */
27
+ function focusNode(node) {
28
+ if (!node.disabled) {
29
+ node.focus();
30
+ }
31
+ }
32
+
33
+ module.exports = focusNode;
@@ -1,5 +1,5 @@
1
1
  /**
2
- * Copyright 2013 Facebook, Inc.
2
+ * Copyright 2013-2014 Facebook, Inc.
3
3
  *
4
4
  * Licensed under the Apache License, Version 2.0 (the "License");
5
5
  * you may not use this file except in compliance with the License.
@@ -1,5 +1,5 @@
1
1
  /**
2
- * Copyright 2013 Facebook, Inc.
2
+ * Copyright 2013-2014 Facebook, Inc.
3
3
  *
4
4
  * Licensed under the Apache License, Version 2.0 (the "License");
5
5
  * you may not use this file except in compliance with the License.
@@ -1,5 +1,5 @@
1
1
  /**
2
- * Copyright 2013 Facebook, Inc.
2
+ * Copyright 2013-2014 Facebook, Inc.
3
3
  *
4
4
  * Licensed under the Apache License, Version 2.0 (the "License");
5
5
  * you may not use this file except in compliance with the License.
@@ -19,8 +19,10 @@
19
19
 
20
20
  "use strict";
21
21
 
22
+ var invariant = require("./invariant");
23
+
22
24
  /**
23
- * Normalization of deprecated HTML5 "key" values
25
+ * Normalization of deprecated HTML5 `key` values
24
26
  * @see https://developer.mozilla.org/en-US/docs/Web/API/KeyboardEvent#Key_names
25
27
  */
26
28
  var normalizeKey = {
@@ -39,7 +41,7 @@ var normalizeKey = {
39
41
  };
40
42
 
41
43
  /**
42
- * Translation from legacy "which/keyCode" to HTML5 "key"
44
+ * Translation from legacy `which`/`keyCode` to HTML5 `key`
43
45
  * Only special keys supported, all others depend on keyboard layout or browser
44
46
  * @see https://developer.mozilla.org/en-US/docs/Web/API/KeyboardEvent#Key_names
45
47
  */
@@ -77,9 +79,37 @@ var translateToKey = {
77
79
  * @return {string} Normalized `key` property.
78
80
  */
79
81
  function getEventKey(nativeEvent) {
80
- return 'key' in nativeEvent ?
81
- normalizeKey[nativeEvent.key] || nativeEvent.key :
82
- translateToKey[nativeEvent.which || nativeEvent.keyCode] || 'Unidentified';
82
+ if (nativeEvent.key) {
83
+ // Normalize inconsistent values reported by browsers due to
84
+ // implementations of a working draft specification.
85
+
86
+ // FireFox implements `key` but returns `MozPrintableKey` for all
87
+ // printable characters (normalized to `Unidentified`), ignore it.
88
+ var key = normalizeKey[nativeEvent.key] || nativeEvent.key;
89
+ if (key !== 'Unidentified') {
90
+ return key;
91
+ }
92
+ }
93
+
94
+ // Browser does not implement `key`, polyfill as much of it as we can.
95
+ if (nativeEvent.type === 'keypress') {
96
+ // Create the character from the `charCode` ourselves and use as an almost
97
+ // perfect replacement.
98
+ var charCode = 'charCode' in nativeEvent ?
99
+ nativeEvent.charCode :
100
+ nativeEvent.keyCode;
101
+
102
+ // The enter-key is technically both printable and non-printable and can
103
+ // thus be captured by `keypress`, no other non-printable key should.
104
+ return charCode === 13 ? 'Enter' : String.fromCharCode(charCode);
105
+ }
106
+ if (nativeEvent.type === 'keydown' || nativeEvent.type === 'keyup') {
107
+ // While user keyboard layout determines the actual meaning of each
108
+ // `keyCode` value, almost all function keys have a universal value.
109
+ return translateToKey[nativeEvent.keyCode] || 'Unidentified';
110
+ }
111
+
112
+ ("production" !== process.env.NODE_ENV ? invariant(false, "Unexpected keyboard event type: %s", nativeEvent.type) : invariant(false));
83
113
  }
84
114
 
85
115
  module.exports = getEventKey;
@@ -0,0 +1,52 @@
1
+ /**
2
+ * Copyright 2013 Facebook, Inc.
3
+ *
4
+ * Licensed under the Apache License, Version 2.0 (the "License");
5
+ * you may not use this file except in compliance with the License.
6
+ * You may obtain a copy of the License at
7
+ *
8
+ * http://www.apache.org/licenses/LICENSE-2.0
9
+ *
10
+ * Unless required by applicable law or agreed to in writing, software
11
+ * distributed under the License is distributed on an "AS IS" BASIS,
12
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ * See the License for the specific language governing permissions and
14
+ * limitations under the License.
15
+ *
16
+ * @providesModule getEventModifierState
17
+ * @typechecks static-only
18
+ */
19
+
20
+ "use strict";
21
+
22
+ /**
23
+ * Translation from modifier key to the associated property in the event.
24
+ * @see http://www.w3.org/TR/DOM-Level-3-Events/#keys-Modifiers
25
+ */
26
+
27
+ var modifierKeyToProp = {
28
+ 'alt': 'altKey',
29
+ 'control': 'ctrlKey',
30
+ 'meta': 'metaKey',
31
+ 'shift': 'shiftKey'
32
+ };
33
+
34
+ // IE8 does not implement getModifierState so we simply map it to the only
35
+ // modifier keys exposed by the event itself, does not support Lock-keys.
36
+ // Currently, all major browsers except Chrome seems to support Lock-keys.
37
+ function modifierStateGetter(keyArg) {
38
+ /*jshint validthis:true */
39
+ var syntheticEvent = this;
40
+ var nativeEvent = syntheticEvent.nativeEvent;
41
+ if (nativeEvent.getModifierState) {
42
+ return nativeEvent.getModifierState(keyArg);
43
+ }
44
+ var keyProp = modifierKeyToProp[keyArg.toLowerCase()];
45
+ return keyProp && nativeEvent[keyProp];
46
+ }
47
+
48
+ function getEventModifierState(nativeEvent) {
49
+ return modifierStateGetter;
50
+ }
51
+
52
+ module.exports = getEventModifierState;
@@ -1,5 +1,5 @@
1
1
  /**
2
- * Copyright 2013 Facebook, Inc.
2
+ * Copyright 2013-2014 Facebook, Inc.
3
3
  *
4
4
  * Licensed under the Apache License, Version 2.0 (the "License");
5
5
  * you may not use this file except in compliance with the License.