react 0.7.0 → 0.9.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 (217) hide show
  1. package/README.md +10 -231
  2. package/addons.js +1 -0
  3. package/lib/AutoFocusMixin.js +30 -0
  4. package/lib/CSSCore.js +115 -0
  5. package/lib/CSSProperty.js +121 -0
  6. package/lib/CSSPropertyOperations.js +97 -0
  7. package/lib/ChangeEventPlugin.js +387 -0
  8. package/lib/ClientReactRootIndex.js +30 -0
  9. package/lib/CompositionEventPlugin.js +260 -0
  10. package/lib/DOMChildrenOperations.js +165 -0
  11. package/lib/DOMProperty.js +268 -0
  12. package/lib/DOMPropertyOperations.js +181 -0
  13. package/lib/Danger.js +187 -0
  14. package/lib/DefaultDOMPropertyConfig.js +203 -0
  15. package/lib/DefaultEventPluginOrder.js +44 -0
  16. package/lib/EnterLeaveEventPlugin.js +145 -0
  17. package/lib/EventConstants.js +76 -0
  18. package/lib/EventListener.js +69 -0
  19. package/lib/EventPluginHub.js +293 -0
  20. package/lib/EventPluginRegistry.js +281 -0
  21. package/lib/EventPluginUtils.js +214 -0
  22. package/lib/EventPropagators.js +143 -0
  23. package/lib/ExecutionEnvironment.js +44 -0
  24. package/lib/LinkedStateMixin.js +46 -0
  25. package/lib/LinkedValueUtils.js +161 -0
  26. package/lib/MobileSafariClickEventPlugin.js +63 -0
  27. package/lib/PooledClass.js +119 -0
  28. package/lib/React.js +95 -0
  29. package/lib/ReactCSSTransitionGroup.js +65 -0
  30. package/lib/ReactCSSTransitionGroupChild.js +138 -0
  31. package/lib/ReactChildren.js +132 -0
  32. package/lib/ReactComponent.js +550 -0
  33. package/lib/ReactComponentBrowserEnvironment.js +158 -0
  34. package/lib/ReactComponentEnvironment.js +26 -0
  35. package/lib/ReactCompositeComponent.js +1455 -0
  36. package/lib/ReactContext.js +67 -0
  37. package/lib/ReactCurrentOwner.js +39 -0
  38. package/lib/ReactDOM.js +207 -0
  39. package/lib/ReactDOMButton.js +68 -0
  40. package/lib/ReactDOMComponent.js +399 -0
  41. package/lib/ReactDOMForm.js +59 -0
  42. package/lib/ReactDOMIDOperations.js +218 -0
  43. package/lib/ReactDOMImg.js +58 -0
  44. package/lib/ReactDOMInput.js +181 -0
  45. package/lib/ReactDOMOption.js +51 -0
  46. package/lib/ReactDOMSelect.js +179 -0
  47. package/lib/ReactDOMSelection.js +189 -0
  48. package/lib/ReactDOMTextarea.js +140 -0
  49. package/lib/ReactDefaultBatchingStrategy.js +75 -0
  50. package/lib/ReactDefaultInjection.js +115 -0
  51. package/lib/ReactDefaultPerf.js +244 -0
  52. package/lib/ReactDefaultPerfAnalysis.js +199 -0
  53. package/lib/ReactErrorUtils.js +37 -0
  54. package/lib/ReactEventEmitter.js +339 -0
  55. package/lib/ReactEventEmitterMixin.js +57 -0
  56. package/lib/ReactEventTopLevelCallback.js +149 -0
  57. package/lib/ReactInjection.js +39 -0
  58. package/lib/ReactInputSelection.js +140 -0
  59. package/lib/ReactInstanceHandles.js +338 -0
  60. package/lib/ReactLink.js +54 -0
  61. package/lib/ReactMarkupChecksum.js +53 -0
  62. package/lib/ReactMount.js +641 -0
  63. package/lib/ReactMountReady.js +95 -0
  64. package/lib/ReactMultiChild.js +425 -0
  65. package/lib/ReactMultiChildUpdateTypes.js +38 -0
  66. package/lib/ReactOwner.js +154 -0
  67. package/lib/ReactPerf.js +85 -0
  68. package/lib/ReactPropTransferer.js +147 -0
  69. package/lib/ReactPropTypeLocationNames.js +31 -0
  70. package/lib/ReactPropTypeLocations.js +29 -0
  71. package/lib/ReactPropTypes.js +359 -0
  72. package/lib/ReactPutListenerQueue.js +61 -0
  73. package/lib/ReactReconcileTransaction.js +181 -0
  74. package/lib/ReactRootIndex.js +36 -0
  75. package/lib/ReactServerRendering.js +59 -0
  76. package/lib/ReactStateSetters.js +111 -0
  77. package/lib/ReactTestUtils.js +394 -0
  78. package/lib/ReactTextComponent.js +99 -0
  79. package/lib/ReactTransitionChildMapping.js +106 -0
  80. package/lib/ReactTransitionEvents.js +97 -0
  81. package/lib/ReactTransitionGroup.js +187 -0
  82. package/lib/ReactUpdates.js +148 -0
  83. package/lib/ReactWithAddons.js +51 -0
  84. package/lib/SelectEventPlugin.js +200 -0
  85. package/lib/ServerReactRootIndex.js +36 -0
  86. package/lib/SimpleEventPlugin.js +413 -0
  87. package/lib/SyntheticClipboardEvent.js +51 -0
  88. package/lib/SyntheticCompositionEvent.js +51 -0
  89. package/lib/SyntheticDragEvent.js +44 -0
  90. package/lib/SyntheticEvent.js +164 -0
  91. package/lib/SyntheticFocusEvent.js +44 -0
  92. package/lib/SyntheticKeyboardEvent.js +58 -0
  93. package/lib/SyntheticMouseEvent.js +85 -0
  94. package/lib/SyntheticTouchEvent.js +50 -0
  95. package/lib/SyntheticUIEvent.js +45 -0
  96. package/lib/SyntheticWheelEvent.js +66 -0
  97. package/lib/Transaction.js +276 -0
  98. package/lib/ViewportMetrics.js +37 -0
  99. package/lib/accumulate.js +54 -0
  100. package/lib/adler32.js +39 -0
  101. package/lib/cloneWithProps.js +59 -0
  102. package/lib/containsNode.js +49 -0
  103. package/lib/copyProperties.js +54 -0
  104. package/lib/createArrayFrom.js +91 -0
  105. package/lib/createFullPageComponent.js +63 -0
  106. package/lib/createNodesFromMarkup.js +93 -0
  107. package/lib/createObjectFrom.js +61 -0
  108. package/lib/cx.js +44 -0
  109. package/lib/dangerousStyleValue.js +57 -0
  110. package/lib/emptyFunction.js +43 -0
  111. package/lib/escapeTextForBrowser.js +47 -0
  112. package/lib/flattenChildren.js +57 -0
  113. package/lib/forEachAccumulated.js +36 -0
  114. package/lib/getActiveElement.js +34 -0
  115. package/lib/getEventKey.js +85 -0
  116. package/lib/getEventTarget.js +36 -0
  117. package/lib/getMarkupWrap.js +118 -0
  118. package/lib/getNodeForCharacterOffset.js +80 -0
  119. package/lib/getReactRootElementInContainer.js +40 -0
  120. package/lib/getTextContentAccessor.js +42 -0
  121. package/lib/getUnboundedScrollPosition.js +45 -0
  122. package/lib/hyphenate.js +35 -0
  123. package/lib/invariant.js +62 -0
  124. package/lib/isEventSupported.js +70 -0
  125. package/lib/isNode.js +33 -0
  126. package/lib/isTextInputElement.js +49 -0
  127. package/lib/isTextNode.js +30 -0
  128. package/lib/joinClasses.js +44 -0
  129. package/lib/keyMirror.js +58 -0
  130. package/lib/keyOf.js +41 -0
  131. package/lib/memoizeStringOnly.js +39 -0
  132. package/lib/merge.js +37 -0
  133. package/lib/mergeHelpers.js +136 -0
  134. package/lib/mergeInto.js +45 -0
  135. package/lib/mixInto.js +34 -0
  136. package/lib/objMap.js +47 -0
  137. package/lib/objMapKeyVal.js +47 -0
  138. package/lib/onlyChild.js +43 -0
  139. package/lib/performanceNow.js +42 -0
  140. package/lib/shallowEqual.js +49 -0
  141. package/lib/shouldUpdateReactComponent.js +58 -0
  142. package/lib/toArray.js +75 -0
  143. package/lib/traverseAllChildren.js +189 -0
  144. package/lib/warning.js +48 -0
  145. package/package.json +33 -21
  146. package/react.js +1 -0
  147. package/.npmignore +0 -7
  148. package/.travis.yml +0 -7
  149. package/Jakefile.js +0 -39
  150. package/LICENSE +0 -19
  151. package/browser-test/dist.html +0 -90
  152. package/browser-test/index.html +0 -86
  153. package/browser-test/min.html +0 -90
  154. package/dist/react.js +0 -3141
  155. package/dist/react.min.js +0 -22
  156. package/doc/advanced.md +0 -174
  157. package/doc/color-def.graffle +0 -938
  158. package/doc/color-def.png +0 -0
  159. package/doc/simple.dot +0 -25
  160. package/doc/simple.png +0 -0
  161. package/examples/longer-example.js +0 -41
  162. package/examples/simple.js +0 -45
  163. package/examples/using-ast-directly.js +0 -30
  164. package/examples/using-events1.js +0 -79
  165. package/examples/using-log-events.js +0 -43
  166. package/lib/base-task.js +0 -120
  167. package/lib/cb-task.js +0 -84
  168. package/lib/core.js +0 -138
  169. package/lib/dsl.js +0 -138
  170. package/lib/error.js +0 -55
  171. package/lib/event-collector.js +0 -81
  172. package/lib/event-manager.js +0 -89
  173. package/lib/eventemitter.js +0 -20
  174. package/lib/finalcb-first-task.js +0 -68
  175. package/lib/finalcb-task.js +0 -65
  176. package/lib/id.js +0 -22
  177. package/lib/input-parser.js +0 -56
  178. package/lib/log-events.js +0 -101
  179. package/lib/parse.js +0 -41
  180. package/lib/promise-resolve.js +0 -50
  181. package/lib/promise-task.js +0 -93
  182. package/lib/react.js +0 -59
  183. package/lib/ret-task.js +0 -71
  184. package/lib/sprintf.js +0 -18
  185. package/lib/status.js +0 -14
  186. package/lib/task.js +0 -251
  187. package/lib/track-tasks.js +0 -74
  188. package/lib/validate.js +0 -159
  189. package/lib/vcon.js +0 -113
  190. package/lib/when-task.js +0 -84
  191. package/src/dist.build.requirejs +0 -20
  192. package/test/ast.mocha.js +0 -136
  193. package/test/cb-task.mocha.js +0 -220
  194. package/test/core-deferred.mocha.js +0 -143
  195. package/test/core-when.mocha.js +0 -96
  196. package/test/core.mocha.js +0 -589
  197. package/test/dsl.mocha.js +0 -352
  198. package/test/event-manager.mocha.js +0 -119
  199. package/test/exec-options.mocha.js +0 -48
  200. package/test/finalcb-task.mocha.js +0 -58
  201. package/test/input-parser.mocha.js +0 -86
  202. package/test/log-events.mocha.js +0 -88
  203. package/test/mocha.opts +0 -2
  204. package/test/module-use.mocha.js +0 -164
  205. package/test/promise-auto-resolve.mocha.js +0 -68
  206. package/test/ret-task.mocha.js +0 -220
  207. package/test/task.mocha.js +0 -42
  208. package/test/validate-cb-task.mocha.js +0 -100
  209. package/test/validate-ret-task.mocha.js +0 -110
  210. package/test/validate.mocha.js +0 -324
  211. package/test/vcon.mocha.js +0 -193
  212. package/vendor/chai/chai.js +0 -4251
  213. package/vendor/jquery/jquery-1.7.1.js +0 -9266
  214. package/vendor/jquery/jquery-1.7.1.min.js +0 -4
  215. package/vendor/node/util.js +0 -531
  216. package/vendor/requirejs/require.js +0 -2045
  217. package/vendor/requirejs/require.min.js +0 -36
