@micromag/core 0.3.347 → 0.3.354
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 +265 -41
- package/es/hooks.js +5 -2
- package/es/index.js +210 -133
- package/es/utils.js +68 -2
- package/lib/components.js +271 -40
- package/lib/hooks.js +5 -2
- package/lib/index.js +211 -134
- package/lib/utils.js +69 -0
- package/package.json +2 -2
package/es/index.js
CHANGED
|
@@ -25,8 +25,8 @@ import _slicedToArray from '@babel/runtime/helpers/slicedToArray';
|
|
|
25
25
|
import 'slugify';
|
|
26
26
|
import uniqBy from 'lodash/uniqBy';
|
|
27
27
|
import _typeof from '@babel/runtime/helpers/typeof';
|
|
28
|
-
import isEmpty from 'lodash/isEmpty';
|
|
29
28
|
import uniq from 'lodash/uniq';
|
|
29
|
+
import isEmpty from 'lodash/isEmpty';
|
|
30
30
|
import { Tracking as Tracking$1 } from '@folklore/tracking';
|
|
31
31
|
|
|
32
32
|
/**
|
|
@@ -605,6 +605,10 @@ var visitor = PropTypes$1.shape({
|
|
|
605
605
|
id: PropTypes$1.oneOfType([PropTypes$1.string, PropTypes$1.number]),
|
|
606
606
|
name: PropTypes$1.string
|
|
607
607
|
});
|
|
608
|
+
var badge = PropTypes$1.shape({
|
|
609
|
+
label: textElement,
|
|
610
|
+
buttonStyle: boxStyle
|
|
611
|
+
});
|
|
608
612
|
|
|
609
613
|
var PropTypes = /*#__PURE__*/Object.freeze({
|
|
610
614
|
__proto__: null,
|
|
@@ -749,7 +753,8 @@ var PropTypes = /*#__PURE__*/Object.freeze({
|
|
|
749
753
|
paymentItems: paymentItems,
|
|
750
754
|
pageMetadata: pageMetadata,
|
|
751
755
|
authorElement: authorElement,
|
|
752
|
-
visitor: visitor
|
|
756
|
+
visitor: visitor,
|
|
757
|
+
badge: badge
|
|
753
758
|
});
|
|
754
759
|
|
|
755
760
|
var sortedColors = function sortedColors(colors) {
|
|
@@ -1137,7 +1142,7 @@ var FieldsManager = /*#__PURE__*/function (_DefinitionsManager) {
|
|
|
1137
1142
|
return FieldsManager;
|
|
1138
1143
|
}(DefinitionsManager);
|
|
1139
1144
|
|
|
1140
|
-
var _excluded$
|
|
1145
|
+
var _excluded$4 = ["medias"];
|
|
1141
1146
|
var MediasParser = /*#__PURE__*/function () {
|
|
1142
1147
|
function MediasParser(_ref) {
|
|
1143
1148
|
var fieldsManager = _ref.fieldsManager,
|
|
@@ -1193,7 +1198,7 @@ var MediasParser = /*#__PURE__*/function () {
|
|
|
1193
1198
|
if (theme !== null) {
|
|
1194
1199
|
var _this$toPath = this.toPath(theme),
|
|
1195
1200
|
themeMedias = _this$toPath.medias,
|
|
1196
|
-
newTheme = _objectWithoutProperties(_this$toPath, _excluded$
|
|
1201
|
+
newTheme = _objectWithoutProperties(_this$toPath, _excluded$4);
|
|
1197
1202
|
return medias !== null || themeMedias !== null ? _objectSpread(_objectSpread({}, story), {}, {
|
|
1198
1203
|
theme: newTheme,
|
|
1199
1204
|
components: newComponents,
|
|
@@ -1425,7 +1430,197 @@ var ScreensManager = /*#__PURE__*/function (_DefinitionsManager) {
|
|
|
1425
1430
|
return ScreensManager;
|
|
1426
1431
|
}(DefinitionsManager);
|
|
1427
1432
|
|
|
1428
|
-
var _excluded$
|
|
1433
|
+
var _excluded$3 = ["fonts"];
|
|
1434
|
+
var FontsParser = /*#__PURE__*/function () {
|
|
1435
|
+
function FontsParser(_ref) {
|
|
1436
|
+
var fieldsManager = _ref.fieldsManager,
|
|
1437
|
+
screensManager = _ref.screensManager;
|
|
1438
|
+
_classCallCheck(this, FontsParser);
|
|
1439
|
+
this.fieldsManager = fieldsManager;
|
|
1440
|
+
this.screensManager = screensManager;
|
|
1441
|
+
this.fieldsPatternCache = {};
|
|
1442
|
+
}
|
|
1443
|
+
_createClass(FontsParser, [{
|
|
1444
|
+
key: "getFieldsPatternByScreen",
|
|
1445
|
+
value: function getFieldsPatternByScreen(type) {
|
|
1446
|
+
if (typeof this.fieldsPatternCache[type] === 'undefined') {
|
|
1447
|
+
var _ref2 = this.screensManager.getDefinition(type) || {},
|
|
1448
|
+
_ref2$fields = _ref2.fields,
|
|
1449
|
+
fields = _ref2$fields === void 0 ? [] : _ref2$fields;
|
|
1450
|
+
this.fieldsPatternCache[type] = this.getFieldsPattern(fields);
|
|
1451
|
+
}
|
|
1452
|
+
return this.fieldsPatternCache[type];
|
|
1453
|
+
}
|
|
1454
|
+
|
|
1455
|
+
// Extract fonts
|
|
1456
|
+
}, {
|
|
1457
|
+
key: "parse",
|
|
1458
|
+
value: function parse(story) {
|
|
1459
|
+
var _this = this;
|
|
1460
|
+
if (story === null) {
|
|
1461
|
+
return story;
|
|
1462
|
+
}
|
|
1463
|
+
|
|
1464
|
+
// Extract fonts from screen
|
|
1465
|
+
var _ref3 = story || {},
|
|
1466
|
+
_ref3$theme = _ref3.theme,
|
|
1467
|
+
theme = _ref3$theme === void 0 ? null : _ref3$theme,
|
|
1468
|
+
_ref3$components = _ref3.components,
|
|
1469
|
+
components = _ref3$components === void 0 ? [] : _ref3$components;
|
|
1470
|
+
var fonts = uniq(components.reduce(function (currentFonts, screen) {
|
|
1471
|
+
var type = screen.type;
|
|
1472
|
+
var fieldsPattern = _this.getFieldsPatternByScreen(type);
|
|
1473
|
+
var newFonts = FontsParser.extractFontsWithPaths(screen, fieldsPattern);
|
|
1474
|
+
return newFonts.length > 0 ? [].concat(_toConsumableArray(currentFonts), _toConsumableArray(newFonts)) : currentFonts;
|
|
1475
|
+
}, []), 'name');
|
|
1476
|
+
|
|
1477
|
+
// Extract fonts from theme
|
|
1478
|
+
if (theme !== null) {
|
|
1479
|
+
var _this$parse = this.parse(theme),
|
|
1480
|
+
_this$parse$fonts = _this$parse.fonts,
|
|
1481
|
+
themeFonts = _this$parse$fonts === void 0 ? [] : _this$parse$fonts,
|
|
1482
|
+
newTheme = _objectWithoutProperties(_this$parse, _excluded$3);
|
|
1483
|
+
return fonts.length > 0 || themeFonts.length > 0 ? _objectSpread(_objectSpread({}, story), {}, {
|
|
1484
|
+
theme: newTheme,
|
|
1485
|
+
fonts: uniq([].concat(_toConsumableArray(themeFonts), _toConsumableArray(fonts)), 'name')
|
|
1486
|
+
}) : story;
|
|
1487
|
+
}
|
|
1488
|
+
return fonts.length > 0 ? _objectSpread(_objectSpread({}, story), {}, {
|
|
1489
|
+
fonts: fonts
|
|
1490
|
+
}) : story;
|
|
1491
|
+
}
|
|
1492
|
+
}, {
|
|
1493
|
+
key: "getFieldsPattern",
|
|
1494
|
+
value: function getFieldsPattern(fields) {
|
|
1495
|
+
var _this2 = this;
|
|
1496
|
+
var namePrefix = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : null;
|
|
1497
|
+
return fields.reduce(function (patterns, field) {
|
|
1498
|
+
var _field$name = field.name,
|
|
1499
|
+
name = _field$name === void 0 ? null : _field$name,
|
|
1500
|
+
_field$type = field.type,
|
|
1501
|
+
type = _field$type === void 0 ? null : _field$type;
|
|
1502
|
+
var path = [namePrefix, name].filter(function (it) {
|
|
1503
|
+
return it !== null;
|
|
1504
|
+
}).join('\\.');
|
|
1505
|
+
var fieldDefinition = _objectSpread(_objectSpread({}, type !== null ? _this2.fieldsManager.getDefinition(type) : null), field);
|
|
1506
|
+
|
|
1507
|
+
// also check settings fields
|
|
1508
|
+
var _fieldDefinition$fiel = fieldDefinition.fields,
|
|
1509
|
+
subFields = _fieldDefinition$fiel === void 0 ? [] : _fieldDefinition$fiel,
|
|
1510
|
+
_fieldDefinition$item = fieldDefinition.itemsField,
|
|
1511
|
+
itemsField = _fieldDefinition$item === void 0 ? null : _fieldDefinition$item,
|
|
1512
|
+
_fieldDefinition$sett = fieldDefinition.settings,
|
|
1513
|
+
settings = _fieldDefinition$sett === void 0 ? [] : _fieldDefinition$sett;
|
|
1514
|
+
return [].concat(_toConsumableArray(patterns), _toConsumableArray(FontsParser.fieldIsFontFamily(fieldDefinition) ? [new RegExp("^".concat(path, "$"))] : []), _toConsumableArray(_this2.getFieldsPattern(subFields, path)), _toConsumableArray(_this2.getFieldsPattern(settings, path)), _toConsumableArray(itemsField !== null ? _this2.getFieldsPattern([itemsField], "".concat(path, "\\.[0-9]+")) : []));
|
|
1515
|
+
}, []);
|
|
1516
|
+
}
|
|
1517
|
+
}], [{
|
|
1518
|
+
key: "fieldIsFontFamily",
|
|
1519
|
+
value: function fieldIsFontFamily(_ref4) {
|
|
1520
|
+
var _ref4$id = _ref4.id,
|
|
1521
|
+
id = _ref4$id === void 0 ? null : _ref4$id;
|
|
1522
|
+
return id === 'font-family';
|
|
1523
|
+
}
|
|
1524
|
+
}, {
|
|
1525
|
+
key: "valueIsFont",
|
|
1526
|
+
value: function valueIsFont(_ref5) {
|
|
1527
|
+
var _ref5$type = _ref5.type,
|
|
1528
|
+
type = _ref5$type === void 0 ? null : _ref5$type;
|
|
1529
|
+
return type === 'custom' || type === 'google';
|
|
1530
|
+
}
|
|
1531
|
+
}, {
|
|
1532
|
+
key: "extractFontsWithPaths",
|
|
1533
|
+
value: function extractFontsWithPaths(data, patterns) {
|
|
1534
|
+
var keyPrefix = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : null;
|
|
1535
|
+
var dataIsArray = isArray(data);
|
|
1536
|
+
var keys = dataIsArray ? _toConsumableArray(data.keys()) : Object.keys(data);
|
|
1537
|
+
return keys.reduce(function (currentFonts, key) {
|
|
1538
|
+
var path = [keyPrefix, key].filter(function (it) {
|
|
1539
|
+
return it !== null;
|
|
1540
|
+
}).join('.');
|
|
1541
|
+
var patternMatch = patterns.reduce(function (found, pattern) {
|
|
1542
|
+
return found || pattern.test(path);
|
|
1543
|
+
}, false);
|
|
1544
|
+
var value = data[key];
|
|
1545
|
+
var font = null;
|
|
1546
|
+
var subFonts = null;
|
|
1547
|
+
if (patternMatch && isObject(value) && FontsParser.valueIsFont(value)) {
|
|
1548
|
+
font = value;
|
|
1549
|
+
} else if (isObject(value) || isArray(value)) {
|
|
1550
|
+
subFonts = FontsParser.extractFontsWithPaths(value, patterns, path);
|
|
1551
|
+
}
|
|
1552
|
+
return subFonts !== null || font !== null ? [].concat(_toConsumableArray(currentFonts), _toConsumableArray(subFonts || []), _toConsumableArray(font !== null ? [font] : [])) : currentFonts;
|
|
1553
|
+
}, []);
|
|
1554
|
+
}
|
|
1555
|
+
}]);
|
|
1556
|
+
return FontsParser;
|
|
1557
|
+
}();
|
|
1558
|
+
|
|
1559
|
+
var _excluded$2 = ["components"],
|
|
1560
|
+
_excluded2$1 = ["shareIncentive", "callToAction"];
|
|
1561
|
+
var MigrationsParser = /*#__PURE__*/function () {
|
|
1562
|
+
function MigrationsParser(_ref) {
|
|
1563
|
+
var fieldsManager = _ref.fieldsManager,
|
|
1564
|
+
screensManager = _ref.screensManager;
|
|
1565
|
+
_classCallCheck(this, MigrationsParser);
|
|
1566
|
+
this.fieldsManager = fieldsManager;
|
|
1567
|
+
this.screensManager = screensManager;
|
|
1568
|
+
}
|
|
1569
|
+
|
|
1570
|
+
// eslint-disable-next-line class-methods-use-this
|
|
1571
|
+
_createClass(MigrationsParser, [{
|
|
1572
|
+
key: "parse",
|
|
1573
|
+
value: function parse(story) {
|
|
1574
|
+
if (story === null) {
|
|
1575
|
+
return story;
|
|
1576
|
+
}
|
|
1577
|
+
var _ref2 = story || {},
|
|
1578
|
+
_ref2$components = _ref2.components,
|
|
1579
|
+
components = _ref2$components === void 0 ? [] : _ref2$components,
|
|
1580
|
+
restStory = _objectWithoutProperties(_ref2, _excluded$2);
|
|
1581
|
+
var finalComponents = components.reduce(function (currentComponents, screen) {
|
|
1582
|
+
var _ref3 = screen || {},
|
|
1583
|
+
_ref3$shareIncentive = _ref3.shareIncentive,
|
|
1584
|
+
shareIncentive = _ref3$shareIncentive === void 0 ? null : _ref3$shareIncentive,
|
|
1585
|
+
_ref3$callToAction = _ref3.callToAction,
|
|
1586
|
+
callToAction = _ref3$callToAction === void 0 ? null : _ref3$callToAction,
|
|
1587
|
+
restScreen = _objectWithoutProperties(_ref3, _excluded2$1);
|
|
1588
|
+
if (shareIncentive === null && callToAction === null) {
|
|
1589
|
+
return [].concat(_toConsumableArray(currentComponents), [restScreen]);
|
|
1590
|
+
}
|
|
1591
|
+
var _ref4 = screen || {},
|
|
1592
|
+
_ref4$header = _ref4.header,
|
|
1593
|
+
header = _ref4$header === void 0 ? null : _ref4$header,
|
|
1594
|
+
_ref4$footer = _ref4.footer,
|
|
1595
|
+
footer = _ref4$footer === void 0 ? null : _ref4$footer;
|
|
1596
|
+
|
|
1597
|
+
// Carful for recursivity here cause same key name
|
|
1598
|
+
var newHeader = shareIncentive !== null ? _objectSpread(_objectSpread({}, shareIncentive !== null ? {
|
|
1599
|
+
shareIncentive: shareIncentive
|
|
1600
|
+
} : null), header !== null ? {
|
|
1601
|
+
header: header
|
|
1602
|
+
} : null) : header;
|
|
1603
|
+
var newFooter = callToAction !== null ? _objectSpread(_objectSpread({}, callToAction !== null ? {
|
|
1604
|
+
callToAction: callToAction
|
|
1605
|
+
} : null), footer !== null ? {
|
|
1606
|
+
footer: footer
|
|
1607
|
+
} : null) : footer;
|
|
1608
|
+
var newScreen = _objectSpread(_objectSpread(_objectSpread({}, restScreen), newHeader !== null ? {
|
|
1609
|
+
header: newHeader
|
|
1610
|
+
} : null), newFooter !== null ? {
|
|
1611
|
+
footer: newFooter
|
|
1612
|
+
} : null);
|
|
1613
|
+
return [].concat(_toConsumableArray(currentComponents), [newScreen]);
|
|
1614
|
+
}, []);
|
|
1615
|
+
return _objectSpread(_objectSpread({}, restStory), {}, {
|
|
1616
|
+
components: finalComponents
|
|
1617
|
+
});
|
|
1618
|
+
}
|
|
1619
|
+
}]);
|
|
1620
|
+
return MigrationsParser;
|
|
1621
|
+
}();
|
|
1622
|
+
|
|
1623
|
+
var _excluded$1 = ["textStyle", "color", "boxStyle"];
|
|
1429
1624
|
var ThemeParser = /*#__PURE__*/function () {
|
|
1430
1625
|
function ThemeParser(_ref) {
|
|
1431
1626
|
var screensManager = _ref.screensManager;
|
|
@@ -1588,7 +1783,7 @@ var ThemeParser = /*#__PURE__*/function () {
|
|
|
1588
1783
|
fieldColorName = _ref4$color === void 0 ? null : _ref4$color,
|
|
1589
1784
|
_ref4$boxStyle = _ref4.boxStyle,
|
|
1590
1785
|
fieldBoxStyleName = _ref4$boxStyle === void 0 ? null : _ref4$boxStyle,
|
|
1591
|
-
otherProps = _objectWithoutProperties(_ref4, _excluded$
|
|
1786
|
+
otherProps = _objectWithoutProperties(_ref4, _excluded$1);
|
|
1592
1787
|
if (fieldTextStyleName === null && fieldColorName === null && fieldBoxStyleName === null && isEmpty(otherProps) && !isObject(fieldTheme)) {
|
|
1593
1788
|
return value;
|
|
1594
1789
|
}
|
|
@@ -1635,132 +1830,6 @@ var ThemeParser = /*#__PURE__*/function () {
|
|
|
1635
1830
|
return ThemeParser;
|
|
1636
1831
|
}();
|
|
1637
1832
|
|
|
1638
|
-
var _excluded$1 = ["fonts"];
|
|
1639
|
-
var FontsParser = /*#__PURE__*/function () {
|
|
1640
|
-
function FontsParser(_ref) {
|
|
1641
|
-
var fieldsManager = _ref.fieldsManager,
|
|
1642
|
-
screensManager = _ref.screensManager;
|
|
1643
|
-
_classCallCheck(this, FontsParser);
|
|
1644
|
-
this.fieldsManager = fieldsManager;
|
|
1645
|
-
this.screensManager = screensManager;
|
|
1646
|
-
this.fieldsPatternCache = {};
|
|
1647
|
-
}
|
|
1648
|
-
_createClass(FontsParser, [{
|
|
1649
|
-
key: "getFieldsPatternByScreen",
|
|
1650
|
-
value: function getFieldsPatternByScreen(type) {
|
|
1651
|
-
if (typeof this.fieldsPatternCache[type] === 'undefined') {
|
|
1652
|
-
var _ref2 = this.screensManager.getDefinition(type) || {},
|
|
1653
|
-
_ref2$fields = _ref2.fields,
|
|
1654
|
-
fields = _ref2$fields === void 0 ? [] : _ref2$fields;
|
|
1655
|
-
this.fieldsPatternCache[type] = this.getFieldsPattern(fields);
|
|
1656
|
-
}
|
|
1657
|
-
return this.fieldsPatternCache[type];
|
|
1658
|
-
}
|
|
1659
|
-
|
|
1660
|
-
// Extract fonts
|
|
1661
|
-
}, {
|
|
1662
|
-
key: "parse",
|
|
1663
|
-
value: function parse(story) {
|
|
1664
|
-
var _this = this;
|
|
1665
|
-
if (story === null) {
|
|
1666
|
-
return story;
|
|
1667
|
-
}
|
|
1668
|
-
|
|
1669
|
-
// Extract fonts from screen
|
|
1670
|
-
var _ref3 = story || {},
|
|
1671
|
-
_ref3$theme = _ref3.theme,
|
|
1672
|
-
theme = _ref3$theme === void 0 ? null : _ref3$theme,
|
|
1673
|
-
_ref3$components = _ref3.components,
|
|
1674
|
-
components = _ref3$components === void 0 ? [] : _ref3$components;
|
|
1675
|
-
var fonts = uniq(components.reduce(function (currentFonts, screen) {
|
|
1676
|
-
var type = screen.type;
|
|
1677
|
-
var fieldsPattern = _this.getFieldsPatternByScreen(type);
|
|
1678
|
-
var newFonts = FontsParser.extractFontsWithPaths(screen, fieldsPattern);
|
|
1679
|
-
return newFonts.length > 0 ? [].concat(_toConsumableArray(currentFonts), _toConsumableArray(newFonts)) : currentFonts;
|
|
1680
|
-
}, []), 'name');
|
|
1681
|
-
|
|
1682
|
-
// Extract fonts from theme
|
|
1683
|
-
if (theme !== null) {
|
|
1684
|
-
var _this$parse = this.parse(theme),
|
|
1685
|
-
_this$parse$fonts = _this$parse.fonts,
|
|
1686
|
-
themeFonts = _this$parse$fonts === void 0 ? [] : _this$parse$fonts,
|
|
1687
|
-
newTheme = _objectWithoutProperties(_this$parse, _excluded$1);
|
|
1688
|
-
return fonts.length > 0 || themeFonts.length > 0 ? _objectSpread(_objectSpread({}, story), {}, {
|
|
1689
|
-
theme: newTheme,
|
|
1690
|
-
fonts: uniq([].concat(_toConsumableArray(themeFonts), _toConsumableArray(fonts)), 'name')
|
|
1691
|
-
}) : story;
|
|
1692
|
-
}
|
|
1693
|
-
return fonts.length > 0 ? _objectSpread(_objectSpread({}, story), {}, {
|
|
1694
|
-
fonts: fonts
|
|
1695
|
-
}) : story;
|
|
1696
|
-
}
|
|
1697
|
-
}, {
|
|
1698
|
-
key: "getFieldsPattern",
|
|
1699
|
-
value: function getFieldsPattern(fields) {
|
|
1700
|
-
var _this2 = this;
|
|
1701
|
-
var namePrefix = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : null;
|
|
1702
|
-
return fields.reduce(function (patterns, field) {
|
|
1703
|
-
var _field$name = field.name,
|
|
1704
|
-
name = _field$name === void 0 ? null : _field$name,
|
|
1705
|
-
_field$type = field.type,
|
|
1706
|
-
type = _field$type === void 0 ? null : _field$type;
|
|
1707
|
-
var path = [namePrefix, name].filter(function (it) {
|
|
1708
|
-
return it !== null;
|
|
1709
|
-
}).join('\\.');
|
|
1710
|
-
var fieldDefinition = _objectSpread(_objectSpread({}, type !== null ? _this2.fieldsManager.getDefinition(type) : null), field);
|
|
1711
|
-
|
|
1712
|
-
// also check settings fields
|
|
1713
|
-
var _fieldDefinition$fiel = fieldDefinition.fields,
|
|
1714
|
-
subFields = _fieldDefinition$fiel === void 0 ? [] : _fieldDefinition$fiel,
|
|
1715
|
-
_fieldDefinition$item = fieldDefinition.itemsField,
|
|
1716
|
-
itemsField = _fieldDefinition$item === void 0 ? null : _fieldDefinition$item,
|
|
1717
|
-
_fieldDefinition$sett = fieldDefinition.settings,
|
|
1718
|
-
settings = _fieldDefinition$sett === void 0 ? [] : _fieldDefinition$sett;
|
|
1719
|
-
return [].concat(_toConsumableArray(patterns), _toConsumableArray(FontsParser.fieldIsFontFamily(fieldDefinition) ? [new RegExp("^".concat(path, "$"))] : []), _toConsumableArray(_this2.getFieldsPattern(subFields, path)), _toConsumableArray(_this2.getFieldsPattern(settings, path)), _toConsumableArray(itemsField !== null ? _this2.getFieldsPattern([itemsField], "".concat(path, "\\.[0-9]+")) : []));
|
|
1720
|
-
}, []);
|
|
1721
|
-
}
|
|
1722
|
-
}], [{
|
|
1723
|
-
key: "fieldIsFontFamily",
|
|
1724
|
-
value: function fieldIsFontFamily(_ref4) {
|
|
1725
|
-
var _ref4$id = _ref4.id,
|
|
1726
|
-
id = _ref4$id === void 0 ? null : _ref4$id;
|
|
1727
|
-
return id === 'font-family';
|
|
1728
|
-
}
|
|
1729
|
-
}, {
|
|
1730
|
-
key: "valueIsFont",
|
|
1731
|
-
value: function valueIsFont(_ref5) {
|
|
1732
|
-
var _ref5$type = _ref5.type,
|
|
1733
|
-
type = _ref5$type === void 0 ? null : _ref5$type;
|
|
1734
|
-
return type === 'custom' || type === 'google';
|
|
1735
|
-
}
|
|
1736
|
-
}, {
|
|
1737
|
-
key: "extractFontsWithPaths",
|
|
1738
|
-
value: function extractFontsWithPaths(data, patterns) {
|
|
1739
|
-
var keyPrefix = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : null;
|
|
1740
|
-
var dataIsArray = isArray(data);
|
|
1741
|
-
var keys = dataIsArray ? _toConsumableArray(data.keys()) : Object.keys(data);
|
|
1742
|
-
return keys.reduce(function (currentFonts, key) {
|
|
1743
|
-
var path = [keyPrefix, key].filter(function (it) {
|
|
1744
|
-
return it !== null;
|
|
1745
|
-
}).join('.');
|
|
1746
|
-
var patternMatch = patterns.reduce(function (found, pattern) {
|
|
1747
|
-
return found || pattern.test(path);
|
|
1748
|
-
}, false);
|
|
1749
|
-
var value = data[key];
|
|
1750
|
-
var font = null;
|
|
1751
|
-
var subFonts = null;
|
|
1752
|
-
if (patternMatch && isObject(value) && FontsParser.valueIsFont(value)) {
|
|
1753
|
-
font = value;
|
|
1754
|
-
} else if (isObject(value) || isArray(value)) {
|
|
1755
|
-
subFonts = FontsParser.extractFontsWithPaths(value, patterns, path);
|
|
1756
|
-
}
|
|
1757
|
-
return subFonts !== null || font !== null ? [].concat(_toConsumableArray(currentFonts), _toConsumableArray(subFonts || []), _toConsumableArray(font !== null ? [font] : [])) : currentFonts;
|
|
1758
|
-
}, []);
|
|
1759
|
-
}
|
|
1760
|
-
}]);
|
|
1761
|
-
return FontsParser;
|
|
1762
|
-
}();
|
|
1763
|
-
|
|
1764
1833
|
var StoryParser = /*#__PURE__*/function () {
|
|
1765
1834
|
function StoryParser(_ref) {
|
|
1766
1835
|
var screensManager = _ref.screensManager,
|
|
@@ -1777,6 +1846,10 @@ var StoryParser = /*#__PURE__*/function () {
|
|
|
1777
1846
|
screensManager: screensManager,
|
|
1778
1847
|
fieldsManager: fieldsManager
|
|
1779
1848
|
});
|
|
1849
|
+
this.migrationsParser = new MigrationsParser({
|
|
1850
|
+
screensManager: screensManager,
|
|
1851
|
+
fieldsManager: fieldsManager
|
|
1852
|
+
});
|
|
1780
1853
|
}
|
|
1781
1854
|
_createClass(StoryParser, [{
|
|
1782
1855
|
key: "parse",
|
|
@@ -1788,7 +1861,9 @@ var StoryParser = /*#__PURE__*/function () {
|
|
|
1788
1861
|
_ref2$withMedias = _ref2.withMedias,
|
|
1789
1862
|
withMedias = _ref2$withMedias === void 0 ? true : _ref2$withMedias,
|
|
1790
1863
|
_ref2$withFonts = _ref2.withFonts,
|
|
1791
|
-
withFonts = _ref2$withFonts === void 0 ? true : _ref2$withFonts
|
|
1864
|
+
withFonts = _ref2$withFonts === void 0 ? true : _ref2$withFonts,
|
|
1865
|
+
_ref2$withMigrations = _ref2.withMigrations,
|
|
1866
|
+
withMigrations = _ref2$withMigrations === void 0 ? true : _ref2$withMigrations;
|
|
1792
1867
|
if (story === null) {
|
|
1793
1868
|
return story;
|
|
1794
1869
|
}
|
|
@@ -1798,6 +1873,8 @@ var StoryParser = /*#__PURE__*/function () {
|
|
|
1798
1873
|
return _this.themeParser.parse(newStory);
|
|
1799
1874
|
}], [withFonts, function (newStory) {
|
|
1800
1875
|
return _this.fontsParser.parse(newStory);
|
|
1876
|
+
}], [withMigrations, function (newStory) {
|
|
1877
|
+
return _this.migrationsParser.parse(newStory);
|
|
1801
1878
|
}]];
|
|
1802
1879
|
return parsers.reduce(function (parsedStory, _ref3) {
|
|
1803
1880
|
var _ref4 = _slicedToArray(_ref3, 2),
|
package/es/utils.js
CHANGED
|
@@ -3,7 +3,7 @@ import { paramCase } from 'param-case';
|
|
|
3
3
|
import _regeneratorRuntime from '@babel/runtime/helpers/regeneratorRuntime';
|
|
4
4
|
import _asyncToGenerator from '@babel/runtime/helpers/asyncToGenerator';
|
|
5
5
|
import isObject from 'lodash/isObject';
|
|
6
|
-
import { useEffect } from 'react';
|
|
6
|
+
import { useEffect, useMemo } from 'react';
|
|
7
7
|
import isString from 'lodash/isString';
|
|
8
8
|
import tinycolor from 'tinycolor2';
|
|
9
9
|
import { pascalCase, paramCase as paramCase$1, snakeCase } from 'change-case';
|
|
@@ -393,6 +393,40 @@ var getFontFamily = function getFontFamily(value) {
|
|
|
393
393
|
}).join(', ');
|
|
394
394
|
};
|
|
395
395
|
|
|
396
|
+
var _excluded$1 = ["isPreview", "isView", "current", "openWebView", "enableInteraction", "disableInteraction"];
|
|
397
|
+
var getFooterProps = function getFooterProps() {
|
|
398
|
+
var footer = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
|
|
399
|
+
var _ref = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {},
|
|
400
|
+
_ref$isPreview = _ref.isPreview,
|
|
401
|
+
isPreview = _ref$isPreview === void 0 ? false : _ref$isPreview,
|
|
402
|
+
_ref$isView = _ref.isView,
|
|
403
|
+
isView = _ref$isView === void 0 ? false : _ref$isView,
|
|
404
|
+
_ref$current = _ref.current,
|
|
405
|
+
current = _ref$current === void 0 ? false : _ref$current,
|
|
406
|
+
_ref$openWebView = _ref.openWebView,
|
|
407
|
+
openWebView = _ref$openWebView === void 0 ? false : _ref$openWebView,
|
|
408
|
+
_ref$enableInteractio = _ref.enableInteraction,
|
|
409
|
+
enableInteraction = _ref$enableInteractio === void 0 ? true : _ref$enableInteractio,
|
|
410
|
+
_ref$disableInteracti = _ref.disableInteraction,
|
|
411
|
+
disableInteraction = _ref$disableInteracti === void 0 ? false : _ref$disableInteracti,
|
|
412
|
+
otherProps = _objectWithoutProperties(_ref, _excluded$1);
|
|
413
|
+
var _ref2 = footer || {},
|
|
414
|
+
_ref2$callToAction = _ref2.callToAction,
|
|
415
|
+
callToAction = _ref2$callToAction === void 0 ? null : _ref2$callToAction;
|
|
416
|
+
var footerProps = useMemo(function () {
|
|
417
|
+
return {
|
|
418
|
+
callToAction: _objectSpread(_objectSpread({}, callToAction), {}, {
|
|
419
|
+
animationDisabled: isPreview,
|
|
420
|
+
focusable: current && isView,
|
|
421
|
+
openWebView: openWebView,
|
|
422
|
+
enableInteraction: enableInteraction,
|
|
423
|
+
disableInteraction: disableInteraction
|
|
424
|
+
}, otherProps)
|
|
425
|
+
};
|
|
426
|
+
}, [callToAction, isPreview, isView, current, enableInteraction, disableInteraction, otherProps]);
|
|
427
|
+
return footerProps;
|
|
428
|
+
};
|
|
429
|
+
|
|
396
430
|
var getGridLayoutName = function getGridLayoutName(layout) {
|
|
397
431
|
return layout.map(function (it) {
|
|
398
432
|
return "".concat(it.rows, "_").concat(it.columns.join('_'));
|
|
@@ -912,6 +946,38 @@ var getLayoutParts = function getLayoutParts() {
|
|
|
912
946
|
};
|
|
913
947
|
};
|
|
914
948
|
|
|
949
|
+
var isHeaderFilled = function isHeaderFilled() {
|
|
950
|
+
var header = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
|
|
951
|
+
var _ref = header || {},
|
|
952
|
+
_ref$badge = _ref.badge,
|
|
953
|
+
badge = _ref$badge === void 0 ? null : _ref$badge;
|
|
954
|
+
var _ref2 = badge || {},
|
|
955
|
+
_ref2$active = _ref2.active,
|
|
956
|
+
badgeActive = _ref2$active === void 0 ? false : _ref2$active,
|
|
957
|
+
_ref2$label = _ref2.label,
|
|
958
|
+
label = _ref2$label === void 0 ? null : _ref2$label;
|
|
959
|
+
var _ref3 = label || {},
|
|
960
|
+
_ref3$body = _ref3.body,
|
|
961
|
+
body = _ref3$body === void 0 ? null : _ref3$body;
|
|
962
|
+
return badgeActive && body !== null;
|
|
963
|
+
};
|
|
964
|
+
|
|
965
|
+
var isFooterFilled = function isFooterFilled() {
|
|
966
|
+
var footer = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
|
|
967
|
+
var _ref = footer || {},
|
|
968
|
+
_ref$callToAction = _ref.callToAction,
|
|
969
|
+
callToAction = _ref$callToAction === void 0 ? null : _ref$callToAction;
|
|
970
|
+
var _ref2 = callToAction || {},
|
|
971
|
+
_ref2$active = _ref2.active,
|
|
972
|
+
callToActionActive = _ref2$active === void 0 ? false : _ref2$active,
|
|
973
|
+
_ref2$label = _ref2.label,
|
|
974
|
+
label = _ref2$label === void 0 ? null : _ref2$label;
|
|
975
|
+
var _ref3 = label || {},
|
|
976
|
+
_ref3$body = _ref3.body,
|
|
977
|
+
body = _ref3$body === void 0 ? null : _ref3$body;
|
|
978
|
+
return callToActionActive && body !== null;
|
|
979
|
+
};
|
|
980
|
+
|
|
915
981
|
var isMessage = function isMessage(message) {
|
|
916
982
|
return isObject(message) && typeof message.defaultMessage !== 'undefined';
|
|
917
983
|
};
|
|
@@ -1043,4 +1109,4 @@ var getContrastingColor = function getContrastingColor(backgroundColor) {
|
|
|
1043
1109
|
return tinycolor(color).spin(30).toString();
|
|
1044
1110
|
};
|
|
1045
1111
|
|
|
1046
|
-
export { convertStyleToString, copyToClipboard, createNullableOnChange, createUseEvent, easings, getColorAsString, getComponentFromName, getContrastingColor, getDeviceScreens, getDisplayName, getFieldByName, getFieldFromPath, getFileName, getFontFamily as getFontFamilyFromFont, getGridLayoutName, largestRemainderRound as getLargestRemainderRound, getLayersFromBackground, getLayoutParts, getMediaFilesAsArray, getOptimalImageUrl, getScreenExtraField, getSecondsFromTime, getShadowCoords, getStyleFromAlignment, getStyleFromBorder, getStyleFromBox, getStyleFromColor, getStyleFromContainer, getStyleFromHighlight, getStyleFromImage, getStyleFromLink, getStyleFromMargin, getStyleFromText, getVideoSupportedMimes, isImageFilled, isIos, isTextFilled$1 as isLabelFilled, isMessage, isTextFilled, isValidUrl, schemaId, setValue as setFieldValue, slug, unique, validateFields };
|
|
1112
|
+
export { convertStyleToString, copyToClipboard, createNullableOnChange, createUseEvent, easings, getColorAsString, getComponentFromName, getContrastingColor, getDeviceScreens, getDisplayName, getFieldByName, getFieldFromPath, getFileName, getFontFamily as getFontFamilyFromFont, getFooterProps, getGridLayoutName, largestRemainderRound as getLargestRemainderRound, getLayersFromBackground, getLayoutParts, getMediaFilesAsArray, getOptimalImageUrl, getScreenExtraField, getSecondsFromTime, getShadowCoords, getStyleFromAlignment, getStyleFromBorder, getStyleFromBox, getStyleFromColor, getStyleFromContainer, getStyleFromHighlight, getStyleFromImage, getStyleFromLink, getStyleFromMargin, getStyleFromText, getVideoSupportedMimes, isFooterFilled, isHeaderFilled, isImageFilled, isIos, isTextFilled$1 as isLabelFilled, isMessage, isTextFilled, isValidUrl, schemaId, setValue as setFieldValue, slug, unique, validateFields };
|