add some default options for mentions

This commit is contained in:
Philipp Kühn
2018-09-29 13:09:45 +02:00
parent ccb11ca876
commit 33d9972110

View File

@@ -8,6 +8,18 @@ export default class MentionNode extends Node {
return 'mention' return 'mention'
} }
get defaultOptions() {
return {
matcher: {
char: '@',
allowSpaces: false,
startOfLine: false,
},
mentionClass: 'mention',
suggestionClass: 'mention-suggestion',
}
}
get schema() { get schema() {
return { return {
attrs: { attrs: {
@@ -21,7 +33,7 @@ export default class MentionNode extends Node {
toDOM: node => [ toDOM: node => [
'span', 'span',
{ {
class: 'mention', class: this.options.mentionClass,
'data-mention-id': node.attrs.id, 'data-mention-id': node.attrs.id,
}, },
`@${node.attrs.label}`, `@${node.attrs.label}`,
@@ -42,21 +54,17 @@ export default class MentionNode extends Node {
get plugins() { get plugins() {
return [ return [
SuggestionsPlugin({ SuggestionsPlugin({
suggestionClass: 'mention-suggestion',
matcher: {
char: '@',
allowSpaces: false,
startOfLine: false,
},
command: ({ range, attrs, schema }) => { command: ({ range, attrs, schema }) => {
return replaceText(range, schema.nodes.mention, attrs) return replaceText(range, schema.nodes.mention, attrs)
}, },
matcher: this.options.matcher,
items: this.options.items, items: this.options.items,
onEnter: this.options.onEnter, onEnter: this.options.onEnter,
onChange: this.options.onChange, onChange: this.options.onChange,
onExit: this.options.onExit, onExit: this.options.onExit,
onKeyDown: this.options.onKeyDown, onKeyDown: this.options.onKeyDown,
onFilter: this.options.onFilter, onFilter: this.options.onFilter,
suggestionClass: this.options.suggestionClass,
}), }),
] ]
} }