react 0.7.1 → 0.8.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +15 -228
- package/ReactJSErrors.js +40 -0
- package/addons.js +4 -0
- package/lib/$.js +46 -0
- package/lib/CSSCore.js +114 -0
- package/lib/CSSProperty.js +90 -0
- package/lib/CSSPropertyOperations.js +97 -0
- package/lib/CallbackRegistry.js +91 -0
- package/lib/ChangeEventPlugin.js +365 -0
- package/lib/CompositionEventPlugin.js +212 -0
- package/lib/DOMChildrenOperations.js +135 -0
- package/lib/DOMProperty.js +266 -0
- package/lib/DOMPropertyOperations.js +168 -0
- package/lib/Danger.js +186 -0
- package/lib/DefaultDOMPropertyConfig.js +187 -0
- package/lib/DefaultEventPluginOrder.js +44 -0
- package/lib/EnterLeaveEventPlugin.js +112 -0
- package/lib/EventConstants.js +73 -0
- package/lib/EventListener.js +61 -0
- package/lib/EventPluginHub.js +190 -0
- package/lib/EventPluginRegistry.js +237 -0
- package/lib/EventPluginUtils.js +185 -0
- package/lib/EventPropagators.js +179 -0
- package/lib/ExecutionEnvironment.js +41 -0
- package/lib/LinkedStateMixin.js +46 -0
- package/lib/LinkedValueMixin.js +68 -0
- package/lib/MobileSafariClickEventPlugin.js +63 -0
- package/lib/PooledClass.js +113 -0
- package/lib/React.js +71 -0
- package/lib/ReactChildren.js +132 -0
- package/lib/ReactComponent.js +515 -0
- package/lib/ReactComponentBrowserEnvironment.js +140 -0
- package/lib/ReactComponentEnvironment.js +24 -0
- package/lib/ReactCompositeComponent.js +1020 -0
- package/lib/ReactCurrentOwner.js +39 -0
- package/lib/ReactDOM.js +194 -0
- package/lib/ReactDOMButton.js +64 -0
- package/lib/ReactDOMComponent.js +374 -0
- package/lib/ReactDOMForm.js +52 -0
- package/lib/ReactDOMIDOperations.js +173 -0
- package/lib/ReactDOMInput.js +169 -0
- package/lib/ReactDOMOption.js +50 -0
- package/lib/ReactDOMSelect.js +160 -0
- package/lib/ReactDOMSelection.js +189 -0
- package/lib/ReactDOMTextarea.js +136 -0
- package/lib/ReactDefaultBatchingStrategy.js +75 -0
- package/lib/ReactDefaultInjection.js +91 -0
- package/lib/ReactDefaultPerf.js +407 -0
- package/lib/ReactErrorUtils.js +46 -0
- package/lib/ReactEventEmitter.js +341 -0
- package/lib/ReactEventEmitterMixin.js +89 -0
- package/lib/ReactEventTopLevelCallback.js +89 -0
- package/lib/ReactInputSelection.js +140 -0
- package/lib/ReactInstanceHandles.js +322 -0
- package/lib/ReactLink.js +54 -0
- package/lib/ReactMarkupChecksum.js +53 -0
- package/lib/ReactMount.js +617 -0
- package/lib/ReactMountReady.js +95 -0
- package/lib/ReactMultiChild.js +441 -0
- package/lib/ReactMultiChildUpdateTypes.js +36 -0
- package/lib/ReactOwner.js +146 -0
- package/lib/ReactPerf.js +88 -0
- package/lib/ReactPropTransferer.js +128 -0
- package/lib/ReactPropTypes.js +158 -0
- package/lib/ReactReconcileTransaction.js +161 -0
- package/lib/ReactServerRendering.js +62 -0
- package/lib/ReactStateSetters.js +111 -0
- package/lib/ReactTextComponent.js +94 -0
- package/lib/ReactTransitionEvents.js +97 -0
- package/lib/ReactTransitionGroup.js +112 -0
- package/lib/ReactTransitionKeySet.js +111 -0
- package/lib/ReactTransitionableChild.js +152 -0
- package/lib/ReactUpdates.js +145 -0
- package/lib/ReactWithAddons.js +41 -0
- package/lib/SelectEventPlugin.js +217 -0
- package/lib/SimpleEventPlugin.js +365 -0
- package/lib/SyntheticClipboardEvent.js +45 -0
- package/lib/SyntheticCompositionEvent.js +51 -0
- package/lib/SyntheticEvent.js +163 -0
- package/lib/SyntheticFocusEvent.js +44 -0
- package/lib/SyntheticKeyboardEvent.js +56 -0
- package/lib/SyntheticMouseEvent.js +85 -0
- package/lib/SyntheticTouchEvent.js +50 -0
- package/lib/SyntheticUIEvent.js +45 -0
- package/lib/SyntheticWheelEvent.js +63 -0
- package/lib/Transaction.js +251 -0
- package/lib/ViewportMetrics.js +37 -0
- package/lib/accumulate.js +54 -0
- package/lib/adler32.js +39 -0
- package/lib/containsNode.js +49 -0
- package/lib/copyProperties.js +54 -0
- package/lib/createArrayFrom.js +94 -0
- package/lib/createNodesFromMarkup.js +93 -0
- package/lib/createObjectFrom.js +61 -0
- package/lib/cx.js +44 -0
- package/lib/dangerousStyleValue.js +57 -0
- package/lib/emptyFunction.js +43 -0
- package/lib/escapeTextForBrowser.js +47 -0
- package/lib/ex.js +49 -0
- package/lib/filterAttributes.js +45 -0
- package/lib/flattenChildren.js +54 -0
- package/lib/forEachAccumulated.js +36 -0
- package/lib/ge.js +76 -0
- package/lib/getActiveElement.js +33 -0
- package/lib/getEventTarget.js +36 -0
- package/lib/getMarkupWrap.js +108 -0
- package/lib/getNodeForCharacterOffset.js +80 -0
- package/lib/getReactRootElementInContainer.js +40 -0
- package/lib/getTextContentAccessor.js +40 -0
- package/lib/getUnboundedScrollPosition.js +45 -0
- package/lib/hyphenate.js +35 -0
- package/lib/invariant.js +54 -0
- package/lib/isEventSupported.js +74 -0
- package/lib/isNode.js +33 -0
- package/lib/isTextInputElement.js +49 -0
- package/lib/isTextNode.js +30 -0
- package/lib/joinClasses.js +44 -0
- package/lib/keyMirror.js +58 -0
- package/lib/keyOf.js +41 -0
- package/lib/memoizeStringOnly.js +39 -0
- package/lib/merge.js +37 -0
- package/lib/mergeHelpers.js +137 -0
- package/lib/mergeInto.js +45 -0
- package/lib/mixInto.js +34 -0
- package/lib/mutateHTMLNodeWithMarkup.js +100 -0
- package/lib/objMap.js +47 -0
- package/lib/objMapKeyVal.js +47 -0
- package/lib/performanceNow.js +42 -0
- package/lib/shallowEqual.js +49 -0
- package/lib/traverseAllChildren.js +127 -0
- package/package.json +33 -31
- package/react.js +4 -0
- package/.npmignore +0 -7
- package/.travis.yml +0 -7
- package/Jakefile.js +0 -39
- package/LICENSE +0 -19
- package/browser-test/dist.html +0 -90
- package/browser-test/index.html +0 -86
- package/browser-test/min.html +0 -90
- package/dist/react.js +0 -3141
- package/dist/react.min.js +0 -22
- package/doc/advanced.md +0 -175
- package/doc/color-def.graffle +0 -938
- package/doc/color-def.png +0 -0
- package/doc/simple.dot +0 -25
- package/doc/simple.png +0 -0
- package/examples/longer-example.js +0 -41
- package/examples/simple.js +0 -45
- package/examples/using-ast-directly.js +0 -30
- package/examples/using-events1.js +0 -79
- package/examples/using-log-events.js +0 -43
- package/lib/base-task.js +0 -120
- package/lib/cb-task.js +0 -84
- package/lib/core.js +0 -138
- package/lib/dsl.js +0 -138
- package/lib/error.js +0 -55
- package/lib/event-collector.js +0 -81
- package/lib/event-manager.js +0 -89
- package/lib/eventemitter.js +0 -20
- package/lib/finalcb-first-task.js +0 -68
- package/lib/finalcb-task.js +0 -65
- package/lib/id.js +0 -22
- package/lib/input-parser.js +0 -56
- package/lib/log-events.js +0 -101
- package/lib/parse.js +0 -41
- package/lib/promise-resolve.js +0 -50
- package/lib/promise-task.js +0 -93
- package/lib/react.js +0 -59
- package/lib/ret-task.js +0 -71
- package/lib/sprintf.js +0 -18
- package/lib/status.js +0 -14
- package/lib/task.js +0 -251
- package/lib/track-tasks.js +0 -74
- package/lib/validate.js +0 -159
- package/lib/vcon.js +0 -113
- package/lib/when-task.js +0 -84
- package/src/dist.build.requirejs +0 -20
- package/test/ast.mocha.js +0 -136
- package/test/cb-task.mocha.js +0 -220
- package/test/core-deferred.mocha.js +0 -143
- package/test/core-when.mocha.js +0 -96
- package/test/core.mocha.js +0 -589
- package/test/dsl.mocha.js +0 -352
- package/test/event-manager.mocha.js +0 -119
- package/test/exec-options.mocha.js +0 -48
- package/test/finalcb-task.mocha.js +0 -58
- package/test/input-parser.mocha.js +0 -86
- package/test/log-events.mocha.js +0 -88
- package/test/mocha.opts +0 -2
- package/test/module-use.mocha.js +0 -164
- package/test/promise-auto-resolve.mocha.js +0 -68
- package/test/ret-task.mocha.js +0 -220
- package/test/task.mocha.js +0 -42
- package/test/validate-cb-task.mocha.js +0 -100
- package/test/validate-ret-task.mocha.js +0 -110
- package/test/validate.mocha.js +0 -324
- package/test/vcon.mocha.js +0 -193
- package/vendor/chai/chai.js +0 -4251
- package/vendor/jquery/jquery-1.7.1.js +0 -9266
- package/vendor/jquery/jquery-1.7.1.min.js +0 -4
- package/vendor/node/util.js +0 -531
- package/vendor/requirejs/require.js +0 -2045
- package/vendor/requirejs/require.min.js +0 -36
|
@@ -0,0 +1,212 @@
|
|
|
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 CompositionEventPlugin
|
|
17
|
+
* @typechecks static-only
|
|
18
|
+
*/
|
|
19
|
+
|
|
20
|
+
"use strict";
|
|
21
|
+
|
|
22
|
+
var EventConstants = require("./EventConstants");
|
|
23
|
+
var EventPropagators = require("./EventPropagators");
|
|
24
|
+
var ExecutionEnvironment = require("./ExecutionEnvironment");
|
|
25
|
+
var ReactInputSelection = require("./ReactInputSelection");
|
|
26
|
+
var SyntheticCompositionEvent = require("./SyntheticCompositionEvent");
|
|
27
|
+
|
|
28
|
+
var getTextContentAccessor = require("./getTextContentAccessor");
|
|
29
|
+
var keyOf = require("./keyOf");
|
|
30
|
+
|
|
31
|
+
var END_KEYCODES = [9, 13, 27, 32]; // Tab, Return, Esc, Space
|
|
32
|
+
var START_KEYCODE = 229;
|
|
33
|
+
|
|
34
|
+
var useCompositionEvent = ExecutionEnvironment.canUseDOM &&
|
|
35
|
+
'CompositionEvent' in window;
|
|
36
|
+
var topLevelTypes = EventConstants.topLevelTypes;
|
|
37
|
+
var currentComposition = null;
|
|
38
|
+
|
|
39
|
+
// Events and their corresponding property names.
|
|
40
|
+
var eventTypes = {
|
|
41
|
+
compositionEnd: {
|
|
42
|
+
phasedRegistrationNames: {
|
|
43
|
+
bubbled: keyOf({onCompositionEnd: null}),
|
|
44
|
+
captured: keyOf({onCompositionEndCapture: null})
|
|
45
|
+
}
|
|
46
|
+
},
|
|
47
|
+
compositionStart: {
|
|
48
|
+
phasedRegistrationNames: {
|
|
49
|
+
bubbled: keyOf({onCompositionStart: null}),
|
|
50
|
+
captured: keyOf({onCompositionStartCapture: null})
|
|
51
|
+
}
|
|
52
|
+
},
|
|
53
|
+
compositionUpdate: {
|
|
54
|
+
phasedRegistrationNames: {
|
|
55
|
+
bubbled: keyOf({onCompositionUpdate: null}),
|
|
56
|
+
captured: keyOf({onCompositionUpdateCapture: null})
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
};
|
|
60
|
+
|
|
61
|
+
/**
|
|
62
|
+
* Translate native top level events into event types.
|
|
63
|
+
*
|
|
64
|
+
* @param {string} topLevelType
|
|
65
|
+
* @return {object}
|
|
66
|
+
*/
|
|
67
|
+
function getCompositionEventType(topLevelType) {
|
|
68
|
+
switch (topLevelType) {
|
|
69
|
+
case topLevelTypes.topCompositionStart:
|
|
70
|
+
return eventTypes.compositionStart;
|
|
71
|
+
case topLevelTypes.topCompositionEnd:
|
|
72
|
+
return eventTypes.compositionEnd;
|
|
73
|
+
case topLevelTypes.topCompositionUpdate:
|
|
74
|
+
return eventTypes.compositionUpdate;
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
/**
|
|
79
|
+
* Does our fallback best-guess model think this event signifies that
|
|
80
|
+
* composition has begun?
|
|
81
|
+
*
|
|
82
|
+
* @param {string} topLevelType
|
|
83
|
+
* @param {object} nativeEvent
|
|
84
|
+
* @return {boolean}
|
|
85
|
+
*/
|
|
86
|
+
function isFallbackStart(topLevelType, nativeEvent) {
|
|
87
|
+
return (
|
|
88
|
+
topLevelType === topLevelTypes.topKeyDown &&
|
|
89
|
+
nativeEvent.keyCode === START_KEYCODE
|
|
90
|
+
);
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
/**
|
|
94
|
+
* Does our fallback mode think that this event is the end of composition?
|
|
95
|
+
*
|
|
96
|
+
* @param {string} topLevelType
|
|
97
|
+
* @param {object} nativeEvent
|
|
98
|
+
* @return {boolean}
|
|
99
|
+
*/
|
|
100
|
+
function isFallbackEnd(topLevelType, nativeEvent) {
|
|
101
|
+
switch (topLevelType) {
|
|
102
|
+
case topLevelTypes.topKeyUp:
|
|
103
|
+
// Command keys insert or clear IME input.
|
|
104
|
+
return (END_KEYCODES.indexOf(nativeEvent.keyCode) !== -1);
|
|
105
|
+
case topLevelTypes.topKeyDown:
|
|
106
|
+
// Expect IME keyCode on each keydown. If we get any other
|
|
107
|
+
// code we must have exited earlier.
|
|
108
|
+
return (nativeEvent.keyCode !== START_KEYCODE);
|
|
109
|
+
case topLevelTypes.topKeyPress:
|
|
110
|
+
case topLevelTypes.topMouseDown:
|
|
111
|
+
case topLevelTypes.topBlur:
|
|
112
|
+
// Events are not possible without cancelling IME.
|
|
113
|
+
return true;
|
|
114
|
+
default:
|
|
115
|
+
return false;
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
/**
|
|
120
|
+
* Helper class stores information about selection and document state
|
|
121
|
+
* so we can figure out what changed at a later date.
|
|
122
|
+
*
|
|
123
|
+
* @param {DOMEventTarget} root
|
|
124
|
+
*/
|
|
125
|
+
function FallbackCompositionState(root) {
|
|
126
|
+
this.root = root;
|
|
127
|
+
this.startSelection = ReactInputSelection.getSelection(root);
|
|
128
|
+
this.startValue = this.getText();
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
/**
|
|
132
|
+
* Get current text of input.
|
|
133
|
+
*
|
|
134
|
+
* @return {string}
|
|
135
|
+
*/
|
|
136
|
+
FallbackCompositionState.prototype.getText = function() {
|
|
137
|
+
return this.root.value || this.root[getTextContentAccessor()];
|
|
138
|
+
};
|
|
139
|
+
|
|
140
|
+
/**
|
|
141
|
+
* Text that has changed since the start of composition.
|
|
142
|
+
*
|
|
143
|
+
* @return {string}
|
|
144
|
+
*/
|
|
145
|
+
FallbackCompositionState.prototype.getData = function() {
|
|
146
|
+
var endValue = this.getText();
|
|
147
|
+
var prefixLength = this.startSelection.start;
|
|
148
|
+
var suffixLength = this.startValue.length - this.startSelection.end;
|
|
149
|
+
|
|
150
|
+
return endValue.substr(
|
|
151
|
+
prefixLength,
|
|
152
|
+
endValue.length - suffixLength - prefixLength
|
|
153
|
+
);
|
|
154
|
+
};
|
|
155
|
+
|
|
156
|
+
/**
|
|
157
|
+
* This plugin creates `onCompositionStart`, `onCompositionUpdate` and
|
|
158
|
+
* `onCompositionEnd` events on inputs, textareas and contentEditable
|
|
159
|
+
* nodes.
|
|
160
|
+
*/
|
|
161
|
+
var CompositionEventPlugin = {
|
|
162
|
+
|
|
163
|
+
eventTypes: eventTypes,
|
|
164
|
+
|
|
165
|
+
/**
|
|
166
|
+
* @param {string} topLevelType Record from `EventConstants`.
|
|
167
|
+
* @param {DOMEventTarget} topLevelTarget The listening component root node.
|
|
168
|
+
* @param {string} topLevelTargetID ID of `topLevelTarget`.
|
|
169
|
+
* @param {object} nativeEvent Native browser event.
|
|
170
|
+
* @return {*} An accumulation of synthetic events.
|
|
171
|
+
* @see {EventPluginHub.extractEvents}
|
|
172
|
+
*/
|
|
173
|
+
extractEvents: function(
|
|
174
|
+
topLevelType,
|
|
175
|
+
topLevelTarget,
|
|
176
|
+
topLevelTargetID,
|
|
177
|
+
nativeEvent) {
|
|
178
|
+
|
|
179
|
+
var eventType;
|
|
180
|
+
var data;
|
|
181
|
+
|
|
182
|
+
if (useCompositionEvent) {
|
|
183
|
+
eventType = getCompositionEventType(topLevelType);
|
|
184
|
+
} else if (!currentComposition) {
|
|
185
|
+
if (isFallbackStart(topLevelType, nativeEvent)) {
|
|
186
|
+
eventType = eventTypes.start;
|
|
187
|
+
currentComposition = new FallbackCompositionState(topLevelTarget);
|
|
188
|
+
}
|
|
189
|
+
} else if (isFallbackEnd(topLevelType, nativeEvent)) {
|
|
190
|
+
eventType = eventTypes.compositionEnd;
|
|
191
|
+
data = currentComposition.getData();
|
|
192
|
+
currentComposition = null;
|
|
193
|
+
}
|
|
194
|
+
|
|
195
|
+
if (eventType) {
|
|
196
|
+
var event = SyntheticCompositionEvent.getPooled(
|
|
197
|
+
eventType,
|
|
198
|
+
topLevelTargetID,
|
|
199
|
+
nativeEvent
|
|
200
|
+
);
|
|
201
|
+
if (data) {
|
|
202
|
+
// Inject data generated from fallback path into the synthetic event.
|
|
203
|
+
// This matches the property of native CompositionEventInterface.
|
|
204
|
+
event.data = data;
|
|
205
|
+
}
|
|
206
|
+
EventPropagators.accumulateTwoPhaseDispatches(event);
|
|
207
|
+
return event;
|
|
208
|
+
}
|
|
209
|
+
}
|
|
210
|
+
};
|
|
211
|
+
|
|
212
|
+
module.exports = CompositionEventPlugin;
|
|
@@ -0,0 +1,135 @@
|
|
|
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 DOMChildrenOperations
|
|
17
|
+
* @typechecks static-only
|
|
18
|
+
*/
|
|
19
|
+
|
|
20
|
+
"use strict";
|
|
21
|
+
|
|
22
|
+
var Danger = require("./Danger");
|
|
23
|
+
var ReactMultiChildUpdateTypes = require("./ReactMultiChildUpdateTypes");
|
|
24
|
+
|
|
25
|
+
var getTextContentAccessor = require("./getTextContentAccessor");
|
|
26
|
+
|
|
27
|
+
/**
|
|
28
|
+
* The DOM property to use when setting text content.
|
|
29
|
+
*
|
|
30
|
+
* @type {string}
|
|
31
|
+
* @private
|
|
32
|
+
*/
|
|
33
|
+
var textContentAccessor = getTextContentAccessor() || 'NA';
|
|
34
|
+
|
|
35
|
+
/**
|
|
36
|
+
* Inserts `childNode` as a child of `parentNode` at the `index`.
|
|
37
|
+
*
|
|
38
|
+
* @param {DOMElement} parentNode Parent node in which to insert.
|
|
39
|
+
* @param {DOMElement} childNode Child node to insert.
|
|
40
|
+
* @param {number} index Index at which to insert the child.
|
|
41
|
+
* @internal
|
|
42
|
+
*/
|
|
43
|
+
function insertChildAt(parentNode, childNode, index) {
|
|
44
|
+
var childNodes = parentNode.childNodes;
|
|
45
|
+
if (childNodes[index] === childNode) {
|
|
46
|
+
return;
|
|
47
|
+
}
|
|
48
|
+
// If `childNode` is already a child of `parentNode`, remove it so that
|
|
49
|
+
// computing `childNodes[index]` takes into account the removal.
|
|
50
|
+
if (childNode.parentNode === parentNode) {
|
|
51
|
+
parentNode.removeChild(childNode);
|
|
52
|
+
}
|
|
53
|
+
if (index >= childNodes.length) {
|
|
54
|
+
parentNode.appendChild(childNode);
|
|
55
|
+
} else {
|
|
56
|
+
parentNode.insertBefore(childNode, childNodes[index]);
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
/**
|
|
61
|
+
* Operations for updating with DOM children.
|
|
62
|
+
*/
|
|
63
|
+
var DOMChildrenOperations = {
|
|
64
|
+
|
|
65
|
+
dangerouslyReplaceNodeWithMarkup: Danger.dangerouslyReplaceNodeWithMarkup,
|
|
66
|
+
|
|
67
|
+
/**
|
|
68
|
+
* Updates a component's children by processing a series of updates. The
|
|
69
|
+
* update configurations are each expected to have a `parentNode` property.
|
|
70
|
+
*
|
|
71
|
+
* @param {array<object>} updates List of update configurations.
|
|
72
|
+
* @param {array<string>} markupList List of markup strings.
|
|
73
|
+
* @internal
|
|
74
|
+
*/
|
|
75
|
+
processUpdates: function(updates, markupList) {
|
|
76
|
+
var update;
|
|
77
|
+
// Mapping from parent IDs to initial child orderings.
|
|
78
|
+
var initialChildren = null;
|
|
79
|
+
// List of children that will be moved or removed.
|
|
80
|
+
var updatedChildren = null;
|
|
81
|
+
|
|
82
|
+
for (var i = 0; update = updates[i]; i++) {
|
|
83
|
+
if (update.type === ReactMultiChildUpdateTypes.MOVE_EXISTING ||
|
|
84
|
+
update.type === ReactMultiChildUpdateTypes.REMOVE_NODE) {
|
|
85
|
+
var updatedIndex = update.fromIndex;
|
|
86
|
+
var updatedChild = update.parentNode.childNodes[updatedIndex];
|
|
87
|
+
var parentID = update.parentID;
|
|
88
|
+
|
|
89
|
+
initialChildren = initialChildren || {};
|
|
90
|
+
initialChildren[parentID] = initialChildren[parentID] || [];
|
|
91
|
+
initialChildren[parentID][updatedIndex] = updatedChild;
|
|
92
|
+
|
|
93
|
+
updatedChildren = updatedChildren || [];
|
|
94
|
+
updatedChildren.push(updatedChild);
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
var renderedMarkup = Danger.dangerouslyRenderMarkup(markupList);
|
|
99
|
+
|
|
100
|
+
// Remove updated children first so that `toIndex` is consistent.
|
|
101
|
+
if (updatedChildren) {
|
|
102
|
+
for (var j = 0; j < updatedChildren.length; j++) {
|
|
103
|
+
updatedChildren[j].parentNode.removeChild(updatedChildren[j]);
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
for (var k = 0; update = updates[k]; k++) {
|
|
108
|
+
switch (update.type) {
|
|
109
|
+
case ReactMultiChildUpdateTypes.INSERT_MARKUP:
|
|
110
|
+
insertChildAt(
|
|
111
|
+
update.parentNode,
|
|
112
|
+
renderedMarkup[update.markupIndex],
|
|
113
|
+
update.toIndex
|
|
114
|
+
);
|
|
115
|
+
break;
|
|
116
|
+
case ReactMultiChildUpdateTypes.MOVE_EXISTING:
|
|
117
|
+
insertChildAt(
|
|
118
|
+
update.parentNode,
|
|
119
|
+
initialChildren[update.parentID][update.fromIndex],
|
|
120
|
+
update.toIndex
|
|
121
|
+
);
|
|
122
|
+
break;
|
|
123
|
+
case ReactMultiChildUpdateTypes.TEXT_CONTENT:
|
|
124
|
+
update.parentNode[textContentAccessor] = update.textContent;
|
|
125
|
+
break;
|
|
126
|
+
case ReactMultiChildUpdateTypes.REMOVE_NODE:
|
|
127
|
+
// Already removed by the for-loop above.
|
|
128
|
+
break;
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
};
|
|
134
|
+
|
|
135
|
+
module.exports = DOMChildrenOperations;
|
|
@@ -0,0 +1,266 @@
|
|
|
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
|
+
/**
|
|
158
|
+
* Checks whether a property name is a standard property.
|
|
159
|
+
* @type {Object}
|
|
160
|
+
*/
|
|
161
|
+
isStandardName: {},
|
|
162
|
+
|
|
163
|
+
/**
|
|
164
|
+
* Mapping from lowercase property names to the properly cased version, used
|
|
165
|
+
* to warn in the case of missing properties.
|
|
166
|
+
* @type {Object}
|
|
167
|
+
*/
|
|
168
|
+
getPossibleStandardName: {},
|
|
169
|
+
|
|
170
|
+
/**
|
|
171
|
+
* Mapping from normalized names to attribute names that differ. Attribute
|
|
172
|
+
* names are used when rendering markup or with `*Attribute()`.
|
|
173
|
+
* @type {Object}
|
|
174
|
+
*/
|
|
175
|
+
getAttributeName: {},
|
|
176
|
+
|
|
177
|
+
/**
|
|
178
|
+
* Mapping from normalized names to properties on DOM node instances.
|
|
179
|
+
* (This includes properties that mutate due to external factors.)
|
|
180
|
+
* @type {Object}
|
|
181
|
+
*/
|
|
182
|
+
getPropertyName: {},
|
|
183
|
+
|
|
184
|
+
/**
|
|
185
|
+
* Mapping from normalized names to mutation methods. This will only exist if
|
|
186
|
+
* mutation cannot be set simply by the property or `setAttribute()`.
|
|
187
|
+
* @type {Object}
|
|
188
|
+
*/
|
|
189
|
+
getMutationMethod: {},
|
|
190
|
+
|
|
191
|
+
/**
|
|
192
|
+
* Whether the property must be accessed and mutated as an object property.
|
|
193
|
+
* @type {Object}
|
|
194
|
+
*/
|
|
195
|
+
mustUseAttribute: {},
|
|
196
|
+
|
|
197
|
+
/**
|
|
198
|
+
* Whether the property must be accessed and mutated using `*Attribute()`.
|
|
199
|
+
* (This includes anything that fails `<propName> in <element>`.)
|
|
200
|
+
* @type {Object}
|
|
201
|
+
*/
|
|
202
|
+
mustUseProperty: {},
|
|
203
|
+
|
|
204
|
+
/**
|
|
205
|
+
* Whether or not setting a value causes side effects such as triggering
|
|
206
|
+
* resources to be loaded or text selection changes. We must ensure that
|
|
207
|
+
* the value is only set if it has changed.
|
|
208
|
+
* @type {Object}
|
|
209
|
+
*/
|
|
210
|
+
hasSideEffects: {},
|
|
211
|
+
|
|
212
|
+
/**
|
|
213
|
+
* Whether the property should be removed when set to a falsey value.
|
|
214
|
+
* @type {Object}
|
|
215
|
+
*/
|
|
216
|
+
hasBooleanValue: {},
|
|
217
|
+
|
|
218
|
+
/**
|
|
219
|
+
* Whether the property must be positive numeric or parse as a positive
|
|
220
|
+
* numeric and should be removed when set to a falsey value.
|
|
221
|
+
* @type {Object}
|
|
222
|
+
*/
|
|
223
|
+
hasPositiveNumericValue: {},
|
|
224
|
+
|
|
225
|
+
/**
|
|
226
|
+
* All of the isCustomAttribute() functions that have been injected.
|
|
227
|
+
*/
|
|
228
|
+
_isCustomAttributeFunctions: [],
|
|
229
|
+
|
|
230
|
+
/**
|
|
231
|
+
* Checks whether a property name is a custom attribute.
|
|
232
|
+
* @method
|
|
233
|
+
*/
|
|
234
|
+
isCustomAttribute: function(attributeName) {
|
|
235
|
+
return DOMProperty._isCustomAttributeFunctions.some(
|
|
236
|
+
function(isCustomAttributeFn) {
|
|
237
|
+
return isCustomAttributeFn.call(null, attributeName);
|
|
238
|
+
}
|
|
239
|
+
);
|
|
240
|
+
},
|
|
241
|
+
|
|
242
|
+
/**
|
|
243
|
+
* Returns the default property value for a DOM property (i.e., not an
|
|
244
|
+
* attribute). Most default values are '' or false, but not all. Worse yet,
|
|
245
|
+
* some (in particular, `type`) vary depending on the type of element.
|
|
246
|
+
*
|
|
247
|
+
* TODO: Is it better to grab all the possible properties when creating an
|
|
248
|
+
* element to avoid having to create the same element twice?
|
|
249
|
+
*/
|
|
250
|
+
getDefaultValueForProperty: function(nodeName, prop) {
|
|
251
|
+
var nodeDefaults = defaultValueCache[nodeName];
|
|
252
|
+
var testElement;
|
|
253
|
+
if (!nodeDefaults) {
|
|
254
|
+
defaultValueCache[nodeName] = nodeDefaults = {};
|
|
255
|
+
}
|
|
256
|
+
if (!(prop in nodeDefaults)) {
|
|
257
|
+
testElement = document.createElement(nodeName);
|
|
258
|
+
nodeDefaults[prop] = testElement[prop];
|
|
259
|
+
}
|
|
260
|
+
return nodeDefaults[prop];
|
|
261
|
+
},
|
|
262
|
+
|
|
263
|
+
injection: DOMPropertyInjection
|
|
264
|
+
};
|
|
265
|
+
|
|
266
|
+
module.exports = DOMProperty;
|