react 0.6.3 → 0.9.0-rc1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +10 -222
- 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 +197 -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 +291 -0
- package/lib/EventPluginRegistry.js +260 -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 +337 -0
- package/lib/ReactEventEmitterMixin.js +57 -0
- package/lib/ReactEventTopLevelCallback.js +109 -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/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 +46 -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 +40 -0
- package/package.json +32 -21
- package/react.js +1 -0
- package/.npmignore +0 -7
- package/.travis.yml +0 -5
- 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 -3107
- 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 -123
- 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 -90
- package/lib/when-task.js +0 -85
- 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 -350
- 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 -147
- 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 -2038
- package/vendor/jquery/jquery-1.7.1.js +0 -9266
- package/vendor/jquery/jquery-1.7.1.min.js +0 -4
- package/vendor/mocha/mocha.css +0 -135
- package/vendor/mocha/mocha.js +0 -3589
- package/vendor/node/util.js +0 -531
- package/vendor/requirejs/require.js +0 -2053
- package/vendor/requirejs/require.min.js +0 -33
|
@@ -0,0 +1,268 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright 2013 Facebook, Inc.
|
|
3
|
+
*
|
|
4
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
5
|
+
* you may not use this file except in compliance with the License.
|
|
6
|
+
* You may obtain a copy of the License at
|
|
7
|
+
*
|
|
8
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
9
|
+
*
|
|
10
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
11
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
12
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
13
|
+
* See the License for the specific language governing permissions and
|
|
14
|
+
* limitations under the License.
|
|
15
|
+
*
|
|
16
|
+
* @providesModule DOMProperty
|
|
17
|
+
* @typechecks static-only
|
|
18
|
+
*/
|
|
19
|
+
|
|
20
|
+
/*jslint bitwise: true */
|
|
21
|
+
|
|
22
|
+
"use strict";
|
|
23
|
+
|
|
24
|
+
var invariant = require("./invariant");
|
|
25
|
+
|
|
26
|
+
var DOMPropertyInjection = {
|
|
27
|
+
/**
|
|
28
|
+
* Mapping from normalized, camelcased property names to a configuration that
|
|
29
|
+
* specifies how the associated DOM property should be accessed or rendered.
|
|
30
|
+
*/
|
|
31
|
+
MUST_USE_ATTRIBUTE: 0x1,
|
|
32
|
+
MUST_USE_PROPERTY: 0x2,
|
|
33
|
+
HAS_SIDE_EFFECTS: 0x4,
|
|
34
|
+
HAS_BOOLEAN_VALUE: 0x8,
|
|
35
|
+
HAS_POSITIVE_NUMERIC_VALUE: 0x10,
|
|
36
|
+
|
|
37
|
+
/**
|
|
38
|
+
* Inject some specialized knowledge about the DOM. This takes a config object
|
|
39
|
+
* with the following properties:
|
|
40
|
+
*
|
|
41
|
+
* isCustomAttribute: function that given an attribute name will return true
|
|
42
|
+
* if it can be inserted into the DOM verbatim. Useful for data-* or aria-*
|
|
43
|
+
* attributes where it's impossible to enumerate all of the possible
|
|
44
|
+
* attribute names,
|
|
45
|
+
*
|
|
46
|
+
* Properties: object mapping DOM property name to one of the
|
|
47
|
+
* DOMPropertyInjection constants or null. If your attribute isn't in here,
|
|
48
|
+
* it won't get written to the DOM.
|
|
49
|
+
*
|
|
50
|
+
* DOMAttributeNames: object mapping React attribute name to the DOM
|
|
51
|
+
* attribute name. Attribute names not specified use the **lowercase**
|
|
52
|
+
* normalized name.
|
|
53
|
+
*
|
|
54
|
+
* DOMPropertyNames: similar to DOMAttributeNames but for DOM properties.
|
|
55
|
+
* Property names not specified use the normalized name.
|
|
56
|
+
*
|
|
57
|
+
* DOMMutationMethods: Properties that require special mutation methods. If
|
|
58
|
+
* `value` is undefined, the mutation method should unset the property.
|
|
59
|
+
*
|
|
60
|
+
* @param {object} domPropertyConfig the config as described above.
|
|
61
|
+
*/
|
|
62
|
+
injectDOMPropertyConfig: function(domPropertyConfig) {
|
|
63
|
+
var Properties = domPropertyConfig.Properties || {};
|
|
64
|
+
var DOMAttributeNames = domPropertyConfig.DOMAttributeNames || {};
|
|
65
|
+
var DOMPropertyNames = domPropertyConfig.DOMPropertyNames || {};
|
|
66
|
+
var DOMMutationMethods = domPropertyConfig.DOMMutationMethods || {};
|
|
67
|
+
|
|
68
|
+
if (domPropertyConfig.isCustomAttribute) {
|
|
69
|
+
DOMProperty._isCustomAttributeFunctions.push(
|
|
70
|
+
domPropertyConfig.isCustomAttribute
|
|
71
|
+
);
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
for (var propName in Properties) {
|
|
75
|
+
("production" !== process.env.NODE_ENV ? invariant(
|
|
76
|
+
!DOMProperty.isStandardName[propName],
|
|
77
|
+
'injectDOMPropertyConfig(...): You\'re trying to inject DOM property ' +
|
|
78
|
+
'\'%s\' which has already been injected. You may be accidentally ' +
|
|
79
|
+
'injecting the same DOM property config twice, or you may be ' +
|
|
80
|
+
'injecting two configs that have conflicting property names.',
|
|
81
|
+
propName
|
|
82
|
+
) : invariant(!DOMProperty.isStandardName[propName]));
|
|
83
|
+
|
|
84
|
+
DOMProperty.isStandardName[propName] = true;
|
|
85
|
+
|
|
86
|
+
var lowerCased = propName.toLowerCase();
|
|
87
|
+
DOMProperty.getPossibleStandardName[lowerCased] = propName;
|
|
88
|
+
|
|
89
|
+
var attributeName = DOMAttributeNames[propName];
|
|
90
|
+
if (attributeName) {
|
|
91
|
+
DOMProperty.getPossibleStandardName[attributeName] = propName;
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
DOMProperty.getAttributeName[propName] = attributeName || lowerCased;
|
|
95
|
+
|
|
96
|
+
DOMProperty.getPropertyName[propName] =
|
|
97
|
+
DOMPropertyNames[propName] || propName;
|
|
98
|
+
|
|
99
|
+
var mutationMethod = DOMMutationMethods[propName];
|
|
100
|
+
if (mutationMethod) {
|
|
101
|
+
DOMProperty.getMutationMethod[propName] = mutationMethod;
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
var propConfig = Properties[propName];
|
|
105
|
+
DOMProperty.mustUseAttribute[propName] =
|
|
106
|
+
propConfig & DOMPropertyInjection.MUST_USE_ATTRIBUTE;
|
|
107
|
+
DOMProperty.mustUseProperty[propName] =
|
|
108
|
+
propConfig & DOMPropertyInjection.MUST_USE_PROPERTY;
|
|
109
|
+
DOMProperty.hasSideEffects[propName] =
|
|
110
|
+
propConfig & DOMPropertyInjection.HAS_SIDE_EFFECTS;
|
|
111
|
+
DOMProperty.hasBooleanValue[propName] =
|
|
112
|
+
propConfig & DOMPropertyInjection.HAS_BOOLEAN_VALUE;
|
|
113
|
+
DOMProperty.hasPositiveNumericValue[propName] =
|
|
114
|
+
propConfig & DOMPropertyInjection.HAS_POSITIVE_NUMERIC_VALUE;
|
|
115
|
+
|
|
116
|
+
("production" !== process.env.NODE_ENV ? invariant(
|
|
117
|
+
!DOMProperty.mustUseAttribute[propName] ||
|
|
118
|
+
!DOMProperty.mustUseProperty[propName],
|
|
119
|
+
'DOMProperty: Cannot require using both attribute and property: %s',
|
|
120
|
+
propName
|
|
121
|
+
) : invariant(!DOMProperty.mustUseAttribute[propName] ||
|
|
122
|
+
!DOMProperty.mustUseProperty[propName]));
|
|
123
|
+
("production" !== process.env.NODE_ENV ? invariant(
|
|
124
|
+
DOMProperty.mustUseProperty[propName] ||
|
|
125
|
+
!DOMProperty.hasSideEffects[propName],
|
|
126
|
+
'DOMProperty: Properties that have side effects must use property: %s',
|
|
127
|
+
propName
|
|
128
|
+
) : invariant(DOMProperty.mustUseProperty[propName] ||
|
|
129
|
+
!DOMProperty.hasSideEffects[propName]));
|
|
130
|
+
("production" !== process.env.NODE_ENV ? invariant(
|
|
131
|
+
!DOMProperty.hasBooleanValue[propName] ||
|
|
132
|
+
!DOMProperty.hasPositiveNumericValue[propName],
|
|
133
|
+
'DOMProperty: Cannot have both boolean and positive numeric value: %s',
|
|
134
|
+
propName
|
|
135
|
+
) : invariant(!DOMProperty.hasBooleanValue[propName] ||
|
|
136
|
+
!DOMProperty.hasPositiveNumericValue[propName]));
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
};
|
|
140
|
+
var defaultValueCache = {};
|
|
141
|
+
|
|
142
|
+
/**
|
|
143
|
+
* DOMProperty exports lookup objects that can be used like functions:
|
|
144
|
+
*
|
|
145
|
+
* > DOMProperty.isValid['id']
|
|
146
|
+
* true
|
|
147
|
+
* > DOMProperty.isValid['foobar']
|
|
148
|
+
* undefined
|
|
149
|
+
*
|
|
150
|
+
* Although this may be confusing, it performs better in general.
|
|
151
|
+
*
|
|
152
|
+
* @see http://jsperf.com/key-exists
|
|
153
|
+
* @see http://jsperf.com/key-missing
|
|
154
|
+
*/
|
|
155
|
+
var DOMProperty = {
|
|
156
|
+
|
|
157
|
+
ID_ATTRIBUTE_NAME: 'data-reactid',
|
|
158
|
+
|
|
159
|
+
/**
|
|
160
|
+
* Checks whether a property name is a standard property.
|
|
161
|
+
* @type {Object}
|
|
162
|
+
*/
|
|
163
|
+
isStandardName: {},
|
|
164
|
+
|
|
165
|
+
/**
|
|
166
|
+
* Mapping from lowercase property names to the properly cased version, used
|
|
167
|
+
* to warn in the case of missing properties.
|
|
168
|
+
* @type {Object}
|
|
169
|
+
*/
|
|
170
|
+
getPossibleStandardName: {},
|
|
171
|
+
|
|
172
|
+
/**
|
|
173
|
+
* Mapping from normalized names to attribute names that differ. Attribute
|
|
174
|
+
* names are used when rendering markup or with `*Attribute()`.
|
|
175
|
+
* @type {Object}
|
|
176
|
+
*/
|
|
177
|
+
getAttributeName: {},
|
|
178
|
+
|
|
179
|
+
/**
|
|
180
|
+
* Mapping from normalized names to properties on DOM node instances.
|
|
181
|
+
* (This includes properties that mutate due to external factors.)
|
|
182
|
+
* @type {Object}
|
|
183
|
+
*/
|
|
184
|
+
getPropertyName: {},
|
|
185
|
+
|
|
186
|
+
/**
|
|
187
|
+
* Mapping from normalized names to mutation methods. This will only exist if
|
|
188
|
+
* mutation cannot be set simply by the property or `setAttribute()`.
|
|
189
|
+
* @type {Object}
|
|
190
|
+
*/
|
|
191
|
+
getMutationMethod: {},
|
|
192
|
+
|
|
193
|
+
/**
|
|
194
|
+
* Whether the property must be accessed and mutated as an object property.
|
|
195
|
+
* @type {Object}
|
|
196
|
+
*/
|
|
197
|
+
mustUseAttribute: {},
|
|
198
|
+
|
|
199
|
+
/**
|
|
200
|
+
* Whether the property must be accessed and mutated using `*Attribute()`.
|
|
201
|
+
* (This includes anything that fails `<propName> in <element>`.)
|
|
202
|
+
* @type {Object}
|
|
203
|
+
*/
|
|
204
|
+
mustUseProperty: {},
|
|
205
|
+
|
|
206
|
+
/**
|
|
207
|
+
* Whether or not setting a value causes side effects such as triggering
|
|
208
|
+
* resources to be loaded or text selection changes. We must ensure that
|
|
209
|
+
* the value is only set if it has changed.
|
|
210
|
+
* @type {Object}
|
|
211
|
+
*/
|
|
212
|
+
hasSideEffects: {},
|
|
213
|
+
|
|
214
|
+
/**
|
|
215
|
+
* Whether the property should be removed when set to a falsey value.
|
|
216
|
+
* @type {Object}
|
|
217
|
+
*/
|
|
218
|
+
hasBooleanValue: {},
|
|
219
|
+
|
|
220
|
+
/**
|
|
221
|
+
* Whether the property must be positive numeric or parse as a positive
|
|
222
|
+
* numeric and should be removed when set to a falsey value.
|
|
223
|
+
* @type {Object}
|
|
224
|
+
*/
|
|
225
|
+
hasPositiveNumericValue: {},
|
|
226
|
+
|
|
227
|
+
/**
|
|
228
|
+
* All of the isCustomAttribute() functions that have been injected.
|
|
229
|
+
*/
|
|
230
|
+
_isCustomAttributeFunctions: [],
|
|
231
|
+
|
|
232
|
+
/**
|
|
233
|
+
* Checks whether a property name is a custom attribute.
|
|
234
|
+
* @method
|
|
235
|
+
*/
|
|
236
|
+
isCustomAttribute: function(attributeName) {
|
|
237
|
+
return DOMProperty._isCustomAttributeFunctions.some(
|
|
238
|
+
function(isCustomAttributeFn) {
|
|
239
|
+
return isCustomAttributeFn.call(null, attributeName);
|
|
240
|
+
}
|
|
241
|
+
);
|
|
242
|
+
},
|
|
243
|
+
|
|
244
|
+
/**
|
|
245
|
+
* Returns the default property value for a DOM property (i.e., not an
|
|
246
|
+
* attribute). Most default values are '' or false, but not all. Worse yet,
|
|
247
|
+
* some (in particular, `type`) vary depending on the type of element.
|
|
248
|
+
*
|
|
249
|
+
* TODO: Is it better to grab all the possible properties when creating an
|
|
250
|
+
* element to avoid having to create the same element twice?
|
|
251
|
+
*/
|
|
252
|
+
getDefaultValueForProperty: function(nodeName, prop) {
|
|
253
|
+
var nodeDefaults = defaultValueCache[nodeName];
|
|
254
|
+
var testElement;
|
|
255
|
+
if (!nodeDefaults) {
|
|
256
|
+
defaultValueCache[nodeName] = nodeDefaults = {};
|
|
257
|
+
}
|
|
258
|
+
if (!(prop in nodeDefaults)) {
|
|
259
|
+
testElement = document.createElement(nodeName);
|
|
260
|
+
nodeDefaults[prop] = testElement[prop];
|
|
261
|
+
}
|
|
262
|
+
return nodeDefaults[prop];
|
|
263
|
+
},
|
|
264
|
+
|
|
265
|
+
injection: DOMPropertyInjection
|
|
266
|
+
};
|
|
267
|
+
|
|
268
|
+
module.exports = DOMProperty;
|
|
@@ -0,0 +1,181 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright 2013 Facebook, Inc.
|
|
3
|
+
*
|
|
4
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
5
|
+
* you may not use this file except in compliance with the License.
|
|
6
|
+
* You may obtain a copy of the License at
|
|
7
|
+
*
|
|
8
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
9
|
+
*
|
|
10
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
11
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
12
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
13
|
+
* See the License for the specific language governing permissions and
|
|
14
|
+
* limitations under the License.
|
|
15
|
+
*
|
|
16
|
+
* @providesModule DOMPropertyOperations
|
|
17
|
+
* @typechecks static-only
|
|
18
|
+
*/
|
|
19
|
+
|
|
20
|
+
"use strict";
|
|
21
|
+
|
|
22
|
+
var DOMProperty = require("./DOMProperty");
|
|
23
|
+
|
|
24
|
+
var escapeTextForBrowser = require("./escapeTextForBrowser");
|
|
25
|
+
var memoizeStringOnly = require("./memoizeStringOnly");
|
|
26
|
+
|
|
27
|
+
function shouldIgnoreValue(name, value) {
|
|
28
|
+
return value == null ||
|
|
29
|
+
DOMProperty.hasBooleanValue[name] && !value ||
|
|
30
|
+
DOMProperty.hasPositiveNumericValue[name] && (isNaN(value) || value < 1);
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
var processAttributeNameAndPrefix = memoizeStringOnly(function(name) {
|
|
34
|
+
return escapeTextForBrowser(name) + '="';
|
|
35
|
+
});
|
|
36
|
+
|
|
37
|
+
if ("production" !== process.env.NODE_ENV) {
|
|
38
|
+
var reactProps = {
|
|
39
|
+
children: true,
|
|
40
|
+
dangerouslySetInnerHTML: true,
|
|
41
|
+
key: true,
|
|
42
|
+
ref: true
|
|
43
|
+
};
|
|
44
|
+
var warnedProperties = {};
|
|
45
|
+
|
|
46
|
+
var warnUnknownProperty = function(name) {
|
|
47
|
+
if (reactProps[name] || warnedProperties[name]) {
|
|
48
|
+
return;
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
warnedProperties[name] = true;
|
|
52
|
+
var lowerCasedName = name.toLowerCase();
|
|
53
|
+
|
|
54
|
+
// data-* attributes should be lowercase; suggest the lowercase version
|
|
55
|
+
var standardName = DOMProperty.isCustomAttribute(lowerCasedName) ?
|
|
56
|
+
lowerCasedName : DOMProperty.getPossibleStandardName[lowerCasedName];
|
|
57
|
+
|
|
58
|
+
// For now, only warn when we have a suggested correction. This prevents
|
|
59
|
+
// logging too much when using transferPropsTo.
|
|
60
|
+
if (standardName != null) {
|
|
61
|
+
console.warn(
|
|
62
|
+
'Unknown DOM property ' + name + '. Did you mean ' + standardName + '?'
|
|
63
|
+
);
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
};
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
/**
|
|
70
|
+
* Operations for dealing with DOM properties.
|
|
71
|
+
*/
|
|
72
|
+
var DOMPropertyOperations = {
|
|
73
|
+
|
|
74
|
+
/**
|
|
75
|
+
* Creates markup for the ID property.
|
|
76
|
+
*
|
|
77
|
+
* @param {string} id Unescaped ID.
|
|
78
|
+
* @return {string} Markup string.
|
|
79
|
+
*/
|
|
80
|
+
createMarkupForID: function(id) {
|
|
81
|
+
return processAttributeNameAndPrefix(DOMProperty.ID_ATTRIBUTE_NAME) +
|
|
82
|
+
escapeTextForBrowser(id) + '"';
|
|
83
|
+
},
|
|
84
|
+
|
|
85
|
+
/**
|
|
86
|
+
* Creates markup for a property.
|
|
87
|
+
*
|
|
88
|
+
* @param {string} name
|
|
89
|
+
* @param {*} value
|
|
90
|
+
* @return {?string} Markup string, or null if the property was invalid.
|
|
91
|
+
*/
|
|
92
|
+
createMarkupForProperty: function(name, value) {
|
|
93
|
+
if (DOMProperty.isStandardName[name]) {
|
|
94
|
+
if (shouldIgnoreValue(name, value)) {
|
|
95
|
+
return '';
|
|
96
|
+
}
|
|
97
|
+
var attributeName = DOMProperty.getAttributeName[name];
|
|
98
|
+
if (DOMProperty.hasBooleanValue[name]) {
|
|
99
|
+
return escapeTextForBrowser(attributeName);
|
|
100
|
+
}
|
|
101
|
+
return processAttributeNameAndPrefix(attributeName) +
|
|
102
|
+
escapeTextForBrowser(value) + '"';
|
|
103
|
+
} else if (DOMProperty.isCustomAttribute(name)) {
|
|
104
|
+
if (value == null) {
|
|
105
|
+
return '';
|
|
106
|
+
}
|
|
107
|
+
return processAttributeNameAndPrefix(name) +
|
|
108
|
+
escapeTextForBrowser(value) + '"';
|
|
109
|
+
} else if ("production" !== process.env.NODE_ENV) {
|
|
110
|
+
warnUnknownProperty(name);
|
|
111
|
+
}
|
|
112
|
+
return null;
|
|
113
|
+
},
|
|
114
|
+
|
|
115
|
+
/**
|
|
116
|
+
* Sets the value for a property on a node.
|
|
117
|
+
*
|
|
118
|
+
* @param {DOMElement} node
|
|
119
|
+
* @param {string} name
|
|
120
|
+
* @param {*} value
|
|
121
|
+
*/
|
|
122
|
+
setValueForProperty: function(node, name, value) {
|
|
123
|
+
if (DOMProperty.isStandardName[name]) {
|
|
124
|
+
var mutationMethod = DOMProperty.getMutationMethod[name];
|
|
125
|
+
if (mutationMethod) {
|
|
126
|
+
mutationMethod(node, value);
|
|
127
|
+
} else if (shouldIgnoreValue(name, value)) {
|
|
128
|
+
this.deleteValueForProperty(node, name);
|
|
129
|
+
} else if (DOMProperty.mustUseAttribute[name]) {
|
|
130
|
+
node.setAttribute(DOMProperty.getAttributeName[name], '' + value);
|
|
131
|
+
} else {
|
|
132
|
+
var propName = DOMProperty.getPropertyName[name];
|
|
133
|
+
if (!DOMProperty.hasSideEffects[name] || node[propName] !== value) {
|
|
134
|
+
node[propName] = value;
|
|
135
|
+
}
|
|
136
|
+
}
|
|
137
|
+
} else if (DOMProperty.isCustomAttribute(name)) {
|
|
138
|
+
if (value == null) {
|
|
139
|
+
node.removeAttribute(DOMProperty.getAttributeName[name]);
|
|
140
|
+
} else {
|
|
141
|
+
node.setAttribute(name, '' + value);
|
|
142
|
+
}
|
|
143
|
+
} else if ("production" !== process.env.NODE_ENV) {
|
|
144
|
+
warnUnknownProperty(name);
|
|
145
|
+
}
|
|
146
|
+
},
|
|
147
|
+
|
|
148
|
+
/**
|
|
149
|
+
* Deletes the value for a property on a node.
|
|
150
|
+
*
|
|
151
|
+
* @param {DOMElement} node
|
|
152
|
+
* @param {string} name
|
|
153
|
+
*/
|
|
154
|
+
deleteValueForProperty: function(node, name) {
|
|
155
|
+
if (DOMProperty.isStandardName[name]) {
|
|
156
|
+
var mutationMethod = DOMProperty.getMutationMethod[name];
|
|
157
|
+
if (mutationMethod) {
|
|
158
|
+
mutationMethod(node, undefined);
|
|
159
|
+
} else if (DOMProperty.mustUseAttribute[name]) {
|
|
160
|
+
node.removeAttribute(DOMProperty.getAttributeName[name]);
|
|
161
|
+
} else {
|
|
162
|
+
var propName = DOMProperty.getPropertyName[name];
|
|
163
|
+
var defaultValue = DOMProperty.getDefaultValueForProperty(
|
|
164
|
+
node.nodeName,
|
|
165
|
+
name
|
|
166
|
+
);
|
|
167
|
+
if (!DOMProperty.hasSideEffects[name] ||
|
|
168
|
+
node[propName] !== defaultValue) {
|
|
169
|
+
node[propName] = defaultValue;
|
|
170
|
+
}
|
|
171
|
+
}
|
|
172
|
+
} else if (DOMProperty.isCustomAttribute(name)) {
|
|
173
|
+
node.removeAttribute(name);
|
|
174
|
+
} else if ("production" !== process.env.NODE_ENV) {
|
|
175
|
+
warnUnknownProperty(name);
|
|
176
|
+
}
|
|
177
|
+
}
|
|
178
|
+
|
|
179
|
+
};
|
|
180
|
+
|
|
181
|
+
module.exports = DOMPropertyOperations;
|
package/lib/Danger.js
ADDED
|
@@ -0,0 +1,187 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright 2013 Facebook, Inc.
|
|
3
|
+
*
|
|
4
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
5
|
+
* you may not use this file except in compliance with the License.
|
|
6
|
+
* You may obtain a copy of the License at
|
|
7
|
+
*
|
|
8
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
9
|
+
*
|
|
10
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
11
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
12
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
13
|
+
* See the License for the specific language governing permissions and
|
|
14
|
+
* limitations under the License.
|
|
15
|
+
*
|
|
16
|
+
* @providesModule Danger
|
|
17
|
+
* @typechecks static-only
|
|
18
|
+
*/
|
|
19
|
+
|
|
20
|
+
/*jslint evil: true, sub: true */
|
|
21
|
+
|
|
22
|
+
"use strict";
|
|
23
|
+
|
|
24
|
+
var ExecutionEnvironment = require("./ExecutionEnvironment");
|
|
25
|
+
|
|
26
|
+
var createNodesFromMarkup = require("./createNodesFromMarkup");
|
|
27
|
+
var emptyFunction = require("./emptyFunction");
|
|
28
|
+
var getMarkupWrap = require("./getMarkupWrap");
|
|
29
|
+
var invariant = require("./invariant");
|
|
30
|
+
|
|
31
|
+
var OPEN_TAG_NAME_EXP = /^(<[^ \/>]+)/;
|
|
32
|
+
var RESULT_INDEX_ATTR = 'data-danger-index';
|
|
33
|
+
|
|
34
|
+
/**
|
|
35
|
+
* Extracts the `nodeName` from a string of markup.
|
|
36
|
+
*
|
|
37
|
+
* NOTE: Extracting the `nodeName` does not require a regular expression match
|
|
38
|
+
* because we make assumptions about React-generated markup (i.e. there are no
|
|
39
|
+
* spaces surrounding the opening tag and there is at least one attribute).
|
|
40
|
+
*
|
|
41
|
+
* @param {string} markup String of markup.
|
|
42
|
+
* @return {string} Node name of the supplied markup.
|
|
43
|
+
* @see http://jsperf.com/extract-nodename
|
|
44
|
+
*/
|
|
45
|
+
function getNodeName(markup) {
|
|
46
|
+
return markup.substring(1, markup.indexOf(' '));
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
var Danger = {
|
|
50
|
+
|
|
51
|
+
/**
|
|
52
|
+
* Renders markup into an array of nodes. The markup is expected to render
|
|
53
|
+
* into a list of root nodes. Also, the length of `resultList` and
|
|
54
|
+
* `markupList` should be the same.
|
|
55
|
+
*
|
|
56
|
+
* @param {array<string>} markupList List of markup strings to render.
|
|
57
|
+
* @return {array<DOMElement>} List of rendered nodes.
|
|
58
|
+
* @internal
|
|
59
|
+
*/
|
|
60
|
+
dangerouslyRenderMarkup: function(markupList) {
|
|
61
|
+
("production" !== process.env.NODE_ENV ? invariant(
|
|
62
|
+
ExecutionEnvironment.canUseDOM,
|
|
63
|
+
'dangerouslyRenderMarkup(...): Cannot render markup in a Worker ' +
|
|
64
|
+
'thread. This is likely a bug in the framework. Please report ' +
|
|
65
|
+
'immediately.'
|
|
66
|
+
) : invariant(ExecutionEnvironment.canUseDOM));
|
|
67
|
+
var nodeName;
|
|
68
|
+
var markupByNodeName = {};
|
|
69
|
+
// Group markup by `nodeName` if a wrap is necessary, else by '*'.
|
|
70
|
+
for (var i = 0; i < markupList.length; i++) {
|
|
71
|
+
("production" !== process.env.NODE_ENV ? invariant(
|
|
72
|
+
markupList[i],
|
|
73
|
+
'dangerouslyRenderMarkup(...): Missing markup.'
|
|
74
|
+
) : invariant(markupList[i]));
|
|
75
|
+
nodeName = getNodeName(markupList[i]);
|
|
76
|
+
nodeName = getMarkupWrap(nodeName) ? nodeName : '*';
|
|
77
|
+
markupByNodeName[nodeName] = markupByNodeName[nodeName] || [];
|
|
78
|
+
markupByNodeName[nodeName][i] = markupList[i];
|
|
79
|
+
}
|
|
80
|
+
var resultList = [];
|
|
81
|
+
var resultListAssignmentCount = 0;
|
|
82
|
+
for (nodeName in markupByNodeName) {
|
|
83
|
+
if (!markupByNodeName.hasOwnProperty(nodeName)) {
|
|
84
|
+
continue;
|
|
85
|
+
}
|
|
86
|
+
var markupListByNodeName = markupByNodeName[nodeName];
|
|
87
|
+
|
|
88
|
+
// This for-in loop skips the holes of the sparse array. The order of
|
|
89
|
+
// iteration should follow the order of assignment, which happens to match
|
|
90
|
+
// numerical index order, but we don't rely on that.
|
|
91
|
+
for (var resultIndex in markupListByNodeName) {
|
|
92
|
+
if (markupListByNodeName.hasOwnProperty(resultIndex)) {
|
|
93
|
+
var markup = markupListByNodeName[resultIndex];
|
|
94
|
+
|
|
95
|
+
// Push the requested markup with an additional RESULT_INDEX_ATTR
|
|
96
|
+
// attribute. If the markup does not start with a < character, it
|
|
97
|
+
// will be discarded below (with an appropriate console.error).
|
|
98
|
+
markupListByNodeName[resultIndex] = markup.replace(
|
|
99
|
+
OPEN_TAG_NAME_EXP,
|
|
100
|
+
// This index will be parsed back out below.
|
|
101
|
+
'$1 ' + RESULT_INDEX_ATTR + '="' + resultIndex + '" '
|
|
102
|
+
);
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
// Render each group of markup with similar wrapping `nodeName`.
|
|
107
|
+
var renderNodes = createNodesFromMarkup(
|
|
108
|
+
markupListByNodeName.join(''),
|
|
109
|
+
emptyFunction // Do nothing special with <script> tags.
|
|
110
|
+
);
|
|
111
|
+
|
|
112
|
+
for (i = 0; i < renderNodes.length; ++i) {
|
|
113
|
+
var renderNode = renderNodes[i];
|
|
114
|
+
if (renderNode.hasAttribute &&
|
|
115
|
+
renderNode.hasAttribute(RESULT_INDEX_ATTR)) {
|
|
116
|
+
|
|
117
|
+
resultIndex = +renderNode.getAttribute(RESULT_INDEX_ATTR);
|
|
118
|
+
renderNode.removeAttribute(RESULT_INDEX_ATTR);
|
|
119
|
+
|
|
120
|
+
("production" !== process.env.NODE_ENV ? invariant(
|
|
121
|
+
!resultList.hasOwnProperty(resultIndex),
|
|
122
|
+
'Danger: Assigning to an already-occupied result index.'
|
|
123
|
+
) : invariant(!resultList.hasOwnProperty(resultIndex)));
|
|
124
|
+
|
|
125
|
+
resultList[resultIndex] = renderNode;
|
|
126
|
+
|
|
127
|
+
// This should match resultList.length and markupList.length when
|
|
128
|
+
// we're done.
|
|
129
|
+
resultListAssignmentCount += 1;
|
|
130
|
+
|
|
131
|
+
} else if ("production" !== process.env.NODE_ENV) {
|
|
132
|
+
console.error(
|
|
133
|
+
"Danger: Discarding unexpected node:",
|
|
134
|
+
renderNode
|
|
135
|
+
);
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
// Although resultList was populated out of order, it should now be a dense
|
|
141
|
+
// array.
|
|
142
|
+
("production" !== process.env.NODE_ENV ? invariant(
|
|
143
|
+
resultListAssignmentCount === resultList.length,
|
|
144
|
+
'Danger: Did not assign to every index of resultList.'
|
|
145
|
+
) : invariant(resultListAssignmentCount === resultList.length));
|
|
146
|
+
|
|
147
|
+
("production" !== process.env.NODE_ENV ? invariant(
|
|
148
|
+
resultList.length === markupList.length,
|
|
149
|
+
'Danger: Expected markup to render %s nodes, but rendered %s.',
|
|
150
|
+
markupList.length,
|
|
151
|
+
resultList.length
|
|
152
|
+
) : invariant(resultList.length === markupList.length));
|
|
153
|
+
|
|
154
|
+
return resultList;
|
|
155
|
+
},
|
|
156
|
+
|
|
157
|
+
/**
|
|
158
|
+
* Replaces a node with a string of markup at its current position within its
|
|
159
|
+
* parent. The markup must render into a single root node.
|
|
160
|
+
*
|
|
161
|
+
* @param {DOMElement} oldChild Child node to replace.
|
|
162
|
+
* @param {string} markup Markup to render in place of the child node.
|
|
163
|
+
* @internal
|
|
164
|
+
*/
|
|
165
|
+
dangerouslyReplaceNodeWithMarkup: function(oldChild, markup) {
|
|
166
|
+
("production" !== process.env.NODE_ENV ? invariant(
|
|
167
|
+
ExecutionEnvironment.canUseDOM,
|
|
168
|
+
'dangerouslyReplaceNodeWithMarkup(...): Cannot render markup in a ' +
|
|
169
|
+
'worker thread. This is likely a bug in the framework. Please report ' +
|
|
170
|
+
'immediately.'
|
|
171
|
+
) : invariant(ExecutionEnvironment.canUseDOM));
|
|
172
|
+
("production" !== process.env.NODE_ENV ? invariant(markup, 'dangerouslyReplaceNodeWithMarkup(...): Missing markup.') : invariant(markup));
|
|
173
|
+
("production" !== process.env.NODE_ENV ? invariant(
|
|
174
|
+
oldChild.tagName.toLowerCase() !== 'html',
|
|
175
|
+
'dangerouslyReplaceNodeWithMarkup(...): Cannot replace markup of the ' +
|
|
176
|
+
'<html> node. This is because browser quirks make this unreliable ' +
|
|
177
|
+
'and/or slow. If you want to render to the root you must use ' +
|
|
178
|
+
'server rendering. See renderComponentToString().'
|
|
179
|
+
) : invariant(oldChild.tagName.toLowerCase() !== 'html'));
|
|
180
|
+
|
|
181
|
+
var newChild = createNodesFromMarkup(markup, emptyFunction)[0];
|
|
182
|
+
oldChild.parentNode.replaceChild(newChild, oldChild);
|
|
183
|
+
}
|
|
184
|
+
|
|
185
|
+
};
|
|
186
|
+
|
|
187
|
+
module.exports = Danger;
|