@contentful/experiences-visual-editor-react 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.
package/dist/renderApp.js CHANGED
@@ -44736,6 +44736,11 @@ const isLink$1 = (maybeLink) => {
44736
44736
  /**
44737
44737
  * This module encapsulates format of the path to a deep reference.
44738
44738
  */
44739
+ const isPreboundProp = (variable) => {
44740
+ return (variable.type === 'BoundValue' &&
44741
+ typeof variable.isPrebound === 'boolean' &&
44742
+ !!variable.pathsByContentType);
44743
+ };
44739
44744
  const parseDataSourcePathIntoFieldset$1 = (path) => {
44740
44745
  const parsedPath = parseDeepPath$1(path);
44741
44746
  if (null === parsedPath) {
@@ -44774,6 +44779,35 @@ const isDeepPath$1 = (deepPathCandidate) => {
44774
44779
  }
44775
44780
  return deepPathParsed.fields.length > 1;
44776
44781
  };
44782
+ const isDeepPrebinding = (boundValueProperty) => {
44783
+ if (!boundValueProperty?.path || boundValueProperty.type !== 'BoundValue') {
44784
+ return false;
44785
+ }
44786
+ if (!isPreboundProp(boundValueProperty)) {
44787
+ return false;
44788
+ }
44789
+ if (isDeepPath$1(boundValueProperty.path)) {
44790
+ return true;
44791
+ }
44792
+ const hasDeepPathByContentType = Object.values(boundValueProperty.pathsByContentType || {}).some((val) => isDeepPath$1(val.path));
44793
+ return hasDeepPathByContentType;
44794
+ };
44795
+ const getPrebindingPathBySourceEntry = (preboundValueProperty, getHeadEntityByDataSourceKey) => {
44796
+ if (!isPreboundProp(preboundValueProperty)) {
44797
+ return undefined;
44798
+ }
44799
+ // incomplete path due to several content types and not known default source
44800
+ const [, dataSourceKey] = preboundValueProperty.path.split('/');
44801
+ if (!dataSourceKey) {
44802
+ return undefined;
44803
+ }
44804
+ const headEntity = getHeadEntityByDataSourceKey(dataSourceKey);
44805
+ if (headEntity?.sys.type !== 'Entry') {
44806
+ return undefined;
44807
+ }
44808
+ const contentTypeId = headEntity.sys.contentType.sys.id;
44809
+ return preboundValueProperty.pathsByContentType?.[contentTypeId]?.path;
44810
+ };
44777
44811
  const parseDeepPath$1 = (deepPathCandidate) => {
44778
44812
  // ALGORITHM:
44779
44813
  // We start with deep path in form:
@@ -46110,7 +46144,7 @@ class DeepReference {
46110
46144
  return new DeepReference(opt);
46111
46145
  }
46112
46146
  }
46113
- function gatherDeepReferencesFromTree(startingNode, dataSource) {
46147
+ function gatherDeepReferencesFromTree(startingNode, dataSource, getEntityFromLink) {
46114
46148
  const deepReferences = [];
46115
46149
  treeVisit(startingNode, (node) => {
46116
46150
  if (!node.data.props)
@@ -46118,12 +46152,27 @@ function gatherDeepReferencesFromTree(startingNode, dataSource) {
46118
46152
  for (const [, variableMapping] of Object.entries(node.data.props)) {
46119
46153
  if (variableMapping.type !== 'BoundValue')
46120
46154
  continue;
46121
- if (!isDeepPath$1(variableMapping.path))
46122
- continue;
46123
- deepReferences.push(DeepReference.from({
46124
- path: variableMapping.path,
46125
- dataSource,
46126
- }));
46155
+ if (isDeepPath$1(variableMapping.path)) {
46156
+ deepReferences.push(DeepReference.from({
46157
+ path: variableMapping.path,
46158
+ dataSource,
46159
+ }));
46160
+ }
46161
+ else if (isPreboundProp(variableMapping) && isDeepPrebinding(variableMapping)) {
46162
+ const getEntityByDataSourceKey = (dataSourceKey) => {
46163
+ const entityLink = dataSource[dataSourceKey];
46164
+ if (!entityLink)
46165
+ return undefined;
46166
+ return getEntityFromLink(entityLink);
46167
+ };
46168
+ const deepPrebindingPath = getPrebindingPathBySourceEntry(variableMapping, getEntityByDataSourceKey);
46169
+ if (!deepPrebindingPath)
46170
+ continue;
46171
+ deepReferences.push(DeepReference.from({
46172
+ path: deepPrebindingPath,
46173
+ dataSource,
46174
+ }));
46175
+ }
46127
46176
  }
46128
46177
  });
46129
46178
  return deepReferences;
@@ -49183,10 +49232,6 @@ const isLink = (maybeLink) => {
49183
49232
  const link = maybeLink;
49184
49233
  return Boolean(link.sys?.id) && link.sys?.type === 'Link' && Boolean(link.sys?.linkType);
49185
49234
  };
49186
-
49187
- /**
49188
- * This module encapsulates format of the path to a deep reference.
49189
- */
49190
49235
  const parseDataSourcePathIntoFieldset = (path) => {
49191
49236
  const parsedPath = parseDeepPath(path);
49192
49237
  if (null === parsedPath) {
@@ -49675,7 +49720,6 @@ function useEditorSubscriber(inMemoryEntitiesStore) {
49675
49720
  ...Object.values(newDataSource),
49676
49721
  ...assembliesRegistry.values(), // we count assemblies here as "L1 entities", for convenience. Even though they're not headEntities.
49677
49722
  ];
49678
- const deepReferences = gatherDeepReferencesFromTree(tree.root, newDataSource);
49679
49723
  /**
49680
49724
  * Checks only for _missing_ L1 entities
49681
49725
  * WARNING: Does NOT check for entity staleness/versions. If an entity is stale, it will NOT be considered missing.
@@ -49717,6 +49761,7 @@ function useEditorSubscriber(inMemoryEntitiesStore) {
49717
49761
  startFetching();
49718
49762
  await fillupL1({ entityLinksL1 });
49719
49763
  }
49764
+ const deepReferences = gatherDeepReferencesFromTree(tree.root, newDataSource, entityStore.getEntityFromLink.bind(entityStore));
49720
49765
  if (isMissingL2Entities(deepReferences)) {
49721
49766
  startFetching();
49722
49767
  await fillupL2({ deepReferences });
@@ -50083,16 +50128,32 @@ const useComponentProps = ({ node, entityStore, areEntitiesFetched, resolveDesig
50083
50128
  };
50084
50129
  }
50085
50130
  else if (variableMapping.type === 'BoundValue') {
50086
- const [, uuid, path] = variableMapping.path.split('/');
50087
- const binding = dataSource[uuid];
50088
- const variableDefinition = definition.variables[variableName];
50089
- let boundValue = transformBoundContentValue(node.data.props, entityStore, binding, resolveDesignValue, variableName, variableDefinition.type, variableMapping.path);
50131
+ // maybePath, because prebound props would have the type 'BoundValue' but the path would be incomplete
50132
+ // eg: "/uuid" vs "/uuid/fields/[fileName]/~locale" as the regular BoundValue would have
50133
+ const [, uuid, maybePath] = variableMapping.path.split('/');
50134
+ const link = dataSource[uuid];
50135
+ let boundValue;
50136
+ // starting from here, if the prop is of type 'BoundValue', and has prebinding
50137
+ // we are going to resolve the incomplete path
50138
+ if (link && isPreboundProp(variableMapping) && variableMapping.isPrebound) {
50139
+ const prebindingPath = getPrebindingPathBySourceEntry(variableMapping, (dataSourceKey) => {
50140
+ const link = dataSource[dataSourceKey];
50141
+ return entityStore.getEntityFromLink(link);
50142
+ }) ?? variableMapping.path;
50143
+ // this allows us to resolve it regularly
50144
+ boundValue = transformBoundContentValue(node.data.props, entityStore, link, resolveDesignValue, variableName, variableDefinition.type, prebindingPath);
50145
+ }
50146
+ else {
50147
+ // here we resolve the regular bound value
50148
+ const variableDefinition = definition.variables[variableName];
50149
+ boundValue = transformBoundContentValue(node.data.props, entityStore, link, resolveDesignValue, variableName, variableDefinition.type, variableMapping.path);
50150
+ }
50090
50151
  // In some cases, there may be an asset linked in the path, so we need to consider this scenario:
50091
50152
  // If no 'boundValue' is found, we also attempt to extract the value associated with the second-to-last item in the path.
50092
50153
  // If successful, it means we have identified the linked asset.
50093
- if (!boundValue) {
50154
+ if (!boundValue && maybePath) {
50094
50155
  const maybeBoundAsset = areEntitiesFetched
50095
- ? entityStore.getValue(binding, path.split('/').slice(0, -2))
50156
+ ? entityStore.getValue(link, maybePath.split('/').slice(0, -2))
50096
50157
  : undefined;
50097
50158
  if (isLinkToAsset(maybeBoundAsset)) {
50098
50159
  boundValue = maybeBoundAsset;