2019-06-22 04:00:42 +08:00
|
|
|
<template>
|
|
|
|
<div class="editor">
|
|
|
|
<editor-content class="editor__content" :editor="editor" />
|
|
|
|
</div>
|
|
|
|
</template>
|
|
|
|
|
|
|
|
<script>
|
|
|
|
import { Editor, EditorContent } from 'tiptap'
|
|
|
|
import { Placeholder } from 'tiptap-extensions'
|
|
|
|
import Doc from './Doc'
|
|
|
|
import Title from './Title'
|
|
|
|
|
|
|
|
export default {
|
|
|
|
components: {
|
|
|
|
EditorContent,
|
|
|
|
},
|
|
|
|
data() {
|
|
|
|
return {
|
|
|
|
editor: new Editor({
|
2019-06-22 04:36:48 +08:00
|
|
|
autoFocus: true,
|
2019-06-22 04:00:42 +08:00
|
|
|
extensions: [
|
|
|
|
new Doc(),
|
|
|
|
new Title(),
|
|
|
|
new Placeholder({
|
2019-06-22 04:36:48 +08:00
|
|
|
showOnlyCurrent: false,
|
|
|
|
emptyNodeText: node => {
|
|
|
|
if (node.type.name === 'title') {
|
|
|
|
return 'Give me a name'
|
|
|
|
}
|
|
|
|
|
|
|
|
return 'Write something'
|
|
|
|
},
|
2019-06-22 04:00:42 +08:00
|
|
|
}),
|
|
|
|
],
|
|
|
|
}),
|
|
|
|
}
|
|
|
|
},
|
|
|
|
beforeDestroy() {
|
|
|
|
this.editor.destroy()
|
|
|
|
},
|
|
|
|
}
|
|
|
|
</script>
|
|
|
|
|
|
|
|
<style lang="scss">
|
2019-06-22 04:36:48 +08:00
|
|
|
.editor *.is-empty:nth-child(1)::before,
|
|
|
|
.editor *.is-empty:nth-child(2)::before {
|
2019-06-22 04:00:42 +08:00
|
|
|
content: attr(data-empty-text);
|
|
|
|
float: left;
|
|
|
|
color: #aaa;
|
|
|
|
pointer-events: none;
|
|
|
|
height: 0;
|
|
|
|
font-style: italic;
|
|
|
|
}
|
|
|
|
</style>
|