From: Luca Stefani Date: Wed, 14 May 2025 08:07:31 +0000 (+0200) Subject: webui: Allow pasting file from clipboard (#13526) X-Git-Url: https://git.djapps.eu/?a=commitdiff_plain;h=d486dd3e8ecfba0170f8632a1530540de560f4a3;p=pkg%2Fggml%2Fsources%2Fllama.cpp webui: Allow pasting file from clipboard (#13526) * server: Allow pasting file from clipboard * server: Prevent default action on file paste * update build * format then build combined --------- Co-authored-by: Xuan Son Nguyen --- diff --git a/tools/server/public/index.html.gz b/tools/server/public/index.html.gz index d7363e13..a2a2ee12 100644 Binary files a/tools/server/public/index.html.gz and b/tools/server/public/index.html.gz differ diff --git a/tools/server/webui/package.json b/tools/server/webui/package.json index ab1b920b..b83defdf 100644 --- a/tools/server/webui/package.json +++ b/tools/server/webui/package.json @@ -5,7 +5,7 @@ "type": "module", "scripts": { "dev": "vite", - "build": "tsc -b && vite build", + "build": "npm run format && tsc -b && vite build", "format": "eslint . && prettier --write .", "lint": "eslint .", "preview": "vite preview" diff --git a/tools/server/webui/src/components/ChatScreen.tsx b/tools/server/webui/src/components/ChatScreen.tsx index b645a494..7d53fe8a 100644 --- a/tools/server/webui/src/components/ChatScreen.tsx +++ b/tools/server/webui/src/components/ChatScreen.tsx @@ -1,4 +1,4 @@ -import { useEffect, useMemo, useRef, useState } from 'react'; +import { ClipboardEvent, useEffect, useMemo, useRef, useState } from 'react'; import { CallbackGeneratedChunk, useAppContext } from '../utils/app.context'; import ChatMessage from './ChatMessage'; import { CanvasType, Message, PendingMessage } from '../utils/types'; @@ -328,6 +328,17 @@ function ChatInput({ {({ getRootProps, getInputProps }) => (
) => { + const files = Array.from(e.clipboardData.items) + .filter((item) => item.kind === 'file') + .map((item) => item.getAsFile()) + .filter((file) => file !== null); + + if (files.length > 0) { + e.preventDefault(); + extraContext.onFileAdded(files); + } + }} {...getRootProps()} > {!isGenerating && (