Skip to content

Commit 182326a

Browse files
feat(react-property): add build script for SVG DOM config
The build script is similar to HTML DOM config except SVG does not have boolean or overloaded boolean attributes/properties.
1 parent 6f8d266 commit 182326a

File tree

2 files changed

+63
-1
lines changed

2 files changed

+63
-1
lines changed
Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
const fs = require('fs');
2+
const path = require('path');
3+
const DOMProperty = require('react-dom/lib/DOMProperty');
4+
const SVGDOMPropertyConfig = require('react-dom/lib/SVGDOMPropertyConfig');
5+
const { LIB_DIR, SVG_DIR } = require('./constants');
6+
7+
/**
8+
* Creates the DOM property map via injection.
9+
*
10+
* @see https://github.com/facebook/react/blob/15-stable/src/renderers/dom/shared/DOMProperty.js#L57
11+
*/
12+
DOMProperty.injection.injectDOMPropertyConfig(SVGDOMPropertyConfig);
13+
14+
// `autofocus` is removed since it's not an applicable attribute for SVG elements
15+
delete DOMProperty.getPossibleStandardName.autofocus;
16+
17+
/**
18+
* Create output directories (if it does not exist).
19+
*/
20+
try {
21+
fs.mkdirSync(LIB_DIR);
22+
} catch (error) {
23+
// throw error;
24+
}
25+
26+
try {
27+
fs.mkdirSync(SVG_DIR);
28+
} catch (error) {
29+
// throw error;
30+
}
31+
32+
/**
33+
* SVG DOM property config.
34+
*/
35+
const attributeToProperty = {};
36+
37+
/**
38+
* List of SVG DOM attributes.
39+
*/
40+
const attributes = [];
41+
42+
Object.keys(DOMProperty.getPossibleStandardName).forEach(attributeName => {
43+
const propertyName = DOMProperty.getPossibleStandardName[attributeName];
44+
45+
if (attributeName !== propertyName) {
46+
attributeToProperty[attributeName] = propertyName;
47+
}
48+
49+
attributes.push(attributeName);
50+
});
51+
52+
fs.writeFileSync(
53+
path.resolve(SVG_DIR, 'attributes.json'),
54+
JSON.stringify(attributes)
55+
);
56+
57+
fs.writeFileSync(
58+
path.resolve(SVG_DIR, 'attribute-to-property.json'),
59+
JSON.stringify(attributeToProperty)
60+
);

packages/react-property/scripts/constants.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,10 @@ const { resolve } = require('path');
22

33
const LIB_DIR = resolve(__dirname, '../lib');
44
const HTML_DIR = resolve(LIB_DIR, 'html');
5+
const SVG_DIR = resolve(LIB_DIR, 'svg');
56

67
module.exports = {
78
LIB_DIR,
8-
HTML_DIR
9+
HTML_DIR,
10+
SVG_DIR
911
};

0 commit comments

Comments
 (0)