Skip to content

Commit c12d330

Browse files
committed
fix(vite): 🐛 restore admin hover without option key
1 parent b8e5341 commit c12d330

1 file changed

Lines changed: 2 additions & 47 deletions

File tree

vite/src/components/general/AdminHover.tsx

Lines changed: 2 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -1,52 +1,10 @@
11
import { PreviewCard } from "@base-ui/react/preview-card";
22
import { Check, Copy } from "lucide-react";
33
import type React from "react";
4-
import { forwardRef, useState, useSyncExternalStore } from "react";
4+
import { forwardRef, useState } from "react";
55
import { cn } from "@/lib/utils";
66
import { useAdmin } from "@/views/admin/hooks/useAdmin";
77

8-
let isOptionKeyPressed = false;
9-
const optionKeyListeners = new Set<() => void>();
10-
11-
const setOptionKeyPressed = (pressed: boolean) => {
12-
if (pressed === isOptionKeyPressed) return;
13-
isOptionKeyPressed = pressed;
14-
for (const listener of optionKeyListeners) listener();
15-
};
16-
17-
const syncOptionKeyPressed = (event: KeyboardEvent) => {
18-
setOptionKeyPressed(event.altKey);
19-
};
20-
21-
const resetOptionKeyPressed = () => setOptionKeyPressed(false);
22-
23-
const subscribeToOptionKey = (listener: () => void) => {
24-
optionKeyListeners.add(listener);
25-
if (optionKeyListeners.size === 1 && typeof window !== "undefined") {
26-
// Observe modifier state without cancelling or changing keyboard events.
27-
window.addEventListener("keydown", syncOptionKeyPressed);
28-
window.addEventListener("keyup", syncOptionKeyPressed);
29-
window.addEventListener("blur", resetOptionKeyPressed);
30-
}
31-
32-
return () => {
33-
optionKeyListeners.delete(listener);
34-
if (optionKeyListeners.size === 0 && typeof window !== "undefined") {
35-
window.removeEventListener("keydown", syncOptionKeyPressed);
36-
window.removeEventListener("keyup", syncOptionKeyPressed);
37-
window.removeEventListener("blur", resetOptionKeyPressed);
38-
resetOptionKeyPressed();
39-
}
40-
};
41-
};
42-
43-
const useOptionKeyPressed = () =>
44-
useSyncExternalStore(
45-
subscribeToOptionKey,
46-
() => isOptionKeyPressed,
47-
() => false,
48-
);
49-
508
export const AdminHover = forwardRef<
519
HTMLElement,
5210
{
@@ -63,11 +21,8 @@ export const AdminHover = forwardRef<
6321
_ref,
6422
) => {
6523
const { isAdmin, skipHover } = useAdmin();
66-
const optionKeyPressed = useOptionKeyPressed();
6724

68-
if (!isAdmin || hide || skipHover || !optionKeyPressed) {
69-
return <>{children}</>;
70-
}
25+
if (!isAdmin || hide || skipHover) return <>{children}</>;
7126

7227
return (
7328
<PreviewCard.Root>

0 commit comments

Comments
 (0)