mirror of
https://github.com/heygen-com/hyperframes.git
synced 2026-11-24 16:06:34 +00:00
feat(studio): expose composable timeline parts
This commit is contained in:
@@ -60,6 +60,22 @@ export type {
|
||||
TimelineElement,
|
||||
TimelineTimeRange,
|
||||
} from "./player";
|
||||
export {
|
||||
TimelineFrame,
|
||||
TimelineLanes,
|
||||
TimelineOverlays,
|
||||
TimelinePlayhead,
|
||||
TimelineRazorGuide,
|
||||
TimelineRuler,
|
||||
TimelineEmptyStatePart,
|
||||
TimelineEditPopover,
|
||||
TimelineClipMenu,
|
||||
TimelineGapMenu,
|
||||
TimelineKeyframeMenu,
|
||||
TimelineShortcutHint,
|
||||
} from "./player/components/TimelineParts";
|
||||
export { TimelineProvider, useTimelineContext } from "./player/components/TimelineProvider";
|
||||
export type { TimelineTheme } from "./player/components/timelineTheme";
|
||||
|
||||
// Host overlays: draw over the preview in composition coordinates (see EditorShellProps.gestureOverlay)
|
||||
export { usePreviewCompositionRect } from "./components/editor/usePreviewCompositionRect";
|
||||
|
||||
@@ -1,9 +1,20 @@
|
||||
import { memo } from "react";
|
||||
import type { TimelineProps } from "./TimelineTypes";
|
||||
import { TimelineEmptyState } from "./TimelineEmptyState";
|
||||
import { TimelineCanvas } from "./TimelineCanvas";
|
||||
import { TimelineOverlays } from "./TimelineOverlays";
|
||||
import { TimelineProvider, useTimelineContext } from "./TimelineProvider";
|
||||
import {
|
||||
TimelineEmptyStatePart,
|
||||
TimelineEditPopover,
|
||||
TimelineClipMenu,
|
||||
TimelineFrame,
|
||||
TimelineGapMenu,
|
||||
TimelineKeyframeMenu,
|
||||
TimelineLanes,
|
||||
TimelineOverlaysPart,
|
||||
TimelinePlayhead,
|
||||
TimelineRazorGuide,
|
||||
TimelineRuler,
|
||||
TimelineShortcutHint,
|
||||
} from "./TimelineParts";
|
||||
|
||||
export * from "./TimelineProvider";
|
||||
export {
|
||||
@@ -28,23 +39,39 @@ function TimelineView() {
|
||||
const { state, meta } = useTimelineContext();
|
||||
const { timelineReady, elements } = state;
|
||||
if (!timelineReady || elements.length === 0) {
|
||||
return <TimelineEmptyState {...meta.emptyState} />;
|
||||
return <TimelineEmptyStatePart />;
|
||||
}
|
||||
return (
|
||||
<div {...meta.containerProps}>
|
||||
<div {...meta.viewportProps}>
|
||||
<TimelineCanvas />
|
||||
{meta.razorGuide}
|
||||
<TimelineFrame />
|
||||
<TimelineRazorGuide />
|
||||
</div>
|
||||
<TimelineOverlays />
|
||||
<TimelineOverlaysPart />
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
export const Timeline = memo(function Timeline(props: TimelineProps = {}) {
|
||||
const TimelineComposed = memo(function TimelineComposed(props: TimelineProps = {}) {
|
||||
return (
|
||||
<TimelineProvider {...props}>
|
||||
<TimelineView />
|
||||
</TimelineProvider>
|
||||
);
|
||||
});
|
||||
|
||||
export const Timeline = Object.assign(TimelineComposed, {
|
||||
Provider: TimelineProvider,
|
||||
Frame: TimelineFrame,
|
||||
Ruler: TimelineRuler,
|
||||
Lanes: TimelineLanes,
|
||||
Playhead: TimelinePlayhead,
|
||||
RazorGuide: TimelineRazorGuide,
|
||||
ShortcutHint: TimelineShortcutHint,
|
||||
EditPopover: TimelineEditPopover,
|
||||
ClipMenu: TimelineClipMenu,
|
||||
KeyframeMenu: TimelineKeyframeMenu,
|
||||
GapMenu: TimelineGapMenu,
|
||||
EmptyState: TimelineEmptyStatePart,
|
||||
Overlays: TimelineOverlaysPart,
|
||||
});
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import { memo } from "react";
|
||||
import { TimelineRuler } from "./TimelineRuler";
|
||||
import { TimelineRulerPart } from "./TimelineRulerPart";
|
||||
import { PlayheadIndicator } from "./PlayheadIndicator";
|
||||
import {
|
||||
RULER_H,
|
||||
@@ -79,19 +79,7 @@ export const TimelineCanvas = memo(function TimelineCanvas() {
|
||||
className="relative"
|
||||
style={{ height: props.totalH, width: props.contentOrigin + props.trackContentWidth }}
|
||||
>
|
||||
<TimelineRuler
|
||||
major={props.major}
|
||||
minor={props.minor}
|
||||
pps={props.pps}
|
||||
trackContentWidth={props.trackContentWidth}
|
||||
totalH={props.totalH}
|
||||
effectiveDuration={props.effectiveDuration}
|
||||
majorTickInterval={props.majorTickInterval}
|
||||
theme={props.theme}
|
||||
beatAnalysis={props.beatAnalysis}
|
||||
contentOrigin={props.contentOrigin}
|
||||
renderTimeRange={props.rowsVirtualized ? props.renderTimeRange : undefined}
|
||||
/>
|
||||
<TimelineRulerPart />
|
||||
|
||||
{/* Breathing room between the sticky ruler and the first track lane — the
|
||||
top half of the CapCut-style padding (see TRACKS_TOP_PAD). */}
|
||||
|
||||
@@ -34,7 +34,12 @@ export function resolveTimelineContextElement({
|
||||
// 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() {
|
||||
export type TimelineOverlayPart = "all" | "shortcut" | "edit" | "clip" | "keyframe" | "gap";
|
||||
|
||||
// The composed overlay keeps target validation and action routing in one owner.
|
||||
// fallow-ignore-next-line complexity
|
||||
// fallow-ignore-next-line unit-size
|
||||
export function TimelineOverlays({ part = "all" }: { part?: TimelineOverlayPart } = {}) {
|
||||
const { state, actions } = useTimelineContext();
|
||||
const overlayProps = state.overlays;
|
||||
const {
|
||||
@@ -105,13 +110,16 @@ export function TimelineOverlays() {
|
||||
if (clipContextMenu && !clipElement) setClipContextMenu(null);
|
||||
}, [clipContextMenu, clipElement, setClipContextMenu]);
|
||||
|
||||
const includes = (candidate: Exclude<TimelineOverlayPart, "all">) =>
|
||||
part === "all" || part === candidate;
|
||||
|
||||
return (
|
||||
<>
|
||||
{showShortcutHint && !showPopover && !rangeSelection && (
|
||||
{includes("shortcut") && showShortcutHint && !showPopover && !rangeSelection && (
|
||||
<TimelineShortcutHint theme={theme} />
|
||||
)}
|
||||
|
||||
{showPopover && rangeSelection && (
|
||||
{includes("edit") && showPopover && rangeSelection && (
|
||||
<EditPopover
|
||||
rangeStart={rangeSelection.start}
|
||||
rangeEnd={rangeSelection.end}
|
||||
@@ -124,7 +132,7 @@ export function TimelineOverlays() {
|
||||
/>
|
||||
)}
|
||||
|
||||
{kfContextMenu && keyframeElement && (
|
||||
{includes("keyframe") && kfContextMenu && keyframeElement && (
|
||||
<KeyframeDiamondContextMenu
|
||||
state={{ ...kfContextMenu, element: keyframeElement }}
|
||||
onClose={() => setKfContextMenu(null)}
|
||||
@@ -179,7 +187,7 @@ export function TimelineOverlays() {
|
||||
/>
|
||||
)}
|
||||
|
||||
{clipContextMenu && clipElement && (
|
||||
{includes("clip") && clipContextMenu && clipElement && (
|
||||
<ClipContextMenu
|
||||
x={clipContextMenu.x}
|
||||
y={clipContextMenu.y}
|
||||
@@ -203,7 +211,7 @@ export function TimelineOverlays() {
|
||||
/>
|
||||
)}
|
||||
|
||||
{gapContextMenu && (
|
||||
{includes("gap") && gapContextMenu && (
|
||||
<TrackGapContextMenu
|
||||
x={gapContextMenu.x}
|
||||
y={gapContextMenu.y}
|
||||
|
||||
@@ -0,0 +1,72 @@
|
||||
import { memo } from "react";
|
||||
import { TimelineCanvas as TimelineCanvasImpl } from "./TimelineCanvas";
|
||||
import { TimelineOverlays as TimelineOverlaysImpl } from "./TimelineOverlays";
|
||||
import { TimelineLanes as TimelineLanesImpl } from "./TimelineLanes";
|
||||
import { PlayheadIndicator } from "./PlayheadIndicator";
|
||||
import { useTimelineContext } from "./TimelineProvider";
|
||||
import { TimelineEmptyState } from "./TimelineEmptyState";
|
||||
import { TimelineRulerPart } from "./TimelineRulerPart";
|
||||
|
||||
/** The provider-backed canvas shell. */
|
||||
export const TimelineFrame = memo(function TimelineFrame() {
|
||||
return <TimelineCanvasImpl />;
|
||||
});
|
||||
|
||||
/** The provider-backed ruler. */
|
||||
export const TimelineRuler = TimelineRulerPart;
|
||||
|
||||
/**
|
||||
* The provider-backed lane renderer. TimelineFrame remains the composed Studio
|
||||
* canvas; this part is exported for hosts that own the canvas arrangement.
|
||||
*/
|
||||
export const TimelineLanes = memo(function TimelineLanes() {
|
||||
const { state, actions } = useTimelineContext();
|
||||
const props = state.canvas;
|
||||
const laneProps = props as unknown as Parameters<typeof TimelineLanesImpl>[0];
|
||||
return (
|
||||
<TimelineLanesImpl
|
||||
{...laneProps}
|
||||
renderClipContent={actions.renderClipContent}
|
||||
renderClipOverlay={actions.renderClipOverlay}
|
||||
/>
|
||||
);
|
||||
});
|
||||
|
||||
/** The provider-backed playhead indicator. */
|
||||
export const TimelinePlayhead = memo(function TimelinePlayhead() {
|
||||
const { state } = useTimelineContext();
|
||||
const props = state.canvas;
|
||||
return <PlayheadIndicator scrubbing={props.isScrubbing} />;
|
||||
});
|
||||
|
||||
/** The provider-backed razor guide. */
|
||||
export const TimelineRazorGuide = memo(function TimelineRazorGuide() {
|
||||
const { meta } = useTimelineContext();
|
||||
return meta.razorGuide;
|
||||
});
|
||||
|
||||
/** The composed overlay surface used by the Studio variant. */
|
||||
export const TimelineOverlaysPart = memo(function TimelineOverlaysPart() {
|
||||
return <TimelineOverlaysImpl />;
|
||||
});
|
||||
|
||||
export const TimelineEmptyStatePart = memo(function TimelineEmptyStatePart() {
|
||||
const { meta } = useTimelineContext();
|
||||
return <TimelineEmptyState {...meta.emptyState} />;
|
||||
});
|
||||
|
||||
export const TimelineShortcutHint = memo(function TimelineShortcutHint() {
|
||||
return <TimelineOverlaysImpl part="shortcut" />;
|
||||
});
|
||||
export const TimelineEditPopover = memo(function TimelineEditPopover() {
|
||||
return <TimelineOverlaysImpl part="edit" />;
|
||||
});
|
||||
export const TimelineClipMenu = memo(function TimelineClipMenu() {
|
||||
return <TimelineOverlaysImpl part="clip" />;
|
||||
});
|
||||
export const TimelineKeyframeMenu = memo(function TimelineKeyframeMenu() {
|
||||
return <TimelineOverlaysImpl part="keyframe" />;
|
||||
});
|
||||
export const TimelineGapMenu = memo(function TimelineGapMenu() {
|
||||
return <TimelineOverlaysImpl part="gap" />;
|
||||
});
|
||||
@@ -0,0 +1,23 @@
|
||||
import { memo } from "react";
|
||||
import { TimelineRuler as TimelineRulerImpl } from "./TimelineRuler";
|
||||
import { useTimelineContext } from "./TimelineProvider";
|
||||
|
||||
export const TimelineRulerPart = memo(function TimelineRulerPart() {
|
||||
const { state } = useTimelineContext();
|
||||
const props = state.canvas;
|
||||
return (
|
||||
<TimelineRulerImpl
|
||||
major={props.major}
|
||||
minor={props.minor}
|
||||
pps={props.pps}
|
||||
trackContentWidth={props.trackContentWidth}
|
||||
totalH={props.totalH}
|
||||
effectiveDuration={props.effectiveDuration}
|
||||
majorTickInterval={props.majorTickInterval}
|
||||
theme={props.theme}
|
||||
beatAnalysis={props.beatAnalysis}
|
||||
contentOrigin={props.contentOrigin}
|
||||
renderTimeRange={props.rowsVirtualized ? props.renderTimeRange : undefined}
|
||||
/>
|
||||
);
|
||||
});
|
||||
Reference in New Issue
Block a user