react 0.10.0 → 0.11.2

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 (104) hide show
  1. package/README.md +3 -0
  2. package/dist/JSXTransformer.js +20344 -0
  3. package/dist/react-with-addons.js +20276 -0
  4. package/dist/react-with-addons.min.js +22 -0
  5. package/dist/react.js +18484 -0
  6. package/dist/react.min.js +21 -0
  7. package/lib/BeforeInputEventPlugin.js +222 -0
  8. package/lib/CSSPropertyOperations.js +3 -3
  9. package/lib/{ReactMountReady.js → CallbackQueue.js} +32 -24
  10. package/lib/ChangeEventPlugin.js +1 -1
  11. package/lib/CompositionEventPlugin.js +5 -1
  12. package/lib/DOMChildrenOperations.js +21 -14
  13. package/lib/DOMProperty.js +45 -17
  14. package/lib/DOMPropertyOperations.js +22 -10
  15. package/lib/DefaultEventPluginOrder.js +1 -0
  16. package/lib/EventConstants.js +1 -0
  17. package/lib/EventListener.js +5 -2
  18. package/lib/EventPluginHub.js +0 -5
  19. package/lib/EventPluginRegistry.js +6 -4
  20. package/lib/EventPluginUtils.js +11 -1
  21. package/lib/ExecutionEnvironment.js +8 -2
  22. package/lib/{DefaultDOMPropertyConfig.js → HTMLDOMPropertyConfig.js} +42 -49
  23. package/lib/LinkedValueUtils.js +21 -22
  24. package/lib/LocalEventTrapMixin.js +52 -0
  25. package/lib/React.js +57 -3
  26. package/lib/ReactBrowserComponentMixin.js +4 -0
  27. package/lib/{ReactEventEmitter.js → ReactBrowserEventEmitter.js} +115 -94
  28. package/lib/ReactCSSTransitionGroup.js +2 -0
  29. package/lib/ReactCSSTransitionGroupChild.js +2 -5
  30. package/lib/ReactChildren.js +31 -10
  31. package/lib/ReactComponent.js +88 -237
  32. package/lib/ReactComponentBrowserEnvironment.js +3 -2
  33. package/lib/ReactComponentWithPureRenderMixin.js +54 -0
  34. package/lib/ReactCompositeComponent.js +222 -384
  35. package/lib/ReactDOM.js +22 -18
  36. package/lib/ReactDOMComponent.js +26 -24
  37. package/lib/ReactDOMForm.js +5 -13
  38. package/lib/ReactDOMIDOperations.js +2 -31
  39. package/lib/ReactDOMImg.js +5 -14
  40. package/lib/ReactDOMSelect.js +16 -15
  41. package/lib/ReactDOMSelection.js +35 -10
  42. package/lib/ReactDOMTextarea.js +2 -4
  43. package/lib/ReactDefaultBatchingStrategy.js +3 -3
  44. package/lib/ReactDefaultInjection.js +18 -15
  45. package/lib/ReactDefaultPerf.js +28 -11
  46. package/lib/ReactDefaultPerfAnalysis.js +4 -0
  47. package/lib/ReactDescriptor.js +251 -0
  48. package/lib/ReactDescriptorValidator.js +283 -0
  49. package/lib/ReactEmptyComponent.js +78 -0
  50. package/lib/ReactEventEmitterMixin.js +1 -3
  51. package/lib/ReactEventListener.js +189 -0
  52. package/lib/ReactInjection.js +4 -2
  53. package/lib/ReactLink.js +24 -0
  54. package/lib/ReactMount.js +51 -19
  55. package/lib/ReactMultiChild.js +9 -11
  56. package/lib/ReactPropTransferer.js +44 -29
  57. package/lib/ReactPropTypes.js +226 -242
  58. package/lib/ReactPutListenerQueue.js +2 -2
  59. package/lib/ReactReconcileTransaction.js +14 -14
  60. package/lib/ReactServerRendering.js +5 -5
  61. package/lib/ReactServerRenderingTransaction.js +4 -5
  62. package/lib/ReactTestUtils.js +39 -21
  63. package/lib/ReactTextComponent.js +8 -22
  64. package/lib/ReactTransitionChildMapping.js +2 -2
  65. package/lib/ReactTransitionEvents.js +19 -0
  66. package/lib/ReactTransitionGroup.js +9 -6
  67. package/lib/ReactUpdates.js +139 -22
  68. package/lib/ReactWithAddons.js +5 -2
  69. package/lib/SVGDOMPropertyConfig.js +97 -0
  70. package/lib/SimpleEventPlugin.js +7 -1
  71. package/lib/SyntheticInputEvent.js +52 -0
  72. package/lib/SyntheticKeyboardEvent.js +33 -4
  73. package/lib/SyntheticMouseEvent.js +3 -0
  74. package/lib/SyntheticTouchEvent.js +4 -1
  75. package/lib/SyntheticUIEvent.js +24 -2
  76. package/lib/Transaction.js +0 -32
  77. package/lib/cloneWithProps.js +3 -1
  78. package/lib/createFullPageComponent.js +1 -1
  79. package/lib/dangerousStyleValue.js +11 -5
  80. package/lib/escapeTextForBrowser.js +2 -3
  81. package/lib/flattenChildren.js +9 -7
  82. package/lib/getEventKey.js +35 -5
  83. package/lib/getEventModifierState.js +52 -0
  84. package/lib/getMarkupWrap.js +2 -0
  85. package/lib/getTextContentAccessor.js +1 -1
  86. package/lib/hyphenate.js +3 -0
  87. package/lib/hyphenateStyleName.js +46 -0
  88. package/lib/instantiateReactComponent.js +13 -21
  89. package/lib/invariant.js +17 -19
  90. package/lib/{objMap.js → mapObject.js} +8 -3
  91. package/lib/mergeHelpers.js +11 -0
  92. package/lib/mergeInto.js +3 -2
  93. package/lib/onlyChild.js +3 -3
  94. package/lib/performance.js +33 -0
  95. package/lib/performanceNow.js +5 -14
  96. package/lib/setInnerHTML.js +85 -0
  97. package/lib/shouldUpdateReactComponent.js +12 -29
  98. package/lib/toArray.js +1 -1
  99. package/lib/traverseAllChildren.js +7 -4
  100. package/lib/update.js +57 -45
  101. package/package.json +4 -3
  102. package/lib/ReactEventTopLevelCallback.js +0 -149
  103. package/lib/createObjectFrom.js +0 -61
  104. package/lib/objMapKeyVal.js +0 -47
