feat(studio): timeline inline expansion + __clipTree runtime primitive

When a child element inside a sub-composition is selected, the timeline
replaces the parent scene clip with the deepest-level siblings. Deselect
or selecting outside collapses back. Expanded clips are fully editable —
move, resize, delete, and split — addressed by their real DOM id with
timeline time rebased onto the sub-comp they live in.

Runtime:
- New window.__clipTree API: a read-only hierarchical ClipNode tree
  (id/parentId/children + backing element) so Studio can derive
  parent/child relationships for inline expansion.

Studio:
- useExpandedTimelineElements derives the expanded view from
  selectedElementId + clipParentMap (pure useMemo, no useEffect).
  Each child rebases onto its immediate sub-comp host (start +
  sourceFile), so multi-level nesting targets the right file.
- NLELayout routes expanded-clip edits through the same handlers
  top-level clips use, in local coordinates — edits save to the
  sub-comp source and reflect via reloadPreview (no separate DOM-patch
  path). This is the canonical update; there is no reactive observer.
- findMatchingTimelineElementId resolves sub-comp children with no
  top-level element to `sourceFile#id`.
- Razor tool enabled by default; studio_razor_split analytics event
  fired on single and split-all.
- O(n²) isElementGsapTargeted extracted to gsapTargetCache.ts with a
  cached Set+WeakSet O(1) lookup.
