@contentful/experiences-visual-editor-react 0.0.1-alpha.11 → 0.0.1-alpha.13

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/renderApp.js CHANGED
@@ -34387,23 +34387,23 @@ const CONTENTFUL_COMPONENTS$1 = {
34387
34387
  name: 'Column',
34388
34388
  },
34389
34389
  button: {
34390
- id: 'button',
34390
+ id: 'contentful-button',
34391
34391
  name: 'Button',
34392
34392
  },
34393
34393
  heading: {
34394
- id: 'heading',
34394
+ id: 'contentful-heading',
34395
34395
  name: 'Heading',
34396
34396
  },
34397
34397
  image: {
34398
- id: 'image',
34398
+ id: 'contentful-image',
34399
34399
  name: 'Image',
34400
34400
  },
34401
34401
  richText: {
34402
- id: 'richText',
34402
+ id: 'contentful-richText',
34403
34403
  name: 'Rich Text',
34404
34404
  },
34405
34405
  text: {
34406
- id: 'text',
34406
+ id: 'contentful-text',
34407
34407
  name: 'Text',
34408
34408
  },
34409
34409
  };
@@ -34779,63 +34779,67 @@ function getOptimizedImageUrl(url, width, quality, format) {
34779
34779
  return `${url}${queryString ? '?' + queryString : ''}`;
34780
34780
  }
34781
34781
 
34782
+ function validateParams(file, quality, format) {
34783
+ if (!file.details.image) {
34784
+ throw Error('No image in file asset to transform');
34785
+ }
34786
+ if (quality < 0 || quality > 100) {
34787
+ throw Error('Quality must be between 0 and 100');
34788
+ }
34789
+ if (format && !SUPPORTED_IMAGE_FORMATS.includes(format)) {
34790
+ throw Error(`Format must be one of ${SUPPORTED_IMAGE_FORMATS.join(', ')}`);
34791
+ }
34792
+ return true;
34793
+ }
34794
+
34782
34795
  const MAX_WIDTH_ALLOWED$1 = 2000;
