@contentful/experiences-visual-editor-react 1.7.2-dev-20240613T0816-4d3b2da.0 → 1.8.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
@@ -2434,7 +2434,7 @@ function getStyle$2(style, snapshot) {
2434
2434
  transitionDuration: `0.001s`,
2435
2435
  };
2436
2436
  }
2437
- const DraggableComponent = ({ children, id, index, isAssemblyBlock = false, isSelected = false, onClick = () => null, onMouseOver = () => null, coordinates, userIsDragging, style, wrapperProps, isContainer, blockId, isDragDisabled = false, placeholder, definition, displayName, ...rest }) => {
2437
+ const DraggableComponent = ({ children, id, index, isAssemblyBlock = false, isSelected = false, onClick = () => null, onMouseOver = () => null, coordinates, userIsDragging, style, wrapperProps, isContainer, blockId, isDragDisabled = false, placeholder, displayName, ...rest }) => {
2438
2438
  const ref = useRef(null);
2439
2439
  const setDomRect = useDraggedItemStore((state) => state.setDomRect);
2440
2440
  const isHoveredComponent = useDraggedItemStore((state) => state.hoveredComponentId === id);
@@ -2462,7 +2462,7 @@ const DraggableComponent = ({ children, id, index, isAssemblyBlock = false, isSe
2462
2462
  e.stopPropagation();
2463
2463
  setDomRect(e.currentTarget.getBoundingClientRect());
2464
2464
  }, onMouseOver: onMouseOver, onClick: onClick },
2465
- React.createElement(Tooltip, { id: id, coordinates: coordinates, isAssemblyBlock: isAssemblyBlock, isContainer: isContainer, label: displayName || definition.name || 'No label specified' }),
2465
+ React.createElement(Tooltip, { id: id, coordinates: coordinates, isAssemblyBlock: isAssemblyBlock, isContainer: isContainer, label: displayName || 'No label specified' }),
2466
2466
  React.createElement(Placeholder, { ...placeholder, id: id }),
2467
2467
  children))));
2468
2468
  };
@@ -2828,9 +2828,12 @@ const useComponentProps = ({ node, areEntitiesFetched, resolveDesignValue, rende
2828
2828
  node,
2829
2829
  renderDropzone,
2830
2830
  ...omit(props, stylesToRemove, ['cfHyperlink', 'cfOpenInNewTab', 'cfSsrClassName']),
2831
- ...(definition.children ? { children: renderDropzone(node) } : {}),
2831
+ ...(definition?.children ? { children: renderDropzone(node) } : {}),
2832
+ };
2833
+ return {
2834
+ componentProps,
2835
+ wrapperProps,
2832
2836
  };
2833
- return { componentProps, wrapperProps };
2834
2837
  };
2835
2838
  const addExtraDropzonePadding = (padding) => padding
2836
2839
  .split(' ')
@@ -3068,7 +3071,8 @@ const useComponent = ({ node: rawNode, resolveDesignValue, renderDropzone, userI
3068
3071
  });
3069
3072
  }
3070
3073
  if (!registration) {
3071
- throw Error(`Component registration not found for component with id: "${node.data.blockId}". The component might of been removed. To proceed, remove the component manually from the layers tab.`);
3074
+ console.warn(`Component registration not found for component with id: "${node.data.blockId}". The component might of been removed. To proceed, remove the component manually from the layers tab.`);
3075
+ return undefined;
3072
3076
  }
3073
3077
  return registration;
3074
3078
  }, [node]);
@@ -3078,24 +3082,40 @@ const useComponent = ({ node: rawNode, resolveDesignValue, renderDropzone, userI
3078
3082
  areEntitiesFetched,
3079
3083
  resolveDesignValue,
3080
3084
  renderDropzone,
3081
- definition: componentRegistration.definition,
3085
+ definition: componentRegistration?.definition,
3082
3086
  userIsDragging,
3083
3087
  slotId,
3084
3088
  });
3085
3089
  // Only pass editor props to built-in components
3086
3090
  const { editorMode, renderDropzone: _renderDropzone, ...otherComponentProps } = componentProps;
