import { useState, useCallback, useEffect, useRef, memo } from "react"; import { formatTime, frameToSeconds } from "../lib/time"; import { Popover, Tooltip } from "../../components/ui"; import { flatActive, flatIdle } from "../../components/timelineToolbarStyles"; import { usePlayerStore } from "../store/playerStore"; import { useCompositionFps } from "../../utils/linkedClipPreferences"; import { matchesKey, useShortcutSections, type ShortcutSection } from "./studioShortcuts"; import { isTypingTarget } from "@hyperframes/core/typing-target"; interface ShortcutsPanelProps { disabled: boolean; duration: number; inPoint: number | null; outPoint: number | null; setInPoint: (v: number | null) => void; setOutPoint: (v: number | null) => void; onSeek: (time: number) => void; sections?: readonly ShortcutSection[]; } /** Stays above its button, shrinking to the room there, rather than flipping down over the timeline. */ const STAY_ABOVE = { side: "none", align: "shift", fallbackAxisSide: "none" } as const; function useShortcutsOpen() { const [open, setOpen] = useState(false); useEffect(() => { const onKeyDown = (e: KeyboardEvent) => { if (e.defaultPrevented || e.repeat || isTypingTarget(e.target)) return; if (!matchesKey(e, "shortcuts")) return; e.preventDefault(); setOpen((wasOpen) => !wasOpen); }; document.addEventListener("keydown", onKeyDown); return () => document.removeEventListener("keydown", onKeyDown); }, []); return [open, setOpen] as const; } export const ShortcutsPanel = memo(function ShortcutsPanel({ disabled, duration, inPoint, outPoint, setInPoint, setOutPoint, onSeek, sections: hostSections, }: ShortcutsPanelProps) { const sections = useShortcutSections(hostSections); const [showShortcuts, setShowShortcuts] = useShortcutsOpen(); const [jumpFrame, setJumpFrame] = useState(""); const compositionFps = useCompositionFps(); // Focus lands on the scrolling body, not the frame input, so keyboard users can scroll and read it. const panelBodyRef = useRef(null); const commitJumpFrame = useCallback(() => { if (disabled) return; const frame = Number.parseInt(jumpFrame, 10); if (!Number.isFinite(frame) || duration <= 0) return; onSeek(Math.min(duration, frameToSeconds(Math.max(0, frame), compositionFps))); }, [compositionFps, disabled, duration, jumpFrame, onSeek]); const handleJumpSubmit = useCallback( (e: React.FormEvent) => { e.preventDefault(); commitJumpFrame(); }, [commitJumpFrame], ); const handleJumpKeyDown = useCallback( (e: React.KeyboardEvent) => { if (e.key !== "Enter") return; e.preventDefault(); commitJumpFrame(); }, [commitJumpFrame], ); return ( } >

Jump to frame

setJumpFrame(e.target.value)} disabled={disabled} inputMode="numeric" pattern="[0-9]*" aria-label="Jump to frame" placeholder="frame number" className="h-6 flex-1 rounded-sm border border-neutral-700 bg-neutral-900 px-2 text-[10px] font-mono tabular-nums text-neutral-200 outline-hidden transition-colors placeholder:text-neutral-600 focus:border-studio-accent/60" onKeyDown={handleJumpKeyDown} onBlur={commitJumpFrame} />

Work area

I In-point
{inPoint !== null ? ( <> {formatTime(inPoint)} ) : ( Not set )}
O Out-point
{outPoint !== null ? ( <> {formatTime(outPoint)} ) : ( Not set )}
{sections.map((section, sectionIndex) => (

{section.title}

{section.hints.map((hint, hintIndex) => (
{hint.key} {hint.label}
))}
))}
); }); export interface ShortcutsButtonProps { sections?: readonly ShortcutSection[]; disabled?: boolean; onSeek?: (time: number) => void; } export function ShortcutsButton({ sections, disabled = false, onSeek }: ShortcutsButtonProps) { const duration = usePlayerStore((s) => s.duration); const inPoint = usePlayerStore((s) => s.inPoint); const outPoint = usePlayerStore((s) => s.outPoint); const { setInPoint, setOutPoint, requestSeek } = usePlayerStore.getState(); return ( ); }