2022-12-23 20:15:19 +01:00
|
|
|
<script setup lang="ts">
|
|
|
|
import type { Picker } from 'emoji-mart'
|
|
|
|
|
|
|
|
const emit = defineEmits<{
|
|
|
|
(e: 'select', code: string): void
|
2022-12-27 19:38:57 +01:00
|
|
|
(e: 'selectCustom', image: any): void
|
2022-12-23 20:15:19 +01:00
|
|
|
}>()
|
|
|
|
|
|
|
|
const el = $ref<HTMLElement>()
|
|
|
|
let picker = $ref<Picker>()
|
2022-12-29 13:26:08 +01:00
|
|
|
const colorMode = useColorMode()
|
2022-12-23 20:15:19 +01:00
|
|
|
|
|
|
|
async function openEmojiPicker() {
|
2022-12-27 13:28:02 +01:00
|
|
|
await updateCustomEmojis()
|
|
|
|
if (picker) {
|
|
|
|
picker.update({
|
2022-12-28 02:06:54 +01:00
|
|
|
theme: colorMode.value,
|
2022-12-27 13:28:02 +01:00
|
|
|
custom: customEmojisData.value,
|
|
|
|
})
|
|
|
|
}
|
|
|
|
else {
|
2023-01-20 20:26:18 +01:00
|
|
|
const promise = import('@emoji-mart/data/sets/14/twitter.json').then(r => r.default)
|
2022-12-23 20:15:19 +01:00
|
|
|
const { Picker } = await import('emoji-mart')
|
|
|
|
picker = new Picker({
|
2022-12-23 23:56:16 +01:00
|
|
|
data: () => promise,
|
2022-12-27 19:38:57 +01:00
|
|
|
onEmojiSelect({ native, src, alt, name }: any) {
|
|
|
|
native
|
|
|
|
? emit('select', native)
|
|
|
|
: emit('selectCustom', { src, alt, 'data-emoji-id': name })
|
2022-12-23 20:15:19 +01:00
|
|
|
},
|
2023-01-20 20:26:18 +01:00
|
|
|
set: 'twitter',
|
2022-12-28 02:06:54 +01:00
|
|
|
theme: colorMode.value,
|
2022-12-23 23:56:16 +01:00
|
|
|
custom: customEmojisData.value,
|
2022-12-23 20:15:19 +01:00
|
|
|
})
|
|
|
|
}
|
2022-12-25 17:58:00 +01:00
|
|
|
await nextTick()
|
|
|
|
// TODO: custom picker
|
|
|
|
el?.appendChild(picker as any as HTMLElement)
|
|
|
|
}
|
|
|
|
|
2022-12-27 13:28:02 +01:00
|
|
|
const hideEmojiPicker = () => {
|
2022-12-25 17:58:00 +01:00
|
|
|
if (picker)
|
|
|
|
el?.removeChild(picker as any as HTMLElement)
|
2022-12-23 20:15:19 +01:00
|
|
|
}
|
|
|
|
</script>
|
|
|
|
|
|
|
|
<template>
|
2023-01-13 17:22:36 +01:00
|
|
|
<CommonTooltip :content="$t('tooltip.add_emojis')">
|
2023-01-04 11:41:19 +01: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 20:15:19 +01:00
|
|
|
</template>
|