@contentful/experiences-visual-editor-react 0.0.1-alpha.4 → 0.0.1-alpha.6

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
@@ -34864,7 +34864,7 @@ const builtInStyles = {
34864
34864
  type: 'Text',
34865
34865
  group: 'style',
34866
34866
  description: 'The border of the section',
34867
- defaultValue: '1px solid rgba(0, 0, 0, 0)',
34867
+ defaultValue: '0px solid rgba(0, 0, 0, 0)',
34868
34868
  },
34869
34869
  cfGap: {
34870
34870
  displayName: 'Gap',
@@ -46168,8 +46168,8 @@ var classnames = {exports: {}};
46168
46168
  var classnamesExports = classnames.exports;
46169
46169
  var classNames = /*@__PURE__*/getDefaultExportFromCjs(classnamesExports);
46170
46170
 
46171
- var css_248z$6 = ".styles-module_DraggableComponent__m5-dA {\n pointer-events: all;\n position: relative;\n transition: outline 0.2s;\n cursor: grab;\n outline-offset: -2px;\n outline: 2px solid transparent;\n box-sizing: border-box;\n display: flex;\n}\n\n.styles-module_DraggableClone__X8zTA {\n outline: 2px solid var(--exp-builder-blue500);\n}\n\n.styles-module_DraggableComponent__m5-dA > * {\n pointer-events: none;\n}\n\n.styles-module_isDragging__WHjPU {\n overflow: hidden;\n}\n\n.styles-module_isDragging__WHjPU * {\n pointer-events: none !important;\n}\n\n.styles-module_isSelected__BzICQ {\n outline: 2px solid transparent !important;\n}\n\n.styles-module_overlay__r4th9 {\n position: absolute;\n display: flex;\n align-items: center;\n min-width: max-content;\n height: 24px;\n z-index: 1;\n font-family: var(--exp-builder-font-stack-primary);\n font-size: 14px;\n font-weight: 500;\n background-color: var(--exp-builder-gray500);\n color: var(--exp-builder-color-white);\n border-radius: 0 0 2px 0;\n padding: 4px 12px 4px 12px;\n transition: opacity 0.2s;\n opacity: 0;\n text-wrap: nowrap;\n}\n\n.styles-module_overlayContainer__eiX-5 {\n opacity: 0;\n}\n\n.styles-module_overlayAssembly__tOzZU {\n background-color: var(--exp-builder-purple600);\n}\n\n.styles-module_userIsDragging__lqbjG > .styles-module_overlay__r4th9,\n.styles-module_userIsDragging__lqbjG > .styles-module_overlayContainer__eiX-5 {\n opacity: 0 !important;\n}\n\n.styles-module_userIsDragging__lqbjG {\n outline: 2px solid transparent !important;\n}\n\n.styles-module_DraggableComponent__m5-dA:hover:not(:has(div[data-rfd-draggable-id]:hover)) > .styles-module_overlay__r4th9 {\n opacity: 1;\n}\n\n.styles-module_DraggableComponent__m5-dA:hover,\n.styles-module_DraggableComponent__m5-dA:hover div[data-rfd-draggable-id] {\n outline: 2px dashed var(--exp-builder-gray500);\n}\n\n.styles-module_DraggableComponent__m5-dA:hover:not(:has(div[data-rfd-draggable-id]:hover)) {\n outline: 2px solid var(--exp-builder-gray500);\n}\n\n.styles-module_isAssemblyBlock__Y3Avk:hover,\n.styles-module_isAssemblyBlock__Y3Avk:hover div[data-rfd-draggable-id],\n.styles-module_DraggableComponent__m5-dA:hover div[data-rfd-draggable-id][data-cf-node-block-type^='assembly'] {\n outline: 2px dashed var(--exp-builder-purple600);\n}\n\n.styles-module_isAssemblyBlock__Y3Avk:hover:not(:has(div[data-rfd-draggable-id]:hover)) {\n outline: 2px solid var(--exp-builder-purple600);\n}\n";
46172
- var styles$3 = {"DraggableComponent":"styles-module_DraggableComponent__m5-dA","DraggableClone":"styles-module_DraggableClone__X8zTA","isDragging":"styles-module_isDragging__WHjPU","isSelected":"styles-module_isSelected__BzICQ","overlay":"styles-module_overlay__r4th9","overlayContainer":"styles-module_overlayContainer__eiX-5","overlayAssembly":"styles-module_overlayAssembly__tOzZU","userIsDragging":"styles-module_userIsDragging__lqbjG","isAssemblyBlock":"styles-module_isAssemblyBlock__Y3Avk"};
46171
+ var css_248z$6 = ".styles-module_DraggableComponent__m5-dA {\n pointer-events: all;\n position: relative;\n transition: outline 0.2s;\n cursor: grab;\n box-sizing: border-box;\n display: flex;\n}\n\n.styles-module_DraggableComponent__m5-dA:before {\n content: '';\n position: absolute;\n top: 0;\n right: 0;\n bottom: 0;\n left: 0;\n outline-offset: -2px;\n outline: 2px solid transparent;\n z-index: 1;\n pointer-events: none;\n}\n\n.styles-module_DraggableClone__X8zTA:before {\n outline: 2px solid var(--exp-builder-blue500);\n}\n\n.styles-module_DraggableClone__X8zTA,\n.styles-module_DraggableClone__X8zTA * {\n pointer-events: none !important;\n}\n\n.styles-module_DraggableComponent__m5-dA:not(.styles-module_userIsDragging__lqbjG) :not(.styles-module_DraggableComponent__m5-dA) {\n pointer-events: none;\n}\n\n.styles-module_isDragging__WHjPU {\n overflow: hidden;\n}\n\n.styles-module_isSelected__BzICQ:before {\n outline: 2px solid transparent !important;\n}\n\n.styles-module_overlay__r4th9 {\n position: absolute;\n display: flex;\n align-items: center;\n min-width: max-content;\n height: 24px;\n z-index: 1;\n font-family: var(--exp-builder-font-stack-primary);\n font-size: 14px;\n font-weight: 500;\n background-color: var(--exp-builder-gray500);\n color: var(--exp-builder-color-white);\n border-radius: 0 0 2px 0;\n padding: 4px 12px 4px 12px;\n transition: opacity 0.2s;\n opacity: 0;\n text-wrap: nowrap;\n}\n\n.styles-module_overlayContainer__eiX-5 {\n opacity: 0;\n}\n\n.styles-module_overlayAssembly__tOzZU {\n background-color: var(--exp-builder-purple600);\n}\n\n.styles-module_userIsDragging__lqbjG > .styles-module_overlay__r4th9,\n.styles-module_userIsDragging__lqbjG > .styles-module_overlayContainer__eiX-5 {\n opacity: 0 !important;\n}\n\n.styles-module_userIsDragging__lqbjG:before {\n outline: 2px solid transparent !important;\n}\n\n.styles-module_DraggableComponent__m5-dA:hover:not(:has(div[data-rfd-draggable-id]:hover)) > .styles-module_overlay__r4th9 {\n opacity: 1;\n}\n\n.styles-module_DraggableComponent__m5-dA:hover:before,\n.styles-module_DraggableComponent__m5-dA:hover div[data-rfd-draggable-id]:before {\n outline: 2px dashed var(--exp-builder-gray500);\n}\n\n.styles-module_DraggableComponent__m5-dA:hover:not(:has(div[data-rfd-draggable-id]:hover)):before {\n outline: 2px solid var(--exp-builder-gray500);\n}\n\n.styles-module_isAssemblyBlock__Y3Avk:hover:before,\n.styles-module_isAssemblyBlock__Y3Avk:hover div[data-rfd-draggable-id]:before,\n.styles-module_DraggableComponent__m5-dA:hover div[data-rfd-draggable-id][data-cf-node-block-type^='assembly']:before {\n outline: 2px dashed var(--exp-builder-purple600);\n}\n\n.styles-module_isAssemblyBlock__Y3Avk:hover:not(:has(div[data-rfd-draggable-id]:hover)):before {\n outline: 2px solid var(--exp-builder-purple600);\n}\n";
46172
+ var styles$3 = {"DraggableComponent":"styles-module_DraggableComponent__m5-dA","DraggableClone":"styles-module_DraggableClone__X8zTA","userIsDragging":"styles-module_userIsDragging__lqbjG","isDragging":"styles-module_isDragging__WHjPU","isSelected":"styles-module_isSelected__BzICQ","overlay":"styles-module_overlay__r4th9","overlayContainer":"styles-module_overlayContainer__eiX-5","overlayAssembly":"styles-module_overlayAssembly__tOzZU","isAssemblyBlock":"styles-module_isAssemblyBlock__Y3Avk"};
46173
46173
  styleInject(css_248z$6);
46174
46174
 
46175
46175
  const SCROLL_STATES = {
@@ -46533,6 +46533,41 @@ var DraggablePosition;
46533
46533
  DraggablePosition[DraggablePosition["MOUSE_POSITION"] = 1] = "MOUSE_POSITION";
46534
46534
  })(DraggablePosition || (DraggablePosition = {}));
