flotilla/src/app/editor/EditorContent.svelte

35 lines
690 B
Svelte
Raw Normal View History

2025-02-05 16:54:04 +00:00
<script lang="ts">
import {Editor} from "@welshman/editor"
2025-02-05 16:54:04 +00:00
import {onDestroy, onMount} from "svelte"
type Props = {
editor: Promise<Editor>
}
const {editor}: Props = $props()
2025-02-05 16:54:04 +00:00
let element: HTMLElement
onMount(() => {
editor.then(ed => {
if (ed.options.element) {
element?.append(ed.options.element)
}
2025-02-05 18:47:56 +00:00
if ((ed as any)._shouldAutofocus) {
const hasContent = ed.getText().trim().length > 0
requestAnimationFrame(() => {
ed.commands.focus(hasContent ? "end" : "start")
})
}
})
2025-02-05 16:54:04 +00:00
})
onDestroy(() => {
editor.then($editor => $editor.destroy())
2025-02-05 16:54:04 +00:00
})
</script>
<div bind:this={element}></div>