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.
Files changed (223) hide show
  1. package/README.md +10 -231
  2. package/addons.js +1 -0
  3. package/lib/AutoFocusMixin.js +32 -0
  4. package/lib/CSSCore.js +115 -0
  5. package/lib/CSSProperty.js +121 -0
  6. package/lib/CSSPropertyOperations.js +97 -0
  7. package/lib/ChangeEventPlugin.js +387 -0
  8. package/lib/ClientReactRootIndex.js +30 -0
  9. package/lib/CompositionEventPlugin.js +260 -0
  10. package/lib/DOMChildrenOperations.js +171 -0
  11. package/lib/DOMProperty.js +270 -0
  12. package/lib/DOMPropertyOperations.js +181 -0
  13. package/lib/Danger.js +187 -0
  14. package/lib/DefaultDOMPropertyConfig.js +196 -0
  15. package/lib/DefaultEventPluginOrder.js +44 -0
  16. package/lib/EnterLeaveEventPlugin.js +145 -0
  17. package/lib/EventConstants.js +76 -0
  18. package/lib/EventListener.js +69 -0
  19. package/lib/EventPluginHub.js +295 -0
  20. package/lib/EventPluginRegistry.js +281 -0
  21. package/lib/EventPluginUtils.js +214 -0
  22. package/lib/EventPropagators.js +143 -0
  23. package/lib/ExecutionEnvironment.js +44 -0
  24. package/lib/LinkedStateMixin.js +46 -0
  25. package/lib/LinkedValueUtils.js +160 -0
  26. package/lib/MobileSafariClickEventPlugin.js +63 -0
  27. package/lib/PooledClass.js +119 -0
  28. package/lib/React.js +97 -0
  29. package/lib/ReactBrowserComponentMixin.js +42 -0
  30. package/lib/ReactCSSTransitionGroup.js +65 -0
  31. package/lib/ReactCSSTransitionGroupChild.js +138 -0
  32. package/lib/ReactChildren.js +132 -0
  33. package/lib/ReactComponent.js +595 -0
  34. package/lib/ReactComponentBrowserEnvironment.js +124 -0
  35. package/lib/ReactCompositeComponent.js +1587 -0
  36. package/lib/ReactContext.js +67 -0
  37. package/lib/ReactCurrentOwner.js +39 -0
  38. package/lib/ReactDOM.js +207 -0
  39. package/lib/ReactDOMButton.js +69 -0
  40. package/lib/ReactDOMComponent.js +416 -0
  41. package/lib/ReactDOMForm.js +62 -0
  42. package/lib/ReactDOMIDOperations.js +218 -0
  43. package/lib/ReactDOMImg.js +61 -0
  44. package/lib/ReactDOMInput.js +182 -0
  45. package/lib/ReactDOMOption.js +55 -0
  46. package/lib/ReactDOMSelect.js +180 -0
  47. package/lib/ReactDOMSelection.js +189 -0
  48. package/lib/ReactDOMTextarea.js +144 -0
  49. package/lib/ReactDefaultBatchingStrategy.js +75 -0
  50. package/lib/ReactDefaultInjection.js +125 -0
  51. package/lib/ReactDefaultPerf.js +244 -0
  52. package/lib/ReactDefaultPerfAnalysis.js +199 -0
  53. package/lib/ReactErrorUtils.js +37 -0
  54. package/lib/ReactEventEmitter.js +339 -0
  55. package/lib/ReactEventEmitterMixin.js +57 -0
  56. package/lib/ReactEventTopLevelCallback.js +149 -0
  57. package/lib/ReactInjection.js +43 -0
  58. package/lib/ReactInputSelection.js +141 -0
  59. package/lib/ReactInstanceHandles.js +338 -0
  60. package/lib/ReactLink.js +54 -0
  61. package/lib/ReactMarkupChecksum.js +53 -0
  62. package/lib/ReactMount.js +649 -0
  63. package/lib/ReactMountReady.js +95 -0
  64. package/lib/ReactMultiChild.js +432 -0
  65. package/lib/ReactMultiChildUpdateTypes.js +38 -0
  66. package/lib/ReactOwner.js +159 -0
  67. package/lib/ReactPerf.js +85 -0
  68. package/lib/ReactPropTransferer.js +147 -0
  69. package/lib/ReactPropTypeLocationNames.js +31 -0
  70. package/lib/ReactPropTypeLocations.js +29 -0
  71. package/lib/ReactPropTypes.js +359 -0
  72. package/lib/ReactPutListenerQueue.js +61 -0
  73. package/lib/ReactReconcileTransaction.js +182 -0
  74. package/lib/ReactRootIndex.js +36 -0
  75. package/lib/ReactServerRendering.js +89 -0
  76. package/lib/ReactServerRenderingTransaction.js +116 -0
  77. package/lib/ReactStateSetters.js +111 -0
  78. package/lib/ReactTestUtils.js +394 -0
  79. package/lib/ReactTextComponent.js +121 -0
  80. package/lib/ReactTransitionChildMapping.js +106 -0
  81. package/lib/ReactTransitionEvents.js +97 -0
  82. package/lib/ReactTransitionGroup.js +187 -0
  83. package/lib/ReactUpdates.js +148 -0
  84. package/lib/ReactWithAddons.js +53 -0
  85. package/lib/SelectEventPlugin.js +200 -0
  86. package/lib/ServerReactRootIndex.js +36 -0
  87. package/lib/SimpleEventPlugin.js +413 -0
  88. package/lib/SyntheticClipboardEvent.js +51 -0
  89. package/lib/SyntheticCompositionEvent.js +51 -0
  90. package/lib/SyntheticDragEvent.js +44 -0
  91. package/lib/SyntheticEvent.js +164 -0
  92. package/lib/SyntheticFocusEvent.js +44 -0
  93. package/lib/SyntheticKeyboardEvent.js +58 -0
  94. package/lib/SyntheticMouseEvent.js +85 -0
  95. package/lib/SyntheticTouchEvent.js +50 -0
  96. package/lib/SyntheticUIEvent.js +45 -0
  97. package/lib/SyntheticWheelEvent.js +66 -0
  98. package/lib/Transaction.js +276 -0
  99. package/lib/ViewportMetrics.js +37 -0
  100. package/lib/accumulate.js +54 -0
  101. package/lib/adler32.js +39 -0
  102. package/lib/cloneWithProps.js +59 -0
  103. package/lib/containsNode.js +49 -0
  104. package/lib/copyProperties.js +54 -0
  105. package/lib/createArrayFrom.js +91 -0
  106. package/lib/createFullPageComponent.js +63 -0
  107. package/lib/createNodesFromMarkup.js +93 -0
  108. package/lib/createObjectFrom.js +61 -0
  109. package/lib/cx.js +44 -0
  110. package/lib/dangerousStyleValue.js +57 -0
  111. package/lib/emptyFunction.js +43 -0
  112. package/lib/emptyObject.js +27 -0
  113. package/lib/escapeTextForBrowser.js +47 -0
  114. package/lib/flattenChildren.js +57 -0
  115. package/lib/focusNode.js +33 -0
  116. package/lib/forEachAccumulated.js +36 -0
  117. package/lib/getActiveElement.js +34 -0
  118. package/lib/getEventKey.js +85 -0
  119. package/lib/getEventTarget.js +36 -0
  120. package/lib/getMarkupWrap.js +118 -0
  121. package/lib/getNodeForCharacterOffset.js +80 -0
  122. package/lib/getReactRootElementInContainer.js +40 -0
  123. package/lib/getTextContentAccessor.js +42 -0
  124. package/lib/getUnboundedScrollPosition.js +45 -0
  125. package/lib/hyphenate.js +35 -0
  126. package/lib/instantiateReactComponent.js +70 -0
  127. package/lib/invariant.js +62 -0
  128. package/lib/isEventSupported.js +70 -0
  129. package/lib/isNode.js +33 -0
  130. package/lib/isTextInputElement.js +49 -0
  131. package/lib/isTextNode.js +30 -0
  132. package/lib/joinClasses.js +44 -0
  133. package/lib/keyMirror.js +58 -0
  134. package/lib/keyOf.js +41 -0
  135. package/lib/memoizeStringOnly.js +39 -0
  136. package/lib/merge.js +37 -0
  137. package/lib/mergeHelpers.js +136 -0
  138. package/lib/mergeInto.js +45 -0
  139. package/lib/mixInto.js +34 -0
  140. package/lib/monitorCodeUse.js +37 -0
  141. package/lib/objMap.js +47 -0
  142. package/lib/objMapKeyVal.js +47 -0
  143. package/lib/onlyChild.js +43 -0
  144. package/lib/performanceNow.js +42 -0
  145. package/lib/shallowEqual.js +49 -0
  146. package/lib/shouldUpdateReactComponent.js +61 -0
  147. package/lib/toArray.js +75 -0
  148. package/lib/traverseAllChildren.js +190 -0
  149. package/lib/update.js +159 -0
  150. package/lib/warning.js +48 -0
  151. package/package.json +33 -31
  152. package/react.js +1 -0
  153. package/.npmignore +0 -7
  154. package/.travis.yml +0 -7
  155. package/Jakefile.js +0 -39
  156. package/LICENSE +0 -19
  157. package/browser-test/dist.html +0 -90
  158. package/browser-test/index.html +0 -86
  159. package/browser-test/min.html +0 -90
  160. package/dist/react.js +0 -3141
  161. package/dist/react.min.js +0 -22
  162. package/doc/advanced.md +0 -175
  163. package/doc/color-def.graffle +0 -938
  164. package/doc/color-def.png +0 -0
  165. package/doc/simple.dot +0 -25
  166. package/doc/simple.png +0 -0
  167. package/examples/longer-example.js +0 -41
  168. package/examples/simple.js +0 -45
  169. package/examples/using-ast-directly.js +0 -30
  170. package/examples/using-events1.js +0 -79
  171. package/examples/using-log-events.js +0 -43
  172. package/lib/base-task.js +0 -120
  173. package/lib/cb-task.js +0 -84
  174. package/lib/core.js +0 -138
  175. package/lib/dsl.js +0 -138
  176. package/lib/error.js +0 -55
  177. package/lib/event-collector.js +0 -81
  178. package/lib/event-manager.js +0 -89
  179. package/lib/eventemitter.js +0 -20
  180. package/lib/finalcb-first-task.js +0 -68
  181. package/lib/finalcb-task.js +0 -65
  182. package/lib/id.js +0 -22
  183. package/lib/input-parser.js +0 -56
  184. package/lib/log-events.js +0 -101
  185. package/lib/parse.js +0 -41
  186. package/lib/promise-resolve.js +0 -50
  187. package/lib/promise-task.js +0 -93
  188. package/lib/react.js +0 -59
  189. package/lib/ret-task.js +0 -71
  190. package/lib/sprintf.js +0 -18
  191. package/lib/status.js +0 -14
  192. package/lib/task.js +0 -251
  193. package/lib/track-tasks.js +0 -74
  194. package/lib/validate.js +0 -159
  195. package/lib/vcon.js +0 -113
  196. package/lib/when-task.js +0 -84
  197. package/src/dist.build.requirejs +0 -20
  198. package/test/ast.mocha.js +0 -136
  199. package/test/cb-task.mocha.js +0 -220
  200. package/test/core-deferred.mocha.js +0 -143
  201. package/test/core-when.mocha.js +0 -96
  202. package/test/core.mocha.js +0 -589
  203. package/test/dsl.mocha.js +0 -352
  204. package/test/event-manager.mocha.js +0 -119
  205. package/test/exec-options.mocha.js +0 -48
  206. package/test/finalcb-task.mocha.js +0 -58
  207. package/test/input-parser.mocha.js +0 -86
  208. package/test/log-events.mocha.js +0 -88
  209. package/test/mocha.opts +0 -2
  210. package/test/module-use.mocha.js +0 -164
  211. package/test/promise-auto-resolve.mocha.js +0 -68
  212. package/test/ret-task.mocha.js +0 -220
  213. package/test/task.mocha.js +0 -42
  214. package/test/validate-cb-task.mocha.js +0 -100
  215. package/test/validate-ret-task.mocha.js +0 -110
  216. package/test/validate.mocha.js +0 -324
  217. package/test/vcon.mocha.js +0 -193
  218. package/vendor/chai/chai.js +0 -4251
  219. package/vendor/jquery/jquery-1.7.1.js +0 -9266
  220. package/vendor/jquery/jquery-1.7.1.min.js +0 -4
  221. package/vendor/node/util.js +0 -531
  222. package/vendor/requirejs/require.js +0 -2045
  223. 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;