2019-08-14 09:48:44 +00:00
|
|
|
<template>
|
|
|
|
<div role="dialog" class="emoji-dialog">
|
|
|
|
<header class="emoji-dialog-header" role="menu">
|
|
|
|
<ul>
|
|
|
|
<li
|
|
|
|
v-for="category in categoryList"
|
2020-04-29 08:24:56 +00:00
|
|
|
:key="category.key"
|
|
|
|
:class="{ active: selectedKey === category.key }"
|
2019-08-14 09:48:44 +00:00
|
|
|
@click="changeCategory(category)"
|
|
|
|
>
|
|
|
|
<div
|
|
|
|
role="menuitem"
|
|
|
|
class="emojione"
|
2020-04-29 08:24:56 +00:00
|
|
|
@click="changeCategory(category)"
|
|
|
|
v-html="` ${getEmojiUnicode(`:${category.emoji}:`)}`"
|
|
|
|
></div>
|
2019-08-14 09:48:44 +00:00
|
|
|
</li>
|
|
|
|
</ul>
|
|
|
|
</header>
|
|
|
|
<div class="emoji-row">
|
2020-04-29 08:24:56 +00:00
|
|
|
<h5 class="emoji-category-title">
|
|
|
|
{{ selectedKey }}
|
|
|
|
</h5>
|
2019-08-14 09:48:44 +00:00
|
|
|
<div
|
2020-04-29 08:24:56 +00:00
|
|
|
v-for="emoji in filteredSelectedEmojis"
|
|
|
|
:key="emoji.shortname"
|
2019-08-14 09:48:44 +00:00
|
|
|
role="menuitem"
|
2020-04-29 08:24:56 +00:00
|
|
|
class="emojione"
|
2019-08-14 09:48:44 +00:00
|
|
|
track-by="$index"
|
2020-04-29 08:24:56 +00:00
|
|
|
@click="onClick(emoji)"
|
|
|
|
v-html="getEmojiUnicode(emoji.shortname)"
|
2019-08-14 09:48:44 +00:00
|
|
|
/>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</template>
|
|
|
|
|
|
|
|
<script>
|
2020-04-29 08:24:56 +00:00
|
|
|
/* eslint-disable no-restricted-syntax */
|
2019-08-14 09:48:44 +00:00
|
|
|
import strategy from 'emojione/emoji.json';
|
|
|
|
import categoryList from './categories';
|
|
|
|
import { getEmojiUnicode } from './utils';
|
|
|
|
|
|
|
|
export default {
|
|
|
|
props: ['onClick'],
|
|
|
|
data() {
|
|
|
|
return {
|
|
|
|
selectedKey: 'people',
|
|
|
|
categoryList,
|
2020-04-29 08:24:56 +00:00
|
|
|
selectedEmojis: {},
|
2019-08-14 09:48:44 +00:00
|
|
|
};
|
|
|
|
},
|
|
|
|
computed: {
|
|
|
|
emojis() {
|
|
|
|
const emojiArr = {};
|
|
|
|
|
|
|
|
// categorise and nest emoji
|
|
|
|
// sort ensures that modifiers appear unmodified keys
|
|
|
|
const keys = Object.keys(strategy);
|
|
|
|
for (const key of keys) {
|
|
|
|
const value = strategy[key];
|
|
|
|
|
|
|
|
// skip unknown categoryList
|
|
|
|
if (value.category !== 'modifier') {
|
|
|
|
if (!emojiArr[value.category]) emojiArr[value.category] = {};
|
|
|
|
const match = key.match(/(.*?)_tone(.*?)$/);
|
|
|
|
|
|
|
|
if (match) {
|
|
|
|
// this check is to stop the plugin from failing in the case that the
|
|
|
|
// emoji strategy miscategorizes tones - which was the case here:
|
|
|
|
const unmodifiedEmojiExists = !!emojiArr[value.category][match[1]];
|
|
|
|
if (unmodifiedEmojiExists) {
|
|
|
|
emojiArr[value.category][match[1]][match[2]] = value;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
emojiArr[value.category][key] = [value];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return emojiArr;
|
|
|
|
},
|
2020-04-29 08:24:56 +00:00
|
|
|
filteredSelectedEmojis() {
|
|
|
|
const emojis = this.selectedEmojis;
|
|
|
|
const filteredEmojis = Object.keys(emojis)
|
|
|
|
.map(key => {
|
|
|
|
const emoji = emojis[key];
|
|
|
|
const [lastEmoji] = emoji.slice(-1);
|
|
|
|
return { ...lastEmoji, key };
|
|
|
|
})
|
|
|
|
.filter(emoji => {
|
|
|
|
const { shortname } = emoji;
|
|
|
|
if (shortname) {
|
|
|
|
return this.filterEmoji(shortname);
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
});
|
|
|
|
return filteredEmojis;
|
|
|
|
},
|
2019-08-14 09:48:44 +00:00
|
|
|
},
|
|
|
|
// On mount render initial emoji
|
|
|
|
mounted() {
|
|
|
|
this.getInitialEmoji();
|
|
|
|
},
|
|
|
|
methods: {
|
|
|
|
// Change category and associated emojis
|
|
|
|
changeCategory(category) {
|
|
|
|
this.selectedKey = category.key;
|
|
|
|
this.selectedEmojis = this.emojis[this.selectedKey];
|
|
|
|
},
|
|
|
|
|
|
|
|
// Filter non-existant or irregular unicode characters
|
|
|
|
filterEmoji(shortName) {
|
|
|
|
return shortName !== ':relaxed:' && shortName !== ':frowning2:';
|
|
|
|
},
|
|
|
|
// Get inital emojis
|
|
|
|
getInitialEmoji() {
|
|
|
|
this.selectedEmojis = this.emojis.people;
|
|
|
|
},
|
|
|
|
getEmojiUnicode,
|
|
|
|
},
|
|
|
|
};
|
|
|
|
</script>
|
2020-04-29 08:24:56 +00:00
|
|
|
<style lang="scss" scoped>
|
|
|
|
@import '~dashboard/assets/scss/widgets/emojiinput';
|
|
|
|
</style>
|