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.
- package/README.md +10 -222
- package/addons.js +1 -0
- package/lib/AutoFocusMixin.js +30 -0
- package/lib/CSSCore.js +115 -0
- package/lib/CSSProperty.js +121 -0
- package/lib/CSSPropertyOperations.js +97 -0
- package/lib/ChangeEventPlugin.js +387 -0
- package/lib/ClientReactRootIndex.js +30 -0
- package/lib/CompositionEventPlugin.js +260 -0
- package/lib/DOMChildrenOperations.js +165 -0
- package/lib/DOMProperty.js +268 -0
- package/lib/DOMPropertyOperations.js +181 -0
- package/lib/Danger.js +187 -0
- package/lib/DefaultDOMPropertyConfig.js +197 -0
- package/lib/DefaultEventPluginOrder.js +44 -0
- package/lib/EnterLeaveEventPlugin.js +145 -0
- package/lib/EventConstants.js +76 -0
- package/lib/EventListener.js +69 -0
- package/lib/EventPluginHub.js +291 -0
- package/lib/EventPluginRegistry.js +260 -0
- package/lib/EventPluginUtils.js +214 -0
- package/lib/EventPropagators.js +143 -0
- package/lib/ExecutionEnvironment.js +44 -0
- package/lib/LinkedStateMixin.js +46 -0
- package/lib/LinkedValueUtils.js +161 -0
- package/lib/MobileSafariClickEventPlugin.js +63 -0
- package/lib/PooledClass.js +119 -0
- package/lib/React.js +95 -0
- package/lib/ReactCSSTransitionGroup.js +65 -0
- package/lib/ReactCSSTransitionGroupChild.js +138 -0
- package/lib/ReactChildren.js +132 -0
- package/lib/ReactComponent.js +550 -0
- package/lib/ReactComponentBrowserEnvironment.js +158 -0
- package/lib/ReactComponentEnvironment.js +26 -0
- package/lib/ReactCompositeComponent.js +1455 -0
- package/lib/ReactContext.js +67 -0
- package/lib/ReactCurrentOwner.js +39 -0
- package/lib/ReactDOM.js +207 -0
- package/lib/ReactDOMButton.js +68 -0
- package/lib/ReactDOMComponent.js +399 -0
- package/lib/ReactDOMForm.js +59 -0
- package/lib/ReactDOMIDOperations.js +218 -0
- package/lib/ReactDOMImg.js +58 -0
- package/lib/ReactDOMInput.js +181 -0
- package/lib/ReactDOMOption.js +51 -0
- package/lib/ReactDOMSelect.js +179 -0
- package/lib/ReactDOMSelection.js +189 -0
- package/lib/ReactDOMTextarea.js +140 -0
- package/lib/ReactDefaultBatchingStrategy.js +75 -0
- package/lib/ReactDefaultInjection.js +115 -0
- package/lib/ReactDefaultPerf.js +244 -0
- package/lib/ReactDefaultPerfAnalysis.js +199 -0
- package/lib/ReactErrorUtils.js +37 -0
- package/lib/ReactEventEmitter.js +337 -0
- package/lib/ReactEventEmitterMixin.js +57 -0
- package/lib/ReactEventTopLevelCallback.js +109 -0
- package/lib/ReactInjection.js +39 -0
- package/lib/ReactInputSelection.js +140 -0
- package/lib/ReactInstanceHandles.js +338 -0
- package/lib/ReactLink.js +54 -0
- package/lib/ReactMarkupChecksum.js +53 -0
- package/lib/ReactMount.js +641 -0
- package/lib/ReactMountReady.js +95 -0
- package/lib/ReactMultiChild.js +425 -0
- package/lib/ReactMultiChildUpdateTypes.js +38 -0
- package/lib/ReactOwner.js +154 -0
- package/lib/ReactPerf.js +85 -0
- package/lib/ReactPropTransferer.js +147 -0
- package/lib/ReactPropTypeLocationNames.js +31 -0
- package/lib/ReactPropTypeLocations.js +29 -0
- package/lib/ReactPropTypes.js +359 -0
- package/lib/ReactPutListenerQueue.js +61 -0
- package/lib/ReactReconcileTransaction.js +181 -0
- package/lib/ReactRootIndex.js +36 -0
- package/lib/ReactServerRendering.js +59 -0
- package/lib/ReactStateSetters.js +111 -0
- package/lib/ReactTextComponent.js +99 -0
- package/lib/ReactTransitionChildMapping.js +106 -0
- package/lib/ReactTransitionEvents.js +97 -0
- package/lib/ReactTransitionGroup.js +187 -0
- package/lib/ReactUpdates.js +148 -0
- package/lib/ReactWithAddons.js +46 -0
- package/lib/SelectEventPlugin.js +200 -0
- package/lib/ServerReactRootIndex.js +36 -0
- package/lib/SimpleEventPlugin.js +413 -0
- package/lib/SyntheticClipboardEvent.js +51 -0
- package/lib/SyntheticCompositionEvent.js +51 -0
- package/lib/SyntheticDragEvent.js +44 -0
- package/lib/SyntheticEvent.js +164 -0
- package/lib/SyntheticFocusEvent.js +44 -0
- package/lib/SyntheticKeyboardEvent.js +58 -0
- package/lib/SyntheticMouseEvent.js +85 -0
- package/lib/SyntheticTouchEvent.js +50 -0
- package/lib/SyntheticUIEvent.js +45 -0
- package/lib/SyntheticWheelEvent.js +66 -0
- package/lib/Transaction.js +276 -0
- package/lib/ViewportMetrics.js +37 -0
- package/lib/accumulate.js +54 -0
- package/lib/adler32.js +39 -0
- package/lib/cloneWithProps.js +59 -0
- package/lib/containsNode.js +49 -0
- package/lib/copyProperties.js +54 -0
- package/lib/createArrayFrom.js +91 -0
- package/lib/createFullPageComponent.js +63 -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/flattenChildren.js +57 -0
- package/lib/forEachAccumulated.js +36 -0
- package/lib/getActiveElement.js +34 -0
- package/lib/getEventKey.js +85 -0
- package/lib/getEventTarget.js +36 -0
- package/lib/getMarkupWrap.js +118 -0
- package/lib/getNodeForCharacterOffset.js +80 -0
- package/lib/getReactRootElementInContainer.js +40 -0
- package/lib/getTextContentAccessor.js +42 -0
- package/lib/getUnboundedScrollPosition.js +45 -0
- package/lib/hyphenate.js +35 -0
- package/lib/invariant.js +62 -0
- package/lib/isEventSupported.js +70 -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 +136 -0
- package/lib/mergeInto.js +45 -0
- package/lib/mixInto.js +34 -0
- package/lib/objMap.js +47 -0
- package/lib/objMapKeyVal.js +47 -0
- package/lib/onlyChild.js +43 -0
- package/lib/performanceNow.js +42 -0
- package/lib/shallowEqual.js +49 -0
- package/lib/shouldUpdateReactComponent.js +58 -0
- package/lib/toArray.js +75 -0
- package/lib/traverseAllChildren.js +189 -0
- package/lib/warning.js +40 -0
- package/package.json +32 -21
- package/react.js +1 -0
- package/.npmignore +0 -7
- package/.travis.yml +0 -5
- 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 -3107
- package/dist/react.min.js +0 -22
- package/doc/advanced.md +0 -174
- 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 -123
- 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 -90
- package/lib/when-task.js +0 -85
- 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 -350
- 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 -147
- 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 -2038
- package/vendor/jquery/jquery-1.7.1.js +0 -9266
- package/vendor/jquery/jquery-1.7.1.min.js +0 -4
- package/vendor/mocha/mocha.css +0 -135
- package/vendor/mocha/mocha.js +0 -3589
- package/vendor/node/util.js +0 -531
- package/vendor/requirejs/require.js +0 -2053
- package/vendor/requirejs/require.min.js +0 -33
|
@@ -0,0 +1,59 @@
|
|
|
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 ReactDOMForm
|
|
17
|
+
*/
|
|
18
|
+
|
|
19
|
+
"use strict";
|
|
20
|
+
|
|
21
|
+
var ReactCompositeComponent = require("./ReactCompositeComponent");
|
|
22
|
+
var ReactDOM = require("./ReactDOM");
|
|
23
|
+
var ReactEventEmitter = require("./ReactEventEmitter");
|
|
24
|
+
var EventConstants = require("./EventConstants");
|
|
25
|
+
|
|
26
|
+
// Store a reference to the <form> `ReactDOMComponent`.
|
|
27
|
+
var form = ReactDOM.form;
|
|
28
|
+
|
|
29
|
+
/**
|
|
30
|
+
* Since onSubmit doesn't bubble OR capture on the top level in IE8, we need
|
|
31
|
+
* to capture it on the <form> element itself. There are lots of hacks we could
|
|
32
|
+
* do to accomplish this, but the most reliable is to make <form> a
|
|
33
|
+
* composite component and use `componentDidMount` to attach the event handlers.
|
|
34
|
+
*/
|
|
35
|
+
var ReactDOMForm = ReactCompositeComponent.createClass({
|
|
36
|
+
displayName: 'ReactDOMForm',
|
|
37
|
+
|
|
38
|
+
render: function() {
|
|
39
|
+
// TODO: Instead of using `ReactDOM` directly, we should use JSX. However,
|
|
40
|
+
// `jshint` fails to parse JSX so in order for linting to work in the open
|
|
41
|
+
// source repo, we need to just use `ReactDOM.form`.
|
|
42
|
+
return this.transferPropsTo(form(null, this.props.children));
|
|
43
|
+
},
|
|
44
|
+
|
|
45
|
+
componentDidMount: function() {
|
|
46
|
+
ReactEventEmitter.trapBubbledEvent(
|
|
47
|
+
EventConstants.topLevelTypes.topReset,
|
|
48
|
+
'reset',
|
|
49
|
+
this.getDOMNode()
|
|
50
|
+
);
|
|
51
|
+
ReactEventEmitter.trapBubbledEvent(
|
|
52
|
+
EventConstants.topLevelTypes.topSubmit,
|
|
53
|
+
'submit',
|
|
54
|
+
this.getDOMNode()
|
|
55
|
+
);
|
|
56
|
+
}
|
|
57
|
+
});
|
|
58
|
+
|
|
59
|
+
module.exports = ReactDOMForm;
|
|
@@ -0,0 +1,218 @@
|
|
|
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 ReactDOMIDOperations
|
|
17
|
+
* @typechecks static-only
|
|
18
|
+
*/
|
|
19
|
+
|
|
20
|
+
/*jslint evil: true */
|
|
21
|
+
|
|
22
|
+
"use strict";
|
|
23
|
+
|
|
24
|
+
var CSSPropertyOperations = require("./CSSPropertyOperations");
|
|
25
|
+
var DOMChildrenOperations = require("./DOMChildrenOperations");
|
|
26
|
+
var DOMPropertyOperations = require("./DOMPropertyOperations");
|
|
27
|
+
var ReactMount = require("./ReactMount");
|
|
28
|
+
var ReactPerf = require("./ReactPerf");
|
|
29
|
+
|
|
30
|
+
var invariant = require("./invariant");
|
|
31
|
+
|
|
32
|
+
/**
|
|
33
|
+
* Errors for properties that should not be updated with `updatePropertyById()`.
|
|
34
|
+
*
|
|
35
|
+
* @type {object}
|
|
36
|
+
* @private
|
|
37
|
+
*/
|
|
38
|
+
var INVALID_PROPERTY_ERRORS = {
|
|
39
|
+
dangerouslySetInnerHTML:
|
|
40
|
+
'`dangerouslySetInnerHTML` must be set using `updateInnerHTMLByID()`.',
|
|
41
|
+
style: '`style` must be set using `updateStylesByID()`.'
|
|
42
|
+
};
|
|
43
|
+
|
|
44
|
+
var useWhitespaceWorkaround;
|
|
45
|
+
|
|
46
|
+
/**
|
|
47
|
+
* Operations used to process updates to DOM nodes. This is made injectable via
|
|
48
|
+
* `ReactComponent.BackendIDOperations`.
|
|
49
|
+
*/
|
|
50
|
+
var ReactDOMIDOperations = {
|
|
51
|
+
|
|
52
|
+
/**
|
|
53
|
+
* Updates a DOM node with new property values. This should only be used to
|
|
54
|
+
* update DOM properties in `DOMProperty`.
|
|
55
|
+
*
|
|
56
|
+
* @param {string} id ID of the node to update.
|
|
57
|
+
* @param {string} name A valid property name, see `DOMProperty`.
|
|
58
|
+
* @param {*} value New value of the property.
|
|
59
|
+
* @internal
|
|
60
|
+
*/
|
|
61
|
+
updatePropertyByID: ReactPerf.measure(
|
|
62
|
+
'ReactDOMIDOperations',
|
|
63
|
+
'updatePropertyByID',
|
|
64
|
+
function(id, name, value) {
|
|
65
|
+
var node = ReactMount.getNode(id);
|
|
66
|
+
("production" !== process.env.NODE_ENV ? invariant(
|
|
67
|
+
!INVALID_PROPERTY_ERRORS.hasOwnProperty(name),
|
|
68
|
+
'updatePropertyByID(...): %s',
|
|
69
|
+
INVALID_PROPERTY_ERRORS[name]
|
|
70
|
+
) : invariant(!INVALID_PROPERTY_ERRORS.hasOwnProperty(name)));
|
|
71
|
+
|
|
72
|
+
// If we're updating to null or undefined, we should remove the property
|
|
73
|
+
// from the DOM node instead of inadvertantly setting to a string. This
|
|
74
|
+
// brings us in line with the same behavior we have on initial render.
|
|
75
|
+
if (value != null) {
|
|
76
|
+
DOMPropertyOperations.setValueForProperty(node, name, value);
|
|
77
|
+
} else {
|
|
78
|
+
DOMPropertyOperations.deleteValueForProperty(node, name);
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
),
|
|
82
|
+
|
|
83
|
+
/**
|
|
84
|
+
* Updates a DOM node to remove a property. This should only be used to remove
|
|
85
|
+
* DOM properties in `DOMProperty`.
|
|
86
|
+
*
|
|
87
|
+
* @param {string} id ID of the node to update.
|
|
88
|
+
* @param {string} name A property name to remove, see `DOMProperty`.
|
|
89
|
+
* @internal
|
|
90
|
+
*/
|
|
91
|
+
deletePropertyByID: ReactPerf.measure(
|
|
92
|
+
'ReactDOMIDOperations',
|
|
93
|
+
'deletePropertyByID',
|
|
94
|
+
function(id, name, value) {
|
|
95
|
+
var node = ReactMount.getNode(id);
|
|
96
|
+
("production" !== process.env.NODE_ENV ? invariant(
|
|
97
|
+
!INVALID_PROPERTY_ERRORS.hasOwnProperty(name),
|
|
98
|
+
'updatePropertyByID(...): %s',
|
|
99
|
+
INVALID_PROPERTY_ERRORS[name]
|
|
100
|
+
) : invariant(!INVALID_PROPERTY_ERRORS.hasOwnProperty(name)));
|
|
101
|
+
DOMPropertyOperations.deleteValueForProperty(node, name, value);
|
|
102
|
+
}
|
|
103
|
+
),
|
|
104
|
+
|
|
105
|
+
/**
|
|
106
|
+
* Updates a DOM node with new style values. If a value is specified as '',
|
|
107
|
+
* the corresponding style property will be unset.
|
|
108
|
+
*
|
|
109
|
+
* @param {string} id ID of the node to update.
|
|
110
|
+
* @param {object} styles Mapping from styles to values.
|
|
111
|
+
* @internal
|
|
112
|
+
*/
|
|
113
|
+
updateStylesByID: ReactPerf.measure(
|
|
114
|
+
'ReactDOMIDOperations',
|
|
115
|
+
'updateStylesByID',
|
|
116
|
+
function(id, styles) {
|
|
117
|
+
var node = ReactMount.getNode(id);
|
|
118
|
+
CSSPropertyOperations.setValueForStyles(node, styles);
|
|
119
|
+
}
|
|
120
|
+
),
|
|
121
|
+
|
|
122
|
+
/**
|
|
123
|
+
* Updates a DOM node's innerHTML.
|
|
124
|
+
*
|
|
125
|
+
* @param {string} id ID of the node to update.
|
|
126
|
+
* @param {string} html An HTML string.
|
|
127
|
+
* @internal
|
|
128
|
+
*/
|
|
129
|
+
updateInnerHTMLByID: ReactPerf.measure(
|
|
130
|
+
'ReactDOMIDOperations',
|
|
131
|
+
'updateInnerHTMLByID',
|
|
132
|
+
function(id, html) {
|
|
133
|
+
var node = ReactMount.getNode(id);
|
|
134
|
+
|
|
135
|
+
// IE8: When updating a just created node with innerHTML only leading
|
|
136
|
+
// whitespace is removed. When updating an existing node with innerHTML
|
|
137
|
+
// whitespace in root TextNodes is also collapsed.
|
|
138
|
+
// @see quirksmode.org/bugreports/archives/2004/11/innerhtml_and_t.html
|
|
139
|
+
|
|
140
|
+
if (useWhitespaceWorkaround === undefined) {
|
|
141
|
+
// Feature detection; only IE8 is known to behave improperly like this.
|
|
142
|
+
var temp = document.createElement('div');
|
|
143
|
+
temp.innerHTML = ' ';
|
|
144
|
+
useWhitespaceWorkaround = temp.innerHTML === '';
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
if (useWhitespaceWorkaround) {
|
|
148
|
+
// Magic theory: IE8 supposedly differentiates between added and updated
|
|
149
|
+
// nodes when processing innerHTML, innerHTML on updated nodes suffers
|
|
150
|
+
// from worse whitespace behavior. Re-adding a node like this triggers
|
|
151
|
+
// the initial and more favorable whitespace behavior.
|
|
152
|
+
node.parentNode.replaceChild(node, node);
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
if (useWhitespaceWorkaround && html.match(/^[ \r\n\t\f]/)) {
|
|
156
|
+
// Recover leading whitespace by temporarily prepending any character.
|
|
157
|
+
// \uFEFF has the potential advantage of being zero-width/invisible.
|
|
158
|
+
node.innerHTML = '\uFEFF' + html;
|
|
159
|
+
node.firstChild.deleteData(0, 1);
|
|
160
|
+
} else {
|
|
161
|
+
node.innerHTML = html;
|
|
162
|
+
}
|
|
163
|
+
}
|
|
164
|
+
),
|
|
165
|
+
|
|
166
|
+
/**
|
|
167
|
+
* Updates a DOM node's text content set by `props.content`.
|
|
168
|
+
*
|
|
169
|
+
* @param {string} id ID of the node to update.
|
|
170
|
+
* @param {string} content Text content.
|
|
171
|
+
* @internal
|
|
172
|
+
*/
|
|
173
|
+
updateTextContentByID: ReactPerf.measure(
|
|
174
|
+
'ReactDOMIDOperations',
|
|
175
|
+
'updateTextContentByID',
|
|
176
|
+
function(id, content) {
|
|
177
|
+
var node = ReactMount.getNode(id);
|
|
178
|
+
DOMChildrenOperations.updateTextContent(node, content);
|
|
179
|
+
}
|
|
180
|
+
),
|
|
181
|
+
|
|
182
|
+
/**
|
|
183
|
+
* Replaces a DOM node that exists in the document with markup.
|
|
184
|
+
*
|
|
185
|
+
* @param {string} id ID of child to be replaced.
|
|
186
|
+
* @param {string} markup Dangerous markup to inject in place of child.
|
|
187
|
+
* @internal
|
|
188
|
+
* @see {Danger.dangerouslyReplaceNodeWithMarkup}
|
|
189
|
+
*/
|
|
190
|
+
dangerouslyReplaceNodeWithMarkupByID: ReactPerf.measure(
|
|
191
|
+
'ReactDOMIDOperations',
|
|
192
|
+
'dangerouslyReplaceNodeWithMarkupByID',
|
|
193
|
+
function(id, markup) {
|
|
194
|
+
var node = ReactMount.getNode(id);
|
|
195
|
+
DOMChildrenOperations.dangerouslyReplaceNodeWithMarkup(node, markup);
|
|
196
|
+
}
|
|
197
|
+
),
|
|
198
|
+
|
|
199
|
+
/**
|
|
200
|
+
* Updates a component's children by processing a series of updates.
|
|
201
|
+
*
|
|
202
|
+
* @param {array<object>} updates List of update configurations.
|
|
203
|
+
* @param {array<string>} markup List of markup strings.
|
|
204
|
+
* @internal
|
|
205
|
+
*/
|
|
206
|
+
dangerouslyProcessChildrenUpdates: ReactPerf.measure(
|
|
207
|
+
'ReactDOMIDOperations',
|
|
208
|
+
'dangerouslyProcessChildrenUpdates',
|
|
209
|
+
function(updates, markup) {
|
|
210
|
+
for (var i = 0; i < updates.length; i++) {
|
|
211
|
+
updates[i].parentNode = ReactMount.getNode(updates[i].parentID);
|
|
212
|
+
}
|
|
213
|
+
DOMChildrenOperations.processUpdates(updates, markup);
|
|
214
|
+
}
|
|
215
|
+
)
|
|
216
|
+
};
|
|
217
|
+
|
|
218
|
+
module.exports = ReactDOMIDOperations;
|
|
@@ -0,0 +1,58 @@
|
|
|
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 ReactDOMImg
|
|
17
|
+
*/
|
|
18
|
+
|
|
19
|
+
"use strict";
|
|
20
|
+
|
|
21
|
+
var ReactCompositeComponent = require("./ReactCompositeComponent");
|
|
22
|
+
var ReactDOM = require("./ReactDOM");
|
|
23
|
+
var ReactEventEmitter = require("./ReactEventEmitter");
|
|
24
|
+
var EventConstants = require("./EventConstants");
|
|
25
|
+
|
|
26
|
+
// Store a reference to the <img> `ReactDOMComponent`.
|
|
27
|
+
var img = ReactDOM.img;
|
|
28
|
+
|
|
29
|
+
/**
|
|
30
|
+
* Since onLoad doesn't bubble OR capture on the top level in IE8, we need to
|
|
31
|
+
* capture it on the <img> element itself. There are lots of hacks we could do
|
|
32
|
+
* to accomplish this, but the most reliable is to make <img> a composite
|
|
33
|
+
* component and use `componentDidMount` to attach the event handlers.
|
|
34
|
+
*/
|
|
35
|
+
var ReactDOMImg = ReactCompositeComponent.createClass({
|
|
36
|
+
displayName: 'ReactDOMImg',
|
|
37
|
+
tagName: 'IMG',
|
|
38
|
+
|
|
39
|
+
render: function() {
|
|
40
|
+
return img(this.props);
|
|
41
|
+
},
|
|
42
|
+
|
|
43
|
+
componentDidMount: function() {
|
|
44
|
+
var node = this.getDOMNode();
|
|
45
|
+
ReactEventEmitter.trapBubbledEvent(
|
|
46
|
+
EventConstants.topLevelTypes.topLoad,
|
|
47
|
+
'load',
|
|
48
|
+
node
|
|
49
|
+
);
|
|
50
|
+
ReactEventEmitter.trapBubbledEvent(
|
|
51
|
+
EventConstants.topLevelTypes.topError,
|
|
52
|
+
'error',
|
|
53
|
+
node
|
|
54
|
+
);
|
|
55
|
+
}
|
|
56
|
+
});
|
|
57
|
+
|
|
58
|
+
module.exports = ReactDOMImg;
|
|
@@ -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 ReactDOMInput
|
|
17
|
+
*/
|
|
18
|
+
|
|
19
|
+
"use strict";
|
|
20
|
+
|
|
21
|
+
var AutoFocusMixin = require("./AutoFocusMixin");
|
|
22
|
+
var DOMPropertyOperations = require("./DOMPropertyOperations");
|
|
23
|
+
var LinkedValueUtils = require("./LinkedValueUtils");
|
|
24
|
+
var ReactCompositeComponent = require("./ReactCompositeComponent");
|
|
25
|
+
var ReactDOM = require("./ReactDOM");
|
|
26
|
+
var ReactMount = require("./ReactMount");
|
|
27
|
+
|
|
28
|
+
var invariant = require("./invariant");
|
|
29
|
+
var merge = require("./merge");
|
|
30
|
+
|
|
31
|
+
// Store a reference to the <input> `ReactDOMComponent`.
|
|
32
|
+
var input = ReactDOM.input;
|
|
33
|
+
|
|
34
|
+
var instancesByReactID = {};
|
|
35
|
+
|
|
36
|
+
/**
|
|
37
|
+
* Implements an <input> native component that allows setting these optional
|
|
38
|
+
* props: `checked`, `value`, `defaultChecked`, and `defaultValue`.
|
|
39
|
+
*
|
|
40
|
+
* If `checked` or `value` are not supplied (or null/undefined), user actions
|
|
41
|
+
* that affect the checked state or value will trigger updates to the element.
|
|
42
|
+
*
|
|
43
|
+
* If they are supplied (and not null/undefined), the rendered element will not
|
|
44
|
+
* trigger updates to the element. Instead, the props must change in order for
|
|
45
|
+
* the rendered element to be updated.
|
|
46
|
+
*
|
|
47
|
+
* The rendered element will be initialized as unchecked (or `defaultChecked`)
|
|
48
|
+
* with an empty value (or `defaultValue`).
|
|
49
|
+
*
|
|
50
|
+
* @see http://www.w3.org/TR/2012/WD-html5-20121025/the-input-element.html
|
|
51
|
+
*/
|
|
52
|
+
var ReactDOMInput = ReactCompositeComponent.createClass({
|
|
53
|
+
displayName: 'ReactDOMInput',
|
|
54
|
+
|
|
55
|
+
mixins: [AutoFocusMixin, LinkedValueUtils.Mixin],
|
|
56
|
+
|
|
57
|
+
getInitialState: function() {
|
|
58
|
+
var defaultValue = this.props.defaultValue;
|
|
59
|
+
return {
|
|
60
|
+
checked: this.props.defaultChecked || false,
|
|
61
|
+
value: defaultValue != null ? defaultValue : null
|
|
62
|
+
};
|
|
63
|
+
},
|
|
64
|
+
|
|
65
|
+
shouldComponentUpdate: function() {
|
|
66
|
+
// Defer any updates to this component during the `onChange` handler.
|
|
67
|
+
return !this._isChanging;
|
|
68
|
+
},
|
|
69
|
+
|
|
70
|
+
render: function() {
|
|
71
|
+
// Clone `this.props` so we don't mutate the input.
|
|
72
|
+
var props = merge(this.props);
|
|
73
|
+
|
|
74
|
+
props.defaultChecked = null;
|
|
75
|
+
props.defaultValue = null;
|
|
76
|
+
|
|
77
|
+
var value = LinkedValueUtils.getValue(this);
|
|
78
|
+
props.value = value != null ? value : this.state.value;
|
|
79
|
+
|
|
80
|
+
var checked = LinkedValueUtils.getChecked(this);
|
|
81
|
+
props.checked = checked != null ? checked : this.state.checked;
|
|
82
|
+
|
|
83
|
+
props.onChange = this._handleChange;
|
|
84
|
+
|
|
85
|
+
return input(props, this.props.children);
|
|
86
|
+
},
|
|
87
|
+
|
|
88
|
+
componentDidMount: function() {
|
|
89
|
+
var id = ReactMount.getID(this.getDOMNode());
|
|
90
|
+
instancesByReactID[id] = this;
|
|
91
|
+
},
|
|
92
|
+
|
|
93
|
+
componentWillUnmount: function() {
|
|
94
|
+
var rootNode = this.getDOMNode();
|
|
95
|
+
var id = ReactMount.getID(rootNode);
|
|
96
|
+
delete instancesByReactID[id];
|
|
97
|
+
},
|
|
98
|
+
|
|
99
|
+
componentDidUpdate: function(prevProps, prevState, prevContext) {
|
|
100
|
+
var rootNode = this.getDOMNode();
|
|
101
|
+
if (this.props.checked != null) {
|
|
102
|
+
DOMPropertyOperations.setValueForProperty(
|
|
103
|
+
rootNode,
|
|
104
|
+
'checked',
|
|
105
|
+
this.props.checked || false
|
|
106
|
+
);
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
var value = LinkedValueUtils.getValue(this);
|
|
110
|
+
if (value != null) {
|
|
111
|
+
// Cast `value` to a string to ensure the value is set correctly. While
|
|
112
|
+
// browsers typically do this as necessary, jsdom doesn't.
|
|
113
|
+
DOMPropertyOperations.setValueForProperty(rootNode, 'value', '' + value);
|
|
114
|
+
}
|
|
115
|
+
},
|
|
116
|
+
|
|
117
|
+
_handleChange: function(event) {
|
|
118
|
+
var returnValue;
|
|
119
|
+
var onChange = LinkedValueUtils.getOnChange(this);
|
|
120
|
+
if (onChange) {
|
|
121
|
+
this._isChanging = true;
|
|
122
|
+
returnValue = onChange.call(this, event);
|
|
123
|
+
this._isChanging = false;
|
|
124
|
+
}
|
|
125
|
+
this.setState({
|
|
126
|
+
checked: event.target.checked,
|
|
127
|
+
value: event.target.value
|
|
128
|
+
});
|
|
129
|
+
|
|
130
|
+
var name = this.props.name;
|
|
131
|
+
if (this.props.type === 'radio' && name != null) {
|
|
132
|
+
var rootNode = this.getDOMNode();
|
|
133
|
+
var queryRoot = rootNode;
|
|
134
|
+
|
|
135
|
+
while (queryRoot.parentNode) {
|
|
136
|
+
queryRoot = queryRoot.parentNode;
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
// If `rootNode.form` was non-null, then we could try `form.elements`,
|
|
140
|
+
// but that sometimes behaves strangely in IE8. We could also try using
|
|
141
|
+
// `form.getElementsByName`, but that will only return direct children
|
|
142
|
+
// and won't include inputs that use the HTML5 `form=` attribute. Since
|
|
143
|
+
// the input might not even be in a form, let's just use the global
|
|
144
|
+
// `querySelectorAll` to ensure we don't miss anything.
|
|
145
|
+
var group = queryRoot.querySelectorAll(
|
|
146
|
+
'input[name=' + JSON.stringify('' + name) + '][type="radio"]');
|
|
147
|
+
|
|
148
|
+
for (var i = 0, groupLen = group.length; i < groupLen; i++) {
|
|
149
|
+
var otherNode = group[i];
|
|
150
|
+
if (otherNode === rootNode ||
|
|
151
|
+
otherNode.form !== rootNode.form) {
|
|
152
|
+
continue;
|
|
153
|
+
}
|
|
154
|
+
var otherID = ReactMount.getID(otherNode);
|
|
155
|
+
("production" !== process.env.NODE_ENV ? invariant(
|
|
156
|
+
otherID,
|
|
157
|
+
'ReactDOMInput: Mixing React and non-React radio inputs with the ' +
|
|
158
|
+
'same `name` is not supported.'
|
|
159
|
+
) : invariant(otherID));
|
|
160
|
+
var otherInstance = instancesByReactID[otherID];
|
|
161
|
+
("production" !== process.env.NODE_ENV ? invariant(
|
|
162
|
+
otherInstance,
|
|
163
|
+
'ReactDOMInput: Unknown radio button ID %s.',
|
|
164
|
+
otherID
|
|
165
|
+
) : invariant(otherInstance));
|
|
166
|
+
// In some cases, this will actually change the `checked` state value.
|
|
167
|
+
// In other cases, there's no change but this forces a reconcile upon
|
|
168
|
+
// which componentDidUpdate will reset the DOM property to whatever it
|
|
169
|
+
// should be.
|
|
170
|
+
otherInstance.setState({
|
|
171
|
+
checked: false
|
|
172
|
+
});
|
|
173
|
+
}
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
return returnValue;
|
|
177
|
+
}
|
|
178
|
+
|
|
179
|
+
});
|
|
180
|
+
|
|
181
|
+
module.exports = ReactDOMInput;
|