@contentful/experiences-sdk-react 1.9.0-dev-20240628T2230-7a4f71f.0 → 1.9.0-dev-20240628T2235-7a4f71f.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.
Files changed (89) hide show
  1. package/package.json +6 -6
  2. package/dist/ExperienceRoot.js +0 -25
  3. package/dist/ExperienceRoot.js.map +0 -1
  4. package/dist/blocks/editor/VisualEditorInjectScript.js +0 -38
  5. package/dist/blocks/editor/VisualEditorInjectScript.js.map +0 -1
  6. package/dist/blocks/editor/VisualEditorLoader.js +0 -28
  7. package/dist/blocks/editor/VisualEditorLoader.js.map +0 -1
  8. package/dist/blocks/editor/VisualEditorRoot.js +0 -17
  9. package/dist/blocks/editor/VisualEditorRoot.js.map +0 -1
  10. package/dist/blocks/preview/CompositionBlock.js +0 -132
  11. package/dist/blocks/preview/CompositionBlock.js.map +0 -1
  12. package/dist/blocks/preview/PreviewDeliveryRoot.js +0 -23
  13. package/dist/blocks/preview/PreviewDeliveryRoot.js.map +0 -1
  14. package/dist/components/Assembly.js +0 -13
  15. package/dist/components/Assembly.js.map +0 -1
  16. package/dist/components/ErrorBoundary.js +0 -37
  17. package/dist/components/ErrorBoundary.js.map +0 -1
  18. package/dist/constants.js +0 -5
  19. package/dist/constants.js.map +0 -1
  20. package/dist/core/componentRegistry.js +0 -292
  21. package/dist/core/componentRegistry.js.map +0 -1
  22. package/dist/core/preview/assemblyUtils.js +0 -71
  23. package/dist/core/preview/assemblyUtils.js.map +0 -1
  24. package/dist/core/sdkFeatures.js +0 -7
  25. package/dist/core/sdkFeatures.js.map +0 -1
  26. package/dist/hooks/useBreakpoints.js +0 -40
  27. package/dist/hooks/useBreakpoints.js.map +0 -1
  28. package/dist/hooks/useClassName.js +0 -42
  29. package/dist/hooks/useClassName.js.map +0 -1
  30. package/dist/hooks/useDetectEditorMode.js +0 -60
  31. package/dist/hooks/useDetectEditorMode.js.map +0 -1
  32. package/dist/hooks/useFetchByBase.js +0 -38
  33. package/dist/hooks/useFetchByBase.js.map +0 -1
  34. package/dist/hooks/useFetchById.js +0 -16
  35. package/dist/hooks/useFetchById.js.map +0 -1
  36. package/dist/hooks/useFetchBySlug.js +0 -16
  37. package/dist/hooks/useFetchBySlug.js.map +0 -1
  38. package/dist/hooks/useInitializeVisualEditor.js +0 -56
  39. package/dist/hooks/useInitializeVisualEditor.js.map +0 -1
  40. package/dist/index.d.ts +0 -67
  41. package/dist/index.js +0 -16
  42. package/dist/index.js.map +0 -1
  43. package/dist/sdkVersion.js +0 -4
  44. package/dist/sdkVersion.js.map +0 -1
  45. package/dist/src/ExperienceRoot.d.ts +0 -10
  46. package/dist/src/blocks/editor/VisualEditorInjectScript.d.ts +0 -4
  47. package/dist/src/blocks/editor/VisualEditorLoader.d.ts +0 -9
  48. package/dist/src/blocks/editor/VisualEditorRoot.d.ts +0 -10
  49. package/dist/src/blocks/preview/CompositionBlock.d.ts +0 -11
  50. package/dist/src/blocks/preview/CompositionBlock.spec.d.ts +0 -1
  51. package/dist/src/blocks/preview/PreviewDeliveryRoot.d.ts +0 -8
  52. package/dist/src/blocks/preview/PreviewDeliveryRoot.test.d.ts +0 -1
  53. package/dist/src/components/Assembly.d.ts +0 -3
  54. package/dist/src/components/ErrorBoundary.d.ts +0 -19
  55. package/dist/src/components/Flex.d.ts +0 -64
  56. package/dist/src/constants.d.ts +0 -3
  57. package/dist/src/core/componentRegistry.d.ts +0 -32
  58. package/dist/src/core/componentRegistry.test.d.ts +0 -1
  59. package/dist/src/core/index.d.ts +0 -1
  60. package/dist/src/core/preview/assemblyUtils.d.ts +0 -10
  61. package/dist/src/core/preview/assemblyUtils.spec.d.ts +0 -1
  62. package/dist/src/core/sdkFeatures.d.ts +0 -1
  63. package/dist/src/hooks/index.d.ts +0 -3
  64. package/dist/src/hooks/useBreakpoints.d.ts +0 -4
  65. package/dist/src/hooks/useBreakpoints.spec.d.ts +0 -1
  66. package/dist/src/hooks/useClassName.d.ts +0 -13
  67. package/dist/src/hooks/useClassName.spec.d.ts +0 -1
  68. package/dist/src/hooks/useDetectEditorMode.d.ts +0 -7
  69. package/dist/src/hooks/useFetchByBase.d.ts +0 -8
  70. package/dist/src/hooks/useFetchById.d.ts +0 -17
  71. package/dist/src/hooks/useFetchById.spec.d.ts +0 -1
  72. package/dist/src/hooks/useFetchBySlug.d.ts +0 -18
  73. package/dist/src/hooks/useFetchBySlug.spec.d.ts +0 -1
  74. package/dist/src/hooks/useInitializeVisualEditor.d.ts +0 -7
  75. package/dist/src/hooks/usePrevious.d.ts +0 -6
  76. package/dist/src/index.d.ts +0 -7
  77. package/dist/src/sdkVersion.d.ts +0 -1
  78. package/dist/src/utils/withComponentWrapper.d.ts +0 -22
  79. package/dist/src/utils/withComponentWrapper.spec.d.ts +0 -1
  80. package/dist/styles/ErrorBoundary.css.js +0 -7
  81. package/dist/styles/ErrorBoundary.css.js.map +0 -1
  82. package/dist/test/__fixtures__/assembly.d.ts +0 -96
  83. package/dist/test/__fixtures__/composition.d.ts +0 -7
  84. package/dist/test/__fixtures__/entities.d.ts +0 -9
  85. package/dist/test/components/Test.d.ts +0 -1
  86. package/dist/test/components/Test.spec.d.ts +0 -1
  87. package/dist/utils/withComponentWrapper.js +0 -32
  88. package/dist/utils/withComponentWrapper.js.map +0 -1
  89. package/dist/vite.config.d.ts +0 -2
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@contentful/experiences-sdk-react",
3
- "version": "1.9.0-dev-20240628T2230-7a4f71f.0",
3
+ "version": "1.9.0-dev-20240628T2235-7a4f71f.0",
4
4
  "main": "./dist/index.js",
