@contentful/experiences-core 3.3.0-dev-20250820T0950-c569ea0.0 → 3.3.0-dev-20250820T1056-fd92026.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.
@@ -1,5 +1,5 @@
1
1
  import { DataSourceEntryValueType, Link, ExperienceEntry, ExperienceTreeNode } from '../types.js';
2
- import { EntityFromLink } from '../entity/EntityStoreBase.js';
2
+ import { EntityFromLink, EntityStoreBase } from '../entity/EntityStoreBase.js';
3
3
  import { ExperienceDataSource } from '@contentful/experiences-validators';
4
4
 
5
5
  type DeepReferenceOpts = {
@@ -22,6 +22,6 @@ declare class DeepReference {
22
22
  static from(opt: DeepReferenceOpts): DeepReference;
23
23
  }
24
24
  declare function gatherDeepReferencesFromExperienceEntry(experienceEntry: ExperienceEntry): DeepReference[];
25
- declare function gatherDeepReferencesFromTree(startingNode: ExperienceTreeNode, dataSource: ExperienceDataSource): DeepReference[];
25
+ declare function gatherDeepReferencesFromTree(startingNode: ExperienceTreeNode, dataSource: ExperienceDataSource, getEntityFromLink: EntityStoreBase['getEntityFromLink']): DeepReference[];
26
26
 
27
27
  export { DeepReference, gatherDeepReferencesFromExperienceEntry, gatherDeepReferencesFromTree };
package/dist/index.d.ts CHANGED
@@ -6,7 +6,7 @@ export { isLinkToAsset } from './utils/isLinkToAsset.js';
6
6
  export { isLinkToEntry } from './utils/isLinkToEntry.js';
7
7
  export { isLink } from './utils/isLink.js';
8
8
  export { localizeEntity } from './utils/localizeEntity.js';
9
- export { Fieldset, UnresolvedFieldset, isDeepPath, lastPathNamedSegmentEq, parseDataSourcePathIntoFieldset, parseDataSourcePathWithL1DeepBindings } from './utils/pathSchema.js';
9
+ export { Fieldset, PreboundVariable, UnresolvedFieldset, getPrebindingPathBySourceEntry, isDeepPath, isDeepPrebinding, isPreboundProp, lastPathNamedSegmentEq, parseDataSourcePathIntoFieldset, parseDataSourcePathWithL1DeepBindings } from './utils/pathSchema.js';
10
10
  export { addLocale, buildTemplate, getTemplateValue, resolveHyperlinkPattern } from './utils/resolveHyperlinkPattern.js';
11
11
  export { sanitizeNodeProps } from './utils/sanitizeNodeProps.js';
12
12
  export { addMinHeightForEmptyStructures, buildCfStyles, buildStyleTag, calculateNodeDefaultHeight, stringifyCssProperties, toCSSAttribute } from './utils/styleUtils/stylesUtils.js';
package/dist/index.js CHANGED
@@ -1756,6 +1756,11 @@ function localizeEntity(entity, locale) {
1756
1756
  /**
1757
1757
  * This module encapsulates format of the path to a deep reference.
1758
1758
  */
1759
+ const isPreboundProp = (variable) => {
1760
+ return (variable.type === 'BoundValue' &&
1761
+ typeof variable.isPrebound === 'boolean' &&
1762
+ !!variable.pathsByContentType);
1763
+ };
1759
1764
  const parseDataSourcePathIntoFieldset = (path) => {
1760
1765
  const parsedPath = parseDeepPath(path);
1761
1766
  if (null === parsedPath) {
@@ -1794,6 +1799,35 @@ const isDeepPath = (deepPathCandidate) => {
1794
1799
  }
1795
1800
  return deepPathParsed.fields.length > 1;
1796
1801
  };
1802
+ const isDeepPrebinding = (boundValueProperty) => {
1803
+ if (!boundValueProperty?.path || boundValueProperty.type !== 'BoundValue') {
1804
+ return false;
1805
+ }
1806
+ if (!isPreboundProp(boundValueProperty)) {
1807
+ return false;
1808
+ }
1809
+ if (isDeepPath(boundValueProperty.path)) {
1810
+ return true;
1811
+ }
1812
+ const hasDeepPathByContentType = Object.values(boundValueProperty.pathsByContentType || {}).some((val) => isDeepPath(val.path));
1813
+ return hasDeepPathByContentType;
1814
+ };
1815
+ const getPrebindingPathBySourceEntry = (preboundValueProperty, getHeadEntityByDataSourceKey) => {
1816
+ if (!isPreboundProp(preboundValueProperty)) {
1817
+ return undefined;
1818
+ }
1819
+ // incomplete path due to several content types and not known default source
1820
+ const [, dataSourceKey] = preboundValueProperty.path.split('/');
1821
+ if (!dataSourceKey) {
1822
+ return undefined;
1823
+ }
1824
+ const headEntity = getHeadEntityByDataSourceKey(dataSourceKey);
1825
+ if (headEntity?.sys.type !== 'Entry') {
1826
+ return undefined;
1827
+ }
1828
+ const contentTypeId = headEntity.sys.contentType.sys.id;
1829
+ return preboundValueProperty.pathsByContentType?.[contentTypeId]?.path;
1830
+ };
1797
1831
  const parseDeepPath = (deepPathCandidate) => {
1798
1832
  // ALGORITHM:
1799
1833
  // We start with deep path in form:
@@ -4231,7 +4265,7 @@ function gatherDeepReferencesFromExperienceEntry(experienceEntry) {
4231
4265
  });
4232
4266
  return deepReferences;
4233
4267
  }
4234
- function gatherDeepReferencesFromTree(startingNode, dataSource) {
4268
+ function gatherDeepReferencesFromTree(startingNode, dataSource, getEntityFromLink) {
4235
4269
  const deepReferences = [];
4236
4270
  treeVisit(startingNode, (node) => {
4237
4271
  if (!node.data.props)
@@ -4239,12 +4273,27 @@ function gatherDeepReferencesFromTree(startingNode, dataSource) {
4239
4273
  for (const [, variableMapping] of Object.entries(node.data.props)) {
4240
4274
  if (variableMapping.type !== 'BoundValue')
4241
4275
  continue;
4242
- if (!isDeepPath(variableMapping.path))
4243
- continue;
4244
- deepReferences.push(DeepReference.from({
4245
- path: variableMapping.path,
4246
- dataSource,
4247
- }));
4276
+ if (isDeepPath(variableMapping.path)) {
4277
+ deepReferences.push(DeepReference.from({
4278
+ path: variableMapping.path,
4279
+ dataSource,
4280
+ }));
4281
+ }
4282
+ else if (isPreboundProp(variableMapping) && isDeepPrebinding(variableMapping)) {
4283
+ const getEntityByDataSourceKey = (dataSourceKey) => {
4284
+ const entityLink = dataSource[dataSourceKey];
4285
+ if (!entityLink)
4286
+ return undefined;
4287
+ return getEntityFromLink(entityLink);
4288
+ };
4289
+ const deepPrebindingPath = getPrebindingPathBySourceEntry(variableMapping, getEntityByDataSourceKey);
4290
+ if (!deepPrebindingPath)
4291
+ continue;
4292
+ deepReferences.push(DeepReference.from({
4293
+ path: deepPrebindingPath,
4294
+ dataSource,
4295
+ }));
4296
+ }
4248
4297
  }
4249
4298
  });
4250
4299
  return deepReferences;
@@ -4725,5 +4774,5 @@ async function fetchById({ client, experienceTypeId, id, localeCode, isEditorMod
4725
4774
  }
4726
4775
  }
4727
4776
 
4728
- export { BREAKPOINTS_STRATEGY_DESKTOP_FIRST, BREAKPOINTS_STRATEGY_MOBILE_FIRST, DebugLogger, DeepReference, EditorModeEntityStore, EntityStore, EntityStoreBase, MEDIA_QUERY_REGEXP, VisualEditorMode, addLocale, addMinHeightForEmptyStructures, breakpointsRegistry, buildCfStyles, buildStyleTag, buildTemplate, builtInStyles, calculateNodeDefaultHeight, checkIsAssemblyDefinition, checkIsAssemblyEntry, checkIsAssemblyNode, columnsBuiltInStyles, containerBuiltInStyles, createExperience, debug, defineBreakpoints, defineDesignTokens, designTokensRegistry, detachExperienceStyles, detectBreakpointsStrategy, disableDebug, dividerBuiltInStyles, doesMismatchMessageSchema, enableDebug, extractLeafLinksReferencedFromExperience, extractReferencesFromEntries, extractReferencesFromEntriesAsIds, fetchAllAssets, fetchAllEntries, fetchById, fetchBySlug, fetchExperienceEntry, fetchReferencedEntities, findOutermostCoordinates, flattenDesignTokenRegistry, gatherDeepReferencesFromExperienceEntry, gatherDeepReferencesFromTree, generateRandomId, getActiveBreakpointIndex, getBreakpointRegistration, getDataFromTree, getDesignTokenRegistration, getElementCoordinates, getFallbackBreakpointIndex, getTargetValueInPixels, getTemplateValue, getValueForBreakpoint, inMemoryEntities, inMemoryEntitiesStore, indexByBreakpoint, isArrayOfLinks, isAsset, isCfStyleAttribute, isComponentAllowedOnRoot, isContentfulComponent, isContentfulStructureComponent, isDeepPath, isElementHidden, isEntry, isExperienceEntry, isLink, isLinkToAsset, isLinkToEntry, isPatternComponent, isPatternEntry, isStructureWithRelativeHeight, isValidBreakpointValue, lastPathNamedSegmentEq, localizeEntity, maybePopulateDesignTokenValue, mediaQueryMatcher, mergeDesignValuesByBreakpoint, optionalBuiltInStyles, parseCSSValue, parseDataSourcePathIntoFieldset, parseDataSourcePathWithL1DeepBindings, referencesOf, resetBreakpointsRegistry, resetDesignTokenRegistry, resolveBackgroundImageBinding, resolveHyperlinkPattern, runBreakpointsValidation, sanitizeNodeProps, sectionBuiltInStyles, sendMessage, singleColumnBuiltInStyles, stringifyCssProperties, toCSSAttribute, toMediaQuery, transformBoundContentValue, transformVisibility, treeMap, treeVisit, tryParseMessage, uniqueById, useInMemoryEntities, validateExperienceBuilderConfig };
4777
+ export { BREAKPOINTS_STRATEGY_DESKTOP_FIRST, BREAKPOINTS_STRATEGY_MOBILE_FIRST, DebugLogger, DeepReference, EditorModeEntityStore, EntityStore, EntityStoreBase, MEDIA_QUERY_REGEXP, VisualEditorMode, addLocale, addMinHeightForEmptyStructures, breakpointsRegistry, buildCfStyles, buildStyleTag, buildTemplate, builtInStyles, calculateNodeDefaultHeight, checkIsAssemblyDefinition, checkIsAssemblyEntry, checkIsAssemblyNode, columnsBuiltInStyles, containerBuiltInStyles, createExperience, debug, defineBreakpoints, defineDesignTokens, designTokensRegistry, detachExperienceStyles, detectBreakpointsStrategy, disableDebug, dividerBuiltInStyles, doesMismatchMessageSchema, enableDebug, extractLeafLinksReferencedFromExperience, extractReferencesFromEntries, extractReferencesFromEntriesAsIds, fetchAllAssets, fetchAllEntries, fetchById, fetchBySlug, fetchExperienceEntry, fetchReferencedEntities, findOutermostCoordinates, flattenDesignTokenRegistry, gatherDeepReferencesFromExperienceEntry, gatherDeepReferencesFromTree, generateRandomId, getActiveBreakpointIndex, getBreakpointRegistration, getDataFromTree, getDesignTokenRegistration, getElementCoordinates, getFallbackBreakpointIndex, getPrebindingPathBySourceEntry, getTargetValueInPixels, getTemplateValue, getValueForBreakpoint, inMemoryEntities, inMemoryEntitiesStore, indexByBreakpoint, isArrayOfLinks, isAsset, isCfStyleAttribute, isComponentAllowedOnRoot, isContentfulComponent, isContentfulStructureComponent, isDeepPath, isDeepPrebinding, isElementHidden, isEntry, isExperienceEntry, isLink, isLinkToAsset, isLinkToEntry, isPatternComponent, isPatternEntry, isPreboundProp, isStructureWithRelativeHeight, isValidBreakpointValue, lastPathNamedSegmentEq, localizeEntity, maybePopulateDesignTokenValue, mediaQueryMatcher, mergeDesignValuesByBreakpoint, optionalBuiltInStyles, parseCSSValue, parseDataSourcePathIntoFieldset, parseDataSourcePathWithL1DeepBindings, referencesOf, resetBreakpointsRegistry, resetDesignTokenRegistry, resolveBackgroundImageBinding, resolveHyperlinkPattern, runBreakpointsValidation, sanitizeNodeProps, sectionBuiltInStyles, sendMessage, singleColumnBuiltInStyles, stringifyCssProperties, toCSSAttribute, toMediaQuery, transformBoundContentValue, transformVisibility, treeMap, treeVisit, tryParseMessage, uniqueById, useInMemoryEntities, validateExperienceBuilderConfig };
4729
4778
  //# sourceMappingURL=index.js.map