Skip to content

Commit 0ea7326

Browse files
TheodoreSpeaksTheodore Li
andauthored
feat(ui): handle image paste (#3826)
* feat(ui): handle image paste * Fix lint * Fix type error --------- Co-authored-by: Theodore Li <theo@sim.ai>
1 parent edc5023 commit 0ea7326

File tree

3 files changed

+25
-1
lines changed

3 files changed

+25
-1
lines changed

apps/sim/app/workspace/[workspaceId]/home/components/user-input/user-input.tsx

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -522,6 +522,28 @@ export function UserInput({
522522
[isInitialView]
523523
)
524524

525+
const handlePaste = useCallback((e: React.ClipboardEvent<HTMLTextAreaElement>) => {
526+
const items = e.clipboardData?.items
527+
if (!items) return
528+
529+
const imageFiles: File[] = []
530+
for (const item of Array.from(items)) {
531+
if (item.kind === 'file' && item.type.startsWith('image/')) {
532+
const file = item.getAsFile()
533+
if (file) imageFiles.push(file)
534+
}
535+
}
536+
537+
if (imageFiles.length === 0) return
538+
539+
e.preventDefault()
540+
const dt = new DataTransfer()
541+
for (const file of imageFiles) {
542+
dt.items.add(file)
543+
}
544+
filesRef.current.processFiles(dt.files)
545+
}, [])
546+
525547
const handleScroll = useCallback((e: React.UIEvent<HTMLTextAreaElement>) => {
526548
if (overlayRef.current) {
527549
overlayRef.current.scrollTop = e.currentTarget.scrollTop
@@ -661,6 +683,7 @@ export function UserInput({
661683
onChange={handleInputChange}
662684
onKeyDown={handleKeyDown}
663685
onInput={handleInput}
686+
onPaste={handlePaste}
664687
onCut={mentionTokensWithContext.handleCut}
665688
onSelect={handleSelectAdjust}
666689
onMouseUp={handleSelectAdjust}

apps/sim/app/workspace/[workspaceId]/w/[workflowId]/components/panel/components/copilot/components/user-input/hooks/use-file-attachments.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -320,5 +320,6 @@ export function useFileAttachments(props: UseFileAttachmentsProps) {
320320
handleDragOver,
321321
handleDrop,
322322
clearAttachedFiles,
323+
processFiles,
323324
}
324325
}

apps/sim/lib/auth/hybrid.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ const BEARER_PREFIX = 'Bearer '
2525
export function hasExternalApiCredentials(headers: Headers): boolean {
2626
if (headers.has(API_KEY_HEADER)) return true
2727
const auth = headers.get('authorization')
28-
return auth !== null && auth.startsWith(BEARER_PREFIX)
28+
return auth?.startsWith(BEARER_PREFIX) ?? false
2929
}
3030

3131
export interface AuthResult {

0 commit comments

Comments
 (0)