react 15.3.1-rc.2 → 15.4.0-rc.1

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 (190) hide show
  1. package/dist/react-with-addons.js +3961 -21387
  2. package/dist/react-with-addons.min.js +3 -6
  3. package/dist/react.js +2701 -19464
  4. package/dist/react.min.js +2 -6
  5. package/lib/LinkedStateMixin.js +1 -2
  6. package/lib/PooledClass.js +3 -0
  7. package/lib/ReactAddonsDOMDependencies.js +36 -0
  8. package/lib/ReactAddonsDOMDependenciesUMDShim.js +32 -0
  9. package/lib/ReactCSSTransitionGroup.js +60 -42
  10. package/lib/ReactCSSTransitionGroupChild.js +2 -2
  11. package/lib/ReactClass.js +38 -53
  12. package/lib/ReactComponentTreeHook.js +84 -100
  13. package/lib/{DOMNamespaces.js → ReactComponentTreeHookUMDShim.js} +5 -7
  14. package/lib/ReactCurrentOwner.js +1 -1
  15. package/lib/{renderSubtreeIntoContainer.js → ReactCurrentOwnerUMDShim.js} +6 -4
  16. package/lib/ReactElement.js +6 -29
  17. package/lib/ReactElementSymbol.js +20 -0
  18. package/lib/{ReactDOMComponentFlags.js → ReactElementType.js} +4 -9
  19. package/lib/ReactElementValidator.js +1 -2
  20. package/lib/ReactPropTypeLocationNames.js +1 -0
  21. package/lib/ReactPropTypeLocations.js +2 -11
  22. package/lib/ReactPropTypes.js +30 -13
  23. package/lib/ReactPropTypesSecret.js +1 -0
  24. package/lib/ReactTransitionEvents.js +1 -1
  25. package/lib/ReactTransitionGroup.js +145 -141
  26. package/lib/ReactUMDEntry.js +11 -5
  27. package/lib/{ReactDOMFeatureFlags.js → ReactUMDShim.js} +4 -6
  28. package/lib/ReactVersion.js +1 -1
  29. package/lib/ReactWithAddons.js +15 -2
  30. package/lib/ReactWithAddonsUMDEntry.js +11 -5
  31. package/lib/canDefineProperty.js +2 -0
  32. package/lib/onlyChild.js +1 -1
  33. package/lib/traverseAllChildren.js +11 -2
  34. package/lib/update.js +6 -7
  35. package/package.json +2 -2
  36. package/lib/AutoFocusUtils.js +0 -24
  37. package/lib/BeforeInputEventPlugin.js +0 -388
  38. package/lib/CSSProperty.js +0 -148
  39. package/lib/CSSPropertyOperations.js +0 -205
  40. package/lib/CallbackQueue.js +0 -106
  41. package/lib/ChangeEventPlugin.js +0 -325
  42. package/lib/DOMChildrenOperations.js +0 -194
  43. package/lib/DOMLazyTree.js +0 -118
  44. package/lib/DOMProperty.js +0 -206
  45. package/lib/DOMPropertyOperations.js +0 -221
  46. package/lib/Danger.js +0 -48
  47. package/lib/DefaultEventPluginOrder.js +0 -27
  48. package/lib/DisabledInputUtils.js +0 -50
  49. package/lib/EnterLeaveEventPlugin.js +0 -105
  50. package/lib/EventConstants.js +0 -97
  51. package/lib/EventPluginHub.js +0 -251
  52. package/lib/EventPluginRegistry.js +0 -247
  53. package/lib/EventPluginUtils.js +0 -229
  54. package/lib/EventPropagators.js +0 -137
  55. package/lib/FallbackCompositionState.js +0 -95
  56. package/lib/HTMLDOMPropertyConfig.js +0 -209
  57. package/lib/LinkedValueUtils.js +0 -136
  58. package/lib/NativeMethodsMixin.js +0 -167
  59. package/lib/ReactBrowserEventEmitter.js +0 -317
  60. package/lib/ReactChildReconciler.js +0 -154
  61. package/lib/ReactChildrenMutationWarningHook.js +0 -54
  62. package/lib/ReactComponentBrowserEnvironment.js +0 -30
  63. package/lib/ReactComponentEnvironment.js +0 -45
  64. package/lib/ReactComponentTreeTestUtils.js +0 -87
  65. package/lib/ReactCompositeComponent.js +0 -920
  66. package/lib/ReactDOM.js +0 -110
  67. package/lib/ReactDOMButton.js +0 -24
  68. package/lib/ReactDOMComponent.js +0 -1005
  69. package/lib/ReactDOMComponentTree.js +0 -188
  70. package/lib/ReactDOMContainerInfo.js +0 -33
  71. package/lib/ReactDOMEmptyComponent.js +0 -60
  72. package/lib/ReactDOMFiber.js +0 -78
  73. package/lib/ReactDOMIDOperations.js +0 -34
  74. package/lib/ReactDOMInput.js +0 -269
  75. package/lib/ReactDOMNullInputValuePropHook.js +0 -43
  76. package/lib/ReactDOMOption.js +0 -123
  77. package/lib/ReactDOMSelect.js +0 -201
  78. package/lib/ReactDOMSelection.js +0 -212
  79. package/lib/ReactDOMServer.js +0 -26
  80. package/lib/ReactDOMTextComponent.js +0 -164
  81. package/lib/ReactDOMTextarea.js +0 -155
  82. package/lib/ReactDOMTreeTraversal.js +0 -136
  83. package/lib/ReactDOMUnknownPropertyHook.js +0 -112
  84. package/lib/ReactDebugTool.js +0 -307
  85. package/lib/ReactDefaultBatchingStrategy.js +0 -68
  86. package/lib/ReactDefaultInjection.js +0 -84
  87. package/lib/ReactEmptyComponent.js +0 -30
  88. package/lib/ReactErrorUtils.js +0 -76
  89. package/lib/ReactEventEmitterMixin.js +0 -33
  90. package/lib/ReactEventListener.js +0 -157
  91. package/lib/ReactFeatureFlags.js +0 -22
  92. package/lib/ReactHostComponent.js +0 -76
  93. package/lib/ReactHostOperationHistoryHook.js +0 -37
  94. package/lib/ReactInjection.js +0 -36
  95. package/lib/ReactInputSelection.js +0 -124
  96. package/lib/ReactInstanceHandles.js +0 -302
  97. package/lib/ReactInstanceMap.js +0 -48
  98. package/lib/ReactInstrumentation.js +0 -21
  99. package/lib/ReactInvalidSetStateWarningHook.js +0 -36
  100. package/lib/ReactMarkupChecksum.js +0 -50
  101. package/lib/ReactMount.js +0 -495
  102. package/lib/ReactMultiChild.js +0 -451
  103. package/lib/ReactMultiChildUpdateTypes.js +0 -32
  104. package/lib/ReactNative.js +0 -71
  105. package/lib/ReactNativeAttributePayload.js +0 -371
  106. package/lib/ReactNativeBaseComponent.js +0 -198
  107. package/lib/ReactNativeBridgeEventPlugin.js +0 -60
  108. package/lib/ReactNativeComponentEnvironment.js +0 -31
  109. package/lib/ReactNativeComponentTree.js +0 -68
  110. package/lib/ReactNativeContainerInfo.js +0 -21
  111. package/lib/ReactNativeDOMIDOperations.js +0 -79
  112. package/lib/ReactNativeDefaultInjection.js +0 -101
  113. package/lib/ReactNativeEventEmitter.js +0 -191
  114. package/lib/ReactNativeEventPluginOrder.js +0 -16
  115. package/lib/ReactNativeGlobalResponderHandler.js +0 -25
  116. package/lib/ReactNativeMount.js +0 -193
  117. package/lib/ReactNativePropRegistry.js +0 -52
  118. package/lib/ReactNativeReconcileTransaction.js +0 -116
  119. package/lib/ReactNativeTagHandles.js +0 -56
  120. package/lib/ReactNativeTextComponent.js +0 -71
  121. package/lib/ReactNativeTreeTraversal.js +0 -127
  122. package/lib/ReactNodeTypes.js +0 -40
  123. package/lib/ReactNoop.js +0 -173
  124. package/lib/ReactOwner.js +0 -94
  125. package/lib/ReactPerf.js +0 -494
  126. package/lib/ReactReconcileTransaction.js +0 -178
  127. package/lib/ReactReconciler.js +0 -168
  128. package/lib/ReactRef.js +0 -80
  129. package/lib/ReactServerBatchingStrategy.js +0 -22
  130. package/lib/ReactServerRendering.js +0 -90
  131. package/lib/ReactServerRenderingTransaction.js +0 -90
  132. package/lib/ReactServerUpdateQueue.js +0 -141
  133. package/lib/ReactSimpleEmptyComponent.js +0 -37
  134. package/lib/ReactTestMount.js +0 -123
  135. package/lib/ReactTestReconcileTransaction.js +0 -108
  136. package/lib/ReactTestRenderer.js +0 -144
  137. package/lib/ReactTestUtils.js +0 -518
  138. package/lib/ReactUpdateQueue.js +0 -226
  139. package/lib/ReactUpdates.js +0 -251
  140. package/lib/ResponderEventPlugin.js +0 -510
  141. package/lib/ResponderSyntheticEvent.js +0 -39
  142. package/lib/ResponderTouchHistoryStore.js +0 -184
  143. package/lib/SVGDOMPropertyConfig.js +0 -302
  144. package/lib/SelectEventPlugin.js +0 -196
  145. package/lib/SimpleEventPlugin.js +0 -635
  146. package/lib/SyntheticAnimationEvent.js +0 -39
  147. package/lib/SyntheticClipboardEvent.js +0 -38
  148. package/lib/SyntheticCompositionEvent.js +0 -36
  149. package/lib/SyntheticDragEvent.js +0 -36
  150. package/lib/SyntheticEvent.js +0 -267
  151. package/lib/SyntheticFocusEvent.js +0 -36
  152. package/lib/SyntheticInputEvent.js +0 -37
  153. package/lib/SyntheticKeyboardEvent.js +0 -84
  154. package/lib/SyntheticMouseEvent.js +0 -72
  155. package/lib/SyntheticTouchEvent.js +0 -45
  156. package/lib/SyntheticTransitionEvent.js +0 -39
  157. package/lib/SyntheticUIEvent.js +0 -59
  158. package/lib/SyntheticWheelEvent.js +0 -54
  159. package/lib/TapEventPlugin.js +0 -110
  160. package/lib/TouchHistoryMath.js +0 -99
  161. package/lib/Transaction.js +0 -233
  162. package/lib/ViewportMetrics.js +0 -27
  163. package/lib/accumulate.js +0 -46
  164. package/lib/accumulateInto.js +0 -58
  165. package/lib/adler32.js +0 -44
  166. package/lib/createMicrosoftUnsafeLocalFunction.js +0 -32
  167. package/lib/createReactNativeComponentClass.js +0 -42
  168. package/lib/dangerousStyleValue.js +0 -79
  169. package/lib/escapeTextContentForBrowser.js +0 -122
  170. package/lib/findDOMNode.js +0 -60
  171. package/lib/findNodeHandle.js +0 -91
  172. package/lib/forEachAccumulated.js +0 -31
  173. package/lib/getEventCharCode.js +0 -50
  174. package/lib/getEventKey.js +0 -102
  175. package/lib/getEventModifierState.js +0 -43
  176. package/lib/getEventTarget.js +0 -35
  177. package/lib/getHostComponentFromComposite.js +0 -30
  178. package/lib/getNodeForCharacterOffset.js +0 -74
  179. package/lib/getTestDocument.js +0 -21
  180. package/lib/getTextContentAccessor.js +0 -33
  181. package/lib/getVendorPrefixedEventName.js +0 -101
  182. package/lib/instantiateReactComponent.js +0 -119
  183. package/lib/isEventSupported.js +0 -60
  184. package/lib/isTextInputElement.js +0 -51
  185. package/lib/quoteAttributeValueForBrowser.js +0 -26
  186. package/lib/reactComponentExpect.js +0 -217
  187. package/lib/setInnerHTML.js +0 -98
  188. package/lib/setTextContent.js +0 -48
  189. package/lib/shouldUpdateReactComponent.js +0 -42
  190. package/lib/validateDOMNesting.js +0 -369
