The open creative studio on ComfyUI: images, video, 3D and audio on open weights, on your own GPU or the cloud. Camera motions, effects, apps, Cinema, Layers, Image to 3D and an AI agent.
TypeScript ai-videocomfyuicreative-toolsgenerative-aiideogramimage-generationimage-to-3dimage-to-videoltx-videominimax-h3nextjsopen-sourceopen-weightsqwen-imagetext-to-imagevideo-generationwan
Clipboard: every Copy button goes through copyText, so copying works on plain-http LAN addresses
Claudec524d0aa70bd
diff --git a/src/components/cinema/cinema-feed.tsx b/src/components/cinema/cinema-feed.tsxindex 67d7fea7..965a4de0 100644--- a/src/components/cinema/cinema-feed.tsx+++ b/src/components/cinema/cinema-feed.tsx@@ -53,6 +53,7 @@ import type { CinemaFolder } from "@/lib/catalog/cinema";import type { Generation, OutputFile } from "@/lib/catalog/types";import { formatCost, timeAgo } from "@/lib/format";import { cn } from "@/lib/utils";+import { copyWithToast } from "@/lib/clipboard";import { MoveToItems } from "./folder-sidebar";import { foreign, useItemActions, type CinemaGeneration } from "./hooks";@@ -224,10 +225,7 @@ function TileMenu({ u, folders, projectId, handlers, onDelete }: { u: Unit; fold<Heart /> {u.g.favorite ? "Unlike" : "Like"}</DropdownMenuItem><DropdownMenuItem- onClick={() => {- void navigator.clipboard.writeText(u.g.prompt ?? "");- toast("Prompt copied");- }}+ onClick={() => void copyWithToast(u.g.prompt ?? "", "Prompt copied")}><Copy /> Copy prompt</DropdownMenuItem>diff --git a/src/components/cinema/projects-view.tsx b/src/components/cinema/projects-view.tsxindex 64fccfd9..4629bd51 100644--- a/src/components/cinema/projects-view.tsx+++ b/src/components/cinema/projects-view.tsx@@ -4,7 +4,6 @@ import { Clapperboard, Copy, ExternalLink, MoreHorizontal, Pin, PinOff, Plus, Seimport Link from "next/link";import { useRouter } from "next/navigation";import { useState } from "react";-import { toast } from "sonner";import { PageShell } from "@/components/page-shell";import { PageHeader } from "@/components/page-shell";import { Button } from "@/components/ui/button";@@ -14,6 +13,7 @@ import type { CinemaProject } from "@/lib/catalog/cinema";import { formatUsd } from "./money";import { timeAgo } from "@/lib/format";import { cn } from "@/lib/utils";+import { copyWithToast } from "@/lib/clipboard";import { useCinemaProjects, useUpdateProject } from "./hooks";import { ProjectDialog } from "./project-settings";@@ -86,10 +86,7 @@ function ProjectCard({ project, onSettings }: { project: CinemaProject; onSettin<ExternalLink /> Open in new tab</DropdownMenuItem><DropdownMenuItem- onClick={() => {- void navigator.clipboard.writeText(new URL(href, window.location.origin).toString());- toast("Link copied");- }}+ onClick={() => void copyWithToast(new URL(href, window.location.origin).toString(), "Link copied")}><Copy /> Copy link</DropdownMenuItem>diff --git a/src/components/cinema/workspace.tsx b/src/components/cinema/workspace.tsxindex 3f278285..a5337c1e 100644--- a/src/components/cinema/workspace.tsx+++ b/src/components/cinema/workspace.tsx@@ -20,6 +20,7 @@ import { rigError, type CinemaFolder, type DirectorSettings, type DirectorShot }import type { StudioElement } from "@/lib/catalog/elements";import type { OutputFile } from "@/lib/catalog/types";import { cn } from "@/lib/utils";+import { copyWithToast } from "@/lib/clipboard";import { CinemaFeed, type FeedHandlers } from "./cinema-feed";import { initialDraft, type CinemaDraft } from "./draft";import { ElementsPanel } from "./elements-panel";@@ -395,10 +396,7 @@ function Workspace({ data, items, loading }: { data: ProjectView; items: CinemaG{project.pinned ? <PinOff /> : <Pin />} {project.pinned ? "Unpin project" : "Pin project"}</DropdownMenuItem><DropdownMenuItem- onClick={() => {- void navigator.clipboard.writeText(window.location.href);- toast("Link copied");- }}+ onClick={() => void copyWithToast(window.location.href, "Link copied")}><Copy /> Copy link</DropdownMenuItem>diff --git a/src/components/layers/top-bar.tsx b/src/components/layers/top-bar.tsxindex 56869c80..b5a55c23 100644--- a/src/components/layers/top-bar.tsx+++ b/src/components/layers/top-bar.tsx@@ -24,6 +24,7 @@ import type { Engine } from "@/lib/catalog/types";import { timeAgo } from "@/lib/format";import { docJson, exportScale, scaledSize, type LayerDoc, type LayerJob, type LayerVersion } from "@/lib/layers";import { cn } from "@/lib/utils";+import { copyWithToast } from "@/lib/clipboard";import { downloadPng, downloadZip, type ExportSize } from "./render";export type SaveState = "saved" | "saving" | "dirty" | "error" | "conflict";@@ -165,14 +166,7 @@ export function TopBar(p: {const [draft, setDraft] = useState(p.name);const [historyOpen, setHistoryOpen] = useState(false);const [restoring, setRestoring] = useState<string | null>(null);- const copyJson = async () => {- try {- await navigator.clipboard.writeText(docJson(p.doc, window.location.origin));- toast.success("JSON copied", { duration: 1500 });- } catch {- toast.error("Could not copy to the clipboard. Try again.");- }- };+ const copyJson = () => void copyWithToast(docJson(p.doc, window.location.origin), "JSON copied");const mod = typeof navigator !== "undefined" && /Mac|iPhone|iPad/.test(navigator.platform) ? "⌘" : "Ctrl";return (diff --git a/src/components/security-settings.tsx b/src/components/security-settings.tsxindex e99894d5..fc6bf938 100644--- a/src/components/security-settings.tsx+++ b/src/components/security-settings.tsx@@ -8,7 +8,7 @@ import { toast } from "sonner";import { Button } from "@/components/ui/button";import { Input } from "@/components/ui/input";import { Label } from "@/components/ui/label";-import { copyText } from "@/lib/clipboard";+import { copyWithToast } from "@/lib/clipboard";import { timeAgo } from "@/lib/format";interface TokenInfo {@@ -24,12 +24,6 @@ interface AuthStatus {tokens: TokenInfo[];}-/** Copy and say whether it worked (plain-http LAN origins have no Clipboard API; copyText falls back). */-async function copyWithToast(text: string) {- if (await copyText(text)) toast("Copied");- else toast.error("Couldn’t copy — select the text and copy it instead");-}-async function call<T>(url: string, method: string, body?: unknown): Promise<T> {const res = await fetch(url, { method, headers: { "Content-Type": "application/json" }, body: body === undefined ? undefined : JSON.stringify(body) });if (res.status === 204) return undefined as T;diff --git a/src/components/studio/attach-menu.tsx b/src/components/studio/attach-menu.tsxindex 02d90d9a..d24b2411 100644--- a/src/components/studio/attach-menu.tsx+++ b/src/components/studio/attach-menu.tsx@@ -11,8 +11,12 @@ import { ResponsivePanel } from "./responsive-panel";const KIND_WORD: Record<MediaKind, string> = { image: "images", video: "videos", audio: "audio", text: "text", model3d: "3D models" };-/** Read pasteable media from the clipboard (needs the browser's clipboard permission). */+/**+ * Read pasteable media from the clipboard. Needs the browser's clipboard permission and a secure+ * origin (plain-http LAN addresses have no Clipboard API): when it fails, the caller suggests ⌘V / Ctrl+V.+ */async function clipboardFiles(): Promise<File[]> {+ if (!navigator.clipboard?.read) throw new Error("No clipboard access here");const items = await navigator.clipboard.read();const files: File[] = [];for (const item of items) {diff --git a/src/components/studio/feed.tsx b/src/components/studio/feed.tsxindex 12525fb6..08a0bc45 100644--- a/src/components/studio/feed.tsx+++ b/src/components/studio/feed.tsx@@ -17,6 +17,7 @@ import { elapsed, formatCost, ratioValue, timeAgo } from "@/lib/format";import { downloadHref, downloadName, userTitle } from "@/lib/library";import { isLayered, shownOutputs } from "@/lib/output-actions";import { cn } from "@/lib/utils";+import { copyWithToast } from "@/lib/clipboard";import { TileActions, useCanHover, type RunnerOptions } from "./result-actions";import { LayersStack, MediaThumb } from "./result-media";import { Viewer } from "./viewer";@@ -258,10 +259,7 @@ export const GenerationGroup = memo(function GenerationGroup({ g }: { g: Generat</DropdownMenuTrigger><DropdownMenuContent align="end"><DropdownMenuItem- onSelect={() => {- void navigator.clipboard.writeText(g.prompt ?? "");- toast("Prompt copied");- }}+ onSelect={() => void copyWithToast(g.prompt ?? "", "Prompt copied")}><Copy /> Copy prompt</DropdownMenuItem>diff --git a/src/components/studio/result-actions.tsx b/src/components/studio/result-actions.tsxindex 47ae5bae..18bb0f6d 100644--- a/src/components/studio/result-actions.tsx+++ b/src/components/studio/result-actions.tsx@@ -56,6 +56,7 @@ import { downloadName } from "@/lib/library";import { toSrt, toVtt } from "@/lib/cues";import { cuesOf, outputActions, textOf, type ActionContext, type OutputAction, type OutputActionId } from "@/lib/output-actions";import { cn } from "@/lib/utils";+import { copyWithToast } from "@/lib/clipboard";export const ACTION_ICONS: Record<OutputActionId, LucideIcon> = {animate: Clapperboard,@@ -181,11 +182,9 @@ export function useActionRunner(opts: RunnerOptions = {}) {case "favorite":return void actions.favorite(g);case "copy-text":- void navigator.clipboard.writeText(textOf(o));- return void toast("Copied");+ return void copyWithToast(textOf(o));case "copy-prompt":- void navigator.clipboard.writeText(g.prompt ?? "");- return void toast("Prompt copied");+ return void copyWithToast(g.prompt ?? "", "Prompt copied");case "download-txt":return saveBlob(textOf(o), downloadName(g, o, index, "txt"), "text/plain");case "download-srt":diff --git a/src/components/studio/viewer.tsx b/src/components/studio/viewer.tsxindex bc0e345e..17eadc80 100644--- a/src/components/studio/viewer.tsx+++ b/src/components/studio/viewer.tsx@@ -3,7 +3,6 @@import { ChevronLeft, ChevronRight, Columns2, Copy, Info, Layers, MoreHorizontal, X } from "lucide-react";import Link from "next/link";import { useEffect, useMemo, useRef, useState } from "react";-import { toast } from "sonner";import { Button } from "@/components/ui/button";import { Dialog, DialogContent, DialogDescription, DialogTitle } from "@/components/ui/dialog";import { Kbd } from "@/components/ui/kbd";@@ -14,6 +13,7 @@ import { formatCost, timeAgo } from "@/lib/format";import { trashDaysLeft, userTitle } from "@/lib/library";import { isLayered, layerInfo, outputActions, type OutputAction } from "@/lib/output-actions";import { cn } from "@/lib/utils";+import { copyWithToast } from "@/lib/clipboard";import { CompareSlider } from "./compare-slider";import { ACTION_ICONS, downloadUrl, SaveElementForm, useActionRunner } from "./result-actions";import { LayersStack, ModelViewer, TextReader } from "./result-media";@@ -67,10 +67,7 @@ function Details({ g, index }: { g: Generation; index: number }) {{g.prompt && g.prompt !== title && <p className="mt-1 line-clamp-6 text-[12px] leading-relaxed break-words text-muted-foreground">Sent to the model: {g.prompt}</p>}{g.prompt && (<button- onClick={() => {- void navigator.clipboard.writeText(g.prompt ?? "");- toast("Prompt copied");- }}+ onClick={() => void copyWithToast(g.prompt ?? "", "Prompt copied")}className="mt-1 inline-flex items-center gap-1 text-[12px] text-muted-foreground hover:text-foreground"><Copy className="size-3" /> Copy promptdiff --git a/src/lib/clipboard.ts b/src/lib/clipboard.tsindex adc8fb7a..c7b0919f 100644--- a/src/lib/clipboard.ts+++ b/src/lib/clipboard.ts@@ -1,3 +1,5 @@+import { toast } from "sonner";+/*** Copy text to the clipboard, also where the Clipboard API is missing: a self-hosted Fuobe opened* over plain http on a LAN address is not a secure context, so `navigator.clipboard` is undefined@@ -36,3 +38,14 @@ function legacyCopy(text: string): boolean {active?.focus?.();}}++/**+ * Copy and say how it went: `done` ("Prompt copied") when it worked, a hint to copy by hand when+ * the browser refused (the same feedback on every Copy button).+ */+export async function copyWithToast(text: string, done = "Copied"): Promise<boolean> {+ const ok = await copyText(text);+ if (ok) toast(done, { duration: 1500 });+ else toast.error("Couldn’t copy — select the text and copy it instead");+ return ok;+}diff --git a/tests/shell-logic.test.ts b/tests/shell-logic.test.tsindex 575ded10..15db4fa8 100644--- a/tests/shell-logic.test.ts+++ b/tests/shell-logic.test.ts@@ -1,6 +1,6 @@import { afterEach, describe, expect, it, vi } from "vitest";import { EFFECTS, MOTIONS } from "@/lib/catalog";-import { copyText } from "@/lib/clipboard";+import { copyText, copyWithToast } from "@/lib/clipboard";import { loseContext, releaseVideo } from "@/lib/media-release";import { GLYPHS, MOVE_GLYPH, glyphFor } from "@/lib/move-glyphs";import {@@ -18,6 +18,9 @@ import {import { createPlaybackStore, MIN_VISIBLE, type PlaybackEnv } from "@/lib/preview-playback";import { pageAfter, progressiveStart, syncProgressive } from "@/lib/progressive";import { storyboardName } from "@/lib/storyboard-board";++const toasts = vi.hoisted(() => ({ ok: [] as string[], error: [] as string[] }));+vi.mock("sonner", () => ({ toast: Object.assign((m: string) => void toasts.ok.push(m), { error: (m: string) => void toasts.error.push(m) }) }));import { capabilityGroup, usedByIndex } from "@/lib/workflow-usage";describe("workflow 'used by' index", () => {@@ -324,4 +327,15 @@ describe("copyText", () => {});expect(await copyText("x")).toBe(false);});++ it("gives every Copy button the same feedback (copyWithToast)", async () => {+ vi.stubGlobal("navigator", { clipboard: { writeText: async () => {} } });+ expect(await copyWithToast("a prompt", "Prompt copied")).toBe(true);+ expect(toasts.ok.at(-1)).toBe("Prompt copied");+ // Plain-http LAN origin and a browser that refuses execCommand too: say how to copy by hand.+ vi.stubGlobal("navigator", {});+ vi.stubGlobal("document", { createElement: () => ({ style: {}, setAttribute() {}, select() {}, setSelectionRange() {}, remove() {} }), body: { appendChild() {} }, activeElement: null, execCommand: () => false });+ expect(await copyWithToast("a link")).toBe(false);+ expect(toasts.error.at(-1)).toMatch(/select the text/);+ });});