diff --git a/packages/studio/src/player/components/TimelineCanvas.tsx b/packages/studio/src/player/components/TimelineCanvas.tsx
index add029101f..1189c5a9c7 100644
--- a/packages/studio/src/player/components/TimelineCanvas.tsx
+++ b/packages/studio/src/player/components/TimelineCanvas.tsx
@@ -12,7 +12,6 @@ import {
getTimelineRowTop,
getTimelineRowHeight,
} from "./timelineLayout";
-import { usePlayerStore } from "../store/playerStore";
import { type MultiDragPreviewInput } from "./timelineMultiDragPreview";
import { useTimelineEditContextOptional } from "../../contexts/TimelineEditContext";
import { TimelineLanes } from "./TimelineLanes";
@@ -25,7 +24,7 @@ import { useTimelineContext } from "./TimelineProvider";
const DROP_PREVIEW_SECONDS = 3;
export const TimelineCanvas = memo(function TimelineCanvas() {
- const { state } = useTimelineContext();
+ const { state, actions } = useTimelineContext();
const props = state.canvas;
const { draggedClip, resizingClip, scrollRef, selectedElementIds, displayTrackOrder } = props;
const snapGuide = resolveSnapGuide(draggedClip, resizingClip);
@@ -52,7 +51,7 @@ export const TimelineCanvas = memo(function TimelineCanvas() {
onRazorSplit,
onRazorSplitAll,
} = useTimelineEditContextOptional();
- const beatDragging = usePlayerStore((s) => s.beatDragging);
+ const beatDragging = props.beatDragging;
const draggedElement = draggedClip?.element ?? null;
const draggedElementIdentity = draggedElement ? getTimelineElementIdentity(draggedElement) : null;
// The drag ghost follows the cursor freely (both axes) — CapCut-style. The
@@ -100,6 +99,8 @@ export const TimelineCanvas = memo(function TimelineCanvas() {
{/* Marquee (rubber-band) multi-select rectangle — mirrors the canvas
diff --git a/packages/studio/src/player/components/TimelineOverlays.test.ts b/packages/studio/src/player/components/TimelineOverlays.test.ts
index b214b91bb7..583f69b04b 100644
--- a/packages/studio/src/player/components/TimelineOverlays.test.ts
+++ b/packages/studio/src/player/components/TimelineOverlays.test.ts
@@ -125,24 +125,42 @@ function renderKeyframeOverlay(options: {
state: {
timelineReady: true,
elements,
+ selectedElementId: null,
+ sessionEpoch: 0,
+ keyframeCache: new Map(),
canvas: {} as TimelineContextValue["state"]["canvas"],
overlays,
},
- actions: {},
+ actions: {
+ renderClipContent: undefined,
+ renderClipOverlay: undefined,
+ setFocusedEaseSegment: vi.fn(),
+ },
meta: {} as TimelineContextValue["meta"],
} satisfies TimelineContextValue;
+ function TestTimelineContext({ value }: { value: TimelineContextValue }) {
+ const selectedElementId = usePlayerStore((state) => state.selectedElementId);
+ const sessionEpoch = usePlayerStore((state) => state.timelineSessionEpoch);
+ return createElement(
+ TimelineContextProvider,
+ {
+ value: {
+ ...value,
+ state: { ...value.state, selectedElementId, sessionEpoch },
+ },
+ },
+ createElement(TimelineOverlays),
+ );
+ }
+
act(() => {
usePlayerStore.setState({
selectedElementId: options.capturedElement.key ?? options.capturedElement.id,
timelineSessionEpoch: 2,
});
root.render(
- createElement(
- TimelineContextProvider,
- { value: contextValue },
- createElement(TimelineOverlays),
- ),
+ createElement(TestTimelineContext, { value: contextValue }, createElement(TimelineOverlays)),
);
});
return { setKfContextMenu, onDeleteAllKeyframes };
diff --git a/packages/studio/src/player/components/TimelineOverlays.tsx b/packages/studio/src/player/components/TimelineOverlays.tsx
index 131e7b3527..85262f7c01 100644
--- a/packages/studio/src/player/components/TimelineOverlays.tsx
+++ b/packages/studio/src/player/components/TimelineOverlays.tsx
@@ -1,18 +1,13 @@
import { useEffect } from "react";
import type { TimelineElement } from "../store/playerStore";
-import { usePlayerStore } from "../store/playerStore";
import { EditPopover } from "./EditModal";
-import {
- KeyframeDiamondContextMenu,
- type KeyframeDiamondContextMenuState,
-} from "./KeyframeDiamondContextMenu";
+import { KeyframeDiamondContextMenu } from "./KeyframeDiamondContextMenu";
import { ClipContextMenu } from "./ClipContextMenu";
import { TrackGapContextMenu } from "./TrackGapContextMenu";
import { TimelineShortcutHint } from "./TimelineShortcutHint";
import { copyTextToClipboard } from "../../utils/clipboard";
import { trackStudioSegmentEaseEdit } from "../../telemetry/events";
import { useTimelineContext } from "./TimelineProvider";
-import type { ClipContextMenuState } from "./TimelineProvider";
interface TimelineContextTargetInput {
capturedElement: TimelineElement;
@@ -36,26 +31,11 @@ export function resolveTimelineContextElement({
return elements.find((element) => (element.key ?? element.id) === identity) ?? null;
}
-function readTimelineContextElement(
- capturedElement: TimelineElement,
- targetSessionEpoch: number | undefined,
- elements: readonly TimelineElement[],
-): TimelineElement | null {
- const state = usePlayerStore.getState();
- return resolveTimelineContextElement({
- capturedElement,
- targetSessionEpoch,
- sessionEpoch: state.timelineSessionEpoch,
- selectedElementId: state.selectedElementId,
- elements,
- });
-}
-
// The timeline's floating overlays, rendered as siblings above the scroll area:
// the shortcut hint, the range-edit popover, the keyframe-diamond context menu,
// and the clip context menu.
export function TimelineOverlays() {
- const { state } = useTimelineContext();
+ const { state, actions } = useTimelineContext();
const overlayProps = state.overlays;
const {
elements,
@@ -87,8 +67,7 @@ export function TimelineOverlays() {
onCloseAllTrackGaps,
onHoverGapAction,
} = overlayProps;
- const selectedElementId = usePlayerStore((state) => state.selectedElementId);
- const sessionEpoch = usePlayerStore((state) => state.timelineSessionEpoch);
+ const { selectedElementId, sessionEpoch, keyframeCache } = state;
const kfTargetSessionEpoch = kfContextMenu?.sessionEpoch;
const clipTargetSessionEpoch = clipContextMenu?.sessionEpoch;
const keyframeElement = kfContextMenu
@@ -110,7 +89,13 @@ export function TimelineOverlays() {
})
: null;
const readCurrentElement = (element: TimelineElement, targetSessionEpoch: number | undefined) =>
- readTimelineContextElement(element, targetSessionEpoch, elementsRef.current);
+ resolveTimelineContextElement({
+ capturedElement: element,
+ targetSessionEpoch,
+ sessionEpoch,
+ selectedElementId,
+ elements: elementsRef.current,
+ });
useEffect(() => {
if (kfContextMenu && !keyframeElement) setKfContextMenu(null);
@@ -171,7 +156,7 @@ export function TimelineOverlays() {
) {
return;
}
- usePlayerStore.getState().setFocusedEaseSegment({
+ actions.setFocusedEaseSegment({
animationId: keyframe.animationId,
collidingAnimationTargets: keyframe.collidingAnimationTargets,
tweenPercentage: keyframe.tweenPercentage,
@@ -182,7 +167,7 @@ export function TimelineOverlays() {
: undefined
}
onCopyProperties={(elementId, keyframe) => {
- const entry = usePlayerStore.getState().keyframeCache.get(elementId);
+ const entry = keyframeCache.get(elementId);
// Tolerance match on clip-%, the same basis the cache is keyed on —
// an exact float compare misses a keyframe the menu just opened over.
const kf = entry?.keyframes.find(
diff --git a/packages/studio/src/player/components/TimelineProvider.tsx b/packages/studio/src/player/components/TimelineProvider.tsx
index 5c85678f5d..087dd92176 100644
--- a/packages/studio/src/player/components/TimelineProvider.tsx
+++ b/packages/studio/src/player/components/TimelineProvider.tsx
@@ -18,6 +18,8 @@ import type { ResizingClipState } from "./useTimelineClipDrag";
import type { TimelineLaneBaseProps } from "./timelineLaneProps";
import type { TimelineLaneGapStrips } from "./useTimelineGapHighlights";
import type { TimelineElement } from "../store/playerStore";
+import type { KeyframeCacheEntry } from "../store/keyframeSlice";
+import type { AnimationKeyframeTarget } from "../../hooks/gsapTweenSynth";
import type { TimelineTheme } from "./timelineTheme";
import type { TimelineEditCallbacks } from "./timelineCallbacks";
import type { KeyframeDiamondContextMenuState } from "./KeyframeDiamondContextMenu";
@@ -43,7 +45,11 @@ export {
export type TimelineCanvasState = Omit<
TimelineLaneBaseProps,
- "setRangeSelection" | "setResizingClip" | "setDraggedClip"
+ | "setRangeSelection"
+ | "setResizingClip"
+ | "setDraggedClip"
+ | "renderClipContent"
+ | "renderClipOverlay"
> & {
major: number[];
minor: number[];
@@ -60,6 +66,7 @@ export type TimelineCanvasState = Omit<
setRangeSelection: (value: TimelineRangeSelection | null) => void;
setResizingClip: (value: ResizingClipState | null) => void;
setDraggedClip: (value: TimelineLaneBaseProps["draggedClip"]) => void;
+ beatDragging: boolean;
};
export interface ClipContextMenuState {
@@ -141,15 +148,25 @@ export interface TimelineViewportProps {
export interface TimelineState {
timelineReady: boolean;
elements: readonly TimelineElement[];
+ selectedElementId: string | null;
+ sessionEpoch: number;
+ keyframeCache: Map;
canvas: TimelineCanvasState;
overlays: TimelineOverlaysState;
}
-export interface TimelineActions {}
+export interface TimelineActions {
+ renderClipContent: TimelineLaneBaseProps["renderClipContent"];
+ renderClipOverlay: TimelineLaneBaseProps["renderClipOverlay"];
+ setFocusedEaseSegment: (target: {
+ animationId: string;
+ collidingAnimationTargets?: AnimationKeyframeTarget[];
+ tweenPercentage: number;
+ elementId: string;
+ }) => void;
+}
export interface TimelineMeta {
- renderClipContent: TimelineCanvasState["renderClipContent"];
- renderClipOverlay: TimelineCanvasState["renderClipOverlay"];
emptyState: ComponentProps;
containerProps: TimelineContainerProps;
viewportProps: TimelineViewportProps;
diff --git a/packages/studio/src/player/components/useTimelineProviderState.tsx b/packages/studio/src/player/components/useTimelineProviderState.tsx
index c74bc9a6fb..089a77096b 100644
--- a/packages/studio/src/player/components/useTimelineProviderState.tsx
+++ b/packages/studio/src/player/components/useTimelineProviderState.tsx
@@ -110,6 +110,9 @@ export function useTimelineProviderState({
const contentGutter = labelMode ? GUTTER : 0;
const setSelectedElementId = usePlayerStore((s) => s.setSelectedElementId);
const currentTime = usePlayerStore((s) => s.currentTime);
+ const beatDragging = usePlayerStore((s) => s.beatDragging);
+ const timelineSessionEpoch = usePlayerStore((s) => s.timelineSessionEpoch);
+ const setFocusedEaseSegment = usePlayerStore((s) => s.setFocusedEaseSegment);
const { zoomMode, manualZoomPercent, setZoomMode, setManualZoomPercent } = useTimelineZoom();
const playheadRef = useRef(null);
const containerRef = useRef(null);
@@ -452,9 +455,6 @@ export function useTimelineProviderState({
blockedClipRef,
suppressClickRef,
scrollRef,
- renderClipContent:
- timelineFocus.rowVirtualizationActive && viewport.isScrolling ? undefined : renderClipContent,
- renderClipOverlay,
playheadRef,
onDrillDown,
onSelectElement,
@@ -486,6 +486,7 @@ export function useTimelineProviderState({
},
onResizeElement,
onMoveElement,
+ beatDragging,
};
const overlaysProps = {
elements: timelineElements,
@@ -517,17 +518,24 @@ export function useTimelineProviderState({
onCloseAllTrackGaps: closeAllTrackGaps,
onHoverGapAction: setHoveredGapAction,
};
+ const timelineRenderClipContent =
+ timelineFocus.rowVirtualizationActive && viewport.isScrolling ? undefined : renderClipContent;
const contextValue: TimelineContextValue = {
state: {
timelineReady,
elements: timelineElements,
+ selectedElementId,
+ sessionEpoch: timelineSessionEpoch,
+ keyframeCache,
canvas: canvasProps,
overlays: overlaysProps,
},
- actions: {},
- meta: {
- renderClipContent,
+ actions: {
+ renderClipContent: timelineRenderClipContent,
renderClipOverlay,
+ setFocusedEaseSegment,
+ },
+ meta: {
emptyState: {
isDragOver: assetDrop.isDragOver,
onFileDrop: !!onFileDrop,