Merge pull request 'Updated files to support modules' (#28) from BordedDev/snek:feat/convert-to-modules into main
Reviewed-on: https://molodetz.nl/retoor/snek/pulls/28 Reviewed-by: retoor <retoor@noreply@molodetz.nl>
This commit is contained in:
commit
a9663c8170
src/snek
@ -7,7 +7,9 @@
|
|||||||
|
|
||||||
// MIT License
|
// MIT License
|
||||||
|
|
||||||
class RESTClient {
|
import { Schedule } from './schedule.js';
|
||||||
|
|
||||||
|
export class RESTClient {
|
||||||
debug = false;
|
debug = false;
|
||||||
|
|
||||||
async get(url, params = {}) {
|
async get(url, params = {}) {
|
||||||
@ -43,7 +45,7 @@ class RESTClient {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
class EventHandler {
|
export class EventHandler {
|
||||||
constructor() {
|
constructor() {
|
||||||
this.subscribers = {};
|
this.subscribers = {};
|
||||||
}
|
}
|
||||||
@ -58,7 +60,7 @@ class EventHandler {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
class Chat extends EventHandler {
|
export class Chat extends EventHandler {
|
||||||
constructor() {
|
constructor() {
|
||||||
super();
|
super();
|
||||||
this._url = window.location.hostname === 'localhost' ? 'ws://localhost/chat.ws' : 'wss://' + window.location.hostname + '/chat.ws';
|
this._url = window.location.hostname === 'localhost' ? 'ws://localhost/chat.ws' : 'wss://' + window.location.hostname + '/chat.ws';
|
||||||
@ -132,7 +134,7 @@ class Chat extends EventHandler {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
class Socket extends EventHandler {
|
export class Socket extends EventHandler {
|
||||||
ws = null;
|
ws = null;
|
||||||
isConnected = null;
|
isConnected = null;
|
||||||
isConnecting = null;
|
isConnecting = null;
|
||||||
@ -259,7 +261,7 @@ class Socket extends EventHandler {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
class NotificationAudio {
|
export class NotificationAudio {
|
||||||
constructor(timeout = 500) {
|
constructor(timeout = 500) {
|
||||||
this.schedule = new Schedule(timeout);
|
this.schedule = new Schedule(timeout);
|
||||||
}
|
}
|
||||||
@ -284,7 +286,7 @@ class NotificationAudio {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
class App extends EventHandler {
|
export class App extends EventHandler {
|
||||||
rest = new RESTClient();
|
rest = new RESTClient();
|
||||||
ws = null;
|
ws = null;
|
||||||
rpc = null;
|
rpc = null;
|
||||||
@ -366,4 +368,4 @@ class App extends EventHandler {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const app = new App();
|
export const app = new App();
|
||||||
|
@ -9,7 +9,7 @@
|
|||||||
// The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
|
// The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
|
||||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||||
|
|
||||||
class Schedule {
|
export class Schedule {
|
||||||
constructor(msDelay = 100) {
|
constructor(msDelay = 100) {
|
||||||
this.msDelay = msDelay;
|
this.msDelay = msDelay;
|
||||||
this._once = false;
|
this._once = false;
|
||||||
|
@ -9,12 +9,11 @@
|
|||||||
<!--
|
<!--
|
||||||
<script src="/push.js"></script>
|
<script src="/push.js"></script>
|
||||||
-->
|
-->
|
||||||
<script src="/fancy-button.js"></script>
|
<script src="/fancy-button.js" type="module"></script>
|
||||||
<script src="/upload-button.js"></script>
|
<script src="/upload-button.js" type="module"></script>
|
||||||
<script src="/generic-form.js"></script>
|
<script src="/generic-form.js" type="module"></script>
|
||||||
<script src="/html-frame.js"></script>
|
<script src="/html-frame.js" type="module"></script>
|
||||||
<script src="/schedule.js"></script>
|
<script src="/app.js" type="module"></script>
|
||||||
<script src="/app.js"></script>
|
|
||||||
<link rel="stylesheet" href="/base.css">
|
<link rel="stylesheet" href="/base.css">
|
||||||
|
|
||||||
<link rel="icon" type="image/png" href="/image/snek1.png" sizes="32x32">
|
<link rel="icon" type="image/png" href="/image/snek1.png" sizes="32x32">
|
||||||
|
@ -12,13 +12,13 @@
|
|||||||
|
|
||||||
<title>{% block title %}Snek chat by Molodetz{% endblock %}</title>
|
<title>{% block title %}Snek chat by Molodetz{% endblock %}</title>
|
||||||
|
|
||||||
<script src="/app.js"></script>
|
<script src="/app.js" type="module"></script>
|
||||||
<script src="/message-list.js"></script>
|
<script src="/message-list.js" type="module"></script>
|
||||||
<style>{{ highlight_styles }}</style>
|
<style>{{ highlight_styles }}</style>
|
||||||
<link rel="stylesheet" href="/style.css">
|
<link rel="stylesheet" href="/style.css">
|
||||||
<script src="/fancy-button.js"></script>
|
<script src="/fancy-button.js" type="module"></script>
|
||||||
<script src="/html-frame.js"></script>
|
<script src="/html-frame.js" type="module"></script>
|
||||||
<script src="/generic-form.js"></script>
|
<script src="/generic-form.js" type="module"></script>
|
||||||
<link rel="stylesheet" href="/html-frame.css">
|
<link rel="stylesheet" href="/html-frame.css">
|
||||||
|
|
||||||
{% block head %}
|
{% block head %}
|
||||||
|
@ -35,7 +35,8 @@
|
|||||||
|
|
||||||
</div>
|
</div>
|
||||||
</section>
|
</section>
|
||||||
<script>
|
<script type="module">
|
||||||
|
import { app } from "/app.js";
|
||||||
|
|
||||||
document.querySelector("[name=query]").focus();
|
document.querySelector("[name=query]").focus();
|
||||||
|
|
||||||
|
@ -24,7 +24,8 @@
|
|||||||
<chat-window style="display:none" class="chat-area"></chat-window>
|
<chat-window style="display:none" class="chat-area"></chat-window>
|
||||||
</section>
|
</section>
|
||||||
|
|
||||||
<script>
|
<script type="module">
|
||||||
|
import { app } from "/app.js";
|
||||||
|
|
||||||
function updateTimes() {
|
function updateTimes() {
|
||||||
document.querySelectorAll(".time").forEach((time) => {
|
document.querySelectorAll(".time").forEach((time) => {
|
||||||
|
@ -19,7 +19,9 @@
|
|||||||
</div>
|
</div>
|
||||||
</section>
|
</section>
|
||||||
|
|
||||||
<script>
|
<script type="module">
|
||||||
|
import { app } from "/app.js";
|
||||||
|
|
||||||
const channelUid = "{{ channel.uid.value }}";
|
const channelUid = "{{ channel.uid.value }}";
|
||||||
|
|
||||||
function getInputField(){
|
function getInputField(){
|
||||||
@ -120,6 +122,8 @@
|
|||||||
loadExtra();
|
loadExtra();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
let lastMessage
|
||||||
|
|
||||||
function updateLayout(doScrollDown) {
|
function updateLayout(doScrollDown) {
|
||||||
const messagesContainer = document.querySelector(".chat-messages");
|
const messagesContainer = document.querySelector(".chat-messages");
|
||||||
updateTimes();
|
updateTimes();
|
||||||
@ -134,7 +138,7 @@
|
|||||||
});
|
});
|
||||||
lastMessage = messagesContainer.querySelector(".message:last-child");
|
lastMessage = messagesContainer.querySelector(".message:last-child");
|
||||||
if (doScrollDown) {
|
if (doScrollDown) {
|
||||||
lastMessage.scrollIntoView({ inline: "nearest" });
|
lastMessage?.scrollIntoView({ inline: "nearest" });
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -171,7 +175,7 @@
|
|||||||
}
|
}
|
||||||
|
|
||||||
const messagesContainer = document.querySelector(".chat-messages");
|
const messagesContainer = document.querySelector(".chat-messages");
|
||||||
const lastMessage = messagesContainer.querySelector(".message:last-child");
|
lastMessage = messagesContainer.querySelector(".message:last-child");
|
||||||
const doScrollDownBecauseLastMessageIsVisible = !lastMessage || isElementVisible(lastMessage);
|
const doScrollDownBecauseLastMessageIsVisible = !lastMessage || isElementVisible(lastMessage);
|
||||||
|
|
||||||
const message = document.createElement("div");
|
const message = document.createElement("div");
|
||||||
|
Loading…
Reference in New Issue
Block a user