This commit is contained in:
Miguel Ángel
2026-06-15 22:16:29 -04:00
committed by GitHub
parent 07030294e0
commit 8cbf4384e1
25 changed files with 843 additions and 126 deletions
@@ -1,4 +1,4 @@
import { memo, useEffect, useRef, useState } from "react";
import { memo, useEffect, useMemo, useRef, useState } from "react";
import { Eye, Layers, Move, X } from "../../icons/SystemIcons";
import { useStudioShellContext } from "../../contexts/StudioContext";
import { readStudioBoxSize, readStudioPathOffset, readStudioRotation } from "./manualEdits";
@@ -111,6 +111,29 @@ export const PropertyPanel = memo(function PropertyPanel({
const cacheElementKey = element?.id ?? element?.selector ?? "";
const cacheEntry = usePlayerStore((s) => s.keyframeCache.get(cacheElementKey));
const iframeRef = previewIframeRef ?? { current: null };
const gsapAnimIdForMemo = element
? (gsapAnimations?.find((a: { keyframes?: unknown }) => a.keyframes)?.id ??
gsapAnimations?.[0]?.id ??
null)
: null;
const gsapRuntimeValues = useMemo(
() =>
element
? readGsapRuntimeValuesForPanel(gsapAnimIdForMemo, gsapAnimations, element, iframeRef)
: null,
// eslint-disable-next-line react-hooks/exhaustive-deps -- iframeRef is stable; currentTime drives re-reads during playback
[gsapAnimIdForMemo, gsapAnimations, element, currentTime],
);
const gsapBorderRadius = useMemo(
() =>
element
? readGsapBorderRadiusForPanel(gsapRuntimeValues, gsapAnimations, element, iframeRef)
: null,
// eslint-disable-next-line react-hooks/exhaustive-deps
[gsapRuntimeValues, gsapAnimations, element, currentTime],
);
if (!element) {
return (
<div className="flex h-full flex-col bg-neutral-900">
@@ -194,21 +217,6 @@ export const PropertyPanel = memo(function PropertyPanel({
return gsapAnimId ?? "";
};
// Read ALL GSAP-interpolated values at the current seek time.
const gsapRuntimeValues = readGsapRuntimeValuesForPanel(
gsapAnimId,
gsapAnimations,
element,
previewIframeRef ?? { current: null },
);
const gsapBorderRadius = readGsapBorderRadiusForPanel(
gsapRuntimeValues,
gsapAnimations,
element,
previewIframeRef ?? { current: null },
);
const displayX = gsapRuntimeValues?.x ?? manualOffset.x;
const displayY = gsapRuntimeValues?.y ?? manualOffset.y;
const displayW = gsapRuntimeValues?.width ?? resolvedWidth;
@@ -73,7 +73,7 @@ export const STUDIO_KEYFRAMES_ENABLED = resolveStudioBooleanEnvFlag(
export const STUDIO_RAZOR_TOOL_ENABLED = resolveStudioBooleanEnvFlag(
env,
["VITE_STUDIO_ENABLE_RAZOR_TOOL", "VITE_STUDIO_RAZOR_TOOL_ENABLED"],
false,
true,
);
// When disabled (the default), drag/resize/rotate commits always take the CSS
@@ -10,10 +10,13 @@ import {
import { useMountEffect } from "../../hooks/useMountEffect";
import { useTimelinePlayer, PlayerControls, Timeline, usePlayerStore } from "../../player";
import type { TimelineElement } from "../../player";
import type { BlockedTimelineEditIntent } from "../../player/components/timelineEditing";
import { NLEPreview } from "./NLEPreview";
import { CompositionBreadcrumb } from "./CompositionBreadcrumb";
import { usePreviewBlockDrop } from "./usePreviewBlockDrop";
import { useCompositionStack } from "./useCompositionStack";
import { useTimelineEditContext } from "../../contexts/TimelineEditContext";
import { trackStudioExpandedClipEdit } from "../../telemetry/events";
import {
TIMELINE_TOGGLE_SHORTCUT_LABEL,
getTimelineToggleTitle,
@@ -58,6 +61,7 @@ interface NLELayoutProps {
blockName: string,
position: { left: number; top: number },
) => Promise<void> | void;
onBlockedEditAttempt?: (element: TimelineElement, intent: BlockedTimelineEditIntent) => void;
onSelectTimelineElement?: (element: TimelineElement | null) => void;
/** Exposes the compIdToSrc map for parent components (e.g., useRenderClipContent) */
onCompIdToSrcChange?: (map: Map<string, string>) => void;
@@ -103,6 +107,7 @@ export const NLELayout = memo(function NLELayout({
onAssetDrop,
onBlockDrop,
onPreviewBlockDrop,
onBlockedEditAttempt,
onSelectTimelineElement,
onCompIdToSrcChange,
timelineVisible,
@@ -175,6 +180,7 @@ export const NLELayout = memo(function NLELayout({
const handleDrillDown = useCallback(
(element: TimelineElement) => {
if (!element.compositionSrc) return;
usePlayerStore.getState().setSelectedElementId(null);
// Check compIdToSrc map first; then scan iframe DOM; then fall through to drillDown
const compId = element.id;
let resolvedPath = compIdToSrc.get(compId);
@@ -202,6 +208,73 @@ export const NLELayout = memo(function NLELayout({
[compIdToSrc, drillDown, iframeRef_],
);
// Move/resize/split come from the timeline edit context, not props — the
// wrappers below intercept expanded clips and must call the *real* handlers.
// (Delete is a direct prop; it stays that way.)
const { onMoveElement, onResizeElement, onSplitElement } = useTimelineEditContext();
// An expanded sub-comp child reaches the normal edit handlers in its own
// local coordinates: addressed by its real DOM id, with timeline time rebased
// onto the sub-comp it lives in. The handlers then save + reloadPreview exactly
// as they do for top-level clips — no separate live-DOM path.
const toLocalElement = useCallback(
(element: TimelineElement, basis: number): TimelineElement => ({
...element,
id: element.domId ?? element.id,
start: element.start - basis,
}),
[],
);
const handleMoveElement = useCallback(
(element: TimelineElement, updates: Pick<TimelineElement, "start" | "track">) => {
const basis = element.expandedParentStart;
if (basis === undefined) return onMoveElement?.(element, updates);
trackStudioExpandedClipEdit({ action: "move" });
onMoveElement?.(toLocalElement(element, basis), {
...updates,
start: Math.max(0, updates.start - basis),
});
},
[onMoveElement, toLocalElement],
);
const handleResizeElement = useCallback(
(
element: TimelineElement,
updates: Pick<TimelineElement, "start" | "duration" | "playbackStart">,
) => {
const basis = element.expandedParentStart;
if (basis === undefined) return onResizeElement?.(element, updates);
trackStudioExpandedClipEdit({ action: "resize" });
onResizeElement?.(toLocalElement(element, basis), {
...updates,
start: Math.max(0, updates.start - basis),
});
},
[onResizeElement, toLocalElement],
);
const handleDeleteElement = useCallback(
(element: TimelineElement) => {
const basis = element.expandedParentStart;
if (basis === undefined) return onDeleteElement?.(element);
trackStudioExpandedClipEdit({ action: "delete" });
return onDeleteElement?.(toLocalElement(element, basis));
},
[onDeleteElement, toLocalElement],
);
const handleSplitElement = useCallback(
(element: TimelineElement, splitTime: number) => {
const basis = element.expandedParentStart;
if (basis === undefined) return onSplitElement?.(element, splitTime);
trackStudioExpandedClipEdit({ action: "split" });
return onSplitElement?.(toLocalElement(element, basis), Math.max(0, splitTime - basis));
},
[onSplitElement, toLocalElement],
);
// Composition ID → file path map from raw index.html
const compIdToSrcRef = useRef(compIdToSrc);
compIdToSrcRef.current = compIdToSrc;
@@ -356,6 +429,17 @@ export const NLELayout = memo(function NLELayout({
<div
className="flex-1 min-h-0 relative"
data-preview-pan-surface="true"
onPointerDown={(e) => {
const el = iframeRef.current?.parentElement ?? iframeRef.current;
if (!el) return;
const rect = el.getBoundingClientRect();
const inside =
e.clientX >= rect.left &&
e.clientX <= rect.right &&
e.clientY >= rect.top &&
e.clientY <= rect.bottom;
if (!inside) onSelectTimelineElement?.(null);
}}
onDragOver={handlePreviewDragOver}
onDragLeave={handlePreviewDragLeave}
onDrop={handlePreviewDrop}
@@ -429,9 +513,13 @@ export const NLELayout = memo(function NLELayout({
onDrillDown={handleDrillDown}
renderClipContent={renderClipContent}
onFileDrop={onFileDrop}
onDeleteElement={onDeleteElement}
onDeleteElement={handleDeleteElement}
onAssetDrop={onAssetDrop}
onBlockDrop={onBlockDrop}
onMoveElement={handleMoveElement}
onResizeElement={handleResizeElement}
onBlockedEditAttempt={onBlockedEditAttempt}
onSplitElement={handleSplitElement}
onSelectElement={onSelectTimelineElement}
/>
</div>