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.
- package/README.md +10 -231
- package/addons.js +1 -0
- package/lib/AutoFocusMixin.js +30 -0
- package/lib/CSSCore.js +115 -0
- package/lib/CSSProperty.js +121 -0
- package/lib/CSSPropertyOperations.js +97 -0
- package/lib/ChangeEventPlugin.js +387 -0
- package/lib/ClientReactRootIndex.js +30 -0
- package/lib/CompositionEventPlugin.js +260 -0
- package/lib/DOMChildrenOperations.js +165 -0
- package/lib/DOMProperty.js +268 -0
- package/lib/DOMPropertyOperations.js +181 -0
- package/lib/Danger.js +187 -0
- package/lib/DefaultDOMPropertyConfig.js +203 -0
- package/lib/DefaultEventPluginOrder.js +44 -0
- package/lib/EnterLeaveEventPlugin.js +145 -0
- package/lib/EventConstants.js +76 -0
- package/lib/EventListener.js +69 -0
- package/lib/EventPluginHub.js +293 -0
- package/lib/EventPluginRegistry.js +281 -0
- package/lib/EventPluginUtils.js +214 -0
- package/lib/EventPropagators.js +143 -0
- package/lib/ExecutionEnvironment.js +44 -0
- package/lib/LinkedStateMixin.js +46 -0
- package/lib/LinkedValueUtils.js +161 -0
- package/lib/MobileSafariClickEventPlugin.js +63 -0
- package/lib/PooledClass.js +119 -0
- package/lib/React.js +95 -0
- package/lib/ReactCSSTransitionGroup.js +65 -0
- package/lib/ReactCSSTransitionGroupChild.js +138 -0
- package/lib/ReactChildren.js +132 -0
- package/lib/ReactComponent.js +550 -0
- package/lib/ReactComponentBrowserEnvironment.js +158 -0
- package/lib/ReactComponentEnvironment.js +26 -0
- package/lib/ReactCompositeComponent.js +1455 -0
- package/lib/ReactContext.js +67 -0
- package/lib/ReactCurrentOwner.js +39 -0
- package/lib/ReactDOM.js +207 -0
- package/lib/ReactDOMButton.js +68 -0
- package/lib/ReactDOMComponent.js +399 -0
- package/lib/ReactDOMForm.js +59 -0
- package/lib/ReactDOMIDOperations.js +218 -0
- package/lib/ReactDOMImg.js +58 -0
- package/lib/ReactDOMInput.js +181 -0
- package/lib/ReactDOMOption.js +51 -0
- package/lib/ReactDOMSelect.js +179 -0
- package/lib/ReactDOMSelection.js +189 -0
- package/lib/ReactDOMTextarea.js +140 -0
- package/lib/ReactDefaultBatchingStrategy.js +75 -0
- package/lib/ReactDefaultInjection.js +115 -0
- package/lib/ReactDefaultPerf.js +244 -0
- package/lib/ReactDefaultPerfAnalysis.js +199 -0
- package/lib/ReactErrorUtils.js +37 -0
- package/lib/ReactEventEmitter.js +339 -0
- package/lib/ReactEventEmitterMixin.js +57 -0
- package/lib/ReactEventTopLevelCallback.js +149 -0
- package/lib/ReactInjection.js +39 -0
- package/lib/ReactInputSelection.js +140 -0
- package/lib/ReactInstanceHandles.js +338 -0
- package/lib/ReactLink.js +54 -0
- package/lib/ReactMarkupChecksum.js +53 -0
- package/lib/ReactMount.js +641 -0
- package/lib/ReactMountReady.js +95 -0
- package/lib/ReactMultiChild.js +425 -0
- package/lib/ReactMultiChildUpdateTypes.js +38 -0
- package/lib/ReactOwner.js +154 -0
- package/lib/ReactPerf.js +85 -0
- package/lib/ReactPropTransferer.js +147 -0
- package/lib/ReactPropTypeLocationNames.js +31 -0
- package/lib/ReactPropTypeLocations.js +29 -0
- package/lib/ReactPropTypes.js +359 -0
- package/lib/ReactPutListenerQueue.js +61 -0
- package/lib/ReactReconcileTransaction.js +181 -0
- package/lib/ReactRootIndex.js +36 -0
- package/lib/ReactServerRendering.js +59 -0
- package/lib/ReactStateSetters.js +111 -0
- package/lib/ReactTestUtils.js +394 -0
- package/lib/ReactTextComponent.js +99 -0
- package/lib/ReactTransitionChildMapping.js +106 -0
- package/lib/ReactTransitionEvents.js +97 -0
- package/lib/ReactTransitionGroup.js +187 -0
- package/lib/ReactUpdates.js +148 -0
- package/lib/ReactWithAddons.js +51 -0
- package/lib/SelectEventPlugin.js +200 -0
- package/lib/ServerReactRootIndex.js +36 -0
- package/lib/SimpleEventPlugin.js +413 -0
- package/lib/SyntheticClipboardEvent.js +51 -0
- package/lib/SyntheticCompositionEvent.js +51 -0
- package/lib/SyntheticDragEvent.js +44 -0
- package/lib/SyntheticEvent.js +164 -0
- package/lib/SyntheticFocusEvent.js +44 -0
- package/lib/SyntheticKeyboardEvent.js +58 -0
- package/lib/SyntheticMouseEvent.js +85 -0
- package/lib/SyntheticTouchEvent.js +50 -0
- package/lib/SyntheticUIEvent.js +45 -0
- package/lib/SyntheticWheelEvent.js +66 -0
- package/lib/Transaction.js +276 -0
- package/lib/ViewportMetrics.js +37 -0
- package/lib/accumulate.js +54 -0
- package/lib/adler32.js +39 -0
- package/lib/cloneWithProps.js +59 -0
- package/lib/containsNode.js +49 -0
- package/lib/copyProperties.js +54 -0
- package/lib/createArrayFrom.js +91 -0
- package/lib/createFullPageComponent.js +63 -0
- package/lib/createNodesFromMarkup.js +93 -0
- package/lib/createObjectFrom.js +61 -0
- package/lib/cx.js +44 -0
- package/lib/dangerousStyleValue.js +57 -0
- package/lib/emptyFunction.js +43 -0
- package/lib/escapeTextForBrowser.js +47 -0
- package/lib/flattenChildren.js +57 -0
- package/lib/forEachAccumulated.js +36 -0
- package/lib/getActiveElement.js +34 -0
- package/lib/getEventKey.js +85 -0
- package/lib/getEventTarget.js +36 -0
- package/lib/getMarkupWrap.js +118 -0
- package/lib/getNodeForCharacterOffset.js +80 -0
- package/lib/getReactRootElementInContainer.js +40 -0
- package/lib/getTextContentAccessor.js +42 -0
- package/lib/getUnboundedScrollPosition.js +45 -0
- package/lib/hyphenate.js +35 -0
- package/lib/invariant.js +62 -0
- package/lib/isEventSupported.js +70 -0
- package/lib/isNode.js +33 -0
- package/lib/isTextInputElement.js +49 -0
- package/lib/isTextNode.js +30 -0
- package/lib/joinClasses.js +44 -0
- package/lib/keyMirror.js +58 -0
- package/lib/keyOf.js +41 -0
- package/lib/memoizeStringOnly.js +39 -0
- package/lib/merge.js +37 -0
- package/lib/mergeHelpers.js +136 -0
- package/lib/mergeInto.js +45 -0
- package/lib/mixInto.js +34 -0
- package/lib/objMap.js +47 -0
- package/lib/objMapKeyVal.js +47 -0
- package/lib/onlyChild.js +43 -0
- package/lib/performanceNow.js +42 -0
- package/lib/shallowEqual.js +49 -0
- package/lib/shouldUpdateReactComponent.js +58 -0
- package/lib/toArray.js +75 -0
- package/lib/traverseAllChildren.js +189 -0
- package/lib/warning.js +48 -0
- package/package.json +33 -21
- package/react.js +1 -0
- package/.npmignore +0 -7
- package/.travis.yml +0 -7
- package/Jakefile.js +0 -39
- package/LICENSE +0 -19
- package/browser-test/dist.html +0 -90
- package/browser-test/index.html +0 -86
- package/browser-test/min.html +0 -90
- package/dist/react.js +0 -3141
- package/dist/react.min.js +0 -22
- package/doc/advanced.md +0 -174
- package/doc/color-def.graffle +0 -938
- package/doc/color-def.png +0 -0
- package/doc/simple.dot +0 -25
- package/doc/simple.png +0 -0
- package/examples/longer-example.js +0 -41
- package/examples/simple.js +0 -45
- package/examples/using-ast-directly.js +0 -30
- package/examples/using-events1.js +0 -79
- package/examples/using-log-events.js +0 -43
- package/lib/base-task.js +0 -120
- package/lib/cb-task.js +0 -84
- package/lib/core.js +0 -138
- package/lib/dsl.js +0 -138
- package/lib/error.js +0 -55
- package/lib/event-collector.js +0 -81
- package/lib/event-manager.js +0 -89
- package/lib/eventemitter.js +0 -20
- package/lib/finalcb-first-task.js +0 -68
- package/lib/finalcb-task.js +0 -65
- package/lib/id.js +0 -22
- package/lib/input-parser.js +0 -56
- package/lib/log-events.js +0 -101
- package/lib/parse.js +0 -41
- package/lib/promise-resolve.js +0 -50
- package/lib/promise-task.js +0 -93
- package/lib/react.js +0 -59
- package/lib/ret-task.js +0 -71
- package/lib/sprintf.js +0 -18
- package/lib/status.js +0 -14
- package/lib/task.js +0 -251
- package/lib/track-tasks.js +0 -74
- package/lib/validate.js +0 -159
- package/lib/vcon.js +0 -113
- package/lib/when-task.js +0 -84
- package/src/dist.build.requirejs +0 -20
- package/test/ast.mocha.js +0 -136
- package/test/cb-task.mocha.js +0 -220
- package/test/core-deferred.mocha.js +0 -143
- package/test/core-when.mocha.js +0 -96
- package/test/core.mocha.js +0 -589
- package/test/dsl.mocha.js +0 -352
- package/test/event-manager.mocha.js +0 -119
- package/test/exec-options.mocha.js +0 -48
- package/test/finalcb-task.mocha.js +0 -58
- package/test/input-parser.mocha.js +0 -86
- package/test/log-events.mocha.js +0 -88
- package/test/mocha.opts +0 -2
- package/test/module-use.mocha.js +0 -164
- package/test/promise-auto-resolve.mocha.js +0 -68
- package/test/ret-task.mocha.js +0 -220
- package/test/task.mocha.js +0 -42
- package/test/validate-cb-task.mocha.js +0 -100
- package/test/validate-ret-task.mocha.js +0 -110
- package/test/validate.mocha.js +0 -324
- package/test/vcon.mocha.js +0 -193
- package/vendor/chai/chai.js +0 -4251
- package/vendor/jquery/jquery-1.7.1.js +0 -9266
- package/vendor/jquery/jquery-1.7.1.min.js +0 -4
- package/vendor/node/util.js +0 -531
- package/vendor/requirejs/require.js +0 -2045
- package/vendor/requirejs/require.min.js +0 -36
|
@@ -0,0 +1,37 @@
|
|
|
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 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,339 @@
|
|
|
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 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
|
+
eventNameDispatchConfigs: EventPluginHub.eventNameDispatchConfigs,
|
|
322
|
+
|
|
323
|
+
registrationNameModules: EventPluginHub.registrationNameModules,
|
|
324
|
+
|
|
325
|
+
putListener: EventPluginHub.putListener,
|
|
326
|
+
|
|
327
|
+
getListener: EventPluginHub.getListener,
|
|
328
|
+
|
|
329
|
+
deleteListener: EventPluginHub.deleteListener,
|
|
330
|
+
|
|
331
|
+
deleteAllListeners: EventPluginHub.deleteAllListeners,
|
|
332
|
+
|
|
333
|
+
trapBubbledEvent: trapBubbledEvent,
|
|
334
|
+
|
|
335
|
+
trapCapturedEvent: trapCapturedEvent
|
|
336
|
+
|
|
337
|
+
});
|
|
338
|
+
|
|
339
|
+
module.exports = ReactEventEmitter;
|
|
@@ -0,0 +1,57 @@
|
|
|
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 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,149 @@
|
|
|
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 ReactEventTopLevelCallback
|
|
17
|
+
* @typechecks static-only
|
|
18
|
+
*/
|
|
19
|
+
|
|
20
|
+
"use strict";
|
|
21
|
+
|
|
22
|
+
var PooledClass = require("./PooledClass");
|
|
23
|
+
var ReactEventEmitter = require("./ReactEventEmitter");
|
|
24
|
+
var ReactInstanceHandles = require("./ReactInstanceHandles");
|
|
25
|
+
var ReactMount = require("./ReactMount");
|
|
26
|
+
|
|
27
|
+
var getEventTarget = require("./getEventTarget");
|
|
28
|
+
var mixInto = require("./mixInto");
|
|
29
|
+
|
|
30
|
+
/**
|
|
31
|
+
* @type {boolean}
|
|
32
|
+
* @private
|
|
33
|
+
*/
|
|
34
|
+
var _topLevelListenersEnabled = true;
|
|
35
|
+
|
|
36
|
+
/**
|
|
37
|
+
* Finds the parent React component of `node`.
|
|
38
|
+
*
|
|
39
|
+
* @param {*} node
|
|
40
|
+
* @return {?DOMEventTarget} Parent container, or `null` if the specified node
|
|
41
|
+
* is not nested.
|
|
42
|
+
*/
|
|
43
|
+
function findParent(node) {
|
|
44
|
+
// TODO: It may be a good idea to cache this to prevent unnecessary DOM
|
|
45
|
+
// traversal, but caching is difficult to do correctly without using a
|
|
46
|
+
// mutation observer to listen for all DOM changes.
|
|
47
|
+
var nodeID = ReactMount.getID(node);
|
|
48
|
+
var rootID = ReactInstanceHandles.getReactRootIDFromNodeID(nodeID);
|
|
49
|
+
var container = ReactMount.findReactContainerForID(rootID);
|
|
50
|
+
var parent = ReactMount.getFirstReactDOM(container);
|
|
51
|
+
return parent;
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
/**
|
|
55
|
+
* Calls ReactEventEmitter.handleTopLevel for each node stored in bookKeeping's
|
|
56
|
+
* ancestor list. Separated from createTopLevelCallback to avoid try/finally
|
|
57
|
+
* deoptimization.
|
|
58
|
+
*
|
|
59
|
+
* @param {string} topLevelType
|
|
60
|
+
* @param {DOMEvent} nativeEvent
|
|
61
|
+
* @param {TopLevelCallbackBookKeeping} bookKeeping
|
|
62
|
+
*/
|
|
63
|
+
function handleTopLevelImpl(topLevelType, nativeEvent, bookKeeping) {
|
|
64
|
+
var topLevelTarget = ReactMount.getFirstReactDOM(
|
|
65
|
+
getEventTarget(nativeEvent)
|
|
66
|
+
) || window;
|
|
67
|
+
|
|
68
|
+
// Loop through the hierarchy, in case there's any nested components.
|
|
69
|
+
// It's important that we build the array of ancestors before calling any
|
|
70
|
+
// event handlers, because event handlers can modify the DOM, leading to
|
|
71
|
+
// inconsistencies with ReactMount's node cache. See #1105.
|
|
72
|
+
var ancestor = topLevelTarget;
|
|
73
|
+
while (ancestor) {
|
|
74
|
+
bookKeeping.ancestors.push(ancestor);
|
|
75
|
+
ancestor = findParent(ancestor);
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
for (var i = 0, l = bookKeeping.ancestors.length; i < l; i++) {
|
|
79
|
+
topLevelTarget = bookKeeping.ancestors[i];
|
|
80
|
+
var topLevelTargetID = ReactMount.getID(topLevelTarget) || '';
|
|
81
|
+
ReactEventEmitter.handleTopLevel(
|
|
82
|
+
topLevelType,
|
|
83
|
+
topLevelTarget,
|
|
84
|
+
topLevelTargetID,
|
|
85
|
+
nativeEvent
|
|
86
|
+
);
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
// Used to store ancestor hierarchy in top level callback
|
|
91
|
+
function TopLevelCallbackBookKeeping() {
|
|
92
|
+
this.ancestors = [];
|
|
93
|
+
}
|
|
94
|
+
mixInto(TopLevelCallbackBookKeeping, {
|
|
95
|
+
destructor: function() {
|
|
96
|
+
this.ancestors.length = 0;
|
|
97
|
+
}
|
|
98
|
+
});
|
|
99
|
+
PooledClass.addPoolingTo(TopLevelCallbackBookKeeping);
|
|
100
|
+
|
|
101
|
+
/**
|
|
102
|
+
* Top-level callback creator used to implement event handling using delegation.
|
|
103
|
+
* This is used via dependency injection.
|
|
104
|
+
*/
|
|
105
|
+
var ReactEventTopLevelCallback = {
|
|
106
|
+
|
|
107
|
+
/**
|
|
108
|
+
* Sets whether or not any created callbacks should be enabled.
|
|
109
|
+
*
|
|
110
|
+
* @param {boolean} enabled True if callbacks should be enabled.
|
|
111
|
+
*/
|
|
112
|
+
setEnabled: function(enabled) {
|
|
113
|
+
_topLevelListenersEnabled = !!enabled;
|
|
114
|
+
},
|
|
115
|
+
|
|
116
|
+
/**
|
|
117
|
+
* @return {boolean} True if callbacks are enabled.
|
|
118
|
+
*/
|
|
119
|
+
isEnabled: function() {
|
|
120
|
+
return _topLevelListenersEnabled;
|
|
121
|
+
},
|
|
122
|
+
|
|
123
|
+
/**
|
|
124
|
+
* Creates a callback for the supplied `topLevelType` that could be added as
|
|
125
|
+
* a listener to the document. The callback computes a `topLevelTarget` which
|
|
126
|
+
* should be the root node of a mounted React component where the listener
|
|
127
|
+
* is attached.
|
|
128
|
+
*
|
|
129
|
+
* @param {string} topLevelType Record from `EventConstants`.
|
|
130
|
+
* @return {function} Callback for handling top-level events.
|
|
131
|
+
*/
|
|
132
|
+
createTopLevelCallback: function(topLevelType) {
|
|
133
|
+
return function(nativeEvent) {
|
|
134
|
+
if (!_topLevelListenersEnabled) {
|
|
135
|
+
return;
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
var bookKeeping = TopLevelCallbackBookKeeping.getPooled();
|
|
139
|
+
try {
|
|
140
|
+
handleTopLevelImpl(topLevelType, nativeEvent, bookKeeping);
|
|
141
|
+
} finally {
|
|
142
|
+
TopLevelCallbackBookKeeping.release(bookKeeping);
|
|
143
|
+
}
|
|
144
|
+
};
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
};
|
|
148
|
+
|
|
149
|
+
module.exports = ReactEventTopLevelCallback;
|