@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/index.js CHANGED
@@ -1063,6 +1063,21 @@ const getValueForBreakpoint = (valuesByBreakpoint, breakpoints, activeBreakpoint
1063
1063
  return valuesByBreakpoint;
1064
1064
  }
1065
1065
  };
1066
+ /** Overwrites the default value breakpoint by breakpoint. If a breakpoint
1067
+ * is not overwritten, it will fall back to the default. */
1068
+ const mergeDesignValuesByBreakpoint = (defaultValue, overwriteValue) => {
1069
+ const mergedValuesByBreakpoint = { ...defaultValue.valuesByBreakpoint };
1070
+ for (const [breakpointId, value] of Object.entries(overwriteValue.valuesByBreakpoint)) {
1071
+ if (!isValidBreakpointValue(value)) {
1072
+ continue;
1073
+ }
1074
+ mergedValuesByBreakpoint[breakpointId] = value;
1075
+ }
1076
+ return {
1077
+ type: 'DesignValue',
1078
+ valuesByBreakpoint: mergedValuesByBreakpoint,
1079
+ };
1080
+ };
1066
1081
 
1067
1082
  const CF_DEBUG_KEY$1 = 'cf_debug';
1068
1083
  let DebugLogger$1 = class DebugLogger {
@@ -3059,6 +3074,26 @@ const useTreeStore = create((set, get) => ({
3059
3074
  reparentChildNode(sourceIndex, destinationIndex, sourceParentId, destinationParentId, state.tree.root);
3060
3075
  }));
3061
3076
  },
3077
+ // breadth first search
3078
+ findNodeById(nodeId) {
3079
+ if (!nodeId) {
3080
+ return null;
3081
+ }
3082
+ const rootNode = get().tree.root;
3083
+ const visitedNodeIds = [];
3084
+ const queue = [];
3085
+ let currentNode = rootNode;
3086
+ queue.push(currentNode);
3087
+ while (queue.length) {
3088
+ currentNode = queue.shift();
3089
+ visitedNodeIds.push(currentNode.data.id);
3090
+ if (currentNode.data.id === nodeId) {
3091
+ return currentNode;
3092
+ }
3093
+ queue.push(...currentNode.children);
3094
+ }
3095
+ return null;
3096
+ },
3062
3097
  }));
3063
3098
  const hasBreakpointDiffs = (currentTree, newTree) => {
3064
3099
  const currentBreakpoints = currentTree?.root?.data?.breakpoints ?? [];
@@ -4604,6 +4639,38 @@ const getUnboundValues = ({ key, fallback, unboundValues, }) => {
4604
4639
  return get$1(unboundValues, lodashPath, fallback);
4605
4640
  };
4606
4641
 
4642
+ /**
4643
+ * When node is a pattern block, we need to look up for default values of the pattern variables
4644
+ * and merge them with the updated node props.
4645
+ * While loop is making sure that we look up for the updated default values in the parent pattern
4646
+ * component settings as well.
4647
+ */
4648
+ const maybeMergePatternDefaultDesignValues = ({ variableName, variableMapping, node, findNodeById, }) => {
4649
+ if (node.type === ASSEMBLY_BLOCK_NODE_TYPE) {
4650
+ const patternId = node.data.pattern?.id;
4651
+ const exposedPropertyName = node['exposedPropertyNameToKeyMap'][variableName];
4652
+ if (!exposedPropertyName || !patternId) {
4653
+ return variableMapping.valuesByBreakpoint;
4654
+ }
4655
+ const exposedVariableDefinition = componentRegistry.get(patternId)?.definition.variables[exposedPropertyName];
4656
+ let exposedDefaultValue = exposedVariableDefinition?.defaultValue;
4657
+ let parentPatternNode = findNodeById(node.data.pattern?.nodeId);
4658
+ while (parentPatternNode) {
4659
+ const parentPatternId = parentPatternNode.data.pattern?.id;
4660
+ const nextKey = parentPatternNode['exposedPropertyNameToKeyMap'][exposedPropertyName];
4661
+ if (!parentPatternId || !nextKey) {
4662
+ break;
4663
+ }
4664
+ const parentPatternVariableDefinition = componentRegistry.get(parentPatternId)?.definition.variables[nextKey];
4665
+ exposedDefaultValue = mergeDesignValuesByBreakpoint(parentPatternVariableDefinition?.defaultValue, exposedDefaultValue);
4666
+ parentPatternNode = findNodeById(parentPatternNode.data.pattern?.nodeId);
4667
+ }
4668
+ const mergedDesignValue = mergeDesignValuesByBreakpoint(exposedDefaultValue, variableMapping);
4669
+ return mergedDesignValue.valuesByBreakpoint;
4670
+ }
4671
+ return variableMapping.valuesByBreakpoint;
4672
+ };
4673
+
4607
4674
  const useComponentProps = ({ node, areEntitiesFetched, resolveDesignValue, renderDropzone, definition, options, userIsDragging, requiresDragWrapper, }) => {
4608
4675
  const unboundValues = useEditorStore((state) => state.unboundValues);
4609
4676
  const hyperlinkPattern = useEditorStore((state) => state.hyperLinkPattern);
@@ -4612,6 +4679,7 @@ const useComponentProps = ({ node, areEntitiesFetched, resolveDesignValue, rende
4612
4679
  const entityStore = useEntityStore((state) => state.entityStore);
4613
4680
  const draggingId = useDraggedItemStore((state) => state.onBeforeCaptureId);
4614
4681
  const nodeRect = useDraggedItemStore((state) => state.domRect);
4682
+ const findNodeById = useTreeStore((state) => state.findNodeById);
4615
4683
  const isEmptyZone = !node.children.length;
4616
4684
  const props = useMemo(() => {
4617
4685
  const propsBase = {
@@ -4635,7 +4703,13 @@ const useComponentProps = ({ node, areEntitiesFetched, resolveDesignValue, rende
4635
4703
  };
4636
4704
  }
4637
4705
  if (variableMapping.type === 'DesignValue') {
4638
- const valuesByBreakpoint = resolveDesignValue(variableMapping.valuesByBreakpoint, variableName);
4706
+ const value = maybeMergePatternDefaultDesignValues({
4707
+ variableName,
4708
+ variableMapping,
4709
+ node,
4710
+ findNodeById,
4711
+ });
4712
+ const valuesByBreakpoint = resolveDesignValue(value, variableName);
4639
4713
  const designValue = variableName === 'cfHeight'
4640
4714
  ? calculateNodeDefaultHeight({
4641
4715
  blockId: node.data.blockId,
@@ -4726,6 +4800,7 @@ const useComponentProps = ({ node, areEntitiesFetched, resolveDesignValue, rende
4726
4800
  unboundValues,
4727
4801
  entityStore,
4728
4802
  renderDropzone,
4803
+ findNodeById,
4729
4804
  ]);
4730
4805
  const cfStyles = useMemo(() => buildCfStyles(props), [props]);
4731
4806
  const cfVisibility = props['cfVisibility'];