5
5
  "module": "./dist/index.js",
6
6
  "typings": "./dist/src/index.d.ts",
@@ -33,10 +33,10 @@
33
33
  "depcruise": "depcruise src"
34
34
  },
35
35
  "dependencies": {
36
- "@contentful/experiences-components-react": "1.9.0-dev-20240628T2230-7a4f71f.0",
37
- "@contentful/experiences-core": "1.9.0-dev-20240628T2230-7a4f71f.0",
38
- "@contentful/experiences-validators": "1.9.0-dev-20240628T2230-7a4f71f.0",
39
- "@contentful/experiences-visual-editor-react": "1.9.0-dev-20240628T2230-7a4f71f.0",
36
+ "@contentful/experiences-components-react": "1.9.0-dev-20240628T2235-7a4f71f.0",
37
+ "@contentful/experiences-core": "1.9.0-dev-20240628T2235-7a4f71f.0",
38
+ "@contentful/experiences-validators": "1.9.0-dev-20240628T2235-7a4f71f.0",
39
+ "@contentful/experiences-visual-editor-react": "1.9.0-dev-20240628T2235-7a4f71f.0",
40
40
  "@contentful/rich-text-types": "^16.2.1",
41
41
  "classnames": "^2.3.2",
42
42
  "csstype": "^3.1.2",
@@ -94,5 +94,5 @@
94
94
  "dist",
95
95
  "package.json"
96
96
  ],
97
- "gitHead": "b4dda124d0eaf3ce606af293e58f64218b705bbe"
97
+ "gitHead": "2794272dc185d96f5c3a3c0ada65b2c872c744b8"
98
98
  }
