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