tiptap/examples/Components/Routes/MenuBubble/index.vue

108 lines
2.3 KiB
Vue
Raw Normal View History

2018-08-22 20:10:44 +08:00
<template>
2018-11-09 05:03:10 +08:00
<div class="editor">
2019-04-30 22:19:28 +08:00
<editor-menu-bubble :editor="editor" :keep-in-bounds="keepInBounds">
2018-11-09 05:03:10 +08:00
<div
slot-scope="{ commands, isActive, menu }"
class="menububble"
:class="{ 'is-active': menu.isActive }"
:style="`left: ${menu.left}px; bottom: ${menu.bottom}px;`"
>
2018-08-22 21:58:32 +08:00
2018-11-09 05:03:10 +08:00
<button
class="menububble__button"
2018-11-14 17:05:34 +08:00
:class="{ 'is-active': isActive.bold() }"
2018-11-09 05:03:10 +08:00
@click="commands.bold"
>
<icon name="bold" />
</button>
2018-08-22 21:58:32 +08:00
2018-11-09 05:03:10 +08:00
<button
class="menububble__button"
2018-11-14 17:05:34 +08:00
:class="{ 'is-active': isActive.italic() }"
2018-11-09 05:03:10 +08:00
@click="commands.italic"
>
<icon name="italic" />
</button>
2018-08-22 21:58:32 +08:00
2018-11-09 05:03:10 +08:00
<button
class="menububble__button"
2018-11-14 17:05:34 +08:00
:class="{ 'is-active': isActive.code() }"
2018-11-09 05:03:10 +08:00
@click="commands.code"
>
<icon name="code" />
</button>
2018-08-22 21:58:32 +08:00
2018-11-09 05:03:10 +08:00
</div>
2018-11-09 05:44:07 +08:00
</editor-menu-bubble>
2018-08-22 21:58:32 +08:00
2018-11-09 05:03:10 +08:00
<editor-content class="editor__content" :editor="editor" />
</div>
2018-08-22 20:10:44 +08:00
</template>
<script>
import Icon from 'Components/Icon'
2018-11-09 05:44:07 +08:00
import { Editor, EditorContent, EditorMenuBubble } from 'tiptap'
2018-08-24 04:08:19 +08:00
import {
2018-11-09 05:03:10 +08:00
Blockquote,
BulletList,
CodeBlock,
HardBreak,
Heading,
ListItem,
OrderedList,
TodoItem,
TodoList,
Bold,
Code,
Italic,
Link,
Strike,
Underline,
History,
2018-08-24 04:08:19 +08:00
} from 'tiptap-extensions'
2018-08-22 20:10:44 +08:00
export default {
2018-11-09 05:03:10 +08:00
components: {
EditorContent,
2018-11-09 05:44:07 +08:00
EditorMenuBubble,
2018-11-09 05:03:10 +08:00
Icon,
},
data() {
return {
keepInBounds: true,
2018-11-09 05:03:10 +08:00
editor: new Editor({
extensions: [
new Blockquote(),
new BulletList(),
new CodeBlock(),
new HardBreak(),
new Heading({ levels: [1, 2, 3] }),
new ListItem(),
new OrderedList(),
new TodoItem(),
new TodoList(),
new Bold(),
new Code(),
new Italic(),
new Link(),
new Strike(),
new Underline(),
new History(),
],
content: `
<h2>
Menu Bubble
</h2>
<p>
Hey, try to select some text here. There will popup a menu for selecting some inline styles. <em>Remember:</em> you have full control about content and styling of this menu.
</p>
`,
}),
}
},
beforeDestroy() {
this.editor.destroy()
},
2018-08-22 20:10:44 +08:00
}
2018-11-09 05:03:10 +08:00
</script>