@@ -1,25 +0,0 @@
1
- "use client";
2
- import { jsx } from 'react/jsx-runtime';
3
- import { createExperience, validateExperienceBuilderConfig, VisualEditorMode } from '@contentful/experiences-core';
4
- import { PreviewDeliveryRoot } from './blocks/preview/PreviewDeliveryRoot.js';
5
- import { VisualEditorRoot } from './blocks/editor/VisualEditorRoot.js';
6
- import { useDetectEditorMode } from './hooks/useDetectEditorMode.js';
7
-
8
- const ExperienceRoot = ({ locale, experience, visualEditorMode = VisualEditorMode.LazyLoad, }) => {
9
- const isEditorMode = useDetectEditorMode();
10
- //If experience is passed in as a JSON string, recreate it to an experience object
11
- const experienceObject = typeof experience === 'string' ? createExperience(experience) : experience;
12
- validateExperienceBuilderConfig({
13
- locale,
14
- isEditorMode,
15
- });
16
- if (isEditorMode) {
17
- return (jsx(VisualEditorRoot, { experience: experienceObject, visualEditorMode: visualEditorMode, initialLocale: locale }));
18
- }
19
- if (!experienceObject)
20
- return null;
21
- return jsx(PreviewDeliveryRoot, { locale: locale, experience: experienceObject });
22
- };
23
-
24
- export { ExperienceRoot };
25
- //# sourceMappingURL=ExperienceRoot.js.map
@@ -1 +0,0 @@
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} 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 { useDetectEditorMode } from './hooks/useDetectEditorMode';\n\ntype ExperienceRootProps = {\n experience?: Experience<EntityStore> | string | null;\n locale: string;\n visualEditorMode?: VisualEditorMode;\n};\n\nexport const ExperienceRoot = ({\n locale,\n experience,\n visualEditorMode = VisualEditorMode.LazyLoad,\n}: ExperienceRootProps) => {\n const isEditorMode = useDetectEditorMode();\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 isEditorMode,\n });\n\n if (isEditorMode) {\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":";;;;;;;AAmBa;AAKX;;AAEA;AAGA;;;AAGC;;AAGC;;AASF;AAAuB;;AAGzB;;"}
@@ -1,38 +0,0 @@
1
- import { jsx } from 'react/jsx-runtime';
2
- import { useEffect } from 'react';
3
- import { VISUAL_EDITOR_CONTAINER_ID } from '@contentful/experiences-core/constants';
4
-
5
- /**
6
- * The version can be any semver version or dist tag
7
- * Examples: @latest, @dev, @pre, @0.0.1-pre-20231213T103332.0
8
- *
9
- * If the version is empty, unpkg will redirect to the latest version of the package
10
- */
11
- const version = '@0.0.1-pre-20231213T210727.0';
12
- /**
13
- * CDN URL for the visual editor script
14
- *
15
- * This can be changed to a local file path for development
16
- *
17
- * TODO: Reconsider unpkg
18
- */
19
- const scriptUrl = `https://unpkg.com/@contentful/experience-builder-visual-editor${version}/dist/renderApp.js`;
20
- /**
21
- * This component injects the visual editor script into the page
22
- */
23
- function VisualEditorInjectScript() {
24
- useEffect(() => {
25
- const script = document.createElement('script');
26
- script.type = 'module';
27
- script.src = scriptUrl;
28
- script.async = true;
29
- document.body.appendChild(script);
30
- return () => {
31
- document.body.removeChild(script);
32
- };
33
- }, []);
34
- return jsx("div", { id: VISUAL_EDITOR_CONTAINER_ID });
35
- }
36
-
37
- export { VisualEditorInjectScript as default };
38
- //# sourceMappingURL=VisualEditorInjectScript.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"VisualEditorInjectScript.js","sources":["../../../../src/blocks/editor/VisualEditorInjectScript.tsx"],"sourcesContent":["import React, { useEffect } from 'react';\nimport { VISUAL_EDITOR_CONTAINER_ID } from '@contentful/experiences-core/constants';\n\n/**\n * The version can be any semver version or dist tag\n * Examples: @latest, @dev, @pre, @0.0.1-pre-20231213T103332.0\n *\n * If the version is empty, unpkg will redirect to the latest version of the package\n */\nconst version = '@0.0.1-pre-20231213T210727.0';\n\n/**\n * CDN URL for the visual editor script\n *\n * This can be changed to a local file path for development\n *\n * TODO: Reconsider unpkg\n */\nconst scriptUrl = `https://unpkg.com/@contentful/experience-builder-visual-editor${version}/dist/renderApp.js`;\n\n/**\n * This component injects the visual editor script into the page\n */\nexport default function VisualEditorInjectScript() {\n useEffect(() => {\n const script = document.createElement('script');\n script.type = 'module';\n script.src = scriptUrl;\n script.async = true;\n\n document.body.appendChild(script);\n return () => {\n document.body.removeChild(script);\n };\n }, []);\n\n return <div id={VISUAL_EDITOR_CONTAINER_ID} />;\n}\n"],"names":["_jsx"],"mappings":";;;;AAGA;;;;;AAKG;AACH,MAAM,OAAO,GAAG,8BAA8B,CAAC;AAE/C;;;;;;AAMG;AACH,MAAM,SAAS,GAAG,CAAiE,8DAAA,EAAA,OAAO,oBAAoB,CAAC;AAE/G;;AAEG;AACW,SAAU,wBAAwB,GAAA;IAC9C,SAAS,CAAC,MAAK;QACb,MAAM,MAAM,GAAG,QAAQ,CAAC,aAAa,CAAC,QAAQ,CAAC,CAAC;AAChD,QAAA,MAAM,CAAC,IAAI,GAAG,QAAQ,CAAC;AACvB,QAAA,MAAM,CAAC,GAAG,GAAG,SAAS,CAAC;AACvB,QAAA,MAAM,CAAC,KAAK,GAAG,IAAI,CAAC;AAEpB,QAAA,QAAQ,CAAC,IAAI,CAAC,WAAW,CAAC,MAAM,CAAC,CAAC;AAClC,QAAA,OAAO,MAAK;AACV,YAAA,QAAQ,CAAC,IAAI,CAAC,WAAW,CAAC,MAAM,CAAC,CAAC;AACpC,SAAC,CAAC;KACH,EAAE,EAAE,CAAC,CAAC;AAEP,IAAA,OAAOA,GAAK,CAAA,KAAA,EAAA,EAAA,EAAE,EAAE,0BAA0B,GAAI,CAAC;AACjD;;;;"}
@@ -1,28 +0,0 @@
1
- import { jsx } from 'react/jsx-runtime';
2
- import { useState, useEffect } from 'react';
3
- import { VisualEditorMode } from '@contentful/experiences-core';
4
-
5
- const VisualEditorLoader = ({ visualEditorMode, experience, }) => {
6
- const [VisualEditor, setVisualEditor] = useState(null);
7
- useEffect(() => {
8
- // Dynamically import the visual editor based on the configured mode
9
- switch (visualEditorMode) {
10
- case VisualEditorMode.InjectScript:
11
- import('./VisualEditorInjectScript.js').then((module) => {
12
- setVisualEditor(() => module.default);
13
- });
14
- break;
15
- // VisualEditorMode.LazyLoad:
16
- default:
17
- import('@contentful/experiences-visual-editor-react').then((module) => {
18
- setVisualEditor(() => module.default);
19
- });
20
- }
21
- }, [visualEditorMode]);
22
- if (!VisualEditor)
23
- return null;
24
- return jsx(VisualEditor, { experience: experience });
25
- };
26
-
27
- export { VisualEditorLoader, VisualEditorLoader as default };
28
- //# sourceMappingURL=VisualEditorLoader.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"VisualEditorLoader.js","sources":["../../../../src/blocks/editor/VisualEditorLoader.tsx"],"sourcesContent":["import React, { useEffect, useState } from 'react';\nimport { EntityStore, VisualEditorMode } 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\n experience,\n}) => {\n const [VisualEditor, setVisualEditor] = useState<React.ComponentType<{\n experience?: Experience<EntityStore>;\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 experience={experience} />;\n};\n\nexport default VisualEditorLoader;\n"],"names":["_jsx"],"mappings":";;;;AASa,MAAA,kBAAkB,GAAsC,CAAC,EACpE,gBAAgB,EAEhB,UAAU,GACX,KAAI;IACH,MAAM,CAAC,YAAY,EAAE,eAAe,CAAC,GAAG,QAAQ,CAErC,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,OAAOA,IAAC,YAAY,EAAA,EAAC,UAAU,EAAE,UAAU,GAAI,CAAC;AAClD;;;;"}
@@ -1,17 +0,0 @@
1
- import { jsx } from 'react/jsx-runtime';
2
- import React, { Suspense } from 'react';
3
- import { ErrorBoundary } from '../../components/ErrorBoundary.js';
4
- import { useInitializeVisualEditor } from '../../hooks/useInitializeVisualEditor.js';
5
-
6
- const VisualEditorLoader = React.lazy(() => import('./VisualEditorLoader.js'));
7
- const VisualEditorRoot = ({ visualEditorMode, experience, initialLocale, }) => {
8
- const initialEntities = experience?.entityStore?.entities || [];
9
- useInitializeVisualEditor({
10
- initialLocale,
11
- initialEntities,
12
- });
13
- return (jsx(ErrorBoundary, { children: jsx(Suspense, { fallback: jsx("div", { children: "Loading..." }), children: jsx(VisualEditorLoader, { experience: experience, visualEditorMode: visualEditorMode }) }) }));
14
- };
15
-
16
- export { VisualEditorRoot, VisualEditorRoot as default };
17
- //# sourceMappingURL=VisualEditorRoot.js.map
@@ -1 +0,0 @@
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 experience={experience} visualEditorMode={visualEditorMode} />\n </Suspense>\n </ErrorBoundary>\n );\n};\n\nexport default VisualEditorRoot;\n"],"names":["_jsx"],"mappings":";;;;;AAMA,MAAM,kBAAkB,GAAG,KAAK,CAAC,IAAI,CAAC,MAAM,OAAO,yBAAsB,CAAC,CAAC,CAAC;AAQrE,MAAM,gBAAgB,GAAoC,CAAC,EAChE,gBAAgB,EAChB,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;IAEH,QACEA,GAAC,CAAA,aAAa,EACZ,EAAA,QAAA,EAAAA,GAAA,CAAC,QAAQ,EAAC,EAAA,QAAQ,EAAEA,GAAA,CAAA,KAAA,EAAA,EAAA,QAAA,EAAA,YAAA,EAAA,CAAqB,EACvC,QAAA,EAAAA,GAAA,CAAC,kBAAkB,EAAC,EAAA,UAAU,EAAE,UAAU,EAAE,gBAAgB,EAAE,gBAAgB,EAAI,CAAA,EAAA,CACzE,EACG,CAAA,EAChB;AACJ;;;;"}
@@ -1,132 +0,0 @@
1
- import { jsx } from 'react/jsx-runtime';
2
- import React, { useMemo } from 'react';
3
- import { omit } from 'lodash-es';
4
- import { checkIsAssemblyNode, resolveHyperlinkPattern, transformBoundContentValue } from '@contentful/experiences-core';
5
- import { HYPERLINK_DEFAULT_PATTERN, CONTENTFUL_COMPONENTS, CF_STYLE_ATTRIBUTES } from '@contentful/experiences-core/constants';
6
- import { getComponentRegistration, createAssemblyRegistration } from '../../core/componentRegistry.js';
7
- import { useClassName } from '../../hooks/useClassName.js';
8
- import { ContentfulContainer, Columns, SingleColumn } from '@contentful/experiences-components-react';
9
- import { resolveAssembly } from '../../core/preview/assemblyUtils.js';
10
- import { Assembly } from '../../components/Assembly.js';
11
-
12
- const CompositionBlock = ({ node: rawNode, locale, entityStore, hyperlinkPattern, resolveDesignValue, }) => {
13
- const isAssembly = useMemo(() => checkIsAssemblyNode({
14
- componentId: rawNode.definitionId,
15
- usedComponents: entityStore.usedComponents,
16
- }), [entityStore.usedComponents, rawNode.definitionId]);
17
- const node = useMemo(() => {
18
- return isAssembly
19
- ? resolveAssembly({
20
- node: rawNode,
21
- entityStore,
22
- })
23
- : rawNode;
24
- }, [entityStore, isAssembly, rawNode]);
25
- const componentRegistration = useMemo(() => {
26
- const registration = getComponentRegistration(node.definitionId);
27
- if (isAssembly && !registration) {
28
- return createAssemblyRegistration({
29
- definitionId: node.definitionId,
30
- component: Assembly,
31
- });
32
- }
33
- return registration;
34
- }, [isAssembly, node.definitionId]);
35
- const nodeProps = useMemo(() => {
36
- const propMap = {
37
- cfSsrClassName: node.variables.cfSsrClassName
38
- ? resolveDesignValue(node.variables.cfSsrClassName.valuesByBreakpoint, 'cfSsrClassName')
39
- : undefined,
40
- };
41
- // Don't enrich the assembly wrapper node with props
42
- if (!componentRegistration || isAssembly) {
43
- return propMap;
44
- }
45
- const props = Object.entries(componentRegistration.definition.variables).reduce((acc, [variableName, variableDefinition]) => {
46
- const variable = node.variables[variableName];
47
- if (!variable)
48
- return acc;
49
- switch (variable.type) {
50
- case 'DesignValue':
51
- acc[variableName] = resolveDesignValue(variable.valuesByBreakpoint, variableName);
52
- break;
53
- case 'BoundValue': {
54
- const [, uuid] = variable.path.split('/');
55
- const binding = entityStore.dataSource[uuid];
56
- const value = transformBoundContentValue(node.variables, entityStore, binding, resolveDesignValue, variableName, variableDefinition, variable.path);
57
- acc[variableName] = value;
58
- break;
59
- }
60
- case 'HyperlinkValue': {
61
- const binding = entityStore.dataSource[variable.linkTargetKey];
62
- const hyperlinkEntry = entityStore.getEntryOrAsset(binding, variable.linkTargetKey);
63
- const value = resolveHyperlinkPattern(componentRegistration.definition.hyperlinkPattern ||
64
- hyperlinkPattern ||
65
- HYPERLINK_DEFAULT_PATTERN, hyperlinkEntry, locale);
66
- if (value) {
67
- acc[variableName] = value;
68
- }
69
- break;
70
- }
71
- case 'UnboundValue': {
72
- const uuid = variable.key;
73
- acc[variableName] = entityStore.unboundValues[uuid]?.value;
74
- break;
75
- }
76
- case 'ComponentValue':
77
- // We're rendering a pattern entry. Content cannot be set for ComponentValue type properties
78
- // directly in the pattern so we can safely use the default value
79
- acc[variableName] = variableDefinition.defaultValue;
80
- break;
81
- }
82
- return acc;
83
- }, propMap);
84
- if (componentRegistration.definition.slots) {
85
- for (const slotId in componentRegistration.definition.slots) {
86
- const slotNode = node.children.find((child) => child.slotId === slotId);
87
- if (slotNode) {
88
- props[slotId] = (jsx(CompositionBlock, { node: slotNode, locale: locale, hyperlinkPattern: hyperlinkPattern, entityStore: entityStore, resolveDesignValue: resolveDesignValue }));
89
- }
90
- }
91
- }
92
- return props;
93
- }, [
94
- componentRegistration,
95
- isAssembly,
96
- node.children,
97
- node.variables,
98
- resolveDesignValue,
99
- entityStore,
100
- hyperlinkPattern,
101
- locale,
102
- ]);
103
- const className = useClassName({ props: nodeProps, node });
104
- if (!componentRegistration) {
105
- return null;
106
- }
107
- const { component } = componentRegistration;
108
- const children = componentRegistration.definition.children === true
109
- ? node.children.map((childNode, index) => {
110
- return (jsx(CompositionBlock, { node: childNode, locale: locale, hyperlinkPattern: hyperlinkPattern, entityStore: entityStore, resolveDesignValue: resolveDesignValue }, index));
111
- })
112
- : null;
113
- if ([CONTENTFUL_COMPONENTS.container.id, CONTENTFUL_COMPONENTS.section.id].includes(node.definitionId)) {
114
- return (jsx(ContentfulContainer, { editorMode: false, cfHyperlink: nodeProps.cfHyperlink, cfOpenInNewTab: nodeProps.cfOpenInNewTab, className: className, children: children }));
115
- }
116
- if (node.definitionId === CONTENTFUL_COMPONENTS.columns.id) {
117
- return (jsx(Columns, { editorMode: false, className: className, children: children }));
118
- }
119
- if (node.definitionId === CONTENTFUL_COMPONENTS.singleColumn.id) {
120
- return (jsx(SingleColumn, { editorMode: false, className: className, children: children }));
121
- }
122
- //List explicit style props that will end up being passed to the component
123
- const stylesToKeep = ['cfImageAsset'];
124
- const stylesToRemove = CF_STYLE_ATTRIBUTES.filter((style) => !stylesToKeep.includes(style));
125
- return React.createElement(component, {
126
- ...omit(nodeProps, stylesToRemove, ['cfHyperlink', 'cfOpenInNewTab', 'cfSsrClassName']),
127
- className,
128
- }, children ?? (typeof nodeProps.children === 'string' ? nodeProps.children : null));
129
- };
130
-
131
- export { CompositionBlock };
132
- //# sourceMappingURL=CompositionBlock.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"CompositionBlock.js","sources":["../../../../src/blocks/preview/CompositionBlock.tsx"],"sourcesContent":["import React, { useMemo } from 'react';\nimport type { UnresolvedLink } from 'contentful';\nimport { omit } from 'lodash-es';\nimport { EntityStore, resolveHyperlinkPattern } from '@contentful/experiences-core';\nimport {\n CF_STYLE_ATTRIBUTES,\n CONTENTFUL_COMPONENTS,\n HYPERLINK_DEFAULT_PATTERN,\n} from '@contentful/experiences-core/constants';\nimport type {\n ComponentTreeNode,\n DesignValue,\n PrimitiveValue,\n ResolveDesignValueType,\n StyleProps,\n} from '@contentful/experiences-core/types';\nimport { createAssemblyRegistration, getComponentRegistration } from '../../core/componentRegistry';\nimport { checkIsAssemblyNode, transformBoundContentValue } from '@contentful/experiences-core';\nimport { useClassName } from '../../hooks/useClassName';\nimport {\n Columns,\n ContentfulContainer,\n SingleColumn,\n} from '@contentful/experiences-components-react';\n\nimport { resolveAssembly } from '../../core/preview/assemblyUtils';\nimport { Assembly } from '../../components/Assembly';\nimport { Entry } from 'contentful';\n\ntype CompositionBlockProps = {\n node: ComponentTreeNode;\n locale: string;\n entityStore: EntityStore;\n hyperlinkPattern?: string | undefined;\n resolveDesignValue: ResolveDesignValueType;\n};\n\nexport const CompositionBlock = ({\n node: rawNode,\n locale,\n entityStore,\n hyperlinkPattern,\n resolveDesignValue,\n}: CompositionBlockProps) => {\n const isAssembly = useMemo(\n () =>\n checkIsAssemblyNode({\n componentId: rawNode.definitionId,\n usedComponents: entityStore.usedComponents,\n }),\n [entityStore.usedComponents, rawNode.definitionId],\n );\n\n const node = useMemo(() => {\n return isAssembly\n ? resolveAssembly({\n node: rawNode,\n entityStore,\n })\n : rawNode;\n }, [entityStore, isAssembly, rawNode]);\n\n const componentRegistration = useMemo(() => {\n const registration = getComponentRegistration(node.definitionId as string);\n\n if (isAssembly && !registration) {\n return createAssemblyRegistration({\n definitionId: node.definitionId as string,\n component: Assembly,\n });\n }\n return registration;\n }, [isAssembly, node.definitionId]);\n\n const nodeProps = useMemo(() => {\n const propMap: Record<string, PrimitiveValue> = {\n cfSsrClassName: node.variables.cfSsrClassName\n ? resolveDesignValue(\n (node.variables.cfSsrClassName as DesignValue).valuesByBreakpoint,\n 'cfSsrClassName',\n )\n : undefined,\n };\n // Don't enrich the assembly wrapper node with props\n if (!componentRegistration || isAssembly) {\n return propMap;\n }\n\n const props = Object.entries(componentRegistration.definition.variables).reduce(\n (acc, [variableName, variableDefinition]) => {\n const variable = node.variables[variableName];\n if (!variable) return acc;\n\n switch (variable.type) {\n case 'DesignValue':\n acc[variableName] = resolveDesignValue(variable.valuesByBreakpoint, variableName);\n break;\n case 'BoundValue': {\n const [, uuid] = variable.path.split('/');\n const binding = entityStore.dataSource[uuid] as UnresolvedLink<'Entry' | 'Asset'>;\n\n const value = transformBoundContentValue(\n node.variables,\n entityStore,\n binding,\n resolveDesignValue,\n variableName,\n variableDefinition,\n variable.path,\n );\n acc[variableName] = value;\n break;\n }\n\n case 'HyperlinkValue': {\n const binding = entityStore.dataSource[variable.linkTargetKey];\n const hyperlinkEntry = entityStore.getEntryOrAsset(binding, variable.linkTargetKey);\n\n const value = resolveHyperlinkPattern(\n componentRegistration.definition.hyperlinkPattern ||\n hyperlinkPattern ||\n HYPERLINK_DEFAULT_PATTERN,\n hyperlinkEntry as Entry,\n locale,\n );\n if (value) {\n acc[variableName] = value;\n }\n break;\n }\n case 'UnboundValue': {\n const uuid = variable.key;\n acc[variableName] = entityStore.unboundValues[uuid]?.value;\n break;\n }\n case 'ComponentValue':\n // We're rendering a pattern entry. Content cannot be set for ComponentValue type properties\n // directly in the pattern so we can safely use the default value\n acc[variableName] = variableDefinition.defaultValue;\n break;\n default:\n break;\n }\n return acc;\n },\n propMap,\n );\n\n if (componentRegistration.definition.slots) {\n for (const slotId in componentRegistration.definition.slots) {\n const slotNode = node.children.find((child) => child.slotId === slotId);\n if (slotNode) {\n props[slotId] = (\n <CompositionBlock\n node={slotNode}\n locale={locale}\n hyperlinkPattern={hyperlinkPattern}\n entityStore={entityStore}\n resolveDesignValue={resolveDesignValue}\n />\n );\n }\n }\n }\n\n return props;\n }, [\n componentRegistration,\n isAssembly,\n node.children,\n node.variables,\n resolveDesignValue,\n entityStore,\n hyperlinkPattern,\n locale,\n ]);\n\n const className = useClassName({ props: nodeProps, node });\n\n if (!componentRegistration) {\n return null;\n }\n\n const { component } = componentRegistration;\n\n const children =\n componentRegistration.definition.children === true\n ? node.children.map((childNode: ComponentTreeNode, index) => {\n return (\n <CompositionBlock\n node={childNode}\n key={index}\n locale={locale}\n hyperlinkPattern={hyperlinkPattern}\n entityStore={entityStore}\n resolveDesignValue={resolveDesignValue}\n />\n );\n })\n : null;\n\n if (\n [CONTENTFUL_COMPONENTS.container.id, CONTENTFUL_COMPONENTS.section.id].includes(\n node.definitionId,\n )\n ) {\n return (\n <ContentfulContainer\n editorMode={false}\n cfHyperlink={(nodeProps as StyleProps).cfHyperlink}\n cfOpenInNewTab={(nodeProps as StyleProps).cfOpenInNewTab}\n className={className}>\n {children}\n </ContentfulContainer>\n );\n }\n\n if (node.definitionId === CONTENTFUL_COMPONENTS.columns.id) {\n return (\n <Columns editorMode={false} className={className}>\n {children}\n </Columns>\n );\n }\n\n if (node.definitionId === CONTENTFUL_COMPONENTS.singleColumn.id) {\n return (\n <SingleColumn editorMode={false} className={className}>\n {children}\n </SingleColumn>\n );\n }\n\n //List explicit style props that will end up being passed to the component\n const stylesToKeep = ['cfImageAsset'];\n const stylesToRemove = CF_STYLE_ATTRIBUTES.filter((style) => !stylesToKeep.includes(style));\n\n return React.createElement(\n component,\n {\n ...omit(nodeProps, stylesToRemove, ['cfHyperlink', 'cfOpenInNewTab', 'cfSsrClassName']),\n className,\n },\n children ?? (typeof nodeProps.children === 'string' ? nodeProps.children : null),\n );\n};\n"],"names":["_jsx"],"mappings":";;;;;;;;;;;AAqCa,MAAA,gBAAgB,GAAG,CAAC,EAC/B,IAAI,EAAE,OAAO,EACb,MAAM,EACN,WAAW,EACX,gBAAgB,EAChB,kBAAkB,GACI,KAAI;IAC1B,MAAM,UAAU,GAAG,OAAO,CACxB,MACE,mBAAmB,CAAC;QAClB,WAAW,EAAE,OAAO,CAAC,YAAY;QACjC,cAAc,EAAE,WAAW,CAAC,cAAc;KAC3C,CAAC,EACJ,CAAC,WAAW,CAAC,cAAc,EAAE,OAAO,CAAC,YAAY,CAAC,CACnD,CAAC;AAEF,IAAA,MAAM,IAAI,GAAG,OAAO,CAAC,MAAK;AACxB,QAAA,OAAO,UAAU;cACb,eAAe,CAAC;AACd,gBAAA,IAAI,EAAE,OAAO;gBACb,WAAW;aACZ,CAAC;cACF,OAAO,CAAC;KACb,EAAE,CAAC,WAAW,EAAE,UAAU,EAAE,OAAO,CAAC,CAAC,CAAC;AAEvC,IAAA,MAAM,qBAAqB,GAAG,OAAO,CAAC,MAAK;QACzC,MAAM,YAAY,GAAG,wBAAwB,CAAC,IAAI,CAAC,YAAsB,CAAC,CAAC;AAE3E,QAAA,IAAI,UAAU,IAAI,CAAC,YAAY,EAAE;AAC/B,YAAA,OAAO,0BAA0B,CAAC;gBAChC,YAAY,EAAE,IAAI,CAAC,YAAsB;AACzC,gBAAA,SAAS,EAAE,QAAQ;AACpB,aAAA,CAAC,CAAC;SACJ;AACD,QAAA,O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AK,EACjB,WAAW,EAAG,SAAwB,CAAC,WAAW,EAClD,cAAc,EAAG,SAAwB,CAAC,cAAc,EACxD,SAAS,EAAE,SAAS,EACnB,QAAA,EAAA,QAAQ,EACW,CAAA,EACtB;KACH;IAED,IAAI,IAAI,CAAC,YAAY,KAAK,qBAAqB,CAAC,OAAO,CAAC,EAAE,EAAE;AAC1D,QAAA,QACEA,GAAA,CAAC,OAAO,EAAA,EAAC,UAAU,EAAE,KAAK,EAAE,SAAS,EAAE,SAAS,EAAA,QAAA,EAC7C,QAAQ,EAAA,CACD,EACV;KACH;IAED,IAAI,IAAI,CAAC,YAAY,KAAK,qBAAqB,CAAC,YAAY,CAAC,EAAE,EAAE;AAC/D,QAAA,QACEA,GAAA,CAAC,YAAY,EAAA,EAAC,UAAU,EAAE,KAAK,EAAE,SAAS,EAAE,SAAS,EAAA,QAAA,EAClD,QAAQ,EAAA,CACI,EACf;KACH;;AAGD,IAAA,MAAM,YAAY,GAAG,CAAC,cAAc,CAAC,CAAC;AACtC,IAAA,MAAM,cAAc,GAAG,mBAAmB,CAAC,MAAM,CAAC,CAAC,KAAK,KAAK,CAAC,YAAY,CAAC,QAAQ,CAAC,KAAK,CAAC,CAAC,CAAC;AAE5F,IAAA,OAAO,KAAK,CAAC,aAAa,CACxB,SAAS,EACT;AACE,QAAA,GAAG,IAAI,CAAC,SAAS,EAAE,cAAc,EAAE,CAAC,aAAa,EAAE,gBAAgB,EAAE,gBAAgB,CAAC,CAAC;QACvF,SAAS;KACV,EACD,QAAQ,KAAK,OAAO,SAAS,CAAC,QAAQ,KAAK,QAAQ,GAAG,SAAS,CAAC,QAAQ,GAAG,IAAI,CAAC,CACjF,CAAC;AACJ;;;;"}
@@ -1,23 +0,0 @@
1
- import { jsx, Fragment } from 'react/jsx-runtime';
2
- import { CompositionBlock } from './CompositionBlock.js';
3
- import { compatibleVersions } from '../../constants.js';
4
- import { useBreakpoints } from '../../hooks/useBreakpoints.js';
5
- import 'react';
6
- import '@contentful/experiences-core';
7
- import '@contentful/experiences-core/constants';
8
-
9
- const PreviewDeliveryRoot = ({ locale, experience }) => {
10
- const { entityStore } = experience;
11
- const { resolveDesignValue } = useBreakpoints(entityStore?.breakpoints ?? []);
12
- if (!entityStore?.experienceEntryFields || !entityStore?.schemaVersion) {
13
- return null;
14
- }
15
- if (!compatibleVersions.includes(entityStore.schemaVersion)) {
16
- console.warn(`[experiences-sdk-react] Contentful experience schema version: ${entityStore.schemaVersion} does not match the compatible schema versions: ${compatibleVersions}. Aborting.`);
17
- return null;
18
- }
19
- return (jsx(Fragment, { children: entityStore.experienceEntryFields.componentTree.children.map((childNode, index) => (jsx(CompositionBlock, { node: childNode, hyperlinkPattern: experience.hyperlinkPattern, locale: locale, entityStore: entityStore, resolveDesignValue: resolveDesignValue }, index))) }));
20
- };
21
-
22
- export { PreviewDeliveryRoot };
23
- //# sourceMappingURL=PreviewDeliveryRoot.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"PreviewDeliveryRoot.js","sources":["../../../../src/blocks/preview/PreviewDeliveryRoot.tsx"],"sourcesContent":["import React from 'react';\nimport { EntityStore } from '@contentful/experiences-core';\nimport type { Experience } from '@contentful/experiences-core/types';\nimport { CompositionBlock } from './CompositionBlock';\nimport { compatibleVersions } from '../../constants';\nimport { useBreakpoints } from '../../hooks';\n\ntype DeliveryRootProps = {\n experience: Experience<EntityStore>;\n locale: string;\n};\n\nexport const PreviewDeliveryRoot = ({ locale, experience }: DeliveryRootProps) => {\n const { entityStore } = experience;\n\n const { resolveDesignValue } = useBreakpoints(entityStore?.breakpoints ?? []);\n\n if (!entityStore?.experienceEntryFields || !entityStore?.schemaVersion) {\n return null;\n }\n\n if (!compatibleVersions.includes(entityStore.schemaVersion)) {\n console.warn(\n `[experiences-sdk-react] Contentful experience schema version: ${entityStore.schemaVersion} does not match the compatible schema versions: ${compatibleVersions}. Aborting.`,\n );\n return null;\n }\n\n return (\n <>\n {entityStore.experienceEntryFields.componentTree.children.map((childNode, index) => (\n <CompositionBlock\n key={index}\n node={childNode}\n hyperlinkPattern={experience.hyperlinkPattern}\n locale={locale}\n entityStore={entityStore}\n resolveDesignValue={resolveDesignValue}\n />\n ))}\n </>\n );\n};\n"],"names":["_jsx"],"mappings":";;;;;;;;AAYa,MAAA,mBAAmB,GAAG,CAAC,EAAE,MAAM,EAAE,UAAU,EAAqB,KAAI;AAC/E,IAAA,MAAM,EAAE,WAAW,EAAE,GAAG,UAAU,CAAC;AAEnC,IAAA,MAAM,EAAE,kBAAkB,EAAE,GAAG,cAAc,CAAC,WAAW,EAAE,WAAW,IAAI,EAAE,CAAC,CAAC;IAE9E,IAAI,CAAC,WAAW,EAAE,qBAAqB,IAAI,CAAC,WAAW,EAAE,aAAa,EAAE;AACtE,QAAA,OAAO,IAAI,CAAC;KACb;IAED,IAAI,CAAC,kBAAkB,CAAC,QAAQ,CAAC,WAAW,CAAC,aAAa,CAAC,EAAE;QAC3D,OAAO,CAAC,IAAI,CACV,CAAiE,8DAAA,EAAA,WAAW,CAAC,aAAa,CAAmD,gDAAA,EAAA,kBAAkB,CAAa,WAAA,CAAA,CAC7K,CAAC;AACF,QAAA,OAAO,IAAI,CAAC;KACb;IAED,QACEA,0BACG,WAAW,CAAC,qBAAqB,CAAC,aAAa,CAAC,QAAQ,CAAC,GAAG,CAAC,CAAC,SAAS,EAAE,KAAK,MAC7EA,GAAA,CAAC,gBAAgB,EAAA,EAEf,IAAI,EAAE,SAAS,EACf,gBAAgB,EAAE,UAAU,CAAC,gBAAgB,EAC7C,MAAM,EAAE,MAAM,EACd,WAAW,EAAE,WAAW,EACxB,kBAAkB,EAAE,kBAAkB,EALjC,EAAA,KAAK,CAMV,CACH,CAAC,EACD,CAAA,EACH;AACJ;;;;"}
@@ -1,13 +0,0 @@
1
- import { jsx } from 'react/jsx-runtime';
2
-
3
- const assemblyStyle = { display: 'contents' };
4
- // Feel free to do any magic as regards variable definitions for assemblies
5
- // Or if this isn't necessary by the time we figure that part out, we can bid this part farewell
6
- const Assembly = ({ ...props }) => {
7
- // Using a display contents so assembly content/children
8
- // can appear as if they are direct children of the div wrapper's parent
9
- return jsx("div", { "data-test-id": "assembly", ...props, style: assemblyStyle });
10
- };
11
-
12
- export { Assembly };
13
- //# sourceMappingURL=Assembly.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"Assembly.js","sources":["../../../src/components/Assembly.tsx"],"sourcesContent":["import React from 'react';\n\nconst assemblyStyle = { display: 'contents' };\n\n// Feel free to do any magic as regards variable definitions for assemblies\n// Or if this isn't necessary by the time we figure that part out, we can bid this part farewell\nexport const Assembly = ({ ...props }) => {\n // Using a display contents so assembly content/children\n // can appear as if they are direct children of the div wrapper's parent\n return <div data-test-id=\"assembly\" {...props} style={assemblyStyle} />;\n};\n"],"names":["_jsx"],"mappings":";;AAEA,MAAM,aAAa,GAAG,EAAE,OAAO,EAAE,UAAU,EAAE,CAAC;AAE9C;AACA;AACa,MAAA,QAAQ,GAAG,CAAC,EAAE,GAAG,KAAK,EAAE,KAAI;;;IAGvC,OAAOA,GAAA,CAAA,KAAA,EAAA,EAAA,cAAA,EAAkB,UAAU,EAAK,GAAA,KAAK,EAAE,KAAK,EAAE,aAAa,EAAA,CAAI,CAAC;AAC1E;;;;"}
@@ -1,37 +0,0 @@
1
- import { jsxs, jsx } from 'react/jsx-runtime';
2
- import React from 'react';
3
- import { sendMessage } from '@contentful/experiences-core';
4
- import '../styles/ErrorBoundary.css.js';
5
- import { OUTGOING_EVENTS } from '@contentful/experiences-core/constants';
6
-
7
- class ErrorBoundary extends React.Component {
8
- constructor(props) {
9
- super(props);
10
- this.state = { hasError: false, error: null, errorInfo: null, showErrorDetails: false };
11
- }
12
- static getDerivedStateFromError() {
13
- return { hasError: true };
14
- }
15
- componentDidCatch(error, errorInfo) {
16
- this.setState({ error, errorInfo });
17
- if (error.name !== 'ImportedComponentError') {
18
- sendMessage(OUTGOING_EVENTS.CanvasError, error);
19
- }
20
- else {
21
- throw error;
22
- }
23
- }
24
- render() {
25
- if (this.state.hasError) {
26
- return (jsxs("div", { className: "cf-error-message", children: [jsx("h2", { className: "title", children: `Something went wrong while rendering the experience` }), jsxs("div", { children: ["The Experience Builder SDK has encountered an error. It may be that the SDK has not been set up properly or an imported component has thrown this error. Try to refresh the page and find more guidance in our", ' ', jsx("a", { href: "https://www.contentful.com/developers/docs/tutorials/general/experience-builder/", rel: "noreferrer", target: "_blank", children: "documentation" }), "."] }), jsx("br", {}), jsxs("span", { className: "more-details", onClick: () => this.setState((prevState) => ({
27
- showErrorDetails: !prevState.showErrorDetails,
28
- })), children: [this.state.showErrorDetails ? 'Hide' : 'See', " details"] }), this.state.showErrorDetails && (jsx("code", { children: this.state.error?.stack?.split('\n').map((i, key) => {
29
- return jsx("div", { children: i }, key);
30
- }) }))] }));
31
- }
32
- return this.props.children;
33
- }
34
- }
35
-
36
- export { ErrorBoundary };
37
- //# sourceMappingURL=ErrorBoundary.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"ErrorBoundary.js","sources":["../../../src/components/ErrorBoundary.tsx"],"sourcesContent":["import React, { ErrorInfo, ReactElement } from 'react';\nimport { sendMessage } from '@contentful/experiences-core';\nimport '../styles/ErrorBoundary.css';\nimport { OUTGOING_EVENTS } from '@contentful/experiences-core/constants';\n\n('use client');\n\nexport class ErrorBoundary extends React.Component<\n { children: ReactElement },\n { hasError: boolean; error: Error | null; errorInfo: ErrorInfo | null; showErrorDetails: boolean }\n> {\n constructor(props: { children: ReactElement }) {\n super(props);\n this.state = { hasError: false, error: null, errorInfo: null, showErrorDetails: false };\n }\n\n static getDerivedStateFromError() {\n return { hasError: true };\n }\n\n componentDidCatch(error: Error, errorInfo: ErrorInfo) {\n this.setState({ error, errorInfo });\n if (error.name !== 'ImportedComponentError') {\n sendMessage(OUTGOING_EVENTS.CanvasError, error);\n } else {\n throw error;\n }\n }\n\n render() {\n if (this.state.hasError) {\n return (\n <div className=\"cf-error-message\">\n <h2 className=\"title\">{`Something went wrong while rendering the experience`}</h2>\n <div>\n The Experience Builder SDK has encountered an error. It may be that the SDK has not been\n set up properly or an imported component has thrown this error. Try to refresh the page\n and find more guidance in our{' '}\n <a\n href=\"https://www.contentful.com/developers/docs/tutorials/general/experience-builder/\"\n rel=\"noreferrer\"\n target=\"_blank\">\n documentation\n </a>\n .\n </div>\n <br />\n <span\n className=\"more-details\"\n onClick={() =>\n this.setState((prevState) => ({\n showErrorDetails: !prevState.showErrorDetails,\n }))\n }>\n {this.state.showErrorDetails ? 'Hide' : 'See'} details\n </span>\n {this.state.showErrorDetails && (\n <code>\n {this.state.error?.stack?.split('\\n').map((i, key) => {\n return <div key={key}>{i}</div>;\n })}\n </code>\n )}\n </div>\n );\n }\n return this.props.children;\n }\n}\n"],"names":["_jsxs","_jsx"],"mappings":";;;;;;AAOa,MAAA,aAAc,SAAQ,KAAK,CAAC,SAGxC,CAAA;AACC,IAAA,WAAA,CAAY,KAAiC,EAAA;QAC3C,KAAK,CAAC,KAAK,CAAC,CAAC;QACb,IAAI,CAAC,KAAK,GAAG,EAAE,QAAQ,EAAE,KAAK,EAAE,KAAK,EAAE,IAAI,EAAE,SAAS,EAAE,IAAI,EAAE,gBAAgB,EAAE,KAAK,EAAE,CAAC;KACzF;AAED,IAAA,OAAO,wBAAwB,GAAA;AAC7B,QAAA,OAAO,EAAE,QAAQ,EAAE,IAAI,EAAE,CAAC;KAC3B;IAED,iBAAiB,CAAC,KAAY,EAAE,SAAoB,EAAA;QAClD,IAAI,CAAC,QAAQ,CAAC,EAAE,KAAK,EAAE,SAAS,EAAE,CAAC,CAAC;AACpC,QAAA,IAAI,KAAK,CAAC,IAAI,KAAK,wBAAwB,EAAE;AAC3C,YAAA,WAAW,CAAC,eAAe,CAAC,WAAW,EAAE,KAAK,CAAC,CAAC;SACjD;aAAM;AACL,YAAA,MAAM,KAAK,CAAC;SACb;KACF;IAED,MAAM,GAAA;AACJ,QAAA,IAAI,IAAI,CAAC,KAAK,CAAC,QAAQ,EAAE;YACvB,QACEA,IAAK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VERSION is compatible with
2
- const compatibleVersions = ['2023-09-28'];
3
-
4
- export { compatibleVersions };
5
- //# sourceMappingURL=constants.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"constants.js","sources":["../../src/constants.ts"],"sourcesContent":["import type { SchemaVersions } from '@contentful/experiences-core/types';\n\n// this is the array of version which currently LATEST_SCHEMA_VERSION is compatible with\nexport const compatibleVersions: SchemaVersions[] = ['2023-09-28'];\n\nexport { SDK_VERSION } from './sdkVersion';\n"],"names":[],"mappings":"AAEA;AACa,MAAA,kBAAkB,GAAqB,CAAC,YAAY;;;;"}