Enable image pasting in markdown textarea

This commit is contained in:
thiloho
2024-08-19 19:31:41 +02:00
parent ec23a6188a
commit 5cc329c2f1
5 changed files with 99 additions and 3 deletions

View File

@@ -1,7 +1,7 @@
<script lang="ts">
import { enhance } from "$app/forms";
import WebsiteEditor from "$lib/components/WebsiteEditor.svelte";
import { ALLOWED_MIME_TYPES } from "$lib/utils";
import { ALLOWED_MIME_TYPES, handleImagePaste } from "$lib/utils";
import SuccessOrError from "$lib/components/SuccessOrError.svelte";
import type { ActionData, PageServerData } from "./$types";
import Modal from "$lib/components/Modal.svelte";
@@ -17,6 +17,11 @@
const { scrollTop, scrollHeight, clientHeight } = mainContentTextarea;
textareaScrollTop = (scrollTop / (scrollHeight - clientHeight)) * 100;
};
const handlePaste = async (event: ClipboardEvent) => {
const newContent = await handleImagePaste(event);
previewContent = newContent;
};
</script>
<SuccessOrError success={form?.success} message={form?.message} />
@@ -149,6 +154,7 @@
bind:value={previewContent}
bind:this={mainContentTextarea}
onscroll={updateScrollPercentage}
onpaste={handlePaste}
required>{data.home.main_content}</textarea
>
</label>