2018-08-22 20:10:44 +08:00
|
|
|
<template>
|
2018-11-09 05:03:10 +08:00
|
|
|
<div class="editor">
|
2018-11-09 05:44:07 +08:00
|
|
|
<editor-menu-bubble class="menububble" :editor="editor">
|
2018-11-09 05:03:10 +08:00
|
|
|
<div
|
2018-11-14 17:22:42 +08:00
|
|
|
slot-scope="{ commands, isActive, getMarkAttrs, menu }"
|
2018-11-09 05:03:10 +08:00
|
|
|
class="menububble"
|
|
|
|
:class="{ 'is-active': menu.isActive }"
|
|
|
|
:style="`left: ${menu.left}px; bottom: ${menu.bottom}px;`"
|
|
|
|
>
|
2018-08-22 20:10:44 +08:00
|
|
|
|
2018-11-09 05:03:10 +08:00
|
|
|
<form class="menububble__form" v-if="linkMenuIsActive" @submit.prevent="setLinkUrl(commands.link, linkUrl)">
|
|
|
|
<input class="menububble__input" type="text" v-model="linkUrl" placeholder="https://" ref="linkInput" @keydown.esc="hideLinkMenu"/>
|
|
|
|
<button class="menububble__button" @click="setLinkUrl(commands.link, null)" type="button">
|
|
|
|
<icon name="remove" />
|
|
|
|
</button>
|
|
|
|
</form>
|
2018-08-22 20:10:44 +08:00
|
|
|
|
2018-11-09 05:03:10 +08:00
|
|
|
<template v-else>
|
|
|
|
<button
|
|
|
|
class="menububble__button"
|
2018-11-14 17:22:42 +08:00
|
|
|
@click="showLinkMenu(getMarkAttrs('link'))"
|
2018-11-14 17:05:34 +08:00
|
|
|
:class="{ 'is-active': isActive.link() }"
|
2018-11-09 05:03:10 +08:00
|
|
|
>
|
|
|
|
<span>Add Link</span>
|
|
|
|
<icon name="link" />
|
|
|
|
</button>
|
|
|
|
</template>
|
2018-10-24 05:21:45 +08:00
|
|
|
|
2018-11-09 05:03:10 +08:00
|
|
|
</div>
|
2018-11-09 05:44:07 +08:00
|
|
|
</editor-menu-bubble>
|
2018-10-24 05:21:45 +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,
|
|
|
|
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 {
|
|
|
|
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 History(),
|
|
|
|
],
|
|
|
|
content: `
|
|
|
|
<h2>
|
|
|
|
Links
|
|
|
|
</h2>
|
|
|
|
<p>
|
|
|
|
Try to add some links to the <a href="https://en.wikipedia.org/wiki/World_Wide_Web">world wide web</a>. By default every link will get a <code>rel="noopener noreferrer nofollow"</code> attribute.
|
|
|
|
</p>
|
|
|
|
`,
|
|
|
|
}),
|
|
|
|
linkUrl: null,
|
|
|
|
linkMenuIsActive: false,
|
|
|
|
}
|
|
|
|
},
|
|
|
|
methods: {
|
|
|
|
showLinkMenu(attrs) {
|
|
|
|
this.linkUrl = attrs.href
|
|
|
|
this.linkMenuIsActive = true
|
|
|
|
this.$nextTick(() => {
|
|
|
|
this.$refs.linkInput.focus()
|
|
|
|
})
|
|
|
|
},
|
|
|
|
hideLinkMenu() {
|
|
|
|
this.linkUrl = null
|
|
|
|
this.linkMenuIsActive = false
|
|
|
|
},
|
|
|
|
setLinkUrl(command, url) {
|
|
|
|
command({ href: url })
|
|
|
|
this.hideLinkMenu()
|
|
|
|
this.editor.focus()
|
|
|
|
},
|
|
|
|
},
|
2018-08-22 20:10:44 +08:00
|
|
|
}
|
2018-11-09 05:03:10 +08:00
|
|
|
</script>
|