mirror of
https://github.com/heygen-com/hyperframes.git
synced 2026-11-17 23:47:33 +00:00
Merge branch 'fix/studio-sfx-u16' into fix/studio-ui-audit-fixes
# Conflicts: # packages/studio/src/player/components/TimelineLanes.test.tsx # packages/studio/src/player/components/TimelineLanes.tsx
This commit is contained in:
@@ -6,23 +6,39 @@ import { afterEach, beforeEach, describe, expect, it, vi } from "vitest";
|
||||
import { EditorShell } from "./EditorShell";
|
||||
|
||||
let captionEditMode = true;
|
||||
const hookMocks = vi.hoisted(() => ({
|
||||
useTimelineSelectionPreviewSync: vi.fn(),
|
||||
}));
|
||||
|
||||
vi.mock("../hooks/useTimelineSelectionPreviewSync", () => hookMocks);
|
||||
|
||||
vi.mock("../contexts/StudioContext", () => ({
|
||||
useStudioPlaybackContext: () => ({
|
||||
captionEditMode,
|
||||
refreshKey: 0,
|
||||
refreshPreviewDocumentVersion: vi.fn(),
|
||||
timelineElements: [],
|
||||
}),
|
||||
useStudioShellContext: () => ({
|
||||
projectId: "project-1",
|
||||
activeCompPath: "index.html",
|
||||
setActiveCompPath: vi.fn(),
|
||||
handlePreviewIframeRef: vi.fn(),
|
||||
showToast: vi.fn(),
|
||||
}),
|
||||
}));
|
||||
|
||||
vi.mock("../contexts/DomEditContext", () => ({
|
||||
useDomEditActionsContext: () => ({ handleTimelineElementSelect: vi.fn() }),
|
||||
useDomEditActionsContext: () => ({
|
||||
handleTimelineElementSelect: vi.fn(),
|
||||
buildDomSelectionForTimelineElement: vi.fn(),
|
||||
applyDomSelection: vi.fn(),
|
||||
applyMarqueeSelection: vi.fn(),
|
||||
}),
|
||||
useDomEditSelectionContext: () => ({
|
||||
domEditSelection: null,
|
||||
domEditGroupSelections: [],
|
||||
}),
|
||||
}));
|
||||
|
||||
vi.mock("./nle/NLEContext", () => ({
|
||||
@@ -55,6 +71,7 @@ let root: Root | null = null;
|
||||
|
||||
beforeEach(() => {
|
||||
captionEditMode = true;
|
||||
hookMocks.useTimelineSelectionPreviewSync.mockClear();
|
||||
});
|
||||
|
||||
afterEach(() => {
|
||||
@@ -101,6 +118,20 @@ function renderShell(): void {
|
||||
}
|
||||
|
||||
describe("EditorShell caption mode", () => {
|
||||
it("wires timeline store selection into preview selection sync", () => {
|
||||
renderShell();
|
||||
|
||||
expect(hookMocks.useTimelineSelectionPreviewSync).toHaveBeenCalledOnce();
|
||||
expect(hookMocks.useTimelineSelectionPreviewSync).toHaveBeenCalledWith(
|
||||
expect.objectContaining({
|
||||
activeCompPath: "index.html",
|
||||
timelineElements: [],
|
||||
domEditSelection: null,
|
||||
domEditGroupSelections: [],
|
||||
}),
|
||||
);
|
||||
});
|
||||
|
||||
it("shows a visible exit control on the caption rail", () => {
|
||||
renderShell();
|
||||
|
||||
|
||||
@@ -10,10 +10,11 @@ import { NLEProvider, useNLEContext } from "./nle/NLEContext";
|
||||
import { CaptionTimeline } from "../captions/components/CaptionTimeline";
|
||||
import { StudioFeedbackBar } from "./StudioFeedbackBar";
|
||||
import { useStudioPlaybackContext, useStudioShellContext } from "../contexts/StudioContext";
|
||||
import { useDomEditActionsContext } from "../contexts/DomEditContext";
|
||||
import { useDomEditActionsContext, useDomEditSelectionContext } from "../contexts/DomEditContext";
|
||||
import { TimelineEditProvider } from "../contexts/TimelineEditContext";
|
||||
import type { TimelineElement } from "../player";
|
||||
import { usePlayerStore, type TimelineElement } from "../player";
|
||||
import type { BlockPreviewInfo } from "./sidebar/BlocksTab";
|
||||
import { useTimelineSelectionPreviewSync } from "../hooks/useTimelineSelectionPreviewSync";
|
||||
|
||||
type RenderClipContent = (
|
||||
element: TimelineElement,
|
||||
@@ -89,10 +90,35 @@ export function EditorShell({
|
||||
gestureOverlay,
|
||||
onExitCaptionMode,
|
||||
}: EditorShellProps) {
|
||||
const { projectId, activeCompPath, setActiveCompPath, handlePreviewIframeRef } =
|
||||
const { projectId, activeCompPath, setActiveCompPath, handlePreviewIframeRef, showToast } =
|
||||
useStudioShellContext();
|
||||
const { refreshKey, captionEditMode, refreshPreviewDocumentVersion } = useStudioPlaybackContext();
|
||||
const { handleTimelineElementSelect } = useDomEditActionsContext();
|
||||
const { refreshKey, captionEditMode, refreshPreviewDocumentVersion, timelineElements } =
|
||||
useStudioPlaybackContext();
|
||||
const {
|
||||
handleTimelineElementSelect,
|
||||
buildDomSelectionForTimelineElement,
|
||||
applyDomSelection,
|
||||
applyMarqueeSelection,
|
||||
} = useDomEditActionsContext();
|
||||
const { domEditSelection, domEditGroupSelections } = useDomEditSelectionContext();
|
||||
const selectedElementId = usePlayerStore((state) => state.selectedElementId);
|
||||
const selectedElementIds = usePlayerStore((state) => state.selectedElementIds);
|
||||
const reportTimelineSelectionNotFound = useCallback(() => {
|
||||
showToast("The selected clip is not available in the preview yet.", "info");
|
||||
}, [showToast]);
|
||||
|
||||
useTimelineSelectionPreviewSync({
|
||||
selectedElementId,
|
||||
selectedElementIds,
|
||||
timelineElements,
|
||||
domEditSelection,
|
||||
domEditGroupSelections,
|
||||
activeCompPath,
|
||||
buildDomSelectionForTimelineElement,
|
||||
applyDomSelection,
|
||||
applyMarqueeSelection,
|
||||
onSelectionNotFound: reportTimelineSelectionNotFound,
|
||||
});
|
||||
|
||||
const timelineEditCallbacks = useTimelineEditCallbacks({
|
||||
handleTimelineElementMove,
|
||||
|
||||
@@ -24,6 +24,7 @@ interface HarnessProps {
|
||||
options?: { revealPanel?: boolean; additive?: boolean; preserveGroup?: boolean },
|
||||
) => void;
|
||||
applyMarqueeSelection: (selections: DomEditSelection[], additive: boolean) => void;
|
||||
onSelectionNotFound: () => void;
|
||||
}
|
||||
|
||||
afterEach(() => {
|
||||
@@ -96,6 +97,7 @@ describe("useTimelineSelectionPreviewSync", () => {
|
||||
buildDomSelectionForTimelineElement,
|
||||
applyDomSelection,
|
||||
applyMarqueeSelection,
|
||||
onSelectionNotFound: vi.fn(),
|
||||
});
|
||||
|
||||
expect(applyMarqueeSelection).toHaveBeenCalledWith([secondSelection, firstSelection], false);
|
||||
@@ -120,10 +122,79 @@ describe("useTimelineSelectionPreviewSync", () => {
|
||||
}),
|
||||
applyDomSelection,
|
||||
applyMarqueeSelection,
|
||||
onSelectionNotFound: vi.fn(),
|
||||
});
|
||||
|
||||
expect(applyDomSelection).toHaveBeenCalledWith(null, { revealPanel: false });
|
||||
expect(applyMarqueeSelection).not.toHaveBeenCalled();
|
||||
harness.cleanup();
|
||||
});
|
||||
|
||||
it("does not apply a stale selection after a rapid clip switch", async () => {
|
||||
const { firstSelection, secondSelection, timelineElements, selectionById } = makeSyncFixture();
|
||||
const applyDomSelection = vi.fn();
|
||||
const applyMarqueeSelection = vi.fn();
|
||||
let resolveFirstSelection: (selection: DomEditSelection | null) => void = () => undefined;
|
||||
const firstSelectionResult = new Promise<DomEditSelection | null>((resolve) => {
|
||||
resolveFirstSelection = resolve;
|
||||
});
|
||||
const buildDomSelectionForTimelineElement = vi.fn((element: TimelineElement) => {
|
||||
if (element.id === "clip-1") return firstSelectionResult;
|
||||
return Promise.resolve(selectionById.get(element.id) ?? null);
|
||||
});
|
||||
const harness = renderHarness();
|
||||
const baseProps = {
|
||||
timelineElements,
|
||||
domEditSelection: null,
|
||||
domEditGroupSelections: [],
|
||||
buildDomSelectionForTimelineElement,
|
||||
applyDomSelection,
|
||||
applyMarqueeSelection,
|
||||
onSelectionNotFound: vi.fn(),
|
||||
};
|
||||
|
||||
await harness.rerender({
|
||||
...baseProps,
|
||||
selectedElementId: "clip-1",
|
||||
selectedElementIds: new Set(["clip-1"]),
|
||||
});
|
||||
await harness.rerender({
|
||||
...baseProps,
|
||||
selectedElementId: "clip-2",
|
||||
selectedElementIds: new Set(["clip-2"]),
|
||||
});
|
||||
await act(async () => {
|
||||
resolveFirstSelection(firstSelection);
|
||||
await firstSelectionResult;
|
||||
});
|
||||
|
||||
expect(applyDomSelection).toHaveBeenCalledTimes(1);
|
||||
expect(applyDomSelection).toHaveBeenCalledWith(secondSelection, { revealPanel: false });
|
||||
harness.cleanup();
|
||||
});
|
||||
|
||||
it("reports when a selected timeline element has no live preview node", async () => {
|
||||
const { timelineElements } = makeSyncFixture();
|
||||
const applyDomSelection = vi.fn();
|
||||
const applyMarqueeSelection = vi.fn();
|
||||
const onSelectionNotFound = vi.fn();
|
||||
const harness = renderHarness();
|
||||
|
||||
await harness.rerender({
|
||||
selectedElementId: "clip-1",
|
||||
selectedElementIds: new Set(["clip-1"]),
|
||||
timelineElements,
|
||||
domEditSelection: null,
|
||||
domEditGroupSelections: [],
|
||||
buildDomSelectionForTimelineElement: vi.fn(async () => null),
|
||||
applyDomSelection,
|
||||
applyMarqueeSelection,
|
||||
onSelectionNotFound,
|
||||
});
|
||||
|
||||
expect(onSelectionNotFound).toHaveBeenCalledOnce();
|
||||
expect(applyDomSelection).not.toHaveBeenCalled();
|
||||
expect(applyMarqueeSelection).not.toHaveBeenCalled();
|
||||
harness.cleanup();
|
||||
});
|
||||
});
|
||||
|
||||
@@ -18,6 +18,7 @@ interface UseTimelineSelectionPreviewSyncParams {
|
||||
options?: { revealPanel?: boolean; additive?: boolean; preserveGroup?: boolean },
|
||||
) => void;
|
||||
applyMarqueeSelection: (selections: DomEditSelection[], additive: boolean) => void;
|
||||
onSelectionNotFound: () => void;
|
||||
}
|
||||
|
||||
function orderSelectedIds(ids: Set<string>, anchor: string | null): string[] {
|
||||
@@ -56,6 +57,7 @@ export function useTimelineSelectionPreviewSync({
|
||||
buildDomSelectionForTimelineElement,
|
||||
applyDomSelection,
|
||||
applyMarqueeSelection,
|
||||
onSelectionNotFound,
|
||||
}: UseTimelineSelectionPreviewSyncParams): void {
|
||||
const selectedIds = useMemo(
|
||||
() => orderSelectedIds(selectedElementIds, selectedElementId),
|
||||
@@ -99,9 +101,10 @@ export function useTimelineSelectionPreviewSync({
|
||||
if (cancelled) return;
|
||||
// The store is the source of truth: applying a partial set would write that
|
||||
// shrunk set back and silently drop the members whose DOM node was not ready.
|
||||
// Bail instead; a later effect run (on timelineElements/DOM change) applies the
|
||||
// full set once every resolvable member has a live node.
|
||||
if (selections.length < resolvableCount) return;
|
||||
if (selections.length < resolvableCount) {
|
||||
onSelectionNotFound();
|
||||
return;
|
||||
}
|
||||
if (selections.length === 0) {
|
||||
applyDomSelection(null, { revealPanel: false });
|
||||
} else if (selections.length === 1) {
|
||||
@@ -122,6 +125,7 @@ export function useTimelineSelectionPreviewSync({
|
||||
buildDomSelectionForTimelineElement,
|
||||
domEditGroupSelections,
|
||||
domEditSelection,
|
||||
onSelectionNotFound,
|
||||
selectedElementId,
|
||||
selectedIds,
|
||||
selectedKey,
|
||||
|
||||
@@ -506,7 +506,6 @@ export const Timeline = memo(function Timeline({
|
||||
renderClipOverlay={renderClipOverlay}
|
||||
playheadRef={playheadRef}
|
||||
onDrillDown={onDrillDown}
|
||||
onSelectElement={onSelectElement}
|
||||
setHoveredClip={setHoveredClip}
|
||||
setShowPopover={setShowPopover}
|
||||
setRangeSelection={setRangeSelection}
|
||||
|
||||
@@ -57,7 +57,6 @@ function renderLanes({
|
||||
const setSelectedElementId = vi.fn((id: string | null) => {
|
||||
usePlayerStore.getState().setSelectedElementId(id);
|
||||
});
|
||||
const onSelectElement = vi.fn();
|
||||
const trackStyle = getTrackStyle("div");
|
||||
|
||||
act(() => {
|
||||
@@ -92,7 +91,6 @@ function renderLanes({
|
||||
keyframeCache={keyframeCache}
|
||||
selectedKeyframes={new Set()}
|
||||
currentTime={0}
|
||||
onSelectElement={onSelectElement}
|
||||
onMoveKeyframe={onMoveKeyframe}
|
||||
onToggleTrackHidden={undefined}
|
||||
onResizeElement={undefined}
|
||||
@@ -103,7 +101,7 @@ function renderLanes({
|
||||
);
|
||||
});
|
||||
|
||||
return { host, root, setSelectedElementId, onSelectElement };
|
||||
return { host, root, setSelectedElementId };
|
||||
}
|
||||
|
||||
function pointerEvent(type: string, init: PointerEventInit): Event {
|
||||
@@ -120,7 +118,7 @@ function clickClip(host: HTMLElement, id: string): void {
|
||||
}
|
||||
|
||||
describe("TimelineLanes selection", () => {
|
||||
it("keeps an already-selected clip selected on a plain click", () => {
|
||||
it("writes a plain clip click to store selection only", () => {
|
||||
usePlayerStore.getState().setSelectedElementId(firstClip.id);
|
||||
const harness = renderLanes({ selectedElementId: firstClip.id });
|
||||
|
||||
@@ -128,12 +126,11 @@ describe("TimelineLanes selection", () => {
|
||||
|
||||
expect(harness.setSelectedElementId).toHaveBeenCalledWith(firstClip.id);
|
||||
expect(harness.setSelectedElementId).not.toHaveBeenCalledWith(null);
|
||||
expect(harness.onSelectElement).toHaveBeenCalledWith(firstClip);
|
||||
expect(usePlayerStore.getState().selectedElementId).toBe(firstClip.id);
|
||||
act(() => harness.root.unmount());
|
||||
});
|
||||
|
||||
it("narrows a marquee selection to the clicked clip", () => {
|
||||
it("narrows a marquee selection in the store to the clicked clip", () => {
|
||||
usePlayerStore.getState().setSelection([firstClip.id, secondClip.id], firstClip.id);
|
||||
const harness = renderLanes({
|
||||
elements: [firstClip, secondClip],
|
||||
@@ -144,7 +141,6 @@ describe("TimelineLanes selection", () => {
|
||||
clickClip(harness.host, secondClip.id);
|
||||
|
||||
expect(harness.setSelectedElementId).toHaveBeenCalledWith(secondClip.id);
|
||||
expect(harness.onSelectElement).toHaveBeenCalledWith(secondClip);
|
||||
expect([...usePlayerStore.getState().selectedElementIds]).toEqual([secondClip.id]);
|
||||
act(() => harness.root.unmount());
|
||||
});
|
||||
@@ -180,8 +176,6 @@ describe("TimelineLanes selection", () => {
|
||||
});
|
||||
expect(harness.setSelectedElementId).toHaveBeenCalledWith(firstClip.id);
|
||||
expect(harness.setSelectedElementId).toHaveBeenCalledTimes(1);
|
||||
expect(harness.onSelectElement).toHaveBeenCalledWith(firstClip);
|
||||
expect(harness.onSelectElement).toHaveBeenCalledTimes(1);
|
||||
|
||||
act(() => {
|
||||
diamond!.dispatchEvent(pointerEvent("pointerup", { bubbles: true, button: 0, clientX: 54 }));
|
||||
|
||||
@@ -53,7 +53,6 @@ export interface TimelineLaneBaseProps {
|
||||
) => ReactNode;
|
||||
renderClipOverlay?: (element: TimelineElement) => ReactNode;
|
||||
onDrillDown?: (element: TimelineElement) => void;
|
||||
onSelectElement?: (element: TimelineElement | null) => void;
|
||||
setHoveredClip: (key: string | null) => void;
|
||||
setShowPopover: (v: boolean) => void;
|
||||
setRangeSelection: (v: null) => void;
|
||||
@@ -114,7 +113,6 @@ export function TimelineLanes({
|
||||
renderClipContent,
|
||||
renderClipOverlay,
|
||||
onDrillDown,
|
||||
onSelectElement,
|
||||
setHoveredClip,
|
||||
setShowPopover,
|
||||
setRangeSelection,
|
||||
@@ -266,7 +264,6 @@ export function TimelineLanes({
|
||||
const selectClip = () => {
|
||||
usePlayerStore.getState().clearSelectedElementIds();
|
||||
setSelectedElementId(elementKey);
|
||||
onSelectElement?.(el);
|
||||
};
|
||||
const isComposition = !!el.compositionSrc;
|
||||
// elementKey (el.key ?? el.id) is already unique per clip; do NOT
|
||||
|
||||
Reference in New Issue
Block a user