34783
- const getOptimizedBackgroundImageAsset = (file, widthStyle, quality = 100, format) => {
34784
- if (!validateParams(file, quality, format)) ;
34796
+ const getOptimizedBackgroundImageAsset = (file, widthStyle, quality = '100%', format) => {
34797
+ const qualityNumber = Number(quality.replace('%', ''));
34798
+ if (!validateParams(file, qualityNumber, format)) ;
34799
+ if (!validateParams(file, qualityNumber, format)) ;
34785
34800
  const url = file.url;
34786
34801
  const { width1x, width2x } = getWidths(widthStyle, file);
34787
- const imageUrl1x = getOptimizedImageUrl(url, width1x, quality, format);
34788
- const imageUrl2x = getOptimizedImageUrl(url, width2x, quality, format);
34802
+ const imageUrl1x = getOptimizedImageUrl(url, width1x, qualityNumber, format);
34803
+ const imageUrl2x = getOptimizedImageUrl(url, width2x, qualityNumber, format);
34789
34804
  const srcSet = [`url(${imageUrl1x}) 1x`, `url(${imageUrl2x}) 2x`];
34790
- const returnedUrlImageUrl = getOptimizedImageUrl(url, width2x, quality, format);
34805
+ const returnedUrl = getOptimizedImageUrl(url, width2x, qualityNumber, format);
34791
34806
  const optimizedBackgroundImageAsset = {
34792
- url: returnedUrlImageUrl,
34807
+ url: returnedUrl,
34793
34808
  srcSet,
34794
34809
  file,
34795
34810
  };
34796
34811
  return optimizedBackgroundImageAsset;
34797
- function validateParams(file, quality, format) {
34798
- if (!file.details.image) {
34799
- throw Error('No image in file asset to transform');
34800
- }
34801
- if (quality < 0 || quality > 100) {
34802
- throw Error('Quality must be between 0 and 100');
34812
+ function getWidths(widthStyle, file) {
34813
+ let width1x = 0;
34814
+ let width2x = 0;
34815
+ const intrinsicImageWidth = file.details.image.width;
34816
+ if (widthStyle.endsWith('px')) {
34817
+ width1x = Math.min(Number(widthStyle.replace('px', '')), intrinsicImageWidth);
34803
34818
  }
34804
- if (format && !SUPPORTED_IMAGE_FORMATS.includes(format)) {
34805
- throw Error(`Format must be one of ${SUPPORTED_IMAGE_FORMATS.join(', ')}`);
34819
+ else {
34820
+ width1x = Math.min(MAX_WIDTH_ALLOWED$1, intrinsicImageWidth);
34806
34821
  }
34807
- return true;
34822
+ width2x = Math.min(width1x * 2, intrinsicImageWidth);
34823
+ return { width1x, width2x };
34808
34824
  }
34809
34825
  };
34810
- function getWidths(widthStyle, file) {
34811
- let width1x = 0;
34812
- let width2x = 0;
34813
- const intrinsicImageWidth = file.details.image.width;
34814
- if (widthStyle.endsWith('px')) {
34815
- width1x = Math.min(Number(widthStyle.replace('px', '')), intrinsicImageWidth);
34816
- }
34817
- else {
34818
- width1x = Math.min(MAX_WIDTH_ALLOWED$1, intrinsicImageWidth);
34819
- }
34820
- width2x = Math.min(width1x * 2, intrinsicImageWidth);
34821
- return { width1x, width2x };
34822
- }
34823
34826
 
34824
34827
  const MAX_WIDTH_ALLOWED = 4000;
34825
- const getOptimizedImageAsset = (file, sizes, quality = 100, format) => {
34826
- if (!validateParams(file, quality, format)) ;
34828
+ const getOptimizedImageAsset = (file, sizes, quality = '100%', format) => {
34829
+ const qualityNumber = Number(quality.replace('%', ''));
34830
+ if (!validateParams(file, qualityNumber, format)) ;
34827
34831
  const url = file.url;
34828
34832
  const maxWidth = Math.min(file.details.image.width, MAX_WIDTH_ALLOWED);
34829
34833
  const numOfParts = Math.max(2, Math.ceil(maxWidth / 500));
34830
34834
  const widthParts = Array.from({ length: numOfParts }, (_, index) => Math.ceil((index + 1) * (maxWidth / numOfParts)));
34831
34835
  const srcSet = sizes
34832
- ? widthParts.map((width) => `${getOptimizedImageUrl(url, width, quality, format)} ${width}w`)
34836
+ ? widthParts.map((width) => `${getOptimizedImageUrl(url, width, qualityNumber, format)} ${width}w`)
34833
34837
  : [];
34834
34838
  const intrinsicImageWidth = file.details.image.width;
34835
34839
  if (intrinsicImageWidth > MAX_WIDTH_ALLOWED) {
34836
- srcSet.push(`${getOptimizedImageUrl(url, undefined, quality, format)} ${intrinsicImageWidth}w`);
34840
+ srcSet.push(`${getOptimizedImageUrl(url, undefined, qualityNumber, format)} ${intrinsicImageWidth}w`);
34837
34841
  }
34838
- const returnedUrl = getOptimizedImageUrl(url, file.details.image.width > 2000 ? 2000 : undefined, quality, format);
34842
+ const returnedUrl = getOptimizedImageUrl(url, file.details.image.width > 2000 ? 2000 : undefined, qualityNumber, format);
34839
34843
  const optimizedImageAsset = {
34840
34844
  url: returnedUrl,
34841
34845
  srcSet,
@@ -34843,18 +34847,6 @@ const getOptimizedImageAsset = (file, sizes, quality = 100, format) => {
34843
34847
  file,
34844
34848
  };
34845
34849
  return optimizedImageAsset;
34846
- function validateParams(file, quality, format) {
34847
- if (!file.details.image) {
34848
- throw Error('No image in file asset to transform');
34849
- }
34850
- if (quality < 0 || quality > 100) {
34851
- throw Error('Quality must be between 0 and 100');
34852
- }
34853
- if (format && !SUPPORTED_IMAGE_FORMATS.includes(format)) {
34854
- throw Error(`Format must be one of ${SUPPORTED_IMAGE_FORMATS.join(', ')}`);
34855
- }
34856
- return true;
34857
- }
34858
34850
  };
34859
34851
 
34860
34852
  const transformMedia = (asset, variables, resolveDesignValue, variableName, path) => {
@@ -34870,7 +34862,7 @@ const transformMedia = (asset, variables, resolveDesignValue, variableName, path
34870
34862
  return;
34871
34863
  }
34872
34864
  try {
34873
- value = getOptimizedImageAsset(asset.fields.file, options.targetSize, Number(options.quality), options.format);
34865
+ value = getOptimizedImageAsset(asset.fields.file, options.targetSize, options.quality, options.format);
34874
34866
  return value;
34875
34867
  }
34876
34868
  catch (error) {
@@ -34889,7 +34881,7 @@ const transformMedia = (asset, variables, resolveDesignValue, variableName, path
34889
34881
  return;
34890
34882
  }
34891
34883
  try {
34892
- value = getOptimizedBackgroundImageAsset(asset.fields.file, width, Number(options.quality), options.format);
34884
+ value = getOptimizedBackgroundImageAsset(asset.fields.file, width, options.quality, options.format);
34893
34885
  return value;
34894
34886
  }
34895
34887
  catch (error) {
@@ -35119,8 +35111,6 @@ const optionalBuiltInStyles = {
35119
35111
  defaultValue: {
35120
35112
  width: DEFAULT_IMAGE_WIDTH,
35121
35113
  height: '100%',
35122
- objectPosition: 'center center',
35123
- quality: '100',
35124
35114
  targetSize: DEFAULT_IMAGE_WIDTH,
35125
35115
  },
35126
35116
  },
@@ -35136,7 +35126,6 @@ const optionalBuiltInStyles = {
35136
35126
  defaultValue: {
35137
35127
  scaling: 'fill',
35138
35128
  alignment: 'left top',
35139
- quality: '100',
35140
35129
  targetSize: '2000px',
35141
35130
  },
35142
35131
  },
@@ -46443,23 +46432,23 @@ const CONTENTFUL_COMPONENTS = {
46443
46432
  name: 'Column',
46444
46433
  },
46445
46434
  button: {
46446
- id: 'button',
46435
+ id: 'contentful-button',
46447
46436
  name: 'Button',
46448
46437
  },
46449
46438
  heading: {
46450
- id: 'heading',
46439
+ id: 'contentful-heading',
46451
46440
  name: 'Heading',
46452
46441
  },
46453
46442
  image: {
46454
- id: 'image',
46443
+ id: 'contentful-image',
46455
46444
  name: 'Image',
46456
46445
  },
46457
46446
  richText: {
46458
- id: 'richText',
46447
+ id: 'contentful-richText',
46459
46448
  name: 'Rich Text',
46460
46449
  },
46461
46450
  text: {
46462
- id: 'text',
46451
+ id: 'contentful-text',
46463
46452
  name: 'Text',
46464
46453
  },
46465
46454
  };
@@ -51587,7 +51576,7 @@ const useComponent = ({ node: rawNode, resolveDesignValue, renderDropzone, userI
51587
51576
  });
51588
51577
  }
51589
51578
  else if (!registration) {
51590
- console.warn(`[experiences-sdk-react] Component registration not found for ${node.data.blockId}`);
51579
+ throw Error(`Component registration not found for component with id: "${node.data.blockId}". The component might of been removed. To proceed, remove the component manually from the layers tab.`);
51591
51580
  }
51592
51581
  return registration;
51593
51582
  }, [node]);