@contentful/experiences-core 1.27.0-dev-20241212T1234-a8135ee.0 → 1.27.0-prerelease-20241213T0010-0475c78.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.js CHANGED
@@ -2024,21 +2024,31 @@ const transformRichText = (entryOrAsset, entityStore, path) => {
2024
2024
  };
2025
2025
  }
2026
2026
  if (typeof value === 'object' && value.nodeType === BLOCKS.DOCUMENT) {
2027
- //resolve any embedded links - we currently only support resolving embedded in the first entry
2027
+ // resolve any links to assets/entries/hyperlinks
2028
2028
  const richTextDocument = value;
2029
- richTextDocument.content.forEach((node) => {
2030
- if ((node.nodeType === BLOCKS.EMBEDDED_ENTRY || node.nodeType === BLOCKS.EMBEDDED_ASSET) &&
2031
- node.data.target.sys.type === 'Link') {
2032
- const entity = entityStore.getEntityFromLink(node.data.target);
2033
- if (entity) {
2034
- node.data.target = entity;
2035
- }
2036
- }
2037
- });
2038
- return value;
2029
+ resolveLinks(richTextDocument, entityStore);
2030
+ return richTextDocument;
2039
2031
  }
2040
2032
  return undefined;
2041
2033
  };
2034
+ const isLinkTarget = (node) => {
2035
+ return node?.data?.target?.sys?.type === 'Link';
2036
+ };
2037
+ const resolveLinks = (node, entityStore) => {
2038
+ if (!node)
2039
+ return;
2040
+ // Resolve link if current node has one
2041
+ if (isLinkTarget(node)) {
2042
+ const entity = entityStore.getEntityFromLink(node.data.target);
2043
+ if (entity) {
2044
+ node.data.target = entity;
2045
+ }
2046
+ }
2047
+ // Process content array if it exists
2048
+ if ('content' in node && Array.isArray(node.content)) {
2049
+ node.content.forEach((childNode) => resolveLinks(childNode, entityStore));
2050
+ }
2051
+ };
2042
2052
 
2043
2053
  function getOptimizedImageUrl(url, width, quality, format) {
2044
2054
  if (url.startsWith('//')) {