1 |
|
2 |
|
3 |
|
4 |
|
5 |
|
6 |
|
7 |
|
8 |
|
9 |
|
10 |
|
11 | 'use strict';
|
12 |
|
13 | var _prodInvariant = require('./reactProdInvariant');
|
14 |
|
15 | var invariant = require('fbjs/lib/invariant');
|
16 |
|
17 | function checkMask(value, bitmask) {
|
18 | return (value & bitmask) === bitmask;
|
19 | }
|
20 |
|
21 | var DOMPropertyInjection = {
|
22 | |
23 |
|
24 |
|
25 |
|
26 | MUST_USE_PROPERTY: 0x1,
|
27 | HAS_BOOLEAN_VALUE: 0x4,
|
28 | HAS_NUMERIC_VALUE: 0x8,
|
29 | HAS_POSITIVE_NUMERIC_VALUE: 0x10 | 0x8,
|
30 | HAS_OVERLOADED_BOOLEAN_VALUE: 0x20,
|
31 |
|
32 | |
33 |
|
34 |
|
35 |
|
36 |
|
37 |
|
38 |
|
39 |
|
40 |
|
41 |
|
42 |
|
43 |
|
44 |
|
45 |
|
46 |
|
47 |
|
48 |
|
49 |
|
50 |
|
51 |
|
52 |
|
53 |
|
54 |
|
55 |
|
56 |
|
57 |
|
58 |
|
59 |
|
60 | injectDOMPropertyConfig: function (domPropertyConfig) {
|
61 | var Injection = DOMPropertyInjection;
|
62 | var Properties = domPropertyConfig.Properties || {};
|
63 | var DOMAttributeNamespaces = domPropertyConfig.DOMAttributeNamespaces || {};
|
64 | var DOMAttributeNames = domPropertyConfig.DOMAttributeNames || {};
|
65 | var DOMPropertyNames = domPropertyConfig.DOMPropertyNames || {};
|
66 | var DOMMutationMethods = domPropertyConfig.DOMMutationMethods || {};
|
67 |
|
68 | if (domPropertyConfig.isCustomAttribute) {
|
69 | DOMProperty._isCustomAttributeFunctions.push(domPropertyConfig.isCustomAttribute);
|
70 | }
|
71 |
|
72 | for (var propName in Properties) {
|
73 | !!DOMProperty.properties.hasOwnProperty(propName) ? process.env.NODE_ENV !== 'production' ? invariant(false, 'injectDOMPropertyConfig(...): You\'re trying to inject DOM property \'%s\' which has already been injected. You may be accidentally injecting the same DOM property config twice, or you may be injecting two configs that have conflicting property names.', propName) : _prodInvariant('48', propName) : void 0;
|
74 |
|
75 | var lowerCased = propName.toLowerCase();
|
76 | var propConfig = Properties[propName];
|
77 |
|
78 | var propertyInfo = {
|
79 | attributeName: lowerCased,
|
80 | attributeNamespace: null,
|
81 | propertyName: propName,
|
82 | mutationMethod: null,
|
83 |
|
84 | mustUseProperty: checkMask(propConfig, Injection.MUST_USE_PROPERTY),
|
85 | hasBooleanValue: checkMask(propConfig, Injection.HAS_BOOLEAN_VALUE),
|
86 | hasNumericValue: checkMask(propConfig, Injection.HAS_NUMERIC_VALUE),
|
87 | hasPositiveNumericValue: checkMask(propConfig, Injection.HAS_POSITIVE_NUMERIC_VALUE),
|
88 | hasOverloadedBooleanValue: checkMask(propConfig, Injection.HAS_OVERLOADED_BOOLEAN_VALUE)
|
89 | };
|
90 | !(propertyInfo.hasBooleanValue + propertyInfo.hasNumericValue + propertyInfo.hasOverloadedBooleanValue <= 1) ? process.env.NODE_ENV !== 'production' ? invariant(false, 'DOMProperty: Value can be one of boolean, overloaded boolean, or numeric value, but not a combination: %s', propName) : _prodInvariant('50', propName) : void 0;
|
91 |
|
92 | if (process.env.NODE_ENV !== 'production') {
|
93 | DOMProperty.getPossibleStandardName[lowerCased] = propName;
|
94 | }
|
95 |
|
96 | if (DOMAttributeNames.hasOwnProperty(propName)) {
|
97 | var attributeName = DOMAttributeNames[propName];
|
98 | propertyInfo.attributeName = attributeName;
|
99 | if (process.env.NODE_ENV !== 'production') {
|
100 | DOMProperty.getPossibleStandardName[attributeName] = propName;
|
101 | }
|
102 | }
|
103 |
|
104 | if (DOMAttributeNamespaces.hasOwnProperty(propName)) {
|
105 | propertyInfo.attributeNamespace = DOMAttributeNamespaces[propName];
|
106 | }
|
107 |
|
108 | if (DOMPropertyNames.hasOwnProperty(propName)) {
|
109 | propertyInfo.propertyName = DOMPropertyNames[propName];
|
110 | }
|
111 |
|
112 | if (DOMMutationMethods.hasOwnProperty(propName)) {
|
113 | propertyInfo.mutationMethod = DOMMutationMethods[propName];
|
114 | }
|
115 |
|
116 | DOMProperty.properties[propName] = propertyInfo;
|
117 | }
|
118 | }
|
119 | };
|
120 |
|
121 |
|
122 | var ATTRIBUTE_NAME_START_CHAR = ':A-Z_a-z\\u00C0-\\u00D6\\u00D8-\\u00F6\\u00F8-\\u02FF\\u0370-\\u037D\\u037F-\\u1FFF\\u200C-\\u200D\\u2070-\\u218F\\u2C00-\\u2FEF\\u3001-\\uD7FF\\uF900-\\uFDCF\\uFDF0-\\uFFFD';
|
123 |
|
124 |
|
125 |
|
126 |
|
127 |
|
128 |
|
129 |
|
130 |
|
131 |
|
132 |
|
133 |
|
134 |
|
135 |
|
136 |
|
137 |
|
138 | var DOMProperty = {
|
139 | ID_ATTRIBUTE_NAME: 'data-reactid',
|
140 | ROOT_ATTRIBUTE_NAME: 'data-reactroot',
|
141 |
|
142 | ATTRIBUTE_NAME_START_CHAR: ATTRIBUTE_NAME_START_CHAR,
|
143 | ATTRIBUTE_NAME_CHAR: ATTRIBUTE_NAME_START_CHAR + '\\-.0-9\\u00B7\\u0300-\\u036F\\u203F-\\u2040',
|
144 |
|
145 | |
146 |
|
147 |
|
148 |
|
149 |
|
150 |
|
151 |
|
152 |
|
153 |
|
154 |
|
155 |
|
156 |
|
157 |
|
158 |
|
159 |
|
160 |
|
161 |
|
162 |
|
163 |
|
164 |
|
165 |
|
166 |
|
167 |
|
168 |
|
169 |
|
170 |
|
171 |
|
172 |
|
173 | properties: {},
|
174 |
|
175 | |
176 |
|
177 |
|
178 |
|
179 |
|
180 |
|
181 |
|
182 |
|
183 |
|
184 | getPossibleStandardName: process.env.NODE_ENV !== 'production' ? { autofocus: 'autoFocus' } : null,
|
185 |
|
186 | |
187 |
|
188 |
|
189 | _isCustomAttributeFunctions: [],
|
190 |
|
191 | |
192 |
|
193 |
|
194 |
|
195 | isCustomAttribute: function (attributeName) {
|
196 | for (var i = 0; i < DOMProperty._isCustomAttributeFunctions.length; i++) {
|
197 | var isCustomAttributeFn = DOMProperty._isCustomAttributeFunctions[i];
|
198 | if (isCustomAttributeFn(attributeName)) {
|
199 | return true;
|
200 | }
|
201 | }
|
202 | return false;
|
203 | },
|
204 |
|
205 | injection: DOMPropertyInjection
|
206 | };
|
207 |
|
208 | module.exports = DOMProperty; |
\ | No newline at end of file |