react 0.7.1 → 0.10.0-rc1

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 (223) hide show
  1. package/README.md +10 -231
  2. package/addons.js +1 -0
  3. package/lib/AutoFocusMixin.js +32 -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 +171 -0
  11. package/lib/DOMProperty.js +270 -0
  12. package/lib/DOMPropertyOperations.js +181 -0
  13. package/lib/Danger.js +187 -0
  14. package/lib/DefaultDOMPropertyConfig.js +196 -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 +295 -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 +160 -0
  26. package/lib/MobileSafariClickEventPlugin.js +63 -0
  27. package/lib/PooledClass.js +119 -0
  28. package/lib/React.js +97 -0
  29. package/lib/ReactBrowserComponentMixin.js +42 -0
  30. package/lib/ReactCSSTransitionGroup.js +65 -0
  31. package/lib/ReactCSSTransitionGroupChild.js +138 -0
  32. package/lib/ReactChildren.js +132 -0
  33. package/lib/ReactComponent.js +595 -0
  34. package/lib/ReactComponentBrowserEnvironment.js +124 -0
  35. package/lib/ReactCompositeComponent.js +1587 -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 +69 -0
  40. package/lib/ReactDOMComponent.js +416 -0
  41. package/lib/ReactDOMForm.js +62 -0
  42. package/lib/ReactDOMIDOperations.js +218 -0
  43. package/lib/ReactDOMImg.js +61 -0
  44. package/lib/ReactDOMInput.js +182 -0
  45. package/lib/ReactDOMOption.js +55 -0
  46. package/lib/ReactDOMSelect.js +180 -0
  47. package/lib/ReactDOMSelection.js +189 -0
  48. package/lib/ReactDOMTextarea.js +144 -0
  49. package/lib/ReactDefaultBatchingStrategy.js +75 -0
  50. package/lib/ReactDefaultInjection.js +125 -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 +43 -0
  58. package/lib/ReactInputSelection.js +141 -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 +649 -0
  63. package/lib/ReactMountReady.js +95 -0
  64. package/lib/ReactMultiChild.js +432 -0
  65. package/lib/ReactMultiChildUpdateTypes.js +38 -0
  66. package/lib/ReactOwner.js +159 -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 +182 -0
  74. package/lib/ReactRootIndex.js +36 -0
  75. package/lib/ReactServerRendering.js +89 -0
  76. package/lib/ReactServerRenderingTransaction.js +116 -0
  77. package/lib/ReactStateSetters.js +111 -0
  78. package/lib/ReactTestUtils.js +394 -0
  79. package/lib/ReactTextComponent.js +121 -0
  80. package/lib/ReactTransitionChildMapping.js +106 -0
  81. package/lib/ReactTransitionEvents.js +97 -0
  82. package/lib/ReactTransitionGroup.js +187 -0
  83. package/lib/ReactUpdates.js +148 -0
  84. package/lib/ReactWithAddons.js +53 -0
  85. package/lib/SelectEventPlugin.js +200 -0
  86. package/lib/ServerReactRootIndex.js +36 -0
  87. package/lib/SimpleEventPlugin.js +413 -0
  88. package/lib/SyntheticClipboardEvent.js +51 -0
  89. package/lib/SyntheticCompositionEvent.js +51 -0
  90. package/lib/SyntheticDragEvent.js +44 -0
  91. package/lib/SyntheticEvent.js +164 -0
  92. package/lib/SyntheticFocusEvent.js +44 -0
  93. package/lib/SyntheticKeyboardEvent.js +58 -0
  94. package/lib/SyntheticMouseEvent.js +85 -0
  95. package/lib/SyntheticTouchEvent.js +50 -0
  96. package/lib/SyntheticUIEvent.js +45 -0
  97. package/lib/SyntheticWheelEvent.js +66 -0
  98. package/lib/Transaction.js +276 -0
  99. package/lib/ViewportMetrics.js +37 -0
  100. package/lib/accumulate.js +54 -0
  101. package/lib/adler32.js +39 -0
  102. package/lib/cloneWithProps.js +59 -0
  103. package/lib/containsNode.js +49 -0
  104. package/lib/copyProperties.js +54 -0
  105. package/lib/createArrayFrom.js +91 -0
  106. package/lib/createFullPageComponent.js +63 -0
  107. package/lib/createNodesFromMarkup.js +93 -0
  108. package/lib/createObjectFrom.js +61 -0
  109. package/lib/cx.js +44 -0
  110. package/lib/dangerousStyleValue.js +57 -0
  111. package/lib/emptyFunction.js +43 -0
  112. package/lib/emptyObject.js +27 -0
  113. package/lib/escapeTextForBrowser.js +47 -0
  114. package/lib/flattenChildren.js +57 -0
  115. package/lib/focusNode.js +33 -0
  116. package/lib/forEachAccumulated.js +36 -0
  117. package/lib/getActiveElement.js +34 -0
  118. package/lib/getEventKey.js +85 -0
  119. package/lib/getEventTarget.js +36 -0
  120. package/lib/getMarkupWrap.js +118 -0
  121. package/lib/getNodeForCharacterOffset.js +80 -0
  122. package/lib/getReactRootElementInContainer.js +40 -0
  123. package/lib/getTextContentAccessor.js +42 -0
  124. package/lib/getUnboundedScrollPosition.js +45 -0
  125. package/lib/hyphenate.js +35 -0
  126. package/lib/instantiateReactComponent.js +70 -0
  127. package/lib/invariant.js +62 -0
  128. package/lib/isEventSupported.js +70 -0
  129. package/lib/isNode.js +33 -0
  130. package/lib/isTextInputElement.js +49 -0
  131. package/lib/isTextNode.js +30 -0
  132. package/lib/joinClasses.js +44 -0
  133. package/lib/keyMirror.js +58 -0
  134. package/lib/keyOf.js +41 -0
  135. package/lib/memoizeStringOnly.js +39 -0
  136. package/lib/merge.js +37 -0
  137. package/lib/mergeHelpers.js +136 -0
  138. package/lib/mergeInto.js +45 -0
  139. package/lib/mixInto.js +34 -0
  140. package/lib/monitorCodeUse.js +37 -0
  141. package/lib/objMap.js +47 -0
  142. package/lib/objMapKeyVal.js +47 -0
  143. package/lib/onlyChild.js +43 -0
  144. package/lib/performanceNow.js +42 -0
  145. package/lib/shallowEqual.js +49 -0
  146. package/lib/shouldUpdateReactComponent.js +61 -0
  147. package/lib/toArray.js +75 -0
  148. package/lib/traverseAllChildren.js +190 -0
  149. package/lib/update.js +159 -0
  150. package/lib/warning.js +48 -0
  151. package/package.json +33 -31
  152. package/react.js +1 -0
  153. package/.npmignore +0 -7
  154. package/.travis.yml +0 -7
  155. package/Jakefile.js +0 -39
  156. package/LICENSE +0 -19
  157. package/browser-test/dist.html +0 -90
  158. package/browser-test/index.html +0 -86
  159. package/browser-test/min.html +0 -90
  160. package/dist/react.js +0 -3141
  161. package/dist/react.min.js +0 -22
  162. package/doc/advanced.md +0 -175
  163. package/doc/color-def.graffle +0 -938
  164. package/doc/color-def.png +0 -0
  165. package/doc/simple.dot +0 -25
  166. package/doc/simple.png +0 -0
  167. package/examples/longer-example.js +0 -41
  168. package/examples/simple.js +0 -45
  169. package/examples/using-ast-directly.js +0 -30
  170. package/examples/using-events1.js +0 -79
  171. package/examples/using-log-events.js +0 -43
  172. package/lib/base-task.js +0 -120
  173. package/lib/cb-task.js +0 -84
  174. package/lib/core.js +0 -138
  175. package/lib/dsl.js +0 -138
  176. package/lib/error.js +0 -55
  177. package/lib/event-collector.js +0 -81
  178. package/lib/event-manager.js +0 -89
  179. package/lib/eventemitter.js +0 -20
  180. package/lib/finalcb-first-task.js +0 -68
  181. package/lib/finalcb-task.js +0 -65
  182. package/lib/id.js +0 -22
  183. package/lib/input-parser.js +0 -56
  184. package/lib/log-events.js +0 -101
  185. package/lib/parse.js +0 -41
  186. package/lib/promise-resolve.js +0 -50
  187. package/lib/promise-task.js +0 -93
  188. package/lib/react.js +0 -59
  189. package/lib/ret-task.js +0 -71
  190. package/lib/sprintf.js +0 -18
  191. package/lib/status.js +0 -14
  192. package/lib/task.js +0 -251
  193. package/lib/track-tasks.js +0 -74
  194. package/lib/validate.js +0 -159
  195. package/lib/vcon.js +0 -113
  196. package/lib/when-task.js +0 -84
  197. package/src/dist.build.requirejs +0 -20
  198. package/test/ast.mocha.js +0 -136
  199. package/test/cb-task.mocha.js +0 -220
  200. package/test/core-deferred.mocha.js +0 -143
  201. package/test/core-when.mocha.js +0 -96
  202. package/test/core.mocha.js +0 -589
  203. package/test/dsl.mocha.js +0 -352
  204. package/test/event-manager.mocha.js +0 -119
  205. package/test/exec-options.mocha.js +0 -48
  206. package/test/finalcb-task.mocha.js +0 -58
  207. package/test/input-parser.mocha.js +0 -86
  208. package/test/log-events.mocha.js +0 -88
  209. package/test/mocha.opts +0 -2
  210. package/test/module-use.mocha.js +0 -164
  211. package/test/promise-auto-resolve.mocha.js +0 -68
  212. package/test/ret-task.mocha.js +0 -220
  213. package/test/task.mocha.js +0 -42
  214. package/test/validate-cb-task.mocha.js +0 -100
  215. package/test/validate-ret-task.mocha.js +0 -110
  216. package/test/validate.mocha.js +0 -324
  217. package/test/vcon.mocha.js +0 -193
  218. package/vendor/chai/chai.js +0 -4251
  219. package/vendor/jquery/jquery-1.7.1.js +0 -9266
  220. package/vendor/jquery/jquery-1.7.1.min.js +0 -4
  221. package/vendor/node/util.js +0 -531
  222. package/vendor/requirejs/require.js +0 -2045
  223. package/vendor/requirejs/require.min.js +0 -36
