Skip to content

Open source CapCut alternative.

TypeScript

fix(site): show card-less chat refs as pills

David Le8e033813708e
diff --git a/site/src/cut/components/AiPanel.tsx b/site/src/cut/components/AiPanel.tsx
index 7d1a2233..5828111e 100644
--- a/site/src/cut/components/AiPanel.tsx
+++ b/site/src/cut/components/AiPanel.tsx
@@ -143,7 +143,7 @@ import { CHAT_TURN_LABEL, useEditor } from "@/cut/lib/store";
import { reportActivity } from "@/cut/lib/tabActivity";
import { cn } from "@/lib/utils";
import { cardIconButton } from "@/cut/components/iconButton";
-import { MentionedText, MentionTextarea, RefChips, RefThumb } from "./AssetRefs";
+import { MentionedText, MentionTextarea, RefChips, RefThumb, refHasCard, UnmentionedRefPills } from "./AssetRefs";
import { ComposerQueue, type QueuedMessage } from "./ComposerQueue";
import { DictationBody } from "./MicDictation";
import { RECORD_RUNNING_TTL_MS, ToolOutputAssets } from "./ChatAssets";
@@ -2840,9 +2840,9 @@ const MessageView = memo(function MessageView({
)
.map(normalizeRef)
.filter((r): r is AssetRef => r !== null);
- // Timeline entities (overlays, cues, keyframes) already read as pills in
- // the bubble; only media gets a card above it.
- const cards = attachments.filter((a) => a.scope !== "entity");
+ // Only a ref a click can act on gets a card above the bubble; the rest
+ // read as pills, in the text or in a row of their own.
+ const cards = attachments.filter(refHasCard);
return (
<div className="ai-msg-user group mb-3 flex flex-col items-end gap-1">
{cards.length > 0 && (
@@ -2852,6 +2852,7 @@ const MessageView = memo(function MessageView({
))}
</div>
)}
+ <UnmentionedRefPills text={text} refs={attachments} className="max-w-[85%] justify-end" />
{text && (
<div className="max-w-[85%] rounded-2xl rounded-br-md bg-neutral-900 px-3 py-2 text-[12.5px] leading-relaxed break-words whitespace-pre-wrap text-white">
<MentionedText text={text} attachments={attachments} onDark />
diff --git a/site/src/cut/components/AssetRefs.tsx b/site/src/cut/components/AssetRefs.tsx
index 117889b2..9581c571 100644
--- a/site/src/cut/components/AssetRefs.tsx
+++ b/site/src/cut/components/AssetRefs.tsx
@@ -367,6 +367,41 @@ export function RefTokenChip({
);
}
+// The scopes a sent card can act on: a click reveals the tile in the side
+// panel (media, stock) or opens the folder.
+const CARD_SCOPES: ReadonlySet<AssetRef["scope"]> = new Set(["project", "library", "stock", "folder"]);
+
+/** Whether a sent ref draws as a card. A note, a desktop text file, a timeline
+ * clip or an entity has no tile a click could reveal, so it reads as its pill. */
+export const refHasCard = (ref: AssetRef) => CARD_SCOPES.has(ref.scope);
+
+/** Pills for the card-less refs a message carries without naming them in its
+ * text — a note dragged onto the composer, say — so every ref still shows. */
+export function UnmentionedRefPills({
+ text,
+ refs,
+ className,
+}: {
+ text: string;
+ refs: AssetRef[];
+ className?: string;
+}) {
+ const named = splitMentions(text, refs).filter((p): p is AssetRef => typeof p !== "string");
+ const pills = refs.filter((r) => !refHasCard(r) && !named.some((n) => sameRef(n, r)));
+
+ if (pills.length === 0) {
+ return null;
+ }
+
+ return (
+ <div className={cn("flex flex-wrap gap-1 text-[12.5px]", className)}>
+ {pills.map((r) => (
+ <RefTokenChip key={`${r.scope}:${r.id}`} item={r} />
+ ))}
+ </div>
+ );
+}
+
/**
* An inline `@1:34` moment token: a place in the cut the message points at.
* Clicking it takes the playhead there. Written messages hold the moment they
diff --git a/site/src/cut/components/ComposerQueue.tsx b/site/src/cut/components/ComposerQueue.tsx
index 31a4c9ec..8a5b4009 100644
--- a/site/src/cut/components/ComposerQueue.tsx
+++ b/site/src/cut/components/ComposerQueue.tsx
@@ -15,7 +15,7 @@ import {
import { cn } from "@/lib/utils";
import { ScrollArea } from "@/components/ui/scroll-area";
import { useDragSort } from "@/components/Sortable";
-import { MentionedText, RefThumb } from "./AssetRefs";
+import { MentionedText, RefThumb, refHasCard, UnmentionedRefPills } from "./AssetRefs";
import type { AssetRef } from "@/cut/lib/assetRef";
import type { TimeMark } from "@/cut/lib/timeMark";
@@ -264,14 +264,15 @@ export function ComposerQueue({
Running in another chat
</div>
)}
- {it.attachments.some((a) => a.scope !== "entity") && (
+ <UnmentionedRefPills text={it.text} refs={it.attachments} className="mt-1 text-xs" />
+ {it.attachments.some(refHasCard) && (
<div
className={cn(
"mt-1 flex flex-wrap gap-1",
gone && "opacity-50",
)}
>
- {it.attachments.filter((a) => a.scope !== "entity").map((a) => (
+ {it.attachments.filter(refHasCard).map((a) => (
<RefThumb
key={`${a.scope}:${a.id}`}
item={a}
diff --git a/site/src/cut/components/sentRefs.test.tsx b/site/src/cut/components/sentRefs.test.tsx
new file mode 100644
index 00000000..03d8959e
--- /dev/null
+++ b/site/src/cut/components/sentRefs.test.tsx
@@ -0,0 +1,27 @@
+import { describe, expect, test } from "bun:test";
+import { renderToStaticMarkup } from "react-dom/server";
+import type { AssetRef } from "@/cut/lib/assetRef";
+import { refHasCard, UnmentionedRefPills } from "./AssetRefs";
+
+const note: AssetRef = { scope: "note", id: "n1", name: "Shot list", kind: "text", url: "data:text/plain," };
+const video: AssetRef = { scope: "project", id: "a1", name: "beach", kind: "video", url: "/m/beach.mp4" };
+
+// A sent card earns its place by doing something on click.
+describe("sent refs", () => {
+ test("media gets a card and a note does not", () => {
+ expect(refHasCard(video)).toBe(true);
+ expect(refHasCard(note)).toBe(false);
+ });
+
+ test("an unmentioned note reads as its pill", () => {
+ const html = renderToStaticMarkup(<UnmentionedRefPills text="tighten this" refs={[note, video]} />);
+ expect(html).toContain("Shot list");
+ expect(html).toContain("target=\"_blank\"");
+ expect(html).not.toContain("beach");
+ });
+
+ test("a note named in the text draws no second pill", () => {
+ const html = renderToStaticMarkup(<UnmentionedRefPills text={`use @"Shot list"`} refs={[note]} />);
+ expect(html).toBe("");
+ });
+});