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