@contentful/experiences-core 0.0.1-alpha.9 → 0.0.1-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/constants.js +5 -5
- package/dist/constants.js.map +1 -1
- package/dist/index.js +131 -98
- package/dist/index.js.map +1 -1
- package/dist/types.d.ts +3 -3
- package/package.json +3 -3
package/dist/constants.js
CHANGED
|
@@ -69,23 +69,23 @@ const CONTENTFUL_COMPONENTS = {
|
|
|
69
69
|
name: 'Column',
|
|
70
70
|
},
|
|
71
71
|
button: {
|
|
72
|
-
id: 'button',
|
|
72
|
+
id: 'contentful-button',
|
|
73
73
|
name: 'Button',
|
|
74
74
|
},
|
|
75
75
|
heading: {
|
|
76
|
-
id: 'heading',
|
|
76
|
+
id: 'contentful-heading',
|
|
77
77
|
name: 'Heading',
|
|
78
78
|
},
|
|
79
79
|
image: {
|
|
80
|
-
id: 'image',
|
|
80
|
+
id: 'contentful-image',
|
|
81
81
|
name: 'Image',
|
|
82
82
|
},
|
|
83
83
|
richText: {
|
|
84
|
-
id: 'richText',
|
|
84
|
+
id: 'contentful-richText',
|
|
85
85
|
name: 'Rich Text',
|
|
86
86
|
},
|
|
87
87
|
text: {
|
|
88
|
-
id: 'text',
|
|
88
|
+
id: 'contentful-text',
|
|
89
89
|
name: 'Text',
|
|
90
90
|
},
|
|
91
91
|
};
|
package/dist/constants.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"constants.js","sources":["../src/constants.ts"],"sourcesContent":["export const SCROLL_STATES = {\n Start: 'scrollStart',\n IsScrolling: 'isScrolling',\n End: 'scrollEnd',\n};\n\nexport const OUTGOING_EVENTS = {\n Connected: 'connected',\n DesignTokens: 'registerDesignTokens',\n HoveredSection: 'hoveredSection',\n MouseMove: 'mouseMove',\n NewHoveredElement: 'newHoveredElement',\n ComponentSelected: 'componentSelected',\n RegisteredComponents: 'registeredComponents',\n RequestComponentTreeUpdate: 'requestComponentTreeUpdate',\n ComponentDragCanceled: 'componentDragCanceled',\n ComponentDropped: 'componentDropped',\n ComponentMoved: 'componentMoved',\n CanvasReload: 'canvasReload',\n UpdateSelectedComponentCoordinates: 'updateSelectedComponentCoordinates',\n UpdateHoveredComponentCoordinates: 'updateHoveredComponentCoordinates',\n CanvasScroll: 'canvasScrolling',\n CanvasError: 'canvasError',\n ComponentMoveStarted: 'componentMoveStarted',\n ComponentMoveEnded: 'componentMoveEnded',\n OutsideCanvasClick: 'outsideCanvasClick',\n};\n\nexport const INCOMING_EVENTS = {\n RequestEditorMode: 'requestEditorMode',\n ExperienceUpdated: 'componentTreeUpdated',\n ComponentDraggingChanged: 'componentDraggingChanged',\n ComponentDragCanceled: 'componentDragCanceled',\n ComponentDragStarted: 'componentDragStarted',\n ComponentDragEnded: 'componentDragEnded',\n ComponentMoveEnded: 'componentMoveEnded',\n CanvasResized: 'canvasResized',\n SelectComponent: 'selectComponent',\n HoverComponent: 'hoverComponent',\n UpdatedEntity: 'updatedEntity',\n AssembliesAdded: 'assembliesAdded',\n AssembliesRegistered: 'assembliesRegistered',\n InitEditor: 'initEditor',\n MouseMove: 'mouseMove',\n};\n\nexport const INTERNAL_EVENTS = {\n ComponentsRegistered: 'cfComponentsRegistered',\n VisualEditorInitialize: 'cfVisualEditorInitialize',\n};\n\nexport const VISUAL_EDITOR_EVENTS = {\n Ready: 'cfVisualEditorReady',\n};\n\nexport const VISUAL_EDITOR_CONTAINER_ID = 'cf-visual-editor';\nexport const CONTENTFUL_COMPONENT_CATEGORY = 'contentful-component';\nexport const CONTENTFUL_DEFAULT_CATEGORY = 'Contentful';\n\nexport const CONTENTFUL_COMPONENTS = {\n section: {\n id: 'contentful-section',\n name: 'Section',\n },\n container: {\n id: 'contentful-container',\n name: 'Container',\n },\n columns: {\n id: 'contentful-columns',\n name: 'Columns',\n },\n singleColumn: {\n id: 'contentful-single-column',\n name: 'Column',\n },\n button: {\n id: 'button',\n name: 'Button',\n },\n heading: {\n id: 'heading',\n name: 'Heading',\n },\n image: {\n id: 'image',\n name: 'Image',\n },\n richText: {\n id: 'richText',\n name: 'Rich Text',\n },\n text: {\n id: 'text',\n name: 'Text',\n },\n};\n\nexport const ASSEMBLY_NODE_TYPE = 'assembly';\nexport const ASSEMBLY_DEFAULT_CATEGORY = 'Assemblies';\nexport const ASSEMBLY_BLOCK_NODE_TYPE = 'assemblyBlock';\nexport const ASSEMBLY_NODE_TYPES = [ASSEMBLY_NODE_TYPE, ASSEMBLY_BLOCK_NODE_TYPE];\nexport const LATEST_SCHEMA_VERSION = '2023-09-28';\nexport const CF_STYLE_ATTRIBUTES = [\n 'cfHorizontalAlignment',\n 'cfVerticalAlignment',\n 'cfMargin',\n 'cfPadding',\n 'cfBackgroundColor',\n 'cfWidth',\n 'cfMaxWidth',\n 'cfHeight',\n 'cfImageAsset',\n 'cfImageOptions',\n 'cfBackgroundImageUrl',\n 'cfBackgroundImageOptions',\n 'cfFlexDirection',\n 'cfFlexWrap',\n 'cfBorder',\n 'cfBorderRadius',\n 'cfGap',\n 'cfFontSize',\n 'cfFontWeight',\n 'cfLineHeight',\n 'cfLetterSpacing',\n 'cfTextColor',\n 'cfTextAlign',\n 'cfTextTransform',\n 'cfTextBold',\n 'cfTextItalic',\n 'cfTextUnderline',\n // For backwards compatibility\n // we need to keep those in this constant array\n // so that omit() in <VisualEditorBlock> and <CompositionBlock>\n // can filter them out and not pass as props\n 'cfBackgroundImageScaling',\n 'cfBackgroundImageAlignment',\n 'cfBackgroundImageAlignmentVertical',\n 'cfBackgroundImageAlignmentHorizontal',\n];\n\nexport const EMPTY_CONTAINER_HEIGHT = '80px';\n\nexport const DEFAULT_IMAGE_WIDTH = '500px';\n\nexport enum PostMessageMethods {\n REQUEST_ENTITIES = 'REQUEST_ENTITIES',\n REQUESTED_ENTITIES = 'REQUESTED_ENTITIES',\n}\n\nexport const SUPPORTED_IMAGE_FORMATS = ['jpg', 'png', 'webp', 'gif', 'avif'] as const;\n"],"names":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AiB;AAClC,IAAA,oBAAoB,EAAE,sBAAsB;AAC5C,IAAA,UAAU,EAAE,YAAY;AACxB,IAAA,SAAS,EAAE,WAAW;EACtB;AAEW,MAAA,eAAe,GAAG;AAC7B,IAAA,oBAAoB,EAAE,wBAAwB;AAC9C,IAAA,sBAAsB,EAAE,0BAA0B;EAClD;AAEW,MAAA,oBAAoB,GAAG;AAClC,IAAA,KAAK,EAAE,qBAAqB;EAC5B;AAEK,MAAM,0BAA0B,GAAG,mBAAmB;AACtD,MAAM,6BAA6B,GAAG,uBAAuB;AAC7D,MAAM,2BAA2B,GAAG,aAAa;AAE3C,MAAA,qBAAqB,GAAG;AACnC,IAAA,OAAO,EAAE;AACP,QAAA,EAAE,EAAE,oBAAoB;AACxB,QAAA,IAAI,EAAE,SAAS;AAChB,KAAA;AACD,IAAA,SAAS,EAAE;AACT,QAAA,EAAE,EAAE,sBAAsB;AAC1B,QAAA,IAAI,EAAE,WAAW;AAClB,KAAA;AACD,IAAA,OAAO,EAAE;AACP,QAAA,EAAE,EAAE,oBAAoB;AACxB,QAAA,IAAI,EAAE,SAAS;AAChB,KAAA;AACD,IAAA,YAAY,EAAE;AACZ,QAAA,EAAE,EAAE,0BAA0B;AAC9B,QAAA,IAAI,EAAE,QAAQ;AACf,KAAA;AACD,IAAA,MAAM,EAAE;AACN,QAAA,EAAE,EAAE,
|
|
1
|
+
{"version":3,"file":"constants.js","sources":["../src/constants.ts"],"sourcesContent":["export const SCROLL_STATES = {\n Start: 'scrollStart',\n IsScrolling: 'isScrolling',\n End: 'scrollEnd',\n};\n\nexport const OUTGOING_EVENTS = {\n Connected: 'connected',\n DesignTokens: 'registerDesignTokens',\n HoveredSection: 'hoveredSection',\n MouseMove: 'mouseMove',\n NewHoveredElement: 'newHoveredElement',\n ComponentSelected: 'componentSelected',\n RegisteredComponents: 'registeredComponents',\n RequestComponentTreeUpdate: 'requestComponentTreeUpdate',\n ComponentDragCanceled: 'componentDragCanceled',\n ComponentDropped: 'componentDropped',\n ComponentMoved: 'componentMoved',\n CanvasReload: 'canvasReload',\n UpdateSelectedComponentCoordinates: 'updateSelectedComponentCoordinates',\n UpdateHoveredComponentCoordinates: 'updateHoveredComponentCoordinates',\n CanvasScroll: 'canvasScrolling',\n CanvasError: 'canvasError',\n ComponentMoveStarted: 'componentMoveStarted',\n ComponentMoveEnded: 'componentMoveEnded',\n OutsideCanvasClick: 'outsideCanvasClick',\n};\n\nexport const INCOMING_EVENTS = {\n RequestEditorMode: 'requestEditorMode',\n ExperienceUpdated: 'componentTreeUpdated',\n ComponentDraggingChanged: 'componentDraggingChanged',\n ComponentDragCanceled: 'componentDragCanceled',\n ComponentDragStarted: 'componentDragStarted',\n ComponentDragEnded: 'componentDragEnded',\n ComponentMoveEnded: 'componentMoveEnded',\n CanvasResized: 'canvasResized',\n SelectComponent: 'selectComponent',\n HoverComponent: 'hoverComponent',\n UpdatedEntity: 'updatedEntity',\n AssembliesAdded: 'assembliesAdded',\n AssembliesRegistered: 'assembliesRegistered',\n InitEditor: 'initEditor',\n MouseMove: 'mouseMove',\n};\n\nexport const INTERNAL_EVENTS = {\n ComponentsRegistered: 'cfComponentsRegistered',\n VisualEditorInitialize: 'cfVisualEditorInitialize',\n};\n\nexport const VISUAL_EDITOR_EVENTS = {\n Ready: 'cfVisualEditorReady',\n};\n\nexport const VISUAL_EDITOR_CONTAINER_ID = 'cf-visual-editor';\nexport const CONTENTFUL_COMPONENT_CATEGORY = 'contentful-component';\nexport const CONTENTFUL_DEFAULT_CATEGORY = 'Contentful';\n\nexport const CONTENTFUL_COMPONENTS = {\n section: {\n id: 'contentful-section',\n name: 'Section',\n },\n container: {\n id: 'contentful-container',\n name: 'Container',\n },\n columns: {\n id: 'contentful-columns',\n name: 'Columns',\n },\n singleColumn: {\n id: 'contentful-single-column',\n name: 'Column',\n },\n button: {\n id: 'contentful-button',\n name: 'Button',\n },\n heading: {\n id: 'contentful-heading',\n name: 'Heading',\n },\n image: {\n id: 'contentful-image',\n name: 'Image',\n },\n richText: {\n id: 'contentful-richText',\n name: 'Rich Text',\n },\n text: {\n id: 'contentful-text',\n name: 'Text',\n },\n};\n\nexport const ASSEMBLY_NODE_TYPE = 'assembly';\nexport const ASSEMBLY_DEFAULT_CATEGORY = 'Assemblies';\nexport const ASSEMBLY_BLOCK_NODE_TYPE = 'assemblyBlock';\nexport const ASSEMBLY_NODE_TYPES = [ASSEMBLY_NODE_TYPE, ASSEMBLY_BLOCK_NODE_TYPE];\nexport const LATEST_SCHEMA_VERSION = '2023-09-28';\nexport const CF_STYLE_ATTRIBUTES = [\n 'cfHorizontalAlignment',\n 'cfVerticalAlignment',\n 'cfMargin',\n 'cfPadding',\n 'cfBackgroundColor',\n 'cfWidth',\n 'cfMaxWidth',\n 'cfHeight',\n 'cfImageAsset',\n 'cfImageOptions',\n 'cfBackgroundImageUrl',\n 'cfBackgroundImageOptions',\n 'cfFlexDirection',\n 'cfFlexWrap',\n 'cfBorder',\n 'cfBorderRadius',\n 'cfGap',\n 'cfFontSize',\n 'cfFontWeight',\n 'cfLineHeight',\n 'cfLetterSpacing',\n 'cfTextColor',\n 'cfTextAlign',\n 'cfTextTransform',\n 'cfTextBold',\n 'cfTextItalic',\n 'cfTextUnderline',\n // For backwards compatibility\n // we need to keep those in this constant array\n // so that omit() in <VisualEditorBlock> and <CompositionBlock>\n // can filter them out and not pass as props\n 'cfBackgroundImageScaling',\n 'cfBackgroundImageAlignment',\n 'cfBackgroundImageAlignmentVertical',\n 'cfBackgroundImageAlignmentHorizontal',\n];\n\nexport const EMPTY_CONTAINER_HEIGHT = '80px';\n\nexport const DEFAULT_IMAGE_WIDTH = '500px';\n\nexport enum PostMessageMethods {\n REQUEST_ENTITIES = 'REQUEST_ENTITIES',\n REQUESTED_ENTITIES = 'REQUESTED_ENTITIES',\n}\n\nexport const SUPPORTED_IMAGE_FORMATS = ['jpg', 'png', 'webp', 'gif', 'avif'] as const;\n"],"names":[],"mappings":"AAAa,MAAA,aAAa,GAAG;AAC3B,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AAA;EACD;AAEK,MAAM,kBAAkB,GAAG,WAAW;AACtC,MAAM,yBAAyB,GAAG,aAAa;AAC/C,MAAM,wBAAwB,GAAG,gBAAgB;MAC3C,mBAAmB,GAAG,CAAC,kBAAkB,EAAE,wBAAwB,EAAE;AAC3E,MAAM,qBAAqB,GAAG,aAAa;AACrC,MAAA,mBAAmB,GAAG;IACjC,uBAAuB;IACvB,qBAAqB;IACrB,UAAU;IACV,WAAW;IACX,mBAAmB;IACnB,SAAS;IACT,YAAY;IACZ,UAAU;IACV,cAAc;IACd,gBAAgB;IAChB,sBAAsB;IACtB,0BAA0B;IAC1B,iBAAiB;IACjB,YAAY;IACZ,UAAU;IACV,gBAAgB;IAChB,OAAO;IACP,YAAY;IACZ,cAAc;IACd,cAAc;IACd,iBAAiB;IACjB,aAAa;IACb,aAAa;IACb,iBAAiB;IACjB,YAAY;IACZ,cAAc;IACd,iBAAiB;;;;;IAKjB,0BAA0B;IAC1B,4BAA4B;IAC5B,oCAAoC;IACpC,sCAAsC;EACtC;AAEK,MAAM,sBAAsB,GAAG,OAAO;AAEtC,MAAM,mBAAmB,GAAG,QAAQ;IAE/B,mBAGX;AAHD,CAAA,UAAY,kBAAkB,EAAA;AAC5B,IAAA,kBAAA,CAAA,kBAAA,CAAA,GAAA,kBAAqC,CAAA;AACrC,IAAA,kBAAA,CAAA,oBAAA,CAAA,GAAA,oBAAyC,CAAA;AAC3C,CAAC,EAHW,kBAAkB,KAAlB,kBAAkB,GAG7B,EAAA,CAAA,CAAA,CAAA;AAEM,MAAM,uBAAuB,GAAG,CAAC,KAAK,EAAE,KAAK,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM;;;;"}
|
package/dist/index.js
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import md5 from 'md5';
|
|
2
2
|
import { BLOCKS } from '@contentful/rich-text-types';
|
|
3
|
+
import { uniqBy } from 'lodash-es';
|
|
3
4
|
|
|
4
5
|
const INCOMING_EVENTS = {
|
|
5
6
|
RequestEditorMode: 'requestEditorMode',
|
|
@@ -37,23 +38,23 @@ const CONTENTFUL_COMPONENTS = {
|
|
|
37
38
|
name: 'Column',
|
|
38
39
|
},
|
|
39
40
|
button: {
|
|
40
|
-
id: 'button',
|
|
41
|
+
id: 'contentful-button',
|
|
41
42
|
name: 'Button',
|
|
42
43
|
},
|
|
43
44
|
heading: {
|
|
44
|
-
id: 'heading',
|
|
45
|
+
id: 'contentful-heading',
|
|
45
46
|
name: 'Heading',
|
|
46
47
|
},
|
|
47
48
|
image: {
|
|
48
|
-
id: 'image',
|
|
49
|
+
id: 'contentful-image',
|
|
49
50
|
name: 'Image',
|
|
50
51
|
},
|
|
51
52
|
richText: {
|
|
52
|
-
id: 'richText',
|
|
53
|
+
id: 'contentful-richText',
|
|
53
54
|
name: 'Rich Text',
|
|
54
55
|
},
|
|
55
56
|
text: {
|
|
56
|
-
id: 'text',
|
|
57
|
+
id: 'contentful-text',
|
|
57
58
|
name: 'Text',
|
|
58
59
|
},
|
|
59
60
|
};
|
|
@@ -438,63 +439,67 @@ function getOptimizedImageUrl(url, width, quality, format) {
|
|
|
438
439
|
return `${url}${queryString ? '?' + queryString : ''}`;
|
|
439
440
|
}
|
|
440
441
|
|
|
442
|
+
function validateParams(file, quality, format) {
|
|
443
|
+
if (!file.details.image) {
|
|
444
|
+
throw Error('No image in file asset to transform');
|
|
445
|
+
}
|
|
446
|
+
if (quality < 0 || quality > 100) {
|
|
447
|
+
throw Error('Quality must be between 0 and 100');
|
|
448
|
+
}
|
|
449
|
+
if (format && !SUPPORTED_IMAGE_FORMATS.includes(format)) {
|
|
450
|
+
throw Error(`Format must be one of ${SUPPORTED_IMAGE_FORMATS.join(', ')}`);
|
|
451
|
+
}
|
|
452
|
+
return true;
|
|
453
|
+
}
|
|
454
|
+
|
|
441
455
|
const MAX_WIDTH_ALLOWED$1 = 2000;
|
|
442
|
-
const getOptimizedBackgroundImageAsset = (file, widthStyle, quality = 100, format) => {
|
|
443
|
-
|
|
456
|
+
const getOptimizedBackgroundImageAsset = (file, widthStyle, quality = '100%', format) => {
|
|
457
|
+
const qualityNumber = Number(quality.replace('%', ''));
|
|
458
|
+
if (!validateParams(file, qualityNumber, format)) ;
|
|
459
|
+
if (!validateParams(file, qualityNumber, format)) ;
|
|
444
460
|
const url = file.url;
|
|
445
461
|
const { width1x, width2x } = getWidths(widthStyle, file);
|
|
446
|
-
const imageUrl1x = getOptimizedImageUrl(url, width1x,
|
|
447
|
-
const imageUrl2x = getOptimizedImageUrl(url, width2x,
|
|
462
|
+
const imageUrl1x = getOptimizedImageUrl(url, width1x, qualityNumber, format);
|
|
463
|
+
const imageUrl2x = getOptimizedImageUrl(url, width2x, qualityNumber, format);
|
|
448
464
|
const srcSet = [`url(${imageUrl1x}) 1x`, `url(${imageUrl2x}) 2x`];
|
|
449
|
-
const
|
|
465
|
+
const returnedUrl = getOptimizedImageUrl(url, width2x, qualityNumber, format);
|
|
450
466
|
const optimizedBackgroundImageAsset = {
|
|
451
|
-
url:
|
|
467
|
+
url: returnedUrl,
|
|
452
468
|
srcSet,
|
|
453
469
|
file,
|
|
454
470
|
};
|
|
455
471
|
return optimizedBackgroundImageAsset;
|
|
456
|
-
function
|
|
457
|
-
|
|
458
|
-
|
|
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);
|
|
459
478
|
}
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
}
|
|
463
|
-
if (format && !SUPPORTED_IMAGE_FORMATS.includes(format)) {
|
|
464
|
-
throw Error(`Format must be one of ${SUPPORTED_IMAGE_FORMATS.join(', ')}`);
|
|
479
|
+
else {
|
|
480
|
+
width1x = Math.min(MAX_WIDTH_ALLOWED$1, intrinsicImageWidth);
|
|
465
481
|
}
|
|
466
|
-
|
|
482
|
+
width2x = Math.min(width1x * 2, intrinsicImageWidth);
|
|
483
|
+
return { width1x, width2x };
|
|
467
484
|
}
|
|
468
485
|
};
|
|
469
|
-
function getWidths(widthStyle, file) {
|
|
470
|
-
let width1x = 0;
|
|
471
|
-
let width2x = 0;
|
|
472
|
-
const intrinsicImageWidth = file.details.image.width;
|
|
473
|
-
if (widthStyle.endsWith('px')) {
|
|
474
|
-
width1x = Math.min(Number(widthStyle.replace('px', '')), intrinsicImageWidth);
|
|
475
|
-
}
|
|
476
|
-
else {
|
|
477
|
-
width1x = Math.min(MAX_WIDTH_ALLOWED$1, intrinsicImageWidth);
|
|
478
|
-
}
|
|
479
|
-
width2x = Math.min(width1x * 2, intrinsicImageWidth);
|
|
480
|
-
return { width1x, width2x };
|
|
481
|
-
}
|
|
482
486
|
|
|
483
487
|
const MAX_WIDTH_ALLOWED = 4000;
|
|
484
|
-
const getOptimizedImageAsset = (file, sizes, quality = 100, format) => {
|
|
485
|
-
|
|
488
|
+
const getOptimizedImageAsset = (file, sizes, quality = '100%', format) => {
|
|
489
|
+
const qualityNumber = Number(quality.replace('%', ''));
|
|
490
|
+
if (!validateParams(file, qualityNumber, format)) ;
|
|
486
491
|
const url = file.url;
|
|
487
492
|
const maxWidth = Math.min(file.details.image.width, MAX_WIDTH_ALLOWED);
|
|
488
493
|
const numOfParts = Math.max(2, Math.ceil(maxWidth / 500));
|
|
489
494
|
const widthParts = Array.from({ length: numOfParts }, (_, index) => Math.ceil((index + 1) * (maxWidth / numOfParts)));
|
|
490
495
|
const srcSet = sizes
|
|
491
|
-
? widthParts.map((width) => `${getOptimizedImageUrl(url, width,
|
|
496
|
+
? widthParts.map((width) => `${getOptimizedImageUrl(url, width, qualityNumber, format)} ${width}w`)
|
|
492
497
|
: [];
|
|
493
498
|
const intrinsicImageWidth = file.details.image.width;
|
|
494
499
|
if (intrinsicImageWidth > MAX_WIDTH_ALLOWED) {
|
|
495
|
-
srcSet.push(`${getOptimizedImageUrl(url, undefined,
|
|
500
|
+
srcSet.push(`${getOptimizedImageUrl(url, undefined, qualityNumber, format)} ${intrinsicImageWidth}w`);
|
|
496
501
|
}
|
|
497
|
-
const returnedUrl = getOptimizedImageUrl(url, file.details.image.width > 2000 ? 2000 : undefined,
|
|
502
|
+
const returnedUrl = getOptimizedImageUrl(url, file.details.image.width > 2000 ? 2000 : undefined, qualityNumber, format);
|
|
498
503
|
const optimizedImageAsset = {
|
|
499
504
|
url: returnedUrl,
|
|
500
505
|
srcSet,
|
|
@@ -502,18 +507,6 @@ const getOptimizedImageAsset = (file, sizes, quality = 100, format) => {
|
|
|
502
507
|
file,
|
|
503
508
|
};
|
|
504
509
|
return optimizedImageAsset;
|
|
505
|
-
function validateParams(file, quality, format) {
|
|
506
|
-
if (!file.details.image) {
|
|
507
|
-
throw Error('No image in file asset to transform');
|
|
508
|
-
}
|
|
509
|
-
if (quality < 0 || quality > 100) {
|
|
510
|
-
throw Error('Quality must be between 0 and 100');
|
|
511
|
-
}
|
|
512
|
-
if (format && !SUPPORTED_IMAGE_FORMATS.includes(format)) {
|
|
513
|
-
throw Error(`Format must be one of ${SUPPORTED_IMAGE_FORMATS.join(', ')}`);
|
|
514
|
-
}
|
|
515
|
-
return true;
|
|
516
|
-
}
|
|
517
510
|
};
|
|
518
511
|
|
|
519
512
|
const transformMedia = (asset, variables, resolveDesignValue, variableName, path) => {
|
|
@@ -529,7 +522,7 @@ const transformMedia = (asset, variables, resolveDesignValue, variableName, path
|
|
|
529
522
|
return;
|
|
530
523
|
}
|
|
531
524
|
try {
|
|
532
|
-
value = getOptimizedImageAsset(asset.fields.file, options.targetSize,
|
|
525
|
+
value = getOptimizedImageAsset(asset.fields.file, options.targetSize, options.quality, options.format);
|
|
533
526
|
return value;
|
|
534
527
|
}
|
|
535
528
|
catch (error) {
|
|
@@ -548,7 +541,7 @@ const transformMedia = (asset, variables, resolveDesignValue, variableName, path
|
|
|
548
541
|
return;
|
|
549
542
|
}
|
|
550
543
|
try {
|
|
551
|
-
value = getOptimizedBackgroundImageAsset(asset.fields.file, width,
|
|
544
|
+
value = getOptimizedBackgroundImageAsset(asset.fields.file, width, options.quality, options.format);
|
|
552
545
|
return value;
|
|
553
546
|
}
|
|
554
547
|
catch (error) {
|
|
@@ -671,6 +664,7 @@ const isExperienceEntry = (entry) => {
|
|
|
671
664
|
|
|
672
665
|
const supportedModes = ['delivery', 'preview', 'editor'];
|
|
673
666
|
|
|
667
|
+
// These styles get added to every component, user custom or contentful provided
|
|
674
668
|
const builtInStyles = {
|
|
675
669
|
cfVerticalAlignment: {
|
|
676
670
|
validations: {
|
|
@@ -781,13 +775,6 @@ const builtInStyles = {
|
|
|
781
775
|
description: 'The border of the section',
|
|
782
776
|
defaultValue: '0px solid rgba(0, 0, 0, 0)',
|
|
783
777
|
},
|
|
784
|
-
cfBorderRadius: {
|
|
785
|
-
displayName: 'Border Radius',
|
|
786
|
-
type: 'Text',
|
|
787
|
-
group: 'style',
|
|
788
|
-
description: 'The border radius of the section',
|
|
789
|
-
defaultValue: '0px',
|
|
790
|
-
},
|
|
791
778
|
cfGap: {
|
|
792
779
|
displayName: 'Gap',
|
|
793
780
|
type: 'Text',
|
|
@@ -854,8 +841,6 @@ const optionalBuiltInStyles = {
|
|
|
854
841
|
defaultValue: {
|
|
855
842
|
width: DEFAULT_IMAGE_WIDTH,
|
|
856
843
|
height: '100%',
|
|
857
|
-
objectPosition: 'center center',
|
|
858
|
-
quality: '100',
|
|
859
844
|
targetSize: DEFAULT_IMAGE_WIDTH,
|
|
860
845
|
},
|
|
861
846
|
},
|
|
@@ -871,10 +856,16 @@ const optionalBuiltInStyles = {
|
|
|
871
856
|
defaultValue: {
|
|
872
857
|
scaling: 'fill',
|
|
873
858
|
alignment: 'left top',
|
|
874
|
-
quality: '100',
|
|
875
859
|
targetSize: '2000px',
|
|
876
860
|
},
|
|
877
861
|
},
|
|
862
|
+
cfBorderRadius: {
|
|
863
|
+
displayName: 'Border Radius',
|
|
864
|
+
type: 'Text',
|
|
865
|
+
group: 'style',
|
|
866
|
+
description: 'The border radius of the section',
|
|
867
|
+
defaultValue: '0px',
|
|
868
|
+
},
|
|
878
869
|
cfLineHeight: {
|
|
879
870
|
displayName: 'Line Height',
|
|
880
871
|
type: 'Text',
|
|
@@ -970,11 +961,13 @@ const optionalBuiltInStyles = {
|
|
|
970
961
|
};
|
|
971
962
|
const sectionBuiltInStyles = {
|
|
972
963
|
...builtInStyles,
|
|
964
|
+
cfBorderRadius: optionalBuiltInStyles.cfBorderRadius,
|
|
973
965
|
cfBackgroundImageUrl: optionalBuiltInStyles.cfBackgroundImageUrl,
|
|
974
966
|
cfBackgroundImageOptions: optionalBuiltInStyles.cfBackgroundImageOptions,
|
|
975
967
|
};
|
|
976
968
|
const containerBuiltInStyles = {
|
|
977
969
|
...builtInStyles,
|
|
970
|
+
cfBorderRadius: optionalBuiltInStyles.cfBorderRadius,
|
|
978
971
|
cfBackgroundImageUrl: optionalBuiltInStyles.cfBackgroundImageUrl,
|
|
979
972
|
cfBackgroundImageOptions: optionalBuiltInStyles.cfBackgroundImageOptions,
|
|
980
973
|
cfMaxWidth: {
|
|
@@ -986,6 +979,7 @@ const containerBuiltInStyles = {
|
|
|
986
979
|
},
|
|
987
980
|
};
|
|
988
981
|
const singleColumnBuiltInStyles = {
|
|
982
|
+
cfBorderRadius: optionalBuiltInStyles.cfBorderRadius,
|
|
989
983
|
cfBackgroundImageUrl: optionalBuiltInStyles.cfBackgroundImageUrl,
|
|
990
984
|
cfBackgroundImageOptions: optionalBuiltInStyles.cfBackgroundImageOptions,
|
|
991
985
|
cfVerticalAlignment: {
|
|
@@ -1069,13 +1063,6 @@ const singleColumnBuiltInStyles = {
|
|
|
1069
1063
|
description: 'The border of the column',
|
|
1070
1064
|
defaultValue: '0px solid rgba(0, 0, 0, 0)',
|
|
1071
1065
|
},
|
|
1072
|
-
cfBorderRadius: {
|
|
1073
|
-
displayName: 'Border Radius',
|
|
1074
|
-
type: 'Text',
|
|
1075
|
-
group: 'style',
|
|
1076
|
-
description: 'The border radius of the column',
|
|
1077
|
-
defaultValue: '0px',
|
|
1078
|
-
},
|
|
1079
1066
|
cfGap: {
|
|
1080
1067
|
displayName: 'Gap',
|
|
1081
1068
|
type: 'Text',
|
|
@@ -1095,6 +1082,7 @@ const singleColumnBuiltInStyles = {
|
|
|
1095
1082
|
},
|
|
1096
1083
|
};
|
|
1097
1084
|
const columnsBuiltInStyles = {
|
|
1085
|
+
cfBorderRadius: optionalBuiltInStyles.cfBorderRadius,
|
|
1098
1086
|
cfBackgroundImageUrl: optionalBuiltInStyles.cfBackgroundImageUrl,
|
|
1099
1087
|
cfBackgroundImageOptions: optionalBuiltInStyles.cfBackgroundImageOptions,
|
|
1100
1088
|
cfMargin: {
|
|
@@ -1139,13 +1127,6 @@ const columnsBuiltInStyles = {
|
|
|
1139
1127
|
description: 'The border of the columns',
|
|
1140
1128
|
defaultValue: '0px solid rgba(0, 0, 0, 0)',
|
|
1141
1129
|
},
|
|
1142
|
-
cfBorderRadius: {
|
|
1143
|
-
displayName: 'Border Radius',
|
|
1144
|
-
type: 'Text',
|
|
1145
|
-
group: 'style',
|
|
1146
|
-
description: 'The border radius of the columns',
|
|
1147
|
-
defaultValue: '0px',
|
|
1148
|
-
},
|
|
1149
1130
|
cfGap: {
|
|
1150
1131
|
displayName: 'Gap',
|
|
1151
1132
|
type: 'Text',
|
|
@@ -2163,31 +2144,84 @@ function gatherAutoFetchedReferentsFromIncludes(deepReferences, entriesResponse)
|
|
|
2163
2144
|
}
|
|
2164
2145
|
|
|
2165
2146
|
const MIN_FETCH_LIMIT = 1;
|
|
2166
|
-
const
|
|
2167
|
-
if (entityType === 'Asset') {
|
|
2168
|
-
return client.getAssets({ ...query });
|
|
2169
|
-
}
|
|
2170
|
-
return client.withoutLinkResolution.getEntries({ ...query });
|
|
2171
|
-
};
|
|
2172
|
-
const fetchAllEntities = async ({ client, entityType, ids, locale, skip = 0, limit = 100, responseItems = [], }) => {
|
|
2147
|
+
const fetchAllEntries = async ({ client, ids, locale, skip = 0, limit = 100, responseItems = [], responseIncludes = { Entry: [], Asset: [] }, }) => {
|
|
2173
2148
|
try {
|
|
2174
|
-
if (!
|
|
2149
|
+
if (!client) {
|
|
2150
|
+
throw new Error('Failed to fetch experience entities. Required "client" parameter was not provided');
|
|
2151
|
+
}
|
|
2152
|
+
if (!ids.length) {
|
|
2175
2153
|
return {
|
|
2176
2154
|
items: [],
|
|
2155
|
+
includes: {
|
|
2156
|
+
Entry: [],
|
|
2157
|
+
Asset: [],
|
|
2158
|
+
},
|
|
2177
2159
|
};
|
|
2178
2160
|
}
|
|
2179
2161
|
const query = { 'sys.id[in]': ids, locale, limit, skip };
|
|
2180
|
-
const
|
|
2181
|
-
|
|
2182
|
-
|
|
2183
|
-
|
|
2184
|
-
|
|
2162
|
+
const { items, includes, total: responseTotal, } = await client.withoutLinkResolution.getEntries({ ...query });
|
|
2163
|
+
responseItems.push(...items);
|
|
2164
|
+
responseIncludes?.Entry?.push(...(includes?.Entry || []));
|
|
2165
|
+
responseIncludes?.Asset?.push(...(includes?.Asset || []));
|
|
2166
|
+
// E.g Total entries = 99
|
|
2167
|
+
// First fetch => { skip: 0, limit: 50, total: 99 } => 50 Entries fetched in Page 0
|
|
2168
|
+
// Total Entries fetched = 50, 49 remaining
|
|
2169
|
+
// 0(skip) + 50(limit) < 99(total) => Fetch again
|
|
2170
|
+
// Second fetch => { skip: 50, limit: 50, total: 99 } => 49 Entries fetched in Page 1
|
|
2171
|
+
// Total Entries fetched = 50(Page 0) + 49(Page 1) = 99, 0 remaining
|
|
2172
|
+
// 50(skip) + 50(limit) > 99(total) => Stop fetching
|
|
2173
|
+
if (skip + limit < responseTotal) {
|
|
2174
|
+
return await fetchAllEntries({
|
|
2175
|
+
client,
|
|
2176
|
+
ids,
|
|
2177
|
+
locale,
|
|
2178
|
+
skip: skip + limit,
|
|
2179
|
+
limit,
|
|
2180
|
+
responseItems,
|
|
2181
|
+
responseIncludes,
|
|
2182
|
+
});
|
|
2185
2183
|
}
|
|
2186
|
-
|
|
2187
|
-
|
|
2188
|
-
|
|
2184
|
+
const dedupedEntries = uniqBy(responseIncludes?.Entry, (entry) => entry.sys.id);
|
|
2185
|
+
const dedupedAssets = uniqBy(responseIncludes?.Asset, (asset) => asset.sys.id);
|
|
2186
|
+
return {
|
|
2187
|
+
items: responseItems,
|
|
2188
|
+
includes: {
|
|
2189
|
+
Entry: dedupedEntries,
|
|
2190
|
+
Asset: dedupedAssets,
|
|
2191
|
+
},
|
|
2192
|
+
};
|
|
2193
|
+
}
|
|
2194
|
+
catch (error) {
|
|
2195
|
+
if (error instanceof Error &&
|
|
2196
|
+
error.message.includes('size too big') &&
|
|
2197
|
+
limit > MIN_FETCH_LIMIT) {
|
|
2198
|
+
const newLimit = Math.max(MIN_FETCH_LIMIT, Math.floor(limit / 2));
|
|
2199
|
+
return fetchAllEntries({
|
|
2200
|
+
client,
|
|
2201
|
+
ids,
|
|
2202
|
+
locale,
|
|
2203
|
+
skip,
|
|
2204
|
+
limit: newLimit,
|
|
2205
|
+
responseItems,
|
|
2206
|
+
});
|
|
2207
|
+
}
|
|
2208
|
+
throw error;
|
|
2209
|
+
}
|
|
2210
|
+
};
|
|
2211
|
+
const fetchAllAssets = async ({ client, ids, locale, skip = 0, limit = 100, responseItems = [], }) => {
|
|
2212
|
+
try {
|
|
2213
|
+
if (!client) {
|
|
2214
|
+
throw new Error('Failed to fetch experience entities. Required "client" parameter was not provided');
|
|
2215
|
+
}
|
|
2216
|
+
if (!ids.length) {
|
|
2217
|
+
return { items: [] };
|
|
2218
|
+
}
|
|
2219
|
+
const query = { 'sys.id[in]': ids, locale, limit, skip };
|
|
2220
|
+
const { items, total: responseTotal } = await client.getAssets({ ...query });
|
|
2221
|
+
responseItems.push(...items);
|
|
2222
|
+
if (skip + limit < responseTotal) {
|
|
2223
|
+
return await fetchAllAssets({
|
|
2189
2224
|
client,
|
|
2190
|
-
entityType,
|
|
2191
2225
|
ids,
|
|
2192
2226
|
locale,
|
|
2193
2227
|
skip: skip + limit,
|
|
@@ -2204,9 +2238,8 @@ const fetchAllEntities = async ({ client, entityType, ids, locale, skip = 0, lim
|
|
|
2204
2238
|
error.message.includes('size too big') &&
|
|
2205
2239
|
limit > MIN_FETCH_LIMIT) {
|
|
2206
2240
|
const newLimit = Math.max(MIN_FETCH_LIMIT, Math.floor(limit / 2));
|
|
2207
|
-
return
|
|
2241
|
+
return fetchAllAssets({
|
|
2208
2242
|
client,
|
|
2209
|
-
entityType,
|
|
2210
2243
|
ids,
|
|
2211
2244
|
locale,
|
|
2212
2245
|
skip,
|
|
@@ -2214,7 +2247,7 @@ const fetchAllEntities = async ({ client, entityType, ids, locale, skip = 0, lim
|
|
|
2214
2247
|
responseItems,
|
|
2215
2248
|
});
|
|
2216
2249
|
}
|
|
2217
|
-
|
|
2250
|
+
throw error;
|
|
2218
2251
|
}
|
|
2219
2252
|
};
|
|
2220
2253
|
|
|
@@ -2243,8 +2276,8 @@ const fetchReferencedEntities = async ({ client, experienceEntry, locale, }) =>
|
|
|
2243
2276
|
}
|
|
2244
2277
|
}
|
|
2245
2278
|
const [entriesResponse, assetsResponse] = (await Promise.all([
|
|
2246
|
-
|
|
2247
|
-
|
|
2279
|
+
fetchAllEntries({ client, ids: entryIds, locale }),
|
|
2280
|
+
fetchAllAssets({ client, ids: assetIds, locale }),
|
|
2248
2281
|
]));
|
|
2249
2282
|
const { autoFetchedReferentAssets, autoFetchedReferentEntries } = gatherAutoFetchedReferentsFromIncludes(deepReferences, entriesResponse);
|
|
2250
2283
|
// Using client getEntries resolves all linked entry references, so we do not need to resolve entries in usedComponents
|