mirror of
https://github.com/heygen-com/hyperframes.git
synced 2026-11-23 11:29:54 +00:00
feat(studio): drag session registry; block cards draggable to timeline and canvas
This commit is contained in:
@@ -3,6 +3,7 @@ import { memo, useState, useCallback, useRef, useMemo, useEffect } from "react";
|
||||
import { VideoFrameThumbnail } from "../ui/VideoFrameThumbnail";
|
||||
import { MEDIA_EXT, IMAGE_EXT, VIDEO_EXT, FONT_EXT } from "../../utils/mediaTypes";
|
||||
import { TIMELINE_ASSET_MIME } from "../../utils/timelineAssetDrop";
|
||||
import { beginDragSession, endDragSession } from "../../utils/dragSession";
|
||||
import { copyTextToClipboard } from "../../utils/clipboard";
|
||||
import { ContextMenu } from "./AssetContextMenu";
|
||||
import { usePlayerStore } from "../../player/store/playerStore";
|
||||
@@ -65,7 +66,15 @@ function ImageCard({
|
||||
e.dataTransfer.effectAllowed = "copy";
|
||||
e.dataTransfer.setData(TIMELINE_ASSET_MIME, JSON.stringify({ path: asset }));
|
||||
e.dataTransfer.setData("text/plain", asset);
|
||||
beginDragSession({
|
||||
source: "asset",
|
||||
path: asset,
|
||||
kind: isVideo ? "video" : "image",
|
||||
durationSec: null,
|
||||
label: name,
|
||||
});
|
||||
}}
|
||||
onDragEnd={endDragSession}
|
||||
onContextMenu={(e) => {
|
||||
e.preventDefault();
|
||||
setContextMenu({ x: e.clientX, y: e.clientY });
|
||||
@@ -505,7 +514,6 @@ export const AssetsTab = memo(function AssetsTab({
|
||||
)}
|
||||
</div>
|
||||
|
||||
{/* Asset list */}
|
||||
<div className="flex-1 overflow-y-auto mt-1">
|
||||
{viewMode === "global" ? (
|
||||
<GlobalAssetsView searchQuery={searchQuery} />
|
||||
|
||||
@@ -2,6 +2,7 @@ import { useState, useRef, useEffect, useCallback } from "react";
|
||||
import { ContextMenu } from "./AssetContextMenu";
|
||||
import { basename, getAudioSubtype } from "./assetHelpers";
|
||||
import { TIMELINE_ASSET_MIME } from "../../utils/timelineAssetDrop";
|
||||
import { beginDragSession, endDragSession } from "../../utils/dragSession";
|
||||
|
||||
export function AudioRow({
|
||||
projectId,
|
||||
@@ -114,7 +115,15 @@ export function AudioRow({
|
||||
e.dataTransfer.effectAllowed = "copy";
|
||||
e.dataTransfer.setData(TIMELINE_ASSET_MIME, JSON.stringify({ path: asset }));
|
||||
e.dataTransfer.setData("text/plain", asset);
|
||||
beginDragSession({
|
||||
source: "asset",
|
||||
path: asset,
|
||||
kind: "audio",
|
||||
durationSec: meta?.duration ?? null,
|
||||
label: name,
|
||||
});
|
||||
}}
|
||||
onDragEnd={endDragSession}
|
||||
onContextMenu={(e) => {
|
||||
e.preventDefault();
|
||||
setContextMenu({ x: e.clientX, y: e.clientY });
|
||||
|
||||
@@ -10,6 +10,8 @@ import {
|
||||
import { usePlayerStore } from "../../player";
|
||||
import { formatTime } from "../../player/lib/time";
|
||||
import { useStudioShellContext } from "../../contexts/StudioContext";
|
||||
import { TIMELINE_BLOCK_MIME } from "../../utils/timelineAssetDrop";
|
||||
import { beginDragSession, endDragSession } from "../../utils/dragSession";
|
||||
export interface BlockPreviewInfo {
|
||||
videoUrl?: string;
|
||||
posterUrl?: string;
|
||||
@@ -383,10 +385,24 @@ function BlockCard({
|
||||
return (
|
||||
<div
|
||||
className="group/card rounded-md overflow-hidden cursor-pointer transition-colors bg-neutral-900 hover:bg-neutral-800"
|
||||
draggable
|
||||
onDragStart={(e) => {
|
||||
e.dataTransfer.effectAllowed = "copy";
|
||||
e.dataTransfer.setData(TIMELINE_BLOCK_MIME, JSON.stringify({ name }));
|
||||
e.dataTransfer.setData("text/plain", name);
|
||||
beginDragSession({
|
||||
source: "block",
|
||||
blockName: name,
|
||||
kind: "block",
|
||||
durationSec: duration ?? null,
|
||||
label: title,
|
||||
});
|
||||
handleLeave(); // cancel the hover-preview timer so it doesn't fire mid-drag
|
||||
}}
|
||||
onDragEnd={endDragSession}
|
||||
onPointerEnter={handleEnter}
|
||||
onPointerLeave={handleLeave}
|
||||
>
|
||||
{/* Thumbnail */}
|
||||
<div className="aspect-video w-full overflow-hidden relative">
|
||||
{hovered && videoUrl ? (
|
||||
<video
|
||||
|
||||
@@ -0,0 +1,37 @@
|
||||
import { describe, expect, it } from "vitest";
|
||||
import { beginDragSession, endDragSession, getActiveDragSession } from "./dragSession";
|
||||
|
||||
describe("dragSession", () => {
|
||||
it("stores and clears the active payload", () => {
|
||||
expect(getActiveDragSession()).toBeNull();
|
||||
beginDragSession({
|
||||
source: "asset",
|
||||
path: "assets/a.mp3",
|
||||
kind: "audio",
|
||||
durationSec: 12.4,
|
||||
label: "a.mp3",
|
||||
});
|
||||
expect(getActiveDragSession()?.kind).toBe("audio");
|
||||
endDragSession();
|
||||
expect(getActiveDragSession()).toBeNull();
|
||||
});
|
||||
|
||||
it("a new begin replaces the previous session", () => {
|
||||
beginDragSession({
|
||||
source: "asset",
|
||||
path: "x.png",
|
||||
kind: "image",
|
||||
durationSec: null,
|
||||
label: "x",
|
||||
});
|
||||
beginDragSession({
|
||||
source: "block",
|
||||
blockName: "confetti",
|
||||
kind: "block",
|
||||
durationSec: 3,
|
||||
label: "Confetti",
|
||||
});
|
||||
expect(getActiveDragSession()?.source).toBe("block");
|
||||
endDragSession();
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,29 @@
|
||||
/**
|
||||
* In-window drag payload registry. HTML5 DnD hides dataTransfer payloads until
|
||||
* drop (Chrome protected mode), but drags that originate inside the studio can
|
||||
* publish their payload here so drag-over UI (ghost, snap) knows what is being
|
||||
* dragged. OS-file drags never appear here — callers must fall back to
|
||||
* dataTransfer.items MIME hints.
|
||||
*/
|
||||
export interface DragSessionPayload {
|
||||
source: "asset" | "block";
|
||||
path?: string;
|
||||
blockName?: string;
|
||||
kind: "image" | "video" | "audio" | "block";
|
||||
durationSec: number | null;
|
||||
label: string;
|
||||
}
|
||||
|
||||
let active: DragSessionPayload | null = null;
|
||||
|
||||
export function beginDragSession(payload: DragSessionPayload): void {
|
||||
active = payload;
|
||||
}
|
||||
|
||||
export function endDragSession(): void {
|
||||
active = null;
|
||||
}
|
||||
|
||||
export function getActiveDragSession(): DragSessionPayload | null {
|
||||
return active;
|
||||
}
|
||||
Reference in New Issue
Block a user