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,148 @@
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 ReactUpdates
17
+ */
18
+
19
+ "use strict";
20
+
21
+ var ReactPerf = require("./ReactPerf");
22
+
23
+ var invariant = require("./invariant");
24
+
25
+ var dirtyComponents = [];
26
+
27
+ var batchingStrategy = null;
28
+
29
+ function ensureBatchingStrategy() {
30
+ ("production" !== process.env.NODE_ENV ? invariant(batchingStrategy, 'ReactUpdates: must inject a batching strategy') : invariant(batchingStrategy));
31
+ }
32
+
33
+ function batchedUpdates(callback, param) {
34
+ ensureBatchingStrategy();
35
+ batchingStrategy.batchedUpdates(callback, param);
36
+ }
37
+
38
+ /**
39
+ * Array comparator for ReactComponents by owner depth
40
+ *
41
+ * @param {ReactComponent} c1 first component you're comparing
42
+ * @param {ReactComponent} c2 second component you're comparing
43
+ * @return {number} Return value usable by Array.prototype.sort().
44
+ */
45
+ function mountDepthComparator(c1, c2) {
46
+ return c1._mountDepth - c2._mountDepth;
47
+ }
48
+
49
+ function runBatchedUpdates() {
50
+ // Since reconciling a component higher in the owner hierarchy usually (not
51
+ // always -- see shouldComponentUpdate()) will reconcile children, reconcile
52
+ // them before their children by sorting the array.
53
+
54
+ dirtyComponents.sort(mountDepthComparator);
55
+
56
+ for (var i = 0; i < dirtyComponents.length; i++) {
57
+ // If a component is unmounted before pending changes apply, ignore them
58
+ // TODO: Queue unmounts in the same list to avoid this happening at all
59
+ var component = dirtyComponents[i];
60
+ if (component.isMounted()) {
61
+ // If performUpdateIfNecessary happens to enqueue any new updates, we
62
+ // shouldn't execute the callbacks until the next render happens, so
63
+ // stash the callbacks first
64
+ var callbacks = component._pendingCallbacks;
65
+ component._pendingCallbacks = null;
66
+ component.performUpdateIfNecessary();
67
+ if (callbacks) {
68
+ for (var j = 0; j < callbacks.length; j++) {
69
+ callbacks[j].call(component);
70
+ }
71
+ }
72
+ }
73
+ }
74
+ }
75
+
76
+ function clearDirtyComponents() {
77
+ dirtyComponents.length = 0;
78
+ }
79
+
80
+ var flushBatchedUpdates = ReactPerf.measure(
81
+ 'ReactUpdates',
82
+ 'flushBatchedUpdates',
83
+ function() {
84
+ // Run these in separate functions so the JIT can optimize
85
+ try {
86
+ runBatchedUpdates();
87
+ } finally {
88
+ clearDirtyComponents();
89
+ }
90
+ }
91
+ );
92
+
93
+ /**
94
+ * Mark a component as needing a rerender, adding an optional callback to a
95
+ * list of functions which will be executed once the rerender occurs.
96
+ */
97
+ function enqueueUpdate(component, callback) {
98
+ ("production" !== process.env.NODE_ENV ? invariant(
99
+ !callback || typeof callback === "function",
100
+ 'enqueueUpdate(...): You called `setProps`, `replaceProps`, ' +
101
+ '`setState`, `replaceState`, or `forceUpdate` with a callback that ' +
102
+ 'isn\'t callable.'
103
+ ) : invariant(!callback || typeof callback === "function"));
104
+ ensureBatchingStrategy();
105
+
106
+ if (!batchingStrategy.isBatchingUpdates) {
107
+ component.performUpdateIfNecessary();
108
+ callback && callback.call(component);
109
+ return;
110
+ }
111
+
112
+ dirtyComponents.push(component);
113
+
114
+ if (callback) {
115
+ if (component._pendingCallbacks) {
116
+ component._pendingCallbacks.push(callback);
117
+ } else {
118
+ component._pendingCallbacks = [callback];
119
+ }
120
+ }
121
+ }
122
+
123
+ var ReactUpdatesInjection = {
124
+ injectBatchingStrategy: function(_batchingStrategy) {
125
+ ("production" !== process.env.NODE_ENV ? invariant(
126
+ _batchingStrategy,
127
+ 'ReactUpdates: must provide a batching strategy'
128
+ ) : invariant(_batchingStrategy));
129
+ ("production" !== process.env.NODE_ENV ? invariant(
130
+ typeof _batchingStrategy.batchedUpdates === 'function',
131
+ 'ReactUpdates: must provide a batchedUpdates() function'
132
+ ) : invariant(typeof _batchingStrategy.batchedUpdates === 'function'));
133
+ ("production" !== process.env.NODE_ENV ? invariant(
134
+ typeof _batchingStrategy.isBatchingUpdates === 'boolean',
135
+ 'ReactUpdates: must provide an isBatchingUpdates boolean attribute'
136
+ ) : invariant(typeof _batchingStrategy.isBatchingUpdates === 'boolean'));
137
+ batchingStrategy = _batchingStrategy;
138
+ }
139
+ };
140
+
141
+ var ReactUpdates = {
142
+ batchedUpdates: batchedUpdates,
143
+ enqueueUpdate: enqueueUpdate,
144
+ flushBatchedUpdates: flushBatchedUpdates,
145
+ injection: ReactUpdatesInjection
146
+ };
147
+
148
+ module.exports = ReactUpdates;
@@ -0,0 +1,51 @@
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 ReactWithAddons
17
+ */
18
+
19
+ /**
20
+ * This module exists purely in the open source project, and is meant as a way
21
+ * to create a separate standalone build of React. This build has "addons", or
22
+ * functionality we've built and think might be useful but doesn't have a good
23
+ * place to live inside React core.
24
+ */
25
+
26
+ "use strict";
27
+
28
+ var LinkedStateMixin = require("./LinkedStateMixin");
29
+ var React = require("./React");
30
+ var ReactCSSTransitionGroup = require("./ReactCSSTransitionGroup");
31
+ var ReactTransitionGroup = require("./ReactTransitionGroup");
32
+ var ReactCSSTransitionGroup = require("./ReactCSSTransitionGroup");
33
+
34
+ var cx = require("./cx");
35
+ var cloneWithProps = require("./cloneWithProps");
36
+
37
+ React.addons = {
38
+ LinkedStateMixin: LinkedStateMixin,
39
+ CSSTransitionGroup: ReactCSSTransitionGroup,
40
+ TransitionGroup: ReactTransitionGroup,
41
+
42
+ classSet: cx,
43
+ cloneWithProps: cloneWithProps
44
+ };
45
+
46
+ if ("production" !== process.env.NODE_ENV) {
47
+ React.addons.TestUtils = require("./ReactTestUtils");
48
+ }
49
+
50
+ module.exports = React;
51
+
@@ -0,0 +1,200 @@
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 SelectEventPlugin
17
+ */
18
+
19
+ "use strict";
20
+
21
+ var EventConstants = require("./EventConstants");
22
+ var EventPropagators = require("./EventPropagators");
23
+ var ReactInputSelection = require("./ReactInputSelection");
24
+ var SyntheticEvent = require("./SyntheticEvent");
25
+
26
+ var getActiveElement = require("./getActiveElement");
27
+ var isTextInputElement = require("./isTextInputElement");
28
+ var keyOf = require("./keyOf");
29
+ var shallowEqual = require("./shallowEqual");
30
+
31
+ var topLevelTypes = EventConstants.topLevelTypes;
32
+
33
+ var eventTypes = {
34
+ select: {
35
+ phasedRegistrationNames: {
36
+ bubbled: keyOf({onSelect: null}),
37
+ captured: keyOf({onSelectCapture: null})
38
+ },
39
+ dependencies: [
40
+ topLevelTypes.topBlur,
41
+ topLevelTypes.topContextMenu,
42
+ topLevelTypes.topFocus,
43
+ topLevelTypes.topKeyDown,
44
+ topLevelTypes.topMouseDown,
45
+ topLevelTypes.topMouseUp,
46
+ topLevelTypes.topSelectionChange
47
+ ]
48
+ }
49
+ };
50
+
51
+ var activeElement = null;
52
+ var activeElementID = null;
53
+ var lastSelection = null;
54
+ var mouseDown = false;
55
+
56
+ /**
57
+ * Get an object which is a unique representation of the current selection.
58
+ *
59
+ * The return value will not be consistent across nodes or browsers, but
60
+ * two identical selections on the same node will return identical objects.
61
+ *
62
+ * @param {DOMElement} node
63
+ * @param {object}
64
+ */
65
+ function getSelection(node) {
66
+ if ('selectionStart' in node &&
67
+ ReactInputSelection.hasSelectionCapabilities(node)) {
68
+ return {
69
+ start: node.selectionStart,
70
+ end: node.selectionEnd
71
+ };
72
+ } else if (document.selection) {
73
+ var range = document.selection.createRange();
74
+ return {
75
+ parentElement: range.parentElement(),
76
+ text: range.text,
77
+ top: range.boundingTop,
78
+ left: range.boundingLeft
79
+ };
80
+ } else {
81
+ var selection = window.getSelection();
82
+ return {
83
+ anchorNode: selection.anchorNode,
84
+ anchorOffset: selection.anchorOffset,
85
+ focusNode: selection.focusNode,
86
+ focusOffset: selection.focusOffset
87
+ };
88
+ }
89
+ }
90
+
91
+ /**
92
+ * Poll selection to see whether it's changed.
93
+ *
94
+ * @param {object} nativeEvent
95
+ * @return {?SyntheticEvent}
96
+ */
97
+ function constructSelectEvent(nativeEvent) {
98
+ // Ensure we have the right element, and that the user is not dragging a
99
+ // selection (this matches native `select` event behavior). In HTML5, select
100
+ // fires only on input and textarea thus if there's no focused element we
101
+ // won't dispatch.
102
+ if (mouseDown ||
103
+ activeElement == null ||
104
+ activeElement != getActiveElement()) {
105
+ return;
106
+ }
107
+
108
+ // Only fire when selection has actually changed.
109
+ var currentSelection = getSelection(activeElement);
110
+ if (!lastSelection || !shallowEqual(lastSelection, currentSelection)) {
111
+ lastSelection = currentSelection;
112
+
113
+ var syntheticEvent = SyntheticEvent.getPooled(
114
+ eventTypes.select,
115
+ activeElementID,
116
+ nativeEvent
117
+ );
118
+
119
+ syntheticEvent.type = 'select';
120
+ syntheticEvent.target = activeElement;
121
+
122
+ EventPropagators.accumulateTwoPhaseDispatches(syntheticEvent);
123
+
124
+ return syntheticEvent;
125
+ }
126
+ }
127
+
128
+ /**
129
+ * This plugin creates an `onSelect` event that normalizes select events
130
+ * across form elements.
131
+ *
132
+ * Supported elements are:
133
+ * - input (see `isTextInputElement`)
134
+ * - textarea
135
+ * - contentEditable
136
+ *
137
+ * This differs from native browser implementations in the following ways:
138
+ * - Fires on contentEditable fields as well as inputs.
139
+ * - Fires for collapsed selection.
140
+ * - Fires after user input.
141
+ */
142
+ var SelectEventPlugin = {
143
+
144
+ eventTypes: eventTypes,
145
+
146
+ /**
147
+ * @param {string} topLevelType Record from `EventConstants`.
148
+ * @param {DOMEventTarget} topLevelTarget The listening component root node.
149
+ * @param {string} topLevelTargetID ID of `topLevelTarget`.
150
+ * @param {object} nativeEvent Native browser event.
151
+ * @return {*} An accumulation of synthetic events.
152
+ * @see {EventPluginHub.extractEvents}
153
+ */
154
+ extractEvents: function(
155
+ topLevelType,
156
+ topLevelTarget,
157
+ topLevelTargetID,
158
+ nativeEvent) {
159
+
160
+ switch (topLevelType) {
161
+ // Track the input node that has focus.
162
+ case topLevelTypes.topFocus:
163
+ if (isTextInputElement(topLevelTarget) ||
164
+ topLevelTarget.contentEditable === 'true') {
165
+ activeElement = topLevelTarget;
166
+ activeElementID = topLevelTargetID;
167
+ lastSelection = null;
168
+ }
169
+ break;
170
+ case topLevelTypes.topBlur:
171
+ activeElement = null;
172
+ activeElementID = null;
173
+ lastSelection = null;
174
+ break;
175
+
176
+ // Don't fire the event while the user is dragging. This matches the
177
+ // semantics of the native select event.
178
+ case topLevelTypes.topMouseDown:
179
+ mouseDown = true;
180
+ break;
181
+ case topLevelTypes.topContextMenu:
182
+ case topLevelTypes.topMouseUp:
183
+ mouseDown = false;
184
+ return constructSelectEvent(nativeEvent);
185
+
186
+ // Chrome and IE fire non-standard event when selection is changed (and
187
+ // sometimes when it hasn't).
188
+ // Firefox doesn't support selectionchange, so check selection status
189
+ // after each key entry. The selection changes after keydown and before
190
+ // keyup, but we check on keydown as well in the case of holding down a
191
+ // key, when multiple keydown events are fired but only one keyup is.
192
+ case topLevelTypes.topSelectionChange:
193
+ case topLevelTypes.topKeyDown:
194
+ case topLevelTypes.topKeyUp:
195
+ return constructSelectEvent(nativeEvent);
196
+ }
197
+ }
198
+ };
199
+
200
+ module.exports = SelectEventPlugin;
@@ -0,0 +1,36 @@
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 ServerReactRootIndex
17
+ * @typechecks
18
+ */
19
+
20
+ "use strict";
21
+
22
+ /**
23
+ * Size of the reactRoot ID space. We generate random numbers for React root
24
+ * IDs and if there's a collision the events and DOM update system will
25
+ * get confused. In the future we need a way to generate GUIDs but for
26
+ * now this will work on a smaller scale.
27
+ */
28
+ var GLOBAL_MOUNT_POINT_MAX = Math.pow(2, 53);
29
+
30
+ var ServerReactRootIndex = {
31
+ createReactRootIndex: function() {
32
+ return Math.ceil(Math.random() * GLOBAL_MOUNT_POINT_MAX);
33
+ }
34
+ };
35
+
36
+ module.exports = ServerReactRootIndex;
@@ -0,0 +1,413 @@
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 SimpleEventPlugin
17
+ */
18
+
19
+ "use strict";
20
+
21
+ var EventConstants = require("./EventConstants");
22
+ var EventPluginUtils = require("./EventPluginUtils");
23
+ var EventPropagators = require("./EventPropagators");
24
+ var SyntheticClipboardEvent = require("./SyntheticClipboardEvent");
25
+ var SyntheticEvent = require("./SyntheticEvent");
26
+ var SyntheticFocusEvent = require("./SyntheticFocusEvent");
27
+ var SyntheticKeyboardEvent = require("./SyntheticKeyboardEvent");
28
+ var SyntheticMouseEvent = require("./SyntheticMouseEvent");
29
+ var SyntheticDragEvent = require("./SyntheticDragEvent");
30
+ var SyntheticTouchEvent = require("./SyntheticTouchEvent");
31
+ var SyntheticUIEvent = require("./SyntheticUIEvent");
32
+ var SyntheticWheelEvent = require("./SyntheticWheelEvent");
33
+
34
+ var invariant = require("./invariant");
35
+ var keyOf = require("./keyOf");
36
+
37
+ var topLevelTypes = EventConstants.topLevelTypes;
38
+
39
+ var eventTypes = {
40
+ blur: {
41
+ phasedRegistrationNames: {
42
+ bubbled: keyOf({onBlur: true}),
43
+ captured: keyOf({onBlurCapture: true})
44
+ }
45
+ },
46
+ click: {
47
+ phasedRegistrationNames: {
48
+ bubbled: keyOf({onClick: true}),
49
+ captured: keyOf({onClickCapture: true})
50
+ }
51
+ },
52
+ contextMenu: {
53
+ phasedRegistrationNames: {
54
+ bubbled: keyOf({onContextMenu: true}),
55
+ captured: keyOf({onContextMenuCapture: true})
56
+ }
57
+ },
58
+ copy: {
59
+ phasedRegistrationNames: {
60
+ bubbled: keyOf({onCopy: true}),
61
+ captured: keyOf({onCopyCapture: true})
62
+ }
63
+ },
64
+ cut: {
65
+ phasedRegistrationNames: {
66
+ bubbled: keyOf({onCut: true}),
67
+ captured: keyOf({onCutCapture: true})
68
+ }
69
+ },
70
+ doubleClick: {
71
+ phasedRegistrationNames: {
72
+ bubbled: keyOf({onDoubleClick: true}),
73
+ captured: keyOf({onDoubleClickCapture: true})
74
+ }
75
+ },
76
+ drag: {
77
+ phasedRegistrationNames: {
78
+ bubbled: keyOf({onDrag: true}),
79
+ captured: keyOf({onDragCapture: true})
80
+ }
81
+ },
82
+ dragEnd: {
83
+ phasedRegistrationNames: {
84
+ bubbled: keyOf({onDragEnd: true}),
85
+ captured: keyOf({onDragEndCapture: true})
86
+ }
87
+ },
88
+ dragEnter: {
89
+ phasedRegistrationNames: {
90
+ bubbled: keyOf({onDragEnter: true}),
91
+ captured: keyOf({onDragEnterCapture: true})
92
+ }
93
+ },
94
+ dragExit: {
95
+ phasedRegistrationNames: {
96
+ bubbled: keyOf({onDragExit: true}),
97
+ captured: keyOf({onDragExitCapture: true})
98
+ }
99
+ },
100
+ dragLeave: {
101
+ phasedRegistrationNames: {
102
+ bubbled: keyOf({onDragLeave: true}),
103
+ captured: keyOf({onDragLeaveCapture: true})
104
+ }
105
+ },
106
+ dragOver: {
107
+ phasedRegistrationNames: {
108
+ bubbled: keyOf({onDragOver: true}),
109
+ captured: keyOf({onDragOverCapture: true})
110
+ }
111
+ },
112
+ dragStart: {
113
+ phasedRegistrationNames: {
114
+ bubbled: keyOf({onDragStart: true}),
115
+ captured: keyOf({onDragStartCapture: true})
116
+ }
117
+ },
118
+ drop: {
119
+ phasedRegistrationNames: {
120
+ bubbled: keyOf({onDrop: true}),
121
+ captured: keyOf({onDropCapture: true})
122
+ }
123
+ },
124
+ focus: {
125
+ phasedRegistrationNames: {
126
+ bubbled: keyOf({onFocus: true}),
127
+ captured: keyOf({onFocusCapture: true})
128
+ }
129
+ },
130
+ input: {
131
+ phasedRegistrationNames: {
132
+ bubbled: keyOf({onInput: true}),
133
+ captured: keyOf({onInputCapture: true})
134
+ }
135
+ },
136
+ keyDown: {
137
+ phasedRegistrationNames: {
138
+ bubbled: keyOf({onKeyDown: true}),
139
+ captured: keyOf({onKeyDownCapture: true})
140
+ }
141
+ },
142
+ keyPress: {
143
+ phasedRegistrationNames: {
144
+ bubbled: keyOf({onKeyPress: true}),
145
+ captured: keyOf({onKeyPressCapture: true})
146
+ }
147
+ },
148
+ keyUp: {
149
+ phasedRegistrationNames: {
150
+ bubbled: keyOf({onKeyUp: true}),
151
+ captured: keyOf({onKeyUpCapture: true})
152
+ }
153
+ },
154
+ load: {
155
+ phasedRegistrationNames: {
156
+ bubbled: keyOf({onLoad: true}),
157
+ captured: keyOf({onLoadCapture: true})
158
+ }
159
+ },
160
+ error: {
161
+ phasedRegistrationNames: {
162
+ bubbled: keyOf({onError: true}),
163
+ captured: keyOf({onErrorCapture: true})
164
+ }
165
+ },
166
+ // Note: We do not allow listening to mouseOver events. Instead, use the
167
+ // onMouseEnter/onMouseLeave created by `EnterLeaveEventPlugin`.
168
+ mouseDown: {
169
+ phasedRegistrationNames: {
170
+ bubbled: keyOf({onMouseDown: true}),
171
+ captured: keyOf({onMouseDownCapture: true})
172
+ }
173
+ },
174
+ mouseMove: {
175
+ phasedRegistrationNames: {
176
+ bubbled: keyOf({onMouseMove: true}),
177
+ captured: keyOf({onMouseMoveCapture: true})
178
+ }
179
+ },
180
+ mouseOut: {
181
+ phasedRegistrationNames: {
182
+ bubbled: keyOf({onMouseOut: true}),
183
+ captured: keyOf({onMouseOutCapture: true})
184
+ }
185
+ },
186
+ mouseOver: {
187
+ phasedRegistrationNames: {
188
+ bubbled: keyOf({onMouseOver: true}),
189
+ captured: keyOf({onMouseOverCapture: true})
190
+ }
191
+ },
192
+ mouseUp: {
193
+ phasedRegistrationNames: {
194
+ bubbled: keyOf({onMouseUp: true}),
195
+ captured: keyOf({onMouseUpCapture: true})
196
+ }
197
+ },
198
+ paste: {
199
+ phasedRegistrationNames: {
200
+ bubbled: keyOf({onPaste: true}),
201
+ captured: keyOf({onPasteCapture: true})
202
+ }
203
+ },
204
+ reset: {
205
+ phasedRegistrationNames: {
206
+ bubbled: keyOf({onReset: true}),
207
+ captured: keyOf({onResetCapture: true})
208
+ }
209
+ },
210
+ scroll: {
211
+ phasedRegistrationNames: {
212
+ bubbled: keyOf({onScroll: true}),
213
+ captured: keyOf({onScrollCapture: true})
214
+ }
215
+ },
216
+ submit: {
217
+ phasedRegistrationNames: {
218
+ bubbled: keyOf({onSubmit: true}),
219
+ captured: keyOf({onSubmitCapture: true})
220
+ }
221
+ },
222
+ touchCancel: {
223
+ phasedRegistrationNames: {
224
+ bubbled: keyOf({onTouchCancel: true}),
225
+ captured: keyOf({onTouchCancelCapture: true})
226
+ }
227
+ },
228
+ touchEnd: {
229
+ phasedRegistrationNames: {
230
+ bubbled: keyOf({onTouchEnd: true}),
231
+ captured: keyOf({onTouchEndCapture: true})
232
+ }
233
+ },
234
+ touchMove: {
235
+ phasedRegistrationNames: {
236
+ bubbled: keyOf({onTouchMove: true}),
237
+ captured: keyOf({onTouchMoveCapture: true})
238
+ }
239
+ },
240
+ touchStart: {
241
+ phasedRegistrationNames: {
242
+ bubbled: keyOf({onTouchStart: true}),
243
+ captured: keyOf({onTouchStartCapture: true})
244
+ }
245
+ },
246
+ wheel: {
247
+ phasedRegistrationNames: {
248
+ bubbled: keyOf({onWheel: true}),
249
+ captured: keyOf({onWheelCapture: true})
250
+ }
251
+ }
252
+ };
253
+
254
+ var topLevelEventsToDispatchConfig = {
255
+ topBlur: eventTypes.blur,
256
+ topClick: eventTypes.click,
257
+ topContextMenu: eventTypes.contextMenu,
258
+ topCopy: eventTypes.copy,
259
+ topCut: eventTypes.cut,
260
+ topDoubleClick: eventTypes.doubleClick,
261
+ topDrag: eventTypes.drag,
262
+ topDragEnd: eventTypes.dragEnd,
263
+ topDragEnter: eventTypes.dragEnter,
264
+ topDragExit: eventTypes.dragExit,
265
+ topDragLeave: eventTypes.dragLeave,
266
+ topDragOver: eventTypes.dragOver,
267
+ topDragStart: eventTypes.dragStart,
268
+ topDrop: eventTypes.drop,
269
+ topError: eventTypes.error,
270
+ topFocus: eventTypes.focus,
271
+ topInput: eventTypes.input,
272
+ topKeyDown: eventTypes.keyDown,
273
+ topKeyPress: eventTypes.keyPress,
274
+ topKeyUp: eventTypes.keyUp,
275
+ topLoad: eventTypes.load,
276
+ topMouseDown: eventTypes.mouseDown,
277
+ topMouseMove: eventTypes.mouseMove,
278
+ topMouseOut: eventTypes.mouseOut,
279
+ topMouseOver: eventTypes.mouseOver,
280
+ topMouseUp: eventTypes.mouseUp,
281
+ topPaste: eventTypes.paste,
282
+ topReset: eventTypes.reset,
283
+ topScroll: eventTypes.scroll,
284
+ topSubmit: eventTypes.submit,
285
+ topTouchCancel: eventTypes.touchCancel,
286
+ topTouchEnd: eventTypes.touchEnd,
287
+ topTouchMove: eventTypes.touchMove,
288
+ topTouchStart: eventTypes.touchStart,
289
+ topWheel: eventTypes.wheel
290
+ };
291
+
292
+ for (var topLevelType in topLevelEventsToDispatchConfig) {
293
+ topLevelEventsToDispatchConfig[topLevelType].dependencies = [topLevelType];
294
+ }
295
+
296
+ var SimpleEventPlugin = {
297
+
298
+ eventTypes: eventTypes,
299
+
300
+ /**
301
+ * Same as the default implementation, except cancels the event when return
302
+ * value is false.
303
+ *
304
+ * @param {object} Event to be dispatched.
305
+ * @param {function} Application-level callback.
306
+ * @param {string} domID DOM ID to pass to the callback.
307
+ */
308
+ executeDispatch: function(event, listener, domID) {
309
+ var returnValue = EventPluginUtils.executeDispatch(event, listener, domID);
310
+ if (returnValue === false) {
311
+ event.stopPropagation();
312
+ event.preventDefault();
313
+ }
314
+ },
315
+
316
+ /**
317
+ * @param {string} topLevelType Record from `EventConstants`.
318
+ * @param {DOMEventTarget} topLevelTarget The listening component root node.
319
+ * @param {string} topLevelTargetID ID of `topLevelTarget`.
320
+ * @param {object} nativeEvent Native browser event.
321
+ * @return {*} An accumulation of synthetic events.
322
+ * @see {EventPluginHub.extractEvents}
323
+ */
324
+ extractEvents: function(
325
+ topLevelType,
326
+ topLevelTarget,
327
+ topLevelTargetID,
328
+ nativeEvent) {
329
+ var dispatchConfig = topLevelEventsToDispatchConfig[topLevelType];
330
+ if (!dispatchConfig) {
331
+ return null;
332
+ }
333
+ var EventConstructor;
334
+ switch (topLevelType) {
335
+ case topLevelTypes.topInput:
336
+ case topLevelTypes.topLoad:
337
+ case topLevelTypes.topError:
338
+ case topLevelTypes.topReset:
339
+ case topLevelTypes.topSubmit:
340
+ // HTML Events
341
+ // @see http://www.w3.org/TR/html5/index.html#events-0
342
+ EventConstructor = SyntheticEvent;
343
+ break;
344
+ case topLevelTypes.topKeyDown:
345
+ case topLevelTypes.topKeyPress:
346
+ case topLevelTypes.topKeyUp:
347
+ EventConstructor = SyntheticKeyboardEvent;
348
+ break;
349
+ case topLevelTypes.topBlur:
350
+ case topLevelTypes.topFocus:
351
+ EventConstructor = SyntheticFocusEvent;
352
+ break;
353
+ case topLevelTypes.topClick:
354
+ // Firefox creates a click event on right mouse clicks. This removes the
355
+ // unwanted click events.
356
+ if (nativeEvent.button === 2) {
357
+ return null;
358
+ }
359
+ /* falls through */
360
+ case topLevelTypes.topContextMenu:
361
+ case topLevelTypes.topDoubleClick:
362
+ case topLevelTypes.topMouseDown:
363
+ case topLevelTypes.topMouseMove:
364
+ case topLevelTypes.topMouseOut:
365
+ case topLevelTypes.topMouseOver:
366
+ case topLevelTypes.topMouseUp:
367
+ EventConstructor = SyntheticMouseEvent;
368
+ break;
369
+ case topLevelTypes.topDrag:
370
+ case topLevelTypes.topDragEnd:
371
+ case topLevelTypes.topDragEnter:
372
+ case topLevelTypes.topDragExit:
373
+ case topLevelTypes.topDragLeave:
374
+ case topLevelTypes.topDragOver:
375
+ case topLevelTypes.topDragStart:
376
+ case topLevelTypes.topDrop:
377
+ EventConstructor = SyntheticDragEvent;
378
+ break;
379
+ case topLevelTypes.topTouchCancel:
380
+ case topLevelTypes.topTouchEnd:
381
+ case topLevelTypes.topTouchMove:
382
+ case topLevelTypes.topTouchStart:
383
+ EventConstructor = SyntheticTouchEvent;
384
+ break;
385
+ case topLevelTypes.topScroll:
386
+ EventConstructor = SyntheticUIEvent;
387
+ break;
388
+ case topLevelTypes.topWheel:
389
+ EventConstructor = SyntheticWheelEvent;
390
+ break;
391
+ case topLevelTypes.topCopy:
392
+ case topLevelTypes.topCut:
393
+ case topLevelTypes.topPaste:
394
+ EventConstructor = SyntheticClipboardEvent;
395
+ break;
396
+ }
397
+ ("production" !== process.env.NODE_ENV ? invariant(
398
+ EventConstructor,
399
+ 'SimpleEventPlugin: Unhandled event type, `%s`.',
400
+ topLevelType
401
+ ) : invariant(EventConstructor));
402
+ var event = EventConstructor.getPooled(
403
+ dispatchConfig,
404
+ topLevelTargetID,
405
+ nativeEvent
406
+ );
407
+ EventPropagators.accumulateTwoPhaseDispatches(event);
408
+ return event;
409
+ }
410
+
411
+ };
412
+
413
+ module.exports = SimpleEventPlugin;