-
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Tiptap.vue
55 lines (41 loc) · 1.42 KB
/
Tiptap.vue
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
<script setup lang="ts">
import { ref } from 'vue';
import StarterKit from '@tiptap/starter-kit';
import { EditorContent, useEditor } from '@tiptap/vue-3';
import { SnippetExtension } from './extensions';
const emit = defineEmits(['newSnippet'])
interface Snippet {
name: string
content: string
}
const snippetName = ref("")
const editor = useEditor({
content: '<p>Example of Snippets with tiptap. 🎉 If you 👍 / ❤️ what I\'m doing, consider 🌟ing the repo, I and the Open-Source-Community appreciate it very much ❤️. </p><p></p><p>Drag a snippet from right and drop it in the line above and see the magic!</p><p>PS: you can create a new snippet from current editor content by giving it a name and pressing "create snippet" button</p>',
extensions: [StarterKit, SnippetExtension],
})
const logHtml = () => {
const snippet: Snippet = {
name: snippetName.value,
content: editor.value?.getHTML() || "<p> Snippet failed </p>"
}
emit('newSnippet', snippet)
}
</script>
<template>
<section class="flex gap-1rem">
<i-input v-model="snippetName" placeholder="New snippet name...">
<template #prepend>
<b>Create new snippet from current editor content.</b>
</template>
</i-input>
<i-button @click="logHtml"> Create </i-button>
</section>
<editor-content :editor="editor" />
</template>
<style lang="scss">
.ProseMirror {
&:focus {
outline: none !important;
}
}
</style>