Spaces:
Runtime error
Runtime error
Liam Dyer
Mishig
commited on
feat: support file pasting in chat input (#1206)
Browse files* feat: support file pasting in chat input
* Forward paste event & simplify pasted file logic (#1212)
Forward paste event & simplify file logic
---------
Co-authored-by: Mishig <mishig.davaadorj@coloradocollege.edu>
src/lib/components/chat/ChatInput.svelte
CHANGED
|
@@ -37,7 +37,7 @@
|
|
| 37 |
});
|
| 38 |
</script>
|
| 39 |
|
| 40 |
-
<div class="relative min-w-0 flex-1">
|
| 41 |
<pre
|
| 42 |
class="scrollbar-custom invisible overflow-x-hidden overflow-y-scroll whitespace-pre-wrap break-words p-3"
|
| 43 |
aria-hidden="true"
|
|
|
|
| 37 |
});
|
| 38 |
</script>
|
| 39 |
|
| 40 |
+
<div class="relative min-w-0 flex-1" on:paste>
|
| 41 |
<pre
|
| 42 |
class="scrollbar-custom invisible overflow-x-hidden overflow-y-scroll whitespace-pre-wrap break-words p-3"
|
| 43 |
aria-hidden="true"
|
src/lib/components/chat/ChatWindow.svelte
CHANGED
|
@@ -84,6 +84,19 @@
|
|
| 84 |
e.preventDefault();
|
| 85 |
};
|
| 86 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 87 |
const convTreeStore = useConvTreeStore();
|
| 88 |
|
| 89 |
$: lastMessage = browser && (messages.find((m) => m.id == $convTreeStore.leaf) as Message);
|
|
@@ -324,6 +337,7 @@
|
|
| 324 |
loginModalOpen = true;
|
| 325 |
}
|
| 326 |
}}
|
|
|
|
| 327 |
maxRows={6}
|
| 328 |
disabled={isReadOnly || lastIsError}
|
| 329 |
/>
|
|
|
|
| 84 |
e.preventDefault();
|
| 85 |
};
|
| 86 |
|
| 87 |
+
const onPaste = (e: ClipboardEvent) => {
|
| 88 |
+
if (!e.clipboardData) {
|
| 89 |
+
return;
|
| 90 |
+
}
|
| 91 |
+
|
| 92 |
+
// paste of files
|
| 93 |
+
const pastedFiles = Array.from(e.clipboardData.files);
|
| 94 |
+
if (pastedFiles.length !== 0) {
|
| 95 |
+
e.preventDefault();
|
| 96 |
+
files = [...files, ...pastedFiles];
|
| 97 |
+
}
|
| 98 |
+
};
|
| 99 |
+
|
| 100 |
const convTreeStore = useConvTreeStore();
|
| 101 |
|
| 102 |
$: lastMessage = browser && (messages.find((m) => m.id == $convTreeStore.leaf) as Message);
|
|
|
|
| 337 |
loginModalOpen = true;
|
| 338 |
}
|
| 339 |
}}
|
| 340 |
+
on:paste={onPaste}
|
| 341 |
maxRows={6}
|
| 342 |
disabled={isReadOnly || lastIsError}
|
| 343 |
/>
|