2022-12-24 04:15:19 +09:00
|
|
|
<script setup lang="ts">
|
|
|
|
import type { Picker } from 'emoji-mart'
|
|
|
|
|
|
|
|
const emit = defineEmits<{
|
|
|
|
(e: 'select', code: string): void
|
2022-12-28 03:38:57 +09:00
|
|
|
(e: 'selectCustom', image: any): void
|
2022-12-24 04:15:19 +09:00
|
|
|
}>()
|
|
|
|
|
|
|
|
const el = $ref<HTMLElement>()
|
|
|
|
let picker = $ref<Picker>()
|
2022-12-29 21:26:08 +09:00
|
|
|
const colorMode = useColorMode()
|
2022-12-24 04:15:19 +09:00
|
|
|
|
|
|
|
async function openEmojiPicker() {
|
2022-12-27 21:28:02 +09:00
|
|
|
await updateCustomEmojis()
|
|
|
|
if (picker) {
|
|
|
|
picker.update({
|
2022-12-28 10:06:54 +09:00
|
|
|
theme: colorMode.value,
|
2022-12-27 21:28:02 +09:00
|
|
|
custom: customEmojisData.value,
|
|
|
|
})
|
|
|
|
}
|
|
|
|
else {
|
2022-12-24 07:56:16 +09:00
|
|
|
const promise = import('@emoji-mart/data').then(r => r.default)
|
2022-12-24 04:15:19 +09:00
|
|
|
const { Picker } = await import('emoji-mart')
|
|
|
|
picker = new Picker({
|
2022-12-24 07:56:16 +09:00
|
|
|
data: () => promise,
|
2022-12-28 03:38:57 +09:00
|
|
|
onEmojiSelect({ native, src, alt, name }: any) {
|
|
|
|
native
|
|
|
|
? emit('select', native)
|
|
|
|
: emit('selectCustom', { src, alt, 'data-emoji-id': name })
|
2022-12-24 04:15:19 +09:00
|
|
|
},
|
2022-12-28 10:06:54 +09:00
|
|
|
theme: colorMode.value,
|
2022-12-24 07:56:16 +09:00
|
|
|
custom: customEmojisData.value,
|
2022-12-24 04:15:19 +09:00
|
|
|
})
|
|
|
|
}
|
2022-12-26 01:58:00 +09:00
|
|
|
await nextTick()
|
|
|
|
// TODO: custom picker
|
|
|
|
el?.appendChild(picker as any as HTMLElement)
|
|
|
|
}
|
|
|
|
|
2022-12-27 21:28:02 +09:00
|
|
|
const hideEmojiPicker = () => {
|
2022-12-26 01:58:00 +09:00
|
|
|
if (picker)
|
|
|
|
el?.removeChild(picker as any as HTMLElement)
|
2022-12-24 04:15:19 +09:00
|
|
|
}
|
|
|
|
</script>
|
|
|
|
|
|
|
|
<template>
|
|
|
|
<VDropdown
|
|
|
|
@apply-show="openEmojiPicker()"
|
2022-12-27 21:28:02 +09:00
|
|
|
@apply-hide="hideEmojiPicker()"
|
2022-12-24 04:15:19 +09:00
|
|
|
>
|
|
|
|
<button btn-action-icon :title="$t('tooltip.emoji')">
|
|
|
|
<div i-ri:emotion-line />
|
|
|
|
</button>
|
|
|
|
<template #popper>
|
2022-12-24 07:56:16 +09:00
|
|
|
<div ref="el" min-w-10 min-h-10 />
|
2022-12-24 04:15:19 +09:00
|
|
|
</template>
|
|
|
|
</VDropdown>
|
|
|
|
</template>
|