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.
Files changed (168) hide show
  1. package/lib/ReactShallowRenderer.js +6 -0
  2. package/lib/shallow/ARIADOMPropertyConfig.js +73 -0
  3. package/lib/shallow/AutoFocusUtils.js +23 -0
  4. package/lib/shallow/BeforeInputEventPlugin.js +384 -0
  5. package/lib/shallow/CSSProperty.js +147 -0
  6. package/lib/shallow/CSSPropertyOperations.js +208 -0
  7. package/lib/shallow/CallbackQueue.js +118 -0
  8. package/lib/shallow/ChangeEventPlugin.js +345 -0
  9. package/lib/shallow/DOMChildrenOperations.js +224 -0
  10. package/lib/shallow/DOMLazyTree.js +117 -0
  11. package/lib/shallow/DOMNamespaces.js +19 -0
  12. package/lib/shallow/DOMProperty.js +209 -0
  13. package/lib/shallow/DOMPropertyOperations.js +236 -0
  14. package/lib/shallow/Danger.js +47 -0
  15. package/lib/shallow/DefaultEventPluginOrder.js +25 -0
  16. package/lib/shallow/EnterLeaveEventPlugin.js +99 -0
  17. package/lib/shallow/EventConstants.js +91 -0
  18. package/lib/shallow/EventPluginHub.js +277 -0
  19. package/lib/shallow/EventPluginRegistry.js +254 -0
  20. package/lib/shallow/EventPluginUtils.js +225 -0
  21. package/lib/shallow/EventPropagators.js +133 -0
  22. package/lib/shallow/FallbackCompositionState.js +94 -0
  23. package/lib/shallow/HTMLDOMPropertyConfig.js +235 -0
  24. package/lib/shallow/KeyEscapeUtils.js +58 -0
  25. package/lib/shallow/LinkedValueUtils.js +137 -0
  26. package/lib/shallow/PluginModuleType.js +12 -0
  27. package/lib/shallow/PooledClass.js +111 -0
  28. package/lib/shallow/ReactBrowserEventEmitter.js +327 -0
  29. package/lib/shallow/ReactChildFiber.js +243 -0
  30. package/lib/shallow/ReactChildReconciler.js +153 -0
  31. package/lib/shallow/ReactComponentBrowserEnvironment.js +29 -0
  32. package/lib/shallow/ReactComponentEnvironment.js +45 -0
  33. package/lib/shallow/ReactCompositeComponent.js +901 -0
  34. package/lib/shallow/ReactCoroutine.js +80 -0
  35. package/lib/shallow/ReactDOM.js +110 -0
  36. package/lib/shallow/ReactDOMComponent.js +1000 -0
  37. package/lib/shallow/ReactDOMComponentFlags.js +17 -0
  38. package/lib/shallow/ReactDOMComponentTree.js +194 -0
  39. package/lib/shallow/ReactDOMContainerInfo.js +32 -0
  40. package/lib/shallow/ReactDOMEmptyComponent.js +59 -0
  41. package/lib/shallow/ReactDOMFeatureFlags.js +18 -0
  42. package/lib/shallow/ReactDOMFiber.js +97 -0
  43. package/lib/shallow/ReactDOMIDOperations.js +33 -0
  44. package/lib/shallow/ReactDOMInput.js +284 -0
  45. package/lib/shallow/ReactDOMInvalidARIAHook.js +92 -0
  46. package/lib/shallow/ReactDOMNullInputValuePropHook.js +42 -0
  47. package/lib/shallow/ReactDOMOption.js +122 -0
  48. package/lib/shallow/ReactDOMSelect.js +199 -0
  49. package/lib/shallow/ReactDOMSelection.js +211 -0
  50. package/lib/shallow/ReactDOMServer.js +25 -0
  51. package/lib/shallow/ReactDOMTextComponent.js +163 -0
  52. package/lib/shallow/ReactDOMTextarea.js +159 -0
  53. package/lib/shallow/ReactDOMTreeTraversal.js +135 -0
  54. package/lib/shallow/ReactDOMUnknownPropertyHook.js +111 -0
  55. package/lib/shallow/ReactDebugTool.js +358 -0
  56. package/lib/shallow/ReactDefaultBatchingStrategy.js +67 -0
  57. package/lib/shallow/ReactDefaultInjection.js +85 -0
  58. package/lib/shallow/ReactElementSymbol.js +19 -0
  59. package/lib/shallow/ReactEmptyComponent.js +29 -0
  60. package/lib/shallow/ReactErrorUtils.js +75 -0
  61. package/lib/shallow/ReactEventEmitterMixin.js +32 -0
  62. package/lib/shallow/ReactEventListener.js +154 -0
  63. package/lib/shallow/ReactFeatureFlags.js +21 -0
  64. package/lib/shallow/ReactFiber.js +190 -0
  65. package/lib/shallow/ReactFiberBeginWork.js +380 -0
  66. package/lib/shallow/ReactFiberCommitWork.js +78 -0
  67. package/lib/shallow/ReactFiberCompleteWork.js +208 -0
  68. package/lib/shallow/ReactFiberReconciler.js +64 -0
  69. package/lib/shallow/ReactFiberRoot.js +29 -0
  70. package/lib/shallow/ReactFiberScheduler.js +331 -0
  71. package/lib/shallow/ReactFiberUpdateQueue.js +77 -0
  72. package/lib/shallow/ReactHostComponent.js +67 -0
  73. package/lib/shallow/ReactHostOperationHistoryHook.js +33 -0
  74. package/lib/shallow/ReactInjection.js +33 -0
  75. package/lib/shallow/ReactInputSelection.js +123 -0
  76. package/lib/shallow/ReactInstanceMap.js +47 -0
  77. package/lib/shallow/ReactInstanceType.js +12 -0
  78. package/lib/shallow/ReactInstrumentation.js +23 -0
  79. package/lib/shallow/ReactInvalidSetStateWarningHook.js +36 -0
  80. package/lib/shallow/ReactMarkupChecksum.js +49 -0
  81. package/lib/shallow/ReactMount.js +537 -0
  82. package/lib/shallow/ReactMultiChild.js +449 -0
  83. package/lib/shallow/ReactMultiChildUpdateTypes.js +18 -0
  84. package/lib/shallow/ReactNodeTypes.js +39 -0
  85. package/lib/shallow/ReactOwner.js +93 -0
  86. package/lib/shallow/ReactPerf.js +500 -0
  87. package/lib/shallow/ReactPriorityLevel.js +20 -0
  88. package/lib/shallow/ReactPropTypeLocationNames.js +24 -0
  89. package/lib/shallow/ReactPropTypeLocations.js +12 -0
  90. package/lib/shallow/ReactPropTypesSecret.js +16 -0
  91. package/lib/shallow/ReactReconcileTransaction.js +177 -0
  92. package/lib/shallow/ReactReconciler.js +167 -0
  93. package/lib/shallow/ReactRef.js +88 -0
  94. package/lib/shallow/ReactReifiedYield.js +30 -0
  95. package/lib/shallow/ReactServerBatchingStrategy.js +21 -0
  96. package/lib/shallow/ReactServerRendering.js +89 -0
  97. package/lib/shallow/ReactServerRenderingTransaction.js +89 -0
  98. package/lib/shallow/ReactServerUpdateQueue.js +138 -0
  99. package/lib/shallow/ReactShallowRenderer.js +150 -0
  100. package/lib/shallow/ReactSimpleEmptyComponent.js +36 -0
  101. package/lib/shallow/ReactSyntheticEventType.js +14 -0
  102. package/lib/shallow/ReactTestEmptyComponent.js +36 -0
  103. package/lib/shallow/ReactTestMount.js +131 -0
  104. package/lib/shallow/ReactTestReconcileTransaction.js +128 -0
  105. package/lib/shallow/ReactTestRenderer.js +139 -0
  106. package/lib/shallow/ReactTestTextComponent.js +40 -0
  107. package/lib/shallow/ReactTypeOfWork.js +23 -0
  108. package/lib/shallow/ReactTypes.js +12 -0
  109. package/lib/shallow/ReactUpdateQueue.js +235 -0
  110. package/lib/shallow/ReactUpdates.js +250 -0
  111. package/lib/shallow/ReactVersion.js +13 -0
  112. package/lib/shallow/ResponderEventPlugin.js +507 -0
  113. package/lib/shallow/ResponderSyntheticEvent.js +38 -0
  114. package/lib/shallow/ResponderTouchHistoryStore.js +183 -0
  115. package/lib/shallow/SVGDOMPropertyConfig.js +301 -0
  116. package/lib/shallow/SelectEventPlugin.js +190 -0
  117. package/lib/shallow/SimpleEventPlugin.js +227 -0
  118. package/lib/shallow/SyntheticAnimationEvent.js +38 -0
  119. package/lib/shallow/SyntheticClipboardEvent.js +37 -0
  120. package/lib/shallow/SyntheticCompositionEvent.js +35 -0
  121. package/lib/shallow/SyntheticDragEvent.js +35 -0
  122. package/lib/shallow/SyntheticEvent.js +267 -0
  123. package/lib/shallow/SyntheticFocusEvent.js +35 -0
  124. package/lib/shallow/SyntheticInputEvent.js +36 -0
  125. package/lib/shallow/SyntheticKeyboardEvent.js +83 -0
  126. package/lib/shallow/SyntheticMouseEvent.js +71 -0
  127. package/lib/shallow/SyntheticTouchEvent.js +44 -0
  128. package/lib/shallow/SyntheticTransitionEvent.js +38 -0
  129. package/lib/shallow/SyntheticUIEvent.js +58 -0
  130. package/lib/shallow/SyntheticWheelEvent.js +53 -0
  131. package/lib/shallow/TapEventPlugin.js +115 -0
  132. package/lib/shallow/TouchHistoryMath.js +98 -0
  133. package/lib/shallow/Transaction.js +224 -0
  134. package/lib/shallow/ViewportMetrics.js +26 -0
  135. package/lib/shallow/accumulate.js +45 -0
  136. package/lib/shallow/accumulateInto.js +57 -0
  137. package/lib/shallow/adler32.js +43 -0
  138. package/lib/shallow/canDefineProperty.js +25 -0
  139. package/lib/shallow/checkReactTypeSpec.js +86 -0
  140. package/lib/shallow/createMicrosoftUnsafeLocalFunction.js +31 -0
  141. package/lib/shallow/dangerousStyleValue.js +78 -0
  142. package/lib/shallow/deprecated.js +56 -0
  143. package/lib/shallow/escapeTextContentForBrowser.js +122 -0
  144. package/lib/shallow/findDOMNode.js +59 -0
  145. package/lib/shallow/flattenChildren.js +75 -0
  146. package/lib/shallow/forEachAccumulated.js +30 -0
  147. package/lib/shallow/getEventCharCode.js +49 -0
  148. package/lib/shallow/getEventKey.js +101 -0
  149. package/lib/shallow/getEventModifierState.js +42 -0
  150. package/lib/shallow/getEventTarget.js +34 -0
  151. package/lib/shallow/getHostComponentFromComposite.js +29 -0
  152. package/lib/shallow/getIteratorFn.js +40 -0
  153. package/lib/shallow/getNodeForCharacterOffset.js +73 -0
  154. package/lib/shallow/getTextContentAccessor.js +32 -0
  155. package/lib/shallow/getVendorPrefixedEventName.js +100 -0
  156. package/lib/shallow/instantiateReactComponent.js +128 -0
  157. package/lib/shallow/isEventSupported.js +59 -0
  158. package/lib/shallow/isTextInputElement.js +50 -0
  159. package/lib/shallow/quoteAttributeValueForBrowser.js +25 -0
  160. package/lib/shallow/reactProdInvariant.js +38 -0
  161. package/lib/shallow/renderSubtreeIntoContainer.js +15 -0
  162. package/lib/shallow/setInnerHTML.js +97 -0
  163. package/lib/shallow/setTextContent.js +51 -0
  164. package/lib/shallow/shouldUpdateReactComponent.js +41 -0
  165. package/lib/shallow/traverseAllChildren.js +175 -0
  166. package/lib/shallow/validateDOMNesting.js +376 -0
  167. package/package.json +1 -1
  168. package/shallow.js +1 -1
