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,224 @@
|
|
|
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 DOMLazyTree = require('./DOMLazyTree');
|
|
14
|
+
var Danger = require('./Danger');
|
|
15
|
+
var ReactDOMComponentTree = require('./ReactDOMComponentTree');
|
|
16
|
+
var ReactInstrumentation = require('./ReactInstrumentation');
|
|
17
|
+
|
|
18
|
+
var createMicrosoftUnsafeLocalFunction = require('./createMicrosoftUnsafeLocalFunction');
|
|
19
|
+
var setInnerHTML = require('./setInnerHTML');
|
|
20
|
+
var setTextContent = require('./setTextContent');
|
|
21
|
+
|
|
22
|
+
function getNodeAfter(parentNode, node) {
|
|
23
|
+
// Special case for text components, which return [open, close] comments
|
|
24
|
+
// from getHostNode.
|
|
25
|
+
if (Array.isArray(node)) {
|
|
26
|
+
node = node[1];
|
|
27
|
+
}
|
|
28
|
+
return node ? node.nextSibling : parentNode.firstChild;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
/**
|
|
32
|
+
* Inserts `childNode` as a child of `parentNode` at the `index`.
|
|
33
|
+
*
|
|
34
|
+
* @param {DOMElement} parentNode Parent node in which to insert.
|
|
35
|
+
* @param {DOMElement} childNode Child node to insert.
|
|
36
|
+
* @param {number} index Index at which to insert the child.
|
|
37
|
+
* @internal
|
|
38
|
+
*/
|
|
39
|
+
var insertChildAt = createMicrosoftUnsafeLocalFunction(function (parentNode, childNode, referenceNode) {
|
|
40
|
+
// We rely exclusively on `insertBefore(node, null)` instead of also using
|
|
41
|
+
// `appendChild(node)`. (Using `undefined` is not allowed by all browsers so
|
|
42
|
+
// we are careful to use `null`.)
|
|
43
|
+
parentNode.insertBefore(childNode, referenceNode);
|
|
44
|
+
});
|
|
45
|
+
|
|
46
|
+
function insertLazyTreeChildAt(parentNode, childTree, referenceNode) {
|
|
47
|
+
DOMLazyTree.insertTreeBefore(parentNode, childTree, referenceNode);
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
function moveChild(parentNode, childNode, referenceNode) {
|
|
51
|
+
if (Array.isArray(childNode)) {
|
|
52
|
+
moveDelimitedText(parentNode, childNode[0], childNode[1], referenceNode);
|
|
53
|
+
} else {
|
|
54
|
+
insertChildAt(parentNode, childNode, referenceNode);
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
function removeChild(parentNode, childNode) {
|
|
59
|
+
if (Array.isArray(childNode)) {
|
|
60
|
+
var closingComment = childNode[1];
|
|
61
|
+
childNode = childNode[0];
|
|
62
|
+
removeDelimitedText(parentNode, childNode, closingComment);
|
|
63
|
+
parentNode.removeChild(closingComment);
|
|
64
|
+
}
|
|
65
|
+
parentNode.removeChild(childNode);
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
function moveDelimitedText(parentNode, openingComment, closingComment, referenceNode) {
|
|
69
|
+
var node = openingComment;
|
|
70
|
+
while (true) {
|
|
71
|
+
var nextNode = node.nextSibling;
|
|
72
|
+
insertChildAt(parentNode, node, referenceNode);
|
|
73
|
+
if (node === closingComment) {
|
|
74
|
+
break;
|
|
75
|
+
}
|
|
76
|
+
node = nextNode;
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
function removeDelimitedText(parentNode, startNode, closingComment) {
|
|
81
|
+
while (true) {
|
|
82
|
+
var node = startNode.nextSibling;
|
|
83
|
+
if (node === closingComment) {
|
|
84
|
+
// The closing comment is removed by ReactMultiChild.
|
|
85
|
+
break;
|
|
86
|
+
} else {
|
|
87
|
+
parentNode.removeChild(node);
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
function replaceDelimitedText(openingComment, closingComment, stringText) {
|
|
93
|
+
var parentNode = openingComment.parentNode;
|
|
94
|
+
var nodeAfterComment = openingComment.nextSibling;
|
|
95
|
+
if (nodeAfterComment === closingComment) {
|
|
96
|
+
// There are no text nodes between the opening and closing comments; insert
|
|
97
|
+
// a new one if stringText isn't empty.
|
|
98
|
+
if (stringText) {
|
|
99
|
+
insertChildAt(parentNode, document.createTextNode(stringText), nodeAfterComment);
|
|
100
|
+
}
|
|
101
|
+
} else {
|
|
102
|
+
if (stringText) {
|
|
103
|
+
// Set the text content of the first node after the opening comment, and
|
|
104
|
+
// remove all following nodes up until the closing comment.
|
|
105
|
+
setTextContent(nodeAfterComment, stringText);
|
|
106
|
+
removeDelimitedText(parentNode, nodeAfterComment, closingComment);
|
|
107
|
+
} else {
|
|
108
|
+
removeDelimitedText(parentNode, openingComment, closingComment);
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
if (process.env.NODE_ENV !== 'production') {
|
|
113
|
+
ReactInstrumentation.debugTool.onHostOperation({
|
|
114
|
+
instanceID: ReactDOMComponentTree.getInstanceFromNode(openingComment)._debugID,
|
|
115
|
+
type: 'replace text',
|
|
116
|
+
payload: stringText
|
|
117
|
+
});
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
var dangerouslyReplaceNodeWithMarkup = Danger.dangerouslyReplaceNodeWithMarkup;
|
|
122
|
+
if (process.env.NODE_ENV !== 'production') {
|
|
123
|
+
dangerouslyReplaceNodeWithMarkup = function (oldChild, markup, prevInstance) {
|
|
124
|
+
Danger.dangerouslyReplaceNodeWithMarkup(oldChild, markup);
|
|
125
|
+
if (prevInstance._debugID !== 0) {
|
|
126
|
+
ReactInstrumentation.debugTool.onHostOperation({
|
|
127
|
+
instanceID: prevInstance._debugID,
|
|
128
|
+
type: 'replace with',
|
|
129
|
+
payload: markup.toString()
|
|
130
|
+
});
|
|
131
|
+
} else {
|
|
132
|
+
var nextInstance = ReactDOMComponentTree.getInstanceFromNode(markup.node);
|
|
133
|
+
if (nextInstance._debugID !== 0) {
|
|
134
|
+
ReactInstrumentation.debugTool.onHostOperation({
|
|
135
|
+
instanceID: nextInstance._debugID,
|
|
136
|
+
type: 'mount',
|
|
137
|
+
payload: markup.toString()
|
|
138
|
+
});
|
|
139
|
+
}
|
|
140
|
+
}
|
|
141
|
+
};
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
/**
|
|
145
|
+
* Operations for updating with DOM children.
|
|
146
|
+
*/
|
|
147
|
+
var DOMChildrenOperations = {
|
|
148
|
+
|
|
149
|
+
dangerouslyReplaceNodeWithMarkup: dangerouslyReplaceNodeWithMarkup,
|
|
150
|
+
|
|
151
|
+
replaceDelimitedText: replaceDelimitedText,
|
|
152
|
+
|
|
153
|
+
/**
|
|
154
|
+
* Updates a component's children by processing a series of updates. The
|
|
155
|
+
* update configurations are each expected to have a `parentNode` property.
|
|
156
|
+
*
|
|
157
|
+
* @param {array<object>} updates List of update configurations.
|
|
158
|
+
* @internal
|
|
159
|
+
*/
|
|
160
|
+
processUpdates: function (parentNode, updates) {
|
|
161
|
+
if (process.env.NODE_ENV !== 'production') {
|
|
162
|
+
var parentNodeDebugID = ReactDOMComponentTree.getInstanceFromNode(parentNode)._debugID;
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
for (var k = 0; k < updates.length; k++) {
|
|
166
|
+
var update = updates[k];
|
|
167
|
+
switch (update.type) {
|
|
168
|
+
case 'INSERT_MARKUP':
|
|
169
|
+
insertLazyTreeChildAt(parentNode, update.content, getNodeAfter(parentNode, update.afterNode));
|
|
170
|
+
if (process.env.NODE_ENV !== 'production') {
|
|
171
|
+
ReactInstrumentation.debugTool.onHostOperation({
|
|
172
|
+
instanceID: parentNodeDebugID,
|
|
173
|
+
type: 'insert child',
|
|
174
|
+
payload: { toIndex: update.toIndex, content: update.content.toString() }
|
|
175
|
+
});
|
|
176
|
+
}
|
|
177
|
+
break;
|
|
178
|
+
case 'MOVE_EXISTING':
|
|
179
|
+
moveChild(parentNode, update.fromNode, getNodeAfter(parentNode, update.afterNode));
|
|
180
|
+
if (process.env.NODE_ENV !== 'production') {
|
|
181
|
+
ReactInstrumentation.debugTool.onHostOperation({
|
|
182
|
+
instanceID: parentNodeDebugID,
|
|
183
|
+
type: 'move child',
|
|
184
|
+
payload: { fromIndex: update.fromIndex, toIndex: update.toIndex }
|
|
185
|
+
});
|
|
186
|
+
}
|
|
187
|
+
break;
|
|
188
|
+
case 'SET_MARKUP':
|
|
189
|
+
setInnerHTML(parentNode, update.content);
|
|
190
|
+
if (process.env.NODE_ENV !== 'production') {
|
|
191
|
+
ReactInstrumentation.debugTool.onHostOperation({
|
|
192
|
+
instanceID: parentNodeDebugID,
|
|
193
|
+
type: 'replace children',
|
|
194
|
+
payload: update.content.toString()
|
|
195
|
+
});
|
|
196
|
+
}
|
|
197
|
+
break;
|
|
198
|
+
case 'TEXT_CONTENT':
|
|
199
|
+
setTextContent(parentNode, update.content);
|
|
200
|
+
if (process.env.NODE_ENV !== 'production') {
|
|
201
|
+
ReactInstrumentation.debugTool.onHostOperation({
|
|
202
|
+
instanceID: parentNodeDebugID,
|
|
203
|
+
type: 'replace text',
|
|
204
|
+
payload: update.content.toString()
|
|
205
|
+
});
|
|
206
|
+
}
|
|
207
|
+
break;
|
|
208
|
+
case 'REMOVE_NODE':
|
|
209
|
+
removeChild(parentNode, update.fromNode);
|
|
210
|
+
if (process.env.NODE_ENV !== 'production') {
|
|
211
|
+
ReactInstrumentation.debugTool.onHostOperation({
|
|
212
|
+
instanceID: parentNodeDebugID,
|
|
213
|
+
type: 'remove child',
|
|
214
|
+
payload: { fromIndex: update.fromIndex }
|
|
215
|
+
});
|
|
216
|
+
}
|
|
217
|
+
break;
|
|
218
|
+
}
|
|
219
|
+
}
|
|
220
|
+
}
|
|
221
|
+
|
|
222
|
+
};
|
|
223
|
+
|
|
224
|
+
module.exports = DOMChildrenOperations;
|
|
@@ -0,0 +1,117 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright 2015-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 DOMNamespaces = require('./DOMNamespaces');
|
|
14
|
+
var setInnerHTML = require('./setInnerHTML');
|
|
15
|
+
|
|
16
|
+
var createMicrosoftUnsafeLocalFunction = require('./createMicrosoftUnsafeLocalFunction');
|
|
17
|
+
var setTextContent = require('./setTextContent');
|
|
18
|
+
|
|
19
|
+
var ELEMENT_NODE_TYPE = 1;
|
|
20
|
+
var DOCUMENT_FRAGMENT_NODE_TYPE = 11;
|
|
21
|
+
|
|
22
|
+
/**
|
|
23
|
+
* In IE (8-11) and Edge, appending nodes with no children is dramatically
|
|
24
|
+
* faster than appending a full subtree, so we essentially queue up the
|
|
25
|
+
* .appendChild calls here and apply them so each node is added to its parent
|
|
26
|
+
* before any children are added.
|
|
27
|
+
*
|
|
28
|
+
* In other browsers, doing so is slower or neutral compared to the other order
|
|
29
|
+
* (in Firefox, twice as slow) so we only do this inversion in IE.
|
|
30
|
+
*
|
|
31
|
+
* See https://github.com/spicyj/innerhtml-vs-createelement-vs-clonenode.
|
|
32
|
+
*/
|
|
33
|
+
var enableLazy = typeof document !== 'undefined' && typeof document.documentMode === 'number' || typeof navigator !== 'undefined' && typeof navigator.userAgent === 'string' && /\bEdge\/\d/.test(navigator.userAgent);
|
|
34
|
+
|
|
35
|
+
function insertTreeChildren(tree) {
|
|
36
|
+
if (!enableLazy) {
|
|
37
|
+
return;
|
|
38
|
+
}
|
|
39
|
+
var node = tree.node;
|
|
40
|
+
var children = tree.children;
|
|
41
|
+
if (children.length) {
|
|
42
|
+
for (var i = 0; i < children.length; i++) {
|
|
43
|
+
insertTreeBefore(node, children[i], null);
|
|
44
|
+
}
|
|
45
|
+
} else if (tree.html != null) {
|
|
46
|
+
setInnerHTML(node, tree.html);
|
|
47
|
+
} else if (tree.text != null) {
|
|
48
|
+
setTextContent(node, tree.text);
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
var insertTreeBefore = createMicrosoftUnsafeLocalFunction(function (parentNode, tree, referenceNode) {
|
|
53
|
+
// DocumentFragments aren't actually part of the DOM after insertion so
|
|
54
|
+
// appending children won't update the DOM. We need to ensure the fragment
|
|
55
|
+
// is properly populated first, breaking out of our lazy approach for just
|
|
56
|
+
// this level. Also, some <object> plugins (like Flash Player) will read
|
|
57
|
+
// <param> nodes immediately upon insertion into the DOM, so <object>
|
|
58
|
+
// must also be populated prior to insertion into the DOM.
|
|
59
|
+
if (tree.node.nodeType === DOCUMENT_FRAGMENT_NODE_TYPE || tree.node.nodeType === ELEMENT_NODE_TYPE && tree.node.nodeName.toLowerCase() === 'object' && (tree.node.namespaceURI == null || tree.node.namespaceURI === DOMNamespaces.html)) {
|
|
60
|
+
insertTreeChildren(tree);
|
|
61
|
+
parentNode.insertBefore(tree.node, referenceNode);
|
|
62
|
+
} else {
|
|
63
|
+
parentNode.insertBefore(tree.node, referenceNode);
|
|
64
|
+
insertTreeChildren(tree);
|
|
65
|
+
}
|
|
66
|
+
});
|
|
67
|
+
|
|
68
|
+
function replaceChildWithTree(oldNode, newTree) {
|
|
69
|
+
oldNode.parentNode.replaceChild(newTree.node, oldNode);
|
|
70
|
+
insertTreeChildren(newTree);
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
function queueChild(parentTree, childTree) {
|
|
74
|
+
if (enableLazy) {
|
|
75
|
+
parentTree.children.push(childTree);
|
|
76
|
+
} else {
|
|
77
|
+
parentTree.node.appendChild(childTree.node);
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
function queueHTML(tree, html) {
|
|
82
|
+
if (enableLazy) {
|
|
83
|
+
tree.html = html;
|
|
84
|
+
} else {
|
|
85
|
+
setInnerHTML(tree.node, html);
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
function queueText(tree, text) {
|
|
90
|
+
if (enableLazy) {
|
|
91
|
+
tree.text = text;
|
|
92
|
+
} else {
|
|
93
|
+
setTextContent(tree.node, text);
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
function toString() {
|
|
98
|
+
return this.node.nodeName;
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
function DOMLazyTree(node) {
|
|
102
|
+
return {
|
|
103
|
+
node: node,
|
|
104
|
+
children: [],
|
|
105
|
+
html: null,
|
|
106
|
+
text: null,
|
|
107
|
+
toString: toString
|
|
108
|
+
};
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
DOMLazyTree.insertTreeBefore = insertTreeBefore;
|
|
112
|
+
DOMLazyTree.replaceChildWithTree = replaceChildWithTree;
|
|
113
|
+
DOMLazyTree.queueChild = queueChild;
|
|
114
|
+
DOMLazyTree.queueHTML = queueHTML;
|
|
115
|
+
DOMLazyTree.queueText = queueText;
|
|
116
|
+
|
|
117
|
+
module.exports = DOMLazyTree;
|
|
@@ -0,0 +1,19 @@
|
|
|
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 DOMNamespaces = {
|
|
14
|
+
html: 'http://www.w3.org/1999/xhtml',
|
|
15
|
+
mathml: 'http://www.w3.org/1998/Math/MathML',
|
|
16
|
+
svg: 'http://www.w3.org/2000/svg'
|
|
17
|
+
};
|
|
18
|
+
|
|
19
|
+
module.exports = DOMNamespaces;
|
|
@@ -0,0 +1,209 @@
|
|
|
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 invariant = require('fbjs/lib/invariant');
|
|
16
|
+
|
|
17
|
+
function checkMask(value, bitmask) {
|
|
18
|
+
return (value & bitmask) === bitmask;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
var DOMPropertyInjection = {
|
|
22
|
+
/**
|
|
23
|
+
* Mapping from normalized, camelcased property names to a configuration that
|
|
24
|
+
* specifies how the associated DOM property should be accessed or rendered.
|
|
25
|
+
*/
|
|
26
|
+
MUST_USE_PROPERTY: 0x1,
|
|
27
|
+
HAS_BOOLEAN_VALUE: 0x4,
|
|
28
|
+
HAS_NUMERIC_VALUE: 0x8,
|
|
29
|
+
HAS_POSITIVE_NUMERIC_VALUE: 0x10 | 0x8,
|
|
30
|
+
HAS_OVERLOADED_BOOLEAN_VALUE: 0x20,
|
|
31
|
+
|
|
32
|
+
/**
|
|
33
|
+
* Inject some specialized knowledge about the DOM. This takes a config object
|
|
34
|
+
* with the following properties:
|
|
35
|
+
*
|
|
36
|
+
* isCustomAttribute: function that given an attribute name will return true
|
|
37
|
+
* if it can be inserted into the DOM verbatim. Useful for data-* or aria-*
|
|
38
|
+
* attributes where it's impossible to enumerate all of the possible
|
|
39
|
+
* attribute names,
|
|
40
|
+
*
|
|
41
|
+
* Properties: object mapping DOM property name to one of the
|
|
42
|
+
* DOMPropertyInjection constants or null. If your attribute isn't in here,
|
|
43
|
+
* it won't get written to the DOM.
|
|
44
|
+
*
|
|
45
|
+
* DOMAttributeNames: object mapping React attribute name to the DOM
|
|
46
|
+
* attribute name. Attribute names not specified use the **lowercase**
|
|
47
|
+
* normalized name.
|
|
48
|
+
*
|
|
49
|
+
* DOMAttributeNamespaces: object mapping React attribute name to the DOM
|
|
50
|
+
* attribute namespace URL. (Attribute names not specified use no namespace.)
|
|
51
|
+
*
|
|
52
|
+
* DOMPropertyNames: similar to DOMAttributeNames but for DOM properties.
|
|
53
|
+
* Property names not specified use the normalized name.
|
|
54
|
+
*
|
|
55
|
+
* DOMMutationMethods: Properties that require special mutation methods. If
|
|
56
|
+
* `value` is undefined, the mutation method should unset the property.
|
|
57
|
+
*
|
|
58
|
+
* @param {object} domPropertyConfig the config as described above.
|
|
59
|
+
*/
|
|
60
|
+
injectDOMPropertyConfig: function (domPropertyConfig) {
|
|
61
|
+
var Injection = DOMPropertyInjection;
|
|
62
|
+
var Properties = domPropertyConfig.Properties || {};
|
|
63
|
+
var DOMAttributeNamespaces = domPropertyConfig.DOMAttributeNamespaces || {};
|
|
64
|
+
var DOMAttributeNames = domPropertyConfig.DOMAttributeNames || {};
|
|
65
|
+
var DOMPropertyNames = domPropertyConfig.DOMPropertyNames || {};
|
|
66
|
+
var DOMMutationMethods = domPropertyConfig.DOMMutationMethods || {};
|
|
67
|
+
|
|
68
|
+
if (domPropertyConfig.isCustomAttribute) {
|
|
69
|
+
DOMProperty._isCustomAttributeFunctions.push(domPropertyConfig.isCustomAttribute);
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
for (var propName in Properties) {
|
|
73
|
+
!!DOMProperty.properties.hasOwnProperty(propName) ? process.env.NODE_ENV !== 'production' ? invariant(false, 'injectDOMPropertyConfig(...): You\'re trying to inject DOM property \'%s\' which has already been injected. You may be accidentally injecting the same DOM property config twice, or you may be injecting two configs that have conflicting property names.', propName) : _prodInvariant('48', propName) : void 0;
|
|
74
|
+
|
|
75
|
+
var lowerCased = propName.toLowerCase();
|
|
76
|
+
var propConfig = Properties[propName];
|
|
77
|
+
|
|
78
|
+
var propertyInfo = {
|
|
79
|
+
attributeName: lowerCased,
|
|
80
|
+
attributeNamespace: null,
|
|
81
|
+
propertyName: propName,
|
|
82
|
+
mutationMethod: null,
|
|
83
|
+
|
|
84
|
+
mustUseProperty: checkMask(propConfig, Injection.MUST_USE_PROPERTY),
|
|
85
|
+
hasBooleanValue: checkMask(propConfig, Injection.HAS_BOOLEAN_VALUE),
|
|
86
|
+
hasNumericValue: checkMask(propConfig, Injection.HAS_NUMERIC_VALUE),
|
|
87
|
+
hasPositiveNumericValue: checkMask(propConfig, Injection.HAS_POSITIVE_NUMERIC_VALUE),
|
|
88
|
+
hasOverloadedBooleanValue: checkMask(propConfig, Injection.HAS_OVERLOADED_BOOLEAN_VALUE)
|
|
89
|
+
};
|
|
90
|
+
!(propertyInfo.hasBooleanValue + propertyInfo.hasNumericValue + propertyInfo.hasOverloadedBooleanValue <= 1) ? process.env.NODE_ENV !== 'production' ? invariant(false, 'DOMProperty: Value can be one of boolean, overloaded boolean, or numeric value, but not a combination: %s', propName) : _prodInvariant('50', propName) : void 0;
|
|
91
|
+
|
|
92
|
+
if (process.env.NODE_ENV !== 'production') {
|
|
93
|
+
DOMProperty.getPossibleStandardName[lowerCased] = propName;
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
if (DOMAttributeNames.hasOwnProperty(propName)) {
|
|
97
|
+
var attributeName = DOMAttributeNames[propName];
|
|
98
|
+
propertyInfo.attributeName = attributeName;
|
|
99
|
+
if (process.env.NODE_ENV !== 'production') {
|
|
100
|
+
DOMProperty.getPossibleStandardName[attributeName] = propName;
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
if (DOMAttributeNamespaces.hasOwnProperty(propName)) {
|
|
105
|
+
propertyInfo.attributeNamespace = DOMAttributeNamespaces[propName];
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
if (DOMPropertyNames.hasOwnProperty(propName)) {
|
|
109
|
+
propertyInfo.propertyName = DOMPropertyNames[propName];
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
if (DOMMutationMethods.hasOwnProperty(propName)) {
|
|
113
|
+
propertyInfo.mutationMethod = DOMMutationMethods[propName];
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
DOMProperty.properties[propName] = propertyInfo;
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
};
|
|
120
|
+
|
|
121
|
+
/* eslint-disable max-len */
|
|
122
|
+
var ATTRIBUTE_NAME_START_CHAR = ':A-Z_a-z\\u00C0-\\u00D6\\u00D8-\\u00F6\\u00F8-\\u02FF\\u0370-\\u037D\\u037F-\\u1FFF\\u200C-\\u200D\\u2070-\\u218F\\u2C00-\\u2FEF\\u3001-\\uD7FF\\uF900-\\uFDCF\\uFDF0-\\uFFFD';
|
|
123
|
+
/* eslint-enable max-len */
|
|
124
|
+
|
|
125
|
+
/**
|
|
126
|
+
* DOMProperty exports lookup objects that can be used like functions:
|
|
127
|
+
*
|
|
128
|
+
* > DOMProperty.isValid['id']
|
|
129
|
+
* true
|
|
130
|
+
* > DOMProperty.isValid['foobar']
|
|
131
|
+
* undefined
|
|
132
|
+
*
|
|
133
|
+
* Although this may be confusing, it performs better in general.
|
|
134
|
+
*
|
|
135
|
+
* @see http://jsperf.com/key-exists
|
|
136
|
+
* @see http://jsperf.com/key-missing
|
|
137
|
+
*/
|
|
138
|
+
var DOMProperty = {
|
|
139
|
+
|
|
140
|
+
ID_ATTRIBUTE_NAME: 'data-reactid',
|
|
141
|
+
ROOT_ATTRIBUTE_NAME: 'data-reactroot',
|
|
142
|
+
|
|
143
|
+
ATTRIBUTE_NAME_START_CHAR: ATTRIBUTE_NAME_START_CHAR,
|
|
144
|
+
ATTRIBUTE_NAME_CHAR: ATTRIBUTE_NAME_START_CHAR + '\\-.0-9\\u00B7\\u0300-\\u036F\\u203F-\\u2040',
|
|
145
|
+
|
|
146
|
+
/**
|
|
147
|
+
* Map from property "standard name" to an object with info about how to set
|
|
148
|
+
* the property in the DOM. Each object contains:
|
|
149
|
+
*
|
|
150
|
+
* attributeName:
|
|
151
|
+
* Used when rendering markup or with `*Attribute()`.
|
|
152
|
+
* attributeNamespace
|
|
153
|
+
* propertyName:
|
|
154
|
+
* Used on DOM node instances. (This includes properties that mutate due to
|
|
155
|
+
* external factors.)
|
|
156
|
+
* mutationMethod:
|
|
157
|
+
* If non-null, used instead of the property or `setAttribute()` after
|
|
158
|
+
* initial render.
|
|
159
|
+
* mustUseProperty:
|
|
160
|
+
* Whether the property must be accessed and mutated as an object property.
|
|
161
|
+
* hasBooleanValue:
|
|
162
|
+
* Whether the property should be removed when set to a falsey value.
|
|
163
|
+
* hasNumericValue:
|
|
164
|
+
* Whether the property must be numeric or parse as a numeric and should be
|
|
165
|
+
* removed when set to a falsey value.
|
|
166
|
+
* hasPositiveNumericValue:
|
|
167
|
+
* Whether the property must be positive numeric or parse as a positive
|
|
168
|
+
* numeric and should be removed when set to a falsey value.
|
|
169
|
+
* hasOverloadedBooleanValue:
|
|
170
|
+
* Whether the property can be used as a flag as well as with a value.
|
|
171
|
+
* Removed when strictly equal to false; present without a value when
|
|
172
|
+
* strictly equal to true; present with a value otherwise.
|
|
173
|
+
*/
|
|
174
|
+
properties: {},
|
|
175
|
+
|
|
176
|
+
/**
|
|
177
|
+
* Mapping from lowercase property names to the properly cased version, used
|
|
178
|
+
* to warn in the case of missing properties. Available only in __DEV__.
|
|
179
|
+
*
|
|
180
|
+
* autofocus is predefined, because adding it to the property whitelist
|
|
181
|
+
* causes unintended side effects.
|
|
182
|
+
*
|
|
183
|
+
* @type {Object}
|
|
184
|
+
*/
|
|
185
|
+
getPossibleStandardName: process.env.NODE_ENV !== 'production' ? { autofocus: 'autoFocus' } : null,
|
|
186
|
+
|
|
187
|
+
/**
|
|
188
|
+
* All of the isCustomAttribute() functions that have been injected.
|
|
189
|
+
*/
|
|
190
|
+
_isCustomAttributeFunctions: [],
|
|
191
|
+
|
|
192
|
+
/**
|
|
193
|
+
* Checks whether a property name is a custom attribute.
|
|
194
|
+
* @method
|
|
195
|
+
*/
|
|
196
|
+
isCustomAttribute: function (attributeName) {
|
|
197
|
+
for (var i = 0; i < DOMProperty._isCustomAttributeFunctions.length; i++) {
|
|
198
|
+
var isCustomAttributeFn = DOMProperty._isCustomAttributeFunctions[i];
|
|
199
|
+
if (isCustomAttributeFn(attributeName)) {
|
|
200
|
+
return true;
|
|
201
|
+
}
|
|
202
|
+
}
|
|
203
|
+
return false;
|
|
204
|
+
},
|
|
205
|
+
|
|
206
|
+
injection: DOMPropertyInjection
|
|
207
|
+
};
|
|
208
|
+
|
|
209
|
+
module.exports = DOMProperty;
|