Skip to content
Source
Sign inSign up

copiedComposerAttachments.ts

21 lines778 Bytes

1import type { EnvironmentId } from "@t3tools/contracts";
2​
3// Keep the latest copy's files alive after source removal, including preview URL revocation.
4// Replacing the copy releases the previous files instead of accumulating draft attachments.
5let latestCopy: { environmentId: EnvironmentId; files: ReadonlyMap<string, File> } | null = null;
6​
7export function rememberCopiedComposerAttachments(
8 environmentId: EnvironmentId,
9 files: ReadonlyMap<string, File>,
10): void {
11 latestCopy = files.size > 0 ? { environmentId, files } : null;
13​
14export function copiedComposerAttachmentFile(
15 environmentId: EnvironmentId,
16 attachmentId: string,
17): File | undefined {
18 return latestCopy?.environmentId === environmentId
19 ? latestCopy.files.get(attachmentId)
20 : undefined;