From 6d665711289f46933be6ca0063d45597972ad6e4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Philipp=20Ku=CC=88hn?= Date: Sun, 28 Feb 2021 23:47:34 +0100 Subject: [PATCH] add useEditor --- packages/vue-3/src/index.ts | 1 + packages/vue-3/src/useEditor.ts | 17 +++++++++++++++++ 2 files changed, 18 insertions(+) create mode 100644 packages/vue-3/src/useEditor.ts diff --git a/packages/vue-3/src/index.ts b/packages/vue-3/src/index.ts index 094ea3652..718398d2c 100644 --- a/packages/vue-3/src/index.ts +++ b/packages/vue-3/src/index.ts @@ -1,5 +1,6 @@ export * from '@tiptap/core' export { Editor } from './Editor' export * from './EditorContent' +export * from './useEditor' export * from './VueRenderer' export * from './VueNodeViewRenderer' diff --git a/packages/vue-3/src/useEditor.ts b/packages/vue-3/src/useEditor.ts new file mode 100644 index 000000000..feb93ca0c --- /dev/null +++ b/packages/vue-3/src/useEditor.ts @@ -0,0 +1,17 @@ +import { onMounted, onBeforeUnmount, ref } from 'vue' +import { EditorOptions } from '@tiptap/core' +import { Editor } from './Editor' + +export const useEditor = (options: Partial = {}) => { + const editor = ref() + + onMounted(() => { + editor.value = new Editor(options) + }) + + onBeforeUnmount(() => { + editor.value.destroy() + }) + + return editor +}