2022-12-23 19:15:19 +00:00
|
|
|
<script setup lang="ts">
|
|
|
|
import type { Picker } from 'emoji-mart'
|
2022-12-23 22:56:16 +00:00
|
|
|
import { updateCustomEmojis } from '~/composables/emojis'
|
2022-12-23 19:15:19 +00:00
|
|
|
|
|
|
|
const emit = defineEmits<{
|
|
|
|
(e: 'select', code: string): void
|
|
|
|
}>()
|
|
|
|
|
|
|
|
const el = $ref<HTMLElement>()
|
|
|
|
let picker = $ref<Picker>()
|
|
|
|
|
|
|
|
async function openEmojiPicker() {
|
|
|
|
if (!picker) {
|
2022-12-23 22:56:16 +00:00
|
|
|
updateCustomEmojis()
|
|
|
|
const promise = import('@emoji-mart/data').then(r => r.default)
|
2022-12-23 19:15:19 +00:00
|
|
|
const { Picker } = await import('emoji-mart')
|
|
|
|
picker = new Picker({
|
2022-12-23 22:56:16 +00:00
|
|
|
data: () => promise,
|
2022-12-23 19:15:19 +00:00
|
|
|
onEmojiSelect(e: any) {
|
2022-12-23 22:56:16 +00:00
|
|
|
emit('select', e.native || e.shortcodes)
|
2022-12-23 19:15:19 +00:00
|
|
|
},
|
|
|
|
theme: isDark.value ? 'dark' : 'light',
|
2022-12-23 22:56:16 +00:00
|
|
|
custom: customEmojisData.value,
|
2022-12-23 19:15:19 +00:00
|
|
|
})
|
|
|
|
// TODO: custom picker
|
|
|
|
el?.appendChild(picker as any as HTMLElement)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-12-23 22:56:16 +00:00
|
|
|
watch(isDark, () => {
|
|
|
|
picker?.update({
|
2022-12-23 19:15:19 +00:00
|
|
|
theme: isDark.value ? 'dark' : 'light',
|
|
|
|
})
|
|
|
|
})
|
2022-12-23 22:56:16 +00:00
|
|
|
|
|
|
|
watch(customEmojisData, () => {
|
|
|
|
picker?.update({
|
|
|
|
custom: customEmojisData.value,
|
|
|
|
})
|
|
|
|
})
|
2022-12-23 19:15:19 +00:00
|
|
|
</script>
|
|
|
|
|
|
|
|
<template>
|
|
|
|
<VDropdown
|
|
|
|
@apply-show="openEmojiPicker()"
|
|
|
|
>
|
|
|
|
<button btn-action-icon :title="$t('tooltip.emoji')">
|
|
|
|
<div i-ri:emotion-line />
|
|
|
|
</button>
|
|
|
|
<template #popper>
|
2022-12-23 22:56:16 +00:00
|
|
|
<div ref="el" min-w-10 min-h-10 />
|
2022-12-23 19:15:19 +00:00
|
|
|
</template>
|
|
|
|
</VDropdown>
|
|
|
|
</template>
|