@contentful/experiences-visual-editor-react 1.0.3 → 1.0.4-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
@@ -520,6 +520,11 @@ const getOptimizedImageAsset = (file, sizes, quality = '100%', format) => {
520
520
 
521
521
  const transformMedia = (asset, variables, resolveDesignValue, variableName, path) => {
522
522
  let value;
523
+ // If it is not a deep path and not pointing to the file of the asset,
524
+ // it is just pointing to a normal field and therefore we just resolve the value as normal field
525
+ if (!isDeepPath(path) && !lastPathNamedSegmentEq(path, 'file')) {
526
+ return getBoundValue(asset, path);
527
+ }
523
528
  //TODO: this will be better served by injectable type transformers instead of if statement
524
529
  if (variableName === 'cfImageAsset') {
525
530
  const optionsVariableName = 'cfImageOptions';
@@ -558,8 +563,7 @@ const transformMedia = (asset, variables, resolveDesignValue, variableName, path
558
563
  }
559
564
  return;
560
565
  }
561
- // return getBoundValue(asset, entityStore, binding, path);
562
- return getBoundValue(asset, path);
566
+ return asset.fields.file?.url;
563
567
  };
564
568
 
565
569
  const transformBoundContentValue = (variables, entityStore, binding, resolveDesignValue, variableName, variableDefinition, path) => {
@@ -568,6 +572,10 @@ const transformBoundContentValue = (variables, entityStore, binding, resolveDesi
568
572
  return;
569
573
  switch (variableDefinition.type) {
570
574
  case 'Media':
575
+ // If we bound a normal entry field to the media veriable we just return the bound value
576
+ if (entityOrAsset.sys.type === 'Entry') {
577
+ return getBoundValue(entityOrAsset, path);
578
+ }
571
579
  return transformMedia(entityOrAsset, variables, resolveDesignValue, variableName, path);
572
580
  case 'RichText':
573
581
  return transformRichText(entityOrAsset, path);
@@ -1165,6 +1173,17 @@ const chunkSegments = (segments, { startNextChunkOnElementEqualTo }) => {
1165
1173
  chunks.push(currentChunk);
1166
1174
  return chunks.filter(excludeEmptyChunks);
1167
1175
  };
1176
+ const lastPathNamedSegmentEq = (path, expectedName) => {
1177
+ // `/key123/fields/featureImage/~locale/fields/file/~locale`
1178
+ // ['', 'key123', 'fields', 'featureImage', '~locale', 'fields', 'file', '~locale']
1179
+ const segments = path.split('/');
1180
+ if (segments.length < 2) {
1181
+ console.warn(`[experiences-sdk-react] Attempting to check whether last named segment of the path (${path}) equals to '${expectedName}', but the path doesn't have enough segments.`);
1182
+ return false;
1183
+ }
1184
+ const secondLast = segments[segments.length - 2]; // skipping trailing '~locale'
1185
+ return secondLast === expectedName;
1186
+ };
1168
1187
 
1169
1188
  const sendMessage = (eventType, data) => {
1170
1189
  if (typeof window === 'undefined') {