feature: Add cursor highlight feature in canvas page (#4007)
* added a color change in cursor to help user find the cursor in the canvas page * [autofix.ci] apply automated fixes --------- Co-authored-by: autofix-ci[bot] <114827586+autofix-ci[bot]@users.noreply.github.com> Co-authored-by: Cristhian Zanforlin Lousa <cristhian.lousa@gmail.com>
This commit is contained in:
parent
0298596b64
commit
99cdaaf073
1 changed files with 66 additions and 0 deletions
|
|
@ -115,6 +115,72 @@ export default function Page({ view }: { view?: boolean }): JSX.Element {
|
||||||
const currentFlowId = useFlowsManagerStore((state) => state.currentFlowId);
|
const currentFlowId = useFlowsManagerStore((state) => state.currentFlowId);
|
||||||
|
|
||||||
const [isAddingNote, setIsAddingNote] = useState(false);
|
const [isAddingNote, setIsAddingNote] = useState(false);
|
||||||
|
const [isHighlightingCursor, setIsHighlightingCursor] = useState(false);
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
const handleVisibilityChange = () => {
|
||||||
|
if (!document.hidden) {
|
||||||
|
setIsHighlightingCursor(true);
|
||||||
|
setTimeout(() => setIsHighlightingCursor(false), 1000);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
document.addEventListener("visibilitychange", handleVisibilityChange);
|
||||||
|
|
||||||
|
return () => {
|
||||||
|
document.removeEventListener("visibilitychange", handleVisibilityChange);
|
||||||
|
};
|
||||||
|
}, []);
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
if (isHighlightingCursor) {
|
||||||
|
const cursor = document.body.style.cursor;
|
||||||
|
document.body.style.cursor = "none";
|
||||||
|
const highlightDiv = document.createElement("div");
|
||||||
|
highlightDiv.style.position = "fixed";
|
||||||
|
highlightDiv.style.width = "40px";
|
||||||
|
highlightDiv.style.height = "40px";
|
||||||
|
highlightDiv.style.borderRadius = "50%";
|
||||||
|
highlightDiv.style.background =
|
||||||
|
"radial-gradient(circle, rgba(135,206,250,0.7) 0%, rgba(135,206,250,0) 70%)";
|
||||||
|
highlightDiv.style.pointerEvents = "none";
|
||||||
|
highlightDiv.style.zIndex = "9999";
|
||||||
|
highlightDiv.style.filter = "blur(5px)";
|
||||||
|
document.body.appendChild(highlightDiv);
|
||||||
|
|
||||||
|
let scale = 1;
|
||||||
|
let increasing = true;
|
||||||
|
|
||||||
|
const blink = () => {
|
||||||
|
if (increasing) {
|
||||||
|
scale += 0.03;
|
||||||
|
if (scale >= 1.3) increasing = false;
|
||||||
|
} else {
|
||||||
|
scale -= 0.03;
|
||||||
|
if (scale <= 0.7) increasing = true;
|
||||||
|
}
|
||||||
|
highlightDiv.style.transform = `scale(${scale})`;
|
||||||
|
};
|
||||||
|
|
||||||
|
const blinkInterval = setInterval(blink, 50);
|
||||||
|
|
||||||
|
const moveHighlight = (e: MouseEvent) => {
|
||||||
|
highlightDiv.style.left = `${e.clientX - 20}px`;
|
||||||
|
highlightDiv.style.top = `${e.clientY - 20}px`;
|
||||||
|
};
|
||||||
|
|
||||||
|
//@ts-ignore
|
||||||
|
document.addEventListener("mousemove", moveHighlight);
|
||||||
|
|
||||||
|
return () => {
|
||||||
|
document.body.style.cursor = cursor;
|
||||||
|
document.body.removeChild(highlightDiv);
|
||||||
|
//@ts-ignore
|
||||||
|
document.removeEventListener("mousemove", moveHighlight);
|
||||||
|
clearInterval(blinkInterval);
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}, [isHighlightingCursor]);
|
||||||
|
|
||||||
const zoomLevel = reactFlowInstance?.getZoom();
|
const zoomLevel = reactFlowInstance?.getZoom();
|
||||||
const shadowBoxWidth = NOTE_NODE_MIN_WIDTH * (zoomLevel || 1);
|
const shadowBoxWidth = NOTE_NODE_MIN_WIDTH * (zoomLevel || 1);
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue