mirror of
https://github.com/DayuanJiang/next-ai-draw-io.git
synced 2026-01-02 22:32:27 +08:00
feat: add clipboard paste handling in ChatInput for image file uploads
This commit is contained in:
@@ -49,6 +49,34 @@ export function ChatInput({
|
|||||||
adjustTextareaHeight();
|
adjustTextareaHeight();
|
||||||
}, [input, adjustTextareaHeight]);
|
}, [input, adjustTextareaHeight]);
|
||||||
|
|
||||||
|
// Handle clipboard paste events
|
||||||
|
const handlePaste = useCallback(
|
||||||
|
(e: React.ClipboardEvent) => {
|
||||||
|
if (!onFileChange) return;
|
||||||
|
|
||||||
|
const items = e.clipboardData.items;
|
||||||
|
const imageItems = Array.from(items).filter(
|
||||||
|
(item) => item.type.indexOf("image") !== -1
|
||||||
|
);
|
||||||
|
|
||||||
|
if (imageItems.length > 0) {
|
||||||
|
e.preventDefault();
|
||||||
|
|
||||||
|
// Convert clipboard image to File
|
||||||
|
const file = imageItems[0].getAsFile();
|
||||||
|
if (file) {
|
||||||
|
// Create a new FileList-like object
|
||||||
|
const dataTransfer = new DataTransfer();
|
||||||
|
dataTransfer.items.add(file);
|
||||||
|
|
||||||
|
// Pass to the existing file handler
|
||||||
|
onFileChange(dataTransfer.files);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
[onFileChange]
|
||||||
|
);
|
||||||
|
|
||||||
// Handle keyboard shortcuts
|
// Handle keyboard shortcuts
|
||||||
const handleKeyDown = (e: React.KeyboardEvent) => {
|
const handleKeyDown = (e: React.KeyboardEvent) => {
|
||||||
if ((e.metaKey || e.ctrlKey) && e.key === "Enter") {
|
if ((e.metaKey || e.ctrlKey) && e.key === "Enter") {
|
||||||
@@ -122,6 +150,7 @@ export function ChatInput({
|
|||||||
value={input}
|
value={input}
|
||||||
onChange={onChange}
|
onChange={onChange}
|
||||||
onKeyDown={handleKeyDown}
|
onKeyDown={handleKeyDown}
|
||||||
|
onPaste={handlePaste}
|
||||||
placeholder="Describe what changes you want to make to the diagram... (Press Cmd/Ctrl + Enter to send)"
|
placeholder="Describe what changes you want to make to the diagram... (Press Cmd/Ctrl + Enter to send)"
|
||||||
disabled={status === "streaming"}
|
disabled={status === "streaming"}
|
||||||
aria-label="Chat input"
|
aria-label="Chat input"
|
||||||
|
|||||||
Reference in New Issue
Block a user