2020-01-15 23:18:00 +01:00
|
|
|
<template lang='pug'>
|
2021-09-27 11:11:25 +02:00
|
|
|
.editor(:class='focused')
|
2020-11-17 00:32:14 +01:00
|
|
|
.label {{label}}
|
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 }')
|
2020-11-17 00:32:14 +01:00
|
|
|
v-btn-toggle(dense)
|
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")
|
2022-02-08 14:45:19 +01:00
|
|
|
v-icon(v-text='mdiFormatBold')
|
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")
|
2022-02-08 14:45:19 +01:00
|
|
|
v-icon(v-text='mdiFormatUnderline')
|
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.strike() }"
|
|
|
|
@click="commands.strike")
|
2022-02-08 14:45:19 +01:00
|
|
|
v-icon(v-text='mdiFormatStrikethroughVariant')
|
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.italic() }"
|
|
|
|
@click="commands.italic")
|
2022-02-08 14:45:19 +01:00
|
|
|
v-icon(v-text='mdiFormatItalic')
|
2020-07-28 12:24:39 +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.heading({level: 1}) }"
|
|
|
|
@click="commands.heading({level: 1})")
|
2022-02-08 14:45:19 +01:00
|
|
|
v-icon(v-text='mdiFormatHeader1')
|
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.heading({level: 2}) }"
|
|
|
|
@click="commands.heading({level: 2})")
|
2022-02-08 14:45:19 +01:00
|
|
|
v-icon(v-text='mdiFormatHeader2')
|
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.heading({level: 3}) }"
|
|
|
|
@click="commands.heading({level: 3})")
|
2022-02-08 14:45:19 +01:00
|
|
|
v-icon(v-text='mdiFormatHeader3')
|
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.code() }"
|
|
|
|
@click="commands.code")
|
2022-02-08 14:45:19 +01:00
|
|
|
v-icon(v-text='mdiCodeTags')
|
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.blockquote() }"
|
|
|
|
@click="commands.blockquote")
|
2022-02-08 14:45:19 +01:00
|
|
|
v-icon(v-text='mdiFormatQuoteOpen')
|
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.bullet_list() }"
|
|
|
|
@click="commands.bullet_list")
|
2022-02-08 14:45:19 +01:00
|
|
|
v-icon(v-text='mdiFormatListBulleted')
|
2020-08-16 14:07:25 +02:00
|
|
|
|
2020-10-09 00:38:56 +02:00
|
|
|
v-btn(icon text tabindex='-1' :class='{ primary: isActive.link() }'
|
2021-03-08 14:39:44 +01:00
|
|
|
@click='commands.link({href: getMarkAttrs("link") && getMarkAttrs("link").href ? "" : "https://"}); $refs.link.focus();')
|
2022-02-08 14:45:19 +01:00
|
|
|
v-icon(v-text='mdiLink')
|
2022-06-23 01:02:09 +02:00
|
|
|
v-text-field.pt-0.ml-1(v-show='isActive.link()' ref='link' @focus='focus' @blur='e => { blur(); commands.link({ href: e.target.value}) }' hide-details
|
2021-03-08 14:39:44 +01:00
|
|
|
:value='isActive.link() && getMarkAttrs("link") && getMarkAttrs("link").href || ""'
|
|
|
|
@keypress.enter='commands.link({ href: $event.target.value}); editor.focus()')
|
2020-08-16 14:07:25 +02:00
|
|
|
|
2022-02-26 21:28:16 +01:00
|
|
|
editor-content.content(:editor='editor' spellcheck='false' :style="{ 'max-height': maxHeight }" :aria-label='label' :label='label')
|
2020-01-15 23:18:00 +01:00
|
|
|
</template>
|
|
|
|
<script>
|
2021-03-16 19:54:26 +01:00
|
|
|
import debounce from 'lodash/debounce'
|
2022-02-08 14:45:19 +01:00
|
|
|
import { mdiLink, mdiFormatListBulleted, mdiFormatQuoteOpen, mdiCodeTags,
|
|
|
|
mdiFormatHeader1, mdiFormatHeader2, mdiFormatHeader3, mdiFormatItalic,
|
|
|
|
mdiFormatStrikethroughVariant, mdiFormatBold, mdiFormatUnderline } from '@mdi/js'
|
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: {
|
2020-10-14 21:13:20 +02:00
|
|
|
label: { type: String, default: 'Editor' },
|
2020-01-15 23:18:00 +01:00
|
|
|
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 {
|
2022-02-08 14:45:19 +01:00
|
|
|
mdiLink, mdiFormatListBulleted, mdiFormatQuoteOpen, mdiCodeTags,
|
|
|
|
mdiFormatHeader1, mdiFormatHeader2, mdiFormatHeader3, mdiFormatItalic,
|
|
|
|
mdiFormatStrikethroughVariant, mdiFormatBold, mdiFormatUnderline,
|
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,
|
2021-03-08 14:39:44 +01:00
|
|
|
blurring: false,
|
2020-11-17 00:32:14 +01:00
|
|
|
update: false,
|
|
|
|
focused: ''
|
2020-02-16 21:04:18 +01:00
|
|
|
}
|
|
|
|
},
|
|
|
|
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({
|
2021-03-08 14:39:44 +01:00
|
|
|
onFocus: () => this.focus(),
|
|
|
|
onBlur: () => this.blur(),
|
2021-03-16 19:54:26 +01:00
|
|
|
onUpdate: debounce(({ getHTML }) => {
|
2020-02-16 21:04:18 +01:00
|
|
|
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(),
|
2021-03-15 22:27:07 +01:00
|
|
|
new Link({ openOnClick: false, target: '_blank' }),
|
2020-01-15 23:18:00 +01:00
|
|
|
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,
|
2020-11-17 00:32:14 +01:00
|
|
|
showOnlyCurrent: true
|
2020-10-09 00:38:56 +02:00
|
|
|
})
|
2020-01-15 23:18:00 +01:00
|
|
|
]
|
|
|
|
})
|
|
|
|
},
|
|
|
|
beforeDestroy () {
|
|
|
|
if (this.editor) { this.editor.destroy() }
|
2021-03-08 14:39:44 +01:00
|
|
|
},
|
|
|
|
methods: {
|
|
|
|
blur () {
|
|
|
|
this.blurring = true
|
|
|
|
window.setTimeout(() => {
|
|
|
|
if (this.blurring) {
|
|
|
|
this.focused = ''
|
|
|
|
this.blurring = false
|
|
|
|
}
|
|
|
|
}, 200)
|
|
|
|
},
|
|
|
|
focus () {
|
|
|
|
this.focused = 'editor--focused'
|
|
|
|
this.$nextTick(() => {
|
|
|
|
this.blurring = false
|
|
|
|
})
|
|
|
|
}
|
2020-01-15 23:18:00 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
</script>
|
2022-05-03 15:23:55 +02:00
|
|
|
<style lang='scss'>
|
2020-11-17 00:32:14 +01:00
|
|
|
|
2020-07-28 12:24:39 +02:00
|
|
|
.editor {
|
2020-11-17 00:32:14 +01:00
|
|
|
margin-top: 4px;
|
|
|
|
padding-top: 12px;
|
|
|
|
padding-bottom: 22px;
|
|
|
|
overflow-y: auto;
|
|
|
|
scrollbar-width: thin;
|
|
|
|
scrollbar-color: #FF4500 transparent;
|
|
|
|
scroll-behavior: smooth;
|
|
|
|
font-family: sans-serif;
|
|
|
|
font-size: 1.1em;
|
|
|
|
|
|
|
|
.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-10-14 21:13:20 +02:00
|
|
|
.label {
|
|
|
|
left: 0px;
|
2020-11-17 00:32:14 +01:00
|
|
|
position: relative;
|
|
|
|
transform-origin: top left;
|
|
|
|
transition: transform .3s, scale .3s, color .3s;
|
|
|
|
transform: translateY(20px);
|
2020-10-14 21:13:20 +02:00
|
|
|
}
|
2020-11-17 00:32:14 +01:00
|
|
|
|
|
|
|
&.editor--focused {
|
|
|
|
.label {
|
|
|
|
color: #FF4500;
|
|
|
|
transform: translateY(0px) scale(0.75);
|
|
|
|
}
|
|
|
|
|
|
|
|
.menubar {
|
2021-04-27 11:10:18 +02:00
|
|
|
visibility: visible;
|
2020-11-17 00:32:14 +01:00
|
|
|
opacity: 1 !important;
|
|
|
|
}
|
|
|
|
|
|
|
|
.ProseMirror::after {
|
|
|
|
width : 100% !important;
|
|
|
|
transform: scaleX(1) !important;
|
|
|
|
}
|
2020-08-16 14:07:25 +02:00
|
|
|
}
|
2020-11-17 00:32:14 +01:00
|
|
|
|
2020-08-16 14:07:25 +02:00
|
|
|
.menubar {
|
2020-11-17 00:32:14 +01:00
|
|
|
transition: opacity .5s;
|
|
|
|
opacity: 0;
|
2021-04-27 11:10:18 +02:00
|
|
|
visibility: hidden;
|
2020-08-16 14:07:25 +02:00
|
|
|
// position: absolute;
|
|
|
|
}
|
|
|
|
|
2020-11-17 00:32:14 +01:00
|
|
|
.focused .ProseMirror::after {
|
|
|
|
width: 100%;
|
|
|
|
}
|
2020-08-16 14:07:25 +02:00
|
|
|
.ProseMirror {
|
|
|
|
padding: 15px;
|
|
|
|
outline: 0;
|
2020-11-17 00:32:14 +01:00
|
|
|
&::before {
|
|
|
|
bottom: 0px;
|
|
|
|
content: "";
|
|
|
|
left: 0;
|
|
|
|
position: absolute;
|
|
|
|
transition: 0.3s cubic-bezier(0.25, 0.8, 0.5, 1);
|
|
|
|
width: 100%;
|
|
|
|
border-width: thin 0 0 0;
|
|
|
|
border-style: solid;
|
|
|
|
height: 0px;
|
|
|
|
border-color: rgba(255, 255, 255, 0.7);
|
|
|
|
}
|
|
|
|
|
|
|
|
&::after {
|
|
|
|
bottom: 0px;
|
|
|
|
content: "";
|
|
|
|
left: 0;
|
|
|
|
position: absolute;
|
|
|
|
height: 0px;
|
|
|
|
transition: 0.3s cubic-bezier(0.25, 0.8, 0.5, 1);
|
|
|
|
width: 100%;
|
|
|
|
border-width: 2px 0 0 0;
|
|
|
|
border-style: solid;
|
|
|
|
border-color: #FF4500;
|
|
|
|
transform: scaleX(0);
|
|
|
|
}
|
2020-08-16 14:07:25 +02:00
|
|
|
}
|
2020-07-28 12:24:39 +02:00
|
|
|
}
|
2020-01-15 23:18:00 +01:00
|
|
|
|
|
|
|
</style>
|