react 0.12.1 → 0.13.0-beta.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 +352 -251
- package/dist/react-with-addons.js +5409 -4242
- package/dist/react-with-addons.min.js +5 -6
- package/dist/react.js +5012 -4136
- package/dist/react.min.js +5 -6
- package/lib/AutoFocusMixin.js +1 -1
- package/lib/BeforeInputEventPlugin.js +389 -112
- package/lib/CSSProperty.js +6 -3
- package/lib/CSSPropertyOperations.js +57 -10
- package/lib/CallbackQueue.js +2 -2
- package/lib/ChangeEventPlugin.js +3 -3
- package/lib/ClientReactRootIndex.js +1 -1
- package/lib/DOMChildrenOperations.js +6 -4
- package/lib/DOMProperty.js +1 -1
- package/lib/DOMPropertyOperations.js +4 -2
- package/lib/Danger.js +7 -6
- package/lib/DefaultEventPluginOrder.js +1 -2
- package/lib/EnterLeaveEventPlugin.js +1 -1
- package/lib/EventConstants.js +1 -1
- package/lib/EventPluginHub.js +9 -7
- package/lib/EventPluginRegistry.js +1 -1
- package/lib/EventPluginUtils.js +1 -1
- package/lib/EventPropagators.js +1 -1
- package/lib/ExecutionEnvironment.js +2 -3
- package/lib/FallbackCompositionState.js +89 -0
- package/lib/HTMLDOMPropertyConfig.js +19 -7
- package/lib/LinkedStateMixin.js +1 -1
- package/lib/LinkedValueUtils.js +3 -3
- package/lib/LocalEventTrapMixin.js +9 -2
- package/lib/MobileSafariClickEventPlugin.js +1 -1
- package/lib/Object.assign.js +3 -1
- package/lib/PooledClass.js +1 -1
- package/lib/React.js +17 -51
- package/lib/ReactBrowserComponentMixin.js +3 -13
- package/lib/ReactBrowserEventEmitter.js +4 -6
- package/lib/ReactCSSTransitionGroup.js +4 -1
- package/lib/ReactCSSTransitionGroupChild.js +12 -2
- package/lib/ReactChildReconciler.js +125 -0
- package/lib/ReactChildren.js +10 -8
- package/lib/ReactClass.js +916 -0
- package/lib/ReactComponent.js +81 -404
- package/lib/ReactComponentBrowserEnvironment.js +10 -83
- package/lib/ReactComponentEnvironment.js +57 -0
- package/lib/ReactComponentWithPureRenderMixin.js +1 -1
- package/lib/ReactCompositeComponent.js +533 -1132
- package/lib/ReactContext.js +6 -2
- package/lib/ReactCurrentOwner.js +1 -1
- package/lib/ReactDOM.js +3 -8
- package/lib/ReactDOMButton.js +5 -6
- package/lib/ReactDOMComponent.js +110 -92
- package/lib/ReactDOMForm.js +5 -6
- package/lib/ReactDOMIDOperations.js +56 -74
- package/lib/ReactDOMImg.js +4 -6
- package/lib/ReactDOMInput.js +5 -6
- package/lib/ReactDOMOption.js +5 -6
- package/lib/ReactDOMSelect.js +57 -65
- package/lib/ReactDOMSelection.js +6 -2
- package/lib/{ReactTextComponent.js → ReactDOMTextComponent.js} +48 -35
- package/lib/ReactDOMTextarea.js +5 -6
- package/lib/ReactDefaultBatchingStrategy.js +4 -4
- package/lib/ReactDefaultInjection.js +14 -8
- package/lib/ReactDefaultPerf.js +16 -7
- package/lib/ReactDefaultPerfAnalysis.js +1 -1
- package/lib/ReactElement.js +23 -15
- package/lib/ReactElementValidator.js +209 -57
- package/lib/ReactEmptyComponent.js +29 -11
- package/lib/ReactEventEmitterMixin.js +1 -1
- package/lib/ReactEventListener.js +3 -4
- package/lib/ReactInjection.js +7 -5
- package/lib/ReactInputSelection.js +3 -4
- package/lib/ReactInstanceHandles.js +3 -2
- package/lib/ReactInstanceMap.js +47 -0
- package/lib/ReactLifeCycle.js +35 -0
- package/lib/ReactLink.js +1 -1
- package/lib/ReactMarkupChecksum.js +1 -1
- package/lib/ReactMount.js +239 -68
- package/lib/ReactMultiChild.js +49 -47
- package/lib/ReactMultiChildUpdateTypes.js +1 -1
- package/lib/ReactNativeComponent.js +72 -25
- package/lib/ReactOwner.js +4 -48
- package/lib/ReactPerf.js +21 -1
- package/lib/ReactPropTransferer.js +2 -57
- package/lib/ReactPropTypeLocationNames.js +1 -1
- package/lib/ReactPropTypeLocations.js +1 -1
- package/lib/ReactPropTypes.js +14 -22
- package/lib/ReactPutListenerQueue.js +1 -1
- package/lib/ReactReconcileTransaction.js +1 -1
- package/lib/ReactReconciler.js +107 -0
- package/lib/ReactRef.js +70 -0
- package/lib/ReactRootIndex.js +1 -1
- package/lib/ReactServerRendering.js +5 -3
- package/lib/ReactServerRenderingTransaction.js +1 -1
- package/lib/ReactStateSetters.js +1 -1
- package/lib/ReactTestUtils.js +112 -26
- package/lib/ReactTransitionChildMapping.js +1 -1
- package/lib/ReactTransitionEvents.js +1 -1
- package/lib/ReactTransitionGroup.js +48 -7
- package/lib/ReactUpdateQueue.js +264 -0
- package/lib/ReactUpdates.js +48 -61
- package/lib/ReactWithAddons.js +1 -1
- package/lib/SVGDOMPropertyConfig.js +1 -1
- package/lib/SelectEventPlugin.js +3 -3
- package/lib/ServerReactRootIndex.js +1 -1
- package/lib/SimpleEventPlugin.js +1 -1
- package/lib/SyntheticClipboardEvent.js +1 -2
- package/lib/SyntheticCompositionEvent.js +1 -2
- package/lib/SyntheticDragEvent.js +1 -1
- package/lib/SyntheticEvent.js +11 -3
- package/lib/SyntheticFocusEvent.js +1 -1
- package/lib/SyntheticInputEvent.js +1 -2
- package/lib/SyntheticKeyboardEvent.js +1 -1
- package/lib/SyntheticMouseEvent.js +2 -4
- package/lib/SyntheticTouchEvent.js +1 -1
- package/lib/SyntheticUIEvent.js +1 -1
- package/lib/SyntheticWheelEvent.js +1 -1
- package/lib/Transaction.js +3 -3
- package/lib/ViewportMetrics.js +2 -5
- package/lib/accumulateInto.js +1 -1
- package/lib/adler32.js +1 -1
- package/lib/cloneWithProps.js +3 -3
- package/lib/copyProperties.js +2 -0
- package/lib/createFullPageComponent.js +3 -3
- package/lib/dangerousStyleValue.js +1 -1
- package/lib/escapeTextForBrowser.js +6 -6
- package/lib/findDOMNode.js +51 -0
- package/lib/flattenChildren.js +11 -22
- package/lib/forEachAccumulated.js +1 -1
- package/lib/getEventCharCode.js +1 -1
- package/lib/getEventKey.js +1 -1
- package/lib/getEventModifierState.js +1 -1
- package/lib/getEventTarget.js +1 -1
- package/lib/getIteratorFn.js +42 -0
- package/lib/getNodeForCharacterOffset.js +2 -2
- package/lib/getReactRootElementInContainer.js +1 -1
- package/lib/getTextContentAccessor.js +1 -1
- package/lib/instantiateReactComponent.js +85 -67
- package/lib/isEventSupported.js +1 -1
- package/lib/isNode.js +3 -4
- package/lib/isTextInputElement.js +2 -3
- package/lib/joinClasses.js +1 -1
- package/lib/keyMirror.js +1 -1
- package/lib/memoizeStringOnly.js +4 -5
- package/lib/onlyChild.js +1 -1
- package/lib/setInnerHTML.js +12 -1
- package/lib/shallowEqual.js +1 -1
- package/lib/shouldUpdateReactComponent.js +48 -6
- package/lib/traverseAllChildren.js +111 -55
- package/lib/update.js +1 -1
- package/lib/warning.js +12 -1
- package/package.json +1 -1
- package/lib/CompositionEventPlugin.js +0 -257
- package/lib/ReactLegacyElement.js +0 -243
- package/lib/deprecated.js +0 -47
|
@@ -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;
|
|
@@ -1,243 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Copyright 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 ReactLegacyElement
|
|
10
|
-
*/
|
|
11
|
-
|
|
12
|
-
"use strict";
|
|
13
|
-
|
|
14
|
-
var ReactCurrentOwner = require("./ReactCurrentOwner");
|
|
15
|
-
|
|
16
|
-
var invariant = require("./invariant");
|
|
17
|
-
var monitorCodeUse = require("./monitorCodeUse");
|
|
18
|
-
var warning = require("./warning");
|
|
19
|
-
|
|
20
|
-
var legacyFactoryLogs = {};
|
|
21
|
-
function warnForLegacyFactoryCall() {
|
|
22
|
-
if (!ReactLegacyElementFactory._isLegacyCallWarningEnabled) {
|
|
23
|
-
return;
|
|
24
|
-
}
|
|
25
|
-
var owner = ReactCurrentOwner.current;
|
|
26
|
-
var name = owner && owner.constructor ? owner.constructor.displayName : '';
|
|
27
|
-
if (!name) {
|
|
28
|
-
name = 'Something';
|
|
29
|
-
}
|
|
30
|
-
if (legacyFactoryLogs.hasOwnProperty(name)) {
|
|
31
|
-
return;
|
|
32
|
-
}
|
|
33
|
-
legacyFactoryLogs[name] = true;
|
|
34
|
-
("production" !== process.env.NODE_ENV ? warning(
|
|
35
|
-
false,
|
|
36
|
-
name + ' is calling a React component directly. ' +
|
|
37
|
-
'Use a factory or JSX instead. See: http://fb.me/react-legacyfactory'
|
|
38
|
-
) : null);
|
|
39
|
-
monitorCodeUse('react_legacy_factory_call', { version: 3, name: name });
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
function warnForPlainFunctionType(type) {
|
|
43
|
-
var isReactClass =
|
|
44
|
-
type.prototype &&
|
|
45
|
-
typeof type.prototype.mountComponent === 'function' &&
|
|
46
|
-
typeof type.prototype.receiveComponent === 'function';
|
|
47
|
-
if (isReactClass) {
|
|
48
|
-
("production" !== process.env.NODE_ENV ? warning(
|
|
49
|
-
false,
|
|
50
|
-
'Did not expect to get a React class here. Use `Component` instead ' +
|
|
51
|
-
'of `Component.type` or `this.constructor`.'
|
|
52
|
-
) : null);
|
|
53
|
-
} else {
|
|
54
|
-
if (!type._reactWarnedForThisType) {
|
|
55
|
-
try {
|
|
56
|
-
type._reactWarnedForThisType = true;
|
|
57
|
-
} catch (x) {
|
|
58
|
-
// just incase this is a frozen object or some special object
|
|
59
|
-
}
|
|
60
|
-
monitorCodeUse(
|
|
61
|
-
'react_non_component_in_jsx',
|
|
62
|
-
{ version: 3, name: type.name }
|
|
63
|
-
);
|
|
64
|
-
}
|
|
65
|
-
("production" !== process.env.NODE_ENV ? warning(
|
|
66
|
-
false,
|
|
67
|
-
'This JSX uses a plain function. Only React components are ' +
|
|
68
|
-
'valid in React\'s JSX transform.'
|
|
69
|
-
) : null);
|
|
70
|
-
}
|
|
71
|
-
}
|
|
72
|
-
|
|
73
|
-
function warnForNonLegacyFactory(type) {
|
|
74
|
-
("production" !== process.env.NODE_ENV ? warning(
|
|
75
|
-
false,
|
|
76
|
-
'Do not pass React.DOM.' + type.type + ' to JSX or createFactory. ' +
|
|
77
|
-
'Use the string "' + type.type + '" instead.'
|
|
78
|
-
) : null);
|
|
79
|
-
}
|
|
80
|
-
|
|
81
|
-
/**
|
|
82
|
-
* Transfer static properties from the source to the target. Functions are
|
|
83
|
-
* rebound to have this reflect the original source.
|
|
84
|
-
*/
|
|
85
|
-
function proxyStaticMethods(target, source) {
|
|
86
|
-
if (typeof source !== 'function') {
|
|
87
|
-
return;
|
|
88
|
-
}
|
|
89
|
-
for (var key in source) {
|
|
90
|
-
if (source.hasOwnProperty(key)) {
|
|
91
|
-
var value = source[key];
|
|
92
|
-
if (typeof value === 'function') {
|
|
93
|
-
var bound = value.bind(source);
|
|
94
|
-
// Copy any properties defined on the function, such as `isRequired` on
|
|
95
|
-
// a PropTypes validator.
|
|
96
|
-
for (var k in value) {
|
|
97
|
-
if (value.hasOwnProperty(k)) {
|
|
98
|
-
bound[k] = value[k];
|
|
99
|
-
}
|
|
100
|
-
}
|
|
101
|
-
target[key] = bound;
|
|
102
|
-
} else {
|
|
103
|
-
target[key] = value;
|
|
104
|
-
}
|
|
105
|
-
}
|
|
106
|
-
}
|
|
107
|
-
}
|
|
108
|
-
|
|
109
|
-
// We use an object instead of a boolean because booleans are ignored by our
|
|
110
|
-
// mocking libraries when these factories gets mocked.
|
|
111
|
-
var LEGACY_MARKER = {};
|
|
112
|
-
var NON_LEGACY_MARKER = {};
|
|
113
|
-
|
|
114
|
-
var ReactLegacyElementFactory = {};
|
|
115
|
-
|
|
116
|
-
ReactLegacyElementFactory.wrapCreateFactory = function(createFactory) {
|
|
117
|
-
var legacyCreateFactory = function(type) {
|
|
118
|
-
if (typeof type !== 'function') {
|
|
119
|
-
// Non-function types cannot be legacy factories
|
|
120
|
-
return createFactory(type);
|
|
121
|
-
}
|
|
122
|
-
|
|
123
|
-
if (type.isReactNonLegacyFactory) {
|
|
124
|
-
// This is probably a factory created by ReactDOM we unwrap it to get to
|
|
125
|
-
// the underlying string type. It shouldn't have been passed here so we
|
|
126
|
-
// warn.
|
|
127
|
-
if ("production" !== process.env.NODE_ENV) {
|
|
128
|
-
warnForNonLegacyFactory(type);
|
|
129
|
-
}
|
|
130
|
-
return createFactory(type.type);
|
|
131
|
-
}
|
|
132
|
-
|
|
133
|
-
if (type.isReactLegacyFactory) {
|
|
134
|
-
// This is probably a legacy factory created by ReactCompositeComponent.
|
|
135
|
-
// We unwrap it to get to the underlying class.
|
|
136
|
-
return createFactory(type.type);
|
|
137
|
-
}
|
|
138
|
-
|
|
139
|
-
if ("production" !== process.env.NODE_ENV) {
|
|
140
|
-
warnForPlainFunctionType(type);
|
|
141
|
-
}
|
|
142
|
-
|
|
143
|
-
// Unless it's a legacy factory, then this is probably a plain function,
|
|
144
|
-
// that is expecting to be invoked by JSX. We can just return it as is.
|
|
145
|
-
return type;
|
|
146
|
-
};
|
|
147
|
-
return legacyCreateFactory;
|
|
148
|
-
};
|
|
149
|
-
|
|
150
|
-
ReactLegacyElementFactory.wrapCreateElement = function(createElement) {
|
|
151
|
-
var legacyCreateElement = function(type, props, children) {
|
|
152
|
-
if (typeof type !== 'function') {
|
|
153
|
-
// Non-function types cannot be legacy factories
|
|
154
|
-
return createElement.apply(this, arguments);
|
|
155
|
-
}
|
|
156
|
-
|
|
157
|
-
var args;
|
|
158
|
-
|
|
159
|
-
if (type.isReactNonLegacyFactory) {
|
|
160
|
-
// This is probably a factory created by ReactDOM we unwrap it to get to
|
|
161
|
-
// the underlying string type. It shouldn't have been passed here so we
|
|
162
|
-
// warn.
|
|
163
|
-
if ("production" !== process.env.NODE_ENV) {
|
|
164
|
-
warnForNonLegacyFactory(type);
|
|
165
|
-
}
|
|
166
|
-
args = Array.prototype.slice.call(arguments, 0);
|
|
167
|
-
args[0] = type.type;
|
|
168
|
-
return createElement.apply(this, args);
|
|
169
|
-
}
|
|
170
|
-
|
|
171
|
-
if (type.isReactLegacyFactory) {
|
|
172
|
-
// This is probably a legacy factory created by ReactCompositeComponent.
|
|
173
|
-
// We unwrap it to get to the underlying class.
|
|
174
|
-
if (type._isMockFunction) {
|
|
175
|
-
// If this is a mock function, people will expect it to be called. We
|
|
176
|
-
// will actually call the original mock factory function instead. This
|
|
177
|
-
// future proofs unit testing that assume that these are classes.
|
|
178
|
-
type.type._mockedReactClassConstructor = type;
|
|
179
|
-
}
|
|
180
|
-
args = Array.prototype.slice.call(arguments, 0);
|
|
181
|
-
args[0] = type.type;
|
|
182
|
-
return createElement.apply(this, args);
|
|
183
|
-
}
|
|
184
|
-
|
|
185
|
-
if ("production" !== process.env.NODE_ENV) {
|
|
186
|
-
warnForPlainFunctionType(type);
|
|
187
|
-
}
|
|
188
|
-
|
|
189
|
-
// This is being called with a plain function we should invoke it
|
|
190
|
-
// immediately as if this was used with legacy JSX.
|
|
191
|
-
return type.apply(null, Array.prototype.slice.call(arguments, 1));
|
|
192
|
-
};
|
|
193
|
-
return legacyCreateElement;
|
|
194
|
-
};
|
|
195
|
-
|
|
196
|
-
ReactLegacyElementFactory.wrapFactory = function(factory) {
|
|
197
|
-
("production" !== process.env.NODE_ENV ? invariant(
|
|
198
|
-
typeof factory === 'function',
|
|
199
|
-
'This is suppose to accept a element factory'
|
|
200
|
-
) : invariant(typeof factory === 'function'));
|
|
201
|
-
var legacyElementFactory = function(config, children) {
|
|
202
|
-
// This factory should not be called when JSX is used. Use JSX instead.
|
|
203
|
-
if ("production" !== process.env.NODE_ENV) {
|
|
204
|
-
warnForLegacyFactoryCall();
|
|
205
|
-
}
|
|
206
|
-
return factory.apply(this, arguments);
|
|
207
|
-
};
|
|
208
|
-
proxyStaticMethods(legacyElementFactory, factory.type);
|
|
209
|
-
legacyElementFactory.isReactLegacyFactory = LEGACY_MARKER;
|
|
210
|
-
legacyElementFactory.type = factory.type;
|
|
211
|
-
return legacyElementFactory;
|
|
212
|
-
};
|
|
213
|
-
|
|
214
|
-
// This is used to mark a factory that will remain. E.g. we're allowed to call
|
|
215
|
-
// it as a function. However, you're not suppose to pass it to createElement
|
|
216
|
-
// or createFactory, so it will warn you if you do.
|
|
217
|
-
ReactLegacyElementFactory.markNonLegacyFactory = function(factory) {
|
|
218
|
-
factory.isReactNonLegacyFactory = NON_LEGACY_MARKER;
|
|
219
|
-
return factory;
|
|
220
|
-
};
|
|
221
|
-
|
|
222
|
-
// Checks if a factory function is actually a legacy factory pretending to
|
|
223
|
-
// be a class.
|
|
224
|
-
ReactLegacyElementFactory.isValidFactory = function(factory) {
|
|
225
|
-
// TODO: This will be removed and moved into a class validator or something.
|
|
226
|
-
return typeof factory === 'function' &&
|
|
227
|
-
factory.isReactLegacyFactory === LEGACY_MARKER;
|
|
228
|
-
};
|
|
229
|
-
|
|
230
|
-
ReactLegacyElementFactory.isValidClass = function(factory) {
|
|
231
|
-
if ("production" !== process.env.NODE_ENV) {
|
|
232
|
-
("production" !== process.env.NODE_ENV ? warning(
|
|
233
|
-
false,
|
|
234
|
-
'isValidClass is deprecated and will be removed in a future release. ' +
|
|
235
|
-
'Use a more specific validator instead.'
|
|
236
|
-
) : null);
|
|
237
|
-
}
|
|
238
|
-
return ReactLegacyElementFactory.isValidFactory(factory);
|
|
239
|
-
};
|
|
240
|
-
|
|
241
|
-
ReactLegacyElementFactory._isLegacyCallWarningEnabled = true;
|
|
242
|
-
|
|
243
|
-
module.exports = ReactLegacyElementFactory;
|