Open source CapCut alternative.
TypeScript
feat(site): paste images and backspace-remove chips in prompt composers
David Leda75585dfe82
diff --git a/site/src/cut/components/AiPanel.tsx b/site/src/cut/components/AiPanel.tsxindex d9c93334..1514520d 100644--- a/site/src/cut/components/AiPanel.tsx+++ b/site/src/cut/components/AiPanel.tsx@@ -549,20 +549,21 @@ function ChatSession({s.run.projectId === projectId &&(!s.run.chatId || s.run.chatId === threadId),);+ // OS files handed to the composer — dropped on it or pasted into it —+ // attach as references (media files import into the project on the way,+ // chat-owned so they stay off the Media panel; text files ride as-is).+ const attachFiles = (files: File[]) => {+ void refsFromDroppedFiles(projectId, files, { chatId: threadId }).then(+ (refs) => setAttachments((prev) => refs.reduce(addRefOnce, prev)),+ );+ };const {active: dropActive,attachTarget,targetProps,} = useAssetDrop((ref) => setAttachments((prev) => addRefOnce(prev, ref)),- // OS files dropped on the chat attach as references (media files import- // into the project on the way, chat-owned so they stay off the Media- // panel; text files ride as-is).- (files) => {- void refsFromDroppedFiles(projectId, files, { chatId: threadId }).then(- (refs) => setAttachments((prev) => refs.reduce(addRefOnce, prev)),- );- },+ attachFiles,);const sessionKeyRef = useRef<string | null>(null);// Resume from the saved thread when this id exists in history.@@ -989,6 +990,8 @@ function ChatSession({onSubmit={() => send(input)}attachedRefs={attachments}onUpsertRef={(ref) => setAttachments((p) => upsertRef(p, ref))}+ onPasteFiles={attachFiles}+ onRemoveLastRef={() => setAttachments((p) => p.slice(0, -1))}/><div className="flex items-center gap-1 px-1.5 pb-1.5"><ModelSelectordiff --git a/site/src/cut/components/AssetRefs.tsx b/site/src/cut/components/AssetRefs.tsxindex 8d6a27b0..4ba8bb13 100644--- a/site/src/cut/components/AssetRefs.tsx+++ b/site/src/cut/components/AssetRefs.tsx@@ -761,6 +761,8 @@ export function MentionTextarea({inputRef,attachedRefs,onUpsertRef,+ onPasteFiles,+ onRemoveLastRef,}: {value: string;onChange: (v: string) => void;@@ -785,6 +787,12 @@ export function MentionTextarea({* makes video/audio mention pills clickable: the pill opens the moment* picker in place, and the pinned ref lands here so it rides at send. */onUpsertRef?: (ref: AssetRef) => void;+ /** Take files pasted into the textarea (a screenshot on the clipboard, an+ * image copied off the web) — same handler as the composer's file drop. */+ onPasteFiles?: (files: File[]) => void;+ /** Backspace with the caret at the very start (nothing selected, nothing to+ * delete leftward) removes the newest attachment chip instead. */+ onRemoveLastRef?: () => void;}) {const taRef = useRef<HTMLTextAreaElement>(null);const rootRef = useRef<HTMLDivElement>(null);@@ -959,8 +967,28 @@ export function MentionTextarea({}}}onSelect={syncCaret}+ onPaste={(e) => {+ if (!onPasteFiles) return;+ const files = Array.from(e.clipboardData.items)+ .filter((item) => item.kind === "file")+ .map((item) => item.getAsFile())+ .filter((f): f is File => f !== null);+ if (files.length === 0) return;+ e.preventDefault();+ onPasteFiles(files);+ }}onKeyDown={(e) => {e.stopPropagation();+ if (+ e.key === "Backspace" &&+ onRemoveLastRef &&+ e.currentTarget.selectionStart === 0 &&+ e.currentTarget.selectionEnd === 0+ ) {+ e.preventDefault();+ onRemoveLastRef();+ return;+ }if (open) {if (e.key === "ArrowDown" || e.key === "ArrowUp") {e.preventDefault();diff --git a/site/src/cut/components/GeneratePanel.tsx b/site/src/cut/components/GeneratePanel.tsxindex 2cf3134e..9d95b4ef 100644--- a/site/src/cut/components/GeneratePanel.tsx+++ b/site/src/cut/components/GeneratePanel.tsx@@ -58,14 +58,16 @@ export function GenerateVideoPanel({ projectId }: { projectId: string }) {const jobs = allJobs.filter((j) => j.projectId === projectId && j.kind === "video" && !j.chatId);const { prompt, refs, character, aspect } = useVideoGen();const candidates = useRefCandidates();+ // OS files handed to the panel — dropped on it or pasted into the prompt —+ // attach as references (media files import into the project on the way;+ // text files ride as-is).+ const attachFiles = (files: File[]) =>+ void refsFromDroppedFiles(projectId, files).then((refs) => {+ for (const r of refs) useVideoGen.getState().addRef(r);+ });const { active: dropActive, attachTarget, targetProps } = useAssetDrop((ref) => useVideoGen.getState().addRef(ref),- // OS files dropped on the panel attach as references (media files import- // into the project on the way; text files ride as-is).- (files) =>- void refsFromDroppedFiles(projectId, files).then((refs) => {- for (const r of refs) useVideoGen.getState().addRef(r);- })+ attachFiles);const [tier, setTier] = useLocalPref<VideoModelOption["tier"]>("cut-gen-tier",@@ -169,6 +171,11 @@ export function GenerateVideoPanel({ projectId }: { projectId: string }) {onSubmit={go}attachedRefs={refs}onUpsertRef={(r) => useVideoGen.getState().updateRef(r)}+ onPasteFiles={attachFiles}+ onRemoveLastRef={() => {+ const last = refs[refs.length - 1];+ if (last) useVideoGen.getState().removeRef(last);+ }}/><DictationControltext={prompt}diff --git a/site/src/cut/components/ImageGenPanel.tsx b/site/src/cut/components/ImageGenPanel.tsxindex 63cde5da..b0ae7089 100644--- a/site/src/cut/components/ImageGenPanel.tsx+++ b/site/src/cut/components/ImageGenPanel.tsx@@ -73,14 +73,16 @@ export function ImageGenPanel({ projectId }: { projectId: string }) {() => assets.filter((a) => a.origin === "generated" && a.type === "image").reverse(),[assets]);+ // OS files handed to the panel — dropped on it or pasted into the prompt —+ // attach as references (media files import into the project on the way;+ // text files ride as-is).+ const attachFiles = (files: File[]) =>+ void refsFromDroppedFiles(projectId, files).then((refs) => {+ for (const r of refs) useImageGen.getState().addRef(r);+ });const { active: dropActive, attachTarget, targetProps } = useAssetDrop((ref) => useImageGen.getState().addRef(ref),- // OS files dropped on the panel attach as references (media files import- // into the project on the way; text files ride as-is).- (files) =>- void refsFromDroppedFiles(projectId, files).then((refs) => {- for (const r of refs) useImageGen.getState().addRef(r);- })+ attachFiles);// Default the size to the project's own orientation when the panel opens, so@@ -132,6 +134,11 @@ export function ImageGenPanel({ projectId }: { projectId: string }) {onSubmit={go}attachedRefs={refs}onUpsertRef={(r) => useImageGen.getState().updateRef(r)}+ onPasteFiles={attachFiles}+ onRemoveLastRef={() => {+ const last = refs[refs.length - 1];+ if (last) useImageGen.getState().removeRef(last);+ }}/><DictationControltext={prompt}