@@ -71,6 +71,18 @@ export function createPromptAttachments(input: PromptAttachmentsInput) {
7171
7272 const addAttachment = ( file : File ) => add ( file )
7373
74+ const addAttachments = async ( files : File [ ] , toast = true ) => {
75+ let found = false
76+
77+ for ( const file of files ) {
78+ const ok = await add ( file , false )
79+ if ( ok ) found = true
80+ }
81+
82+ if ( ! found && files . length > 0 && toast ) warn ( )
83+ return found
84+ }
85+
7486 const removeAttachment = ( id : string ) => {
7587 const current = prompt . current ( )
7688 const next = current . filter ( ( part ) => part . type !== "image" || part . id !== id )
@@ -84,18 +96,14 @@ export function createPromptAttachments(input: PromptAttachmentsInput) {
8496 event . preventDefault ( )
8597 event . stopPropagation ( )
8698
87- const items = Array . from ( clipboardData . items )
88- const fileItems = items . filter ( ( item ) => item . kind === "file" )
99+ const files = Array . from ( clipboardData . items ) . flatMap ( ( item ) => {
100+ if ( item . kind !== "file" ) return [ ]
101+ const file = item . getAsFile ( )
102+ return file ? [ file ] : [ ]
103+ } )
89104
90- if ( fileItems . length > 0 ) {
91- let found = false
92- for ( const item of fileItems ) {
93- const file = item . getAsFile ( )
94- if ( ! file ) continue
95- const ok = await add ( file , false )
96- if ( ok ) found = true
97- }
98- if ( ! found ) warn ( )
105+ if ( files . length > 0 ) {
106+ await addAttachments ( files )
99107 return
100108 }
101109
@@ -169,12 +177,7 @@ export function createPromptAttachments(input: PromptAttachmentsInput) {
169177 const dropped = event . dataTransfer ?. files
170178 if ( ! dropped ) return
171179
172- let found = false
173- for ( const file of Array . from ( dropped ) ) {
174- const ok = await add ( file , false )
175- if ( ok ) found = true
176- }
177- if ( ! found && dropped . length > 0 ) warn ( )
180+ await addAttachments ( Array . from ( dropped ) )
178181 }
179182
180183 onMount ( ( ) => {
@@ -191,6 +194,7 @@ export function createPromptAttachments(input: PromptAttachmentsInput) {
191194
192195 return {
193196 addAttachment,
197+ addAttachments,
194198 removeAttachment,
195199 handlePaste,
196200 }
0 commit comments