partey_workadventure/front/src/Components/Menu/TextGlobalMessage.svelte

83 lines
2.7 KiB
Svelte
Raw Normal View History

<script lang="ts">
import { menuInputFocusStore } from "../../Stores/MenuStore";
import { onDestroy, onMount } from "svelte";
import { gameManager } from "../../Phaser/Game/GameManager";
import { AdminMessageEventTypes } from "../../Connexion/AdminMessagesService";
import type { Quill } from "quill";
import type { PlayGlobalMessageInterface } from "../../Connexion/ConnexionModels";
2022-01-21 17:06:03 +01:00
import LL from "../../i18n/i18n-svelte";
//toolbar
const toolbarOptions = [
2021-12-06 16:12:37 +01:00
["bold", "italic", "underline", "strike"], // toggled buttons
["blockquote", "code-block"],
2021-12-06 16:12:37 +01:00
[{ header: 1 }, { header: 2 }], // custom button values
[{ list: "ordered" }, { list: "bullet" }],
[{ script: "sub" }, { script: "super" }], // superscript/subscript
[{ indent: "-1" }, { indent: "+1" }], // outdent/indent
[{ direction: "rtl" }], // text direction
2021-12-06 16:12:37 +01:00
[{ size: ["small", false, "large", "huge"] }], // custom dropdown
[{ header: [1, 2, 3, 4, 5, 6, false] }],
2021-12-06 16:12:37 +01:00
[{ color: [] }, { background: [] }], // dropdown with defaults from theme
[{ font: [] }],
[{ align: [] }],
2021-12-06 16:12:37 +01:00
["clean"], // remove formatting button
2021-12-06 16:12:37 +01:00
["link", "image", "video"],
];
const gameScene = gameManager.getCurrentGameScene();
const MESSAGE_TYPE = AdminMessageEventTypes.admin;
let quill: Quill;
let QUILL_EDITOR: HTMLDivElement;
export const handleSending = {
2021-07-20 15:16:51 +02:00
sendTextMessage(broadcastToWorld: boolean) {
if (gameScene == undefined) {
return;
}
const text = JSON.stringify(quill.getContents(0, quill.getLength()));
const textGlobalMessage: PlayGlobalMessageInterface = {
2021-07-20 15:16:51 +02:00
type: MESSAGE_TYPE,
content: text,
2021-12-06 16:12:37 +01:00
broadcastToWorld: broadcastToWorld,
};
quill.deleteText(0, quill.getLength());
gameScene.connection?.emitGlobalMessage(textGlobalMessage);
2021-12-06 16:12:37 +01:00
},
};
//Quill
onMount(async () => {
// Import quill
2021-12-06 16:12:37 +01:00
const { default: Quill } = await import("quill"); // eslint-disable-line @typescript-eslint/no-explicit-any
quill = new Quill(QUILL_EDITOR, {
2022-01-21 17:06:03 +01:00
placeholder: $LL.menu.globalMessage.enter(),
2021-12-06 16:12:37 +01:00
theme: "snow",
modules: {
2021-12-06 16:12:37 +01:00
toolbar: toolbarOptions,
},
});
menuInputFocusStore.set(true);
});
onDestroy(() => {
menuInputFocusStore.set(false);
2021-12-06 16:12:37 +01:00
});
</script>
<section class="section-input-send-text">
2021-12-06 16:12:37 +01:00
<div class="input-send-text" bind:this={QUILL_EDITOR} />
</section>
<style lang="scss">
2021-12-06 16:12:37 +01:00
@import "https://cdn.quilljs.com/1.3.7/quill.snow.css";
</style>