@@ -18,21 +18,99 @@
18
18
 
19
19
  "use strict";
20
20
 
21
+ var CallbackQueue = require("./CallbackQueue");
22
+ var PooledClass = require("./PooledClass");
23
+ var ReactCurrentOwner = require("./ReactCurrentOwner");
21
24
  var ReactPerf = require("./ReactPerf");
25
+ var Transaction = require("./Transaction");
22
26
 
23
27
  var invariant = require("./invariant");
28
+ var mixInto = require("./mixInto");
29
+ var warning = require("./warning");
24
30
 
25
31
  var dirtyComponents = [];
26
32
 
27
33
  var batchingStrategy = null;
28
34
 
29
- function ensureBatchingStrategy() {
30
- ("production" !== process.env.NODE_ENV ? invariant(batchingStrategy, 'ReactUpdates: must inject a batching strategy') : invariant(batchingStrategy));
35
+ function ensureInjected() {
36
+ ("production" !== process.env.NODE_ENV ? invariant(
37
+ ReactUpdates.ReactReconcileTransaction && batchingStrategy,
38
+ 'ReactUpdates: must inject a reconcile transaction class and batching ' +
39
+ 'strategy'
40
+ ) : invariant(ReactUpdates.ReactReconcileTransaction && batchingStrategy));
31
41
  }
32
42
 
33
- function batchedUpdates(callback, param) {
34
- ensureBatchingStrategy();
35
- batchingStrategy.batchedUpdates(callback, param);
43
+ var NESTED_UPDATES = {
44
+ initialize: function() {
45
+ this.dirtyComponentsLength = dirtyComponents.length;
46
+ },
47
+ close: function() {
48
+ if (this.dirtyComponentsLength !== dirtyComponents.length) {
49
+ // Additional updates were enqueued by componentDidUpdate handlers or
50
+ // similar; before our own UPDATE_QUEUEING wrapper closes, we want to run
51
+ // these new updates so that if A's componentDidUpdate calls setState on
52
+ // B, B will update before the callback A's updater provided when calling
53
+ // setState.
54
+ dirtyComponents.splice(0, this.dirtyComponentsLength);
55
+ flushBatchedUpdates();
56
+ } else {
57
+ dirtyComponents.length = 0;
58
+ }
59
+ }
60
+ };
61
+
62
+ var UPDATE_QUEUEING = {
63
+ initialize: function() {
64
+ this.callbackQueue.reset();
65
+ },
66
+ close: function() {
67
+ this.callbackQueue.notifyAll();
68
+ }
69
+ };
70
+
71
+ var TRANSACTION_WRAPPERS = [NESTED_UPDATES, UPDATE_QUEUEING];
72
+
73
+ function ReactUpdatesFlushTransaction() {
74
+ this.reinitializeTransaction();
75
+ this.dirtyComponentsLength = null;
76
+ this.callbackQueue = CallbackQueue.getPooled(null);
77
+ this.reconcileTransaction =
78
+ ReactUpdates.ReactReconcileTransaction.getPooled();
79
+ }
80
+
81
+ mixInto(ReactUpdatesFlushTransaction, Transaction.Mixin);
82
+ mixInto(ReactUpdatesFlushTransaction, {
83
+ getTransactionWrappers: function() {
84
+ return TRANSACTION_WRAPPERS;
85
+ },
86
+
87
+ destructor: function() {
88
+ this.dirtyComponentsLength = null;
89
+ CallbackQueue.release(this.callbackQueue);
90
+ this.callbackQueue = null;
91
+ ReactUpdates.ReactReconcileTransaction.release(this.reconcileTransaction);
92
+ this.reconcileTransaction = null;
93
+ },
94
+
95
+ perform: function(method, scope, a) {
96
+ // Essentially calls `this.reconcileTransaction.perform(method, scope, a)`
97
+ // with this transaction's wrappers around it.
98
+ return Transaction.Mixin.perform.call(
99
+ this,
100
+ this.reconcileTransaction.perform,
101
+ this.reconcileTransaction,
102
+ method,
103
+ scope,
104
+ a
105
+ );
106
+ }
107
+ });
108
+
109
+ PooledClass.addPoolingTo(ReactUpdatesFlushTransaction);
110
+
111
+ function batchedUpdates(callback, a, b) {
112
+ ensureInjected();
113
+ batchingStrategy.batchedUpdates(callback, a, b);
36
114
  }
37
115
 
38
116
  /**
@@ -46,14 +124,22 @@ function mountDepthComparator(c1, c2) {
46
124
  return c1._mountDepth - c2._mountDepth;
47
125
  }
48
126
 
49
- function runBatchedUpdates() {
127
+ function runBatchedUpdates(transaction) {
128
+ var len = transaction.dirtyComponentsLength;
129
+ ("production" !== process.env.NODE_ENV ? invariant(
130
+ len === dirtyComponents.length,
131
+ 'Expected flush transaction\'s stored dirty-components length (%s) to ' +
132
+ 'match dirty-components array length (%s).',
133
+ len,
134
+ dirtyComponents.length
135
+ ) : invariant(len === dirtyComponents.length));
136
+
50
137
  // Since reconciling a component higher in the owner hierarchy usually (not
51
138
  // always -- see shouldComponentUpdate()) will reconcile children, reconcile
52
139
  // them before their children by sorting the array.
53
-
54
140
  dirtyComponents.sort(mountDepthComparator);
55
141
 
56
- for (var i = 0; i < dirtyComponents.length; i++) {
142
+ for (var i = 0; i < len; i++) {
57
143
  // If a component is unmounted before pending changes apply, ignore them
58
144
  // TODO: Queue unmounts in the same list to avoid this happening at all
59
145
  var component = dirtyComponents[i];
@@ -63,29 +149,32 @@ function runBatchedUpdates() {
63
149
  // stash the callbacks first
64
150
  var callbacks = component._pendingCallbacks;
65
151
  component._pendingCallbacks = null;
66
- component.performUpdateIfNecessary();
152
+ component.performUpdateIfNecessary(transaction.reconcileTransaction);
153
+
67
154
  if (callbacks) {
68
155
  for (var j = 0; j < callbacks.length; j++) {
69
- callbacks[j].call(component);
156
+ transaction.callbackQueue.enqueue(
157
+ callbacks[j],
158
+ component
159
+ );
70
160
  }
71
161
  }
72
162
  }
73
163
  }
74
164
  }
75
165
 
76
- function clearDirtyComponents() {
77
- dirtyComponents.length = 0;
78
- }
79
-
80
166
  var flushBatchedUpdates = ReactPerf.measure(
81
167
  'ReactUpdates',
82
168
  'flushBatchedUpdates',
83
169
  function() {
84
- // Run these in separate functions so the JIT can optimize
85
- try {
86
- runBatchedUpdates();
87
- } finally {
88
- clearDirtyComponents();
170
+ // ReactUpdatesFlushTransaction's wrappers will clear the dirtyComponents
171
+ // array and perform any updates enqueued by mount-ready handlers (i.e.,
172
+ // componentDidUpdate) but we need to check here too in order to catch
173
+ // updates enqueued by setState callbacks.
174
+ while (dirtyComponents.length) {
175
+ var transaction = ReactUpdatesFlushTransaction.getPooled();
176
+ transaction.perform(runBatchedUpdates, null, transaction);
177
+ ReactUpdatesFlushTransaction.release(transaction);
89
178
  }
90
179
  }
91
180
  );
@@ -101,11 +190,23 @@ function enqueueUpdate(component, callback) {
101
190
  '`setState`, `replaceState`, or `forceUpdate` with a callback that ' +
102
191
  'isn\'t callable.'
103
192
  ) : invariant(!callback || typeof callback === "function"));
104
- ensureBatchingStrategy();
193
+ ensureInjected();
194
+
195
+ // Various parts of our code (such as ReactCompositeComponent's
196
+ // _renderValidatedComponent) assume that calls to render aren't nested;
197
+ // verify that that's the case. (This is called by each top-level update
198
+ // function, like setProps, setState, forceUpdate, etc.; creation and
199
+ // destruction of top-level components is guarded in ReactMount.)
200
+ ("production" !== process.env.NODE_ENV ? warning(
201
+ ReactCurrentOwner.current == null,
202
+ 'enqueueUpdate(): Render methods should be a pure function of props ' +
203
+ 'and state; triggering nested component updates from render is not ' +
204
+ 'allowed. If necessary, trigger nested updates in ' +
205
+ 'componentDidUpdate.'
206
+ ) : null);
105
207
 
106
208
  if (!batchingStrategy.isBatchingUpdates) {
107
- component.performUpdateIfNecessary();
108
- callback && callback.call(component);
209
+ batchingStrategy.batchedUpdates(enqueueUpdate, component, callback);
109
210
  return;
110
211
  }
111
212
 
@@ -121,6 +222,14 @@ function enqueueUpdate(component, callback) {
121
222
  }
122
223
 
123
224
  var ReactUpdatesInjection = {
225
+ injectReconcileTransaction: function(ReconcileTransaction) {
226
+ ("production" !== process.env.NODE_ENV ? invariant(
227
+ ReconcileTransaction,
228
+ 'ReactUpdates: must provide a reconcile transaction class'
229
+ ) : invariant(ReconcileTransaction));
230
+ ReactUpdates.ReactReconcileTransaction = ReconcileTransaction;
231
+ },
232
+
124
233
  injectBatchingStrategy: function(_batchingStrategy) {
125
234
  ("production" !== process.env.NODE_ENV ? invariant(
126
235
  _batchingStrategy,
@@ -139,6 +248,14 @@ var ReactUpdatesInjection = {
139
248
  };
140
249
 
141
250
  var ReactUpdates = {
251
+ /**
252
+ * React references `ReactReconcileTransaction` using this property in order
253
+ * to allow dependency injection.
254
+ *
255
+ * @internal
256
+ */
257
+ ReactReconcileTransaction: null,
258
+
142
259
  batchedUpdates: batchedUpdates,
143
260
  enqueueUpdate: enqueueUpdate,
144
261
  flushBatchedUpdates: flushBatchedUpdates,
@@ -27,17 +27,19 @@
27
27
 
28
28
  var LinkedStateMixin = require("./LinkedStateMixin");
29
29
  var React = require("./React");
30
+ var ReactComponentWithPureRenderMixin =
31
+ require("./ReactComponentWithPureRenderMixin");
30
32
  var ReactCSSTransitionGroup = require("./ReactCSSTransitionGroup");
31
33
  var ReactTransitionGroup = require("./ReactTransitionGroup");
32
- var ReactCSSTransitionGroup = require("./ReactCSSTransitionGroup");
33
34
 
34
35
  var cx = require("./cx");
35
36
  var cloneWithProps = require("./cloneWithProps");
36
37
  var update = require("./update");
37
38
 
38
39
  React.addons = {
39
- LinkedStateMixin: LinkedStateMixin,
40
40
  CSSTransitionGroup: ReactCSSTransitionGroup,
41
+ LinkedStateMixin: LinkedStateMixin,
42
+ PureRenderMixin: ReactComponentWithPureRenderMixin,
41
43
  TransitionGroup: ReactTransitionGroup,
42
44
 
43
45
  classSet: cx,
@@ -46,6 +48,7 @@ React.addons = {
46
48
  };
47
49
 
48
50
  if ("production" !== process.env.NODE_ENV) {
51
+ React.addons.Perf = require("./ReactDefaultPerf");
49
52
  React.addons.TestUtils = require("./ReactTestUtils");
50
53
  }
51
54
 
@@ -0,0 +1,97 @@
1
+ /**
2
+ * Copyright 2013-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 SVGDOMPropertyConfig
17
+ */
18
+
19
+ /*jslint bitwise: true*/
20
+
21
+ "use strict";
22
+
23
+ var DOMProperty = require("./DOMProperty");
24
+
25
+ var MUST_USE_ATTRIBUTE = DOMProperty.injection.MUST_USE_ATTRIBUTE;
26
+
27
+ var SVGDOMPropertyConfig = {
28
+ Properties: {
29
+ cx: MUST_USE_ATTRIBUTE,
30
+ cy: MUST_USE_ATTRIBUTE,
31
+ d: MUST_USE_ATTRIBUTE,
32
+ dx: MUST_USE_ATTRIBUTE,
33
+ dy: MUST_USE_ATTRIBUTE,
34
+ fill: MUST_USE_ATTRIBUTE,
35
+ fillOpacity: MUST_USE_ATTRIBUTE,
36
+ fontFamily: MUST_USE_ATTRIBUTE,
37
+ fontSize: MUST_USE_ATTRIBUTE,
38
+ fx: MUST_USE_ATTRIBUTE,
39
+ fy: MUST_USE_ATTRIBUTE,
40
+ gradientTransform: MUST_USE_ATTRIBUTE,
41
+ gradientUnits: MUST_USE_ATTRIBUTE,
42
+ markerEnd: MUST_USE_ATTRIBUTE,
43
+ markerMid: MUST_USE_ATTRIBUTE,
44
+ markerStart: MUST_USE_ATTRIBUTE,
45
+ offset: MUST_USE_ATTRIBUTE,
46
+ opacity: MUST_USE_ATTRIBUTE,
47
+ patternContentUnits: MUST_USE_ATTRIBUTE,
48
+ patternUnits: MUST_USE_ATTRIBUTE,
49
+ points: MUST_USE_ATTRIBUTE,
50
+ preserveAspectRatio: MUST_USE_ATTRIBUTE,
51
+ r: MUST_USE_ATTRIBUTE,
52
+ rx: MUST_USE_ATTRIBUTE,
53
+ ry: MUST_USE_ATTRIBUTE,
54
+ spreadMethod: MUST_USE_ATTRIBUTE,
55
+ stopColor: MUST_USE_ATTRIBUTE,
56
+ stopOpacity: MUST_USE_ATTRIBUTE,
57
+ stroke: MUST_USE_ATTRIBUTE,
58
+ strokeDasharray: MUST_USE_ATTRIBUTE,
59
+ strokeLinecap: MUST_USE_ATTRIBUTE,
60
+ strokeOpacity: MUST_USE_ATTRIBUTE,
61
+ strokeWidth: MUST_USE_ATTRIBUTE,
62
+ textAnchor: MUST_USE_ATTRIBUTE,
63
+ transform: MUST_USE_ATTRIBUTE,
64
+ version: MUST_USE_ATTRIBUTE,
65
+ viewBox: MUST_USE_ATTRIBUTE,
66
+ x1: MUST_USE_ATTRIBUTE,
67
+ x2: MUST_USE_ATTRIBUTE,
68
+ x: MUST_USE_ATTRIBUTE,
69
+ y1: MUST_USE_ATTRIBUTE,
70
+ y2: MUST_USE_ATTRIBUTE,
71
+ y: MUST_USE_ATTRIBUTE
72
+ },
73
+ DOMAttributeNames: {
74
+ fillOpacity: 'fill-opacity',
75
+ fontFamily: 'font-family',
76
+ fontSize: 'font-size',
77
+ gradientTransform: 'gradientTransform',
78
+ gradientUnits: 'gradientUnits',
79
+ markerEnd: 'marker-end',
80
+ markerMid: 'marker-mid',
81
+ markerStart: 'marker-start',
82
+ patternContentUnits: 'patternContentUnits',
83
+ patternUnits: 'patternUnits',
84
+ preserveAspectRatio: 'preserveAspectRatio',
85
+ spreadMethod: 'spreadMethod',
86
+ stopColor: 'stop-color',
87
+ stopOpacity: 'stop-opacity',
88
+ strokeDasharray: 'stroke-dasharray',
89
+ strokeLinecap: 'stroke-linecap',
90
+ strokeOpacity: 'stroke-opacity',
91
+ strokeWidth: 'stroke-width',
92
+ textAnchor: 'text-anchor',
93
+ viewBox: 'viewBox'
94
+ }
95
+ };
96
+
97
+ module.exports = SVGDOMPropertyConfig;
@@ -341,8 +341,14 @@ var SimpleEventPlugin = {
341
341
  // @see http://www.w3.org/TR/html5/index.html#events-0
342
342
  EventConstructor = SyntheticEvent;
343
343
  break;
344
- case topLevelTypes.topKeyDown:
345
344
  case topLevelTypes.topKeyPress:
345
+ // FireFox creates a keypress event for function keys too. This removes
346
+ // the unwanted keypress events.
347
+ if (nativeEvent.charCode === 0) {
348
+ return null;
349
+ }
350
+ /* falls through */
351
+ case topLevelTypes.topKeyDown:
346
352
  case topLevelTypes.topKeyUp:
347
353
  EventConstructor = SyntheticKeyboardEvent;
348
354
  break;
@@ -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 SyntheticInputEvent
17
+ * @typechecks static-only
18
+ */
19
+
20
+ "use strict";
21
+
22
+ var SyntheticEvent = require("./SyntheticEvent");
23
+
24
+ /**
25
+ * @interface Event
26
+ * @see http://www.w3.org/TR/2013/WD-DOM-Level-3-Events-20131105
27
+ * /#events-inputevents
28
+ */
29
+ var InputEventInterface = {
30
+ data: null
31
+ };
32
+
33
+ /**
34
+ * @param {object} dispatchConfig Configuration used to dispatch this event.
35
+ * @param {string} dispatchMarker Marker identifying the event target.
36
+ * @param {object} nativeEvent Native browser event.
37
+ * @extends {SyntheticUIEvent}
38
+ */
39
+ function SyntheticInputEvent(
40
+ dispatchConfig,
41
+ dispatchMarker,
42
+ nativeEvent) {
43
+ SyntheticEvent.call(this, dispatchConfig, dispatchMarker, nativeEvent);
44
+ }
45
+
46
+ SyntheticEvent.augmentClass(
47
+ SyntheticInputEvent,
48
+ InputEventInterface
49
+ );
50
+
51
+ module.exports = SyntheticInputEvent;
52
+
@@ -22,6 +22,7 @@
22
22
  var SyntheticUIEvent = require("./SyntheticUIEvent");
23
23
 
24
24
  var getEventKey = require("./getEventKey");
25
+ var getEventModifierState = require("./getEventModifierState");
25
26
 
26
27
  /**
27
28
  * @interface KeyboardEvent
@@ -36,11 +37,39 @@ var KeyboardEventInterface = {
36
37
  metaKey: null,
37
38
  repeat: null,
38
39
  locale: null,
40
+ getModifierState: getEventModifierState,
39
41
  // Legacy Interface
40
- 'char': null,
41
- charCode: null,
42
- keyCode: null,
43
- which: null
42
+ charCode: function(event) {
43
+ // `charCode` is the result of a KeyPress event and represents the value of
44
+ // the actual printable character.
45
+
46
+ // KeyPress is deprecated but its replacement is not yet final and not
47
+ // implemented in any major browser.
48
+ if (event.type === 'keypress') {
49
+ // IE8 does not implement "charCode", but "keyCode" has the correct value.
50
+ return 'charCode' in event ? event.charCode : event.keyCode;
51
+ }
52
+ return 0;
53
+ },
54
+ keyCode: function(event) {
55
+ // `keyCode` is the result of a KeyDown/Up event and represents the value of
56
+ // physical keyboard key.
57
+
58
+ // The actual meaning of the value depends on the users' keyboard layout
59
+ // which cannot be detected. Assuming that it is a US keyboard layout
60
+ // provides a surprisingly accurate mapping for US and European users.
61
+ // Due to this, it is left to the user to implement at this time.
62
+ if (event.type === 'keydown' || event.type === 'keyup') {
63
+ return event.keyCode;
64
+ }
65
+ return 0;
66
+ },
67
+ which: function(event) {
68
+ // `which` is an alias for either `keyCode` or `charCode` depending on the
69
+ // type of the event. There is no need to determine the type of the event
70
+ // as `keyCode` and `charCode` are either aliased or default to zero.
71
+ return event.keyCode || event.charCode;
72
+ }
44
73
  };
45
74
 
46
75
  /**