flotilla/src/app/editor/EditorContent.svelte

31 lines
595 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(({options}) => {
if (options.element) {
element?.append(options.element)
}
2025-02-05 18:47:56 +00:00
if (options.autofocus) {
;(element?.querySelector("[contenteditable]") as HTMLElement)?.focus()
}
})
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>