Skip to content

Instantly share code, notes, and snippets.

@IharKrasnik
Created November 3, 2023 12:50
Show Gist options
  • Select an option

  • Save IharKrasnik/43c005c30ba72f57f38062defab40fc4 to your computer and use it in GitHub Desktop.

Select an option

Save IharKrasnik/43c005c30ba72f57f38062defab40fc4 to your computer and use it in GitHub Desktop.
<!-- This code reads images and gifs on clipboard paste
Use it for your rich text editors so your users can edit content fast -->
<script>
import { uploadFile } from 'yourApiLib';
const pasteImage = (evt) => {
Array.from(evt.clipboardData.files).forEach(async (file) => {
if (file.type.startsWith('image/') || file.type.startsWith('video/')) {
uploadFile(file);
}
});
};
</script>
<!-- Here's how you use it in your Html Markup (Svelte Here) -->
<div contenteditable on:paste={pasteImage} />
<input on:paste={pasteImage} />
<textarea on:paste={pasteImage} />
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment