react 0.6.3 → 0.9.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 (218) hide show
  1. package/README.md +10 -222
  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 +197 -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 +291 -0
  20. package/lib/EventPluginRegistry.js +260 -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 +337 -0
  55. package/lib/ReactEventEmitterMixin.js +57 -0
  56. package/lib/ReactEventTopLevelCallback.js +109 -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/ReactTextComponent.js +99 -0
  78. package/lib/ReactTransitionChildMapping.js +106 -0
  79. package/lib/ReactTransitionEvents.js +97 -0
  80. package/lib/ReactTransitionGroup.js +187 -0
  81. package/lib/ReactUpdates.js +148 -0
  82. package/lib/ReactWithAddons.js +46 -0
  83. package/lib/SelectEventPlugin.js +200 -0
  84. package/lib/ServerReactRootIndex.js +36 -0
  85. package/lib/SimpleEventPlugin.js +413 -0
  86. package/lib/SyntheticClipboardEvent.js +51 -0
  87. package/lib/SyntheticCompositionEvent.js +51 -0
  88. package/lib/SyntheticDragEvent.js +44 -0
  89. package/lib/SyntheticEvent.js +164 -0
  90. package/lib/SyntheticFocusEvent.js +44 -0
  91. package/lib/SyntheticKeyboardEvent.js +58 -0
  92. package/lib/SyntheticMouseEvent.js +85 -0
  93. package/lib/SyntheticTouchEvent.js +50 -0
  94. package/lib/SyntheticUIEvent.js +45 -0
  95. package/lib/SyntheticWheelEvent.js +66 -0
  96. package/lib/Transaction.js +276 -0
  97. package/lib/ViewportMetrics.js +37 -0
  98. package/lib/accumulate.js +54 -0
  99. package/lib/adler32.js +39 -0
  100. package/lib/cloneWithProps.js +59 -0
  101. package/lib/containsNode.js +49 -0
  102. package/lib/copyProperties.js +54 -0
  103. package/lib/createArrayFrom.js +91 -0
  104. package/lib/createFullPageComponent.js +63 -0
  105. package/lib/createNodesFromMarkup.js +93 -0
  106. package/lib/createObjectFrom.js +61 -0
  107. package/lib/cx.js +44 -0
  108. package/lib/dangerousStyleValue.js +57 -0
  109. package/lib/emptyFunction.js +43 -0
  110. package/lib/escapeTextForBrowser.js +47 -0
  111. package/lib/flattenChildren.js +57 -0
  112. package/lib/forEachAccumulated.js +36 -0
  113. package/lib/getActiveElement.js +34 -0
  114. package/lib/getEventKey.js +85 -0
  115. package/lib/getEventTarget.js +36 -0
  116. package/lib/getMarkupWrap.js +118 -0
  117. package/lib/getNodeForCharacterOffset.js +80 -0
  118. package/lib/getReactRootElementInContainer.js +40 -0
  119. package/lib/getTextContentAccessor.js +42 -0
  120. package/lib/getUnboundedScrollPosition.js +45 -0
  121. package/lib/hyphenate.js +35 -0
  122. package/lib/invariant.js +62 -0
  123. package/lib/isEventSupported.js +70 -0
  124. package/lib/isNode.js +33 -0
  125. package/lib/isTextInputElement.js +49 -0
  126. package/lib/isTextNode.js +30 -0
  127. package/lib/joinClasses.js +44 -0
  128. package/lib/keyMirror.js +58 -0
  129. package/lib/keyOf.js +41 -0
  130. package/lib/memoizeStringOnly.js +39 -0
  131. package/lib/merge.js +37 -0
  132. package/lib/mergeHelpers.js +136 -0
  133. package/lib/mergeInto.js +45 -0
  134. package/lib/mixInto.js +34 -0
  135. package/lib/objMap.js +47 -0
  136. package/lib/objMapKeyVal.js +47 -0
  137. package/lib/onlyChild.js +43 -0
  138. package/lib/performanceNow.js +42 -0
  139. package/lib/shallowEqual.js +49 -0
  140. package/lib/shouldUpdateReactComponent.js +58 -0
  141. package/lib/toArray.js +75 -0
  142. package/lib/traverseAllChildren.js +189 -0
  143. package/lib/warning.js +40 -0
  144. package/package.json +32 -21
  145. package/react.js +1 -0
  146. package/.npmignore +0 -7
  147. package/.travis.yml +0 -5
  148. package/Jakefile.js +0 -39
  149. package/LICENSE +0 -19
  150. package/browser-test/dist.html +0 -90
  151. package/browser-test/index.html +0 -86
  152. package/browser-test/min.html +0 -90
  153. package/dist/react.js +0 -3107
  154. package/dist/react.min.js +0 -22
  155. package/doc/advanced.md +0 -174
  156. package/doc/color-def.graffle +0 -938
  157. package/doc/color-def.png +0 -0
  158. package/doc/simple.dot +0 -25
  159. package/doc/simple.png +0 -0
  160. package/examples/longer-example.js +0 -41
  161. package/examples/simple.js +0 -45
  162. package/examples/using-ast-directly.js +0 -30
  163. package/examples/using-events1.js +0 -79
  164. package/examples/using-log-events.js +0 -43
  165. package/lib/base-task.js +0 -123
  166. package/lib/cb-task.js +0 -84
  167. package/lib/core.js +0 -138
  168. package/lib/dsl.js +0 -138
  169. package/lib/error.js +0 -55
  170. package/lib/event-collector.js +0 -81
  171. package/lib/event-manager.js +0 -89
  172. package/lib/eventemitter.js +0 -20
  173. package/lib/finalcb-first-task.js +0 -68
  174. package/lib/finalcb-task.js +0 -65
  175. package/lib/id.js +0 -22
  176. package/lib/input-parser.js +0 -56
  177. package/lib/log-events.js +0 -101
  178. package/lib/parse.js +0 -41
  179. package/lib/promise-resolve.js +0 -50
  180. package/lib/promise-task.js +0 -93
  181. package/lib/react.js +0 -59
  182. package/lib/ret-task.js +0 -71
  183. package/lib/sprintf.js +0 -18
  184. package/lib/status.js +0 -14
  185. package/lib/task.js +0 -251
  186. package/lib/track-tasks.js +0 -74
  187. package/lib/validate.js +0 -159
  188. package/lib/vcon.js +0 -90
  189. package/lib/when-task.js +0 -85
  190. package/src/dist.build.requirejs +0 -20
  191. package/test/ast.mocha.js +0 -136
  192. package/test/cb-task.mocha.js +0 -220
  193. package/test/core-deferred.mocha.js +0 -143
  194. package/test/core-when.mocha.js +0 -96
  195. package/test/core.mocha.js +0 -589
  196. package/test/dsl.mocha.js +0 -350
  197. package/test/event-manager.mocha.js +0 -119
  198. package/test/exec-options.mocha.js +0 -48
  199. package/test/finalcb-task.mocha.js +0 -58
  200. package/test/input-parser.mocha.js +0 -86
  201. package/test/log-events.mocha.js +0 -88
  202. package/test/mocha.opts +0 -2
  203. package/test/module-use.mocha.js +0 -147
  204. package/test/promise-auto-resolve.mocha.js +0 -68
  205. package/test/ret-task.mocha.js +0 -220
  206. package/test/task.mocha.js +0 -42
  207. package/test/validate-cb-task.mocha.js +0 -100
  208. package/test/validate-ret-task.mocha.js +0 -110
  209. package/test/validate.mocha.js +0 -324
  210. package/test/vcon.mocha.js +0 -193
  211. package/vendor/chai/chai.js +0 -2038
  212. package/vendor/jquery/jquery-1.7.1.js +0 -9266
  213. package/vendor/jquery/jquery-1.7.1.min.js +0 -4
  214. package/vendor/mocha/mocha.css +0 -135
  215. package/vendor/mocha/mocha.js +0 -3589
  216. package/vendor/node/util.js +0 -531
  217. package/vendor/requirejs/require.js +0 -2053
  218. package/vendor/requirejs/require.min.js +0 -33