@@ -0,0 +1,59 @@
1
+ /**
2
+ * Copyright 2013-2014 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 ReactDOMForm
17
+ */
18
+
19
+ "use strict";
20
+
21
+ var ReactCompositeComponent = require("./ReactCompositeComponent");
22
+ var ReactDOM = require("./ReactDOM");
23
+ var ReactEventEmitter = require("./ReactEventEmitter");
24
+ var EventConstants = require("./EventConstants");
25
+
26
+ // Store a reference to the <form> `ReactDOMComponent`.
27
+ var form = ReactDOM.form;
28
+
29
+ /**
30
+ * Since onSubmit doesn't bubble OR capture on the top level in IE8, we need
31
+ * to capture it on the <form> element itself. There are lots of hacks we could
32
+ * do to accomplish this, but the most reliable is to make <form> a
33
+ * composite component and use `componentDidMount` to attach the event handlers.
34
+ */
35
+ var ReactDOMForm = ReactCompositeComponent.createClass({
36
+ displayName: 'ReactDOMForm',
37
+
38
+ render: function() {
39
+ // TODO: Instead of using `ReactDOM` directly, we should use JSX. However,
40
+ // `jshint` fails to parse JSX so in order for linting to work in the open
41
+ // source repo, we need to just use `ReactDOM.form`.
42
+ return this.transferPropsTo(form(null, this.props.children));
43
+ },
44
+
45
+ componentDidMount: function() {
46
+ ReactEventEmitter.trapBubbledEvent(
47
+ EventConstants.topLevelTypes.topReset,
48
+ 'reset',
49
+ this.getDOMNode()
50
+ );
51
+ ReactEventEmitter.trapBubbledEvent(
52
+ EventConstants.topLevelTypes.topSubmit,
53
+ 'submit',
54
+ this.getDOMNode()
55
+ );
56
+ }
57
+ });
58
+
59
+ module.exports = ReactDOMForm;
@@ -0,0 +1,218 @@
1
+ /**
2
+ * Copyright 2013-2014 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 ReactDOMIDOperations
17
+ * @typechecks static-only
18
+ */
19
+
20
+ /*jslint evil: true */
21
+
22
+ "use strict";
23
+
24
+ var CSSPropertyOperations = require("./CSSPropertyOperations");
25
+ var DOMChildrenOperations = require("./DOMChildrenOperations");
26
+ var DOMPropertyOperations = require("./DOMPropertyOperations");
27
+ var ReactMount = require("./ReactMount");
28
+ var ReactPerf = require("./ReactPerf");
29
+
30
+ var invariant = require("./invariant");
31
+
32
+ /**
33
+ * Errors for properties that should not be updated with `updatePropertyById()`.
34
+ *
35
+ * @type {object}
36
+ * @private
37
+ */
38
+ var INVALID_PROPERTY_ERRORS = {
39
+ dangerouslySetInnerHTML:
40
+ '`dangerouslySetInnerHTML` must be set using `updateInnerHTMLByID()`.',
41
+ style: '`style` must be set using `updateStylesByID()`.'
42
+ };
43
+
44
+ var useWhitespaceWorkaround;
45
+
46
+ /**
47
+ * Operations used to process updates to DOM nodes. This is made injectable via
48
+ * `ReactComponent.BackendIDOperations`.
49
+ */
50
+ var ReactDOMIDOperations = {
51
+
52
+ /**
53
+ * Updates a DOM node with new property values. This should only be used to
54
+ * update DOM properties in `DOMProperty`.
55
+ *
56
+ * @param {string} id ID of the node to update.
57
+ * @param {string} name A valid property name, see `DOMProperty`.
58
+ * @param {*} value New value of the property.
59
+ * @internal
60
+ */
61
+ updatePropertyByID: ReactPerf.measure(
62
+ 'ReactDOMIDOperations',
63
+ 'updatePropertyByID',
64
+ function(id, name, value) {
65
+ var node = ReactMount.getNode(id);
66
+ ("production" !== process.env.NODE_ENV ? invariant(
67
+ !INVALID_PROPERTY_ERRORS.hasOwnProperty(name),
68
+ 'updatePropertyByID(...): %s',
69
+ INVALID_PROPERTY_ERRORS[name]
70
+ ) : invariant(!INVALID_PROPERTY_ERRORS.hasOwnProperty(name)));
71
+
72
+ // If we're updating to null or undefined, we should remove the property
73
+ // from the DOM node instead of inadvertantly setting to a string. This
74
+ // brings us in line with the same behavior we have on initial render.
75
+ if (value != null) {
76
+ DOMPropertyOperations.setValueForProperty(node, name, value);
77
+ } else {
78
+ DOMPropertyOperations.deleteValueForProperty(node, name);
79
+ }
80
+ }
81
+ ),
82
+
83
+ /**
84
+ * Updates a DOM node to remove a property. This should only be used to remove
85
+ * DOM properties in `DOMProperty`.
86
+ *
87
+ * @param {string} id ID of the node to update.
88
+ * @param {string} name A property name to remove, see `DOMProperty`.
89
+ * @internal
90
+ */
91
+ deletePropertyByID: ReactPerf.measure(
92
+ 'ReactDOMIDOperations',
93
+ 'deletePropertyByID',
94
+ function(id, name, value) {
95
+ var node = ReactMount.getNode(id);
96
+ ("production" !== process.env.NODE_ENV ? invariant(
97
+ !INVALID_PROPERTY_ERRORS.hasOwnProperty(name),
98
+ 'updatePropertyByID(...): %s',
99
+ INVALID_PROPERTY_ERRORS[name]
100
+ ) : invariant(!INVALID_PROPERTY_ERRORS.hasOwnProperty(name)));
101
+ DOMPropertyOperations.deleteValueForProperty(node, name, value);
102
+ }
103
+ ),
104
+
105
+ /**
106
+ * Updates a DOM node with new style values. If a value is specified as '',
107
+ * the corresponding style property will be unset.
108
+ *
109
+ * @param {string} id ID of the node to update.
110
+ * @param {object} styles Mapping from styles to values.
111
+ * @internal
112
+ */
113
+ updateStylesByID: ReactPerf.measure(
114
+ 'ReactDOMIDOperations',
115
+ 'updateStylesByID',
116
+ function(id, styles) {
117
+ var node = ReactMount.getNode(id);
118
+ CSSPropertyOperations.setValueForStyles(node, styles);
119
+ }
120
+ ),
121
+
122
+ /**
123
+ * Updates a DOM node's innerHTML.
124
+ *
125
+ * @param {string} id ID of the node to update.
126
+ * @param {string} html An HTML string.
127
+ * @internal
128
+ */
129
+ updateInnerHTMLByID: ReactPerf.measure(
130
+ 'ReactDOMIDOperations',
131
+ 'updateInnerHTMLByID',
132
+ function(id, html) {
133
+ var node = ReactMount.getNode(id);
134
+
135
+ // IE8: When updating a just created node with innerHTML only leading
136
+ // whitespace is removed. When updating an existing node with innerHTML
137
+ // whitespace in root TextNodes is also collapsed.
138
+ // @see quirksmode.org/bugreports/archives/2004/11/innerhtml_and_t.html
139
+
140
+ if (useWhitespaceWorkaround === undefined) {
141
+ // Feature detection; only IE8 is known to behave improperly like this.
142
+ var temp = document.createElement('div');
143
+ temp.innerHTML = ' ';
144
+ useWhitespaceWorkaround = temp.innerHTML === '';
145
+ }
146
+
147
+ if (useWhitespaceWorkaround) {
148
+ // Magic theory: IE8 supposedly differentiates between added and updated
149
+ // nodes when processing innerHTML, innerHTML on updated nodes suffers
150
+ // from worse whitespace behavior. Re-adding a node like this triggers
151
+ // the initial and more favorable whitespace behavior.
152
+ node.parentNode.replaceChild(node, node);
153
+ }
154
+
155
+ if (useWhitespaceWorkaround && html.match(/^[ \r\n\t\f]/)) {
156
+ // Recover leading whitespace by temporarily prepending any character.
157
+ // \uFEFF has the potential advantage of being zero-width/invisible.
158
+ node.innerHTML = '\uFEFF' + html;
159
+ node.firstChild.deleteData(0, 1);
160
+ } else {
161
+ node.innerHTML = html;
162
+ }
163
+ }
164
+ ),
165
+
166
+ /**
167
+ * Updates a DOM node's text content set by `props.content`.
168
+ *
169
+ * @param {string} id ID of the node to update.
170
+ * @param {string} content Text content.
171
+ * @internal
172
+ */
173
+ updateTextContentByID: ReactPerf.measure(
174
+ 'ReactDOMIDOperations',
175
+ 'updateTextContentByID',
176
+ function(id, content) {
177
+ var node = ReactMount.getNode(id);
178
+ DOMChildrenOperations.updateTextContent(node, content);
179
+ }
180
+ ),
181
+
182
+ /**
183
+ * Replaces a DOM node that exists in the document with markup.
184
+ *
185
+ * @param {string} id ID of child to be replaced.
186
+ * @param {string} markup Dangerous markup to inject in place of child.
187
+ * @internal
188
+ * @see {Danger.dangerouslyReplaceNodeWithMarkup}
189
+ */
190
+ dangerouslyReplaceNodeWithMarkupByID: ReactPerf.measure(
191
+ 'ReactDOMIDOperations',
192
+ 'dangerouslyReplaceNodeWithMarkupByID',
193
+ function(id, markup) {
194
+ var node = ReactMount.getNode(id);
195
+ DOMChildrenOperations.dangerouslyReplaceNodeWithMarkup(node, markup);
196
+ }
197
+ ),
198
+
199
+ /**
200
+ * Updates a component's children by processing a series of updates.
201
+ *
202
+ * @param {array<object>} updates List of update configurations.
203
+ * @param {array<string>} markup List of markup strings.
204
+ * @internal
205
+ */
206
+ dangerouslyProcessChildrenUpdates: ReactPerf.measure(
207
+ 'ReactDOMIDOperations',
208
+ 'dangerouslyProcessChildrenUpdates',
209
+ function(updates, markup) {
210
+ for (var i = 0; i < updates.length; i++) {
211
+ updates[i].parentNode = ReactMount.getNode(updates[i].parentID);
212
+ }
213
+ DOMChildrenOperations.processUpdates(updates, markup);
214
+ }
215
+ )
216
+ };
217
+
218
+ module.exports = ReactDOMIDOperations;
@@ -0,0 +1,58 @@
1
+ /**
2
+ * Copyright 2013-2014 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 ReactDOMImg
17
+ */
18
+
19
+ "use strict";
20
+
21
+ var ReactCompositeComponent = require("./ReactCompositeComponent");
22
+ var ReactDOM = require("./ReactDOM");
23
+ var ReactEventEmitter = require("./ReactEventEmitter");
24
+ var EventConstants = require("./EventConstants");
25
+
26
+ // Store a reference to the <img> `ReactDOMComponent`.
27
+ var img = ReactDOM.img;
28
+
29
+ /**
30
+ * Since onLoad doesn't bubble OR capture on the top level in IE8, we need to
31
+ * capture it on the <img> element itself. There are lots of hacks we could do
32
+ * to accomplish this, but the most reliable is to make <img> a composite
33
+ * component and use `componentDidMount` to attach the event handlers.
34
+ */
35
+ var ReactDOMImg = ReactCompositeComponent.createClass({
36
+ displayName: 'ReactDOMImg',
37
+ tagName: 'IMG',
38
+
39
+ render: function() {
40
+ return img(this.props);
41
+ },
42
+
43
+ componentDidMount: function() {
44
+ var node = this.getDOMNode();
45
+ ReactEventEmitter.trapBubbledEvent(
46
+ EventConstants.topLevelTypes.topLoad,
47
+ 'load',
48
+ node
49
+ );
50
+ ReactEventEmitter.trapBubbledEvent(
51
+ EventConstants.topLevelTypes.topError,
52
+ 'error',
53
+ node
54
+ );
55
+ }
56
+ });
57
+
58
+ module.exports = ReactDOMImg;
@@ -0,0 +1,181 @@
1
+ /**
2
+ * Copyright 2013-2014 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 ReactDOMInput
17
+ */
18
+
19
+ "use strict";
20
+
21
+ var AutoFocusMixin = require("./AutoFocusMixin");
22
+ var DOMPropertyOperations = require("./DOMPropertyOperations");
23
+ var LinkedValueUtils = require("./LinkedValueUtils");
24
+ var ReactCompositeComponent = require("./ReactCompositeComponent");
25
+ var ReactDOM = require("./ReactDOM");
26
+ var ReactMount = require("./ReactMount");
27
+
28
+ var invariant = require("./invariant");
29
+ var merge = require("./merge");
30
+
31
+ // Store a reference to the <input> `ReactDOMComponent`.
32
+ var input = ReactDOM.input;
33
+
34
+ var instancesByReactID = {};
35
+
36
+ /**
37
+ * Implements an <input> native component that allows setting these optional
38
+ * props: `checked`, `value`, `defaultChecked`, and `defaultValue`.
39
+ *
40
+ * If `checked` or `value` are not supplied (or null/undefined), user actions
41
+ * that affect the checked state or value will trigger updates to the element.
42
+ *
43
+ * If they are supplied (and not null/undefined), the rendered element will not
44
+ * trigger updates to the element. Instead, the props must change in order for
45
+ * the rendered element to be updated.
46
+ *
47
+ * The rendered element will be initialized as unchecked (or `defaultChecked`)
48
+ * with an empty value (or `defaultValue`).
49
+ *
50
+ * @see http://www.w3.org/TR/2012/WD-html5-20121025/the-input-element.html
51
+ */
52
+ var ReactDOMInput = ReactCompositeComponent.createClass({
53
+ displayName: 'ReactDOMInput',
54
+
55
+ mixins: [AutoFocusMixin, LinkedValueUtils.Mixin],
56
+
57
+ getInitialState: function() {
58
+ var defaultValue = this.props.defaultValue;
59
+ return {
60
+ checked: this.props.defaultChecked || false,
61
+ value: defaultValue != null ? defaultValue : null
62
+ };
63
+ },
64
+
65
+ shouldComponentUpdate: function() {
66
+ // Defer any updates to this component during the `onChange` handler.
67
+ return !this._isChanging;
68
+ },
69
+
70
+ render: function() {
71
+ // Clone `this.props` so we don't mutate the input.
72
+ var props = merge(this.props);
73
+
74
+ props.defaultChecked = null;
75
+ props.defaultValue = null;
76
+
77
+ var value = LinkedValueUtils.getValue(this);
78
+ props.value = value != null ? value : this.state.value;
79
+
80
+ var checked = LinkedValueUtils.getChecked(this);
81
+ props.checked = checked != null ? checked : this.state.checked;
82
+
83
+ props.onChange = this._handleChange;
84
+
85
+ return input(props, this.props.children);
86
+ },
87
+
88
+ componentDidMount: function() {
89
+ var id = ReactMount.getID(this.getDOMNode());
90
+ instancesByReactID[id] = this;
91
+ },
92
+
93
+ componentWillUnmount: function() {
94
+ var rootNode = this.getDOMNode();
95
+ var id = ReactMount.getID(rootNode);
96
+ delete instancesByReactID[id];
97
+ },
98
+
99
+ componentDidUpdate: function(prevProps, prevState, prevContext) {
100
+ var rootNode = this.getDOMNode();
101
+ if (this.props.checked != null) {
102
+ DOMPropertyOperations.setValueForProperty(
103
+ rootNode,
104
+ 'checked',
105
+ this.props.checked || false
106
+ );
107
+ }
108
+
109
+ var value = LinkedValueUtils.getValue(this);
110
+ if (value != null) {
111
+ // Cast `value` to a string to ensure the value is set correctly. While
112
+ // browsers typically do this as necessary, jsdom doesn't.
113
+ DOMPropertyOperations.setValueForProperty(rootNode, 'value', '' + value);
114
+ }
115
+ },
116
+
117
+ _handleChange: function(event) {
118
+ var returnValue;
119
+ var onChange = LinkedValueUtils.getOnChange(this);
120
+ if (onChange) {
121
+ this._isChanging = true;
122
+ returnValue = onChange.call(this, event);
123
+ this._isChanging = false;
124
+ }
125
+ this.setState({
126
+ checked: event.target.checked,
127
+ value: event.target.value
128
+ });
129
+
130
+ var name = this.props.name;
131
+ if (this.props.type === 'radio' && name != null) {
132
+ var rootNode = this.getDOMNode();
133
+ var queryRoot = rootNode;
134
+
135
+ while (queryRoot.parentNode) {
136
+ queryRoot = queryRoot.parentNode;
137
+ }
138
+
139
+ // If `rootNode.form` was non-null, then we could try `form.elements`,
140
+ // but that sometimes behaves strangely in IE8. We could also try using
141
+ // `form.getElementsByName`, but that will only return direct children
142
+ // and won't include inputs that use the HTML5 `form=` attribute. Since
143
+ // the input might not even be in a form, let's just use the global
144
+ // `querySelectorAll` to ensure we don't miss anything.
145
+ var group = queryRoot.querySelectorAll(
146
+ 'input[name=' + JSON.stringify('' + name) + '][type="radio"]');
147
+
148
+ for (var i = 0, groupLen = group.length; i < groupLen; i++) {
149
+ var otherNode = group[i];
150
+ if (otherNode === rootNode ||
151
+ otherNode.form !== rootNode.form) {
152
+ continue;
153
+ }
154
+ var otherID = ReactMount.getID(otherNode);
155
+ ("production" !== process.env.NODE_ENV ? invariant(
156
+ otherID,
157
+ 'ReactDOMInput: Mixing React and non-React radio inputs with the ' +
158
+ 'same `name` is not supported.'
159
+ ) : invariant(otherID));
160
+ var otherInstance = instancesByReactID[otherID];
161
+ ("production" !== process.env.NODE_ENV ? invariant(
162
+ otherInstance,
163
+ 'ReactDOMInput: Unknown radio button ID %s.',
164
+ otherID
165
+ ) : invariant(otherInstance));
166
+ // In some cases, this will actually change the `checked` state value.
167
+ // In other cases, there's no change but this forces a reconcile upon
168
+ // which componentDidUpdate will reset the DOM property to whatever it
169
+ // should be.
170
+ otherInstance.setState({
171
+ checked: false
172
+ });
173
+ }
174
+ }
175
+
176
+ return returnValue;
177
+ }
178
+
179
+ });
180
+
181
+ module.exports = ReactDOMInput;