46535
46535
 
46536
+ const calcOffsetLeft = (parentElement, placeholderWidth, nodeWidth) => {
46537
+ if (!parentElement) {
46538
+ return 0;
46539
+ }
46540
+ const alignItems = window.getComputedStyle(parentElement).alignItems;
46541
+ if (alignItems === 'center') {
46542
+ return -(placeholderWidth - nodeWidth) / 2;
46543
+ }
46544
+ if (alignItems === 'end') {
46545
+ return -placeholderWidth + nodeWidth + 2;
46546
+ }
46547
+ return 0;
46548
+ };
46549
+ const calcOffsetTop = (parentElement, placeholderHeight, nodeHeight) => {
46550
+ if (!parentElement) {
46551
+ return 0;
46552
+ }
46553
+ const alignItems = window.getComputedStyle(parentElement).alignItems;
46554
+ if (alignItems === 'center') {
46555
+ return -(placeholderHeight - nodeHeight) / 2;
46556
+ }
46557
+ if (alignItems === 'end') {
46558
+ return -placeholderHeight + nodeHeight + 2;
46559
+ }
46560
+ return 0;
46561
+ };
46562
+ const getPaddingOffset = (element) => {
46563
+ const paddingLeft = parseFloat(window.getComputedStyle(element).paddingLeft);
46564
+ const paddingRight = parseFloat(window.getComputedStyle(element).paddingRight);
46565
+ const paddingTop = parseFloat(window.getComputedStyle(element).paddingTop);
46566
+ const paddingBottom = parseFloat(window.getComputedStyle(element).paddingBottom);
46567
+ const horizontalOffset = paddingLeft + paddingRight;
46568
+ const verticalOffset = paddingTop + paddingBottom;
46569
+ return [horizontalOffset, verticalOffset];
46570
+ };
46536
46571
  /**
46537
46572
  * Calculate the size and position of the dropzone indicator
46538
46573
  * when dragging a new component onto the canvas
@@ -46550,10 +46585,15 @@ const calcNewComponentStyles = (params) => {
46550
46585
  }
46551
46586
  const elementSizes = element.getBoundingClientRect();
46552
46587
  const dropzoneSizes = dropzone.getBoundingClientRect();
46553
- const width = isHorizontal ? DRAGGABLE_WIDTH : dropzoneSizes.width;
46554
- const height = isHorizontal ? dropzoneSizes.height : DRAGGABLE_HEIGHT;
46555
- const top = isHorizontal ? -(height - elementSizes.height) / 2 : -height;
46556
- const left = isHorizontal ? -width : -(width - elementSizes.width) / 2;
46588
+ const [horizontalPadding, verticalPadding] = getPaddingOffset(dropzone);
46589
+ const width = isHorizontal ? DRAGGABLE_WIDTH : dropzoneSizes.width - horizontalPadding;
46590
+ const height = isHorizontal ? dropzoneSizes.height - verticalPadding : DRAGGABLE_HEIGHT;
46591
+ const top = isHorizontal
46592
+ ? calcOffsetTop(element.parentElement, height, elementSizes.height)
46593
+ : -height;
46594
+ const left = isHorizontal
46595
+ ? -width
46596
+ : calcOffsetLeft(element.parentElement, width, elementSizes.width);
46557
46597
  return {
46558
46598
  width,
46559
46599
  height,
@@ -46584,10 +46624,15 @@ const calcMovementStyles = (params) => {
46584
46624
  const elementSizes = element.getBoundingClientRect();
46585
46625
  const dropzoneSizes = dropzone.getBoundingClientRect();
46586
46626
  const draggableSizes = draggable.getBoundingClientRect();
46587
- const width = isHorizontal ? draggableSizes.width : dropzoneSizes.width;
46588
- const height = isHorizontal ? dropzoneSizes.height : draggableSizes.height;
46589
- const top = isHorizontal ? -(height - elementSizes.height) / 2 : -height;
46590
- const left = isHorizontal ? -width : -(width - elementSizes.width) / 2;
46627
+ const [horizontalPadding, verticalPadding] = getPaddingOffset(dropzone);
46628
+ const width = isHorizontal ? draggableSizes.width : dropzoneSizes.width - horizontalPadding;
46629
+ const height = isHorizontal ? dropzoneSizes.height - verticalPadding : draggableSizes.height;
46630
+ const top = isHorizontal
46631
+ ? calcOffsetTop(element.parentElement, height, elementSizes.height)
46632
+ : -height;
46633
+ const left = isHorizontal
46634
+ ? -width
46635
+ : calcOffsetLeft(element.parentElement, width, elementSizes.width);
46591
46636
  return {
46592
46637
  width,
46593
46638
  height,
@@ -50330,9 +50375,11 @@ const useSelectedInstanceCoordinates = ({ node }) => {
50330
50375
  if (selectedNodeId !== node.data.id) {
50331
50376
  return;
50332
50377
  }
50378
+ // Allows the drop animation to finish before
50379
+ // calculating the components coordinates
50333
50380
  setTimeout(() => {
50334
50381
  sendSelectedComponentCoordinates(node.data.id);
50335
- }, 200);
50382
+ }, 10);
50336
50383
  }, [node, selectedNodeId]);
50337
50384
  const selectedElement = node.data.id
50338
50385
  ? document.querySelector(`[data-cf-node-id="${selectedNodeId}"]`)
@@ -51368,7 +51415,7 @@ const DraggableChildComponent = (props) => {
51368
51415
  })));
51369
51416
  };
51370
51417
 
51371
- var css_248z$2 = ".styles-module_container__te-1H {\n margin-left: auto;\n margin-right: auto;\n position: relative;\n height: 100%;\n outline-offset: -2px;\n outline: 2px solid transparent;\n width: 100%;\n background-color: transparent;\n transition:\n outline 0.2s,\n background-color 0.2s;\n pointer-events: all;\n}\n\n.styles-module_container__te-1H:not(.styles-module_isRoot__5cn-i) {\n outline-offset: -1px;\n}\n\n.styles-module_isRoot__5cn-i,\n.styles-module_isEmptyCanvas__0XHZR {\n flex: 1;\n}\n\n.styles-module_isEmptyZone__zVpnZ {\n min-height: 80px;\n}\n\n.styles-module_isDragging__Gm8v5:not(.styles-module_isRoot__5cn-i) {\n outline: 2px dashed var(--exp-builder-gray300);\n}\n\n.styles-module_isDestination__5sCQx:not(.styles-module_isRoot__5cn-i) {\n outline: 2px dashed var(--exp-builder-blue400);\n background-color: rgba(var(--exp-builder-blue100-rgb), 0.5);\n z-index: 100;\n}\n\n.styles-module_hitbox__YQ-1Z {\n position: fixed;\n pointer-events: all !important;\n}\n";
51418
+ var css_248z$2 = ".styles-module_container__te-1H {\n margin-left: auto;\n margin-right: auto;\n position: relative;\n height: 100%;\n width: 100%;\n background-color: transparent;\n transition: background-color 0.2s;\n pointer-events: all !important;\n}\n\n.styles-module_container__te-1H:not(.styles-module_isRoot__5cn-i):before {\n content: '';\n position: absolute;\n top: 0;\n right: 0;\n bottom: 0;\n left: 0;\n outline-offset: -1px;\n outline: 2px solid transparent;\n z-index: 1;\n transition: outline 0.2s;\n pointer-events: none;\n}\n\n.styles-module_isRoot__5cn-i,\n.styles-module_isEmptyCanvas__0XHZR {\n flex: 1;\n}\n\n.styles-module_isEmptyZone__zVpnZ {\n min-height: 80px;\n}\n\n.styles-module_isDragging__Gm8v5:not(.styles-module_isRoot__5cn-i):before {\n outline: 2px dashed var(--exp-builder-gray300);\n}\n\n.styles-module_isDestination__5sCQx:not(.styles-module_isRoot__5cn-i):before {\n transition:\n outline 0.2s,\n background-color 0.2s;\n outline: 2px dashed var(--exp-builder-blue400);\n background-color: rgba(var(--exp-builder-blue100-rgb), 0.5);\n z-index: 2;\n}\n\n.styles-module_hitbox__YQ-1Z {\n position: fixed;\n pointer-events: all !important;\n}\n";
51372
51419
  var styles$2 = {"container":"styles-module_container__te-1H","isRoot":"styles-module_isRoot__5cn-i","isEmptyCanvas":"styles-module_isEmptyCanvas__0XHZR","isEmptyZone":"styles-module_isEmptyZone__zVpnZ","isDragging":"styles-module_isDragging__Gm8v5","isDestination":"styles-module_isDestination__5sCQx","hitbox":"styles-module_hitbox__YQ-1Z"};
51373
51420
  styleInject(css_248z$2);
51374
51421
 
@@ -53767,27 +53814,28 @@ const RootRenderer = ({ onChange }) => {
53767
53814
  const dragItem = useDraggedItemStore((state) => state.componentId);
53768
53815
  const userIsDragging = useDraggedItemStore((state) => state.isDraggingOnCanvas);
53769
53816
  const breakpoints = useTreeStore((state) => state.breakpoints);
53817
+ const setSelectedNodeId = useEditorStore((state) => state.setSelectedNodeId);
53770
53818
  const draggableSourceId = useDraggedItemStore((state) => state.draggedItem?.source.droppableId);
53771
53819
  const draggingNewComponent = !!draggableSourceId?.startsWith(COMPONENT_LIST_ID);
53772
53820
  const containerRef = reactExports.useRef(null);
53773
53821
  const { resolveDesignValue } = useBreakpoints(breakpoints);
53774
53822
  const [containerStyles, setContainerStyles] = reactExports.useState({});
53775
53823
  const tree = useTreeStore((state) => state.tree);
53776
- reactExports.useEffect(() => {
53777
- if (onChange)
53778
- onChange(tree);
53779
- }, [tree, onChange]);
53780
- reactExports.useEffect(() => {
53781
- document.addEventListener('click', handleClickOutside);
53782
- return () => {
53783
- document.removeEventListener('click', handleClickOutside);
53784
- };
53785
- }, []);
53786
- const handleClickOutside = () => {
53824
+ const handleClickOutside = reactExports.useCallback((e) => {
53825
+ const element = e.target;
53826
+ const isRoot = element.getAttribute('data-ctfl-zone-id') === ROOT_ID;
53827
+ const clickedOnCanvas = element.closest(`[data-ctfl-root]`);
53828
+ if (clickedOnCanvas && !isRoot) {
53829
+ return;
53830
+ }
53787
53831
  sendMessage(OUTGOING_EVENTS.OutsideCanvasClick, {
53788
53832
  outsideCanvasClick: true,
53789
53833
  });
53790
- };
53834
+ sendMessage(OUTGOING_EVENTS.ComponentSelected, {
53835
+ selectedId: '',
53836
+ });
53837
+ setSelectedNodeId('');
53838
+ }, [setSelectedNodeId]);
53791
53839
  const handleResizeCanvas = reactExports.useCallback(() => {
53792
53840
  const parentElement = containerRef.current?.parentElement;
53793
53841
  if (!parentElement) {
@@ -53817,6 +53865,16 @@ const RootRenderer = ({ onChange }) => {
53817
53865
  });
53818
53866
  // eslint-disable-next-line react-hooks/exhaustive-deps
53819
53867
  }, [containerRef.current]);
53868
+ reactExports.useEffect(() => {
53869
+ if (onChange)
53870
+ onChange(tree);
53871
+ }, [tree, onChange]);
53872
+ reactExports.useEffect(() => {
53873
+ document.addEventListener('click', handleClickOutside);
53874
+ return () => {
53875
+ document.removeEventListener('click', handleClickOutside);
53876
+ };
53877
+ }, [handleClickOutside]);
53820
53878
  reactExports.useEffect(() => {
53821
53879
  handleResizeCanvas();
53822
53880
  // eslint-disable-next-line react-hooks/exhaustive-deps
@@ -53868,16 +53926,6 @@ const useInitializeEditor = () => {
53868
53926
  return initialized;
53869
53927
  };
53870
53928
 
53871
- const findNearestDropzone = (element) => {
53872
- const zoneId = element.getAttribute(CTFL_ZONE_ID);
53873
- if (!element.parentElement) {
53874
- return null;
53875
- }
53876
- if (element.tagName === 'BODY') {
53877
- return null;
53878
- }
53879
- return zoneId ?? findNearestDropzone(element.parentElement);
53880
- };
53881
53929
  const VisualEditorRoot = () => {
53882
53930
  const initialized = useInitializeEditor();
53883
53931
  const locale = useEditorStore((state) => state.locale);
@@ -53898,7 +53946,7 @@ const VisualEditorRoot = () => {
53898
53946
  const onMouseMove = (e) => {
53899
53947
  setMousePosition(e.clientX, e.clientY);
53900
53948
  const target = e.target;
53901
- const zoneId = findNearestDropzone(target);
53949
+ const zoneId = target.closest(`[${CTFL_ZONE_ID}]`)?.getAttribute(CTFL_ZONE_ID);
53902
53950
  if (zoneId) {
53903
53951
  setHoveringZone(zoneId);
53904
53952
  }