@contentful/experiences-visual-editor-react 1.3.0-beta.0 → 1.3.1-dev-20240508T1336-149a569.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
@@ -50745,17 +50745,15 @@ const useSelectedInstanceCoordinates = ({ node }) => {
50745
50745
  };
50746
50746
 
50747
50747
  /**
50748
- *
50749
50748
  * @param styles: the list of styles to apply
50750
- * @param nodeId: [Optional] the id of node that these styles will be applied to
50749
+ * @param nodeId: the id of node that these styles will be applied to
50751
50750
  * @returns className: the className that was used
50752
50751
  * Builds and adds a style tag in the document. Returns the className to be attached to the element.
50753
50752
  * In editor mode the nodeId is used as the identifier in order to avoid creating endless tags as the styles are tweeked
50754
- * In preview/delivery mode the styles don't change oftem so we're using the md5 hash of the content of the tag
50755
50753
  */
50756
- const useStyleTag = ({ styles, nodeId }) => {
50754
+ const useEditorModeClassName = ({ styles, nodeId, }) => {
50757
50755
  const [className, setClassName] = reactExports.useState('');
50758
- reactExports.useEffect(() => {
50756
+ reactExports.useLayoutEffect(() => {
50759
50757
  if (Object.keys(styles).length === 0) {
50760
50758
  return;
50761
50759
  }
@@ -50763,19 +50761,14 @@ const useStyleTag = ({ styles, nodeId }) => {
50763
50761
  setClassName(className);
50764
50762
  const existingTag = document.querySelector(`[data-cf-styles="${className}"]`);
50765
50763
  if (existingTag) {
50766
- // editor mode - update existing
50767
- if (nodeId) {
50768
- existingTag.innerHTML = styleRule;
50769
- }
50770
- // preview/delivery mode - here we don't need to update the existing tag because
50771
- // the className is based on the md5 hash of the content so it hasn't changed
50764
+ existingTag.innerHTML = styleRule;
50772
50765
  return;
50773
50766
  }
50774
50767
  const styleTag = document.createElement('style');
50775
50768
  styleTag.dataset['cfStyles'] = className;
50776
50769
  document.head.appendChild(styleTag).innerHTML = styleRule;
50777
50770
  }, [styles, nodeId]);
50778
- return { className };
50771
+ return className;
50779
50772
  };
50780
50773
 
50781
50774
  const getUnboundValues = ({ key, fallback, unboundValues, }) => {
@@ -50807,11 +50800,11 @@ const useComponentProps = ({ node, areEntitiesFetched, resolveDesignValue, rende
50807
50800
  const dataSource = useEditorStore((state) => state.dataSource);
50808
50801
  const entityStore = useEntityStore((state) => state.entityStore);
50809
50802
  const props = reactExports.useMemo(() => {
50810
- const propsBase = node.data.props?.cfSsrClassName
50811
- ? {
50812
- cfSsrClassName: resolveDesignValue(node.data.props.cfSsrClassName.valuesByBreakpoint, 'cfSsrClassName'),
50813
- }
50814
- : {};
50803
+ const propsBase = {
50804
+ cfSsrClassName: node.data.props.cfSsrClassName
50805
+ ? resolveDesignValue(node.data.props.cfSsrClassName.valuesByBreakpoint, 'cfSsrClassName')
50806
+ : undefined,
50807
+ };
50815
50808
  // Don't enrich the assembly wrapper node with props
50816
50809
  if (!definition || node.type === ASSEMBLY_NODE_TYPE) {
50817
50810
  return propsBase;
@@ -50910,7 +50903,7 @@ const useComponentProps = ({ node, areEntitiesFetched, resolveDesignValue, rende
50910
50903
  // Separate the component styles from the editor wrapper styles
50911
50904
  const { margin, height, width, maxWidth, ...componentStyles } = cfStyles;
50912
50905
  // Styles that will be applied to the editor wrapper (draggable) element
50913
- const { className: wrapperClass } = useStyleTag({
50906
+ const wrapperClass = useEditorModeClassName({
50914
50907
  styles:
50915
50908
  // To ensure that assembly nodes are rendered like they are rendered in
50916
50909
  // the assembly editor, we need to use a normal block instead of a flex box.
@@ -50928,7 +50921,7 @@ const useComponentProps = ({ node, areEntitiesFetched, resolveDesignValue, rende
50928
50921
  nodeId: `editor-${node.data.id}`,
50929
50922
  });
50930
50923
  // Styles that will be applied to the component element
50931
- const { className: componentClass } = useStyleTag({
50924
+ const componentClass = useEditorModeClassName({
50932
50925
  styles: {
50933
50926
  ...componentStyles,
50934
50927
  margin: 0,
@@ -50960,7 +50953,7 @@ const useComponentProps = ({ node, areEntitiesFetched, resolveDesignValue, rende
50960
50953
  editorMode: true,
50961
50954
  node,
50962
50955
  renderDropzone,
50963
- ...omit$1(props, stylesToRemove, ['cfHyperlink', 'cfOpenInNewTab']),
50956
+ ...omit$1(props, stylesToRemove, ['cfHyperlink', 'cfOpenInNewTab', 'cfSsrClassName']),
50964
50957
  ...(definition.children ? { children: renderDropzone(node) } : {}),
50965
50958
  };
50966
50959
  return { componentProps, wrapperProps };