@contentful/experiences-sdk-react 0.0.1-alpha.9 → 0.0.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/index.d.ts
CHANGED
|
@@ -47,5 +47,13 @@ declare const useFetchBySlug: ({ slug, localeCode, client, experienceTypeId, }:
|
|
|
47
47
|
* @returns void
|
|
48
48
|
*/
|
|
49
49
|
declare const defineComponents: (componentRegistrations: ComponentRegistration[], options?: ComponentRegistrationOptions) => void;
|
|
50
|
+
/**
|
|
51
|
+
* @deprecated This method is used to maintain the basic component ids (without the prefix 'contentful-') in order to be compatible
|
|
52
|
+
* with experiences created with an older alpha version of the SDK. Components in these experiences should be migrated to use
|
|
53
|
+
* the components with the 'contentful-' prefix. To do so, load the experience in the editor, and replace any older basic components
|
|
54
|
+
* (marked with [OLD] in the UI) with the new components (without the [OLD]). This method (and functionality for the older components)
|
|
55
|
+
* will be removed in the next major release.
|
|
56
|
+
*/
|
|
57
|
+
declare const maintainBasicComponentIdsWithoutPrefix: () => void;
|
|
50
58
|
|
|
51
|
-
export { ExperienceRoot, defineComponents, useFetchById, useFetchBySlug };
|
|
59
|
+
export { ExperienceRoot, defineComponents, maintainBasicComponentIdsWithoutPrefix, useFetchById, useFetchBySlug };
|
package/dist/index.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { jsx, Fragment, jsxs } from 'react/jsx-runtime';
|
|
2
2
|
import { containerDefinition, sectionDefinition, columnsDefinition, singleColumnDefinition, builtInStyles, optionalBuiltInStyles, sendMessage, designTokensRegistry, buildStyleTag, checkIsAssemblyNode, 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
|
-
import React, { useState, useEffect,
|
|
4
|
+
import React, { useMemo, useLayoutEffect, useState, useEffect, useCallback, useRef, Suspense } from 'react';
|
|
5
5
|
import { omit } from 'lodash-es';
|
|
6
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';
|
|
7
7
|
export { CF_STYLE_ATTRIBUTES, CONTENTFUL_COMPONENTS, LATEST_SCHEMA_VERSION } from '@contentful/experiences-core/constants';
|
|
@@ -9,7 +9,7 @@ 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 = '0.0.1-alpha.
|
|
12
|
+
const SDK_VERSION = '0.0.1-alpha.13';
|
|
13
13
|
|
|
14
14
|
var util;
|
|
15
15
|
(function (util) {
|
|
@@ -4487,7 +4487,7 @@ const optionalBuiltInComponents = [
|
|
|
4487
4487
|
];
|
|
4488
4488
|
const sendRegisteredComponentsMessage = () => {
|
|
4489
4489
|
// Send the definitions (without components) via the connection message to the experience builder
|
|
4490
|
-
const registeredDefinitions = Array.from(componentRegistry.values());
|
|
4490
|
+
const registeredDefinitions = Array.from(componentRegistry.values()).map(({ definition }) => definition);
|
|
4491
4491
|
sendMessage(OUTGOING_EVENTS.RegisteredComponents, {
|
|
4492
4492
|
definitions: registeredDefinitions,
|
|
4493
4493
|
});
|
|
@@ -4552,6 +4552,27 @@ const createAssemblyRegistration = ({ definitionId, definitionName, component, }
|
|
|
4552
4552
|
addComponentRegistration({ component, definition });
|
|
4553
4553
|
return componentRegistry.get(definitionId);
|
|
4554
4554
|
};
|
|
4555
|
+
/**
|
|
4556
|
+
* @deprecated This method is used to maintain the basic component ids (without the prefix 'contentful-') in order to be compatible
|
|
4557
|
+
* with experiences created with an older alpha version of the SDK. Components in these experiences should be migrated to use
|
|
4558
|
+
* the components with the 'contentful-' prefix. To do so, load the experience in the editor, and replace any older basic components
|
|
4559
|
+
* (marked with [OLD] in the UI) with the new components (without the [OLD]). This method (and functionality for the older components)
|
|
4560
|
+
* will be removed in the next major release.
|
|
4561
|
+
*/
|
|
4562
|
+
const maintainBasicComponentIdsWithoutPrefix = () => {
|
|
4563
|
+
optionalBuiltInComponents.forEach((id) => {
|
|
4564
|
+
if (componentRegistry.has(id) && id.startsWith('contentful-')) {
|
|
4565
|
+
const registeredComponent = componentRegistry.get(id);
|
|
4566
|
+
const definition = registeredComponent.definition;
|
|
4567
|
+
const newDefinition = cloneObject(definition);
|
|
4568
|
+
newDefinition.name = newDefinition.name + '[OLD]';
|
|
4569
|
+
const newId = id.replace('contentful-', '');
|
|
4570
|
+
newDefinition.id = newId;
|
|
4571
|
+
const newRegisteredComponent = { ...registeredComponent, definition: newDefinition };
|
|
4572
|
+
componentRegistry.set(newId, newRegisteredComponent);
|
|
4573
|
+
}
|
|
4574
|
+
});
|
|
4575
|
+
};
|
|
4555
4576
|
|
|
4556
4577
|
/**
|
|
4557
4578
|
*
|
|
@@ -4563,13 +4584,17 @@ const createAssemblyRegistration = ({ definitionId, definitionName, component, }
|
|
|
4563
4584
|
* In preview/delivery mode the styles don't change oftem so we're using the md5 hash of the content of the tag
|
|
4564
4585
|
*/
|
|
4565
4586
|
const useStyleTag = ({ styles, nodeId }) => {
|
|
4566
|
-
const [className,
|
|
4567
|
-
useEffect(() => {
|
|
4587
|
+
const [className, styleRule] = useMemo(() => {
|
|
4568
4588
|
if (Object.keys(styles).length === 0) {
|
|
4589
|
+
return [''];
|
|
4590
|
+
}
|
|
4591
|
+
return buildStyleTag({ styles, nodeId });
|
|
4592
|
+
}, [styles, nodeId]);
|
|
4593
|
+
// Once our React support allows it (>=18), this should be implemented with useInsertionEffect.
|
|
4594
|
+
useLayoutEffect(() => {
|
|
4595
|
+
if (!className || !styleRule) {
|
|
4569
4596
|
return;
|
|
4570
4597
|
}
|
|
4571
|
-
const [className, styleRule] = buildStyleTag({ styles, nodeId });
|
|
4572
|
-
setClassName(className);
|
|
4573
4598
|
const existingTag = document.querySelector(`[data-cf-styles="${className}"]`);
|
|
4574
4599
|
if (existingTag) {
|
|
4575
4600
|
// editor mode - update existing
|
|
@@ -4583,7 +4608,7 @@ const useStyleTag = ({ styles, nodeId }) => {
|
|
|
4583
4608
|
const styleTag = document.createElement('style');
|
|
4584
4609
|
styleTag.dataset['cfStyles'] = className;
|
|
4585
4610
|
document.head.appendChild(styleTag).innerHTML = styleRule;
|
|
4586
|
-
}, [
|
|
4611
|
+
}, [className, nodeId, styleRule]);
|
|
4587
4612
|
return { className };
|
|
4588
4613
|
};
|
|
4589
4614
|
|
|
@@ -4737,7 +4762,7 @@ const CompositionBlock = ({ node: rawNode, locale, entityStore, resolveDesignVal
|
|
|
4737
4762
|
return React.createElement(component, {
|
|
4738
4763
|
...omit(nodeProps, stylesToRemove, ['cfHyperlink', 'cfOpenInNewTab']),
|
|
4739
4764
|
className,
|
|
4740
|
-
}, children);
|
|
4765
|
+
}, children ?? (typeof nodeProps.children === 'string' ? nodeProps.children : null));
|
|
4741
4766
|
};
|
|
4742
4767
|
|
|
4743
4768
|
// TODO: In order to support integrations without React, we should extract this heavy logic into simple
|
|
@@ -5010,5 +5035,5 @@ if (typeof window !== 'undefined') {
|
|
|
5010
5035
|
};
|
|
5011
5036
|
}
|
|
5012
5037
|
|
|
5013
|
-
export { ExperienceRoot, defineComponents, useFetchById, useFetchBySlug };
|
|
5038
|
+
export { ExperienceRoot, defineComponents, maintainBasicComponentIdsWithoutPrefix, useFetchById, useFetchBySlug };
|
|
5014
5039
|
//# sourceMappingURL=index.js.map
|