@contentful/experiences-core 1.5.0 → 1.5.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/README.md +13 -3
- package/dist/constants.d.ts +1 -0
- package/dist/constants.js +1 -0
- package/dist/constants.js.map +1 -1
- package/dist/entity/EntityStore.d.ts +1 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.js +357 -1
- package/dist/index.js.map +1 -1
- package/dist/registries/breakpointsRegistry.d.ts +20 -0
- package/package.json +3 -3
package/README.md
CHANGED
|
@@ -1,7 +1,17 @@
|
|
|
1
1
|
# @contentful/experiences-core
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
### Purpose
|
|
4
|
+
- To contain shared code and utilities across the Experiences packages such as constants, types, transformers, and hooks.
|
|
5
|
+
- This means additions to core should be framework agnostic. For example, code that is only compatible with React does not belong in the core package.
|
|
4
6
|
|
|
5
|
-
|
|
7
|
+
### Concepts
|
|
8
|
+
- **Deep binding**: Relates to the ability to resolve multiple references. Such an entry containing a reference to another entry which may also contain a reference to another entry and so on.
|
|
9
|
+
- **Component definition** Baseline definition to outline what is needed to define all component types whether it is a structure, built-in, or custom component.
|
|
10
|
+
- **Entity**: Contentful entries that get converted into an experience object that can be used within the experiences packages.
|
|
11
|
+
- **Fetchers**: The helper classes and functions in the Entity directory get consumed by the fetchers which get bundled up into either `fetchBySlug` or `fetchById`. The listed fetchers are the two main functions that are exposed to the end user in the SDK to fetch a user's experience which is stored in Contentful as an entry.
|
|
12
|
+
- **Registries**: An in-memory storage technique that the user can decide to provide for themselves or other personas in the editor canvas. Design tokens is an useful example where a user can provide their own thematic values with regards to text size, component sizes, spacing, colors, and borders in a JSON format that is resolved by the registry and provided as options in the UI editor sidebar.
|
|
13
|
+
- **Exporting types and constants**: Notice in the `package.json` there is a `typesVersions` definition that separates the constants and types as separated bundled packages where the rollup is defined in the `rollup.config.mjs` file. This effectively means in practice consuming the types and constants have different imports - namely `@contentful/experiences-core/constants` and `@contentful/experiences-core/types`.
|
|
6
14
|
|
|
7
|
-
|
|
15
|
+
### Relevant Contentful documentation links
|
|
16
|
+
- [Data structures](https://www.contentful.com/developers/docs/experiences/data-structures/)
|
|
17
|
+
- [Design tokens](https://www.contentful.com/developers/docs/experiences/design-tokens/)
|
package/dist/constants.d.ts
CHANGED
package/dist/constants.js
CHANGED
|
@@ -6,6 +6,7 @@ const SCROLL_STATES = {
|
|
|
6
6
|
const OUTGOING_EVENTS = {
|
|
7
7
|
Connected: 'connected',
|
|
8
8
|
DesignTokens: 'registerDesignTokens',
|
|
9
|
+
RegisteredBreakpoints: 'registeredBreakpoints',
|
|
9
10
|
HoveredSection: 'hoveredSection',
|
|
10
11
|
MouseMove: 'mouseMove',
|
|
11
12
|
NewHoveredElement: 'newHoveredElement',
|
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: '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 divider: {\n id: 'contentful-divider',\n name: 'Divider',\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 HYPERLINK_DEFAULT_PATTERN = `/{locale}/{entry.fields.slug}/`;\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,IAAA,KAAK,EAAE,aAAa;AACpB,IAAA,WAAW,EAAE,aAAa;AAC1B,IAAA,GAAG,EAAE,WAAW;EAChB;AAEW,MAAA,eAAe,GAAG;AAC7B,IAAA,SAAS,EAAE,WAAW;AACtB,IAAA,YAAY,EAAE,sBAAsB;AACpC,IAAA,cAAc,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,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,yBAAyB,GAAG,iCAAiC;AAEnE,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;;;;"}
|
|
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 RegisteredBreakpoints: 'registeredBreakpoints',\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 divider: {\n id: 'contentful-divider',\n name: 'Divider',\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 HYPERLINK_DEFAULT_PATTERN = `/{locale}/{entry.fields.slug}/`;\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,IAAA,KAAK,EAAE,aAAa;AACpB,IAAA,WAAW,EAAE,aAAa;AAC1B,IAAA,GAAG,EAAE,WAAW;EAChB;AAEW,MAAA,eAAe,GAAG;AAC7B,IAAA,SAAS,EAAE,WAAW;AACtB,IAAA,YAAY,EAAE,sBAAsB;AACpC,IAAA,qBAAqB,EAAE,uBAAuB;AAC9C,IAAA,cAAc,EAAE,gBAAgB;AAChC,IAAA,SAAS,EAAE,WAAW;AACtB,IAAA,iBAAiB,EAAE,mBAAmB;AACtC,IAAA,iBAAiB,EAAE,mBAAmB;AACtC,IAAA,oBAAoB,EAAE,sBAAsB;AAC5C,IAAA,0BAA0B,EAAE,4BAA4B;AACxD,IAAA,qBAAqB,EAAE,uBAAuB;AAC9C,IAAA,gBAAgB,EAAE,kBAAkB;AACpC,IAAA,cAAc,EAAE,gBAAgB;AAChC,IAAA,YAAY,EAAE,cAAc;AAC5B,IAAA,kCAAkC,EAAE,oCAAoC;AACxE,IAAA,iCAAiC,EAAE,mCAAmC;AACtE,IAAA,YAAY,EAAE,iBAAiB;AAC/B,IAAA,WAAW,EAAE,aAAa;AAC1B,IAAA,oBAAoB,EAAE,sBAAsB;AAC5C,IAAA,kBAAkB,EAAE,oBAAoB;AACxC,IAAA,kBAAkB,EAAE,oBAAoB;EACxC;AAEW,MAAA,eAAe,GAAG;AAC7B,IAAA,iBAAiB,EAAE,mBAAmB;AACtC,IAAA,iBAAiB,EAAE,sBAAsB;AACzC,IAAA,wBAAwB,EAAE,0BAA0B;AACpD,IAAA,qBAAqB,EAAE,uBAAuB;AAC9C,I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,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.d.ts
CHANGED
|
@@ -22,4 +22,5 @@ export { fetchBySlug } from './fetchers/fetchBySlug.js';
|
|
|
22
22
|
export { fetchById } from './fetchers/fetchById.js';
|
|
23
23
|
export { createExperience } from './fetchers/createExperience.js';
|
|
24
24
|
export { defineDesignTokens, designTokensRegistry, getDesignTokenRegistration, resetDesignTokenRegistry } from './registries/designTokenRegistry.js';
|
|
25
|
+
export { breakpointsRegistry, defineBreakpoints, getBreakpointRegistration, resetBreakpointsRegistry, runBreakpointsValidation } from './registries/breakpointsRegistry.js';
|
|
25
26
|
export { DeepReference, gatherDeepReferencesFromExperienceEntry, gatherDeepReferencesFromTree } from './deep-binding/DeepReference.js';
|
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 { z, ZodIssueCode } from 'zod';
|
|
3
4
|
import { uniqBy } from 'lodash-es';
|
|
4
5
|
|
|
5
6
|
const INCOMING_EVENTS = {
|
|
@@ -1262,6 +1263,361 @@ const resetDesignTokenRegistry = () => {
|
|
|
1262
1263
|
designTokensRegistry = {};
|
|
1263
1264
|
};
|
|
1264
1265
|
|
|
1266
|
+
// If more than one version is supported, use z.union
|
|
1267
|
+
const SchemaVersions = z.literal('2023-09-28');
|
|
1268
|
+
// Keep deprecated versions here just for reference
|
|
1269
|
+
z.union([
|
|
1270
|
+
z.literal('2023-08-23'),
|
|
1271
|
+
z.literal('2023-07-26'),
|
|
1272
|
+
z.literal('2023-06-27'),
|
|
1273
|
+
]);
|
|
1274
|
+
|
|
1275
|
+
const DefinitionPropertyTypeSchema = z.enum([
|
|
1276
|
+
'Text',
|
|
1277
|
+
'RichText',
|
|
1278
|
+
'Number',
|
|
1279
|
+
'Date',
|
|
1280
|
+
'Boolean',
|
|
1281
|
+
'Location',
|
|
1282
|
+
'Media',
|
|
1283
|
+
'Object',
|
|
1284
|
+
'Hyperlink',
|
|
1285
|
+
]);
|
|
1286
|
+
const DefinitionPropertyKeySchema = z
|
|
1287
|
+
.string()
|
|
1288
|
+
.regex(/^[a-zA-Z0-9-_]{1,32}$/, { message: 'Property needs to match: /^[a-zA-Z0-9-_]{1,32}$/' });
|
|
1289
|
+
z.object({
|
|
1290
|
+
id: DefinitionPropertyKeySchema,
|
|
1291
|
+
variables: z.record(DefinitionPropertyKeySchema, z.object({
|
|
1292
|
+
// TODO - extend with definition of validations and defaultValue
|
|
1293
|
+
displayName: z.string().optional(),
|
|
1294
|
+
type: DefinitionPropertyTypeSchema,
|
|
1295
|
+
description: z.string().optional(),
|
|
1296
|
+
group: z.string().optional(),
|
|
1297
|
+
})),
|
|
1298
|
+
});
|
|
1299
|
+
|
|
1300
|
+
const uuidKeySchema = z
|
|
1301
|
+
.string()
|
|
1302
|
+
.regex(/^[a-zA-Z0-9-_]{1,21}$/, { message: 'Does not match /^[a-zA-Z0-9-_]{1,21}$/' });
|
|
1303
|
+
/**
|
|
1304
|
+
* Property keys for imported components have a limit of 32 characters (to be implemented) while
|
|
1305
|
+
* property keys for patterns have a limit of 54 characters (<32-char-variabl-name>_<21-char-nanoid-id>).
|
|
1306
|
+
* Because we cannot distinguish between the two in the componentTree, we will use the larger limit for both.
|
|
1307
|
+
*/
|
|
1308
|
+
const propertyKeySchema = z
|
|
1309
|
+
.string()
|
|
1310
|
+
.regex(/^[a-zA-Z0-9-_]{1,54}$/, { message: 'Does not match /^[a-zA-Z0-9-_]{1,54}$/' });
|
|
1311
|
+
const DataSourceSchema = z.record(uuidKeySchema, z.object({
|
|
1312
|
+
sys: z.object({
|
|
1313
|
+
type: z.literal('Link'),
|
|
1314
|
+
id: z.string(),
|
|
1315
|
+
linkType: z.enum(['Entry', 'Asset']),
|
|
1316
|
+
}),
|
|
1317
|
+
}));
|
|
1318
|
+
const PrimitiveValueSchema = z.union([
|
|
1319
|
+
z.string(),
|
|
1320
|
+
z.boolean(),
|
|
1321
|
+
z.number(),
|
|
1322
|
+
z.record(z.any(), z.any()),
|
|
1323
|
+
z.undefined(),
|
|
1324
|
+
]);
|
|
1325
|
+
const ValuesByBreakpointSchema = z.record(z.lazy(() => PrimitiveValueSchema));
|
|
1326
|
+
const DesignValueSchema = z
|
|
1327
|
+
.object({
|
|
1328
|
+
type: z.literal('DesignValue'),
|
|
1329
|
+
valuesByBreakpoint: ValuesByBreakpointSchema,
|
|
1330
|
+
})
|
|
1331
|
+
.strict();
|
|
1332
|
+
const BoundValueSchema = z
|
|
1333
|
+
.object({
|
|
1334
|
+
type: z.literal('BoundValue'),
|
|
1335
|
+
path: z.string(),
|
|
1336
|
+
})
|
|
1337
|
+
.strict();
|
|
1338
|
+
const HyperlinkValueSchema = z
|
|
1339
|
+
.object({
|
|
1340
|
+
type: z.literal('HyperlinkValue'),
|
|
1341
|
+
linkTargetKey: z.string(),
|
|
1342
|
+
overrides: z.object({}).optional(),
|
|
1343
|
+
})
|
|
1344
|
+
.strict();
|
|
1345
|
+
const UnboundValueSchema = z
|
|
1346
|
+
.object({
|
|
1347
|
+
type: z.literal('UnboundValue'),
|
|
1348
|
+
key: z.string(),
|
|
1349
|
+
})
|
|
1350
|
+
.strict();
|
|
1351
|
+
const ComponentValueSchema = z
|
|
1352
|
+
.object({
|
|
1353
|
+
type: z.literal('ComponentValue'),
|
|
1354
|
+
key: z.string(),
|
|
1355
|
+
})
|
|
1356
|
+
.strict();
|
|
1357
|
+
const ComponentPropertyValueSchema = z.discriminatedUnion('type', [
|
|
1358
|
+
DesignValueSchema,
|
|
1359
|
+
BoundValueSchema,
|
|
1360
|
+
UnboundValueSchema,
|
|
1361
|
+
HyperlinkValueSchema,
|
|
1362
|
+
ComponentValueSchema,
|
|
1363
|
+
]);
|
|
1364
|
+
const BreakpointSchema = z
|
|
1365
|
+
.object({
|
|
1366
|
+
id: propertyKeySchema,
|
|
1367
|
+
query: z.string().regex(/^\*$|^<[0-9*]+px$/),
|
|
1368
|
+
previewSize: z.string(),
|
|
1369
|
+
displayName: z.string(),
|
|
1370
|
+
displayIconUrl: z.string().optional(),
|
|
1371
|
+
})
|
|
1372
|
+
.strict();
|
|
1373
|
+
const UnboundValuesSchema = z.record(uuidKeySchema, z.object({
|
|
1374
|
+
value: PrimitiveValueSchema,
|
|
1375
|
+
}));
|
|
1376
|
+
// Use helper schema to define a recursive schema with its type correctly below
|
|
1377
|
+
const BaseComponentTreeNodeSchema = z.object({
|
|
1378
|
+
definitionId: DefinitionPropertyKeySchema,
|
|
1379
|
+
displayName: z.string().optional(),
|
|
1380
|
+
slotId: z.string().optional(),
|
|
1381
|
+
variables: z.record(propertyKeySchema, ComponentPropertyValueSchema),
|
|
1382
|
+
});
|
|
1383
|
+
const ComponentTreeNodeSchema = BaseComponentTreeNodeSchema.extend({
|
|
1384
|
+
children: z.lazy(() => ComponentTreeNodeSchema.array()),
|
|
1385
|
+
});
|
|
1386
|
+
const ComponentSettingsSchema = z.object({
|
|
1387
|
+
variableDefinitions: z.record(z.string().regex(/^[a-zA-Z0-9-_]{1,54}$/), // Here the key is <variableName>_<nanoidId> so we need to allow for a longer length
|
|
1388
|
+
z.object({
|
|
1389
|
+
displayName: z.string().optional(),
|
|
1390
|
+
type: DefinitionPropertyTypeSchema,
|
|
1391
|
+
defaultValue: PrimitiveValueSchema.or(ComponentPropertyValueSchema).optional(),
|
|
1392
|
+
description: z.string().optional(),
|
|
1393
|
+
group: z.string().optional(),
|
|
1394
|
+
validations: z
|
|
1395
|
+
.object({
|
|
1396
|
+
required: z.boolean().optional(),
|
|
1397
|
+
format: z.literal('URL').optional(),
|
|
1398
|
+
in: z
|
|
1399
|
+
.array(z.object({
|
|
1400
|
+
value: z.union([z.string(), z.number()]),
|
|
1401
|
+
displayName: z.string().optional(),
|
|
1402
|
+
}))
|
|
1403
|
+
.optional(),
|
|
1404
|
+
})
|
|
1405
|
+
.optional(),
|
|
1406
|
+
})),
|
|
1407
|
+
});
|
|
1408
|
+
const UsedComponentsSchema = z.array(z.object({
|
|
1409
|
+
sys: z.object({
|
|
1410
|
+
type: z.literal('Link'),
|
|
1411
|
+
id: z.string(),
|
|
1412
|
+
linkType: z.literal('Entry'),
|
|
1413
|
+
}),
|
|
1414
|
+
}));
|
|
1415
|
+
const breakpointsRefinement = (value, ctx) => {
|
|
1416
|
+
if (!value.length || value[0].query !== '*') {
|
|
1417
|
+
ctx.addIssue({
|
|
1418
|
+
code: z.ZodIssueCode.custom,
|
|
1419
|
+
message: `The first breakpoint should include the following attributes: { "query": "*" }`,
|
|
1420
|
+
});
|
|
1421
|
+
}
|
|
1422
|
+
const hasDuplicateIds = value.some((currentBreakpoint, currentBreakpointIndex) => {
|
|
1423
|
+
// check if the current breakpoint id is found in the rest of the array
|
|
1424
|
+
const breakpointIndex = value.findIndex((breakpoint) => breakpoint.id === currentBreakpoint.id);
|
|
1425
|
+
return breakpointIndex !== currentBreakpointIndex;
|
|
1426
|
+
});
|
|
1427
|
+
if (hasDuplicateIds) {
|
|
1428
|
+
ctx.addIssue({
|
|
1429
|
+
code: z.ZodIssueCode.custom,
|
|
1430
|
+
message: `Breakpoint IDs must be unique`,
|
|
1431
|
+
});
|
|
1432
|
+
}
|
|
1433
|
+
// Extract the queries boundary by removing the special characters around it
|
|
1434
|
+
const queries = value.map((bp) => bp.query === '*' ? bp.query : parseInt(bp.query.replace(/px|<|>/, '')));
|
|
1435
|
+
// sort updates queries array in place so we need to create a copy
|
|
1436
|
+
const originalQueries = [...queries];
|
|
1437
|
+
queries.sort((q1, q2) => {
|
|
1438
|
+
if (q1 === '*') {
|
|
1439
|
+
return -1;
|
|
1440
|
+
}
|
|
1441
|
+
if (q2 === '*') {
|
|
1442
|
+
return 1;
|
|
1443
|
+
}
|
|
1444
|
+
return q1 > q2 ? -1 : 1;
|
|
1445
|
+
});
|
|
1446
|
+
if (originalQueries.join('') !== queries.join('')) {
|
|
1447
|
+
ctx.addIssue({
|
|
1448
|
+
code: z.ZodIssueCode.custom,
|
|
1449
|
+
message: `Breakpoints should be ordered from largest to smallest pixel value`,
|
|
1450
|
+
});
|
|
1451
|
+
}
|
|
1452
|
+
};
|
|
1453
|
+
const componentSettingsRefinement = (value, ctx) => {
|
|
1454
|
+
const { componentSettings, usedComponents } = value;
|
|
1455
|
+
if (!componentSettings || !usedComponents) {
|
|
1456
|
+
return;
|
|
1457
|
+
}
|
|
1458
|
+
const localeKey = Object.keys(componentSettings ?? {})[0];
|
|
1459
|
+
if (componentSettings[localeKey] !== undefined && usedComponents[localeKey] !== undefined) {
|
|
1460
|
+
ctx.addIssue({
|
|
1461
|
+
code: z.ZodIssueCode.custom,
|
|
1462
|
+
message: `'componentSettings' field cannot be used in conjunction with 'usedComponents' field`,
|
|
1463
|
+
path: ['componentSettings', localeKey],
|
|
1464
|
+
});
|
|
1465
|
+
}
|
|
1466
|
+
};
|
|
1467
|
+
const ComponentTreeSchema = z
|
|
1468
|
+
.object({
|
|
1469
|
+
breakpoints: z.array(BreakpointSchema).superRefine(breakpointsRefinement),
|
|
1470
|
+
children: z.array(ComponentTreeNodeSchema),
|
|
1471
|
+
schemaVersion: SchemaVersions,
|
|
1472
|
+
})
|
|
1473
|
+
.strict();
|
|
1474
|
+
const localeWrapper = (fieldSchema) => z.record(z.string(), fieldSchema);
|
|
1475
|
+
z
|
|
1476
|
+
.object({
|
|
1477
|
+
componentTree: localeWrapper(ComponentTreeSchema),
|
|
1478
|
+
dataSource: localeWrapper(DataSourceSchema),
|
|
1479
|
+
unboundValues: localeWrapper(UnboundValuesSchema),
|
|
1480
|
+
usedComponents: localeWrapper(UsedComponentsSchema).optional(),
|
|
1481
|
+
componentSettings: localeWrapper(ComponentSettingsSchema).optional(),
|
|
1482
|
+
})
|
|
1483
|
+
.superRefine(componentSettingsRefinement);
|
|
1484
|
+
|
|
1485
|
+
var CodeNames;
|
|
1486
|
+
(function (CodeNames) {
|
|
1487
|
+
CodeNames["Type"] = "type";
|
|
1488
|
+
CodeNames["Required"] = "required";
|
|
1489
|
+
CodeNames["Unexpected"] = "unexpected";
|
|
1490
|
+
CodeNames["Regex"] = "regex";
|
|
1491
|
+
CodeNames["In"] = "in";
|
|
1492
|
+
CodeNames["Size"] = "size";
|
|
1493
|
+
CodeNames["Custom"] = "custom";
|
|
1494
|
+
})(CodeNames || (CodeNames = {}));
|
|
1495
|
+
const convertInvalidType = (issue) => {
|
|
1496
|
+
const name = issue.received === 'undefined' ? CodeNames.Required : CodeNames.Type;
|
|
1497
|
+
const details = issue.received === 'undefined'
|
|
1498
|
+
? `The property "${issue.path.slice(-1)}" is required here`
|
|
1499
|
+
: `The type of "${issue.path.slice(-1)}" is incorrect, expected type: ${issue.expected}`;
|
|
1500
|
+
return {
|
|
1501
|
+
details: details,
|
|
1502
|
+
name: name,
|
|
1503
|
+
path: issue.path,
|
|
1504
|
+
value: issue.received.toString(),
|
|
1505
|
+
};
|
|
1506
|
+
};
|
|
1507
|
+
const convertUnrecognizedKeys = (issue) => {
|
|
1508
|
+
const missingProperties = issue.keys.map((k) => `"${k}"`).join(', ');
|
|
1509
|
+
return {
|
|
1510
|
+
details: issue.keys.length > 1
|
|
1511
|
+
? `The properties ${missingProperties} are not expected`
|
|
1512
|
+
: `The property ${missingProperties} is not expected`,
|
|
1513
|
+
name: CodeNames.Unexpected,
|
|
1514
|
+
path: issue.path,
|
|
1515
|
+
};
|
|
1516
|
+
};
|
|
1517
|
+
const convertInvalidString = (issue) => {
|
|
1518
|
+
return {
|
|
1519
|
+
details: issue.message || 'Invalid string',
|
|
1520
|
+
name: issue.validation === 'regex' ? CodeNames.Regex : CodeNames.Unexpected,
|
|
1521
|
+
path: issue.path,
|
|
1522
|
+
};
|
|
1523
|
+
};
|
|
1524
|
+
const convertInvalidEnumValue = (issue) => {
|
|
1525
|
+
return {
|
|
1526
|
+
details: issue.message || 'Value must be one of expected values',
|
|
1527
|
+
name: CodeNames.In,
|
|
1528
|
+
path: issue.path,
|
|
1529
|
+
value: issue.received.toString(),
|
|
1530
|
+
expected: issue.options,
|
|
1531
|
+
};
|
|
1532
|
+
};
|
|
1533
|
+
const convertInvalidLiteral = (issue) => {
|
|
1534
|
+
return {
|
|
1535
|
+
details: issue.message || 'Value must be one of expected values',
|
|
1536
|
+
name: CodeNames.In,
|
|
1537
|
+
path: issue.path,
|
|
1538
|
+
value: issue.received,
|
|
1539
|
+
expected: [issue.expected],
|
|
1540
|
+
};
|
|
1541
|
+
};
|
|
1542
|
+
const convertTooBig = (issue) => {
|
|
1543
|
+
return {
|
|
1544
|
+
details: issue.message || `Size should be at most ${issue.maximum}`,
|
|
1545
|
+
name: CodeNames.Size,
|
|
1546
|
+
path: issue.path,
|
|
1547
|
+
max: issue.maximum,
|
|
1548
|
+
};
|
|
1549
|
+
};
|
|
1550
|
+
const convertTooSmall = (issue) => {
|
|
1551
|
+
return {
|
|
1552
|
+
details: issue.message || `Size should be at least ${issue.minimum}`,
|
|
1553
|
+
name: CodeNames.Size,
|
|
1554
|
+
path: issue.path,
|
|
1555
|
+
min: issue.minimum,
|
|
1556
|
+
};
|
|
1557
|
+
};
|
|
1558
|
+
const defaultConversion = (issue) => {
|
|
1559
|
+
return {
|
|
1560
|
+
details: issue.message || 'An unexpected error occurred',
|
|
1561
|
+
name: CodeNames.Custom,
|
|
1562
|
+
path: issue.path.map(String),
|
|
1563
|
+
};
|
|
1564
|
+
};
|
|
1565
|
+
const zodToContentfulError = (issue) => {
|
|
1566
|
+
switch (issue.code) {
|
|
1567
|
+
case ZodIssueCode.invalid_type:
|
|
1568
|
+
return convertInvalidType(issue);
|
|
1569
|
+
case ZodIssueCode.unrecognized_keys:
|
|
1570
|
+
return convertUnrecognizedKeys(issue);
|
|
1571
|
+
case ZodIssueCode.invalid_enum_value:
|
|
1572
|
+
return convertInvalidEnumValue(issue);
|
|
1573
|
+
case ZodIssueCode.invalid_string:
|
|
1574
|
+
return convertInvalidString(issue);
|
|
1575
|
+
case ZodIssueCode.too_small:
|
|
1576
|
+
return convertTooSmall(issue);
|
|
1577
|
+
case ZodIssueCode.too_big:
|
|
1578
|
+
return convertTooBig(issue);
|
|
1579
|
+
case ZodIssueCode.invalid_literal:
|
|
1580
|
+
return convertInvalidLiteral(issue);
|
|
1581
|
+
default:
|
|
1582
|
+
return defaultConversion(issue);
|
|
1583
|
+
}
|
|
1584
|
+
};
|
|
1585
|
+
const validateBreakpointsDefinition = (breakpoints) => {
|
|
1586
|
+
const result = z
|
|
1587
|
+
.array(BreakpointSchema)
|
|
1588
|
+
.superRefine(breakpointsRefinement)
|
|
1589
|
+
.safeParse(breakpoints);
|
|
1590
|
+
if (!result.success) {
|
|
1591
|
+
return {
|
|
1592
|
+
success: false,
|
|
1593
|
+
errors: result.error.issues.map(zodToContentfulError),
|
|
1594
|
+
};
|
|
1595
|
+
}
|
|
1596
|
+
return { success: true };
|
|
1597
|
+
};
|
|
1598
|
+
|
|
1599
|
+
let breakpointsRegistry = [];
|
|
1600
|
+
/**
|
|
1601
|
+
* Register custom breakpoints
|
|
1602
|
+
* @param breakpoints - [{[key:string]: string}]
|
|
1603
|
+
* @returns void
|
|
1604
|
+
*/
|
|
1605
|
+
const defineBreakpoints = (breakpoints) => {
|
|
1606
|
+
Object.assign(breakpointsRegistry, breakpoints);
|
|
1607
|
+
};
|
|
1608
|
+
const runBreakpointsValidation = () => {
|
|
1609
|
+
const validation = validateBreakpointsDefinition(breakpointsRegistry);
|
|
1610
|
+
if (!validation.success) {
|
|
1611
|
+
throw new Error(`Invalid breakpoints definition. Failed with errors: \n${JSON.stringify(validation.errors, null, 2)}`);
|
|
1612
|
+
}
|
|
1613
|
+
};
|
|
1614
|
+
// Used in the tests to get a breakpoint registration
|
|
1615
|
+
const getBreakpointRegistration = (id) => breakpointsRegistry.find((breakpoint) => breakpoint.id === id);
|
|
1616
|
+
// Used in the tests to reset the registry
|
|
1617
|
+
const resetBreakpointsRegistry = () => {
|
|
1618
|
+
breakpointsRegistry = [];
|
|
1619
|
+
};
|
|
1620
|
+
|
|
1265
1621
|
const MEDIA_QUERY_REGEXP = /(<|>)(\d{1,})(px|cm|mm|in|pt|pc)$/;
|
|
1266
1622
|
const toCSSMediaQuery = ({ query }) => {
|
|
1267
1623
|
if (query === '*')
|
|
@@ -2539,5 +2895,5 @@ async function fetchById({ client, experienceTypeId, id, localeCode, }) {
|
|
|
2539
2895
|
}
|
|
2540
2896
|
}
|
|
2541
2897
|
|
|
2542
|
-
export { DeepReference, EditorModeEntityStore, EntityStore, EntityStoreBase, MEDIA_QUERY_REGEXP, VisualEditorMode, addLocale, buildCfStyles, buildStyleTag, buildTemplate, builtInStyles, calculateNodeDefaultHeight, checkIsAssembly, checkIsAssemblyDefinition, checkIsAssemblyEntry, checkIsAssemblyNode, columnsBuiltInStyles, columnsDefinition, containerBuiltInStyles, containerDefinition, createExperience, defineDesignTokens, designTokensRegistry, dividerBuiltInStyles, dividerDefinition, doesMismatchMessageSchema, fetchById, fetchBySlug, findOutermostCoordinates, gatherDeepReferencesFromExperienceEntry, gatherDeepReferencesFromTree, generateRandomId, getActiveBreakpointIndex, getDataFromTree, getDesignTokenRegistration, getElementCoordinates, getFallbackBreakpointIndex, getInsertionData, getTemplateValue, getValueForBreakpoint, isComponentAllowedOnRoot, isContentfulStructureComponent, isDeepPath, isEmptyStructureWithRelativeHeight, isExperienceEntry, isLink, isLinkToAsset, lastPathNamedSegmentEq, mediaQueryMatcher, optionalBuiltInStyles, parseDataSourcePathIntoFieldset, parseDataSourcePathWithL1DeepBindings, resetDesignTokenRegistry, resolveHyperlinkPattern, sectionBuiltInStyles, sectionDefinition, sendMessage, singleColumnBuiltInStyles, singleColumnDefinition, supportedModes, toCSSAttribute, transformBoundContentValue, tryParseMessage, validateExperienceBuilderConfig };
|
|
2898
|
+
export { DeepReference, EditorModeEntityStore, EntityStore, EntityStoreBase, MEDIA_QUERY_REGEXP, VisualEditorMode, addLocale, breakpointsRegistry, buildCfStyles, buildStyleTag, buildTemplate, builtInStyles, calculateNodeDefaultHeight, checkIsAssembly, checkIsAssemblyDefinition, checkIsAssemblyEntry, checkIsAssemblyNode, columnsBuiltInStyles, columnsDefinition, containerBuiltInStyles, containerDefinition, createExperience, defineBreakpoints, defineDesignTokens, designTokensRegistry, dividerBuiltInStyles, dividerDefinition, doesMismatchMessageSchema, fetchById, fetchBySlug, findOutermostCoordinates, gatherDeepReferencesFromExperienceEntry, gatherDeepReferencesFromTree, generateRandomId, getActiveBreakpointIndex, getBreakpointRegistration, getDataFromTree, getDesignTokenRegistration, getElementCoordinates, getFallbackBreakpointIndex, getInsertionData, getTemplateValue, getValueForBreakpoint, isComponentAllowedOnRoot, isContentfulStructureComponent, isDeepPath, isEmptyStructureWithRelativeHeight, isExperienceEntry, isLink, isLinkToAsset, lastPathNamedSegmentEq, mediaQueryMatcher, optionalBuiltInStyles, parseDataSourcePathIntoFieldset, parseDataSourcePathWithL1DeepBindings, resetBreakpointsRegistry, resetDesignTokenRegistry, resolveHyperlinkPattern, runBreakpointsValidation, sectionBuiltInStyles, sectionDefinition, sendMessage, singleColumnBuiltInStyles, singleColumnDefinition, supportedModes, toCSSAttribute, transformBoundContentValue, tryParseMessage, validateExperienceBuilderConfig };
|
|
2543
2899
|
//# sourceMappingURL=index.js.map
|