@contentful/experiences-visual-editor-react 1.6.0 → 1.7.0-beta.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
@@ -216,7 +216,6 @@ const transformBorderStyle = (value) => {
216
216
  // Just accept the passed value
217
217
  if (parts.length < 3)
218
218
  return { border: value };
219
- // Replace the second part always with `solid` and set the box sizing accordingly
220
219
  const [borderSize, borderStyle, ...borderColorParts] = parts;
221
220
  const borderColor = borderColorParts.join(' ');
222
221
  return {
@@ -301,27 +300,6 @@ const transformBackgroundImage = (cfBackgroundImageUrl, cfBackgroundImageOptions
301
300
  backgroundSize: matchBackgroundSize(cfBackgroundImageOptions?.scaling),
302
301
  };
303
302
  };
304
- const transformWidthSizing = ({ value, cfMargin, componentId, }) => {
305
- if (!value || !componentId)
306
- return;
307
- const transformedValue = transformFill(value);
308
- if (isContentfulStructureComponent(componentId)) {
309
- const marginValues = cfMargin ? cfMargin.split(' ') : [];
310
- const rightMargin = marginValues[1] || '0px';
311
- const leftMargin = marginValues[3] || '0px';
312
- const calcValue = `calc(${transformedValue} - ${leftMargin} - ${rightMargin})`;
313
- /**
314
- * We want to check if the calculated value is valid CSS. If this fails,
315
- * this means the `transformedValue` is not a calculable value (not a px, rem, or %).
316
- * The value may instead be a string such as `min-content` or `max-content`. In
317
- * that case we don't want to use calc and instead return the raw value.
318
- */
319
- if (typeof window !== 'undefined' && CSS.supports('width', calcValue)) {
320
- return calcValue;
321
- }
322
- }
323
- return transformedValue;
324
- };
325
303
 
326
304
  const toCSSAttribute = (key) => {
327
305
  let val = key.replace(/[A-Z]/g, (m) => '-' + m.toLowerCase());
@@ -338,12 +316,12 @@ const buildStyleTag = ({ styles, nodeId }) => {
338
316
  const styleRule = `.${className}{ ${stylesStr} }`;
339
317
  return [className, styleRule];
340
318
  };
341
- const buildCfStyles = ({ cfHorizontalAlignment, cfVerticalAlignment, cfFlexDirection, cfFlexWrap, cfMargin, cfPadding, cfBackgroundColor, cfWidth, cfHeight, cfMaxWidth, cfBorder, cfBorderRadius, cfGap, cfBackgroundImageUrl, cfBackgroundImageOptions, cfFontSize, cfFontWeight, cfImageOptions, cfLineHeight, cfLetterSpacing, cfTextColor, cfTextAlign, cfTextTransform, cfTextBold, cfTextItalic, cfTextUnderline, cfColumnSpan, }, componentId) => {
319
+ const buildCfStyles = ({ cfHorizontalAlignment, cfVerticalAlignment, cfFlexDirection, cfFlexWrap, cfMargin, cfPadding, cfBackgroundColor, cfWidth, cfHeight, cfMaxWidth, cfBorder, cfBorderRadius, cfGap, cfBackgroundImageUrl, cfBackgroundImageOptions, cfFontSize, cfFontWeight, cfImageOptions, cfLineHeight, cfLetterSpacing, cfTextColor, cfTextAlign, cfTextTransform, cfTextBold, cfTextItalic, cfTextUnderline, cfColumnSpan, }) => {
342
320
  return {
343
321
  margin: cfMargin,
344
322
  padding: cfPadding,
345
323
  backgroundColor: cfBackgroundColor,
346
- width: transformWidthSizing({ value: cfWidth || cfImageOptions?.width, cfMargin, componentId }),
324
+ width: transformFill(cfWidth || cfImageOptions?.width),
347
325
  height: transformFill(cfHeight || cfImageOptions?.height),
348
326
  maxWidth: cfMaxWidth,
349
327
  ...transformGridColumn(cfColumnSpan),
@@ -911,13 +889,31 @@ const optionalBuiltInStyles = {
911
889
  };
912
890
 
913
891
  let designTokensRegistry = {};
892
+ // This function is used to ensure that the composite values are valid since composite values are optional.
893
+ // Therefore only border and in the future text related design tokens are/will be checked in this funciton.
894
+ // Ensuring values for simple key-value design tokens are not neccessary since they are required via typescript.
895
+ const ensureValidCompositeValues = (designTokenDefinition) => {
896
+ // TODO: add validation logic when text related design tokens are added
897
+ // Border validation
898
+ if (designTokenDefinition.border) {
899
+ for (const borderKey in designTokenDefinition.border) {
900
+ const borderValue = designTokenDefinition.border[borderKey];
901
+ designTokenDefinition.border[borderKey] = {
902
+ width: borderValue.width || '1px',
903
+ style: borderValue.style || 'solid',
904
+ color: borderValue.color || '#000000',
905
+ };
906
+ }
907
+ }
908
+ return designTokenDefinition;
909
+ };
914
910
  /**
915
911
  * Register design tokens styling
916
912
  * @param designTokenDefinition - {[key:string]: Record<string, string>}
917
913
  * @returns void
918
914
  */
919
915
  const defineDesignTokens = (designTokenDefinition) => {
920
- Object.assign(designTokensRegistry, designTokenDefinition);
916
+ Object.assign(designTokensRegistry, ensureValidCompositeValues(designTokenDefinition));
921
917
  };
922
918
  const templateStringRegex = /\${(.+?)}/g;
923
919
  const getDesignTokenRegistration = (breakpointValue, variableName) => {
@@ -1057,7 +1053,7 @@ const BreakpointSchema = z
1057
1053
  query: z.string().regex(/^\*$|^<[0-9*]+px$/),
1058
1054
  previewSize: z.string(),
1059
1055
  displayName: z.string(),
1060
- displayIconUrl: z.string().optional(),
1056
+ displayIcon: z.enum(['desktop', 'tablet', 'mobile']).optional(),
1061
1057
  })
1062
1058
  .strict();
1063
1059
  const UnboundValuesSchema = z.record(uuidKeySchema, z.object({
@@ -1906,11 +1902,10 @@ class DeepReference {
1906
1902
  /**
1907
1903
  * Extracts referent from the path, using EntityStore as source of
1908
1904
  * entities during the resolution path.
1909
- * TODO: should it be called `extractLeafReferent` ? or `followToLeafReferent`
1910
1905
  */
1911
1906
  extractReferent(entityStore) {
1912
1907
  const headEntity = entityStore.getEntityFromLink(this.entityLink);
1913
- const maybeReferentLink = headEntity.fields[this.field];
1908
+ const maybeReferentLink = headEntity?.fields[this.field];
1914
1909
  if (undefined === maybeReferentLink) {
1915
1910
  // field references nothing (or even field doesn't exist)
1916
1911
  return undefined;
@@ -2778,7 +2773,7 @@ const useComponentProps = ({ node, areEntitiesFetched, resolveDesignValue, rende
2778
2773
  entityStore,
2779
2774
  renderDropzone,
2780
2775
  ]);
2781
- const cfStyles = buildCfStyles(props, node.data.blockId);
2776
+ const cfStyles = buildCfStyles(props);
2782
2777
  // Separate the component styles from the editor wrapper styles
2783
2778
  const { margin, height, width, maxWidth, ...componentStyles } = cfStyles;
2784
2779
  // Styles that will be applied to the editor wrapper (draggable) element