Customize Mention node based on Superclass

This commit is contained in:
Robert Schäfer 2019-04-15 22:10:55 +02:00
parent b5f60369a5
commit bf18754b4d
3 changed files with 31 additions and 13 deletions

View File

@ -71,7 +71,8 @@ export default {
id: null,
loading: false,
disabled: false,
slug: null
slug: null,
users: []
}
},
watch: {

View File

@ -185,8 +185,8 @@ import {
Underline,
Link,
History,
Mention
} from 'tiptap-extensions'
import Mention from './nodes/Mention.js'
let throttleInputEvent
@ -358,7 +358,8 @@ export default {
this.insertMention({
range: this.suggestionRange,
attrs: {
id: user.id,
// TODO: use router here
url: `/profile/${user.id}`,
label: user.name
}
})
@ -533,17 +534,8 @@ li > p {
}
.editor {
.mention {
background: rgba($color-neutral-0, 0.1);
color: rgba($color-neutral-0, 0.6);
font-size: 0.8rem;
font-weight: bold;
border-radius: 5px;
padding: 0.2rem 0.5rem;
white-space: nowrap;
}
.mention-suggestion {
color: rgba($color-neutral-0, 0.6);
color: $color-primary
}
&__floating-menu {
position: absolute;

View File

@ -0,0 +1,25 @@
import { Node } from 'tiptap'
import { replaceText } from 'tiptap-commands'
import { Mention as TipTapMention } from 'tiptap-extensions'
export default class Mention extends TipTapMention {
get schema() {
const schema = super.schema
schema.attrs = {
url: {},
label: {},
},
schema.toDOM = node => [
'a',
{
class: this.options.mentionClass,
href: node.attrs.url,
},
`${this.options.matcher.char}${node.attrs.label}`
]
schema.parseDOM = [
// this is not implemented
]
return schema
}
}