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.
- package/README.md +3 -0
- package/dist/JSXTransformer.js +13445 -0
- package/dist/react-with-addons.js +20226 -0
- package/dist/react-with-addons.min.js +22 -0
- package/dist/react.js +18434 -0
- package/dist/react.min.js +21 -0
- package/lib/AutoFocusMixin.js +4 -2
- package/lib/BeforeInputEventPlugin.js +222 -0
- package/lib/CSSCore.js +1 -1
- package/lib/CSSProperty.js +1 -1
- package/lib/CSSPropertyOperations.js +4 -4
- package/lib/{ReactMountReady.js → CallbackQueue.js} +33 -25
- package/lib/ChangeEventPlugin.js +2 -2
- package/lib/ClientReactRootIndex.js +1 -1
- package/lib/CompositionEventPlugin.js +6 -2
- package/lib/DOMChildrenOperations.js +34 -21
- package/lib/DOMProperty.js +52 -22
- package/lib/DOMPropertyOperations.js +29 -17
- package/lib/Danger.js +1 -1
- package/lib/DefaultEventPluginOrder.js +2 -1
- package/lib/EnterLeaveEventPlugin.js +1 -1
- package/lib/EventConstants.js +2 -1
- package/lib/EventListener.js +5 -2
- package/lib/EventPluginHub.js +5 -6
- package/lib/EventPluginRegistry.js +27 -4
- package/lib/EventPluginUtils.js +12 -2
- package/lib/EventPropagators.js +1 -1
- package/lib/ExecutionEnvironment.js +9 -3
- package/lib/{DefaultDOMPropertyConfig.js → HTMLDOMPropertyConfig.js} +47 -58
- package/lib/LinkedStateMixin.js +1 -1
- package/lib/LinkedValueUtils.js +27 -29
- package/lib/LocalEventTrapMixin.js +52 -0
- package/lib/MobileSafariClickEventPlugin.js +1 -1
- package/lib/PooledClass.js +1 -1
- package/lib/React.js +39 -4
- package/lib/ReactBrowserComponentMixin.js +46 -0
- package/lib/{ReactEventEmitter.js → ReactBrowserEventEmitter.js} +118 -95
- package/lib/ReactCSSTransitionGroup.js +13 -11
- package/lib/ReactCSSTransitionGroupChild.js +3 -6
- package/lib/ReactChildren.js +35 -14
- package/lib/ReactComponent.js +120 -224
- package/lib/ReactComponentBrowserEnvironment.js +4 -37
- package/lib/ReactComponentWithPureRenderMixin.js +54 -0
- package/lib/ReactCompositeComponent.js +250 -288
- package/lib/ReactContext.js +1 -1
- package/lib/ReactCurrentOwner.js +1 -1
- package/lib/ReactDOM.js +26 -24
- package/lib/ReactDOMButton.js +3 -2
- package/lib/ReactDOMComponent.js +43 -24
- package/lib/ReactDOMForm.js +8 -13
- package/lib/ReactDOMIDOperations.js +3 -32
- package/lib/ReactDOMImg.js +8 -14
- package/lib/ReactDOMInput.js +3 -2
- package/lib/ReactDOMOption.js +12 -8
- package/lib/ReactDOMSelect.js +19 -17
- package/lib/ReactDOMSelection.js +36 -11
- package/lib/ReactDOMTextarea.js +10 -8
- package/lib/ReactDefaultBatchingStrategy.js +4 -4
- package/lib/ReactDefaultInjection.js +28 -15
- package/lib/ReactDefaultPerf.js +29 -12
- package/lib/ReactDefaultPerfAnalysis.js +5 -1
- package/lib/ReactDescriptor.js +243 -0
- package/lib/ReactDescriptorValidator.js +283 -0
- package/lib/ReactEmptyComponent.js +78 -0
- package/lib/ReactErrorUtils.js +1 -1
- package/lib/ReactEventEmitterMixin.js +2 -4
- package/lib/ReactEventListener.js +189 -0
- package/lib/ReactInjection.js +9 -3
- package/lib/ReactInputSelection.js +3 -2
- package/lib/ReactInstanceHandles.js +1 -1
- package/lib/ReactLink.js +25 -1
- package/lib/ReactMarkupChecksum.js +1 -1
- package/lib/ReactMount.js +62 -22
- package/lib/ReactMultiChild.js +19 -14
- package/lib/ReactMultiChildUpdateTypes.js +1 -1
- package/lib/ReactOwner.js +7 -2
- package/lib/ReactPerf.js +1 -1
- package/lib/ReactPropTransferer.js +45 -30
- package/lib/ReactPropTypeLocationNames.js +1 -1
- package/lib/ReactPropTypeLocations.js +1 -1
- package/lib/ReactPropTypes.js +222 -238
- package/lib/ReactPutListenerQueue.js +3 -3
- package/lib/ReactReconcileTransaction.js +22 -21
- package/lib/ReactRootIndex.js +1 -1
- package/lib/ReactServerRendering.js +42 -12
- package/lib/ReactServerRenderingTransaction.js +115 -0
- package/lib/ReactStateSetters.js +1 -1
- package/lib/ReactTestUtils.js +412 -0
- package/lib/ReactTextComponent.js +22 -14
- package/lib/ReactTransitionChildMapping.js +3 -3
- package/lib/ReactTransitionEvents.js +20 -1
- package/lib/ReactTransitionGroup.js +10 -7
- package/lib/ReactUpdates.js +140 -23
- package/lib/ReactWithAddons.js +13 -3
- package/lib/SVGDOMPropertyConfig.js +97 -0
- package/lib/SelectEventPlugin.js +1 -1
- package/lib/ServerReactRootIndex.js +1 -1
- package/lib/SimpleEventPlugin.js +8 -2
- package/lib/SyntheticClipboardEvent.js +1 -1
- package/lib/SyntheticCompositionEvent.js +1 -1
- package/lib/SyntheticDragEvent.js +1 -1
- package/lib/SyntheticEvent.js +1 -1
- package/lib/SyntheticFocusEvent.js +1 -1
- package/lib/SyntheticInputEvent.js +52 -0
- package/lib/SyntheticKeyboardEvent.js +34 -5
- package/lib/SyntheticMouseEvent.js +4 -1
- package/lib/SyntheticTouchEvent.js +5 -2
- package/lib/SyntheticUIEvent.js +25 -3
- package/lib/SyntheticWheelEvent.js +1 -1
- package/lib/Transaction.js +1 -33
- package/lib/ViewportMetrics.js +1 -1
- package/lib/accumulate.js +1 -1
- package/lib/adler32.js +1 -1
- package/lib/cloneWithProps.js +11 -9
- package/lib/containsNode.js +1 -1
- package/lib/copyProperties.js +1 -1
- package/lib/createArrayFrom.js +1 -1
- package/lib/createFullPageComponent.js +2 -2
- package/lib/createNodesFromMarkup.js +1 -1
- package/lib/cx.js +1 -1
- package/lib/dangerousStyleValue.js +12 -6
- package/lib/emptyFunction.js +1 -1
- package/lib/{ReactComponentEnvironment.js → emptyObject.js} +7 -6
- package/lib/escapeTextForBrowser.js +3 -4
- package/lib/flattenChildren.js +10 -8
- package/lib/focusNode.js +33 -0
- package/lib/forEachAccumulated.js +1 -1
- package/lib/getActiveElement.js +1 -1
- package/lib/getEventKey.js +36 -6
- package/lib/getEventModifierState.js +52 -0
- package/lib/getEventTarget.js +1 -1
- package/lib/getMarkupWrap.js +3 -1
- package/lib/getNodeForCharacterOffset.js +1 -1
- package/lib/getReactRootElementInContainer.js +1 -1
- package/lib/getTextContentAccessor.js +2 -2
- package/lib/getUnboundedScrollPosition.js +1 -1
- package/lib/hyphenate.js +4 -1
- package/lib/hyphenateStyleName.js +46 -0
- package/lib/instantiateReactComponent.js +62 -0
- package/lib/invariant.js +21 -23
- package/lib/isEventSupported.js +1 -1
- package/lib/isNode.js +2 -2
- package/lib/isTextInputElement.js +1 -1
- package/lib/isTextNode.js +1 -1
- package/lib/joinClasses.js +1 -1
- package/lib/keyMirror.js +1 -1
- package/lib/keyOf.js +1 -1
- package/lib/{objMap.js → mapObject.js} +9 -4
- package/lib/memoizeStringOnly.js +1 -1
- package/lib/merge.js +1 -1
- package/lib/mergeHelpers.js +12 -1
- package/lib/mergeInto.js +4 -3
- package/lib/mixInto.js +1 -1
- package/lib/monitorCodeUse.js +37 -0
- package/lib/onlyChild.js +4 -4
- package/lib/performance.js +33 -0
- package/lib/performanceNow.js +6 -15
- package/lib/setInnerHTML.js +77 -0
- package/lib/shallowEqual.js +1 -1
- package/lib/shouldUpdateReactComponent.js +15 -29
- package/lib/toArray.js +1 -1
- package/lib/traverseAllChildren.js +10 -6
- package/lib/update.js +171 -0
- package/lib/warning.js +19 -11
- package/package.json +5 -3
- package/lib/ReactEventTopLevelCallback.js +0 -109
- package/lib/createObjectFrom.js +0 -61
- package/lib/objMapKeyVal.js +0 -47
package/lib/ViewportMetrics.js
CHANGED
package/lib/accumulate.js
CHANGED
package/lib/adler32.js
CHANGED
package/lib/cloneWithProps.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.
|
|
@@ -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
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
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
|
-
|
|
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;
|
package/lib/containsNode.js
CHANGED
package/lib/copyProperties.js
CHANGED
package/lib/createArrayFrom.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.
|
|
@@ -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.
|
|
41
|
+
componentClass.type.displayName || ''
|
|
42
42
|
),
|
|
43
43
|
|
|
44
44
|
componentWillUnmount: function() {
|
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.
|
|
@@ -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 `
|
|
26
|
-
*
|
|
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}
|
|
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(
|
|
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 ||
|
|
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
|
|
package/lib/emptyFunction.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.
|
|
@@ -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
|
|
16
|
+
* @providesModule emptyObject
|
|
17
17
|
*/
|
|
18
18
|
|
|
19
19
|
"use strict";
|
|
20
20
|
|
|
21
|
-
var
|
|
22
|
-
require("./ReactComponentBrowserEnvironment");
|
|
21
|
+
var emptyObject = {};
|
|
23
22
|
|
|
24
|
-
|
|
23
|
+
if ("production" !== process.env.NODE_ENV) {
|
|
24
|
+
Object.freeze(emptyObject);
|
|
25
|
+
}
|
|
25
26
|
|
|
26
|
-
module.exports =
|
|
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
|
"<": "<",
|
|
26
26
|
"\"": """,
|
|
27
|
-
"'": "'"
|
|
28
|
-
"/": "/"
|
|
27
|
+
"'": "'"
|
|
29
28
|
};
|
|
30
29
|
|
|
31
|
-
var ESCAPE_REGEX = /[&><"'
|
|
30
|
+
var ESCAPE_REGEX = /[&><"']/g;
|
|
32
31
|
|
|
33
32
|
function escaper(match) {
|
|
34
33
|
return ESCAPE_LOOKUP[match];
|
package/lib/flattenChildren.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.
|
|
@@ -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
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
'
|
|
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
|
-
) :
|
|
38
|
-
if (child != null) {
|
|
39
|
+
) : null);
|
|
40
|
+
if (keyUnique && child != null) {
|
|
39
41
|
result[name] = child;
|
|
40
42
|
}
|
|
41
43
|
}
|
package/lib/focusNode.js
ADDED
|
@@ -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;
|
package/lib/getActiveElement.js
CHANGED
package/lib/getEventKey.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.
|
|
@@ -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
|
|
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
|
|
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
|
-
|
|
81
|
-
|
|
82
|
-
|
|
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;
|
package/lib/getEventTarget.js
CHANGED