react-test-renderer 15.5.0 → 15.5.4

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 (168) hide show
  1. package/lib/ReactShallowRenderer.js +6 -0
  2. package/lib/shallow/ARIADOMPropertyConfig.js +73 -0
  3. package/lib/shallow/AutoFocusUtils.js +23 -0
  4. package/lib/shallow/BeforeInputEventPlugin.js +384 -0
  5. package/lib/shallow/CSSProperty.js +147 -0
  6. package/lib/shallow/CSSPropertyOperations.js +208 -0
  7. package/lib/shallow/CallbackQueue.js +118 -0
  8. package/lib/shallow/ChangeEventPlugin.js +345 -0
  9. package/lib/shallow/DOMChildrenOperations.js +224 -0
  10. package/lib/shallow/DOMLazyTree.js +117 -0
  11. package/lib/shallow/DOMNamespaces.js +19 -0
  12. package/lib/shallow/DOMProperty.js +209 -0
  13. package/lib/shallow/DOMPropertyOperations.js +236 -0
  14. package/lib/shallow/Danger.js +47 -0
  15. package/lib/shallow/DefaultEventPluginOrder.js +25 -0
  16. package/lib/shallow/EnterLeaveEventPlugin.js +99 -0
  17. package/lib/shallow/EventConstants.js +91 -0
  18. package/lib/shallow/EventPluginHub.js +277 -0
  19. package/lib/shallow/EventPluginRegistry.js +254 -0
  20. package/lib/shallow/EventPluginUtils.js +225 -0
  21. package/lib/shallow/EventPropagators.js +133 -0
  22. package/lib/shallow/FallbackCompositionState.js +94 -0
  23. package/lib/shallow/HTMLDOMPropertyConfig.js +235 -0
  24. package/lib/shallow/KeyEscapeUtils.js +58 -0
  25. package/lib/shallow/LinkedValueUtils.js +137 -0
  26. package/lib/shallow/PluginModuleType.js +12 -0
  27. package/lib/shallow/PooledClass.js +111 -0
  28. package/lib/shallow/ReactBrowserEventEmitter.js +327 -0
  29. package/lib/shallow/ReactChildFiber.js +243 -0
  30. package/lib/shallow/ReactChildReconciler.js +153 -0
  31. package/lib/shallow/ReactComponentBrowserEnvironment.js +29 -0
  32. package/lib/shallow/ReactComponentEnvironment.js +45 -0
  33. package/lib/shallow/ReactCompositeComponent.js +901 -0
  34. package/lib/shallow/ReactCoroutine.js +80 -0
  35. package/lib/shallow/ReactDOM.js +110 -0
  36. package/lib/shallow/ReactDOMComponent.js +1000 -0
  37. package/lib/shallow/ReactDOMComponentFlags.js +17 -0
  38. package/lib/shallow/ReactDOMComponentTree.js +194 -0
  39. package/lib/shallow/ReactDOMContainerInfo.js +32 -0
  40. package/lib/shallow/ReactDOMEmptyComponent.js +59 -0
  41. package/lib/shallow/ReactDOMFeatureFlags.js +18 -0
  42. package/lib/shallow/ReactDOMFiber.js +97 -0
  43. package/lib/shallow/ReactDOMIDOperations.js +33 -0
  44. package/lib/shallow/ReactDOMInput.js +284 -0
  45. package/lib/shallow/ReactDOMInvalidARIAHook.js +92 -0
  46. package/lib/shallow/ReactDOMNullInputValuePropHook.js +42 -0
  47. package/lib/shallow/ReactDOMOption.js +122 -0
  48. package/lib/shallow/ReactDOMSelect.js +199 -0
  49. package/lib/shallow/ReactDOMSelection.js +211 -0
  50. package/lib/shallow/ReactDOMServer.js +25 -0
  51. package/lib/shallow/ReactDOMTextComponent.js +163 -0
  52. package/lib/shallow/ReactDOMTextarea.js +159 -0
  53. package/lib/shallow/ReactDOMTreeTraversal.js +135 -0
  54. package/lib/shallow/ReactDOMUnknownPropertyHook.js +111 -0
  55. package/lib/shallow/ReactDebugTool.js +358 -0
  56. package/lib/shallow/ReactDefaultBatchingStrategy.js +67 -0
  57. package/lib/shallow/ReactDefaultInjection.js +85 -0
  58. package/lib/shallow/ReactElementSymbol.js +19 -0
  59. package/lib/shallow/ReactEmptyComponent.js +29 -0
  60. package/lib/shallow/ReactErrorUtils.js +75 -0
  61. package/lib/shallow/ReactEventEmitterMixin.js +32 -0
  62. package/lib/shallow/ReactEventListener.js +154 -0
  63. package/lib/shallow/ReactFeatureFlags.js +21 -0
  64. package/lib/shallow/ReactFiber.js +190 -0
  65. package/lib/shallow/ReactFiberBeginWork.js +380 -0
  66. package/lib/shallow/ReactFiberCommitWork.js +78 -0
  67. package/lib/shallow/ReactFiberCompleteWork.js +208 -0
  68. package/lib/shallow/ReactFiberReconciler.js +64 -0
  69. package/lib/shallow/ReactFiberRoot.js +29 -0
  70. package/lib/shallow/ReactFiberScheduler.js +331 -0
  71. package/lib/shallow/ReactFiberUpdateQueue.js +77 -0
  72. package/lib/shallow/ReactHostComponent.js +67 -0
  73. package/lib/shallow/ReactHostOperationHistoryHook.js +33 -0
  74. package/lib/shallow/ReactInjection.js +33 -0
  75. package/lib/shallow/ReactInputSelection.js +123 -0
  76. package/lib/shallow/ReactInstanceMap.js +47 -0
  77. package/lib/shallow/ReactInstanceType.js +12 -0
  78. package/lib/shallow/ReactInstrumentation.js +23 -0
  79. package/lib/shallow/ReactInvalidSetStateWarningHook.js +36 -0
  80. package/lib/shallow/ReactMarkupChecksum.js +49 -0
  81. package/lib/shallow/ReactMount.js +537 -0
  82. package/lib/shallow/ReactMultiChild.js +449 -0
  83. package/lib/shallow/ReactMultiChildUpdateTypes.js +18 -0
  84. package/lib/shallow/ReactNodeTypes.js +39 -0
  85. package/lib/shallow/ReactOwner.js +93 -0
  86. package/lib/shallow/ReactPerf.js +500 -0
  87. package/lib/shallow/ReactPriorityLevel.js +20 -0
  88. package/lib/shallow/ReactPropTypeLocationNames.js +24 -0
  89. package/lib/shallow/ReactPropTypeLocations.js +12 -0
  90. package/lib/shallow/ReactPropTypesSecret.js +16 -0
  91. package/lib/shallow/ReactReconcileTransaction.js +177 -0
  92. package/lib/shallow/ReactReconciler.js +167 -0
  93. package/lib/shallow/ReactRef.js +88 -0
  94. package/lib/shallow/ReactReifiedYield.js +30 -0
  95. package/lib/shallow/ReactServerBatchingStrategy.js +21 -0
  96. package/lib/shallow/ReactServerRendering.js +89 -0
  97. package/lib/shallow/ReactServerRenderingTransaction.js +89 -0
  98. package/lib/shallow/ReactServerUpdateQueue.js +138 -0
  99. package/lib/shallow/ReactShallowRenderer.js +150 -0
  100. package/lib/shallow/ReactSimpleEmptyComponent.js +36 -0
  101. package/lib/shallow/ReactSyntheticEventType.js +14 -0
  102. package/lib/shallow/ReactTestEmptyComponent.js +36 -0
  103. package/lib/shallow/ReactTestMount.js +131 -0
  104. package/lib/shallow/ReactTestReconcileTransaction.js +128 -0
  105. package/lib/shallow/ReactTestRenderer.js +139 -0
  106. package/lib/shallow/ReactTestTextComponent.js +40 -0
  107. package/lib/shallow/ReactTypeOfWork.js +23 -0
  108. package/lib/shallow/ReactTypes.js +12 -0
  109. package/lib/shallow/ReactUpdateQueue.js +235 -0
  110. package/lib/shallow/ReactUpdates.js +250 -0
  111. package/lib/shallow/ReactVersion.js +13 -0
  112. package/lib/shallow/ResponderEventPlugin.js +507 -0
  113. package/lib/shallow/ResponderSyntheticEvent.js +38 -0
  114. package/lib/shallow/ResponderTouchHistoryStore.js +183 -0
  115. package/lib/shallow/SVGDOMPropertyConfig.js +301 -0
  116. package/lib/shallow/SelectEventPlugin.js +190 -0
  117. package/lib/shallow/SimpleEventPlugin.js +227 -0
  118. package/lib/shallow/SyntheticAnimationEvent.js +38 -0
  119. package/lib/shallow/SyntheticClipboardEvent.js +37 -0
  120. package/lib/shallow/SyntheticCompositionEvent.js +35 -0
  121. package/lib/shallow/SyntheticDragEvent.js +35 -0
  122. package/lib/shallow/SyntheticEvent.js +267 -0
  123. package/lib/shallow/SyntheticFocusEvent.js +35 -0
  124. package/lib/shallow/SyntheticInputEvent.js +36 -0
  125. package/lib/shallow/SyntheticKeyboardEvent.js +83 -0
  126. package/lib/shallow/SyntheticMouseEvent.js +71 -0
  127. package/lib/shallow/SyntheticTouchEvent.js +44 -0
  128. package/lib/shallow/SyntheticTransitionEvent.js +38 -0
  129. package/lib/shallow/SyntheticUIEvent.js +58 -0
  130. package/lib/shallow/SyntheticWheelEvent.js +53 -0
  131. package/lib/shallow/TapEventPlugin.js +115 -0
  132. package/lib/shallow/TouchHistoryMath.js +98 -0
  133. package/lib/shallow/Transaction.js +224 -0
  134. package/lib/shallow/ViewportMetrics.js +26 -0
  135. package/lib/shallow/accumulate.js +45 -0
  136. package/lib/shallow/accumulateInto.js +57 -0
  137. package/lib/shallow/adler32.js +43 -0
  138. package/lib/shallow/canDefineProperty.js +25 -0
  139. package/lib/shallow/checkReactTypeSpec.js +86 -0
  140. package/lib/shallow/createMicrosoftUnsafeLocalFunction.js +31 -0
  141. package/lib/shallow/dangerousStyleValue.js +78 -0
  142. package/lib/shallow/deprecated.js +56 -0
  143. package/lib/shallow/escapeTextContentForBrowser.js +122 -0
  144. package/lib/shallow/findDOMNode.js +59 -0
  145. package/lib/shallow/flattenChildren.js +75 -0
  146. package/lib/shallow/forEachAccumulated.js +30 -0
  147. package/lib/shallow/getEventCharCode.js +49 -0
  148. package/lib/shallow/getEventKey.js +101 -0
  149. package/lib/shallow/getEventModifierState.js +42 -0
  150. package/lib/shallow/getEventTarget.js +34 -0
  151. package/lib/shallow/getHostComponentFromComposite.js +29 -0
  152. package/lib/shallow/getIteratorFn.js +40 -0
  153. package/lib/shallow/getNodeForCharacterOffset.js +73 -0
  154. package/lib/shallow/getTextContentAccessor.js +32 -0
  155. package/lib/shallow/getVendorPrefixedEventName.js +100 -0
  156. package/lib/shallow/instantiateReactComponent.js +128 -0
  157. package/lib/shallow/isEventSupported.js +59 -0
  158. package/lib/shallow/isTextInputElement.js +50 -0
  159. package/lib/shallow/quoteAttributeValueForBrowser.js +25 -0
  160. package/lib/shallow/reactProdInvariant.js +38 -0
  161. package/lib/shallow/renderSubtreeIntoContainer.js +15 -0
  162. package/lib/shallow/setInnerHTML.js +97 -0
  163. package/lib/shallow/setTextContent.js +51 -0
  164. package/lib/shallow/shouldUpdateReactComponent.js +41 -0
  165. package/lib/shallow/traverseAllChildren.js +175 -0
  166. package/lib/shallow/validateDOMNesting.js +376 -0
  167. package/package.json +1 -1
  168. package/shallow.js +1 -1
