|
|
@ -1,5 +1,6 @@
|
|
|
|
import Completion from '../../services/completion/completion.js'
|
|
|
|
import Completion from '../../services/completion/completion.js'
|
|
|
|
import EmojiPicker from '../emoji_picker/emoji_picker.vue'
|
|
|
|
import EmojiPicker from '../emoji_picker/emoji_picker.vue'
|
|
|
|
|
|
|
|
import Popover from 'src/components/popover/popover.vue'
|
|
|
|
import UnicodeDomainIndicator from '../unicode_domain_indicator/unicode_domain_indicator.vue'
|
|
|
|
import UnicodeDomainIndicator from '../unicode_domain_indicator/unicode_domain_indicator.vue'
|
|
|
|
import { take } from 'lodash'
|
|
|
|
import { take } from 'lodash'
|
|
|
|
import { findOffset } from '../../services/offset_finder/offset_finder.service.js'
|
|
|
|
import { findOffset } from '../../services/offset_finder/offset_finder.service.js'
|
|
|
@ -109,18 +110,20 @@ const EmojiInput = {
|
|
|
|
data () {
|
|
|
|
data () {
|
|
|
|
return {
|
|
|
|
return {
|
|
|
|
input: undefined,
|
|
|
|
input: undefined,
|
|
|
|
|
|
|
|
caretEl: undefined,
|
|
|
|
highlighted: 0,
|
|
|
|
highlighted: 0,
|
|
|
|
caret: 0,
|
|
|
|
caret: 0,
|
|
|
|
focused: false,
|
|
|
|
focused: false,
|
|
|
|
blurTimeout: null,
|
|
|
|
blurTimeout: null,
|
|
|
|
showPicker: false,
|
|
|
|
|
|
|
|
temporarilyHideSuggestions: false,
|
|
|
|
temporarilyHideSuggestions: false,
|
|
|
|
keepOpen: false,
|
|
|
|
|
|
|
|
disableClickOutside: false,
|
|
|
|
disableClickOutside: false,
|
|
|
|
suggestions: []
|
|
|
|
suggestions: [],
|
|
|
|
|
|
|
|
overlayStyle: {},
|
|
|
|
|
|
|
|
pickerShown: false
|
|
|
|
}
|
|
|
|
}
|
|
|
|
},
|
|
|
|
},
|
|
|
|
components: {
|
|
|
|
components: {
|
|
|
|
|
|
|
|
Popover,
|
|
|
|
EmojiPicker,
|
|
|
|
EmojiPicker,
|
|
|
|
UnicodeDomainIndicator
|
|
|
|
UnicodeDomainIndicator
|
|
|
|
},
|
|
|
|
},
|
|
|
@ -128,15 +131,21 @@ const EmojiInput = {
|
|
|
|
padEmoji () {
|
|
|
|
padEmoji () {
|
|
|
|
return this.$store.getters.mergedConfig.padEmoji
|
|
|
|
return this.$store.getters.mergedConfig.padEmoji
|
|
|
|
},
|
|
|
|
},
|
|
|
|
|
|
|
|
preText () {
|
|
|
|
|
|
|
|
return this.modelValue.slice(0, this.caret)
|
|
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
postText () {
|
|
|
|
|
|
|
|
return this.modelValue.slice(this.caret)
|
|
|
|
|
|
|
|
},
|
|
|
|
showSuggestions () {
|
|
|
|
showSuggestions () {
|
|
|
|
return this.focused &&
|
|
|
|
return this.focused &&
|
|
|
|
this.suggestions &&
|
|
|
|
this.suggestions &&
|
|
|
|
this.suggestions.length > 0 &&
|
|
|
|
this.suggestions.length > 0 &&
|
|
|
|
!this.showPicker &&
|
|
|
|
!this.pickerShown &&
|
|
|
|
!this.temporarilyHideSuggestions
|
|
|
|
!this.temporarilyHideSuggestions
|
|
|
|
},
|
|
|
|
},
|
|
|
|
textAtCaret () {
|
|
|
|
textAtCaret () {
|
|
|
|
return (this.wordAtCaret || {}).word || ''
|
|
|
|
return this.wordAtCaret?.word
|
|
|
|
},
|
|
|
|
},
|
|
|
|
wordAtCaret () {
|
|
|
|
wordAtCaret () {
|
|
|
|
if (this.modelValue && this.caret) {
|
|
|
|
if (this.modelValue && this.caret) {
|
|
|
@ -188,13 +197,35 @@ const EmojiInput = {
|
|
|
|
|
|
|
|
|
|
|
|
return emoji.displayText
|
|
|
|
return emoji.displayText
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
onInputScroll () {
|
|
|
|
|
|
|
|
this.$refs.hiddenOverlay.scrollTo({
|
|
|
|
|
|
|
|
top: this.input.scrollTop,
|
|
|
|
|
|
|
|
left: this.input.scrollLeft
|
|
|
|
|
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|
|
|
|
},
|
|
|
|
},
|
|
|
|
mounted () {
|
|
|
|
mounted () {
|
|
|
|
const { root } = this.$refs
|
|
|
|
const { root, hiddenOverlayCaret, suggestorPopover } = this.$refs
|
|
|
|
const input = root.querySelector('.emoji-input > input') || root.querySelector('.emoji-input > textarea')
|
|
|
|
const input = root.querySelector('.emoji-input > input') || root.querySelector('.emoji-input > textarea')
|
|
|
|
if (!input) return
|
|
|
|
if (!input) return
|
|
|
|
this.input = input
|
|
|
|
this.input = input
|
|
|
|
|
|
|
|
this.caretEl = hiddenOverlayCaret
|
|
|
|
|
|
|
|
if (suggestorPopover.setAnchorEl) {
|
|
|
|
|
|
|
|
suggestorPopover.setAnchorEl(this.caretEl) // unit test compat
|
|
|
|
|
|
|
|
this.$refs.picker.setAnchorEl(this.caretEl)
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
console.warn('setAnchorEl not found, are we in a unit test?')
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
const style = getComputedStyle(this.input)
|
|
|
|
|
|
|
|
this.overlayStyle.padding = style.padding
|
|
|
|
|
|
|
|
this.overlayStyle.border = style.border
|
|
|
|
|
|
|
|
this.overlayStyle.margin = style.margin
|
|
|
|
|
|
|
|
this.overlayStyle.lineHeight = style.lineHeight
|
|
|
|
|
|
|
|
this.overlayStyle.fontFamily = style.fontFamily
|
|
|
|
|
|
|
|
this.overlayStyle.fontSize = style.fontSize
|
|
|
|
|
|
|
|
this.overlayStyle.wordWrap = style.wordWrap
|
|
|
|
|
|
|
|
this.overlayStyle.whiteSpace = style.whiteSpace
|
|
|
|
this.resize()
|
|
|
|
this.resize()
|
|
|
|
input.addEventListener('blur', this.onBlur)
|
|
|
|
input.addEventListener('blur', this.onBlur)
|
|
|
|
input.addEventListener('focus', this.onFocus)
|
|
|
|
input.addEventListener('focus', this.onFocus)
|
|
|
@ -204,6 +235,7 @@ const EmojiInput = {
|
|
|
|
input.addEventListener('click', this.onClickInput)
|
|
|
|
input.addEventListener('click', this.onClickInput)
|
|
|
|
input.addEventListener('transitionend', this.onTransition)
|
|
|
|
input.addEventListener('transitionend', this.onTransition)
|
|
|
|
input.addEventListener('input', this.onInput)
|
|
|
|
input.addEventListener('input', this.onInput)
|
|
|
|
|
|
|
|
input.addEventListener('scroll', this.onInputScroll)
|
|
|
|
},
|
|
|
|
},
|
|
|
|
unmounted () {
|
|
|
|
unmounted () {
|
|
|
|
const { input } = this
|
|
|
|
const { input } = this
|
|
|
@ -216,45 +248,43 @@ const EmojiInput = {
|
|
|
|
input.removeEventListener('click', this.onClickInput)
|
|
|
|
input.removeEventListener('click', this.onClickInput)
|
|
|
|
input.removeEventListener('transitionend', this.onTransition)
|
|
|
|
input.removeEventListener('transitionend', this.onTransition)
|
|
|
|
input.removeEventListener('input', this.onInput)
|
|
|
|
input.removeEventListener('input', this.onInput)
|
|
|
|
|
|
|
|
input.removeEventListener('scroll', this.onInputScroll)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
},
|
|
|
|
},
|
|
|
|
watch: {
|
|
|
|
watch: {
|
|
|
|
showSuggestions: function (newValue) {
|
|
|
|
showSuggestions: function (newValue, oldValue) {
|
|
|
|
this.$emit('shown', newValue)
|
|
|
|
this.$emit('shown', newValue)
|
|
|
|
|
|
|
|
if (newValue) {
|
|
|
|
|
|
|
|
this.$refs.suggestorPopover.showPopover()
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
this.$refs.suggestorPopover.hidePopover()
|
|
|
|
|
|
|
|
}
|
|
|
|
},
|
|
|
|
},
|
|
|
|
textAtCaret: async function (newWord) {
|
|
|
|
textAtCaret: async function (newWord) {
|
|
|
|
|
|
|
|
if (newWord === undefined) return
|
|
|
|
const firstchar = newWord.charAt(0)
|
|
|
|
const firstchar = newWord.charAt(0)
|
|
|
|
this.suggestions = []
|
|
|
|
if (newWord === firstchar) {
|
|
|
|
if (newWord === firstchar) return
|
|
|
|
this.suggestions = []
|
|
|
|
|
|
|
|
return
|
|
|
|
|
|
|
|
}
|
|
|
|
const matchedSuggestions = await this.suggest(newWord, this.maybeLocalizedEmojiNamesAndKeywords)
|
|
|
|
const matchedSuggestions = await this.suggest(newWord, this.maybeLocalizedEmojiNamesAndKeywords)
|
|
|
|
// Async: cancel if textAtCaret has changed during wait
|
|
|
|
// Async: cancel if textAtCaret has changed during wait
|
|
|
|
if (this.textAtCaret !== newWord) return
|
|
|
|
if (this.textAtCaret !== newWord || matchedSuggestions.length <= 0) {
|
|
|
|
if (matchedSuggestions.length <= 0) return
|
|
|
|
this.suggestions = []
|
|
|
|
|
|
|
|
return
|
|
|
|
|
|
|
|
}
|
|
|
|
this.suggestions = take(matchedSuggestions, 5)
|
|
|
|
this.suggestions = take(matchedSuggestions, 5)
|
|
|
|
.map(({ imageUrl, ...rest }) => ({
|
|
|
|
.map(({ imageUrl, ...rest }) => ({
|
|
|
|
...rest,
|
|
|
|
...rest,
|
|
|
|
img: imageUrl || ''
|
|
|
|
img: imageUrl || ''
|
|
|
|
}))
|
|
|
|
}))
|
|
|
|
},
|
|
|
|
|
|
|
|
suggestions: {
|
|
|
|
|
|
|
|
handler (newValue) {
|
|
|
|
|
|
|
|
this.$nextTick(this.resize)
|
|
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
deep: true
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
},
|
|
|
|
},
|
|
|
|
methods: {
|
|
|
|
methods: {
|
|
|
|
focusPickerInput () {
|
|
|
|
|
|
|
|
const pickerEl = this.$refs.picker.$el
|
|
|
|
|
|
|
|
if (!pickerEl) return
|
|
|
|
|
|
|
|
const pickerInput = pickerEl.querySelector('input')
|
|
|
|
|
|
|
|
if (pickerInput) pickerInput.focus()
|
|
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
triggerShowPicker () {
|
|
|
|
triggerShowPicker () {
|
|
|
|
this.showPicker = true
|
|
|
|
|
|
|
|
this.$nextTick(() => {
|
|
|
|
this.$nextTick(() => {
|
|
|
|
|
|
|
|
this.$refs.picker.showPicker()
|
|
|
|
this.scrollIntoView()
|
|
|
|
this.scrollIntoView()
|
|
|
|
this.focusPickerInput()
|
|
|
|
|
|
|
|
})
|
|
|
|
})
|
|
|
|
// This temporarily disables "click outside" handler
|
|
|
|
// This temporarily disables "click outside" handler
|
|
|
|
// since external trigger also means click originates
|
|
|
|
// since external trigger also means click originates
|
|
|
@ -266,11 +296,12 @@ const EmojiInput = {
|
|
|
|
},
|
|
|
|
},
|
|
|
|
togglePicker () {
|
|
|
|
togglePicker () {
|
|
|
|
this.input.focus()
|
|
|
|
this.input.focus()
|
|
|
|
this.showPicker = !this.showPicker
|
|
|
|
if (!this.pickerShown) {
|
|
|
|
if (this.showPicker) {
|
|
|
|
|
|
|
|
this.scrollIntoView()
|
|
|
|
this.scrollIntoView()
|
|
|
|
|
|
|
|
this.$refs.picker.showPicker()
|
|
|
|
this.$refs.picker.startEmojiLoad()
|
|
|
|
this.$refs.picker.startEmojiLoad()
|
|
|
|
this.$nextTick(this.focusPickerInput)
|
|
|
|
} else {
|
|
|
|
|
|
|
|
this.$refs.picker.hidePicker()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
},
|
|
|
|
},
|
|
|
|
replace (replacement) {
|
|
|
|
replace (replacement) {
|
|
|
@ -307,7 +338,6 @@ const EmojiInput = {
|
|
|
|
spaceAfter,
|
|
|
|
spaceAfter,
|
|
|
|
after
|
|
|
|
after
|
|
|
|
].join('')
|
|
|
|
].join('')
|
|
|
|
this.keepOpen = keepOpen
|
|
|
|
|
|
|
|
this.$emit('update:modelValue', newValue)
|
|
|
|
this.$emit('update:modelValue', newValue)
|
|
|
|
const position = this.caret + (insertion + spaceAfter + spaceBefore).length
|
|
|
|
const position = this.caret + (insertion + spaceAfter + spaceBefore).length
|
|
|
|
if (!keepOpen) {
|
|
|
|
if (!keepOpen) {
|
|
|
@ -407,8 +437,11 @@ const EmojiInput = {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
})
|
|
|
|
})
|
|
|
|
},
|
|
|
|
},
|
|
|
|
onTransition (e) {
|
|
|
|
onPickerShown () {
|
|
|
|
this.resize()
|
|
|
|
this.pickerShown = true
|
|
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
onPickerClosed () {
|
|
|
|
|
|
|
|
this.pickerShown = false
|
|
|
|
},
|
|
|
|
},
|
|
|
|
onBlur (e) {
|
|
|
|
onBlur (e) {
|
|
|
|
// Clicking on any suggestion removes focus from autocomplete,
|
|
|
|
// Clicking on any suggestion removes focus from autocomplete,
|
|
|
@ -416,7 +449,6 @@ const EmojiInput = {
|
|
|
|
this.blurTimeout = setTimeout(() => {
|
|
|
|
this.blurTimeout = setTimeout(() => {
|
|
|
|
this.focused = false
|
|
|
|
this.focused = false
|
|
|
|
this.setCaret(e)
|
|
|
|
this.setCaret(e)
|
|
|
|
this.resize()
|
|
|
|
|
|
|
|
}, 200)
|
|
|
|
}, 200)
|
|
|
|
},
|
|
|
|
},
|
|
|
|
onClick (e, suggestion) {
|
|
|
|
onClick (e, suggestion) {
|
|
|
@ -428,18 +460,13 @@ const EmojiInput = {
|
|
|
|
this.blurTimeout = null
|
|
|
|
this.blurTimeout = null
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if (!this.keepOpen) {
|
|
|
|
|
|
|
|
this.showPicker = false
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
this.focused = true
|
|
|
|
this.focused = true
|
|
|
|
this.setCaret(e)
|
|
|
|
this.setCaret(e)
|
|
|
|
this.resize()
|
|
|
|
|
|
|
|
this.temporarilyHideSuggestions = false
|
|
|
|
this.temporarilyHideSuggestions = false
|
|
|
|
},
|
|
|
|
},
|
|
|
|
onKeyUp (e) {
|
|
|
|
onKeyUp (e) {
|
|
|
|
const { key } = e
|
|
|
|
const { key } = e
|
|
|
|
this.setCaret(e)
|
|
|
|
this.setCaret(e)
|
|
|
|
this.resize()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Setting hider in keyUp to prevent suggestions from blinking
|
|
|
|
// Setting hider in keyUp to prevent suggestions from blinking
|
|
|
|
// when moving away from suggested spot
|
|
|
|
// when moving away from suggested spot
|
|
|
@ -451,7 +478,6 @@ const EmojiInput = {
|
|
|
|
},
|
|
|
|
},
|
|
|
|
onPaste (e) {
|
|
|
|
onPaste (e) {
|
|
|
|
this.setCaret(e)
|
|
|
|
this.setCaret(e)
|
|
|
|
this.resize()
|
|
|
|
|
|
|
|
},
|
|
|
|
},
|
|
|
|
onKeyDown (e) {
|
|
|
|
onKeyDown (e) {
|
|
|
|
const { ctrlKey, shiftKey, key } = e
|
|
|
|
const { ctrlKey, shiftKey, key } = e
|
|
|
@ -496,58 +522,24 @@ const EmojiInput = {
|
|
|
|
this.input.focus()
|
|
|
|
this.input.focus()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
this.showPicker = false
|
|
|
|
|
|
|
|
this.resize()
|
|
|
|
|
|
|
|
},
|
|
|
|
},
|
|
|
|
onInput (e) {
|
|
|
|
onInput (e) {
|
|
|
|
this.showPicker = false
|
|
|
|
|
|
|
|
this.setCaret(e)
|
|
|
|
this.setCaret(e)
|
|
|
|
this.resize()
|
|
|
|
|
|
|
|
this.$emit('update:modelValue', e.target.value)
|
|
|
|
this.$emit('update:modelValue', e.target.value)
|
|
|
|
},
|
|
|
|
},
|
|
|
|
onClickInput (e) {
|
|
|
|
|
|
|
|
this.showPicker = false
|
|
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
onClickOutside (e) {
|
|
|
|
|
|
|
|
if (this.disableClickOutside) return
|
|
|
|
|
|
|
|
this.showPicker = false
|
|
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
onStickerUploaded (e) {
|
|
|
|
onStickerUploaded (e) {
|
|
|
|
this.showPicker = false
|
|
|
|
|
|
|
|
this.$emit('sticker-uploaded', e)
|
|
|
|
this.$emit('sticker-uploaded', e)
|
|
|
|
},
|
|
|
|
},
|
|
|
|
onStickerUploadFailed (e) {
|
|
|
|
onStickerUploadFailed (e) {
|
|
|
|
this.showPicker = false
|
|
|
|
|
|
|
|
this.$emit('sticker-upload-Failed', e)
|
|
|
|
this.$emit('sticker-upload-Failed', e)
|
|
|
|
},
|
|
|
|
},
|
|
|
|
setCaret ({ target: { selectionStart } }) {
|
|
|
|
setCaret ({ target: { selectionStart } }) {
|
|
|
|
this.caret = selectionStart
|
|
|
|
this.caret = selectionStart
|
|
|
|
|
|
|
|
this.$nextTick(() => {
|
|
|
|
|
|
|
|
this.$refs.suggestorPopover.updateStyles()
|
|
|
|
|
|
|
|
})
|
|
|
|
},
|
|
|
|
},
|
|
|
|
resize () {
|
|
|
|
resize () {
|
|
|
|
const panel = this.$refs.panel
|
|
|
|
|
|
|
|
if (!panel) return
|
|
|
|
|
|
|
|
const picker = this.$refs.picker.$el
|
|
|
|
|
|
|
|
const panelBody = this.$refs['panel-body']
|
|
|
|
|
|
|
|
const { offsetHeight, offsetTop } = this.input
|
|
|
|
|
|
|
|
const offsetBottom = offsetTop + offsetHeight
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
this.setPlacement(panelBody, panel, offsetBottom)
|
|
|
|
|
|
|
|
this.setPlacement(picker, picker, offsetBottom)
|
|
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
setPlacement (container, target, offsetBottom) {
|
|
|
|
|
|
|
|
if (!container || !target) return
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
target.style.top = offsetBottom + 'px'
|
|
|
|
|
|
|
|
target.style.bottom = 'auto'
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (this.placement === 'top' || (this.placement === 'auto' && this.overflowsBottom(container))) {
|
|
|
|
|
|
|
|
target.style.top = 'auto'
|
|
|
|
|
|
|
|
target.style.bottom = this.input.offsetHeight + 'px'
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
overflowsBottom (el) {
|
|
|
|
|
|
|
|
return el.getBoundingClientRect().bottom > window.innerHeight
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|