2022-12-23 22:15:19 +03:00
|
|
|
<script setup lang="ts">
|
2023-02-15 22:15:11 +03:00
|
|
|
import importEmojiLang from 'virtual:emoji-mart-lang-importer'
|
2022-12-23 22:15:19 +03:00
|
|
|
import type { Picker } from 'emoji-mart'
|
|
|
|
|
|
|
|
const emit = defineEmits<{
|
|
|
|
(e: 'select', code: string): void
|
2022-12-27 21:38:57 +03:00
|
|
|
(e: 'selectCustom', image: any): void
|
2022-12-23 22:15:19 +03:00
|
|
|
}>()
|
|
|
|
|
2023-02-15 22:15:11 +03:00
|
|
|
const { locale } = useI18n()
|
|
|
|
|
2022-12-23 22:15:19 +03:00
|
|
|
const el = $ref<HTMLElement>()
|
|
|
|
let picker = $ref<Picker>()
|
2022-12-29 15:26:08 +03:00
|
|
|
const colorMode = useColorMode()
|
2022-12-23 22:15:19 +03:00
|
|
|
|
|
|
|
async function openEmojiPicker() {
|
2022-12-27 15:28:02 +03:00
|
|
|
await updateCustomEmojis()
|
2023-02-15 22:15:11 +03:00
|
|
|
|
2022-12-27 15:28:02 +03:00
|
|
|
if (picker) {
|
|
|
|
picker.update({
|
2022-12-28 04:06:54 +03:00
|
|
|
theme: colorMode.value,
|
2022-12-27 15:28:02 +03:00
|
|
|
custom: customEmojisData.value,
|
|
|
|
})
|
|
|
|
}
|
|
|
|
else {
|
2023-02-15 22:15:11 +03:00
|
|
|
const [Picker, dataPromise, i18n] = await Promise.all([
|
|
|
|
import('emoji-mart').then(({ Picker }) => Picker),
|
|
|
|
import('@emoji-mart/data/sets/14/twitter.json').then((r: any) => r.default).catch(() => {}),
|
|
|
|
importEmojiLang(locale.value.split('-')[0]),
|
|
|
|
])
|
|
|
|
|
2022-12-23 22:15:19 +03:00
|
|
|
picker = new Picker({
|
2023-02-15 22:15:11 +03:00
|
|
|
data: () => dataPromise,
|
2022-12-27 21:38:57 +03:00
|
|
|
onEmojiSelect({ native, src, alt, name }: any) {
|
|
|
|
native
|
|
|
|
? emit('select', native)
|
|
|
|
: emit('selectCustom', { src, alt, 'data-emoji-id': name })
|
2022-12-23 22:15:19 +03:00
|
|
|
},
|
2023-01-20 22:26:18 +03:00
|
|
|
set: 'twitter',
|
2022-12-28 04:06:54 +03:00
|
|
|
theme: colorMode.value,
|
2022-12-24 01:56:16 +03:00
|
|
|
custom: customEmojisData.value,
|
2023-02-15 22:15:11 +03:00
|
|
|
i18n,
|
2022-12-23 22:15:19 +03:00
|
|
|
})
|
|
|
|
}
|
2022-12-25 19:58:00 +03:00
|
|
|
await nextTick()
|
|
|
|
// TODO: custom picker
|
|
|
|
el?.appendChild(picker as any as HTMLElement)
|
|
|
|
}
|
|
|
|
|
2023-03-30 22:01:24 +03:00
|
|
|
function hideEmojiPicker() {
|
2022-12-25 19:58:00 +03:00
|
|
|
if (picker)
|
|
|
|
el?.removeChild(picker as any as HTMLElement)
|
2022-12-23 22:15:19 +03:00
|
|
|
}
|
|
|
|
</script>
|
|
|
|
|
|
|
|
<template>
|
2023-01-13 19:22:36 +03:00
|
|
|
<CommonTooltip :content="$t('tooltip.add_emojis')">
|
2023-01-04 13:41:19 +03:00
|
|
|
<VDropdown
|
|
|
|
auto-boundary-max-size
|
|
|
|
@apply-show="openEmojiPicker()"
|
|
|
|
@apply-hide="hideEmojiPicker()"
|
|
|
|
>
|
|
|
|
<slot />
|
|
|
|
|
|
|
|
<template #popper>
|
|
|
|
<div ref="el" min-w-10 min-h-10 />
|
|
|
|
</template>
|
|
|
|
</VDropdown>
|
|
|
|
</CommonTooltip>
|
2022-12-23 22:15:19 +03:00
|
|
|
</template>
|