@@ -124,6 +124,12 @@ var ReactShallowRenderer = function () {
124
124
  }
125
125
  };
126
126
 
127
+ ReactShallowRenderer.prototype.unstable_batchedUpdates = function unstable_batchedUpdates(callback, bookkeeping) {
128
+ // This is used by Enzyme for fake-simulating events in shallow mode.
129
+ injectDefaults();
130
+ return ReactUpdates.batchedUpdates(callback, bookkeeping);
131
+ };
132
+
127
133
  ReactShallowRenderer.prototype._render = function _render(element, transaction, context) {
128
134
  if (this._instance) {
129
135
  ReactReconciler.receiveComponent(this._instance, element, transaction, context);
@@ -0,0 +1,73 @@
1
+ /**
2
+ * Copyright 2013-present, 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
+ */
10
+
11
+ 'use strict';
12
+
13
+ var ARIADOMPropertyConfig = {
14
+ Properties: {
15
+ // Global States and Properties
16
+ 'aria-current': 0, // state
17
+ 'aria-details': 0,
18
+ 'aria-disabled': 0, // state
19
+ 'aria-hidden': 0, // state
20
+ 'aria-invalid': 0, // state
21
+ 'aria-keyshortcuts': 0,
22
+ 'aria-label': 0,
23
+ 'aria-roledescription': 0,
24
+ // Widget Attributes
25
+ 'aria-autocomplete': 0,
26
+ 'aria-checked': 0,
27
+ 'aria-expanded': 0,
28
+ 'aria-haspopup': 0,
29
+ 'aria-level': 0,
30
+ 'aria-modal': 0,
31
+ 'aria-multiline': 0,
32
+ 'aria-multiselectable': 0,
33
+ 'aria-orientation': 0,
34
+ 'aria-placeholder': 0,
35
+ 'aria-pressed': 0,
36
+ 'aria-readonly': 0,
37
+ 'aria-required': 0,
38
+ 'aria-selected': 0,
39
+ 'aria-sort': 0,
40
+ 'aria-valuemax': 0,
41
+ 'aria-valuemin': 0,
42
+ 'aria-valuenow': 0,
43
+ 'aria-valuetext': 0,
44
+ // Live Region Attributes
45
+ 'aria-atomic': 0,
46
+ 'aria-busy': 0,
47
+ 'aria-live': 0,
48
+ 'aria-relevant': 0,
49
+ // Drag-and-Drop Attributes
50
+ 'aria-dropeffect': 0,
51
+ 'aria-grabbed': 0,
52
+ // Relationship Attributes
53
+ 'aria-activedescendant': 0,
54
+ 'aria-colcount': 0,
55
+ 'aria-colindex': 0,
56
+ 'aria-colspan': 0,
57
+ 'aria-controls': 0,
58
+ 'aria-describedby': 0,
59
+ 'aria-errormessage': 0,
60
+ 'aria-flowto': 0,
61
+ 'aria-labelledby': 0,
62
+ 'aria-owns': 0,
63
+ 'aria-posinset': 0,
64
+ 'aria-rowcount': 0,
65
+ 'aria-rowindex': 0,
66
+ 'aria-rowspan': 0,
67
+ 'aria-setsize': 0
68
+ },
69
+ DOMAttributeNames: {},
70
+ DOMPropertyNames: {}
71
+ };
72
+
73
+ module.exports = ARIADOMPropertyConfig;
@@ -0,0 +1,23 @@
1
+ /**
2
+ * Copyright 2013-present, 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
+ */
10
+
11
+ 'use strict';
12
+
13
+ var ReactDOMComponentTree = require('./ReactDOMComponentTree');
14
+
15
+ var focusNode = require('fbjs/lib/focusNode');
16
+
17
+ var AutoFocusUtils = {
18
+ focusDOMComponent: function () {
19
+ focusNode(ReactDOMComponentTree.getNodeFromInstance(this));
20
+ }
21
+ };
22
+
23
+ module.exports = AutoFocusUtils;
@@ -0,0 +1,384 @@
1
+ /**
2
+ * Copyright 2013-present 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
+ */
10
+
11
+ 'use strict';
12
+
13
+ var EventPropagators = require('./EventPropagators');
14
+ var ExecutionEnvironment = require('fbjs/lib/ExecutionEnvironment');
15
+ var FallbackCompositionState = require('./FallbackCompositionState');
16
+ var SyntheticCompositionEvent = require('./SyntheticCompositionEvent');
17
+ var SyntheticInputEvent = require('./SyntheticInputEvent');
18
+
19
+ var END_KEYCODES = [9, 13, 27, 32]; // Tab, Return, Esc, Space
20
+ var START_KEYCODE = 229;
21
+
22
+ var canUseCompositionEvent = ExecutionEnvironment.canUseDOM && 'CompositionEvent' in window;
23
+
24
+ var documentMode = null;
25
+ if (ExecutionEnvironment.canUseDOM && 'documentMode' in document) {
26
+ documentMode = document.documentMode;
27
+ }
28
+
29
+ // Webkit offers a very useful `textInput` event that can be used to
30
+ // directly represent `beforeInput`. The IE `textinput` event is not as
31
+ // useful, so we don't use it.
32
+ var canUseTextInputEvent = ExecutionEnvironment.canUseDOM && 'TextEvent' in window && !documentMode && !isPresto();
33
+
34
+ // In IE9+, we have access to composition events, but the data supplied
35
+ // by the native compositionend event may be incorrect. Japanese ideographic
36
+ // spaces, for instance (\u3000) are not recorded correctly.
37
+ var useFallbackCompositionData = ExecutionEnvironment.canUseDOM && (!canUseCompositionEvent || documentMode && documentMode > 8 && documentMode <= 11);
38
+
39
+ /**
40
+ * Opera <= 12 includes TextEvent in window, but does not fire
41
+ * text input events. Rely on keypress instead.
42
+ */
43
+ function isPresto() {
44
+ var opera = window.opera;
45
+ return typeof opera === 'object' && typeof opera.version === 'function' && parseInt(opera.version(), 10) <= 12;
46
+ }
47
+
48
+ var SPACEBAR_CODE = 32;
49
+ var SPACEBAR_CHAR = String.fromCharCode(SPACEBAR_CODE);
50
+
51
+ // Events and their corresponding property names.
52
+ var eventTypes = {
53
+ beforeInput: {
54
+ phasedRegistrationNames: {
55
+ bubbled: 'onBeforeInput',
56
+ captured: 'onBeforeInputCapture'
57
+ },
58
+ dependencies: ['topCompositionEnd', 'topKeyPress', 'topTextInput', 'topPaste']
59
+ },
60
+ compositionEnd: {
61
+ phasedRegistrationNames: {
62
+ bubbled: 'onCompositionEnd',
63
+ captured: 'onCompositionEndCapture'
64
+ },
65
+ dependencies: ['topBlur', 'topCompositionEnd', 'topKeyDown', 'topKeyPress', 'topKeyUp', 'topMouseDown']
66
+ },
67
+ compositionStart: {
68
+ phasedRegistrationNames: {
69
+ bubbled: 'onCompositionStart',
70
+ captured: 'onCompositionStartCapture'
71
+ },
72
+ dependencies: ['topBlur', 'topCompositionStart', 'topKeyDown', 'topKeyPress', 'topKeyUp', 'topMouseDown']
73
+ },
74
+ compositionUpdate: {
75
+ phasedRegistrationNames: {
76
+ bubbled: 'onCompositionUpdate',
77
+ captured: 'onCompositionUpdateCapture'
78
+ },
79
+ dependencies: ['topBlur', 'topCompositionUpdate', 'topKeyDown', 'topKeyPress', 'topKeyUp', 'topMouseDown']
80
+ }
81
+ };
82
+
83
+ // Track whether we've ever handled a keypress on the space key.
84
+ var hasSpaceKeypress = false;
85
+
86
+ /**
87
+ * Return whether a native keypress event is assumed to be a command.
88
+ * This is required because Firefox fires `keypress` events for key commands
89
+ * (cut, copy, select-all, etc.) even though no character is inserted.
90
+ */
91
+ function isKeypressCommand(nativeEvent) {
92
+ return (nativeEvent.ctrlKey || nativeEvent.altKey || nativeEvent.metaKey) &&
93
+ // ctrlKey && altKey is equivalent to AltGr, and is not a command.
94
+ !(nativeEvent.ctrlKey && nativeEvent.altKey);
95
+ }
96
+
97
+ /**
98
+ * Translate native top level events into event types.
99
+ *
100
+ * @param {string} topLevelType
101
+ * @return {object}
102
+ */
103
+ function getCompositionEventType(topLevelType) {
104
+ switch (topLevelType) {
105
+ case 'topCompositionStart':
106
+ return eventTypes.compositionStart;
107
+ case 'topCompositionEnd':
108
+ return eventTypes.compositionEnd;
109
+ case 'topCompositionUpdate':
110
+ return eventTypes.compositionUpdate;
111
+ }
112
+ }
113
+
114
+ /**
115
+ * Does our fallback best-guess model think this event signifies that
116
+ * composition has begun?
117
+ *
118
+ * @param {string} topLevelType
119
+ * @param {object} nativeEvent
120
+ * @return {boolean}
121
+ */
122
+ function isFallbackCompositionStart(topLevelType, nativeEvent) {
123
+ return topLevelType === 'topKeyDown' && nativeEvent.keyCode === START_KEYCODE;
124
+ }
125
+
126
+ /**
127
+ * Does our fallback mode think that this event is the end of composition?
128
+ *
129
+ * @param {string} topLevelType
130
+ * @param {object} nativeEvent
131
+ * @return {boolean}
132
+ */
133
+ function isFallbackCompositionEnd(topLevelType, nativeEvent) {
134
+ switch (topLevelType) {
135
+ case 'topKeyUp':
136
+ // Command keys insert or clear IME input.
137
+ return END_KEYCODES.indexOf(nativeEvent.keyCode) !== -1;
138
+ case 'topKeyDown':
139
+ // Expect IME keyCode on each keydown. If we get any other
140
+ // code we must have exited earlier.
141
+ return nativeEvent.keyCode !== START_KEYCODE;
142
+ case 'topKeyPress':
143
+ case 'topMouseDown':
144
+ case 'topBlur':
145
+ // Events are not possible without cancelling IME.
146
+ return true;
147
+ default:
148
+ return false;
149
+ }
150
+ }
151
+
152
+ /**
153
+ * Google Input Tools provides composition data via a CustomEvent,
154
+ * with the `data` property populated in the `detail` object. If this
155
+ * is available on the event object, use it. If not, this is a plain
156
+ * composition event and we have nothing special to extract.
157
+ *
158
+ * @param {object} nativeEvent
159
+ * @return {?string}
160
+ */
161
+ function getDataFromCustomEvent(nativeEvent) {
162
+ var detail = nativeEvent.detail;
163
+ if (typeof detail === 'object' && 'data' in detail) {
164
+ return detail.data;
165
+ }
166
+ return null;
167
+ }
168
+
169
+ // Track the current IME composition fallback object, if any.
170
+ var currentComposition = null;
171
+
172
+ /**
173
+ * @return {?object} A SyntheticCompositionEvent.
174
+ */
175
+ function extractCompositionEvent(topLevelType, targetInst, nativeEvent, nativeEventTarget) {
176
+ var eventType;
177
+ var fallbackData;
178
+
179
+ if (canUseCompositionEvent) {
180
+ eventType = getCompositionEventType(topLevelType);
181
+ } else if (!currentComposition) {
182
+ if (isFallbackCompositionStart(topLevelType, nativeEvent)) {
183
+ eventType = eventTypes.compositionStart;
184
+ }
185
+ } else if (isFallbackCompositionEnd(topLevelType, nativeEvent)) {
186
+ eventType = eventTypes.compositionEnd;
187
+ }
188
+
189
+ if (!eventType) {
190
+ return null;
191
+ }
192
+
193
+ if (useFallbackCompositionData) {
194
+ // The current composition is stored statically and must not be
195
+ // overwritten while composition continues.
196
+ if (!currentComposition && eventType === eventTypes.compositionStart) {
197
+ currentComposition = FallbackCompositionState.getPooled(nativeEventTarget);
198
+ } else if (eventType === eventTypes.compositionEnd) {
199
+ if (currentComposition) {
200
+ fallbackData = currentComposition.getData();
201
+ }
202
+ }
203
+ }
204
+
205
+ var event = SyntheticCompositionEvent.getPooled(eventType, targetInst, nativeEvent, nativeEventTarget);
206
+
207
+ if (fallbackData) {
208
+ // Inject data generated from fallback path into the synthetic event.
209
+ // This matches the property of native CompositionEventInterface.
210
+ event.data = fallbackData;
211
+ } else {
212
+ var customData = getDataFromCustomEvent(nativeEvent);
213
+ if (customData !== null) {
214
+ event.data = customData;
215
+ }
216
+ }
217
+
218
+ EventPropagators.accumulateTwoPhaseDispatches(event);
219
+ return event;
220
+ }
221
+
222
+ /**
223
+ * @param {string} topLevelType Record from `EventConstants`.
224
+ * @param {object} nativeEvent Native browser event.
225
+ * @return {?string} The string corresponding to this `beforeInput` event.
226
+ */
227
+ function getNativeBeforeInputChars(topLevelType, nativeEvent) {
228
+ switch (topLevelType) {
229
+ case 'topCompositionEnd':
230
+ return getDataFromCustomEvent(nativeEvent);
231
+ case 'topKeyPress':
232
+ /**
233
+ * If native `textInput` events are available, our goal is to make
234
+ * use of them. However, there is a special case: the spacebar key.
235
+ * In Webkit, preventing default on a spacebar `textInput` event
236
+ * cancels character insertion, but it *also* causes the browser
237
+ * to fall back to its default spacebar behavior of scrolling the
238
+ * page.
239
+ *
240
+ * Tracking at:
241
+ * https://code.google.com/p/chromium/issues/detail?id=355103
242
+ *
243
+ * To avoid this issue, use the keypress event as if no `textInput`
244
+ * event is available.
245
+ */
246
+ var which = nativeEvent.which;
247
+ if (which !== SPACEBAR_CODE) {
248
+ return null;
249
+ }
250
+
251
+ hasSpaceKeypress = true;
252
+ return SPACEBAR_CHAR;
253
+
254
+ case 'topTextInput':
255
+ // Record the characters to be added to the DOM.
256
+ var chars = nativeEvent.data;
257
+
258
+ // If it's a spacebar character, assume that we have already handled
259
+ // it at the keypress level and bail immediately. Android Chrome
260
+ // doesn't give us keycodes, so we need to blacklist it.
261
+ if (chars === SPACEBAR_CHAR && hasSpaceKeypress) {
262
+ return null;
263
+ }
264
+
265
+ return chars;
266
+
267
+ default:
268
+ // For other native event types, do nothing.
269
+ return null;
270
+ }
271
+ }
272
+
273
+ /**
274
+ * For browsers that do not provide the `textInput` event, extract the
275
+ * appropriate string to use for SyntheticInputEvent.
276
+ *
277
+ * @param {string} topLevelType Record from `EventConstants`.
278
+ * @param {object} nativeEvent Native browser event.
279
+ * @return {?string} The fallback string for this `beforeInput` event.
280
+ */
281
+ function getFallbackBeforeInputChars(topLevelType, nativeEvent) {
282
+ // If we are currently composing (IME) and using a fallback to do so,
283
+ // try to extract the composed characters from the fallback object.
284
+ // If composition event is available, we extract a string only at
285
+ // compositionevent, otherwise extract it at fallback events.
286
+ if (currentComposition) {
287
+ if (topLevelType === 'topCompositionEnd' || !canUseCompositionEvent && isFallbackCompositionEnd(topLevelType, nativeEvent)) {
288
+ var chars = currentComposition.getData();
289
+ FallbackCompositionState.release(currentComposition);
290
+ currentComposition = null;
291
+ return chars;
292
+ }
293
+ return null;
294
+ }
295
+
296
+ switch (topLevelType) {
297
+ case 'topPaste':
298
+ // If a paste event occurs after a keypress, throw out the input
299
+ // chars. Paste events should not lead to BeforeInput events.
300
+ return null;
301
+ case 'topKeyPress':
302
+ /**
303
+ * As of v27, Firefox may fire keypress events even when no character
304
+ * will be inserted. A few possibilities:
305
+ *
306
+ * - `which` is `0`. Arrow keys, Esc key, etc.
307
+ *
308
+ * - `which` is the pressed key code, but no char is available.
309
+ * Ex: 'AltGr + d` in Polish. There is no modified character for
310
+ * this key combination and no character is inserted into the
311
+ * document, but FF fires the keypress for char code `100` anyway.
312
+ * No `input` event will occur.
313
+ *
314
+ * - `which` is the pressed key code, but a command combination is
315
+ * being used. Ex: `Cmd+C`. No character is inserted, and no
316
+ * `input` event will occur.
317
+ */
318
+ if (nativeEvent.which && !isKeypressCommand(nativeEvent)) {
319
+ return String.fromCharCode(nativeEvent.which);
320
+ }
321
+ return null;
322
+ case 'topCompositionEnd':
323
+ return useFallbackCompositionData ? null : nativeEvent.data;
324
+ default:
325
+ return null;
326
+ }
327
+ }
328
+
329
+ /**
330
+ * Extract a SyntheticInputEvent for `beforeInput`, based on either native
331
+ * `textInput` or fallback behavior.
332
+ *
333
+ * @return {?object} A SyntheticInputEvent.
334
+ */
335
+ function extractBeforeInputEvent(topLevelType, targetInst, nativeEvent, nativeEventTarget) {
336
+ var chars;
337
+
338
+ if (canUseTextInputEvent) {
339
+ chars = getNativeBeforeInputChars(topLevelType, nativeEvent);
340
+ } else {
341
+ chars = getFallbackBeforeInputChars(topLevelType, nativeEvent);
342
+ }
343
+
344
+ // If no characters are being inserted, no BeforeInput event should
345
+ // be fired.
346
+ if (!chars) {
347
+ return null;
348
+ }
349
+
350
+ var event = SyntheticInputEvent.getPooled(eventTypes.beforeInput, targetInst, nativeEvent, nativeEventTarget);
351
+
352
+ event.data = chars;
353
+ EventPropagators.accumulateTwoPhaseDispatches(event);
354
+ return event;
355
+ }
356
+
357
+ /**
358
+ * Create an `onBeforeInput` event to match
359
+ * http://www.w3.org/TR/2013/WD-DOM-Level-3-Events-20131105/#events-inputevents.
360
+ *
361
+ * This event plugin is based on the native `textInput` event
362
+ * available in Chrome, Safari, Opera, and IE. This event fires after
363
+ * `onKeyPress` and `onCompositionEnd`, but before `onInput`.
364
+ *
365
+ * `beforeInput` is spec'd but not implemented in any browsers, and
366
+ * the `input` event does not provide any useful information about what has
367
+ * actually been added, contrary to the spec. Thus, `textInput` is the best
368
+ * available event to identify the characters that have actually been inserted
369
+ * into the target node.
370
+ *
371
+ * This plugin is also responsible for emitting `composition` events, thus
372
+ * allowing us to share composition fallback code for both `beforeInput` and
373
+ * `composition` event types.
374
+ */
375
+ var BeforeInputEventPlugin = {
376
+
377
+ eventTypes: eventTypes,
378
+
379
+ extractEvents: function (topLevelType, targetInst, nativeEvent, nativeEventTarget) {
380
+ return [extractCompositionEvent(topLevelType, targetInst, nativeEvent, nativeEventTarget), extractBeforeInputEvent(topLevelType, targetInst, nativeEvent, nativeEventTarget)];
381
+ }
382
+ };
383
+
384
+ module.exports = BeforeInputEventPlugin;
@@ -0,0 +1,147 @@
1
+ /**
2
+ * Copyright 2013-present, 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
+ */
10
+
11
+ 'use strict';
12
+
13
+ /**
14
+ * CSS properties which accept numbers but are not in units of "px".
15
+ */
16
+
17
+ var isUnitlessNumber = {
18
+ animationIterationCount: true,
19
+ borderImageOutset: true,
20
+ borderImageSlice: true,
21
+ borderImageWidth: true,
22
+ boxFlex: true,
23
+ boxFlexGroup: true,
24
+ boxOrdinalGroup: true,
25
+ columnCount: true,
26
+ flex: true,
27
+ flexGrow: true,
28
+ flexPositive: true,
29
+ flexShrink: true,
30
+ flexNegative: true,
31
+ flexOrder: true,
32
+ gridRow: true,
33
+ gridColumn: true,
34
+ fontWeight: true,
35
+ lineClamp: true,
36
+ lineHeight: true,
37
+ opacity: true,
38
+ order: true,
39
+ orphans: true,
40
+ tabSize: true,
41
+ widows: true,
42
+ zIndex: true,
43
+ zoom: true,
44
+
45
+ // SVG-related properties
46
+ fillOpacity: true,
47
+ floodOpacity: true,
48
+ stopOpacity: true,
49
+ strokeDasharray: true,
50
+ strokeDashoffset: true,
51
+ strokeMiterlimit: true,
52
+ strokeOpacity: true,
53
+ strokeWidth: true
54
+ };
55
+
56
+ /**
57
+ * @param {string} prefix vendor-specific prefix, eg: Webkit
58
+ * @param {string} key style name, eg: transitionDuration
59
+ * @return {string} style name prefixed with `prefix`, properly camelCased, eg:
60
+ * WebkitTransitionDuration
61
+ */
62
+ function prefixKey(prefix, key) {
63
+ return prefix + key.charAt(0).toUpperCase() + key.substring(1);
64
+ }
65
+
66
+ /**
67
+ * Support style names that may come passed in prefixed by adding permutations
68
+ * of vendor prefixes.
69
+ */
70
+ var prefixes = ['Webkit', 'ms', 'Moz', 'O'];
71
+
72
+ // Using Object.keys here, or else the vanilla for-in loop makes IE8 go into an
73
+ // infinite loop, because it iterates over the newly added props too.
74
+ Object.keys(isUnitlessNumber).forEach(function (prop) {
75
+ prefixes.forEach(function (prefix) {
76
+ isUnitlessNumber[prefixKey(prefix, prop)] = isUnitlessNumber[prop];
77
+ });
78
+ });
79
+
80
+ /**
81
+ * Most style properties can be unset by doing .style[prop] = '' but IE8
82
+ * doesn't like doing that with shorthand properties so for the properties that
83
+ * IE8 breaks on, which are listed here, we instead unset each of the
84
+ * individual properties. See http://bugs.jquery.com/ticket/12385.
85
+ * The 4-value 'clock' properties like margin, padding, border-width seem to
86
+ * behave without any problems. Curiously, list-style works too without any
87
+ * special prodding.
88
+ */
89
+ var shorthandPropertyExpansions = {
90
+ background: {
91
+ backgroundAttachment: true,
92
+ backgroundColor: true,
93
+ backgroundImage: true,
94
+ backgroundPositionX: true,
95
+ backgroundPositionY: true,
96
+ backgroundRepeat: true
97
+ },
98
+ backgroundPosition: {
99
+ backgroundPositionX: true,
100
+ backgroundPositionY: true
101
+ },
102
+ border: {
103
+ borderWidth: true,
104
+ borderStyle: true,
105
+ borderColor: true
106
+ },
107
+ borderBottom: {
108
+ borderBottomWidth: true,
109
+ borderBottomStyle: true,
110
+ borderBottomColor: true
111
+ },
112
+ borderLeft: {
113
+ borderLeftWidth: true,
114
+ borderLeftStyle: true,
115
+ borderLeftColor: true
116
+ },
117
+ borderRight: {
118
+ borderRightWidth: true,
119
+ borderRightStyle: true,
120
+ borderRightColor: true
121
+ },
122
+ borderTop: {
123
+ borderTopWidth: true,
124
+ borderTopStyle: true,
125
+ borderTopColor: true
126
+ },
127
+ font: {
128
+ fontStyle: true,
129
+ fontVariant: true,
130
+ fontWeight: true,
131
+ fontSize: true,
132
+ lineHeight: true,
133
+ fontFamily: true
134
+ },
135
+ outline: {
136
+ outlineWidth: true,
137
+ outlineStyle: true,
138
+ outlineColor: true
139
+ }
140
+ };
141
+
142
+ var CSSProperty = {
143
+ isUnitlessNumber: isUnitlessNumber,
144
+ shorthandPropertyExpansions: shorthandPropertyExpansions
145
+ };
146
+
147
+ module.exports = CSSProperty;