interpolate-components
Advanced tools
Comparing version
# Changelog | ||
## 1.1.1 | ||
* Remove `react-addons-create-fragment` dependency, use `cloneElement` to specify a key manually instead. | ||
* Drop deprecated React.createClass, React.DOM from test | ||
* Bump to allow for React ^16.0.0 | ||
* Drop deprecated React.createClass, React.DOM from test | ||
@@ -8,0 +7,0 @@ ## 1.1.0 |
@@ -21,2 +21,6 @@ 'use strict'; | ||
var _reactAddonsCreateFragment = require('react-addons-create-fragment'); | ||
var _reactAddonsCreateFragment2 = _interopRequireDefault(_reactAddonsCreateFragment); | ||
var _tokenize = require('./tokenize'); | ||
@@ -56,2 +60,4 @@ | ||
var children = [], | ||
childrenObject = {}, | ||
openComponent, | ||
clonedOpenComponent, | ||
@@ -86,20 +92,25 @@ openIndex, | ||
if (token.type === 'componentOpen') { | ||
openComponent = components[token.value]; | ||
openIndex = i; | ||
closeIndex = getCloseIndex(openIndex, tokens); | ||
grandChildTokens = tokens.slice(openIndex + 1, closeIndex); | ||
grandChildren = buildChildren(grandChildTokens, components); | ||
clonedOpenComponent = _react2.default.cloneElement(components[token.value], { key: openIndex }, grandChildren); | ||
children.push(clonedOpenComponent); | ||
i = closeIndex; | ||
continue; | ||
break; | ||
} | ||
// componentSelfClosing token | ||
if (components[token.value]) { | ||
children.push(_react2.default.cloneElement(components[token.value], { key: i })); | ||
} | ||
children.push(components[token.value]); | ||
continue; | ||
} | ||
if (openComponent) { | ||
closeIndex = getCloseIndex(openIndex, tokens); | ||
grandChildTokens = tokens.slice(openIndex + 1, closeIndex); | ||
grandChildren = buildChildren(grandChildTokens, components); | ||
clonedOpenComponent = _react2.default.cloneElement(openComponent, {}, grandChildren); | ||
children.push(clonedOpenComponent); | ||
if (closeIndex < tokens.length - 1) { | ||
siblingTokens = tokens.slice(closeIndex + 1); | ||
siblings = buildChildren(siblingTokens, components); | ||
children = children.concat(siblings); | ||
} | ||
} | ||
if (children.length === 1) { | ||
@@ -109,3 +120,9 @@ return children[0]; | ||
return children; | ||
children.forEach(function (child, index) { | ||
if (child) { | ||
childrenObject['interpolation-child-' + index] = child; | ||
} | ||
}); | ||
return (0, _reactAddonsCreateFragment2.default)(childrenObject); | ||
} | ||
@@ -112,0 +129,0 @@ |
{ | ||
"name": "interpolate-components", | ||
"version": "1.1.1-alpha.3", | ||
"version": "1.1.1", | ||
"description": "Convert strings into structured React components.", | ||
@@ -37,2 +37,3 @@ "repository": { | ||
"react": "^0.14.3 || ^15.1.0 || ^16.0.0", | ||
"react-addons-create-fragment": "^0.14.3 || ^15.1.0", | ||
"react-dom": "^0.14.3 || ^15.1.0 || ^16.0.0" | ||
@@ -39,0 +40,0 @@ }, |
Sorry, the diff of this file is not supported yet
AI-detected possible typosquat
Supply chain riskAI has identified this package as a potential typosquat of a more popular package. This suggests that the package may be intentionally mimicking another package's name, description, or other metadata.
Found 1 instance in 1 package
No v1
QualityPackage is not semver >=1. This means it is not stable and does not support ^ ranges.
Found 1 instance in 1 package
42329
2.99%409
3.54%0
-100%3
50%1
Infinity%+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added