mirror of
https://github.com/heygen-com/hyperframes.git
synced 2026-09-12 07:09:59 +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:
@@ -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));
|
||||
}
|
||||
Reference in New Issue
Block a user