@contentful/experiences-sdk-react 3.1.0-dev-20250807T0841-78e6af6.0 → 3.1.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/ExperienceRoot.js +1 -1
- package/dist/ExperienceRoot.js.map +1 -1
- package/dist/blocks/editor/VisualEditorLoader.js +2 -2
- package/dist/blocks/editor/VisualEditorLoader.js.map +1 -1
- package/dist/blocks/editor/VisualEditorRoot.js +2 -2
- package/dist/blocks/editor/VisualEditorRoot.js.map +1 -1
- package/dist/core/componentRegistry.js +2 -6
- package/dist/core/componentRegistry.js.map +1 -1
- package/dist/core/preview/assemblyUtils.js +3 -2
- package/dist/core/preview/assemblyUtils.js.map +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/sdkVersion.js +1 -1
- package/dist/sdkVersion.js.map +1 -1
- package/dist/src/blocks/editor/VisualEditorLoader.d.ts +2 -0
- package/dist/src/blocks/editor/VisualEditorRoot.d.ts +2 -0
- package/dist/src/sdkVersion.d.ts +1 -1
- package/dist/src/utils/prebindingUtils.d.ts +2 -3
- package/dist/src/utils/withComponentWrapper.d.ts +3 -5
- package/dist/utils/prebindingUtils.js +9 -4
- package/dist/utils/prebindingUtils.js.map +1 -1
- package/dist/utils/withComponentWrapper.js +12 -15
- package/dist/utils/withComponentWrapper.js.map +1 -1
- package/package.json +6 -7
package/dist/ExperienceRoot.js
CHANGED
|
@@ -18,7 +18,7 @@ const ExperienceRoot = ({ locale, experience, visualEditorMode = VisualEditorMod
|
|
|
18
18
|
mode,
|
|
19
19
|
});
|
|
20
20
|
if (mode === StudioCanvasMode.EDITOR || mode === StudioCanvasMode.READ_ONLY) {
|
|
21
|
-
return (jsx(VisualEditorRoot, { experience: experienceObject, visualEditorMode: visualEditorMode, initialLocale: locale }));
|
|
21
|
+
return (jsx(VisualEditorRoot, { experience: experienceObject, visualEditorMode: visualEditorMode, initialLocale: locale, canvasMode: mode }));
|
|
22
22
|
}
|
|
23
23
|
if (!experienceObject)
|
|
24
24
|
return null;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ExperienceRoot.js","sources":["../../src/ExperienceRoot.tsx"],"sourcesContent":["'use client';\nimport React from 'react';\nimport {\n VisualEditorMode,\n createExperience,\n validateExperienceBuilderConfig,\n debug as cfDebug,\n} from '@contentful/experiences-core';\nimport { EntityStore } from '@contentful/experiences-core';\nimport type { Experience } from '@contentful/experiences-core/types';\nimport { PreviewDeliveryRoot } from './blocks/preview/PreviewDeliveryRoot';\nimport VisualEditorRoot from './blocks/editor/VisualEditorRoot';\nimport { useDetectCanvasMode } from './hooks/useDetectCanvasMode';\nimport { StudioCanvasMode } from '@contentful/experiences-core/constants';\n\ntype ExperienceRootProps = {\n experience?: Experience<EntityStore> | string | null;\n locale: string;\n visualEditorMode?: VisualEditorMode;\n /** Enables extra logging in the SDK to support troubleshooting.\n * This option is not recommended for production environments as it\n * will result in too many unnecessary logs being produced during runtime.\n * Default: false\n */\n debug?: boolean;\n};\n\nexport const ExperienceRoot = ({\n locale,\n experience,\n visualEditorMode = VisualEditorMode.LazyLoad,\n debug,\n}: ExperienceRootProps) => {\n const mode = useDetectCanvasMode();\n\n if (typeof debug === 'boolean') {\n cfDebug.setEnabled(debug);\n }\n\n //If experience is passed in as a JSON string, recreate it to an experience object\n const experienceObject =\n typeof experience === 'string' ? createExperience(experience) : experience;\n\n validateExperienceBuilderConfig({\n locale,\n mode,\n });\n\n if (mode === StudioCanvasMode.EDITOR || mode === StudioCanvasMode.READ_ONLY) {\n return (\n <VisualEditorRoot\n experience={experienceObject as Experience<EntityStore> | undefined}\n visualEditorMode={visualEditorMode}\n initialLocale={locale}\n />\n );\n }\n\n if (!experienceObject) return null;\n\n return <PreviewDeliveryRoot locale={locale} experience={experienceObject} />;\n};\n"],"names":[],"mappings":";;;;;;;;AA2Ba;AAMX;AAEA;AACE;;;AAIF;AAGA;;;AAGC;AAED;
|
|
1
|
+
{"version":3,"file":"ExperienceRoot.js","sources":["../../src/ExperienceRoot.tsx"],"sourcesContent":["'use client';\nimport React from 'react';\nimport {\n VisualEditorMode,\n createExperience,\n validateExperienceBuilderConfig,\n debug as cfDebug,\n} from '@contentful/experiences-core';\nimport { EntityStore } from '@contentful/experiences-core';\nimport type { Experience } from '@contentful/experiences-core/types';\nimport { PreviewDeliveryRoot } from './blocks/preview/PreviewDeliveryRoot';\nimport VisualEditorRoot from './blocks/editor/VisualEditorRoot';\nimport { useDetectCanvasMode } from './hooks/useDetectCanvasMode';\nimport { StudioCanvasMode } from '@contentful/experiences-core/constants';\n\ntype ExperienceRootProps = {\n experience?: Experience<EntityStore> | string | null;\n locale: string;\n visualEditorMode?: VisualEditorMode;\n /** Enables extra logging in the SDK to support troubleshooting.\n * This option is not recommended for production environments as it\n * will result in too many unnecessary logs being produced during runtime.\n * Default: false\n */\n debug?: boolean;\n};\n\nexport const ExperienceRoot = ({\n locale,\n experience,\n visualEditorMode = VisualEditorMode.LazyLoad,\n debug,\n}: ExperienceRootProps) => {\n const mode = useDetectCanvasMode();\n\n if (typeof debug === 'boolean') {\n cfDebug.setEnabled(debug);\n }\n\n //If experience is passed in as a JSON string, recreate it to an experience object\n const experienceObject =\n typeof experience === 'string' ? createExperience(experience) : experience;\n\n validateExperienceBuilderConfig({\n locale,\n mode,\n });\n\n if (mode === StudioCanvasMode.EDITOR || mode === StudioCanvasMode.READ_ONLY) {\n return (\n <VisualEditorRoot\n experience={experienceObject as Experience<EntityStore> | undefined}\n visualEditorMode={visualEditorMode}\n initialLocale={locale}\n canvasMode={mode}\n />\n );\n }\n\n if (!experienceObject) return null;\n\n return <PreviewDeliveryRoot locale={locale} experience={experienceObject} />;\n};\n"],"names":[],"mappings":";;;;;;;;AA2Ba;AAMX;AAEA;AACE;;;AAIF;AAGA;;;AAGC;AAED;;;AAWA;AAAuB;;AAGzB;;"}
|
|
@@ -2,7 +2,7 @@ import { jsx } from 'react/jsx-runtime';
|
|
|
2
2
|
import { useState, useEffect } from 'react';
|
|
3
3
|
import { VisualEditorMode, inMemoryEntitiesStore } from '@contentful/experiences-core';
|
|
4
4
|
|
|
5
|
-
const VisualEditorLoader = ({ visualEditorMode, experience, }) => {
|
|
5
|
+
const VisualEditorLoader = ({ visualEditorMode, experience, canvasMode, }) => {
|
|
6
6
|
const [VisualEditor, setVisualEditor] = useState(null);
|
|
7
7
|
useEffect(() => {
|
|
8
8
|
// Dynamically import the visual editor based on the configured mode
|
|
@@ -21,7 +21,7 @@ const VisualEditorLoader = ({ visualEditorMode, experience, }) => {
|
|
|
21
21
|
}, [visualEditorMode]);
|
|
22
22
|
if (!VisualEditor)
|
|
23
23
|
return null;
|
|
24
|
-
return jsx(VisualEditor, { experience: experience, inMemoryEntitiesStore: inMemoryEntitiesStore });
|
|
24
|
+
return (jsx(VisualEditor, { experience: experience, inMemoryEntitiesStore: inMemoryEntitiesStore, canvasMode: canvasMode }));
|
|
25
25
|
};
|
|
26
26
|
|
|
27
27
|
export { VisualEditorLoader, VisualEditorLoader as default };
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"VisualEditorLoader.js","sources":["../../../../src/blocks/editor/VisualEditorLoader.tsx"],"sourcesContent":["import React, { useEffect, useState } from 'react';\nimport {\n type InMemoryEntitiesStore,\n type EntityStore,\n inMemoryEntitiesStore,\n VisualEditorMode,\n} from '@contentful/experiences-core';\nimport type { Experience } from '@contentful/experiences-core/types';\n\ntype VisualEditorLoaderProps = {\n visualEditorMode: VisualEditorMode;\n experience?: Experience<EntityStore>;\n};\n\nexport const VisualEditorLoader: React.FC<VisualEditorLoaderProps> = ({\n visualEditorMode,\n experience,\n}) => {\n const [VisualEditor, setVisualEditor] = useState<React.ComponentType<{\n experience?: Experience<EntityStore>;\n inMemoryEntitiesStore?: InMemoryEntitiesStore;\n }> | null>(null);\n\n useEffect(() => {\n // Dynamically import the visual editor based on the configured mode\n switch (visualEditorMode) {\n case VisualEditorMode.InjectScript:\n import('./VisualEditorInjectScript').then((module) => {\n setVisualEditor(() => module.default);\n });\n break;\n\n // VisualEditorMode.LazyLoad:\n default:\n import('@contentful/experiences-visual-editor-react').then((module) => {\n setVisualEditor(() => module.default);\n });\n }\n }, [visualEditorMode]);\n\n if (!VisualEditor) return null;\n\n return <VisualEditor
|
|
1
|
+
{"version":3,"file":"VisualEditorLoader.js","sources":["../../../../src/blocks/editor/VisualEditorLoader.tsx"],"sourcesContent":["import React, { useEffect, useState } from 'react';\nimport {\n type InMemoryEntitiesStore,\n type EntityStore,\n inMemoryEntitiesStore,\n VisualEditorMode,\n} from '@contentful/experiences-core';\nimport type { Experience } from '@contentful/experiences-core/types';\nimport type { StudioCanvasMode } from '@contentful/experiences-core/constants';\n\ntype VisualEditorLoaderProps = {\n visualEditorMode: VisualEditorMode;\n canvasMode?: StudioCanvasMode;\n experience?: Experience<EntityStore>;\n};\n\nexport const VisualEditorLoader: React.FC<VisualEditorLoaderProps> = ({\n visualEditorMode,\n experience,\n canvasMode,\n}) => {\n const [VisualEditor, setVisualEditor] = useState<React.ComponentType<{\n experience?: Experience<EntityStore>;\n inMemoryEntitiesStore?: InMemoryEntitiesStore;\n canvasMode?: StudioCanvasMode;\n }> | null>(null);\n\n useEffect(() => {\n // Dynamically import the visual editor based on the configured mode\n switch (visualEditorMode) {\n case VisualEditorMode.InjectScript:\n import('./VisualEditorInjectScript').then((module) => {\n setVisualEditor(() => module.default);\n });\n break;\n\n // VisualEditorMode.LazyLoad:\n default:\n import('@contentful/experiences-visual-editor-react').then((module) => {\n setVisualEditor(() => module.default);\n });\n }\n }, [visualEditorMode]);\n\n if (!VisualEditor) return null;\n\n return (\n <VisualEditor\n experience={experience}\n inMemoryEntitiesStore={inMemoryEntitiesStore}\n canvasMode={canvasMode}\n />\n );\n};\n\nexport default VisualEditorLoader;\n"],"names":["_jsx"],"mappings":";;;;AAgBO,MAAM,kBAAkB,GAAsC,CAAC,EACpE,gBAAgB,EAChB,UAAU,EACV,UAAU,GACX,KAAI;IACH,MAAM,CAAC,YAAY,EAAE,eAAe,CAAC,GAAG,QAAQ,CAIrC,IAAI,CAAC,CAAC;IAEjB,SAAS,CAAC,MAAK;;QAEb,QAAQ,gBAAgB;YACtB,KAAK,gBAAgB,CAAC,YAAY;gBAChC,OAAO,+BAA4B,CAAC,CAAC,IAAI,CAAC,CAAC,MAAM,KAAI;oBACnD,eAAe,CAAC,MAAM,MAAM,CAAC,OAAO,CAAC,CAAC;AACxC,iBAAC,CAAC,CAAC;gBACH,MAAM;;AAGR,YAAA;gBACE,OAAO,6CAA6C,CAAC,CAAC,IAAI,CAAC,CAAC,MAAM,KAAI;oBACpE,eAAe,CAAC,MAAM,MAAM,CAAC,OAAO,CAAC,CAAC;AACxC,iBAAC,CAAC,CAAC;SACN;AACH,KAAC,EAAE,CAAC,gBAAgB,CAAC,CAAC,CAAC;AAEvB,IAAA,IAAI,CAAC,YAAY;AAAE,QAAA,OAAO,IAAI,CAAC;AAE/B,IAAA,QACEA,GAAC,CAAA,YAAY,EACX,EAAA,UAAU,EAAE,UAAU,EACtB,qBAAqB,EAAE,qBAAqB,EAC5C,UAAU,EAAE,UAAU,EAAA,CACtB,EACF;AACJ;;;;"}
|
|
@@ -4,13 +4,13 @@ import { ErrorBoundary } from '../../components/ErrorBoundary.js';
|
|
|
4
4
|
import { useInitializeVisualEditor } from '../../hooks/useInitializeVisualEditor.js';
|
|
5
5
|
|
|
6
6
|
const VisualEditorLoader = React.lazy(() => import('./VisualEditorLoader.js'));
|
|
7
|
-
const VisualEditorRoot = ({ visualEditorMode, experience, initialLocale, }) => {
|
|
7
|
+
const VisualEditorRoot = ({ visualEditorMode, canvasMode, experience, initialLocale, }) => {
|
|
8
8
|
const initialEntities = experience?.entityStore?.entities || [];
|
|
9
9
|
useInitializeVisualEditor({
|
|
10
10
|
initialLocale,
|
|
11
11
|
initialEntities,
|
|
12
12
|
});
|
|
13
|
-
return (jsx(ErrorBoundary, { children: jsx(Suspense, { fallback: jsx("div", { children: "Loading..." }), children: jsx(VisualEditorLoader, { experience: experience, visualEditorMode: visualEditorMode }) }) }));
|
|
13
|
+
return (jsx(ErrorBoundary, { children: jsx(Suspense, { fallback: jsx("div", { children: "Loading..." }), children: jsx(VisualEditorLoader, { experience: experience, visualEditorMode: visualEditorMode, canvasMode: canvasMode }) }) }));
|
|
14
14
|
};
|
|
15
15
|
|
|
16
16
|
export { VisualEditorRoot, VisualEditorRoot as default };
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"VisualEditorRoot.js","sources":["../../../../src/blocks/editor/VisualEditorRoot.tsx"],"sourcesContent":["import React, { Suspense } from 'react';\nimport { EntityStore, VisualEditorMode } from '@contentful/experiences-core';\nimport { ErrorBoundary } from '../../components/ErrorBoundary';\nimport { useInitializeVisualEditor } from '../../hooks/useInitializeVisualEditor';\nimport type { Experience } from '@contentful/experiences-core/types';\n\nconst VisualEditorLoader = React.lazy(() => import('./VisualEditorLoader'));\n\ntype VisualEditorRootProps = {\n visualEditorMode: VisualEditorMode;\n experience?: Experience<EntityStore>;\n initialLocale: string;\n};\n\nexport const VisualEditorRoot: React.FC<VisualEditorRootProps> = ({\n visualEditorMode,\n experience,\n initialLocale,\n}) => {\n const initialEntities = experience?.entityStore?.entities || [];\n\n useInitializeVisualEditor({\n initialLocale,\n initialEntities,\n });\n\n return (\n <ErrorBoundary>\n <Suspense fallback={<div>Loading...</div>}>\n <VisualEditorLoader
|
|
1
|
+
{"version":3,"file":"VisualEditorRoot.js","sources":["../../../../src/blocks/editor/VisualEditorRoot.tsx"],"sourcesContent":["import React, { Suspense } from 'react';\nimport { EntityStore, VisualEditorMode } from '@contentful/experiences-core';\nimport { ErrorBoundary } from '../../components/ErrorBoundary';\nimport { useInitializeVisualEditor } from '../../hooks/useInitializeVisualEditor';\nimport type { Experience } from '@contentful/experiences-core/types';\nimport type { StudioCanvasMode } from '@contentful/experiences-core/constants';\n\nconst VisualEditorLoader = React.lazy(() => import('./VisualEditorLoader'));\n\ntype VisualEditorRootProps = {\n visualEditorMode: VisualEditorMode;\n canvasMode?: StudioCanvasMode;\n experience?: Experience<EntityStore>;\n initialLocale: string;\n};\n\nexport const VisualEditorRoot: React.FC<VisualEditorRootProps> = ({\n visualEditorMode,\n canvasMode,\n experience,\n initialLocale,\n}) => {\n const initialEntities = experience?.entityStore?.entities || [];\n\n useInitializeVisualEditor({\n initialLocale,\n initialEntities,\n });\n\n return (\n <ErrorBoundary>\n <Suspense fallback={<div>Loading...</div>}>\n <VisualEditorLoader\n experience={experience}\n visualEditorMode={visualEditorMode}\n canvasMode={canvasMode}\n />\n </Suspense>\n </ErrorBoundary>\n );\n};\n\nexport default VisualEditorRoot;\n"],"names":["_jsx"],"mappings":";;;;;AAOA,MAAM,kBAAkB,GAAG,KAAK,CAAC,IAAI,CAAC,MAAM,OAAO,yBAAsB,CAAC,CAAC,CAAC;AASrE,MAAM,gBAAgB,GAAoC,CAAC,EAChE,gBAAgB,EAChB,UAAU,EACV,UAAU,EACV,aAAa,GACd,KAAI;IACH,MAAM,eAAe,GAAG,UAAU,EAAE,WAAW,EAAE,QAAQ,IAAI,EAAE,CAAC;AAEhE,IAAA,yBAAyB,CAAC;QACxB,aAAa;QACb,eAAe;AAChB,KAAA,CAAC,CAAC;AAEH,IAAA,QACEA,GAAA,CAAC,aAAa,EAAA,EAAA,QAAA,EACZA,GAAC,CAAA,QAAQ,EAAC,EAAA,QAAQ,EAAEA,GAAA,CAAA,KAAA,EAAA,EAAA,QAAA,EAAA,YAAA,EAAA,CAAqB,EACvC,QAAA,EAAAA,GAAA,CAAC,kBAAkB,EAAA,EACjB,UAAU,EAAE,UAAU,EACtB,gBAAgB,EAAE,gBAAgB,EAClC,UAAU,EAAE,UAAU,EAAA,CACtB,EACO,CAAA,EAAA,CACG,EAChB;AACJ;;;;"}
|
|
@@ -21,9 +21,6 @@ const applyComponentDefinitionFallbacks = (componentDefinition) => {
|
|
|
21
21
|
return clone;
|
|
22
22
|
};
|
|
23
23
|
const applyBuiltInStyleDefinitions = (componentDefinition) => {
|
|
24
|
-
if (componentDefinition.id === CONTENTFUL_COMPONENTS.container.id) {
|
|
25
|
-
return componentDefinition;
|
|
26
|
-
}
|
|
27
24
|
const clone = cloneObject(componentDefinition);
|
|
28
25
|
// set margin built-in style by default
|
|
29
26
|
if (!clone.builtInStyles) {
|
|
@@ -103,14 +100,13 @@ const DEFAULT_COMPONENT_REGISTRATIONS = {
|
|
|
103
100
|
wrapComponent: false,
|
|
104
101
|
},
|
|
105
102
|
}),
|
|
106
|
-
divider: {
|
|
107
|
-
// Don't wrap this component `withComponentWrapper`. Need to explicitly ignore dragProps
|
|
103
|
+
divider: enrichComponentDefinition({
|
|
108
104
|
component: Components.ContentfulDivider,
|
|
109
105
|
definition: dividerDefinition,
|
|
110
106
|
options: {
|
|
111
107
|
wrapComponent: false,
|
|
112
108
|
},
|
|
113
|
-
},
|
|
109
|
+
}),
|
|
114
110
|
carousel: enrichComponentDefinition({
|
|
115
111
|
component: Components.Carousel,
|
|
116
112
|
definition: Components.carouselDefinition,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"componentRegistry.js","sources":["../../../src/core/componentRegistry.ts"],"sourcesContent":["import * as Components from '@contentful/experiences-components-react';\nimport type {\n ComponentRegistration,\n ComponentDefinition,\n ComponentRegistrationOptions,\n DesignTokensDefinition,\n} from '@contentful/experiences-core/types';\nimport {\n OUTGOING_EVENTS,\n INTERNAL_EVENTS,\n CONTENTFUL_COMPONENTS,\n ASSEMBLY_DEFAULT_CATEGORY,\n} from '@contentful/experiences-core/constants';\nimport {\n builtInStyles as builtInStyleDefinitions,\n designTokensRegistry,\n breakpointsRegistry,\n optionalBuiltInStyles,\n sendMessage,\n} from '@contentful/experiences-core';\nimport { validateComponentDefinition } from '@contentful/experiences-validators';\nimport { withComponentWrapper } from '../utils/withComponentWrapper';\nimport { SDK_VERSION } from '../constants';\nimport {\n sectionDefinition,\n containerDefinition,\n columnsDefinition,\n singleColumnDefinition,\n dividerDefinition,\n} from '@contentful/experiences-components-react';\n\nconst CssVarRegex = /var\\(--[\\w-]+\\)/;\n\nconst cloneObject = <T>(targetObject: T): T => {\n if (typeof structuredClone !== 'undefined') {\n return structuredClone(targetObject);\n }\n\n return JSON.parse(JSON.stringify(targetObject));\n};\n\nconst applyComponentDefinitionFallbacks = (componentDefinition: ComponentDefinition) => {\n const clone = cloneObject(componentDefinition);\n for (const variable of Object.values(clone.variables)) {\n variable.group = variable.group ?? 'content';\n }\n return clone;\n};\n\nconst applyBuiltInStyleDefinitions = (componentDefinition: ComponentDefinition) => {\n if (componentDefinition.id === CONTENTFUL_COMPONENTS.container.id) {\n return componentDefinition;\n }\n\n const clone = cloneObject(componentDefinition);\n\n // set margin built-in style by default\n if (!clone.builtInStyles) {\n clone.builtInStyles = ['cfMargin'];\n }\n\n if (!clone.variables) {\n clone.variables = {};\n }\n\n // Enforce the presence of this property for toggling visibility on any node\n clone.variables['cfVisibility'] = builtInStyleDefinitions['cfVisibility'];\n\n for (const style of clone.builtInStyles || []) {\n if (builtInStyleDefinitions[style]) {\n clone.variables[style] = builtInStyleDefinitions[style] as any; // TODO: fix type\n }\n if (optionalBuiltInStyles[style]) {\n clone.variables[style] = optionalBuiltInStyles[style] as any; // TODO: fix type\n }\n }\n return clone;\n};\n\nexport const enrichComponentDefinition = ({\n component,\n definition,\n options,\n}: ComponentRegistration): ComponentRegistration => {\n const definitionWithFallbacks = applyComponentDefinitionFallbacks(definition);\n const definitionWithBuiltInStyles = applyBuiltInStyleDefinitions(definitionWithFallbacks);\n return {\n component: withComponentWrapper(component, options),\n definition: definitionWithBuiltInStyles,\n options,\n };\n};\n\nconst DEFAULT_COMPONENT_REGISTRATIONS = {\n container: {\n component: Components.ContentfulContainer,\n definition: containerDefinition,\n },\n section: {\n component: Components.ContentfulContainer,\n definition: sectionDefinition,\n },\n columns: {\n component: Components.Columns,\n definition: columnsDefinition,\n },\n singleColumn: {\n component: Components.SingleColumn,\n definition: singleColumnDefinition,\n },\n button: enrichComponentDefinition({\n component: Components.Button,\n definition: Components.ButtonComponentDefinition,\n options: {\n wrapComponent: false,\n },\n }),\n heading: enrichComponentDefinition({\n component: Components.Heading,\n definition: Components.HeadingComponentDefinition,\n options: {\n wrapComponent: false,\n },\n }),\n image: enrichComponentDefinition({\n component: Components.Image,\n definition: Components.ImageComponentDefinition,\n options: { wrapComponent: false },\n }),\n richText: enrichComponentDefinition({\n component: Components.RichText,\n definition: Components.RichTextComponentDefinition,\n options: {\n wrapComponent: false,\n },\n }),\n text: enrichComponentDefinition({\n component: Components.Text,\n definition: Components.TextComponentDefinition,\n options: {\n wrapComponent: false,\n },\n }),\n divider: {\n // Don't wrap this component `withComponentWrapper`. Need to explicitly ignore dragProps\n component: Components.ContentfulDivider,\n definition: dividerDefinition,\n options: {\n wrapComponent: false,\n },\n },\n carousel: enrichComponentDefinition({\n component: Components.Carousel,\n definition: Components.carouselDefinition,\n options: {\n wrapComponent: false,\n },\n }),\n} satisfies Record<string, ComponentRegistration>;\n\n// pre-filling with the default component registrations\nexport const componentRegistry = new Map<string, ComponentRegistration>([\n [DEFAULT_COMPONENT_REGISTRATIONS.section.definition.id, DEFAULT_COMPONENT_REGISTRATIONS.section],\n [\n DEFAULT_COMPONENT_REGISTRATIONS.container.definition.id,\n DEFAULT_COMPONENT_REGISTRATIONS.container,\n ],\n [\n DEFAULT_COMPONENT_REGISTRATIONS.singleColumn.definition.id,\n DEFAULT_COMPONENT_REGISTRATIONS.singleColumn,\n ],\n [DEFAULT_COMPONENT_REGISTRATIONS.columns.definition.id, DEFAULT_COMPONENT_REGISTRATIONS.columns],\n [DEFAULT_COMPONENT_REGISTRATIONS.button.definition.id, DEFAULT_COMPONENT_REGISTRATIONS.button],\n [DEFAULT_COMPONENT_REGISTRATIONS.heading.definition.id, DEFAULT_COMPONENT_REGISTRATIONS.heading],\n [DEFAULT_COMPONENT_REGISTRATIONS.image.definition.id, DEFAULT_COMPONENT_REGISTRATIONS.image],\n [\n DEFAULT_COMPONENT_REGISTRATIONS.richText.definition.id,\n DEFAULT_COMPONENT_REGISTRATIONS.richText,\n ],\n [DEFAULT_COMPONENT_REGISTRATIONS.text.definition.id, DEFAULT_COMPONENT_REGISTRATIONS.text],\n [DEFAULT_COMPONENT_REGISTRATIONS.divider.definition.id, DEFAULT_COMPONENT_REGISTRATIONS.divider],\n]);\n\nexport const optionalBuiltInComponents = [\n DEFAULT_COMPONENT_REGISTRATIONS.button.definition.id,\n DEFAULT_COMPONENT_REGISTRATIONS.heading.definition.id,\n DEFAULT_COMPONENT_REGISTRATIONS.image.definition.id,\n DEFAULT_COMPONENT_REGISTRATIONS.richText.definition.id,\n DEFAULT_COMPONENT_REGISTRATIONS.text.definition.id,\n DEFAULT_COMPONENT_REGISTRATIONS.divider.definition.id,\n];\n\nexport const sendRegisteredComponentsMessage = () => {\n // Send the definitions (without components) via the connection message to the experience builder\n const registeredDefinitions = Array.from(componentRegistry.values())\n .map(({ definition }) => definition)\n // Pattern definitions are empty placeholder within the SDK without variables\n // We don't send those to the editor as they would overwrite the actual correct definitions.\n .filter((definition) => definition.category !== ASSEMBLY_DEFAULT_CATEGORY);\n\n sendMessage(OUTGOING_EVENTS.RegisteredComponents, {\n definitions: registeredDefinitions,\n });\n};\n\nexport const runRegisteredComponentValidations = () => {\n Array.from(componentRegistry.values()).map(({ definition }) => {\n const validation = validateComponentDefinition(definition);\n if (!validation.success) {\n throw new Error(\n `Invalid component definition for component '${definition.name}'. Failed with errors: \\n${JSON.stringify(validation.errors, null, 2)}`,\n );\n }\n });\n};\n\nconst getSingleCssVariableValue = (\n element: HTMLDivElement,\n cssVariableValue: string,\n cssAttribute: any,\n) => {\n element.style[cssAttribute] = cssVariableValue;\n const styles = getComputedStyle(element);\n const resolvedValue = styles.getPropertyValue(cssAttribute);\n return resolvedValue;\n};\n\nconst getAllCssVariableValues = (\n element: HTMLDivElement,\n cssVariable: Record<string, string>,\n cssAttribute: any,\n) => {\n const resolvedCssVariables = {} as Record<string, string>;\n\n Object.keys(cssVariable).forEach((key) => {\n const cssVariableValue = cssVariable[key];\n if (CssVarRegex.test(cssVariableValue)) {\n const resolvedValue = getSingleCssVariableValue(element, cssVariableValue, cssAttribute);\n resolvedCssVariables[cssVariableValue] = resolvedValue;\n }\n });\n return resolvedCssVariables;\n};\n\ntype CssMapType = {\n variable?: Record<string, string>;\n property: string;\n};\n\nconst resolveCssVariables = (designTokensDefinition: DesignTokensDefinition) => {\n const {\n spacing,\n sizing,\n color,\n borderRadius,\n fontSize,\n lineHeight,\n letterSpacing,\n textColor,\n border,\n } = designTokensDefinition;\n const resolvedCssVariables = {} as Record<string, string>;\n\n // Create an element\n const element = document.createElement('div');\n document.body.appendChild(element);\n\n const cssProperties: CssMapType[] = [\n { variable: spacing, property: 'margin' },\n { variable: sizing, property: 'width' },\n { variable: color, property: 'background-color' },\n { variable: borderRadius, property: 'border-radius' },\n { variable: fontSize, property: 'font-size' },\n { variable: lineHeight, property: 'line-height' },\n { variable: letterSpacing, property: 'letter-spacing' },\n { variable: textColor, property: 'color' },\n ];\n\n cssProperties.forEach(({ variable, property }) => {\n if (variable) {\n const rawResolvedValues = getAllCssVariableValues(element, variable, property);\n Object.assign(resolvedCssVariables, rawResolvedValues);\n }\n });\n\n if (border) {\n const tempResolvedValue = {} as Record<string, string>;\n Object.keys(border).forEach((borderKey) => {\n const { width, style, color } = border[borderKey];\n\n if (width && CssVarRegex.test(width)) {\n const resolvedValue = getSingleCssVariableValue(element, width, 'border-width');\n tempResolvedValue[width] = resolvedValue;\n }\n if (style && CssVarRegex.test(style)) {\n const resolvedValue = getSingleCssVariableValue(element, style, 'border-style');\n tempResolvedValue[style] = resolvedValue;\n }\n if (color && CssVarRegex.test(color)) {\n const resolvedValue = getSingleCssVariableValue(element, color, 'border-color');\n tempResolvedValue[color] = resolvedValue;\n }\n Object.assign(resolvedCssVariables, tempResolvedValue);\n });\n }\n\n document.body.removeChild(element);\n return resolvedCssVariables;\n};\n\nexport const sendConnectedEventWithRegisteredComponents = () => {\n // Send the definitions (without components) via the connection message to the experience builder\n const registeredDefinitions = Array.from(componentRegistry.values()).map(\n ({ definition }) => definition,\n );\n\n sendMessage(OUTGOING_EVENTS.Connected, {\n sdkVersion: SDK_VERSION,\n definitions: registeredDefinitions,\n });\n\n sendMessage(OUTGOING_EVENTS.RegisteredBreakpoints, {\n breakpoints: breakpointsRegistry,\n });\n\n sendMessage(OUTGOING_EVENTS.DesignTokens, {\n designTokens: designTokensRegistry,\n resolvedCssVariables: resolveCssVariables(designTokensRegistry),\n });\n};\n\n/**\n * Registers multiple components and their component definitions at once\n * @param componentRegistrations - ComponentRegistration[]\n * @returns void\n */\nexport const defineComponents = (\n componentRegistrations: ComponentRegistration[],\n options?: ComponentRegistrationOptions,\n) => {\n if (options?.experimentalComponents?.carousel) {\n componentRegistry.set(\n CONTENTFUL_COMPONENTS.carousel.id,\n DEFAULT_COMPONENT_REGISTRATIONS.carousel,\n );\n }\n\n if (options?.enabledBuiltInComponents) {\n for (const id of optionalBuiltInComponents) {\n if (!options.enabledBuiltInComponents.includes(id)) {\n componentRegistry.delete(id);\n }\n }\n }\n\n for (const registration of componentRegistrations) {\n // Fill definitions with fallbacks values\n const enrichedComponentRegistration = enrichComponentDefinition(registration);\n\n componentRegistry.set(\n enrichedComponentRegistration.definition.id,\n enrichedComponentRegistration,\n );\n }\n\n if (typeof window !== 'undefined') {\n window.dispatchEvent(new CustomEvent(INTERNAL_EVENTS.ComponentsRegistered));\n }\n};\n\n/**\n * use this function only in tests\n */\nexport const resetComponentRegistry = () => {\n componentRegistry.clear();\n for (const registration of Object.values(DEFAULT_COMPONENT_REGISTRATIONS)) {\n componentRegistry.set(registration.definition.id, registration);\n }\n};\n\nexport const getComponentRegistration = (id: string) => componentRegistry.get(id);\n\nexport const addComponentRegistration = (componentRegistration: ComponentRegistration) => {\n componentRegistry.set(componentRegistration.definition.id, componentRegistration);\n};\n\nexport const createAssemblyRegistration = ({\n definitionId,\n definitionName,\n component,\n}: {\n definitionId: string;\n definitionName?: string;\n component: ComponentRegistration['component'];\n}) => {\n const componentRegistration = componentRegistry.get(definitionId);\n\n if (componentRegistration) {\n return componentRegistration;\n }\n\n const definition = {\n id: definitionId,\n name: definitionName || 'Component',\n variables: {},\n children: true,\n category: ASSEMBLY_DEFAULT_CATEGORY,\n };\n\n addComponentRegistration({ component, definition });\n\n return componentRegistry.get(definitionId);\n};\n"],"names":["builtInStyleDefinitions"],"mappings":";;;;;;;;AA+BA,MAAM,WAAW,GAAG,iBAAiB,CAAC;AAEtC,MAAM,WAAW,GAAG,CAAI,YAAe,KAAO;AAC5C,IAAA,IAAI,OAAO,eAAe,KAAK,WAAW,EAAE;AAC1C,QAAA,OAAO,eAAe,CAAC,YAAY,CAAC,CAAC;KACtC;IAED,OAAO,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,SAAS,CAAC,YAAY,CAAC,CAAC,CAAC;AAClD,CAAC,CAAC;AAEF,MAAM,iCAAiC,GAAG,CAAC,mBAAwC,KAAI;AACrF,IAAA,MAAM,KAAK,GAAG,WAAW,CAAC,mBAAmB,CAAC,CAAC;AAC/C,IAAA,KAAK,MAAM,QAAQ,IAAI,MAAM,CAAC,MAAM,CAAC,KAAK,CAAC,SAAS,CAAC,EAAE;QACrD,QAAQ,CAAC,KAAK,GAAG,QAAQ,CAAC,KAAK,IAAI,SAAS,CAAC;KAC9C;AACD,IAAA,OAAO,KAAK,CAAC;AACf,CAAC,CAAC;AAEF,MAAM,4BAA4B,GAAG,CAAC,mBAAwC,KAAI;IAChF,IAAI,mBAAmB,CAAC,EAAE,KAAK,qBAAqB,CAAC,SAAS,CAAC,EAAE,EAAE;AACjE,QAAA,OAAO,mBAAmB,CAAC;KAC5B;AAED,IAAA,MAAM,KAAK,GAAG,WAAW,CAAC,mBAAmB,CAAC,CAAC;;AAG/C,IAAA,IAAI,CAAC,KAAK,CAAC,aAAa,EAAE;AACxB,QAAA,KAAK,CAAC,aAAa,GAAG,CAAC,UAAU,CAAC,CAAC;KACp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,MAAM,0BAA0B,GAAG,CAAC,EACzC,YAAY,EACZ,cAAc,EACd,SAAS,GAKV,KAAI;IACH,MAAM,qBAAqB,GAAG,iBAAiB,CAAC,GAAG,CAAC,YAAY,CAAC,CAAC;IAElE,IAAI,qBAAqB,EAAE;AACzB,QAAA,OAAO,qBAAqB,CAAC;KAC9B;AAED,IAAA,MAAM,UAAU,GAAG;AACjB,QAAA,EAAE,EAAE,YAAY;QAChB,IAAI,EAAE,cAAc,IAAI,WAAW;AACnC,QAAA,SAAS,EAAE,EAAE;AACb,QAAA,QAAQ,EAAE,IAAI;AACd,QAAA,QAAQ,EAAE,yBAAyB;KACpC,CAAC;AAEF,IAAA,wBAAwB,CAAC,EAAE,SAAS,EAAE,UAAU,EAAE,CAAC,CAAC;AAEpD,IAAA,OAAO,iBAAiB,CAAC,GAAG,CAAC,YAAY,CAAC,CAAC;AAC7C;;;;"}
|
|
1
|
+
{"version":3,"file":"componentRegistry.js","sources":["../../../src/core/componentRegistry.ts"],"sourcesContent":["import * as Components from '@contentful/experiences-components-react';\nimport type {\n ComponentRegistration,\n ComponentDefinition,\n ComponentRegistrationOptions,\n DesignTokensDefinition,\n} from '@contentful/experiences-core/types';\nimport {\n OUTGOING_EVENTS,\n INTERNAL_EVENTS,\n CONTENTFUL_COMPONENTS,\n ASSEMBLY_DEFAULT_CATEGORY,\n} from '@contentful/experiences-core/constants';\nimport {\n builtInStyles as builtInStyleDefinitions,\n designTokensRegistry,\n breakpointsRegistry,\n optionalBuiltInStyles,\n sendMessage,\n} from '@contentful/experiences-core';\nimport { validateComponentDefinition } from '@contentful/experiences-validators';\nimport { withComponentWrapper } from '../utils/withComponentWrapper';\nimport { SDK_VERSION } from '../constants';\nimport {\n sectionDefinition,\n containerDefinition,\n columnsDefinition,\n singleColumnDefinition,\n dividerDefinition,\n} from '@contentful/experiences-components-react';\n\nconst CssVarRegex = /var\\(--[\\w-]+\\)/;\n\nconst cloneObject = <T>(targetObject: T): T => {\n if (typeof structuredClone !== 'undefined') {\n return structuredClone(targetObject);\n }\n\n return JSON.parse(JSON.stringify(targetObject));\n};\n\nconst applyComponentDefinitionFallbacks = (componentDefinition: ComponentDefinition) => {\n const clone = cloneObject(componentDefinition);\n for (const variable of Object.values(clone.variables)) {\n variable.group = variable.group ?? 'content';\n }\n return clone;\n};\n\nconst applyBuiltInStyleDefinitions = (componentDefinition: ComponentDefinition) => {\n const clone = cloneObject(componentDefinition);\n\n // set margin built-in style by default\n if (!clone.builtInStyles) {\n clone.builtInStyles = ['cfMargin'];\n }\n\n if (!clone.variables) {\n clone.variables = {};\n }\n\n // Enforce the presence of this property for toggling visibility on any node\n clone.variables['cfVisibility'] = builtInStyleDefinitions['cfVisibility'];\n\n for (const style of clone.builtInStyles || []) {\n if (builtInStyleDefinitions[style]) {\n clone.variables[style] = builtInStyleDefinitions[style] as any; // TODO: fix type\n }\n if (optionalBuiltInStyles[style]) {\n clone.variables[style] = optionalBuiltInStyles[style] as any; // TODO: fix type\n }\n }\n return clone;\n};\n\nexport const enrichComponentDefinition = ({\n component,\n definition,\n options,\n}: ComponentRegistration): ComponentRegistration => {\n const definitionWithFallbacks = applyComponentDefinitionFallbacks(definition);\n const definitionWithBuiltInStyles = applyBuiltInStyleDefinitions(definitionWithFallbacks);\n return {\n component: withComponentWrapper(component, options),\n definition: definitionWithBuiltInStyles,\n options,\n };\n};\n\nconst DEFAULT_COMPONENT_REGISTRATIONS = {\n container: {\n component: Components.ContentfulContainer,\n definition: containerDefinition,\n },\n section: {\n component: Components.ContentfulContainer,\n definition: sectionDefinition,\n },\n columns: {\n component: Components.Columns,\n definition: columnsDefinition,\n },\n singleColumn: {\n component: Components.SingleColumn,\n definition: singleColumnDefinition,\n },\n button: enrichComponentDefinition({\n component: Components.Button,\n definition: Components.ButtonComponentDefinition,\n options: {\n wrapComponent: false,\n },\n }),\n heading: enrichComponentDefinition({\n component: Components.Heading,\n definition: Components.HeadingComponentDefinition,\n options: {\n wrapComponent: false,\n },\n }),\n image: enrichComponentDefinition({\n component: Components.Image,\n definition: Components.ImageComponentDefinition,\n options: { wrapComponent: false },\n }),\n richText: enrichComponentDefinition({\n component: Components.RichText,\n definition: Components.RichTextComponentDefinition,\n options: {\n wrapComponent: false,\n },\n }),\n text: enrichComponentDefinition({\n component: Components.Text,\n definition: Components.TextComponentDefinition,\n options: {\n wrapComponent: false,\n },\n }),\n divider: enrichComponentDefinition({\n component: Components.ContentfulDivider,\n definition: dividerDefinition,\n options: {\n wrapComponent: false,\n },\n }),\n carousel: enrichComponentDefinition({\n component: Components.Carousel,\n definition: Components.carouselDefinition,\n options: {\n wrapComponent: false,\n },\n }),\n} satisfies Record<string, ComponentRegistration>;\n\n// pre-filling with the default component registrations\nexport const componentRegistry = new Map<string, ComponentRegistration>([\n [DEFAULT_COMPONENT_REGISTRATIONS.section.definition.id, DEFAULT_COMPONENT_REGISTRATIONS.section],\n [\n DEFAULT_COMPONENT_REGISTRATIONS.container.definition.id,\n DEFAULT_COMPONENT_REGISTRATIONS.container,\n ],\n [\n DEFAULT_COMPONENT_REGISTRATIONS.singleColumn.definition.id,\n DEFAULT_COMPONENT_REGISTRATIONS.singleColumn,\n ],\n [DEFAULT_COMPONENT_REGISTRATIONS.columns.definition.id, DEFAULT_COMPONENT_REGISTRATIONS.columns],\n [DEFAULT_COMPONENT_REGISTRATIONS.button.definition.id, DEFAULT_COMPONENT_REGISTRATIONS.button],\n [DEFAULT_COMPONENT_REGISTRATIONS.heading.definition.id, DEFAULT_COMPONENT_REGISTRATIONS.heading],\n [DEFAULT_COMPONENT_REGISTRATIONS.image.definition.id, DEFAULT_COMPONENT_REGISTRATIONS.image],\n [\n DEFAULT_COMPONENT_REGISTRATIONS.richText.definition.id,\n DEFAULT_COMPONENT_REGISTRATIONS.richText,\n ],\n [DEFAULT_COMPONENT_REGISTRATIONS.text.definition.id, DEFAULT_COMPONENT_REGISTRATIONS.text],\n [DEFAULT_COMPONENT_REGISTRATIONS.divider.definition.id, DEFAULT_COMPONENT_REGISTRATIONS.divider],\n]);\n\nexport const optionalBuiltInComponents = [\n DEFAULT_COMPONENT_REGISTRATIONS.button.definition.id,\n DEFAULT_COMPONENT_REGISTRATIONS.heading.definition.id,\n DEFAULT_COMPONENT_REGISTRATIONS.image.definition.id,\n DEFAULT_COMPONENT_REGISTRATIONS.richText.definition.id,\n DEFAULT_COMPONENT_REGISTRATIONS.text.definition.id,\n DEFAULT_COMPONENT_REGISTRATIONS.divider.definition.id,\n];\n\nexport const sendRegisteredComponentsMessage = () => {\n // Send the definitions (without components) via the connection message to the experience builder\n const registeredDefinitions = Array.from(componentRegistry.values())\n .map(({ definition }) => definition)\n // Pattern definitions are empty placeholder within the SDK without variables\n // We don't send those to the editor as they would overwrite the actual correct definitions.\n .filter((definition) => definition.category !== ASSEMBLY_DEFAULT_CATEGORY);\n\n sendMessage(OUTGOING_EVENTS.RegisteredComponents, {\n definitions: registeredDefinitions,\n });\n};\n\nexport const runRegisteredComponentValidations = () => {\n Array.from(componentRegistry.values()).map(({ definition }) => {\n const validation = validateComponentDefinition(definition);\n if (!validation.success) {\n throw new Error(\n `Invalid component definition for component '${definition.name}'. Failed with errors: \\n${JSON.stringify(validation.errors, null, 2)}`,\n );\n }\n });\n};\n\nconst getSingleCssVariableValue = (\n element: HTMLDivElement,\n cssVariableValue: string,\n cssAttribute: any,\n) => {\n element.style[cssAttribute] = cssVariableValue;\n const styles = getComputedStyle(element);\n const resolvedValue = styles.getPropertyValue(cssAttribute);\n return resolvedValue;\n};\n\nconst getAllCssVariableValues = (\n element: HTMLDivElement,\n cssVariable: Record<string, string>,\n cssAttribute: any,\n) => {\n const resolvedCssVariables = {} as Record<string, string>;\n\n Object.keys(cssVariable).forEach((key) => {\n const cssVariableValue = cssVariable[key];\n if (CssVarRegex.test(cssVariableValue)) {\n const resolvedValue = getSingleCssVariableValue(element, cssVariableValue, cssAttribute);\n resolvedCssVariables[cssVariableValue] = resolvedValue;\n }\n });\n return resolvedCssVariables;\n};\n\ntype CssMapType = {\n variable?: Record<string, string>;\n property: string;\n};\n\nconst resolveCssVariables = (designTokensDefinition: DesignTokensDefinition) => {\n const {\n spacing,\n sizing,\n color,\n borderRadius,\n fontSize,\n lineHeight,\n letterSpacing,\n textColor,\n border,\n } = designTokensDefinition;\n const resolvedCssVariables = {} as Record<string, string>;\n\n // Create an element\n const element = document.createElement('div');\n document.body.appendChild(element);\n\n const cssProperties: CssMapType[] = [\n { variable: spacing, property: 'margin' },\n { variable: sizing, property: 'width' },\n { variable: color, property: 'background-color' },\n { variable: borderRadius, property: 'border-radius' },\n { variable: fontSize, property: 'font-size' },\n { variable: lineHeight, property: 'line-height' },\n { variable: letterSpacing, property: 'letter-spacing' },\n { variable: textColor, property: 'color' },\n ];\n\n cssProperties.forEach(({ variable, property }) => {\n if (variable) {\n const rawResolvedValues = getAllCssVariableValues(element, variable, property);\n Object.assign(resolvedCssVariables, rawResolvedValues);\n }\n });\n\n if (border) {\n const tempResolvedValue = {} as Record<string, string>;\n Object.keys(border).forEach((borderKey) => {\n const { width, style, color } = border[borderKey];\n\n if (width && CssVarRegex.test(width)) {\n const resolvedValue = getSingleCssVariableValue(element, width, 'border-width');\n tempResolvedValue[width] = resolvedValue;\n }\n if (style && CssVarRegex.test(style)) {\n const resolvedValue = getSingleCssVariableValue(element, style, 'border-style');\n tempResolvedValue[style] = resolvedValue;\n }\n if (color && CssVarRegex.test(color)) {\n const resolvedValue = getSingleCssVariableValue(element, color, 'border-color');\n tempResolvedValue[color] = resolvedValue;\n }\n Object.assign(resolvedCssVariables, tempResolvedValue);\n });\n }\n\n document.body.removeChild(element);\n return resolvedCssVariables;\n};\n\nexport const sendConnectedEventWithRegisteredComponents = () => {\n // Send the definitions (without components) via the connection message to the experience builder\n const registeredDefinitions = Array.from(componentRegistry.values()).map(\n ({ definition }) => definition,\n );\n\n sendMessage(OUTGOING_EVENTS.Connected, {\n sdkVersion: SDK_VERSION,\n definitions: registeredDefinitions,\n });\n\n sendMessage(OUTGOING_EVENTS.RegisteredBreakpoints, {\n breakpoints: breakpointsRegistry,\n });\n\n sendMessage(OUTGOING_EVENTS.DesignTokens, {\n designTokens: designTokensRegistry,\n resolvedCssVariables: resolveCssVariables(designTokensRegistry),\n });\n};\n\n/**\n * Registers multiple components and their component definitions at once\n * @param componentRegistrations - ComponentRegistration[]\n * @returns void\n */\nexport const defineComponents = (\n componentRegistrations: ComponentRegistration[],\n options?: ComponentRegistrationOptions,\n) => {\n if (options?.experimentalComponents?.carousel) {\n componentRegistry.set(\n CONTENTFUL_COMPONENTS.carousel.id,\n DEFAULT_COMPONENT_REGISTRATIONS.carousel,\n );\n }\n\n if (options?.enabledBuiltInComponents) {\n for (const id of optionalBuiltInComponents) {\n if (!options.enabledBuiltInComponents.includes(id)) {\n componentRegistry.delete(id);\n }\n }\n }\n\n for (const registration of componentRegistrations) {\n // Fill definitions with fallbacks values\n const enrichedComponentRegistration = enrichComponentDefinition(registration);\n\n componentRegistry.set(\n enrichedComponentRegistration.definition.id,\n enrichedComponentRegistration,\n );\n }\n\n if (typeof window !== 'undefined') {\n window.dispatchEvent(new CustomEvent(INTERNAL_EVENTS.ComponentsRegistered));\n }\n};\n\n/**\n * use this function only in tests\n */\nexport const resetComponentRegistry = () => {\n componentRegistry.clear();\n for (const registration of Object.values(DEFAULT_COMPONENT_REGISTRATIONS)) {\n componentRegistry.set(registration.definition.id, registration);\n }\n};\n\nexport const getComponentRegistration = (id: string) => componentRegistry.get(id);\n\nexport const addComponentRegistration = (componentRegistration: ComponentRegistration) => {\n componentRegistry.set(componentRegistration.definition.id, componentRegistration);\n};\n\nexport const createAssemblyRegistration = ({\n definitionId,\n definitionName,\n component,\n}: {\n definitionId: string;\n definitionName?: string;\n component: ComponentRegistration['component'];\n}) => {\n const componentRegistration = componentRegistry.get(definitionId);\n\n if (componentRegistration) {\n return componentRegistration;\n }\n\n const definition = {\n id: definitionId,\n name: definitionName || 'Component',\n variables: {},\n children: true,\n category: ASSEMBLY_DEFAULT_CATEGORY,\n };\n\n addComponentRegistration({ component, definition });\n\n return componentRegistry.get(definitionId);\n};\n"],"names":["builtInStyleDefinitions"],"mappings":";;;;;;;;AA+BA,MAAM,WAAW,GAAG,iBAAiB,CAAC;AAEtC,MAAM,WAAW,GAAG,CAAI,YAAe,KAAO;AAC5C,IAAA,IAAI,OAAO,eAAe,KAAK,WAAW,EAAE;AAC1C,QAAA,OAAO,eAAe,CAAC,YAAY,CAAC,CAAC;KACtC;IAED,OAAO,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,SAAS,CAAC,YAAY,CAAC,CAAC,CAAC;AAClD,CAAC,CAAC;AAEF,MAAM,iCAAiC,GAAG,CAAC,mBAAwC,KAAI;AACrF,IAAA,MAAM,KAAK,GAAG,WAAW,CAAC,mBAAmB,CAAC,CAAC;AAC/C,IAAA,KAAK,MAAM,QAAQ,IAAI,MAAM,CAAC,MAAM,CAAC,KAAK,CAAC,SAAS,CAAC,EAAE;QACrD,QAAQ,CAAC,KAAK,GAAG,QAAQ,CAAC,KAAK,IAAI,SAAS,CAAC;KAC9C;AACD,IAAA,OAAO,KAAK,CAAC;AACf,CAAC,CAAC;AAEF,MAAM,4BAA4B,GAAG,CAAC,mBAAwC,KAAI;AAChF,IAAA,MAAM,KAAK,GAAG,WAAW,CAAC,mBAAmB,CAAC,CAAC;;AAG/C,IAAA,IAAI,CAAC,KAAK,CAAC,aAAa,EAAE;AACxB,QAAA,KAAK,CAAC,aAAa,GAAG,CAAC,UAAU,CAAC,CAAC;KACpC;AAED,IAAA,IAAI,CAAC,KAAK,CAAC,SAAS,EAAE;AACpB,QAAA,KAAK,CAAC,SAAS,GAAG,EAAE,CAAC;KACtB;;IAGD,KAAK,CAAC,SAAS,CAAC,cAAc,CAAC,GAAGA,aAAuB,CAAC,cAAc,CAAC,CAAC;IAE1E,KAAK,MAAM,KAAK,IAAI,KAAK,CAAC,aAAa,IAAI,EAAE,EAAE;AAC7C,QAAA,IAAIA,aAAuB,CAAC,KAAK,CAAC,EAAE;AACl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AAW;AACnC,QAAA,SAAS,EAAE,EAAE;AACb,QAAA,QAAQ,EAAE,IAAI;AACd,QAAA,QAAQ,EAAE,yBAAyB;KACpC,CAAC;AAEF,IAAA,wBAAwB,CAAC,EAAE,SAAS,EAAE,UAAU,EAAE,CAAC,CAAC;AAEpD,IAAA,OAAO,iBAAiB,CAAC,GAAG,CAAC,YAAY,CAAC,CAAC;AAC7C;;;;"}
|
|
@@ -18,7 +18,6 @@ const deserializePatternNode = ({ node, componentInstanceVariables, componentSet
|
|
|
18
18
|
componentSettings,
|
|
19
19
|
componentValueKey,
|
|
20
20
|
parameters: parameters,
|
|
21
|
-
variable: instanceProperty,
|
|
22
21
|
});
|
|
23
22
|
const path = resolvePrebindingPath({
|
|
24
23
|
componentSettings,
|
|
@@ -41,7 +40,9 @@ const deserializePatternNode = ({ node, componentInstanceVariables, componentSet
|
|
|
41
40
|
};
|
|
42
41
|
}
|
|
43
42
|
else if (instanceProperty?.type === 'NoValue') {
|
|
44
|
-
|
|
43
|
+
throw new Error(`Unexpected NoValue for variable "${variableName}" when deserializing pattern "${node.definitionId}". ` +
|
|
44
|
+
`This can only happen if you created experience in pre-release version of prebinding and experience contains NoValue properties. ` +
|
|
45
|
+
`Resave experience to fix this issue.`);
|
|
45
46
|
}
|
|
46
47
|
else if (instanceProperty?.type === 'BoundValue') {
|
|
47
48
|
variables[variableName] = {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"assemblyUtils.js","sources":["../../../../src/core/preview/assemblyUtils.ts"],"sourcesContent":["import { EntityStore, mergeDesignValuesByBreakpoint } from '@contentful/experiences-core';\nimport md5 from 'md5';\nimport type {\n ComponentPropertyValue,\n ComponentTreeNode,\n DesignValue,\n ExperienceComponentSettings,\n Parameter,\n} from '@contentful/experiences-core/types';\nimport { resolvePrebindingPath, shouldUsePrebinding } from '../../utils/prebindingUtils';\nimport { PATTERN_PROPERTY_DIVIDER } from '@contentful/experiences-core/constants';\n\n/** While unfolding the pattern definition on the instance, this function will replace all\n * ComponentValue in the definitions tree with the actual value on the instance. */\nexport const deserializePatternNode = ({\n node,\n componentInstanceVariables,\n componentSettings,\n parameters,\n entityStore,\n}: {\n node: ComponentTreeNode;\n componentInstanceVariables: ComponentTreeNode['variables'];\n componentSettings: ExperienceComponentSettings;\n parameters: Record<string, Parameter>;\n entityStore: EntityStore;\n}): ComponentTreeNode => {\n const variables: Record<string, ComponentPropertyValue> = {};\n\n for (const [variableName, variable] of Object.entries(node.variables)) {\n variables[variableName] = variable;\n if (variable.type === 'ComponentValue') {\n const componentValueKey = variable.key;\n const instanceProperty = componentInstanceVariables[componentValueKey];\n const variableDefinition = componentSettings.variableDefinitions?.[componentValueKey];\n const defaultValue = variableDefinition?.defaultValue;\n\n const usePrebinding = shouldUsePrebinding({\n componentSettings,\n componentValueKey,\n parameters: parameters,\n
|
|
1
|
+
{"version":3,"file":"assemblyUtils.js","sources":["../../../../src/core/preview/assemblyUtils.ts"],"sourcesContent":["import { EntityStore, mergeDesignValuesByBreakpoint } from '@contentful/experiences-core';\nimport md5 from 'md5';\nimport type {\n ComponentPropertyValue,\n ComponentTreeNode,\n DesignValue,\n ExperienceComponentSettings,\n Parameter,\n} from '@contentful/experiences-core/types';\nimport { resolvePrebindingPath, shouldUsePrebinding } from '../../utils/prebindingUtils';\nimport { PATTERN_PROPERTY_DIVIDER } from '@contentful/experiences-core/constants';\n\n/** While unfolding the pattern definition on the instance, this function will replace all\n * ComponentValue in the definitions tree with the actual value on the instance. */\nexport const deserializePatternNode = ({\n node,\n componentInstanceVariables,\n componentSettings,\n parameters,\n entityStore,\n}: {\n node: ComponentTreeNode;\n componentInstanceVariables: ComponentTreeNode['variables'];\n componentSettings: ExperienceComponentSettings;\n parameters: Record<string, Parameter>;\n entityStore: EntityStore;\n}): ComponentTreeNode => {\n const variables: Record<string, ComponentPropertyValue> = {};\n\n for (const [variableName, variable] of Object.entries(node.variables)) {\n variables[variableName] = variable;\n if (variable.type === 'ComponentValue') {\n const componentValueKey = variable.key;\n const instanceProperty = componentInstanceVariables[componentValueKey];\n const variableDefinition = componentSettings.variableDefinitions?.[componentValueKey];\n const defaultValue = variableDefinition?.defaultValue;\n\n const usePrebinding = shouldUsePrebinding({\n componentSettings,\n componentValueKey,\n parameters: parameters,\n });\n const path = resolvePrebindingPath({\n componentSettings,\n componentValueKey,\n parameters: parameters,\n entityStore,\n });\n\n if (usePrebinding && path) {\n variables[variableName] = {\n type: 'BoundValue',\n path,\n };\n\n // For assembly, we look up the variable in the assembly instance and\n // replace the ComponentValue with that one.\n } else if (instanceProperty?.type === 'UnboundValue') {\n variables[variableName] = {\n type: 'UnboundValue',\n key: instanceProperty.key,\n };\n } else if (instanceProperty?.type === 'NoValue') {\n throw new Error(\n `Unexpected NoValue for variable \"${variableName}\" when deserializing pattern \"${node.definitionId}\". ` +\n `This can only happen if you created experience in pre-release version of prebinding and experience contains NoValue properties. ` +\n `Resave experience to fix this issue.`,\n );\n } else if (instanceProperty?.type === 'BoundValue') {\n variables[variableName] = {\n type: 'BoundValue',\n path: instanceProperty.path,\n };\n } else if (instanceProperty?.type === 'HyperlinkValue') {\n variables[variableName] = {\n type: 'HyperlinkValue',\n linkTargetKey: instanceProperty.linkTargetKey,\n };\n } else if (instanceProperty?.type === 'DesignValue') {\n variables[variableName] = mergeDesignValuesByBreakpoint(\n defaultValue as DesignValue | undefined,\n instanceProperty,\n );\n } else if (!instanceProperty && defaultValue) {\n // So far, we only automatically fallback to the defaultValue for design properties\n if (variableDefinition.group === 'style') {\n variables[variableName] = {\n type: 'DesignValue',\n valuesByBreakpoint: (defaultValue as DesignValue).valuesByBreakpoint,\n };\n }\n }\n }\n }\n\n const children: ComponentTreeNode[] = node.children.map((child) =>\n deserializePatternNode({\n node: child,\n componentInstanceVariables,\n componentSettings,\n parameters,\n entityStore,\n }),\n );\n\n return {\n definitionId: node.definitionId,\n id: node.id,\n variables,\n children,\n slotId: node.slotId,\n displayName: node.displayName,\n parameters: node.parameters,\n };\n};\n\nexport const resolvePattern = ({\n node,\n parentParameters,\n patternRootNodeIdsChain,\n entityStore,\n}: {\n node: ComponentTreeNode;\n entityStore: EntityStore;\n parentParameters: Record<string, Parameter>;\n patternRootNodeIdsChain: string;\n}) => {\n const componentId = node.definitionId as string;\n const assembly = entityStore.usedComponents?.find(\n (component) => component.sys.id === componentId,\n );\n\n if (!assembly || !('fields' in assembly)) {\n return node;\n }\n\n const parameters: Record<string, Parameter> = {};\n\n const allParameters = {\n ...parentParameters,\n ...(node.parameters || {}),\n };\n\n for (const [parameterKey, parameter] of Object.entries(allParameters)) {\n /**\n * Bubbled up pattern properties are a concatenation of the node id\n * and the pattern property definition id. We need to split them so\n * that the node only uses the pattern property definition id.\n */\n const [hashKey, parameterId] = parameterKey.split(PATTERN_PROPERTY_DIVIDER);\n\n const hashedNodeChain = md5(patternRootNodeIdsChain || '');\n\n const isMatchingNode = hashKey === hashedNodeChain;\n\n if (!isMatchingNode) continue;\n\n parameters[parameterId] = parameter;\n }\n\n const componentFields = assembly.fields;\n\n const deserializedNode = deserializePatternNode({\n node: {\n definitionId: node.definitionId,\n id: node.id,\n variables: node.variables,\n children: componentFields.componentTree.children,\n parameters: parameters,\n },\n componentInstanceVariables: node.variables,\n componentSettings: componentFields.componentSettings!,\n parameters: parameters,\n entityStore,\n });\n\n entityStore.addAssemblyUnboundValues(componentFields.unboundValues);\n\n return deserializedNode;\n};\n"],"names":[],"mappings":";;;;;AAYA;AACmF;AACtE,MAAA,sBAAsB,GAAG,CAAC,EACrC,IAAI,EACJ,0BAA0B,EAC1B,iBAAiB,EACjB,UAAU,EACV,WAAW,GAOZ,KAAuB;IACtB,MAAM,SAAS,GAA2C,EAAE,CAAC;AAE7D,IAAA,KAAK,MAAM,CAAC,YAAY,EAAE,QAAQ,CAAC,IAAI,MAAM,CAAC,OAAO,CAAC,IAAI,CAAC,SAAS,CAAC,EAAE;AACrE,QAAA,SAAS,CAAC,YAAY,CAAC,GAAG,QAAQ,CAAC;AACnC,QAAA,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vB,SAAA;QACD,0BAA0B,EAAE,IAAI,CAAC,SAAS;QAC1C,iBAAiB,EAAE,eAAe,CAAC,iBAAkB;AACrD,QAAA,UAAU,EAAE,UAAU;QACtB,WAAW;AACZ,KAAA,CAAC,CAAC;AAEH,IAAA,WAAW,CAAC,wBAAwB,CAAC,eAAe,CAAC,aAAa,CAAC,CAAC;AAEpE,IAAA,OAAO,gBAAgB,CAAC;AAC1B;;;;"}
|
package/dist/index.d.ts
CHANGED
|
@@ -9,7 +9,7 @@ import * as _contentful_experiences_core_constants from '@contentful/experiences
|
|
|
9
9
|
export { CF_STYLE_ATTRIBUTES, CONTENTFUL_COMPONENTS, LATEST_SCHEMA_VERSION } from '@contentful/experiences-core/constants';
|
|
10
10
|
import { ContentfulClientApi } from 'contentful';
|
|
11
11
|
|
|
12
|
-
declare const SDK_VERSION = "3.1.
|
|
12
|
+
declare const SDK_VERSION = "3.1.1-beta.0";
|
|
13
13
|
|
|
14
14
|
type ExperienceRootProps = {
|
|
15
15
|
experience?: Experience<EntityStore> | string | null;
|
package/dist/sdkVersion.js
CHANGED
package/dist/sdkVersion.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"sdkVersion.js","sources":["../../src/sdkVersion.ts"],"sourcesContent":["export const SDK_VERSION = '3.1.
|
|
1
|
+
{"version":3,"file":"sdkVersion.js","sources":["../../src/sdkVersion.ts"],"sourcesContent":["export const SDK_VERSION = '3.1.1-beta.0';\n"],"names":[],"mappings":"AAAO,MAAM,WAAW,GAAG;;;;"}
|
|
@@ -1,8 +1,10 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
2
|
import { type EntityStore, VisualEditorMode } from '@contentful/experiences-core';
|
|
3
3
|
import type { Experience } from '@contentful/experiences-core/types';
|
|
4
|
+
import type { StudioCanvasMode } from '@contentful/experiences-core/constants';
|
|
4
5
|
type VisualEditorLoaderProps = {
|
|
5
6
|
visualEditorMode: VisualEditorMode;
|
|
7
|
+
canvasMode?: StudioCanvasMode;
|
|
6
8
|
experience?: Experience<EntityStore>;
|
|
7
9
|
};
|
|
8
10
|
export declare const VisualEditorLoader: React.FC<VisualEditorLoaderProps>;
|
|
@@ -1,8 +1,10 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
2
|
import { EntityStore, VisualEditorMode } from '@contentful/experiences-core';
|
|
3
3
|
import type { Experience } from '@contentful/experiences-core/types';
|
|
4
|
+
import type { StudioCanvasMode } from '@contentful/experiences-core/constants';
|
|
4
5
|
type VisualEditorRootProps = {
|
|
5
6
|
visualEditorMode: VisualEditorMode;
|
|
7
|
+
canvasMode?: StudioCanvasMode;
|
|
6
8
|
experience?: Experience<EntityStore>;
|
|
7
9
|
initialLocale: string;
|
|
8
10
|
};
|
package/dist/src/sdkVersion.d.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export declare const SDK_VERSION = "3.1.
|
|
1
|
+
export declare const SDK_VERSION = "3.1.1-beta.0";
|
|
@@ -1,10 +1,9 @@
|
|
|
1
1
|
import { type EntityStore } from '@contentful/experiences-core';
|
|
2
|
-
import {
|
|
3
|
-
export declare const shouldUsePrebinding: ({ componentValueKey, componentSettings, parameters,
|
|
2
|
+
import { ExperienceComponentSettings, Parameter } from '@contentful/experiences-validators';
|
|
3
|
+
export declare const shouldUsePrebinding: ({ componentValueKey, componentSettings, parameters, }: {
|
|
4
4
|
componentValueKey: string;
|
|
5
5
|
componentSettings: ExperienceComponentSettings;
|
|
6
6
|
parameters: Record<string, Parameter>;
|
|
7
|
-
variable: ComponentPropertyValue;
|
|
8
7
|
}) => boolean;
|
|
9
8
|
export declare const resolvePrebindingPath: ({ componentValueKey, componentSettings, parameters, entityStore, }: {
|
|
10
9
|
componentValueKey: string;
|
|
@@ -5,11 +5,9 @@ interface CFProps extends React.HtmlHTMLAttributes<HTMLElement> {
|
|
|
5
5
|
* Classes to be applied to the container component if `wrapComponent` is true, or directly to the child component if false.
|
|
6
6
|
*/
|
|
7
7
|
className?: string;
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
classes?: string;
|
|
12
|
-
dragProps?: any;
|
|
8
|
+
'data-cf-node-id': string;
|
|
9
|
+
'data-cf-node-block-id': string;
|
|
10
|
+
'data-cf-node-block-type': string;
|
|
13
11
|
}
|
|
14
12
|
/**
|
|
15
13
|
* Sets up a component to be consumed by Experience Builder. This function can be used to wrap a component with a container component, or to pass props to the component directly.
|
|
@@ -1,14 +1,19 @@
|
|
|
1
1
|
import { isLink } from '@contentful/experiences-core';
|
|
2
2
|
import { SIDELOADED_PREFIX } from '@contentful/experiences-core/constants';
|
|
3
3
|
|
|
4
|
-
const shouldUsePrebinding = ({ componentValueKey, componentSettings, parameters,
|
|
4
|
+
const shouldUsePrebinding = ({ componentValueKey, componentSettings, parameters, }) => {
|
|
5
5
|
const { prebindingDefinitions } = componentSettings;
|
|
6
|
-
const { parameterDefinitions, variableMappings } = prebindingDefinitions?.[0] || {};
|
|
6
|
+
const { parameterDefinitions, variableMappings, allowedVariableOverrides } = prebindingDefinitions?.[0] || {};
|
|
7
7
|
const variableMapping = variableMappings?.[componentValueKey];
|
|
8
8
|
const parameterDefinition = parameterDefinitions?.[variableMapping?.parameterId || ''];
|
|
9
9
|
const parameter = parameters?.[variableMapping?.parameterId || ''];
|
|
10
|
-
const isValidForPrebinding = !!parameterDefinition &&
|
|
11
|
-
|
|
10
|
+
const isValidForPrebinding = !!parameterDefinition &&
|
|
11
|
+
!!parameter &&
|
|
12
|
+
!!variableMapping &&
|
|
13
|
+
!!allowedVariableOverrides &&
|
|
14
|
+
Array.isArray(allowedVariableOverrides);
|
|
15
|
+
const isForDirectBindingOnly = (allowedVariableOverrides) => allowedVariableOverrides.includes(componentValueKey); // removed 'NoValue' check
|
|
16
|
+
return isValidForPrebinding && !isForDirectBindingOnly(allowedVariableOverrides);
|
|
12
17
|
};
|
|
13
18
|
const resolvePrebindingPath = ({ componentValueKey, componentSettings, parameters, entityStore, }) => {
|
|
14
19
|
const prebindingDefinition = componentSettings.prebindingDefinitions?.[0];
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"prebindingUtils.js","sources":["../../../src/utils/prebindingUtils.ts"],"sourcesContent":["import { type EntityStore, isLink } from '@contentful/experiences-core';\nimport { SIDELOADED_PREFIX } from '@contentful/experiences-core/constants';\nimport {
|
|
1
|
+
{"version":3,"file":"prebindingUtils.js","sources":["../../../src/utils/prebindingUtils.ts"],"sourcesContent":["import { type EntityStore, isLink } from '@contentful/experiences-core';\nimport { SIDELOADED_PREFIX } from '@contentful/experiences-core/constants';\nimport { ExperienceComponentSettings, Parameter } from '@contentful/experiences-validators';\n\nexport const shouldUsePrebinding = ({\n componentValueKey,\n componentSettings,\n parameters,\n}: {\n componentValueKey: string;\n componentSettings: ExperienceComponentSettings;\n parameters: Record<string, Parameter>;\n}) => {\n const { prebindingDefinitions } = componentSettings;\n const { parameterDefinitions, variableMappings, allowedVariableOverrides } =\n prebindingDefinitions?.[0] || {};\n\n const variableMapping = variableMappings?.[componentValueKey];\n\n const parameterDefinition = parameterDefinitions?.[variableMapping?.parameterId || ''];\n const parameter = parameters?.[variableMapping?.parameterId || ''];\n\n const isValidForPrebinding =\n !!parameterDefinition &&\n !!parameter &&\n !!variableMapping &&\n !!allowedVariableOverrides &&\n Array.isArray(allowedVariableOverrides);\n\n const isForDirectBindingOnly = (allowedVariableOverrides: string[]) =>\n allowedVariableOverrides.includes(componentValueKey); // removed 'NoValue' check\n\n return isValidForPrebinding && !isForDirectBindingOnly(allowedVariableOverrides);\n};\n\nexport const resolvePrebindingPath = ({\n componentValueKey,\n componentSettings,\n parameters,\n entityStore,\n}: {\n componentValueKey: string;\n componentSettings: ExperienceComponentSettings;\n parameters: Record<string, Parameter>;\n entityStore: EntityStore;\n}) => {\n const prebindingDefinition = componentSettings.prebindingDefinitions?.[0];\n if (!prebindingDefinition) return '';\n\n const variableMapping = prebindingDefinition.variableMappings?.[componentValueKey];\n\n if (!variableMapping) return '';\n\n const parameter = parameters?.[variableMapping.parameterId];\n\n if (!parameter) return '';\n\n const dataSourceKey = parameter.path.split('/')[1];\n\n const entityLink = entityStore.dataSource[dataSourceKey];\n if (!entityLink) return '';\n\n const entity = entityStore.getEntityFromLink(entityLink);\n if (!entity || entity.sys.type === 'Asset') return '';\n\n const contentType = entity.sys.contentType.sys.id;\n\n const fieldPath = variableMapping?.pathsByContentType?.[contentType]?.path;\n\n if (!fieldPath) return '';\n\n return parameter.path + fieldPath;\n};\n\nexport const resolveMaybePrebindingDefaultValuePath = ({\n componentValueKey,\n entityStore,\n}: {\n componentValueKey: string;\n entityStore: EntityStore;\n}): string | undefined => {\n const variableMapping = entityStore.hoistedVariableMappings[componentValueKey];\n if (!variableMapping) return;\n\n const pdID = variableMapping.parameterId;\n const prebindingDefinition = entityStore.hoistedParameterDefinitions[pdID];\n\n if (!prebindingDefinition) {\n // probably shouldn't happen, as if ppd is not defined, then variableMapping should not be defined either\n return;\n }\n if (!prebindingDefinition.defaultSource) {\n // pretty normal, prebinding definitions are not required to have default source\n return;\n }\n\n const { contentTypeId, link: defaultEntryLink } = prebindingDefinition.defaultSource;\n\n if (!isLink(defaultEntryLink)) {\n // just extra safety check, defaultEntryLink should always be a link\n return;\n }\n\n if (contentTypeId in prebindingDefinition.contentTypes) {\n const entity = entityStore.getEntityFromLink(defaultEntryLink);\n if (!entity) {\n // looks like sideloading of the prebinding default value didn't work as expected.\n // And didn't sideload the entry into entityStore (and didn't add it's sideloaded_dsKey to the entityStore.dataSource)\n return;\n }\n\n const fieldPath = variableMapping.pathsByContentType[contentTypeId].path;\n if (!fieldPath) {\n // Path not found or degenerate shape (e.g. empty string '')\n return;\n }\n\n const fullDefaultValuePath = `/${SIDELOADED_PREFIX}${defaultEntryLink.sys.id}${fieldPath}`;\n return fullDefaultValuePath;\n }\n};\n"],"names":[],"mappings":";;;AAIO,MAAM,mBAAmB,GAAG,CAAC,EAClC,iBAAiB,EACjB,iBAAiB,EACjB,UAAU,GAKX,KAAI;AACH,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BAAgB,EAAE,GAAG,oBAAoB,CAAC,aAAa,CAAC;AAErF,IAAA,IAAI,CAAC,MAAM,CAAC,gBAAgB,CAAC,EAAE;;QAE7B,OAAO;KACR;AAED,IAAA,IAAI,aAAa,IAAI,oBAAoB,CAAC,YAAY,EAAE;QACtD,MAAM,MAAM,GAAG,WAAW,CAAC,iBAAiB,CAAC,gBAAgB,CAAC,CAAC;QAC/D,IAAI,CAAC,MAAM,EAAE;;;YAGX,OAAO;SACR;QAED,MAAM,SAAS,GAAG,eAAe,CAAC,kBAAkB,CAAC,aAAa,CAAC,CAAC,IAAI,CAAC;QACzE,IAAI,CAAC,SAAS,EAAE;;YAEd,OAAO;SACR;AAED,QAAA,MAAM,oBAAoB,GAAG,CAAI,CAAA,EAAA,iBAAiB,CAAG,EAAA,gBAAgB,CAAC,GAAG,CAAC,EAAE,CAAG,EAAA,SAAS,EAAE,CAAC;AAC3F,QAAA,OAAO,oBAAoB,CAAC;KAC7B;AACH;;;;"}
|
|
@@ -1,5 +1,4 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import classNames from 'classnames';
|
|
1
|
+
import { jsx } from 'react/jsx-runtime';
|
|
3
2
|
import React from 'react';
|
|
4
3
|
|
|
5
4
|
/**
|
|
@@ -9,19 +8,17 @@ import React from 'react';
|
|
|
9
8
|
* @default { wrapComponent: true, wrapContainer: 'div' }
|
|
10
9
|
* @returns A component that can be passed to `defineComponents`.
|
|
11
10
|
*/
|
|
12
|
-
function withComponentWrapper(Component, options = {
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
...props,
|
|
24
|
-
}));
|
|
11
|
+
function withComponentWrapper(Component, options = {}) {
|
|
12
|
+
const mergedOptions = {
|
|
13
|
+
// Merge default values with overwriting options
|
|
14
|
+
wrapComponent: true,
|
|
15
|
+
wrapContainer: 'div',
|
|
16
|
+
...options,
|
|
17
|
+
};
|
|
18
|
+
const Wrapped = (props) => {
|
|
19
|
+
const Tag = mergedOptions.wrapContainer;
|
|
20
|
+
const { className = '', 'data-cf-node-id': dataCfNodeId, 'data-cf-node-block-id': dataCfNodeBlockId, 'data-cf-node-block-type': dataCfNodeBlockType, ...componentProps } = props;
|
|
21
|
+
const component = mergedOptions.wrapComponent ? (jsx(Tag, { "data-component-wrapper": true, className: className, "data-cf-node-id": dataCfNodeId, "data-cf-node-block-id": dataCfNodeBlockId, "data-cf-node-block-type": dataCfNodeBlockType, children: jsx(Component, { ...componentProps }) })) : (React.createElement(Component, props));
|
|
25
22
|
return component;
|
|
26
23
|
};
|
|
27
24
|
return Wrapped;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"withComponentWrapper.js","sources":["../../../src/utils/withComponentWrapper.tsx"],"sourcesContent":["import { ComponentRegistration } from '@contentful/experiences-core/types';\nimport
|
|
1
|
+
{"version":3,"file":"withComponentWrapper.js","sources":["../../../src/utils/withComponentWrapper.tsx"],"sourcesContent":["import { ComponentRegistration } from '@contentful/experiences-core/types';\nimport React from 'react';\ninterface CFProps extends React.HtmlHTMLAttributes<HTMLElement> {\n /**\n * Classes to be applied to the container component if `wrapComponent` is true, or directly to the child component if false.\n */\n className?: string;\n 'data-cf-node-id': string;\n 'data-cf-node-block-id': string;\n 'data-cf-node-block-type': string;\n}\n\n/**\n * Sets up a component to be consumed by Experience Builder. This function can be used to wrap a component with a container component, or to pass props to the component directly.\n * @param Component Component to be used by Experience Builder.\n * @param options Options for the `withComponentWrapper` function.\n * @default { wrapComponent: true, wrapContainer: 'div' }\n * @returns A component that can be passed to `defineComponents`.\n */\nexport function withComponentWrapper<T>(\n Component: React.ElementType,\n options: ComponentRegistration['options'] = {},\n) {\n const mergedOptions = {\n // Merge default values with overwriting options\n wrapComponent: true,\n wrapContainer: 'div' as keyof JSX.IntrinsicElements,\n ...options,\n };\n const Wrapped: React.FC<CFProps & T> = (props) => {\n const Tag = mergedOptions.wrapContainer;\n const {\n className = '',\n 'data-cf-node-id': dataCfNodeId,\n 'data-cf-node-block-id': dataCfNodeBlockId,\n 'data-cf-node-block-type': dataCfNodeBlockType,\n ...componentProps\n } = props;\n const component = mergedOptions.wrapComponent ? (\n <Tag\n data-component-wrapper\n className={className}\n data-cf-node-id={dataCfNodeId}\n data-cf-node-block-id={dataCfNodeBlockId}\n data-cf-node-block-type={dataCfNodeBlockType}>\n <Component {...componentProps} />\n </Tag>\n ) : (\n React.createElement(Component, props)\n );\n return component;\n };\n\n return Wrapped;\n}\n"],"names":["_jsx"],"mappings":";;;AAYA;;;;;;AAMG;SACa,oBAAoB,CAClC,SAA4B,EAC5B,UAA4C,EAAE,EAAA;AAE9C,IAAA,MAAM,aAAa,GAAG;;AAEpB,QAAA,aAAa,EAAE,IAAI;AACnB,QAAA,aAAa,EAAE,KAAoC;AACnD,QAAA,GAAG,OAAO;KACX,CAAC;AACF,IAAA,MAAM,OAAO,GAA0B,CAAC,KAAK,KAAI;AAC/C,QAAA,MAAM,GAAG,GAAG,aAAa,CAAC,aAAa,CAAC;QACxC,MAAM,EACJ,SAAS,GAAG,EAAE,EACd,iBAAiB,EAAE,YAAY,EAC/B,uBAAuB,EAAE,iBAAiB,EAC1C,yBAAyB,EAAE,mBAAmB,EAC9C,GAAG,cAAc,EAClB,GAAG,KAAK,CAAC;AACV,QAAA,MAAM,SAAS,GAAG,aAAa,CAAC,aAAa,IAC3CA,IAAC,GAAG,EAAA,EAAA,wBAAA,EAAA,IAAA,EAEF,SAAS,EAAE,SAAS,qBACH,YAAY,EAAA,uBAAA,EACN,iBAAiB,EACf,yBAAA,EAAA,mBAAmB,EAC5C,QAAA,EAAAA,GAAA,CAAC,SAAS,EAAK,EAAA,GAAA,cAAc,GAAI,EAC7B,CAAA,KAEN,KAAK,CAAC,aAAa,CAAC,SAAS,EAAE,KAAK,CAAC,CACtC,CAAC;AACF,QAAA,OAAO,SAAS,CAAC;AACnB,KAAC,CAAC;AAEF,IAAA,OAAO,OAAO,CAAC;AACjB;;;;"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@contentful/experiences-sdk-react",
|
|
3
|
-
"version": "3.1.
|
|
3
|
+
"version": "3.1.1-beta.0",
|
|
4
4
|
"main": "./dist/index.js",
|
|
5
5
|
"module": "./dist/index.js",
|
|
6
6
|
"typings": "./dist/src/index.d.ts",
|
|
@@ -41,12 +41,11 @@
|
|
|
41
41
|
"depcruise": "depcruise src"
|
|
42
42
|
},
|
|
43
43
|
"dependencies": {
|
|
44
|
-
"@contentful/experiences-components-react": "3.1.
|
|
45
|
-
"@contentful/experiences-core": "3.1.
|
|
46
|
-
"@contentful/experiences-validators": "3.1.
|
|
47
|
-
"@contentful/experiences-visual-editor-react": "3.1.
|
|
44
|
+
"@contentful/experiences-components-react": "3.1.1-beta.0",
|
|
45
|
+
"@contentful/experiences-core": "3.1.1-beta.0",
|
|
46
|
+
"@contentful/experiences-validators": "3.1.1-beta.0",
|
|
47
|
+
"@contentful/experiences-visual-editor-react": "3.1.1-beta.0",
|
|
48
48
|
"@contentful/rich-text-types": "^17.0.0",
|
|
49
|
-
"classnames": "^2.3.2",
|
|
50
49
|
"csstype": "^3.1.2",
|
|
51
50
|
"immer": "^10.0.3",
|
|
52
51
|
"lodash-es": "^4.17.21",
|
|
@@ -99,5 +98,5 @@
|
|
|
99
98
|
"dist",
|
|
100
99
|
"package.json"
|
|
101
100
|
],
|
|
102
|
-
"gitHead": "
|
|
101
|
+
"gitHead": "1c47cc45d6535f193c77746b42d0fb4150f1e9c5"
|
|
103
102
|
}
|