Skip to content

Commit 167887f

Browse files
feat(react-property): consolidate injection logic to index.js
BREAKING CHANGE: remove exports `HTMLDOMPropertyConfig` and `SVGDOMPropertyConfig` and consolidate the properties in `properties`. As a result of this change, `src/` directory is removed since all the injection logic is handled in `index.js` and the npm script `copy` is removed as well.
1 parent 8cdfdf6 commit 167887f

File tree

5 files changed

+71
-111
lines changed

5 files changed

+71
-111
lines changed

packages/react-property/index.js

Lines changed: 68 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,78 @@
1-
var HTMLDOMPropertyConfig = require('./lib/html');
2-
var SVGDOMPropertyConfig = require('./lib/svg');
1+
var HTMLDOMPropertyConfig = require('./lib/HTMLDOMPropertyConfig');
2+
var SVGDOMPropertyConfig = require('./lib/SVGDOMPropertyConfig');
3+
var injection = require('./lib/injection');
4+
5+
var MUST_USE_PROPERTY = injection.MUST_USE_PROPERTY;
6+
var HAS_BOOLEAN_VALUE = injection.HAS_BOOLEAN_VALUE;
7+
var HAS_NUMERIC_VALUE = injection.HAS_NUMERIC_VALUE;
8+
var HAS_POSITIVE_NUMERIC_VALUE = injection.HAS_POSITIVE_NUMERIC_VALUE;
9+
var HAS_OVERLOADED_BOOLEAN_VALUE = injection.HAS_OVERLOADED_BOOLEAN_VALUE;
10+
11+
/**
12+
* @see https://github.com/facebook/react/blob/15-stable/src/renderers/dom/shared/DOMProperty.js#L14-L16
13+
*
14+
* @param {Number} value
15+
* @param {Number} bitmask
16+
* @return {Boolean}
17+
*/
18+
function checkMask(value, bitmask) {
19+
return (value & bitmask) === bitmask;
20+
}
21+
22+
/**
23+
* @see https://github.com/facebook/react/blob/15-stable/src/renderers/dom/shared/DOMProperty.js#L57
24+
*
25+
* @param {Object} domPropertyConfig - HTMLDOMPropertyConfig or SVGDOMPropertyConfig
26+
* @param {Object} config - The object to be mutated
27+
* @param {Boolean} isSVG - Whether the injected config is HTML or SVG (it assumes the default is HTML)
28+
*/
29+
function injectDOMPropertyConfig(domPropertyConfig, config, isSVG) {
30+
var Properties = domPropertyConfig.Properties;
31+
var DOMAttributeNames = domPropertyConfig.DOMAttributeNames;
32+
var attributeName;
33+
var propertyName;
34+
var propConfig;
35+
36+
for (propertyName in Properties) {
37+
attributeName =
38+
DOMAttributeNames[propertyName] ||
39+
(isSVG ? propertyName : propertyName.toLowerCase());
40+
propConfig = Properties[propertyName];
41+
42+
config[attributeName] = {
43+
attributeName: attributeName,
44+
propertyName: propertyName,
45+
mustUseProperty: checkMask(propConfig, MUST_USE_PROPERTY),
46+
hasBooleanValue: checkMask(propConfig, HAS_BOOLEAN_VALUE),
47+
hasNumericValue: checkMask(propConfig, HAS_NUMERIC_VALUE),
48+
hasPositiveNumericValue: checkMask(
49+
propConfig,
50+
HAS_POSITIVE_NUMERIC_VALUE
51+
),
52+
hasOverloadedBooleanValue: checkMask(
53+
propConfig,
54+
HAS_OVERLOADED_BOOLEAN_VALUE
55+
)
56+
};
57+
}
58+
}
59+
60+
/**
61+
* Properties map.
62+
*
63+
* @type {Object}
64+
*/
65+
var properties = {};
66+
injectDOMPropertyConfig(HTMLDOMPropertyConfig, properties);
67+
injectDOMPropertyConfig(SVGDOMPropertyConfig, properties, true);
368

469
var ATTRIBUTE_NAME_START_CHAR =
570
':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';
6-
771
var ATTRIBUTE_NAME_CHAR =
872
ATTRIBUTE_NAME_START_CHAR + '\\-.0-9\\u00B7\\u0300-\\u036F\\u203F-\\u2040';
973

1074
module.exports = {
11-
HTMLDOMPropertyConfig: HTMLDOMPropertyConfig,
12-
SVGDOMPropertyConfig: SVGDOMPropertyConfig,
75+
properties: properties,
1376

1477
/**
1578
* Checks whether a property name is a custom attribute.

packages/react-property/package.json

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,10 @@
44
"description": "HTML and SVG DOM property configs used by React.",
55
"main": "index.js",
66
"scripts": {
7-
"build": "npm run clean && npm run build:html && npm run build:injection && npm run build:svg && npm run copy",
7+
"build": "npm run clean && npm run build:html && npm run build:injection && npm run build:svg",
88
"build:html": "node scripts/build-html",
99
"build:injection": "node scripts/build-injection",
1010
"build:svg": "node scripts/build-svg",
11-
"copy": "cp -r src/* lib",
1211
"clean": "rm -rf lib",
1312
"lint": "eslint .",
1413
"lint:fix": "eslint . --fix",

packages/react-property/src/html/index.js

Lines changed: 0 additions & 51 deletions
This file was deleted.

packages/react-property/src/svg/index.js

Lines changed: 0 additions & 51 deletions
This file was deleted.

packages/react-property/test/index.spec.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ describe('HTMLDOMPropertyConfig', () => {
1515
const attributeName =
1616
HTMLDOMPropertyConfig.DOMAttributeNames[propName] ||
1717
propName.toLowerCase();
18-
expect(main.HTMLDOMPropertyConfig[attributeName]).toEqual(property);
18+
expect(main.properties[attributeName]).toEqual(property);
1919
}
2020
);
2121
});
@@ -35,7 +35,7 @@ describe('SVGDOMPropertyConfig', () => {
3535
delete property.mutationMethod;
3636
const attributeName =
3737
SVGDOMPropertyConfig.DOMAttributeNames[propName] || propName;
38-
expect(main.SVGDOMPropertyConfig[attributeName]).toEqual(property);
38+
expect(main.properties[attributeName]).toEqual(property);
3939
}
4040
);
4141
});

0 commit comments

Comments
 (0)