mirror of
https://github.com/heygen-com/hyperframes.git
synced 2026-09-05 00:56:23 +00:00
fix(studio): retime flat tween boundaries and target the clicked keyframe's own tween
Two more regressions the QA triage attributed to this stack. Dragging a flat tween's boundary diamond did nothing: the handler bailed on `!anim.keyframes` even though resolveKeyframeRetime already resolves that case to a position/duration resize. The empty remap now dispatches update-meta, which moves the window without rewriting the authored flat tween into keyframes form (what the keyframed-resize writer would do as a side effect). The property panel's keyframe gutter guessed one animation per property group, so clicking a keyframe authored by a sibling tween on a merged row named the wrong tween and the writer silently removed nothing. The diamond now reports the clicked keyframe's own animationId, with the group guess kept as the fallback for cache rows that carry no identity.
This commit is contained in:
@@ -11,12 +11,15 @@ interface KeyframeNavigationProps {
|
||||
tweenPercentage?: number;
|
||||
properties: Record<string, number | string>;
|
||||
ease?: string;
|
||||
/** The tween that authored this keyframe, when the cache knows it. */
|
||||
animationId?: string;
|
||||
}> | null;
|
||||
/** Current playhead percentage within the element's lifetime (0-100) */
|
||||
currentPercentage: number;
|
||||
onSeek: (percentage: number) => void;
|
||||
onAddKeyframe: (percentage: number) => void;
|
||||
onRemoveKeyframe: (percentage: number) => void;
|
||||
/** `animationId` is the clicked keyframe's OWN tween; see handleDiamondClick. */
|
||||
onRemoveKeyframe: (percentage: number, animationId?: string) => void;
|
||||
onConvertToKeyframes: () => void;
|
||||
}
|
||||
|
||||
@@ -152,7 +155,12 @@ export const KeyframeNavigation = memo(function KeyframeNavigation({
|
||||
if (diamondState === "ghost") {
|
||||
onConvertToKeyframes();
|
||||
} else if (diamondState === "active" && atCurrent) {
|
||||
onRemoveKeyframe(atCurrent.tweenPercentage ?? atCurrent.percentage);
|
||||
// Report the keyframe's OWN tween. A merged gutter row shows the keyframes
|
||||
// of every tween in the property group, so the caller's "the group's
|
||||
// animation" guess names the wrong tween whenever the clicked keyframe
|
||||
// belongs to a sibling — and the writer then finds no keyframe at that
|
||||
// percentage and silently does nothing.
|
||||
onRemoveKeyframe(atCurrent.tweenPercentage ?? atCurrent.percentage, atCurrent.animationId);
|
||||
} else {
|
||||
onAddKeyframe(clipToTweenPercentage(propertyKeyframes, currentPercentage));
|
||||
}
|
||||
|
||||
@@ -0,0 +1,59 @@
|
||||
// @vitest-environment happy-dom
|
||||
|
||||
import { act } from "react";
|
||||
import { beforeAll, describe, expect, it, vi } from "vitest";
|
||||
import { installReactActEnvironment, mountReactHarness } from "../../hooks/domSelectionTestHarness";
|
||||
import { KeyframeNavigation } from "./KeyframeNavigation";
|
||||
|
||||
beforeAll(installReactActEnvironment);
|
||||
|
||||
/**
|
||||
* Regression: a merged gutter row shows the keyframes of EVERY tween in the
|
||||
* property group. The panel guesses "the group's animation" for the write, so a
|
||||
* click on a keyframe authored by a sibling tween named the wrong animation and
|
||||
* the writer silently found nothing to remove. The diamond now reports the
|
||||
* clicked keyframe's own animationId.
|
||||
*/
|
||||
const MERGED_ROW = [
|
||||
{ percentage: 0, tweenPercentage: 0, properties: { x: 0 }, animationId: "delta-to-500-position" },
|
||||
{
|
||||
percentage: 50,
|
||||
tweenPercentage: 25,
|
||||
properties: { x: 120 },
|
||||
animationId: "delta-to-4000-position",
|
||||
},
|
||||
];
|
||||
|
||||
function clickDiamond(currentPercentage: number, onRemoveKeyframe: (...args: never[]) => void) {
|
||||
const root = mountReactHarness(
|
||||
<KeyframeNavigation
|
||||
property="x"
|
||||
keyframes={MERGED_ROW}
|
||||
currentPercentage={currentPercentage}
|
||||
onSeek={vi.fn()}
|
||||
onAddKeyframe={vi.fn()}
|
||||
onRemoveKeyframe={onRemoveKeyframe as never}
|
||||
onConvertToKeyframes={vi.fn()}
|
||||
/>,
|
||||
);
|
||||
const diamond = document.querySelector<HTMLElement>('[title="Remove x keyframe"]');
|
||||
expect(diamond).not.toBeNull();
|
||||
act(() => {
|
||||
diamond?.click();
|
||||
});
|
||||
act(() => root.unmount());
|
||||
}
|
||||
|
||||
describe("KeyframeNavigation diamond", () => {
|
||||
it("reports the clicked keyframe's own animation on a merged row", () => {
|
||||
const onRemoveKeyframe = vi.fn();
|
||||
clickDiamond(50, onRemoveKeyframe);
|
||||
expect(onRemoveKeyframe).toHaveBeenCalledWith(25, "delta-to-4000-position");
|
||||
});
|
||||
|
||||
it("still reports the first tween's keyframe as its own", () => {
|
||||
const onRemoveKeyframe = vi.fn();
|
||||
clickDiamond(0, onRemoveKeyframe);
|
||||
expect(onRemoveKeyframe).toHaveBeenCalledWith(0, "delta-to-500-position");
|
||||
});
|
||||
});
|
||||
@@ -408,7 +408,9 @@ export const PropertyPanel = memo(function PropertyPanel(props: PropertyPanelPro
|
||||
onCommitAnimatedProperty &&
|
||||
void onCommitAnimatedProperty(element, "x", displayX)
|
||||
}
|
||||
onRemoveKeyframe={(pct) => onRemoveKeyframe?.(animIdForProp("x"), pct)}
|
||||
onRemoveKeyframe={(pct, animationId) =>
|
||||
onRemoveKeyframe?.(animationId ?? animIdForProp("x"), pct)
|
||||
}
|
||||
onConvertToKeyframes={() => onConvertToKeyframes?.(animIdForProp("x"))}
|
||||
/>
|
||||
)}
|
||||
@@ -433,7 +435,9 @@ export const PropertyPanel = memo(function PropertyPanel(props: PropertyPanelPro
|
||||
onCommitAnimatedProperty &&
|
||||
void onCommitAnimatedProperty(element, "y", displayY)
|
||||
}
|
||||
onRemoveKeyframe={(pct) => onRemoveKeyframe?.(animIdForProp("y"), pct)}
|
||||
onRemoveKeyframe={(pct, animationId) =>
|
||||
onRemoveKeyframe?.(animationId ?? animIdForProp("y"), pct)
|
||||
}
|
||||
onConvertToKeyframes={() => onConvertToKeyframes?.(animIdForProp("y"))}
|
||||
/>
|
||||
)}
|
||||
@@ -458,7 +462,9 @@ export const PropertyPanel = memo(function PropertyPanel(props: PropertyPanelPro
|
||||
onCommitAnimatedProperty &&
|
||||
void onCommitAnimatedProperty(element, "width", displayW)
|
||||
}
|
||||
onRemoveKeyframe={(pct) => onRemoveKeyframe?.(animIdForProp("width"), pct)}
|
||||
onRemoveKeyframe={(pct, animationId) =>
|
||||
onRemoveKeyframe?.(animationId ?? animIdForProp("width"), pct)
|
||||
}
|
||||
onConvertToKeyframes={() => onConvertToKeyframes?.(animIdForProp("width"))}
|
||||
/>
|
||||
)}
|
||||
@@ -483,7 +489,9 @@ export const PropertyPanel = memo(function PropertyPanel(props: PropertyPanelPro
|
||||
onCommitAnimatedProperty &&
|
||||
void onCommitAnimatedProperty(element, "height", displayH)
|
||||
}
|
||||
onRemoveKeyframe={(pct) => onRemoveKeyframe?.(animIdForProp("height"), pct)}
|
||||
onRemoveKeyframe={(pct, animationId) =>
|
||||
onRemoveKeyframe?.(animationId ?? animIdForProp("height"), pct)
|
||||
}
|
||||
onConvertToKeyframes={() => onConvertToKeyframes?.(animIdForProp("height"))}
|
||||
/>
|
||||
)}
|
||||
@@ -507,7 +515,9 @@ export const PropertyPanel = memo(function PropertyPanel(props: PropertyPanelPro
|
||||
onCommitAnimatedProperty &&
|
||||
void onCommitAnimatedProperty(element, "rotation", displayR)
|
||||
}
|
||||
onRemoveKeyframe={(pct) => onRemoveKeyframe?.(animIdForProp("rotation"), pct)}
|
||||
onRemoveKeyframe={(pct, animationId) =>
|
||||
onRemoveKeyframe?.(animationId ?? animIdForProp("rotation"), pct)
|
||||
}
|
||||
onConvertToKeyframes={() => onConvertToKeyframes?.(animIdForProp("rotation"))}
|
||||
/>
|
||||
)}
|
||||
|
||||
@@ -83,10 +83,10 @@ function KeyframeGutter({
|
||||
track("button", `Add ${property} keyframe`);
|
||||
void onCommitAnimatedProperty(element, property, displayValue);
|
||||
}}
|
||||
onRemoveKeyframe={(pct) => {
|
||||
onRemoveKeyframe={(pct, animationId) => {
|
||||
if (!onRemoveKeyframe) return;
|
||||
track("button", `Remove ${property} keyframe`);
|
||||
onRemoveKeyframe(animIdForProp(property), pct);
|
||||
onRemoveKeyframe(animationId ?? animIdForProp(property), pct);
|
||||
}}
|
||||
onConvertToKeyframes={() => {
|
||||
if (!onConvertToKeyframes) return;
|
||||
|
||||
Reference in New Issue
Block a user