react 0.7.1 → 0.8.0

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 (203) hide show
  1. package/README.md +15 -228
  2. package/ReactJSErrors.js +40 -0
  3. package/addons.js +4 -0
  4. package/lib/$.js +46 -0
  5. package/lib/CSSCore.js +114 -0
  6. package/lib/CSSProperty.js +90 -0
  7. package/lib/CSSPropertyOperations.js +97 -0
  8. package/lib/CallbackRegistry.js +91 -0
  9. package/lib/ChangeEventPlugin.js +365 -0
  10. package/lib/CompositionEventPlugin.js +212 -0
  11. package/lib/DOMChildrenOperations.js +135 -0
  12. package/lib/DOMProperty.js +266 -0
  13. package/lib/DOMPropertyOperations.js +168 -0
  14. package/lib/Danger.js +186 -0
  15. package/lib/DefaultDOMPropertyConfig.js +187 -0
  16. package/lib/DefaultEventPluginOrder.js +44 -0
  17. package/lib/EnterLeaveEventPlugin.js +112 -0
  18. package/lib/EventConstants.js +73 -0
  19. package/lib/EventListener.js +61 -0
  20. package/lib/EventPluginHub.js +190 -0
  21. package/lib/EventPluginRegistry.js +237 -0
  22. package/lib/EventPluginUtils.js +185 -0
  23. package/lib/EventPropagators.js +179 -0
  24. package/lib/ExecutionEnvironment.js +41 -0
  25. package/lib/LinkedStateMixin.js +46 -0
  26. package/lib/LinkedValueMixin.js +68 -0
  27. package/lib/MobileSafariClickEventPlugin.js +63 -0
  28. package/lib/PooledClass.js +113 -0
  29. package/lib/React.js +71 -0
  30. package/lib/ReactChildren.js +132 -0
  31. package/lib/ReactComponent.js +515 -0
  32. package/lib/ReactComponentBrowserEnvironment.js +140 -0
  33. package/lib/ReactComponentEnvironment.js +24 -0
  34. package/lib/ReactCompositeComponent.js +1020 -0
  35. package/lib/ReactCurrentOwner.js +39 -0
  36. package/lib/ReactDOM.js +194 -0
  37. package/lib/ReactDOMButton.js +64 -0
  38. package/lib/ReactDOMComponent.js +374 -0
  39. package/lib/ReactDOMForm.js +52 -0
  40. package/lib/ReactDOMIDOperations.js +173 -0
  41. package/lib/ReactDOMInput.js +169 -0
  42. package/lib/ReactDOMOption.js +50 -0
  43. package/lib/ReactDOMSelect.js +160 -0
  44. package/lib/ReactDOMSelection.js +189 -0
  45. package/lib/ReactDOMTextarea.js +136 -0
  46. package/lib/ReactDefaultBatchingStrategy.js +75 -0
  47. package/lib/ReactDefaultInjection.js +91 -0
  48. package/lib/ReactDefaultPerf.js +407 -0
  49. package/lib/ReactErrorUtils.js +46 -0
  50. package/lib/ReactEventEmitter.js +341 -0
  51. package/lib/ReactEventEmitterMixin.js +89 -0
  52. package/lib/ReactEventTopLevelCallback.js +89 -0
  53. package/lib/ReactInputSelection.js +140 -0
  54. package/lib/ReactInstanceHandles.js +322 -0
  55. package/lib/ReactLink.js +54 -0
  56. package/lib/ReactMarkupChecksum.js +53 -0
  57. package/lib/ReactMount.js +617 -0
  58. package/lib/ReactMountReady.js +95 -0
  59. package/lib/ReactMultiChild.js +441 -0
  60. package/lib/ReactMultiChildUpdateTypes.js +36 -0
  61. package/lib/ReactOwner.js +146 -0
  62. package/lib/ReactPerf.js +88 -0
  63. package/lib/ReactPropTransferer.js +128 -0
  64. package/lib/ReactPropTypes.js +158 -0
  65. package/lib/ReactReconcileTransaction.js +161 -0
  66. package/lib/ReactServerRendering.js +62 -0
  67. package/lib/ReactStateSetters.js +111 -0
  68. package/lib/ReactTextComponent.js +94 -0
  69. package/lib/ReactTransitionEvents.js +97 -0
  70. package/lib/ReactTransitionGroup.js +112 -0
  71. package/lib/ReactTransitionKeySet.js +111 -0
  72. package/lib/ReactTransitionableChild.js +152 -0
  73. package/lib/ReactUpdates.js +145 -0
  74. package/lib/ReactWithAddons.js +41 -0
  75. package/lib/SelectEventPlugin.js +217 -0
  76. package/lib/SimpleEventPlugin.js +365 -0
  77. package/lib/SyntheticClipboardEvent.js +45 -0
  78. package/lib/SyntheticCompositionEvent.js +51 -0
  79. package/lib/SyntheticEvent.js +163 -0
  80. package/lib/SyntheticFocusEvent.js +44 -0
  81. package/lib/SyntheticKeyboardEvent.js +56 -0
  82. package/lib/SyntheticMouseEvent.js +85 -0
  83. package/lib/SyntheticTouchEvent.js +50 -0
  84. package/lib/SyntheticUIEvent.js +45 -0
  85. package/lib/SyntheticWheelEvent.js +63 -0
  86. package/lib/Transaction.js +251 -0
  87. package/lib/ViewportMetrics.js +37 -0
  88. package/lib/accumulate.js +54 -0
  89. package/lib/adler32.js +39 -0
  90. package/lib/containsNode.js +49 -0
  91. package/lib/copyProperties.js +54 -0
  92. package/lib/createArrayFrom.js +94 -0
  93. package/lib/createNodesFromMarkup.js +93 -0
  94. package/lib/createObjectFrom.js +61 -0
  95. package/lib/cx.js +44 -0
  96. package/lib/dangerousStyleValue.js +57 -0
  97. package/lib/emptyFunction.js +43 -0
  98. package/lib/escapeTextForBrowser.js +47 -0
  99. package/lib/ex.js +49 -0
  100. package/lib/filterAttributes.js +45 -0
  101. package/lib/flattenChildren.js +54 -0
  102. package/lib/forEachAccumulated.js +36 -0
  103. package/lib/ge.js +76 -0
  104. package/lib/getActiveElement.js +33 -0
  105. package/lib/getEventTarget.js +36 -0
  106. package/lib/getMarkupWrap.js +108 -0
  107. package/lib/getNodeForCharacterOffset.js +80 -0
  108. package/lib/getReactRootElementInContainer.js +40 -0
  109. package/lib/getTextContentAccessor.js +40 -0
  110. package/lib/getUnboundedScrollPosition.js +45 -0
  111. package/lib/hyphenate.js +35 -0
  112. package/lib/invariant.js +54 -0
  113. package/lib/isEventSupported.js +74 -0
  114. package/lib/isNode.js +33 -0
  115. package/lib/isTextInputElement.js +49 -0
  116. package/lib/isTextNode.js +30 -0
  117. package/lib/joinClasses.js +44 -0
  118. package/lib/keyMirror.js +58 -0
  119. package/lib/keyOf.js +41 -0
  120. package/lib/memoizeStringOnly.js +39 -0
  121. package/lib/merge.js +37 -0
  122. package/lib/mergeHelpers.js +137 -0
  123. package/lib/mergeInto.js +45 -0
  124. package/lib/mixInto.js +34 -0
  125. package/lib/mutateHTMLNodeWithMarkup.js +100 -0
  126. package/lib/objMap.js +47 -0
  127. package/lib/objMapKeyVal.js +47 -0
  128. package/lib/performanceNow.js +42 -0
  129. package/lib/shallowEqual.js +49 -0
  130. package/lib/traverseAllChildren.js +127 -0
  131. package/package.json +33 -31
  132. package/react.js +4 -0
  133. package/.npmignore +0 -7
  134. package/.travis.yml +0 -7
  135. package/Jakefile.js +0 -39
  136. package/LICENSE +0 -19
  137. package/browser-test/dist.html +0 -90
  138. package/browser-test/index.html +0 -86
  139. package/browser-test/min.html +0 -90
  140. package/dist/react.js +0 -3141
  141. package/dist/react.min.js +0 -22
  142. package/doc/advanced.md +0 -175
  143. package/doc/color-def.graffle +0 -938
  144. package/doc/color-def.png +0 -0
  145. package/doc/simple.dot +0 -25
  146. package/doc/simple.png +0 -0
  147. package/examples/longer-example.js +0 -41
  148. package/examples/simple.js +0 -45
  149. package/examples/using-ast-directly.js +0 -30
  150. package/examples/using-events1.js +0 -79
  151. package/examples/using-log-events.js +0 -43
  152. package/lib/base-task.js +0 -120
  153. package/lib/cb-task.js +0 -84
  154. package/lib/core.js +0 -138
  155. package/lib/dsl.js +0 -138
  156. package/lib/error.js +0 -55
  157. package/lib/event-collector.js +0 -81
  158. package/lib/event-manager.js +0 -89
  159. package/lib/eventemitter.js +0 -20
  160. package/lib/finalcb-first-task.js +0 -68
  161. package/lib/finalcb-task.js +0 -65
  162. package/lib/id.js +0 -22
  163. package/lib/input-parser.js +0 -56
  164. package/lib/log-events.js +0 -101
  165. package/lib/parse.js +0 -41
  166. package/lib/promise-resolve.js +0 -50
  167. package/lib/promise-task.js +0 -93
  168. package/lib/react.js +0 -59
  169. package/lib/ret-task.js +0 -71
  170. package/lib/sprintf.js +0 -18
  171. package/lib/status.js +0 -14
  172. package/lib/task.js +0 -251
  173. package/lib/track-tasks.js +0 -74
  174. package/lib/validate.js +0 -159
  175. package/lib/vcon.js +0 -113
  176. package/lib/when-task.js +0 -84
  177. package/src/dist.build.requirejs +0 -20
  178. package/test/ast.mocha.js +0 -136
  179. package/test/cb-task.mocha.js +0 -220
  180. package/test/core-deferred.mocha.js +0 -143
  181. package/test/core-when.mocha.js +0 -96
  182. package/test/core.mocha.js +0 -589
  183. package/test/dsl.mocha.js +0 -352
  184. package/test/event-manager.mocha.js +0 -119
  185. package/test/exec-options.mocha.js +0 -48
  186. package/test/finalcb-task.mocha.js +0 -58
  187. package/test/input-parser.mocha.js +0 -86
  188. package/test/log-events.mocha.js +0 -88
  189. package/test/mocha.opts +0 -2
  190. package/test/module-use.mocha.js +0 -164
  191. package/test/promise-auto-resolve.mocha.js +0 -68
  192. package/test/ret-task.mocha.js +0 -220
  193. package/test/task.mocha.js +0 -42
  194. package/test/validate-cb-task.mocha.js +0 -100
  195. package/test/validate-ret-task.mocha.js +0 -110
  196. package/test/validate.mocha.js +0 -324
  197. package/test/vcon.mocha.js +0 -193
  198. package/vendor/chai/chai.js +0 -4251
  199. package/vendor/jquery/jquery-1.7.1.js +0 -9266
  200. package/vendor/jquery/jquery-1.7.1.min.js +0 -4
  201. package/vendor/node/util.js +0 -531
  202. package/vendor/requirejs/require.js +0 -2045
  203. package/vendor/requirejs/require.min.js +0 -36
