mirror of
https://github.com/heygen-com/hyperframes.git
synced 2026-11-19 19:36:04 +00:00
## Summary Add the actual Studio timeline editing layer on top of the preview/runtime foundation. This PR includes: - drag-to-move clips across time and tracks - left/right resize handles with media-aware trim persistence - edge auto-scroll and edge track creation while dragging - selector-based source patching for `data-start`, `data-duration`, `data-track-index`, `z-index`, and media trim attributes - timeline UI cleanup, theming, hover/drag states, and the `Copy Prompt` action ## Why This PR Is Separate This is the user-facing editing behavior. It depends on the preview/runtime fixes in the base PR, but it is much easier to review once that plumbing is isolated. ## Verification - `bun run --filter @hyperframes/studio test` - `bun run --filter @hyperframes/studio typecheck` - `bunx oxlint packages/studio/src/App.tsx packages/studio/src/components/nle/NLELayout.tsx packages/studio/src/player/components/EditModal.tsx packages/studio/src/player/components/Timeline.tsx packages/studio/src/player/components/TimelineClip.tsx packages/studio/src/player/components/timelineEditing.ts packages/studio/src/player/components/timelineEditing.test.ts packages/studio/src/player/components/timelineTheme.ts packages/studio/src/player/components/timelineTheme.test.ts packages/studio/src/utils/sourcePatcher.ts packages/studio/src/utils/sourcePatcher.test.ts` - `bunx oxfmt --check packages/studio/src/App.tsx packages/studio/src/components/nle/NLELayout.tsx packages/studio/src/player/components/EditModal.tsx packages/studio/src/player/components/Timeline.tsx packages/studio/src/player/components/TimelineClip.tsx packages/studio/src/player/components/timelineEditing.ts packages/studio/src/player/components/timelineEditing.test.ts packages/studio/src/player/components/timelineTheme.ts packages/studio/src/player/components/timelineTheme.test.ts packages/studio/src/utils/sourcePatcher.ts packages/studio/src/utils/sourcePatcher.test.ts` ## Browser Proof - verified timeline drag / resize / trim flows in Studio with `agent-browser` - verified preview hot-refresh behavior without iframe remount flashes ## Stack - depends on #389 - followed by `fix: smooth scrubber end seeking` [result.mp4 <span class="graphite__hidden">(uploaded via Graphite)</span> <img class="graphite__hidden" src="https://app.graphite.com/user-attachments/thumbnails/ca71c177-5042-468d-906f-b353938f40f8.mp4" />](https://app.graphite.com/user-attachments/video/ca71c177-5042-468d-906f-b353938f40f8.mp4)
85 lines
3.0 KiB
TypeScript
85 lines
3.0 KiB
TypeScript
import { describe, expect, it } from "vitest";
|
|
import { applyPatchByTarget, readAttributeByTarget, type PatchOperation } from "./sourcePatcher";
|
|
|
|
describe("applyPatchByTarget", () => {
|
|
it("updates a composition host by data-composition-id selector", () => {
|
|
const html = `<div data-composition-id="intro" data-start="0" data-track-index="1"></div>`;
|
|
const op: PatchOperation = { type: "attribute", property: "start", value: "2.5" };
|
|
|
|
expect(applyPatchByTarget(html, { selector: '[data-composition-id="intro"]' }, op)).toContain(
|
|
'data-start="2.5"',
|
|
);
|
|
});
|
|
|
|
it("updates a class-based layer when the clip has no DOM id", () => {
|
|
const html = `<div class="headline clip" data-start="0" data-track-index="1"></div>`;
|
|
const op: PatchOperation = { type: "attribute", property: "track-index", value: "3" };
|
|
|
|
expect(applyPatchByTarget(html, { selector: ".headline" }, op)).toContain(
|
|
'data-track-index="3"',
|
|
);
|
|
});
|
|
|
|
it("updates inline z-index by selector when the clip has no DOM id", () => {
|
|
const html = `<div class="headline clip" style="position: absolute; opacity: 1" data-start="0"></div>`;
|
|
const op: PatchOperation = { type: "inline-style", property: "z-index", value: "3" };
|
|
|
|
expect(applyPatchByTarget(html, { selector: ".headline" }, op)).toContain(
|
|
'style="position: absolute; opacity: 1; z-index: 3"',
|
|
);
|
|
});
|
|
|
|
it("updates media timing attributes by selector", () => {
|
|
const html = `<video class="hero clip" data-start="0.2" data-duration="1.4" data-media-start="0.4"></video>`;
|
|
|
|
const withDuration = applyPatchByTarget(
|
|
html,
|
|
{ selector: ".hero" },
|
|
{
|
|
type: "attribute",
|
|
property: "duration",
|
|
value: "1.1",
|
|
},
|
|
);
|
|
const withMediaStart = applyPatchByTarget(
|
|
withDuration,
|
|
{ selector: ".hero" },
|
|
{
|
|
type: "attribute",
|
|
property: "media-start",
|
|
value: "0.7",
|
|
},
|
|
);
|
|
|
|
expect(withMediaStart).toContain('data-duration="1.1"');
|
|
expect(withMediaStart).toContain('data-media-start="0.7"');
|
|
});
|
|
|
|
it("reads media timing attributes by selector", () => {
|
|
const html = `<div class="hero clip" data-start="0.2" data-duration="1.4" data-media-start="0.4"></div>`;
|
|
|
|
expect(readAttributeByTarget(html, { selector: ".hero" }, "media-start")).toBe("0.4");
|
|
expect(readAttributeByTarget(html, { selector: ".hero" }, "duration")).toBe("1.4");
|
|
});
|
|
|
|
it("patches the correct duplicate selector occurrence", () => {
|
|
const html = [
|
|
`<div class="headline clip" data-start="0"></div>`,
|
|
`<div class="headline clip" data-start="1"></div>`,
|
|
].join("");
|
|
|
|
const patched = applyPatchByTarget(
|
|
html,
|
|
{ selector: ".headline", selectorIndex: 1 },
|
|
{
|
|
type: "attribute",
|
|
property: "start",
|
|
value: "2.5",
|
|
},
|
|
);
|
|
|
|
expect(patched).toContain(`<div class="headline clip" data-start="0"></div>`);
|
|
expect(patched).toContain(`<div class="headline clip" data-start="2.5"></div>`);
|
|
});
|
|
});
|