@contentful/experiences-sdk-react 1.0.4 → 1.0.5-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.
@@ -2,7 +2,7 @@ import { jsx } from 'react/jsx-runtime';
2
2
  import { useState, useEffect } from 'react';
3
3
  import { VisualEditorMode } from '@contentful/experiences-core';
4
4
 
5
- const VisualEditorLoader = ({ visualEditorMode }) => {
5
+ const VisualEditorLoader = ({ visualEditorMode, experience, }) => {
6
6
  const [VisualEditor, setVisualEditor] = useState(null);
7
7
  useEffect(() => {
8
8
  // Dynamically import the visual editor based on the configured mode
@@ -21,8 +21,8 @@ const VisualEditorLoader = ({ visualEditorMode }) => {
21
21
  }, [visualEditorMode]);
22
22
  if (!VisualEditor)
23
23
  return null;
24
- return jsx(VisualEditor, {});
24
+ return jsx(VisualEditor, { experience: experience });
25
25
  };
26
26
 
27
27
  export { VisualEditorLoader, VisualEditorLoader as default };
28
- //# sourceMappingURL=VisualEditorLoader-255ce544.js.map
28
+ //# sourceMappingURL=VisualEditorLoader-3839b3a6.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"VisualEditorLoader-3839b3a6.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,wCAA4B,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;;;;"}
package/dist/index.d.ts CHANGED
@@ -2,7 +2,6 @@ import * as react_jsx_runtime from 'react/jsx-runtime';
2
2
  import * as _contentful_experiences_core from '@contentful/experiences-core';
3
3
  import { EntityStore, VisualEditorMode } from '@contentful/experiences-core';
4
4
  export { VisualEditorMode, createExperience, defineDesignTokens, fetchById, fetchBySlug } from '@contentful/experiences-core';
5
- import * as _contentful_experiences_core_types from '@contentful/experiences-core/types';
6
5
  import { Experience, ComponentRegistration, ComponentRegistrationOptions } from '@contentful/experiences-core/types';
7
6
  export { ComponentDefinition, ExternalSDKMode } from '@contentful/experiences-core/types';
8
7
  import { ContentfulClientApi } from 'contentful';
@@ -20,10 +19,14 @@ type UseFetchByIdArgs = {
20
19
  id: string;
21
20
  experienceTypeId: string;
22
21
  localeCode: string;
22
+ hyperlinkPattern?: string;
23
23
  };
24
- declare const useFetchById: ({ id, localeCode, client, experienceTypeId }: UseFetchByIdArgs) => {
24
+ declare const useFetchById: ({ id, localeCode, client, experienceTypeId, hyperlinkPattern, }: UseFetchByIdArgs) => {
25
+ experience: {
26
+ hyperlinkPattern: string | undefined;
27
+ entityStore?: _contentful_experiences_core.EntityStore | undefined;
28
+ };
25
29
  error: Error | undefined;
26
- experience: _contentful_experiences_core_types.Experience<_contentful_experiences_core.EntityStore> | undefined;
27
30
  isLoading: boolean;
28
31
  isEditorMode: boolean;
29
32
  };
@@ -33,10 +36,15 @@ type UseFetchBySlugArgs = {
33
36
  slug: string;
34
37
  experienceTypeId: string;
35
38
  localeCode: string;
39
+ /** The pattern being used to generate links for hyperlink properties **/
40
+ hyperlinkPattern?: string;
36
41
  };
37
- declare const useFetchBySlug: ({ slug, localeCode, client, experienceTypeId, }: UseFetchBySlugArgs) => {
42
+ declare const useFetchBySlug: ({ slug, localeCode, client, experienceTypeId, hyperlinkPattern, }: UseFetchBySlugArgs) => {
43
+ experience: {
44
+ hyperlinkPattern: string | undefined;
45
+ entityStore?: _contentful_experiences_core.EntityStore | undefined;
46
+ };
38
47
  error: Error | undefined;
39
- experience: _contentful_experiences_core_types.Experience<_contentful_experiences_core.EntityStore> | undefined;
40
48
  isLoading: boolean;
41
49
  isEditorMode: boolean;
42
50
  };
package/dist/index.js CHANGED
@@ -1,15 +1,15 @@
1
1
  import { jsx, Fragment, jsxs } from 'react/jsx-runtime';
2
- import { containerDefinition, sectionDefinition, columnsDefinition, singleColumnDefinition, dividerDefinition, builtInStyles, optionalBuiltInStyles, sendMessage, designTokensRegistry, buildStyleTag, checkIsAssemblyNode, transformBoundContentValue, buildCfStyles, isEmptyStructureWithRelativeHeight, mediaQueryMatcher, getFallbackBreakpointIndex, getActiveBreakpointIndex, getValueForBreakpoint, doesMismatchMessageSchema, tryParseMessage, fetchById, fetchBySlug, validateExperienceBuilderConfig, VisualEditorMode } from '@contentful/experiences-core';
2
+ import { containerDefinition, sectionDefinition, columnsDefinition, singleColumnDefinition, dividerDefinition, builtInStyles, optionalBuiltInStyles, sendMessage, designTokensRegistry, buildStyleTag, checkIsAssemblyNode, resolveHyperlinkPattern, transformBoundContentValue, buildCfStyles, isEmptyStructureWithRelativeHeight, mediaQueryMatcher, getFallbackBreakpointIndex, getActiveBreakpointIndex, getValueForBreakpoint, doesMismatchMessageSchema, tryParseMessage, fetchById, fetchBySlug, validateExperienceBuilderConfig, VisualEditorMode } from '@contentful/experiences-core';
3
3
  export { VisualEditorMode, createExperience, defineDesignTokens, fetchById, fetchBySlug } from '@contentful/experiences-core';
4
4
  import React, { useMemo, useLayoutEffect, useState, useEffect, useCallback, useRef, Suspense } from 'react';
5
5
  import { omit } from 'lodash-es';
6
- import { INTERNAL_EVENTS, CONTENTFUL_COMPONENTS, OUTGOING_EVENTS, ASSEMBLY_DEFAULT_CATEGORY, EMPTY_CONTAINER_HEIGHT, CF_STYLE_ATTRIBUTES, INCOMING_EVENTS, VISUAL_EDITOR_EVENTS } from '@contentful/experiences-core/constants';
6
+ import { INTERNAL_EVENTS, CONTENTFUL_COMPONENTS, OUTGOING_EVENTS, ASSEMBLY_DEFAULT_CATEGORY, HYPERLINK_DEFAULT_PATTERN, EMPTY_CONTAINER_HEIGHT, CF_STYLE_ATTRIBUTES, INCOMING_EVENTS, VISUAL_EDITOR_EVENTS } from '@contentful/experiences-core/constants';
7
7
  export { CF_STYLE_ATTRIBUTES, CONTENTFUL_COMPONENTS, LATEST_SCHEMA_VERSION } from '@contentful/experiences-core/constants';
8
8
  import * as Components from '@contentful/experiences-components-react';
9
9
  import { ContentfulContainer, Columns, SingleColumn } from '@contentful/experiences-components-react';
10
10
  import styleInject from 'style-inject';
11
11
 
12
- const SDK_VERSION = '1.0.4-beta.0';
12
+ const SDK_VERSION = '1.0.4';
13
13
 
14
14
  var util;
15
15
  (function (util) {
@@ -4652,6 +4652,12 @@ const deserializeAssemblyNode = ({ node, componentInstanceVariables, }) => {
4652
4652
  path: instanceProperty.path,
4653
4653
  };
4654
4654
  }
4655
+ else if (instanceProperty?.type === 'HyperlinkValue') {
4656
+ variables[variableName] = {
4657
+ type: 'HyperlinkValue',
4658
+ linkTargetKey: instanceProperty.linkTargetKey,
4659
+ };
4660
+ }
4655
4661
  }
4656
4662
  }
4657
4663
  const children = node.children.map((child) => deserializeAssemblyNode({
@@ -4699,7 +4705,7 @@ const Assembly = ({ ...props }) => {
4699
4705
  return jsx("div", { "data-test-id": "assembly", ...props, style: assemblyStyle });
4700
4706
  };
4701
4707
 
4702
- const CompositionBlock = ({ node: rawNode, locale, entityStore, resolveDesignValue, }) => {
4708
+ const CompositionBlock = ({ node: rawNode, locale, entityStore, hyperlinkPattern, resolveDesignValue, }) => {
4703
4709
  const isAssembly = useMemo(() => checkIsAssemblyNode({
4704
4710
  componentId: rawNode.definitionId,
4705
4711
  usedComponents: entityStore.usedComponents,
@@ -4743,6 +4749,17 @@ const CompositionBlock = ({ node: rawNode, locale, entityStore, resolveDesignVal
4743
4749
  acc[variableName] = value;
4744
4750
  break;
4745
4751
  }
4752
+ case 'HyperlinkValue': {
4753
+ const binding = entityStore.dataSource[variable.linkTargetKey];
4754
+ const hyperlinkEntry = entityStore.getEntryOrAsset(binding, variable.linkTargetKey);
4755
+ const value = resolveHyperlinkPattern(componentRegistration.definition.hyperlinkPattern ||
4756
+ hyperlinkPattern ||
4757
+ HYPERLINK_DEFAULT_PATTERN, hyperlinkEntry, locale);
4758
+ if (value) {
4759
+ acc[variableName] = value;
4760
+ }
4761
+ break;
4762
+ }
4746
4763
  case 'UnboundValue': {
4747
4764
  const uuid = variable.key;
4748
4765
  acc[variableName] = entityStore.unboundValues[uuid]?.value;
@@ -4751,7 +4768,15 @@ const CompositionBlock = ({ node: rawNode, locale, entityStore, resolveDesignVal
4751
4768
  }
4752
4769
  return acc;
4753
4770
  }, propMap);
4754
- }, [componentRegistration, isAssembly, node.variables, resolveDesignValue, entityStore]);
4771
+ }, [
4772
+ componentRegistration,
4773
+ isAssembly,
4774
+ node.variables,
4775
+ resolveDesignValue,
4776
+ entityStore,
4777
+ hyperlinkPattern,
4778
+ locale,
4779
+ ]);
4755
4780
  const cfStyles = buildCfStyles(nodeProps, node.definitionId);
4756
4781
  if (isEmptyStructureWithRelativeHeight(node.children.length, node.definitionId, cfStyles.height)) {
4757
4782
  cfStyles.minHeight = EMPTY_CONTAINER_HEIGHT;
@@ -4763,7 +4788,7 @@ const CompositionBlock = ({ node: rawNode, locale, entityStore, resolveDesignVal
4763
4788
  const { component } = componentRegistration;
4764
4789
  const children = componentRegistration.definition.children === true
4765
4790
  ? node.children.map((childNode, index) => {
4766
- return (jsx(CompositionBlock, { node: childNode, locale: locale, entityStore: entityStore, resolveDesignValue: resolveDesignValue }, index));
4791
+ return (jsx(CompositionBlock, { node: childNode, locale: locale, hyperlinkPattern: hyperlinkPattern, entityStore: entityStore, resolveDesignValue: resolveDesignValue }, index));
4767
4792
  })
4768
4793
  : null;
4769
4794
  if ([CONTENTFUL_COMPONENTS.container.id, CONTENTFUL_COMPONENTS.section.id].includes(node.definitionId)) {
@@ -4903,20 +4928,22 @@ function inIframe() {
4903
4928
  }
4904
4929
  }
4905
4930
 
4906
- const useFetchById = ({ id, localeCode, client, experienceTypeId }) => {
4931
+ const useFetchById = ({ id, localeCode, client, experienceTypeId, hyperlinkPattern, }) => {
4907
4932
  const isEditorMode = useDetectEditorMode({ isClientSide: typeof window !== 'undefined' });
4908
4933
  const fetchMethod = useCallback(() => {
4909
4934
  return fetchById({ id, localeCode, client, experienceTypeId });
4910
4935
  }, [id, localeCode, client, experienceTypeId]);
4911
- return useFetchByBase(fetchMethod, isEditorMode);
4936
+ const fetchResult = useFetchByBase(fetchMethod, isEditorMode);
4937
+ return { ...fetchResult, experience: { ...fetchResult.experience, hyperlinkPattern } };
4912
4938
  };
4913
4939
 
4914
- const useFetchBySlug = ({ slug, localeCode, client, experienceTypeId, }) => {
4940
+ const useFetchBySlug = ({ slug, localeCode, client, experienceTypeId, hyperlinkPattern, }) => {
4915
4941
  const isEditorMode = useDetectEditorMode({ isClientSide: typeof window !== 'undefined' });
4916
4942
  const fetchMethod = useCallback(() => {
4917
4943
  return fetchBySlug({ slug, localeCode, client, experienceTypeId });
4918
4944
  }, [slug, localeCode, client, experienceTypeId]);
4919
- return useFetchByBase(fetchMethod, isEditorMode);
4945
+ const fetchResult = useFetchByBase(fetchMethod, isEditorMode);
4946
+ return { ...fetchResult, experience: { ...fetchResult.experience, hyperlinkPattern } };
4920
4947
  };
4921
4948
 
4922
4949
  const PreviewDeliveryRoot = ({ locale, experience }) => {
@@ -4929,7 +4956,7 @@ const PreviewDeliveryRoot = ({ locale, experience }) => {
4929
4956
  console.warn(`[experiences-sdk-react] Contentful experience schema version: ${entityStore.schemaVersion} does not match the compatible schema versions: ${compatibleVersions}. Aborting.`);
4930
4957
  return null;
4931
4958
  }
4932
- return (jsx(Fragment, { children: entityStore.experienceEntryFields.componentTree.children.map((childNode, index) => (jsx(CompositionBlock, { node: childNode, locale: locale, entityStore: entityStore, resolveDesignValue: resolveDesignValue }, index))) }));
4959
+ 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))) }));
4933
4960
  };
4934
4961
 
4935
4962
  var css_248z = ".cf-error-message {\n margin: 24px;\n font-size: var(--exp-builder-font-size-m);\n font-family: var(--exp-builder-font-stack-primary);\n color: var(--exp-builder-red800);\n padding: 16px;\n background-color: var(--exp-builder-red200);\n}\n\n.cf-error-message .title {\n margin-top: 0;\n font-size: var(--exp-builder-font-size-l);\n}\n\n.cf-error-message .more-details {\n cursor: pointer;\n color: var(--exp-builder-blue700);\n}\n";
@@ -5023,13 +5050,14 @@ const useInitializeVisualEditor = (params) => {
5023
5050
  }, [locale, initialEntities]);
5024
5051
  };
5025
5052
 
5026
- const VisualEditorLoader = React.lazy(() => import('./VisualEditorLoader-255ce544.js'));
5027
- const VisualEditorRoot = ({ visualEditorMode, initialEntities, initialLocale, }) => {
5053
+ const VisualEditorLoader = React.lazy(() => import('./VisualEditorLoader-3839b3a6.js'));
5054
+ const VisualEditorRoot = ({ visualEditorMode, experience, initialLocale, }) => {
5055
+ const initialEntities = experience?.entityStore?.entities || [];
5028
5056
  useInitializeVisualEditor({
5029
5057
  initialLocale,
5030
5058
  initialEntities,
5031
5059
  });
5032
- return (jsx(ErrorBoundary, { children: jsx(Suspense, { fallback: jsx("div", { children: "Loading..." }), children: jsx(VisualEditorLoader, { visualEditorMode: visualEditorMode }) }) }));
5060
+ return (jsx(ErrorBoundary, { children: jsx(Suspense, { fallback: jsx("div", { children: "Loading..." }), children: jsx(VisualEditorLoader, { experience: experience, visualEditorMode: visualEditorMode }) }) }));
5033
5061
  };
5034
5062
 
5035
5063
  const ExperienceRoot = ({ locale, experience, visualEditorMode = VisualEditorMode.LazyLoad, }) => {
@@ -5039,8 +5067,7 @@ const ExperienceRoot = ({ locale, experience, visualEditorMode = VisualEditorMod
5039
5067
  isEditorMode,
5040
5068
  });
5041
5069
  if (isEditorMode) {
5042
- const entityStore = experience?.entityStore;
5043
- return (jsx(VisualEditorRoot, { visualEditorMode: visualEditorMode, initialEntities: entityStore?.entities || [], initialLocale: locale }));
5070
+ return (jsx(VisualEditorRoot, { experience: experience, visualEditorMode: visualEditorMode, initialLocale: locale }));
5044
5071
  }
5045
5072
  if (!experience)
5046
5073
  return null;