Implement #2: simulate hover event
This commit is contained in:
@@ -47,6 +47,6 @@
|
|||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"mitt": "^1.1.3",
|
"mitt": "^1.1.3",
|
||||||
"rrweb-snapshot": "0.5.3"
|
"rrweb-snapshot": "^0.5.6"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -199,13 +199,14 @@ function initMousemoveObserver(cb: mousemoveCallBack): listenerHandler {
|
|||||||
}, 500);
|
}, 500);
|
||||||
const updatePosition = throttle<MouseEvent>(
|
const updatePosition = throttle<MouseEvent>(
|
||||||
evt => {
|
evt => {
|
||||||
const { clientX, clientY } = evt;
|
const { clientX, clientY, target } = evt;
|
||||||
if (!timeBaseline) {
|
if (!timeBaseline) {
|
||||||
timeBaseline = Date.now();
|
timeBaseline = Date.now();
|
||||||
}
|
}
|
||||||
positions.push({
|
positions.push({
|
||||||
x: clientX,
|
x: clientX,
|
||||||
y: clientY,
|
y: clientY,
|
||||||
|
id: mirror.getId(target as INode),
|
||||||
timeOffset: Date.now() - timeBaseline,
|
timeOffset: Date.now() - timeBaseline,
|
||||||
});
|
});
|
||||||
wrappedCb();
|
wrappedCb();
|
||||||
|
|||||||
@@ -31,11 +31,11 @@ export class Replayer {
|
|||||||
|
|
||||||
private iframe: HTMLIFrameElement;
|
private iframe: HTMLIFrameElement;
|
||||||
private mouse: HTMLDivElement;
|
private mouse: HTMLDivElement;
|
||||||
private baselineTime: number = 0;
|
|
||||||
|
|
||||||
private timerIds: number[] = [];
|
private timerIds: number[] = [];
|
||||||
private emitter: mitt.Emitter = mitt();
|
private emitter: mitt.Emitter = mitt();
|
||||||
|
|
||||||
|
private baselineTime: number = 0;
|
||||||
// record last played event timestamp when paused
|
// record last played event timestamp when paused
|
||||||
private lastPlayedEvent: eventWithTime;
|
private lastPlayedEvent: eventWithTime;
|
||||||
|
|
||||||
@@ -260,6 +260,10 @@ export class Replayer {
|
|||||||
this.later(() => {
|
this.later(() => {
|
||||||
this.mouse.style.left = `${p.x}px`;
|
this.mouse.style.left = `${p.x}px`;
|
||||||
this.mouse.style.top = `${p.y}px`;
|
this.mouse.style.top = `${p.y}px`;
|
||||||
|
const target = mirror.getNode(p.id);
|
||||||
|
if (target) {
|
||||||
|
this.hoverElements((target as Node) as Element);
|
||||||
|
}
|
||||||
}, p.timeOffset);
|
}, p.timeOffset);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@@ -308,4 +312,17 @@ export class Replayer {
|
|||||||
default:
|
default:
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private hoverElements(el: Element) {
|
||||||
|
this.iframe
|
||||||
|
.contentDocument!.querySelectorAll('.\\:hover')
|
||||||
|
.forEach(hoveredEl => {
|
||||||
|
hoveredEl.classList.remove(':hover');
|
||||||
|
});
|
||||||
|
let currentEl: Element | null = el;
|
||||||
|
while (currentEl) {
|
||||||
|
currentEl.classList.add(':hover');
|
||||||
|
currentEl = currentEl.parentElement;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -159,6 +159,7 @@ export type mousemoveCallBack = (p: mousePosition[]) => void;
|
|||||||
export type mousePosition = {
|
export type mousePosition = {
|
||||||
x: number;
|
x: number;
|
||||||
y: number;
|
y: number;
|
||||||
|
id: number;
|
||||||
timeOffset: number;
|
timeOffset: number;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user