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

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
@@ -1703,7 +1703,7 @@ const NEW_COMPONENT_ID = 'ctfl-new-draggable';
1703
1703
  const CTFL_ZONE_ID = 'data-ctfl-zone-id';
1704
1704
  const CTFL_DRAGGING_ELEMENT = 'data-ctfl-dragging-element';
1705
1705
  const HITBOX = {
1706
- WIDTH: 80,
1706
+ WIDTH: 70,
1707
1707
  HEIGHT: 20,
1708
1708
  INITIAL_OFFSET: 10,
1709
1709
  OFFSET_INCREMENT: 8,
@@ -2120,10 +2120,12 @@ const useEntityStore = create((set) => ({
2120
2120
  },
2121
2121
  resetEntityStore(locale, entities = []) {
2122
2122
  console.debug(`[experiences-sdk-react] Resetting entity store because the locale changed to '${locale}'.`);
2123
+ const newEntityStore = new EditorModeEntityStore({ locale, entities });
2123
2124
  set({
2124
- entityStore: new EditorModeEntityStore({ locale, entities }),
2125
+ entityStore: newEntityStore,
2125
2126
  areEntitiesFetched: false,
2126
2127
  });
2128
+ return newEntityStore;
2127
2129
  },
2128
2130
  }));
2129
2131
 
@@ -3102,11 +3104,11 @@ const EditorBlock = ({ node: rawNode, resolveDesignValue, renderDropzone, draggi
3102
3104
  if (node.data.blockId === CONTENTFUL_COMPONENTS.singleColumn.id) {
3103
3105
  return (React.createElement(React.Fragment, null,
3104
3106
  React.createElement(DraggableChildComponent, { elementToRender: elementToRender, id: componentId, index: index, isAssemblyBlock: isAssemblyBlock, isDragDisabled: isSingleColumn, isSelected: selectedNodeId === componentId, userIsDragging: userIsDragging, isContainer: isContainer, blockId: node.data.blockId, coordinates: coordinates, wrapperProps: wrapperProps, onClick: onClick, definition: definition }),
3105
- isStructureComponent && userIsDragging && (React.createElement(Hitboxes, { parentZoneId: zoneId, zoneId: componentId, enableRootHitboxes: enableRootHitboxes }))));
3107
+ isStructureComponent && !isSingleColumn && userIsDragging && (React.createElement(Hitboxes, { parentZoneId: zoneId, zoneId: componentId, enableRootHitboxes: enableRootHitboxes }))));
3106
3108
  }
3107
3109
  return (React.createElement(DraggableComponent, { placeholder: placeholder, definition: definition, id: componentId, index: index, isAssemblyBlock: isAssemblyBlock, isDragDisabled: isAssemblyBlock, isSelected: selectedNodeId === componentId, userIsDragging: userIsDragging, isContainer: isContainer, blockId: node.data.blockId, coordinates: coordinates, wrapperProps: wrapperProps, onClick: onClick },
3108
3110
  elementToRender(),
3109
- isStructureComponent && userIsDragging && (React.createElement(Hitboxes, { parentZoneId: zoneId, zoneId: componentId, enableRootHitboxes: enableRootHitboxes }))));
3111
+ isStructureComponent && !isSingleColumn && userIsDragging && (React.createElement(Hitboxes, { parentZoneId: zoneId, zoneId: componentId, enableRootHitboxes: enableRootHitboxes }))));
3110
3112
  };
3111
3113
 
3112
3114
  var css_248z$1 = ".EmptyContainer-module_container__XPH5b {\n height: 200px;\n display: flex;\n width: 100%;\n position: absolute;\n align-items: center;\n justify-content: center;\n flex-direction: row;\n transition: all 0.2s;\n color: var(--exp-builder-gray400);\n font-size: var(--exp-builder-font-size-l);\n font-family: var(--exp-builder-font-stack-primary);\n outline: 2px dashed var(--exp-builder-gray400);\n outline-offset: -2px;\n}\n\n.EmptyContainer-module_highlight__lcICy:hover {\n outline: 2px dashed var(--exp-builder-blue500);\n background-color: rgba(var(--exp-builder-blue100-rgb), 0.5);\n cursor: grabbing;\n}\n\n.EmptyContainer-module_icon__82-2O rect {\n fill: var(--exp-builder-gray400);\n}\n\n.EmptyContainer-module_label__4TxRa {\n margin-left: var(--exp-builder-spacing-s);\n}\n";
