2020-01-15 23:18:00 +01:00
|
|
|
<template lang='pug'>
|
2020-07-28 12:24:39 +02:00
|
|
|
.editor
|
2020-08-16 14:07:25 +02:00
|
|
|
editor-menu-bar.menubar.is-hidden(:editor='editor'
|
|
|
|
:keep-in-bounds='true' v-slot='{ commands, isActive, getMarkAttrs, focused }')
|
|
|
|
v-btn-toggle(dense :class="{ focused }")
|
2020-10-09 00:38:56 +02:00
|
|
|
v-btn(icon text tabindex='-1'
|
2020-08-16 14:07:25 +02:00
|
|
|
:class="{ primary: isActive.bold() }"
|
2020-07-28 12:24:39 +02:00
|
|
|
@click="commands.bold")
|
|
|
|
v-icon mdi-format-bold
|
2020-08-16 14:07:25 +02:00
|
|
|
|
2020-10-09 00:38:56 +02:00
|
|
|
v-btn(icon text tabindex='-1'
|
2020-08-16 14:07:25 +02:00
|
|
|
:class="{ primary: isActive.underline() }"
|
2020-07-28 12:24:39 +02:00
|
|
|
@click="commands.underline")
|
2020-08-16 14:07:25 +02:00
|
|
|
v-icon mdi-format-underline
|
|
|
|
|
2020-10-09 00:38:56 +02:00
|
|
|
v-btn(icon text tabindex='-1'
|
2020-08-16 14:07:25 +02:00
|
|
|
:class="{ primary: isActive.strike() }"
|
|
|
|
@click="commands.strike")
|
|
|
|
v-icon mdi-format-strikethrough-variant
|
|
|
|
|
2020-10-09 00:38:56 +02:00
|
|
|
v-btn(icon text tabindex='-1'
|
2020-08-16 14:07:25 +02:00
|
|
|
:class="{ primary: isActive.italic() }"
|
|
|
|
@click="commands.italic")
|
2020-07-28 12:24:39 +02:00
|
|
|
v-icon mdi-format-italic
|
|
|
|
|
2020-10-09 00:38:56 +02:00
|
|
|
v-btn(icon text tabindex='-1'
|
2020-08-16 14:07:25 +02:00
|
|
|
:class="{ primary: isActive.heading({level: 1}) }"
|
|
|
|
@click="commands.heading({level: 1})")
|
|
|
|
v-icon mdi-format-header-1
|
|
|
|
|
2020-10-09 00:38:56 +02:00
|
|
|
v-btn(icon text tabindex='-1'
|
2020-08-16 14:07:25 +02:00
|
|
|
:class="{ primary: isActive.heading({level: 2}) }"
|
|
|
|
@click="commands.heading({level: 2})")
|
|
|
|
v-icon mdi-format-header-2
|
|
|
|
|
2020-10-09 00:38:56 +02:00
|
|
|
v-btn(icon text tabindex='-1'
|
2020-08-16 14:07:25 +02:00
|
|
|
:class="{ primary: isActive.heading({level: 3}) }"
|
|
|
|
@click="commands.heading({level: 3})")
|
|
|
|
v-icon mdi-format-header-3
|
|
|
|
|
2020-10-09 00:38:56 +02:00
|
|
|
v-btn(icon text tabindex='-1'
|
2020-08-16 14:07:25 +02:00
|
|
|
:class="{ primary: isActive.code() }"
|
|
|
|
@click="commands.code")
|
|
|
|
v-icon mdi-code-tags
|
|
|
|
|
2020-10-09 00:38:56 +02:00
|
|
|
v-btn(icon text tabindex='-1'
|
2020-08-16 14:07:25 +02:00
|
|
|
:class="{ primary: isActive.blockquote() }"
|
|
|
|
@click="commands.blockquote")
|
|
|
|
v-icon mdi-format-quote-open
|
|
|
|
|
2020-10-09 00:38:56 +02:00
|
|
|
v-btn(icon text tabindex='-1'
|
2020-08-16 14:07:25 +02:00
|
|
|
:class="{ primary: isActive.bullet_list() }"
|
|
|
|
@click="commands.bullet_list")
|
|
|
|
v-icon mdi-format-list-bulleted
|
|
|
|
|
2020-10-09 00:38:56 +02:00
|
|
|
v-btn(icon text tabindex='-1' :class='{ primary: isActive.link() }'
|
2020-08-16 14:07:25 +02:00
|
|
|
@click='commands.link({href: ""}); $refs.link.focus(); linkActive=true')
|
|
|
|
v-icon mdi-link
|
|
|
|
|
|
|
|
editor-content.content(:editor='editor' spellcheck='false' :style="{ 'max-height': maxHeight }")
|
2020-01-15 23:18:00 +01:00
|
|
|
</template>
|
|
|
|
<script>
|
|
|
|
import _ from 'lodash'
|
2020-07-05 23:51:45 +02:00
|
|
|
import { Editor, EditorContent, EditorMenuBar, EditorMenuBubble } from 'tiptap'
|
2020-01-15 23:18:00 +01:00
|
|
|
import {
|
|
|
|
Blockquote,
|
|
|
|
BulletList,
|
|
|
|
CodeBlock,
|
|
|
|
HardBreak,
|
|
|
|
Heading,
|
|
|
|
ListItem,
|
|
|
|
OrderedList,
|
|
|
|
Bold,
|
|
|
|
Code,
|
|
|
|
Italic,
|
|
|
|
Link,
|
|
|
|
History,
|
|
|
|
Strike,
|
2020-10-09 00:38:56 +02:00
|
|
|
Underline,
|
|
|
|
Placeholder
|
2020-01-15 23:18:00 +01:00
|
|
|
} from 'tiptap-extensions'
|
|
|
|
|
|
|
|
export default {
|
|
|
|
name: 'Editor',
|
|
|
|
components: { EditorContent, EditorMenuBar, EditorMenuBubble },
|
|
|
|
props: {
|
|
|
|
value: { type: String, default: '' },
|
|
|
|
border: { type: Boolean, default: false },
|
2020-08-16 14:07:25 +02:00
|
|
|
noSave: { type: Boolean, default: false },
|
2020-10-09 00:38:56 +02:00
|
|
|
maxHeight: { type: String, Number, default: '' },
|
|
|
|
placeholder: { type: String, default: '' }
|
2020-01-15 23:18:00 +01:00
|
|
|
},
|
|
|
|
data () {
|
|
|
|
return {
|
2020-07-28 12:24:39 +02:00
|
|
|
options: [],
|
2020-01-15 23:18:00 +01:00
|
|
|
linkActive: false,
|
2020-02-16 21:04:18 +01:00
|
|
|
editor: null,
|
|
|
|
update: false
|
|
|
|
}
|
|
|
|
},
|
|
|
|
watch: {
|
|
|
|
value () {
|
|
|
|
if (this.update) {
|
|
|
|
this.update = false
|
|
|
|
return
|
|
|
|
}
|
|
|
|
this.editor.setContent(this.value)
|
2020-01-15 23:18:00 +01:00
|
|
|
}
|
|
|
|
},
|
|
|
|
mounted () {
|
|
|
|
this.editor = new Editor({
|
2020-02-16 21:04:18 +01:00
|
|
|
onUpdate: _.debounce(({ getHTML }) => {
|
|
|
|
this.update = true
|
|
|
|
this.$emit('input', getHTML())
|
2020-10-09 00:38:56 +02:00
|
|
|
}, 1000),
|
2020-01-15 23:18:00 +01:00
|
|
|
content: this.value,
|
|
|
|
extensions: [
|
|
|
|
new Blockquote(),
|
|
|
|
new BulletList(),
|
|
|
|
new CodeBlock(),
|
|
|
|
new HardBreak(),
|
|
|
|
new Heading({ levels: [1, 2, 3, 4, 5, 6] }),
|
|
|
|
new OrderedList(),
|
|
|
|
new ListItem(),
|
|
|
|
new Code(),
|
|
|
|
new History(),
|
|
|
|
new Link({ openOnClick: false }),
|
|
|
|
new Bold(),
|
|
|
|
new Italic(),
|
|
|
|
new Strike(),
|
2020-10-09 00:38:56 +02:00
|
|
|
new Underline(),
|
|
|
|
new Placeholder({
|
|
|
|
emptyEditorClass: 'is-editor-empty',
|
|
|
|
emptyNodeClass: 'is-empty',
|
|
|
|
emptyNodeText: this.placeholder,
|
|
|
|
showOnlyWhenEditable: true,
|
|
|
|
showOnlyCurrent: true,
|
|
|
|
})
|
2020-01-15 23:18:00 +01:00
|
|
|
]
|
|
|
|
})
|
|
|
|
},
|
|
|
|
beforeDestroy () {
|
|
|
|
if (this.editor) { this.editor.destroy() }
|
|
|
|
}
|
|
|
|
}
|
|
|
|
</script>
|
2020-01-21 22:59:54 +01:00
|
|
|
<style lang='less'>
|
2020-10-09 00:38:56 +02:00
|
|
|
.editor p.is-editor-empty:first-child::before {
|
|
|
|
content: attr(data-empty-text);
|
|
|
|
float: left;
|
|
|
|
color: #aaa;
|
|
|
|
// opacity: .4;
|
|
|
|
pointer-events: none;
|
|
|
|
height: 0;
|
|
|
|
font-style: italic;
|
|
|
|
}
|
2020-07-28 12:24:39 +02:00
|
|
|
.editor {
|
2020-08-16 14:07:25 +02:00
|
|
|
// max-height: auto;
|
|
|
|
// height: auto;
|
2020-10-07 10:05:09 +02:00
|
|
|
overflow-y: auto;
|
|
|
|
scrollbar-width: thin;
|
|
|
|
scrollbar-color: #FF4500 transparent;
|
|
|
|
scroll-behavior: smooth;
|
2020-07-28 12:24:39 +02:00
|
|
|
font-family: sans-serif;
|
|
|
|
font-size: 1.1em;
|
|
|
|
border-color: currentColor;
|
|
|
|
border-style: solid;
|
|
|
|
border-width: 0 0 thin 0;
|
2020-08-16 14:07:25 +02:00
|
|
|
// background-color: rgba(255,255,255,0.04);
|
|
|
|
.focused {
|
|
|
|
opacity: 1 !important;
|
|
|
|
}
|
|
|
|
.menubar {
|
|
|
|
opacity: .3;
|
|
|
|
// position: absolute;
|
|
|
|
}
|
|
|
|
|
|
|
|
.ProseMirror {
|
|
|
|
padding: 15px;
|
|
|
|
outline: 0;
|
|
|
|
}
|
2020-07-28 12:24:39 +02:00
|
|
|
}
|
2020-07-25 21:41:22 +02:00
|
|
|
// position: relative;
|
|
|
|
// overflow-y: auto;
|
|
|
|
// padding-top: 1.7em;
|
2020-01-15 23:18:00 +01:00
|
|
|
|
2020-07-25 21:41:22 +02:00
|
|
|
// &.with-border {
|
|
|
|
// border: 1px solid #ddd;
|
|
|
|
// border-radius: 5px;
|
|
|
|
// }
|
2020-01-15 23:18:00 +01:00
|
|
|
|
2020-07-25 21:41:22 +02:00
|
|
|
// .content {
|
|
|
|
// padding: 0px 5px 0px 5px;
|
|
|
|
// flex: 1;
|
|
|
|
// scrollbar-width: thin;
|
|
|
|
// overflow-y: auto;
|
|
|
|
// }
|
2020-01-15 23:18:00 +01:00
|
|
|
|
2020-07-25 21:41:22 +02:00
|
|
|
// .menububble {
|
|
|
|
// position: absolute;
|
|
|
|
// display: flex;
|
|
|
|
// overflow: hidden;
|
|
|
|
// opacity: 0;
|
|
|
|
// z-index: 1;
|
|
|
|
// background: #dddddd;
|
|
|
|
// transform: translateX(-50%);
|
|
|
|
// border-radius: 3px;
|
|
|
|
// padding: 0.07rem;
|
|
|
|
// transition: opacity 0.2s, visibility 0.2s, left .2s, bottom .2s;
|
|
|
|
// visibility: hidden;
|
2020-01-15 23:18:00 +01:00
|
|
|
|
2020-07-25 21:41:22 +02:00
|
|
|
// &.is-active {
|
|
|
|
// opacity: 1;
|
|
|
|
// visibility: visible;
|
|
|
|
// }
|
|
|
|
// input {
|
|
|
|
// padding: 0;
|
|
|
|
// margin: 1px;
|
|
|
|
// display: block;
|
|
|
|
// border: 0;
|
|
|
|
// color: #444;
|
|
|
|
// font-size: .8em;
|
|
|
|
// border-radius: 3px;
|
|
|
|
// line-height: 100%;
|
|
|
|
// transition: width .2s;
|
|
|
|
// padding-left: 5px;
|
|
|
|
// flex-grow: 1;
|
|
|
|
// }
|
2020-01-15 23:18:00 +01:00
|
|
|
|
2020-07-25 21:41:22 +02:00
|
|
|
// .fa-icon {
|
|
|
|
// width: auto;
|
|
|
|
// font-size: 10px;
|
|
|
|
// height: 1.4em; /* or any other relative font sizes */
|
|
|
|
// /* You would have to include the following two lines to make this work in Safari */
|
|
|
|
// // max-width: 100%;
|
|
|
|
// max-height: 100%;
|
|
|
|
// }
|
2020-01-15 23:18:00 +01:00
|
|
|
|
2020-07-25 21:41:22 +02:00
|
|
|
// }
|
|
|
|
// }
|
2020-01-15 23:18:00 +01:00
|
|
|
|
|
|
|
</style>
|