|
| 1 | +var React = require('react'); |
1 | 2 | var attributesToProps = require('./attributes-to-props');
|
2 | 3 | var utilities = require('./utilities');
|
3 | 4 |
|
4 | 5 | /**
|
5 | 6 | * Converts DOM nodes to React elements.
|
6 | 7 | *
|
7 |
| - * @param {DomElement[]} nodes - The DOM nodes. |
8 |
| - * @param {Object} [options={}] - The additional options. |
9 |
| - * @param {Function} [options.replace] - The replacer. |
10 |
| - * @param {Object} [options.library] - The library (React, Preact, etc.). |
11 |
| - * @return {String|ReactElement|ReactElement[]} |
| 8 | + * @param {DomElement[]} nodes - DOM nodes. |
| 9 | + * @param {object} [options={}] - Options. |
| 10 | + * @param {Function} [options.replace] - Replacer. |
| 11 | + * @param {object} [options.library] - Library (React/Preact/etc.). |
| 12 | + * @return {string|ReactElement|ReactElement[]} |
12 | 13 | */
|
13 | 14 | function domToReact(nodes, options) {
|
14 | 15 | options = options || {};
|
15 | 16 |
|
16 |
| - var React = options.library || require('react'); |
17 |
| - var cloneElement = React.cloneElement; |
18 |
| - var createElement = React.createElement; |
19 |
| - var isValidElement = React.isValidElement; |
| 17 | + var library = options.library || React; |
| 18 | + var cloneElement = library.cloneElement; |
| 19 | + var createElement = library.createElement; |
| 20 | + var isValidElement = library.isValidElement; |
20 | 21 |
|
21 | 22 | var result = [];
|
22 | 23 | var node;
|
@@ -61,7 +62,7 @@ function domToReact(nodes, options) {
|
61 | 62 | }
|
62 | 63 |
|
63 | 64 | props = node.attribs;
|
64 |
| - if (!shouldPassAttributesUnaltered(node)) { |
| 65 | + if (!skipAttributesToProps(node)) { |
65 | 66 | props = attributesToProps(node.attribs);
|
66 | 67 | }
|
67 | 68 |
|
@@ -108,12 +109,13 @@ function domToReact(nodes, options) {
|
108 | 109 | }
|
109 | 110 |
|
110 | 111 | /**
|
111 |
| - * Determines whether attributes should be altered or not. |
| 112 | + * Determines whether DOM element attributes should be transformed to props. |
| 113 | + * Web Components (custom elements) should not have their attributes transformed. |
112 | 114 | *
|
113 |
| - * @param {React.ReactElement} node |
114 |
| - * @return {Boolean} |
| 115 | + * @param {DomElement} node |
| 116 | + * @return {boolean} |
115 | 117 | */
|
116 |
| -function shouldPassAttributesUnaltered(node) { |
| 118 | +function skipAttributesToProps(node) { |
117 | 119 | return (
|
118 | 120 | utilities.PRESERVE_CUSTOM_ATTRIBUTES &&
|
119 | 121 | node.type === 'tag' &&
|
|
0 commit comments