2024-08-19 21:22:16 +00:00
|
|
|
<script lang="ts">
|
2024-08-26 21:43:43 +00:00
|
|
|
import {onMount} from "svelte"
|
2024-11-19 21:24:18 +00:00
|
|
|
import {createEditor, EditorContent} from "svelte-tiptap"
|
2024-11-15 23:16:06 +00:00
|
|
|
import {isMobile} from "@lib/html"
|
2024-08-26 21:43:43 +00:00
|
|
|
import Icon from "@lib/components/Icon.svelte"
|
|
|
|
|
import Button from "@lib/components/Button.svelte"
|
2024-11-16 16:04:09 +00:00
|
|
|
import {getEditorOptions, getEditorTags} from "@lib/editor"
|
2024-09-23 20:58:01 +00:00
|
|
|
import {getPubkeyHints} from "@app/commands"
|
2024-08-23 20:33:36 +00:00
|
|
|
|
2024-11-19 21:24:18 +00:00
|
|
|
export let onSubmit: any
|
2024-10-23 23:41:11 +00:00
|
|
|
export let content = ""
|
2024-11-19 21:24:18 +00:00
|
|
|
export let editor = createEditor(
|
|
|
|
|
getEditorOptions({
|
|
|
|
|
submit,
|
|
|
|
|
getPubkeyHints,
|
|
|
|
|
submitOnEnter: true,
|
|
|
|
|
autofocus: !isMobile,
|
|
|
|
|
}),
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
function submit() {
|
2024-11-16 16:04:09 +00:00
|
|
|
if ($loading) return
|
|
|
|
|
|
2024-10-01 18:47:21 +00:00
|
|
|
onSubmit({
|
2024-10-31 19:24:40 +00:00
|
|
|
content: $editor.getText({blockSeparator: "\n"}),
|
2024-10-01 18:47:21 +00:00
|
|
|
tags: getEditorTags($editor),
|
2024-08-22 23:16:35 +00:00
|
|
|
})
|
2024-08-23 20:33:36 +00:00
|
|
|
|
|
|
|
|
$editor.chain().clearContent().run()
|
2024-08-22 23:16:35 +00:00
|
|
|
}
|
|
|
|
|
|
2024-11-16 16:04:09 +00:00
|
|
|
$: loading = $editor?.storage.fileUpload.loading
|
|
|
|
|
|
2024-08-19 21:22:16 +00:00
|
|
|
onMount(() => {
|
2024-10-23 23:41:11 +00:00
|
|
|
$editor.commands.setContent(content)
|
2024-08-19 21:22:16 +00:00
|
|
|
})
|
|
|
|
|
</script>
|
|
|
|
|
|
2024-11-16 16:04:09 +00:00
|
|
|
<form
|
|
|
|
|
class="relative z-feature flex gap-2 p-2"
|
|
|
|
|
on:submit|preventDefault={$loading ? undefined : submit}>
|
2024-08-26 21:43:43 +00:00
|
|
|
<Button
|
2024-09-11 22:21:25 +00:00
|
|
|
data-tip="Add an image"
|
2024-10-25 00:25:28 +00:00
|
|
|
class="center tooltip tooltip-right h-10 w-10 min-w-10 rounded-box bg-base-300 transition-colors hover:bg-base-200"
|
2024-11-16 16:04:09 +00:00
|
|
|
disabled={$loading}
|
|
|
|
|
on:click={$editor.commands.selectFiles}>
|
2024-09-23 20:58:01 +00:00
|
|
|
{#if $loading}
|
2024-08-22 23:16:35 +00:00
|
|
|
<span class="loading loading-spinner loading-xs"></span>
|
|
|
|
|
{:else}
|
|
|
|
|
<Icon icon="gallery-send" />
|
|
|
|
|
{/if}
|
|
|
|
|
</Button>
|
2024-09-23 20:58:01 +00:00
|
|
|
<div class="chat-editor flex-grow overflow-hidden">
|
2024-08-22 23:16:35 +00:00
|
|
|
<EditorContent editor={$editor} />
|
|
|
|
|
</div>
|
2024-11-16 16:04:09 +00:00
|
|
|
</form>
|