Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1,252 changes: 148 additions & 1,104 deletions site/src/pages/AgentsPage/components/AgentChatInput.tsx

Large diffs are not rendered by default.

26 changes: 3 additions & 23 deletions site/src/pages/AgentsPage/components/AgentComposer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ import {
type ComposerContextValue,
useAgentComposer,
} from "./AgentComposer/context";
import { Frame } from "./AgentComposer/Frame";
import { Frame, FrameEventBoundary } from "./AgentComposer/Frame";
import { useComposerRuntime } from "./AgentComposer/useComposerRuntime";
import { AttachmentPreview } from "./AttachmentPreview";
import { ChatMessageInput } from "./ChatMessageInput/ChatMessageInput";
Expand Down Expand Up @@ -106,20 +106,6 @@ type TextPreview = {
mediaType: string;
};

// Preview dialogs portal out of the frame's DOM but still bubble React
// events through it. Stopping the events the frame handles keeps Escape
// and file drops inside a preview from cancelling an edit, interrupting
// the stream, or attaching files.
const stopFrameEvent = (event: React.SyntheticEvent) => {
event.stopPropagation();
};

const stopFrameEscape = (event: React.KeyboardEvent) => {
if (event.key === "Escape") {
event.stopPropagation();
}
};

function Attachments({
onTextPreview,
}: {
Expand Down Expand Up @@ -169,13 +155,7 @@ function Attachments({
/>
)}
{isPreviewOpen && (
<div
role="presentation"
onKeyDown={stopFrameEscape}
onDragOver={stopFrameEvent}
onDragLeave={stopFrameEvent}
onDrop={stopFrameEvent}
>
<FrameEventBoundary>
{previewImage && (
<ImageLightbox
src={previewImage}
Expand All @@ -188,7 +168,7 @@ function Attachments({
onClose={() => setPreviewText(null)}
/>
)}
</div>
</FrameEventBoundary>
)}
</>
);
Expand Down
37 changes: 37 additions & 0 deletions site/src/pages/AgentsPage/components/AgentComposer/Frame.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,43 @@ function synchronizeDropdownViewport(composerElement: HTMLDivElement) {
};
}

const stopFrameEvent = (event: React.SyntheticEvent) => {
event.stopPropagation();
};

const stopFrameEscape = (event: React.KeyboardEvent) => {
if (event.key === "Escape") {
event.stopPropagation();
}
};

/**
* Wraps dialogs rendered inside the frame. Dialogs portal out of the
* frame's DOM but still bubble React events through it, so this stops the
* events the frame handles: Escape and file drops inside a dialog do not
* cancel an edit, interrupt the stream, or attach files.
*/
export function FrameEventBoundary({
children,
className,
}: {
children: React.ReactNode;
className?: string;
}) {
return (
<div
role="presentation"
className={className}
onKeyDown={stopFrameEscape}
onDragOver={stopFrameEvent}
onDragLeave={stopFrameEvent}
onDrop={stopFrameEvent}
>
{children}
</div>
);
}

/** Anchors composer interactions and synchronizes mobile dropdown geometry. */
export function Frame({
children,
Expand Down
Loading
Loading