@contentful/experiences-core 3.8.3 → 3.8.4-beta.1
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/cjs/index.cjs +46 -34
- package/dist/cjs/index.cjs.map +1 -1
- package/dist/esm/index.js +46 -34
- package/dist/esm/index.js.map +1 -1
- package/package.json +3 -3
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
|
-
|
|
2842
|
-
|
|
2843
|
-
|
|
2844
|
-
|
|
2845
|
-
|
|
2846
|
-
|
|
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
|
|
2855
|
-
const { width, style, color } =
|
|
2857
|
+
if (typeof value === 'object') {
|
|
2858
|
+
const { width, style, color } = value;
|
|
2856
2859
|
return `${width} ${style} ${color}`;
|
|
2857
2860
|
}
|
|
2858
2861
|
}
|
|
2859
|
-
return
|
|
2860
|
-
}
|
|
2861
|
-
|
|
2862
|
-
|
|
2863
|
-
|
|
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 {
|
|
@@ -2924,6 +2919,11 @@ const resolveBackgroundImageBinding = ({ variableData, getBoundEntityById, dataS
|
|
|
2924
2919
|
// '/lUERH7tX7nJTaPX6f0udB/fields/assetReference/~locale/fields/file/~locale'
|
|
2925
2920
|
const [, uuid] = variableData.path.split('/');
|
|
2926
2921
|
const binding = dataSource[uuid];
|
|
2922
|
+
// Safeguard against edge cases - we should not have bound style values that do not have a data source entry.
|
|
2923
|
+
// However, just in case, we handle it here as empty and allow the user to replace without errors.
|
|
2924
|
+
if (!binding) {
|
|
2925
|
+
return;
|
|
2926
|
+
}
|
|
2927
2927
|
const boundEntity = getBoundEntityById(binding.sys.id);
|
|
2928
2928
|
if (!boundEntity) {
|
|
2929
2929
|
return;
|
|
@@ -3090,18 +3090,30 @@ const indexByBreakpoint = ({ variables, breakpointIds, getBoundEntityById, unbou
|
|
|
3090
3090
|
* `{ 'color.key': [value] }`
|
|
3091
3091
|
*/
|
|
3092
3092
|
const flattenDesignTokenRegistry = (designTokenRegistry) => {
|
|
3093
|
-
|
|
3094
|
-
|
|
3095
|
-
|
|
3096
|
-
|
|
3097
|
-
|
|
3098
|
-
|
|
3093
|
+
const flattenObject = (obj, prefix = '') => {
|
|
3094
|
+
return Object.entries(obj).reduce((acc, [key, value]) => {
|
|
3095
|
+
const newKey = prefix ? `${prefix}.${key}` : key;
|
|
3096
|
+
if (value &&
|
|
3097
|
+
typeof value === 'object' &&
|
|
3098
|
+
!Array.isArray(value) &&
|
|
3099
|
+
// handle border types
|
|
3100
|
+
!(typeof value === 'object' && ('width' in value || 'style' in value || 'color' in value))) {
|
|
3101
|
+
// Recursively flatten nested objects, but skip objects that look like border definitions
|
|
3102
|
+
return {
|
|
3103
|
+
...acc,
|
|
3104
|
+
...flattenObject(value, newKey),
|
|
3105
|
+
};
|
|
3106
|
+
}
|
|
3107
|
+
else {
|
|
3108
|
+
// This is a leaf value (string, number, or border object)
|
|
3109
|
+
return {
|
|
3110
|
+
...acc,
|
|
3111
|
+
[newKey]: value,
|
|
3112
|
+
};
|
|
3113
|
+
}
|
|
3099
3114
|
}, {});
|
|
3100
|
-
|
|
3101
|
-
|
|
3102
|
-
...tokensWithCategory,
|
|
3103
|
-
};
|
|
3104
|
-
}, {});
|
|
3115
|
+
};
|
|
3116
|
+
return flattenObject(designTokenRegistry);
|
|
3105
3117
|
};
|
|
3106
3118
|
function mergeDefaultAndOverwriteValues(defaultValue, overwriteValue) {
|
|
3107
3119
|
if (defaultValue?.type === 'DesignValue' && overwriteValue?.type === 'DesignValue') {
|