2021-09-10 16:57:21 +02:00
|
|
|
<script lang="typescript">
|
2021-12-06 16:12:37 +01:00
|
|
|
import type { Unsubscriber } from "svelte/store";
|
|
|
|
import { emoteStore, emoteMenuStore } from "../../Stores/EmoteStore";
|
|
|
|
import { onDestroy, onMount } from "svelte";
|
|
|
|
import { EmojiButton } from "@joeattardi/emoji-button";
|
|
|
|
import { isMobile } from "../../Enum/EnvironmentVariable";
|
2021-09-10 16:57:21 +02:00
|
|
|
|
2021-12-06 16:12:37 +01:00
|
|
|
let emojiContainer: HTMLElement;
|
|
|
|
let picker: EmojiButton;
|
2021-09-16 18:20:42 +02:00
|
|
|
|
2021-12-06 16:12:37 +01:00
|
|
|
let unsubscriber: Unsubscriber | null = null;
|
2021-09-10 16:57:21 +02:00
|
|
|
|
2021-12-06 16:12:37 +01:00
|
|
|
onMount(() => {
|
|
|
|
picker = new EmojiButton({
|
|
|
|
rootElement: emojiContainer,
|
|
|
|
styleProperties: {
|
|
|
|
"--font": "Press Start 2P",
|
|
|
|
},
|
|
|
|
emojisPerRow: isMobile() ? 6 : 8,
|
|
|
|
autoFocusSearch: false,
|
|
|
|
style: "twemoji",
|
|
|
|
});
|
|
|
|
//the timeout is here to prevent the menu from flashing
|
|
|
|
setTimeout(() => picker.showPicker(emojiContainer), 100);
|
2021-09-10 16:57:21 +02:00
|
|
|
|
2021-12-06 16:12:37 +01:00
|
|
|
picker.on("emoji", (selection) => {
|
|
|
|
emoteStore.set({
|
|
|
|
unicode: selection.emoji,
|
|
|
|
url: selection.url,
|
|
|
|
name: selection.name,
|
|
|
|
});
|
|
|
|
});
|
2021-09-10 16:57:21 +02:00
|
|
|
|
2021-12-06 16:12:37 +01:00
|
|
|
picker.on("hidden", () => {
|
|
|
|
emoteMenuStore.closeEmoteMenu();
|
|
|
|
});
|
2021-09-10 16:57:21 +02:00
|
|
|
});
|
|
|
|
|
2021-12-06 16:12:37 +01:00
|
|
|
function onKeyDown(e: KeyboardEvent) {
|
|
|
|
if (e.key === "Escape") {
|
|
|
|
emoteMenuStore.closeEmoteMenu();
|
|
|
|
}
|
2021-09-16 18:20:42 +02:00
|
|
|
}
|
|
|
|
|
2021-12-06 16:12:37 +01:00
|
|
|
onDestroy(() => {
|
|
|
|
if (unsubscriber) {
|
|
|
|
unsubscriber();
|
|
|
|
}
|
2021-09-10 16:57:21 +02:00
|
|
|
|
2021-12-06 16:12:37 +01:00
|
|
|
picker.destroyPicker();
|
|
|
|
});
|
2021-09-10 16:57:21 +02:00
|
|
|
</script>
|
|
|
|
|
2021-12-06 16:12:37 +01:00
|
|
|
<svelte:window on:keydown={onKeyDown} />
|
2021-09-16 18:20:42 +02:00
|
|
|
|
2021-09-10 16:57:21 +02:00
|
|
|
<div class="emote-menu-container">
|
2021-12-06 16:12:37 +01:00
|
|
|
<div class="emote-menu" bind:this={emojiContainer} />
|
2021-09-10 16:57:21 +02:00
|
|
|
</div>
|
|
|
|
|
|
|
|
<style lang="scss">
|
2021-12-06 16:12:37 +01:00
|
|
|
.emote-menu-container {
|
|
|
|
display: flex;
|
|
|
|
width: 100%;
|
|
|
|
height: 100%;
|
|
|
|
justify-content: center;
|
|
|
|
align-items: center;
|
|
|
|
}
|
2021-09-10 16:57:21 +02:00
|
|
|
|
2021-12-06 16:12:37 +01:00
|
|
|
.emote-menu {
|
|
|
|
pointer-events: all;
|
|
|
|
}
|
|
|
|
</style>
|