react 0.12.1 → 0.13.0-beta.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (153) hide show
  1. package/dist/JSXTransformer.js +352 -251
  2. package/dist/react-with-addons.js +5409 -4242
  3. package/dist/react-with-addons.min.js +5 -6
  4. package/dist/react.js +5012 -4136
  5. package/dist/react.min.js +5 -6
  6. package/lib/AutoFocusMixin.js +1 -1
  7. package/lib/BeforeInputEventPlugin.js +389 -112
  8. package/lib/CSSProperty.js +6 -3
  9. package/lib/CSSPropertyOperations.js +57 -10
  10. package/lib/CallbackQueue.js +2 -2
  11. package/lib/ChangeEventPlugin.js +3 -3
  12. package/lib/ClientReactRootIndex.js +1 -1
  13. package/lib/DOMChildrenOperations.js +6 -4
  14. package/lib/DOMProperty.js +1 -1
  15. package/lib/DOMPropertyOperations.js +4 -2
  16. package/lib/Danger.js +7 -6
  17. package/lib/DefaultEventPluginOrder.js +1 -2
  18. package/lib/EnterLeaveEventPlugin.js +1 -1
  19. package/lib/EventConstants.js +1 -1
  20. package/lib/EventPluginHub.js +9 -7
  21. package/lib/EventPluginRegistry.js +1 -1
  22. package/lib/EventPluginUtils.js +1 -1
  23. package/lib/EventPropagators.js +1 -1
  24. package/lib/ExecutionEnvironment.js +2 -3
  25. package/lib/FallbackCompositionState.js +89 -0
  26. package/lib/HTMLDOMPropertyConfig.js +19 -7
  27. package/lib/LinkedStateMixin.js +1 -1
  28. package/lib/LinkedValueUtils.js +3 -3
  29. package/lib/LocalEventTrapMixin.js +9 -2
  30. package/lib/MobileSafariClickEventPlugin.js +1 -1
  31. package/lib/Object.assign.js +3 -1
  32. package/lib/PooledClass.js +1 -1
  33. package/lib/React.js +17 -51
  34. package/lib/ReactBrowserComponentMixin.js +3 -13
  35. package/lib/ReactBrowserEventEmitter.js +4 -6
  36. package/lib/ReactCSSTransitionGroup.js +4 -1
  37. package/lib/ReactCSSTransitionGroupChild.js +12 -2
  38. package/lib/ReactChildReconciler.js +125 -0
  39. package/lib/ReactChildren.js +10 -8
  40. package/lib/ReactClass.js +916 -0
  41. package/lib/ReactComponent.js +81 -404
  42. package/lib/ReactComponentBrowserEnvironment.js +10 -83
  43. package/lib/ReactComponentEnvironment.js +57 -0
  44. package/lib/ReactComponentWithPureRenderMixin.js +1 -1
  45. package/lib/ReactCompositeComponent.js +533 -1132
  46. package/lib/ReactContext.js +6 -2
  47. package/lib/ReactCurrentOwner.js +1 -1
  48. package/lib/ReactDOM.js +3 -8
  49. package/lib/ReactDOMButton.js +5 -6
  50. package/lib/ReactDOMComponent.js +110 -92
  51. package/lib/ReactDOMForm.js +5 -6
  52. package/lib/ReactDOMIDOperations.js +56 -74
  53. package/lib/ReactDOMImg.js +4 -6
  54. package/lib/ReactDOMInput.js +5 -6
  55. package/lib/ReactDOMOption.js +5 -6
  56. package/lib/ReactDOMSelect.js +57 -65
  57. package/lib/ReactDOMSelection.js +6 -2
  58. package/lib/{ReactTextComponent.js → ReactDOMTextComponent.js} +48 -35
  59. package/lib/ReactDOMTextarea.js +5 -6
  60. package/lib/ReactDefaultBatchingStrategy.js +4 -4
  61. package/lib/ReactDefaultInjection.js +14 -8
  62. package/lib/ReactDefaultPerf.js +16 -7
  63. package/lib/ReactDefaultPerfAnalysis.js +1 -1
  64. package/lib/ReactElement.js +23 -15
  65. package/lib/ReactElementValidator.js +209 -57
  66. package/lib/ReactEmptyComponent.js +29 -11
  67. package/lib/ReactEventEmitterMixin.js +1 -1
  68. package/lib/ReactEventListener.js +3 -4
  69. package/lib/ReactInjection.js +7 -5
  70. package/lib/ReactInputSelection.js +3 -4
  71. package/lib/ReactInstanceHandles.js +3 -2
  72. package/lib/ReactInstanceMap.js +47 -0
  73. package/lib/ReactLifeCycle.js +35 -0
  74. package/lib/ReactLink.js +1 -1
  75. package/lib/ReactMarkupChecksum.js +1 -1
  76. package/lib/ReactMount.js +239 -68
  77. package/lib/ReactMultiChild.js +49 -47
  78. package/lib/ReactMultiChildUpdateTypes.js +1 -1
  79. package/lib/ReactNativeComponent.js +72 -25
  80. package/lib/ReactOwner.js +4 -48
  81. package/lib/ReactPerf.js +21 -1
  82. package/lib/ReactPropTransferer.js +2 -57
  83. package/lib/ReactPropTypeLocationNames.js +1 -1
  84. package/lib/ReactPropTypeLocations.js +1 -1
  85. package/lib/ReactPropTypes.js +14 -22
  86. package/lib/ReactPutListenerQueue.js +1 -1
  87. package/lib/ReactReconcileTransaction.js +1 -1
  88. package/lib/ReactReconciler.js +107 -0
  89. package/lib/ReactRef.js +70 -0
  90. package/lib/ReactRootIndex.js +1 -1
  91. package/lib/ReactServerRendering.js +5 -3
  92. package/lib/ReactServerRenderingTransaction.js +1 -1
  93. package/lib/ReactStateSetters.js +1 -1
  94. package/lib/ReactTestUtils.js +112 -26
  95. package/lib/ReactTransitionChildMapping.js +1 -1
  96. package/lib/ReactTransitionEvents.js +1 -1
  97. package/lib/ReactTransitionGroup.js +48 -7
  98. package/lib/ReactUpdateQueue.js +264 -0
  99. package/lib/ReactUpdates.js +48 -61
  100. package/lib/ReactWithAddons.js +1 -1
  101. package/lib/SVGDOMPropertyConfig.js +1 -1
  102. package/lib/SelectEventPlugin.js +3 -3
  103. package/lib/ServerReactRootIndex.js +1 -1
  104. package/lib/SimpleEventPlugin.js +1 -1
  105. package/lib/SyntheticClipboardEvent.js +1 -2
  106. package/lib/SyntheticCompositionEvent.js +1 -2
  107. package/lib/SyntheticDragEvent.js +1 -1
  108. package/lib/SyntheticEvent.js +11 -3
  109. package/lib/SyntheticFocusEvent.js +1 -1
  110. package/lib/SyntheticInputEvent.js +1 -2
  111. package/lib/SyntheticKeyboardEvent.js +1 -1
  112. package/lib/SyntheticMouseEvent.js +2 -4
  113. package/lib/SyntheticTouchEvent.js +1 -1
  114. package/lib/SyntheticUIEvent.js +1 -1
  115. package/lib/SyntheticWheelEvent.js +1 -1
  116. package/lib/Transaction.js +3 -3
  117. package/lib/ViewportMetrics.js +2 -5
  118. package/lib/accumulateInto.js +1 -1
  119. package/lib/adler32.js +1 -1
  120. package/lib/cloneWithProps.js +3 -3
  121. package/lib/copyProperties.js +2 -0
  122. package/lib/createFullPageComponent.js +3 -3
  123. package/lib/dangerousStyleValue.js +1 -1
  124. package/lib/escapeTextForBrowser.js +6 -6
  125. package/lib/findDOMNode.js +51 -0
  126. package/lib/flattenChildren.js +11 -22
  127. package/lib/forEachAccumulated.js +1 -1
  128. package/lib/getEventCharCode.js +1 -1
  129. package/lib/getEventKey.js +1 -1
  130. package/lib/getEventModifierState.js +1 -1
  131. package/lib/getEventTarget.js +1 -1
  132. package/lib/getIteratorFn.js +42 -0
  133. package/lib/getNodeForCharacterOffset.js +2 -2
  134. package/lib/getReactRootElementInContainer.js +1 -1
  135. package/lib/getTextContentAccessor.js +1 -1
  136. package/lib/instantiateReactComponent.js +85 -67
  137. package/lib/isEventSupported.js +1 -1
  138. package/lib/isNode.js +3 -4
  139. package/lib/isTextInputElement.js +2 -3
  140. package/lib/joinClasses.js +1 -1
  141. package/lib/keyMirror.js +1 -1
  142. package/lib/memoizeStringOnly.js +4 -5
  143. package/lib/onlyChild.js +1 -1
  144. package/lib/setInnerHTML.js +12 -1
  145. package/lib/shallowEqual.js +1 -1
  146. package/lib/shouldUpdateReactComponent.js +48 -6
  147. package/lib/traverseAllChildren.js +111 -55
  148. package/lib/update.js +1 -1
  149. package/lib/warning.js +12 -1
  150. package/package.json +1 -1
  151. package/lib/CompositionEventPlugin.js +0 -257
  152. package/lib/ReactLegacyElement.js +0 -243
  153. package/lib/deprecated.js +0 -47
