@contentful/experiences-core 1.27.1 → 1.28.0-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.js CHANGED
@@ -1162,9 +1162,12 @@ const BreakpointSchema = z
1162
1162
  const UnboundValuesSchema = z.record(uuidKeySchema, z.object({
1163
1163
  value: PrimitiveValueSchema,
1164
1164
  }));
1165
+ const ComponentTreeNodeIdSchema = z
1166
+ .string()
1167
+ .regex(/^[a-zA-Z0-9]{1,8}$/, { message: 'Does not match /^[a-zA-Z0-9]{1,8}$/' });
1165
1168
  // Use helper schema to define a recursive schema with its type correctly below
1166
1169
  const BaseComponentTreeNodeSchema = z.object({
1167
- id: uuidKeySchema.optional(),
1170
+ id: ComponentTreeNodeIdSchema.optional(),
1168
1171
  definitionId: DefinitionPropertyKeySchema,
1169
1172
  displayName: z.string().optional(),
1170
1173
  slotId: z.string().optional(),
@@ -2024,21 +2027,31 @@ const transformRichText = (entryOrAsset, entityStore, path) => {
2024
2027
  };
2025
2028
  }
2026
2029
  if (typeof value === 'object' && value.nodeType === BLOCKS.DOCUMENT) {
2027
- //resolve any embedded links - we currently only support resolving embedded in the first entry
2030
+ // resolve any links to assets/entries/hyperlinks
2028
2031
  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;
2032
+ resolveLinks(richTextDocument, entityStore);
2033
+ return richTextDocument;
2039
2034
  }
2040
2035
  return undefined;
2041
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
+ };
2042
2055
 
2043
2056
  function getOptimizedImageUrl(url, width, quality, format) {
2044
2057
  if (url.startsWith('//')) {