@contentful/experiences-components-react 3.4.0 → 3.4.1-dev-20250901T1330-2519e19.0

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/dist/index.js CHANGED
@@ -1624,19 +1624,22 @@ const checkLocalStorageAvailability = () => {
1624
1624
  return false;
1625
1625
  }
1626
1626
  };
1627
+ const DEBUG_LEVELS_HIERARCHY = ['error', 'warn', 'log', 'debug'];
1627
1628
  class DebugLogger {
1628
1629
  constructor() {
1630
+ this.activeLevel = 'warn';
1629
1631
  // Public methods for logging
1630
1632
  this.error = this.logger('error');
1631
1633
  this.warn = this.logger('warn');
1632
1634
  this.log = this.logger('log');
1633
1635
  this.debug = this.logger('debug');
1634
1636
  if (!checkLocalStorageAvailability()) {
1635
- this.enabled = false;
1636
1637
  return;
1637
1638
  }
1638
1639
  // Default to checking localStorage for the debug mode on initialization if in browser
1639
- this.enabled = localStorage.getItem(CF_DEBUG_KEY) === 'true';
1640
+ if (localStorage.getItem(CF_DEBUG_KEY) === 'true') {
1641
+ this.activeLevel = 'debug';
1642
+ }
1640
1643
  }
1641
1644
  static getInstance() {
1642
1645
  if (this.instance === null) {
@@ -1644,15 +1647,15 @@ class DebugLogger {
1644
1647
  }
1645
1648
  return this.instance;
1646
1649
  }
1647
- getEnabled() {
1648
- return this.enabled;
1650
+ getActiveLevel() {
1651
+ return this.activeLevel;
1649
1652
  }
1650
- setEnabled(enabled) {
1651
- this.enabled = enabled;
1652
- if (typeof localStorage === 'undefined') {
1653
+ setActiveLevel(level) {
1654
+ this.activeLevel = level;
1655
+ if (!checkLocalStorageAvailability()) {
1653
1656
  return;
1654
1657
  }
1655
- if (enabled) {
1658
+ if (this.activeLevel === 'debug' || this.activeLevel === 'log') {
1656
1659
  localStorage.setItem(CF_DEBUG_KEY, 'true');
1657
1660
  }
1658
1661
  else {
@@ -1662,23 +1665,26 @@ class DebugLogger {
1662
1665
  // Log method for different levels (error, warn, log)
1663
1666
  logger(level) {
1664
1667
  return (...args) => {
1665
- if (this.enabled) {
1666
- console[level]('[cf-experiences-sdk]', ...args);
1668
+ const levelPriority = DEBUG_LEVELS_HIERARCHY.indexOf(level);
1669
+ const activeLevelPriority = DEBUG_LEVELS_HIERARCHY.indexOf(this.activeLevel);
1670
+ const enabled = levelPriority <= activeLevelPriority;
1671
+ if (enabled) {
1672
+ console[level](...args);
1667
1673
  }
1668
1674
  };
1669
1675
  }
1670
1676
  }
1671
1677
  DebugLogger.instance = null;
1672
- DebugLogger.getInstance();
1678
+ const debug = DebugLogger.getInstance();
1673
1679
 
1674
- const isLink = (maybeLink) => {
1680
+ function isLink(maybeLink) {
1675
1681
  if (maybeLink === null)
1676
1682
  return false;
1677
1683
  if (typeof maybeLink !== 'object')
1678
1684
  return false;
1679
1685
  const link = maybeLink;
1680
1686
  return Boolean(link.sys?.id) && link.sys?.type === 'Link' && Boolean(link.sys?.linkType);
1681
- };
1687
+ }
1682
1688
  const parseDataSourcePathIntoFieldset = (path) => {
1683
1689
  const parsedPath = parseDeepPath(path);
1684
1690
  if (null === parsedPath) {
@@ -1835,7 +1841,7 @@ class EntityStoreBase {
1835
1841
  ? this.entryMap.get(linkOrEntryOrAsset.sys.id)
1836
1842
  : this.assetMap.get(linkOrEntryOrAsset.sys.id);
1837
1843
  if (!resolvedEntity || resolvedEntity.sys.type !== linkOrEntryOrAsset.sys.linkType) {
1838
- console.warn(`Experience references unresolved entity: ${JSON.stringify(linkOrEntryOrAsset)}`);
1844
+ debug.warn(`[experiences-core::EntityStoreBase] Experience references unresolved entity: ${JSON.stringify(linkOrEntryOrAsset)}`);
1839
1845
  return;
1840
1846
  }
1841
1847
  entity = resolvedEntity;
@@ -1845,7 +1851,7 @@ class EntityStoreBase {
1845
1851
  entity = linkOrEntryOrAsset;
1846
1852
  }
1847
1853
  else {
1848
- throw new Error(`Unexpected object when resolving entity: ${JSON.stringify(linkOrEntryOrAsset)}`);
1854
+ throw new Error(`[experiences-core::EntityStoreBase] Unexpected object when resolving entity: ${JSON.stringify(linkOrEntryOrAsset)}`);
1849
1855
  }
1850
1856
  return entity;
1851
1857
  }
@@ -1859,7 +1865,7 @@ class EntityStoreBase {
1859
1865
  const entity = this.getEntity(entityLink.sys.linkType, entityLink.sys.id);
1860
1866
  if (!entity) {
1861
1867
  // TODO: move to `debug` utils once it is extracted
1862
- console.warn(`Unresolved entity reference: ${entityLink.sys.linkType} with ID ${entityLink.sys.id}`);
1868
+ debug.warn(`Unresolved entity reference: ${entityLink.sys.linkType} with ID ${entityLink.sys.id}`);
1863
1869
  return;
1864
1870
  }
1865
1871
  return get(entity, path);
@@ -1869,7 +1875,7 @@ class EntityStoreBase {
1869
1875
  ? this.entryMap.get(link.sys.id)
1870
1876
  : this.assetMap.get(link.sys.id);
1871
1877
  if (!resolvedEntity || resolvedEntity.sys.type !== link.sys.linkType) {
1872
- console.warn(`Experience references unresolved entity: ${JSON.stringify(link)}`);
1878
+ debug.warn(`[experiences-core::EntityStoreBase] Experience references unresolved entity: ${JSON.stringify(link)}`);
1873
1879
  return;
1874
1880
  }
1875
1881
  return resolvedEntity;
@@ -1877,7 +1883,7 @@ class EntityStoreBase {
1877
1883
  getAssetById(assetId) {
1878
1884
  const asset = this.assetMap.get(assetId);
1879
1885
  if (!asset) {
1880
- console.warn(`Asset with ID "${assetId}" is not found in the store`);
1886
+ debug.warn(`[experiences-core::EntityStoreBase] Asset with ID "${assetId}" is not found in the store`);
1881
1887
  return;
1882
1888
  }
1883
1889
  return asset;
@@ -1885,7 +1891,7 @@ class EntityStoreBase {
1885
1891
  getEntryById(entryId) {
1886
1892
  const entry = this.entryMap.get(entryId);
1887
1893
  if (!entry) {
1888
- console.warn(`Entry with ID "${entryId}" is not found in the store`);
1894
+ debug.warn(`[experiences-core::EntityStoreBase] Entry with ID "${entryId}" is not found in the store`);
1889
1895
  return;
1890
1896
  }
1891
1897
  return entry;
@@ -1924,7 +1930,7 @@ class EntityStoreBase {
1924
1930
  const { resolved, missing } = this.getEntitiesFromMap('Asset', [id]);
1925
1931
  if (missing.length) {
1926
1932
  // TODO: move to `debug` utils once it is extracted
1927
- console.warn(`Asset "${id}" is not in the store`);
1933
+ debug.warn(`[experiences-core::EntityStoreBase] Asset "${id}" is not in the store`);
1928
1934
  return;
1929
1935
  }
1930
1936
  return resolved[0];
@@ -1940,7 +1946,7 @@ class EntityStoreBase {
1940
1946
  const { resolved, missing } = this.getEntitiesFromMap('Entry', [id]);
1941
1947
  if (missing.length) {
1942
1948
  // TODO: move to `debug` utils once it is extracted
1943
- console.warn(`Entry "${id}" is not in the store`);
1949
+ debug.warn(`[experiences-core::EntityStoreBase] Entry "${id}" is not in the store`);
1944
1950
  return;
1945
1951
  }
1946
1952
  return resolved[0];
@@ -2016,8 +2022,9 @@ class EntityStoreBase {
2016
2022
  // in case we can't follow till the end, we should signal that there was null-reference in the path
2017
2023
  const { resolvedFieldset, isFullyResolved, reason } = resolveFieldset(unresolvedFieldset, headEntity);
2018
2024
  if (!isFullyResolved) {
2019
- reason &&
2020
- console.debug(`[exp-builder.sdk::EntityStoreBased::getValueDeep()] Deep path wasn't resolved till leaf node, falling back to undefined, because: ${reason}`);
2025
+ if (reason) {
2026
+ debug.log(`[experiences-core::EntityStoreBase] Deep path wasn't resolved till leaf node, falling back to undefined, because: ${reason}`);
2027
+ }
2021
2028
  return;
2022
2029
  }
2023
2030
  const [leafEntity] = resolvedFieldset[resolvedFieldset.length - 1];
@@ -2138,7 +2145,8 @@ const stopEventPropagation = (event) => {
2138
2145
 
2139
2146
  /* eslint-disable */
2140
2147
  const ContentfulContainer = (props) => {
2141
- const { className, editorMode, children, cfHyperlink, ...otherProps } = props;
2148
+ // Extract hyperlink-related props to not pass them to the regular container
2149
+ const { className, editorMode, children, cfHyperlink, cfOpenInNewTab, ...otherProps } = props;
2142
2150
  if (cfHyperlink) {
2143
2151
  return React.createElement(ContentfulContainerAsHyperlink, { ...props }, children);
2144
2152
  }