@@ -1,48 +0,0 @@
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
- * @providesModule ReactInstanceMap
10
- */
11
-
12
- 'use strict';
13
-
14
- /**
15
- * `ReactInstanceMap` maintains a mapping from a public facing stateful
16
- * instance (key) and the internal representation (value). This allows public
17
- * methods to accept the user facing instance as an argument and map them back
18
- * to internal methods.
19
- */
20
-
21
- // TODO: Replace this with ES6: var ReactInstanceMap = new Map();
22
-
23
- var ReactInstanceMap = {
24
-
25
- /**
26
- * This API should be called `delete` but we'd have to make sure to always
27
- * transform these to strings for IE support. When this transform is fully
28
- * supported we can rename it.
29
- */
30
- remove: function (key) {
31
- key._reactInternalInstance = undefined;
32
- },
33
-
34
- get: function (key) {
35
- return key._reactInternalInstance;
36
- },
37
-
38
- has: function (key) {
39
- return key._reactInternalInstance !== undefined;
40
- },
41
-
42
- set: function (key, value) {
43
- key._reactInternalInstance = value;
44
- }
45
-
46
- };
47
-
48
- module.exports = ReactInstanceMap;
@@ -1,21 +0,0 @@
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
- * @providesModule ReactInstrumentation
10
- */
11
-
12
- 'use strict';
13
-
14
- var debugTool = null;
15
-
16
- if (process.env.NODE_ENV !== 'production') {
17
- var ReactDebugTool = require('./ReactDebugTool');
18
- debugTool = ReactDebugTool;
19
- }
20
-
21
- module.exports = { debugTool: debugTool };
@@ -1,36 +0,0 @@
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
- * @providesModule ReactInvalidSetStateWarningHook
10
- */
11
-
12
- 'use strict';
13
-
14
- var warning = require('fbjs/lib/warning');
15
-
16
- if (process.env.NODE_ENV !== 'production') {
17
- var processingChildContext = false;
18
-
19
- var warnInvalidSetState = function () {
20
- process.env.NODE_ENV !== 'production' ? warning(!processingChildContext, 'setState(...): Cannot call setState() inside getChildContext()') : void 0;
21
- };
22
- }
23
-
24
- var ReactInvalidSetStateWarningHook = {
25
- onBeginProcessingChildContext: function () {
26
- processingChildContext = true;
27
- },
28
- onEndProcessingChildContext: function () {
29
- processingChildContext = false;
30
- },
31
- onSetState: function () {
32
- warnInvalidSetState();
33
- }
34
- };
35
-
36
- module.exports = ReactInvalidSetStateWarningHook;
@@ -1,50 +0,0 @@
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
- * @providesModule ReactMarkupChecksum
10
- */
11
-
12
- 'use strict';
13
-
14
- var adler32 = require('./adler32');
15
-
16
- var TAG_END = /\/?>/;
17
- var COMMENT_START = /^<\!\-\-/;
18
-
19
- var ReactMarkupChecksum = {
20
- CHECKSUM_ATTR_NAME: 'data-react-checksum',
21
-
22
- /**
23
- * @param {string} markup Markup string
24
- * @return {string} Markup string with checksum attribute attached
25
- */
26
- addChecksumToMarkup: function (markup) {
27
- var checksum = adler32(markup);
28
-
29
- // Add checksum (handle both parent tags, comments and self-closing tags)
30
- if (COMMENT_START.test(markup)) {
31
- return markup;
32
- } else {
33
- return markup.replace(TAG_END, ' ' + ReactMarkupChecksum.CHECKSUM_ATTR_NAME + '="' + checksum + '"$&');
34
- }
35
- },
36
-
37
- /**
38
- * @param {string} markup to use
39
- * @param {DOMElement} element root React element
40
- * @returns {boolean} whether or not the markup is the same
41
- */
42
- canReuseMarkup: function (markup, element) {
43
- var existingChecksum = element.getAttribute(ReactMarkupChecksum.CHECKSUM_ATTR_NAME);
44
- existingChecksum = existingChecksum && parseInt(existingChecksum, 10);
45
- var markupChecksum = adler32(markup);
46
- return markupChecksum === existingChecksum;
47
- }
48
- };
49
-
50
- module.exports = ReactMarkupChecksum;
package/lib/ReactMount.js DELETED
@@ -1,495 +0,0 @@
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
- * @providesModule ReactMount
10
- */
11
-
12
- 'use strict';
13
-
14
- var _prodInvariant = require('./reactProdInvariant');
15
-
16
- var DOMLazyTree = require('./DOMLazyTree');
17
- var DOMProperty = require('./DOMProperty');
18
- var ReactBrowserEventEmitter = require('./ReactBrowserEventEmitter');
19
- var ReactCurrentOwner = require('./ReactCurrentOwner');
20
- var ReactDOMComponentTree = require('./ReactDOMComponentTree');
21
- var ReactDOMContainerInfo = require('./ReactDOMContainerInfo');
22
- var ReactDOMFeatureFlags = require('./ReactDOMFeatureFlags');
23
- var ReactElement = require('./ReactElement');
24
- var ReactFeatureFlags = require('./ReactFeatureFlags');
25
- var ReactInstanceMap = require('./ReactInstanceMap');
26
- var ReactInstrumentation = require('./ReactInstrumentation');
27
- var ReactMarkupChecksum = require('./ReactMarkupChecksum');
28
- var ReactReconciler = require('./ReactReconciler');
29
- var ReactUpdateQueue = require('./ReactUpdateQueue');
30
- var ReactUpdates = require('./ReactUpdates');
31
-
32
- var emptyObject = require('fbjs/lib/emptyObject');
33
- var instantiateReactComponent = require('./instantiateReactComponent');
34
- var invariant = require('fbjs/lib/invariant');
35
- var setInnerHTML = require('./setInnerHTML');
36
- var shouldUpdateReactComponent = require('./shouldUpdateReactComponent');
37
- var warning = require('fbjs/lib/warning');
38
-
39
- var ATTR_NAME = DOMProperty.ID_ATTRIBUTE_NAME;
40
- var ROOT_ATTR_NAME = DOMProperty.ROOT_ATTRIBUTE_NAME;
41
-
42
- var ELEMENT_NODE_TYPE = 1;
43
- var DOC_NODE_TYPE = 9;
44
- var DOCUMENT_FRAGMENT_NODE_TYPE = 11;
45
-
46
- var instancesByReactRootID = {};
47
-
48
- /**
49
- * Finds the index of the first character
50
- * that's not common between the two given strings.
51
- *
52
- * @return {number} the index of the character where the strings diverge
53
- */
54
- function firstDifferenceIndex(string1, string2) {
55
- var minLen = Math.min(string1.length, string2.length);
56
- for (var i = 0; i < minLen; i++) {
57
- if (string1.charAt(i) !== string2.charAt(i)) {
58
- return i;
59
- }
60
- }
61
- return string1.length === string2.length ? -1 : minLen;
62
- }
63
-
64
- /**
65
- * @param {DOMElement|DOMDocument} container DOM element that may contain
66
- * a React component
67
- * @return {?*} DOM element that may have the reactRoot ID, or null.
68
- */
69
- function getReactRootElementInContainer(container) {
70
- if (!container) {
71
- return null;
72
- }
73
-
74
- if (container.nodeType === DOC_NODE_TYPE) {
75
- return container.documentElement;
76
- } else {
77
- return container.firstChild;
78
- }
79
- }
80
-
81
- function internalGetID(node) {
82
- // If node is something like a window, document, or text node, none of
83
- // which support attributes or a .getAttribute method, gracefully return
84
- // the empty string, as if the attribute were missing.
85
- return node.getAttribute && node.getAttribute(ATTR_NAME) || '';
86
- }
87
-
88
- /**
89
- * Mounts this component and inserts it into the DOM.
90
- *
91
- * @param {ReactComponent} componentInstance The instance to mount.
92
- * @param {DOMElement} container DOM element to mount into.
93
- * @param {ReactReconcileTransaction} transaction
94
- * @param {boolean} shouldReuseMarkup If true, do not insert markup
95
- */
96
- function mountComponentIntoNode(wrapperInstance, container, transaction, shouldReuseMarkup, context) {
97
- var markerName;
98
- if (ReactFeatureFlags.logTopLevelRenders) {
99
- var wrappedElement = wrapperInstance._currentElement.props;
100
- var type = wrappedElement.type;
101
- markerName = 'React mount: ' + (typeof type === 'string' ? type : type.displayName || type.name);
102
- console.time(markerName);
103
- }
104
-
105
- var markup = ReactReconciler.mountComponent(wrapperInstance, transaction, null, ReactDOMContainerInfo(wrapperInstance, container), context, 0 /* parentDebugID */
106
- );
107
-
108
- if (markerName) {
109
- console.timeEnd(markerName);
110
- }
111
-
112
- wrapperInstance._renderedComponent._topLevelWrapper = wrapperInstance;
113
- ReactMount._mountImageIntoNode(markup, container, wrapperInstance, shouldReuseMarkup, transaction);
114
- }
115
-
116
- /**
117
- * Batched mount.
118
- *
119
- * @param {ReactComponent} componentInstance The instance to mount.
120
- * @param {DOMElement} container DOM element to mount into.
121
- * @param {boolean} shouldReuseMarkup If true, do not insert markup
122
- */
123
- function batchedMountComponentIntoNode(componentInstance, container, shouldReuseMarkup, context) {
124
- var transaction = ReactUpdates.ReactReconcileTransaction.getPooled(
125
- /* useCreateElement */
126
- !shouldReuseMarkup && ReactDOMFeatureFlags.useCreateElement);
127
- transaction.perform(mountComponentIntoNode, null, componentInstance, container, transaction, shouldReuseMarkup, context);
128
- ReactUpdates.ReactReconcileTransaction.release(transaction);
129
- }
130
-
131
- /**
132
- * Unmounts a component and removes it from the DOM.
133
- *
134
- * @param {ReactComponent} instance React component instance.
135
- * @param {DOMElement} container DOM element to unmount from.
136
- * @final
137
- * @internal
138
- * @see {ReactMount.unmountComponentAtNode}
139
- */
140
- function unmountComponentFromNode(instance, container, safely) {
141
- if (process.env.NODE_ENV !== 'production') {
142
- ReactInstrumentation.debugTool.onBeginFlush();
143
- }
144
- ReactReconciler.unmountComponent(instance, safely);
145
- if (process.env.NODE_ENV !== 'production') {
146
- ReactInstrumentation.debugTool.onEndFlush();
147
- }
148
-
149
- if (container.nodeType === DOC_NODE_TYPE) {
150
- container = container.documentElement;
151
- }
152
-
153
- // http://jsperf.com/emptying-a-node
154
- while (container.lastChild) {
155
- container.removeChild(container.lastChild);
156
- }
157
- }
158
-
159
- /**
160
- * True if the supplied DOM node has a direct React-rendered child that is
161
- * not a React root element. Useful for warning in `render`,
162
- * `unmountComponentAtNode`, etc.
163
- *
164
- * @param {?DOMElement} node The candidate DOM node.
165
- * @return {boolean} True if the DOM element contains a direct child that was
166
- * rendered by React but is not a root element.
167
- * @internal
168
- */
169
- function hasNonRootReactChild(container) {
170
- var rootEl = getReactRootElementInContainer(container);
171
- if (rootEl) {
172
- var inst = ReactDOMComponentTree.getInstanceFromNode(rootEl);
173
- return !!(inst && inst._hostParent);
174
- }
175
- }
176
-
177
- function getHostRootInstanceInContainer(container) {
178
- var rootEl = getReactRootElementInContainer(container);
179
- var prevHostInstance = rootEl && ReactDOMComponentTree.getInstanceFromNode(rootEl);
180
- return prevHostInstance && !prevHostInstance._hostParent ? prevHostInstance : null;
181
- }
182
-
183
- function getTopLevelWrapperInContainer(container) {
184
- var root = getHostRootInstanceInContainer(container);
185
- return root ? root._hostContainerInfo._topLevelWrapper : null;
186
- }
187
-
188
- /**
189
- * Temporary (?) hack so that we can store all top-level pending updates on
190
- * composites instead of having to worry about different types of components
191
- * here.
192
- */
193
- var topLevelRootCounter = 1;
194
- var TopLevelWrapper = function () {
195
- this.rootID = topLevelRootCounter++;
196
- };
197
- TopLevelWrapper.prototype.isReactComponent = {};
198
- if (process.env.NODE_ENV !== 'production') {
199
- TopLevelWrapper.displayName = 'TopLevelWrapper';
200
- }
201
- TopLevelWrapper.prototype.render = function () {
202
- // this.props is actually a ReactElement
203
- return this.props;
204
- };
205
-
206
- /**
207
- * Mounting is the process of initializing a React component by creating its
208
- * representative DOM elements and inserting them into a supplied `container`.
209
- * Any prior content inside `container` is destroyed in the process.
210
- *
211
- * ReactMount.render(
212
- * component,
213
- * document.getElementById('container')
214
- * );
215
- *
216
- * <div id="container"> <-- Supplied `container`.
217
- * <div data-reactid=".3"> <-- Rendered reactRoot of React
218
- * // ... component.
219
- * </div>
220
- * </div>
221
- *
222
- * Inside of `container`, the first element rendered is the "reactRoot".
223
- */
224
- var ReactMount = {
225
-
226
- TopLevelWrapper: TopLevelWrapper,
227
-
228
- /**
229
- * Used by devtools. The keys are not important.
230
- */
231
- _instancesByReactRootID: instancesByReactRootID,
232
-
233
- /**
234
- * This is a hook provided to support rendering React components while
235
- * ensuring that the apparent scroll position of its `container` does not
236
- * change.
237
- *
238
- * @param {DOMElement} container The `container` being rendered into.
239
- * @param {function} renderCallback This must be called once to do the render.
240
- */
241
- scrollMonitor: function (container, renderCallback) {
242
- renderCallback();
243
- },
244
-
245
- /**
246
- * Take a component that's already mounted into the DOM and replace its props
247
- * @param {ReactComponent} prevComponent component instance already in the DOM
248
- * @param {ReactElement} nextElement component instance to render
249
- * @param {DOMElement} container container to render into
250
- * @param {?function} callback function triggered on completion
251
- */
252
- _updateRootComponent: function (prevComponent, nextElement, nextContext, container, callback) {
253
- ReactMount.scrollMonitor(container, function () {
254
- ReactUpdateQueue.enqueueElementInternal(prevComponent, nextElement, nextContext);
255
- if (callback) {
256
- ReactUpdateQueue.enqueueCallbackInternal(prevComponent, callback);
257
- }
258
- });
259
-
260
- return prevComponent;
261
- },
262
-
263
- /**
264
- * Render a new component into the DOM. Hooked by hooks!
265
- *
266
- * @param {ReactElement} nextElement element to render
267
- * @param {DOMElement} container container to render into
268
- * @param {boolean} shouldReuseMarkup if we should skip the markup insertion
269
- * @return {ReactComponent} nextComponent
270
- */
271
- _renderNewRootComponent: function (nextElement, container, shouldReuseMarkup, context) {
272
- // Various parts of our code (such as ReactCompositeComponent's
273
- // _renderValidatedComponent) assume that calls to render aren't nested;
274
- // verify that that's the case.
275
- process.env.NODE_ENV !== 'production' ? warning(ReactCurrentOwner.current == null, '_renderNewRootComponent(): Render methods should be a pure function ' + 'of props and state; triggering nested component updates from ' + 'render is not allowed. If necessary, trigger nested updates in ' + 'componentDidUpdate. Check the render method of %s.', ReactCurrentOwner.current && ReactCurrentOwner.current.getName() || 'ReactCompositeComponent') : void 0;
276
-
277
- !(container && (container.nodeType === ELEMENT_NODE_TYPE || container.nodeType === DOC_NODE_TYPE || container.nodeType === DOCUMENT_FRAGMENT_NODE_TYPE)) ? process.env.NODE_ENV !== 'production' ? invariant(false, '_registerComponent(...): Target container is not a DOM element.') : _prodInvariant('37') : void 0;
278
-
279
- ReactBrowserEventEmitter.ensureScrollValueMonitoring();
280
- var componentInstance = instantiateReactComponent(nextElement, false);
281
-
282
- // The initial render is synchronous but any updates that happen during
283
- // rendering, in componentWillMount or componentDidMount, will be batched
284
- // according to the current batching strategy.
285
-
286
- ReactUpdates.batchedUpdates(batchedMountComponentIntoNode, componentInstance, container, shouldReuseMarkup, context);
287
-
288
- var wrapperID = componentInstance._instance.rootID;
289
- instancesByReactRootID[wrapperID] = componentInstance;
290
-
291
- return componentInstance;
292
- },
293
-
294
- /**
295
- * Renders a React component into the DOM in the supplied `container`.
296
- *
297
- * If the React component was previously rendered into `container`, this will
298
- * perform an update on it and only mutate the DOM as necessary to reflect the
299
- * latest React component.
300
- *
301
- * @param {ReactComponent} parentComponent The conceptual parent of this render tree.
302
- * @param {ReactElement} nextElement Component element to render.
303
- * @param {DOMElement} container DOM element to render into.
304
- * @param {?function} callback function triggered on completion
305
- * @return {ReactComponent} Component instance rendered in `container`.
306
- */
307
- renderSubtreeIntoContainer: function (parentComponent, nextElement, container, callback) {
308
- !(parentComponent != null && ReactInstanceMap.has(parentComponent)) ? process.env.NODE_ENV !== 'production' ? invariant(false, 'parentComponent must be a valid React Component') : _prodInvariant('38') : void 0;
309
- return ReactMount._renderSubtreeIntoContainer(parentComponent, nextElement, container, callback);
310
- },
311
-
312
- _renderSubtreeIntoContainer: function (parentComponent, nextElement, container, callback) {
313
- ReactUpdateQueue.validateCallback(callback, 'ReactDOM.render');
314
- !ReactElement.isValidElement(nextElement) ? process.env.NODE_ENV !== 'production' ? invariant(false, 'ReactDOM.render(): Invalid component element.%s', typeof nextElement === 'string' ? ' Instead of passing a string like \'div\', pass ' + 'React.createElement(\'div\') or <div />.' : typeof nextElement === 'function' ? ' Instead of passing a class like Foo, pass ' + 'React.createElement(Foo) or <Foo />.' :
315
- // Check if it quacks like an element
316
- nextElement != null && nextElement.props !== undefined ? ' This may be caused by unintentionally loading two independent ' + 'copies of React.' : '') : _prodInvariant('39', typeof nextElement === 'string' ? ' Instead of passing a string like \'div\', pass ' + 'React.createElement(\'div\') or <div />.' : typeof nextElement === 'function' ? ' Instead of passing a class like Foo, pass ' + 'React.createElement(Foo) or <Foo />.' : nextElement != null && nextElement.props !== undefined ? ' This may be caused by unintentionally loading two independent ' + 'copies of React.' : '') : void 0;
317
-
318
- process.env.NODE_ENV !== 'production' ? warning(!container || !container.tagName || container.tagName.toUpperCase() !== 'BODY', 'render(): Rendering components directly into document.body is ' + 'discouraged, since its children are often manipulated by third-party ' + 'scripts and browser extensions. This may lead to subtle ' + 'reconciliation issues. Try rendering into a container element created ' + 'for your app.') : void 0;
319
-
320
- var nextWrappedElement = ReactElement(TopLevelWrapper, null, null, null, null, null, nextElement);
321
-
322
- var nextContext;
323
- if (parentComponent) {
324
- var parentInst = ReactInstanceMap.get(parentComponent);
325
- nextContext = parentInst._processChildContext(parentInst._context);
326
- } else {
327
- nextContext = emptyObject;
328
- }
329
-
330
- var prevComponent = getTopLevelWrapperInContainer(container);
331
-
332
- if (prevComponent) {
333
- var prevWrappedElement = prevComponent._currentElement;
334
- var prevElement = prevWrappedElement.props;
335
- if (shouldUpdateReactComponent(prevElement, nextElement)) {
336
- var publicInst = prevComponent._renderedComponent.getPublicInstance();
337
- var updatedCallback = callback && function () {
338
- callback.call(publicInst);
339
- };
340
- ReactMount._updateRootComponent(prevComponent, nextWrappedElement, nextContext, container, updatedCallback);
341
- return publicInst;
342
- } else {
343
- ReactMount.unmountComponentAtNode(container);
344
- }
345
- }
346
-
347
- var reactRootElement = getReactRootElementInContainer(container);
348
- var containerHasReactMarkup = reactRootElement && !!internalGetID(reactRootElement);
349
- var containerHasNonRootReactChild = hasNonRootReactChild(container);
350
-
351
- if (process.env.NODE_ENV !== 'production') {
352
- process.env.NODE_ENV !== 'production' ? warning(!containerHasNonRootReactChild, 'render(...): Replacing React-rendered children with a new root ' + 'component. If you intended to update the children of this node, ' + 'you should instead have the existing children update their state ' + 'and render the new components instead of calling ReactDOM.render.') : void 0;
353
-
354
- if (!containerHasReactMarkup || reactRootElement.nextSibling) {
355
- var rootElementSibling = reactRootElement;
356
- while (rootElementSibling) {
357
- if (internalGetID(rootElementSibling)) {
358
- process.env.NODE_ENV !== 'production' ? warning(false, 'render(): Target node has markup rendered by React, but there ' + 'are unrelated nodes as well. This is most commonly caused by ' + 'white-space inserted around server-rendered markup.') : void 0;
359
- break;
360
- }
361
- rootElementSibling = rootElementSibling.nextSibling;
362
- }
363
- }
364
- }
365
-
366
- var shouldReuseMarkup = containerHasReactMarkup && !prevComponent && !containerHasNonRootReactChild;
367
- var component = ReactMount._renderNewRootComponent(nextWrappedElement, container, shouldReuseMarkup, nextContext)._renderedComponent.getPublicInstance();
368
- if (callback) {
369
- callback.call(component);
370
- }
371
- return component;
372
- },
373
-
374
- /**
375
- * Renders a React component into the DOM in the supplied `container`.
376
- * See https://facebook.github.io/react/docs/top-level-api.html#reactdom.render
377
- *
378
- * If the React component was previously rendered into `container`, this will
379
- * perform an update on it and only mutate the DOM as necessary to reflect the
380
- * latest React component.
381
- *
382
- * @param {ReactElement} nextElement Component element to render.
383
- * @param {DOMElement} container DOM element to render into.
384
- * @param {?function} callback function triggered on completion
385
- * @return {ReactComponent} Component instance rendered in `container`.
386
- */
387
- render: function (nextElement, container, callback) {
388
- return ReactMount._renderSubtreeIntoContainer(null, nextElement, container, callback);
389
- },
390
-
391
- /**
392
- * Unmounts and destroys the React component rendered in the `container`.
393
- * See https://facebook.github.io/react/docs/top-level-api.html#reactdom.unmountcomponentatnode
394
- *
395
- * @param {DOMElement} container DOM element containing a React component.
396
- * @return {boolean} True if a component was found in and unmounted from
397
- * `container`
398
- */
399
- unmountComponentAtNode: function (container) {
400
- // Various parts of our code (such as ReactCompositeComponent's
401
- // _renderValidatedComponent) assume that calls to render aren't nested;
402
- // verify that that's the case. (Strictly speaking, unmounting won't cause a
403
- // render but we still don't expect to be in a render call here.)
404
- process.env.NODE_ENV !== 'production' ? warning(ReactCurrentOwner.current == null, 'unmountComponentAtNode(): Render methods should be a pure function ' + 'of props and state; triggering nested component updates from render ' + 'is not allowed. If necessary, trigger nested updates in ' + 'componentDidUpdate. Check the render method of %s.', ReactCurrentOwner.current && ReactCurrentOwner.current.getName() || 'ReactCompositeComponent') : void 0;
405
-
406
- !(container && (container.nodeType === ELEMENT_NODE_TYPE || container.nodeType === DOC_NODE_TYPE || container.nodeType === DOCUMENT_FRAGMENT_NODE_TYPE)) ? process.env.NODE_ENV !== 'production' ? invariant(false, 'unmountComponentAtNode(...): Target container is not a DOM element.') : _prodInvariant('40') : void 0;
407
-
408
- var prevComponent = getTopLevelWrapperInContainer(container);
409
- if (!prevComponent) {
410
- // Check if the node being unmounted was rendered by React, but isn't a
411
- // root node.
412
- var containerHasNonRootReactChild = hasNonRootReactChild(container);
413
-
414
- // Check if the container itself is a React root node.
415
- var isContainerReactRoot = container.nodeType === 1 && container.hasAttribute(ROOT_ATTR_NAME);
416
-
417
- if (process.env.NODE_ENV !== 'production') {
418
- process.env.NODE_ENV !== 'production' ? warning(!containerHasNonRootReactChild, 'unmountComponentAtNode(): The node you\'re attempting to unmount ' + 'was rendered by React and is not a top-level container. %s', isContainerReactRoot ? 'You may have accidentally passed in a React root node instead ' + 'of its container.' : 'Instead, have the parent component update its state and ' + 'rerender in order to remove this component.') : void 0;
419
- }
420
-
421
- return false;
422
- }
423
- delete instancesByReactRootID[prevComponent._instance.rootID];
424
- ReactUpdates.batchedUpdates(unmountComponentFromNode, prevComponent, container, false);
425
- return true;
426
- },
427
-
428
- _mountImageIntoNode: function (markup, container, instance, shouldReuseMarkup, transaction) {
429
- !(container && (container.nodeType === ELEMENT_NODE_TYPE || container.nodeType === DOC_NODE_TYPE || container.nodeType === DOCUMENT_FRAGMENT_NODE_TYPE)) ? process.env.NODE_ENV !== 'production' ? invariant(false, 'mountComponentIntoNode(...): Target container is not valid.') : _prodInvariant('41') : void 0;
430
-
431
- if (shouldReuseMarkup) {
432
- var rootElement = getReactRootElementInContainer(container);
433
- if (ReactMarkupChecksum.canReuseMarkup(markup, rootElement)) {
434
- ReactDOMComponentTree.precacheNode(instance, rootElement);
435
- return;
436
- } else {
437
- var checksum = rootElement.getAttribute(ReactMarkupChecksum.CHECKSUM_ATTR_NAME);
438
- rootElement.removeAttribute(ReactMarkupChecksum.CHECKSUM_ATTR_NAME);
439
-
440
- var rootMarkup = rootElement.outerHTML;
441
- rootElement.setAttribute(ReactMarkupChecksum.CHECKSUM_ATTR_NAME, checksum);
442
-
443
- var normalizedMarkup = markup;
444
- if (process.env.NODE_ENV !== 'production') {
445
- // because rootMarkup is retrieved from the DOM, various normalizations
446
- // will have occurred which will not be present in `markup`. Here,
447
- // insert markup into a <div> or <iframe> depending on the container
448
- // type to perform the same normalizations before comparing.
449
- var normalizer;
450
- if (container.nodeType === ELEMENT_NODE_TYPE) {
451
- normalizer = document.createElement('div');
452
- normalizer.innerHTML = markup;
453
- normalizedMarkup = normalizer.innerHTML;
454
- } else {
455
- normalizer = document.createElement('iframe');
456
- document.body.appendChild(normalizer);
457
- normalizer.contentDocument.write(markup);
458
- normalizedMarkup = normalizer.contentDocument.documentElement.outerHTML;
459
- document.body.removeChild(normalizer);
460
- }
461
- }
462
-
463
- var diffIndex = firstDifferenceIndex(normalizedMarkup, rootMarkup);
464
- var difference = ' (client) ' + normalizedMarkup.substring(diffIndex - 20, diffIndex + 20) + '\n (server) ' + rootMarkup.substring(diffIndex - 20, diffIndex + 20);
465
-
466
- !(container.nodeType !== DOC_NODE_TYPE) ? process.env.NODE_ENV !== 'production' ? invariant(false, 'You\'re trying to render a component to the document using server rendering but the checksum was invalid. This usually means you rendered a different component type or props on the client from the one on the server, or your render() methods are impure. React cannot handle this case due to cross-browser quirks by rendering at the document root. You should look for environment dependent code in your components and ensure the props are the same client and server side:\n%s', difference) : _prodInvariant('42', difference) : void 0;
467
-
468
- if (process.env.NODE_ENV !== 'production') {
469
- process.env.NODE_ENV !== 'production' ? warning(false, 'React attempted to reuse markup in a container but the ' + 'checksum was invalid. This generally means that you are ' + 'using server rendering and the markup generated on the ' + 'server was not what the client was expecting. React injected ' + 'new markup to compensate which works but you have lost many ' + 'of the benefits of server rendering. Instead, figure out ' + 'why the markup being generated is different on the client ' + 'or server:\n%s', difference) : void 0;
470
- }
471
- }
472
- }
473
-
474
- !(container.nodeType !== DOC_NODE_TYPE) ? process.env.NODE_ENV !== 'production' ? invariant(false, 'You\'re trying to render a component to the document but you didn\'t use server rendering. We can\'t do this without using server rendering due to cross-browser quirks. See ReactDOMServer.renderToString() for server rendering.') : _prodInvariant('43') : void 0;
475
-
476
- if (transaction.useCreateElement) {
477
- while (container.lastChild) {
478
- container.removeChild(container.lastChild);
479
- }
480
- DOMLazyTree.insertTreeBefore(container, markup, null);
481
- } else {
482
- setInnerHTML(container, markup);
483
- ReactDOMComponentTree.precacheNode(instance, container.firstChild);
484
- }
485
-
486
- if (process.env.NODE_ENV !== 'production') {
487
- var hostNode = ReactDOMComponentTree.getInstanceFromNode(container.firstChild);
488
- if (hostNode._debugID !== 0) {
489
- ReactInstrumentation.debugTool.onHostOperation(hostNode._debugID, 'mount', markup.toString());
490
- }
491
- }
492
- }
493
- };
494
-
495
- module.exports = ReactMount;