@micromag/core 0.3.417 → 0.3.420
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/es/components.js +8 -4
- package/es/index.js +204 -44
- package/lib/components.js +8 -4
- package/lib/index.js +204 -44
- package/package.json +2 -2
package/es/components.js
CHANGED
|
@@ -3827,7 +3827,7 @@ var Placeholder = /*#__PURE__*/React.memo(ScreenPlaceholder);
|
|
|
3827
3827
|
|
|
3828
3828
|
var styles$6 = {"stack":"micromag-core-screens-preview-stack","stackScreen":"micromag-core-screens-preview-stackScreen","stackItem":"micromag-core-screens-preview-stackItem","screen":"micromag-core-screens-preview-screen"};
|
|
3829
3829
|
|
|
3830
|
-
var _excluded = ["screen", "screenState", "width", "height", "screenWidth", "screenHeight", "className", "withSize"];
|
|
3830
|
+
var _excluded = ["screen", "screenState", "width", "height", "screenWidth", "screenHeight", "className", "withSize", "hidden"];
|
|
3831
3831
|
var propTypes$7 = {
|
|
3832
3832
|
screen: PropTypes.component.isRequired,
|
|
3833
3833
|
screenState: PropTypes$1.string,
|
|
@@ -3836,7 +3836,8 @@ var propTypes$7 = {
|
|
|
3836
3836
|
screenWidth: PropTypes$1.number,
|
|
3837
3837
|
screenHeight: PropTypes$1.number,
|
|
3838
3838
|
className: PropTypes$1.string,
|
|
3839
|
-
withSize: PropTypes$1.bool
|
|
3839
|
+
withSize: PropTypes$1.bool,
|
|
3840
|
+
hidden: PropTypes$1.bool
|
|
3840
3841
|
};
|
|
3841
3842
|
var defaultProps$7 = {
|
|
3842
3843
|
screenState: null,
|
|
@@ -3845,7 +3846,8 @@ var defaultProps$7 = {
|
|
|
3845
3846
|
screenWidth: undefined,
|
|
3846
3847
|
screenHeight: undefined,
|
|
3847
3848
|
className: null,
|
|
3848
|
-
withSize: false
|
|
3849
|
+
withSize: false,
|
|
3850
|
+
hidden: false
|
|
3849
3851
|
};
|
|
3850
3852
|
var ScreenPreview = function ScreenPreview(_ref) {
|
|
3851
3853
|
var screen = _ref.screen,
|
|
@@ -3856,6 +3858,7 @@ var ScreenPreview = function ScreenPreview(_ref) {
|
|
|
3856
3858
|
screenHeight = _ref.screenHeight,
|
|
3857
3859
|
className = _ref.className,
|
|
3858
3860
|
withSize = _ref.withSize,
|
|
3861
|
+
hidden = _ref.hidden,
|
|
3859
3862
|
props = _objectWithoutProperties(_ref, _excluded);
|
|
3860
3863
|
var screenElement = /*#__PURE__*/React.createElement(Screen$1, Object.assign({
|
|
3861
3864
|
screen: screen,
|
|
@@ -3865,13 +3868,14 @@ var ScreenPreview = function ScreenPreview(_ref) {
|
|
|
3865
3868
|
height: !withSize ? height : undefined,
|
|
3866
3869
|
className: classNames([styles$6.screen, _defineProperty({}, className, !withSize)])
|
|
3867
3870
|
}, props));
|
|
3871
|
+
var element = !hidden ? screenElement : /*#__PURE__*/React.createElement("div", null);
|
|
3868
3872
|
var screenWithSize = withSize ? /*#__PURE__*/React.createElement(ScreenSizer, {
|
|
3869
3873
|
className: className,
|
|
3870
3874
|
screenWidth: screenWidth,
|
|
3871
3875
|
screenHeight: screenHeight,
|
|
3872
3876
|
width: width,
|
|
3873
3877
|
height: height
|
|
3874
|
-
},
|
|
3878
|
+
}, element) : element;
|
|
3875
3879
|
return screenWithSize;
|
|
3876
3880
|
};
|
|
3877
3881
|
ScreenPreview.propTypes = propTypes$7;
|
package/es/index.js
CHANGED
|
@@ -1156,7 +1156,8 @@ var FieldsManager = /*#__PURE__*/function (_DefinitionsManager) {
|
|
|
1156
1156
|
return FieldsManager;
|
|
1157
1157
|
}(DefinitionsManager);
|
|
1158
1158
|
|
|
1159
|
-
var _excluded$4 = ["medias"]
|
|
1159
|
+
var _excluded$4 = ["medias"],
|
|
1160
|
+
_excluded2$2 = ["medias"];
|
|
1160
1161
|
var MediasParser = /*#__PURE__*/function () {
|
|
1161
1162
|
function MediasParser(_ref) {
|
|
1162
1163
|
var fieldsManager = _ref.fieldsManager,
|
|
@@ -1165,8 +1166,23 @@ var MediasParser = /*#__PURE__*/function () {
|
|
|
1165
1166
|
this.fieldsManager = fieldsManager;
|
|
1166
1167
|
this.screensManager = screensManager;
|
|
1167
1168
|
this.fieldsPatternCache = {};
|
|
1169
|
+
this.parsedThemesCache = {};
|
|
1168
1170
|
}
|
|
1169
1171
|
_createClass(MediasParser, [{
|
|
1172
|
+
key: "getParsedStoryTheme",
|
|
1173
|
+
value: function getParsedStoryTheme(storyId, theme) {
|
|
1174
|
+
if (typeof this.parsedThemesCache[storyId] === 'undefined') {
|
|
1175
|
+
var _this$toPath = this.toPath(theme),
|
|
1176
|
+
themeMedias = _this$toPath.medias,
|
|
1177
|
+
newTheme = _objectWithoutProperties(_this$toPath, _excluded$4);
|
|
1178
|
+
this.parsedThemesCache[storyId] = {
|
|
1179
|
+
themeMedias: themeMedias,
|
|
1180
|
+
newTheme: newTheme
|
|
1181
|
+
};
|
|
1182
|
+
}
|
|
1183
|
+
return this.parsedThemesCache[storyId];
|
|
1184
|
+
}
|
|
1185
|
+
}, {
|
|
1170
1186
|
key: "getFieldsPatternByScreen",
|
|
1171
1187
|
value: function getFieldsPatternByScreen(type) {
|
|
1172
1188
|
if (typeof this.fieldsPatternCache[type] === 'undefined') {
|
|
@@ -1187,6 +1203,8 @@ var MediasParser = /*#__PURE__*/function () {
|
|
|
1187
1203
|
return story;
|
|
1188
1204
|
}
|
|
1189
1205
|
var _ref3 = story || {},
|
|
1206
|
+
_ref3$id = _ref3.id,
|
|
1207
|
+
storyId = _ref3$id === void 0 ? null : _ref3$id,
|
|
1190
1208
|
_ref3$theme = _ref3.theme,
|
|
1191
1209
|
theme = _ref3$theme === void 0 ? null : _ref3$theme,
|
|
1192
1210
|
_ref3$components = _ref3.components,
|
|
@@ -1210,9 +1228,9 @@ var MediasParser = /*#__PURE__*/function () {
|
|
|
1210
1228
|
newComponents = _components$reduce.components,
|
|
1211
1229
|
medias = _components$reduce.medias;
|
|
1212
1230
|
if (theme !== null) {
|
|
1213
|
-
var _this$
|
|
1214
|
-
themeMedias = _this$
|
|
1215
|
-
newTheme = _objectWithoutProperties(_this$
|
|
1231
|
+
var _this$getParsedStoryT = this.getParsedStoryTheme(storyId, theme),
|
|
1232
|
+
themeMedias = _this$getParsedStoryT.medias,
|
|
1233
|
+
newTheme = _objectWithoutProperties(_this$getParsedStoryT, _excluded2$2);
|
|
1216
1234
|
return medias !== null || themeMedias !== null ? _objectSpread(_objectSpread({}, story), {}, {
|
|
1217
1235
|
theme: newTheme,
|
|
1218
1236
|
components: newComponents,
|
|
@@ -1641,6 +1659,7 @@ var ThemeParser = /*#__PURE__*/function () {
|
|
|
1641
1659
|
_classCallCheck(this, ThemeParser);
|
|
1642
1660
|
this.screensManager = screensManager;
|
|
1643
1661
|
this.definitionCache = {};
|
|
1662
|
+
this.fieldsCache = {};
|
|
1644
1663
|
}
|
|
1645
1664
|
_createClass(ThemeParser, [{
|
|
1646
1665
|
key: "getDefinitionByScreen",
|
|
@@ -1657,6 +1676,54 @@ var ThemeParser = /*#__PURE__*/function () {
|
|
|
1657
1676
|
}
|
|
1658
1677
|
return this.definitionCache[type];
|
|
1659
1678
|
}
|
|
1679
|
+
}, {
|
|
1680
|
+
key: "getFieldsForDefinition",
|
|
1681
|
+
value: function getFieldsForDefinition(definition) {
|
|
1682
|
+
var _ref2 = definition || {},
|
|
1683
|
+
_ref2$id = _ref2.id,
|
|
1684
|
+
definitionId = _ref2$id === void 0 ? null : _ref2$id,
|
|
1685
|
+
_ref2$fields = _ref2.fields,
|
|
1686
|
+
fields = _ref2$fields === void 0 ? [] : _ref2$fields,
|
|
1687
|
+
_ref2$states = _ref2.states,
|
|
1688
|
+
states = _ref2$states === void 0 ? [] : _ref2$states;
|
|
1689
|
+
if (typeof this.fieldsCache[definitionId] === 'undefined') {
|
|
1690
|
+
if (states === null || states.length === 0) {
|
|
1691
|
+
this.fieldsCache[definitionId] = {
|
|
1692
|
+
fields: fields
|
|
1693
|
+
};
|
|
1694
|
+
} else {
|
|
1695
|
+
// TODO: test this
|
|
1696
|
+
var finalFields = fields;
|
|
1697
|
+
var repetableStates = [];
|
|
1698
|
+
if (states !== null && states.length > 0) {
|
|
1699
|
+
var nonRepetableStates = states.filter(function (_ref3) {
|
|
1700
|
+
var _ref3$repeatable = _ref3.repeatable,
|
|
1701
|
+
repeatable = _ref3$repeatable === void 0 ? false : _ref3$repeatable;
|
|
1702
|
+
return repeatable === false;
|
|
1703
|
+
});
|
|
1704
|
+
repetableStates = states.filter(function (_ref4) {
|
|
1705
|
+
var _ref4$repeatable = _ref4.repeatable,
|
|
1706
|
+
repeatable = _ref4$repeatable === void 0 ? false : _ref4$repeatable;
|
|
1707
|
+
return repeatable === true;
|
|
1708
|
+
});
|
|
1709
|
+
finalFields = nonRepetableStates.reduce(function (acc, it) {
|
|
1710
|
+
var _ref5 = it || {},
|
|
1711
|
+
_ref5$fields = _ref5.fields,
|
|
1712
|
+
itemFields = _ref5$fields === void 0 ? [] : _ref5$fields;
|
|
1713
|
+
if (itemFields !== null && itemFields.length > 0) {
|
|
1714
|
+
return acc.concat(itemFields);
|
|
1715
|
+
}
|
|
1716
|
+
return acc;
|
|
1717
|
+
}, finalFields);
|
|
1718
|
+
}
|
|
1719
|
+
this.fieldsCache[definitionId] = {
|
|
1720
|
+
fields: finalFields,
|
|
1721
|
+
repetableStates: repetableStates
|
|
1722
|
+
};
|
|
1723
|
+
}
|
|
1724
|
+
}
|
|
1725
|
+
return this.fieldsCache[definitionId];
|
|
1726
|
+
}
|
|
1660
1727
|
}, {
|
|
1661
1728
|
key: "parse",
|
|
1662
1729
|
value: function parse(story) {
|
|
@@ -1664,11 +1731,11 @@ var ThemeParser = /*#__PURE__*/function () {
|
|
|
1664
1731
|
if (story === null) {
|
|
1665
1732
|
return story;
|
|
1666
1733
|
}
|
|
1667
|
-
var
|
|
1668
|
-
|
|
1669
|
-
theme =
|
|
1670
|
-
|
|
1671
|
-
components =
|
|
1734
|
+
var _ref6 = story || {},
|
|
1735
|
+
_ref6$theme = _ref6.theme,
|
|
1736
|
+
theme = _ref6$theme === void 0 ? null : _ref6$theme,
|
|
1737
|
+
_ref6$components = _ref6.components,
|
|
1738
|
+
components = _ref6$components === void 0 ? null : _ref6$components;
|
|
1672
1739
|
if (theme === null || components === null) {
|
|
1673
1740
|
return story;
|
|
1674
1741
|
}
|
|
@@ -1682,6 +1749,33 @@ var ThemeParser = /*#__PURE__*/function () {
|
|
|
1682
1749
|
themeTextStyles = _theme$textStyles === void 0 ? null : _theme$textStyles,
|
|
1683
1750
|
_theme$boxStyles = theme.boxStyles,
|
|
1684
1751
|
themeBoxStyles = _theme$boxStyles === void 0 ? null : _theme$boxStyles;
|
|
1752
|
+
|
|
1753
|
+
// Speed test
|
|
1754
|
+
// const newComponents = [...components];
|
|
1755
|
+
// for (let index = 0; index < components.length; index += 1) {
|
|
1756
|
+
// const screen = components[index] || {};
|
|
1757
|
+
// const { type } = screen;
|
|
1758
|
+
// const { definition, themeScreen } = this.getDefinitionByScreen(type, themeComponents);
|
|
1759
|
+
// const newScreen = this.parseScreen(
|
|
1760
|
+
// definition,
|
|
1761
|
+
// screen,
|
|
1762
|
+
// themeScreen,
|
|
1763
|
+
// themeBackground,
|
|
1764
|
+
// themeColors,
|
|
1765
|
+
// themeTextStyles,
|
|
1766
|
+
// themeBoxStyles,
|
|
1767
|
+
// );
|
|
1768
|
+
|
|
1769
|
+
// if (newScreen !== screen || themeScreen !== null) {
|
|
1770
|
+
// newComponents[index] = {
|
|
1771
|
+
// ...themeScreen,
|
|
1772
|
+
// ...newScreen,
|
|
1773
|
+
// };
|
|
1774
|
+
// }
|
|
1775
|
+
// }
|
|
1776
|
+
// story.components = newComponents;
|
|
1777
|
+
// return story;
|
|
1778
|
+
|
|
1685
1779
|
var newComponents = components.reduce(function (currentComponents, screen, index) {
|
|
1686
1780
|
var type = screen.type;
|
|
1687
1781
|
var _this$getDefinitionBy = _this.getDefinitionByScreen(type, themeComponents),
|
|
@@ -1700,8 +1794,11 @@ var ThemeParser = /*#__PURE__*/function () {
|
|
|
1700
1794
|
key: "parseScreen",
|
|
1701
1795
|
value: function parseScreen(definition, value, themeValue, themeBackground, themeColors, themeTextStyles, themeBoxStyles) {
|
|
1702
1796
|
var _this2 = this;
|
|
1703
|
-
var
|
|
1704
|
-
|
|
1797
|
+
var _this$getFieldsForDef = this.getFieldsForDefinition(definition),
|
|
1798
|
+
_this$getFieldsForDef2 = _this$getFieldsForDef.fields,
|
|
1799
|
+
fields = _this$getFieldsForDef2 === void 0 ? null : _this$getFieldsForDef2,
|
|
1800
|
+
_this$getFieldsForDef3 = _this$getFieldsForDef.repetableStates,
|
|
1801
|
+
repetableStates = _this$getFieldsForDef3 === void 0 ? null : _this$getFieldsForDef3;
|
|
1705
1802
|
var newThemeValue = themeValue === null && themeBackground !== null ? {} : themeValue;
|
|
1706
1803
|
if (themeBackground !== null && typeof newThemeValue.background !== 'undefined') {
|
|
1707
1804
|
newThemeValue.background = _objectSpread(_objectSpread({}, themeBackground), newThemeValue.background);
|
|
@@ -1709,12 +1806,33 @@ var ThemeParser = /*#__PURE__*/function () {
|
|
|
1709
1806
|
newThemeValue.background = themeBackground;
|
|
1710
1807
|
}
|
|
1711
1808
|
var newScreenValue = Object.keys(value).reduce(function (currentValue, key) {
|
|
1712
|
-
var
|
|
1809
|
+
var repetableState = null;
|
|
1810
|
+
if (repetableStates !== null && repetableStates.length > 0) {
|
|
1811
|
+
repetableState = repetableStates.find(function (_ref7) {
|
|
1812
|
+
var _ref7$id = _ref7.id,
|
|
1813
|
+
stateId = _ref7$id === void 0 ? null : _ref7$id;
|
|
1814
|
+
return stateId !== null && stateId === key;
|
|
1815
|
+
}) || null;
|
|
1816
|
+
}
|
|
1817
|
+
var fieldDefinition = (fields || null).find(function (it) {
|
|
1713
1818
|
return it.name === key;
|
|
1714
|
-
}) || {};
|
|
1819
|
+
}) || repetableState || {};
|
|
1715
1820
|
var fieldValue = value[key];
|
|
1716
1821
|
var fieldThemeValue = newThemeValue !== null ? newThemeValue[key] || null : null;
|
|
1717
|
-
|
|
1822
|
+
|
|
1823
|
+
// Try for early return
|
|
1824
|
+
var _ref8 = fieldDefinition || {},
|
|
1825
|
+
_ref8$theme = _ref8.theme,
|
|
1826
|
+
theme = _ref8$theme === void 0 ? null : _ref8$theme;
|
|
1827
|
+
if ((theme === null || !isObject(theme)) && fields === null) {
|
|
1828
|
+
return _objectSpread(_objectSpread({}, currentValue), {}, _defineProperty({}, key, fieldValue));
|
|
1829
|
+
}
|
|
1830
|
+
|
|
1831
|
+
// console.log('start', key, fieldValue);
|
|
1832
|
+
var newFieldValue = _this2.parseField(fieldValue, fieldDefinition, fieldThemeValue, themeColors, themeTextStyles, themeBoxStyles);
|
|
1833
|
+
// console.log('result', newFieldValue);
|
|
1834
|
+
|
|
1835
|
+
// const newFieldValue = fieldValue;
|
|
1718
1836
|
|
|
1719
1837
|
// Only switch field if it has changed
|
|
1720
1838
|
return newFieldValue !== fieldValue ? _objectSpread(_objectSpread({}, currentValue), {}, _defineProperty({}, key, newFieldValue)) : currentValue;
|
|
@@ -1725,40 +1843,49 @@ var ThemeParser = /*#__PURE__*/function () {
|
|
|
1725
1843
|
// eslint-disable-next-line class-methods-use-this
|
|
1726
1844
|
}, {
|
|
1727
1845
|
key: "parseField",
|
|
1728
|
-
value: function parseField(
|
|
1729
|
-
var
|
|
1730
|
-
|
|
1731
|
-
|
|
1846
|
+
value: function parseField(value, fieldDefinition, themeValue, themeColors, themeTextStyles, themeBoxStyles) {
|
|
1847
|
+
var _this3 = this;
|
|
1848
|
+
var _fieldDefinition$them = fieldDefinition.theme,
|
|
1849
|
+
fieldTheme = _fieldDefinition$them === void 0 ? null : _fieldDefinition$them,
|
|
1850
|
+
_fieldDefinition$fiel = fieldDefinition.fields,
|
|
1851
|
+
definitionFields = _fieldDefinition$fiel === void 0 ? null : _fieldDefinition$fiel;
|
|
1852
|
+
|
|
1853
|
+
// There are sub-fields in this definition
|
|
1854
|
+
if (definitionFields !== null && value !== null) {
|
|
1855
|
+
return isArray(value) ? value.map(function (innerFieldValue) {
|
|
1856
|
+
if (innerFieldValue === null) {
|
|
1857
|
+
return innerFieldValue;
|
|
1858
|
+
}
|
|
1859
|
+
return _this3.parseInnerFields(innerFieldValue, definitionFields, themeValue, themeColors, themeTextStyles, themeBoxStyles);
|
|
1860
|
+
}) : this.parseInnerFields(value, definitionFields, themeValue, themeColors, themeTextStyles, themeBoxStyles);
|
|
1861
|
+
}
|
|
1732
1862
|
|
|
1733
1863
|
// Early return
|
|
1734
1864
|
if (fieldTheme === null || !isObject(fieldTheme)) {
|
|
1735
1865
|
return value;
|
|
1736
1866
|
}
|
|
1737
1867
|
|
|
1738
|
-
// @TODO very
|
|
1868
|
+
// @TODO very slooow...
|
|
1739
1869
|
if (isArray(value)) {
|
|
1740
1870
|
var newFieldValue = value.map(function (innerField) {
|
|
1741
1871
|
return innerField !== null ? Object.keys(innerField).reduce(function (newInnerField, innerFieldName) {
|
|
1742
|
-
// console.log('innerField', innerField);
|
|
1743
1872
|
// Early return
|
|
1744
1873
|
if (!isObject(innerField[innerFieldName])) {
|
|
1745
1874
|
return newInnerField;
|
|
1746
1875
|
}
|
|
1747
|
-
var
|
|
1748
|
-
|
|
1749
|
-
innerFieldTextStyle =
|
|
1750
|
-
|
|
1751
|
-
innerFieldColor =
|
|
1752
|
-
|
|
1753
|
-
innerFieldBoxStyle =
|
|
1876
|
+
var _ref9 = fieldTheme[innerFieldName] || {},
|
|
1877
|
+
_ref9$textStyle = _ref9.textStyle,
|
|
1878
|
+
innerFieldTextStyle = _ref9$textStyle === void 0 ? null : _ref9$textStyle,
|
|
1879
|
+
_ref9$color = _ref9.color,
|
|
1880
|
+
innerFieldColor = _ref9$color === void 0 ? null : _ref9$color,
|
|
1881
|
+
_ref9$boxStyle = _ref9.boxStyle,
|
|
1882
|
+
innerFieldBoxStyle = _ref9$boxStyle === void 0 ? null : _ref9$boxStyle;
|
|
1754
1883
|
|
|
1755
1884
|
// Early return, no theme
|
|
1756
1885
|
if (innerFieldTextStyle === null && innerFieldColor === null && innerFieldBoxStyle === null) {
|
|
1757
1886
|
return newInnerField;
|
|
1758
1887
|
}
|
|
1759
1888
|
|
|
1760
|
-
// TODO: replace this with the recursive parseValue...
|
|
1761
|
-
|
|
1762
1889
|
// Color
|
|
1763
1890
|
var colorValue = innerFieldColor !== null ? {
|
|
1764
1891
|
color: innerFieldColor !== null && themeColors !== null ? themeColors[innerFieldColor] || null : null
|
|
@@ -1784,22 +1911,55 @@ var ThemeParser = /*#__PURE__*/function () {
|
|
|
1784
1911
|
}
|
|
1785
1912
|
return value;
|
|
1786
1913
|
}
|
|
1914
|
+
}, {
|
|
1915
|
+
key: "parseInnerFields",
|
|
1916
|
+
value: function parseInnerFields(value, fieldsOrDefinition, themeValue, themeColors, themeTextStyles, themeBoxStyles) {
|
|
1917
|
+
var _this4 = this;
|
|
1918
|
+
var newValue = Object.keys(value).reduce(function (finalValue, innerFieldName) {
|
|
1919
|
+
var innerDefinition = isArray(fieldsOrDefinition) ? fieldsOrDefinition.find(function (it) {
|
|
1920
|
+
return it.name === innerFieldName;
|
|
1921
|
+
}) || null : fieldsOrDefinition;
|
|
1922
|
+
var _ref10 = innerDefinition || {},
|
|
1923
|
+
_ref10$theme = _ref10.theme,
|
|
1924
|
+
idfTheme = _ref10$theme === void 0 ? null : _ref10$theme;
|
|
1925
|
+
var innerValue = value[innerFieldName];
|
|
1926
|
+
|
|
1927
|
+
// For items fields
|
|
1928
|
+
if (innerValue !== null && innerDefinition !== null && isArray(innerValue)) {
|
|
1929
|
+
// eslint-disable-next-line no-param-reassign
|
|
1930
|
+
finalValue[innerFieldName] = _this4.parseField(innerValue, innerDefinition, themeValue, themeColors, themeTextStyles, themeBoxStyles);
|
|
1931
|
+
return finalValue;
|
|
1932
|
+
}
|
|
1933
|
+
|
|
1934
|
+
// For fields with fields
|
|
1935
|
+
if (innerValue !== null && idfTheme !== null && isObject(idfTheme) && isObject(innerValue)) {
|
|
1936
|
+
// eslint-disable-next-line no-param-reassign
|
|
1937
|
+
finalValue[innerFieldName] = _this4.parseValue(innerValue, idfTheme, themeValue, themeColors, themeTextStyles, themeBoxStyles);
|
|
1938
|
+
return finalValue;
|
|
1939
|
+
}
|
|
1940
|
+
|
|
1941
|
+
// eslint-disable-next-line no-param-reassign
|
|
1942
|
+
finalValue[innerFieldName] = value[innerFieldName];
|
|
1943
|
+
return finalValue;
|
|
1944
|
+
}, {});
|
|
1945
|
+
return newValue;
|
|
1946
|
+
}
|
|
1787
1947
|
|
|
1788
1948
|
// eslint-disable-next-line class-methods-use-this
|
|
1789
1949
|
}, {
|
|
1790
1950
|
key: "parseValue",
|
|
1791
1951
|
value: function parseValue(initialValue, fieldTheme, themeValue, themeColors, themeTextStyles, themeBoxStyles) {
|
|
1792
|
-
var
|
|
1952
|
+
var _this5 = this;
|
|
1793
1953
|
if (isObject(initialValue) || isObject(fieldTheme)) {
|
|
1794
1954
|
var value = initialValue || null;
|
|
1795
|
-
var
|
|
1796
|
-
|
|
1797
|
-
fieldTextStyleName =
|
|
1798
|
-
|
|
1799
|
-
fieldColorName =
|
|
1800
|
-
|
|
1801
|
-
fieldBoxStyleName =
|
|
1802
|
-
otherProps = _objectWithoutProperties(
|
|
1955
|
+
var _ref11 = fieldTheme || {},
|
|
1956
|
+
_ref11$textStyle = _ref11.textStyle,
|
|
1957
|
+
fieldTextStyleName = _ref11$textStyle === void 0 ? null : _ref11$textStyle,
|
|
1958
|
+
_ref11$color = _ref11.color,
|
|
1959
|
+
fieldColorName = _ref11$color === void 0 ? null : _ref11$color,
|
|
1960
|
+
_ref11$boxStyle = _ref11.boxStyle,
|
|
1961
|
+
fieldBoxStyleName = _ref11$boxStyle === void 0 ? null : _ref11$boxStyle,
|
|
1962
|
+
otherProps = _objectWithoutProperties(_ref11, _excluded$1);
|
|
1803
1963
|
if (fieldTextStyleName === null && fieldColorName === null && fieldBoxStyleName === null && isEmpty(otherProps) && !isObject(fieldTheme)) {
|
|
1804
1964
|
return value;
|
|
1805
1965
|
}
|
|
@@ -1807,15 +1967,15 @@ var ThemeParser = /*#__PURE__*/function () {
|
|
|
1807
1967
|
if (!isEmpty(otherProps)) {
|
|
1808
1968
|
complexValue = Object.keys(otherProps).reduce(function (newObject, key) {
|
|
1809
1969
|
var innerValue = value !== null ? value[key] || null : null;
|
|
1810
|
-
var newValue =
|
|
1970
|
+
var newValue = _this5.parseValue(innerValue, otherProps[key], themeValue, themeColors, themeTextStyles, themeBoxStyles);
|
|
1811
1971
|
return _objectSpread(_objectSpread({}, newObject), newValue !== null ? _defineProperty({}, key, newValue) : null);
|
|
1812
1972
|
}, {});
|
|
1813
1973
|
}
|
|
1814
|
-
var
|
|
1815
|
-
|
|
1816
|
-
valueTextStyle =
|
|
1817
|
-
|
|
1818
|
-
valueBoxStyle =
|
|
1974
|
+
var _ref13 = value || {},
|
|
1975
|
+
_ref13$textStyle = _ref13.textStyle,
|
|
1976
|
+
valueTextStyle = _ref13$textStyle === void 0 ? null : _ref13$textStyle,
|
|
1977
|
+
_ref13$boxStyle = _ref13.boxStyle,
|
|
1978
|
+
valueBoxStyle = _ref13$boxStyle === void 0 ? null : _ref13$boxStyle;
|
|
1819
1979
|
|
|
1820
1980
|
// Color
|
|
1821
1981
|
var fieldColor = fieldColorName !== null && themeColors !== null ? themeColors[fieldColorName] || null : null;
|
package/lib/components.js
CHANGED
|
@@ -3868,7 +3868,7 @@ var Placeholder = /*#__PURE__*/React__default["default"].memo(ScreenPlaceholder)
|
|
|
3868
3868
|
|
|
3869
3869
|
var styles$6 = {"stack":"micromag-core-screens-preview-stack","stackScreen":"micromag-core-screens-preview-stackScreen","stackItem":"micromag-core-screens-preview-stackItem","screen":"micromag-core-screens-preview-screen"};
|
|
3870
3870
|
|
|
3871
|
-
var _excluded = ["screen", "screenState", "width", "height", "screenWidth", "screenHeight", "className", "withSize"];
|
|
3871
|
+
var _excluded = ["screen", "screenState", "width", "height", "screenWidth", "screenHeight", "className", "withSize", "hidden"];
|
|
3872
3872
|
var propTypes$7 = {
|
|
3873
3873
|
screen: core.PropTypes.component.isRequired,
|
|
3874
3874
|
screenState: PropTypes__default["default"].string,
|
|
@@ -3877,7 +3877,8 @@ var propTypes$7 = {
|
|
|
3877
3877
|
screenWidth: PropTypes__default["default"].number,
|
|
3878
3878
|
screenHeight: PropTypes__default["default"].number,
|
|
3879
3879
|
className: PropTypes__default["default"].string,
|
|
3880
|
-
withSize: PropTypes__default["default"].bool
|
|
3880
|
+
withSize: PropTypes__default["default"].bool,
|
|
3881
|
+
hidden: PropTypes__default["default"].bool
|
|
3881
3882
|
};
|
|
3882
3883
|
var defaultProps$7 = {
|
|
3883
3884
|
screenState: null,
|
|
@@ -3886,7 +3887,8 @@ var defaultProps$7 = {
|
|
|
3886
3887
|
screenWidth: undefined,
|
|
3887
3888
|
screenHeight: undefined,
|
|
3888
3889
|
className: null,
|
|
3889
|
-
withSize: false
|
|
3890
|
+
withSize: false,
|
|
3891
|
+
hidden: false
|
|
3890
3892
|
};
|
|
3891
3893
|
var ScreenPreview = function ScreenPreview(_ref) {
|
|
3892
3894
|
var screen = _ref.screen,
|
|
@@ -3897,6 +3899,7 @@ var ScreenPreview = function ScreenPreview(_ref) {
|
|
|
3897
3899
|
screenHeight = _ref.screenHeight,
|
|
3898
3900
|
className = _ref.className,
|
|
3899
3901
|
withSize = _ref.withSize,
|
|
3902
|
+
hidden = _ref.hidden,
|
|
3900
3903
|
props = _objectWithoutProperties__default["default"](_ref, _excluded);
|
|
3901
3904
|
var screenElement = /*#__PURE__*/React__default["default"].createElement(Screen$1, Object.assign({
|
|
3902
3905
|
screen: screen,
|
|
@@ -3906,13 +3909,14 @@ var ScreenPreview = function ScreenPreview(_ref) {
|
|
|
3906
3909
|
height: !withSize ? height : undefined,
|
|
3907
3910
|
className: classNames__default["default"]([styles$6.screen, _defineProperty__default["default"]({}, className, !withSize)])
|
|
3908
3911
|
}, props));
|
|
3912
|
+
var element = !hidden ? screenElement : /*#__PURE__*/React__default["default"].createElement("div", null);
|
|
3909
3913
|
var screenWithSize = withSize ? /*#__PURE__*/React__default["default"].createElement(ScreenSizer, {
|
|
3910
3914
|
className: className,
|
|
3911
3915
|
screenWidth: screenWidth,
|
|
3912
3916
|
screenHeight: screenHeight,
|
|
3913
3917
|
width: width,
|
|
3914
3918
|
height: height
|
|
3915
|
-
},
|
|
3919
|
+
}, element) : element;
|
|
3916
3920
|
return screenWithSize;
|
|
3917
3921
|
};
|
|
3918
3922
|
ScreenPreview.propTypes = propTypes$7;
|
package/lib/index.js
CHANGED
|
@@ -1183,7 +1183,8 @@ var FieldsManager = /*#__PURE__*/function (_DefinitionsManager) {
|
|
|
1183
1183
|
return FieldsManager;
|
|
1184
1184
|
}(DefinitionsManager);
|
|
1185
1185
|
|
|
1186
|
-
var _excluded$4 = ["medias"]
|
|
1186
|
+
var _excluded$4 = ["medias"],
|
|
1187
|
+
_excluded2$2 = ["medias"];
|
|
1187
1188
|
var MediasParser = /*#__PURE__*/function () {
|
|
1188
1189
|
function MediasParser(_ref) {
|
|
1189
1190
|
var fieldsManager = _ref.fieldsManager,
|
|
@@ -1192,8 +1193,23 @@ var MediasParser = /*#__PURE__*/function () {
|
|
|
1192
1193
|
this.fieldsManager = fieldsManager;
|
|
1193
1194
|
this.screensManager = screensManager;
|
|
1194
1195
|
this.fieldsPatternCache = {};
|
|
1196
|
+
this.parsedThemesCache = {};
|
|
1195
1197
|
}
|
|
1196
1198
|
_createClass__default["default"](MediasParser, [{
|
|
1199
|
+
key: "getParsedStoryTheme",
|
|
1200
|
+
value: function getParsedStoryTheme(storyId, theme) {
|
|
1201
|
+
if (typeof this.parsedThemesCache[storyId] === 'undefined') {
|
|
1202
|
+
var _this$toPath = this.toPath(theme),
|
|
1203
|
+
themeMedias = _this$toPath.medias,
|
|
1204
|
+
newTheme = _objectWithoutProperties__default["default"](_this$toPath, _excluded$4);
|
|
1205
|
+
this.parsedThemesCache[storyId] = {
|
|
1206
|
+
themeMedias: themeMedias,
|
|
1207
|
+
newTheme: newTheme
|
|
1208
|
+
};
|
|
1209
|
+
}
|
|
1210
|
+
return this.parsedThemesCache[storyId];
|
|
1211
|
+
}
|
|
1212
|
+
}, {
|
|
1197
1213
|
key: "getFieldsPatternByScreen",
|
|
1198
1214
|
value: function getFieldsPatternByScreen(type) {
|
|
1199
1215
|
if (typeof this.fieldsPatternCache[type] === 'undefined') {
|
|
@@ -1214,6 +1230,8 @@ var MediasParser = /*#__PURE__*/function () {
|
|
|
1214
1230
|
return story;
|
|
1215
1231
|
}
|
|
1216
1232
|
var _ref3 = story || {},
|
|
1233
|
+
_ref3$id = _ref3.id,
|
|
1234
|
+
storyId = _ref3$id === void 0 ? null : _ref3$id,
|
|
1217
1235
|
_ref3$theme = _ref3.theme,
|
|
1218
1236
|
theme = _ref3$theme === void 0 ? null : _ref3$theme,
|
|
1219
1237
|
_ref3$components = _ref3.components,
|
|
@@ -1237,9 +1255,9 @@ var MediasParser = /*#__PURE__*/function () {
|
|
|
1237
1255
|
newComponents = _components$reduce.components,
|
|
1238
1256
|
medias = _components$reduce.medias;
|
|
1239
1257
|
if (theme !== null) {
|
|
1240
|
-
var _this$
|
|
1241
|
-
themeMedias = _this$
|
|
1242
|
-
newTheme = _objectWithoutProperties__default["default"](_this$
|
|
1258
|
+
var _this$getParsedStoryT = this.getParsedStoryTheme(storyId, theme),
|
|
1259
|
+
themeMedias = _this$getParsedStoryT.medias,
|
|
1260
|
+
newTheme = _objectWithoutProperties__default["default"](_this$getParsedStoryT, _excluded2$2);
|
|
1243
1261
|
return medias !== null || themeMedias !== null ? _objectSpread__default["default"](_objectSpread__default["default"]({}, story), {}, {
|
|
1244
1262
|
theme: newTheme,
|
|
1245
1263
|
components: newComponents,
|
|
@@ -1668,6 +1686,7 @@ var ThemeParser = /*#__PURE__*/function () {
|
|
|
1668
1686
|
_classCallCheck__default["default"](this, ThemeParser);
|
|
1669
1687
|
this.screensManager = screensManager;
|
|
1670
1688
|
this.definitionCache = {};
|
|
1689
|
+
this.fieldsCache = {};
|
|
1671
1690
|
}
|
|
1672
1691
|
_createClass__default["default"](ThemeParser, [{
|
|
1673
1692
|
key: "getDefinitionByScreen",
|
|
@@ -1684,6 +1703,54 @@ var ThemeParser = /*#__PURE__*/function () {
|
|
|
1684
1703
|
}
|
|
1685
1704
|
return this.definitionCache[type];
|
|
1686
1705
|
}
|
|
1706
|
+
}, {
|
|
1707
|
+
key: "getFieldsForDefinition",
|
|
1708
|
+
value: function getFieldsForDefinition(definition) {
|
|
1709
|
+
var _ref2 = definition || {},
|
|
1710
|
+
_ref2$id = _ref2.id,
|
|
1711
|
+
definitionId = _ref2$id === void 0 ? null : _ref2$id,
|
|
1712
|
+
_ref2$fields = _ref2.fields,
|
|
1713
|
+
fields = _ref2$fields === void 0 ? [] : _ref2$fields,
|
|
1714
|
+
_ref2$states = _ref2.states,
|
|
1715
|
+
states = _ref2$states === void 0 ? [] : _ref2$states;
|
|
1716
|
+
if (typeof this.fieldsCache[definitionId] === 'undefined') {
|
|
1717
|
+
if (states === null || states.length === 0) {
|
|
1718
|
+
this.fieldsCache[definitionId] = {
|
|
1719
|
+
fields: fields
|
|
1720
|
+
};
|
|
1721
|
+
} else {
|
|
1722
|
+
// TODO: test this
|
|
1723
|
+
var finalFields = fields;
|
|
1724
|
+
var repetableStates = [];
|
|
1725
|
+
if (states !== null && states.length > 0) {
|
|
1726
|
+
var nonRepetableStates = states.filter(function (_ref3) {
|
|
1727
|
+
var _ref3$repeatable = _ref3.repeatable,
|
|
1728
|
+
repeatable = _ref3$repeatable === void 0 ? false : _ref3$repeatable;
|
|
1729
|
+
return repeatable === false;
|
|
1730
|
+
});
|
|
1731
|
+
repetableStates = states.filter(function (_ref4) {
|
|
1732
|
+
var _ref4$repeatable = _ref4.repeatable,
|
|
1733
|
+
repeatable = _ref4$repeatable === void 0 ? false : _ref4$repeatable;
|
|
1734
|
+
return repeatable === true;
|
|
1735
|
+
});
|
|
1736
|
+
finalFields = nonRepetableStates.reduce(function (acc, it) {
|
|
1737
|
+
var _ref5 = it || {},
|
|
1738
|
+
_ref5$fields = _ref5.fields,
|
|
1739
|
+
itemFields = _ref5$fields === void 0 ? [] : _ref5$fields;
|
|
1740
|
+
if (itemFields !== null && itemFields.length > 0) {
|
|
1741
|
+
return acc.concat(itemFields);
|
|
1742
|
+
}
|
|
1743
|
+
return acc;
|
|
1744
|
+
}, finalFields);
|
|
1745
|
+
}
|
|
1746
|
+
this.fieldsCache[definitionId] = {
|
|
1747
|
+
fields: finalFields,
|
|
1748
|
+
repetableStates: repetableStates
|
|
1749
|
+
};
|
|
1750
|
+
}
|
|
1751
|
+
}
|
|
1752
|
+
return this.fieldsCache[definitionId];
|
|
1753
|
+
}
|
|
1687
1754
|
}, {
|
|
1688
1755
|
key: "parse",
|
|
1689
1756
|
value: function parse(story) {
|
|
@@ -1691,11 +1758,11 @@ var ThemeParser = /*#__PURE__*/function () {
|
|
|
1691
1758
|
if (story === null) {
|
|
1692
1759
|
return story;
|
|
1693
1760
|
}
|
|
1694
|
-
var
|
|
1695
|
-
|
|
1696
|
-
theme =
|
|
1697
|
-
|
|
1698
|
-
components =
|
|
1761
|
+
var _ref6 = story || {},
|
|
1762
|
+
_ref6$theme = _ref6.theme,
|
|
1763
|
+
theme = _ref6$theme === void 0 ? null : _ref6$theme,
|
|
1764
|
+
_ref6$components = _ref6.components,
|
|
1765
|
+
components = _ref6$components === void 0 ? null : _ref6$components;
|
|
1699
1766
|
if (theme === null || components === null) {
|
|
1700
1767
|
return story;
|
|
1701
1768
|
}
|
|
@@ -1709,6 +1776,33 @@ var ThemeParser = /*#__PURE__*/function () {
|
|
|
1709
1776
|
themeTextStyles = _theme$textStyles === void 0 ? null : _theme$textStyles,
|
|
1710
1777
|
_theme$boxStyles = theme.boxStyles,
|
|
1711
1778
|
themeBoxStyles = _theme$boxStyles === void 0 ? null : _theme$boxStyles;
|
|
1779
|
+
|
|
1780
|
+
// Speed test
|
|
1781
|
+
// const newComponents = [...components];
|
|
1782
|
+
// for (let index = 0; index < components.length; index += 1) {
|
|
1783
|
+
// const screen = components[index] || {};
|
|
1784
|
+
// const { type } = screen;
|
|
1785
|
+
// const { definition, themeScreen } = this.getDefinitionByScreen(type, themeComponents);
|
|
1786
|
+
// const newScreen = this.parseScreen(
|
|
1787
|
+
// definition,
|
|
1788
|
+
// screen,
|
|
1789
|
+
// themeScreen,
|
|
1790
|
+
// themeBackground,
|
|
1791
|
+
// themeColors,
|
|
1792
|
+
// themeTextStyles,
|
|
1793
|
+
// themeBoxStyles,
|
|
1794
|
+
// );
|
|
1795
|
+
|
|
1796
|
+
// if (newScreen !== screen || themeScreen !== null) {
|
|
1797
|
+
// newComponents[index] = {
|
|
1798
|
+
// ...themeScreen,
|
|
1799
|
+
// ...newScreen,
|
|
1800
|
+
// };
|
|
1801
|
+
// }
|
|
1802
|
+
// }
|
|
1803
|
+
// story.components = newComponents;
|
|
1804
|
+
// return story;
|
|
1805
|
+
|
|
1712
1806
|
var newComponents = components.reduce(function (currentComponents, screen, index) {
|
|
1713
1807
|
var type = screen.type;
|
|
1714
1808
|
var _this$getDefinitionBy = _this.getDefinitionByScreen(type, themeComponents),
|
|
@@ -1727,8 +1821,11 @@ var ThemeParser = /*#__PURE__*/function () {
|
|
|
1727
1821
|
key: "parseScreen",
|
|
1728
1822
|
value: function parseScreen(definition, value, themeValue, themeBackground, themeColors, themeTextStyles, themeBoxStyles) {
|
|
1729
1823
|
var _this2 = this;
|
|
1730
|
-
var
|
|
1731
|
-
|
|
1824
|
+
var _this$getFieldsForDef = this.getFieldsForDefinition(definition),
|
|
1825
|
+
_this$getFieldsForDef2 = _this$getFieldsForDef.fields,
|
|
1826
|
+
fields = _this$getFieldsForDef2 === void 0 ? null : _this$getFieldsForDef2,
|
|
1827
|
+
_this$getFieldsForDef3 = _this$getFieldsForDef.repetableStates,
|
|
1828
|
+
repetableStates = _this$getFieldsForDef3 === void 0 ? null : _this$getFieldsForDef3;
|
|
1732
1829
|
var newThemeValue = themeValue === null && themeBackground !== null ? {} : themeValue;
|
|
1733
1830
|
if (themeBackground !== null && typeof newThemeValue.background !== 'undefined') {
|
|
1734
1831
|
newThemeValue.background = _objectSpread__default["default"](_objectSpread__default["default"]({}, themeBackground), newThemeValue.background);
|
|
@@ -1736,12 +1833,33 @@ var ThemeParser = /*#__PURE__*/function () {
|
|
|
1736
1833
|
newThemeValue.background = themeBackground;
|
|
1737
1834
|
}
|
|
1738
1835
|
var newScreenValue = Object.keys(value).reduce(function (currentValue, key) {
|
|
1739
|
-
var
|
|
1836
|
+
var repetableState = null;
|
|
1837
|
+
if (repetableStates !== null && repetableStates.length > 0) {
|
|
1838
|
+
repetableState = repetableStates.find(function (_ref7) {
|
|
1839
|
+
var _ref7$id = _ref7.id,
|
|
1840
|
+
stateId = _ref7$id === void 0 ? null : _ref7$id;
|
|
1841
|
+
return stateId !== null && stateId === key;
|
|
1842
|
+
}) || null;
|
|
1843
|
+
}
|
|
1844
|
+
var fieldDefinition = (fields || null).find(function (it) {
|
|
1740
1845
|
return it.name === key;
|
|
1741
|
-
}) || {};
|
|
1846
|
+
}) || repetableState || {};
|
|
1742
1847
|
var fieldValue = value[key];
|
|
1743
1848
|
var fieldThemeValue = newThemeValue !== null ? newThemeValue[key] || null : null;
|
|
1744
|
-
|
|
1849
|
+
|
|
1850
|
+
// Try for early return
|
|
1851
|
+
var _ref8 = fieldDefinition || {},
|
|
1852
|
+
_ref8$theme = _ref8.theme,
|
|
1853
|
+
theme = _ref8$theme === void 0 ? null : _ref8$theme;
|
|
1854
|
+
if ((theme === null || !isObject__default["default"](theme)) && fields === null) {
|
|
1855
|
+
return _objectSpread__default["default"](_objectSpread__default["default"]({}, currentValue), {}, _defineProperty__default["default"]({}, key, fieldValue));
|
|
1856
|
+
}
|
|
1857
|
+
|
|
1858
|
+
// console.log('start', key, fieldValue);
|
|
1859
|
+
var newFieldValue = _this2.parseField(fieldValue, fieldDefinition, fieldThemeValue, themeColors, themeTextStyles, themeBoxStyles);
|
|
1860
|
+
// console.log('result', newFieldValue);
|
|
1861
|
+
|
|
1862
|
+
// const newFieldValue = fieldValue;
|
|
1745
1863
|
|
|
1746
1864
|
// Only switch field if it has changed
|
|
1747
1865
|
return newFieldValue !== fieldValue ? _objectSpread__default["default"](_objectSpread__default["default"]({}, currentValue), {}, _defineProperty__default["default"]({}, key, newFieldValue)) : currentValue;
|
|
@@ -1752,40 +1870,49 @@ var ThemeParser = /*#__PURE__*/function () {
|
|
|
1752
1870
|
// eslint-disable-next-line class-methods-use-this
|
|
1753
1871
|
}, {
|
|
1754
1872
|
key: "parseField",
|
|
1755
|
-
value: function parseField(
|
|
1756
|
-
var
|
|
1757
|
-
|
|
1758
|
-
|
|
1873
|
+
value: function parseField(value, fieldDefinition, themeValue, themeColors, themeTextStyles, themeBoxStyles) {
|
|
1874
|
+
var _this3 = this;
|
|
1875
|
+
var _fieldDefinition$them = fieldDefinition.theme,
|
|
1876
|
+
fieldTheme = _fieldDefinition$them === void 0 ? null : _fieldDefinition$them,
|
|
1877
|
+
_fieldDefinition$fiel = fieldDefinition.fields,
|
|
1878
|
+
definitionFields = _fieldDefinition$fiel === void 0 ? null : _fieldDefinition$fiel;
|
|
1879
|
+
|
|
1880
|
+
// There are sub-fields in this definition
|
|
1881
|
+
if (definitionFields !== null && value !== null) {
|
|
1882
|
+
return isArray__default["default"](value) ? value.map(function (innerFieldValue) {
|
|
1883
|
+
if (innerFieldValue === null) {
|
|
1884
|
+
return innerFieldValue;
|
|
1885
|
+
}
|
|
1886
|
+
return _this3.parseInnerFields(innerFieldValue, definitionFields, themeValue, themeColors, themeTextStyles, themeBoxStyles);
|
|
1887
|
+
}) : this.parseInnerFields(value, definitionFields, themeValue, themeColors, themeTextStyles, themeBoxStyles);
|
|
1888
|
+
}
|
|
1759
1889
|
|
|
1760
1890
|
// Early return
|
|
1761
1891
|
if (fieldTheme === null || !isObject__default["default"](fieldTheme)) {
|
|
1762
1892
|
return value;
|
|
1763
1893
|
}
|
|
1764
1894
|
|
|
1765
|
-
// @TODO very
|
|
1895
|
+
// @TODO very slooow...
|
|
1766
1896
|
if (isArray__default["default"](value)) {
|
|
1767
1897
|
var newFieldValue = value.map(function (innerField) {
|
|
1768
1898
|
return innerField !== null ? Object.keys(innerField).reduce(function (newInnerField, innerFieldName) {
|
|
1769
|
-
// console.log('innerField', innerField);
|
|
1770
1899
|
// Early return
|
|
1771
1900
|
if (!isObject__default["default"](innerField[innerFieldName])) {
|
|
1772
1901
|
return newInnerField;
|
|
1773
1902
|
}
|
|
1774
|
-
var
|
|
1775
|
-
|
|
1776
|
-
innerFieldTextStyle =
|
|
1777
|
-
|
|
1778
|
-
innerFieldColor =
|
|
1779
|
-
|
|
1780
|
-
innerFieldBoxStyle =
|
|
1903
|
+
var _ref9 = fieldTheme[innerFieldName] || {},
|
|
1904
|
+
_ref9$textStyle = _ref9.textStyle,
|
|
1905
|
+
innerFieldTextStyle = _ref9$textStyle === void 0 ? null : _ref9$textStyle,
|
|
1906
|
+
_ref9$color = _ref9.color,
|
|
1907
|
+
innerFieldColor = _ref9$color === void 0 ? null : _ref9$color,
|
|
1908
|
+
_ref9$boxStyle = _ref9.boxStyle,
|
|
1909
|
+
innerFieldBoxStyle = _ref9$boxStyle === void 0 ? null : _ref9$boxStyle;
|
|
1781
1910
|
|
|
1782
1911
|
// Early return, no theme
|
|
1783
1912
|
if (innerFieldTextStyle === null && innerFieldColor === null && innerFieldBoxStyle === null) {
|
|
1784
1913
|
return newInnerField;
|
|
1785
1914
|
}
|
|
1786
1915
|
|
|
1787
|
-
// TODO: replace this with the recursive parseValue...
|
|
1788
|
-
|
|
1789
1916
|
// Color
|
|
1790
1917
|
var colorValue = innerFieldColor !== null ? {
|
|
1791
1918
|
color: innerFieldColor !== null && themeColors !== null ? themeColors[innerFieldColor] || null : null
|
|
@@ -1811,22 +1938,55 @@ var ThemeParser = /*#__PURE__*/function () {
|
|
|
1811
1938
|
}
|
|
1812
1939
|
return value;
|
|
1813
1940
|
}
|
|
1941
|
+
}, {
|
|
1942
|
+
key: "parseInnerFields",
|
|
1943
|
+
value: function parseInnerFields(value, fieldsOrDefinition, themeValue, themeColors, themeTextStyles, themeBoxStyles) {
|
|
1944
|
+
var _this4 = this;
|
|
1945
|
+
var newValue = Object.keys(value).reduce(function (finalValue, innerFieldName) {
|
|
1946
|
+
var innerDefinition = isArray__default["default"](fieldsOrDefinition) ? fieldsOrDefinition.find(function (it) {
|
|
1947
|
+
return it.name === innerFieldName;
|
|
1948
|
+
}) || null : fieldsOrDefinition;
|
|
1949
|
+
var _ref10 = innerDefinition || {},
|
|
1950
|
+
_ref10$theme = _ref10.theme,
|
|
1951
|
+
idfTheme = _ref10$theme === void 0 ? null : _ref10$theme;
|
|
1952
|
+
var innerValue = value[innerFieldName];
|
|
1953
|
+
|
|
1954
|
+
// For items fields
|
|
1955
|
+
if (innerValue !== null && innerDefinition !== null && isArray__default["default"](innerValue)) {
|
|
1956
|
+
// eslint-disable-next-line no-param-reassign
|
|
1957
|
+
finalValue[innerFieldName] = _this4.parseField(innerValue, innerDefinition, themeValue, themeColors, themeTextStyles, themeBoxStyles);
|
|
1958
|
+
return finalValue;
|
|
1959
|
+
}
|
|
1960
|
+
|
|
1961
|
+
// For fields with fields
|
|
1962
|
+
if (innerValue !== null && idfTheme !== null && isObject__default["default"](idfTheme) && isObject__default["default"](innerValue)) {
|
|
1963
|
+
// eslint-disable-next-line no-param-reassign
|
|
1964
|
+
finalValue[innerFieldName] = _this4.parseValue(innerValue, idfTheme, themeValue, themeColors, themeTextStyles, themeBoxStyles);
|
|
1965
|
+
return finalValue;
|
|
1966
|
+
}
|
|
1967
|
+
|
|
1968
|
+
// eslint-disable-next-line no-param-reassign
|
|
1969
|
+
finalValue[innerFieldName] = value[innerFieldName];
|
|
1970
|
+
return finalValue;
|
|
1971
|
+
}, {});
|
|
1972
|
+
return newValue;
|
|
1973
|
+
}
|
|
1814
1974
|
|
|
1815
1975
|
// eslint-disable-next-line class-methods-use-this
|
|
1816
1976
|
}, {
|
|
1817
1977
|
key: "parseValue",
|
|
1818
1978
|
value: function parseValue(initialValue, fieldTheme, themeValue, themeColors, themeTextStyles, themeBoxStyles) {
|
|
1819
|
-
var
|
|
1979
|
+
var _this5 = this;
|
|
1820
1980
|
if (isObject__default["default"](initialValue) || isObject__default["default"](fieldTheme)) {
|
|
1821
1981
|
var value = initialValue || null;
|
|
1822
|
-
var
|
|
1823
|
-
|
|
1824
|
-
fieldTextStyleName =
|
|
1825
|
-
|
|
1826
|
-
fieldColorName =
|
|
1827
|
-
|
|
1828
|
-
fieldBoxStyleName =
|
|
1829
|
-
otherProps = _objectWithoutProperties__default["default"](
|
|
1982
|
+
var _ref11 = fieldTheme || {},
|
|
1983
|
+
_ref11$textStyle = _ref11.textStyle,
|
|
1984
|
+
fieldTextStyleName = _ref11$textStyle === void 0 ? null : _ref11$textStyle,
|
|
1985
|
+
_ref11$color = _ref11.color,
|
|
1986
|
+
fieldColorName = _ref11$color === void 0 ? null : _ref11$color,
|
|
1987
|
+
_ref11$boxStyle = _ref11.boxStyle,
|
|
1988
|
+
fieldBoxStyleName = _ref11$boxStyle === void 0 ? null : _ref11$boxStyle,
|
|
1989
|
+
otherProps = _objectWithoutProperties__default["default"](_ref11, _excluded$1);
|
|
1830
1990
|
if (fieldTextStyleName === null && fieldColorName === null && fieldBoxStyleName === null && isEmpty__default["default"](otherProps) && !isObject__default["default"](fieldTheme)) {
|
|
1831
1991
|
return value;
|
|
1832
1992
|
}
|
|
@@ -1834,15 +1994,15 @@ var ThemeParser = /*#__PURE__*/function () {
|
|
|
1834
1994
|
if (!isEmpty__default["default"](otherProps)) {
|
|
1835
1995
|
complexValue = Object.keys(otherProps).reduce(function (newObject, key) {
|
|
1836
1996
|
var innerValue = value !== null ? value[key] || null : null;
|
|
1837
|
-
var newValue =
|
|
1997
|
+
var newValue = _this5.parseValue(innerValue, otherProps[key], themeValue, themeColors, themeTextStyles, themeBoxStyles);
|
|
1838
1998
|
return _objectSpread__default["default"](_objectSpread__default["default"]({}, newObject), newValue !== null ? _defineProperty__default["default"]({}, key, newValue) : null);
|
|
1839
1999
|
}, {});
|
|
1840
2000
|
}
|
|
1841
|
-
var
|
|
1842
|
-
|
|
1843
|
-
valueTextStyle =
|
|
1844
|
-
|
|
1845
|
-
valueBoxStyle =
|
|
2001
|
+
var _ref13 = value || {},
|
|
2002
|
+
_ref13$textStyle = _ref13.textStyle,
|
|
2003
|
+
valueTextStyle = _ref13$textStyle === void 0 ? null : _ref13$textStyle,
|
|
2004
|
+
_ref13$boxStyle = _ref13.boxStyle,
|
|
2005
|
+
valueBoxStyle = _ref13$boxStyle === void 0 ? null : _ref13$boxStyle;
|
|
1846
2006
|
|
|
1847
2007
|
// Color
|
|
1848
2008
|
var fieldColor = fieldColorName !== null && themeColors !== null ? themeColors[fieldColorName] || null : null;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@micromag/core",
|
|
3
|
-
"version": "0.3.
|
|
3
|
+
"version": "0.3.420",
|
|
4
4
|
"private": false,
|
|
5
5
|
"description": "",
|
|
6
6
|
"keywords": [
|
|
@@ -136,5 +136,5 @@
|
|
|
136
136
|
"access": "public",
|
|
137
137
|
"registry": "https://registry.npmjs.org/"
|
|
138
138
|
},
|
|
139
|
-
"gitHead": "
|
|
139
|
+
"gitHead": "5b0f037a41c3bca07a5bce8f0dce205242f7ad17"
|
|
140
140
|
}
|