feat: refactor clicks to generic mouse interactions with click/hover subtypes
This commit is contained in:
@@ -132,7 +132,7 @@ export function RecordModeProvider({ children }: { children: React.ReactNode })
|
||||
if (el) {
|
||||
if (event.type === 'scroll') {
|
||||
el.scrollIntoView({ behavior: 'smooth', block: 'center' });
|
||||
} else if (event.type === 'click') {
|
||||
} else if (event.type === 'mouse') {
|
||||
const currentRect = el.getBoundingClientRect();
|
||||
|
||||
// Calculate Point based on Origin
|
||||
@@ -157,6 +157,7 @@ export function RecordModeProvider({ children }: { children: React.ReactNode })
|
||||
clientX: targetX,
|
||||
clientY: targetY
|
||||
};
|
||||
|
||||
const dispatchMouse = (type: string) => {
|
||||
el.dispatchEvent(new MouseEvent(type, {
|
||||
view: window,
|
||||
@@ -165,10 +166,21 @@ export function RecordModeProvider({ children }: { children: React.ReactNode })
|
||||
...eventCoords
|
||||
}));
|
||||
};
|
||||
dispatchMouse('mousedown');
|
||||
dispatchMouse('mouseup');
|
||||
dispatchMouse('click');
|
||||
el.click();
|
||||
|
||||
if (event.interactionType === 'click') {
|
||||
dispatchMouse('mousedown');
|
||||
dispatchMouse('mouseup');
|
||||
dispatchMouse('click');
|
||||
|
||||
if (event.realClick) {
|
||||
el.click();
|
||||
}
|
||||
} else {
|
||||
// Hover Interaction
|
||||
dispatchMouse('mousemove');
|
||||
dispatchMouse('mouseover');
|
||||
dispatchMouse('mouseenter');
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -275,7 +287,7 @@ export function RecordModeProvider({ children }: { children: React.ReactNode })
|
||||
if (el) {
|
||||
if (event.type === 'scroll') {
|
||||
el.scrollIntoView({ behavior: 'smooth', block: 'center' });
|
||||
} else if (event.type === 'click') {
|
||||
} else if (event.type === 'mouse') {
|
||||
const currentRect = el.getBoundingClientRect();
|
||||
|
||||
// Calculate Point based on Origin (same as above for parity)
|
||||
@@ -300,6 +312,7 @@ export function RecordModeProvider({ children }: { children: React.ReactNode })
|
||||
clientX: targetX,
|
||||
clientY: targetY
|
||||
};
|
||||
|
||||
const dispatchMouse = (type: string) => {
|
||||
el.dispatchEvent(new MouseEvent(type, {
|
||||
view: window,
|
||||
@@ -308,10 +321,21 @@ export function RecordModeProvider({ children }: { children: React.ReactNode })
|
||||
...eventCoords
|
||||
}));
|
||||
};
|
||||
dispatchMouse('mousedown');
|
||||
dispatchMouse('mouseup');
|
||||
dispatchMouse('click');
|
||||
el.click();
|
||||
|
||||
if (event.interactionType === 'click') {
|
||||
dispatchMouse('mousedown');
|
||||
dispatchMouse('mouseup');
|
||||
dispatchMouse('click');
|
||||
|
||||
if (event.realClick) {
|
||||
el.click();
|
||||
}
|
||||
} else {
|
||||
// Hover Interaction
|
||||
dispatchMouse('mousemove');
|
||||
dispatchMouse('mouseover');
|
||||
dispatchMouse('mouseenter');
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user