@@ -3633,6 +3635,7 @@ function useEditorSubscriber() {
3633
3635
  const setDataSource = useEditorStore((state) => state.setDataSource);
3634
3636
  const setSelectedNodeId = useEditorStore((state) => state.setSelectedNodeId);
3635
3637
  const selectedNodeId = useEditorStore((state) => state.selectedNodeId);
3638
+ const resetEntityStore = useEntityStore((state) => state.resetEntityStore);
3636
3639
  const setComponentId = useDraggedItemStore((state) => state.setComponentId);
3637
3640
  const setDraggingOnCanvas = useDraggedItemStore((state) => state.setDraggingOnCanvas);
3638
3641
  const setMousePosition = useDraggedItemStore((state) => state.setMousePosition);
@@ -3654,7 +3657,7 @@ function useEditorSubscriber() {
3654
3657
  * Fills up entityStore with entities from newDataSource and from the tree.
3655
3658
  * Also manages "entity status" variables (areEntitiesFetched, isFetchingEntities)
3656
3659
  */
3657
- const fetchMissingEntities = useCallback(async (newDataSource, tree) => {
3660
+ const fetchMissingEntities = useCallback(async (entityStore, newDataSource, tree) => {
3658
3661
  // if we realize that there's nothing missing and nothing to fill-fetch before we do any async call,
3659
3662
  // then we can simply return and not lock the EntityStore at all.
3660
3663
  const startFetching = () => {
@@ -3725,10 +3728,7 @@ function useEditorSubscriber() {
3725
3728
  finally {
3726
3729
  endFetching();
3727
3730
  }
3728
- }, [
3729
- /* dataSource, */ entityStore,
3730
- setEntitiesFetched /* setFetchingEntities, assembliesRegistry */,
3731
- ]);
3731
+ }, [setEntitiesFetched /* setFetchingEntities, assembliesRegistry */]);
3732
3732
  useEffect(() => {
3733
3733
  const onMessage = async (event) => {
3734
3734
  let reason;
@@ -3758,6 +3758,11 @@ function useEditorSubscriber() {
3758
3758
  // If the assemblyEntry is not yet fetched, this will be done below by
3759
3759
  // the imperative calls to fetchMissingEntities.
3760
3760
  }
3761
+ let newEntityStore = entityStore;
3762
+ if (entityStore.locale !== locale) {
3763
+ newEntityStore = resetEntityStore(locale);
3764
+ setLocale(locale);
3765
+ }
3761
3766
  // Below are mutually exclusive cases
3762
3767
  if (changedNode) {
3763
3768
  /**
@@ -3770,7 +3775,7 @@ function useEditorSubscriber() {
3770
3775
  if (changedValueType === 'BoundValue') {
3771
3776
  const newDataSource = { ...dataSource, ...changedNode.data.dataSource };
3772
3777
  setDataSource(newDataSource);
3773
- await fetchMissingEntities(newDataSource, tree);
3778
+ await fetchMissingEntities(newEntityStore, newDataSource, tree);
3774
3779
  }
3775
3780
  else if (changedValueType === 'UnboundValue') {
3776
3781
  setUnboundValues({
@@ -3778,19 +3783,15 @@ function useEditorSubscriber() {
3778
3783
  ...changedNode.data.unboundValues,
3779
3784
  });
3780
3785
  }
3781
- // Update the tree when all necessary data is fetched and ready for rendering.
3782
- updateTree(tree);
3783
- setLocale(locale);
3784
3786
  }
3785
3787
  else {
3786
3788
  const { dataSource, unboundValues } = getDataFromTree(tree);
3787
3789
  setDataSource(dataSource);
3788
3790
  setUnboundValues(unboundValues);
3789
- await fetchMissingEntities(dataSource, tree);
3790
- // Update the tree when all necessary data is fetched and ready for rendering.
3791
- updateTree(tree);
3792
- setLocale(locale);
3791
+ await fetchMissingEntities(newEntityStore, dataSource, tree);
3793
3792
  }
3793
+ // Update the tree when all necessary data is fetched and ready for rendering.
3794
+ updateTree(tree);
3794
3795
  break;
3795
3796
  }
3796
3797
  case INCOMING_EVENTS.AssembliesRegistered: {
@@ -3924,6 +3925,7 @@ function useEditorSubscriber() {
3924
3925
  updateTree,
3925
3926
  updateNodesByUpdatedEntity,
3926
3927
  setMousePosition,
3928
+ resetEntityStore,
3927
3929
  ]);
3928
3930
  /*
3929
3931
  * Handles on scroll business
@@ -4304,20 +4306,8 @@ const useInitializeEditor = () => {
4304
4306
 
4305
4307
  const VisualEditorRoot = () => {
4306
4308
  const initialized = useInitializeEditor();
4307
- const locale = useEditorStore((state) => state.locale);
4308
4309
  const setMousePosition = useDraggedItemStore((state) => state.setMousePosition);
4309
- const entityStore = useEntityStore((state) => state.entityStore);
4310
4310
  const setHoveringZone = useZoneStore((state) => state.setHoveringZone);
4311
- const resetEntityStore = useEntityStore((state) => state.resetEntityStore);
4312
- useEffect(() => {
4313
- if (!locale) {
4314
- return;
4315
- }
4316
- if (entityStore.locale === locale) {
4317
- return;
4318
- }
4319
- resetEntityStore(locale);
4320
- }, [locale, resetEntityStore, entityStore.locale]);
4321
4311
  useEffect(() => {
4322
4312
  const onMouseMove = (e) => {
4323
4313
  setMousePosition(e.clientX, e.clientY);