2018-04-04 20:33:17 -07:00
|
|
|
<ModalDialog
|
2018-05-01 17:05:36 -07:00
|
|
|
{id}
|
|
|
|
{label}
|
|
|
|
{title}
|
2018-04-04 20:33:17 -07:00
|
|
|
background="var(--main-bg)"
|
|
|
|
>
|
2018-12-18 00:43:51 -08:00
|
|
|
<div class="emoji-container" {style} >
|
|
|
|
{#if loaded}
|
|
|
|
<emoji-mart props-json={emojiMartPropsJson} ></emoji-mart>
|
|
|
|
{:elseif error}
|
|
|
|
<div>Failed to load emoji picker: {error}</div>
|
2018-05-01 17:05:36 -07:00
|
|
|
{:else}
|
2018-12-18 00:43:51 -08:00
|
|
|
<div class="emoji-container-loading" >
|
|
|
|
<LoadingSpinner />
|
|
|
|
</div>
|
2018-05-01 17:05:36 -07:00
|
|
|
{/if}
|
2018-02-27 23:18:07 -08:00
|
|
|
</div>
|
|
|
|
</ModalDialog>
|
|
|
|
<style>
|
2018-12-18 00:43:51 -08:00
|
|
|
.emoji-container {
|
|
|
|
max-width: calc(100vw - 20px);
|
|
|
|
position: relative;
|
2018-02-27 23:18:07 -08:00
|
|
|
}
|
2018-12-18 00:43:51 -08:00
|
|
|
.emoji-container-loading {
|
|
|
|
position: absolute;
|
|
|
|
left: 0;
|
|
|
|
right: 0;
|
|
|
|
top: 0;
|
|
|
|
bottom: 0;
|
|
|
|
display: flex;
|
|
|
|
align-items: center;
|
|
|
|
justify-content: center;
|
2018-02-27 23:18:07 -08:00
|
|
|
}
|
2018-12-18 00:43:51 -08:00
|
|
|
:global(.emoji-mart-category .emoji-mart-emoji-custom span,
|
|
|
|
.emoji-mart-preview-emoji .emoji-mart-emoji-custom span) {
|
|
|
|
/* some custom emoji look repeated because they aren't tall enough */
|
|
|
|
background-repeat: no-repeat;
|
|
|
|
background-position: center center;
|
2018-02-27 23:18:07 -08:00
|
|
|
}
|
2018-12-18 12:45:41 -08:00
|
|
|
:global(.emoji-container .emoji-mart-emoji-native) {
|
|
|
|
/* remove if/when https://github.com/missive/emoji-mart/pull/256 is merged */
|
|
|
|
font-family: PinaforeEmoji, sans-serif;
|
|
|
|
}
|
2018-02-27 23:18:07 -08:00
|
|
|
</style>
|
|
|
|
<script>
|
|
|
|
import ModalDialog from './ModalDialog.html'
|
2018-04-08 16:56:20 -07:00
|
|
|
import { store } from '../../../_store/store'
|
|
|
|
import { insertEmoji } from '../../../_actions/emoji'
|
|
|
|
import { show } from '../helpers/showDialog'
|
|
|
|
import { close } from '../helpers/closeDialog'
|
2018-12-18 00:43:51 -08:00
|
|
|
import { oncreate as onCreateDialog } from '../helpers/onCreateDialog'
|
|
|
|
import { define } from 'remount/es6'
|
|
|
|
import { loadCSS } from '../../../_utils/loadCSS'
|
|
|
|
import LoadingSpinner from '../../../_components/LoadingSpinner.html'
|
|
|
|
import { importEmojiMart } from '../../../_utils/asyncModules'
|
|
|
|
import { on } from '../../../_utils/eventBus'
|
2018-02-27 23:18:07 -08:00
|
|
|
|
|
|
|
export default {
|
2018-12-18 00:43:51 -08:00
|
|
|
async oncreate () {
|
|
|
|
onCreateDialog.call(this)
|
|
|
|
on('emoji-selected', this, emoji => this.onEmojiSelected(emoji))
|
|
|
|
try {
|
|
|
|
loadCSS('/emoji-mart.css')
|
|
|
|
let Picker = await importEmojiMart()
|
|
|
|
if (!customElements.get('emoji-mart')) {
|
|
|
|
define({ 'emoji-mart': Picker })
|
|
|
|
}
|
|
|
|
this.set({ loaded: true })
|
|
|
|
} catch (error) {
|
|
|
|
this.set({ error }) // should never happen, but you never know
|
|
|
|
}
|
|
|
|
},
|
2018-02-27 23:18:07 -08:00
|
|
|
components: {
|
2018-12-18 00:43:51 -08:00
|
|
|
ModalDialog,
|
|
|
|
LoadingSpinner
|
2018-02-27 23:18:07 -08:00
|
|
|
},
|
|
|
|
store: () => store,
|
2018-12-18 00:43:51 -08:00
|
|
|
data: () => ({
|
|
|
|
loading: true,
|
|
|
|
loaded: false,
|
|
|
|
error: void 0
|
|
|
|
}),
|
2018-02-27 23:18:07 -08:00
|
|
|
computed: {
|
2018-12-18 00:43:51 -08:00
|
|
|
// try to estimate size of emoji-mart based on mobile vs desktop
|
|
|
|
style: ({ $isSmallMobileSize }) => (`
|
|
|
|
min-width: ${$isSmallMobileSize ? 250 : 300}px;
|
|
|
|
min-height: ${$isSmallMobileSize ? 300 : 400}px;
|
|
|
|
`),
|
|
|
|
emojiMartPropsJson: ({ emojiMartProps }) => JSON.stringify(emojiMartProps),
|
|
|
|
emojiMartProps: ({ perLine, custom, showPreview }) => ({
|
|
|
|
perLine,
|
|
|
|
custom,
|
|
|
|
showPreview,
|
|
|
|
color: 'var(--nav-bg)',
|
|
|
|
emoji: 'sailboat',
|
|
|
|
title: 'Emoji'
|
|
|
|
}),
|
|
|
|
showPreview: ({ $isSmallMobileSize }) => !$isSmallMobileSize,
|
|
|
|
perLine: ({ $isSmallMobileSize }) => $isSmallMobileSize ? 7 : 9,
|
|
|
|
custom: ({ $currentCustomEmoji, $autoplayGifs }) => {
|
2018-02-27 23:18:07 -08:00
|
|
|
if (!$currentCustomEmoji) {
|
|
|
|
return []
|
|
|
|
}
|
2018-12-18 00:43:51 -08:00
|
|
|
return $currentCustomEmoji.filter(emoji => emoji.visible_in_picker).map(emoji => ({
|
|
|
|
name: emoji.shortcode,
|
|
|
|
short_names: [emoji.shortcode],
|
|
|
|
text: `:${emoji.shortcode}:`,
|
|
|
|
emoticons: [],
|
|
|
|
keywords: [emoji.shortcode],
|
|
|
|
imageUrl: $autoplayGifs ? emoji.url : emoji.static_url
|
|
|
|
}))
|
2018-02-27 23:18:07 -08:00
|
|
|
}
|
|
|
|
},
|
|
|
|
methods: {
|
2018-04-08 16:56:20 -07:00
|
|
|
show,
|
|
|
|
close,
|
2018-12-18 00:43:51 -08:00
|
|
|
onEmojiSelected (emoji) {
|
2018-04-19 09:37:05 -07:00
|
|
|
let { realm } = this.get()
|
|
|
|
insertEmoji(realm, emoji)
|
2018-04-08 16:56:20 -07:00
|
|
|
this.close()
|
2018-02-27 23:18:07 -08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2018-12-18 00:43:51 -08:00
|
|
|
</script>
|