Skip to content

Commit 9e63a86

Browse files
State orchestration bugs resolved (#706)
* The state machine will transition from selected to pressed only if it has a comp id * Passed parent to removeHintOverlays because on selectEnd it did not get the parent reference * If a user clicks outside a dropped component the state transitions to Ready.Idle * Log statements used for debugging removed * Used canvasZoneMapIds instead of an optional field to reduce exposure --------- Co-authored-by: Jonathan Alvares <alvaresjonathan599@gmail.com>
1 parent c754027 commit 9e63a86

File tree

3 files changed

+24
-7
lines changed

3 files changed

+24
-7
lines changed

‎packages/atri-app-core/src/canvasMachine.ts‎

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -275,6 +275,13 @@ function insideComponent(
275275
return false;
276276
}
277277

278+
function notInsideComponent(
279+
context: CanvasMachineContext,
280+
event: MOUSE_DOWN_EVENT
281+
) {
282+
return !insideComponent(context, event);
283+
}
284+
278285
function hoveringOverDifferentComponent(
279286
context: CanvasMachineContext,
280287
event: MOUSE_MOVE_EVENT
@@ -615,10 +622,17 @@ export function createCanvasMachine(id: string) {
615622
context.selected = null;
616623
},
617624
on: {
618-
[MOUSE_DOWN]: {
619-
target: pressed,
620-
actions: ["setMousePosition"],
621-
},
625+
[MOUSE_DOWN]: [
626+
{
627+
target: pressed,
628+
cond: insideComponent,
629+
actions: ["setMousePosition"],
630+
},
631+
{
632+
target: `#${id}.${ready}.${idle}`,
633+
cond: notInsideComponent,
634+
},
635+
],
622636
},
623637
type: "parallel",
624638
states: {

‎packages/atri-app-core/src/editor-components/CanvasOverlay/hooks/useSelectHints.tsx‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,7 @@ export function useSelectHints() {
127127
}, []);
128128

129129
useEffect(() => {
130-
return subscribeCanvasMachine("selectEnd", (context, event) => {
130+
return subscribeCanvasMachine("selectEnd", (context, event: any) => {
131131
clearOverlay();
132132
compId.current = null;
133133
});

‎packages/atri-app-core/src/editor-components/VisualHints/hintOverlays.ts‎

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,11 @@ export function removeHintOverlays(overlayIds: string[]) {
3434
return;
3535
}
3636
const overlay = hintOverlays[overlayId]!;
37-
const canvasZoneId = componentStoreApi.getComponent(overlay.compId)!.parent
38-
.canvasZoneId;
37+
let canvasZoneId = "";
38+
for (const property in overlayCanvasZoneMap) {
39+
if (overlayCanvasZoneMap[property].includes(overlay.overlayId))
40+
canvasZoneId = property;
41+
}
3942
affectedCanvasZones.add(canvasZoneId);
4043
if (hintOverlays[overlayId]) {
4144
delete hintOverlays[overlayId];

0 commit comments

Comments
 (0)