fix(webui): treat iPad and hybrid pointers as touch chrome
A mouse on iPad is still a coarse pointer. Use the sheet layout, show the custom cursor only after a real mouse move, and keep theme and wallpaper changes from hanging the page.
This commit is contained in:
12 files changed
+98
-59
No files matched your search
@@ -142,12 +142,9 @@ export function useDropdown({
|
||||
const onDown = (event: PointerEvent) => {
|
||||
if (!rootRef.current?.contains(event.target as Node)) close(false);
|
||||
};
|
||||
const onWindowBlur = () => close(false);
|
||||
document.addEventListener("pointerdown", onDown, true);
|
||||
window.addEventListener("blur", onWindowBlur);
|
||||
return () => {
|
||||
document.removeEventListener("pointerdown", onDown, true);
|
||||
window.removeEventListener("blur", onWindowBlur);
|
||||
};
|
||||
}, [open, close]);
|
||||
|
||||
@@ -344,7 +341,7 @@ export function Dropdown({
|
||||
<ul
|
||||
{...listProps}
|
||||
aria-label={label}
|
||||
className="relative max-h-[216px] overflow-y-auto outline-none [scrollbar-gutter:stable]"
|
||||
className="relative max-h-[216px] overflow-y-auto overscroll-contain outline-none [scrollbar-gutter:stable]"
|
||||
>
|
||||
<motion.span
|
||||
aria-hidden
|
||||
|
||||
@@ -364,7 +364,7 @@ export function WizardSteps({
|
||||
: "rounded-[11px] shadow-sm"
|
||||
}`}
|
||||
>
|
||||
<AnimatePresence initial={false} custom={direction}>
|
||||
<AnimatePresence initial={false} custom={direction} mode="wait">
|
||||
<motion.div
|
||||
key={complete ? "__complete" : step.id}
|
||||
custom={direction}
|
||||
@@ -373,8 +373,7 @@ export function WizardSteps({
|
||||
animate="center"
|
||||
exit="exit"
|
||||
transition={panelTransition}
|
||||
style={{ scrollbarGutter: "stable" }}
|
||||
className={`absolute inset-0 overscroll-contain text-foreground ${
|
||||
className={`absolute inset-0 h-full w-full overscroll-contain text-foreground ${
|
||||
step.scrollMode === "content" ? "overflow-hidden" : "overflow-y-auto"
|
||||
} ${spacious ? "p-4 text-sm leading-relaxed sm:p-5 lg:p-6" : "p-4 text-[13.5px] leading-relaxed"}`}
|
||||
>
|
||||
|
||||
@@ -6,7 +6,7 @@ import { Sheet, SheetContent, SheetDescription, SheetTitle } from '@/components/
|
||||
import { ScrollArea } from '@/components/ui/scroll-area';
|
||||
import { Sidebar } from '@/components/layout/sidebar';
|
||||
import { TopBar } from '@/components/layout/top-bar';
|
||||
import { useMediaQuery } from '@/hooks/use-media-query';
|
||||
import { useFinePointer, useMediaQuery } from '@/hooks/use-media-query';
|
||||
import { useTheme } from '@/contexts/ThemeContext';
|
||||
import { useLayout } from '@/contexts/LayoutContext';
|
||||
import { useKiosk } from '@/contexts/KioskContext';
|
||||
@@ -20,7 +20,9 @@ interface MainLayoutProps {
|
||||
}
|
||||
|
||||
export function MainLayout({ status, onLogout, notice, children }: MainLayoutProps) {
|
||||
const isMobile = !useMediaQuery('(min-width: 768px)');
|
||||
const isWide = useMediaQuery('(min-width: 768px)');
|
||||
const canHover = useFinePointer();
|
||||
const isMobile = !isWide || !canHover;
|
||||
const { appearance } = useTheme();
|
||||
const customBg = appearance.background.type !== 'none';
|
||||
// Framer's reducedMotion only suppresses transforms, so the always-present
|
||||
@@ -46,14 +48,14 @@ export function MainLayout({ status, onLogout, notice, children }: MainLayoutPro
|
||||
const pathname = useRouterState({ select: (s) => s.location.pathname });
|
||||
|
||||
return (
|
||||
<div className={cn('flex h-screen w-screen overflow-hidden text-foreground', customBg ? 'bg-transparent' : 'bg-sidebar')}>
|
||||
<div className={cn('flex h-dvh w-full max-w-full overflow-hidden text-foreground', customBg ? 'bg-transparent' : 'bg-sidebar')}>
|
||||
{/* Desktop sidebar (hidden in kiosk) */}
|
||||
{!isMobile && !kiosk && (
|
||||
<motion.aside
|
||||
initial={false}
|
||||
animate={{ width: showCollapsed ? 64 : 248 }}
|
||||
transition={reduce ? { duration: 0 } : { duration: 0.26, ease: [0.4, 0, 0.1, 1] }}
|
||||
onMouseEnter={() => setHovered(true)}
|
||||
onMouseEnter={() => { if (canHover) setHovered(true); }}
|
||||
onMouseLeave={() => setHovered(false)}
|
||||
onFocusCapture={(e) => {
|
||||
// Only *keyboard* focus (focus-visible) peeks the rail open. A mouse
|
||||
@@ -80,7 +82,7 @@ export function MainLayout({ status, onLogout, notice, children }: MainLayoutPro
|
||||
{/* Mobile sidebar in sheet (hidden in kiosk) */}
|
||||
{isMobile && !kiosk && (
|
||||
<Sheet open={mobileOpen} onOpenChange={setMobileOpen}>
|
||||
<SheetContent side="left" className="w-64 max-w-[80vw] p-0">
|
||||
<SheetContent side="left" showClose={false} className="w-64 max-w-[80vw] p-0 overscroll-contain">
|
||||
{/* Radix Dialog (the Sheet primitive) requires an accessible name +
|
||||
description; the nav itself is the visible content, so these are
|
||||
screen-reader-only. */}
|
||||
@@ -98,7 +100,8 @@ export function MainLayout({ status, onLogout, notice, children }: MainLayoutPro
|
||||
onClick={exitKiosk}
|
||||
title="退出展示模式 (Esc)"
|
||||
aria-label="退出展示模式"
|
||||
className="fixed right-3 top-3 z-50 inline-flex size-9 items-center justify-center rounded-full border bg-background/85 text-foreground opacity-70 backdrop-blur transition-opacity outline-none hover:opacity-100 focus-visible:opacity-100 focus-visible:ring-[3px] focus-visible:ring-ring/40"
|
||||
className="fixed z-50 inline-flex size-9 items-center justify-center rounded-full border bg-background text-foreground opacity-70 transition-opacity outline-none hover:opacity-100 focus-visible:opacity-100 focus-visible:ring-[3px] focus-visible:ring-ring/40"
|
||||
style={{ top: 'max(0.75rem, env(safe-area-inset-top))', right: 'max(0.75rem, env(safe-area-inset-right))' }}
|
||||
>
|
||||
<Minimize2 className="size-4" />
|
||||
</button>
|
||||
|
||||
@@ -51,7 +51,7 @@ export function TopBar({
|
||||
);
|
||||
|
||||
return (
|
||||
<header className="sticky top-0 z-30 flex h-16 shrink-0 items-center gap-[4px] bg-background/55 px-[10px] backdrop-blur-xl backdrop-saturate-150 supports-[backdrop-filter]:bg-background/45 md:gap-2 md:px-4">
|
||||
<header className="z-30 flex min-h-16 shrink-0 items-center gap-[4px] bg-background px-[max(10px,env(safe-area-inset-left))] pr-[max(1rem,env(safe-area-inset-right))] pt-[env(safe-area-inset-top)] md:gap-2 md:px-4">
|
||||
{/* Mobile-only menu trigger. On desktop there's no collapse button — the
|
||||
sidebar auto-expands on hover/focus, and its boundary with the content
|
||||
is a soft surface-tone shift, not a hard border. */}
|
||||
|
||||
@@ -6,8 +6,10 @@ import {
|
||||
useSpring,
|
||||
} from 'motion/react';
|
||||
import { useTheme } from '@/contexts/ThemeContext';
|
||||
import { FINE_POINTER_QUERY } from '@/lib/utils';
|
||||
import { useMediaQuery } from '@/hooks/use-media-query';
|
||||
|
||||
const POINTER_MEDIA = '(hover: hover) and (pointer: fine)';
|
||||
const POINTER_MEDIA = FINE_POINTER_QUERY;
|
||||
const MODE_PROPERTY = '--snowluma-cursor-mode';
|
||||
const RESIZE_MODE_PROPERTY = '--snowluma-cursor-resize-mode';
|
||||
const POINTER_SPRING = { stiffness: 1000, damping: 50 } as const;
|
||||
@@ -41,20 +43,6 @@ interface CursorContext {
|
||||
tracksPointerRegion: boolean;
|
||||
}
|
||||
|
||||
function useMediaQuery(query: string): boolean {
|
||||
const [matches, setMatches] = React.useState(false);
|
||||
|
||||
React.useEffect(() => {
|
||||
const media = window.matchMedia(query);
|
||||
const update = () => setMatches(media.matches);
|
||||
update();
|
||||
media.addEventListener('change', update);
|
||||
return () => media.removeEventListener('change', update);
|
||||
}, [query]);
|
||||
|
||||
return matches;
|
||||
}
|
||||
|
||||
function readCursorMode(element: Element): CursorMode {
|
||||
const value = getComputedStyle(element).getPropertyValue(MODE_PROPERTY).trim();
|
||||
return (CURSOR_MODES as readonly string[]).includes(value)
|
||||
@@ -148,8 +136,18 @@ export function AdaptivePointer() {
|
||||
let targetObserver: ResizeObserver | null = null;
|
||||
|
||||
root.dataset.cursorSystem = 'custom';
|
||||
delete root.dataset.cursorArmed;
|
||||
cursor.dataset.visible = 'false';
|
||||
|
||||
const arm = () => {
|
||||
root.dataset.cursorArmed = '1';
|
||||
cursor.dataset.visible = 'true';
|
||||
};
|
||||
const disarm = () => {
|
||||
delete root.dataset.cursorArmed;
|
||||
cursor.dataset.visible = 'false';
|
||||
};
|
||||
|
||||
const stopObservingTarget = () => {
|
||||
targetObserver?.disconnect();
|
||||
targetObserver = null;
|
||||
@@ -215,7 +213,7 @@ export function AdaptivePointer() {
|
||||
if (event.pointerType === 'touch') return;
|
||||
lastPoint.x = event.clientX;
|
||||
lastPoint.y = event.clientY;
|
||||
cursor.dataset.visible = 'true';
|
||||
arm();
|
||||
if (event.target !== lastEventTarget || context.tracksPointerRegion) refreshContext(event.target);
|
||||
else positionAtPointer();
|
||||
};
|
||||
@@ -224,12 +222,13 @@ export function AdaptivePointer() {
|
||||
if (event.pointerType === 'touch') return;
|
||||
lastPoint.x = event.clientX;
|
||||
lastPoint.y = event.clientY;
|
||||
cursor.dataset.visible = 'true';
|
||||
arm();
|
||||
refreshContext(event.target);
|
||||
};
|
||||
|
||||
const onPointerOut = (event: PointerEvent) => {
|
||||
if (event.relatedTarget === null) cursor.dataset.visible = 'false';
|
||||
if (event.pointerType === 'touch') return;
|
||||
if (event.relatedTarget === null) disarm();
|
||||
};
|
||||
|
||||
const onPointerDown = (event: PointerEvent) => {
|
||||
@@ -251,7 +250,7 @@ export function AdaptivePointer() {
|
||||
};
|
||||
|
||||
const onViewportChange = () => positionTarget();
|
||||
const hide = () => { cursor.dataset.visible = 'false'; };
|
||||
const hide = () => { disarm(); };
|
||||
const onVisibilityChange = () => {
|
||||
if (document.visibilityState !== 'visible') hide();
|
||||
};
|
||||
@@ -272,6 +271,7 @@ export function AdaptivePointer() {
|
||||
return () => {
|
||||
stopObservingTarget();
|
||||
delete root.dataset.cursorSystem;
|
||||
delete root.dataset.cursorArmed;
|
||||
cursor.dataset.visible = 'false';
|
||||
window.removeEventListener('pointermove', onPointerMove);
|
||||
window.removeEventListener('pointerover', onPointerOver);
|
||||
|
||||
@@ -13,6 +13,7 @@ import {
|
||||
} from 'lucide-react';
|
||||
import { ContextMenuSurface } from '@/components/interior/context-menu';
|
||||
import { useTheme } from '@/contexts/ThemeContext';
|
||||
import { FINE_POINTER_QUERY } from '@/lib/utils';
|
||||
|
||||
type TextEditor = HTMLInputElement | HTMLTextAreaElement | HTMLElement;
|
||||
|
||||
@@ -326,7 +327,7 @@ export function GlobalContextMenu() {
|
||||
if (!enabled) return;
|
||||
|
||||
const onContextMenu = (event: MouseEvent) => {
|
||||
if (event.shiftKey || !window.matchMedia('(hover: hover) and (pointer: fine)').matches) return;
|
||||
if (event.shiftKey || !window.matchMedia(FINE_POINTER_QUERY).matches) return;
|
||||
if (!(event.target instanceof Element)) return;
|
||||
if (event.target.closest('[data-context-menu="native"]')) return;
|
||||
if (event.target.closest('.global-context-menu')) {
|
||||
|
||||
@@ -80,12 +80,16 @@ export function Picker({
|
||||
if (!open) return;
|
||||
setScrollTop(0);
|
||||
setActive(0);
|
||||
const t = setTimeout(() => searchRef.current?.focus(), 10);
|
||||
const coarse = window.matchMedia('(pointer: coarse)').matches;
|
||||
const t = coarse ? undefined : setTimeout(() => searchRef.current?.focus(), 10);
|
||||
const onPointer = (e: PointerEvent) => {
|
||||
if (rootRef.current && !rootRef.current.contains(e.target as Node)) setOpen(false);
|
||||
};
|
||||
document.addEventListener('pointerdown', onPointer);
|
||||
return () => { clearTimeout(t); document.removeEventListener('pointerdown', onPointer); };
|
||||
return () => {
|
||||
if (t !== undefined) clearTimeout(t);
|
||||
document.removeEventListener('pointerdown', onPointer);
|
||||
};
|
||||
}, [open]);
|
||||
|
||||
const totalRows = filtered.length + (rawRow ? 1 : 0);
|
||||
@@ -199,7 +203,7 @@ export function Picker({
|
||||
if (listRef.current) listRef.current.scrollTop = 0;
|
||||
}}
|
||||
placeholder="搜索名称 / 号码…"
|
||||
className="min-w-0 flex-1 bg-transparent text-sm outline-none placeholder:text-muted-foreground"
|
||||
className="min-w-0 flex-1 bg-transparent text-base outline-none placeholder:text-muted-foreground md:text-sm"
|
||||
/>
|
||||
{onRefresh && (
|
||||
<button type="button" title="刷新" onClick={onRefresh}
|
||||
|
||||
@@ -18,7 +18,7 @@ const ScrollArea = React.forwardRef<React.ElementRef<typeof ScrollAreaPrimitive.
|
||||
>
|
||||
<ScrollAreaPrimitive.Viewport
|
||||
ref={viewportRef}
|
||||
className={cn('size-full rounded-[inherit] [&>div]:!block', viewportClassName)}
|
||||
className={cn('size-full rounded-[inherit] overscroll-contain [&>div]:!block', viewportClassName)}
|
||||
>
|
||||
{children}
|
||||
</ScrollAreaPrimitive.Viewport>
|
||||
|
||||
@@ -17,7 +17,7 @@ const SheetOverlay = React.forwardRef<
|
||||
<DialogPrimitive.Overlay
|
||||
ref={ref}
|
||||
className={cn(
|
||||
'fixed inset-0 z-50 bg-black/50 backdrop-blur-sm data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0',
|
||||
'fixed inset-0 z-50 bg-black/50 pointer-events-auto data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0',
|
||||
className
|
||||
)}
|
||||
{...props}
|
||||
@@ -32,8 +32,8 @@ const sheetVariants = cva(
|
||||
side: {
|
||||
top: 'inset-x-0 top-0 border-b data-[state=closed]:slide-out-to-top data-[state=open]:slide-in-from-top',
|
||||
bottom: 'inset-x-0 bottom-0 border-t data-[state=closed]:slide-out-to-bottom data-[state=open]:slide-in-from-bottom',
|
||||
left: 'inset-y-0 left-0 h-full w-3/4 max-w-xs border-r data-[state=closed]:slide-out-to-left data-[state=open]:slide-in-from-left sm:max-w-sm',
|
||||
right: 'inset-y-0 right-0 h-full w-3/4 max-w-xs border-l data-[state=closed]:slide-out-to-right data-[state=open]:slide-in-from-right sm:max-w-sm',
|
||||
left: 'inset-y-0 left-0 h-[100dvh] max-h-[100dvh] w-3/4 max-w-xs border-r overscroll-contain pt-[env(safe-area-inset-top)] pb-[env(safe-area-inset-bottom)] pointer-events-auto data-[state=closed]:slide-out-to-left data-[state=open]:slide-in-from-left sm:max-w-sm',
|
||||
right: 'inset-y-0 right-0 h-[100dvh] max-h-[100dvh] w-3/4 max-w-xs border-l overscroll-contain pt-[env(safe-area-inset-top)] pb-[env(safe-area-inset-bottom)] pointer-events-auto data-[state=closed]:slide-out-to-right data-[state=open]:slide-in-from-right sm:max-w-sm',
|
||||
},
|
||||
},
|
||||
defaultVariants: { side: 'right' },
|
||||
|
||||
@@ -110,7 +110,7 @@ export function ScrollableTabList({
|
||||
data-scroll-start={edges.start ? '' : undefined}
|
||||
data-scroll-end={edges.end ? '' : undefined}
|
||||
className={cn(
|
||||
'flex min-w-0 max-w-full overflow-x-auto overscroll-x-contain scroll-px-6 [scrollbar-width:none] [&::-webkit-scrollbar]:hidden',
|
||||
'flex min-w-0 max-w-full overflow-x-auto overscroll-x-contain scroll-px-6 touch-pan-x [scrollbar-width:none] [&::-webkit-scrollbar]:hidden',
|
||||
className,
|
||||
)}
|
||||
{...props}
|
||||
|
||||
Reference in new issue
Block a user