refac/enh: channel input paste behaviour

This commit is contained in:
Timothy Jaeryang Baek 2025-09-17 02:21:45 -05:00
parent 365756c9a2
commit 6549fc839f

View file

@ -888,7 +888,37 @@
}}
on:paste={async (e) => {
e = e.detail.event;
console.info(e);
console.log(e);
const clipboardData = e.clipboardData || window.clipboardData;
if (clipboardData && clipboardData.items) {
for (const item of clipboardData.items) {
if (item.type.indexOf('image') !== -1) {
const blob = item.getAsFile();
const reader = new FileReader();
reader.onload = function (e) {
files = [
...files,
{
type: 'image',
url: `${e.target.result}`
}
];
};
reader.readAsDataURL(blob);
} else if (item?.kind === 'file') {
const file = item.getAsFile();
if (file) {
const _files = [file];
await inputFilesHandler(_files);
e.preventDefault();
}
}
}
}
}}
/>
{/key}