@contentful/experiences-visual-editor-react 0.0.1-alpha.10 → 0.0.1-alpha.12
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 +50 -62
- package/dist/index.js.map +1 -1
- package/dist/renderApp.js +50 -62
- package/dist/renderApp.js.map +1 -1
- package/package.json +4 -4
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
|
-
|
|
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,
|
|
450
|
-
const imageUrl2x = getOptimizedImageUrl(url, width2x,
|
|
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
|
|
467
|
+
const returnedUrl = getOptimizedImageUrl(url, width2x, qualityNumber, format);
|
|
453
468
|
const optimizedBackgroundImageAsset = {
|
|
454
|
-
url:
|
|
469
|
+
url: returnedUrl,
|
|
455
470
|
srcSet,
|
|
456
471
|
file,
|
|
457
472
|
};
|
|
458
473
|
return optimizedBackgroundImageAsset;
|
|
459
|
-
function
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
if (
|
|
464
|
-
|
|
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
|
-
|
|
467
|
-
|
|
481
|
+
else {
|
|
482
|
+
width1x = Math.min(MAX_WIDTH_ALLOWED$1, intrinsicImageWidth);
|
|
468
483
|
}
|
|
469
|
-
|
|
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
|
-
|
|
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,
|
|
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,
|
|
502
|
+
srcSet.push(`${getOptimizedImageUrl(url, undefined, qualityNumber, format)} ${intrinsicImageWidth}w`);
|
|
499
503
|
}
|
|
500
|
-
const returnedUrl = getOptimizedImageUrl(url, file.details.image.width > 2000 ? 2000 : undefined,
|
|
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,
|
|
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,
|
|
546
|
+
value = getOptimizedBackgroundImageAsset(asset.fields.file, width, options.quality, options.format);
|
|
555
547
|
return value;
|
|
556
548
|
}
|
|
557
549
|
catch (error) {
|
|
@@ -781,9 +773,6 @@ const optionalBuiltInStyles = {
|
|
|
781
773
|
defaultValue: {
|
|
782
774
|
width: DEFAULT_IMAGE_WIDTH,
|
|
783
775
|
height: '100%',
|
|
784
|
-
objectFit: 'none',
|
|
785
|
-
objectPosition: 'center center',
|
|
786
|
-
quality: '100',
|
|
787
776
|
targetSize: DEFAULT_IMAGE_WIDTH,
|
|
788
777
|
},
|
|
789
778
|
},
|
|
@@ -799,7 +788,6 @@ const optionalBuiltInStyles = {
|
|
|
799
788
|
defaultValue: {
|
|
800
789
|
scaling: 'fill',
|
|
801
790
|
alignment: 'left top',
|
|
802
|
-
quality: '100',
|
|
803
791
|
targetSize: '2000px',
|
|
804
792
|
},
|
|
805
793
|
},
|
|
@@ -1713,23 +1701,23 @@ const CONTENTFUL_COMPONENTS = {
|
|
|
1713
1701
|
name: 'Column',
|
|
1714
1702
|
},
|
|
1715
1703
|
button: {
|
|
1716
|
-
id: 'button',
|
|
1704
|
+
id: 'contentful-button',
|
|
1717
1705
|
name: 'Button',
|
|
1718
1706
|
},
|
|
1719
1707
|
heading: {
|
|
1720
|
-
id: 'heading',
|
|
1708
|
+
id: 'contentful-heading',
|
|
1721
1709
|
name: 'Heading',
|
|
1722
1710
|
},
|
|
1723
1711
|
image: {
|
|
1724
|
-
id: 'image',
|
|
1712
|
+
id: 'contentful-image',
|
|
1725
1713
|
name: 'Image',
|
|
1726
1714
|
},
|
|
1727
1715
|
richText: {
|
|
1728
|
-
id: 'richText',
|
|
1716
|
+
id: 'contentful-richText',
|
|
1729
1717
|
name: 'Rich Text',
|
|
1730
1718
|
},
|
|
1731
1719
|
text: {
|
|
1732
|
-
id: 'text',
|
|
1720
|
+
id: 'contentful-text',
|
|
1733
1721
|
name: 'Text',
|
|
1734
1722
|
},
|
|
1735
1723
|
};
|
|
@@ -2683,7 +2671,7 @@ const useComponent = ({ node: rawNode, resolveDesignValue, renderDropzone, userI
|
|
|
2683
2671
|
});
|
|
2684
2672
|
}
|
|
2685
2673
|
else if (!registration) {
|
|
2686
|
-
|
|
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.`);
|
|
2687
2675
|
}
|
|
2688
2676
|
return registration;
|
|
2689
2677
|
}, [node]);
|