2021-03-01 06:47:34 +08:00
|
|
|
import { EditorOptions } from '@tiptap/core'
|
2022-06-08 20:10:25 +08:00
|
|
|
import { onBeforeUnmount, onMounted, shallowRef } from 'vue'
|
|
|
|
|
2023-07-01 03:03:49 +08:00
|
|
|
import { Editor } from './Editor.js'
|
2021-03-01 06:47:34 +08:00
|
|
|
|
2022-01-05 16:21:54 +08:00
|
|
|
export const useEditor = (options: Partial<EditorOptions> = {}) => {
|
|
|
|
const editor = shallowRef<Editor>()
|
2021-03-01 06:47:34 +08:00
|
|
|
|
|
|
|
onMounted(() => {
|
|
|
|
editor.value = new Editor(options)
|
|
|
|
})
|
|
|
|
|
|
|
|
onBeforeUnmount(() => {
|
2021-03-18 04:21:57 +08:00
|
|
|
editor.value?.destroy()
|
2021-03-01 06:47:34 +08:00
|
|
|
})
|
|
|
|
|
|
|
|
return editor
|
|
|
|
}
|