@@ -0,0 +1,67 @@
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 ReactContext
17
+ */
18
+
19
+ "use strict";
20
+
21
+ var merge = require("./merge");
22
+
23
+ /**
24
+ * Keeps track of the current context.
25
+ *
26
+ * The context is automatically passed down the component ownership hierarchy
27
+ * and is accessible via `this.context` on ReactCompositeComponents.
28
+ */
29
+ var ReactContext = {
30
+
31
+ /**
32
+ * @internal
33
+ * @type {object}
34
+ */
35
+ current: {},
36
+
37
+ /**
38
+ * Temporarily extends the current context while executing scopedCallback.
39
+ *
40
+ * A typical use case might look like
41
+ *
42
+ * render: function() {
43
+ * var children = ReactContext.withContext({foo: 'foo'} () => (
44
+ *
45
+ * ));
46
+ * return <div>{children}</div>;
47
+ * }
48
+ *
49
+ * @param {object} newContext New context to merge into the existing context
50
+ * @param {function} scopedCallback Callback to run with the new context
51
+ * @return {ReactComponent|array<ReactComponent>}
52
+ */
53
+ withContext: function(newContext, scopedCallback) {
54
+ var result;
55
+ var previousContext = ReactContext.current;
56
+ ReactContext.current = merge(previousContext, newContext);
57
+ try {
58
+ result = scopedCallback();
59
+ } finally {
60
+ ReactContext.current = previousContext;
61
+ }
62
+ return result;
63
+ }
64
+
65
+ };
66
+
67
+ module.exports = ReactContext;
@@ -0,0 +1,39 @@
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 ReactCurrentOwner
17
+ */
18
+
19
+ "use strict";
20
+
21
+ /**
22
+ * Keeps track of the current owner.
23
+ *
24
+ * The current owner is the component who should own any components that are
25
+ * currently being constructed.
26
+ *
27
+ * The depth indicate how many composite components are above this render level.
28
+ */
29
+ var ReactCurrentOwner = {
30
+
31
+ /**
32
+ * @internal
33
+ * @type {ReactComponent}
34
+ */
35
+ current: null
36
+
37
+ };
38
+
39
+ module.exports = ReactCurrentOwner;
@@ -0,0 +1,207 @@
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 ReactDOM
17
+ * @typechecks static-only
18
+ */
19
+
20
+ "use strict";
21
+
22
+ var ReactDOMComponent = require("./ReactDOMComponent");
23
+
24
+ var mergeInto = require("./mergeInto");
25
+ var objMapKeyVal = require("./objMapKeyVal");
26
+
27
+ /**
28
+ * Creates a new React class that is idempotent and capable of containing other
29
+ * React components. It accepts event listeners and DOM properties that are
30
+ * valid according to `DOMProperty`.
31
+ *
32
+ * - Event listeners: `onClick`, `onMouseDown`, etc.
33
+ * - DOM properties: `className`, `name`, `title`, etc.
34
+ *
35
+ * The `style` property functions differently from the DOM API. It accepts an
36
+ * object mapping of style properties to values.
37
+ *
38
+ * @param {string} tag Tag name (e.g. `div`).
39
+ * @param {boolean} omitClose True if the close tag should be omitted.
40
+ * @private
41
+ */
42
+ function createDOMComponentClass(tag, omitClose) {
43
+ var Constructor = function() {};
44
+ Constructor.prototype = new ReactDOMComponent(tag, omitClose);
45
+ Constructor.prototype.constructor = Constructor;
46
+ Constructor.displayName = tag;
47
+
48
+ var ConvenienceConstructor = function(props, children) {
49
+ var instance = new Constructor();
50
+ instance.construct.apply(instance, arguments);
51
+ return instance;
52
+ };
53
+
54
+ // Expose the constructor on the ConvenienceConstructor and prototype so that
55
+ // it can be easily easily accessed on descriptors.
56
+ // E.g. <div />.type === div.type
57
+ ConvenienceConstructor.type = Constructor;
58
+ Constructor.prototype.type = Constructor;
59
+
60
+ Constructor.ConvenienceConstructor = ConvenienceConstructor;
61
+ ConvenienceConstructor.componentConstructor = Constructor;
62
+ return ConvenienceConstructor;
63
+ }
64
+
65
+ /**
66
+ * Creates a mapping from supported HTML tags to `ReactDOMComponent` classes.
67
+ * This is also accessible via `React.DOM`.
68
+ *
69
+ * @public
70
+ */
71
+ var ReactDOM = objMapKeyVal({
72
+ a: false,
73
+ abbr: false,
74
+ address: false,
75
+ area: true,
76
+ article: false,
77
+ aside: false,
78
+ audio: false,
79
+ b: false,
80
+ base: true,
81
+ bdi: false,
82
+ bdo: false,
83
+ big: false,
84
+ blockquote: false,
85
+ body: false,
86
+ br: true,
87
+ button: false,
88
+ canvas: false,
89
+ caption: false,
90
+ cite: false,
91
+ code: false,
92
+ col: true,
93
+ colgroup: false,
94
+ data: false,
95
+ datalist: false,
96
+ dd: false,
97
+ del: false,
98
+ details: false,
99
+ dfn: false,
100
+ div: false,
101
+ dl: false,
102
+ dt: false,
103
+ em: false,
104
+ embed: true,
105
+ fieldset: false,
106
+ figcaption: false,
107
+ figure: false,
108
+ footer: false,
109
+ form: false, // NOTE: Injected, see `ReactDOMForm`.
110
+ h1: false,
111
+ h2: false,
112
+ h3: false,
113
+ h4: false,
114
+ h5: false,
115
+ h6: false,
116
+ head: false,
117
+ header: false,
118
+ hr: true,
119
+ html: false,
120
+ i: false,
121
+ iframe: false,
122
+ img: true,
123
+ input: true,
124
+ ins: false,
125
+ kbd: false,
126
+ keygen: true,
127
+ label: false,
128
+ legend: false,
129
+ li: false,
130
+ link: true,
131
+ main: false,
132
+ map: false,
133
+ mark: false,
134
+ menu: false,
135
+ menuitem: false, // NOTE: Close tag should be omitted, but causes problems.
136
+ meta: true,
137
+ meter: false,
138
+ nav: false,
139
+ noscript: false,
140
+ object: false,
141
+ ol: false,
142
+ optgroup: false,
143
+ option: false,
144
+ output: false,
145
+ p: false,
146
+ param: true,
147
+ pre: false,
148
+ progress: false,
149
+ q: false,
150
+ rp: false,
151
+ rt: false,
152
+ ruby: false,
153
+ s: false,
154
+ samp: false,
155
+ script: false,
156
+ section: false,
157
+ select: false,
158
+ small: false,
159
+ source: true,
160
+ span: false,
161
+ strong: false,
162
+ style: false,
163
+ sub: false,
164
+ summary: false,
165
+ sup: false,
166
+ table: false,
167
+ tbody: false,
168
+ td: false,
169
+ textarea: false, // NOTE: Injected, see `ReactDOMTextarea`.
170
+ tfoot: false,
171
+ th: false,
172
+ thead: false,
173
+ time: false,
174
+ title: false,
175
+ tr: false,
176
+ track: true,
177
+ u: false,
178
+ ul: false,
179
+ 'var': false,
180
+ video: false,
181
+ wbr: true,
182
+
183
+ // SVG
184
+ circle: false,
185
+ defs: false,
186
+ g: false,
187
+ line: false,
188
+ linearGradient: false,
189
+ path: false,
190
+ polygon: false,
191
+ polyline: false,
192
+ radialGradient: false,
193
+ rect: false,
194
+ stop: false,
195
+ svg: false,
196
+ text: false
197
+ }, createDOMComponentClass);
198
+
199
+ var injection = {
200
+ injectComponentClasses: function(componentClasses) {
201
+ mergeInto(ReactDOM, componentClasses);
202
+ }
203
+ };
204
+
205
+ ReactDOM.injection = injection;
206
+
207
+ module.exports = ReactDOM;
@@ -0,0 +1,69 @@
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 ReactDOMButton
17
+ */
18
+
19
+ "use strict";
20
+
21
+ var AutoFocusMixin = require("./AutoFocusMixin");
22
+ var ReactBrowserComponentMixin = require("./ReactBrowserComponentMixin");
23
+ var ReactCompositeComponent = require("./ReactCompositeComponent");
24
+ var ReactDOM = require("./ReactDOM");
25
+
26
+ var keyMirror = require("./keyMirror");
27
+
28
+ // Store a reference to the <button> `ReactDOMComponent`.
29
+ var button = ReactDOM.button;
30
+
31
+ var mouseListenerNames = keyMirror({
32
+ onClick: true,
33
+ onDoubleClick: true,
34
+ onMouseDown: true,
35
+ onMouseMove: true,
36
+ onMouseUp: true,
37
+ onClickCapture: true,
38
+ onDoubleClickCapture: true,
39
+ onMouseDownCapture: true,
40
+ onMouseMoveCapture: true,
41
+ onMouseUpCapture: true
42
+ });
43
+
44
+ /**
45
+ * Implements a <button> native component that does not receive mouse events
46
+ * when `disabled` is set.
47
+ */
48
+ var ReactDOMButton = ReactCompositeComponent.createClass({
49
+ displayName: 'ReactDOMButton',
50
+
51
+ mixins: [AutoFocusMixin, ReactBrowserComponentMixin],
52
+
53
+ render: function() {
54
+ var props = {};
55
+
56
+ // Copy the props; except the mouse listeners if we're disabled
57
+ for (var key in this.props) {
58
+ if (this.props.hasOwnProperty(key) &&
59
+ (!this.props.disabled || !mouseListenerNames[key])) {
60
+ props[key] = this.props[key];
61
+ }
62
+ }
63
+
64
+ return button(props, this.props.children);
65
+ }
66
+
67
+ });
68
+
69
+ module.exports = ReactDOMButton;
@@ -0,0 +1,416 @@
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 ReactDOMComponent
17
+ * @typechecks static-only
18
+ */
19
+
20
+ "use strict";
21
+
22
+ var CSSPropertyOperations = require("./CSSPropertyOperations");
23
+ var DOMProperty = require("./DOMProperty");
24
+ var DOMPropertyOperations = require("./DOMPropertyOperations");
25
+ var ReactBrowserComponentMixin = require("./ReactBrowserComponentMixin");
26
+ var ReactComponent = require("./ReactComponent");
27
+ var ReactEventEmitter = require("./ReactEventEmitter");
28
+ var ReactMount = require("./ReactMount");
29
+ var ReactMultiChild = require("./ReactMultiChild");
30
+ var ReactPerf = require("./ReactPerf");
31
+
32
+ var escapeTextForBrowser = require("./escapeTextForBrowser");
33
+ var invariant = require("./invariant");
34
+ var keyOf = require("./keyOf");
35
+ var merge = require("./merge");
36
+ var mixInto = require("./mixInto");
37
+
38
+ var deleteListener = ReactEventEmitter.deleteListener;
39
+ var listenTo = ReactEventEmitter.listenTo;
40
+ var registrationNameModules = ReactEventEmitter.registrationNameModules;
41
+
42
+ // For quickly matching children type, to test if can be treated as content.
43
+ var CONTENT_TYPES = {'string': true, 'number': true};
44
+
45
+ var STYLE = keyOf({style: null});
46
+
47
+ var ELEMENT_NODE_TYPE = 1;
48
+
49
+ /**
50
+ * @param {?object} props
51
+ */
52
+ function assertValidProps(props) {
53
+ if (!props) {
54
+ return;
55
+ }
56
+ // Note the use of `==` which checks for null or undefined.
57
+ ("production" !== process.env.NODE_ENV ? invariant(
58
+ props.children == null || props.dangerouslySetInnerHTML == null,
59
+ 'Can only set one of `children` or `props.dangerouslySetInnerHTML`.'
60
+ ) : invariant(props.children == null || props.dangerouslySetInnerHTML == null));
61
+ ("production" !== process.env.NODE_ENV ? invariant(
62
+ props.style == null || typeof props.style === 'object',
63
+ 'The `style` prop expects a mapping from style properties to values, ' +
64
+ 'not a string.'
65
+ ) : invariant(props.style == null || typeof props.style === 'object'));
66
+ }
67
+
68
+ function putListener(id, registrationName, listener, transaction) {
69
+ var container = ReactMount.findReactContainerForID(id);
70
+ if (container) {
71
+ var doc = container.nodeType === ELEMENT_NODE_TYPE ?
72
+ container.ownerDocument :
73
+ container;
74
+ listenTo(registrationName, doc);
75
+ }
76
+ transaction.getPutListenerQueue().enqueuePutListener(
77
+ id,
78
+ registrationName,
79
+ listener
80
+ );
81
+ }
82
+
83
+
84
+ /**
85
+ * @constructor ReactDOMComponent
86
+ * @extends ReactComponent
87
+ * @extends ReactMultiChild
88
+ */
89
+ function ReactDOMComponent(tag, omitClose) {
90
+ this._tagOpen = '<' + tag;
91
+ this._tagClose = omitClose ? '' : '</' + tag + '>';
92
+ this.tagName = tag.toUpperCase();
93
+ }
94
+
95
+ ReactDOMComponent.Mixin = {
96
+
97
+ /**
98
+ * Generates root tag markup then recurses. This method has side effects and
99
+ * is not idempotent.
100
+ *
101
+ * @internal
102
+ * @param {string} rootID The root DOM ID for this node.
103
+ * @param {ReactReconcileTransaction|ReactServerRenderingTransaction} transaction
104
+ * @param {number} mountDepth number of components in the owner hierarchy
105
+ * @return {string} The computed markup.
106
+ */
107
+ mountComponent: ReactPerf.measure(
108
+ 'ReactDOMComponent',
109
+ 'mountComponent',
110
+ function(rootID, transaction, mountDepth) {
111
+ ReactComponent.Mixin.mountComponent.call(
112
+ this,
113
+ rootID,
114
+ transaction,
115
+ mountDepth
116
+ );
117
+ assertValidProps(this.props);
118
+ return (
119
+ this._createOpenTagMarkupAndPutListeners(transaction) +
120
+ this._createContentMarkup(transaction) +
121
+ this._tagClose
122
+ );
123
+ }
124
+ ),
125
+
126
+ /**
127
+ * Creates markup for the open tag and all attributes.
128
+ *
129
+ * This method has side effects because events get registered.
130
+ *
131
+ * Iterating over object properties is faster than iterating over arrays.
132
+ * @see http://jsperf.com/obj-vs-arr-iteration
133
+ *
134
+ * @private
135
+ * @param {ReactReconcileTransaction|ReactServerRenderingTransaction} transaction
136
+ * @return {string} Markup of opening tag.
137
+ */
138
+ _createOpenTagMarkupAndPutListeners: function(transaction) {
139
+ var props = this.props;
140
+ var ret = this._tagOpen;
141
+
142
+ for (var propKey in props) {
143
+ if (!props.hasOwnProperty(propKey)) {
144
+ continue;
145
+ }
146
+ var propValue = props[propKey];
147
+ if (propValue == null) {
148
+ continue;
149
+ }
150
+ if (registrationNameModules[propKey]) {
151
+ putListener(this._rootNodeID, propKey, propValue, transaction);
152
+ } else {
153
+ if (propKey === STYLE) {
154
+ if (propValue) {
155
+ propValue = props.style = merge(props.style);
156
+ }
157
+ propValue = CSSPropertyOperations.createMarkupForStyles(propValue);
158
+ }
159
+ var markup =
160
+ DOMPropertyOperations.createMarkupForProperty(propKey, propValue);
161
+ if (markup) {
162
+ ret += ' ' + markup;
163
+ }
164
+ }
165
+ }
166
+
167
+ // For static pages, no need to put React ID and checksum. Saves lots of
168
+ // bytes.
169
+ if (transaction.renderToStaticMarkup) {
170
+ return ret + '>';
171
+ }
172
+
173
+ var markupForID = DOMPropertyOperations.createMarkupForID(this._rootNodeID);
174
+ return ret + ' ' + markupForID + '>';
175
+ },
176
+
177
+ /**
178
+ * Creates markup for the content between the tags.
179
+ *
180
+ * @private
181
+ * @param {ReactReconcileTransaction|ReactServerRenderingTransaction} transaction
182
+ * @return {string} Content markup.
183
+ */
184
+ _createContentMarkup: function(transaction) {
185
+ // Intentional use of != to avoid catching zero/false.
186
+ var innerHTML = this.props.dangerouslySetInnerHTML;
187
+ if (innerHTML != null) {
188
+ if (innerHTML.__html != null) {
189
+ return innerHTML.__html;
190
+ }
191
+ } else {
192
+ var contentToUse =
193
+ CONTENT_TYPES[typeof this.props.children] ? this.props.children : null;
194
+ var childrenToUse = contentToUse != null ? null : this.props.children;
195
+ if (contentToUse != null) {
196
+ return escapeTextForBrowser(contentToUse);
197
+ } else if (childrenToUse != null) {
198
+ var mountImages = this.mountChildren(
199
+ childrenToUse,
200
+ transaction
201
+ );
202
+ return mountImages.join('');
203
+ }
204
+ }
205
+ return '';
206
+ },
207
+
208
+ receiveComponent: function(nextComponent, transaction) {
209
+ if (nextComponent === this) {
210
+ // Since props and context are immutable after the component is
211
+ // mounted, we can do a cheap identity compare here to determine
212
+ // if this is a superfluous reconcile.
213
+
214
+ // TODO: compare the descriptor
215
+ return;
216
+ }
217
+
218
+ assertValidProps(nextComponent.props);
219
+ ReactComponent.Mixin.receiveComponent.call(
220
+ this,
221
+ nextComponent,
222
+ transaction
223
+ );
224
+ },
225
+
226
+ /**
227
+ * Updates a native DOM component after it has already been allocated and
228
+ * attached to the DOM. Reconciles the root DOM node, then recurses.
229
+ *
230
+ * @param {ReactReconcileTransaction} transaction
231
+ * @param {object} prevProps
232
+ * @internal
233
+ * @overridable
234
+ */
235
+ updateComponent: ReactPerf.measure(
236
+ 'ReactDOMComponent',
237
+ 'updateComponent',
238
+ function(transaction, prevProps, prevOwner) {
239
+ ReactComponent.Mixin.updateComponent.call(
240
+ this,
241
+ transaction,
242
+ prevProps,
243
+ prevOwner
244
+ );
245
+ this._updateDOMProperties(prevProps, transaction);
246
+ this._updateDOMChildren(prevProps, transaction);
247
+ }
248
+ ),
249
+
250
+ /**
251
+ * Reconciles the properties by detecting differences in property values and
252
+ * updating the DOM as necessary. This function is probably the single most
253
+ * critical path for performance optimization.
254
+ *
255
+ * TODO: Benchmark whether checking for changed values in memory actually
256
+ * improves performance (especially statically positioned elements).
257
+ * TODO: Benchmark the effects of putting this at the top since 99% of props
258
+ * do not change for a given reconciliation.
259
+ * TODO: Benchmark areas that can be improved with caching.
260
+ *
261
+ * @private
262
+ * @param {object} lastProps
263
+ * @param {ReactReconcileTransaction} transaction
264
+ */
265
+ _updateDOMProperties: function(lastProps, transaction) {
266
+ var nextProps = this.props;
267
+ var propKey;
268
+ var styleName;
269
+ var styleUpdates;
270
+ for (propKey in lastProps) {
271
+ if (nextProps.hasOwnProperty(propKey) ||
272
+ !lastProps.hasOwnProperty(propKey)) {
273
+ continue;
274
+ }
275
+ if (propKey === STYLE) {
276
+ var lastStyle = lastProps[propKey];
277
+ for (styleName in lastStyle) {
278
+ if (lastStyle.hasOwnProperty(styleName)) {
279
+ styleUpdates = styleUpdates || {};
280
+ styleUpdates[styleName] = '';
281
+ }
282
+ }
283
+ } else if (registrationNameModules[propKey]) {
284
+ deleteListener(this._rootNodeID, propKey);
285
+ } else if (
286
+ DOMProperty.isStandardName[propKey] ||
287
+ DOMProperty.isCustomAttribute(propKey)) {
288
+ ReactComponent.BackendIDOperations.deletePropertyByID(
289
+ this._rootNodeID,
290
+ propKey
291
+ );
292
+ }
293
+ }
294
+ for (propKey in nextProps) {
295
+ var nextProp = nextProps[propKey];
296
+ var lastProp = lastProps[propKey];
297
+ if (!nextProps.hasOwnProperty(propKey) || nextProp === lastProp) {
298
+ continue;
299
+ }
300
+ if (propKey === STYLE) {
301
+ if (nextProp) {
302
+ nextProp = nextProps.style = merge(nextProp);
303
+ }
304
+ if (lastProp) {
305
+ // Unset styles on `lastProp` but not on `nextProp`.
306
+ for (styleName in lastProp) {
307
+ if (lastProp.hasOwnProperty(styleName) &&
308
+ !nextProp.hasOwnProperty(styleName)) {
309
+ styleUpdates = styleUpdates || {};
310
+ styleUpdates[styleName] = '';
311
+ }
312
+ }
313
+ // Update styles that changed since `lastProp`.
314
+ for (styleName in nextProp) {
315
+ if (nextProp.hasOwnProperty(styleName) &&
316
+ lastProp[styleName] !== nextProp[styleName]) {
317
+ styleUpdates = styleUpdates || {};
318
+ styleUpdates[styleName] = nextProp[styleName];
319
+ }
320
+ }
321
+ } else {
322
+ // Relies on `updateStylesByID` not mutating `styleUpdates`.
323
+ styleUpdates = nextProp;
324
+ }
325
+ } else if (registrationNameModules[propKey]) {
326
+ putListener(this._rootNodeID, propKey, nextProp, transaction);
327
+ } else if (
328
+ DOMProperty.isStandardName[propKey] ||
329
+ DOMProperty.isCustomAttribute(propKey)) {
330
+ ReactComponent.BackendIDOperations.updatePropertyByID(
331
+ this._rootNodeID,
332
+ propKey,
333
+ nextProp
334
+ );
335
+ }
336
+ }
337
+ if (styleUpdates) {
338
+ ReactComponent.BackendIDOperations.updateStylesByID(
339
+ this._rootNodeID,
340
+ styleUpdates
341
+ );
342
+ }
343
+ },
344
+
345
+ /**
346
+ * Reconciles the children with the various properties that affect the
347
+ * children content.
348
+ *
349
+ * @param {object} lastProps
350
+ * @param {ReactReconcileTransaction} transaction
351
+ */
352
+ _updateDOMChildren: function(lastProps, transaction) {
353
+ var nextProps = this.props;
354
+
355
+ var lastContent =
356
+ CONTENT_TYPES[typeof lastProps.children] ? lastProps.children : null;
357
+ var nextContent =
358
+ CONTENT_TYPES[typeof nextProps.children] ? nextProps.children : null;
359
+
360
+ var lastHtml =
361
+ lastProps.dangerouslySetInnerHTML &&
362
+ lastProps.dangerouslySetInnerHTML.__html;
363
+ var nextHtml =
364
+ nextProps.dangerouslySetInnerHTML &&
365
+ nextProps.dangerouslySetInnerHTML.__html;
366
+
367
+ // Note the use of `!=` which checks for null or undefined.
368
+ var lastChildren = lastContent != null ? null : lastProps.children;
369
+ var nextChildren = nextContent != null ? null : nextProps.children;
370
+
371
+ // If we're switching from children to content/html or vice versa, remove
372
+ // the old content
373
+ var lastHasContentOrHtml = lastContent != null || lastHtml != null;
374
+ var nextHasContentOrHtml = nextContent != null || nextHtml != null;
375
+ if (lastChildren != null && nextChildren == null) {
376
+ this.updateChildren(null, transaction);
377
+ } else if (lastHasContentOrHtml && !nextHasContentOrHtml) {
378
+ this.updateTextContent('');
379
+ }
380
+
381
+ if (nextContent != null) {
382
+ if (lastContent !== nextContent) {
383
+ this.updateTextContent('' + nextContent);
384
+ }
385
+ } else if (nextHtml != null) {
386
+ if (lastHtml !== nextHtml) {
387
+ ReactComponent.BackendIDOperations.updateInnerHTMLByID(
388
+ this._rootNodeID,
389
+ nextHtml
390
+ );
391
+ }
392
+ } else if (nextChildren != null) {
393
+ this.updateChildren(nextChildren, transaction);
394
+ }
395
+ },
396
+
397
+ /**
398
+ * Destroys all event registrations for this instance. Does not remove from
399
+ * the DOM. That must be done by the parent.
400
+ *
401
+ * @internal
402
+ */
403
+ unmountComponent: function() {
404
+ this.unmountChildren();
405
+ ReactEventEmitter.deleteAllListeners(this._rootNodeID);
406
+ ReactComponent.Mixin.unmountComponent.call(this);
407
+ }
408
+
409
+ };
410
+
411
+ mixInto(ReactDOMComponent, ReactComponent.Mixin);
412
+ mixInto(ReactDOMComponent, ReactDOMComponent.Mixin);
413
+ mixInto(ReactDOMComponent, ReactMultiChild.Mixin);
414
+ mixInto(ReactDOMComponent, ReactBrowserComponentMixin);
415
+
416
+ module.exports = ReactDOMComponent;