Skip to content

OpenReel Video - Professional browser-based video editor. Open source CapCut alternative. 100% browser-based, no installation, no cloud uploads, no watermarks.

TypeScript

feat(timeline): support external OS file drag-and-drop onto timeline

lvalics932c55bd401a
diff --git a/apps/web/src/components/editor/Timeline.tsx b/apps/web/src/components/editor/Timeline.tsx
index d2f587c7..3d3a6b2c 100644
--- a/apps/web/src/components/editor/Timeline.tsx
+++ b/apps/web/src/components/editor/Timeline.tsx
@@ -26,6 +26,7 @@ import {
import { useProjectStore } from "../../stores/project-store";
import { useTimelineStore } from "../../stores/timeline-store";
import { useUIStore } from "../../stores/ui-store";
+import { toast } from "../../stores/notification-store";
import { useEngineStore } from "../../stores/engine-store";
import { getPlaybackBridge } from "../../bridges/playback-bridge";
import {
@@ -961,44 +962,78 @@ export const Timeline: React.FC = () => {
e.preventDefault();
e.dataTransfer.dropEffect = "copy";
}}
- onDrop={(e) => {
+ onDrop={async (e) => {
e.preventDefault();
- try {
- const rawData = e.dataTransfer.getData("application/json");
- if (!rawData) return;
- const data = JSON.parse(rawData);
- if (!data?.mediaId) return;
- const rect = tracksRef.current?.getBoundingClientRect();
- if (!rect) return;
- const x = e.clientX - rect.left + (tracksRef.current?.scrollLeft ?? 0);
- const rawTime = Math.max(0, x / pixelsPerSecond);
-
- const allClips = project.timeline.tracks.flatMap(t => t.clips);
- let snappedTime = rawTime;
- if (snapSettings.enabled) {
- const threshold = snapSettings.snapThreshold / pixelsPerSecond;
- let bestDist = Infinity;
- for (const clip of allClips) {
- const clipEnd = clip.startTime + clip.duration;
- const distToEnd = Math.abs(rawTime - clipEnd);
- const distToStart = Math.abs(rawTime - clip.startTime);
- if (distToEnd < threshold && distToEnd < bestDist) {
- bestDist = distToEnd;
- snappedTime = clipEnd;
- }
- if (distToStart < threshold && distToStart < bestDist) {
- bestDist = distToStart;
- snappedTime = clip.startTime;
- }
+ const rect = tracksRef.current?.getBoundingClientRect();
+ if (!rect) return;
+ const x = e.clientX - rect.left + (tracksRef.current?.scrollLeft ?? 0);
+ const rawTime = Math.max(0, x / pixelsPerSecond);
+
+ const allClips = project.timeline.tracks.flatMap(t => t.clips);
+ let snappedTime = rawTime;
+ if (snapSettings.enabled) {
+ const threshold = snapSettings.snapThreshold / pixelsPerSecond;
+ let bestDist = Infinity;
+ for (const clip of allClips) {
+ const clipEnd = clip.startTime + clip.duration;
+ const distToEnd = Math.abs(rawTime - clipEnd);
+ const distToStart = Math.abs(rawTime - clip.startTime);
+ if (distToEnd < threshold && distToEnd < bestDist) {
+ bestDist = distToEnd;
+ snappedTime = clipEnd;
+ }
+ if (distToStart < threshold && distToStart < bestDist) {
+ bestDist = distToStart;
+ snappedTime = clip.startTime;
+ }
+ }
+ if (snapSettings.snapToPlayhead) {
+ const distToPlayhead = Math.abs(rawTime - playheadPosition);
+ if (distToPlayhead < threshold && distToPlayhead < bestDist) {
+ snappedTime = playheadPosition;
}
- if (snapSettings.snapToPlayhead) {
- const distToPlayhead = Math.abs(rawTime - playheadPosition);
- if (distToPlayhead < threshold && distToPlayhead < bestDist) {
- snappedTime = playheadPosition;
+ }
+ }
+
+ // External OS file drop (e.g. from Windows Explorer)
+ if (e.dataTransfer.files && e.dataTransfer.files.length > 0) {
+ const { importMedia, addClipToNewTrack } = useProjectStore.getState();
+ for (const file of Array.from(e.dataTransfer.files)) {
+ try {
+ const beforeIds = new Set(
+ useProjectStore.getState().project.mediaLibrary.items.map(i => i.id)
+ );
+ const result = await importMedia(file);
+ if (result.success) {
+ const newItem = useProjectStore
+ .getState()
+ .project.mediaLibrary.items.find(i => !beforeIds.has(i.id));
+ if (newItem) {
+ await addClipToNewTrack(newItem.id, snappedTime);
+ const track = useProjectStore
+ .getState()
+ .project.timeline.tracks.find(t =>
+ t.clips.some(c => c.mediaId === newItem.id)
+ );
+ if (track) {
+ toast.success(`Added to ${track.name}`, file.name);
+ }
+ }
}
+ } catch (err) {
+ console.error("[Timeline] External file drop failed:", err);
}
}
+ return;
+ }
+
+ // Internal drag from assets panel
+ try {
+ const rawData = e.dataTransfer.getData("application/json");
+ if (!rawData) return;
+ const data = JSON.parse(rawData);
+ if (!data?.mediaId) return;
handleDropMedia("", data.mediaId, snappedTime);
} catch {
// ignore
diff --git a/apps/web/src/components/editor/timeline/TrackLane.tsx b/apps/web/src/components/editor/timeline/TrackLane.tsx
index 19a01fd6..8bbae35e 100644
--- a/apps/web/src/components/editor/timeline/TrackLane.tsx
+++ b/apps/web/src/components/editor/timeline/TrackLane.tsx
@@ -13,6 +13,8 @@ import { KeyframeTrack } from "./KeyframeTrack";
import { calculateSnap } from "./utils";
import { useTimelineStore } from "../../../stores/timeline-store";
import { useUIStore } from "../../../stores/ui-store";
+import { useProjectStore } from "../../../stores/project-store";
+import { toast } from "../../../stores/notification-store";
type GraphicClipUnion = ShapeClip | SVGClip | StickerClip;
@@ -107,11 +109,56 @@ export const TrackLane: React.FC<TrackLaneProps> = ({
}, []);
const handleDrop = useCallback(
- (e: React.DragEvent) => {
+ async (e: React.DragEvent) => {
e.preventDefault();
e.stopPropagation();
setIsDragOver(false);
+ // External OS file drop (e.g. from Windows Explorer)
+ if (e.dataTransfer.files && e.dataTransfer.files.length > 0) {
+ const rect = laneRef.current?.getBoundingClientRect();
+ if (!rect) return;
+ const x = e.clientX - rect.left + scrollX;
+ const rawTime = Math.max(0, x / pixelsPerSecond);
+ const snapResult = calculateSnap(
+ rawTime,
+ "",
+ allTracks,
+ playheadPosition,
+ snapSettings,
+ pixelsPerSecond,
+ );
+ const { importMedia, addClipToNewTrack } = useProjectStore.getState();
+ for (const file of Array.from(e.dataTransfer.files)) {
+ try {
+ const beforeIds = new Set(
+ useProjectStore.getState().project.mediaLibrary.items.map(i => i.id)
+ );
+ const result = await importMedia(file);
+ if (result.success) {
+ const newItem = useProjectStore
+ .getState()
+ .project.mediaLibrary.items.find(i => !beforeIds.has(i.id));
+ if (newItem) {
+ await addClipToNewTrack(newItem.id, snapResult.time);
+ const addedTrack = useProjectStore
+ .getState()
+ .project.timeline.tracks.find(t =>
+ t.clips.some(c => c.mediaId === newItem.id)
+ );
+ if (addedTrack) {
+ toast.success(`Added to ${addedTrack.name}`, file.name);
+ }
+ }
+ }
+ } catch (err) {
+ console.error("[TrackLane] External file drop failed:", err);
+ }
+ }
+ return;
+ }
+
+ // Internal drag from assets panel
try {
const rawData = e.dataTransfer.getData("application/json");
if (!rawData) return;