react 0.7.1 → 0.10.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 -231
- package/addons.js +1 -0
- package/lib/AutoFocusMixin.js +32 -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 +171 -0
- package/lib/DOMProperty.js +270 -0
- package/lib/DOMPropertyOperations.js +181 -0
- package/lib/Danger.js +187 -0
- package/lib/DefaultDOMPropertyConfig.js +196 -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 +295 -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 +160 -0
- package/lib/MobileSafariClickEventPlugin.js +63 -0
- package/lib/PooledClass.js +119 -0
- package/lib/React.js +97 -0
- package/lib/ReactBrowserComponentMixin.js +42 -0
- package/lib/ReactCSSTransitionGroup.js +65 -0
- package/lib/ReactCSSTransitionGroupChild.js +138 -0
- package/lib/ReactChildren.js +132 -0
- package/lib/ReactComponent.js +595 -0
- package/lib/ReactComponentBrowserEnvironment.js +124 -0
- package/lib/ReactCompositeComponent.js +1587 -0
- package/lib/ReactContext.js +67 -0
- package/lib/ReactCurrentOwner.js +39 -0
- package/lib/ReactDOM.js +207 -0
- package/lib/ReactDOMButton.js +69 -0
- package/lib/ReactDOMComponent.js +416 -0
- package/lib/ReactDOMForm.js +62 -0
- package/lib/ReactDOMIDOperations.js +218 -0
- package/lib/ReactDOMImg.js +61 -0
- package/lib/ReactDOMInput.js +182 -0
- package/lib/ReactDOMOption.js +55 -0
- package/lib/ReactDOMSelect.js +180 -0
- package/lib/ReactDOMSelection.js +189 -0
- package/lib/ReactDOMTextarea.js +144 -0
- package/lib/ReactDefaultBatchingStrategy.js +75 -0
- package/lib/ReactDefaultInjection.js +125 -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 +43 -0
- package/lib/ReactInputSelection.js +141 -0
- package/lib/ReactInstanceHandles.js +338 -0
- package/lib/ReactLink.js +54 -0
- package/lib/ReactMarkupChecksum.js +53 -0
- package/lib/ReactMount.js +649 -0
- package/lib/ReactMountReady.js +95 -0
- package/lib/ReactMultiChild.js +432 -0
- package/lib/ReactMultiChildUpdateTypes.js +38 -0
- package/lib/ReactOwner.js +159 -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 +182 -0
- package/lib/ReactRootIndex.js +36 -0
- package/lib/ReactServerRendering.js +89 -0
- package/lib/ReactServerRenderingTransaction.js +116 -0
- package/lib/ReactStateSetters.js +111 -0
- package/lib/ReactTestUtils.js +394 -0
- package/lib/ReactTextComponent.js +121 -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 +53 -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/emptyObject.js +27 -0
- package/lib/escapeTextForBrowser.js +47 -0
- package/lib/flattenChildren.js +57 -0
- package/lib/focusNode.js +33 -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/instantiateReactComponent.js +70 -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/monitorCodeUse.js +37 -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 +61 -0
- package/lib/toArray.js +75 -0
- package/lib/traverseAllChildren.js +190 -0
- package/lib/update.js +159 -0
- package/lib/warning.js +48 -0
- package/package.json +33 -31
- 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 -175
- 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,270 @@
|
|
|
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 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
|
+
for (var i = 0; i < DOMProperty._isCustomAttributeFunctions.length; i++) {
|
|
238
|
+
var isCustomAttributeFn = DOMProperty._isCustomAttributeFunctions[i];
|
|
239
|
+
if (isCustomAttributeFn(attributeName)) {
|
|
240
|
+
return true;
|
|
241
|
+
}
|
|
242
|
+
}
|
|
243
|
+
return false;
|
|
244
|
+
},
|
|
245
|
+
|
|
246
|
+
/**
|
|
247
|
+
* Returns the default property value for a DOM property (i.e., not an
|
|
248
|
+
* attribute). Most default values are '' or false, but not all. Worse yet,
|
|
249
|
+
* some (in particular, `type`) vary depending on the type of element.
|
|
250
|
+
*
|
|
251
|
+
* TODO: Is it better to grab all the possible properties when creating an
|
|
252
|
+
* element to avoid having to create the same element twice?
|
|
253
|
+
*/
|
|
254
|
+
getDefaultValueForProperty: function(nodeName, prop) {
|
|
255
|
+
var nodeDefaults = defaultValueCache[nodeName];
|
|
256
|
+
var testElement;
|
|
257
|
+
if (!nodeDefaults) {
|
|
258
|
+
defaultValueCache[nodeName] = nodeDefaults = {};
|
|
259
|
+
}
|
|
260
|
+
if (!(prop in nodeDefaults)) {
|
|
261
|
+
testElement = document.createElement(nodeName);
|
|
262
|
+
nodeDefaults[prop] = testElement[prop];
|
|
263
|
+
}
|
|
264
|
+
return nodeDefaults[prop];
|
|
265
|
+
},
|
|
266
|
+
|
|
267
|
+
injection: DOMPropertyInjection
|
|
268
|
+
};
|
|
269
|
+
|
|
270
|
+
module.exports = DOMProperty;
|
|
@@ -0,0 +1,181 @@
|
|
|
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 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
|
+
var warning = require("./warning");
|
|
27
|
+
|
|
28
|
+
function shouldIgnoreValue(name, value) {
|
|
29
|
+
return value == null ||
|
|
30
|
+
DOMProperty.hasBooleanValue[name] && !value ||
|
|
31
|
+
DOMProperty.hasPositiveNumericValue[name] && (isNaN(value) || value < 1);
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
var processAttributeNameAndPrefix = memoizeStringOnly(function(name) {
|
|
35
|
+
return escapeTextForBrowser(name) + '="';
|
|
36
|
+
});
|
|
37
|
+
|
|
38
|
+
if ("production" !== process.env.NODE_ENV) {
|
|
39
|
+
var reactProps = {
|
|
40
|
+
children: true,
|
|
41
|
+
dangerouslySetInnerHTML: true,
|
|
42
|
+
key: true,
|
|
43
|
+
ref: true
|
|
44
|
+
};
|
|
45
|
+
var warnedProperties = {};
|
|
46
|
+
|
|
47
|
+
var warnUnknownProperty = function(name) {
|
|
48
|
+
if (reactProps[name] || warnedProperties[name]) {
|
|
49
|
+
return;
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
warnedProperties[name] = true;
|
|
53
|
+
var lowerCasedName = name.toLowerCase();
|
|
54
|
+
|
|
55
|
+
// data-* attributes should be lowercase; suggest the lowercase version
|
|
56
|
+
var standardName = DOMProperty.isCustomAttribute(lowerCasedName) ?
|
|
57
|
+
lowerCasedName : DOMProperty.getPossibleStandardName[lowerCasedName];
|
|
58
|
+
|
|
59
|
+
// For now, only warn when we have a suggested correction. This prevents
|
|
60
|
+
// logging too much when using transferPropsTo.
|
|
61
|
+
("production" !== process.env.NODE_ENV ? warning(
|
|
62
|
+
standardName == null,
|
|
63
|
+
'Unknown DOM property ' + name + '. Did you mean ' + standardName + '?'
|
|
64
|
+
) : null);
|
|
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
|
+
propName
|
|
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;
|