@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/index.js CHANGED
@@ -49,23 +49,23 @@ const CONTENTFUL_COMPONENTS$1 = {
49
49
  name: 'Column',
50
50
  },
51
51
  button: {
52
- id: 'button',
52
+ id: 'contentful-button',
53
53
  name: 'Button',
54
54
  },
55
55
  heading: {
56
- id: 'heading',
56
+ id: 'contentful-heading',
57
57
  name: 'Heading',
58
58
  },
59
59
  image: {
60
- id: 'image',
60
+ id: 'contentful-image',
61
61
  name: 'Image',
62
62
  },
63
63
  richText: {
64
- id: 'richText',
64
+ id: 'contentful-richText',
65
65
  name: 'Rich Text',
66
66
  },
67
67
  text: {
68
- id: 'text',
68
+ id: 'contentful-text',
69
69
  name: 'Text',
70
70
  },
71
71
  };
@@ -441,63 +441,67 @@ function getOptimizedImageUrl(url, width, quality, format) {
441
441
  return `${url}${queryString ? '?' + queryString : ''}`;
442
442
  }
443
443
 
444
+ function validateParams(file, quality, format) {
445
+ if (!file.details.image) {
446
+ throw Error('No image in file asset to transform');
447
+ }
448
+ if (quality < 0 || quality > 100) {
449
+ throw Error('Quality must be between 0 and 100');
450
+ }
451
+ if (format && !SUPPORTED_IMAGE_FORMATS.includes(format)) {
452
+ throw Error(`Format must be one of ${SUPPORTED_IMAGE_FORMATS.join(', ')}`);
453
+ }
454
+ return true;
455
+ }
456
+
444
457
  const MAX_WIDTH_ALLOWED$1 = 2000;
