Skip to content

The open-source full-stack studio for Opus 5.5 motion video. Reverse engineering for any video. Code video with HTML: recreate, edit and render. BYOA + BYOK · Motion.md · Images, Video, Music & Voice.

fix(studio): unify feedback for all content insertion drops

罗高afc68f21590a
diff --git a/docs/product/architecture.md b/docs/product/architecture.md
index 53ef4c00..20fe742e 100644
--- a/docs/product/architecture.md
+++ b/docs/product/architecture.md
@@ -22,7 +22,7 @@ Model Gateway remains a shared media-generation backend for MCP, using local Cod
- The composition list places the full video first, preserves the remaining clip order, and marks the live preview target. Queued, loading, missing and failed covers share a muted gray OD placeholder without failure text; decoded covers replace it automatically. A confirmed empty root is omitted from this list using the same loaded-preview content check; when no clips remain, the panel shows a brief empty state. The MVP omits the duplicate preview breadcrumb; composition switching and existing return shortcuts remain available.
- The editor header keeps the OpenDesign logo, drawer toggle and template library on the left (the English entry is Template; Chinese remains 模板库), centers the editable project name, and places undo/redo and export on the right. Clearing the title and committing with blur or Enter saves the localized Untitled default; Escape cancels. A logo-only community link sits immediately before Export and opens the public Discord community in every interface language, with a localized accessible tooltip; external links open separately from the editor. Undo, redo and version history form one visual group with 4px internal gaps; the history group and community retain a 16px button gap. The community-to-Export button gap is 12px (18px from the 16px community icon to the Export edge), shifting only community and the three history icons right by 4px while Export and the other header content stay fixed. A decorative 1px by 16px divider in the shared border color sits between history and community without moving the buttons; it hides with the history group on narrow screens. Transient save/error status remains available. Workspace and export failures show concise causes and available next steps, with raw diagnostics behind expandable, copyable details. Workspace connection failures use a persistent single-line feedback toast at the top center with a Reconnecting status and no buttons or diagnostic details. The Reconnecting ellipsis animates without changing the toast width; reduced-motion preferences keep it static. Automatic polling waits 1.8 seconds after each completed attempt and removes the toast on recovery; it has no overall retry limit or explicit per-request timeout and does not start a stopped service. Other notice dismissal does not bypass write guards. Editor toasts stack at the top center; editor, connection and template-copy feedback share a top-layer host above native dialogs and ordinary overlays, without taking focus. Template-copy feedback retains its existing placement and three-second lifetime; identical notices replace their previous instance. Error toasts use the compact neutral feedback surface and concise recognized causes, with a dismiss button and no details icon or expandable diagnostics. Detailed error panels retain their diagnostic controls. Informational toasts disappear after three seconds without a close control; actionable error notices remain dismissible and do not auto-expire. Save-queue pauses use a brief, localized feedback toast without paths, diagnostics or a retry action; it expires after three seconds without clearing the write guard or claiming that failed edits were saved. The template library reuses the website catalog layout: brand/use-case/video-type facets, configured featured templates, search and sorting, without site navigation, promotional hero or footer. Prism metadata and local cache updates drive the list. The catalog selects the editor locale from a shared multilingual publication, falling back to English and then the Resource default; template-copy prompts support the same eleven UI languages. Previews, author/source links and editable-project opening remain available. The detail view keeps the motion.md download action (`motionDocumentUrl`) above its guide content (`styleDescription`, `reviewFocus`, `motionGuideUrl`). Recreate opens a separate prompt dialog; copied instructions never occupy the guide area.
- The asset panel shows only the current project, with compact search/import controls, type filters, and a dedicated scrollable list. User-uploaded audio rows in My assets show full filenames with their original extensions and wrap long names within the panel; the generic Audio label is omitted, while duration and specific BGM/SFX/Voice labels remain when available. Official library sources and presentation are unchanged. Assets referenced by the current composition carry an In use badge (已使用 in Chinese); unused assets have no badge. MVP My assets deletion invokes the existing file-deletion handler directly from the menu, without a second confirmation; the full editor retains its confirmation. This does not introduce a new undo mechanism or alter official catalog assets. Usage filtering is omitted; used assets still sort first within each type. In both My assets and the official animation library, hover plays only the card thumbnail, while clicking opens a centered modal preview over a gray full-editor backdrop. The modal reuses Studio-styled playback, volume and speed controls; its play button stays centered, and speed/loop controls hide below 420px to avoid overlap. Volume and loop icons are 16px inside 28px buttons, and playback speed text is 12px; closing it restores access to the paused composition; previewing media does not add it to the project. The global cache view remains in source but has no editor entry in the MVP.
-- Each accepted project-asset, composition-list or catalog-block drop immediately shows a transient loading clip at its timeline placement, including an empty timeline. It remains until the saved clip appears; failures remain at the placement with a dismiss action. Repeated drops create independent clips; composition insertions and catalog installs queue their writes while each accepted drop keeps its own visible placeholder instead of relying on a transient progress toast. Composition placeholders settle to the native insertion's actual track and duration; switching composition or project invalidates queued insertions and old selection changes. Known drag metadata bypasses duration probing, and concurrent requests for the same project asset share one in-flight probe without coalescing insertions. Unreadable durations fail visibly instead of inserting a five-second clip. Placeholders never enter project source or undo history.
+- All supported content-insertion drops share persistent timeline feedback, including project images/video/audio, the composition list, official catalog items dropped on the timeline or preview, and local files dropped on the timeline or editor shell. Accepted drops immediately show a transient loading clip, including in an empty timeline; it remains until the saved clip appears, and failures remain dismissible at the placement. A local-file batch shows an upload placeholder immediately, then hands off without an empty frame to separate placeholders for the accepted uploaded paths; rejected files retain the upload handler's existing error feedback. Uploads retain the existing single multipart request. Catalog insertion buttons and overlays use the same state instead of progress toasts. Feedback starts at the requested time, reserves space between pending drops, and settles to the saved host identity, duration and placement once metadata and native collision resolution finish. Repeated drops remain independent. Composition insertions and catalog installs queue their writes; switching composition or project invalidates queued insertions and old selection changes. Known drag metadata bypasses duration probing, and concurrent requests for the same project asset share one in-flight probe without coalescing insertions. Unreadable durations fail visibly instead of inserting a five-second clip. Placeholders never enter project source or undo history. Drops on the Assets panel import files without inserting timeline content and retain that panel's importing state.
- Panel positions are fixed. Export settings and render history live in a compact popover below the header Export button, outside the right panel. Both side groups can temporarily collapse into 48px vertical icon rails, giving their width to preview; the rail toggle restores the previous width and tab, while a module icon opens that module. Collapse does not remove panels or remount the player. Opening the MVP starts both sides collapsed and the timeline at 30% of the available dock height (subject to minimum sizes); users can then drag the divider to enlarge or reduce it. The fixed layout reserves at least 360px for preview, 260px for each expanded side panel. Side availability retains the existing conservative breakpoints, independently of the resizable minimums: below 740px both side groups and rails hide; from 740px to 1011px only one side can expand; wider hosts allow both only when their requested widths leave the preview floor intact. Opening a side through a toggle, module shortcut or programmatic activation uses the same fit check and closes the opposite side when necessary. Shrinking the host collapses expanded sides when they no longer fit; widening restores collapsed rails without automatically reopening panels. At widths smaller than the preview floor, preview uses the available workspace. Remembered expanded side widths remain available when reopening a side. Divider hover and drag change only the thin line to green. Divider resizing and per-project expanded-size persistence remain; panel movement, closing and layout presets are absent. Preview alone can temporarily expand within the editor workspace, keeping the host chat visible and the player mounted. Its header button or Escape restores the previous layout and playback position; expansion is not persisted across reloads.
- MVP controls share a locally bundled Remix Icon 4.9.1 set with the reference design system. Menu selections consistently use check icons, and the language menu is 180px wide. Expanded side-panel tabs remain text-only; collapsed rails use the corresponding panel icons. Brand artwork and timeline geometry are separate from control icons.
- The editor startup shell and project/editor loading boundaries share a centered, theme-aware OD symbol without adding a minimum loading delay. Below 700px of workspace content width, the editor header stays on one row: undo/redo and version history hide, the template library becomes icon-only, the project title truncates, and Export stays at the right edge.
diff --git a/studio/src/hooks/useBlockHandlers.test.tsx b/studio/src/hooks/useBlockHandlers.test.tsx
index ca406482..5b683088 100644
--- a/studio/src/hooks/useBlockHandlers.test.tsx
+++ b/studio/src/hooks/useBlockHandlers.test.tsx
@@ -4,6 +4,7 @@ import React, { act } from "react";
import { afterEach, describe, expect, it, vi } from "vitest";
import { mountReactHarness } from "./domSelectionTestHarness";
import { useBlockHandlers, type UseBlockHandlersResult } from "./useBlockHandlers";
+import { usePlayerStore } from "../player/store/playerStore";
(globalThis as unknown as { IS_REACT_ACT_ENVIRONMENT: boolean }).IS_REACT_ACT_ENVIRONMENT = true;
@@ -16,6 +17,7 @@ vi.mock("../utils/blockInstaller", () => ({
afterEach(() => {
document.body.innerHTML = "";
+ usePlayerStore.getState().reset();
});
describe("useBlockHandlers", () => {
@@ -56,10 +58,9 @@ describe("useBlockHandlers", () => {
});
expect(events).toEqual([
- "show Adding x-post…",
"show Installing catalog items needs hyperframes preview",
- "dismiss 1",
]);
+ expect(usePlayerStore.getState().pendingAssetDrops[0].failed).toBe("add");
act(() => root.unmount());
});
});
diff --git a/studio/src/hooks/useBlockHandlers.ts b/studio/src/hooks/useBlockHandlers.ts
index 86b7f551..78a3cf8c 100644
--- a/studio/src/hooks/useBlockHandlers.ts
+++ b/studio/src/hooks/useBlockHandlers.ts
@@ -10,7 +10,7 @@ import { selectAndRevealTimelineElement } from "../player/components/timelineDro
import type { BlockParam } from "@hyperframes/core/registry";
import type { RightPanelTab } from "../utils/studioHelpers";
import type { MediaOverlayPlacement } from "../components/editor/propertyPanelTypes";
-import { beginPendingAssetDrop, updatePendingAssetDrop } from "../player/store/pendingAssetDrops";
+import { beginPendingAssetDrop, finishPendingAssetDrop } from "../player/store/pendingAssetDrops";
interface BlockCtxDeps {
activeCompPath: string | null;
@@ -95,39 +95,37 @@ export function useBlockHandlers({
scopeRef.current = scope;
return () => { scopeRef.current = null; };
}, [scope]);
- const { showToast, dismissToast } = blockCtxDeps;
+ const { showToast } = blockCtxDeps;
const runBlockInstall = useCallback(
- (blockName: string, install: () => ReturnType<typeof addBlockToProject>, pendingId?: string) => {
+ (blockName: string, install: () => ReturnType<typeof addBlockToProject>, placement: { start: number; track?: number; duration?: number } = {
+ start: usePlayerStore.getState().currentTime, track: 0,
+ }) => {
+ const pendingId = beginPendingAssetDrop(blockName, { start: placement.start, track: placement.track ?? 0 }, placement.duration);
const work = installQueueRef.current.then(async () => {
if (scopeRef.current !== scope) return null;
- const progress = pendingId ? null : showToast(`Adding ${blockName}…`, "info");
try {
const result = await install();
if (scopeRef.current !== scope) return null;
- if (pendingId) updatePendingAssetDrop(pendingId, result
- ? { element: result.element, duration: result.element.duration,
- placement: { start: result.element.start, track: result.element.track } }
- : { failed: "add" });
+ finishPendingAssetDrop(pendingId, result?.element);
return result;
} catch (error) {
if (scopeRef.current === scope) {
- if (pendingId) updatePendingAssetDrop(pendingId, { failed: "add" });
+ finishPendingAssetDrop(pendingId);
showToast(error instanceof Error ? error.message : "Failed to add block", "error");
}
return null;
- } finally {
- if (progress !== null) dismissToast(progress);
}
});
installQueueRef.current = work.then(() => undefined, () => undefined);
return work;
},
- [showToast, dismissToast, scope],
+ [showToast, scope],
);
const handleAddBlock = useCallback(
(blockName: string) => {
if (!projectId) return;
+ const currentTime = usePlayerStore.getState().currentTime;
// fallow-ignore-next-line complexity
void (async () => {
const result = await runBlockInstall(blockName, () =>
@@ -136,7 +134,7 @@ export function useBlockHandlers({
blockName,
...blockCtx,
previewIframe: previewIframeRef.current,
- currentTime: usePlayerStore.getState().currentTime,
+ currentTime,
}),
);
if (result === null) return;
@@ -159,7 +157,6 @@ export function useBlockHandlers({
const handleTimelineBlockDrop = useCallback(
async (blockName: string, placement: { start: number; track: number }) => {
if (!projectId) return;
- const pendingId = beginPendingAssetDrop(blockName, placement);
const result = await runBlockInstall(blockName, () =>
addBlockToProject({
projectId,
@@ -168,7 +165,7 @@ export function useBlockHandlers({
...blockCtx,
previewIframe: previewIframeRef.current,
currentTime: usePlayerStore.getState().currentTime,
- }), pendingId,
+ }), placement,
);
if (result) selectAndRevealTimelineElement(result.hostKey);
},
@@ -188,7 +185,7 @@ export function useBlockHandlers({
placement: timelinePlacement,
previewIframe: previewIframeRef.current,
currentTime: usePlayerStore.getState().currentTime,
- }),
+ }), timelinePlacement,
);
},
[projectId, blockCtx, previewIframeRef, runBlockInstall],
@@ -197,6 +194,7 @@ export function useBlockHandlers({
const handlePreviewBlockDrop = useCallback(
(blockName: string, position: { left: number; top: number }) => {
if (!projectId) return;
+ const currentTime = usePlayerStore.getState().currentTime;
void runBlockInstall(blockName, () =>
addBlockToProject({
projectId,
@@ -204,7 +202,7 @@ export function useBlockHandlers({
visualPosition: position,
...blockCtx,
previewIframe: previewIframeRef.current,
- currentTime: usePlayerStore.getState().currentTime,
+ currentTime,
}),
).then((result) => {
if (result) selectAndRevealTimelineElement(result.hostKey);
diff --git a/studio/src/hooks/useTimelineAssetDropFeedback.test.tsx b/studio/src/hooks/useTimelineAssetDropFeedback.test.tsx
index 11ddb1a0..45cea9bc 100644
--- a/studio/src/hooks/useTimelineAssetDropFeedback.test.tsx
+++ b/studio/src/hooks/useTimelineAssetDropFeedback.test.tsx
@@ -9,6 +9,7 @@ import { installTimelineMountEnv } from "../player/components/timelineMountTestE
import { I18nProvider } from "../i18n/I18n";
import type { TimelineElement } from "../player";
import { failPendingAssetPreviews } from "../player/store/pendingAssetDrops";
+import * as studioHelpers from "../utils/studioHelpers";
(globalThis as { IS_REACT_ACT_ENVIRONMENT?: boolean }).IS_REACT_ACT_ENVIRONMENT = true;
installTimelineMountEnv();
@@ -21,7 +22,7 @@ afterEach(() => {
document.body.replaceChildren();
});
-function mountDropEditor(elements: TimelineElement[] = []) {
+function mountDropEditor(elements: TimelineElement[] = [], uploadProjectFiles: (files: Iterable<File>) => Promise<string[]> = vi.fn()) {
let source = '<main data-composition-id="scene" data-duration="30"></main>';
const write = vi.fn(async (_path: string, content: string) => { source = content; });
const recordEdit = vi.fn(async () => {});
@@ -34,7 +35,7 @@ function mountDropEditor(elements: TimelineElement[] = []) {
const timelineElements = usePlayerStore((state) => state.elements);
handlers = useTimelineAssetDropOps({
projectIdRef, activeCompPath: path, timelineElements, showToast,
- writeProjectFile: write, recordEdit, reloadPreview: vi.fn(), uploadProjectFiles: vi.fn(),
+ writeProjectFile: write, recordEdit, reloadPreview: vi.fn(), uploadProjectFiles,
});
return <I18nProvider initialLocale="zh-CN"><Timeline onAssetDrop={handlers.handleTimelineAssetDrop} /></I18nProvider>;
}
@@ -46,6 +47,7 @@ function mountDropEditor(elements: TimelineElement[] = []) {
return {
host, write, recordEdit, showToast,
drop: (...args: Parameters<typeof handlers.handleTimelineAssetDrop>) => handlers.handleTimelineAssetDrop(...args),
+ files: (...args: Parameters<typeof handlers.handleTimelineFileDrop>) => handlers.handleTimelineFileDrop(...args),
switchComposition: () => act(() => root.render(<Editor path="other.html" />)),
source: () => source,
placeholders: () => Array.from(host.querySelectorAll<HTMLElement>('[data-testid="timeline-pending-asset"]')),
@@ -53,6 +55,49 @@ function mountDropEditor(elements: TimelineElement[] = []) {
}
describe("timeline asset drop feedback", () => {
+ it.each(["picture.png", "video.mp4", "sound.mp3"])("keeps identical feedback through saving for %s", async name => {
+ vi.spyOn(studioHelpers, "resolveDroppedAssetHasAudio").mockResolvedValue(false);
+ const view = mountDropEditor([{ id: "existing", tag: name.endsWith("mp3") ? "audio" : "div", start: 0, duration: 30, track: 0 }]);
+ let save!: () => void;
+ view.write.mockImplementation(() => new Promise<void>(resolve => { save = resolve; }));
+ let task!: Promise<void>;
+ await act(async () => { task = view.drop(`assets/${name}`, { start: 2, track: 0 }, 5); });
+ expect(view.placeholders()).toHaveLength(1);
+ expect(view.placeholders()[0].getAttribute("aria-busy")).toBe("true");
+ expect(view.showToast).not.toHaveBeenCalled();
+ await act(async () => { save(); await task; });
+ const element = usePlayerStore.getState().pendingAssetDrops[0].element!;
+ expect(view.placeholders()).toHaveLength(1);
+ act(() => usePlayerStore.setState({ elements: [element], timelineReady: true }));
+ expect(view.placeholders()).toHaveLength(0);
+ });
+
+ it("shows upload feedback immediately, then keeps every accepted file visible through queued saves", async () => {
+ let upload!: (paths: string[]) => void;
+ const view = mountDropEditor([], () => new Promise(resolve => { upload = resolve; }));
+ let task!: Promise<void>;
+ act(() => { task = view.files([new File(["x"], "one.png"), new File(["x"], "two.png")], { start: 0, track: 0 }); });
+ expect(view.placeholders()).toHaveLength(1);
+ expect(view.placeholders()[0].getAttribute("aria-label")).toContain("one.png · two.png");
+ expect(view.write).not.toHaveBeenCalled();
+ await act(async () => { upload(["one.png", "two.png"]); await task; });
+ expect(view.placeholders()).toHaveLength(2);
+ const elements = usePlayerStore.getState().pendingAssetDrops.map(drop => drop.element!);
+ expect(elements.every(Boolean)).toBe(true);
+ expect(new Set(elements.map(element => element.key)).size).toBe(2);
+ act(() => usePlayerStore.setState({ elements, timelineReady: true }));
+ expect(view.placeholders()).toHaveLength(0);
+ });
+
+ it("leaves upload rejection visible and clears pending uploads on composition change", async () => {
+ const view = mountDropEditor([], async () => []);
+ await act(async () => view.files([new File(["x"], "one.png")]));
+ expect(view.placeholders()[0].getAttribute("role")).toBe("alert");
+ view.switchComposition();
+ expect(view.placeholders()).toHaveLength(0);
+ expect(view.write).not.toHaveBeenCalled();
+ });
+
it("shows each repeated audio drop immediately, shares probing, and replaces each only when its clip appears", async () => {
const view = mountDropEditor();
const createElement = document.createElement.bind(document);
diff --git a/studio/src/hooks/useTimelineAssetDropOps.ts b/studio/src/hooks/useTimelineAssetDropOps.ts
index 25ea54b7..2214573d 100644
--- a/studio/src/hooks/useTimelineAssetDropOps.ts
+++ b/studio/src/hooks/useTimelineAssetDropOps.ts
@@ -30,7 +30,7 @@ import { extendRootDurationInSource } from "../utils/rootDuration";
import { deriveTimelineStoreKeyForDomId } from "../player/lib/timelineElementHelpers";
import { selectAndRevealTimelineElement } from "../player/components/timelineDropReveal";
import { usePlayerStore } from "../player/store/playerStore";
-import { beginPendingAssetDrop, updatePendingAssetDrop } from "../player/store/pendingAssetDrops";
+import { beginPendingAssetDrop, dismissPendingAssetDrop, finishPendingAssetDrop, isPendingAssetDropActive, updatePendingAssetDrop } from "../player/store/pendingAssetDrops";
/** The first uploaded file opens the new track (if asked); each next one aims right after the previous. */
function fileDropPlacement(
@@ -119,13 +119,16 @@ export function useTimelineAssetDropOps({
placement: TimelineDropPlacement,
durationOverride?: number,
gesture: DropGesture = { placed: [], onNewTrack: false },
+ existingPendingId?: string,
): Promise<TimelineElement | undefined> => {
if (isRecordingRef?.current) {
+ if (existingPendingId) finishPendingAssetDrop(existingPendingId);
showToast("Cannot edit timeline while recording", "error");
return undefined;
}
const targetPath = activeCompPath || "index.html";
if (checkEditable && !checkEditable([timelineDropTarget(targetPath, placement)])) {
+ if (existingPendingId) finishPendingAssetDrop(existingPendingId);
return undefined;
}
const pid = projectIdRef.current;
@@ -133,12 +136,13 @@ export function useTimelineAssetDropOps({
const kind = getTimelineAssetKind(assetPath);
if (!kind) {
+ if (existingPendingId) finishPendingAssetDrop(existingPendingId);
showToast("Only image, video, and audio assets can be dropped onto the timeline.");
return undefined;
}
- const pendingId = beginPendingAssetDrop(assetPath, placement, durationOverride);
- const stillActive = () => usePlayerStore.getState().pendingAssetDrops.some((drop) => drop.id === pendingId);
+ const pendingId = existingPendingId ?? beginPendingAssetDrop(assetPath, placement, durationOverride);
+ const stillActive = () => isPendingAssetDropActive(pendingId);
try {
const normalizedStart = Number(formatTimelineAttributeNumber(placement.start));
const duration =
@@ -227,7 +231,7 @@ export function useTimelineAssetDropOps({
id: newId, key, domId: newId, sourceFile: targetPath,
tag, start, duration: normalizedDuration, track: lane, authoredTrack: track,
};
- updatePendingAssetDrop(pendingId, { element });
+ finishPendingAssetDrop(pendingId, element);
if (!stillActive()) return element;
selectAndRevealTimelineElement(key);
forceReloadSdkSession?.();
@@ -235,7 +239,7 @@ export function useTimelineAssetDropOps({
return element;
} catch (error) {
if (!stillActive()) return undefined;
- updatePendingAssetDrop(pendingId, { failed: "add" });
+ finishPendingAssetDrop(pendingId);
const message =
error instanceof Error ? error.message : "Failed to drop asset onto timeline";
showToast(message);
@@ -268,6 +272,7 @@ export function useTimelineAssetDropOps({
const handleTimelineFileDrop = useCallback(
// fallow-ignore-next-line complexity
async (files: File[], placement?: TimelineDropPlacement) => {
+ if (!files.length) return;
if (isRecordingRef?.current) {
showToast("Cannot edit timeline while recording", "error");
return;
@@ -280,16 +285,31 @@ export function useTimelineAssetDropOps({
const pid = projectIdRef.current;
if (!pid) return;
const scope = dropScopeRef.current;
- const uploaded = await uploadProjectFiles(files);
+ const uploadingId = beginPendingAssetDrop(files.map(file => file.name).join(" · "), initialPlacement);
+ let uploaded: string[];
+ try { uploaded = await uploadProjectFiles(files); }
+ catch (error) {
+ if (!isPendingAssetDropActive(uploadingId)) return;
+ finishPendingAssetDrop(uploadingId);
+ showToast(error instanceof Error ? error.message : "Upload failed: network error", "error");
+ return;
+ }
if (scope !== dropScopeRef.current) return;
- if (uploaded.length === 0) return;
+ if (uploaded.length === 0) { finishPendingAssetDrop(uploadingId); return; }
+ // The upload returns accepted paths only; do not guess which rejected filename they replace.
+ dismissPendingAssetDrop(uploadingId);
+ const pendingIds = uploaded.map(path => beginPendingAssetDrop(path, initialPlacement));
const gesture: DropGesture = { placed: [], onNewTrack: false };
for (const [index, assetPath] of uploaded.entries()) {
+ if (scope !== dropScopeRef.current) return;
+ const nextPlacement = fileDropPlacement(index, initialPlacement, placement, gesture.placed.at(-1));
+ updatePendingAssetDrop(pendingIds[index], { placement: nextPlacement });
const clip = await dropAssetAt(
assetPath,
- fileDropPlacement(index, initialPlacement, placement, gesture.placed.at(-1)),
+ nextPlacement,
undefined,
gesture,
+ pendingIds[index],
);
if (!clip) continue;
gesture.placed.push(clip);
@@ -320,7 +340,7 @@ export function useTimelineAssetDropOps({
const pid = projectIdRef.current;
if (!pid) throw new Error("No active project");
const pendingId = beginPendingAssetDrop(sourcePath, placement);
- const isActive = () => usePlayerStore.getState().pendingAssetDrops.some((drop) => drop.id === pendingId);
+ const isActive = () => isPendingAssetDropActive(pendingId);
try {
const element = await commitTimelineCompositionInsertion({
projectId: pid,
@@ -336,13 +356,10 @@ export function useTimelineAssetDropOps({
refresh: reloadPreview,
isActive,
});
- if (element && isActive()) updatePendingAssetDrop(pendingId, {
- element, duration: element.duration,
- placement: { start: element.start, track: element.track },
- });
+ if (element && isActive()) finishPendingAssetDrop(pendingId, element);
} catch (error) {
if (!isActive()) return;
- updatePendingAssetDrop(pendingId, { failed: "add" });
+ finishPendingAssetDrop(pendingId);
showToast(compositionInsertionFailureMessage(error), "error");
}
},
diff --git a/studio/src/hooks/useTimelineBlockDropFeedback.test.tsx b/studio/src/hooks/useTimelineBlockDropFeedback.test.tsx
index 976bf576..c513bea2 100644
--- a/studio/src/hooks/useTimelineBlockDropFeedback.test.tsx
+++ b/studio/src/hooks/useTimelineBlockDropFeedback.test.tsx
@@ -65,6 +65,9 @@ function mountEditor() {
return {
host, files, installs, installed, showToast, reloadPreview, recordEdit,
drop: (start = 0) => handlers.handleTimelineBlockDrop("sparkle", { start, track: 0 }),
+ previewDrop: () => handlers.handlePreviewBlockDrop("sparkle", { left: 100, top: 120 }),
+ add: () => handlers.handleAddBlock("sparkle"),
+ overlay: () => handlers.handleAddMediaOverlay("sparkle", { start: 3, track: 1, duration: 4 }),
switchComposition: () => act(() => root.render(<Editor path="other.html" />)),
unmount: () => act(() => root.unmount()),
placeholders: () => host.querySelectorAll('[data-testid="timeline-pending-asset"]'),
@@ -72,6 +75,21 @@ function mountEditor() {
}
describe("catalog block drop feedback", () => {
+ it.each(["previewDrop", "add", "overlay"] as const)("uses the same pending clip for the %s entry instead of a progress toast", async entry => {
+ const view = mountEditor();
+ act(() => { view[entry](); });
+ expect(view.placeholders()).toHaveLength(1);
+ await act(async () => {});
+ expect(view.installs).toHaveLength(1);
+ expect(view.showToast).not.toHaveBeenCalled();
+ await act(async () => view.installs[0].resolve(view.installed()));
+ const element = usePlayerStore.getState().pendingAssetDrops[0].element!;
+ expect(element.key).toBe("index.html#sparkle");
+ expect(view.placeholders()).toHaveLength(1);
+ act(() => usePlayerStore.setState({ elements: [element], timelineReady: true }));
+ expect(view.placeholders()).toHaveLength(0);
+ });
+
it("keeps the actual block drag's placeholder after mouse release until the inserted clip is usable", async () => {
const view = mountEditor();
const target = view.host.querySelector(".h-full.border-t")!;
diff --git a/studio/src/player/store/pendingAssetDrops.ts b/studio/src/player/store/pendingAssetDrops.ts
index 1741dfa7..bd7ea96e 100644
--- a/studio/src/player/store/pendingAssetDrops.ts
+++ b/studio/src/player/store/pendingAssetDrops.ts
@@ -22,15 +22,13 @@ export function beginPendingAssetDrop(
const id = generateId();
usePlayerStore.setState((state) => {
const kind = getTimelineAssetKind(assetPath);
- const pending = state.pendingAssetDrops.filter((drop) =>
+ // Show feedback at the drop time; the save resolves collisions once metadata is known.
+ const busy = state.pendingAssetDrops.filter((drop) =>
(!drop.failed || drop.element) && drop.placement.insertRow === placement.insertRow,
).map((drop) => drop.element ?? {
id: drop.id, tag: getTimelineAssetKind(drop.assetPath) ?? "div",
...drop.placement, duration: drop.duration ?? 5,
- });
- // Native composition insertion chooses a free track at the requested time.
- const busy = [...(kind && placement.insertRow == null ? state.elements : []), ...pending]
- .filter((element) => (element.tag === "audio") === (kind === "audio"));
+ }).filter((element) => (element.tag === "audio") === (kind === "audio"));
const start = resolveNearestFreeStart(busy, placement.track, placement.start, duration ?? 5, null);
return { pendingAssetDrops: [...state.pendingAssetDrops, {
id, assetPath, placement: { ...placement, start }, duration,
@@ -45,6 +43,17 @@ export function updatePendingAssetDrop(id: string, patch: Partial<PendingAssetDr
}));
}
+export function isPendingAssetDropActive(id: string): boolean {
+ return usePlayerStore.getState().pendingAssetDrops.some((drop) => drop.id === id);
+}
+
+export function finishPendingAssetDrop(id: string, element?: TimelineElement): void {
+ updatePendingAssetDrop(id, element ? {
+ element, duration: element.duration,
+ placement: { start: element.start, track: element.track },
+ } : { failed: "add" });
+}
+
export function dismissPendingAssetDrop(id: string): void {
usePlayerStore.setState((state) => ({
pendingAssetDrops: state.pendingAssetDrops.filter((drop) => drop.id !== id),
diff --git a/studio/tests/e2e/catalog-drop-loading.mjs b/studio/tests/e2e/catalog-drop-loading.mjs
index f2530c7a..735f7508 100644
--- a/studio/tests/e2e/catalog-drop-loading.mjs
+++ b/studio/tests/e2e/catalog-drop-loading.mjs
@@ -111,7 +111,35 @@ try {
await page.waitForSelector('[data-testid="timeline-pending-asset"][role="alert"][aria-busy="false"]');
await page.screenshot({ path: path.join(output, 'failed.png') });
assert.equal((await readFile(entry, 'utf8')).match(/data-composition-src=/g).length, 2);
- const result = { status: 'PASS', scope: 'Production editor, native saves/history and preview; controlled catalog list and download response only', sampledFrames: samples.length, noEmptyFrames: true, repeatedClips: 2, failureVisible: true };
+ await page.click('[data-testid="timeline-pending-asset"][role="alert"] button');
+ const previewDrop = () => page.evaluate(() => {
+ const card = document.querySelector('[data-motion-catalog] [draggable]');
+ const target = document.querySelector('[data-preview-pan-surface]');
+ const transfer = new DataTransfer();
+ card.dispatchEvent(new DragEvent('dragstart', { bubbles: true, dataTransfer: transfer }));
+ const rect = target.getBoundingClientRect();
+ const options = { bubbles: true, cancelable: true, dataTransfer: transfer, clientX: rect.left + rect.width / 2, clientY: rect.top + rect.height / 2 };
+ target.dispatchEvent(new DragEvent('dragenter', options));
+ target.dispatchEvent(new DragEvent('dragover', options));
+ target.dispatchEvent(new DragEvent('drop', options));
+ card.dispatchEvent(new DragEvent('dragend', options));
+ });
+ await previewDrop();
+ await page.waitForSelector('[data-testid="timeline-pending-asset"][aria-busy="true"]');
+ await previewDrop();
+ await page.waitForFunction(() => document.querySelectorAll('[data-testid="timeline-pending-asset"]').length === 2);
+ assert.equal(await page.$$eval('.hf-toast-enter[role="status"]', nodes => nodes.length), 0);
+ await page.screenshot({ path: path.join(output, 'preview-drop-pending.png') });
+ for (let attempt = 0; attempt < 100 && requests.length < 4; attempt++) await new Promise(resolve => setTimeout(resolve, 50));
+ assert.equal(requests.length, 4);
+ await fulfill(requests[3], 4);
+ for (let attempt = 0; attempt < 100 && requests.length < 5; attempt++) await new Promise(resolve => setTimeout(resolve, 50));
+ assert.equal(requests.length, 5);
+ await fulfill(requests[4], 5);
+ await page.waitForFunction(() => !document.querySelector('[data-testid="timeline-pending-asset"]') && !!document.querySelector('[data-el-id="index.html#loading-test_4"]'), { timeout: 30000 });
+ assert.equal((await readFile(entry, 'utf8')).match(/data-composition-src=/g).length, 4);
+ await page.screenshot({ path: path.join(output, 'preview-drop-ready.png') });
+ const result = { status: 'PASS', scope: 'Production editor timeline and preview drops, native saves/history and preview; controlled catalog list and download response only', sampledFrames: samples.length, noEmptyFrames: true, repeatedClips: 2, failureVisible: true, previewDrops: 2 };
await writeFile(path.join(output, 'browser-result.json'), JSON.stringify(result, null, 2));
console.log(JSON.stringify(result));
} catch (error) {
diff --git a/studio/tests/e2e/composition-drop-loading.mjs b/studio/tests/e2e/composition-drop-loading.mjs
index 72e8e99e..b6f9c6f5 100644
--- a/studio/tests/e2e/composition-drop-loading.mjs
+++ b/studio/tests/e2e/composition-drop-loading.mjs
@@ -23,10 +23,13 @@ await writeFile(entry, `<!doctype html><html><head><script src="assets/gsap.min.
const native = await startWorkspaceStudio(root, store.directory, store.projectDirectory, Number(process.env.D4_LANE_API_PORT));
const studio = { url: native.origin, alive: () => true, projectDirectory: store.projectDirectory };
const requests = [];
+const uploads = [];
const server = createServer((req, res) => {
const forward = () => handler(req, res, store, { studio, runtimeRoot: root, nativeRoot: root, ffmpeg: true, ensureStudio: async () => studio });
if (req.method === 'POST' && req.url.includes('/file-mutations/insert-composition/')) {
requests.push({ forward });
+ } else if (req.method === 'POST' && req.url.endsWith('/upload')) {
+ uploads.push({ forward });
} else void forward();
});
await new Promise(resolve => server.listen(Number(process.env.PLAYWRIGHT_WEB_PORT), '127.0.0.1', resolve));
@@ -125,7 +128,48 @@ try {
await page.waitForSelector('[data-testid="timeline-pending-asset"][role="alert"][aria-busy="false"]');
assert.equal((await readFile(entry, 'utf8')).match(/data-composition-src=/g).length, 2);
await page.screenshot({ path: path.join(output, 'composition-failed.png') });
- const result = { status: 'PASS', scope: 'Real composition-list drag payload, native insertions/history and preview; requests delayed, responses never mocked', sampledFrames: samples.length, eachDropHasNoEmptyFrame: true, repeatedClips: 2, nativeCycleErrorVisible: true };
+ await page.click('[data-testid="timeline-pending-asset"][role="alert"] button');
+ await page.evaluate(async () => {
+ window.__uploadSamples = [];
+ const sample = () => {
+ const visible = node => {
+ const box = node.getBoundingClientRect(), view = node.closest('[data-timeline-scroll-viewport]').getBoundingClientRect();
+ return box.right > view.left && box.left < view.right && box.bottom > view.top && box.top < view.bottom;
+ };
+ window.__uploadSamples.push({
+ pending: [...document.querySelectorAll('[data-testid="timeline-pending-asset"]')].filter(visible).map(node => node.getAttribute('aria-label')),
+ clips: [...document.querySelectorAll('[data-clip="true"]')].filter(visible).map(node => node.dataset.elId),
+ });
+ window.__uploadSampleFrame = requestAnimationFrame(sample);
+ };
+ sample();
+ const canvas = document.createElement('canvas'); canvas.width = 16; canvas.height = 16;
+ canvas.getContext('2d').fillRect(0, 0, 16, 16);
+ const blob = await new Promise(resolve => canvas.toBlob(resolve, 'image/png'));
+ const transfer = new DataTransfer();
+ transfer.items.add(new File([blob], 'upload-one.png', { type: 'image/png' }));
+ transfer.items.add(new File([blob], 'upload-two.png', { type: 'image/png' }));
+ const target = document.querySelector('[data-timeline-scroll-viewport]'), rect = target.getBoundingClientRect();
+ const options = { bubbles: true, cancelable: true, dataTransfer: transfer, clientX: rect.left + 640, clientY: rect.top + 64 };
+ target.dispatchEvent(new DragEvent('dragover', options));
+ target.dispatchEvent(new DragEvent('drop', options));
+ });
+ await page.waitForSelector('[data-testid="timeline-pending-asset"][aria-busy="true"]');
+ await new Promise(resolve => setTimeout(resolve, 1000));
+ assert.equal(uploads.length, 1, 'Keep the existing single multipart upload');
+ assert.equal(await page.$$eval('[data-testid="timeline-pending-asset"]', nodes => nodes.length), 1);
+ await page.screenshot({ path: path.join(output, 'upload-pending.png') });
+ await uploads[0].forward();
+ await page.waitForFunction(() => !document.querySelector('[data-testid="timeline-pending-asset"]') && !!document.querySelector('[data-el-id="index.html#upload-two"]'), { timeout: 30000 });
+ const uploadSamples = await page.evaluate(() => { cancelAnimationFrame(window.__uploadSampleFrame); return window.__uploadSamples; });
+ for (const name of ['upload-one', 'upload-two']) {
+ const accepted = uploadSamples.findIndex(sample => sample.pending.some(label => label.includes(name)));
+ assert.ok(accepted >= 0);
+ assert.ok(uploadSamples.slice(accepted).every(sample => sample.pending.some(label => label.includes(name)) || sample.clips.includes(`index.html#${name}`)), `No empty frame from upload to committed clip: ${name}`);
+ }
+ assert.equal((await readFile(entry, 'utf8')).match(/<img\s/g).length, 2);
+ await page.screenshot({ path: path.join(output, 'upload-ready.png') });
+ const result = { status: 'PASS', scope: 'Real composition-list drag, batch file upload, native saves/history and preview; requests delayed, responses never mocked', sampledFrames: samples.length, eachDropHasNoEmptyFrame: true, repeatedClips: 2, nativeCycleErrorVisible: true, uploadFrames: uploadSamples.length, uploadFiles: 2, uploadHasNoEmptyFrame: true };
await writeFile(path.join(output, 'browser-result.json'), JSON.stringify(result, null, 2));
console.log(JSON.stringify(result));
} catch (error) {