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

209 lines
3.9 KiB
Vue
Raw Normal View History

2018-08-22 19:30:53 +08:00
<template>
2018-10-22 14:43:48 +08:00
<div class="editor">
<menu-bar class="menubar" :editor="editor">
2018-10-29 05:17:21 +08:00
<template slot-scope="{ nodes, marks, commands }">
2018-10-29 02:26:14 +08:00
<button
class="menubar__button"
2018-10-29 05:17:21 +08:00
@click="commands.undo"
2018-10-29 02:26:14 +08:00
>
</button>
<button
class="menubar__button"
2018-10-29 05:17:21 +08:00
@click="commands.redo"
2018-10-29 02:26:14 +08:00
>
</button>
2018-10-22 14:43:48 +08:00
<button
class="menubar__button"
:class="{ 'is-active': marks.bold.active() }"
2018-10-29 05:57:05 +08:00
@click="commands.bold"
2018-10-22 14:43:48 +08:00
>
<icon name="bold" />
</button>
<button
class="menubar__button"
:class="{ 'is-active': marks.italic.active() }"
2018-10-29 05:57:05 +08:00
@click="commands.italic"
2018-10-22 14:43:48 +08:00
>
<icon name="italic" />
</button>
<button
class="menubar__button"
:class="{ 'is-active': marks.strike.active() }"
2018-10-29 05:57:05 +08:00
@click="commands.strike"
2018-10-22 14:43:48 +08:00
>
<icon name="strike" />
</button>
<button
class="menubar__button"
:class="{ 'is-active': marks.underline.active() }"
2018-10-29 05:57:05 +08:00
@click="commands.underline"
2018-10-22 14:43:48 +08:00
>
<icon name="underline" />
</button>
<button
class="menubar__button"
2018-10-29 05:57:05 +08:00
:class="{ 'is-active': marks.code.active() }"
@click="commands.code"
>
2018-10-22 14:43:48 +08:00
<icon name="code" />
</button>
<button
class="menubar__button"
:class="{ 'is-active': nodes.paragraph.active() }"
2018-10-29 05:57:05 +08:00
@click="commands.paragraph"
2018-10-22 14:43:48 +08:00
>
<icon name="paragraph" />
</button>
<button
class="menubar__button"
:class="{ 'is-active': nodes.heading.active({ level: 1 }) }"
2018-10-29 05:57:05 +08:00
@click="commands.heading({ level: 1 })"
2018-10-22 14:43:48 +08:00
>
H1
</button>
<button
class="menubar__button"
:class="{ 'is-active': nodes.heading.active({ level: 2 }) }"
2018-10-29 05:57:05 +08:00
@click="commands.heading({ level: 2 })"
2018-10-22 14:43:48 +08:00
>
H2
</button>
<button
class="menubar__button"
:class="{ 'is-active': nodes.heading.active({ level: 3 }) }"
2018-10-29 05:57:05 +08:00
@click="commands.heading({ level: 3 })"
2018-10-22 14:43:48 +08:00
>
H3
</button>
<button
class="menubar__button"
:class="{ 'is-active': nodes.bullet_list.active() }"
2018-10-29 05:57:05 +08:00
@click="commands.bullet_list"
2018-10-22 14:43:48 +08:00
>
<icon name="ul" />
</button>
<button
class="menubar__button"
:class="{ 'is-active': nodes.ordered_list.active() }"
2018-10-29 05:57:05 +08:00
@click="commands.ordered_list"
2018-10-22 14:43:48 +08:00
>
<icon name="ol" />
</button>
<button
class="menubar__button"
:class="{ 'is-active': nodes.blockquote.active() }"
2018-10-29 05:57:05 +08:00
@click="commands.blockquote"
2018-10-22 14:43:48 +08:00
>
<icon name="quote" />
</button>
<button
class="menubar__button"
:class="{ 'is-active': nodes.code_block.active() }"
2018-10-29 05:57:05 +08:00
@click="commands.code_block"
2018-10-22 14:43:48 +08:00
>
<icon name="code" />
</button>
</template>
</menu-bar>
<editor-content class="editor__content" :editor="editor" />
2018-08-22 19:30:53 +08:00
</div>
</template>
<script>
import Icon from 'Components/Icon'
2018-10-22 04:44:13 +08:00
import { Editor, EditorContent, MenuBar } from 'tiptap'
2018-10-22 03:55:24 +08:00
import {
2018-10-24 13:46:47 +08:00
Blockquote,
BulletList,
CodeBlock,
HardBreak,
Heading,
ListItem,
OrderedList,
TodoItem,
TodoList,
Bold,
Code,
Italic,
Link,
Strike,
Underline,
History,
2018-10-22 03:55:24 +08:00
} from 'tiptap-extensions'
2018-08-22 19:30:53 +08:00
export default {
2018-08-23 01:28:57 +08:00
components: {
2018-10-21 21:50:10 +08:00
EditorContent,
2018-10-22 04:44:13 +08:00
MenuBar,
2018-08-23 01:28:57 +08:00
Icon,
},
2018-08-24 04:08:19 +08:00
data() {
return {
2018-10-21 21:50:10 +08:00
editor: new Editor({
extensions: [
2018-10-24 13:46:47 +08:00
new Blockquote(),
new BulletList(),
new CodeBlock(),
new HardBreak(),
new Heading({ levels: [1, 2, 3] }),
2018-10-24 13:46:47 +08:00
new ListItem(),
new OrderedList(),
new TodoItem(),
new TodoList(),
new Bold(),
new Code(),
new Italic(),
new Link(),
new Strike(),
new Underline(),
new History(),
2018-10-21 21:50:10 +08:00
],
2018-10-22 14:43:48 +08:00
content: `
<h2>
Hi there,
</h2>
<p>
this is a very <em>basic</em> example of tiptap.
</p>
<pre><code>body { display: none; }</code></pre>
<ul>
<li>
A regular list
</li>
<li>
With regular items
</li>
</ul>
<blockquote>
It's amazing 👏
<br />
mom
</blockquote>
`,
2018-10-21 21:50:10 +08:00
}),
2018-08-24 04:08:19 +08:00
}
},
2018-10-23 03:40:12 +08:00
beforeDestroy() {
this.editor.destroy()
},
2018-08-22 19:30:53 +08:00
}
</script>