@contentful/experiences-core 1.11.2-dev-20240730T1241-81b30e6.0 → 1.11.2-dev-20240731T1935-8ed41a3.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
@@ -1448,7 +1448,7 @@ const detachExperienceStyles = (experience) => {
1448
1448
  }, {});
1449
1449
  // getting the breakpoint ids
1450
1450
  const breakpointIds = Object.keys(mediaQueriesTemplate);
1451
- const iterateOverTreeAndExtractStyles = ({ componentTree, dataSource, unboundValues, componentSettings, componentVariablesOverwrites, }) => {
1451
+ const iterateOverTreeAndExtractStyles = ({ componentTree, dataSource, unboundValues, componentSettings, componentVariablesOverwrites, patternWrapper, }) => {
1452
1452
  // traversing the tree
1453
1453
  const queue = [];
1454
1454
  queue.push(...componentTree.children);
@@ -1503,6 +1503,8 @@ const detachExperienceStyles = (experience) => {
1503
1503
  // and this is where the over-writes for the default values are stored
1504
1504
  // yes, I know, it's a bit confusing
1505
1505
  componentVariablesOverwrites: currentNode.variables,
1506
+ // pass top-level pattern node to store instance-specific child styles for rendering
1507
+ patternWrapper: currentNode,
1506
1508
  });
1507
1509
  continue;
1508
1510
  }
@@ -1630,12 +1632,29 @@ const detachExperienceStyles = (experience) => {
1630
1632
  // className3 will win over className2 and className1
1631
1633
  // making sure that we respect the order of breakpoints from
1632
1634
  // we can achieve "desktop first" or "mobile first" approach to style over-writes
1633
- currentNode.variables.cfSsrClassName = {
1634
- type: 'DesignValue',
1635
- valuesByBreakpoint: {
1636
- [breakpointIds[0]]: currentNodeClassNames.join(' '),
1637
- },
1638
- };
1635
+ if (patternWrapper) {
1636
+ // @ts-expect-error -- temporarily add node ID to pick up the className during rendering in CompositionBlock
1637
+ currentNode.id = currentNode.id ?? generateRandomId(15);
1638
+ // @ts-expect-error -- valueByBreakpoint is not explicitly defined, but it's already defined in the patternWrapper styles
1639
+ patternWrapper.variables.cfSsrClassName = {
1640
+ ...(patternWrapper.variables.cfSsrClassName ?? {}),
1641
+ type: 'DesignValue',
1642
+ // @ts-expect-error -- id is not defined in ComponentTreeNode type
1643
+ [currentNode.id]: {
1644
+ valuesByBreakpoint: {
1645
+ [breakpointIds[0]]: currentNodeClassNames.join(' '),
1646
+ },
1647
+ },
1648
+ };
1649
+ }
1650
+ else {
1651
+ currentNode.variables.cfSsrClassName = {
1652
+ type: 'DesignValue',
1653
+ valuesByBreakpoint: {
1654
+ [breakpointIds[0]]: currentNodeClassNames.join(' '),
1655
+ },
1656
+ };
1657
+ }
1639
1658
  queue.push(...currentNode.children);
1640
1659
  }
1641
1660
  };
@@ -1787,10 +1806,19 @@ const indexByBreakpoint = ({ variables, breakpointIds, getBoundEntityById, unbou
1787
1806
  }
1788
1807
  continue;
1789
1808
  }
1790
- if (variableData.type !== 'DesignValue') {
1809
+ let resolvedVariableData = variableData;
1810
+ if (variableData.type === 'ComponentValue') {
1811
+ const variableDefinition = componentSettings?.variableDefinitions[variableData.key];
1812
+ if (variableDefinition.group === 'style' && variableDefinition.defaultValue !== undefined) {
1813
+ const overrideVariableData = componentVariablesOverwrites?.[variableData.key];
1814
+ resolvedVariableData =
1815
+ overrideVariableData || variableDefinition.defaultValue;
1816
+ }
1817
+ }
1818
+ if (resolvedVariableData.type !== 'DesignValue') {
1791
1819
  continue;
1792
1820
  }
1793
- for (const [breakpointId, variableValue] of Object.entries(variableData.valuesByBreakpoint)) {
1821
+ for (const [breakpointId, variableValue] of Object.entries(resolvedVariableData.valuesByBreakpoint)) {
1794
1822
  if (!variableValue) {
1795
1823
  continue;
1796
1824
  }