2021-06-21 17:19:27 +02:00
|
|
|
<script lang="ts">
|
2021-08-09 14:49:17 +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";
|
2021-06-21 17:19:27 +02:00
|
|
|
|
|
|
|
//toolbar
|
2021-07-19 09:22:47 +02:00
|
|
|
const toolbarOptions = [
|
2021-06-21 17:19:27 +02:00
|
|
|
['bold', 'italic', 'underline', 'strike'], // toggled buttons
|
|
|
|
['blockquote', 'code-block'],
|
|
|
|
|
|
|
|
[{'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
|
|
|
|
|
|
|
|
[{'size': ['small', false, 'large', 'huge']}], // custom dropdown
|
|
|
|
[{'header': [1, 2, 3, 4, 5, 6, false]}],
|
|
|
|
|
|
|
|
[{'color': []}, {'background': []}], // dropdown with defaults from theme
|
|
|
|
[{'font': []}],
|
|
|
|
[{'align': []}],
|
|
|
|
|
|
|
|
['clean'],
|
|
|
|
|
|
|
|
['link', 'image', 'video']
|
|
|
|
// remove formatting button
|
|
|
|
];
|
|
|
|
|
2021-08-03 17:19:47 +02:00
|
|
|
const gameScene = gameManager.getCurrentGameScene();
|
2021-06-21 17:19:27 +02:00
|
|
|
const MESSAGE_TYPE = AdminMessageEventTypes.admin;
|
2021-08-09 14:49:17 +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,
|
|
|
|
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-07-19 09:22:47 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-06-21 17:19:27 +02:00
|
|
|
//Quill
|
|
|
|
onMount(async () => {
|
|
|
|
// Import quill
|
|
|
|
const {default: Quill} = await import("quill"); // eslint-disable-line @typescript-eslint/no-explicit-any
|
|
|
|
|
2021-08-09 14:49:17 +02:00
|
|
|
quill = new Quill(QUILL_EDITOR, {
|
2021-07-15 15:09:35 +02:00
|
|
|
placeholder: 'Enter your message here...',
|
2021-06-21 17:19:27 +02:00
|
|
|
theme: 'snow',
|
|
|
|
modules: {
|
|
|
|
toolbar: toolbarOptions
|
|
|
|
},
|
|
|
|
});
|
2021-08-09 14:49:17 +02:00
|
|
|
menuInputFocusStore.set(true);
|
2021-06-21 17:19:27 +02:00
|
|
|
});
|
|
|
|
|
2021-07-23 16:17:53 +02:00
|
|
|
onDestroy(() => {
|
2021-08-09 14:49:17 +02:00
|
|
|
menuInputFocusStore.set(false);
|
2021-07-23 16:17:53 +02:00
|
|
|
})
|
2021-06-21 17:19:27 +02:00
|
|
|
</script>
|
|
|
|
|
|
|
|
<section class="section-input-send-text">
|
2021-08-09 14:49:17 +02:00
|
|
|
<div class="input-send-text" bind:this={QUILL_EDITOR}></div>
|
2021-06-21 17:19:27 +02:00
|
|
|
</section>
|
|
|
|
|
|
|
|
|
|
|
|
<style lang="scss">
|
|
|
|
@import 'https://cdn.quilljs.com/1.3.7/quill.snow.css';
|
|
|
|
</style>
|