@contentful/experiences-visual-editor-react 1.37.1-dev-20250513T1442-6484576.0 → 1.37.1-dev-20250514T1115-cc6f809.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
@@ -43684,6 +43684,21 @@ const getValueForBreakpoint = (valuesByBreakpoint, breakpoints, activeBreakpoint
43684
43684
  return valuesByBreakpoint;
43685
43685
  }
43686
43686
  };
43687
+ /** Overwrites the default value breakpoint by breakpoint. If a breakpoint
43688
+ * is not overwritten, it will fall back to the default. */
43689
+ const mergeDesignValuesByBreakpoint = (defaultValue, overwriteValue) => {
43690
+ const mergedValuesByBreakpoint = { ...defaultValue.valuesByBreakpoint };
43691
+ for (const [breakpointId, value] of Object.entries(overwriteValue.valuesByBreakpoint)) {
43692
+ if (!isValidBreakpointValue(value)) {
43693
+ continue;
43694
+ }
43695
+ mergedValuesByBreakpoint[breakpointId] = value;
43696
+ }
43697
+ return {
43698
+ type: 'DesignValue',
43699
+ valuesByBreakpoint: mergedValuesByBreakpoint,
43700
+ };
43701
+ };
43687
43702
 
43688
43703
  const CF_DEBUG_KEY$1 = 'cf_debug';
43689
43704
  let DebugLogger$1 = class DebugLogger {
@@ -56747,6 +56762,26 @@ const useTreeStore = create$1((set, get) => ({
56747
56762
  reparentChildNode(sourceIndex, destinationIndex, sourceParentId, destinationParentId, state.tree.root);
56748
56763
  }));
56749
56764
  },
56765
+ // breadth first search
56766
+ findNodeById(nodeId) {
56767
+ if (!nodeId) {
56768
+ return null;
56769
+ }
56770
+ const rootNode = get().tree.root;
56771
+ const visitedNodeIds = [];
56772
+ const queue = [];
56773
+ let currentNode = rootNode;
56774
+ queue.push(currentNode);
56775
+ while (queue.length) {
56776
+ currentNode = queue.shift();
56777
+ visitedNodeIds.push(currentNode.data.id);
56778
+ if (currentNode.data.id === nodeId) {
56779
+ return currentNode;
56780
+ }
56781
+ queue.push(...currentNode.children);
56782
+ }
56783
+ return null;
56784
+ },
56750
56785
  }));
56751
56786
  const hasBreakpointDiffs = (currentTree, newTree) => {
56752
56787
  const currentBreakpoints = currentTree?.root?.data?.breakpoints ?? [];
@@ -59573,6 +59608,38 @@ const getUnboundValues = ({ key, fallback, unboundValues, }) => {
59573
59608
  return get$1(unboundValues, lodashPath, fallback);
59574
59609
  };
59575
59610
 
59611
+ /**
59612
+ * When node is a pattern block, we need to look up for default values of the pattern variables
59613
+ * and merge them with the updated node props.
59614
+ * While loop is making sure that we look up for the updated default values in the parent pattern
59615
+ * component settings as well.
59616
+ */
59617
+ const maybeMergePatternDefaultDesignValues = ({ variableName, variableMapping, node, findNodeById, }) => {
59618
+ if (node.type === ASSEMBLY_BLOCK_NODE_TYPE) {
59619
+ const patternId = node.data.pattern?.id;
59620
+ const exposedPropertyName = node['exposedPropertyNameToKeyMap'][variableName];
59621
+ if (!exposedPropertyName || !patternId) {
59622
+ return variableMapping.valuesByBreakpoint;
59623
+ }
59624
+ const exposedVariableDefinition = componentRegistry.get(patternId)?.definition.variables[exposedPropertyName];
59625
+ let exposedDefaultValue = exposedVariableDefinition?.defaultValue;
59626
+ let parentPatternNode = findNodeById(node.data.pattern?.nodeId);
59627
+ while (parentPatternNode) {
59628
+ const parentPatternId = parentPatternNode.data.pattern?.id;
59629
+ const nextKey = parentPatternNode['exposedPropertyNameToKeyMap'][exposedPropertyName];
59630
+ if (!parentPatternId || !nextKey) {
59631
+ break;
59632
+ }
59633
+ const parentPatternVariableDefinition = componentRegistry.get(parentPatternId)?.definition.variables[nextKey];
59634
+ exposedDefaultValue = mergeDesignValuesByBreakpoint(parentPatternVariableDefinition?.defaultValue, exposedDefaultValue);
59635
+ parentPatternNode = findNodeById(parentPatternNode.data.pattern?.nodeId);
59636
+ }
59637
+ const mergedDesignValue = mergeDesignValuesByBreakpoint(exposedDefaultValue, variableMapping);
59638
+ return mergedDesignValue.valuesByBreakpoint;
59639
+ }
59640
+ return variableMapping.valuesByBreakpoint;
59641
+ };
59642
+
59576
59643
  const useComponentProps = ({ node, areEntitiesFetched, resolveDesignValue, renderDropzone, definition, options, userIsDragging, requiresDragWrapper, }) => {
59577
59644
  const unboundValues = useEditorStore((state) => state.unboundValues);
59578
59645
  const hyperlinkPattern = useEditorStore((state) => state.hyperLinkPattern);
@@ -59581,6 +59648,7 @@ const useComponentProps = ({ node, areEntitiesFetched, resolveDesignValue, rende
59581
59648
  const entityStore = useEntityStore((state) => state.entityStore);
59582
59649
  const draggingId = useDraggedItemStore((state) => state.onBeforeCaptureId);
59583
59650
  const nodeRect = useDraggedItemStore((state) => state.domRect);
59651
+ const findNodeById = useTreeStore((state) => state.findNodeById);
59584
59652
  const isEmptyZone = !node.children.length;
59585
59653
  const props = reactExports.useMemo(() => {
59586
59654
  const propsBase = {
@@ -59604,7 +59672,13 @@ const useComponentProps = ({ node, areEntitiesFetched, resolveDesignValue, rende
59604
59672
  };
59605
59673
  }
59606
59674
  if (variableMapping.type === 'DesignValue') {
59607
- const valuesByBreakpoint = resolveDesignValue(variableMapping.valuesByBreakpoint, variableName);
59675
+ const value = maybeMergePatternDefaultDesignValues({
59676
+ variableName,
59677
+ variableMapping,
59678
+ node,
59679
+ findNodeById,
59680
+ });
59681
+ const valuesByBreakpoint = resolveDesignValue(value, variableName);
59608
59682
  const designValue = variableName === 'cfHeight'
59609
59683
  ? calculateNodeDefaultHeight({
59610
59684
  blockId: node.data.blockId,
@@ -59695,6 +59769,7 @@ const useComponentProps = ({ node, areEntitiesFetched, resolveDesignValue, rende
59695
59769
  unboundValues,
59696
59770
  entityStore,
59697
59771
  renderDropzone,
59772
+ findNodeById,
59698
59773
  ]);
59699
59774
  const cfStyles = reactExports.useMemo(() => buildCfStyles(props), [props]);
59700
59775
  const cfVisibility = props['cfVisibility'];