generated from nhcarrigan/template
feat: add clipboard paste file support (#65)
This commit is contained in:
@@ -441,6 +441,44 @@ User: ${formattedMessage}`;
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function handlePaste(event: ClipboardEvent) {
|
||||||
|
const items = event.clipboardData?.items;
|
||||||
|
if (!items) return;
|
||||||
|
|
||||||
|
for (const item of items) {
|
||||||
|
// Check if the item is a file (image or other)
|
||||||
|
if (item.kind === "file") {
|
||||||
|
const file = item.getAsFile();
|
||||||
|
if (!file) continue;
|
||||||
|
|
||||||
|
// Prevent default for file pastes so we handle it
|
||||||
|
event.preventDefault();
|
||||||
|
|
||||||
|
const filename = file.name || `pasted-${Date.now()}.${file.type.split("/")[1] || "png"}`;
|
||||||
|
const extension = filename.split(".").pop()?.toLowerCase() || "";
|
||||||
|
const fileType = getFileTypeFromExtension(extension);
|
||||||
|
|
||||||
|
// Create preview URL for images
|
||||||
|
let previewUrl: string | undefined;
|
||||||
|
if (fileType === "image" || file.type.startsWith("image/")) {
|
||||||
|
previewUrl = URL.createObjectURL(file);
|
||||||
|
}
|
||||||
|
|
||||||
|
const attachment: Attachment = {
|
||||||
|
id: `attachment-${Date.now()}-${Math.random().toString(36).substr(2, 9)}`,
|
||||||
|
filename,
|
||||||
|
path: filename,
|
||||||
|
size: file.size,
|
||||||
|
type: file.type.startsWith("image/") ? "image" : fileType,
|
||||||
|
mimeType: file.type,
|
||||||
|
previewUrl,
|
||||||
|
};
|
||||||
|
|
||||||
|
claudeStore.addAttachment(attachment);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
function handleKeyDown(event: KeyboardEvent) {
|
function handleKeyDown(event: KeyboardEvent) {
|
||||||
// Handle command menu navigation
|
// Handle command menu navigation
|
||||||
if (showCommandMenu && matchingCommands.length > 0) {
|
if (showCommandMenu && matchingCommands.length > 0) {
|
||||||
@@ -532,6 +570,7 @@ User: ${formattedMessage}`;
|
|||||||
bind:value={inputValue}
|
bind:value={inputValue}
|
||||||
onkeydown={handleKeyDown}
|
onkeydown={handleKeyDown}
|
||||||
oninput={handleInputChange}
|
oninput={handleInputChange}
|
||||||
|
onpaste={handlePaste}
|
||||||
placeholder={isConnected
|
placeholder={isConnected
|
||||||
? "Ask Hikari anything... (type / for commands)"
|
? "Ask Hikari anything... (type / for commands)"
|
||||||
: "Connect to Claude first..."}
|
: "Connect to Claude first..."}
|
||||||
|
|||||||
Reference in New Issue
Block a user