@@ -0,0 +1,37 @@
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 ReactErrorUtils
17
+ * @typechecks
18
+ */
19
+
20
+ "use strict";
21
+
22
+ var ReactErrorUtils = {
23
+ /**
24
+ * Creates a guarded version of a function. This is supposed to make debugging
25
+ * of event handlers easier. To aid debugging with the browser's debugger,
26
+ * this currently simply returns the original function.
27
+ *
28
+ * @param {function} func Function to be executed
29
+ * @param {string} name The name of the guard
30
+ * @return {function}
31
+ */
32
+ guard: function(func, name) {
33
+ return func;
34
+ }
35
+ };
36
+
37
+ module.exports = ReactErrorUtils;
@@ -0,0 +1,337 @@
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 ReactEventEmitter
17
+ * @typechecks static-only
18
+ */
19
+
20
+ "use strict";
21
+
22
+ var EventConstants = require("./EventConstants");
23
+ var EventListener = require("./EventListener");
24
+ var EventPluginHub = require("./EventPluginHub");
25
+ var EventPluginRegistry = require("./EventPluginRegistry");
26
+ var ExecutionEnvironment = require("./ExecutionEnvironment");
27
+ var ReactEventEmitterMixin = require("./ReactEventEmitterMixin");
28
+ var ViewportMetrics = require("./ViewportMetrics");
29
+
30
+ var invariant = require("./invariant");
31
+ var isEventSupported = require("./isEventSupported");
32
+ var merge = require("./merge");
33
+
34
+ /**
35
+ * Summary of `ReactEventEmitter` event handling:
36
+ *
37
+ * - Top-level delegation is used to trap native browser events. We normalize
38
+ * and de-duplicate events to account for browser quirks.
39
+ *
40
+ * - Forward these native events (with the associated top-level type used to
41
+ * trap it) to `EventPluginHub`, which in turn will ask plugins if they want
42
+ * to extract any synthetic events.
43
+ *
44
+ * - The `EventPluginHub` will then process each event by annotating them with
45
+ * "dispatches", a sequence of listeners and IDs that care about that event.
46
+ *
47
+ * - The `EventPluginHub` then dispatches the events.
48
+ *
49
+ * Overview of React and the event system:
50
+ *
51
+ * .
52
+ * +------------+ .
53
+ * | DOM | .
54
+ * +------------+ . +-----------+
55
+ * + . +--------+|SimpleEvent|
56
+ * | . | |Plugin |
57
+ * +-----|------+ . v +-----------+
58
+ * | | | . +--------------+ +------------+
59
+ * | +-----------.--->|EventPluginHub| | Event |
60
+ * | | . | | +-----------+ | Propagators|
61
+ * | ReactEvent | . | | |TapEvent | |------------|
62
+ * | Emitter | . | |<---+|Plugin | |other plugin|
63
+ * | | . | | +-----------+ | utilities |
64
+ * | +-----------.--->| | +------------+
65
+ * | | | . +--------------+
66
+ * +-----|------+ . ^ +-----------+
67
+ * | . | |Enter/Leave|
68
+ * + . +-------+|Plugin |
69
+ * +-------------+ . +-----------+
70
+ * | application | .
71
+ * |-------------| .
72
+ * | | .
73
+ * | | .
74
+ * +-------------+ .
75
+ * .
76
+ * React Core . General Purpose Event Plugin System
77
+ */
78
+
79
+ var alreadyListeningTo = {};
80
+ var isMonitoringScrollValue = false;
81
+ var reactTopListenersCounter = 0;
82
+
83
+ // For events like 'submit' which don't consistently bubble (which we trap at a
84
+ // lower node than `document`), binding at `document` would cause duplicate
85
+ // events so we don't include them here
86
+ var topEventMapping = {
87
+ topBlur: 'blur',
88
+ topChange: 'change',
89
+ topClick: 'click',
90
+ topCompositionEnd: 'compositionend',
91
+ topCompositionStart: 'compositionstart',
92
+ topCompositionUpdate: 'compositionupdate',
93
+ topContextMenu: 'contextmenu',
94
+ topCopy: 'copy',
95
+ topCut: 'cut',
96
+ topDoubleClick: 'dblclick',
97
+ topDrag: 'drag',
98
+ topDragEnd: 'dragend',
99
+ topDragEnter: 'dragenter',
100
+ topDragExit: 'dragexit',
101
+ topDragLeave: 'dragleave',
102
+ topDragOver: 'dragover',
103
+ topDragStart: 'dragstart',
104
+ topDrop: 'drop',
105
+ topFocus: 'focus',
106
+ topInput: 'input',
107
+ topKeyDown: 'keydown',
108
+ topKeyPress: 'keypress',
109
+ topKeyUp: 'keyup',
110
+ topMouseDown: 'mousedown',
111
+ topMouseMove: 'mousemove',
112
+ topMouseOut: 'mouseout',
113
+ topMouseOver: 'mouseover',
114
+ topMouseUp: 'mouseup',
115
+ topPaste: 'paste',
116
+ topScroll: 'scroll',
117
+ topSelectionChange: 'selectionchange',
118
+ topTouchCancel: 'touchcancel',
119
+ topTouchEnd: 'touchend',
120
+ topTouchMove: 'touchmove',
121
+ topTouchStart: 'touchstart',
122
+ topWheel: 'wheel'
123
+ };
124
+
125
+ /**
126
+ * To ensure no conflicts with other potential React instances on the page
127
+ */
128
+ var topListenersIDKey = "_reactListenersID" + String(Math.random()).slice(2);
129
+
130
+ function getListeningForDocument(mountAt) {
131
+ if (mountAt[topListenersIDKey] == null) {
132
+ mountAt[topListenersIDKey] = reactTopListenersCounter++;
133
+ alreadyListeningTo[mountAt[topListenersIDKey]] = {};
134
+ }
135
+ return alreadyListeningTo[mountAt[topListenersIDKey]];
136
+ }
137
+
138
+ /**
139
+ * Traps top-level events by using event bubbling.
140
+ *
141
+ * @param {string} topLevelType Record from `EventConstants`.
142
+ * @param {string} handlerBaseName Event name (e.g. "click").
143
+ * @param {DOMEventTarget} element Element on which to attach listener.
144
+ * @internal
145
+ */
146
+ function trapBubbledEvent(topLevelType, handlerBaseName, element) {
147
+ EventListener.listen(
148
+ element,
149
+ handlerBaseName,
150
+ ReactEventEmitter.TopLevelCallbackCreator.createTopLevelCallback(
151
+ topLevelType
152
+ )
153
+ );
154
+ }
155
+
156
+ /**
157
+ * Traps a top-level event by using event capturing.
158
+ *
159
+ * @param {string} topLevelType Record from `EventConstants`.
160
+ * @param {string} handlerBaseName Event name (e.g. "click").
161
+ * @param {DOMEventTarget} element Element on which to attach listener.
162
+ * @internal
163
+ */
164
+ function trapCapturedEvent(topLevelType, handlerBaseName, element) {
165
+ EventListener.capture(
166
+ element,
167
+ handlerBaseName,
168
+ ReactEventEmitter.TopLevelCallbackCreator.createTopLevelCallback(
169
+ topLevelType
170
+ )
171
+ );
172
+ }
173
+
174
+ /**
175
+ * `ReactEventEmitter` is used to attach top-level event listeners. For example:
176
+ *
177
+ * ReactEventEmitter.putListener('myID', 'onClick', myFunction);
178
+ *
179
+ * This would allocate a "registration" of `('onClick', myFunction)` on 'myID'.
180
+ *
181
+ * @internal
182
+ */
183
+ var ReactEventEmitter = merge(ReactEventEmitterMixin, {
184
+
185
+ /**
186
+ * React references `ReactEventTopLevelCallback` using this property in order
187
+ * to allow dependency injection.
188
+ */
189
+ TopLevelCallbackCreator: null,
190
+
191
+ injection: {
192
+ /**
193
+ * @param {function} TopLevelCallbackCreator
194
+ */
195
+ injectTopLevelCallbackCreator: function(TopLevelCallbackCreator) {
196
+ ReactEventEmitter.TopLevelCallbackCreator = TopLevelCallbackCreator;
197
+ }
198
+ },
199
+
200
+ /**
201
+ * Sets whether or not any created callbacks should be enabled.
202
+ *
203
+ * @param {boolean} enabled True if callbacks should be enabled.
204
+ */
205
+ setEnabled: function(enabled) {
206
+ ("production" !== process.env.NODE_ENV ? invariant(
207
+ ExecutionEnvironment.canUseDOM,
208
+ 'setEnabled(...): Cannot toggle event listening in a Worker thread. ' +
209
+ 'This is likely a bug in the framework. Please report immediately.'
210
+ ) : invariant(ExecutionEnvironment.canUseDOM));
211
+ if (ReactEventEmitter.TopLevelCallbackCreator) {
212
+ ReactEventEmitter.TopLevelCallbackCreator.setEnabled(enabled);
213
+ }
214
+ },
215
+
216
+ /**
217
+ * @return {boolean} True if callbacks are enabled.
218
+ */
219
+ isEnabled: function() {
220
+ return !!(
221
+ ReactEventEmitter.TopLevelCallbackCreator &&
222
+ ReactEventEmitter.TopLevelCallbackCreator.isEnabled()
223
+ );
224
+ },
225
+
226
+ /**
227
+ * We listen for bubbled touch events on the document object.
228
+ *
229
+ * Firefox v8.01 (and possibly others) exhibited strange behavior when
230
+ * mounting `onmousemove` events at some node that was not the document
231
+ * element. The symptoms were that if your mouse is not moving over something
232
+ * contained within that mount point (for example on the background) the
233
+ * top-level listeners for `onmousemove` won't be called. However, if you
234
+ * register the `mousemove` on the document object, then it will of course
235
+ * catch all `mousemove`s. This along with iOS quirks, justifies restricting
236
+ * top-level listeners to the document object only, at least for these
237
+ * movement types of events and possibly all events.
238
+ *
239
+ * @see http://www.quirksmode.org/blog/archives/2010/09/click_event_del.html
240
+ *
241
+ * Also, `keyup`/`keypress`/`keydown` do not bubble to the window on IE, but
242
+ * they bubble to document.
243
+ *
244
+ * @param {string} registrationName Name of listener (e.g. `onClick`).
245
+ * @param {DOMDocument} contentDocument Document which owns the container
246
+ */
247
+ listenTo: function(registrationName, contentDocument) {
248
+ var mountAt = contentDocument;
249
+ var isListening = getListeningForDocument(mountAt);
250
+ var dependencies = EventPluginRegistry.
251
+ registrationNameDependencies[registrationName];
252
+
253
+ var topLevelTypes = EventConstants.topLevelTypes;
254
+ for (var i = 0, l = dependencies.length; i < l; i++) {
255
+ var dependency = dependencies[i];
256
+ if (!isListening[dependency]) {
257
+ var topLevelType = topLevelTypes[dependency];
258
+
259
+ if (topLevelType === topLevelTypes.topWheel) {
260
+ if (isEventSupported('wheel')) {
261
+ trapBubbledEvent(topLevelTypes.topWheel, 'wheel', mountAt);
262
+ } else if (isEventSupported('mousewheel')) {
263
+ trapBubbledEvent(topLevelTypes.topWheel, 'mousewheel', mountAt);
264
+ } else {
265
+ // Firefox needs to capture a different mouse scroll event.
266
+ // @see http://www.quirksmode.org/dom/events/tests/scroll.html
267
+ trapBubbledEvent(
268
+ topLevelTypes.topWheel,
269
+ 'DOMMouseScroll',
270
+ mountAt);
271
+ }
272
+ } else if (topLevelType === topLevelTypes.topScroll) {
273
+
274
+ if (isEventSupported('scroll', true)) {
275
+ trapCapturedEvent(topLevelTypes.topScroll, 'scroll', mountAt);
276
+ } else {
277
+ trapBubbledEvent(topLevelTypes.topScroll, 'scroll', window);
278
+ }
279
+ } else if (topLevelType === topLevelTypes.topFocus ||
280
+ topLevelType === topLevelTypes.topBlur) {
281
+
282
+ if (isEventSupported('focus', true)) {
283
+ trapCapturedEvent(topLevelTypes.topFocus, 'focus', mountAt);
284
+ trapCapturedEvent(topLevelTypes.topBlur, 'blur', mountAt);
285
+ } else if (isEventSupported('focusin')) {
286
+ // IE has `focusin` and `focusout` events which bubble.
287
+ // @see http://www.quirksmode.org/blog/archives/2008/04/delegating_the.html
288
+ trapBubbledEvent(topLevelTypes.topFocus, 'focusin', mountAt);
289
+ trapBubbledEvent(topLevelTypes.topBlur, 'focusout', mountAt);
290
+ }
291
+
292
+ // to make sure blur and focus event listeners are only attached once
293
+ isListening[topLevelTypes.topBlur] = true;
294
+ isListening[topLevelTypes.topFocus] = true;
295
+ } else if (topEventMapping[dependency]) {
296
+ trapBubbledEvent(topLevelType, topEventMapping[dependency], mountAt);
297
+ }
298
+
299
+ isListening[dependency] = true;
300
+ }
301
+ }
302
+ },
303
+
304
+ /**
305
+ * Listens to window scroll and resize events. We cache scroll values so that
306
+ * application code can access them without triggering reflows.
307
+ *
308
+ * NOTE: Scroll events do not bubble.
309
+ *
310
+ * @see http://www.quirksmode.org/dom/events/scroll.html
311
+ */
312
+ ensureScrollValueMonitoring: function(){
313
+ if (!isMonitoringScrollValue) {
314
+ var refresh = ViewportMetrics.refreshScrollValues;
315
+ EventListener.listen(window, 'scroll', refresh);
316
+ EventListener.listen(window, 'resize', refresh);
317
+ isMonitoringScrollValue = true;
318
+ }
319
+ },
320
+
321
+ registrationNameModules: EventPluginHub.registrationNameModules,
322
+
323
+ putListener: EventPluginHub.putListener,
324
+
325
+ getListener: EventPluginHub.getListener,
326
+
327
+ deleteListener: EventPluginHub.deleteListener,
328
+
329
+ deleteAllListeners: EventPluginHub.deleteAllListeners,
330
+
331
+ trapBubbledEvent: trapBubbledEvent,
332
+
333
+ trapCapturedEvent: trapCapturedEvent
334
+
335
+ });
336
+
337
+ module.exports = ReactEventEmitter;
@@ -0,0 +1,57 @@
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 ReactEventEmitterMixin
17
+ */
18
+
19
+ "use strict";
20
+
21
+ var EventPluginHub = require("./EventPluginHub");
22
+ var ReactUpdates = require("./ReactUpdates");
23
+
24
+ function runEventQueueInBatch(events) {
25
+ EventPluginHub.enqueueEvents(events);
26
+ EventPluginHub.processEventQueue();
27
+ }
28
+
29
+ var ReactEventEmitterMixin = {
30
+
31
+ /**
32
+ * Streams a fired top-level event to `EventPluginHub` where plugins have the
33
+ * opportunity to create `ReactEvent`s to be dispatched.
34
+ *
35
+ * @param {string} topLevelType Record from `EventConstants`.
36
+ * @param {object} topLevelTarget The listening component root node.
37
+ * @param {string} topLevelTargetID ID of `topLevelTarget`.
38
+ * @param {object} nativeEvent Native environment event.
39
+ */
40
+ handleTopLevel: function(
41
+ topLevelType,
42
+ topLevelTarget,
43
+ topLevelTargetID,
44
+ nativeEvent) {
45
+ var events = EventPluginHub.extractEvents(
46
+ topLevelType,
47
+ topLevelTarget,
48
+ topLevelTargetID,
49
+ nativeEvent
50
+ );
51
+
52
+ // Event queue being processed in the same cycle allows `preventDefault`.
53
+ ReactUpdates.batchedUpdates(runEventQueueInBatch, events);
54
+ }
55
+ };
56
+
57
+ module.exports = ReactEventEmitterMixin;
@@ -0,0 +1,109 @@
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 ReactEventTopLevelCallback
17
+ * @typechecks static-only
18
+ */
19
+
20
+ "use strict";
21
+
22
+ var ReactEventEmitter = require("./ReactEventEmitter");
23
+ var ReactInstanceHandles = require("./ReactInstanceHandles");
24
+ var ReactMount = require("./ReactMount");
25
+
26
+ var getEventTarget = require("./getEventTarget");
27
+
28
+ /**
29
+ * @type {boolean}
30
+ * @private
31
+ */
32
+ var _topLevelListenersEnabled = true;
33
+
34
+ /**
35
+ * Finds the parent React component of `node`.
36
+ *
37
+ * @param {*} node
38
+ * @return {?DOMEventTarget} Parent container, or `null` if the specified node
39
+ * is not nested.
40
+ */
41
+ function findParent(node) {
42
+ // TODO: It may be a good idea to cache this to prevent unnecessary DOM
43
+ // traversal, but caching is difficult to do correctly without using a
44
+ // mutation observer to listen for all DOM changes.
45
+ var nodeID = ReactMount.getID(node);
46
+ var rootID = ReactInstanceHandles.getReactRootIDFromNodeID(nodeID);
47
+ var container = ReactMount.findReactContainerForID(rootID);
48
+ var parent = ReactMount.getFirstReactDOM(container);
49
+ return parent;
50
+ }
51
+
52
+ /**
53
+ * Top-level callback creator used to implement event handling using delegation.
54
+ * This is used via dependency injection.
55
+ */
56
+ var ReactEventTopLevelCallback = {
57
+
58
+ /**
59
+ * Sets whether or not any created callbacks should be enabled.
60
+ *
61
+ * @param {boolean} enabled True if callbacks should be enabled.
62
+ */
63
+ setEnabled: function(enabled) {
64
+ _topLevelListenersEnabled = !!enabled;
65
+ },
66
+
67
+ /**
68
+ * @return {boolean} True if callbacks are enabled.
69
+ */
70
+ isEnabled: function() {
71
+ return _topLevelListenersEnabled;
72
+ },
73
+
74
+ /**
75
+ * Creates a callback for the supplied `topLevelType` that could be added as
76
+ * a listener to the document. The callback computes a `topLevelTarget` which
77
+ * should be the root node of a mounted React component where the listener
78
+ * is attached.
79
+ *
80
+ * @param {string} topLevelType Record from `EventConstants`.
81
+ * @return {function} Callback for handling top-level events.
82
+ */
83
+ createTopLevelCallback: function(topLevelType) {
84
+ return function(nativeEvent) {
85
+ if (!_topLevelListenersEnabled) {
86
+ return;
87
+ }
88
+ var topLevelTarget = ReactMount.getFirstReactDOM(
89
+ getEventTarget(nativeEvent)
90
+ ) || window;
91
+
92
+ // Loop through the hierarchy, in case there's any nested components.
93
+ while (topLevelTarget) {
94
+ var topLevelTargetID = ReactMount.getID(topLevelTarget) || '';
95
+ ReactEventEmitter.handleTopLevel(
96
+ topLevelType,
97
+ topLevelTarget,
98
+ topLevelTargetID,
99
+ nativeEvent
100
+ );
101
+
102
+ topLevelTarget = findParent(topLevelTarget);
103
+ }
104
+ };
105
+ }
106
+
107
+ };
108
+
109
+ module.exports = ReactEventTopLevelCallback;