2021-06-21 17:19:27 +02:00
|
|
|
<script lang="ts">
|
2021-08-26 12:01:07 +02:00
|
|
|
import { menuInputFocusStore } from "../../Stores/MenuStore";
|
|
|
|
import { onDestroy, onMount } from "svelte";
|
|
|
|
import { gameManager } from "../../Phaser/Game/GameManager";
|
2021-07-19 09:22:47 +02:00
|
|
|
import { AdminMessageEventTypes } from "../../Connexion/AdminMessagesService";
|
|
|
|
import type { Quill } from "quill";
|
2021-07-22 16:14:27 +02:00
|
|
|
import type { PlayGlobalMessageInterface } from "../../Connexion/ConnexionModels";
|
2022-01-19 09:28:08 +01:00
|
|
|
import { _ } from "../../Translator/Translator";
|
2021-06-21 17:19:27 +02:00
|
|
|
|
|
|
|
//toolbar
|
2021-07-19 09:22:47 +02:00
|
|
|
const toolbarOptions = [
|
2021-12-06 16:12:37 +01:00
|
|
|
["bold", "italic", "underline", "strike"], // toggled buttons
|
|
|
|
["blockquote", "code-block"],
|
2021-06-21 17:19:27 +02:00
|
|
|
|
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-06-21 17:19:27 +02:00
|
|
|
|
2021-12-06 16:12:37 +01:00
|
|
|
[{ size: ["small", false, "large", "huge"] }], // custom dropdown
|
|
|
|
[{ header: [1, 2, 3, 4, 5, 6, false] }],
|
2021-06-21 17:19:27 +02:00
|
|
|
|
2021-12-06 16:12:37 +01:00
|
|
|
[{ color: [] }, { background: [] }], // dropdown with defaults from theme
|
|
|
|
[{ font: [] }],
|
|
|
|
[{ align: [] }],
|
2021-06-21 17:19:27 +02:00
|
|
|
|
2021-12-06 16:12:37 +01:00
|
|
|
["clean"], // remove formatting button
|
2021-06-21 17:19:27 +02:00
|
|
|
|
2021-12-06 16:12:37 +01:00
|
|
|
["link", "image", "video"],
|
2021-06-21 17:19:27 +02:00
|
|
|
];
|
|
|
|
|
2021-08-16 11:43:29 +02:00
|
|
|
const gameScene = gameManager.getCurrentGameScene();
|
2021-06-21 17:19:27 +02:00
|
|
|
const MESSAGE_TYPE = AdminMessageEventTypes.admin;
|
2021-08-26 12:01:07 +02:00
|
|
|
let quill: Quill;
|
|
|
|
let QUILL_EDITOR: HTMLDivElement;
|
2021-06-21 17:19:27 +02:00
|
|
|
|
2021-07-19 09:22:47 +02:00
|
|
|
export const handleSending = {
|
2021-07-20 15:16:51 +02:00
|
|
|
sendTextMessage(broadcastToWorld: boolean) {
|
2021-07-19 09:22:47 +02:00
|
|
|
if (gameScene == undefined) {
|
|
|
|
return;
|
|
|
|
}
|
2021-07-23 11:07:17 +02:00
|
|
|
const text = JSON.stringify(quill.getContents(0, quill.getLength()));
|
2021-07-22 16:14:27 +02:00
|
|
|
|
|
|
|
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,
|
2021-07-19 09:22:47 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
quill.deleteText(0, quill.getLength());
|
2021-07-22 16:14:27 +02:00
|
|
|
gameScene.connection?.emitGlobalMessage(textGlobalMessage);
|
2021-12-06 16:12:37 +01:00
|
|
|
},
|
|
|
|
};
|
2021-07-19 09:22:47 +02:00
|
|
|
|
2021-06-21 17:19:27 +02: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
|
2021-06-21 17:19:27 +02:00
|
|
|
|
2021-08-26 12:01:07 +02:00
|
|
|
quill = new Quill(QUILL_EDITOR, {
|
2022-01-19 09:28:08 +01:00
|
|
|
placeholder: _("menu.global-message.enter"),
|
2021-12-06 16:12:37 +01:00
|
|
|
theme: "snow",
|
2021-06-21 17:19:27 +02:00
|
|
|
modules: {
|
2021-12-06 16:12:37 +01:00
|
|
|
toolbar: toolbarOptions,
|
2021-06-21 17:19:27 +02:00
|
|
|
},
|
|
|
|
});
|
2021-08-26 12:01:07 +02:00
|
|
|
menuInputFocusStore.set(true);
|
2021-06-21 17:19:27 +02:00
|
|
|
});
|
|
|
|
|
2021-07-23 16:17:53 +02:00
|
|
|
onDestroy(() => {
|
2021-08-26 12:01:07 +02:00
|
|
|
menuInputFocusStore.set(false);
|
2021-12-06 16:12:37 +01:00
|
|
|
});
|
2021-06-21 17:19:27 +02: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} />
|
2021-06-21 17:19:27 +02:00
|
|
|
</section>
|
|
|
|
|
|
|
|
<style lang="scss">
|
2021-12-06 16:12:37 +01:00
|
|
|
@import "https://cdn.quilljs.com/1.3.7/quill.snow.css";
|
2021-06-21 17:19:27 +02:00
|
|
|
</style>
|