3087
- const elementToRender = builtInComponents.includes(node.data.blockId || '')
3088
- ? (dragProps) => React.createElement(componentRegistration.component, { ...dragProps, ...componentProps })
3089
- : node.type === ASSEMBLY_NODE_TYPE
3090
- ? // Assembly.tsx requires renderDropzone and editorMode as well
3091
- () => React.createElement(componentRegistration.component, componentProps)
3092
- : () => React.createElement(ImportedComponentErrorBoundary, null, React.createElement(componentRegistration.component, otherComponentProps));
3091
+ const createElementToRender = (componentRegistration) => {
3092
+ if (builtInComponents.includes(node.data.blockId || '')) {
3093
+ // eslint-disable-next-line react/display-name
3094
+ return (dragProps) => React.createElement(componentRegistration.component, {
3095
+ ...dragProps,
3096
+ ...componentProps,
3097
+ });
3098
+ }
3099
+ if (node.type === ASSEMBLY_NODE_TYPE) {
3100
+ // Assembly.tsx requires renderDropzone and editorMode as well
3101
+ // eslint-disable-next-line react/display-name
3102
+ return () => React.createElement(componentRegistration.component, componentProps);
3103
+ }
3104
+ return function createComponentWrappedInErrorBoundary() {
3105
+ const elementToWrap = React.createElement(componentRegistration.component, otherComponentProps);
3106
+ return React.createElement(ImportedComponentErrorBoundary, null, elementToWrap);
3107
+ };
3108
+ };
3109
+ const elementToRender = componentRegistration
3110
+ ? createElementToRender(componentRegistration)
3111
+ : null;
3093
3112
  return {
3113
+ isComponentMissing: !componentRegistration,
3094
3114
  node,
3095
3115
  componentId,
3096
3116
  elementToRender,
3097
3117
  wrapperProps,
3098
- definition: componentRegistration.definition,
3118
+ definition: componentRegistration?.definition,
3099
3119
  };
3100
3120
  };
3101
3121
 
@@ -3671,11 +3691,22 @@ const Hitboxes = ({ zoneId, parentZoneId, isEmptyZone }) => {
3671
3691
  return createPortal(ActiveHitboxes, hitboxContainer);
3672
3692
  };
3673
3693
 