445
- const getOptimizedBackgroundImageAsset = (file, widthStyle, quality = 100, format) => {
446
- if (!validateParams(file, quality, format)) ;
458
+ const getOptimizedBackgroundImageAsset = (file, widthStyle, quality = '100%', format) => {
459
+ const qualityNumber = Number(quality.replace('%', ''));
460
+ if (!validateParams(file, qualityNumber, format)) ;
461
+ if (!validateParams(file, qualityNumber, format)) ;
447
462
  const url = file.url;
448
463
  const { width1x, width2x } = getWidths(widthStyle, file);
449
- const imageUrl1x = getOptimizedImageUrl(url, width1x, quality, format);
450
- const imageUrl2x = getOptimizedImageUrl(url, width2x, quality, format);
464
+ const imageUrl1x = getOptimizedImageUrl(url, width1x, qualityNumber, format);
465
+ const imageUrl2x = getOptimizedImageUrl(url, width2x, qualityNumber, format);
451
466
  const srcSet = [`url(${imageUrl1x}) 1x`, `url(${imageUrl2x}) 2x`];
452
- const returnedUrlImageUrl = getOptimizedImageUrl(url, width2x, quality, format);
467
+ const returnedUrl = getOptimizedImageUrl(url, width2x, qualityNumber, format);
453
468
  const optimizedBackgroundImageAsset = {
454
- url: returnedUrlImageUrl,
469
+ url: returnedUrl,
455
470
  srcSet,
456
471
  file,
457
472
  };
458
473
  return optimizedBackgroundImageAsset;
459
- function validateParams(file, quality, format) {
460
- if (!file.details.image) {
461
- throw Error('No image in file asset to transform');
462
- }
463
- if (quality < 0 || quality > 100) {
464
- throw Error('Quality must be between 0 and 100');
474
+ function getWidths(widthStyle, file) {
475
+ let width1x = 0;
476
+ let width2x = 0;
477
+ const intrinsicImageWidth = file.details.image.width;
478
+ if (widthStyle.endsWith('px')) {
479
+ width1x = Math.min(Number(widthStyle.replace('px', '')), intrinsicImageWidth);
465
480
  }
466
- if (format && !SUPPORTED_IMAGE_FORMATS.includes(format)) {
467
- throw Error(`Format must be one of ${SUPPORTED_IMAGE_FORMATS.join(', ')}`);
481
+ else {
482
+ width1x = Math.min(MAX_WIDTH_ALLOWED$1, intrinsicImageWidth);
468
483
  }
469
- return true;
484
+ width2x = Math.min(width1x * 2, intrinsicImageWidth);
485
+ return { width1x, width2x };
470
486
  }
471
487
  };
472
- function getWidths(widthStyle, file) {
473
- let width1x = 0;
474
- let width2x = 0;
475
- const intrinsicImageWidth = file.details.image.width;
476
- if (widthStyle.endsWith('px')) {
477
- width1x = Math.min(Number(widthStyle.replace('px', '')), intrinsicImageWidth);
478
- }
479
- else {
480
- width1x = Math.min(MAX_WIDTH_ALLOWED$1, intrinsicImageWidth);
481
- }
482
- width2x = Math.min(width1x * 2, intrinsicImageWidth);
483
- return { width1x, width2x };
484
- }
485
488
 
486
489
  const MAX_WIDTH_ALLOWED = 4000;
487
- const getOptimizedImageAsset = (file, sizes, quality = 100, format) => {
488
- if (!validateParams(file, quality, format)) ;
490
+ const getOptimizedImageAsset = (file, sizes, quality = '100%', format) => {
491
+ const qualityNumber = Number(quality.replace('%', ''));
492
+ if (!validateParams(file, qualityNumber, format)) ;
489
493
  const url = file.url;
490
494
  const maxWidth = Math.min(file.details.image.width, MAX_WIDTH_ALLOWED);
491
495
  const numOfParts = Math.max(2, Math.ceil(maxWidth / 500));
492
496
  const widthParts = Array.from({ length: numOfParts }, (_, index) => Math.ceil((index + 1) * (maxWidth / numOfParts)));
493
497
  const srcSet = sizes
494
- ? widthParts.map((width) => `${getOptimizedImageUrl(url, width, quality, format)} ${width}w`)
498
+ ? widthParts.map((width) => `${getOptimizedImageUrl(url, width, qualityNumber, format)} ${width}w`)
495
499
  : [];
496
500
  const intrinsicImageWidth = file.details.image.width;
497
501
  if (intrinsicImageWidth > MAX_WIDTH_ALLOWED) {
498
- srcSet.push(`${getOptimizedImageUrl(url, undefined, quality, format)} ${intrinsicImageWidth}w`);
502
+ srcSet.push(`${getOptimizedImageUrl(url, undefined, qualityNumber, format)} ${intrinsicImageWidth}w`);
499
503
  }
500
- const returnedUrl = getOptimizedImageUrl(url, file.details.image.width > 2000 ? 2000 : undefined, quality, format);
504
+ const returnedUrl = getOptimizedImageUrl(url, file.details.image.width > 2000 ? 2000 : undefined, qualityNumber, format);
501
505
  const optimizedImageAsset = {
502
506
  url: returnedUrl,
503
507
  srcSet,
@@ -505,18 +509,6 @@ const getOptimizedImageAsset = (file, sizes, quality = 100, format) => {
505
509
  file,
506
510
  };
507
511
  return optimizedImageAsset;
508
- function validateParams(file, quality, format) {
509
- if (!file.details.image) {
510
- throw Error('No image in file asset to transform');
511
- }
512
- if (quality < 0 || quality > 100) {
513
- throw Error('Quality must be between 0 and 100');
514
- }
515
- if (format && !SUPPORTED_IMAGE_FORMATS.includes(format)) {
516
- throw Error(`Format must be one of ${SUPPORTED_IMAGE_FORMATS.join(', ')}`);
517
- }
518
- return true;
519
- }
520
512
  };
521
513
 
522
514
  const transformMedia = (asset, variables, resolveDesignValue, variableName, path) => {
@@ -532,7 +524,7 @@ const transformMedia = (asset, variables, resolveDesignValue, variableName, path
532
524
  return;
533
525
  }
534
526
  try {
535
- value = getOptimizedImageAsset(asset.fields.file, options.targetSize, Number(options.quality), options.format);
527
+ value = getOptimizedImageAsset(asset.fields.file, options.targetSize, options.quality, options.format);
536
528
  return value;
537
529
  }
538
530
  catch (error) {
@@ -551,7 +543,7 @@ const transformMedia = (asset, variables, resolveDesignValue, variableName, path
551
543
  return;
552
544
  }
553
545
  try {
554
- value = getOptimizedBackgroundImageAsset(asset.fields.file, width, Number(options.quality), options.format);
546
+ value = getOptimizedBackgroundImageAsset(asset.fields.file, width, options.quality, options.format);
555
547
  return value;
556
548
  }
557
549
  catch (error) {
@@ -781,8 +773,6 @@ const optionalBuiltInStyles = {
781
773
  defaultValue: {
782
774
  width: DEFAULT_IMAGE_WIDTH,
783
775
  height: '100%',
784
- objectPosition: 'center center',
785
- quality: '100',
786
776
  targetSize: DEFAULT_IMAGE_WIDTH,
787
777
  },
788
778
  },
@@ -798,7 +788,6 @@ const optionalBuiltInStyles = {
798
788
  defaultValue: {
799
789
  scaling: 'fill',
800
790
  alignment: 'left top',
801
- quality: '100',
802
791
  targetSize: '2000px',
803
792
  },
804
793
  },
@@ -1712,23 +1701,23 @@ const CONTENTFUL_COMPONENTS = {
1712
1701
  name: 'Column',
1713
1702
  },
1714
1703
  button: {
1715
- id: 'button',
1704
+ id: 'contentful-button',
1716
1705
  name: 'Button',
1717
1706
  },
1718
1707
  heading: {
1719
- id: 'heading',
1708
+ id: 'contentful-heading',
1720
1709
  name: 'Heading',
1721
1710
  },
1722
1711
  image: {
1723
- id: 'image',
1712
+ id: 'contentful-image',
1724
1713
  name: 'Image',
1725
1714
  },
1726
1715
  richText: {
1727
- id: 'richText',
1716
+ id: 'contentful-richText',
1728
1717
  name: 'Rich Text',
1729
1718
  },
1730
1719
  text: {
1731
- id: 'text',
1720
+ id: 'contentful-text',
1732
1721
  name: 'Text',
1733
1722
  },
1734
1723
  };
@@ -2682,7 +2671,7 @@ const useComponent = ({ node: rawNode, resolveDesignValue, renderDropzone, userI
2682
2671
  });
2683
2672
  }
2684
2673
  else if (!registration) {
2685
- console.warn(`[experiences-sdk-react] Component registration not found for ${node.data.blockId}`);
2674
+ 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.`);
2686
2675
  }
2687
2676
  return registration;
2688
2677
  }, [node]);