@@ -9,14 +9,13 @@
9
9
  * @providesModule CSSProperty
10
10
  */
11
11
 
12
- "use strict";
12
+ 'use strict';
13
13
 
14
14
  /**
15
15
  * CSS properties which accept numbers but are not in units of "px".
16
16
  */
17
17
  var isUnitlessNumber = {
18
18
  columnCount: true,
19
- fillOpacity: true,
20
19
  flex: true,
21
20
  flexGrow: true,
22
21
  flexShrink: true,
@@ -28,7 +27,11 @@ var isUnitlessNumber = {
28
27
  orphans: true,
29
28
  widows: true,
30
29
  zIndex: true,
31
- zoom: true
30
+ zoom: true,
31
+
32
+ // SVG-related properties
33
+ fillOpacity: true,
34
+ strokeOpacity: true
32
35
  };
33
36
 
34
37
  /**
@@ -10,7 +10,7 @@
10
10
  * @typechecks static-only
11
11
  */
12
12
 
13
- "use strict";
13
+ 'use strict';
14
14
 
15
15
  var CSSProperty = require("./CSSProperty");
16
16
  var ExecutionEnvironment = require("./ExecutionEnvironment");
@@ -34,7 +34,14 @@ if (ExecutionEnvironment.canUseDOM) {
34
34
  }
35
35
 
36
36
  if ("production" !== process.env.NODE_ENV) {
37
+ // 'msTransform' is correct, but the other prefixes should be capitalized
38
+ var badVendoredStyleNamePattern = /^(?:webkit|moz|o)[A-Z]/;
39
+
40
+ // style values shouldn't contain a semicolon
41
+ var badStyleValueWithSemicolonPattern = /;\s*$/;
42
+
37
43
  var warnedStyleNames = {};
44
+ var warnedStyleValues = {};
38
45
 
39
46
  var warnHyphenatedStyleName = function(name) {
40
47
  if (warnedStyleNames.hasOwnProperty(name) && warnedStyleNames[name]) {
@@ -44,10 +51,54 @@ if ("production" !== process.env.NODE_ENV) {
44
51
  warnedStyleNames[name] = true;
45
52
  ("production" !== process.env.NODE_ENV ? warning(
46
53
  false,
47
- 'Unsupported style property ' + name + '. Did you mean ' +
48
- camelizeStyleName(name) + '?'
54
+ 'Unsupported style property %s. Did you mean %s?',
55
+ name,
56
+ camelizeStyleName(name)
49
57
  ) : null);
50
58
  };
59
+
60
+ var warnBadVendoredStyleName = function(name) {
61
+ if (warnedStyleNames.hasOwnProperty(name) && warnedStyleNames[name]) {
62
+ return;
63
+ }
64
+
65
+ warnedStyleNames[name] = true;
66
+ ("production" !== process.env.NODE_ENV ? warning(
67
+ false,
68
+ 'Unsupported vendor-prefixed style property %s. Did you mean %s?',
69
+ name,
70
+ name.charAt(0).toUpperCase() + name.slice(1)
71
+ ) : null);
72
+ };
73
+
74
+ var warnStyleValueWithSemicolon = function(name, value) {
75
+ if (warnedStyleValues.hasOwnProperty(value) && warnedStyleValues[value]) {
76
+ return;
77
+ }
78
+
79
+ warnedStyleValues[value] = true;
80
+ ("production" !== process.env.NODE_ENV ? warning(
81
+ false,
82
+ 'Style property values shouldn\'t contain a semicolon. ' +
83
+ 'Try "%s: %s" instead.',
84
+ name,
85
+ value.replace(badStyleValueWithSemicolonPattern, '')
86
+ ) : null);
87
+ };
88
+
89
+ /**
90
+ * @param {string} name
91
+ * @param {*} value
92
+ */
93
+ var warnValidStyle = function(name, value) {
94
+ if (name.indexOf('-') > -1) {
95
+ warnHyphenatedStyleName(name);
96
+ } else if (badVendoredStyleNamePattern.test(name)) {
97
+ warnBadVendoredStyleName(name);
98
+ } else if (badStyleValueWithSemicolonPattern.test(value)) {
99
+ warnStyleValueWithSemicolon(name, value);
100
+ }
101
+ };
51
102
  }
52
103
 
53
104
  /**
@@ -73,12 +124,10 @@ var CSSPropertyOperations = {
73
124
  if (!styles.hasOwnProperty(styleName)) {
74
125
  continue;
75
126
  }
127
+ var styleValue = styles[styleName];
76
128
  if ("production" !== process.env.NODE_ENV) {
77
- if (styleName.indexOf('-') > -1) {
78
- warnHyphenatedStyleName(styleName);
79
- }
129
+ warnValidStyle(styleName, styleValue);
80
130
  }
81
- var styleValue = styles[styleName];
82
131
  if (styleValue != null) {
83
132
  serialized += processStyleName(styleName) + ':';
84
133
  serialized += dangerousStyleValue(styleName, styleValue) + ';';
@@ -101,9 +150,7 @@ var CSSPropertyOperations = {
101
150
  continue;
102
151
  }
103
152
  if ("production" !== process.env.NODE_ENV) {
104
- if (styleName.indexOf('-') > -1) {
105
- warnHyphenatedStyleName(styleName);
106
- }
153
+ warnValidStyle(styleName, styles[styleName]);
107
154
  }
108
155
  var styleValue = dangerousStyleValue(styleName, styles[styleName]);
109
156
  if (styleName === 'float') {
@@ -9,7 +9,7 @@
9
9
  * @providesModule CallbackQueue
10
10
  */
11
11
 
12
- "use strict";
12
+ 'use strict';
13
13
 
14
14
  var PooledClass = require("./PooledClass");
15
15
 
@@ -60,7 +60,7 @@ assign(CallbackQueue.prototype, {
60
60
  if (callbacks) {
61
61
  ("production" !== process.env.NODE_ENV ? invariant(
62
62
  callbacks.length === contexts.length,
63
- "Mismatched list of contexts in callback queue"
63
+ 'Mismatched list of contexts in callback queue'
64
64
  ) : invariant(callbacks.length === contexts.length));
65
65
  this._callbacks = null;
66
66
  this._contexts = null;
@@ -9,7 +9,7 @@
9
9
  * @providesModule ChangeEventPlugin
10
10
  */
11
11
 
12
- "use strict";
12
+ 'use strict';
13
13
 
14
14
  var EventConstants = require("./EventConstants");
15
15
  var EventPluginHub = require("./EventPluginHub");
@@ -65,7 +65,7 @@ var doesChangeEventBubble = false;
65
65
  if (ExecutionEnvironment.canUseDOM) {
66
66
  // See `handleChange` comment below
67
67
  doesChangeEventBubble = isEventSupported('change') && (
68
- !('documentMode' in document) || document.documentMode > 8
68
+ (!('documentMode' in document) || document.documentMode > 8)
69
69
  );
70
70
  }
71
71
 
@@ -142,7 +142,7 @@ if (ExecutionEnvironment.canUseDOM) {
142
142
  // IE9 claims to support the input event but fails to trigger it when
143
143
  // deleting text, so we ignore its input events
144
144
  isInputEventSupported = isEventSupported('input') && (
145
- !('documentMode' in document) || document.documentMode > 9
145
+ (!('documentMode' in document) || document.documentMode > 9)
146
146
  );
147
147
  }
148
148
 
@@ -10,7 +10,7 @@
10
10
  * @typechecks
11
11
  */
12
12
 
13
- "use strict";
13
+ 'use strict';
14
14
 
15
15
  var nextReactRootIndex = 0;
16
16
 
@@ -10,7 +10,7 @@
10
10
  * @typechecks static-only
11
11
  */
12
12
 
13
- "use strict";
13
+ 'use strict';
14
14
 
15
15
  var Danger = require("./Danger");
16
16
  var ReactMultiChildUpdateTypes = require("./ReactMultiChildUpdateTypes");
@@ -100,7 +100,8 @@ var DOMChildrenOperations = {
100
100
  // List of children that will be moved or removed.
101
101
  var updatedChildren = null;
102
102
 
103
- for (var i = 0; update = updates[i]; i++) {
103
+ for (var i = 0; i < updates.length; i++) {
104
+ update = updates[i];
104
105
  if (update.type === ReactMultiChildUpdateTypes.MOVE_EXISTING ||
105
106
  update.type === ReactMultiChildUpdateTypes.REMOVE_NODE) {
106
107
  var updatedIndex = update.fromIndex;
@@ -112,7 +113,7 @@ var DOMChildrenOperations = {
112
113
  'processUpdates(): Unable to find child %s of element. This ' +
113
114
  'probably means the DOM was unexpectedly mutated (e.g., by the ' +
114
115
  'browser), usually due to forgetting a <tbody> when using tables, ' +
115
- 'nesting tags like <form>, <p>, or <a>, or using non-SVG elements '+
116
+ 'nesting tags like <form>, <p>, or <a>, or using non-SVG elements ' +
116
117
  'in an <svg> parent. Try inspecting the child nodes of the element ' +
117
118
  'with React ID `%s`.',
118
119
  updatedIndex,
@@ -137,7 +138,8 @@ var DOMChildrenOperations = {
137
138
  }
138
139
  }
139
140
 
140
- for (var k = 0; update = updates[k]; k++) {
141
+ for (var k = 0; k < updates.length; k++) {
142
+ update = updates[k];
141
143
  switch (update.type) {
142
144
  case ReactMultiChildUpdateTypes.INSERT_MARKUP:
143
145
  insertChildAt(
@@ -12,7 +12,7 @@
12
12
 
13
13
  /*jslint bitwise: true */
14
14
 
15
- "use strict";
15
+ 'use strict';
16
16
 
17
17
  var invariant = require("./invariant");
18
18
 
@@ -10,7 +10,7 @@
10
10
  * @typechecks static-only
11
11
  */
12
12
 
13
- "use strict";
13
+ 'use strict';
14
14
 
15
15
  var DOMProperty = require("./DOMProperty");
16
16
 
@@ -61,7 +61,9 @@ if ("production" !== process.env.NODE_ENV) {
61
61
  // logging too much when using transferPropsTo.
62
62
  ("production" !== process.env.NODE_ENV ? warning(
63
63
  standardName == null,
64
- 'Unknown DOM property ' + name + '. Did you mean ' + standardName + '?'
64
+ 'Unknown DOM property %s. Did you mean %s?',
65
+ name,
66
+ standardName
65
67
  ) : null);
66
68
 
67
69
  };
package/lib/Danger.js CHANGED
@@ -12,7 +12,7 @@
12
12
 
13
13
  /*jslint evil: true, sub: true */
14
14
 
15
- "use strict";
15
+ 'use strict';
16
16
 
17
17
  var ExecutionEnvironment = require("./ExecutionEnvironment");
18
18
 
@@ -82,7 +82,8 @@ var Danger = {
82
82
  // This for-in loop skips the holes of the sparse array. The order of
83
83
  // iteration should follow the order of assignment, which happens to match
84
84
  // numerical index order, but we don't rely on that.
85
- for (var resultIndex in markupListByNodeName) {
85
+ var resultIndex;
86
+ for (resultIndex in markupListByNodeName) {
86
87
  if (markupListByNodeName.hasOwnProperty(resultIndex)) {
87
88
  var markup = markupListByNodeName[resultIndex];
88
89
 
@@ -103,8 +104,8 @@ var Danger = {
103
104
  emptyFunction // Do nothing special with <script> tags.
104
105
  );
105
106
 
106
- for (i = 0; i < renderNodes.length; ++i) {
107
- var renderNode = renderNodes[i];
107
+ for (var j = 0; j < renderNodes.length; ++j) {
108
+ var renderNode = renderNodes[j];
108
109
  if (renderNode.hasAttribute &&
109
110
  renderNode.hasAttribute(RESULT_INDEX_ATTR)) {
110
111
 
@@ -124,7 +125,7 @@ var Danger = {
124
125
 
125
126
  } else if ("production" !== process.env.NODE_ENV) {
126
127
  console.error(
127
- "Danger: Discarding unexpected node:",
128
+ 'Danger: Discarding unexpected node:',
128
129
  renderNode
129
130
  );
130
131
  }
@@ -170,7 +171,7 @@ var Danger = {
170
171
  'dangerouslyReplaceNodeWithMarkup(...): Cannot replace markup of the ' +
171
172
  '<html> node. This is because browser quirks make this unreliable ' +
172
173
  'and/or slow. If you want to render to the root you must use ' +
173
- 'server rendering. See renderComponentToString().'
174
+ 'server rendering. See React.renderToString().'
174
175
  ) : invariant(oldChild.tagName.toLowerCase() !== 'html'));
175
176
 
176
177
  var newChild = createNodesFromMarkup(markup, emptyFunction)[0];
@@ -9,7 +9,7 @@
9
9
  * @providesModule DefaultEventPluginOrder
10
10
  */
11
11
 
12
- "use strict";
12
+ 'use strict';
13
13
 
14
14
  var keyOf = require("./keyOf");
15
15
 
@@ -29,7 +29,6 @@ var DefaultEventPluginOrder = [
29
29
  keyOf({EnterLeaveEventPlugin: null}),
30
30
  keyOf({ChangeEventPlugin: null}),
31
31
  keyOf({SelectEventPlugin: null}),
32
- keyOf({CompositionEventPlugin: null}),
33
32
  keyOf({BeforeInputEventPlugin: null}),
34
33
  keyOf({AnalyticsEventPlugin: null}),
35
34
  keyOf({MobileSafariClickEventPlugin: null})
@@ -10,7 +10,7 @@
10
10
  * @typechecks static-only
11
11
  */
12
12
 
13
- "use strict";
13
+ 'use strict';
14
14
 
15
15
  var EventConstants = require("./EventConstants");
16
16
  var EventPropagators = require("./EventPropagators");
@@ -9,7 +9,7 @@
9
9
  * @providesModule EventConstants
10
10
  */
11
11
 
12
- "use strict";
12
+ 'use strict';
13
13
 
14
14
  var keyMirror = require("./keyMirror");
15
15
 
@@ -9,7 +9,7 @@
9
9
  * @providesModule EventPluginHub
10
10
  */
11
11
 
12
- "use strict";
12
+ 'use strict';
13
13
 
14
14
  var EventPluginRegistry = require("./EventPluginRegistry");
15
15
  var EventPluginUtils = require("./EventPluginUtils");
@@ -58,12 +58,14 @@ var executeDispatchesAndRelease = function(event) {
58
58
  var InstanceHandle = null;
59
59
 
60
60
  function validateInstanceHandle() {
61
- var invalid = !InstanceHandle||
62
- !InstanceHandle.traverseTwoPhase ||
63
- !InstanceHandle.traverseEnterLeave;
64
- if (invalid) {
65
- throw new Error('InstanceHandle not injected before use!');
66
- }
61
+ var valid =
62
+ InstanceHandle &&
63
+ InstanceHandle.traverseTwoPhase &&
64
+ InstanceHandle.traverseEnterLeave;
65
+ ("production" !== process.env.NODE_ENV ? invariant(
66
+ valid,
67
+ 'InstanceHandle not injected before use!'
68
+ ) : invariant(valid));
67
69
  }
68
70
 
69
71
  /**
@@ -10,7 +10,7 @@
10
10
  * @typechecks static-only
11
11
  */
12
12
 
13
- "use strict";
13
+ 'use strict';
14
14
 
15
15
  var invariant = require("./invariant");
16
16
 
@@ -9,7 +9,7 @@
9
9
  * @providesModule EventPluginUtils
10
10
  */
11
11
 
12
- "use strict";
12
+ 'use strict';
13
13
 
14
14
  var EventConstants = require("./EventConstants");
15
15
 
@@ -9,7 +9,7 @@
9
9
  * @providesModule EventPropagators
10
10
  */
11
11
 
12
- "use strict";
12
+ 'use strict';
13
13
 
14
14
  var EventConstants = require("./EventConstants");
15
15
  var EventPluginHub = require("./EventPluginHub");
@@ -14,9 +14,8 @@
14
14
  "use strict";
15
15
 
16
16
  var canUseDOM = !!(
17
- typeof window !== 'undefined' &&
18
- window.document &&
19
- window.document.createElement
17
+ (typeof window !== 'undefined' &&
18
+ window.document && window.document.createElement)
20
19
  );
21
20
 
22
21
  /**
@@ -0,0 +1,89 @@
1
+ /**
2
+ * Copyright 2013 Facebook, Inc.
3
+ * All rights reserved.
4
+ *
5
+ * This source code is licensed under the BSD-style license found in the
6
+ * LICENSE file in the root directory of this source tree. An additional grant
7
+ * of patent rights can be found in the PATENTS file in the same directory.
8
+ *
9
+ * @providesModule FallbackCompositionState
10
+ * @typechecks static-only
11
+ */
12
+
13
+ 'use strict';
14
+
15
+ var PooledClass = require("./PooledClass");
16
+
17
+ var assign = require("./Object.assign");
18
+ var getTextContentAccessor = require("./getTextContentAccessor");
19
+
20
+ /**
21
+ * This helper class stores information about text content of a target node,
22
+ * allowing comparison of content before and after a given event.
23
+ *
24
+ * Identify the node where selection currently begins, then observe
25
+ * both its text content and its current position in the DOM. Since the
26
+ * browser may natively replace the target node during composition, we can
27
+ * use its position to find its replacement.
28
+ *
29
+ * @param {DOMEventTarget} root
30
+ */
31
+ function FallbackCompositionState(root) {
32
+ this._root = root;
33
+ this._startText = this.getText();
34
+ this._fallbackText = null;
35
+ }
36
+
37
+ assign(FallbackCompositionState.prototype, {
38
+ /**
39
+ * Get current text of input.
40
+ *
41
+ * @return {string}
42
+ */
43
+ getText: function() {
44
+ if ('value' in this._root) {
45
+ return this._root.value;
46
+ }
47
+ return this._root[getTextContentAccessor()];
48
+ },
49
+
50
+ /**
51
+ * Determine the differing substring between the initially stored
52
+ * text content and the current content.
53
+ *
54
+ * @return {string}
55
+ */
56
+ getData: function() {
57
+ if (this._fallbackText) {
58
+ return this._fallbackText;
59
+ }
60
+
61
+ var start;
62
+ var startValue = this._startText;
63
+ var startLength = startValue.length;
64
+ var end;
65
+ var endValue = this.getText();
66
+ var endLength = endValue.length;
67
+
68
+ for (start = 0; start < startLength; start++) {
69
+ if (startValue[start] !== endValue[start]) {
70
+ break;
71
+ }
72
+ }
73
+
74
+ var minEnd = startLength - start;
75
+ for (end = 1; end <= minEnd; end++) {
76
+ if (startValue[startLength - end] !== endValue[endLength - end]) {
77
+ break;
78
+ }
79
+ }
80
+
81
+ var sliceTail = end > 1 ? 1 - end : undefined;
82
+ this._fallbackText = endValue.slice(start, sliceTail);
83
+ return this._fallbackText;
84
+ }
85
+ });
86
+
87
+ PooledClass.addPoolingTo(FallbackCompositionState);
88
+
89
+ module.exports = FallbackCompositionState;