@contentful/experiences-sdk-react 1.4.0 → 1.4.1-dev-20240516T1930-07eee5f.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 +64 -1
- package/dist/index.js.map +1 -1
- package/dist/src/sdkVersion.d.ts +1 -1
- package/package.json +5 -5
package/dist/index.js
CHANGED
|
@@ -10,7 +10,7 @@ import { ContentfulContainer, Columns, SingleColumn } from '@contentful/experien
|
|
|
10
10
|
import styleInject from 'style-inject';
|
|
11
11
|
import md5 from 'md5';
|
|
12
12
|
|
|
13
|
-
const SDK_VERSION = '1.4.0
|
|
13
|
+
const SDK_VERSION = '1.4.0';
|
|
14
14
|
|
|
15
15
|
var util;
|
|
16
16
|
(function (util) {
|
|
@@ -4380,6 +4380,7 @@ function withComponentWrapper(Component, options = {
|
|
|
4380
4380
|
// this is the array of version which currently LATEST_SCHEMA_VERSION is compatible with
|
|
4381
4381
|
const compatibleVersions = ['2023-09-28'];
|
|
4382
4382
|
|
|
4383
|
+
const CssVarRegex = /var\(--[\w-]+\)/;
|
|
4383
4384
|
const cloneObject = (targetObject) => {
|
|
4384
4385
|
if (typeof structuredClone !== 'undefined') {
|
|
4385
4386
|
return structuredClone(targetObject);
|
|
@@ -4522,6 +4523,67 @@ const runRegisteredComponentValidations = () => {
|
|
|
4522
4523
|
}
|
|
4523
4524
|
});
|
|
4524
4525
|
};
|
|
4526
|
+
const getSingleCssVariableValue = (element, cssVariableValue, cssAttribute) => {
|
|
4527
|
+
element.style[cssAttribute] = cssVariableValue;
|
|
4528
|
+
const styles = getComputedStyle(element);
|
|
4529
|
+
const resolvedValue = styles.getPropertyValue(cssAttribute);
|
|
4530
|
+
return resolvedValue;
|
|
4531
|
+
};
|
|
4532
|
+
const getAllCssVariableValues = (element, cssVariable, cssAttribute) => {
|
|
4533
|
+
const resolvedCssVariables = {};
|
|
4534
|
+
Object.keys(cssVariable).forEach((key) => {
|
|
4535
|
+
const cssVariableValue = cssVariable[key];
|
|
4536
|
+
if (CssVarRegex.test(cssVariableValue)) {
|
|
4537
|
+
const resolvedValue = getSingleCssVariableValue(element, cssVariableValue, cssAttribute);
|
|
4538
|
+
resolvedCssVariables[cssVariableValue] = resolvedValue;
|
|
4539
|
+
}
|
|
4540
|
+
});
|
|
4541
|
+
return resolvedCssVariables;
|
|
4542
|
+
};
|
|
4543
|
+
const resolveCssVariables = (designTokensDefinition) => {
|
|
4544
|
+
const { spacing, sizing, color, borderRadius, fontSize, lineHeight, letterSpacing, textColor, border, } = designTokensDefinition;
|
|
4545
|
+
const resolvedCssVariables = {};
|
|
4546
|
+
// Create an element
|
|
4547
|
+
const element = document.createElement('div');
|
|
4548
|
+
document.body.appendChild(element);
|
|
4549
|
+
const cssProperties = [
|
|
4550
|
+
{ variable: spacing, property: 'margin' },
|
|
4551
|
+
{ variable: sizing, property: 'width' },
|
|
4552
|
+
{ variable: color, property: 'background-color' },
|
|
4553
|
+
{ variable: borderRadius, property: 'border-radius' },
|
|
4554
|
+
{ variable: fontSize, property: 'font-size' },
|
|
4555
|
+
{ variable: lineHeight, property: 'line-height' },
|
|
4556
|
+
{ variable: letterSpacing, property: 'letter-spacing' },
|
|
4557
|
+
{ variable: textColor, property: 'color' },
|
|
4558
|
+
];
|
|
4559
|
+
cssProperties.forEach(({ variable, property }) => {
|
|
4560
|
+
if (variable) {
|
|
4561
|
+
const rawResolvedValues = getAllCssVariableValues(element, variable, property);
|
|
4562
|
+
Object.assign(resolvedCssVariables, rawResolvedValues);
|
|
4563
|
+
}
|
|
4564
|
+
});
|
|
4565
|
+
if (border) {
|
|
4566
|
+
const tempResolvedValue = {};
|
|
4567
|
+
Object.keys(border).forEach((borderKey) => {
|
|
4568
|
+
const { width, style, color } = border[borderKey];
|
|
4569
|
+
if (CssVarRegex.test(width)) {
|
|
4570
|
+
const resolvedValue = getSingleCssVariableValue(element, width, 'border-width');
|
|
4571
|
+
tempResolvedValue[width] = resolvedValue;
|
|
4572
|
+
}
|
|
4573
|
+
if (CssVarRegex.test(style)) {
|
|
4574
|
+
const resolvedValue = getSingleCssVariableValue(element, style, 'border-style');
|
|
4575
|
+
tempResolvedValue[style] = resolvedValue;
|
|
4576
|
+
}
|
|
4577
|
+
if (CssVarRegex.test(color)) {
|
|
4578
|
+
const resolvedValue = getSingleCssVariableValue(element, color, 'border-color');
|
|
4579
|
+
tempResolvedValue[color] = resolvedValue;
|
|
4580
|
+
}
|
|
4581
|
+
Object.assign(resolvedCssVariables, tempResolvedValue);
|
|
4582
|
+
});
|
|
4583
|
+
}
|
|
4584
|
+
document.body.removeChild(element);
|
|
4585
|
+
return resolvedCssVariables;
|
|
4586
|
+
};
|
|
4525
4587
|
const sendConnectedEventWithRegisteredComponents = () => {
|
|
4526
4588
|
// Send the definitions (without components) via the connection message to the experience builder
|
|
4527
4589
|
const registeredDefinitions = Array.from(componentRegistry.values()).map(({ definition }) => definition);
|
|
@@ -4531,6 +4593,7 @@ const sendConnectedEventWithRegisteredComponents = () => {
|
|
|
4531
4593
|
});
|
|
4532
4594
|
sendMessage(OUTGOING_EVENTS.DesignTokens, {
|
|
4533
4595
|
designTokens: designTokensRegistry,
|
|
4596
|
+
resolvedCssVariables: resolveCssVariables(designTokensRegistry),
|
|
4534
4597
|
});
|
|
4535
4598
|
};
|
|
4536
4599
|
/**
|