@stigmer/react 3.8.0 → 3.10.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/attachment/AttachmentChipList.d.ts +16 -4
- package/attachment/AttachmentChipList.d.ts.map +1 -1
- package/attachment/AttachmentChipList.js +106 -11
- package/attachment/AttachmentChipList.js.map +1 -1
- package/attachment/AttachmentImageLightbox.d.ts +39 -0
- package/attachment/AttachmentImageLightbox.d.ts.map +1 -0
- package/attachment/AttachmentImageLightbox.js +57 -0
- package/attachment/AttachmentImageLightbox.js.map +1 -0
- package/attachment/attachment-utils.d.ts +11 -0
- package/attachment/attachment-utils.d.ts.map +1 -1
- package/attachment/attachment-utils.js +23 -0
- package/attachment/attachment-utils.js.map +1 -1
- package/attachment/clipboard.d.ts +51 -0
- package/attachment/clipboard.d.ts.map +1 -0
- package/attachment/clipboard.js +89 -0
- package/attachment/clipboard.js.map +1 -0
- package/attachment/index.d.ts +6 -1
- package/attachment/index.d.ts.map +1 -1
- package/attachment/index.js +4 -1
- package/attachment/index.js.map +1 -1
- package/attachment/prepare-image.d.ts +43 -0
- package/attachment/prepare-image.d.ts.map +1 -0
- package/attachment/prepare-image.js +162 -0
- package/attachment/prepare-image.js.map +1 -0
- package/attachment/useAttachments.d.ts.map +1 -1
- package/attachment/useAttachments.js +23 -3
- package/attachment/useAttachments.js.map +1 -1
- package/attachment/useObjectUrl.d.ts +15 -0
- package/attachment/useObjectUrl.d.ts.map +1 -0
- package/attachment/useObjectUrl.js +25 -0
- package/attachment/useObjectUrl.js.map +1 -0
- package/attachment/vision-fit.d.ts +50 -0
- package/attachment/vision-fit.d.ts.map +1 -0
- package/attachment/vision-fit.js +76 -0
- package/attachment/vision-fit.js.map +1 -0
- package/composer/SessionComposer.d.ts +3 -1
- package/composer/SessionComposer.d.ts.map +1 -1
- package/composer/SessionComposer.js +50 -4
- package/composer/SessionComposer.js.map +1 -1
- package/conversation/ConversationMediaAttachment.d.ts +45 -0
- package/conversation/ConversationMediaAttachment.d.ts.map +1 -0
- package/conversation/ConversationMediaAttachment.js +153 -0
- package/conversation/ConversationMediaAttachment.js.map +1 -0
- package/conversation/ConversationTimelineView.d.ts +18 -1
- package/conversation/ConversationTimelineView.d.ts.map +1 -1
- package/conversation/ConversationTimelineView.js +14 -5
- package/conversation/ConversationTimelineView.js.map +1 -1
- package/conversation/ConversationsWorkbench.d.ts.map +1 -1
- package/conversation/ConversationsWorkbench.js +1 -1
- package/conversation/ConversationsWorkbench.js.map +1 -1
- package/conversation/conversationPresentation.d.ts +10 -3
- package/conversation/conversationPresentation.d.ts.map +1 -1
- package/conversation/conversationPresentation.js +10 -3
- package/conversation/conversationPresentation.js.map +1 -1
- package/conversation/index.d.ts +2 -0
- package/conversation/index.d.ts.map +1 -1
- package/conversation/index.js +1 -0
- package/conversation/index.js.map +1 -1
- package/conversation/useConversationMediaUrl.d.ts +65 -0
- package/conversation/useConversationMediaUrl.d.ts.map +1 -0
- package/conversation/useConversationMediaUrl.js +61 -0
- package/conversation/useConversationMediaUrl.js.map +1 -0
- package/execution/MessageAttachments.d.ts +52 -0
- package/execution/MessageAttachments.d.ts.map +1 -0
- package/execution/MessageAttachments.js +142 -0
- package/execution/MessageAttachments.js.map +1 -0
- package/execution/MessageEntry.d.ts +18 -0
- package/execution/MessageEntry.d.ts.map +1 -1
- package/execution/MessageEntry.js +5 -4
- package/execution/MessageEntry.js.map +1 -1
- package/execution/MessageThread.d.ts +15 -2
- package/execution/MessageThread.d.ts.map +1 -1
- package/execution/MessageThread.js +24 -7
- package/execution/MessageThread.js.map +1 -1
- package/execution/index.d.ts +2 -0
- package/execution/index.d.ts.map +1 -1
- package/execution/index.js +1 -0
- package/execution/index.js.map +1 -1
- package/github/decodeGitHubContent.d.ts +10 -5
- package/github/decodeGitHubContent.d.ts.map +1 -1
- package/github/decodeGitHubContent.js +21 -7
- package/github/decodeGitHubContent.js.map +1 -1
- package/github/useGitHubFileReader.d.ts.map +1 -1
- package/github/useGitHubFileReader.js +5 -5
- package/github/useGitHubFileReader.js.map +1 -1
- package/index.d.ts +5 -5
- package/index.d.ts.map +1 -1
- package/index.js +5 -4
- package/index.js.map +1 -1
- package/internal/form-primitives.d.ts +13 -0
- package/internal/form-primitives.d.ts.map +1 -1
- package/internal/form-primitives.js +13 -0
- package/internal/form-primitives.js.map +1 -1
- package/package.json +4 -4
- package/session/SessionViewer.js +1 -1
- package/session/SessionViewer.js.map +1 -1
- package/session/useSessionConversation.d.ts +8 -0
- package/session/useSessionConversation.d.ts.map +1 -1
- package/session/useSessionConversation.js +12 -2
- package/session/useSessionConversation.js.map +1 -1
- package/src/attachment/AttachmentChipList.tsx +330 -40
- package/src/attachment/AttachmentImageLightbox.tsx +156 -0
- package/src/attachment/__tests__/AttachmentChipList.test.tsx +326 -0
- package/src/attachment/__tests__/attachment-utils.test.ts +54 -0
- package/src/attachment/__tests__/clipboard.test.ts +110 -0
- package/src/attachment/__tests__/prepare-image.browser.test.ts +166 -0
- package/src/attachment/__tests__/prepare-image.test.ts +32 -0
- package/src/attachment/__tests__/vision-fit.test.ts +93 -0
- package/src/attachment/attachment-utils.ts +27 -0
- package/src/attachment/clipboard.ts +102 -0
- package/src/attachment/index.ts +13 -0
- package/src/attachment/prepare-image.ts +179 -0
- package/src/attachment/useAttachments.ts +26 -2
- package/src/attachment/useObjectUrl.ts +28 -0
- package/src/attachment/vision-fit.ts +90 -0
- package/src/composer/SessionComposer.tsx +73 -4
- package/src/composer/__tests__/SessionComposer-paste.test.tsx +263 -0
- package/src/composer/__tests__/SessionComposer-uploadGate.test.tsx +239 -0
- package/src/conversation/ConversationMediaAttachment.tsx +308 -0
- package/src/conversation/ConversationTimelineView.tsx +60 -10
- package/src/conversation/ConversationsWorkbench.tsx +2 -0
- package/src/conversation/__tests__/ConversationTimelineView.test.tsx +233 -6
- package/src/conversation/__tests__/a11y/conversation-surfaces.a11y.test.tsx +67 -1
- package/src/conversation/__tests__/useConversationMediaUrl.test.tsx +66 -0
- package/src/conversation/conversationPresentation.ts +10 -3
- package/src/conversation/index.ts +6 -0
- package/src/conversation/useConversationMediaUrl.ts +121 -0
- package/src/execution/MessageAttachments.tsx +364 -0
- package/src/execution/MessageEntry.tsx +38 -0
- package/src/execution/MessageThread.tsx +44 -4
- package/src/execution/__tests__/MessageEntry-attachments.test.tsx +228 -0
- package/src/execution/__tests__/buildThreadItems-attachments.test.ts +174 -0
- package/src/execution/index.ts +6 -0
- package/src/github/__tests__/decodeGitHubContent.test.ts +42 -1
- package/src/github/decodeGitHubContent.ts +22 -5
- package/src/github/useGitHubFileReader.ts +13 -3
- package/src/index.ts +16 -1
- package/src/internal/form-primitives.tsx +14 -0
- package/src/session/SessionViewer.tsx +1 -0
- package/src/session/__tests__/useSessionConversation.test.tsx +62 -0
- package/src/session/useSessionConversation.ts +21 -2
- package/src/workspace/FileViewer.tsx +109 -0
- package/src/workspace/WorkspaceFileReader.ts +55 -1
- package/src/workspace/__tests__/FileViewer.test.tsx +98 -0
- package/src/workspace/index.ts +2 -0
- package/styles.css +1 -1
- package/workspace/FileViewer.d.ts.map +1 -1
- package/workspace/FileViewer.js +40 -2
- package/workspace/FileViewer.js.map +1 -1
- package/workspace/WorkspaceFileReader.d.ts +29 -1
- package/workspace/WorkspaceFileReader.d.ts.map +1 -1
- package/workspace/WorkspaceFileReader.js +42 -0
- package/workspace/WorkspaceFileReader.js.map +1 -1
- package/workspace/index.d.ts +1 -1
- package/workspace/index.d.ts.map +1 -1
- package/workspace/index.js +1 -1
- package/workspace/index.js.map +1 -1
|
@@ -7,14 +7,26 @@ export interface AttachmentChipListProps {
|
|
|
7
7
|
readonly onRemove: (id: string) => void;
|
|
8
8
|
/** Retry callback for failed uploads (by entry ID). */
|
|
9
9
|
readonly onRetry: (id: string) => void;
|
|
10
|
-
/**
|
|
10
|
+
/**
|
|
11
|
+
* Called when the user clicks an image chip's preview target. When
|
|
12
|
+
* provided, it **replaces** the built-in lightbox — platform builders
|
|
13
|
+
* route the click to their own viewer. Omit for the default behavior:
|
|
14
|
+
* a full-size image lightbox over the locally-held file bytes.
|
|
15
|
+
*/
|
|
16
|
+
readonly onPreview?: (entry: AttachmentEntry) => void;
|
|
17
|
+
/** Disables remove and retry actions. Preview stays active — it is read-only. */
|
|
11
18
|
readonly disabled?: boolean;
|
|
12
19
|
/** Additional CSS class names for the root container. */
|
|
13
20
|
readonly className?: string;
|
|
14
21
|
}
|
|
15
22
|
/**
|
|
16
|
-
* Renders a horizontal list of
|
|
17
|
-
*
|
|
23
|
+
* Renders a horizontal list of attachment chips: image attachments as
|
|
24
|
+
* preview-only thumbnail tiles (the image IS the chip — no filename
|
|
25
|
+
* text; visible from the moment of paste, through upload, and on error
|
|
26
|
+
* — stigmer/stigmer#371, #372), other files as compact filename chips.
|
|
27
|
+
* Filename, size, and upload status stay available on every chip via
|
|
28
|
+
* the tooltip and the accessible label; clicking an image tile opens
|
|
29
|
+
* the full image.
|
|
18
30
|
*
|
|
19
31
|
* Designed to sit between the context chips and toolbar in
|
|
20
32
|
* {@link SessionComposer}, but usable standalone by platform builders
|
|
@@ -37,5 +49,5 @@ export interface AttachmentChipListProps {
|
|
|
37
49
|
* }
|
|
38
50
|
* ```
|
|
39
51
|
*/
|
|
40
|
-
export declare function AttachmentChipList({ entries, onRemove, onRetry, disabled, className, }: AttachmentChipListProps): import("react/jsx-runtime").JSX.Element | null;
|
|
52
|
+
export declare function AttachmentChipList({ entries, onRemove, onRetry, onPreview, disabled, className, }: AttachmentChipListProps): import("react/jsx-runtime").JSX.Element | null;
|
|
41
53
|
//# sourceMappingURL=AttachmentChipList.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"AttachmentChipList.d.ts","sourceRoot":"","sources":["../../src/attachment/AttachmentChipList.tsx"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"AttachmentChipList.d.ts","sourceRoot":"","sources":["../../src/attachment/AttachmentChipList.tsx"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,qBAAqB,CAAC;AAM3D,4CAA4C;AAC5C,MAAM,WAAW,uBAAuB;IACtC,sDAAsD;IACtD,QAAQ,CAAC,OAAO,EAAE,SAAS,eAAe,EAAE,CAAC;IAC7C,qCAAqC;IACrC,QAAQ,CAAC,QAAQ,EAAE,CAAC,EAAE,EAAE,MAAM,KAAK,IAAI,CAAC;IACxC,uDAAuD;IACvD,QAAQ,CAAC,OAAO,EAAE,CAAC,EAAE,EAAE,MAAM,KAAK,IAAI,CAAC;IACvC;;;;;OAKG;IACH,QAAQ,CAAC,SAAS,CAAC,EAAE,CAAC,KAAK,EAAE,eAAe,KAAK,IAAI,CAAC;IACtD,iFAAiF;IACjF,QAAQ,CAAC,QAAQ,CAAC,EAAE,OAAO,CAAC;IAC5B,yDAAyD;IACzD,QAAQ,CAAC,SAAS,CAAC,EAAE,MAAM,CAAC;CAC7B;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA6BG;AACH,wBAAgB,kBAAkB,CAAC,EACjC,OAAO,EACP,QAAQ,EACR,OAAO,EACP,SAAS,EACT,QAAQ,EACR,SAAS,GACV,EAAE,uBAAuB,kDAgDzB"}
|
|
@@ -1,10 +1,19 @@
|
|
|
1
1
|
"use client";
|
|
2
|
-
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { jsx as _jsx, Fragment as _Fragment, jsxs as _jsxs } from "react/jsx-runtime";
|
|
3
|
+
import { useState } from "react";
|
|
3
4
|
import { cn } from "@stigmer/theme";
|
|
4
5
|
import { formatFileSize } from "./attachment-utils.js";
|
|
6
|
+
import { useObjectUrl } from "./useObjectUrl.js";
|
|
7
|
+
import { AttachmentImageLightbox } from "./AttachmentImageLightbox.js";
|
|
8
|
+
import { UNSTYLED_BUTTON } from "../internal/form-primitives.js";
|
|
5
9
|
/**
|
|
6
|
-
* Renders a horizontal list of
|
|
7
|
-
*
|
|
10
|
+
* Renders a horizontal list of attachment chips: image attachments as
|
|
11
|
+
* preview-only thumbnail tiles (the image IS the chip — no filename
|
|
12
|
+
* text; visible from the moment of paste, through upload, and on error
|
|
13
|
+
* — stigmer/stigmer#371, #372), other files as compact filename chips.
|
|
14
|
+
* Filename, size, and upload status stay available on every chip via
|
|
15
|
+
* the tooltip and the accessible label; clicking an image tile opens
|
|
16
|
+
* the full image.
|
|
8
17
|
*
|
|
9
18
|
* Designed to sit between the context chips and toolbar in
|
|
10
19
|
* {@link SessionComposer}, but usable standalone by platform builders
|
|
@@ -27,26 +36,112 @@ import { formatFileSize } from "./attachment-utils.js";
|
|
|
27
36
|
* }
|
|
28
37
|
* ```
|
|
29
38
|
*/
|
|
30
|
-
export function AttachmentChipList({ entries, onRemove, onRetry, disabled, className, }) {
|
|
39
|
+
export function AttachmentChipList({ entries, onRemove, onRetry, onPreview, disabled, className, }) {
|
|
40
|
+
// The built-in lightbox tracks the previewed entry by ID (direct identity,
|
|
41
|
+
// never object reference), and the entry itself is derived from `entries`
|
|
42
|
+
// on render — so removing an attachment while its preview is open closes
|
|
43
|
+
// the lightbox without any effect-based synchronization.
|
|
44
|
+
const [previewId, setPreviewId] = useState(null);
|
|
45
|
+
const previewEntry = previewId !== null ? (entries.find((e) => e.id === previewId) ?? null) : null;
|
|
31
46
|
if (entries.length === 0)
|
|
32
47
|
return null;
|
|
33
|
-
return (_jsx("div", { className: cn("flex flex-wrap gap-1.5", className), role: "list", "aria-label": "Attached files", children: entries.map((entry) => (_jsx(AttachmentChip, { entry: entry, onRemove: () => onRemove(entry.id), onRetry: () => onRetry(entry.id),
|
|
48
|
+
return (_jsxs(_Fragment, { children: [_jsx("div", { className: cn("flex flex-wrap items-center gap-1.5", className), role: "list", "aria-label": "Attached files", children: entries.map((entry) => (_jsx(AttachmentChip, { entry: entry, onRemove: () => onRemove(entry.id), onRetry: () => onRetry(entry.id), onPreview: onPreview
|
|
49
|
+
? () => onPreview(entry)
|
|
50
|
+
: () => setPreviewId(entry.id), disabled: disabled }, entry.id))) }), previewEntry && (_jsx(ChipPreviewLightbox, { entry: previewEntry, onClose: () => setPreviewId(null) }))] }));
|
|
34
51
|
}
|
|
35
52
|
// ---------------------------------------------------------------------------
|
|
36
|
-
// Individual chip
|
|
53
|
+
// Individual chip — dispatches on content type
|
|
37
54
|
// ---------------------------------------------------------------------------
|
|
38
|
-
function AttachmentChip({ entry, onRemove, onRetry, disabled, }) {
|
|
55
|
+
function AttachmentChip({ entry, onRemove, onRetry, onPreview, disabled, }) {
|
|
56
|
+
return entry.contentType.startsWith("image/") ? (_jsx(ImageAttachmentChip, { entry: entry, onRemove: onRemove, onRetry: onRetry, onPreview: onPreview, disabled: disabled })) : (_jsx(FileAttachmentChip, { entry: entry, onRemove: onRemove, onRetry: onRetry, disabled: disabled }));
|
|
57
|
+
}
|
|
58
|
+
/** Shared accessible name: filename, size, and upload status. */
|
|
59
|
+
function chipAriaLabel(entry) {
|
|
60
|
+
const isUploading = entry.phase === "uploading";
|
|
61
|
+
const isError = entry.phase === "error";
|
|
62
|
+
return `${entry.file.name}, ${formatFileSize(entry.file.size)}${isUploading ? ", uploading" : ""}${isError ? ", upload failed" : ""}`;
|
|
63
|
+
}
|
|
64
|
+
// ---------------------------------------------------------------------------
|
|
65
|
+
// Image chip — a preview-only thumbnail tile (#371, #372)
|
|
66
|
+
// ---------------------------------------------------------------------------
|
|
67
|
+
/**
|
|
68
|
+
* The preview-only image tile: the thumbnail IS the chip. No filename
|
|
69
|
+
* text, no size caption — the image is its own identity (the grammar
|
|
70
|
+
* users know from Cursor/ChatGPT attachment tiles), while filename,
|
|
71
|
+
* size, and upload status stay one hover away in the tooltip and are
|
|
72
|
+
* always in the accessible label.
|
|
73
|
+
*
|
|
74
|
+
* The tile is alive through every upload phase (the spinner overlays
|
|
75
|
+
* the image during upload, never replaces it — the bytes are local, so
|
|
76
|
+
* the preview never waits on the network) and is one large click
|
|
77
|
+
* target that opens the full image. Remove is an always-visible corner
|
|
78
|
+
* badge — never hover-revealed, so it exists on touch devices and is
|
|
79
|
+
* discoverable without a pointer.
|
|
80
|
+
*
|
|
81
|
+
* On upload error the tile stays loud: destructive ring, dimmed image,
|
|
82
|
+
* and a centered Retry pill — failure never hides behind hover.
|
|
83
|
+
*
|
|
84
|
+
* If the file claims `image/*` but the browser can't decode it (corrupt,
|
|
85
|
+
* zero-byte), the chip degrades to the compact file-chip treatment — a
|
|
86
|
+
* generic icon and no preview affordance, never a broken-image glyph.
|
|
87
|
+
*/
|
|
88
|
+
function ImageAttachmentChip({ entry, onRemove, onRetry, onPreview, disabled, }) {
|
|
89
|
+
const url = useObjectUrl(entry.file);
|
|
90
|
+
const [loadFailed, setLoadFailed] = useState(false);
|
|
91
|
+
if (loadFailed) {
|
|
92
|
+
return (_jsx(FileAttachmentChip, { entry: entry, onRemove: onRemove, onRetry: onRetry, disabled: disabled }));
|
|
93
|
+
}
|
|
39
94
|
const isError = entry.phase === "error";
|
|
40
95
|
const isUploading = entry.phase === "uploading";
|
|
41
|
-
return (
|
|
96
|
+
return (
|
|
97
|
+
// The remove badge and retry pill are SIBLINGS of the preview button,
|
|
98
|
+
// absolutely positioned over it — buttons cannot nest inside buttons.
|
|
99
|
+
_jsxs("span", { role: "listitem", "aria-label": chipAriaLabel(entry), title: entry.file.name, className: "relative inline-flex", children: [_jsxs("button", { type: "button", onClick: onPreview, "aria-label": `Preview ${entry.file.name}`, className: cn(UNSTYLED_BUTTON, "relative block h-14 w-14 overflow-hidden rounded-md focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring", isError && "ring-1 ring-destructive"), children: [url ? (_jsx("img", { src: url, alt: "", "aria-hidden": "true", onError: () => setLoadFailed(true), className: cn("h-full w-full object-cover", (isUploading || isError) && "opacity-50") })) : (
|
|
100
|
+
// One-frame placeholder until the object-URL effect runs; same
|
|
101
|
+
// footprint as the image, so no layout shift.
|
|
102
|
+
_jsx("span", { className: "block h-full w-full animate-pulse bg-muted", "aria-hidden": "true" })), isUploading && (_jsx("span", { className: "absolute inset-0 flex items-center justify-center", children: _jsx(ChipSpinner, { size: 16 }) }))] }), isError && (_jsx("button", { type: "button", onClick: onRetry, disabled: disabled, "aria-label": `Retry uploading ${entry.file.name}`, className: cn(UNSTYLED_BUTTON, "absolute left-1/2 top-1/2 -translate-x-1/2 -translate-y-1/2 rounded-full bg-destructive px-1.5 py-0.5 text-[0.6rem] font-medium leading-none text-destructive-foreground shadow-sm [font-family:inherit] hover:bg-destructive-hover disabled:pointer-events-none"), children: "Retry" })), _jsx("button", { type: "button", onClick: onRemove, disabled: disabled, "aria-label": `Remove ${entry.file.name}`, className: cn(UNSTYLED_BUTTON,
|
|
103
|
+
// The established corner-badge geometry (ContextPopover,
|
|
104
|
+
// ComposerToolbar). Solid bg + border keep it legible over any
|
|
105
|
+
// image without opacity-modified tokens (Dont-Do #4).
|
|
106
|
+
"absolute -right-1.5 -top-1.5 flex h-4 w-4 items-center justify-center rounded-full border border-border bg-background text-muted-foreground shadow-sm hover:text-destructive disabled:pointer-events-none"), children: _jsx(XIcon, {}) })] }));
|
|
107
|
+
}
|
|
108
|
+
// ---------------------------------------------------------------------------
|
|
109
|
+
// File chip — the compact treatment for non-image attachments
|
|
110
|
+
// ---------------------------------------------------------------------------
|
|
111
|
+
function FileAttachmentChip({ entry, onRemove, onRetry, disabled, }) {
|
|
112
|
+
const isError = entry.phase === "error";
|
|
113
|
+
const isUploading = entry.phase === "uploading";
|
|
114
|
+
return (_jsxs("span", { role: "listitem", "aria-label": chipAriaLabel(entry), className: cn("inline-flex max-w-[200px] items-center gap-1 rounded-md px-2 py-0.5 text-xs", isError
|
|
42
115
|
? "border border-destructive/30 bg-destructive-subtle text-destructive"
|
|
43
|
-
: "bg-muted-subtle text-foreground", isUploading && "opacity-70"), children: [isUploading && _jsx(ChipSpinner, {}), isError && _jsx(ErrorDot, {}), !isUploading && !isError && _jsx(FileIcon, {}), _jsx("span", { className: "truncate", children: entry.file.name }), _jsx("span", { className: "shrink-0 text-[0.6rem] tabular-nums text-muted-foreground", children: formatFileSize(entry.file.size) }), isError &&
|
|
116
|
+
: "bg-muted-subtle text-foreground", isUploading && "opacity-70"), children: [isUploading && _jsx(ChipSpinner, {}), isError && _jsx(ErrorDot, {}), !isUploading && !isError && _jsx(FileIcon, {}), _jsx("span", { className: "truncate", children: entry.file.name }), _jsx("span", { className: "shrink-0 text-[0.6rem] tabular-nums text-muted-foreground", children: formatFileSize(entry.file.size) }), isError && _jsx(RetryButton, { filename: entry.file.name, onRetry: onRetry, disabled: disabled }), _jsx(RemoveButton, { filename: entry.file.name, onRemove: onRemove, disabled: disabled })] }));
|
|
117
|
+
}
|
|
118
|
+
// ---------------------------------------------------------------------------
|
|
119
|
+
// Shared chip actions
|
|
120
|
+
// ---------------------------------------------------------------------------
|
|
121
|
+
function RetryButton({ filename, onRetry, disabled, }) {
|
|
122
|
+
return (_jsx("button", { type: "button", onClick: onRetry, disabled: disabled, className: cn(UNSTYLED_BUTTON, "shrink-0 text-[0.6rem] font-medium text-destructive underline [font-family:inherit] hover:text-destructive-muted disabled:pointer-events-none"), "aria-label": `Retry uploading ${filename}`, children: "Retry" }));
|
|
123
|
+
}
|
|
124
|
+
function RemoveButton({ filename, onRemove, disabled, }) {
|
|
125
|
+
return (_jsx("button", { type: "button", onClick: onRemove, disabled: disabled, className: cn(UNSTYLED_BUTTON, "ml-0.5 shrink-0 text-muted-foreground hover:text-destructive disabled:pointer-events-none"), "aria-label": `Remove ${filename}`, children: _jsx(XIcon, {}) }));
|
|
126
|
+
}
|
|
127
|
+
// ---------------------------------------------------------------------------
|
|
128
|
+
// Built-in lightbox mount
|
|
129
|
+
// ---------------------------------------------------------------------------
|
|
130
|
+
/**
|
|
131
|
+
* Bridges the previewed entry to the dumb {@link AttachmentImageLightbox}:
|
|
132
|
+
* mounted only while a preview is open, so its object URL is created on
|
|
133
|
+
* open and revoked on close (independent of the chip's own URL, whose
|
|
134
|
+
* lifetime tracks the chip).
|
|
135
|
+
*/
|
|
136
|
+
function ChipPreviewLightbox({ entry, onClose, }) {
|
|
137
|
+
const src = useObjectUrl(entry.file);
|
|
138
|
+
return (_jsx(AttachmentImageLightbox, { src: src, filename: entry.file.name, open: true, onClose: onClose }));
|
|
44
139
|
}
|
|
45
140
|
// ---------------------------------------------------------------------------
|
|
46
141
|
// Inline SVG icons — kept minimal and consistent with SessionComposer icons
|
|
47
142
|
// ---------------------------------------------------------------------------
|
|
48
|
-
function ChipSpinner() {
|
|
49
|
-
return (_jsx("svg", { width:
|
|
143
|
+
function ChipSpinner({ size = 10 }) {
|
|
144
|
+
return (_jsx("svg", { width: size, height: size, viewBox: "0 0 16 16", fill: "none", stroke: "currentColor", strokeWidth: "2.5", strokeLinecap: "round", className: "shrink-0 animate-spin text-muted-foreground", "aria-hidden": "true", children: _jsx("path", { d: "M8 2a6 6 0 1 0 6 6" }) }));
|
|
50
145
|
}
|
|
51
146
|
function ErrorDot() {
|
|
52
147
|
return (_jsx("span", { className: "inline-block h-1.5 w-1.5 shrink-0 rounded-full bg-destructive", "aria-hidden": "true" }));
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"AttachmentChipList.js","sourceRoot":"","sources":["../../src/attachment/AttachmentChipList.tsx"],"names":[],"mappings":"AAAA,YAAY,CAAC;;AAEb,OAAO,EAAE,EAAE,EAAE,MAAM,gBAAgB,CAAC;AAEpC,OAAO,EAAE,cAAc,EAAE,MAAM,uBAAuB,CAAC;
|
|
1
|
+
{"version":3,"file":"AttachmentChipList.js","sourceRoot":"","sources":["../../src/attachment/AttachmentChipList.tsx"],"names":[],"mappings":"AAAA,YAAY,CAAC;;AAEb,OAAO,EAAE,QAAQ,EAAE,MAAM,OAAO,CAAC;AACjC,OAAO,EAAE,EAAE,EAAE,MAAM,gBAAgB,CAAC;AAEpC,OAAO,EAAE,cAAc,EAAE,MAAM,uBAAuB,CAAC;AACvD,OAAO,EAAE,YAAY,EAAE,MAAM,mBAAmB,CAAC;AACjD,OAAO,EAAE,uBAAuB,EAAE,MAAM,8BAA8B,CA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iBACV,MAAM,YAElB,eAAM,CAAC,EAAC,sBAAsB,GAAG,GAC7B,CACP,CAAC;AACJ,CAAC"}
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
/** Props for {@link AttachmentImageLightbox}. */
|
|
2
|
+
export interface AttachmentImageLightboxProps {
|
|
3
|
+
/**
|
|
4
|
+
* Image source URL. `null` for the first-paint frame before the caller's
|
|
5
|
+
* object URL exists — the lightbox shows a pulse placeholder, never a
|
|
6
|
+
* broken-image glyph.
|
|
7
|
+
*/
|
|
8
|
+
readonly src: string | null;
|
|
9
|
+
/** Filename shown in the header and used as the image alt text. */
|
|
10
|
+
readonly filename: string;
|
|
11
|
+
/** Controls visibility. `true` opens the dialog via `showModal()`. */
|
|
12
|
+
readonly open: boolean;
|
|
13
|
+
/** Called when the lightbox should close (Escape, backdrop click, close button). */
|
|
14
|
+
readonly onClose: () => void;
|
|
15
|
+
/** Additional CSS classes for the dialog element. */
|
|
16
|
+
readonly className?: string;
|
|
17
|
+
}
|
|
18
|
+
/**
|
|
19
|
+
* Full-size image preview in a native `<dialog>` — the click-to-open target
|
|
20
|
+
* for composer attachment chips (stigmer/stigmer#371).
|
|
21
|
+
*
|
|
22
|
+
* A thin modal shell following the SDK's established dialog pattern
|
|
23
|
+
* ({@link ArtifactPreviewModal}): `showModal()`/`close()` driven by the
|
|
24
|
+
* `open` prop, Escape via the intercepted `cancel` event, focus trap and
|
|
25
|
+
* top layer native — no portal plumbing, no `@base-ui/react` dependency.
|
|
26
|
+
* Backdrop click closes via the canonical `e.target === dialog` check
|
|
27
|
+
* (clicks on content children never match the dialog element itself).
|
|
28
|
+
*
|
|
29
|
+
* Deliberately dumb (`src` + `filename`, no attachment types): liftable to
|
|
30
|
+
* `internal/` unchanged if other image surfaces (e.g. tool-output
|
|
31
|
+
* screenshots in `ResultView`) later want in-app preview instead of
|
|
32
|
+
* open-in-new-tab.
|
|
33
|
+
*
|
|
34
|
+
* The backdrop uses the `--stgm-backdrop` theme token ("modal backdrop
|
|
35
|
+
* overlay behind dialogs") rather than the `bg-black/50` hardcode found in
|
|
36
|
+
* older dialogs — the token is the designed value (Dont-Do #3).
|
|
37
|
+
*/
|
|
38
|
+
export declare function AttachmentImageLightbox({ src, filename, open, onClose, className, }: AttachmentImageLightboxProps): import("react/jsx-runtime").JSX.Element;
|
|
39
|
+
//# sourceMappingURL=AttachmentImageLightbox.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"AttachmentImageLightbox.d.ts","sourceRoot":"","sources":["../../src/attachment/AttachmentImageLightbox.tsx"],"names":[],"mappings":"AAKA,iDAAiD;AACjD,MAAM,WAAW,4BAA4B;IAC3C;;;;OAIG;IACH,QAAQ,CAAC,GAAG,EAAE,MAAM,GAAG,IAAI,CAAC;IAC5B,mEAAmE;IACnE,QAAQ,CAAC,QAAQ,EAAE,MAAM,CAAC;IAC1B,sEAAsE;IACtE,QAAQ,CAAC,IAAI,EAAE,OAAO,CAAC;IACvB,oFAAoF;IACpF,QAAQ,CAAC,OAAO,EAAE,MAAM,IAAI,CAAC;IAC7B,qDAAqD;IACrD,QAAQ,CAAC,SAAS,CAAC,EAAE,MAAM,CAAC;CAC7B;AAED;;;;;;;;;;;;;;;;;;;GAmBG;AACH,wBAAgB,uBAAuB,CAAC,EACtC,GAAG,EACH,QAAQ,EACR,IAAI,EACJ,OAAO,EACP,SAAS,GACV,EAAE,4BAA4B,2CAmF9B"}
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
3
|
+
import { useCallback, useEffect, useRef } from "react";
|
|
4
|
+
import { cn } from "@stigmer/theme";
|
|
5
|
+
/**
|
|
6
|
+
* Full-size image preview in a native `<dialog>` — the click-to-open target
|
|
7
|
+
* for composer attachment chips (stigmer/stigmer#371).
|
|
8
|
+
*
|
|
9
|
+
* A thin modal shell following the SDK's established dialog pattern
|
|
10
|
+
* ({@link ArtifactPreviewModal}): `showModal()`/`close()` driven by the
|
|
11
|
+
* `open` prop, Escape via the intercepted `cancel` event, focus trap and
|
|
12
|
+
* top layer native — no portal plumbing, no `@base-ui/react` dependency.
|
|
13
|
+
* Backdrop click closes via the canonical `e.target === dialog` check
|
|
14
|
+
* (clicks on content children never match the dialog element itself).
|
|
15
|
+
*
|
|
16
|
+
* Deliberately dumb (`src` + `filename`, no attachment types): liftable to
|
|
17
|
+
* `internal/` unchanged if other image surfaces (e.g. tool-output
|
|
18
|
+
* screenshots in `ResultView`) later want in-app preview instead of
|
|
19
|
+
* open-in-new-tab.
|
|
20
|
+
*
|
|
21
|
+
* The backdrop uses the `--stgm-backdrop` theme token ("modal backdrop
|
|
22
|
+
* overlay behind dialogs") rather than the `bg-black/50` hardcode found in
|
|
23
|
+
* older dialogs — the token is the designed value (Dont-Do #3).
|
|
24
|
+
*/
|
|
25
|
+
export function AttachmentImageLightbox({ src, filename, open, onClose, className, }) {
|
|
26
|
+
const dialogRef = useRef(null);
|
|
27
|
+
useEffect(() => {
|
|
28
|
+
const dialog = dialogRef.current;
|
|
29
|
+
if (!dialog)
|
|
30
|
+
return;
|
|
31
|
+
if (open && !dialog.open) {
|
|
32
|
+
dialog.showModal();
|
|
33
|
+
}
|
|
34
|
+
else if (!open && dialog.open) {
|
|
35
|
+
dialog.close();
|
|
36
|
+
}
|
|
37
|
+
}, [open]);
|
|
38
|
+
// Escape arrives as the native `cancel` event; intercept it so the
|
|
39
|
+
// caller's `open` prop stays the single source of truth for visibility.
|
|
40
|
+
const handleCancel = useCallback((e) => {
|
|
41
|
+
e.preventDefault();
|
|
42
|
+
onClose();
|
|
43
|
+
}, [onClose]);
|
|
44
|
+
const handleBackdropClick = useCallback((e) => {
|
|
45
|
+
if (e.target === dialogRef.current) {
|
|
46
|
+
onClose();
|
|
47
|
+
}
|
|
48
|
+
}, [onClose]);
|
|
49
|
+
return (_jsx("dialog", { ref: dialogRef, onCancel: handleCancel, onClick: handleBackdropClick, "aria-label": `Preview ${filename}`, className: cn("fixed inset-0 m-auto max-h-[85vh] max-w-[85vw] rounded-lg border border-border bg-background p-0 text-foreground shadow-lg outline-none", "backdrop:bg-backdrop", className), children: open && (_jsxs("div", { className: "flex flex-col", children: [_jsxs("div", { className: "flex items-center gap-2 px-3 py-2", children: [_jsx("span", { className: "min-w-0 flex-1 truncate text-xs font-semibold text-foreground", title: filename, children: filename }), _jsx("button", { type: "button", onClick: onClose, "aria-label": "Close image preview", className: "shrink-0 cursor-pointer rounded bg-transparent p-0.5 text-muted-foreground transition-colors hover:text-foreground focus-visible:outline-none focus-visible:ring-1 focus-visible:ring-ring", children: _jsx(CloseIcon, {}) })] }), _jsx("div", { className: "min-h-0 overflow-auto border-t border-border", children: src ? (_jsx("img", { src: src, alt: filename, className: "block max-h-[75vh] max-w-full object-contain" })) : (_jsx("div", { className: "h-48 w-72 animate-pulse bg-muted", "aria-hidden": "true" })) })] })) }));
|
|
50
|
+
}
|
|
51
|
+
// ---------------------------------------------------------------------------
|
|
52
|
+
// Inline SVG icons (SDK pattern: no external icon dependency)
|
|
53
|
+
// ---------------------------------------------------------------------------
|
|
54
|
+
function CloseIcon() {
|
|
55
|
+
return (_jsxs("svg", { width: "14", height: "14", viewBox: "0 0 14 14", fill: "none", stroke: "currentColor", strokeWidth: "1.5", strokeLinecap: "round", strokeLinejoin: "round", "aria-hidden": "true", children: [_jsx("path", { d: "M3 3L11 11" }), _jsx("path", { d: "M11 3L3 11" })] }));
|
|
56
|
+
}
|
|
57
|
+
//# sourceMappingURL=AttachmentImageLightbox.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"AttachmentImageLightbox.js","sourceRoot":"","sources":["../../src/attachment/AttachmentImageLightbox.tsx"],"names":[],"mappings":"AAAA,YAAY,CAAC;;AAEb,OAAO,EAAE,WAAW,EAAE,SAAS,EAAE,MAAM,EAAE,MAAM,OAAO,CAAC;AACvD,OAAO,EAAE,EAAE,EAAE,MAAM,g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AK,SAAS,EAAC,mCAAmC,aAChD,eACE,SAAS,EAAC,+DAA+D,EACzE,KAAK,EAAE,QAAQ,YAEd,QAAQ,GACJ,EAGP,iBACE,IAAI,EAAC,QAAQ,EACb,OAAO,EAAE,OAAO,gBACL,qBAAqB,EAChC,SAAS,EAAC,4LAA4L,YAEtM,KAAC,SAAS,KAAG,GACN,IACL,EACN,cAAK,SAAS,EAAC,8CAA8C,YAC1D,GAAG,CAAC,CAAC,CAAC,CACL,cACE,GAAG,EAAE,GAAG,EACR,GAAG,EAAE,QAAQ,EACb,SAAS,EAAC,8CAA8C,GACxD,CACH,CAAC,CAAC,CAAC,CACF,cACE,SAAS,EAAC,kCAAkC,iBAChC,MAAM,GAClB,CACH,GACG,IACF,CACP,GACM,CACV,CAAC;AACJ,CAAC;AAED,8EAA8E;AAC9E,8DAA8D;AAC9D,8EAA8E;AAE9E,SAAS,SAAS;IAChB,OAAO,CACL,eACE,KAAK,EAAC,IAAI,EACV,MAAM,EAAC,IAAI,EACX,OAAO,EAAC,WAAW,EACnB,IAAI,EAAC,MAAM,EACX,MAAM,EAAC,cAAc,EACrB,WAAW,EAAC,KAAK,EACjB,aAAa,EAAC,OAAO,EACrB,cAAc,EAAC,OAAO,iBACV,MAAM,aAElB,eAAM,CAAC,EAAC,YAAY,GAAG,EACvB,eAAM,CAAC,EAAC,YAAY,GAAG,IACnB,CACP,CAAC;AACJ,CAAC"}
|
|
@@ -29,4 +29,15 @@ export declare function formatFileSize(bytes: number): string;
|
|
|
29
29
|
* file exceeds {@link MAX_ATTACHMENT_BYTES}.
|
|
30
30
|
*/
|
|
31
31
|
export declare function validateAttachmentSize(file: File): string | null;
|
|
32
|
+
/**
|
|
33
|
+
* Returns `name` unchanged when it is not in `taken`, otherwise the first
|
|
34
|
+
* free `stem-2.ext`, `stem-3.ext`, … variant.
|
|
35
|
+
*
|
|
36
|
+
* Duplicate filenames within one turn are not a cosmetic problem:
|
|
37
|
+
* attachments materialize at `.stigmer/inputs/{filename}`, where the
|
|
38
|
+
* deep-agent harness fails the whole execution on a mount-path collision
|
|
39
|
+
* and the Cursor harness silently overwrites the earlier file. A visible
|
|
40
|
+
* rename on the attachment chip is strictly better than either outcome.
|
|
41
|
+
*/
|
|
42
|
+
export declare function uniquifyFilename(name: string, taken: ReadonlySet<string>): string;
|
|
32
43
|
//# sourceMappingURL=attachment-utils.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"attachment-utils.d.ts","sourceRoot":"","sources":["../../src/attachment/attachment-utils.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AACH,eAAO,MAAM,oBAAoB,QAAmB,CAAC;AAiDrD;;;;;;;GAOG;AACH,wBAAgB,iBAAiB,CAAC,IAAI,EAAE,IAAI,GAAG,MAAM,CAapD;AAID;;;;;GAKG;AACH,wBAAgB,cAAc,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,CAapD;AAED;;;;;GAKG;AACH,wBAAgB,sBAAsB,CAAC,IAAI,EAAE,IAAI,GAAG,MAAM,GAAG,IAAI,CAKhE"}
|
|
1
|
+
{"version":3,"file":"attachment-utils.d.ts","sourceRoot":"","sources":["../../src/attachment/attachment-utils.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AACH,eAAO,MAAM,oBAAoB,QAAmB,CAAC;AAiDrD;;;;;;;GAOG;AACH,wBAAgB,iBAAiB,CAAC,IAAI,EAAE,IAAI,GAAG,MAAM,CAapD;AAID;;;;;GAKG;AACH,wBAAgB,cAAc,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,CAapD;AAED;;;;;GAKG;AACH,wBAAgB,sBAAsB,CAAC,IAAI,EAAE,IAAI,GAAG,MAAM,GAAG,IAAI,CAKhE;AAED;;;;;;;;;GASG;AACH,wBAAgB,gBAAgB,CAC9B,IAAI,EAAE,MAAM,EACZ,KAAK,EAAE,WAAW,CAAC,MAAM,CAAC,GACzB,MAAM,CAYR"}
|
|
@@ -101,4 +101,27 @@ export function validateAttachmentSize(file) {
|
|
|
101
101
|
}
|
|
102
102
|
return null;
|
|
103
103
|
}
|
|
104
|
+
/**
|
|
105
|
+
* Returns `name` unchanged when it is not in `taken`, otherwise the first
|
|
106
|
+
* free `stem-2.ext`, `stem-3.ext`, … variant.
|
|
107
|
+
*
|
|
108
|
+
* Duplicate filenames within one turn are not a cosmetic problem:
|
|
109
|
+
* attachments materialize at `.stigmer/inputs/{filename}`, where the
|
|
110
|
+
* deep-agent harness fails the whole execution on a mount-path collision
|
|
111
|
+
* and the Cursor harness silently overwrites the earlier file. A visible
|
|
112
|
+
* rename on the attachment chip is strictly better than either outcome.
|
|
113
|
+
*/
|
|
114
|
+
export function uniquifyFilename(name, taken) {
|
|
115
|
+
if (!taken.has(name))
|
|
116
|
+
return name;
|
|
117
|
+
const dotIndex = name.lastIndexOf(".");
|
|
118
|
+
// A leading dot (".env") is a hidden-file prefix, not an extension.
|
|
119
|
+
const stem = dotIndex > 0 ? name.slice(0, dotIndex) : name;
|
|
120
|
+
const ext = dotIndex > 0 ? name.slice(dotIndex) : "";
|
|
121
|
+
for (let n = 2;; n++) {
|
|
122
|
+
const candidate = `${stem}-${n}${ext}`;
|
|
123
|
+
if (!taken.has(candidate))
|
|
124
|
+
return candidate;
|
|
125
|
+
}
|
|
126
|
+
}
|
|
104
127
|
//# sourceMappingURL=attachment-utils.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"attachment-utils.js","sourceRoot":"","sources":["../../src/attachment/attachment-utils.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AACH,MAAM,CAAC,MAAM,oBAAoB,GAAG,EAAE,GAAG,IAAI,GAAG,IAAI,CAAC;AAErD;;;;;GAKG;AACH,MAAM,kBAAkB,GAA2B;IACjD,KAAK,EAAE,eAAe;IACtB,WAAW,EAAE,eAAe;IAC5B,OAAO,EAAE,oBAAoB;IAC7B,MAAM,EAAE,oBAAoB;IAC5B,OAAO,EAAE,kBAAkB;IAC3B,MAAM,EAAE,UA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,CAAC;IAC1F,CAAC;IACD,OAAO,IAAI,CAAC;AACd,CAAC;AAED;;;;;;;;;GASG;AACH,MAAM,UAAU,gBAAgB,CAC9B,IAAY,EACZ,KAA0B;IAE1B,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,IAAI,CAAC;QAAE,OAAO,IAAI,CAAC;IAElC,MAAM,QAAQ,GAAG,IAAI,CAAC,WAAW,CAAC,GAAG,CAAC,CAAC;IACvC,oEAAoE;IACpE,MAAM,IAAI,GAAG,QAAQ,GAAG,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,EAAE,QAAQ,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC;IAC3D,MAAM,GAAG,GAAG,QAAQ,GAAG,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,KAAK,CAAC,QAAQ,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC;IAErD,KAAK,IAAI,CAAC,GAAG,CAAC,GAAI,CAAC,EAAE,EAAE,CAAC;QACtB,MAAM,SAAS,GAAG,GAAG,IAAI,IAAI,CAAC,GAAG,GAAG,EAAE,CAAC;QACvC,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,SAAS,CAAC;YAAE,OAAO,SAAS,CAAC;IAC9C,CAAC;AACH,CAAC"}
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Clipboard file extraction for composer surfaces — the paste half of
|
|
3
|
+
* "paste a screenshot and the agent sees it" (stigmer/stigmer#284).
|
|
4
|
+
*
|
|
5
|
+
* Extraction is deliberately SYNCHRONOUS. Clipboard file handles are only
|
|
6
|
+
* reliable while the paste event is being dispatched, and the caller must
|
|
7
|
+
* decide `preventDefault()` in the same tick (a copied image usually carries
|
|
8
|
+
* an HTML/text flavor that would otherwise paste as junk markup). An async
|
|
9
|
+
* "one call" API here would pass in tests and lose pastes in real browsers.
|
|
10
|
+
* Async work on the extracted files (e.g. {@link prepareImageForVision})
|
|
11
|
+
* happens after extraction, on plain `File` objects that stay valid.
|
|
12
|
+
*/
|
|
13
|
+
/**
|
|
14
|
+
* Structural source for {@link extractClipboardFiles}: both the native
|
|
15
|
+
* `ClipboardEvent` and React's synthetic clipboard event satisfy it.
|
|
16
|
+
*/
|
|
17
|
+
export interface ClipboardFilesSource {
|
|
18
|
+
readonly clipboardData: {
|
|
19
|
+
readonly files: FileList;
|
|
20
|
+
} | null;
|
|
21
|
+
}
|
|
22
|
+
/**
|
|
23
|
+
* Extracts files from a paste event, giving clipboard images that carry the
|
|
24
|
+
* browser's generic `image.png` name a unique, human-readable one
|
|
25
|
+
* (`pasted-image-<HHMMSS>-<n>.<ext>`).
|
|
26
|
+
*
|
|
27
|
+
* Unique names are load-bearing, not cosmetic: attachments mount at
|
|
28
|
+
* `.stigmer/inputs/{filename}`, and two same-named attachments either fail
|
|
29
|
+
* the execution (deep-agent harness) or silently overwrite each other
|
|
30
|
+
* (Cursor harness). Files with real names (pasted from a file manager) are
|
|
31
|
+
* returned unchanged.
|
|
32
|
+
*
|
|
33
|
+
* Returns an empty array for a text-only paste — callers use that to let
|
|
34
|
+
* the default text insertion proceed untouched.
|
|
35
|
+
*
|
|
36
|
+
* Must be called synchronously from the paste event handler. Call
|
|
37
|
+
* `event.preventDefault()` in the same tick when the result is non-empty;
|
|
38
|
+
* the returned `File` objects remain valid afterwards.
|
|
39
|
+
*
|
|
40
|
+
* @example
|
|
41
|
+
* ```tsx
|
|
42
|
+
* function handlePaste(e: React.ClipboardEvent<HTMLTextAreaElement>) {
|
|
43
|
+
* const files = extractClipboardFiles(e);
|
|
44
|
+
* if (files.length === 0) return; // plain text paste — leave it alone
|
|
45
|
+
* e.preventDefault();
|
|
46
|
+
* attachments.addFiles(files);
|
|
47
|
+
* }
|
|
48
|
+
* ```
|
|
49
|
+
*/
|
|
50
|
+
export declare function extractClipboardFiles(event: ClipboardFilesSource): File[];
|
|
51
|
+
//# sourceMappingURL=clipboard.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"clipboard.d.ts","sourceRoot":"","sources":["../../src/attachment/clipboard.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AAEH;;;GAGG;AACH,MAAM,WAAW,oBAAoB;IACnC,QAAQ,CAAC,aAAa,EAAE;QAAE,QAAQ,CAAC,KAAK,EAAE,QAAQ,CAAA;KAAE,GAAG,IAAI,CAAC;CAC7D;AAuCD;;;;;;;;;;;;;;;;;;;;;;;;;;;GA2BG;AACH,wBAAgB,qBAAqB,CAAC,KAAK,EAAE,oBAAoB,GAAG,IAAI,EAAE,CAezE"}
|
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Clipboard file extraction for composer surfaces — the paste half of
|
|
3
|
+
* "paste a screenshot and the agent sees it" (stigmer/stigmer#284).
|
|
4
|
+
*
|
|
5
|
+
* Extraction is deliberately SYNCHRONOUS. Clipboard file handles are only
|
|
6
|
+
* reliable while the paste event is being dispatched, and the caller must
|
|
7
|
+
* decide `preventDefault()` in the same tick (a copied image usually carries
|
|
8
|
+
* an HTML/text flavor that would otherwise paste as junk markup). An async
|
|
9
|
+
* "one call" API here would pass in tests and lose pastes in real browsers.
|
|
10
|
+
* Async work on the extracted files (e.g. {@link prepareImageForVision})
|
|
11
|
+
* happens after extraction, on plain `File` objects that stay valid.
|
|
12
|
+
*/
|
|
13
|
+
/**
|
|
14
|
+
* Names browsers assign to clipboard images that never had a real filename
|
|
15
|
+
* (a screenshot, an image copied off a web page). Chrome, Firefox, and
|
|
16
|
+
* Safari all use `image.<ext>`. A file pasted from the OS file manager
|
|
17
|
+
* keeps its real name and never matches.
|
|
18
|
+
*/
|
|
19
|
+
const GENERIC_CLIPBOARD_IMAGE_NAME = /^image\.(png|jpe?g|gif|webp|tiff?|bmp|avif)$/i;
|
|
20
|
+
/** Extension for a synthesized name, keyed by the clipboard MIME type. */
|
|
21
|
+
const IMAGE_MIME_EXTENSIONS = {
|
|
22
|
+
"image/png": "png",
|
|
23
|
+
"image/jpeg": "jpg",
|
|
24
|
+
"image/gif": "gif",
|
|
25
|
+
"image/webp": "webp",
|
|
26
|
+
"image/tiff": "tiff",
|
|
27
|
+
"image/bmp": "bmp",
|
|
28
|
+
"image/avif": "avif",
|
|
29
|
+
"image/svg+xml": "svg",
|
|
30
|
+
};
|
|
31
|
+
/**
|
|
32
|
+
* Monotonic per-page-session counter. Combined with the time component this
|
|
33
|
+
* keeps synthesized names unique even across page reloads within one agent
|
|
34
|
+
* session — required because attachments materialize at
|
|
35
|
+
* `.stigmer/inputs/{filename}` in a session-scoped directory, where a
|
|
36
|
+
* repeated name from a later turn silently replaces the earlier turn's file.
|
|
37
|
+
*/
|
|
38
|
+
let pasteSequence = 0;
|
|
39
|
+
function synthesizePastedImageName(mimeType, now) {
|
|
40
|
+
const pad = (n) => String(n).padStart(2, "0");
|
|
41
|
+
const time = `${pad(now.getHours())}${pad(now.getMinutes())}${pad(now.getSeconds())}`;
|
|
42
|
+
const ext = IMAGE_MIME_EXTENSIONS[mimeType.toLowerCase()] ?? "png";
|
|
43
|
+
pasteSequence += 1;
|
|
44
|
+
return `pasted-image-${time}-${pasteSequence}.${ext}`;
|
|
45
|
+
}
|
|
46
|
+
/**
|
|
47
|
+
* Extracts files from a paste event, giving clipboard images that carry the
|
|
48
|
+
* browser's generic `image.png` name a unique, human-readable one
|
|
49
|
+
* (`pasted-image-<HHMMSS>-<n>.<ext>`).
|
|
50
|
+
*
|
|
51
|
+
* Unique names are load-bearing, not cosmetic: attachments mount at
|
|
52
|
+
* `.stigmer/inputs/{filename}`, and two same-named attachments either fail
|
|
53
|
+
* the execution (deep-agent harness) or silently overwrite each other
|
|
54
|
+
* (Cursor harness). Files with real names (pasted from a file manager) are
|
|
55
|
+
* returned unchanged.
|
|
56
|
+
*
|
|
57
|
+
* Returns an empty array for a text-only paste — callers use that to let
|
|
58
|
+
* the default text insertion proceed untouched.
|
|
59
|
+
*
|
|
60
|
+
* Must be called synchronously from the paste event handler. Call
|
|
61
|
+
* `event.preventDefault()` in the same tick when the result is non-empty;
|
|
62
|
+
* the returned `File` objects remain valid afterwards.
|
|
63
|
+
*
|
|
64
|
+
* @example
|
|
65
|
+
* ```tsx
|
|
66
|
+
* function handlePaste(e: React.ClipboardEvent<HTMLTextAreaElement>) {
|
|
67
|
+
* const files = extractClipboardFiles(e);
|
|
68
|
+
* if (files.length === 0) return; // plain text paste — leave it alone
|
|
69
|
+
* e.preventDefault();
|
|
70
|
+
* attachments.addFiles(files);
|
|
71
|
+
* }
|
|
72
|
+
* ```
|
|
73
|
+
*/
|
|
74
|
+
export function extractClipboardFiles(event) {
|
|
75
|
+
const fileList = event.clipboardData?.files;
|
|
76
|
+
if (!fileList || fileList.length === 0)
|
|
77
|
+
return [];
|
|
78
|
+
return Array.from(fileList).map((file) => {
|
|
79
|
+
const isGenericImage = file.type.toLowerCase().startsWith("image/") &&
|
|
80
|
+
(file.name === "" || GENERIC_CLIPBOARD_IMAGE_NAME.test(file.name));
|
|
81
|
+
if (!isGenericImage)
|
|
82
|
+
return file;
|
|
83
|
+
return new File([file], synthesizePastedImageName(file.type, new Date()), {
|
|
84
|
+
type: file.type,
|
|
85
|
+
lastModified: file.lastModified,
|
|
86
|
+
});
|
|
87
|
+
});
|
|
88
|
+
}
|
|
89
|
+
//# sourceMappingURL=clipboard.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"clipboard.js","sourceRoot":"","sources":["../../src/attachment/clipboard.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AAUH;;;;;GAKG;AACH,MAAM,4BAA4B,GAAG,+CAA+C,CAAC;AAErF,0EAA0E;AAC1E,MAAM,qBAAqB,GAA2B;IACpD,WAAW,EAAE,KAAK;IAClB,YAAY,EAAE,KAAK;IACnB,WAAW,EAAE,KAAK;IAClB,YAAY,EAAE,MAAM;IACpB,YAAY,EAAE,MAAM;IACpB,WAAW,EAAE,KAAK;IAClB,YAAY,EAAE,MAAM;IACpB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I,CAAC,CAAC,IAAI,CAAC,EAAE,yBAAyB,CAAC,IAAI,CAAC,IAAI,EAAE,IAAI,IAAI,EAAE,CAAC,EAAE;YACxE,IAAI,EAAE,IAAI,CAAC,IAAI;YACf,YAAY,EAAE,IAAI,CAAC,YAAY;SAChC,CAAC,CAAC;IACL,CAAC,CAAC,CAAC;AACL,CAAC"}
|
package/attachment/index.d.ts
CHANGED
|
@@ -2,5 +2,10 @@ export { useAttachments } from "./useAttachments.js";
|
|
|
2
2
|
export type { AttachmentPhase, AttachmentEntry, UseAttachmentsOptions, UseAttachmentsReturn, } from "./useAttachments.js";
|
|
3
3
|
export { AttachmentChipList } from "./AttachmentChipList.js";
|
|
4
4
|
export type { AttachmentChipListProps } from "./AttachmentChipList.js";
|
|
5
|
-
export { MAX_ATTACHMENT_BYTES, detectContentType, formatFileSize, validateAttachmentSize, } from "./attachment-utils.js";
|
|
5
|
+
export { MAX_ATTACHMENT_BYTES, detectContentType, formatFileSize, uniquifyFilename, validateAttachmentSize, } from "./attachment-utils.js";
|
|
6
|
+
export { extractClipboardFiles } from "./clipboard.js";
|
|
7
|
+
export type { ClipboardFilesSource } from "./clipboard.js";
|
|
8
|
+
export { prepareImageForVision } from "./prepare-image.js";
|
|
9
|
+
export { MAX_VISION_LONG_EDGE_PX, MAX_VISION_PIXELS, exceedsVisionResolution, fitToVisionResolution, } from "./vision-fit.js";
|
|
10
|
+
export type { VisionFitSize } from "./vision-fit.js";
|
|
6
11
|
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/attachment/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,MAAM,qBAAqB,CAAC;AACrD,YAAY,EACV,eAAe,EACf,eAAe,EACf,qBAAqB,EACrB,oBAAoB,GACrB,MAAM,qBAAqB,CAAC;AAE7B,OAAO,EAAE,kBAAkB,EAAE,MAAM,yBAAyB,CAAC;AAC7D,YAAY,EAAE,uBAAuB,EAAE,MAAM,yBAAyB,CAAC;AAEvE,OAAO,EACL,oBAAoB,EACpB,iBAAiB,EACjB,cAAc,EACd,sBAAsB,GACvB,MAAM,uBAAuB,CAAC"}
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/attachment/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,MAAM,qBAAqB,CAAC;AACrD,YAAY,EACV,eAAe,EACf,eAAe,EACf,qBAAqB,EACrB,oBAAoB,GACrB,MAAM,qBAAqB,CAAC;AAE7B,OAAO,EAAE,kBAAkB,EAAE,MAAM,yBAAyB,CAAC;AAC7D,YAAY,EAAE,uBAAuB,EAAE,MAAM,yBAAyB,CAAC;AAEvE,OAAO,EACL,oBAAoB,EACpB,iBAAiB,EACjB,cAAc,EACd,gBAAgB,EAChB,sBAAsB,GACvB,MAAM,uBAAuB,CAAC;AAE/B,OAAO,EAAE,qBAAqB,EAAE,MAAM,gBAAgB,CAAC;AACvD,YAAY,EAAE,oBAAoB,EAAE,MAAM,gBAAgB,CAAC;AAE3D,OAAO,EAAE,qBAAqB,EAAE,MAAM,oBAAoB,CAAC;AAC3D,OAAO,EACL,uBAAuB,EACvB,iBAAiB,EACjB,uBAAuB,EACvB,qBAAqB,GACtB,MAAM,iBAAiB,CAAC;AACzB,YAAY,EAAE,aAAa,EAAE,MAAM,iBAAiB,CAAC"}
|
package/attachment/index.js
CHANGED
|
@@ -1,4 +1,7 @@
|
|
|
1
1
|
export { useAttachments } from "./useAttachments.js";
|
|
2
2
|
export { AttachmentChipList } from "./AttachmentChipList.js";
|
|
3
|
-
export { MAX_ATTACHMENT_BYTES, detectContentType, formatFileSize, validateAttachmentSize, } from "./attachment-utils.js";
|
|
3
|
+
export { MAX_ATTACHMENT_BYTES, detectContentType, formatFileSize, uniquifyFilename, validateAttachmentSize, } from "./attachment-utils.js";
|
|
4
|
+
export { extractClipboardFiles } from "./clipboard.js";
|
|
5
|
+
export { prepareImageForVision } from "./prepare-image.js";
|
|
6
|
+
export { MAX_VISION_LONG_EDGE_PX, MAX_VISION_PIXELS, exceedsVisionResolution, fitToVisionResolution, } from "./vision-fit.js";
|
|
4
7
|
//# sourceMappingURL=index.js.map
|
package/attachment/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/attachment/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,MAAM,qBAAqB,CAAC;AAQrD,OAAO,EAAE,kBAAkB,EAAE,MAAM,yBAAyB,CAAC;AAG7D,OAAO,EACL,oBAAoB,EACpB,iBAAiB,EACjB,cAAc,EACd,sBAAsB,GACvB,MAAM,uBAAuB,CAAC"}
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/attachment/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,MAAM,qBAAqB,CAAC;AAQrD,OAAO,EAAE,kBAAkB,EAAE,MAAM,yBAAyB,CAAC;AAG7D,OAAO,EACL,oBAAoB,EACpB,iBAAiB,EACjB,cAAc,EACd,gBAAgB,EAChB,sBAAsB,GACvB,MAAM,uBAAuB,CAAC;AAE/B,OAAO,EAAE,qBAAqB,EAAE,MAAM,gBAAgB,CAAC;AAGvD,OAAO,EAAE,qBAAqB,EAAE,MAAM,oBAAoB,CAAC;AAC3D,OAAO,EACL,uBAAuB,EACvB,iBAAiB,EACjB,uBAAuB,EACvB,qBAAqB,GACtB,MAAM,iBAAiB,CAAC"}
|