1 |
|
2 |
|
3 |
|
4 |
|
5 |
|
6 |
|
7 |
|
8 |
|
9 | 'use strict';
|
10 |
|
11 | var _prodInvariant = require('./reactProdInvariant');
|
12 |
|
13 | var invariant = require('fbjs/lib/invariant');
|
14 |
|
15 | function checkMask(value, bitmask) {
|
16 | return (value & bitmask) === bitmask;
|
17 | }
|
18 |
|
19 | var DOMPropertyInjection = {
|
20 | |
21 |
|
22 |
|
23 |
|
24 | MUST_USE_PROPERTY: 0x1,
|
25 | HAS_BOOLEAN_VALUE: 0x4,
|
26 | HAS_NUMERIC_VALUE: 0x8,
|
27 | HAS_POSITIVE_NUMERIC_VALUE: 0x10 | 0x8,
|
28 | HAS_OVERLOADED_BOOLEAN_VALUE: 0x20,
|
29 |
|
30 | |
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 | injectDOMPropertyConfig: function (domPropertyConfig) {
|
59 | var Injection = DOMPropertyInjection;
|
60 | var Properties = domPropertyConfig.Properties || {};
|
61 | var DOMAttributeNamespaces = domPropertyConfig.DOMAttributeNamespaces || {};
|
62 | var DOMAttributeNames = domPropertyConfig.DOMAttributeNames || {};
|
63 | var DOMPropertyNames = domPropertyConfig.DOMPropertyNames || {};
|
64 | var DOMMutationMethods = domPropertyConfig.DOMMutationMethods || {};
|
65 |
|
66 | if (domPropertyConfig.isCustomAttribute) {
|
67 | DOMProperty._isCustomAttributeFunctions.push(domPropertyConfig.isCustomAttribute);
|
68 | }
|
69 |
|
70 | for (var propName in Properties) {
|
71 | !!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;
|
72 |
|
73 | var lowerCased = propName.toLowerCase();
|
74 | var propConfig = Properties[propName];
|
75 |
|
76 | var propertyInfo = {
|
77 | attributeName: lowerCased,
|
78 | attributeNamespace: null,
|
79 | propertyName: propName,
|
80 | mutationMethod: null,
|
81 |
|
82 | mustUseProperty: checkMask(propConfig, Injection.MUST_USE_PROPERTY),
|
83 | hasBooleanValue: checkMask(propConfig, Injection.HAS_BOOLEAN_VALUE),
|
84 | hasNumericValue: checkMask(propConfig, Injection.HAS_NUMERIC_VALUE),
|
85 | hasPositiveNumericValue: checkMask(propConfig, Injection.HAS_POSITIVE_NUMERIC_VALUE),
|
86 | hasOverloadedBooleanValue: checkMask(propConfig, Injection.HAS_OVERLOADED_BOOLEAN_VALUE)
|
87 | };
|
88 | !(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;
|
89 |
|
90 | if (process.env.NODE_ENV !== 'production') {
|
91 | DOMProperty.getPossibleStandardName[lowerCased] = propName;
|
92 | }
|
93 |
|
94 | if (DOMAttributeNames.hasOwnProperty(propName)) {
|
95 | var attributeName = DOMAttributeNames[propName];
|
96 | propertyInfo.attributeName = attributeName;
|
97 | if (process.env.NODE_ENV !== 'production') {
|
98 | DOMProperty.getPossibleStandardName[attributeName] = propName;
|
99 | }
|
100 | }
|
101 |
|
102 | if (DOMAttributeNamespaces.hasOwnProperty(propName)) {
|
103 | propertyInfo.attributeNamespace = DOMAttributeNamespaces[propName];
|
104 | }
|
105 |
|
106 | if (DOMPropertyNames.hasOwnProperty(propName)) {
|
107 | propertyInfo.propertyName = DOMPropertyNames[propName];
|
108 | }
|
109 |
|
110 | if (DOMMutationMethods.hasOwnProperty(propName)) {
|
111 | propertyInfo.mutationMethod = DOMMutationMethods[propName];
|
112 | }
|
113 |
|
114 | DOMProperty.properties[propName] = propertyInfo;
|
115 | }
|
116 | }
|
117 | };
|
118 |
|
119 |
|
120 | 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';
|
121 |
|
122 |
|
123 |
|
124 |
|
125 |
|
126 |
|
127 |
|
128 |
|
129 |
|
130 |
|
131 |
|
132 |
|
133 |
|
134 |
|
135 |
|
136 | var DOMProperty = {
|
137 | ID_ATTRIBUTE_NAME: 'data-reactid',
|
138 | ROOT_ATTRIBUTE_NAME: 'data-reactroot',
|
139 |
|
140 | ATTRIBUTE_NAME_START_CHAR: ATTRIBUTE_NAME_START_CHAR,
|
141 | ATTRIBUTE_NAME_CHAR: ATTRIBUTE_NAME_START_CHAR + '\\-.0-9\\u00B7\\u0300-\\u036F\\u203F-\\u2040',
|
142 |
|
143 | |
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 | properties: {},
|
172 |
|
173 | |
174 |
|
175 |
|
176 |
|
177 |
|
178 |
|
179 |
|
180 |
|
181 |
|
182 | getPossibleStandardName: process.env.NODE_ENV !== 'production' ? { autofocus: 'autoFocus' } : null,
|
183 |
|
184 | |
185 |
|
186 |
|
187 | _isCustomAttributeFunctions: [],
|
188 |
|
189 | |
190 |
|
191 |
|
192 |
|
193 | isCustomAttribute: function (attributeName) {
|
194 | for (var i = 0; i < DOMProperty._isCustomAttributeFunctions.length; i++) {
|
195 | var isCustomAttributeFn = DOMProperty._isCustomAttributeFunctions[i];
|
196 | if (isCustomAttributeFn(attributeName)) {
|
197 | return true;
|
198 | }
|
199 | }
|
200 | return false;
|
201 | },
|
202 |
|
203 | injection: DOMPropertyInjection
|
204 | };
|
205 |
|
206 | module.exports = DOMProperty; |
\ | No newline at end of file |