mirror of
https://github.com/ueberdosis/tiptap.git
synced 2025-01-06 02:17:49 +08:00
94 lines
1.9 KiB
Vue
94 lines
1.9 KiB
Vue
<template>
|
|
<div class="editor">
|
|
<menu-bar :editor="editor">
|
|
<div class="menubar" slot-scope="{ commands, isActive }">
|
|
|
|
<button
|
|
class="menubar__button"
|
|
:class="{ 'is-active': isActive('paragraph', { textAlign: 'left' }) }"
|
|
@click="commands.paragraph({ textAlign: 'left' })"
|
|
>
|
|
<icon name="align-left" />
|
|
</button>
|
|
|
|
<button
|
|
class="menubar__button"
|
|
:class="{ 'is-active': isActive('paragraph', { textAlign: 'center' }) }"
|
|
@click="commands.paragraph({ textAlign: 'center' })"
|
|
>
|
|
<icon name="align-center" />
|
|
</button>
|
|
|
|
<button
|
|
class="menubar__button"
|
|
:class="{ 'is-active': isActive('paragraph', { textAlign: 'right' }) }"
|
|
@click="commands.paragraph({ textAlign: 'right' })"
|
|
>
|
|
<icon name="align-right" />
|
|
</button>
|
|
|
|
</div>
|
|
</menu-bar>
|
|
|
|
<editor-content class="editor__content" :editor="editor" />
|
|
</div>
|
|
</template>
|
|
|
|
<script>
|
|
import Icon from 'Components/Icon'
|
|
import { Editor, EditorContent, MenuBar } from 'tiptap'
|
|
import {
|
|
HardBreak,
|
|
Code,
|
|
} from 'tiptap-extensions'
|
|
import ParagraphAlignment from './Paragraph.js'
|
|
|
|
export default {
|
|
components: {
|
|
EditorContent,
|
|
MenuBar,
|
|
Icon,
|
|
},
|
|
data() {
|
|
return {
|
|
editor: new Editor({
|
|
extensions: [
|
|
new HardBreak(),
|
|
new Code(),
|
|
new ParagraphAlignment(),
|
|
],
|
|
content: `
|
|
<p style="text-align: left">
|
|
Maybe you want to implement text alignment. If so, you're able to overwrite the default <code>ParagraphNode</code>. You can define some classes oder inline styles in your schema to achive that.
|
|
</p>
|
|
<p style="text-align: right">
|
|
Have fun! 🙌
|
|
</p>
|
|
`,
|
|
}),
|
|
}
|
|
},
|
|
beforeDestroy() {
|
|
this.editor.destroy()
|
|
},
|
|
}
|
|
</script>
|
|
|
|
<style lang="scss">
|
|
.text-align {
|
|
|
|
&--left {
|
|
text-align: left;
|
|
}
|
|
|
|
&--center {
|
|
text-align: center;
|
|
}
|
|
|
|
&--right {
|
|
text-align: right;
|
|
}
|
|
|
|
}
|
|
</style>
|