react 0.12.2 → 0.13.0-alpha.1
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/dist/JSXTransformer.js +6 -4
- package/dist/react-with-addons.js +4022 -3267
- package/dist/react-with-addons.min.js +6 -6
- package/dist/react.js +3853 -3358
- package/dist/react.min.js +6 -6
- package/lib/BeforeInputEventPlugin.js +388 -111
- package/lib/CSSPropertyOperations.js +20 -0
- package/lib/ChangeEventPlugin.js +2 -2
- package/lib/Danger.js +1 -1
- package/lib/DefaultEventPluginOrder.js +0 -1
- package/lib/ExecutionEnvironment.js +2 -3
- package/lib/FallbackCompositionState.js +87 -0
- package/lib/HTMLDOMPropertyConfig.js +1 -0
- package/lib/Object.assign.js +3 -1
- package/lib/React.js +14 -49
- package/lib/ReactBrowserComponentMixin.js +2 -12
- package/lib/ReactBrowserEventEmitter.js +2 -4
- package/lib/ReactCSSTransitionGroup.js +3 -0
- package/lib/ReactCSSTransitionGroupChild.js +8 -0
- package/lib/ReactChildReconciler.js +121 -0
- package/lib/ReactClass.js +916 -0
- package/lib/ReactComponent.js +36 -286
- package/lib/ReactComponentBrowserEnvironment.js +9 -82
- package/lib/ReactComponentEnvironment.js +57 -0
- package/lib/ReactCompositeComponent.js +608 -1026
- package/lib/ReactContext.js +5 -1
- package/lib/ReactDOM.js +2 -7
- package/lib/ReactDOMButton.js +4 -5
- package/lib/ReactDOMComponent.js +97 -69
- package/lib/ReactDOMForm.js +4 -5
- package/lib/ReactDOMIDOperations.js +55 -73
- package/lib/ReactDOMImg.js +3 -5
- package/lib/ReactDOMInput.js +4 -5
- package/lib/ReactDOMOption.js +4 -5
- package/lib/ReactDOMSelect.js +55 -63
- package/lib/ReactDOMSelection.js +5 -1
- package/lib/{ReactTextComponent.js → ReactDOMTextComponent.js} +54 -34
- package/lib/ReactDOMTextarea.js +4 -5
- package/lib/ReactDefaultInjection.js +13 -7
- package/lib/ReactDefaultPerf.js +6 -5
- package/lib/ReactDefaultPerfAnalysis.js +1 -1
- package/lib/ReactElement.js +17 -11
- package/lib/ReactElementValidator.js +74 -37
- package/lib/ReactEmptyComponent.js +17 -10
- package/lib/ReactInjection.js +6 -4
- package/lib/ReactInputSelection.js +2 -3
- package/lib/ReactInstanceMap.js +47 -0
- package/lib/ReactMount.js +193 -64
- package/lib/ReactMultiChild.js +32 -42
- package/lib/ReactNativeComponent.js +45 -8
- package/lib/ReactOwner.js +3 -47
- package/lib/ReactPerf.js +20 -0
- package/lib/ReactPropTransferer.js +0 -55
- package/lib/ReactPropTypes.js +1 -17
- package/lib/ReactRef.js +96 -0
- package/lib/ReactServerRendering.js +3 -2
- package/lib/ReactTestUtils.js +82 -25
- package/lib/ReactTransitionGroup.js +47 -6
- package/lib/ReactUpdates.js +43 -42
- package/lib/SyntheticMouseEvent.js +1 -3
- package/lib/ViewportMetrics.js +1 -4
- package/lib/accumulate.js +47 -0
- package/lib/cloneWithProps.js +2 -2
- package/lib/copyProperties.js +2 -0
- package/lib/createFullPageComponent.js +2 -2
- package/lib/findDOMNode.js +52 -0
- package/lib/flattenChildren.js +1 -14
- package/lib/getIteratorFn.js +42 -0
- package/lib/instantiateReactComponent.js +88 -65
- package/lib/isNode.js +3 -4
- package/lib/isTextInputElement.js +1 -2
- package/lib/shouldUpdateReactComponent.js +13 -5
- package/lib/traverseAllChildren.js +110 -54
- package/package.json +1 -1
- package/lib/CompositionEventPlugin.js +0 -257
- package/lib/ReactLegacyElement.js +0 -243
- package/lib/deprecated.js +0 -47
package/lib/isNode.js
CHANGED
|
@@ -16,10 +16,9 @@
|
|
|
16
16
|
*/
|
|
17
17
|
function isNode(object) {
|
|
18
18
|
return !!(object && (
|
|
19
|
-
typeof Node === 'function' ? object instanceof Node :
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
typeof object.nodeName === 'string'
|
|
19
|
+
((typeof Node === 'function' ? object instanceof Node : typeof object === 'object' &&
|
|
20
|
+
typeof object.nodeType === 'number' &&
|
|
21
|
+
typeof object.nodeName === 'string'))
|
|
23
22
|
));
|
|
24
23
|
}
|
|
25
24
|
|
|
@@ -34,8 +34,7 @@ var supportedInputTypes = {
|
|
|
34
34
|
|
|
35
35
|
function isTextInputElement(elem) {
|
|
36
36
|
return elem && (
|
|
37
|
-
(elem.nodeName === 'INPUT' && supportedInputTypes[elem.type]
|
|
38
|
-
elem.nodeName === 'TEXTAREA'
|
|
37
|
+
(elem.nodeName === 'INPUT' && supportedInputTypes[elem.type] || elem.nodeName === 'TEXTAREA')
|
|
39
38
|
);
|
|
40
39
|
}
|
|
41
40
|
|
|
@@ -24,11 +24,19 @@
|
|
|
24
24
|
* @protected
|
|
25
25
|
*/
|
|
26
26
|
function shouldUpdateReactComponent(prevElement, nextElement) {
|
|
27
|
-
if (prevElement && nextElement
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
27
|
+
if (prevElement != null && nextElement != null) {
|
|
28
|
+
var prevType = typeof prevElement;
|
|
29
|
+
var nextType = typeof nextElement;
|
|
30
|
+
if (prevType === 'string' || prevType === 'number') {
|
|
31
|
+
return (nextType === 'string' || nextType === 'number');
|
|
32
|
+
} else {
|
|
33
|
+
return (
|
|
34
|
+
nextType === 'object' &&
|
|
35
|
+
prevElement.type === nextElement.type &&
|
|
36
|
+
prevElement.key === nextElement.key &&
|
|
37
|
+
prevElement._owner === nextElement._owner
|
|
38
|
+
);
|
|
39
|
+
}
|
|
32
40
|
}
|
|
33
41
|
return false;
|
|
34
42
|
}
|
|
@@ -14,17 +14,15 @@
|
|
|
14
14
|
var ReactElement = require("./ReactElement");
|
|
15
15
|
var ReactInstanceHandles = require("./ReactInstanceHandles");
|
|
16
16
|
|
|
17
|
+
var getIteratorFn = require("./getIteratorFn");
|
|
17
18
|
var invariant = require("./invariant");
|
|
18
19
|
|
|
19
20
|
var SEPARATOR = ReactInstanceHandles.SEPARATOR;
|
|
20
21
|
var SUBSEPARATOR = ':';
|
|
21
22
|
|
|
22
23
|
/**
|
|
23
|
-
* TODO: Test that
|
|
24
|
-
*
|
|
25
|
-
* 2. it('should fail when supplied duplicate key', function() {
|
|
26
|
-
* 3. That a single child and an array with one item have the same key pattern.
|
|
27
|
-
* });
|
|
24
|
+
* TODO: Test that a single child and an array with one item have the same key
|
|
25
|
+
* pattern.
|
|
28
26
|
*/
|
|
29
27
|
|
|
30
28
|
var userProvidedKeyEscaperLookup = {
|
|
@@ -88,58 +86,90 @@ function wrapUserProvidedKey(key) {
|
|
|
88
86
|
* process.
|
|
89
87
|
* @return {!number} The number of children in this subtree.
|
|
90
88
|
*/
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
} else {
|
|
113
|
-
var type = typeof children;
|
|
114
|
-
var isOnlyChild = nameSoFar === '';
|
|
89
|
+
function traverseAllChildrenImpl(
|
|
90
|
+
children,
|
|
91
|
+
nameSoFar,
|
|
92
|
+
indexSoFar,
|
|
93
|
+
callback,
|
|
94
|
+
traverseContext
|
|
95
|
+
) {
|
|
96
|
+
var type = typeof children;
|
|
97
|
+
|
|
98
|
+
if (type === 'undefined' || type === 'boolean') {
|
|
99
|
+
// All of the above are perceived as null.
|
|
100
|
+
children = null;
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
if (children === null ||
|
|
104
|
+
type === 'string' ||
|
|
105
|
+
type === 'number' ||
|
|
106
|
+
ReactElement.isValidElement(children)) {
|
|
107
|
+
callback(
|
|
108
|
+
traverseContext,
|
|
109
|
+
children,
|
|
115
110
|
// If it's the only child, treat the name as if it was wrapped in an array
|
|
116
|
-
// so that it's consistent if the number of children grows
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
111
|
+
// so that it's consistent if the number of children grows.
|
|
112
|
+
nameSoFar === '' ? SEPARATOR + getComponentKey(children, 0) : nameSoFar,
|
|
113
|
+
indexSoFar
|
|
114
|
+
);
|
|
115
|
+
return 1;
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
var child, nextName, nextIndex;
|
|
119
|
+
var subtreeCount = 0; // Count of children found in the current subtree.
|
|
120
|
+
|
|
121
|
+
if (Array.isArray(children)) {
|
|
122
|
+
for (var i = 0; i < children.length; i++) {
|
|
123
|
+
child = children[i];
|
|
124
|
+
nextName = (
|
|
125
|
+
(nameSoFar !== '' ? nameSoFar + SUBSEPARATOR : SEPARATOR) +
|
|
126
|
+
getComponentKey(child, i)
|
|
127
|
+
);
|
|
128
|
+
nextIndex = indexSoFar + subtreeCount;
|
|
129
|
+
subtreeCount += traverseAllChildrenImpl(
|
|
130
|
+
child,
|
|
131
|
+
nextName,
|
|
132
|
+
nextIndex,
|
|
133
|
+
callback,
|
|
134
|
+
traverseContext
|
|
135
|
+
);
|
|
136
|
+
}
|
|
137
|
+
} else {
|
|
138
|
+
var iteratorFn = getIteratorFn(children);
|
|
139
|
+
if (iteratorFn) {
|
|
140
|
+
var iterator = iteratorFn.call(children);
|
|
141
|
+
var step;
|
|
142
|
+
if (iteratorFn !== children.entries) {
|
|
143
|
+
var ii = 0;
|
|
144
|
+
while (!(step = iterator.next()).done) {
|
|
145
|
+
child = step.value;
|
|
146
|
+
nextName = (
|
|
147
|
+
(nameSoFar !== '' ? nameSoFar + SUBSEPARATOR : SEPARATOR) +
|
|
148
|
+
getComponentKey(child, ii++)
|
|
149
|
+
);
|
|
150
|
+
nextIndex = indexSoFar + subtreeCount;
|
|
151
|
+
subtreeCount += traverseAllChildrenImpl(
|
|
152
|
+
child,
|
|
153
|
+
nextName,
|
|
154
|
+
nextIndex,
|
|
155
|
+
callback,
|
|
156
|
+
traverseContext
|
|
157
|
+
);
|
|
158
|
+
}
|
|
159
|
+
} else {
|
|
160
|
+
// Iterator will provide entry [k,v] tuples rather than values.
|
|
161
|
+
while (!(step = iterator.next()).done) {
|
|
162
|
+
var entry = step.value;
|
|
163
|
+
if (entry) {
|
|
164
|
+
child = entry[1];
|
|
135
165
|
nextName = (
|
|
136
|
-
nameSoFar
|
|
137
|
-
wrapUserProvidedKey(
|
|
138
|
-
getComponentKey(
|
|
166
|
+
(nameSoFar !== '' ? nameSoFar + SUBSEPARATOR : SEPARATOR) +
|
|
167
|
+
wrapUserProvidedKey(entry[0]) + SUBSEPARATOR +
|
|
168
|
+
getComponentKey(child, 0)
|
|
139
169
|
);
|
|
140
170
|
nextIndex = indexSoFar + subtreeCount;
|
|
141
171
|
subtreeCount += traverseAllChildrenImpl(
|
|
142
|
-
|
|
172
|
+
child,
|
|
143
173
|
nextName,
|
|
144
174
|
nextIndex,
|
|
145
175
|
callback,
|
|
@@ -148,9 +178,35 @@ var traverseAllChildrenImpl =
|
|
|
148
178
|
}
|
|
149
179
|
}
|
|
150
180
|
}
|
|
181
|
+
} else if (type === 'object') {
|
|
182
|
+
("production" !== process.env.NODE_ENV ? invariant(
|
|
183
|
+
children.nodeType !== 1,
|
|
184
|
+
'traverseAllChildren(...): Encountered an invalid child; DOM ' +
|
|
185
|
+
'elements are not valid children of React components.'
|
|
186
|
+
) : invariant(children.nodeType !== 1));
|
|
187
|
+
for (var key in children) {
|
|
188
|
+
if (children.hasOwnProperty(key)) {
|
|
189
|
+
child = children[key];
|
|
190
|
+
nextName = (
|
|
191
|
+
(nameSoFar !== '' ? nameSoFar + SUBSEPARATOR : SEPARATOR) +
|
|
192
|
+
wrapUserProvidedKey(key) + SUBSEPARATOR +
|
|
193
|
+
getComponentKey(child, 0)
|
|
194
|
+
);
|
|
195
|
+
nextIndex = indexSoFar + subtreeCount;
|
|
196
|
+
subtreeCount += traverseAllChildrenImpl(
|
|
197
|
+
child,
|
|
198
|
+
nextName,
|
|
199
|
+
nextIndex,
|
|
200
|
+
callback,
|
|
201
|
+
traverseContext
|
|
202
|
+
);
|
|
203
|
+
}
|
|
204
|
+
}
|
|
151
205
|
}
|
|
152
|
-
|
|
153
|
-
|
|
206
|
+
}
|
|
207
|
+
|
|
208
|
+
return subtreeCount;
|
|
209
|
+
}
|
|
154
210
|
|
|
155
211
|
/**
|
|
156
212
|
* Traverses children that are typically specified as `props.children`, but
|
package/package.json
CHANGED
|
@@ -1,257 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Copyright 2013-2014, Facebook, Inc.
|
|
3
|
-
* All rights reserved.
|
|
4
|
-
*
|
|
5
|
-
* This source code is licensed under the BSD-style license found in the
|
|
6
|
-
* LICENSE file in the root directory of this source tree. An additional grant
|
|
7
|
-
* of patent rights can be found in the PATENTS file in the same directory.
|
|
8
|
-
*
|
|
9
|
-
* @providesModule CompositionEventPlugin
|
|
10
|
-
* @typechecks static-only
|
|
11
|
-
*/
|
|
12
|
-
|
|
13
|
-
"use strict";
|
|
14
|
-
|
|
15
|
-
var EventConstants = require("./EventConstants");
|
|
16
|
-
var EventPropagators = require("./EventPropagators");
|
|
17
|
-
var ExecutionEnvironment = require("./ExecutionEnvironment");
|
|
18
|
-
var ReactInputSelection = require("./ReactInputSelection");
|
|
19
|
-
var SyntheticCompositionEvent = require("./SyntheticCompositionEvent");
|
|
20
|
-
|
|
21
|
-
var getTextContentAccessor = require("./getTextContentAccessor");
|
|
22
|
-
var keyOf = require("./keyOf");
|
|
23
|
-
|
|
24
|
-
var END_KEYCODES = [9, 13, 27, 32]; // Tab, Return, Esc, Space
|
|
25
|
-
var START_KEYCODE = 229;
|
|
26
|
-
|
|
27
|
-
var useCompositionEvent = (
|
|
28
|
-
ExecutionEnvironment.canUseDOM &&
|
|
29
|
-
'CompositionEvent' in window
|
|
30
|
-
);
|
|
31
|
-
|
|
32
|
-
// In IE9+, we have access to composition events, but the data supplied
|
|
33
|
-
// by the native compositionend event may be incorrect. In Korean, for example,
|
|
34
|
-
// the compositionend event contains only one character regardless of
|
|
35
|
-
// how many characters have been composed since compositionstart.
|
|
36
|
-
// We therefore use the fallback data while still using the native
|
|
37
|
-
// events as triggers.
|
|
38
|
-
var useFallbackData = (
|
|
39
|
-
!useCompositionEvent ||
|
|
40
|
-
(
|
|
41
|
-
'documentMode' in document &&
|
|
42
|
-
document.documentMode > 8 &&
|
|
43
|
-
document.documentMode <= 11
|
|
44
|
-
)
|
|
45
|
-
);
|
|
46
|
-
|
|
47
|
-
var topLevelTypes = EventConstants.topLevelTypes;
|
|
48
|
-
var currentComposition = null;
|
|
49
|
-
|
|
50
|
-
// Events and their corresponding property names.
|
|
51
|
-
var eventTypes = {
|
|
52
|
-
compositionEnd: {
|
|
53
|
-
phasedRegistrationNames: {
|
|
54
|
-
bubbled: keyOf({onCompositionEnd: null}),
|
|
55
|
-
captured: keyOf({onCompositionEndCapture: null})
|
|
56
|
-
},
|
|
57
|
-
dependencies: [
|
|
58
|
-
topLevelTypes.topBlur,
|
|
59
|
-
topLevelTypes.topCompositionEnd,
|
|
60
|
-
topLevelTypes.topKeyDown,
|
|
61
|
-
topLevelTypes.topKeyPress,
|
|
62
|
-
topLevelTypes.topKeyUp,
|
|
63
|
-
topLevelTypes.topMouseDown
|
|
64
|
-
]
|
|
65
|
-
},
|
|
66
|
-
compositionStart: {
|
|
67
|
-
phasedRegistrationNames: {
|
|
68
|
-
bubbled: keyOf({onCompositionStart: null}),
|
|
69
|
-
captured: keyOf({onCompositionStartCapture: null})
|
|
70
|
-
},
|
|
71
|
-
dependencies: [
|
|
72
|
-
topLevelTypes.topBlur,
|
|
73
|
-
topLevelTypes.topCompositionStart,
|
|
74
|
-
topLevelTypes.topKeyDown,
|
|
75
|
-
topLevelTypes.topKeyPress,
|
|
76
|
-
topLevelTypes.topKeyUp,
|
|
77
|
-
topLevelTypes.topMouseDown
|
|
78
|
-
]
|
|
79
|
-
},
|
|
80
|
-
compositionUpdate: {
|
|
81
|
-
phasedRegistrationNames: {
|
|
82
|
-
bubbled: keyOf({onCompositionUpdate: null}),
|
|
83
|
-
captured: keyOf({onCompositionUpdateCapture: null})
|
|
84
|
-
},
|
|
85
|
-
dependencies: [
|
|
86
|
-
topLevelTypes.topBlur,
|
|
87
|
-
topLevelTypes.topCompositionUpdate,
|
|
88
|
-
topLevelTypes.topKeyDown,
|
|
89
|
-
topLevelTypes.topKeyPress,
|
|
90
|
-
topLevelTypes.topKeyUp,
|
|
91
|
-
topLevelTypes.topMouseDown
|
|
92
|
-
]
|
|
93
|
-
}
|
|
94
|
-
};
|
|
95
|
-
|
|
96
|
-
/**
|
|
97
|
-
* Translate native top level events into event types.
|
|
98
|
-
*
|
|
99
|
-
* @param {string} topLevelType
|
|
100
|
-
* @return {object}
|
|
101
|
-
*/
|
|
102
|
-
function getCompositionEventType(topLevelType) {
|
|
103
|
-
switch (topLevelType) {
|
|
104
|
-
case topLevelTypes.topCompositionStart:
|
|
105
|
-
return eventTypes.compositionStart;
|
|
106
|
-
case topLevelTypes.topCompositionEnd:
|
|
107
|
-
return eventTypes.compositionEnd;
|
|
108
|
-
case topLevelTypes.topCompositionUpdate:
|
|
109
|
-
return eventTypes.compositionUpdate;
|
|
110
|
-
}
|
|
111
|
-
}
|
|
112
|
-
|
|
113
|
-
/**
|
|
114
|
-
* Does our fallback best-guess model think this event signifies that
|
|
115
|
-
* composition has begun?
|
|
116
|
-
*
|
|
117
|
-
* @param {string} topLevelType
|
|
118
|
-
* @param {object} nativeEvent
|
|
119
|
-
* @return {boolean}
|
|
120
|
-
*/
|
|
121
|
-
function isFallbackStart(topLevelType, nativeEvent) {
|
|
122
|
-
return (
|
|
123
|
-
topLevelType === topLevelTypes.topKeyDown &&
|
|
124
|
-
nativeEvent.keyCode === START_KEYCODE
|
|
125
|
-
);
|
|
126
|
-
}
|
|
127
|
-
|
|
128
|
-
/**
|
|
129
|
-
* Does our fallback mode think that this event is the end of composition?
|
|
130
|
-
*
|
|
131
|
-
* @param {string} topLevelType
|
|
132
|
-
* @param {object} nativeEvent
|
|
133
|
-
* @return {boolean}
|
|
134
|
-
*/
|
|
135
|
-
function isFallbackEnd(topLevelType, nativeEvent) {
|
|
136
|
-
switch (topLevelType) {
|
|
137
|
-
case topLevelTypes.topKeyUp:
|
|
138
|
-
// Command keys insert or clear IME input.
|
|
139
|
-
return (END_KEYCODES.indexOf(nativeEvent.keyCode) !== -1);
|
|
140
|
-
case topLevelTypes.topKeyDown:
|
|
141
|
-
// Expect IME keyCode on each keydown. If we get any other
|
|
142
|
-
// code we must have exited earlier.
|
|
143
|
-
return (nativeEvent.keyCode !== START_KEYCODE);
|
|
144
|
-
case topLevelTypes.topKeyPress:
|
|
145
|
-
case topLevelTypes.topMouseDown:
|
|
146
|
-
case topLevelTypes.topBlur:
|
|
147
|
-
// Events are not possible without cancelling IME.
|
|
148
|
-
return true;
|
|
149
|
-
default:
|
|
150
|
-
return false;
|
|
151
|
-
}
|
|
152
|
-
}
|
|
153
|
-
|
|
154
|
-
/**
|
|
155
|
-
* Helper class stores information about selection and document state
|
|
156
|
-
* so we can figure out what changed at a later date.
|
|
157
|
-
*
|
|
158
|
-
* @param {DOMEventTarget} root
|
|
159
|
-
*/
|
|
160
|
-
function FallbackCompositionState(root) {
|
|
161
|
-
this.root = root;
|
|
162
|
-
this.startSelection = ReactInputSelection.getSelection(root);
|
|
163
|
-
this.startValue = this.getText();
|
|
164
|
-
}
|
|
165
|
-
|
|
166
|
-
/**
|
|
167
|
-
* Get current text of input.
|
|
168
|
-
*
|
|
169
|
-
* @return {string}
|
|
170
|
-
*/
|
|
171
|
-
FallbackCompositionState.prototype.getText = function() {
|
|
172
|
-
return this.root.value || this.root[getTextContentAccessor()];
|
|
173
|
-
};
|
|
174
|
-
|
|
175
|
-
/**
|
|
176
|
-
* Text that has changed since the start of composition.
|
|
177
|
-
*
|
|
178
|
-
* @return {string}
|
|
179
|
-
*/
|
|
180
|
-
FallbackCompositionState.prototype.getData = function() {
|
|
181
|
-
var endValue = this.getText();
|
|
182
|
-
var prefixLength = this.startSelection.start;
|
|
183
|
-
var suffixLength = this.startValue.length - this.startSelection.end;
|
|
184
|
-
|
|
185
|
-
return endValue.substr(
|
|
186
|
-
prefixLength,
|
|
187
|
-
endValue.length - suffixLength - prefixLength
|
|
188
|
-
);
|
|
189
|
-
};
|
|
190
|
-
|
|
191
|
-
/**
|
|
192
|
-
* This plugin creates `onCompositionStart`, `onCompositionUpdate` and
|
|
193
|
-
* `onCompositionEnd` events on inputs, textareas and contentEditable
|
|
194
|
-
* nodes.
|
|
195
|
-
*/
|
|
196
|
-
var CompositionEventPlugin = {
|
|
197
|
-
|
|
198
|
-
eventTypes: eventTypes,
|
|
199
|
-
|
|
200
|
-
/**
|
|
201
|
-
* @param {string} topLevelType Record from `EventConstants`.
|
|
202
|
-
* @param {DOMEventTarget} topLevelTarget The listening component root node.
|
|
203
|
-
* @param {string} topLevelTargetID ID of `topLevelTarget`.
|
|
204
|
-
* @param {object} nativeEvent Native browser event.
|
|
205
|
-
* @return {*} An accumulation of synthetic events.
|
|
206
|
-
* @see {EventPluginHub.extractEvents}
|
|
207
|
-
*/
|
|
208
|
-
extractEvents: function(
|
|
209
|
-
topLevelType,
|
|
210
|
-
topLevelTarget,
|
|
211
|
-
topLevelTargetID,
|
|
212
|
-
nativeEvent) {
|
|
213
|
-
|
|
214
|
-
var eventType;
|
|
215
|
-
var data;
|
|
216
|
-
|
|
217
|
-
if (useCompositionEvent) {
|
|
218
|
-
eventType = getCompositionEventType(topLevelType);
|
|
219
|
-
} else if (!currentComposition) {
|
|
220
|
-
if (isFallbackStart(topLevelType, nativeEvent)) {
|
|
221
|
-
eventType = eventTypes.compositionStart;
|
|
222
|
-
}
|
|
223
|
-
} else if (isFallbackEnd(topLevelType, nativeEvent)) {
|
|
224
|
-
eventType = eventTypes.compositionEnd;
|
|
225
|
-
}
|
|
226
|
-
|
|
227
|
-
if (useFallbackData) {
|
|
228
|
-
// The current composition is stored statically and must not be
|
|
229
|
-
// overwritten while composition continues.
|
|
230
|
-
if (!currentComposition && eventType === eventTypes.compositionStart) {
|
|
231
|
-
currentComposition = new FallbackCompositionState(topLevelTarget);
|
|
232
|
-
} else if (eventType === eventTypes.compositionEnd) {
|
|
233
|
-
if (currentComposition) {
|
|
234
|
-
data = currentComposition.getData();
|
|
235
|
-
currentComposition = null;
|
|
236
|
-
}
|
|
237
|
-
}
|
|
238
|
-
}
|
|
239
|
-
|
|
240
|
-
if (eventType) {
|
|
241
|
-
var event = SyntheticCompositionEvent.getPooled(
|
|
242
|
-
eventType,
|
|
243
|
-
topLevelTargetID,
|
|
244
|
-
nativeEvent
|
|
245
|
-
);
|
|
246
|
-
if (data) {
|
|
247
|
-
// Inject data generated from fallback path into the synthetic event.
|
|
248
|
-
// This matches the property of native CompositionEventInterface.
|
|
249
|
-
event.data = data;
|
|
250
|
-
}
|
|
251
|
-
EventPropagators.accumulateTwoPhaseDispatches(event);
|
|
252
|
-
return event;
|
|
253
|
-
}
|
|
254
|
-
}
|
|
255
|
-
};
|
|
256
|
-
|
|
257
|
-
module.exports = CompositionEventPlugin;
|