react-test-renderer 15.5.0 → 15.5.4
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/lib/ReactShallowRenderer.js +6 -0
- package/lib/shallow/ARIADOMPropertyConfig.js +73 -0
- package/lib/shallow/AutoFocusUtils.js +23 -0
- package/lib/shallow/BeforeInputEventPlugin.js +384 -0
- package/lib/shallow/CSSProperty.js +147 -0
- package/lib/shallow/CSSPropertyOperations.js +208 -0
- package/lib/shallow/CallbackQueue.js +118 -0
- package/lib/shallow/ChangeEventPlugin.js +345 -0
- package/lib/shallow/DOMChildrenOperations.js +224 -0
- package/lib/shallow/DOMLazyTree.js +117 -0
- package/lib/shallow/DOMNamespaces.js +19 -0
- package/lib/shallow/DOMProperty.js +209 -0
- package/lib/shallow/DOMPropertyOperations.js +236 -0
- package/lib/shallow/Danger.js +47 -0
- package/lib/shallow/DefaultEventPluginOrder.js +25 -0
- package/lib/shallow/EnterLeaveEventPlugin.js +99 -0
- package/lib/shallow/EventConstants.js +91 -0
- package/lib/shallow/EventPluginHub.js +277 -0
- package/lib/shallow/EventPluginRegistry.js +254 -0
- package/lib/shallow/EventPluginUtils.js +225 -0
- package/lib/shallow/EventPropagators.js +133 -0
- package/lib/shallow/FallbackCompositionState.js +94 -0
- package/lib/shallow/HTMLDOMPropertyConfig.js +235 -0
- package/lib/shallow/KeyEscapeUtils.js +58 -0
- package/lib/shallow/LinkedValueUtils.js +137 -0
- package/lib/shallow/PluginModuleType.js +12 -0
- package/lib/shallow/PooledClass.js +111 -0
- package/lib/shallow/ReactBrowserEventEmitter.js +327 -0
- package/lib/shallow/ReactChildFiber.js +243 -0
- package/lib/shallow/ReactChildReconciler.js +153 -0
- package/lib/shallow/ReactComponentBrowserEnvironment.js +29 -0
- package/lib/shallow/ReactComponentEnvironment.js +45 -0
- package/lib/shallow/ReactCompositeComponent.js +901 -0
- package/lib/shallow/ReactCoroutine.js +80 -0
- package/lib/shallow/ReactDOM.js +110 -0
- package/lib/shallow/ReactDOMComponent.js +1000 -0
- package/lib/shallow/ReactDOMComponentFlags.js +17 -0
- package/lib/shallow/ReactDOMComponentTree.js +194 -0
- package/lib/shallow/ReactDOMContainerInfo.js +32 -0
- package/lib/shallow/ReactDOMEmptyComponent.js +59 -0
- package/lib/shallow/ReactDOMFeatureFlags.js +18 -0
- package/lib/shallow/ReactDOMFiber.js +97 -0
- package/lib/shallow/ReactDOMIDOperations.js +33 -0
- package/lib/shallow/ReactDOMInput.js +284 -0
- package/lib/shallow/ReactDOMInvalidARIAHook.js +92 -0
- package/lib/shallow/ReactDOMNullInputValuePropHook.js +42 -0
- package/lib/shallow/ReactDOMOption.js +122 -0
- package/lib/shallow/ReactDOMSelect.js +199 -0
- package/lib/shallow/ReactDOMSelection.js +211 -0
- package/lib/shallow/ReactDOMServer.js +25 -0
- package/lib/shallow/ReactDOMTextComponent.js +163 -0
- package/lib/shallow/ReactDOMTextarea.js +159 -0
- package/lib/shallow/ReactDOMTreeTraversal.js +135 -0
- package/lib/shallow/ReactDOMUnknownPropertyHook.js +111 -0
- package/lib/shallow/ReactDebugTool.js +358 -0
- package/lib/shallow/ReactDefaultBatchingStrategy.js +67 -0
- package/lib/shallow/ReactDefaultInjection.js +85 -0
- package/lib/shallow/ReactElementSymbol.js +19 -0
- package/lib/shallow/ReactEmptyComponent.js +29 -0
- package/lib/shallow/ReactErrorUtils.js +75 -0
- package/lib/shallow/ReactEventEmitterMixin.js +32 -0
- package/lib/shallow/ReactEventListener.js +154 -0
- package/lib/shallow/ReactFeatureFlags.js +21 -0
- package/lib/shallow/ReactFiber.js +190 -0
- package/lib/shallow/ReactFiberBeginWork.js +380 -0
- package/lib/shallow/ReactFiberCommitWork.js +78 -0
- package/lib/shallow/ReactFiberCompleteWork.js +208 -0
- package/lib/shallow/ReactFiberReconciler.js +64 -0
- package/lib/shallow/ReactFiberRoot.js +29 -0
- package/lib/shallow/ReactFiberScheduler.js +331 -0
- package/lib/shallow/ReactFiberUpdateQueue.js +77 -0
- package/lib/shallow/ReactHostComponent.js +67 -0
- package/lib/shallow/ReactHostOperationHistoryHook.js +33 -0
- package/lib/shallow/ReactInjection.js +33 -0
- package/lib/shallow/ReactInputSelection.js +123 -0
- package/lib/shallow/ReactInstanceMap.js +47 -0
- package/lib/shallow/ReactInstanceType.js +12 -0
- package/lib/shallow/ReactInstrumentation.js +23 -0
- package/lib/shallow/ReactInvalidSetStateWarningHook.js +36 -0
- package/lib/shallow/ReactMarkupChecksum.js +49 -0
- package/lib/shallow/ReactMount.js +537 -0
- package/lib/shallow/ReactMultiChild.js +449 -0
- package/lib/shallow/ReactMultiChildUpdateTypes.js +18 -0
- package/lib/shallow/ReactNodeTypes.js +39 -0
- package/lib/shallow/ReactOwner.js +93 -0
- package/lib/shallow/ReactPerf.js +500 -0
- package/lib/shallow/ReactPriorityLevel.js +20 -0
- package/lib/shallow/ReactPropTypeLocationNames.js +24 -0
- package/lib/shallow/ReactPropTypeLocations.js +12 -0
- package/lib/shallow/ReactPropTypesSecret.js +16 -0
- package/lib/shallow/ReactReconcileTransaction.js +177 -0
- package/lib/shallow/ReactReconciler.js +167 -0
- package/lib/shallow/ReactRef.js +88 -0
- package/lib/shallow/ReactReifiedYield.js +30 -0
- package/lib/shallow/ReactServerBatchingStrategy.js +21 -0
- package/lib/shallow/ReactServerRendering.js +89 -0
- package/lib/shallow/ReactServerRenderingTransaction.js +89 -0
- package/lib/shallow/ReactServerUpdateQueue.js +138 -0
- package/lib/shallow/ReactShallowRenderer.js +150 -0
- package/lib/shallow/ReactSimpleEmptyComponent.js +36 -0
- package/lib/shallow/ReactSyntheticEventType.js +14 -0
- package/lib/shallow/ReactTestEmptyComponent.js +36 -0
- package/lib/shallow/ReactTestMount.js +131 -0
- package/lib/shallow/ReactTestReconcileTransaction.js +128 -0
- package/lib/shallow/ReactTestRenderer.js +139 -0
- package/lib/shallow/ReactTestTextComponent.js +40 -0
- package/lib/shallow/ReactTypeOfWork.js +23 -0
- package/lib/shallow/ReactTypes.js +12 -0
- package/lib/shallow/ReactUpdateQueue.js +235 -0
- package/lib/shallow/ReactUpdates.js +250 -0
- package/lib/shallow/ReactVersion.js +13 -0
- package/lib/shallow/ResponderEventPlugin.js +507 -0
- package/lib/shallow/ResponderSyntheticEvent.js +38 -0
- package/lib/shallow/ResponderTouchHistoryStore.js +183 -0
- package/lib/shallow/SVGDOMPropertyConfig.js +301 -0
- package/lib/shallow/SelectEventPlugin.js +190 -0
- package/lib/shallow/SimpleEventPlugin.js +227 -0
- package/lib/shallow/SyntheticAnimationEvent.js +38 -0
- package/lib/shallow/SyntheticClipboardEvent.js +37 -0
- package/lib/shallow/SyntheticCompositionEvent.js +35 -0
- package/lib/shallow/SyntheticDragEvent.js +35 -0
- package/lib/shallow/SyntheticEvent.js +267 -0
- package/lib/shallow/SyntheticFocusEvent.js +35 -0
- package/lib/shallow/SyntheticInputEvent.js +36 -0
- package/lib/shallow/SyntheticKeyboardEvent.js +83 -0
- package/lib/shallow/SyntheticMouseEvent.js +71 -0
- package/lib/shallow/SyntheticTouchEvent.js +44 -0
- package/lib/shallow/SyntheticTransitionEvent.js +38 -0
- package/lib/shallow/SyntheticUIEvent.js +58 -0
- package/lib/shallow/SyntheticWheelEvent.js +53 -0
- package/lib/shallow/TapEventPlugin.js +115 -0
- package/lib/shallow/TouchHistoryMath.js +98 -0
- package/lib/shallow/Transaction.js +224 -0
- package/lib/shallow/ViewportMetrics.js +26 -0
- package/lib/shallow/accumulate.js +45 -0
- package/lib/shallow/accumulateInto.js +57 -0
- package/lib/shallow/adler32.js +43 -0
- package/lib/shallow/canDefineProperty.js +25 -0
- package/lib/shallow/checkReactTypeSpec.js +86 -0
- package/lib/shallow/createMicrosoftUnsafeLocalFunction.js +31 -0
- package/lib/shallow/dangerousStyleValue.js +78 -0
- package/lib/shallow/deprecated.js +56 -0
- package/lib/shallow/escapeTextContentForBrowser.js +122 -0
- package/lib/shallow/findDOMNode.js +59 -0
- package/lib/shallow/flattenChildren.js +75 -0
- package/lib/shallow/forEachAccumulated.js +30 -0
- package/lib/shallow/getEventCharCode.js +49 -0
- package/lib/shallow/getEventKey.js +101 -0
- package/lib/shallow/getEventModifierState.js +42 -0
- package/lib/shallow/getEventTarget.js +34 -0
- package/lib/shallow/getHostComponentFromComposite.js +29 -0
- package/lib/shallow/getIteratorFn.js +40 -0
- package/lib/shallow/getNodeForCharacterOffset.js +73 -0
- package/lib/shallow/getTextContentAccessor.js +32 -0
- package/lib/shallow/getVendorPrefixedEventName.js +100 -0
- package/lib/shallow/instantiateReactComponent.js +128 -0
- package/lib/shallow/isEventSupported.js +59 -0
- package/lib/shallow/isTextInputElement.js +50 -0
- package/lib/shallow/quoteAttributeValueForBrowser.js +25 -0
- package/lib/shallow/reactProdInvariant.js +38 -0
- package/lib/shallow/renderSubtreeIntoContainer.js +15 -0
- package/lib/shallow/setInnerHTML.js +97 -0
- package/lib/shallow/setTextContent.js +51 -0
- package/lib/shallow/shouldUpdateReactComponent.js +41 -0
- package/lib/shallow/traverseAllChildren.js +175 -0
- package/lib/shallow/validateDOMNesting.js +376 -0
- package/package.json +1 -1
- package/shallow.js +1 -1
|
@@ -0,0 +1,122 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright 2016-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
|
+
* Based on the escape-html library, which is used under the MIT License below:
|
|
10
|
+
*
|
|
11
|
+
* Copyright (c) 2012-2013 TJ Holowaychuk
|
|
12
|
+
* Copyright (c) 2015 Andreas Lubbe
|
|
13
|
+
* Copyright (c) 2015 Tiancheng "Timothy" Gu
|
|
14
|
+
*
|
|
15
|
+
* Permission is hereby granted, free of charge, to any person obtaining
|
|
16
|
+
* a copy of this software and associated documentation files (the
|
|
17
|
+
* 'Software'), to deal in the Software without restriction, including
|
|
18
|
+
* without limitation the rights to use, copy, modify, merge, publish,
|
|
19
|
+
* distribute, sublicense, and/or sell copies of the Software, and to
|
|
20
|
+
* permit persons to whom the Software is furnished to do so, subject to
|
|
21
|
+
* the following conditions:
|
|
22
|
+
*
|
|
23
|
+
* The above copyright notice and this permission notice shall be
|
|
24
|
+
* included in all copies or substantial portions of the Software.
|
|
25
|
+
*
|
|
26
|
+
* THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
|
|
27
|
+
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
|
28
|
+
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
|
|
29
|
+
* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
|
|
30
|
+
* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
|
|
31
|
+
* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
|
|
32
|
+
* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
|
33
|
+
*
|
|
34
|
+
*/
|
|
35
|
+
|
|
36
|
+
'use strict';
|
|
37
|
+
|
|
38
|
+
// code copied and modified from escape-html
|
|
39
|
+
/**
|
|
40
|
+
* Module variables.
|
|
41
|
+
* @private
|
|
42
|
+
*/
|
|
43
|
+
|
|
44
|
+
var matchHtmlRegExp = /["'&<>]/;
|
|
45
|
+
|
|
46
|
+
/**
|
|
47
|
+
* Escape special characters in the given string of html.
|
|
48
|
+
*
|
|
49
|
+
* @param {string} string The string to escape for inserting into HTML
|
|
50
|
+
* @return {string}
|
|
51
|
+
* @public
|
|
52
|
+
*/
|
|
53
|
+
|
|
54
|
+
function escapeHtml(string) {
|
|
55
|
+
var str = '' + string;
|
|
56
|
+
var match = matchHtmlRegExp.exec(str);
|
|
57
|
+
|
|
58
|
+
if (!match) {
|
|
59
|
+
return str;
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
var escape;
|
|
63
|
+
var html = '';
|
|
64
|
+
var index = 0;
|
|
65
|
+
var lastIndex = 0;
|
|
66
|
+
|
|
67
|
+
for (index = match.index; index < str.length; index++) {
|
|
68
|
+
switch (str.charCodeAt(index)) {
|
|
69
|
+
case 34:
|
|
70
|
+
// "
|
|
71
|
+
escape = '"';
|
|
72
|
+
break;
|
|
73
|
+
case 38:
|
|
74
|
+
// &
|
|
75
|
+
escape = '&';
|
|
76
|
+
break;
|
|
77
|
+
case 39:
|
|
78
|
+
// '
|
|
79
|
+
escape = '''; // modified from escape-html; used to be '''
|
|
80
|
+
break;
|
|
81
|
+
case 60:
|
|
82
|
+
// <
|
|
83
|
+
escape = '<';
|
|
84
|
+
break;
|
|
85
|
+
case 62:
|
|
86
|
+
// >
|
|
87
|
+
escape = '>';
|
|
88
|
+
break;
|
|
89
|
+
default:
|
|
90
|
+
continue;
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
if (lastIndex !== index) {
|
|
94
|
+
html += str.substring(lastIndex, index);
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
lastIndex = index + 1;
|
|
98
|
+
html += escape;
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
return lastIndex !== index ? html + str.substring(lastIndex, index) : html;
|
|
102
|
+
}
|
|
103
|
+
// end code copied and modified from escape-html
|
|
104
|
+
|
|
105
|
+
|
|
106
|
+
/**
|
|
107
|
+
* Escapes text to prevent scripting attacks.
|
|
108
|
+
*
|
|
109
|
+
* @param {*} text Text value to escape.
|
|
110
|
+
* @return {string} An escaped string.
|
|
111
|
+
*/
|
|
112
|
+
function escapeTextContentForBrowser(text) {
|
|
113
|
+
if (typeof text === 'boolean' || typeof text === 'number') {
|
|
114
|
+
// this shortcircuit helps perf for types that we know will never have
|
|
115
|
+
// special characters, especially given that this function is used often
|
|
116
|
+
// for numeric dom ids.
|
|
117
|
+
return '' + text;
|
|
118
|
+
}
|
|
119
|
+
return escapeHtml(text);
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
module.exports = escapeTextContentForBrowser;
|
|
@@ -0,0 +1,59 @@
|
|
|
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
|
+
*/
|
|
10
|
+
|
|
11
|
+
'use strict';
|
|
12
|
+
|
|
13
|
+
var _prodInvariant = require('./reactProdInvariant');
|
|
14
|
+
|
|
15
|
+
var ReactCurrentOwner = require('react/lib/ReactCurrentOwner');
|
|
16
|
+
var ReactDOMComponentTree = require('./ReactDOMComponentTree');
|
|
17
|
+
var ReactInstanceMap = require('./ReactInstanceMap');
|
|
18
|
+
|
|
19
|
+
var getHostComponentFromComposite = require('./getHostComponentFromComposite');
|
|
20
|
+
var invariant = require('fbjs/lib/invariant');
|
|
21
|
+
var warning = require('fbjs/lib/warning');
|
|
22
|
+
|
|
23
|
+
/**
|
|
24
|
+
* Returns the DOM node rendered by this element.
|
|
25
|
+
*
|
|
26
|
+
* See https://facebook.github.io/react/docs/top-level-api.html#reactdom.finddomnode
|
|
27
|
+
*
|
|
28
|
+
* @param {ReactComponent|DOMElement} componentOrElement
|
|
29
|
+
* @return {?DOMElement} The root node of this element.
|
|
30
|
+
*/
|
|
31
|
+
function findDOMNode(componentOrElement) {
|
|
32
|
+
if (process.env.NODE_ENV !== 'production') {
|
|
33
|
+
var owner = ReactCurrentOwner.current;
|
|
34
|
+
if (owner !== null) {
|
|
35
|
+
process.env.NODE_ENV !== 'production' ? warning(owner._warnedAboutRefsInRender, '%s is accessing findDOMNode inside its render(). ' + 'render() should be a pure function of props and state. It should ' + 'never access something that requires stale data from the previous ' + 'render, such as refs. Move this logic to componentDidMount and ' + 'componentDidUpdate instead.', owner.getName() || 'A component') : void 0;
|
|
36
|
+
owner._warnedAboutRefsInRender = true;
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
if (componentOrElement == null) {
|
|
40
|
+
return null;
|
|
41
|
+
}
|
|
42
|
+
if (componentOrElement.nodeType === 1) {
|
|
43
|
+
return componentOrElement;
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
var inst = ReactInstanceMap.get(componentOrElement);
|
|
47
|
+
if (inst) {
|
|
48
|
+
inst = getHostComponentFromComposite(inst);
|
|
49
|
+
return inst ? ReactDOMComponentTree.getNodeFromInstance(inst) : null;
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
if (typeof componentOrElement.render === 'function') {
|
|
53
|
+
!false ? process.env.NODE_ENV !== 'production' ? invariant(false, 'findDOMNode was called on an unmounted component.') : _prodInvariant('44') : void 0;
|
|
54
|
+
} else {
|
|
55
|
+
!false ? process.env.NODE_ENV !== 'production' ? invariant(false, 'Element appears to be neither ReactComponent nor DOMNode (keys: %s)', Object.keys(componentOrElement)) : _prodInvariant('45', Object.keys(componentOrElement)) : void 0;
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
module.exports = findDOMNode;
|
|
@@ -0,0 +1,75 @@
|
|
|
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
|
+
*
|
|
10
|
+
*/
|
|
11
|
+
|
|
12
|
+
'use strict';
|
|
13
|
+
|
|
14
|
+
var KeyEscapeUtils = require('./KeyEscapeUtils');
|
|
15
|
+
var traverseAllChildren = require('./traverseAllChildren');
|
|
16
|
+
var warning = require('fbjs/lib/warning');
|
|
17
|
+
|
|
18
|
+
var ReactComponentTreeHook;
|
|
19
|
+
|
|
20
|
+
if (typeof process !== 'undefined' && process.env && process.env.NODE_ENV === 'test') {
|
|
21
|
+
// Temporary hack.
|
|
22
|
+
// Inline requires don't work well with Jest:
|
|
23
|
+
// https://github.com/facebook/react/issues/7240
|
|
24
|
+
// Remove the inline requires when we don't need them anymore:
|
|
25
|
+
// https://github.com/facebook/react/pull/7178
|
|
26
|
+
ReactComponentTreeHook = require('react/lib/ReactComponentTreeHook');
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
/**
|
|
30
|
+
* @param {function} traverseContext Context passed through traversal.
|
|
31
|
+
* @param {?ReactComponent} child React child component.
|
|
32
|
+
* @param {!string} name String name of key path to child.
|
|
33
|
+
* @param {number=} selfDebugID Optional debugID of the current internal instance.
|
|
34
|
+
*/
|
|
35
|
+
function flattenSingleChildIntoContext(traverseContext, child, name, selfDebugID) {
|
|
36
|
+
// We found a component instance.
|
|
37
|
+
if (traverseContext && typeof traverseContext === 'object') {
|
|
38
|
+
var result = traverseContext;
|
|
39
|
+
var keyUnique = result[name] === undefined;
|
|
40
|
+
if (process.env.NODE_ENV !== 'production') {
|
|
41
|
+
if (!ReactComponentTreeHook) {
|
|
42
|
+
ReactComponentTreeHook = require('react/lib/ReactComponentTreeHook');
|
|
43
|
+
}
|
|
44
|
+
if (!keyUnique) {
|
|
45
|
+
process.env.NODE_ENV !== 'production' ? warning(false, 'flattenChildren(...): Encountered two children with the same key, ' + '`%s`. Child keys must be unique; when two children share a key, only ' + 'the first child will be used.%s', KeyEscapeUtils.unescape(name), ReactComponentTreeHook.getStackAddendumByID(selfDebugID)) : void 0;
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
if (keyUnique && child != null) {
|
|
49
|
+
result[name] = child;
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
/**
|
|
55
|
+
* Flattens children that are typically specified as `props.children`. Any null
|
|
56
|
+
* children will not be included in the resulting object.
|
|
57
|
+
* @return {!object} flattened children keyed by name.
|
|
58
|
+
*/
|
|
59
|
+
function flattenChildren(children, selfDebugID) {
|
|
60
|
+
if (children == null) {
|
|
61
|
+
return children;
|
|
62
|
+
}
|
|
63
|
+
var result = {};
|
|
64
|
+
|
|
65
|
+
if (process.env.NODE_ENV !== 'production') {
|
|
66
|
+
traverseAllChildren(children, function (traverseContext, child, name) {
|
|
67
|
+
return flattenSingleChildIntoContext(traverseContext, child, name, selfDebugID);
|
|
68
|
+
}, result);
|
|
69
|
+
} else {
|
|
70
|
+
traverseAllChildren(children, flattenSingleChildIntoContext, result);
|
|
71
|
+
}
|
|
72
|
+
return result;
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
module.exports = flattenChildren;
|
|
@@ -0,0 +1,30 @@
|
|
|
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
|
+
*
|
|
10
|
+
*/
|
|
11
|
+
|
|
12
|
+
'use strict';
|
|
13
|
+
|
|
14
|
+
/**
|
|
15
|
+
* @param {array} arr an "accumulation" of items which is either an Array or
|
|
16
|
+
* a single item. Useful when paired with the `accumulate` module. This is a
|
|
17
|
+
* simple utility that allows us to reason about a collection of items, but
|
|
18
|
+
* handling the case when there is exactly one item (and we do not need to
|
|
19
|
+
* allocate an array).
|
|
20
|
+
*/
|
|
21
|
+
|
|
22
|
+
function forEachAccumulated(arr, cb, scope) {
|
|
23
|
+
if (Array.isArray(arr)) {
|
|
24
|
+
arr.forEach(cb, scope);
|
|
25
|
+
} else if (arr) {
|
|
26
|
+
cb.call(scope, arr);
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
module.exports = forEachAccumulated;
|
|
@@ -0,0 +1,49 @@
|
|
|
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
|
+
*/
|
|
10
|
+
|
|
11
|
+
'use strict';
|
|
12
|
+
|
|
13
|
+
/**
|
|
14
|
+
* `charCode` represents the actual "character code" and is safe to use with
|
|
15
|
+
* `String.fromCharCode`. As such, only keys that correspond to printable
|
|
16
|
+
* characters produce a valid `charCode`, the only exception to this is Enter.
|
|
17
|
+
* The Tab-key is considered non-printable and does not have a `charCode`,
|
|
18
|
+
* presumably because it does not produce a tab-character in browsers.
|
|
19
|
+
*
|
|
20
|
+
* @param {object} nativeEvent Native browser event.
|
|
21
|
+
* @return {number} Normalized `charCode` property.
|
|
22
|
+
*/
|
|
23
|
+
|
|
24
|
+
function getEventCharCode(nativeEvent) {
|
|
25
|
+
var charCode;
|
|
26
|
+
var keyCode = nativeEvent.keyCode;
|
|
27
|
+
|
|
28
|
+
if ('charCode' in nativeEvent) {
|
|
29
|
+
charCode = nativeEvent.charCode;
|
|
30
|
+
|
|
31
|
+
// FF does not set `charCode` for the Enter-key, check against `keyCode`.
|
|
32
|
+
if (charCode === 0 && keyCode === 13) {
|
|
33
|
+
charCode = 13;
|
|
34
|
+
}
|
|
35
|
+
} else {
|
|
36
|
+
// IE8 does not implement `charCode`, but `keyCode` has the correct value.
|
|
37
|
+
charCode = keyCode;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
// Some non-printable keys are reported in `charCode`/`keyCode`, discard them.
|
|
41
|
+
// Must not discard the (non-)printable Enter-key.
|
|
42
|
+
if (charCode >= 32 || charCode === 13) {
|
|
43
|
+
return charCode;
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
return 0;
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
module.exports = getEventCharCode;
|
|
@@ -0,0 +1,101 @@
|
|
|
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
|
+
*/
|
|
10
|
+
|
|
11
|
+
'use strict';
|
|
12
|
+
|
|
13
|
+
var getEventCharCode = require('./getEventCharCode');
|
|
14
|
+
|
|
15
|
+
/**
|
|
16
|
+
* Normalization of deprecated HTML5 `key` values
|
|
17
|
+
* @see https://developer.mozilla.org/en-US/docs/Web/API/KeyboardEvent#Key_names
|
|
18
|
+
*/
|
|
19
|
+
var normalizeKey = {
|
|
20
|
+
'Esc': 'Escape',
|
|
21
|
+
'Spacebar': ' ',
|
|
22
|
+
'Left': 'ArrowLeft',
|
|
23
|
+
'Up': 'ArrowUp',
|
|
24
|
+
'Right': 'ArrowRight',
|
|
25
|
+
'Down': 'ArrowDown',
|
|
26
|
+
'Del': 'Delete',
|
|
27
|
+
'Win': 'OS',
|
|
28
|
+
'Menu': 'ContextMenu',
|
|
29
|
+
'Apps': 'ContextMenu',
|
|
30
|
+
'Scroll': 'ScrollLock',
|
|
31
|
+
'MozPrintableKey': 'Unidentified'
|
|
32
|
+
};
|
|
33
|
+
|
|
34
|
+
/**
|
|
35
|
+
* Translation from legacy `keyCode` to HTML5 `key`
|
|
36
|
+
* Only special keys supported, all others depend on keyboard layout or browser
|
|
37
|
+
* @see https://developer.mozilla.org/en-US/docs/Web/API/KeyboardEvent#Key_names
|
|
38
|
+
*/
|
|
39
|
+
var translateToKey = {
|
|
40
|
+
8: 'Backspace',
|
|
41
|
+
9: 'Tab',
|
|
42
|
+
12: 'Clear',
|
|
43
|
+
13: 'Enter',
|
|
44
|
+
16: 'Shift',
|
|
45
|
+
17: 'Control',
|
|
46
|
+
18: 'Alt',
|
|
47
|
+
19: 'Pause',
|
|
48
|
+
20: 'CapsLock',
|
|
49
|
+
27: 'Escape',
|
|
50
|
+
32: ' ',
|
|
51
|
+
33: 'PageUp',
|
|
52
|
+
34: 'PageDown',
|
|
53
|
+
35: 'End',
|
|
54
|
+
36: 'Home',
|
|
55
|
+
37: 'ArrowLeft',
|
|
56
|
+
38: 'ArrowUp',
|
|
57
|
+
39: 'ArrowRight',
|
|
58
|
+
40: 'ArrowDown',
|
|
59
|
+
45: 'Insert',
|
|
60
|
+
46: 'Delete',
|
|
61
|
+
112: 'F1', 113: 'F2', 114: 'F3', 115: 'F4', 116: 'F5', 117: 'F6',
|
|
62
|
+
118: 'F7', 119: 'F8', 120: 'F9', 121: 'F10', 122: 'F11', 123: 'F12',
|
|
63
|
+
144: 'NumLock',
|
|
64
|
+
145: 'ScrollLock',
|
|
65
|
+
224: 'Meta'
|
|
66
|
+
};
|
|
67
|
+
|
|
68
|
+
/**
|
|
69
|
+
* @param {object} nativeEvent Native browser event.
|
|
70
|
+
* @return {string} Normalized `key` property.
|
|
71
|
+
*/
|
|
72
|
+
function getEventKey(nativeEvent) {
|
|
73
|
+
if (nativeEvent.key) {
|
|
74
|
+
// Normalize inconsistent values reported by browsers due to
|
|
75
|
+
// implementations of a working draft specification.
|
|
76
|
+
|
|
77
|
+
// FireFox implements `key` but returns `MozPrintableKey` for all
|
|
78
|
+
// printable characters (normalized to `Unidentified`), ignore it.
|
|
79
|
+
var key = normalizeKey[nativeEvent.key] || nativeEvent.key;
|
|
80
|
+
if (key !== 'Unidentified') {
|
|
81
|
+
return key;
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
// Browser does not implement `key`, polyfill as much of it as we can.
|
|
86
|
+
if (nativeEvent.type === 'keypress') {
|
|
87
|
+
var charCode = getEventCharCode(nativeEvent);
|
|
88
|
+
|
|
89
|
+
// The enter-key is technically both printable and non-printable and can
|
|
90
|
+
// thus be captured by `keypress`, no other non-printable key should.
|
|
91
|
+
return charCode === 13 ? 'Enter' : String.fromCharCode(charCode);
|
|
92
|
+
}
|
|
93
|
+
if (nativeEvent.type === 'keydown' || nativeEvent.type === 'keyup') {
|
|
94
|
+
// While user keyboard layout determines the actual meaning of each
|
|
95
|
+
// `keyCode` value, almost all function keys have a universal value.
|
|
96
|
+
return translateToKey[nativeEvent.keyCode] || 'Unidentified';
|
|
97
|
+
}
|
|
98
|
+
return '';
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
module.exports = getEventKey;
|
|
@@ -0,0 +1,42 @@
|
|
|
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
|
+
*/
|
|
10
|
+
|
|
11
|
+
'use strict';
|
|
12
|
+
|
|
13
|
+
/**
|
|
14
|
+
* Translation from modifier key to the associated property in the event.
|
|
15
|
+
* @see http://www.w3.org/TR/DOM-Level-3-Events/#keys-Modifiers
|
|
16
|
+
*/
|
|
17
|
+
|
|
18
|
+
var modifierKeyToProp = {
|
|
19
|
+
'Alt': 'altKey',
|
|
20
|
+
'Control': 'ctrlKey',
|
|
21
|
+
'Meta': 'metaKey',
|
|
22
|
+
'Shift': 'shiftKey'
|
|
23
|
+
};
|
|
24
|
+
|
|
25
|
+
// IE8 does not implement getModifierState so we simply map it to the only
|
|
26
|
+
// modifier keys exposed by the event itself, does not support Lock-keys.
|
|
27
|
+
// Currently, all major browsers except Chrome seems to support Lock-keys.
|
|
28
|
+
function modifierStateGetter(keyArg) {
|
|
29
|
+
var syntheticEvent = this;
|
|
30
|
+
var nativeEvent = syntheticEvent.nativeEvent;
|
|
31
|
+
if (nativeEvent.getModifierState) {
|
|
32
|
+
return nativeEvent.getModifierState(keyArg);
|
|
33
|
+
}
|
|
34
|
+
var keyProp = modifierKeyToProp[keyArg];
|
|
35
|
+
return keyProp ? !!nativeEvent[keyProp] : false;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
function getEventModifierState(nativeEvent) {
|
|
39
|
+
return modifierStateGetter;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
module.exports = getEventModifierState;
|
|
@@ -0,0 +1,34 @@
|
|
|
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
|
+
*/
|
|
10
|
+
|
|
11
|
+
'use strict';
|
|
12
|
+
|
|
13
|
+
/**
|
|
14
|
+
* Gets the target node from a native browser event by accounting for
|
|
15
|
+
* inconsistencies in browser DOM APIs.
|
|
16
|
+
*
|
|
17
|
+
* @param {object} nativeEvent Native browser event.
|
|
18
|
+
* @return {DOMEventTarget} Target node.
|
|
19
|
+
*/
|
|
20
|
+
|
|
21
|
+
function getEventTarget(nativeEvent) {
|
|
22
|
+
var target = nativeEvent.target || nativeEvent.srcElement || window;
|
|
23
|
+
|
|
24
|
+
// Normalize SVG <use> element events #4963
|
|
25
|
+
if (target.correspondingUseElement) {
|
|
26
|
+
target = target.correspondingUseElement;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
// Safari may fire events on text nodes (Node.TEXT_NODE is 3).
|
|
30
|
+
// @see http://www.quirksmode.org/js/events_properties.html
|
|
31
|
+
return target.nodeType === 3 ? target.parentNode : target;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
module.exports = getEventTarget;
|
|
@@ -0,0 +1,29 @@
|
|
|
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
|
+
*/
|
|
10
|
+
|
|
11
|
+
'use strict';
|
|
12
|
+
|
|
13
|
+
var ReactNodeTypes = require('./ReactNodeTypes');
|
|
14
|
+
|
|
15
|
+
function getHostComponentFromComposite(inst) {
|
|
16
|
+
var type;
|
|
17
|
+
|
|
18
|
+
while ((type = inst._renderedNodeType) === ReactNodeTypes.COMPOSITE) {
|
|
19
|
+
inst = inst._renderedComponent;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
if (type === ReactNodeTypes.HOST) {
|
|
23
|
+
return inst._renderedComponent;
|
|
24
|
+
} else if (type === ReactNodeTypes.EMPTY) {
|
|
25
|
+
return null;
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
module.exports = getHostComponentFromComposite;
|
|
@@ -0,0 +1,40 @@
|
|
|
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
|
+
*
|
|
10
|
+
*/
|
|
11
|
+
|
|
12
|
+
'use strict';
|
|
13
|
+
|
|
14
|
+
/* global Symbol */
|
|
15
|
+
|
|
16
|
+
var ITERATOR_SYMBOL = typeof Symbol === 'function' && Symbol.iterator;
|
|
17
|
+
var FAUX_ITERATOR_SYMBOL = '@@iterator'; // Before Symbol spec.
|
|
18
|
+
|
|
19
|
+
/**
|
|
20
|
+
* Returns the iterator method function contained on the iterable object.
|
|
21
|
+
*
|
|
22
|
+
* Be sure to invoke the function with the iterable as context:
|
|
23
|
+
*
|
|
24
|
+
* var iteratorFn = getIteratorFn(myIterable);
|
|
25
|
+
* if (iteratorFn) {
|
|
26
|
+
* var iterator = iteratorFn.call(myIterable);
|
|
27
|
+
* ...
|
|
28
|
+
* }
|
|
29
|
+
*
|
|
30
|
+
* @param {?object} maybeIterable
|
|
31
|
+
* @return {?function}
|
|
32
|
+
*/
|
|
33
|
+
function getIteratorFn(maybeIterable) {
|
|
34
|
+
var iteratorFn = maybeIterable && (ITERATOR_SYMBOL && maybeIterable[ITERATOR_SYMBOL] || maybeIterable[FAUX_ITERATOR_SYMBOL]);
|
|
35
|
+
if (typeof iteratorFn === 'function') {
|
|
36
|
+
return iteratorFn;
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
module.exports = getIteratorFn;
|
|
@@ -0,0 +1,73 @@
|
|
|
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
|
+
*/
|
|
10
|
+
|
|
11
|
+
'use strict';
|
|
12
|
+
|
|
13
|
+
/**
|
|
14
|
+
* Given any node return the first leaf node without children.
|
|
15
|
+
*
|
|
16
|
+
* @param {DOMElement|DOMTextNode} node
|
|
17
|
+
* @return {DOMElement|DOMTextNode}
|
|
18
|
+
*/
|
|
19
|
+
|
|
20
|
+
function getLeafNode(node) {
|
|
21
|
+
while (node && node.firstChild) {
|
|
22
|
+
node = node.firstChild;
|
|
23
|
+
}
|
|
24
|
+
return node;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
/**
|
|
28
|
+
* Get the next sibling within a container. This will walk up the
|
|
29
|
+
* DOM if a node's siblings have been exhausted.
|
|
30
|
+
*
|
|
31
|
+
* @param {DOMElement|DOMTextNode} node
|
|
32
|
+
* @return {?DOMElement|DOMTextNode}
|
|
33
|
+
*/
|
|
34
|
+
function getSiblingNode(node) {
|
|
35
|
+
while (node) {
|
|
36
|
+
if (node.nextSibling) {
|
|
37
|
+
return node.nextSibling;
|
|
38
|
+
}
|
|
39
|
+
node = node.parentNode;
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
/**
|
|
44
|
+
* Get object describing the nodes which contain characters at offset.
|
|
45
|
+
*
|
|
46
|
+
* @param {DOMElement|DOMTextNode} root
|
|
47
|
+
* @param {number} offset
|
|
48
|
+
* @return {?object}
|
|
49
|
+
*/
|
|
50
|
+
function getNodeForCharacterOffset(root, offset) {
|
|
51
|
+
var node = getLeafNode(root);
|
|
52
|
+
var nodeStart = 0;
|
|
53
|
+
var nodeEnd = 0;
|
|
54
|
+
|
|
55
|
+
while (node) {
|
|
56
|
+
if (node.nodeType === 3) {
|
|
57
|
+
nodeEnd = nodeStart + node.textContent.length;
|
|
58
|
+
|
|
59
|
+
if (nodeStart <= offset && nodeEnd >= offset) {
|
|
60
|
+
return {
|
|
61
|
+
node: node,
|
|
62
|
+
offset: offset - nodeStart
|
|
63
|
+
};
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
nodeStart = nodeEnd;
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
node = getLeafNode(getSiblingNode(node));
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
module.exports = getNodeForCharacterOffset;
|
|
@@ -0,0 +1,32 @@
|
|
|
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
|
+
*/
|
|
10
|
+
|
|
11
|
+
'use strict';
|
|
12
|
+
|
|
13
|
+
var ExecutionEnvironment = require('fbjs/lib/ExecutionEnvironment');
|
|
14
|
+
|
|
15
|
+
var contentKey = null;
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
* Gets the key used to access text content on a DOM node.
|
|
19
|
+
*
|
|
20
|
+
* @return {?string} Key used to access text content.
|
|
21
|
+
* @internal
|
|
22
|
+
*/
|
|
23
|
+
function getTextContentAccessor() {
|
|
24
|
+
if (!contentKey && ExecutionEnvironment.canUseDOM) {
|
|
25
|
+
// Prefer textContent to innerText because many browsers support both but
|
|
26
|
+
// SVG <text> elements don't support innerText even when <div> does.
|
|
27
|
+
contentKey = 'textContent' in document.documentElement ? 'textContent' : 'innerText';
|
|
28
|
+
}
|
|
29
|
+
return contentKey;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
module.exports = getTextContentAccessor;
|