feat: add image block type (#709)
This commit is contained in:
parent
6c23a8a604
commit
df449a408a
13 changed files with 229 additions and 92 deletions
22
hooks/use-multimodal-copy-to-clipboard.ts
Normal file
22
hooks/use-multimodal-copy-to-clipboard.ts
Normal file
|
|
@ -0,0 +1,22 @@
|
|||
import { useCopyToClipboard } from 'usehooks-ts';
|
||||
|
||||
async function copyImageToClipboard(base64String: string) {
|
||||
try {
|
||||
const blob = await fetch(`data:image/png;base64,${base64String}`).then(
|
||||
(res) => res.blob(),
|
||||
);
|
||||
|
||||
const item = new ClipboardItem({
|
||||
'image/png': blob,
|
||||
});
|
||||
|
||||
await navigator.clipboard.write([item]);
|
||||
} catch (error) {
|
||||
console.error('Failed to copy image to clipboard:', error);
|
||||
}
|
||||
}
|
||||
|
||||
export function useMultimodalCopyToClipboard() {
|
||||
const [_, copyTextToClipboard] = useCopyToClipboard();
|
||||
return { copyTextToClipboard, copyImageToClipboard };
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue