@contentful/experiences-sdk-react 1.8.2-dev-20240625T1531-940b953.0 → 1.8.2-dev-20240625T1857-ee5ef2b.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 +25 -0
- package/dist/ExperienceRoot.js.map +1 -0
- package/dist/{VisualEditorInjectScript-6a92528d.js → blocks/editor/VisualEditorInjectScript.js} +1 -1
- package/dist/blocks/editor/VisualEditorInjectScript.js.map +1 -0
- package/dist/{VisualEditorLoader-3839b3a6.js → blocks/editor/VisualEditorLoader.js} +2 -2
- package/dist/blocks/editor/VisualEditorLoader.js.map +1 -0
- package/dist/blocks/editor/VisualEditorRoot.js +17 -0
- package/dist/blocks/editor/VisualEditorRoot.js.map +1 -0
- package/dist/blocks/preview/CompositionBlock.js +132 -0
- package/dist/blocks/preview/CompositionBlock.js.map +1 -0
- package/dist/blocks/preview/PreviewDeliveryRoot.js +23 -0
- package/dist/blocks/preview/PreviewDeliveryRoot.js.map +1 -0
- package/dist/components/Assembly.js +13 -0
- package/dist/components/Assembly.js.map +1 -0
- package/dist/components/ErrorBoundary.js +37 -0
- package/dist/components/ErrorBoundary.js.map +1 -0
- package/dist/constants.js +5 -0
- package/dist/constants.js.map +1 -0
- package/dist/core/componentRegistry.js +291 -0
- package/dist/core/componentRegistry.js.map +1 -0
- package/dist/core/preview/assemblyUtils.js +71 -0
- package/dist/core/preview/assemblyUtils.js.map +1 -0
- package/dist/core/sdkFeatures.js +7 -0
- package/dist/core/sdkFeatures.js.map +1 -0
- package/dist/hooks/useBreakpoints.js +40 -0
- package/dist/hooks/useBreakpoints.js.map +1 -0
- package/dist/hooks/useClassName.js +42 -0
- package/dist/hooks/useClassName.js.map +1 -0
- package/dist/hooks/useDetectEditorMode.js +60 -0
- package/dist/hooks/useDetectEditorMode.js.map +1 -0
- package/dist/hooks/useFetchByBase.js +38 -0
- package/dist/hooks/useFetchByBase.js.map +1 -0
- package/dist/hooks/useFetchById.js +16 -0
- package/dist/hooks/useFetchById.js.map +1 -0
- package/dist/hooks/useFetchBySlug.js +16 -0
- package/dist/hooks/useFetchBySlug.js.map +1 -0
- package/dist/hooks/useInitializeVisualEditor.js +56 -0
- package/dist/hooks/useInitializeVisualEditor.js.map +1 -0
- package/dist/index.d.ts +1 -1
- package/dist/index.js +6 -5166
- package/dist/index.js.map +1 -1
- package/dist/sdkVersion.js +4 -0
- package/dist/sdkVersion.js.map +1 -0
- package/dist/src/ExperienceRoot.d.ts +1 -1
- package/dist/src/sdkVersion.d.ts +1 -1
- package/dist/styles/ErrorBoundary.css.js +7 -0
- package/dist/styles/ErrorBoundary.css.js.map +1 -0
- package/dist/utils/withComponentWrapper.js +36 -0
- package/dist/utils/withComponentWrapper.js.map +1 -0
- package/package.json +7 -5
- package/dist/VisualEditorInjectScript-6a92528d.js.map +0 -1
- package/dist/VisualEditorLoader-3839b3a6.js.map +0 -1
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useFetchByBase.js","sources":["../../../src/hooks/useFetchByBase.ts"],"sourcesContent":["'use client';\nimport { useEffect, useState } from 'react';\nimport { EntityStore } from '@contentful/experiences-core';\nimport type { Experience } from '@contentful/experiences-core/types';\n\nexport const useFetchByBase = (\n fetchMethod: () => Promise<Experience<EntityStore> | undefined>,\n isEditorMode: boolean,\n) => {\n const [experience, setExperience] = useState<Experience<EntityStore>>();\n const [isLoading, setIsLoading] = useState(false);\n const [error, setError] = useState<Error>();\n\n useEffect(() => {\n (async () => {\n // if we are in editor mode, we don't want to fetch the experience here\n // it is passed via postMessage instead\n if (isEditorMode) {\n return;\n }\n setIsLoading(true);\n setError(undefined);\n try {\n const exp = await fetchMethod();\n setExperience(exp);\n } catch (error) {\n setError(error as Error);\n } finally {\n setIsLoading(false);\n }\n })();\n }, [fetchMethod, isEditorMode]);\n\n return {\n error,\n experience,\n isLoading,\n isEditorMode,\n };\n};\n"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAsBM;AACE;;;;;;;;;;AAQN;;;;;;;AAQF;;"}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { useCallback } from 'react';
|
|
2
|
+
import { useFetchByBase } from './useFetchByBase.js';
|
|
3
|
+
import { fetchById } from '@contentful/experiences-core';
|
|
4
|
+
import { useDetectEditorMode } from './useDetectEditorMode.js';
|
|
5
|
+
|
|
6
|
+
const useFetchById = ({ id, localeCode, client, experienceTypeId, hyperlinkPattern, }) => {
|
|
7
|
+
const isEditorMode = useDetectEditorMode({ isClientSide: typeof window !== 'undefined' });
|
|
8
|
+
const fetchMethod = useCallback(() => {
|
|
9
|
+
return fetchById({ id, localeCode, client, experienceTypeId });
|
|
10
|
+
}, [id, localeCode, client, experienceTypeId]);
|
|
11
|
+
const fetchResult = useFetchByBase(fetchMethod, isEditorMode);
|
|
12
|
+
return { ...fetchResult, experience: { ...fetchResult.experience, hyperlinkPattern } };
|
|
13
|
+
};
|
|
14
|
+
|
|
15
|
+
export { useFetchById };
|
|
16
|
+
//# sourceMappingURL=useFetchById.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useFetchById.js","sources":["../../../src/hooks/useFetchById.ts"],"sourcesContent":["import { useCallback } from 'react';\nimport type { ContentfulClientApi } from 'contentful';\nimport { useFetchByBase } from './useFetchByBase';\nimport { fetchById } from '@contentful/experiences-core';\nimport { useDetectEditorMode } from './useDetectEditorMode';\n\nexport type UseFetchByIdArgs = {\n client: ContentfulClientApi<undefined>;\n id: string;\n experienceTypeId: string;\n localeCode: string;\n hyperlinkPattern?: string;\n};\n\nexport const useFetchById = ({\n id,\n localeCode,\n client,\n experienceTypeId,\n hyperlinkPattern,\n}: UseFetchByIdArgs) => {\n const isEditorMode = useDetectEditorMode({ isClientSide: typeof window !== 'undefined' });\n\n const fetchMethod = useCallback(() => {\n return fetchById({ id, localeCode, client, experienceTypeId });\n }, [id, localeCode, client, experienceTypeId]);\n\n const fetchResult = useFetchByBase(fetchMethod, isEditorMode);\n\n return { ...fetchResult, experience: { ...fetchResult.experience, hyperlinkPattern } };\n};\n"],"names":[],"mappings":";;;;;AAca,MAAA,YAAY,GAAG,CAAC,EAC3B,EAAE,EACF,UAAU,EACV,MAAM,EACN,gBAAgB,EAChB,gBAAgB,GACC,KAAI;AACrB,IAAA,MAAM,YAAY,GAAG,mBAAmB,CAAC,EAAE,YAAY,EAAE,OAAO,MAAM,KAAK,WAAW,EAAE,CAAC,CAAC;AAE1F,IAAA,MAAM,WAAW,GAAG,WAAW,CAAC,MAAK;AACnC,QAAA,OAAO,SAAS,CAAC,EAAE,EAAE,EAAE,UAAU,EAAE,MAAM,EAAE,gBAAgB,EAAE,CAAC,CAAC;KAChE,EAAE,CAAC,EAAE,EAAE,UAAU,EAAE,MAAM,EAAE,gBAAgB,CAAC,CAAC,CAAC;IAE/C,MAAM,WAAW,GAAG,cAAc,CAAC,WAAW,EAAE,YAAY,CAAC,CAAC;AAE9D,IAAA,OAAO,EAAE,GAAG,WAAW,EAAE,UAAU,EAAE,EAAE,GAAG,WAAW,CAAC,UAAU,EAAE,gBAAgB,EAAE,EAAE,CAAC;AACzF;;;;"}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { useCallback } from 'react';
|
|
2
|
+
import { useFetchByBase } from './useFetchByBase.js';
|
|
3
|
+
import { fetchBySlug } from '@contentful/experiences-core';
|
|
4
|
+
import { useDetectEditorMode } from './useDetectEditorMode.js';
|
|
5
|
+
|
|
6
|
+
const useFetchBySlug = ({ slug, localeCode, client, experienceTypeId, hyperlinkPattern, }) => {
|
|
7
|
+
const isEditorMode = useDetectEditorMode({ isClientSide: typeof window !== 'undefined' });
|
|
8
|
+
const fetchMethod = useCallback(() => {
|
|
9
|
+
return fetchBySlug({ slug, localeCode, client, experienceTypeId });
|
|
10
|
+
}, [slug, localeCode, client, experienceTypeId]);
|
|
11
|
+
const fetchResult = useFetchByBase(fetchMethod, isEditorMode);
|
|
12
|
+
return { ...fetchResult, experience: { ...fetchResult.experience, hyperlinkPattern } };
|
|
13
|
+
};
|
|
14
|
+
|
|
15
|
+
export { useFetchBySlug };
|
|
16
|
+
//# sourceMappingURL=useFetchBySlug.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useFetchBySlug.js","sources":["../../../src/hooks/useFetchBySlug.ts"],"sourcesContent":["import { useCallback } from 'react';\nimport type { ContentfulClientApi } from 'contentful';\nimport { useFetchByBase } from './useFetchByBase';\nimport { fetchBySlug } from '@contentful/experiences-core';\nimport { useDetectEditorMode } from './useDetectEditorMode';\n\nexport type UseFetchBySlugArgs = {\n client: ContentfulClientApi<undefined>;\n slug: string;\n experienceTypeId: string;\n localeCode: string;\n /** The pattern being used to generate links for hyperlink properties **/\n hyperlinkPattern?: string;\n};\n\nexport const useFetchBySlug = ({\n slug,\n localeCode,\n client,\n experienceTypeId,\n hyperlinkPattern,\n}: UseFetchBySlugArgs) => {\n const isEditorMode = useDetectEditorMode({ isClientSide: typeof window !== 'undefined' });\n\n const fetchMethod = useCallback(() => {\n return fetchBySlug({ slug, localeCode, client, experienceTypeId });\n }, [slug, localeCode, client, experienceTypeId]);\n\n const fetchResult = useFetchByBase(fetchMethod, isEditorMode);\n\n return { ...fetchResult, experience: { ...fetchResult.experience, hyperlinkPattern } };\n};\n"],"names":[],"mappings":";;;;;AAea,MAAA,cAAc,GAAG,CAAC,EAC7B,IAAI,EACJ,UAAU,EACV,MAAM,EACN,gBAAgB,EAChB,gBAAgB,GACG,KAAI;AACvB,IAAA,MAAM,YAAY,GAAG,mBAAmB,CAAC,EAAE,YAAY,EAAE,OAAO,MAAM,KAAK,WAAW,EAAE,CAAC,CAAC;AAE1F,IAAA,MAAM,WAAW,GAAG,WAAW,CAAC,MAAK;AACnC,QAAA,OAAO,WAAW,CAAC,EAAE,IAAI,EAAE,UAAU,EAAE,MAAM,EAAE,gBAAgB,EAAE,CAAC,CAAC;KACpE,EAAE,CAAC,IAAI,EAAE,UAAU,EAAE,MAAM,EAAE,gBAAgB,CAAC,CAAC,CAAC;IAEjD,MAAM,WAAW,GAAG,cAAc,CAAC,WAAW,EAAE,YAAY,CAAC,CAAC;AAE9D,IAAA,OAAO,EAAE,GAAG,WAAW,EAAE,UAAU,EAAE,EAAE,GAAG,WAAW,CAAC,UAAU,EAAE,gBAAgB,EAAE,EAAE,CAAC;AACzF;;;;"}
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
import { useState, useRef, useEffect } from 'react';
|
|
2
|
+
import { runBreakpointsValidation, designTokensRegistry, breakpointsRegistry } from '@contentful/experiences-core';
|
|
3
|
+
import { runRegisteredComponentValidations, sendConnectedEventWithRegisteredComponents, sendRegisteredComponentsMessage, componentRegistry } from '../core/componentRegistry.js';
|
|
4
|
+
import { INTERNAL_EVENTS, VISUAL_EDITOR_EVENTS } from '@contentful/experiences-core/constants';
|
|
5
|
+
|
|
6
|
+
const useInitializeVisualEditor = (params) => {
|
|
7
|
+
const { initialLocale, initialEntities } = params;
|
|
8
|
+
const [locale, setLocale] = useState(initialLocale);
|
|
9
|
+
const hasConnectEventBeenSent = useRef(false);
|
|
10
|
+
// sends component definitions to the web app
|
|
11
|
+
// InternalEvents.COMPONENTS_REGISTERED is triggered by defineComponents function
|
|
12
|
+
useEffect(() => {
|
|
13
|
+
if (!hasConnectEventBeenSent.current) {
|
|
14
|
+
runRegisteredComponentValidations();
|
|
15
|
+
runBreakpointsValidation();
|
|
16
|
+
// sending CONNECT but with the registered components now
|
|
17
|
+
sendConnectedEventWithRegisteredComponents();
|
|
18
|
+
hasConnectEventBeenSent.current = true;
|
|
19
|
+
}
|
|
20
|
+
const onComponentsRegistered = () => {
|
|
21
|
+
runRegisteredComponentValidations();
|
|
22
|
+
sendRegisteredComponentsMessage();
|
|
23
|
+
};
|
|
24
|
+
if (typeof window !== 'undefined') {
|
|
25
|
+
window.addEventListener(INTERNAL_EVENTS.ComponentsRegistered, onComponentsRegistered);
|
|
26
|
+
}
|
|
27
|
+
return () => {
|
|
28
|
+
if (typeof window !== 'undefined') {
|
|
29
|
+
window.removeEventListener(INTERNAL_EVENTS.ComponentsRegistered, onComponentsRegistered);
|
|
30
|
+
}
|
|
31
|
+
};
|
|
32
|
+
}, []);
|
|
33
|
+
useEffect(() => {
|
|
34
|
+
setLocale(initialLocale);
|
|
35
|
+
}, [initialLocale]);
|
|
36
|
+
useEffect(() => {
|
|
37
|
+
const onVisualEditorReady = () => {
|
|
38
|
+
window.dispatchEvent(new CustomEvent(INTERNAL_EVENTS.VisualEditorInitialize, {
|
|
39
|
+
detail: {
|
|
40
|
+
componentRegistry,
|
|
41
|
+
designTokens: designTokensRegistry,
|
|
42
|
+
breakpoints: breakpointsRegistry,
|
|
43
|
+
locale,
|
|
44
|
+
entities: initialEntities ?? [],
|
|
45
|
+
},
|
|
46
|
+
}));
|
|
47
|
+
};
|
|
48
|
+
window.addEventListener(VISUAL_EDITOR_EVENTS.Ready, onVisualEditorReady);
|
|
49
|
+
return () => {
|
|
50
|
+
window.removeEventListener(VISUAL_EDITOR_EVENTS.Ready, onVisualEditorReady);
|
|
51
|
+
};
|
|
52
|
+
}, [locale, initialEntities]);
|
|
53
|
+
};
|
|
54
|
+
|
|
55
|
+
export { useInitializeVisualEditor };
|
|
56
|
+
//# sourceMappingURL=useInitializeVisualEditor.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useInitializeVisualEditor.js","sources":["../../../src/hooks/useInitializeVisualEditor.ts"],"sourcesContent":["import { useEffect, useRef, useState } from 'react';\nimport { EntityStore, breakpointsRegistry } from '@contentful/experiences-core';\nimport {\n componentRegistry,\n sendConnectedEventWithRegisteredComponents,\n sendRegisteredComponentsMessage,\n runRegisteredComponentValidations,\n} from '../core/componentRegistry';\nimport { INTERNAL_EVENTS, VISUAL_EDITOR_EVENTS } from '@contentful/experiences-core/constants';\nimport { designTokensRegistry, runBreakpointsValidation } from '@contentful/experiences-core';\n\ntype InitializeVisualEditorParams = {\n initialLocale: string;\n initialEntities?: EntityStore['entities'];\n};\n\nexport const useInitializeVisualEditor = (params: InitializeVisualEditorParams) => {\n const { initialLocale, initialEntities } = params;\n const [locale, setLocale] = useState<string>(initialLocale);\n const hasConnectEventBeenSent = useRef(false);\n\n // sends component definitions to the web app\n // InternalEvents.COMPONENTS_REGISTERED is triggered by defineComponents function\n useEffect(() => {\n if (!hasConnectEventBeenSent.current) {\n runRegisteredComponentValidations();\n runBreakpointsValidation();\n // sending CONNECT but with the registered components now\n sendConnectedEventWithRegisteredComponents();\n hasConnectEventBeenSent.current = true;\n }\n\n const onComponentsRegistered = () => {\n runRegisteredComponentValidations();\n sendRegisteredComponentsMessage();\n };\n\n if (typeof window !== 'undefined') {\n window.addEventListener(INTERNAL_EVENTS.ComponentsRegistered, onComponentsRegistered);\n }\n\n return () => {\n if (typeof window !== 'undefined') {\n window.removeEventListener(INTERNAL_EVENTS.ComponentsRegistered, onComponentsRegistered);\n }\n };\n }, []);\n\n useEffect(() => {\n setLocale(initialLocale);\n }, [initialLocale]);\n\n useEffect(() => {\n const onVisualEditorReady = () => {\n window.dispatchEvent(\n new CustomEvent(INTERNAL_EVENTS.VisualEditorInitialize, {\n detail: {\n componentRegistry,\n designTokens: designTokensRegistry,\n breakpoints: breakpointsRegistry,\n locale,\n entities: initialEntities ?? [],\n },\n }),\n );\n };\n\n window.addEventListener(VISUAL_EDITOR_EVENTS.Ready, onVisualEditorReady);\n return () => {\n window.removeEventListener(VISUAL_EDITOR_EVENTS.Ready, onVisualEditorReady);\n };\n }, [locale, initialEntities]);\n};\n"],"names":[],"mappings":";;;;;AAgBa,MAAA,yBAAyB,GAAG,CAAC,MAAoC,KAAI;AAChF,IAAA,MAAM,EAAE,aAAa,EAAE,eAAe,EAAE,GAAG,MAAM,CAAC;IAClD,MAAM,CAAC,MAAM,EAAE,SAAS,CAAC,GAAG,QAAQ,CAAS,aAAa,CAAC,CAAC;AAC5D,IAAA,MAAM,uBAAuB,GAAG,MAAM,CAAC,KAAK,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C;AACzE,QAAA,OAAO,MAAK;YACV,MAAM,CAAC,mBAAmB,CAAC,oBAAoB,CAAC,KAAK,EAAE,mBAAmB,CAAC,CAAC;AAC9E,SAAC,CAAC;AACJ,KAAC,EAAE,CAAC,MAAM,EAAE,eAAe,CAAC,CAAC,CAAC;AAChC;;;;"}
|
package/dist/index.d.ts
CHANGED
|
@@ -8,7 +8,7 @@ import { ContentfulClientApi } from 'contentful';
|
|
|
8
8
|
export { CF_STYLE_ATTRIBUTES, CONTENTFUL_COMPONENTS, LATEST_SCHEMA_VERSION } from '@contentful/experiences-core/constants';
|
|
9
9
|
|
|
10
10
|
type ExperienceRootProps = {
|
|
11
|
-
experience?: Experience<EntityStore
|
|
11
|
+
experience?: Experience<EntityStore> | string | null;
|
|
12
12
|
locale: string;
|
|
13
13
|
visualEditorMode?: VisualEditorMode;
|
|
14
14
|
};
|