Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@whatl3y
Created May 25, 2019 19:30
Show Gist options
  • Star 6 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save whatl3y/d1a9fb7bab75c2188b226e902c6faff5 to your computer and use it in GitHub Desktop.
Save whatl3y/d1a9fb7bab75c2188b226e902c6faff5 to your computer and use it in GitHub Desktop.
<template lang="pug">
quill-editor(v-model="dynamicValue",:options="editorSettings",@change="textChange")
</template>
<script>
import 'quill/dist/quill.core.css'
import 'quill/dist/quill.snow.css'
import 'quill/dist/quill.bubble.css'
import Quill from 'quill'
import { quillEditor } from 'vue-quill-editor'
import Mention from 'quill-mention'
export default {
props: {
value: { type: String, default: null }
},
watch: {
value(newVal) {
this.dynamicValue = newVal
}
},
data() {
return {
dynamicValue: this.value,
allMentionUsers: this.$store.state.users.map(u => ({ id: u.id, value: u.name })),
editorSettings: {
modules: {
mention: {
allowedChars: /^[A-Za-z\d\s@_]*$/,
mentionDenotationChars: ["@"],
source: (searchTerm, renderList) => {
if (!(this.allMentionUsers && this.allMentionUsers.length > 0))
return
if (searchTerm.length === 0)
return renderList(this.allMentionUsers, searchTerm)
const matchingValues = this.allMentionUsers.filter(user => {
return (
user.id.toLowerCase().includes(searchTerm.toLowerCase()) ||
user.value.toLowerCase().includes(searchTerm.toLowerCase())
)
})
renderList(matchingValues, searchTerm)
},
onSelect: (item, insertItem) => {
this.$emit("mentionReplaced", item)
insertItem(item)
}
}
}
}
}
},
methods: {
textChange() {
this.$emit('input', this.dynamicValue)
}
},
components: {
quillEditor
}
}
</script>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment