Merge pull request 'Updated files to support modules' () 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:
retoor 2025-03-16 01:40:06 +00:00
commit a9663c8170
7 changed files with 31 additions and 24 deletions

View File

@ -7,7 +7,9 @@
// MIT License
class RESTClient {
import { Schedule } from './schedule.js';
export class RESTClient {
debug = false;
async get(url, params = {}) {
@ -43,7 +45,7 @@ class RESTClient {
}
}
class EventHandler {
export class EventHandler {
constructor() {
this.subscribers = {};
}
@ -58,7 +60,7 @@ class EventHandler {
}
}
class Chat extends EventHandler {
export class Chat extends EventHandler {
constructor() {
super();
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;
isConnected = null;
isConnecting = null;
@ -259,7 +261,7 @@ class Socket extends EventHandler {
}
}
class NotificationAudio {
export class NotificationAudio {
constructor(timeout = 500) {
this.schedule = new Schedule(timeout);
}
@ -284,7 +286,7 @@ class NotificationAudio {
}
}
class App extends EventHandler {
export class App extends EventHandler {
rest = new RESTClient();
ws = null;
rpc = null;
@ -366,4 +368,4 @@ class App extends EventHandler {
}
}
const app = new App();
export const app = new App();

View File

@ -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 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) {
this.msDelay = msDelay;
this._once = false;

View File

@ -9,12 +9,11 @@
<!--
<script src="/push.js"></script>
-->
<script src="/fancy-button.js"></script>
<script src="/upload-button.js"></script>
<script src="/generic-form.js"></script>
<script src="/html-frame.js"></script>
<script src="/schedule.js"></script>
<script src="/app.js"></script>
<script src="/fancy-button.js" type="module"></script>
<script src="/upload-button.js" type="module"></script>
<script src="/generic-form.js" type="module"></script>
<script src="/html-frame.js" type="module"></script>
<script src="/app.js" type="module"></script>
<link rel="stylesheet" href="/base.css">
<link rel="icon" type="image/png" href="/image/snek1.png" sizes="32x32">

View File

@ -12,13 +12,13 @@
<title>{% block title %}Snek chat by Molodetz{% endblock %}</title>
<script src="/app.js"></script>
<script src="/message-list.js"></script>
<script src="/app.js" type="module"></script>
<script src="/message-list.js" type="module"></script>
<style>{{ highlight_styles }}</style>
<link rel="stylesheet" href="/style.css">
<script src="/fancy-button.js"></script>
<script src="/html-frame.js"></script>
<script src="/generic-form.js"></script>
<script src="/fancy-button.js" type="module"></script>
<script src="/html-frame.js" type="module"></script>
<script src="/generic-form.js" type="module"></script>
<link rel="stylesheet" href="/html-frame.css">
{% block head %}

View File

@ -35,7 +35,8 @@
</div>
</section>
<script>
<script type="module">
import { app } from "/app.js";
document.querySelector("[name=query]").focus();

View File

@ -24,7 +24,8 @@
<chat-window style="display:none" class="chat-area"></chat-window>
</section>
<script>
<script type="module">
import { app } from "/app.js";
function updateTimes() {
document.querySelectorAll(".time").forEach((time) => {

View File

@ -19,7 +19,9 @@
</div>
</section>
<script>
<script type="module">
import { app } from "/app.js";
const channelUid = "{{ channel.uid.value }}";
function getInputField(){
@ -120,6 +122,8 @@
loadExtra();
});
let lastMessage
function updateLayout(doScrollDown) {
const messagesContainer = document.querySelector(".chat-messages");
updateTimes();
@ -134,7 +138,7 @@
});
lastMessage = messagesContainer.querySelector(".message:last-child");
if (doScrollDown) {
lastMessage.scrollIntoView({ inline: "nearest" });
lastMessage?.scrollIntoView({ inline: "nearest" });
}
}
@ -171,7 +175,7 @@
}
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 message = document.createElement("div");