3694
+ const MissingComponentPlacehoder = ({ blockId }) => {
3695
+ return (React.createElement("div", { style: {
3696
+ border: '1px solid red',
3697
+ width: '100%',
3698
+ height: '100%',
3699
+ } },
3700
+ "Missing component '",
3701
+ blockId,
3702
+ "'"));
3703
+ };
3704
+
3674
3705
  const EditorBlock = ({ node: rawNode, resolveDesignValue, renderDropzone, index, zoneId, userIsDragging, placeholder, }) => {
3675
3706
  const { slotId } = parseZoneId(zoneId);
3676
3707
  const setSelectedNodeId = useEditorStore((state) => state.setSelectedNodeId);
3677
3708
  const selectedNodeId = useEditorStore((state) => state.selectedNodeId);
3678
- const { node, wrapperProps, definition, elementToRender } = useComponent({
3709
+ const { node, wrapperProps, definition, elementToRender, isComponentMissing } = useComponent({
3679
3710
  node: rawNode,
3680
3711
  resolveDesignValue,
3681
3712
  renderDropzone,
@@ -3718,10 +3749,14 @@ const EditorBlock = ({ node: rawNode, resolveDesignValue, renderDropzone, index,
3718
3749
  nodeId: node.data.id,
3719
3750
  });
3720
3751
  };
3752
+ if (isComponentMissing || !definition || !elementToRender) {
3753
+ return (React.createElement(DraggableComponent, { placeholder: placeholder, id: node.data.id, index: index, isAssemblyBlock: isAssembly || isAssemblyBlock, isDragDisabled: false, isSelected: selectedNodeId === node.data.id, userIsDragging: userIsDragging, isContainer: isContainer, blockId: node.data.blockId, coordinates: coordinates, wrapperProps: wrapperProps, onClick: onClick, onMouseOver: onMouseOver, displayName: displayName || definition?.name },
3754
+ React.createElement(MissingComponentPlacehoder, { blockId: node.data.blockId })));
3755
+ }
3721
3756
  if (isSingleColumn) {
3722
3757
  return (React.createElement(DraggableChildComponent, { elementToRender: elementToRender, id: node.data.id, index: index, isAssemblyBlock: isAssembly || isAssemblyBlock, isDragDisabled: true, isSelected: selectedNodeId === node.data.id, userIsDragging: userIsDragging, isContainer: isContainer, blockId: node.data.blockId, coordinates: coordinates, wrapperProps: wrapperProps, onClick: onClick, onMouseOver: onMouseOver, definition: definition, displayName: displayName }));
3723
3758
  }
3724
- return (React.createElement(DraggableComponent, { placeholder: placeholder, definition: definition, id: node.data.id, index: index, isAssemblyBlock: isAssembly || isAssemblyBlock, isDragDisabled: isAssemblyBlock || isSlotComponent, isSelected: selectedNodeId === node.data.id, userIsDragging: userIsDragging, isContainer: isContainer, blockId: node.data.blockId, coordinates: coordinates, wrapperProps: wrapperProps, onClick: onClick, onMouseOver: onMouseOver, displayName: displayName },
3759
+ return (React.createElement(DraggableComponent, { placeholder: placeholder, id: node.data.id, index: index, isAssemblyBlock: isAssembly || isAssemblyBlock, isDragDisabled: isAssemblyBlock || isSlotComponent, isSelected: selectedNodeId === node.data.id, userIsDragging: userIsDragging, isContainer: isContainer, blockId: node.data.blockId, coordinates: coordinates, wrapperProps: wrapperProps, onClick: onClick, onMouseOver: onMouseOver, displayName: displayName },
3725
3760
  elementToRender(),
3726
3761
  isStructureComponent && userIsDragging && (React.createElement(Hitboxes, { parentZoneId: zoneId, zoneId: node.data.id, isEmptyZone: isEmptyZone }))));
3727
3762
  };
@@ -3784,7 +3819,7 @@ function getStyle$1(style = {}, snapshot) {
3784
3819
  }
3785
3820
  const EditorBlockClone = ({ node: rawNode, resolveDesignValue, snapshot, provided, renderDropzone, }) => {
3786
3821
  const userIsDragging = useDraggedItemStore((state) => state.isDraggingOnCanvas);
3787
- const { node, wrapperProps, elementToRender } = useComponent({
3822
+ const { isComponentMissing, node, wrapperProps, elementToRender } = useComponent({
3788
3823
  node: rawNode,
3789
3824
  resolveDesignValue,
3790
3825
  renderDropzone,
@@ -3792,6 +3827,14 @@ const EditorBlockClone = ({ node: rawNode, resolveDesignValue, snapshot, provide
3792
3827
  });
3793
3828
  const isAssemblyBlock = node.type === ASSEMBLY_BLOCK_NODE_TYPE;
3794
3829
  const isSingleColumn = node.data.blockId === CONTENTFUL_COMPONENTS.singleColumn.id;
3830
+ if (isComponentMissing || !elementToRender) {
3831
+ // !elementToRender is for typescript
3832
+ return (React.createElement("div", { ref: provided?.innerRef, "data-ctfl-dragging-element": true, ...wrapperProps, ...provided?.draggableProps, ...provided?.dragHandleProps, className: classNames(styles$3.DraggableComponent, wrapperProps.className, styles$3.DraggableClone, {
3833
+ [styles$3.isAssemblyBlock]: isAssemblyBlock,
3834
+ [styles$3.isDragging]: snapshot?.isDragging,
3835
+ }), style: getStyle$1(provided?.draggableProps.style, snapshot) },
3836
+ React.createElement(MissingComponentPlacehoder, { blockId: node.data.blockId })));
3837
+ }
3795
3838
  if (isSingleColumn) {
3796
3839
  return elementToRender();
3797
3840
  }