@@ -0,0 +1,199 @@
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 _assign = require('object-assign');
14
+
15
+ var LinkedValueUtils = require('./LinkedValueUtils');
16
+ var ReactDOMComponentTree = require('./ReactDOMComponentTree');
17
+ var ReactUpdates = require('./ReactUpdates');
18
+
19
+ var warning = require('fbjs/lib/warning');
20
+
21
+ var didWarnValueLink = false;
22
+ var didWarnValueDefaultValue = false;
23
+
24
+ function updateOptionsIfPendingUpdateAndMounted() {
25
+ if (this._rootNodeID && this._wrapperState.pendingUpdate) {
26
+ this._wrapperState.pendingUpdate = false;
27
+
28
+ var props = this._currentElement.props;
29
+ var value = LinkedValueUtils.getValue(props);
30
+
31
+ if (value != null) {
32
+ updateOptions(this, Boolean(props.multiple), value);
33
+ }
34
+ }
35
+ }
36
+
37
+ function getDeclarationErrorAddendum(owner) {
38
+ if (owner) {
39
+ var name = owner.getName();
40
+ if (name) {
41
+ return ' Check the render method of `' + name + '`.';
42
+ }
43
+ }
44
+ return '';
45
+ }
46
+
47
+ var valuePropNames = ['value', 'defaultValue'];
48
+
49
+ /**
50
+ * Validation function for `value` and `defaultValue`.
51
+ * @private
52
+ */
53
+ function checkSelectPropTypes(inst, props) {
54
+ var owner = inst._currentElement._owner;
55
+ LinkedValueUtils.checkPropTypes('select', props, owner);
56
+
57
+ if (props.valueLink !== undefined && !didWarnValueLink) {
58
+ process.env.NODE_ENV !== 'production' ? warning(false, '`valueLink` prop on `select` is deprecated; set `value` and `onChange` instead.') : void 0;
59
+ didWarnValueLink = true;
60
+ }
61
+
62
+ for (var i = 0; i < valuePropNames.length; i++) {
63
+ var propName = valuePropNames[i];
64
+ if (props[propName] == null) {
65
+ continue;
66
+ }
67
+ var isArray = Array.isArray(props[propName]);
68
+ if (props.multiple && !isArray) {
69
+ process.env.NODE_ENV !== 'production' ? warning(false, 'The `%s` prop supplied to <select> must be an array if ' + '`multiple` is true.%s', propName, getDeclarationErrorAddendum(owner)) : void 0;
70
+ } else if (!props.multiple && isArray) {
71
+ process.env.NODE_ENV !== 'production' ? warning(false, 'The `%s` prop supplied to <select> must be a scalar ' + 'value if `multiple` is false.%s', propName, getDeclarationErrorAddendum(owner)) : void 0;
72
+ }
73
+ }
74
+ }
75
+
76
+ /**
77
+ * @param {ReactDOMComponent} inst
78
+ * @param {boolean} multiple
79
+ * @param {*} propValue A stringable (with `multiple`, a list of stringables).
80
+ * @private
81
+ */
82
+ function updateOptions(inst, multiple, propValue) {
83
+ var selectedValue, i;
84
+ var options = ReactDOMComponentTree.getNodeFromInstance(inst).options;
85
+
86
+ if (multiple) {
87
+ selectedValue = {};
88
+ for (i = 0; i < propValue.length; i++) {
89
+ selectedValue['' + propValue[i]] = true;
90
+ }
91
+ for (i = 0; i < options.length; i++) {
92
+ var selected = selectedValue.hasOwnProperty(options[i].value);
93
+ if (options[i].selected !== selected) {
94
+ options[i].selected = selected;
95
+ }
96
+ }
97
+ } else {
98
+ // Do not set `select.value` as exact behavior isn't consistent across all
99
+ // browsers for all cases.
100
+ selectedValue = '' + propValue;
101
+ for (i = 0; i < options.length; i++) {
102
+ if (options[i].value === selectedValue) {
103
+ options[i].selected = true;
104
+ return;
105
+ }
106
+ }
107
+ if (options.length) {
108
+ options[0].selected = true;
109
+ }
110
+ }
111
+ }
112
+
113
+ /**
114
+ * Implements a <select> host component that allows optionally setting the
115
+ * props `value` and `defaultValue`. If `multiple` is false, the prop must be a
116
+ * stringable. If `multiple` is true, the prop must be an array of stringables.
117
+ *
118
+ * If `value` is not supplied (or null/undefined), user actions that change the
119
+ * selected option will trigger updates to the rendered options.
120
+ *
121
+ * If it is supplied (and not null/undefined), the rendered options will not
122
+ * update in response to user actions. Instead, the `value` prop must change in
123
+ * order for the rendered options to update.
124
+ *
125
+ * If `defaultValue` is provided, any options with the supplied values will be
126
+ * selected.
127
+ */
128
+ var ReactDOMSelect = {
129
+ getHostProps: function (inst, props) {
130
+ return _assign({}, props, {
131
+ onChange: inst._wrapperState.onChange,
132
+ value: undefined
133
+ });
134
+ },
135
+
136
+ mountWrapper: function (inst, props) {
137
+ if (process.env.NODE_ENV !== 'production') {
138
+ checkSelectPropTypes(inst, props);
139
+ }
140
+
141
+ var value = LinkedValueUtils.getValue(props);
142
+ inst._wrapperState = {
143
+ pendingUpdate: false,
144
+ initialValue: value != null ? value : props.defaultValue,
145
+ listeners: null,
146
+ onChange: _handleChange.bind(inst),
147
+ wasMultiple: Boolean(props.multiple)
148
+ };
149
+
150
+ if (props.value !== undefined && props.defaultValue !== undefined && !didWarnValueDefaultValue) {
151
+ process.env.NODE_ENV !== 'production' ? warning(false, 'Select elements must be either controlled or uncontrolled ' + '(specify either the value prop, or the defaultValue prop, but not ' + 'both). Decide between using a controlled or uncontrolled select ' + 'element and remove one of these props. More info: ' + 'https://fb.me/react-controlled-components') : void 0;
152
+ didWarnValueDefaultValue = true;
153
+ }
154
+ },
155
+
156
+ getSelectValueContext: function (inst) {
157
+ // ReactDOMOption looks at this initial value so the initial generated
158
+ // markup has correct `selected` attributes
159
+ return inst._wrapperState.initialValue;
160
+ },
161
+
162
+ postUpdateWrapper: function (inst) {
163
+ var props = inst._currentElement.props;
164
+
165
+ // After the initial mount, we control selected-ness manually so don't pass
166
+ // this value down
167
+ inst._wrapperState.initialValue = undefined;
168
+
169
+ var wasMultiple = inst._wrapperState.wasMultiple;
170
+ inst._wrapperState.wasMultiple = Boolean(props.multiple);
171
+
172
+ var value = LinkedValueUtils.getValue(props);
173
+ if (value != null) {
174
+ inst._wrapperState.pendingUpdate = false;
175
+ updateOptions(inst, Boolean(props.multiple), value);
176
+ } else if (wasMultiple !== Boolean(props.multiple)) {
177
+ // For simplicity, reapply `defaultValue` if `multiple` is toggled.
178
+ if (props.defaultValue != null) {
179
+ updateOptions(inst, Boolean(props.multiple), props.defaultValue);
180
+ } else {
181
+ // Revert the select back to its default unselected state.
182
+ updateOptions(inst, Boolean(props.multiple), props.multiple ? [] : '');
183
+ }
184
+ }
185
+ }
186
+ };
187
+
188
+ function _handleChange(event) {
189
+ var props = this._currentElement.props;
190
+ var returnValue = LinkedValueUtils.executeOnChange(props, event);
191
+
192
+ if (this._rootNodeID) {
193
+ this._wrapperState.pendingUpdate = true;
194
+ }
195
+ ReactUpdates.asap(updateOptionsIfPendingUpdateAndMounted, this);
196
+ return returnValue;
197
+ }
198
+
199
+ module.exports = ReactDOMSelect;
@@ -0,0 +1,211 @@
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 getNodeForCharacterOffset = require('./getNodeForCharacterOffset');
16
+ var getTextContentAccessor = require('./getTextContentAccessor');
17
+
18
+ /**
19
+ * While `isCollapsed` is available on the Selection object and `collapsed`
20
+ * is available on the Range object, IE11 sometimes gets them wrong.
21
+ * If the anchor/focus nodes and offsets are the same, the range is collapsed.
22
+ */
23
+ function isCollapsed(anchorNode, anchorOffset, focusNode, focusOffset) {
24
+ return anchorNode === focusNode && anchorOffset === focusOffset;
25
+ }
26
+
27
+ /**
28
+ * Get the appropriate anchor and focus node/offset pairs for IE.
29
+ *
30
+ * The catch here is that IE's selection API doesn't provide information
31
+ * about whether the selection is forward or backward, so we have to
32
+ * behave as though it's always forward.
33
+ *
34
+ * IE text differs from modern selection in that it behaves as though
35
+ * block elements end with a new line. This means character offsets will
36
+ * differ between the two APIs.
37
+ *
38
+ * @param {DOMElement} node
39
+ * @return {object}
40
+ */
41
+ function getIEOffsets(node) {
42
+ var selection = document.selection;
43
+ var selectedRange = selection.createRange();
44
+ var selectedLength = selectedRange.text.length;
45
+
46
+ // Duplicate selection so we can move range without breaking user selection.
47
+ var fromStart = selectedRange.duplicate();
48
+ fromStart.moveToElementText(node);
49
+ fromStart.setEndPoint('EndToStart', selectedRange);
50
+
51
+ var startOffset = fromStart.text.length;
52
+ var endOffset = startOffset + selectedLength;
53
+
54
+ return {
55
+ start: startOffset,
56
+ end: endOffset
57
+ };
58
+ }
59
+
60
+ /**
61
+ * @param {DOMElement} node
62
+ * @return {?object}
63
+ */
64
+ function getModernOffsets(node) {
65
+ var selection = window.getSelection && window.getSelection();
66
+
67
+ if (!selection || selection.rangeCount === 0) {
68
+ return null;
69
+ }
70
+
71
+ var anchorNode = selection.anchorNode;
72
+ var anchorOffset = selection.anchorOffset;
73
+ var focusNode = selection.focusNode;
74
+ var focusOffset = selection.focusOffset;
75
+
76
+ var currentRange = selection.getRangeAt(0);
77
+
78
+ // In Firefox, range.startContainer and range.endContainer can be "anonymous
79
+ // divs", e.g. the up/down buttons on an <input type="number">. Anonymous
80
+ // divs do not seem to expose properties, triggering a "Permission denied
81
+ // error" if any of its properties are accessed. The only seemingly possible
82
+ // way to avoid erroring is to access a property that typically works for
83
+ // non-anonymous divs and catch any error that may otherwise arise. See
84
+ // https://bugzilla.mozilla.org/show_bug.cgi?id=208427
85
+ try {
86
+ /* eslint-disable no-unused-expressions */
87
+ currentRange.startContainer.nodeType;
88
+ currentRange.endContainer.nodeType;
89
+ /* eslint-enable no-unused-expressions */
90
+ } catch (e) {
91
+ return null;
92
+ }
93
+
94
+ // If the node and offset values are the same, the selection is collapsed.
95
+ // `Selection.isCollapsed` is available natively, but IE sometimes gets
96
+ // this value wrong.
97
+ var isSelectionCollapsed = isCollapsed(selection.anchorNode, selection.anchorOffset, selection.focusNode, selection.focusOffset);
98
+
99
+ var rangeLength = isSelectionCollapsed ? 0 : currentRange.toString().length;
100
+
101
+ var tempRange = currentRange.cloneRange();
102
+ tempRange.selectNodeContents(node);
103
+ tempRange.setEnd(currentRange.startContainer, currentRange.startOffset);
104
+
105
+ var isTempRangeCollapsed = isCollapsed(tempRange.startContainer, tempRange.startOffset, tempRange.endContainer, tempRange.endOffset);
106
+
107
+ var start = isTempRangeCollapsed ? 0 : tempRange.toString().length;
108
+ var end = start + rangeLength;
109
+
110
+ // Detect whether the selection is backward.
111
+ var detectionRange = document.createRange();
112
+ detectionRange.setStart(anchorNode, anchorOffset);
113
+ detectionRange.setEnd(focusNode, focusOffset);
114
+ var isBackward = detectionRange.collapsed;
115
+
116
+ return {
117
+ start: isBackward ? end : start,
118
+ end: isBackward ? start : end
119
+ };
120
+ }
121
+
122
+ /**
123
+ * @param {DOMElement|DOMTextNode} node
124
+ * @param {object} offsets
125
+ */
126
+ function setIEOffsets(node, offsets) {
127
+ var range = document.selection.createRange().duplicate();
128
+ var start, end;
129
+
130
+ if (offsets.end === undefined) {
131
+ start = offsets.start;
132
+ end = start;
133
+ } else if (offsets.start > offsets.end) {
134
+ start = offsets.end;
135
+ end = offsets.start;
136
+ } else {
137
+ start = offsets.start;
138
+ end = offsets.end;
139
+ }
140
+
141
+ range.moveToElementText(node);
142
+ range.moveStart('character', start);
143
+ range.setEndPoint('EndToStart', range);
144
+ range.moveEnd('character', end - start);
145
+ range.select();
146
+ }
147
+
148
+ /**
149
+ * In modern non-IE browsers, we can support both forward and backward
150
+ * selections.
151
+ *
152
+ * Note: IE10+ supports the Selection object, but it does not support
153
+ * the `extend` method, which means that even in modern IE, it's not possible
154
+ * to programmatically create a backward selection. Thus, for all IE
155
+ * versions, we use the old IE API to create our selections.
156
+ *
157
+ * @param {DOMElement|DOMTextNode} node
158
+ * @param {object} offsets
159
+ */
160
+ function setModernOffsets(node, offsets) {
161
+ if (!window.getSelection) {
162
+ return;
163
+ }
164
+
165
+ var selection = window.getSelection();
166
+ var length = node[getTextContentAccessor()].length;
167
+ var start = Math.min(offsets.start, length);
168
+ var end = offsets.end === undefined ? start : Math.min(offsets.end, length);
169
+
170
+ // IE 11 uses modern selection, but doesn't support the extend method.
171
+ // Flip backward selections, so we can set with a single range.
172
+ if (!selection.extend && start > end) {
173
+ var temp = end;
174
+ end = start;
175
+ start = temp;
176
+ }
177
+
178
+ var startMarker = getNodeForCharacterOffset(node, start);
179
+ var endMarker = getNodeForCharacterOffset(node, end);
180
+
181
+ if (startMarker && endMarker) {
182
+ var range = document.createRange();
183
+ range.setStart(startMarker.node, startMarker.offset);
184
+ selection.removeAllRanges();
185
+
186
+ if (start > end) {
187
+ selection.addRange(range);
188
+ selection.extend(endMarker.node, endMarker.offset);
189
+ } else {
190
+ range.setEnd(endMarker.node, endMarker.offset);
191
+ selection.addRange(range);
192
+ }
193
+ }
194
+ }
195
+
196
+ var useIEOffsets = ExecutionEnvironment.canUseDOM && 'selection' in document && !('getSelection' in window);
197
+
198
+ var ReactDOMSelection = {
199
+ /**
200
+ * @param {DOMElement} node
201
+ */
202
+ getOffsets: useIEOffsets ? getIEOffsets : getModernOffsets,
203
+
204
+ /**
205
+ * @param {DOMElement|DOMTextNode} node
206
+ * @param {object} offsets
207
+ */
208
+ setOffsets: useIEOffsets ? setIEOffsets : setModernOffsets
209
+ };
210
+
211
+ module.exports = ReactDOMSelection;
@@ -0,0 +1,25 @@
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 ReactDefaultInjection = require('./ReactDefaultInjection');
14
+ var ReactServerRendering = require('./ReactServerRendering');
15
+ var ReactVersion = require('./ReactVersion');
16
+
17
+ ReactDefaultInjection.inject();
18
+
19
+ var ReactDOMServer = {
20
+ renderToString: ReactServerRendering.renderToString,
21
+ renderToStaticMarkup: ReactServerRendering.renderToStaticMarkup,
22
+ version: ReactVersion
23
+ };
24
+
25
+ module.exports = ReactDOMServer;
@@ -0,0 +1,163 @@
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
+ _assign = require('object-assign');
15
+
16
+ var DOMChildrenOperations = require('./DOMChildrenOperations');
17
+ var DOMLazyTree = require('./DOMLazyTree');
18
+ var ReactDOMComponentTree = require('./ReactDOMComponentTree');
19
+
20
+ var escapeTextContentForBrowser = require('./escapeTextContentForBrowser');
21
+ var invariant = require('fbjs/lib/invariant');
22
+ var validateDOMNesting = require('./validateDOMNesting');
23
+
24
+ /**
25
+ * Text nodes violate a couple assumptions that React makes about components:
26
+ *
27
+ * - When mounting text into the DOM, adjacent text nodes are merged.
28
+ * - Text nodes cannot be assigned a React root ID.
29
+ *
30
+ * This component is used to wrap strings between comment nodes so that they
31
+ * can undergo the same reconciliation that is applied to elements.
32
+ *
33
+ * TODO: Investigate representing React components in the DOM with text nodes.
34
+ *
35
+ * @class ReactDOMTextComponent
36
+ * @extends ReactComponent
37
+ * @internal
38
+ */
39
+ var ReactDOMTextComponent = function (text) {
40
+ // TODO: This is really a ReactText (ReactNode), not a ReactElement
41
+ this._currentElement = text;
42
+ this._stringText = '' + text;
43
+ // ReactDOMComponentTree uses these:
44
+ this._hostNode = null;
45
+ this._hostParent = null;
46
+
47
+ // Properties
48
+ this._domID = 0;
49
+ this._mountIndex = 0;
50
+ this._closingComment = null;
51
+ this._commentNodes = null;
52
+ };
53
+
54
+ _assign(ReactDOMTextComponent.prototype, {
55
+
56
+ /**
57
+ * Creates the markup for this text node. This node is not intended to have
58
+ * any features besides containing text content.
59
+ *
60
+ * @param {ReactReconcileTransaction|ReactServerRenderingTransaction} transaction
61
+ * @return {string} Markup for this text node.
62
+ * @internal
63
+ */
64
+ mountComponent: function (transaction, hostParent, hostContainerInfo, context) {
65
+ if (process.env.NODE_ENV !== 'production') {
66
+ var parentInfo;
67
+ if (hostParent != null) {
68
+ parentInfo = hostParent._ancestorInfo;
69
+ } else if (hostContainerInfo != null) {
70
+ parentInfo = hostContainerInfo._ancestorInfo;
71
+ }
72
+ if (parentInfo) {
73
+ // parentInfo should always be present except for the top-level
74
+ // component when server rendering
75
+ validateDOMNesting(null, this._stringText, this, parentInfo);
76
+ }
77
+ }
78
+
79
+ var domID = hostContainerInfo._idCounter++;
80
+ var openingValue = ' react-text: ' + domID + ' ';
81
+ var closingValue = ' /react-text ';
82
+ this._domID = domID;
83
+ this._hostParent = hostParent;
84
+ if (transaction.useCreateElement) {
85
+ var ownerDocument = hostContainerInfo._ownerDocument;
86
+ var openingComment = ownerDocument.createComment(openingValue);
87
+ var closingComment = ownerDocument.createComment(closingValue);
88
+ var lazyTree = DOMLazyTree(ownerDocument.createDocumentFragment());
89
+ DOMLazyTree.queueChild(lazyTree, DOMLazyTree(openingComment));
90
+ if (this._stringText) {
91
+ DOMLazyTree.queueChild(lazyTree, DOMLazyTree(ownerDocument.createTextNode(this._stringText)));
92
+ }
93
+ DOMLazyTree.queueChild(lazyTree, DOMLazyTree(closingComment));
94
+ ReactDOMComponentTree.precacheNode(this, openingComment);
95
+ this._closingComment = closingComment;
96
+ return lazyTree;
97
+ } else {
98
+ var escapedText = escapeTextContentForBrowser(this._stringText);
99
+
100
+ if (transaction.renderToStaticMarkup) {
101
+ // Normally we'd wrap this between comment nodes for the reasons stated
102
+ // above, but since this is a situation where React won't take over
103
+ // (static pages), we can simply return the text as it is.
104
+ return escapedText;
105
+ }
106
+
107
+ return '<!--' + openingValue + '-->' + escapedText + '<!--' + closingValue + '-->';
108
+ }
109
+ },
110
+
111
+ /**
112
+ * Updates this component by updating the text content.
113
+ *
114
+ * @param {ReactText} nextText The next text content
115
+ * @param {ReactReconcileTransaction} transaction
116
+ * @internal
117
+ */
118
+ receiveComponent: function (nextText, transaction) {
119
+ if (nextText !== this._currentElement) {
120
+ this._currentElement = nextText;
121
+ var nextStringText = '' + nextText;
122
+ if (nextStringText !== this._stringText) {
123
+ // TODO: Save this as pending props and use performUpdateIfNecessary
124
+ // and/or updateComponent to do the actual update for consistency with
125
+ // other component types?
126
+ this._stringText = nextStringText;
127
+ var commentNodes = this.getHostNode();
128
+ DOMChildrenOperations.replaceDelimitedText(commentNodes[0], commentNodes[1], nextStringText);
129
+ }
130
+ }
131
+ },
132
+
133
+ getHostNode: function () {
134
+ var hostNode = this._commentNodes;
135
+ if (hostNode) {
136
+ return hostNode;
137
+ }
138
+ if (!this._closingComment) {
139
+ var openingComment = ReactDOMComponentTree.getNodeFromInstance(this);
140
+ var node = openingComment.nextSibling;
141
+ while (true) {
142
+ !(node != null) ? process.env.NODE_ENV !== 'production' ? invariant(false, 'Missing closing comment for text component %s', this._domID) : _prodInvariant('67', this._domID) : void 0;
143
+ if (node.nodeType === 8 && node.nodeValue === ' /react-text ') {
144
+ this._closingComment = node;
145
+ break;
146
+ }
147
+ node = node.nextSibling;
148
+ }
149
+ }
150
+ hostNode = [this._hostNode, this._closingComment];
151
+ this._commentNodes = hostNode;
152
+ return hostNode;
153
+ },
154
+
155
+ unmountComponent: function () {
156
+ this._closingComment = null;
157
+ this._commentNodes = null;
158
+ ReactDOMComponentTree.uncacheNode(this);
159
+ }
160
+
161
+ });
162
+
163
+ module.exports = ReactDOMTextComponent;