mirror of
https://github.com/heygen-com/hyperframes.git
synced 2026-09-10 22:20:14 +00:00
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:
@@ -37,6 +37,13 @@ function isRecord(value: unknown): value is Record<string, unknown> {
|
||||
return typeof value === "object" && value !== null;
|
||||
}
|
||||
|
||||
export function formatFieldsSuffix(rawFields: unknown): string {
|
||||
const fields = Array.isArray(rawFields)
|
||||
? rawFields.filter((f): f is string => typeof f === "string")
|
||||
: [];
|
||||
return fields.length > 0 ? ` (${fields.join(", ")})` : "";
|
||||
}
|
||||
|
||||
export async function readJsonResponseBody(res: Response): Promise<unknown> {
|
||||
const contentType = res.headers.get("content-type") ?? "";
|
||||
if (!contentType.includes("application/json")) {
|
||||
@@ -55,14 +62,10 @@ function formatGsapMutationHttpErrorMessage(statusCode: number, body: unknown):
|
||||
export function formatGsapMutationRejectionToast(error: GsapMutationHttpError): string {
|
||||
const body = error.responseBody;
|
||||
if (isRecord(body)) {
|
||||
const fields = Array.isArray(body.fields)
|
||||
? body.fields.filter((field): field is string => typeof field === "string")
|
||||
: [];
|
||||
const suffix = fields.length > 0 ? ` (${fields.join(", ")})` : "";
|
||||
return `Couldn't save animation: ${formatGsapMutationHttpErrorMessage(
|
||||
error.statusCode,
|
||||
body,
|
||||
)}${suffix}`;
|
||||
)}${formatFieldsSuffix(body.fields)}`;
|
||||
}
|
||||
return `Couldn't save animation: ${error.message}`;
|
||||
}
|
||||
|
||||
@@ -0,0 +1,65 @@
|
||||
import { STUDIO_GSAP_DRAG_INTERCEPT_ENABLED } from "../components/editor/manualEditingAvailability";
|
||||
|
||||
type TimelineLike = { getChildren?: (nested: boolean) => Array<{ targets?: () => Element[] }> };
|
||||
|
||||
let _gsapCachedTimelines: Record<string, TimelineLike> | undefined;
|
||||
let _gsapTargetIds: Set<string> | undefined;
|
||||
let _gsapTargetNodes: WeakSet<Element> | undefined;
|
||||
|
||||
function addTargetsFromTimeline(tl: TimelineLike, ids: Set<string>, nodes: WeakSet<Element>): void {
|
||||
const children = tl.getChildren?.(true);
|
||||
if (!children) return;
|
||||
for (const child of children) {
|
||||
const targets = child.targets?.();
|
||||
if (!targets) continue;
|
||||
for (const t of targets) {
|
||||
nodes.add(t);
|
||||
if (t.id) ids.add(t.id);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function collectGsapTargets(timelines: Record<string, TimelineLike>): {
|
||||
ids: Set<string>;
|
||||
nodes: WeakSet<Element>;
|
||||
} {
|
||||
const ids = new Set<string>();
|
||||
const nodes = new WeakSet<Element>();
|
||||
for (const tl of Object.values(timelines)) {
|
||||
if (!tl) continue;
|
||||
try {
|
||||
addTargetsFromTimeline(tl, ids, nodes);
|
||||
} catch {
|
||||
/* teardown race */
|
||||
}
|
||||
}
|
||||
return { ids, nodes };
|
||||
}
|
||||
|
||||
function readTimelines(iframe: HTMLIFrameElement | null): Record<string, TimelineLike> | undefined {
|
||||
if (!iframe?.contentWindow) return undefined;
|
||||
try {
|
||||
return (iframe.contentWindow as Window & { __timelines?: Record<string, TimelineLike> })
|
||||
.__timelines;
|
||||
} catch {
|
||||
return undefined;
|
||||
}
|
||||
}
|
||||
|
||||
export function isElementGsapTargeted(
|
||||
iframe: HTMLIFrameElement | null,
|
||||
element: HTMLElement,
|
||||
): boolean {
|
||||
if (!STUDIO_GSAP_DRAG_INTERCEPT_ENABLED) return false;
|
||||
const timelines = readTimelines(iframe);
|
||||
if (!timelines) return false;
|
||||
|
||||
if (timelines !== _gsapCachedTimelines) {
|
||||
const cache = collectGsapTargets(timelines);
|
||||
_gsapTargetIds = cache.ids;
|
||||
_gsapTargetNodes = cache.nodes;
|
||||
_gsapCachedTimelines = timelines;
|
||||
}
|
||||
|
||||
return _gsapTargetNodes!.has(element) || !!(element.id && _gsapTargetIds!.has(element.id));
|
||||
}
|
||||
@@ -136,6 +136,7 @@ interface HotkeyCallbacks {
|
||||
onToggleRecording?: () => void;
|
||||
leftSidebarRef: React.RefObject<LeftSidebarHandle | null>;
|
||||
domEditSelectionRef: React.MutableRefObject<DomEditSelection | null>;
|
||||
showToast: (message: string, tone?: "error" | "info") => void;
|
||||
}
|
||||
|
||||
function dispatchModifierKey(event: KeyboardEvent, key: string, cb: HotkeyCallbacks): boolean {
|
||||
@@ -205,6 +206,14 @@ function dispatchPlainKey(event: KeyboardEvent, key: string, cb: HotkeyCallbacks
|
||||
void cb.handleTimelineElementSplit(el, currentTime);
|
||||
return;
|
||||
}
|
||||
// Expanded sub-comp children carry a qualified `sourceFile#id` selection
|
||||
// that isn't in the raw `elements` list, so the s-key can't resolve them.
|
||||
// Nudge toward the razor tool instead of failing silently.
|
||||
if (!el && selectedElementId.includes("#")) {
|
||||
event.preventDefault();
|
||||
cb.showToast("Use the razor tool (B) to split clips inside a sub-composition", "info");
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -376,6 +385,7 @@ export function useAppHotkeys({
|
||||
onToggleRecording,
|
||||
leftSidebarRef,
|
||||
domEditSelectionRef,
|
||||
showToast,
|
||||
};
|
||||
|
||||
// ── Keydown dispatch ──
|
||||
|
||||
@@ -14,6 +14,7 @@ import { useDomEditPositionPatchCommit } from "./useDomEditPositionPatchCommit";
|
||||
import { useDomEditTextCommits } from "./useDomEditTextCommits";
|
||||
import { useDomGeometryCommits } from "./useDomGeometryCommits";
|
||||
import { useElementLifecycleOps } from "./useElementLifecycleOps";
|
||||
import { formatFieldsSuffix } from "./gsapScriptCommitHelpers";
|
||||
|
||||
// ── Helpers ──
|
||||
|
||||
@@ -31,14 +32,7 @@ async function readErrorResponseBody(
|
||||
|
||||
function formatPatchRejectionMessage(body: { error?: string; fields?: string[] } | null): string {
|
||||
if (!body?.error) return "Couldn't save edit";
|
||||
// Pre-existing clone of the GSAP save-error formatter (gsapScriptCommitHelpers);
|
||||
// surfaced here by this PR's adjacent edits, not introduced by it.
|
||||
// fallow-ignore-next-line code-duplication
|
||||
const fields = Array.isArray(body.fields)
|
||||
? body.fields.filter((field): field is string => typeof field === "string")
|
||||
: [];
|
||||
const suffix = fields.length > 0 ? ` (${fields.join(", ")})` : "";
|
||||
return `Couldn't save edit: ${body.error}${suffix}`;
|
||||
return `Couldn't save edit: ${body.error}${formatFieldsSuffix(body.fields)}`;
|
||||
}
|
||||
|
||||
interface RecordEditInput {
|
||||
|
||||
@@ -1,5 +1,4 @@
|
||||
import { useCallback } from "react";
|
||||
import { STUDIO_GSAP_DRAG_INTERCEPT_ENABLED } from "../components/editor/manualEditingAvailability";
|
||||
import { getDomEditTargetKey, type DomEditSelection } from "../components/editor/domEditing";
|
||||
import {
|
||||
applyStudioPathOffset,
|
||||
@@ -19,45 +18,11 @@ import {
|
||||
} from "../components/editor/manualEditsDomPatches";
|
||||
import type { DomEditGroupPathOffsetCommit } from "../components/editor/DomEditOverlay";
|
||||
import type { PatchOperation } from "../utils/sourcePatcher";
|
||||
import { isElementGsapTargeted } from "./gsapTargetCache";
|
||||
|
||||
export const GSAP_CSS_FALLBACK_BLOCKED_MESSAGE =
|
||||
"This element is GSAP-animated — dragging via CSS would corrupt keyframes";
|
||||
|
||||
// ── Helpers ──
|
||||
|
||||
type TimelineLike = { getChildren?: (nested: boolean) => Array<{ targets?: () => Element[] }> };
|
||||
|
||||
// fallow-ignore-next-line complexity
|
||||
function isElementGsapTargeted(iframe: HTMLIFrameElement | null, element: HTMLElement): boolean {
|
||||
// When the GSAP drag intercept is disabled for debugging, treat every
|
||||
// element as un-targeted so commits take the plain CSS persist path.
|
||||
if (!STUDIO_GSAP_DRAG_INTERCEPT_ENABLED) return false;
|
||||
if (!iframe?.contentWindow) return false;
|
||||
let timelines: Record<string, TimelineLike> | undefined;
|
||||
try {
|
||||
timelines = (iframe.contentWindow as Window & { __timelines?: Record<string, TimelineLike> })
|
||||
.__timelines;
|
||||
} catch {
|
||||
return false;
|
||||
}
|
||||
if (!timelines) return false;
|
||||
const id = element.id;
|
||||
for (const tl of Object.values(timelines)) {
|
||||
if (!tl?.getChildren) continue;
|
||||
try {
|
||||
for (const child of tl.getChildren(true)) {
|
||||
if (!child.targets) continue;
|
||||
for (const t of child.targets()) {
|
||||
if (t === element || (id && t.id === id)) return true;
|
||||
}
|
||||
}
|
||||
} catch {
|
||||
continue;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
// ── Hook ──
|
||||
|
||||
interface UseDomGeometryCommitsParams {
|
||||
|
||||
@@ -3,6 +3,7 @@ import type { TimelineElement } from "../player";
|
||||
import { usePlayerStore } from "../player";
|
||||
import { saveProjectFilesWithHistory } from "../utils/studioFileHistory";
|
||||
import { getTimelineElementLabel, collectHtmlIds } from "../utils/studioHelpers";
|
||||
import { trackStudioRazorSplit } from "../telemetry/events";
|
||||
import {
|
||||
canSplitElement,
|
||||
buildPatchTarget,
|
||||
@@ -196,6 +197,7 @@ export function useRazorSplit({
|
||||
});
|
||||
|
||||
reloadPreview();
|
||||
trackStudioRazorSplit({ mode: "single", count: 1 });
|
||||
showToast(`Split ${getTimelineElementLabel(element)} at ${splitTime.toFixed(2)}s`, "info");
|
||||
if (skippedSelectors?.length) {
|
||||
showToast(
|
||||
@@ -277,6 +279,7 @@ export function useRazorSplit({
|
||||
});
|
||||
|
||||
reloadPreview();
|
||||
trackStudioRazorSplit({ mode: "all", count: splitCount });
|
||||
showToast(`Split ${splitCount} clips at ${splitTime.toFixed(2)}s`, "info");
|
||||
} catch (error) {
|
||||
const message = error instanceof Error ? error.message : "Failed to split clips";
|
||||
|
||||
Reference in New Issue
Block a user