@contentful/experiences-core 3.8.3 → 3.8.4-dev-20251024T1213-2c026d6.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/esm/index.js CHANGED
@@ -2838,37 +2838,32 @@ const maybePopulateDesignTokenValue = (variableName, variableValue, mapOfDesignV
2838
2838
  if (!isCfStyleAttribute(variableName)) {
2839
2839
  return variableValue;
2840
2840
  }
2841
- const resolveSimpleDesignToken = (variableName, variableValue) => {
2842
- const nonTemplateDesignTokenValue = variableValue.replace(templateStringRegex, '$1');
2843
- const tokenValue = mapOfDesignVariableKeys[nonTemplateDesignTokenValue];
2844
- if (!tokenValue) {
2845
- if (builtInStyles[variableName]) {
2846
- return builtInStyles[variableName].defaultValue;
2841
+ // matches ${...} and captures the content between ${ and }
2842
+ // ${color.Blue}, ${spacing.Sizes.Large} or ${border.Text Heading.Small}
2843
+ const templateStringRegex = /\$\{(\w[^}]*)}/g;
2844
+ const result = variableValue
2845
+ .replace(templateStringRegex, (_, rawKey) => {
2846
+ const value = mapOfDesignVariableKeys[rawKey];
2847
+ if (!value) {
2848
+ if (builtInStyles[variableName]?.defaultValue) {
2849
+ return String(builtInStyles[variableName].defaultValue);
2847
2850
  }
2848
- if (optionalBuiltInStyles[variableName]) {
2849
- return optionalBuiltInStyles[variableName].defaultValue;
2851
+ if (optionalBuiltInStyles[variableName]?.defaultValue) {
2852
+ return String(optionalBuiltInStyles[variableName].defaultValue);
2850
2853
  }
2851
2854
  return '0px';
2852
2855
  }
2853
2856
  if (variableName === 'cfBorder' || variableName.startsWith('cfBorder_')) {
2854
- if (typeof tokenValue === 'object') {
2855
- const { width, style, color } = tokenValue;
2857
+ if (typeof value === 'object') {
2858
+ const { width, style, color } = value;
2856
2859
  return `${width} ${style} ${color}`;
2857
2860
  }
2858
2861
  }
2859
- return tokenValue;
2860
- };
2861
- const templateStringRegex = /\${(.+?)}/g;
2862
- const parts = variableValue.split(' ');
2863
- let resolvedValue = '';
2864
- for (const part of parts) {
2865
- const tokenValue = templateStringRegex.test(part)
2866
- ? resolveSimpleDesignToken(variableName, part)
2867
- : part;
2868
- resolvedValue += `${tokenValue} `;
2869
- }
2870
- // Not trimming would end up with a trailing space that breaks the check in `calculateNodeDefaultHeight`
2871
- return resolvedValue.trim();
2862
+ return String(value);
2863
+ })
2864
+ // Replace all multiple spaces with a single space
2865
+ .replace(/ +/g, ' ');
2866
+ return result;
2872
2867
  };
2873
2868
  const transformMedia$1 = (boundAsset, width, options) => {
2874
2869
  try {
@@ -3090,18 +3085,30 @@ const indexByBreakpoint = ({ variables, breakpointIds, getBoundEntityById, unbou
3090
3085
  * `{ 'color.key': [value] }`
3091
3086
  */
3092
3087
  const flattenDesignTokenRegistry = (designTokenRegistry) => {
3093
- return Object.entries(designTokenRegistry).reduce((acc, [categoryName, tokenCategory]) => {
3094
- const tokensWithCategory = Object.entries(tokenCategory).reduce((acc, [tokenName, tokenValue]) => {
3095
- return {
3096
- ...acc,
3097
- [`${categoryName}.${tokenName}`]: tokenValue,
3098
- };
3088
+ const flattenObject = (obj, prefix = '') => {
3089
+ return Object.entries(obj).reduce((acc, [key, value]) => {
3090
+ const newKey = prefix ? `${prefix}.${key}` : key;
3091
+ if (value &&
3092
+ typeof value === 'object' &&
3093
+ !Array.isArray(value) &&
3094
+ // handle border types
3095
+ !(typeof value === 'object' && ('width' in value || 'style' in value || 'color' in value))) {
3096
+ // Recursively flatten nested objects, but skip objects that look like border definitions
3097
+ return {
3098
+ ...acc,
3099
+ ...flattenObject(value, newKey),
3100
+ };
3101
+ }
3102
+ else {
3103
+ // This is a leaf value (string, number, or border object)
3104
+ return {
3105
+ ...acc,
3106
+ [newKey]: value,
3107
+ };
3108
+ }
3099
3109
  }, {});
3100
- return {
3101
- ...acc,
3102
- ...tokensWithCategory,
3103
- };
3104
- }, {});
3110
+ };
3111
+ return flattenObject(designTokenRegistry);
3105
3112
  };
3106
3113
  function mergeDefaultAndOverwriteValues(defaultValue, overwriteValue) {
3107
3114
  if (defaultValue?.type === 'DesignValue' && overwriteValue?.type === 'DesignValue') {