@@ -0,0 +1,140 @@
1
+ /**
2
+ * Copyright 2013 Facebook, Inc.
3
+ *
4
+ * Licensed under the Apache License, Version 2.0 (the "License");
5
+ * you may not use this file except in compliance with the License.
6
+ * You may obtain a copy of the License at
7
+ *
8
+ * http://www.apache.org/licenses/LICENSE-2.0
9
+ *
10
+ * Unless required by applicable law or agreed to in writing, software
11
+ * distributed under the License is distributed on an "AS IS" BASIS,
12
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ * See the License for the specific language governing permissions and
14
+ * limitations under the License.
15
+ *
16
+ * @providesModule ReactInputSelection
17
+ */
18
+
19
+ "use strict";
20
+
21
+ var ReactDOMSelection = require("./ReactDOMSelection");
22
+
23
+ var containsNode = require("./containsNode");
24
+ var getActiveElement = require("./getActiveElement");
25
+
26
+ function isInDocument(node) {
27
+ return containsNode(document.documentElement, node);
28
+ }
29
+
30
+ /**
31
+ * @ReactInputSelection: React input selection module. Based on Selection.js,
32
+ * but modified to be suitable for react and has a couple of bug fixes (doesn't
33
+ * assume buttons have range selections allowed).
34
+ * Input selection module for React.
35
+ */
36
+ var ReactInputSelection = {
37
+
38
+ hasSelectionCapabilities: function(elem) {
39
+ return elem && (
40
+ (elem.nodeName === 'INPUT' && elem.type === 'text') ||
41
+ elem.nodeName === 'TEXTAREA' ||
42
+ elem.contentEditable === 'true'
43
+ );
44
+ },
45
+
46
+ getSelectionInformation: function() {
47
+ var focusedElem = getActiveElement();
48
+ return {
49
+ focusedElem: focusedElem,
50
+ selectionRange:
51
+ ReactInputSelection.hasSelectionCapabilities(focusedElem) ?
52
+ ReactInputSelection.getSelection(focusedElem) :
53
+ null
54
+ };
55
+ },
56
+
57
+ /**
58
+ * @restoreSelection: If any selection information was potentially lost,
59
+ * restore it. This is useful when performing operations that could remove dom
60
+ * nodes and place them back in, resulting in focus being lost.
61
+ */
62
+ restoreSelection: function(priorSelectionInformation) {
63
+ var curFocusedElem = getActiveElement();
64
+ var priorFocusedElem = priorSelectionInformation.focusedElem;
65
+ var priorSelectionRange = priorSelectionInformation.selectionRange;
66
+ if (curFocusedElem !== priorFocusedElem &&
67
+ isInDocument(priorFocusedElem)) {
68
+ if (ReactInputSelection.hasSelectionCapabilities(priorFocusedElem)) {
69
+ ReactInputSelection.setSelection(
70
+ priorFocusedElem,
71
+ priorSelectionRange
72
+ );
73
+ }
74
+ priorFocusedElem.focus();
75
+ }
76
+ },
77
+
78
+ /**
79
+ * @getSelection: Gets the selection bounds of a focused textarea, input or
80
+ * contentEditable node.
81
+ * -@input: Look up selection bounds of this input
82
+ * -@return {start: selectionStart, end: selectionEnd}
83
+ */
84
+ getSelection: function(input) {
85
+ var selection;
86
+
87
+ if ('selectionStart' in input) {
88
+ // Modern browser with input or textarea.
89
+ selection = {
90
+ start: input.selectionStart,
91
+ end: input.selectionEnd
92
+ };
93
+ } else if (document.selection && input.nodeName === 'INPUT') {
94
+ // IE8 input.
95
+ var range = document.selection.createRange();
96
+ // There can only be one selection per document in IE, so it must
97
+ // be in our element.
98
+ if (range.parentElement() === input) {
99
+ selection = {
100
+ start: -range.moveStart('character', -input.value.length),
101
+ end: -range.moveEnd('character', -input.value.length)
102
+ };
103
+ }
104
+ } else {
105
+ // Content editable or old IE textarea.
106
+ selection = ReactDOMSelection.getOffsets(input);
107
+ }
108
+
109
+ return selection || {start: 0, end: 0};
110
+ },
111
+
112
+ /**
113
+ * @setSelection: Sets the selection bounds of a textarea or input and focuses
114
+ * the input.
115
+ * -@input Set selection bounds of this input or textarea
116
+ * -@offsets Object of same form that is returned from get*
117
+ */
118
+ setSelection: function(input, offsets) {
119
+ var start = offsets.start;
120
+ var end = offsets.end;
121
+ if (typeof end === 'undefined') {
122
+ end = start;
123
+ }
124
+
125
+ if ('selectionStart' in input) {
126
+ input.selectionStart = start;
127
+ input.selectionEnd = Math.min(end, input.value.length);
128
+ } else if (document.selection && input.nodeName === 'INPUT') {
129
+ var range = input.createTextRange();
130
+ range.collapse(true);
131
+ range.moveStart('character', start);
132
+ range.moveEnd('character', end - start);
133
+ range.select();
134
+ } else {
135
+ ReactDOMSelection.setOffsets(input, offsets);
136
+ }
137
+ }
138
+ };
139
+
140
+ module.exports = ReactInputSelection;
@@ -0,0 +1,322 @@
1
+ /**
2
+ * Copyright 2013 Facebook, Inc.
3
+ *
4
+ * Licensed under the Apache License, Version 2.0 (the "License");
5
+ * you may not use this file except in compliance with the License.
6
+ * You may obtain a copy of the License at
7
+ *
8
+ * http://www.apache.org/licenses/LICENSE-2.0
9
+ *
10
+ * Unless required by applicable law or agreed to in writing, software
11
+ * distributed under the License is distributed on an "AS IS" BASIS,
12
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ * See the License for the specific language governing permissions and
14
+ * limitations under the License.
15
+ *
16
+ * @providesModule ReactInstanceHandles
17
+ * @typechecks static-only
18
+ */
19
+
20
+ "use strict";
21
+
22
+ var invariant = require("./invariant");
23
+
24
+ var SEPARATOR = '.';
25
+ var SEPARATOR_LENGTH = SEPARATOR.length;
26
+
27
+ /**
28
+ * Maximum depth of traversals before we consider the possibility of a bad ID.
29
+ */
30
+ var MAX_TREE_DEPTH = 100;
31
+
32
+ /**
33
+ * Size of the reactRoot ID space. We generate random numbers for React root
34
+ * IDs and if there's a collision the events and DOM update system will
35
+ * get confused. If we assume 100 React components per page, and a user
36
+ * loads 1 page per minute 24/7 for 50 years, with a mount point space of
37
+ * 9,999,999 the likelihood of never having a collision is 99.997%.
38
+ */
39
+ var GLOBAL_MOUNT_POINT_MAX = 9999999;
40
+
41
+ /**
42
+ * Creates a DOM ID prefix to use when mounting React components.
43
+ *
44
+ * @param {number} index A unique integer
45
+ * @return {string} React root ID.
46
+ * @internal
47
+ */
48
+ function getReactRootIDString(index) {
49
+ return SEPARATOR + 'r[' + index.toString(36) + ']';
50
+ }
51
+
52
+ /**
53
+ * Checks if a character in the supplied ID is a separator or the end.
54
+ *
55
+ * @param {string} id A React DOM ID.
56
+ * @param {number} index Index of the character to check.
57
+ * @return {boolean} True if the character is a separator or end of the ID.
58
+ * @private
59
+ */
60
+ function isBoundary(id, index) {
61
+ return id.charAt(index) === SEPARATOR || index === id.length;
62
+ }
63
+
64
+ /**
65
+ * Checks if the supplied string is a valid React DOM ID.
66
+ *
67
+ * @param {string} id A React DOM ID, maybe.
68
+ * @return {boolean} True if the string is a valid React DOM ID.
69
+ * @private
70
+ */
71
+ function isValidID(id) {
72
+ return id === '' || (
73
+ id.charAt(0) === SEPARATOR && id.charAt(id.length - 1) !== SEPARATOR
74
+ );
75
+ }
76
+
77
+ /**
78
+ * Checks if the first ID is an ancestor of or equal to the second ID.
79
+ *
80
+ * @param {string} ancestorID
81
+ * @param {string} descendantID
82
+ * @return {boolean} True if `ancestorID` is an ancestor of `descendantID`.
83
+ * @internal
84
+ */
85
+ function isAncestorIDOf(ancestorID, descendantID) {
86
+ return (
87
+ descendantID.indexOf(ancestorID) === 0 &&
88
+ isBoundary(descendantID, ancestorID.length)
89
+ );
90
+ }
91
+
92
+ /**
93
+ * Gets the parent ID of the supplied React DOM ID, `id`.
94
+ *
95
+ * @param {string} id ID of a component.
96
+ * @return {string} ID of the parent, or an empty string.
97
+ * @private
98
+ */
99
+ function getParentID(id) {
100
+ return id ? id.substr(0, id.lastIndexOf(SEPARATOR)) : '';
101
+ }
102
+
103
+ /**
104
+ * Gets the next DOM ID on the tree path from the supplied `ancestorID` to the
105
+ * supplied `destinationID`. If they are equal, the ID is returned.
106
+ *
107
+ * @param {string} ancestorID ID of an ancestor node of `destinationID`.
108
+ * @param {string} destinationID ID of the destination node.
109
+ * @return {string} Next ID on the path from `ancestorID` to `destinationID`.
110
+ * @private
111
+ */
112
+ function getNextDescendantID(ancestorID, destinationID) {
113
+ ("production" !== process.env.NODE_ENV ? invariant(
114
+ isValidID(ancestorID) && isValidID(destinationID),
115
+ 'getNextDescendantID(%s, %s): Received an invalid React DOM ID.',
116
+ ancestorID,
117
+ destinationID
118
+ ) : invariant(isValidID(ancestorID) && isValidID(destinationID)));
119
+ ("production" !== process.env.NODE_ENV ? invariant(
120
+ isAncestorIDOf(ancestorID, destinationID),
121
+ 'getNextDescendantID(...): React has made an invalid assumption about ' +
122
+ 'the DOM hierarchy. Expected `%s` to be an ancestor of `%s`.',
123
+ ancestorID,
124
+ destinationID
125
+ ) : invariant(isAncestorIDOf(ancestorID, destinationID)));
126
+ if (ancestorID === destinationID) {
127
+ return ancestorID;
128
+ }
129
+ // Skip over the ancestor and the immediate separator. Traverse until we hit
130
+ // another separator or we reach the end of `destinationID`.
131
+ var start = ancestorID.length + SEPARATOR_LENGTH;
132
+ for (var i = start; i < destinationID.length; i++) {
133
+ if (isBoundary(destinationID, i)) {
134
+ break;
135
+ }
136
+ }
137
+ return destinationID.substr(0, i);
138
+ }
139
+
140
+ /**
141
+ * Gets the nearest common ancestor ID of two IDs.
142
+ *
143
+ * Using this ID scheme, the nearest common ancestor ID is the longest common
144
+ * prefix of the two IDs that immediately preceded a "marker" in both strings.
145
+ *
146
+ * @param {string} oneID
147
+ * @param {string} twoID
148
+ * @return {string} Nearest common ancestor ID, or the empty string if none.
149
+ * @private
150
+ */
151
+ function getFirstCommonAncestorID(oneID, twoID) {
152
+ var minLength = Math.min(oneID.length, twoID.length);
153
+ if (minLength === 0) {
154
+ return '';
155
+ }
156
+ var lastCommonMarkerIndex = 0;
157
+ // Use `<=` to traverse until the "EOL" of the shorter string.
158
+ for (var i = 0; i <= minLength; i++) {
159
+ if (isBoundary(oneID, i) && isBoundary(twoID, i)) {
160
+ lastCommonMarkerIndex = i;
161
+ } else if (oneID.charAt(i) !== twoID.charAt(i)) {
162
+ break;
163
+ }
164
+ }
165
+ var longestCommonID = oneID.substr(0, lastCommonMarkerIndex);
166
+ ("production" !== process.env.NODE_ENV ? invariant(
167
+ isValidID(longestCommonID),
168
+ 'getFirstCommonAncestorID(%s, %s): Expected a valid React DOM ID: %s',
169
+ oneID,
170
+ twoID,
171
+ longestCommonID
172
+ ) : invariant(isValidID(longestCommonID)));
173
+ return longestCommonID;
174
+ }
175
+
176
+ /**
177
+ * Traverses the parent path between two IDs (either up or down). The IDs must
178
+ * not be the same, and there must exist a parent path between them.
179
+ *
180
+ * @param {?string} start ID at which to start traversal.
181
+ * @param {?string} stop ID at which to end traversal.
182
+ * @param {function} cb Callback to invoke each ID with.
183
+ * @param {?boolean} skipFirst Whether or not to skip the first node.
184
+ * @param {?boolean} skipLast Whether or not to skip the last node.
185
+ * @private
186
+ */
187
+ function traverseParentPath(start, stop, cb, arg, skipFirst, skipLast) {
188
+ start = start || '';
189
+ stop = stop || '';
190
+ ("production" !== process.env.NODE_ENV ? invariant(
191
+ start !== stop,
192
+ 'traverseParentPath(...): Cannot traverse from and to the same ID, `%s`.',
193
+ start
194
+ ) : invariant(start !== stop));
195
+ var traverseUp = isAncestorIDOf(stop, start);
196
+ ("production" !== process.env.NODE_ENV ? invariant(
197
+ traverseUp || isAncestorIDOf(start, stop),
198
+ 'traverseParentPath(%s, %s, ...): Cannot traverse from two IDs that do ' +
199
+ 'not have a parent path.',
200
+ start,
201
+ stop
202
+ ) : invariant(traverseUp || isAncestorIDOf(start, stop)));
203
+ // Traverse from `start` to `stop` one depth at a time.
204
+ var depth = 0;
205
+ var traverse = traverseUp ? getParentID : getNextDescendantID;
206
+ for (var id = start; /* until break */; id = traverse(id, stop)) {
207
+ if ((!skipFirst || id !== start) && (!skipLast || id !== stop)) {
208
+ cb(id, traverseUp, arg);
209
+ }
210
+ if (id === stop) {
211
+ // Only break //after// visiting `stop`.
212
+ break;
213
+ }
214
+ ("production" !== process.env.NODE_ENV ? invariant(
215
+ depth++ < MAX_TREE_DEPTH,
216
+ 'traverseParentPath(%s, %s, ...): Detected an infinite loop while ' +
217
+ 'traversing the React DOM ID tree. This may be due to malformed IDs: %s',
218
+ start, stop
219
+ ) : invariant(depth++ < MAX_TREE_DEPTH));
220
+ }
221
+ }
222
+
223
+ /**
224
+ * Manages the IDs assigned to DOM representations of React components. This
225
+ * uses a specific scheme in order to traverse the DOM efficiently (e.g. in
226
+ * order to simulate events).
227
+ *
228
+ * @internal
229
+ */
230
+ var ReactInstanceHandles = {
231
+
232
+ createReactRootID: function() {
233
+ return getReactRootIDString(
234
+ Math.ceil(Math.random() * GLOBAL_MOUNT_POINT_MAX)
235
+ );
236
+ },
237
+
238
+ /**
239
+ * Constructs a React ID by joining a root ID with a name.
240
+ *
241
+ * @param {string} rootID Root ID of a parent component.
242
+ * @param {string} name A component's name (as flattened children).
243
+ * @return {string} A React ID.
244
+ * @internal
245
+ */
246
+ createReactID: function(rootID, name) {
247
+ return rootID + SEPARATOR + name;
248
+ },
249
+
250
+ /**
251
+ * Gets the DOM ID of the React component that is the root of the tree that
252
+ * contains the React component with the supplied DOM ID.
253
+ *
254
+ * @param {string} id DOM ID of a React component.
255
+ * @return {?string} DOM ID of the React component that is the root.
256
+ * @internal
257
+ */
258
+ getReactRootIDFromNodeID: function(id) {
259
+ var regexResult = /\.r\[[^\]]+\]/.exec(id);
260
+ return regexResult && regexResult[0];
261
+ },
262
+
263
+ /**
264
+ * Traverses the ID hierarchy and invokes the supplied `cb` on any IDs that
265
+ * should would receive a `mouseEnter` or `mouseLeave` event.
266
+ *
267
+ * NOTE: Does not invoke the callback on the nearest common ancestor because
268
+ * nothing "entered" or "left" that element.
269
+ *
270
+ * @param {string} leaveID ID being left.
271
+ * @param {string} enterID ID being entered.
272
+ * @param {function} cb Callback to invoke on each entered/left ID.
273
+ * @param {*} upArg Argument to invoke the callback with on left IDs.
274
+ * @param {*} downArg Argument to invoke the callback with on entered IDs.
275
+ * @internal
276
+ */
277
+ traverseEnterLeave: function(leaveID, enterID, cb, upArg, downArg) {
278
+ var ancestorID = getFirstCommonAncestorID(leaveID, enterID);
279
+ if (ancestorID !== leaveID) {
280
+ traverseParentPath(leaveID, ancestorID, cb, upArg, false, true);
281
+ }
282
+ if (ancestorID !== enterID) {
283
+ traverseParentPath(ancestorID, enterID, cb, downArg, true, false);
284
+ }
285
+ },
286
+
287
+ /**
288
+ * Simulates the traversal of a two-phase, capture/bubble event dispatch.
289
+ *
290
+ * NOTE: This traversal happens on IDs without touching the DOM.
291
+ *
292
+ * @param {string} targetID ID of the target node.
293
+ * @param {function} cb Callback to invoke.
294
+ * @param {*} arg Argument to invoke the callback with.
295
+ * @internal
296
+ */
297
+ traverseTwoPhase: function(targetID, cb, arg) {
298
+ if (targetID) {
299
+ traverseParentPath('', targetID, cb, arg, true, false);
300
+ traverseParentPath(targetID, '', cb, arg, false, true);
301
+ }
302
+ },
303
+
304
+ /**
305
+ * Exposed for unit testing.
306
+ * @private
307
+ */
308
+ _getFirstCommonAncestorID: getFirstCommonAncestorID,
309
+
310
+ /**
311
+ * Exposed for unit testing.
312
+ * @private
313
+ */
314
+ _getNextDescendantID: getNextDescendantID,
315
+
316
+ isAncestorIDOf: isAncestorIDOf,
317
+
318
+ SEPARATOR: SEPARATOR
319
+
320
+ };
321
+
322
+ module.exports = ReactInstanceHandles;