2022-12-23 19:15:19 +00:00
|
|
|
<script setup lang="ts">
|
|
|
|
import type { Picker } from 'emoji-mart'
|
2024-09-30 09:11:56 +01:00
|
|
|
import importEmojiLang from 'virtual:emoji-mart-lang-importer'
|
2022-12-23 19:15:19 +00:00
|
|
|
|
|
|
|
const emit = defineEmits<{
|
|
|
|
(e: 'select', code: string): void
|
2022-12-27 18:38:57 +00:00
|
|
|
(e: 'selectCustom', image: any): void
|
2022-12-23 19:15:19 +00:00
|
|
|
}>()
|
|
|
|
|
2023-02-15 19:15:11 +00:00
|
|
|
const { locale } = useI18n()
|
|
|
|
|
2024-02-21 15:20:08 +00:00
|
|
|
const el = ref<HTMLElement>()
|
|
|
|
const picker = ref<Picker>()
|
2022-12-29 12:26:08 +00:00
|
|
|
const colorMode = useColorMode()
|
2022-12-23 19:15:19 +00:00
|
|
|
|
|
|
|
async function openEmojiPicker() {
|
2022-12-27 12:28:02 +00:00
|
|
|
await updateCustomEmojis()
|
2023-02-15 19:15:11 +00:00
|
|
|
|
2024-02-21 15:20:08 +00:00
|
|
|
if (picker.value) {
|
|
|
|
picker.value.update({
|
|
|
|
theme: colorMode,
|
2022-12-27 12:28:02 +00:00
|
|
|
custom: customEmojisData.value,
|
|
|
|
})
|
|
|
|
}
|
|
|
|
else {
|
2023-02-15 19:15:11 +00: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]),
|
|
|
|
])
|
|
|
|
|
2024-02-21 15:20:08 +00:00
|
|
|
picker.value = new Picker({
|
2023-02-15 19:15:11 +00:00
|
|
|
data: () => dataPromise,
|
2022-12-27 18:38:57 +00:00
|
|
|
onEmojiSelect({ native, src, alt, name }: any) {
|
2024-08-16 15:52:08 +01:00
|
|
|
if (native)
|
|
|
|
emit('select', native)
|
|
|
|
else
|
|
|
|
emit('selectCustom', { src, alt, 'data-emoji-id': name })
|
2022-12-23 19:15:19 +00:00
|
|
|
},
|
2023-01-20 19:26:18 +00:00
|
|
|
set: 'twitter',
|
2024-02-21 15:20:08 +00:00
|
|
|
theme: colorMode,
|
2022-12-23 22:56:16 +00:00
|
|
|
custom: customEmojisData.value,
|
2023-02-15 19:15:11 +00:00
|
|
|
i18n,
|
2022-12-23 19:15:19 +00:00
|
|
|
})
|
|
|
|
}
|
2022-12-25 16:58:00 +00:00
|
|
|
await nextTick()
|
|
|
|
// TODO: custom picker
|
2024-02-21 15:20:08 +00:00
|
|
|
el.value?.appendChild(picker.value as any as HTMLElement)
|
2022-12-25 16:58:00 +00:00
|
|
|
}
|
|
|
|
|
2023-03-30 20:01:24 +01:00
|
|
|
function hideEmojiPicker() {
|
2024-02-21 15:20:08 +00:00
|
|
|
if (picker.value)
|
|
|
|
el.value?.removeChild(picker.value as any as HTMLElement)
|
2022-12-23 19:15:19 +00:00
|
|
|
}
|
|
|
|
</script>
|
|
|
|
|
|
|
|
<template>
|
2023-01-13 16:22:36 +00:00
|
|
|
<CommonTooltip :content="$t('tooltip.add_emojis')">
|
2023-01-04 10:41:19 +00: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 19:15:19 +00:00
|
|
|
</template>
|