Create new EditorContent component

This commit is contained in:
Jon Staab
2025-02-03 20:57:47 -08:00
parent 7d4ba6c806
commit fedc99b0f0
7 changed files with 59 additions and 39 deletions
+3 -13
View File
@@ -1,6 +1,6 @@
import {asClassComponent} from "svelte/legacy"
import type {Writable} from "svelte/store"
import {derived, readable} from "svelte/store"
import {derived} from "svelte/store"
import {Editor, SvelteNodeViewRenderer} from "svelte-tiptap"
import {ctx} from "@welshman/lib"
import type {StampedEvent} from "@welshman/util"
@@ -44,10 +44,8 @@ export const makeEditor = ({
submit: () => void
uploading?: Writable<boolean>
wordCount?: Writable<number>
}) => {
let setter: (editor: Editor) => void
const _editor = new Editor({
}) =>
new Editor({
content,
autofocus,
extensions: [
@@ -96,15 +94,7 @@ export const makeEditor = ({
}),
],
onUpdate({editor}) {
setter?.(editor)
wordCount?.set(editor.storage.wordCount.words)
charCount?.set(editor.storage.wordCount.chars)
},
})
return readable(_editor, set => {
setter = set
return () => _editor.destroy()
})
}